adhdev 0.7.41 → 0.7.42
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/cli/index.js +360 -123
- package/dist/cli/index.js.map +1 -1
- package/dist/index.js +360 -121
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -34,7 +34,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
34
34
|
// ../../oss/packages/daemon-core/src/config/config.ts
|
|
35
35
|
var config_exports = {};
|
|
36
36
|
__export(config_exports, {
|
|
37
|
-
generateConnectionToken: () => generateConnectionToken,
|
|
38
37
|
generateMachineId: () => generateMachineId,
|
|
39
38
|
getConfigDir: () => getConfigDir,
|
|
40
39
|
isSetupComplete: () => isSetupComplete,
|
|
@@ -45,6 +44,57 @@ __export(config_exports, {
|
|
|
45
44
|
saveConfig: () => saveConfig,
|
|
46
45
|
updateConfig: () => updateConfig
|
|
47
46
|
});
|
|
47
|
+
function isPlainObject(value) {
|
|
48
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
49
|
+
}
|
|
50
|
+
function asStringArray(value) {
|
|
51
|
+
if (!Array.isArray(value)) return [];
|
|
52
|
+
return value.filter((item) => typeof item === "string");
|
|
53
|
+
}
|
|
54
|
+
function asNullableString(value) {
|
|
55
|
+
return typeof value === "string" ? value : null;
|
|
56
|
+
}
|
|
57
|
+
function asOptionalString(value) {
|
|
58
|
+
return typeof value === "string" && value.trim() ? value : void 0;
|
|
59
|
+
}
|
|
60
|
+
function asBoolean(value, fallback) {
|
|
61
|
+
return typeof value === "boolean" ? value : fallback;
|
|
62
|
+
}
|
|
63
|
+
function normalizeConfig(raw) {
|
|
64
|
+
const parsed = isPlainObject(raw) ? raw : {};
|
|
65
|
+
const legacySessionReads = isPlainObject(parsed.recentSessionReads) ? parsed.recentSessionReads : {};
|
|
66
|
+
const sessionReads = isPlainObject(parsed.sessionReads) ? parsed.sessionReads : {};
|
|
67
|
+
const mergedSessionReads = Object.fromEntries(
|
|
68
|
+
Object.entries({ ...legacySessionReads, ...sessionReads }).filter(([, value]) => typeof value === "number" && Number.isFinite(value))
|
|
69
|
+
);
|
|
70
|
+
const sessionReadMarkers = Object.fromEntries(
|
|
71
|
+
Object.entries(isPlainObject(parsed.sessionReadMarkers) ? parsed.sessionReadMarkers : {}).filter(([, value]) => typeof value === "string")
|
|
72
|
+
);
|
|
73
|
+
return {
|
|
74
|
+
serverUrl: typeof parsed.serverUrl === "string" && parsed.serverUrl.trim() ? parsed.serverUrl : DEFAULT_CONFIG.serverUrl,
|
|
75
|
+
selectedIde: asNullableString(parsed.selectedIde),
|
|
76
|
+
configuredIdes: asStringArray(parsed.configuredIdes),
|
|
77
|
+
installedExtensions: asStringArray(parsed.installedExtensions),
|
|
78
|
+
userEmail: asNullableString(parsed.userEmail),
|
|
79
|
+
userName: asNullableString(parsed.userName),
|
|
80
|
+
setupCompleted: asBoolean(parsed.setupCompleted, DEFAULT_CONFIG.setupCompleted),
|
|
81
|
+
setupDate: asNullableString(parsed.setupDate),
|
|
82
|
+
enabledIdes: asStringArray(parsed.enabledIdes),
|
|
83
|
+
workspaces: Array.isArray(parsed.workspaces) ? parsed.workspaces : [],
|
|
84
|
+
defaultWorkspaceId: asNullableString(parsed.defaultWorkspaceId) ?? asNullableString(parsed.activeWorkspaceId),
|
|
85
|
+
recentActivity: Array.isArray(parsed.recentActivity) ? parsed.recentActivity : [],
|
|
86
|
+
sessionReads: mergedSessionReads,
|
|
87
|
+
sessionReadMarkers,
|
|
88
|
+
machineNickname: asNullableString(parsed.machineNickname),
|
|
89
|
+
machineId: asOptionalString(parsed.machineId),
|
|
90
|
+
machineSecret: parsed.machineSecret === null ? null : asOptionalString(parsed.machineSecret),
|
|
91
|
+
registeredMachineId: asOptionalString(parsed.registeredMachineId),
|
|
92
|
+
providerSettings: isPlainObject(parsed.providerSettings) ? parsed.providerSettings : {},
|
|
93
|
+
ideSettings: isPlainObject(parsed.ideSettings) ? parsed.ideSettings : {},
|
|
94
|
+
disableUpstream: asBoolean(parsed.disableUpstream, DEFAULT_CONFIG.disableUpstream ?? false),
|
|
95
|
+
providerDir: asOptionalString(parsed.providerDir)
|
|
96
|
+
};
|
|
97
|
+
}
|
|
48
98
|
function generateMachineId() {
|
|
49
99
|
return `${MACHINE_ID_PREFIX}${(0, import_crypto.randomUUID)().replace(/-/g, "")}`;
|
|
50
100
|
}
|
|
@@ -88,14 +138,10 @@ function loadConfig() {
|
|
|
88
138
|
try {
|
|
89
139
|
const raw = (0, import_fs.readFileSync)(configPath, "utf-8");
|
|
90
140
|
const parsed = JSON.parse(raw);
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
merged.defaultWorkspaceId = merged.activeWorkspaceId;
|
|
94
|
-
}
|
|
95
|
-
delete merged.activeWorkspaceId;
|
|
96
|
-
const ensured = ensureMachineId(merged);
|
|
141
|
+
const normalizedInput = normalizeConfig(parsed);
|
|
142
|
+
const ensured = ensureMachineId(normalizedInput);
|
|
97
143
|
const normalized = ensured.config;
|
|
98
|
-
if (ensured.changed) {
|
|
144
|
+
if (ensured.changed || JSON.stringify(parsed) !== JSON.stringify(normalized)) {
|
|
99
145
|
try {
|
|
100
146
|
saveConfig(normalized);
|
|
101
147
|
} catch {
|
|
@@ -110,10 +156,11 @@ function loadConfig() {
|
|
|
110
156
|
function saveConfig(config2) {
|
|
111
157
|
const configPath = getConfigPath();
|
|
112
158
|
const dir = getConfigDir();
|
|
159
|
+
const normalized = normalizeConfig(config2);
|
|
113
160
|
if (!(0, import_fs.existsSync)(dir)) {
|
|
114
161
|
(0, import_fs.mkdirSync)(dir, { recursive: true, mode: 448 });
|
|
115
162
|
}
|
|
116
|
-
(0, import_fs.writeFileSync)(configPath, JSON.stringify(
|
|
163
|
+
(0, import_fs.writeFileSync)(configPath, JSON.stringify(normalized, null, 2), { encoding: "utf-8", mode: 384 });
|
|
117
164
|
try {
|
|
118
165
|
(0, import_fs.chmodSync)(configPath, 384);
|
|
119
166
|
} catch {
|
|
@@ -142,14 +189,6 @@ function isSetupComplete() {
|
|
|
142
189
|
function resetConfig() {
|
|
143
190
|
saveConfig({ ...DEFAULT_CONFIG });
|
|
144
191
|
}
|
|
145
|
-
function generateConnectionToken() {
|
|
146
|
-
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
147
|
-
let token = "db_";
|
|
148
|
-
for (let i = 0; i < 32; i++) {
|
|
149
|
-
token += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
150
|
-
}
|
|
151
|
-
return token;
|
|
152
|
-
}
|
|
153
192
|
var import_os, import_path, import_fs, import_crypto, DEFAULT_CONFIG, MACHINE_ID_PREFIX;
|
|
154
193
|
var init_config = __esm({
|
|
155
194
|
"../../oss/packages/daemon-core/src/config/config.ts"() {
|
|
@@ -160,18 +199,13 @@ var init_config = __esm({
|
|
|
160
199
|
import_crypto = require("crypto");
|
|
161
200
|
DEFAULT_CONFIG = {
|
|
162
201
|
serverUrl: "https://api.adhf.dev",
|
|
163
|
-
apiToken: null,
|
|
164
|
-
connectionToken: null,
|
|
165
202
|
selectedIde: null,
|
|
166
203
|
configuredIdes: [],
|
|
167
204
|
installedExtensions: [],
|
|
168
|
-
autoConnect: true,
|
|
169
|
-
notifications: true,
|
|
170
205
|
userEmail: null,
|
|
171
206
|
userName: null,
|
|
172
207
|
setupCompleted: false,
|
|
173
208
|
setupDate: null,
|
|
174
|
-
configuredCLIs: [],
|
|
175
209
|
enabledIdes: [],
|
|
176
210
|
workspaces: [],
|
|
177
211
|
defaultWorkspaceId: null,
|
|
@@ -2345,6 +2379,8 @@ var init_extension_provider_instance = __esm({
|
|
|
2345
2379
|
this.detectTransition(newStatus, data);
|
|
2346
2380
|
this.currentStatus = newStatus;
|
|
2347
2381
|
}
|
|
2382
|
+
} else if (event === "stream_reset") {
|
|
2383
|
+
this.resetStreamState();
|
|
2348
2384
|
} else if (event === "extension_connected") {
|
|
2349
2385
|
this.ideType = data?.ideType || "";
|
|
2350
2386
|
}
|
|
@@ -2424,6 +2460,30 @@ var init_extension_provider_instance = __esm({
|
|
|
2424
2460
|
const title = typeof data?.title === "string" && data.title.trim() ? data.title.trim() : this.chatTitle;
|
|
2425
2461
|
return title || this.agentName || this.provider.name;
|
|
2426
2462
|
}
|
|
2463
|
+
resetStreamState() {
|
|
2464
|
+
if (this.currentStatus !== "idle") {
|
|
2465
|
+
this.detectTransition("idle", {
|
|
2466
|
+
title: this.chatTitle,
|
|
2467
|
+
agentName: this.agentName,
|
|
2468
|
+
extensionId: this.extensionId,
|
|
2469
|
+
messages: this.messages
|
|
2470
|
+
});
|
|
2471
|
+
}
|
|
2472
|
+
this.agentStreams = [];
|
|
2473
|
+
this.messages = [];
|
|
2474
|
+
this.activeModal = null;
|
|
2475
|
+
this.currentModel = "";
|
|
2476
|
+
this.currentMode = "";
|
|
2477
|
+
this.controlValues = {};
|
|
2478
|
+
this.currentStatus = "idle";
|
|
2479
|
+
this.chatId = null;
|
|
2480
|
+
this.chatTitle = null;
|
|
2481
|
+
this.agentName = "";
|
|
2482
|
+
this.extensionId = "";
|
|
2483
|
+
this.lastAgentStatus = "idle";
|
|
2484
|
+
this.generatingStartedAt = 0;
|
|
2485
|
+
this.monitor.reset();
|
|
2486
|
+
}
|
|
2427
2487
|
};
|
|
2428
2488
|
}
|
|
2429
2489
|
});
|
|
@@ -2722,11 +2782,23 @@ var init_ide_provider_instance = __esm({
|
|
|
2722
2782
|
} else if (event === "cdp_disconnected") {
|
|
2723
2783
|
this.cachedChat = null;
|
|
2724
2784
|
this.currentStatus = "idle";
|
|
2785
|
+
for (const ext of this.extensions.values()) {
|
|
2786
|
+
ext.onEvent("stream_reset");
|
|
2787
|
+
}
|
|
2725
2788
|
} else if (event === "stream_update") {
|
|
2726
2789
|
const extType = data?.extensionType;
|
|
2727
2790
|
if (extType && this.extensions.has(extType)) {
|
|
2728
2791
|
this.extensions.get(extType).onEvent("stream_update", data);
|
|
2729
2792
|
}
|
|
2793
|
+
} else if (event === "stream_reset") {
|
|
2794
|
+
const extType = data?.extensionType;
|
|
2795
|
+
if (extType && this.extensions.has(extType)) {
|
|
2796
|
+
this.extensions.get(extType).onEvent("stream_reset");
|
|
2797
|
+
}
|
|
2798
|
+
} else if (event === "stream_reset_all") {
|
|
2799
|
+
for (const ext of this.extensions.values()) {
|
|
2800
|
+
ext.onEvent("stream_reset");
|
|
2801
|
+
}
|
|
2730
2802
|
}
|
|
2731
2803
|
}
|
|
2732
2804
|
dispose() {
|
|
@@ -3411,6 +3483,55 @@ var init_initializer = __esm({
|
|
|
3411
3483
|
});
|
|
3412
3484
|
|
|
3413
3485
|
// ../../oss/packages/daemon-core/src/status/normalize.ts
|
|
3486
|
+
function truncateString(value, maxChars) {
|
|
3487
|
+
if (value.length <= maxChars) return value;
|
|
3488
|
+
if (maxChars <= 12) return value.slice(0, Math.max(0, maxChars));
|
|
3489
|
+
return `${value.slice(0, maxChars - 12)}...[truncated]`;
|
|
3490
|
+
}
|
|
3491
|
+
function truncateStringTail(value, maxChars) {
|
|
3492
|
+
if (value.length <= maxChars) return value;
|
|
3493
|
+
if (maxChars <= 12) return value.slice(value.length - Math.max(0, maxChars));
|
|
3494
|
+
return `...[truncated]${value.slice(value.length - (maxChars - 12))}`;
|
|
3495
|
+
}
|
|
3496
|
+
function trimStructuredStrings(value, maxChars) {
|
|
3497
|
+
if (typeof value === "string") return truncateString(value, maxChars);
|
|
3498
|
+
if (Array.isArray(value)) return value.map((item) => trimStructuredStrings(item, maxChars));
|
|
3499
|
+
if (!value || typeof value !== "object") return value;
|
|
3500
|
+
return Object.fromEntries(
|
|
3501
|
+
Object.entries(value).map(([key, nested]) => [key, trimStructuredStrings(nested, maxChars)])
|
|
3502
|
+
);
|
|
3503
|
+
}
|
|
3504
|
+
function estimateBytes(value) {
|
|
3505
|
+
try {
|
|
3506
|
+
return JSON.stringify(value).length;
|
|
3507
|
+
} catch {
|
|
3508
|
+
return String(value ?? "").length;
|
|
3509
|
+
}
|
|
3510
|
+
}
|
|
3511
|
+
function trimMessageForStatus(message, stringLimit) {
|
|
3512
|
+
if (!message || typeof message !== "object") return message;
|
|
3513
|
+
return trimStructuredStrings(message, stringLimit);
|
|
3514
|
+
}
|
|
3515
|
+
function trimMessagesForStatus(messages) {
|
|
3516
|
+
if (!Array.isArray(messages) || messages.length === 0) return [];
|
|
3517
|
+
const recent = messages.slice(-STATUS_ACTIVE_CHAT_MESSAGE_LIMIT);
|
|
3518
|
+
const kept = [];
|
|
3519
|
+
let totalBytes = 0;
|
|
3520
|
+
for (let i = recent.length - 1; i >= 0; i -= 1) {
|
|
3521
|
+
let normalized = trimMessageForStatus(recent[i], STATUS_ACTIVE_CHAT_STRING_LIMIT);
|
|
3522
|
+
let size = estimateBytes(normalized);
|
|
3523
|
+
if (size > STATUS_ACTIVE_CHAT_TOTAL_BYTES_LIMIT) {
|
|
3524
|
+
normalized = trimMessageForStatus(recent[i], STATUS_ACTIVE_CHAT_FALLBACK_STRING_LIMIT);
|
|
3525
|
+
size = estimateBytes(normalized);
|
|
3526
|
+
}
|
|
3527
|
+
if (kept.length > 0 && totalBytes + size > STATUS_ACTIVE_CHAT_TOTAL_BYTES_LIMIT) {
|
|
3528
|
+
continue;
|
|
3529
|
+
}
|
|
3530
|
+
kept.push(normalized);
|
|
3531
|
+
totalBytes += size;
|
|
3532
|
+
}
|
|
3533
|
+
return kept.reverse();
|
|
3534
|
+
}
|
|
3414
3535
|
function hasApprovalButtons(activeModal) {
|
|
3415
3536
|
return (activeModal?.buttons?.length ?? 0) > 0;
|
|
3416
3537
|
}
|
|
@@ -3437,10 +3558,19 @@ function normalizeActiveChatData(activeChat) {
|
|
|
3437
3558
|
if (!activeChat) return activeChat;
|
|
3438
3559
|
return {
|
|
3439
3560
|
...activeChat,
|
|
3440
|
-
status: normalizeManagedStatus(activeChat.status, { activeModal: activeChat.activeModal })
|
|
3561
|
+
status: normalizeManagedStatus(activeChat.status, { activeModal: activeChat.activeModal }),
|
|
3562
|
+
messages: trimMessagesForStatus(activeChat.messages),
|
|
3563
|
+
activeModal: activeChat.activeModal ? {
|
|
3564
|
+
message: truncateString(activeChat.activeModal.message || "", STATUS_MODAL_MESSAGE_LIMIT),
|
|
3565
|
+
buttons: (activeChat.activeModal.buttons || []).map(
|
|
3566
|
+
(button) => truncateString(String(button || ""), STATUS_MODAL_BUTTON_LIMIT)
|
|
3567
|
+
)
|
|
3568
|
+
} : activeChat.activeModal,
|
|
3569
|
+
terminalHistory: activeChat.terminalHistory ? truncateStringTail(activeChat.terminalHistory, STATUS_TERMINAL_HISTORY_LIMIT) : activeChat.terminalHistory,
|
|
3570
|
+
inputContent: activeChat.inputContent ? truncateString(activeChat.inputContent, STATUS_INPUT_CONTENT_LIMIT) : activeChat.inputContent
|
|
3441
3571
|
};
|
|
3442
3572
|
}
|
|
3443
|
-
var WORKING_STATUSES;
|
|
3573
|
+
var WORKING_STATUSES, STATUS_ACTIVE_CHAT_MESSAGE_LIMIT, STATUS_ACTIVE_CHAT_TOTAL_BYTES_LIMIT, STATUS_ACTIVE_CHAT_STRING_LIMIT, STATUS_ACTIVE_CHAT_FALLBACK_STRING_LIMIT, STATUS_TERMINAL_HISTORY_LIMIT, STATUS_INPUT_CONTENT_LIMIT, STATUS_MODAL_MESSAGE_LIMIT, STATUS_MODAL_BUTTON_LIMIT;
|
|
3444
3574
|
var init_normalize = __esm({
|
|
3445
3575
|
"../../oss/packages/daemon-core/src/status/normalize.ts"() {
|
|
3446
3576
|
"use strict";
|
|
@@ -3452,6 +3582,14 @@ var init_normalize = __esm({
|
|
|
3452
3582
|
"thinking",
|
|
3453
3583
|
"active"
|
|
3454
3584
|
]);
|
|
3585
|
+
STATUS_ACTIVE_CHAT_MESSAGE_LIMIT = 60;
|
|
3586
|
+
STATUS_ACTIVE_CHAT_TOTAL_BYTES_LIMIT = 96 * 1024;
|
|
3587
|
+
STATUS_ACTIVE_CHAT_STRING_LIMIT = 4 * 1024;
|
|
3588
|
+
STATUS_ACTIVE_CHAT_FALLBACK_STRING_LIMIT = 1024;
|
|
3589
|
+
STATUS_TERMINAL_HISTORY_LIMIT = 8 * 1024;
|
|
3590
|
+
STATUS_INPUT_CONTENT_LIMIT = 2 * 1024;
|
|
3591
|
+
STATUS_MODAL_MESSAGE_LIMIT = 2 * 1024;
|
|
3592
|
+
STATUS_MODAL_BUTTON_LIMIT = 120;
|
|
3455
3593
|
}
|
|
3456
3594
|
});
|
|
3457
3595
|
|
|
@@ -3601,11 +3739,10 @@ function buildCliSession(state) {
|
|
|
3601
3739
|
runtimeWorkspaceLabel: state.runtime?.workspaceLabel,
|
|
3602
3740
|
runtimeWriteOwner: state.runtime?.writeOwner || null,
|
|
3603
3741
|
runtimeAttachedClients: state.runtime?.attachedClients || [],
|
|
3604
|
-
launchMode: state.launchMode,
|
|
3605
3742
|
mode: state.mode,
|
|
3606
3743
|
resume: state.resume,
|
|
3607
3744
|
activeChat,
|
|
3608
|
-
capabilities: PTY_SESSION_CAPABILITIES,
|
|
3745
|
+
capabilities: state.mode === "terminal" ? PTY_SESSION_CAPABILITIES : CLI_CHAT_SESSION_CAPABILITIES,
|
|
3609
3746
|
controlValues: state.controlValues,
|
|
3610
3747
|
providerControls: buildFallbackControls(
|
|
3611
3748
|
state.providerControls
|
|
@@ -3675,7 +3812,7 @@ function buildSessionEntries(allStates, cdpManagers) {
|
|
|
3675
3812
|
}
|
|
3676
3813
|
return sessions;
|
|
3677
3814
|
}
|
|
3678
|
-
var IDE_SESSION_CAPABILITIES, EXTENSION_SESSION_CAPABILITIES, PTY_SESSION_CAPABILITIES, ACP_SESSION_CAPABILITIES;
|
|
3815
|
+
var IDE_SESSION_CAPABILITIES, EXTENSION_SESSION_CAPABILITIES, PTY_SESSION_CAPABILITIES, CLI_CHAT_SESSION_CAPABILITIES, ACP_SESSION_CAPABILITIES;
|
|
3679
3816
|
var init_builders = __esm({
|
|
3680
3817
|
"../../oss/packages/daemon-core/src/status/builders.ts"() {
|
|
3681
3818
|
"use strict";
|
|
@@ -3708,6 +3845,11 @@ var init_builders = __esm({
|
|
|
3708
3845
|
"terminal_io",
|
|
3709
3846
|
"resize_terminal"
|
|
3710
3847
|
];
|
|
3848
|
+
CLI_CHAT_SESSION_CAPABILITIES = [
|
|
3849
|
+
"read_chat",
|
|
3850
|
+
"send_message",
|
|
3851
|
+
"resolve_action"
|
|
3852
|
+
];
|
|
3711
3853
|
ACP_SESSION_CAPABILITIES = [
|
|
3712
3854
|
"read_chat",
|
|
3713
3855
|
"send_message",
|
|
@@ -4832,6 +4974,13 @@ var init_cdp_commands = __esm({
|
|
|
4832
4974
|
});
|
|
4833
4975
|
|
|
4834
4976
|
// ../../oss/packages/daemon-core/src/commands/stream-commands.ts
|
|
4977
|
+
function getCliPresentationMode(h, targetSessionId) {
|
|
4978
|
+
if (!targetSessionId) return null;
|
|
4979
|
+
const instance = h.ctx.instanceManager?.getInstance(targetSessionId);
|
|
4980
|
+
if (instance?.category !== "cli") return null;
|
|
4981
|
+
const mode = instance.getPresentationMode?.();
|
|
4982
|
+
return mode === "chat" || mode === "terminal" ? mode : null;
|
|
4983
|
+
}
|
|
4835
4984
|
async function handleFocusSession(h, args) {
|
|
4836
4985
|
if (!h.agentStream || !h.getCdp()) return { success: false, error: "AgentStream or CDP not available" };
|
|
4837
4986
|
const sessionId = args?.targetSessionId || h.currentSession?.sessionId;
|
|
@@ -4842,6 +4991,9 @@ async function handleFocusSession(h, args) {
|
|
|
4842
4991
|
function handlePtyInput(h, args) {
|
|
4843
4992
|
const { cliType, data, targetSessionId } = args || {};
|
|
4844
4993
|
if (!data) return { success: false, error: "data required" };
|
|
4994
|
+
if (getCliPresentationMode(h, targetSessionId) === "chat") {
|
|
4995
|
+
return { success: false, error: "CLI session is in chat mode", code: "CLI_VIEW_MODE_NOT_TERMINAL" };
|
|
4996
|
+
}
|
|
4845
4997
|
const adapter = h.getCliAdapter(targetSessionId || cliType);
|
|
4846
4998
|
if (!adapter || typeof adapter.writeRaw !== "function") {
|
|
4847
4999
|
return { success: false, error: `CLI adapter not found: ${targetSessionId || cliType || "unknown"}` };
|
|
@@ -4852,6 +5004,9 @@ function handlePtyInput(h, args) {
|
|
|
4852
5004
|
function handlePtyResize(h, args) {
|
|
4853
5005
|
const { cliType, cols, rows, force, targetSessionId } = args || {};
|
|
4854
5006
|
if (!cols || !rows) return { success: false, error: "cols and rows required" };
|
|
5007
|
+
if (getCliPresentationMode(h, targetSessionId) === "chat") {
|
|
5008
|
+
return { success: false, error: "CLI session is in chat mode", code: "CLI_VIEW_MODE_NOT_TERMINAL" };
|
|
5009
|
+
}
|
|
4855
5010
|
const adapter = h.getCliAdapter(targetSessionId || cliType);
|
|
4856
5011
|
if (!adapter || typeof adapter.resize !== "function") {
|
|
4857
5012
|
return { success: false, error: `CLI adapter not found: ${targetSessionId || cliType || "unknown"}` };
|
|
@@ -18412,6 +18567,7 @@ var init_router = __esm({
|
|
|
18412
18567
|
// ─── CLI / ACP commands ───
|
|
18413
18568
|
case "launch_cli":
|
|
18414
18569
|
case "stop_cli":
|
|
18570
|
+
case "set_cli_view_mode":
|
|
18415
18571
|
case "agent_command": {
|
|
18416
18572
|
return this.deps.cliManager.handleCliCommand(cmd, args);
|
|
18417
18573
|
}
|
|
@@ -18764,6 +18920,20 @@ var init_reporter = __esm({
|
|
|
18764
18920
|
ts() {
|
|
18765
18921
|
return (/* @__PURE__ */ new Date()).toISOString().slice(11, 23);
|
|
18766
18922
|
}
|
|
18923
|
+
summarizeLargePayloadSessions(payload) {
|
|
18924
|
+
const sessions = Array.isArray(payload.sessions) ? payload.sessions : [];
|
|
18925
|
+
return sessions.map((session) => ({
|
|
18926
|
+
id: String(session?.id || ""),
|
|
18927
|
+
providerType: String(session?.providerType || ""),
|
|
18928
|
+
bytes: (() => {
|
|
18929
|
+
try {
|
|
18930
|
+
return JSON.stringify(session).length;
|
|
18931
|
+
} catch {
|
|
18932
|
+
return 0;
|
|
18933
|
+
}
|
|
18934
|
+
})()
|
|
18935
|
+
})).sort((a, b2) => b2.bytes - a.bytes).slice(0, 3).map((session) => `${session.providerType || "unknown"}:${session.id}=${session.bytes}b`).join(", ");
|
|
18936
|
+
}
|
|
18767
18937
|
async sendUnifiedStatusReport(opts) {
|
|
18768
18938
|
const { serverConn, p2p } = this.deps;
|
|
18769
18939
|
if (!serverConn?.isConnected()) return;
|
|
@@ -18816,9 +18986,16 @@ var init_reporter = __esm({
|
|
|
18816
18986
|
screenshotUsage: this.deps.getScreenshotUsage?.() || null,
|
|
18817
18987
|
connectedExtensions: []
|
|
18818
18988
|
};
|
|
18989
|
+
const payloadBytes = JSON.stringify(payload).length;
|
|
18819
18990
|
const p2pSent = this.sendP2PPayload(payload);
|
|
18820
18991
|
if (p2pSent) {
|
|
18821
|
-
LOG.debug("P2P", `sent (${
|
|
18992
|
+
LOG.debug("P2P", `sent (${payloadBytes} bytes)`);
|
|
18993
|
+
if (payloadBytes > 256 * 1024) {
|
|
18994
|
+
LOG.warn(
|
|
18995
|
+
"P2P",
|
|
18996
|
+
`large status payload (${payloadBytes} bytes) top sessions: ${this.summarizeLargePayloadSessions(payload) || "n/a"}`
|
|
18997
|
+
);
|
|
18998
|
+
}
|
|
18822
18999
|
}
|
|
18823
19000
|
if (opts?.p2pOnly) return;
|
|
18824
19001
|
const wsPayload = {
|
|
@@ -18848,7 +19025,9 @@ var init_reporter = __esm({
|
|
|
18848
19025
|
acpModes: session.acpModes
|
|
18849
19026
|
})),
|
|
18850
19027
|
p2p: payload.p2p,
|
|
18851
|
-
timestamp: now
|
|
19028
|
+
timestamp: now,
|
|
19029
|
+
detectedIdes: payload.detectedIdes,
|
|
19030
|
+
availableProviders: payload.availableProviders
|
|
18852
19031
|
};
|
|
18853
19032
|
serverConn.sendMessage("status_report", wsPayload);
|
|
18854
19033
|
LOG.debug("Server", `sent status_report (${JSON.stringify(wsPayload).length} bytes)`);
|
|
@@ -19220,6 +19399,13 @@ var init_provider_cli_adapter = __esm({
|
|
|
19220
19399
|
this.messages = [...this.committedMessages];
|
|
19221
19400
|
this.structuredMessages = [...this.committedMessages];
|
|
19222
19401
|
}
|
|
19402
|
+
normalizeParsedMessages(parsedMessages) {
|
|
19403
|
+
return parsedMessages.filter((message) => message && (message.role === "user" || message.role === "assistant")).map((message) => ({
|
|
19404
|
+
role: message.role,
|
|
19405
|
+
content: typeof message.content === "string" ? message.content : String(message.content || ""),
|
|
19406
|
+
timestamp: typeof message.timestamp === "number" && Number.isFinite(message.timestamp) ? message.timestamp : Date.now()
|
|
19407
|
+
}));
|
|
19408
|
+
}
|
|
19223
19409
|
sliceFromOffset(text, start) {
|
|
19224
19410
|
if (!text) return "";
|
|
19225
19411
|
if (!Number.isFinite(start) || start <= 0) return text;
|
|
@@ -19616,6 +19802,15 @@ var init_provider_cli_adapter = __esm({
|
|
|
19616
19802
|
this.onStatusChange?.();
|
|
19617
19803
|
}
|
|
19618
19804
|
commitCurrentTranscript() {
|
|
19805
|
+
const parsed = this.parseCurrentTranscript(
|
|
19806
|
+
this.committedMessages,
|
|
19807
|
+
this.responseBuffer,
|
|
19808
|
+
this.currentTurnScope
|
|
19809
|
+
);
|
|
19810
|
+
if (parsed && Array.isArray(parsed.messages)) {
|
|
19811
|
+
this.committedMessages = this.normalizeParsedMessages(parsed.messages);
|
|
19812
|
+
this.syncMessageViews();
|
|
19813
|
+
}
|
|
19619
19814
|
}
|
|
19620
19815
|
// ─── Script Execution ──────────────────────────
|
|
19621
19816
|
runDetectStatus(text) {
|
|
@@ -19660,6 +19855,21 @@ var init_provider_cli_adapter = __esm({
|
|
|
19660
19855
|
* Called by command handler / dashboard for rich content rendering.
|
|
19661
19856
|
*/
|
|
19662
19857
|
getScriptParsedStatus() {
|
|
19858
|
+
const parsed = this.parseCurrentTranscript(
|
|
19859
|
+
this.committedMessages,
|
|
19860
|
+
this.responseBuffer,
|
|
19861
|
+
this.currentTurnScope
|
|
19862
|
+
);
|
|
19863
|
+
if (parsed && Array.isArray(parsed.messages)) {
|
|
19864
|
+
return {
|
|
19865
|
+
id: parsed.id || "cli_session",
|
|
19866
|
+
status: parsed.status || this.currentStatus,
|
|
19867
|
+
title: parsed.title || this.cliName,
|
|
19868
|
+
terminalHistory: this.terminalHistory,
|
|
19869
|
+
messages: parsed.messages,
|
|
19870
|
+
activeModal: parsed.activeModal ?? this.activeModal
|
|
19871
|
+
};
|
|
19872
|
+
}
|
|
19663
19873
|
const messages = [...this.committedMessages];
|
|
19664
19874
|
return {
|
|
19665
19875
|
id: "cli_session",
|
|
@@ -20099,14 +20309,13 @@ var init_cli_provider_instance = __esm({
|
|
|
20099
20309
|
init_chat_history();
|
|
20100
20310
|
init_logger();
|
|
20101
20311
|
CliProviderInstance = class {
|
|
20102
|
-
constructor(provider, workingDir, cliArgs = [], instanceId, transportFactory
|
|
20312
|
+
constructor(provider, workingDir, cliArgs = [], instanceId, transportFactory) {
|
|
20103
20313
|
this.provider = provider;
|
|
20104
20314
|
this.workingDir = workingDir;
|
|
20105
20315
|
this.cliArgs = cliArgs;
|
|
20106
20316
|
this.type = provider.type;
|
|
20107
20317
|
this.instanceId = instanceId || crypto3.randomUUID();
|
|
20108
|
-
this.
|
|
20109
|
-
this.resolvedOutputFormat = this.resolveOutputFormat();
|
|
20318
|
+
this.presentationMode = "terminal";
|
|
20110
20319
|
this.adapter = new ProviderCliAdapter(provider, workingDir, cliArgs, transportFactory);
|
|
20111
20320
|
this.monitor = new StatusMonitor();
|
|
20112
20321
|
this.historyWriter = new ChatHistoryWriter();
|
|
@@ -20125,26 +20334,7 @@ var init_cli_provider_instance = __esm({
|
|
|
20125
20334
|
lastApprovalEventAt = 0;
|
|
20126
20335
|
historyWriter;
|
|
20127
20336
|
instanceId;
|
|
20128
|
-
|
|
20129
|
-
resolvedOutputFormat;
|
|
20130
|
-
/**
|
|
20131
|
-
* Determine output rendering format from:
|
|
20132
|
-
* 1. launchMode.outputFormat (explicit override)
|
|
20133
|
-
* 2. launchOptions[].outputFormatMap — check actual args for matching values
|
|
20134
|
-
* 3. Default: 'terminal'
|
|
20135
|
-
*/
|
|
20136
|
-
resolveOutputFormat() {
|
|
20137
|
-
if (this.launchMode?.outputFormat) return this.launchMode.outputFormat;
|
|
20138
|
-
if (this.provider.launchOptions?.length) {
|
|
20139
|
-
for (const opt of this.provider.launchOptions) {
|
|
20140
|
-
if (!opt.outputFormatMap) continue;
|
|
20141
|
-
for (const [val, fmt] of Object.entries(opt.outputFormatMap)) {
|
|
20142
|
-
if (this.cliArgs.includes(val)) return fmt;
|
|
20143
|
-
}
|
|
20144
|
-
}
|
|
20145
|
-
}
|
|
20146
|
-
return "terminal";
|
|
20147
|
-
}
|
|
20337
|
+
presentationMode;
|
|
20148
20338
|
// ─── Lifecycle ─────────────────────────────────
|
|
20149
20339
|
async init(context) {
|
|
20150
20340
|
this.context = context;
|
|
@@ -20169,6 +20359,7 @@ var init_cli_provider_instance = __esm({
|
|
|
20169
20359
|
}
|
|
20170
20360
|
getState() {
|
|
20171
20361
|
const adapterStatus = this.adapter.getStatus();
|
|
20362
|
+
const parsedStatus = this.adapter.getScriptParsedStatus?.() || null;
|
|
20172
20363
|
const runtime = this.adapter.getRuntimeMetadata();
|
|
20173
20364
|
const dirName = this.workingDir.split("/").filter(Boolean).pop() || "session";
|
|
20174
20365
|
if (adapterStatus.terminalHistory?.trim()) {
|
|
@@ -20184,14 +20375,13 @@ var init_cli_provider_instance = __esm({
|
|
|
20184
20375
|
name: this.provider.name,
|
|
20185
20376
|
category: "cli",
|
|
20186
20377
|
status: adapterStatus.status,
|
|
20187
|
-
mode: this.
|
|
20188
|
-
launchMode: this.launchMode?.id,
|
|
20378
|
+
mode: this.presentationMode,
|
|
20189
20379
|
activeChat: {
|
|
20190
20380
|
id: `${this.type}_${this.workingDir}`,
|
|
20191
|
-
title: `${this.provider.name} \xB7 ${dirName}`,
|
|
20192
|
-
status: adapterStatus.status,
|
|
20193
|
-
messages: [],
|
|
20194
|
-
activeModal: adapterStatus.activeModal,
|
|
20381
|
+
title: parsedStatus?.title || `${this.provider.name} \xB7 ${dirName}`,
|
|
20382
|
+
status: parsedStatus?.status || adapterStatus.status,
|
|
20383
|
+
messages: Array.isArray(parsedStatus?.messages) ? parsedStatus.messages : [],
|
|
20384
|
+
activeModal: parsedStatus?.activeModal ?? adapterStatus.activeModal,
|
|
20195
20385
|
terminalHistory: adapterStatus.terminalHistory,
|
|
20196
20386
|
inputContent: ""
|
|
20197
20387
|
},
|
|
@@ -20214,6 +20404,13 @@ var init_cli_provider_instance = __esm({
|
|
|
20214
20404
|
providerControls: this.provider.controls
|
|
20215
20405
|
};
|
|
20216
20406
|
}
|
|
20407
|
+
setPresentationMode(mode) {
|
|
20408
|
+
if (this.presentationMode === mode) return;
|
|
20409
|
+
this.presentationMode = mode;
|
|
20410
|
+
}
|
|
20411
|
+
getPresentationMode() {
|
|
20412
|
+
return this.presentationMode;
|
|
20413
|
+
}
|
|
20217
20414
|
onEvent(event, data) {
|
|
20218
20415
|
if (event === "send_message" && data?.text) {
|
|
20219
20416
|
void this.adapter.sendMessage(data.text).catch((e) => {
|
|
@@ -20474,7 +20671,7 @@ __export(util_exports, {
|
|
|
20474
20671
|
getSizableOrigin: () => getSizableOrigin,
|
|
20475
20672
|
hexToUint8Array: () => hexToUint8Array,
|
|
20476
20673
|
isObject: () => isObject,
|
|
20477
|
-
isPlainObject: () =>
|
|
20674
|
+
isPlainObject: () => isPlainObject2,
|
|
20478
20675
|
issue: () => issue,
|
|
20479
20676
|
joinValues: () => joinValues,
|
|
20480
20677
|
jsonStringifyReplacer: () => jsonStringifyReplacer,
|
|
@@ -20643,7 +20840,7 @@ function slugify(input) {
|
|
|
20643
20840
|
function isObject(data) {
|
|
20644
20841
|
return typeof data === "object" && data !== null && !Array.isArray(data);
|
|
20645
20842
|
}
|
|
20646
|
-
function
|
|
20843
|
+
function isPlainObject2(o) {
|
|
20647
20844
|
if (isObject(o) === false)
|
|
20648
20845
|
return false;
|
|
20649
20846
|
const ctor = o.constructor;
|
|
@@ -20660,7 +20857,7 @@ function isPlainObject(o) {
|
|
|
20660
20857
|
return true;
|
|
20661
20858
|
}
|
|
20662
20859
|
function shallowClone(o) {
|
|
20663
|
-
if (
|
|
20860
|
+
if (isPlainObject2(o))
|
|
20664
20861
|
return { ...o };
|
|
20665
20862
|
if (Array.isArray(o))
|
|
20666
20863
|
return [...o];
|
|
@@ -20796,7 +20993,7 @@ function omit(schema, mask) {
|
|
|
20796
20993
|
return clone(schema, def);
|
|
20797
20994
|
}
|
|
20798
20995
|
function extend(schema, shape) {
|
|
20799
|
-
if (!
|
|
20996
|
+
if (!isPlainObject2(shape)) {
|
|
20800
20997
|
throw new Error("Invalid input to extend: expected a plain object");
|
|
20801
20998
|
}
|
|
20802
20999
|
const checks = schema._zod.def.checks;
|
|
@@ -20819,7 +21016,7 @@ function extend(schema, shape) {
|
|
|
20819
21016
|
return clone(schema, def);
|
|
20820
21017
|
}
|
|
20821
21018
|
function safeExtend(schema, shape) {
|
|
20822
|
-
if (!
|
|
21019
|
+
if (!isPlainObject2(shape)) {
|
|
20823
21020
|
throw new Error("Invalid input to safeExtend: expected a plain object");
|
|
20824
21021
|
}
|
|
20825
21022
|
const def = mergeDefs(schema._zod.def, {
|
|
@@ -22302,7 +22499,7 @@ function mergeValues(a, b2) {
|
|
|
22302
22499
|
if (a instanceof Date && b2 instanceof Date && +a === +b2) {
|
|
22303
22500
|
return { valid: true, data: a };
|
|
22304
22501
|
}
|
|
22305
|
-
if (
|
|
22502
|
+
if (isPlainObject2(a) && isPlainObject2(b2)) {
|
|
22306
22503
|
const bKeys = Object.keys(b2);
|
|
22307
22504
|
const sharedKeys = Object.keys(a).filter((key) => bKeys.indexOf(key) !== -1);
|
|
22308
22505
|
const newObj = { ...a, ...b2 };
|
|
@@ -23497,7 +23694,7 @@ var init_schemas = __esm({
|
|
|
23497
23694
|
$ZodType.init(inst, def);
|
|
23498
23695
|
inst._zod.parse = (payload, ctx) => {
|
|
23499
23696
|
const input = payload.value;
|
|
23500
|
-
if (!
|
|
23697
|
+
if (!isPlainObject2(input)) {
|
|
23501
23698
|
payload.issues.push({
|
|
23502
23699
|
expected: "record",
|
|
23503
23700
|
code: "invalid_type",
|
|
@@ -37601,6 +37798,15 @@ var init_cli_manager = __esm({
|
|
|
37601
37798
|
const hash2 = require("crypto").createHash("md5").update(require("path").resolve(dir)).digest("hex").slice(0, 8);
|
|
37602
37799
|
return `${cliType}_${hash2}`;
|
|
37603
37800
|
}
|
|
37801
|
+
getSessionPresentationMode(sessionId) {
|
|
37802
|
+
if (!sessionId) return null;
|
|
37803
|
+
const instance = this.deps.getInstanceManager()?.getInstance(sessionId);
|
|
37804
|
+
const mode = instance?.category === "cli" ? instance.getPresentationMode?.() : null;
|
|
37805
|
+
return mode === "chat" || mode === "terminal" ? mode : null;
|
|
37806
|
+
}
|
|
37807
|
+
isTerminalSession(sessionId) {
|
|
37808
|
+
return this.getSessionPresentationMode(sessionId) === "terminal";
|
|
37809
|
+
}
|
|
37604
37810
|
persistRecentActivity(entry) {
|
|
37605
37811
|
try {
|
|
37606
37812
|
saveConfig(appendRecentActivity(loadConfig(), entry));
|
|
@@ -37656,12 +37862,12 @@ var init_cli_manager = __esm({
|
|
|
37656
37862
|
}
|
|
37657
37863
|
}, 3e3);
|
|
37658
37864
|
}
|
|
37659
|
-
async registerCliInstance(key, normalizedType, cliType, resolvedDir, cliArgs, provider, settings, attachExisting = false
|
|
37865
|
+
async registerCliInstance(key, normalizedType, cliType, resolvedDir, cliArgs, provider, settings, attachExisting = false) {
|
|
37660
37866
|
const instanceManager = this.deps.getInstanceManager();
|
|
37661
37867
|
const sessionRegistry = this.deps.getSessionRegistry?.() || null;
|
|
37662
37868
|
if (!instanceManager) throw new Error("InstanceManager not available");
|
|
37663
37869
|
const transportFactory = this.getTransportFactory(key, normalizedType, resolvedDir, cliArgs, attachExisting);
|
|
37664
|
-
const cliInstance = new CliProviderInstance(provider, resolvedDir, cliArgs, key, transportFactory
|
|
37870
|
+
const cliInstance = new CliProviderInstance(provider, resolvedDir, cliArgs, key, transportFactory);
|
|
37665
37871
|
try {
|
|
37666
37872
|
await instanceManager.addInstance(key, cliInstance, {
|
|
37667
37873
|
serverConn: this.deps.getServerConn(),
|
|
@@ -37687,7 +37893,7 @@ var init_cli_manager = __esm({
|
|
|
37687
37893
|
this.startCliExitMonitor(key, cliType);
|
|
37688
37894
|
}
|
|
37689
37895
|
// ─── Session start/management ──────────────────────────────
|
|
37690
|
-
async startSession(cliType, workingDir, cliArgs, initialModel
|
|
37896
|
+
async startSession(cliType, workingDir, cliArgs, initialModel) {
|
|
37691
37897
|
const trimmed = (workingDir || "").trim();
|
|
37692
37898
|
if (!trimmed) throw new Error("working directory required");
|
|
37693
37899
|
const resolvedDir = trimmed.startsWith("~") ? trimmed.replace(/^~/, os14.homedir()) : path10.resolve(trimmed);
|
|
@@ -37779,29 +37985,7 @@ ${installInfo}`
|
|
|
37779
37985
|
if (provider) {
|
|
37780
37986
|
console.log(colorize("cyan", ` \u{1F4E6} Using provider: ${provider.name} (${provider.type})`));
|
|
37781
37987
|
}
|
|
37782
|
-
|
|
37783
|
-
let resolvedLaunchMode = launchMode;
|
|
37784
|
-
const activeMode = provider?.launchModes?.length ? launchMode ? provider.launchModes.find((m) => m.id === launchMode) : provider.launchModes.find((m) => m.default) : void 0;
|
|
37785
|
-
if (activeMode) {
|
|
37786
|
-
resolvedLaunchMode = activeMode.id;
|
|
37787
|
-
}
|
|
37788
|
-
if (provider?.launchArgBuilder) {
|
|
37789
|
-
const defaults = {};
|
|
37790
|
-
for (const opt of provider.launchOptions || []) {
|
|
37791
|
-
if (opt.default !== void 0) defaults[opt.id] = opt.default;
|
|
37792
|
-
}
|
|
37793
|
-
const modeOptions = activeMode?.options || {};
|
|
37794
|
-
const userOptions = launchOptionValues || {};
|
|
37795
|
-
const merged = { ...defaults, ...modeOptions, ...userOptions };
|
|
37796
|
-
const extraArgs = provider.launchArgBuilder(merged);
|
|
37797
|
-
if (extraArgs.length) {
|
|
37798
|
-
resolvedCliArgs = [...cliArgs || [], ...extraArgs];
|
|
37799
|
-
console.log(colorize("cyan", ` \u{1F680} Launch options applied: ${extraArgs.join(" ")}`));
|
|
37800
|
-
}
|
|
37801
|
-
} else if (activeMode?.extraArgs?.length) {
|
|
37802
|
-
resolvedCliArgs = [...cliArgs || [], ...activeMode.extraArgs];
|
|
37803
|
-
console.log(colorize("cyan", ` \u{1F680} Launch mode '${activeMode.name}': appending args ${activeMode.extraArgs.join(" ")}`));
|
|
37804
|
-
}
|
|
37988
|
+
const resolvedCliArgs = cliArgs;
|
|
37805
37989
|
const instanceManager = this.deps.getInstanceManager();
|
|
37806
37990
|
if (provider && instanceManager) {
|
|
37807
37991
|
const resolvedProvider = this.providerLoader.resolve(cliType, { version: cliInfo.version }) || provider;
|
|
@@ -37813,8 +37997,7 @@ ${installInfo}`
|
|
|
37813
37997
|
resolvedCliArgs,
|
|
37814
37998
|
resolvedProvider,
|
|
37815
37999
|
{},
|
|
37816
|
-
false
|
|
37817
|
-
resolvedLaunchMode
|
|
38000
|
+
false
|
|
37818
38001
|
);
|
|
37819
38002
|
console.log(colorize("green", ` \u2713 CLI started: ${cliInfo.displayName} v${cliInfo.version || "unknown"} in ${resolvedDir}`));
|
|
37820
38003
|
} else {
|
|
@@ -37926,8 +38109,7 @@ ${installInfo}`
|
|
|
37926
38109
|
record2.cliArgs,
|
|
37927
38110
|
resolvedProvider,
|
|
37928
38111
|
{},
|
|
37929
|
-
true
|
|
37930
|
-
record2.launchMode
|
|
38112
|
+
true
|
|
37931
38113
|
);
|
|
37932
38114
|
restored += 1;
|
|
37933
38115
|
LOG.info("CLI", `\u267B Restored hosted runtime: ${record2.runtimeKey || record2.runtimeId} (${record2.displayName || record2.workspace})`);
|
|
@@ -37969,6 +38151,14 @@ ${installInfo}`
|
|
|
37969
38151
|
}
|
|
37970
38152
|
return null;
|
|
37971
38153
|
}
|
|
38154
|
+
findAdapterBySessionId(instanceKey) {
|
|
38155
|
+
if (!instanceKey) return null;
|
|
38156
|
+
let ik = instanceKey;
|
|
38157
|
+
const colonIdx = ik.lastIndexOf(":");
|
|
38158
|
+
if (colonIdx >= 0) ik = ik.substring(colonIdx + 1);
|
|
38159
|
+
const adapter = this.adapters.get(ik);
|
|
38160
|
+
return adapter ? { adapter, key: ik } : null;
|
|
38161
|
+
}
|
|
37972
38162
|
// ─── CLI command handling ────────────────────────────
|
|
37973
38163
|
async handleCliCommand(cmd, args) {
|
|
37974
38164
|
switch (cmd) {
|
|
@@ -37997,7 +38187,7 @@ ${installInfo}`
|
|
|
37997
38187
|
const dir = resolved.path;
|
|
37998
38188
|
const launchSource = resolved.source;
|
|
37999
38189
|
if (!cliType) throw new Error("cliType required");
|
|
38000
|
-
await this.startSession(cliType, dir, args?.cliArgs, args?.initialModel
|
|
38190
|
+
await this.startSession(cliType, dir, args?.cliArgs, args?.initialModel);
|
|
38001
38191
|
let newKey = null;
|
|
38002
38192
|
for (const [k, adapter] of this.adapters) {
|
|
38003
38193
|
if (adapter.cliType === cliType && adapter.workingDir === dir) {
|
|
@@ -38019,6 +38209,23 @@ ${installInfo}`
|
|
|
38019
38209
|
}
|
|
38020
38210
|
return { success: true, cliType, dir, stopped: true, mode };
|
|
38021
38211
|
}
|
|
38212
|
+
case "set_cli_view_mode": {
|
|
38213
|
+
const mode = args?.mode === "chat" ? "chat" : "terminal";
|
|
38214
|
+
const targetSessionId = typeof args?.targetSessionId === "string" ? args.targetSessionId : "";
|
|
38215
|
+
const cliType = args?.cliType || args?.agentType || "";
|
|
38216
|
+
const dir = args?.dir || "";
|
|
38217
|
+
const found = this.findAdapterBySessionId(targetSessionId) || (cliType ? this.findAdapter(cliType, { instanceKey: targetSessionId, dir }) : null);
|
|
38218
|
+
if (!found) {
|
|
38219
|
+
return { success: false, error: "CLI session not found", code: "CLI_SESSION_NOT_FOUND" };
|
|
38220
|
+
}
|
|
38221
|
+
const instance = this.deps.getInstanceManager()?.getInstance(found.key);
|
|
38222
|
+
if (!(instance instanceof CliProviderInstance)) {
|
|
38223
|
+
return { success: false, error: "CLI instance not found", code: "CLI_INSTANCE_NOT_FOUND" };
|
|
38224
|
+
}
|
|
38225
|
+
instance.setPresentationMode(mode);
|
|
38226
|
+
this.deps.onStatusChange();
|
|
38227
|
+
return { success: true, id: found.key, mode };
|
|
38228
|
+
}
|
|
38022
38229
|
case "restart_session": {
|
|
38023
38230
|
const cliType = args?.cliType || args?.agentType || args?.ideType;
|
|
38024
38231
|
const cfg = loadConfig();
|
|
@@ -38670,7 +38877,12 @@ var init_poller = __esm({
|
|
|
38670
38877
|
} catch {
|
|
38671
38878
|
}
|
|
38672
38879
|
}
|
|
38673
|
-
if (!resolvedActiveSessionId || !parentSessionId)
|
|
38880
|
+
if (!resolvedActiveSessionId || !parentSessionId) {
|
|
38881
|
+
if (parentSessionId) {
|
|
38882
|
+
this.deps.onStreamsUpdated?.(ideType, []);
|
|
38883
|
+
}
|
|
38884
|
+
continue;
|
|
38885
|
+
}
|
|
38674
38886
|
try {
|
|
38675
38887
|
await agentStreamManager.syncActiveSession(cdp, parentSessionId);
|
|
38676
38888
|
const stream = await agentStreamManager.collectActiveSession(cdp, parentSessionId);
|
|
@@ -38698,7 +38910,11 @@ var init_agent_stream = __esm({
|
|
|
38698
38910
|
function forwardAgentStreamsToIdeInstance(instanceManager, ideType, streams) {
|
|
38699
38911
|
const ideInstance = instanceManager.getInstance(`ide:${ideType}`);
|
|
38700
38912
|
if (!ideInstance?.onEvent) return;
|
|
38913
|
+
const seenExtensionTypes = /* @__PURE__ */ new Set();
|
|
38701
38914
|
for (const stream of streams) {
|
|
38915
|
+
if (typeof stream.agentType === "string" && stream.agentType) {
|
|
38916
|
+
seenExtensionTypes.add(stream.agentType);
|
|
38917
|
+
}
|
|
38702
38918
|
ideInstance.onEvent("stream_update", {
|
|
38703
38919
|
extensionType: stream.agentType,
|
|
38704
38920
|
streams: [stream],
|
|
@@ -38715,6 +38931,16 @@ function forwardAgentStreamsToIdeInstance(instanceManager, ideType, streams) {
|
|
|
38715
38931
|
inputContent: stream.inputContent || ""
|
|
38716
38932
|
});
|
|
38717
38933
|
}
|
|
38934
|
+
const extensionTypes = ideInstance.getExtensionTypes?.() || [];
|
|
38935
|
+
if (streams.length === 0) {
|
|
38936
|
+
ideInstance.onEvent("stream_reset_all");
|
|
38937
|
+
return;
|
|
38938
|
+
}
|
|
38939
|
+
for (const extensionType of extensionTypes) {
|
|
38940
|
+
if (!seenExtensionTypes.has(extensionType)) {
|
|
38941
|
+
ideInstance.onEvent("stream_reset", { extensionType });
|
|
38942
|
+
}
|
|
38943
|
+
}
|
|
38718
38944
|
}
|
|
38719
38945
|
var init_forward = __esm({
|
|
38720
38946
|
"../../oss/packages/daemon-core/src/agent-stream/forward.ts"() {
|
|
@@ -44458,13 +44684,8 @@ var init_server_connection = __esm({
|
|
|
44458
44684
|
LOG.info("Server", `[ServerConn] Run 'adhdev setup' to re-authenticate.`);
|
|
44459
44685
|
this.setState("disconnected");
|
|
44460
44686
|
try {
|
|
44461
|
-
|
|
44462
|
-
|
|
44463
|
-
const configPath = path18.join(process.env.HOME || process.env.USERPROFILE || "", ".adhdev", "config.json");
|
|
44464
|
-
if (fs16.existsSync(configPath)) {
|
|
44465
|
-
fs16.unlinkSync(configPath);
|
|
44466
|
-
LOG.info("Server", `[ServerConn] Config file removed. Re-run 'adhdev setup'.`);
|
|
44467
|
-
}
|
|
44687
|
+
resetConfig();
|
|
44688
|
+
LOG.info("Server", `[ServerConn] Config reset. Re-run 'adhdev setup'.`);
|
|
44468
44689
|
} catch {
|
|
44469
44690
|
}
|
|
44470
44691
|
return;
|
|
@@ -44733,10 +44954,9 @@ ${e?.stack || ""}`);
|
|
|
44733
44954
|
async fetchTurnCredentials() {
|
|
44734
44955
|
try {
|
|
44735
44956
|
const serverUrl = process.env.ADHDEV_SERVER_URL || "https://api.adhf.dev";
|
|
44736
|
-
const configPath = path15.join(os18.homedir(), ".adhdev", "config.json");
|
|
44737
44957
|
let token = "";
|
|
44738
44958
|
try {
|
|
44739
|
-
const config2 =
|
|
44959
|
+
const config2 = loadConfig();
|
|
44740
44960
|
token = config2.machineSecret || "";
|
|
44741
44961
|
} catch {
|
|
44742
44962
|
}
|
|
@@ -45035,8 +45255,9 @@ ${e?.stack || ""}`);
|
|
|
45035
45255
|
log(`pty_input: REJECTED \u2014 permission=${permission} peer=${peerId}`);
|
|
45036
45256
|
return;
|
|
45037
45257
|
}
|
|
45038
|
-
|
|
45039
|
-
|
|
45258
|
+
const sessionId = parsed.sessionId || parsed.cliId || parsed.cliType || "";
|
|
45259
|
+
if (this.ptyInputHandler && parsed.data && sessionId) {
|
|
45260
|
+
this.ptyInputHandler(sessionId, parsed.data);
|
|
45040
45261
|
}
|
|
45041
45262
|
return;
|
|
45042
45263
|
}
|
|
@@ -45046,8 +45267,9 @@ ${e?.stack || ""}`);
|
|
|
45046
45267
|
log(`pty_resize: REJECTED \u2014 permission=${permission} peer=${peerId}`);
|
|
45047
45268
|
return;
|
|
45048
45269
|
}
|
|
45049
|
-
|
|
45050
|
-
|
|
45270
|
+
const sessionId = parsed.sessionId || parsed.cliId || parsed.cliType || "";
|
|
45271
|
+
if (this.ptyResizeHandler && parsed.cols && parsed.rows && sessionId) {
|
|
45272
|
+
this.ptyResizeHandler(sessionId, parsed.cols, parsed.rows);
|
|
45051
45273
|
}
|
|
45052
45274
|
return;
|
|
45053
45275
|
}
|
|
@@ -45075,8 +45297,8 @@ ${e?.stack || ""}`);
|
|
|
45075
45297
|
return sentAny;
|
|
45076
45298
|
}
|
|
45077
45299
|
/** Broadcast PTY output to all connected peers */
|
|
45078
|
-
broadcastPtyOutput(
|
|
45079
|
-
const msg = JSON.stringify({ type: "pty_output",
|
|
45300
|
+
broadcastPtyOutput(sessionId, data) {
|
|
45301
|
+
const msg = JSON.stringify({ type: "pty_output", sessionId, data });
|
|
45080
45302
|
let sentAny = false;
|
|
45081
45303
|
for (const peer of this.peers.values()) {
|
|
45082
45304
|
if (peer.state !== "connected" || !peer.dataChannel) continue;
|
|
@@ -45710,7 +45932,7 @@ var init_adhdev_daemon = __esm({
|
|
|
45710
45932
|
fs15 = __toESM(require("fs"));
|
|
45711
45933
|
path17 = __toESM(require("path"));
|
|
45712
45934
|
import_chalk2 = __toESM(require("chalk"));
|
|
45713
|
-
pkgVersion = "0.7.
|
|
45935
|
+
pkgVersion = "0.7.42";
|
|
45714
45936
|
if (pkgVersion === "unknown") {
|
|
45715
45937
|
try {
|
|
45716
45938
|
const possiblePaths = [
|
|
@@ -45755,6 +45977,16 @@ var init_adhdev_daemon = __esm({
|
|
|
45755
45977
|
constructor() {
|
|
45756
45978
|
this.localPort = 19222;
|
|
45757
45979
|
}
|
|
45980
|
+
getCliPresentationMode(sessionId) {
|
|
45981
|
+
if (!sessionId || !this.components) return null;
|
|
45982
|
+
const instance = this.components.instanceManager.getInstance(sessionId);
|
|
45983
|
+
if (instance?.category !== "cli") return null;
|
|
45984
|
+
const mode = instance.getPresentationMode?.();
|
|
45985
|
+
return mode === "chat" || mode === "terminal" ? mode : null;
|
|
45986
|
+
}
|
|
45987
|
+
isTerminalCliSession(sessionId) {
|
|
45988
|
+
return this.getCliPresentationMode(sessionId) === "terminal";
|
|
45989
|
+
}
|
|
45758
45990
|
async start(options = {}) {
|
|
45759
45991
|
try {
|
|
45760
45992
|
const { installGlobalInterceptor: installGlobalInterceptor2 } = require("./logging/logger");
|
|
@@ -45784,9 +46016,6 @@ ${err?.stack || ""}`);
|
|
|
45784
46016
|
const authToken = config2.machineSecret;
|
|
45785
46017
|
if (!authToken) {
|
|
45786
46018
|
console.log(import_chalk2.default.red("\n\u2717 No machine secret found."));
|
|
45787
|
-
if (config2.connectionToken) {
|
|
45788
|
-
console.log(import_chalk2.default.yellow(" Legacy connectionToken detected \u2014 please re-run setup."));
|
|
45789
|
-
}
|
|
45790
46019
|
console.log(import_chalk2.default.gray(" Run `adhdev setup` first.\n"));
|
|
45791
46020
|
process.exit(1);
|
|
45792
46021
|
}
|
|
@@ -45796,7 +46025,12 @@ ${err?.stack || ""}`);
|
|
|
45796
46025
|
providerLogFn: LOG.forComponent("Provider").asLogFn(),
|
|
45797
46026
|
cliManagerDeps: {
|
|
45798
46027
|
getServerConn: () => this.serverConn,
|
|
45799
|
-
getP2p: () =>
|
|
46028
|
+
getP2p: () => ({
|
|
46029
|
+
broadcastPtyOutput: (key, data) => {
|
|
46030
|
+
if (!this.isTerminalCliSession(key)) return;
|
|
46031
|
+
this.p2p?.broadcastPtyOutput(key, data);
|
|
46032
|
+
}
|
|
46033
|
+
}),
|
|
45800
46034
|
onStatusChange: () => this.statusReporter?.onStatusChange(),
|
|
45801
46035
|
removeAgentTracking: (key) => this.statusReporter?.removeAgentTracking(key),
|
|
45802
46036
|
createPtyTransportFactory: ({ runtimeId, providerType, workspace, cliArgs, attachExisting }) => new SessionHostPtyTransportFactory({
|
|
@@ -45873,14 +46107,16 @@ ${err?.stack || ""}`);
|
|
|
45873
46107
|
return { id: req.id, success: result.success, entries: result.files, error: result.error };
|
|
45874
46108
|
}
|
|
45875
46109
|
});
|
|
45876
|
-
this.p2p.onPtyInput((
|
|
45877
|
-
|
|
46110
|
+
this.p2p.onPtyInput((sessionId, data) => {
|
|
46111
|
+
if (!this.isTerminalCliSession(sessionId)) return;
|
|
46112
|
+
const found = this.components.cliManager.findAdapter(sessionId, { instanceKey: sessionId });
|
|
45878
46113
|
if (found && typeof found.adapter.writeRaw === "function") {
|
|
45879
46114
|
found.adapter.writeRaw(data);
|
|
45880
46115
|
}
|
|
45881
46116
|
});
|
|
45882
|
-
this.p2p.onPtyResize((
|
|
45883
|
-
|
|
46117
|
+
this.p2p.onPtyResize((sessionId, cols, rows) => {
|
|
46118
|
+
if (!this.isTerminalCliSession(sessionId)) return;
|
|
46119
|
+
const found = this.components.cliManager.findAdapter(sessionId, { instanceKey: sessionId });
|
|
45884
46120
|
if (found && typeof found.adapter.resize === "function") {
|
|
45885
46121
|
found.adapter.resize(cols, rows);
|
|
45886
46122
|
}
|
|
@@ -46056,6 +46292,9 @@ ${err?.stack || ""}`);
|
|
|
46056
46292
|
case "get_runtime_snapshot": {
|
|
46057
46293
|
const sessionId = typeof data.sessionId === "string" ? data.sessionId : "";
|
|
46058
46294
|
if (!sessionId) return { success: false, error: "sessionId is required" };
|
|
46295
|
+
if (!this.isTerminalCliSession(sessionId)) {
|
|
46296
|
+
return { success: false, error: "CLI session is not in terminal mode", code: "CLI_VIEW_MODE_NOT_TERMINAL" };
|
|
46297
|
+
}
|
|
46059
46298
|
if (!this.sessionHostEndpoint) return { success: false, error: "Session host unavailable" };
|
|
46060
46299
|
const client = new SessionHostClient({ endpoint: this.sessionHostEndpoint });
|
|
46061
46300
|
try {
|
|
@@ -46905,7 +47144,6 @@ function registerSetupCommands(program2, providerLoader) {
|
|
|
46905
47144
|
console.log(import_chalk4.default.gray(` \u2022 ${ext}`));
|
|
46906
47145
|
});
|
|
46907
47146
|
console.log(` ${import_chalk4.default.bold("User:")} ${config2.userEmail || import_chalk4.default.gray("not logged in")}`);
|
|
46908
|
-
console.log(` ${import_chalk4.default.bold("Auto-connect:")} ${config2.autoConnect ? import_chalk4.default.green("enabled") : import_chalk4.default.gray("disabled")}`);
|
|
46909
47147
|
console.log(` ${import_chalk4.default.bold("Server:")} ${config2.serverUrl}`);
|
|
46910
47148
|
console.log(` ${import_chalk4.default.bold("Setup date:")} ${config2.setupDate || "unknown"}`);
|
|
46911
47149
|
console.log();
|
|
@@ -47001,7 +47239,6 @@ function registerSetupCommands(program2, providerLoader) {
|
|
|
47001
47239
|
} catch {
|
|
47002
47240
|
}
|
|
47003
47241
|
const config2 = loadConfig2();
|
|
47004
|
-
config2.apiToken = null;
|
|
47005
47242
|
config2.machineSecret = void 0;
|
|
47006
47243
|
config2.userEmail = null;
|
|
47007
47244
|
config2.userName = null;
|