@oh-my-pi/pi-coding-agent 17.2.4 → 17.2.5
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 +51 -0
- package/dist/{CHANGELOG-bpmhv26t.md → CHANGELOG-q2w43aw3.md} +51 -0
- package/dist/cli.js +4148 -3717
- package/dist/{template-8vdv6xb4.js → template-c2hyaytt.js} +8 -26
- package/dist/types/cli/args.d.ts +4 -1
- package/dist/types/cli/browser-relay-cli.d.ts +15 -0
- package/dist/types/cli/command-help.d.ts +99 -0
- package/dist/types/cli/help-extra.d.ts +2 -0
- package/dist/types/cli/thinking-levels.d.ts +5 -0
- package/dist/types/cli/update-cli.d.ts +13 -0
- package/dist/types/commands/browser-relay.d.ts +38 -0
- package/dist/types/commands/commit.d.ts +3 -0
- package/dist/types/commands/complete.d.ts +1 -1
- package/dist/types/commands/completions.d.ts +6 -0
- package/dist/types/commands/grep.d.ts +3 -0
- package/dist/types/commands/join.d.ts +4 -0
- package/dist/types/commands/launch-help.d.ts +171 -0
- package/dist/types/commands/launch.d.ts +5 -1
- package/dist/types/commands/models.d.ts +3 -0
- package/dist/types/commands/say.d.ts +10 -0
- package/dist/types/commands/worktree.d.ts +3 -0
- package/dist/types/config/keybindings.d.ts +5 -0
- package/dist/types/config/model-discovery.d.ts +2 -2
- package/dist/types/config/models-config-schema-bundle.d.ts +3 -0
- package/dist/types/config/models-config-schema.d.ts +2 -0
- package/dist/types/config/models-config.d.ts +1 -0
- package/dist/types/config/service-tier.d.ts +2 -0
- package/dist/types/config/settings-schema.d.ts +69 -21
- package/dist/types/cursor-bridge-tools.d.ts +1 -1
- package/dist/types/cursor.d.ts +7 -4
- package/dist/types/edit/index.d.ts +3 -3
- package/dist/types/edit/modes/replace.d.ts +22 -15
- package/dist/types/edit/renderer.d.ts +1 -1
- package/dist/types/eval/py/kernel.d.ts +3 -1
- package/dist/types/eval/py/spawn-options.d.ts +12 -16
- package/dist/types/extensibility/legacy-pi-ai-shim.d.ts +8 -1
- package/dist/types/extensibility/legacy-pi-coding-agent-shim.d.ts +1 -1
- package/dist/types/extensibility/plugins/legacy-pi-compat.d.ts +2 -0
- package/dist/types/launch/broker.d.ts +1 -1
- package/dist/types/launch/client.d.ts +6 -3
- package/dist/types/launch/ensure.d.ts +8 -0
- package/dist/types/launch/paths.d.ts +1 -1
- package/dist/types/launch/protocol.d.ts +2 -2
- package/dist/types/lsp/client.d.ts +2 -0
- package/dist/types/lsp/mux/daemon.d.ts +15 -0
- package/dist/types/lsp/mux/protocol.d.ts +57 -0
- package/dist/types/lsp/mux/server.d.ts +18 -0
- package/dist/types/lsp/types.d.ts +22 -2
- package/dist/types/main.d.ts +2 -0
- package/dist/types/mnemopi/embed-client.d.ts +1 -1
- package/dist/types/mnemopi/state.d.ts +0 -23
- package/dist/types/modes/components/assistant-message.d.ts +2 -0
- package/dist/types/modes/components/custom-editor.d.ts +2 -1
- package/dist/types/modes/components/read-tool-group.d.ts +2 -0
- package/dist/types/modes/components/stripped-tool-calls-placeholder.d.ts +12 -0
- package/dist/types/modes/components/tool-execution.d.ts +2 -0
- package/dist/types/modes/controllers/input-controller.d.ts +1 -0
- package/dist/types/modes/interactive-mode.d.ts +1 -0
- package/dist/types/modes/types.d.ts +1 -0
- package/dist/types/modes/workflow.d.ts +2 -1
- package/dist/types/sdk.d.ts +3 -1
- package/dist/types/secrets/index.d.ts +1 -1
- package/dist/types/session/agent-session-types.d.ts +3 -1
- package/dist/types/session/indexed-session-storage.d.ts +1 -0
- package/dist/types/session/session-advisors.d.ts +1 -1
- package/dist/types/session/session-context.d.ts +2 -1
- package/dist/types/session/session-maintenance.d.ts +1 -0
- package/dist/types/session/session-manager.d.ts +16 -11
- package/dist/types/session/session-stats.d.ts +10 -0
- package/dist/types/session/session-storage.d.ts +15 -3
- package/dist/types/system-prompt.d.ts +4 -1
- package/dist/types/task/index.d.ts +2 -1
- package/dist/types/task/spawn-policy.d.ts +5 -0
- package/dist/types/thinking.d.ts +1 -7
- package/dist/types/tools/ast-grep.d.ts +1 -1
- package/dist/types/tools/browser/registry.d.ts +2 -1
- package/dist/types/tools/browser/relay/bridge.d.ts +35 -0
- package/dist/types/tools/browser/relay/daemon.d.ts +16 -0
- package/dist/types/tools/browser/relay/kind.d.ts +19 -0
- package/dist/types/tools/browser/relay/protocol.d.ts +97 -0
- package/dist/types/tools/browser/relay/server.d.ts +35 -0
- package/dist/types/tools/browser/render.d.ts +1 -0
- package/dist/types/tools/browser.d.ts +3 -0
- package/dist/types/tools/computer/exposure.d.ts +9 -7
- package/dist/types/tools/computer/protocol.d.ts +70 -17
- package/dist/types/tools/computer/supervisor.d.ts +23 -10
- package/dist/types/tools/computer/worker-entry.d.ts +1 -0
- package/dist/types/tools/computer/worker.d.ts +42 -7
- package/dist/types/tools/computer-renderer.d.ts +7 -5
- package/dist/types/tools/computer.d.ts +25 -44
- package/dist/types/tools/context.d.ts +3 -0
- package/dist/types/tools/glob.d.ts +1 -1
- package/dist/types/tools/grep.d.ts +1 -1
- package/dist/types/tools/render-utils.d.ts +2 -0
- package/dist/types/tools/{browser/run-cancellation.d.ts → run-scope.d.ts} +8 -8
- package/dist/types/tools/tool-timeouts.d.ts +5 -0
- package/dist/types/tools/xdev.d.ts +8 -0
- package/dist/types/utils/clipboard.d.ts +2 -2
- package/dist/types/web/kagi.d.ts +1 -0
- package/dist/types/web/search/index.d.ts +1 -1
- package/dist/types/web/search/providers/anthropic.d.ts +1 -0
- package/dist/types/web/search/providers/base.d.ts +2 -0
- package/dist/types/web/search/providers/brave.d.ts +1 -0
- package/dist/types/web/search/providers/browser-page.d.ts +1 -0
- package/dist/types/web/search/providers/codex.d.ts +1 -0
- package/dist/types/web/search/providers/exa.d.ts +1 -0
- package/dist/types/web/search/providers/firecrawl.d.ts +1 -0
- package/dist/types/web/search/providers/gemini.d.ts +1 -0
- package/dist/types/web/search/providers/jina.d.ts +1 -0
- package/dist/types/web/search/providers/kagi.d.ts +1 -0
- package/dist/types/web/search/providers/kimi.d.ts +1 -0
- package/dist/types/web/search/providers/parallel.d.ts +1 -0
- package/dist/types/web/search/providers/perplexity.d.ts +1 -0
- package/dist/types/web/search/providers/searxng.d.ts +1 -0
- package/dist/types/web/search/providers/tavily.d.ts +1 -0
- package/dist/types/web/search/providers/tinyfish.d.ts +1 -0
- package/dist/types/web/search/providers/utils.d.ts +6 -9
- package/dist/types/web/search/providers/zai.d.ts +1 -0
- package/dist/types/web/search/types.d.ts +4 -0
- package/package.json +12 -12
- package/src/cli/args.ts +7 -87
- package/src/cli/browser-relay-cli.ts +119 -0
- package/src/cli/command-help.ts +103 -0
- package/src/cli/completion-gen.ts +5 -5
- package/src/cli/flag-tables.ts +9 -0
- package/src/cli/help-extra.ts +89 -0
- package/src/cli/setup-cli.ts +13 -21
- package/src/cli/thinking-levels.ts +7 -0
- package/src/cli/update-cli.ts +26 -7
- package/src/cli-commands.ts +170 -33
- package/src/cli.ts +17 -5
- package/src/commands/acp.ts +3 -1
- package/src/commands/agents.ts +3 -2
- package/src/commands/auth-broker.ts +3 -2
- package/src/commands/auth-gateway.ts +3 -2
- package/src/commands/bench.ts +2 -3
- package/src/commands/browser-relay.ts +53 -0
- package/src/commands/cleanse.ts +2 -2
- package/src/commands/commit.ts +3 -2
- package/src/commands/complete.ts +2 -1
- package/src/commands/completions.ts +3 -2
- package/src/commands/config.ts +3 -2
- package/src/commands/dry-balance.ts +2 -2
- package/src/commands/gallery.ts +3 -2
- package/src/commands/gc.ts +3 -2
- package/src/commands/grep.ts +3 -2
- package/src/commands/grievances.ts +3 -2
- package/src/commands/install.ts +2 -2
- package/src/commands/join.ts +3 -2
- package/src/commands/launch-help.ts +116 -0
- package/src/commands/launch.ts +7 -191
- package/src/commands/models.ts +3 -2
- package/src/commands/plugin.ts +3 -2
- package/src/commands/read.ts +3 -2
- package/src/commands/say.ts +3 -2
- package/src/commands/setup.ts +3 -2
- package/src/commands/shell.ts +3 -2
- package/src/commands/ssh.ts +3 -2
- package/src/commands/stats.ts +3 -2
- package/src/commands/tiny-models.ts +2 -2
- package/src/commands/token.ts +2 -2
- package/src/commands/ttsr.ts +2 -2
- package/src/commands/update.ts +3 -2
- package/src/commands/usage.ts +3 -2
- package/src/commands/web-search.ts +3 -2
- package/src/commands/worktree.ts +3 -2
- package/src/config/keybindings.ts +5 -0
- package/src/config/model-discovery.ts +30 -13
- package/src/config/model-registry.ts +9 -5
- package/src/config/models-config-schema-bundle.ts +9 -0
- package/src/config/resolve-config-value.ts +2 -1
- package/src/config/service-tier.ts +5 -0
- package/src/config/settings-schema.ts +72 -20
- package/src/cursor-bridge-tools.ts +1 -1
- package/src/cursor.ts +10 -14
- package/src/edit/diff.ts +17 -8
- package/src/edit/index.ts +20 -7
- package/src/edit/modes/replace.ts +93 -40
- package/src/edit/renderer.ts +1 -1
- package/src/edit/streaming.ts +14 -17
- package/src/eval/py/kernel.ts +2 -1
- package/src/eval/py/spawn-options.ts +24 -29
- package/src/export/html/template.js +8 -26
- package/src/extensibility/extensions/wrapper.ts +1 -0
- package/src/extensibility/legacy-pi-ai-shim.ts +22 -1
- package/src/extensibility/legacy-pi-coding-agent-shim.ts +7 -6
- package/src/extensibility/plugins/legacy-pi-compat.ts +124 -57
- package/src/extensibility/skills.ts +11 -0
- package/src/extensibility/utils.ts +10 -2
- package/src/launch/broker.ts +1 -1
- package/src/launch/client.ts +32 -13
- package/src/launch/ensure.ts +73 -0
- package/src/launch/paths.ts +1 -1
- package/src/launch/protocol.ts +2 -2
- package/src/lsp/client.ts +23 -2
- package/src/lsp/index.ts +8 -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/types.ts +28 -2
- package/src/main.ts +7 -2
- package/src/mcp/oauth-flow.ts +11 -1
- package/src/mnemopi/embed-client.ts +49 -2
- package/src/mnemopi/state.ts +57 -23
- package/src/modes/components/assistant-message.ts +11 -0
- package/src/modes/components/chat-transcript-builder.ts +4 -0
- package/src/modes/components/custom-editor.ts +9 -0
- package/src/modes/components/read-tool-group.ts +10 -0
- package/src/modes/components/status-line/component.ts +1 -1
- package/src/modes/components/stripped-tool-calls-placeholder.ts +35 -0
- package/src/modes/components/tool-execution.ts +8 -0
- package/src/modes/components/tree-selector.ts +46 -48
- package/src/modes/controllers/event-controller.ts +17 -0
- package/src/modes/controllers/input-controller.ts +39 -1
- package/src/modes/controllers/mcp-command-controller.ts +11 -5
- package/src/modes/controllers/selector-controller.ts +20 -0
- package/src/modes/interactive-mode.ts +2 -0
- package/src/modes/types.ts +1 -0
- package/src/modes/utils/hotkeys-markdown.ts +1 -0
- package/src/modes/utils/interactive-context-helpers.ts +1 -0
- package/src/modes/utils/ui-helpers.ts +6 -10
- package/src/modes/workflow.ts +8 -2
- package/src/prompts/agents/init.md +1 -1
- package/src/prompts/system/plan-mode-active.md +2 -2
- package/src/prompts/system/system-prompt.md +26 -52
- package/src/prompts/system/workflow-notice.md +3 -3
- package/src/prompts/tools/ast-grep.md +1 -1
- package/src/prompts/tools/bash.md +1 -1
- package/src/prompts/tools/browser.md +1 -0
- package/src/prompts/tools/computer.md +21 -21
- package/src/prompts/tools/glob.md +1 -1
- package/src/prompts/tools/grep.md +1 -1
- package/src/prompts/tools/replace.md +5 -4
- package/src/prompts/tools/task.md +4 -4
- package/src/sdk.ts +34 -6
- package/src/secrets/index.ts +1 -1
- package/src/session/agent-session-types.ts +3 -1
- package/src/session/agent-session.ts +13 -1
- package/src/session/indexed-session-storage.ts +9 -0
- package/src/session/prewalk.ts +24 -2
- package/src/session/session-advisors.ts +2 -2
- package/src/session/session-context.ts +16 -12
- package/src/session/session-dump-format.ts +1 -1
- package/src/session/session-maintenance.ts +38 -4
- package/src/session/session-manager.ts +102 -67
- package/src/session/session-paths.ts +118 -55
- package/src/session/session-stats.ts +48 -3
- package/src/session/session-storage.ts +30 -22
- package/src/session/stream-guards.ts +1 -1
- package/src/slash-commands/builtin-registry.ts +27 -24
- package/src/system-prompt.ts +8 -3
- package/src/task/index.ts +23 -8
- package/src/task/spawn-policy.ts +14 -0
- package/src/thinking.ts +2 -8
- package/src/tools/ast-grep.ts +10 -4
- package/src/tools/browser/cmux/cmux-tab.ts +5 -10
- package/src/tools/browser/cmux/rpc.ts +2 -8
- package/src/tools/browser/registry.ts +53 -2
- 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 +4 -1
- package/src/tools/browser/shared-daemon.ts +7 -58
- package/src/tools/browser/tab-supervisor.ts +5 -4
- package/src/tools/browser/tab-worker.ts +33 -12
- package/src/tools/browser.ts +26 -1
- package/src/tools/computer/exposure.ts +11 -35
- package/src/tools/computer/protocol.ts +51 -10
- package/src/tools/computer/supervisor.ts +227 -124
- package/src/tools/computer/worker-entry.ts +11 -6
- package/src/tools/computer/worker.ts +695 -81
- package/src/tools/computer-renderer.ts +104 -65
- package/src/tools/computer.ts +134 -428
- package/src/tools/context.ts +3 -0
- package/src/tools/glob.ts +9 -2
- package/src/tools/grep.ts +12 -6
- package/src/tools/inspect-image.ts +32 -6
- package/src/tools/render-utils.ts +2 -0
- package/src/tools/{browser/run-cancellation.ts → run-scope.ts} +11 -11
- package/src/tools/tool-timeouts.ts +1 -0
- package/src/tools/xdev.ts +29 -2
- package/src/utils/clipboard.ts +40 -14
- package/src/utils/command-args.ts +26 -28
- package/src/utils/tool-choice.ts +0 -13
- package/src/web/kagi.ts +2 -1
- package/src/web/search/index.ts +18 -2
- package/src/web/search/providers/anthropic.ts +4 -1
- package/src/web/search/providers/base.ts +2 -0
- package/src/web/search/providers/brave.ts +3 -1
- package/src/web/search/providers/browser-page.ts +6 -4
- package/src/web/search/providers/codex.ts +4 -1
- package/src/web/search/providers/duckduckgo.ts +2 -1
- package/src/web/search/providers/ecosia.ts +2 -1
- package/src/web/search/providers/exa.ts +4 -2
- package/src/web/search/providers/firecrawl.ts +3 -1
- package/src/web/search/providers/gemini.ts +8 -2
- package/src/web/search/providers/google.ts +2 -1
- package/src/web/search/providers/jina.ts +12 -2
- package/src/web/search/providers/kagi.ts +3 -0
- package/src/web/search/providers/kimi.ts +5 -1
- package/src/web/search/providers/mojeek.ts +2 -1
- package/src/web/search/providers/parallel.ts +5 -1
- package/src/web/search/providers/perplexity.ts +6 -3
- package/src/web/search/providers/public.ts +1 -1
- package/src/web/search/providers/searxng.ts +11 -5
- package/src/web/search/providers/startpage.ts +10 -4
- package/src/web/search/providers/synthetic.ts +11 -5
- package/src/web/search/providers/tavily.ts +3 -1
- package/src/web/search/providers/tinyfish.ts +3 -1
- package/src/web/search/providers/utils.ts +12 -10
- package/src/web/search/providers/xai.ts +2 -2
- package/src/web/search/providers/zai.ts +18 -3
- package/src/web/search/types.ts +6 -0
package/src/commands/usage.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Show provider usage limits for every authenticated account.
|
|
3
3
|
*/
|
|
4
|
+
|
|
4
5
|
import { Args, Command, Flags } from "@oh-my-pi/pi-utils/cli";
|
|
6
|
+
import { usageHelp as commandHelp } from "../cli/command-help";
|
|
5
7
|
import { runUsageCommand } from "../cli/usage-cli";
|
|
6
8
|
|
|
7
9
|
export default class Usage extends Command {
|
|
8
|
-
static description =
|
|
9
|
-
|
|
10
|
+
static description = commandHelp.description;
|
|
10
11
|
static args = {
|
|
11
12
|
action: Args.string({
|
|
12
13
|
description: "Optional subcommand to execute",
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Test web search providers.
|
|
3
3
|
*/
|
|
4
|
+
|
|
4
5
|
import { Args, Command, Flags } from "@oh-my-pi/pi-utils/cli";
|
|
6
|
+
import { searchHelp as commandHelp } from "../cli/command-help";
|
|
5
7
|
import { runSearchCommand, type SearchCommandArgs } from "../cli/web-search-cli";
|
|
6
8
|
import { SEARCH_PROVIDER_ORDER } from "../web/search/provider";
|
|
7
9
|
|
|
@@ -10,8 +12,7 @@ const PROVIDERS: Array<string> = ["auto", ...SEARCH_PROVIDER_ORDER];
|
|
|
10
12
|
const RECENCY: NonNullable<SearchCommandArgs["recency"]>[] = ["day", "week", "month", "year"];
|
|
11
13
|
|
|
12
14
|
export default class Search extends Command {
|
|
13
|
-
static description =
|
|
14
|
-
|
|
15
|
+
static description = commandHelp.description;
|
|
15
16
|
static aliases = ["q"];
|
|
16
17
|
|
|
17
18
|
static args = {
|
package/src/commands/worktree.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* List and clean up agent-managed git worktrees under `~/.omp/wt`.
|
|
3
3
|
*/
|
|
4
|
+
|
|
4
5
|
import { getProjectDir } from "@oh-my-pi/pi-utils";
|
|
5
6
|
import { Args, Command, Flags } from "@oh-my-pi/pi-utils/cli";
|
|
7
|
+
import { worktreeHelp as commandHelp } from "../cli/command-help";
|
|
6
8
|
import { clearWorktrees, listWorktrees } from "../cli/worktree-cli";
|
|
7
9
|
import { Settings } from "../config/settings";
|
|
8
10
|
|
|
9
11
|
export default class Worktree extends Command {
|
|
10
|
-
static description =
|
|
11
|
-
|
|
12
|
+
static description = commandHelp.description;
|
|
12
13
|
static aliases = ["wt"];
|
|
13
14
|
|
|
14
15
|
static args = {
|
|
@@ -29,6 +29,7 @@ interface AppKeybindings {
|
|
|
29
29
|
"app.model.select": true;
|
|
30
30
|
"app.model.selectTemporary": true;
|
|
31
31
|
"app.tools.expand": true;
|
|
32
|
+
"app.tools.toggleVisibility": true;
|
|
32
33
|
"app.editor.external": true;
|
|
33
34
|
"app.message.followUp": true;
|
|
34
35
|
"app.retry": true;
|
|
@@ -124,6 +125,10 @@ export const KEYBINDINGS = {
|
|
|
124
125
|
defaultKeys: "ctrl+o",
|
|
125
126
|
description: "Expand tools",
|
|
126
127
|
},
|
|
128
|
+
"app.tools.toggleVisibility": {
|
|
129
|
+
defaultKeys: "ctrl+shift+o",
|
|
130
|
+
description: "Show or hide tool activity",
|
|
131
|
+
},
|
|
127
132
|
"app.editor.external": {
|
|
128
133
|
defaultKeys: "ctrl+g",
|
|
129
134
|
description: "Open external editor",
|
|
@@ -76,7 +76,10 @@ const REMOTE_DISCOVERY_TIMEOUT_MS = 10_000;
|
|
|
76
76
|
* empty (issue #7087). Anything that is not strictly loopback therefore gets
|
|
77
77
|
* {@link REMOTE_DISCOVERY_TIMEOUT_MS}.
|
|
78
78
|
*/
|
|
79
|
-
export function discoveryProbeTimeoutMs(baseUrl: string, loopbackMs: number): number {
|
|
79
|
+
export function discoveryProbeTimeoutMs(baseUrl: string, loopbackMs: number, customTimeoutMs?: number): number {
|
|
80
|
+
if (typeof customTimeoutMs === "number" && customTimeoutMs > 0 && Number.isFinite(customTimeoutMs)) {
|
|
81
|
+
return customTimeoutMs;
|
|
82
|
+
}
|
|
80
83
|
let hostname: string;
|
|
81
84
|
try {
|
|
82
85
|
hostname = new URL(baseUrl).hostname;
|
|
@@ -415,10 +418,11 @@ async function discoverOllamaModelMetadata(
|
|
|
415
418
|
endpoint: string,
|
|
416
419
|
modelId: string,
|
|
417
420
|
headers: Record<string, string> | undefined,
|
|
421
|
+
customTimeoutMs?: number,
|
|
418
422
|
): Promise<OllamaDiscoveredModelMetadata | null> {
|
|
419
423
|
const showUrl = `${endpoint}/api/show`;
|
|
420
424
|
try {
|
|
421
|
-
const payload = await withTimeoutSignal(discoveryProbeTimeoutMs(endpoint, 150), async signal => {
|
|
425
|
+
const payload = await withTimeoutSignal(discoveryProbeTimeoutMs(endpoint, 150, customTimeoutMs), async signal => {
|
|
422
426
|
const response = await ctx.fetch(showUrl, {
|
|
423
427
|
method: "POST",
|
|
424
428
|
headers: { ...(headers ?? {}), "Content-Type": "application/json" },
|
|
@@ -471,7 +475,8 @@ export async function discoverOllamaModels(
|
|
|
471
475
|
const endpoint = normalizeOllamaBaseUrl(providerConfig.baseUrl);
|
|
472
476
|
const tagsUrl = `${endpoint}/api/tags`;
|
|
473
477
|
const headers = { ...(providerConfig.headers ?? {}) };
|
|
474
|
-
const
|
|
478
|
+
const customTimeoutMs = providerConfig.discovery.timeoutMs;
|
|
479
|
+
const payload = await withTimeoutSignal(discoveryProbeTimeoutMs(endpoint, 250, customTimeoutMs), async signal => {
|
|
475
480
|
const response = await ctx.fetch(tagsUrl, {
|
|
476
481
|
headers,
|
|
477
482
|
signal,
|
|
@@ -488,7 +493,11 @@ export async function discoverOllamaModels(
|
|
|
488
493
|
const metadataById = new Map(
|
|
489
494
|
await Promise.all(
|
|
490
495
|
entries.map(
|
|
491
|
-
async entry =>
|
|
496
|
+
async entry =>
|
|
497
|
+
[
|
|
498
|
+
entry.id,
|
|
499
|
+
await discoverOllamaModelMetadata(ctx, endpoint, entry.id, headers, customTimeoutMs),
|
|
500
|
+
] as const,
|
|
492
501
|
),
|
|
493
502
|
),
|
|
494
503
|
);
|
|
@@ -515,10 +524,11 @@ async function discoverLlamaCppServerMetadata(
|
|
|
515
524
|
ctx: DiscoveryContext,
|
|
516
525
|
baseUrl: string,
|
|
517
526
|
headers: Record<string, string> | undefined,
|
|
527
|
+
customTimeoutMs?: number,
|
|
518
528
|
): Promise<LlamaCppDiscoveredServerMetadata | null> {
|
|
519
529
|
const propsUrl = `${toLlamaCppNativeBaseUrl(baseUrl)}/props`;
|
|
520
530
|
try {
|
|
521
|
-
const payload = await withTimeoutSignal(discoveryProbeTimeoutMs(baseUrl, 150), async signal => {
|
|
531
|
+
const payload = await withTimeoutSignal(discoveryProbeTimeoutMs(baseUrl, 150, customTimeoutMs), async signal => {
|
|
522
532
|
const response = await ctx.fetch(propsUrl, {
|
|
523
533
|
headers,
|
|
524
534
|
signal,
|
|
@@ -592,9 +602,10 @@ export async function discoverLlamaCppModels(
|
|
|
592
602
|
|
|
593
603
|
const baseHeaders: Record<string, string> = { ...(providerConfig.headers ?? {}) };
|
|
594
604
|
let headers = baseHeaders;
|
|
605
|
+
const customTimeoutMs = providerConfig.discovery.timeoutMs;
|
|
595
606
|
const attempt = async (h: Record<string, string>) => {
|
|
596
607
|
const [payload, metadata] = await Promise.all([
|
|
597
|
-
withTimeoutSignal(discoveryProbeTimeoutMs(baseUrl, 250), async signal => {
|
|
608
|
+
withTimeoutSignal(discoveryProbeTimeoutMs(baseUrl, 250, customTimeoutMs), async signal => {
|
|
598
609
|
const response = await ctx.fetch(modelsUrl, {
|
|
599
610
|
headers: h,
|
|
600
611
|
signal,
|
|
@@ -605,7 +616,7 @@ export async function discoverLlamaCppModels(
|
|
|
605
616
|
headers = h;
|
|
606
617
|
return (await response.json()) as unknown;
|
|
607
618
|
}),
|
|
608
|
-
discoverLlamaCppServerMetadata(ctx, baseUrl, h),
|
|
619
|
+
discoverLlamaCppServerMetadata(ctx, baseUrl, h, customTimeoutMs),
|
|
609
620
|
]);
|
|
610
621
|
return [payload, metadata] as const;
|
|
611
622
|
};
|
|
@@ -657,6 +668,7 @@ export async function discoverLlamaCppModels(
|
|
|
657
668
|
export async function discoverLlamaCppModelRuntimeMetadata(
|
|
658
669
|
model: Pick<Model<Api>, "provider" | "id" | "baseUrl" | "headers">,
|
|
659
670
|
ctx: DiscoveryContext,
|
|
671
|
+
customTimeoutMs?: number,
|
|
660
672
|
): Promise<LlamaCppDiscoveredModelRuntimeMetadata | undefined> {
|
|
661
673
|
const baseUrl = normalizeLlamaCppBaseUrl(model.baseUrl);
|
|
662
674
|
// Probe the native `/models` endpoint (not the OpenAI-compatible `/v1/models`)
|
|
@@ -668,7 +680,7 @@ export async function discoverLlamaCppModelRuntimeMetadata(
|
|
|
668
680
|
const baseHeaders: Record<string, string> = { ...(model.headers ?? {}) };
|
|
669
681
|
const attempt = async (headers: Record<string, string>) => {
|
|
670
682
|
const [entries, serverMetadata] = await Promise.all([
|
|
671
|
-
withTimeoutSignal(discoveryProbeTimeoutMs(nativeBaseUrl, 250), async signal => {
|
|
683
|
+
withTimeoutSignal(discoveryProbeTimeoutMs(nativeBaseUrl, 250, customTimeoutMs), async signal => {
|
|
672
684
|
const response = await ctx.fetch(modelsUrl, {
|
|
673
685
|
headers,
|
|
674
686
|
signal,
|
|
@@ -678,7 +690,7 @@ export async function discoverLlamaCppModelRuntimeMetadata(
|
|
|
678
690
|
}
|
|
679
691
|
return parseLlamaCppModelList(await response.json());
|
|
680
692
|
}),
|
|
681
|
-
discoverLlamaCppServerMetadata(ctx, nativeBaseUrl, headers),
|
|
693
|
+
discoverLlamaCppServerMetadata(ctx, nativeBaseUrl, headers, customTimeoutMs),
|
|
682
694
|
]);
|
|
683
695
|
if (!entries) {
|
|
684
696
|
return undefined;
|
|
@@ -721,13 +733,16 @@ export async function discoverOpenAIModelsList(
|
|
|
721
733
|
|
|
722
734
|
const baseHeaders: Record<string, string> = { ...(providerConfig.headers ?? {}) };
|
|
723
735
|
let headers = baseHeaders;
|
|
736
|
+
const timeoutMs = providerConfig.discovery.timeoutMs ?? 10_000;
|
|
724
737
|
const attempt = async (h: Record<string, string>) => {
|
|
725
738
|
const nativeMetadataPromise =
|
|
726
739
|
providerConfig.discovery.type === "lm-studio"
|
|
727
|
-
?
|
|
740
|
+
? withTimeoutSignal(timeoutMs, signal =>
|
|
741
|
+
fetchLmStudioNativeModelMetadata(baseUrl, ctx.fetch, { headers: h, signal }),
|
|
742
|
+
)
|
|
728
743
|
: Promise.resolve(null);
|
|
729
744
|
const [payload, nativeMetadata] = await Promise.all([
|
|
730
|
-
withTimeoutSignal(
|
|
745
|
+
withTimeoutSignal(timeoutMs, async signal => {
|
|
731
746
|
const res = await ctx.fetch(modelsUrl, {
|
|
732
747
|
headers: h,
|
|
733
748
|
signal,
|
|
@@ -819,6 +834,7 @@ export async function discoverLiteLLMModels(
|
|
|
819
834
|
const resolveReference = (id: string) => resolveModelReference(id, references) as ModelSpec<Api> | undefined;
|
|
820
835
|
const baseHeaders: Record<string, string> = { ...(providerConfig.headers ?? {}) };
|
|
821
836
|
let headers = baseHeaders;
|
|
837
|
+
const timeoutMs = providerConfig.discovery.timeoutMs ?? 10_000;
|
|
822
838
|
const attempt = async (h: Record<string, string>) => {
|
|
823
839
|
headers = h;
|
|
824
840
|
let authError: (Error & { status: number }) | undefined;
|
|
@@ -830,7 +846,7 @@ export async function discoverLiteLLMModels(
|
|
|
830
846
|
}
|
|
831
847
|
return response;
|
|
832
848
|
};
|
|
833
|
-
const models = await withTimeoutSignal(
|
|
849
|
+
const models = await withTimeoutSignal(timeoutMs, signal =>
|
|
834
850
|
fetchLiteLLMRichModels({
|
|
835
851
|
api: providerConfig.api,
|
|
836
852
|
provider: providerConfig.provider,
|
|
@@ -889,8 +905,9 @@ export async function discoverProxyModels(
|
|
|
889
905
|
|
|
890
906
|
const baseHeaders: Record<string, string> = { ...(providerConfig.headers ?? {}) };
|
|
891
907
|
let headers = baseHeaders;
|
|
908
|
+
const timeoutMs = providerConfig.discovery.timeoutMs ?? 10_000;
|
|
892
909
|
const attempt = async (h: Record<string, string>) =>
|
|
893
|
-
withTimeoutSignal(
|
|
910
|
+
withTimeoutSignal(timeoutMs, async signal => {
|
|
894
911
|
const res = await ctx.fetch(modelsUrl, {
|
|
895
912
|
headers: h,
|
|
896
913
|
signal,
|
|
@@ -73,7 +73,7 @@ import {
|
|
|
73
73
|
inheritReferenceThinking,
|
|
74
74
|
resolveModelReference,
|
|
75
75
|
} from "@oh-my-pi/pi-catalog/identity";
|
|
76
|
-
import { isBunTestRuntime, isRecord, logger, wrapFetchForExtraCa } from "@oh-my-pi/pi-utils";
|
|
76
|
+
import { $envExact, isBunTestRuntime, isRecord, logger, wrapFetchForExtraCa } from "@oh-my-pi/pi-utils";
|
|
77
77
|
import { parseModelString, resolveProviderModelReference } from "../config/model-resolver";
|
|
78
78
|
import { generateCodexAttestation } from "../live/attestation";
|
|
79
79
|
import type { AuthStorage, OAuthCredential } from "../session/auth-storage";
|
|
@@ -329,7 +329,7 @@ interface CommandApiKeyResolution {
|
|
|
329
329
|
*/
|
|
330
330
|
function resolveConfigValue(valueConfig: string): string | undefined {
|
|
331
331
|
if (valueConfig.startsWith("!")) return resolveCommandConfig(valueConfig.slice(1).trim());
|
|
332
|
-
const envValue =
|
|
332
|
+
const envValue = $envExact(valueConfig);
|
|
333
333
|
if (envValue) return envValue;
|
|
334
334
|
return valueConfig;
|
|
335
335
|
}
|
|
@@ -972,14 +972,18 @@ export class ModelRegistry {
|
|
|
972
972
|
* Refresh dynamic metadata that can appear only after a local model loads.
|
|
973
973
|
*/
|
|
974
974
|
async refreshSelectedModelMetadata(model: Model<Api>): Promise<Model<Api>> {
|
|
975
|
-
const
|
|
975
|
+
const llamaCppDiscoveryConfig = this.#discoverableProviders.find(
|
|
976
976
|
providerConfig => providerConfig.provider === model.provider && providerConfig.discovery.type === "llama.cpp",
|
|
977
977
|
);
|
|
978
|
-
if (!
|
|
978
|
+
if (!llamaCppDiscoveryConfig) {
|
|
979
979
|
return model;
|
|
980
980
|
}
|
|
981
981
|
this.#ensureFullSnapshot();
|
|
982
|
-
const runtimeMetadata = await discoverLlamaCppModelRuntimeMetadata(
|
|
982
|
+
const runtimeMetadata = await discoverLlamaCppModelRuntimeMetadata(
|
|
983
|
+
model,
|
|
984
|
+
this.#nonResolvingDiscoveryContext(),
|
|
985
|
+
llamaCppDiscoveryConfig.discovery.timeoutMs,
|
|
986
|
+
);
|
|
983
987
|
if (runtimeMetadata === undefined) {
|
|
984
988
|
return this.find(model.provider, model.id) ?? model;
|
|
985
989
|
}
|
|
@@ -262,6 +262,15 @@ export const getModelsConfigSchemaBundle = once(() => {
|
|
|
262
262
|
|
|
263
263
|
const ProviderDiscoverySchema = type({
|
|
264
264
|
type: '"ollama" | "llama.cpp" | "lm-studio" | "openai-models-list" | "proxy" | "litellm"',
|
|
265
|
+
"timeoutMs?": "number",
|
|
266
|
+
}).narrow((value, ctx) => {
|
|
267
|
+
if (
|
|
268
|
+
value.timeoutMs !== undefined &&
|
|
269
|
+
(typeof value.timeoutMs !== "number" || value.timeoutMs <= 0 || !Number.isFinite(value.timeoutMs))
|
|
270
|
+
) {
|
|
271
|
+
return ctx.mustBe("timeoutMs a positive finite number");
|
|
272
|
+
}
|
|
273
|
+
return true;
|
|
265
274
|
});
|
|
266
275
|
|
|
267
276
|
const ProviderAuthSchema = type('"apiKey" | "none" | "oauth"');
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { executeShell } from "@oh-my-pi/pi-natives";
|
|
8
|
+
import { $envExact } from "@oh-my-pi/pi-utils";
|
|
8
9
|
|
|
9
10
|
/** Cache for successful shell command results (persists for process lifetime). */
|
|
10
11
|
const commandResultCache = new Map<string, string>();
|
|
@@ -21,7 +22,7 @@ export async function resolveConfigValue(config: string): Promise<string | undef
|
|
|
21
22
|
if (config.startsWith("!")) {
|
|
22
23
|
return await executeCommand(config);
|
|
23
24
|
}
|
|
24
|
-
const envValue =
|
|
25
|
+
const envValue = $envExact(config);
|
|
25
26
|
return envValue || config;
|
|
26
27
|
}
|
|
27
28
|
|
|
@@ -16,6 +16,11 @@ export type ServiceTierOpenAISettingValue = (typeof SERVICE_TIER_OPENAI_VALUES)[
|
|
|
16
16
|
export type ServiceTierAnthropicSettingValue = (typeof SERVICE_TIER_ANTHROPIC_VALUES)[number];
|
|
17
17
|
export type ServiceTierGoogleSettingValue = (typeof SERVICE_TIER_GOOGLE_VALUES)[number];
|
|
18
18
|
|
|
19
|
+
/** Whether a runtime value is a supported OpenAI service-tier setting. */
|
|
20
|
+
export function isServiceTierOpenAISettingValue(value: string): value is ServiceTierOpenAISettingValue {
|
|
21
|
+
return SERVICE_TIER_OPENAI_VALUES.some(tier => tier === value);
|
|
22
|
+
}
|
|
23
|
+
|
|
19
24
|
/** Whether a runtime value names a provider family with an independent service-tier knob. */
|
|
20
25
|
export function isServiceTierFamily(value: unknown): value is ServiceTierFamily {
|
|
21
26
|
return value === "openai" || value === "anthropic" || value === "google";
|
|
@@ -37,7 +37,12 @@ import {
|
|
|
37
37
|
TTS_LOCAL_VOICE_VALUES,
|
|
38
38
|
} from "../tts/models";
|
|
39
39
|
import { EDIT_MODES } from "../utils/edit-mode";
|
|
40
|
-
import {
|
|
40
|
+
import {
|
|
41
|
+
DEFAULT_WEB_SEARCH_TIMEOUT_SECONDS,
|
|
42
|
+
MAX_WEB_SEARCH_TIMEOUT_SECONDS,
|
|
43
|
+
SEARCH_PROVIDER_CHOICES,
|
|
44
|
+
type SearchProviderId,
|
|
45
|
+
} from "../web/search/types";
|
|
41
46
|
import {
|
|
42
47
|
SERVICE_TIER_ANTHROPIC_OPTIONS,
|
|
43
48
|
SERVICE_TIER_ANTHROPIC_VALUES,
|
|
@@ -1013,6 +1018,17 @@ export const SETTINGS_SCHEMA = {
|
|
|
1013
1018
|
},
|
|
1014
1019
|
},
|
|
1015
1020
|
|
|
1021
|
+
"display.hideToolActivity": {
|
|
1022
|
+
type: "boolean",
|
|
1023
|
+
default: false,
|
|
1024
|
+
ui: {
|
|
1025
|
+
tab: "appearance",
|
|
1026
|
+
group: "Display",
|
|
1027
|
+
label: "Hide Tool Activity",
|
|
1028
|
+
description: "Hide model-initiated tool calls and results from the transcript",
|
|
1029
|
+
},
|
|
1030
|
+
},
|
|
1031
|
+
|
|
1016
1032
|
"display.showTokenUsage": {
|
|
1017
1033
|
type: "boolean",
|
|
1018
1034
|
default: false,
|
|
@@ -3382,6 +3398,18 @@ export const SETTINGS_SCHEMA = {
|
|
|
3382
3398
|
},
|
|
3383
3399
|
},
|
|
3384
3400
|
|
|
3401
|
+
"lsp.shared": {
|
|
3402
|
+
type: "boolean",
|
|
3403
|
+
default: true,
|
|
3404
|
+
ui: {
|
|
3405
|
+
tab: "files",
|
|
3406
|
+
group: "LSP",
|
|
3407
|
+
label: "Shared Language Servers",
|
|
3408
|
+
description:
|
|
3409
|
+
"Share one language server per project across omp instances via the daemon broker (falls back to private servers when unavailable)",
|
|
3410
|
+
},
|
|
3411
|
+
},
|
|
3412
|
+
|
|
3385
3413
|
"lsp.formatOnWrite": {
|
|
3386
3414
|
type: "boolean",
|
|
3387
3415
|
default: false,
|
|
@@ -3897,23 +3925,7 @@ export const SETTINGS_SCHEMA = {
|
|
|
3897
3925
|
tab: "tools",
|
|
3898
3926
|
group: "Available Tools",
|
|
3899
3927
|
label: "Computer",
|
|
3900
|
-
description: "Enable
|
|
3901
|
-
},
|
|
3902
|
-
},
|
|
3903
|
-
|
|
3904
|
-
"computer.backend": {
|
|
3905
|
-
type: "enum",
|
|
3906
|
-
values: ["auto", "native"] as const,
|
|
3907
|
-
default: "auto",
|
|
3908
|
-
ui: {
|
|
3909
|
-
tab: "tools",
|
|
3910
|
-
group: "Computer",
|
|
3911
|
-
label: "Computer Backend",
|
|
3912
|
-
description: "Select automatic or explicit platform-native desktop capture and input",
|
|
3913
|
-
options: [
|
|
3914
|
-
{ value: "auto", label: "Auto" },
|
|
3915
|
-
{ value: "native", label: "Native" },
|
|
3916
|
-
],
|
|
3928
|
+
description: "Enable the scriptable host-desktop control tool (screenshots, input, accessibility)",
|
|
3917
3929
|
},
|
|
3918
3930
|
},
|
|
3919
3931
|
|
|
@@ -3930,7 +3942,7 @@ export const SETTINGS_SCHEMA = {
|
|
|
3930
3942
|
|
|
3931
3943
|
"computer.maxWidth": {
|
|
3932
3944
|
type: "number",
|
|
3933
|
-
default:
|
|
3945
|
+
default: 3840,
|
|
3934
3946
|
ui: {
|
|
3935
3947
|
tab: "tools",
|
|
3936
3948
|
group: "Computer",
|
|
@@ -3941,7 +3953,7 @@ export const SETTINGS_SCHEMA = {
|
|
|
3941
3953
|
|
|
3942
3954
|
"computer.maxHeight": {
|
|
3943
3955
|
type: "number",
|
|
3944
|
-
default:
|
|
3956
|
+
default: 2400,
|
|
3945
3957
|
ui: {
|
|
3946
3958
|
tab: "tools",
|
|
3947
3959
|
group: "Computer",
|
|
@@ -4108,6 +4120,29 @@ export const SETTINGS_SCHEMA = {
|
|
|
4108
4120
|
},
|
|
4109
4121
|
},
|
|
4110
4122
|
|
|
4123
|
+
"browser.relay": {
|
|
4124
|
+
type: "boolean",
|
|
4125
|
+
default: false,
|
|
4126
|
+
ui: {
|
|
4127
|
+
tab: "tools",
|
|
4128
|
+
group: "Grep & Browser",
|
|
4129
|
+
label: "Browser Relay",
|
|
4130
|
+
description:
|
|
4131
|
+
"Drive your own Chrome tabs through the omp browser relay. Install the extension once (`omp browser-relay install`); the relay server auto-starts when the browser tool needs it. Takes precedence over Browser CDP URL; set PI_BROWSER_RELAY=0 or PI_BROWSER_RELAY=1 to override.",
|
|
4132
|
+
},
|
|
4133
|
+
},
|
|
4134
|
+
|
|
4135
|
+
"browser.relayUrl": {
|
|
4136
|
+
type: "string",
|
|
4137
|
+
default: undefined,
|
|
4138
|
+
ui: {
|
|
4139
|
+
tab: "tools",
|
|
4140
|
+
group: "Grep & Browser",
|
|
4141
|
+
label: "Browser Relay URL",
|
|
4142
|
+
description: "omp browser relay endpoint (default http://127.0.0.1:9224).",
|
|
4143
|
+
},
|
|
4144
|
+
},
|
|
4145
|
+
|
|
4111
4146
|
"browser.headless": {
|
|
4112
4147
|
type: "boolean",
|
|
4113
4148
|
default: true,
|
|
@@ -4869,6 +4904,23 @@ export const SETTINGS_SCHEMA = {
|
|
|
4869
4904
|
options: SEARCH_PROVIDER_CHOICES,
|
|
4870
4905
|
},
|
|
4871
4906
|
},
|
|
4907
|
+
"providers.webSearchTimeoutSeconds": {
|
|
4908
|
+
type: "number",
|
|
4909
|
+
default: DEFAULT_WEB_SEARCH_TIMEOUT_SECONDS,
|
|
4910
|
+
ui: {
|
|
4911
|
+
tab: "providers",
|
|
4912
|
+
group: "Services",
|
|
4913
|
+
label: "Web Search Timeout",
|
|
4914
|
+
description: `Hard timeout for each provider's search transport before web_search advances to the next fallback, in seconds (maximum ${MAX_WEB_SEARCH_TIMEOUT_SECONDS})`,
|
|
4915
|
+
options: [
|
|
4916
|
+
{ value: "30", label: "30 seconds" },
|
|
4917
|
+
{ value: "60", label: "1 minute" },
|
|
4918
|
+
{ value: "120", label: "2 minutes" },
|
|
4919
|
+
{ value: "180", label: "3 minutes" },
|
|
4920
|
+
{ value: "300", label: "5 minutes" },
|
|
4921
|
+
],
|
|
4922
|
+
},
|
|
4923
|
+
},
|
|
4872
4924
|
"providers.webSearchGeminiModel": {
|
|
4873
4925
|
type: "string",
|
|
4874
4926
|
default: undefined,
|
|
@@ -39,7 +39,7 @@ export function createBridgeGrepFactory(
|
|
|
39
39
|
/**
|
|
40
40
|
* Build the `replace`-mode `edit` the bridge answers `pi_edit` with.
|
|
41
41
|
*
|
|
42
|
-
* `PiEditExecArgs` carries `
|
|
42
|
+
* `PiEditExecArgs` carries `old_string`/`new_string` replacements, which is exactly
|
|
43
43
|
* `replace`'s schema and nothing else's. The session's own instance follows the
|
|
44
44
|
* configured `edit.mode` — `hashline` by default, whose schema is a single
|
|
45
45
|
* `input` string — so a frame handed that instance fails validation instead of
|
package/src/cursor.ts
CHANGED
|
@@ -69,7 +69,7 @@ interface CursorExecBridgeOptions {
|
|
|
69
69
|
*
|
|
70
70
|
* `PiEditExecArgs` is that mode's schema verbatim, and the session's own
|
|
71
71
|
* `edit` may be in any mode — `hashline` by default — whose schema rejects
|
|
72
|
-
* `
|
|
72
|
+
* `old_string`/`new_string` outright. {@link tools} therefore cannot be trusted
|
|
73
73
|
* for this one frame: a session that starts on another provider keeps its
|
|
74
74
|
* configured instance in the map (only Cursor sessions move `edit` out), and
|
|
75
75
|
* switching to Cursor later does not rebuild the roster.
|
|
@@ -641,25 +641,21 @@ export class CursorExecHandlers implements ICursorExecHandlers {
|
|
|
641
641
|
}
|
|
642
642
|
|
|
643
643
|
/**
|
|
644
|
-
* `PiEditExecArgs`
|
|
645
|
-
*
|
|
646
|
-
*
|
|
644
|
+
* `PiEditExecArgs` carries a path plus `oldText`/`newText` replacement
|
|
645
|
+
* pairs. A single replacement maps onto the model-facing single-edit
|
|
646
|
+
* `replace` schema verbatim; a multi-replacement frame still runs as ONE
|
|
647
|
+
* tool lifecycle (one start/end event pair, one aggregate diff), so it is
|
|
648
|
+
* sent in the tool's internal `edits` batch form (`ReplaceBatchParams`),
|
|
649
|
+
* which only this bridge produces.
|
|
647
650
|
*
|
|
648
651
|
* The replace-mode instance is requested explicitly rather than resolved
|
|
649
652
|
* from {@link CursorExecBridgeOptions.tools}: the registry's `edit` is in
|
|
650
653
|
* the session's configured mode, whose schema rejects these arguments.
|
|
651
654
|
*/
|
|
652
655
|
async piEdit(call: Parameters<NonNullable<ICursorExecHandlers["piEdit"]>>[0]) {
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
call.toolCallId,
|
|
657
|
-
{
|
|
658
|
-
path: call.args.path,
|
|
659
|
-
edits: call.args.edits.map(edit => ({ old_text: edit.oldText, new_text: edit.newText })),
|
|
660
|
-
},
|
|
661
|
-
this.options.getEditReplaceTool?.(),
|
|
662
|
-
);
|
|
656
|
+
const edits = call.args.edits.map(edit => ({ old_string: edit.oldText, new_string: edit.newText }));
|
|
657
|
+
const args = edits.length === 1 ? { path: call.args.path, ...edits[0] } : { path: call.args.path, edits };
|
|
658
|
+
return await executeTool(this.options, "edit", call.toolCallId, args, this.options.getEditReplaceTool?.());
|
|
663
659
|
}
|
|
664
660
|
|
|
665
661
|
async piWrite(call: Parameters<NonNullable<ICursorExecHandlers["piWrite"]>>[0]) {
|
package/src/edit/diff.ts
CHANGED
|
@@ -855,7 +855,6 @@ export function replaceText(content: string, oldText: string, newText: string, o
|
|
|
855
855
|
let normalizedContent = normalizeToLF(content);
|
|
856
856
|
const normalizedOldText = normalizeToLF(oldText);
|
|
857
857
|
const normalizedNewText = normalizeToLF(newText);
|
|
858
|
-
let count = 0;
|
|
859
858
|
|
|
860
859
|
if (options.all) {
|
|
861
860
|
// Check for exact matches first
|
|
@@ -867,11 +866,13 @@ export function replaceText(content: string, oldText: string, newText: string, o
|
|
|
867
866
|
};
|
|
868
867
|
}
|
|
869
868
|
|
|
870
|
-
//
|
|
869
|
+
// Match against the immutable source so inserted replacement text cannot become a later candidate.
|
|
870
|
+
const replacements: Array<{ startIndex: number; endIndex: number; text: string }> = [];
|
|
871
871
|
while (true) {
|
|
872
872
|
const matchOutcome = findMatch(normalizedContent, normalizedOldText, {
|
|
873
873
|
allowFuzzy: options.fuzzy,
|
|
874
874
|
threshold,
|
|
875
|
+
excludedRanges: replacements,
|
|
875
876
|
});
|
|
876
877
|
|
|
877
878
|
const shouldUseClosest =
|
|
@@ -888,14 +889,22 @@ export function replaceText(content: string, oldText: string, newText: string, o
|
|
|
888
889
|
if (adjustedNewText === match.actualText) {
|
|
889
890
|
break;
|
|
890
891
|
}
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
892
|
+
replacements.push({
|
|
893
|
+
startIndex: match.startIndex,
|
|
894
|
+
endIndex: match.startIndex + Math.max(match.actualText.length, 1),
|
|
895
|
+
text: adjustedNewText,
|
|
896
|
+
});
|
|
896
897
|
}
|
|
897
898
|
|
|
898
|
-
|
|
899
|
+
replacements.sort((a, b) => a.startIndex - b.startIndex);
|
|
900
|
+
const parts: string[] = [];
|
|
901
|
+
let sourceIndex = 0;
|
|
902
|
+
for (const replacement of replacements) {
|
|
903
|
+
parts.push(normalizedContent.substring(sourceIndex, replacement.startIndex), replacement.text);
|
|
904
|
+
sourceIndex = replacement.endIndex;
|
|
905
|
+
}
|
|
906
|
+
parts.push(normalizedContent.substring(sourceIndex));
|
|
907
|
+
return { content: parts.join(""), count: replacements.length };
|
|
899
908
|
}
|
|
900
909
|
|
|
901
910
|
// Single replacement mode
|
package/src/edit/index.ts
CHANGED
|
@@ -19,7 +19,7 @@ import { executeHashlineSingle, hashlineEditParamsSchema } from "./hashline";
|
|
|
19
19
|
import { type ApplyPatchParams, applyPatchSchema, expandApplyPatchToEntries } from "./modes/apply-patch";
|
|
20
20
|
import applyPatchGrammar from "./modes/apply-patch.lark" with { type: "text" };
|
|
21
21
|
import { executePatchSingle, type PatchEditEntry, type PatchParams, patchEditSchema } from "./modes/patch";
|
|
22
|
-
import {
|
|
22
|
+
import { executeReplace, type ReplaceBatchParams, type ReplaceParams, replaceEditSchema } from "./modes/replace";
|
|
23
23
|
import { type EditToolDetails, type EditToolPerFileResult, getLspBatchRequest, type LspBatchRequest } from "./renderer";
|
|
24
24
|
import { pruneOversizedEditSnapshots } from "./snapshot-details";
|
|
25
25
|
import { EDIT_MODE_STRATEGIES } from "./streaming";
|
|
@@ -46,7 +46,7 @@ type TInput =
|
|
|
46
46
|
|
|
47
47
|
type HashlineParams = typeof hashlineEditParamsSchema.infer;
|
|
48
48
|
|
|
49
|
-
type EditParams = ReplaceParams | PatchParams | HashlineParams | ApplyPatchParams;
|
|
49
|
+
type EditParams = ReplaceParams | ReplaceBatchParams | PatchParams | HashlineParams | ApplyPatchParams;
|
|
50
50
|
|
|
51
51
|
type EditModeDefinition = {
|
|
52
52
|
description: (session: ToolSession) => string;
|
|
@@ -402,7 +402,7 @@ export class EditTool implements AgentTool<TInput> {
|
|
|
402
402
|
/**
|
|
403
403
|
* `mode` pins the edit variant for this instance, for callers whose protocol
|
|
404
404
|
* fixes the shape of an edit. The Cursor `pi_edit` frame carries
|
|
405
|
-
* `
|
|
405
|
+
* `old_string`/`new_string` args, which only `replace` accepts — under the
|
|
406
406
|
* default `hashline` mode those args do not match the schema at all. Left
|
|
407
407
|
* unset, the env/settings resolution applies as before.
|
|
408
408
|
*/
|
|
@@ -662,11 +662,24 @@ export class EditTool implements AgentTool<TInput> {
|
|
|
662
662
|
batchRequest: LspBatchRequest | undefined,
|
|
663
663
|
onUpdate?: (partialResult: AgentToolResult<EditToolDetails, TInput>) => void,
|
|
664
664
|
) => {
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
665
|
+
// `edits` is the internal `ReplaceBatchParams` form only the Cursor
|
|
666
|
+
// exec bridge produces (multi-replacement `pi_edit` frames run as one
|
|
667
|
+
// lifecycle); model calls always arrive in the single-edit schema shape.
|
|
668
|
+
const replaceParams = params as ReplaceParams | ReplaceBatchParams;
|
|
669
|
+
const entries =
|
|
670
|
+
"edits" in replaceParams
|
|
671
|
+
? replaceParams.edits
|
|
672
|
+
: [
|
|
673
|
+
{
|
|
674
|
+
old_string: replaceParams.old_string,
|
|
675
|
+
new_string: replaceParams.new_string,
|
|
676
|
+
replace_all: replaceParams.replace_all,
|
|
677
|
+
},
|
|
678
|
+
];
|
|
679
|
+
const targetPath = await resolveEditPath(tool.session, replaceParams.path, { mustExist: true, signal });
|
|
680
|
+
const runs = entries.map(
|
|
668
681
|
entry => (br: LspBatchRequest | undefined) =>
|
|
669
|
-
|
|
682
|
+
executeReplace({
|
|
670
683
|
session: tool.session,
|
|
671
684
|
path: targetPath,
|
|
672
685
|
params: entry,
|