@adhdev/daemon-core 0.8.34 → 0.8.36
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/boot/daemon-lifecycle.d.ts +4 -0
- package/dist/commands/router.d.ts +3 -0
- package/dist/config/config.d.ts +5 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +585 -256
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +584 -256
- package/dist/index.mjs.map +1 -1
- package/dist/shared-types.d.ts +286 -16
- package/dist/status/builders.d.ts +5 -1
- package/dist/status/normalize.d.ts +11 -1
- package/dist/status/normalize.js +36 -16
- package/dist/status/normalize.js.map +1 -1
- package/dist/status/normalize.mjs +35 -16
- package/dist/status/normalize.mjs.map +1 -1
- package/dist/status/reporter.d.ts +7 -0
- package/dist/status/snapshot.d.ts +5 -5
- package/dist/types.d.ts +1 -1
- package/node_modules/@adhdev/session-host-core/package.json +1 -1
- package/package.json +1 -1
- package/src/agent-stream/forward.d.ts +8 -0
- package/src/agent-stream/index.d.ts +6 -0
- package/src/agent-stream/manager.d.ts +60 -0
- package/src/agent-stream/poller.d.ts +41 -0
- package/src/agent-stream/provider-adapter.d.ts +36 -0
- package/src/agent-stream/types.d.ts +68 -0
- package/src/boot/daemon-lifecycle.d.ts +100 -0
- package/src/boot/daemon-lifecycle.ts +7 -0
- package/src/cdp/devtools.d.ts +51 -0
- package/src/cdp/initializer.d.ts +50 -0
- package/src/cdp/manager.d.ts +147 -0
- package/src/cdp/scanner.d.ts +58 -0
- package/src/cdp/setup.d.ts +58 -0
- package/src/cli-adapter-types.d.ts +57 -0
- package/src/cli-adapters/provider-cli-adapter.d.ts +177 -0
- package/src/cli-adapters/provider-cli-adapter.ts +115 -91
- package/src/cli-adapters/provider-cli-config.d.ts +30 -0
- package/src/cli-adapters/provider-cli-parse.d.ts +42 -0
- package/src/cli-adapters/provider-cli-runtime.d.ts +29 -0
- package/src/cli-adapters/provider-cli-shared.d.ts +158 -0
- package/src/cli-adapters/pty-transport.d.ts +48 -0
- package/src/cli-adapters/session-host-transport.d.ts +20 -0
- package/src/cli-adapters/spawn-env.d.ts +8 -0
- package/src/cli-adapters/terminal-backends/ghostty-vt-backend.d.ts +16 -0
- package/src/cli-adapters/terminal-backends/types.d.ts +18 -0
- package/src/cli-adapters/terminal-backends/xterm-backend.d.ts +17 -0
- package/src/cli-adapters/terminal-screen.d.ts +33 -0
- package/src/commands/cdp-commands.d.ts +15 -0
- package/src/commands/chat-commands.d.ts +15 -0
- package/src/commands/chat-commands.ts +192 -17
- package/src/commands/cli-manager.d.ts +94 -0
- package/src/commands/handler.d.ts +103 -0
- package/src/commands/router.d.ts +98 -0
- package/src/commands/router.ts +25 -0
- package/src/commands/stream-commands.d.ts +14 -0
- package/src/commands/stream-commands.ts +14 -10
- package/src/commands/upgrade-helper.d.ts +10 -0
- package/src/commands/workspace-commands.d.ts +11 -0
- package/src/config/chat-history.d.ts +99 -0
- package/src/config/config.d.ts +14 -0
- package/src/config/config.ts +8 -0
- package/src/config/recent-activity.d.ts +29 -0
- package/src/config/saved-sessions.d.ts +22 -0
- package/src/config/state-store.d.ts +32 -0
- package/src/config/workspaces.d.ts +0 -1
- package/src/daemon/dev-auto-implement.d.ts +43 -0
- package/src/daemon/dev-cdp-handlers.d.ts +22 -0
- package/src/daemon/dev-cli-debug.d.ts +106 -0
- package/src/daemon/dev-server-types.d.ts +43 -0
- package/src/daemon/dev-server.d.ts +140 -0
- package/src/daemon/scaffold-template.d.ts +32 -0
- package/src/daemon-core.d.ts +36 -0
- package/src/detection/cli-detector.d.ts +31 -0
- package/src/detection/ide-detector.d.ts +35 -0
- package/src/index.d.ts +83 -0
- package/src/index.ts +34 -1
- package/src/installer.d.ts +50 -0
- package/src/ipc-protocol.d.ts +111 -0
- package/src/launch.d.ts +46 -0
- package/src/logging/command-log.d.ts +31 -0
- package/src/logging/logger.d.ts +89 -0
- package/src/providers/acp-provider-instance.d.ts +102 -0
- package/src/providers/approval-utils.d.ts +7 -0
- package/src/providers/cli-provider-instance.d.ts +86 -0
- package/src/providers/contracts.d.ts +193 -1
- package/src/providers/control-effects.d.ts +4 -0
- package/src/providers/extension-provider-instance.d.ts +61 -0
- package/src/providers/ide-provider-instance.d.ts +70 -0
- package/src/providers/provider-instance-manager.d.ts +84 -0
- package/src/providers/provider-instance.d.ts +7 -1
- package/src/providers/provider-loader.d.ts +299 -0
- package/src/providers/status-monitor.d.ts +48 -0
- package/src/providers/version-archive.d.ts +52 -0
- package/src/session-host/runtime-support.d.ts +8 -0
- package/src/sessions/reconcile.d.ts +22 -0
- package/src/sessions/registry.d.ts +24 -0
- package/src/shared-types-extra.d.ts +29 -0
- package/src/shared-types.d.ts +204 -38
- package/src/shared-types.ts +319 -16
- package/src/status/builders.d.ts +33 -0
- package/src/status/builders.ts +110 -54
- package/src/status/normalize.ts +54 -19
- package/src/status/reporter.d.ts +69 -0
- package/src/status/reporter.ts +104 -26
- package/src/status/snapshot.d.ts +58 -0
- package/src/status/snapshot.ts +79 -41
- package/src/system/host-memory.d.ts +19 -0
- package/src/types.d.ts +3 -7
- package/src/types.ts +1 -1
package/dist/index.mjs
CHANGED
|
@@ -62,6 +62,7 @@ function normalizeConfig(raw) {
|
|
|
62
62
|
const parsed = isPlainObject(raw) ? raw : {};
|
|
63
63
|
return {
|
|
64
64
|
serverUrl: typeof parsed.serverUrl === "string" && parsed.serverUrl.trim() ? parsed.serverUrl : DEFAULT_CONFIG.serverUrl,
|
|
65
|
+
allowServerApiProxy: asBoolean(parsed.allowServerApiProxy, DEFAULT_CONFIG.allowServerApiProxy ?? false),
|
|
65
66
|
selectedIde: asNullableString(parsed.selectedIde),
|
|
66
67
|
configuredIdes: asStringArray(parsed.configuredIdes),
|
|
67
68
|
installedExtensions: asStringArray(parsed.installedExtensions),
|
|
@@ -206,6 +207,7 @@ var init_config = __esm({
|
|
|
206
207
|
"use strict";
|
|
207
208
|
DEFAULT_CONFIG = {
|
|
208
209
|
serverUrl: "https://api.adhf.dev",
|
|
210
|
+
allowServerApiProxy: false,
|
|
209
211
|
selectedIde: null,
|
|
210
212
|
configuredIdes: [],
|
|
211
213
|
installedExtensions: [],
|
|
@@ -2485,8 +2487,6 @@ ${data.message || ""}`.trim();
|
|
|
2485
2487
|
if (blockingModal || this.currentStatus === "waiting_approval") {
|
|
2486
2488
|
throw new Error(`${this.cliName} is awaiting confirmation before it can accept a prompt`);
|
|
2487
2489
|
}
|
|
2488
|
-
this.committedMessages.push({ role: "user", content: text, timestamp: Date.now() });
|
|
2489
|
-
this.syncMessageViews();
|
|
2490
2490
|
this.isWaitingForResponse = true;
|
|
2491
2491
|
this.responseBuffer = "";
|
|
2492
2492
|
this.finishRetryCount = 0;
|
|
@@ -2518,6 +2518,13 @@ ${data.message || ""}`.trim();
|
|
|
2518
2518
|
const submitDelayMs = this.sendDelayMs + Math.min(2e3, Math.max(0, estimatedLines - 1) * 350);
|
|
2519
2519
|
const maxEchoWaitMs = submitDelayMs + Math.max(1500, Math.min(5e3, estimatedLines * 500));
|
|
2520
2520
|
const retryDelayMs = Math.max(350, Math.min(1500, Math.max(this.sendDelayMs, submitDelayMs)));
|
|
2521
|
+
let didCommitUserTurn = false;
|
|
2522
|
+
const commitUserTurn = () => {
|
|
2523
|
+
if (didCommitUserTurn) return;
|
|
2524
|
+
didCommitUserTurn = true;
|
|
2525
|
+
this.committedMessages.push({ role: "user", content: text, timestamp: Date.now() });
|
|
2526
|
+
this.syncMessageViews();
|
|
2527
|
+
};
|
|
2521
2528
|
if (this.settleTimer) {
|
|
2522
2529
|
clearTimeout(this.settleTimer);
|
|
2523
2530
|
this.settleTimer = null;
|
|
@@ -2530,109 +2537,128 @@ ${data.message || ""}`.trim();
|
|
|
2530
2537
|
if (this.isWaitingForResponse) this.finishResponse();
|
|
2531
2538
|
}, this.timeouts.maxResponse);
|
|
2532
2539
|
};
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2540
|
+
await new Promise((resolve12) => {
|
|
2541
|
+
let resolved = false;
|
|
2542
|
+
const resolveOnce = () => {
|
|
2543
|
+
if (resolved) return;
|
|
2544
|
+
resolved = true;
|
|
2545
|
+
resolve12();
|
|
2546
|
+
};
|
|
2547
|
+
const submit = () => {
|
|
2548
|
+
if (!this.ptyProcess) {
|
|
2549
|
+
resolveOnce();
|
|
2550
|
+
return;
|
|
2551
|
+
}
|
|
2552
|
+
commitUserTurn();
|
|
2553
|
+
this.submitPendingUntil = 0;
|
|
2547
2554
|
const screenText = this.terminalScreen.getText();
|
|
2548
|
-
if (!promptLikelyVisible(screenText, normalizedPromptSnippet)) return;
|
|
2549
|
-
if (/Esc to interrupt|Do you want to proceed|This command requires approval|Allow Codex to|Approve and run now|Always approve this session|Running…|Running\.\.\./i.test(screenText)) return;
|
|
2550
|
-
this.responseSettleIgnoreUntil = Date.now() + this.timeouts.outputSettle + 400;
|
|
2551
|
-
LOG.info("CLI", `[${this.cliType}] Retrying submit key for stuck prompt (attempt ${attempt})`);
|
|
2552
2555
|
this.recordTrace("submit_write", {
|
|
2553
|
-
mode: "
|
|
2554
|
-
attempt,
|
|
2556
|
+
mode: "submit_key",
|
|
2555
2557
|
sendKey: this.sendKey,
|
|
2556
2558
|
screenText: summarizeCliTraceText(screenText, 500)
|
|
2557
2559
|
});
|
|
2558
2560
|
this.ptyProcess.write(this.sendKey);
|
|
2559
|
-
|
|
2560
|
-
this.
|
|
2561
|
-
return;
|
|
2562
|
-
|
|
2563
|
-
|
|
2561
|
+
const retrySubmitIfStuck = (attempt) => {
|
|
2562
|
+
this.submitRetryTimer = null;
|
|
2563
|
+
if (!this.ptyProcess || !this.isWaitingForResponse || this.submitRetryUsed) return;
|
|
2564
|
+
if (this.currentStatus === "waiting_approval") return;
|
|
2565
|
+
if ((this.responseBuffer || "").trim()) return;
|
|
2566
|
+
const screenText2 = this.terminalScreen.getText();
|
|
2567
|
+
if (!promptLikelyVisible(screenText2, normalizedPromptSnippet)) return;
|
|
2568
|
+
if (/Esc to interrupt|Do you want to proceed|This command requires approval|Allow Codex to|Approve and run now|Always approve this session|Running…|Running\.\.\./i.test(screenText2)) return;
|
|
2569
|
+
this.responseSettleIgnoreUntil = Date.now() + this.timeouts.outputSettle + 400;
|
|
2570
|
+
LOG.info("CLI", `[${this.cliType}] Retrying submit key for stuck prompt (attempt ${attempt})`);
|
|
2571
|
+
this.recordTrace("submit_write", {
|
|
2572
|
+
mode: "submit_retry",
|
|
2573
|
+
attempt,
|
|
2574
|
+
sendKey: this.sendKey,
|
|
2575
|
+
screenText: summarizeCliTraceText(screenText2, 500)
|
|
2576
|
+
});
|
|
2577
|
+
this.ptyProcess.write(this.sendKey);
|
|
2578
|
+
if (attempt >= 3) {
|
|
2579
|
+
this.submitRetryUsed = true;
|
|
2580
|
+
return;
|
|
2581
|
+
}
|
|
2582
|
+
this.submitRetryTimer = setTimeout(() => retrySubmitIfStuck(attempt + 1), retryDelayMs);
|
|
2583
|
+
};
|
|
2584
|
+
this.submitRetryTimer = setTimeout(() => retrySubmitIfStuck(1), retryDelayMs);
|
|
2585
|
+
startResponseTimeout();
|
|
2586
|
+
resolveOnce();
|
|
2564
2587
|
};
|
|
2565
|
-
this.
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2588
|
+
if (this.submitStrategy === "immediate") {
|
|
2589
|
+
commitUserTurn();
|
|
2590
|
+
this.submitPendingUntil = 0;
|
|
2591
|
+
this.recordTrace("submit_write", {
|
|
2592
|
+
mode: "immediate",
|
|
2593
|
+
text: summarizeCliTraceText(text, 500),
|
|
2594
|
+
sendKey: this.sendKey,
|
|
2595
|
+
screenText: summarizeCliTraceText(this.terminalScreen.getText(), 500)
|
|
2596
|
+
});
|
|
2597
|
+
this.ptyProcess.write(text + this.sendKey);
|
|
2598
|
+
this.submitRetryTimer = setTimeout(() => {
|
|
2599
|
+
this.submitRetryTimer = null;
|
|
2600
|
+
if (!this.ptyProcess || !this.isWaitingForResponse || this.submitRetryUsed) return;
|
|
2601
|
+
if (this.currentStatus === "waiting_approval") return;
|
|
2602
|
+
if ((this.responseBuffer || "").trim()) return;
|
|
2603
|
+
const screenText = this.terminalScreen.getText();
|
|
2604
|
+
if (!promptLikelyVisible(screenText, normalizedPromptSnippet)) return;
|
|
2605
|
+
LOG.info("CLI", `[${this.cliType}] Retrying submit key for stuck prompt (attempt 1)`);
|
|
2606
|
+
this.responseSettleIgnoreUntil = Date.now() + this.timeouts.outputSettle + 400;
|
|
2607
|
+
this.recordTrace("submit_write", {
|
|
2608
|
+
mode: "immediate_retry",
|
|
2609
|
+
attempt: 1,
|
|
2610
|
+
sendKey: this.sendKey,
|
|
2611
|
+
screenText: summarizeCliTraceText(screenText, 500)
|
|
2612
|
+
});
|
|
2613
|
+
this.ptyProcess.write(this.sendKey);
|
|
2614
|
+
this.submitRetryUsed = true;
|
|
2615
|
+
}, retryDelayMs);
|
|
2616
|
+
startResponseTimeout();
|
|
2617
|
+
resolveOnce();
|
|
2618
|
+
return;
|
|
2619
|
+
}
|
|
2620
|
+
if (submitDelayMs > 0) {
|
|
2621
|
+
this.submitPendingUntil = Date.now() + submitDelayMs;
|
|
2622
|
+
}
|
|
2623
|
+
this.ptyProcess.write(text);
|
|
2570
2624
|
this.recordTrace("submit_write", {
|
|
2571
|
-
mode: "
|
|
2625
|
+
mode: "type_then_submit",
|
|
2572
2626
|
text: summarizeCliTraceText(text, 500),
|
|
2573
2627
|
sendKey: this.sendKey,
|
|
2574
2628
|
screenText: summarizeCliTraceText(this.terminalScreen.getText(), 500)
|
|
2575
2629
|
});
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
if (this.
|
|
2581
|
-
|
|
2630
|
+
const submitStartedAt = Date.now();
|
|
2631
|
+
let lastNormalizedScreen = "";
|
|
2632
|
+
let lastScreenChangeAt = submitStartedAt;
|
|
2633
|
+
const waitForEchoAndSubmit = () => {
|
|
2634
|
+
if (!this.ptyProcess) {
|
|
2635
|
+
resolveOnce();
|
|
2636
|
+
return;
|
|
2637
|
+
}
|
|
2638
|
+
const now = Date.now();
|
|
2639
|
+
const elapsed = now - submitStartedAt;
|
|
2582
2640
|
const screenText = this.terminalScreen.getText();
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
}
|
|
2598
|
-
if (submitDelayMs > 0) {
|
|
2599
|
-
this.submitPendingUntil = Date.now() + submitDelayMs;
|
|
2600
|
-
}
|
|
2601
|
-
this.ptyProcess.write(text);
|
|
2602
|
-
this.recordTrace("submit_write", {
|
|
2603
|
-
mode: "type_then_submit",
|
|
2604
|
-
text: summarizeCliTraceText(text, 500),
|
|
2605
|
-
sendKey: this.sendKey,
|
|
2606
|
-
screenText: summarizeCliTraceText(this.terminalScreen.getText(), 500)
|
|
2607
|
-
});
|
|
2608
|
-
const submitStartedAt = Date.now();
|
|
2609
|
-
let lastNormalizedScreen = "";
|
|
2610
|
-
let lastScreenChangeAt = submitStartedAt;
|
|
2611
|
-
const waitForEchoAndSubmit = () => {
|
|
2612
|
-
if (!this.ptyProcess) return;
|
|
2613
|
-
const now = Date.now();
|
|
2614
|
-
const elapsed = now - submitStartedAt;
|
|
2615
|
-
const screenText = this.terminalScreen.getText();
|
|
2616
|
-
const normalizedScreen = normalizePromptText(screenText);
|
|
2617
|
-
if (normalizedScreen !== lastNormalizedScreen) {
|
|
2618
|
-
lastNormalizedScreen = normalizedScreen;
|
|
2619
|
-
lastScreenChangeAt = now;
|
|
2620
|
-
}
|
|
2621
|
-
const echoVisible = !normalizedPromptSnippet || promptLikelyVisible(screenText, normalizedPromptSnippet);
|
|
2622
|
-
if (echoVisible) {
|
|
2623
|
-
const screenSettled = now - lastScreenChangeAt >= 500;
|
|
2624
|
-
if (elapsed >= submitDelayMs && screenSettled) {
|
|
2641
|
+
const normalizedScreen = normalizePromptText(screenText);
|
|
2642
|
+
if (normalizedScreen !== lastNormalizedScreen) {
|
|
2643
|
+
lastNormalizedScreen = normalizedScreen;
|
|
2644
|
+
lastScreenChangeAt = now;
|
|
2645
|
+
}
|
|
2646
|
+
const echoVisible = !normalizedPromptSnippet || promptLikelyVisible(screenText, normalizedPromptSnippet);
|
|
2647
|
+
if (echoVisible) {
|
|
2648
|
+
const screenSettled = now - lastScreenChangeAt >= 500;
|
|
2649
|
+
if (elapsed >= submitDelayMs && screenSettled) {
|
|
2650
|
+
submit();
|
|
2651
|
+
return;
|
|
2652
|
+
}
|
|
2653
|
+
}
|
|
2654
|
+
if (elapsed >= maxEchoWaitMs) {
|
|
2625
2655
|
submit();
|
|
2626
2656
|
return;
|
|
2627
2657
|
}
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
}
|
|
2633
|
-
setTimeout(waitForEchoAndSubmit, 50);
|
|
2634
|
-
};
|
|
2635
|
-
waitForEchoAndSubmit();
|
|
2658
|
+
setTimeout(waitForEchoAndSubmit, 50);
|
|
2659
|
+
};
|
|
2660
|
+
waitForEchoAndSubmit();
|
|
2661
|
+
});
|
|
2636
2662
|
}
|
|
2637
2663
|
getPartialResponse() {
|
|
2638
2664
|
if (!this.isWaitingForResponse) return "";
|
|
@@ -6874,11 +6900,24 @@ var WORKING_STATUSES = /* @__PURE__ */ new Set([
|
|
|
6874
6900
|
"thinking",
|
|
6875
6901
|
"active"
|
|
6876
6902
|
]);
|
|
6877
|
-
var
|
|
6878
|
-
|
|
6879
|
-
|
|
6880
|
-
|
|
6881
|
-
|
|
6903
|
+
var FULL_STATUS_ACTIVE_CHAT_OPTIONS = {
|
|
6904
|
+
includeMessages: true,
|
|
6905
|
+
includeInputContent: true,
|
|
6906
|
+
includeActiveModal: true,
|
|
6907
|
+
messageLimit: 60,
|
|
6908
|
+
totalBytesLimit: 96 * 1024,
|
|
6909
|
+
stringLimit: 4 * 1024,
|
|
6910
|
+
fallbackStringLimit: 1024
|
|
6911
|
+
};
|
|
6912
|
+
var LIVE_STATUS_ACTIVE_CHAT_OPTIONS = {
|
|
6913
|
+
includeMessages: false,
|
|
6914
|
+
includeInputContent: false,
|
|
6915
|
+
includeActiveModal: false,
|
|
6916
|
+
messageLimit: 0,
|
|
6917
|
+
totalBytesLimit: 0,
|
|
6918
|
+
stringLimit: 512,
|
|
6919
|
+
fallbackStringLimit: 256
|
|
6920
|
+
};
|
|
6882
6921
|
var STATUS_MODAL_MESSAGE_LIMIT = 2 * 1024;
|
|
6883
6922
|
var STATUS_MODAL_BUTTON_LIMIT = 120;
|
|
6884
6923
|
function truncateString(value, maxChars) {
|
|
@@ -6917,19 +6956,20 @@ function normalizeMessageTime(message) {
|
|
|
6917
6956
|
}
|
|
6918
6957
|
return msg;
|
|
6919
6958
|
}
|
|
6920
|
-
function trimMessagesForStatus(messages) {
|
|
6959
|
+
function trimMessagesForStatus(messages, options) {
|
|
6960
|
+
if (!options.includeMessages || options.messageLimit <= 0 || options.totalBytesLimit <= 0) return [];
|
|
6921
6961
|
if (!Array.isArray(messages) || messages.length === 0) return [];
|
|
6922
|
-
const recent = messages.slice(-
|
|
6962
|
+
const recent = messages.slice(-options.messageLimit);
|
|
6923
6963
|
const kept = [];
|
|
6924
6964
|
let totalBytes = 0;
|
|
6925
6965
|
for (let i = recent.length - 1; i >= 0; i -= 1) {
|
|
6926
|
-
let normalized = normalizeMessageTime(trimMessageForStatus(recent[i],
|
|
6966
|
+
let normalized = normalizeMessageTime(trimMessageForStatus(recent[i], options.stringLimit));
|
|
6927
6967
|
let size = estimateBytes(normalized);
|
|
6928
|
-
if (size >
|
|
6929
|
-
normalized = normalizeMessageTime(trimMessageForStatus(recent[i],
|
|
6968
|
+
if (size > options.totalBytesLimit) {
|
|
6969
|
+
normalized = normalizeMessageTime(trimMessageForStatus(recent[i], options.fallbackStringLimit));
|
|
6930
6970
|
size = estimateBytes(normalized);
|
|
6931
6971
|
}
|
|
6932
|
-
if (kept.length > 0 && totalBytes + size >
|
|
6972
|
+
if (kept.length > 0 && totalBytes + size > options.totalBytesLimit) {
|
|
6933
6973
|
continue;
|
|
6934
6974
|
}
|
|
6935
6975
|
kept.push(normalized);
|
|
@@ -6959,23 +6999,40 @@ function isManagedStatusWorking(status) {
|
|
|
6959
6999
|
function isManagedStatusWaiting(status, opts) {
|
|
6960
7000
|
return normalizeManagedStatus(status, opts) === "waiting_approval";
|
|
6961
7001
|
}
|
|
6962
|
-
function normalizeActiveChatData(activeChat) {
|
|
7002
|
+
function normalizeActiveChatData(activeChat, options = FULL_STATUS_ACTIVE_CHAT_OPTIONS) {
|
|
6963
7003
|
if (!activeChat) return activeChat;
|
|
7004
|
+
const resolvedOptions = {
|
|
7005
|
+
...FULL_STATUS_ACTIVE_CHAT_OPTIONS,
|
|
7006
|
+
...options
|
|
7007
|
+
};
|
|
6964
7008
|
return {
|
|
6965
7009
|
...activeChat,
|
|
6966
7010
|
status: normalizeManagedStatus(activeChat.status, { activeModal: activeChat.activeModal }),
|
|
6967
|
-
messages: trimMessagesForStatus(activeChat.messages),
|
|
6968
|
-
activeModal: activeChat.activeModal ? {
|
|
7011
|
+
messages: trimMessagesForStatus(activeChat.messages, resolvedOptions),
|
|
7012
|
+
activeModal: resolvedOptions.includeActiveModal && activeChat.activeModal ? {
|
|
6969
7013
|
message: truncateString(activeChat.activeModal.message || "", STATUS_MODAL_MESSAGE_LIMIT),
|
|
6970
7014
|
buttons: (activeChat.activeModal.buttons || []).map(
|
|
6971
7015
|
(button) => truncateString(String(button || ""), STATUS_MODAL_BUTTON_LIMIT)
|
|
6972
7016
|
)
|
|
6973
|
-
} :
|
|
6974
|
-
inputContent: activeChat.inputContent ? truncateString(activeChat.inputContent,
|
|
7017
|
+
} : null,
|
|
7018
|
+
inputContent: resolvedOptions.includeInputContent && activeChat.inputContent ? truncateString(activeChat.inputContent, 2 * 1024) : void 0
|
|
6975
7019
|
};
|
|
6976
7020
|
}
|
|
6977
7021
|
|
|
6978
7022
|
// src/status/builders.ts
|
|
7023
|
+
function getActiveChatOptions(profile) {
|
|
7024
|
+
if (profile === "full") return {};
|
|
7025
|
+
return LIVE_STATUS_ACTIVE_CHAT_OPTIONS;
|
|
7026
|
+
}
|
|
7027
|
+
function shouldIncludeSessionControls(profile) {
|
|
7028
|
+
return profile !== "live";
|
|
7029
|
+
}
|
|
7030
|
+
function shouldIncludeSessionMetadata(profile) {
|
|
7031
|
+
return profile !== "live";
|
|
7032
|
+
}
|
|
7033
|
+
function shouldIncludeRuntimeMetadata(profile) {
|
|
7034
|
+
return profile !== "live";
|
|
7035
|
+
}
|
|
6979
7036
|
function findCdpManager(cdpManagers, key) {
|
|
6980
7037
|
const exact = cdpManagers.get(key);
|
|
6981
7038
|
if (exact) return exact;
|
|
@@ -7083,74 +7140,88 @@ var ACP_SESSION_CAPABILITIES = [
|
|
|
7083
7140
|
"set_mode",
|
|
7084
7141
|
"set_thought_level"
|
|
7085
7142
|
];
|
|
7086
|
-
function buildIdeWorkspaceSession(state, cdpManagers) {
|
|
7087
|
-
const
|
|
7143
|
+
function buildIdeWorkspaceSession(state, cdpManagers, options) {
|
|
7144
|
+
const profile = options.profile || "full";
|
|
7145
|
+
const activeChat = normalizeActiveChatData(state.activeChat, getActiveChatOptions(profile));
|
|
7146
|
+
const includeSessionMetadata = shouldIncludeSessionMetadata(profile);
|
|
7147
|
+
const includeSessionControls = shouldIncludeSessionControls(profile);
|
|
7088
7148
|
const title = activeChat?.title || state.name;
|
|
7089
7149
|
return {
|
|
7090
7150
|
id: state.instanceId || state.type,
|
|
7091
7151
|
parentId: null,
|
|
7092
7152
|
providerType: state.type,
|
|
7093
|
-
providerName: state.name,
|
|
7153
|
+
...includeSessionMetadata && { providerName: state.name },
|
|
7094
7154
|
kind: "workspace",
|
|
7095
7155
|
transport: "cdp-page",
|
|
7096
7156
|
status: normalizeManagedStatus(activeChat?.status || state.status, {
|
|
7097
7157
|
activeModal: activeChat?.activeModal || null
|
|
7098
7158
|
}),
|
|
7099
7159
|
title,
|
|
7100
|
-
workspace: state.workspace || null,
|
|
7160
|
+
...includeSessionMetadata && { workspace: state.workspace || null },
|
|
7101
7161
|
activeChat,
|
|
7102
|
-
capabilities: IDE_SESSION_CAPABILITIES,
|
|
7162
|
+
...includeSessionMetadata && { capabilities: IDE_SESSION_CAPABILITIES },
|
|
7103
7163
|
cdpConnected: state.cdpConnected ?? isCdpConnected(cdpManagers, state.type),
|
|
7104
7164
|
currentModel: state.currentModel,
|
|
7105
7165
|
currentPlan: state.currentPlan,
|
|
7106
7166
|
currentAutoApprove: state.currentAutoApprove,
|
|
7107
|
-
|
|
7108
|
-
|
|
7109
|
-
|
|
7110
|
-
|
|
7111
|
-
|
|
7112
|
-
|
|
7167
|
+
...includeSessionControls && {
|
|
7168
|
+
controlValues: state.controlValues,
|
|
7169
|
+
providerControls: buildFallbackControls(
|
|
7170
|
+
state.providerControls,
|
|
7171
|
+
state.currentModel,
|
|
7172
|
+
state.currentPlan
|
|
7173
|
+
)
|
|
7174
|
+
},
|
|
7113
7175
|
errorMessage: state.errorMessage,
|
|
7114
7176
|
errorReason: state.errorReason,
|
|
7115
7177
|
lastUpdated: state.lastUpdated
|
|
7116
7178
|
};
|
|
7117
7179
|
}
|
|
7118
|
-
function buildExtensionAgentSession(parent, ext) {
|
|
7119
|
-
const
|
|
7180
|
+
function buildExtensionAgentSession(parent, ext, options) {
|
|
7181
|
+
const profile = options.profile || "full";
|
|
7182
|
+
const activeChat = normalizeActiveChatData(ext.activeChat, getActiveChatOptions(profile));
|
|
7183
|
+
const includeSessionMetadata = shouldIncludeSessionMetadata(profile);
|
|
7184
|
+
const includeSessionControls = shouldIncludeSessionControls(profile);
|
|
7120
7185
|
return {
|
|
7121
7186
|
id: ext.instanceId || `${parent.instanceId}:${ext.type}`,
|
|
7122
7187
|
parentId: parent.instanceId || parent.type,
|
|
7123
7188
|
providerType: ext.type,
|
|
7124
|
-
providerName: ext.name,
|
|
7189
|
+
...includeSessionMetadata && { providerName: ext.name },
|
|
7125
7190
|
kind: "agent",
|
|
7126
7191
|
transport: "cdp-webview",
|
|
7127
7192
|
status: normalizeManagedStatus(activeChat?.status || ext.status, {
|
|
7128
7193
|
activeModal: activeChat?.activeModal || null
|
|
7129
7194
|
}),
|
|
7130
7195
|
title: activeChat?.title || ext.name,
|
|
7131
|
-
workspace: parent.workspace || null,
|
|
7196
|
+
...includeSessionMetadata && { workspace: parent.workspace || null },
|
|
7132
7197
|
activeChat,
|
|
7133
|
-
capabilities: EXTENSION_SESSION_CAPABILITIES,
|
|
7198
|
+
...includeSessionMetadata && { capabilities: EXTENSION_SESSION_CAPABILITIES },
|
|
7134
7199
|
currentModel: ext.currentModel,
|
|
7135
7200
|
currentPlan: ext.currentPlan,
|
|
7136
|
-
|
|
7137
|
-
|
|
7138
|
-
|
|
7139
|
-
|
|
7140
|
-
|
|
7141
|
-
|
|
7201
|
+
...includeSessionControls && {
|
|
7202
|
+
controlValues: ext.controlValues,
|
|
7203
|
+
providerControls: buildFallbackControls(
|
|
7204
|
+
ext.providerControls,
|
|
7205
|
+
ext.currentModel,
|
|
7206
|
+
ext.currentPlan
|
|
7207
|
+
)
|
|
7208
|
+
},
|
|
7142
7209
|
errorMessage: ext.errorMessage,
|
|
7143
7210
|
errorReason: ext.errorReason,
|
|
7144
7211
|
lastUpdated: ext.lastUpdated
|
|
7145
7212
|
};
|
|
7146
7213
|
}
|
|
7147
|
-
function buildCliSession(state) {
|
|
7148
|
-
const
|
|
7214
|
+
function buildCliSession(state, options) {
|
|
7215
|
+
const profile = options.profile || "full";
|
|
7216
|
+
const activeChat = normalizeActiveChatData(state.activeChat, getActiveChatOptions(profile));
|
|
7217
|
+
const includeSessionMetadata = shouldIncludeSessionMetadata(profile);
|
|
7218
|
+
const includeRuntimeMetadata = shouldIncludeRuntimeMetadata(profile);
|
|
7219
|
+
const includeSessionControls = shouldIncludeSessionControls(profile);
|
|
7149
7220
|
return {
|
|
7150
7221
|
id: state.instanceId,
|
|
7151
7222
|
parentId: null,
|
|
7152
7223
|
providerType: state.type,
|
|
7153
|
-
providerName: state.name,
|
|
7224
|
+
...includeSessionMetadata && { providerName: state.name },
|
|
7154
7225
|
providerSessionId: state.providerSessionId,
|
|
7155
7226
|
kind: "agent",
|
|
7156
7227
|
transport: "pty",
|
|
@@ -7158,74 +7229,85 @@ function buildCliSession(state) {
|
|
|
7158
7229
|
activeModal: activeChat?.activeModal || null
|
|
7159
7230
|
}),
|
|
7160
7231
|
title: activeChat?.title || state.name,
|
|
7161
|
-
workspace: state.workspace || null,
|
|
7162
|
-
|
|
7163
|
-
|
|
7164
|
-
|
|
7165
|
-
|
|
7166
|
-
|
|
7232
|
+
...includeSessionMetadata && { workspace: state.workspace || null },
|
|
7233
|
+
...includeRuntimeMetadata && {
|
|
7234
|
+
runtimeKey: state.runtime?.runtimeKey,
|
|
7235
|
+
runtimeDisplayName: state.runtime?.displayName,
|
|
7236
|
+
runtimeWorkspaceLabel: state.runtime?.workspaceLabel,
|
|
7237
|
+
runtimeWriteOwner: state.runtime?.writeOwner || null,
|
|
7238
|
+
runtimeAttachedClients: state.runtime?.attachedClients || []
|
|
7239
|
+
},
|
|
7167
7240
|
mode: state.mode,
|
|
7168
7241
|
resume: state.resume,
|
|
7169
7242
|
activeChat,
|
|
7170
|
-
|
|
7171
|
-
|
|
7172
|
-
|
|
7173
|
-
|
|
7174
|
-
|
|
7243
|
+
...includeSessionMetadata && {
|
|
7244
|
+
capabilities: state.mode === "terminal" ? PTY_SESSION_CAPABILITIES : CLI_CHAT_SESSION_CAPABILITIES
|
|
7245
|
+
},
|
|
7246
|
+
...includeSessionControls && {
|
|
7247
|
+
controlValues: state.controlValues,
|
|
7248
|
+
providerControls: buildFallbackControls(
|
|
7249
|
+
state.providerControls
|
|
7250
|
+
)
|
|
7251
|
+
},
|
|
7175
7252
|
errorMessage: state.errorMessage,
|
|
7176
7253
|
errorReason: state.errorReason,
|
|
7177
7254
|
lastUpdated: state.lastUpdated
|
|
7178
7255
|
};
|
|
7179
7256
|
}
|
|
7180
|
-
function buildAcpSession(state) {
|
|
7181
|
-
const
|
|
7257
|
+
function buildAcpSession(state, options) {
|
|
7258
|
+
const profile = options.profile || "full";
|
|
7259
|
+
const activeChat = normalizeActiveChatData(state.activeChat, getActiveChatOptions(profile));
|
|
7260
|
+
const includeSessionMetadata = shouldIncludeSessionMetadata(profile);
|
|
7261
|
+
const includeSessionControls = shouldIncludeSessionControls(profile);
|
|
7182
7262
|
return {
|
|
7183
7263
|
id: state.instanceId,
|
|
7184
7264
|
parentId: null,
|
|
7185
7265
|
providerType: state.type,
|
|
7186
|
-
providerName: state.name,
|
|
7266
|
+
...includeSessionMetadata && { providerName: state.name },
|
|
7187
7267
|
kind: "agent",
|
|
7188
7268
|
transport: "acp",
|
|
7189
7269
|
status: normalizeManagedStatus(activeChat?.status || state.status, {
|
|
7190
7270
|
activeModal: activeChat?.activeModal || null
|
|
7191
7271
|
}),
|
|
7192
7272
|
title: activeChat?.title || state.name,
|
|
7193
|
-
workspace: state.workspace || null,
|
|
7273
|
+
...includeSessionMetadata && { workspace: state.workspace || null },
|
|
7194
7274
|
activeChat,
|
|
7195
|
-
capabilities: ACP_SESSION_CAPABILITIES,
|
|
7275
|
+
...includeSessionMetadata && { capabilities: ACP_SESSION_CAPABILITIES },
|
|
7196
7276
|
currentModel: state.currentModel,
|
|
7197
7277
|
currentPlan: state.currentPlan,
|
|
7198
|
-
|
|
7199
|
-
|
|
7200
|
-
|
|
7201
|
-
|
|
7202
|
-
|
|
7203
|
-
|
|
7204
|
-
|
|
7205
|
-
|
|
7206
|
-
|
|
7207
|
-
|
|
7278
|
+
...includeSessionControls && {
|
|
7279
|
+
acpConfigOptions: state.acpConfigOptions,
|
|
7280
|
+
acpModes: state.acpModes,
|
|
7281
|
+
controlValues: state.controlValues,
|
|
7282
|
+
providerControls: buildFallbackControls(
|
|
7283
|
+
state.providerControls,
|
|
7284
|
+
state.currentModel,
|
|
7285
|
+
state.currentPlan,
|
|
7286
|
+
state.acpConfigOptions,
|
|
7287
|
+
state.acpModes
|
|
7288
|
+
)
|
|
7289
|
+
},
|
|
7208
7290
|
errorMessage: state.errorMessage,
|
|
7209
7291
|
errorReason: state.errorReason,
|
|
7210
7292
|
lastUpdated: state.lastUpdated
|
|
7211
7293
|
};
|
|
7212
7294
|
}
|
|
7213
|
-
function buildSessionEntries(allStates, cdpManagers) {
|
|
7295
|
+
function buildSessionEntries(allStates, cdpManagers, options = {}) {
|
|
7214
7296
|
const sessions = [];
|
|
7215
7297
|
const ideStates = allStates.filter((s) => s.category === "ide");
|
|
7216
7298
|
const cliStates = allStates.filter((s) => s.category === "cli");
|
|
7217
7299
|
const acpStates = allStates.filter((s) => s.category === "acp");
|
|
7218
7300
|
for (const state of ideStates) {
|
|
7219
|
-
sessions.push(buildIdeWorkspaceSession(state, cdpManagers));
|
|
7301
|
+
sessions.push(buildIdeWorkspaceSession(state, cdpManagers, options));
|
|
7220
7302
|
for (const ext of state.extensions) {
|
|
7221
|
-
sessions.push(buildExtensionAgentSession(state, ext));
|
|
7303
|
+
sessions.push(buildExtensionAgentSession(state, ext, options));
|
|
7222
7304
|
}
|
|
7223
7305
|
}
|
|
7224
7306
|
for (const state of cliStates) {
|
|
7225
|
-
sessions.push(buildCliSession(state));
|
|
7307
|
+
sessions.push(buildCliSession(state, options));
|
|
7226
7308
|
}
|
|
7227
7309
|
for (const state of acpStates) {
|
|
7228
|
-
sessions.push(buildAcpSession(state));
|
|
7310
|
+
sessions.push(buildAcpSession(state, options));
|
|
7229
7311
|
}
|
|
7230
7312
|
const extensionParentIds = new Set(
|
|
7231
7313
|
sessions.filter((session) => session.transport === "cdp-webview" && !!session.parentId).map((session) => session.parentId)
|
|
@@ -7286,10 +7368,29 @@ function reconcileIdeRuntimeSessions(instanceManager, sessionRegistry) {
|
|
|
7286
7368
|
// src/commands/handler.ts
|
|
7287
7369
|
init_logger();
|
|
7288
7370
|
|
|
7371
|
+
// src/providers/contracts.ts
|
|
7372
|
+
function flattenContent(content) {
|
|
7373
|
+
if (typeof content === "string") return content;
|
|
7374
|
+
return content.filter((b) => b.type === "text").map((b) => b.text).join("\n");
|
|
7375
|
+
}
|
|
7376
|
+
|
|
7289
7377
|
// src/commands/chat-commands.ts
|
|
7290
7378
|
init_logger();
|
|
7291
7379
|
var RECENT_SEND_WINDOW_MS = 1200;
|
|
7292
7380
|
var recentSendByTarget = /* @__PURE__ */ new Map();
|
|
7381
|
+
function hashSignatureParts(parts) {
|
|
7382
|
+
let hash = 2166136261;
|
|
7383
|
+
for (const part of parts) {
|
|
7384
|
+
const text = String(part || "");
|
|
7385
|
+
for (let i = 0; i < text.length; i += 1) {
|
|
7386
|
+
hash ^= text.charCodeAt(i);
|
|
7387
|
+
hash = Math.imul(hash, 16777619) >>> 0;
|
|
7388
|
+
}
|
|
7389
|
+
hash ^= 255;
|
|
7390
|
+
hash = Math.imul(hash, 16777619) >>> 0;
|
|
7391
|
+
}
|
|
7392
|
+
return hash.toString(16).padStart(8, "0");
|
|
7393
|
+
}
|
|
7293
7394
|
function getCurrentProviderType(h, fallback = "") {
|
|
7294
7395
|
return h.currentSession?.providerType || h.currentProviderType || fallback;
|
|
7295
7396
|
}
|
|
@@ -7363,6 +7464,134 @@ function parseMaybeJson(value) {
|
|
|
7363
7464
|
return value;
|
|
7364
7465
|
}
|
|
7365
7466
|
}
|
|
7467
|
+
function getChatMessageSignature(message) {
|
|
7468
|
+
if (!message) return "";
|
|
7469
|
+
let content = "";
|
|
7470
|
+
try {
|
|
7471
|
+
content = JSON.stringify(message.content ?? "");
|
|
7472
|
+
} catch {
|
|
7473
|
+
content = String(message.content ?? "");
|
|
7474
|
+
}
|
|
7475
|
+
return hashSignatureParts([
|
|
7476
|
+
String(message.id || ""),
|
|
7477
|
+
String(message.index ?? ""),
|
|
7478
|
+
String(message.role || ""),
|
|
7479
|
+
String(message.receivedAt ?? message.timestamp ?? ""),
|
|
7480
|
+
content
|
|
7481
|
+
]);
|
|
7482
|
+
}
|
|
7483
|
+
function normalizeReadChatCursor(args) {
|
|
7484
|
+
const knownMessageCount = Math.max(0, Number(args?.knownMessageCount || 0));
|
|
7485
|
+
const lastMessageSignature = typeof args?.lastMessageSignature === "string" ? args.lastMessageSignature : "";
|
|
7486
|
+
const tailLimit = Math.max(0, Number(args?.tailLimit || 0));
|
|
7487
|
+
return { knownMessageCount, lastMessageSignature, tailLimit };
|
|
7488
|
+
}
|
|
7489
|
+
function normalizeReadChatMessages(payload) {
|
|
7490
|
+
const messages = Array.isArray(payload.messages) ? payload.messages : [];
|
|
7491
|
+
return messages;
|
|
7492
|
+
}
|
|
7493
|
+
function deriveHistoryDedupKey(message) {
|
|
7494
|
+
const unitKey = typeof message._unitKey === "string" ? message._unitKey.trim() : "";
|
|
7495
|
+
if (unitKey) return `read_chat:${unitKey}`;
|
|
7496
|
+
const turnKey = typeof message._turnKey === "string" ? message._turnKey.trim() : "";
|
|
7497
|
+
if (!turnKey) return void 0;
|
|
7498
|
+
let content = "";
|
|
7499
|
+
try {
|
|
7500
|
+
content = JSON.stringify(message.content ?? "");
|
|
7501
|
+
} catch {
|
|
7502
|
+
content = String(message.content ?? "");
|
|
7503
|
+
}
|
|
7504
|
+
return `read_chat:${turnKey}:${String(message.role || "").toLowerCase()}:${content}`;
|
|
7505
|
+
}
|
|
7506
|
+
function toHistoryPersistedMessages(messages) {
|
|
7507
|
+
return messages.map((message) => ({
|
|
7508
|
+
role: message.role,
|
|
7509
|
+
content: flattenContent(message.content),
|
|
7510
|
+
receivedAt: typeof message.receivedAt === "number" ? message.receivedAt : void 0,
|
|
7511
|
+
kind: typeof message.kind === "string" ? message.kind : void 0,
|
|
7512
|
+
senderName: typeof message.senderName === "string" ? message.senderName : void 0,
|
|
7513
|
+
historyDedupKey: deriveHistoryDedupKey(message)
|
|
7514
|
+
}));
|
|
7515
|
+
}
|
|
7516
|
+
function computeReadChatSync(messages, cursor) {
|
|
7517
|
+
const totalMessages = messages.length;
|
|
7518
|
+
const lastMessageSignature = getChatMessageSignature(messages[totalMessages - 1]);
|
|
7519
|
+
const { knownMessageCount, lastMessageSignature: knownSignature } = cursor;
|
|
7520
|
+
if (!knownMessageCount || !knownSignature) {
|
|
7521
|
+
return {
|
|
7522
|
+
syncMode: "full",
|
|
7523
|
+
replaceFrom: 0,
|
|
7524
|
+
messages,
|
|
7525
|
+
totalMessages,
|
|
7526
|
+
lastMessageSignature
|
|
7527
|
+
};
|
|
7528
|
+
}
|
|
7529
|
+
if (knownMessageCount > totalMessages) {
|
|
7530
|
+
return {
|
|
7531
|
+
syncMode: "full",
|
|
7532
|
+
replaceFrom: 0,
|
|
7533
|
+
messages,
|
|
7534
|
+
totalMessages,
|
|
7535
|
+
lastMessageSignature
|
|
7536
|
+
};
|
|
7537
|
+
}
|
|
7538
|
+
if (knownMessageCount === totalMessages && knownSignature === lastMessageSignature) {
|
|
7539
|
+
return {
|
|
7540
|
+
syncMode: "noop",
|
|
7541
|
+
replaceFrom: totalMessages,
|
|
7542
|
+
messages: [],
|
|
7543
|
+
totalMessages,
|
|
7544
|
+
lastMessageSignature
|
|
7545
|
+
};
|
|
7546
|
+
}
|
|
7547
|
+
if (knownMessageCount < totalMessages) {
|
|
7548
|
+
const anchorSignature = getChatMessageSignature(messages[knownMessageCount - 1]);
|
|
7549
|
+
if (anchorSignature === knownSignature) {
|
|
7550
|
+
return {
|
|
7551
|
+
syncMode: "append",
|
|
7552
|
+
replaceFrom: knownMessageCount,
|
|
7553
|
+
messages: messages.slice(knownMessageCount),
|
|
7554
|
+
totalMessages,
|
|
7555
|
+
lastMessageSignature
|
|
7556
|
+
};
|
|
7557
|
+
}
|
|
7558
|
+
}
|
|
7559
|
+
const replaceFrom = Math.max(0, Math.min(knownMessageCount - 1, totalMessages));
|
|
7560
|
+
return {
|
|
7561
|
+
syncMode: replaceFrom === 0 ? "full" : "replace_tail",
|
|
7562
|
+
replaceFrom,
|
|
7563
|
+
messages: replaceFrom === 0 ? messages : messages.slice(replaceFrom),
|
|
7564
|
+
totalMessages,
|
|
7565
|
+
lastMessageSignature
|
|
7566
|
+
};
|
|
7567
|
+
}
|
|
7568
|
+
function buildReadChatCommandResult(payload, args) {
|
|
7569
|
+
const messages = normalizeReadChatMessages(payload);
|
|
7570
|
+
const cursor = normalizeReadChatCursor(args);
|
|
7571
|
+
if (!cursor.knownMessageCount && !cursor.lastMessageSignature && cursor.tailLimit > 0 && messages.length > cursor.tailLimit) {
|
|
7572
|
+
const tailMessages = messages.slice(-cursor.tailLimit);
|
|
7573
|
+
const lastMessageSignature = getChatMessageSignature(tailMessages[tailMessages.length - 1]);
|
|
7574
|
+
return {
|
|
7575
|
+
success: true,
|
|
7576
|
+
...payload,
|
|
7577
|
+
messages: tailMessages,
|
|
7578
|
+
syncMode: "full",
|
|
7579
|
+
replaceFrom: 0,
|
|
7580
|
+
totalMessages: messages.length,
|
|
7581
|
+
lastMessageSignature
|
|
7582
|
+
};
|
|
7583
|
+
}
|
|
7584
|
+
const sync = computeReadChatSync(messages, cursor);
|
|
7585
|
+
return {
|
|
7586
|
+
success: true,
|
|
7587
|
+
...payload,
|
|
7588
|
+
messages: sync.messages,
|
|
7589
|
+
syncMode: sync.syncMode,
|
|
7590
|
+
replaceFrom: sync.replaceFrom,
|
|
7591
|
+
totalMessages: sync.totalMessages,
|
|
7592
|
+
lastMessageSignature: sync.lastMessageSignature
|
|
7593
|
+
};
|
|
7594
|
+
}
|
|
7366
7595
|
function didProviderConfirmSend(result) {
|
|
7367
7596
|
const parsed = parseMaybeJson(result);
|
|
7368
7597
|
if (parsed === true) return true;
|
|
@@ -7436,12 +7665,11 @@ async function handleReadChat(h, args) {
|
|
|
7436
7665
|
_log(`${transport} adapter: ${adapter.cliType}`);
|
|
7437
7666
|
const status = adapter.getStatus();
|
|
7438
7667
|
if (status) {
|
|
7439
|
-
return {
|
|
7440
|
-
success: true,
|
|
7668
|
+
return buildReadChatCommandResult({
|
|
7441
7669
|
messages: status.messages || [],
|
|
7442
7670
|
status: status.status,
|
|
7443
7671
|
activeModal: status.activeModal
|
|
7444
|
-
};
|
|
7672
|
+
}, args);
|
|
7445
7673
|
}
|
|
7446
7674
|
}
|
|
7447
7675
|
return { success: false, error: `${transport} adapter not found` };
|
|
@@ -7461,12 +7689,12 @@ async function handleReadChat(h, args) {
|
|
|
7461
7689
|
_log(`Extension OK: ${parsed.messages?.length || 0} msgs`);
|
|
7462
7690
|
h.historyWriter.appendNewMessages(
|
|
7463
7691
|
provider?.type || "unknown_extension",
|
|
7464
|
-
parsed
|
|
7692
|
+
toHistoryPersistedMessages(normalizeReadChatMessages(parsed)),
|
|
7465
7693
|
parsed.title,
|
|
7466
7694
|
args?.targetSessionId,
|
|
7467
7695
|
historySessionId
|
|
7468
7696
|
);
|
|
7469
|
-
return
|
|
7697
|
+
return buildReadChatCommandResult(parsed, args);
|
|
7470
7698
|
}
|
|
7471
7699
|
}
|
|
7472
7700
|
} catch (e) {
|
|
@@ -7478,21 +7706,25 @@ async function handleReadChat(h, args) {
|
|
|
7478
7706
|
if (cdp2 && parentSessionId) {
|
|
7479
7707
|
const stream = await h.agentStream.collectActiveSession(cdp2, parentSessionId);
|
|
7480
7708
|
if (stream?.agentType !== provider?.type) {
|
|
7481
|
-
return {
|
|
7709
|
+
return buildReadChatCommandResult({ messages: [], status: "idle" }, args);
|
|
7482
7710
|
}
|
|
7483
7711
|
if (stream) {
|
|
7484
7712
|
h.historyWriter.appendNewMessages(
|
|
7485
7713
|
stream.agentType,
|
|
7486
|
-
stream.messages || [],
|
|
7714
|
+
toHistoryPersistedMessages(stream.messages || []),
|
|
7487
7715
|
void 0,
|
|
7488
7716
|
args?.targetSessionId,
|
|
7489
7717
|
historySessionId
|
|
7490
7718
|
);
|
|
7491
|
-
return {
|
|
7719
|
+
return buildReadChatCommandResult({
|
|
7720
|
+
messages: stream.messages || [],
|
|
7721
|
+
status: stream.status,
|
|
7722
|
+
agentType: stream.agentType
|
|
7723
|
+
}, args);
|
|
7492
7724
|
}
|
|
7493
7725
|
}
|
|
7494
7726
|
}
|
|
7495
|
-
return {
|
|
7727
|
+
return buildReadChatCommandResult({ messages: [], status: "idle" }, args);
|
|
7496
7728
|
}
|
|
7497
7729
|
const cdp = h.getCdp();
|
|
7498
7730
|
if (!cdp?.isConnected) return { success: false, error: "CDP not connected" };
|
|
@@ -7514,18 +7746,18 @@ async function handleReadChat(h, args) {
|
|
|
7514
7746
|
_log(`Webview OK: ${parsed.messages?.length || 0} msgs`);
|
|
7515
7747
|
h.historyWriter.appendNewMessages(
|
|
7516
7748
|
provider?.type || getCurrentProviderType(h, "unknown_webview"),
|
|
7517
|
-
parsed
|
|
7749
|
+
toHistoryPersistedMessages(normalizeReadChatMessages(parsed)),
|
|
7518
7750
|
parsed.title,
|
|
7519
7751
|
args?.targetSessionId,
|
|
7520
7752
|
historySessionId
|
|
7521
7753
|
);
|
|
7522
|
-
return
|
|
7754
|
+
return buildReadChatCommandResult(parsed, args);
|
|
7523
7755
|
}
|
|
7524
7756
|
}
|
|
7525
7757
|
} catch (e) {
|
|
7526
7758
|
_log(`Webview readChat error: ${e.message}`);
|
|
7527
7759
|
}
|
|
7528
|
-
return {
|
|
7760
|
+
return buildReadChatCommandResult({ messages: [], status: "idle" }, args);
|
|
7529
7761
|
}
|
|
7530
7762
|
const script = h.getProviderScript("readChat") || h.getProviderScript("read_chat");
|
|
7531
7763
|
if (script) {
|
|
@@ -7542,18 +7774,18 @@ async function handleReadChat(h, args) {
|
|
|
7542
7774
|
_log(`OK: ${parsed.messages?.length} msgs`);
|
|
7543
7775
|
h.historyWriter.appendNewMessages(
|
|
7544
7776
|
provider?.type || getCurrentProviderType(h, "unknown_ide"),
|
|
7545
|
-
parsed
|
|
7777
|
+
toHistoryPersistedMessages(normalizeReadChatMessages(parsed)),
|
|
7546
7778
|
parsed.title,
|
|
7547
7779
|
args?.targetSessionId,
|
|
7548
7780
|
historySessionId
|
|
7549
7781
|
);
|
|
7550
|
-
return
|
|
7782
|
+
return buildReadChatCommandResult(parsed, args);
|
|
7551
7783
|
}
|
|
7552
7784
|
} catch (e) {
|
|
7553
7785
|
LOG.info("Command", `[read_chat] Script error: ${e.message}`);
|
|
7554
7786
|
}
|
|
7555
7787
|
}
|
|
7556
|
-
return {
|
|
7788
|
+
return buildReadChatCommandResult({ messages: [], status: "idle" }, args);
|
|
7557
7789
|
}
|
|
7558
7790
|
async function handleSendChat(h, args) {
|
|
7559
7791
|
const text = args?.text || args?.message;
|
|
@@ -8674,21 +8906,21 @@ function applyProviderPatch(h, args, payload) {
|
|
|
8674
8906
|
});
|
|
8675
8907
|
}
|
|
8676
8908
|
async function executeProviderScript(h, args, scriptName) {
|
|
8677
|
-
const
|
|
8678
|
-
if (!
|
|
8909
|
+
const resolvedProviderType = h.currentSession?.providerType || h.currentProviderType || args?.agentType || args?.providerType;
|
|
8910
|
+
if (!resolvedProviderType) return { success: false, error: "targetSessionId or providerType is required" };
|
|
8679
8911
|
const loader = h.ctx.providerLoader;
|
|
8680
8912
|
if (!loader) return { success: false, error: "ProviderLoader not initialized" };
|
|
8681
|
-
const provider = loader.resolve(
|
|
8682
|
-
if (!provider) return { success: false, error: `Provider not found: ${
|
|
8913
|
+
const provider = loader.resolve(resolvedProviderType);
|
|
8914
|
+
if (!provider) return { success: false, error: `Provider not found: ${resolvedProviderType}` };
|
|
8683
8915
|
const webviewScriptName = `webview${scriptName.charAt(0).toUpperCase() + scriptName.slice(1)}`;
|
|
8684
8916
|
const hasWebviewScript = provider.category === "ide" && !!provider.scripts?.[webviewScriptName];
|
|
8685
8917
|
const actualScriptName = hasWebviewScript ? webviewScriptName : scriptName;
|
|
8686
8918
|
if (!provider.scripts?.[actualScriptName]) {
|
|
8687
|
-
return { success: false, error: `Script '${actualScriptName}' not available for ${
|
|
8919
|
+
return { success: false, error: `Script '${actualScriptName}' not available for ${resolvedProviderType}` };
|
|
8688
8920
|
}
|
|
8689
8921
|
const normalizedArgs = normalizeProviderScriptArgs(args);
|
|
8690
8922
|
if (provider.category === "cli") {
|
|
8691
|
-
const adapter = h.getCliAdapter(args?.targetSessionId ||
|
|
8923
|
+
const adapter = h.getCliAdapter(args?.targetSessionId || resolvedProviderType);
|
|
8692
8924
|
if (!adapter?.invokeScript) {
|
|
8693
8925
|
return { success: false, error: `CLI adapter does not support script '${actualScriptName}'` };
|
|
8694
8926
|
}
|
|
@@ -8713,7 +8945,7 @@ async function executeProviderScript(h, args, scriptName) {
|
|
|
8713
8945
|
const scriptFn = provider.scripts[actualScriptName];
|
|
8714
8946
|
const scriptCode = scriptFn(normalizedArgs);
|
|
8715
8947
|
if (!scriptCode) return { success: false, error: `Script '${actualScriptName}' returned null` };
|
|
8716
|
-
const cdpKey = provider.category === "ide" ? h.currentSession?.cdpManagerKey || h.currentManagerKey ||
|
|
8948
|
+
const cdpKey = provider.category === "ide" ? h.currentSession?.cdpManagerKey || h.currentManagerKey || resolvedProviderType : h.currentSession?.cdpManagerKey || h.currentManagerKey;
|
|
8717
8949
|
LOG.info("Command", `[ExtScript] provider=${provider.type} category=${provider.category} cdpKey=${cdpKey}`);
|
|
8718
8950
|
const cdp = h.getCdp(cdpKey);
|
|
8719
8951
|
if (!cdp?.isConnected) return { success: false, error: `No CDP connection for ${cdpKey || "any"}` };
|
|
@@ -8721,7 +8953,7 @@ async function executeProviderScript(h, args, scriptName) {
|
|
|
8721
8953
|
let result;
|
|
8722
8954
|
if (provider.category === "extension") {
|
|
8723
8955
|
const runtimeSessionId = h.currentSession?.sessionId || args?.targetSessionId;
|
|
8724
|
-
if (!runtimeSessionId) return { success: false, error: `No target session found for ${
|
|
8956
|
+
if (!runtimeSessionId) return { success: false, error: `No target session found for ${resolvedProviderType}` };
|
|
8725
8957
|
const parentSessionId = h.currentSession?.parentSessionId;
|
|
8726
8958
|
if (parentSessionId) {
|
|
8727
8959
|
await h.agentStream?.setActiveSession(cdp, parentSessionId, runtimeSessionId);
|
|
@@ -8750,7 +8982,7 @@ async function executeProviderScript(h, args, scriptName) {
|
|
|
8750
8982
|
}
|
|
8751
8983
|
} else {
|
|
8752
8984
|
if (!targetSessionId) {
|
|
8753
|
-
return { success: false, error: `No active session found for ${
|
|
8985
|
+
return { success: false, error: `No active session found for ${resolvedProviderType}` };
|
|
8754
8986
|
}
|
|
8755
8987
|
result = await cdp.evaluateInSessionFrame(targetSessionId, scriptCode);
|
|
8756
8988
|
}
|
|
@@ -10138,14 +10370,6 @@ import {
|
|
|
10138
10370
|
RequestError,
|
|
10139
10371
|
PROTOCOL_VERSION
|
|
10140
10372
|
} from "@agentclientprotocol/sdk";
|
|
10141
|
-
|
|
10142
|
-
// src/providers/contracts.ts
|
|
10143
|
-
function flattenContent(content) {
|
|
10144
|
-
if (typeof content === "string") return content;
|
|
10145
|
-
return content.filter((b) => b.type === "text").map((b) => b.text).join("\n");
|
|
10146
|
-
}
|
|
10147
|
-
|
|
10148
|
-
// src/providers/acp-provider-instance.ts
|
|
10149
10373
|
init_logger();
|
|
10150
10374
|
var AcpProviderInstance = class {
|
|
10151
10375
|
constructor(provider, workingDir, cliArgs = []) {
|
|
@@ -13511,6 +13735,37 @@ function buildAvailableProviders(providerLoader) {
|
|
|
13511
13735
|
...provider.detectedPath !== void 0 ? { detectedPath: provider.detectedPath } : {}
|
|
13512
13736
|
}));
|
|
13513
13737
|
}
|
|
13738
|
+
function buildMachineInfo(profile = "full") {
|
|
13739
|
+
const base = {
|
|
13740
|
+
hostname: os16.hostname(),
|
|
13741
|
+
platform: os16.platform()
|
|
13742
|
+
};
|
|
13743
|
+
if (profile === "live") {
|
|
13744
|
+
return base;
|
|
13745
|
+
}
|
|
13746
|
+
if (profile === "metadata") {
|
|
13747
|
+
const memSnap2 = getHostMemorySnapshot();
|
|
13748
|
+
return {
|
|
13749
|
+
...base,
|
|
13750
|
+
arch: os16.arch(),
|
|
13751
|
+
cpus: os16.cpus().length,
|
|
13752
|
+
totalMem: memSnap2.totalMem,
|
|
13753
|
+
release: os16.release()
|
|
13754
|
+
};
|
|
13755
|
+
}
|
|
13756
|
+
const memSnap = getHostMemorySnapshot();
|
|
13757
|
+
return {
|
|
13758
|
+
...base,
|
|
13759
|
+
arch: os16.arch(),
|
|
13760
|
+
cpus: os16.cpus().length,
|
|
13761
|
+
totalMem: memSnap.totalMem,
|
|
13762
|
+
freeMem: memSnap.freeMem,
|
|
13763
|
+
availableMem: memSnap.availableMem,
|
|
13764
|
+
loadavg: os16.loadavg(),
|
|
13765
|
+
uptime: os16.uptime(),
|
|
13766
|
+
release: os16.release()
|
|
13767
|
+
};
|
|
13768
|
+
}
|
|
13514
13769
|
function parseMessageTime(value) {
|
|
13515
13770
|
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
13516
13771
|
if (typeof value === "string") {
|
|
@@ -13566,26 +13821,35 @@ function buildRecentLaunches(recentActivity) {
|
|
|
13566
13821
|
})).sort((a, b) => b.lastLaunchedAt - a.lastLaunchedAt).slice(0, 12);
|
|
13567
13822
|
}
|
|
13568
13823
|
function buildStatusSnapshot(options) {
|
|
13824
|
+
const profile = options.profile || "full";
|
|
13569
13825
|
const cfg = loadConfig();
|
|
13570
13826
|
const state = loadState();
|
|
13571
13827
|
const wsState = getWorkspaceState(cfg);
|
|
13572
|
-
const memSnap = getHostMemorySnapshot();
|
|
13573
13828
|
const recentActivity = getRecentActivity(state, 20);
|
|
13574
|
-
const
|
|
13829
|
+
const unreadSourceSessions = buildSessionEntries(
|
|
13575
13830
|
options.allStates,
|
|
13576
|
-
options.cdpManagers
|
|
13831
|
+
options.cdpManagers,
|
|
13832
|
+
{ profile: "full" }
|
|
13577
13833
|
);
|
|
13578
|
-
|
|
13579
|
-
|
|
13580
|
-
|
|
13581
|
-
|
|
13582
|
-
|
|
13583
|
-
|
|
13584
|
-
|
|
13585
|
-
|
|
13834
|
+
const sessions = profile === "full" ? unreadSourceSessions : buildSessionEntries(
|
|
13835
|
+
options.allStates,
|
|
13836
|
+
options.cdpManagers,
|
|
13837
|
+
{ profile }
|
|
13838
|
+
);
|
|
13839
|
+
const sessionsById = new Map(sessions.map((session) => [session.id, session]));
|
|
13840
|
+
for (const sourceSession of unreadSourceSessions) {
|
|
13841
|
+
const session = sessionsById.get(sourceSession.id);
|
|
13842
|
+
if (!session) continue;
|
|
13843
|
+
const lastSeenAt = getSessionSeenAt(state, sourceSession.id);
|
|
13844
|
+
const seenCompletionMarker = getSessionSeenMarker(state, sourceSession.id);
|
|
13845
|
+
const lastUsedAt = getSessionLastUsedAt(sourceSession);
|
|
13846
|
+
const completionMarker = getSessionCompletionMarker(sourceSession);
|
|
13847
|
+
const { unread, inboxBucket } = sourceSession.surfaceHidden ? { unread: false, inboxBucket: "idle" } : getUnreadState(
|
|
13848
|
+
getSessionMessageUpdatedAt(sourceSession) > 0,
|
|
13849
|
+
sourceSession.status,
|
|
13586
13850
|
lastUsedAt,
|
|
13587
13851
|
lastSeenAt,
|
|
13588
|
-
getLastMessageRole(
|
|
13852
|
+
getLastMessageRole(sourceSession),
|
|
13589
13853
|
completionMarker,
|
|
13590
13854
|
seenCompletionMarker
|
|
13591
13855
|
);
|
|
@@ -13595,39 +13859,30 @@ function buildStatusSnapshot(options) {
|
|
|
13595
13859
|
if (READ_DEBUG_ENABLED && (session.unread || session.inboxBucket !== "idle" || session.providerType.includes("codex"))) {
|
|
13596
13860
|
LOG.info(
|
|
13597
13861
|
"RecentRead",
|
|
13598
|
-
`snapshot session id=${session.id} provider=${session.providerType} status=${String(session.status || "")} bucket=${inboxBucket} unread=${String(unread)} lastSeenAt=${lastSeenAt} completionMarker=${completionMarker || "-"} seenMarker=${seenCompletionMarker || "-"} lastUpdated=${String(session.lastUpdated || 0)} lastUsedAt=${lastUsedAt} lastRole=${getLastMessageRole(
|
|
13862
|
+
`snapshot session id=${session.id} provider=${session.providerType} status=${String(session.status || "")} bucket=${inboxBucket} unread=${String(unread)} lastSeenAt=${lastSeenAt} completionMarker=${completionMarker || "-"} seenMarker=${seenCompletionMarker || "-"} lastUpdated=${String(session.lastUpdated || 0)} lastUsedAt=${lastUsedAt} lastRole=${getLastMessageRole(sourceSession)} msgUpdatedAt=${getSessionMessageUpdatedAt(sourceSession)}`
|
|
13599
13863
|
);
|
|
13600
13864
|
}
|
|
13601
13865
|
}
|
|
13602
|
-
const
|
|
13866
|
+
const includeMachineMetadata = profile !== "live";
|
|
13867
|
+
const terminalBackend = includeMachineMetadata ? getTerminalBackendRuntimeStatus() : void 0;
|
|
13603
13868
|
return {
|
|
13604
13869
|
instanceId: options.instanceId,
|
|
13605
|
-
version: options.version,
|
|
13606
|
-
|
|
13607
|
-
|
|
13608
|
-
hostname: os16.hostname(),
|
|
13609
|
-
platform: os16.platform(),
|
|
13610
|
-
arch: os16.arch(),
|
|
13611
|
-
cpus: os16.cpus().length,
|
|
13612
|
-
totalMem: memSnap.totalMem,
|
|
13613
|
-
freeMem: memSnap.freeMem,
|
|
13614
|
-
availableMem: memSnap.availableMem,
|
|
13615
|
-
loadavg: os16.loadavg(),
|
|
13616
|
-
uptime: os16.uptime(),
|
|
13617
|
-
release: os16.release()
|
|
13618
|
-
},
|
|
13619
|
-
machineNickname: options.machineNickname ?? cfg.machineNickname ?? null,
|
|
13870
|
+
...includeMachineMetadata ? { version: options.version } : {},
|
|
13871
|
+
machine: buildMachineInfo(profile),
|
|
13872
|
+
...includeMachineMetadata ? { machineNickname: options.machineNickname ?? cfg.machineNickname ?? null } : {},
|
|
13620
13873
|
timestamp: options.timestamp ?? Date.now(),
|
|
13621
|
-
detectedIdes: buildDetectedIdeInfos(options.detectedIdes, options.cdpManagers),
|
|
13622
13874
|
...options.p2p ? { p2p: options.p2p } : {},
|
|
13623
13875
|
sessions,
|
|
13624
|
-
|
|
13625
|
-
|
|
13626
|
-
|
|
13627
|
-
|
|
13628
|
-
|
|
13629
|
-
|
|
13630
|
-
|
|
13876
|
+
...terminalBackend ? { terminalBackend } : {},
|
|
13877
|
+
...includeMachineMetadata && {
|
|
13878
|
+
detectedIdes: buildDetectedIdeInfos(options.detectedIdes, options.cdpManagers),
|
|
13879
|
+
workspaces: wsState.workspaces,
|
|
13880
|
+
defaultWorkspaceId: wsState.defaultWorkspaceId,
|
|
13881
|
+
defaultWorkspacePath: wsState.defaultWorkspacePath,
|
|
13882
|
+
terminalSizingMode: cfg.terminalSizingMode || "measured",
|
|
13883
|
+
recentLaunches: buildRecentLaunches(recentActivity),
|
|
13884
|
+
availableProviders: buildAvailableProviders(options.providerLoader)
|
|
13885
|
+
}
|
|
13631
13886
|
};
|
|
13632
13887
|
}
|
|
13633
13888
|
|
|
@@ -14183,6 +14438,25 @@ var DaemonCommandRouter = class {
|
|
|
14183
14438
|
updateConfig({ userName: name });
|
|
14184
14439
|
return { success: true, userName: name };
|
|
14185
14440
|
}
|
|
14441
|
+
case "get_status_metadata": {
|
|
14442
|
+
const snapshot = buildStatusSnapshot({
|
|
14443
|
+
allStates: this.deps.instanceManager.collectAllStates(),
|
|
14444
|
+
cdpManagers: this.deps.cdpManagers,
|
|
14445
|
+
providerLoader: this.deps.providerLoader,
|
|
14446
|
+
detectedIdes: this.deps.detectedIdes.value,
|
|
14447
|
+
instanceId: this.deps.statusInstanceId || loadConfig().machineId || "daemon",
|
|
14448
|
+
version: this.deps.statusVersion || "unknown",
|
|
14449
|
+
profile: "metadata"
|
|
14450
|
+
});
|
|
14451
|
+
return { success: true, status: snapshot };
|
|
14452
|
+
}
|
|
14453
|
+
case "get_machine_runtime_stats": {
|
|
14454
|
+
return {
|
|
14455
|
+
success: true,
|
|
14456
|
+
machine: buildMachineInfo("full"),
|
|
14457
|
+
timestamp: Date.now()
|
|
14458
|
+
};
|
|
14459
|
+
}
|
|
14186
14460
|
case "mark_session_seen": {
|
|
14187
14461
|
const sessionId = args?.sessionId;
|
|
14188
14462
|
if (!sessionId || typeof sessionId !== "string") {
|
|
@@ -14336,6 +14610,7 @@ var DaemonStatusReporter = class {
|
|
|
14336
14610
|
lastStatusSentAt = 0;
|
|
14337
14611
|
statusPendingThrottle = false;
|
|
14338
14612
|
lastP2PStatusHash = "";
|
|
14613
|
+
lastServerStatusHash = "";
|
|
14339
14614
|
lastStatusSummary = "";
|
|
14340
14615
|
statusTimer = null;
|
|
14341
14616
|
p2pTimer = null;
|
|
@@ -14346,11 +14621,11 @@ var DaemonStatusReporter = class {
|
|
|
14346
14621
|
// ─── Lifecycle ───────────────────────────────────
|
|
14347
14622
|
startReporting() {
|
|
14348
14623
|
setTimeout(() => {
|
|
14349
|
-
this.sendUnifiedStatusReport().catch((e) => LOG.warn("Status", `Initial report failed: ${e?.message}`));
|
|
14624
|
+
this.sendUnifiedStatusReport({ forceServer: true, reason: "initial" }).catch((e) => LOG.warn("Status", `Initial report failed: ${e?.message}`));
|
|
14350
14625
|
}, 2e3);
|
|
14351
14626
|
const scheduleServerReport = () => {
|
|
14352
14627
|
this.statusTimer = setTimeout(() => {
|
|
14353
|
-
this.sendUnifiedStatusReport().catch((e) => LOG.warn("Status", `Periodic report failed: ${e?.message}`));
|
|
14628
|
+
this.sendUnifiedStatusReport({ forceServer: true, reason: "periodic" }).catch((e) => LOG.warn("Status", `Periodic report failed: ${e?.message}`));
|
|
14354
14629
|
scheduleServerReport();
|
|
14355
14630
|
}, 3e4);
|
|
14356
14631
|
};
|
|
@@ -14387,9 +14662,58 @@ var DaemonStatusReporter = class {
|
|
|
14387
14662
|
}, 5e3 - elapsed);
|
|
14388
14663
|
}
|
|
14389
14664
|
}
|
|
14665
|
+
toDaemonStatusEventName(value) {
|
|
14666
|
+
switch (value) {
|
|
14667
|
+
case "agent:generating_started":
|
|
14668
|
+
case "agent:waiting_approval":
|
|
14669
|
+
case "agent:generating_completed":
|
|
14670
|
+
case "agent:stopped":
|
|
14671
|
+
case "monitor:long_generating":
|
|
14672
|
+
return value;
|
|
14673
|
+
default:
|
|
14674
|
+
return null;
|
|
14675
|
+
}
|
|
14676
|
+
}
|
|
14677
|
+
buildServerStatusEvent(event) {
|
|
14678
|
+
const eventName = this.toDaemonStatusEventName(event.event);
|
|
14679
|
+
if (!eventName) return null;
|
|
14680
|
+
if (eventName.startsWith("provider:")) {
|
|
14681
|
+
return null;
|
|
14682
|
+
}
|
|
14683
|
+
const payload = {
|
|
14684
|
+
event: eventName,
|
|
14685
|
+
timestamp: typeof event.timestamp === "number" && Number.isFinite(event.timestamp) ? event.timestamp : Date.now()
|
|
14686
|
+
};
|
|
14687
|
+
if (typeof event.targetSessionId === "string" && event.targetSessionId.trim()) {
|
|
14688
|
+
payload.targetSessionId = event.targetSessionId.trim();
|
|
14689
|
+
}
|
|
14690
|
+
const providerType = typeof event.providerType === "string" && event.providerType.trim() ? event.providerType.trim() : typeof event.ideType === "string" && event.ideType.trim() ? event.ideType.trim() : "";
|
|
14691
|
+
if (providerType) {
|
|
14692
|
+
payload.providerType = providerType;
|
|
14693
|
+
}
|
|
14694
|
+
if (typeof event.duration === "number" && Number.isFinite(event.duration)) {
|
|
14695
|
+
payload.duration = event.duration;
|
|
14696
|
+
}
|
|
14697
|
+
if (typeof event.elapsedSec === "number" && Number.isFinite(event.elapsedSec)) {
|
|
14698
|
+
payload.elapsedSec = event.elapsedSec;
|
|
14699
|
+
}
|
|
14700
|
+
if (typeof event.modalMessage === "string" && event.modalMessage.trim()) {
|
|
14701
|
+
payload.modalMessage = event.modalMessage;
|
|
14702
|
+
}
|
|
14703
|
+
if (Array.isArray(event.modalButtons)) {
|
|
14704
|
+
const modalButtons = event.modalButtons.filter((button) => typeof button === "string" && button.trim().length > 0);
|
|
14705
|
+
if (modalButtons.length > 0) {
|
|
14706
|
+
payload.modalButtons = modalButtons;
|
|
14707
|
+
}
|
|
14708
|
+
}
|
|
14709
|
+
return payload;
|
|
14710
|
+
}
|
|
14390
14711
|
emitStatusEvent(event) {
|
|
14391
14712
|
LOG.info("StatusEvent", `${event.event} (${event.providerType || event.ideType || ""})`);
|
|
14392
|
-
this.
|
|
14713
|
+
const serverEvent = this.buildServerStatusEvent(event);
|
|
14714
|
+
if (!serverEvent) return;
|
|
14715
|
+
this.deps.p2p?.sendStatusEvent(serverEvent);
|
|
14716
|
+
this.deps.serverConn?.sendMessage("status_event", serverEvent);
|
|
14393
14717
|
}
|
|
14394
14718
|
removeAgentTracking(_key) {
|
|
14395
14719
|
}
|
|
@@ -14458,17 +14782,16 @@ var DaemonStatusReporter = class {
|
|
|
14458
14782
|
detectedIdes: this.deps.detectedIdes || [],
|
|
14459
14783
|
instanceId: this.deps.instanceId,
|
|
14460
14784
|
version: this.deps.daemonVersion || "unknown",
|
|
14461
|
-
daemonMode: true,
|
|
14462
14785
|
timestamp: now,
|
|
14463
14786
|
p2p: {
|
|
14464
14787
|
available: p2p?.isAvailable || false,
|
|
14465
14788
|
state: p2p?.connectionState || "unavailable",
|
|
14466
14789
|
peers: p2p?.connectedPeerCount || 0,
|
|
14467
14790
|
screenshotActive: p2p?.screenshotActive || false
|
|
14468
|
-
}
|
|
14791
|
+
},
|
|
14792
|
+
profile: "live"
|
|
14469
14793
|
}),
|
|
14470
|
-
screenshotUsage: this.deps.getScreenshotUsage?.() || null
|
|
14471
|
-
connectedExtensions: []
|
|
14794
|
+
screenshotUsage: this.deps.getScreenshotUsage?.() || null
|
|
14472
14795
|
};
|
|
14473
14796
|
const payloadBytes = JSON.stringify(payload).length;
|
|
14474
14797
|
const p2pSent = this.sendP2PPayload(payload);
|
|
@@ -14483,46 +14806,48 @@ var DaemonStatusReporter = class {
|
|
|
14483
14806
|
}
|
|
14484
14807
|
if (opts?.p2pOnly) return;
|
|
14485
14808
|
const wsPayload = {
|
|
14486
|
-
daemonMode: true,
|
|
14487
14809
|
sessions: sessions.map((session) => ({
|
|
14488
14810
|
id: session.id,
|
|
14489
14811
|
parentId: session.parentId,
|
|
14490
14812
|
providerType: session.providerType,
|
|
14491
|
-
providerName: session.providerName,
|
|
14813
|
+
providerName: session.providerName || session.providerType,
|
|
14492
14814
|
kind: session.kind,
|
|
14493
14815
|
transport: session.transport,
|
|
14494
14816
|
status: session.status,
|
|
14495
|
-
workspace: session.workspace,
|
|
14817
|
+
workspace: session.workspace ?? null,
|
|
14496
14818
|
title: session.title,
|
|
14497
14819
|
cdpConnected: session.cdpConnected,
|
|
14498
14820
|
currentModel: session.currentModel,
|
|
14499
14821
|
currentPlan: session.currentPlan,
|
|
14500
|
-
currentAutoApprove: session.currentAutoApprove
|
|
14501
|
-
lastUpdated: session.lastUpdated,
|
|
14502
|
-
unread: session.unread,
|
|
14503
|
-
lastSeenAt: session.lastSeenAt,
|
|
14504
|
-
inboxBucket: session.inboxBucket,
|
|
14505
|
-
surfaceHidden: session.surfaceHidden,
|
|
14506
|
-
controlValues: session.controlValues,
|
|
14507
|
-
providerControls: session.providerControls,
|
|
14508
|
-
acpConfigOptions: session.acpConfigOptions,
|
|
14509
|
-
acpModes: session.acpModes
|
|
14822
|
+
currentAutoApprove: session.currentAutoApprove
|
|
14510
14823
|
})),
|
|
14511
14824
|
p2p: payload.p2p,
|
|
14512
|
-
timestamp: now
|
|
14513
|
-
detectedIdes: payload.detectedIdes,
|
|
14514
|
-
availableProviders: payload.availableProviders
|
|
14825
|
+
timestamp: now
|
|
14515
14826
|
};
|
|
14827
|
+
const wsHash = this.simpleHash(JSON.stringify({
|
|
14828
|
+
...wsPayload,
|
|
14829
|
+
timestamp: void 0
|
|
14830
|
+
}));
|
|
14831
|
+
if (!opts?.forceServer && wsHash === this.lastServerStatusHash) {
|
|
14832
|
+
LOG.debug("Server", `skip duplicate status_report${opts?.reason ? ` (${opts.reason})` : ""}`);
|
|
14833
|
+
return;
|
|
14834
|
+
}
|
|
14835
|
+
this.lastServerStatusHash = wsHash;
|
|
14516
14836
|
serverConn.sendMessage("status_report", wsPayload);
|
|
14517
|
-
LOG.debug("Server", `sent status_report (${JSON.stringify(wsPayload).length} bytes)`);
|
|
14837
|
+
LOG.debug("Server", `sent status_report (${JSON.stringify(wsPayload).length} bytes)${opts?.reason ? ` [${opts.reason}]` : ""}`);
|
|
14518
14838
|
}
|
|
14519
14839
|
// ─── P2P ─────────────────────────────────────────
|
|
14520
14840
|
sendP2PPayload(payload) {
|
|
14521
14841
|
const { timestamp: _ts, system: _sys, ...hashTarget } = payload;
|
|
14842
|
+
const sessions = Array.isArray(hashTarget.sessions) ? hashTarget.sessions.map((session) => {
|
|
14843
|
+
if (!session || typeof session !== "object") return session;
|
|
14844
|
+
const { lastUpdated: _lu, ...stableSession } = session;
|
|
14845
|
+
return stableSession;
|
|
14846
|
+
}) : hashTarget.sessions;
|
|
14522
14847
|
const hashPayload = hashTarget.machine ? (() => {
|
|
14523
14848
|
const { freeMem: _f, availableMem: _a, loadavg: _l, uptime: _u, ...stableMachine } = hashTarget.machine;
|
|
14524
|
-
return { ...hashTarget, machine: stableMachine };
|
|
14525
|
-
})() : hashTarget;
|
|
14849
|
+
return { ...hashTarget, sessions, machine: stableMachine };
|
|
14850
|
+
})() : { ...hashTarget, sessions };
|
|
14526
14851
|
const h = this.simpleHash(JSON.stringify(hashPayload));
|
|
14527
14852
|
if (h !== this.lastP2PStatusHash) {
|
|
14528
14853
|
this.lastP2PStatusHash = h;
|
|
@@ -21625,6 +21950,8 @@ async function initDaemonComponents(config) {
|
|
|
21625
21950
|
onStatusChange: config.onStatusChange,
|
|
21626
21951
|
onPostChatCommand: config.onPostChatCommand,
|
|
21627
21952
|
sessionHostControl: config.sessionHostControl,
|
|
21953
|
+
statusInstanceId: config.statusInstanceId,
|
|
21954
|
+
statusVersion: config.statusVersion,
|
|
21628
21955
|
getCdpLogFn: config.getCdpLogFn || ((ideType) => LOG.forComponent(`CDP:${ideType}`).asLogFn())
|
|
21629
21956
|
});
|
|
21630
21957
|
poller = new AgentStreamPoller({
|
|
@@ -21726,6 +22053,7 @@ export {
|
|
|
21726
22053
|
SessionHostPtyTransportFactory,
|
|
21727
22054
|
VersionArchive,
|
|
21728
22055
|
appendRecentActivity,
|
|
22056
|
+
buildMachineInfo,
|
|
21729
22057
|
buildSessionEntries,
|
|
21730
22058
|
buildStatusSnapshot,
|
|
21731
22059
|
connectCdpManager,
|