From cfc2b8b30fa1235d5f3b03b0fa95243846e94292 Mon Sep 17 00:00:00 2001 From: Jack Zhuang <277994282+os-zhuang@users.noreply.github.com> Date: Mon, 20 Jul 2026 02:47:21 +0800 Subject: [PATCH] =?UTF-8?q?fix(showcase):=20call=20ctx.log.info/.warn=20in?= =?UTF-8?q?=20hook=20bodies=20=E2=80=94=20sandbox=20ctx.log=20is=20an=20ob?= =?UTF-8?q?ject?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- examples/app-showcase/src/data/hooks/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/app-showcase/src/data/hooks/index.ts b/examples/app-showcase/src/data/hooks/index.ts index 68a16be3c9..a423bb1b5d 100644 --- a/examples/app-showcase/src/data/hooks/index.ts +++ b/examples/app-showcase/src/data/hooks/index.ts @@ -47,7 +47,7 @@ export const AuditTaskCompletionHook = { condition: "record.done == true", body: { language: 'js' as const, - source: "var r = ctx.result || ctx.input || {}; if (typeof ctx.log === 'function') ctx.log('task completed: ' + (r.title || r.id || 'unknown'));", + source: "var r = ctx.result || ctx.input || {}; ctx.log.info('task completed: ' + (r.title || r.id || 'unknown'));", capabilities: ['log'] as ('log')[], }, async: true, @@ -70,7 +70,7 @@ export const WarnOverBudgetHook = { condition: "has(record.spent) && has(record.budget) && record.spent > record.budget", body: { language: 'js' as const, - 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 + ')');", + source: "var r = ctx.result || ctx.input || {}; ctx.log.warn('project over budget: ' + (r.name || r.id || 'unknown') + ' (' + r.spent + ' / ' + r.budget + ')');", capabilities: ['log'] as ('log')[], }, async: true,