@namzu/sdk 70.0.0 → 71.0.1
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 +123 -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.map +1 -1
- package/dist/authorization/protected-paths.js +46 -1
- 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 +108 -3
- 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/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 +1 -1
- 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/scan.d.ts +16 -0
- package/dist/plugin/hook-module/scan.d.ts.map +1 -1
- package/dist/plugin/hook-module/scan.js +67 -2
- package/dist/plugin/hook-module/scan.js.map +1 -1
- package/dist/plugin/hook-module/worker-source.d.ts.map +1 -1
- package/dist/plugin/hook-module/worker-source.js +56 -0
- 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 +8 -6
- package/dist/public-runtime.d.ts.map +1 -1
- package/dist/public-runtime.js +8 -5
- package/dist/public-runtime.js.map +1 -1
- package/dist/public-tools.d.ts +6 -2
- package/dist/public-tools.d.ts.map +1 -1
- package/dist/public-tools.js +6 -2
- 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 +60 -5
- 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.map +1 -1
- package/dist/runtime/query/review-policy.js +4 -2
- 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.d.ts +17 -0
- package/dist/skills/inline-shell.d.ts.map +1 -1
- package/dist/skills/inline-shell.js +1232 -14
- package/dist/skills/inline-shell.js.map +1 -1
- package/dist/store/session-index/index.d.ts +5 -0
- package/dist/store/session-index/index.d.ts.map +1 -1
- package/dist/store/session-index/index.js +5 -1
- package/dist/store/session-index/index.js.map +1 -1
- package/dist/store/session-index/rebuild.d.ts +18 -0
- package/dist/store/session-index/rebuild.d.ts.map +1 -1
- package/dist/store/session-index/rebuild.js +79 -5
- package/dist/store/session-index/rebuild.js.map +1 -1
- package/dist/store/session-index/sqlite.d.ts +8 -0
- package/dist/store/session-index/sqlite.d.ts.map +1 -1
- package/dist/store/session-index/sqlite.js +23 -1
- package/dist/store/session-index/sqlite.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 +28 -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/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 +6 -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 +45 -1
- package/src/authorization/readonly-commands.ts +75 -6
- package/src/authorization/readonly-flags.ts +103 -0
- package/src/authorization/shell-lexer.ts +126 -3
- 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/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 +1 -1
- package/src/plugin/common-layout-names.ts +0 -1
- package/src/plugin/hook-module/scan.ts +74 -2
- package/src/plugin/hook-module/worker-source.ts +56 -0
- 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 +21 -0
- package/src/public-tools.ts +32 -1
- 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 +79 -5
- 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 +5 -2
- 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.ts +1268 -14
- package/src/store/session-index/index.ts +10 -1
- package/src/store/session-index/rebuild.ts +81 -5
- package/src/store/session-index/sqlite.ts +30 -1
- 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 +27 -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/plugin/index.ts +10 -2
- package/src/types/tool/index.ts +6 -0
- package/src/utils/plain-terminal-text.ts +142 -0
|
@@ -27,5 +27,132 @@ export function leadingLongSleep(command: string): string | null {
|
|
|
27
27
|
|
|
28
28
|
/** What the model is told when a long leading sleep is refused. */
|
|
29
29
|
export function longSleepRefusal(what: string): string {
|
|
30
|
-
return `Blocked: ${what}.
|
|
30
|
+
return `Blocked: ${what}. Do not wait with sleeps. For a condition, run a background until-loop (\`until <check>; do sleep 2; done\`) with run_in_background: true and end your turn, you are told when it exits; for a stream of events, use monitor. Do not chain shorter sleeps to work around this block.`
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Describes a chain of two or more `sleep <seconds>` sub-commands that add up
|
|
35
|
+
* to a long wait, or `null`. A sleep inside a loop (`do sleep 2`) is not a
|
|
36
|
+
* sub-command of its own and is left alone.
|
|
37
|
+
*/
|
|
38
|
+
export function chainedSleeps(command: string): string | null {
|
|
39
|
+
const sleeps = command
|
|
40
|
+
.split(/&&|\|\||;|\||\n/)
|
|
41
|
+
.map((part) => /^\s*sleep\s+(\d+(?:\.\d*)?)\s*$/.exec(part))
|
|
42
|
+
.filter((m): m is RegExpExecArray => m !== null)
|
|
43
|
+
.map((m) => Number.parseFloat(m[1] ?? ''))
|
|
44
|
+
const total = sleeps.reduce((a, b) => a + b, 0)
|
|
45
|
+
return sleeps.length >= 2 && total >= LONG_SLEEP_SECONDS
|
|
46
|
+
? `${sleeps.length} chained sleeps adding up to ${total} seconds`
|
|
47
|
+
: null
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** A `timeout` cap at or above this many seconds is left alone: a person can finish a sign-in in it. */
|
|
51
|
+
const SIGN_IN_CAP_SECONDS = 600
|
|
52
|
+
|
|
53
|
+
/** A script or command named for a sign-in: `login`, `./login.sh`, `sign-in.mjs`. */
|
|
54
|
+
const SIGN_IN_COMMAND = /^(?:login|log-in|signin|sign-in|authenticate)(?:\.\w+)?$/i
|
|
55
|
+
|
|
56
|
+
/** A word that, as the first or second word of a command, makes it a sign-in: `gh auth`, `npm login`. */
|
|
57
|
+
const SIGN_IN_WORDS = new Set(['login', 'log-in', 'signin', 'sign-in', 'authenticate', 'auth'])
|
|
58
|
+
|
|
59
|
+
const ENV_ASSIGNMENT = /^[A-Za-z_]\w*=/
|
|
60
|
+
|
|
61
|
+
function stripQuotes(word: string): string {
|
|
62
|
+
return word.replace(/^['"]+|['"]+$/g, '')
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Seconds a `timeout` duration word names, or `null` when it is not one. */
|
|
66
|
+
function durationSeconds(word: string): number | null {
|
|
67
|
+
const m = /^(\d+(?:\.\d*)?)([smhd])?$/.exec(word)
|
|
68
|
+
if (!m) return null
|
|
69
|
+
const unit = m[2] ?? 's'
|
|
70
|
+
return (
|
|
71
|
+
Number.parseFloat(m[1] ?? '') *
|
|
72
|
+
(unit === 'd' ? 86400 : unit === 'h' ? 3600 : unit === 'm' ? 60 : 1)
|
|
73
|
+
)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* One sub-command's leading `timeout` cap and the words it runs, after
|
|
78
|
+
* `VAR=value`, `env` and `nice`-style prefixes are dropped, or `null` when it
|
|
79
|
+
* is not a capped command. `timeout`, `gtimeout` and a path to either count.
|
|
80
|
+
*/
|
|
81
|
+
function cappedWords(part: string): { seconds: number; words: string[] } | null {
|
|
82
|
+
const tokens = part.split(/\s+/).filter((token) => token !== '')
|
|
83
|
+
let i = 0
|
|
84
|
+
const skipPrefixes = (): void => {
|
|
85
|
+
for (;;) {
|
|
86
|
+
const token = tokens[i]
|
|
87
|
+
if (token === undefined) return
|
|
88
|
+
if (ENV_ASSIGNMENT.test(token)) i++
|
|
89
|
+
else if (token === 'env' || token === 'command' || token === 'exec') {
|
|
90
|
+
i++
|
|
91
|
+
while (tokens[i] !== undefined && /^-/.test(tokens[i] ?? '')) i++
|
|
92
|
+
} else return
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
skipPrefixes()
|
|
96
|
+
const name = (tokens[i] ?? '').split('/').pop()
|
|
97
|
+
if (name !== 'timeout' && name !== 'gtimeout') return null
|
|
98
|
+
i++
|
|
99
|
+
while (tokens[i] !== undefined && /^-/.test(tokens[i] ?? '')) {
|
|
100
|
+
// `-k 5` and `-s TERM` take a value; the long forms use `=`.
|
|
101
|
+
i += /^-[ks]$/.test(tokens[i] ?? '') ? 2 : 1
|
|
102
|
+
}
|
|
103
|
+
const seconds = durationSeconds(tokens[i] ?? '')
|
|
104
|
+
if (seconds === null) return null
|
|
105
|
+
i++
|
|
106
|
+
const rest = tokens.slice(i)
|
|
107
|
+
i = 0
|
|
108
|
+
// A command run through a shell: read what the quoted string starts with.
|
|
109
|
+
const words = rest.map(stripQuotes)
|
|
110
|
+
return { seconds, words }
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** Whether the words a capped command runs name a sign-in or an until-loop. */
|
|
114
|
+
function waitsForSomething(words: string[]): boolean {
|
|
115
|
+
let w = words
|
|
116
|
+
while (w[0] !== undefined && (ENV_ASSIGNMENT.test(w[0]) || w[0] === 'env')) w = w.slice(1)
|
|
117
|
+
const first = (w[0] ?? '').split('/').pop() ?? ''
|
|
118
|
+
if (first === 'until') return true
|
|
119
|
+
if (/^(?:ba|z|da)?sh$/.test(first)) {
|
|
120
|
+
const c = w.findIndex((word) => /^-\w*c$/.test(word))
|
|
121
|
+
if (c !== -1)
|
|
122
|
+
return (
|
|
123
|
+
(w[c + 1] ?? '') === 'until' ||
|
|
124
|
+
SIGN_IN_COMMAND.test((w[c + 1] ?? '').split('/').pop() ?? '')
|
|
125
|
+
)
|
|
126
|
+
}
|
|
127
|
+
if (SIGN_IN_COMMAND.test(first)) return true
|
|
128
|
+
const subs = w.slice(1, 4).filter((word) => !word.startsWith('-'))
|
|
129
|
+
return SIGN_IN_WORDS.has(subs[0] ?? '') && first !== 'timeout'
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Describes a sign-in command or an until-loop held under a `timeout` cap, or
|
|
134
|
+
* `null`. Every sub-command is read; `VAR=value`, `env` and `gtimeout` do not
|
|
135
|
+
* hide it. Only command words count: a flag (`--auth`) or a path
|
|
136
|
+
* (`/auth/health`) does not. A sign-in waits for a person, and a short cap
|
|
137
|
+
* ends it before they finish.
|
|
138
|
+
*/
|
|
139
|
+
export function cappedSignIn(command: string): string | null {
|
|
140
|
+
for (const part of command.split(/&&|\|\||;|\||\n/)) {
|
|
141
|
+
const capped = cappedWords(part.trim())
|
|
142
|
+
if (!capped || !(capped.seconds < SIGN_IN_CAP_SECONDS)) continue
|
|
143
|
+
if (waitsForSomething(capped.words))
|
|
144
|
+
return `timeout ${capped.seconds} around a command that waits`
|
|
145
|
+
}
|
|
146
|
+
return null
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* What the model is told when a sign-in command is capped by `timeout`. A
|
|
151
|
+
* background launch is told to drop the wrapper; a foreground one to move to
|
|
152
|
+
* a background job.
|
|
153
|
+
*/
|
|
154
|
+
export function cappedSignInRefusal(what: string, background = false): string {
|
|
155
|
+
return background
|
|
156
|
+
? `Blocked: ${what}. The command waits for a person or a condition, and a short cap ends it before they finish, even in the background. Start it again with run_in_background: true and no timeout wrapper, tell the person the step, then end your turn: you are told when it exits. To watch for a line it prints, use monitor.`
|
|
157
|
+
: `Blocked: ${what}. A command that asks for a sign-in waits for a person, and a short cap ends it before they finish. Run it with run_in_background: true and no timeout wrapper, tell the person the step, then end your turn: you are told when it exits. To watch for a line it prints, use monitor.`
|
|
31
158
|
}
|
|
@@ -97,7 +97,7 @@ type WaitForJobInput = z.infer<typeof inputSchema>
|
|
|
97
97
|
export const WaitForJobTool = defineTool({
|
|
98
98
|
name: 'wait_for_job',
|
|
99
99
|
description:
|
|
100
|
-
'Wait for an owned background job to exit, or set output_contains to observe an exact output marker while it stays running.
|
|
100
|
+
'Wait for an owned background job to exit, or set output_contains to observe an exact output marker while it stays running. Only for when the result is needed inside this step. Otherwise end your turn: you are told when a job exits. Never use it, or a short timeout_ms, for something that waits for a person. Output markers do not prove service health or completion and never express intent to wait until exit. A bounded wait returns output and next_offset without stopping the job; pass that cursor as from_offset to exclude earlier output.',
|
|
101
101
|
inputSchema,
|
|
102
102
|
category: 'shell',
|
|
103
103
|
permissions: ['shell_execute'],
|
|
@@ -57,8 +57,62 @@ const searchInput = z.object({
|
|
|
57
57
|
.max(25)
|
|
58
58
|
.optional()
|
|
59
59
|
.describe('How many results to return. The provider may return fewer.'),
|
|
60
|
+
allowed_domains: z
|
|
61
|
+
.array(z.string())
|
|
62
|
+
.optional()
|
|
63
|
+
.describe(
|
|
64
|
+
'Only include search results from these domains (a domain also covers its subdomains), for example ["docs.example.com"]. Cannot be combined with blocked_domains.',
|
|
65
|
+
),
|
|
66
|
+
blocked_domains: z
|
|
67
|
+
.array(z.string())
|
|
68
|
+
.optional()
|
|
69
|
+
.describe(
|
|
70
|
+
'Never include search results from these domains (a domain also covers its subdomains). Cannot be combined with allowed_domains.',
|
|
71
|
+
),
|
|
60
72
|
})
|
|
61
73
|
|
|
74
|
+
/** A domain as written by a model: a host, a URL, or `www.`/`*.` prefixed. Undefined when nothing is left. */
|
|
75
|
+
function normalizeDomain(raw: string): string | undefined {
|
|
76
|
+
let d = raw.trim().toLowerCase()
|
|
77
|
+
d = d.replace(/^[a-z][a-z0-9+.-]*:\/\//, '')
|
|
78
|
+
d = d.split(/[/?#]/, 1)[0] ?? ''
|
|
79
|
+
d = d.replace(/^[^@]*@/, '').replace(/:\d+$/, '')
|
|
80
|
+
d = d
|
|
81
|
+
.replace(/^\*\./, '')
|
|
82
|
+
.replace(/^www\./, '')
|
|
83
|
+
.replace(/\.$/, '')
|
|
84
|
+
if (d === '') return undefined
|
|
85
|
+
// The URL parser gives the same (punycode) form hostOf sees, so a Unicode
|
|
86
|
+
// domain matches the host of a result.
|
|
87
|
+
try {
|
|
88
|
+
d = new URL(`http://${d}`).hostname.replace(/\.$/, '')
|
|
89
|
+
} catch {
|
|
90
|
+
return undefined
|
|
91
|
+
}
|
|
92
|
+
return d === '' ? undefined : d
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function hostOf(url: string): string | undefined {
|
|
96
|
+
try {
|
|
97
|
+
const host = new URL(url).hostname
|
|
98
|
+
.toLowerCase()
|
|
99
|
+
.replace(/^www\./, '')
|
|
100
|
+
.replace(/\.$/, '')
|
|
101
|
+
// mailto:, file: and data: addresses have no host and cannot be shown to match a list.
|
|
102
|
+
return host === '' ? undefined : host
|
|
103
|
+
} catch {
|
|
104
|
+
return undefined
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function inDomains(host: string, domains: readonly string[]): boolean {
|
|
109
|
+
return domains.some((d) => host === d || host.endsWith(`.${d}`))
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** How many results are asked for when a filter will drop some of them. */
|
|
113
|
+
const OVERFETCH_FACTOR = 3
|
|
114
|
+
const OVERFETCH_MAX = 50
|
|
115
|
+
|
|
62
116
|
export const WEB_FETCH_TOOL_NAME = 'web_fetch'
|
|
63
117
|
export const WEB_SEARCH_TOOL_NAME = 'web_search'
|
|
64
118
|
|
|
@@ -167,6 +221,10 @@ export const WebFetchTool = defineTool({
|
|
|
167
221
|
readOnly: true,
|
|
168
222
|
destructive: false,
|
|
169
223
|
concurrencySafe: true,
|
|
224
|
+
// `url` is a URL, not a command line, so the gate does not split it at `&`
|
|
225
|
+
// and a rule on it tests it whole; the model-written `prompt` is never part
|
|
226
|
+
// of what a rule compares.
|
|
227
|
+
urlArgument: 'url',
|
|
170
228
|
|
|
171
229
|
async execute(input, context) {
|
|
172
230
|
const fetcher = context.web?.fetch
|
|
@@ -350,7 +408,7 @@ function redirectNotice(
|
|
|
350
408
|
export const WebSearchTool = defineTool({
|
|
351
409
|
name: WEB_SEARCH_TOOL_NAME,
|
|
352
410
|
description:
|
|
353
|
-
"Searches the web and returns titles, URLs and the provider's own snippets. A snippet is the provider's summary, not the page: fetch a result with web_fetch before relying on its contents, and do not state something as fact on a snippet alone.",
|
|
411
|
+
"Searches the web and returns titles, URLs and the provider's own snippets. `allowed_domains` keeps only results from those domains and `blocked_domains` drops results from those domains (a domain also covers its subdomains); set only one of the two in a call. A snippet is the provider's summary, not the page: fetch a result with web_fetch before relying on its contents, and do not state something as fact on a snippet alone.",
|
|
354
412
|
inputSchema: searchInput,
|
|
355
413
|
category: 'network',
|
|
356
414
|
permissions: ['network_access'],
|
|
@@ -372,11 +430,50 @@ export const WebSearchTool = defineTool({
|
|
|
372
430
|
}
|
|
373
431
|
}
|
|
374
432
|
|
|
375
|
-
|
|
433
|
+
if (input.allowed_domains?.length && input.blocked_domains?.length) {
|
|
434
|
+
return {
|
|
435
|
+
success: false,
|
|
436
|
+
output: '',
|
|
437
|
+
error: 'Error: Cannot specify both allowed_domains and blocked_domains in the same request',
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
const allowed = (input.allowed_domains ?? []).map(normalizeDomain)
|
|
441
|
+
const blocked = (input.blocked_domains ?? []).map(normalizeDomain)
|
|
442
|
+
if (allowed.includes(undefined) || blocked.includes(undefined)) {
|
|
443
|
+
return {
|
|
444
|
+
success: false,
|
|
445
|
+
output: '',
|
|
446
|
+
error: 'allowed_domains and blocked_domains entries must be domain names, not empty.',
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
const allow = allowed as string[]
|
|
450
|
+
const block = blocked as string[]
|
|
451
|
+
const filtering = allow.length > 0 || block.length > 0
|
|
452
|
+
|
|
453
|
+
const raw = await context.web.search.search({
|
|
376
454
|
query: input.query,
|
|
377
|
-
...(input.limit === undefined
|
|
455
|
+
...(input.limit === undefined
|
|
456
|
+
? {}
|
|
457
|
+
: {
|
|
458
|
+
limit: filtering
|
|
459
|
+
? Math.min(Math.max(input.limit * OVERFETCH_FACTOR, input.limit), OVERFETCH_MAX)
|
|
460
|
+
: input.limit,
|
|
461
|
+
}),
|
|
462
|
+
...(allow.length > 0 ? { allowedDomains: allow } : {}),
|
|
463
|
+
...(block.length > 0 ? { blockedDomains: block } : {}),
|
|
378
464
|
...(context.abortSignal ? { signal: context.abortSignal } : {}),
|
|
379
465
|
})
|
|
466
|
+
let hits = raw.hits
|
|
467
|
+
if (filtering) {
|
|
468
|
+
hits = hits.filter((hit) => {
|
|
469
|
+
const host = hostOf(hit.url)
|
|
470
|
+
if (host === undefined) return false // an address that cannot be read cannot be shown to be allowed
|
|
471
|
+
if (allow.length > 0 && !inDomains(host, allow)) return false
|
|
472
|
+
return !inDomains(host, block)
|
|
473
|
+
})
|
|
474
|
+
}
|
|
475
|
+
if (input.limit !== undefined) hits = hits.slice(0, input.limit)
|
|
476
|
+
const result = { query: raw.query, hits }
|
|
380
477
|
|
|
381
478
|
if (result.hits.length === 0) {
|
|
382
479
|
// A real answer, and distinct from the refusal above: the search
|
|
@@ -69,6 +69,12 @@ export interface CommandShell {
|
|
|
69
69
|
readonly source: 'override' | 'bash' | 'sh' | 'platform'
|
|
70
70
|
/** True when this is a Windows executable (Git Bash), which needs Windows-only spawn details. */
|
|
71
71
|
readonly windows?: true
|
|
72
|
+
/**
|
|
73
|
+
* True when this is PowerShell (a scheduled script job's own choice, never the
|
|
74
|
+
* `bash` tool's). It is run with the line as one encoded argument, not `-c`,
|
|
75
|
+
* and `dialect` is `cmd`: the shell lexer cannot read PowerShell.
|
|
76
|
+
*/
|
|
77
|
+
readonly powershell?: true
|
|
72
78
|
}
|
|
73
79
|
|
|
74
80
|
/** What resolution looks at. Injected by tests to simulate a host without bash. */
|
|
@@ -81,6 +87,11 @@ export interface CommandShellProbe {
|
|
|
81
87
|
* Absent or throwing means git was not found on PATH.
|
|
82
88
|
*/
|
|
83
89
|
readonly whereGit?: () => readonly string[]
|
|
90
|
+
/**
|
|
91
|
+
* Windows only: the paths that name PowerShell, best first (`pwsh`, then
|
|
92
|
+
* Windows PowerShell). Absent or throwing means none was found.
|
|
93
|
+
*/
|
|
94
|
+
readonly windowsPowerShell?: () => readonly string[]
|
|
84
95
|
/** Windows only: the working directory, whose own programs are never trusted. Default: `process.cwd()`. */
|
|
85
96
|
readonly cwd?: string
|
|
86
97
|
}
|
|
@@ -280,6 +291,160 @@ export function findCommandShellForDialect(
|
|
|
280
291
|
return undefined
|
|
281
292
|
}
|
|
282
293
|
|
|
294
|
+
/** The interpreters a scheduled script job can record. */
|
|
295
|
+
export type ScriptShellName = 'bash' | 'sh' | 'powershell'
|
|
296
|
+
|
|
297
|
+
function windowsProgramName(path: string): string {
|
|
298
|
+
return (
|
|
299
|
+
path
|
|
300
|
+
.split(/[\\/]/)
|
|
301
|
+
.at(-1)
|
|
302
|
+
?.toLowerCase()
|
|
303
|
+
.replace(/\.exe$/, '') ?? ''
|
|
304
|
+
)
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* What `NAMZU_BASH_SHELL` names on Windows, when it is not bash or sh. A script
|
|
309
|
+
* job refuses such a value rather than ignore it, since the operator asked for
|
|
310
|
+
* that program and a different one would run instead.
|
|
311
|
+
*/
|
|
312
|
+
export function windowsShellOverrideProblem(env: NodeJS.ProcessEnv): string | undefined {
|
|
313
|
+
const override = env.NAMZU_BASH_SHELL
|
|
314
|
+
if (override === undefined || override === '') return undefined
|
|
315
|
+
const name = windowsProgramName(override)
|
|
316
|
+
return name === 'bash' || name === 'sh' ? undefined : name
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* The interpreter a scheduled script job recorded, never another one.
|
|
321
|
+
*
|
|
322
|
+
* - `bash` / `sh` off Windows: {@link findCommandShellForDialect}.
|
|
323
|
+
* - `bash` / `sh` on Windows: Git Bash. `NAMZU_BASH_SHELL` may name a
|
|
324
|
+
* `bash.exe` or `sh.exe` by absolute path; any other program there makes the
|
|
325
|
+
* answer "none" (see {@link windowsShellOverrideProblem}). Without the
|
|
326
|
+
* variable, bash is Git for Windows' own (`findGitBash`, never a `bash` found
|
|
327
|
+
* on PATH, which can be WSL's launcher) and sh is the `sh.exe` beside it.
|
|
328
|
+
* - `powershell`: Windows only. `pwsh` first, then Windows PowerShell, each by
|
|
329
|
+
* an absolute path that is not inside the working directory.
|
|
330
|
+
*
|
|
331
|
+
* No branch falls back to a different shell. Undefined means "not here".
|
|
332
|
+
*/
|
|
333
|
+
export function findScriptShell(
|
|
334
|
+
name: ScriptShellName,
|
|
335
|
+
probe: CommandShellProbe,
|
|
336
|
+
): CommandShell | undefined {
|
|
337
|
+
if (name === 'powershell') {
|
|
338
|
+
if (probe.platform !== 'win32') return undefined
|
|
339
|
+
const cwd = probe.cwd ?? process.cwd()
|
|
340
|
+
let candidates: readonly string[] = []
|
|
341
|
+
try {
|
|
342
|
+
candidates = probe.windowsPowerShell?.() ?? []
|
|
343
|
+
} catch {
|
|
344
|
+
return undefined
|
|
345
|
+
}
|
|
346
|
+
for (const raw of candidates) {
|
|
347
|
+
const candidate = raw.trim()
|
|
348
|
+
const program = windowsProgramName(candidate)
|
|
349
|
+
if (program !== 'pwsh' && program !== 'powershell') continue
|
|
350
|
+
if (!win32.isAbsolute(candidate) || insideDirectory(candidate, cwd)) continue
|
|
351
|
+
if (probe.isExecutable(candidate)) {
|
|
352
|
+
return { path: candidate, dialect: 'cmd', source: 'platform', powershell: true }
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
return undefined
|
|
356
|
+
}
|
|
357
|
+
if (probe.platform !== 'win32') return findCommandShellForDialect(name, probe)
|
|
358
|
+
const override = probe.env.NAMZU_BASH_SHELL
|
|
359
|
+
if (override !== undefined && override !== '') {
|
|
360
|
+
const program = windowsProgramName(override)
|
|
361
|
+
if (program !== 'bash' && program !== 'sh') return undefined
|
|
362
|
+
if (program === name) {
|
|
363
|
+
return win32.isAbsolute(override) && probe.isExecutable(override)
|
|
364
|
+
? { path: override, dialect: name, source: 'override', windows: true }
|
|
365
|
+
: undefined
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
const gitBash = findGitBash(probe)
|
|
369
|
+
if (gitBash === undefined) return undefined
|
|
370
|
+
if (name === 'bash') return { path: gitBash, dialect: 'bash', source: 'bash', windows: true }
|
|
371
|
+
const sh = win32.join(win32.dirname(gitBash), 'sh.exe')
|
|
372
|
+
return probe.isExecutable(sh)
|
|
373
|
+
? { path: sh, dialect: 'sh', source: 'sh', windows: true }
|
|
374
|
+
: undefined
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* The shell a script job gets when none is named: bash, and on Windows without
|
|
379
|
+
* Git Bash, PowerShell. The caller records the answer in the job.
|
|
380
|
+
*/
|
|
381
|
+
export function defaultScriptShellName(probe: CommandShellProbe): ScriptShellName {
|
|
382
|
+
return probe.platform === 'win32' && findScriptShell('bash', probe) === undefined
|
|
383
|
+
? 'powershell'
|
|
384
|
+
: 'bash'
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/** `where.exe pwsh`, then Windows PowerShell's fixed path, both by absolute path. */
|
|
388
|
+
function wherePowerShell(): readonly string[] {
|
|
389
|
+
const root = process.env.SystemRoot ?? process.env.windir ?? 'C:\\Windows'
|
|
390
|
+
const found: string[] = []
|
|
391
|
+
try {
|
|
392
|
+
found.push(
|
|
393
|
+
...execFileSync(win32.join(root, 'System32', 'where.exe'), ['pwsh'], {
|
|
394
|
+
encoding: 'utf8',
|
|
395
|
+
windowsHide: true,
|
|
396
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
397
|
+
timeout: 5000,
|
|
398
|
+
}).split(/\r?\n/),
|
|
399
|
+
)
|
|
400
|
+
} catch {
|
|
401
|
+
// pwsh is not on PATH
|
|
402
|
+
}
|
|
403
|
+
found.push(win32.join(root, 'System32', 'WindowsPowerShell', 'v1.0', 'powershell.exe'))
|
|
404
|
+
return found
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
function hostScriptProbe(): CommandShellProbe {
|
|
408
|
+
return {
|
|
409
|
+
env: process.env,
|
|
410
|
+
platform: process.platform,
|
|
411
|
+
isExecutable,
|
|
412
|
+
whereGit,
|
|
413
|
+
windowsPowerShell: wherePowerShell,
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/** {@link findScriptShell} against this host; re-checked at every confirmation and fire. */
|
|
418
|
+
export function installedScriptShell(name: ScriptShellName): CommandShell | undefined {
|
|
419
|
+
return findScriptShell(name, hostScriptProbe())
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/** {@link defaultScriptShellName} against this host. */
|
|
423
|
+
export function hostDefaultScriptShellName(): ScriptShellName {
|
|
424
|
+
return defaultScriptShellName(hostScriptProbe())
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/** The longest PowerShell script one process can be given (Windows allows 32,767 characters on a command line). */
|
|
428
|
+
export const POWERSHELL_MAX_SCRIPT_CHARS = 8000
|
|
429
|
+
|
|
430
|
+
/** Output is read as UTF-8, so the console is told to write it. */
|
|
431
|
+
const POWERSHELL_PROLOGUE = '[Console]::OutputEncoding = [System.Text.UTF8Encoding]::new($false)\n'
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* PowerShell's argv for one script: the script as a single base64 argument
|
|
435
|
+
* (UTF-16LE), so nothing in it is ever parsed as a command line.
|
|
436
|
+
*/
|
|
437
|
+
export function powershellArgs(script: string): readonly string[] {
|
|
438
|
+
return [
|
|
439
|
+
'-NoProfile',
|
|
440
|
+
'-NonInteractive',
|
|
441
|
+
'-OutputFormat',
|
|
442
|
+
'Text',
|
|
443
|
+
'-EncodedCommand',
|
|
444
|
+
Buffer.from(POWERSHELL_PROLOGUE + script, 'utf16le').toString('base64'),
|
|
445
|
+
]
|
|
446
|
+
}
|
|
447
|
+
|
|
283
448
|
function isExecutable(path: string): boolean {
|
|
284
449
|
try {
|
|
285
450
|
accessSync(path, constants.X_OK)
|
|
@@ -337,6 +502,7 @@ export function hostShellSpawn(
|
|
|
337
502
|
readonly env: NodeJS.ProcessEnv
|
|
338
503
|
} {
|
|
339
504
|
if (shell.path === undefined) return { file: undefined, args: [command], env }
|
|
505
|
+
if (shell.powershell === true) return { file: shell.path, args: powershellArgs(command), env }
|
|
340
506
|
if (shell.dialect !== 'bash') return { file: shell.path, args: ['-c', command], env }
|
|
341
507
|
const clean = withoutBashStartup(env)
|
|
342
508
|
// Git for Windows: the line is read as bash, so `>nul` must already have
|
package/src/tools/env-scrub.ts
CHANGED
|
@@ -54,6 +54,18 @@ export { isCredentialEnvKey }
|
|
|
54
54
|
// Two copies would mean a name in one and not the other — a variable the
|
|
55
55
|
// credential seam reads a secret from and this scrub hands to a shell.
|
|
56
56
|
|
|
57
|
+
/**
|
|
58
|
+
* Names a host wrote on purpose into the process environment (for example the user's own
|
|
59
|
+
* settings `env` block). They arrive through `process.env`, but unlike an inherited variable
|
|
60
|
+
* somebody decided a command should see them, so the scrub leaves them in.
|
|
61
|
+
*/
|
|
62
|
+
let deliberateKeys: ReadonlySet<string> = new Set()
|
|
63
|
+
|
|
64
|
+
/** Replaces the set of names the scrub leaves in; an empty list clears it. */
|
|
65
|
+
export function setDeliberateEnvKeys(names: Iterable<string>): void {
|
|
66
|
+
deliberateKeys = new Set(names)
|
|
67
|
+
}
|
|
68
|
+
|
|
57
69
|
/** Outcome of a scrub — the surviving environment and what was withheld. */
|
|
58
70
|
export interface ScrubbedEnv {
|
|
59
71
|
readonly env: Record<string, string>
|
|
@@ -81,7 +93,7 @@ export function scrubInheritedEnv(source: NodeJS.ProcessEnv = process.env): Scru
|
|
|
81
93
|
|
|
82
94
|
for (const [key, value] of Object.entries(source)) {
|
|
83
95
|
if (value === undefined) continue
|
|
84
|
-
if (isCredentialEnvKey(key)) {
|
|
96
|
+
if (isCredentialEnvKey(key) && !deliberateKeys.has(key)) {
|
|
85
97
|
dropped.push(key)
|
|
86
98
|
continue
|
|
87
99
|
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Git configuration carried in the environment of a command.
|
|
3
|
+
*
|
|
4
|
+
* A folder that looks like a bare repository (`HEAD`, `objects/`, `refs/` and a
|
|
5
|
+
* `config` outside a `.git` folder) is read by git as a repository when git is
|
|
6
|
+
* started inside it, and its `config` can name a program for git to run
|
|
7
|
+
* (`core.fsmonitor`) before it prints anything. A model in a mode that allows
|
|
8
|
+
* edits can write such a folder, and a later read-only looking `git status`
|
|
9
|
+
* from inside it then runs that program. So every git a session starts is
|
|
10
|
+
* given the same three settings, through git's own `GIT_CONFIG_COUNT`
|
|
11
|
+
* variables, which beat a repository's `config`:
|
|
12
|
+
*
|
|
13
|
+
* - `safe.bareRepository=explicit`: git only treats a folder as a bare
|
|
14
|
+
* repository when it is named (`--git-dir=.`, `GIT_DIR`), never because the
|
|
15
|
+
* current folder happens to look like one.
|
|
16
|
+
* - `core.fsmonitor=` (empty): no file-system monitor program is started.
|
|
17
|
+
* - `core.hooksPath` (host-side calls only): no hook runs. The model's own
|
|
18
|
+
* commands keep their hooks, because a person's `pre-commit` is part of how
|
|
19
|
+
* the project wants commits made.
|
|
20
|
+
*
|
|
21
|
+
* The entries are appended after whatever `GIT_CONFIG_COUNT` the caller
|
|
22
|
+
* already set, so a caller's own entries survive and these win a key they
|
|
23
|
+
* share. Applying the helper twice changes nothing. A count git reads
|
|
24
|
+
* (`+1`, spaces around it) is honoured; one it cannot use is replaced, and the
|
|
25
|
+
* new entries go after the highest index already in the environment.
|
|
26
|
+
*
|
|
27
|
+
* git older than 2.31 ignores `GIT_CONFIG_COUNT`, and older than 2.38 does not
|
|
28
|
+
* know `safe.bareRepository`; there the helper is inert, not harmful.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/** One `key=value` pair of git configuration. */
|
|
32
|
+
export type GitConfigEntry = readonly [key: string, value: string]
|
|
33
|
+
|
|
34
|
+
/** The settings every git a session starts carries. */
|
|
35
|
+
export const SAFE_GIT_CONFIG: readonly GitConfigEntry[] = Object.freeze([
|
|
36
|
+
['safe.bareRepository', 'explicit'] as const,
|
|
37
|
+
['core.fsmonitor', ''] as const,
|
|
38
|
+
])
|
|
39
|
+
|
|
40
|
+
/** The null device git accepts as a hooks folder, so no hook runs. */
|
|
41
|
+
export function nullHooksPath(platform: NodeJS.Platform = process.platform): string {
|
|
42
|
+
return platform === 'win32' ? '\\\\.\\NUL' : '/dev/null'
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** The settings for git run by the host itself: the above, and no hooks. */
|
|
46
|
+
export function hostGitConfig(platform: NodeJS.Platform = process.platform): GitConfigEntry[] {
|
|
47
|
+
return [...SAFE_GIT_CONFIG, ['core.hooksPath', nullHooksPath(platform)] as const]
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// A count past this is not a real list of settings; reading it as zero keeps a
|
|
51
|
+
// hostile value from making the helper loop.
|
|
52
|
+
const MAX_ENTRIES = 4096
|
|
53
|
+
|
|
54
|
+
function readCount(raw: string | undefined): number | undefined {
|
|
55
|
+
if (raw === undefined) return 0
|
|
56
|
+
// The forms git's own number reader accepts: a leading sign and spaces.
|
|
57
|
+
const m = /^\s*\+?(\d+)\s*$/.exec(raw)
|
|
58
|
+
if (m === null) return undefined
|
|
59
|
+
const n = Number(m[1])
|
|
60
|
+
return Number.isSafeInteger(n) && n <= MAX_ENTRIES ? n : undefined
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** One past the highest `GIT_CONFIG_KEY_<n>` or `GIT_CONFIG_VALUE_<n>` the env holds. */
|
|
64
|
+
function afterHighestIndex(env: Record<string, string | undefined>): number {
|
|
65
|
+
let next = 0
|
|
66
|
+
for (const k of Object.keys(env)) {
|
|
67
|
+
const m = /^GIT_CONFIG_(?:KEY|VALUE)_(\d{1,9})$/.exec(k)
|
|
68
|
+
if (m !== null) next = Math.max(next, Number(m[1]) + 1)
|
|
69
|
+
}
|
|
70
|
+
return next
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function findKey(env: Record<string, string | undefined>, name: string): string | undefined {
|
|
74
|
+
if (Object.hasOwn(env, name)) return name
|
|
75
|
+
const upper = name.toUpperCase()
|
|
76
|
+
return Object.keys(env).find((k) => k.toUpperCase() === upper)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Return a copy of `env` with `entries` appended to its git configuration.
|
|
81
|
+
* Never mutates its input.
|
|
82
|
+
*/
|
|
83
|
+
export function withGitConfig<E extends Record<string, string | undefined>>(
|
|
84
|
+
env: E,
|
|
85
|
+
entries: readonly GitConfigEntry[],
|
|
86
|
+
): E {
|
|
87
|
+
const out: Record<string, string | undefined> = { ...env }
|
|
88
|
+
const countKey = findKey(out, 'GIT_CONFIG_COUNT')
|
|
89
|
+
const parsed = readCount(countKey === undefined ? undefined : out[countKey])
|
|
90
|
+
// A count that cannot be read is not trusted, but the entries beside it are
|
|
91
|
+
// the caller's: start after them rather than over them.
|
|
92
|
+
const count = parsed ?? afterHighestIndex(out)
|
|
93
|
+
if (countKey !== undefined && countKey !== 'GIT_CONFIG_COUNT') delete out[countKey]
|
|
94
|
+
|
|
95
|
+
// The last value each key holds among the entries already there.
|
|
96
|
+
const last = new Map<string, string>()
|
|
97
|
+
for (let i = 0; i < count; i++) {
|
|
98
|
+
const k = out[`GIT_CONFIG_KEY_${i}`]
|
|
99
|
+
const v = out[`GIT_CONFIG_VALUE_${i}`]
|
|
100
|
+
if (k !== undefined && v !== undefined) last.set(k.toLowerCase(), v)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
let next = count
|
|
104
|
+
for (const [key, value] of entries) {
|
|
105
|
+
if (last.get(key.toLowerCase()) === value) continue
|
|
106
|
+
out[`GIT_CONFIG_KEY_${next}`] = key
|
|
107
|
+
out[`GIT_CONFIG_VALUE_${next}`] = value
|
|
108
|
+
last.set(key.toLowerCase(), value)
|
|
109
|
+
next++
|
|
110
|
+
}
|
|
111
|
+
out.GIT_CONFIG_COUNT = String(next)
|
|
112
|
+
return out as E
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** `env` with the settings a command a model started carries. */
|
|
116
|
+
export function withSafeGitConfig<E extends Record<string, string | undefined>>(env: E): E {
|
|
117
|
+
return withGitConfig(env, SAFE_GIT_CONFIG)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** `env` with the full settings for git the host itself runs. */
|
|
121
|
+
export function withHostGitConfig<E extends Record<string, string | undefined>>(env: E): E {
|
|
122
|
+
return withGitConfig(env, hostGitConfig())
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* A copy of `base` (the process environment by default) with the full settings
|
|
127
|
+
* for git the host itself runs, for an `execFile('git', ...)` that names no
|
|
128
|
+
* environment of its own: `{ env: hostGitEnv() }`.
|
|
129
|
+
*/
|
|
130
|
+
export function hostGitEnv(base: NodeJS.ProcessEnv = process.env): NodeJS.ProcessEnv {
|
|
131
|
+
return withHostGitConfig({ ...base })
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** The program name without folder or Windows extension, lower case. */
|
|
135
|
+
function programName(command: string): string {
|
|
136
|
+
const base = command.split(/[\\/]/).pop() ?? command
|
|
137
|
+
return base.replace(/\.(exe|cmd|bat|com)$/i, '').toLowerCase()
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** Whether `command` starts git itself rather than a shell or another program. */
|
|
141
|
+
export function isGitProgram(command: string): boolean {
|
|
142
|
+
return programName(command) === 'git'
|
|
143
|
+
}
|