@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
|
@@ -1845,7 +1845,15 @@ function isLinkedWorktreePeer(a: string, b: string): boolean {
|
|
|
1845
1845
|
* Read the terminal breadcrumb for the current terminal, scoped to a cwd.
|
|
1846
1846
|
* Returns the session file path if it exists and matches the cwd, null otherwise.
|
|
1847
1847
|
*/
|
|
1848
|
-
async function readTerminalBreadcrumb(
|
|
1848
|
+
async function readTerminalBreadcrumb(
|
|
1849
|
+
cwd: string,
|
|
1850
|
+
options: {
|
|
1851
|
+
sessionsRoot?: string;
|
|
1852
|
+
allowExplicitOutsideRoot?: boolean;
|
|
1853
|
+
/** Managed continuation inventory, including project-local transcripts. */
|
|
1854
|
+
continuationInventory?: readonly SessionInfo[];
|
|
1855
|
+
} = {},
|
|
1856
|
+
): Promise<string | null> {
|
|
1849
1857
|
const terminalId = getTerminalId();
|
|
1850
1858
|
if (!terminalId) return null;
|
|
1851
1859
|
|
|
@@ -1866,9 +1874,9 @@ async function readTerminalBreadcrumb(cwd: string): Promise<string | null> {
|
|
|
1866
1874
|
}
|
|
1867
1875
|
|
|
1868
1876
|
const inspected = inspectResumeSessionFile(sessionFile, new FileSessionStorage());
|
|
1877
|
+
const sessionsRoot = options.sessionsRoot ?? getSessionsDir();
|
|
1869
1878
|
if ("kind" in inspected) {
|
|
1870
1879
|
if (inspected.reason !== "missing") return null;
|
|
1871
|
-
const sessionsRoot = getSessionsDir();
|
|
1872
1880
|
const resolved = resolveManagedScope({
|
|
1873
1881
|
cwd: breadcrumbCwd,
|
|
1874
1882
|
agentDir: path.resolve(sessionsRoot, ".."),
|
|
@@ -1884,7 +1892,6 @@ async function readTerminalBreadcrumb(cwd: string): Promise<string | null> {
|
|
|
1884
1892
|
}
|
|
1885
1893
|
const header = inspected.entries[0] as SessionHeader;
|
|
1886
1894
|
if (resolveEquivalentPath(header.cwd) !== resolveEquivalentPath(breadcrumbCwd)) return null;
|
|
1887
|
-
const sessionsRoot = getSessionsDir();
|
|
1888
1895
|
const resolved = resolveManagedScope({
|
|
1889
1896
|
cwd: header.cwd,
|
|
1890
1897
|
agentDir: path.resolve(sessionsRoot, ".."),
|
|
@@ -1897,7 +1904,22 @@ async function readTerminalBreadcrumb(cwd: string): Promise<string | null> {
|
|
|
1897
1904
|
if (exact) return exact.path;
|
|
1898
1905
|
const byIdentity = listing.owned.find(candidate => candidate.sessionId === header.id);
|
|
1899
1906
|
if (byIdentity) return byIdentity.path;
|
|
1900
|
-
|
|
1907
|
+
// Not an owned managed candidate. A file inside the sessions root stays
|
|
1908
|
+
// rejected. A file outside that root is resumed only when this continuation
|
|
1909
|
+
// inventory already contains it. An explicit destination still receives an
|
|
1910
|
+
// unmatched outside path; the caller applies containment.
|
|
1911
|
+
const resolvedFile = path.resolve(sessionFile);
|
|
1912
|
+
const insideSessionsRoot = pathIsWithin(sessionsRoot, resolvedFile);
|
|
1913
|
+
if (
|
|
1914
|
+
!insideSessionsRoot &&
|
|
1915
|
+
options.continuationInventory?.some(
|
|
1916
|
+
session => session.id === header.id && path.resolve(session.path) === resolvedFile,
|
|
1917
|
+
)
|
|
1918
|
+
) {
|
|
1919
|
+
return resolvedFile;
|
|
1920
|
+
}
|
|
1921
|
+
if (!options.allowExplicitOutsideRoot || insideSessionsRoot) return null;
|
|
1922
|
+
return resolvedFile;
|
|
1901
1923
|
} catch (err) {
|
|
1902
1924
|
if (!isEnoent(err)) logger.debug("Terminal breadcrumb read failed", { err });
|
|
1903
1925
|
// Breadcrumb doesn't exist or is corrupt — fall through
|
|
@@ -2824,6 +2846,9 @@ function externalizeResidentValueSync(obj: unknown, stores: ResidentBlobStores,
|
|
|
2824
2846
|
return changed ? result : obj;
|
|
2825
2847
|
}
|
|
2826
2848
|
if (typeof obj === "object") {
|
|
2849
|
+
// Signed reasoning replays byte-for-byte; keep it inline so a lost cache
|
|
2850
|
+
// file can never turn it into placeholder text under a valid signature.
|
|
2851
|
+
if (isSignedReasoningBlock(obj)) return obj;
|
|
2827
2852
|
let changed = false;
|
|
2828
2853
|
const entries: Array<readonly [string, unknown]> = [];
|
|
2829
2854
|
for (const [childKey, value] of Object.entries(obj)) {
|
|
@@ -2840,6 +2865,34 @@ function prepareEntryForResidentSync(entry: FileEntry, stores: ResidentBlobStore
|
|
|
2840
2865
|
return externalizeResidentValueSync(entry, stores) as FileEntry;
|
|
2841
2866
|
}
|
|
2842
2867
|
|
|
2868
|
+
/**
|
|
2869
|
+
* Thinking and redacted-thinking blocks: providers verify their text against a
|
|
2870
|
+
* signature (Anthropic) or treat it as opaque replay data, so the bytes cannot
|
|
2871
|
+
* be substituted.
|
|
2872
|
+
*/
|
|
2873
|
+
function isSignedReasoningBlock(obj: object): boolean {
|
|
2874
|
+
const type = (obj as { type?: unknown }).type;
|
|
2875
|
+
return type === "thinking" || type === "redactedThinking";
|
|
2876
|
+
}
|
|
2877
|
+
|
|
2878
|
+
/**
|
|
2879
|
+
* Reasoning whose resident blob is gone (sessions written before reasoning was
|
|
2880
|
+
* kept inline). The original bytes are unrecoverable, so drop the text and the
|
|
2881
|
+
* signature together: an empty unsigned block is skipped on replay, while
|
|
2882
|
+
* placeholder text under the original signature is rejected by the provider
|
|
2883
|
+
* (`Invalid signature in thinking block`) on every later request.
|
|
2884
|
+
*/
|
|
2885
|
+
function withoutLostReasoning(obj: object): object {
|
|
2886
|
+
if ((obj as { type?: unknown }).type === "redactedThinking") return { type: "redactedThinking", data: "" };
|
|
2887
|
+
const kept: Record<string, unknown> = { type: "thinking", thinking: "" };
|
|
2888
|
+
for (const [childKey, value] of Object.entries(obj)) {
|
|
2889
|
+
if (childKey === "type" || childKey === "thinking" || childKey === "thinkingSignature") continue;
|
|
2890
|
+
if (isResidentBlobSentinel(value)) continue;
|
|
2891
|
+
kept[childKey] = value;
|
|
2892
|
+
}
|
|
2893
|
+
return kept;
|
|
2894
|
+
}
|
|
2895
|
+
|
|
2843
2896
|
function materializeResidentValueSync(
|
|
2844
2897
|
obj: unknown,
|
|
2845
2898
|
stores: ResidentBlobStores,
|
|
@@ -2882,6 +2935,14 @@ function materializeResidentValueSync(
|
|
|
2882
2935
|
return changed ? result : obj;
|
|
2883
2936
|
}
|
|
2884
2937
|
if (typeof obj === "object") {
|
|
2938
|
+
if (missingPolicy === "placeholder" && isSignedReasoningBlock(obj)) {
|
|
2939
|
+
try {
|
|
2940
|
+
return materializeResidentValueSync(obj, stores, key, cache, "throw");
|
|
2941
|
+
} catch (err) {
|
|
2942
|
+
if (!(err instanceof ResidentBlobMissingError)) throw err;
|
|
2943
|
+
return withoutLostReasoning(obj);
|
|
2944
|
+
}
|
|
2945
|
+
}
|
|
2885
2946
|
let changed = false;
|
|
2886
2947
|
const entries = Object.entries(obj).map(([childKey, value]) => {
|
|
2887
2948
|
const newValue = materializeResidentValueSync(value, stores, childKey, cache, missingPolicy);
|
|
@@ -3070,7 +3131,17 @@ function coldSpillResidentValue(
|
|
|
3070
3131
|
writes: ColdSpillWrite[],
|
|
3071
3132
|
promotion: ColdSpillResidentPromotion,
|
|
3072
3133
|
): string {
|
|
3073
|
-
|
|
3134
|
+
// Spilled history is already covered by a compaction summary and never reaches
|
|
3135
|
+
// the provider again. A missing resident blob is unrecoverable either way;
|
|
3136
|
+
// failing here only blocked every later compaction, so the session could never
|
|
3137
|
+
// drop the damaged history.
|
|
3138
|
+
let data: Buffer;
|
|
3139
|
+
try {
|
|
3140
|
+
data = residentBlobBytesForColdSpill(value, promotion);
|
|
3141
|
+
} catch (err) {
|
|
3142
|
+
if (!(err instanceof ResidentBlobMissingError)) throw err;
|
|
3143
|
+
data = Buffer.from(residentBlobMissingPlaceholder(err), "utf8");
|
|
3144
|
+
}
|
|
3074
3145
|
writes.push({ path: basePath, encoding: "utf8", data, originalChars: data.byteLength });
|
|
3075
3146
|
return COLD_SPILL_NOTICE;
|
|
3076
3147
|
}
|
|
@@ -3972,6 +4043,68 @@ const SESSION_LIST_MAX_WORKERS = 16;
|
|
|
3972
4043
|
const sessionListPrefixDecoder = new TextDecoder("utf-8", { fatal: false });
|
|
3973
4044
|
let residentCacheInstanceCounter = 0;
|
|
3974
4045
|
|
|
4046
|
+
/** Nearest real directory at or above `start`. A file or missing path is not a root. */
|
|
4047
|
+
function nearestExistingDirectory(start: string): string | null {
|
|
4048
|
+
let current = path.resolve(start);
|
|
4049
|
+
for (let depth = 0; depth < 64; depth++) {
|
|
4050
|
+
try {
|
|
4051
|
+
if (fs.lstatSync(current).isDirectory()) return current;
|
|
4052
|
+
} catch {
|
|
4053
|
+
// Missing components are not worktree roots.
|
|
4054
|
+
}
|
|
4055
|
+
const parent = path.dirname(current);
|
|
4056
|
+
if (parent === current) return null;
|
|
4057
|
+
current = parent;
|
|
4058
|
+
}
|
|
4059
|
+
return null;
|
|
4060
|
+
}
|
|
4061
|
+
|
|
4062
|
+
/**
|
|
4063
|
+
* Canonical path of `start`, following a symlink ancestor. The unmatched suffix
|
|
4064
|
+
* is appended so a not-yet-created cache directory classifies the directory the
|
|
4065
|
+
* blob store would create it in.
|
|
4066
|
+
*/
|
|
4067
|
+
function canonicalCachePath(start: string): string | null {
|
|
4068
|
+
let current = path.resolve(start);
|
|
4069
|
+
const pending: string[] = [];
|
|
4070
|
+
for (let depth = 0; depth < 64; depth++) {
|
|
4071
|
+
try {
|
|
4072
|
+
const stat = fs.lstatSync(current);
|
|
4073
|
+
if (stat.isDirectory() || stat.isSymbolicLink()) {
|
|
4074
|
+
const real = fs.realpathSync(current);
|
|
4075
|
+
return pending.length === 0 ? real : path.join(real, ...pending.reverse());
|
|
4076
|
+
}
|
|
4077
|
+
} catch {
|
|
4078
|
+
// Missing components are resolved from the nearest existing ancestor.
|
|
4079
|
+
}
|
|
4080
|
+
const parent = path.dirname(current);
|
|
4081
|
+
if (parent === current) return null;
|
|
4082
|
+
pending.push(path.basename(current));
|
|
4083
|
+
current = parent;
|
|
4084
|
+
}
|
|
4085
|
+
return null;
|
|
4086
|
+
}
|
|
4087
|
+
|
|
4088
|
+
/**
|
|
4089
|
+
* Resident text is a second plaintext copy of assistant and tool output. A cache
|
|
4090
|
+
* directory inside a Git worktree can be staged by a later `git add`, so that
|
|
4091
|
+
* cache stays in memory. Both the lexical and the canonical directory are
|
|
4092
|
+
* classified: a symlink outside the worktree must not hide a target inside it.
|
|
4093
|
+
* No existing directory within 64 ancestors, or a resolver error, stays in memory.
|
|
4094
|
+
*/
|
|
4095
|
+
export function residentTextCacheRootAllowsDisk(cacheRoot: string): boolean {
|
|
4096
|
+
try {
|
|
4097
|
+
const lexical = nearestExistingDirectory(cacheRoot);
|
|
4098
|
+
if (lexical === null || git.repo.resolveSync(lexical) !== null) return false;
|
|
4099
|
+
const canonical = canonicalCachePath(cacheRoot);
|
|
4100
|
+
if (canonical === null) return false;
|
|
4101
|
+
const canonicalDirectory = nearestExistingDirectory(canonical);
|
|
4102
|
+
return canonicalDirectory !== null && git.repo.resolveSync(canonicalDirectory) === null;
|
|
4103
|
+
} catch {
|
|
4104
|
+
return false;
|
|
4105
|
+
}
|
|
4106
|
+
}
|
|
4107
|
+
|
|
3975
4108
|
async function readSessionListPrefix(file: string, storage: SessionStorage, buffer: Buffer): Promise<string> {
|
|
3976
4109
|
if (!(storage instanceof FileSessionStorage)) {
|
|
3977
4110
|
return storage.readTextPrefix(file, buffer.byteLength);
|
|
@@ -4312,6 +4445,17 @@ function sessionMatchesResumeArg(session: SessionInfo, sessionArg: string): bool
|
|
|
4312
4445
|
return fileSessionId.startsWith(normalizedArg);
|
|
4313
4446
|
}
|
|
4314
4447
|
|
|
4448
|
+
/**
|
|
4449
|
+
* Equal session id first, the same `id ===` check managed resume already uses.
|
|
4450
|
+
* Prefix matching stays for every other argument, in list order.
|
|
4451
|
+
*/
|
|
4452
|
+
export function pickResumableSession(sessions: readonly SessionInfo[], sessionArg: string): SessionInfo | undefined {
|
|
4453
|
+
return (
|
|
4454
|
+
sessions.find(session => session.id === sessionArg) ??
|
|
4455
|
+
sessions.find(session => sessionMatchesResumeArg(session, sessionArg))
|
|
4456
|
+
);
|
|
4457
|
+
}
|
|
4458
|
+
|
|
4315
4459
|
export async function resolveResumableSession(
|
|
4316
4460
|
sessionArg: string,
|
|
4317
4461
|
cwd: string,
|
|
@@ -4322,7 +4466,7 @@ export async function resolveResumableSession(
|
|
|
4322
4466
|
const localSessions = sessionDir
|
|
4323
4467
|
? await SessionManager.list(cwd, sessionDir, storage)
|
|
4324
4468
|
: await SessionManager.listManagedForResumePickerReadOnly(cwd, managedAgentDir, storage);
|
|
4325
|
-
const localMatch = localSessions
|
|
4469
|
+
const localMatch = pickResumableSession(localSessions, sessionArg);
|
|
4326
4470
|
if (localMatch) {
|
|
4327
4471
|
return { session: localMatch, scope: "local" };
|
|
4328
4472
|
}
|
|
@@ -4332,7 +4476,7 @@ export async function resolveResumableSession(
|
|
|
4332
4476
|
}
|
|
4333
4477
|
|
|
4334
4478
|
const globalSessions = await SessionManager.listAll(storage, managedAgentDir);
|
|
4335
|
-
const globalMatch = globalSessions
|
|
4479
|
+
const globalMatch = pickResumableSession(globalSessions, sessionArg);
|
|
4336
4480
|
if (!globalMatch) {
|
|
4337
4481
|
return undefined;
|
|
4338
4482
|
}
|
|
@@ -4559,7 +4703,12 @@ export class SessionManager {
|
|
|
4559
4703
|
this.#sessionFile &&
|
|
4560
4704
|
this.storage instanceof FileSessionStorage
|
|
4561
4705
|
) {
|
|
4562
|
-
|
|
4706
|
+
const cacheDir = this.#residentCacheDir(this.#sessionFile);
|
|
4707
|
+
// The fork keeps the resident cache next to the session file. A session
|
|
4708
|
+
// directory inside a Git worktree keeps resident text in memory instead.
|
|
4709
|
+
if (residentTextCacheRootAllowsDisk(cacheDir)) {
|
|
4710
|
+
this.#residentTextBlobStore = new EphemeralBlobStore(cacheDir);
|
|
4711
|
+
}
|
|
4563
4712
|
}
|
|
4564
4713
|
}
|
|
4565
4714
|
|
|
@@ -5292,7 +5441,10 @@ export class SessionManager {
|
|
|
5292
5441
|
const oldSessionFile = this.#sessionFile;
|
|
5293
5442
|
const oldSessionId = this.#sessionId;
|
|
5294
5443
|
const materializedEntries = materializeResidentEntriesForReadSync(this.#fileEntries, this.#residentBlobStores());
|
|
5295
|
-
|
|
5444
|
+
// Roll back from materialized text: the live entries hold resident sentinels
|
|
5445
|
+
// into the store that the fork disposes, so restoring them as-is would leave
|
|
5446
|
+
// every large string (and signed thinking) pointing at a deleted blob.
|
|
5447
|
+
const oldFileEntries = materializedEntries;
|
|
5296
5448
|
const oldSessionName = this.#sessionName;
|
|
5297
5449
|
const oldTitleSource = this.#titleSource;
|
|
5298
5450
|
|
|
@@ -9346,7 +9498,15 @@ export class SessionManager {
|
|
|
9346
9498
|
storage,
|
|
9347
9499
|
);
|
|
9348
9500
|
|
|
9349
|
-
const terminalSession = await readTerminalBreadcrumb(cwd
|
|
9501
|
+
const terminalSession = await readTerminalBreadcrumb(cwd, {
|
|
9502
|
+
...(destination.kind === "managed"
|
|
9503
|
+
? {
|
|
9504
|
+
sessionsRoot: destination.securityContext.sessionsRoot,
|
|
9505
|
+
continuationInventory: managedCandidates,
|
|
9506
|
+
}
|
|
9507
|
+
: {}),
|
|
9508
|
+
allowExplicitOutsideRoot: destination.kind === "explicit",
|
|
9509
|
+
});
|
|
9350
9510
|
const terminalSessionIsInExplicitRoot = (() => {
|
|
9351
9511
|
if (destination.kind === "managed" || !terminalSession) return destination.kind === "managed";
|
|
9352
9512
|
const canonicalRoot = canonicalizeTrustedPath(destination.directory);
|
|
@@ -480,6 +480,35 @@ function secureOwnerOnlyFileDescriptor(
|
|
|
480
480
|
if (!result.ok) throw new Error(`Owner-only security rejected ${pathname}: ${result.code}`);
|
|
481
481
|
}
|
|
482
482
|
|
|
483
|
+
/**
|
|
484
|
+
* Replace an explicit file owned by this user. Creation mode `0600` does not
|
|
485
|
+
* install a Windows owner-only DACL, so this applies and verifies the same
|
|
486
|
+
* native path a primary transcript uses when it has no managed security
|
|
487
|
+
* context. POSIX mode stays `0600`, and a final-component symlink fails the
|
|
488
|
+
* open (`O_NOFOLLOW`).
|
|
489
|
+
*/
|
|
490
|
+
export function writeExplicitOwnerOnlyTextSync(pathname: string, content: string): void {
|
|
491
|
+
const fd = fs.openSync(
|
|
492
|
+
pathname,
|
|
493
|
+
fs.constants.O_WRONLY | fs.constants.O_CREAT | (fs.constants.O_NOFOLLOW ?? 0),
|
|
494
|
+
0o600,
|
|
495
|
+
);
|
|
496
|
+
try {
|
|
497
|
+
secureOwnerOnlyFileDescriptor(pathname, fd, "apply", undefined);
|
|
498
|
+
fs.ftruncateSync(fd, 0);
|
|
499
|
+
const bytes = Buffer.from(content, "utf8");
|
|
500
|
+
let offset = 0;
|
|
501
|
+
while (offset < bytes.byteLength) {
|
|
502
|
+
const written = fs.writeSync(fd, bytes, offset, bytes.byteLength - offset);
|
|
503
|
+
if (written === 0) throw new Error("Short write");
|
|
504
|
+
offset += written;
|
|
505
|
+
}
|
|
506
|
+
secureOwnerOnlyFileDescriptor(pathname, fd, "verify", undefined);
|
|
507
|
+
} finally {
|
|
508
|
+
fs.closeSync(fd);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
|
|
483
512
|
/** Reject a symlink/junction/reparse component before a storage path is created or opened. */
|
|
484
513
|
function assertNoReparsePath(pathname: string): void {
|
|
485
514
|
const resolved = path.resolve(pathname);
|
|
@@ -685,7 +714,8 @@ export class FileSessionStorage implements SessionStorage {
|
|
|
685
714
|
|
|
686
715
|
writeTextSync(fpath: string, content: string): void {
|
|
687
716
|
this.ensureDirSync(path.dirname(fpath));
|
|
688
|
-
|
|
717
|
+
// New fork and branch transcripts are created here.
|
|
718
|
+
writeExplicitOwnerOnlyTextSync(fpath, content);
|
|
689
719
|
}
|
|
690
720
|
|
|
691
721
|
readTextSync(fpath: string): string {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
1
2
|
import type { AgentToolUpdateCallback } from "@sayknow-cli/agent-core";
|
|
2
3
|
|
|
3
4
|
import { sanitizeText } from "@sayknow-cli/utils";
|
|
@@ -28,6 +29,78 @@ const NL = "\n";
|
|
|
28
29
|
|
|
29
30
|
const ELLIPSIS = "…";
|
|
30
31
|
|
|
32
|
+
// Bound the temporary parts/join allocation in #applyColumnCap for a single
|
|
33
|
+
// large callback. Keep batches small enough to avoid per-line retention work.
|
|
34
|
+
const COLUMN_CAP_BATCH_CHARS = 64 * 1024;
|
|
35
|
+
|
|
36
|
+
const outputPlainSecrets = new AsyncLocalStorage<readonly string[]>();
|
|
37
|
+
|
|
38
|
+
/** Run `fn` while column caps can see these plain secrets. */
|
|
39
|
+
export function runWithOutputRedaction<T>(plainSecrets: readonly string[], fn: () => T): T {
|
|
40
|
+
return outputPlainSecrets.run(plainSecrets, fn);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Get the active plain secrets from AsyncLocalStorage, if any are set. */
|
|
44
|
+
function activePlainSecrets(): readonly string[] | undefined {
|
|
45
|
+
const secrets = outputPlainSecrets.getStore();
|
|
46
|
+
return secrets && secrets.length > 0 ? secrets : undefined;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Pull a column-cap end back to the start of any plain secret that crosses it.
|
|
51
|
+
* A secret that ends on the cut stays, so a later whole-string obfuscator can match it.
|
|
52
|
+
*/
|
|
53
|
+
function columnHeadEndOutsideSecrets(segment: string, end: number, secrets: readonly string[]): number {
|
|
54
|
+
let cut = end;
|
|
55
|
+
while (cut > 0) {
|
|
56
|
+
let earliest = cut;
|
|
57
|
+
for (const secret of secrets) {
|
|
58
|
+
const secretChars = secret.length;
|
|
59
|
+
if (secretChars === 0) continue;
|
|
60
|
+
const windowStart = Math.max(0, cut - secretChars);
|
|
61
|
+
const window = segment.slice(windowStart, Math.min(segment.length, cut + secretChars));
|
|
62
|
+
const limit = cut - windowStart;
|
|
63
|
+
let from = 0;
|
|
64
|
+
while (from < limit) {
|
|
65
|
+
const rel = window.indexOf(secret, from);
|
|
66
|
+
if (rel === -1 || rel >= limit) break;
|
|
67
|
+
if (rel + secretChars > limit) earliest = Math.min(earliest, windowStart + rel);
|
|
68
|
+
from = rel + 1;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (earliest === cut) break;
|
|
72
|
+
cut = earliest;
|
|
73
|
+
}
|
|
74
|
+
return cut;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Pull a column-cap end off a proper prefix of a plain secret.
|
|
79
|
+
* Each candidate's continuation is checked from longest to shortest.
|
|
80
|
+
* A longer candidate that is already finished or contradicted does not hide
|
|
81
|
+
* a shorter open prefix. A secret that already ends on the cut stays.
|
|
82
|
+
*/
|
|
83
|
+
function columnHeadEndBeforeOpenPrefix(text: string, end: number, secrets: readonly string[]): number {
|
|
84
|
+
let cut = end;
|
|
85
|
+
const after = text.slice(end);
|
|
86
|
+
for (const secret of secrets) {
|
|
87
|
+
const secretChars = secret.length;
|
|
88
|
+
if (secretChars < 2 || end < 1) continue;
|
|
89
|
+
if (end >= secretChars && text.slice(end - secretChars, end) === secret) continue;
|
|
90
|
+
const maxPrefix = Math.min(secretChars - 1, end);
|
|
91
|
+
for (let k = maxPrefix; k >= 1; k--) {
|
|
92
|
+
if (text.slice(end - k, end) !== secret.slice(0, k)) continue;
|
|
93
|
+
const rest = secret.slice(k);
|
|
94
|
+
const have = Math.min(after.length, rest.length);
|
|
95
|
+
if (have === rest.length) continue;
|
|
96
|
+
if (after.slice(0, have) !== rest.slice(0, have)) continue;
|
|
97
|
+
cut = Math.min(cut, end - k);
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return cut;
|
|
102
|
+
}
|
|
103
|
+
|
|
31
104
|
// =============================================================================
|
|
32
105
|
// Interfaces
|
|
33
106
|
// =============================================================================
|
|
@@ -285,6 +358,72 @@ export function truncateLine(
|
|
|
285
358
|
return { text: `${line.slice(0, maxChars)}…`, wasTruncated: true };
|
|
286
359
|
}
|
|
287
360
|
|
|
361
|
+
/**
|
|
362
|
+
* Truncate each line to max characters without leaving a configured plain-secret
|
|
363
|
+
* prefix in the retained text. Prior uncapped lines remain in scope because a
|
|
364
|
+
* later line's cut can split a multiline secret.
|
|
365
|
+
*/
|
|
366
|
+
export function truncateTextWithSecretAwareness(
|
|
367
|
+
text: string,
|
|
368
|
+
maxChars: number = DEFAULT_MAX_COLUMN,
|
|
369
|
+
secrets?: readonly string[],
|
|
370
|
+
): { text: string; wasTruncated: boolean } {
|
|
371
|
+
const lines = text.split(NL);
|
|
372
|
+
const activeSecrets = secrets ?? activePlainSecrets();
|
|
373
|
+
if (!activeSecrets?.some(secret => secret.length > 0)) {
|
|
374
|
+
let wasTruncated = false;
|
|
375
|
+
const truncated = lines.map(line => {
|
|
376
|
+
const result = truncateLine(line, maxChars);
|
|
377
|
+
wasTruncated ||= result.wasTruncated;
|
|
378
|
+
return result.text;
|
|
379
|
+
});
|
|
380
|
+
return { text: truncated.join(NL), wasTruncated };
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
const contextChars = activeSecrets.reduce((max, secret) => Math.max(max, secret.length), 0);
|
|
384
|
+
let context = "";
|
|
385
|
+
const outputParts: string[] = [];
|
|
386
|
+
let wasTruncated = false;
|
|
387
|
+
for (let index = 0; index < lines.length; index++) {
|
|
388
|
+
const line = lines[index] ?? "";
|
|
389
|
+
const newline = index < lines.length - 1 ? NL : "";
|
|
390
|
+
if (line.length <= maxChars) {
|
|
391
|
+
outputParts.push(line, newline);
|
|
392
|
+
context = (context + line + newline).slice(-contextChars);
|
|
393
|
+
continue;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
wasTruncated = true;
|
|
397
|
+
const combined = context + line;
|
|
398
|
+
let end = context.length + maxChars;
|
|
399
|
+
while (end > 0) {
|
|
400
|
+
const next = Math.min(
|
|
401
|
+
columnHeadEndOutsideSecrets(combined, end, activeSecrets),
|
|
402
|
+
columnHeadEndBeforeOpenPrefix(combined, end, activeSecrets),
|
|
403
|
+
);
|
|
404
|
+
if (next >= end) break;
|
|
405
|
+
end = next;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
if (end < context.length) {
|
|
409
|
+
const retract = context.slice(end);
|
|
410
|
+
let output = outputParts.join("");
|
|
411
|
+
if (output.endsWith(retract)) {
|
|
412
|
+
output = output.slice(0, output.length - retract.length);
|
|
413
|
+
output += NL.repeat(countNewlines(retract));
|
|
414
|
+
} else {
|
|
415
|
+
output = NL.repeat(countNewlines(output));
|
|
416
|
+
}
|
|
417
|
+
outputParts.length = 0;
|
|
418
|
+
outputParts.push(output);
|
|
419
|
+
}
|
|
420
|
+
const keptChars = Math.max(0, end - context.length);
|
|
421
|
+
outputParts.push(line.slice(0, keptChars), ELLIPSIS, newline);
|
|
422
|
+
context = "";
|
|
423
|
+
}
|
|
424
|
+
return { text: outputParts.join(""), wasTruncated };
|
|
425
|
+
}
|
|
426
|
+
|
|
288
427
|
// =============================================================================
|
|
289
428
|
// Content truncation (line + byte aware, no full Buffer allocation)
|
|
290
429
|
// =============================================================================
|
|
@@ -920,6 +1059,13 @@ export class OutputSink {
|
|
|
920
1059
|
#columnEllipsisAdded = false;
|
|
921
1060
|
#columnDroppedBytes = 0;
|
|
922
1061
|
#columnTruncatedLines = 0;
|
|
1062
|
+
/** Plain secrets captured when this sink is built inside an active redaction scope. */
|
|
1063
|
+
readonly #plainSecrets?: readonly string[];
|
|
1064
|
+
readonly #plainSecretContextChars: number;
|
|
1065
|
+
/** Text already retained for the open line. A later chunk may shorten it. */
|
|
1066
|
+
#columnLine = "";
|
|
1067
|
+
/** Bounded suffix of prior uncapped output, preserved for multiline secrets. */
|
|
1068
|
+
#columnLineContext = "";
|
|
923
1069
|
#file?: {
|
|
924
1070
|
path: string;
|
|
925
1071
|
artifactId?: string;
|
|
@@ -971,6 +1117,8 @@ export class OutputSink {
|
|
|
971
1117
|
this.#chunkThrottleMs = chunkThrottleMs;
|
|
972
1118
|
this.#artifactMaxBytes = Math.max(0, artifactMaxBytes);
|
|
973
1119
|
this.#coalesceSanitize = coalesceSanitize;
|
|
1120
|
+
this.#plainSecrets = activePlainSecrets();
|
|
1121
|
+
this.#plainSecretContextChars = this.#plainSecrets?.reduce((max, secret) => Math.max(max, secret.length), 0) ?? 0;
|
|
974
1122
|
}
|
|
975
1123
|
|
|
976
1124
|
#headText(): string {
|
|
@@ -1063,9 +1211,45 @@ export class OutputSink {
|
|
|
1063
1211
|
|
|
1064
1212
|
if (rawBytes === 0) return;
|
|
1065
1213
|
|
|
1066
|
-
const visibleChunk = this.#maxColumns > 0 ? this.#applyColumnCap(sanitizedChunk) : sanitizedChunk;
|
|
1067
1214
|
if (this.#artifactPath && this.#maxColumns > 0) this.#enqueueFileWrite(rawChunk, rawBytes);
|
|
1215
|
+
|
|
1216
|
+
// Retain line by line: a secret-aware column cut-back may retract output a prior line already retained.
|
|
1217
|
+
if (this.#maxColumns > 0) {
|
|
1218
|
+
if (this.#plainSecrets) {
|
|
1219
|
+
// Secret-aware cuts can retract text from an earlier line, so retain
|
|
1220
|
+
// each line before processing the next one.
|
|
1221
|
+
let cursor = 0;
|
|
1222
|
+
while (cursor < sanitizedChunk.length) {
|
|
1223
|
+
const newline = sanitizedChunk.indexOf(NL, cursor);
|
|
1224
|
+
const end = newline === -1 ? sanitizedChunk.length : newline + 1;
|
|
1225
|
+
this.#retainVisible(this.#applyColumnCap(sanitizedChunk.slice(cursor, end)));
|
|
1226
|
+
cursor = end;
|
|
1227
|
+
}
|
|
1228
|
+
} else {
|
|
1229
|
+
// Batch ordinary output while bounding #applyColumnCap's temporary
|
|
1230
|
+
// parts/join allocation for large single callbacks. Retaining each
|
|
1231
|
+
// line separately repeats accounting millions of times.
|
|
1232
|
+
let cursor = 0;
|
|
1233
|
+
while (cursor < sanitizedChunk.length) {
|
|
1234
|
+
let end = Math.min(cursor + COLUMN_CAP_BATCH_CHARS, sanitizedChunk.length);
|
|
1235
|
+
// UTF-8 byte accounting must not observe a surrogate pair as two
|
|
1236
|
+
// replacement characters when a batch boundary lands between them.
|
|
1237
|
+
if (end < sanitizedChunk.length) {
|
|
1238
|
+
const before = sanitizedChunk.charCodeAt(end - 1);
|
|
1239
|
+
const after = sanitizedChunk.charCodeAt(end);
|
|
1240
|
+
if (before >= 0xd800 && before <= 0xdbff && after >= 0xdc00 && after <= 0xdfff) end--;
|
|
1241
|
+
}
|
|
1242
|
+
this.#retainVisible(this.#applyColumnCap(sanitizedChunk.slice(cursor, end)));
|
|
1243
|
+
cursor = end;
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
} else {
|
|
1247
|
+
this.#retainVisible(sanitizedChunk);
|
|
1248
|
+
}
|
|
1068
1249
|
if (this.#columnDroppedBytes > 0) this.#createFileSink();
|
|
1250
|
+
}
|
|
1251
|
+
|
|
1252
|
+
#retainVisible(visibleChunk: string): void {
|
|
1069
1253
|
const visibleBytes = Buffer.byteLength(visibleChunk, "utf-8");
|
|
1070
1254
|
if (visibleChunk.length > 0) {
|
|
1071
1255
|
this.#processedBytes += visibleBytes;
|
|
@@ -1083,6 +1267,7 @@ export class OutputSink {
|
|
|
1083
1267
|
return;
|
|
1084
1268
|
}
|
|
1085
1269
|
const headSlice = truncateHeadBytes(visibleChunk, room);
|
|
1270
|
+
this.#headRetentionDisabled = true;
|
|
1086
1271
|
if (headSlice.bytes > 0) {
|
|
1087
1272
|
this.#appendHead(headSlice.text, headSlice.bytes);
|
|
1088
1273
|
tailChunk = visibleChunk.substring(headSlice.text.length);
|
|
@@ -1119,34 +1304,106 @@ export class OutputSink {
|
|
|
1119
1304
|
if (segBytes <= remaining) {
|
|
1120
1305
|
parts.push(segment);
|
|
1121
1306
|
this.#currentLineBytes += segBytes;
|
|
1307
|
+
if (this.#plainSecrets) this.#columnLine += segment;
|
|
1122
1308
|
} else {
|
|
1123
1309
|
// First overflow on this line: keep what fits, append ellipsis,
|
|
1124
|
-
// arm the skip-until-newline flag.
|
|
1310
|
+
// arm the skip-until-newline flag. With secrets, do not emit a
|
|
1311
|
+
// kept-head suffix that is still a prefix of a plain secret, and
|
|
1312
|
+
// do not end inside one the whole-string obfuscator must see whole.
|
|
1125
1313
|
const ellipsisBytes = 3; // "…" in UTF-8
|
|
1126
1314
|
const headRoom = Math.max(0, remaining - ellipsisBytes);
|
|
1127
1315
|
let keptBytes = 0;
|
|
1316
|
+
let keptText = "";
|
|
1128
1317
|
if (headRoom > 0) {
|
|
1129
1318
|
const sliced = truncateHeadBytes(segment, headRoom);
|
|
1319
|
+
keptText = sliced.text;
|
|
1130
1320
|
keptBytes = sliced.bytes;
|
|
1131
|
-
parts.push(sliced.text);
|
|
1132
1321
|
}
|
|
1322
|
+
const secrets = this.#plainSecrets;
|
|
1323
|
+
let lineBytesReset = false;
|
|
1324
|
+
if (secrets && segment.startsWith(keptText)) {
|
|
1325
|
+
const prior = this.#columnLine;
|
|
1326
|
+
const prefix = this.#columnLineContext + prior;
|
|
1327
|
+
const text = prefix + segment;
|
|
1328
|
+
const cut = prefix.length + keptText.length;
|
|
1329
|
+
let end = cut;
|
|
1330
|
+
while (end > 0) {
|
|
1331
|
+
const next = Math.min(
|
|
1332
|
+
columnHeadEndOutsideSecrets(text, end, secrets),
|
|
1333
|
+
columnHeadEndBeforeOpenPrefix(text, end, secrets),
|
|
1334
|
+
);
|
|
1335
|
+
if (next >= end) break;
|
|
1336
|
+
end = next;
|
|
1337
|
+
}
|
|
1338
|
+
if (end < cut) {
|
|
1339
|
+
if (end < prefix.length) {
|
|
1340
|
+
this.#retractColumnSuffix(prefix.slice(end));
|
|
1341
|
+
if (end < this.#columnLineContext.length) {
|
|
1342
|
+
this.#columnLineContext = this.#columnLineContext.slice(0, end);
|
|
1343
|
+
this.#columnLine = "";
|
|
1344
|
+
} else {
|
|
1345
|
+
this.#columnLine = prior.slice(0, end - this.#columnLineContext.length);
|
|
1346
|
+
}
|
|
1347
|
+
keptText = "";
|
|
1348
|
+
keptBytes = 0;
|
|
1349
|
+
} else {
|
|
1350
|
+
keptText = segment.slice(0, end - prefix.length);
|
|
1351
|
+
keptBytes = Buffer.byteLength(keptText, "utf-8");
|
|
1352
|
+
this.#columnLine = prior + keptText;
|
|
1353
|
+
}
|
|
1354
|
+
// columnLine already includes the bytes kept from this segment.
|
|
1355
|
+
this.#currentLineBytes = Buffer.byteLength(this.#columnLine, "utf-8");
|
|
1356
|
+
lineBytesReset = true;
|
|
1357
|
+
} else {
|
|
1358
|
+
this.#columnLine = prior + keptText;
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
if (keptText.length > 0) parts.push(keptText);
|
|
1133
1362
|
parts.push(ELLIPSIS);
|
|
1134
1363
|
this.#columnDroppedBytes += segBytes - keptBytes;
|
|
1135
1364
|
this.#columnTruncatedLines++;
|
|
1136
|
-
this.#currentLineBytes += keptBytes + ellipsisBytes;
|
|
1365
|
+
this.#currentLineBytes += (lineBytesReset ? 0 : keptBytes) + ellipsisBytes;
|
|
1137
1366
|
this.#columnEllipsisAdded = true;
|
|
1138
1367
|
}
|
|
1139
1368
|
}
|
|
1140
1369
|
}
|
|
1141
1370
|
if (nlIdx === -1) break;
|
|
1142
1371
|
parts.push(NL);
|
|
1372
|
+
if (this.#plainSecretContextChars > 0 && !this.#columnEllipsisAdded) {
|
|
1373
|
+
const context = this.#columnLineContext + this.#columnLine + NL;
|
|
1374
|
+
this.#columnLineContext = context.slice(-this.#plainSecretContextChars);
|
|
1375
|
+
} else {
|
|
1376
|
+
this.#columnLineContext = "";
|
|
1377
|
+
}
|
|
1143
1378
|
this.#currentLineBytes = 0;
|
|
1144
1379
|
this.#columnEllipsisAdded = false;
|
|
1380
|
+
this.#columnLine = "";
|
|
1145
1381
|
cursor = nlIdx + 1;
|
|
1146
1382
|
}
|
|
1147
1383
|
return parts.join("");
|
|
1148
1384
|
}
|
|
1149
1385
|
|
|
1386
|
+
/** Remove a suffix of previously retained output after a secret-aware cut-back. */
|
|
1387
|
+
#retractColumnSuffix(suffix: string): void {
|
|
1388
|
+
if (suffix.length === 0) return;
|
|
1389
|
+
const bytes = Buffer.byteLength(suffix, "utf-8");
|
|
1390
|
+
const startByte = Math.max(0, this.#processedBytes - bytes);
|
|
1391
|
+
const tailStartByte = Math.max(0, this.#processedBytes - this.#bufferBytes);
|
|
1392
|
+
const keptTailBytes = Math.max(0, Math.min(this.#bufferBytes, startByte - tailStartByte));
|
|
1393
|
+
if (keptTailBytes < this.#bufferBytes) {
|
|
1394
|
+
const nextTail = truncateHeadBytes(this.#buffer, keptTailBytes);
|
|
1395
|
+
this.#setTail(nextTail.text, nextTail.bytes);
|
|
1396
|
+
}
|
|
1397
|
+
if (startByte < this.#headBytes) {
|
|
1398
|
+
const nextHead = truncateHeadBytes(this.#head, startByte);
|
|
1399
|
+
this.#head = nextHead.text;
|
|
1400
|
+
this.#headBytes = nextHead.bytes;
|
|
1401
|
+
}
|
|
1402
|
+
this.#processedBytes = Math.max(0, this.#processedBytes - bytes);
|
|
1403
|
+
this.#processedLines = Math.max(0, this.#processedLines - countNewlines(suffix));
|
|
1404
|
+
this.#columnDroppedBytes += bytes;
|
|
1405
|
+
}
|
|
1406
|
+
|
|
1150
1407
|
#retainedSummary(text: string): { text: string; bytes: number; lines: number } {
|
|
1151
1408
|
return { text, bytes: Buffer.byteLength(text, "utf-8"), lines: text.length > 0 ? countNewlines(text) : 0 };
|
|
1152
1409
|
}
|
|
@@ -1311,6 +1568,8 @@ export class OutputSink {
|
|
|
1311
1568
|
*/
|
|
1312
1569
|
replace(text: string): void {
|
|
1313
1570
|
this.#coalesceBuf = "";
|
|
1571
|
+
this.#columnLine = "";
|
|
1572
|
+
this.#columnLineContext = "";
|
|
1314
1573
|
this.#setTail(text);
|
|
1315
1574
|
this.#head = "";
|
|
1316
1575
|
this.#headBytes = 0;
|