Skip to content

Commit cfc2b8b

Browse files
os-zhuangclaude
andcommitted
fix(showcase): call ctx.log.info/.warn in hook bodies — sandbox ctx.log is an object
AuditTaskCompletion and WarnOverBudget guarded their log line with `if (typeof ctx.log === 'function')`, but the sandboxed hook runtime installs `ctx.log` as an object `{ info, warn, error }` (quickjs-runner installCtx / ScriptContext.log), so the guard was always false and the lines were dead code. Call the correct object-method API: `ctx.log.info(...)` for the audit hook and `ctx.log.warn(...)` for the over-budget warning. Both already declare capabilities: ['log'], so no capability change is needed. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 524696a commit cfc2b8b

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

  • examples/app-showcase/src/data/hooks

examples/app-showcase/src/data/hooks/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const AuditTaskCompletionHook = {
4747
condition: "record.done == true",
4848
body: {
4949
language: 'js' as const,
50-
source: "var r = ctx.result || ctx.input || {}; if (typeof ctx.log === 'function') ctx.log('task completed: ' + (r.title || r.id || 'unknown'));",
50+
source: "var r = ctx.result || ctx.input || {}; ctx.log.info('task completed: ' + (r.title || r.id || 'unknown'));",
5151
capabilities: ['log'] as ('log')[],
5252
},
5353
async: true,
@@ -70,7 +70,7 @@ export const WarnOverBudgetHook = {
7070
condition: "has(record.spent) && has(record.budget) && record.spent > record.budget",
7171
body: {
7272
language: 'js' as const,
73-
source: "var r = ctx.result || ctx.input || {}; if (typeof ctx.log === 'function') ctx.log('project over budget: ' + (r.name || r.id || 'unknown') + ' (' + r.spent + ' / ' + r.budget + ')');",
73+
source: "var r = ctx.result || ctx.input || {}; ctx.log.warn('project over budget: ' + (r.name || r.id || 'unknown') + ' (' + r.spent + ' / ' + r.budget + ')');",
7474
capabilities: ['log'] as ('log')[],
7575
},
7676
async: true,

0 commit comments

Comments
 (0)