@namzu/sdk 51.1.0 → 52.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +119 -0
- package/dist/agents/QueryAgent.d.ts.map +1 -1
- package/dist/agents/QueryAgent.js +2 -0
- package/dist/agents/QueryAgent.js.map +1 -1
- package/dist/agents/SupervisorAgent.d.ts +1 -1
- package/dist/agents/SupervisorAgent.d.ts.map +1 -1
- package/dist/agents/SupervisorAgent.js.map +1 -1
- package/dist/agents/examples/SupervisorAgent.d.ts +42 -0
- package/dist/agents/examples/SupervisorAgent.d.ts.map +1 -1
- package/dist/agents/examples/SupervisorAgent.js +80 -4
- package/dist/agents/examples/SupervisorAgent.js.map +1 -1
- package/dist/agents/index.d.ts +1 -1
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/index.js.map +1 -1
- package/dist/authorization/protected-paths.d.ts +36 -0
- package/dist/authorization/protected-paths.d.ts.map +1 -0
- package/dist/authorization/protected-paths.js +107 -0
- package/dist/authorization/protected-paths.js.map +1 -0
- package/dist/authorization/readonly-commands.d.ts +39 -0
- package/dist/authorization/readonly-commands.d.ts.map +1 -0
- package/dist/authorization/readonly-commands.js +797 -0
- package/dist/authorization/readonly-commands.js.map +1 -0
- package/dist/authorization/readonly-flags.d.ts +19 -0
- package/dist/authorization/readonly-flags.d.ts.map +1 -0
- package/dist/authorization/readonly-flags.js +178 -0
- package/dist/authorization/readonly-flags.js.map +1 -0
- package/dist/authorization/removal.d.ts +52 -0
- package/dist/authorization/removal.d.ts.map +1 -0
- package/dist/authorization/removal.js +283 -0
- package/dist/authorization/removal.js.map +1 -0
- package/dist/authorization/shell-paths.d.ts +66 -0
- package/dist/authorization/shell-paths.d.ts.map +1 -0
- package/dist/authorization/shell-paths.js +697 -0
- package/dist/authorization/shell-paths.js.map +1 -0
- package/dist/bridge/acp/update.d.ts.map +1 -1
- package/dist/bridge/acp/update.js +1 -0
- package/dist/bridge/acp/update.js.map +1 -1
- package/dist/compaction/context-window.d.ts +24 -0
- package/dist/compaction/context-window.d.ts.map +1 -1
- package/dist/compaction/context-window.js +34 -0
- package/dist/compaction/context-window.js.map +1 -1
- package/dist/compaction/manual.d.ts.map +1 -1
- package/dist/compaction/manual.js +10 -2
- package/dist/compaction/manual.js.map +1 -1
- package/dist/compaction/plan.d.ts +4 -0
- package/dist/compaction/plan.d.ts.map +1 -1
- package/dist/compaction/plan.js +6 -2
- package/dist/compaction/plan.js.map +1 -1
- package/dist/compaction/verifier.d.ts +11 -1
- package/dist/compaction/verifier.d.ts.map +1 -1
- package/dist/compaction/verifier.js +75 -23
- package/dist/compaction/verifier.js.map +1 -1
- package/dist/config/runtime.d.ts +55 -7
- package/dist/config/runtime.d.ts.map +1 -1
- package/dist/config/runtime.js +23 -2
- package/dist/config/runtime.js.map +1 -1
- package/dist/connector/web/guarded-fetch.d.ts.map +1 -1
- package/dist/connector/web/guarded-fetch.js +24 -0
- package/dist/connector/web/guarded-fetch.js.map +1 -1
- package/dist/connector/web/index.d.ts +1 -1
- package/dist/connector/web/index.d.ts.map +1 -1
- package/dist/connector/web/page.d.ts +59 -0
- package/dist/connector/web/page.d.ts.map +1 -0
- package/dist/connector/web/page.js +112 -0
- package/dist/connector/web/page.js.map +1 -0
- package/dist/connector/web/types.d.ts +47 -0
- package/dist/connector/web/types.d.ts.map +1 -1
- package/dist/connector/web/types.js.map +1 -1
- package/dist/constants/continuation.d.ts +8 -0
- package/dist/constants/continuation.d.ts.map +1 -1
- package/dist/constants/continuation.js +8 -0
- package/dist/constants/continuation.js.map +1 -1
- package/dist/constants/plugin/index.d.ts +1 -1
- package/dist/constants/plugin/index.d.ts.map +1 -1
- package/dist/constants/plugin/index.js +1 -1
- package/dist/constants/plugin/index.js.map +1 -1
- package/dist/contracts/a2a.d.ts +2 -2
- package/dist/manager/agent/lifecycle.d.ts +7 -0
- package/dist/manager/agent/lifecycle.d.ts.map +1 -1
- package/dist/manager/agent/lifecycle.js +11 -2
- package/dist/manager/agent/lifecycle.js.map +1 -1
- package/dist/manager/session/turn-recorder.d.ts.map +1 -1
- package/dist/manager/session/turn-recorder.js +4 -2
- package/dist/manager/session/turn-recorder.js.map +1 -1
- package/dist/plugin/index.d.ts +1 -1
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +1 -1
- package/dist/plugin/index.js.map +1 -1
- package/dist/plugin/lifecycle.d.ts +6 -0
- package/dist/plugin/lifecycle.d.ts.map +1 -1
- package/dist/plugin/lifecycle.js +98 -114
- package/dist/plugin/lifecycle.js.map +1 -1
- package/dist/plugin/shell-hook.d.ts +90 -22
- package/dist/plugin/shell-hook.d.ts.map +1 -1
- package/dist/plugin/shell-hook.js +434 -41
- package/dist/plugin/shell-hook.js.map +1 -1
- package/dist/provider/capabilities.d.ts +9 -0
- package/dist/provider/capabilities.d.ts.map +1 -1
- package/dist/provider/capabilities.js +15 -0
- package/dist/provider/capabilities.js.map +1 -1
- package/dist/provider/errors.d.ts.map +1 -1
- package/dist/provider/errors.js +13 -0
- package/dist/provider/errors.js.map +1 -1
- package/dist/provider/fallback.d.ts.map +1 -1
- package/dist/provider/fallback.js +10 -0
- package/dist/provider/fallback.js.map +1 -1
- package/dist/provider/idle-timeout.d.ts.map +1 -1
- package/dist/provider/idle-timeout.js +5 -0
- package/dist/provider/idle-timeout.js.map +1 -1
- package/dist/provider/image-input-refusal.d.ts +9 -0
- package/dist/provider/image-input-refusal.d.ts.map +1 -0
- package/dist/provider/image-input-refusal.js +54 -0
- package/dist/provider/image-input-refusal.js.map +1 -0
- package/dist/provider/index.d.ts +2 -1
- package/dist/provider/index.d.ts.map +1 -1
- package/dist/provider/index.js +2 -1
- package/dist/provider/index.js.map +1 -1
- package/dist/provider/retry.d.ts +7 -2
- package/dist/provider/retry.d.ts.map +1 -1
- package/dist/provider/retry.js +38 -4
- package/dist/provider/retry.js.map +1 -1
- package/dist/public-runtime.d.ts +5 -2
- package/dist/public-runtime.d.ts.map +1 -1
- package/dist/public-runtime.js +5 -2
- package/dist/public-runtime.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/registry.d.ts +21 -0
- package/dist/runtime/jobs/registry.d.ts.map +1 -1
- package/dist/runtime/jobs/registry.js +15 -2
- package/dist/runtime/jobs/registry.js.map +1 -1
- package/dist/runtime/query/deferred-sandbox.d.ts +54 -0
- package/dist/runtime/query/deferred-sandbox.d.ts.map +1 -0
- package/dist/runtime/query/deferred-sandbox.js +75 -0
- package/dist/runtime/query/deferred-sandbox.js.map +1 -0
- package/dist/runtime/query/executor/tool-call-admission.d.ts +10 -0
- package/dist/runtime/query/executor/tool-call-admission.d.ts.map +1 -1
- package/dist/runtime/query/executor/tool-call-admission.js +74 -13
- package/dist/runtime/query/executor/tool-call-admission.js.map +1 -1
- package/dist/runtime/query/executor.d.ts +51 -2
- package/dist/runtime/query/executor.d.ts.map +1 -1
- package/dist/runtime/query/executor.js +214 -9
- package/dist/runtime/query/executor.js.map +1 -1
- package/dist/runtime/query/finalize-turn.d.ts +6 -0
- package/dist/runtime/query/finalize-turn.d.ts.map +1 -1
- package/dist/runtime/query/finalize-turn.js +1 -1
- package/dist/runtime/query/finalize-turn.js.map +1 -1
- package/dist/runtime/query/index.d.ts +29 -0
- package/dist/runtime/query/index.d.ts.map +1 -1
- package/dist/runtime/query/index.js +108 -28
- package/dist/runtime/query/index.js.map +1 -1
- package/dist/runtime/query/iteration/index.d.ts +57 -0
- package/dist/runtime/query/iteration/index.d.ts.map +1 -1
- package/dist/runtime/query/iteration/index.js +380 -28
- package/dist/runtime/query/iteration/index.js.map +1 -1
- package/dist/runtime/query/iteration/phases/compaction-breaker.d.ts +61 -0
- package/dist/runtime/query/iteration/phases/compaction-breaker.d.ts.map +1 -0
- package/dist/runtime/query/iteration/phases/compaction-breaker.js +94 -0
- package/dist/runtime/query/iteration/phases/compaction-breaker.js.map +1 -0
- package/dist/runtime/query/iteration/phases/compaction.d.ts +42 -1
- package/dist/runtime/query/iteration/phases/compaction.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/compaction.js +203 -23
- package/dist/runtime/query/iteration/phases/compaction.js.map +1 -1
- package/dist/runtime/query/iteration/phases/context.d.ts +10 -0
- package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/context.js.map +1 -1
- package/dist/runtime/query/iteration/phases/tool-review.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/tool-review.js +165 -2
- package/dist/runtime/query/iteration/phases/tool-review.js.map +1 -1
- package/dist/runtime/query/iteration/provider-rejected-image.d.ts +21 -1
- package/dist/runtime/query/iteration/provider-rejected-image.d.ts.map +1 -1
- package/dist/runtime/query/iteration/provider-rejected-image.js +53 -7
- package/dist/runtime/query/iteration/provider-rejected-image.js.map +1 -1
- package/dist/runtime/query/iteration/request-repair.d.ts +108 -0
- package/dist/runtime/query/iteration/request-repair.d.ts.map +1 -0
- package/dist/runtime/query/iteration/request-repair.js +593 -0
- package/dist/runtime/query/iteration/request-repair.js.map +1 -0
- package/dist/runtime/query/iteration/stream-turn.d.ts +6 -0
- package/dist/runtime/query/iteration/stream-turn.d.ts.map +1 -1
- package/dist/runtime/query/iteration/stream-turn.js +2 -2
- package/dist/runtime/query/iteration/stream-turn.js.map +1 -1
- package/dist/runtime/query/path-escalation.d.ts +36 -0
- package/dist/runtime/query/path-escalation.d.ts.map +1 -0
- package/dist/runtime/query/path-escalation.js +184 -0
- package/dist/runtime/query/path-escalation.js.map +1 -0
- package/dist/runtime/query/plugin-hooks.d.ts.map +1 -1
- package/dist/runtime/query/plugin-hooks.js +8 -0
- package/dist/runtime/query/plugin-hooks.js.map +1 -1
- package/dist/runtime/query/reminders.d.ts +35 -0
- package/dist/runtime/query/reminders.d.ts.map +1 -0
- package/dist/runtime/query/reminders.js +7 -0
- package/dist/runtime/query/reminders.js.map +1 -0
- package/dist/runtime/query/request-rich-content.d.ts +5 -1
- package/dist/runtime/query/request-rich-content.d.ts.map +1 -1
- package/dist/runtime/query/request-rich-content.js +67 -25
- package/dist/runtime/query/request-rich-content.js.map +1 -1
- package/dist/runtime/query/resume-pending.d.ts.map +1 -1
- package/dist/runtime/query/resume-pending.js +26 -0
- package/dist/runtime/query/resume-pending.js.map +1 -1
- package/dist/runtime/query/review-policy.d.ts +26 -0
- package/dist/runtime/query/review-policy.d.ts.map +1 -1
- package/dist/runtime/query/review-policy.js +79 -5
- package/dist/runtime/query/review-policy.js.map +1 -1
- package/dist/runtime/query/tool-output-budget.d.ts +46 -0
- package/dist/runtime/query/tool-output-budget.d.ts.map +1 -1
- package/dist/runtime/query/tool-output-budget.js +85 -1
- package/dist/runtime/query/tool-output-budget.js.map +1 -1
- package/dist/runtime/query/tooling.d.ts +1 -0
- package/dist/runtime/query/tooling.d.ts.map +1 -1
- package/dist/runtime/query/tooling.js +5 -0
- package/dist/runtime/query/tooling.js.map +1 -1
- package/dist/session/paths.d.ts +5 -1
- package/dist/session/paths.d.ts.map +1 -1
- package/dist/session/paths.js +8 -0
- package/dist/session/paths.js.map +1 -1
- package/dist/store/memory/disk.d.ts.map +1 -1
- package/dist/store/memory/disk.js +2 -2
- package/dist/store/memory/disk.js.map +1 -1
- package/dist/store/memory/markdown.d.ts.map +1 -1
- package/dist/store/memory/markdown.js +2 -2
- package/dist/store/memory/markdown.js.map +1 -1
- package/dist/store/memory/naming.d.ts +9 -0
- package/dist/store/memory/naming.d.ts.map +1 -1
- package/dist/store/memory/naming.js +12 -0
- package/dist/store/memory/naming.js.map +1 -1
- package/dist/tools/builtins/bash.d.ts +30 -1
- package/dist/tools/builtins/bash.d.ts.map +1 -1
- package/dist/tools/builtins/bash.js +170 -26
- package/dist/tools/builtins/bash.js.map +1 -1
- package/dist/tools/builtins/computer-use.d.ts +1 -1
- package/dist/tools/builtins/computer-use.d.ts.map +1 -1
- package/dist/tools/builtins/computer-use.js +12 -5
- package/dist/tools/builtins/computer-use.js.map +1 -1
- package/dist/tools/builtins/content-fingerprint.d.ts +2 -0
- package/dist/tools/builtins/content-fingerprint.d.ts.map +1 -1
- package/dist/tools/builtins/content-fingerprint.js +4 -0
- package/dist/tools/builtins/content-fingerprint.js.map +1 -1
- package/dist/tools/builtins/edit.d.ts.map +1 -1
- package/dist/tools/builtins/edit.js +60 -18
- package/dist/tools/builtins/edit.js.map +1 -1
- package/dist/tools/builtins/grep.d.ts +8 -1
- package/dist/tools/builtins/grep.d.ts.map +1 -1
- package/dist/tools/builtins/grep.js +152 -33
- package/dist/tools/builtins/grep.js.map +1 -1
- package/dist/tools/builtins/read-file.d.ts +1 -0
- package/dist/tools/builtins/read-file.d.ts.map +1 -1
- package/dist/tools/builtins/read-file.js +44 -5
- package/dist/tools/builtins/read-file.js.map +1 -1
- package/dist/tools/builtins/read-render.d.ts +52 -0
- package/dist/tools/builtins/read-render.d.ts.map +1 -1
- package/dist/tools/builtins/read-render.js +143 -0
- package/dist/tools/builtins/read-render.js.map +1 -1
- package/dist/tools/builtins/web.d.ts +13 -2
- package/dist/tools/builtins/web.d.ts.map +1 -1
- package/dist/tools/builtins/web.js +225 -32
- package/dist/tools/builtins/web.js.map +1 -1
- package/dist/tools/coordinator/ask-user-question.d.ts +2 -0
- package/dist/tools/coordinator/ask-user-question.d.ts.map +1 -1
- package/dist/tools/coordinator/ask-user-question.js +256 -92
- package/dist/tools/coordinator/ask-user-question.js.map +1 -1
- package/dist/tools/coordinator/question-options.d.ts +1 -0
- package/dist/tools/coordinator/question-options.d.ts.map +1 -1
- package/dist/tools/coordinator/question-options.js +6 -1
- package/dist/tools/coordinator/question-options.js.map +1 -1
- package/dist/tools/defineTool.d.ts +4 -1
- package/dist/tools/defineTool.d.ts.map +1 -1
- package/dist/tools/defineTool.js +6 -1
- package/dist/tools/defineTool.js.map +1 -1
- package/dist/tools/paths.d.ts +6 -0
- package/dist/tools/paths.d.ts.map +1 -1
- package/dist/tools/paths.js +1 -1
- package/dist/tools/paths.js.map +1 -1
- package/dist/types/agent/query.d.ts +3 -0
- package/dist/types/agent/query.d.ts.map +1 -1
- package/dist/types/errors/catalog.js +1 -1
- package/dist/types/errors/catalog.js.map +1 -1
- package/dist/types/hitl/index.d.ts +104 -0
- package/dist/types/hitl/index.d.ts.map +1 -1
- package/dist/types/hitl/index.js.map +1 -1
- package/dist/types/message/index.d.ts +1 -1
- package/dist/types/message/index.d.ts.map +1 -1
- package/dist/types/message/index.js +2 -0
- package/dist/types/message/index.js.map +1 -1
- package/dist/types/plugin/index.d.ts +93 -19
- package/dist/types/plugin/index.d.ts.map +1 -1
- package/dist/types/plugin/index.js +3 -0
- package/dist/types/plugin/index.js.map +1 -1
- package/dist/types/provider/errors.d.ts +19 -0
- package/dist/types/provider/errors.d.ts.map +1 -1
- package/dist/types/provider/errors.js +54 -5
- package/dist/types/provider/errors.js.map +1 -1
- package/dist/types/provider/interface.d.ts +12 -0
- package/dist/types/provider/interface.d.ts.map +1 -1
- package/dist/types/provider/stream.d.ts +1 -1
- package/dist/types/session/config.d.ts +14 -0
- package/dist/types/session/config.d.ts.map +1 -1
- package/dist/types/session/events.d.ts +27 -4
- package/dist/types/session/events.d.ts.map +1 -1
- package/dist/types/session/events.js.map +1 -1
- package/dist/types/session/records.d.ts +9 -9
- package/dist/types/session/records.d.ts.map +1 -1
- package/dist/types/session/records.js +1 -0
- package/dist/types/session/records.js.map +1 -1
- package/dist/types/session/stop-reason.d.ts +5 -0
- package/dist/types/session/stop-reason.d.ts.map +1 -1
- package/dist/types/tool/index.d.ts +52 -0
- package/dist/types/tool/index.d.ts.map +1 -1
- package/dist/types/tool/index.js.map +1 -1
- package/package.json +4 -2
- package/src/agents/QueryAgent.ts +5 -1
- package/src/agents/SupervisorAgent.ts +1 -1
- package/src/agents/examples/SupervisorAgent.ts +217 -106
- package/src/agents/index.ts +1 -1
- package/src/authorization/protected-paths.ts +110 -0
- package/src/authorization/readonly-commands.ts +771 -0
- package/src/authorization/readonly-flags.ts +196 -0
- package/src/authorization/removal.ts +326 -0
- package/src/authorization/shell-paths.ts +927 -0
- package/src/bridge/acp/update.ts +1 -0
- package/src/compaction/context-window.ts +41 -0
- package/src/compaction/manual.ts +10 -2
- package/src/compaction/plan.ts +11 -2
- package/src/compaction/verifier.ts +84 -22
- package/src/config/runtime.ts +23 -2
- package/src/connector/web/guarded-fetch.ts +26 -0
- package/src/connector/web/index.ts +3 -0
- package/src/connector/web/page.ts +130 -0
- package/src/connector/web/types.ts +47 -0
- package/src/constants/continuation.ts +10 -0
- package/src/constants/plugin/index.ts +1 -1
- package/src/manager/agent/lifecycle.ts +12 -4
- package/src/manager/session/turn-recorder.ts +10 -2
- package/src/plugin/index.ts +1 -0
- package/src/plugin/lifecycle.ts +107 -119
- package/src/plugin/shell-hook.ts +477 -43
- package/src/provider/capabilities.ts +17 -0
- package/src/provider/errors.ts +13 -0
- package/src/provider/fallback.ts +10 -0
- package/src/provider/idle-timeout.ts +5 -0
- package/src/provider/image-input-refusal.ts +54 -0
- package/src/provider/index.ts +2 -0
- package/src/provider/retry.ts +42 -4
- package/src/public-runtime.ts +11 -0
- package/src/public-types.ts +4 -0
- package/src/runtime/jobs/registry.ts +39 -2
- package/src/runtime/query/deferred-sandbox.ts +110 -0
- package/src/runtime/query/executor/tool-call-admission.ts +79 -13
- package/src/runtime/query/executor.ts +267 -11
- package/src/runtime/query/finalize-turn.ts +7 -1
- package/src/runtime/query/index.ts +169 -52
- package/src/runtime/query/iteration/index.ts +439 -35
- package/src/runtime/query/iteration/phases/compaction-breaker.ts +108 -0
- package/src/runtime/query/iteration/phases/compaction.ts +241 -38
- package/src/runtime/query/iteration/phases/context.ts +11 -0
- package/src/runtime/query/iteration/phases/tool-review.ts +177 -2
- package/src/runtime/query/iteration/provider-rejected-image.ts +71 -5
- package/src/runtime/query/iteration/request-repair.ts +743 -0
- package/src/runtime/query/iteration/stream-turn.ts +11 -1
- package/src/runtime/query/path-escalation.ts +204 -0
- package/src/runtime/query/plugin-hooks.ts +8 -0
- package/src/runtime/query/reminders.ts +45 -0
- package/src/runtime/query/request-rich-content.ts +77 -27
- package/src/runtime/query/resume-pending.ts +27 -0
- package/src/runtime/query/review-policy.ts +106 -5
- package/src/runtime/query/tool-output-budget.ts +115 -1
- package/src/runtime/query/tooling.ts +6 -0
- package/src/session/paths.ts +11 -1
- package/src/store/memory/disk.ts +2 -1
- package/src/store/memory/markdown.ts +2 -1
- package/src/store/memory/naming.ts +13 -0
- package/src/tools/builtins/bash.ts +203 -34
- package/src/tools/builtins/computer-use.ts +13 -4
- package/src/tools/builtins/content-fingerprint.ts +5 -0
- package/src/tools/builtins/edit.ts +69 -19
- package/src/tools/builtins/grep.ts +159 -38
- package/src/tools/builtins/read-file.ts +48 -5
- package/src/tools/builtins/read-render.ts +193 -0
- package/src/tools/builtins/web.ts +258 -33
- package/src/tools/coordinator/ask-user-question.ts +309 -103
- package/src/tools/coordinator/question-options.ts +8 -1
- package/src/tools/defineTool.ts +11 -2
- package/src/tools/paths.ts +1 -1
- package/src/types/agent/query.ts +3 -0
- package/src/types/errors/catalog.ts +1 -1
- package/src/types/hitl/index.ts +104 -0
- package/src/types/message/index.ts +2 -0
- package/src/types/plugin/index.ts +101 -18
- package/src/types/provider/errors.ts +66 -5
- package/src/types/provider/interface.ts +13 -0
- package/src/types/provider/stream.ts +1 -1
- package/src/types/session/config.ts +14 -0
- package/src/types/session/events.ts +32 -4
- package/src/types/session/records.ts +1 -0
- package/src/types/session/stop-reason.ts +5 -0
- package/src/types/tool/index.ts +53 -2
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { EMPTY_TOKEN_USAGE } from '../../constants/limits.js'
|
|
2
2
|
import { drainQuery } from '../../runtime/query/index.js'
|
|
3
3
|
import { PendingAnswers, QuestionParkBinding } from '../../runtime/query/question-park.js'
|
|
4
|
+
import { resumeSession } from '../../runtime/query/resume-session.js'
|
|
4
5
|
import { CompletionInbox } from '../../scheduler/completion-inbox.js'
|
|
5
6
|
import { LocalTaskScheduler } from '../../scheduler/local.js'
|
|
6
7
|
import {
|
|
@@ -18,10 +19,13 @@ import type {
|
|
|
18
19
|
} from '../../types/agent/index.js'
|
|
19
20
|
import type { TaskHandle, TaskScheduler } from '../../types/agent/scheduler.js'
|
|
20
21
|
import type { AgentTaskContext } from '../../types/agent/task.js'
|
|
22
|
+
import { NamzuError } from '../../types/errors/index.js'
|
|
23
|
+
import { type HITLResumeDecision, autoApproveHandler } from '../../types/hitl/index.js'
|
|
21
24
|
import type { SessionId, TurnId } from '../../types/ids/index.js'
|
|
22
25
|
import { deriveChildState } from '../../types/invocation/index.js'
|
|
23
26
|
import type { ActorRef } from '../../types/session/actor.js'
|
|
24
27
|
import type { SessionEventListener } from '../../types/session/events.js'
|
|
28
|
+
import type { TurnState } from '../../types/session/index.js'
|
|
25
29
|
import type { ToolDefinition } from '../../types/tool/index.js'
|
|
26
30
|
import { ZERO_COST } from '../../utils/cost.js'
|
|
27
31
|
import type { Logger } from '../../utils/logger.js'
|
|
@@ -71,6 +75,24 @@ export function countCompletedTasks(taskResults: readonly AgentTaskResult[]): nu
|
|
|
71
75
|
return taskResults.filter((t) => t.result.status === 'completed').length
|
|
72
76
|
}
|
|
73
77
|
|
|
78
|
+
/**
|
|
79
|
+
* Which paused turn {@link SupervisorAgent.resume} continues.
|
|
80
|
+
*/
|
|
81
|
+
export interface SupervisorResumeTarget {
|
|
82
|
+
/** The turn that ended in `turn_paused`. It keeps this id. */
|
|
83
|
+
readonly turnId: TurnId
|
|
84
|
+
/**
|
|
85
|
+
* A specific checkpoint of that turn. Absent means the one an open
|
|
86
|
+
* decision references, else the newest, as `resumeSession` chooses.
|
|
87
|
+
*/
|
|
88
|
+
readonly checkpointId?: TurnState['checkpointId']
|
|
89
|
+
/**
|
|
90
|
+
* The answer to a park the checkpoint is waiting on. Without it a turn
|
|
91
|
+
* parked on a decision is refused rather than stepped past.
|
|
92
|
+
*/
|
|
93
|
+
readonly pendingDecision?: HITLResumeDecision
|
|
94
|
+
}
|
|
95
|
+
|
|
74
96
|
/** @deprecated Example of supervised delegation; hosts can compose their own agent. */
|
|
75
97
|
export class SupervisorAgent extends AbstractAgent<SupervisorAgentConfig, SupervisorAgentResult> {
|
|
76
98
|
readonly type = 'supervisor' as const
|
|
@@ -110,10 +132,38 @@ export class SupervisorAgent extends AbstractAgent<SupervisorAgentConfig, Superv
|
|
|
110
132
|
)
|
|
111
133
|
}
|
|
112
134
|
|
|
135
|
+
/**
|
|
136
|
+
* Continue a turn that ended in `turn_paused`: the SAME `turnId`, from the
|
|
137
|
+
* selected checkpoint, with the context folded from the session log.
|
|
138
|
+
*
|
|
139
|
+
* Takes what `run` takes and rebuilds the same delegation, budget and
|
|
140
|
+
* scheduler wiring for the turn, then hands the turn to `resumeSession`.
|
|
141
|
+
* `input.messages` is ignored: the transcript is the log's. `config` must
|
|
142
|
+
* carry the `sessionLog` (and `checkpointStore`, if it is not the one
|
|
143
|
+
* beside the log) the turn was written to.
|
|
144
|
+
*
|
|
145
|
+
* Emits the same `turn_paused` and terminal events as `run`, so a host
|
|
146
|
+
* bounds its resumes by counting `turn_paused`. Rejects with a
|
|
147
|
+
* `NamzuError` (`invalid_config`) when the turn is unknown, already
|
|
148
|
+
* ended, has no checkpoint, or waits on a decision `target` does not
|
|
149
|
+
* answer.
|
|
150
|
+
*/
|
|
151
|
+
async resume(
|
|
152
|
+
input: AgentInput,
|
|
153
|
+
config: SupervisorAgentConfig,
|
|
154
|
+
target: SupervisorResumeTarget,
|
|
155
|
+
listener?: SessionEventListener,
|
|
156
|
+
): Promise<SupervisorAgentResult> {
|
|
157
|
+
return await this.underIdempotencyKey(config.idempotencyKey, () =>
|
|
158
|
+
this.underInvocationLock(() => this.runExclusive(input, config, listener, target)),
|
|
159
|
+
)
|
|
160
|
+
}
|
|
161
|
+
|
|
113
162
|
private async runExclusive(
|
|
114
163
|
input: AgentInput,
|
|
115
164
|
config: SupervisorAgentConfig,
|
|
116
165
|
listener?: SessionEventListener,
|
|
166
|
+
resume?: SupervisorResumeTarget,
|
|
117
167
|
): Promise<SupervisorAgentResult> {
|
|
118
168
|
const startTime = Date.now()
|
|
119
169
|
if (!config.sessionId || !config.topicId || !config.projectId || !config.tenantId) {
|
|
@@ -122,7 +172,14 @@ export class SupervisorAgent extends AbstractAgent<SupervisorAgentConfig, Superv
|
|
|
122
172
|
)
|
|
123
173
|
}
|
|
124
174
|
const sessionId = config.sessionId
|
|
125
|
-
|
|
175
|
+
if (resume && !config.sessionLog) {
|
|
176
|
+
throw new NamzuError({
|
|
177
|
+
code: 'invalid_config',
|
|
178
|
+
message:
|
|
179
|
+
'SupervisorAgent.resume requires config.sessionLog: the log the paused turn was written to.',
|
|
180
|
+
})
|
|
181
|
+
}
|
|
182
|
+
const turnId = resume?.turnId ?? this.createTurnId()
|
|
126
183
|
this.bindTurn(sessionId, turnId, config.logger)
|
|
127
184
|
const topicId = config.topicId
|
|
128
185
|
const projectId = config.projectId
|
|
@@ -325,114 +382,115 @@ export class SupervisorAgent extends AbstractAgent<SupervisorAgentConfig, Superv
|
|
|
325
382
|
this.metadata.id,
|
|
326
383
|
)
|
|
327
384
|
|
|
328
|
-
const
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
? { streamIdleTimeoutMs: config.streamIdleTimeoutMs }
|
|
348
|
-
: {}),
|
|
349
|
-
...(config.maxRequestRichContentBytes !== undefined
|
|
350
|
-
? {
|
|
351
|
-
maxRequestRichContentBytes: config.maxRequestRichContentBytes,
|
|
352
|
-
}
|
|
353
|
-
: {}),
|
|
354
|
-
maxIterations: config.maxIterations,
|
|
355
|
-
temperature: config.temperature,
|
|
356
|
-
env: config.env,
|
|
357
|
-
...(config.pruneKeepLast !== undefined ? { pruneKeepLast: config.pruneKeepLast } : {}),
|
|
358
|
-
logger: this.log,
|
|
359
|
-
// See ReactiveAgent: a hand-listed literal drops what nobody
|
|
360
|
-
// remembered to add, and reports nothing when it does.
|
|
361
|
-
...(config.thinking ? { thinking: config.thinking } : {}),
|
|
362
|
-
...(config.effort ? { effort: config.effort } : {}),
|
|
363
|
-
},
|
|
364
|
-
questionParks,
|
|
365
|
-
pendingAnswers,
|
|
366
|
-
// How wide a fan-out actually runs. Absent leaves the kernel
|
|
367
|
-
// default — the same forwarding ReactiveAgent has always done,
|
|
368
|
-
// missing from the one agent whose job is delegation.
|
|
369
|
-
...(config.maxToolConcurrency !== undefined
|
|
370
|
-
? { maxToolConcurrency: config.maxToolConcurrency }
|
|
371
|
-
: {}),
|
|
372
|
-
agentId: this.metadata.id,
|
|
373
|
-
agentName: this.metadata.name,
|
|
374
|
-
workingDirectory: input.workingDirectory,
|
|
375
|
-
messages: input.messages,
|
|
376
|
-
signal: input.signal,
|
|
377
|
-
sessionId,
|
|
378
|
-
topicId,
|
|
379
|
-
projectId,
|
|
380
|
-
tenantId,
|
|
381
|
-
turnId,
|
|
382
|
-
...(config.parentSessionId ? { parentSessionId: config.parentSessionId } : {}),
|
|
383
|
-
...(config.parentTurnId ? { parentTurnId: config.parentTurnId } : {}),
|
|
384
|
-
depth: config.depth,
|
|
385
|
-
contextLevel: 'full',
|
|
386
|
-
onContextCreated: ({ planManager }) => {
|
|
387
|
-
planManagerRef = planManager
|
|
388
|
-
},
|
|
389
|
-
taskStore: input.taskStore,
|
|
390
|
-
runtimeToolOverrides: input.runtimeToolOverrides,
|
|
391
|
-
runtimeContext: input.runtimeContext,
|
|
392
|
-
taskScheduler: gateway,
|
|
393
|
-
budget,
|
|
394
|
-
completionInbox,
|
|
395
|
-
advisory: config.advisory,
|
|
396
|
-
invocationState: childInvocationState,
|
|
397
|
-
// HITL surface: forward optional review-time hooks so hosts can
|
|
398
|
-
// run "Ask before acting" supervisors instead of the default
|
|
399
|
-
// auto-approve. drainQuery falls back to autoApproveHandler
|
|
400
|
-
// when resumeHandler is omitted (= same behaviour as before).
|
|
401
|
-
...(config.resumeHandler ? { resumeHandler: config.resumeHandler } : {}),
|
|
402
|
-
...(config.reviewAllowedCalls ? { reviewAllowedCalls: config.reviewAllowedCalls } : {}),
|
|
403
|
-
// Forwarded for the same reason the handler is. A capability the
|
|
404
|
-
// kernel honours in `drainQuery` but that never reaches the
|
|
405
|
-
// surface a host actually constructs is a capability nobody can
|
|
406
|
-
// use — which is the shape of defect this file has already been
|
|
407
|
-
// corrected for twice.
|
|
408
|
-
...(config.steering ? { steering: config.steering } : {}),
|
|
409
|
-
...(config.inboundMessages ? { inboundMessages: config.inboundMessages } : {}),
|
|
410
|
-
...(config.durableInbound ? { durableInbound: config.durableInbound } : {}),
|
|
411
|
-
...(config.projectInstructionContext
|
|
412
|
-
? { projectInstructionContext: config.projectInstructionContext }
|
|
413
|
-
: {}),
|
|
414
|
-
...(config.authorizationGate ? { authorizationGate: config.authorizationGate } : {}),
|
|
415
|
-
// The one hop between the config and the tool. `drainQuery`
|
|
416
|
-
// registers `structured_output` from this and the loop
|
|
417
|
-
// captures it, so the kernel never cared which archetype it
|
|
418
|
-
// came from — only `ReactiveAgent` was passing it.
|
|
419
|
-
...(config.structuredOutput ? { structuredOutput: config.structuredOutput } : {}),
|
|
420
|
-
...(config.sandboxProvider ? { sandboxProvider: config.sandboxProvider } : {}),
|
|
421
|
-
...(config.sandboxTeardownTimeoutMs !== undefined
|
|
422
|
-
? { sandboxTeardownTimeoutMs: config.sandboxTeardownTimeoutMs }
|
|
385
|
+
const queryParams: Parameters<typeof drainQuery>[0] = {
|
|
386
|
+
systemPrompt: config.systemPrompt,
|
|
387
|
+
skills: config.skills,
|
|
388
|
+
provider: config.provider,
|
|
389
|
+
toolsets,
|
|
390
|
+
...(config.toolResultGuardrails !== undefined
|
|
391
|
+
? { toolResultGuardrails: config.toolResultGuardrails }
|
|
392
|
+
: {}),
|
|
393
|
+
...(input.attachmentStore ? { attachmentStore: input.attachmentStore } : {}),
|
|
394
|
+
...(config.attachmentResolveTimeoutMs !== undefined
|
|
395
|
+
? { attachmentResolveTimeoutMs: config.attachmentResolveTimeoutMs }
|
|
396
|
+
: {}),
|
|
397
|
+
turnConfig: {
|
|
398
|
+
model: config.model,
|
|
399
|
+
tokenBudget: config.tokenBudget,
|
|
400
|
+
timeoutMs: config.timeoutMs,
|
|
401
|
+
...(config.sandbox ? { sandbox: config.sandbox } : {}),
|
|
402
|
+
...(config.streamIdleTimeoutMs !== undefined
|
|
403
|
+
? { streamIdleTimeoutMs: config.streamIdleTimeoutMs }
|
|
423
404
|
: {}),
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
? { workingMemoryProvider: config.workingMemoryProvider }
|
|
405
|
+
...(config.maxRequestRichContentBytes !== undefined
|
|
406
|
+
? {
|
|
407
|
+
maxRequestRichContentBytes: config.maxRequestRichContentBytes,
|
|
408
|
+
}
|
|
429
409
|
: {}),
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
410
|
+
maxIterations: config.maxIterations,
|
|
411
|
+
temperature: config.temperature,
|
|
412
|
+
env: config.env,
|
|
413
|
+
...(config.pruneKeepLast !== undefined ? { pruneKeepLast: config.pruneKeepLast } : {}),
|
|
414
|
+
logger: this.log,
|
|
415
|
+
// See ReactiveAgent: a hand-listed literal drops what nobody
|
|
416
|
+
// remembered to add, and reports nothing when it does.
|
|
417
|
+
...(config.thinking ? { thinking: config.thinking } : {}),
|
|
418
|
+
...(config.effort ? { effort: config.effort } : {}),
|
|
433
419
|
},
|
|
434
|
-
|
|
435
|
-
|
|
420
|
+
questionParks,
|
|
421
|
+
pendingAnswers,
|
|
422
|
+
// How wide a fan-out actually runs. Absent leaves the kernel
|
|
423
|
+
// default — the same forwarding ReactiveAgent has always done,
|
|
424
|
+
// missing from the one agent whose job is delegation.
|
|
425
|
+
...(config.maxToolConcurrency !== undefined
|
|
426
|
+
? { maxToolConcurrency: config.maxToolConcurrency }
|
|
427
|
+
: {}),
|
|
428
|
+
agentId: this.metadata.id,
|
|
429
|
+
agentName: this.metadata.name,
|
|
430
|
+
workingDirectory: input.workingDirectory,
|
|
431
|
+
messages: input.messages,
|
|
432
|
+
signal: input.signal,
|
|
433
|
+
sessionId,
|
|
434
|
+
topicId,
|
|
435
|
+
projectId,
|
|
436
|
+
tenantId,
|
|
437
|
+
turnId,
|
|
438
|
+
...(config.parentSessionId ? { parentSessionId: config.parentSessionId } : {}),
|
|
439
|
+
...(config.parentTurnId ? { parentTurnId: config.parentTurnId } : {}),
|
|
440
|
+
depth: config.depth,
|
|
441
|
+
contextLevel: 'full',
|
|
442
|
+
onContextCreated: ({ planManager }) => {
|
|
443
|
+
planManagerRef = planManager
|
|
444
|
+
},
|
|
445
|
+
taskStore: input.taskStore,
|
|
446
|
+
runtimeToolOverrides: input.runtimeToolOverrides,
|
|
447
|
+
runtimeContext: input.runtimeContext,
|
|
448
|
+
taskScheduler: gateway,
|
|
449
|
+
budget,
|
|
450
|
+
completionInbox,
|
|
451
|
+
advisory: config.advisory,
|
|
452
|
+
invocationState: childInvocationState,
|
|
453
|
+
// HITL surface: forward optional review-time hooks so hosts can
|
|
454
|
+
// run "Ask before acting" supervisors instead of the default
|
|
455
|
+
// auto-approve. drainQuery falls back to autoApproveHandler
|
|
456
|
+
// when resumeHandler is omitted (= same behaviour as before).
|
|
457
|
+
...(config.resumeHandler ? { resumeHandler: config.resumeHandler } : {}),
|
|
458
|
+
...(config.reviewAllowedCalls ? { reviewAllowedCalls: config.reviewAllowedCalls } : {}),
|
|
459
|
+
// Forwarded for the same reason the handler is. A capability the
|
|
460
|
+
// kernel honours in `drainQuery` but that never reaches the
|
|
461
|
+
// surface a host actually constructs is a capability nobody can
|
|
462
|
+
// use — which is the shape of defect this file has already been
|
|
463
|
+
// corrected for twice.
|
|
464
|
+
...(config.steering ? { steering: config.steering } : {}),
|
|
465
|
+
...(config.inboundMessages ? { inboundMessages: config.inboundMessages } : {}),
|
|
466
|
+
...(config.durableInbound ? { durableInbound: config.durableInbound } : {}),
|
|
467
|
+
...(config.projectInstructionContext
|
|
468
|
+
? { projectInstructionContext: config.projectInstructionContext }
|
|
469
|
+
: {}),
|
|
470
|
+
...(config.authorizationGate ? { authorizationGate: config.authorizationGate } : {}),
|
|
471
|
+
// The one hop between the config and the tool. `drainQuery`
|
|
472
|
+
// registers `structured_output` from this and the loop
|
|
473
|
+
// captures it, so the kernel never cared which archetype it
|
|
474
|
+
// came from — only `ReactiveAgent` was passing it.
|
|
475
|
+
...(config.structuredOutput ? { structuredOutput: config.structuredOutput } : {}),
|
|
476
|
+
...(config.sandboxProvider ? { sandboxProvider: config.sandboxProvider } : {}),
|
|
477
|
+
...(config.sandboxTeardownTimeoutMs !== undefined
|
|
478
|
+
? { sandboxTeardownTimeoutMs: config.sandboxTeardownTimeoutMs }
|
|
479
|
+
: {}),
|
|
480
|
+
// Working-memory / compaction seam (optional; absent => unchanged
|
|
481
|
+
// run path, byte-identical for every existing consumer).
|
|
482
|
+
...(config.compactionConfig ? { compactionConfig: config.compactionConfig } : {}),
|
|
483
|
+
...(config.workingMemoryProvider
|
|
484
|
+
? { workingMemoryProvider: config.workingMemoryProvider }
|
|
485
|
+
: {}),
|
|
486
|
+
...(config.paths ? { paths: config.paths } : {}),
|
|
487
|
+
...(config.sessionLog ? { sessionLog: config.sessionLog } : {}),
|
|
488
|
+
...(config.checkpointStore ? { checkpointStore: config.checkpointStore } : {}),
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
const turn = resume
|
|
492
|
+
? await this.resumeTurn(queryParams, config, resume, listener)
|
|
493
|
+
: await drainQuery(queryParams, listener)
|
|
436
494
|
|
|
437
495
|
const taskHandles = gateway.listTasks()
|
|
438
496
|
const taskResults = synthesizeTaskResults(taskHandles, {
|
|
@@ -470,4 +528,57 @@ export class SupervisorAgent extends AbstractAgent<SupervisorAgentConfig, Superv
|
|
|
470
528
|
completionInbox.close()
|
|
471
529
|
}
|
|
472
530
|
}
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* The resumed counterpart of `drainQuery`: same params, so the wiring is
|
|
534
|
+
* the one a fresh turn gets, handed to `resumeSession` rather than a
|
|
535
|
+
* second copy of its machinery.
|
|
536
|
+
*/
|
|
537
|
+
private async resumeTurn(
|
|
538
|
+
queryParams: Parameters<typeof drainQuery>[0],
|
|
539
|
+
config: SupervisorAgentConfig,
|
|
540
|
+
resume: SupervisorResumeTarget,
|
|
541
|
+
listener?: SessionEventListener,
|
|
542
|
+
) {
|
|
543
|
+
const { messages: _messages, turnId: _turnId, ...rest } = queryParams
|
|
544
|
+
const sessionLog = config.sessionLog
|
|
545
|
+
if (
|
|
546
|
+
!sessionLog ||
|
|
547
|
+
!config.sessionId ||
|
|
548
|
+
!config.topicId ||
|
|
549
|
+
!config.projectId ||
|
|
550
|
+
!config.tenantId
|
|
551
|
+
) {
|
|
552
|
+
throw new NamzuError({
|
|
553
|
+
code: 'invalid_config',
|
|
554
|
+
message: 'SupervisorAgent.resume requires config.sessionLog.',
|
|
555
|
+
})
|
|
556
|
+
}
|
|
557
|
+
const outcome = await resumeSession({
|
|
558
|
+
...rest,
|
|
559
|
+
resumeHandler: rest.resumeHandler ?? autoApproveHandler,
|
|
560
|
+
scope: {
|
|
561
|
+
tenantId: config.tenantId,
|
|
562
|
+
projectId: config.projectId,
|
|
563
|
+
topicId: config.topicId,
|
|
564
|
+
sessionId: config.sessionId,
|
|
565
|
+
turnId: resume.turnId,
|
|
566
|
+
...(config.parentSessionId ? { parentSessionId: config.parentSessionId } : {}),
|
|
567
|
+
...(config.parentTurnId ? { parentTurnId: config.parentTurnId } : {}),
|
|
568
|
+
},
|
|
569
|
+
sessionLog,
|
|
570
|
+
...(resume.checkpointId ? { checkpointId: resume.checkpointId } : {}),
|
|
571
|
+
...(resume.pendingDecision ? { pendingDecision: resume.pendingDecision } : {}),
|
|
572
|
+
...(listener ? { listener } : {}),
|
|
573
|
+
})
|
|
574
|
+
if (outcome.resumed) return outcome.turn
|
|
575
|
+
throw new NamzuError({
|
|
576
|
+
code: 'invalid_config',
|
|
577
|
+
message:
|
|
578
|
+
outcome.reason === 'no-checkpoint'
|
|
579
|
+
? `Turn ${resume.turnId} has no checkpoint${resume.checkpointId ? ` ${resume.checkpointId}` : ''} to resume.`
|
|
580
|
+
: `Turn ${resume.turnId} is waiting on a decision; pass resume.pendingDecision.`,
|
|
581
|
+
details: { turnId: resume.turnId, reason: outcome.reason },
|
|
582
|
+
})
|
|
583
|
+
}
|
|
473
584
|
}
|
package/src/agents/index.ts
CHANGED
|
@@ -4,7 +4,7 @@ export { QueryAgent } from './QueryAgent.js'
|
|
|
4
4
|
export { ReactiveAgent } from './ReactiveAgent.js'
|
|
5
5
|
export { PipelineAgent } from './PipelineAgent.js'
|
|
6
6
|
export { RouterAgent } from './RouterAgent.js'
|
|
7
|
-
export { SupervisorAgent } from './SupervisorAgent.js'
|
|
7
|
+
export { SupervisorAgent, type SupervisorResumeTarget } from './SupervisorAgent.js'
|
|
8
8
|
export { defineAgent } from './defineAgent.js'
|
|
9
9
|
export type { DefineAgentOptions } from './defineAgent.js'
|
|
10
10
|
export { InvocationLock, ConcurrentInvocationError } from './lock.js'
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Paths a write is always asked about, in every mode.
|
|
3
|
+
*
|
|
4
|
+
* A repository carries files that are not data but triggers: a git hook runs
|
|
5
|
+
* on the next commit, a shell rc file on the next terminal, `.vscode/tasks.json`
|
|
6
|
+
* when a folder opens, `.envrc` on the next `cd`. A model that can write them
|
|
7
|
+
* does not need to run anything now; it plants code that runs later, outside
|
|
8
|
+
* the turn, with the operator's own rights. So a write to one of them is a
|
|
9
|
+
* question for a person, whatever the mode and whatever a rule or an earlier
|
|
10
|
+
* "approve all" said. That is what a mode is, an answer given before the call
|
|
11
|
+
* existed, and none of them saw this path.
|
|
12
|
+
*
|
|
13
|
+
* The lists are the reference terminal's protected-directory and
|
|
14
|
+
* protected-file tables (version 2.1.302), with its own configuration
|
|
15
|
+
* directory and file mapped to Namzu's: the project directory is `.namzu` and
|
|
16
|
+
* the project file is `namzu.config.json`.
|
|
17
|
+
*
|
|
18
|
+
* Matching is by name, on every segment of the path. `.git` anywhere above a
|
|
19
|
+
* file protects it, and `.config/git` counts as one two-segment unit. Names
|
|
20
|
+
* are case-folded, including the dotless `ı` and long `ſ` that fold to `i`
|
|
21
|
+
* and `s`, so `.GIT` and `.gıt` on a case-insensitive file system are the
|
|
22
|
+
* same directory.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/** Directory names; a path with one of these as any segment is protected. */
|
|
26
|
+
export const PROTECTED_DIRECTORIES: readonly string[] = [
|
|
27
|
+
'.git',
|
|
28
|
+
'.vscode',
|
|
29
|
+
'.idea',
|
|
30
|
+
'.namzu',
|
|
31
|
+
'.husky',
|
|
32
|
+
'.cargo',
|
|
33
|
+
'.devcontainer',
|
|
34
|
+
'.yarn',
|
|
35
|
+
'.mvn',
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
/** Directory sequences; the segments must be adjacent. */
|
|
39
|
+
export const PROTECTED_NESTED_DIRECTORIES: readonly (readonly string[])[] = [['.config', 'git']]
|
|
40
|
+
|
|
41
|
+
/** File names; a path whose last segment is one of these is protected. */
|
|
42
|
+
export const PROTECTED_FILE_NAMES: readonly string[] = [
|
|
43
|
+
'.gitconfig',
|
|
44
|
+
'.gitmodules',
|
|
45
|
+
'.bashrc',
|
|
46
|
+
'.bash_profile',
|
|
47
|
+
'.zshrc',
|
|
48
|
+
'.zprofile',
|
|
49
|
+
'.profile',
|
|
50
|
+
'.zshenv',
|
|
51
|
+
'.zlogin',
|
|
52
|
+
'.zlogout',
|
|
53
|
+
'.bash_login',
|
|
54
|
+
'.bash_aliases',
|
|
55
|
+
'.bash_logout',
|
|
56
|
+
'.envrc',
|
|
57
|
+
'.ripgreprc',
|
|
58
|
+
'.mcp.json',
|
|
59
|
+
'namzu.config.json',
|
|
60
|
+
// The project's local config, where "don't ask again" answers are written.
|
|
61
|
+
'namzu.config.local.json',
|
|
62
|
+
'.npmrc',
|
|
63
|
+
'.yarnrc',
|
|
64
|
+
'.yarnrc.yml',
|
|
65
|
+
'.pnp.cjs',
|
|
66
|
+
'.pnp.loader.mjs',
|
|
67
|
+
'.pnpmfile.cjs',
|
|
68
|
+
'bunfig.toml',
|
|
69
|
+
'.bunfig.toml',
|
|
70
|
+
'.bazelrc',
|
|
71
|
+
'.bazelversion',
|
|
72
|
+
'.bazeliskrc',
|
|
73
|
+
'.pre-commit-config.yaml',
|
|
74
|
+
'lefthook.yml',
|
|
75
|
+
'.lefthook.yml',
|
|
76
|
+
'lefthook.yaml',
|
|
77
|
+
'.lefthook.yaml',
|
|
78
|
+
'gradle-wrapper.properties',
|
|
79
|
+
'maven-wrapper.properties',
|
|
80
|
+
'.devcontainer.json',
|
|
81
|
+
'pyrightconfig.json',
|
|
82
|
+
]
|
|
83
|
+
|
|
84
|
+
/** Lower case, with the two letters that fold into ASCII on some file systems. */
|
|
85
|
+
function fold(name: string): string {
|
|
86
|
+
return name.toLowerCase().replace(/ı/g, 'i').replace(/ſ/g, 's')
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const DIRECTORIES = new Set(PROTECTED_DIRECTORIES.map(fold))
|
|
90
|
+
const FILE_NAMES = new Set(PROTECTED_FILE_NAMES.map(fold))
|
|
91
|
+
const NESTED = PROTECTED_NESTED_DIRECTORIES.map((sequence) => sequence.map(fold))
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Whether a write to `path` is one of the protected kinds. Pure: it reads the
|
|
95
|
+
* spelling it is given, so a caller that wants a symlink's target covered
|
|
96
|
+
* passes the canonical path as well.
|
|
97
|
+
*/
|
|
98
|
+
export function isProtectedPath(path: string): boolean {
|
|
99
|
+
const segments = path.split(/[\\/]+/).map(fold)
|
|
100
|
+
for (const segment of segments) {
|
|
101
|
+
if (DIRECTORIES.has(segment)) return true
|
|
102
|
+
}
|
|
103
|
+
for (const sequence of NESTED) {
|
|
104
|
+
for (let start = 0; start + sequence.length <= segments.length; start += 1) {
|
|
105
|
+
if (sequence.every((name, offset) => segments[start + offset] === name)) return true
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const last = segments[segments.length - 1]
|
|
109
|
+
return last !== undefined && last !== '' && FILE_NAMES.has(last)
|
|
110
|
+
}
|