@oh-my-pi/pi-coding-agent 17.2.4 → 17.2.6
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 +69 -0
- package/dist/{CHANGELOG-bpmhv26t.md → CHANGELOG-gs76k6wc.md} +69 -0
- package/dist/cli.js +4438 -3962
- 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/gc-cli.d.ts +1 -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 +15 -4
- 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 +19 -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/btw-panel.d.ts +3 -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/btw-controller.d.ts +2 -0
- package/dist/types/modes/controllers/command-controller.d.ts +1 -0
- package/dist/types/modes/controllers/input-controller.d.ts +1 -0
- package/dist/types/modes/interactive-mode.d.ts +5 -1
- package/dist/types/modes/types.d.ts +4 -1
- 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/security/contracts/schemas.d.ts +405 -403
- package/dist/types/session/agent-session-types.d.ts +8 -1
- package/dist/types/session/agent-session.d.ts +26 -2
- package/dist/types/session/indexed-session-storage.d.ts +1 -0
- package/dist/types/session/launch-completion.d.ts +10 -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-entries.d.ts +15 -1
- package/dist/types/session/session-maintenance.d.ts +1 -0
- package/dist/types/session/session-manager.d.ts +23 -11
- package/dist/types/session/session-stats.d.ts +10 -0
- package/dist/types/session/session-storage.d.ts +15 -3
- package/dist/types/session/yield-queue.d.ts +6 -1
- 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/index.d.ts +9 -0
- 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/gc-cli.ts +641 -21
- 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 +44 -27
- package/src/config/model-registry.ts +19 -13
- 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/config/settings.ts +1 -1
- 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/index.ts +10 -3
- package/src/export/html/template.js +8 -26
- package/src/export/share.ts +4 -0
- 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 +223 -7
- package/src/launch/client.ts +192 -21
- package/src/launch/ensure.ts +73 -0
- package/src/launch/paths.ts +1 -1
- package/src/launch/protocol.ts +54 -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 +20 -8
- package/src/mcp/config-writer.ts +1 -1
- 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/btw-panel.ts +41 -4
- 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/btw-controller.ts +55 -7
- package/src/modes/controllers/command-controller.ts +31 -0
- package/src/modes/controllers/event-controller.ts +17 -0
- package/src/modes/controllers/input-controller.ts +63 -8
- 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 +18 -2
- package/src/modes/types.ts +9 -1
- 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/session/launch-completion.md +1 -0
- 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 +49 -6
- package/src/secrets/index.ts +1 -1
- package/src/security/contracts/schemas.ts +205 -183
- package/src/security/contracts/validation.ts +5 -1
- package/src/security/store.ts +2 -2
- package/src/session/agent-session-types.ts +9 -1
- package/src/session/agent-session.ts +204 -15
- package/src/session/indexed-session-storage.ts +9 -0
- package/src/session/launch-completion.ts +37 -0
- package/src/session/prewalk.ts +24 -2
- package/src/session/session-advisors.ts +2 -2
- package/src/session/session-context.ts +42 -12
- package/src/session/session-dump-format.ts +1 -1
- package/src/session/session-entries.ts +17 -1
- package/src/session/session-maintenance.ts +38 -4
- package/src/session/session-manager.ts +123 -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/session/yield-queue.ts +121 -16
- package/src/slash-commands/builtin-registry.ts +37 -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 +97 -14
- 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/hub/launch.ts +122 -6
- package/src/tools/index.ts +9 -0
- 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/dist/types/config/file-lock.d.ts +0 -29
- package/src/config/file-lock.ts +0 -164
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,
|
|
@@ -258,23 +258,41 @@ function formatPreviewWindow(lines: string[], centerIndex: number, options: Prev
|
|
|
258
258
|
.join("\n");
|
|
259
259
|
}
|
|
260
260
|
|
|
261
|
-
function findExactMatchOutcome(
|
|
262
|
-
|
|
263
|
-
|
|
261
|
+
function findExactMatchOutcome(
|
|
262
|
+
content: string,
|
|
263
|
+
target: string,
|
|
264
|
+
excludedRanges: readonly { startIndex: number; endIndex: number }[],
|
|
265
|
+
): MatchOutcome | undefined {
|
|
266
|
+
let firstIndex: number | undefined;
|
|
267
|
+
let occurrences = 0;
|
|
268
|
+
const recordedIndices: number[] = [];
|
|
269
|
+
let searchStart = 0;
|
|
270
|
+
|
|
271
|
+
while (searchStart <= content.length - target.length) {
|
|
272
|
+
const index = content.indexOf(target, searchStart);
|
|
273
|
+
if (index === -1) break;
|
|
274
|
+
|
|
275
|
+
const endIndex = index + target.length;
|
|
276
|
+
if (!excludedRanges.some(range => index < range.endIndex && endIndex > range.startIndex)) {
|
|
277
|
+
firstIndex ??= index;
|
|
278
|
+
occurrences++;
|
|
279
|
+
if (recordedIndices.length < MAX_RECORDED_MATCHES) {
|
|
280
|
+
recordedIndices.push(index);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
searchStart = endIndex;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
if (firstIndex === undefined) {
|
|
264
287
|
return undefined;
|
|
265
288
|
}
|
|
266
289
|
|
|
267
|
-
const occurrences = content.split(target).length - 1;
|
|
268
290
|
if (occurrences > 1) {
|
|
269
291
|
const contentLines = content.split("\n");
|
|
270
292
|
const occurrenceLines: number[] = [];
|
|
271
293
|
const occurrencePreviews: string[] = [];
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
for (let i = 0; i < MAX_RECORDED_MATCHES; i++) {
|
|
275
|
-
const idx = content.indexOf(target, searchStart);
|
|
276
|
-
if (idx === -1) break;
|
|
277
|
-
const lineNumber = content.slice(0, idx).split("\n").length;
|
|
294
|
+
for (const index of recordedIndices) {
|
|
295
|
+
const lineNumber = content.slice(0, index).split("\n").length;
|
|
278
296
|
occurrenceLines.push(lineNumber);
|
|
279
297
|
occurrencePreviews.push(
|
|
280
298
|
formatPreviewWindow(contentLines, lineNumber - 1, {
|
|
@@ -282,17 +300,16 @@ function findExactMatchOutcome(content: string, target: string): MatchOutcome |
|
|
|
282
300
|
maxLen: OCCURRENCE_PREVIEW_MAX_LEN,
|
|
283
301
|
}),
|
|
284
302
|
);
|
|
285
|
-
searchStart = idx + 1;
|
|
286
303
|
}
|
|
287
304
|
|
|
288
305
|
return { occurrences, occurrenceLines, occurrencePreviews };
|
|
289
306
|
}
|
|
290
307
|
|
|
291
|
-
const startLine = content.slice(0,
|
|
308
|
+
const startLine = content.slice(0, firstIndex).split("\n").length;
|
|
292
309
|
return {
|
|
293
310
|
match: {
|
|
294
311
|
actualText: target,
|
|
295
|
-
startIndex:
|
|
312
|
+
startIndex: firstIndex,
|
|
296
313
|
startLine,
|
|
297
314
|
confidence: 1,
|
|
298
315
|
},
|
|
@@ -408,6 +425,7 @@ function findBestFuzzyMatchCore(
|
|
|
408
425
|
offsets: number[],
|
|
409
426
|
threshold: number,
|
|
410
427
|
includeDepth: boolean,
|
|
428
|
+
excludedRanges: readonly { startIndex: number; endIndex: number }[],
|
|
411
429
|
): BestFuzzyMatchResult {
|
|
412
430
|
const targetNormalized = normalizeLines(targetLines, includeDepth);
|
|
413
431
|
|
|
@@ -417,6 +435,12 @@ function findBestFuzzyMatchCore(
|
|
|
417
435
|
let aboveThresholdCount = 0;
|
|
418
436
|
|
|
419
437
|
for (let start = 0; start <= contentLines.length - targetLines.length; start++) {
|
|
438
|
+
const startIndex = offsets[start];
|
|
439
|
+
const endLine = start + targetLines.length - 1;
|
|
440
|
+
const endIndex = Math.max(startIndex + 1, offsets[endLine] + contentLines[endLine].length);
|
|
441
|
+
if (excludedRanges.some(range => startIndex < range.endIndex && endIndex > range.startIndex)) {
|
|
442
|
+
continue;
|
|
443
|
+
}
|
|
420
444
|
const windowLines = contentLines.slice(start, start + targetLines.length);
|
|
421
445
|
const windowNormalized = normalizeLines(windowLines, includeDepth);
|
|
422
446
|
let score = 0;
|
|
@@ -434,7 +458,7 @@ function findBestFuzzyMatchCore(
|
|
|
434
458
|
bestScore = score;
|
|
435
459
|
best = {
|
|
436
460
|
actualText: windowLines.join("\n"),
|
|
437
|
-
startIndex
|
|
461
|
+
startIndex,
|
|
438
462
|
startLine: start + 1,
|
|
439
463
|
confidence: score,
|
|
440
464
|
};
|
|
@@ -446,7 +470,12 @@ function findBestFuzzyMatchCore(
|
|
|
446
470
|
return { best, aboveThresholdCount, secondBestScore };
|
|
447
471
|
}
|
|
448
472
|
|
|
449
|
-
function findBestFuzzyMatch(
|
|
473
|
+
function findBestFuzzyMatch(
|
|
474
|
+
content: string,
|
|
475
|
+
target: string,
|
|
476
|
+
threshold: number,
|
|
477
|
+
excludedRanges: readonly { startIndex: number; endIndex: number }[],
|
|
478
|
+
): BestFuzzyMatchResult {
|
|
450
479
|
const contentLines = content.split("\n");
|
|
451
480
|
const targetLines = target.split("\n");
|
|
452
481
|
|
|
@@ -458,11 +487,18 @@ function findBestFuzzyMatch(content: string, target: string, threshold: number):
|
|
|
458
487
|
}
|
|
459
488
|
|
|
460
489
|
const offsets = computeLineOffsets(contentLines);
|
|
461
|
-
let result = findBestFuzzyMatchCore(contentLines, targetLines, offsets, threshold, true);
|
|
490
|
+
let result = findBestFuzzyMatchCore(contentLines, targetLines, offsets, threshold, true, excludedRanges);
|
|
462
491
|
|
|
463
492
|
// Retry without indent depth if match is close but below threshold
|
|
464
493
|
if (result.best && result.best.confidence < threshold && result.best.confidence >= FALLBACK_THRESHOLD) {
|
|
465
|
-
const noDepthResult = findBestFuzzyMatchCore(
|
|
494
|
+
const noDepthResult = findBestFuzzyMatchCore(
|
|
495
|
+
contentLines,
|
|
496
|
+
targetLines,
|
|
497
|
+
offsets,
|
|
498
|
+
threshold,
|
|
499
|
+
false,
|
|
500
|
+
excludedRanges,
|
|
501
|
+
);
|
|
466
502
|
if (noDepthResult.best && noDepthResult.best.confidence > result.best.confidence) {
|
|
467
503
|
result = noDepthResult;
|
|
468
504
|
}
|
|
@@ -473,25 +509,35 @@ function findBestFuzzyMatch(content: string, target: string, threshold: number):
|
|
|
473
509
|
|
|
474
510
|
/**
|
|
475
511
|
* Find a match for target text within content.
|
|
476
|
-
* Used primarily for replace-mode edits.
|
|
512
|
+
* Used primarily for replace-mode edits; excluded ranges remain invisible to exact and fuzzy matching.
|
|
477
513
|
*/
|
|
478
514
|
export function findMatch(
|
|
479
515
|
content: string,
|
|
480
516
|
target: string,
|
|
481
|
-
options: {
|
|
517
|
+
options: {
|
|
518
|
+
allowFuzzy: boolean;
|
|
519
|
+
threshold?: number;
|
|
520
|
+
excludedRanges?: readonly { startIndex: number; endIndex: number }[];
|
|
521
|
+
},
|
|
482
522
|
): MatchOutcome {
|
|
483
523
|
if (target.length === 0) {
|
|
484
524
|
return {};
|
|
485
525
|
}
|
|
526
|
+
const excludedRanges = options.excludedRanges ?? [];
|
|
486
527
|
|
|
487
|
-
const exactMatch = findExactMatchOutcome(content, target);
|
|
528
|
+
const exactMatch = findExactMatchOutcome(content, target, excludedRanges);
|
|
488
529
|
if (exactMatch) {
|
|
489
530
|
return exactMatch;
|
|
490
531
|
}
|
|
491
532
|
|
|
492
533
|
// Try fuzzy match
|
|
493
534
|
const threshold = options.threshold ?? DEFAULT_FUZZY_THRESHOLD;
|
|
494
|
-
const { best, aboveThresholdCount, secondBestScore } = findBestFuzzyMatch(
|
|
535
|
+
const { best, aboveThresholdCount, secondBestScore } = findBestFuzzyMatch(
|
|
536
|
+
content,
|
|
537
|
+
target,
|
|
538
|
+
threshold,
|
|
539
|
+
excludedRanges,
|
|
540
|
+
);
|
|
495
541
|
|
|
496
542
|
if (!best) {
|
|
497
543
|
return {};
|
|
@@ -1012,24 +1058,31 @@ export function findContextLine(
|
|
|
1012
1058
|
return { index: undefined, confidence: bestScore };
|
|
1013
1059
|
}
|
|
1014
1060
|
|
|
1015
|
-
export const replaceEditEntrySchema = type({
|
|
1016
|
-
old_text: "string",
|
|
1017
|
-
new_text: "string",
|
|
1018
|
-
"all?": "boolean",
|
|
1019
|
-
});
|
|
1020
|
-
|
|
1021
1061
|
export const replaceEditSchema = type({
|
|
1022
1062
|
path: "string",
|
|
1023
|
-
|
|
1063
|
+
old_string: "string",
|
|
1064
|
+
new_string: "string",
|
|
1065
|
+
"replace_all?": "boolean",
|
|
1024
1066
|
});
|
|
1025
1067
|
|
|
1026
|
-
export type ReplaceEditEntry = typeof replaceEditEntrySchema.infer;
|
|
1027
1068
|
export type ReplaceParams = typeof replaceEditSchema.infer;
|
|
1028
1069
|
|
|
1029
|
-
|
|
1070
|
+
/**
|
|
1071
|
+
* Internal batch form of {@link ReplaceParams}, produced only by the Cursor
|
|
1072
|
+
* exec bridge: a `pi_edit` frame carries several replacements against one
|
|
1073
|
+
* path but must run as a single tool lifecycle with one aggregate result.
|
|
1074
|
+
* Never advertised to the model — the agent loop validates model calls
|
|
1075
|
+
* against {@link replaceEditSchema}, which has no `edits` field.
|
|
1076
|
+
*/
|
|
1077
|
+
export interface ReplaceBatchParams {
|
|
1078
|
+
path: string;
|
|
1079
|
+
edits: Omit<ReplaceParams, "path">[];
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
export interface ExecuteReplaceOptions {
|
|
1030
1083
|
session: ToolSession;
|
|
1031
1084
|
path: string;
|
|
1032
|
-
params:
|
|
1085
|
+
params: Omit<ReplaceParams, "path">;
|
|
1033
1086
|
signal?: AbortSignal;
|
|
1034
1087
|
batchRequest?: LspBatchRequest;
|
|
1035
1088
|
allowFuzzy: boolean;
|
|
@@ -1038,9 +1091,9 @@ export interface ExecuteReplaceSingleOptions {
|
|
|
1038
1091
|
beginDeferredDiagnosticsForPath: (path: string) => WritethroughDeferredHandle;
|
|
1039
1092
|
}
|
|
1040
1093
|
|
|
1041
|
-
export async function
|
|
1042
|
-
options:
|
|
1043
|
-
): Promise<AgentToolResult<EditToolDetails,
|
|
1094
|
+
export async function executeReplace(
|
|
1095
|
+
options: ExecuteReplaceOptions,
|
|
1096
|
+
): Promise<AgentToolResult<EditToolDetails, ReplaceParams>> {
|
|
1044
1097
|
const {
|
|
1045
1098
|
session,
|
|
1046
1099
|
path,
|
|
@@ -1052,12 +1105,12 @@ export async function executeReplaceSingle(
|
|
|
1052
1105
|
writethrough,
|
|
1053
1106
|
beginDeferredDiagnosticsForPath,
|
|
1054
1107
|
} = options;
|
|
1055
|
-
const {
|
|
1108
|
+
const { old_string, new_string, replace_all } = params;
|
|
1056
1109
|
|
|
1057
1110
|
enforcePlanModeWrite(session, path);
|
|
1058
1111
|
|
|
1059
|
-
if (
|
|
1060
|
-
throw new Error("
|
|
1112
|
+
if (old_string.length === 0) {
|
|
1113
|
+
throw new Error("old_string must not be empty.");
|
|
1061
1114
|
}
|
|
1062
1115
|
|
|
1063
1116
|
const absolutePath = resolvePlanPath(session, path);
|
|
@@ -1065,12 +1118,12 @@ export async function executeReplaceSingle(
|
|
|
1065
1118
|
const { bom, text: content } = stripBom(rawContent);
|
|
1066
1119
|
const originalEnding = detectLineEnding(content);
|
|
1067
1120
|
const normalizedContent = normalizeToLF(content);
|
|
1068
|
-
const normalizedOldText = normalizeToLF(
|
|
1069
|
-
const normalizedNewText = normalizeToLF(
|
|
1121
|
+
const normalizedOldText = normalizeToLF(old_string);
|
|
1122
|
+
const normalizedNewText = normalizeToLF(new_string);
|
|
1070
1123
|
|
|
1071
1124
|
const result = replaceText(normalizedContent, normalizedOldText, normalizedNewText, {
|
|
1072
1125
|
fuzzy: allowFuzzy,
|
|
1073
|
-
all:
|
|
1126
|
+
all: replace_all ?? false,
|
|
1074
1127
|
threshold: fuzzyThreshold,
|
|
1075
1128
|
});
|
|
1076
1129
|
|
package/src/edit/renderer.ts
CHANGED
package/src/edit/streaming.ts
CHANGED
|
@@ -30,7 +30,6 @@ import { computeEditDiff, type DiffError, type DiffResult } from "./diff";
|
|
|
30
30
|
import { computeHashlineDiff, computeHashlineSectionDiff } from "./hashline/diff";
|
|
31
31
|
import { type ApplyPatchEntry, expandApplyPatchToEntries, expandApplyPatchToPreviewEntries } from "./modes/apply-patch";
|
|
32
32
|
import { computePatchDiff, type PatchEditEntry } from "./modes/patch";
|
|
33
|
-
import type { ReplaceEditEntry } from "./modes/replace";
|
|
34
33
|
|
|
35
34
|
export interface PerFileDiffPreview {
|
|
36
35
|
path: string;
|
|
@@ -333,27 +332,32 @@ function splitApplyPatchPerFile(input: string): EditMatcherEntry[] {
|
|
|
333
332
|
|
|
334
333
|
interface ReplaceArgs {
|
|
335
334
|
path?: string;
|
|
336
|
-
|
|
335
|
+
old_string?: string;
|
|
336
|
+
new_string?: string;
|
|
337
|
+
replace_all?: boolean;
|
|
337
338
|
__partialJson?: string;
|
|
338
339
|
}
|
|
339
340
|
|
|
340
341
|
const replaceStrategy: EditStreamingStrategy<ReplaceArgs> = {
|
|
341
342
|
extractCompleteEdits(args, partialJson) {
|
|
342
|
-
|
|
343
|
-
|
|
343
|
+
// While args are still streaming, `old_string` is only trustworthy once
|
|
344
|
+
// the parser has moved past it — i.e. the `new_string` key has appeared.
|
|
345
|
+
// Previewing a half-streamed `old_string` would flash a bogus
|
|
346
|
+
// "no match" diff error until the rest of the value arrives.
|
|
347
|
+
if (!partialJson || partialJson.includes('"new_string"')) return args;
|
|
348
|
+
return { ...args, old_string: undefined, new_string: undefined };
|
|
344
349
|
},
|
|
345
350
|
async computeDiffPreview(args, ctx) {
|
|
346
351
|
if (!args.path) return null;
|
|
347
|
-
|
|
348
|
-
if (!first || first.old_text === undefined || first.new_text === undefined) return null;
|
|
352
|
+
if (args.old_string === undefined || args.new_string === undefined) return null;
|
|
349
353
|
ctx.signal.throwIfAborted();
|
|
350
354
|
const result = await computeEditDiff(
|
|
351
355
|
args.path,
|
|
352
|
-
|
|
353
|
-
|
|
356
|
+
args.old_string,
|
|
357
|
+
args.new_string,
|
|
354
358
|
ctx.cwd,
|
|
355
359
|
ctx.allowFuzzy ?? true,
|
|
356
|
-
|
|
360
|
+
args.replace_all,
|
|
357
361
|
ctx.fuzzyThreshold,
|
|
358
362
|
);
|
|
359
363
|
ctx.signal.throwIfAborted();
|
|
@@ -363,14 +367,7 @@ const replaceStrategy: EditStreamingStrategy<ReplaceArgs> = {
|
|
|
363
367
|
return "";
|
|
364
368
|
},
|
|
365
369
|
matcherDigest(args) {
|
|
366
|
-
|
|
367
|
-
if (!Array.isArray(edits)) return undefined;
|
|
368
|
-
let digest: string | undefined;
|
|
369
|
-
for (const edit of edits) {
|
|
370
|
-
if (typeof edit?.new_text !== "string") continue;
|
|
371
|
-
digest = digest === undefined ? edit.new_text : `${digest}\n${edit.new_text}`;
|
|
372
|
-
}
|
|
373
|
-
return digest;
|
|
370
|
+
return typeof args?.new_string === "string" ? args.new_string : undefined;
|
|
374
371
|
},
|
|
375
372
|
matcherPaths(args) {
|
|
376
373
|
return typeof args?.path === "string" && args.path.length > 0 ? [args.path] : undefined;
|
package/src/eval/py/kernel.ts
CHANGED
|
@@ -82,8 +82,9 @@ const availabilityCache = new Map<string, Promise<PythonKernelAvailability>>();
|
|
|
82
82
|
export async function checkPythonKernelAvailability(
|
|
83
83
|
cwd: string,
|
|
84
84
|
interpreter?: string,
|
|
85
|
+
options?: { forceProbe?: boolean },
|
|
85
86
|
): Promise<PythonKernelAvailability> {
|
|
86
|
-
if (isBunTestRuntime() || $flag("PI_PYTHON_SKIP_CHECK")) {
|
|
87
|
+
if (!options?.forceProbe && (isBunTestRuntime() || $flag("PI_PYTHON_SKIP_CHECK"))) {
|
|
87
88
|
return { ok: true };
|
|
88
89
|
}
|
|
89
90
|
const resolvedCwd = path.resolve(cwd);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Subprocess spawn-option helpers for the Python kernel.
|
|
3
3
|
*
|
|
4
|
-
* Pure helpers (`shouldHideKernelWindow`, `
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* Pure helpers (`shouldHideKernelWindow`, `consoleAttached`) live here so they
|
|
5
|
+
* can be unit-tested without dragging in the kernel's runtime dependencies.
|
|
6
|
+
* The effectful `hostHasInheritableConsole` combines a Win32 FFI probe with
|
|
7
|
+
* TTY evidence and is the function `kernel.ts` actually calls.
|
|
8
8
|
*/
|
|
9
9
|
import { dlopen, FFIType } from "bun:ffi";
|
|
10
10
|
|
|
@@ -54,20 +54,21 @@ export function shouldDetachKernel(platform: NodeJS.Platform): boolean {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
|
-
*
|
|
57
|
+
* Combine native Win32 and stdio TTY evidence of an inheritable console.
|
|
58
58
|
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* Win32 probe over this fallback whenever possible.
|
|
59
|
+
* `GetConsoleWindow()` detects classic consoles even when every stdio stream
|
|
60
|
+
* is redirected. TTY detection covers ConPTY-backed terminals, where compiled
|
|
61
|
+
* hosts can receive a null HWND despite being attached to Windows Terminal.
|
|
62
|
+
* Either signal must preserve console inheritance: `CREATE_NO_WINDOW` can
|
|
63
|
+
* deadlock NumPy native-extension loading in the Python child.
|
|
65
64
|
*/
|
|
66
|
-
export function
|
|
65
|
+
export function consoleAttached(opts: {
|
|
66
|
+
nativeConsole?: boolean | null;
|
|
67
67
|
stdinIsTTY: boolean;
|
|
68
68
|
stdoutIsTTY: boolean;
|
|
69
69
|
stderrIsTTY: boolean;
|
|
70
70
|
}): boolean {
|
|
71
|
+
if (opts.nativeConsole === true) return true;
|
|
71
72
|
return opts.stdinIsTTY || opts.stdoutIsTTY || opts.stderrIsTTY;
|
|
72
73
|
}
|
|
73
74
|
|
|
@@ -75,10 +76,10 @@ export function consoleAttachedViaTTY(opts: {
|
|
|
75
76
|
* Probe `kernel32.dll!GetConsoleWindow()` to detect whether the current
|
|
76
77
|
* Windows process owns a console window.
|
|
77
78
|
*
|
|
78
|
-
* Returns `true` for a non-NULL HWND, `false` when NULL
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
79
|
+
* Returns `true` for a non-NULL HWND, `false` when NULL, and `null` when the
|
|
80
|
+
* probe itself fails (off-Windows, FFI disabled, or unexpected kernel32
|
|
81
|
+
* layout). A false result is not conclusive for ConPTY-backed terminals, so
|
|
82
|
+
* callers must also inspect the stdio TTY signals.
|
|
82
83
|
*
|
|
83
84
|
* Cached on first call because in practice the console attachment of a
|
|
84
85
|
* long-lived OMP host never changes for the lifetime of the process, and
|
|
@@ -117,21 +118,15 @@ export function __resetWindowsConsoleProbeCache(): void {
|
|
|
117
118
|
/**
|
|
118
119
|
* Whether the host process owns a console its children can inherit.
|
|
119
120
|
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
* correctly classified as console-attached and the kernel keeps its
|
|
125
|
-
* inheritable console.
|
|
126
|
-
* - On any other platform, or if the FFI probe fails, fall back to the
|
|
127
|
-
* TTY-OR heuristic. That still catches the common interactive cases.
|
|
121
|
+
* On Windows, `GetConsoleWindow()` detects classic consoles and all-stdio-
|
|
122
|
+
* redirected launches while stdio TTYs detect ConPTY-backed terminals. Either
|
|
123
|
+
* signal is sufficient. Other platforms use the same TTY evidence, although
|
|
124
|
+
* `windowsHide` is a no-op there.
|
|
128
125
|
*/
|
|
129
126
|
export function hostHasInheritableConsole(): boolean {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
return consoleAttachedViaTTY({
|
|
127
|
+
const nativeConsole = process.platform === "win32" ? probeWindowsConsoleWindow() : null;
|
|
128
|
+
return consoleAttached({
|
|
129
|
+
nativeConsole,
|
|
135
130
|
stdinIsTTY: !!process.stdin.isTTY,
|
|
136
131
|
stdoutIsTTY: !!process.stdout.isTTY,
|
|
137
132
|
stderrIsTTY: !!process.stderr.isTTY,
|
package/src/export/html/index.ts
CHANGED
|
@@ -181,10 +181,17 @@ export interface SessionData {
|
|
|
181
181
|
subSessions?: Record<string, SubSession>;
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
+
function sessionHeaderForExport(header: SessionHeader | null): SessionHeader | null {
|
|
185
|
+
if (!header) return null;
|
|
186
|
+
const exported = { ...header };
|
|
187
|
+
delete exported.previousSessionFiles;
|
|
188
|
+
return exported;
|
|
189
|
+
}
|
|
190
|
+
|
|
184
191
|
/** Snapshot the session (plus optional agent state) into the JSON shape the viewer renders. */
|
|
185
192
|
export function buildSessionData(sm: SessionManager, state?: AgentState): SessionData {
|
|
186
193
|
return {
|
|
187
|
-
header: sm.getHeader(),
|
|
194
|
+
header: sessionHeaderForExport(sm.getHeader()),
|
|
188
195
|
entries: sm.getEntries(),
|
|
189
196
|
leafId: sm.getLeafId(),
|
|
190
197
|
systemPrompt: state?.systemPrompt.join("\n\n"),
|
|
@@ -231,7 +238,7 @@ async function collectSubSessionsFromDir(
|
|
|
231
238
|
out[key] = {
|
|
232
239
|
agentId,
|
|
233
240
|
parent: parentKey,
|
|
234
|
-
header,
|
|
241
|
+
header: sessionHeaderForExport(header),
|
|
235
242
|
entries,
|
|
236
243
|
leafId: entries.length > 0 ? entries[entries.length - 1].id : null,
|
|
237
244
|
};
|
|
@@ -295,7 +302,7 @@ export async function exportFromFile(inputPath: string, options?: ExportOptions
|
|
|
295
302
|
}
|
|
296
303
|
|
|
297
304
|
const sessionData: SessionData = {
|
|
298
|
-
header: sm.getHeader(),
|
|
305
|
+
header: sessionHeaderForExport(sm.getHeader()),
|
|
299
306
|
entries: sm.getEntries(),
|
|
300
307
|
leafId: sm.getLeafId(),
|
|
301
308
|
};
|