@sayknow-cli/coding-agent 0.7.10 → 0.7.12
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 +18 -0
- package/dist/types/async/result-formatting.d.ts +2 -0
- package/dist/types/capability/fs.d.ts +22 -3
- package/dist/types/capability/mcp.d.ts +2 -0
- package/dist/types/cli/append-system-prompt.d.ts +6 -0
- package/dist/types/cli/update-cli.d.ts +3 -0
- package/dist/types/commands/contribution-prep.d.ts +0 -3
- package/dist/types/commands/migrate.d.ts +1 -1
- package/dist/types/commands/sdk.d.ts +9 -0
- package/dist/types/commit/changelog/index.d.ts +1 -0
- package/dist/types/config/settings-schema.d.ts +14 -0
- package/dist/types/config/settings.d.ts +7 -1
- package/dist/types/coordinator-mcp/session-reaper.d.ts +5 -0
- package/dist/types/cursor-delete-path.d.ts +1 -0
- package/dist/types/cursor-mcp-name.d.ts +8 -0
- package/dist/types/dap/config.d.ts +8 -4
- package/dist/types/dap/session.d.ts +11 -2
- package/dist/types/debug/report-bundle-parent.d.ts +2 -0
- package/dist/types/debug/system-info.d.ts +6 -1
- package/dist/types/discovery/helpers.d.ts +11 -3
- package/dist/types/discovery/mcp-json.d.ts +1 -0
- package/dist/types/edit/file-read-cache.d.ts +4 -0
- package/dist/types/edit/modes/patch.d.ts +14 -0
- package/dist/types/edit/modes/replace.d.ts +8 -0
- package/dist/types/eval/py/runtime.d.ts +9 -0
- package/dist/types/exa/mcp-client.d.ts +11 -6
- package/dist/types/exec/bash-executor.d.ts +18 -1
- package/dist/types/export/html/css-color.d.ts +2 -0
- package/dist/types/export/html/html-export-destination.d.ts +2 -0
- package/dist/types/export/html/template.generated.d.ts +1 -1
- package/dist/types/extensibility/custom-tools/loader.d.ts +3 -2
- package/dist/types/extensibility/custom-tools/types.d.ts +3 -1
- package/dist/types/extensibility/plugins/marketplace/cache.d.ts +2 -0
- package/dist/types/extensibility/plugins/plugin-link-path.d.ts +2 -0
- package/dist/types/goals/runtime.d.ts +6 -0
- package/dist/types/harness-control-plane/receipt-spool.d.ts +4 -0
- package/dist/types/hindsight/content.d.ts +5 -6
- package/dist/types/internal-urls/skill-path.d.ts +1 -0
- package/dist/types/internal-urls/types.d.ts +2 -0
- package/dist/types/lsp/clients/swiftlint-client.d.ts +0 -4
- package/dist/types/lsp/config.d.ts +8 -5
- package/dist/types/lsp/workspace-path.d.ts +1 -0
- package/dist/types/migrate/adapters/codex.d.ts +2 -1
- package/dist/types/migrate/adapters/index.d.ts +10 -1
- package/dist/types/migrate/executor.d.ts +3 -1
- package/dist/types/migrate/types.d.ts +15 -3
- package/dist/types/modes/components/custom-editor.d.ts +6 -0
- package/dist/types/modes/components/extensions/state-manager.d.ts +4 -3
- package/dist/types/modes/components/model-selector.d.ts +46 -0
- package/dist/types/modes/controllers/input-controller.d.ts +9 -0
- package/dist/types/modes/interactive-mode.d.ts +1 -0
- package/dist/types/modes/utils/macos-option-forwarding.d.ts +17 -0
- package/dist/types/runtime-mcp/content-limits.d.ts +4 -0
- package/dist/types/runtime-mcp/manager.d.ts +9 -1
- package/dist/types/runtime-mcp/mcp-redirect.d.ts +9 -0
- package/dist/types/runtime-mcp/oauth-public-url.d.ts +1 -0
- package/dist/types/runtime-mcp/plugin-mcp-name-filter.d.ts +22 -0
- package/dist/types/runtime-mcp/plugin-network-boundary.d.ts +1 -0
- package/dist/types/runtime-mcp/project-host-values.d.ts +33 -0
- package/dist/types/runtime-mcp/smithery-registry.d.ts +24 -0
- package/dist/types/runtime-mcp/tool-bridge.d.ts +4 -0
- package/dist/types/runtime-mcp/types.d.ts +6 -0
- package/dist/types/sdk/broker/ensure.d.ts +2 -0
- package/dist/types/sdk/broker/lifecycle-ledger.d.ts +5 -1
- package/dist/types/sdk/broker/runtime.d.ts +1 -1
- package/dist/types/sdk/bus/chat-daemon-control.d.ts +3 -1
- package/dist/types/sdk/bus/telegram-daemon-contract.d.ts +3 -1
- package/dist/types/sdk/bus/telegram-daemon.d.ts +1 -0
- package/dist/types/sdk/host/events.d.ts +4 -0
- package/dist/types/session/agent-session.d.ts +20 -1
- package/dist/types/session/messages.d.ts +5 -1
- package/dist/types/session/session-manager.d.ts +13 -0
- package/dist/types/session/session-storage.d.ts +8 -0
- package/dist/types/session/streaming-output.d.ts +11 -0
- package/dist/types/session-import/redact.d.ts +1 -1
- package/dist/types/skc-runtime/managed-owner-admission.d.ts +3 -0
- package/dist/types/skc-runtime/psmux-detect.d.ts +5 -4
- package/dist/types/skc-runtime/ralplan-runtime.d.ts +5 -0
- package/dist/types/skc-runtime/sidecar-bootstrap-env.d.ts +6 -0
- package/dist/types/skc-runtime/state-writer.d.ts +4 -1
- package/dist/types/skc-runtime/tmux-sessions.d.ts +24 -0
- package/dist/types/skc-runtime/ultragoal-runtime.d.ts +4 -0
- package/dist/types/skill-state/workflow-mutation-guard.d.ts +20 -1
- package/dist/types/slash-commands/helpers/mcp.d.ts +5 -0
- package/dist/types/ssh/ssh-executor.d.ts +3 -1
- package/dist/types/system-prompt.d.ts +5 -2
- package/dist/types/task/executor.d.ts +17 -3
- package/dist/types/task/isolation-dir.d.ts +26 -0
- package/dist/types/task/role-body.d.ts +11 -0
- package/dist/types/task/token-log-mode.test.d.ts +1 -0
- package/dist/types/tools/ask.d.ts +77 -254
- package/dist/types/tools/ast-edit-write-path.d.ts +23 -0
- package/dist/types/tools/atomic-file-write.d.ts +74 -0
- package/dist/types/tools/auto-generated-guard.d.ts +5 -2
- package/dist/types/tools/bash-allowed-prefixes.d.ts +16 -0
- package/dist/types/tools/bash-interactive.d.ts +2 -0
- package/dist/types/tools/bash-skill-urls.d.ts +5 -1
- package/dist/types/tools/bash.d.ts +1 -0
- package/dist/types/tools/browser/cdp-url.d.ts +2 -0
- package/dist/types/tools/browser/tab-worker.d.ts +2 -0
- package/dist/types/tools/debug.d.ts +2 -2
- package/dist/types/tools/explicit-artifact.d.ts +8 -0
- package/dist/types/tools/fetch.d.ts +7 -4
- package/dist/types/tools/github-side-effect.d.ts +22 -0
- package/dist/types/tools/index.d.ts +3 -0
- package/dist/types/tools/monitor-mutation.d.ts +9 -0
- package/dist/types/tools/recipe/index.d.ts +2 -0
- package/dist/types/tools/recipe/recipe-guard.d.ts +7 -0
- package/dist/types/tools/restricted-cwd.d.ts +1 -0
- package/dist/types/tools/reverse-engineer.d.ts +81 -0
- package/dist/types/tools/search-tool-bm25.d.ts +2 -0
- package/dist/types/tools/tmux-self-injection-guard.d.ts +17 -0
- package/dist/types/tools/untrusted-content.d.ts +12 -0
- package/dist/types/utils/file-mentions.d.ts +5 -0
- package/dist/types/utils/open.d.ts +0 -1
- package/dist/types/utils/shell-snapshot.d.ts +2 -0
- package/dist/types/utils/title-generator.d.ts +12 -2
- package/dist/types/utils/tools-checksum.d.ts +7 -0
- package/dist/types/utils/xml-escape.d.ts +2 -0
- package/dist/types/web/scrapers/types.d.ts +8 -1
- package/dist/types/web/search/providers/codex.d.ts +6 -7
- package/dist/types/web/search/providers/insane.d.ts +7 -1
- package/dist/types/web/search/providers/kimi.d.ts +2 -0
- package/dist/types/web/search/providers/searxng.d.ts +7 -0
- package/dist/types/web/search/providers/xai.d.ts +2 -0
- package/package.json +7 -7
- package/scripts/generate-sdk-operation-inventory.ts +4 -0
- package/src/async/job-manager.ts +23 -9
- package/src/async/result-formatting.ts +40 -0
- package/src/capability/fs.ts +78 -11
- package/src/capability/mcp.ts +2 -0
- package/src/cli/append-system-prompt.ts +12 -0
- package/src/cli/auth-broker-cli.ts +22 -12
- package/src/cli/config-cli.ts +8 -18
- package/src/cli/migrate-cli.ts +7 -5
- package/src/cli/ssh-cli.ts +6 -3
- package/src/cli/stats-cli.ts +9 -4
- package/src/cli/update-cli.ts +42 -0
- package/src/cli/web-search-cli.ts +9 -3
- package/src/cli.ts +5 -9
- package/src/commands/commit.ts +2 -2
- package/src/commands/contribution-prep.ts +1 -3
- package/src/commands/harness.ts +25 -15
- package/src/commands/launch.ts +1 -1
- package/src/commands/migrate.ts +3 -3
- package/src/commands/sdk.ts +115 -14
- package/src/commands/ultragoal.ts +14 -8
- package/src/commit/agentic/agent.ts +6 -6
- package/src/commit/analysis/conventional.ts +14 -5
- package/src/commit/changelog/index.ts +39 -1
- package/src/commit/message.ts +10 -3
- package/src/config/config-file.ts +106 -3
- package/src/config/keybindings.ts +154 -7
- package/src/config/mcp-schema.json +4 -0
- package/src/config/model-registry.ts +10 -2
- package/src/config/settings-schema.ts +18 -0
- package/src/config/settings.ts +32 -4
- package/src/coordinator-mcp/policy.ts +14 -4
- package/src/coordinator-mcp/server.ts +44 -4
- package/src/coordinator-mcp/session-reaper.ts +9 -1
- package/src/cursor-delete-path.ts +10 -0
- package/src/cursor-mcp-name.ts +15 -0
- package/src/cursor.ts +13 -2
- package/src/dap/client.ts +9 -2
- package/src/dap/config.ts +33 -13
- package/src/dap/defaults.json +1 -1
- package/src/dap/session.ts +161 -36
- package/src/debug/crash-diagnostics.ts +89 -6
- package/src/debug/report-bundle-parent.ts +22 -0
- package/src/debug/report-bundle.ts +100 -3
- package/src/debug/system-info.ts +21 -4
- package/src/defaults/skc/extensions/grok-cli-vendor/src/shared/base-url.ts +21 -7
- package/src/defaults/skc/skills/deep-interview/SKILL.md +1 -1
- package/src/discovery/agents-md.ts +3 -2
- package/src/discovery/agents.ts +3 -2
- package/src/discovery/builtin.ts +21 -11
- package/src/discovery/claude.ts +5 -4
- package/src/discovery/cline.ts +2 -2
- package/src/discovery/codex.ts +6 -5
- package/src/discovery/cursor.ts +11 -2
- package/src/discovery/gemini.ts +4 -3
- package/src/discovery/github.ts +2 -2
- package/src/discovery/helpers.ts +51 -11
- package/src/discovery/mcp-json.ts +28 -12
- package/src/discovery/opencode.ts +2 -1
- package/src/discovery/ssh.ts +11 -6
- package/src/discovery/substitute-plugin-root.ts +3 -1
- package/src/discovery/vscode.ts +3 -3
- package/src/edit/apply-patch/index.ts +12 -1
- package/src/edit/file-read-cache.ts +24 -6
- package/src/edit/index.ts +90 -20
- package/src/edit/modes/patch.ts +215 -9
- package/src/edit/modes/replace.ts +141 -0
- package/src/eval/js/context-manager.ts +29 -3
- package/src/eval/js/worker-entry.ts +51 -18
- package/src/eval/py/runner.py +144 -5
- package/src/eval/py/runtime.ts +44 -4
- package/src/eval/py/tool-bridge.ts +4 -0
- package/src/exa/mcp-client.ts +53 -11
- package/src/exec/bash-executor.ts +87 -4
- package/src/exec/non-interactive-env.ts +0 -1
- package/src/export/html/css-color.ts +9 -0
- package/src/export/html/html-export-destination.ts +16 -0
- package/src/export/html/index.ts +102 -8
- package/src/export/html/template.generated.ts +1 -1
- package/src/extensibility/custom-tools/loader.ts +13 -3
- package/src/extensibility/custom-tools/types.ts +3 -1
- package/src/extensibility/custom-tools/wrapper.ts +3 -1
- package/src/extensibility/plugins/manager.ts +3 -2
- package/src/extensibility/plugins/marketplace/cache.ts +15 -0
- package/src/extensibility/plugins/marketplace/fetcher.ts +2 -2
- package/src/extensibility/plugins/marketplace/manager.ts +5 -3
- package/src/extensibility/plugins/plugin-link-path.ts +12 -0
- package/src/extensibility/skc-plugins/mcp-policy.ts +2 -1
- package/src/goals/runtime.ts +30 -8
- package/src/harness-control-plane/finalize.ts +10 -0
- package/src/harness-control-plane/operate.ts +12 -4
- package/src/harness-control-plane/owner.ts +8 -1
- package/src/harness-control-plane/receipt-spool.ts +105 -28
- package/src/harness-control-plane/storage.ts +124 -6
- package/src/hashline/execute.ts +3 -3
- package/src/hashline/recovery.ts +85 -2
- package/src/hindsight/config.ts +9 -3
- package/src/hindsight/content.ts +116 -16
- package/src/hindsight/mental-models.ts +22 -10
- package/src/hindsight/state.ts +7 -4
- package/src/hooks/native-skill-hook.ts +17 -12
- package/src/i18n/messages/de.settings.ts +3 -0
- package/src/i18n/messages/es.settings.ts +3 -0
- package/src/i18n/messages/fr.settings.ts +3 -0
- package/src/i18n/messages/ja.settings.ts +3 -0
- package/src/i18n/messages/ko.settings.ts +3 -0
- package/src/i18n/messages/zh.settings.ts +3 -0
- package/src/internal-urls/artifact-protocol.ts +3 -1
- package/src/internal-urls/docs-index.generated.ts +10 -10
- package/src/internal-urls/local-protocol.ts +167 -8
- package/src/internal-urls/skill-path.ts +18 -0
- package/src/internal-urls/skill-protocol.ts +2 -0
- package/src/internal-urls/types.ts +2 -0
- package/src/lsp/client.ts +2 -1
- package/src/lsp/clients/biome-client.ts +2 -0
- package/src/lsp/clients/swiftlint-client.ts +2 -0
- package/src/lsp/config.ts +18 -62
- package/src/lsp/edits.ts +6 -0
- package/src/lsp/index.ts +29 -0
- package/src/lsp/workspace-path.ts +75 -0
- package/src/main.ts +33 -11
- package/src/memories/index.ts +141 -9
- package/src/migrate/action-planner.ts +57 -0
- package/src/migrate/adapters/claude-code.ts +23 -4
- package/src/migrate/adapters/codex.ts +22 -4
- package/src/migrate/adapters/index.ts +22 -4
- package/src/migrate/adapters/opencode.ts +6 -1
- package/src/migrate/executor.ts +84 -7
- package/src/migrate/report.ts +19 -2
- package/src/migrate/types.ts +14 -4
- package/src/modes/DESIGN.md +5 -0
- package/src/modes/acp/acp-agent.ts +35 -2
- package/src/modes/acp/permission-mode.ts +18 -1
- package/src/modes/components/custom-editor.ts +14 -0
- package/src/modes/components/extensions/extension-dashboard.ts +2 -2
- package/src/modes/components/extensions/inspector-panel.ts +9 -5
- package/src/modes/components/extensions/state-manager.ts +15 -5
- package/src/modes/components/model-selector.ts +144 -94
- package/src/modes/components/welcome.ts +3 -2
- package/src/modes/controllers/command-controller.ts +300 -9
- package/src/modes/controllers/event-controller.ts +1 -1
- package/src/modes/controllers/extension-ui-controller.ts +32 -19
- package/src/modes/controllers/input-controller.ts +62 -26
- package/src/modes/controllers/plan-mode-controller.ts +17 -7
- package/src/modes/controllers/runtime-mcp-command-controller.ts +25 -20
- package/src/modes/controllers/ssh-command-controller.ts +3 -1
- package/src/modes/interactive-mode.ts +10 -0
- package/src/modes/utils/macos-option-forwarding.ts +80 -0
- package/src/prompts/system/irc-incoming.md +3 -1
- package/src/prompts/system/project-prompt.md +19 -0
- package/src/prompts/system/system-prompt.md +3 -0
- package/src/prompts/tools/ask.md +2 -0
- package/src/prompts/tools/debug.md +1 -1
- package/src/prompts/tools/monitor.md +7 -5
- package/src/prompts/tools/reverse-engineer.md +29 -0
- package/src/runtime-credential-selector.ts +2 -2
- package/src/runtime-mcp/config-writer.ts +10 -6
- package/src/runtime-mcp/config.ts +1 -0
- package/src/runtime-mcp/content-limits.ts +7 -0
- package/src/runtime-mcp/json-rpc.ts +2 -1
- package/src/runtime-mcp/manager.ts +57 -9
- package/src/runtime-mcp/mcp-redirect.ts +73 -0
- package/src/runtime-mcp/oauth-flow.ts +43 -5
- package/src/runtime-mcp/oauth-public-url.ts +8 -0
- package/src/runtime-mcp/plugin-mcp-name-filter.ts +62 -0
- package/src/runtime-mcp/plugin-network-boundary.ts +4 -0
- package/src/runtime-mcp/project-host-values.ts +50 -0
- package/src/runtime-mcp/render.ts +16 -1
- package/src/runtime-mcp/smithery-registry.ts +22 -3
- package/src/runtime-mcp/tool-bridge.ts +194 -21
- package/src/runtime-mcp/transports/http.ts +4 -3
- package/src/runtime-mcp/transports/stdio.ts +2 -1
- package/src/runtime-mcp/types.ts +6 -0
- package/src/sdk/broker/broker.ts +11 -2
- package/src/sdk/broker/ensure.ts +131 -10
- package/src/sdk/broker/lifecycle-ledger.ts +18 -3
- package/src/sdk/broker/lifecycle.ts +21 -19
- package/src/sdk/broker/runtime.ts +1 -1
- package/src/sdk/bus/chat-daemon-cli.ts +38 -1
- package/src/sdk/bus/chat-daemon-control.ts +5 -3
- package/src/sdk/bus/index.ts +5 -3
- package/src/sdk/bus/lifecycle-control-runtime.ts +9 -2
- package/src/sdk/bus/session-control.ts +2 -0
- package/src/sdk/bus/slack-daemon.ts +8 -1
- package/src/sdk/bus/slack-live-provider.ts +3 -1
- package/src/sdk/bus/telegram-daemon-contract.ts +3 -1
- package/src/sdk/bus/telegram-daemon-control.ts +17 -12
- package/src/sdk/bus/telegram-daemon.ts +41 -1
- package/src/sdk/host/events.ts +67 -4
- package/src/sdk/mcp/server.ts +16 -3
- package/src/sdk/protocol/operation-inventory.generated.json +22 -0
- package/src/sdk/session.ts +18 -25
- package/src/secrets/obfuscator.ts +92 -12
- package/src/session/agent-session.ts +395 -79
- package/src/session/artifacts.ts +3 -1
- package/src/session/history-storage.ts +172 -8
- package/src/session/internal/managed-session-scope.ts +130 -52
- package/src/session/messages.ts +47 -6
- package/src/session/session-manager.ts +170 -10
- package/src/session/session-storage.ts +31 -1
- package/src/session/streaming-output.ts +263 -4
- package/src/session-import/redact.ts +76 -3
- package/src/setup/hermes-setup.ts +4 -1
- package/src/skc-runtime/gc-runtime.ts +26 -4
- package/src/skc-runtime/launch-tmux.ts +21 -11
- package/src/skc-runtime/launch-worktree.ts +42 -3
- package/src/skc-runtime/managed-owner-admission.ts +46 -2
- package/src/skc-runtime/psmux-detect.ts +29 -5
- package/src/skc-runtime/ralplan-runtime.ts +14 -1
- package/src/skc-runtime/session-resolution.ts +38 -6
- package/src/skc-runtime/sidecar-bootstrap-env.ts +19 -0
- package/src/skc-runtime/state-writer.ts +134 -16
- package/src/skc-runtime/tmux-sessions.ts +85 -4
- package/src/skc-runtime/ultragoal-change-set.ts +18 -2
- package/src/skc-runtime/ultragoal-guard.ts +9 -1
- package/src/skc-runtime/ultragoal-runtime.ts +26 -9
- package/src/skill-state/active-state.ts +13 -0
- package/src/skill-state/workflow-mutation-guard.ts +3297 -180
- package/src/slash-commands/builtin-registry.ts +14 -8
- package/src/slash-commands/helpers/mcp.ts +20 -7
- package/src/ssh/ssh-executor.ts +3 -1
- package/src/stt/recorder.ts +26 -9
- package/src/system-prompt.ts +65 -16
- package/src/task/commands.ts +3 -1
- package/src/task/executor.ts +52 -7
- package/src/task/index.ts +28 -0
- package/src/task/isolation-dir.ts +143 -0
- package/src/task/role-body.ts +84 -0
- package/src/task/token-log-mode.test.ts +162 -0
- package/src/task/token-log.ts +91 -2
- package/src/task/worktree.ts +16 -7
- package/src/tools/archive-reader.ts +653 -31
- package/src/tools/ask.ts +86 -14
- package/src/tools/ast-edit-write-path.ts +133 -0
- package/src/tools/ast-edit.ts +27 -1
- package/src/tools/ast-grep.ts +7 -2
- package/src/tools/atomic-file-write.ts +625 -0
- package/src/tools/auto-generated-guard.ts +28 -8
- package/src/tools/bash-allowed-prefixes.ts +225 -6
- package/src/tools/bash-interactive.ts +12 -0
- package/src/tools/bash-skill-urls.ts +113 -7
- package/src/tools/bash.ts +152 -20
- package/src/tools/browser/cdp-url.ts +18 -0
- package/src/tools/browser/tab-worker.ts +49 -14
- package/src/tools/browser.ts +25 -8
- package/src/tools/cron.ts +10 -1
- package/src/tools/debug.ts +16 -8
- package/src/tools/eval.ts +71 -34
- package/src/tools/explicit-artifact.ts +89 -0
- package/src/tools/fetch.ts +26 -17
- package/src/tools/gh.ts +40 -12
- package/src/tools/github-side-effect.ts +112 -0
- package/src/tools/image-gen.ts +24 -10
- package/src/tools/index.ts +6 -0
- package/src/tools/monitor-mutation.ts +27 -0
- package/src/tools/monitor.ts +28 -1
- package/src/tools/output-meta.ts +74 -5
- package/src/tools/read.ts +24 -36
- package/src/tools/recipe/index.ts +12 -0
- package/src/tools/recipe/recipe-guard.ts +19 -0
- package/src/tools/recipe/runner.ts +23 -12
- package/src/tools/render-utils.ts +2 -2
- package/src/tools/restricted-cwd.ts +10 -0
- package/src/tools/reverse-engineer.ts +497 -0
- package/src/tools/search-tool-bm25.ts +14 -3
- package/src/tools/search.ts +3 -2
- package/src/tools/ssh.ts +235 -8
- package/src/tools/subagent-render.ts +43 -7
- package/src/tools/subagent.ts +7 -3
- package/src/tools/tmux-self-injection-guard.ts +3538 -0
- package/src/tools/todo-write.ts +41 -3
- package/src/tools/untrusted-content.ts +23 -0
- package/src/tools/vim.ts +2 -2
- package/src/tools/write.ts +37 -4
- package/src/tui/tree-list.ts +15 -1
- package/src/utils/commit-message-generator.ts +9 -2
- package/src/utils/external-editor.ts +21 -7
- package/src/utils/file-mentions.ts +75 -7
- package/src/utils/git.ts +38 -7
- package/src/utils/open.ts +73 -4
- package/src/utils/shell-snapshot.ts +9 -1
- package/src/utils/title-generator.ts +61 -16
- package/src/utils/tools-checksum.ts +34 -0
- package/src/utils/tools-manager.ts +24 -6
- package/src/utils/xml-escape.ts +14 -0
- package/src/web/insane/url-guard.ts +2 -1
- package/src/web/scrapers/types.ts +8 -0
- package/src/web/scrapers/youtube.ts +3 -2
- package/src/web/search/index.ts +4 -3
- package/src/web/search/providers/anthropic.ts +4 -4
- package/src/web/search/providers/codex.ts +31 -34
- package/src/web/search/providers/insane.ts +145 -28
- package/src/web/search/providers/kimi.ts +15 -5
- package/src/web/search/providers/searxng.ts +47 -4
- package/src/web/search/providers/xai.ts +7 -2
- package/dist/types/cli/shell-cli.d.ts +0 -8
- package/dist/types/commands/shell.d.ts +0 -21
- package/src/cli/shell-cli.ts +0 -176
- package/src/commands/shell.ts +0 -29
package/src/session/artifacts.ts
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
type ManagedSessionDescendantStore,
|
|
15
15
|
publishManagedFileNoReplace,
|
|
16
16
|
} from "./internal/managed-session-storage";
|
|
17
|
+
import { writeExplicitOwnerOnlyTextSync } from "./session-storage";
|
|
17
18
|
import { DEFAULT_ARTIFACT_MAX_BYTES, truncateHeadBytes } from "./streaming-output";
|
|
18
19
|
|
|
19
20
|
export interface ManagedOutputGeneration {
|
|
@@ -138,7 +139,8 @@ export class ArtifactManager {
|
|
|
138
139
|
if (!/^[a-zA-Z0-9_.-]+$/.test(filename)) throw new Error("Unsafe named artifact");
|
|
139
140
|
await this.#ensureDir();
|
|
140
141
|
if (this.#store) await this.#store.replace(filename, Buffer.from(content, "utf8"));
|
|
141
|
-
|
|
142
|
+
// Named files, including draft.txt, are created here.
|
|
143
|
+
else writeExplicitOwnerOnlyTextSync(path.join(this.#dir, filename), content);
|
|
142
144
|
}
|
|
143
145
|
|
|
144
146
|
async replaceNamedBytes(filename: string, bytes: Uint8Array): Promise<void> {
|
|
@@ -25,6 +25,155 @@ function escapeLikePattern(text: string): string {
|
|
|
25
25
|
return text.replace(/[\\%_]/g, "\\$&");
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
const HISTORY_SUFFIXES = ["", "-wal", "-shm"] as const;
|
|
29
|
+
let openingHistory: Database | undefined;
|
|
30
|
+
|
|
31
|
+
function secureHistoryPath(pathname: string, kind: "directory" | "file"): void {
|
|
32
|
+
if (process.platform !== "win32") return;
|
|
33
|
+
const native = require("@sayknow-cli/natives") as typeof import("@sayknow-cli/natives");
|
|
34
|
+
const applied = native.applyOwnerOnlyPathSecurity(pathname, kind);
|
|
35
|
+
const verified = native.verifyOwnerOnlyPathSecurity(pathname, kind);
|
|
36
|
+
if (applied?.ok !== true || verified?.ok !== true) {
|
|
37
|
+
throw new Error("history database owner-only protection could not be established");
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function historyErrno(error: unknown): string | undefined {
|
|
42
|
+
return (error as NodeJS.ErrnoException | undefined)?.code;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function historyLeaf(dbPath: string, suffix: string): fs.BigIntStats | undefined {
|
|
46
|
+
try {
|
|
47
|
+
return fs.lstatSync(`${dbPath}${suffix}`, { bigint: true });
|
|
48
|
+
} catch (error) {
|
|
49
|
+
if (historyErrno(error) !== "ENOENT") throw error;
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function assertRegularHistoryLeaf(existing: fs.BigIntStats | undefined): void {
|
|
55
|
+
if (existing && (existing.isSymbolicLink() || !existing.isFile())) {
|
|
56
|
+
throw new Error("history database path is not a regular file");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function assertHistoryLeaves(dbPath: string): Set<string> {
|
|
61
|
+
const present = new Set<string>();
|
|
62
|
+
for (const suffix of HISTORY_SUFFIXES) {
|
|
63
|
+
const existing = historyLeaf(dbPath, suffix);
|
|
64
|
+
assertRegularHistoryLeaf(existing);
|
|
65
|
+
if (existing) present.add(suffix);
|
|
66
|
+
}
|
|
67
|
+
return present;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function removeNewHistoryLeaves(): void {
|
|
71
|
+
// A WAL reader can stay live while BEGIN EXCLUSIVE succeeds, so failure
|
|
72
|
+
// cleanup must not unlink a database another opener has adopted.
|
|
73
|
+
try {
|
|
74
|
+
openingHistory?.close();
|
|
75
|
+
} catch {
|
|
76
|
+
// The caller reports the original open failure.
|
|
77
|
+
}
|
|
78
|
+
openingHistory = undefined;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function readHistoryDirectory(dir: string): fs.Stats | undefined {
|
|
82
|
+
let existing: fs.Stats;
|
|
83
|
+
try {
|
|
84
|
+
existing = fs.lstatSync(dir);
|
|
85
|
+
} catch (error) {
|
|
86
|
+
if (historyErrno(error) !== "ENOENT") throw error;
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
if (existing.isSymbolicLink() || !existing.isDirectory()) {
|
|
90
|
+
throw new Error("history database directory is not a real directory");
|
|
91
|
+
}
|
|
92
|
+
return existing;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function tightenHistoryDirectory(dir: string): void {
|
|
96
|
+
let existing = readHistoryDirectory(dir);
|
|
97
|
+
if (!existing) {
|
|
98
|
+
try {
|
|
99
|
+
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
100
|
+
} catch (error) {
|
|
101
|
+
if (historyErrno(error) !== "EEXIST") throw error;
|
|
102
|
+
}
|
|
103
|
+
existing = readHistoryDirectory(dir);
|
|
104
|
+
if (!existing) throw new Error("history database directory is not a real directory");
|
|
105
|
+
}
|
|
106
|
+
secureHistoryPath(dir, "directory");
|
|
107
|
+
if (process.platform === "win32") return;
|
|
108
|
+
// 0300/0700 are already owner-only. Sticky directories are shared and stay as they are.
|
|
109
|
+
// chmod(2) needs no read bit, so mode 0333 becomes 0700. A symlink swap is
|
|
110
|
+
// followed by chmod; the recheck then refuses and no database file is created.
|
|
111
|
+
if ((existing.mode & 0o077) === 0 || (existing.mode & 0o1000) !== 0) return;
|
|
112
|
+
try {
|
|
113
|
+
fs.chmodSync(dir, 0o700);
|
|
114
|
+
} catch (error) {
|
|
115
|
+
if (historyErrno(error) === "ELOOP") throw new Error("history database directory is not a real directory");
|
|
116
|
+
throw error;
|
|
117
|
+
}
|
|
118
|
+
const after = readHistoryDirectory(dir);
|
|
119
|
+
if (!after || (after.mode & 0o077) !== 0) {
|
|
120
|
+
throw new Error("history database directory could not be tightened to mode 0700");
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function sameHistoryFile(left: fs.BigIntStats, right: fs.BigIntStats): boolean {
|
|
125
|
+
return left.dev === right.dev && left.ino === right.ino && left.nlink === right.nlink;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function restrictHistoryFiles(dbPath: string, createMissingDb: boolean): void {
|
|
129
|
+
const noFollow = process.platform === "win32" ? 0 : (fs.constants.O_NOFOLLOW ?? 0);
|
|
130
|
+
for (const suffix of HISTORY_SUFFIXES) {
|
|
131
|
+
const target = `${dbPath}${suffix}`;
|
|
132
|
+
let existing = historyLeaf(dbPath, suffix);
|
|
133
|
+
assertRegularHistoryLeaf(existing);
|
|
134
|
+
if (!existing && suffix === "" && createMissingDb) {
|
|
135
|
+
let created: number | undefined;
|
|
136
|
+
try {
|
|
137
|
+
created = fs.openSync(
|
|
138
|
+
target,
|
|
139
|
+
fs.constants.O_WRONLY | fs.constants.O_CREAT | fs.constants.O_EXCL | noFollow,
|
|
140
|
+
0o600,
|
|
141
|
+
);
|
|
142
|
+
fs.fchmodSync(created, 0o600);
|
|
143
|
+
} catch (error) {
|
|
144
|
+
if (historyErrno(error) === "ELOOP") throw new Error("history database path is not a regular file");
|
|
145
|
+
if (historyErrno(error) !== "EEXIST") throw error;
|
|
146
|
+
} finally {
|
|
147
|
+
if (created !== undefined) fs.closeSync(created);
|
|
148
|
+
}
|
|
149
|
+
existing = historyLeaf(dbPath, suffix);
|
|
150
|
+
assertRegularHistoryLeaf(existing);
|
|
151
|
+
if (!existing) throw new Error("history database path is not a regular file");
|
|
152
|
+
}
|
|
153
|
+
if (!existing) continue;
|
|
154
|
+
secureHistoryPath(target, "file");
|
|
155
|
+
if (process.platform === "win32" || (Number(existing.mode) & 0o077) === 0) continue;
|
|
156
|
+
let fd: number | undefined;
|
|
157
|
+
try {
|
|
158
|
+
fd = fs.openSync(target, fs.constants.O_RDONLY | noFollow);
|
|
159
|
+
const opened = fs.fstatSync(fd, { bigint: true });
|
|
160
|
+
const again = historyLeaf(dbPath, suffix);
|
|
161
|
+
if (!again || !opened.isFile() || !sameHistoryFile(existing, opened) || !sameHistoryFile(opened, again)) {
|
|
162
|
+
throw new Error("history database path is not a regular file");
|
|
163
|
+
}
|
|
164
|
+
fs.fchmodSync(fd, 0o600);
|
|
165
|
+
if ((Number(fs.fstatSync(fd, { bigint: true }).mode) & 0o777) !== 0o600) {
|
|
166
|
+
throw new Error("history database path could not be tightened to mode 0600");
|
|
167
|
+
}
|
|
168
|
+
} catch (error) {
|
|
169
|
+
if (historyErrno(error) === "ELOOP") throw new Error("history database path is not a regular file");
|
|
170
|
+
throw error;
|
|
171
|
+
} finally {
|
|
172
|
+
if (fd !== undefined) fs.closeSync(fd);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
28
177
|
class AsyncDrain<T> {
|
|
29
178
|
#queue?: T[];
|
|
30
179
|
#promise = Promise.resolve();
|
|
@@ -80,9 +229,8 @@ export class HistoryStorage {
|
|
|
80
229
|
#lastPromptCache: string | null = null;
|
|
81
230
|
|
|
82
231
|
private constructor(dbPath: string) {
|
|
83
|
-
this.#ensureDir(dbPath);
|
|
84
|
-
|
|
85
232
|
this.#db = new Database(dbPath);
|
|
233
|
+
openingHistory = this.#db;
|
|
86
234
|
|
|
87
235
|
const hasFts = this.#db.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name='history_fts'").get();
|
|
88
236
|
|
|
@@ -137,11 +285,32 @@ CREATE TRIGGER IF NOT EXISTS history_ai AFTER INSERT ON history BEGIN
|
|
|
137
285
|
|
|
138
286
|
const last = this.#lastPromptStmt.get() as { prompt?: string } | undefined;
|
|
139
287
|
this.#lastPromptCache = last?.prompt ?? null;
|
|
288
|
+
try {
|
|
289
|
+
restrictHistoryFiles(dbPath, false);
|
|
290
|
+
} catch (error) {
|
|
291
|
+
this.#db.close();
|
|
292
|
+
throw error;
|
|
293
|
+
}
|
|
294
|
+
openingHistory = undefined;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
static #openNew(dbPath: string): HistoryStorage {
|
|
298
|
+
openingHistory = undefined;
|
|
299
|
+
assertHistoryLeaves(dbPath);
|
|
300
|
+
try {
|
|
301
|
+
tightenHistoryDirectory(path.dirname(dbPath));
|
|
302
|
+
assertHistoryLeaves(dbPath);
|
|
303
|
+
restrictHistoryFiles(dbPath, true);
|
|
304
|
+
return new HistoryStorage(dbPath);
|
|
305
|
+
} catch (error) {
|
|
306
|
+
removeNewHistoryLeaves();
|
|
307
|
+
throw error;
|
|
308
|
+
}
|
|
140
309
|
}
|
|
141
310
|
|
|
142
311
|
static open(dbPath: string = getHistoryDbPath()): HistoryStorage {
|
|
143
312
|
if (!HistoryStorage.#instance) {
|
|
144
|
-
HistoryStorage.#instance =
|
|
313
|
+
HistoryStorage.#instance = HistoryStorage.#openNew(dbPath);
|
|
145
314
|
}
|
|
146
315
|
return HistoryStorage.#instance;
|
|
147
316
|
}
|
|
@@ -241,11 +410,6 @@ CREATE TRIGGER IF NOT EXISTS history_ai AFTER INSERT ON history BEGIN
|
|
|
241
410
|
return merged;
|
|
242
411
|
}
|
|
243
412
|
|
|
244
|
-
#ensureDir(dbPath: string): void {
|
|
245
|
-
const dir = path.dirname(dbPath);
|
|
246
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
247
|
-
}
|
|
248
|
-
|
|
249
413
|
#historySchemaUsesUnixEpoch(): boolean {
|
|
250
414
|
const row = this.#db.prepare("SELECT sql FROM sqlite_master WHERE type = 'table' AND name = 'history'").get() as
|
|
251
415
|
| { sql?: string | null }
|
|
@@ -95,14 +95,22 @@ function bindManagedWriteAuthority(scope: ManagedScope, authority: ManagedCandid
|
|
|
95
95
|
function assertRetainedManagedDirectoryIdentity(scope: ManagedScope): void {
|
|
96
96
|
const expected = managedDirectoryIdentities.get(scope);
|
|
97
97
|
if (!expected) return;
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
98
|
+
assertSameManagedDirectoryIdentity(fs.lstatSync(scope.directoryPath, { bigint: true }), expected);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Fence a managed directory to the identity it was bound with. The decision is
|
|
103
|
+
* the same for every mismatch; only the reported reason differs. The same
|
|
104
|
+
* inode on a different `dev` is the shape a remount, drive-letter change or
|
|
105
|
+
* volume-serial change leaves behind (#6750). It is still refused, because an
|
|
106
|
+
* inode is only unique within one volume, but it is named so an operator is
|
|
107
|
+
* not sent looking for a corrupted binding.
|
|
108
|
+
*/
|
|
109
|
+
function assertSameManagedDirectoryIdentity(current: fs.BigIntStats, expected: { dev: bigint; ino: bigint }): void {
|
|
110
|
+
if (!current.isDirectory() || current.isSymbolicLink()) throw new Error("Managed session directory changed");
|
|
111
|
+
if (current.dev === expected.dev && current.ino === expected.ino) return;
|
|
112
|
+
if (current.ino === expected.ino) throw new Error("volume_identity_changed");
|
|
113
|
+
throw new Error("Managed session directory changed");
|
|
106
114
|
}
|
|
107
115
|
|
|
108
116
|
export function managedDirectoryAuthorityForScope(scope: ManagedScope): native.RecoveryFsRoot | undefined {
|
|
@@ -746,7 +754,8 @@ function listDirectoryCandidates(
|
|
|
746
754
|
try {
|
|
747
755
|
directoryStat = fs.lstatSync(directory);
|
|
748
756
|
} catch (error) {
|
|
749
|
-
|
|
757
|
+
const code = (error as NodeJS.ErrnoException).code;
|
|
758
|
+
if (code === "ENOENT" || (provenance === "legacy" && code === "ENAMETOOLONG")) return [];
|
|
750
759
|
throw error;
|
|
751
760
|
}
|
|
752
761
|
if (!directoryStat.isDirectory() || directoryStat.isSymbolicLink()) throw new Error("unsafe directory");
|
|
@@ -948,13 +957,7 @@ export function prepareManagedSessionScopeForWriteSync(
|
|
|
948
957
|
const validated = validateBindingRaw(scope, capturedBinding.bytes.toString("utf8"));
|
|
949
958
|
managedDirectoryAuthorities.set(scope, retainedAuthority);
|
|
950
959
|
const directoryStat = fs.lstatSync(scope.directoryPath, { bigint: true });
|
|
951
|
-
|
|
952
|
-
!directoryStat.isDirectory() ||
|
|
953
|
-
directoryStat.isSymbolicLink() ||
|
|
954
|
-
directoryStat.dev !== preparedDirectory.dev ||
|
|
955
|
-
directoryStat.ino !== preparedDirectory.ino
|
|
956
|
-
)
|
|
957
|
-
throw new Error("Managed session directory changed");
|
|
960
|
+
assertSameManagedDirectoryIdentity(directoryStat, preparedDirectory);
|
|
958
961
|
managedDirectoryIdentities.set(scope, { dev: preparedDirectory.dev, ino: preparedDirectory.ino });
|
|
959
962
|
if (validated) return validated;
|
|
960
963
|
const internal = managedInternalDirectory(scope);
|
|
@@ -1053,7 +1056,8 @@ export function listManagedCandidates(
|
|
|
1053
1056
|
}
|
|
1054
1057
|
}
|
|
1055
1058
|
}
|
|
1056
|
-
const
|
|
1059
|
+
const retired = owned.length > 0 ? retiredTargetKeys(scope) : new Set<string>();
|
|
1060
|
+
const visible = owned.filter(candidate => !isRetiredIn(retired, candidate));
|
|
1057
1061
|
const active = visible.filter(
|
|
1058
1062
|
candidate =>
|
|
1059
1063
|
candidate.provenance === "v2" ||
|
|
@@ -2158,8 +2162,96 @@ function tombstonePathContaining(scope: ManagedScope, candidate: ManagedCandidat
|
|
|
2158
2162
|
return undefined;
|
|
2159
2163
|
}
|
|
2160
2164
|
|
|
2161
|
-
|
|
2165
|
+
/**
|
|
2166
|
+
* Identity fields a retired tombstone target must match exactly for a candidate
|
|
2167
|
+
* to be hidden. `dev`, `ino`, and `mtimeNs` are persisted as decimal strings.
|
|
2168
|
+
*/
|
|
2169
|
+
type RetiredTargetIdentity = readonly [
|
|
2170
|
+
path: string,
|
|
2171
|
+
sessionId: string,
|
|
2172
|
+
cwd: string,
|
|
2173
|
+
canonicalPath: string,
|
|
2174
|
+
dev: string,
|
|
2175
|
+
ino: string,
|
|
2176
|
+
size: number,
|
|
2177
|
+
mtimeNs: string,
|
|
2178
|
+
sha256: string,
|
|
2179
|
+
];
|
|
2180
|
+
|
|
2181
|
+
function candidateRetiredIdentity(candidate: ManagedCandidate): RetiredTargetIdentity {
|
|
2182
|
+
return [
|
|
2183
|
+
candidate.path,
|
|
2184
|
+
candidate.sessionId,
|
|
2185
|
+
candidate.cwd,
|
|
2186
|
+
candidate.identity.canonicalPath,
|
|
2187
|
+
String(candidate.identity.dev),
|
|
2188
|
+
String(candidate.identity.ino),
|
|
2189
|
+
candidate.identity.size,
|
|
2190
|
+
String(candidate.identity.mtimeNs),
|
|
2191
|
+
candidate.identity.sha256,
|
|
2192
|
+
];
|
|
2193
|
+
}
|
|
2194
|
+
|
|
2195
|
+
/** Returns the target's identity only when every field has the type a candidate can carry. */
|
|
2196
|
+
function parseRetiredTargetIdentity(target: unknown): RetiredTargetIdentity | undefined {
|
|
2197
|
+
if (!target || typeof target !== "object") return undefined;
|
|
2198
|
+
const value = target as { path?: unknown; sessionId?: unknown; cwd?: unknown; identity?: unknown };
|
|
2199
|
+
if (!value.identity || typeof value.identity !== "object") return undefined;
|
|
2200
|
+
const identity = value.identity as {
|
|
2201
|
+
canonicalPath?: unknown;
|
|
2202
|
+
dev?: unknown;
|
|
2203
|
+
ino?: unknown;
|
|
2204
|
+
size?: unknown;
|
|
2205
|
+
mtimeNs?: unknown;
|
|
2206
|
+
sha256?: unknown;
|
|
2207
|
+
};
|
|
2208
|
+
if (
|
|
2209
|
+
typeof value.path !== "string" ||
|
|
2210
|
+
typeof value.sessionId !== "string" ||
|
|
2211
|
+
typeof value.cwd !== "string" ||
|
|
2212
|
+
typeof identity.canonicalPath !== "string" ||
|
|
2213
|
+
typeof identity.dev !== "string" ||
|
|
2214
|
+
typeof identity.ino !== "string" ||
|
|
2215
|
+
typeof identity.size !== "number" ||
|
|
2216
|
+
typeof identity.mtimeNs !== "string" ||
|
|
2217
|
+
typeof identity.sha256 !== "string"
|
|
2218
|
+
)
|
|
2219
|
+
return undefined;
|
|
2220
|
+
return [
|
|
2221
|
+
value.path,
|
|
2222
|
+
value.sessionId,
|
|
2223
|
+
value.cwd,
|
|
2224
|
+
identity.canonicalPath,
|
|
2225
|
+
identity.dev,
|
|
2226
|
+
identity.ino,
|
|
2227
|
+
identity.size,
|
|
2228
|
+
identity.mtimeNs,
|
|
2229
|
+
identity.sha256,
|
|
2230
|
+
];
|
|
2231
|
+
}
|
|
2232
|
+
|
|
2233
|
+
/**
|
|
2234
|
+
* Key equality matches strict equality of every member: strings and finite
|
|
2235
|
+
* numbers encode distinctly. A non-finite tombstone `size` encodes as `null`,
|
|
2236
|
+
* which no candidate produces.
|
|
2237
|
+
*/
|
|
2238
|
+
function retiredIdentityKey(identity: RetiredTargetIdentity): string {
|
|
2239
|
+
return JSON.stringify(identity);
|
|
2240
|
+
}
|
|
2241
|
+
|
|
2242
|
+
/**
|
|
2243
|
+
* Snapshot of the identities retired by a scope's tombstones.
|
|
2244
|
+
*
|
|
2245
|
+
* Tombstones are visited in directory order and the walk stops at the first
|
|
2246
|
+
* unreadable or malformed one: it grants no retirement authority, and neither do
|
|
2247
|
+
* the tombstones after it. Listing builds this once and checks every candidate
|
|
2248
|
+
* against it, so its cost is linear in tombstones rather than in
|
|
2249
|
+
* candidates x tombstones.
|
|
2250
|
+
*/
|
|
2251
|
+
function retiredTargetKeys(scope: ManagedScope): ReadonlySet<string> {
|
|
2252
|
+
const keys = new Set<string>();
|
|
2162
2253
|
const directory = path.join(managedInternalDirectory(scope), MANAGED_TOMBSTONES_DIRECTORY);
|
|
2254
|
+
const digest = scopeDigest(scope.platform, scope.canonicalCwd);
|
|
2163
2255
|
try {
|
|
2164
2256
|
for (const name of fs.readdirSync(directory)) {
|
|
2165
2257
|
const pathname = path.join(directory, name);
|
|
@@ -2169,47 +2261,27 @@ function isRetired(scope: ManagedScope, candidate: ManagedCandidate): boolean {
|
|
|
2169
2261
|
if (
|
|
2170
2262
|
record.schemaVersion !== 2 ||
|
|
2171
2263
|
record.state !== "retired" ||
|
|
2172
|
-
record.scope !==
|
|
2264
|
+
record.scope !== digest ||
|
|
2173
2265
|
!Array.isArray(record.targets)
|
|
2174
2266
|
)
|
|
2175
2267
|
continue;
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
path?: unknown;
|
|
2181
|
-
sessionId?: unknown;
|
|
2182
|
-
cwd?: unknown;
|
|
2183
|
-
identity?: {
|
|
2184
|
-
canonicalPath?: unknown;
|
|
2185
|
-
dev?: unknown;
|
|
2186
|
-
ino?: unknown;
|
|
2187
|
-
size?: unknown;
|
|
2188
|
-
mtimeNs?: unknown;
|
|
2189
|
-
sha256?: unknown;
|
|
2190
|
-
};
|
|
2191
|
-
};
|
|
2192
|
-
const identity = value.identity;
|
|
2193
|
-
if (!identity) return false;
|
|
2194
|
-
return (
|
|
2195
|
-
value.path === candidate.path &&
|
|
2196
|
-
value.sessionId === candidate.sessionId &&
|
|
2197
|
-
value.cwd === candidate.cwd &&
|
|
2198
|
-
identity.canonicalPath === candidate.identity.canonicalPath &&
|
|
2199
|
-
identity.dev === String(candidate.identity.dev) &&
|
|
2200
|
-
identity.ino === String(candidate.identity.ino) &&
|
|
2201
|
-
identity.size === candidate.identity.size &&
|
|
2202
|
-
identity.mtimeNs === String(candidate.identity.mtimeNs) &&
|
|
2203
|
-
identity.sha256 === candidate.identity.sha256
|
|
2204
|
-
);
|
|
2205
|
-
})
|
|
2206
|
-
)
|
|
2207
|
-
return true;
|
|
2268
|
+
for (const target of record.targets) {
|
|
2269
|
+
const identity = parseRetiredTargetIdentity(target);
|
|
2270
|
+
if (identity) keys.add(retiredIdentityKey(identity));
|
|
2271
|
+
}
|
|
2208
2272
|
}
|
|
2209
2273
|
} catch {
|
|
2210
2274
|
/* a missing/malformed tombstone grants no retirement authority */
|
|
2211
2275
|
}
|
|
2212
|
-
return
|
|
2276
|
+
return keys;
|
|
2277
|
+
}
|
|
2278
|
+
|
|
2279
|
+
function isRetiredIn(retired: ReadonlySet<string>, candidate: ManagedCandidate): boolean {
|
|
2280
|
+
return retired.has(retiredIdentityKey(candidateRetiredIdentity(candidate)));
|
|
2281
|
+
}
|
|
2282
|
+
|
|
2283
|
+
function isRetired(scope: ManagedScope, candidate: ManagedCandidate): boolean {
|
|
2284
|
+
return isRetiredIn(retiredTargetKeys(scope), candidate);
|
|
2213
2285
|
}
|
|
2214
2286
|
|
|
2215
2287
|
type ArtifactManifestEntry =
|
|
@@ -2868,6 +2940,12 @@ export async function reconcileManagedTombstones(
|
|
|
2868
2940
|
expectedCandidate?: ManagedCandidate,
|
|
2869
2941
|
): Promise<void> {
|
|
2870
2942
|
const directory = path.join(managedInternalDirectory(scope), MANAGED_TOMBSTONES_DIRECTORY);
|
|
2943
|
+
// Ensure scope authority is prepared before any operations that might access the GC protocol
|
|
2944
|
+
const prepared = await ensureManagedScope(
|
|
2945
|
+
scope,
|
|
2946
|
+
scope.platform === "win32" ? "windows-existing-verify-first" : "default",
|
|
2947
|
+
);
|
|
2948
|
+
if (prepared.kind === "error") throw new Error(prepared.message);
|
|
2871
2949
|
for (const name of fs.readdirSync(directory)) {
|
|
2872
2950
|
const tombstone = path.join(directory, name);
|
|
2873
2951
|
const targets = retiredTargets(scope, tombstone);
|
package/src/session/messages.ts
CHANGED
|
@@ -218,6 +218,34 @@ function getPrunedToolResultContent(message: ToolResultMessage): (TextContent |
|
|
|
218
218
|
export const PRE_ADMISSION_ARTIFACT_SPILL_HEAD_BYTES = 4096;
|
|
219
219
|
export const PRE_ADMISSION_ARTIFACT_SPILL_TAIL_BYTES = 4096;
|
|
220
220
|
|
|
221
|
+
/**
|
|
222
|
+
* Keep an authenticated `#SKC1_` placeholder whole when the byte cut lands
|
|
223
|
+
* inside it. Short inputs whose head and tail already overlap stay on the
|
|
224
|
+
* original byte limits.
|
|
225
|
+
*/
|
|
226
|
+
function retainStraddlingPlaceholders(text: string, head: string, tail: string): { head: string; tail: string } {
|
|
227
|
+
const headEnd = head.length;
|
|
228
|
+
const tailStart = text.length - tail.length;
|
|
229
|
+
if (headEnd > tailStart) return { head, tail };
|
|
230
|
+
|
|
231
|
+
let nextHeadEnd = headEnd;
|
|
232
|
+
let nextTailStart = tailStart;
|
|
233
|
+
const placeholder = /#SKC1_[A-Za-z0-9_-]{22}#/g;
|
|
234
|
+
for (;;) {
|
|
235
|
+
const match = placeholder.exec(text);
|
|
236
|
+
if (match === null) break;
|
|
237
|
+
const start = match.index;
|
|
238
|
+
const stop = start + match[0].length;
|
|
239
|
+
if (start < headEnd && stop > headEnd) nextHeadEnd = Math.max(nextHeadEnd, stop);
|
|
240
|
+
if (start < tailStart && stop > tailStart) nextTailStart = Math.min(nextTailStart, start);
|
|
241
|
+
}
|
|
242
|
+
if (nextHeadEnd > nextTailStart) return { head, tail };
|
|
243
|
+
return {
|
|
244
|
+
head: nextHeadEnd === headEnd ? head : text.slice(0, nextHeadEnd),
|
|
245
|
+
tail: nextTailStart === tailStart ? tail : text.slice(nextTailStart),
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
|
|
221
249
|
function utf8Prefix(text: string, maxBytes: number): string {
|
|
222
250
|
if (Buffer.byteLength(text, "utf-8") <= maxBytes) return text;
|
|
223
251
|
let bytes = 0;
|
|
@@ -253,15 +281,28 @@ function utf8Suffix(text: string, maxBytes: number): string {
|
|
|
253
281
|
* Build the deterministic inline receipt for a tool result saved before the
|
|
254
282
|
* next provider context is constructed. Byte boundaries never split UTF-8
|
|
255
283
|
* code points, so head/tail recovery remains readable for emoji and CJK text.
|
|
284
|
+
*
|
|
285
|
+
* `redact` runs on the complete text before the cut. The digest stays the
|
|
286
|
+
* caller's hash of the stored artifact; the omitted count is the redacted
|
|
287
|
+
* preview's omitted bytes.
|
|
256
288
|
*/
|
|
257
|
-
export function createPreAdmissionArtifactSpillPreview(
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
289
|
+
export function createPreAdmissionArtifactSpillPreview(
|
|
290
|
+
fullText: string,
|
|
291
|
+
artifactId: string,
|
|
292
|
+
digest: string,
|
|
293
|
+
redact?: (text: string) => string,
|
|
294
|
+
): string {
|
|
295
|
+
const source = redact ? redact(fullText) : fullText;
|
|
296
|
+
const totalBytes = Buffer.byteLength(source, "utf-8");
|
|
297
|
+
const head = utf8Prefix(source, PRE_ADMISSION_ARTIFACT_SPILL_HEAD_BYTES);
|
|
298
|
+
const tail = utf8Suffix(source, PRE_ADMISSION_ARTIFACT_SPILL_TAIL_BYTES);
|
|
299
|
+
// Without redaction the cut stays on the historical byte limits, including
|
|
300
|
+
// when the tool text itself contains a placeholder-shaped string.
|
|
301
|
+
const retained = redact ? retainStraddlingPlaceholders(source, head, tail) : { head, tail };
|
|
302
|
+
const retainedBytes = Buffer.byteLength(retained.head, "utf-8") + Buffer.byteLength(retained.tail, "utf-8");
|
|
262
303
|
const omittedBytes = Math.max(0, totalBytes - retainedBytes);
|
|
263
304
|
const receipt = `[${omittedBytes} bytes omitted; sha256:${digest}; full output: artifact://${artifactId}]`;
|
|
264
|
-
return `${head}\n\n${receipt}\n\n${tail}`;
|
|
305
|
+
return `${retained.head}\n\n${receipt}\n\n${retained.tail}`;
|
|
265
306
|
}
|
|
266
307
|
|
|
267
308
|
/**
|