@sayknow-cli/coding-agent 0.7.11 → 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 +10 -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 +116 -8
- 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/tools/eval.ts
CHANGED
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
stripOutputNotice,
|
|
22
22
|
} from "./output-meta";
|
|
23
23
|
import { formatTitle, replaceTabs, shortenPath, truncateToWidth, wrapBrackets } from "./render-utils";
|
|
24
|
-
import {
|
|
24
|
+
import { ToolError, throwIfAborted } from "./tool-errors";
|
|
25
25
|
import { toolResult } from "./tool-result";
|
|
26
26
|
import { clampTimeout } from "./tool-timeouts";
|
|
27
27
|
|
|
@@ -149,6 +149,18 @@ export interface EvalToolOptions {
|
|
|
149
149
|
proxyExecutor?: EvalProxyExecutor;
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
+
/**
|
|
153
|
+
* In-process eval is not a shell command, so a bash allowlist cannot authorize it.
|
|
154
|
+
* The same flags that turn the bash tool's allowlist on refuse eval outright.
|
|
155
|
+
* Blank prefixes match `checkBashAllowedPrefixes`: they do not restrict.
|
|
156
|
+
*/
|
|
157
|
+
function bashRestrictionBlocksEval(
|
|
158
|
+
session: Pick<ToolSession, "bashAllowedPrefixes" | "bashRestrictionProfile">,
|
|
159
|
+
): boolean {
|
|
160
|
+
if (session.bashRestrictionProfile === "read-only") return true;
|
|
161
|
+
return (session.bashAllowedPrefixes ?? []).some(prefix => prefix.trim().length > 0);
|
|
162
|
+
}
|
|
163
|
+
|
|
152
164
|
interface ResolvedBackend {
|
|
153
165
|
backend: ExecutorBackend;
|
|
154
166
|
notice?: string;
|
|
@@ -238,6 +250,9 @@ export class EvalTool implements AgentTool<typeof evalSchema> {
|
|
|
238
250
|
onUpdate?: AgentToolUpdateCallback,
|
|
239
251
|
_ctx?: AgentToolContext,
|
|
240
252
|
): Promise<AgentToolResult<EvalToolDetails | undefined>> {
|
|
253
|
+
if (this.session && bashRestrictionBlocksEval(this.session)) {
|
|
254
|
+
throw new ToolError("Eval is unavailable while this session's bash allowlist or read-only profile is active.");
|
|
255
|
+
}
|
|
241
256
|
if (this.#proxyExecutor) {
|
|
242
257
|
return this.#proxyExecutor(params, signal);
|
|
243
258
|
}
|
|
@@ -247,23 +262,27 @@ export class EvalTool implements AgentTool<typeof evalSchema> {
|
|
|
247
262
|
}
|
|
248
263
|
const session = this.session;
|
|
249
264
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
265
|
+
// Register the complete invocation before any asynchronous preflight: backend
|
|
266
|
+
// resolution can spawn a kernel probe, and disposal must be able to abort and
|
|
267
|
+
// await it. Session identity is captured once so a mid-run session switch
|
|
268
|
+
// cannot retarget the kernel.
|
|
269
|
+
session.assertEvalExecutionAllowed?.();
|
|
270
|
+
const cwd = session.cwd;
|
|
271
|
+
const settings = session.settings;
|
|
272
|
+
const sessionFile = session.getSessionFile?.() ?? null;
|
|
273
|
+
const kernelOwnerId = session.getEvalKernelOwnerId?.() ?? null;
|
|
274
|
+
const sessionId = sessionFile ? `session:${sessionFile}:cwd:${cwd}` : `cwd:${cwd}`;
|
|
275
|
+
const evalSession: ToolSession = {
|
|
276
|
+
...session,
|
|
277
|
+
cwd,
|
|
278
|
+
settings,
|
|
279
|
+
getSessionFile: () => sessionFile,
|
|
280
|
+
getEvalKernelOwnerId: () => kernelOwnerId,
|
|
281
|
+
};
|
|
266
282
|
const sessionAbortController = new AbortController();
|
|
283
|
+
const abortFromCaller = (): void => sessionAbortController.abort(signal?.reason);
|
|
284
|
+
if (signal?.aborted) abortFromCaller();
|
|
285
|
+
else signal?.addEventListener("abort", abortFromCaller, { once: true });
|
|
267
286
|
let outputSink: OutputSink | undefined;
|
|
268
287
|
let outputSummary: OutputSummary | undefined;
|
|
269
288
|
let outputDumped = false;
|
|
@@ -274,12 +293,30 @@ export class EvalTool implements AgentTool<typeof evalSchema> {
|
|
|
274
293
|
return outputSummary;
|
|
275
294
|
};
|
|
276
295
|
|
|
277
|
-
const execution = (async (): Promise<AgentToolResult<EvalToolDetails | undefined>> => {
|
|
296
|
+
const execution = Promise.resolve().then(async (): Promise<AgentToolResult<EvalToolDetails | undefined>> => {
|
|
278
297
|
try {
|
|
279
|
-
|
|
280
|
-
throw new ToolAbortError();
|
|
281
|
-
}
|
|
298
|
+
throwIfAborted(sessionAbortController.signal);
|
|
282
299
|
session.assertEvalExecutionAllowed?.();
|
|
300
|
+
const cells: ResolvedEvalCell[] = [];
|
|
301
|
+
for (let i = 0; i < params.cells.length; i++) {
|
|
302
|
+
throwIfAborted(sessionAbortController.signal);
|
|
303
|
+
session.assertEvalExecutionAllowed?.();
|
|
304
|
+
const cell = params.cells[i];
|
|
305
|
+
const language: EvalLanguage = cell.language === "py" ? "python" : "js";
|
|
306
|
+
const resolved = await resolveBackend(evalSession, language);
|
|
307
|
+
throwIfAborted(sessionAbortController.signal);
|
|
308
|
+
session.assertEvalExecutionAllowed?.();
|
|
309
|
+
cells.push({
|
|
310
|
+
index: i,
|
|
311
|
+
title: cell.title,
|
|
312
|
+
code: cell.code,
|
|
313
|
+
timeoutMs: (cell.timeout ?? 30) * 1000,
|
|
314
|
+
reset: cell.reset ?? false,
|
|
315
|
+
resolved,
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
const languages = uniqueEvalLanguages(cells);
|
|
319
|
+
const notice = detailsNotice(cells);
|
|
283
320
|
|
|
284
321
|
const tailBuffer = new TailBuffer(DEFAULT_MAX_BYTES * 2);
|
|
285
322
|
const jsonOutputs: unknown[] = [];
|
|
@@ -333,31 +370,28 @@ export class EvalTool implements AgentTool<typeof evalSchema> {
|
|
|
333
370
|
});
|
|
334
371
|
};
|
|
335
372
|
|
|
336
|
-
|
|
337
|
-
|
|
373
|
+
throwIfAborted(sessionAbortController.signal);
|
|
374
|
+
session.assertEvalExecutionAllowed?.();
|
|
338
375
|
const { path: artifactPath, id: artifactId } = (await session.allocateOutputArtifact?.("eval")) ?? {};
|
|
376
|
+
throwIfAborted(sessionAbortController.signal);
|
|
339
377
|
session.assertEvalExecutionAllowed?.();
|
|
340
378
|
outputSink = new OutputSink({
|
|
341
379
|
artifactPath,
|
|
342
380
|
artifactId,
|
|
343
|
-
headBytes: resolveOutputSinkHeadBytes(
|
|
344
|
-
maxColumns: resolveOutputMaxColumns(
|
|
381
|
+
headBytes: resolveOutputSinkHeadBytes(settings),
|
|
382
|
+
maxColumns: resolveOutputMaxColumns(settings),
|
|
345
383
|
onChunk: chunk => {
|
|
346
384
|
appendTail(chunk);
|
|
347
385
|
pushUpdate();
|
|
348
386
|
},
|
|
349
387
|
});
|
|
350
|
-
const sessionId = sessionFile ? `session:${sessionFile}:cwd:${session.cwd}` : `cwd:${session.cwd}`;
|
|
351
|
-
|
|
352
388
|
for (let i = 0; i < cells.length; i++) {
|
|
353
389
|
const cell = cells[i];
|
|
354
390
|
const backend = cell.resolved.backend;
|
|
355
391
|
const timeoutSec = timeoutSecondsFromMs(cell.timeoutMs);
|
|
356
392
|
const deadlineMs = Date.now() + timeoutSec * 1000;
|
|
357
393
|
const timeoutSignal = AbortSignal.timeout(Math.max(0, deadlineMs - Date.now()));
|
|
358
|
-
const combinedSignal = signal
|
|
359
|
-
? AbortSignal.any([signal, timeoutSignal, sessionAbortController.signal])
|
|
360
|
-
: AbortSignal.any([timeoutSignal, sessionAbortController.signal]);
|
|
394
|
+
const combinedSignal = AbortSignal.any([timeoutSignal, sessionAbortController.signal]);
|
|
361
395
|
|
|
362
396
|
const cellResult = cellResults[i];
|
|
363
397
|
cellResult.status = "running";
|
|
@@ -366,15 +400,17 @@ export class EvalTool implements AgentTool<typeof evalSchema> {
|
|
|
366
400
|
cellResult.exitCode = undefined;
|
|
367
401
|
cellResult.durationMs = undefined;
|
|
368
402
|
pushUpdate();
|
|
403
|
+
throwIfAborted(sessionAbortController.signal);
|
|
404
|
+
session.assertEvalExecutionAllowed?.();
|
|
369
405
|
|
|
370
406
|
const startTime = Date.now();
|
|
371
407
|
const result = await backend.execute(cell.code, {
|
|
372
|
-
cwd
|
|
408
|
+
cwd,
|
|
373
409
|
sessionId,
|
|
374
410
|
sessionFile: sessionFile ?? undefined,
|
|
375
|
-
kernelOwnerId,
|
|
411
|
+
kernelOwnerId: kernelOwnerId ?? undefined,
|
|
376
412
|
signal: combinedSignal,
|
|
377
|
-
session,
|
|
413
|
+
session: evalSession,
|
|
378
414
|
deadlineMs,
|
|
379
415
|
reset: cell.reset,
|
|
380
416
|
artifactPath,
|
|
@@ -518,13 +554,14 @@ export class EvalTool implements AgentTool<typeof evalSchema> {
|
|
|
518
554
|
.truncationFromSummary(summaryForMeta, { direction: "tail" })
|
|
519
555
|
.done();
|
|
520
556
|
} finally {
|
|
557
|
+
signal?.removeEventListener("abort", abortFromCaller);
|
|
521
558
|
if (!outputDumped) {
|
|
522
559
|
try {
|
|
523
560
|
await finalizeOutput();
|
|
524
561
|
} catch {}
|
|
525
562
|
}
|
|
526
563
|
}
|
|
527
|
-
})
|
|
564
|
+
});
|
|
528
565
|
|
|
529
566
|
return await (session.trackEvalExecution?.(execution, sessionAbortController) ?? execution);
|
|
530
567
|
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import * as nodeFs from "node:fs";
|
|
3
|
+
import * as fs from "node:fs/promises";
|
|
4
|
+
import * as path from "node:path";
|
|
5
|
+
|
|
6
|
+
const ARTIFACT_NOFOLLOW = process.platform === "win32" ? 0 : (nodeFs.constants.O_NOFOLLOW ?? 0);
|
|
7
|
+
|
|
8
|
+
async function unlinkOwnedStaging(staging: string, dev: bigint, ino: bigint): Promise<void> {
|
|
9
|
+
try {
|
|
10
|
+
const stat = await fs.lstat(staging, { bigint: true });
|
|
11
|
+
if (!stat.isFile() || stat.isSymbolicLink() || stat.dev !== dev || stat.ino !== ino) return;
|
|
12
|
+
await fs.unlink(staging);
|
|
13
|
+
} catch (error) {
|
|
14
|
+
if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Publish text at an explicit artifact path the way `ArtifactManager.save` does:
|
|
20
|
+
* a temp file opened with `O_NOFOLLOW` and mode 0600, then rename. A symlink is
|
|
21
|
+
* not followed. A pre-existing regular file is replaced, so mode 0644 is not kept.
|
|
22
|
+
*
|
|
23
|
+
* Node built-ins only, so `gh` can publish without importing `tools/fetch`.
|
|
24
|
+
*/
|
|
25
|
+
export async function publishExplicitArtifactText(destination: string, text: string): Promise<void> {
|
|
26
|
+
const bytes = Buffer.from(text, "utf8");
|
|
27
|
+
const parent = path.dirname(destination);
|
|
28
|
+
// Bun.write created a missing parent. Match that when the allocated path's
|
|
29
|
+
// directory does not exist yet.
|
|
30
|
+
try {
|
|
31
|
+
await fs.lstat(parent);
|
|
32
|
+
} catch (error) {
|
|
33
|
+
if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
|
|
34
|
+
await fs.mkdir(parent, { recursive: true, mode: 0o700 });
|
|
35
|
+
}
|
|
36
|
+
// Keep the staging component a fixed length. A destination basename near NAME_MAX
|
|
37
|
+
// plus a UUID would make the temp name longer than the filesystem allows.
|
|
38
|
+
const staging = path.join(parent, `.artifact-${randomUUID()}.staging`);
|
|
39
|
+
let handle: fs.FileHandle | undefined;
|
|
40
|
+
let stagedDev: bigint | undefined;
|
|
41
|
+
let stagedIno: bigint | undefined;
|
|
42
|
+
let published = false;
|
|
43
|
+
try {
|
|
44
|
+
handle = await fs.open(
|
|
45
|
+
staging,
|
|
46
|
+
nodeFs.constants.O_CREAT | nodeFs.constants.O_EXCL | nodeFs.constants.O_WRONLY | ARTIFACT_NOFOLLOW,
|
|
47
|
+
0o600,
|
|
48
|
+
);
|
|
49
|
+
const opened = await handle.stat({ bigint: true });
|
|
50
|
+
stagedDev = opened.dev;
|
|
51
|
+
stagedIno = opened.ino;
|
|
52
|
+
if (process.platform !== "win32") await handle.chmod(0o600);
|
|
53
|
+
await handle.writeFile(bytes);
|
|
54
|
+
await handle.sync();
|
|
55
|
+
const staged = await handle.stat({ bigint: true });
|
|
56
|
+
if (process.platform !== "win32" && (Number(staged.mode) & 0o777) !== 0o600) {
|
|
57
|
+
throw new Error("artifact_publish_mode");
|
|
58
|
+
}
|
|
59
|
+
await handle.close();
|
|
60
|
+
handle = undefined;
|
|
61
|
+
|
|
62
|
+
let existing: nodeFs.Stats | undefined;
|
|
63
|
+
try {
|
|
64
|
+
existing = await fs.lstat(destination);
|
|
65
|
+
} catch (error) {
|
|
66
|
+
if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
|
|
67
|
+
}
|
|
68
|
+
if (existing?.isSymbolicLink()) throw new Error("artifact_destination_symlink");
|
|
69
|
+
if (existing && !existing.isFile()) throw new Error("artifact_destination_not_file");
|
|
70
|
+
|
|
71
|
+
await fs.rename(staging, destination);
|
|
72
|
+
const named = await fs.lstat(destination, { bigint: true });
|
|
73
|
+
if (
|
|
74
|
+
!named.isFile() ||
|
|
75
|
+
named.isSymbolicLink() ||
|
|
76
|
+
named.dev !== stagedDev ||
|
|
77
|
+
named.ino !== stagedIno ||
|
|
78
|
+
(process.platform !== "win32" && (Number(named.mode) & 0o777) !== 0o600)
|
|
79
|
+
) {
|
|
80
|
+
throw new Error("artifact_destination_identity_changed");
|
|
81
|
+
}
|
|
82
|
+
published = true;
|
|
83
|
+
} finally {
|
|
84
|
+
if (handle) await handle.close().catch(() => undefined);
|
|
85
|
+
if (!published && stagedDev !== undefined && stagedIno !== undefined) {
|
|
86
|
+
await unlinkOwnedStaging(staging, stagedDev, stagedIno);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
package/src/tools/fetch.ts
CHANGED
|
@@ -21,12 +21,20 @@ import { specialHandlers } from "../web/scrapers";
|
|
|
21
21
|
import type { RenderResult } from "../web/scrapers/types";
|
|
22
22
|
import { finalizeOutput, loadPage, looksLikeHtml, MAX_OUTPUT_CHARS } from "../web/scrapers/types";
|
|
23
23
|
import { convertWithMarkit, fetchBinary } from "../web/scrapers/utils";
|
|
24
|
+
import { publishExplicitArtifactText } from "./explicit-artifact";
|
|
24
25
|
import { applyListLimit } from "./list-limit";
|
|
25
26
|
import { formatStyledArtifactReference, type OutputMeta } from "./output-meta";
|
|
26
27
|
import { formatExpandHint, getDomain, replaceTabs } from "./render-utils";
|
|
27
28
|
import { ToolAbortError, ToolError } from "./tool-errors";
|
|
28
29
|
import { toolResult } from "./tool-result";
|
|
29
30
|
import { clampTimeout } from "./tool-timeouts";
|
|
31
|
+
import {
|
|
32
|
+
escapeUntrustedContent,
|
|
33
|
+
UNTRUSTED_CONTENT_OPEN,
|
|
34
|
+
WRAP_PREFIX_CHARS,
|
|
35
|
+
WRAP_SUFFIX,
|
|
36
|
+
wrapUntrustedContent,
|
|
37
|
+
} from "./untrusted-content";
|
|
30
38
|
|
|
31
39
|
// =============================================================================
|
|
32
40
|
// Types and Constants
|
|
@@ -605,12 +613,13 @@ async function handleSpecialUrls(
|
|
|
605
613
|
timeout: number,
|
|
606
614
|
signal: AbortSignal | undefined,
|
|
607
615
|
storage: AgentStorage | null,
|
|
616
|
+
settings: Settings,
|
|
608
617
|
): Promise<FetchRenderResult | null> {
|
|
609
618
|
for (const handler of specialHandlers) {
|
|
610
619
|
if (signal?.aborted) {
|
|
611
620
|
throw new ToolAbortError();
|
|
612
621
|
}
|
|
613
|
-
const result = await handler(url, timeout, signal, storage);
|
|
622
|
+
const result = await handler(url, timeout, signal, storage, settings);
|
|
614
623
|
if (result) return result;
|
|
615
624
|
}
|
|
616
625
|
return null;
|
|
@@ -689,7 +698,7 @@ async function renderUrl(
|
|
|
689
698
|
|
|
690
699
|
// Step 1: Try special handlers for known sites (unless raw mode)
|
|
691
700
|
if (!raw) {
|
|
692
|
-
const specialResult = await handleSpecialUrls(url, timeout, signal, storage);
|
|
701
|
+
const specialResult = await handleSpecialUrls(url, timeout, signal, storage, settings);
|
|
693
702
|
if (specialResult) return specialResult;
|
|
694
703
|
}
|
|
695
704
|
|
|
@@ -1161,6 +1170,13 @@ interface ReadUrlCacheEntry {
|
|
|
1161
1170
|
|
|
1162
1171
|
const readUrlCache = new Map<string, ReadUrlCacheEntry>();
|
|
1163
1172
|
|
|
1173
|
+
/** Test seam: the read-url cache is process-wide, so suites reset it between cases. */
|
|
1174
|
+
export const readUrlCacheTestHooks = {
|
|
1175
|
+
reset(): void {
|
|
1176
|
+
readUrlCache.clear();
|
|
1177
|
+
},
|
|
1178
|
+
};
|
|
1179
|
+
|
|
1164
1180
|
function getReadUrlCacheKey(session: ToolSession, requestedUrl: string, raw: boolean): string {
|
|
1165
1181
|
const scope = session.getSessionFile() ?? session.cwd;
|
|
1166
1182
|
return `${scope}::${raw ? "raw" : "rendered"}::${normalizeUrl(requestedUrl)}`;
|
|
@@ -1200,10 +1216,16 @@ async function materializeReadUrlCacheEntry(
|
|
|
1200
1216
|
return null;
|
|
1201
1217
|
}
|
|
1202
1218
|
|
|
1219
|
+
// The artifact publisher and the untrusted-content envelope live in import-free
|
|
1220
|
+
// leaf modules so `gh` can use them without importing this file (and with it the
|
|
1221
|
+
// web scrapers) into the `config/settings` import cycle. Re-exported here for the
|
|
1222
|
+
// existing `./fetch` importers.
|
|
1223
|
+
export { escapeUntrustedContent, publishExplicitArtifactText, WRAP_PREFIX_CHARS, wrapUntrustedContent };
|
|
1224
|
+
|
|
1203
1225
|
async function persistReadUrlArtifact(session: ToolSession, output: string): Promise<string | undefined> {
|
|
1204
1226
|
const { path: artifactPath, id } = (await session.allocateOutputArtifact?.("read")) ?? {};
|
|
1205
1227
|
if (!artifactPath) return undefined;
|
|
1206
|
-
await
|
|
1228
|
+
await publishExplicitArtifactText(artifactPath, wrapUntrustedContent(output));
|
|
1207
1229
|
return id;
|
|
1208
1230
|
}
|
|
1209
1231
|
|
|
@@ -1279,19 +1301,6 @@ export async function loadReadUrlCacheEntry(
|
|
|
1279
1301
|
return fresh;
|
|
1280
1302
|
}
|
|
1281
1303
|
|
|
1282
|
-
const UNTRUSTED_CONTENT_OPEN = "<untrusted-content>";
|
|
1283
|
-
const UNTRUSTED_CONTENT_CLOSE = "</untrusted-content>";
|
|
1284
|
-
export const WRAP_PREFIX_CHARS = `${UNTRUSTED_CONTENT_OPEN}\n`.length;
|
|
1285
|
-
const WRAP_SUFFIX = `\n${UNTRUSTED_CONTENT_CLOSE}`;
|
|
1286
|
-
|
|
1287
|
-
export function escapeUntrustedContent(content: string): string {
|
|
1288
|
-
return content.replace(/<\/untrusted-content>/gi, "</untrusted-content>");
|
|
1289
|
-
}
|
|
1290
|
-
|
|
1291
|
-
export function wrapUntrustedContent(content: string): string {
|
|
1292
|
-
return `${UNTRUSTED_CONTENT_OPEN}\n${escapeUntrustedContent(content)}${WRAP_SUFFIX}`;
|
|
1293
|
-
}
|
|
1294
|
-
|
|
1295
1304
|
function isWrappedReadUrlOutput(output: string): boolean {
|
|
1296
1305
|
return output.startsWith(`${UNTRUSTED_CONTENT_OPEN}\n`) && output.endsWith(WRAP_SUFFIX);
|
|
1297
1306
|
}
|
|
@@ -1361,7 +1370,7 @@ export async function executeReadUrl(
|
|
|
1361
1370
|
WRAP_PREFIX_CHARS + escapeUntrustedContent(buildReadUrlPreamble(cacheEntry.details)).length)
|
|
1362
1371
|
: cacheEntry.preambleChars;
|
|
1363
1372
|
const wrappedPrefix = isWrappedOutput ? WRAP_PREFIX_CHARS : 0;
|
|
1364
|
-
const wrappedSuffix = isWrappedOutput ?
|
|
1373
|
+
const wrappedSuffix = isWrappedOutput ? WRAP_SUFFIX : "";
|
|
1365
1374
|
const bodyEnd = cacheEntry.output.length - wrappedSuffix.length;
|
|
1366
1375
|
const unwrappedOutput = isWrappedOutput
|
|
1367
1376
|
? cacheEntry.output.slice(wrappedPrefix, Math.max(wrappedPrefix, bodyEnd))
|
package/src/tools/gh.ts
CHANGED
|
@@ -8,13 +8,19 @@ import { getWorktreeDir, hashPath, isEnoent, prompt, untilAborted } from "@saykn
|
|
|
8
8
|
import * as z from "zod/v4";
|
|
9
9
|
import type { Settings } from "../config/settings";
|
|
10
10
|
import githubDescription from "../prompts/tools/github.md" with { type: "text" };
|
|
11
|
+
import { assertWorkflowMutationAllowed } from "../skill-state/workflow-mutation-guard";
|
|
11
12
|
import * as git from "../utils/git";
|
|
12
13
|
import type { ToolSession } from ".";
|
|
14
|
+
import { publishExplicitArtifactText } from "./explicit-artifact";
|
|
13
15
|
import { formatShortSha } from "./gh-format";
|
|
14
16
|
import { type CacheStatus, getOrFetchView, resolveGithubCacheAuthKey } from "./github-cache";
|
|
17
|
+
import { githubMutationTool, isGithubReadOnlyOp } from "./github-side-effect";
|
|
15
18
|
import type { OutputMeta } from "./output-meta";
|
|
16
19
|
import { ToolError, throwIfAborted } from "./tool-errors";
|
|
17
20
|
import { toolResult } from "./tool-result";
|
|
21
|
+
// Not "./fetch": gh is reachable from config/settings (internal-urls ->
|
|
22
|
+
// issue-pr-protocol), and fetch would pull the web scrapers into that cycle.
|
|
23
|
+
import { wrapUntrustedContent } from "./untrusted-content";
|
|
18
24
|
|
|
19
25
|
const GH_REPO_FIELDS = [
|
|
20
26
|
"nameWithOwner",
|
|
@@ -2540,7 +2546,7 @@ async function saveArtifactText(session: ToolSession, toolType: string, text: st
|
|
|
2540
2546
|
return undefined;
|
|
2541
2547
|
}
|
|
2542
2548
|
|
|
2543
|
-
await
|
|
2549
|
+
await publishExplicitArtifactText(artifactPath, text);
|
|
2544
2550
|
return artifactId;
|
|
2545
2551
|
}
|
|
2546
2552
|
|
|
@@ -2556,11 +2562,13 @@ function buildTextResult(
|
|
|
2556
2562
|
text: string,
|
|
2557
2563
|
sourceUrl?: string,
|
|
2558
2564
|
details?: GhToolDetails,
|
|
2559
|
-
options?: { artifactId?: string; artifactLabel?: string },
|
|
2565
|
+
options?: { artifactId?: string; artifactLabel?: string; untrusted?: boolean },
|
|
2560
2566
|
): AgentToolResult<GhToolDetails> {
|
|
2561
|
-
const
|
|
2562
|
-
|
|
2563
|
-
|
|
2567
|
+
const visible = appendArtifactReference(text, options?.artifactId, options?.artifactLabel ?? "Saved artifact");
|
|
2568
|
+
// Remote GitHub prose (titles, bodies, comments, search hits, logs) is third-party text.
|
|
2569
|
+
// Pass untrusted:false only for a local confirmation that contains none of it.
|
|
2570
|
+
const modelText = options?.untrusted === false ? visible : wrapUntrustedContent(visible);
|
|
2571
|
+
const builder = toolResult<GhToolDetails>(details).text(modelText);
|
|
2564
2572
|
if (sourceUrl) {
|
|
2565
2573
|
builder.sourceUrl(sourceUrl);
|
|
2566
2574
|
}
|
|
@@ -2591,6 +2599,14 @@ export class GithubTool implements AgentTool<typeof githubSchema, GhToolDetails>
|
|
|
2591
2599
|
_context?: AgentToolContext,
|
|
2592
2600
|
): Promise<AgentToolResult<GhToolDetails>> {
|
|
2593
2601
|
return untilAborted(signal, async () => {
|
|
2602
|
+
if (!isGithubReadOnlyOp(params.op)) {
|
|
2603
|
+
await assertWorkflowMutationAllowed({
|
|
2604
|
+
cwd: this.session.cwd,
|
|
2605
|
+
sessionId: this.session.getSessionId?.() ?? undefined,
|
|
2606
|
+
tool: githubMutationTool,
|
|
2607
|
+
args: params,
|
|
2608
|
+
});
|
|
2609
|
+
}
|
|
2594
2610
|
switch (params.op) {
|
|
2595
2611
|
case "repo_view":
|
|
2596
2612
|
return executeRepoView(this.session, params, signal);
|
|
@@ -3306,6 +3322,7 @@ async function executePrPush(
|
|
|
3306
3322
|
remote: target.remoteName,
|
|
3307
3323
|
remoteBranch: target.remoteBranch,
|
|
3308
3324
|
},
|
|
3325
|
+
{ untrusted: false },
|
|
3309
3326
|
);
|
|
3310
3327
|
}
|
|
3311
3328
|
|
|
@@ -3571,7 +3588,7 @@ async function executeRunWatch(
|
|
|
3571
3588
|
pollCount,
|
|
3572
3589
|
});
|
|
3573
3590
|
onUpdate?.({
|
|
3574
|
-
content: [{ type: "text", text: formatRunWatchSnapshot(repo, run, pollCount) }],
|
|
3591
|
+
content: [{ type: "text", text: wrapUntrustedContent(formatRunWatchSnapshot(repo, run, pollCount)) }],
|
|
3575
3592
|
details,
|
|
3576
3593
|
});
|
|
3577
3594
|
|
|
@@ -3585,7 +3602,7 @@ async function executeRunWatch(
|
|
|
3585
3602
|
content: [
|
|
3586
3603
|
{
|
|
3587
3604
|
type: "text",
|
|
3588
|
-
text: formatRunWatchSnapshot(repo, run, pollCount, note),
|
|
3605
|
+
text: wrapUntrustedContent(formatRunWatchSnapshot(repo, run, pollCount, note)),
|
|
3589
3606
|
},
|
|
3590
3607
|
],
|
|
3591
3608
|
details: buildRunWatchDetails(repo, run, {
|
|
@@ -3612,7 +3629,7 @@ async function executeRunWatch(
|
|
|
3612
3629
|
const artifactId = await saveArtifactText(
|
|
3613
3630
|
session,
|
|
3614
3631
|
toolName,
|
|
3615
|
-
formatRunWatchResult(repo, run, failedJobLogs, tail, { mode: "full" }),
|
|
3632
|
+
wrapUntrustedContent(formatRunWatchResult(repo, run, failedJobLogs, tail, { mode: "full" })),
|
|
3616
3633
|
);
|
|
3617
3634
|
return buildTextResult(
|
|
3618
3635
|
formatRunWatchResult(repo, run, failedJobLogs, tail),
|
|
@@ -3650,7 +3667,12 @@ async function executeRunWatch(
|
|
|
3650
3667
|
pollCount,
|
|
3651
3668
|
});
|
|
3652
3669
|
onUpdate?.({
|
|
3653
|
-
content: [
|
|
3670
|
+
content: [
|
|
3671
|
+
{
|
|
3672
|
+
type: "text",
|
|
3673
|
+
text: wrapUntrustedContent(formatCommitRunWatchSnapshot(repo, headSha, branch, runs, pollCount)),
|
|
3674
|
+
},
|
|
3675
|
+
],
|
|
3654
3676
|
details,
|
|
3655
3677
|
});
|
|
3656
3678
|
|
|
@@ -3662,7 +3684,9 @@ async function executeRunWatch(
|
|
|
3662
3684
|
content: [
|
|
3663
3685
|
{
|
|
3664
3686
|
type: "text",
|
|
3665
|
-
text:
|
|
3687
|
+
text: wrapUntrustedContent(
|
|
3688
|
+
formatCommitRunWatchSnapshot(repo, headSha, branch, runs, pollCount, note),
|
|
3689
|
+
),
|
|
3666
3690
|
},
|
|
3667
3691
|
],
|
|
3668
3692
|
details: buildCommitRunWatchDetails(repo, headSha, branch, runs, {
|
|
@@ -3689,7 +3713,9 @@ async function executeRunWatch(
|
|
|
3689
3713
|
const artifactId = await saveArtifactText(
|
|
3690
3714
|
session,
|
|
3691
3715
|
toolName,
|
|
3692
|
-
|
|
3716
|
+
wrapUntrustedContent(
|
|
3717
|
+
formatCommitRunWatchResult(repo, headSha, branch, runs, failedJobLogs, tail, { mode: "full" }),
|
|
3718
|
+
),
|
|
3693
3719
|
);
|
|
3694
3720
|
return buildTextResult(
|
|
3695
3721
|
formatCommitRunWatchResult(repo, headSha, branch, runs, failedJobLogs, tail),
|
|
@@ -3718,7 +3744,9 @@ async function executeRunWatch(
|
|
|
3718
3744
|
content: [
|
|
3719
3745
|
{
|
|
3720
3746
|
type: "text",
|
|
3721
|
-
text:
|
|
3747
|
+
text: wrapUntrustedContent(
|
|
3748
|
+
formatCommitRunWatchSnapshot(repo, headSha, branch, runs, pollCount, note),
|
|
3749
|
+
),
|
|
3722
3750
|
},
|
|
3723
3751
|
],
|
|
3724
3752
|
details: buildCommitRunWatchDetails(repo, headSha, branch, runs, {
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Classify `github` tool operations for the approval gate and the planning
|
|
3
|
+
* mutation guard. Read-only ops stay available. Every other op, including a
|
|
4
|
+
* missing or unrecognized one, is a side effect and fails closed.
|
|
5
|
+
*/
|
|
6
|
+
import type { AgentTool } from "@sayknow-cli/agent-core";
|
|
7
|
+
|
|
8
|
+
/** Name-only tool the planning guard uses when `GithubTool.execute` checks itself. */
|
|
9
|
+
export const githubMutationTool = {
|
|
10
|
+
name: "github",
|
|
11
|
+
label: "GitHub",
|
|
12
|
+
description: "github",
|
|
13
|
+
parameters: {},
|
|
14
|
+
execute: async () => ({ content: [] }),
|
|
15
|
+
} as AgentTool;
|
|
16
|
+
|
|
17
|
+
const GITHUB_READ_ONLY_OPS = new Set([
|
|
18
|
+
"repo_view",
|
|
19
|
+
"search_issues",
|
|
20
|
+
"search_prs",
|
|
21
|
+
"search_code",
|
|
22
|
+
"search_commits",
|
|
23
|
+
"search_repos",
|
|
24
|
+
"run_watch",
|
|
25
|
+
]);
|
|
26
|
+
|
|
27
|
+
const GITHUB_SIDE_EFFECT_OPS = new Set(["pr_create", "pr_checkout", "pr_push"]);
|
|
28
|
+
|
|
29
|
+
const TITLE_MAX = 160;
|
|
30
|
+
|
|
31
|
+
function recordOf(args: unknown): Record<string, unknown> | undefined {
|
|
32
|
+
if (!args || typeof args !== "object" || Array.isArray(args)) return undefined;
|
|
33
|
+
return args as Record<string, unknown>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function stringField(record: Record<string, unknown> | undefined, key: string): string | undefined {
|
|
37
|
+
const value = record?.[key];
|
|
38
|
+
if (typeof value !== "string") return undefined;
|
|
39
|
+
const trimmed = value.trim();
|
|
40
|
+
return trimmed.length > 0 ? trimmed : undefined;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function clip(value: string): string {
|
|
44
|
+
const cleaned = value
|
|
45
|
+
.replace(/[\u0000-\u001f\u007f]/g, " ")
|
|
46
|
+
.replace(/\s+/g, " ")
|
|
47
|
+
.trim();
|
|
48
|
+
if (cleaned.length <= TITLE_MAX) return cleaned;
|
|
49
|
+
return `${cleaned.slice(0, TITLE_MAX - 1)}…`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function formatPr(value: unknown): string {
|
|
53
|
+
if (typeof value === "string" && value.trim()) return value.trim();
|
|
54
|
+
if (!Array.isArray(value)) return "the current pull request";
|
|
55
|
+
const parts = value.filter((item): item is string => typeof item === "string" && item.trim().length > 0);
|
|
56
|
+
return parts.length > 0 ? parts.join(", ") : "the current pull request";
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function githubOp(args: unknown): string | undefined {
|
|
60
|
+
const op = recordOf(args)?.op;
|
|
61
|
+
return typeof op === "string" ? op : undefined;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** True only for a known read-only github op. Missing and unknown ops are not read-only. */
|
|
65
|
+
export function isGithubReadOnlyArgs(args: unknown): boolean {
|
|
66
|
+
const op = githubOp(args);
|
|
67
|
+
return op !== undefined && GITHUB_READ_ONLY_OPS.has(op);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function isGithubReadOnlyOp(op: string): boolean {
|
|
71
|
+
return GITHUB_READ_ONLY_OPS.has(op);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Approval summary for a side-effect github call. The PR body is omitted so a
|
|
76
|
+
* token pasted into `body` is not copied into the permission title.
|
|
77
|
+
*/
|
|
78
|
+
export function describeGithubSideEffect(args: unknown): string {
|
|
79
|
+
const record = recordOf(args);
|
|
80
|
+
const op = githubOp(args) ?? "";
|
|
81
|
+
if (op === "pr_push") {
|
|
82
|
+
const branch = stringField(record, "branch") ?? "the current branch";
|
|
83
|
+
const lease = record?.forceWithLease === true ? " with --force-with-lease" : "";
|
|
84
|
+
return clip(`Push ${branch} to its pull request branch${lease} using stored git credentials`);
|
|
85
|
+
}
|
|
86
|
+
if (op === "pr_checkout") {
|
|
87
|
+
const force = record?.force === true ? " and reset the local branch" : "";
|
|
88
|
+
return clip(
|
|
89
|
+
`Check out ${formatPr(record?.pr)} into ~/.skc/wt, write branch git config, and may add a remote${force}`,
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
if (op === "pr_create") {
|
|
93
|
+
const repo = stringField(record, "repo") ?? "the current repository";
|
|
94
|
+
const head = stringField(record, "head") ?? "the current branch";
|
|
95
|
+
const base = stringField(record, "base") ?? "the default base";
|
|
96
|
+
return clip(`Create a pull request on ${repo} from ${head} into ${base} with gh`);
|
|
97
|
+
}
|
|
98
|
+
return "Run a github operation that is not read-only";
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function githubPermissionIntent(
|
|
102
|
+
args: unknown,
|
|
103
|
+
): { toolName: string; title: string; cacheKey: string } | undefined {
|
|
104
|
+
if (isGithubReadOnlyArgs(args)) return undefined;
|
|
105
|
+
const op = githubOp(args);
|
|
106
|
+
const cacheOp = op && GITHUB_SIDE_EFFECT_OPS.has(op) ? op : "unspecified";
|
|
107
|
+
return {
|
|
108
|
+
toolName: "github",
|
|
109
|
+
title: describeGithubSideEffect(args),
|
|
110
|
+
cacheKey: `github:${cacheOp}`,
|
|
111
|
+
};
|
|
112
|
+
}
|