@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
|
@@ -21,6 +21,7 @@ import type {
|
|
|
21
21
|
MCPRequestOptions,
|
|
22
22
|
MCPResource,
|
|
23
23
|
MCPResourceTemplate,
|
|
24
|
+
MCPRoot,
|
|
24
25
|
MCPServerCapabilities,
|
|
25
26
|
MCPToolDefinition,
|
|
26
27
|
MCPToolResult,
|
|
@@ -381,7 +382,29 @@ export class MCPClient {
|
|
|
381
382
|
* to avoid cutting a call this client would have kept alive.
|
|
382
383
|
*/
|
|
383
384
|
getToolCallWindowMs(): number | undefined {
|
|
384
|
-
|
|
385
|
+
const fixed = this.config.toolCallTimeoutMs
|
|
386
|
+
if (!this.resetTimeoutOnProgress) return fixed
|
|
387
|
+
return fixed === undefined ? this.maxTotalTimeoutMs : Math.max(fixed, this.maxTotalTimeoutMs)
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/** The deadline a request of this method holds, when nothing extends it. */
|
|
391
|
+
private fixedDeadlineMs(method: string): number {
|
|
392
|
+
return method === 'tools/call' && this.config.toolCallTimeoutMs !== undefined
|
|
393
|
+
? this.config.toolCallTimeoutMs
|
|
394
|
+
: this.requestTimeoutMs
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Tell the server its roots changed. A no-op until connected, on a modern
|
|
399
|
+
* connection (which has no such notification) or when no `roots` were given.
|
|
400
|
+
*/
|
|
401
|
+
notifyRootsChanged(): void {
|
|
402
|
+
if (!this.config.roots || !this.isConnected() || this.era?.kind !== 'legacy') return
|
|
403
|
+
void this.notify('notifications/roots/list_changed', {}).catch((err) => {
|
|
404
|
+
this.log.debug('Failed to send roots/list_changed', {
|
|
405
|
+
'exception.message': toErrorMessage(err),
|
|
406
|
+
})
|
|
407
|
+
})
|
|
385
408
|
}
|
|
386
409
|
|
|
387
410
|
constructor(config: MCPClientConfig) {
|
|
@@ -390,6 +413,9 @@ export class MCPClient {
|
|
|
390
413
|
config.requestTimeoutMs ?? DEFAULT_MCP_REQUEST_TIMEOUT_MS,
|
|
391
414
|
'MCPClient requestTimeoutMs',
|
|
392
415
|
)
|
|
416
|
+
if (config.toolCallTimeoutMs !== undefined) {
|
|
417
|
+
validateConnectorTimeoutMs(config.toolCallTimeoutMs, 'MCPClient toolCallTimeoutMs')
|
|
418
|
+
}
|
|
393
419
|
this.resetTimeoutOnProgress = config.resetTimeoutOnProgress === true
|
|
394
420
|
const maxTotal = validateConnectorTimeoutMs(
|
|
395
421
|
config.maxTotalTimeoutMs ??
|
|
@@ -523,6 +549,7 @@ export class MCPClient {
|
|
|
523
549
|
capabilities: {
|
|
524
550
|
...(this.config.capabilities ?? {}),
|
|
525
551
|
...(this.config.onElicitation ? { elicitation: {} } : {}),
|
|
552
|
+
...(this.config.roots ? { roots: { listChanged: true } } : {}),
|
|
526
553
|
},
|
|
527
554
|
clientInfo: this.config.clientInfo ?? NAMZU_CLIENT_INFO,
|
|
528
555
|
})) as MCPInitializeResult
|
|
@@ -1224,7 +1251,8 @@ export class MCPClient {
|
|
|
1224
1251
|
this.taskWaits.add(wait)
|
|
1225
1252
|
const extendable = this.resetTimeoutOnProgress && options?.onProgress !== undefined
|
|
1226
1253
|
const started = Date.now()
|
|
1227
|
-
const totalDeadline =
|
|
1254
|
+
const totalDeadline =
|
|
1255
|
+
started + (extendable ? this.maxTotalTimeoutMs : this.fixedDeadlineMs('tools/call'))
|
|
1228
1256
|
let lastChange = started
|
|
1229
1257
|
let reports = 0
|
|
1230
1258
|
let seen: string | undefined
|
|
@@ -1903,7 +1931,12 @@ export class MCPClient {
|
|
|
1903
1931
|
|
|
1904
1932
|
this.pendingRequests.set(id, entry)
|
|
1905
1933
|
const expire = (deadline: 'request' | 'idle' | 'total_cap'): void => {
|
|
1906
|
-
const limit =
|
|
1934
|
+
const limit =
|
|
1935
|
+
deadline === 'total_cap'
|
|
1936
|
+
? this.maxTotalTimeoutMs
|
|
1937
|
+
: deadline === 'request'
|
|
1938
|
+
? this.fixedDeadlineMs(method)
|
|
1939
|
+
: this.requestTimeoutMs
|
|
1907
1940
|
const what =
|
|
1908
1941
|
deadline === 'request'
|
|
1909
1942
|
? `timed out after ${limit}ms`
|
|
@@ -1922,7 +1955,10 @@ export class MCPClient {
|
|
|
1922
1955
|
}
|
|
1923
1956
|
const armIdle = (): void => {
|
|
1924
1957
|
clearTimeout(idleTimer)
|
|
1925
|
-
idleTimer = setTimeout(
|
|
1958
|
+
idleTimer = setTimeout(
|
|
1959
|
+
() => expire(extendable ? 'idle' : 'request'),
|
|
1960
|
+
extendable ? this.requestTimeoutMs : this.fixedDeadlineMs(method),
|
|
1961
|
+
)
|
|
1926
1962
|
}
|
|
1927
1963
|
if (progressToken !== undefined && options?.onProgress) {
|
|
1928
1964
|
this.progressRequests.set(progressToken, {
|
|
@@ -2219,6 +2255,27 @@ export class MCPClient {
|
|
|
2219
2255
|
})
|
|
2220
2256
|
return
|
|
2221
2257
|
}
|
|
2258
|
+
if (
|
|
2259
|
+
message.method === 'roots/list' &&
|
|
2260
|
+
message.id !== undefined &&
|
|
2261
|
+
this.config.roots &&
|
|
2262
|
+
this.era?.kind === 'legacy'
|
|
2263
|
+
) {
|
|
2264
|
+
let roots: readonly MCPRoot[] = []
|
|
2265
|
+
try {
|
|
2266
|
+
roots = this.config.roots()
|
|
2267
|
+
} catch (err) {
|
|
2268
|
+
this.log.debug('Roots provider failed', { 'exception.message': toErrorMessage(err) })
|
|
2269
|
+
}
|
|
2270
|
+
void this.transport
|
|
2271
|
+
.send({ jsonrpc: '2.0', id: message.id, result: { roots: [...roots] } })
|
|
2272
|
+
.catch((err) => {
|
|
2273
|
+
this.log.debug('Failed to send roots/list reply', {
|
|
2274
|
+
'exception.message': toErrorMessage(err),
|
|
2275
|
+
})
|
|
2276
|
+
})
|
|
2277
|
+
return
|
|
2278
|
+
}
|
|
2222
2279
|
if (message.method && message.id !== undefined) {
|
|
2223
2280
|
this.log.warn('Declining unsupported server-initiated MCP request', {
|
|
2224
2281
|
'namzu.connector.server': this.config.serverName,
|
|
@@ -162,6 +162,98 @@ export function isPrivateAddress(address: string): boolean {
|
|
|
162
162
|
return false
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
+
/**
|
|
166
|
+
* Why `hostname` may not be fetched because of where it points, or `undefined`
|
|
167
|
+
* when every address it resolves to is outside the host's own network.
|
|
168
|
+
*
|
|
169
|
+
* The same check {@link GuardedFetchProvider} makes, for a caller that does its
|
|
170
|
+
* own fetching (a plugin download, a hook module's `$.http.fetch`) and so
|
|
171
|
+
* walks its own redirects: call it for the first address and for every hop.
|
|
172
|
+
* It fails closed: a name that cannot be resolved, or resolves to nothing, is
|
|
173
|
+
* refused, since the fetch that follows would resolve it again for real.
|
|
174
|
+
*/
|
|
175
|
+
export async function privateAddressProblem(
|
|
176
|
+
hostname: string,
|
|
177
|
+
options: {
|
|
178
|
+
readonly resolve?: (hostname: string, signal?: AbortSignal) => Promise<readonly string[]>
|
|
179
|
+
readonly signal?: AbortSignal
|
|
180
|
+
/**
|
|
181
|
+
* The request goes out through a proxy, which resolves the name itself: this machine failing
|
|
182
|
+
* to resolve it says nothing about where it points, so that failure is not a refusal. A name
|
|
183
|
+
* that does resolve here is still checked, and a literal address always is.
|
|
184
|
+
*/
|
|
185
|
+
readonly proxied?: boolean
|
|
186
|
+
} = {},
|
|
187
|
+
): Promise<string | undefined> {
|
|
188
|
+
const name = hostname.toLowerCase().replace(/^\[|\]$/g, '')
|
|
189
|
+
let addresses: readonly string[]
|
|
190
|
+
if (isIP(name) !== 0) {
|
|
191
|
+
addresses = [name]
|
|
192
|
+
} else {
|
|
193
|
+
const resolve =
|
|
194
|
+
options.resolve ??
|
|
195
|
+
(async (value: string) => (await lookup(value, { all: true })).map((r) => r.address))
|
|
196
|
+
try {
|
|
197
|
+
addresses = await resolve(name, options.signal)
|
|
198
|
+
} catch (error) {
|
|
199
|
+
if (options.proxied === true && !options.signal?.aborted) return undefined
|
|
200
|
+
return `${name} could not be resolved (${error instanceof Error ? error.message : String(error)}), so nothing here can say where it points`
|
|
201
|
+
}
|
|
202
|
+
if (addresses.length === 0) return `${name} resolves to no addresses`
|
|
203
|
+
}
|
|
204
|
+
for (const address of addresses) {
|
|
205
|
+
if (isPrivateAddress(address))
|
|
206
|
+
return `${name} resolves to ${address}, inside this host's own network`
|
|
207
|
+
}
|
|
208
|
+
return undefined
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** Whether a proxy variable holds an http or https proxy address (what the client library uses). */
|
|
212
|
+
function usableProxy(value: string | undefined): boolean {
|
|
213
|
+
const text = (value ?? '').trim()
|
|
214
|
+
if (text === '') return false
|
|
215
|
+
try {
|
|
216
|
+
const url = new URL(/^[a-z][a-z0-9+.-]*:\/\//i.test(text) ? text : `http://${text}`)
|
|
217
|
+
return (url.protocol === 'http:' || url.protocol === 'https:') && url.hostname !== ''
|
|
218
|
+
} catch {
|
|
219
|
+
return false
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** Whether `host` is on the `NO_PROXY` list of the environment (`*`, a name, or a dotted suffix). */
|
|
224
|
+
function bypassesProxy(env: NodeJS.ProcessEnv, host: string): boolean {
|
|
225
|
+
const bare = host
|
|
226
|
+
.toLowerCase()
|
|
227
|
+
.replace(/^\[|\]$/g, '')
|
|
228
|
+
.replace(/\.+$/, '')
|
|
229
|
+
const lists = [env.NO_PROXY, env.no_proxy].filter((v): v is string => typeof v === 'string')
|
|
230
|
+
for (const list of lists) {
|
|
231
|
+
for (const raw of list.split(',')) {
|
|
232
|
+
const entry = raw.trim().toLowerCase().replace(/:\d+$/, '')
|
|
233
|
+
if (entry === '') continue
|
|
234
|
+
if (entry === '*') return true
|
|
235
|
+
const name = entry.replace(/^\*?\./, '')
|
|
236
|
+
if (bare === name || bare.endsWith(`.${name}`)) return true
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return false
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Whether a web request to `host` goes through a proxy: `HTTPS_PROXY` or `HTTP_PROXY` (either case)
|
|
244
|
+
* holds an http or https address and `NO_PROXY` does not name the host. These are the variables
|
|
245
|
+
* the CLI's own connection setup reads, so a value it ignores (a socks address, `ALL_PROXY`) does
|
|
246
|
+
* not count. Behind a proxy the proxy resolves names, so {@link privateAddressProblem} is told
|
|
247
|
+
* (`proxied`) not to treat a name this machine cannot resolve as unsafe; the check is then limited
|
|
248
|
+
* to literal addresses and to names this machine can resolve. Without `host`, `NO_PROXY` is not
|
|
249
|
+
* consulted.
|
|
250
|
+
*/
|
|
251
|
+
export function proxyConfigured(env: NodeJS.ProcessEnv = process.env, host?: string): boolean {
|
|
252
|
+
const set = [env.HTTPS_PROXY, env.https_proxy, env.HTTP_PROXY, env.http_proxy].some(usableProxy)
|
|
253
|
+
if (!set) return false
|
|
254
|
+
return host === undefined || !bypassesProxy(env, host)
|
|
255
|
+
}
|
|
256
|
+
|
|
165
257
|
/** A canonical IPv6 address (as `new URL` writes it, no dots) as its eight 16-bit groups. */
|
|
166
258
|
function expandHextets(canonical: string): number[] {
|
|
167
259
|
const [head = '', tail] = canonical.split('::')
|
|
@@ -2,7 +2,12 @@
|
|
|
2
2
|
// rules are about the network and the same everywhere; searching is not,
|
|
3
3
|
// and ships with no vendor. See `types.ts` for why that asymmetry is the
|
|
4
4
|
// design rather than an omission.
|
|
5
|
-
export {
|
|
5
|
+
export {
|
|
6
|
+
GuardedFetchProvider,
|
|
7
|
+
isPrivateAddress,
|
|
8
|
+
privateAddressProblem,
|
|
9
|
+
proxyConfigured,
|
|
10
|
+
} from './guarded-fetch.js'
|
|
6
11
|
export type { GuardedFetchConfig } from './guarded-fetch.js'
|
|
7
12
|
export { WebFetchRefusedError } from './types.js'
|
|
8
13
|
export type {
|
|
@@ -112,6 +112,14 @@ export interface WebContentExtractor {
|
|
|
112
112
|
export interface WebSearchRequest {
|
|
113
113
|
readonly query: string
|
|
114
114
|
readonly limit?: number
|
|
115
|
+
/**
|
|
116
|
+
* Only results from these domains (a domain also covers its subdomains).
|
|
117
|
+
* `web_search` filters the hits itself as well, so a backend that cannot
|
|
118
|
+
* filter may ignore this; one that can saves a round of over-fetching.
|
|
119
|
+
*/
|
|
120
|
+
readonly allowedDomains?: readonly string[]
|
|
121
|
+
/** Never results from these domains (a domain also covers its subdomains). Same contract as `allowedDomains`. */
|
|
122
|
+
readonly blockedDomains?: readonly string[]
|
|
115
123
|
readonly signal?: AbortSignal
|
|
116
124
|
}
|
|
117
125
|
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// because both mutate file content.
|
|
6
6
|
export const READ_TOOLS = new Set(['read'])
|
|
7
7
|
|
|
8
|
-
export const EDIT_TOOLS = new Set(['write', 'edit'])
|
|
8
|
+
export const EDIT_TOOLS = new Set(['write', 'edit', 'notebook_edit'])
|
|
9
9
|
|
|
10
10
|
export const SHELL_TOOLS = new Set(['bash'])
|
|
11
11
|
|
|
@@ -27,21 +27,25 @@ async function main() {
|
|
|
27
27
|
let sliceStart = 0
|
|
28
28
|
let cpuUsed = 0
|
|
29
29
|
let interrupted = false
|
|
30
|
+
// Slices are timed on the monotonic sub-millisecond clock. Date.now() is
|
|
31
|
+
// whole milliseconds: a slice of 32 microtasks lasts a few microseconds, so
|
|
32
|
+
// its start and end read the same value and add 0 to the total, and a loop
|
|
33
|
+
// of such slices can run forever without the total ever growing.
|
|
34
|
+
const clock = () => performance.now()
|
|
30
35
|
function inSlice(fn) {
|
|
31
36
|
if (!cpu) return fn()
|
|
32
|
-
if (sliceDepth === 0) sliceStart =
|
|
37
|
+
if (sliceDepth === 0) sliceStart = clock()
|
|
33
38
|
sliceDepth++
|
|
34
39
|
try { return fn() }
|
|
35
40
|
finally {
|
|
36
41
|
sliceDepth--
|
|
37
|
-
if (sliceDepth === 0) cpuUsed +=
|
|
42
|
+
if (sliceDepth === 0) cpuUsed += clock() - sliceStart
|
|
38
43
|
}
|
|
39
44
|
}
|
|
40
45
|
runtime.setInterruptHandler(() => {
|
|
41
|
-
const now = Date.now()
|
|
42
46
|
const stop = cpu
|
|
43
|
-
? sliceDepth > 0 && (
|
|
44
|
-
: now >= workerData.deadline
|
|
47
|
+
? sliceDepth > 0 && (clock() - sliceStart >= cpu.sliceMs || cpuUsed + (clock() - sliceStart) >= cpu.totalMs)
|
|
48
|
+
: Date.now() >= workerData.deadline
|
|
45
49
|
if (stop) interrupted = true
|
|
46
50
|
return stop
|
|
47
51
|
})
|
package/src/execution/local.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { existsSync } from 'node:fs'
|
|
|
3
3
|
import { resolve } from 'node:path'
|
|
4
4
|
import { killTree } from '../process/kill-tree.js'
|
|
5
5
|
import { withSessionChildMarker } from '../process/session-child.js'
|
|
6
|
+
import { isGitProgram, withHostGitConfig, withSafeGitConfig } from '../tools/git-config-env.js'
|
|
6
7
|
import type { LocalExecutionContextConfig } from '../types/connector/index.js'
|
|
7
8
|
import type {
|
|
8
9
|
CommandExecutor,
|
|
@@ -162,7 +163,11 @@ export class LocalExecutionContext extends BaseExecutionContext implements Comma
|
|
|
162
163
|
}
|
|
163
164
|
|
|
164
165
|
const cwd = options?.cwd ? resolve(this.cwd, options.cwd) : this.cwd
|
|
165
|
-
|
|
166
|
+
// Git the host starts itself gets the full hardening; any other command only
|
|
167
|
+
// the part that keeps a git it starts from reading a folder that merely looks
|
|
168
|
+
// like a repository. Applied last so a caller's own entries are appended to.
|
|
169
|
+
const merged = withSessionChildMarker({ ...process.env, ...this.envVars, ...options?.env })
|
|
170
|
+
const env = isGitProgram(command) ? withHostGitConfig(merged) : withSafeGitConfig(merged)
|
|
166
171
|
const timeoutMs = options?.timeoutMs ?? LOCAL_COMMAND_DEFAULT_TIMEOUT_MS
|
|
167
172
|
if (!Number.isInteger(timeoutMs) || timeoutMs < 0) {
|
|
168
173
|
throw new RangeError(
|
package/src/peers/index.ts
CHANGED
|
@@ -25,8 +25,14 @@ export {
|
|
|
25
25
|
} from './dir.js'
|
|
26
26
|
export type { HardenPeerDirectory, PeerRuntimeDir, ResolvePeerRuntimeDirOptions } from './dir.js'
|
|
27
27
|
|
|
28
|
-
export {
|
|
29
|
-
|
|
28
|
+
export {
|
|
29
|
+
derivePeerRef,
|
|
30
|
+
PEER_AGENTS_MAX,
|
|
31
|
+
PEER_RECORD_VERSION,
|
|
32
|
+
PEER_TRAIL_MAX,
|
|
33
|
+
PeerRecordSchema,
|
|
34
|
+
} from './record.js'
|
|
35
|
+
export type { PeerAgentNode, PeerExchange, PeerRecord } from './record.js'
|
|
30
36
|
|
|
31
37
|
export {
|
|
32
38
|
isPeerRecordLive,
|
package/src/peers/record.ts
CHANGED
|
@@ -41,6 +41,31 @@ export type PeerExchange = z.infer<typeof PeerExchangeSchema>
|
|
|
41
41
|
/** The most recent exchanges a record keeps, newest last. A burst between two reads of a record is not lost for four or fewer. */
|
|
42
42
|
export const PEER_TRAIL_MAX = 4
|
|
43
43
|
|
|
44
|
+
/** The most agent rows a record carries; a session with more says nothing about the rest. */
|
|
45
|
+
export const PEER_AGENTS_MAX = 40
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* One row of a session's own agents: a workflow, an agent, a teammate or a background shell
|
|
49
|
+
* task, flat with the id of its parent (a workflow's agents name the workflow). A host that
|
|
50
|
+
* draws the tree needs a state, a name, one line of detail and a start time and nothing else:
|
|
51
|
+
* never a prompt, a transcript or a command's output.
|
|
52
|
+
*/
|
|
53
|
+
export const PeerAgentNodeSchema = z
|
|
54
|
+
.object({
|
|
55
|
+
id: z.string().min(1).max(64),
|
|
56
|
+
/** Absent for a row directly under the session. */
|
|
57
|
+
parent: z.string().min(1).max(64).optional(),
|
|
58
|
+
kind: z.enum(['workflow', 'agent', 'teammate', 'task']),
|
|
59
|
+
state: z.enum(['needs-you', 'working', 'finished', 'idle', 'failed', 'stopped']),
|
|
60
|
+
name: z.string().max(80),
|
|
61
|
+
detail: z.string().max(160).optional(),
|
|
62
|
+
/** When it started or last changed state (epoch ms); the host shows its age. */
|
|
63
|
+
since: z.number().int().nonnegative(),
|
|
64
|
+
})
|
|
65
|
+
.strict()
|
|
66
|
+
|
|
67
|
+
export type PeerAgentNode = z.infer<typeof PeerAgentNodeSchema>
|
|
68
|
+
|
|
44
69
|
export const PeerRecordSchema = z
|
|
45
70
|
.object({
|
|
46
71
|
v: z.literal(PEER_RECORD_VERSION),
|
|
@@ -73,6 +98,10 @@ export const PeerRecordSchema = z
|
|
|
73
98
|
limitedUntil: z.number().int().positive().optional(),
|
|
74
99
|
/** The latest exchanges with other terminals, newest last; absent for a terminal that has had none or does not report them. */
|
|
75
100
|
trail: z.array(PeerExchangeSchema).max(PEER_TRAIL_MAX).optional(),
|
|
101
|
+
/** The session's own agents, workflows, teammates and background tasks, for a host that draws them as a tree; written inside a workspaces host, or in a plain terminal after its first left arrow, at most once a second. */
|
|
102
|
+
agents: z.array(PeerAgentNodeSchema).max(PEER_AGENTS_MAX).optional(),
|
|
103
|
+
/** One line of what the session is on: the question it waits on, else the last line of its latest reply; at most 160 characters, never the prompt. Written where `agents` is. */
|
|
104
|
+
detail: z.string().max(160).optional(),
|
|
76
105
|
/** A role another machine (or the person) set for this session; descriptive only, never a permission. */
|
|
77
106
|
role: z.string().min(1).max(500).optional(),
|
|
78
107
|
/** The name of the machine that set the role. */
|
|
@@ -87,7 +116,22 @@ export const PeerRecordSchema = z
|
|
|
87
116
|
* a newer build (extra optional fields) stays visible to an older reader.
|
|
88
117
|
* Writers keep using the strict `PeerRecordSchema`.
|
|
89
118
|
*/
|
|
90
|
-
export const PeerRecordReaderSchema = PeerRecordSchema.
|
|
119
|
+
export const PeerRecordReaderSchema = PeerRecordSchema.extend({
|
|
120
|
+
// A list that does not fit its schema drops only the list, never the whole session.
|
|
121
|
+
agents: z
|
|
122
|
+
.preprocess((value) => {
|
|
123
|
+
const parsed = z.array(PeerAgentNodeSchema).max(PEER_AGENTS_MAX).safeParse(value)
|
|
124
|
+
return parsed.success ? parsed.data : undefined
|
|
125
|
+
}, z.array(PeerAgentNodeSchema).max(PEER_AGENTS_MAX).optional())
|
|
126
|
+
.optional(),
|
|
127
|
+
// A line that does not fit (too long, not a string) drops only the line, never the whole session.
|
|
128
|
+
detail: z
|
|
129
|
+
.preprocess((value) => {
|
|
130
|
+
const parsed = z.string().max(160).safeParse(value)
|
|
131
|
+
return parsed.success ? parsed.data : undefined
|
|
132
|
+
}, z.string().max(160).optional())
|
|
133
|
+
.optional(),
|
|
134
|
+
}).strip()
|
|
91
135
|
|
|
92
136
|
export type PeerRecord = z.infer<typeof PeerRecordSchema>
|
|
93
137
|
|
package/src/peers/registry.ts
CHANGED
|
@@ -68,6 +68,21 @@ export function writePeerRecord(sessionsDir: string, record: PeerRecord): void {
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
/** A record is a few KiB; a file far beyond that is not one, and is not read. */
|
|
72
|
+
const RECORD_MAX_BYTES = 256 * 1024
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The text of a record file, or `undefined` when the path is not a regular file this user owns
|
|
76
|
+
* (a link, a device, another user's file) or is over the size cap. A missing file throws ENOENT.
|
|
77
|
+
*/
|
|
78
|
+
function readRecordFile(path: string): string | undefined {
|
|
79
|
+
const info = lstatSync(path)
|
|
80
|
+
if (!info.isFile() || info.size > RECORD_MAX_BYTES) return undefined
|
|
81
|
+
const uid = typeof process.getuid === 'function' ? process.getuid() : undefined
|
|
82
|
+
if (uid !== undefined && info.uid !== uid) return undefined
|
|
83
|
+
return readFileSync(path, 'utf8')
|
|
84
|
+
}
|
|
85
|
+
|
|
71
86
|
function parseRecordText(text: string): PeerRecord | undefined {
|
|
72
87
|
let parsed: unknown
|
|
73
88
|
try {
|
|
@@ -81,14 +96,14 @@ function parseRecordText(text: string): PeerRecord | undefined {
|
|
|
81
96
|
|
|
82
97
|
/** One session's record, or `undefined` if it has none or its file does not parse. */
|
|
83
98
|
export function readPeerRecord(sessionsDir: string, sessionId: string): PeerRecord | undefined {
|
|
84
|
-
let text: string
|
|
99
|
+
let text: string | undefined
|
|
85
100
|
try {
|
|
86
|
-
text =
|
|
101
|
+
text = readRecordFile(recordPath(sessionsDir, sessionId))
|
|
87
102
|
} catch (error) {
|
|
88
103
|
if ((error as NodeJS.ErrnoException).code === 'ENOENT') return undefined
|
|
89
104
|
throw error
|
|
90
105
|
}
|
|
91
|
-
return parseRecordText(text)
|
|
106
|
+
return text === undefined ? undefined : parseRecordText(text)
|
|
92
107
|
}
|
|
93
108
|
|
|
94
109
|
/**
|
|
@@ -109,12 +124,13 @@ export function readPeerRecords(sessionsDir: string): PeerRecord[] {
|
|
|
109
124
|
const records: PeerRecord[] = []
|
|
110
125
|
for (const entry of entries) {
|
|
111
126
|
if (!entry.endsWith('.json')) continue
|
|
112
|
-
let text: string
|
|
127
|
+
let text: string | undefined
|
|
113
128
|
try {
|
|
114
|
-
text =
|
|
129
|
+
text = readRecordFile(join(sessionsDir, entry))
|
|
115
130
|
} catch {
|
|
116
131
|
continue // Vanished between readdir and read; not this reader's concern.
|
|
117
132
|
}
|
|
133
|
+
if (text === undefined) continue
|
|
118
134
|
const record = parseRecordText(text)
|
|
119
135
|
if (record) records.push(record)
|
|
120
136
|
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { existsSync, lstatSync, readdirSync, realpathSync } from 'node:fs'
|
|
2
|
+
import { delimiter, isAbsolute, join, relative } from 'node:path'
|
|
3
|
+
import { readEnvironmentEntry, setEnvironmentEntry } from '../utils/process-environment.js'
|
|
4
|
+
|
|
5
|
+
/** What a plugin's `bin/` folder came to: a folder to put on PATH, or the reason it is not. */
|
|
6
|
+
export type PluginBinResolution =
|
|
7
|
+
| { readonly dir: string }
|
|
8
|
+
| { readonly dir?: undefined; readonly refused: string }
|
|
9
|
+
|
|
10
|
+
function inside(root: string, candidate: string): boolean {
|
|
11
|
+
const rel = relative(root, candidate)
|
|
12
|
+
return rel !== '' && !rel.startsWith('..') && !isAbsolute(rel)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// A folder whose name could be read by a shell as more than a path is left off.
|
|
16
|
+
const UNSAFE_PATH_CHARACTERS = /[:"'$`\\\n\r;]/u
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The folder of a plugin's programs, when it is safe to put on a shell's PATH.
|
|
20
|
+
*
|
|
21
|
+
* Nothing here reads a file's contents. A plugin without a `bin/` folder is
|
|
22
|
+
* simply absent (undefined). A `bin/` that is a link leaving the plugin, or
|
|
23
|
+
* that holds a link leaving the plugin, is refused whole: PATH lookup follows
|
|
24
|
+
* links, so one such entry would run a program the install never listed.
|
|
25
|
+
*/
|
|
26
|
+
export function resolvePluginBinDirectory(rootDir: string): PluginBinResolution | undefined {
|
|
27
|
+
let realRoot: string
|
|
28
|
+
let bin: string
|
|
29
|
+
try {
|
|
30
|
+
realRoot = realpathSync(rootDir)
|
|
31
|
+
const lexical = join(realRoot, 'bin')
|
|
32
|
+
try {
|
|
33
|
+
lstatSync(lexical)
|
|
34
|
+
} catch {
|
|
35
|
+
return undefined
|
|
36
|
+
}
|
|
37
|
+
bin = realpathSync(lexical)
|
|
38
|
+
} catch {
|
|
39
|
+
return undefined
|
|
40
|
+
}
|
|
41
|
+
if (!inside(realRoot, bin)) return { refused: 'bin/ resolves outside the plugin folder' }
|
|
42
|
+
try {
|
|
43
|
+
if (!lstatSync(bin).isDirectory()) return undefined
|
|
44
|
+
} catch {
|
|
45
|
+
return undefined
|
|
46
|
+
}
|
|
47
|
+
if (UNSAFE_PATH_CHARACTERS.test(bin) || bin.includes(delimiter)) {
|
|
48
|
+
return { refused: 'the folder name holds a character a shell could read as more than a path' }
|
|
49
|
+
}
|
|
50
|
+
let entries: import('node:fs').Dirent[]
|
|
51
|
+
try {
|
|
52
|
+
entries = readdirSync(bin, { withFileTypes: true })
|
|
53
|
+
} catch {
|
|
54
|
+
return undefined
|
|
55
|
+
}
|
|
56
|
+
for (const entry of entries) {
|
|
57
|
+
if (!entry.isSymbolicLink()) continue
|
|
58
|
+
let target: string
|
|
59
|
+
try {
|
|
60
|
+
target = realpathSync(join(bin, entry.name))
|
|
61
|
+
} catch {
|
|
62
|
+
// A dangling link runs nothing now; refusing it keeps the rule simple.
|
|
63
|
+
return { refused: `bin/${entry.name} is a link that does not resolve` }
|
|
64
|
+
}
|
|
65
|
+
if (!inside(realRoot, target)) {
|
|
66
|
+
return { refused: `bin/${entry.name} is a link that leaves the plugin folder` }
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return { dir: bin }
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Add folders to the END of an environment's PATH, so a program already on
|
|
74
|
+
* PATH (a system command a permission rule or the read-only list names) always
|
|
75
|
+
* wins over a plugin's program of the same name. Folders already on PATH are
|
|
76
|
+
* not added twice. An environment without PATH is returned unchanged.
|
|
77
|
+
*/
|
|
78
|
+
export function appendDirsToPath(
|
|
79
|
+
env: Record<string, string>,
|
|
80
|
+
dirs: readonly string[],
|
|
81
|
+
platform: NodeJS.Platform = process.platform,
|
|
82
|
+
): Record<string, string> {
|
|
83
|
+
if (dirs.length === 0) return env
|
|
84
|
+
const entry = readEnvironmentEntry(env, 'PATH', platform)
|
|
85
|
+
if (!entry) return env
|
|
86
|
+
const [name, value] = entry
|
|
87
|
+
const sep = platform === 'win32' ? ';' : ':'
|
|
88
|
+
const present = new Set(value.split(sep))
|
|
89
|
+
const added = dirs.filter((dir) => !dir.includes(sep) && !present.has(dir))
|
|
90
|
+
if (added.length === 0) return env
|
|
91
|
+
setEnvironmentEntry(env, name, [value, ...added].filter(Boolean).join(sep), platform)
|
|
92
|
+
return env
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
type BinSource = { enabledBinDirs(): readonly string[] }
|
|
96
|
+
const binSources = new Set<WeakRef<BinSource>>()
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Record where the enabled plugins' bin folders come from, so a check that has
|
|
100
|
+
* no turn context (the read-only command list) can ask whether a plugin
|
|
101
|
+
* supplies a program. Held weakly: a manager that is dropped drops out.
|
|
102
|
+
*/
|
|
103
|
+
export function registerPluginBinSource(source: BinSource): void {
|
|
104
|
+
binSources.add(new WeakRef(source))
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Whether an enabled plugin's bin folder holds a program called `name`. The
|
|
109
|
+
* folders sit at the end of PATH, so on a machine that lacks a command the
|
|
110
|
+
* read-only list names (`rg`, `tree`, `jq`) the plugin's file is what runs;
|
|
111
|
+
* such a name must not be treated as read-only.
|
|
112
|
+
*/
|
|
113
|
+
export function pluginSuppliesProgram(
|
|
114
|
+
name: string,
|
|
115
|
+
platform: NodeJS.Platform = process.platform,
|
|
116
|
+
): boolean {
|
|
117
|
+
if (binSources.size === 0) return false
|
|
118
|
+
for (const ref of [...binSources]) {
|
|
119
|
+
const source = ref.deref()
|
|
120
|
+
if (source === undefined) {
|
|
121
|
+
binSources.delete(ref)
|
|
122
|
+
continue
|
|
123
|
+
}
|
|
124
|
+
let dirs: readonly string[]
|
|
125
|
+
try {
|
|
126
|
+
dirs = source.enabledBinDirs()
|
|
127
|
+
} catch {
|
|
128
|
+
// A source that cannot say is not trusted to say "none".
|
|
129
|
+
return true
|
|
130
|
+
}
|
|
131
|
+
for (const dir of dirs) {
|
|
132
|
+
try {
|
|
133
|
+
if (platform === 'win32') {
|
|
134
|
+
const want = name.toLowerCase()
|
|
135
|
+
for (const file of readdirSync(dir)) {
|
|
136
|
+
const lower = file.toLowerCase()
|
|
137
|
+
const dot = lower.lastIndexOf('.')
|
|
138
|
+
if (lower === want || (dot > 0 && lower.slice(0, dot) === want)) return true
|
|
139
|
+
}
|
|
140
|
+
} else if (existsSync(join(dir, name))) {
|
|
141
|
+
return true
|
|
142
|
+
}
|
|
143
|
+
} catch {
|
|
144
|
+
return true
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return false
|
|
149
|
+
}
|
|
@@ -249,7 +249,7 @@ function noteHookModule(root: string, out: Collector): void {
|
|
|
249
249
|
code: 'hooks-module-scan-refused',
|
|
250
250
|
field: 'hooks',
|
|
251
251
|
path: refusal.file,
|
|
252
|
-
message: `${refusal.file}:${refusal.line}: ${refusal.message}. The module does not run; its plain hook entries still load.`,
|
|
252
|
+
message: `${refusal.file}:${refusal.line}: ${refusal.message}. The module does not run, and a tool call is refused until it is fixed or the plugin is turned off; its plain hook entries still load.`,
|
|
253
253
|
})
|
|
254
254
|
}
|
|
255
255
|
if (scan.refusals.length > 0) return
|
|
@@ -278,7 +278,7 @@ function noteHookModule(root: string, out: Collector): void {
|
|
|
278
278
|
code: 'hooks-module-used',
|
|
279
279
|
field: 'hooks',
|
|
280
280
|
path: located.entry,
|
|
281
|
-
message: `${located.entry} runs in
|
|
281
|
+
message: `${located.entry} runs in a worker with your permissions (events: ${summary.events.join(', ') || 'none'}).`,
|
|
282
282
|
})
|
|
283
283
|
}
|
|
284
284
|
|
|
@@ -1080,7 +1080,7 @@ async function readMerged(
|
|
|
1080
1080
|
code: 'component-unsupported',
|
|
1081
1081
|
field: dir,
|
|
1082
1082
|
path: dir,
|
|
1083
|
-
message: `${dir}/ (${count}) is not used by Namzu
|
|
1083
|
+
message: `${dir}/ (${count}) is not used by Namzu.`,
|
|
1084
1084
|
})
|
|
1085
1085
|
}
|
|
1086
1086
|
}
|