@adhdev/daemon-core 0.7.37 → 0.7.39
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/agent-stream/forward.d.ts +8 -0
- package/dist/agent-stream/index.d.ts +6 -0
- package/dist/agent-stream/manager.d.ts +59 -0
- package/dist/agent-stream/poller.d.ts +41 -0
- package/dist/agent-stream/provider-adapter.d.ts +29 -0
- package/dist/agent-stream/types.d.ts +62 -0
- package/dist/boot/daemon-lifecycle.d.ts +97 -0
- package/dist/cdp/devtools.d.ts +51 -0
- package/dist/cdp/initializer.d.ts +50 -0
- package/dist/cdp/manager.d.ts +145 -0
- package/dist/cdp/scanner.d.ts +58 -0
- package/dist/cdp/setup.d.ts +58 -0
- package/dist/cli-adapter-types.d.ts +25 -0
- package/dist/cli-adapters/provider-cli-adapter.d.ts +229 -0
- package/dist/cli-adapters/pty-transport.d.ts +43 -0
- package/dist/cli-adapters/session-host-transport.d.ts +19 -0
- package/dist/cli-adapters/terminal-backends/ghostty-vt-backend.d.ts +12 -0
- package/dist/cli-adapters/terminal-backends/types.d.ts +14 -0
- package/dist/cli-adapters/terminal-backends/xterm-backend.d.ts +13 -0
- package/dist/cli-adapters/terminal-screen.d.ts +27 -0
- package/dist/commands/cdp-commands.d.ts +15 -0
- package/dist/commands/chat-commands.d.ts +15 -0
- package/dist/commands/cli-manager.d.ts +82 -0
- package/dist/commands/handler.d.ts +101 -0
- package/dist/commands/router.d.ts +69 -0
- package/dist/commands/stream-commands.d.ts +13 -0
- package/dist/commands/workspace-commands.d.ts +11 -0
- package/dist/config/chat-history.d.ts +60 -0
- package/dist/config/config.d.ts +101 -0
- package/dist/config/recent-activity.d.ts +27 -0
- package/dist/config/workspaces.d.ts +82 -0
- package/dist/daemon/dev-auto-implement.d.ts +26 -0
- package/dist/daemon/dev-cdp-handlers.d.ts +22 -0
- package/dist/daemon/dev-cli-debug.d.ts +24 -0
- package/dist/daemon/dev-server-types.d.ts +43 -0
- package/dist/daemon/dev-server.d.ts +133 -0
- package/dist/daemon/scaffold-template.d.ts +32 -0
- package/dist/daemon-core.d.ts +36 -0
- package/dist/detection/cli-detector.d.ts +27 -0
- package/dist/detection/ide-detector.d.ts +34 -0
- package/dist/index.d.ts +72 -2499
- package/dist/index.js +458 -637
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +465 -642
- package/dist/index.mjs.map +1 -1
- package/dist/installer.d.ts +50 -0
- package/dist/ipc-protocol.d.ts +111 -0
- package/dist/launch.d.ts +46 -0
- package/dist/logging/command-log.d.ts +31 -0
- package/dist/logging/logger.d.ts +87 -0
- package/dist/providers/acp-provider-instance.d.ts +101 -0
- package/dist/providers/cli-provider-instance.d.ts +43 -0
- package/dist/providers/contracts.d.ts +483 -0
- package/dist/providers/extension-provider-instance.d.ts +44 -0
- package/dist/providers/ide-provider-instance.d.ts +61 -0
- package/dist/providers/index.d.ts +5 -0
- package/dist/providers/provider-instance-manager.d.ts +84 -0
- package/dist/providers/provider-instance.d.ts +148 -0
- package/dist/providers/provider-loader.d.ts +270 -0
- package/dist/providers/status-monitor.d.ts +48 -0
- package/dist/providers/version-archive.d.ts +52 -0
- package/dist/session-host/runtime-support.d.ts +8 -0
- package/dist/sessions/registry.d.ts +24 -0
- package/dist/shared-types-extra.d.ts +29 -0
- package/dist/shared-types.d.ts +213 -0
- package/dist/status/builders.d.ts +33 -0
- package/dist/status/normalize.d.ts +14 -1
- package/dist/status/reporter.d.ts +69 -0
- package/dist/status/snapshot.d.ts +38 -0
- package/dist/system/host-memory.d.ts +19 -0
- package/dist/types.d.ts +123 -0
- package/node_modules/@adhdev/session-host-core/package.json +1 -1
- package/package.json +3 -2
- package/src/commands/cli-manager.ts +1 -26
- package/src/commands/handler.ts +0 -31
- package/src/commands/router.ts +1 -18
- package/src/commands/stream-commands.ts +2 -4
- package/src/commands/workspace-commands.ts +9 -23
- package/src/config/config.ts +1 -78
- package/src/config/workspaces.ts +0 -24
- package/src/index.ts +16 -15
- package/src/providers/provider-loader.ts +13 -5
- package/src/shared-types-extra.ts +34 -0
- package/src/shared-types.ts +14 -27
- package/src/status/builders.ts +12 -0
- package/src/status/reporter.ts +1 -0
- package/src/status/snapshot.ts +26 -13
- package/src/types.ts +3 -8
- package/dist/index.d.mts +0 -2504
- package/dist/normalize-DVI4Lo5I.d.mts +0 -947
- package/dist/normalize-DVI4Lo5I.d.ts +0 -947
- package/dist/status/normalize.d.mts +0 -1
- package/src/config/workspace-activity.ts +0 -65
package/dist/index.mjs
CHANGED
|
@@ -25,201 +25,9 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
25
25
|
};
|
|
26
26
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
27
|
|
|
28
|
-
// src/config/workspaces.ts
|
|
29
|
-
import * as fs from "fs";
|
|
30
|
-
import * as os from "os";
|
|
31
|
-
import * as path from "path";
|
|
32
|
-
import { randomUUID } from "crypto";
|
|
33
|
-
function expandPath(p) {
|
|
34
|
-
const t = (p || "").trim();
|
|
35
|
-
if (!t) return "";
|
|
36
|
-
if (t.startsWith("~")) return path.join(os.homedir(), t.slice(1).replace(/^\//, ""));
|
|
37
|
-
return path.resolve(t);
|
|
38
|
-
}
|
|
39
|
-
function validateWorkspacePath(absPath) {
|
|
40
|
-
try {
|
|
41
|
-
if (!absPath) return { ok: false, error: "Path required" };
|
|
42
|
-
if (!fs.existsSync(absPath)) return { ok: false, error: "Path does not exist" };
|
|
43
|
-
const st = fs.statSync(absPath);
|
|
44
|
-
if (!st.isDirectory()) return { ok: false, error: "Not a directory" };
|
|
45
|
-
return { ok: true };
|
|
46
|
-
} catch (e) {
|
|
47
|
-
return { ok: false, error: e?.message || "Invalid path" };
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
function defaultWorkspaceLabel(absPath) {
|
|
51
|
-
const base = path.basename(absPath) || absPath;
|
|
52
|
-
return base;
|
|
53
|
-
}
|
|
54
|
-
function migrateWorkspacesFromRecent(config) {
|
|
55
|
-
if (!config.workspaces) config.workspaces = [];
|
|
56
|
-
if (config.workspaces.length > 0) return config;
|
|
57
|
-
const recent = config.recentCliWorkspaces || [];
|
|
58
|
-
const now = Date.now();
|
|
59
|
-
for (const raw of recent) {
|
|
60
|
-
const abs = expandPath(raw);
|
|
61
|
-
if (!abs || validateWorkspacePath(abs).ok !== true) continue;
|
|
62
|
-
if (config.workspaces.some((w) => path.resolve(w.path) === abs)) continue;
|
|
63
|
-
config.workspaces.push({
|
|
64
|
-
id: randomUUID(),
|
|
65
|
-
path: abs,
|
|
66
|
-
label: defaultWorkspaceLabel(abs),
|
|
67
|
-
addedAt: now
|
|
68
|
-
});
|
|
69
|
-
if (config.workspaces.length >= MAX_WORKSPACES) break;
|
|
70
|
-
}
|
|
71
|
-
return config;
|
|
72
|
-
}
|
|
73
|
-
function getDefaultWorkspacePath(config) {
|
|
74
|
-
const id = config.defaultWorkspaceId;
|
|
75
|
-
if (!id) return null;
|
|
76
|
-
const w = (config.workspaces || []).find((x) => x.id === id);
|
|
77
|
-
if (!w) return null;
|
|
78
|
-
const abs = expandPath(w.path);
|
|
79
|
-
if (validateWorkspacePath(abs).ok !== true) return null;
|
|
80
|
-
return abs;
|
|
81
|
-
}
|
|
82
|
-
function getWorkspaceState(config) {
|
|
83
|
-
const workspaces = [...config.workspaces || []].sort((a, b) => b.addedAt - a.addedAt);
|
|
84
|
-
const defaultWorkspacePath = getDefaultWorkspacePath(config);
|
|
85
|
-
return {
|
|
86
|
-
workspaces,
|
|
87
|
-
defaultWorkspaceId: config.defaultWorkspaceId ?? null,
|
|
88
|
-
defaultWorkspacePath
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
function resolveLaunchDirectory(args, config) {
|
|
92
|
-
const a = args || {};
|
|
93
|
-
if (a.dir != null && String(a.dir).trim()) {
|
|
94
|
-
const abs = expandPath(String(a.dir).trim());
|
|
95
|
-
if (abs && validateWorkspacePath(abs).ok === true) {
|
|
96
|
-
return { ok: true, path: abs, source: "dir" };
|
|
97
|
-
}
|
|
98
|
-
return {
|
|
99
|
-
ok: false,
|
|
100
|
-
code: "WORKSPACE_LAUNCH_CONTEXT_REQUIRED",
|
|
101
|
-
message: abs ? "Directory path is not valid or does not exist" : "Invalid directory path"
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
if (a.workspaceId) {
|
|
105
|
-
const w = (config.workspaces || []).find((x) => x.id === a.workspaceId);
|
|
106
|
-
if (w) {
|
|
107
|
-
const abs = expandPath(w.path);
|
|
108
|
-
if (validateWorkspacePath(abs).ok === true) {
|
|
109
|
-
return { ok: true, path: abs, source: "workspaceId" };
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
return {
|
|
113
|
-
ok: false,
|
|
114
|
-
code: "WORKSPACE_LAUNCH_CONTEXT_REQUIRED",
|
|
115
|
-
message: "Saved workspace not found or path is no longer valid"
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
if (a.useDefaultWorkspace === true) {
|
|
119
|
-
const d = getDefaultWorkspacePath(config);
|
|
120
|
-
if (d) return { ok: true, path: d, source: "defaultWorkspace" };
|
|
121
|
-
return {
|
|
122
|
-
ok: false,
|
|
123
|
-
code: "WORKSPACE_LAUNCH_CONTEXT_REQUIRED",
|
|
124
|
-
message: "No default workspace is set"
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
if (a.useHome === true) {
|
|
128
|
-
return { ok: true, path: os.homedir(), source: "home" };
|
|
129
|
-
}
|
|
130
|
-
return {
|
|
131
|
-
ok: false,
|
|
132
|
-
code: "WORKSPACE_LAUNCH_CONTEXT_REQUIRED",
|
|
133
|
-
message: "Choose a directory, saved workspace, default workspace, or home before launching."
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
function resolveIdeWorkspaceFromArgs(args, config) {
|
|
137
|
-
const ar = args || {};
|
|
138
|
-
if (ar.workspace) {
|
|
139
|
-
const abs = expandPath(ar.workspace);
|
|
140
|
-
if (abs && validateWorkspacePath(abs).ok === true) return abs;
|
|
141
|
-
}
|
|
142
|
-
if (ar.workspaceId) {
|
|
143
|
-
const w = (config.workspaces || []).find((x) => x.id === ar.workspaceId);
|
|
144
|
-
if (w) {
|
|
145
|
-
const abs = expandPath(w.path);
|
|
146
|
-
if (validateWorkspacePath(abs).ok === true) return abs;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
if (ar.useDefaultWorkspace === true) {
|
|
150
|
-
return getDefaultWorkspacePath(config) || void 0;
|
|
151
|
-
}
|
|
152
|
-
return void 0;
|
|
153
|
-
}
|
|
154
|
-
function resolveIdeLaunchWorkspace(args, config) {
|
|
155
|
-
const direct = resolveIdeWorkspaceFromArgs(args, config);
|
|
156
|
-
if (direct) return direct;
|
|
157
|
-
if (args?.useDefaultWorkspace === false) return void 0;
|
|
158
|
-
return getDefaultWorkspacePath(config) || void 0;
|
|
159
|
-
}
|
|
160
|
-
function findWorkspaceByPath(config, rawPath) {
|
|
161
|
-
const abs = path.resolve(expandPath(rawPath));
|
|
162
|
-
if (!abs) return void 0;
|
|
163
|
-
return (config.workspaces || []).find((w) => path.resolve(expandPath(w.path)) === abs);
|
|
164
|
-
}
|
|
165
|
-
function addWorkspaceEntry(config, rawPath, label, options) {
|
|
166
|
-
const abs = expandPath(rawPath);
|
|
167
|
-
const createIfMissing = options?.createIfMissing === true;
|
|
168
|
-
if (!abs) return { error: "Path required" };
|
|
169
|
-
if (!fs.existsSync(abs) && createIfMissing) {
|
|
170
|
-
try {
|
|
171
|
-
fs.mkdirSync(abs, { recursive: true });
|
|
172
|
-
} catch (e) {
|
|
173
|
-
return { error: e?.message || "Could not create directory" };
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
const v = validateWorkspacePath(abs);
|
|
177
|
-
if (!v.ok) return { error: v.error };
|
|
178
|
-
const list = [...config.workspaces || []];
|
|
179
|
-
if (list.some((w) => path.resolve(w.path) === abs)) {
|
|
180
|
-
return { error: "Workspace already in list" };
|
|
181
|
-
}
|
|
182
|
-
if (list.length >= MAX_WORKSPACES) {
|
|
183
|
-
return { error: `Maximum ${MAX_WORKSPACES} workspaces` };
|
|
184
|
-
}
|
|
185
|
-
const entry = {
|
|
186
|
-
id: randomUUID(),
|
|
187
|
-
path: abs,
|
|
188
|
-
label: (label || "").trim() || defaultWorkspaceLabel(abs),
|
|
189
|
-
addedAt: Date.now()
|
|
190
|
-
};
|
|
191
|
-
list.push(entry);
|
|
192
|
-
return { config: { ...config, workspaces: list }, entry };
|
|
193
|
-
}
|
|
194
|
-
function removeWorkspaceEntry(config, id) {
|
|
195
|
-
const list = (config.workspaces || []).filter((w) => w.id !== id);
|
|
196
|
-
if (list.length === (config.workspaces || []).length) return { error: "Workspace not found" };
|
|
197
|
-
let defaultWorkspaceId = config.defaultWorkspaceId;
|
|
198
|
-
if (defaultWorkspaceId === id) defaultWorkspaceId = null;
|
|
199
|
-
return { config: { ...config, workspaces: list, defaultWorkspaceId } };
|
|
200
|
-
}
|
|
201
|
-
function setDefaultWorkspaceId(config, id) {
|
|
202
|
-
if (id === null) {
|
|
203
|
-
return { config: { ...config, defaultWorkspaceId: null } };
|
|
204
|
-
}
|
|
205
|
-
const w = (config.workspaces || []).find((x) => x.id === id);
|
|
206
|
-
if (!w) return { error: "Workspace not found" };
|
|
207
|
-
const abs = expandPath(w.path);
|
|
208
|
-
if (validateWorkspacePath(abs).ok !== true) return { error: "Workspace path is no longer valid" };
|
|
209
|
-
return { config: { ...config, defaultWorkspaceId: id } };
|
|
210
|
-
}
|
|
211
|
-
var MAX_WORKSPACES;
|
|
212
|
-
var init_workspaces = __esm({
|
|
213
|
-
"src/config/workspaces.ts"() {
|
|
214
|
-
"use strict";
|
|
215
|
-
MAX_WORKSPACES = 50;
|
|
216
|
-
}
|
|
217
|
-
});
|
|
218
|
-
|
|
219
28
|
// src/config/config.ts
|
|
220
29
|
var config_exports = {};
|
|
221
30
|
__export(config_exports, {
|
|
222
|
-
addCliHistory: () => addCliHistory,
|
|
223
31
|
generateConnectionToken: () => generateConnectionToken,
|
|
224
32
|
generateMachineId: () => generateMachineId,
|
|
225
33
|
getConfigDir: () => getConfigDir,
|
|
@@ -231,12 +39,12 @@ __export(config_exports, {
|
|
|
231
39
|
saveConfig: () => saveConfig,
|
|
232
40
|
updateConfig: () => updateConfig
|
|
233
41
|
});
|
|
234
|
-
import { homedir
|
|
235
|
-
import { join
|
|
236
|
-
import { existsSync
|
|
237
|
-
import { randomUUID
|
|
42
|
+
import { homedir } from "os";
|
|
43
|
+
import { join } from "path";
|
|
44
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync, chmodSync } from "fs";
|
|
45
|
+
import { randomUUID } from "crypto";
|
|
238
46
|
function generateMachineId() {
|
|
239
|
-
return `${MACHINE_ID_PREFIX}${
|
|
47
|
+
return `${MACHINE_ID_PREFIX}${randomUUID().replace(/-/g, "")}`;
|
|
240
48
|
}
|
|
241
49
|
function isStableMachineId(machineId) {
|
|
242
50
|
return typeof machineId === "string" && machineId.startsWith(MACHINE_ID_PREFIX);
|
|
@@ -256,18 +64,18 @@ function ensureMachineId(config) {
|
|
|
256
64
|
};
|
|
257
65
|
}
|
|
258
66
|
function getConfigDir() {
|
|
259
|
-
const dir =
|
|
260
|
-
if (!
|
|
261
|
-
|
|
67
|
+
const dir = join(homedir(), ".adhdev");
|
|
68
|
+
if (!existsSync(dir)) {
|
|
69
|
+
mkdirSync(dir, { recursive: true });
|
|
262
70
|
}
|
|
263
71
|
return dir;
|
|
264
72
|
}
|
|
265
73
|
function getConfigPath() {
|
|
266
|
-
return
|
|
74
|
+
return join(getConfigDir(), "config.json");
|
|
267
75
|
}
|
|
268
76
|
function loadConfig() {
|
|
269
77
|
const configPath = getConfigPath();
|
|
270
|
-
if (!
|
|
78
|
+
if (!existsSync(configPath)) {
|
|
271
79
|
const initialized = ensureMachineId({ ...DEFAULT_CONFIG });
|
|
272
80
|
try {
|
|
273
81
|
saveConfig(initialized.config);
|
|
@@ -283,15 +91,9 @@ function loadConfig() {
|
|
|
283
91
|
merged.defaultWorkspaceId = merged.activeWorkspaceId;
|
|
284
92
|
}
|
|
285
93
|
delete merged.activeWorkspaceId;
|
|
286
|
-
const hadStoredWorkspaces = Array.isArray(parsed.workspaces) && parsed.workspaces.length > 0;
|
|
287
94
|
const ensured = ensureMachineId(merged);
|
|
288
95
|
const normalized = ensured.config;
|
|
289
|
-
|
|
290
|
-
let configChanged = ensured.changed;
|
|
291
|
-
if (!hadStoredWorkspaces && (normalized.workspaces?.length || 0) > 0) {
|
|
292
|
-
configChanged = true;
|
|
293
|
-
}
|
|
294
|
-
if (configChanged) {
|
|
96
|
+
if (ensured.changed) {
|
|
295
97
|
try {
|
|
296
98
|
saveConfig(normalized);
|
|
297
99
|
} catch {
|
|
@@ -306,8 +108,8 @@ function loadConfig() {
|
|
|
306
108
|
function saveConfig(config) {
|
|
307
109
|
const configPath = getConfigPath();
|
|
308
110
|
const dir = getConfigDir();
|
|
309
|
-
if (!
|
|
310
|
-
|
|
111
|
+
if (!existsSync(dir)) {
|
|
112
|
+
mkdirSync(dir, { recursive: true, mode: 448 });
|
|
311
113
|
}
|
|
312
114
|
writeFileSync(configPath, JSON.stringify(config, null, 2), { encoding: "utf-8", mode: 384 });
|
|
313
115
|
try {
|
|
@@ -346,39 +148,10 @@ function generateConnectionToken() {
|
|
|
346
148
|
}
|
|
347
149
|
return token;
|
|
348
150
|
}
|
|
349
|
-
function addCliHistory(entry) {
|
|
350
|
-
const config = loadConfig();
|
|
351
|
-
const history = config.cliHistory || [];
|
|
352
|
-
const argsKey = (entry.cliArgs || []).join(" ");
|
|
353
|
-
const category = entry.category || "cli";
|
|
354
|
-
const workspaceKey = entry.workspace || "";
|
|
355
|
-
const modelKey = entry.model || "";
|
|
356
|
-
const filtered = history.filter((h) => {
|
|
357
|
-
const hArgsKey = (h.cliArgs || []).join(" ");
|
|
358
|
-
return !((h.category || "cli") === category && h.cliType === entry.cliType && h.dir === entry.dir && hArgsKey === argsKey && (h.workspace || "") === workspaceKey && (h.model || "") === modelKey);
|
|
359
|
-
});
|
|
360
|
-
filtered.unshift({
|
|
361
|
-
...entry,
|
|
362
|
-
category,
|
|
363
|
-
timestamp: Date.now(),
|
|
364
|
-
label: entry.label || (() => {
|
|
365
|
-
const base = `${entry.cliType} \xB7 ${entry.dir.split("/").filter(Boolean).pop() || "root"}`;
|
|
366
|
-
const suffix = [];
|
|
367
|
-
if (entry.workspace && entry.workspace !== entry.dir) suffix.push(entry.workspace.split("/").filter(Boolean).pop() || entry.workspace);
|
|
368
|
-
if (entry.model) suffix.push(`model=${entry.model}`);
|
|
369
|
-
if (argsKey) suffix.push(argsKey);
|
|
370
|
-
if (entry.newWindow) suffix.push("new window");
|
|
371
|
-
return suffix.length > 0 ? `${base} (${suffix.join(" \xB7 ")})` : base;
|
|
372
|
-
})()
|
|
373
|
-
});
|
|
374
|
-
config.cliHistory = filtered.slice(0, 20);
|
|
375
|
-
saveConfig(config);
|
|
376
|
-
}
|
|
377
151
|
var DEFAULT_CONFIG, MACHINE_ID_PREFIX;
|
|
378
152
|
var init_config = __esm({
|
|
379
153
|
"src/config/config.ts"() {
|
|
380
154
|
"use strict";
|
|
381
|
-
init_workspaces();
|
|
382
155
|
DEFAULT_CONFIG = {
|
|
383
156
|
serverUrl: "https://api.adhf.dev",
|
|
384
157
|
apiToken: null,
|
|
@@ -394,17 +167,14 @@ var init_config = __esm({
|
|
|
394
167
|
setupDate: null,
|
|
395
168
|
configuredCLIs: [],
|
|
396
169
|
enabledIdes: [],
|
|
397
|
-
recentCliWorkspaces: [],
|
|
398
170
|
workspaces: [],
|
|
399
171
|
defaultWorkspaceId: null,
|
|
400
|
-
recentWorkspaceActivity: [],
|
|
401
172
|
recentActivity: [],
|
|
402
173
|
recentSessionReads: {},
|
|
403
174
|
machineNickname: null,
|
|
404
175
|
machineId: void 0,
|
|
405
176
|
machineSecret: null,
|
|
406
177
|
registeredMachineId: void 0,
|
|
407
|
-
cliHistory: [],
|
|
408
178
|
providerSettings: {},
|
|
409
179
|
ideSettings: {},
|
|
410
180
|
disableUpstream: false
|
|
@@ -415,7 +185,7 @@ var init_config = __esm({
|
|
|
415
185
|
|
|
416
186
|
// src/logging/logger.ts
|
|
417
187
|
import * as fs2 from "fs";
|
|
418
|
-
import * as
|
|
188
|
+
import * as path3 from "path";
|
|
419
189
|
import * as os4 from "os";
|
|
420
190
|
function setLogLevel(level) {
|
|
421
191
|
currentLevel = level;
|
|
@@ -431,7 +201,7 @@ function checkDateRotation() {
|
|
|
431
201
|
const today = getDateStr();
|
|
432
202
|
if (today !== currentDate) {
|
|
433
203
|
currentDate = today;
|
|
434
|
-
currentLogFile =
|
|
204
|
+
currentLogFile = path3.join(LOG_DIR, `daemon-${currentDate}.log`);
|
|
435
205
|
cleanOldLogs();
|
|
436
206
|
}
|
|
437
207
|
}
|
|
@@ -445,7 +215,7 @@ function cleanOldLogs() {
|
|
|
445
215
|
const dateMatch = file.match(/daemon-(\d{4}-\d{2}-\d{2})/);
|
|
446
216
|
if (dateMatch && dateMatch[1] < cutoffStr) {
|
|
447
217
|
try {
|
|
448
|
-
fs2.unlinkSync(
|
|
218
|
+
fs2.unlinkSync(path3.join(LOG_DIR, file));
|
|
449
219
|
} catch {
|
|
450
220
|
}
|
|
451
221
|
}
|
|
@@ -569,7 +339,7 @@ var init_logger = __esm({
|
|
|
569
339
|
LEVEL_NUM = { debug: 0, info: 1, warn: 2, error: 3 };
|
|
570
340
|
LEVEL_LABEL = { debug: "DBG", info: "INF", warn: "WRN", error: "ERR" };
|
|
571
341
|
currentLevel = "info";
|
|
572
|
-
LOG_DIR = process.platform === "win32" ?
|
|
342
|
+
LOG_DIR = process.platform === "win32" ? path3.join(process.env.LOCALAPPDATA || process.env.APPDATA || path3.join(os4.homedir(), "AppData", "Local"), "adhdev", "logs") : process.platform === "darwin" ? path3.join(os4.homedir(), "Library", "Logs", "adhdev") : path3.join(os4.homedir(), ".local", "share", "adhdev", "logs");
|
|
573
343
|
MAX_LOG_SIZE = 5 * 1024 * 1024;
|
|
574
344
|
MAX_LOG_DAYS = 7;
|
|
575
345
|
try {
|
|
@@ -577,16 +347,16 @@ var init_logger = __esm({
|
|
|
577
347
|
} catch {
|
|
578
348
|
}
|
|
579
349
|
currentDate = getDateStr();
|
|
580
|
-
currentLogFile =
|
|
350
|
+
currentLogFile = path3.join(LOG_DIR, `daemon-${currentDate}.log`);
|
|
581
351
|
cleanOldLogs();
|
|
582
352
|
try {
|
|
583
|
-
const oldLog =
|
|
353
|
+
const oldLog = path3.join(LOG_DIR, "daemon.log");
|
|
584
354
|
if (fs2.existsSync(oldLog)) {
|
|
585
355
|
const stat = fs2.statSync(oldLog);
|
|
586
356
|
const oldDate = stat.mtime.toISOString().slice(0, 10);
|
|
587
|
-
fs2.renameSync(oldLog,
|
|
357
|
+
fs2.renameSync(oldLog, path3.join(LOG_DIR, `daemon-${oldDate}.log`));
|
|
588
358
|
}
|
|
589
|
-
const oldLogBackup =
|
|
359
|
+
const oldLogBackup = path3.join(LOG_DIR, "daemon.log.old");
|
|
590
360
|
if (fs2.existsSync(oldLogBackup)) {
|
|
591
361
|
fs2.unlinkSync(oldLogBackup);
|
|
592
362
|
}
|
|
@@ -618,7 +388,7 @@ var init_logger = __esm({
|
|
|
618
388
|
}
|
|
619
389
|
};
|
|
620
390
|
interceptorInstalled = false;
|
|
621
|
-
LOG_PATH =
|
|
391
|
+
LOG_PATH = path3.join(LOG_DIR, `daemon-${getDateStr()}.log`);
|
|
622
392
|
}
|
|
623
393
|
});
|
|
624
394
|
|
|
@@ -928,7 +698,7 @@ __export(provider_cli_adapter_exports, {
|
|
|
928
698
|
normalizeCliProviderForRuntime: () => normalizeCliProviderForRuntime
|
|
929
699
|
});
|
|
930
700
|
import * as os12 from "os";
|
|
931
|
-
import * as
|
|
701
|
+
import * as path9 from "path";
|
|
932
702
|
import { execSync as execSync4 } from "child_process";
|
|
933
703
|
function stripAnsi(str) {
|
|
934
704
|
return str.replace(/\x1B\[\d*[A-HJKSTfG]/g, " ").replace(/\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])/g, "").replace(/\x1B\][^\x07]*\x07/g, "").replace(/\x1B\][^\x1B]*\x1B\\/g, "").replace(/ +/g, " ");
|
|
@@ -949,7 +719,7 @@ function findBinary(name) {
|
|
|
949
719
|
}
|
|
950
720
|
}
|
|
951
721
|
function isScriptBinary(binaryPath) {
|
|
952
|
-
if (!
|
|
722
|
+
if (!path9.isAbsolute(binaryPath)) return false;
|
|
953
723
|
try {
|
|
954
724
|
const fs12 = __require("fs");
|
|
955
725
|
const resolved = fs12.realpathSync(binaryPath);
|
|
@@ -965,7 +735,7 @@ function isScriptBinary(binaryPath) {
|
|
|
965
735
|
}
|
|
966
736
|
}
|
|
967
737
|
function looksLikeMachOOrElf(filePath) {
|
|
968
|
-
if (!
|
|
738
|
+
if (!path9.isAbsolute(filePath)) return false;
|
|
969
739
|
try {
|
|
970
740
|
const fs12 = __require("fs");
|
|
971
741
|
const resolved = fs12.realpathSync(filePath);
|
|
@@ -1091,9 +861,9 @@ var init_provider_cli_adapter = __esm({
|
|
|
1091
861
|
if (os12.platform() !== "win32") {
|
|
1092
862
|
try {
|
|
1093
863
|
const fs12 = __require("fs");
|
|
1094
|
-
const ptyDir =
|
|
864
|
+
const ptyDir = path9.resolve(path9.dirname(__require.resolve("node-pty")), "..");
|
|
1095
865
|
const platformArch = `${os12.platform()}-${os12.arch()}`;
|
|
1096
|
-
const helper =
|
|
866
|
+
const helper = path9.join(ptyDir, "prebuilds", platformArch, "spawn-helper");
|
|
1097
867
|
if (fs12.existsSync(helper)) {
|
|
1098
868
|
const stat = fs12.statSync(helper);
|
|
1099
869
|
if (!(stat.mode & 73)) {
|
|
@@ -1282,7 +1052,7 @@ var init_provider_cli_adapter = __esm({
|
|
|
1282
1052
|
LOG.info("CLI", `[${this.cliType}] Spawning in ${this.workingDir}`);
|
|
1283
1053
|
let shellCmd;
|
|
1284
1054
|
let shellArgs;
|
|
1285
|
-
const useShellUnix = !isWin && (!!spawnConfig.shell || !
|
|
1055
|
+
const useShellUnix = !isWin && (!!spawnConfig.shell || !path9.isAbsolute(binaryPath) || isScriptBinary(binaryPath) || !looksLikeMachOOrElf(binaryPath));
|
|
1286
1056
|
const useShell = isWin ? !!spawnConfig.shell : useShellUnix;
|
|
1287
1057
|
if (useShell) {
|
|
1288
1058
|
if (!spawnConfig.shell && !isWin) {
|
|
@@ -1707,7 +1477,7 @@ ${data.message || ""}`.trim();
|
|
|
1707
1477
|
if (this.startupParseGate) {
|
|
1708
1478
|
const deadline = Date.now() + 1e4;
|
|
1709
1479
|
while (this.startupParseGate && Date.now() < deadline) {
|
|
1710
|
-
await new Promise((
|
|
1480
|
+
await new Promise((resolve9) => setTimeout(resolve9, 50));
|
|
1711
1481
|
}
|
|
1712
1482
|
}
|
|
1713
1483
|
if (!this.ready) throw new Error(`${this.cliName} not ready (status: ${this.currentStatus})`);
|
|
@@ -1875,17 +1645,17 @@ ${data.message || ""}`.trim();
|
|
|
1875
1645
|
}
|
|
1876
1646
|
}
|
|
1877
1647
|
waitForStopped(timeoutMs) {
|
|
1878
|
-
return new Promise((
|
|
1648
|
+
return new Promise((resolve9) => {
|
|
1879
1649
|
const startedAt = Date.now();
|
|
1880
1650
|
const timer = setInterval(() => {
|
|
1881
1651
|
if (!this.ptyProcess || this.currentStatus === "stopped") {
|
|
1882
1652
|
clearInterval(timer);
|
|
1883
|
-
|
|
1653
|
+
resolve9(true);
|
|
1884
1654
|
return;
|
|
1885
1655
|
}
|
|
1886
1656
|
if (Date.now() - startedAt >= timeoutMs) {
|
|
1887
1657
|
clearInterval(timer);
|
|
1888
|
-
|
|
1658
|
+
resolve9(false);
|
|
1889
1659
|
}
|
|
1890
1660
|
}, 100);
|
|
1891
1661
|
});
|
|
@@ -2077,58 +1847,182 @@ ${data.message || ""}`.trim();
|
|
|
2077
1847
|
|
|
2078
1848
|
// src/index.ts
|
|
2079
1849
|
init_config();
|
|
2080
|
-
init_workspaces();
|
|
2081
1850
|
|
|
2082
|
-
// src/config/
|
|
2083
|
-
|
|
2084
|
-
import * as
|
|
2085
|
-
|
|
2086
|
-
|
|
1851
|
+
// src/config/workspaces.ts
|
|
1852
|
+
import * as fs from "fs";
|
|
1853
|
+
import * as os from "os";
|
|
1854
|
+
import * as path from "path";
|
|
1855
|
+
import { randomUUID as randomUUID2 } from "crypto";
|
|
1856
|
+
var MAX_WORKSPACES = 50;
|
|
1857
|
+
function expandPath(p) {
|
|
1858
|
+
const t = (p || "").trim();
|
|
1859
|
+
if (!t) return "";
|
|
1860
|
+
if (t.startsWith("~")) return path.join(os.homedir(), t.slice(1).replace(/^\//, ""));
|
|
1861
|
+
return path.resolve(t);
|
|
1862
|
+
}
|
|
1863
|
+
function validateWorkspacePath(absPath) {
|
|
2087
1864
|
try {
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
1865
|
+
if (!absPath) return { ok: false, error: "Path required" };
|
|
1866
|
+
if (!fs.existsSync(absPath)) return { ok: false, error: "Path does not exist" };
|
|
1867
|
+
const st = fs.statSync(absPath);
|
|
1868
|
+
if (!st.isDirectory()) return { ok: false, error: "Not a directory" };
|
|
1869
|
+
return { ok: true };
|
|
1870
|
+
} catch (e) {
|
|
1871
|
+
return { ok: false, error: e?.message || "Invalid path" };
|
|
2091
1872
|
}
|
|
2092
1873
|
}
|
|
2093
|
-
function
|
|
2094
|
-
const
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
1874
|
+
function defaultWorkspaceLabel(absPath) {
|
|
1875
|
+
const base = path.basename(absPath) || absPath;
|
|
1876
|
+
return base;
|
|
1877
|
+
}
|
|
1878
|
+
function getDefaultWorkspacePath(config) {
|
|
1879
|
+
const id = config.defaultWorkspaceId;
|
|
1880
|
+
if (!id) return null;
|
|
1881
|
+
const w = (config.workspaces || []).find((x) => x.id === id);
|
|
1882
|
+
if (!w) return null;
|
|
1883
|
+
const abs = expandPath(w.path);
|
|
1884
|
+
if (validateWorkspacePath(abs).ok !== true) return null;
|
|
1885
|
+
return abs;
|
|
1886
|
+
}
|
|
1887
|
+
function getWorkspaceState(config) {
|
|
1888
|
+
const workspaces = [...config.workspaces || []].sort((a, b) => b.addedAt - a.addedAt);
|
|
1889
|
+
const defaultWorkspacePath = getDefaultWorkspacePath(config);
|
|
1890
|
+
return {
|
|
1891
|
+
workspaces,
|
|
1892
|
+
defaultWorkspaceId: config.defaultWorkspaceId ?? null,
|
|
1893
|
+
defaultWorkspacePath
|
|
1894
|
+
};
|
|
1895
|
+
}
|
|
1896
|
+
function resolveLaunchDirectory(args, config) {
|
|
1897
|
+
const a = args || {};
|
|
1898
|
+
if (a.dir != null && String(a.dir).trim()) {
|
|
1899
|
+
const abs = expandPath(String(a.dir).trim());
|
|
1900
|
+
if (abs && validateWorkspacePath(abs).ok === true) {
|
|
1901
|
+
return { ok: true, path: abs, source: "dir" };
|
|
1902
|
+
}
|
|
1903
|
+
return {
|
|
1904
|
+
ok: false,
|
|
1905
|
+
code: "WORKSPACE_LAUNCH_CONTEXT_REQUIRED",
|
|
1906
|
+
message: abs ? "Directory path is not valid or does not exist" : "Invalid directory path"
|
|
1907
|
+
};
|
|
1908
|
+
}
|
|
1909
|
+
if (a.workspaceId) {
|
|
1910
|
+
const w = (config.workspaces || []).find((x) => x.id === a.workspaceId);
|
|
1911
|
+
if (w) {
|
|
1912
|
+
const abs = expandPath(w.path);
|
|
1913
|
+
if (validateWorkspacePath(abs).ok === true) {
|
|
1914
|
+
return { ok: true, path: abs, source: "workspaceId" };
|
|
1915
|
+
}
|
|
1916
|
+
}
|
|
1917
|
+
return {
|
|
1918
|
+
ok: false,
|
|
1919
|
+
code: "WORKSPACE_LAUNCH_CONTEXT_REQUIRED",
|
|
1920
|
+
message: "Saved workspace not found or path is no longer valid"
|
|
1921
|
+
};
|
|
1922
|
+
}
|
|
1923
|
+
if (a.useDefaultWorkspace === true) {
|
|
1924
|
+
const d = getDefaultWorkspacePath(config);
|
|
1925
|
+
if (d) return { ok: true, path: d, source: "defaultWorkspace" };
|
|
1926
|
+
return {
|
|
1927
|
+
ok: false,
|
|
1928
|
+
code: "WORKSPACE_LAUNCH_CONTEXT_REQUIRED",
|
|
1929
|
+
message: "No default workspace is set"
|
|
1930
|
+
};
|
|
1931
|
+
}
|
|
1932
|
+
if (a.useHome === true) {
|
|
1933
|
+
return { ok: true, path: os.homedir(), source: "home" };
|
|
1934
|
+
}
|
|
1935
|
+
return {
|
|
1936
|
+
ok: false,
|
|
1937
|
+
code: "WORKSPACE_LAUNCH_CONTEXT_REQUIRED",
|
|
1938
|
+
message: "Choose a directory, saved workspace, default workspace, or home before launching."
|
|
1939
|
+
};
|
|
1940
|
+
}
|
|
1941
|
+
function resolveIdeWorkspaceFromArgs(args, config) {
|
|
1942
|
+
const ar = args || {};
|
|
1943
|
+
if (ar.workspace) {
|
|
1944
|
+
const abs = expandPath(ar.workspace);
|
|
1945
|
+
if (abs && validateWorkspacePath(abs).ok === true) return abs;
|
|
1946
|
+
}
|
|
1947
|
+
if (ar.workspaceId) {
|
|
1948
|
+
const w = (config.workspaces || []).find((x) => x.id === ar.workspaceId);
|
|
1949
|
+
if (w) {
|
|
1950
|
+
const abs = expandPath(w.path);
|
|
1951
|
+
if (validateWorkspacePath(abs).ok === true) return abs;
|
|
1952
|
+
}
|
|
1953
|
+
}
|
|
1954
|
+
if (ar.useDefaultWorkspace === true) {
|
|
1955
|
+
return getDefaultWorkspacePath(config) || void 0;
|
|
1956
|
+
}
|
|
1957
|
+
return void 0;
|
|
1958
|
+
}
|
|
1959
|
+
function resolveIdeLaunchWorkspace(args, config) {
|
|
1960
|
+
const direct = resolveIdeWorkspaceFromArgs(args, config);
|
|
1961
|
+
if (direct) return direct;
|
|
1962
|
+
if (args?.useDefaultWorkspace === false) return void 0;
|
|
1963
|
+
return getDefaultWorkspacePath(config) || void 0;
|
|
1964
|
+
}
|
|
1965
|
+
function findWorkspaceByPath(config, rawPath) {
|
|
1966
|
+
const abs = path.resolve(expandPath(rawPath));
|
|
1967
|
+
if (!abs) return void 0;
|
|
1968
|
+
return (config.workspaces || []).find((w) => path.resolve(expandPath(w.path)) === abs);
|
|
1969
|
+
}
|
|
1970
|
+
function addWorkspaceEntry(config, rawPath, label, options) {
|
|
1971
|
+
const abs = expandPath(rawPath);
|
|
1972
|
+
const createIfMissing = options?.createIfMissing === true;
|
|
1973
|
+
if (!abs) return { error: "Path required" };
|
|
1974
|
+
if (!fs.existsSync(abs) && createIfMissing) {
|
|
1975
|
+
try {
|
|
1976
|
+
fs.mkdirSync(abs, { recursive: true });
|
|
1977
|
+
} catch (e) {
|
|
1978
|
+
return { error: e?.message || "Could not create directory" };
|
|
1979
|
+
}
|
|
1980
|
+
}
|
|
1981
|
+
const v = validateWorkspacePath(abs);
|
|
1982
|
+
if (!v.ok) return { error: v.error };
|
|
1983
|
+
const list = [...config.workspaces || []];
|
|
1984
|
+
if (list.some((w) => path.resolve(w.path) === abs)) {
|
|
1985
|
+
return { error: "Workspace already in list" };
|
|
1986
|
+
}
|
|
1987
|
+
if (list.length >= MAX_WORKSPACES) {
|
|
1988
|
+
return { error: `Maximum ${MAX_WORKSPACES} workspaces` };
|
|
1989
|
+
}
|
|
2098
1990
|
const entry = {
|
|
1991
|
+
id: randomUUID2(),
|
|
2099
1992
|
path: abs,
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
agentType: meta?.agentType
|
|
1993
|
+
label: (label || "").trim() || defaultWorkspaceLabel(abs),
|
|
1994
|
+
addedAt: Date.now()
|
|
2103
1995
|
};
|
|
2104
|
-
|
|
2105
|
-
return { ...config,
|
|
1996
|
+
list.push(entry);
|
|
1997
|
+
return { config: { ...config, workspaces: list }, entry };
|
|
2106
1998
|
}
|
|
2107
|
-
function
|
|
2108
|
-
const list =
|
|
2109
|
-
list.
|
|
2110
|
-
|
|
1999
|
+
function removeWorkspaceEntry(config, id) {
|
|
2000
|
+
const list = (config.workspaces || []).filter((w) => w.id !== id);
|
|
2001
|
+
if (list.length === (config.workspaces || []).length) return { error: "Workspace not found" };
|
|
2002
|
+
let defaultWorkspaceId = config.defaultWorkspaceId;
|
|
2003
|
+
if (defaultWorkspaceId === id) defaultWorkspaceId = null;
|
|
2004
|
+
return { config: { ...config, workspaces: list, defaultWorkspaceId } };
|
|
2111
2005
|
}
|
|
2112
|
-
function
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
};
|
|
2006
|
+
function setDefaultWorkspaceId(config, id) {
|
|
2007
|
+
if (id === null) {
|
|
2008
|
+
return { config: { ...config, defaultWorkspaceId: null } };
|
|
2009
|
+
}
|
|
2010
|
+
const w = (config.workspaces || []).find((x) => x.id === id);
|
|
2011
|
+
if (!w) return { error: "Workspace not found" };
|
|
2012
|
+
const abs = expandPath(w.path);
|
|
2013
|
+
if (validateWorkspacePath(abs).ok !== true) return { error: "Workspace path is no longer valid" };
|
|
2014
|
+
return { config: { ...config, defaultWorkspaceId: id } };
|
|
2120
2015
|
}
|
|
2121
2016
|
|
|
2122
2017
|
// src/config/recent-activity.ts
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
var MAX_ACTIVITY2 = 30;
|
|
2018
|
+
import * as path2 from "path";
|
|
2019
|
+
var MAX_ACTIVITY = 30;
|
|
2126
2020
|
function normalizeWorkspace(workspace) {
|
|
2127
2021
|
if (!workspace) return "";
|
|
2128
2022
|
try {
|
|
2129
|
-
return
|
|
2023
|
+
return path2.resolve(expandPath(workspace));
|
|
2130
2024
|
} catch {
|
|
2131
|
-
return
|
|
2025
|
+
return path2.resolve(workspace);
|
|
2132
2026
|
}
|
|
2133
2027
|
}
|
|
2134
2028
|
function buildRecentActivityKey(entry) {
|
|
@@ -2144,7 +2038,7 @@ function appendRecentActivity(config, entry) {
|
|
|
2144
2038
|
const filtered = (config.recentActivity || []).filter((item) => item.id !== nextEntry.id);
|
|
2145
2039
|
return {
|
|
2146
2040
|
...config,
|
|
2147
|
-
recentActivity: [nextEntry, ...filtered].slice(0,
|
|
2041
|
+
recentActivity: [nextEntry, ...filtered].slice(0, MAX_ACTIVITY)
|
|
2148
2042
|
};
|
|
2149
2043
|
}
|
|
2150
2044
|
function getRecentActivity(config, limit = 20) {
|
|
@@ -2272,15 +2166,15 @@ function parseVersion(raw) {
|
|
|
2272
2166
|
return match ? match[1] : raw.split("\n")[0].slice(0, 100);
|
|
2273
2167
|
}
|
|
2274
2168
|
function execAsync(cmd, timeoutMs = 5e3) {
|
|
2275
|
-
return new Promise((
|
|
2169
|
+
return new Promise((resolve9) => {
|
|
2276
2170
|
const child = exec(cmd, { encoding: "utf-8", timeout: timeoutMs }, (err, stdout) => {
|
|
2277
2171
|
if (err || !stdout?.trim()) {
|
|
2278
|
-
|
|
2172
|
+
resolve9(null);
|
|
2279
2173
|
} else {
|
|
2280
|
-
|
|
2174
|
+
resolve9(stdout.trim());
|
|
2281
2175
|
}
|
|
2282
2176
|
});
|
|
2283
|
-
child.on("error", () =>
|
|
2177
|
+
child.on("error", () => resolve9(null));
|
|
2284
2178
|
});
|
|
2285
2179
|
}
|
|
2286
2180
|
async function detectCLIs(providerLoader) {
|
|
@@ -2447,7 +2341,7 @@ var DaemonCdpManager = class {
|
|
|
2447
2341
|
* Returns multiple entries if multiple IDE windows are open on same port
|
|
2448
2342
|
*/
|
|
2449
2343
|
static listAllTargets(port) {
|
|
2450
|
-
return new Promise((
|
|
2344
|
+
return new Promise((resolve9) => {
|
|
2451
2345
|
const req = http.get(`http://127.0.0.1:${port}/json`, (res) => {
|
|
2452
2346
|
let data = "";
|
|
2453
2347
|
res.on("data", (chunk) => data += chunk.toString());
|
|
@@ -2463,16 +2357,16 @@ var DaemonCdpManager = class {
|
|
|
2463
2357
|
(t) => !isNonMain(t.title || "") && t.url?.includes("workbench.html") && !t.url?.includes("agent")
|
|
2464
2358
|
);
|
|
2465
2359
|
const fallbackPages = pages.filter((t) => !isNonMain(t.title || ""));
|
|
2466
|
-
|
|
2360
|
+
resolve9(mainPages.length > 0 ? mainPages : fallbackPages);
|
|
2467
2361
|
} catch {
|
|
2468
|
-
|
|
2362
|
+
resolve9([]);
|
|
2469
2363
|
}
|
|
2470
2364
|
});
|
|
2471
2365
|
});
|
|
2472
|
-
req.on("error", () =>
|
|
2366
|
+
req.on("error", () => resolve9([]));
|
|
2473
2367
|
req.setTimeout(2e3, () => {
|
|
2474
2368
|
req.destroy();
|
|
2475
|
-
|
|
2369
|
+
resolve9([]);
|
|
2476
2370
|
});
|
|
2477
2371
|
});
|
|
2478
2372
|
}
|
|
@@ -2512,7 +2406,7 @@ var DaemonCdpManager = class {
|
|
|
2512
2406
|
}
|
|
2513
2407
|
}
|
|
2514
2408
|
findTargetOnPort(port) {
|
|
2515
|
-
return new Promise((
|
|
2409
|
+
return new Promise((resolve9) => {
|
|
2516
2410
|
const req = http.get(`http://127.0.0.1:${port}/json`, (res) => {
|
|
2517
2411
|
let data = "";
|
|
2518
2412
|
res.on("data", (chunk) => data += chunk.toString());
|
|
@@ -2523,7 +2417,7 @@ var DaemonCdpManager = class {
|
|
|
2523
2417
|
(t) => (t.type === "page" || t.type === "browser" || t.type === "Page") && t.webSocketDebuggerUrl
|
|
2524
2418
|
);
|
|
2525
2419
|
if (pages.length === 0) {
|
|
2526
|
-
|
|
2420
|
+
resolve9(targets.find((t) => t.webSocketDebuggerUrl) || null);
|
|
2527
2421
|
return;
|
|
2528
2422
|
}
|
|
2529
2423
|
const mainPages = pages.filter((t) => !this.isNonMainTitle(t.title || ""));
|
|
@@ -2533,24 +2427,24 @@ var DaemonCdpManager = class {
|
|
|
2533
2427
|
const specific = list.find((t) => t.id === this._targetId);
|
|
2534
2428
|
if (specific) {
|
|
2535
2429
|
this._pageTitle = specific.title || "";
|
|
2536
|
-
|
|
2430
|
+
resolve9(specific);
|
|
2537
2431
|
} else {
|
|
2538
2432
|
this.log(`[CDP] Target ${this._targetId} not found in page list`);
|
|
2539
|
-
|
|
2433
|
+
resolve9(null);
|
|
2540
2434
|
}
|
|
2541
2435
|
return;
|
|
2542
2436
|
}
|
|
2543
2437
|
this._pageTitle = list[0]?.title || "";
|
|
2544
|
-
|
|
2438
|
+
resolve9(list[0]);
|
|
2545
2439
|
} catch {
|
|
2546
|
-
|
|
2440
|
+
resolve9(null);
|
|
2547
2441
|
}
|
|
2548
2442
|
});
|
|
2549
2443
|
});
|
|
2550
|
-
req.on("error", () =>
|
|
2444
|
+
req.on("error", () => resolve9(null));
|
|
2551
2445
|
req.setTimeout(2e3, () => {
|
|
2552
2446
|
req.destroy();
|
|
2553
|
-
|
|
2447
|
+
resolve9(null);
|
|
2554
2448
|
});
|
|
2555
2449
|
});
|
|
2556
2450
|
}
|
|
@@ -2561,7 +2455,7 @@ var DaemonCdpManager = class {
|
|
|
2561
2455
|
this.extensionProviders = providers;
|
|
2562
2456
|
}
|
|
2563
2457
|
connectToTarget(wsUrl) {
|
|
2564
|
-
return new Promise((
|
|
2458
|
+
return new Promise((resolve9) => {
|
|
2565
2459
|
this.ws = new WebSocket(wsUrl);
|
|
2566
2460
|
this.ws.on("open", async () => {
|
|
2567
2461
|
this._connected = true;
|
|
@@ -2571,17 +2465,17 @@ var DaemonCdpManager = class {
|
|
|
2571
2465
|
}
|
|
2572
2466
|
this.connectBrowserWs().catch(() => {
|
|
2573
2467
|
});
|
|
2574
|
-
|
|
2468
|
+
resolve9(true);
|
|
2575
2469
|
});
|
|
2576
2470
|
this.ws.on("message", (data) => {
|
|
2577
2471
|
try {
|
|
2578
2472
|
const msg = JSON.parse(data.toString());
|
|
2579
2473
|
if (msg.id && this.pending.has(msg.id)) {
|
|
2580
|
-
const { resolve:
|
|
2474
|
+
const { resolve: resolve10, reject } = this.pending.get(msg.id);
|
|
2581
2475
|
this.pending.delete(msg.id);
|
|
2582
2476
|
this.failureCount = 0;
|
|
2583
2477
|
if (msg.error) reject(new Error(msg.error.message));
|
|
2584
|
-
else
|
|
2478
|
+
else resolve10(msg.result);
|
|
2585
2479
|
} else if (msg.method === "Runtime.executionContextCreated") {
|
|
2586
2480
|
this.contexts.add(msg.params.context.id);
|
|
2587
2481
|
} else if (msg.method === "Runtime.executionContextDestroyed") {
|
|
@@ -2604,7 +2498,7 @@ var DaemonCdpManager = class {
|
|
|
2604
2498
|
this.ws.on("error", (err) => {
|
|
2605
2499
|
this.log(`[CDP] WebSocket error: ${err.message}`);
|
|
2606
2500
|
this._connected = false;
|
|
2607
|
-
|
|
2501
|
+
resolve9(false);
|
|
2608
2502
|
});
|
|
2609
2503
|
});
|
|
2610
2504
|
}
|
|
@@ -2618,7 +2512,7 @@ var DaemonCdpManager = class {
|
|
|
2618
2512
|
return;
|
|
2619
2513
|
}
|
|
2620
2514
|
this.log(`[CDP] Connecting browser WS for target discovery...`);
|
|
2621
|
-
await new Promise((
|
|
2515
|
+
await new Promise((resolve9, reject) => {
|
|
2622
2516
|
this.browserWs = new WebSocket(browserWsUrl);
|
|
2623
2517
|
this.browserWs.on("open", async () => {
|
|
2624
2518
|
this._browserConnected = true;
|
|
@@ -2628,16 +2522,16 @@ var DaemonCdpManager = class {
|
|
|
2628
2522
|
} catch (e) {
|
|
2629
2523
|
this.log(`[CDP] setDiscoverTargets failed: ${e.message}`);
|
|
2630
2524
|
}
|
|
2631
|
-
|
|
2525
|
+
resolve9();
|
|
2632
2526
|
});
|
|
2633
2527
|
this.browserWs.on("message", (data) => {
|
|
2634
2528
|
try {
|
|
2635
2529
|
const msg = JSON.parse(data.toString());
|
|
2636
2530
|
if (msg.id && this.browserPending.has(msg.id)) {
|
|
2637
|
-
const { resolve:
|
|
2531
|
+
const { resolve: resolve10, reject: reject2 } = this.browserPending.get(msg.id);
|
|
2638
2532
|
this.browserPending.delete(msg.id);
|
|
2639
2533
|
if (msg.error) reject2(new Error(msg.error.message));
|
|
2640
|
-
else
|
|
2534
|
+
else resolve10(msg.result);
|
|
2641
2535
|
}
|
|
2642
2536
|
} catch {
|
|
2643
2537
|
}
|
|
@@ -2657,31 +2551,31 @@ var DaemonCdpManager = class {
|
|
|
2657
2551
|
}
|
|
2658
2552
|
}
|
|
2659
2553
|
getBrowserWsUrl() {
|
|
2660
|
-
return new Promise((
|
|
2554
|
+
return new Promise((resolve9) => {
|
|
2661
2555
|
const req = http.get(`http://127.0.0.1:${this.port}/json/version`, (res) => {
|
|
2662
2556
|
let data = "";
|
|
2663
2557
|
res.on("data", (chunk) => data += chunk.toString());
|
|
2664
2558
|
res.on("end", () => {
|
|
2665
2559
|
try {
|
|
2666
2560
|
const info = JSON.parse(data);
|
|
2667
|
-
|
|
2561
|
+
resolve9(info.webSocketDebuggerUrl || null);
|
|
2668
2562
|
} catch {
|
|
2669
|
-
|
|
2563
|
+
resolve9(null);
|
|
2670
2564
|
}
|
|
2671
2565
|
});
|
|
2672
2566
|
});
|
|
2673
|
-
req.on("error", () =>
|
|
2567
|
+
req.on("error", () => resolve9(null));
|
|
2674
2568
|
req.setTimeout(3e3, () => {
|
|
2675
2569
|
req.destroy();
|
|
2676
|
-
|
|
2570
|
+
resolve9(null);
|
|
2677
2571
|
});
|
|
2678
2572
|
});
|
|
2679
2573
|
}
|
|
2680
2574
|
sendBrowser(method, params = {}, timeoutMs = 15e3) {
|
|
2681
|
-
return new Promise((
|
|
2575
|
+
return new Promise((resolve9, reject) => {
|
|
2682
2576
|
if (!this.browserWs || !this._browserConnected) return reject(new Error("Browser WS not connected"));
|
|
2683
2577
|
const id = this.browserMsgId++;
|
|
2684
|
-
this.browserPending.set(id, { resolve:
|
|
2578
|
+
this.browserPending.set(id, { resolve: resolve9, reject });
|
|
2685
2579
|
this.browserWs.send(JSON.stringify({ id, method, params }));
|
|
2686
2580
|
setTimeout(() => {
|
|
2687
2581
|
if (this.browserPending.has(id)) {
|
|
@@ -2721,11 +2615,11 @@ var DaemonCdpManager = class {
|
|
|
2721
2615
|
}
|
|
2722
2616
|
// ─── CDP Protocol ────────────────────────────────────────
|
|
2723
2617
|
sendInternal(method, params = {}, timeoutMs = 15e3) {
|
|
2724
|
-
return new Promise((
|
|
2618
|
+
return new Promise((resolve9, reject) => {
|
|
2725
2619
|
if (!this.ws || !this._connected) return reject(new Error("CDP not connected"));
|
|
2726
2620
|
if (this.ws.readyState !== WebSocket.OPEN) return reject(new Error("WebSocket not open"));
|
|
2727
2621
|
const id = this.msgId++;
|
|
2728
|
-
this.pending.set(id, { resolve:
|
|
2622
|
+
this.pending.set(id, { resolve: resolve9, reject });
|
|
2729
2623
|
this.ws.send(JSON.stringify({ id, method, params }));
|
|
2730
2624
|
setTimeout(() => {
|
|
2731
2625
|
if (this.pending.has(id)) {
|
|
@@ -2974,7 +2868,7 @@ var DaemonCdpManager = class {
|
|
|
2974
2868
|
const browserWs = this.browserWs;
|
|
2975
2869
|
let msgId = this.browserMsgId;
|
|
2976
2870
|
const sendWs = (method, params = {}, sessionId) => {
|
|
2977
|
-
return new Promise((
|
|
2871
|
+
return new Promise((resolve9, reject) => {
|
|
2978
2872
|
const mid = msgId++;
|
|
2979
2873
|
this.browserMsgId = msgId;
|
|
2980
2874
|
const handler = (raw) => {
|
|
@@ -2983,7 +2877,7 @@ var DaemonCdpManager = class {
|
|
|
2983
2877
|
if (msg.id === mid) {
|
|
2984
2878
|
browserWs.removeListener("message", handler);
|
|
2985
2879
|
if (msg.error) reject(new Error(msg.error.message || JSON.stringify(msg.error)));
|
|
2986
|
-
else
|
|
2880
|
+
else resolve9(msg.result);
|
|
2987
2881
|
}
|
|
2988
2882
|
} catch {
|
|
2989
2883
|
}
|
|
@@ -3174,14 +3068,14 @@ var DaemonCdpManager = class {
|
|
|
3174
3068
|
if (!ws || ws.readyState !== WebSocket.OPEN) {
|
|
3175
3069
|
throw new Error("CDP not connected");
|
|
3176
3070
|
}
|
|
3177
|
-
return new Promise((
|
|
3071
|
+
return new Promise((resolve9, reject) => {
|
|
3178
3072
|
const id = getNextId();
|
|
3179
3073
|
pendingMap.set(id, {
|
|
3180
3074
|
resolve: (result) => {
|
|
3181
3075
|
if (result?.result?.subtype === "error") {
|
|
3182
3076
|
reject(new Error(result.result.description));
|
|
3183
3077
|
} else {
|
|
3184
|
-
|
|
3078
|
+
resolve9(result?.result?.value);
|
|
3185
3079
|
}
|
|
3186
3080
|
},
|
|
3187
3081
|
reject
|
|
@@ -3213,10 +3107,10 @@ var DaemonCdpManager = class {
|
|
|
3213
3107
|
throw new Error("CDP not connected");
|
|
3214
3108
|
}
|
|
3215
3109
|
const sendViaSession = (method, params = {}) => {
|
|
3216
|
-
return new Promise((
|
|
3110
|
+
return new Promise((resolve9, reject) => {
|
|
3217
3111
|
const pendingMap = this._browserConnected ? this.browserPending : this.pending;
|
|
3218
3112
|
const id = this._browserConnected ? this.browserMsgId++ : this.msgId++;
|
|
3219
|
-
pendingMap.set(id, { resolve:
|
|
3113
|
+
pendingMap.set(id, { resolve: resolve9, reject });
|
|
3220
3114
|
ws.send(JSON.stringify({ id, sessionId, method, params }));
|
|
3221
3115
|
setTimeout(() => {
|
|
3222
3116
|
if (pendingMap.has(id)) {
|
|
@@ -3923,9 +3817,9 @@ var ExtensionProviderInstance = class {
|
|
|
3923
3817
|
|
|
3924
3818
|
// src/config/chat-history.ts
|
|
3925
3819
|
import * as fs3 from "fs";
|
|
3926
|
-
import * as
|
|
3820
|
+
import * as path4 from "path";
|
|
3927
3821
|
import * as os5 from "os";
|
|
3928
|
-
var HISTORY_DIR =
|
|
3822
|
+
var HISTORY_DIR = path4.join(os5.homedir(), ".adhdev", "history");
|
|
3929
3823
|
var RETAIN_DAYS = 30;
|
|
3930
3824
|
var ChatHistoryWriter = class {
|
|
3931
3825
|
/** Last seen message count per agent (deduplication) */
|
|
@@ -3968,11 +3862,11 @@ var ChatHistoryWriter = class {
|
|
|
3968
3862
|
});
|
|
3969
3863
|
}
|
|
3970
3864
|
if (newMessages.length === 0) return;
|
|
3971
|
-
const dir =
|
|
3865
|
+
const dir = path4.join(HISTORY_DIR, this.sanitize(agentType));
|
|
3972
3866
|
fs3.mkdirSync(dir, { recursive: true });
|
|
3973
3867
|
const date = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
3974
3868
|
const filePrefix = instanceId ? `${this.sanitize(instanceId)}_` : "";
|
|
3975
|
-
const filePath =
|
|
3869
|
+
const filePath = path4.join(dir, `${filePrefix}${date}.jsonl`);
|
|
3976
3870
|
const lines = newMessages.map((m) => JSON.stringify(m)).join("\n") + "\n";
|
|
3977
3871
|
fs3.appendFileSync(filePath, lines, "utf-8");
|
|
3978
3872
|
const prevCount = this.lastSeenCounts.get(dedupKey) || 0;
|
|
@@ -4016,11 +3910,11 @@ ${next}`;
|
|
|
4016
3910
|
this.lastSeenTerminal.set(dedupKey, next);
|
|
4017
3911
|
return;
|
|
4018
3912
|
}
|
|
4019
|
-
const dir =
|
|
3913
|
+
const dir = path4.join(HISTORY_DIR, this.sanitize(agentType));
|
|
4020
3914
|
fs3.mkdirSync(dir, { recursive: true });
|
|
4021
3915
|
const date = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
4022
3916
|
const filePrefix = instanceId ? `${this.sanitize(instanceId)}_` : "";
|
|
4023
|
-
const filePath =
|
|
3917
|
+
const filePath = path4.join(dir, `${filePrefix}${date}.terminal.log`);
|
|
4024
3918
|
fs3.appendFileSync(filePath, delta, "utf-8");
|
|
4025
3919
|
this.lastSeenTerminal.set(dedupKey, next);
|
|
4026
3920
|
if (!this.rotated) {
|
|
@@ -4044,10 +3938,10 @@ ${next}`;
|
|
|
4044
3938
|
const cutoff = Date.now() - RETAIN_DAYS * 24 * 60 * 60 * 1e3;
|
|
4045
3939
|
const agentDirs = fs3.readdirSync(HISTORY_DIR, { withFileTypes: true }).filter((d) => d.isDirectory());
|
|
4046
3940
|
for (const dir of agentDirs) {
|
|
4047
|
-
const dirPath =
|
|
3941
|
+
const dirPath = path4.join(HISTORY_DIR, dir.name);
|
|
4048
3942
|
const files = fs3.readdirSync(dirPath).filter((f) => f.endsWith(".jsonl") || f.endsWith(".terminal.log"));
|
|
4049
3943
|
for (const file of files) {
|
|
4050
|
-
const filePath =
|
|
3944
|
+
const filePath = path4.join(dirPath, file);
|
|
4051
3945
|
const stat = fs3.statSync(filePath);
|
|
4052
3946
|
if (stat.mtimeMs < cutoff) {
|
|
4053
3947
|
fs3.unlinkSync(filePath);
|
|
@@ -4065,7 +3959,7 @@ ${next}`;
|
|
|
4065
3959
|
function readChatHistory(agentType, offset = 0, limit = 30, instanceId) {
|
|
4066
3960
|
try {
|
|
4067
3961
|
const sanitized = agentType.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
4068
|
-
const dir =
|
|
3962
|
+
const dir = path4.join(HISTORY_DIR, sanitized);
|
|
4069
3963
|
if (!fs3.existsSync(dir)) return { messages: [], hasMore: false };
|
|
4070
3964
|
const sanitizedInstance = instanceId?.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
4071
3965
|
const files = fs3.readdirSync(dir).filter((f) => {
|
|
@@ -4079,7 +3973,7 @@ function readChatHistory(agentType, offset = 0, limit = 30, instanceId) {
|
|
|
4079
3973
|
const needed = offset + limit + 1;
|
|
4080
3974
|
for (const file of files) {
|
|
4081
3975
|
if (allMessages.length >= needed) break;
|
|
4082
|
-
const filePath =
|
|
3976
|
+
const filePath = path4.join(dir, file);
|
|
4083
3977
|
const content = fs3.readFileSync(filePath, "utf-8");
|
|
4084
3978
|
const lines = content.trim().split("\n").filter(Boolean);
|
|
4085
3979
|
for (let i = lines.length - 1; i >= 0; i--) {
|
|
@@ -5147,11 +5041,18 @@ function buildSessionEntries(allStates, cdpManagers) {
|
|
|
5147
5041
|
for (const state of acpStates) {
|
|
5148
5042
|
sessions.push(buildAcpSession(state));
|
|
5149
5043
|
}
|
|
5044
|
+
const extensionParentIds = new Set(
|
|
5045
|
+
sessions.filter((session) => session.transport === "cdp-webview" && !!session.parentId).map((session) => session.parentId)
|
|
5046
|
+
);
|
|
5047
|
+
for (const session of sessions) {
|
|
5048
|
+
if (session.transport === "cdp-page" && extensionParentIds.has(session.id)) {
|
|
5049
|
+
session.surfaceHidden = true;
|
|
5050
|
+
}
|
|
5051
|
+
}
|
|
5150
5052
|
return sessions;
|
|
5151
5053
|
}
|
|
5152
5054
|
|
|
5153
5055
|
// src/commands/handler.ts
|
|
5154
|
-
init_config();
|
|
5155
5056
|
init_logger();
|
|
5156
5057
|
|
|
5157
5058
|
// src/commands/chat-commands.ts
|
|
@@ -5976,7 +5877,7 @@ async function handleResolveAction(h, args) {
|
|
|
5976
5877
|
|
|
5977
5878
|
// src/commands/cdp-commands.ts
|
|
5978
5879
|
import * as fs4 from "fs";
|
|
5979
|
-
import * as
|
|
5880
|
+
import * as path5 from "path";
|
|
5980
5881
|
import * as os6 from "os";
|
|
5981
5882
|
var KEY_TO_VK = {
|
|
5982
5883
|
Backspace: 8,
|
|
@@ -6207,11 +6108,11 @@ function resolveSafePath(requestedPath) {
|
|
|
6207
6108
|
const home = os6.homedir();
|
|
6208
6109
|
let resolved;
|
|
6209
6110
|
if (requestedPath.startsWith("~")) {
|
|
6210
|
-
resolved =
|
|
6211
|
-
} else if (
|
|
6111
|
+
resolved = path5.join(home, requestedPath.slice(1));
|
|
6112
|
+
} else if (path5.isAbsolute(requestedPath)) {
|
|
6212
6113
|
resolved = requestedPath;
|
|
6213
6114
|
} else {
|
|
6214
|
-
resolved =
|
|
6115
|
+
resolved = path5.resolve(requestedPath);
|
|
6215
6116
|
}
|
|
6216
6117
|
return resolved;
|
|
6217
6118
|
}
|
|
@@ -6227,7 +6128,7 @@ async function handleFileRead(h, args) {
|
|
|
6227
6128
|
async function handleFileWrite(h, args) {
|
|
6228
6129
|
try {
|
|
6229
6130
|
const filePath = resolveSafePath(args?.path);
|
|
6230
|
-
fs4.mkdirSync(
|
|
6131
|
+
fs4.mkdirSync(path5.dirname(filePath), { recursive: true });
|
|
6231
6132
|
fs4.writeFileSync(filePath, args?.content || "", "utf-8");
|
|
6232
6133
|
return { success: true, path: filePath };
|
|
6233
6134
|
} catch (e) {
|
|
@@ -6241,7 +6142,7 @@ async function handleFileList(h, args) {
|
|
|
6241
6142
|
const files = entries.map((e) => ({
|
|
6242
6143
|
name: e.name,
|
|
6243
6144
|
type: e.isDirectory() ? "directory" : "file",
|
|
6244
|
-
size: e.isFile() ? fs4.statSync(
|
|
6145
|
+
size: e.isFile() ? fs4.statSync(path5.join(dirPath, e.name)).size : void 0
|
|
6245
6146
|
}));
|
|
6246
6147
|
return { success: true, files, path: dirPath };
|
|
6247
6148
|
} catch (e) {
|
|
@@ -6253,7 +6154,6 @@ async function handleFileListBrowse(h, args) {
|
|
|
6253
6154
|
}
|
|
6254
6155
|
|
|
6255
6156
|
// src/commands/stream-commands.ts
|
|
6256
|
-
init_config();
|
|
6257
6157
|
init_logger();
|
|
6258
6158
|
async function handleFocusSession(h, args) {
|
|
6259
6159
|
if (!h.agentStream || !h.getCdp()) return { success: false, error: "AgentStream or CDP not available" };
|
|
@@ -6407,13 +6307,12 @@ function handleGetIdeExtensions(h, args) {
|
|
|
6407
6307
|
const loader = h.ctx.providerLoader;
|
|
6408
6308
|
if (!loader) return { success: false, error: "ProviderLoader not initialized" };
|
|
6409
6309
|
const allExtProviders = loader.getByCategory?.("extension") || [];
|
|
6410
|
-
const config = loadConfig();
|
|
6411
6310
|
if (ideType) {
|
|
6412
6311
|
const extensions = allExtProviders.map((p) => ({
|
|
6413
6312
|
type: p.type,
|
|
6414
6313
|
name: p.name,
|
|
6415
6314
|
extensionId: p.extensionId,
|
|
6416
|
-
enabled:
|
|
6315
|
+
enabled: loader.getIdeExtensionEnabledState?.(ideType, p.type) === true
|
|
6417
6316
|
}));
|
|
6418
6317
|
return { success: true, ideType, extensions };
|
|
6419
6318
|
}
|
|
@@ -6424,7 +6323,7 @@ function handleGetIdeExtensions(h, args) {
|
|
|
6424
6323
|
type: p.type,
|
|
6425
6324
|
name: p.name,
|
|
6426
6325
|
extensionId: p.extensionId,
|
|
6427
|
-
enabled:
|
|
6326
|
+
enabled: loader.getIdeExtensionEnabledState?.(ide, p.type) === true
|
|
6428
6327
|
}));
|
|
6429
6328
|
}
|
|
6430
6329
|
return { success: true, ideExtensions: result };
|
|
@@ -6447,7 +6346,6 @@ function handleSetIdeExtension(h, args) {
|
|
|
6447
6346
|
|
|
6448
6347
|
// src/commands/workspace-commands.ts
|
|
6449
6348
|
init_config();
|
|
6450
|
-
init_workspaces();
|
|
6451
6349
|
function handleWorkspaceList() {
|
|
6452
6350
|
const config = loadConfig();
|
|
6453
6351
|
const state = getWorkspaceState(config);
|
|
@@ -6455,9 +6353,7 @@ function handleWorkspaceList() {
|
|
|
6455
6353
|
success: true,
|
|
6456
6354
|
workspaces: state.workspaces,
|
|
6457
6355
|
defaultWorkspaceId: state.defaultWorkspaceId,
|
|
6458
|
-
defaultWorkspacePath: state.defaultWorkspacePath
|
|
6459
|
-
legacyRecentPaths: config.recentCliWorkspaces || [],
|
|
6460
|
-
activity: getWorkspaceActivity(config, 25)
|
|
6356
|
+
defaultWorkspacePath: state.defaultWorkspacePath
|
|
6461
6357
|
};
|
|
6462
6358
|
}
|
|
6463
6359
|
function handleWorkspaceAdd(args) {
|
|
@@ -6468,10 +6364,9 @@ function handleWorkspaceAdd(args) {
|
|
|
6468
6364
|
const config = loadConfig();
|
|
6469
6365
|
const result = addWorkspaceEntry(config, rawPath, label, { createIfMissing });
|
|
6470
6366
|
if ("error" in result) return { success: false, error: result.error };
|
|
6471
|
-
|
|
6472
|
-
|
|
6473
|
-
|
|
6474
|
-
return { success: true, entry: result.entry, ...state, activity: getWorkspaceActivity(cfg, 25) };
|
|
6367
|
+
saveConfig(result.config);
|
|
6368
|
+
const state = getWorkspaceState(result.config);
|
|
6369
|
+
return { success: true, entry: result.entry, ...state };
|
|
6475
6370
|
}
|
|
6476
6371
|
function handleWorkspaceRemove(args) {
|
|
6477
6372
|
const id = (args?.id || "").trim();
|
|
@@ -6480,13 +6375,9 @@ function handleWorkspaceRemove(args) {
|
|
|
6480
6375
|
const removed = (config.workspaces || []).find((w) => w.id === id);
|
|
6481
6376
|
const result = removeWorkspaceEntry(config, id);
|
|
6482
6377
|
if ("error" in result) return { success: false, error: result.error };
|
|
6483
|
-
|
|
6484
|
-
|
|
6485
|
-
|
|
6486
|
-
}
|
|
6487
|
-
saveConfig(cfg);
|
|
6488
|
-
const state = getWorkspaceState(cfg);
|
|
6489
|
-
return { success: true, removedId: id, ...state, activity: getWorkspaceActivity(cfg, 25) };
|
|
6378
|
+
saveConfig(result.config);
|
|
6379
|
+
const state = getWorkspaceState(result.config);
|
|
6380
|
+
return { success: true, removedId: id, ...state };
|
|
6490
6381
|
}
|
|
6491
6382
|
function handleWorkspaceSetDefault(args) {
|
|
6492
6383
|
const clear = args?.clear === true || args?.id === null || args?.id === "";
|
|
@@ -6498,8 +6389,7 @@ function handleWorkspaceSetDefault(args) {
|
|
|
6498
6389
|
const state2 = getWorkspaceState(result2.config);
|
|
6499
6390
|
return {
|
|
6500
6391
|
success: true,
|
|
6501
|
-
...state2
|
|
6502
|
-
activity: getWorkspaceActivity(result2.config, 25)
|
|
6392
|
+
...state2
|
|
6503
6393
|
};
|
|
6504
6394
|
}
|
|
6505
6395
|
const pathArg = args?.path != null && String(args.path).trim() ? String(args.path).trim() : "";
|
|
@@ -6523,18 +6413,12 @@ function handleWorkspaceSetDefault(args) {
|
|
|
6523
6413
|
}
|
|
6524
6414
|
const result = setDefaultWorkspaceId(config, nextId);
|
|
6525
6415
|
if ("error" in result) return { success: false, error: result.error };
|
|
6526
|
-
|
|
6527
|
-
const
|
|
6528
|
-
|
|
6529
|
-
out = appendWorkspaceActivity(out, ap, { kind: "default" });
|
|
6530
|
-
}
|
|
6531
|
-
saveConfig(out);
|
|
6532
|
-
const state = getWorkspaceState(out);
|
|
6533
|
-
return { success: true, ...state, activity: getWorkspaceActivity(out, 25) };
|
|
6416
|
+
saveConfig(result.config);
|
|
6417
|
+
const state = getWorkspaceState(result.config);
|
|
6418
|
+
return { success: true, ...state };
|
|
6534
6419
|
}
|
|
6535
6420
|
|
|
6536
6421
|
// src/commands/handler.ts
|
|
6537
|
-
init_workspaces();
|
|
6538
6422
|
var COMMAND_DEBUG_LEVELS = /* @__PURE__ */ new Set([
|
|
6539
6423
|
"pty_input",
|
|
6540
6424
|
"pty_resize",
|
|
@@ -6861,22 +6745,7 @@ var DaemonCommandHandler = class {
|
|
|
6861
6745
|
return handleFileList(this, args);
|
|
6862
6746
|
case "file_list_browse":
|
|
6863
6747
|
return handleFileListBrowse(this, args);
|
|
6864
|
-
// ─── VSCode API commands (not available) ────
|
|
6865
|
-
case "vscode_command_exec":
|
|
6866
|
-
case "execute_vscode_command": {
|
|
6867
|
-
const resolvedCmd = args?.commandId || args?.command;
|
|
6868
|
-
if (resolvedCmd === "adhdev.captureCdpScreenshot") {
|
|
6869
|
-
return handleScreenshot(this, args);
|
|
6870
|
-
}
|
|
6871
|
-
return { success: false, error: `VSCode command not available: ${resolvedCmd || cmd}` };
|
|
6872
|
-
}
|
|
6873
6748
|
// ─── Workspace cmds ──────────────
|
|
6874
|
-
case "get_recent_workspaces":
|
|
6875
|
-
return this.handleGetRecentWorkspaces(args);
|
|
6876
|
-
case "get_cli_history": {
|
|
6877
|
-
const config = loadConfig();
|
|
6878
|
-
return { success: true, history: config.cliHistory || [] };
|
|
6879
|
-
}
|
|
6880
6749
|
case "workspace_list":
|
|
6881
6750
|
return handleWorkspaceList();
|
|
6882
6751
|
case "workspace_add":
|
|
@@ -6884,7 +6753,6 @@ var DaemonCommandHandler = class {
|
|
|
6884
6753
|
case "workspace_remove":
|
|
6885
6754
|
return handleWorkspaceRemove(args);
|
|
6886
6755
|
case "workspace_set_default":
|
|
6887
|
-
case "workspace_set_active":
|
|
6888
6756
|
return handleWorkspaceSetDefault(args);
|
|
6889
6757
|
// ─── Script manage ───────────────────
|
|
6890
6758
|
case "refresh_scripts":
|
|
@@ -6930,19 +6798,6 @@ var DaemonCommandHandler = class {
|
|
|
6930
6798
|
}
|
|
6931
6799
|
}
|
|
6932
6800
|
// ─── Misc (kept in handler — too small to extract) ───────
|
|
6933
|
-
async handleGetRecentWorkspaces(_args) {
|
|
6934
|
-
const config = loadConfig();
|
|
6935
|
-
const cliRecent = config.recentCliWorkspaces || [];
|
|
6936
|
-
const ws = getWorkspaceState(config);
|
|
6937
|
-
return {
|
|
6938
|
-
success: true,
|
|
6939
|
-
result: cliRecent,
|
|
6940
|
-
workspaces: ws.workspaces,
|
|
6941
|
-
defaultWorkspaceId: ws.defaultWorkspaceId,
|
|
6942
|
-
defaultWorkspacePath: ws.defaultWorkspacePath,
|
|
6943
|
-
activity: getWorkspaceActivity(config, 25)
|
|
6944
|
-
};
|
|
6945
|
-
}
|
|
6946
6801
|
async handleRefreshScripts(_args) {
|
|
6947
6802
|
if (this._ctx.providerLoader) {
|
|
6948
6803
|
await this._ctx.providerLoader.fetchLatest().catch(() => {
|
|
@@ -6960,7 +6815,7 @@ var DaemonCommandHandler = class {
|
|
|
6960
6815
|
try {
|
|
6961
6816
|
const http3 = await import("http");
|
|
6962
6817
|
const postData = JSON.stringify(body);
|
|
6963
|
-
const result = await new Promise((
|
|
6818
|
+
const result = await new Promise((resolve9, reject) => {
|
|
6964
6819
|
const req = http3.request({
|
|
6965
6820
|
hostname: "127.0.0.1",
|
|
6966
6821
|
port: 19280,
|
|
@@ -6972,9 +6827,9 @@ var DaemonCommandHandler = class {
|
|
|
6972
6827
|
res.on("data", (chunk) => data += chunk);
|
|
6973
6828
|
res.on("end", () => {
|
|
6974
6829
|
try {
|
|
6975
|
-
|
|
6830
|
+
resolve9(JSON.parse(data));
|
|
6976
6831
|
} catch {
|
|
6977
|
-
|
|
6832
|
+
resolve9({ raw: data });
|
|
6978
6833
|
}
|
|
6979
6834
|
});
|
|
6980
6835
|
});
|
|
@@ -6992,15 +6847,15 @@ var DaemonCommandHandler = class {
|
|
|
6992
6847
|
if (!providerType) return { success: false, error: "providerType required" };
|
|
6993
6848
|
try {
|
|
6994
6849
|
const http3 = await import("http");
|
|
6995
|
-
const result = await new Promise((
|
|
6850
|
+
const result = await new Promise((resolve9, reject) => {
|
|
6996
6851
|
http3.get(`http://127.0.0.1:19280/api/providers/${providerType}/${endpoint}`, (res) => {
|
|
6997
6852
|
let data = "";
|
|
6998
6853
|
res.on("data", (chunk) => data += chunk);
|
|
6999
6854
|
res.on("end", () => {
|
|
7000
6855
|
try {
|
|
7001
|
-
|
|
6856
|
+
resolve9(JSON.parse(data));
|
|
7002
6857
|
} catch {
|
|
7003
|
-
|
|
6858
|
+
resolve9({ raw: data });
|
|
7004
6859
|
}
|
|
7005
6860
|
});
|
|
7006
6861
|
}).on("error", reject);
|
|
@@ -7014,7 +6869,7 @@ var DaemonCommandHandler = class {
|
|
|
7014
6869
|
try {
|
|
7015
6870
|
const http3 = await import("http");
|
|
7016
6871
|
const postData = JSON.stringify(args || {});
|
|
7017
|
-
const result = await new Promise((
|
|
6872
|
+
const result = await new Promise((resolve9, reject) => {
|
|
7018
6873
|
const req = http3.request({
|
|
7019
6874
|
hostname: "127.0.0.1",
|
|
7020
6875
|
port: 19280,
|
|
@@ -7026,9 +6881,9 @@ var DaemonCommandHandler = class {
|
|
|
7026
6881
|
res.on("data", (chunk) => data += chunk);
|
|
7027
6882
|
res.on("end", () => {
|
|
7028
6883
|
try {
|
|
7029
|
-
|
|
6884
|
+
resolve9(JSON.parse(data));
|
|
7030
6885
|
} catch {
|
|
7031
|
-
|
|
6886
|
+
resolve9({ raw: data });
|
|
7032
6887
|
}
|
|
7033
6888
|
});
|
|
7034
6889
|
});
|
|
@@ -7047,11 +6902,11 @@ var DaemonCommandHandler = class {
|
|
|
7047
6902
|
import { execSync as execSync3, spawn } from "child_process";
|
|
7048
6903
|
import * as net from "net";
|
|
7049
6904
|
import * as os8 from "os";
|
|
7050
|
-
import * as
|
|
6905
|
+
import * as path7 from "path";
|
|
7051
6906
|
|
|
7052
6907
|
// src/providers/provider-loader.ts
|
|
7053
6908
|
import * as fs5 from "fs";
|
|
7054
|
-
import * as
|
|
6909
|
+
import * as path6 from "path";
|
|
7055
6910
|
import * as os7 from "os";
|
|
7056
6911
|
import * as chokidar from "chokidar";
|
|
7057
6912
|
init_logger();
|
|
@@ -7072,12 +6927,12 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
7072
6927
|
static META_FILE = ".meta.json";
|
|
7073
6928
|
constructor(options) {
|
|
7074
6929
|
this.logFn = options?.logFn || LOG.forComponent("Provider").asLogFn();
|
|
7075
|
-
const defaultProvidersDir =
|
|
6930
|
+
const defaultProvidersDir = path6.join(os7.homedir(), ".adhdev", "providers");
|
|
7076
6931
|
if (options?.userDir) {
|
|
7077
6932
|
this.userDir = options.userDir;
|
|
7078
6933
|
this.log(`Config 'providerDir' applied: ${this.userDir}`);
|
|
7079
6934
|
} else {
|
|
7080
|
-
const localRepoPath =
|
|
6935
|
+
const localRepoPath = path6.resolve(__dirname, "../../../../../adhdev-providers");
|
|
7081
6936
|
if (fs5.existsSync(localRepoPath)) {
|
|
7082
6937
|
this.userDir = localRepoPath;
|
|
7083
6938
|
this.log(`Auto-detected local public repository: ${this.userDir} (Dev workspace speedup)`);
|
|
@@ -7086,7 +6941,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
7086
6941
|
this.log(`Using default user providers directory: ${this.userDir}`);
|
|
7087
6942
|
}
|
|
7088
6943
|
}
|
|
7089
|
-
this.upstreamDir =
|
|
6944
|
+
this.upstreamDir = path6.join(defaultProvidersDir, ".upstream");
|
|
7090
6945
|
this.disableUpstream = options?.disableUpstream ?? false;
|
|
7091
6946
|
}
|
|
7092
6947
|
log(msg) {
|
|
@@ -7116,7 +6971,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
7116
6971
|
* Canonical provider directory shape for a given root.
|
|
7117
6972
|
*/
|
|
7118
6973
|
getProviderDir(root, category, type) {
|
|
7119
|
-
return
|
|
6974
|
+
return path6.join(root, category, type);
|
|
7120
6975
|
}
|
|
7121
6976
|
/**
|
|
7122
6977
|
* Canonical user override directory for a provider.
|
|
@@ -7143,7 +6998,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
7143
6998
|
resolveProviderFile(type, ...segments) {
|
|
7144
6999
|
const dir = this.findProviderDirInternal(type);
|
|
7145
7000
|
if (!dir) return null;
|
|
7146
|
-
return
|
|
7001
|
+
return path6.join(dir, ...segments);
|
|
7147
7002
|
}
|
|
7148
7003
|
/**
|
|
7149
7004
|
* Load all providers (3-tier priority)
|
|
@@ -7181,7 +7036,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
7181
7036
|
if (!fs5.existsSync(this.upstreamDir)) return false;
|
|
7182
7037
|
try {
|
|
7183
7038
|
return fs5.readdirSync(this.upstreamDir).some(
|
|
7184
|
-
(d) => fs5.statSync(
|
|
7039
|
+
(d) => fs5.statSync(path6.join(this.upstreamDir, d)).isDirectory()
|
|
7185
7040
|
);
|
|
7186
7041
|
} catch {
|
|
7187
7042
|
return false;
|
|
@@ -7266,16 +7121,23 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
7266
7121
|
isEnabled(type, ideType) {
|
|
7267
7122
|
if (!ideType) return true;
|
|
7268
7123
|
try {
|
|
7269
|
-
|
|
7270
|
-
const config = loadConfig2();
|
|
7271
|
-
const baseIdeType = ideType.split("_")[0];
|
|
7272
|
-
const val = config.ideSettings?.[baseIdeType]?.extensions?.[type]?.enabled;
|
|
7273
|
-
return val === true;
|
|
7124
|
+
return this.getIdeExtensionEnabledState(ideType, type);
|
|
7274
7125
|
} catch {
|
|
7275
7126
|
return false;
|
|
7276
7127
|
}
|
|
7277
7128
|
}
|
|
7278
7129
|
/**
|
|
7130
|
+
* Resolve per-IDE extension enabled state using the same normalization
|
|
7131
|
+
* that runtime attach/remove uses.
|
|
7132
|
+
*/
|
|
7133
|
+
getIdeExtensionEnabledState(ideType, extensionType) {
|
|
7134
|
+
const { loadConfig: loadConfig2 } = (init_config(), __toCommonJS(config_exports));
|
|
7135
|
+
const config = loadConfig2();
|
|
7136
|
+
const baseIdeType = ideType.split("_")[0];
|
|
7137
|
+
const val = config.ideSettings?.[baseIdeType]?.extensions?.[extensionType]?.enabled;
|
|
7138
|
+
return val === true;
|
|
7139
|
+
}
|
|
7140
|
+
/**
|
|
7279
7141
|
* Save IDE extension enabled setting
|
|
7280
7142
|
*/
|
|
7281
7143
|
setIdeExtensionEnabled(ideType, extensionType, enabled) {
|
|
@@ -7473,14 +7335,14 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
7473
7335
|
this.log(` [loadScriptsFromDir] ${type}: providerDir not found`);
|
|
7474
7336
|
return null;
|
|
7475
7337
|
}
|
|
7476
|
-
const dir =
|
|
7338
|
+
const dir = path6.join(providerDir, scriptDir);
|
|
7477
7339
|
if (!fs5.existsSync(dir)) {
|
|
7478
7340
|
this.log(` [loadScriptsFromDir] ${type}: dir not found: ${dir}`);
|
|
7479
7341
|
return null;
|
|
7480
7342
|
}
|
|
7481
7343
|
const cached = this.scriptsCache.get(dir);
|
|
7482
7344
|
if (cached) return cached;
|
|
7483
|
-
const scriptsJs =
|
|
7345
|
+
const scriptsJs = path6.join(dir, "scripts.js");
|
|
7484
7346
|
if (fs5.existsSync(scriptsJs)) {
|
|
7485
7347
|
try {
|
|
7486
7348
|
delete __require.cache[__require.resolve(scriptsJs)];
|
|
@@ -7519,7 +7381,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
7519
7381
|
});
|
|
7520
7382
|
const handleChange = (filePath) => {
|
|
7521
7383
|
if (filePath.endsWith(".js") || filePath.endsWith(".json")) {
|
|
7522
|
-
this.log(`File changed: ${
|
|
7384
|
+
this.log(`File changed: ${path6.basename(filePath)}, reloading...`);
|
|
7523
7385
|
this.reload();
|
|
7524
7386
|
}
|
|
7525
7387
|
};
|
|
@@ -7574,7 +7436,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
7574
7436
|
}
|
|
7575
7437
|
const https = __require("https");
|
|
7576
7438
|
const { execSync: execSync7 } = __require("child_process");
|
|
7577
|
-
const metaPath =
|
|
7439
|
+
const metaPath = path6.join(this.upstreamDir, _ProviderLoader.META_FILE);
|
|
7578
7440
|
let prevEtag = "";
|
|
7579
7441
|
let prevTimestamp = 0;
|
|
7580
7442
|
try {
|
|
@@ -7591,7 +7453,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
7591
7453
|
return { updated: false };
|
|
7592
7454
|
}
|
|
7593
7455
|
try {
|
|
7594
|
-
const etag = await new Promise((
|
|
7456
|
+
const etag = await new Promise((resolve9, reject) => {
|
|
7595
7457
|
const options = {
|
|
7596
7458
|
method: "HEAD",
|
|
7597
7459
|
hostname: "github.com",
|
|
@@ -7609,7 +7471,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
7609
7471
|
headers: { "User-Agent": "adhdev-launcher" },
|
|
7610
7472
|
timeout: 1e4
|
|
7611
7473
|
}, (res2) => {
|
|
7612
|
-
|
|
7474
|
+
resolve9(res2.headers.etag || res2.headers["last-modified"] || "");
|
|
7613
7475
|
});
|
|
7614
7476
|
req2.on("error", reject);
|
|
7615
7477
|
req2.on("timeout", () => {
|
|
@@ -7618,7 +7480,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
7618
7480
|
});
|
|
7619
7481
|
req2.end();
|
|
7620
7482
|
} else {
|
|
7621
|
-
|
|
7483
|
+
resolve9(res.headers.etag || res.headers["last-modified"] || "");
|
|
7622
7484
|
}
|
|
7623
7485
|
});
|
|
7624
7486
|
req.on("error", reject);
|
|
@@ -7634,17 +7496,17 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
7634
7496
|
return { updated: false };
|
|
7635
7497
|
}
|
|
7636
7498
|
this.log("Downloading latest providers from GitHub...");
|
|
7637
|
-
const tmpTar =
|
|
7638
|
-
const tmpExtract =
|
|
7499
|
+
const tmpTar = path6.join(os7.tmpdir(), `adhdev-providers-${Date.now()}.tar.gz`);
|
|
7500
|
+
const tmpExtract = path6.join(os7.tmpdir(), `adhdev-providers-extract-${Date.now()}`);
|
|
7639
7501
|
await this.downloadFile(_ProviderLoader.GITHUB_TARBALL_URL, tmpTar);
|
|
7640
7502
|
fs5.mkdirSync(tmpExtract, { recursive: true });
|
|
7641
7503
|
execSync7(`tar -xzf "${tmpTar}" -C "${tmpExtract}"`, { timeout: 3e4 });
|
|
7642
7504
|
const extracted = fs5.readdirSync(tmpExtract);
|
|
7643
7505
|
const rootDir = extracted.find(
|
|
7644
|
-
(d) => fs5.statSync(
|
|
7506
|
+
(d) => fs5.statSync(path6.join(tmpExtract, d)).isDirectory() && d.startsWith("adhdev-providers")
|
|
7645
7507
|
);
|
|
7646
7508
|
if (!rootDir) throw new Error("Unexpected tarball structure");
|
|
7647
|
-
const sourceDir =
|
|
7509
|
+
const sourceDir = path6.join(tmpExtract, rootDir);
|
|
7648
7510
|
const backupDir = this.upstreamDir + ".bak";
|
|
7649
7511
|
if (fs5.existsSync(this.upstreamDir)) {
|
|
7650
7512
|
if (fs5.existsSync(backupDir)) fs5.rmSync(backupDir, { recursive: true, force: true });
|
|
@@ -7682,7 +7544,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
7682
7544
|
downloadFile(url, destPath) {
|
|
7683
7545
|
const https = __require("https");
|
|
7684
7546
|
const http3 = __require("http");
|
|
7685
|
-
return new Promise((
|
|
7547
|
+
return new Promise((resolve9, reject) => {
|
|
7686
7548
|
const doRequest = (reqUrl, redirectCount = 0) => {
|
|
7687
7549
|
if (redirectCount > 5) {
|
|
7688
7550
|
reject(new Error("Too many redirects"));
|
|
@@ -7702,7 +7564,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
7702
7564
|
res.pipe(ws);
|
|
7703
7565
|
ws.on("finish", () => {
|
|
7704
7566
|
ws.close();
|
|
7705
|
-
|
|
7567
|
+
resolve9();
|
|
7706
7568
|
});
|
|
7707
7569
|
ws.on("error", reject);
|
|
7708
7570
|
});
|
|
@@ -7719,8 +7581,8 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
7719
7581
|
copyDirRecursive(src, dest) {
|
|
7720
7582
|
fs5.mkdirSync(dest, { recursive: true });
|
|
7721
7583
|
for (const entry of fs5.readdirSync(src, { withFileTypes: true })) {
|
|
7722
|
-
const srcPath =
|
|
7723
|
-
const destPath =
|
|
7584
|
+
const srcPath = path6.join(src, entry.name);
|
|
7585
|
+
const destPath = path6.join(dest, entry.name);
|
|
7724
7586
|
if (entry.isDirectory()) {
|
|
7725
7587
|
this.copyDirRecursive(srcPath, destPath);
|
|
7726
7588
|
} else {
|
|
@@ -7731,7 +7593,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
7731
7593
|
/** .meta.json save */
|
|
7732
7594
|
writeMeta(metaPath, etag, timestamp) {
|
|
7733
7595
|
try {
|
|
7734
|
-
fs5.mkdirSync(
|
|
7596
|
+
fs5.mkdirSync(path6.dirname(metaPath), { recursive: true });
|
|
7735
7597
|
fs5.writeFileSync(metaPath, JSON.stringify({
|
|
7736
7598
|
etag,
|
|
7737
7599
|
timestamp,
|
|
@@ -7748,7 +7610,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
7748
7610
|
const scan = (d) => {
|
|
7749
7611
|
try {
|
|
7750
7612
|
for (const entry of fs5.readdirSync(d, { withFileTypes: true })) {
|
|
7751
|
-
if (entry.isDirectory()) scan(
|
|
7613
|
+
if (entry.isDirectory()) scan(path6.join(d, entry.name));
|
|
7752
7614
|
else if (entry.name === "provider.json") count++;
|
|
7753
7615
|
}
|
|
7754
7616
|
} catch {
|
|
@@ -7847,17 +7709,17 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
7847
7709
|
for (const root of searchRoots) {
|
|
7848
7710
|
if (!fs5.existsSync(root)) continue;
|
|
7849
7711
|
const candidate = this.getProviderDir(root, cat, type);
|
|
7850
|
-
if (fs5.existsSync(
|
|
7851
|
-
const catDir =
|
|
7712
|
+
if (fs5.existsSync(path6.join(candidate, "provider.json"))) return candidate;
|
|
7713
|
+
const catDir = path6.join(root, cat);
|
|
7852
7714
|
if (fs5.existsSync(catDir)) {
|
|
7853
7715
|
try {
|
|
7854
7716
|
for (const entry of fs5.readdirSync(catDir, { withFileTypes: true })) {
|
|
7855
7717
|
if (!entry.isDirectory()) continue;
|
|
7856
|
-
const jsonPath =
|
|
7718
|
+
const jsonPath = path6.join(catDir, entry.name, "provider.json");
|
|
7857
7719
|
if (fs5.existsSync(jsonPath)) {
|
|
7858
7720
|
try {
|
|
7859
7721
|
const data = JSON.parse(fs5.readFileSync(jsonPath, "utf-8"));
|
|
7860
|
-
if (data.type === type) return
|
|
7722
|
+
if (data.type === type) return path6.join(catDir, entry.name);
|
|
7861
7723
|
} catch {
|
|
7862
7724
|
}
|
|
7863
7725
|
}
|
|
@@ -7874,7 +7736,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
7874
7736
|
* (template substitution is NOT applied here — scripts.js handles that)
|
|
7875
7737
|
*/
|
|
7876
7738
|
buildScriptWrappersFromDir(dir) {
|
|
7877
|
-
const scriptsJs =
|
|
7739
|
+
const scriptsJs = path6.join(dir, "scripts.js");
|
|
7878
7740
|
if (fs5.existsSync(scriptsJs)) {
|
|
7879
7741
|
try {
|
|
7880
7742
|
delete __require.cache[__require.resolve(scriptsJs)];
|
|
@@ -7888,7 +7750,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
7888
7750
|
for (const file of fs5.readdirSync(dir)) {
|
|
7889
7751
|
if (!file.endsWith(".js")) continue;
|
|
7890
7752
|
const scriptName = toCamel(file.replace(".js", ""));
|
|
7891
|
-
const filePath =
|
|
7753
|
+
const filePath = path6.join(dir, file);
|
|
7892
7754
|
result[scriptName] = (...args) => {
|
|
7893
7755
|
try {
|
|
7894
7756
|
let content = fs5.readFileSync(filePath, "utf-8");
|
|
@@ -7948,7 +7810,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
7948
7810
|
}
|
|
7949
7811
|
const hasJson = entries.some((e) => e.name === "provider.json");
|
|
7950
7812
|
if (hasJson) {
|
|
7951
|
-
const jsonPath =
|
|
7813
|
+
const jsonPath = path6.join(d, "provider.json");
|
|
7952
7814
|
try {
|
|
7953
7815
|
const raw = fs5.readFileSync(jsonPath, "utf-8");
|
|
7954
7816
|
const mod = JSON.parse(raw);
|
|
@@ -7961,7 +7823,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
7961
7823
|
delete mod.extensionIdPattern_flags;
|
|
7962
7824
|
}
|
|
7963
7825
|
const hasCompatibility = Array.isArray(mod.compatibility);
|
|
7964
|
-
const scriptsPath =
|
|
7826
|
+
const scriptsPath = path6.join(d, "scripts.js");
|
|
7965
7827
|
if (!hasCompatibility && fs5.existsSync(scriptsPath)) {
|
|
7966
7828
|
try {
|
|
7967
7829
|
delete __require.cache[__require.resolve(scriptsPath)];
|
|
@@ -7987,7 +7849,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
7987
7849
|
if (!entry.isDirectory()) continue;
|
|
7988
7850
|
if (entry.name.startsWith("_") || entry.name.startsWith(".")) continue;
|
|
7989
7851
|
if (excludeDirs && d === dir && excludeDirs.includes(entry.name)) continue;
|
|
7990
|
-
scan(
|
|
7852
|
+
scan(path6.join(d, entry.name));
|
|
7991
7853
|
}
|
|
7992
7854
|
}
|
|
7993
7855
|
};
|
|
@@ -8067,17 +7929,17 @@ async function findFreePort(ports) {
|
|
|
8067
7929
|
throw new Error("No free port found");
|
|
8068
7930
|
}
|
|
8069
7931
|
function checkPortFree(port) {
|
|
8070
|
-
return new Promise((
|
|
7932
|
+
return new Promise((resolve9) => {
|
|
8071
7933
|
const server = net.createServer();
|
|
8072
7934
|
server.unref();
|
|
8073
|
-
server.on("error", () =>
|
|
7935
|
+
server.on("error", () => resolve9(false));
|
|
8074
7936
|
server.listen(port, "127.0.0.1", () => {
|
|
8075
|
-
server.close(() =>
|
|
7937
|
+
server.close(() => resolve9(true));
|
|
8076
7938
|
});
|
|
8077
7939
|
});
|
|
8078
7940
|
}
|
|
8079
7941
|
async function isCdpActive(port) {
|
|
8080
|
-
return new Promise((
|
|
7942
|
+
return new Promise((resolve9) => {
|
|
8081
7943
|
const req = __require("http").get(`http://127.0.0.1:${port}/json/version`, {
|
|
8082
7944
|
timeout: 2e3
|
|
8083
7945
|
}, (res) => {
|
|
@@ -8086,16 +7948,16 @@ async function isCdpActive(port) {
|
|
|
8086
7948
|
res.on("end", () => {
|
|
8087
7949
|
try {
|
|
8088
7950
|
const info = JSON.parse(data);
|
|
8089
|
-
|
|
7951
|
+
resolve9(!!info["WebKit-Version"] || !!info["Browser"]);
|
|
8090
7952
|
} catch {
|
|
8091
|
-
|
|
7953
|
+
resolve9(false);
|
|
8092
7954
|
}
|
|
8093
7955
|
});
|
|
8094
7956
|
});
|
|
8095
|
-
req.on("error", () =>
|
|
7957
|
+
req.on("error", () => resolve9(false));
|
|
8096
7958
|
req.on("timeout", () => {
|
|
8097
7959
|
req.destroy();
|
|
8098
|
-
|
|
7960
|
+
resolve9(false);
|
|
8099
7961
|
});
|
|
8100
7962
|
});
|
|
8101
7963
|
}
|
|
@@ -8214,8 +8076,8 @@ function detectCurrentWorkspace(ideId) {
|
|
|
8214
8076
|
const appNameMap = getMacAppIdentifiers();
|
|
8215
8077
|
const appName = appNameMap[ideId];
|
|
8216
8078
|
if (appName) {
|
|
8217
|
-
const storagePath =
|
|
8218
|
-
process.env.APPDATA ||
|
|
8079
|
+
const storagePath = path7.join(
|
|
8080
|
+
process.env.APPDATA || path7.join(os8.homedir(), "AppData", "Roaming"),
|
|
8219
8081
|
appName,
|
|
8220
8082
|
"storage.json"
|
|
8221
8083
|
);
|
|
@@ -8384,15 +8246,13 @@ function getAvailableIdeIds() {
|
|
|
8384
8246
|
|
|
8385
8247
|
// src/commands/router.ts
|
|
8386
8248
|
init_config();
|
|
8387
|
-
init_workspaces();
|
|
8388
|
-
init_config();
|
|
8389
8249
|
init_logger();
|
|
8390
8250
|
|
|
8391
8251
|
// src/logging/command-log.ts
|
|
8392
8252
|
import * as fs6 from "fs";
|
|
8393
|
-
import * as
|
|
8253
|
+
import * as path8 from "path";
|
|
8394
8254
|
import * as os9 from "os";
|
|
8395
|
-
var LOG_DIR2 = process.platform === "win32" ?
|
|
8255
|
+
var LOG_DIR2 = process.platform === "win32" ? path8.join(process.env.LOCALAPPDATA || process.env.APPDATA || path8.join(os9.homedir(), "AppData", "Local"), "adhdev", "logs") : process.platform === "darwin" ? path8.join(os9.homedir(), "Library", "Logs", "adhdev") : path8.join(os9.homedir(), ".local", "share", "adhdev", "logs");
|
|
8396
8256
|
var MAX_FILE_SIZE = 5 * 1024 * 1024;
|
|
8397
8257
|
var MAX_DAYS = 7;
|
|
8398
8258
|
try {
|
|
@@ -8430,13 +8290,13 @@ function getDateStr2() {
|
|
|
8430
8290
|
return (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
8431
8291
|
}
|
|
8432
8292
|
var currentDate2 = getDateStr2();
|
|
8433
|
-
var currentFile =
|
|
8293
|
+
var currentFile = path8.join(LOG_DIR2, `commands-${currentDate2}.jsonl`);
|
|
8434
8294
|
var writeCount2 = 0;
|
|
8435
8295
|
function checkRotation() {
|
|
8436
8296
|
const today = getDateStr2();
|
|
8437
8297
|
if (today !== currentDate2) {
|
|
8438
8298
|
currentDate2 = today;
|
|
8439
|
-
currentFile =
|
|
8299
|
+
currentFile = path8.join(LOG_DIR2, `commands-${currentDate2}.jsonl`);
|
|
8440
8300
|
cleanOldFiles();
|
|
8441
8301
|
}
|
|
8442
8302
|
}
|
|
@@ -8450,7 +8310,7 @@ function cleanOldFiles() {
|
|
|
8450
8310
|
const dateMatch = file.match(/commands-(\d{4}-\d{2}-\d{2})/);
|
|
8451
8311
|
if (dateMatch && dateMatch[1] < cutoffStr) {
|
|
8452
8312
|
try {
|
|
8453
|
-
fs6.unlinkSync(
|
|
8313
|
+
fs6.unlinkSync(path8.join(LOG_DIR2, file));
|
|
8454
8314
|
} catch {
|
|
8455
8315
|
}
|
|
8456
8316
|
}
|
|
@@ -8651,18 +8511,6 @@ var DaemonCommandRouter = class {
|
|
|
8651
8511
|
};
|
|
8652
8512
|
LOG.info("LaunchIDE", `target=${ideKey || "auto"}`);
|
|
8653
8513
|
const result = await launchWithCdp(launchArgs);
|
|
8654
|
-
if (result.success && (result.ideId || ideKey)) {
|
|
8655
|
-
try {
|
|
8656
|
-
addCliHistory({
|
|
8657
|
-
category: "ide",
|
|
8658
|
-
cliType: result.ideId || ideKey,
|
|
8659
|
-
dir: resolvedWorkspace || "",
|
|
8660
|
-
workspace: resolvedWorkspace || "",
|
|
8661
|
-
newWindow: args?.newWindow === true
|
|
8662
|
-
});
|
|
8663
|
-
} catch {
|
|
8664
|
-
}
|
|
8665
|
-
}
|
|
8666
8514
|
if (result.success && result.port && result.ideId && !this.deps.cdpManagers.has(result.ideId)) {
|
|
8667
8515
|
const logFn = this.deps.getCdpLogFn ? this.deps.getCdpLogFn(result.ideId) : LOG.forComponent(`CDP:${result.ideId}`).asLogFn();
|
|
8668
8516
|
const provider = this.deps.providerLoader.getMeta(result.ideId);
|
|
@@ -8679,11 +8527,7 @@ var DaemonCommandRouter = class {
|
|
|
8679
8527
|
this.deps.onIdeConnected?.();
|
|
8680
8528
|
if (result.success && resolvedWorkspace) {
|
|
8681
8529
|
try {
|
|
8682
|
-
|
|
8683
|
-
kind: "ide",
|
|
8684
|
-
agentType: result.ideId
|
|
8685
|
-
});
|
|
8686
|
-
next = appendRecentActivity(next, {
|
|
8530
|
+
const next = appendRecentActivity(loadConfig(), {
|
|
8687
8531
|
kind: "ide",
|
|
8688
8532
|
providerType: result.ideId || ideKey,
|
|
8689
8533
|
providerName: result.ideId || ideKey,
|
|
@@ -8761,9 +8605,9 @@ var DaemonCommandRouter = class {
|
|
|
8761
8605
|
setTimeout(() => {
|
|
8762
8606
|
LOG.info("Upgrade", "Restarting daemon with new version...");
|
|
8763
8607
|
try {
|
|
8764
|
-
const
|
|
8608
|
+
const path15 = __require("path");
|
|
8765
8609
|
const fs12 = __require("fs");
|
|
8766
|
-
const pidFile =
|
|
8610
|
+
const pidFile = path15.join(process.env.HOME || process.env.USERPROFILE || "", ".adhdev", "daemon.pid");
|
|
8767
8611
|
if (fs12.existsSync(pidFile)) fs12.unlinkSync(pidFile);
|
|
8768
8612
|
} catch {
|
|
8769
8613
|
}
|
|
@@ -8861,7 +8705,6 @@ init_logger();
|
|
|
8861
8705
|
// src/status/snapshot.ts
|
|
8862
8706
|
init_config();
|
|
8863
8707
|
import * as os10 from "os";
|
|
8864
|
-
init_workspaces();
|
|
8865
8708
|
init_terminal_screen();
|
|
8866
8709
|
function buildDetectedIdeInfos(detectedIdes, cdpManagers) {
|
|
8867
8710
|
return detectedIdes.filter((ide) => ide.installed !== false).map((ide) => ({
|
|
@@ -8915,7 +8758,9 @@ function getUnreadState(hasContentChange, status, lastUsedAt, lastSeenAt, lastRo
|
|
|
8915
8758
|
return { unread, inboxBucket: unread ? "task_complete" : "idle" };
|
|
8916
8759
|
}
|
|
8917
8760
|
function buildRecentSessions(sessions, recentActivity, readState) {
|
|
8918
|
-
const
|
|
8761
|
+
const visibleKeys = /* @__PURE__ */ new Set();
|
|
8762
|
+
const hiddenKeys = /* @__PURE__ */ new Set();
|
|
8763
|
+
const live = sessions.filter((session) => !session.surfaceHidden && session.status !== "stopped").map((session) => {
|
|
8919
8764
|
const kind = getSessionKind(session);
|
|
8920
8765
|
const recentKey = buildRecentActivityKey({
|
|
8921
8766
|
kind,
|
|
@@ -8945,11 +8790,21 @@ function buildRecentSessions(sessions, recentActivity, readState) {
|
|
|
8945
8790
|
lastUsedAt,
|
|
8946
8791
|
unread,
|
|
8947
8792
|
lastSeenAt,
|
|
8948
|
-
inboxBucket
|
|
8793
|
+
inboxBucket,
|
|
8794
|
+
surfaceHidden: false
|
|
8949
8795
|
};
|
|
8950
8796
|
});
|
|
8951
|
-
const
|
|
8952
|
-
|
|
8797
|
+
for (const item of live) {
|
|
8798
|
+
visibleKeys.add(`${item.kind}:${item.providerType}:${item.workspace || ""}`);
|
|
8799
|
+
}
|
|
8800
|
+
for (const session of sessions) {
|
|
8801
|
+
if (!session.surfaceHidden) continue;
|
|
8802
|
+
hiddenKeys.add(`${getSessionKind(session)}:${session.providerType}:${session.workspace || ""}`);
|
|
8803
|
+
}
|
|
8804
|
+
const persisted = recentActivity.filter((item) => {
|
|
8805
|
+
const key = `${item.kind}:${item.providerType}:${item.workspace || ""}`;
|
|
8806
|
+
return !visibleKeys.has(key) && !hiddenKeys.has(key);
|
|
8807
|
+
}).map((item) => {
|
|
8953
8808
|
const lastSeenAt = readState[item.id] || 0;
|
|
8954
8809
|
const unread = item.lastUsedAt > lastSeenAt;
|
|
8955
8810
|
return {
|
|
@@ -8965,7 +8820,8 @@ function buildRecentSessions(sessions, recentActivity, readState) {
|
|
|
8965
8820
|
lastUsedAt: item.lastUsedAt,
|
|
8966
8821
|
unread,
|
|
8967
8822
|
lastSeenAt,
|
|
8968
|
-
inboxBucket: unread ? "task_complete" : "idle"
|
|
8823
|
+
inboxBucket: unread ? "task_complete" : "idle",
|
|
8824
|
+
surfaceHidden: false
|
|
8969
8825
|
};
|
|
8970
8826
|
});
|
|
8971
8827
|
return [...live, ...persisted].sort((a, b) => b.lastUsedAt - a.lastUsedAt).slice(0, 12);
|
|
@@ -8989,7 +8845,7 @@ function buildStatusSnapshot(options) {
|
|
|
8989
8845
|
});
|
|
8990
8846
|
const lastSeenAt = getRecentSessionSeenAt(cfg, recentKey);
|
|
8991
8847
|
const lastUsedAt = getSessionLastUsedAt(session);
|
|
8992
|
-
const { unread, inboxBucket } = getUnreadState(
|
|
8848
|
+
const { unread, inboxBucket } = session.surfaceHidden ? { unread: false, inboxBucket: "idle" } : getUnreadState(
|
|
8993
8849
|
getSessionMessageUpdatedAt(session) > 0,
|
|
8994
8850
|
session.status,
|
|
8995
8851
|
lastUsedAt,
|
|
@@ -9026,7 +8882,6 @@ function buildStatusSnapshot(options) {
|
|
|
9026
8882
|
workspaces: wsState.workspaces,
|
|
9027
8883
|
defaultWorkspaceId: wsState.defaultWorkspaceId,
|
|
9028
8884
|
defaultWorkspacePath: wsState.defaultWorkspacePath,
|
|
9029
|
-
workspaceActivity: getWorkspaceActivity(cfg, 15),
|
|
9030
8885
|
recentSessions: buildRecentSessions(sessions, recentActivity, readState),
|
|
9031
8886
|
terminalBackend,
|
|
9032
8887
|
availableProviders: buildAvailableProviders(options.providerLoader)
|
|
@@ -9185,6 +9040,7 @@ var DaemonStatusReporter = class {
|
|
|
9185
9040
|
unread: session.unread,
|
|
9186
9041
|
lastSeenAt: session.lastSeenAt,
|
|
9187
9042
|
inboxBucket: session.inboxBucket,
|
|
9043
|
+
surfaceHidden: session.surfaceHidden,
|
|
9188
9044
|
controlValues: session.controlValues,
|
|
9189
9045
|
providerControls: session.providerControls,
|
|
9190
9046
|
acpConfigOptions: session.acpConfigOptions,
|
|
@@ -9227,11 +9083,10 @@ init_logger();
|
|
|
9227
9083
|
// src/commands/cli-manager.ts
|
|
9228
9084
|
init_provider_cli_adapter();
|
|
9229
9085
|
import * as os13 from "os";
|
|
9230
|
-
import * as
|
|
9086
|
+
import * as path10 from "path";
|
|
9231
9087
|
import * as crypto4 from "crypto";
|
|
9232
9088
|
import chalk from "chalk";
|
|
9233
9089
|
init_config();
|
|
9234
|
-
init_workspaces();
|
|
9235
9090
|
|
|
9236
9091
|
// src/providers/cli-provider-instance.ts
|
|
9237
9092
|
init_provider_cli_adapter();
|
|
@@ -9912,13 +9767,13 @@ var AcpProviderInstance = class {
|
|
|
9912
9767
|
}
|
|
9913
9768
|
this.currentStatus = "waiting_approval";
|
|
9914
9769
|
this.detectStatusTransition();
|
|
9915
|
-
const approved = await new Promise((
|
|
9916
|
-
this.permissionResolvers.push(
|
|
9770
|
+
const approved = await new Promise((resolve9) => {
|
|
9771
|
+
this.permissionResolvers.push(resolve9);
|
|
9917
9772
|
setTimeout(() => {
|
|
9918
|
-
const idx = this.permissionResolvers.indexOf(
|
|
9773
|
+
const idx = this.permissionResolvers.indexOf(resolve9);
|
|
9919
9774
|
if (idx >= 0) {
|
|
9920
9775
|
this.permissionResolvers.splice(idx, 1);
|
|
9921
|
-
|
|
9776
|
+
resolve9(false);
|
|
9922
9777
|
}
|
|
9923
9778
|
}, 3e5);
|
|
9924
9779
|
});
|
|
@@ -10393,24 +10248,6 @@ var DaemonCliManager = class {
|
|
|
10393
10248
|
const hash = __require("crypto").createHash("md5").update(__require("path").resolve(dir)).digest("hex").slice(0, 8);
|
|
10394
10249
|
return `${cliType}_${hash}`;
|
|
10395
10250
|
}
|
|
10396
|
-
persistRecentDir(cliType, dir) {
|
|
10397
|
-
try {
|
|
10398
|
-
const normalizedType = this.providerLoader.resolveAlias(cliType);
|
|
10399
|
-
const provider = this.providerLoader.getByAlias(cliType);
|
|
10400
|
-
const actKind = provider?.category === "acp" ? "acp" : "cli";
|
|
10401
|
-
let next = loadConfig();
|
|
10402
|
-
console.log(colorize("cyan", ` \u{1F4C2} Saving recent workspace: ${dir}`));
|
|
10403
|
-
const recent = next.recentCliWorkspaces || [];
|
|
10404
|
-
if (!recent.includes(dir)) {
|
|
10405
|
-
next = { ...next, recentCliWorkspaces: [dir, ...recent].slice(0, 10) };
|
|
10406
|
-
}
|
|
10407
|
-
next = appendWorkspaceActivity(next, dir, { kind: actKind, agentType: normalizedType });
|
|
10408
|
-
saveConfig(next);
|
|
10409
|
-
console.log(colorize("green", ` \u2713 Recent workspace saved: ${dir}`));
|
|
10410
|
-
} catch (e) {
|
|
10411
|
-
console.error(colorize("red", ` \u2717 Failed to save recent workspace: ${e}`));
|
|
10412
|
-
}
|
|
10413
|
-
}
|
|
10414
10251
|
persistRecentActivity(entry) {
|
|
10415
10252
|
try {
|
|
10416
10253
|
saveConfig(appendRecentActivity(loadConfig(), entry));
|
|
@@ -10500,7 +10337,7 @@ var DaemonCliManager = class {
|
|
|
10500
10337
|
async startSession(cliType, workingDir, cliArgs, initialModel) {
|
|
10501
10338
|
const trimmed = (workingDir || "").trim();
|
|
10502
10339
|
if (!trimmed) throw new Error("working directory required");
|
|
10503
|
-
const resolvedDir = trimmed.startsWith("~") ? trimmed.replace(/^~/, os13.homedir()) :
|
|
10340
|
+
const resolvedDir = trimmed.startsWith("~") ? trimmed.replace(/^~/, os13.homedir()) : path10.resolve(trimmed);
|
|
10504
10341
|
const normalizedType = this.providerLoader.resolveAlias(cliType);
|
|
10505
10342
|
const provider = this.providerLoader.getByAlias(cliType);
|
|
10506
10343
|
const key = crypto4.randomUUID();
|
|
@@ -10571,11 +10408,6 @@ ${installInfo}`
|
|
|
10571
10408
|
LOG.warn("CLI", `[ACP] Initial model set failed: ${e?.message}`);
|
|
10572
10409
|
}
|
|
10573
10410
|
}
|
|
10574
|
-
try {
|
|
10575
|
-
addCliHistory({ category: "acp", cliType: normalizedType, dir: resolvedDir, workspace: resolvedDir, cliArgs, model: initialModel });
|
|
10576
|
-
} catch (e) {
|
|
10577
|
-
LOG.warn("CLI", `ACP history save failed: ${e?.message}`);
|
|
10578
|
-
}
|
|
10579
10411
|
this.persistRecentActivity({
|
|
10580
10412
|
kind: "acp",
|
|
10581
10413
|
providerType: normalizedType,
|
|
@@ -10642,11 +10474,6 @@ ${installInfo}`
|
|
|
10642
10474
|
this.adapters.set(key, adapter);
|
|
10643
10475
|
console.log(colorize("green", ` \u2713 CLI started: ${cliInfo.displayName} v${cliInfo.version || "unknown"} in ${resolvedDir}`));
|
|
10644
10476
|
}
|
|
10645
|
-
try {
|
|
10646
|
-
addCliHistory({ category: "cli", cliType, dir: resolvedDir, workspace: resolvedDir, cliArgs, model: initialModel });
|
|
10647
|
-
} catch (e) {
|
|
10648
|
-
LOG.warn("CLI", `CLI history save failed: ${e?.message}`);
|
|
10649
|
-
}
|
|
10650
10477
|
this.persistRecentActivity({
|
|
10651
10478
|
kind: "cli",
|
|
10652
10479
|
providerType: normalizedType,
|
|
@@ -10799,7 +10626,6 @@ ${installInfo}`
|
|
|
10799
10626
|
newKey = k;
|
|
10800
10627
|
}
|
|
10801
10628
|
}
|
|
10802
|
-
this.persistRecentDir(cliType, dir);
|
|
10803
10629
|
return { success: true, cliType, dir, id: newKey, launchSource };
|
|
10804
10630
|
}
|
|
10805
10631
|
case "stop_cli": {
|
|
@@ -10842,7 +10668,6 @@ ${installInfo}`
|
|
|
10842
10668
|
const found = this.findAdapter(cliType, { instanceKey: args?.targetSessionId, dir });
|
|
10843
10669
|
if (found) await this.stopSession(found.key);
|
|
10844
10670
|
await this.startSession(cliType, dir);
|
|
10845
|
-
this.persistRecentDir(cliType, dir);
|
|
10846
10671
|
return { success: true, restarted: true };
|
|
10847
10672
|
}
|
|
10848
10673
|
case "agent_command": {
|
|
@@ -11665,11 +11490,11 @@ var ProviderInstanceManager = class {
|
|
|
11665
11490
|
|
|
11666
11491
|
// src/providers/version-archive.ts
|
|
11667
11492
|
import * as fs8 from "fs";
|
|
11668
|
-
import * as
|
|
11493
|
+
import * as path11 from "path";
|
|
11669
11494
|
import * as os14 from "os";
|
|
11670
11495
|
import { execSync as execSync5 } from "child_process";
|
|
11671
11496
|
import { platform as platform8 } from "os";
|
|
11672
|
-
var ARCHIVE_PATH =
|
|
11497
|
+
var ARCHIVE_PATH = path11.join(os14.homedir(), ".adhdev", "version-history.json");
|
|
11673
11498
|
var MAX_ENTRIES_PER_PROVIDER = 20;
|
|
11674
11499
|
var VersionArchive = class {
|
|
11675
11500
|
history = {};
|
|
@@ -11716,7 +11541,7 @@ var VersionArchive = class {
|
|
|
11716
11541
|
}
|
|
11717
11542
|
save() {
|
|
11718
11543
|
try {
|
|
11719
|
-
fs8.mkdirSync(
|
|
11544
|
+
fs8.mkdirSync(path11.dirname(ARCHIVE_PATH), { recursive: true });
|
|
11720
11545
|
fs8.writeFileSync(ARCHIVE_PATH, JSON.stringify(this.history, null, 2));
|
|
11721
11546
|
} catch {
|
|
11722
11547
|
}
|
|
@@ -11757,7 +11582,7 @@ function checkPathExists2(paths) {
|
|
|
11757
11582
|
for (const p of paths) {
|
|
11758
11583
|
if (p.includes("*")) {
|
|
11759
11584
|
const home = os14.homedir();
|
|
11760
|
-
const resolved = p.replace(/\*/g, home.split(
|
|
11585
|
+
const resolved = p.replace(/\*/g, home.split(path11.sep).pop() || "");
|
|
11761
11586
|
if (fs8.existsSync(resolved)) return resolved;
|
|
11762
11587
|
} else {
|
|
11763
11588
|
if (fs8.existsSync(p)) return p;
|
|
@@ -11767,7 +11592,7 @@ function checkPathExists2(paths) {
|
|
|
11767
11592
|
}
|
|
11768
11593
|
function getMacAppVersion(appPath) {
|
|
11769
11594
|
if (platform8() !== "darwin" || !appPath.endsWith(".app")) return null;
|
|
11770
|
-
const plistPath =
|
|
11595
|
+
const plistPath = path11.join(appPath, "Contents", "Info.plist");
|
|
11771
11596
|
if (!fs8.existsSync(plistPath)) return null;
|
|
11772
11597
|
const raw = runCommand(`/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "${plistPath}"`);
|
|
11773
11598
|
return raw || null;
|
|
@@ -11794,7 +11619,7 @@ async function detectAllVersions(loader, archive) {
|
|
|
11794
11619
|
const cliBin = provider.cli ? findBinary2(provider.cli) : null;
|
|
11795
11620
|
let resolvedBin = cliBin;
|
|
11796
11621
|
if (!resolvedBin && appPath && currentOs === "darwin") {
|
|
11797
|
-
const bundled =
|
|
11622
|
+
const bundled = path11.join(appPath, "Contents", "Resources", "app", "bin", provider.cli || "");
|
|
11798
11623
|
if (provider.cli && fs8.existsSync(bundled)) resolvedBin = bundled;
|
|
11799
11624
|
}
|
|
11800
11625
|
info.installed = !!(appPath || resolvedBin);
|
|
@@ -11835,7 +11660,7 @@ async function detectAllVersions(loader, archive) {
|
|
|
11835
11660
|
// src/daemon/dev-server.ts
|
|
11836
11661
|
import * as http2 from "http";
|
|
11837
11662
|
import * as fs11 from "fs";
|
|
11838
|
-
import * as
|
|
11663
|
+
import * as path14 from "path";
|
|
11839
11664
|
|
|
11840
11665
|
// src/daemon/scaffold-template.ts
|
|
11841
11666
|
function generateFiles(type, name, category, opts = {}) {
|
|
@@ -12172,7 +11997,7 @@ init_logger();
|
|
|
12172
11997
|
// src/daemon/dev-cdp-handlers.ts
|
|
12173
11998
|
init_logger();
|
|
12174
11999
|
import * as fs9 from "fs";
|
|
12175
|
-
import * as
|
|
12000
|
+
import * as path12 from "path";
|
|
12176
12001
|
async function handleCdpEvaluate(ctx, req, res) {
|
|
12177
12002
|
const body = await ctx.readBody(req);
|
|
12178
12003
|
const { expression, timeout, ideType } = body;
|
|
@@ -12350,17 +12175,17 @@ async function handleScriptHints(ctx, type, _req, res) {
|
|
|
12350
12175
|
return;
|
|
12351
12176
|
}
|
|
12352
12177
|
let scriptsPath = "";
|
|
12353
|
-
const directScripts =
|
|
12178
|
+
const directScripts = path12.join(dir, "scripts.js");
|
|
12354
12179
|
if (fs9.existsSync(directScripts)) {
|
|
12355
12180
|
scriptsPath = directScripts;
|
|
12356
12181
|
} else {
|
|
12357
|
-
const scriptsDir =
|
|
12182
|
+
const scriptsDir = path12.join(dir, "scripts");
|
|
12358
12183
|
if (fs9.existsSync(scriptsDir)) {
|
|
12359
12184
|
const versions = fs9.readdirSync(scriptsDir).filter((d) => {
|
|
12360
|
-
return fs9.statSync(
|
|
12185
|
+
return fs9.statSync(path12.join(scriptsDir, d)).isDirectory();
|
|
12361
12186
|
}).sort().reverse();
|
|
12362
12187
|
for (const ver of versions) {
|
|
12363
|
-
const p =
|
|
12188
|
+
const p = path12.join(scriptsDir, ver, "scripts.js");
|
|
12364
12189
|
if (fs9.existsSync(p)) {
|
|
12365
12190
|
scriptsPath = p;
|
|
12366
12191
|
break;
|
|
@@ -13415,7 +13240,7 @@ async function handleCliRaw(ctx, req, res) {
|
|
|
13415
13240
|
|
|
13416
13241
|
// src/daemon/dev-auto-implement.ts
|
|
13417
13242
|
import * as fs10 from "fs";
|
|
13418
|
-
import * as
|
|
13243
|
+
import * as path13 from "path";
|
|
13419
13244
|
import * as os15 from "os";
|
|
13420
13245
|
function getDefaultAutoImplReference(ctx, category, type) {
|
|
13421
13246
|
if (category === "cli") {
|
|
@@ -13435,22 +13260,22 @@ function getLatestScriptVersionDir(scriptsDir) {
|
|
|
13435
13260
|
if (!fs10.existsSync(scriptsDir)) return null;
|
|
13436
13261
|
const versions = fs10.readdirSync(scriptsDir).filter((d) => {
|
|
13437
13262
|
try {
|
|
13438
|
-
return fs10.statSync(
|
|
13263
|
+
return fs10.statSync(path13.join(scriptsDir, d)).isDirectory();
|
|
13439
13264
|
} catch {
|
|
13440
13265
|
return false;
|
|
13441
13266
|
}
|
|
13442
13267
|
}).sort((a, b) => b.localeCompare(a, void 0, { numeric: true, sensitivity: "base" }));
|
|
13443
13268
|
if (versions.length === 0) return null;
|
|
13444
|
-
return
|
|
13269
|
+
return path13.join(scriptsDir, versions[0]);
|
|
13445
13270
|
}
|
|
13446
13271
|
function resolveAutoImplWritableProviderDir(ctx, category, type, requestedDir) {
|
|
13447
|
-
const canonicalUserDir =
|
|
13448
|
-
const desiredDir = requestedDir ?
|
|
13449
|
-
const upstreamRoot =
|
|
13450
|
-
if (desiredDir === upstreamRoot || desiredDir.startsWith(`${upstreamRoot}${
|
|
13272
|
+
const canonicalUserDir = path13.resolve(ctx.providerLoader.getUserProviderDir(category, type));
|
|
13273
|
+
const desiredDir = requestedDir ? path13.resolve(requestedDir) : canonicalUserDir;
|
|
13274
|
+
const upstreamRoot = path13.resolve(ctx.providerLoader.getUpstreamDir());
|
|
13275
|
+
if (desiredDir === upstreamRoot || desiredDir.startsWith(`${upstreamRoot}${path13.sep}`)) {
|
|
13451
13276
|
return { dir: null, reason: `Refusing to write into upstream provider directory: ${desiredDir}` };
|
|
13452
13277
|
}
|
|
13453
|
-
if (
|
|
13278
|
+
if (path13.basename(desiredDir) !== type) {
|
|
13454
13279
|
return { dir: null, reason: `Requested writable provider directory must end with '${type}': ${desiredDir}` };
|
|
13455
13280
|
}
|
|
13456
13281
|
const sourceDir = ctx.findProviderDir(type);
|
|
@@ -13458,11 +13283,11 @@ function resolveAutoImplWritableProviderDir(ctx, category, type, requestedDir) {
|
|
|
13458
13283
|
return { dir: null, reason: `Provider source directory not found for '${type}'` };
|
|
13459
13284
|
}
|
|
13460
13285
|
if (!fs10.existsSync(desiredDir)) {
|
|
13461
|
-
fs10.mkdirSync(
|
|
13286
|
+
fs10.mkdirSync(path13.dirname(desiredDir), { recursive: true });
|
|
13462
13287
|
fs10.cpSync(sourceDir, desiredDir, { recursive: true });
|
|
13463
13288
|
ctx.log(`Auto-implement writable copy created: ${desiredDir}`);
|
|
13464
13289
|
}
|
|
13465
|
-
const providerJson =
|
|
13290
|
+
const providerJson = path13.join(desiredDir, "provider.json");
|
|
13466
13291
|
if (!fs10.existsSync(providerJson)) {
|
|
13467
13292
|
return { dir: null, reason: `provider.json not found in writable provider directory: ${desiredDir}` };
|
|
13468
13293
|
}
|
|
@@ -13485,13 +13310,13 @@ function loadAutoImplReferenceScripts(ctx, referenceType) {
|
|
|
13485
13310
|
const refDir = ctx.findProviderDir(referenceType);
|
|
13486
13311
|
if (!refDir || !fs10.existsSync(refDir)) return {};
|
|
13487
13312
|
const referenceScripts = {};
|
|
13488
|
-
const scriptsDir =
|
|
13313
|
+
const scriptsDir = path13.join(refDir, "scripts");
|
|
13489
13314
|
const latestDir = getLatestScriptVersionDir(scriptsDir);
|
|
13490
13315
|
if (!latestDir) return referenceScripts;
|
|
13491
13316
|
for (const file of fs10.readdirSync(latestDir)) {
|
|
13492
13317
|
if (!file.endsWith(".js")) continue;
|
|
13493
13318
|
try {
|
|
13494
|
-
referenceScripts[file] = fs10.readFileSync(
|
|
13319
|
+
referenceScripts[file] = fs10.readFileSync(path13.join(latestDir, file), "utf-8");
|
|
13495
13320
|
} catch {
|
|
13496
13321
|
}
|
|
13497
13322
|
}
|
|
@@ -13542,9 +13367,9 @@ async function handleAutoImplement(ctx, type, req, res) {
|
|
|
13542
13367
|
});
|
|
13543
13368
|
const referenceScripts = loadAutoImplReferenceScripts(ctx, resolvedReference);
|
|
13544
13369
|
const prompt = buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domContext, referenceScripts, comment, resolvedReference);
|
|
13545
|
-
const tmpDir =
|
|
13370
|
+
const tmpDir = path13.join(os15.tmpdir(), "adhdev-autoimpl");
|
|
13546
13371
|
if (!fs10.existsSync(tmpDir)) fs10.mkdirSync(tmpDir, { recursive: true });
|
|
13547
|
-
const promptFile =
|
|
13372
|
+
const promptFile = path13.join(tmpDir, `prompt-${type}-${Date.now()}.md`);
|
|
13548
13373
|
fs10.writeFileSync(promptFile, prompt, "utf-8");
|
|
13549
13374
|
ctx.log(`Auto-implement prompt written to ${promptFile} (${prompt.length} chars)`);
|
|
13550
13375
|
const agentProvider = ctx.providerLoader.resolve(agent) || ctx.providerLoader.getMeta(agent);
|
|
@@ -13915,7 +13740,7 @@ function buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domCon
|
|
|
13915
13740
|
setMode: "set_mode.js"
|
|
13916
13741
|
};
|
|
13917
13742
|
const targetFileNames = new Set(functions.map((fn) => funcToFile[fn]).filter(Boolean));
|
|
13918
|
-
const scriptsDir =
|
|
13743
|
+
const scriptsDir = path13.join(providerDir, "scripts");
|
|
13919
13744
|
const latestScriptsDir = getLatestScriptVersionDir(scriptsDir);
|
|
13920
13745
|
if (latestScriptsDir) {
|
|
13921
13746
|
lines.push(`Scripts version directory: \`${latestScriptsDir}\``);
|
|
@@ -13926,7 +13751,7 @@ function buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domCon
|
|
|
13926
13751
|
for (const file of fs10.readdirSync(latestScriptsDir)) {
|
|
13927
13752
|
if (file.endsWith(".js") && targetFileNames.has(file)) {
|
|
13928
13753
|
try {
|
|
13929
|
-
const content = fs10.readFileSync(
|
|
13754
|
+
const content = fs10.readFileSync(path13.join(latestScriptsDir, file), "utf-8");
|
|
13930
13755
|
lines.push(`### \`${file}\` \u270F\uFE0F EDIT`);
|
|
13931
13756
|
lines.push("```javascript");
|
|
13932
13757
|
lines.push(content);
|
|
@@ -13943,7 +13768,7 @@ function buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domCon
|
|
|
13943
13768
|
lines.push("");
|
|
13944
13769
|
for (const file of refFiles) {
|
|
13945
13770
|
try {
|
|
13946
|
-
const content = fs10.readFileSync(
|
|
13771
|
+
const content = fs10.readFileSync(path13.join(latestScriptsDir, file), "utf-8");
|
|
13947
13772
|
lines.push(`### \`${file}\` \u{1F512}`);
|
|
13948
13773
|
lines.push("```javascript");
|
|
13949
13774
|
lines.push(content);
|
|
@@ -13984,10 +13809,10 @@ function buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domCon
|
|
|
13984
13809
|
lines.push("");
|
|
13985
13810
|
}
|
|
13986
13811
|
}
|
|
13987
|
-
const docsDir =
|
|
13812
|
+
const docsDir = path13.join(providerDir, "../../docs");
|
|
13988
13813
|
const loadGuide = (name) => {
|
|
13989
13814
|
try {
|
|
13990
|
-
const p =
|
|
13815
|
+
const p = path13.join(docsDir, name);
|
|
13991
13816
|
if (fs10.existsSync(p)) return fs10.readFileSync(p, "utf-8");
|
|
13992
13817
|
} catch {
|
|
13993
13818
|
}
|
|
@@ -14161,7 +13986,7 @@ function buildCliAutoImplPrompt(ctx, type, provider, providerDir, functions, ref
|
|
|
14161
13986
|
parseApproval: "parse_approval.js"
|
|
14162
13987
|
};
|
|
14163
13988
|
const targetFileNames = new Set(functions.map((fn) => funcToFile[fn]).filter(Boolean));
|
|
14164
|
-
const scriptsDir =
|
|
13989
|
+
const scriptsDir = path13.join(providerDir, "scripts");
|
|
14165
13990
|
const latestScriptsDir = getLatestScriptVersionDir(scriptsDir);
|
|
14166
13991
|
if (latestScriptsDir) {
|
|
14167
13992
|
lines.push(`Scripts version directory: \`${latestScriptsDir}\``);
|
|
@@ -14173,7 +13998,7 @@ function buildCliAutoImplPrompt(ctx, type, provider, providerDir, functions, ref
|
|
|
14173
13998
|
if (!file.endsWith(".js")) continue;
|
|
14174
13999
|
if (!targetFileNames.has(file)) continue;
|
|
14175
14000
|
try {
|
|
14176
|
-
const content = fs10.readFileSync(
|
|
14001
|
+
const content = fs10.readFileSync(path13.join(latestScriptsDir, file), "utf-8");
|
|
14177
14002
|
lines.push(`### \`${file}\` \u270F\uFE0F EDIT`);
|
|
14178
14003
|
lines.push("```javascript");
|
|
14179
14004
|
lines.push(content);
|
|
@@ -14189,7 +14014,7 @@ function buildCliAutoImplPrompt(ctx, type, provider, providerDir, functions, ref
|
|
|
14189
14014
|
lines.push("");
|
|
14190
14015
|
for (const file of refFiles) {
|
|
14191
14016
|
try {
|
|
14192
|
-
const content = fs10.readFileSync(
|
|
14017
|
+
const content = fs10.readFileSync(path13.join(latestScriptsDir, file), "utf-8");
|
|
14193
14018
|
lines.push(`### \`${file}\` \u{1F512}`);
|
|
14194
14019
|
lines.push("```javascript");
|
|
14195
14020
|
lines.push(content);
|
|
@@ -14222,10 +14047,10 @@ function buildCliAutoImplPrompt(ctx, type, provider, providerDir, functions, ref
|
|
|
14222
14047
|
lines.push("");
|
|
14223
14048
|
}
|
|
14224
14049
|
}
|
|
14225
|
-
const docsDir =
|
|
14050
|
+
const docsDir = path13.join(providerDir, "../../docs");
|
|
14226
14051
|
const loadGuide = (name) => {
|
|
14227
14052
|
try {
|
|
14228
|
-
const p =
|
|
14053
|
+
const p = path13.join(docsDir, name);
|
|
14229
14054
|
if (fs10.existsSync(p)) return fs10.readFileSync(p, "utf-8");
|
|
14230
14055
|
} catch {
|
|
14231
14056
|
}
|
|
@@ -14483,8 +14308,8 @@ var DevServer = class _DevServer {
|
|
|
14483
14308
|
}
|
|
14484
14309
|
getEndpointList() {
|
|
14485
14310
|
return this.routes.map((r) => {
|
|
14486
|
-
const
|
|
14487
|
-
return `${r.method.padEnd(5)} ${
|
|
14311
|
+
const path15 = typeof r.pattern === "string" ? r.pattern : r.pattern.source.replace(/\\\//g, "/").replace(/\(\[.*?\]\+\)/g, ":type").replace(/[\^$]/g, "");
|
|
14312
|
+
return `${r.method.padEnd(5)} ${path15}`;
|
|
14488
14313
|
});
|
|
14489
14314
|
}
|
|
14490
14315
|
async start(port = DEV_SERVER_PORT) {
|
|
@@ -14515,15 +14340,15 @@ var DevServer = class _DevServer {
|
|
|
14515
14340
|
this.json(res, 500, { error: e.message });
|
|
14516
14341
|
}
|
|
14517
14342
|
});
|
|
14518
|
-
return new Promise((
|
|
14343
|
+
return new Promise((resolve9, reject) => {
|
|
14519
14344
|
this.server.listen(port, "127.0.0.1", () => {
|
|
14520
14345
|
this.log(`Dev server listening on http://127.0.0.1:${port}`);
|
|
14521
|
-
|
|
14346
|
+
resolve9();
|
|
14522
14347
|
});
|
|
14523
14348
|
this.server.on("error", (e) => {
|
|
14524
14349
|
if (e.code === "EADDRINUSE") {
|
|
14525
14350
|
this.log(`Port ${port} in use, skipping dev server`);
|
|
14526
|
-
|
|
14351
|
+
resolve9();
|
|
14527
14352
|
} else {
|
|
14528
14353
|
reject(e);
|
|
14529
14354
|
}
|
|
@@ -14606,20 +14431,20 @@ var DevServer = class _DevServer {
|
|
|
14606
14431
|
child.stderr?.on("data", (d) => {
|
|
14607
14432
|
stderr += d.toString().slice(0, 2e3);
|
|
14608
14433
|
});
|
|
14609
|
-
await new Promise((
|
|
14434
|
+
await new Promise((resolve9) => {
|
|
14610
14435
|
const timer = setTimeout(() => {
|
|
14611
14436
|
child.kill();
|
|
14612
|
-
|
|
14437
|
+
resolve9();
|
|
14613
14438
|
}, 3e3);
|
|
14614
14439
|
child.on("exit", () => {
|
|
14615
14440
|
clearTimeout(timer);
|
|
14616
|
-
|
|
14441
|
+
resolve9();
|
|
14617
14442
|
});
|
|
14618
14443
|
child.stdout?.once("data", () => {
|
|
14619
14444
|
setTimeout(() => {
|
|
14620
14445
|
child.kill();
|
|
14621
14446
|
clearTimeout(timer);
|
|
14622
|
-
|
|
14447
|
+
resolve9();
|
|
14623
14448
|
}, 500);
|
|
14624
14449
|
});
|
|
14625
14450
|
});
|
|
@@ -14766,12 +14591,12 @@ var DevServer = class _DevServer {
|
|
|
14766
14591
|
// ─── DevConsole SPA ───
|
|
14767
14592
|
getConsoleDistDir() {
|
|
14768
14593
|
const candidates = [
|
|
14769
|
-
|
|
14770
|
-
|
|
14771
|
-
|
|
14594
|
+
path14.resolve(__dirname, "../../web-devconsole/dist"),
|
|
14595
|
+
path14.resolve(__dirname, "../../../web-devconsole/dist"),
|
|
14596
|
+
path14.join(process.cwd(), "packages/web-devconsole/dist")
|
|
14772
14597
|
];
|
|
14773
14598
|
for (const dir of candidates) {
|
|
14774
|
-
if (fs11.existsSync(
|
|
14599
|
+
if (fs11.existsSync(path14.join(dir, "index.html"))) return dir;
|
|
14775
14600
|
}
|
|
14776
14601
|
return null;
|
|
14777
14602
|
}
|
|
@@ -14781,7 +14606,7 @@ var DevServer = class _DevServer {
|
|
|
14781
14606
|
this.json(res, 500, { error: "DevConsole not found. Run: npm run build -w packages/web-devconsole" });
|
|
14782
14607
|
return;
|
|
14783
14608
|
}
|
|
14784
|
-
const htmlPath =
|
|
14609
|
+
const htmlPath = path14.join(distDir, "index.html");
|
|
14785
14610
|
try {
|
|
14786
14611
|
const html = fs11.readFileSync(htmlPath, "utf-8");
|
|
14787
14612
|
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
|
|
@@ -14806,15 +14631,15 @@ var DevServer = class _DevServer {
|
|
|
14806
14631
|
this.json(res, 404, { error: "Not found" });
|
|
14807
14632
|
return;
|
|
14808
14633
|
}
|
|
14809
|
-
const safePath =
|
|
14810
|
-
const filePath =
|
|
14634
|
+
const safePath = path14.normalize(pathname).replace(/^\.\.\//, "");
|
|
14635
|
+
const filePath = path14.join(distDir, safePath);
|
|
14811
14636
|
if (!filePath.startsWith(distDir)) {
|
|
14812
14637
|
this.json(res, 403, { error: "Forbidden" });
|
|
14813
14638
|
return;
|
|
14814
14639
|
}
|
|
14815
14640
|
try {
|
|
14816
14641
|
const content = fs11.readFileSync(filePath);
|
|
14817
|
-
const ext =
|
|
14642
|
+
const ext = path14.extname(filePath);
|
|
14818
14643
|
const contentType = _DevServer.MIME_MAP[ext] || "application/octet-stream";
|
|
14819
14644
|
res.writeHead(200, { "Content-Type": contentType, "Cache-Control": "public, max-age=31536000, immutable" });
|
|
14820
14645
|
res.end(content);
|
|
@@ -14927,9 +14752,9 @@ var DevServer = class _DevServer {
|
|
|
14927
14752
|
const rel = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
14928
14753
|
if (entry.isDirectory()) {
|
|
14929
14754
|
files.push({ path: rel, size: 0, type: "dir" });
|
|
14930
|
-
scan(
|
|
14755
|
+
scan(path14.join(d, entry.name), rel);
|
|
14931
14756
|
} else {
|
|
14932
|
-
const stat = fs11.statSync(
|
|
14757
|
+
const stat = fs11.statSync(path14.join(d, entry.name));
|
|
14933
14758
|
files.push({ path: rel, size: stat.size, type: "file" });
|
|
14934
14759
|
}
|
|
14935
14760
|
}
|
|
@@ -14952,7 +14777,7 @@ var DevServer = class _DevServer {
|
|
|
14952
14777
|
this.json(res, 404, { error: `Provider directory not found: ${type}` });
|
|
14953
14778
|
return;
|
|
14954
14779
|
}
|
|
14955
|
-
const fullPath =
|
|
14780
|
+
const fullPath = path14.resolve(dir, path14.normalize(filePath));
|
|
14956
14781
|
if (!fullPath.startsWith(dir)) {
|
|
14957
14782
|
this.json(res, 403, { error: "Forbidden" });
|
|
14958
14783
|
return;
|
|
@@ -14977,14 +14802,14 @@ var DevServer = class _DevServer {
|
|
|
14977
14802
|
this.json(res, 404, { error: `Provider directory not found: ${type}` });
|
|
14978
14803
|
return;
|
|
14979
14804
|
}
|
|
14980
|
-
const fullPath =
|
|
14805
|
+
const fullPath = path14.resolve(dir, path14.normalize(filePath));
|
|
14981
14806
|
if (!fullPath.startsWith(dir)) {
|
|
14982
14807
|
this.json(res, 403, { error: "Forbidden" });
|
|
14983
14808
|
return;
|
|
14984
14809
|
}
|
|
14985
14810
|
try {
|
|
14986
14811
|
if (fs11.existsSync(fullPath)) fs11.copyFileSync(fullPath, fullPath + ".bak");
|
|
14987
|
-
fs11.mkdirSync(
|
|
14812
|
+
fs11.mkdirSync(path14.dirname(fullPath), { recursive: true });
|
|
14988
14813
|
fs11.writeFileSync(fullPath, content, "utf-8");
|
|
14989
14814
|
this.log(`File saved: ${fullPath} (${content.length} chars)`);
|
|
14990
14815
|
this.providerLoader.reload();
|
|
@@ -15001,7 +14826,7 @@ var DevServer = class _DevServer {
|
|
|
15001
14826
|
return;
|
|
15002
14827
|
}
|
|
15003
14828
|
for (const name of ["scripts.js", "provider.json"]) {
|
|
15004
|
-
const p =
|
|
14829
|
+
const p = path14.join(dir, name);
|
|
15005
14830
|
if (fs11.existsSync(p)) {
|
|
15006
14831
|
const source = fs11.readFileSync(p, "utf-8");
|
|
15007
14832
|
this.json(res, 200, { type, path: p, source, lines: source.split("\n").length });
|
|
@@ -15022,8 +14847,8 @@ var DevServer = class _DevServer {
|
|
|
15022
14847
|
this.json(res, 404, { error: `Provider not found: ${type}` });
|
|
15023
14848
|
return;
|
|
15024
14849
|
}
|
|
15025
|
-
const target = fs11.existsSync(
|
|
15026
|
-
const targetPath =
|
|
14850
|
+
const target = fs11.existsSync(path14.join(dir, "scripts.js")) ? "scripts.js" : "provider.json";
|
|
14851
|
+
const targetPath = path14.join(dir, target);
|
|
15027
14852
|
try {
|
|
15028
14853
|
if (fs11.existsSync(targetPath)) fs11.copyFileSync(targetPath, targetPath + ".bak");
|
|
15029
14854
|
fs11.writeFileSync(targetPath, source, "utf-8");
|
|
@@ -15128,14 +14953,14 @@ var DevServer = class _DevServer {
|
|
|
15128
14953
|
child.stderr?.on("data", (d) => {
|
|
15129
14954
|
stderr += d.toString();
|
|
15130
14955
|
});
|
|
15131
|
-
await new Promise((
|
|
14956
|
+
await new Promise((resolve9) => {
|
|
15132
14957
|
const timer = setTimeout(() => {
|
|
15133
14958
|
child.kill();
|
|
15134
|
-
|
|
14959
|
+
resolve9();
|
|
15135
14960
|
}, timeout);
|
|
15136
14961
|
child.on("exit", () => {
|
|
15137
14962
|
clearTimeout(timer);
|
|
15138
|
-
|
|
14963
|
+
resolve9();
|
|
15139
14964
|
});
|
|
15140
14965
|
});
|
|
15141
14966
|
const elapsed = Date.now() - start;
|
|
@@ -15183,7 +15008,7 @@ var DevServer = class _DevServer {
|
|
|
15183
15008
|
}
|
|
15184
15009
|
let targetDir;
|
|
15185
15010
|
targetDir = this.providerLoader.getUserProviderDir(category, type);
|
|
15186
|
-
const jsonPath =
|
|
15011
|
+
const jsonPath = path14.join(targetDir, "provider.json");
|
|
15187
15012
|
if (fs11.existsSync(jsonPath)) {
|
|
15188
15013
|
this.json(res, 409, { error: `Provider already exists at ${targetDir}`, path: targetDir });
|
|
15189
15014
|
return;
|
|
@@ -15195,8 +15020,8 @@ var DevServer = class _DevServer {
|
|
|
15195
15020
|
const createdFiles = ["provider.json"];
|
|
15196
15021
|
if (result.files) {
|
|
15197
15022
|
for (const [relPath, content] of Object.entries(result.files)) {
|
|
15198
|
-
const fullPath =
|
|
15199
|
-
fs11.mkdirSync(
|
|
15023
|
+
const fullPath = path14.join(targetDir, relPath);
|
|
15024
|
+
fs11.mkdirSync(path14.dirname(fullPath), { recursive: true });
|
|
15200
15025
|
fs11.writeFileSync(fullPath, content, "utf-8");
|
|
15201
15026
|
createdFiles.push(relPath);
|
|
15202
15027
|
}
|
|
@@ -15249,22 +15074,22 @@ var DevServer = class _DevServer {
|
|
|
15249
15074
|
if (!fs11.existsSync(scriptsDir)) return null;
|
|
15250
15075
|
const versions = fs11.readdirSync(scriptsDir).filter((d) => {
|
|
15251
15076
|
try {
|
|
15252
|
-
return fs11.statSync(
|
|
15077
|
+
return fs11.statSync(path14.join(scriptsDir, d)).isDirectory();
|
|
15253
15078
|
} catch {
|
|
15254
15079
|
return false;
|
|
15255
15080
|
}
|
|
15256
15081
|
}).sort((a, b) => b.localeCompare(a, void 0, { numeric: true, sensitivity: "base" }));
|
|
15257
15082
|
if (versions.length === 0) return null;
|
|
15258
|
-
return
|
|
15083
|
+
return path14.join(scriptsDir, versions[0]);
|
|
15259
15084
|
}
|
|
15260
15085
|
resolveAutoImplWritableProviderDir(category, type, requestedDir) {
|
|
15261
|
-
const canonicalUserDir =
|
|
15262
|
-
const desiredDir = requestedDir ?
|
|
15263
|
-
const upstreamRoot =
|
|
15264
|
-
if (desiredDir === upstreamRoot || desiredDir.startsWith(`${upstreamRoot}${
|
|
15086
|
+
const canonicalUserDir = path14.resolve(this.providerLoader.getUserProviderDir(category, type));
|
|
15087
|
+
const desiredDir = requestedDir ? path14.resolve(requestedDir) : canonicalUserDir;
|
|
15088
|
+
const upstreamRoot = path14.resolve(this.providerLoader.getUpstreamDir());
|
|
15089
|
+
if (desiredDir === upstreamRoot || desiredDir.startsWith(`${upstreamRoot}${path14.sep}`)) {
|
|
15265
15090
|
return { dir: null, reason: `Refusing to write into upstream provider directory: ${desiredDir}` };
|
|
15266
15091
|
}
|
|
15267
|
-
if (
|
|
15092
|
+
if (path14.basename(desiredDir) !== type) {
|
|
15268
15093
|
return { dir: null, reason: `Requested writable provider directory must end with '${type}': ${desiredDir}` };
|
|
15269
15094
|
}
|
|
15270
15095
|
const sourceDir = this.findProviderDir(type);
|
|
@@ -15272,11 +15097,11 @@ var DevServer = class _DevServer {
|
|
|
15272
15097
|
return { dir: null, reason: `Provider source directory not found for '${type}'` };
|
|
15273
15098
|
}
|
|
15274
15099
|
if (!fs11.existsSync(desiredDir)) {
|
|
15275
|
-
fs11.mkdirSync(
|
|
15100
|
+
fs11.mkdirSync(path14.dirname(desiredDir), { recursive: true });
|
|
15276
15101
|
fs11.cpSync(sourceDir, desiredDir, { recursive: true });
|
|
15277
15102
|
this.log(`Auto-implement writable copy created: ${desiredDir}`);
|
|
15278
15103
|
}
|
|
15279
|
-
const providerJson =
|
|
15104
|
+
const providerJson = path14.join(desiredDir, "provider.json");
|
|
15280
15105
|
if (!fs11.existsSync(providerJson)) {
|
|
15281
15106
|
return { dir: null, reason: `provider.json not found in writable provider directory: ${desiredDir}` };
|
|
15282
15107
|
}
|
|
@@ -15324,7 +15149,7 @@ var DevServer = class _DevServer {
|
|
|
15324
15149
|
setMode: "set_mode.js"
|
|
15325
15150
|
};
|
|
15326
15151
|
const targetFileNames = new Set(functions.map((fn) => funcToFile[fn]).filter(Boolean));
|
|
15327
|
-
const scriptsDir =
|
|
15152
|
+
const scriptsDir = path14.join(providerDir, "scripts");
|
|
15328
15153
|
const latestScriptsDir = this.getLatestScriptVersionDir(scriptsDir);
|
|
15329
15154
|
if (latestScriptsDir) {
|
|
15330
15155
|
lines.push(`Scripts version directory: \`${latestScriptsDir}\``);
|
|
@@ -15335,7 +15160,7 @@ var DevServer = class _DevServer {
|
|
|
15335
15160
|
for (const file of fs11.readdirSync(latestScriptsDir)) {
|
|
15336
15161
|
if (file.endsWith(".js") && targetFileNames.has(file)) {
|
|
15337
15162
|
try {
|
|
15338
|
-
const content = fs11.readFileSync(
|
|
15163
|
+
const content = fs11.readFileSync(path14.join(latestScriptsDir, file), "utf-8");
|
|
15339
15164
|
lines.push(`### \`${file}\` \u270F\uFE0F EDIT`);
|
|
15340
15165
|
lines.push("```javascript");
|
|
15341
15166
|
lines.push(content);
|
|
@@ -15352,7 +15177,7 @@ var DevServer = class _DevServer {
|
|
|
15352
15177
|
lines.push("");
|
|
15353
15178
|
for (const file of refFiles) {
|
|
15354
15179
|
try {
|
|
15355
|
-
const content = fs11.readFileSync(
|
|
15180
|
+
const content = fs11.readFileSync(path14.join(latestScriptsDir, file), "utf-8");
|
|
15356
15181
|
lines.push(`### \`${file}\` \u{1F512}`);
|
|
15357
15182
|
lines.push("```javascript");
|
|
15358
15183
|
lines.push(content);
|
|
@@ -15393,10 +15218,10 @@ var DevServer = class _DevServer {
|
|
|
15393
15218
|
lines.push("");
|
|
15394
15219
|
}
|
|
15395
15220
|
}
|
|
15396
|
-
const docsDir =
|
|
15221
|
+
const docsDir = path14.join(providerDir, "../../docs");
|
|
15397
15222
|
const loadGuide = (name) => {
|
|
15398
15223
|
try {
|
|
15399
|
-
const p =
|
|
15224
|
+
const p = path14.join(docsDir, name);
|
|
15400
15225
|
if (fs11.existsSync(p)) return fs11.readFileSync(p, "utf-8");
|
|
15401
15226
|
} catch {
|
|
15402
15227
|
}
|
|
@@ -15570,7 +15395,7 @@ var DevServer = class _DevServer {
|
|
|
15570
15395
|
parseApproval: "parse_approval.js"
|
|
15571
15396
|
};
|
|
15572
15397
|
const targetFileNames = new Set(functions.map((fn) => funcToFile[fn]).filter(Boolean));
|
|
15573
|
-
const scriptsDir =
|
|
15398
|
+
const scriptsDir = path14.join(providerDir, "scripts");
|
|
15574
15399
|
const latestScriptsDir = this.getLatestScriptVersionDir(scriptsDir);
|
|
15575
15400
|
if (latestScriptsDir) {
|
|
15576
15401
|
lines.push(`Scripts version directory: \`${latestScriptsDir}\``);
|
|
@@ -15582,7 +15407,7 @@ var DevServer = class _DevServer {
|
|
|
15582
15407
|
if (!file.endsWith(".js")) continue;
|
|
15583
15408
|
if (!targetFileNames.has(file)) continue;
|
|
15584
15409
|
try {
|
|
15585
|
-
const content = fs11.readFileSync(
|
|
15410
|
+
const content = fs11.readFileSync(path14.join(latestScriptsDir, file), "utf-8");
|
|
15586
15411
|
lines.push(`### \`${file}\` \u270F\uFE0F EDIT`);
|
|
15587
15412
|
lines.push("```javascript");
|
|
15588
15413
|
lines.push(content);
|
|
@@ -15598,7 +15423,7 @@ var DevServer = class _DevServer {
|
|
|
15598
15423
|
lines.push("");
|
|
15599
15424
|
for (const file of refFiles) {
|
|
15600
15425
|
try {
|
|
15601
|
-
const content = fs11.readFileSync(
|
|
15426
|
+
const content = fs11.readFileSync(path14.join(latestScriptsDir, file), "utf-8");
|
|
15602
15427
|
lines.push(`### \`${file}\` \u{1F512}`);
|
|
15603
15428
|
lines.push("```javascript");
|
|
15604
15429
|
lines.push(content);
|
|
@@ -15631,10 +15456,10 @@ var DevServer = class _DevServer {
|
|
|
15631
15456
|
lines.push("");
|
|
15632
15457
|
}
|
|
15633
15458
|
}
|
|
15634
|
-
const docsDir =
|
|
15459
|
+
const docsDir = path14.join(providerDir, "../../docs");
|
|
15635
15460
|
const loadGuide = (name) => {
|
|
15636
15461
|
try {
|
|
15637
|
-
const p =
|
|
15462
|
+
const p = path14.join(docsDir, name);
|
|
15638
15463
|
if (fs11.existsSync(p)) return fs11.readFileSync(p, "utf-8");
|
|
15639
15464
|
} catch {
|
|
15640
15465
|
}
|
|
@@ -15791,14 +15616,14 @@ data: ${JSON.stringify(msg.data)}
|
|
|
15791
15616
|
res.end(JSON.stringify(data, null, 2));
|
|
15792
15617
|
}
|
|
15793
15618
|
async readBody(req) {
|
|
15794
|
-
return new Promise((
|
|
15619
|
+
return new Promise((resolve9) => {
|
|
15795
15620
|
let body = "";
|
|
15796
15621
|
req.on("data", (chunk) => body += chunk);
|
|
15797
15622
|
req.on("end", () => {
|
|
15798
15623
|
try {
|
|
15799
|
-
|
|
15624
|
+
resolve9(JSON.parse(body));
|
|
15800
15625
|
} catch {
|
|
15801
|
-
|
|
15626
|
+
resolve9({});
|
|
15802
15627
|
}
|
|
15803
15628
|
});
|
|
15804
15629
|
});
|
|
@@ -16220,7 +16045,7 @@ async function waitForReady(endpoint, timeoutMs = STARTUP_TIMEOUT_MS) {
|
|
|
16220
16045
|
const deadline = Date.now() + timeoutMs;
|
|
16221
16046
|
while (Date.now() < deadline) {
|
|
16222
16047
|
if (await canConnect(endpoint)) return;
|
|
16223
|
-
await new Promise((
|
|
16048
|
+
await new Promise((resolve9) => setTimeout(resolve9, STARTUP_POLL_MS));
|
|
16224
16049
|
}
|
|
16225
16050
|
throw new Error(`Session host did not become ready within ${timeoutMs}ms`);
|
|
16226
16051
|
}
|
|
@@ -16375,10 +16200,10 @@ async function installExtension(ide, extension) {
|
|
|
16375
16200
|
const buffer = Buffer.from(await res.arrayBuffer());
|
|
16376
16201
|
const fs12 = await import("fs");
|
|
16377
16202
|
fs12.writeFileSync(vsixPath, buffer);
|
|
16378
|
-
return new Promise((
|
|
16203
|
+
return new Promise((resolve9) => {
|
|
16379
16204
|
const cmd = `"${ide.cliCommand}" --install-extension "${vsixPath}" --force`;
|
|
16380
16205
|
exec2(cmd, { timeout: 6e4 }, (error, _stdout, stderr) => {
|
|
16381
|
-
|
|
16206
|
+
resolve9({
|
|
16382
16207
|
extensionId: extension.id,
|
|
16383
16208
|
marketplaceId: extension.marketplaceId,
|
|
16384
16209
|
success: !error,
|
|
@@ -16391,11 +16216,11 @@ async function installExtension(ide, extension) {
|
|
|
16391
16216
|
} catch (e) {
|
|
16392
16217
|
}
|
|
16393
16218
|
}
|
|
16394
|
-
return new Promise((
|
|
16219
|
+
return new Promise((resolve9) => {
|
|
16395
16220
|
const cmd = `"${ide.cliCommand}" --install-extension ${extension.marketplaceId} --force`;
|
|
16396
16221
|
exec2(cmd, { timeout: 6e4 }, (error, stdout, stderr) => {
|
|
16397
16222
|
if (error) {
|
|
16398
|
-
|
|
16223
|
+
resolve9({
|
|
16399
16224
|
extensionId: extension.id,
|
|
16400
16225
|
marketplaceId: extension.marketplaceId,
|
|
16401
16226
|
success: false,
|
|
@@ -16403,7 +16228,7 @@ async function installExtension(ide, extension) {
|
|
|
16403
16228
|
error: stderr || error.message
|
|
16404
16229
|
});
|
|
16405
16230
|
} else {
|
|
16406
|
-
|
|
16231
|
+
resolve9({
|
|
16407
16232
|
extensionId: extension.id,
|
|
16408
16233
|
marketplaceId: extension.marketplaceId,
|
|
16409
16234
|
success: true,
|
|
@@ -16706,7 +16531,6 @@ export {
|
|
|
16706
16531
|
ProviderLoader,
|
|
16707
16532
|
SessionHostPtyTransportFactory,
|
|
16708
16533
|
VersionArchive,
|
|
16709
|
-
addCliHistory,
|
|
16710
16534
|
appendRecentActivity,
|
|
16711
16535
|
buildSessionEntries,
|
|
16712
16536
|
buildStatusSnapshot,
|
|
@@ -16724,7 +16548,6 @@ export {
|
|
|
16724
16548
|
getRecentActivity,
|
|
16725
16549
|
getRecentCommands,
|
|
16726
16550
|
getRecentLogs,
|
|
16727
|
-
getWorkspaceActivity,
|
|
16728
16551
|
getWorkspaceState,
|
|
16729
16552
|
hasCdpManager,
|
|
16730
16553
|
initDaemonComponents,
|