@draht/coding-agent 2026.7.13 → 2026.9.5-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +241 -0
- package/README.md +47 -2
- package/agents/debugger.md +12 -1
- package/agents/git-committer.md +1 -0
- package/agents/implementer.md +20 -0
- package/agents/investigator.md +75 -0
- package/agents/reviewer.md +7 -0
- package/agents/spec-reviewer.md +66 -0
- package/agents/verifier.md +4 -3
- package/bin/draht-tools.cjs +472 -41
- package/dist/agents/debugger.md +12 -1
- package/dist/agents/git-committer.md +1 -0
- package/dist/agents/implementer.md +20 -0
- package/dist/agents/investigator.md +75 -0
- package/dist/agents/reviewer.md +7 -0
- package/dist/agents/spec-reviewer.md +66 -0
- package/dist/agents/verifier.md +4 -3
- package/dist/bun/cli.js +2 -0
- package/dist/bun/cli.js.map +1 -1
- package/dist/cli/args.d.ts +10 -0
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +80 -3
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/attach-mode.d.ts +61 -0
- package/dist/cli/attach-mode.d.ts.map +1 -1
- package/dist/cli/attach-mode.js +243 -5
- package/dist/cli/attach-mode.js.map +1 -1
- package/dist/cli/config-selector.js +1 -1
- package/dist/cli/config-selector.js.map +1 -1
- package/dist/cli/credential-print.d.ts +23 -0
- package/dist/cli/credential-print.d.ts.map +1 -0
- package/dist/cli/credential-print.js +117 -0
- package/dist/cli/credential-print.js.map +1 -0
- package/dist/cli/list-models.d.ts +2 -2
- package/dist/cli/list-models.d.ts.map +1 -1
- package/dist/cli/list-models.js +3 -3
- package/dist/cli/list-models.js.map +1 -1
- package/dist/cli/startup-ui.js +1 -1
- package/dist/cli/startup-ui.js.map +1 -1
- package/dist/config.d.ts +9 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +31 -4
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts +17 -1
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +90 -30
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session-services.d.ts +4 -7
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js +24 -9
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session.d.ts +87 -27
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +337 -154
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-storage.d.ts +20 -104
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +104 -260
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/builtins/checkpoints.d.ts +20 -0
- package/dist/core/builtins/checkpoints.d.ts.map +1 -0
- package/dist/core/builtins/checkpoints.js +161 -0
- package/dist/core/builtins/checkpoints.js.map +1 -0
- package/dist/core/builtins/duet.d.ts +26 -0
- package/dist/core/builtins/duet.d.ts.map +1 -0
- package/dist/core/builtins/duet.js +660 -0
- package/dist/core/builtins/duet.js.map +1 -0
- package/dist/core/builtins/index.d.ts.map +1 -1
- package/dist/core/builtins/index.js +7 -1
- package/dist/core/builtins/index.js.map +1 -1
- package/dist/core/builtins/subagent.d.ts +24 -4
- package/dist/core/builtins/subagent.d.ts.map +1 -1
- package/dist/core/builtins/subagent.js +278 -35
- package/dist/core/builtins/subagent.js.map +1 -1
- package/dist/core/cache-stats.d.ts +2 -2
- package/dist/core/cache-stats.d.ts.map +1 -1
- package/dist/core/cache-stats.js +1 -1
- package/dist/core/cache-stats.js.map +1 -1
- package/dist/core/checkpoints/checkpoint-cli.d.ts +17 -0
- package/dist/core/checkpoints/checkpoint-cli.d.ts.map +1 -0
- package/dist/core/checkpoints/checkpoint-cli.js +78 -0
- package/dist/core/checkpoints/checkpoint-cli.js.map +1 -0
- package/dist/core/checkpoints/checkpoint-manager.d.ts +294 -0
- package/dist/core/checkpoints/checkpoint-manager.d.ts.map +1 -0
- package/dist/core/checkpoints/checkpoint-manager.js +865 -0
- package/dist/core/checkpoints/checkpoint-manager.js.map +1 -0
- package/dist/core/checkpoints/rewind.d.ts +141 -0
- package/dist/core/checkpoints/rewind.d.ts.map +1 -0
- package/dist/core/checkpoints/rewind.js +246 -0
- package/dist/core/checkpoints/rewind.js.map +1 -0
- package/dist/core/compaction/branch-summarization.d.ts +9 -3
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/core/compaction/branch-summarization.js +16 -14
- package/dist/core/compaction/branch-summarization.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts +24 -3
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +96 -30
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/compaction/utils.d.ts +1 -1
- package/dist/core/compaction/utils.d.ts.map +1 -1
- package/dist/core/compaction/utils.js +6 -17
- package/dist/core/compaction/utils.js.map +1 -1
- package/dist/core/context-windows.d.ts +7 -0
- package/dist/core/context-windows.d.ts.map +1 -0
- package/dist/core/context-windows.js +35 -0
- package/dist/core/context-windows.js.map +1 -0
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +101 -23
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +19 -3
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +117 -2
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +236 -9
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/extensions/wrapper.d.ts.map +1 -1
- package/dist/core/extensions/wrapper.js +22 -3
- package/dist/core/extensions/wrapper.js.map +1 -1
- package/dist/core/footer-data-provider.d.ts +10 -0
- package/dist/core/footer-data-provider.d.ts.map +1 -1
- package/dist/core/footer-data-provider.js +1 -1
- package/dist/core/footer-data-provider.js.map +1 -1
- package/dist/core/http-dispatcher.d.ts.map +1 -1
- package/dist/core/http-dispatcher.js +7 -0
- package/dist/core/http-dispatcher.js.map +1 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/keybindings.d.ts +18 -3
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +12 -3
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/model-config.d.ts +542 -0
- package/dist/core/model-config.d.ts.map +1 -0
- package/dist/core/model-config.js +247 -0
- package/dist/core/model-config.js.map +1 -0
- package/dist/core/model-registry.d.ts +19 -124
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +56 -727
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts +7 -6
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +74 -27
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/model-runtime.d.ts +89 -0
- package/dist/core/model-runtime.d.ts.map +1 -0
- package/dist/core/model-runtime.js +451 -0
- package/dist/core/model-runtime.js.map +1 -0
- package/dist/core/models-store.d.ts +17 -0
- package/dist/core/models-store.d.ts.map +1 -0
- package/dist/core/models-store.js +46 -0
- package/dist/core/models-store.js.map +1 -0
- package/dist/core/multi-agent/permission-gate.d.ts.map +1 -1
- package/dist/core/multi-agent/permission-gate.js +4 -3
- package/dist/core/multi-agent/permission-gate.js.map +1 -1
- package/dist/core/multi-agent/worktree.d.ts +2 -0
- package/dist/core/multi-agent/worktree.d.ts.map +1 -1
- package/dist/core/multi-agent/worktree.js +2 -2
- package/dist/core/multi-agent/worktree.js.map +1 -1
- package/dist/core/package-manager.d.ts +7 -1
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +41 -45
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/permission-relay/index.d.ts +19 -0
- package/dist/core/permission-relay/index.d.ts.map +1 -0
- package/dist/core/permission-relay/index.js +49 -0
- package/dist/core/permission-relay/index.js.map +1 -0
- package/dist/core/permission-relay/relay-ui-context.d.ts +39 -0
- package/dist/core/permission-relay/relay-ui-context.d.ts.map +1 -0
- package/dist/core/permission-relay/relay-ui-context.js +788 -0
- package/dist/core/permission-relay/relay-ui-context.js.map +1 -0
- package/dist/core/permission-relay/types.d.ts +222 -0
- package/dist/core/permission-relay/types.d.ts.map +1 -0
- package/dist/core/permission-relay/types.js +15 -0
- package/dist/core/permission-relay/types.js.map +1 -0
- package/dist/core/pi-manifest.d.ts +14 -0
- package/dist/core/pi-manifest.d.ts.map +1 -0
- package/dist/core/pi-manifest.js +35 -0
- package/dist/core/pi-manifest.js.map +1 -0
- package/dist/core/project-trust.js +2 -2
- package/dist/core/project-trust.js.map +1 -1
- package/dist/core/prompt-templates.d.ts +1 -0
- package/dist/core/prompt-templates.d.ts.map +1 -1
- package/dist/core/prompt-templates.js +4 -4
- package/dist/core/prompt-templates.js.map +1 -1
- package/dist/core/provider-composer.d.ts +55 -0
- package/dist/core/provider-composer.d.ts.map +1 -0
- package/dist/core/provider-composer.js +375 -0
- package/dist/core/provider-composer.js.map +1 -0
- package/dist/core/radius.d.ts +2 -0
- package/dist/core/radius.d.ts.map +1 -0
- package/dist/core/radius.js +2 -0
- package/dist/core/radius.js.map +1 -0
- package/dist/core/remote-catalog-provider.d.ts +5 -0
- package/dist/core/remote-catalog-provider.d.ts.map +1 -0
- package/dist/core/remote-catalog-provider.js +115 -0
- package/dist/core/remote-catalog-provider.js.map +1 -0
- package/dist/core/resource-loader.d.ts +36 -0
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +159 -27
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/runtime-credentials.d.ts +15 -0
- package/dist/core/runtime-credentials.d.ts.map +1 -0
- package/dist/core/runtime-credentials.js +35 -0
- package/dist/core/runtime-credentials.js.map +1 -0
- package/dist/core/sandbox/bash-operations.d.ts +149 -0
- package/dist/core/sandbox/bash-operations.d.ts.map +1 -0
- package/dist/core/sandbox/bash-operations.js +163 -0
- package/dist/core/sandbox/bash-operations.js.map +1 -0
- package/dist/core/sandbox/env.d.ts +83 -0
- package/dist/core/sandbox/env.d.ts.map +1 -0
- package/dist/core/sandbox/env.js +123 -0
- package/dist/core/sandbox/env.js.map +1 -0
- package/dist/core/sandbox/executor.d.ts +104 -0
- package/dist/core/sandbox/executor.d.ts.map +1 -0
- package/dist/core/sandbox/executor.js +92 -0
- package/dist/core/sandbox/executor.js.map +1 -0
- package/dist/core/sandbox/index.d.ts +36 -0
- package/dist/core/sandbox/index.d.ts.map +1 -0
- package/dist/core/sandbox/index.js +36 -0
- package/dist/core/sandbox/index.js.map +1 -0
- package/dist/core/sandbox/linux.d.ts +121 -0
- package/dist/core/sandbox/linux.d.ts.map +1 -0
- package/dist/core/sandbox/linux.js +260 -0
- package/dist/core/sandbox/linux.js.map +1 -0
- package/dist/core/sandbox/policy.d.ts +142 -0
- package/dist/core/sandbox/policy.d.ts.map +1 -0
- package/dist/core/sandbox/policy.js +297 -0
- package/dist/core/sandbox/policy.js.map +1 -0
- package/dist/core/sandbox/real-path.d.ts +112 -0
- package/dist/core/sandbox/real-path.d.ts.map +1 -0
- package/dist/core/sandbox/real-path.js +158 -0
- package/dist/core/sandbox/real-path.js.map +1 -0
- package/dist/core/sandbox/seatbelt-profile.d.ts +95 -0
- package/dist/core/sandbox/seatbelt-profile.d.ts.map +1 -0
- package/dist/core/sandbox/seatbelt-profile.js +239 -0
- package/dist/core/sandbox/seatbelt-profile.js.map +1 -0
- package/dist/core/sandbox/seatbelt.d.ts +95 -0
- package/dist/core/sandbox/seatbelt.d.ts.map +1 -0
- package/dist/core/sandbox/seatbelt.js +154 -0
- package/dist/core/sandbox/seatbelt.js.map +1 -0
- package/dist/core/sandbox/self-test.d.ts +109 -0
- package/dist/core/sandbox/self-test.d.ts.map +1 -0
- package/dist/core/sandbox/self-test.js +369 -0
- package/dist/core/sandbox/self-test.js.map +1 -0
- package/dist/core/sandbox/spawn.d.ts +33 -0
- package/dist/core/sandbox/spawn.d.ts.map +1 -0
- package/dist/core/sandbox/spawn.js +87 -0
- package/dist/core/sandbox/spawn.js.map +1 -0
- package/dist/core/sdk.d.ts +3 -6
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +25 -22
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-manager.d.ts +74 -7
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +169 -34
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-manager.d.ts +22 -1
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +36 -16
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/skills.d.ts +3 -1
- package/dist/core/skills.d.ts.map +1 -1
- package/dist/core/skills.js +19 -6
- package/dist/core/skills.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +1 -0
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/soak/soak-log.d.ts +298 -0
- package/dist/core/soak/soak-log.d.ts.map +1 -0
- package/dist/core/soak/soak-log.js +660 -0
- package/dist/core/soak/soak-log.js.map +1 -0
- package/dist/core/soak/soak-reader.d.ts +60 -0
- package/dist/core/soak/soak-reader.d.ts.map +1 -0
- package/dist/core/soak/soak-reader.js +106 -0
- package/dist/core/soak/soak-reader.js.map +1 -0
- package/dist/core/socket-server/discovery.d.ts +78 -1
- package/dist/core/socket-server/discovery.d.ts.map +1 -1
- package/dist/core/socket-server/discovery.js +356 -37
- package/dist/core/socket-server/discovery.js.map +1 -1
- package/dist/core/socket-server/index.d.ts +10 -4
- package/dist/core/socket-server/index.d.ts.map +1 -1
- package/dist/core/socket-server/index.js +6 -3
- package/dist/core/socket-server/index.js.map +1 -1
- package/dist/core/socket-server/permission-delivery.d.ts +125 -0
- package/dist/core/socket-server/permission-delivery.d.ts.map +1 -0
- package/dist/core/socket-server/permission-delivery.js +152 -0
- package/dist/core/socket-server/permission-delivery.js.map +1 -0
- package/dist/core/socket-server/permission-registry.d.ts +301 -0
- package/dist/core/socket-server/permission-registry.d.ts.map +1 -0
- package/dist/core/socket-server/permission-registry.js +410 -0
- package/dist/core/socket-server/permission-registry.js.map +1 -0
- package/dist/core/socket-server/permission-relay.d.ts +81 -0
- package/dist/core/socket-server/permission-relay.d.ts.map +1 -0
- package/dist/core/socket-server/permission-relay.js +528 -0
- package/dist/core/socket-server/permission-relay.js.map +1 -0
- package/dist/core/socket-server/safe-text.d.ts +83 -0
- package/dist/core/socket-server/safe-text.d.ts.map +1 -0
- package/dist/core/socket-server/safe-text.js +277 -0
- package/dist/core/socket-server/safe-text.js.map +1 -0
- package/dist/core/socket-server/session-integration.d.ts +65 -2
- package/dist/core/socket-server/session-integration.d.ts.map +1 -1
- package/dist/core/socket-server/session-integration.js +434 -32
- package/dist/core/socket-server/session-integration.js.map +1 -1
- package/dist/core/socket-server/socket-client.d.ts +21 -2
- package/dist/core/socket-server/socket-client.d.ts.map +1 -1
- package/dist/core/socket-server/socket-client.js +52 -1
- package/dist/core/socket-server/socket-client.js.map +1 -1
- package/dist/core/socket-server/socket-server.d.ts +152 -1
- package/dist/core/socket-server/socket-server.d.ts.map +1 -1
- package/dist/core/socket-server/socket-server.js +775 -26
- package/dist/core/socket-server/socket-server.js.map +1 -1
- package/dist/core/socket-server/types.d.ts +106 -2
- package/dist/core/socket-server/types.d.ts.map +1 -1
- package/dist/core/socket-server/types.js +13 -1
- package/dist/core/socket-server/types.js.map +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +10 -21
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tools/bash.d.ts +3 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +39 -7
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +17 -2
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/find.d.ts +3 -0
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +11 -18
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/read.js +1 -1
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
- package/dist/core/tools/tool-definition-wrapper.js +3 -1
- package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
- package/dist/core/trust-manager.d.ts +6 -4
- package/dist/core/trust-manager.d.ts.map +1 -1
- package/dist/core/trust-manager.js +55 -21
- package/dist/core/trust-manager.js.map +1 -1
- package/dist/core/usage-totals.d.ts +19 -0
- package/dist/core/usage-totals.d.ts.map +1 -0
- package/dist/core/usage-totals.js +52 -0
- package/dist/core/usage-totals.js.map +1 -0
- package/dist/extensions/index.d.ts +3 -0
- package/dist/extensions/index.d.ts.map +1 -0
- package/dist/extensions/index.js +7 -0
- package/dist/extensions/index.js.map +1 -0
- package/dist/extensions/llama/client.d.ts +61 -0
- package/dist/extensions/llama/client.d.ts.map +1 -0
- package/dist/extensions/llama/client.js +300 -0
- package/dist/extensions/llama/client.js.map +1 -0
- package/dist/extensions/llama/huggingface.d.ts +23 -0
- package/dist/extensions/llama/huggingface.d.ts.map +1 -0
- package/dist/extensions/llama/huggingface.js +139 -0
- package/dist/extensions/llama/huggingface.js.map +1 -0
- package/dist/extensions/llama/index.d.ts +3 -0
- package/dist/extensions/llama/index.d.ts.map +1 -0
- package/dist/extensions/llama/index.js +208 -0
- package/dist/extensions/llama/index.js.map +1 -0
- package/dist/extensions/llama/provider.d.ts +10 -0
- package/dist/extensions/llama/provider.d.ts.map +1 -0
- package/dist/extensions/llama/provider.js +111 -0
- package/dist/extensions/llama/provider.js.map +1 -0
- package/dist/extensions/llama/ui.d.ts +42 -0
- package/dist/extensions/llama/ui.d.ts.map +1 -0
- package/dist/extensions/llama/ui.js +400 -0
- package/dist/extensions/llama/ui.js.map +1 -0
- package/dist/extensions/stub-provider/index.d.ts +9 -0
- package/dist/extensions/stub-provider/index.d.ts.map +1 -0
- package/dist/extensions/stub-provider/index.js +13 -0
- package/dist/extensions/stub-provider/index.js.map +1 -0
- package/dist/extensions/stub-provider/provider.d.ts +77 -0
- package/dist/extensions/stub-provider/provider.d.ts.map +1 -0
- package/dist/extensions/stub-provider/provider.js +193 -0
- package/dist/extensions/stub-provider/provider.js.map +1 -0
- package/dist/hooks/gsd/draht-quality-gate.js +3 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +305 -61
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +22 -10
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/config-selector.js +3 -2
- package/dist/modes/interactive/components/config-selector.js.map +1 -1
- package/dist/modes/interactive/components/custom-editor.js +1 -1
- package/dist/modes/interactive/components/custom-editor.js.map +1 -1
- package/dist/modes/interactive/components/custom-message.d.ts +3 -1
- package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-message.js +9 -2
- package/dist/modes/interactive/components/custom-message.js.map +1 -1
- package/dist/modes/interactive/components/extension-editor.d.ts +1 -2
- package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-editor.js +16 -46
- package/dist/modes/interactive/components/extension-editor.js.map +1 -1
- package/dist/modes/interactive/components/extension-selector.d.ts +49 -0
- package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-selector.js +202 -5
- package/dist/modes/interactive/components/extension-selector.js.map +1 -1
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +24 -23
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/login-dialog.d.ts +5 -5
- package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
- package/dist/modes/interactive/components/login-dialog.js +17 -8
- package/dist/modes/interactive/components/login-dialog.js.map +1 -1
- package/dist/modes/interactive/components/model-selector.d.ts +11 -4
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +74 -41
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.d.ts +4 -4
- package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.js +14 -25
- package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.js +22 -13
- package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector.js +10 -2
- package/dist/modes/interactive/components/session-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts +2 -0
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +10 -0
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +10 -1
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/tree-selector.d.ts +25 -2
- package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector.js +68 -17
- package/dist/modes/interactive/components/tree-selector.js.map +1 -1
- package/dist/modes/interactive/external-editor.d.ts +12 -0
- package/dist/modes/interactive/external-editor.d.ts.map +1 -0
- package/dist/modes/interactive/external-editor.js +37 -0
- package/dist/modes/interactive/external-editor.js.map +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts +107 -10
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +763 -285
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts +4 -0
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +7 -0
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +185 -9
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +79 -1
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/package-manager-cli.d.ts.map +1 -1
- package/dist/package-manager-cli.js +67 -5
- package/dist/package-manager-cli.js.map +1 -1
- package/dist/prompts/commands/atomic-commit.md +1 -12
- package/dist/prompts/commands/brainstorm.md +12 -15
- package/dist/prompts/commands/create-verification-skill.md +108 -0
- package/dist/prompts/commands/discuss-phase.md +3 -14
- package/dist/prompts/commands/execute-phase.md +3 -11
- package/dist/prompts/commands/fix.md +41 -18
- package/dist/prompts/commands/grill.md +66 -0
- package/dist/prompts/commands/init-project.md +5 -15
- package/dist/prompts/commands/map-codebase.md +1 -13
- package/dist/prompts/commands/new-project.md +5 -15
- package/dist/prompts/commands/next-milestone.md +1 -13
- package/dist/prompts/commands/orchestrate.md +1 -1
- package/dist/prompts/commands/pause-work.md +1 -13
- package/dist/prompts/commands/plan-phase.md +2 -11
- package/dist/prompts/commands/progress.md +0 -13
- package/dist/prompts/commands/quick.md +3 -11
- package/dist/prompts/commands/resolve-conflicts.md +71 -0
- package/dist/prompts/commands/resume-work.md +0 -13
- package/dist/prompts/commands/review.md +4 -13
- package/dist/prompts/commands/triage.md +159 -0
- package/dist/prompts/commands/verify-work.md +4 -14
- package/dist/prompts/commands/why.md +135 -0
- package/dist/skills/atomic-reasoning/SKILL.md +115 -0
- package/dist/skills/blast-radius/SKILL.md +55 -0
- package/dist/skills/epistemics/SKILL.md +99 -0
- package/dist/skills/hexagon-animation/SKILL.md +49 -0
- package/dist/skills/hexagon-animation/generate.mjs +81 -0
- package/dist/skills/hexagon-animation/template.html +361 -0
- package/dist/skills/typescript-discipline/SKILL.md +50 -0
- package/dist/skills/typescript-discipline/references/patterns.md +294 -0
- package/dist/skills/unslop/SKILL.md +101 -0
- package/dist/utils/canonical-path.d.ts +28 -0
- package/dist/utils/canonical-path.d.ts.map +1 -0
- package/dist/utils/canonical-path.js +90 -0
- package/dist/utils/canonical-path.js.map +1 -0
- package/dist/utils/child-process.d.ts +12 -1
- package/dist/utils/child-process.d.ts.map +1 -1
- package/dist/utils/child-process.js +25 -8
- package/dist/utils/child-process.js.map +1 -1
- package/dist/utils/clipboard-native.d.ts +1 -0
- package/dist/utils/clipboard-native.d.ts.map +1 -1
- package/dist/utils/clipboard-native.js.map +1 -1
- package/dist/utils/clipboard.d.ts +2 -0
- package/dist/utils/clipboard.d.ts.map +1 -1
- package/dist/utils/clipboard.js +53 -9
- package/dist/utils/clipboard.js.map +1 -1
- package/dist/utils/exif-orientation.d.ts.map +1 -1
- package/dist/utils/exif-orientation.js +2 -3
- package/dist/utils/exif-orientation.js.map +1 -1
- package/dist/utils/paths.d.ts +2 -7
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/paths.js +13 -15
- package/dist/utils/paths.js.map +1 -1
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +6 -4
- package/dist/utils/shell.js.map +1 -1
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js +3 -5
- package/dist/utils/tools-manager.js.map +1 -1
- package/dist/utils/version-check.d.ts.map +1 -1
- package/dist/utils/version-check.js +3 -1
- package/dist/utils/version-check.js.map +1 -1
- package/docs/attachable-sessions.md +79 -0
- package/docs/compaction.md +29 -24
- package/docs/containerization.md +23 -23
- package/docs/custom-provider.md +66 -32
- package/docs/development.md +9 -9
- package/docs/docs.json +6 -2
- package/docs/duet.md +42 -0
- package/docs/environment-variables.md +88 -0
- package/docs/extensions.md +278 -65
- package/docs/index.md +12 -10
- package/docs/json.md +12 -8
- package/docs/keybindings.md +8 -5
- package/docs/llama-cpp.md +99 -0
- package/docs/models.md +19 -8
- package/docs/packages.md +43 -42
- package/docs/prompt-templates.md +5 -4
- package/docs/providers.md +45 -11
- package/docs/quickstart.md +33 -33
- package/docs/rpc.md +190 -19
- package/docs/sdk.md +18 -15
- package/docs/security.md +18 -18
- package/docs/session-format.md +53 -15
- package/docs/sessions.md +17 -14
- package/docs/settings.md +26 -19
- package/docs/shell-aliases.md +2 -2
- package/docs/skills.md +12 -11
- package/docs/terminal-setup.md +12 -12
- package/docs/termux.md +6 -6
- package/docs/themes.md +11 -11
- package/docs/tmux.md +4 -4
- package/docs/tui.md +46 -31
- package/docs/usage.md +53 -63
- package/docs/windows.md +2 -2
- package/examples/extensions/custom-compaction.ts +4 -0
- package/examples/extensions/custom-provider-anthropic/index.ts +9 -3
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/custom-provider-qwen-cli/package.json +1 -1
- package/examples/extensions/gondolin/package.json +2 -2
- package/examples/extensions/handoff.ts +9 -1
- package/examples/extensions/kimi-deferred-tools.ts +61 -0
- package/examples/extensions/message-renderer.ts +2 -2
- package/examples/extensions/overlay-qa-tests.ts +3 -3
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/summarize.ts +3 -0
- package/examples/extensions/with-deps/package.json +1 -1
- package/examples/sdk/02-custom-model.ts +5 -8
- package/examples/sdk/09-api-keys-and-oauth.ts +15 -31
- package/examples/sdk/12-full-control.ts +9 -12
- package/hooks/gsd/draht-quality-gate.js +3 -3
- package/package.json +14 -11
- package/prompts/commands/atomic-commit.md +1 -12
- package/prompts/commands/brainstorm.md +12 -15
- package/prompts/commands/create-verification-skill.md +108 -0
- package/prompts/commands/discuss-phase.md +3 -14
- package/prompts/commands/execute-phase.md +3 -11
- package/prompts/commands/fix.md +41 -18
- package/prompts/commands/grill.md +66 -0
- package/prompts/commands/init-project.md +5 -15
- package/prompts/commands/map-codebase.md +1 -13
- package/prompts/commands/new-project.md +5 -15
- package/prompts/commands/next-milestone.md +1 -13
- package/prompts/commands/orchestrate.md +1 -1
- package/prompts/commands/pause-work.md +1 -13
- package/prompts/commands/plan-phase.md +2 -11
- package/prompts/commands/progress.md +0 -13
- package/prompts/commands/quick.md +3 -11
- package/prompts/commands/resolve-conflicts.md +71 -0
- package/prompts/commands/resume-work.md +0 -13
- package/prompts/commands/review.md +4 -13
- package/prompts/commands/triage.md +159 -0
- package/prompts/commands/verify-work.md +4 -14
- package/prompts/commands/why.md +135 -0
- package/skills/atomic-reasoning/SKILL.md +115 -0
- package/skills/blast-radius/SKILL.md +55 -0
- package/skills/epistemics/SKILL.md +99 -0
- package/skills/hexagon-animation/SKILL.md +49 -0
- package/skills/hexagon-animation/generate.mjs +81 -0
- package/skills/hexagon-animation/template.html +361 -0
- package/skills/typescript-discipline/SKILL.md +50 -0
- package/skills/typescript-discipline/references/patterns.md +294 -0
- package/skills/unslop/SKILL.md +101 -0
- package/dist/core/provider-display-names.d.ts +0 -2
- package/dist/core/provider-display-names.d.ts.map +0 -1
- package/dist/core/provider-display-names.js +0 -36
- package/dist/core/provider-display-names.js.map +0 -1
- package/dist/prompts/agents/build.md +0 -86
- package/dist/prompts/agents/plan.md +0 -79
- package/dist/prompts/agents/verify.md +0 -69
- package/prompts/agents/build.md +0 -86
- package/prompts/agents/plan.md +0 -79
- package/prompts/agents/verify.md +0 -69
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"soak-log.js","sourceRoot":"","sources":["../../../src/core/soak/soak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AI,CAAC,CAAC;YAC1B,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE;gBAAE,SAAS;YAC3B,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;QAChE,CAAC;QAAC,MAAM,CAAC;YACR,iEAAiE;QAClE,CAAC;IACF,CAAC;IACD,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACvE,OAAO,KAAK,CAAC;AACd,CAAC;AAED,IAAI,SAA8B,CAAC;AAEnC;;;;;GAKG;AACH,MAAM,UAAU,UAAU;IACzB,IAAI,CAAC,SAAS;QAAE,SAAS,GAAG,IAAI,OAAO,EAAE,CAAC;IAC1C,OAAO,SAAS,CAAC;AAClB,CAAC;AAED,6FAA6F;AAC7F,MAAM,UAAU,UAAU,CAAC,GAAwB;IAClD,SAAS,EAAE,aAAa,EAAE,CAAC;IAC3B,SAAS,GAAG,GAAG,CAAC;AACjB,CAAC","sourcesContent":["/**\n * SOAK LOG — the append-only, rotating, restart-surviving JSONL that a long-run\n * verdict reads back weeks later.\n *\n * ─────────────────────────────────────────────────────────────────────────────\n * FILE FORMAT CONTRACT (v1)\n * ─────────────────────────────────────────────────────────────────────────────\n * This comment is the contract, not a description of this implementation. A\n * second writer — the daemon half, which lives on the far side of a package\n * boundary that forbids importing this package — must be implementable from\n * this section alone. Do NOT export a shared module across that boundary; the\n * two halves agree on these bytes and on nothing else.\n *\n * LOCATION\n * <agentDir>/soak/ directory, mode 0700\n * <agentDir>/soak/<stem>.jsonl the ACTIVE file, mode 0600\n * <agentDir>/soak/<stem>-<gen>.jsonl a ROTATED generation, mode 0600\n * <agentDir>/soak/<stem>.rotate.lock the rotation lock, mode 0600\n *\n * `<agentDir>` is the coding agent's config dir (honours DRAHT_CODING_AGENT_DIR).\n * `<stem>` names the WRITING HALF, one file per half: \"session\" for a session\n * process, \"daemon\" for the gateway/daemon process. The halves observe\n * different events from different lifecycles; they are never interleaved into\n * one file and are joined by `sessionId`/`wall` at verdict time.\n * `<gen>` is `<compact-utc>-<pid>-<counter>` and is UNIQUE FOREVER — a\n * generation name is never reused, so a rotation can never clobber evidence.\n * Example: `session-20260822T114530123Z-40321-0.jsonl`.\n *\n * RECORDS\n * One JSON object per line, UTF-8, terminated by \"\\n\". No trailing commas, no\n * pretty printing, no multi-line values. Every record carries:\n * level \"info\" | \"warn\" | \"error\" (matches the gateway logger shape)\n * timestamp ISO-8601 string (matches the gateway logger shape)\n * event string (see SOAK_EVENTS)\n * v 1 (this format version)\n * wall Date.now() milliseconds\n * mono performance.now() milliseconds\n * uptimeMs process.uptime() * 1000\n * pid writing process id\n * rss process.memoryUsage().rss bytes\n * plus whatever fields the event carries. The fields above are stamped LAST,\n * after the event's own: a caller field that collides with one of them is\n * dropped rather than honoured, because a record whose `pid` or `wall` came\n * from a call site is a record the reader classifies as malformed and drops.\n * `sessionId` is present on every\n * record a session process writes; prompt/permission records additionally\n * carry `requestId`, so this stream can be JOINED against the durable\n * per-session permission rows without duplicating any decision here.\n *\n * All three clocks are recorded on every record on purpose. A frozen process\n * (SIGSTOP/SIGCONT, and by extension a suspended host) shows up as a WALL-CLOCK\n * GAP between consecutive heartbeats, not as divergence between the clocks —\n * measured, all three advanced identically across a 2,677 ms stop. Recording\n * all three costs nothing and leaves the question answerable if a real lid-close\n * behaves differently.\n *\n * APPENDING\n * One open(\"a\", 0600) / write / close per record. NOT a held descriptor: this\n * writer reports an fd gauge, and holding its own fd would perturb the metric\n * it publishes. Concurrent appends from many processes are safe because each\n * record is a single write() to an O_APPEND descriptor.\n *\n * NO fsync. Measured 4.0–4.7 ms per record under Node against 0.017–0.025 ms\n * under Bun; on seams that fire per client attach and per prompt that is a\n * hot-path cost, and it would give materially different guarantees on the\n * runtime this product actually ships as (a Bun-compiled binary). The tolerated\n * failure is the loss of the last few records on a hard power cut; the reader\n * is torn-tail tolerant, so that loss costs one line, never the file.\n *\n * ROTATION (the part that loses data if done naively — measured)\n * A two-slot `rename(f, f.1)` scheme under 8 concurrent writers lost 11,148 of\n * 12,000 records. The scheme below lost ZERO across 8 generations. Implement\n * EXACTLY this order:\n * 1. after appending, fstat the descriptor you just wrote through: that\n * yields both the size and the INODE you filled;\n * 2. if size < maxFileBytes, stop;\n * 3. open(lockPath, \"wx\", 0600). EEXIST means another writer is rotating:\n * give up silently and let the next append retry. (A lock whose mtime is\n * older than the stale window is debris and may be removed once.)\n * 4. stat the active path again and COMPARE THE INODE against step 1. A\n * different inode means another writer already rotated the file you\n * filled: release the lock and stop. This comparison is the whole\n * correctness argument — without it, two writers rotate in sequence and\n * the second one renames away a fresh file that other writers are still\n * appending to.\n * 5. rename the active path to a UNIQUE generation name.\n * 6. prune (see RETENTION), then append ONE `rotation` record to the new\n * active file naming the generation just closed and everything pruned.\n * 7. unlink the lock.\n *\n * A writer holding a descriptor across step 5 keeps writing into the renamed\n * inode. That is not loss: the reader reads every generation, so those records\n * are still found. It is why generation files may keep growing after rotation\n * and why file order — not byte order across files — is the only ordering the\n * reader promises.\n *\n * RETENTION\n * Two gates, BOTH must permit a delete:\n * • a byte cap over the directory (maxTotalBytes), and\n * • a retention FLOOR: a generation whose newest write is younger than\n * `retentionFloorMs` (default 14 days) is NEVER pruned, even when the byte\n * cap says prune.\n * A byte-only cap sized for a quiet week silently rotates away the first days\n * of a busy one, and a multi-week soak verdict would destroy its own evidence.\n * When the floor blocks a prune the log simply grows; that is the intended\n * trade. Every prune is named in the `rotation` record written into the\n * surviving file, so a gap in the evidence is VISIBLE rather than invisible.\n *\n * HARD RULES FOR ANY IMPLEMENTATION\n * • NEVER write to stdout or stderr. Not a warning, not a stack trace. The TUI\n * owns the terminal, and a default-on session's streams are asserted\n * byte-identical to a feature-off run; one stray line breaks that.\n * • NEVER throw into a caller. Every failure is swallowed; the last one is\n * retained on the instance for a debugger to look at, and that is all.\n * • The soak directory is OUTSIDE the session store on purpose, which is what\n * exempts it from the byte-identity claim.\n */\n\nimport {\n\tcloseSync,\n\tfstatSync,\n\tmkdirSync,\n\topenSync,\n\treaddirSync,\n\trenameSync,\n\tstatSync,\n\tunlinkSync,\n\twriteSync,\n} from \"node:fs\";\nimport { join } from \"node:path\";\nimport { getAgentDir } from \"../../config.js\";\n\n/** Format version stamped on every record as `v`. */\nexport const SOAK_FORMAT_VERSION = 1;\n\n/** Directory under the agent dir that holds every soak file. */\nexport const SOAK_DIR_NAME = \"soak\";\n\n/** File stem for the half a session process writes. */\nexport const SOAK_STEM_SESSION = \"session\";\n\n/** File stem for the half the daemon writes (a separate implementation of this same contract). */\nexport const SOAK_STEM_DAEMON = \"daemon\";\n\n/**\n * Canonical event names. Kept as a frozen map rather than a union type so a call\n * site can add a field — or a new event — without editing this file.\n */\nexport const SOAK_EVENTS = Object.freeze({\n\tSOCKET_BIND: \"socket_bind\",\n\tSOCKET_REBIND: \"socket_rebind\",\n\tSOCKET_TEARDOWN: \"socket_teardown\",\n\tCLIENT_ATTACH: \"client_attach\",\n\tCLIENT_DETACH: \"client_detach\",\n\tCLIENT_REJECTED: \"client_rejected\",\n\tPROMPT_REJECTED: \"prompt_rejected\",\n\tSOCKETS_REAPED: \"sockets_reaped\",\n\tHEARTBEAT: \"heartbeat\",\n\tROTATION: \"rotation\",\n});\n\n/** Severity, matching the gateway logger's vocabulary so both streams parse the same way. */\nexport type SoakLevel = \"info\" | \"warn\" | \"error\";\n\n/** Arbitrary caller-supplied fields. */\nexport type SoakFields = Record<string, unknown>;\n\n/** One parsed record. The named fields are guaranteed by the contract; the rest are event-specific. */\nexport interface SoakRecord extends SoakFields {\n\tlevel: SoakLevel;\n\ttimestamp: string;\n\tevent: string;\n\tv: number;\n\twall: number;\n\tmono: number;\n\tuptimeMs: number;\n\tpid: number;\n\trss?: number;\n\tsessionId?: string;\n\trequestId?: string;\n}\n\n/** Directory counts for the sockets dir, gathered with one readdir (1.12 ms for 553 entries). */\nexport interface SocketDirCounts {\n\tsockCount: number;\n\tlockCount: number;\n}\n\nexport interface SoakLogOptions {\n\t/** Soak directory. Defaults to `<agentDir>/soak`. */\n\tdir?: string;\n\t/** File stem naming the writing half. Defaults to `session`. */\n\tstem?: string;\n\t/** Rotate once the active file reaches this many bytes. */\n\tmaxFileBytes?: number;\n\t/** Prune oldest generations once the directory exceeds this many bytes — subject to the retention floor. */\n\tmaxTotalBytes?: number;\n\t/** Never prune a generation whose newest write is younger than this. */\n\tretentionFloorMs?: number;\n\t/** Heartbeat period used by {@link SoakLog.startHeartbeat}. */\n\theartbeatMs?: number;\n\t/** Sockets directory used for the sock/lock gauges. Defaults to `<agentDir>/sockets`. */\n\tsocketsDir?: string;\n\t/** Stamped on every record when set. */\n\tsessionId?: string;\n\t/** Live client count for the heartbeat, when the caller can supply one. */\n\tclientCount?: () => number;\n\t/** Injectable clock, for tests. */\n\tnow?: () => number;\n\t/**\n\t * TEST SEAM. Invoked under the rotation lock, immediately before the active\n\t * path is re-stat'd — i.e. inside the exact window another process's rotation\n\t * can land in.\n\t *\n\t * It exists because the inode re-check is otherwise UNFALSIFIABLE: the size\n\t * guard one line below it hides the check under any load a test can generate\n\t * (measured — dropping the inode comparison entirely left 8 processes x 1,500\n\t * records byte-for-byte identical, same generation count). A guard no test can\n\t * kill is a guard that will be deleted by someone who reads it as dead code, so\n\t * the window is made addressable rather than left to chance. Undefined in\n\t * production, where it costs one property read per rotation.\n\t */\n\tonRotateWindow?: () => void;\n}\n\n/** 4 MiB per generation: ~20k records of the size these events produce. */\nconst DEFAULT_MAX_FILE_BYTES = 4 * 1024 * 1024;\n\n/** 64 MiB across the whole directory before the byte gate opens. */\nconst DEFAULT_MAX_TOTAL_BYTES = 64 * 1024 * 1024;\n\n/** 14 days: a 7-day soak plus a full week of slack before its first day can be pruned. */\nconst DEFAULT_RETENTION_FLOOR_MS = 14 * 24 * 60 * 60 * 1000;\n\n/** One heartbeat a minute: fine enough to see a sleep/wake gap, coarse enough to be free. */\nconst DEFAULT_HEARTBEAT_MS = 60_000;\n\n/** A rotation lock older than this was left by a process that died mid-rotation. */\nconst LOCK_STALE_MS = 30_000;\n\n/** Every soak file — active and rotated alike — carries this suffix. */\nconst GENERATION_SUFFIX = \".jsonl\";\n\n/** `process.memoryUsage().rss`, or 0 if the runtime refuses. Works under Node and Bun. */\nexport function currentRss(): number {\n\ttry {\n\t\treturn process.memoryUsage().rss;\n\t} catch {\n\t\treturn 0;\n\t}\n}\n\n/**\n * Milliseconds since this process started, from `process.uptime()`.\n *\n * The in-tree `time()` helper cannot supply this: it compiles itself out unless\n * DRAHT_TIMING=1, so a soak run would carry no startup delta at all.\n */\nexport function startupDeltaMs(): number {\n\ttry {\n\t\treturn Math.round(process.uptime() * 1000);\n\t} catch {\n\t\treturn 0;\n\t}\n}\n\n/**\n * Open descriptor gauge: open /dev/null, record the descriptor number POSIX hands\n * back (always the lowest free one), close it. 0.04 ms, and it tracks fd growth\n * exactly.\n *\n * Deliberately NOT `lsof` (176–200 ms, 4,000x more — and `lsof -p <pid> -U` ORs\n * its selectors and returns every socket on the machine; the correct form is\n * `lsof -a -p <pid> -U`). Deliberately NOT `process.getActiveResourcesInfo()`,\n * which reports 20 under Node with 20 live listeners and 0 under Bun with the\n * same 20 — and the shipped draht is a Bun-compiled binary.\n */\nexport function fdGauge(): number {\n\tlet fd: number | undefined;\n\ttry {\n\t\tfd = openSync(\"/dev/null\", \"r\");\n\t\treturn fd;\n\t} catch {\n\t\treturn -1;\n\t} finally {\n\t\tif (fd !== undefined) {\n\t\t\ttry {\n\t\t\t\tcloseSync(fd);\n\t\t\t} catch {\n\t\t\t\t/* swallowed: the gauge must never disturb the caller */\n\t\t\t}\n\t\t}\n\t}\n}\n\n/** Counts `.sock` and `.lock` entries with one readdir. Never `lsof`. */\nexport function socketDirCounts(socketsDir: string): SocketDirCounts {\n\tlet sockCount = 0;\n\tlet lockCount = 0;\n\ttry {\n\t\tfor (const entry of readdirSync(socketsDir)) {\n\t\t\tif (entry.endsWith(\".sock\")) sockCount++;\n\t\t\telse if (entry.endsWith(\".lock\")) lockCount++;\n\t\t}\n\t} catch {\n\t\t/* no sockets dir yet: both gauges are honestly zero */\n\t}\n\treturn { sockCount, lockCount };\n}\n\n/** Default soak directory for this process. */\nexport function getSoakDir(): string {\n\treturn join(getAgentDir(), SOAK_DIR_NAME);\n}\n\n/**\n * The rotating soak writer.\n *\n * Every public method swallows every failure — a soak log that can break a\n * session is worse than no soak log — and NOTHING here writes to stdout or\n * stderr under any condition.\n */\nexport class SoakLog {\n\treadonly dir: string;\n\treadonly stem: string;\n\treadonly activePath: string;\n\treadonly lockPath: string;\n\n\treadonly #maxFileBytes: number;\n\treadonly #maxTotalBytes: number;\n\treadonly #retentionFloorMs: number;\n\treadonly #heartbeatMs: number;\n\treadonly #socketsDir: string;\n\treadonly #now: () => number;\n\treadonly #onRotateWindow: (() => void) | undefined;\n\n\t#sessionId: string | undefined;\n\t#clientCount: (() => number) | undefined;\n\t#dirReady = false;\n\t#generationCounter = 0;\n\t#timer: ReturnType<typeof setInterval> | undefined;\n\n\t/** Last swallowed failure, retained for a debugger. Never printed. */\n\tlastError: unknown;\n\n\tconstructor(options: SoakLogOptions = {}) {\n\t\tlet dir: string;\n\t\tlet socketsDir: string;\n\t\ttry {\n\t\t\tdir = options.dir ?? getSoakDir();\n\t\t\tsocketsDir = options.socketsDir ?? join(getAgentDir(), \"sockets\");\n\t\t} catch (error) {\n\t\t\t// getAgentDir() reads the environment and can in principle throw; a\n\t\t\t// constructor that throws would take the session with it.\n\t\t\tthis.lastError = error;\n\t\t\tdir = options.dir ?? join(\".\", SOAK_DIR_NAME);\n\t\t\tsocketsDir = options.socketsDir ?? join(\".\", \"sockets\");\n\t\t}\n\t\tthis.dir = dir;\n\t\tthis.stem = options.stem ?? SOAK_STEM_SESSION;\n\t\tthis.activePath = join(this.dir, `${this.stem}${GENERATION_SUFFIX}`);\n\t\tthis.lockPath = join(this.dir, `${this.stem}.rotate.lock`);\n\t\tthis.#maxFileBytes = options.maxFileBytes ?? DEFAULT_MAX_FILE_BYTES;\n\t\tthis.#maxTotalBytes = options.maxTotalBytes ?? DEFAULT_MAX_TOTAL_BYTES;\n\t\tthis.#retentionFloorMs = options.retentionFloorMs ?? DEFAULT_RETENTION_FLOOR_MS;\n\t\tthis.#heartbeatMs = options.heartbeatMs ?? DEFAULT_HEARTBEAT_MS;\n\t\tthis.#socketsDir = socketsDir;\n\t\tthis.#now = options.now ?? Date.now;\n\t\tthis.#sessionId = options.sessionId;\n\t\tthis.#clientCount = options.clientCount;\n\t\tthis.#onRotateWindow = options.onRotateWindow;\n\t}\n\n\t/** Stamp every subsequent record with this session id. */\n\tsetSessionId(sessionId: string | undefined): void {\n\t\tthis.#sessionId = sessionId;\n\t}\n\n\t/** Supply a live client count for the heartbeat. */\n\tsetClientCountProvider(provider: (() => number) | undefined): void {\n\t\tthis.#clientCount = provider;\n\t}\n\n\t/**\n\t * Append one record. This is the whole write API: a new event or a new field\n\t * needs no change to this file.\n\t *\n\t * `fields` may therefore carry ANY name, including one the contract reserves.\n\t * A collision loses: the contract's value is stamped over it. The one\n\t * exception is `sessionId` on a writer that has none of its own — the daemon\n\t * half writes about sessions it does not belong to — where the caller's value\n\t * stands.\n\t */\n\trecord(event: string, fields: SoakFields = {}, level: SoakLevel = \"info\"): void {\n\t\ttry {\n\t\t\tthis.#write(event, fields, level, true);\n\t\t} catch (error) {\n\t\t\tthis.lastError = error;\n\t\t}\n\t}\n\n\t/**\n\t * Write one heartbeat now.\n\t *\n\t * Edge events cannot answer \"how many days did this run\", \"did the host\n\t * sleep\", or \"did fds grow\" — only a periodic record can, so the heartbeat is\n\t * part of the record set, not a nicety.\n\t */\n\theartbeat(fields: SoakFields = {}): void {\n\t\ttry {\n\t\t\tconst counts = socketDirCounts(this.#socketsDir);\n\t\t\tlet clientCount: number | undefined;\n\t\t\ttry {\n\t\t\t\tclientCount = this.#clientCount?.();\n\t\t\t} catch (error) {\n\t\t\t\tthis.lastError = error;\n\t\t\t}\n\t\t\tthis.#write(\n\t\t\t\tSOAK_EVENTS.HEARTBEAT,\n\t\t\t\t{\n\t\t\t\t\t// Same rule as #write: the measured gauges are stamped over a\n\t\t\t\t\t// caller field of the same name, never under it. A heartbeat whose\n\t\t\t\t\t// fdGauge came from its call site measures nothing.\n\t\t\t\t\t...fields,\n\t\t\t\t\tfdGauge: fdGauge(),\n\t\t\t\t\tsockCount: counts.sockCount,\n\t\t\t\t\tlockCount: counts.lockCount,\n\t\t\t\t\t...(clientCount === undefined ? {} : { clientCount }),\n\t\t\t\t},\n\t\t\t\t\"info\",\n\t\t\t\ttrue,\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tthis.lastError = error;\n\t\t}\n\t}\n\n\t/**\n\t * Start the periodic heartbeat. The timer is `unref`'d, so it fires while the\n\t * process is alive and does not by itself keep the process alive — the idiom\n\t * the fleet route already uses. Idempotent.\n\t */\n\tstartHeartbeat(intervalMs: number = this.#heartbeatMs): void {\n\t\ttry {\n\t\t\tif (this.#timer) return;\n\t\t\tconst timer = setInterval(() => this.heartbeat(), intervalMs);\n\t\t\t(timer as { unref?: () => void }).unref?.();\n\t\t\tthis.#timer = timer;\n\t\t} catch (error) {\n\t\t\tthis.lastError = error;\n\t\t}\n\t}\n\n\t/** Stop the periodic heartbeat. Idempotent. */\n\tstopHeartbeat(): void {\n\t\ttry {\n\t\t\tif (!this.#timer) return;\n\t\t\tclearInterval(this.#timer);\n\t\t\tthis.#timer = undefined;\n\t\t} catch (error) {\n\t\t\tthis.lastError = error;\n\t\t}\n\t}\n\n\t// ── internals ────────────────────────────────────────────────────────────\n\n\t#write(event: string, fields: SoakFields, level: SoakLevel, mayRotate: boolean): void {\n\t\tthis.#ensureDir();\n\t\tconst record: SoakRecord = {\n\t\t\t// CALLER FIELDS FIRST, and the contract's fields last, so a caller can\n\t\t\t// never shadow one. `record()` promises that a new event or a new field\n\t\t\t// needs no edit to this file, which makes every call site free to pick a\n\t\t\t// field name — and `pid` is an entirely plausible one at a socket seam,\n\t\t\t// where the `.lock` files already carry one. Spread the other way round,\n\t\t\t// `record(\"client_attach\", { pid: \"not-a-pid\" })` writes a line the\n\t\t\t// reader then rejects as malformed and drops: the seam that reported the\n\t\t\t// event disappears from the evidence instead of failing loudly.\n\t\t\t...fields,\n\t\t\tlevel,\n\t\t\ttimestamp: new Date(this.#now()).toISOString(),\n\t\t\tevent,\n\t\t\tv: SOAK_FORMAT_VERSION,\n\t\t\twall: this.#now(),\n\t\t\tmono: Math.round(performance.now() * 1000) / 1000,\n\t\t\tuptimeMs: startupDeltaMs(),\n\t\t\tpid: process.pid,\n\t\t\trss: currentRss(),\n\t\t\t...(this.#sessionId === undefined ? {} : { sessionId: this.#sessionId }),\n\t\t};\n\t\tconst line = `${JSON.stringify(record)}\\n`;\n\t\tconst filled = this.#append(line);\n\t\tif (mayRotate && filled && filled.size >= this.#maxFileBytes) {\n\t\t\tthis.#rotate(filled.ino);\n\t\t}\n\t}\n\n\t/**\n\t * One open/write/close. The fstat before the close is what makes rotation\n\t * safe: it yields the size AND the inode of the file this record actually\n\t * landed in, so the rotator can prove it is renaming the file it filled.\n\t */\n\t#append(line: string): { size: number; ino: number } | undefined {\n\t\tlet fd: number | undefined;\n\t\ttry {\n\t\t\tfd = openSync(this.activePath, \"a\", 0o600);\n\t\t\tconst buf = Buffer.from(line, \"utf8\");\n\t\t\tlet offset = 0;\n\t\t\twhile (offset < buf.length) {\n\t\t\t\tconst written = writeSync(fd, buf, offset, buf.length - offset);\n\t\t\t\tif (written <= 0) break;\n\t\t\t\toffset += written;\n\t\t\t}\n\t\t\tconst st = fstatSync(fd);\n\t\t\treturn { size: st.size, ino: Number(st.ino) };\n\t\t} catch (error) {\n\t\t\tthis.lastError = error;\n\t\t\treturn undefined;\n\t\t} finally {\n\t\t\tif (fd !== undefined) {\n\t\t\t\ttry {\n\t\t\t\t\tcloseSync(fd);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tthis.lastError = error;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t#ensureDir(): void {\n\t\tif (this.#dirReady) return;\n\t\tmkdirSync(this.dir, { recursive: true, mode: 0o700 });\n\t\tthis.#dirReady = true;\n\t}\n\n\t/**\n\t * Lock-guarded, inode-checked, unique-generation rotation. See the contract at\n\t * the top of this file; the ORDER of the steps is the correctness argument and\n\t * must not be rearranged.\n\t */\n\t#rotate(filledIno: number): void {\n\t\tlet lockFd: number | undefined;\n\t\ttry {\n\t\t\tlockFd = this.#claimRotationLock();\n\t\t\tif (lockFd === undefined) return; // another writer is rotating; next append retries\n\n\t\t\tif (this.#onRotateWindow) {\n\t\t\t\ttry {\n\t\t\t\t\tthis.#onRotateWindow();\n\t\t\t\t} catch (error) {\n\t\t\t\t\tthis.lastError = error;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlet current: { size: number; ino: number };\n\t\t\ttry {\n\t\t\t\tconst st = statSync(this.activePath);\n\t\t\t\tcurrent = { size: st.size, ino: Number(st.ino) };\n\t\t\t} catch {\n\t\t\t\treturn; // already renamed away by someone else\n\t\t\t}\n\t\t\t// THE INODE CHECK: rotate the file THIS record landed in, or rotate\n\t\t\t// nothing. Another writer that rotated while we queued for the lock has\n\t\t\t// already replaced the active path, and renaming its fresh file away is\n\t\t\t// closing a generation nobody filled.\n\t\t\t//\n\t\t\t// Honest note on its weight: with unique generation names the size guard\n\t\t\t// below covers the common case, so this line is defence in depth rather\n\t\t\t// than the thing standing between the log and data loss. It is what keeps\n\t\t\t// the scheme correct if the cap is ever raised at runtime or the size\n\t\t\t// guard is ever relaxed, and `onRotateWindow` exists so it can be killed\n\t\t\t// by a test instead of surviving as unfalsifiable code.\n\t\t\tif (current.ino !== filledIno) return;\n\t\t\tif (current.size < this.#maxFileBytes) return;\n\n\t\t\tconst generation = this.#nextGenerationPath();\n\t\t\trenameSync(this.activePath, generation);\n\n\t\t\tconst pruned = this.#prune();\n\t\t\t// Into the SURVIVING file, so a pruned gap is visible rather than invisible.\n\t\t\tthis.#write(\n\t\t\t\tSOAK_EVENTS.ROTATION,\n\t\t\t\t{\n\t\t\t\t\trotatedTo: generation.slice(this.dir.length + 1),\n\t\t\t\t\trotatedBytes: current.size,\n\t\t\t\t\tmaxFileBytes: this.#maxFileBytes,\n\t\t\t\t\tmaxTotalBytes: this.#maxTotalBytes,\n\t\t\t\t\tretentionFloorMs: this.#retentionFloorMs,\n\t\t\t\t\tpruned: pruned.names,\n\t\t\t\t\tprunedBytes: pruned.bytes,\n\t\t\t\t\tretainedByFloor: pruned.retainedByFloor,\n\t\t\t\t},\n\t\t\t\t\"info\",\n\t\t\t\tfalse,\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tthis.lastError = error;\n\t\t} finally {\n\t\t\tif (lockFd !== undefined) {\n\t\t\t\ttry {\n\t\t\t\t\tcloseSync(lockFd);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tthis.lastError = error;\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\tunlinkSync(this.lockPath);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tthis.lastError = error;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/** `wx` exclusive create — the idiom the socket lock already uses. Undefined means \"someone else holds it\". */\n\t#claimRotationLock(): number | undefined {\n\t\tfor (let attempt = 0; attempt < 2; attempt++) {\n\t\t\ttry {\n\t\t\t\tconst fd = openSync(this.lockPath, \"wx\", 0o600);\n\t\t\t\ttry {\n\t\t\t\t\twriteSync(fd, `${process.pid}\\n${new Date(this.#now()).toISOString()}\\n`);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tthis.lastError = error;\n\t\t\t\t}\n\t\t\t\treturn fd;\n\t\t\t} catch (error) {\n\t\t\t\tif ((error as NodeJS.ErrnoException)?.code !== \"EEXIST\") {\n\t\t\t\t\tthis.lastError = error;\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// A lock that has sat far longer than any rotation takes was left by a\n\t\t\t// process that died mid-rotation. Remove it once, then retry.\n\t\t\ttry {\n\t\t\t\tconst st = statSync(this.lockPath);\n\t\t\t\tif (this.#now() - st.mtimeMs < LOCK_STALE_MS) return undefined;\n\t\t\t\tunlinkSync(this.lockPath);\n\t\t\t} catch {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/** Unique forever: compact UTC stamp + pid + a per-process counter, and never an existing path. */\n\t#nextGenerationPath(): string {\n\t\tfor (;;) {\n\t\t\tconst stamp = new Date(this.#now()).toISOString().replace(/[-:.]/g, \"\");\n\t\t\tconst name = `${this.stem}-${stamp}-${process.pid}-${this.#generationCounter++}${GENERATION_SUFFIX}`;\n\t\t\tconst candidate = join(this.dir, name);\n\t\t\ttry {\n\t\t\t\tstatSync(candidate);\n\t\t\t} catch {\n\t\t\t\treturn candidate; // does not exist\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Byte cap AND retention floor, both of which must permit a delete. Returns\n\t * what went, what it weighed, and how many generations the floor saved — all\n\t * of which land in the rotation record.\n\t */\n\t#prune(): { names: string[]; bytes: number; retainedByFloor: number } {\n\t\tconst names: string[] = [];\n\t\tlet bytes = 0;\n\t\tlet retainedByFloor = 0;\n\t\ttry {\n\t\t\tconst generations = listGenerationFiles(this.dir, this.stem);\n\t\t\tlet total = 0;\n\t\t\tfor (const gen of generations) total += gen.size;\n\t\t\ttry {\n\t\t\t\ttotal += statSync(this.activePath).size;\n\t\t\t} catch {\n\t\t\t\t/* no active file right now; it is about to be created */\n\t\t\t}\n\t\t\tconst now = this.#now();\n\t\t\tfor (const gen of generations) {\n\t\t\t\tif (total <= this.#maxTotalBytes) break;\n\t\t\t\tif (now - gen.mtimeMs < this.#retentionFloorMs) {\n\t\t\t\t\t// The floor wins over the byte cap, always. Growing is the intended\n\t\t\t\t\t// trade: a soak verdict that prunes its own first days is worthless.\n\t\t\t\t\tretainedByFloor++;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\tunlinkSync(gen.path);\n\t\t\t\t\tnames.push(gen.name);\n\t\t\t\t\tbytes += gen.size;\n\t\t\t\t\ttotal -= gen.size;\n\t\t\t\t} catch (error) {\n\t\t\t\t\tthis.lastError = error;\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tthis.lastError = error;\n\t\t}\n\t\treturn { names, bytes, retainedByFloor };\n\t}\n}\n\n/** One rotated generation on disk. */\nexport interface SoakGenerationFile {\n\tname: string;\n\tpath: string;\n\tsize: number;\n\tmtimeMs: number;\n}\n\n/**\n * Every rotated generation for `stem`, oldest first.\n *\n * Ordered by the timestamp embedded in the NAME, not by mtime: a straggler\n * writer still holding a descriptor keeps appending to a generation after it was\n * renamed, which moves its mtime but not its place in the sequence.\n */\nexport function listGenerationFiles(dir: string, stem: string): SoakGenerationFile[] {\n\tconst prefix = `${stem}-`;\n\tconst files: SoakGenerationFile[] = [];\n\tlet entries: string[];\n\ttry {\n\t\tentries = readdirSync(dir);\n\t} catch {\n\t\treturn files;\n\t}\n\tfor (const name of entries) {\n\t\tif (!name.startsWith(prefix) || !name.endsWith(GENERATION_SUFFIX)) continue;\n\t\tconst path = join(dir, name);\n\t\ttry {\n\t\t\tconst st = statSync(path);\n\t\t\tif (!st.isFile()) continue;\n\t\t\tfiles.push({ name, path, size: st.size, mtimeMs: st.mtimeMs });\n\t\t} catch {\n\t\t\t/* vanished between readdir and stat; another writer pruned it */\n\t\t}\n\t}\n\tfiles.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));\n\treturn files;\n}\n\nlet singleton: SoakLog | undefined;\n\n/**\n * Process-wide soak log for the session half.\n *\n * Constructed lazily so importing this module costs nothing and creates no\n * directory; the first record makes the directory.\n */\nexport function getSoakLog(): SoakLog {\n\tif (!singleton) singleton = new SoakLog();\n\treturn singleton;\n}\n\n/** Replace the process-wide log (tests, and the daemon half if it ever shares a process). */\nexport function setSoakLog(log: SoakLog | undefined): void {\n\tsingleton?.stopHeartbeat();\n\tsingleton = log;\n}\n"]}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SOAK READER — reads back every generation a soak log has written, tolerating
|
|
3
|
+
* the one kind of damage the writer's no-fsync append can leave behind.
|
|
4
|
+
*
|
|
5
|
+
* The reader is the offline half: a verdict tool, a test, or an operator runs
|
|
6
|
+
* it, never the hot path. It therefore does the opposite of the writer on one
|
|
7
|
+
* point — it REPORTS damage instead of swallowing it — but it still never
|
|
8
|
+
* throws on damage, because refusing to read a week of evidence over one torn
|
|
9
|
+
* line would be the same failure the retention floor exists to prevent.
|
|
10
|
+
*
|
|
11
|
+
* TORN TAIL. The writer does not fsync, so a hard power cut can leave the final
|
|
12
|
+
* line of a file unterminated (or truncated mid-JSON). That specific case is
|
|
13
|
+
* expected: the partial tail is dropped, the file is reported in `torn`, and the
|
|
14
|
+
* bytes are handed back in `tornTails` so a caller that cares can look. This is
|
|
15
|
+
* the same tolerance the install journal's reader implements.
|
|
16
|
+
*
|
|
17
|
+
* MALFORMED ELSEWHERE. A bad line anywhere but the end is NOT an expected torn
|
|
18
|
+
* tail — it is genuine corruption or a foreign writer. It is collected in
|
|
19
|
+
* `malformed` with its file and 1-based line number rather than thrown, so one
|
|
20
|
+
* bad line costs one line.
|
|
21
|
+
*
|
|
22
|
+
* ORDERING. Records come back in file order: generations oldest-first by their
|
|
23
|
+
* embedded generation stamp, then the active file. Within a file, byte order.
|
|
24
|
+
* ACROSS files the wall clocks can overlap by design — a writer holding a
|
|
25
|
+
* descriptor keeps appending to a generation after it was renamed — so sort by
|
|
26
|
+
* `wall` if you need a global timeline.
|
|
27
|
+
*/
|
|
28
|
+
import { type SoakRecord } from "./soak-log.js";
|
|
29
|
+
/** A line that parsed as neither a torn tail nor a record. */
|
|
30
|
+
export interface SoakMalformedLine {
|
|
31
|
+
file: string;
|
|
32
|
+
/** 1-based line number within `file`. */
|
|
33
|
+
line: number;
|
|
34
|
+
raw: string;
|
|
35
|
+
reason: string;
|
|
36
|
+
}
|
|
37
|
+
export interface SoakReadResult {
|
|
38
|
+
records: SoakRecord[];
|
|
39
|
+
/** Files read, in the order they were read. */
|
|
40
|
+
files: string[];
|
|
41
|
+
/** Files whose final line was an unterminated append. */
|
|
42
|
+
torn: string[];
|
|
43
|
+
/** The unterminated bytes, keyed by file name. */
|
|
44
|
+
tornTails: Record<string, string>;
|
|
45
|
+
/** Lines that were neither a record nor a torn tail. Expected to be empty. */
|
|
46
|
+
malformed: SoakMalformedLine[];
|
|
47
|
+
}
|
|
48
|
+
export interface ReadSoakLogOptions {
|
|
49
|
+
/** Soak directory to read. */
|
|
50
|
+
dir: string;
|
|
51
|
+
/** Which half to read: `session` (default) or `daemon`. */
|
|
52
|
+
stem?: string;
|
|
53
|
+
/** Keep only these events. */
|
|
54
|
+
events?: readonly string[];
|
|
55
|
+
}
|
|
56
|
+
/** Every soak file for `stem`, in read order: generations oldest-first, then the active file. */
|
|
57
|
+
export declare function listSoakFiles(dir: string, stem?: string): string[];
|
|
58
|
+
/** Reads every generation plus the active file. Never throws on damaged content. */
|
|
59
|
+
export declare function readSoakLog(options: ReadSoakLogOptions): SoakReadResult;
|
|
60
|
+
//# sourceMappingURL=soak-reader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"soak-reader.d.ts","sourceRoot":"","sources":["../../../src/core/soak/soak-reader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAIH,OAAO,EAA0C,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AAExF,8DAA8D;AAC9D,MAAM,WAAW,iBAAiB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,yCAAyC;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,cAAc;IAC9B,OAAO,EAAE,UAAU,EAAE,CAAC;IACtB,+CAA+C;IAC/C,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,yDAAyD;IACzD,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,kDAAkD;IAClD,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,8EAA8E;IAC9E,SAAS,EAAE,iBAAiB,EAAE,CAAC;CAC/B;AAED,MAAM,WAAW,kBAAkB;IAClC,8BAA8B;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,2DAA2D;IAC3D,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,8BAA8B;IAC9B,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC3B;AAED,iGAAiG;AACjG,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,GAAE,MAA0B,GAAG,MAAM,EAAE,CASrF;AAED,oFAAoF;AACpF,wBAAgB,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,cAAc,CAsCvE"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SOAK READER — reads back every generation a soak log has written, tolerating
|
|
3
|
+
* the one kind of damage the writer's no-fsync append can leave behind.
|
|
4
|
+
*
|
|
5
|
+
* The reader is the offline half: a verdict tool, a test, or an operator runs
|
|
6
|
+
* it, never the hot path. It therefore does the opposite of the writer on one
|
|
7
|
+
* point — it REPORTS damage instead of swallowing it — but it still never
|
|
8
|
+
* throws on damage, because refusing to read a week of evidence over one torn
|
|
9
|
+
* line would be the same failure the retention floor exists to prevent.
|
|
10
|
+
*
|
|
11
|
+
* TORN TAIL. The writer does not fsync, so a hard power cut can leave the final
|
|
12
|
+
* line of a file unterminated (or truncated mid-JSON). That specific case is
|
|
13
|
+
* expected: the partial tail is dropped, the file is reported in `torn`, and the
|
|
14
|
+
* bytes are handed back in `tornTails` so a caller that cares can look. This is
|
|
15
|
+
* the same tolerance the install journal's reader implements.
|
|
16
|
+
*
|
|
17
|
+
* MALFORMED ELSEWHERE. A bad line anywhere but the end is NOT an expected torn
|
|
18
|
+
* tail — it is genuine corruption or a foreign writer. It is collected in
|
|
19
|
+
* `malformed` with its file and 1-based line number rather than thrown, so one
|
|
20
|
+
* bad line costs one line.
|
|
21
|
+
*
|
|
22
|
+
* ORDERING. Records come back in file order: generations oldest-first by their
|
|
23
|
+
* embedded generation stamp, then the active file. Within a file, byte order.
|
|
24
|
+
* ACROSS files the wall clocks can overlap by design — a writer holding a
|
|
25
|
+
* descriptor keeps appending to a generation after it was renamed — so sort by
|
|
26
|
+
* `wall` if you need a global timeline.
|
|
27
|
+
*/
|
|
28
|
+
import { readFileSync, statSync } from "node:fs";
|
|
29
|
+
import { join } from "node:path";
|
|
30
|
+
import { listGenerationFiles, SOAK_STEM_SESSION } from "./soak-log.js";
|
|
31
|
+
/** Every soak file for `stem`, in read order: generations oldest-first, then the active file. */
|
|
32
|
+
export function listSoakFiles(dir, stem = SOAK_STEM_SESSION) {
|
|
33
|
+
const paths = listGenerationFiles(dir, stem).map((generation) => generation.path);
|
|
34
|
+
const active = join(dir, `${stem}.jsonl`);
|
|
35
|
+
try {
|
|
36
|
+
if (statSync(active).isFile())
|
|
37
|
+
paths.push(active);
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
/* no active file yet */
|
|
41
|
+
}
|
|
42
|
+
return paths;
|
|
43
|
+
}
|
|
44
|
+
/** Reads every generation plus the active file. Never throws on damaged content. */
|
|
45
|
+
export function readSoakLog(options) {
|
|
46
|
+
const stem = options.stem ?? SOAK_STEM_SESSION;
|
|
47
|
+
const wanted = options.events ? new Set(options.events) : undefined;
|
|
48
|
+
const result = { records: [], files: [], torn: [], tornTails: {}, malformed: [] };
|
|
49
|
+
for (const path of listSoakFiles(options.dir, stem)) {
|
|
50
|
+
let raw;
|
|
51
|
+
try {
|
|
52
|
+
raw = readFileSync(path, "utf8");
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
continue; // pruned between listing and reading
|
|
56
|
+
}
|
|
57
|
+
result.files.push(path);
|
|
58
|
+
if (raw.length === 0)
|
|
59
|
+
continue;
|
|
60
|
+
const lines = raw.split("\n");
|
|
61
|
+
if (raw.endsWith("\n")) {
|
|
62
|
+
lines.pop(); // the empty string split() leaves after the final newline
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
const tail = lines.pop() ?? "";
|
|
66
|
+
result.torn.push(path);
|
|
67
|
+
result.tornTails[path] = tail;
|
|
68
|
+
}
|
|
69
|
+
for (let i = 0; i < lines.length; i++) {
|
|
70
|
+
const line = lines[i];
|
|
71
|
+
if (line.trim() === "")
|
|
72
|
+
continue;
|
|
73
|
+
const parsed = parseSoakLine(line);
|
|
74
|
+
if (typeof parsed === "string") {
|
|
75
|
+
result.malformed.push({ file: path, line: i + 1, raw: line, reason: parsed });
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if (wanted && !wanted.has(parsed.event))
|
|
79
|
+
continue;
|
|
80
|
+
result.records.push(parsed);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
85
|
+
/** Returns the record, or a reason string when the line is not one. */
|
|
86
|
+
function parseSoakLine(line) {
|
|
87
|
+
let parsed;
|
|
88
|
+
try {
|
|
89
|
+
parsed = JSON.parse(line);
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
return error instanceof Error ? error.message : String(error);
|
|
93
|
+
}
|
|
94
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
95
|
+
return "not a JSON object";
|
|
96
|
+
}
|
|
97
|
+
const candidate = parsed;
|
|
98
|
+
if (typeof candidate.event !== "string")
|
|
99
|
+
return "missing event";
|
|
100
|
+
if (typeof candidate.wall !== "number")
|
|
101
|
+
return "missing wall";
|
|
102
|
+
if (typeof candidate.pid !== "number")
|
|
103
|
+
return "missing pid";
|
|
104
|
+
return candidate;
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=soak-reader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"soak-reader.js","sourceRoot":"","sources":["../../../src/core/soak/soak-reader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAmB,MAAM,eAAe,CAAC;AAgCxF,iGAAiG;AACjG,MAAM,UAAU,aAAa,CAAC,GAAW,EAAE,IAAI,GAAW,iBAAiB;IAC1E,MAAM,KAAK,GAAG,mBAAmB,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAClF,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,QAAQ,CAAC,CAAC;IAC1C,IAAI,CAAC;QACJ,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE;YAAE,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACnD,CAAC;IAAC,MAAM,CAAC;QACR,wBAAwB;IACzB,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AAED,oFAAoF;AACpF,MAAM,UAAU,WAAW,CAAC,OAA2B;IACtD,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,iBAAiB,CAAC;IAC/C,MAAM,MAAM,GAAG,OAAO,CAAC,MA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AAO,aAAa,CAAC;IAC5D,OAAO,SAAuB,CAAC;AAChC,CAAC","sourcesContent":["/**\n * SOAK READER — reads back every generation a soak log has written, tolerating\n * the one kind of damage the writer's no-fsync append can leave behind.\n *\n * The reader is the offline half: a verdict tool, a test, or an operator runs\n * it, never the hot path. It therefore does the opposite of the writer on one\n * point — it REPORTS damage instead of swallowing it — but it still never\n * throws on damage, because refusing to read a week of evidence over one torn\n * line would be the same failure the retention floor exists to prevent.\n *\n * TORN TAIL. The writer does not fsync, so a hard power cut can leave the final\n * line of a file unterminated (or truncated mid-JSON). That specific case is\n * expected: the partial tail is dropped, the file is reported in `torn`, and the\n * bytes are handed back in `tornTails` so a caller that cares can look. This is\n * the same tolerance the install journal's reader implements.\n *\n * MALFORMED ELSEWHERE. A bad line anywhere but the end is NOT an expected torn\n * tail — it is genuine corruption or a foreign writer. It is collected in\n * `malformed` with its file and 1-based line number rather than thrown, so one\n * bad line costs one line.\n *\n * ORDERING. Records come back in file order: generations oldest-first by their\n * embedded generation stamp, then the active file. Within a file, byte order.\n * ACROSS files the wall clocks can overlap by design — a writer holding a\n * descriptor keeps appending to a generation after it was renamed — so sort by\n * `wall` if you need a global timeline.\n */\n\nimport { readFileSync, statSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { listGenerationFiles, SOAK_STEM_SESSION, type SoakRecord } from \"./soak-log.js\";\n\n/** A line that parsed as neither a torn tail nor a record. */\nexport interface SoakMalformedLine {\n\tfile: string;\n\t/** 1-based line number within `file`. */\n\tline: number;\n\traw: string;\n\treason: string;\n}\n\nexport interface SoakReadResult {\n\trecords: SoakRecord[];\n\t/** Files read, in the order they were read. */\n\tfiles: string[];\n\t/** Files whose final line was an unterminated append. */\n\ttorn: string[];\n\t/** The unterminated bytes, keyed by file name. */\n\ttornTails: Record<string, string>;\n\t/** Lines that were neither a record nor a torn tail. Expected to be empty. */\n\tmalformed: SoakMalformedLine[];\n}\n\nexport interface ReadSoakLogOptions {\n\t/** Soak directory to read. */\n\tdir: string;\n\t/** Which half to read: `session` (default) or `daemon`. */\n\tstem?: string;\n\t/** Keep only these events. */\n\tevents?: readonly string[];\n}\n\n/** Every soak file for `stem`, in read order: generations oldest-first, then the active file. */\nexport function listSoakFiles(dir: string, stem: string = SOAK_STEM_SESSION): string[] {\n\tconst paths = listGenerationFiles(dir, stem).map((generation) => generation.path);\n\tconst active = join(dir, `${stem}.jsonl`);\n\ttry {\n\t\tif (statSync(active).isFile()) paths.push(active);\n\t} catch {\n\t\t/* no active file yet */\n\t}\n\treturn paths;\n}\n\n/** Reads every generation plus the active file. Never throws on damaged content. */\nexport function readSoakLog(options: ReadSoakLogOptions): SoakReadResult {\n\tconst stem = options.stem ?? SOAK_STEM_SESSION;\n\tconst wanted = options.events ? new Set(options.events) : undefined;\n\tconst result: SoakReadResult = { records: [], files: [], torn: [], tornTails: {}, malformed: [] };\n\n\tfor (const path of listSoakFiles(options.dir, stem)) {\n\t\tlet raw: string;\n\t\ttry {\n\t\t\traw = readFileSync(path, \"utf8\");\n\t\t} catch {\n\t\t\tcontinue; // pruned between listing and reading\n\t\t}\n\t\tresult.files.push(path);\n\t\tif (raw.length === 0) continue;\n\n\t\tconst lines = raw.split(\"\\n\");\n\t\tif (raw.endsWith(\"\\n\")) {\n\t\t\tlines.pop(); // the empty string split() leaves after the final newline\n\t\t} else {\n\t\t\tconst tail = lines.pop() ?? \"\";\n\t\t\tresult.torn.push(path);\n\t\t\tresult.tornTails[path] = tail;\n\t\t}\n\n\t\tfor (let i = 0; i < lines.length; i++) {\n\t\t\tconst line = lines[i];\n\t\t\tif (line.trim() === \"\") continue;\n\t\t\tconst parsed = parseSoakLine(line);\n\t\t\tif (typeof parsed === \"string\") {\n\t\t\t\tresult.malformed.push({ file: path, line: i + 1, raw: line, reason: parsed });\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (wanted && !wanted.has(parsed.event)) continue;\n\t\t\tresult.records.push(parsed);\n\t\t}\n\t}\n\n\treturn result;\n}\n\n/** Returns the record, or a reason string when the line is not one. */\nfunction parseSoakLine(line: string): SoakRecord | string {\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(line);\n\t} catch (error) {\n\t\treturn error instanceof Error ? error.message : String(error);\n\t}\n\tif (typeof parsed !== \"object\" || parsed === null || Array.isArray(parsed)) {\n\t\treturn \"not a JSON object\";\n\t}\n\tconst candidate = parsed as Partial<SoakRecord>;\n\tif (typeof candidate.event !== \"string\") return \"missing event\";\n\tif (typeof candidate.wall !== \"number\") return \"missing wall\";\n\tif (typeof candidate.pid !== \"number\") return \"missing pid\";\n\treturn candidate as SoakRecord;\n}\n"]}
|
|
@@ -2,15 +2,92 @@
|
|
|
2
2
|
* Socket Session Discovery
|
|
3
3
|
*
|
|
4
4
|
* Scans the sockets directory to find all running attachable sessions.
|
|
5
|
+
*
|
|
6
|
+
* ── OWNERSHIP AND HYGIENE RULES (R35-ALWAYS.3, R35-ALWAYS.4) ───────────────────
|
|
7
|
+
*
|
|
8
|
+
* These rules are implemented TWICE on purpose: here, and synchronously in
|
|
9
|
+
* `packages/geist-core/src/attach/socket-sessions.ts`, which may not import this
|
|
10
|
+
* package across the geist boundary gate. `scripts/check-geist-protocol.mjs`'s
|
|
11
|
+
* mirror clause only covers the relayed FRAMES — it does not cover any of this —
|
|
12
|
+
* so the two files have to be changed together by hand. They had already drifted
|
|
13
|
+
* once (this file used to shield a lock from the orphan sweep before it had
|
|
14
|
+
* established that `<id>.sock` was a socket at all); that drift is fixed here.
|
|
15
|
+
*
|
|
16
|
+
* O1. OURS OR INVISIBLE. An entry whose file uid is not this process's uid, or
|
|
17
|
+
* whose lock names a live process we cannot signal (`kill` → EPERM, i.e. it
|
|
18
|
+
* belongs to another user), is never listed and never dialled. Before this,
|
|
19
|
+
* a world-writable sockets directory holding a 0666 socket and a lock naming
|
|
20
|
+
* root's pid 1 was listed as a live attachable session by both readers and
|
|
21
|
+
* would have been dialled by the bridge; the 0700 directory mode was the
|
|
22
|
+
* only thing in the way, and nothing asserted it.
|
|
23
|
+
* O2. FOREIGN IS NOT REAPED HERE. A read must not destroy what it cannot
|
|
24
|
+
* interpret, and a fleet scan runs on an HTTP request. Foreign entries are
|
|
25
|
+
* skipped. `SocketServer.start()` is the one place allowed to remove them,
|
|
26
|
+
* and only after it has asserted the directory really is ours and owner-only
|
|
27
|
+
* — which makes a foreign file inside it debris by construction.
|
|
28
|
+
* O3. EPERM STILL MEANS ALIVE. `kill(pid, 0)` → EPERM says the process exists.
|
|
29
|
+
* It is never read as dead, so another user's live session is never reaped.
|
|
30
|
+
* What changed is that "alive" no longer implies "ours".
|
|
31
|
+
* O4. DEBRIS. Two classes used to be immortal — a `.sock` with no `.lock`, and a
|
|
32
|
+
* regular file named `<id>.sock` — because both readers `continue`d past
|
|
33
|
+
* them without reaping. Two such orphans had been sitting in the real
|
|
34
|
+
* `~/.draht/agent/sockets` since 2026-08-21. Both are now reaped once they
|
|
35
|
+
* are older than {@link DEBRIS_GRACE_MS}, which no legitimate transient
|
|
36
|
+
* state survives: the lock is claimed BEFORE the socket is bound, and
|
|
37
|
+
* teardown removes the socket BEFORE the lock, so a socket without a lock is
|
|
38
|
+
* never a normal intermediate state in either direction.
|
|
39
|
+
* O5. A LOCK CANNOT PREDATE THE BOOT. See {@link lockIsPreBootDebris}.
|
|
5
40
|
*/
|
|
6
41
|
import type { SocketSessionInfo } from "./types.js";
|
|
42
|
+
/**
|
|
43
|
+
* How long a file has to sit untouched before it counts as debris rather than as
|
|
44
|
+
* a transient another starter is in the middle of creating.
|
|
45
|
+
*
|
|
46
|
+
* Deliberately the same number as `UNWRITTEN_LOCK_STALE_MS` in `socket-server.ts`
|
|
47
|
+
* and `DEBRIS_GRACE_MS` in geist-core's `socket-sessions.ts`. It is duplicated
|
|
48
|
+
* rather than imported for the boundary reason at the top of this file.
|
|
49
|
+
*/
|
|
50
|
+
export declare const DEBRIS_GRACE_MS = 10000;
|
|
51
|
+
/** What this process may do about the process a lock names. */
|
|
52
|
+
export type PidOwnership =
|
|
53
|
+
/** Alive and signallable by us: a session this user is running. */
|
|
54
|
+
"ours"
|
|
55
|
+
/** Alive, but `kill` says EPERM — it belongs to another user. */
|
|
56
|
+
| "foreign"
|
|
57
|
+
/** No such process. */
|
|
58
|
+
| "dead";
|
|
59
|
+
/**
|
|
60
|
+
* Who owns the process a lock names.
|
|
61
|
+
*
|
|
62
|
+
* `process.kill(pid, 0)` sends no signal; it only asks whether the pid could be
|
|
63
|
+
* signalled. EPERM is the discriminator that costs nothing: a process this uid
|
|
64
|
+
* could have started is always signallable by this uid, so EPERM means alive AND
|
|
65
|
+
* not ours. That single distinction is what R35-ALWAYS.3 rests on — without it a
|
|
66
|
+
* lock naming root's pid 1 reads as a live session of ours forever.
|
|
67
|
+
*/
|
|
68
|
+
export declare function pidOwnership(pid: number): PidOwnership;
|
|
69
|
+
/**
|
|
70
|
+
* Check if a process with the given PID is running.
|
|
71
|
+
*
|
|
72
|
+
* Uses `process.kill(pid, 0)` which doesn't actually send a signal,
|
|
73
|
+
* but throws if the process doesn't exist.
|
|
74
|
+
*
|
|
75
|
+
* EPERM means the process exists but belongs to another user: alive, and still
|
|
76
|
+
* reported as alive (O3). Callers that also care WHOSE it is ask
|
|
77
|
+
* {@link pidOwnership} instead.
|
|
78
|
+
*/
|
|
79
|
+
export declare function isProcessRunning(pid: number): boolean;
|
|
80
|
+
/** This process's uid, or null off POSIX where the concept does not exist. */
|
|
81
|
+
export declare function currentUid(): number | null;
|
|
7
82
|
/**
|
|
8
83
|
* Discover all running socket-based sessions.
|
|
9
84
|
*
|
|
10
85
|
* Scans the socket directory for .sock files and reads their corresponding
|
|
11
86
|
* .lock files to extract metadata (PID, cwd, createdAt).
|
|
12
87
|
*
|
|
13
|
-
*
|
|
88
|
+
* Only sessions belonging to this uid are returned, and reaping follows the rules
|
|
89
|
+
* at the top of this file: dead-owner pairs, pre-boot locks, lockless sockets and
|
|
90
|
+
* non-socket `<id>.sock` files go; anything foreign, fresh, or unreadable stays.
|
|
14
91
|
*
|
|
15
92
|
* @param socketDir - Directory containing socket files
|
|
16
93
|
* @returns Array of discovered session info
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../../../src/core/socket-server/discovery.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../../../src/core/socket-server/discovery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAQH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,QAAS,CAAC;AA8HtC,+DAA+D;AAC/D,MAAM,MAAM,YAAY;AACvB,mEAAmE;AACjE,MAAM;AACR,iEAAiE;GAC/D,SAAS;AACX,uBAAuB;GACrB,MAAM,CAAC;AAEV;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,CAQtD;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAErD;AAED,8EAA8E;AAC9E,wBAAgB,UAAU,IAAI,MAAM,GAAG,IAAI,CAE1C;AAgFD;;;;;;;;;;;;GAYG;AACH,wBAAsB,sBAAsB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAmH5F"}
|