@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
|
@@ -0,0 +1,504 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Opening a page the agent wrote.
|
|
3
|
+
*
|
|
4
|
+
* The browser tools take web addresses, and a `file:` address is not one the
|
|
5
|
+
* browser is ever handed: a page loaded from `file:` can be steered at other
|
|
6
|
+
* local addresses, and Chromium treats every `file:` document as its own
|
|
7
|
+
* origin, so neither the site rules nor the host's origin check mean anything
|
|
8
|
+
* for it. A page the agent wrote is opened through a door the tool owns
|
|
9
|
+
* instead:
|
|
10
|
+
*
|
|
11
|
+
* - the model names a path (relative, absolute, or a `file:` URL, Windows
|
|
12
|
+
* forms included);
|
|
13
|
+
* - the tool resolves it to a real file inside the session's work folder, a
|
|
14
|
+
* folder added to the session, or Namzu's scratch folder, and refuses
|
|
15
|
+
* everything else with the reason;
|
|
16
|
+
* - a read-only server bound to 127.0.0.1 on a random port serves that one
|
|
17
|
+
* root under a random token, and the browser is given the `http:` address
|
|
18
|
+
* of the file there.
|
|
19
|
+
*
|
|
20
|
+
* Because the page lives on a real `http:` origin, relative CSS, images and
|
|
21
|
+
* scripts load, screenshots and clicks work as on any page, and the host's
|
|
22
|
+
* site rules and origin check apply unchanged. Because the server resolves
|
|
23
|
+
* each request to a real path and serves it only when that path is inside the
|
|
24
|
+
* root, a page cannot read anything else on the disk through it, however it
|
|
25
|
+
* spells the request.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import { randomBytes } from 'node:crypto'
|
|
29
|
+
import { createReadStream } from 'node:fs'
|
|
30
|
+
import { realpath, stat } from 'node:fs/promises'
|
|
31
|
+
import { type Server, createServer } from 'node:http'
|
|
32
|
+
import type { IncomingMessage, ServerResponse } from 'node:http'
|
|
33
|
+
import type { AddressInfo } from 'node:net'
|
|
34
|
+
import { basename, extname, isAbsolute, join, relative, resolve, sep } from 'node:path'
|
|
35
|
+
|
|
36
|
+
import { privateTempRootPath } from '../../utils/temp.js'
|
|
37
|
+
|
|
38
|
+
// ---------------------------------------------------------------------------
|
|
39
|
+
// Reading what the model wrote
|
|
40
|
+
// ---------------------------------------------------------------------------
|
|
41
|
+
|
|
42
|
+
/** A path the model named, before anything on disk has been looked at. */
|
|
43
|
+
export type LocalPageReading =
|
|
44
|
+
| { readonly ok: true; readonly path: string; readonly suffix: string }
|
|
45
|
+
| { readonly ok: false; readonly reason: string }
|
|
46
|
+
|
|
47
|
+
const SCHEME = /^[A-Za-z][A-Za-z0-9+.-]*:/
|
|
48
|
+
const WINDOWS_DRIVE = /^[A-Za-z]:[\\/]/
|
|
49
|
+
|
|
50
|
+
/** `C:\x` and `C:/x`. */
|
|
51
|
+
export function isWindowsDrivePath(path: string): boolean {
|
|
52
|
+
return WINDOWS_DRIVE.test(path)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Is `raw` a local page the model named rather than a web address, and if so
|
|
57
|
+
* which path does it name? `undefined` means it is not local (an `http:` or
|
|
58
|
+
* `https:` address, `about:blank`, any other scheme): the caller treats it as
|
|
59
|
+
* a web address.
|
|
60
|
+
*
|
|
61
|
+
* Local forms: a plain relative or absolute path, a Windows path (`C:\x`,
|
|
62
|
+
* `C:/x`), and a `file:` URL (`file:///home/a/x.html`, `file:///C:/x.html`,
|
|
63
|
+
* `file://localhost/x.html`, `file:C:/x.html`). A `file:` URL's query and
|
|
64
|
+
* fragment come back as `suffix`, so `x.html#top` still opens at `#top`.
|
|
65
|
+
*
|
|
66
|
+
* Pure: reads nothing from the disk and does not depend on the platform.
|
|
67
|
+
*/
|
|
68
|
+
export function readLocalPageReference(raw: string): LocalPageReading | undefined {
|
|
69
|
+
if (typeof raw !== 'string') return undefined
|
|
70
|
+
const text = raw.trim()
|
|
71
|
+
if (text === '' || text.includes('\0')) return undefined
|
|
72
|
+
|
|
73
|
+
if (/^file:/i.test(text)) {
|
|
74
|
+
let url: URL
|
|
75
|
+
try {
|
|
76
|
+
url = new URL(text)
|
|
77
|
+
} catch {
|
|
78
|
+
return { ok: false, reason: 'the file: address could not be read' }
|
|
79
|
+
}
|
|
80
|
+
if (url.hostname !== '' && url.hostname.toLowerCase() !== 'localhost') {
|
|
81
|
+
return {
|
|
82
|
+
ok: false,
|
|
83
|
+
reason: `file://${url.hostname}/... names another machine; only a file in this session's folders can be opened`,
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
let path: string
|
|
87
|
+
try {
|
|
88
|
+
path = decodeURIComponent(url.pathname)
|
|
89
|
+
} catch {
|
|
90
|
+
return { ok: false, reason: 'the file: address has a broken percent-escape' }
|
|
91
|
+
}
|
|
92
|
+
if (path.includes('\0')) return undefined
|
|
93
|
+
// `/C:/x` is how a URL spells `C:\x`.
|
|
94
|
+
if (/^\/[A-Za-z]:(?:[\\/]|$)/.test(path)) path = path.slice(1)
|
|
95
|
+
return { ok: true, path, suffix: `${url.search}${url.hash}` }
|
|
96
|
+
}
|
|
97
|
+
if (isWindowsDrivePath(text)) return { ok: true, path: text, suffix: '' }
|
|
98
|
+
if (/^(?:\\\\|\/\/)/.test(text)) {
|
|
99
|
+
return {
|
|
100
|
+
ok: false,
|
|
101
|
+
reason: 'a network share (\\\\host\\...) is not a folder of this session',
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (SCHEME.test(text)) return undefined
|
|
105
|
+
return { ok: true, path: text, suffix: '' }
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// ---------------------------------------------------------------------------
|
|
109
|
+
// What is never served
|
|
110
|
+
// ---------------------------------------------------------------------------
|
|
111
|
+
|
|
112
|
+
/** Folder names no page is served from, at any depth. */
|
|
113
|
+
const SECRET_FOLDERS = new Set(['.git', '.ssh', '.gnupg', '.aws', '.namzu'])
|
|
114
|
+
|
|
115
|
+
/** File names (lowercased) that hold credentials. */
|
|
116
|
+
const SECRET_FILES = new Set([
|
|
117
|
+
'.npmrc',
|
|
118
|
+
'.netrc',
|
|
119
|
+
'.pypirc',
|
|
120
|
+
'.git-credentials',
|
|
121
|
+
'.htpasswd',
|
|
122
|
+
'credentials.json',
|
|
123
|
+
'secrets.json',
|
|
124
|
+
'service-account.json',
|
|
125
|
+
])
|
|
126
|
+
|
|
127
|
+
const SECRET_NAME_PATTERNS: readonly RegExp[] = [
|
|
128
|
+
/^\.env(?:\..+)?$/i,
|
|
129
|
+
/^id_(?:rsa|dsa|ecdsa|ed25519)(?:\.pub)?$/i,
|
|
130
|
+
/\.(?:pem|key|p12|pfx|jks|keystore|kdbx)$/i,
|
|
131
|
+
]
|
|
132
|
+
|
|
133
|
+
const ENV_TEMPLATES = /^\.env\.(?:example|sample|template|dist)$/i
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* The reason a path is never served, or `undefined`. `segments` are the
|
|
137
|
+
* path's parts below its root.
|
|
138
|
+
*
|
|
139
|
+
* This is the floor. A host that carries read rules (`ToolContext.readDenied`)
|
|
140
|
+
* adds those on top; they are the operator's own list and the tool reuses it
|
|
141
|
+
* rather than keeping a second one.
|
|
142
|
+
*/
|
|
143
|
+
export function secretPathReason(segments: readonly string[]): string | undefined {
|
|
144
|
+
for (const segment of segments) {
|
|
145
|
+
const lower = segment.toLowerCase()
|
|
146
|
+
if (lower === '.git') return 'it is inside a .git folder'
|
|
147
|
+
if (SECRET_FOLDERS.has(lower)) return `it is inside a ${segment} folder, which holds secrets`
|
|
148
|
+
}
|
|
149
|
+
const name = (segments[segments.length - 1] ?? '').toLowerCase()
|
|
150
|
+
if (ENV_TEMPLATES.test(name)) return undefined
|
|
151
|
+
if (SECRET_FILES.has(name) || SECRET_NAME_PATTERNS.some((p) => p.test(name))) {
|
|
152
|
+
return `${segments[segments.length - 1]} looks like a secret file`
|
|
153
|
+
}
|
|
154
|
+
return undefined
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// ---------------------------------------------------------------------------
|
|
158
|
+
// Resolving a path to a file inside an allowed root
|
|
159
|
+
// ---------------------------------------------------------------------------
|
|
160
|
+
|
|
161
|
+
/** What the resolver needs of a tool call. */
|
|
162
|
+
export interface LocalPageContext {
|
|
163
|
+
readonly workingDirectory: string
|
|
164
|
+
readonly additionalDirectories?: readonly string[] | undefined
|
|
165
|
+
readonly readDenied?: ((absolutePath: string) => boolean) | undefined
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** A file inside an allowed root, by real path. */
|
|
169
|
+
export interface LocalPageTarget {
|
|
170
|
+
/** Real path of the root that holds the file. */
|
|
171
|
+
readonly root: string
|
|
172
|
+
/** Segments below the root, of the file's real path. */
|
|
173
|
+
readonly segments: readonly string[]
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export class LocalPageRefusal extends Error {
|
|
177
|
+
override readonly name = 'LocalPageRefusal'
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function isInside(root: string, path: string): boolean {
|
|
181
|
+
const rel = relative(root, path)
|
|
182
|
+
return rel === '' || (!rel.startsWith('..') && !isAbsolute(rel))
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function segmentsBelow(root: string, path: string): string[] {
|
|
186
|
+
const rel = relative(root, path)
|
|
187
|
+
return rel === '' ? [] : rel.split(sep)
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** The folders a local page may come from, in the order they are tried. */
|
|
191
|
+
export function localPageRoots(context: LocalPageContext): string[] {
|
|
192
|
+
const roots = [context.workingDirectory, ...(context.additionalDirectories ?? [])]
|
|
193
|
+
try {
|
|
194
|
+
roots.push(privateTempRootPath())
|
|
195
|
+
} catch {
|
|
196
|
+
// No scratch folder is configured here; the work folder still is.
|
|
197
|
+
}
|
|
198
|
+
return roots
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function describeAllowed(context: LocalPageContext): string {
|
|
202
|
+
const extra = context.additionalDirectories ?? []
|
|
203
|
+
return `Local pages open from this session's work folder (${resolve(context.workingDirectory)})${
|
|
204
|
+
extra.length > 0 ? `, the folders added to it (${extra.map((d) => resolve(d)).join(', ')})` : ''
|
|
205
|
+
} and Namzu's scratch folder.`
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* The real file `reading` names, if it is inside an allowed root and is not
|
|
210
|
+
* one that is never served. Refuses with a {@link LocalPageRefusal} whose
|
|
211
|
+
* message says why and what IS allowed.
|
|
212
|
+
*
|
|
213
|
+
* Each root is resolved to its real path first and the file's real path is
|
|
214
|
+
* compared against those, so a link inside the folder that leads out of it
|
|
215
|
+
* is outside, and a `..` is gone before the comparison.
|
|
216
|
+
*/
|
|
217
|
+
export async function resolveLocalPage(
|
|
218
|
+
reading: { readonly path: string },
|
|
219
|
+
context: LocalPageContext,
|
|
220
|
+
platform: NodeJS.Platform = process.platform,
|
|
221
|
+
): Promise<LocalPageTarget> {
|
|
222
|
+
const allowed = describeAllowed(context)
|
|
223
|
+
if (isWindowsDrivePath(reading.path) && platform !== 'win32') {
|
|
224
|
+
throw new LocalPageRefusal(
|
|
225
|
+
`${reading.path} is a Windows path and this session runs on ${platform}. Give the path the way this machine writes it. ${allowed}`,
|
|
226
|
+
)
|
|
227
|
+
}
|
|
228
|
+
const lexical = resolve(context.workingDirectory, reading.path)
|
|
229
|
+
|
|
230
|
+
let target: string
|
|
231
|
+
try {
|
|
232
|
+
target = await realpath(lexical)
|
|
233
|
+
} catch (error) {
|
|
234
|
+
if ((error as NodeJS.ErrnoException).code === 'ENOENT') {
|
|
235
|
+
throw new LocalPageRefusal(
|
|
236
|
+
`There is no file at ${lexical}. If you meant a website, give its full https:// address; otherwise write the page first. ${allowed}`,
|
|
237
|
+
)
|
|
238
|
+
}
|
|
239
|
+
throw new LocalPageRefusal(`${lexical} could not be read (${errorCode(error)}). ${allowed}`)
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const realRoots: string[] = []
|
|
243
|
+
for (const root of localPageRoots(context)) {
|
|
244
|
+
try {
|
|
245
|
+
realRoots.push(await realpath(root))
|
|
246
|
+
} catch {
|
|
247
|
+
// A root that does not exist holds nothing.
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
const root = realRoots.find((candidate) => isInside(candidate, target))
|
|
251
|
+
if (root === undefined) {
|
|
252
|
+
const linked = realRoots.some((candidate) => isInside(candidate, resolve(lexical)))
|
|
253
|
+
throw new LocalPageRefusal(
|
|
254
|
+
linked
|
|
255
|
+
? `${lexical} is a link that leads outside the allowed folders, to ${target}, so it is not opened. ${allowed}`
|
|
256
|
+
: `${lexical} is outside the folders local pages open from. ${allowed}`,
|
|
257
|
+
)
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
let file = target
|
|
261
|
+
let info = await stat(file)
|
|
262
|
+
if (info.isDirectory()) {
|
|
263
|
+
file = join(file, 'index.html')
|
|
264
|
+
try {
|
|
265
|
+
file = await realpath(file)
|
|
266
|
+
info = await stat(file)
|
|
267
|
+
} catch {
|
|
268
|
+
throw new LocalPageRefusal(
|
|
269
|
+
`${lexical} is a folder with no index.html; folders are never listed. Name the page file. ${allowed}`,
|
|
270
|
+
)
|
|
271
|
+
}
|
|
272
|
+
if (!isInside(root, file)) {
|
|
273
|
+
throw new LocalPageRefusal(`${lexical}/index.html leads outside the allowed folders.`)
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
if (!info.isFile()) throw new LocalPageRefusal(`${lexical} is not a file.`)
|
|
277
|
+
|
|
278
|
+
const segments = segmentsBelow(root, file)
|
|
279
|
+
const secret = secretPathReason(segments)
|
|
280
|
+
// The lexical spelling too: a link named `site.html` that points at `.env`.
|
|
281
|
+
// Taken below the root the spelling sits in, so a root that itself lives
|
|
282
|
+
// under a folder such as .namzu does not refuse every page in it.
|
|
283
|
+
const lexicalRoot = localPageRoots(context)
|
|
284
|
+
.map((candidate) => resolve(candidate))
|
|
285
|
+
.find((candidate) => isInside(candidate, lexical))
|
|
286
|
+
const lexicalSecret =
|
|
287
|
+
lexicalRoot === undefined ? undefined : secretPathReason(segmentsBelow(lexicalRoot, lexical))
|
|
288
|
+
const reason = secret ?? lexicalSecret
|
|
289
|
+
if (reason !== undefined) {
|
|
290
|
+
throw new LocalPageRefusal(`${lexical} is not opened: ${reason}.`)
|
|
291
|
+
}
|
|
292
|
+
if (context.readDenied?.(file) === true || context.readDenied?.(lexical) === true) {
|
|
293
|
+
throw new LocalPageRefusal(`${lexical} is not opened: this session's read rules deny it.`)
|
|
294
|
+
}
|
|
295
|
+
return { root, segments }
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
function errorCode(error: unknown): string {
|
|
299
|
+
return (error as NodeJS.ErrnoException)?.code ?? 'unknown error'
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// ---------------------------------------------------------------------------
|
|
303
|
+
// The door
|
|
304
|
+
// ---------------------------------------------------------------------------
|
|
305
|
+
|
|
306
|
+
const CONTENT_TYPES: Readonly<Record<string, string>> = {
|
|
307
|
+
'.html': 'text/html; charset=utf-8',
|
|
308
|
+
'.htm': 'text/html; charset=utf-8',
|
|
309
|
+
'.css': 'text/css; charset=utf-8',
|
|
310
|
+
'.js': 'text/javascript; charset=utf-8',
|
|
311
|
+
'.mjs': 'text/javascript; charset=utf-8',
|
|
312
|
+
'.json': 'application/json; charset=utf-8',
|
|
313
|
+
'.map': 'application/json; charset=utf-8',
|
|
314
|
+
'.txt': 'text/plain; charset=utf-8',
|
|
315
|
+
'.md': 'text/plain; charset=utf-8',
|
|
316
|
+
'.csv': 'text/csv; charset=utf-8',
|
|
317
|
+
'.xml': 'application/xml; charset=utf-8',
|
|
318
|
+
'.svg': 'image/svg+xml',
|
|
319
|
+
'.png': 'image/png',
|
|
320
|
+
'.jpg': 'image/jpeg',
|
|
321
|
+
'.jpeg': 'image/jpeg',
|
|
322
|
+
'.gif': 'image/gif',
|
|
323
|
+
'.webp': 'image/webp',
|
|
324
|
+
'.avif': 'image/avif',
|
|
325
|
+
'.ico': 'image/x-icon',
|
|
326
|
+
'.woff': 'font/woff',
|
|
327
|
+
'.woff2': 'font/woff2',
|
|
328
|
+
'.ttf': 'font/ttf',
|
|
329
|
+
'.otf': 'font/otf',
|
|
330
|
+
'.wasm': 'application/wasm',
|
|
331
|
+
'.mp3': 'audio/mpeg',
|
|
332
|
+
'.wav': 'audio/wav',
|
|
333
|
+
'.mp4': 'video/mp4',
|
|
334
|
+
'.webm': 'video/webm',
|
|
335
|
+
'.pdf': 'application/pdf',
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
interface RootServer {
|
|
339
|
+
readonly server: Server
|
|
340
|
+
readonly token: string
|
|
341
|
+
readonly origin: string
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Read-only static servers, one per root, owned by one browser tool set.
|
|
346
|
+
*
|
|
347
|
+
* Each is bound to 127.0.0.1 on a random port and answers only under
|
|
348
|
+
* `/<token>/`, with a `Host` that is its own address (a page on another
|
|
349
|
+
* origin cannot reach it by rebinding a name). A request is resolved to a
|
|
350
|
+
* real path and served only when that path is a file inside the real root and
|
|
351
|
+
* passes {@link secretPathReason} and the session's read rules; anything else
|
|
352
|
+
* is a 404 or 403. Nothing lists a directory. The servers do not keep the
|
|
353
|
+
* process alive, and {@link close} stops them.
|
|
354
|
+
*/
|
|
355
|
+
export class LocalPageServers {
|
|
356
|
+
private readonly servers = new Map<string, Promise<RootServer>>()
|
|
357
|
+
private denied: ((absolutePath: string) => boolean) | undefined
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* The `http:` address on which `target` is served, starting the root's
|
|
361
|
+
* server if needed. `denied` is the session's read rules, as of this call.
|
|
362
|
+
*/
|
|
363
|
+
async urlFor(
|
|
364
|
+
target: LocalPageTarget,
|
|
365
|
+
suffix = '',
|
|
366
|
+
denied?: (absolutePath: string) => boolean,
|
|
367
|
+
): Promise<string> {
|
|
368
|
+
this.denied = denied
|
|
369
|
+
let started = this.servers.get(target.root)
|
|
370
|
+
if (!started) {
|
|
371
|
+
started = this.start(target.root)
|
|
372
|
+
this.servers.set(target.root, started)
|
|
373
|
+
started.catch(() => this.servers.delete(target.root))
|
|
374
|
+
}
|
|
375
|
+
const { token, origin } = await started
|
|
376
|
+
const path = target.segments.map((segment) => encodeURIComponent(segment)).join('/')
|
|
377
|
+
return `${origin}/${token}/${path}${suffix}`
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/** Whether a server is up. */
|
|
381
|
+
get running(): boolean {
|
|
382
|
+
return this.servers.size > 0
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/** Stop every server and drop its connections. Safe to call twice. */
|
|
386
|
+
async close(): Promise<void> {
|
|
387
|
+
const all = [...this.servers.values()]
|
|
388
|
+
this.servers.clear()
|
|
389
|
+
await Promise.all(
|
|
390
|
+
all.map(async (started) => {
|
|
391
|
+
try {
|
|
392
|
+
const { server } = await started
|
|
393
|
+
await new Promise<void>((done) => {
|
|
394
|
+
server.close(() => done())
|
|
395
|
+
server.closeAllConnections()
|
|
396
|
+
})
|
|
397
|
+
} catch {
|
|
398
|
+
// It never started.
|
|
399
|
+
}
|
|
400
|
+
}),
|
|
401
|
+
)
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
private async start(root: string): Promise<RootServer> {
|
|
405
|
+
const token = randomBytes(24).toString('base64url')
|
|
406
|
+
const server = createServer((req, res) => {
|
|
407
|
+
this.handle(root, token, server, req, res).catch(() => {
|
|
408
|
+
if (!res.headersSent) respond(res, 500)
|
|
409
|
+
else res.destroy()
|
|
410
|
+
})
|
|
411
|
+
})
|
|
412
|
+
await new Promise<void>((ok, fail) => {
|
|
413
|
+
server.once('error', fail)
|
|
414
|
+
server.listen(0, '127.0.0.1', () => {
|
|
415
|
+
server.off('error', fail)
|
|
416
|
+
ok()
|
|
417
|
+
})
|
|
418
|
+
})
|
|
419
|
+
// A page the model forgot about must not keep the process alive.
|
|
420
|
+
server.unref()
|
|
421
|
+
const { port } = server.address() as AddressInfo
|
|
422
|
+
return { server, token, origin: `http://127.0.0.1:${port}` }
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
private async handle(
|
|
426
|
+
root: string,
|
|
427
|
+
token: string,
|
|
428
|
+
server: Server,
|
|
429
|
+
req: IncomingMessage,
|
|
430
|
+
res: ServerResponse,
|
|
431
|
+
): Promise<void> {
|
|
432
|
+
const { port } = server.address() as AddressInfo
|
|
433
|
+
if (req.headers.host !== `127.0.0.1:${port}`) return respond(res, 403)
|
|
434
|
+
if (req.method !== 'GET' && req.method !== 'HEAD') return respond(res, 405)
|
|
435
|
+
|
|
436
|
+
let pathname: string
|
|
437
|
+
try {
|
|
438
|
+
pathname = new URL(req.url ?? '/', 'http://127.0.0.1').pathname
|
|
439
|
+
} catch {
|
|
440
|
+
return respond(res, 400)
|
|
441
|
+
}
|
|
442
|
+
const prefix = `/${token}/`
|
|
443
|
+
if (!pathname.startsWith(prefix)) return respond(res, 404)
|
|
444
|
+
const parts = pathname.slice(prefix.length).split('/')
|
|
445
|
+
const segments: string[] = []
|
|
446
|
+
try {
|
|
447
|
+
for (const part of parts) segments.push(decodeURIComponent(part))
|
|
448
|
+
} catch {
|
|
449
|
+
return respond(res, 400)
|
|
450
|
+
}
|
|
451
|
+
if (segments[segments.length - 1] === '') segments.pop()
|
|
452
|
+
for (const segment of segments) {
|
|
453
|
+
if (
|
|
454
|
+
segment === '' ||
|
|
455
|
+
segment === '.' ||
|
|
456
|
+
segment === '..' ||
|
|
457
|
+
segment.includes('\0') ||
|
|
458
|
+
segment.includes('/') ||
|
|
459
|
+
segment.includes('\\') ||
|
|
460
|
+
/^[A-Za-z]:/.test(segment)
|
|
461
|
+
)
|
|
462
|
+
return respond(res, 400)
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
let file = join(root, ...segments)
|
|
466
|
+
try {
|
|
467
|
+
file = await realpath(file)
|
|
468
|
+
if (!isInside(root, file)) return respond(res, 403)
|
|
469
|
+
let info = await stat(file)
|
|
470
|
+
if (info.isDirectory()) {
|
|
471
|
+
file = await realpath(join(file, 'index.html'))
|
|
472
|
+
if (!isInside(root, file)) return respond(res, 403)
|
|
473
|
+
info = await stat(file)
|
|
474
|
+
}
|
|
475
|
+
if (!info.isFile()) return respond(res, 404)
|
|
476
|
+
const real = segmentsBelow(root, file)
|
|
477
|
+
if (secretPathReason(real) !== undefined || secretPathReason(segments) !== undefined)
|
|
478
|
+
return respond(res, 403)
|
|
479
|
+
if (this.denied?.(file) === true) return respond(res, 403)
|
|
480
|
+
res.writeHead(200, {
|
|
481
|
+
'Content-Type':
|
|
482
|
+
CONTENT_TYPES[extname(basename(file)).toLowerCase()] ?? 'application/octet-stream',
|
|
483
|
+
'Content-Length': info.size,
|
|
484
|
+
'Cache-Control': 'no-store',
|
|
485
|
+
'X-Content-Type-Options': 'nosniff',
|
|
486
|
+
'Cross-Origin-Resource-Policy': 'same-origin',
|
|
487
|
+
})
|
|
488
|
+
if (req.method === 'HEAD') return void res.end()
|
|
489
|
+
createReadStream(file)
|
|
490
|
+
.on('error', () => res.destroy())
|
|
491
|
+
.pipe(res)
|
|
492
|
+
} catch {
|
|
493
|
+
respond(res, 404)
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
function respond(res: ServerResponse, status: number): void {
|
|
499
|
+
res.writeHead(status, {
|
|
500
|
+
'Content-Type': 'text/plain; charset=utf-8',
|
|
501
|
+
'Cache-Control': 'no-store',
|
|
502
|
+
})
|
|
503
|
+
res.end(status === 403 ? 'Not served.' : status === 404 ? 'Not found.' : 'Refused.')
|
|
504
|
+
}
|