@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
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Command output as plain text: what a terminal would leave on its screen,
|
|
3
|
+
* without the escape codes that drew it.
|
|
4
|
+
*
|
|
5
|
+
* The kernel hands the model a command's output as it was printed, colour and
|
|
6
|
+
* cursor codes included. A host that shows it as text (a web view, a protocol
|
|
7
|
+
* client) calls this instead of printing `\u001b[32m`:
|
|
8
|
+
*
|
|
9
|
+
* - CSI sequences (`ESC [ ... final`), OSC sequences (`ESC ] ... BEL` or
|
|
10
|
+
* `ESC \`, so an OSC 8 link keeps its visible text and loses its address),
|
|
11
|
+
* the string sequences DCS, SOS, PM and APC, and every other two-byte escape
|
|
12
|
+
* are dropped. A sequence cut off by the end of the text is dropped too.
|
|
13
|
+
* - A carriage return puts the cursor back at the start of the line and a
|
|
14
|
+
* backspace one column left, so what follows overwrites, and a progress bar
|
|
15
|
+
* that redraws itself shows its final state, not every frame. `ESC [ K`
|
|
16
|
+
* erases as a terminal does, so a shorter redraw leaves nothing of a longer
|
|
17
|
+
* one behind.
|
|
18
|
+
* - Newline and tab stay. Any other control character is dropped.
|
|
19
|
+
*/
|
|
20
|
+
const ESC = 0x1b;
|
|
21
|
+
const BEL = 0x07;
|
|
22
|
+
/** True when `text` holds nothing this function would change. */
|
|
23
|
+
function isPlain(text) {
|
|
24
|
+
for (let i = 0; i < text.length; i++) {
|
|
25
|
+
const code = text.charCodeAt(i);
|
|
26
|
+
if (code === 0x0a || code === 0x09)
|
|
27
|
+
continue;
|
|
28
|
+
if (code < 0x20 || (code >= 0x7f && code <= 0x9f))
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
/** Index just past the string sequence body that starts at `from`, or the end of `text`. */
|
|
34
|
+
function endOfString(text, from, belEnds) {
|
|
35
|
+
for (let i = from; i < text.length; i++) {
|
|
36
|
+
const code = text.charCodeAt(i);
|
|
37
|
+
if (belEnds && code === BEL)
|
|
38
|
+
return i + 1;
|
|
39
|
+
if (code === 0x9c)
|
|
40
|
+
return i + 1;
|
|
41
|
+
if (code === ESC && text.charCodeAt(i + 1) === 0x5c)
|
|
42
|
+
return i + 2;
|
|
43
|
+
}
|
|
44
|
+
return text.length;
|
|
45
|
+
}
|
|
46
|
+
/** Index just past the CSI sequence whose parameters start at `from`, or the end of `text`. */
|
|
47
|
+
function endOfCsi(text, from) {
|
|
48
|
+
let i = from;
|
|
49
|
+
while (i < text.length) {
|
|
50
|
+
const code = text.charCodeAt(i);
|
|
51
|
+
if (code >= 0x40 && code <= 0x7e) {
|
|
52
|
+
return { end: i + 1, params: text.slice(from, i), final: text[i] };
|
|
53
|
+
}
|
|
54
|
+
// A byte that cannot be part of a sequence ends it without a final byte.
|
|
55
|
+
if (code < 0x20 || code > 0x3f)
|
|
56
|
+
break;
|
|
57
|
+
i++;
|
|
58
|
+
}
|
|
59
|
+
return { end: i >= text.length ? text.length : i, params: '', final: '' };
|
|
60
|
+
}
|
|
61
|
+
export function plainTerminalText(text) {
|
|
62
|
+
if (isPlain(text))
|
|
63
|
+
return text;
|
|
64
|
+
const lines = [];
|
|
65
|
+
let line = [];
|
|
66
|
+
let col = 0;
|
|
67
|
+
const put = (char) => {
|
|
68
|
+
while (line.length < col)
|
|
69
|
+
line.push(' ');
|
|
70
|
+
line[col] = char;
|
|
71
|
+
col++;
|
|
72
|
+
};
|
|
73
|
+
let i = 0;
|
|
74
|
+
while (i < text.length) {
|
|
75
|
+
const code = text.charCodeAt(i);
|
|
76
|
+
if (code === ESC) {
|
|
77
|
+
const next = text.charCodeAt(i + 1);
|
|
78
|
+
if (next === 0x5b) {
|
|
79
|
+
const csi = endOfCsi(text, i + 2);
|
|
80
|
+
if (csi.final === 'K') {
|
|
81
|
+
const mode = csi.params === '' ? 0 : Number(csi.params);
|
|
82
|
+
if (mode === 0)
|
|
83
|
+
line.length = Math.min(line.length, col);
|
|
84
|
+
else if (mode === 1)
|
|
85
|
+
for (let c = 0; c <= col && c < line.length; c++)
|
|
86
|
+
line[c] = ' ';
|
|
87
|
+
else if (mode === 2)
|
|
88
|
+
line = [];
|
|
89
|
+
}
|
|
90
|
+
i = csi.end;
|
|
91
|
+
}
|
|
92
|
+
else if (next === 0x5d) {
|
|
93
|
+
i = endOfString(text, i + 2, true);
|
|
94
|
+
}
|
|
95
|
+
else if (next === 0x50 || next === 0x58 || next === 0x5e || next === 0x5f) {
|
|
96
|
+
i = endOfString(text, i + 2, false);
|
|
97
|
+
}
|
|
98
|
+
else if (Number.isNaN(next)) {
|
|
99
|
+
i += 1;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
// An escape, any intermediate bytes (0x20-0x2f), then one final byte.
|
|
103
|
+
// Only a byte in 0x30-0x7e is a final byte: an ESC restarts a sequence,
|
|
104
|
+
// a control character stays what it is, and a character outside ASCII
|
|
105
|
+
// (taken whole, never as half a surrogate pair) is text after a lone ESC.
|
|
106
|
+
let j = i + 1;
|
|
107
|
+
while (j < text.length && text.charCodeAt(j) >= 0x20 && text.charCodeAt(j) <= 0x2f)
|
|
108
|
+
j++;
|
|
109
|
+
const final = text.charCodeAt(j);
|
|
110
|
+
i = final >= 0x30 && final <= 0x7e ? j + 1 : j;
|
|
111
|
+
}
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
if (code === 0x9b) {
|
|
115
|
+
i = endOfCsi(text, i + 1).end;
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
if (code === 0x9d) {
|
|
119
|
+
i = endOfString(text, i + 1, true);
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
if (code === 0x90 || code === 0x98 || code === 0x9e || code === 0x9f) {
|
|
123
|
+
i = endOfString(text, i + 1, false);
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
if (code === 0x0a) {
|
|
127
|
+
lines.push(line);
|
|
128
|
+
line = [];
|
|
129
|
+
col = 0;
|
|
130
|
+
}
|
|
131
|
+
else if (code === 0x0d) {
|
|
132
|
+
col = 0;
|
|
133
|
+
}
|
|
134
|
+
else if (code === 0x08) {
|
|
135
|
+
if (col > 0)
|
|
136
|
+
col--;
|
|
137
|
+
}
|
|
138
|
+
else if (code === 0x09) {
|
|
139
|
+
put('\t');
|
|
140
|
+
}
|
|
141
|
+
else if (code < 0x20 || (code >= 0x7f && code <= 0x9f)) {
|
|
142
|
+
// Dropped.
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
const point = text.codePointAt(i);
|
|
146
|
+
const char = String.fromCodePoint(point);
|
|
147
|
+
put(char);
|
|
148
|
+
i += char.length;
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
i++;
|
|
152
|
+
}
|
|
153
|
+
lines.push(line);
|
|
154
|
+
return lines.map((cells) => cells.join('')).join('\n');
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=plain-terminal-text.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plain-terminal-text.js","sourceRoot":"","sources":["../../src/utils/plain-terminal-text.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,MAAM,GAAG,GAAG,IAAI,CAAA;AAChB,MAAM,GAAG,GAAG,IAAI,CAAA;AAEhB,iEAAiE;AACjE,SAAS,OAAO,CAAC,IAAY;IAC5B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAA;QAC/B,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,IAAI;YAAE,SAAQ;QAC5C,IAAI,IAAI,GAAG,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,CAAC;YAAE,OAAO,KAAK,CAAA;IAChE,CAAC;IACD,OAAO,IAAI,CAAA;AACZ,CAAC;AAED,4FAA4F;AAC5F,SAAS,WAAW,CAAC,IAAY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AAW,CAAC,CAAC,CAAW,CAAA;YAC3C,MAAM,IAAI,GAAG,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAA;YACxC,GAAG,CAAC,IAAI,CAAC,CAAA;YACT,CAAC,IAAI,IAAI,CAAC,MAAM,CAAA;YAChB,SAAQ;QACT,CAAC;QACD,CAAC,EAAE,CAAA;IACJ,CAAC;IACD,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAChB,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACvD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@namzu/sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "71.0.1",
|
|
4
4
|
"description": "Open-source AI kernel for TypeScript: runs an agent the way an operating system runs a process, with an identity and a budget, scheduled tool calls and checkpointed turns.",
|
|
5
5
|
"license": "FSL-1.1-MIT",
|
|
6
6
|
"engines": {
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a folder looks like a bare git repository that is not one.
|
|
3
|
+
*
|
|
4
|
+
* Git started in a folder that holds `HEAD`, `objects/` and `refs/` outside a
|
|
5
|
+
* `.git` folder reads it as a repository and obeys its `config`, which can name
|
|
6
|
+
* a program to run. A model that may write files can plant such a folder, so a
|
|
7
|
+
* `git` line that looks harmless is not harmless when the folder it starts in,
|
|
8
|
+
* or one above it, looks like that. The read-only decision asks the person when
|
|
9
|
+
* this is true (see `readonly-commands.ts`).
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { statSync } from 'node:fs'
|
|
13
|
+
import { dirname, sep } from 'node:path'
|
|
14
|
+
|
|
15
|
+
/** The sentence a person reads when a git line is asked about for this reason. */
|
|
16
|
+
export const BARE_INDICATORS_REASON =
|
|
17
|
+
'Git command in a folder that looks like a bare repository (HEAD, objects and refs outside a .git folder). Git may read it as a repository and run the configuration and programs it names. To work with a real bare repository, name it: git --git-dir=<folder> <command>.'
|
|
18
|
+
|
|
19
|
+
/** The sentence for a `cd` and a `git` command in one line. */
|
|
20
|
+
export const CD_AND_GIT_REASON =
|
|
21
|
+
'A line that changes folder and runs git needs approval: the folder it enters may hold a repository that was planted there.'
|
|
22
|
+
|
|
23
|
+
// A path longer than this many folders is not a real checkout; stop looking.
|
|
24
|
+
const MAX_DEPTH = 64
|
|
25
|
+
|
|
26
|
+
function isDirectory(path: string): boolean {
|
|
27
|
+
try {
|
|
28
|
+
return statSync(path).isDirectory()
|
|
29
|
+
} catch {
|
|
30
|
+
return false
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function isFile(path: string): boolean {
|
|
35
|
+
try {
|
|
36
|
+
return statSync(path).isFile()
|
|
37
|
+
} catch {
|
|
38
|
+
return false
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Whether `folder` itself has the three marks of a bare repository. */
|
|
43
|
+
function hasBareMarks(folder: string): boolean {
|
|
44
|
+
return (
|
|
45
|
+
isFile(`${folder}${sep}HEAD`) &&
|
|
46
|
+
isDirectory(`${folder}${sep}objects`) &&
|
|
47
|
+
isDirectory(`${folder}${sep}refs`)
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Whether `folder` is, or lies inside, a `.git` folder. */
|
|
52
|
+
function insideDotGit(folder: string): boolean {
|
|
53
|
+
return folder.split(/[\\/]/).includes('.git')
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The folder, from `cwd` up to the root, that looks like a bare repository
|
|
58
|
+
* outside a `.git` folder, or `undefined` when none does. A folder that cannot
|
|
59
|
+
* be read counts as not looking like one: there is nothing git could read.
|
|
60
|
+
*/
|
|
61
|
+
export function bareRepositoryIndicator(cwd: string): string | undefined {
|
|
62
|
+
let folder = cwd
|
|
63
|
+
for (let depth = 0; depth < MAX_DEPTH; depth++) {
|
|
64
|
+
if (!insideDotGit(folder) && hasBareMarks(folder)) return folder
|
|
65
|
+
const parent = dirname(folder)
|
|
66
|
+
if (parent === folder) return undefined
|
|
67
|
+
folder = parent
|
|
68
|
+
}
|
|
69
|
+
return undefined
|
|
70
|
+
}
|
|
@@ -83,6 +83,7 @@ import {
|
|
|
83
83
|
basename,
|
|
84
84
|
lexShellCommandLine,
|
|
85
85
|
} from './shell-lexer.js'
|
|
86
|
+
import { type ShellAttributes, currentShellAttributes } from './shell-session-state.js'
|
|
86
87
|
|
|
87
88
|
/** The commands a line runs, and whether that list can be trusted as complete. */
|
|
88
89
|
export interface CommandLineDecomposition {
|
|
@@ -232,14 +233,27 @@ function writes(redirection: ShellRedirection): boolean {
|
|
|
232
233
|
* asks for it again. The last line lexed is kept so that is one lexing.
|
|
233
234
|
*/
|
|
234
235
|
let cached:
|
|
235
|
-
| {
|
|
236
|
+
| {
|
|
237
|
+
readonly command: string
|
|
238
|
+
readonly dialect: ShellDialect
|
|
239
|
+
readonly attributes: ShellAttributes | undefined
|
|
240
|
+
readonly result: ShellLexResult
|
|
241
|
+
}
|
|
236
242
|
| undefined
|
|
237
243
|
|
|
238
244
|
function lex(command: string, dialect: ShellDialect): ShellLexResult {
|
|
239
|
-
|
|
245
|
+
// The session's attributes are part of the reading: another session, or
|
|
246
|
+
// the same one after it declared a name, reads the same text differently.
|
|
247
|
+
const attributes = currentShellAttributes()
|
|
248
|
+
if (
|
|
249
|
+
cached !== undefined &&
|
|
250
|
+
cached.command === command &&
|
|
251
|
+
cached.dialect === dialect &&
|
|
252
|
+
cached.attributes === attributes
|
|
253
|
+
) {
|
|
240
254
|
return cached.result
|
|
241
255
|
}
|
|
242
|
-
const result = lexShellCommandLine(command, { dialect })
|
|
243
|
-
cached = { command, dialect, result }
|
|
256
|
+
const result = lexShellCommandLine(command, { dialect, ...(attributes ? { attributes } : {}) })
|
|
257
|
+
cached = { command, dialect, attributes, result }
|
|
244
258
|
return result
|
|
245
259
|
}
|
|
@@ -14,6 +14,7 @@ import type { Logger } from '../utils/logger.js'
|
|
|
14
14
|
import { describeDangerousFinding } from './dangerous-commands.js'
|
|
15
15
|
import { dangerousFindingFor, evaluateRule } from './rules.js'
|
|
16
16
|
import type { ShellDialect } from './shell-lexer.js'
|
|
17
|
+
import { withShellSession } from './shell-session-state.js'
|
|
17
18
|
|
|
18
19
|
export interface ToolCallContext {
|
|
19
20
|
readonly toolName: string
|
|
@@ -32,6 +33,12 @@ export interface ToolCallContext {
|
|
|
32
33
|
* omitted, it is read the same as a host-defined tool.
|
|
33
34
|
*/
|
|
34
35
|
readonly toolSource?: ToolSourceRef
|
|
36
|
+
/**
|
|
37
|
+
* The shell session the call runs in. The gate reads a command line with
|
|
38
|
+
* the integer names earlier lines of that session declared (see
|
|
39
|
+
* `shell-session-state.ts`), in every rule, predicates included.
|
|
40
|
+
*/
|
|
41
|
+
readonly sessionId?: string
|
|
35
42
|
}
|
|
36
43
|
|
|
37
44
|
/**
|
|
@@ -250,6 +257,10 @@ export class AuthorizationGate {
|
|
|
250
257
|
}
|
|
251
258
|
|
|
252
259
|
evaluate(ctx: ToolCallContext): GateEvaluationResult {
|
|
260
|
+
return withShellSession(ctx.sessionId, () => this.evaluateIn(ctx))
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
private evaluateIn(ctx: ToolCallContext): GateEvaluationResult {
|
|
253
264
|
if (!this.enabled) {
|
|
254
265
|
return {
|
|
255
266
|
decision: 'review',
|
|
@@ -32,11 +32,22 @@ export const PROTECTED_DIRECTORIES: readonly string[] = [
|
|
|
32
32
|
'.devcontainer',
|
|
33
33
|
'.yarn',
|
|
34
34
|
'.mvn',
|
|
35
|
+
// Credential homes: a key, token or kubeconfig written here is used later
|
|
36
|
+
// by every command that signs in with it.
|
|
37
|
+
'.ssh',
|
|
38
|
+
'.aws',
|
|
39
|
+
'.azure',
|
|
40
|
+
'.gnupg',
|
|
41
|
+
'.kube',
|
|
42
|
+
'.docker',
|
|
35
43
|
]
|
|
36
44
|
|
|
37
45
|
/** Directory sequences; the segments must be adjacent. */
|
|
38
46
|
export const PROTECTED_NESTED_DIRECTORIES: readonly (readonly string[])[] = [
|
|
39
47
|
['.config', 'git'],
|
|
48
|
+
['.config', 'gh'],
|
|
49
|
+
['.config', 'glab-cli'],
|
|
50
|
+
['.config', 'gcloud'],
|
|
40
51
|
// A skill, agent or command folder is read back as instructions, and a
|
|
41
52
|
// skill's hooks run commands. `.agents/skills` is one of the folders Namzu
|
|
42
53
|
// loads skills from, at every level from the checkout root down.
|
|
@@ -124,10 +135,43 @@ const PROJECT_DIRECTORY = '.namzu'
|
|
|
124
135
|
const SKILL_FILE = 'skill.md'
|
|
125
136
|
|
|
126
137
|
/** Lower case, with the two letters that fold into ASCII on some file systems. */
|
|
127
|
-
function
|
|
138
|
+
function lower(name: string): string {
|
|
128
139
|
return name.toLowerCase().replace(/ı/g, 'i').replace(/ſ/g, 's')
|
|
129
140
|
}
|
|
130
141
|
|
|
142
|
+
/** The six letters an 8.3 short name keeps of a long one: no dots, no spaces. */
|
|
143
|
+
function shortStem(name: string): string {
|
|
144
|
+
return name.replace(/[^a-z0-9]/g, '').slice(0, 6)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Protected names by the stem their NTFS short alias (`GIT~1` for `.git`) starts with.
|
|
148
|
+
const SHORT_STEMS = new Map<string, string>()
|
|
149
|
+
function rememberShortNames(names: readonly string[]): void {
|
|
150
|
+
for (const raw of names) {
|
|
151
|
+
const name = lower(raw)
|
|
152
|
+
const stem = shortStem(name)
|
|
153
|
+
if (stem !== '' && !SHORT_STEMS.has(stem)) SHORT_STEMS.set(stem, name)
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* A path segment as the file system names it: lower case, with the two letters
|
|
159
|
+
* that fold into ASCII, a stream suffix (`:$INDEX_ALLOCATION`) dropped, the
|
|
160
|
+
* trailing dots and spaces Windows ignores removed, and an 8.3 alias read as
|
|
161
|
+
* the long name it stands for.
|
|
162
|
+
*/
|
|
163
|
+
function fold(name: string): string {
|
|
164
|
+
let out = lower(name)
|
|
165
|
+
const colon = out.indexOf(':')
|
|
166
|
+
if (colon > 0) out = out.slice(0, colon)
|
|
167
|
+
const trimmed = out.replace(/[. ]+$/, '')
|
|
168
|
+
if (trimmed !== '') out = trimmed
|
|
169
|
+
const alias = /^([a-z0-9]{1,6})~\d+$/.exec(out)
|
|
170
|
+
if (alias !== null) return SHORT_STEMS.get(alias[1] as string) ?? out
|
|
171
|
+
return out
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
rememberShortNames([...PROTECTED_DIRECTORIES, ...PROTECTED_FILE_NAMES])
|
|
131
175
|
const AUTHORED = new Set(PROJECT_DIRECTORY_AUTHORED_FOLDERS.map(fold))
|
|
132
176
|
const DIRECTORIES = new Set(PROTECTED_DIRECTORIES.map(fold))
|
|
133
177
|
const FILE_NAMES = new Set(PROTECTED_FILE_NAMES.map(fold))
|
|
@@ -25,20 +25,33 @@
|
|
|
25
25
|
* No `-i`, `-e`, `-f`, no substitution, no `w`, `r`, `e`, `y` or `d`, no
|
|
26
26
|
* regular-expression address: every one of those is refused.
|
|
27
27
|
*
|
|
28
|
+
* - `gh` is read-only only as one of the named forms (`gh pr view`, `gh issue
|
|
29
|
+
* list`, `gh run view`, `gh search code`, ...) with the flags its table
|
|
30
|
+
* names. `gh api`, `--web`, `-q/--jq`, `--template`, `--hostname`, a leading
|
|
31
|
+
* `--repo`, `GH_HOST=` and `GH_REPO=` assignments, an extension or an alias
|
|
32
|
+
* are in no table, so they are refused; a repository argument naming a
|
|
33
|
+
* host, a URL or `user@host` is refused.
|
|
34
|
+
*
|
|
28
35
|
* Not ported, and so never read-only here: `ps`, `lsof`, `ss`, `date`,
|
|
29
|
-
* `man`, `xargs`, `fd`, `
|
|
30
|
-
* and the shell builtins other than `cd`.
|
|
31
|
-
*
|
|
32
|
-
*
|
|
36
|
+
* `man`, `xargs`, `fd`, `docker logs|inspect`, `printf`, `[[`, `test`
|
|
37
|
+
* and the shell builtins other than `cd`.
|
|
38
|
+
*
|
|
39
|
+
* A `git` or `gh` line is not read-only when the folder it starts in, or one
|
|
40
|
+
* above it, holds `HEAD`, `objects/` and `refs/` outside a `.git` folder: git
|
|
41
|
+
* would read it as a repository and run what its `config` names. The folder is
|
|
42
|
+
* the session's own (`withShellSession`), or `options.directory`.
|
|
33
43
|
*
|
|
34
44
|
* This decides only "does not need a prompt for being a command". The path
|
|
35
45
|
* floor still applies: a read-only command that reads outside the roots is
|
|
36
46
|
* asked about, and so is anything the protected-path and removal floors see.
|
|
37
47
|
*/
|
|
38
48
|
|
|
49
|
+
import { pluginSuppliesProgram } from '../plugin/bin-path.js'
|
|
39
50
|
import type { ShellDialect } from '../types/tool/index.js'
|
|
51
|
+
import { bareRepositoryIndicator } from './bare-repository.js'
|
|
40
52
|
import { FLAG_TABLES, type FlagTable } from './readonly-flags.js'
|
|
41
53
|
import { type ShellWord, lexShellCommandLine } from './shell-lexer.js'
|
|
54
|
+
import { currentShellDirectory } from './shell-session-state.js'
|
|
42
55
|
|
|
43
56
|
/** Lines longer than this are not analysed (the budget). */
|
|
44
57
|
const MAX_LINE_LENGTH = 20_000
|
|
@@ -418,6 +431,34 @@ function flagsAreVetted(
|
|
|
418
431
|
return true
|
|
419
432
|
}
|
|
420
433
|
|
|
434
|
+
// -- `gh` hardening --------------------------------------------------------
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* Whether an argument of a vetted `gh` form names somewhere other than a
|
|
438
|
+
* repository of the current host. `gh` sends the stored token to whatever
|
|
439
|
+
* host a repository argument names, so `--repo github.example.net/o/r`, a URL,
|
|
440
|
+
* `user@host` and a `~` path are refused; `--repo owner/name` (one slash) and a
|
|
441
|
+
* number, branch or workflow file are the ordinary reads. This applies to the
|
|
442
|
+
* flag values and the operands alike.
|
|
443
|
+
*/
|
|
444
|
+
function ghValueIsDangerous(args: readonly string[]): boolean {
|
|
445
|
+
for (const arg of args) {
|
|
446
|
+
if (arg === '') continue
|
|
447
|
+
if (arg.includes('~')) return true
|
|
448
|
+
let value = arg
|
|
449
|
+
if (arg.startsWith('-')) {
|
|
450
|
+
const equals = arg.indexOf('=')
|
|
451
|
+
if (equals === -1) continue
|
|
452
|
+
value = arg.slice(equals + 1)
|
|
453
|
+
if (value === '') continue
|
|
454
|
+
}
|
|
455
|
+
if (value.includes('://') || value.includes('@') || value.includes('\\')) return true
|
|
456
|
+
if (looksLikeNetworkPath(value)) return true
|
|
457
|
+
if ((value.match(/\//g) ?? []).length >= 2) return true
|
|
458
|
+
}
|
|
459
|
+
return false
|
|
460
|
+
}
|
|
461
|
+
|
|
421
462
|
// -- `git` hardening -------------------------------------------------------
|
|
422
463
|
|
|
423
464
|
const SIGNATURE = /%[-+ ]?G|%\(\*?signature/
|
|
@@ -669,6 +710,21 @@ function dockerIsReadOnly(args: readonly string[]): boolean {
|
|
|
669
710
|
const GIT_NEUTRAL_GLOBALS: ReadonlySet<string> = new Set(['--no-optional-locks', '--no-pager'])
|
|
670
711
|
|
|
671
712
|
function commandIsReadOnly(vector: readonly string[], text: string): boolean {
|
|
713
|
+
if (!commandIsReadOnlyByList(vector, text)) return false
|
|
714
|
+
// A program an enabled plugin ships may be what this name runs. Asked only
|
|
715
|
+
// after the list approved the command, so a refusal costs no file reads.
|
|
716
|
+
return !pluginSuppliesProgram(headOf(vector))
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
function headOf(vector: readonly string[]): string {
|
|
720
|
+
let argv = vector
|
|
721
|
+
while (argv[0] === 'git' && argv[1] !== undefined && GIT_NEUTRAL_GLOBALS.has(argv[1])) {
|
|
722
|
+
argv = ['git', ...argv.slice(2)]
|
|
723
|
+
}
|
|
724
|
+
return argv[0] ?? ''
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
function commandIsReadOnlyByList(vector: readonly string[], text: string): boolean {
|
|
672
728
|
// `git --no-optional-locks status`: the option keeps git from taking the
|
|
673
729
|
// index lock for an opportunistic refresh, so it only makes a read gentler.
|
|
674
730
|
let argv = vector
|
|
@@ -741,6 +797,7 @@ function commandIsReadOnly(vector: readonly string[], text: string): boolean {
|
|
|
741
797
|
}
|
|
742
798
|
if (!flagsAreVetted(argv, words, flagTable, head)) return false
|
|
743
799
|
if ((GREP_FAMILY.has(head) || head === 'rg') && /[\n\r]/.test(text)) return false
|
|
800
|
+
if (head === 'gh' && ghValueIsDangerous(rest2)) return false
|
|
744
801
|
const check = GIT_CHECKS[key]
|
|
745
802
|
if (check?.(rest2)) return false
|
|
746
803
|
return true
|
|
@@ -786,7 +843,11 @@ function redirectionsAreHarmless(
|
|
|
786
843
|
* Whether `line` only reads: every command in it is vetted and nothing in it
|
|
787
844
|
* is decided at run time. False for anything this module cannot vouch for.
|
|
788
845
|
*/
|
|
789
|
-
export function isReadOnlyCommandLine(
|
|
846
|
+
export function isReadOnlyCommandLine(
|
|
847
|
+
line: string,
|
|
848
|
+
dialect: ShellDialect = 'bash',
|
|
849
|
+
options: { readonly directory?: string } = {},
|
|
850
|
+
): boolean {
|
|
790
851
|
if (dialect === 'cmd') return false
|
|
791
852
|
if (line.trim() === '' || line.length > MAX_LINE_LENGTH) return false
|
|
792
853
|
if (hasDynamicSyntax(line)) return false
|
|
@@ -825,9 +886,17 @@ export function isReadOnlyCommandLine(line: string, dialect: ShellDialect = 'bas
|
|
|
825
886
|
|
|
826
887
|
const argv = words.map((word) => word.value)
|
|
827
888
|
if (!commandIsReadOnly(argv, command.text)) return false
|
|
828
|
-
if (head.value === 'git') runsGit = true
|
|
889
|
+
if (head.value === 'git' || head.value === 'gh') runsGit = true
|
|
829
890
|
if (head.value === 'cd') changesDirectory = true
|
|
830
891
|
}
|
|
831
892
|
if (runsGit && changesDirectory) return false
|
|
893
|
+
// Git trusts the folder it starts in. The directory of the session carries
|
|
894
|
+
// over between calls, so `cd vendor/cache` and `git status` are two lines
|
|
895
|
+
// that are only dangerous together. A folder that looks like a bare
|
|
896
|
+
// repository, here or above, is a question for a person.
|
|
897
|
+
if (runsGit) {
|
|
898
|
+
const directory = options.directory ?? currentShellDirectory()
|
|
899
|
+
if (directory !== undefined && bareRepositoryIndicator(directory) !== undefined) return false
|
|
900
|
+
}
|
|
832
901
|
return true
|
|
833
902
|
}
|
|
@@ -192,4 +192,107 @@ export const FLAG_TABLES: Readonly<Record<string, FlagTable>> = {
|
|
|
192
192
|
'-P -I --gitfile --infofile --charset --timefmt --sort -H --hintro --houtro -T --scheme --authority',
|
|
193
193
|
number: '-L --filelimit',
|
|
194
194
|
}),
|
|
195
|
+
// `gh`: the forms that only read from GitHub. A form not named here, `gh api`,
|
|
196
|
+
// `gh pr checkout`, `gh <extension>` or an alias included, is not read-only.
|
|
197
|
+
// No form takes `--web`, `-q/--jq`, `-t/--template`, `--output`, `--hostname`
|
|
198
|
+
// or a body flag.
|
|
199
|
+
'gh pr view': table({
|
|
200
|
+
none: '--comments',
|
|
201
|
+
string: '--json --repo -R',
|
|
202
|
+
}),
|
|
203
|
+
'gh pr list': table({
|
|
204
|
+
none: '--draft',
|
|
205
|
+
string: '--state -s --author --assignee --label --base --head --search --json --app --repo -R',
|
|
206
|
+
number: '--limit -L',
|
|
207
|
+
}),
|
|
208
|
+
'gh pr diff': table({
|
|
209
|
+
none: '--name-only --patch',
|
|
210
|
+
string: '--color --repo -R',
|
|
211
|
+
}),
|
|
212
|
+
'gh pr checks': table({
|
|
213
|
+
none: '--watch --required --fail-fast',
|
|
214
|
+
string: '--json --repo -R',
|
|
215
|
+
number: '--interval',
|
|
216
|
+
}),
|
|
217
|
+
'gh issue view': table({
|
|
218
|
+
none: '--comments',
|
|
219
|
+
string: '--json --repo -R',
|
|
220
|
+
}),
|
|
221
|
+
'gh issue list': table({
|
|
222
|
+
string: '--state -s --assignee --author --label --milestone --search --json --app --repo -R',
|
|
223
|
+
number: '--limit -L',
|
|
224
|
+
}),
|
|
225
|
+
'gh repo view': table({
|
|
226
|
+
string: '--json',
|
|
227
|
+
}),
|
|
228
|
+
'gh run list': table({
|
|
229
|
+
string:
|
|
230
|
+
'--branch -b --status -s --workflow -w --json --repo -R --event -e --user -u --created --commit -c',
|
|
231
|
+
number: '--limit -L',
|
|
232
|
+
}),
|
|
233
|
+
'gh run view': table({
|
|
234
|
+
none: '--log --log-failed --exit-status --verbose -v',
|
|
235
|
+
string: '--json --repo -R --job -j',
|
|
236
|
+
number: '--attempt -a',
|
|
237
|
+
}),
|
|
238
|
+
'gh auth status': table({
|
|
239
|
+
none: '--active -a',
|
|
240
|
+
string: '--json',
|
|
241
|
+
}),
|
|
242
|
+
'gh pr status': table({
|
|
243
|
+
none: '--conflict-status -c',
|
|
244
|
+
string: '--json --repo -R',
|
|
245
|
+
}),
|
|
246
|
+
'gh issue status': table({
|
|
247
|
+
string: '--json --repo -R',
|
|
248
|
+
}),
|
|
249
|
+
'gh release list': table({
|
|
250
|
+
none: '--exclude-drafts --exclude-pre-releases',
|
|
251
|
+
string: '--json --order -O --repo -R',
|
|
252
|
+
number: '--limit -L',
|
|
253
|
+
}),
|
|
254
|
+
'gh release view': table({
|
|
255
|
+
string: '--json --repo -R',
|
|
256
|
+
}),
|
|
257
|
+
'gh workflow list': table({
|
|
258
|
+
none: '--all -a',
|
|
259
|
+
string: '--json --repo -R',
|
|
260
|
+
number: '--limit -L',
|
|
261
|
+
}),
|
|
262
|
+
'gh workflow view': table({
|
|
263
|
+
none: '--yaml -y',
|
|
264
|
+
string: '--ref -r --repo -R',
|
|
265
|
+
}),
|
|
266
|
+
'gh label list': table({
|
|
267
|
+
string: '--json --order --search -S --sort --repo -R',
|
|
268
|
+
number: '--limit -L',
|
|
269
|
+
}),
|
|
270
|
+
'gh search repos': table({
|
|
271
|
+
none: '--archived',
|
|
272
|
+
string:
|
|
273
|
+
'--created --followers --forks --good-first-issues --help-wanted-issues --include-forks --json --language --license --match --number-topics --order --owner --size --sort --stars --topic --updated --visibility',
|
|
274
|
+
number: '--limit -L',
|
|
275
|
+
}),
|
|
276
|
+
'gh search issues': table({
|
|
277
|
+
none: '--include-prs --locked --no-assignee --no-label --no-milestone --no-project',
|
|
278
|
+
string:
|
|
279
|
+
'--app --assignee --author --closed --commenter --comments --created --interactions --involves --json --label --language --match --mentions --milestone --order --owner --project --reactions --repo -R --sort --state --team-mentions --updated --visibility',
|
|
280
|
+
number: '--limit -L',
|
|
281
|
+
}),
|
|
282
|
+
'gh search prs': table({
|
|
283
|
+
none: '--draft --locked --merged --no-assignee --no-label --no-milestone --no-project',
|
|
284
|
+
string:
|
|
285
|
+
'--app --assignee --author --base -B --checks --closed --commenter --comments --created --head -H --interactions --involves --json --label --language --match --mentions --merged-at --milestone --order --owner --project --reactions --repo -R --review --review-requested --reviewed-by --sort --state --team-mentions --updated --visibility',
|
|
286
|
+
number: '--limit -L',
|
|
287
|
+
}),
|
|
288
|
+
'gh search commits': table({
|
|
289
|
+
none: '--merge',
|
|
290
|
+
string:
|
|
291
|
+
'--author --author-date --author-email --author-name --committer --committer-date --committer-email --committer-name --hash --json --order --owner --parent --repo -R --sort --tree --visibility',
|
|
292
|
+
number: '--limit -L',
|
|
293
|
+
}),
|
|
294
|
+
'gh search code': table({
|
|
295
|
+
string: '--extension --filename --json --language --match --owner --repo -R --size',
|
|
296
|
+
number: '--limit -L',
|
|
297
|
+
}),
|
|
195
298
|
}
|