@kr78/pi-coding-agent 17.2.10
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 +14861 -0
- package/README.md +35 -0
- package/dist/CHANGELOG-chtdxh1z.md +14861 -0
- package/dist/cli.js +20483 -0
- package/dist/template-c2hyaytt.js +1653 -0
- package/dist/template-f8wx9vfn.css +1355 -0
- package/dist/template-qat058wr.html +55 -0
- package/dist/tool-views.generated-jdfmzwmn.js +35 -0
- package/examples/README.md +21 -0
- package/examples/custom-tools/README.md +104 -0
- package/examples/custom-tools/hello/index.ts +20 -0
- package/examples/extensions/README.md +142 -0
- package/examples/extensions/api-demo.ts +78 -0
- package/examples/extensions/chalk-logger.ts +25 -0
- package/examples/extensions/hello.ts +31 -0
- package/examples/extensions/pirate.ts +43 -0
- package/examples/extensions/plan-mode.ts +549 -0
- package/examples/extensions/reload-runtime.ts +38 -0
- package/examples/extensions/thinking-note.ts +13 -0
- package/examples/extensions/tools.ts +145 -0
- package/examples/extensions/with-deps/index.ts +36 -0
- package/examples/extensions/with-deps/package-lock.json +31 -0
- package/examples/extensions/with-deps/package.json +17 -0
- package/examples/hooks/README.md +56 -0
- package/examples/hooks/auto-commit-on-exit.ts +48 -0
- package/examples/hooks/confirm-destructive.ts +58 -0
- package/examples/hooks/custom-compaction.ts +115 -0
- package/examples/hooks/dirty-repo-guard.ts +51 -0
- package/examples/hooks/file-trigger.ts +40 -0
- package/examples/hooks/git-checkpoint.ts +52 -0
- package/examples/hooks/handoff.ts +149 -0
- package/examples/hooks/permission-gate.ts +33 -0
- package/examples/hooks/protected-paths.ts +29 -0
- package/examples/hooks/qna.ts +118 -0
- package/examples/hooks/status-line.ts +39 -0
- package/examples/sdk/01-minimal.ts +21 -0
- package/examples/sdk/02-custom-model.ts +49 -0
- package/examples/sdk/03-custom-prompt.ts +46 -0
- package/examples/sdk/04-skills.ts +43 -0
- package/examples/sdk/06-extensions.ts +82 -0
- package/examples/sdk/06-hooks.ts +61 -0
- package/examples/sdk/07-context-files.ts +35 -0
- package/examples/sdk/08-prompt-templates.ts +41 -0
- package/examples/sdk/08-slash-commands.ts +46 -0
- package/examples/sdk/09-api-keys-and-oauth.ts +54 -0
- package/examples/sdk/11-sessions.ts +47 -0
- package/examples/sdk/12-redis-sessions.ts +54 -0
- package/examples/sdk/13-sql-sessions.ts +61 -0
- package/examples/sdk/README.md +169 -0
- package/package.json +587 -0
- package/scripts/bench-guard.ts +71 -0
- package/scripts/bench-title-models.ts +332 -0
- package/scripts/build-binary.ts +117 -0
- package/scripts/bundle-dist.ts +123 -0
- package/scripts/compile-binary.ts +69 -0
- package/scripts/embed-mupdf-wasm.ts +67 -0
- package/scripts/format-prompts.ts +68 -0
- package/scripts/generate-aria-snapshot.ts +134 -0
- package/scripts/generate-docs-index.ts +58 -0
- package/scripts/generate-share-viewer.ts +34 -0
- package/scripts/legacy-pi-virtual-module.ts +205 -0
- package/scripts/measure-prompt-tokens.ts +63 -0
- package/scripts/omp +51 -0
- package/scripts/omp.ts +19 -0
- package/scripts/security-compare.ts +40 -0
- package/src/advisor/advise-tool.ts +234 -0
- package/src/advisor/config.ts +341 -0
- package/src/advisor/emission-guard.ts +172 -0
- package/src/advisor/index.ts +6 -0
- package/src/advisor/runtime.ts +1412 -0
- package/src/advisor/transcript-recorder.ts +215 -0
- package/src/advisor/watchdog.ts +135 -0
- package/src/async/index.ts +1 -0
- package/src/async/job-manager.ts +847 -0
- package/src/auto-thinking/classifier.ts +220 -0
- package/src/autolearn/controller.ts +152 -0
- package/src/autolearn/managed-skills.ts +255 -0
- package/src/autoresearch/command-resume.md +14 -0
- package/src/autoresearch/dashboard.ts +436 -0
- package/src/autoresearch/git.ts +331 -0
- package/src/autoresearch/helpers.ts +218 -0
- package/src/autoresearch/index.ts +541 -0
- package/src/autoresearch/prompt-setup.md +43 -0
- package/src/autoresearch/prompt.md +103 -0
- package/src/autoresearch/resume-message.md +10 -0
- package/src/autoresearch/state.ts +273 -0
- package/src/autoresearch/storage.ts +700 -0
- package/src/autoresearch/tools/init-experiment.ts +268 -0
- package/src/autoresearch/tools/log-experiment.ts +520 -0
- package/src/autoresearch/tools/run-experiment.ts +407 -0
- package/src/autoresearch/tools/update-notes.ts +109 -0
- package/src/autoresearch/types.ts +168 -0
- package/src/capability/context-file.ts +44 -0
- package/src/capability/extension-module.ts +34 -0
- package/src/capability/extension.ts +47 -0
- package/src/capability/fs.ts +117 -0
- package/src/capability/hook.ts +40 -0
- package/src/capability/index.ts +467 -0
- package/src/capability/instruction.ts +37 -0
- package/src/capability/mcp.ts +115 -0
- package/src/capability/prompt.ts +35 -0
- package/src/capability/rule-buckets.ts +66 -0
- package/src/capability/rule.ts +298 -0
- package/src/capability/settings.ts +34 -0
- package/src/capability/skill.ts +69 -0
- package/src/capability/slash-command.ts +40 -0
- package/src/capability/ssh.ts +41 -0
- package/src/capability/system-prompt.ts +34 -0
- package/src/capability/tool.ts +38 -0
- package/src/capability/types.ts +187 -0
- package/src/cleanse/agent.ts +226 -0
- package/src/cleanse/balance.ts +79 -0
- package/src/cleanse/checkers.ts +996 -0
- package/src/cleanse/index.ts +190 -0
- package/src/cleanse/loop.ts +51 -0
- package/src/cleanse/parsers.ts +726 -0
- package/src/cleanse/progress.ts +50 -0
- package/src/cleanse/prompts/assignment.md +47 -0
- package/src/cleanse/types.ts +72 -0
- package/src/cli/agents-cli.ts +138 -0
- package/src/cli/args.ts +368 -0
- package/src/cli/auth-broker-cli.ts +940 -0
- package/src/cli/auth-gateway-cli.ts +674 -0
- package/src/cli/bench-cli.ts +990 -0
- package/src/cli/browser-relay-cli.ts +119 -0
- package/src/cli/classify-install-target.ts +76 -0
- package/src/cli/claude-trace-cli.ts +795 -0
- package/src/cli/command-help.ts +107 -0
- package/src/cli/commands/init-xdg.ts +27 -0
- package/src/cli/completion-gen.ts +550 -0
- package/src/cli/config-cli.ts +459 -0
- package/src/cli/dry-balance-cli.ts +864 -0
- package/src/cli/extension-flags.ts +48 -0
- package/src/cli/file-processor.ts +132 -0
- package/src/cli/flag-tables.ts +367 -0
- package/src/cli/gallery-cli.ts +272 -0
- package/src/cli/gallery-fixtures/agentic.ts +420 -0
- package/src/cli/gallery-fixtures/codeintel.ts +187 -0
- package/src/cli/gallery-fixtures/edit.ts +254 -0
- package/src/cli/gallery-fixtures/fs.ts +245 -0
- package/src/cli/gallery-fixtures/index.ts +40 -0
- package/src/cli/gallery-fixtures/interaction.ts +46 -0
- package/src/cli/gallery-fixtures/memory.ts +81 -0
- package/src/cli/gallery-fixtures/misc.ts +177 -0
- package/src/cli/gallery-fixtures/search.ts +135 -0
- package/src/cli/gallery-fixtures/shell.ts +241 -0
- package/src/cli/gallery-fixtures/types.ts +57 -0
- package/src/cli/gallery-fixtures/web.ts +158 -0
- package/src/cli/gallery-screenshot.ts +279 -0
- package/src/cli/gc-cli.ts +1566 -0
- package/src/cli/grep-cli.ts +161 -0
- package/src/cli/grievances-cli.ts +256 -0
- package/src/cli/help-extra.ts +89 -0
- package/src/cli/initial-message.ts +58 -0
- package/src/cli/models-cli.ts +385 -0
- package/src/cli/plugin-cli.ts +996 -0
- package/src/cli/profile-alias.ts +369 -0
- package/src/cli/profile-bootstrap.ts +233 -0
- package/src/cli/read-cli.ts +99 -0
- package/src/cli/session-picker.ts +110 -0
- package/src/cli/setup-cli.ts +312 -0
- package/src/cli/setup-model-picker.ts +43 -0
- package/src/cli/shell-cli.ts +176 -0
- package/src/cli/ssh-cli.ts +179 -0
- package/src/cli/startup-cwd.ts +58 -0
- package/src/cli/stats-cli.ts +229 -0
- package/src/cli/thinking-levels.ts +7 -0
- package/src/cli/tiny-models-cli.ts +153 -0
- package/src/cli/ttsr-cli.ts +1013 -0
- package/src/cli/update-cli.ts +1184 -0
- package/src/cli/usage-cli.ts +1084 -0
- package/src/cli/usage-error.ts +7 -0
- package/src/cli/web-search-cli.ts +144 -0
- package/src/cli/worktree-cli.ts +311 -0
- package/src/cli-commands.ts +308 -0
- package/src/cli.ts +428 -0
- package/src/collab/crypto.ts +63 -0
- package/src/collab/display-name.ts +13 -0
- package/src/collab/guest.ts +764 -0
- package/src/collab/host.ts +692 -0
- package/src/collab/protocol.ts +296 -0
- package/src/collab/relay-client.ts +282 -0
- package/src/collab/replication-shrink.ts +111 -0
- package/src/commands/acp.ts +35 -0
- package/src/commands/agents.ts +58 -0
- package/src/commands/auth-broker.ts +100 -0
- package/src/commands/auth-gateway.ts +70 -0
- package/src/commands/bench.ts +64 -0
- package/src/commands/browser-relay.ts +53 -0
- package/src/commands/cleanse.ts +45 -0
- package/src/commands/commit.ts +47 -0
- package/src/commands/complete.ts +67 -0
- package/src/commands/completions.ts +61 -0
- package/src/commands/config.ts +52 -0
- package/src/commands/dry-balance.ts +43 -0
- package/src/commands/gallery.ts +61 -0
- package/src/commands/gc.ts +47 -0
- package/src/commands/grep.ts +49 -0
- package/src/commands/grievances.ts +52 -0
- package/src/commands/install.ts +107 -0
- package/src/commands/join.ts +40 -0
- package/src/commands/launch-help.ts +116 -0
- package/src/commands/launch.ts +34 -0
- package/src/commands/models.ts +61 -0
- package/src/commands/plugin.ts +79 -0
- package/src/commands/read.ts +39 -0
- package/src/commands/say.ts +146 -0
- package/src/commands/setup.ts +68 -0
- package/src/commands/share.ts +71 -0
- package/src/commands/shell.ts +30 -0
- package/src/commands/ssh.ts +61 -0
- package/src/commands/stats.ts +30 -0
- package/src/commands/tiny-models.ts +36 -0
- package/src/commands/token.ts +164 -0
- package/src/commands/ttsr.ts +125 -0
- package/src/commands/update.ts +34 -0
- package/src/commands/usage.ts +55 -0
- package/src/commands/web-search.ts +43 -0
- package/src/commands/worktree.ts +63 -0
- package/src/commit/agentic/agent.ts +322 -0
- package/src/commit/agentic/fallback.ts +96 -0
- package/src/commit/agentic/index.ts +383 -0
- package/src/commit/agentic/lock-files.ts +107 -0
- package/src/commit/agentic/prompts/analyze-file.md +22 -0
- package/src/commit/agentic/prompts/session-user.md +25 -0
- package/src/commit/agentic/prompts/split-confirm.md +1 -0
- package/src/commit/agentic/prompts/system.md +38 -0
- package/src/commit/agentic/state.ts +60 -0
- package/src/commit/agentic/tools/analyze-file.ts +148 -0
- package/src/commit/agentic/tools/git-file-diff.ts +191 -0
- package/src/commit/agentic/tools/git-hunk.ts +52 -0
- package/src/commit/agentic/tools/git-overview.ts +62 -0
- package/src/commit/agentic/tools/index.ts +54 -0
- package/src/commit/agentic/tools/propose-changelog.ts +147 -0
- package/src/commit/agentic/tools/propose-commit.ts +109 -0
- package/src/commit/agentic/tools/recent-commits.ts +81 -0
- package/src/commit/agentic/tools/schemas.ts +11 -0
- package/src/commit/agentic/tools/split-commit.ts +241 -0
- package/src/commit/agentic/topo-sort.ts +44 -0
- package/src/commit/agentic/trivial.ts +51 -0
- package/src/commit/agentic/validation.ts +183 -0
- package/src/commit/analysis/conventional.ts +64 -0
- package/src/commit/analysis/index.ts +4 -0
- package/src/commit/analysis/scope.ts +242 -0
- package/src/commit/analysis/summary.ts +107 -0
- package/src/commit/analysis/validation.ts +66 -0
- package/src/commit/changelog/detect.ts +40 -0
- package/src/commit/changelog/generate.ts +101 -0
- package/src/commit/changelog/index.ts +234 -0
- package/src/commit/changelog/parse.ts +44 -0
- package/src/commit/cli.ts +85 -0
- package/src/commit/git/diff.ts +148 -0
- package/src/commit/index.ts +5 -0
- package/src/commit/map-reduce/index.ts +69 -0
- package/src/commit/map-reduce/map-phase.ts +193 -0
- package/src/commit/map-reduce/reduce-phase.ts +49 -0
- package/src/commit/map-reduce/utils.ts +9 -0
- package/src/commit/message.ts +11 -0
- package/src/commit/model-selection.ts +95 -0
- package/src/commit/pipeline.ts +244 -0
- package/src/commit/prompts/analysis-system.md +148 -0
- package/src/commit/prompts/analysis-user.md +38 -0
- package/src/commit/prompts/changelog-system.md +50 -0
- package/src/commit/prompts/changelog-user.md +18 -0
- package/src/commit/prompts/file-observer-system.md +24 -0
- package/src/commit/prompts/file-observer-user.md +8 -0
- package/src/commit/prompts/reduce-system.md +50 -0
- package/src/commit/prompts/reduce-user.md +17 -0
- package/src/commit/prompts/summary-retry.md +3 -0
- package/src/commit/prompts/summary-system.md +38 -0
- package/src/commit/prompts/summary-user.md +13 -0
- package/src/commit/prompts/types-description.md +2 -0
- package/src/commit/shared-llm.ts +70 -0
- package/src/commit/types.ts +118 -0
- package/src/commit/utils/exclusions.ts +42 -0
- package/src/commit/utils.ts +58 -0
- package/src/config/api-key-resolver.ts +81 -0
- package/src/config/append-only-context-mode.ts +76 -0
- package/src/config/config-file.ts +347 -0
- package/src/config/inline-tool-descriptors-mode.ts +26 -0
- package/src/config/keybindings.ts +703 -0
- package/src/config/mcp-schema.json +252 -0
- package/src/config/model-discovery.ts +1077 -0
- package/src/config/model-registry.ts +2822 -0
- package/src/config/model-resolver.ts +2115 -0
- package/src/config/model-roles.ts +113 -0
- package/src/config/models-config-schema-bundle.ts +315 -0
- package/src/config/models-config-schema.ts +14 -0
- package/src/config/models-config.ts +130 -0
- package/src/config/prompt-templates.ts +205 -0
- package/src/config/provider-globals.ts +25 -0
- package/src/config/resolve-config-value.ts +95 -0
- package/src/config/service-tier.ts +146 -0
- package/src/config/settings-schema.ts +5887 -0
- package/src/config/settings.ts +2394 -0
- package/src/config.ts +242 -0
- package/src/cursor-bridge-tools.ts +81 -0
- package/src/cursor.ts +960 -0
- package/src/dap/client.ts +1043 -0
- package/src/dap/config.ts +480 -0
- package/src/dap/defaults.json +212 -0
- package/src/dap/index.ts +4 -0
- package/src/dap/session.ts +1841 -0
- package/src/dap/types.ts +611 -0
- package/src/debug/index.ts +584 -0
- package/src/debug/log-formatting.ts +58 -0
- package/src/debug/log-viewer.ts +966 -0
- package/src/debug/profiler.ts +168 -0
- package/src/debug/protocol-probe.ts +267 -0
- package/src/debug/raw-sse-buffer.ts +421 -0
- package/src/debug/raw-sse.ts +312 -0
- package/src/debug/remote-debugger.ts +151 -0
- package/src/debug/report-bundle.ts +411 -0
- package/src/debug/system-info.ts +111 -0
- package/src/debug/terminal-info.ts +124 -0
- package/src/discovery/agent-plugin-format.ts +551 -0
- package/src/discovery/agent-plugins.ts +341 -0
- package/src/discovery/agents-md.ts +67 -0
- package/src/discovery/agents.ts +300 -0
- package/src/discovery/at-imports.ts +273 -0
- package/src/discovery/builtin-defaults.ts +39 -0
- package/src/discovery/builtin-rules/go-add-cleanup.md +33 -0
- package/src/discovery/builtin-rules/go-bench-loop.md +36 -0
- package/src/discovery/builtin-rules/go-exp-promoted.md +40 -0
- package/src/discovery/builtin-rules/go-ioutil.md +37 -0
- package/src/discovery/builtin-rules/go-join-hostport.md +30 -0
- package/src/discovery/builtin-rules/go-new-expr.md +44 -0
- package/src/discovery/builtin-rules/go-rand-v2.md +41 -0
- package/src/discovery/builtin-rules/go-range-int.md +45 -0
- package/src/discovery/builtin-rules/index.ts +74 -0
- package/src/discovery/builtin-rules/rs-box-leak.md +49 -0
- package/src/discovery/builtin-rules/rs-future-prelude.md +24 -0
- package/src/discovery/builtin-rules/rs-lazylock.md +52 -0
- package/src/discovery/builtin-rules/rs-match-ergonomics.md +68 -0
- package/src/discovery/builtin-rules/rs-parking-lot.md +45 -0
- package/src/discovery/builtin-rules/rs-result-type.md +20 -0
- package/src/discovery/builtin-rules/ts-bare-catch.md +39 -0
- package/src/discovery/builtin-rules/ts-import-type.md +43 -0
- package/src/discovery/builtin-rules/ts-no-any.md +66 -0
- package/src/discovery/builtin-rules/ts-no-deprecated-leftovers.md +45 -0
- package/src/discovery/builtin-rules/ts-no-dynamic-import.md +40 -0
- package/src/discovery/builtin-rules/ts-no-inline-cast-access.md +56 -0
- package/src/discovery/builtin-rules/ts-no-local-is-record.md +48 -0
- package/src/discovery/builtin-rules/ts-no-return-type.md +45 -0
- package/src/discovery/builtin-rules/ts-no-test-timers.md +55 -0
- package/src/discovery/builtin-rules/ts-no-tiny-functions.md +51 -0
- package/src/discovery/builtin-rules/ts-promise-with-resolvers.md +66 -0
- package/src/discovery/builtin-rules/ts-redundant-clear-guard.md +75 -0
- package/src/discovery/builtin-rules/ts-set-map.md +28 -0
- package/src/discovery/builtin.ts +945 -0
- package/src/discovery/claude-plugins.ts +640 -0
- package/src/discovery/claude.ts +591 -0
- package/src/discovery/cline.ts +83 -0
- package/src/discovery/codex.ts +553 -0
- package/src/discovery/contained-path.ts +78 -0
- package/src/discovery/cursor.ts +223 -0
- package/src/discovery/gemini.ts +386 -0
- package/src/discovery/github.ts +337 -0
- package/src/discovery/helpers.ts +1183 -0
- package/src/discovery/index.ts +82 -0
- package/src/discovery/mcp-json.ts +182 -0
- package/src/discovery/omp-extension-roots.ts +272 -0
- package/src/discovery/omp-plugins.ts +409 -0
- package/src/discovery/opencode.ts +441 -0
- package/src/discovery/plugin-dir-roots.ts +28 -0
- package/src/discovery/ssh.ts +153 -0
- package/src/discovery/substitute-plugin-root.ts +77 -0
- package/src/discovery/vscode.ts +106 -0
- package/src/discovery/windsurf.ts +149 -0
- package/src/edit/apply-patch/index.ts +87 -0
- package/src/edit/apply-patch/parser.ts +174 -0
- package/src/edit/diff.ts +1008 -0
- package/src/edit/edit-clipboard.ts +23 -0
- package/src/edit/file-snapshot-store.ts +148 -0
- package/src/edit/hashline/block-resolver.ts +33 -0
- package/src/edit/hashline/diff.ts +402 -0
- package/src/edit/hashline/execute.ts +313 -0
- package/src/edit/hashline/filesystem.ts +247 -0
- package/src/edit/hashline/index.ts +5 -0
- package/src/edit/hashline/noop-loop-guard.ts +99 -0
- package/src/edit/hashline/params.ts +12 -0
- package/src/edit/index.ts +699 -0
- package/src/edit/modes/apply-patch.lark +19 -0
- package/src/edit/modes/apply-patch.ts +53 -0
- package/src/edit/modes/patch.ts +1958 -0
- package/src/edit/modes/replace.ts +1191 -0
- package/src/edit/normalize.ts +345 -0
- package/src/edit/notebook.ts +242 -0
- package/src/edit/read-file.ts +25 -0
- package/src/edit/renderer.ts +998 -0
- package/src/edit/snapshot-details.ts +77 -0
- package/src/edit/streaming.ts +710 -0
- package/src/eval/agent-bridge.ts +224 -0
- package/src/eval/backend-helpers.ts +48 -0
- package/src/eval/backend.ts +71 -0
- package/src/eval/bridge-timeout.ts +65 -0
- package/src/eval/budget-bridge.ts +48 -0
- package/src/eval/completion-bridge.ts +212 -0
- package/src/eval/concurrency-bridge.ts +34 -0
- package/src/eval/executor-base.ts +562 -0
- package/src/eval/idle-timeout.ts +91 -0
- package/src/eval/index.ts +6 -0
- package/src/eval/jl/executor.ts +551 -0
- package/src/eval/jl/index.ts +54 -0
- package/src/eval/jl/kernel.ts +236 -0
- package/src/eval/jl/prelude.jl +736 -0
- package/src/eval/jl/prelude.ts +3 -0
- package/src/eval/jl/runner.jl +666 -0
- package/src/eval/jl/runtime.ts +118 -0
- package/src/eval/js/context-manager.ts +872 -0
- package/src/eval/js/executor.ts +178 -0
- package/src/eval/js/index.ts +41 -0
- package/src/eval/js/process-entry.ts +31 -0
- package/src/eval/js/shared/helpers.ts +170 -0
- package/src/eval/js/shared/indirect-eval.ts +30 -0
- package/src/eval/js/shared/local-module-loader.ts +364 -0
- package/src/eval/js/shared/prelude.ts +2 -0
- package/src/eval/js/shared/prelude.txt +294 -0
- package/src/eval/js/shared/rewrite-imports.ts +550 -0
- package/src/eval/js/shared/runtime.ts +590 -0
- package/src/eval/js/shared/types.ts +18 -0
- package/src/eval/js/tool-bridge.ts +163 -0
- package/src/eval/js/worker-core.ts +380 -0
- package/src/eval/js/worker-entry.ts +37 -0
- package/src/eval/js/worker-protocol.ts +47 -0
- package/src/eval/kernel-base.ts +569 -0
- package/src/eval/py/display.ts +71 -0
- package/src/eval/py/executor.ts +643 -0
- package/src/eval/py/index.ts +57 -0
- package/src/eval/py/kernel.ts +235 -0
- package/src/eval/py/prelude.py +673 -0
- package/src/eval/py/prelude.ts +3 -0
- package/src/eval/py/runner.py +1425 -0
- package/src/eval/py/runtime.ts +276 -0
- package/src/eval/py/spawn-options.ts +134 -0
- package/src/eval/py/tool-bridge.ts +201 -0
- package/src/eval/rb/executor.ts +511 -0
- package/src/eval/rb/index.ts +54 -0
- package/src/eval/rb/kernel.ts +231 -0
- package/src/eval/rb/prelude.rb +551 -0
- package/src/eval/rb/prelude.ts +3 -0
- package/src/eval/rb/runner.rb +581 -0
- package/src/eval/rb/runtime.ts +132 -0
- package/src/eval/runtime-env.ts +104 -0
- package/src/eval/session-id.ts +8 -0
- package/src/eval/types.ts +48 -0
- package/src/exa/index.ts +2 -0
- package/src/exa/mcp-client.ts +370 -0
- package/src/exa/types.ts +69 -0
- package/src/exec/bash-executor.ts +627 -0
- package/src/exec/direnv.ts +145 -0
- package/src/exec/exec.ts +53 -0
- package/src/exec/non-interactive-env.ts +118 -0
- package/src/export/custom-share.ts +65 -0
- package/src/export/html/args.ts +20 -0
- package/src/export/html/index.ts +320 -0
- package/src/export/html/share-loader.js +102 -0
- package/src/export/html/template.css +1355 -0
- package/src/export/html/template.html +55 -0
- package/src/export/html/template.js +1653 -0
- package/src/export/html/tool-views.generated.js +35 -0
- package/src/export/html/vendor/highlight.min.js +1213 -0
- package/src/export/html/vendor/marked.min.js +6 -0
- package/src/export/html/web-palette.ts +126 -0
- package/src/export/share.ts +686 -0
- package/src/export/ttsr.ts +590 -0
- package/src/extensibility/custom-commands/bundled/ci-green/index.ts +54 -0
- package/src/extensibility/custom-commands/bundled/review/index.ts +698 -0
- package/src/extensibility/custom-commands/index.ts +2 -0
- package/src/extensibility/custom-commands/loader.ts +242 -0
- package/src/extensibility/custom-commands/types.ts +119 -0
- package/src/extensibility/custom-tools/index.ts +7 -0
- package/src/extensibility/custom-tools/loader.ts +301 -0
- package/src/extensibility/custom-tools/types.ts +287 -0
- package/src/extensibility/custom-tools/wrapper.ts +50 -0
- package/src/extensibility/extensions/compact-handler.ts +40 -0
- package/src/extensibility/extensions/get-commands-handler.ts +78 -0
- package/src/extensibility/extensions/index.ts +16 -0
- package/src/extensibility/extensions/load-errors.ts +13 -0
- package/src/extensibility/extensions/loader.ts +663 -0
- package/src/extensibility/extensions/managed-timers.ts +83 -0
- package/src/extensibility/extensions/model-api.ts +39 -0
- package/src/extensibility/extensions/runner.ts +1396 -0
- package/src/extensibility/extensions/types.ts +1603 -0
- package/src/extensibility/extensions/wrapper.ts +395 -0
- package/src/extensibility/hooks/index.ts +6 -0
- package/src/extensibility/hooks/loader.ts +243 -0
- package/src/extensibility/hooks/runner.ts +425 -0
- package/src/extensibility/hooks/tool-wrapper.ts +124 -0
- package/src/extensibility/hooks/types.ts +612 -0
- package/src/extensibility/legacy-pi-ai-shim.ts +161 -0
- package/src/extensibility/legacy-pi-coding-agent-shim.ts +1460 -0
- package/src/extensibility/legacy-pi-tui-shim.ts +43 -0
- package/src/extensibility/legacy-typebox.ts +101 -0
- package/src/extensibility/plugins/bun-git-cache.ts +91 -0
- package/src/extensibility/plugins/doctor.ts +65 -0
- package/src/extensibility/plugins/git-url.ts +367 -0
- package/src/extensibility/plugins/index.ts +9 -0
- package/src/extensibility/plugins/installer.ts +201 -0
- package/src/extensibility/plugins/legacy-pi-compat.ts +2643 -0
- package/src/extensibility/plugins/legacy-pi-virtual-modules.d.ts +4 -0
- package/src/extensibility/plugins/loader.ts +535 -0
- package/src/extensibility/plugins/manager.ts +1142 -0
- package/src/extensibility/plugins/marketplace/cache.ts +136 -0
- package/src/extensibility/plugins/marketplace/fetcher.ts +316 -0
- package/src/extensibility/plugins/marketplace/index.ts +6 -0
- package/src/extensibility/plugins/marketplace/manager.ts +927 -0
- package/src/extensibility/plugins/marketplace/registry.ts +192 -0
- package/src/extensibility/plugins/marketplace/source-resolver.ts +147 -0
- package/src/extensibility/plugins/marketplace/types.ts +192 -0
- package/src/extensibility/plugins/marketplace-auto-update.ts +49 -0
- package/src/extensibility/plugins/parser.ts +107 -0
- package/src/extensibility/plugins/runtime-config.ts +9 -0
- package/src/extensibility/plugins/types.ts +194 -0
- package/src/extensibility/session-handler-types.ts +21 -0
- package/src/extensibility/shared-events.ts +401 -0
- package/src/extensibility/skills.ts +531 -0
- package/src/extensibility/slash-commands.ts +131 -0
- package/src/extensibility/tool-event-input.ts +80 -0
- package/src/extensibility/tool-proxy.ts +28 -0
- package/src/extensibility/utils.ts +192 -0
- package/src/goals/index.ts +3 -0
- package/src/goals/runtime.ts +521 -0
- package/src/goals/state.ts +37 -0
- package/src/goals/tools/goal-tool.ts +251 -0
- package/src/hindsight/backend.ts +354 -0
- package/src/hindsight/bank.ts +156 -0
- package/src/hindsight/client.ts +680 -0
- package/src/hindsight/config.ts +193 -0
- package/src/hindsight/content.ts +266 -0
- package/src/hindsight/index.ts +8 -0
- package/src/hindsight/mental-models.ts +429 -0
- package/src/hindsight/seeds.json +32 -0
- package/src/hindsight/state.ts +530 -0
- package/src/hindsight/transcript.ts +71 -0
- package/src/index.ts +66 -0
- package/src/internal-urls/agent-protocol.ts +180 -0
- package/src/internal-urls/artifact-protocol.ts +151 -0
- package/src/internal-urls/docs-index.ts +102 -0
- package/src/internal-urls/filesystem-resource.ts +34 -0
- package/src/internal-urls/history-protocol.ts +198 -0
- package/src/internal-urls/index.ts +28 -0
- package/src/internal-urls/issue-pr-protocol.ts +594 -0
- package/src/internal-urls/json-query.ts +126 -0
- package/src/internal-urls/local-protocol.ts +471 -0
- package/src/internal-urls/mcp-protocol.ts +168 -0
- package/src/internal-urls/memory-protocol.ts +380 -0
- package/src/internal-urls/omp-protocol.ts +94 -0
- package/src/internal-urls/parse.ts +103 -0
- package/src/internal-urls/registry-helpers.ts +132 -0
- package/src/internal-urls/router.ts +153 -0
- package/src/internal-urls/rule-protocol.ts +45 -0
- package/src/internal-urls/security-protocol.ts +261 -0
- package/src/internal-urls/skill-protocol.ts +131 -0
- package/src/internal-urls/ssh-protocol.ts +368 -0
- package/src/internal-urls/types.ts +196 -0
- package/src/internal-urls/vault-protocol.ts +940 -0
- package/src/internal-urls/xd-protocol.ts +46 -0
- package/src/irc/bus.ts +380 -0
- package/src/jsonrpc/message-framing.ts +142 -0
- package/src/launch/broker.ts +1368 -0
- package/src/launch/client.ts +521 -0
- package/src/launch/ensure.ts +73 -0
- package/src/launch/paths.ts +14 -0
- package/src/launch/presence.ts +82 -0
- package/src/launch/protocol.ts +448 -0
- package/src/launch/spawn-options.ts +17 -0
- package/src/launch/terminal-output-worker-client.ts +53 -0
- package/src/launch/terminal-output-worker-protocol.ts +11 -0
- package/src/launch/terminal-output-worker.ts +23 -0
- package/src/launch/terminal-output.ts +46 -0
- package/src/lib/xai-http.ts +150 -0
- package/src/live/attestation.ts +91 -0
- package/src/live/controller.ts +517 -0
- package/src/live/prompts/agent-final-message.md +3 -0
- package/src/live/prompts/live-instructions.md +23 -0
- package/src/live/protocol.ts +233 -0
- package/src/live/transport.ts +422 -0
- package/src/live/visualizer.ts +221 -0
- package/src/live/voices.ts +18 -0
- package/src/lsp/client.ts +1465 -0
- package/src/lsp/clients/biome-client.ts +263 -0
- package/src/lsp/clients/index.ts +50 -0
- package/src/lsp/clients/lsp-linter-client.ts +85 -0
- package/src/lsp/clients/swiftlint-client.ts +120 -0
- package/src/lsp/config.ts +549 -0
- package/src/lsp/defaults.json +499 -0
- package/src/lsp/deferred-diagnostics.ts +66 -0
- package/src/lsp/diagnostics-ledger.ts +51 -0
- package/src/lsp/edits.ts +288 -0
- package/src/lsp/format-options.ts +119 -0
- package/src/lsp/index.ts +2821 -0
- package/src/lsp/lspmux.ts +233 -0
- package/src/lsp/mux/daemon.ts +348 -0
- package/src/lsp/mux/protocol.ts +96 -0
- package/src/lsp/mux/server.ts +797 -0
- package/src/lsp/render.ts +668 -0
- package/src/lsp/startup-events.ts +13 -0
- package/src/lsp/types.ts +479 -0
- package/src/lsp/utils.ts +747 -0
- package/src/main.ts +1799 -0
- package/src/markit/NOTICE +32 -0
- package/src/markit/converters/docx.ts +56 -0
- package/src/markit/converters/epub.ts +136 -0
- package/src/markit/converters/pdf/columns.ts +103 -0
- package/src/markit/converters/pdf/extract.ts +598 -0
- package/src/markit/converters/pdf/grid.ts +780 -0
- package/src/markit/converters/pdf/headers.ts +106 -0
- package/src/markit/converters/pdf/index.ts +146 -0
- package/src/markit/converters/pdf/render.ts +501 -0
- package/src/markit/converters/pdf/types.ts +84 -0
- package/src/markit/converters/pptx.ts +325 -0
- package/src/markit/converters/xlsx.ts +173 -0
- package/src/markit/index.ts +2 -0
- package/src/markit/registry.ts +59 -0
- package/src/markit/types.ts +35 -0
- package/src/mcp/client.ts +511 -0
- package/src/mcp/config-writer.ts +377 -0
- package/src/mcp/config.ts +385 -0
- package/src/mcp/index.ts +29 -0
- package/src/mcp/json-rpc.ts +122 -0
- package/src/mcp/loader.ts +125 -0
- package/src/mcp/manager.ts +1524 -0
- package/src/mcp/oauth-credentials.ts +104 -0
- package/src/mcp/oauth-discovery.ts +587 -0
- package/src/mcp/oauth-flow.ts +830 -0
- package/src/mcp/render.ts +214 -0
- package/src/mcp/request-id.ts +24 -0
- package/src/mcp/smithery-auth.ts +108 -0
- package/src/mcp/smithery-connect.ts +154 -0
- package/src/mcp/smithery-registry.ts +500 -0
- package/src/mcp/startup-events.ts +116 -0
- package/src/mcp/timeout.ts +59 -0
- package/src/mcp/tool-bridge.ts +691 -0
- package/src/mcp/tool-cache.ts +117 -0
- package/src/mcp/transports/header-policy.ts +95 -0
- package/src/mcp/transports/http.ts +508 -0
- package/src/mcp/transports/index.ts +7 -0
- package/src/mcp/transports/sse.ts +372 -0
- package/src/mcp/transports/stdio.ts +905 -0
- package/src/mcp/types.ts +467 -0
- package/src/memories/index.ts +1434 -0
- package/src/memories/storage.ts +578 -0
- package/src/memory-backend/index.ts +19 -0
- package/src/memory-backend/local-backend.ts +47 -0
- package/src/memory-backend/messages.ts +19 -0
- package/src/memory-backend/off-backend.ts +25 -0
- package/src/memory-backend/resolve.ts +25 -0
- package/src/memory-backend/runtime.ts +66 -0
- package/src/memory-backend/tool-names.ts +2 -0
- package/src/memory-backend/types.ts +166 -0
- package/src/mnemopi/backend.ts +629 -0
- package/src/mnemopi/config.ts +267 -0
- package/src/mnemopi/embed-client.ts +293 -0
- package/src/mnemopi/embed-protocol.ts +35 -0
- package/src/mnemopi/embed-worker.ts +114 -0
- package/src/mnemopi/index.ts +3 -0
- package/src/mnemopi/state.ts +940 -0
- package/src/modes/acp/acp-agent.ts +2595 -0
- package/src/modes/acp/acp-client-bridge.ts +154 -0
- package/src/modes/acp/acp-event-mapper.ts +1084 -0
- package/src/modes/acp/acp-mode.ts +48 -0
- package/src/modes/acp/index.ts +2 -0
- package/src/modes/acp/terminal-auth.ts +37 -0
- package/src/modes/components/advisor-config.ts +635 -0
- package/src/modes/components/advisor-message.ts +109 -0
- package/src/modes/components/agent-dashboard.ts +1252 -0
- package/src/modes/components/agent-hub-projection.ts +248 -0
- package/src/modes/components/agent-hub-renderer.ts +194 -0
- package/src/modes/components/agent-hub.ts +1126 -0
- package/src/modes/components/agent-transcript-viewer.ts +647 -0
- package/src/modes/components/ask-dialog.ts +1017 -0
- package/src/modes/components/assistant-message.ts +978 -0
- package/src/modes/components/background-tan-message.ts +36 -0
- package/src/modes/components/bash-execution.ts +233 -0
- package/src/modes/components/bordered-loader.ts +41 -0
- package/src/modes/components/btw-panel.ts +161 -0
- package/src/modes/components/cache-invalidation-marker.ts +110 -0
- package/src/modes/components/chat-block.ts +111 -0
- package/src/modes/components/chat-transcript-builder.ts +518 -0
- package/src/modes/components/codex-reset-fireworks.ts +369 -0
- package/src/modes/components/collab-prompt-message.ts +32 -0
- package/src/modes/components/compaction-summary-message.ts +221 -0
- package/src/modes/components/copy-selector.ts +218 -0
- package/src/modes/components/countdown-timer.ts +75 -0
- package/src/modes/components/custom-editor.ts +1036 -0
- package/src/modes/components/custom-message.ts +70 -0
- package/src/modes/components/diff.ts +254 -0
- package/src/modes/components/dynamic-border.ts +37 -0
- package/src/modes/components/error-banner.ts +33 -0
- package/src/modes/components/eval-execution.ts +169 -0
- package/src/modes/components/execution-shared.ts +101 -0
- package/src/modes/components/extensions/extension-dashboard.ts +492 -0
- package/src/modes/components/extensions/extension-list.ts +507 -0
- package/src/modes/components/extensions/index.ts +9 -0
- package/src/modes/components/extensions/inspector-panel.ts +326 -0
- package/src/modes/components/extensions/state-manager.ts +648 -0
- package/src/modes/components/extensions/types.ts +186 -0
- package/src/modes/components/footer.ts +274 -0
- package/src/modes/components/history-search.ts +268 -0
- package/src/modes/components/hook-editor.ts +213 -0
- package/src/modes/components/hook-input.ts +87 -0
- package/src/modes/components/hook-message.ts +67 -0
- package/src/modes/components/hook-selector.ts +691 -0
- package/src/modes/components/index.ts +42 -0
- package/src/modes/components/keybinding-hints.ts +56 -0
- package/src/modes/components/late-diagnostics-message.ts +60 -0
- package/src/modes/components/login-dialog.ts +197 -0
- package/src/modes/components/logout-account-selector.ts +130 -0
- package/src/modes/components/mcp-add-wizard.ts +1413 -0
- package/src/modes/components/message-frame.ts +98 -0
- package/src/modes/components/model-browser.ts +888 -0
- package/src/modes/components/model-hub.ts +2014 -0
- package/src/modes/components/model-picker.ts +237 -0
- package/src/modes/components/move-overlay.ts +293 -0
- package/src/modes/components/oauth-selector.ts +474 -0
- package/src/modes/components/omfg-panel.ts +141 -0
- package/src/modes/components/overlay-box.ts +109 -0
- package/src/modes/components/pause-screen.ts +208 -0
- package/src/modes/components/plan-review-overlay.ts +1226 -0
- package/src/modes/components/plan-toc.ts +138 -0
- package/src/modes/components/plugin-selector.ts +100 -0
- package/src/modes/components/plugin-settings.ts +745 -0
- package/src/modes/components/queue-mode-selector.ts +61 -0
- package/src/modes/components/read-tool-group.ts +856 -0
- package/src/modes/components/reset-usage-selector.ts +161 -0
- package/src/modes/components/segment-track.ts +89 -0
- package/src/modes/components/select-list-mouse-routing.ts +35 -0
- package/src/modes/components/selector-helpers.ts +129 -0
- package/src/modes/components/session-account-selector.ts +62 -0
- package/src/modes/components/session-selector.ts +1035 -0
- package/src/modes/components/settings-defs.ts +267 -0
- package/src/modes/components/settings-selector.ts +1445 -0
- package/src/modes/components/show-images-selector.ts +50 -0
- package/src/modes/components/skill-message.ts +110 -0
- package/src/modes/components/snapcompact-shape-preview-doc.md +14 -0
- package/src/modes/components/snapcompact-shape-preview.ts +192 -0
- package/src/modes/components/status-line/component.ts +1843 -0
- package/src/modes/components/status-line/context-thresholds.ts +86 -0
- package/src/modes/components/status-line/git-utils.ts +42 -0
- package/src/modes/components/status-line/index.ts +5 -0
- package/src/modes/components/status-line/presets.ts +106 -0
- package/src/modes/components/status-line/segments.ts +710 -0
- package/src/modes/components/status-line/separators.ts +55 -0
- package/src/modes/components/status-line/types.ts +159 -0
- package/src/modes/components/stripped-tool-calls-placeholder.ts +35 -0
- package/src/modes/components/theme-selector.ts +68 -0
- package/src/modes/components/thinking-selector.ts +57 -0
- package/src/modes/components/tiny-title-download-progress.ts +90 -0
- package/src/modes/components/tips.txt +26 -0
- package/src/modes/components/todo-reminder.ts +43 -0
- package/src/modes/components/tool-execution.ts +1467 -0
- package/src/modes/components/transcript-container.ts +527 -0
- package/src/modes/components/tree-selector.ts +1006 -0
- package/src/modes/components/ttsr-notification.ts +123 -0
- package/src/modes/components/usage-row.ts +52 -0
- package/src/modes/components/user-message-selector.ts +227 -0
- package/src/modes/components/user-message.ts +167 -0
- package/src/modes/components/visual-truncate.ts +63 -0
- package/src/modes/components/welcome.ts +578 -0
- package/src/modes/controllers/btw-controller.ts +246 -0
- package/src/modes/controllers/command-controller-shared.ts +109 -0
- package/src/modes/controllers/command-controller.ts +2024 -0
- package/src/modes/controllers/event-controller.ts +2173 -0
- package/src/modes/controllers/extension-ui-controller.ts +1243 -0
- package/src/modes/controllers/input-controller.ts +2037 -0
- package/src/modes/controllers/live-command-controller.ts +261 -0
- package/src/modes/controllers/mcp-command-controller.ts +2552 -0
- package/src/modes/controllers/omfg-controller.ts +287 -0
- package/src/modes/controllers/omfg-rule.ts +647 -0
- package/src/modes/controllers/selector-controller.ts +2058 -0
- package/src/modes/controllers/session-focus-controller.ts +117 -0
- package/src/modes/controllers/ssh-command-controller.ts +385 -0
- package/src/modes/controllers/streaming-reveal.ts +399 -0
- package/src/modes/controllers/tan-command-controller.ts +243 -0
- package/src/modes/controllers/todo-command-controller.ts +487 -0
- package/src/modes/controllers/tool-args-reveal.ts +591 -0
- package/src/modes/data/emojis.json +1 -0
- package/src/modes/emoji-autocomplete.ts +285 -0
- package/src/modes/github-ref-autocomplete.ts +75 -0
- package/src/modes/gradient-highlight.ts +99 -0
- package/src/modes/image-references.ts +137 -0
- package/src/modes/index.ts +10 -0
- package/src/modes/interactive-mode.ts +5055 -0
- package/src/modes/internal-url-autocomplete.ts +158 -0
- package/src/modes/loop-limit.ts +192 -0
- package/src/modes/magic-keyword-boundary.ts +23 -0
- package/src/modes/magic-keywords.ts +42 -0
- package/src/modes/markdown-prose.ts +247 -0
- package/src/modes/oauth-manual-input.ts +69 -0
- package/src/modes/orchestrate.ts +43 -0
- package/src/modes/print-mode.ts +282 -0
- package/src/modes/prompt-action-autocomplete.ts +322 -0
- package/src/modes/queue-input.ts +132 -0
- package/src/modes/rpc/host-tools.ts +204 -0
- package/src/modes/rpc/host-uris.ts +241 -0
- package/src/modes/rpc/rpc-client.ts +1213 -0
- package/src/modes/rpc/rpc-frame.ts +316 -0
- package/src/modes/rpc/rpc-input.ts +38 -0
- package/src/modes/rpc/rpc-messages.ts +127 -0
- package/src/modes/rpc/rpc-mode.ts +1519 -0
- package/src/modes/rpc/rpc-subagents.ts +265 -0
- package/src/modes/rpc/rpc-types.ts +544 -0
- package/src/modes/running-subagent-badge.ts +13 -0
- package/src/modes/runtime-init.ts +144 -0
- package/src/modes/session-observer-registry.ts +223 -0
- package/src/modes/session-teardown.ts +82 -0
- package/src/modes/setup-version.ts +11 -0
- package/src/modes/setup-wizard/index.ts +103 -0
- package/src/modes/setup-wizard/lazy.ts +16 -0
- package/src/modes/setup-wizard/scenes/glyph.ts +103 -0
- package/src/modes/setup-wizard/scenes/model.ts +132 -0
- package/src/modes/setup-wizard/scenes/outro.ts +35 -0
- package/src/modes/setup-wizard/scenes/providers.ts +105 -0
- package/src/modes/setup-wizard/scenes/sign-in.ts +312 -0
- package/src/modes/setup-wizard/scenes/splash.ts +201 -0
- package/src/modes/setup-wizard/scenes/theme.ts +330 -0
- package/src/modes/setup-wizard/scenes/types.ts +65 -0
- package/src/modes/setup-wizard/scenes/web-search.ts +153 -0
- package/src/modes/setup-wizard/startup-splash.ts +107 -0
- package/src/modes/setup-wizard/wizard-overlay.ts +335 -0
- package/src/modes/shared.ts +49 -0
- package/src/modes/skill-command.ts +91 -0
- package/src/modes/theme/dark.json +95 -0
- package/src/modes/theme/defaults/alabaster.json +93 -0
- package/src/modes/theme/defaults/amethyst.json +96 -0
- package/src/modes/theme/defaults/anthracite.json +93 -0
- package/src/modes/theme/defaults/basalt.json +91 -0
- package/src/modes/theme/defaults/birch.json +95 -0
- package/src/modes/theme/defaults/dark-abyss.json +91 -0
- package/src/modes/theme/defaults/dark-arctic.json +104 -0
- package/src/modes/theme/defaults/dark-aurora.json +95 -0
- package/src/modes/theme/defaults/dark-catppuccin.json +107 -0
- package/src/modes/theme/defaults/dark-cavern.json +91 -0
- package/src/modes/theme/defaults/dark-copper.json +95 -0
- package/src/modes/theme/defaults/dark-cosmos.json +90 -0
- package/src/modes/theme/defaults/dark-cyberpunk.json +102 -0
- package/src/modes/theme/defaults/dark-dracula.json +98 -0
- package/src/modes/theme/defaults/dark-eclipse.json +91 -0
- package/src/modes/theme/defaults/dark-ember.json +95 -0
- package/src/modes/theme/defaults/dark-equinox.json +90 -0
- package/src/modes/theme/defaults/dark-forest.json +96 -0
- package/src/modes/theme/defaults/dark-github.json +105 -0
- package/src/modes/theme/defaults/dark-gruvbox.json +112 -0
- package/src/modes/theme/defaults/dark-lavender.json +95 -0
- package/src/modes/theme/defaults/dark-lunar.json +89 -0
- package/src/modes/theme/defaults/dark-midnight.json +95 -0
- package/src/modes/theme/defaults/dark-monochrome.json +94 -0
- package/src/modes/theme/defaults/dark-monokai.json +98 -0
- package/src/modes/theme/defaults/dark-nebula.json +90 -0
- package/src/modes/theme/defaults/dark-nord.json +97 -0
- package/src/modes/theme/defaults/dark-ocean.json +101 -0
- package/src/modes/theme/defaults/dark-one.json +100 -0
- package/src/modes/theme/defaults/dark-poimandres.json +143 -0
- package/src/modes/theme/defaults/dark-rainforest.json +91 -0
- package/src/modes/theme/defaults/dark-reef.json +91 -0
- package/src/modes/theme/defaults/dark-retro.json +92 -0
- package/src/modes/theme/defaults/dark-rose-pine.json +96 -0
- package/src/modes/theme/defaults/dark-sakura.json +95 -0
- package/src/modes/theme/defaults/dark-slate.json +95 -0
- package/src/modes/theme/defaults/dark-solarized.json +97 -0
- package/src/modes/theme/defaults/dark-solstice.json +90 -0
- package/src/modes/theme/defaults/dark-starfall.json +91 -0
- package/src/modes/theme/defaults/dark-sunset.json +99 -0
- package/src/modes/theme/defaults/dark-swamp.json +90 -0
- package/src/modes/theme/defaults/dark-synthwave.json +103 -0
- package/src/modes/theme/defaults/dark-taiga.json +91 -0
- package/src/modes/theme/defaults/dark-terminal.json +95 -0
- package/src/modes/theme/defaults/dark-tokyo-night.json +101 -0
- package/src/modes/theme/defaults/dark-tundra.json +91 -0
- package/src/modes/theme/defaults/dark-twilight.json +91 -0
- package/src/modes/theme/defaults/dark-volcanic.json +91 -0
- package/src/modes/theme/defaults/graphite.json +92 -0
- package/src/modes/theme/defaults/index.ts +199 -0
- package/src/modes/theme/defaults/light-arctic.json +107 -0
- package/src/modes/theme/defaults/light-aurora-day.json +91 -0
- package/src/modes/theme/defaults/light-canyon.json +91 -0
- package/src/modes/theme/defaults/light-catppuccin.json +106 -0
- package/src/modes/theme/defaults/light-cirrus.json +90 -0
- package/src/modes/theme/defaults/light-coral.json +95 -0
- package/src/modes/theme/defaults/light-cyberpunk.json +96 -0
- package/src/modes/theme/defaults/light-dawn.json +90 -0
- package/src/modes/theme/defaults/light-dunes.json +91 -0
- package/src/modes/theme/defaults/light-eucalyptus.json +95 -0
- package/src/modes/theme/defaults/light-forest.json +100 -0
- package/src/modes/theme/defaults/light-frost.json +95 -0
- package/src/modes/theme/defaults/light-github.json +115 -0
- package/src/modes/theme/defaults/light-glacier.json +91 -0
- package/src/modes/theme/defaults/light-gruvbox.json +108 -0
- package/src/modes/theme/defaults/light-haze.json +90 -0
- package/src/modes/theme/defaults/light-honeycomb.json +95 -0
- package/src/modes/theme/defaults/light-lagoon.json +91 -0
- package/src/modes/theme/defaults/light-lavender.json +95 -0
- package/src/modes/theme/defaults/light-meadow.json +91 -0
- package/src/modes/theme/defaults/light-mint.json +95 -0
- package/src/modes/theme/defaults/light-monochrome.json +101 -0
- package/src/modes/theme/defaults/light-ocean.json +99 -0
- package/src/modes/theme/defaults/light-one.json +99 -0
- package/src/modes/theme/defaults/light-opal.json +91 -0
- package/src/modes/theme/defaults/light-orchard.json +91 -0
- package/src/modes/theme/defaults/light-paper.json +95 -0
- package/src/modes/theme/defaults/light-poimandres.json +143 -0
- package/src/modes/theme/defaults/light-prism.json +90 -0
- package/src/modes/theme/defaults/light-retro.json +98 -0
- package/src/modes/theme/defaults/light-sand.json +95 -0
- package/src/modes/theme/defaults/light-savanna.json +91 -0
- package/src/modes/theme/defaults/light-solarized.json +102 -0
- package/src/modes/theme/defaults/light-soleil.json +90 -0
- package/src/modes/theme/defaults/light-sunset.json +99 -0
- package/src/modes/theme/defaults/light-synthwave.json +98 -0
- package/src/modes/theme/defaults/light-tokyo-night.json +111 -0
- package/src/modes/theme/defaults/light-wetland.json +91 -0
- package/src/modes/theme/defaults/light-zenith.json +89 -0
- package/src/modes/theme/defaults/limestone.json +94 -0
- package/src/modes/theme/defaults/mahogany.json +97 -0
- package/src/modes/theme/defaults/marble.json +93 -0
- package/src/modes/theme/defaults/obsidian.json +91 -0
- package/src/modes/theme/defaults/onyx.json +91 -0
- package/src/modes/theme/defaults/pearl.json +93 -0
- package/src/modes/theme/defaults/porcelain.json +91 -0
- package/src/modes/theme/defaults/quartz.json +96 -0
- package/src/modes/theme/defaults/sandstone.json +95 -0
- package/src/modes/theme/defaults/titanium.json +90 -0
- package/src/modes/theme/light.json +93 -0
- package/src/modes/theme/mermaid-cache.ts +92 -0
- package/src/modes/theme/shimmer.ts +305 -0
- package/src/modes/theme/theme-schema.json +463 -0
- package/src/modes/theme/theme.ts +3171 -0
- package/src/modes/turn-budget.ts +31 -0
- package/src/modes/types.ts +494 -0
- package/src/modes/ultrathink.ts +42 -0
- package/src/modes/utils/context-usage.ts +518 -0
- package/src/modes/utils/copy-targets.ts +378 -0
- package/src/modes/utils/hotkeys-markdown.ts +65 -0
- package/src/modes/utils/interactive-context-helpers.ts +31 -0
- package/src/modes/utils/keybinding-matchers.ts +86 -0
- package/src/modes/utils/tools-markdown.ts +31 -0
- package/src/modes/utils/transcript-render-helpers.ts +253 -0
- package/src/modes/utils/ui-helpers.ts +976 -0
- package/src/modes/warp-events.ts +232 -0
- package/src/modes/workflow.ts +55 -0
- package/src/plan-mode/approved-plan.ts +194 -0
- package/src/plan-mode/model-transition.ts +51 -0
- package/src/plan-mode/plan-files.ts +40 -0
- package/src/plan-mode/plan-handoff.ts +37 -0
- package/src/plan-mode/plan-protection.ts +31 -0
- package/src/plan-mode/state.ts +6 -0
- package/src/priority.json +60 -0
- package/src/prompts/advisor/active-repo-watchdog.md +6 -0
- package/src/prompts/advisor/advise-tool.md +3 -0
- package/src/prompts/advisor/context-files.md +8 -0
- package/src/prompts/advisor/system.md +98 -0
- package/src/prompts/agents/designer.md +74 -0
- package/src/prompts/agents/frontmatter.md +12 -0
- package/src/prompts/agents/init.md +33 -0
- package/src/prompts/agents/librarian.md +119 -0
- package/src/prompts/agents/reviewer.md +139 -0
- package/src/prompts/agents/scout.md +58 -0
- package/src/prompts/agents/security-reviewer.md +75 -0
- package/src/prompts/agents/task.md +17 -0
- package/src/prompts/bench/cache-prefix-chunk.md +1 -0
- package/src/prompts/bench/cache-prefix.md +3 -0
- package/src/prompts/bench/cache-suffix.md +1 -0
- package/src/prompts/bench.md +6 -0
- package/src/prompts/ci-green-request.md +36 -0
- package/src/prompts/dry-balance-bench.md +8 -0
- package/src/prompts/goals/goal-budget-limit.md +16 -0
- package/src/prompts/goals/goal-continuation.md +28 -0
- package/src/prompts/goals/goal-mode-active.md +23 -0
- package/src/prompts/goals/goal-mode-context.md +4 -0
- package/src/prompts/goals/goal-todo-context.md +12 -0
- package/src/prompts/goals/guided-goal-interview.md +43 -0
- package/src/prompts/memories/consolidation.md +30 -0
- package/src/prompts/memories/consolidation_system.md +4 -0
- package/src/prompts/memories/read-path.md +17 -0
- package/src/prompts/memories/stage_one_input.md +6 -0
- package/src/prompts/memories/stage_one_system.md +21 -0
- package/src/prompts/review-custom-request.md +21 -0
- package/src/prompts/review-headless-request.md +16 -0
- package/src/prompts/review-request.md +68 -0
- package/src/prompts/security/scan-coordinator.md +7 -0
- package/src/prompts/security/scan-request.md +21 -0
- package/src/prompts/security/validate-request.md +8 -0
- package/src/prompts/session/launch-completion.md +1 -0
- package/src/prompts/skills/autoload.md +8 -0
- package/src/prompts/skills/user-invocation.md +11 -0
- package/src/prompts/steering/parent-irc.md +5 -0
- package/src/prompts/steering/user-interjection.md +6 -0
- package/src/prompts/system/active-repo-context.md +4 -0
- package/src/prompts/system/agent-creation-architect.md +50 -0
- package/src/prompts/system/agent-creation-user.md +6 -0
- package/src/prompts/system/auto-continue.md +1 -0
- package/src/prompts/system/auto-thinking-difficulty-local.md +14 -0
- package/src/prompts/system/auto-thinking-difficulty.md +14 -0
- package/src/prompts/system/autolearn-guidance-learn.md +1 -0
- package/src/prompts/system/autolearn-guidance.md +7 -0
- package/src/prompts/system/autolearn-nudge-autocontinue.md +5 -0
- package/src/prompts/system/background-tan-dispatch.md +8 -0
- package/src/prompts/system/btw-user.md +8 -0
- package/src/prompts/system/commit-message-system.md +14 -0
- package/src/prompts/system/computer-safety.md +14 -0
- package/src/prompts/system/custom-system-prompt.md +64 -0
- package/src/prompts/system/eager-task.md +7 -0
- package/src/prompts/system/eager-todo.md +18 -0
- package/src/prompts/system/empty-stop-retry.md +4 -0
- package/src/prompts/system/gemini-tool-call-reminder.md +9 -0
- package/src/prompts/system/interrupted-thinking.md +7 -0
- package/src/prompts/system/irc-autoreply.md +6 -0
- package/src/prompts/system/irc-incoming.md +9 -0
- package/src/prompts/system/manual-continue.md +7 -0
- package/src/prompts/system/mcp-xdev-guidance.md +11 -0
- package/src/prompts/system/memory-consolidation-system.md +8 -0
- package/src/prompts/system/memory-extraction-system.md +26 -0
- package/src/prompts/system/mid-run-todo-nudge.md +3 -0
- package/src/prompts/system/omfg-user.md +50 -0
- package/src/prompts/system/orchestrate-notice.md +40 -0
- package/src/prompts/system/personalities/default.md +18 -0
- package/src/prompts/system/personalities/friendly.md +17 -0
- package/src/prompts/system/personalities/pragmatic.md +15 -0
- package/src/prompts/system/plan-mode-active.md +125 -0
- package/src/prompts/system/plan-mode-approved.md +22 -0
- package/src/prompts/system/plan-mode-compact-instructions.md +17 -0
- package/src/prompts/system/plan-mode-reference.md +10 -0
- package/src/prompts/system/plan-mode-subagent.md +33 -0
- package/src/prompts/system/plan-mode-tool-decision-reminder.md +9 -0
- package/src/prompts/system/plan-yolo-handoff.md +5 -0
- package/src/prompts/system/prewalk-checklist.md +7 -0
- package/src/prompts/system/prewalk-continue.md +1 -0
- package/src/prompts/system/prewalk-plan.md +13 -0
- package/src/prompts/system/project-prompt.md +61 -0
- package/src/prompts/system/recap-user.md +9 -0
- package/src/prompts/system/resolve-device-reminder.md +3 -0
- package/src/prompts/system/rewind-report.md +6 -0
- package/src/prompts/system/side-channel-no-tools.md +3 -0
- package/src/prompts/system/snapcompact-context-frames-note.md +1 -0
- package/src/prompts/system/snapcompact-context-stub.md +1 -0
- package/src/prompts/system/snapcompact-system-frames-note.md +1 -0
- package/src/prompts/system/snapcompact-system-stub.md +1 -0
- package/src/prompts/system/snapcompact-toolresult-note.md +1 -0
- package/src/prompts/system/speech-rewrite.md +15 -0
- package/src/prompts/system/subagent-async-pending.md +6 -0
- package/src/prompts/system/subagent-system-prompt.md +73 -0
- package/src/prompts/system/subagent-user-prompt.md +3 -0
- package/src/prompts/system/subagent-yield-reminder.md +23 -0
- package/src/prompts/system/system-prompt.md +263 -0
- package/src/prompts/system/tan-context-switch.md +17 -0
- package/src/prompts/system/task-label.md +23 -0
- package/src/prompts/system/thinking-loop-redirect.md +10 -0
- package/src/prompts/system/title-marker-instruction.md +1 -0
- package/src/prompts/system/title-system.md +16 -0
- package/src/prompts/system/tool-call-loop-redirect.md +8 -0
- package/src/prompts/system/ttsr-interrupt.md +7 -0
- package/src/prompts/system/ttsr-tool-reminder.md +5 -0
- package/src/prompts/system/ultrathink-notice.md +3 -0
- package/src/prompts/system/unexpected-stop-classifier.md +17 -0
- package/src/prompts/system/unexpected-stop-retry.md +4 -0
- package/src/prompts/system/vibe-mode-active.md +26 -0
- package/src/prompts/system/web-search.md +25 -0
- package/src/prompts/system/workflow-notice.md +112 -0
- package/src/prompts/system/xdev-mount-notice.md +20 -0
- package/src/prompts/tools/apply-patch.md +65 -0
- package/src/prompts/tools/ask.md +22 -0
- package/src/prompts/tools/ast-edit.md +11 -0
- package/src/prompts/tools/ast-grep.md +19 -0
- package/src/prompts/tools/async-result.md +8 -0
- package/src/prompts/tools/bash.md +23 -0
- package/src/prompts/tools/browser.md +29 -0
- package/src/prompts/tools/checkpoint.md +15 -0
- package/src/prompts/tools/computer.md +26 -0
- package/src/prompts/tools/debug.md +3 -0
- package/src/prompts/tools/eval.md +45 -0
- package/src/prompts/tools/github.md +22 -0
- package/src/prompts/tools/glob.md +16 -0
- package/src/prompts/tools/goal.md +11 -0
- package/src/prompts/tools/grep.md +13 -0
- package/src/prompts/tools/hub.md +34 -0
- package/src/prompts/tools/image-attachment-describe-system.md +8 -0
- package/src/prompts/tools/image-attachment-describe.md +10 -0
- package/src/prompts/tools/image-gen.md +7 -0
- package/src/prompts/tools/inspect-image-system.md +20 -0
- package/src/prompts/tools/inspect-image.md +22 -0
- package/src/prompts/tools/learn.md +7 -0
- package/src/prompts/tools/lsp-late-diagnostic.md +8 -0
- package/src/prompts/tools/lsp.md +19 -0
- package/src/prompts/tools/manage-skill.md +9 -0
- package/src/prompts/tools/memory-edit.md +12 -0
- package/src/prompts/tools/patch.md +57 -0
- package/src/prompts/tools/read.md +27 -0
- package/src/prompts/tools/recall.md +7 -0
- package/src/prompts/tools/reflect.md +5 -0
- package/src/prompts/tools/replace.md +30 -0
- package/src/prompts/tools/retain.md +6 -0
- package/src/prompts/tools/rewind.md +14 -0
- package/src/prompts/tools/security-publish.md +1 -0
- package/src/prompts/tools/security-scan.md +1 -0
- package/src/prompts/tools/task-async-contract.md +1 -0
- package/src/prompts/tools/task-summary.md +20 -0
- package/src/prompts/tools/task.md +83 -0
- package/src/prompts/tools/todo.md +42 -0
- package/src/prompts/tools/vibe-kill.md +3 -0
- package/src/prompts/tools/vibe-list.md +3 -0
- package/src/prompts/tools/vibe-send.md +9 -0
- package/src/prompts/tools/vibe-spawn.md +10 -0
- package/src/prompts/tools/vibe-turn-result.md +19 -0
- package/src/prompts/tools/vibe-wait.md +8 -0
- package/src/prompts/tools/web-search.md +8 -0
- package/src/prompts/tools/write.md +14 -0
- package/src/registry/agent-lifecycle.ts +505 -0
- package/src/registry/agent-registry.ts +287 -0
- package/src/registry/persisted-agents.ts +423 -0
- package/src/sdk.ts +3820 -0
- package/src/secrets/index.ts +375 -0
- package/src/secrets/obfuscator.ts +2629 -0
- package/src/secrets/regex.ts +21 -0
- package/src/security/auth.ts +98 -0
- package/src/security/cloud.ts +686 -0
- package/src/security/comparison.ts +255 -0
- package/src/security/contracts/ids.ts +111 -0
- package/src/security/contracts/index.ts +4 -0
- package/src/security/contracts/schemas.ts +219 -0
- package/src/security/contracts/types.ts +254 -0
- package/src/security/contracts/validation.ts +69 -0
- package/src/security/coordinator.ts +708 -0
- package/src/security/importers/codex-security.ts +387 -0
- package/src/security/importers/index.ts +2 -0
- package/src/security/importers/sarif.ts +357 -0
- package/src/security/index.ts +13 -0
- package/src/security/preflight.ts +405 -0
- package/src/security/provenance.ts +106 -0
- package/src/security/publication.ts +326 -0
- package/src/security/remediation.ts +93 -0
- package/src/security/resource-output.ts +50 -0
- package/src/security/sarif.ts +78 -0
- package/src/security/store.ts +430 -0
- package/src/session/acp-permission-gate.ts +165 -0
- package/src/session/agent-session-events.ts +67 -0
- package/src/session/agent-session-types.ts +407 -0
- package/src/session/agent-session.ts +9000 -0
- package/src/session/agent-storage.ts +807 -0
- package/src/session/artifacts.ts +154 -0
- package/src/session/async-job-delivery.ts +82 -0
- package/src/session/auth-broker-config.ts +92 -0
- package/src/session/auth-storage.ts +25 -0
- package/src/session/bash-runner.ts +326 -0
- package/src/session/blob-store.ts +295 -0
- package/src/session/checkpoint-entries.ts +81 -0
- package/src/session/claude-session-store.ts +426 -0
- package/src/session/client-bridge.ts +85 -0
- package/src/session/codex-auto-reset.ts +673 -0
- package/src/session/codex-session-store.ts +673 -0
- package/src/session/compact-modes.ts +105 -0
- package/src/session/credential-pin.ts +93 -0
- package/src/session/eval-runner.ts +219 -0
- package/src/session/exit-diagnostics.ts +310 -0
- package/src/session/foreign-session-import.ts +52 -0
- package/src/session/foreign-session-jsonl.ts +29 -0
- package/src/session/foreign-session-store.ts +26 -0
- package/src/session/history-storage.ts +329 -0
- package/src/session/indexed-session-storage.ts +553 -0
- package/src/session/irc-bridge.ts +203 -0
- package/src/session/launch-completion.ts +37 -0
- package/src/session/messages.ts +1304 -0
- package/src/session/model-controls.ts +757 -0
- package/src/session/prewalk.ts +279 -0
- package/src/session/provider-image-budget.ts +86 -0
- package/src/session/queued-messages.ts +99 -0
- package/src/session/redis-session-storage.ts +257 -0
- package/src/session/retry-fallback-chains.ts +455 -0
- package/src/session/role-models.ts +85 -0
- package/src/session/session-advisors.ts +1896 -0
- package/src/session/session-context.ts +584 -0
- package/src/session/session-dump-format.ts +216 -0
- package/src/session/session-entries.ts +306 -0
- package/src/session/session-handoff.ts +325 -0
- package/src/session/session-history-format.ts +459 -0
- package/src/session/session-listing.ts +715 -0
- package/src/session/session-loader.ts +362 -0
- package/src/session/session-maintenance.ts +3115 -0
- package/src/session/session-manager.ts +2747 -0
- package/src/session/session-memory.ts +222 -0
- package/src/session/session-metadata.ts +53 -0
- package/src/session/session-migrations.ts +78 -0
- package/src/session/session-paths.ts +280 -0
- package/src/session/session-persistence.ts +293 -0
- package/src/session/session-provider-boundary.ts +306 -0
- package/src/session/session-stats.ts +349 -0
- package/src/session/session-storage.ts +774 -0
- package/src/session/session-title-slot.ts +141 -0
- package/src/session/session-tools.ts +1385 -0
- package/src/session/session-workspace.ts +53 -0
- package/src/session/settings-stream-fn.ts +79 -0
- package/src/session/shake-types.ts +43 -0
- package/src/session/snapcompact-inline.ts +545 -0
- package/src/session/snapcompact-savings-journal.ts +113 -0
- package/src/session/sql-session-storage.ts +374 -0
- package/src/session/stream-guards.ts +417 -0
- package/src/session/streaming-output.ts +1459 -0
- package/src/session/todo-tracker.ts +380 -0
- package/src/session/tool-choice-queue.ts +305 -0
- package/src/session/ttsr-coordinator.ts +496 -0
- package/src/session/turn-persistence.ts +142 -0
- package/src/session/turn-recovery.ts +2005 -0
- package/src/session/unexpected-stop-classifier.ts +141 -0
- package/src/session/yield-queue.ts +288 -0
- package/src/slash-commands/acp-builtins.ts +70 -0
- package/src/slash-commands/available-commands.ts +105 -0
- package/src/slash-commands/builtin-registry.ts +3149 -0
- package/src/slash-commands/helpers/active-oauth-account.ts +80 -0
- package/src/slash-commands/helpers/collab-qrcode.ts +28 -0
- package/src/slash-commands/helpers/context-report.ts +66 -0
- package/src/slash-commands/helpers/format.ts +46 -0
- package/src/slash-commands/helpers/logout.ts +108 -0
- package/src/slash-commands/helpers/marketplace-manager.ts +25 -0
- package/src/slash-commands/helpers/mcp.ts +533 -0
- package/src/slash-commands/helpers/parse.ts +85 -0
- package/src/slash-commands/helpers/reset-usage.ts +68 -0
- package/src/slash-commands/helpers/security.ts +451 -0
- package/src/slash-commands/helpers/session-pin.ts +44 -0
- package/src/slash-commands/helpers/ssh.ts +196 -0
- package/src/slash-commands/helpers/stats-dashboard.ts +86 -0
- package/src/slash-commands/helpers/todo.ts +285 -0
- package/src/slash-commands/helpers/usage-report.ts +198 -0
- package/src/slash-commands/marketplace-install-parser.ts +99 -0
- package/src/slash-commands/types.ts +139 -0
- package/src/ssh/config-writer.ts +183 -0
- package/src/ssh/connection-manager.ts +667 -0
- package/src/ssh/file-transfer.ts +214 -0
- package/src/ssh/sshfs-mount.ts +163 -0
- package/src/ssh/utils.ts +51 -0
- package/src/startup-splash.ts +19 -0
- package/src/stt/asr-client.ts +401 -0
- package/src/stt/asr-protocol.ts +65 -0
- package/src/stt/asr-worker.ts +603 -0
- package/src/stt/downloader.ts +142 -0
- package/src/stt/endpointer.ts +259 -0
- package/src/stt/index.ts +6 -0
- package/src/stt/models.ts +150 -0
- package/src/stt/sherpa-runtime.ts +71 -0
- package/src/stt/stt-controller.ts +320 -0
- package/src/stt/submit-trigger.ts +74 -0
- package/src/subprocess/worker-client.ts +463 -0
- package/src/subprocess/worker-runtime.ts +494 -0
- package/src/system-prompt.ts +921 -0
- package/src/task/agents.ts +170 -0
- package/src/task/commands.ts +132 -0
- package/src/task/discovery.ts +145 -0
- package/src/task/executor.ts +3431 -0
- package/src/task/index.ts +1515 -0
- package/src/task/isolation-ownership.ts +106 -0
- package/src/task/isolation-runner.ts +444 -0
- package/src/task/label.ts +40 -0
- package/src/task/name-generator.ts +1577 -0
- package/src/task/omp-command.ts +26 -0
- package/src/task/output-manager.ts +115 -0
- package/src/task/parallel.ts +221 -0
- package/src/task/persisted-revive.ts +173 -0
- package/src/task/prewalk.ts +6 -0
- package/src/task/prompt-policy.ts +8 -0
- package/src/task/provider-concurrency.ts +100 -0
- package/src/task/read-only-policy.ts +27 -0
- package/src/task/render.ts +1830 -0
- package/src/task/renderer.ts +14 -0
- package/src/task/repair-args.ts +118 -0
- package/src/task/spawn-policy.ts +72 -0
- package/src/task/structured-subagent.ts +676 -0
- package/src/task/subprocess-tool-registry.ts +88 -0
- package/src/task/types.ts +555 -0
- package/src/task/worktree.ts +967 -0
- package/src/task/yield-assembly.ts +198 -0
- package/src/telemetry-export.ts +504 -0
- package/src/thinking.ts +377 -0
- package/src/tiny/device.ts +111 -0
- package/src/tiny/dtype.ts +101 -0
- package/src/tiny/message-preproc.ts +155 -0
- package/src/tiny/models.ts +268 -0
- package/src/tiny/text.ts +290 -0
- package/src/tiny/title-client.ts +460 -0
- package/src/tiny/title-protocol.ts +56 -0
- package/src/tiny/worker.ts +354 -0
- package/src/tools/acp-bridge.ts +125 -0
- package/src/tools/approval.ts +245 -0
- package/src/tools/ask.ts +1459 -0
- package/src/tools/ast-edit.ts +718 -0
- package/src/tools/ast-grep.ts +526 -0
- package/src/tools/auto-generated-guard.ts +335 -0
- package/src/tools/bash-interactive.ts +435 -0
- package/src/tools/bash-interceptor.ts +148 -0
- package/src/tools/bash-pty-selection.ts +14 -0
- package/src/tools/bash-skill-urls.ts +350 -0
- package/src/tools/bash.ts +1826 -0
- package/src/tools/browser/aria/aria-snapshot.bundle.txt +7 -0
- package/src/tools/browser/aria/aria-snapshot.ts +131 -0
- package/src/tools/browser/attach.ts +219 -0
- package/src/tools/browser/cmux/cmux-tab.ts +1531 -0
- package/src/tools/browser/cmux/rpc.ts +200 -0
- package/src/tools/browser/cmux/socket-client.ts +445 -0
- package/src/tools/browser/launch.ts +939 -0
- package/src/tools/browser/readable.ts +112 -0
- package/src/tools/browser/registry.ts +447 -0
- package/src/tools/browser/relay/bridge.ts +945 -0
- package/src/tools/browser/relay/daemon.ts +117 -0
- package/src/tools/browser/relay/extension-assets/background.js.txt +242 -0
- package/src/tools/browser/relay/extension-assets/manifest.json.txt +14 -0
- package/src/tools/browser/relay/extension-assets/options.html.txt +53 -0
- package/src/tools/browser/relay/extension-assets/options.js.txt +23 -0
- package/src/tools/browser/relay/kind.ts +41 -0
- package/src/tools/browser/relay/protocol.ts +54 -0
- package/src/tools/browser/relay/server.ts +141 -0
- package/src/tools/browser/render.ts +229 -0
- package/src/tools/browser/run-output.ts +76 -0
- package/src/tools/browser/shared-daemon.ts +139 -0
- package/src/tools/browser/tab-protocol.ts +123 -0
- package/src/tools/browser/tab-supervisor.ts +1077 -0
- package/src/tools/browser/tab-worker-entry.ts +29 -0
- package/src/tools/browser/tab-worker.ts +1982 -0
- package/src/tools/browser.ts +487 -0
- package/src/tools/builtin-names.ts +67 -0
- package/src/tools/checkpoint.ts +137 -0
- package/src/tools/computer/exposure.ts +14 -0
- package/src/tools/computer/protocol.ts +69 -0
- package/src/tools/computer/supervisor.ts +409 -0
- package/src/tools/computer/worker-entry.ts +39 -0
- package/src/tools/computer/worker.ts +745 -0
- package/src/tools/computer-renderer.ts +147 -0
- package/src/tools/computer.ts +222 -0
- package/src/tools/conflict-detect.ts +815 -0
- package/src/tools/context.ts +49 -0
- package/src/tools/debug.ts +1121 -0
- package/src/tools/default-renderer.ts +154 -0
- package/src/tools/essential-tools.ts +46 -0
- package/src/tools/eval-backends.ts +34 -0
- package/src/tools/eval-format/index.ts +24 -0
- package/src/tools/eval-format/javascript.ts +952 -0
- package/src/tools/eval-format/julia.ts +446 -0
- package/src/tools/eval-format/python.ts +544 -0
- package/src/tools/eval-format/ruby.ts +380 -0
- package/src/tools/eval-render.ts +784 -0
- package/src/tools/eval.ts +774 -0
- package/src/tools/fetch.ts +1889 -0
- package/src/tools/file-recorder.ts +35 -0
- package/src/tools/fs-cache-invalidation.ts +28 -0
- package/src/tools/gh-cache-invalidation.ts +175 -0
- package/src/tools/gh-format.ts +12 -0
- package/src/tools/gh-renderer.ts +484 -0
- package/src/tools/gh.ts +3958 -0
- package/src/tools/github-cache.ts +663 -0
- package/src/tools/glob.ts +691 -0
- package/src/tools/grep.ts +1920 -0
- package/src/tools/grouped-file-output.ts +210 -0
- package/src/tools/hub/index.ts +579 -0
- package/src/tools/hub/jobs.ts +714 -0
- package/src/tools/hub/launch.ts +690 -0
- package/src/tools/hub/messaging.ts +735 -0
- package/src/tools/hub/types.ts +117 -0
- package/src/tools/image-gen.ts +1689 -0
- package/src/tools/image-providers.ts +50 -0
- package/src/tools/index.ts +736 -0
- package/src/tools/inspect-image-renderer.ts +133 -0
- package/src/tools/inspect-image.ts +316 -0
- package/src/tools/json-tree.ts +260 -0
- package/src/tools/jtd-to-json-schema.ts +219 -0
- package/src/tools/jtd-to-typescript.ts +136 -0
- package/src/tools/jtd-utils.ts +102 -0
- package/src/tools/learn.ts +141 -0
- package/src/tools/list-limit.ts +40 -0
- package/src/tools/manage-skill.ts +102 -0
- package/src/tools/match-line-format.ts +20 -0
- package/src/tools/memory-edit.ts +61 -0
- package/src/tools/memory-recall.ts +102 -0
- package/src/tools/memory-reflect.ts +88 -0
- package/src/tools/memory-render.ts +211 -0
- package/src/tools/memory-retain.ts +89 -0
- package/src/tools/output-meta.ts +860 -0
- package/src/tools/output-schema-validator.ts +307 -0
- package/src/tools/path-utils.ts +1489 -0
- package/src/tools/plan-mode-guard.ts +155 -0
- package/src/tools/puppeteer/00_stealth_tampering.txt +44 -0
- package/src/tools/puppeteer/01_stealth_activity.txt +80 -0
- package/src/tools/puppeteer/02_stealth_hairline.txt +57 -0
- package/src/tools/puppeteer/03_stealth_botd.txt +380 -0
- package/src/tools/puppeteer/04_stealth_iframe.txt +174 -0
- package/src/tools/puppeteer/05_stealth_webgl.txt +233 -0
- package/src/tools/puppeteer/06_stealth_screen.txt +260 -0
- package/src/tools/puppeteer/07_stealth_fonts.txt +99 -0
- package/src/tools/puppeteer/08_stealth_audio.txt +63 -0
- package/src/tools/puppeteer/09_stealth_locale.txt +51 -0
- package/src/tools/puppeteer/10_stealth_plugins.txt +212 -0
- package/src/tools/puppeteer/11_stealth_hardware.txt +59 -0
- package/src/tools/puppeteer/12_stealth_codecs.txt +42 -0
- package/src/tools/puppeteer/13_stealth_worker.txt +235 -0
- package/src/tools/read.ts +3762 -0
- package/src/tools/render-utils.ts +926 -0
- package/src/tools/renderers.ts +133 -0
- package/src/tools/report-tool-issue.ts +568 -0
- package/src/tools/resolve.ts +423 -0
- package/src/tools/review.ts +103 -0
- package/src/tools/run-scope.ts +417 -0
- package/src/tools/security-scan.ts +287 -0
- package/src/tools/shell-tokenize.ts +213 -0
- package/src/tools/sqlite-reader.ts +884 -0
- package/src/tools/terminal-output.ts +141 -0
- package/src/tools/todo.ts +1226 -0
- package/src/tools/tool-errors.ts +62 -0
- package/src/tools/tool-result.ts +102 -0
- package/src/tools/tool-timeouts.ts +38 -0
- package/src/tools/tts.ts +266 -0
- package/src/tools/vibe.ts +608 -0
- package/src/tools/write.ts +1646 -0
- package/src/tools/xdev.ts +560 -0
- package/src/tools/yield.ts +486 -0
- package/src/tts/downloader.ts +64 -0
- package/src/tts/index.ts +10 -0
- package/src/tts/models.ts +137 -0
- package/src/tts/runtime.ts +21 -0
- package/src/tts/speakable.ts +392 -0
- package/src/tts/speech-enhancer.ts +206 -0
- package/src/tts/streaming-player.ts +120 -0
- package/src/tts/tts-client.ts +475 -0
- package/src/tts/tts-protocol.ts +69 -0
- package/src/tts/tts-worker.ts +434 -0
- package/src/tts/vocalizer.ts +419 -0
- package/src/tts/wav.ts +58 -0
- package/src/tui/code-cell.ts +268 -0
- package/src/tui/file-list.ts +55 -0
- package/src/tui/hyperlink.ts +178 -0
- package/src/tui/index.ts +13 -0
- package/src/tui/output-block.ts +268 -0
- package/src/tui/status-line.ts +54 -0
- package/src/tui/tree-list.ts +172 -0
- package/src/tui/types.ts +15 -0
- package/src/tui/utils.ts +103 -0
- package/src/tui/width-aware-text.ts +58 -0
- package/src/utils/active-repo-context.ts +143 -0
- package/src/utils/block-context.ts +312 -0
- package/src/utils/changelog.ts +373 -0
- package/src/utils/clipboard.ts +361 -0
- package/src/utils/command-args.ts +74 -0
- package/src/utils/commit-message-generator.ts +148 -0
- package/src/utils/cpuprofile.ts +235 -0
- package/src/utils/edit-mode.ts +61 -0
- package/src/utils/enhanced-paste.ts +230 -0
- package/src/utils/event-bus.ts +33 -0
- package/src/utils/external-editor.ts +80 -0
- package/src/utils/fetch-timeout.ts +10 -0
- package/src/utils/file-display-mode.ts +44 -0
- package/src/utils/file-mentions.ts +293 -0
- package/src/utils/git.ts +2472 -0
- package/src/utils/image-loading.ts +236 -0
- package/src/utils/image-resize.ts +420 -0
- package/src/utils/image-vision-fallback.ts +196 -0
- package/src/utils/inspect-image-mode.ts +39 -0
- package/src/utils/ipc.ts +38 -0
- package/src/utils/jj.ts +422 -0
- package/src/utils/lang-from-path.ts +251 -0
- package/src/utils/late-cleanup.ts +17 -0
- package/src/utils/local-date.ts +7 -0
- package/src/utils/mac-file-urls.applescript +37 -0
- package/src/utils/markit-cache.ts +166 -0
- package/src/utils/markit.ts +223 -0
- package/src/utils/mupdf-wasm-embed.ts +12 -0
- package/src/utils/open.ts +126 -0
- package/src/utils/profile-tree.ts +111 -0
- package/src/utils/prompt-path.ts +3 -0
- package/src/utils/qrcode.ts +535 -0
- package/src/utils/sample-profile.ts +437 -0
- package/src/utils/session-color.ts +142 -0
- package/src/utils/shell-snapshot-fn-env.sh +63 -0
- package/src/utils/shell-snapshot.ts +326 -0
- package/src/utils/sixel.ts +69 -0
- package/src/utils/thinking-display.ts +163 -0
- package/src/utils/title-generator.ts +597 -0
- package/src/utils/token-rate.ts +72 -0
- package/src/utils/tool-choice.ts +50 -0
- package/src/utils/tools-manager.ts +411 -0
- package/src/utils/turndown.ts +82 -0
- package/src/utils/zip.ts +1106 -0
- package/src/vibe/runtime.ts +1684 -0
- package/src/vibe/state.ts +4 -0
- package/src/web/kagi.ts +305 -0
- package/src/web/parallel.ts +354 -0
- package/src/web/scrapers/artifacthub.ts +207 -0
- package/src/web/scrapers/arxiv.ts +83 -0
- package/src/web/scrapers/aur.ts +162 -0
- package/src/web/scrapers/biorxiv.ts +133 -0
- package/src/web/scrapers/bluesky.ts +262 -0
- package/src/web/scrapers/brew.ts +172 -0
- package/src/web/scrapers/cheatsh.ts +68 -0
- package/src/web/scrapers/chocolatey.ts +196 -0
- package/src/web/scrapers/choosealicense.ts +95 -0
- package/src/web/scrapers/cisa-kev.ts +87 -0
- package/src/web/scrapers/clojars.ts +154 -0
- package/src/web/scrapers/coingecko.ts +177 -0
- package/src/web/scrapers/crates-io.ts +97 -0
- package/src/web/scrapers/crossref.ts +136 -0
- package/src/web/scrapers/devto.ts +147 -0
- package/src/web/scrapers/discogs.ts +306 -0
- package/src/web/scrapers/discourse.ts +197 -0
- package/src/web/scrapers/dockerhub.ts +138 -0
- package/src/web/scrapers/docs-rs.ts +663 -0
- package/src/web/scrapers/fdroid.ts +134 -0
- package/src/web/scrapers/firefox-addons.ts +191 -0
- package/src/web/scrapers/flathub.ts +223 -0
- package/src/web/scrapers/github-gist.ts +58 -0
- package/src/web/scrapers/github.ts +800 -0
- package/src/web/scrapers/gitlab.ts +401 -0
- package/src/web/scrapers/go-pkg.ts +266 -0
- package/src/web/scrapers/hackage.ts +129 -0
- package/src/web/scrapers/hackernews.ts +189 -0
- package/src/web/scrapers/hex.ts +105 -0
- package/src/web/scrapers/huggingface.ts +321 -0
- package/src/web/scrapers/iacr.ts +89 -0
- package/src/web/scrapers/index.ts +252 -0
- package/src/web/scrapers/jetbrains-marketplace.ts +159 -0
- package/src/web/scrapers/lemmy.ts +203 -0
- package/src/web/scrapers/lobsters.ts +175 -0
- package/src/web/scrapers/mastodon.ts +292 -0
- package/src/web/scrapers/maven.ts +138 -0
- package/src/web/scrapers/mdn.ts +173 -0
- package/src/web/scrapers/metacpan.ts +222 -0
- package/src/web/scrapers/musicbrainz.ts +250 -0
- package/src/web/scrapers/npm.ts +98 -0
- package/src/web/scrapers/nuget.ts +183 -0
- package/src/web/scrapers/nvd.ts +222 -0
- package/src/web/scrapers/ollama.ts +239 -0
- package/src/web/scrapers/open-vsx.ts +106 -0
- package/src/web/scrapers/opencorporates.ts +292 -0
- package/src/web/scrapers/openlibrary.ts +336 -0
- package/src/web/scrapers/orcid.ts +286 -0
- package/src/web/scrapers/osv.ts +176 -0
- package/src/web/scrapers/packagist.ts +160 -0
- package/src/web/scrapers/pub-dev.ts +143 -0
- package/src/web/scrapers/pubmed.ts +211 -0
- package/src/web/scrapers/pypi.ts +112 -0
- package/src/web/scrapers/rawg.ts +110 -0
- package/src/web/scrapers/readthedocs.ts +121 -0
- package/src/web/scrapers/reddit.ts +95 -0
- package/src/web/scrapers/repology.ts +251 -0
- package/src/web/scrapers/rfc.ts +201 -0
- package/src/web/scrapers/rubygems.ts +103 -0
- package/src/web/scrapers/searchcode.ts +189 -0
- package/src/web/scrapers/sec-edgar.ts +261 -0
- package/src/web/scrapers/semantic-scholar.ts +171 -0
- package/src/web/scrapers/snapcraft.ts +187 -0
- package/src/web/scrapers/sourcegraph.ts +336 -0
- package/src/web/scrapers/spdx.ts +108 -0
- package/src/web/scrapers/spotify.ts +198 -0
- package/src/web/scrapers/stackoverflow.ts +120 -0
- package/src/web/scrapers/terraform.ts +277 -0
- package/src/web/scrapers/tldr.ts +47 -0
- package/src/web/scrapers/twitter.ts +94 -0
- package/src/web/scrapers/types.ts +354 -0
- package/src/web/scrapers/utils.ts +109 -0
- package/src/web/scrapers/vimeo.ts +133 -0
- package/src/web/scrapers/vscode-marketplace.ts +187 -0
- package/src/web/scrapers/w3c.ts +156 -0
- package/src/web/scrapers/wikidata.ts +344 -0
- package/src/web/scrapers/wikipedia.ts +84 -0
- package/src/web/scrapers/youtube.ts +325 -0
- package/src/web/search/index.ts +393 -0
- package/src/web/search/provider.ts +272 -0
- package/src/web/search/providers/anthropic.ts +406 -0
- package/src/web/search/providers/base.ts +112 -0
- package/src/web/search/providers/brave.ts +181 -0
- package/src/web/search/providers/browser-headers.ts +82 -0
- package/src/web/search/providers/browser-page.ts +125 -0
- package/src/web/search/providers/codex.ts +788 -0
- package/src/web/search/providers/duckduckgo.ts +382 -0
- package/src/web/search/providers/ecosia.ts +183 -0
- package/src/web/search/providers/exa.ts +513 -0
- package/src/web/search/providers/firecrawl.ts +213 -0
- package/src/web/search/providers/gemini.ts +634 -0
- package/src/web/search/providers/google.ts +195 -0
- package/src/web/search/providers/jina.ts +144 -0
- package/src/web/search/providers/kagi.ts +98 -0
- package/src/web/search/providers/kimi.ts +221 -0
- package/src/web/search/providers/mojeek.ts +220 -0
- package/src/web/search/providers/parallel.ts +186 -0
- package/src/web/search/providers/perplexity-auth.ts +142 -0
- package/src/web/search/providers/perplexity.ts +997 -0
- package/src/web/search/providers/public.ts +199 -0
- package/src/web/search/providers/searxng.ts +467 -0
- package/src/web/search/providers/startpage.ts +225 -0
- package/src/web/search/providers/synthetic.ts +126 -0
- package/src/web/search/providers/tavily.ts +244 -0
- package/src/web/search/providers/tinyfish.ts +166 -0
- package/src/web/search/providers/utils.ts +130 -0
- package/src/web/search/providers/xai.ts +372 -0
- package/src/web/search/providers/zai.ts +452 -0
- package/src/web/search/query.ts +850 -0
- package/src/web/search/render.ts +262 -0
- package/src/web/search/types.ts +518 -0
- package/src/web/search/utils.ts +17 -0
- package/src/workspace-tree.ts +326 -0
package/src/main.ts
ADDED
|
@@ -0,0 +1,1799 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Main entry point for the coding agent CLI.
|
|
3
|
+
*
|
|
4
|
+
* This file handles CLI argument parsing and translates them into
|
|
5
|
+
* createAgentSession() options. The SDK does the heavy lifting.
|
|
6
|
+
*/
|
|
7
|
+
import * as fsSync from "node:fs";
|
|
8
|
+
import * as os from "node:os";
|
|
9
|
+
import { createInterface } from "node:readline/promises";
|
|
10
|
+
import { EventLoopKeepalive } from "@oh-my-pi/pi-agent-core";
|
|
11
|
+
import type { ImageContent } from "@oh-my-pi/pi-ai";
|
|
12
|
+
import {
|
|
13
|
+
$env,
|
|
14
|
+
directoryExists,
|
|
15
|
+
getLogPath,
|
|
16
|
+
getProjectDir,
|
|
17
|
+
logger,
|
|
18
|
+
normalizePathForComparison,
|
|
19
|
+
postmortem,
|
|
20
|
+
setInteractiveHost,
|
|
21
|
+
setProjectDir,
|
|
22
|
+
VERSION,
|
|
23
|
+
} from "@oh-my-pi/pi-utils";
|
|
24
|
+
import chalk from "@oh-my-pi/pi-utils/chalk";
|
|
25
|
+
import { reset as resetCapabilities } from "./capability";
|
|
26
|
+
import { type Args, reportUnrecognizedFlags } from "./cli/args";
|
|
27
|
+
import { applyExtensionFlags, type ExtensionFlagSink } from "./cli/extension-flags";
|
|
28
|
+
import { processFileArguments } from "./cli/file-processor";
|
|
29
|
+
import { buildInitialMessage } from "./cli/initial-message";
|
|
30
|
+
import { selectSession } from "./cli/session-picker";
|
|
31
|
+
import { applyStartupCwd } from "./cli/startup-cwd";
|
|
32
|
+
import { findConfigFile } from "./config";
|
|
33
|
+
import { ModelRegistry } from "./config/model-registry";
|
|
34
|
+
import {
|
|
35
|
+
DEFAULT_PREWALK_TARGET,
|
|
36
|
+
expandRoleAlias,
|
|
37
|
+
getModelMatchPreferences,
|
|
38
|
+
resolveCliModel,
|
|
39
|
+
resolveModelRoleValue,
|
|
40
|
+
resolveModelScope,
|
|
41
|
+
type ScopedModel,
|
|
42
|
+
} from "./config/model-resolver";
|
|
43
|
+
import { ModelsConfigFile } from "./config/models-config";
|
|
44
|
+
import { serviceTierSettingToTier } from "./config/service-tier";
|
|
45
|
+
import { getDefault, type SettingPath, Settings, type SettingValue, settings } from "./config/settings";
|
|
46
|
+
import { initializeWithSettings } from "./discovery";
|
|
47
|
+
import {
|
|
48
|
+
clearPluginRootsAndCaches,
|
|
49
|
+
injectPluginDirRoots,
|
|
50
|
+
preloadPluginRoots,
|
|
51
|
+
resolveActiveProjectRegistryPath,
|
|
52
|
+
} from "./discovery/helpers";
|
|
53
|
+
import { injectOmpExtensionCliRoots } from "./discovery/omp-extension-roots";
|
|
54
|
+
import { formatExtensionLoadNotifications } from "./extensibility/extensions/load-errors";
|
|
55
|
+
import { loadExtensions } from "./extensibility/extensions/loader";
|
|
56
|
+
import { ExtensionRunner } from "./extensibility/extensions/runner";
|
|
57
|
+
import type { ExtensionUIContext } from "./extensibility/extensions/types";
|
|
58
|
+
import { scheduleMarketplaceAutoUpdate } from "./extensibility/plugins/marketplace-auto-update";
|
|
59
|
+
import { registerDaemonProjectPresence } from "./launch/presence";
|
|
60
|
+
import type { MCPManager } from "./mcp";
|
|
61
|
+
import { InteractiveMode } from "./modes/interactive-mode";
|
|
62
|
+
import type { PrintModeOptions } from "./modes/print-mode";
|
|
63
|
+
import { claimRpcInput } from "./modes/rpc/rpc-input";
|
|
64
|
+
import { CURRENT_SETUP_VERSION } from "./modes/setup-version";
|
|
65
|
+
import { initTheme, stopThemeWatcher } from "./modes/theme/theme";
|
|
66
|
+
import type { SubmittedUserInput } from "./modes/types";
|
|
67
|
+
import { createWarpEventBridgeExtension } from "./modes/warp-events";
|
|
68
|
+
import { AgentLifecycleManager } from "./registry/agent-lifecycle";
|
|
69
|
+
import {
|
|
70
|
+
type CreateAgentSessionOptions,
|
|
71
|
+
type CreateAgentSessionResult,
|
|
72
|
+
createAgentSession,
|
|
73
|
+
discoverAuthStorage,
|
|
74
|
+
loadSessionExtensions,
|
|
75
|
+
} from "./sdk";
|
|
76
|
+
import type { AgentSession } from "./session/agent-session";
|
|
77
|
+
import type { AuthStorage } from "./session/auth-storage";
|
|
78
|
+
import { describePendingToolCalls } from "./session/exit-diagnostics";
|
|
79
|
+
import {
|
|
80
|
+
createForeignSessionStore,
|
|
81
|
+
foreignSessionInfoToSessionInfo,
|
|
82
|
+
foreignSessionSourceName,
|
|
83
|
+
persistForeignSession,
|
|
84
|
+
} from "./session/foreign-session-import";
|
|
85
|
+
import type { ForeignSessionInfo, ForeignSessionSource, ForeignSessionStore } from "./session/foreign-session-store";
|
|
86
|
+
import { resolveResumableSession, type SessionInfo } from "./session/session-listing";
|
|
87
|
+
import { SessionManager } from "./session/session-manager";
|
|
88
|
+
import { executeBuiltinSlashCommand } from "./slash-commands/builtin-registry";
|
|
89
|
+
import { shouldShowStartupSplash } from "./startup-splash";
|
|
90
|
+
import { discoverTitleSystemPromptFile, resolvePromptInput } from "./system-prompt";
|
|
91
|
+
import { createPersistedSubagentReviverFactory } from "./task/persisted-revive";
|
|
92
|
+
import { createTelemetryExportConfig, initTelemetryExport, isTelemetryExportEnabled } from "./telemetry-export";
|
|
93
|
+
import { concreteThinkingLevel, parseConfiguredThinkingLevel } from "./thinking";
|
|
94
|
+
import type { LspStartupServerInfo } from "./tools";
|
|
95
|
+
import { getChangelogPath, resolveStartupChangelogForDisplay, type StartupChangelogSelection } from "./utils/changelog";
|
|
96
|
+
import { EventBus } from "./utils/event-bus";
|
|
97
|
+
import { withTimeoutSignal } from "./utils/fetch-timeout";
|
|
98
|
+
|
|
99
|
+
type RunAcpMode = (createSession: AcpSessionFactory) => Promise<never>;
|
|
100
|
+
type RunPrintMode = (session: AgentSession, options: PrintModeOptions) => Promise<void>;
|
|
101
|
+
type RunRpcMode = (
|
|
102
|
+
session: AgentSession,
|
|
103
|
+
setToolUIContext?: (uiContext: ExtensionUIContext, hasUI: boolean) => void,
|
|
104
|
+
eventBus?: EventBus,
|
|
105
|
+
input?: ReadableStream<Uint8Array>,
|
|
106
|
+
) => Promise<never>;
|
|
107
|
+
|
|
108
|
+
export function writeStartupNotice(parsedArgs: Pick<Args, "mode">, text: string): void {
|
|
109
|
+
(parsedArgs.mode === "json" ? process.stderr : process.stdout).write(text);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async function checkForNewVersion(currentVersion: string): Promise<string | undefined> {
|
|
113
|
+
if (!settings.get("startup.checkUpdate")) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
try {
|
|
117
|
+
const response = await fetch("https://registry.npmjs.org/@oh-my-pi/pi-coding-agent/latest", {
|
|
118
|
+
signal: withTimeoutSignal(5_000),
|
|
119
|
+
});
|
|
120
|
+
if (!response.ok) return undefined;
|
|
121
|
+
|
|
122
|
+
const data = (await response.json()) as { version?: string };
|
|
123
|
+
const latestVersion = data.version;
|
|
124
|
+
|
|
125
|
+
if (latestVersion && Bun.semver.order(latestVersion, currentVersion) > 0) {
|
|
126
|
+
return latestVersion;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return undefined;
|
|
130
|
+
} catch {
|
|
131
|
+
return undefined;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Todo settings are caller-controlled in protocol modes. Do not host-default them:
|
|
136
|
+
// embedders need project-level opt-outs for reminder/prelude prompt injection.
|
|
137
|
+
const HOST_DEFAULTED_SETTING_PATHS: SettingPath[] = [
|
|
138
|
+
"task.isolation.mode",
|
|
139
|
+
"task.isolation.apply",
|
|
140
|
+
"task.isolation.merge",
|
|
141
|
+
"task.isolation.commits",
|
|
142
|
+
"task.eager",
|
|
143
|
+
"task.batch",
|
|
144
|
+
"task.maxConcurrency",
|
|
145
|
+
"task.maxRecursionDepth",
|
|
146
|
+
"task.disabledAgents",
|
|
147
|
+
"task.agentModelOverrides",
|
|
148
|
+
"task.agentPrewalk",
|
|
149
|
+
// Memory subsystems are off-by-default for RPC/ACP hosts; embedders that want
|
|
150
|
+
// memory should opt in explicitly through their own settings layer.
|
|
151
|
+
"memory.backend",
|
|
152
|
+
"memories.enabled",
|
|
153
|
+
// Advisor is interactive-session assistance. Protocol hosts opt in explicitly
|
|
154
|
+
// instead of inheriting a user's globally-enabled local preference, and when
|
|
155
|
+
// they do opt in they get the default tuning rather than the user's local tuning.
|
|
156
|
+
"advisor.enabled",
|
|
157
|
+
"advisor.subagents",
|
|
158
|
+
"advisor.syncBacklog",
|
|
159
|
+
"advisor.immuneTurns",
|
|
160
|
+
"tier.advisor",
|
|
161
|
+
];
|
|
162
|
+
|
|
163
|
+
const RPC_BACKGROUND_DEFAULTED_SETTING_PATHS: SettingPath[] = [
|
|
164
|
+
"async.enabled",
|
|
165
|
+
"async.maxJobs",
|
|
166
|
+
"bash.autoBackground.enabled",
|
|
167
|
+
"bash.autoBackground.thresholdMs",
|
|
168
|
+
];
|
|
169
|
+
|
|
170
|
+
// Protocol-mode hosts opt into a small set of paths whose host-default we
|
|
171
|
+
// re-apply at startup so embedders inherit OMP's neutral defaults instead of
|
|
172
|
+
// the local user's globally-persisted preferences for interactive use. The
|
|
173
|
+
// guard preserves any explicit configuration — caller `Settings.isolated`
|
|
174
|
+
// overrides, project `.claude/settings.yml`, `--config` overlays, or global
|
|
175
|
+
// `config.yml` — so the host default only kicks in when nothing is set. Without
|
|
176
|
+
// it the override clobbers every caller/host choice (#2598, #3207).
|
|
177
|
+
function applyDefaultSettingOverrides(settingPaths: SettingPath[], targetSettings: Settings): void {
|
|
178
|
+
for (const settingPath of settingPaths) {
|
|
179
|
+
if (targetSettings.isConfigured(settingPath)) continue;
|
|
180
|
+
targetSettings.override(settingPath, getDefault(settingPath));
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function applyRpcDefaultSettingOverrides(targetSettings: Settings = settings): void {
|
|
185
|
+
applyDefaultSettingOverrides(HOST_DEFAULTED_SETTING_PATHS, targetSettings);
|
|
186
|
+
applyDefaultSettingOverrides(RPC_BACKGROUND_DEFAULTED_SETTING_PATHS, targetSettings);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function applyAcpDefaultSettingOverrides(targetSettings: Settings = settings): void {
|
|
190
|
+
applyDefaultSettingOverrides(HOST_DEFAULTED_SETTING_PATHS, targetSettings);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** Reads a non-TTY stdin stream as prompt text. */
|
|
194
|
+
export async function readPipedInput(): Promise<string | undefined> {
|
|
195
|
+
if (process.stdin.isTTY === true) return undefined;
|
|
196
|
+
// stdin is a pipe: a producer that never writes nor closes would block
|
|
197
|
+
// startup forever with zero output. Say what we're blocked on after 1s.
|
|
198
|
+
const notice = setTimeout(() => {
|
|
199
|
+
process.stderr.write(`${chalk.dim("Reading prompt from piped stdin (waiting for EOF; ctrl+c to abort)…")}\n`);
|
|
200
|
+
}, 1000);
|
|
201
|
+
notice.unref?.();
|
|
202
|
+
try {
|
|
203
|
+
const text = await Bun.stdin.text();
|
|
204
|
+
if (text.trim().length === 0) return undefined;
|
|
205
|
+
return text;
|
|
206
|
+
} catch {
|
|
207
|
+
return undefined;
|
|
208
|
+
} finally {
|
|
209
|
+
clearTimeout(notice);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// ---------------------------------------------------------------------------
|
|
214
|
+
// Startup watchdog
|
|
215
|
+
// ---------------------------------------------------------------------------
|
|
216
|
+
// Speculative-hang reporter: until startup hands off to a mode runner, print a
|
|
217
|
+
// stderr line every 10s naming the deepest in-flight startup phase. Turns
|
|
218
|
+
// zero-output indefinite hangs (stuck discovery read, network wait, stdin
|
|
219
|
+
// pipe) into self-diagnosing reports instead of "it just hangs" (see the
|
|
220
|
+
// PI_DEBUG_STARTUP markers for the synchronous-hang counterpart).
|
|
221
|
+
|
|
222
|
+
const STARTUP_WATCHDOG_INTERVAL_MS = 10_000;
|
|
223
|
+
let startupWatchdogTimer: NodeJS.Timeout | undefined;
|
|
224
|
+
let startupWatchdogActive = false;
|
|
225
|
+
let startupWatchdogStartedAt = 0;
|
|
226
|
+
|
|
227
|
+
function armStartupWatchdog(): void {
|
|
228
|
+
if (startupWatchdogTimer) return;
|
|
229
|
+
startupWatchdogTimer = setInterval(() => {
|
|
230
|
+
const elapsed = Math.round((Date.now() - startupWatchdogStartedAt) / 1000);
|
|
231
|
+
const phase = logger.openSpanPath().join(" > ") || "module load / pre-phase work";
|
|
232
|
+
process.stderr.write(
|
|
233
|
+
`${chalk.yellow(`Still starting after ${elapsed}s`)}${chalk.dim(` — phase: ${phase}`)}\n` +
|
|
234
|
+
`${chalk.dim(` logs: ${getLogPath()} · re-run with PI_DEBUG_STARTUP=1 for streaming phase markers`)}\n`,
|
|
235
|
+
);
|
|
236
|
+
}, STARTUP_WATCHDOG_INTERVAL_MS);
|
|
237
|
+
startupWatchdogTimer.unref?.();
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function disarmStartupWatchdog(): void {
|
|
241
|
+
if (!startupWatchdogTimer) return;
|
|
242
|
+
clearInterval(startupWatchdogTimer);
|
|
243
|
+
startupWatchdogTimer = undefined;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/** Begin watching startup (idempotent). */
|
|
247
|
+
function startStartupWatchdog(): void {
|
|
248
|
+
startupWatchdogActive = true;
|
|
249
|
+
startupWatchdogStartedAt = Date.now();
|
|
250
|
+
armStartupWatchdog();
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/** Permanently stop watching: a mode runner now owns the terminal. */
|
|
254
|
+
function stopStartupWatchdog(): void {
|
|
255
|
+
startupWatchdogActive = false;
|
|
256
|
+
disarmStartupWatchdog();
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/** Pause while an interactive prompt legitimately waits on the user. */
|
|
260
|
+
function pauseStartupWatchdog(): void {
|
|
261
|
+
disarmStartupWatchdog();
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/** Resume after an interactive prompt, if startup is still being watched. */
|
|
265
|
+
function resumeStartupWatchdog(): void {
|
|
266
|
+
if (startupWatchdogActive) armStartupWatchdog();
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export interface InteractiveModeNotify {
|
|
270
|
+
kind: "warn" | "error" | "info";
|
|
271
|
+
message: string;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export function buildModelScopeNotification(
|
|
275
|
+
scopedModelsForDisplay: readonly Pick<ScopedModel, "model" | "thinkingLevel" | "explicitThinkingLevel">[],
|
|
276
|
+
startupQuiet: boolean,
|
|
277
|
+
): InteractiveModeNotify | null {
|
|
278
|
+
if (startupQuiet || scopedModelsForDisplay.length === 0) {
|
|
279
|
+
return null;
|
|
280
|
+
}
|
|
281
|
+
const modelList = scopedModelsForDisplay
|
|
282
|
+
.map(scopedModel => {
|
|
283
|
+
const thinkingStr =
|
|
284
|
+
scopedModel.explicitThinkingLevel && scopedModel.thinkingLevel ? `:${scopedModel.thinkingLevel}` : "";
|
|
285
|
+
return `${scopedModel.model.id}${thinkingStr}`;
|
|
286
|
+
})
|
|
287
|
+
.join(", ");
|
|
288
|
+
return { kind: "info", message: `Model scope: ${modelList} (Ctrl+P to cycle)` };
|
|
289
|
+
}
|
|
290
|
+
export async function submitInteractiveInput(
|
|
291
|
+
mode: Pick<
|
|
292
|
+
InteractiveMode,
|
|
293
|
+
"markPendingSubmissionStarted" | "finishPendingSubmission" | "showError" | "checkShutdownRequested"
|
|
294
|
+
>,
|
|
295
|
+
session: Pick<AgentSession, "prompt" | "promptCustomMessage" | "isStreaming">,
|
|
296
|
+
input: SubmittedUserInput,
|
|
297
|
+
): Promise<void> {
|
|
298
|
+
if (input.cancelled) {
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
try {
|
|
303
|
+
using _keepalive = new EventLoopKeepalive();
|
|
304
|
+
// Honor the submission's queue intent, defaulting to followUp. Reading
|
|
305
|
+
// `session.isStreaming` to decide queue-vs-fresh is NOT atomic with the
|
|
306
|
+
// eventual `agent.prompt()` call inside `session.prompt()`: a background turn
|
|
307
|
+
// (queued-message drain, idle compaction, goal/loop continuation timer) can
|
|
308
|
+
// flip the agent busy in the gap, and a bare prompt() would then throw
|
|
309
|
+
// AgentBusyError straight to an error toast even though the UI shows no
|
|
310
|
+
// "Working…". Passing a behavior unconditionally is a no-op when the session
|
|
311
|
+
// is genuinely idle (a fresh turn runs and the option is ignored) and queues
|
|
312
|
+
// the message instead of erroring when a turn is already underway. Normal
|
|
313
|
+
// user Enter carries "steer" (interrupt, matching the streaming-branch Enter);
|
|
314
|
+
// background/continuation submits omit it and fall back to "followUp". The
|
|
315
|
+
// synthetic branch below opts out by design.
|
|
316
|
+
const streamingBehavior = input.streamingBehavior ?? ("followUp" as const);
|
|
317
|
+
// Continue shortcuts submit an already-started synthetic developer prompt with
|
|
318
|
+
// no optimistic user message.
|
|
319
|
+
if (!input.started && !mode.markPendingSubmissionStarted(input)) {
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
if (input.customType) {
|
|
323
|
+
const message = {
|
|
324
|
+
customType: input.customType,
|
|
325
|
+
content: input.text,
|
|
326
|
+
display: input.display ?? false,
|
|
327
|
+
attribution: "agent" as const,
|
|
328
|
+
};
|
|
329
|
+
await session.promptCustomMessage(message, { streamingBehavior });
|
|
330
|
+
} else if (input.synthetic) {
|
|
331
|
+
// Synthetic continue shortcuts are hidden developer prompts. The streaming
|
|
332
|
+
// queue (#queueUserMessage) only carries user-attributed messages, so we do
|
|
333
|
+
// NOT pass streamingBehavior here: queueing would silently demote the
|
|
334
|
+
// developer directive to a visible user message. A synthetic submit while
|
|
335
|
+
// streaming keeps its prior behavior (rejected as busy) rather than changing
|
|
336
|
+
// its role.
|
|
337
|
+
await session.prompt(input.text, {
|
|
338
|
+
synthetic: true,
|
|
339
|
+
expandPromptTemplates: false,
|
|
340
|
+
userInitiated: input.userInitiated,
|
|
341
|
+
});
|
|
342
|
+
} else {
|
|
343
|
+
await session.prompt(input.text, { images: input.images, streamingBehavior });
|
|
344
|
+
}
|
|
345
|
+
} catch (error: unknown) {
|
|
346
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
|
|
347
|
+
mode.showError(errorMessage);
|
|
348
|
+
} finally {
|
|
349
|
+
mode.finishPendingSubmission(input);
|
|
350
|
+
await mode.checkShutdownRequested();
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
type AcpSessionFactory = (cwd: string) => Promise<AgentSession>;
|
|
355
|
+
|
|
356
|
+
export interface AcpSessionFactoryOptions {
|
|
357
|
+
baseOptions: CreateAgentSessionOptions;
|
|
358
|
+
settings: Settings;
|
|
359
|
+
sessionDir?: string;
|
|
360
|
+
authStorage: AuthStorage;
|
|
361
|
+
modelRegistry: ModelRegistry;
|
|
362
|
+
parsedArgs: Pick<Args, "apiKey" | "trustedExtensions">;
|
|
363
|
+
rawArgs: string[];
|
|
364
|
+
createSession: (options: CreateAgentSessionOptions) => Promise<CreateAgentSessionResult>;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
async function loadTrustedSessionExtensions(
|
|
368
|
+
options: Pick<CreateAgentSessionOptions, "additionalExtensionPaths">,
|
|
369
|
+
cwd: string,
|
|
370
|
+
eventBus: EventBus,
|
|
371
|
+
) {
|
|
372
|
+
const paths = options.additionalExtensionPaths ?? [];
|
|
373
|
+
for (const trustedPath of paths) {
|
|
374
|
+
let stat: fsSync.Stats;
|
|
375
|
+
try {
|
|
376
|
+
stat = fsSync.statSync(trustedPath);
|
|
377
|
+
} catch {
|
|
378
|
+
throw new Error(`Trusted extension must be an existing module file: ${trustedPath}`);
|
|
379
|
+
}
|
|
380
|
+
if (!stat.isFile()) {
|
|
381
|
+
throw new Error(`Trusted extension must be a module file, not a directory: ${trustedPath}`);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
return loadExtensions(paths, cwd, eventBus);
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Build the per-`session/new` factory used by ACP mode.
|
|
389
|
+
*
|
|
390
|
+
* MCP servers in ACP sessions are owned exclusively by the ACP client, which
|
|
391
|
+
* supplies them through `session/new.mcpServers` and re-applies them via
|
|
392
|
+
* {@link AcpAgent#configureMcpServers}. We therefore force `enableMCP: false`
|
|
393
|
+
* on every session created here so {@link createAgentSession} skips the on-disk
|
|
394
|
+
* `.mcp.json` discovery path — otherwise host MCP tools land in the session's
|
|
395
|
+
* tool registry and shadow the client-supplied servers (issue #1234).
|
|
396
|
+
*/
|
|
397
|
+
export function createAcpSessionFactory(args: AcpSessionFactoryOptions): AcpSessionFactory {
|
|
398
|
+
return async cwd => {
|
|
399
|
+
const nextSettings = await args.settings.cloneForCwd(cwd);
|
|
400
|
+
const nextSessionManager = SessionManager.create(cwd, args.sessionDir);
|
|
401
|
+
const agentId = `acp:${nextSessionManager.getSessionId()}`;
|
|
402
|
+
// `baseOptions.titleSystemPrompt` is resolved from the launch cwd; an ACP
|
|
403
|
+
// host can open `session/new` for any client-supplied workspace, so
|
|
404
|
+
// re-discover `TITLE_SYSTEM.md` against THIS session's `cwd` to keep the
|
|
405
|
+
// replan-driven title refresh consistent with the target project's
|
|
406
|
+
// policy (PR #3736 follow-up).
|
|
407
|
+
const titleSystemPromptSource = discoverTitleSystemPromptFile(cwd);
|
|
408
|
+
const titleSystemPrompt = await resolvePromptInput(titleSystemPromptSource, "title system prompt");
|
|
409
|
+
const eventBus = new EventBus();
|
|
410
|
+
const trustedExtensions =
|
|
411
|
+
args.parsedArgs.trustedExtensions && args.parsedArgs.trustedExtensions.length > 0
|
|
412
|
+
? await loadTrustedSessionExtensions(args.baseOptions, cwd, eventBus)
|
|
413
|
+
: undefined;
|
|
414
|
+
if (trustedExtensions && trustedExtensions.errors.length > 0) {
|
|
415
|
+
throw new Error(
|
|
416
|
+
`Trusted extension failed to load: ${trustedExtensions.errors.map(item => item.error).join("; ")}`,
|
|
417
|
+
);
|
|
418
|
+
}
|
|
419
|
+
const { session: nextSession } = await args.createSession({
|
|
420
|
+
...args.baseOptions,
|
|
421
|
+
cwd,
|
|
422
|
+
sessionManager: nextSessionManager,
|
|
423
|
+
settings: nextSettings,
|
|
424
|
+
authStorage: args.authStorage,
|
|
425
|
+
modelRegistry: args.modelRegistry,
|
|
426
|
+
agentId,
|
|
427
|
+
// Preserve reserve-policy confirmation until ACP capabilities are known
|
|
428
|
+
// without enabling AskTool or other UI-only session behavior.
|
|
429
|
+
deferUsageReserveConfirmation: true,
|
|
430
|
+
enableMCP: false,
|
|
431
|
+
titleSystemPrompt,
|
|
432
|
+
eventBus,
|
|
433
|
+
preloadedExtensions: trustedExtensions,
|
|
434
|
+
});
|
|
435
|
+
if (args.parsedArgs.apiKey && !args.baseOptions.model && nextSession.model) {
|
|
436
|
+
args.authStorage.setRuntimeApiKey(nextSession.model.provider, args.parsedArgs.apiKey);
|
|
437
|
+
}
|
|
438
|
+
applyExtensionFlags(nextSession.extensionRunner, args.rawArgs);
|
|
439
|
+
return nextSession;
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
async function runInteractiveMode(
|
|
444
|
+
session: AgentSession,
|
|
445
|
+
version: string,
|
|
446
|
+
startupChangelog: StartupChangelogSelection | undefined,
|
|
447
|
+
notifs: (InteractiveModeNotify | null)[],
|
|
448
|
+
versionCheckPromise: Promise<string | undefined>,
|
|
449
|
+
initialMessages: string[],
|
|
450
|
+
setExtensionUIContext: (uiContext: ExtensionUIContext, hasUI: boolean) => void,
|
|
451
|
+
lspServers: LspStartupServerInfo[] | undefined,
|
|
452
|
+
mcpManager: MCPManager | undefined,
|
|
453
|
+
resuming: boolean,
|
|
454
|
+
forceSetupWizard: boolean,
|
|
455
|
+
showStartupSplash: boolean,
|
|
456
|
+
eventBus?: EventBus,
|
|
457
|
+
initialMessage?: string,
|
|
458
|
+
initialImages?: ImageContent[],
|
|
459
|
+
joinLink?: string,
|
|
460
|
+
): Promise<void> {
|
|
461
|
+
const mode = new InteractiveMode(
|
|
462
|
+
session,
|
|
463
|
+
version,
|
|
464
|
+
startupChangelog,
|
|
465
|
+
setExtensionUIContext,
|
|
466
|
+
lspServers,
|
|
467
|
+
mcpManager,
|
|
468
|
+
eventBus,
|
|
469
|
+
);
|
|
470
|
+
|
|
471
|
+
// Cold-launch gate: the full setup wizard (every scene + the overlay and
|
|
472
|
+
// their TUI/OAuth/search/theme deps) is heavy, yet the common case only needs
|
|
473
|
+
// to know whether the stored setup version is current. Lazy-load the wizard
|
|
474
|
+
// barrel only when setup is stale, forced, or the explicit startup splash
|
|
475
|
+
// setting needs the shared setup splash renderer.
|
|
476
|
+
const storedSetupVersion = settings.get("setupVersion");
|
|
477
|
+
const setupWizard =
|
|
478
|
+
forceSetupWizard || storedSetupVersion < CURRENT_SETUP_VERSION || showStartupSplash
|
|
479
|
+
? await import("./modes/setup-wizard")
|
|
480
|
+
: undefined;
|
|
481
|
+
const setupScenes = setupWizard
|
|
482
|
+
? await setupWizard.selectSetupScenes(storedSetupVersion, setupWizard.ALL_SCENES, mode, {
|
|
483
|
+
resuming,
|
|
484
|
+
isTTY: process.stdin.isTTY && process.stdout.isTTY,
|
|
485
|
+
setupWizardEnabled: settings.get("startup.setupWizard"),
|
|
486
|
+
force: forceSetupWizard,
|
|
487
|
+
})
|
|
488
|
+
: [];
|
|
489
|
+
const playStartupSplash = showStartupSplash && setupScenes.length === 0;
|
|
490
|
+
|
|
491
|
+
await mode.init({
|
|
492
|
+
suppressWelcomeIntro: resuming || setupScenes.length > 0 || playStartupSplash,
|
|
493
|
+
clearInitialTerminalHistory: true,
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
if (setupWizard && playStartupSplash) {
|
|
497
|
+
await setupWizard.runStartupSplash(mode);
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
if (setupWizard && setupScenes.length > 0) {
|
|
501
|
+
await setupWizard.runSetupWizard(mode, setupScenes);
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
versionCheckPromise
|
|
505
|
+
.then(newVersion => {
|
|
506
|
+
if (!settings.get("startup.checkUpdate")) {
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
if (newVersion) {
|
|
510
|
+
mode.showNewVersionNotification(newVersion);
|
|
511
|
+
}
|
|
512
|
+
})
|
|
513
|
+
.catch(() => {});
|
|
514
|
+
|
|
515
|
+
// Cold-launch cleanup: the first paint already clears native history, and this
|
|
516
|
+
// replay replaces the welcome/startup frame with the resumed/new transcript.
|
|
517
|
+
// Every in-process session load also uses `clearTerminalHistory`; cold launch
|
|
518
|
+
// follows the same clean-cutover path instead of preserving a previous run's
|
|
519
|
+
// transcript above the fresh one.
|
|
520
|
+
mode.renderInitialMessages({ preserveExistingChat: true, clearTerminalHistory: true });
|
|
521
|
+
|
|
522
|
+
for (const notify of notifs) {
|
|
523
|
+
if (!notify) {
|
|
524
|
+
continue;
|
|
525
|
+
}
|
|
526
|
+
if (notify.kind === "warn") {
|
|
527
|
+
mode.showWarning(notify.message);
|
|
528
|
+
} else if (notify.kind === "error") {
|
|
529
|
+
mode.showError(notify.message);
|
|
530
|
+
} else if (notify.kind === "info") {
|
|
531
|
+
mode.showStatus(notify.message);
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
// `omp join <link>`: dispatch through the same builtin path as a typed
|
|
536
|
+
// `/join` so collab guards and error rendering stay in one place.
|
|
537
|
+
if (joinLink !== undefined) {
|
|
538
|
+
await executeBuiltinSlashCommand(`/join ${joinLink}`, { ctx: mode });
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
if (initialMessage !== undefined) {
|
|
542
|
+
session.maybeStartTitleGeneration(initialMessage);
|
|
543
|
+
try {
|
|
544
|
+
using _keepalive = new EventLoopKeepalive();
|
|
545
|
+
await session.prompt(initialMessage, { images: initialImages });
|
|
546
|
+
} catch (error: unknown) {
|
|
547
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
|
|
548
|
+
mode.showError(errorMessage);
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
for (const message of initialMessages) {
|
|
553
|
+
session.maybeStartTitleGeneration(message);
|
|
554
|
+
try {
|
|
555
|
+
using _keepalive = new EventLoopKeepalive();
|
|
556
|
+
await session.prompt(message);
|
|
557
|
+
} catch (error: unknown) {
|
|
558
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
|
|
559
|
+
mode.showError(errorMessage);
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
while (true) {
|
|
564
|
+
const input = await mode.getUserInput();
|
|
565
|
+
await submitInteractiveInput(mode, session, input);
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
type SessionPromptResult = "accepted" | "declined" | "unavailable";
|
|
570
|
+
|
|
571
|
+
type SessionPrompt = (session: SessionInfo) => Promise<SessionPromptResult>;
|
|
572
|
+
|
|
573
|
+
async function promptMoveSession(session: SessionInfo): Promise<SessionPromptResult> {
|
|
574
|
+
if (!process.stdin.isTTY) {
|
|
575
|
+
return "unavailable";
|
|
576
|
+
}
|
|
577
|
+
const message = `Session's directory no longer exists (${session.cwd}). Move (re-root) it into the current directory? [Y/n] `;
|
|
578
|
+
pauseStartupWatchdog();
|
|
579
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
580
|
+
try {
|
|
581
|
+
const answer = (await rl.question(message)).trim().toLowerCase();
|
|
582
|
+
return answer === "" || answer === "y" || answer === "yes" ? "accepted" : "declined";
|
|
583
|
+
} finally {
|
|
584
|
+
rl.close();
|
|
585
|
+
resumeStartupWatchdog();
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
/**
|
|
590
|
+
* Friendly CLI failure raised by {@link createSessionManager} when the user's
|
|
591
|
+
* session-resolution flags (`--resume`/`--fork`/missing-directory move prompts)
|
|
592
|
+
* cannot be satisfied. {@link runRootCommand} catches it and prints a clean
|
|
593
|
+
* stderr message instead of letting it surface as `[Uncaught Exception]`
|
|
594
|
+
* (see issue #2084).
|
|
595
|
+
*/
|
|
596
|
+
export class SessionResolutionError extends Error {
|
|
597
|
+
readonly hint?: string;
|
|
598
|
+
constructor(message: string, hint?: string) {
|
|
599
|
+
super(message);
|
|
600
|
+
this.name = "SessionResolutionError";
|
|
601
|
+
this.hint = hint;
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
function resolveForeignSessionSource(
|
|
606
|
+
parsed: Pick<Args, "continue" | "fork" | "fromClaude" | "fromCodex" | "noSession" | "resume">,
|
|
607
|
+
): ForeignSessionSource | undefined {
|
|
608
|
+
if (parsed.fromClaude && parsed.fromCodex) {
|
|
609
|
+
throw new SessionResolutionError("--from-claude and --from-codex cannot be used together");
|
|
610
|
+
}
|
|
611
|
+
const source = parsed.fromClaude ? "claude" : parsed.fromCodex ? "codex" : undefined;
|
|
612
|
+
if (!source) return undefined;
|
|
613
|
+
if (parsed.noSession) {
|
|
614
|
+
throw new SessionResolutionError(`--from-${source} requires session persistence`);
|
|
615
|
+
}
|
|
616
|
+
if (parsed.continue || parsed.resume || parsed.fork) {
|
|
617
|
+
throw new SessionResolutionError(`--from-${source} cannot be combined with --continue, --resume, or --fork`);
|
|
618
|
+
}
|
|
619
|
+
return source;
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
function isForeignSessionImport(parsed: Pick<Args, "fromClaude" | "fromCodex">): boolean {
|
|
623
|
+
return parsed.fromClaude === true || parsed.fromCodex === true;
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
type MissingCwdMoveResult =
|
|
627
|
+
| { status: "not-needed" }
|
|
628
|
+
| { status: "declined" }
|
|
629
|
+
| { status: "moved"; manager: SessionManager };
|
|
630
|
+
|
|
631
|
+
async function moveMissingCwdSessionIfNeeded(
|
|
632
|
+
sessionArg: string,
|
|
633
|
+
session: SessionInfo,
|
|
634
|
+
cwd: string,
|
|
635
|
+
sessionDir: string | undefined,
|
|
636
|
+
askToMoveSession: SessionPrompt,
|
|
637
|
+
): Promise<MissingCwdMoveResult> {
|
|
638
|
+
const sourceCwd = session.cwd;
|
|
639
|
+
if (!sourceCwd || fsSync.existsSync(sourceCwd)) {
|
|
640
|
+
return { status: "not-needed" };
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
const movePromptResult = await askToMoveSession(session);
|
|
644
|
+
if (movePromptResult === "unavailable") {
|
|
645
|
+
throw new SessionResolutionError(
|
|
646
|
+
`Session "${sessionArg}" belongs to a directory that no longer exists (${sourceCwd}); run interactively to move it into the current project.`,
|
|
647
|
+
);
|
|
648
|
+
}
|
|
649
|
+
if (movePromptResult === "declined") {
|
|
650
|
+
return { status: "declined" };
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
// Open anchored at the (now-missing) recorded cwd: `open` otherwise falls back
|
|
654
|
+
// to the launch cwd, which would make the `moveTo` below a no-op whenever the
|
|
655
|
+
// move target equals the current project dir. moveTo never chdirs, so the
|
|
656
|
+
// stale cwd is only a relocation source, not a directory we enter.
|
|
657
|
+
const manager = await SessionManager.open(session.path, sessionDir, undefined, { initialCwd: sourceCwd });
|
|
658
|
+
await manager.moveTo(cwd, sessionDir);
|
|
659
|
+
return { status: "moved", manager };
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
async function switchToResumedProject(
|
|
663
|
+
resumedCwd: string | undefined,
|
|
664
|
+
activeSettings: Settings,
|
|
665
|
+
pluginPreloadPromise: Promise<unknown>,
|
|
666
|
+
): Promise<string> {
|
|
667
|
+
if (
|
|
668
|
+
!resumedCwd ||
|
|
669
|
+
normalizePathForComparison(resumedCwd) === normalizePathForComparison(getProjectDir()) ||
|
|
670
|
+
!(await directoryExists(resumedCwd))
|
|
671
|
+
) {
|
|
672
|
+
return getProjectDir();
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
// Let the launch-cwd preload settle before clearing and re-warming its caches.
|
|
676
|
+
await pluginPreloadPromise.catch(() => {});
|
|
677
|
+
setProjectDir(resumedCwd);
|
|
678
|
+
clearPluginRootsAndCaches();
|
|
679
|
+
resetCapabilities();
|
|
680
|
+
const cwd = getProjectDir();
|
|
681
|
+
// clearPluginRootsAndCaches only kicks off an unawaited re-warm; await a fresh
|
|
682
|
+
// destination preload so sync consumers (plugin-provided LSP/DAP config) never
|
|
683
|
+
// read the launch project's stale/empty roots during session creation.
|
|
684
|
+
await preloadPluginRoots(os.homedir(), cwd);
|
|
685
|
+
await activeSettings.reloadForCwd(cwd);
|
|
686
|
+
return cwd;
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
/**
|
|
690
|
+
* Resolve the effective model allow-list from an explicit `--models` scope or,
|
|
691
|
+
* failing that, the active project's `enabledModels`. Re-run after a resume
|
|
692
|
+
* switches projects so the destination project's settings-derived scope wins
|
|
693
|
+
* over the launch directory's.
|
|
694
|
+
*/
|
|
695
|
+
async function resolveScopedModels(
|
|
696
|
+
parsed: Args,
|
|
697
|
+
modelRegistry: ModelRegistry,
|
|
698
|
+
activeSettings: Settings,
|
|
699
|
+
): Promise<ScopedModel[]> {
|
|
700
|
+
const modelPatterns = parsed.models ?? activeSettings.get("enabledModels");
|
|
701
|
+
if (!modelPatterns || modelPatterns.length === 0) {
|
|
702
|
+
return [];
|
|
703
|
+
}
|
|
704
|
+
return await resolveModelScope(
|
|
705
|
+
modelPatterns,
|
|
706
|
+
modelRegistry,
|
|
707
|
+
getModelMatchPreferences(activeSettings),
|
|
708
|
+
activeSettings,
|
|
709
|
+
);
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
async function getChangelogForDisplay(
|
|
713
|
+
parsed: Args,
|
|
714
|
+
mode: SettingValue<"startup.changelogMode">,
|
|
715
|
+
): Promise<StartupChangelogSelection | undefined> {
|
|
716
|
+
if (parsed.continue || parsed.resume || isForeignSessionImport(parsed)) {
|
|
717
|
+
return undefined;
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
return resolveStartupChangelogForDisplay({
|
|
721
|
+
mode,
|
|
722
|
+
currentVersion: VERSION,
|
|
723
|
+
changelogPath: getChangelogPath(),
|
|
724
|
+
});
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
const SESSION_ID_ARG_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
728
|
+
|
|
729
|
+
export function normalizeContinueSessionArgs(parsed: Args, rawArgs?: readonly string[]): void {
|
|
730
|
+
if (!parsed.continue || parsed.resume || parsed.fork) return;
|
|
731
|
+
|
|
732
|
+
let message: string | undefined;
|
|
733
|
+
if (parsed.unrecognizedFlags.length === 0 && parsed.messages.length === 1) {
|
|
734
|
+
message = parsed.messages[0]?.trim();
|
|
735
|
+
} else if (rawArgs) {
|
|
736
|
+
const continueIndex = rawArgs.findIndex(arg => arg === "--continue" || arg === "-c");
|
|
737
|
+
message = rawArgs[continueIndex + 1]?.trim();
|
|
738
|
+
}
|
|
739
|
+
if (!message || !SESSION_ID_ARG_RE.test(message)) return;
|
|
740
|
+
|
|
741
|
+
const messageIndex = parsed.messages.indexOf(message);
|
|
742
|
+
if (messageIndex === -1) return;
|
|
743
|
+
parsed.resume = message;
|
|
744
|
+
parsed.continue = false;
|
|
745
|
+
parsed.messages.splice(messageIndex, 1);
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
/** Resolves CLI session flags into an existing, forked, in-memory, or cancelled session manager. */
|
|
749
|
+
export async function createSessionManager(
|
|
750
|
+
parsed: Args,
|
|
751
|
+
cwd: string,
|
|
752
|
+
activeSettings: Settings = settings,
|
|
753
|
+
askToMoveSession: SessionPrompt = promptMoveSession,
|
|
754
|
+
): Promise<SessionManager | undefined> {
|
|
755
|
+
if (parsed.fork) {
|
|
756
|
+
if (parsed.noSession) {
|
|
757
|
+
throw new SessionResolutionError("--fork requires session persistence");
|
|
758
|
+
}
|
|
759
|
+
const forkSource = parsed.fork;
|
|
760
|
+
if (forkSource.includes("/") || forkSource.includes("\\") || forkSource.endsWith(".jsonl")) {
|
|
761
|
+
return await SessionManager.forkFrom(forkSource, cwd, parsed.sessionDir);
|
|
762
|
+
}
|
|
763
|
+
const match = await resolveResumableSession(forkSource, cwd, parsed.sessionDir);
|
|
764
|
+
if (!match) {
|
|
765
|
+
throw new SessionResolutionError(
|
|
766
|
+
`Session "${forkSource}" not found.`,
|
|
767
|
+
"Run `omp --resume` without an argument to pick from recent sessions, or `omp` to start a new one.",
|
|
768
|
+
);
|
|
769
|
+
}
|
|
770
|
+
return await SessionManager.forkFrom(match.session.path, cwd, parsed.sessionDir);
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
if (parsed.noSession) {
|
|
774
|
+
return SessionManager.inMemory();
|
|
775
|
+
}
|
|
776
|
+
normalizeContinueSessionArgs(parsed);
|
|
777
|
+
|
|
778
|
+
if (typeof parsed.resume === "string") {
|
|
779
|
+
const sessionArg = parsed.resume;
|
|
780
|
+
if (sessionArg.includes("/") || sessionArg.includes("\\") || sessionArg.endsWith(".jsonl")) {
|
|
781
|
+
return await SessionManager.open(sessionArg, parsed.sessionDir);
|
|
782
|
+
}
|
|
783
|
+
const match = await resolveResumableSession(sessionArg, cwd, parsed.sessionDir);
|
|
784
|
+
if (!match) {
|
|
785
|
+
throw new SessionResolutionError(
|
|
786
|
+
`Session "${sessionArg}" not found.`,
|
|
787
|
+
"Run `omp --resume` without an argument to pick from recent sessions, or `omp` to start a new one.",
|
|
788
|
+
);
|
|
789
|
+
}
|
|
790
|
+
if (match.scope === "local") {
|
|
791
|
+
const moveResult = await moveMissingCwdSessionIfNeeded(
|
|
792
|
+
sessionArg,
|
|
793
|
+
match.session,
|
|
794
|
+
cwd,
|
|
795
|
+
parsed.sessionDir,
|
|
796
|
+
askToMoveSession,
|
|
797
|
+
);
|
|
798
|
+
if (moveResult.status === "moved") {
|
|
799
|
+
return moveResult.manager;
|
|
800
|
+
}
|
|
801
|
+
if (moveResult.status === "declined") {
|
|
802
|
+
return undefined;
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
if (match.scope === "global") {
|
|
806
|
+
const moveResult = await moveMissingCwdSessionIfNeeded(
|
|
807
|
+
sessionArg,
|
|
808
|
+
match.session,
|
|
809
|
+
cwd,
|
|
810
|
+
parsed.sessionDir,
|
|
811
|
+
askToMoveSession,
|
|
812
|
+
);
|
|
813
|
+
if (moveResult.status === "moved") {
|
|
814
|
+
return moveResult.manager;
|
|
815
|
+
}
|
|
816
|
+
if (moveResult.status === "declined") {
|
|
817
|
+
return undefined;
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
return await SessionManager.open(match.session.path, parsed.sessionDir);
|
|
821
|
+
}
|
|
822
|
+
if (parsed.continue) {
|
|
823
|
+
return await SessionManager.continueRecent(cwd, parsed.sessionDir);
|
|
824
|
+
}
|
|
825
|
+
// --resume without value is handled separately (needs picker UI)
|
|
826
|
+
// If --session-dir provided without --continue/--resume, create new session there
|
|
827
|
+
if (parsed.sessionDir) {
|
|
828
|
+
return SessionManager.create(cwd, parsed.sessionDir);
|
|
829
|
+
}
|
|
830
|
+
// Auto-resume: behave like --continue if the setting is enabled and a prior
|
|
831
|
+
// session exists. When a prior session is resumed, mark parsed.continue so
|
|
832
|
+
// buildSessionOptions restores the session's model/thinking instead of
|
|
833
|
+
// overriding them with CLI defaults.
|
|
834
|
+
if (activeSettings.get("autoResume")) {
|
|
835
|
+
const manager = await SessionManager.continueRecent(cwd, parsed.sessionDir);
|
|
836
|
+
if (manager.getEntries().length > 0) {
|
|
837
|
+
parsed.continue = true;
|
|
838
|
+
}
|
|
839
|
+
return manager;
|
|
840
|
+
}
|
|
841
|
+
// Default case (new session) returns undefined, SDK will create one
|
|
842
|
+
return undefined;
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
/** Discover SYSTEM.md file if no CLI system prompt was provided */
|
|
846
|
+
function discoverSystemPromptFile(): string | undefined {
|
|
847
|
+
// Check project-local first (.omp/SYSTEM.md, .pi/SYSTEM.md legacy)
|
|
848
|
+
const projectPath = findConfigFile("SYSTEM.md", { user: false });
|
|
849
|
+
if (projectPath) {
|
|
850
|
+
return projectPath;
|
|
851
|
+
}
|
|
852
|
+
// If not found, check SYSTEM.md file in the global directory.
|
|
853
|
+
const globalPath = findConfigFile("SYSTEM.md", { user: true });
|
|
854
|
+
if (globalPath) {
|
|
855
|
+
return globalPath;
|
|
856
|
+
}
|
|
857
|
+
return undefined;
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
/** Discover APPEND_SYSTEM.md file if no CLI append system prompt was provided */
|
|
861
|
+
function discoverAppendSystemPromptFile(): string | undefined {
|
|
862
|
+
const projectPath = findConfigFile("APPEND_SYSTEM.md", { user: false });
|
|
863
|
+
if (projectPath) {
|
|
864
|
+
return projectPath;
|
|
865
|
+
}
|
|
866
|
+
const globalPath = findConfigFile("APPEND_SYSTEM.md", { user: true });
|
|
867
|
+
if (globalPath) {
|
|
868
|
+
return globalPath;
|
|
869
|
+
}
|
|
870
|
+
return undefined;
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
/** Apply resolved CLI/discovered prompt files without bypassing system prompt templates. */
|
|
874
|
+
export function applyResolvedSystemPromptInputs(
|
|
875
|
+
options: CreateAgentSessionOptions,
|
|
876
|
+
resolvedSystemPrompt: string | undefined,
|
|
877
|
+
resolvedAppendPrompt: string | undefined,
|
|
878
|
+
): void {
|
|
879
|
+
if (resolvedSystemPrompt) {
|
|
880
|
+
options.customSystemPrompt = resolvedSystemPrompt;
|
|
881
|
+
}
|
|
882
|
+
if (resolvedAppendPrompt) {
|
|
883
|
+
options.appendSystemPrompt = resolvedAppendPrompt;
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
/** Builds startup session options from parsed CLI flags, scoped models, and resolved session lineage. */
|
|
888
|
+
export async function buildSessionOptions(
|
|
889
|
+
parsed: Args,
|
|
890
|
+
scopedModels: ScopedModel[],
|
|
891
|
+
sessionManager: SessionManager | undefined,
|
|
892
|
+
modelRegistry: ModelRegistry,
|
|
893
|
+
activeSettings: Settings,
|
|
894
|
+
): Promise<CreateAgentSessionOptions> {
|
|
895
|
+
const options: CreateAgentSessionOptions = {
|
|
896
|
+
cwd: parsed.cwd ?? getProjectDir(),
|
|
897
|
+
autoApprove: parsed.autoApprove ?? false,
|
|
898
|
+
};
|
|
899
|
+
const restoringSession = Boolean(parsed.continue || parsed.resume || isForeignSessionImport(parsed));
|
|
900
|
+
if (parsed.serviceTier !== undefined) {
|
|
901
|
+
options.openAIServiceTier = serviceTierSettingToTier(parsed.serviceTier) ?? null;
|
|
902
|
+
}
|
|
903
|
+
const cliDirs = parsed.addDir ?? [];
|
|
904
|
+
const settingsDirs = activeSettings.get("workspace.additionalDirectories");
|
|
905
|
+
if (cliDirs.length > 0 || settingsDirs.length > 0) {
|
|
906
|
+
options.additionalDirectories = [...new Set([...cliDirs, ...settingsDirs])];
|
|
907
|
+
}
|
|
908
|
+
if (parsed.maxTime !== undefined) {
|
|
909
|
+
options.deadline = Date.now() + parsed.maxTime * 1000;
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
// Auto-discover SYSTEM.md if no CLI system prompt provided
|
|
913
|
+
const systemPromptSource = parsed.systemPrompt ?? discoverSystemPromptFile();
|
|
914
|
+
const appendPromptSource = parsed.appendSystemPrompt ?? discoverAppendSystemPromptFile();
|
|
915
|
+
const titleSystemPromptSource = discoverTitleSystemPromptFile();
|
|
916
|
+
const [resolvedSystemPrompt, resolvedAppendPrompt, titleSystemPrompt] = await Promise.all([
|
|
917
|
+
resolvePromptInput(systemPromptSource, "system prompt"),
|
|
918
|
+
resolvePromptInput(appendPromptSource, "append system prompt"),
|
|
919
|
+
resolvePromptInput(titleSystemPromptSource, "title system prompt"),
|
|
920
|
+
]);
|
|
921
|
+
|
|
922
|
+
if (sessionManager) {
|
|
923
|
+
options.sessionManager = sessionManager;
|
|
924
|
+
}
|
|
925
|
+
if (parsed.providerSessionId) {
|
|
926
|
+
options.providerSessionId = parsed.providerSessionId;
|
|
927
|
+
}
|
|
928
|
+
if (parsed.providerPromptCacheKey) {
|
|
929
|
+
options.providerPromptCacheKey = parsed.providerPromptCacheKey;
|
|
930
|
+
options.providerPromptCacheKeySource = "explicit";
|
|
931
|
+
} else {
|
|
932
|
+
const header = sessionManager?.getHeader();
|
|
933
|
+
const scopedModelOverride = scopedModels.length > 0 && !restoringSession;
|
|
934
|
+
const forkCacheShapeChanged =
|
|
935
|
+
scopedModelOverride ||
|
|
936
|
+
parsed.model !== undefined ||
|
|
937
|
+
parsed.thinking !== undefined ||
|
|
938
|
+
parsed.systemPrompt !== undefined ||
|
|
939
|
+
parsed.appendSystemPrompt !== undefined ||
|
|
940
|
+
parsed.tools !== undefined ||
|
|
941
|
+
parsed.noTools === true;
|
|
942
|
+
if (!forkCacheShapeChanged && header?.providerPromptCacheKey) {
|
|
943
|
+
options.providerPromptCacheKey = header.providerPromptCacheKey;
|
|
944
|
+
options.providerPromptCacheKeySource = "fork";
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
// Model from CLI
|
|
949
|
+
// - supports --provider <name> --model <pattern>
|
|
950
|
+
// - supports --model <provider>/<pattern>
|
|
951
|
+
const modelMatchPreferences = getModelMatchPreferences(activeSettings);
|
|
952
|
+
// True when a configured `default` role was deliberately left unresolved for
|
|
953
|
+
// createAgentSession's post-extension re-resolution (issue #6694); the
|
|
954
|
+
// scoped thinking-level seed below must be deferred along with the model.
|
|
955
|
+
let deferredDefaultRole = false;
|
|
956
|
+
if (parsed.model) {
|
|
957
|
+
const resolved = resolveCliModel({
|
|
958
|
+
cliProvider: parsed.provider,
|
|
959
|
+
cliModel: parsed.model,
|
|
960
|
+
modelRegistry,
|
|
961
|
+
availableModels: modelRegistry.getAvailable(),
|
|
962
|
+
settings: activeSettings,
|
|
963
|
+
preferences: modelMatchPreferences,
|
|
964
|
+
});
|
|
965
|
+
if (resolved.warning) {
|
|
966
|
+
process.stderr.write(`${chalk.yellow(`Warning: ${resolved.warning}`)}\n`);
|
|
967
|
+
}
|
|
968
|
+
const matchedAfterMissingRolePattern = (resolved.configuredPatternIndex ?? 0) > 0;
|
|
969
|
+
if (matchedAfterMissingRolePattern) {
|
|
970
|
+
// Extensions may register an earlier configured role candidate.
|
|
971
|
+
options.modelPattern = parsed.model;
|
|
972
|
+
} else if (resolved.error) {
|
|
973
|
+
if (!parsed.provider && ((resolved.configuredPatterns?.length ?? 0) > 0 || !parsed.model.includes(":"))) {
|
|
974
|
+
// Model not found in built-in registry — defer resolution to after extensions load
|
|
975
|
+
// (extensions may register additional providers/models via registerProvider)
|
|
976
|
+
options.modelPattern = parsed.model;
|
|
977
|
+
} else {
|
|
978
|
+
process.stderr.write(`${chalk.red(resolved.error)}\n`);
|
|
979
|
+
process.exit(1);
|
|
980
|
+
}
|
|
981
|
+
} else if (resolved.model) {
|
|
982
|
+
options.model = resolved.model;
|
|
983
|
+
activeSettings.overrideModelRoles({
|
|
984
|
+
default: resolved.selector ?? `${resolved.model.provider}/${resolved.model.id}`,
|
|
985
|
+
});
|
|
986
|
+
if (!parsed.thinking && resolved.thinkingLevel) {
|
|
987
|
+
options.thinkingLevel = resolved.thinkingLevel;
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
} else if (scopedModels.length > 0 && !restoringSession) {
|
|
991
|
+
const remembered = activeSettings.getModelRole("default");
|
|
992
|
+
if (remembered) {
|
|
993
|
+
const rememberedSpec = resolveModelRoleValue(
|
|
994
|
+
remembered,
|
|
995
|
+
scopedModels.map(scopedModel => scopedModel.model),
|
|
996
|
+
{
|
|
997
|
+
settings: activeSettings,
|
|
998
|
+
matchPreferences: modelMatchPreferences,
|
|
999
|
+
},
|
|
1000
|
+
);
|
|
1001
|
+
const rememberedResolvedModel = rememberedSpec.model;
|
|
1002
|
+
const rememberedModel = rememberedResolvedModel
|
|
1003
|
+
? scopedModels.find(
|
|
1004
|
+
scopedModel =>
|
|
1005
|
+
scopedModel.model.provider === rememberedResolvedModel.provider &&
|
|
1006
|
+
scopedModel.model.id === rememberedResolvedModel.id,
|
|
1007
|
+
)
|
|
1008
|
+
: scopedModels.find(scopedModel => scopedModel.model.id.toLowerCase() === remembered.toLowerCase());
|
|
1009
|
+
if (rememberedModel) {
|
|
1010
|
+
options.model = rememberedModel.model;
|
|
1011
|
+
// Apply explicit thinking level from remembered role value
|
|
1012
|
+
if (!parsed.thinking && rememberedSpec.explicitThinkingLevel && rememberedSpec.thinkingLevel) {
|
|
1013
|
+
options.thinkingLevel = rememberedSpec.thinkingLevel;
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
// A configured `default` role that doesn't resolve within the startup
|
|
1018
|
+
// scope is deferred, NOT silently pinned to `scopedModels[0]`: the scope
|
|
1019
|
+
// is resolved before extensions register their providers, so a role naming
|
|
1020
|
+
// an extension-registered model (listed in `enabledModels`) would drop out
|
|
1021
|
+
// here and the session would run on an unrelated in-scope provider without
|
|
1022
|
+
// any error. Leaving `options.model` unset lets createAgentSession's
|
|
1023
|
+
// post-extension default-role resolution reclaim it against the fully
|
|
1024
|
+
// registered, still enabledModels-scoped catalog (issue #6694).
|
|
1025
|
+
// Defer ONLY for a settings-derived scope: createAgentSession re-resolves
|
|
1026
|
+
// against `settings.enabledModels` and never sees CLI `--models`, so
|
|
1027
|
+
// deferring under an explicit CLI scope would let the saved default
|
|
1028
|
+
// escape it — keep pinning the first scoped model there.
|
|
1029
|
+
deferredDefaultRole = !options.model && Boolean(remembered) && !((parsed.models?.length ?? 0) > 0);
|
|
1030
|
+
if (!options.model && !deferredDefaultRole) options.model = scopedModels[0].model;
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
if (parsed.noPrewalk && (parsed.prewalk || parsed.prewalkInto !== undefined)) {
|
|
1034
|
+
throw new Error("--no-prewalk cannot be combined with --prewalk or --prewalk-into");
|
|
1035
|
+
}
|
|
1036
|
+
const prewalkEnabled = parsed.noPrewalk
|
|
1037
|
+
? false
|
|
1038
|
+
: parsed.prewalk === true || parsed.prewalkInto !== undefined
|
|
1039
|
+
? true
|
|
1040
|
+
: activeSettings.get("prewalk.enabled");
|
|
1041
|
+
if (prewalkEnabled) {
|
|
1042
|
+
const rolePattern = expandRoleAlias(parsed.prewalkInto ?? DEFAULT_PREWALK_TARGET, activeSettings);
|
|
1043
|
+
const resolved = resolveCliModel({ cliModel: rolePattern, modelRegistry, preferences: modelMatchPreferences });
|
|
1044
|
+
if (resolved.warning) {
|
|
1045
|
+
process.stderr.write(`${chalk.yellow(`Warning: ${resolved.warning}`)}\n`);
|
|
1046
|
+
}
|
|
1047
|
+
// Prewalk is an optional optimization (off by default): switch to a fast
|
|
1048
|
+
// model at the first edit. If its hand-off target can't be resolved or has
|
|
1049
|
+
// no configured auth, warn and leave prewalk unarmed rather than aborting
|
|
1050
|
+
// startup and locking the user out of the app (issue #6064).
|
|
1051
|
+
if (resolved.error || !resolved.model) {
|
|
1052
|
+
const target = parsed.prewalkInto ?? DEFAULT_PREWALK_TARGET;
|
|
1053
|
+
process.stderr.write(
|
|
1054
|
+
`${chalk.yellow(`Warning: prewalk disabled — ${resolved.error ?? `model "${target}" not found`}`)}\n`,
|
|
1055
|
+
);
|
|
1056
|
+
} else if (!modelRegistry.hasConfiguredAuth(resolved.model)) {
|
|
1057
|
+
process.stderr.write(
|
|
1058
|
+
`${chalk.yellow(`Warning: prewalk disabled — no API key for ${resolved.model.provider}/${resolved.model.id}`)}\n`,
|
|
1059
|
+
);
|
|
1060
|
+
} else {
|
|
1061
|
+
options.prewalk = { target: resolved.model, thinkingLevel: resolved.thinkingLevel };
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
if (parsed.planYoloInto !== undefined && !parsed.planYolo) {
|
|
1066
|
+
throw new Error("--plan-yolo-into requires --plan-yolo");
|
|
1067
|
+
}
|
|
1068
|
+
if (parsed.planYolo) {
|
|
1069
|
+
const rolePattern = expandRoleAlias(parsed.planYoloInto ?? "@smol", activeSettings);
|
|
1070
|
+
const resolved = resolveCliModel({ cliModel: rolePattern, modelRegistry, preferences: modelMatchPreferences });
|
|
1071
|
+
if (resolved.warning) {
|
|
1072
|
+
process.stderr.write(`${chalk.yellow(`Warning: ${resolved.warning}`)}\n`);
|
|
1073
|
+
}
|
|
1074
|
+
if (resolved.error || !resolved.model) {
|
|
1075
|
+
throw new Error(resolved.error ?? `Model "${parsed.planYoloInto ?? "@smol"}" not found`);
|
|
1076
|
+
}
|
|
1077
|
+
if (!modelRegistry.hasConfiguredAuth(resolved.model)) {
|
|
1078
|
+
throw new Error(`No API key for ${resolved.model.provider}/${resolved.model.id}`);
|
|
1079
|
+
}
|
|
1080
|
+
options.planYolo = { target: resolved.model, thinkingLevel: resolved.thinkingLevel };
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
// Thinking level
|
|
1084
|
+
if (parsed.thinking) {
|
|
1085
|
+
options.thinkingLevel = parsed.thinking;
|
|
1086
|
+
} else if (
|
|
1087
|
+
scopedModels.length > 0 &&
|
|
1088
|
+
scopedModels[0].explicitThinkingLevel === true &&
|
|
1089
|
+
// A deferred default role resolves its own model (and any explicit
|
|
1090
|
+
// thinking suffix) after extensions register; seeding the fallback
|
|
1091
|
+
// scoped model's level here would override it in createAgentSession.
|
|
1092
|
+
!deferredDefaultRole &&
|
|
1093
|
+
!restoringSession
|
|
1094
|
+
) {
|
|
1095
|
+
options.thinkingLevel = scopedModels[0].thinkingLevel;
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
// Scoped models for Ctrl+P cycling - fill in default thinking levels when not explicit
|
|
1099
|
+
if (scopedModels.length > 0) {
|
|
1100
|
+
// `auto` is a session-level concept only; per-scoped-model (Ctrl+P) thinking
|
|
1101
|
+
// overrides stay concrete, so coerce the auto default to "unset" here.
|
|
1102
|
+
const defaultThinkingLevel = concreteThinkingLevel(
|
|
1103
|
+
parseConfiguredThinkingLevel(activeSettings.get("defaultThinkingLevel")),
|
|
1104
|
+
);
|
|
1105
|
+
options.scopedModels = scopedModels.map(scopedModel => ({
|
|
1106
|
+
model: scopedModel.model,
|
|
1107
|
+
thinkingLevel: scopedModel.explicitThinkingLevel
|
|
1108
|
+
? (scopedModel.thinkingLevel ?? defaultThinkingLevel)
|
|
1109
|
+
: defaultThinkingLevel,
|
|
1110
|
+
}));
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
// API key from CLI - set in authStorage
|
|
1114
|
+
// (handled by caller before createAgentSession)
|
|
1115
|
+
|
|
1116
|
+
// System prompt
|
|
1117
|
+
applyResolvedSystemPromptInputs(options, resolvedSystemPrompt, resolvedAppendPrompt);
|
|
1118
|
+
// Replan-driven title refresh resolves the override from this same field on
|
|
1119
|
+
// `AgentSession`, so threading it through `CreateAgentSessionOptions` keeps
|
|
1120
|
+
// both first-input titling (`input-controller.ts`) and replan refresh
|
|
1121
|
+
// (`AgentSession.#refreshTitleAfterReplan`) on one source of truth.
|
|
1122
|
+
if (titleSystemPrompt) {
|
|
1123
|
+
options.titleSystemPrompt = titleSystemPrompt;
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
// Tools
|
|
1127
|
+
if (parsed.noTools) {
|
|
1128
|
+
options.toolNames = parsed.tools && parsed.tools.length > 0 ? parsed.tools : [];
|
|
1129
|
+
} else if (parsed.tools) {
|
|
1130
|
+
options.toolNames = parsed.tools;
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1133
|
+
if (parsed.noLsp) {
|
|
1134
|
+
options.enableLsp = false;
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
// Skills
|
|
1138
|
+
if (parsed.noSkills) {
|
|
1139
|
+
options.skills = [];
|
|
1140
|
+
} else if (parsed.skills && parsed.skills.length > 0) {
|
|
1141
|
+
// Override includeSkills for this session
|
|
1142
|
+
activeSettings.override("skills.includeSkills", parsed.skills as string[]);
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
// Rules
|
|
1146
|
+
if (parsed.noRules) {
|
|
1147
|
+
options.rules = [];
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
// Trusted extension paths are an exact allowlist for extension modules.
|
|
1151
|
+
if (parsed.trustedExtensions && parsed.trustedExtensions.length > 0) {
|
|
1152
|
+
const trustedPaths = parsed.trustedExtensions.map(trustedPath => {
|
|
1153
|
+
let resolvedPath: string;
|
|
1154
|
+
let stat: fsSync.Stats;
|
|
1155
|
+
try {
|
|
1156
|
+
resolvedPath = fsSync.realpathSync.native(trustedPath);
|
|
1157
|
+
stat = fsSync.statSync(resolvedPath);
|
|
1158
|
+
} catch {
|
|
1159
|
+
throw new Error(`Trusted extension must be an existing module file: ${trustedPath}`);
|
|
1160
|
+
}
|
|
1161
|
+
if (!stat.isFile()) {
|
|
1162
|
+
throw new Error(`Trusted extension must be a module file, not a directory: ${trustedPath}`);
|
|
1163
|
+
}
|
|
1164
|
+
return resolvedPath;
|
|
1165
|
+
});
|
|
1166
|
+
options.disableExtensionDiscovery = true;
|
|
1167
|
+
options.additionalExtensionPaths = trustedPaths;
|
|
1168
|
+
} else {
|
|
1169
|
+
// Additional extension paths from CLI
|
|
1170
|
+
const cliExtensionPaths = [...(parsed.extensions ?? []), ...(parsed.hooks ?? [])];
|
|
1171
|
+
if (cliExtensionPaths.length > 0) {
|
|
1172
|
+
options.additionalExtensionPaths = cliExtensionPaths;
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
if (parsed.noExtensions) {
|
|
1176
|
+
options.disableExtensionDiscovery = true;
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
return options;
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
interface RunRootCommandDependencies {
|
|
1184
|
+
createAgentSession?: typeof createAgentSession;
|
|
1185
|
+
discoverAuthStorage?: typeof discoverAuthStorage;
|
|
1186
|
+
selectSession?: typeof selectSession;
|
|
1187
|
+
runAcpMode?: RunAcpMode;
|
|
1188
|
+
createForeignSessionStore?: (source: ForeignSessionSource) => ForeignSessionStore;
|
|
1189
|
+
settings?: Settings;
|
|
1190
|
+
forceSetupWizard?: boolean;
|
|
1191
|
+
}
|
|
1192
|
+
const DEFAULT_RUN_ROOT_DEPENDENCIES: RunRootCommandDependencies = {};
|
|
1193
|
+
|
|
1194
|
+
export async function runRootCommand(
|
|
1195
|
+
parsed: Args,
|
|
1196
|
+
rawArgs: string[],
|
|
1197
|
+
deps: RunRootCommandDependencies = DEFAULT_RUN_ROOT_DEPENDENCIES,
|
|
1198
|
+
): Promise<void> {
|
|
1199
|
+
logger.startTiming();
|
|
1200
|
+
startStartupWatchdog();
|
|
1201
|
+
|
|
1202
|
+
// Initialize theme early with defaults (CLI commands need symbols)
|
|
1203
|
+
// Will be re-initialized with user preferences later
|
|
1204
|
+
await logger.time("initTheme:initial", initTheme);
|
|
1205
|
+
|
|
1206
|
+
const parsedArgs = parsed;
|
|
1207
|
+
await logger.time("applyStartupCwd", applyStartupCwd, parsedArgs);
|
|
1208
|
+
|
|
1209
|
+
const notifs: (InteractiveModeNotify | null)[] = [];
|
|
1210
|
+
|
|
1211
|
+
if (parsedArgs.version) {
|
|
1212
|
+
writeStartupNotice(parsedArgs, `${VERSION}\n`);
|
|
1213
|
+
process.exit(0);
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1216
|
+
if (parsedArgs.export) {
|
|
1217
|
+
let result: string;
|
|
1218
|
+
try {
|
|
1219
|
+
const outputPath = parsedArgs.messages.length > 0 ? parsedArgs.messages[0] : undefined;
|
|
1220
|
+
const { exportFromFile } = await import("./export/html");
|
|
1221
|
+
result = await exportFromFile(parsedArgs.export, outputPath);
|
|
1222
|
+
} catch (error: unknown) {
|
|
1223
|
+
const message = error instanceof Error ? error.message : "Failed to export session";
|
|
1224
|
+
process.stderr.write(`${chalk.red(`Error: ${message}`)}\n`);
|
|
1225
|
+
process.exit(1);
|
|
1226
|
+
}
|
|
1227
|
+
writeStartupNotice(parsedArgs, `Exported to: ${result}\n`);
|
|
1228
|
+
process.exit(0);
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1231
|
+
if ((parsedArgs.mode === "rpc" || parsedArgs.mode === "rpc-ui") && parsedArgs.fileArgs.length > 0) {
|
|
1232
|
+
process.stderr.write(`${chalk.red("Error: @file arguments are not supported in RPC mode")}\n`);
|
|
1233
|
+
process.exit(1);
|
|
1234
|
+
}
|
|
1235
|
+
const mode = parsedArgs.mode || "text";
|
|
1236
|
+
// RPC owns stdin. Claim its singleton stream before plugin/extension discovery can load an in-process consumer.
|
|
1237
|
+
const rpcInput = mode === "rpc" || mode === "rpc-ui" ? claimRpcInput() : undefined;
|
|
1238
|
+
|
|
1239
|
+
// Kick off plugin-root preload in parallel with the remaining startup work.
|
|
1240
|
+
// Awaited later (before extension/skill discovery in createAgentSession needs it).
|
|
1241
|
+
const home = os.homedir();
|
|
1242
|
+
const pluginPreloadPromise =
|
|
1243
|
+
parsedArgs.pluginDirs && parsedArgs.pluginDirs.length > 0
|
|
1244
|
+
? logger.time("injectPluginDirRoots", injectPluginDirRoots, home, parsedArgs.pluginDirs, getProjectDir())
|
|
1245
|
+
: logger.time("preloadPluginRoots", preloadPluginRoots, home, getProjectDir());
|
|
1246
|
+
// Mark the promise as handled so a synchronous failure does not surface as an unhandled-rejection
|
|
1247
|
+
// warning before we reach the await site below.
|
|
1248
|
+
pluginPreloadPromise.catch(() => {});
|
|
1249
|
+
|
|
1250
|
+
// Trusted files load as exact module paths, never as package roots whose
|
|
1251
|
+
// sibling hooks/tools/commands/MCP content could be discovered implicitly.
|
|
1252
|
+
if (!parsedArgs.trustedExtensions?.length) {
|
|
1253
|
+
// Register CLI-provided extension package paths (`--extension`, `--hook`) so
|
|
1254
|
+
// the `omp-plugins` discovery provider can surface their `skills/`, `hooks/`,
|
|
1255
|
+
// `tools/`, `commands/`, `rules/`, `prompts/`, and `.mcp.json` sub-trees.
|
|
1256
|
+
// Explicit roots remain authorized under `--no-extensions`; only ambient
|
|
1257
|
+
// extension discovery is disabled.
|
|
1258
|
+
const cliExtensions = [...(parsedArgs.extensions ?? []), ...(parsedArgs.hooks ?? [])];
|
|
1259
|
+
injectOmpExtensionCliRoots(cliExtensions, home, getProjectDir(), {
|
|
1260
|
+
mode: parsedArgs.noExtensions ? "explicit-only" : "merge",
|
|
1261
|
+
replace: true,
|
|
1262
|
+
});
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1265
|
+
let cwd = getProjectDir();
|
|
1266
|
+
// Classify the host before opening auth or settings storage so every
|
|
1267
|
+
// session-critical database connection picks the right busy timeout.
|
|
1268
|
+
// See getDbBusyTimeoutMs().
|
|
1269
|
+
const isProtocolMode = mode === "rpc" || mode === "rpc-ui" || mode === "acp";
|
|
1270
|
+
// Protocol modes own stdin; treating it as prompt text would consume JSON-RPC frames before their transports start.
|
|
1271
|
+
const pipedInput = isProtocolMode ? undefined : await logger.time("readPipedInput", readPipedInput);
|
|
1272
|
+
const autoPrint = pipedInput !== undefined && !parsedArgs.print && parsedArgs.mode === undefined;
|
|
1273
|
+
const isInteractive = !parsedArgs.print && !autoPrint && parsedArgs.mode === undefined;
|
|
1274
|
+
// Only the interactive host renders a focusable Agent Hub / subagent session
|
|
1275
|
+
// tree; declare it so headless subagent optimizations (e.g. skipping replan
|
|
1276
|
+
// title refresh) can tell a focusable process from a print/RPC/eval one.
|
|
1277
|
+
setInteractiveHost(isInteractive);
|
|
1278
|
+
// Create AuthStorage and ModelRegistry upfront
|
|
1279
|
+
const authStorage = await logger.time("discoverAuthStorage", deps.discoverAuthStorage ?? discoverAuthStorage);
|
|
1280
|
+
const modelRegistry = logger.time("modelRegistry:init", () => new ModelRegistry(authStorage));
|
|
1281
|
+
|
|
1282
|
+
const settingsInstance =
|
|
1283
|
+
deps.settings ?? (await logger.time("settings:init", Settings.init, { cwd, configFiles: parsedArgs.config }));
|
|
1284
|
+
if (parsedArgs.approvalMode) {
|
|
1285
|
+
// Runtime override (not persisted): every settings.get("tools.approvalMode") downstream
|
|
1286
|
+
// sees this value. The wrapper still honours --auto-approve / --yolo on top of it.
|
|
1287
|
+
settingsInstance.override("tools.approvalMode", parsedArgs.approvalMode);
|
|
1288
|
+
} else if (parsedArgs.autoApprove) {
|
|
1289
|
+
// --auto-approve / --yolo without an explicit --approval-mode: reflect in settings so
|
|
1290
|
+
// setup-time checks (e.g. #wrapToolForAcpPermission) also see the yolo intent.
|
|
1291
|
+
settingsInstance.override("tools.approvalMode", "yolo");
|
|
1292
|
+
}
|
|
1293
|
+
if (parsedArgs.mode === "rpc" || parsedArgs.mode === "rpc-ui") {
|
|
1294
|
+
applyRpcDefaultSettingOverrides(settingsInstance);
|
|
1295
|
+
} else if (parsedArgs.mode === "acp") {
|
|
1296
|
+
applyAcpDefaultSettingOverrides(settingsInstance);
|
|
1297
|
+
}
|
|
1298
|
+
if (parsedArgs.noPty || parsedArgs.mode === "rpc-ui") {
|
|
1299
|
+
Bun.env.PI_NO_PTY = "1";
|
|
1300
|
+
}
|
|
1301
|
+
if (parsedArgs.noTitle || parsedArgs.mode === "rpc" || parsedArgs.mode === "rpc-ui" || parsedArgs.mode === "acp") {
|
|
1302
|
+
Bun.env.PI_NO_TITLE = "1";
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
// Initialize discovery system with settings for provider persistence
|
|
1306
|
+
logger.time("initializeWithSettings", initializeWithSettings, settingsInstance);
|
|
1307
|
+
|
|
1308
|
+
// Apply model role overrides from CLI args or env vars (ephemeral, not persisted)
|
|
1309
|
+
const smolModel = parsedArgs.smol ?? $env.PI_SMOL_MODEL;
|
|
1310
|
+
const slowModel = parsedArgs.slow ?? $env.PI_SLOW_MODEL;
|
|
1311
|
+
const planModel = parsedArgs.plan ?? $env.PI_PLAN_MODEL;
|
|
1312
|
+
if (smolModel || slowModel || planModel) {
|
|
1313
|
+
settingsInstance.overrideModelRoles({
|
|
1314
|
+
smol: smolModel,
|
|
1315
|
+
slow: slowModel,
|
|
1316
|
+
plan: planModel,
|
|
1317
|
+
});
|
|
1318
|
+
}
|
|
1319
|
+
|
|
1320
|
+
// --print-thoughts (single-shot print mode) must surface reasoning, so un-hide
|
|
1321
|
+
// thinking before the session is built — otherwise a passive omitThinking
|
|
1322
|
+
// setting makes the provider omit summaries and the flag prints nothing. An
|
|
1323
|
+
// explicit --hide-thinking block display option still wins for output display.
|
|
1324
|
+
if (parsedArgs.printThoughts && !isProtocolMode && !isInteractive) {
|
|
1325
|
+
settingsInstance.override("omitThinking", false);
|
|
1326
|
+
}
|
|
1327
|
+
// Apply --hide-thinking CLI flag (ephemeral, not persisted)
|
|
1328
|
+
if (parsedArgs.hideThinking) {
|
|
1329
|
+
settingsInstance.override("hideThinkingBlock", true);
|
|
1330
|
+
}
|
|
1331
|
+
// Apply --advisor CLI flag (ephemeral, not persisted)
|
|
1332
|
+
if (parsedArgs.advisor) {
|
|
1333
|
+
settingsInstance.override("advisor.enabled", true);
|
|
1334
|
+
}
|
|
1335
|
+
|
|
1336
|
+
await logger.time(
|
|
1337
|
+
"initTheme:final",
|
|
1338
|
+
initTheme,
|
|
1339
|
+
isInteractive,
|
|
1340
|
+
settingsInstance.get("symbolPreset"),
|
|
1341
|
+
settingsInstance.get("colorBlindMode"),
|
|
1342
|
+
settingsInstance.get("theme.dark"),
|
|
1343
|
+
settingsInstance.get("theme.light"),
|
|
1344
|
+
);
|
|
1345
|
+
|
|
1346
|
+
let scopedModels = await logger.time(
|
|
1347
|
+
"resolveModelScope",
|
|
1348
|
+
resolveScopedModels,
|
|
1349
|
+
parsedArgs,
|
|
1350
|
+
modelRegistry,
|
|
1351
|
+
settingsInstance,
|
|
1352
|
+
);
|
|
1353
|
+
|
|
1354
|
+
// Resolve an explicit `--continue <id>` before extension flags are loaded.
|
|
1355
|
+
// Reading the token immediately after `--continue` distinguishes the session
|
|
1356
|
+
// id from UUID-shaped values owned by later extension flags.
|
|
1357
|
+
normalizeContinueSessionArgs(parsedArgs, rawArgs);
|
|
1358
|
+
|
|
1359
|
+
// Resolve native resume/fork flags or import one foreign transcript into a
|
|
1360
|
+
// fresh persisted OMP session before constructing the AgentSession.
|
|
1361
|
+
let sessionManager: SessionManager | undefined;
|
|
1362
|
+
let foreignSource: ForeignSessionSource | undefined;
|
|
1363
|
+
try {
|
|
1364
|
+
foreignSource = resolveForeignSessionSource(parsedArgs);
|
|
1365
|
+
if (foreignSource) {
|
|
1366
|
+
if (isProtocolMode) {
|
|
1367
|
+
throw new SessionResolutionError(`--from-${foreignSource} is not supported in ${mode} mode`);
|
|
1368
|
+
}
|
|
1369
|
+
const sourceName = foreignSessionSourceName(foreignSource);
|
|
1370
|
+
const store = (deps.createForeignSessionStore ?? createForeignSessionStore)(foreignSource);
|
|
1371
|
+
let foreignSessions: ForeignSessionInfo[];
|
|
1372
|
+
try {
|
|
1373
|
+
foreignSessions = await logger.time(`list${sourceName}Sessions`, () => store.list());
|
|
1374
|
+
} catch (error) {
|
|
1375
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1376
|
+
throw new SessionResolutionError(`Failed to list ${sourceName} sessions: ${message}`);
|
|
1377
|
+
}
|
|
1378
|
+
if (foreignSessions.length === 0) {
|
|
1379
|
+
writeStartupNotice(parsedArgs, `${chalk.dim(`No ${sourceName} sessions found`)}\n`);
|
|
1380
|
+
stopStartupWatchdog();
|
|
1381
|
+
process.exit(0);
|
|
1382
|
+
}
|
|
1383
|
+
const choices = foreignSessions.map(foreignSessionInfoToSessionInfo);
|
|
1384
|
+
pauseStartupWatchdog();
|
|
1385
|
+
let selected: SessionInfo | null;
|
|
1386
|
+
try {
|
|
1387
|
+
selected = await logger.time(`select${sourceName}Session`, deps.selectSession ?? selectSession, choices, {
|
|
1388
|
+
title: `Import ${sourceName} Session`,
|
|
1389
|
+
scopeLabel: false,
|
|
1390
|
+
showCwd: true,
|
|
1391
|
+
allowDelete: false,
|
|
1392
|
+
allowGlobalScope: false,
|
|
1393
|
+
historySearch: false,
|
|
1394
|
+
});
|
|
1395
|
+
} finally {
|
|
1396
|
+
resumeStartupWatchdog();
|
|
1397
|
+
}
|
|
1398
|
+
if (!selected) {
|
|
1399
|
+
writeStartupNotice(parsedArgs, `${chalk.dim(`No ${sourceName} session selected`)}\n`);
|
|
1400
|
+
stopStartupWatchdog();
|
|
1401
|
+
process.exit(0);
|
|
1402
|
+
}
|
|
1403
|
+
const foreignSession = foreignSessions.find(
|
|
1404
|
+
session => session.id === selected.id && session.path === selected.path,
|
|
1405
|
+
);
|
|
1406
|
+
if (!foreignSession) {
|
|
1407
|
+
throw new SessionResolutionError(`Selected ${sourceName} session is no longer available`);
|
|
1408
|
+
}
|
|
1409
|
+
try {
|
|
1410
|
+
sessionManager = await logger.time(
|
|
1411
|
+
`import${sourceName}Session`,
|
|
1412
|
+
persistForeignSession,
|
|
1413
|
+
store,
|
|
1414
|
+
foreignSession,
|
|
1415
|
+
{ fallbackCwd: cwd, sessionDir: parsedArgs.sessionDir },
|
|
1416
|
+
);
|
|
1417
|
+
} catch (error) {
|
|
1418
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1419
|
+
throw new SessionResolutionError(`Failed to import ${sourceName} session: ${message}`);
|
|
1420
|
+
}
|
|
1421
|
+
} else {
|
|
1422
|
+
sessionManager = await logger.time(
|
|
1423
|
+
"createSessionManager",
|
|
1424
|
+
createSessionManager,
|
|
1425
|
+
parsedArgs,
|
|
1426
|
+
cwd,
|
|
1427
|
+
settingsInstance,
|
|
1428
|
+
);
|
|
1429
|
+
}
|
|
1430
|
+
} catch (error: unknown) {
|
|
1431
|
+
if (error instanceof SessionResolutionError) {
|
|
1432
|
+
process.stderr.write(`${chalk.red(`Error: ${error.message}`)}\n`);
|
|
1433
|
+
if (error.hint) {
|
|
1434
|
+
process.stderr.write(`${chalk.dim(error.hint)}\n`);
|
|
1435
|
+
}
|
|
1436
|
+
process.exit(1);
|
|
1437
|
+
}
|
|
1438
|
+
throw error;
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
if ((typeof parsedArgs.resume === "string" || foreignSource) && sessionManager) {
|
|
1442
|
+
const previousCwd = cwd;
|
|
1443
|
+
cwd = await switchToResumedProject(sessionManager.getCwd(), settingsInstance, pluginPreloadPromise);
|
|
1444
|
+
if (cwd !== previousCwd) {
|
|
1445
|
+
// applyStartupCwd persists an explicit --cwd in parsedArgs; once resume
|
|
1446
|
+
// switches projects, keep session construction on the destination too.
|
|
1447
|
+
parsedArgs.cwd = cwd;
|
|
1448
|
+
// Destination project may scope a different `enabledModels`; re-resolve
|
|
1449
|
+
// so the model UI and session options reflect it (explicit `--models`
|
|
1450
|
+
// stays fixed inside resolveScopedModels).
|
|
1451
|
+
scopedModels = await resolveScopedModels(parsedArgs, modelRegistry, settingsInstance);
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1454
|
+
|
|
1455
|
+
// User declined the missing-directory move prompt — exit cleanly instead of
|
|
1456
|
+
// letting the cancellation fall through to a new session.
|
|
1457
|
+
if (typeof parsedArgs.resume === "string" && !sessionManager) {
|
|
1458
|
+
writeStartupNotice(parsedArgs, `${chalk.dim("Resume cancelled: session was not moved.")}\n`);
|
|
1459
|
+
stopStartupWatchdog();
|
|
1460
|
+
process.exit(0);
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1463
|
+
// Handle --resume (no value): show session picker
|
|
1464
|
+
if (parsedArgs.resume === true && !parsedArgs.fork) {
|
|
1465
|
+
const folderSessions = await logger.time("SessionManager.list", SessionManager.list, cwd, parsedArgs.sessionDir);
|
|
1466
|
+
let preloadedAllSessions: SessionInfo[] | undefined;
|
|
1467
|
+
if (folderSessions.length === 0) {
|
|
1468
|
+
// Probe globally so we can exit fast when the user has no sessions at
|
|
1469
|
+
// all, but never auto-switch the picker into all-projects scope — that
|
|
1470
|
+
// silently surfaced other projects' history when the cwd was empty
|
|
1471
|
+
// (issue #3099). The preloaded list also makes the user's Tab switch
|
|
1472
|
+
// instant on the way in.
|
|
1473
|
+
preloadedAllSessions = await logger.time("SessionManager.listAll", SessionManager.listAll);
|
|
1474
|
+
if (preloadedAllSessions.length === 0) {
|
|
1475
|
+
writeStartupNotice(parsedArgs, `${chalk.dim("No sessions found")}\n`);
|
|
1476
|
+
stopStartupWatchdog();
|
|
1477
|
+
process.exit(0);
|
|
1478
|
+
}
|
|
1479
|
+
}
|
|
1480
|
+
pauseStartupWatchdog();
|
|
1481
|
+
const selected = await logger.time("selectSession", deps.selectSession ?? selectSession, folderSessions, {
|
|
1482
|
+
allSessions: preloadedAllSessions,
|
|
1483
|
+
});
|
|
1484
|
+
resumeStartupWatchdog();
|
|
1485
|
+
if (!selected) {
|
|
1486
|
+
writeStartupNotice(parsedArgs, `${chalk.dim("No session selected")}\n`);
|
|
1487
|
+
// Quit instead of returning: startup already armed long-lived handles
|
|
1488
|
+
// (theme watcher + SIGWINCH/macOS appearance listeners via initTheme,
|
|
1489
|
+
// settings save timer, model registry) that keep the event loop alive,
|
|
1490
|
+
// so a bare return hangs the process after the picker leaves the alt
|
|
1491
|
+
// screen. No session was built here, so there is nothing to flush. The
|
|
1492
|
+
// in-session `/resume` picker (selector-controller.ts) takes a different
|
|
1493
|
+
// onCancel that just closes the overlay — only this startup path exits.
|
|
1494
|
+
stopStartupWatchdog();
|
|
1495
|
+
process.exit(0);
|
|
1496
|
+
}
|
|
1497
|
+
// Re-scope every cwd-derived input before building the resumed session.
|
|
1498
|
+
const previousCwd = cwd;
|
|
1499
|
+
cwd = await switchToResumedProject(selected.cwd, settingsInstance, pluginPreloadPromise);
|
|
1500
|
+
if (cwd !== previousCwd) {
|
|
1501
|
+
parsedArgs.cwd = cwd;
|
|
1502
|
+
scopedModels = await resolveScopedModels(parsedArgs, modelRegistry, settingsInstance);
|
|
1503
|
+
}
|
|
1504
|
+
sessionManager = await SessionManager.open(selected.path);
|
|
1505
|
+
}
|
|
1506
|
+
|
|
1507
|
+
if (sessionManager && (parsedArgs.continue || parsedArgs.resume || parsedArgs.fork || foreignSource)) {
|
|
1508
|
+
const pendingToolWarning = describePendingToolCalls(sessionManager.getBranch());
|
|
1509
|
+
if (pendingToolWarning) {
|
|
1510
|
+
logger.warn("Resumed session has pending tool calls", {
|
|
1511
|
+
sessionId: sessionManager.getSessionId(),
|
|
1512
|
+
sessionFile: sessionManager.getSessionFile(),
|
|
1513
|
+
});
|
|
1514
|
+
if (isInteractive) {
|
|
1515
|
+
notifs.push({ kind: "warn", message: pendingToolWarning });
|
|
1516
|
+
} else {
|
|
1517
|
+
process.stderr.write(`${chalk.yellow(`${pendingToolWarning}\n`)}`);
|
|
1518
|
+
}
|
|
1519
|
+
}
|
|
1520
|
+
}
|
|
1521
|
+
|
|
1522
|
+
await pluginPreloadPromise;
|
|
1523
|
+
if (deps === DEFAULT_RUN_ROOT_DEPENDENCIES) {
|
|
1524
|
+
await logger.time("registerDaemonProjectPresence", registerDaemonProjectPresence, cwd);
|
|
1525
|
+
}
|
|
1526
|
+
|
|
1527
|
+
scheduleMarketplaceAutoUpdate({
|
|
1528
|
+
autoUpdate: settingsInstance.get("marketplace.autoUpdate"),
|
|
1529
|
+
resolveActiveProjectRegistryPath,
|
|
1530
|
+
clearPluginRootsCache: clearPluginRootsAndCaches,
|
|
1531
|
+
});
|
|
1532
|
+
|
|
1533
|
+
const sessionOptions = await logger.time(
|
|
1534
|
+
"buildSessionOptions",
|
|
1535
|
+
buildSessionOptions,
|
|
1536
|
+
parsedArgs,
|
|
1537
|
+
scopedModels,
|
|
1538
|
+
sessionManager,
|
|
1539
|
+
modelRegistry,
|
|
1540
|
+
settingsInstance,
|
|
1541
|
+
);
|
|
1542
|
+
sessionOptions.authStorage = authStorage;
|
|
1543
|
+
sessionOptions.modelRegistry = modelRegistry;
|
|
1544
|
+
sessionOptions.hasUI = isInteractive || mode === "rpc-ui";
|
|
1545
|
+
sessionOptions.settings = settingsInstance;
|
|
1546
|
+
|
|
1547
|
+
// OTEL: register global OTLP exporters when an endpoint is configured via
|
|
1548
|
+
// env, then switch on the agent loop's telemetry hooks so traces, run-level
|
|
1549
|
+
// metrics, and structured logs have source events to export. Content capture
|
|
1550
|
+
// remains governed by OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT.
|
|
1551
|
+
await logger.time("initTelemetryExport", initTelemetryExport);
|
|
1552
|
+
if (isTelemetryExportEnabled()) {
|
|
1553
|
+
sessionOptions.telemetry = createTelemetryExportConfig(sessionOptions.telemetry);
|
|
1554
|
+
}
|
|
1555
|
+
|
|
1556
|
+
// Handle CLI --api-key as runtime override (not persisted)
|
|
1557
|
+
if (parsedArgs.apiKey) {
|
|
1558
|
+
if (!sessionOptions.model && !sessionOptions.modelPattern) {
|
|
1559
|
+
process.stderr.write(
|
|
1560
|
+
`${chalk.red("--api-key requires a model to be specified via --model, --provider/--model, or --models")}\n`,
|
|
1561
|
+
);
|
|
1562
|
+
process.exit(1);
|
|
1563
|
+
}
|
|
1564
|
+
if (sessionOptions.model) {
|
|
1565
|
+
authStorage.setRuntimeApiKey(sessionOptions.model.provider, parsedArgs.apiKey);
|
|
1566
|
+
}
|
|
1567
|
+
}
|
|
1568
|
+
|
|
1569
|
+
const createAgentSessionImpl = deps.createAgentSession ?? createAgentSession;
|
|
1570
|
+
const createSession = async (options: CreateAgentSessionOptions): Promise<CreateAgentSessionResult> => {
|
|
1571
|
+
const result = await logger.time("createAgentSession", createAgentSessionImpl, options);
|
|
1572
|
+
// Kick off background model discovery only after createAgentSession finishes its parallel
|
|
1573
|
+
// discovery arms; running these concurrently contends for the event loop and stretches
|
|
1574
|
+
// every parallel arm by ~30ms.
|
|
1575
|
+
modelRegistry.refreshInBackground();
|
|
1576
|
+
return result;
|
|
1577
|
+
};
|
|
1578
|
+
|
|
1579
|
+
if (mode === "acp") {
|
|
1580
|
+
const createAcpSession = createAcpSessionFactory({
|
|
1581
|
+
baseOptions: sessionOptions,
|
|
1582
|
+
settings: settingsInstance,
|
|
1583
|
+
sessionDir: parsedArgs.sessionDir,
|
|
1584
|
+
authStorage,
|
|
1585
|
+
modelRegistry,
|
|
1586
|
+
parsedArgs,
|
|
1587
|
+
rawArgs,
|
|
1588
|
+
createSession,
|
|
1589
|
+
});
|
|
1590
|
+
// Branch-only protocol runner: keep ACP server code out of normal interactive startup.
|
|
1591
|
+
const runAcpMode = deps.runAcpMode ?? (await import("./modes/acp/acp-mode")).runAcpMode;
|
|
1592
|
+
stopStartupWatchdog();
|
|
1593
|
+
await runAcpMode(createAcpSession);
|
|
1594
|
+
} else {
|
|
1595
|
+
// Resolve extension-registered CLI flags before creating the session so a
|
|
1596
|
+
// bad `@file` fails fast WITHOUT leaving a junk session/breadcrumb
|
|
1597
|
+
// (createAgentSession writes the terminal breadcrumb eagerly). Loading the
|
|
1598
|
+
// extensions here also makes `@file` classification extension-aware — e.g. a
|
|
1599
|
+
// string-flag value such as `--target @notes.md` is the flag's value, not a
|
|
1600
|
+
// file — and the same result is handed to createAgentSession via
|
|
1601
|
+
// `preloadedExtensions` so the discovery work is not repeated.
|
|
1602
|
+
if (isInteractive && !parsedArgs.trustedExtensions?.length) {
|
|
1603
|
+
sessionOptions.extensions = [...(sessionOptions.extensions ?? []), createWarpEventBridgeExtension()];
|
|
1604
|
+
}
|
|
1605
|
+
|
|
1606
|
+
const eventBus = new EventBus();
|
|
1607
|
+
const extensionsResult = parsedArgs.trustedExtensions?.length
|
|
1608
|
+
? await loadTrustedSessionExtensions(sessionOptions, cwd, eventBus)
|
|
1609
|
+
: await loadSessionExtensions(sessionOptions, cwd, settingsInstance, eventBus);
|
|
1610
|
+
const extensionFlagSink: ExtensionFlagSink = {
|
|
1611
|
+
getFlags: () => ExtensionRunner.aggregateFlags(extensionsResult.extensions),
|
|
1612
|
+
setFlagValue: (name, value) => {
|
|
1613
|
+
extensionsResult.runtime.flagValues.set(name, value);
|
|
1614
|
+
},
|
|
1615
|
+
};
|
|
1616
|
+
const initialArgs = applyExtensionFlags(extensionFlagSink, rawArgs) ?? parsedArgs;
|
|
1617
|
+
normalizeContinueSessionArgs(initialArgs, rawArgs);
|
|
1618
|
+
if ((parsedArgs.trustedExtensions?.length ?? 0) > 0 && extensionsResult.errors.length > 0) {
|
|
1619
|
+
throw new Error(
|
|
1620
|
+
`Trusted extension failed to load: ${extensionsResult.errors.map(item => item.error).join("; ")}`,
|
|
1621
|
+
);
|
|
1622
|
+
}
|
|
1623
|
+
for (const message of formatExtensionLoadNotifications(extensionsResult.errors)) {
|
|
1624
|
+
if (isInteractive) {
|
|
1625
|
+
notifs.push({ kind: "warn", message });
|
|
1626
|
+
} else {
|
|
1627
|
+
process.stderr.write(`${chalk.yellow(`${message}\n`)}`);
|
|
1628
|
+
}
|
|
1629
|
+
}
|
|
1630
|
+
// Fail fast on stale/typo flags (e.g. `omp --list-models`) now that we
|
|
1631
|
+
// know the real extension flag set. Without this check the unrecognized
|
|
1632
|
+
// token gets silently consumed and any following positional leaks as the
|
|
1633
|
+
// initial prompt — kicking off a real LLM session, MCP connection, and
|
|
1634
|
+
// tool calls (issue #2459). Exit code 2 matches the conventional
|
|
1635
|
+
// "command line usage error" convention.
|
|
1636
|
+
if (reportUnrecognizedFlags(initialArgs)) {
|
|
1637
|
+
process.exit(2);
|
|
1638
|
+
}
|
|
1639
|
+
const processedFiles =
|
|
1640
|
+
initialArgs.fileArgs.length > 0
|
|
1641
|
+
? await logger.time("processFileArguments", () =>
|
|
1642
|
+
processFileArguments(initialArgs.fileArgs, {
|
|
1643
|
+
autoResizeImages: settingsInstance.get("images.autoResize"),
|
|
1644
|
+
}),
|
|
1645
|
+
)
|
|
1646
|
+
: undefined;
|
|
1647
|
+
const { initialMessage, initialImages } = buildInitialMessage({
|
|
1648
|
+
parsed: initialArgs,
|
|
1649
|
+
fileText: processedFiles?.text,
|
|
1650
|
+
fileImages: processedFiles?.images,
|
|
1651
|
+
stdinContent: pipedInput,
|
|
1652
|
+
});
|
|
1653
|
+
|
|
1654
|
+
const showStartupSplash = shouldShowStartupSplash({
|
|
1655
|
+
configured: settingsInstance.get("startup.showSplash"),
|
|
1656
|
+
isInteractive,
|
|
1657
|
+
resuming: Boolean(parsedArgs.continue || parsedArgs.resume || parsedArgs.fork || foreignSource),
|
|
1658
|
+
quiet: settingsInstance.get("startup.quiet"),
|
|
1659
|
+
timing: Boolean($env.PI_TIMING),
|
|
1660
|
+
stdinIsTTY: process.stdin.isTTY,
|
|
1661
|
+
stdoutIsTTY: process.stdout.isTTY,
|
|
1662
|
+
});
|
|
1663
|
+
|
|
1664
|
+
// Startup changelog is only consumed by interactive mode below; kick the
|
|
1665
|
+
// CHANGELOG.md parse off now so it overlaps session creation instead of
|
|
1666
|
+
// serializing after it.
|
|
1667
|
+
const startupChangelogPromise = isInteractive
|
|
1668
|
+
? logger.time(
|
|
1669
|
+
"main:getChangelogForDisplay",
|
|
1670
|
+
getChangelogForDisplay,
|
|
1671
|
+
parsedArgs,
|
|
1672
|
+
settingsInstance.get("startup.changelogMode"),
|
|
1673
|
+
)
|
|
1674
|
+
: undefined;
|
|
1675
|
+
|
|
1676
|
+
const { session, setToolUIContext, modelFallbackMessage, lspServers, mcpManager } = await createSession({
|
|
1677
|
+
...sessionOptions,
|
|
1678
|
+
eventBus,
|
|
1679
|
+
preloadedExtensions: extensionsResult,
|
|
1680
|
+
});
|
|
1681
|
+
|
|
1682
|
+
// Cold-revive support: a `parked` subagent ref restored from disk (Agent Hub
|
|
1683
|
+
// scan, collab mirror, resumed process) has a sessionFile but no in-memory
|
|
1684
|
+
// reviver, so `ensureLive` (IRC sends, hub focus) would refuse it. Install a
|
|
1685
|
+
// factory — bound to THIS top-level session — that rebuilds the subagent from
|
|
1686
|
+
// its persisted JSONL (see persisted-revive.ts). Scoped to the non-ACP
|
|
1687
|
+
// bootstrap: ACP keeps several concurrent top-level sessions and a single
|
|
1688
|
+
// process-global factory must not be clobbered by the most recent one.
|
|
1689
|
+
AgentLifecycleManager.global().setPersistedSubagentReviverFactory(
|
|
1690
|
+
createPersistedSubagentReviverFactory({
|
|
1691
|
+
session,
|
|
1692
|
+
authStorage,
|
|
1693
|
+
modelRegistry,
|
|
1694
|
+
settings: settingsInstance,
|
|
1695
|
+
enableLsp: sessionOptions.enableLsp ?? true,
|
|
1696
|
+
eventBus,
|
|
1697
|
+
}),
|
|
1698
|
+
Math.trunc(Number(settingsInstance.get("task.agentIdleTtlMs") ?? 420_000) || 0),
|
|
1699
|
+
);
|
|
1700
|
+
if (parsedArgs.apiKey && !sessionOptions.model && session.model) {
|
|
1701
|
+
authStorage.setRuntimeApiKey(session.model.provider, parsedArgs.apiKey);
|
|
1702
|
+
}
|
|
1703
|
+
|
|
1704
|
+
if (modelFallbackMessage) {
|
|
1705
|
+
notifs.push({ kind: "warn", message: modelFallbackMessage });
|
|
1706
|
+
}
|
|
1707
|
+
|
|
1708
|
+
const modelRegistryError = modelRegistry.getError();
|
|
1709
|
+
if (modelRegistryError) {
|
|
1710
|
+
notifs.push({ kind: "error", message: modelRegistryError.message });
|
|
1711
|
+
}
|
|
1712
|
+
|
|
1713
|
+
if (!isInteractive && !session.model) {
|
|
1714
|
+
if (modelRegistryError) {
|
|
1715
|
+
process.stderr.write(`${chalk.red(modelRegistryError.message)}\n\n`);
|
|
1716
|
+
}
|
|
1717
|
+
if (modelFallbackMessage) {
|
|
1718
|
+
process.stderr.write(`${chalk.red(modelFallbackMessage)}\n`);
|
|
1719
|
+
} else {
|
|
1720
|
+
process.stderr.write(`${chalk.red("No models available.")}\n`);
|
|
1721
|
+
}
|
|
1722
|
+
process.stderr.write(`${chalk.yellow("\nSet an API key environment variable:")}\n`);
|
|
1723
|
+
process.stderr.write(" ANTHROPIC_API_KEY, OPENAI_API_KEY, GEMINI_API_KEY, etc.\n");
|
|
1724
|
+
process.stderr.write(`${chalk.yellow(`\nOr create ${ModelsConfigFile.path()}`)}\n`);
|
|
1725
|
+
process.exit(1);
|
|
1726
|
+
}
|
|
1727
|
+
|
|
1728
|
+
if (mode === "rpc" || mode === "rpc-ui") {
|
|
1729
|
+
// Branch-only protocol runner: keep RPC host code out of normal interactive startup.
|
|
1730
|
+
const runRpcMode: RunRpcMode = (await import("./modes/rpc/rpc-mode")).runRpcMode;
|
|
1731
|
+
stopStartupWatchdog();
|
|
1732
|
+
await runRpcMode(session, mode === "rpc-ui" ? setToolUIContext : undefined, eventBus, rpcInput);
|
|
1733
|
+
} else if (isInteractive) {
|
|
1734
|
+
const versionCheckPromise = checkForNewVersion(VERSION).catch(() => undefined);
|
|
1735
|
+
const startupChangelog = await startupChangelogPromise;
|
|
1736
|
+
|
|
1737
|
+
const modelScopeNotification = buildModelScopeNotification(
|
|
1738
|
+
scopedModels,
|
|
1739
|
+
settingsInstance.get("startup.quiet"),
|
|
1740
|
+
);
|
|
1741
|
+
if (modelScopeNotification) {
|
|
1742
|
+
// Routed through the TUI (not stdout): the startup capture owns the
|
|
1743
|
+
// terminal in raw mode here, and the TUI's first clearScrollback paint
|
|
1744
|
+
// would wipe a pre-TUI line anyway.
|
|
1745
|
+
notifs.push(modelScopeNotification);
|
|
1746
|
+
}
|
|
1747
|
+
|
|
1748
|
+
if ($env.PI_TIMING) {
|
|
1749
|
+
logger.printTimings();
|
|
1750
|
+
if (logger.shouldExitAfterTimings()) {
|
|
1751
|
+
process.exit(0);
|
|
1752
|
+
}
|
|
1753
|
+
}
|
|
1754
|
+
|
|
1755
|
+
stopStartupWatchdog();
|
|
1756
|
+
logger.endTiming();
|
|
1757
|
+
await runInteractiveMode(
|
|
1758
|
+
session,
|
|
1759
|
+
VERSION,
|
|
1760
|
+
startupChangelog,
|
|
1761
|
+
notifs,
|
|
1762
|
+
versionCheckPromise,
|
|
1763
|
+
initialArgs.messages,
|
|
1764
|
+
setToolUIContext,
|
|
1765
|
+
lspServers,
|
|
1766
|
+
mcpManager,
|
|
1767
|
+
Boolean(parsedArgs.continue || parsedArgs.resume || parsedArgs.fork || foreignSource),
|
|
1768
|
+
deps.forceSetupWizard === true,
|
|
1769
|
+
showStartupSplash,
|
|
1770
|
+
eventBus,
|
|
1771
|
+
initialMessage,
|
|
1772
|
+
initialImages,
|
|
1773
|
+
parsedArgs.join,
|
|
1774
|
+
);
|
|
1775
|
+
} else {
|
|
1776
|
+
// Branch-only single-shot runner: keep print-mode code out of normal interactive startup.
|
|
1777
|
+
stopStartupWatchdog();
|
|
1778
|
+
const runPrintMode: RunPrintMode = (await import("./modes/print-mode")).runPrintMode;
|
|
1779
|
+
await runPrintMode(session, {
|
|
1780
|
+
mode,
|
|
1781
|
+
messages: initialArgs.messages,
|
|
1782
|
+
initialMessage,
|
|
1783
|
+
initialImages,
|
|
1784
|
+
printThoughts: initialArgs.printThoughts,
|
|
1785
|
+
});
|
|
1786
|
+
if ($env.PI_TIMING) {
|
|
1787
|
+
logger.printTimings();
|
|
1788
|
+
}
|
|
1789
|
+
await session.dispose();
|
|
1790
|
+
stopThemeWatcher();
|
|
1791
|
+
await postmortem.quit(0);
|
|
1792
|
+
}
|
|
1793
|
+
}
|
|
1794
|
+
}
|
|
1795
|
+
|
|
1796
|
+
export async function main(args: string[]): Promise<void> {
|
|
1797
|
+
const { runCli } = await import("./cli");
|
|
1798
|
+
await runCli(args.length === 0 ? ["launch"] : args);
|
|
1799
|
+
}
|