@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/tools/grep.ts
CHANGED
|
@@ -22,6 +22,7 @@ import type { InternalResource, ResolveContext } from "../internal-urls/types";
|
|
|
22
22
|
import type { Theme } from "../modes/theme/theme";
|
|
23
23
|
import grepDescription from "../prompts/tools/grep.md" with { type: "text" };
|
|
24
24
|
import { DEFAULT_MAX_COLUMN, type TruncationResult, truncateHead, truncateLine } from "../session/streaming-output";
|
|
25
|
+
import { isScoutSpawnable } from "../task/spawn-policy";
|
|
25
26
|
import {
|
|
26
27
|
Ellipsis,
|
|
27
28
|
fileHyperlink,
|
|
@@ -909,7 +910,17 @@ export class GrepTool implements AgentTool<typeof searchSchema, GrepToolDetails>
|
|
|
909
910
|
readonly label = "Grep";
|
|
910
911
|
readonly loadMode = "discoverable";
|
|
911
912
|
readonly summary = "Grep file contents using ripgrep (fast regex search)";
|
|
912
|
-
|
|
913
|
+
get description(): string {
|
|
914
|
+
const displayMode = resolveFileDisplayMode(this.session);
|
|
915
|
+
return prompt.render(grepDescription, {
|
|
916
|
+
IS_HL_MODE: displayMode.hashLines,
|
|
917
|
+
IS_LINE_NUMBER_MODE: !displayMode.hashLines && displayMode.lineNumbers,
|
|
918
|
+
scoutAvailable: isScoutSpawnable(
|
|
919
|
+
this.session.settings.get("task.disabledAgents") as string[] | undefined,
|
|
920
|
+
this.session.getSessionSpawns?.() ?? "*",
|
|
921
|
+
),
|
|
922
|
+
});
|
|
923
|
+
}
|
|
913
924
|
readonly parameters = searchSchema;
|
|
914
925
|
readonly strict = true;
|
|
915
926
|
|
|
@@ -924,11 +935,6 @@ export class GrepTool implements AgentTool<typeof searchSchema, GrepToolDetails>
|
|
|
924
935
|
this.#contextOverride = context !== undefined ? Math.max(0, Math.floor(context)) : undefined;
|
|
925
936
|
const total = options?.totalMatchLimit;
|
|
926
937
|
this.#totalMatchLimit = total !== undefined ? Math.max(1, Math.floor(total)) : undefined;
|
|
927
|
-
const displayMode = resolveFileDisplayMode(session);
|
|
928
|
-
this.description = prompt.render(grepDescription, {
|
|
929
|
-
IS_HL_MODE: displayMode.hashLines,
|
|
930
|
-
IS_LINE_NUMBER_MODE: !displayMode.hashLines && displayMode.lineNumbers,
|
|
931
|
-
});
|
|
932
938
|
}
|
|
933
939
|
|
|
934
940
|
async execute(
|
package/src/tools/hub/launch.ts
CHANGED
|
@@ -10,7 +10,7 @@ import type { Component } from "@oh-my-pi/pi-tui";
|
|
|
10
10
|
import { Text } from "@oh-my-pi/pi-tui";
|
|
11
11
|
import { sanitizeText } from "@oh-my-pi/pi-utils";
|
|
12
12
|
import type { RenderResultOptions } from "../../extensibility/custom-tools/types";
|
|
13
|
-
import { daemonClientForProject } from "../../launch/client";
|
|
13
|
+
import { type DaemonBrokerClient, DaemonBrokerRejectedError, daemonClientForProject } from "../../launch/client";
|
|
14
14
|
import type { DaemonOperation, DaemonRpcResult, DaemonSnapshot, DaemonSpec, DaemonState } from "../../launch/protocol";
|
|
15
15
|
import { renderTerminalOutputIsolated } from "../../launch/terminal-output-worker-client";
|
|
16
16
|
import type { Theme, ThemeColor } from "../../modes/theme/theme";
|
|
@@ -35,6 +35,81 @@ import {
|
|
|
35
35
|
import { styleTerminalRow } from "../terminal-output";
|
|
36
36
|
import { ToolError } from "../tool-errors";
|
|
37
37
|
|
|
38
|
+
interface CompletionRegistration {
|
|
39
|
+
inFlight: number;
|
|
40
|
+
retained: boolean;
|
|
41
|
+
active: boolean;
|
|
42
|
+
cleanup: (preservePending?: boolean) => void;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
interface CompletionLease {
|
|
46
|
+
retain: () => void;
|
|
47
|
+
reject: (preservePending?: boolean) => void;
|
|
48
|
+
hasConcurrentRequest: () => boolean;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const completionRegistrations = new WeakMap<
|
|
52
|
+
ToolSession,
|
|
53
|
+
Map<DaemonBrokerClient, Map<string, CompletionRegistration>>
|
|
54
|
+
>();
|
|
55
|
+
|
|
56
|
+
function registerCompletionSink(
|
|
57
|
+
session: ToolSession,
|
|
58
|
+
client: DaemonBrokerClient,
|
|
59
|
+
owner: string,
|
|
60
|
+
): CompletionLease | undefined {
|
|
61
|
+
if (!session.queueLaunchCompletion) return undefined;
|
|
62
|
+
let clients = completionRegistrations.get(session);
|
|
63
|
+
if (!clients) {
|
|
64
|
+
clients = new Map();
|
|
65
|
+
completionRegistrations.set(session, clients);
|
|
66
|
+
}
|
|
67
|
+
let owners = clients.get(client);
|
|
68
|
+
if (!owners) {
|
|
69
|
+
owners = new Map();
|
|
70
|
+
clients.set(client, owners);
|
|
71
|
+
}
|
|
72
|
+
let registration = owners.get(owner);
|
|
73
|
+
if (!registration) {
|
|
74
|
+
const unregister = client.onCompletion(owner, notification => {
|
|
75
|
+
if (session.isDisposed?.()) throw new Error("Session disposed before launch completion delivery");
|
|
76
|
+
const delivery = session.queueLaunchCompletion?.(notification);
|
|
77
|
+
if (!delivery) throw new Error("Session cannot accept launch completion delivery");
|
|
78
|
+
return delivery;
|
|
79
|
+
});
|
|
80
|
+
let unregisterDispose: (() => void) | void;
|
|
81
|
+
let unregisterSessionChange: (() => void) | void;
|
|
82
|
+
const cleanup = (preservePending = false): void => {
|
|
83
|
+
if (!registration?.active) return;
|
|
84
|
+
registration.active = false;
|
|
85
|
+
unregister({ preservePending });
|
|
86
|
+
unregisterDispose?.();
|
|
87
|
+
unregisterSessionChange?.();
|
|
88
|
+
owners.delete(owner);
|
|
89
|
+
if (owners.size === 0) clients.delete(client);
|
|
90
|
+
if (clients.size === 0) completionRegistrations.delete(session);
|
|
91
|
+
};
|
|
92
|
+
registration = { inFlight: 0, retained: false, active: true, cleanup };
|
|
93
|
+
owners.set(owner, registration);
|
|
94
|
+
unregisterDispose = session.registerDisposeCallback?.(() => cleanup(true));
|
|
95
|
+
unregisterSessionChange = session.registerSessionChangeCallback?.(() => cleanup(true));
|
|
96
|
+
}
|
|
97
|
+
registration.inFlight++;
|
|
98
|
+
let settled = false;
|
|
99
|
+
const settle = (retain: boolean, preservePending = false): void => {
|
|
100
|
+
if (settled || !registration.active) return;
|
|
101
|
+
settled = true;
|
|
102
|
+
registration.inFlight--;
|
|
103
|
+
if (retain) registration.retained = true;
|
|
104
|
+
if (!registration.retained && registration.inFlight === 0) registration.cleanup(preservePending);
|
|
105
|
+
};
|
|
106
|
+
return {
|
|
107
|
+
retain: () => settle(true),
|
|
108
|
+
hasConcurrentRequest: () => registration.active && registration.inFlight > 1,
|
|
109
|
+
reject: preservePending => settle(false, preservePending),
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
38
113
|
/** Broker-facing launch parameters; the hub adapts its `ps` op to `list` before calling in. */
|
|
39
114
|
export interface LaunchParams {
|
|
40
115
|
op: "start" | "list" | "logs" | "wait" | "send" | "stop" | "restart" | "describe";
|
|
@@ -321,11 +396,52 @@ export async function executeLaunch(
|
|
|
321
396
|
signal?: AbortSignal,
|
|
322
397
|
): Promise<AgentToolResult<LaunchToolDetails>> {
|
|
323
398
|
const client = await daemonClientForProject(session.cwd);
|
|
324
|
-
const
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
399
|
+
const operation = operationFor(params, session);
|
|
400
|
+
const owner = operation.op === "start" ? operation.owner : undefined;
|
|
401
|
+
const resumedOwner = params.op !== "start" ? (session.getSessionId?.() ?? undefined) : undefined;
|
|
402
|
+
const completionLease = owner
|
|
403
|
+
? registerCompletionSink(session, client, owner)
|
|
404
|
+
: resumedOwner
|
|
405
|
+
? registerCompletionSink(session, client, resumedOwner)
|
|
406
|
+
: undefined;
|
|
407
|
+
try {
|
|
408
|
+
const result = await client.request(operation, signal);
|
|
409
|
+
const sessionOwner = session.getSessionId?.();
|
|
410
|
+
let resumedDaemonFound = false;
|
|
411
|
+
const daemons =
|
|
412
|
+
result.op === "list" ? result.daemons : "daemon" in result && result.daemon ? [result.daemon] : [];
|
|
413
|
+
for (const daemon of daemons) {
|
|
414
|
+
if (!daemon.owner || daemon.owner !== sessionOwner || TERMINAL_STATES[daemon.state]) continue;
|
|
415
|
+
resumedDaemonFound = true;
|
|
416
|
+
if (daemon.owner !== resumedOwner) registerCompletionSink(session, client, daemon.owner)?.retain();
|
|
417
|
+
}
|
|
418
|
+
if (params.op === "list" && resumedOwner && !resumedDaemonFound) completionLease?.reject(true);
|
|
419
|
+
else completionLease?.retain();
|
|
420
|
+
return {
|
|
421
|
+
content: [{ type: "text", text: replaceTabs(toolContent(result, params)) }],
|
|
422
|
+
details: await toolDetails(result, params),
|
|
423
|
+
};
|
|
424
|
+
} catch (error) {
|
|
425
|
+
if (error instanceof DaemonBrokerRejectedError && owner) {
|
|
426
|
+
if (completionLease?.hasConcurrentRequest()) {
|
|
427
|
+
completionLease.reject();
|
|
428
|
+
} else {
|
|
429
|
+
try {
|
|
430
|
+
const listed = await client.request({ op: "list" }, signal);
|
|
431
|
+
const ownerStillRunning =
|
|
432
|
+
listed.op === "list" &&
|
|
433
|
+
listed.daemons.some(daemon => daemon.owner === owner && !TERMINAL_STATES[daemon.state]);
|
|
434
|
+
if (ownerStillRunning) completionLease?.retain();
|
|
435
|
+
else completionLease?.reject(true);
|
|
436
|
+
} catch {
|
|
437
|
+
completionLease?.retain();
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
} else {
|
|
441
|
+
completionLease?.retain();
|
|
442
|
+
}
|
|
443
|
+
throw error;
|
|
444
|
+
}
|
|
329
445
|
}
|
|
330
446
|
|
|
331
447
|
// =============================================================================
|
package/src/tools/index.ts
CHANGED
|
@@ -16,6 +16,7 @@ import type { GoalModeState, GoalRuntime } from "../goals";
|
|
|
16
16
|
import { GoalTool } from "../goals/tools/goal-tool";
|
|
17
17
|
import type { HindsightSessionState } from "../hindsight/state";
|
|
18
18
|
import type { LocalProtocolOptions } from "../internal-urls";
|
|
19
|
+
import type { DaemonCompletionNotification } from "../launch/protocol";
|
|
19
20
|
import { LspTool } from "../lsp";
|
|
20
21
|
import type { MCPManager } from "../mcp";
|
|
21
22
|
import type { MnemopiSessionState } from "../mnemopi/state";
|
|
@@ -155,6 +156,8 @@ export interface ToolSession {
|
|
|
155
156
|
additionalDirectories?: string[];
|
|
156
157
|
/** Whether UI is available */
|
|
157
158
|
hasUI: boolean;
|
|
159
|
+
/** Whether this session has begun disposal. */
|
|
160
|
+
isDisposed?: () => boolean;
|
|
158
161
|
/**
|
|
159
162
|
* Suppress the spawn specialization/coordination advisory appended to `task`
|
|
160
163
|
* results. Set by internal/programmatic callers (e.g. the commit agent's
|
|
@@ -380,6 +383,12 @@ export interface ToolSession {
|
|
|
380
383
|
|
|
381
384
|
/** Queue a hidden message to be injected at the next agent turn. */
|
|
382
385
|
queueDeferredMessage?(message: CustomMessage): void;
|
|
386
|
+
/** Queue a broker supervised-process completion for the owning session. */
|
|
387
|
+
queueLaunchCompletion?(notification: DaemonCompletionNotification): Promise<void>;
|
|
388
|
+
/** Register cleanup that runs when this session is disposed; returns a handle that removes the cleanup. */
|
|
389
|
+
registerDisposeCallback?(callback: () => void): (() => void) | void;
|
|
390
|
+
/** Register cleanup that runs when this ToolSession adopts a different session ID. */
|
|
391
|
+
registerSessionChangeCallback?(callback: () => void): (() => void) | void;
|
|
383
392
|
/** Queue late LSP diagnostics (arrived after an edit/write returned) to be shown
|
|
384
393
|
* in the transcript and delivered to the model at the next yield, like background
|
|
385
394
|
* job results. */
|
|
@@ -12,9 +12,15 @@ import { prompt } from "@oh-my-pi/pi-utils";
|
|
|
12
12
|
import { type } from "arktype";
|
|
13
13
|
import { extractTextContent } from "../commit/utils";
|
|
14
14
|
|
|
15
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
expandRoleAlias,
|
|
17
|
+
extractExplicitThinkingSelector,
|
|
18
|
+
getModelMatchPreferences,
|
|
19
|
+
resolveModelFromString,
|
|
20
|
+
} from "../config/model-resolver";
|
|
16
21
|
import inspectImageDescription from "../prompts/tools/inspect-image.md" with { type: "text" };
|
|
17
22
|
import inspectImageSystemPromptTemplate from "../prompts/tools/inspect-image-system.md" with { type: "text" };
|
|
23
|
+
import { concreteThinkingLevel, resolveThinkingLevelForModel, toReasoningEffort } from "../thinking";
|
|
18
24
|
import {
|
|
19
25
|
ImageInputTooLargeError,
|
|
20
26
|
type LoadedImageInput,
|
|
@@ -163,11 +169,17 @@ export class InspectImageTool implements AgentTool<typeof inspectImageSchema, In
|
|
|
163
169
|
};
|
|
164
170
|
|
|
165
171
|
const activeModelPattern = this.session.getActiveModelString?.() ?? this.session.getModelString?.();
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
resolvePattern(
|
|
170
|
-
|
|
172
|
+
let model: Model<Api> | undefined;
|
|
173
|
+
let selectedPattern: string | undefined;
|
|
174
|
+
for (const pattern of ["@vision", "@default", activeModelPattern]) {
|
|
175
|
+
const resolved = resolvePattern(pattern);
|
|
176
|
+
if (resolved) {
|
|
177
|
+
model = resolved;
|
|
178
|
+
selectedPattern = pattern;
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
model ??= availableModels[0];
|
|
171
183
|
if (!model) {
|
|
172
184
|
throw new ToolError("Unable to resolve a model for inspect_image.");
|
|
173
185
|
}
|
|
@@ -233,6 +245,19 @@ export class InspectImageTool implements AgentTool<typeof inspectImageSchema, In
|
|
|
233
245
|
return `inspect_image request timed out after ${seconds}s. Increase inspect_image.timeoutMs (currently ${timeoutMs}ms; 0 disables) or check the vision model provider.`;
|
|
234
246
|
};
|
|
235
247
|
|
|
248
|
+
// Honor the thinking effort configured on the resolved model role
|
|
249
|
+
// (e.g. `modelRoles.vision: <model>:high`). Without it the oneshot sent a
|
|
250
|
+
// suppressed/zero thinking budget, which thinking-only models (Gemini 3.x)
|
|
251
|
+
// reject with HTTP 400 ("Budget 0 is invalid. This model only works in
|
|
252
|
+
// thinking mode.").
|
|
253
|
+
const configuredThinking = concreteThinkingLevel(
|
|
254
|
+
extractExplicitThinkingSelector(selectedPattern, this.session.settings, {
|
|
255
|
+
isLiteralModelId: (provider, id) =>
|
|
256
|
+
availableModels.some(candidate => candidate.provider === provider && candidate.id === id),
|
|
257
|
+
}),
|
|
258
|
+
);
|
|
259
|
+
const reasoning = toReasoningEffort(resolveThinkingLevelForModel(model, configuredThinking));
|
|
260
|
+
|
|
236
261
|
let response: AssistantMessage;
|
|
237
262
|
try {
|
|
238
263
|
response = await instrumentedCompleteSimple(
|
|
@@ -253,6 +278,7 @@ export class InspectImageTool implements AgentTool<typeof inspectImageSchema, In
|
|
|
253
278
|
{
|
|
254
279
|
apiKey: modelRegistry.resolver(model, this.session.getSessionId?.() ?? undefined),
|
|
255
280
|
signal: effectiveSignal,
|
|
281
|
+
reasoning,
|
|
256
282
|
},
|
|
257
283
|
{ telemetry, oneshotKind: "inspect_image", completeImpl: this.completeImageRequest },
|
|
258
284
|
);
|
|
@@ -61,6 +61,8 @@ export const PREVIEW_LIMITS = {
|
|
|
61
61
|
OUTPUT_COLLAPSED: 3,
|
|
62
62
|
/** Output preview lines in expanded view */
|
|
63
63
|
OUTPUT_EXPANDED: 10,
|
|
64
|
+
/** Computer script lines shown in collapsed view */
|
|
65
|
+
COMPUTER_CODE_COLLAPSED: 10,
|
|
64
66
|
/** Max hunks shown when collapsed (edit tool) */
|
|
65
67
|
DIFF_COLLAPSED_HUNKS: 8,
|
|
66
68
|
/** Max diff lines shown when collapsed (edit tool) */
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { untilAborted } from "@oh-my-pi/pi-utils";
|
|
2
|
-
import { ToolError, throwIfAborted } from "
|
|
1
|
+
import { untilAborted } from "@oh-my-pi/pi-utils/abortable";
|
|
2
|
+
import { ToolError, throwIfAborted } from "./tool-errors";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Marks a run-scoped promise as observed without changing its behavior for awaited callers.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
7
|
+
* Run teardown aborts can reject promises created for evaluated code after user code
|
|
8
8
|
* has stopped observing them (for example fire-and-forget `wait()`/facade calls). In 16.3.0
|
|
9
9
|
* those zero-consumer rejections reached the process-level `unhandledRejection` handler and
|
|
10
10
|
* killed every subagent sharing the process (issues #4499/#4672). Attaching a no-op rejection
|
|
@@ -33,8 +33,8 @@ export interface WaitPredicateOptions {
|
|
|
33
33
|
/**
|
|
34
34
|
* Effective `wait(predicate)` deadline for a given cell budget. Always strictly below
|
|
35
35
|
* the cell budget so the named `wait(predicate) timed out` error wins the race against
|
|
36
|
-
* the opaque whole-cell
|
|
37
|
-
*
|
|
36
|
+
* the opaque whole-cell execution timeout. `0`/`Infinity` ("disable") map to the largest
|
|
37
|
+
* bounded deadline; negative/NaN garbage falls back to the default.
|
|
38
38
|
*/
|
|
39
39
|
export function resolvePredicateTimeout(cellTimeoutMs: number, explicit?: number): number {
|
|
40
40
|
const budgetBound = Math.max(1, cellTimeoutMs - CELL_BUDGET_SLACK_MS);
|
|
@@ -44,15 +44,15 @@ export function resolvePredicateTimeout(cellTimeoutMs: number, explicit?: number
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
|
-
* Run-scoped `wait()` helper for evaluated browser
|
|
48
|
-
* cancellation signal.
|
|
47
|
+
* Run-scoped `wait()` helper for evaluated code (browser and computer workers), honoring
|
|
48
|
+
* the owning run's cancellation signal.
|
|
49
49
|
*
|
|
50
50
|
* - `wait(ms)` sleeps for `ms` milliseconds.
|
|
51
51
|
* - `wait(fn, { timeout?, interval? })` polls `fn` (sync or async) until it returns a
|
|
52
52
|
* truthy value and resolves with that value; throws a named `ToolError` on timeout
|
|
53
53
|
* instead of stalling into the whole-cell deadline. Predicate errors propagate.
|
|
54
54
|
*/
|
|
55
|
-
export function
|
|
55
|
+
export function waitForRun(
|
|
56
56
|
msOrPredicate: number | (() => unknown),
|
|
57
57
|
signal: AbortSignal,
|
|
58
58
|
opts?: WaitPredicateOptions,
|
|
@@ -86,8 +86,8 @@ export function waitForBrowserRun(
|
|
|
86
86
|
return markHandled(promise);
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
/** Binds a long-lived
|
|
90
|
-
export function
|
|
89
|
+
/** Binds a long-lived scope facade (page/tab/desktop objects) to one evaluated run's abort signal. */
|
|
90
|
+
export function bindRunFacade<T extends object>(target: T, signal: AbortSignal): T {
|
|
91
91
|
const cache = new Map<PropertyKey, unknown>();
|
|
92
92
|
return new Proxy(target, {
|
|
93
93
|
get(current, prop) {
|
|
@@ -121,7 +121,7 @@ export function bindBrowserRunFacade<T extends object>(target: T, signal: AbortS
|
|
|
121
121
|
// brand-check internal slots that a Proxy cannot forward, and reading a
|
|
122
122
|
// signal needs no abort gating anyway.
|
|
123
123
|
if (value instanceof AbortSignal) return value;
|
|
124
|
-
const wrapped =
|
|
124
|
+
const wrapped = bindRunFacade(value, signal);
|
|
125
125
|
cache.set(prop, wrapped);
|
|
126
126
|
return wrapped;
|
|
127
127
|
}
|
|
@@ -11,6 +11,7 @@ export const TOOL_TIMEOUTS = {
|
|
|
11
11
|
bash: { default: 300, min: 1, max: 3600 },
|
|
12
12
|
eval: { default: 30, min: 1, max: 3600 },
|
|
13
13
|
browser: { default: 30, min: 1, max: 300 },
|
|
14
|
+
computer: { default: 120, min: 1, max: 300 },
|
|
14
15
|
ssh: { default: 60, min: 1, max: 3600 },
|
|
15
16
|
fetch: { default: 20, min: 1, max: 45 },
|
|
16
17
|
lsp: { default: 20, min: 5, max: 300 },
|
package/src/tools/xdev.ts
CHANGED
|
@@ -36,6 +36,7 @@ import type { RenderResultOptions } from "../extensibility/custom-tools/types";
|
|
|
36
36
|
import { XD_URL_PREFIX } from "../internal-urls/xd-protocol";
|
|
37
37
|
import type { Theme } from "../modes/theme/theme";
|
|
38
38
|
import { truncateHeadBytes } from "../session/streaming-output";
|
|
39
|
+
import { resolveToolTier, type ToolTier } from "./approval";
|
|
39
40
|
import { renderDefaultToolExecution } from "./default-renderer";
|
|
40
41
|
import type { Tool } from "./index";
|
|
41
42
|
import { replaceTabs } from "./render-utils";
|
|
@@ -88,6 +89,13 @@ export interface XdevDispatch {
|
|
|
88
89
|
mode: "help" | "execute";
|
|
89
90
|
/** Validated inner args, kept for renderer delegation on result rebuilds. */
|
|
90
91
|
args?: Record<string, unknown>;
|
|
92
|
+
/**
|
|
93
|
+
* Approval tier of the wrapped tool for {@link args} (`read` = no workspace
|
|
94
|
+
* mutation). Absent for `help` dispatches and calls whose tier could not be
|
|
95
|
+
* resolved. Consumed by the prewalk coordinator to skip read-only device
|
|
96
|
+
* calls when deciding the model hand-off (issue #7312).
|
|
97
|
+
*/
|
|
98
|
+
tier?: ToolTier;
|
|
91
99
|
/** Details object returned by the wrapped tool, when executed. */
|
|
92
100
|
inner?: unknown;
|
|
93
101
|
}
|
|
@@ -415,7 +423,18 @@ export async function dispatchXdevTool(
|
|
|
415
423
|
}
|
|
416
424
|
|
|
417
425
|
const validated = parseDeviceArgs(canonical as AiTool, content, toolCallId, () => renderDocs(canonical));
|
|
418
|
-
|
|
426
|
+
// Record the wrapped tool's approval tier so the prewalk coordinator can
|
|
427
|
+
// tell a read-only device call (e.g. `lsp` navigation) from a real
|
|
428
|
+
// workspace mutation without re-decoding the payload. Best-effort: a
|
|
429
|
+
// throwing approval leaves the tier absent (prewalk then declines to
|
|
430
|
+
// switch), unlike the write gate which fails closed to `exec`.
|
|
431
|
+
let tier: ToolTier | undefined;
|
|
432
|
+
try {
|
|
433
|
+
tier = resolveToolTier(canonical, validated);
|
|
434
|
+
} catch {
|
|
435
|
+
tier = undefined;
|
|
436
|
+
}
|
|
437
|
+
xdev = { ...xdev, args: validated, tier };
|
|
419
438
|
const innerOnUpdate: AgentToolUpdateCallback | undefined = onUpdate
|
|
420
439
|
? partial =>
|
|
421
440
|
onUpdate({
|
|
@@ -425,7 +444,15 @@ export async function dispatchXdevTool(
|
|
|
425
444
|
})
|
|
426
445
|
: undefined;
|
|
427
446
|
const executable = state.decorateExecution?.(canonical) ?? canonical;
|
|
428
|
-
const
|
|
447
|
+
const executionContext = context
|
|
448
|
+
? {
|
|
449
|
+
...context,
|
|
450
|
+
xdevTierResolved: (effectiveTier: ToolTier) => {
|
|
451
|
+
xdev = { ...xdev, tier: effectiveTier };
|
|
452
|
+
},
|
|
453
|
+
}
|
|
454
|
+
: undefined;
|
|
455
|
+
const result = await executable.execute(toolCallId, validated as never, signal, innerOnUpdate, executionContext);
|
|
429
456
|
return { result, xdev: { ...xdev, inner: result.details } };
|
|
430
457
|
} catch (error) {
|
|
431
458
|
if (
|
package/src/utils/clipboard.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
type ClipboardImage,
|
|
3
|
+
copyToClipboard as nativeCopyToClipboard,
|
|
4
|
+
readImageFromClipboard as nativeReadImageFromClipboard,
|
|
5
|
+
} from "@oh-my-pi/pi-natives/clipboard";
|
|
6
|
+
import * as logger from "@oh-my-pi/pi-utils/logger";
|
|
7
|
+
import { SUPPORTED_IMAGE_MIME_TYPES } from "@oh-my-pi/pi-utils/mime";
|
|
4
8
|
import MAC_FILE_URL_SCRIPT from "./mac-file-urls.applescript" with { type: "text" };
|
|
5
9
|
|
|
10
|
+
type SpawnCaptureOptions = { input?: string; timeoutMs?: number };
|
|
11
|
+
|
|
6
12
|
/**
|
|
7
13
|
* Run a subprocess and capture its stdout without blocking the event loop.
|
|
8
14
|
*
|
|
@@ -10,15 +16,20 @@ import MAC_FILE_URL_SCRIPT from "./mac-file-urls.applescript" with { type: "text
|
|
|
10
16
|
* path all shell out to CLI clipboard tools. The synchronous `execSync` API
|
|
11
17
|
* parks the render loop until the child exits or the timeout fires, so a hung
|
|
12
18
|
* clipboard daemon freezes the TUI for the full 2000ms budget (#4235). This
|
|
13
|
-
* helper mirrors the previous semantics —
|
|
14
|
-
*
|
|
15
|
-
*
|
|
19
|
+
* helper mirrors the previous semantics — capture stdout, throw on non-zero
|
|
20
|
+
* exit or timeout, forward optional stdin — but yields to the event loop while
|
|
21
|
+
* the child runs.
|
|
16
22
|
*
|
|
17
23
|
* @throws Error when the child fails to spawn, is killed by the timeout, or
|
|
18
|
-
* exits with a non-zero status. Callers rely on this to
|
|
19
|
-
*
|
|
24
|
+
* exits with a non-zero status. Callers rely on this to use platform
|
|
25
|
+
* fallbacks or report an empty clipboard.
|
|
20
26
|
*/
|
|
21
|
-
async function spawnCapture(cmd: string[], options:
|
|
27
|
+
async function spawnCapture(cmd: string[], options: SpawnCaptureOptions & { encoding: "bytes" }): Promise<Uint8Array>;
|
|
28
|
+
async function spawnCapture(cmd: string[], options?: SpawnCaptureOptions): Promise<string>;
|
|
29
|
+
async function spawnCapture(
|
|
30
|
+
cmd: string[],
|
|
31
|
+
options: SpawnCaptureOptions & { encoding?: "bytes" } = {},
|
|
32
|
+
): Promise<string | Uint8Array> {
|
|
22
33
|
const timeoutMs = options.timeoutMs ?? 2000;
|
|
23
34
|
const proc = Bun.spawn(cmd, {
|
|
24
35
|
stdout: "pipe",
|
|
@@ -31,7 +42,9 @@ async function spawnCapture(cmd: string[], options: { input?: string; timeoutMs?
|
|
|
31
42
|
proc.kill();
|
|
32
43
|
}, timeoutMs);
|
|
33
44
|
try {
|
|
34
|
-
const
|
|
45
|
+
const response = new Response(proc.stdout);
|
|
46
|
+
const stdout =
|
|
47
|
+
options.encoding === "bytes" ? new Uint8Array(await response.arrayBuffer()) : await response.text();
|
|
35
48
|
await proc.exited;
|
|
36
49
|
if (timedOut) {
|
|
37
50
|
throw new Error(`${cmd[0]} timed out after ${timeoutMs}ms`);
|
|
@@ -125,7 +138,7 @@ export async function copyToClipboard(text: string): Promise<void> {
|
|
|
125
138
|
}
|
|
126
139
|
}
|
|
127
140
|
|
|
128
|
-
await
|
|
141
|
+
await nativeCopyToClipboard(text);
|
|
129
142
|
} catch {
|
|
130
143
|
// Ignore — clipboard copy is best-effort
|
|
131
144
|
}
|
|
@@ -255,7 +268,7 @@ async function readTextViaPowerShell(): Promise<string | null> {
|
|
|
255
268
|
* because terminal clipboard paths can leave image payloads invisible to the
|
|
256
269
|
* native bridge.
|
|
257
270
|
*
|
|
258
|
-
* @returns
|
|
271
|
+
* @returns A supported image payload or null when no image is available.
|
|
259
272
|
*/
|
|
260
273
|
export async function readImageFromClipboard(): Promise<ClipboardImage | null> {
|
|
261
274
|
if (process.env.TERMUX_VERSION) {
|
|
@@ -272,7 +285,7 @@ export async function readImageFromClipboard(): Promise<ClipboardImage | null> {
|
|
|
272
285
|
|
|
273
286
|
if (process.platform === "win32") {
|
|
274
287
|
try {
|
|
275
|
-
const image = await
|
|
288
|
+
const image = await nativeReadImageFromClipboard();
|
|
276
289
|
if (image) return image;
|
|
277
290
|
} catch (err) {
|
|
278
291
|
logger.warn("clipboard: native Windows image read failed", { error: String(err) });
|
|
@@ -280,11 +293,24 @@ export async function readImageFromClipboard(): Promise<ClipboardImage | null> {
|
|
|
280
293
|
return await readImageViaPowerShell();
|
|
281
294
|
}
|
|
282
295
|
|
|
296
|
+
if (process.platform === "linux" && process.env.WAYLAND_DISPLAY) {
|
|
297
|
+
try {
|
|
298
|
+
const offeredMimeTypes = new Set((await spawnCapture(["wl-paste", "--list-types"])).split(/\r?\n/));
|
|
299
|
+
for (const mimeType of SUPPORTED_IMAGE_MIME_TYPES) {
|
|
300
|
+
if (!offeredMimeTypes.has(mimeType)) continue;
|
|
301
|
+
const data = await spawnCapture(["wl-paste", "--type", mimeType], { encoding: "bytes" });
|
|
302
|
+
if (data.byteLength > 0) return { data, mimeType };
|
|
303
|
+
}
|
|
304
|
+
} catch {
|
|
305
|
+
// Fall through when wl-clipboard is absent or no advertised image payload can be read.
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
283
309
|
if (!hasDisplay()) {
|
|
284
310
|
return null;
|
|
285
311
|
}
|
|
286
312
|
|
|
287
|
-
return (await
|
|
313
|
+
return (await nativeReadImageFromClipboard()) ?? null;
|
|
288
314
|
}
|
|
289
315
|
|
|
290
316
|
/**
|
|
@@ -39,38 +39,36 @@ export function parseCommandArgs(argsString: string): string[] {
|
|
|
39
39
|
* containing patterns like $1, $@, or $ARGUMENTS are NOT recursively substituted.
|
|
40
40
|
*/
|
|
41
41
|
export function substituteArgs(content: string, args: string[]): string {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
// Replace $1, $2, etc. with positional args FIRST (before wildcards)
|
|
45
|
-
// This prevents wildcard replacement values containing $<digit> patterns from being re-substituted
|
|
46
|
-
result = result.replace(/\$(\d+)/g, (_, num) => {
|
|
47
|
-
const index = parseInt(num, 10) - 1;
|
|
48
|
-
return args[index] ?? "";
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
result = result.replace(/\$@\[(\d+)(?::(\d*)?)?\]/g, (_, startRaw: string, lengthRaw?: string) => {
|
|
52
|
-
const start = Number.parseInt(startRaw, 10);
|
|
53
|
-
if (!Number.isFinite(start) || start < 1) return "";
|
|
54
|
-
const startIndex = start - 1;
|
|
55
|
-
if (startIndex >= args.length) return "";
|
|
42
|
+
const allArgs = args.join(" ");
|
|
56
43
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
44
|
+
return content.replace(
|
|
45
|
+
/\$@\[(\d+)(?::(\d*)?)?\]|\$ARGUMENTS|\$@|\$(\d+)/g,
|
|
46
|
+
(match, startRaw?: string, lengthRaw?: string, positionalNum?: string) => {
|
|
47
|
+
if (positionalNum !== undefined) {
|
|
48
|
+
const index = Number.parseInt(positionalNum, 10) - 1;
|
|
49
|
+
return args[index] ?? "";
|
|
50
|
+
}
|
|
60
51
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
52
|
+
if (startRaw !== undefined) {
|
|
53
|
+
const start = Number.parseInt(startRaw, 10);
|
|
54
|
+
if (!Number.isFinite(start) || start < 1) return "";
|
|
55
|
+
const startIndex = start - 1;
|
|
56
|
+
if (startIndex >= args.length) return "";
|
|
65
57
|
|
|
66
|
-
|
|
67
|
-
|
|
58
|
+
if (lengthRaw === undefined || lengthRaw === "") {
|
|
59
|
+
return args.slice(startIndex).join(" ");
|
|
60
|
+
}
|
|
68
61
|
|
|
69
|
-
|
|
70
|
-
|
|
62
|
+
const length = Number.parseInt(lengthRaw, 10);
|
|
63
|
+
if (!Number.isFinite(length) || length <= 0) return "";
|
|
64
|
+
return args.slice(startIndex, startIndex + length).join(" ");
|
|
65
|
+
}
|
|
71
66
|
|
|
72
|
-
|
|
73
|
-
|
|
67
|
+
if (match === "$ARGUMENTS" || match === "$@") {
|
|
68
|
+
return allArgs;
|
|
69
|
+
}
|
|
74
70
|
|
|
75
|
-
|
|
71
|
+
return match;
|
|
72
|
+
},
|
|
73
|
+
);
|
|
76
74
|
}
|
package/src/utils/tool-choice.ts
CHANGED
|
@@ -12,19 +12,6 @@ export function buildNamedToolChoice(toolName: string, model?: Model<Api>): Tool
|
|
|
12
12
|
return { type: "tool", name: toolName };
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
if (toolName === "computer" && model.supportsComputerUse === true) {
|
|
16
|
-
if (
|
|
17
|
-
model.api === "openai-codex-responses" ||
|
|
18
|
-
model.api === "openai-responses" ||
|
|
19
|
-
model.api === "azure-openai-responses"
|
|
20
|
-
) {
|
|
21
|
-
return { type: "computer" };
|
|
22
|
-
}
|
|
23
|
-
return undefined;
|
|
24
|
-
}
|
|
25
|
-
// Models without native computer support receive the tool as a regular
|
|
26
|
-
// function tool, so the generic named-function forcing below applies.
|
|
27
|
-
|
|
28
15
|
if (
|
|
29
16
|
model.api === "openai-codex-responses" ||
|
|
30
17
|
model.api === "openai-responses" ||
|
package/src/web/kagi.ts
CHANGED
|
@@ -156,6 +156,7 @@ export interface KagiSearchOptions {
|
|
|
156
156
|
recency?: "day" | "week" | "month" | "year";
|
|
157
157
|
sessionId?: string;
|
|
158
158
|
signal?: AbortSignal;
|
|
159
|
+
timeoutMs?: number;
|
|
159
160
|
fetch?: FetchImpl;
|
|
160
161
|
}
|
|
161
162
|
|
|
@@ -253,7 +254,7 @@ export async function searchWithKagi(
|
|
|
253
254
|
Accept: "application/json",
|
|
254
255
|
},
|
|
255
256
|
body,
|
|
256
|
-
signal: withHardTimeout(options.signal),
|
|
257
|
+
signal: withHardTimeout(options.signal, options.timeoutMs),
|
|
257
258
|
});
|
|
258
259
|
|
|
259
260
|
if (!res.ok) {
|