@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,280 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises'
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
import type { ToolContext, ToolResult } from '../../types/tool/index.js'
|
|
4
|
+
import type { ToolFacts } from '../../types/tool/presentation.js'
|
|
5
|
+
import { defineTool } from '../defineTool.js'
|
|
6
|
+
import { resolveWithinAnyReal, toolRoots } from '../paths.js'
|
|
7
|
+
import { atomicWriteFile } from './atomic-write-file.js'
|
|
8
|
+
import { clip } from './classifier-input.js'
|
|
9
|
+
import { CURRENT_ON_DISK, movedSinceRead, staleFileError } from './content-fingerprint.js'
|
|
10
|
+
import { withFileMutationLock } from './file-mutation-lock.js'
|
|
11
|
+
import { lineDiff } from './line-diff.js'
|
|
12
|
+
import { applyNotebookEdit } from './notebook-cells.js'
|
|
13
|
+
import { isNotebookPath, notebookRefusal } from './notebook-guard.js'
|
|
14
|
+
import { NOTEBOOK_MAX_BYTES } from './read-media.js'
|
|
15
|
+
|
|
16
|
+
const inputSchema = z
|
|
17
|
+
.object({
|
|
18
|
+
notebook_path: z
|
|
19
|
+
.string()
|
|
20
|
+
.min(1)
|
|
21
|
+
.refine((value) => value.trim().length > 0, 'notebook_path must not be empty.')
|
|
22
|
+
.describe('The path of the Jupyter notebook (.ipynb) to edit.'),
|
|
23
|
+
cell_id: z
|
|
24
|
+
.string()
|
|
25
|
+
.optional()
|
|
26
|
+
.describe(
|
|
27
|
+
'The ID of the cell to edit. When inserting, the new cell goes after the cell with this ID, or at the beginning when it is not given.',
|
|
28
|
+
),
|
|
29
|
+
new_source: z
|
|
30
|
+
.string()
|
|
31
|
+
.optional()
|
|
32
|
+
.describe('The new source for the cell. Not needed to delete.'),
|
|
33
|
+
cell_type: z
|
|
34
|
+
.enum(['code', 'markdown'])
|
|
35
|
+
.optional()
|
|
36
|
+
.describe(
|
|
37
|
+
'The type of the cell (code or markdown). When left out, a replaced cell keeps its type. Required when inserting.',
|
|
38
|
+
),
|
|
39
|
+
edit_mode: z
|
|
40
|
+
.enum(['replace', 'insert', 'delete'])
|
|
41
|
+
.optional()
|
|
42
|
+
.describe('The kind of edit (replace, insert or delete). Defaults to replace.'),
|
|
43
|
+
})
|
|
44
|
+
.strict()
|
|
45
|
+
|
|
46
|
+
type NotebookEditInput = z.infer<typeof inputSchema>
|
|
47
|
+
|
|
48
|
+
const modelInputSchema: Record<string, unknown> = {
|
|
49
|
+
type: 'object',
|
|
50
|
+
properties: {
|
|
51
|
+
notebook_path: {
|
|
52
|
+
type: 'string',
|
|
53
|
+
description: 'The path of the Jupyter notebook (.ipynb) to edit.',
|
|
54
|
+
},
|
|
55
|
+
cell_id: {
|
|
56
|
+
type: 'string',
|
|
57
|
+
description:
|
|
58
|
+
'The ID of the cell to edit. When inserting, the new cell goes after the cell with this ID, or at the beginning when it is not given.',
|
|
59
|
+
},
|
|
60
|
+
new_source: {
|
|
61
|
+
type: 'string',
|
|
62
|
+
description: 'The new source for the cell. Not needed to delete.',
|
|
63
|
+
},
|
|
64
|
+
cell_type: {
|
|
65
|
+
type: 'string',
|
|
66
|
+
enum: ['code', 'markdown'],
|
|
67
|
+
description:
|
|
68
|
+
'The type of the cell (code or markdown). When left out, a replaced cell keeps its type. Required when inserting.',
|
|
69
|
+
},
|
|
70
|
+
edit_mode: {
|
|
71
|
+
type: 'string',
|
|
72
|
+
enum: ['replace', 'insert', 'delete'],
|
|
73
|
+
description: 'The kind of edit (replace, insert or delete). Defaults to replace.',
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
required: ['notebook_path'],
|
|
77
|
+
additionalProperties: false,
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const SHAPES =
|
|
81
|
+
'Replace: {"notebook_path":"a.ipynb","cell_id":"<id>","new_source":"print(1)"}. Insert after a cell: {"notebook_path":"a.ipynb","cell_id":"<id>","new_source":"# Title","cell_type":"markdown","edit_mode":"insert"} (leave out cell_id to insert at the top; cell_type is required). Delete: {"notebook_path":"a.ipynb","cell_id":"<id>","edit_mode":"delete"}.'
|
|
82
|
+
|
|
83
|
+
type Failure = { success: false; output: ''; error: string; facts?: ToolFacts }
|
|
84
|
+
|
|
85
|
+
function failure(error: string, facts?: ToolFacts): Failure {
|
|
86
|
+
return { success: false, output: '', error, ...(facts ? { facts } : {}) }
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Why the notebook cannot be edited from what the session has read, or `undefined` when it can. */
|
|
90
|
+
function freshnessProblem(context: ToolContext, key: string, current: string): Failure | undefined {
|
|
91
|
+
const tracker = context.fileReadTracker
|
|
92
|
+
if (!tracker) return undefined
|
|
93
|
+
if (!tracker.hasRead(key)) {
|
|
94
|
+
return failure(
|
|
95
|
+
`${key} has not been read in this conversation, so no cell was changed. Read the notebook with the \`read\` tool (it shows each cell with its id), then call \`notebook_edit\` again.`,
|
|
96
|
+
{ kind: 'failure', reason: 'not_read', subject: key },
|
|
97
|
+
)
|
|
98
|
+
}
|
|
99
|
+
if (movedSinceRead(tracker, key, current)) {
|
|
100
|
+
tracker.recordDriftObserved?.(key)
|
|
101
|
+
return failure(staleFileError(key), {
|
|
102
|
+
kind: 'failure',
|
|
103
|
+
reason: 'changed_on_disk',
|
|
104
|
+
subject: key,
|
|
105
|
+
})
|
|
106
|
+
}
|
|
107
|
+
return undefined
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function record(context: ToolContext, key: string, content: string): void {
|
|
111
|
+
const tracker = context.fileReadTracker
|
|
112
|
+
if (!tracker) return
|
|
113
|
+
if (tracker.recordEdit && context.toolUseId) {
|
|
114
|
+
tracker.recordEdit(key, content, context.toolUseId)
|
|
115
|
+
return
|
|
116
|
+
}
|
|
117
|
+
tracker.recordRead(key, content)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async function readHost(path: string): Promise<string | undefined> {
|
|
121
|
+
try {
|
|
122
|
+
return await readFile(path, 'utf-8')
|
|
123
|
+
} catch (error) {
|
|
124
|
+
if ((error as { code?: unknown } | null)?.code === 'ENOENT') return undefined
|
|
125
|
+
throw error
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* What can be refused before a person is asked: arguments that cannot work, a
|
|
131
|
+
* notebook the session never read, one that moved since it was read. The text
|
|
132
|
+
* is the one `execute` gives.
|
|
133
|
+
*/
|
|
134
|
+
async function refuseBeforeReview(
|
|
135
|
+
input: NotebookEditInput,
|
|
136
|
+
context: ToolContext,
|
|
137
|
+
): Promise<{ readonly error: string; readonly facts?: ToolFacts } | undefined> {
|
|
138
|
+
const parsed = inputSchema.safeParse(input)
|
|
139
|
+
if (!parsed.success) return undefined
|
|
140
|
+
const path = parsed.data.notebook_path
|
|
141
|
+
if (!isNotebookPath(path)) return { error: NOT_A_NOTEBOOK }
|
|
142
|
+
if (context.sandbox) return undefined
|
|
143
|
+
let key: string
|
|
144
|
+
let current: string | undefined
|
|
145
|
+
try {
|
|
146
|
+
key = await resolveWithinAnyReal(toolRoots(context), path)
|
|
147
|
+
current = await readHost(key)
|
|
148
|
+
} catch {
|
|
149
|
+
return undefined
|
|
150
|
+
}
|
|
151
|
+
if (current === undefined) return undefined
|
|
152
|
+
const problem = freshnessProblem(context, key, current)
|
|
153
|
+
return problem
|
|
154
|
+
? { error: problem.error, ...(problem.facts ? { facts: problem.facts } : {}) }
|
|
155
|
+
: undefined
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const NOT_A_NOTEBOOK =
|
|
159
|
+
'notebook_path must name a Jupyter notebook (a .ipynb file). To change any other file use `edit`.'
|
|
160
|
+
|
|
161
|
+
export const NotebookEditTool = defineTool({
|
|
162
|
+
name: 'notebook_edit',
|
|
163
|
+
description:
|
|
164
|
+
'Replaces, inserts or deletes a single cell in a Jupyter notebook (.ipynb file). Everything else in the notebook (other cells, metadata, format) is kept as it was (the file is saved as JSON with the indent it had, so number spellings such as `1.0` may become `1`; a notebook that cannot be rewritten exactly is refused).\n\nUsage:\n- You must use the `read` tool on the notebook in this conversation before editing; this tool fails otherwise, and also when the notebook changed on disk since you read it.\n- `cell_id` is the `id` shown in the `<cell id="...">` rows of the `read` output. It is required for `replace` and `delete`.\n- `edit_mode` defaults to `replace`, which sets the cell\'s source (and clears the output and run count of a code cell, which belonged to the old code). `insert` adds a new cell after the cell with the given `cell_id`, or at the beginning of the notebook when `cell_id` is left out; `cell_type` is required when inserting. `delete` removes the cell.\n- A notebook change that is not a single cell (the notebook\'s metadata, several cells at once) is a job for `edit`; use this tool for cell text.',
|
|
165
|
+
inputSchema,
|
|
166
|
+
modelInputSchema,
|
|
167
|
+
enforceModelInput: true,
|
|
168
|
+
validationErrorHint: SHAPES,
|
|
169
|
+
malformedInputHint: `${SHAPES} Inside new_source, a newline is \\n and a quote is \\".`,
|
|
170
|
+
category: 'filesystem',
|
|
171
|
+
// Declared so a path outside the turn's roots is reviewed before the call
|
|
172
|
+
// runs. See `ToolDefinition.pathArgument`.
|
|
173
|
+
pathArgument: 'notebook_path',
|
|
174
|
+
refuseBeforeReview,
|
|
175
|
+
classifierInput: (input: NotebookEditInput) =>
|
|
176
|
+
clip(
|
|
177
|
+
`${input.notebook_path}: ${input.edit_mode ?? 'replace'} cell ${input.cell_id ?? '(start)'}${input.new_source !== undefined ? `, ${input.new_source.length} characters` : ''}`,
|
|
178
|
+
500,
|
|
179
|
+
),
|
|
180
|
+
permissions: ['file_write'],
|
|
181
|
+
readOnly: false,
|
|
182
|
+
destructive: false,
|
|
183
|
+
concurrencySafe: false,
|
|
184
|
+
|
|
185
|
+
presentCall(input: NotebookEditInput) {
|
|
186
|
+
return { kind: 'generic' as const, label: input.notebook_path }
|
|
187
|
+
},
|
|
188
|
+
|
|
189
|
+
presentResult(_input: NotebookEditInput, result: ToolResult) {
|
|
190
|
+
return { kind: 'generic' as const, label: result.output?.split('\n')[0] ?? '' }
|
|
191
|
+
},
|
|
192
|
+
|
|
193
|
+
async execute(input: NotebookEditInput, context) {
|
|
194
|
+
const parsed = inputSchema.safeParse(input)
|
|
195
|
+
if (!parsed.success) {
|
|
196
|
+
return failure(
|
|
197
|
+
`Invalid notebook_edit input: ${parsed.error.issues.map((issue) => issue.message).join('; ')}`,
|
|
198
|
+
)
|
|
199
|
+
}
|
|
200
|
+
const valid = parsed.data
|
|
201
|
+
if (!isNotebookPath(valid.notebook_path)) return failure(NOT_A_NOTEBOOK)
|
|
202
|
+
const edit = {
|
|
203
|
+
cellId: valid.cell_id,
|
|
204
|
+
newSource: valid.new_source,
|
|
205
|
+
cellType: valid.cell_type,
|
|
206
|
+
editMode: valid.edit_mode ?? 'replace',
|
|
207
|
+
} as const
|
|
208
|
+
|
|
209
|
+
const hostPath = context.sandbox
|
|
210
|
+
? undefined
|
|
211
|
+
: await resolveWithinAnyReal(toolRoots(context), valid.notebook_path)
|
|
212
|
+
const key = hostPath ?? valid.notebook_path
|
|
213
|
+
const lockKey = context.sandbox ? `sandbox:${key}` : `local:${key}`
|
|
214
|
+
|
|
215
|
+
return withFileMutationLock(lockKey, async () => {
|
|
216
|
+
let before: string | undefined
|
|
217
|
+
if (context.sandbox) {
|
|
218
|
+
try {
|
|
219
|
+
before = (await context.sandbox.readFile(key)).toString('utf-8')
|
|
220
|
+
} catch {
|
|
221
|
+
before = undefined
|
|
222
|
+
}
|
|
223
|
+
} else {
|
|
224
|
+
before = await readHost(key)
|
|
225
|
+
}
|
|
226
|
+
if (before === undefined) return failure(`Notebook file does not exist: ${key}.`)
|
|
227
|
+
if (Buffer.byteLength(before) > NOTEBOOK_MAX_BYTES) {
|
|
228
|
+
return failure(
|
|
229
|
+
`${key} is larger than this tool reads. Change it with \`edit\` or a shell command. The file was not changed.`,
|
|
230
|
+
)
|
|
231
|
+
}
|
|
232
|
+
const stale = freshnessProblem(context, key, before)
|
|
233
|
+
if (stale) return stale
|
|
234
|
+
|
|
235
|
+
const outcome = applyNotebookEdit(before, edit)
|
|
236
|
+
if (!outcome.ok) return failure(outcome.error)
|
|
237
|
+
// The same check `edit` and `write` make: whatever was done, the file must still open.
|
|
238
|
+
const refusal = notebookRefusal(key, outcome.content, before)
|
|
239
|
+
if (refusal) return failure(refusal)
|
|
240
|
+
if (Buffer.byteLength(outcome.content) > NOTEBOOK_MAX_BYTES) {
|
|
241
|
+
return failure(
|
|
242
|
+
'The updated notebook would be larger than this tool can read. The file was not changed.',
|
|
243
|
+
)
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
if (context.sandbox) await context.sandbox.writeFile(key, outcome.content)
|
|
247
|
+
else await atomicWriteFile(key, outcome.content)
|
|
248
|
+
record(context, key, outcome.content)
|
|
249
|
+
|
|
250
|
+
const diff = lineDiff(before, outcome.content)
|
|
251
|
+
const named = outcome.cellId ? `cell ${outcome.cellId}` : 'a new cell'
|
|
252
|
+
const done =
|
|
253
|
+
outcome.editMode === 'replace'
|
|
254
|
+
? `Updated cell ${outcome.cellId}`
|
|
255
|
+
: outcome.editMode === 'insert'
|
|
256
|
+
? `Inserted ${named}`
|
|
257
|
+
: `Deleted cell ${outcome.cellId}`
|
|
258
|
+
return {
|
|
259
|
+
success: true as const,
|
|
260
|
+
output: `${done} in ${key} (+${diff.added} -${diff.removed})${context.sandbox ? ' [sandboxed]' : ''}. ${CURRENT_ON_DISK}`,
|
|
261
|
+
data: {
|
|
262
|
+
notebook_path: key,
|
|
263
|
+
edit_mode: outcome.editMode,
|
|
264
|
+
cell_type: outcome.cellType,
|
|
265
|
+
...(outcome.cellId ? { cell_id: outcome.cellId } : {}),
|
|
266
|
+
...(outcome.oldSource !== undefined ? { old_source: outcome.oldSource } : {}),
|
|
267
|
+
},
|
|
268
|
+
facts: {
|
|
269
|
+
kind: 'edit' as const,
|
|
270
|
+
path: key,
|
|
271
|
+
replacements: 1,
|
|
272
|
+
added: diff.added,
|
|
273
|
+
removed: diff.removed,
|
|
274
|
+
...(diff.hunks.length > 0 ? { hunks: diff.hunks } : {}),
|
|
275
|
+
...(diff.truncated ? { hunksTruncated: true as const } : {}),
|
|
276
|
+
},
|
|
277
|
+
}
|
|
278
|
+
})
|
|
279
|
+
},
|
|
280
|
+
})
|
|
@@ -43,7 +43,8 @@ function shapeProblem(parsed: unknown): string | undefined {
|
|
|
43
43
|
function bodyProblem(content: string): string | undefined {
|
|
44
44
|
let parsed: unknown
|
|
45
45
|
try {
|
|
46
|
-
|
|
46
|
+
// A byte-order mark is how some editors save a notebook that opens fine.
|
|
47
|
+
parsed = JSON.parse(content.replace(/^\uFEFF/u, ''))
|
|
47
48
|
} catch (error) {
|
|
48
49
|
const reason = error instanceof Error ? error.message : String(error)
|
|
49
50
|
return `it is not valid JSON (${reason})`
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
import type { ToolDefinition } from '../../types/tool/index.js'
|
|
3
|
+
import { defineTool } from '../defineTool.js'
|
|
4
|
+
|
|
5
|
+
export const PUSH_NOTIFICATION_TOOL_NAME = 'push_notification'
|
|
6
|
+
|
|
7
|
+
/** The longest message one notification carries; the rest is cut. */
|
|
8
|
+
export const PUSH_NOTIFICATION_MAX_CHARS = 200
|
|
9
|
+
|
|
10
|
+
/** The least time between two notifications from one session. */
|
|
11
|
+
export const PUSH_NOTIFICATION_MIN_INTERVAL_MS = 60_000
|
|
12
|
+
|
|
13
|
+
const inputSchema = z.object({
|
|
14
|
+
message: z
|
|
15
|
+
.string()
|
|
16
|
+
.min(1)
|
|
17
|
+
.describe(
|
|
18
|
+
`The notification text. One short line, under ${PUSH_NOTIFICATION_MAX_CHARS} characters; a longer one is cut. Say what finished or what you need. Never put a secret, a token or file contents in it.`,
|
|
19
|
+
),
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
/** What the host did with one request. */
|
|
23
|
+
export type PushNotificationOutcome =
|
|
24
|
+
| { readonly status: 'sent' }
|
|
25
|
+
/** The person is at the terminal already, so a notification would repeat what they see. */
|
|
26
|
+
| { readonly status: 'user-present' }
|
|
27
|
+
/** The person turned notifications from the model off. */
|
|
28
|
+
| { readonly status: 'disabled' }
|
|
29
|
+
| { readonly status: 'unavailable'; readonly detail: string }
|
|
30
|
+
|
|
31
|
+
export interface PushNotificationToolOptions {
|
|
32
|
+
/** Raise one notification. The message is already one safe line. */
|
|
33
|
+
readonly notify: (message: string) => PushNotificationOutcome | Promise<PushNotificationOutcome>
|
|
34
|
+
/** The clock, in milliseconds; a test hands its own. */
|
|
35
|
+
readonly now?: () => number
|
|
36
|
+
/** Overrides {@link PUSH_NOTIFICATION_MIN_INTERVAL_MS}. */
|
|
37
|
+
readonly minIntervalMs?: number
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function isStripped(code: number): boolean {
|
|
41
|
+
return (
|
|
42
|
+
code <= 0x1f ||
|
|
43
|
+
(code >= 0x7f && code <= 0x9f) ||
|
|
44
|
+
code === 0xad ||
|
|
45
|
+
code === 0x061c ||
|
|
46
|
+
code === 0x180e ||
|
|
47
|
+
(code >= 0x200b && code <= 0x200f) ||
|
|
48
|
+
(code >= 0x2028 && code <= 0x202e) ||
|
|
49
|
+
(code >= 0x2060 && code <= 0x206f) ||
|
|
50
|
+
code === 0xfeff ||
|
|
51
|
+
(code >= 0xfff9 && code <= 0xfffb)
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* One safe line: control, format and bidirectional characters removed (a
|
|
57
|
+
* terminal reads escape sequences in what it is shown), whitespace runs
|
|
58
|
+
* collapsed, cut at the cap with an ellipsis.
|
|
59
|
+
*/
|
|
60
|
+
export function pushNotificationLine(text: string): string {
|
|
61
|
+
let out = ''
|
|
62
|
+
for (const ch of text) {
|
|
63
|
+
const code = ch.codePointAt(0) ?? 0
|
|
64
|
+
if (code === 0x09 || code === 0x0a || code === 0x0d) out += ' '
|
|
65
|
+
else if (!isStripped(code)) out += ch
|
|
66
|
+
}
|
|
67
|
+
out = out.replace(/\s+/g, ' ').trim()
|
|
68
|
+
const chars = [...out]
|
|
69
|
+
return chars.length > PUSH_NOTIFICATION_MAX_CHARS
|
|
70
|
+
? `${chars.slice(0, PUSH_NOTIFICATION_MAX_CHARS - 1).join('')}…`
|
|
71
|
+
: out
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const DESCRIPTION = `Send a desktop notification to the person's terminal, to pull their attention back. Use it only when a long task has finished or you need a decision and they have probably walked away, or they asked for notifications. Do not use it for routine progress, for a quick task, or while they are in the conversation: it is not sent when they are at the terminal, and at most one goes out a minute. One short line; never a secret.`
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Raises a notification through the host. The host owns delivery (the tool
|
|
78
|
+
* knows no terminal); the tool owns the message (one cleaned line, capped) and
|
|
79
|
+
* the pace (one a minute per session, counted only for notifications sent).
|
|
80
|
+
* Build it only where a person can see a notification; a host with nobody to
|
|
81
|
+
* notify does not offer it.
|
|
82
|
+
*/
|
|
83
|
+
export function createPushNotificationTool(
|
|
84
|
+
options: PushNotificationToolOptions,
|
|
85
|
+
): ToolDefinition<z.infer<typeof inputSchema>> {
|
|
86
|
+
const now = options.now ?? Date.now
|
|
87
|
+
const interval = options.minIntervalMs ?? PUSH_NOTIFICATION_MIN_INTERVAL_MS
|
|
88
|
+
let lastSentAt: number | undefined
|
|
89
|
+
return defineTool({
|
|
90
|
+
name: PUSH_NOTIFICATION_TOOL_NAME,
|
|
91
|
+
description: DESCRIPTION,
|
|
92
|
+
inputSchema,
|
|
93
|
+
category: 'custom',
|
|
94
|
+
permissions: [],
|
|
95
|
+
readOnly: true,
|
|
96
|
+
destructive: false,
|
|
97
|
+
concurrencySafe: false,
|
|
98
|
+
presentCall: (input) => ({
|
|
99
|
+
kind: 'generic',
|
|
100
|
+
label: `Notify · ${pushNotificationLine(input.message)}`,
|
|
101
|
+
presentation: 'activity',
|
|
102
|
+
}),
|
|
103
|
+
async execute(input) {
|
|
104
|
+
const message = pushNotificationLine(input.message)
|
|
105
|
+
if (message === '') {
|
|
106
|
+
const text = 'Not sent: the message is empty once control characters are removed.'
|
|
107
|
+
return { success: false, output: text, error: text }
|
|
108
|
+
}
|
|
109
|
+
const at = now()
|
|
110
|
+
if (lastSentAt !== undefined && at - lastSentAt < interval) {
|
|
111
|
+
const wait = Math.ceil((interval - (at - lastSentAt)) / 1000)
|
|
112
|
+
return {
|
|
113
|
+
success: true,
|
|
114
|
+
output: `Not sent: a notification went out a moment ago (one a minute). Try again in ${wait}s only if it still matters.`,
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
const outcome = await options.notify(message)
|
|
118
|
+
switch (outcome.status) {
|
|
119
|
+
case 'sent':
|
|
120
|
+
lastSentAt = at
|
|
121
|
+
return { success: true, output: 'Notification sent.', data: { message } }
|
|
122
|
+
case 'user-present':
|
|
123
|
+
return {
|
|
124
|
+
success: true,
|
|
125
|
+
output:
|
|
126
|
+
'Not sent: the person is at the terminal, so your reply here already reaches them.',
|
|
127
|
+
}
|
|
128
|
+
case 'disabled':
|
|
129
|
+
return {
|
|
130
|
+
success: true,
|
|
131
|
+
output: 'Not sent: the person has turned notifications from the model off.',
|
|
132
|
+
}
|
|
133
|
+
case 'unavailable':
|
|
134
|
+
return { success: true, output: `Not sent: ${outcome.detail}` }
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
})
|
|
138
|
+
}
|
|
@@ -42,7 +42,9 @@ const inputSchema = z.object({
|
|
|
42
42
|
.int()
|
|
43
43
|
.min(0)
|
|
44
44
|
.optional()
|
|
45
|
-
.describe(
|
|
45
|
+
.describe(
|
|
46
|
+
'Line number to start from, counted from 1 (offset 100 is line 100, as grep reports it). Defaults to 1; 0 is read as 1.',
|
|
47
|
+
),
|
|
46
48
|
limit: z.coerce.number().optional().describe('Maximum number of lines to read'),
|
|
47
49
|
pages: z
|
|
48
50
|
.string()
|
|
@@ -61,7 +63,7 @@ const inputSchema = z.object({
|
|
|
61
63
|
export const ReadFileTool = defineTool({
|
|
62
64
|
name: 'read',
|
|
63
65
|
description:
|
|
64
|
-
'Reads a file and returns its contents with line numbers: a right-aligned number, an arrow (→) and the line as it is in the file. The number and arrow are not file text; the tabs and spaces after the arrow are. Also reads images (PNG, JPEG, WebP), which come back as pictures; PDFs, whose pages come back as images (pass pages, for example "1-5", at most 20 pages per request; a PDF of more than 10 pages needs it); and Jupyter notebooks (.ipynb), which come back as cells with their outputs. Supports readRange ([start,end], 1-indexed inclusive) or offset/limit for large files. Without a window it returns the first 2000 lines and says so — pass offset/limit to continue. A file over 256 KiB is refused unless a window is named, and a result over about 25,000 tokens is cut to a first page that names the next call; pass allow_large only when you need all of it.',
|
|
66
|
+
'Reads a file and returns its contents with line numbers: a right-aligned number, an arrow (→) and the line as it is in the file. The number and arrow are not file text; the tabs and spaces after the arrow are. Also reads images (PNG, JPEG, WebP), which come back as pictures; PDFs, whose pages come back as images (pass pages, for example "1-5", at most 20 pages per request; a PDF of more than 10 pages needs it); and Jupyter notebooks (.ipynb), which come back as cells with their outputs. Supports readRange ([start,end], 1-indexed inclusive) or offset (a line number from 1)/limit for large files. Without a window it returns the first 2000 lines and says so — pass offset/limit to continue. A file over 256 KiB is refused unless a window is named, and a result over about 25,000 tokens is cut to a first page that names the next call; pass allow_large only when you need all of it.',
|
|
65
67
|
inputSchema,
|
|
66
68
|
category: 'filesystem',
|
|
67
69
|
// Declared so a path outside the turn's roots can be reviewed before the
|
|
@@ -292,6 +294,10 @@ async function readMediaFile(
|
|
|
292
294
|
? await readPdfPages(buffer, input.pages, path, context.abortSignal)
|
|
293
295
|
: readNotebook(buffer, path)
|
|
294
296
|
if (!media.ok) return mediaFailure(path, buffer.length, media.message, sandboxed)
|
|
297
|
+
// A notebook shown whole is a read like any other: the body is what a later
|
|
298
|
+
// edit of it is checked against, and `notebook_edit` refuses a notebook the
|
|
299
|
+
// session has not read.
|
|
300
|
+
if (kind === 'notebook') context.fileReadTracker?.recordRead(path, buffer.toString('utf-8'))
|
|
295
301
|
const text = media.parts
|
|
296
302
|
.filter((part) => part.type === 'text')
|
|
297
303
|
.map((part) => part.text)
|
|
@@ -422,7 +428,7 @@ function windowKey(input: ReadWindowInput): string {
|
|
|
422
428
|
const range = input.readRange
|
|
423
429
|
const lines = range
|
|
424
430
|
? `r${range[0]}-${range[1]}`
|
|
425
|
-
: `o${input.offset ??
|
|
431
|
+
: `o${Math.max(1, input.offset ?? 1)}l${input.limit === undefined ? 'all' : input.limit}`
|
|
426
432
|
return input.allow_large === true ? `${lines}+large` : lines
|
|
427
433
|
}
|
|
428
434
|
|
|
@@ -414,7 +414,8 @@ export function readNotebook(bytes: Buffer, label: string): MediaRead {
|
|
|
414
414
|
}
|
|
415
415
|
let parsed: unknown
|
|
416
416
|
try {
|
|
417
|
-
|
|
417
|
+
// A byte-order mark is part of how some editors save a notebook, not of its JSON.
|
|
418
|
+
parsed = JSON.parse(bytes.toString('utf-8').replace(/^\uFEFF/u, ''))
|
|
418
419
|
} catch (error) {
|
|
419
420
|
return {
|
|
420
421
|
ok: false,
|
|
@@ -129,7 +129,7 @@ function partialViewNotice(
|
|
|
129
129
|
'',
|
|
130
130
|
'',
|
|
131
131
|
`[PARTIAL view — lines ${start + 1}-${shownTo} of ${total}.`,
|
|
132
|
-
`Continue with read({ offset: ${shownTo}, limit: N }), or narrow with grep.]`,
|
|
132
|
+
`Continue with read({ offset: ${shownTo + 1}, limit: N }), or narrow with grep.]`,
|
|
133
133
|
].join('\n')
|
|
134
134
|
}
|
|
135
135
|
|
|
@@ -150,7 +150,9 @@ export function resolveReadWindow(
|
|
|
150
150
|
const end = Math.min(totalLines, Math.max(start, last))
|
|
151
151
|
return { start, end }
|
|
152
152
|
}
|
|
153
|
-
|
|
153
|
+
// `offset` is a line number counted from 1, like `readRange`; 0 and a missing
|
|
154
|
+
// offset both mean the first line.
|
|
155
|
+
const start = Math.max(0, (input.offset ?? 1) - 1)
|
|
154
156
|
// A bare `read({ path })` used to return the entire file, so a 2 MB
|
|
155
157
|
// lockfile became ~500k tokens in one tool_result. Default to a window
|
|
156
158
|
// and say so in the output; the model asks for more when it needs it.
|
|
@@ -341,7 +343,7 @@ function trimFirstPage(
|
|
|
341
343
|
}
|
|
342
344
|
|
|
343
345
|
return {
|
|
344
|
-
output: `${numbered(selected.slice(0, keep))}\n\n[Truncated: PARTIAL view — ${path}: showing lines 1-${keep} of ${totalLines} total (${tokens} tokens, cap ${maxTokens}). Call read with offset=${keep} limit=${keep} for the next page, or grep to find a specific section. ${tail}`,
|
|
346
|
+
output: `${numbered(selected.slice(0, keep))}\n\n[Truncated: PARTIAL view — ${path}: showing lines 1-${keep} of ${totalLines} total (${tokens} tokens, cap ${maxTokens}). Call read with offset=${keep + 1} limit=${keep} for the next page, or grep to find a specific section. ${tail}`,
|
|
345
347
|
totalLines,
|
|
346
348
|
returnedLines: keep,
|
|
347
349
|
partial: true,
|
|
@@ -1,13 +1,27 @@
|
|
|
1
1
|
import { isAbsolute, join as joinPath, posix, relative, sep } from 'node:path'
|
|
2
2
|
|
|
3
3
|
import { subscribeToAbort } from '../../utils/abort.js'
|
|
4
|
+
import { readPositiveIntEnv } from '../../utils/env.js'
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* How long grep and glob search before they return what they have. The tool
|
|
7
|
-
* deadline (
|
|
8
|
-
* that ends itself a little earlier can still hand back its matches.
|
|
8
|
+
* deadline (budget + 3 s) cancels a call outright and discards its output; a
|
|
9
|
+
* search that ends itself a little earlier can still hand back its matches.
|
|
10
|
+
* A value above 600 s falls back to the default: a timer past 2^31 ms
|
|
11
|
+
* overflows and fires at once.
|
|
9
12
|
*/
|
|
10
|
-
|
|
13
|
+
const MAX_SEARCH_SECONDS = 600
|
|
14
|
+
const configuredSeconds = readPositiveIntEnv('NAMZU_SEARCH_TIMEOUT_SECONDS', 12)
|
|
15
|
+
export const SEARCH_BUDGET_MS =
|
|
16
|
+
(configuredSeconds > MAX_SEARCH_SECONDS ? 12 : configuredSeconds) * 1000
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The deadline glob and grep declare to the executor: always a few seconds
|
|
20
|
+
* past the budget, so a search that ends itself can still return its matches.
|
|
21
|
+
* `NAMZU_SEARCH_TIMEOUT_SECONDS` sets the budget (default 12); both are read
|
|
22
|
+
* once, when the module loads.
|
|
23
|
+
*/
|
|
24
|
+
export const SEARCH_TOOL_TIMEOUT_MS = SEARCH_BUDGET_MS + 3_000
|
|
11
25
|
|
|
12
26
|
/** Matching files a search reads at most; past it the search ends with what it has. */
|
|
13
27
|
export const MAX_FILES_SEARCHED = 50_000
|
|
@@ -3,6 +3,7 @@ import { z } from 'zod'
|
|
|
3
3
|
|
|
4
4
|
import { parseAllowedTools } from '../../authorization/skill-grant.js'
|
|
5
5
|
import { forkedSkillReportNote } from '../../compaction/loaded-skills.js'
|
|
6
|
+
import { fillArguments, takesSkillArguments } from '../../skills/arguments.js'
|
|
6
7
|
import {
|
|
7
8
|
type SkillShellHookOptions,
|
|
8
9
|
createSkillShellHook,
|
|
@@ -14,7 +15,6 @@ import {
|
|
|
14
15
|
InlineShellError,
|
|
15
16
|
expandInlineShell,
|
|
16
17
|
findInlineShell,
|
|
17
|
-
substituteEscaped,
|
|
18
18
|
} from '../../skills/inline-shell.js'
|
|
19
19
|
import type { PluginSkillShellInvoker } from '../../types/plugin/index.js'
|
|
20
20
|
import type { Sandbox } from '../../types/sandbox/index.js'
|
|
@@ -395,10 +395,24 @@ export function createSkillTool(options: SkillToolOptions = {}) {
|
|
|
395
395
|
readonly reuse: boolean
|
|
396
396
|
}): Promise<string> => {
|
|
397
397
|
const shell = options.shell
|
|
398
|
-
if (shell === undefined || findInlineShell(input.body).length === 0) return input.body
|
|
399
398
|
const key = `${input.name}\u0000${input.body}`
|
|
400
399
|
const kept = input.reuse ? expanded.get(key) : undefined
|
|
401
400
|
if (kept !== undefined) return kept
|
|
401
|
+
if (shell === undefined || findInlineShell(input.body).length === 0) {
|
|
402
|
+
// No command to run: the arguments go into the text as plain text, with nothing to
|
|
403
|
+
// escape for. A call that carries no arguments at all leaves the body as written.
|
|
404
|
+
// The first load's text is kept for the pages a continuation asks for, whatever
|
|
405
|
+
// arguments that continuation repeats, so every page is cut from the same text.
|
|
406
|
+
const filled =
|
|
407
|
+
input.args === undefined
|
|
408
|
+
? input.body
|
|
409
|
+
: fillArguments(input.body, input.args, { append: false, escape: false })
|
|
410
|
+
if (!input.reuse) {
|
|
411
|
+
if (expanded.size >= 8) expanded.delete(expanded.keys().next().value as string)
|
|
412
|
+
expanded.set(key, filled)
|
|
413
|
+
}
|
|
414
|
+
return filled
|
|
415
|
+
}
|
|
402
416
|
const where = shell.sourceOf?.(input.name)
|
|
403
417
|
// A host that answers where skills come from, and has no answer for this one, has not
|
|
404
418
|
// placed it: its commands do not run.
|
|
@@ -408,12 +422,14 @@ export function createSkillTool(options: SkillToolOptions = {}) {
|
|
|
408
422
|
: shell.sourceOf !== undefined && where === undefined
|
|
409
423
|
? 'remote'
|
|
410
424
|
: where?.block
|
|
411
|
-
const
|
|
425
|
+
const variables: Record<string, string> = {}
|
|
412
426
|
if (input.directory !== undefined) {
|
|
413
|
-
|
|
414
|
-
|
|
427
|
+
variables['${CLAUDE_SKILL_DIR}'] = input.directory
|
|
428
|
+
variables['${NAMZU_SKILL_DIR}'] = input.directory
|
|
415
429
|
}
|
|
416
|
-
|
|
430
|
+
// Arguments no placeholder takes reach the model in the `Arguments:` line of the load,
|
|
431
|
+
// not appended here.
|
|
432
|
+
const text = fillArguments(input.body, input.args, { variables, append: false })
|
|
417
433
|
const hook = createSkillShellHook({
|
|
418
434
|
manager: shell.hooks?.(),
|
|
419
435
|
sessionId: shell.sessionId?.() ?? String(input.context.sessionId),
|
|
@@ -611,8 +627,12 @@ export function createSkillTool(options: SkillToolOptions = {}) {
|
|
|
611
627
|
}
|
|
612
628
|
}
|
|
613
629
|
|
|
630
|
+
// Arguments that a placeholder in the body takes are in the text already; the rest
|
|
631
|
+
// are put first, so a long skill's later pages do not hide them.
|
|
614
632
|
const argsLine =
|
|
615
|
-
input.args !== undefined &&
|
|
633
|
+
input.args !== undefined &&
|
|
634
|
+
input.args.trim() !== '' &&
|
|
635
|
+
!takesSkillArguments(skill.body ?? '', input.args)
|
|
616
636
|
? `Arguments: ${input.args.trim()}\n\n`
|
|
617
637
|
: ''
|
|
618
638
|
|