@adhdev/daemon-core 0.6.57 → 0.6.59
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/dist/index.d.ts +18 -1
- package/dist/index.js +339 -167
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/cli-adapters/provider-cli-adapter.ts +223 -48
- package/src/commands/chat-commands.ts +7 -1
- package/src/config/chat-history.ts +53 -1
- package/src/daemon/dev-server.ts +7 -9
- package/src/detection/ide-detector.ts +1 -1
- package/src/providers/cli-provider-instance.ts +10 -23
- package/src/providers/provider-instance.ts +1 -0
- package/src/providers/provider-loader.ts +3 -6
- package/src/providers/version-archive.ts +4 -1
- package/providers/_builtin/.github/workflows/generate-registry.yml +0 -76
- package/providers/_builtin/COMPATIBILITY.md +0 -217
- package/providers/_builtin/CONTRIBUTING.md +0 -200
- package/providers/_builtin/README.md +0 -119
- package/providers/_builtin/_helpers/index.js +0 -188
- package/providers/_builtin/acp/agentpool/provider.json +0 -54
- package/providers/_builtin/acp/amp/provider.json +0 -52
- package/providers/_builtin/acp/auggie/provider.json +0 -57
- package/providers/_builtin/acp/autodev/provider.json +0 -54
- package/providers/_builtin/acp/autohand/provider.json +0 -52
- package/providers/_builtin/acp/blackbox-ai/provider.json +0 -54
- package/providers/_builtin/acp/claude-agent/provider.json +0 -57
- package/providers/_builtin/acp/cline-acp/provider.json +0 -54
- package/providers/_builtin/acp/codebuddy/provider.json +0 -54
- package/providers/_builtin/acp/codex-cli/provider.json +0 -57
- package/providers/_builtin/acp/corust-agent/provider.json +0 -52
- package/providers/_builtin/acp/crow-cli/provider.json +0 -54
- package/providers/_builtin/acp/cursor-acp/provider.json +0 -54
- package/providers/_builtin/acp/deepagents/provider.json +0 -52
- package/providers/_builtin/acp/dimcode/provider.json +0 -54
- package/providers/_builtin/acp/docker-cagent/provider.json +0 -57
- package/providers/_builtin/acp/factory-droid/provider.json +0 -60
- package/providers/_builtin/acp/fast-agent/provider.json +0 -52
- package/providers/_builtin/acp/gemini-cli/provider.json +0 -114
- package/providers/_builtin/acp/github-copilot/provider.json +0 -54
- package/providers/_builtin/acp/goose/provider.json +0 -57
- package/providers/_builtin/acp/junie/provider.json +0 -52
- package/providers/_builtin/acp/kilo/provider.json +0 -54
- package/providers/_builtin/acp/kimi-cli/provider.json +0 -57
- package/providers/_builtin/acp/minion-code/provider.json +0 -52
- package/providers/_builtin/acp/mistral-vibe/provider.json +0 -57
- package/providers/_builtin/acp/nova/provider.json +0 -54
- package/providers/_builtin/acp/openclaw/provider.json +0 -54
- package/providers/_builtin/acp/opencode/provider.json +0 -52
- package/providers/_builtin/acp/openhands/provider.json +0 -54
- package/providers/_builtin/acp/pi-acp/provider.json +0 -52
- package/providers/_builtin/acp/qoder/provider.json +0 -54
- package/providers/_builtin/acp/qwen-code/provider.json +0 -60
- package/providers/_builtin/acp/stakpak/provider.json +0 -54
- package/providers/_builtin/acp/vtcode/provider.json +0 -54
- package/providers/_builtin/cli/aider-cli/provider.json +0 -37
- package/providers/_builtin/cli/aider-cli/scripts/1.0/detect_status.js +0 -20
- package/providers/_builtin/cli/aider-cli/scripts/1.0/parse_approval.js +0 -10
- package/providers/_builtin/cli/aider-cli/scripts/1.0/parse_output.js +0 -49
- package/providers/_builtin/cli/aider-cli/scripts/1.0/scripts.js +0 -7
- package/providers/_builtin/cli/claude-cli/provider.json +0 -109
- package/providers/_builtin/cli/claude-cli/scripts/1.0/detect_status.js +0 -31
- package/providers/_builtin/cli/claude-cli/scripts/1.0/parse_approval.js +0 -38
- package/providers/_builtin/cli/claude-cli/scripts/1.0/parse_output.js +0 -164
- package/providers/_builtin/cli/claude-cli/scripts/1.0/scripts.js +0 -42
- package/providers/_builtin/cli/codex-cli/provider.json +0 -88
- package/providers/_builtin/cli/codex-cli/scripts/1.0/detect_status.js +0 -20
- package/providers/_builtin/cli/codex-cli/scripts/1.0/parse_approval.js +0 -15
- package/providers/_builtin/cli/codex-cli/scripts/1.0/parse_output.js +0 -68
- package/providers/_builtin/cli/codex-cli/scripts/1.0/scripts.js +0 -11
- package/providers/_builtin/cli/cursor-cli/provider.json +0 -37
- package/providers/_builtin/cli/cursor-cli/scripts/1.0/detect_status.js +0 -19
- package/providers/_builtin/cli/cursor-cli/scripts/1.0/parse_approval.js +0 -10
- package/providers/_builtin/cli/cursor-cli/scripts/1.0/parse_output.js +0 -48
- package/providers/_builtin/cli/cursor-cli/scripts/1.0/scripts.js +0 -7
- package/providers/_builtin/cli/gemini-cli/provider.json +0 -109
- package/providers/_builtin/cli/gemini-cli/scripts/1.0/detect_status.js +0 -26
- package/providers/_builtin/cli/gemini-cli/scripts/1.0/parse_approval.js +0 -22
- package/providers/_builtin/cli/gemini-cli/scripts/1.0/parse_output.js +0 -71
- package/providers/_builtin/cli/gemini-cli/scripts/1.0/scripts.js +0 -12
- package/providers/_builtin/cli/github-copilot-cli/provider.json +0 -37
- package/providers/_builtin/cli/github-copilot-cli/scripts/1.0/detect_status.js +0 -19
- package/providers/_builtin/cli/github-copilot-cli/scripts/1.0/parse_approval.js +0 -9
- package/providers/_builtin/cli/github-copilot-cli/scripts/1.0/parse_output.js +0 -48
- package/providers/_builtin/cli/github-copilot-cli/scripts/1.0/scripts.js +0 -7
- package/providers/_builtin/cli/goose-cli/provider.json +0 -37
- package/providers/_builtin/cli/goose-cli/scripts/1.0/detect_status.js +0 -20
- package/providers/_builtin/cli/goose-cli/scripts/1.0/parse_approval.js +0 -10
- package/providers/_builtin/cli/goose-cli/scripts/1.0/parse_output.js +0 -48
- package/providers/_builtin/cli/goose-cli/scripts/1.0/scripts.js +0 -7
- package/providers/_builtin/cli/opencode-cli/provider.json +0 -37
- package/providers/_builtin/cli/opencode-cli/scripts/1.0/detect_status.js +0 -15
- package/providers/_builtin/cli/opencode-cli/scripts/1.0/parse_approval.js +0 -9
- package/providers/_builtin/cli/opencode-cli/scripts/1.0/parse_output.js +0 -48
- package/providers/_builtin/cli/opencode-cli/scripts/1.0/scripts.js +0 -7
- package/providers/_builtin/docs/CDP_SELECTOR_GUIDE.md +0 -370
- package/providers/_builtin/docs/PROVIDER_GUIDE.md +0 -916
- package/providers/_builtin/extension/cline/provider.json +0 -37
- package/providers/_builtin/extension/cline/scripts/1.0/focus_editor.js +0 -48
- package/providers/_builtin/extension/cline/scripts/1.0/list_chats.js +0 -100
- package/providers/_builtin/extension/cline/scripts/1.0/list_models.js +0 -43
- package/providers/_builtin/extension/cline/scripts/1.0/list_modes.js +0 -35
- package/providers/_builtin/extension/cline/scripts/1.0/new_session.js +0 -85
- package/providers/_builtin/extension/cline/scripts/1.0/open_panel.js +0 -25
- package/providers/_builtin/extension/cline/scripts/1.0/read_chat.js +0 -270
- package/providers/_builtin/extension/cline/scripts/1.0/resolve_action.js +0 -83
- package/providers/_builtin/extension/cline/scripts/1.0/scripts.js +0 -82
- package/providers/_builtin/extension/cline/scripts/1.0/send_message.js +0 -95
- package/providers/_builtin/extension/cline/scripts/1.0/set_mode.js +0 -36
- package/providers/_builtin/extension/cline/scripts/1.0/set_model.js +0 -36
- package/providers/_builtin/extension/cline/scripts/1.0/switch_session.js +0 -206
- package/providers/_builtin/extension/codex/provider.json +0 -38
- package/providers/_builtin/extension/codex/scripts/1.0/click_conversation_webview.js +0 -24
- package/providers/_builtin/extension/codex/scripts/1.0/explore_chat_webview.js +0 -110
- package/providers/_builtin/extension/codex/scripts/1.0/explore_controls_webview.js +0 -75
- package/providers/_builtin/extension/codex/scripts/1.0/explore_dom.js +0 -58
- package/providers/_builtin/extension/codex/scripts/1.0/explore_dropdown_webview.js +0 -64
- package/providers/_builtin/extension/codex/scripts/1.0/inspect_code_webview.js +0 -55
- package/providers/_builtin/extension/codex/scripts/1.0/list_models.js +0 -63
- package/providers/_builtin/extension/codex/scripts/1.0/list_modes.js +0 -140
- package/providers/_builtin/extension/codex/scripts/1.0/message_structure_webview.js +0 -79
- package/providers/_builtin/extension/codex/scripts/1.0/new_session.js +0 -26
- package/providers/_builtin/extension/codex/scripts/1.0/read_chat.js +0 -516
- package/providers/_builtin/extension/codex/scripts/1.0/resolve_action.js +0 -82
- package/providers/_builtin/extension/codex/scripts/1.0/send_message.js +0 -42
- package/providers/_builtin/extension/codex/scripts/1.0/set_mode.js +0 -165
- package/providers/_builtin/extension/codex/scripts/1.0/set_model.js +0 -86
- package/providers/_builtin/extension/roo-code/provider.json +0 -37
- package/providers/_builtin/extension/roo-code/scripts/1.0/scripts.js +0 -82
- package/providers/_builtin/ide/antigravity/provider.json +0 -88
- package/providers/_builtin/ide/antigravity/scripts/1.0/focus_editor.js +0 -20
- package/providers/_builtin/ide/antigravity/scripts/1.0/list_chats.js +0 -137
- package/providers/_builtin/ide/antigravity/scripts/1.0/list_models.js +0 -61
- package/providers/_builtin/ide/antigravity/scripts/1.0/list_modes.js +0 -72
- package/providers/_builtin/ide/antigravity/scripts/1.0/new_session.js +0 -75
- package/providers/_builtin/ide/antigravity/scripts/1.0/read_chat.js +0 -352
- package/providers/_builtin/ide/antigravity/scripts/1.0/resolve_action.js +0 -63
- package/providers/_builtin/ide/antigravity/scripts/1.0/scripts.js +0 -67
- package/providers/_builtin/ide/antigravity/scripts/1.0/send_message.js +0 -56
- package/providers/_builtin/ide/antigravity/scripts/1.0/set_mode.js +0 -67
- package/providers/_builtin/ide/antigravity/scripts/1.0/set_model.js +0 -72
- package/providers/_builtin/ide/antigravity/scripts/1.0/switch_session.js +0 -114
- package/providers/_builtin/ide/cursor/provider.json +0 -70
- package/providers/_builtin/ide/cursor/scripts/1.0/dismiss_notification.js +0 -30
- package/providers/_builtin/ide/cursor/scripts/1.0/focus_editor.js +0 -13
- package/providers/_builtin/ide/cursor/scripts/1.0/list_models.js +0 -78
- package/providers/_builtin/ide/cursor/scripts/1.0/list_modes.js +0 -40
- package/providers/_builtin/ide/cursor/scripts/1.0/list_notifications.js +0 -23
- package/providers/_builtin/ide/cursor/scripts/1.0/list_sessions.js +0 -42
- package/providers/_builtin/ide/cursor/scripts/1.0/new_session.js +0 -20
- package/providers/_builtin/ide/cursor/scripts/1.0/open_panel.js +0 -23
- package/providers/_builtin/ide/cursor/scripts/1.0/read_chat.js +0 -318
- package/providers/_builtin/ide/cursor/scripts/1.0/resolve_action.js +0 -19
- package/providers/_builtin/ide/cursor/scripts/1.0/scripts.js +0 -78
- package/providers/_builtin/ide/cursor/scripts/1.0/send_message.js +0 -23
- package/providers/_builtin/ide/cursor/scripts/1.0/set_mode.js +0 -38
- package/providers/_builtin/ide/cursor/scripts/1.0/set_model.js +0 -81
- package/providers/_builtin/ide/cursor/scripts/1.0/switch_session.js +0 -28
- package/providers/_builtin/ide/kiro/provider.json +0 -68
- package/providers/_builtin/ide/kiro/scripts/1.0/focus_editor.js +0 -20
- package/providers/_builtin/ide/kiro/scripts/1.0/open_panel.js +0 -47
- package/providers/_builtin/ide/kiro/scripts/1.0/resolve_action.js +0 -54
- package/providers/_builtin/ide/kiro/scripts/1.0/send_message.js +0 -29
- package/providers/_builtin/ide/kiro/scripts/1.0/webview_dump_html.js +0 -1
- package/providers/_builtin/ide/kiro/scripts/1.0/webview_list_models.js +0 -42
- package/providers/_builtin/ide/kiro/scripts/1.0/webview_list_modes.js +0 -22
- package/providers/_builtin/ide/kiro/scripts/1.0/webview_list_sessions.js +0 -21
- package/providers/_builtin/ide/kiro/scripts/1.0/webview_new_session.js +0 -34
- package/providers/_builtin/ide/kiro/scripts/1.0/webview_read_chat.js +0 -161
- package/providers/_builtin/ide/kiro/scripts/1.0/webview_resolve_action.js +0 -62
- package/providers/_builtin/ide/kiro/scripts/1.0/webview_send_message.js +0 -94
- package/providers/_builtin/ide/kiro/scripts/1.0/webview_set_mode.js +0 -34
- package/providers/_builtin/ide/kiro/scripts/1.0/webview_set_model.js +0 -47
- package/providers/_builtin/ide/kiro/scripts/1.0/webview_switch_session.js +0 -26
- package/providers/_builtin/ide/pearai/.tmp/after_rich.json +0 -157
- package/providers/_builtin/ide/pearai/.tmp/after_rich_raw.json +0 -161
- package/providers/_builtin/ide/pearai/.tmp/after_switch.json +0 -592
- package/providers/_builtin/ide/pearai/.tmp/after_switch_raw.json +0 -596
- package/providers/_builtin/ide/pearai/.tmp/home_dump_raw.json +0 -176
- package/providers/_builtin/ide/pearai/.tmp/items_raw.json +0 -778
- package/providers/_builtin/ide/pearai/.tmp/webview_dump.json +0 -157
- package/providers/_builtin/ide/pearai/.tmp/webview_dump_raw.json +0 -161
- package/providers/_builtin/ide/pearai/provider.json +0 -71
- package/providers/_builtin/ide/pearai/scripts/1.0/focus_editor.js +0 -16
- package/providers/_builtin/ide/pearai/scripts/1.0/list_models.js +0 -45
- package/providers/_builtin/ide/pearai/scripts/1.0/list_modes.js +0 -44
- package/providers/_builtin/ide/pearai/scripts/1.0/list_sessions.js +0 -93
- package/providers/_builtin/ide/pearai/scripts/1.0/new_session.js +0 -38
- package/providers/_builtin/ide/pearai/scripts/1.0/open_panel.js +0 -23
- package/providers/_builtin/ide/pearai/scripts/1.0/read_chat.js +0 -169
- package/providers/_builtin/ide/pearai/scripts/1.0/resolve_action.js +0 -60
- package/providers/_builtin/ide/pearai/scripts/1.0/scripts.js +0 -111
- package/providers/_builtin/ide/pearai/scripts/1.0/send_message.js +0 -104
- package/providers/_builtin/ide/pearai/scripts/1.0/set_mode.js +0 -51
- package/providers/_builtin/ide/pearai/scripts/1.0/set_model.js +0 -54
- package/providers/_builtin/ide/pearai/scripts/1.0/switch_session.js +0 -81
- package/providers/_builtin/ide/trae/provider.json +0 -72
- package/providers/_builtin/ide/trae/scripts/1.0/focus_editor.js +0 -20
- package/providers/_builtin/ide/trae/scripts/1.0/list_chats.js +0 -24
- package/providers/_builtin/ide/trae/scripts/1.0/list_models.js +0 -39
- package/providers/_builtin/ide/trae/scripts/1.0/list_modes.js +0 -39
- package/providers/_builtin/ide/trae/scripts/1.0/new_session.js +0 -30
- package/providers/_builtin/ide/trae/scripts/1.0/open_panel.js +0 -44
- package/providers/_builtin/ide/trae/scripts/1.0/read_chat.js +0 -113
- package/providers/_builtin/ide/trae/scripts/1.0/resolve_action.js +0 -54
- package/providers/_builtin/ide/trae/scripts/1.0/scripts.js +0 -82
- package/providers/_builtin/ide/trae/scripts/1.0/send_message.js +0 -69
- package/providers/_builtin/ide/trae/scripts/1.0/set_mode.js +0 -15
- package/providers/_builtin/ide/trae/scripts/1.0/set_model.js +0 -15
- package/providers/_builtin/ide/trae/scripts/1.0/switch_session.js +0 -23
- package/providers/_builtin/ide/vscode/provider.json +0 -70
- package/providers/_builtin/ide/vscode-insiders/provider.json +0 -68
- package/providers/_builtin/ide/vscodium/provider.json +0 -69
- package/providers/_builtin/ide/windsurf/provider.json +0 -57
- package/providers/_builtin/ide/windsurf/scripts/1.0/focus_editor.js +0 -36
- package/providers/_builtin/ide/windsurf/scripts/1.0/list_chats.js +0 -23
- package/providers/_builtin/ide/windsurf/scripts/1.0/list_models.js +0 -56
- package/providers/_builtin/ide/windsurf/scripts/1.0/list_modes.js +0 -63
- package/providers/_builtin/ide/windsurf/scripts/1.0/list_sessions.js +0 -79
- package/providers/_builtin/ide/windsurf/scripts/1.0/new_session.js +0 -58
- package/providers/_builtin/ide/windsurf/scripts/1.0/open_panel.js +0 -67
- package/providers/_builtin/ide/windsurf/scripts/1.0/read_chat.js +0 -253
- package/providers/_builtin/ide/windsurf/scripts/1.0/resolve_action.js +0 -82
- package/providers/_builtin/ide/windsurf/scripts/1.0/scripts.js +0 -82
- package/providers/_builtin/ide/windsurf/scripts/1.0/send_message.js +0 -20
- package/providers/_builtin/ide/windsurf/scripts/1.0/set_mode.js +0 -43
- package/providers/_builtin/ide/windsurf/scripts/1.0/set_model.js +0 -49
- package/providers/_builtin/ide/windsurf/scripts/1.0/switch_session.js +0 -82
- package/providers/_builtin/ide/windsurf/scripts/1.0.bak/focus_editor.js +0 -30
- package/providers/_builtin/ide/windsurf/scripts/1.0.bak/list_chats.js +0 -117
- package/providers/_builtin/ide/windsurf/scripts/1.0.bak/list_models.js +0 -39
- package/providers/_builtin/ide/windsurf/scripts/1.0.bak/list_modes.js +0 -39
- package/providers/_builtin/ide/windsurf/scripts/1.0.bak/new_session.js +0 -69
- package/providers/_builtin/ide/windsurf/scripts/1.0.bak/open_panel.js +0 -58
- package/providers/_builtin/ide/windsurf/scripts/1.0.bak/read_chat.js +0 -315
- package/providers/_builtin/ide/windsurf/scripts/1.0.bak/resolve_action.js +0 -68
- package/providers/_builtin/ide/windsurf/scripts/1.0.bak/scripts.js +0 -82
- package/providers/_builtin/ide/windsurf/scripts/1.0.bak/send_message.js +0 -87
- package/providers/_builtin/ide/windsurf/scripts/1.0.bak/set_mode.js +0 -15
- package/providers/_builtin/ide/windsurf/scripts/1.0.bak/set_model.js +0 -15
- package/providers/_builtin/ide/windsurf/scripts/1.0.bak/switch_session.js +0 -58
- package/providers/_builtin/registry.json +0 -376
- package/providers/_builtin/validate.js +0 -156
package/dist/index.js
CHANGED
|
@@ -750,6 +750,36 @@ function promptLikelyVisible(screenText, promptSnippet) {
|
|
|
750
750
|
).length;
|
|
751
751
|
return matched >= required;
|
|
752
752
|
}
|
|
753
|
+
function splitHistoryLines(text) {
|
|
754
|
+
return String(text || "").split("\n").map((line) => line.replace(/\s+$/, ""));
|
|
755
|
+
}
|
|
756
|
+
function normalizeHistoryLine(line) {
|
|
757
|
+
return String(line || "").replace(/\s+/g, " ").trim();
|
|
758
|
+
}
|
|
759
|
+
function mergeTerminalHistory(existing, snapshot) {
|
|
760
|
+
const next = String(snapshot || "").trim();
|
|
761
|
+
if (!next) return existing;
|
|
762
|
+
const prev = String(existing || "").trim();
|
|
763
|
+
if (!prev) return next;
|
|
764
|
+
if (prev === next || prev.endsWith(next)) return prev;
|
|
765
|
+
const prevLines = splitHistoryLines(prev);
|
|
766
|
+
const nextLines = splitHistoryLines(next);
|
|
767
|
+
const prevNorm = prevLines.map(normalizeHistoryLine);
|
|
768
|
+
const nextNorm = nextLines.map(normalizeHistoryLine);
|
|
769
|
+
const maxOverlap = Math.min(prevLines.length, nextLines.length);
|
|
770
|
+
for (let overlap = maxOverlap; overlap >= 1; overlap -= 1) {
|
|
771
|
+
const prevTail = prevNorm.slice(prevNorm.length - overlap);
|
|
772
|
+
const nextHead = nextNorm.slice(0, overlap);
|
|
773
|
+
if (prevTail.every((line, index) => line === nextHead[index])) {
|
|
774
|
+
return [...prevLines, ...nextLines.slice(overlap)].join("\n").trim();
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
const compactPrev = prevNorm.join("\n");
|
|
778
|
+
const compactNext = nextNorm.join("\n");
|
|
779
|
+
if (compactPrev.includes(compactNext)) return prev;
|
|
780
|
+
return `${prev}
|
|
781
|
+
${next}`.trim();
|
|
782
|
+
}
|
|
753
783
|
function parsePatternEntry(x) {
|
|
754
784
|
if (x instanceof RegExp) return x;
|
|
755
785
|
if (x && typeof x === "object" && typeof x.source === "string") {
|
|
@@ -826,6 +856,7 @@ var init_provider_cli_adapter = __esm({
|
|
|
826
856
|
this.approvalKeys = rawKeys && typeof rawKeys === "object" ? rawKeys : {};
|
|
827
857
|
this.sendDelayMs = typeof provider.sendDelayMs === "number" ? Math.max(0, provider.sendDelayMs) : 0;
|
|
828
858
|
this.sendKey = typeof provider.sendKey === "string" && provider.sendKey.length > 0 ? provider.sendKey : "\r";
|
|
859
|
+
this.submitStrategy = provider.submitStrategy === "immediate" ? "immediate" : "wait_for_echo";
|
|
829
860
|
this.cliScripts = provider.scripts || {};
|
|
830
861
|
const scriptNames = Object.keys(this.cliScripts).filter((k) => typeof this.cliScripts[k] === "function");
|
|
831
862
|
if (scriptNames.length > 0) {
|
|
@@ -840,6 +871,7 @@ var init_provider_cli_adapter = __esm({
|
|
|
840
871
|
provider;
|
|
841
872
|
ptyProcess = null;
|
|
842
873
|
messages = [];
|
|
874
|
+
committedMessages = [];
|
|
843
875
|
structuredMessages = [];
|
|
844
876
|
currentStatus = "starting";
|
|
845
877
|
onStatusChange = null;
|
|
@@ -886,8 +918,35 @@ var init_provider_cli_adapter = __esm({
|
|
|
886
918
|
accumulatedRawBuffer = "";
|
|
887
919
|
/** Current visible terminal screen snapshot */
|
|
888
920
|
terminalScreen = new TerminalScreen(40, 120);
|
|
921
|
+
/** Rolling append-only terminal transcript built from screen snapshots */
|
|
922
|
+
terminalHistory = "";
|
|
889
923
|
/** Max accumulated buffer size (last 50KB) */
|
|
890
924
|
static MAX_ACCUMULATED_BUFFER = 5e4;
|
|
925
|
+
currentTurnScope = null;
|
|
926
|
+
syncMessageViews() {
|
|
927
|
+
this.messages = [...this.committedMessages];
|
|
928
|
+
this.structuredMessages = [...this.committedMessages];
|
|
929
|
+
}
|
|
930
|
+
sliceFromOffset(text, start) {
|
|
931
|
+
if (!text) return "";
|
|
932
|
+
if (!Number.isFinite(start) || start <= 0) return text;
|
|
933
|
+
if (start >= text.length) return "";
|
|
934
|
+
return text.slice(start);
|
|
935
|
+
}
|
|
936
|
+
buildParseInput(baseMessages, partialResponse, scope) {
|
|
937
|
+
const buffer = scope ? this.sliceFromOffset(this.terminalHistory, scope.terminalHistoryStart) || this.sliceFromOffset(this.accumulatedBuffer, scope.bufferStart) || this.accumulatedBuffer : this.accumulatedBuffer;
|
|
938
|
+
const rawBuffer = scope ? this.sliceFromOffset(this.accumulatedRawBuffer, scope.rawBufferStart) || this.accumulatedRawBuffer : this.accumulatedRawBuffer;
|
|
939
|
+
const terminalHistory = scope ? this.sliceFromOffset(this.terminalHistory, scope.terminalHistoryStart) || this.terminalHistory : this.terminalHistory;
|
|
940
|
+
return {
|
|
941
|
+
buffer,
|
|
942
|
+
rawBuffer,
|
|
943
|
+
recentBuffer: buffer.slice(-1e3) || this.recentOutputBuffer,
|
|
944
|
+
screenText: this.terminalScreen.getText(),
|
|
945
|
+
terminalHistory,
|
|
946
|
+
messages: [...baseMessages],
|
|
947
|
+
partialResponse
|
|
948
|
+
};
|
|
949
|
+
}
|
|
891
950
|
setStatus(status, trigger) {
|
|
892
951
|
const prev = this.currentStatus;
|
|
893
952
|
if (prev === status) return;
|
|
@@ -902,6 +961,7 @@ var init_provider_cli_adapter = __esm({
|
|
|
902
961
|
approvalKeys;
|
|
903
962
|
sendDelayMs;
|
|
904
963
|
sendKey;
|
|
964
|
+
submitStrategy;
|
|
905
965
|
/** Inject CLI scripts after construction (e.g. when resolved by ProviderLoader) */
|
|
906
966
|
setCliScripts(scripts) {
|
|
907
967
|
this.cliScripts = scripts;
|
|
@@ -997,6 +1057,8 @@ var init_provider_cli_adapter = __esm({
|
|
|
997
1057
|
this.startupParseGate = true;
|
|
998
1058
|
this.startupBuffer = "";
|
|
999
1059
|
this.terminalScreen.reset(40, 120);
|
|
1060
|
+
this.terminalHistory = "";
|
|
1061
|
+
this.currentTurnScope = null;
|
|
1000
1062
|
this.ready = false;
|
|
1001
1063
|
this.setStatus("idle", "pty_ready");
|
|
1002
1064
|
this.onStatusChange?.();
|
|
@@ -1008,6 +1070,7 @@ var init_provider_cli_adapter = __esm({
|
|
|
1008
1070
|
this.ptyProcess?.write("\x1B[1;1R");
|
|
1009
1071
|
}
|
|
1010
1072
|
this.terminalScreen.write(rawData);
|
|
1073
|
+
this.terminalHistory = mergeTerminalHistory(this.terminalHistory, this.terminalScreen.getText());
|
|
1011
1074
|
const cleanData = stripAnsi(rawData);
|
|
1012
1075
|
if (this.isWaitingForResponse && cleanData) {
|
|
1013
1076
|
this.responseBuffer = (this.responseBuffer + cleanData).slice(-8e3);
|
|
@@ -1152,6 +1215,7 @@ var init_provider_cli_adapter = __esm({
|
|
|
1152
1215
|
finishResponse() {
|
|
1153
1216
|
if (this.submitPendingUntil > Date.now()) return;
|
|
1154
1217
|
if (this.responseSettleIgnoreUntil > Date.now()) return;
|
|
1218
|
+
this.commitCurrentTranscript();
|
|
1155
1219
|
if (this.responseTimeout) {
|
|
1156
1220
|
clearTimeout(this.responseTimeout);
|
|
1157
1221
|
this.responseTimeout = null;
|
|
@@ -1173,10 +1237,58 @@ var init_provider_cli_adapter = __esm({
|
|
|
1173
1237
|
this.responseSettleIgnoreUntil = 0;
|
|
1174
1238
|
this.submitRetryUsed = false;
|
|
1175
1239
|
this.submitRetryPromptSnippet = "";
|
|
1240
|
+
this.currentTurnScope = null;
|
|
1176
1241
|
this.activeModal = null;
|
|
1177
1242
|
this.setStatus("idle", "response_finished");
|
|
1178
1243
|
this.onStatusChange?.();
|
|
1179
1244
|
}
|
|
1245
|
+
commitCurrentTranscript() {
|
|
1246
|
+
const baseMessages = [...this.committedMessages];
|
|
1247
|
+
const parsed = this.parseCurrentTranscript(baseMessages, "", this.currentTurnScope);
|
|
1248
|
+
if (parsed && Array.isArray(parsed.messages) && parsed.messages.length > 0) {
|
|
1249
|
+
const parsedMessages = parsed.messages.filter((m) => m && (m.role === "user" || m.role === "assistant")).map((m) => ({
|
|
1250
|
+
role: m.role,
|
|
1251
|
+
content: typeof m.content === "string" ? m.content : String(m.content || ""),
|
|
1252
|
+
timestamp: m.timestamp
|
|
1253
|
+
}));
|
|
1254
|
+
const latestAssistant = [...parsedMessages].reverse().find((m) => m.role === "assistant" && m.content.trim());
|
|
1255
|
+
if (latestAssistant) {
|
|
1256
|
+
LOG.info("CLI", `[${this.cliType}] commitCurrentTranscript parsed assistant len=${latestAssistant.content.length} scopePrompt=${JSON.stringify(this.currentTurnScope?.prompt || "").slice(0, 120)}`);
|
|
1257
|
+
const nextMessages = [...baseMessages];
|
|
1258
|
+
const last2 = nextMessages[nextMessages.length - 1];
|
|
1259
|
+
if (last2?.role === "assistant") {
|
|
1260
|
+
last2.content = latestAssistant.content;
|
|
1261
|
+
last2.timestamp = latestAssistant.timestamp || last2.timestamp;
|
|
1262
|
+
} else if (last2?.role === "user") {
|
|
1263
|
+
nextMessages.push({
|
|
1264
|
+
role: "assistant",
|
|
1265
|
+
content: latestAssistant.content,
|
|
1266
|
+
timestamp: latestAssistant.timestamp || Date.now()
|
|
1267
|
+
});
|
|
1268
|
+
} else {
|
|
1269
|
+
nextMessages.push({
|
|
1270
|
+
role: "assistant",
|
|
1271
|
+
content: latestAssistant.content,
|
|
1272
|
+
timestamp: latestAssistant.timestamp || Date.now()
|
|
1273
|
+
});
|
|
1274
|
+
}
|
|
1275
|
+
this.committedMessages = nextMessages;
|
|
1276
|
+
this.syncMessageViews();
|
|
1277
|
+
return;
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
const fallback = String(this.responseBuffer || "").trim();
|
|
1281
|
+
LOG.info("CLI", `[${this.cliType}] commitCurrentTranscript fallback len=${fallback.length} scopePrompt=${JSON.stringify(this.currentTurnScope?.prompt || "").slice(0, 120)}`);
|
|
1282
|
+
if (!fallback) return;
|
|
1283
|
+
const last = baseMessages[baseMessages.length - 1];
|
|
1284
|
+
if (last?.role === "assistant") {
|
|
1285
|
+
last.content = fallback;
|
|
1286
|
+
} else {
|
|
1287
|
+
baseMessages.push({ role: "assistant", content: fallback, timestamp: Date.now() });
|
|
1288
|
+
}
|
|
1289
|
+
this.committedMessages = baseMessages;
|
|
1290
|
+
this.syncMessageViews();
|
|
1291
|
+
}
|
|
1180
1292
|
// ─── Script Execution ──────────────────────────
|
|
1181
1293
|
runDetectStatus(text) {
|
|
1182
1294
|
if (!this.cliScripts?.detectStatus) return null;
|
|
@@ -1206,24 +1318,12 @@ var init_provider_cli_adapter = __esm({
|
|
|
1206
1318
|
}
|
|
1207
1319
|
// ─── Public API (CliAdapter) ───────────────────
|
|
1208
1320
|
getStatus() {
|
|
1209
|
-
const scriptResult = this.getScriptParsedStatus();
|
|
1210
|
-
if (scriptResult) {
|
|
1211
|
-
return {
|
|
1212
|
-
status: this.currentStatus,
|
|
1213
|
-
messages: (scriptResult.messages || []).map((m) => ({
|
|
1214
|
-
role: m.role,
|
|
1215
|
-
content: m.content,
|
|
1216
|
-
timestamp: m.timestamp
|
|
1217
|
-
})),
|
|
1218
|
-
workingDir: this.workingDir,
|
|
1219
|
-
activeModal: this.activeModal
|
|
1220
|
-
};
|
|
1221
|
-
}
|
|
1222
1321
|
return {
|
|
1223
1322
|
status: this.currentStatus,
|
|
1224
|
-
messages: [...this.
|
|
1323
|
+
messages: [...this.committedMessages],
|
|
1225
1324
|
workingDir: this.workingDir,
|
|
1226
|
-
activeModal: this.activeModal
|
|
1325
|
+
activeModal: this.activeModal,
|
|
1326
|
+
terminalHistory: this.terminalHistory
|
|
1227
1327
|
};
|
|
1228
1328
|
}
|
|
1229
1329
|
/**
|
|
@@ -1231,31 +1331,32 @@ var init_provider_cli_adapter = __esm({
|
|
|
1231
1331
|
* Called by command handler / dashboard for rich content rendering.
|
|
1232
1332
|
*/
|
|
1233
1333
|
getScriptParsedStatus() {
|
|
1334
|
+
const messages = [...this.committedMessages];
|
|
1335
|
+
return {
|
|
1336
|
+
id: "cli_session",
|
|
1337
|
+
status: this.currentStatus,
|
|
1338
|
+
title: this.cliName,
|
|
1339
|
+
terminalHistory: this.terminalHistory,
|
|
1340
|
+
messages: messages.slice(-50).map((message, index) => ({
|
|
1341
|
+
id: `msg_${index}`,
|
|
1342
|
+
role: message.role,
|
|
1343
|
+
content: message.content,
|
|
1344
|
+
timestamp: message.timestamp,
|
|
1345
|
+
index,
|
|
1346
|
+
kind: "standard"
|
|
1347
|
+
})),
|
|
1348
|
+
activeModal: this.activeModal
|
|
1349
|
+
};
|
|
1350
|
+
}
|
|
1351
|
+
parseCurrentTranscript(baseMessages, partialResponse, scope) {
|
|
1234
1352
|
if (!this.cliScripts?.parseOutput) return null;
|
|
1235
1353
|
try {
|
|
1236
|
-
const input =
|
|
1237
|
-
|
|
1238
|
-
rawBuffer: this.accumulatedRawBuffer,
|
|
1239
|
-
recentBuffer: this.recentOutputBuffer,
|
|
1240
|
-
screenText: this.terminalScreen.getText(),
|
|
1241
|
-
messages: [...this.structuredMessages.length > 0 ? this.structuredMessages : this.messages],
|
|
1242
|
-
partialResponse: this.responseBuffer
|
|
1243
|
-
};
|
|
1244
|
-
const result = this.cliScripts.parseOutput(input);
|
|
1245
|
-
if (result && typeof result === "object") {
|
|
1246
|
-
if (Array.isArray(result.messages)) {
|
|
1247
|
-
this.structuredMessages = result.messages.map((m) => ({
|
|
1248
|
-
role: m.role,
|
|
1249
|
-
content: m.content,
|
|
1250
|
-
timestamp: m.timestamp
|
|
1251
|
-
}));
|
|
1252
|
-
}
|
|
1253
|
-
return result;
|
|
1254
|
-
}
|
|
1354
|
+
const input = this.buildParseInput(baseMessages, partialResponse, scope);
|
|
1355
|
+
return this.cliScripts.parseOutput(input);
|
|
1255
1356
|
} catch (e) {
|
|
1256
1357
|
LOG.warn("CLI", `[${this.cliType}] parseOutput error: ${e.message}`);
|
|
1358
|
+
return null;
|
|
1257
1359
|
}
|
|
1258
|
-
return null;
|
|
1259
1360
|
}
|
|
1260
1361
|
/** Whether this adapter has CLI scripts loaded */
|
|
1261
1362
|
hasCliScripts() {
|
|
@@ -1290,15 +1391,23 @@ ${data.message || ""}`.trim();
|
|
|
1290
1391
|
if (this.startupParseGate) {
|
|
1291
1392
|
const deadline = Date.now() + 1e4;
|
|
1292
1393
|
while (this.startupParseGate && Date.now() < deadline) {
|
|
1293
|
-
await new Promise((
|
|
1394
|
+
await new Promise((resolve7) => setTimeout(resolve7, 50));
|
|
1294
1395
|
}
|
|
1295
1396
|
}
|
|
1296
1397
|
if (!this.ready) throw new Error(`${this.cliName} not ready (status: ${this.currentStatus})`);
|
|
1297
1398
|
if (this.isWaitingForResponse) return;
|
|
1298
|
-
this.
|
|
1299
|
-
this.
|
|
1399
|
+
this.committedMessages.push({ role: "user", content: text, timestamp: Date.now() });
|
|
1400
|
+
this.syncMessageViews();
|
|
1300
1401
|
this.isWaitingForResponse = true;
|
|
1301
1402
|
this.responseBuffer = "";
|
|
1403
|
+
this.currentTurnScope = {
|
|
1404
|
+
prompt: text,
|
|
1405
|
+
startedAt: Date.now(),
|
|
1406
|
+
bufferStart: this.accumulatedBuffer.length,
|
|
1407
|
+
rawBufferStart: this.accumulatedRawBuffer.length,
|
|
1408
|
+
terminalHistoryStart: this.terminalHistory.length
|
|
1409
|
+
};
|
|
1410
|
+
LOG.info("CLI", `[${this.cliType}] sendMessage turn scope buffer=${this.currentTurnScope.bufferStart} raw=${this.currentTurnScope.rawBufferStart} terminal=${this.currentTurnScope.terminalHistoryStart} prompt=${JSON.stringify(text).slice(0, 120)}`);
|
|
1302
1411
|
this.submitRetryUsed = false;
|
|
1303
1412
|
this.submitRetryPromptSnippet = extractPromptRetrySnippet(text);
|
|
1304
1413
|
const normalizedPromptSnippet = normalizePromptText(this.submitRetryPromptSnippet);
|
|
@@ -1318,10 +1427,12 @@ ${data.message || ""}`.trim();
|
|
|
1318
1427
|
this.responseSettleIgnoreUntil = Date.now() + submitDelayMs + this.timeouts.outputSettle + 250;
|
|
1319
1428
|
this.setStatus("generating", "sendMessage");
|
|
1320
1429
|
this.onStatusChange?.();
|
|
1321
|
-
|
|
1322
|
-
this.
|
|
1323
|
-
|
|
1324
|
-
|
|
1430
|
+
const startResponseTimeout = () => {
|
|
1431
|
+
if (this.responseTimeout) clearTimeout(this.responseTimeout);
|
|
1432
|
+
this.responseTimeout = setTimeout(() => {
|
|
1433
|
+
if (this.isWaitingForResponse) this.finishResponse();
|
|
1434
|
+
}, this.timeouts.maxResponse);
|
|
1435
|
+
};
|
|
1325
1436
|
const submit = () => {
|
|
1326
1437
|
if (!this.ptyProcess) return;
|
|
1327
1438
|
this.submitPendingUntil = 0;
|
|
@@ -1344,10 +1455,30 @@ ${data.message || ""}`.trim();
|
|
|
1344
1455
|
this.submitRetryTimer = setTimeout(() => retrySubmitIfStuck(attempt + 1), retryDelayMs);
|
|
1345
1456
|
};
|
|
1346
1457
|
this.submitRetryTimer = setTimeout(() => retrySubmitIfStuck(1), retryDelayMs);
|
|
1347
|
-
|
|
1348
|
-
if (this.isWaitingForResponse) this.finishResponse();
|
|
1349
|
-
}, this.timeouts.maxResponse);
|
|
1458
|
+
startResponseTimeout();
|
|
1350
1459
|
};
|
|
1460
|
+
if (this.submitStrategy === "immediate") {
|
|
1461
|
+
this.submitPendingUntil = 0;
|
|
1462
|
+
this.ptyProcess.write(text + this.sendKey);
|
|
1463
|
+
this.submitRetryTimer = setTimeout(() => {
|
|
1464
|
+
this.submitRetryTimer = null;
|
|
1465
|
+
if (!this.ptyProcess || !this.isWaitingForResponse || this.submitRetryUsed) return;
|
|
1466
|
+
if (this.currentStatus !== "generating") return;
|
|
1467
|
+
if ((this.responseBuffer || "").trim()) return;
|
|
1468
|
+
const screenText = this.terminalScreen.getText();
|
|
1469
|
+
if (!promptLikelyVisible(screenText, normalizedPromptSnippet)) return;
|
|
1470
|
+
LOG.info("CLI", `[${this.cliType}] Retrying submit key for stuck prompt (attempt 1)`);
|
|
1471
|
+
this.responseSettleIgnoreUntil = Date.now() + this.timeouts.outputSettle + 400;
|
|
1472
|
+
this.ptyProcess.write(this.sendKey);
|
|
1473
|
+
this.submitRetryUsed = true;
|
|
1474
|
+
}, retryDelayMs);
|
|
1475
|
+
startResponseTimeout();
|
|
1476
|
+
return;
|
|
1477
|
+
}
|
|
1478
|
+
if (submitDelayMs > 0) {
|
|
1479
|
+
this.submitPendingUntil = Date.now() + submitDelayMs;
|
|
1480
|
+
}
|
|
1481
|
+
this.ptyProcess.write(text);
|
|
1351
1482
|
const submitStartedAt = Date.now();
|
|
1352
1483
|
let lastNormalizedScreen = "";
|
|
1353
1484
|
let lastScreenChangeAt = submitStartedAt;
|
|
@@ -1414,10 +1545,12 @@ ${data.message || ""}`.trim();
|
|
|
1414
1545
|
}
|
|
1415
1546
|
}
|
|
1416
1547
|
clearHistory() {
|
|
1417
|
-
this.
|
|
1418
|
-
this.
|
|
1548
|
+
this.committedMessages = [];
|
|
1549
|
+
this.syncMessageViews();
|
|
1419
1550
|
this.accumulatedBuffer = "";
|
|
1420
1551
|
this.accumulatedRawBuffer = "";
|
|
1552
|
+
this.terminalHistory = "";
|
|
1553
|
+
this.currentTurnScope = null;
|
|
1421
1554
|
this.submitRetryUsed = false;
|
|
1422
1555
|
this.submitRetryPromptSnippet = "";
|
|
1423
1556
|
this.terminalScreen.reset();
|
|
@@ -1471,9 +1604,12 @@ ${data.message || ""}`.trim();
|
|
|
1471
1604
|
spawnAt: this.spawnAt,
|
|
1472
1605
|
workingDir: this.workingDir,
|
|
1473
1606
|
messages: this.messages.slice(-20),
|
|
1607
|
+
committedMessages: this.committedMessages.slice(-20),
|
|
1474
1608
|
structuredMessages: this.structuredMessages.slice(-20),
|
|
1475
|
-
messageCount: this.
|
|
1609
|
+
messageCount: this.committedMessages.length,
|
|
1476
1610
|
screenText: this.terminalScreen.getText().slice(-4e3),
|
|
1611
|
+
terminalHistory: this.terminalHistory.slice(-8e3),
|
|
1612
|
+
currentTurnScope: this.currentTurnScope,
|
|
1477
1613
|
startupBuffer: this.startupBuffer.slice(-4e3),
|
|
1478
1614
|
recentOutputBuffer: this.recentOutputBuffer.slice(-500),
|
|
1479
1615
|
settledBuffer: this.settledBuffer.slice(-500),
|
|
@@ -1486,6 +1622,7 @@ ${data.message || ""}`.trim();
|
|
|
1486
1622
|
lastApprovalResolvedAt: this.lastApprovalResolvedAt,
|
|
1487
1623
|
sendDelayMs: this.sendDelayMs,
|
|
1488
1624
|
sendKey: this.sendKey,
|
|
1625
|
+
submitStrategy: this.submitStrategy,
|
|
1489
1626
|
submitPendingUntil: this.submitPendingUntil,
|
|
1490
1627
|
responseSettleIgnoreUntil: this.responseSettleIgnoreUntil,
|
|
1491
1628
|
resizeSuppressUntil: this.resizeSuppressUntil,
|
|
@@ -1713,15 +1850,15 @@ async function detectIDEs() {
|
|
|
1713
1850
|
var import_child_process2 = require("child_process");
|
|
1714
1851
|
var os2 = __toESM(require("os"));
|
|
1715
1852
|
function execAsync(cmd, timeoutMs = 5e3) {
|
|
1716
|
-
return new Promise((
|
|
1853
|
+
return new Promise((resolve7) => {
|
|
1717
1854
|
const child = (0, import_child_process2.exec)(cmd, { encoding: "utf-8", timeout: timeoutMs }, (err, stdout) => {
|
|
1718
1855
|
if (err || !stdout?.trim()) {
|
|
1719
|
-
|
|
1856
|
+
resolve7(null);
|
|
1720
1857
|
} else {
|
|
1721
|
-
|
|
1858
|
+
resolve7(stdout.trim());
|
|
1722
1859
|
}
|
|
1723
1860
|
});
|
|
1724
|
-
child.on("error", () =>
|
|
1861
|
+
child.on("error", () => resolve7(null));
|
|
1725
1862
|
});
|
|
1726
1863
|
}
|
|
1727
1864
|
async function detectCLIs(providerLoader) {
|
|
@@ -1876,7 +2013,7 @@ var DaemonCdpManager = class {
|
|
|
1876
2013
|
* Returns multiple entries if multiple IDE windows are open on same port
|
|
1877
2014
|
*/
|
|
1878
2015
|
static listAllTargets(port) {
|
|
1879
|
-
return new Promise((
|
|
2016
|
+
return new Promise((resolve7) => {
|
|
1880
2017
|
const req = http.get(`http://127.0.0.1:${port}/json`, (res) => {
|
|
1881
2018
|
let data = "";
|
|
1882
2019
|
res.on("data", (chunk) => data += chunk.toString());
|
|
@@ -1892,16 +2029,16 @@ var DaemonCdpManager = class {
|
|
|
1892
2029
|
(t) => !isNonMain(t.title || "") && t.url?.includes("workbench.html") && !t.url?.includes("agent")
|
|
1893
2030
|
);
|
|
1894
2031
|
const fallbackPages = pages.filter((t) => !isNonMain(t.title || ""));
|
|
1895
|
-
|
|
2032
|
+
resolve7(mainPages.length > 0 ? mainPages : fallbackPages);
|
|
1896
2033
|
} catch {
|
|
1897
|
-
|
|
2034
|
+
resolve7([]);
|
|
1898
2035
|
}
|
|
1899
2036
|
});
|
|
1900
2037
|
});
|
|
1901
|
-
req.on("error", () =>
|
|
2038
|
+
req.on("error", () => resolve7([]));
|
|
1902
2039
|
req.setTimeout(2e3, () => {
|
|
1903
2040
|
req.destroy();
|
|
1904
|
-
|
|
2041
|
+
resolve7([]);
|
|
1905
2042
|
});
|
|
1906
2043
|
});
|
|
1907
2044
|
}
|
|
@@ -1941,7 +2078,7 @@ var DaemonCdpManager = class {
|
|
|
1941
2078
|
}
|
|
1942
2079
|
}
|
|
1943
2080
|
findTargetOnPort(port) {
|
|
1944
|
-
return new Promise((
|
|
2081
|
+
return new Promise((resolve7) => {
|
|
1945
2082
|
const req = http.get(`http://127.0.0.1:${port}/json`, (res) => {
|
|
1946
2083
|
let data = "";
|
|
1947
2084
|
res.on("data", (chunk) => data += chunk.toString());
|
|
@@ -1952,7 +2089,7 @@ var DaemonCdpManager = class {
|
|
|
1952
2089
|
(t) => (t.type === "page" || t.type === "browser" || t.type === "Page") && t.webSocketDebuggerUrl
|
|
1953
2090
|
);
|
|
1954
2091
|
if (pages.length === 0) {
|
|
1955
|
-
|
|
2092
|
+
resolve7(targets.find((t) => t.webSocketDebuggerUrl) || null);
|
|
1956
2093
|
return;
|
|
1957
2094
|
}
|
|
1958
2095
|
const mainPages = pages.filter((t) => !this.isNonMainTitle(t.title || ""));
|
|
@@ -1962,24 +2099,24 @@ var DaemonCdpManager = class {
|
|
|
1962
2099
|
const specific = list.find((t) => t.id === this._targetId);
|
|
1963
2100
|
if (specific) {
|
|
1964
2101
|
this._pageTitle = specific.title || "";
|
|
1965
|
-
|
|
2102
|
+
resolve7(specific);
|
|
1966
2103
|
} else {
|
|
1967
2104
|
this.log(`[CDP] Target ${this._targetId} not found in page list`);
|
|
1968
|
-
|
|
2105
|
+
resolve7(null);
|
|
1969
2106
|
}
|
|
1970
2107
|
return;
|
|
1971
2108
|
}
|
|
1972
2109
|
this._pageTitle = list[0]?.title || "";
|
|
1973
|
-
|
|
2110
|
+
resolve7(list[0]);
|
|
1974
2111
|
} catch {
|
|
1975
|
-
|
|
2112
|
+
resolve7(null);
|
|
1976
2113
|
}
|
|
1977
2114
|
});
|
|
1978
2115
|
});
|
|
1979
|
-
req.on("error", () =>
|
|
2116
|
+
req.on("error", () => resolve7(null));
|
|
1980
2117
|
req.setTimeout(2e3, () => {
|
|
1981
2118
|
req.destroy();
|
|
1982
|
-
|
|
2119
|
+
resolve7(null);
|
|
1983
2120
|
});
|
|
1984
2121
|
});
|
|
1985
2122
|
}
|
|
@@ -1990,7 +2127,7 @@ var DaemonCdpManager = class {
|
|
|
1990
2127
|
this.extensionProviders = providers;
|
|
1991
2128
|
}
|
|
1992
2129
|
connectToTarget(wsUrl) {
|
|
1993
|
-
return new Promise((
|
|
2130
|
+
return new Promise((resolve7) => {
|
|
1994
2131
|
this.ws = new import_ws.default(wsUrl);
|
|
1995
2132
|
this.ws.on("open", async () => {
|
|
1996
2133
|
this._connected = true;
|
|
@@ -2000,17 +2137,17 @@ var DaemonCdpManager = class {
|
|
|
2000
2137
|
}
|
|
2001
2138
|
this.connectBrowserWs().catch(() => {
|
|
2002
2139
|
});
|
|
2003
|
-
|
|
2140
|
+
resolve7(true);
|
|
2004
2141
|
});
|
|
2005
2142
|
this.ws.on("message", (data) => {
|
|
2006
2143
|
try {
|
|
2007
2144
|
const msg = JSON.parse(data.toString());
|
|
2008
2145
|
if (msg.id && this.pending.has(msg.id)) {
|
|
2009
|
-
const { resolve:
|
|
2146
|
+
const { resolve: resolve8, reject } = this.pending.get(msg.id);
|
|
2010
2147
|
this.pending.delete(msg.id);
|
|
2011
2148
|
this.failureCount = 0;
|
|
2012
2149
|
if (msg.error) reject(new Error(msg.error.message));
|
|
2013
|
-
else
|
|
2150
|
+
else resolve8(msg.result);
|
|
2014
2151
|
} else if (msg.method === "Runtime.executionContextCreated") {
|
|
2015
2152
|
this.contexts.add(msg.params.context.id);
|
|
2016
2153
|
} else if (msg.method === "Runtime.executionContextDestroyed") {
|
|
@@ -2033,7 +2170,7 @@ var DaemonCdpManager = class {
|
|
|
2033
2170
|
this.ws.on("error", (err) => {
|
|
2034
2171
|
this.log(`[CDP] WebSocket error: ${err.message}`);
|
|
2035
2172
|
this._connected = false;
|
|
2036
|
-
|
|
2173
|
+
resolve7(false);
|
|
2037
2174
|
});
|
|
2038
2175
|
});
|
|
2039
2176
|
}
|
|
@@ -2047,7 +2184,7 @@ var DaemonCdpManager = class {
|
|
|
2047
2184
|
return;
|
|
2048
2185
|
}
|
|
2049
2186
|
this.log(`[CDP] Connecting browser WS for target discovery...`);
|
|
2050
|
-
await new Promise((
|
|
2187
|
+
await new Promise((resolve7, reject) => {
|
|
2051
2188
|
this.browserWs = new import_ws.default(browserWsUrl);
|
|
2052
2189
|
this.browserWs.on("open", async () => {
|
|
2053
2190
|
this._browserConnected = true;
|
|
@@ -2057,16 +2194,16 @@ var DaemonCdpManager = class {
|
|
|
2057
2194
|
} catch (e) {
|
|
2058
2195
|
this.log(`[CDP] setDiscoverTargets failed: ${e.message}`);
|
|
2059
2196
|
}
|
|
2060
|
-
|
|
2197
|
+
resolve7();
|
|
2061
2198
|
});
|
|
2062
2199
|
this.browserWs.on("message", (data) => {
|
|
2063
2200
|
try {
|
|
2064
2201
|
const msg = JSON.parse(data.toString());
|
|
2065
2202
|
if (msg.id && this.browserPending.has(msg.id)) {
|
|
2066
|
-
const { resolve:
|
|
2203
|
+
const { resolve: resolve8, reject: reject2 } = this.browserPending.get(msg.id);
|
|
2067
2204
|
this.browserPending.delete(msg.id);
|
|
2068
2205
|
if (msg.error) reject2(new Error(msg.error.message));
|
|
2069
|
-
else
|
|
2206
|
+
else resolve8(msg.result);
|
|
2070
2207
|
}
|
|
2071
2208
|
} catch {
|
|
2072
2209
|
}
|
|
@@ -2086,31 +2223,31 @@ var DaemonCdpManager = class {
|
|
|
2086
2223
|
}
|
|
2087
2224
|
}
|
|
2088
2225
|
getBrowserWsUrl() {
|
|
2089
|
-
return new Promise((
|
|
2226
|
+
return new Promise((resolve7) => {
|
|
2090
2227
|
const req = http.get(`http://127.0.0.1:${this.port}/json/version`, (res) => {
|
|
2091
2228
|
let data = "";
|
|
2092
2229
|
res.on("data", (chunk) => data += chunk.toString());
|
|
2093
2230
|
res.on("end", () => {
|
|
2094
2231
|
try {
|
|
2095
2232
|
const info = JSON.parse(data);
|
|
2096
|
-
|
|
2233
|
+
resolve7(info.webSocketDebuggerUrl || null);
|
|
2097
2234
|
} catch {
|
|
2098
|
-
|
|
2235
|
+
resolve7(null);
|
|
2099
2236
|
}
|
|
2100
2237
|
});
|
|
2101
2238
|
});
|
|
2102
|
-
req.on("error", () =>
|
|
2239
|
+
req.on("error", () => resolve7(null));
|
|
2103
2240
|
req.setTimeout(3e3, () => {
|
|
2104
2241
|
req.destroy();
|
|
2105
|
-
|
|
2242
|
+
resolve7(null);
|
|
2106
2243
|
});
|
|
2107
2244
|
});
|
|
2108
2245
|
}
|
|
2109
2246
|
sendBrowser(method, params = {}, timeoutMs = 15e3) {
|
|
2110
|
-
return new Promise((
|
|
2247
|
+
return new Promise((resolve7, reject) => {
|
|
2111
2248
|
if (!this.browserWs || !this._browserConnected) return reject(new Error("Browser WS not connected"));
|
|
2112
2249
|
const id = this.browserMsgId++;
|
|
2113
|
-
this.browserPending.set(id, { resolve:
|
|
2250
|
+
this.browserPending.set(id, { resolve: resolve7, reject });
|
|
2114
2251
|
this.browserWs.send(JSON.stringify({ id, method, params }));
|
|
2115
2252
|
setTimeout(() => {
|
|
2116
2253
|
if (this.browserPending.has(id)) {
|
|
@@ -2150,11 +2287,11 @@ var DaemonCdpManager = class {
|
|
|
2150
2287
|
}
|
|
2151
2288
|
// ─── CDP Protocol ────────────────────────────────────────
|
|
2152
2289
|
sendInternal(method, params = {}, timeoutMs = 15e3) {
|
|
2153
|
-
return new Promise((
|
|
2290
|
+
return new Promise((resolve7, reject) => {
|
|
2154
2291
|
if (!this.ws || !this._connected) return reject(new Error("CDP not connected"));
|
|
2155
2292
|
if (this.ws.readyState !== import_ws.default.OPEN) return reject(new Error("WebSocket not open"));
|
|
2156
2293
|
const id = this.msgId++;
|
|
2157
|
-
this.pending.set(id, { resolve:
|
|
2294
|
+
this.pending.set(id, { resolve: resolve7, reject });
|
|
2158
2295
|
this.ws.send(JSON.stringify({ id, method, params }));
|
|
2159
2296
|
setTimeout(() => {
|
|
2160
2297
|
if (this.pending.has(id)) {
|
|
@@ -2403,7 +2540,7 @@ var DaemonCdpManager = class {
|
|
|
2403
2540
|
const browserWs = this.browserWs;
|
|
2404
2541
|
let msgId = this.browserMsgId;
|
|
2405
2542
|
const sendWs = (method, params = {}, sessionId) => {
|
|
2406
|
-
return new Promise((
|
|
2543
|
+
return new Promise((resolve7, reject) => {
|
|
2407
2544
|
const mid = msgId++;
|
|
2408
2545
|
this.browserMsgId = msgId;
|
|
2409
2546
|
const handler = (raw) => {
|
|
@@ -2412,7 +2549,7 @@ var DaemonCdpManager = class {
|
|
|
2412
2549
|
if (msg.id === mid) {
|
|
2413
2550
|
browserWs.removeListener("message", handler);
|
|
2414
2551
|
if (msg.error) reject(new Error(msg.error.message || JSON.stringify(msg.error)));
|
|
2415
|
-
else
|
|
2552
|
+
else resolve7(msg.result);
|
|
2416
2553
|
}
|
|
2417
2554
|
} catch {
|
|
2418
2555
|
}
|
|
@@ -2594,14 +2731,14 @@ var DaemonCdpManager = class {
|
|
|
2594
2731
|
if (!ws || ws.readyState !== import_ws.default.OPEN) {
|
|
2595
2732
|
throw new Error("CDP not connected");
|
|
2596
2733
|
}
|
|
2597
|
-
return new Promise((
|
|
2734
|
+
return new Promise((resolve7, reject) => {
|
|
2598
2735
|
const id = getNextId();
|
|
2599
2736
|
pendingMap.set(id, {
|
|
2600
2737
|
resolve: (result) => {
|
|
2601
2738
|
if (result?.result?.subtype === "error") {
|
|
2602
2739
|
reject(new Error(result.result.description));
|
|
2603
2740
|
} else {
|
|
2604
|
-
|
|
2741
|
+
resolve7(result?.result?.value);
|
|
2605
2742
|
}
|
|
2606
2743
|
},
|
|
2607
2744
|
reject
|
|
@@ -2633,10 +2770,10 @@ var DaemonCdpManager = class {
|
|
|
2633
2770
|
throw new Error("CDP not connected");
|
|
2634
2771
|
}
|
|
2635
2772
|
const sendViaSession = (method, params = {}) => {
|
|
2636
|
-
return new Promise((
|
|
2773
|
+
return new Promise((resolve7, reject) => {
|
|
2637
2774
|
const pendingMap = this._browserConnected ? this.browserPending : this.pending;
|
|
2638
2775
|
const id = this._browserConnected ? this.browserMsgId++ : this.msgId++;
|
|
2639
|
-
pendingMap.set(id, { resolve:
|
|
2776
|
+
pendingMap.set(id, { resolve: resolve7, reject });
|
|
2640
2777
|
ws.send(JSON.stringify({ id, sessionId, method, params }));
|
|
2641
2778
|
setTimeout(() => {
|
|
2642
2779
|
if (pendingMap.has(id)) {
|
|
@@ -3278,6 +3415,8 @@ var ChatHistoryWriter = class {
|
|
|
3278
3415
|
lastSeenCounts = /* @__PURE__ */ new Map();
|
|
3279
3416
|
/** Last seen message hash per agent (deduplication) */
|
|
3280
3417
|
lastSeenHashes = /* @__PURE__ */ new Map();
|
|
3418
|
+
/** Last seen append-only terminal transcript per agent */
|
|
3419
|
+
lastSeenTerminal = /* @__PURE__ */ new Map();
|
|
3281
3420
|
rotated = false;
|
|
3282
3421
|
/**
|
|
3283
3422
|
* Append new messages to history
|
|
@@ -3335,10 +3474,51 @@ var ChatHistoryWriter = class {
|
|
|
3335
3474
|
} catch {
|
|
3336
3475
|
}
|
|
3337
3476
|
}
|
|
3477
|
+
appendTerminalHistory(agentType, terminalHistory, sessionTitle, instanceId) {
|
|
3478
|
+
const next = String(terminalHistory || "");
|
|
3479
|
+
if (!next.trim()) return;
|
|
3480
|
+
try {
|
|
3481
|
+
const dedupKey = instanceId ? `${agentType}:${instanceId}:terminal` : `${agentType}:terminal`;
|
|
3482
|
+
const prev = this.lastSeenTerminal.get(dedupKey) || "";
|
|
3483
|
+
if (prev === next) return;
|
|
3484
|
+
let delta = "";
|
|
3485
|
+
if (!prev) {
|
|
3486
|
+
delta = next;
|
|
3487
|
+
} else if (next.startsWith(prev)) {
|
|
3488
|
+
delta = next.slice(prev.length);
|
|
3489
|
+
} else if (prev.includes(next)) {
|
|
3490
|
+
this.lastSeenTerminal.set(dedupKey, next);
|
|
3491
|
+
return;
|
|
3492
|
+
} else {
|
|
3493
|
+
delta = `
|
|
3494
|
+
|
|
3495
|
+
[terminal snapshot reset ${(/* @__PURE__ */ new Date()).toISOString()} | ${sessionTitle || agentType}]
|
|
3496
|
+
${next}`;
|
|
3497
|
+
}
|
|
3498
|
+
if (!delta) {
|
|
3499
|
+
this.lastSeenTerminal.set(dedupKey, next);
|
|
3500
|
+
return;
|
|
3501
|
+
}
|
|
3502
|
+
const dir = path4.join(HISTORY_DIR, this.sanitize(agentType));
|
|
3503
|
+
fs3.mkdirSync(dir, { recursive: true });
|
|
3504
|
+
const date = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
3505
|
+
const filePrefix = instanceId ? `${this.sanitize(instanceId)}_` : "";
|
|
3506
|
+
const filePath = path4.join(dir, `${filePrefix}${date}.terminal.log`);
|
|
3507
|
+
fs3.appendFileSync(filePath, delta, "utf-8");
|
|
3508
|
+
this.lastSeenTerminal.set(dedupKey, next);
|
|
3509
|
+
if (!this.rotated) {
|
|
3510
|
+
this.rotated = true;
|
|
3511
|
+
this.rotateOldFiles().catch(() => {
|
|
3512
|
+
});
|
|
3513
|
+
}
|
|
3514
|
+
} catch {
|
|
3515
|
+
}
|
|
3516
|
+
}
|
|
3338
3517
|
/** Called when agent session is explicitly changed */
|
|
3339
3518
|
onSessionChange(agentType) {
|
|
3340
3519
|
this.lastSeenHashes.delete(agentType);
|
|
3341
3520
|
this.lastSeenCounts.delete(agentType);
|
|
3521
|
+
this.lastSeenTerminal.delete(`${agentType}:terminal`);
|
|
3342
3522
|
}
|
|
3343
3523
|
/** Delete history files older than 30 days */
|
|
3344
3524
|
async rotateOldFiles() {
|
|
@@ -3348,7 +3528,7 @@ var ChatHistoryWriter = class {
|
|
|
3348
3528
|
const agentDirs = fs3.readdirSync(HISTORY_DIR, { withFileTypes: true }).filter((d) => d.isDirectory());
|
|
3349
3529
|
for (const dir of agentDirs) {
|
|
3350
3530
|
const dirPath = path4.join(HISTORY_DIR, dir.name);
|
|
3351
|
-
const files = fs3.readdirSync(dirPath).filter((f) => f.endsWith(".jsonl"));
|
|
3531
|
+
const files = fs3.readdirSync(dirPath).filter((f) => f.endsWith(".jsonl") || f.endsWith(".terminal.log"));
|
|
3352
3532
|
for (const file of files) {
|
|
3353
3533
|
const filePath = path4.join(dirPath, file);
|
|
3354
3534
|
const stat = fs3.statSync(filePath);
|
|
@@ -4256,7 +4436,13 @@ async function handleReadChat(h, args) {
|
|
|
4256
4436
|
_log(`${provider.category} adapter: ${adapter.cliType}`);
|
|
4257
4437
|
const status = adapter.getStatus?.();
|
|
4258
4438
|
if (status) {
|
|
4259
|
-
return {
|
|
4439
|
+
return {
|
|
4440
|
+
success: true,
|
|
4441
|
+
messages: status.messages || [],
|
|
4442
|
+
status: status.status,
|
|
4443
|
+
activeModal: status.activeModal,
|
|
4444
|
+
terminalHistory: status.terminalHistory || ""
|
|
4445
|
+
};
|
|
4260
4446
|
}
|
|
4261
4447
|
}
|
|
4262
4448
|
return { success: false, error: `${provider.category} adapter not found` };
|
|
@@ -5988,7 +6174,7 @@ var DaemonCommandHandler = class {
|
|
|
5988
6174
|
try {
|
|
5989
6175
|
const http3 = await import("http");
|
|
5990
6176
|
const postData = JSON.stringify(body);
|
|
5991
|
-
const result = await new Promise((
|
|
6177
|
+
const result = await new Promise((resolve7, reject) => {
|
|
5992
6178
|
const req = http3.request({
|
|
5993
6179
|
hostname: "127.0.0.1",
|
|
5994
6180
|
port: 19280,
|
|
@@ -6000,9 +6186,9 @@ var DaemonCommandHandler = class {
|
|
|
6000
6186
|
res.on("data", (chunk) => data += chunk);
|
|
6001
6187
|
res.on("end", () => {
|
|
6002
6188
|
try {
|
|
6003
|
-
|
|
6189
|
+
resolve7(JSON.parse(data));
|
|
6004
6190
|
} catch {
|
|
6005
|
-
|
|
6191
|
+
resolve7({ raw: data });
|
|
6006
6192
|
}
|
|
6007
6193
|
});
|
|
6008
6194
|
});
|
|
@@ -6020,15 +6206,15 @@ var DaemonCommandHandler = class {
|
|
|
6020
6206
|
if (!providerType) return { success: false, error: "providerType required" };
|
|
6021
6207
|
try {
|
|
6022
6208
|
const http3 = await import("http");
|
|
6023
|
-
const result = await new Promise((
|
|
6209
|
+
const result = await new Promise((resolve7, reject) => {
|
|
6024
6210
|
http3.get(`http://127.0.0.1:19280/api/providers/${providerType}/${endpoint}`, (res) => {
|
|
6025
6211
|
let data = "";
|
|
6026
6212
|
res.on("data", (chunk) => data += chunk);
|
|
6027
6213
|
res.on("end", () => {
|
|
6028
6214
|
try {
|
|
6029
|
-
|
|
6215
|
+
resolve7(JSON.parse(data));
|
|
6030
6216
|
} catch {
|
|
6031
|
-
|
|
6217
|
+
resolve7({ raw: data });
|
|
6032
6218
|
}
|
|
6033
6219
|
});
|
|
6034
6220
|
}).on("error", reject);
|
|
@@ -6042,7 +6228,7 @@ var DaemonCommandHandler = class {
|
|
|
6042
6228
|
try {
|
|
6043
6229
|
const http3 = await import("http");
|
|
6044
6230
|
const postData = JSON.stringify(args || {});
|
|
6045
|
-
const result = await new Promise((
|
|
6231
|
+
const result = await new Promise((resolve7, reject) => {
|
|
6046
6232
|
const req = http3.request({
|
|
6047
6233
|
hostname: "127.0.0.1",
|
|
6048
6234
|
port: 19280,
|
|
@@ -6054,9 +6240,9 @@ var DaemonCommandHandler = class {
|
|
|
6054
6240
|
res.on("data", (chunk) => data += chunk);
|
|
6055
6241
|
res.on("end", () => {
|
|
6056
6242
|
try {
|
|
6057
|
-
|
|
6243
|
+
resolve7(JSON.parse(data));
|
|
6058
6244
|
} catch {
|
|
6059
|
-
|
|
6245
|
+
resolve7({ raw: data });
|
|
6060
6246
|
}
|
|
6061
6247
|
});
|
|
6062
6248
|
});
|
|
@@ -6102,9 +6288,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
6102
6288
|
if (options?.builtinDir) {
|
|
6103
6289
|
this.builtinDirs = Array.isArray(options.builtinDir) ? options.builtinDir : [options.builtinDir];
|
|
6104
6290
|
} else {
|
|
6105
|
-
|
|
6106
|
-
const devDir = path6.resolve(__dirname, "../../providers/_builtin");
|
|
6107
|
-
this.builtinDirs = [fs5.existsSync(devDir) ? devDir : bundledDir];
|
|
6291
|
+
this.builtinDirs = [];
|
|
6108
6292
|
}
|
|
6109
6293
|
this.userDir = options?.userDir || path6.join(os7.homedir(), ".adhdev", "providers");
|
|
6110
6294
|
this.upstreamDir = path6.join(this.userDir, ".upstream");
|
|
@@ -6626,7 +6810,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
6626
6810
|
return { updated: false };
|
|
6627
6811
|
}
|
|
6628
6812
|
try {
|
|
6629
|
-
const etag = await new Promise((
|
|
6813
|
+
const etag = await new Promise((resolve7, reject) => {
|
|
6630
6814
|
const options = {
|
|
6631
6815
|
method: "HEAD",
|
|
6632
6816
|
hostname: "github.com",
|
|
@@ -6644,7 +6828,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
6644
6828
|
headers: { "User-Agent": "adhdev-launcher" },
|
|
6645
6829
|
timeout: 1e4
|
|
6646
6830
|
}, (res2) => {
|
|
6647
|
-
|
|
6831
|
+
resolve7(res2.headers.etag || res2.headers["last-modified"] || "");
|
|
6648
6832
|
});
|
|
6649
6833
|
req2.on("error", reject);
|
|
6650
6834
|
req2.on("timeout", () => {
|
|
@@ -6653,7 +6837,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
6653
6837
|
});
|
|
6654
6838
|
req2.end();
|
|
6655
6839
|
} else {
|
|
6656
|
-
|
|
6840
|
+
resolve7(res.headers.etag || res.headers["last-modified"] || "");
|
|
6657
6841
|
}
|
|
6658
6842
|
});
|
|
6659
6843
|
req.on("error", reject);
|
|
@@ -6717,7 +6901,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
6717
6901
|
downloadFile(url, destPath) {
|
|
6718
6902
|
const https = require("https");
|
|
6719
6903
|
const http3 = require("http");
|
|
6720
|
-
return new Promise((
|
|
6904
|
+
return new Promise((resolve7, reject) => {
|
|
6721
6905
|
const doRequest = (reqUrl, redirectCount = 0) => {
|
|
6722
6906
|
if (redirectCount > 5) {
|
|
6723
6907
|
reject(new Error("Too many redirects"));
|
|
@@ -6737,7 +6921,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
6737
6921
|
res.pipe(ws);
|
|
6738
6922
|
ws.on("finish", () => {
|
|
6739
6923
|
ws.close();
|
|
6740
|
-
|
|
6924
|
+
resolve7();
|
|
6741
6925
|
});
|
|
6742
6926
|
ws.on("error", reject);
|
|
6743
6927
|
});
|
|
@@ -7102,17 +7286,17 @@ async function findFreePort(ports) {
|
|
|
7102
7286
|
throw new Error("No free port found");
|
|
7103
7287
|
}
|
|
7104
7288
|
function checkPortFree(port) {
|
|
7105
|
-
return new Promise((
|
|
7289
|
+
return new Promise((resolve7) => {
|
|
7106
7290
|
const server = net.createServer();
|
|
7107
7291
|
server.unref();
|
|
7108
|
-
server.on("error", () =>
|
|
7292
|
+
server.on("error", () => resolve7(false));
|
|
7109
7293
|
server.listen(port, "127.0.0.1", () => {
|
|
7110
|
-
server.close(() =>
|
|
7294
|
+
server.close(() => resolve7(true));
|
|
7111
7295
|
});
|
|
7112
7296
|
});
|
|
7113
7297
|
}
|
|
7114
7298
|
async function isCdpActive(port) {
|
|
7115
|
-
return new Promise((
|
|
7299
|
+
return new Promise((resolve7) => {
|
|
7116
7300
|
const req = require("http").get(`http://127.0.0.1:${port}/json/version`, {
|
|
7117
7301
|
timeout: 2e3
|
|
7118
7302
|
}, (res) => {
|
|
@@ -7121,16 +7305,16 @@ async function isCdpActive(port) {
|
|
|
7121
7305
|
res.on("end", () => {
|
|
7122
7306
|
try {
|
|
7123
7307
|
const info = JSON.parse(data);
|
|
7124
|
-
|
|
7308
|
+
resolve7(!!info["WebKit-Version"] || !!info["Browser"]);
|
|
7125
7309
|
} catch {
|
|
7126
|
-
|
|
7310
|
+
resolve7(false);
|
|
7127
7311
|
}
|
|
7128
7312
|
});
|
|
7129
7313
|
});
|
|
7130
|
-
req.on("error", () =>
|
|
7314
|
+
req.on("error", () => resolve7(false));
|
|
7131
7315
|
req.on("timeout", () => {
|
|
7132
7316
|
req.destroy();
|
|
7133
|
-
|
|
7317
|
+
resolve7(false);
|
|
7134
7318
|
});
|
|
7135
7319
|
});
|
|
7136
7320
|
}
|
|
@@ -8136,31 +8320,12 @@ var CliProviderInstance = class {
|
|
|
8136
8320
|
async onTick() {
|
|
8137
8321
|
}
|
|
8138
8322
|
getState() {
|
|
8139
|
-
const
|
|
8140
|
-
const parsedStatus = this.adapter.getScriptParsedStatus();
|
|
8141
|
-
const adapterStatus = parsedStatus ? {
|
|
8142
|
-
...rawStatus,
|
|
8143
|
-
messages: parsedStatus.messages || rawStatus.messages,
|
|
8144
|
-
activeModal: parsedStatus.activeModal || rawStatus.activeModal
|
|
8145
|
-
} : rawStatus;
|
|
8323
|
+
const adapterStatus = this.adapter.getStatus();
|
|
8146
8324
|
const dirName = this.workingDir.split("/").filter(Boolean).pop() || "session";
|
|
8147
8325
|
const recentMessages = adapterStatus.messages.slice(-50).map((m) => {
|
|
8148
8326
|
const content = typeof m.content === "string" && m.content.length > 8e3 ? m.content.slice(0, 8e3) + "\n... (truncated)" : m.content;
|
|
8149
8327
|
return { ...m, content };
|
|
8150
8328
|
});
|
|
8151
|
-
const partial = this.adapter.getPartialResponse();
|
|
8152
|
-
const shouldAppendRawPartial = !parsedStatus;
|
|
8153
|
-
if (shouldAppendRawPartial && adapterStatus.status === "generating" && partial) {
|
|
8154
|
-
const cleaned = partial.trim();
|
|
8155
|
-
if (cleaned && cleaned !== "(generating...)") {
|
|
8156
|
-
recentMessages.push({
|
|
8157
|
-
role: "assistant",
|
|
8158
|
-
content: (cleaned.length > 8e3 ? cleaned.slice(0, 8e3) + "..." : cleaned) + "...",
|
|
8159
|
-
timestamp: Date.now(),
|
|
8160
|
-
meta: { streaming: true }
|
|
8161
|
-
});
|
|
8162
|
-
}
|
|
8163
|
-
}
|
|
8164
8329
|
if (recentMessages.length > 0) {
|
|
8165
8330
|
const dirName2 = this.workingDir.split("/").filter(Boolean).pop() || "session";
|
|
8166
8331
|
this.historyWriter.appendNewMessages(
|
|
@@ -8170,6 +8335,14 @@ var CliProviderInstance = class {
|
|
|
8170
8335
|
this.instanceId
|
|
8171
8336
|
);
|
|
8172
8337
|
}
|
|
8338
|
+
if (adapterStatus.terminalHistory?.trim()) {
|
|
8339
|
+
this.historyWriter.appendTerminalHistory(
|
|
8340
|
+
this.type,
|
|
8341
|
+
adapterStatus.terminalHistory,
|
|
8342
|
+
`${this.provider.name} \xB7 ${dirName}`,
|
|
8343
|
+
this.instanceId
|
|
8344
|
+
);
|
|
8345
|
+
}
|
|
8173
8346
|
return {
|
|
8174
8347
|
type: this.type,
|
|
8175
8348
|
name: this.provider.name,
|
|
@@ -8182,6 +8355,7 @@ var CliProviderInstance = class {
|
|
|
8182
8355
|
status: adapterStatus.status,
|
|
8183
8356
|
messages: recentMessages,
|
|
8184
8357
|
activeModal: adapterStatus.activeModal,
|
|
8358
|
+
terminalHistory: adapterStatus.terminalHistory,
|
|
8185
8359
|
inputContent: ""
|
|
8186
8360
|
},
|
|
8187
8361
|
workspace: this.workingDir,
|
|
@@ -8756,13 +8930,13 @@ var AcpProviderInstance = class {
|
|
|
8756
8930
|
}
|
|
8757
8931
|
this.currentStatus = "waiting_approval";
|
|
8758
8932
|
this.detectStatusTransition();
|
|
8759
|
-
const approved = await new Promise((
|
|
8760
|
-
this.permissionResolvers.push(
|
|
8933
|
+
const approved = await new Promise((resolve7) => {
|
|
8934
|
+
this.permissionResolvers.push(resolve7);
|
|
8761
8935
|
setTimeout(() => {
|
|
8762
|
-
const idx = this.permissionResolvers.indexOf(
|
|
8936
|
+
const idx = this.permissionResolvers.indexOf(resolve7);
|
|
8763
8937
|
if (idx >= 0) {
|
|
8764
8938
|
this.permissionResolvers.splice(idx, 1);
|
|
8765
|
-
|
|
8939
|
+
resolve7(false);
|
|
8766
8940
|
}
|
|
8767
8941
|
}, 3e5);
|
|
8768
8942
|
});
|
|
@@ -10342,7 +10516,8 @@ async function detectAllVersions(loader, archive) {
|
|
|
10342
10516
|
binary: null,
|
|
10343
10517
|
detectedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
10344
10518
|
};
|
|
10345
|
-
const
|
|
10519
|
+
const verCmdConfig = provider.versionCommand;
|
|
10520
|
+
const versionCommand = typeof verCmdConfig === "object" && verCmdConfig !== null ? verCmdConfig[currentOs] : verCmdConfig;
|
|
10346
10521
|
if (provider.category === "ide") {
|
|
10347
10522
|
const osPaths = provider.paths?.[currentOs] || [];
|
|
10348
10523
|
const appPath = checkPathExists2(osPaths);
|
|
@@ -10848,15 +11023,15 @@ var DevServer = class _DevServer {
|
|
|
10848
11023
|
this.json(res, 500, { error: e.message });
|
|
10849
11024
|
}
|
|
10850
11025
|
});
|
|
10851
|
-
return new Promise((
|
|
11026
|
+
return new Promise((resolve7, reject) => {
|
|
10852
11027
|
this.server.listen(port, "127.0.0.1", () => {
|
|
10853
11028
|
this.log(`Dev server listening on http://127.0.0.1:${port}`);
|
|
10854
|
-
|
|
11029
|
+
resolve7();
|
|
10855
11030
|
});
|
|
10856
11031
|
this.server.on("error", (e) => {
|
|
10857
11032
|
if (e.code === "EADDRINUSE") {
|
|
10858
11033
|
this.log(`Port ${port} in use, skipping dev server`);
|
|
10859
|
-
|
|
11034
|
+
resolve7();
|
|
10860
11035
|
} else {
|
|
10861
11036
|
reject(e);
|
|
10862
11037
|
}
|
|
@@ -10939,20 +11114,20 @@ var DevServer = class _DevServer {
|
|
|
10939
11114
|
child.stderr?.on("data", (d) => {
|
|
10940
11115
|
stderr += d.toString().slice(0, 2e3);
|
|
10941
11116
|
});
|
|
10942
|
-
await new Promise((
|
|
11117
|
+
await new Promise((resolve7) => {
|
|
10943
11118
|
const timer = setTimeout(() => {
|
|
10944
11119
|
child.kill();
|
|
10945
|
-
|
|
11120
|
+
resolve7();
|
|
10946
11121
|
}, 3e3);
|
|
10947
11122
|
child.on("exit", () => {
|
|
10948
11123
|
clearTimeout(timer);
|
|
10949
|
-
|
|
11124
|
+
resolve7();
|
|
10950
11125
|
});
|
|
10951
11126
|
child.stdout?.once("data", () => {
|
|
10952
11127
|
setTimeout(() => {
|
|
10953
11128
|
child.kill();
|
|
10954
11129
|
clearTimeout(timer);
|
|
10955
|
-
|
|
11130
|
+
resolve7();
|
|
10956
11131
|
}, 500);
|
|
10957
11132
|
});
|
|
10958
11133
|
});
|
|
@@ -11696,14 +11871,14 @@ var DevServer = class _DevServer {
|
|
|
11696
11871
|
child.stderr?.on("data", (d) => {
|
|
11697
11872
|
stderr += d.toString();
|
|
11698
11873
|
});
|
|
11699
|
-
await new Promise((
|
|
11874
|
+
await new Promise((resolve7) => {
|
|
11700
11875
|
const timer = setTimeout(() => {
|
|
11701
11876
|
child.kill();
|
|
11702
|
-
|
|
11877
|
+
resolve7();
|
|
11703
11878
|
}, timeout);
|
|
11704
11879
|
child.on("exit", () => {
|
|
11705
11880
|
clearTimeout(timer);
|
|
11706
|
-
|
|
11881
|
+
resolve7();
|
|
11707
11882
|
});
|
|
11708
11883
|
});
|
|
11709
11884
|
const elapsed = Date.now() - start;
|
|
@@ -11754,11 +11929,7 @@ var DevServer = class _DevServer {
|
|
|
11754
11929
|
return;
|
|
11755
11930
|
}
|
|
11756
11931
|
let targetDir;
|
|
11757
|
-
|
|
11758
|
-
targetDir = this.providerLoader.getUserProviderDir(category, type);
|
|
11759
|
-
} else {
|
|
11760
|
-
targetDir = this.providerLoader.getBuiltinProviderDir(category, type);
|
|
11761
|
-
}
|
|
11932
|
+
targetDir = this.providerLoader.getUserProviderDir(category, type);
|
|
11762
11933
|
const jsonPath = path12.join(targetDir, "provider.json");
|
|
11763
11934
|
if (fs9.existsSync(jsonPath)) {
|
|
11764
11935
|
this.json(res, 409, { error: `Provider already exists at ${targetDir}`, path: targetDir });
|
|
@@ -12556,8 +12727,7 @@ var DevServer = class _DevServer {
|
|
|
12556
12727
|
}
|
|
12557
12728
|
loadAutoImplReferenceScripts(category, referenceType) {
|
|
12558
12729
|
if (!referenceType) return {};
|
|
12559
|
-
const
|
|
12560
|
-
const refDir = path12.join(builtinDir, category, referenceType);
|
|
12730
|
+
const refDir = this.providerLoader.getUpstreamProviderDir(category, referenceType);
|
|
12561
12731
|
if (!fs9.existsSync(refDir)) return {};
|
|
12562
12732
|
const referenceScripts = {};
|
|
12563
12733
|
const scriptsDir = path12.join(refDir, "scripts");
|
|
@@ -12796,7 +12966,7 @@ var DevServer = class _DevServer {
|
|
|
12796
12966
|
}
|
|
12797
12967
|
if (model) args.push("--model", model);
|
|
12798
12968
|
const escapedArgs = args.map((a) => `'${a.replace(/'/g, "'\\''")}'`).join(" ");
|
|
12799
|
-
const metaPrompt = `Read the file at ${promptFile} and follow ALL instructions
|
|
12969
|
+
const metaPrompt = `Read the file at ${promptFile} and follow ALL instructions strictly. DO NOT spend time exploring the filesystem or other providers. You have full authority to implement ALL required script files and independently test them against 127.0.0.1:19280 via CDP CURL. Upon complete validation of ALL assigned files, print exactly "_PIPELINE_COMPLETE_SIGNAL_" to gracefully close the pipeline. DO NOT WAIT FOR APPROVAL, execute completely autonomously.`;
|
|
12800
12970
|
shellCmd = `${command} ${escapedArgs} "${metaPrompt}"`;
|
|
12801
12971
|
} else {
|
|
12802
12972
|
const escapedArgs = baseArgs.map((a) => `'${a.replace(/'/g, "'\\''")}'`).join(" ");
|
|
@@ -13059,6 +13229,8 @@ var DevServer = class _DevServer {
|
|
|
13059
13229
|
lines.push("5. Do NOT modify `scripts.js` router \u2014 only edit individual `*.js` files");
|
|
13060
13230
|
lines.push("6. All scripts run in the browser (CDP evaluate) \u2014 use DOM APIs only");
|
|
13061
13231
|
lines.push('7. **Cross-Platform Compatibility**: If you use ARIA labels that contain keyboard shortcuts (e.g., `Cascade (\u2318L)`), you MUST use substring matches (`aria-label*="Cascade"`) or handle both macOS (`\u2318`, `Cmd`) and Windows (`Ctrl`) so the script does not break on other operating systems.');
|
|
13232
|
+
lines.push("8. **CRITICAL: DO NOT explore the filesystem or read other providers.** The reference implementation pattern is already provided below. Do not run `find`, `rg`, or `cat` on upstream providers. Doing so wastes context tokens and will crash the agent session. Focus entirely on modifying the target files.");
|
|
13233
|
+
lines.push("9. Do NOT delete any files. Implement the logic by replacing the empty stubs.");
|
|
13062
13234
|
lines.push("");
|
|
13063
13235
|
lines.push("## Required Return Format");
|
|
13064
13236
|
lines.push("| Function | Return JSON |");
|
|
@@ -13408,14 +13580,14 @@ data: ${JSON.stringify(msg.data)}
|
|
|
13408
13580
|
res.end(JSON.stringify(data, null, 2));
|
|
13409
13581
|
}
|
|
13410
13582
|
async readBody(req) {
|
|
13411
|
-
return new Promise((
|
|
13583
|
+
return new Promise((resolve7) => {
|
|
13412
13584
|
let body = "";
|
|
13413
13585
|
req.on("data", (chunk) => body += chunk);
|
|
13414
13586
|
req.on("end", () => {
|
|
13415
13587
|
try {
|
|
13416
|
-
|
|
13588
|
+
resolve7(JSON.parse(body));
|
|
13417
13589
|
} catch {
|
|
13418
|
-
|
|
13590
|
+
resolve7({});
|
|
13419
13591
|
}
|
|
13420
13592
|
});
|
|
13421
13593
|
});
|
|
@@ -13795,10 +13967,10 @@ async function installExtension(ide, extension) {
|
|
|
13795
13967
|
const buffer = Buffer.from(await res.arrayBuffer());
|
|
13796
13968
|
const fs10 = await import("fs");
|
|
13797
13969
|
fs10.writeFileSync(vsixPath, buffer);
|
|
13798
|
-
return new Promise((
|
|
13970
|
+
return new Promise((resolve7) => {
|
|
13799
13971
|
const cmd = `"${ide.cliCommand}" --install-extension "${vsixPath}" --force`;
|
|
13800
13972
|
(0, import_child_process8.exec)(cmd, { timeout: 6e4 }, (error, _stdout, stderr) => {
|
|
13801
|
-
|
|
13973
|
+
resolve7({
|
|
13802
13974
|
extensionId: extension.id,
|
|
13803
13975
|
marketplaceId: extension.marketplaceId,
|
|
13804
13976
|
success: !error,
|
|
@@ -13811,11 +13983,11 @@ async function installExtension(ide, extension) {
|
|
|
13811
13983
|
} catch (e) {
|
|
13812
13984
|
}
|
|
13813
13985
|
}
|
|
13814
|
-
return new Promise((
|
|
13986
|
+
return new Promise((resolve7) => {
|
|
13815
13987
|
const cmd = `"${ide.cliCommand}" --install-extension ${extension.marketplaceId} --force`;
|
|
13816
13988
|
(0, import_child_process8.exec)(cmd, { timeout: 6e4 }, (error, stdout, stderr) => {
|
|
13817
13989
|
if (error) {
|
|
13818
|
-
|
|
13990
|
+
resolve7({
|
|
13819
13991
|
extensionId: extension.id,
|
|
13820
13992
|
marketplaceId: extension.marketplaceId,
|
|
13821
13993
|
success: false,
|
|
@@ -13823,7 +13995,7 @@ async function installExtension(ide, extension) {
|
|
|
13823
13995
|
error: stderr || error.message
|
|
13824
13996
|
});
|
|
13825
13997
|
} else {
|
|
13826
|
-
|
|
13998
|
+
resolve7({
|
|
13827
13999
|
extensionId: extension.id,
|
|
13828
14000
|
marketplaceId: extension.marketplaceId,
|
|
13829
14001
|
success: true,
|