@namzu/sdk 65.3.0 → 68.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +167 -0
- package/dist/account/lock.d.ts +4 -12
- package/dist/account/lock.d.ts.map +1 -1
- package/dist/account/lock.js +5 -140
- package/dist/account/lock.js.map +1 -1
- package/dist/account/registry.d.ts.map +1 -1
- package/dist/account/registry.js +50 -6
- package/dist/account/registry.js.map +1 -1
- package/dist/account/types.d.ts +7 -5
- package/dist/account/types.d.ts.map +1 -1
- package/dist/account/types.js +6 -7
- package/dist/account/types.js.map +1 -1
- package/dist/authorization/dangerous-commands.d.ts +64 -0
- package/dist/authorization/dangerous-commands.d.ts.map +1 -0
- package/dist/authorization/dangerous-commands.js +479 -0
- package/dist/authorization/dangerous-commands.js.map +1 -0
- package/dist/authorization/gate.d.ts.map +1 -1
- package/dist/authorization/gate.js +19 -5
- package/dist/authorization/gate.js.map +1 -1
- package/dist/authorization/protected-paths.d.ts +11 -6
- package/dist/authorization/protected-paths.d.ts.map +1 -1
- package/dist/authorization/protected-paths.js +13 -8
- package/dist/authorization/protected-paths.js.map +1 -1
- package/dist/authorization/readonly-commands.d.ts +6 -1
- package/dist/authorization/readonly-commands.d.ts.map +1 -1
- package/dist/authorization/readonly-commands.js +35 -1
- package/dist/authorization/readonly-commands.js.map +1 -1
- package/dist/authorization/removal.d.ts +10 -0
- package/dist/authorization/removal.d.ts.map +1 -1
- package/dist/authorization/removal.js +7 -7
- package/dist/authorization/removal.js.map +1 -1
- package/dist/authorization/rules.d.ts +10 -0
- package/dist/authorization/rules.d.ts.map +1 -1
- package/dist/authorization/rules.js +60 -14
- package/dist/authorization/rules.js.map +1 -1
- package/dist/authorization/shell-lexer.d.ts +10 -0
- package/dist/authorization/shell-lexer.d.ts.map +1 -1
- package/dist/authorization/shell-lexer.js +15 -0
- package/dist/authorization/shell-lexer.js.map +1 -1
- package/dist/bridge/acp/permission.d.ts +5 -0
- package/dist/bridge/acp/permission.d.ts.map +1 -1
- package/dist/bridge/acp/permission.js.map +1 -1
- package/dist/bridge/acp/server.d.ts +8 -1
- package/dist/bridge/acp/server.d.ts.map +1 -1
- package/dist/bridge/acp/server.js +48 -6
- package/dist/bridge/acp/server.js.map +1 -1
- package/dist/compaction/context-breakdown.d.ts +25 -6
- package/dist/compaction/context-breakdown.d.ts.map +1 -1
- package/dist/compaction/context-breakdown.js +27 -7
- package/dist/compaction/context-breakdown.js.map +1 -1
- package/dist/compaction/dangling.d.ts.map +1 -1
- package/dist/compaction/dangling.js +2 -0
- package/dist/compaction/dangling.js.map +1 -1
- package/dist/compaction/extractor.d.ts +7 -1
- package/dist/compaction/extractor.d.ts.map +1 -1
- package/dist/compaction/extractor.js +8 -1
- package/dist/compaction/extractor.js.map +1 -1
- package/dist/compaction/index.d.ts +1 -1
- package/dist/compaction/index.d.ts.map +1 -1
- package/dist/compaction/index.js +1 -1
- package/dist/compaction/index.js.map +1 -1
- package/dist/compaction/managers/structured.js +2 -2
- package/dist/compaction/managers/structured.js.map +1 -1
- package/dist/compaction/manual.d.ts.map +1 -1
- package/dist/compaction/manual.js +11 -6
- package/dist/compaction/manual.js.map +1 -1
- package/dist/compaction/model-summary.d.ts.map +1 -1
- package/dist/compaction/model-summary.js +7 -1
- package/dist/compaction/model-summary.js.map +1 -1
- package/dist/compaction/summary.d.ts +13 -2
- package/dist/compaction/summary.d.ts.map +1 -1
- package/dist/compaction/summary.js +46 -3
- package/dist/compaction/summary.js.map +1 -1
- package/dist/constants/tools/index.d.ts +18 -1
- package/dist/constants/tools/index.d.ts.map +1 -1
- package/dist/constants/tools/index.js +28 -16
- package/dist/constants/tools/index.js.map +1 -1
- package/dist/manager/session/turn-recorder.d.ts +6 -0
- package/dist/manager/session/turn-recorder.d.ts.map +1 -1
- package/dist/manager/session/turn-recorder.js +29 -1
- package/dist/manager/session/turn-recorder.js.map +1 -1
- package/dist/network/audit.d.ts +49 -0
- package/dist/network/audit.d.ts.map +1 -0
- package/dist/network/audit.js +84 -0
- package/dist/network/audit.js.map +1 -0
- package/dist/network/clock.d.ts +21 -0
- package/dist/network/clock.d.ts.map +1 -0
- package/dist/network/clock.js +51 -0
- package/dist/network/clock.js.map +1 -0
- package/dist/network/discovery-mdns.d.ts +120 -0
- package/dist/network/discovery-mdns.d.ts.map +1 -0
- package/dist/network/discovery-mdns.js +442 -0
- package/dist/network/discovery-mdns.js.map +1 -0
- package/dist/network/discovery.d.ts +63 -0
- package/dist/network/discovery.d.ts.map +1 -0
- package/dist/network/discovery.js +163 -0
- package/dist/network/discovery.js.map +1 -0
- package/dist/network/fingerprint.d.ts +73 -0
- package/dist/network/fingerprint.d.ts.map +1 -0
- package/dist/network/fingerprint.js +208 -0
- package/dist/network/fingerprint.js.map +1 -0
- package/dist/network/identity.d.ts +38 -0
- package/dist/network/identity.d.ts.map +1 -0
- package/dist/network/identity.js +71 -0
- package/dist/network/identity.js.map +1 -0
- package/dist/network/index.d.ts +39 -0
- package/dist/network/index.d.ts.map +1 -0
- package/dist/network/index.js +25 -0
- package/dist/network/index.js.map +1 -0
- package/dist/network/join.d.ts +69 -0
- package/dist/network/join.d.ts.map +1 -0
- package/dist/network/join.js +136 -0
- package/dist/network/join.js.map +1 -0
- package/dist/network/mail-policy.d.ts +97 -0
- package/dist/network/mail-policy.d.ts.map +1 -0
- package/dist/network/mail-policy.js +147 -0
- package/dist/network/mail-policy.js.map +1 -0
- package/dist/network/membership.d.ts +76 -0
- package/dist/network/membership.d.ts.map +1 -0
- package/dist/network/membership.js +225 -0
- package/dist/network/membership.js.map +1 -0
- package/dist/network/roster.d.ts +59 -0
- package/dist/network/roster.d.ts.map +1 -0
- package/dist/network/roster.js +120 -0
- package/dist/network/roster.js.map +1 -0
- package/dist/network/service.d.ts +303 -0
- package/dist/network/service.d.ts.map +1 -0
- package/dist/network/service.js +1891 -0
- package/dist/network/service.js.map +1 -0
- package/dist/network/store.d.ts +141 -0
- package/dist/network/store.d.ts.map +1 -0
- package/dist/network/store.js +198 -0
- package/dist/network/store.js.map +1 -0
- package/dist/network/transport.d.ts +96 -0
- package/dist/network/transport.d.ts.map +1 -0
- package/dist/network/transport.js +342 -0
- package/dist/network/transport.js.map +1 -0
- package/dist/network/wire.d.ts +345 -0
- package/dist/network/wire.d.ts.map +1 -0
- package/dist/network/wire.js +212 -0
- package/dist/network/wire.js.map +1 -0
- package/dist/network/x509.d.ts +28 -0
- package/dist/network/x509.d.ts.map +1 -0
- package/dist/network/x509.js +84 -0
- package/dist/network/x509.js.map +1 -0
- package/dist/pals/activity/causality.d.ts.map +1 -1
- package/dist/pals/activity/causality.js +14 -2
- package/dist/pals/activity/causality.js.map +1 -1
- package/dist/peers/endpoint.d.ts.map +1 -1
- package/dist/peers/endpoint.js +6 -0
- package/dist/peers/endpoint.js.map +1 -1
- package/dist/peers/envelope.d.ts +18 -0
- package/dist/peers/envelope.d.ts.map +1 -1
- package/dist/peers/envelope.js +68 -5
- package/dist/peers/envelope.js.map +1 -1
- package/dist/peers/index.d.ts +5 -4
- package/dist/peers/index.d.ts.map +1 -1
- package/dist/peers/index.js +3 -2
- package/dist/peers/index.js.map +1 -1
- package/dist/peers/mode-word.d.ts +10 -0
- package/dist/peers/mode-word.d.ts.map +1 -0
- package/dist/peers/mode-word.js +19 -0
- package/dist/peers/mode-word.js.map +1 -0
- package/dist/peers/protocol.d.ts +42 -0
- package/dist/peers/protocol.d.ts.map +1 -1
- package/dist/peers/protocol.js +22 -1
- package/dist/peers/protocol.js.map +1 -1
- package/dist/peers/record.d.ts +8 -0
- package/dist/peers/record.d.ts.map +1 -1
- package/dist/peers/record.js +5 -0
- package/dist/peers/record.js.map +1 -1
- package/dist/plugin/session-hook-env.d.ts.map +1 -1
- package/dist/plugin/session-hook-env.js +22 -2
- package/dist/plugin/session-hook-env.js.map +1 -1
- package/dist/plugin/shell-hook.d.ts +16 -2
- package/dist/plugin/shell-hook.d.ts.map +1 -1
- package/dist/plugin/shell-hook.js +183 -14
- package/dist/plugin/shell-hook.js.map +1 -1
- package/dist/pricing/catalogue.generated.d.ts.map +1 -1
- package/dist/pricing/catalogue.generated.js +6 -0
- package/dist/pricing/catalogue.generated.js.map +1 -1
- package/dist/prompt/coding-agent-doctrine.d.ts +4 -2
- package/dist/prompt/coding-agent-doctrine.d.ts.map +1 -1
- package/dist/prompt/coding-agent-doctrine.js +33 -38
- package/dist/prompt/coding-agent-doctrine.js.map +1 -1
- package/dist/provider/fallback.d.ts.map +1 -1
- package/dist/provider/fallback.js +12 -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/model-window-suffix.d.ts.map +1 -1
- package/dist/provider/model-window-suffix.js +1 -0
- package/dist/provider/model-window-suffix.js.map +1 -1
- package/dist/provider/retry.d.ts.map +1 -1
- package/dist/provider/retry.js +5 -0
- package/dist/provider/retry.js.map +1 -1
- package/dist/public-runtime.d.ts +16 -8
- package/dist/public-runtime.d.ts.map +1 -1
- package/dist/public-runtime.js +24 -7
- package/dist/public-runtime.js.map +1 -1
- package/dist/public-tools.d.ts +3 -2
- package/dist/public-tools.d.ts.map +1 -1
- package/dist/public-tools.js +2 -2
- package/dist/public-tools.js.map +1 -1
- package/dist/public-types.d.ts +10 -5
- package/dist/public-types.d.ts.map +1 -1
- package/dist/registry/command/kernel-commands.d.ts +11 -1
- package/dist/registry/command/kernel-commands.d.ts.map +1 -1
- package/dist/registry/command/kernel-commands.js +114 -46
- package/dist/registry/command/kernel-commands.js.map +1 -1
- package/dist/runtime/jobs/registry.d.ts +29 -1
- package/dist/runtime/jobs/registry.d.ts.map +1 -1
- package/dist/runtime/jobs/registry.js +64 -0
- package/dist/runtime/jobs/registry.js.map +1 -1
- package/dist/runtime/query/auto-review/classifier.d.ts +30 -6
- package/dist/runtime/query/auto-review/classifier.d.ts.map +1 -1
- package/dist/runtime/query/auto-review/classifier.js +40 -12
- package/dist/runtime/query/auto-review/classifier.js.map +1 -1
- package/dist/runtime/query/auto-review/feedback.d.ts +37 -0
- package/dist/runtime/query/auto-review/feedback.d.ts.map +1 -0
- package/dist/runtime/query/auto-review/feedback.js +45 -0
- package/dist/runtime/query/auto-review/feedback.js.map +1 -0
- package/dist/runtime/query/auto-review/git-status.d.ts +59 -0
- package/dist/runtime/query/auto-review/git-status.d.ts.map +1 -0
- package/dist/runtime/query/auto-review/git-status.js +379 -0
- package/dist/runtime/query/auto-review/git-status.js.map +1 -0
- package/dist/runtime/query/auto-review/index.d.ts +3 -3
- package/dist/runtime/query/auto-review/index.d.ts.map +1 -1
- package/dist/runtime/query/auto-review/index.js +2 -2
- package/dist/runtime/query/auto-review/index.js.map +1 -1
- package/dist/runtime/query/auto-review/prompt.d.ts.map +1 -1
- package/dist/runtime/query/auto-review/prompt.js +6 -1
- package/dist/runtime/query/auto-review/prompt.js.map +1 -1
- package/dist/runtime/query/auto-review/transcript.d.ts +14 -1
- package/dist/runtime/query/auto-review/transcript.d.ts.map +1 -1
- package/dist/runtime/query/auto-review/transcript.js +48 -2
- package/dist/runtime/query/auto-review/transcript.js.map +1 -1
- package/dist/runtime/query/executor/tool-call-admission.d.ts.map +1 -1
- package/dist/runtime/query/executor/tool-call-admission.js +40 -3
- package/dist/runtime/query/executor/tool-call-admission.js.map +1 -1
- package/dist/runtime/query/executor.d.ts +32 -10
- package/dist/runtime/query/executor.d.ts.map +1 -1
- package/dist/runtime/query/executor.js +78 -17
- package/dist/runtime/query/executor.js.map +1 -1
- package/dist/runtime/query/index.d.ts +9 -0
- package/dist/runtime/query/index.d.ts.map +1 -1
- package/dist/runtime/query/index.js +54 -17
- package/dist/runtime/query/index.js.map +1 -1
- package/dist/runtime/query/iteration/index.d.ts +1 -1
- package/dist/runtime/query/iteration/index.d.ts.map +1 -1
- package/dist/runtime/query/iteration/index.js +20 -6
- package/dist/runtime/query/iteration/index.js.map +1 -1
- package/dist/runtime/query/iteration/phases/compaction.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/compaction.js +5 -2
- package/dist/runtime/query/iteration/phases/compaction.js.map +1 -1
- package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/context.js +5 -0
- package/dist/runtime/query/iteration/phases/context.js.map +1 -1
- package/dist/runtime/query/iteration/phases/per-call-review.d.ts +1 -2
- package/dist/runtime/query/iteration/phases/per-call-review.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/per-call-review.js +2 -5
- package/dist/runtime/query/iteration/phases/per-call-review.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 +6 -1
- package/dist/runtime/query/iteration/phases/tool-review.js.map +1 -1
- package/dist/runtime/query/pasted-frames.d.ts +34 -0
- package/dist/runtime/query/pasted-frames.d.ts.map +1 -0
- package/dist/runtime/query/pasted-frames.js +108 -0
- package/dist/runtime/query/pasted-frames.js.map +1 -0
- 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 +15 -3
- package/dist/runtime/query/path-escalation.js.map +1 -1
- package/dist/runtime/query/request-interrupted-turns.d.ts +20 -0
- package/dist/runtime/query/request-interrupted-turns.d.ts.map +1 -0
- package/dist/runtime/query/request-interrupted-turns.js +43 -0
- package/dist/runtime/query/request-interrupted-turns.js.map +1 -0
- package/dist/runtime/query/review-policy.d.ts +16 -6
- package/dist/runtime/query/review-policy.d.ts.map +1 -1
- package/dist/runtime/query/review-policy.js +111 -15
- package/dist/runtime/query/review-policy.js.map +1 -1
- package/dist/runtime/query/turn/outcome-ledger.d.ts +9 -0
- package/dist/runtime/query/turn/outcome-ledger.d.ts.map +1 -1
- package/dist/runtime/query/turn/outcome-ledger.js +94 -6
- package/dist/runtime/query/turn/outcome-ledger.js.map +1 -1
- package/dist/runtime/query/unanswered.d.ts +19 -0
- package/dist/runtime/query/unanswered.d.ts.map +1 -0
- package/dist/runtime/query/unanswered.js +25 -0
- package/dist/runtime/query/unanswered.js.map +1 -0
- package/dist/runtime/system-events.d.ts +4 -4
- package/dist/runtime/system-events.d.ts.map +1 -1
- package/dist/runtime/system-events.js +2 -0
- package/dist/runtime/system-events.js.map +1 -1
- package/dist/session/workspace/git-worktree.d.ts +8 -0
- package/dist/session/workspace/git-worktree.d.ts.map +1 -1
- package/dist/session/workspace/git-worktree.js +21 -3
- package/dist/session/workspace/git-worktree.js.map +1 -1
- package/dist/store/evidence/source-kind.d.ts +1 -1
- package/dist/store/evidence/source-kind.d.ts.map +1 -1
- package/dist/store/evidence/source-kind.js +1 -1
- package/dist/store/evidence/source-kind.js.map +1 -1
- package/dist/store/goal/index.d.ts +53 -3
- package/dist/store/goal/index.d.ts.map +1 -1
- package/dist/store/goal/index.js +245 -9
- package/dist/store/goal/index.js.map +1 -1
- package/dist/store/session-index/sqlite.d.ts.map +1 -1
- package/dist/store/session-index/sqlite.js +42 -3
- package/dist/store/session-index/sqlite.js.map +1 -1
- package/dist/store/session-log/disk.js +1 -1
- package/dist/store/session-log/disk.js.map +1 -1
- package/dist/store/session-log/lease.d.ts.map +1 -1
- package/dist/store/session-log/lease.js +3 -2
- package/dist/store/session-log/lease.js.map +1 -1
- package/dist/tools/admit-facts.d.ts.map +1 -1
- package/dist/tools/admit-facts.js +2 -0
- package/dist/tools/admit-facts.js.map +1 -1
- package/dist/tools/builtins/bash.d.ts +10 -2
- package/dist/tools/builtins/bash.d.ts.map +1 -1
- package/dist/tools/builtins/bash.js +56 -17
- package/dist/tools/builtins/bash.js.map +1 -1
- package/dist/tools/builtins/browser-local.d.ts +117 -0
- package/dist/tools/builtins/browser-local.d.ts.map +1 -0
- package/dist/tools/builtins/browser-local.js +437 -0
- package/dist/tools/builtins/browser-local.js.map +1 -0
- package/dist/tools/builtins/browser.d.ts +18 -1
- package/dist/tools/builtins/browser.d.ts.map +1 -1
- package/dist/tools/builtins/browser.js +84 -6
- package/dist/tools/builtins/browser.js.map +1 -1
- package/dist/tools/builtins/computer-use-window-id.d.ts +16 -0
- package/dist/tools/builtins/computer-use-window-id.d.ts.map +1 -0
- package/dist/tools/builtins/computer-use-window-id.js +52 -0
- package/dist/tools/builtins/computer-use-window-id.js.map +1 -0
- package/dist/tools/builtins/computer-use.d.ts +65 -7
- package/dist/tools/builtins/computer-use.d.ts.map +1 -1
- package/dist/tools/builtins/computer-use.js +384 -71
- package/dist/tools/builtins/computer-use.js.map +1 -1
- package/dist/tools/builtins/content-fingerprint.d.ts +6 -0
- package/dist/tools/builtins/content-fingerprint.d.ts.map +1 -1
- package/dist/tools/builtins/content-fingerprint.js +7 -1
- 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 +89 -7
- package/dist/tools/builtins/edit.js.map +1 -1
- package/dist/tools/builtins/file-write-result.d.ts.map +1 -1
- package/dist/tools/builtins/file-write-result.js +2 -1
- package/dist/tools/builtins/file-write-result.js.map +1 -1
- package/dist/tools/builtins/grep.js +1 -1
- package/dist/tools/builtins/grep.js.map +1 -1
- package/dist/tools/builtins/job.d.ts.map +1 -1
- package/dist/tools/builtins/job.js +4 -2
- package/dist/tools/builtins/job.js.map +1 -1
- package/dist/tools/builtins/monitor.d.ts.map +1 -1
- package/dist/tools/builtins/monitor.js +6 -1
- package/dist/tools/builtins/monitor.js.map +1 -1
- package/dist/tools/builtins/search-tools.d.ts +12 -1
- package/dist/tools/builtins/search-tools.d.ts.map +1 -1
- package/dist/tools/builtins/search-tools.js +166 -20
- package/dist/tools/builtins/search-tools.js.map +1 -1
- package/dist/tools/builtins/shell-read-credit.d.ts +18 -6
- package/dist/tools/builtins/shell-read-credit.d.ts.map +1 -1
- package/dist/tools/builtins/shell-read-credit.js +95 -27
- package/dist/tools/builtins/shell-read-credit.js.map +1 -1
- package/dist/tools/builtins/wait-for-job.d.ts.map +1 -1
- package/dist/tools/builtins/wait-for-job.js +14 -3
- package/dist/tools/builtins/wait-for-job.js.map +1 -1
- package/dist/tools/builtins/web-guidance.d.ts +6 -0
- package/dist/tools/builtins/web-guidance.d.ts.map +1 -1
- package/dist/tools/builtins/web-guidance.js +6 -0
- package/dist/tools/builtins/web-guidance.js.map +1 -1
- package/dist/tools/builtins/web.d.ts.map +1 -1
- package/dist/tools/builtins/web.js +2 -1
- package/dist/tools/builtins/web.js.map +1 -1
- package/dist/tools/builtins/write-file.d.ts.map +1 -1
- package/dist/tools/builtins/write-file.js +32 -2
- package/dist/tools/builtins/write-file.js.map +1 -1
- package/dist/tools/command-shell.d.ts +1 -1
- package/dist/tools/command-shell.d.ts.map +1 -1
- package/dist/tools/command-shell.js +6 -8
- package/dist/tools/command-shell.js.map +1 -1
- package/dist/tools/defineTool.d.ts +2 -0
- package/dist/tools/defineTool.d.ts.map +1 -1
- package/dist/tools/defineTool.js +17 -1
- package/dist/tools/defineTool.js.map +1 -1
- package/dist/tools/goal/confirmation.d.ts +82 -1
- package/dist/tools/goal/confirmation.d.ts.map +1 -1
- package/dist/tools/goal/confirmation.js +153 -3
- package/dist/tools/goal/confirmation.js.map +1 -1
- package/dist/tools/goal/index.d.ts.map +1 -1
- package/dist/tools/goal/index.js +34 -3
- package/dist/tools/goal/index.js.map +1 -1
- package/dist/tools/schedules/index.d.ts +1 -0
- package/dist/tools/schedules/index.d.ts.map +1 -1
- package/dist/tools/schedules/index.js +1 -0
- package/dist/tools/schedules/index.js.map +1 -1
- package/dist/tools/schedules/loop-tool.d.ts.map +1 -1
- package/dist/tools/schedules/loop-tool.js +8 -6
- package/dist/tools/schedules/loop-tool.js.map +1 -1
- package/dist/tools/schedules/present.js +1 -1
- package/dist/tools/schedules/present.js.map +1 -1
- package/dist/tools/schedules/timer-tools.d.ts +36 -0
- package/dist/tools/schedules/timer-tools.d.ts.map +1 -0
- package/dist/tools/schedules/timer-tools.js +234 -0
- package/dist/tools/schedules/timer-tools.js.map +1 -0
- package/dist/tools/schedules/types.d.ts +68 -3
- package/dist/tools/schedules/types.d.ts.map +1 -1
- package/dist/tools/task/create.d.ts.map +1 -1
- package/dist/tools/task/create.js +2 -0
- package/dist/tools/task/create.js.map +1 -1
- package/dist/toolsets/manager.d.ts +49 -7
- package/dist/toolsets/manager.d.ts.map +1 -1
- package/dist/toolsets/manager.js +239 -40
- package/dist/toolsets/manager.js.map +1 -1
- package/dist/turn/evidence-query.d.ts +18 -1
- package/dist/turn/evidence-query.d.ts.map +1 -1
- package/dist/turn/evidence-query.js +177 -35
- package/dist/turn/evidence-query.js.map +1 -1
- package/dist/turn/evidence-recall.d.ts +8 -1
- package/dist/turn/evidence-recall.d.ts.map +1 -1
- package/dist/turn/evidence-recall.js +82 -22
- package/dist/turn/evidence-recall.js.map +1 -1
- package/dist/turn/history-shed.d.ts +15 -0
- package/dist/turn/history-shed.d.ts.map +1 -0
- package/dist/turn/history-shed.js +23 -0
- package/dist/turn/history-shed.js.map +1 -0
- package/dist/types/acp/index.d.ts +26 -0
- package/dist/types/acp/index.d.ts.map +1 -1
- package/dist/types/authorization/index.d.ts +9 -1
- package/dist/types/authorization/index.d.ts.map +1 -1
- package/dist/types/authorization/index.js +11 -2
- package/dist/types/authorization/index.js.map +1 -1
- package/dist/types/command/index.d.ts +26 -2
- package/dist/types/command/index.d.ts.map +1 -1
- package/dist/types/command/index.js +5 -2
- package/dist/types/command/index.js.map +1 -1
- package/dist/types/common/index.d.ts +4 -2
- package/dist/types/common/index.d.ts.map +1 -1
- package/dist/types/common/index.js.map +1 -1
- package/dist/types/goal/index.d.ts +59 -0
- package/dist/types/goal/index.d.ts.map +1 -1
- package/dist/types/hitl/index.d.ts +10 -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 +56 -1
- package/dist/types/message/index.d.ts.map +1 -1
- package/dist/types/message/index.js +2 -1
- package/dist/types/message/index.js.map +1 -1
- package/dist/types/permission/index.d.ts +14 -0
- package/dist/types/permission/index.d.ts.map +1 -1
- package/dist/types/permission/index.js +14 -0
- package/dist/types/permission/index.js.map +1 -1
- package/dist/types/plugin/index.d.ts +148 -1
- package/dist/types/plugin/index.d.ts.map +1 -1
- package/dist/types/plugin/index.js +9 -0
- package/dist/types/plugin/index.js.map +1 -1
- package/dist/types/provider/chat.d.ts +10 -5
- package/dist/types/provider/chat.d.ts.map +1 -1
- package/dist/types/provider/index.d.ts +1 -0
- package/dist/types/provider/index.d.ts.map +1 -1
- package/dist/types/provider/interface.d.ts +19 -0
- package/dist/types/provider/interface.d.ts.map +1 -1
- package/dist/types/provider/limits.d.ts +33 -0
- package/dist/types/provider/limits.d.ts.map +1 -0
- package/dist/types/provider/limits.js +7 -0
- package/dist/types/provider/limits.js.map +1 -0
- package/dist/types/provider/model.d.ts +5 -0
- package/dist/types/provider/model.d.ts.map +1 -1
- package/dist/types/session/config.d.ts +2 -2
- package/dist/types/session/outcome.d.ts +5 -2
- package/dist/types/session/outcome.d.ts.map +1 -1
- package/dist/types/session/outcome.js.map +1 -1
- package/dist/types/tool/index.d.ts +30 -0
- package/dist/types/tool/index.d.ts.map +1 -1
- package/dist/types/tool/index.js.map +1 -1
- package/dist/types/tool/presentation.d.ts +4 -0
- package/dist/types/tool/presentation.d.ts.map +1 -1
- package/dist/utils/cost.d.ts +1 -1
- package/dist/utils/cost.d.ts.map +1 -1
- package/dist/utils/cost.js +14 -5
- package/dist/utils/cost.js.map +1 -1
- package/dist/utils/file-lock.d.ts +88 -0
- package/dist/utils/file-lock.d.ts.map +1 -0
- package/dist/utils/file-lock.js +281 -0
- package/dist/utils/file-lock.js.map +1 -0
- package/dist/utils/state-backup.d.ts +87 -0
- package/dist/utils/state-backup.d.ts.map +1 -0
- package/dist/utils/state-backup.js +272 -0
- package/dist/utils/state-backup.js.map +1 -0
- package/dist/utils/temp-sweep.d.ts +66 -0
- package/dist/utils/temp-sweep.d.ts.map +1 -0
- package/dist/utils/temp-sweep.js +311 -0
- package/dist/utils/temp-sweep.js.map +1 -0
- package/dist/utils/temp.d.ts +14 -0
- package/dist/utils/temp.d.ts.map +1 -1
- package/dist/utils/temp.js +70 -2
- package/dist/utils/temp.js.map +1 -1
- package/package.json +1 -1
- package/src/account/lock.ts +13 -133
- package/src/account/registry.ts +75 -21
- package/src/account/types.ts +8 -9
- package/src/authorization/dangerous-commands.ts +542 -0
- package/src/authorization/gate.ts +19 -5
- package/src/authorization/protected-paths.ts +13 -8
- package/src/authorization/readonly-commands.ts +35 -1
- package/src/authorization/removal.ts +7 -7
- package/src/authorization/rules.ts +75 -15
- package/src/authorization/shell-lexer.ts +19 -0
- package/src/bridge/acp/permission.ts +2 -0
- package/src/bridge/acp/server.ts +66 -6
- package/src/compaction/context-breakdown.ts +53 -11
- package/src/compaction/dangling.ts +2 -0
- package/src/compaction/extractor.ts +9 -1
- package/src/compaction/index.ts +1 -0
- package/src/compaction/managers/structured.ts +2 -2
- package/src/compaction/manual.ts +11 -3
- package/src/compaction/model-summary.ts +8 -1
- package/src/compaction/summary.ts +54 -7
- package/src/constants/tools/index.ts +30 -16
- package/src/manager/session/turn-recorder.ts +37 -1
- package/src/network/audit.ts +113 -0
- package/src/network/clock.ts +62 -0
- package/src/network/discovery-mdns.ts +485 -0
- package/src/network/discovery.ts +210 -0
- package/src/network/fingerprint.ts +241 -0
- package/src/network/identity.ts +98 -0
- package/src/network/index.ts +134 -0
- package/src/network/join.ts +177 -0
- package/src/network/mail-policy.ts +199 -0
- package/src/network/membership.ts +290 -0
- package/src/network/roster.ts +165 -0
- package/src/network/service.ts +2304 -0
- package/src/network/store.ts +261 -0
- package/src/network/transport.ts +445 -0
- package/src/network/wire.ts +250 -0
- package/src/network/x509.ts +114 -0
- package/src/pals/activity/causality.ts +16 -2
- package/src/peers/endpoint.ts +6 -0
- package/src/peers/envelope.ts +82 -5
- package/src/peers/index.ts +10 -2
- package/src/peers/mode-word.ts +18 -0
- package/src/peers/protocol.ts +24 -1
- package/src/peers/record.ts +5 -0
- package/src/plugin/session-hook-env.ts +25 -2
- package/src/plugin/shell-hook.ts +208 -14
- package/src/pricing/catalogue.generated.ts +6 -0
- package/src/pricing/rates.source.json +13 -7
- package/src/prompt/coding-agent-doctrine.ts +33 -38
- package/src/provider/fallback.ts +11 -0
- package/src/provider/idle-timeout.ts +5 -0
- package/src/provider/model-window-suffix.ts +1 -0
- package/src/provider/retry.ts +5 -0
- package/src/public-runtime.ts +116 -1
- package/src/public-tools.ts +11 -0
- package/src/public-types.ts +74 -1
- package/src/registry/command/kernel-commands.ts +136 -49
- package/src/runtime/jobs/registry.ts +93 -3
- package/src/runtime/query/auto-review/classifier.ts +76 -14
- package/src/runtime/query/auto-review/feedback.ts +50 -0
- package/src/runtime/query/auto-review/git-status.ts +437 -0
- package/src/runtime/query/auto-review/index.ts +7 -2
- package/src/runtime/query/auto-review/prompt.ts +6 -1
- package/src/runtime/query/auto-review/transcript.ts +67 -4
- package/src/runtime/query/executor/tool-call-admission.ts +49 -3
- package/src/runtime/query/executor.ts +104 -21
- package/src/runtime/query/index.ts +66 -17
- package/src/runtime/query/iteration/index.ts +33 -9
- package/src/runtime/query/iteration/phases/compaction.ts +4 -0
- package/src/runtime/query/iteration/phases/context.ts +5 -0
- package/src/runtime/query/iteration/phases/per-call-review.ts +8 -13
- package/src/runtime/query/iteration/phases/tool-review.ts +7 -1
- package/src/runtime/query/pasted-frames.ts +119 -0
- package/src/runtime/query/path-escalation.ts +27 -3
- package/src/runtime/query/request-interrupted-turns.ts +47 -0
- package/src/runtime/query/review-policy.ts +125 -22
- package/src/runtime/query/turn/outcome-ledger.ts +99 -6
- package/src/runtime/query/unanswered.ts +35 -0
- package/src/runtime/system-events.ts +2 -0
- package/src/session/workspace/git-worktree.ts +34 -3
- package/src/store/evidence/source-kind.ts +1 -1
- package/src/store/goal/index.ts +320 -21
- package/src/store/session-index/sqlite.ts +40 -3
- package/src/store/session-log/disk.ts +1 -1
- package/src/store/session-log/lease.ts +3 -2
- package/src/tools/admit-facts.ts +2 -0
- package/src/tools/builtins/bash.ts +62 -19
- package/src/tools/builtins/browser-local.ts +504 -0
- package/src/tools/builtins/browser.ts +108 -6
- package/src/tools/builtins/computer-use-window-id.ts +50 -0
- package/src/tools/builtins/computer-use.ts +460 -68
- package/src/tools/builtins/content-fingerprint.ts +8 -1
- package/src/tools/builtins/edit.ts +93 -7
- package/src/tools/builtins/file-write-result.ts +2 -1
- package/src/tools/builtins/grep.ts +1 -1
- package/src/tools/builtins/job.ts +4 -2
- package/src/tools/builtins/monitor.ts +6 -1
- package/src/tools/builtins/search-tools.ts +196 -21
- package/src/tools/builtins/shell-read-credit.ts +97 -33
- package/src/tools/builtins/wait-for-job.ts +13 -3
- package/src/tools/builtins/web-guidance.ts +6 -0
- package/src/tools/builtins/web.ts +2 -1
- package/src/tools/builtins/write-file.ts +31 -3
- package/src/tools/command-shell.ts +6 -8
- package/src/tools/defineTool.ts +20 -1
- package/src/tools/goal/confirmation.ts +227 -3
- package/src/tools/goal/index.ts +40 -4
- package/src/tools/schedules/index.ts +11 -0
- package/src/tools/schedules/loop-tool.ts +10 -6
- package/src/tools/schedules/present.ts +1 -1
- package/src/tools/schedules/timer-tools.ts +258 -0
- package/src/tools/schedules/types.ts +72 -3
- package/src/tools/task/create.ts +2 -0
- package/src/toolsets/manager.ts +262 -46
- package/src/turn/evidence-query.ts +183 -42
- package/src/turn/evidence-recall.ts +96 -19
- package/src/turn/history-shed.ts +30 -0
- package/src/types/acp/index.ts +24 -0
- package/src/types/authorization/index.ts +20 -3
- package/src/types/command/index.ts +27 -2
- package/src/types/common/index.ts +4 -2
- package/src/types/goal/index.ts +61 -0
- package/src/types/hitl/index.ts +10 -0
- package/src/types/message/index.ts +65 -0
- package/src/types/permission/index.ts +18 -0
- package/src/types/plugin/index.ts +205 -26
- package/src/types/provider/chat.ts +10 -5
- package/src/types/provider/index.ts +1 -0
- package/src/types/provider/interface.ts +21 -0
- package/src/types/provider/limits.ts +35 -0
- package/src/types/provider/model.ts +5 -0
- package/src/types/session/config.ts +2 -2
- package/src/types/session/outcome.ts +3 -1
- package/src/types/tool/index.ts +30 -2
- package/src/types/tool/presentation.ts +4 -0
- package/src/utils/cost.ts +15 -6
- package/src/utils/file-lock.ts +328 -0
- package/src/utils/state-backup.ts +318 -0
- package/src/utils/temp-sweep.ts +327 -0
- package/src/utils/temp.ts +73 -2
|
@@ -64,10 +64,29 @@ export interface GitWorktreeDriverConfig {
|
|
|
64
64
|
*/
|
|
65
65
|
worktreesDir?: string
|
|
66
66
|
logger: Logger
|
|
67
|
+
/**
|
|
68
|
+
* The first part of every branch this driver makes: `<branchPrefix>/<label>`.
|
|
69
|
+
* One safe component (letters, digits, `.`, `_`, `-`; at most 40 characters).
|
|
70
|
+
* Defaults to `namzu`. A worktree made under another prefix is still owned
|
|
71
|
+
* and still found, because Git, not the prefix, vouches for the branch.
|
|
72
|
+
*/
|
|
73
|
+
branchPrefix?: string
|
|
67
74
|
/** Test-seam: inject a stub `execFile` implementation. */
|
|
68
75
|
execFile?: ExecFile
|
|
69
76
|
}
|
|
70
77
|
|
|
78
|
+
const DEFAULT_BRANCH_PREFIX = 'namzu'
|
|
79
|
+
|
|
80
|
+
/** One safe branch component: no slash, no leading dot or hyphen, no Git syntax. */
|
|
81
|
+
function isBranchPrefix(value: string): boolean {
|
|
82
|
+
return (
|
|
83
|
+
/^[A-Za-z0-9_][A-Za-z0-9._-]{0,39}$/.test(value) &&
|
|
84
|
+
!value.endsWith('.') &&
|
|
85
|
+
!value.includes('..') &&
|
|
86
|
+
!value.endsWith('.lock')
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
|
|
71
90
|
export class GitWorktreeDriver implements WorkspaceBackendDriver {
|
|
72
91
|
readonly kind = 'git-worktree' as const
|
|
73
92
|
|
|
@@ -75,12 +94,20 @@ export class GitWorktreeDriver implements WorkspaceBackendDriver {
|
|
|
75
94
|
private readonly worktreesDir: string
|
|
76
95
|
private readonly log: Logger
|
|
77
96
|
private readonly exec: ExecFile
|
|
97
|
+
private readonly branchPrefix: string
|
|
78
98
|
|
|
79
99
|
constructor(config: GitWorktreeDriverConfig) {
|
|
80
100
|
this.repoRoot = resolve(config.repoRoot)
|
|
81
101
|
this.worktreesDir = resolve(config.worktreesDir ?? defaultWorktreesDir(config.repoRoot))
|
|
82
102
|
this.log = config.logger.child({ [SCOPE_ATTRIBUTE]: 'session/workspace/git-worktree' })
|
|
83
103
|
this.exec = config.execFile ?? defaultExecFile
|
|
104
|
+
const prefix = config.branchPrefix ?? DEFAULT_BRANCH_PREFIX
|
|
105
|
+
if (!isBranchPrefix(prefix)) {
|
|
106
|
+
throw new Error(
|
|
107
|
+
'A worktree branch prefix must be 1 to 40 letters, digits, dots, underscores or hyphens, and must not start with a dot or hyphen.',
|
|
108
|
+
)
|
|
109
|
+
}
|
|
110
|
+
this.branchPrefix = prefix
|
|
84
111
|
}
|
|
85
112
|
|
|
86
113
|
async create(params: CreateWorkspaceParams): Promise<WorkspaceRef> {
|
|
@@ -112,7 +139,7 @@ export class GitWorktreeDriver implements WorkspaceBackendDriver {
|
|
|
112
139
|
}
|
|
113
140
|
|
|
114
141
|
const relativePath = relative(worktreesDir, worktreePath).split(sep).join('/')
|
|
115
|
-
const branch =
|
|
142
|
+
const branch = `${this.branchPrefix}/${relativePath}`
|
|
116
143
|
|
|
117
144
|
// `--` belongs before caller-controlled positional arguments. Without it,
|
|
118
145
|
// a base ref such as `--no-checkout` is accepted as a Git option and the
|
|
@@ -349,8 +376,12 @@ export class GitWorktreeDriver implements WorkspaceBackendDriver {
|
|
|
349
376
|
}
|
|
350
377
|
|
|
351
378
|
const label = relative(worktreesDir, worktreePath).split(sep).join('/')
|
|
352
|
-
|
|
353
|
-
|
|
379
|
+
// The prefix is whatever the host chose when the worktree was made, so
|
|
380
|
+
// it may differ from the one set now. Ownership rests on the path and
|
|
381
|
+
// on Git registering exactly this branch there, not on the prefix.
|
|
382
|
+
const branch = ref.meta.branch
|
|
383
|
+
const suffix = `/${label}`
|
|
384
|
+
if (!branch.endsWith(suffix) || !isBranchPrefix(branch.slice(0, -suffix.length))) {
|
|
354
385
|
throw new Error('Workspace reference branch does not match its managed path')
|
|
355
386
|
}
|
|
356
387
|
|
|
@@ -33,4 +33,4 @@ export function classifyEvidenceSource(source: string): EvidenceRecordKind {
|
|
|
33
33
|
|
|
34
34
|
/** Shared model-facing interpretation for hosts projecting recorded evidence. */
|
|
35
35
|
export const EVIDENCE_RECORD_GUIDANCE =
|
|
36
|
-
'Producer kinds do not establish truth or independence. assistant_message is a
|
|
36
|
+
'Producer kinds do not establish truth or independence. assistant_message is what the assistant itself said earlier in this conversation. For a question about what you said or why, it is the record: quote it and answer from it. For a question about what is true now, a prior claim is not proof of observed state or successful action; attribute it as a claim unless supported by the original observation, and re-check only the current state. Tool results may themselves quote claims.'
|
package/src/store/goal/index.ts
CHANGED
|
@@ -4,9 +4,11 @@ import { TenantIsolationError } from '../../session/errors.js'
|
|
|
4
4
|
import type {
|
|
5
5
|
GoalBlockReason,
|
|
6
6
|
GoalConfirmedBy,
|
|
7
|
+
GoalGuards,
|
|
7
8
|
GoalPhase,
|
|
8
9
|
GoalRef,
|
|
9
10
|
GoalRoundAuthority,
|
|
11
|
+
GoalRoundOutcome,
|
|
10
12
|
SessionGoal,
|
|
11
13
|
} from '../../types/goal/index.js'
|
|
12
14
|
import type { GoalId, SessionId, TenantId } from '../../types/ids/index.js'
|
|
@@ -26,10 +28,23 @@ export const MAX_GOAL_OBJECTIVE_CHARS = 4_000
|
|
|
26
28
|
/** Source-aligned default; hosts may choose a smaller positive finite cap. */
|
|
27
29
|
export const DEFAULT_MAX_GOAL_ROUNDS = 256
|
|
28
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Automatic turns in a row without progress, or ending on the same failure,
|
|
33
|
+
* after which a host that applies the stop rules blocks the goal. Three: a
|
|
34
|
+
* first empty turn is normal (the model looked around), a second can be a
|
|
35
|
+
* check that needed a rerun, a third is a loop.
|
|
36
|
+
*/
|
|
37
|
+
export const DEFAULT_GOAL_STALL_ROUNDS = 3
|
|
38
|
+
|
|
39
|
+
/** Admitted rounds between check-in pauses that a host applying them may choose. */
|
|
40
|
+
export const DEFAULT_GOAL_CHECK_IN_ROUNDS = 50
|
|
41
|
+
|
|
29
42
|
export interface CreateSessionGoalParams {
|
|
30
43
|
readonly sessionId: SessionId
|
|
31
44
|
readonly objective: string
|
|
32
45
|
readonly maxGoalRounds?: number
|
|
46
|
+
/** Stop rules for this goal; absent fields are not applied. */
|
|
47
|
+
readonly guards?: GoalGuards
|
|
33
48
|
/** Set only when this goal chooses; absent leaves the choice to the host's setting. */
|
|
34
49
|
readonly confirmedBy?: GoalConfirmedBy
|
|
35
50
|
}
|
|
@@ -48,7 +63,12 @@ export interface SessionGoalStore {
|
|
|
48
63
|
changes: EditSessionGoalParams,
|
|
49
64
|
): Promise<SessionGoal>
|
|
50
65
|
pauseGoal(sessionId: SessionId, tenantId: TenantId, ref: GoalRef): Promise<SessionGoal>
|
|
51
|
-
resumeGoal(
|
|
66
|
+
resumeGoal(
|
|
67
|
+
sessionId: SessionId,
|
|
68
|
+
tenantId: TenantId,
|
|
69
|
+
ref: GoalRef,
|
|
70
|
+
options?: ResumeSessionGoalOptions,
|
|
71
|
+
): Promise<SessionGoal>
|
|
52
72
|
/** Durably reserve one automatic round before any provider work begins. */
|
|
53
73
|
admitRound(sessionId: SessionId, tenantId: TenantId, ref: GoalRef): Promise<GoalRoundAuthority>
|
|
54
74
|
completeGoal(sessionId: SessionId, tenantId: TenantId, ref: GoalRef): Promise<SessionGoal>
|
|
@@ -59,6 +79,51 @@ export interface SessionGoalStore {
|
|
|
59
79
|
reason: GoalBlockReason,
|
|
60
80
|
): Promise<SessionGoal>
|
|
61
81
|
clearGoal(sessionId: SessionId, tenantId: TenantId, ref: GoalRef): Promise<void>
|
|
82
|
+
/**
|
|
83
|
+
* Write down what one finished automatic turn did: what it spent, whether it
|
|
84
|
+
* moved the work, and the failure it ended on. The stop rules read these
|
|
85
|
+
* counts, so a goal that did nothing for `stallRounds` turns in a row, or
|
|
86
|
+
* ended on the same failure that many times, is blocked here. Optional so a
|
|
87
|
+
* store written before it existed still satisfies the interface; without it a
|
|
88
|
+
* host's goals are never stopped by those rules. Returns `null` when the
|
|
89
|
+
* session has no goal of that id.
|
|
90
|
+
*/
|
|
91
|
+
recordRound?(
|
|
92
|
+
sessionId: SessionId,
|
|
93
|
+
tenantId: TenantId,
|
|
94
|
+
goalId: GoalId,
|
|
95
|
+
outcome: GoalRoundOutcome,
|
|
96
|
+
): Promise<SessionGoal | null>
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** What a resume may raise so that a goal stopped by a limit can go on. */
|
|
100
|
+
export interface ResumeSessionGoalOptions {
|
|
101
|
+
/** Replaces the round cap when larger than the current one. */
|
|
102
|
+
readonly maxGoalRounds?: number
|
|
103
|
+
/** Replaces the token budget when larger than the current one. */
|
|
104
|
+
readonly tokenBudget?: number
|
|
105
|
+
/**
|
|
106
|
+
* Stop rules to fill in for a goal that has none of its own, such as one saved
|
|
107
|
+
* before they existed. A rule the goal already has is kept.
|
|
108
|
+
*/
|
|
109
|
+
readonly guards?: GoalGuards
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** What a goal has cost so far, as a dollar amount. */
|
|
113
|
+
export function goalCostText(goal: Pick<SessionGoal, 'costUsd'>): string {
|
|
114
|
+
const cost = goal.costUsd ?? 0
|
|
115
|
+
return cost > 0 && cost < 0.01 ? `$${cost.toFixed(4)}` : `$${cost.toFixed(2)}`
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** What a goal has tokens-spent so far, as a number with separators. */
|
|
119
|
+
export function goalTokensText(goal: Pick<SessionGoal, 'tokensUsed'>): string {
|
|
120
|
+
return (goal.tokensUsed ?? 0).toLocaleString('en-US')
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** The sentence that says what a goal has spent: automatic turns, tokens and cost. */
|
|
124
|
+
export function goalUsageSentence(goal: SessionGoal): string {
|
|
125
|
+
const rounds = goal.roundsAdmitted
|
|
126
|
+
return `${rounds} automatic turn${rounds === 1 ? '' : 's'}, ${goalTokensText(goal)} tokens, ${goalCostText(goal)}`
|
|
62
127
|
}
|
|
63
128
|
|
|
64
129
|
/** A mutation was based on a goal revision that is no longer current. */
|
|
@@ -121,6 +186,27 @@ export class GoalRoundLimitError extends Error {
|
|
|
121
186
|
}
|
|
122
187
|
}
|
|
123
188
|
|
|
189
|
+
/** Admission paused the goal for a check-in instead of starting another round. */
|
|
190
|
+
export class GoalCheckInError extends Error {
|
|
191
|
+
constructor(readonly goal: SessionGoal) {
|
|
192
|
+
super(`Goal ${goal.id} paused for a check-in after ${goal.roundsAdmitted} automatic rounds.`)
|
|
193
|
+
this.name = 'GoalCheckInError'
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** Admission blocked the goal because its token budget was spent and its last round given. */
|
|
198
|
+
export class GoalBudgetLimitError extends Error {
|
|
199
|
+
constructor(readonly goal: SessionGoal) {
|
|
200
|
+
super(`Goal ${goal.id} reached its token budget.`)
|
|
201
|
+
this.name = 'GoalBudgetLimitError'
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
type AdmitOutcome =
|
|
206
|
+
| { readonly kind: 'admitted'; readonly authority: GoalRoundAuthority }
|
|
207
|
+
| { readonly kind: 'exhausted'; readonly goal: SessionGoal }
|
|
208
|
+
| { readonly kind: 'check-in'; readonly goal: SessionGoal }
|
|
209
|
+
|
|
124
210
|
interface SessionGoalRecord {
|
|
125
211
|
readonly sessionId: SessionId
|
|
126
212
|
readonly tenantId: TenantId
|
|
@@ -202,6 +288,27 @@ function maxGoalRounds(value: number | undefined): number {
|
|
|
202
288
|
return resolved
|
|
203
289
|
}
|
|
204
290
|
|
|
291
|
+
function guardNumber(name: string, value: number | undefined, minimum: number): number | undefined {
|
|
292
|
+
if (value === undefined) return undefined
|
|
293
|
+
if (!Number.isSafeInteger(value) || value < minimum) {
|
|
294
|
+
throw new TypeError(`${name} must be a safe integer of at least ${minimum}, got ${value}.`)
|
|
295
|
+
}
|
|
296
|
+
return value
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function goalGuards(value: GoalGuards | undefined): GoalGuards | undefined {
|
|
300
|
+
if (value === undefined) return undefined
|
|
301
|
+
const stallRounds = guardNumber('stallRounds', value.stallRounds, 1)
|
|
302
|
+
const checkInEvery = guardNumber('checkInEvery', value.checkInEvery, 0)
|
|
303
|
+
const tokenBudget = guardNumber('tokenBudget', value.tokenBudget, 1)
|
|
304
|
+
const guards: GoalGuards = {
|
|
305
|
+
...(stallRounds !== undefined ? { stallRounds } : {}),
|
|
306
|
+
...(checkInEvery !== undefined ? { checkInEvery } : {}),
|
|
307
|
+
...(tokenBudget !== undefined ? { tokenBudget } : {}),
|
|
308
|
+
}
|
|
309
|
+
return Object.keys(guards).length > 0 ? guards : undefined
|
|
310
|
+
}
|
|
311
|
+
|
|
205
312
|
function blockReason(value: GoalBlockReason): GoalBlockReason {
|
|
206
313
|
if (
|
|
207
314
|
typeof value?.code !== 'string' ||
|
|
@@ -276,6 +383,7 @@ abstract class SessionGoalStoreBase implements SessionGoalStore {
|
|
|
276
383
|
const sessionId = await this.requireSession(params.sessionId, tenantId)
|
|
277
384
|
const text = objective(params.objective)
|
|
278
385
|
const maxRounds = maxGoalRounds(params.maxGoalRounds)
|
|
386
|
+
const guards = goalGuards(params.guards)
|
|
279
387
|
if (
|
|
280
388
|
params.confirmedBy !== undefined &&
|
|
281
389
|
params.confirmedBy !== 'model' &&
|
|
@@ -300,6 +408,7 @@ abstract class SessionGoalStoreBase implements SessionGoalStore {
|
|
|
300
408
|
phase: 'active',
|
|
301
409
|
maxGoalRounds: maxRounds,
|
|
302
410
|
roundsAdmitted: 0,
|
|
411
|
+
...(guards !== undefined ? { guards } : {}),
|
|
303
412
|
...(params.confirmedBy !== undefined ? { confirmedBy: params.confirmedBy } : {}),
|
|
304
413
|
createdAt: now,
|
|
305
414
|
updatedAt: now,
|
|
@@ -337,15 +446,62 @@ abstract class SessionGoalStoreBase implements SessionGoalStore {
|
|
|
337
446
|
return await this.transition(sessionId, tenantId, ref, 'pause', ['active'], 'paused')
|
|
338
447
|
}
|
|
339
448
|
|
|
340
|
-
async resumeGoal(
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
)
|
|
449
|
+
async resumeGoal(
|
|
450
|
+
sessionId: SessionId,
|
|
451
|
+
tenantId: TenantId,
|
|
452
|
+
ref: GoalRef,
|
|
453
|
+
options: ResumeSessionGoalOptions = {},
|
|
454
|
+
): Promise<SessionGoal> {
|
|
455
|
+
const checked = await this.requireSession(sessionId, tenantId)
|
|
456
|
+
const expected = validRef(ref)
|
|
457
|
+
const raisedRounds = guardNumber('maxGoalRounds', options.maxGoalRounds, 1)
|
|
458
|
+
const raisedBudget = guardNumber('tokenBudget', options.tokenBudget, 1)
|
|
459
|
+
return await this.mutate(checked, tenantId, expected, (goal) => {
|
|
460
|
+
if (goal.phase !== 'paused' && goal.phase !== 'blocked') {
|
|
461
|
+
throw new GoalTransitionError(goal.phase, 'resume')
|
|
462
|
+
}
|
|
463
|
+
const {
|
|
464
|
+
blockedReason: _blockedReason,
|
|
465
|
+
pauseReason: _pauseReason,
|
|
466
|
+
quietRounds: _quietRounds,
|
|
467
|
+
failureRounds: _failureRounds,
|
|
468
|
+
failureSignature: _failureSignature,
|
|
469
|
+
wrapUpRound: _wrapUpRound,
|
|
470
|
+
...rest
|
|
471
|
+
} = goal
|
|
472
|
+
// A resume starts the stall counts again; the round count and the
|
|
473
|
+
// check-in position are never reset, so a check-in resumed continues.
|
|
474
|
+
// A rule the host sets on resume replaces the stored one, so a
|
|
475
|
+
// check-in of 0 turns it off and a looser limit takes effect.
|
|
476
|
+
const filled = goalGuards(options.guards)
|
|
477
|
+
const own: GoalGuards | undefined =
|
|
478
|
+
filled === undefined && goal.guards === undefined
|
|
479
|
+
? undefined
|
|
480
|
+
: { ...goal.guards, ...filled }
|
|
481
|
+
const budget =
|
|
482
|
+
raisedBudget !== undefined && raisedBudget > (own?.tokenBudget ?? 0)
|
|
483
|
+
? raisedBudget
|
|
484
|
+
: own?.tokenBudget
|
|
485
|
+
const guards: GoalGuards | undefined =
|
|
486
|
+
own === undefined && budget === undefined
|
|
487
|
+
? undefined
|
|
488
|
+
: { ...own, ...(budget !== undefined ? { tokenBudget: budget } : {}) }
|
|
489
|
+
// A check-in rule added or changed now counts from here, not from the first round.
|
|
490
|
+
const newCheckIn =
|
|
491
|
+
filled?.checkInEvery !== undefined &&
|
|
492
|
+
filled.checkInEvery > 0 &&
|
|
493
|
+
filled.checkInEvery !== goal.guards?.checkInEvery
|
|
494
|
+
return {
|
|
495
|
+
...rest,
|
|
496
|
+
phase: 'active',
|
|
497
|
+
...(newCheckIn ? { checkedInAtRound: goal.roundsAdmitted } : {}),
|
|
498
|
+
maxGoalRounds:
|
|
499
|
+
raisedRounds !== undefined && raisedRounds > goal.maxGoalRounds
|
|
500
|
+
? raisedRounds
|
|
501
|
+
: goal.maxGoalRounds,
|
|
502
|
+
...(guards !== undefined ? { guards } : {}),
|
|
503
|
+
}
|
|
504
|
+
})
|
|
349
505
|
}
|
|
350
506
|
|
|
351
507
|
async admitRound(
|
|
@@ -355,22 +511,20 @@ abstract class SessionGoalStoreBase implements SessionGoalStore {
|
|
|
355
511
|
): Promise<GoalRoundAuthority> {
|
|
356
512
|
const checked = await this.requireSession(sessionId, tenantId)
|
|
357
513
|
const expected = validRef(ref)
|
|
358
|
-
const outcome = await backendFor(this).transact<
|
|
359
|
-
| { readonly kind: 'admitted'; readonly authority: GoalRoundAuthority }
|
|
360
|
-
| { readonly kind: 'exhausted'; readonly goal: SessionGoal }
|
|
361
|
-
>(checked, (existing) => {
|
|
514
|
+
const outcome = await backendFor(this).transact<AdmitOutcome>(checked, (existing) => {
|
|
362
515
|
const goal = currentGoal(existing, checked, tenantId, expected)
|
|
363
516
|
if (goal.phase !== 'active') throw new GoalTransitionError(goal.phase, 'admit a round for')
|
|
364
517
|
const now = this.now()
|
|
365
|
-
|
|
518
|
+
const stop = (
|
|
519
|
+
reason: GoalBlockReason,
|
|
520
|
+
extra: Partial<SessionGoal> = {},
|
|
521
|
+
): { record: SessionGoalRecord; result: AdmitOutcome } => {
|
|
366
522
|
const blocked: SessionGoal = {
|
|
367
523
|
...goal,
|
|
524
|
+
...extra,
|
|
368
525
|
revision: goal.revision + 1,
|
|
369
526
|
phase: 'blocked',
|
|
370
|
-
blockedReason:
|
|
371
|
-
code: 'round-limit',
|
|
372
|
-
message: `Reached the ${goal.maxGoalRounds}-round limit.`,
|
|
373
|
-
},
|
|
527
|
+
blockedReason: reason,
|
|
374
528
|
updatedAt: now,
|
|
375
529
|
}
|
|
376
530
|
return {
|
|
@@ -384,11 +538,57 @@ abstract class SessionGoalStoreBase implements SessionGoalStore {
|
|
|
384
538
|
result: { kind: 'exhausted', goal: blocked },
|
|
385
539
|
}
|
|
386
540
|
}
|
|
541
|
+
if (goal.roundsAdmitted >= goal.maxGoalRounds) {
|
|
542
|
+
return stop({
|
|
543
|
+
code: 'round-limit',
|
|
544
|
+
message: `Reached the ${goal.maxGoalRounds}-round limit.`,
|
|
545
|
+
})
|
|
546
|
+
}
|
|
547
|
+
const budget = goal.guards?.tokenBudget
|
|
548
|
+
const overBudget = budget !== undefined && (goal.tokensUsed ?? 0) >= budget
|
|
549
|
+
if (overBudget && goal.wrapUpRound !== undefined) {
|
|
550
|
+
return {
|
|
551
|
+
...stop({
|
|
552
|
+
code: 'budget-limited',
|
|
553
|
+
message: `Reached the ${budget.toLocaleString('en-US')}-token budget after ${goalUsageSentence(goal)}.`,
|
|
554
|
+
}),
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
const checkInEvery = goal.guards?.checkInEvery ?? 0
|
|
558
|
+
if (
|
|
559
|
+
!overBudget &&
|
|
560
|
+
checkInEvery > 0 &&
|
|
561
|
+
goal.roundsAdmitted - (goal.checkedInAtRound ?? 0) >= checkInEvery
|
|
562
|
+
) {
|
|
563
|
+
const paused: SessionGoal = {
|
|
564
|
+
...goal,
|
|
565
|
+
revision: goal.revision + 1,
|
|
566
|
+
phase: 'paused',
|
|
567
|
+
pauseReason: {
|
|
568
|
+
code: 'check-in',
|
|
569
|
+
message: `Paused for a check-in after ${goalUsageSentence(goal)}.`,
|
|
570
|
+
},
|
|
571
|
+
checkedInAtRound: goal.roundsAdmitted,
|
|
572
|
+
updatedAt: now,
|
|
573
|
+
}
|
|
574
|
+
return {
|
|
575
|
+
record: {
|
|
576
|
+
sessionId: checked,
|
|
577
|
+
tenantId,
|
|
578
|
+
storageRevision: (existing?.storageRevision ?? 0) + 1,
|
|
579
|
+
goal: paused,
|
|
580
|
+
updatedAt: now,
|
|
581
|
+
},
|
|
582
|
+
result: { kind: 'check-in', goal: paused },
|
|
583
|
+
}
|
|
584
|
+
}
|
|
387
585
|
|
|
586
|
+
const { missing: _missing, ...withoutMissing } = goal
|
|
388
587
|
const admitted: SessionGoal = {
|
|
389
|
-
...
|
|
588
|
+
...withoutMissing,
|
|
390
589
|
revision: goal.revision + 1,
|
|
391
590
|
roundsAdmitted: goal.roundsAdmitted + 1,
|
|
591
|
+
...(overBudget ? { wrapUpRound: goal.roundsAdmitted + 1 } : {}),
|
|
392
592
|
updatedAt: now,
|
|
393
593
|
}
|
|
394
594
|
const authority: GoalRoundAuthority = {
|
|
@@ -399,6 +599,10 @@ abstract class SessionGoalStoreBase implements SessionGoalStore {
|
|
|
399
599
|
objective: admitted.objective,
|
|
400
600
|
round: admitted.roundsAdmitted,
|
|
401
601
|
maxGoalRounds: admitted.maxGoalRounds,
|
|
602
|
+
...(goal.tokensUsed !== undefined ? { tokensUsed: goal.tokensUsed } : {}),
|
|
603
|
+
...(goal.costUsd !== undefined ? { costUsd: goal.costUsd } : {}),
|
|
604
|
+
...(overBudget ? { wrapUp: true } : {}),
|
|
605
|
+
...(goal.missing && goal.missing.length > 0 ? { missing: goal.missing } : {}),
|
|
402
606
|
}
|
|
403
607
|
return {
|
|
404
608
|
record: {
|
|
@@ -411,10 +615,105 @@ abstract class SessionGoalStoreBase implements SessionGoalStore {
|
|
|
411
615
|
result: { kind: 'admitted', authority },
|
|
412
616
|
}
|
|
413
617
|
})
|
|
414
|
-
if (outcome.kind === '
|
|
618
|
+
if (outcome.kind === 'check-in') throw new GoalCheckInError(outcome.goal)
|
|
619
|
+
if (outcome.kind === 'exhausted') {
|
|
620
|
+
if (outcome.goal.blockedReason?.code === 'budget-limited') {
|
|
621
|
+
throw new GoalBudgetLimitError(outcome.goal)
|
|
622
|
+
}
|
|
623
|
+
throw new GoalRoundLimitError(outcome.goal)
|
|
624
|
+
}
|
|
415
625
|
return outcome.authority
|
|
416
626
|
}
|
|
417
627
|
|
|
628
|
+
async recordRound(
|
|
629
|
+
sessionId: SessionId,
|
|
630
|
+
tenantId: TenantId,
|
|
631
|
+
goalId: GoalId,
|
|
632
|
+
outcome: GoalRoundOutcome,
|
|
633
|
+
): Promise<SessionGoal | null> {
|
|
634
|
+
const checked = await this.requireSession(sessionId, tenantId)
|
|
635
|
+
const id = asGoalId(goalId)
|
|
636
|
+
const before = await backendFor(this).read(checked)
|
|
637
|
+
if (!before || before.goal?.id !== id) return null
|
|
638
|
+
return await backendFor(this).transact<SessionGoal | null>(checked, (existing) => {
|
|
639
|
+
if (!existing) throw new GoalNotFoundError(checked)
|
|
640
|
+
assertTenant(existing, tenantId)
|
|
641
|
+
const goal = existing.goal
|
|
642
|
+
const now = this.now()
|
|
643
|
+
if (!goal || goal.id !== id) {
|
|
644
|
+
// The goal was replaced while this was read: nothing to add to.
|
|
645
|
+
return {
|
|
646
|
+
record: {
|
|
647
|
+
sessionId: checked,
|
|
648
|
+
tenantId,
|
|
649
|
+
storageRevision: existing.storageRevision + 1,
|
|
650
|
+
goal: existing.goal,
|
|
651
|
+
updatedAt: now,
|
|
652
|
+
},
|
|
653
|
+
result: null,
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
const guards = goal.guards
|
|
657
|
+
const empty = outcome.progress === 'empty'
|
|
658
|
+
const quietRounds = empty ? (goal.quietRounds ?? 0) + 1 : 0
|
|
659
|
+
const sameFailure =
|
|
660
|
+
outcome.failureSignature !== undefined && outcome.failureSignature === goal.failureSignature
|
|
661
|
+
const failureRounds =
|
|
662
|
+
outcome.failureSignature === undefined ? 0 : sameFailure ? (goal.failureRounds ?? 0) + 1 : 1
|
|
663
|
+
const { failureSignature: _drop, missing: _missing, lastAction: _lastAction, ...rest } = goal
|
|
664
|
+
const lastAction = outcome.action ?? goal.lastAction
|
|
665
|
+
const missing = outcome.missing !== undefined ? outcome.missing : goal.missing
|
|
666
|
+
let updated: SessionGoal = {
|
|
667
|
+
...rest,
|
|
668
|
+
tokensUsed: (goal.tokensUsed ?? 0) + Math.max(0, outcome.tokens ?? 0),
|
|
669
|
+
costUsd: (goal.costUsd ?? 0) + Math.max(0, outcome.costUsd ?? 0),
|
|
670
|
+
quietRounds,
|
|
671
|
+
failureRounds,
|
|
672
|
+
...(outcome.failureSignature !== undefined
|
|
673
|
+
? { failureSignature: outcome.failureSignature }
|
|
674
|
+
: {}),
|
|
675
|
+
...(lastAction !== undefined ? { lastAction } : {}),
|
|
676
|
+
...(missing !== undefined && missing.length > 0 ? { missing } : {}),
|
|
677
|
+
updatedAt: now,
|
|
678
|
+
}
|
|
679
|
+
const stall = guards?.stallRounds
|
|
680
|
+
if (goal.phase === 'active' && stall !== undefined) {
|
|
681
|
+
const after = lastAction !== undefined ? ` Last action: ${lastAction}.` : ''
|
|
682
|
+
if (quietRounds >= stall) {
|
|
683
|
+
updated = {
|
|
684
|
+
...updated,
|
|
685
|
+
revision: goal.revision + 1,
|
|
686
|
+
phase: 'blocked',
|
|
687
|
+
blockedReason: {
|
|
688
|
+
code: 'no-progress',
|
|
689
|
+
message: `${stall} automatic turns in a row changed nothing and checked nothing.${after}`,
|
|
690
|
+
},
|
|
691
|
+
}
|
|
692
|
+
} else if (failureRounds >= stall && outcome.failureSignature !== undefined) {
|
|
693
|
+
updated = {
|
|
694
|
+
...updated,
|
|
695
|
+
revision: goal.revision + 1,
|
|
696
|
+
phase: 'blocked',
|
|
697
|
+
blockedReason: {
|
|
698
|
+
code: 'repeated-failure',
|
|
699
|
+
message: `The same failure ended ${stall} automatic turns in a row: ${outcome.failureSignature}.${after}`,
|
|
700
|
+
},
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
return {
|
|
705
|
+
record: {
|
|
706
|
+
sessionId: checked,
|
|
707
|
+
tenantId,
|
|
708
|
+
storageRevision: existing.storageRevision + 1,
|
|
709
|
+
goal: updated,
|
|
710
|
+
updatedAt: now,
|
|
711
|
+
},
|
|
712
|
+
result: updated,
|
|
713
|
+
}
|
|
714
|
+
})
|
|
715
|
+
}
|
|
716
|
+
|
|
418
717
|
async completeGoal(sessionId: SessionId, tenantId: TenantId, ref: GoalRef): Promise<SessionGoal> {
|
|
419
718
|
return await this.transition(
|
|
420
719
|
sessionId,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { existsSync, statSync } from 'node:fs'
|
|
2
|
-
import { mkdir, readdir, rename, rm, stat } from 'node:fs/promises'
|
|
1
|
+
import { chmodSync, existsSync, lstatSync, statSync } from 'node:fs'
|
|
2
|
+
import { mkdir, open, readdir, rename, rm, stat } from 'node:fs/promises'
|
|
3
3
|
import { createRequire } from 'node:module'
|
|
4
4
|
import { basename, dirname, join } from 'node:path'
|
|
5
5
|
import type { DatabaseSync, SQLInputValue, StatementSync } from 'node:sqlite'
|
|
@@ -43,6 +43,36 @@ import type { ExternalRefClaim, ExternalRefKind, ExternalRefTarget } from './ref
|
|
|
43
43
|
/** `PRAGMA user_version` of an index this module writes. Any other version is rebuilt, never migrated. */
|
|
44
44
|
export const SESSION_INDEX_VERSION = 1
|
|
45
45
|
|
|
46
|
+
/**
|
|
47
|
+
* The index holds every prompt's opening text and the full text of tool
|
|
48
|
+
* results and replies, so it is the owner's alone, like the session logs it is
|
|
49
|
+
* derived from. Its folder, when this module creates it, is too.
|
|
50
|
+
*/
|
|
51
|
+
const INDEX_FILE_MODE = 0o600
|
|
52
|
+
const INDEX_DIRECTORY_MODE = 0o700
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Narrow the index at `path`, and any journal SQLite keeps beside it, to its
|
|
56
|
+
* owner. An index written before this rule kept the umask's mode (0644 on most
|
|
57
|
+
* systems), which let other users of the machine read it. A file this process
|
|
58
|
+
* does not own, a link, or a platform without POSIX modes is left as it is:
|
|
59
|
+
* the change is a tightening, never a reason to fail the open.
|
|
60
|
+
*/
|
|
61
|
+
function restrictIndexFiles(path: string): void {
|
|
62
|
+
if (process.platform === 'win32') return
|
|
63
|
+
const uid = process.getuid?.()
|
|
64
|
+
for (const file of [path, `${path}-journal`, `${path}-wal`, `${path}-shm`]) {
|
|
65
|
+
try {
|
|
66
|
+
const entry = lstatSync(file)
|
|
67
|
+
if (!entry.isFile() || (entry.mode & 0o077) === 0) continue
|
|
68
|
+
if (uid !== undefined && entry.uid !== uid) continue
|
|
69
|
+
chmodSync(file, INDEX_FILE_MODE)
|
|
70
|
+
} catch {
|
|
71
|
+
// Absent, or not ours to change.
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
46
76
|
type SqliteModule = typeof import('node:sqlite')
|
|
47
77
|
|
|
48
78
|
let sqliteModule: SqliteModule | null | undefined
|
|
@@ -677,10 +707,14 @@ export class SqliteSessionIndex extends SessionIndexBase {
|
|
|
677
707
|
/** See {@link rebuildSqliteSessionIndex}. */
|
|
678
708
|
static async rebuild(options: RebuildSqliteSessionIndexOptions): Promise<boolean> {
|
|
679
709
|
const { DatabaseSync } = requireSqlite()
|
|
680
|
-
await mkdir(dirname(options.path), { recursive: true })
|
|
710
|
+
await mkdir(dirname(options.path), { recursive: true, mode: INDEX_DIRECTORY_MODE })
|
|
681
711
|
await sweepAbandonedRebuilds(options.path)
|
|
682
712
|
const temporary = `${options.path}.tmp-${process.pid}-${uuidv7()}`
|
|
683
713
|
try {
|
|
714
|
+
// Every index file starts as this temporary one, so creating it owner-only
|
|
715
|
+
// here is what makes the renamed index owner-only. SQLite opens an empty
|
|
716
|
+
// file as an empty database, and gives its journal the file's mode.
|
|
717
|
+
await (await open(temporary, 'wx', INDEX_FILE_MODE)).close()
|
|
684
718
|
const db = new DatabaseSync(temporary)
|
|
685
719
|
const index = new SqliteSessionIndex(db)
|
|
686
720
|
try {
|
|
@@ -714,6 +748,7 @@ export class SqliteSessionIndex extends SessionIndexBase {
|
|
|
714
748
|
} else {
|
|
715
749
|
await sweepAbandonedRebuilds(options.path)
|
|
716
750
|
}
|
|
751
|
+
restrictIndexFiles(options.path)
|
|
717
752
|
const db = new DatabaseSync(options.path)
|
|
718
753
|
try {
|
|
719
754
|
configure(db)
|
|
@@ -742,6 +777,8 @@ export class SqliteSessionIndex extends SessionIndexBase {
|
|
|
742
777
|
const identity = fileIdentity(path)
|
|
743
778
|
if (identity === undefined || (!force && identity === this.#identity)) return
|
|
744
779
|
const { DatabaseSync } = requireSqlite()
|
|
780
|
+
// A peer on an older version may have renamed its own, wider file in.
|
|
781
|
+
restrictIndexFiles(path)
|
|
745
782
|
const db = new DatabaseSync(path)
|
|
746
783
|
try {
|
|
747
784
|
configure(db)
|
|
@@ -119,7 +119,7 @@ export class DiskLogMedium implements LogMedium {
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
async append(bytes: Uint8Array, expectedOffset: number, sync: boolean): Promise<void> {
|
|
122
|
-
await mkdir(dirname(this.file), { recursive: true })
|
|
122
|
+
await mkdir(dirname(this.file), { recursive: true, mode: 0o700 })
|
|
123
123
|
const handle = await open(this.file, 'a', 0o600)
|
|
124
124
|
try {
|
|
125
125
|
const before = (await handle.stat()).size
|
|
@@ -215,7 +215,8 @@ export class DiskSessionLeaseStore implements SessionLeaseStore {
|
|
|
215
215
|
/** Write `body` and make it visible at `fence`, whole or not at all. Throws `EEXIST` on a lost race. */
|
|
216
216
|
async #publish(fence: number, body: LeaseBody): Promise<void> {
|
|
217
217
|
const temporary = join(this.sessionDir, tempName(fence))
|
|
218
|
-
|
|
218
|
+
// Owner-only, like the log it guards.
|
|
219
|
+
await writeFile(temporary, JSON.stringify(body), { flag: 'wx', mode: 0o600 })
|
|
219
220
|
try {
|
|
220
221
|
await link(temporary, join(this.sessionDir, `lease.${fence}.json`))
|
|
221
222
|
} finally {
|
|
@@ -239,7 +240,7 @@ export class DiskSessionLeaseStore implements SessionLeaseStore {
|
|
|
239
240
|
context: LeaseClaimContext = {},
|
|
240
241
|
): Promise<SessionLease | null> {
|
|
241
242
|
const now = options.now ?? Date.now()
|
|
242
|
-
await mkdir(this.sessionDir, { recursive: true })
|
|
243
|
+
await mkdir(this.sessionDir, { recursive: true, mode: 0o700 })
|
|
243
244
|
for (let attempt = 0; attempt < 8; attempt++) {
|
|
244
245
|
const held = await this.current()
|
|
245
246
|
const decision = decideClaim(held, options, context, now)
|
package/src/tools/admit-facts.ts
CHANGED
|
@@ -119,6 +119,8 @@ export function admitToolFacts(value: unknown): ToolFacts | undefined {
|
|
|
119
119
|
: undefined,
|
|
120
120
|
background: flag(value.background),
|
|
121
121
|
continued: flag(value.continued),
|
|
122
|
+
jobId: text(value.jobId),
|
|
123
|
+
timeLimitMs: count(value.timeLimitMs),
|
|
122
124
|
})
|
|
123
125
|
case 'read': {
|
|
124
126
|
const path = text(value.path)
|