@namzu/sdk 69.4.0 → 71.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +161 -0
- package/dist/authorization/bare-repository.d.ts +21 -0
- package/dist/authorization/bare-repository.d.ts.map +1 -0
- package/dist/authorization/bare-repository.js +62 -0
- package/dist/authorization/bare-repository.js.map +1 -0
- package/dist/authorization/command-line.d.ts.map +1 -1
- package/dist/authorization/command-line.js +10 -3
- package/dist/authorization/command-line.js.map +1 -1
- package/dist/authorization/gate.d.ts +7 -0
- package/dist/authorization/gate.d.ts.map +1 -1
- package/dist/authorization/gate.js +4 -0
- package/dist/authorization/gate.js.map +1 -1
- package/dist/authorization/protected-paths.d.ts +24 -6
- package/dist/authorization/protected-paths.d.ts.map +1 -1
- package/dist/authorization/protected-paths.js +83 -10
- package/dist/authorization/protected-paths.js.map +1 -1
- package/dist/authorization/readonly-commands.d.ts +17 -5
- package/dist/authorization/readonly-commands.d.ts.map +1 -1
- package/dist/authorization/readonly-commands.js +77 -6
- package/dist/authorization/readonly-commands.js.map +1 -1
- package/dist/authorization/readonly-flags.d.ts.map +1 -1
- package/dist/authorization/readonly-flags.js +98 -0
- package/dist/authorization/readonly-flags.js.map +1 -1
- package/dist/authorization/shell-lexer.d.ts +15 -0
- package/dist/authorization/shell-lexer.d.ts.map +1 -1
- package/dist/authorization/shell-lexer.js +370 -2
- package/dist/authorization/shell-lexer.js.map +1 -1
- package/dist/authorization/shell-paths.d.ts.map +1 -1
- package/dist/authorization/shell-paths.js +276 -0
- package/dist/authorization/shell-paths.js.map +1 -1
- package/dist/authorization/shell-session-state.d.ts +47 -0
- package/dist/authorization/shell-session-state.d.ts.map +1 -0
- package/dist/authorization/shell-session-state.js +70 -0
- package/dist/authorization/shell-session-state.js.map +1 -0
- package/dist/authorization/shell-session.d.ts +9 -0
- package/dist/authorization/shell-session.d.ts.map +1 -0
- package/dist/authorization/shell-session.js +19 -0
- package/dist/authorization/shell-session.js.map +1 -0
- package/dist/authorization/skill-grant.d.ts.map +1 -1
- package/dist/authorization/skill-grant.js +1 -0
- package/dist/authorization/skill-grant.js.map +1 -1
- package/dist/compaction/extractor.d.ts.map +1 -1
- package/dist/compaction/extractor.js +2 -0
- package/dist/compaction/extractor.js.map +1 -1
- package/dist/compaction/hooks.d.ts +16 -0
- package/dist/compaction/hooks.d.ts.map +1 -1
- package/dist/compaction/hooks.js +26 -1
- package/dist/compaction/hooks.js.map +1 -1
- package/dist/compaction/manual.d.ts.map +1 -1
- package/dist/compaction/manual.js +6 -1
- package/dist/compaction/manual.js.map +1 -1
- package/dist/compaction/restore.d.ts.map +1 -1
- package/dist/compaction/restore.js +3 -2
- package/dist/compaction/restore.js.map +1 -1
- package/dist/config/runtime.d.ts +2 -0
- package/dist/config/runtime.d.ts.map +1 -1
- package/dist/config/runtime.js +7 -0
- package/dist/config/runtime.js.map +1 -1
- package/dist/connector/mcp/client.d.ts +7 -0
- package/dist/connector/mcp/client.d.ts.map +1 -1
- package/dist/connector/mcp/client.js +54 -4
- package/dist/connector/mcp/client.js.map +1 -1
- package/dist/connector/web/guarded-fetch.d.ts +30 -0
- package/dist/connector/web/guarded-fetch.d.ts.map +1 -1
- package/dist/connector/web/guarded-fetch.js +85 -0
- package/dist/connector/web/guarded-fetch.js.map +1 -1
- package/dist/connector/web/index.d.ts +1 -1
- package/dist/connector/web/index.d.ts.map +1 -1
- package/dist/connector/web/index.js +1 -1
- package/dist/connector/web/index.js.map +1 -1
- package/dist/connector/web/types.d.ts +8 -0
- package/dist/connector/web/types.d.ts.map +1 -1
- package/dist/constants/compaction/index.d.ts.map +1 -1
- package/dist/constants/compaction/index.js +1 -1
- package/dist/constants/compaction/index.js.map +1 -1
- package/dist/execution/code-runtime/worker-program.d.ts +1 -1
- package/dist/execution/code-runtime/worker-program.d.ts.map +1 -1
- package/dist/execution/code-runtime/worker-program.js +9 -5
- package/dist/execution/code-runtime/worker-program.js.map +1 -1
- package/dist/execution/local.d.ts.map +1 -1
- package/dist/execution/local.js +6 -1
- package/dist/execution/local.js.map +1 -1
- package/dist/peers/index.d.ts +2 -2
- package/dist/peers/index.d.ts.map +1 -1
- package/dist/peers/index.js +1 -1
- package/dist/peers/index.js.map +1 -1
- package/dist/peers/record.d.ts +74 -0
- package/dist/peers/record.d.ts.map +1 -1
- package/dist/peers/record.js +41 -1
- package/dist/peers/record.js.map +1 -1
- package/dist/peers/registry.d.ts.map +1 -1
- package/dist/peers/registry.js +20 -3
- package/dist/peers/registry.js.map +1 -1
- package/dist/plugin/bin-path.d.ts +41 -0
- package/dist/plugin/bin-path.d.ts.map +1 -0
- package/dist/plugin/bin-path.js +146 -0
- package/dist/plugin/bin-path.js.map +1 -0
- package/dist/plugin/common-layout/read.js +3 -3
- package/dist/plugin/common-layout/read.js.map +1 -1
- package/dist/plugin/common-layout-names.d.ts.map +1 -1
- package/dist/plugin/common-layout-names.js +0 -1
- package/dist/plugin/common-layout-names.js.map +1 -1
- package/dist/plugin/hook-module/capabilities.d.ts +12 -0
- package/dist/plugin/hook-module/capabilities.d.ts.map +1 -1
- package/dist/plugin/hook-module/capabilities.js +82 -10
- package/dist/plugin/hook-module/capabilities.js.map +1 -1
- package/dist/plugin/hook-module/consent.d.ts +11 -0
- package/dist/plugin/hook-module/consent.d.ts.map +1 -1
- package/dist/plugin/hook-module/consent.js +31 -0
- package/dist/plugin/hook-module/consent.js.map +1 -1
- package/dist/plugin/hook-module/host.d.ts.map +1 -1
- package/dist/plugin/hook-module/host.js +69 -23
- package/dist/plugin/hook-module/host.js.map +1 -1
- package/dist/plugin/hook-module/index.d.ts +1 -1
- package/dist/plugin/hook-module/index.d.ts.map +1 -1
- package/dist/plugin/hook-module/index.js +1 -1
- package/dist/plugin/hook-module/index.js.map +1 -1
- package/dist/plugin/hook-module/scan.d.ts +16 -0
- package/dist/plugin/hook-module/scan.d.ts.map +1 -1
- package/dist/plugin/hook-module/scan.js +68 -3
- package/dist/plugin/hook-module/scan.js.map +1 -1
- package/dist/plugin/hook-module/worker-source.d.ts +5 -4
- package/dist/plugin/hook-module/worker-source.d.ts.map +1 -1
- package/dist/plugin/hook-module/worker-source.js +254 -28
- package/dist/plugin/hook-module/worker-source.js.map +1 -1
- package/dist/plugin/lifecycle.d.ts +21 -0
- package/dist/plugin/lifecycle.d.ts.map +1 -1
- package/dist/plugin/lifecycle.js +64 -0
- package/dist/plugin/lifecycle.js.map +1 -1
- package/dist/plugin/shell-hook-tool-names.d.ts.map +1 -1
- package/dist/plugin/shell-hook-tool-names.js +1 -0
- package/dist/plugin/shell-hook-tool-names.js.map +1 -1
- package/dist/plugin/shell-hook.d.ts +1 -1
- package/dist/plugin/shell-hook.d.ts.map +1 -1
- package/dist/plugin/shell-hook.js +22 -4
- package/dist/plugin/shell-hook.js.map +1 -1
- package/dist/public-runtime.d.ts +11 -9
- package/dist/public-runtime.d.ts.map +1 -1
- package/dist/public-runtime.js +11 -8
- package/dist/public-runtime.js.map +1 -1
- package/dist/public-tools.d.ts +7 -3
- package/dist/public-tools.d.ts.map +1 -1
- package/dist/public-tools.js +7 -3
- package/dist/public-tools.js.map +1 -1
- package/dist/public-types.d.ts +2 -2
- package/dist/public-types.d.ts.map +1 -1
- package/dist/runtime/jobs/monitor-stream.d.ts +9 -1
- package/dist/runtime/jobs/monitor-stream.d.ts.map +1 -1
- package/dist/runtime/jobs/monitor-stream.js +13 -4
- package/dist/runtime/jobs/monitor-stream.js.map +1 -1
- package/dist/runtime/jobs/registry.d.ts +4 -0
- package/dist/runtime/jobs/registry.d.ts.map +1 -1
- package/dist/runtime/jobs/registry.js +12 -2
- package/dist/runtime/jobs/registry.js.map +1 -1
- package/dist/runtime/query/auto-review/git-status.d.ts.map +1 -1
- package/dist/runtime/query/auto-review/git-status.js +3 -2
- package/dist/runtime/query/auto-review/git-status.js.map +1 -1
- package/dist/runtime/query/executor.d.ts +16 -6
- package/dist/runtime/query/executor.d.ts.map +1 -1
- package/dist/runtime/query/executor.js +135 -15
- package/dist/runtime/query/executor.js.map +1 -1
- package/dist/runtime/query/index.d.ts.map +1 -1
- package/dist/runtime/query/index.js +2 -2
- package/dist/runtime/query/index.js.map +1 -1
- package/dist/runtime/query/iteration/outstanding-work.d.ts.map +1 -1
- package/dist/runtime/query/iteration/outstanding-work.js +14 -4
- package/dist/runtime/query/iteration/outstanding-work.js.map +1 -1
- package/dist/runtime/query/iteration/phases/compaction.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/compaction.js +11 -1
- package/dist/runtime/query/iteration/phases/compaction.js.map +1 -1
- package/dist/runtime/query/iteration/phases/tool-review.d.ts +2 -0
- package/dist/runtime/query/iteration/phases/tool-review.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/tool-review.js +19 -8
- package/dist/runtime/query/iteration/phases/tool-review.js.map +1 -1
- package/dist/runtime/query/path-escalation.d.ts +6 -0
- package/dist/runtime/query/path-escalation.d.ts.map +1 -1
- package/dist/runtime/query/path-escalation.js +58 -4
- package/dist/runtime/query/path-escalation.js.map +1 -1
- package/dist/runtime/query/review-policy.d.ts +21 -3
- package/dist/runtime/query/review-policy.d.ts.map +1 -1
- package/dist/runtime/query/review-policy.js +39 -21
- package/dist/runtime/query/review-policy.js.map +1 -1
- package/dist/runtime/query/steering.d.ts +11 -2
- package/dist/runtime/query/steering.d.ts.map +1 -1
- package/dist/runtime/query/steering.js +18 -4
- package/dist/runtime/query/steering.js.map +1 -1
- package/dist/sandbox/provider/local.d.ts.map +1 -1
- package/dist/sandbox/provider/local.js +3 -1
- package/dist/sandbox/provider/local.js.map +1 -1
- package/dist/schedules/describe.d.ts.map +1 -1
- package/dist/schedules/describe.js +2 -0
- package/dist/schedules/describe.js.map +1 -1
- package/dist/schedules/evaluate.d.ts +4 -0
- package/dist/schedules/evaluate.d.ts.map +1 -1
- package/dist/schedules/evaluate.js +26 -1
- package/dist/schedules/evaluate.js.map +1 -1
- package/dist/schedules/index.d.ts +3 -1
- package/dist/schedules/index.d.ts.map +1 -1
- package/dist/schedules/index.js +2 -1
- package/dist/schedules/index.js.map +1 -1
- package/dist/schedules/next-fire.d.ts.map +1 -1
- package/dist/schedules/next-fire.js +10 -0
- package/dist/schedules/next-fire.js.map +1 -1
- package/dist/schedules/spec.d.ts +9 -0
- package/dist/schedules/spec.d.ts.map +1 -1
- package/dist/schedules/spec.js +33 -0
- package/dist/schedules/spec.js.map +1 -1
- package/dist/schedules/types.d.ts +32 -4
- package/dist/schedules/types.d.ts.map +1 -1
- package/dist/schedules/types.js +3 -2
- package/dist/schedules/types.js.map +1 -1
- package/dist/schedules/watch.d.ts +23 -0
- package/dist/schedules/watch.d.ts.map +1 -0
- package/dist/schedules/watch.js +46 -0
- package/dist/schedules/watch.js.map +1 -0
- package/dist/session/workspace/git-worktree.d.ts.map +1 -1
- package/dist/session/workspace/git-worktree.js +2 -1
- package/dist/session/workspace/git-worktree.js.map +1 -1
- package/dist/skills/arguments.d.ts +58 -0
- package/dist/skills/arguments.d.ts.map +1 -0
- package/dist/skills/arguments.js +208 -0
- package/dist/skills/arguments.js.map +1 -0
- package/dist/skills/index.d.ts +3 -1
- package/dist/skills/index.d.ts.map +1 -1
- package/dist/skills/index.js +1 -0
- package/dist/skills/index.js.map +1 -1
- package/dist/skills/inline-shell-host.d.ts +6 -0
- package/dist/skills/inline-shell-host.d.ts.map +1 -1
- package/dist/skills/inline-shell-host.js +8 -0
- package/dist/skills/inline-shell-host.js.map +1 -1
- package/dist/skills/inline-shell.d.ts +26 -1
- package/dist/skills/inline-shell.d.ts.map +1 -1
- package/dist/skills/inline-shell.js +1308 -22
- package/dist/skills/inline-shell.js.map +1 -1
- package/dist/tools/builtins/bash-cwd.d.ts.map +1 -1
- package/dist/tools/builtins/bash-cwd.js +2 -0
- package/dist/tools/builtins/bash-cwd.js.map +1 -1
- package/dist/tools/builtins/bash.d.ts.map +1 -1
- package/dist/tools/builtins/bash.js +79 -11
- package/dist/tools/builtins/bash.js.map +1 -1
- package/dist/tools/builtins/exit-semantics.d.ts +6 -0
- package/dist/tools/builtins/exit-semantics.d.ts.map +1 -1
- package/dist/tools/builtins/exit-semantics.js +10 -0
- package/dist/tools/builtins/exit-semantics.js.map +1 -1
- package/dist/tools/builtins/glob.d.ts.map +1 -1
- package/dist/tools/builtins/glob.js +68 -13
- package/dist/tools/builtins/glob.js.map +1 -1
- package/dist/tools/builtins/grep.d.ts.map +1 -1
- package/dist/tools/builtins/grep.js +37 -12
- package/dist/tools/builtins/grep.js.map +1 -1
- package/dist/tools/builtins/index.d.ts +11 -0
- package/dist/tools/builtins/index.d.ts.map +1 -1
- package/dist/tools/builtins/index.js +14 -0
- package/dist/tools/builtins/index.js.map +1 -1
- package/dist/tools/builtins/job.js +1 -1
- package/dist/tools/builtins/job.js.map +1 -1
- package/dist/tools/builtins/monitor.d.ts +1 -1
- package/dist/tools/builtins/monitor.d.ts.map +1 -1
- package/dist/tools/builtins/monitor.js +4 -2
- package/dist/tools/builtins/monitor.js.map +1 -1
- package/dist/tools/builtins/notebook-cells.d.ts +31 -0
- package/dist/tools/builtins/notebook-cells.d.ts.map +1 -0
- package/dist/tools/builtins/notebook-cells.js +160 -0
- package/dist/tools/builtins/notebook-cells.js.map +1 -0
- package/dist/tools/builtins/notebook-edit.d.ts +8 -0
- package/dist/tools/builtins/notebook-edit.d.ts.map +1 -0
- package/dist/tools/builtins/notebook-edit.js +249 -0
- package/dist/tools/builtins/notebook-edit.js.map +1 -0
- package/dist/tools/builtins/notebook-guard.d.ts.map +1 -1
- package/dist/tools/builtins/notebook-guard.js +2 -1
- package/dist/tools/builtins/notebook-guard.js.map +1 -1
- package/dist/tools/builtins/push-notification.d.ts +49 -0
- package/dist/tools/builtins/push-notification.d.ts.map +1 -0
- package/dist/tools/builtins/push-notification.js +107 -0
- package/dist/tools/builtins/push-notification.js.map +1 -0
- package/dist/tools/builtins/read-file.d.ts.map +1 -1
- package/dist/tools/builtins/read-file.js +8 -3
- package/dist/tools/builtins/read-file.js.map +1 -1
- package/dist/tools/builtins/read-media.d.ts.map +1 -1
- package/dist/tools/builtins/read-media.js +2 -1
- package/dist/tools/builtins/read-media.js.map +1 -1
- package/dist/tools/builtins/read-render.d.ts.map +1 -1
- package/dist/tools/builtins/read-render.js +5 -3
- package/dist/tools/builtins/read-render.js.map +1 -1
- package/dist/tools/builtins/search-support.d.ts +6 -4
- package/dist/tools/builtins/search-support.d.ts.map +1 -1
- package/dist/tools/builtins/search-support.js +15 -3
- package/dist/tools/builtins/search-support.js.map +1 -1
- package/dist/tools/builtins/skill.d.ts.map +1 -1
- package/dist/tools/builtins/skill.js +30 -8
- package/dist/tools/builtins/skill.js.map +1 -1
- package/dist/tools/builtins/sleep-guard.d.ts +20 -0
- package/dist/tools/builtins/sleep-guard.d.ts.map +1 -1
- package/dist/tools/builtins/sleep-guard.js +125 -1
- package/dist/tools/builtins/sleep-guard.js.map +1 -1
- package/dist/tools/builtins/wait-for-job.js +1 -1
- package/dist/tools/builtins/wait-for-job.js.map +1 -1
- package/dist/tools/builtins/web.d.ts +2 -0
- package/dist/tools/builtins/web.d.ts.map +1 -1
- package/dist/tools/builtins/web.js +97 -3
- package/dist/tools/builtins/web.js.map +1 -1
- package/dist/tools/command-shell.d.ts +50 -0
- package/dist/tools/command-shell.d.ts.map +1 -1
- package/dist/tools/command-shell.js +145 -0
- package/dist/tools/command-shell.js.map +1 -1
- package/dist/tools/env-scrub.d.ts +2 -0
- package/dist/tools/env-scrub.d.ts.map +1 -1
- package/dist/tools/env-scrub.js +15 -1
- package/dist/tools/env-scrub.js.map +1 -1
- package/dist/tools/git-config-env.d.ts +55 -0
- package/dist/tools/git-config-env.d.ts.map +1 -0
- package/dist/tools/git-config-env.js +130 -0
- package/dist/tools/git-config-env.js.map +1 -0
- package/dist/tools/schedules/schedule-tool.d.ts +7 -0
- package/dist/tools/schedules/schedule-tool.d.ts.map +1 -1
- package/dist/tools/schedules/schedule-tool.js +72 -3
- package/dist/tools/schedules/schedule-tool.js.map +1 -1
- package/dist/tools/schedules/types.d.ts +38 -2
- package/dist/tools/schedules/types.d.ts.map +1 -1
- package/dist/types/connector/mcp.d.ts +24 -0
- package/dist/types/connector/mcp.d.ts.map +1 -1
- package/dist/types/message/index.d.ts +21 -1
- package/dist/types/message/index.d.ts.map +1 -1
- package/dist/types/message/index.js +37 -2
- package/dist/types/message/index.js.map +1 -1
- package/dist/types/permission/index.d.ts +11 -2
- package/dist/types/permission/index.d.ts.map +1 -1
- package/dist/types/permission/index.js +12 -2
- package/dist/types/permission/index.js.map +1 -1
- package/dist/types/plugin/index.d.ts +10 -2
- package/dist/types/plugin/index.d.ts.map +1 -1
- package/dist/types/plugin/index.js.map +1 -1
- package/dist/types/tool/index.d.ts +13 -0
- package/dist/types/tool/index.d.ts.map +1 -1
- package/dist/types/tool/index.js.map +1 -1
- package/dist/utils/plain-terminal-text.d.ts +21 -0
- package/dist/utils/plain-terminal-text.d.ts.map +1 -0
- package/dist/utils/plain-terminal-text.js +156 -0
- package/dist/utils/plain-terminal-text.js.map +1 -0
- package/package.json +1 -1
- package/src/authorization/bare-repository.ts +70 -0
- package/src/authorization/command-line.ts +18 -4
- package/src/authorization/gate.ts +11 -0
- package/src/authorization/protected-paths.ts +89 -10
- package/src/authorization/readonly-commands.ts +75 -6
- package/src/authorization/readonly-flags.ts +103 -0
- package/src/authorization/shell-lexer.ts +367 -2
- package/src/authorization/shell-paths.ts +386 -0
- package/src/authorization/shell-session-state.ts +97 -0
- package/src/authorization/shell-session.ts +23 -0
- package/src/authorization/skill-grant.ts +1 -0
- package/src/compaction/extractor.ts +1 -0
- package/src/compaction/hooks.ts +43 -1
- package/src/compaction/manual.ts +6 -0
- package/src/compaction/restore.ts +3 -2
- package/src/config/runtime.ts +7 -0
- package/src/connector/mcp/client.ts +61 -4
- package/src/connector/web/guarded-fetch.ts +92 -0
- package/src/connector/web/index.ts +6 -1
- package/src/connector/web/types.ts +8 -0
- package/src/constants/compaction/index.ts +1 -1
- package/src/execution/code-runtime/worker-program.ts +9 -5
- package/src/execution/local.ts +6 -1
- package/src/peers/index.ts +8 -2
- package/src/peers/record.ts +45 -1
- package/src/peers/registry.ts +21 -5
- package/src/plugin/bin-path.ts +149 -0
- package/src/plugin/common-layout/read.ts +3 -3
- package/src/plugin/common-layout-names.ts +0 -1
- package/src/plugin/hook-module/capabilities.ts +94 -10
- package/src/plugin/hook-module/consent.ts +36 -0
- package/src/plugin/hook-module/host.ts +72 -21
- package/src/plugin/hook-module/index.ts +2 -0
- package/src/plugin/hook-module/scan.ts +76 -4
- package/src/plugin/hook-module/worker-source.ts +255 -28
- package/src/plugin/lifecycle.ts +67 -0
- package/src/plugin/shell-hook-tool-names.ts +1 -0
- package/src/plugin/shell-hook.ts +23 -4
- package/src/public-runtime.ts +27 -0
- package/src/public-tools.ts +36 -2
- package/src/public-types.ts +3 -1
- package/src/runtime/jobs/monitor-stream.ts +18 -4
- package/src/runtime/jobs/registry.ts +22 -2
- package/src/runtime/query/auto-review/git-status.ts +3 -2
- package/src/runtime/query/executor.ts +153 -12
- package/src/runtime/query/index.ts +5 -2
- package/src/runtime/query/iteration/outstanding-work.ts +22 -4
- package/src/runtime/query/iteration/phases/compaction.ts +14 -1
- package/src/runtime/query/iteration/phases/tool-review.ts +24 -7
- package/src/runtime/query/path-escalation.ts +52 -4
- package/src/runtime/query/review-policy.ts +47 -15
- package/src/runtime/query/steering.ts +32 -4
- package/src/sandbox/provider/local.ts +3 -1
- package/src/schedules/describe.ts +2 -0
- package/src/schedules/evaluate.ts +29 -1
- package/src/schedules/index.ts +9 -1
- package/src/schedules/next-fire.ts +9 -0
- package/src/schedules/spec.ts +42 -0
- package/src/schedules/types.ts +33 -3
- package/src/schedules/watch.ts +71 -0
- package/src/session/workspace/git-worktree.ts +3 -1
- package/src/skills/arguments.ts +250 -0
- package/src/skills/index.ts +10 -0
- package/src/skills/inline-shell-host.ts +16 -0
- package/src/skills/inline-shell.ts +1358 -22
- package/src/tools/builtins/bash-cwd.ts +2 -0
- package/src/tools/builtins/bash.ts +93 -13
- package/src/tools/builtins/exit-semantics.ts +10 -0
- package/src/tools/builtins/glob.ts +79 -15
- package/src/tools/builtins/grep.ts +37 -10
- package/src/tools/builtins/index.ts +15 -0
- package/src/tools/builtins/job.ts +1 -1
- package/src/tools/builtins/monitor.ts +4 -2
- package/src/tools/builtins/notebook-cells.ts +196 -0
- package/src/tools/builtins/notebook-edit.ts +280 -0
- package/src/tools/builtins/notebook-guard.ts +2 -1
- package/src/tools/builtins/push-notification.ts +138 -0
- package/src/tools/builtins/read-file.ts +9 -3
- package/src/tools/builtins/read-media.ts +2 -1
- package/src/tools/builtins/read-render.ts +5 -3
- package/src/tools/builtins/search-support.ts +17 -3
- package/src/tools/builtins/skill.ts +29 -7
- package/src/tools/builtins/sleep-guard.ts +128 -1
- package/src/tools/builtins/wait-for-job.ts +1 -1
- package/src/tools/builtins/web.ts +100 -3
- package/src/tools/command-shell.ts +166 -0
- package/src/tools/env-scrub.ts +13 -1
- package/src/tools/git-config-env.ts +143 -0
- package/src/tools/schedules/schedule-tool.ts +79 -3
- package/src/tools/schedules/types.ts +47 -9
- package/src/types/connector/mcp.ts +25 -0
- package/src/types/message/index.ts +53 -1
- package/src/types/permission/index.ts +20 -3
- package/src/types/plugin/index.ts +10 -2
- package/src/types/tool/index.ts +13 -0
- package/src/utils/plain-terminal-text.ts +142 -0
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
} from 'node:fs'
|
|
15
15
|
import { isAbsolute, join, relative, resolve } from 'node:path'
|
|
16
16
|
|
|
17
|
+
import { privateAddressProblem, proxyConfigured } from '../../connector/web/guarded-fetch.js'
|
|
17
18
|
import type { Logger } from '../../utils/logger.js'
|
|
18
19
|
|
|
19
20
|
/** The most one read, one output stream or one answer body may hold. */
|
|
@@ -23,6 +24,17 @@ export const MAX_STORE_BYTES = 1024 * 1024
|
|
|
23
24
|
export const DEFAULT_PROCESS_TIMEOUT_MS = 30_000
|
|
24
25
|
export const MAX_PROCESS_TIMEOUT_MS = 10 * 60_000
|
|
25
26
|
export const HTTP_TIMEOUT_MS = 30_000
|
|
27
|
+
const MAX_HTTP_REDIRECTS = 5
|
|
28
|
+
/** The request headers that follow a redirect to another origin. */
|
|
29
|
+
const CROSS_ORIGIN_HEADERS: ReadonlySet<string> = new Set([
|
|
30
|
+
'accept',
|
|
31
|
+
'accept-language',
|
|
32
|
+
'content-type',
|
|
33
|
+
'user-agent',
|
|
34
|
+
])
|
|
35
|
+
|
|
36
|
+
/** A request header that only a caller reaching a cloud metadata service sets. */
|
|
37
|
+
const METADATA_HEADER = /metadata/i
|
|
26
38
|
/** The file the module's store is kept in, inside the plugin's data folder. */
|
|
27
39
|
export const STORE_FILE = 'hook-module-store.json'
|
|
28
40
|
|
|
@@ -35,12 +47,24 @@ export interface CapabilityBridgeOptions {
|
|
|
35
47
|
readonly projectDir: string
|
|
36
48
|
/** The variables the scan found named by literal; `$.env.get` answers no other. */
|
|
37
49
|
readonly envNames: readonly string[]
|
|
50
|
+
/**
|
|
51
|
+
* The calls the module's own scan found, as `$.noun.method`. When given, the bridge answers
|
|
52
|
+
* only these, so a call the module did not declare is refused here whatever the worker sent.
|
|
53
|
+
* Without it every supported call is answered.
|
|
54
|
+
*/
|
|
55
|
+
readonly allowedCalls?: readonly string[]
|
|
38
56
|
/** The environment those variables are read from, and a child inherits. Default `process.env`. */
|
|
39
57
|
readonly environment?: Readonly<Record<string, string | undefined>>
|
|
40
58
|
readonly log: Logger
|
|
41
59
|
readonly pluginName: string
|
|
42
60
|
/** The web fetch. Default the global one. */
|
|
43
61
|
readonly fetch?: typeof fetch
|
|
62
|
+
/** How a host name becomes addresses for the private-address check. Default `node:dns`. Tests inject it. */
|
|
63
|
+
readonly resolve?: (hostname: string, signal?: AbortSignal) => Promise<readonly string[]>
|
|
64
|
+
/** Let `$.http.fetch` use plain http to 127.0.0.1 or `[::1]`. For a test's own server; never set by a host. */
|
|
65
|
+
readonly allowLoopbackHttp?: boolean
|
|
66
|
+
/** Test only: whether requests go through a proxy; read from the environment when absent. */
|
|
67
|
+
readonly proxied?: boolean
|
|
44
68
|
}
|
|
45
69
|
|
|
46
70
|
export interface CapabilityBridge {
|
|
@@ -412,23 +436,60 @@ export function createCapabilityBridge(options: CapabilityBridgeOptions): Capabi
|
|
|
412
436
|
} catch {
|
|
413
437
|
throw new Error(`${url} is not a URL`)
|
|
414
438
|
}
|
|
415
|
-
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
|
|
416
|
-
throw new Error(`${parsed.protocol} is not http or https`)
|
|
417
|
-
}
|
|
418
439
|
const spec = isRecord(init) ? init : {}
|
|
419
440
|
const headers: Record<string, string> = {}
|
|
420
441
|
if (isRecord(spec.headers)) {
|
|
421
442
|
for (const [key, value] of Object.entries(spec.headers)) {
|
|
422
|
-
|
|
443
|
+
// A cloud metadata service asks for a header (`Metadata`, `Metadata-Flavor`,
|
|
444
|
+
// `X-aws-ec2-metadata-token`) that proves the caller meant to reach it;
|
|
445
|
+
// a module does not get to set one. `Host` would route a checked address
|
|
446
|
+
// to another virtual host.
|
|
447
|
+
if (typeof value === 'string' && !METADATA_HEADER.test(key) && key.toLowerCase() !== 'host')
|
|
448
|
+
headers[key] = value
|
|
423
449
|
}
|
|
424
450
|
}
|
|
425
451
|
if (spec.body !== undefined && typeof spec.body !== 'string') throw new Error('body is text')
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
452
|
+
let method = typeof spec.method === 'string' ? spec.method : 'GET'
|
|
453
|
+
let body = typeof spec.body === 'string' ? spec.body : undefined
|
|
454
|
+
const deadline = AbortSignal.timeout(HTTP_TIMEOUT_MS)
|
|
455
|
+
// Every hop is checked before it is requested, and redirects are never left to
|
|
456
|
+
// `fetch`: a public address that answers `302 -> http://169.254.169.254/` must
|
|
457
|
+
// not be followed there.
|
|
458
|
+
let response: Response
|
|
459
|
+
for (let hop = 0; ; hop++) {
|
|
460
|
+
await assertReachable(parsed, deadline)
|
|
461
|
+
response = await fetchImpl(parsed, {
|
|
462
|
+
method,
|
|
463
|
+
headers,
|
|
464
|
+
...(body !== undefined ? { body } : {}),
|
|
465
|
+
redirect: 'manual',
|
|
466
|
+
signal: deadline,
|
|
467
|
+
})
|
|
468
|
+
const location = response.headers.get('location')
|
|
469
|
+
if (response.status < 300 || response.status >= 400 || location === null) break
|
|
470
|
+
await response.body?.cancel().catch(() => undefined)
|
|
471
|
+
if (hop >= MAX_HTTP_REDIRECTS) throw new Error(`${parsed.hostname} redirected too many times`)
|
|
472
|
+
let next: URL
|
|
473
|
+
try {
|
|
474
|
+
next = new URL(location, parsed)
|
|
475
|
+
} catch {
|
|
476
|
+
throw new Error(`${parsed.hostname} redirected to something that is not an address`)
|
|
477
|
+
}
|
|
478
|
+
if (next.origin !== parsed.origin) {
|
|
479
|
+
// Only request headers that say what is wanted cross to another origin; a custom
|
|
480
|
+
// `X-Api-Key` or a signature header is a credential whatever its name.
|
|
481
|
+
for (const key of Object.keys(headers))
|
|
482
|
+
if (!CROSS_ORIGIN_HEADERS.has(key.toLowerCase())) delete headers[key]
|
|
483
|
+
}
|
|
484
|
+
if (
|
|
485
|
+
response.status === 303 ||
|
|
486
|
+
((response.status === 301 || response.status === 302) && method === 'POST')
|
|
487
|
+
) {
|
|
488
|
+
method = 'GET'
|
|
489
|
+
body = undefined
|
|
490
|
+
}
|
|
491
|
+
parsed = next
|
|
492
|
+
}
|
|
432
493
|
const bytes = Buffer.from(await response.arrayBuffer())
|
|
433
494
|
const answered: Record<string, string> = {}
|
|
434
495
|
response.headers.forEach((value, key) => {
|
|
@@ -442,6 +503,26 @@ export function createCapabilityBridge(options: CapabilityBridgeOptions): Capabi
|
|
|
442
503
|
}
|
|
443
504
|
}
|
|
444
505
|
|
|
506
|
+
/** Refuse an address a module may not reach: not https, or inside this machine's own network. */
|
|
507
|
+
const assertReachable = async (target: URL, signal: AbortSignal): Promise<void> => {
|
|
508
|
+
if (target.protocol !== 'https:' && target.protocol !== 'http:') {
|
|
509
|
+
throw new Error(`${target.protocol} is not http or https`)
|
|
510
|
+
}
|
|
511
|
+
const loopback = target.hostname === '127.0.0.1' || target.hostname === '[::1]'
|
|
512
|
+
if (target.protocol === 'http:' && !(options.allowLoopbackHttp === true && loopback)) {
|
|
513
|
+
throw new Error(`${target.hostname}: only https addresses are fetched`)
|
|
514
|
+
}
|
|
515
|
+
if (options.allowLoopbackHttp === true && loopback) return
|
|
516
|
+
const problem = await privateAddressProblem(target.hostname, {
|
|
517
|
+
...(options.resolve !== undefined ? { resolve: options.resolve } : {}),
|
|
518
|
+
proxied: options.proxied ?? proxyConfigured(process.env, target.hostname),
|
|
519
|
+
signal,
|
|
520
|
+
})
|
|
521
|
+
if (problem !== undefined) throw new Error(`${target.hostname} was not fetched: ${problem}`)
|
|
522
|
+
}
|
|
523
|
+
const allowedCalls =
|
|
524
|
+
options.allowedCalls === undefined ? undefined : new Set(options.allowedCalls)
|
|
525
|
+
|
|
445
526
|
return {
|
|
446
527
|
endProcesses() {
|
|
447
528
|
for (const child of children) {
|
|
@@ -454,6 +535,9 @@ export function createCapabilityBridge(options: CapabilityBridgeOptions): Capabi
|
|
|
454
535
|
children.clear()
|
|
455
536
|
},
|
|
456
537
|
async call(noun, method, args) {
|
|
538
|
+
if (allowedCalls !== undefined && !allowedCalls.has(`$.${noun}.${method}`)) {
|
|
539
|
+
throw new Error(`$.${noun}.${method} is not among the calls this module declares`)
|
|
540
|
+
}
|
|
457
541
|
switch (`${noun}.${method}`) {
|
|
458
542
|
case 'fs.read':
|
|
459
543
|
return fs.read(args)
|
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
import { classicWrittenName } from './events.js'
|
|
2
2
|
import type { HookModuleScan } from './scan.js'
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* What a person does about a hooks module that does not load or whose hook failed: the module guards
|
|
6
|
+
* calls, so a call is refused while it is broken, and the way out is to fix it or turn the plugin off.
|
|
7
|
+
*/
|
|
8
|
+
export function hookModuleRecovery(pluginName: string): string {
|
|
9
|
+
return `Update or fix the plugin, then start a new session, or turn it off with \`namzu plugin disable ${pluginName}\`.`
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** The text as a sentence: closed with a full stop when it does not already end in one. */
|
|
13
|
+
export function endedSentence(text: string): string {
|
|
14
|
+
const trimmed = text.trimEnd()
|
|
15
|
+
return /[.!?]$/.test(trimmed) ? trimmed : `${trimmed}.`
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** A refusal followed by the way out, the two kept apart as sentences. Said once if it already carries it. */
|
|
19
|
+
export function withHookModuleRecovery(text: string, pluginName: string): string {
|
|
20
|
+
const recovery = hookModuleRecovery(pluginName)
|
|
21
|
+
return text.includes(recovery) ? text : `${endedSentence(text)} ${recovery}`
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** What a person does about one hook that failed while the module stays loaded. */
|
|
25
|
+
export function hookFailureRecovery(pluginName: string): string {
|
|
26
|
+
return `Fix the hook, or turn the plugin off with \`namzu plugin disable ${pluginName}\`.`
|
|
27
|
+
}
|
|
28
|
+
|
|
4
29
|
/** What a hooks module does, in the terms a person is asked about. */
|
|
5
30
|
export interface HookModuleSummary {
|
|
6
31
|
/** The module, relative to the plugin. */
|
|
@@ -57,6 +82,13 @@ export function summarizeHookModule(scan: HookModuleScan): HookModuleSummary {
|
|
|
57
82
|
}
|
|
58
83
|
}
|
|
59
84
|
|
|
85
|
+
/** The events a hook answers for the person or against a call: a yes, a no or a changed call. */
|
|
86
|
+
const GATING_EVENTS: ReadonlySet<string> = new Set([
|
|
87
|
+
'PreToolUse',
|
|
88
|
+
'PermissionRequest',
|
|
89
|
+
'PreSkillShellCommand',
|
|
90
|
+
])
|
|
91
|
+
|
|
60
92
|
/** One line per thing a person is told about before a module is allowed to run. */
|
|
61
93
|
export function hookModuleConsentLines(summary: HookModuleSummary): string[] {
|
|
62
94
|
const lines: string[] = []
|
|
@@ -65,6 +97,10 @@ export function hookModuleConsentLines(summary: HookModuleSummary): string[] {
|
|
|
65
97
|
? `hooks ${summary.events.join(', ')}`
|
|
66
98
|
: 'hooks no event that Namzu runs',
|
|
67
99
|
)
|
|
100
|
+
// Naming the events is not enough: these ones decide whether a call goes ahead.
|
|
101
|
+
if (summary.events.some((event) => GATING_EVENTS.has(event))) {
|
|
102
|
+
lines.push('can approve, deny or change tool calls without asking you')
|
|
103
|
+
}
|
|
68
104
|
if (summary.runsCommands) lines.push('runs commands')
|
|
69
105
|
if (summary.readsFiles) lines.push('reads files in the plugin and the project')
|
|
70
106
|
if (summary.usesNetwork) lines.push('uses the network')
|
|
@@ -16,6 +16,12 @@ import {
|
|
|
16
16
|
shellHookVerdict,
|
|
17
17
|
} from '../shell-hook.js'
|
|
18
18
|
import { type CapabilityBridge, createCapabilityBridge } from './capabilities.js'
|
|
19
|
+
import {
|
|
20
|
+
endedSentence,
|
|
21
|
+
hookFailureRecovery,
|
|
22
|
+
hookModuleRecovery,
|
|
23
|
+
withHookModuleRecovery,
|
|
24
|
+
} from './consent.js'
|
|
19
25
|
import {
|
|
20
26
|
MODULE_HOOK_EVENTS,
|
|
21
27
|
classicEventName,
|
|
@@ -281,13 +287,65 @@ export async function startHookModule(options: StartHookModuleOptions): Promise<
|
|
|
281
287
|
log.warn('Hooks module not loaded', { ...attrs, 'namzu.hook_module.reason': why })
|
|
282
288
|
options.onUnload?.(why)
|
|
283
289
|
}
|
|
284
|
-
|
|
290
|
+
let disposed = false
|
|
291
|
+
const recovery = hookModuleRecovery(plugin.name)
|
|
292
|
+
/** A refusal says how to get past it; a message that already says so is not told twice. */
|
|
293
|
+
const withRecovery = (text: string): string => withHookModuleRecovery(text, plugin.name)
|
|
294
|
+
const commandLabel = `module ${label}`
|
|
295
|
+
const failurePolicy = (event: ShellHookEvent, why: string): PluginHookResult => {
|
|
296
|
+
log.warn('Hooks module hook failed', {
|
|
297
|
+
...attrs,
|
|
298
|
+
'namzu.hook.event': event,
|
|
299
|
+
'namzu.hook_module.reason': why,
|
|
300
|
+
})
|
|
301
|
+
// A hook that failed leaves the module loaded, so its way out is not a new session; a message that
|
|
302
|
+
// is already an unload or refusal text carries its own recovery.
|
|
303
|
+
const closed = why.includes(recovery)
|
|
304
|
+
? why
|
|
305
|
+
: `${endedSentence(why)} ${hookFailureRecovery(plugin.name)}`
|
|
306
|
+
const line = `${commandLabel}: ${closed}`
|
|
307
|
+
// A guard that failed does not wave the call through: the call is refused and the model is told why.
|
|
308
|
+
if (event === 'pre_tool_use') return { action: 'error', message: line }
|
|
309
|
+
if (event === 'pre_skill_shell_command') return { action: 'skip', reason: line }
|
|
310
|
+
// A permission request that gets no decision stays with the person: the prompt is still asked.
|
|
311
|
+
return { action: 'continue', notice: line }
|
|
312
|
+
}
|
|
313
|
+
/** The events whose hooks gate a call: a gate that did not load must not read as a gate that passed. */
|
|
314
|
+
const guards = new Set<ShellHookEvent>([
|
|
315
|
+
'pre_tool_use',
|
|
316
|
+
'pre_skill_shell_command',
|
|
317
|
+
'permission_request',
|
|
318
|
+
])
|
|
319
|
+
|
|
320
|
+
const unloaded = (why: string, refusedGuards?: ReadonlySet<ShellHookEvent>): HookModuleHandle => {
|
|
285
321
|
unload(why)
|
|
286
|
-
|
|
322
|
+
// A refused module's guards never attached, which reads as a guard that passed. The events its
|
|
323
|
+
// scan saw it hook are still answered as a failed guard is, so a refusal does not wave calls through.
|
|
324
|
+
const hooks: PluginHookDefinition[] = []
|
|
325
|
+
for (const event of MODULE_HOOK_EVENTS) {
|
|
326
|
+
if (!refusedGuards?.has(event)) continue
|
|
327
|
+
hooks.push({
|
|
328
|
+
event,
|
|
329
|
+
handler: async (): Promise<PluginHookResult> =>
|
|
330
|
+
disposed ? { action: 'continue' } : failurePolicy(event, why),
|
|
331
|
+
} as PluginHookDefinition)
|
|
332
|
+
}
|
|
333
|
+
return {
|
|
334
|
+
scan,
|
|
335
|
+
status,
|
|
336
|
+
message: why,
|
|
337
|
+
hooks,
|
|
338
|
+
dispose: async () => {
|
|
339
|
+
disposed = true
|
|
340
|
+
},
|
|
341
|
+
}
|
|
287
342
|
}
|
|
288
343
|
|
|
289
344
|
if (scan.refusals.length > 0 || scan.program === undefined) {
|
|
290
|
-
|
|
345
|
+
// A refusal can come from a name the scan does not follow, so which events the module hooks is
|
|
346
|
+
// unknown, and unknown reads as guarding: every guarding event is answered as a failed guard.
|
|
347
|
+
const seen = guards
|
|
348
|
+
return unloaded(withRecovery(`hooks module ${label} not loaded: ${refusalLine(scan)}`), seen)
|
|
291
349
|
}
|
|
292
350
|
const program = scan.program
|
|
293
351
|
const runnable = new Set<ShellHookEvent>()
|
|
@@ -305,6 +363,8 @@ export async function startHookModule(options: StartHookModuleOptions): Promise<
|
|
|
305
363
|
...(plugin.dataDir !== undefined ? { dataDir: plugin.dataDir } : {}),
|
|
306
364
|
projectDir: options.projectDir,
|
|
307
365
|
envNames: scan.envNames,
|
|
366
|
+
// What the module's own scan declared is all its calls reach, whatever the worker sends.
|
|
367
|
+
allowedCalls: scan.calls.filter((call) => call.supported).map((call) => call.call),
|
|
308
368
|
...(options.environment !== undefined ? { environment: options.environment } : {}),
|
|
309
369
|
...(options.fetch !== undefined ? { fetch: options.fetch } : {}),
|
|
310
370
|
log,
|
|
@@ -526,7 +586,7 @@ export async function startHookModule(options: StartHookModuleOptions): Promise<
|
|
|
526
586
|
try {
|
|
527
587
|
await start()
|
|
528
588
|
} catch (error) {
|
|
529
|
-
const why = `hooks module ${label} failed to load: ${toErrorMessage(error)}`
|
|
589
|
+
const why = withRecovery(`hooks module ${label} failed to load: ${toErrorMessage(error)}`)
|
|
530
590
|
unload(why)
|
|
531
591
|
return { kind: 'failed', message: why }
|
|
532
592
|
}
|
|
@@ -574,20 +634,6 @@ export async function startHookModule(options: StartHookModuleOptions): Promise<
|
|
|
574
634
|
}
|
|
575
635
|
|
|
576
636
|
// --- the hooks ---------------------------------------------------------
|
|
577
|
-
const commandLabel = `module ${label}`
|
|
578
|
-
const failurePolicy = (event: ShellHookEvent, why: string): PluginHookResult => {
|
|
579
|
-
log.warn('Hooks module hook failed', {
|
|
580
|
-
...attrs,
|
|
581
|
-
'namzu.hook.event': event,
|
|
582
|
-
'namzu.hook_module.reason': why,
|
|
583
|
-
})
|
|
584
|
-
const line = `${commandLabel}: ${why}`
|
|
585
|
-
// A guard that failed does not wave the call through: the call is refused and the model is told why.
|
|
586
|
-
if (event === 'pre_tool_use') return { action: 'error', message: line }
|
|
587
|
-
if (event === 'pre_skill_shell_command') return { action: 'skip', reason: line }
|
|
588
|
-
return { action: 'continue', notice: line }
|
|
589
|
-
}
|
|
590
|
-
|
|
591
637
|
const hooks: PluginHookDefinition[] = []
|
|
592
638
|
for (const event of MODULE_HOOK_EVENTS) {
|
|
593
639
|
if (!runnable.has(event)) continue
|
|
@@ -595,7 +641,11 @@ export async function startHookModule(options: StartHookModuleOptions): Promise<
|
|
|
595
641
|
hooks.push({
|
|
596
642
|
event,
|
|
597
643
|
handler: async (context: PluginHookContext): Promise<PluginHookResult> => {
|
|
598
|
-
if (status === 'unloaded')
|
|
644
|
+
if (status === 'unloaded') {
|
|
645
|
+
// A module that never loaded guards nothing, so a guarding event is answered as a failed guard is.
|
|
646
|
+
if (disposed || !guards.has(event)) return { action: 'continue' }
|
|
647
|
+
return failurePolicy(event, message ?? `hooks module ${label} is not loaded`)
|
|
648
|
+
}
|
|
599
649
|
const input = shellHookInputFor(event, context, options.shell, { toolNames: 'written' })
|
|
600
650
|
const payload = JSON.parse(shellHookPayload(input)) as Record<string, unknown>
|
|
601
651
|
const e = event === 'pre_tool_use' ? toolEnvelope(payload) : payload
|
|
@@ -603,9 +653,9 @@ export async function startHookModule(options: StartHookModuleOptions): Promise<
|
|
|
603
653
|
try {
|
|
604
654
|
await start()
|
|
605
655
|
} catch (error) {
|
|
606
|
-
const why = `hooks module ${label} failed to load: ${toErrorMessage(error)}`
|
|
656
|
+
const why = withRecovery(`hooks module ${label} failed to load: ${toErrorMessage(error)}`)
|
|
607
657
|
unload(why)
|
|
608
|
-
return { action: 'continue', notice: why }
|
|
658
|
+
return guards.has(event) ? failurePolicy(event, why) : { action: 'continue', notice: why }
|
|
609
659
|
}
|
|
610
660
|
const registrations: number[] = []
|
|
611
661
|
for (const [index, events] of registrationEvents.entries()) {
|
|
@@ -642,6 +692,7 @@ export async function startHookModule(options: StartHookModuleOptions): Promise<
|
|
|
642
692
|
},
|
|
643
693
|
hooks,
|
|
644
694
|
dispose: async () => {
|
|
695
|
+
disposed = true
|
|
645
696
|
status = 'unloaded'
|
|
646
697
|
await endWorker('the hooks worker was stopped')
|
|
647
698
|
},
|
|
@@ -47,6 +47,8 @@ export type { CapabilityBridge, CapabilityBridgeOptions } from './capabilities.j
|
|
|
47
47
|
export {
|
|
48
48
|
hookModuleConsentEntry,
|
|
49
49
|
hookModuleConsentLines,
|
|
50
|
+
hookModuleRecovery,
|
|
50
51
|
summarizeHookModule,
|
|
52
|
+
withHookModuleRecovery,
|
|
51
53
|
} from './consent.js'
|
|
52
54
|
export type { HookModuleConsentEntry, HookModuleSummary } from './consent.js'
|
|
@@ -271,9 +271,9 @@ function walk(
|
|
|
271
271
|
parents.pop()
|
|
272
272
|
}
|
|
273
273
|
|
|
274
|
-
function isFunctionNode(node: AnyNode | undefined): boolean {
|
|
274
|
+
function isFunctionNode(node: AnyNode | null | undefined): boolean {
|
|
275
275
|
return (
|
|
276
|
-
node
|
|
276
|
+
node != null &&
|
|
277
277
|
(node.type === 'FunctionDeclaration' ||
|
|
278
278
|
node.type === 'FunctionExpression' ||
|
|
279
279
|
node.type === 'ArrowFunctionExpression')
|
|
@@ -831,6 +831,66 @@ interface Edit {
|
|
|
831
831
|
* file's neighbours, exports become assignments, and nothing else changes, so a
|
|
832
832
|
* line number in an error is the line in the author's file.
|
|
833
833
|
*/
|
|
834
|
+
/** The wrapper the worker compiles around a file's text, character for character. */
|
|
835
|
+
export const WORKER_WRAPPER_HEAD = '(function (__exports, __import) {"use strict";'
|
|
836
|
+
export const WORKER_WRAPPER_TAIL = '\n})'
|
|
837
|
+
|
|
838
|
+
type Spans = { type: string; start: number; end: number }[]
|
|
839
|
+
|
|
840
|
+
/**
|
|
841
|
+
* The tokens the parser itself consumed, not the standalone tokenizer's: the
|
|
842
|
+
* tokenizer guesses whether `/` opens a regular expression from the token
|
|
843
|
+
* before it, and the parser reads it again where the grammar says an expression
|
|
844
|
+
* starts, so the two disagree after `)`, `}` and a few keywords. Throws when the
|
|
845
|
+
* text does not parse as the given kind.
|
|
846
|
+
*/
|
|
847
|
+
function tokenSpans(text: string, sourceType: 'module' | 'script'): Spans {
|
|
848
|
+
const spans: Spans = []
|
|
849
|
+
acorn.parse(text, {
|
|
850
|
+
ecmaVersion: 'latest',
|
|
851
|
+
sourceType,
|
|
852
|
+
onToken: (token) => {
|
|
853
|
+
spans.push({ type: token.type.label, start: token.start, end: token.end })
|
|
854
|
+
},
|
|
855
|
+
})
|
|
856
|
+
return spans
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
/**
|
|
860
|
+
* The scan parses a module; the worker compiles a script, and a script reads
|
|
861
|
+
* `<!--` and a line-start `-->` as comments. Read the exact text the worker
|
|
862
|
+
* compiles both ways: where the two token lists differ, something is code to
|
|
863
|
+
* one reader and a comment to the other. Returns the line of the first
|
|
864
|
+
* difference, 0 for none, and -1 when the text cannot be tokenized.
|
|
865
|
+
*/
|
|
866
|
+
export function htmlCommentDivergence(source: string): number {
|
|
867
|
+
const text = WORKER_WRAPPER_HEAD + source + WORKER_WRAPPER_TAIL
|
|
868
|
+
let asModule: Spans
|
|
869
|
+
let asScript: Spans
|
|
870
|
+
try {
|
|
871
|
+
asModule = tokenSpans(text, 'module')
|
|
872
|
+
asScript = tokenSpans(text, 'script')
|
|
873
|
+
} catch {
|
|
874
|
+
return -1
|
|
875
|
+
}
|
|
876
|
+
const length = Math.min(asModule.length, asScript.length)
|
|
877
|
+
let at = -1
|
|
878
|
+
for (let i = 0; i < length; i++) {
|
|
879
|
+
const a = asModule[i] as Spans[number]
|
|
880
|
+
const b = asScript[i] as Spans[number]
|
|
881
|
+
if (a.type !== b.type || a.start !== b.start || a.end !== b.end) {
|
|
882
|
+
at = Math.min(a.start, b.start)
|
|
883
|
+
break
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
if (at === -1 && asModule.length === asScript.length) return 0
|
|
887
|
+
if (at === -1) {
|
|
888
|
+
const longer = asModule.length > asScript.length ? asModule : asScript
|
|
889
|
+
at = (longer[length] as Spans[number]).start
|
|
890
|
+
}
|
|
891
|
+
return text.slice(0, at).split('\n').length
|
|
892
|
+
}
|
|
893
|
+
|
|
834
894
|
function rewrite(code: string, ast: AnyNode, resolved: ReadonlyMap<string, string>): string {
|
|
835
895
|
const edits: Edit[] = []
|
|
836
896
|
const prelude: string[] = []
|
|
@@ -979,9 +1039,21 @@ export function scanHookModule(root: string, entry: string): HookModuleScan {
|
|
|
979
1039
|
const target = resolveImport(state, rel, item.specifier)
|
|
980
1040
|
if (target !== undefined) resolved.set(item.specifier, target)
|
|
981
1041
|
}
|
|
982
|
-
|
|
1042
|
+
const text = rewrite(analysis.code, analysis.ast, resolved)
|
|
1043
|
+
const divergence = htmlCommentDivergence(text)
|
|
1044
|
+
if (divergence !== 0) {
|
|
1045
|
+
refuse(
|
|
1046
|
+
state,
|
|
1047
|
+
rel,
|
|
1048
|
+
Math.max(divergence, 1),
|
|
1049
|
+
divergence < 0
|
|
1050
|
+
? `${rel}: the text cannot be read the way it will run.`
|
|
1051
|
+
: `${rel}: a <!-- or --> that the module reads as code and the runtime reads as a comment (line ${divergence}).`,
|
|
1052
|
+
)
|
|
1053
|
+
}
|
|
1054
|
+
files[rel] = text
|
|
983
1055
|
}
|
|
984
|
-
program = { entry: entryRel, files }
|
|
1056
|
+
if (state.refusals.length === 0) program = { entry: entryRel, files }
|
|
985
1057
|
}
|
|
986
1058
|
const calls = state.calls.map((call, index) => {
|
|
987
1059
|
const at = state.callStarts[index]
|