@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
|
@@ -15,6 +15,8 @@ import type { AuthStorage } from "@sayknow-cli/ai";
|
|
|
15
15
|
|
|
16
16
|
import type { SearchResponse, SearchSource } from "../../../web/search/types";
|
|
17
17
|
import { SearchProviderError } from "../../../web/search/types";
|
|
18
|
+
import type { AddressResolver } from "../../insane/url-guard";
|
|
19
|
+
import { guardedPublicFetch, validatePublicHttpUrl } from "../../insane/url-guard";
|
|
18
20
|
import { clampNumResults } from "../utils";
|
|
19
21
|
import type { SearchParams } from "./base";
|
|
20
22
|
import { SearchProvider } from "./base";
|
|
@@ -24,7 +26,10 @@ import { withHardTimeout } from "./utils";
|
|
|
24
26
|
const DEFAULT_NUM_RESULTS = 10;
|
|
25
27
|
const MAX_NUM_RESULTS = 20;
|
|
26
28
|
const PUBLIC_ROUTE_TIMEOUT_MS = 15_000;
|
|
29
|
+
const MAX_PUBLIC_ROUTE_REDIRECTS = 5;
|
|
30
|
+
const REDIRECT_STATUSES = new Set([301, 302, 303, 307, 308]);
|
|
27
31
|
const DISCOVERY_LIMIT = 8;
|
|
32
|
+
const MAX_PUBLIC_ROUTE_RESPONSE_BYTES = 1024 * 1024;
|
|
28
33
|
|
|
29
34
|
const USER_AGENT = "Sayknow-CLI insane-search safe-public-routes/1.0 (+https://github.com/jaybeyond/Sayknow_CLI)";
|
|
30
35
|
|
|
@@ -146,20 +151,111 @@ function attempt(
|
|
|
146
151
|
return { platform, route, ok, status, bytes: new TextEncoder().encode(body).byteLength, note };
|
|
147
152
|
}
|
|
148
153
|
|
|
154
|
+
class ResponseTooLargeError extends Error {
|
|
155
|
+
override readonly name = "response_too_large";
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
class PublicUrlRejectedError extends Error {
|
|
159
|
+
override readonly name = "public_url_rejected";
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
async function cancelBody(body: ReadableStream<Uint8Array> | null): Promise<void> {
|
|
163
|
+
if (!body) return;
|
|
164
|
+
try {
|
|
165
|
+
await body.cancel();
|
|
166
|
+
} catch {
|
|
167
|
+
// Best-effort teardown; preserve the stable size-limit diagnostic.
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
async function readResponseText(response: Response): Promise<string> {
|
|
172
|
+
const contentLength = response.headers.get("content-length");
|
|
173
|
+
if (contentLength !== null) {
|
|
174
|
+
const declaredBytes = Number.parseInt(contentLength, 10);
|
|
175
|
+
if (Number.isFinite(declaredBytes) && declaredBytes > MAX_PUBLIC_ROUTE_RESPONSE_BYTES) {
|
|
176
|
+
await cancelBody(response.body);
|
|
177
|
+
throw new ResponseTooLargeError();
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const reader = response.body?.getReader();
|
|
182
|
+
if (!reader) return "";
|
|
183
|
+
|
|
184
|
+
const decoder = new TextDecoder();
|
|
185
|
+
let totalBytes = 0;
|
|
186
|
+
let text = "";
|
|
187
|
+
try {
|
|
188
|
+
while (true) {
|
|
189
|
+
const { done, value } = await reader.read();
|
|
190
|
+
if (done) break;
|
|
191
|
+
if (!value || value.byteLength === 0) continue;
|
|
192
|
+
|
|
193
|
+
totalBytes += value.byteLength;
|
|
194
|
+
if (totalBytes > MAX_PUBLIC_ROUTE_RESPONSE_BYTES) {
|
|
195
|
+
try {
|
|
196
|
+
await reader.cancel();
|
|
197
|
+
} catch {
|
|
198
|
+
// Best-effort teardown; preserve the stable size-limit diagnostic.
|
|
199
|
+
}
|
|
200
|
+
throw new ResponseTooLargeError();
|
|
201
|
+
}
|
|
202
|
+
text += decoder.decode(value, { stream: true });
|
|
203
|
+
}
|
|
204
|
+
text += decoder.decode();
|
|
205
|
+
return text;
|
|
206
|
+
} finally {
|
|
207
|
+
reader.releaseLock();
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
149
211
|
async function fetchText(
|
|
150
212
|
url: string,
|
|
151
213
|
signal?: AbortSignal,
|
|
214
|
+
resolverOption?: { resolver?: AddressResolver },
|
|
152
215
|
): Promise<{ status: number; text: string; contentType: string }> {
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
216
|
+
const deadline = withHardTimeout(signal, PUBLIC_ROUTE_TIMEOUT_MS);
|
|
217
|
+
let currentUrl = url;
|
|
218
|
+
|
|
219
|
+
for (let redirectCount = 0; ; redirectCount++) {
|
|
220
|
+
// Fresh GET each hop: no body and no caller auth headers. guardedPublicFetch forces redirect:"manual".
|
|
221
|
+
const dial = await guardedPublicFetch(
|
|
222
|
+
currentUrl,
|
|
223
|
+
{
|
|
224
|
+
method: "GET",
|
|
225
|
+
headers: {
|
|
226
|
+
Accept:
|
|
227
|
+
"application/json, application/atom+xml, application/rss+xml, text/xml, text/html;q=0.8, */*;q=0.5",
|
|
228
|
+
"User-Agent": USER_AGENT,
|
|
229
|
+
},
|
|
230
|
+
redirect: "manual",
|
|
231
|
+
signal: deadline,
|
|
232
|
+
},
|
|
233
|
+
resolverOption,
|
|
234
|
+
);
|
|
235
|
+
if (!dial.ok) throw new PublicUrlRejectedError(dial.reason);
|
|
236
|
+
|
|
237
|
+
const { response, logicalUrl } = dial;
|
|
238
|
+
if (!REDIRECT_STATUSES.has(response.status)) {
|
|
239
|
+
const text = await readResponseText(response);
|
|
240
|
+
return { status: response.status, text, contentType: response.headers.get("content-type") ?? "" };
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const location = response.headers.get("location")?.trim();
|
|
244
|
+
await cancelBody(response.body);
|
|
245
|
+
if (!location) throw new PublicUrlRejectedError("redirect missing Location");
|
|
246
|
+
if (redirectCount >= MAX_PUBLIC_ROUTE_REDIRECTS) throw new PublicUrlRejectedError("redirect limit exceeded");
|
|
247
|
+
|
|
248
|
+
let nextUrl: URL;
|
|
249
|
+
try {
|
|
250
|
+
nextUrl = new URL(location, logicalUrl);
|
|
251
|
+
} catch {
|
|
252
|
+
throw new PublicUrlRejectedError("invalid redirect Location");
|
|
253
|
+
}
|
|
254
|
+
const guard = await validatePublicHttpUrl(nextUrl.href, { signal: deadline, resolver: resolverOption?.resolver });
|
|
255
|
+
if (deadline.aborted) throw deadline.reason;
|
|
256
|
+
if (!guard.ok) throw new PublicUrlRejectedError(guard.reason);
|
|
257
|
+
currentUrl = guard.url.href;
|
|
258
|
+
}
|
|
163
259
|
}
|
|
164
260
|
|
|
165
261
|
function attr(input: string, name: string): string | undefined {
|
|
@@ -213,11 +309,15 @@ function redditFeedUrls(url: URL): string[] {
|
|
|
213
309
|
return [`${base}/.rss`, `${base}.rss`];
|
|
214
310
|
}
|
|
215
311
|
|
|
216
|
-
async function routeReddit(
|
|
312
|
+
async function routeReddit(
|
|
313
|
+
url: URL,
|
|
314
|
+
signal?: AbortSignal,
|
|
315
|
+
resolverOption?: { resolver?: AddressResolver },
|
|
316
|
+
): Promise<RouteResult> {
|
|
217
317
|
const attempts: InsaneRouteAttempt[] = [];
|
|
218
318
|
for (const feedUrl of redditFeedUrls(url)) {
|
|
219
319
|
try {
|
|
220
|
-
const response = await fetchText(feedUrl, signal);
|
|
320
|
+
const response = await fetchText(feedUrl, signal, resolverOption);
|
|
221
321
|
const ok = response.status === 200 && /<(feed|rss)\b/i.test(response.text) && !isBlockedBody(response.text);
|
|
222
322
|
attempts.push(attempt("reddit", "rss", ok, response.status, response.text, ok ? "feed" : "no-feed-markers"));
|
|
223
323
|
if (ok)
|
|
@@ -271,13 +371,17 @@ function sourceFromOEmbed(raw: string, url: string): SearchSource | null {
|
|
|
271
371
|
return { title, url: data.url ?? url, snippet, author: data.author_name };
|
|
272
372
|
}
|
|
273
373
|
|
|
274
|
-
async function routeX(
|
|
374
|
+
async function routeX(
|
|
375
|
+
url: URL,
|
|
376
|
+
signal?: AbortSignal,
|
|
377
|
+
resolverOption?: { resolver?: AddressResolver },
|
|
378
|
+
): Promise<RouteResult> {
|
|
275
379
|
const attempts: InsaneRouteAttempt[] = [];
|
|
276
380
|
const id = tweetId(url);
|
|
277
381
|
if (id) {
|
|
278
382
|
const tweetResultUrl = `https://cdn.syndication.twimg.com/tweet-result?id=${encodeURIComponent(id)}&token=a`;
|
|
279
383
|
try {
|
|
280
|
-
const response = await fetchText(tweetResultUrl, signal);
|
|
384
|
+
const response = await fetchText(tweetResultUrl, signal, resolverOption);
|
|
281
385
|
const source =
|
|
282
386
|
response.status === 200 && !isBlockedBody(response.text)
|
|
283
387
|
? sourceFromTweetJson(response.text, url.toString())
|
|
@@ -292,7 +396,7 @@ async function routeX(url: URL, signal?: AbortSignal): Promise<RouteResult> {
|
|
|
292
396
|
}
|
|
293
397
|
const oembedUrl = `https://publish.twitter.com/oembed?url=${encodeURIComponent(`https://twitter.com/i/status/${id}`)}&omit_script=1`;
|
|
294
398
|
try {
|
|
295
|
-
const response = await fetchText(oembedUrl, signal);
|
|
399
|
+
const response = await fetchText(oembedUrl, signal, resolverOption);
|
|
296
400
|
const source =
|
|
297
401
|
response.status === 200 && !isBlockedBody(response.text)
|
|
298
402
|
? sourceFromOEmbed(response.text, oembedUrl)
|
|
@@ -309,7 +413,7 @@ async function routeX(url: URL, signal?: AbortSignal): Promise<RouteResult> {
|
|
|
309
413
|
if (handle) {
|
|
310
414
|
const timelineUrl = `https://syndication.twitter.com/srv/timeline-profile/screen-name/${encodeURIComponent(handle)}`;
|
|
311
415
|
try {
|
|
312
|
-
const response = await fetchText(timelineUrl, signal);
|
|
416
|
+
const response = await fetchText(timelineUrl, signal, resolverOption);
|
|
313
417
|
const ok = response.status === 200 && response.text.includes("__NEXT_DATA__") && !isBlockedBody(response.text);
|
|
314
418
|
attempts.push(
|
|
315
419
|
attempt("x", "syndication-timeline", ok, response.status, response.text, ok ? "timeline" : "no-next-data"),
|
|
@@ -342,14 +446,18 @@ function youtubeVideoId(url: URL): string | null {
|
|
|
342
446
|
return url.searchParams.get("v") ?? url.pathname.match(/\/shorts\/([^/?#]+)/)?.[1] ?? null;
|
|
343
447
|
}
|
|
344
448
|
|
|
345
|
-
async function routeYouTube(
|
|
449
|
+
async function routeYouTube(
|
|
450
|
+
url: URL,
|
|
451
|
+
signal?: AbortSignal,
|
|
452
|
+
resolverOption?: { resolver?: AddressResolver },
|
|
453
|
+
): Promise<RouteResult> {
|
|
346
454
|
const attempts: InsaneRouteAttempt[] = [];
|
|
347
455
|
const videoId = youtubeVideoId(url);
|
|
348
456
|
if (videoId) {
|
|
349
457
|
const watchUrl = `https://www.youtube.com/watch?v=${encodeURIComponent(videoId)}`;
|
|
350
458
|
const oembedUrl = `https://www.youtube.com/oembed?url=${encodeURIComponent(watchUrl)}&format=json`;
|
|
351
459
|
try {
|
|
352
|
-
const response = await fetchText(oembedUrl, signal);
|
|
460
|
+
const response = await fetchText(oembedUrl, signal, resolverOption);
|
|
353
461
|
const source =
|
|
354
462
|
response.status === 200 && !isBlockedBody(response.text) ? sourceFromOEmbed(response.text, watchUrl) : null;
|
|
355
463
|
attempts.push(
|
|
@@ -364,7 +472,7 @@ async function routeYouTube(url: URL, signal?: AbortSignal): Promise<RouteResult
|
|
|
364
472
|
if (channelId) {
|
|
365
473
|
const feedUrl = `https://www.youtube.com/feeds/videos.xml?channel_id=${encodeURIComponent(channelId)}`;
|
|
366
474
|
try {
|
|
367
|
-
const response = await fetchText(feedUrl, signal);
|
|
475
|
+
const response = await fetchText(feedUrl, signal, resolverOption);
|
|
368
476
|
const ok = response.status === 200 && /<feed\b/i.test(response.text) && !isBlockedBody(response.text);
|
|
369
477
|
attempts.push(attempt("youtube", "feed", ok, response.status, response.text, ok ? "feed" : "no-feed"));
|
|
370
478
|
if (ok)
|
|
@@ -412,13 +520,17 @@ function hnSourceFromItem(raw: string): SearchSource | null {
|
|
|
412
520
|
};
|
|
413
521
|
}
|
|
414
522
|
|
|
415
|
-
async function routeHackerNews(
|
|
523
|
+
async function routeHackerNews(
|
|
524
|
+
url: URL,
|
|
525
|
+
signal?: AbortSignal,
|
|
526
|
+
resolverOption?: { resolver?: AddressResolver },
|
|
527
|
+
): Promise<RouteResult> {
|
|
416
528
|
const attempts: InsaneRouteAttempt[] = [];
|
|
417
529
|
const id = hnItemId(url);
|
|
418
530
|
if (!id) return { platform: "hackernews", attempts };
|
|
419
531
|
const itemUrl = `https://hacker-news.firebaseio.com/v0/item/${encodeURIComponent(id)}.json`;
|
|
420
532
|
try {
|
|
421
|
-
const response = await fetchText(itemUrl, signal);
|
|
533
|
+
const response = await fetchText(itemUrl, signal, resolverOption);
|
|
422
534
|
const source = response.status === 200 && !isBlockedBody(response.text) ? hnSourceFromItem(response.text) : null;
|
|
423
535
|
attempts.push(
|
|
424
536
|
attempt("hackernews", "firebase-item", !!source, response.status, response.text, source ? "item" : "no-item"),
|
|
@@ -433,14 +545,18 @@ async function routeHackerNews(url: URL, signal?: AbortSignal): Promise<RouteRes
|
|
|
433
545
|
return { platform: "hackernews", attempts };
|
|
434
546
|
}
|
|
435
547
|
|
|
436
|
-
export async function routeInsanePublicUrl(
|
|
548
|
+
export async function routeInsanePublicUrl(
|
|
549
|
+
rawUrl: string,
|
|
550
|
+
signal?: AbortSignal,
|
|
551
|
+
resolverOption?: { resolver?: AddressResolver },
|
|
552
|
+
): Promise<RouteResult> {
|
|
437
553
|
const url = parseHttpUrl(rawUrl);
|
|
438
554
|
if (!url) return null;
|
|
439
555
|
const platform = detectPlatform(url);
|
|
440
|
-
if (platform === "reddit") return routeReddit(url, signal);
|
|
441
|
-
if (platform === "x") return routeX(url, signal);
|
|
442
|
-
if (platform === "youtube") return routeYouTube(url, signal);
|
|
443
|
-
if (platform === "hackernews") return routeHackerNews(url, signal);
|
|
556
|
+
if (platform === "reddit") return routeReddit(url, signal, resolverOption);
|
|
557
|
+
if (platform === "x") return routeX(url, signal, resolverOption);
|
|
558
|
+
if (platform === "youtube") return routeYouTube(url, signal, resolverOption);
|
|
559
|
+
if (platform === "hackernews") return routeHackerNews(url, signal, resolverOption);
|
|
444
560
|
return null;
|
|
445
561
|
}
|
|
446
562
|
|
|
@@ -474,9 +590,10 @@ export async function searchInsane(params: {
|
|
|
474
590
|
num_results?: number;
|
|
475
591
|
recency?: "day" | "week" | "month" | "year";
|
|
476
592
|
signal?: AbortSignal;
|
|
593
|
+
resolverOption?: { resolver?: AddressResolver };
|
|
477
594
|
}): Promise<SearchResponse> {
|
|
478
595
|
const numResults = clampNumResults(params.num_results, DEFAULT_NUM_RESULTS, MAX_NUM_RESULTS);
|
|
479
|
-
const direct = await routeInsanePublicUrl(params.query, params.signal);
|
|
596
|
+
const direct = await routeInsanePublicUrl(params.query, params.signal, params.resolverOption);
|
|
480
597
|
if (isSuccess(direct) && direct.sources.length > 0) {
|
|
481
598
|
return {
|
|
482
599
|
provider: "insane",
|
|
@@ -506,7 +623,7 @@ export async function searchInsane(params: {
|
|
|
506
623
|
const seenUrls = new Set<string>();
|
|
507
624
|
for (const candidate of discovery.sources) {
|
|
508
625
|
if (routedSources.length >= numResults) break;
|
|
509
|
-
const routed = await routeInsanePublicUrl(candidate.url, params.signal);
|
|
626
|
+
const routed = await routeInsanePublicUrl(candidate.url, params.signal, params.resolverOption);
|
|
510
627
|
if (routed && "attempts" in routed) attempts.push(...routed.attempts);
|
|
511
628
|
if (!isSuccess(routed)) continue;
|
|
512
629
|
for (const source of routed.sources) {
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Endpoint: POST https://api.kimi.com/coding/v1/search
|
|
6
6
|
*/
|
|
7
7
|
import type { AuthStorage } from "@sayknow-cli/ai";
|
|
8
|
-
import { $
|
|
8
|
+
import { $credentialEnv } from "@sayknow-cli/utils";
|
|
9
9
|
|
|
10
10
|
import type { SearchResponse, SearchSource } from "../../../web/search/types";
|
|
11
11
|
import { SearchProviderError } from "../../../web/search/types";
|
|
@@ -55,8 +55,17 @@ function asTrimmed(value: string | undefined): string | undefined {
|
|
|
55
55
|
return trimmed.length > 0 ? trimmed : undefined;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
/** Test seam: the Kimi search base URL as resolved from trusted env. */
|
|
59
|
+
export function resolveKimiSearchBaseUrlForTest(): string {
|
|
60
|
+
return resolveBaseUrl();
|
|
61
|
+
}
|
|
62
|
+
|
|
58
63
|
function resolveBaseUrl(): string {
|
|
59
|
-
return
|
|
64
|
+
return (
|
|
65
|
+
asTrimmed($credentialEnv("MOONSHOT_SEARCH_BASE_URL")) ??
|
|
66
|
+
asTrimmed($credentialEnv("KIMI_SEARCH_BASE_URL")) ??
|
|
67
|
+
KIMI_SEARCH_URL
|
|
68
|
+
);
|
|
60
69
|
}
|
|
61
70
|
|
|
62
71
|
/** Find Kimi search credentials from environment or AuthStorage. */
|
|
@@ -65,7 +74,8 @@ async function findApiKey(
|
|
|
65
74
|
sessionId: string | undefined,
|
|
66
75
|
signal: AbortSignal | undefined,
|
|
67
76
|
): Promise<string | null> {
|
|
68
|
-
const envKey =
|
|
77
|
+
const envKey =
|
|
78
|
+
asTrimmed($credentialEnv("MOONSHOT_SEARCH_API_KEY")) ?? asTrimmed($credentialEnv("KIMI_SEARCH_API_KEY"));
|
|
69
79
|
if (envKey) return envKey;
|
|
70
80
|
|
|
71
81
|
return (
|
|
@@ -157,8 +167,8 @@ export class KimiProvider extends SearchProvider {
|
|
|
157
167
|
|
|
158
168
|
isAvailable(authStorage: AuthStorage): boolean {
|
|
159
169
|
return (
|
|
160
|
-
!!asTrimmed($
|
|
161
|
-
!!asTrimmed($
|
|
170
|
+
!!asTrimmed($credentialEnv("MOONSHOT_SEARCH_API_KEY")) ||
|
|
171
|
+
!!asTrimmed($credentialEnv("KIMI_SEARCH_API_KEY")) ||
|
|
162
172
|
authStorage.hasAuth("moonshot") ||
|
|
163
173
|
authStorage.hasAuth("kimi-code")
|
|
164
174
|
);
|
|
@@ -25,7 +25,9 @@
|
|
|
25
25
|
* Reference: https://docs.searxng.org/dev/search_api.html
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
|
+
import * as path from "node:path";
|
|
28
29
|
import type { AuthStorage } from "@sayknow-cli/ai";
|
|
30
|
+
import { $credentialEnv, parseEnvFile } from "@sayknow-cli/utils";
|
|
29
31
|
|
|
30
32
|
import { settings } from "../../../config/settings";
|
|
31
33
|
import type { SearchResponse, SearchSource } from "../../../web/search/types";
|
|
@@ -74,6 +76,47 @@ interface SearXNGAuth {
|
|
|
74
76
|
}
|
|
75
77
|
|
|
76
78
|
/** Find SearXNG endpoint from settings or environment. */
|
|
79
|
+
/**
|
|
80
|
+
* SearXNG environment value, from trusted sources only, preserving an
|
|
81
|
+
* intentionally empty setting.
|
|
82
|
+
*
|
|
83
|
+
* These four names decide where search requests go and what credential they
|
|
84
|
+
* carry, and `$env` merges the caller's `cwd/.env` into `process.env`, so a
|
|
85
|
+
* repository could otherwise redirect the search and hand over the basic-auth
|
|
86
|
+
* material.
|
|
87
|
+
*
|
|
88
|
+
* `$credentialEnv` is the resolver for that boundary, but it collapses an empty
|
|
89
|
+
* value to `undefined` — and SearXNG basic auth treats "set but empty" as
|
|
90
|
+
* meaningful (`alice:` and `:s3cret` are both valid). So an empty value is
|
|
91
|
+
* recovered explicitly, and only when the project `.env` is not what set it.
|
|
92
|
+
*/
|
|
93
|
+
function trustedSearxngEnv(name: string): string | null {
|
|
94
|
+
const trusted = $credentialEnv(name);
|
|
95
|
+
if (trusted !== undefined) return trusted;
|
|
96
|
+
|
|
97
|
+
const raw = process.env[name];
|
|
98
|
+
if (raw === undefined || raw.trim().length > 0) return null;
|
|
99
|
+
// Empty-but-set. Honour it unless the project `.env` is the source.
|
|
100
|
+
const projectValue = parseEnvFile(path.join(process.cwd(), ".env"))[name];
|
|
101
|
+
if (projectValue !== undefined && projectValue.trim().length === 0) return null;
|
|
102
|
+
return "";
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Test seam: the SearXNG endpoint and auth material as resolved from trusted env. */
|
|
106
|
+
export function resolveSearxngConfigForTest(): {
|
|
107
|
+
endpoint: string | null;
|
|
108
|
+
token: string | null;
|
|
109
|
+
basicUsername: string | null;
|
|
110
|
+
basicPassword: string | null;
|
|
111
|
+
} {
|
|
112
|
+
return {
|
|
113
|
+
endpoint: findEndpoint(),
|
|
114
|
+
token: findToken(),
|
|
115
|
+
basicUsername: findBasicUsername(),
|
|
116
|
+
basicPassword: findBasicPassword(),
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
77
120
|
function findEndpoint(): string | null {
|
|
78
121
|
try {
|
|
79
122
|
const endpoint = settings.get("searxng.endpoint");
|
|
@@ -81,7 +124,7 @@ function findEndpoint(): string | null {
|
|
|
81
124
|
} catch {
|
|
82
125
|
// Settings not initialized yet
|
|
83
126
|
}
|
|
84
|
-
return
|
|
127
|
+
return trustedSearxngEnv("SEARXNG_ENDPOINT");
|
|
85
128
|
}
|
|
86
129
|
|
|
87
130
|
/** Find SearXNG bearer token from settings or environment. */
|
|
@@ -92,7 +135,7 @@ function findToken(): string | null {
|
|
|
92
135
|
} catch {
|
|
93
136
|
// Settings not initialized yet
|
|
94
137
|
}
|
|
95
|
-
return
|
|
138
|
+
return trustedSearxngEnv("SEARXNG_TOKEN");
|
|
96
139
|
}
|
|
97
140
|
|
|
98
141
|
/** Find SearXNG Basic auth username from settings or environment. */
|
|
@@ -103,7 +146,7 @@ function findBasicUsername(): string | null {
|
|
|
103
146
|
} catch {
|
|
104
147
|
// Settings not initialized yet
|
|
105
148
|
}
|
|
106
|
-
return
|
|
149
|
+
return trustedSearxngEnv("SEARXNG_BASIC_USERNAME");
|
|
107
150
|
}
|
|
108
151
|
|
|
109
152
|
/** Find SearXNG Basic auth password from settings or environment. */
|
|
@@ -114,7 +157,7 @@ function findBasicPassword(): string | null {
|
|
|
114
157
|
} catch {
|
|
115
158
|
// Settings not initialized yet
|
|
116
159
|
}
|
|
117
|
-
return
|
|
160
|
+
return trustedSearxngEnv("SEARXNG_BASIC_PASSWORD");
|
|
118
161
|
}
|
|
119
162
|
|
|
120
163
|
/** Build the RFC 7617 Basic auth credential using UTF-8 bytes. */
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Endpoint: POST https://api.x.ai/v1/responses
|
|
6
6
|
*/
|
|
7
7
|
import type { AuthStorage } from "@sayknow-cli/ai";
|
|
8
|
-
import { $env } from "@sayknow-cli/utils";
|
|
8
|
+
import { $credentialEnv, $env } from "@sayknow-cli/utils";
|
|
9
9
|
import type { SearchCitation, SearchResponse, SearchSource, SearchUsage } from "../../../web/search/types";
|
|
10
10
|
import { SearchProviderError } from "../../../web/search/types";
|
|
11
11
|
import type { SearchParams } from "./base";
|
|
@@ -71,8 +71,13 @@ function getModel(): string {
|
|
|
71
71
|
return asTrimmed($env.PI_XAI_WEB_SEARCH_MODEL) ?? asTrimmed($env.XAI_WEB_SEARCH_MODEL) ?? DEFAULT_MODEL;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
+
/** Test seam: the xAI search base URL as resolved from trusted env. */
|
|
75
|
+
export function resolveXaiSearchBaseUrlForTest(): string {
|
|
76
|
+
return getBaseUrl();
|
|
77
|
+
}
|
|
78
|
+
|
|
74
79
|
function getBaseUrl(): string {
|
|
75
|
-
return asTrimmed($
|
|
80
|
+
return asTrimmed($credentialEnv("XAI_SEARCH_BASE_URL")) ?? DEFAULT_BASE_URL;
|
|
76
81
|
}
|
|
77
82
|
|
|
78
83
|
function responsesEndpoint(): string {
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export interface ShellCommandArgs {
|
|
2
|
-
cwd?: string;
|
|
3
|
-
timeoutMs?: number;
|
|
4
|
-
noSnapshot?: boolean;
|
|
5
|
-
}
|
|
6
|
-
export declare function parseShellArgs(args: string[]): ShellCommandArgs | undefined;
|
|
7
|
-
export declare function runShellCommand(cmd: ShellCommandArgs): Promise<void>;
|
|
8
|
-
export declare function printShellHelp(): void;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Interactive shell console.
|
|
3
|
-
*/
|
|
4
|
-
import { Command } from "@sayknow-cli/utils/cli";
|
|
5
|
-
export default class Shell extends Command {
|
|
6
|
-
static description: string;
|
|
7
|
-
static flags: {
|
|
8
|
-
cwd: import("@sayknow-cli/utils/cli").FlagDescriptor<"string"> & {
|
|
9
|
-
char: string;
|
|
10
|
-
description: string;
|
|
11
|
-
};
|
|
12
|
-
timeout: import("@sayknow-cli/utils/cli").FlagDescriptor<"integer"> & {
|
|
13
|
-
char: string;
|
|
14
|
-
description: string;
|
|
15
|
-
};
|
|
16
|
-
"no-snapshot": import("@sayknow-cli/utils/cli").FlagDescriptor<"boolean"> & {
|
|
17
|
-
description: string;
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
run(): Promise<void>;
|
|
21
|
-
}
|
package/src/cli/shell-cli.ts
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shell CLI command handlers.
|
|
3
|
-
*
|
|
4
|
-
* Handles `skc shell` subcommand for testing the native brush-core shell.
|
|
5
|
-
*/
|
|
6
|
-
import * as path from "node:path";
|
|
7
|
-
import { createInterface } from "node:readline/promises";
|
|
8
|
-
import { Shell } from "@sayknow-cli/natives";
|
|
9
|
-
import { APP_NAME, getProjectDir } from "@sayknow-cli/utils";
|
|
10
|
-
import chalk from "chalk";
|
|
11
|
-
import { Settings } from "../config/settings";
|
|
12
|
-
import { buildMinimizerOptions } from "../exec/bash-executor";
|
|
13
|
-
import { getOrCreateSnapshot } from "../utils/shell-snapshot";
|
|
14
|
-
|
|
15
|
-
export interface ShellCommandArgs {
|
|
16
|
-
cwd?: string;
|
|
17
|
-
timeoutMs?: number;
|
|
18
|
-
noSnapshot?: boolean;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function parseShellArgs(args: string[]): ShellCommandArgs | undefined {
|
|
22
|
-
if (args.length === 0 || args[0] !== "shell") {
|
|
23
|
-
return undefined;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const result: ShellCommandArgs = {};
|
|
27
|
-
|
|
28
|
-
for (let i = 1; i < args.length; i++) {
|
|
29
|
-
const arg = args[i];
|
|
30
|
-
if (arg === "--cwd" || arg === "-C") {
|
|
31
|
-
result.cwd = args[++i];
|
|
32
|
-
} else if (arg === "--timeout" || arg === "-t") {
|
|
33
|
-
const parsed = Number.parseInt(args[++i], 10);
|
|
34
|
-
if (Number.isFinite(parsed)) {
|
|
35
|
-
result.timeoutMs = parsed;
|
|
36
|
-
}
|
|
37
|
-
} else if (arg === "--no-snapshot") {
|
|
38
|
-
result.noSnapshot = true;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return result;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export async function runShellCommand(cmd: ShellCommandArgs): Promise<void> {
|
|
46
|
-
if (!process.stdin.isTTY) {
|
|
47
|
-
process.stderr.write("Error: shell console requires an interactive TTY.\n");
|
|
48
|
-
process.exit(1);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const cwd = cmd.cwd ? path.resolve(cmd.cwd) : getProjectDir();
|
|
52
|
-
const settings = await Settings.init({ cwd });
|
|
53
|
-
const { shell, env: shellEnv } = settings.getShellConfig();
|
|
54
|
-
const snapshotPath = cmd.noSnapshot || !shell.includes("bash") ? null : await getOrCreateSnapshot(shell, shellEnv);
|
|
55
|
-
const minimizer = buildMinimizerOptions(settings.getGroup("shellMinimizer"));
|
|
56
|
-
const shellSession = new Shell({ sessionEnv: shellEnv, snapshotPath: snapshotPath ?? undefined, minimizer });
|
|
57
|
-
|
|
58
|
-
let active = false;
|
|
59
|
-
let lastChar: string | null = null;
|
|
60
|
-
|
|
61
|
-
const rl = createInterface({ input: process.stdin, output: process.stdout, terminal: true });
|
|
62
|
-
const prompt = chalk.cyan(`${APP_NAME} shell> `);
|
|
63
|
-
|
|
64
|
-
const printHelp = () => {
|
|
65
|
-
process.stdout.write(
|
|
66
|
-
`${chalk.bold("Shell Console Commands")}
|
|
67
|
-
|
|
68
|
-
` +
|
|
69
|
-
`${chalk.bold("Special Commands:")}
|
|
70
|
-
.help Show this help
|
|
71
|
-
.exit, exit Exit the console
|
|
72
|
-
|
|
73
|
-
` +
|
|
74
|
-
`${chalk.bold("Options:")}
|
|
75
|
-
--cwd, -C <path> Set working directory for commands
|
|
76
|
-
--timeout, -t <ms> Timeout per command in milliseconds
|
|
77
|
-
--no-snapshot Skip sourcing snapshot from user shell
|
|
78
|
-
|
|
79
|
-
` +
|
|
80
|
-
`${chalk.bold("Notes:")}
|
|
81
|
-
Runs in a persistent brush-core shell session.
|
|
82
|
-
Variables and functions defined in one command persist for the next.
|
|
83
|
-
|
|
84
|
-
`,
|
|
85
|
-
);
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
const interruptHandler = () => {
|
|
89
|
-
if (active) {
|
|
90
|
-
void shellSession.abort();
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
rl.close();
|
|
94
|
-
process.exit(0);
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
process.on("SIGINT", interruptHandler);
|
|
98
|
-
process.stdout.write(chalk.dim("Type .help for commands.\n"));
|
|
99
|
-
|
|
100
|
-
try {
|
|
101
|
-
while (true) {
|
|
102
|
-
const line = (await rl.question(prompt)).trim();
|
|
103
|
-
if (!line) {
|
|
104
|
-
continue;
|
|
105
|
-
}
|
|
106
|
-
if (line === ".help") {
|
|
107
|
-
printHelp();
|
|
108
|
-
continue;
|
|
109
|
-
}
|
|
110
|
-
if (line === ".exit" || line === "exit" || line === "quit") {
|
|
111
|
-
break;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
active = true;
|
|
115
|
-
lastChar = null;
|
|
116
|
-
try {
|
|
117
|
-
const result = await shellSession.run(
|
|
118
|
-
{
|
|
119
|
-
command: line,
|
|
120
|
-
cwd,
|
|
121
|
-
timeoutMs: cmd.timeoutMs,
|
|
122
|
-
},
|
|
123
|
-
(err, chunk) => {
|
|
124
|
-
if (err) {
|
|
125
|
-
process.stderr.write(`${err.message}\n`);
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
if (chunk.length > 0) {
|
|
129
|
-
lastChar = chunk[chunk.length - 1] ?? null;
|
|
130
|
-
}
|
|
131
|
-
process.stdout.write(chunk);
|
|
132
|
-
},
|
|
133
|
-
);
|
|
134
|
-
|
|
135
|
-
if (lastChar && lastChar !== "\n") {
|
|
136
|
-
process.stdout.write("\n");
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
if (result.timedOut) {
|
|
140
|
-
process.stderr.write(chalk.yellow("Command timed out.\n"));
|
|
141
|
-
} else if (result.cancelled) {
|
|
142
|
-
process.stderr.write(chalk.yellow("Command cancelled.\n"));
|
|
143
|
-
} else if (result.exitCode !== 0 && result.exitCode !== undefined) {
|
|
144
|
-
process.stderr.write(chalk.yellow(`Exit code: ${result.exitCode}\n`));
|
|
145
|
-
}
|
|
146
|
-
} catch (err) {
|
|
147
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
148
|
-
process.stderr.write(chalk.red(`Error: ${message}\n`));
|
|
149
|
-
} finally {
|
|
150
|
-
active = false;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
} finally {
|
|
154
|
-
process.off("SIGINT", interruptHandler);
|
|
155
|
-
rl.close();
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
export function printShellHelp(): void {
|
|
160
|
-
process.stdout.write(`${chalk.bold(`${APP_NAME} shell`)} - Interactive shell console for testing
|
|
161
|
-
|
|
162
|
-
${chalk.bold("Usage:")}
|
|
163
|
-
${APP_NAME} shell [options]
|
|
164
|
-
|
|
165
|
-
${chalk.bold("Options:")}
|
|
166
|
-
--cwd, -C <path> Set working directory for commands
|
|
167
|
-
--timeout, -t <ms> Timeout per command in milliseconds
|
|
168
|
-
--no-snapshot Skip sourcing snapshot from user shell
|
|
169
|
-
-h, --help Show this help
|
|
170
|
-
|
|
171
|
-
${chalk.bold("Examples:")}
|
|
172
|
-
${APP_NAME} shell
|
|
173
|
-
${APP_NAME} shell --cwd ./tmp
|
|
174
|
-
${APP_NAME} shell --timeout 2000
|
|
175
|
-
`);
|
|
176
|
-
}
|