@namzu/sdk 65.3.0 → 67.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 +153 -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/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/public-runtime.d.ts +14 -6
- package/dist/public-runtime.d.ts.map +1 -1
- package/dist/public-runtime.js +22 -5
- 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 +7 -2
- package/dist/public-types.d.ts.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.map +1 -1
- package/dist/runtime/query/iteration/index.js +17 -3
- 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/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/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/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/index.d.ts +1 -0
- package/dist/types/provider/index.d.ts.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/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/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/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/prompt/coding-agent-doctrine.ts +33 -38
- package/src/public-runtime.ts +107 -1
- package/src/public-tools.ts +11 -0
- package/src/public-types.ts +67 -1
- 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 +24 -3
- 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/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/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/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/index.ts +1 -0
- package/src/types/provider/interface.ts +13 -0
- package/src/types/provider/limits.ts +35 -0
- package/src/types/tool/index.ts +30 -2
- package/src/types/tool/presentation.ts +4 -0
- 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
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync } from 'node:fs'
|
|
2
|
+
import {
|
|
3
|
+
chmod,
|
|
4
|
+
lstat,
|
|
5
|
+
readFile,
|
|
6
|
+
readdir,
|
|
7
|
+
readlink,
|
|
8
|
+
rm,
|
|
9
|
+
rmdir,
|
|
10
|
+
stat,
|
|
11
|
+
unlink,
|
|
12
|
+
} from 'node:fs/promises'
|
|
13
|
+
import { isAbsolute, join, resolve } from 'node:path'
|
|
14
|
+
import { isEntityId } from './id.js'
|
|
15
|
+
import { privateTempRootPath } from './temp.js'
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Clearing what sessions left in Namzu's private temporary folder
|
|
19
|
+
* (`<temp base>/namzu-<user>`, see `temp.ts`).
|
|
20
|
+
*
|
|
21
|
+
* Nothing removed a session's scratch folder when the session ended, and the
|
|
22
|
+
* operating system does not always clear its temporary folder: on a machine
|
|
23
|
+
* that is never restarted, or where `/tmp` is a plain folder on the main disk,
|
|
24
|
+
* the folders stay until the disk is full. This sweep removes three kinds of
|
|
25
|
+
* leftovers, and nothing else in the folder:
|
|
26
|
+
*
|
|
27
|
+
* - `<slug>/<session-id>/` folders (the scratch folder and its `jobs/`) in
|
|
28
|
+
* which nothing has changed for {@link TEMP_SWEEP_MAX_AGE_MS}, unless the
|
|
29
|
+
* caller says the session is running. The age is the newest change of
|
|
30
|
+
* anything inside, not the folder's own time: one folder is shared by every
|
|
31
|
+
* home on the machine, so a session of another home that this process
|
|
32
|
+
* cannot ask about is protected by its own recent writes.
|
|
33
|
+
* - `hook-env*` folders whose owner process has exited. A folder made before
|
|
34
|
+
* owners were recorded is removed once nothing in it changed for the same age.
|
|
35
|
+
* - `s-<hex>` short names whose folder is gone.
|
|
36
|
+
*
|
|
37
|
+
* A link is never followed, an entry of another user is never touched, and a
|
|
38
|
+
* folder too large to read in full counts as recent. Errors are counted and
|
|
39
|
+
* left: this is housekeeping, and it never stops a session from starting.
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
/** A scratch folder in which nothing changed for this long belongs to no running session. */
|
|
43
|
+
export const TEMP_SWEEP_MAX_AGE_MS = 7 * 24 * 60 * 60 * 1000
|
|
44
|
+
/** The sweep runs at most this often; the stamp file records when it last did. */
|
|
45
|
+
export const TEMP_SWEEP_EVERY_MS = 24 * 60 * 60 * 1000
|
|
46
|
+
/** The stamp file in the private folder. */
|
|
47
|
+
export const TEMP_SWEEP_STAMP = '.last-cleanup'
|
|
48
|
+
/** The file a hook-env folder's owner writes into it (`session-hook-env.ts`). */
|
|
49
|
+
export const HOOK_ENV_OWNER_FILE = 'owner.json'
|
|
50
|
+
/** The most entries read inside one folder to learn its age; a larger folder counts as recent. */
|
|
51
|
+
const MAX_ENTRIES_PER_FOLDER = 5000
|
|
52
|
+
const ALIAS = /^s-[0-9a-f]{8}$/
|
|
53
|
+
const HOOK_ENV = /^hook-env/
|
|
54
|
+
|
|
55
|
+
export interface TempSweepOptions {
|
|
56
|
+
/** The private folder. Default {@link privateTempRootPath}. */
|
|
57
|
+
readonly root?: string
|
|
58
|
+
/** Default `Date.now()`. */
|
|
59
|
+
readonly now?: number
|
|
60
|
+
/** Default {@link TEMP_SWEEP_MAX_AGE_MS}. */
|
|
61
|
+
readonly maxAgeMs?: number
|
|
62
|
+
/** Default {@link TEMP_SWEEP_EVERY_MS}; 0 runs every time. */
|
|
63
|
+
readonly everyMs?: number
|
|
64
|
+
/** Session ids never to touch: the ones this process runs. */
|
|
65
|
+
readonly keep?: ReadonlySet<string>
|
|
66
|
+
/** Whether a session is running (its writer lease is live). A throw counts as running. */
|
|
67
|
+
readonly isSessionLive?: (slug: string, sessionId: string) => boolean | Promise<boolean>
|
|
68
|
+
/** Default `process.kill(pid, 0)`. */
|
|
69
|
+
readonly isPidAlive?: (pid: number) => boolean
|
|
70
|
+
/** Default `process.getuid`; `undefined` skips the owner check (win32). */
|
|
71
|
+
readonly getuid?: (() => number) | undefined
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface TempSweepReport {
|
|
75
|
+
/** False when the sweep was not due (or the folder does not exist). */
|
|
76
|
+
readonly ran: boolean
|
|
77
|
+
readonly removedSessions: number
|
|
78
|
+
readonly removedHookEnv: number
|
|
79
|
+
readonly removedAliases: number
|
|
80
|
+
/** Folders it could not remove, or could not read in full. */
|
|
81
|
+
readonly failed: number
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const NOT_RUN: TempSweepReport = {
|
|
85
|
+
ran: false,
|
|
86
|
+
removedSessions: 0,
|
|
87
|
+
removedHookEnv: 0,
|
|
88
|
+
removedAliases: 0,
|
|
89
|
+
failed: 0,
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function defaultPidAlive(pid: number): boolean {
|
|
93
|
+
try {
|
|
94
|
+
process.kill(pid, 0)
|
|
95
|
+
return true
|
|
96
|
+
} catch (error) {
|
|
97
|
+
// EPERM: the process exists and belongs to someone else.
|
|
98
|
+
return (error as NodeJS.ErrnoException).code === 'EPERM'
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* The newest change inside `dir` (its own time included), walking real folders
|
|
104
|
+
* only. `undefined` when the folder holds more than the bound: it is then
|
|
105
|
+
* treated as recent, so a folder that cannot be read in full is never removed.
|
|
106
|
+
*/
|
|
107
|
+
async function newestChange(dir: string): Promise<number | undefined> {
|
|
108
|
+
let newest = 0
|
|
109
|
+
let seen = 0
|
|
110
|
+
const pending = [dir]
|
|
111
|
+
while (pending.length > 0) {
|
|
112
|
+
const current = pending.pop() as string
|
|
113
|
+
const entry = await lstat(current)
|
|
114
|
+
newest = Math.max(newest, entry.mtimeMs, entry.ctimeMs)
|
|
115
|
+
if (!entry.isDirectory()) continue
|
|
116
|
+
const names = await readdir(current)
|
|
117
|
+
seen += names.length
|
|
118
|
+
if (seen > MAX_ENTRIES_PER_FOLDER) return undefined
|
|
119
|
+
for (const name of names) pending.push(join(current, name))
|
|
120
|
+
}
|
|
121
|
+
return newest
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function ownedBy(entry: { uid: number }, getuid: (() => number) | undefined): boolean {
|
|
125
|
+
return getuid === undefined || entry.uid === getuid()
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Make a folder writable again before removing it: a test or a tool may leave read-only folders. */
|
|
129
|
+
async function removeTree(path: string): Promise<void> {
|
|
130
|
+
try {
|
|
131
|
+
await rm(path, { recursive: true, force: true })
|
|
132
|
+
} catch (error) {
|
|
133
|
+
const code = (error as NodeJS.ErrnoException).code
|
|
134
|
+
if (code !== 'EACCES' && code !== 'EPERM') throw error
|
|
135
|
+
const pending = [path]
|
|
136
|
+
while (pending.length > 0) {
|
|
137
|
+
const current = pending.pop() as string
|
|
138
|
+
const entry = await lstat(current).catch(() => undefined)
|
|
139
|
+
if (!entry?.isDirectory()) continue
|
|
140
|
+
await chmod(current, 0o700).catch(() => undefined)
|
|
141
|
+
for (const name of await readdir(current).catch(() => [] as string[]))
|
|
142
|
+
pending.push(join(current, name))
|
|
143
|
+
}
|
|
144
|
+
await rm(path, { recursive: true, force: true })
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** Whether the stamp says the sweep ran within `everyMs`; writes a new stamp when it is due. */
|
|
149
|
+
function claimDue(root: string, now: number, everyMs: number): boolean {
|
|
150
|
+
if (everyMs <= 0) return true
|
|
151
|
+
const stamp = join(root, TEMP_SWEEP_STAMP)
|
|
152
|
+
try {
|
|
153
|
+
const last = Date.parse(readFileSync(stamp, 'utf8').trim())
|
|
154
|
+
if (Number.isFinite(last) && last <= now && now - last < everyMs) return false
|
|
155
|
+
} catch {
|
|
156
|
+
// No stamp yet, or one that cannot be read: the sweep is due.
|
|
157
|
+
}
|
|
158
|
+
try {
|
|
159
|
+
writeFileSync(stamp, `${new Date(now).toISOString()}\n`, { mode: 0o600 })
|
|
160
|
+
} catch {
|
|
161
|
+
// A stamp that cannot be written means the next start sweeps again; that is all.
|
|
162
|
+
}
|
|
163
|
+
return true
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** A hook-env folder whose owner reads as dead is removed only once nothing in it changed for this long. */
|
|
167
|
+
const HOOK_ENV_IDLE_MS = 10 * 60 * 1000
|
|
168
|
+
|
|
169
|
+
/** The owner a hook-env folder recorded, if it recorded one. */
|
|
170
|
+
async function hookEnvOwner(dir: string): Promise<number | undefined> {
|
|
171
|
+
try {
|
|
172
|
+
const raw = JSON.parse(await readFile(join(dir, HOOK_ENV_OWNER_FILE), 'utf8')) as {
|
|
173
|
+
pid?: unknown
|
|
174
|
+
}
|
|
175
|
+
return typeof raw.pid === 'number' && Number.isSafeInteger(raw.pid) && raw.pid > 0
|
|
176
|
+
? raw.pid
|
|
177
|
+
: undefined
|
|
178
|
+
} catch {
|
|
179
|
+
return undefined
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Remove old session scratch folders, hook-env folders of exited processes and
|
|
185
|
+
* short names that point nowhere, in Namzu's private temporary folder. See the
|
|
186
|
+
* module header for exactly what is and is not removed.
|
|
187
|
+
*/
|
|
188
|
+
export async function sweepPrivateTempRoot(
|
|
189
|
+
options: TempSweepOptions = {},
|
|
190
|
+
): Promise<TempSweepReport> {
|
|
191
|
+
const root = resolve(options.root ?? privateTempRootPath())
|
|
192
|
+
if (!isAbsolute(root)) return NOT_RUN
|
|
193
|
+
const now = options.now ?? Date.now()
|
|
194
|
+
const maxAgeMs = options.maxAgeMs ?? TEMP_SWEEP_MAX_AGE_MS
|
|
195
|
+
const getuid = 'getuid' in options ? options.getuid : process.getuid?.bind(process)
|
|
196
|
+
const isPidAlive = options.isPidAlive ?? defaultPidAlive
|
|
197
|
+
const keep = options.keep ?? new Set<string>()
|
|
198
|
+
try {
|
|
199
|
+
const top = await lstat(root)
|
|
200
|
+
if (!top.isDirectory() || top.isSymbolicLink() || !ownedBy(top, getuid)) return NOT_RUN
|
|
201
|
+
} catch {
|
|
202
|
+
return NOT_RUN
|
|
203
|
+
}
|
|
204
|
+
if (!claimDue(root, now, options.everyMs ?? TEMP_SWEEP_EVERY_MS)) return NOT_RUN
|
|
205
|
+
|
|
206
|
+
let removedSessions = 0
|
|
207
|
+
let removedHookEnv = 0
|
|
208
|
+
let removedAliases = 0
|
|
209
|
+
let failed = 0
|
|
210
|
+
const old = async (dir: string): Promise<boolean> => {
|
|
211
|
+
try {
|
|
212
|
+
const newest = await newestChange(dir)
|
|
213
|
+
if (newest === undefined) {
|
|
214
|
+
failed += 1
|
|
215
|
+
return false
|
|
216
|
+
}
|
|
217
|
+
return now - newest >= maxAgeMs
|
|
218
|
+
} catch {
|
|
219
|
+
failed += 1
|
|
220
|
+
return false
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
const idleFor = async (dir: string, ms: number): Promise<boolean> => {
|
|
224
|
+
try {
|
|
225
|
+
const newest = await newestChange(dir)
|
|
226
|
+
return newest !== undefined && now - newest >= ms
|
|
227
|
+
} catch {
|
|
228
|
+
return false
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
const running = async (slug: string, sessionId: string): Promise<boolean> => {
|
|
232
|
+
if (keep.has(sessionId)) return true
|
|
233
|
+
if (!options.isSessionLive) return false
|
|
234
|
+
try {
|
|
235
|
+
return await options.isSessionLive(slug, sessionId)
|
|
236
|
+
} catch {
|
|
237
|
+
return true
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
let names: string[]
|
|
242
|
+
try {
|
|
243
|
+
names = await readdir(root)
|
|
244
|
+
} catch {
|
|
245
|
+
return { ...NOT_RUN, ran: true, failed: 1 }
|
|
246
|
+
}
|
|
247
|
+
for (const name of names) {
|
|
248
|
+
if (ALIAS.test(name)) continue // after the folders, so a link to one removed now goes too
|
|
249
|
+
const path = join(root, name)
|
|
250
|
+
let entry: Awaited<ReturnType<typeof lstat>>
|
|
251
|
+
try {
|
|
252
|
+
entry = await lstat(path)
|
|
253
|
+
} catch {
|
|
254
|
+
continue
|
|
255
|
+
}
|
|
256
|
+
if (!entry.isDirectory() || entry.isSymbolicLink() || !ownedBy(entry, getuid)) continue
|
|
257
|
+
if (HOOK_ENV.test(name)) {
|
|
258
|
+
const pid = await hookEnvOwner(path)
|
|
259
|
+
// A pid this process cannot see (another pid namespace sharing the folder) reads as dead, so
|
|
260
|
+
// a dead owner alone is not enough: the folder must also have been idle for a while.
|
|
261
|
+
const gone =
|
|
262
|
+
pid === undefined
|
|
263
|
+
? await old(path)
|
|
264
|
+
: !isPidAlive(pid) && (await idleFor(path, HOOK_ENV_IDLE_MS))
|
|
265
|
+
if (!gone) continue
|
|
266
|
+
try {
|
|
267
|
+
await removeTree(path)
|
|
268
|
+
removedHookEnv += 1
|
|
269
|
+
} catch {
|
|
270
|
+
failed += 1
|
|
271
|
+
}
|
|
272
|
+
continue
|
|
273
|
+
}
|
|
274
|
+
// A project's folder holds one folder per session, named by its id.
|
|
275
|
+
let children: string[]
|
|
276
|
+
try {
|
|
277
|
+
children = await readdir(path)
|
|
278
|
+
} catch {
|
|
279
|
+
continue
|
|
280
|
+
}
|
|
281
|
+
let removedHere = 0
|
|
282
|
+
for (const child of children) {
|
|
283
|
+
if (!isEntityId(child, 'session')) continue
|
|
284
|
+
const sessionDir = join(path, child)
|
|
285
|
+
try {
|
|
286
|
+
const inner = await lstat(sessionDir)
|
|
287
|
+
if (!inner.isDirectory() || inner.isSymbolicLink() || !ownedBy(inner, getuid)) continue
|
|
288
|
+
} catch {
|
|
289
|
+
continue
|
|
290
|
+
}
|
|
291
|
+
if (await running(name, child)) continue
|
|
292
|
+
if (!(await old(sessionDir))) continue
|
|
293
|
+
try {
|
|
294
|
+
await removeTree(sessionDir)
|
|
295
|
+
removedSessions += 1
|
|
296
|
+
removedHere += 1
|
|
297
|
+
} catch {
|
|
298
|
+
failed += 1
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
if (removedHere > 0) {
|
|
302
|
+
// Only an empty folder goes (rmdir refuses one that is not); one that holds anything stays.
|
|
303
|
+
await rmdir(path).catch(() => undefined)
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
for (const name of names) {
|
|
307
|
+
if (!ALIAS.test(name)) continue
|
|
308
|
+
const link = join(root, name)
|
|
309
|
+
try {
|
|
310
|
+
if (!(await lstat(link)).isSymbolicLink()) continue
|
|
311
|
+
const target = await readlink(link)
|
|
312
|
+
try {
|
|
313
|
+
await stat(link)
|
|
314
|
+
continue // the folder it names is still there
|
|
315
|
+
} catch (error) {
|
|
316
|
+
if ((error as NodeJS.ErrnoException).code !== 'ENOENT') continue
|
|
317
|
+
}
|
|
318
|
+
// Re-read before removing: a session may have just pointed the name at a new folder.
|
|
319
|
+
if ((await readlink(link)) !== target) continue
|
|
320
|
+
await unlink(link)
|
|
321
|
+
removedAliases += 1
|
|
322
|
+
} catch {
|
|
323
|
+
// Removed by someone else first, or not ours to read.
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
return { ran: true, removedSessions, removedHookEnv, removedAliases, failed }
|
|
327
|
+
}
|
package/src/utils/temp.ts
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto'
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
existsSync,
|
|
4
|
+
lstatSync,
|
|
5
|
+
mkdirSync,
|
|
6
|
+
mkdtempSync,
|
|
7
|
+
readdirSync,
|
|
8
|
+
readlinkSync,
|
|
9
|
+
renameSync,
|
|
10
|
+
symlinkSync,
|
|
11
|
+
unlinkSync,
|
|
12
|
+
} from 'node:fs'
|
|
3
13
|
import { mkdtemp } from 'node:fs/promises'
|
|
4
14
|
import { tmpdir, userInfo } from 'node:os'
|
|
5
|
-
import { isAbsolute, join, relative, resolve, sep } from 'node:path'
|
|
15
|
+
import { basename, isAbsolute, join, relative, resolve, sep } from 'node:path'
|
|
6
16
|
|
|
7
17
|
/**
|
|
8
18
|
* Namzu's own scratch space: the one place that decides where temporary files
|
|
@@ -248,3 +258,64 @@ export function ensureScratchpadDirectory(
|
|
|
248
258
|
}
|
|
249
259
|
return target
|
|
250
260
|
}
|
|
261
|
+
|
|
262
|
+
/** Scratch links whose folder is gone are removed, so they do not pile up across sessions. */
|
|
263
|
+
function pruneDanglingAliases(root: string, keep: string): void {
|
|
264
|
+
try {
|
|
265
|
+
for (const name of readdirSync(root)) {
|
|
266
|
+
if (!/^s-[0-9a-f]{8}$/.test(name)) continue
|
|
267
|
+
const link = join(root, name)
|
|
268
|
+
if (link === keep) continue
|
|
269
|
+
try {
|
|
270
|
+
if (lstatSync(link).isSymbolicLink() && !existsSync(link)) unlinkSync(link)
|
|
271
|
+
} catch {
|
|
272
|
+
// Another process may have removed it first.
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
} catch {
|
|
276
|
+
// Pruning is housekeeping; the alias itself is already in place.
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/** The environment variable a shell command reads the session's scratch folder from. */
|
|
281
|
+
export const NAMZU_SCRATCH_ENV = 'NAMZU_SCRATCH'
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* A short path for a session's scratch folder: `<private root>/s-<8 hex>`, a
|
|
285
|
+
* symbolic link to the real folder, which keeps its long encoded path. The long
|
|
286
|
+
* path is easy to mistype (a dot for a dash, a dropped segment), and a command
|
|
287
|
+
* that fails on a mistyped path reads as "the write did not happen".
|
|
288
|
+
*
|
|
289
|
+
* The link lies directly under the private root, which only this user may
|
|
290
|
+
* enter, and is made only for a folder {@link ensureScratchpadDirectory} has
|
|
291
|
+
* accepted. When it cannot be made or is not ours to replace, the real folder
|
|
292
|
+
* is returned: the alias is a convenience, never a requirement.
|
|
293
|
+
*/
|
|
294
|
+
export function scratchpadAlias(directory: string, options: PrivateTempRootOptions = {}): string {
|
|
295
|
+
try {
|
|
296
|
+
const root = privateTempRoot(options)
|
|
297
|
+
const target = resolve(directory)
|
|
298
|
+
const alias = join(root, `s-${createHash('sha256').update(target).digest('hex').slice(0, 8)}`)
|
|
299
|
+
try {
|
|
300
|
+
if (readlinkSync(alias) === target) return alias
|
|
301
|
+
} catch (error) {
|
|
302
|
+
const code = (error as NodeJS.ErrnoException).code
|
|
303
|
+
// A path that exists and is not a link (EINVAL) is not ours to replace.
|
|
304
|
+
if (code !== 'ENOENT') return target
|
|
305
|
+
}
|
|
306
|
+
// Link under a private name and rename it into place: the swap is atomic, so
|
|
307
|
+
// two processes racing on one name never leave it missing or half made.
|
|
308
|
+
const staging = join(root, `.${basename(alias)}-${process.pid}`)
|
|
309
|
+
try {
|
|
310
|
+
unlinkSync(staging)
|
|
311
|
+
} catch {
|
|
312
|
+
// Nothing left over from an earlier attempt.
|
|
313
|
+
}
|
|
314
|
+
symlinkSync(target, staging, 'dir')
|
|
315
|
+
renameSync(staging, alias)
|
|
316
|
+
pruneDanglingAliases(root, alias)
|
|
317
|
+
return alias
|
|
318
|
+
} catch {
|
|
319
|
+
return resolve(directory)
|
|
320
|
+
}
|
|
321
|
+
}
|