fix(showcase): call ctx.log.info/.warn in hook bodies — sandbox ctx.log is an object#3323
Merged
Merged
Conversation
…og 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>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
examples/app-showcase的两个 hook body 用if (typeof ctx.log === 'function') ctx.log(...)守卫日志行,但沙箱 hook 运行时把ctx.log装成对象{ info, warn, error }(见packages/runtime/src/sandbox/quickjs-runner.ts的installCtx与script-runner.ts的ScriptContext.log),所以typeof ctx.log === 'function'恒为 false,这两行审计/告警日志是死代码,从不触发。改动
改用正确的对象方法 API:
AuditTaskCompletionHook(审计)ctx.log.info(...)WarnOverBudgetHook(告警)ctx.log.warn(...)两个 hook 都已声明
capabilities: ['log'],无需改能力。body 保持极简(去掉死守卫后更短,便于当文档阅读)。ctx.log的发射本身是 best-effort(转发到ctx.log?.[level]?.(),hook 路径下 host logger 可能缺省 → 静默 no-op),所以本改动修的是"调对 API",不改变可观测性;未把它们改造成写数据的 hook(超出范围)。纯 bug 修复,无需 changeset(AGENTS.md §263)。验证
os validate通过(showcase 全量,仅有与本改动无关的预存权限/master-detail 警告)。vitest run:9 文件 / 55 测试全绿。quickjs-runner.tsinstallCtx 把ctx.log装为对象、每 level 转发ctx.log?.[level]?.(...);ScriptContext.log类型为{ info, warn, error }。🤖 Generated with Claude Code