@i14ks/ccv 0.37.0 → 0.39.0
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/bundle/ccv.mjs +756 -319
- package/package.json +1 -1
- package/web/assets/{codemirror-D1cUi2V7.js → codemirror-DxtGDGFk.js} +1 -1
- package/web/assets/{index-B2o6F4n4.js → index-7ePJH0ro.js} +1 -1
- package/web/assets/{index-BKD3Q2Nb.js → index-B37sMj0O.js} +1 -1
- package/web/assets/{index-DJKT02UQ.js → index-BFDq9QAB.js} +1 -1
- package/web/assets/{index-BhVCT3ST.js → index-BVT3q-Tt.js} +1 -1
- package/web/assets/index-BwKT4Ywt.css +1 -0
- package/web/assets/{index-Dlh4RtNI.js → index-ByfO4I3S.js} +1 -1
- package/web/assets/{index-BOi5nzFz.js → index-C2I0tlZW.js} +1 -1
- package/web/assets/{index-CBhA54BF.js → index-C8qIDcIc.js} +1 -1
- package/web/assets/{index-qMt-4408.js → index-CUvAPVSk.js} +1 -1
- package/web/assets/{index-DAUUK4vp.js → index-CYTeESKp.js} +1 -1
- package/web/assets/{index-DooYh81f.js → index-Ce3CzqV9.js} +1 -1
- package/web/assets/{index-BJoy_XAx.js → index-CeQc1DVq.js} +1 -1
- package/web/assets/{index-DnRv3bEx.js → index-CkyUKgI0.js} +1 -1
- package/web/assets/{index-SiXyTYpN.js → index-CotBHbkI.js} +1 -1
- package/web/assets/index-CpfHiTlz.js +134 -0
- package/web/assets/{index-DNUqPqF2.js → index-D6EEDkTZ.js} +1 -1
- package/web/assets/{index-EeZRrDkR.js → index-DpOYCClV.js} +1 -1
- package/web/assets/{index-BXJ1espS.js → index-m4coFts1.js} +1 -1
- package/web/assets/{index-Bqy6ikrI.js → index-o26-Q-i0.js} +1 -1
- package/web/assets/{index-CfBrRHFZ.js → index-szPJRpmr.js} +1 -1
- package/web/assets/{index-xs5AxpJq.js → index-vBfnpOGr.js} +1 -1
- package/web/index.html +2 -2
- package/web/assets/index-3GiZYI9o.css +0 -1
- package/web/assets/index-BBsKh79k.js +0 -134
package/bundle/ccv.mjs
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
// dist/ccv.js
|
|
4
4
|
import { spawn as spawn3 } from "node:child_process";
|
|
5
|
-
import { readFile as
|
|
6
|
-
import
|
|
5
|
+
import { readFile as readFile18 } from "node:fs/promises";
|
|
6
|
+
import path25 from "node:path";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
8
|
import { parseArgs } from "node:util";
|
|
9
9
|
|
|
@@ -63,7 +63,8 @@ async function runClaude(args, options2) {
|
|
|
63
63
|
execFile(file, [...prefix, ...args], {
|
|
64
64
|
timeout: options2.timeout,
|
|
65
65
|
maxBuffer: options2.maxBuffer ?? 1024 * 1024,
|
|
66
|
-
windowsHide: true
|
|
66
|
+
windowsHide: true,
|
|
67
|
+
...options2.env ? { env: options2.env } : {}
|
|
67
68
|
}, (error, stdout, stderr) => {
|
|
68
69
|
if (!error)
|
|
69
70
|
return resolve(stdout.trim());
|
|
@@ -75,9 +76,9 @@ async function runClaude(args, options2) {
|
|
|
75
76
|
});
|
|
76
77
|
});
|
|
77
78
|
}
|
|
78
|
-
async function spawnClaude(args) {
|
|
79
|
+
async function spawnClaude(args, env) {
|
|
79
80
|
const { file, prefix } = await claudeLauncher();
|
|
80
|
-
return spawn(file, [...prefix, ...args], { windowsHide: true });
|
|
81
|
+
return spawn(file, [...prefix, ...args], { windowsHide: true, ...env ? { env } : {} });
|
|
81
82
|
}
|
|
82
83
|
async function locate() {
|
|
83
84
|
for (const dir of searchDirs()) {
|
|
@@ -146,14 +147,16 @@ function envDefaults() {
|
|
|
146
147
|
// ../host/dist/server.js
|
|
147
148
|
import { createServer } from "node:http";
|
|
148
149
|
import { createReadStream, existsSync as existsSync4, statSync as statSync3 } from "node:fs";
|
|
149
|
-
import
|
|
150
|
-
import { homedir as
|
|
151
|
-
import { randomUUID as
|
|
150
|
+
import path24 from "node:path";
|
|
151
|
+
import { homedir as homedir7 } from "node:os";
|
|
152
|
+
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
152
153
|
import { WebSocketServer } from "ws";
|
|
153
154
|
import { renameSession as renameSession2 } from "@anthropic-ai/claude-agent-sdk";
|
|
154
155
|
|
|
155
156
|
// ../protocol/dist/index.js
|
|
156
157
|
var PROTOCOL_VERSION = 1;
|
|
158
|
+
var MAIN_ACCOUNT_ID = "main";
|
|
159
|
+
var ACCOUNT_COLORS = ["orange", "blue", "green", "purple", "pink", "teal"];
|
|
157
160
|
function isClientFrame(value) {
|
|
158
161
|
return typeof value === "object" && value !== null && typeof value.type === "string";
|
|
159
162
|
}
|
|
@@ -184,15 +187,227 @@ function hashText(text) {
|
|
|
184
187
|
return (4294967296 * (2097151 & h2) + (h1 >>> 0)).toString(36);
|
|
185
188
|
}
|
|
186
189
|
|
|
190
|
+
// ../host/dist/accounts.js
|
|
191
|
+
import { randomUUID } from "node:crypto";
|
|
192
|
+
import { lstat, mkdir, readFile as readFile2, readdir, rename, stat, symlink, writeFile } from "node:fs/promises";
|
|
193
|
+
import { homedir as homedir2 } from "node:os";
|
|
194
|
+
import path3 from "node:path";
|
|
195
|
+
var MAIN_DEFAULT = {
|
|
196
|
+
id: MAIN_ACCOUNT_ID,
|
|
197
|
+
name: "\u041E\u0441\u043D\u043E\u0432\u043D\u043E\u0439",
|
|
198
|
+
color: "orange",
|
|
199
|
+
configDir: null
|
|
200
|
+
};
|
|
201
|
+
var AccountStore = class {
|
|
202
|
+
#accounts = [{ ...MAIN_DEFAULT }];
|
|
203
|
+
#file;
|
|
204
|
+
constructor(dataDir) {
|
|
205
|
+
this.#file = path3.join(dataDir, "accounts.json");
|
|
206
|
+
}
|
|
207
|
+
async load() {
|
|
208
|
+
try {
|
|
209
|
+
const parsed = JSON.parse(await readFile2(this.#file, "utf8"));
|
|
210
|
+
const stored = (parsed.accounts ?? []).filter(isStored);
|
|
211
|
+
const main = stored.find((a) => a.id === MAIN_ACCOUNT_ID);
|
|
212
|
+
this.#accounts = [
|
|
213
|
+
{
|
|
214
|
+
...MAIN_DEFAULT,
|
|
215
|
+
...main ? { name: main.name, color: main.color, configDir: main.configDir } : {}
|
|
216
|
+
},
|
|
217
|
+
...stored.filter((a) => a.id !== MAIN_ACCOUNT_ID && a.configDir)
|
|
218
|
+
];
|
|
219
|
+
} catch {
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
get all() {
|
|
223
|
+
return this.#accounts;
|
|
224
|
+
}
|
|
225
|
+
find(id) {
|
|
226
|
+
return this.#accounts.find((a) => a.id === (id ?? MAIN_ACCOUNT_ID));
|
|
227
|
+
}
|
|
228
|
+
/** Каталог конфигурации аккаунта, заданный явно; null — унаследованный. */
|
|
229
|
+
configDir(id) {
|
|
230
|
+
return this.find(id)?.configDir ?? null;
|
|
231
|
+
}
|
|
232
|
+
/** Каталог, в который аккаунт смотрит на самом деле. */
|
|
233
|
+
effectiveDir(id) {
|
|
234
|
+
return this.find(id)?.configDir ?? inheritedDir();
|
|
235
|
+
}
|
|
236
|
+
async add(input) {
|
|
237
|
+
const name = cleanName(input.name);
|
|
238
|
+
const id = randomUUID().slice(0, 8);
|
|
239
|
+
const configDir = input.configDir?.trim() ? path3.resolve(input.configDir.trim()) : path3.join(homedir2(), `.claude-ccv-${id}`);
|
|
240
|
+
if (this.#accounts.some((a) => sameDir(this.effectiveDir(a.id), configDir))) {
|
|
241
|
+
throw new Error("\u042D\u0442\u043E\u0442 \u043A\u0430\u0442\u0430\u043B\u043E\u0433 \u043A\u043E\u043D\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0443\u0436\u0435 \u0437\u0430\u043D\u044F\u0442 \u0434\u0440\u0443\u0433\u0438\u043C \u0430\u043A\u043A\u0430\u0443\u043D\u0442\u043E\u043C");
|
|
242
|
+
}
|
|
243
|
+
const color = input.color ?? this.#freeColor();
|
|
244
|
+
const account = { id, name, color, configDir };
|
|
245
|
+
await mkdir(configDir, { recursive: true });
|
|
246
|
+
if (input.shareConfig)
|
|
247
|
+
await linkSharedConfig(configDir, this.effectiveDir(MAIN_ACCOUNT_ID));
|
|
248
|
+
this.#accounts = [...this.#accounts, account];
|
|
249
|
+
await this.#save();
|
|
250
|
+
return account;
|
|
251
|
+
}
|
|
252
|
+
async update(id, patch) {
|
|
253
|
+
const account = this.find(id);
|
|
254
|
+
if (!account)
|
|
255
|
+
throw new Error("\u0410\u043A\u043A\u0430\u0443\u043D\u0442 \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D");
|
|
256
|
+
if (patch.configDir !== void 0) {
|
|
257
|
+
if (patch.configDir === null) {
|
|
258
|
+
if (account.id !== MAIN_ACCOUNT_ID)
|
|
259
|
+
throw new Error("\u0423\u043A\u0430\u0436\u0438\u0442\u0435 \u043A\u0430\u0442\u0430\u043B\u043E\u0433 \u043A\u043E\u043D\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438");
|
|
260
|
+
account.configDir = null;
|
|
261
|
+
} else {
|
|
262
|
+
const dir = path3.resolve(patch.configDir.trim());
|
|
263
|
+
if (!await isDirectory(dir))
|
|
264
|
+
throw new Error(`\u041A\u0430\u0442\u0430\u043B\u043E\u0433 \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D: ${dir}`);
|
|
265
|
+
const taken = this.#accounts.find((a) => a.id !== account.id && sameDir(this.effectiveDir(a.id), dir));
|
|
266
|
+
if (taken)
|
|
267
|
+
throw new Error(`\u042D\u0442\u043E\u0442 \u043A\u0430\u0442\u0430\u043B\u043E\u0433 \u0443\u0436\u0435 \u0437\u0430\u043D\u044F\u0442 \u0430\u043A\u043A\u0430\u0443\u043D\u0442\u043E\u043C \xAB${taken.name}\xBB`);
|
|
268
|
+
account.configDir = dir;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
if (patch.name !== void 0)
|
|
272
|
+
account.name = cleanName(patch.name);
|
|
273
|
+
if (patch.color !== void 0 && ACCOUNT_COLORS.includes(patch.color))
|
|
274
|
+
account.color = patch.color;
|
|
275
|
+
await this.#save();
|
|
276
|
+
}
|
|
277
|
+
async remove(id) {
|
|
278
|
+
if (id === MAIN_ACCOUNT_ID)
|
|
279
|
+
throw new Error("\u041E\u0441\u043D\u043E\u0432\u043D\u043E\u0439 \u0430\u043A\u043A\u0430\u0443\u043D\u0442 \u0443\u0434\u0430\u043B\u0438\u0442\u044C \u043D\u0435\u043B\u044C\u0437\u044F");
|
|
280
|
+
if (!this.find(id))
|
|
281
|
+
return;
|
|
282
|
+
this.#accounts = this.#accounts.filter((a) => a.id !== id);
|
|
283
|
+
await this.#save();
|
|
284
|
+
}
|
|
285
|
+
#freeColor() {
|
|
286
|
+
const used = new Set(this.#accounts.map((a) => a.color));
|
|
287
|
+
return ACCOUNT_COLORS.find((c) => !used.has(c)) ?? ACCOUNT_COLORS[1];
|
|
288
|
+
}
|
|
289
|
+
async #save() {
|
|
290
|
+
await mkdir(path3.dirname(this.#file), { recursive: true });
|
|
291
|
+
await writeFile(this.#file, `${JSON.stringify({ accounts: this.#accounts }, null, 2)}
|
|
292
|
+
`, "utf8");
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
function accountEnv(configDir) {
|
|
296
|
+
return configDir ? { ...process.env, CLAUDE_CONFIG_DIR: configDir } : { ...process.env };
|
|
297
|
+
}
|
|
298
|
+
function inheritedDir() {
|
|
299
|
+
return process.env.CLAUDE_CONFIG_DIR?.trim() || path3.join(homedir2(), ".claude");
|
|
300
|
+
}
|
|
301
|
+
var chain = Promise.resolve();
|
|
302
|
+
function withConfigDir(configDir, work) {
|
|
303
|
+
if (!configDir) {
|
|
304
|
+
const run2 = chain.then(work, work);
|
|
305
|
+
chain = run2.catch(() => void 0);
|
|
306
|
+
return run2;
|
|
307
|
+
}
|
|
308
|
+
const run = chain.then(async () => {
|
|
309
|
+
const before = process.env.CLAUDE_CONFIG_DIR;
|
|
310
|
+
process.env.CLAUDE_CONFIG_DIR = configDir;
|
|
311
|
+
try {
|
|
312
|
+
return await work();
|
|
313
|
+
} finally {
|
|
314
|
+
if (before === void 0)
|
|
315
|
+
delete process.env.CLAUDE_CONFIG_DIR;
|
|
316
|
+
else
|
|
317
|
+
process.env.CLAUDE_CONFIG_DIR = before;
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
chain = run.catch(() => void 0);
|
|
321
|
+
return run;
|
|
322
|
+
}
|
|
323
|
+
function cleanName(raw) {
|
|
324
|
+
const name = raw.trim().slice(0, 40);
|
|
325
|
+
if (!name)
|
|
326
|
+
throw new Error("\u0414\u0430\u0439\u0442\u0435 \u0430\u043A\u043A\u0430\u0443\u043D\u0442\u0443 \u0438\u043C\u044F");
|
|
327
|
+
return name;
|
|
328
|
+
}
|
|
329
|
+
function sameDir(a, b) {
|
|
330
|
+
const norm = (value) => path3.resolve(value).toLowerCase();
|
|
331
|
+
return norm(a) === norm(b);
|
|
332
|
+
}
|
|
333
|
+
function isStored(value) {
|
|
334
|
+
if (!value || typeof value !== "object")
|
|
335
|
+
return false;
|
|
336
|
+
const v = value;
|
|
337
|
+
return typeof v.id === "string" && typeof v.name === "string" && typeof v.color === "string" && ACCOUNT_COLORS.includes(v.color) && (v.configDir === null || typeof v.configDir === "string");
|
|
338
|
+
}
|
|
339
|
+
var SHARED_DIRS = ["skills", "agents", "hooks", "commands", "plugins"];
|
|
340
|
+
var SHARED_FILES = ["CLAUDE.md", "settings.json"];
|
|
341
|
+
function sharedConfigDir() {
|
|
342
|
+
return process.env.CCV_SHARED_CONFIG_DIR?.trim() || path3.join(homedir2(), ".claude-shared");
|
|
343
|
+
}
|
|
344
|
+
async function linkSharedConfig(configDir, main = inheritedDir()) {
|
|
345
|
+
const shared = sharedConfigDir();
|
|
346
|
+
await mkdir(shared, { recursive: true });
|
|
347
|
+
for (const name of [...SHARED_DIRS, ...SHARED_FILES]) {
|
|
348
|
+
const isDir = SHARED_DIRS.includes(name);
|
|
349
|
+
const target = path3.join(shared, name);
|
|
350
|
+
const origin = path3.join(main, name);
|
|
351
|
+
if (!await exists(target)) {
|
|
352
|
+
if (await isRealEntry(origin))
|
|
353
|
+
await rename(origin, target);
|
|
354
|
+
else if (isDir)
|
|
355
|
+
await mkdir(target, { recursive: true });
|
|
356
|
+
else
|
|
357
|
+
continue;
|
|
358
|
+
}
|
|
359
|
+
if (!await exists(origin) && !sameDir(main, configDir))
|
|
360
|
+
await link(target, origin, isDir);
|
|
361
|
+
const own = path3.join(configDir, name);
|
|
362
|
+
if (!await exists(own))
|
|
363
|
+
await link(target, own, isDir);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
async function link(target, at, isDir) {
|
|
367
|
+
try {
|
|
368
|
+
await symlink(target, at, isDir ? "junction" : "file");
|
|
369
|
+
} catch (error) {
|
|
370
|
+
throw new Error(`\u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u0441\u043E\u0437\u0434\u0430\u0442\u044C \u0441\u0441\u044B\u043B\u043A\u0443 ${at}: ${error instanceof Error ? error.message : String(error)}. \u041D\u0430 Windows \u0441\u0438\u043C\u0432\u043E\u043B\u044C\u043D\u044B\u0435 \u0441\u0441\u044B\u043B\u043A\u0438 \u043D\u0430 \u0444\u0430\u0439\u043B\u044B \u0442\u0440\u0435\u0431\u0443\u044E\u0442 \u0440\u0435\u0436\u0438\u043C\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043E\u0442\u0447\u0438\u043A\u0430.`);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
async function exists(file) {
|
|
374
|
+
return lstat(file).then(() => true, () => false);
|
|
375
|
+
}
|
|
376
|
+
async function isRealEntry(file) {
|
|
377
|
+
return lstat(file).then((stat3) => !stat3.isSymbolicLink(), () => false);
|
|
378
|
+
}
|
|
379
|
+
async function candidateConfigDirs() {
|
|
380
|
+
const home = homedir2();
|
|
381
|
+
const found = /* @__PURE__ */ new Set();
|
|
382
|
+
const add = async (dir) => {
|
|
383
|
+
if (!await isDirectory(dir))
|
|
384
|
+
return;
|
|
385
|
+
const marked = await exists(path3.join(dir, ".credentials.json")) || await exists(path3.join(dir, ".claude.json"));
|
|
386
|
+
if (marked)
|
|
387
|
+
found.add(path3.resolve(dir));
|
|
388
|
+
};
|
|
389
|
+
const skip = /* @__PURE__ */ new Set([".claude-shared", ".claude-code-visual", ".claude-code"]);
|
|
390
|
+
for (const name of await readdir(home).catch(() => [])) {
|
|
391
|
+
if (!/^\.claude(-.+)?$/.test(name) || skip.has(name))
|
|
392
|
+
continue;
|
|
393
|
+
await add(path3.join(home, name));
|
|
394
|
+
}
|
|
395
|
+
await add(inheritedDir());
|
|
396
|
+
return [...found];
|
|
397
|
+
}
|
|
398
|
+
async function isDirectory(file) {
|
|
399
|
+
return stat(file).then((s) => s.isDirectory(), () => false);
|
|
400
|
+
}
|
|
401
|
+
|
|
187
402
|
// ../host/dist/workspace-ids.js
|
|
188
403
|
function workspaceIdRemap(paths, sessionsOf) {
|
|
189
404
|
const byLegacy = /* @__PURE__ */ new Map();
|
|
190
|
-
for (const
|
|
191
|
-
const id = workspaceIdFromPath(
|
|
192
|
-
for (const legacy of formerWorkspaceIdsFromPath(
|
|
405
|
+
for (const path26 of paths) {
|
|
406
|
+
const id = workspaceIdFromPath(path26);
|
|
407
|
+
for (const legacy of formerWorkspaceIdsFromPath(path26)) {
|
|
193
408
|
const group = byLegacy.get(legacy) ?? [];
|
|
194
409
|
if (!group.some((target) => target.id === id))
|
|
195
|
-
group.push({ id, path:
|
|
410
|
+
group.push({ id, path: path26 });
|
|
196
411
|
byLegacy.set(legacy, group);
|
|
197
412
|
}
|
|
198
413
|
}
|
|
@@ -224,8 +439,8 @@ function workspaceIdRemap(paths, sessionsOf) {
|
|
|
224
439
|
|
|
225
440
|
// ../host/dist/session.js
|
|
226
441
|
import { EventEmitter as EventEmitter2 } from "node:events";
|
|
227
|
-
import { randomUUID } from "node:crypto";
|
|
228
|
-
import
|
|
442
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
443
|
+
import path6 from "node:path";
|
|
229
444
|
import { query, renameSession } from "@anthropic-ai/claude-agent-sdk";
|
|
230
445
|
|
|
231
446
|
// ../host/dist/async-queue.js
|
|
@@ -276,8 +491,8 @@ var AsyncQueue = class {
|
|
|
276
491
|
};
|
|
277
492
|
|
|
278
493
|
// ../host/dist/files.js
|
|
279
|
-
import { cp, lstat, mkdir, readFile as
|
|
280
|
-
import
|
|
494
|
+
import { cp, lstat as lstat2, mkdir as mkdir2, readFile as readFile3, readdir as readdir2, realpath, rename as renamePath, rm, stat as stat2, writeFile as writeFile2 } from "node:fs/promises";
|
|
495
|
+
import path4 from "node:path";
|
|
281
496
|
var MAX_FILE = 4 * 1024 * 1024;
|
|
282
497
|
var MAX_MEDIA = 64 * 1024 * 1024;
|
|
283
498
|
var MEDIA_MIME = {
|
|
@@ -310,14 +525,14 @@ var ProjectFiles = class {
|
|
|
310
525
|
}
|
|
311
526
|
async list(relative) {
|
|
312
527
|
const dir = await this.#resolve(relative);
|
|
313
|
-
const names2 = await
|
|
528
|
+
const names2 = await readdir2(dir, { withFileTypes: true });
|
|
314
529
|
const entries = [];
|
|
315
530
|
for (const dirent of names2) {
|
|
316
531
|
if (HIDDEN.has(dirent.name))
|
|
317
532
|
continue;
|
|
318
|
-
const full =
|
|
319
|
-
const
|
|
320
|
-
const info = await
|
|
533
|
+
const full = path4.join(dir, dirent.name);
|
|
534
|
+
const link2 = dirent.isSymbolicLink();
|
|
535
|
+
const info = await stat2(full).catch(() => null);
|
|
321
536
|
if (!info)
|
|
322
537
|
continue;
|
|
323
538
|
entries.push({
|
|
@@ -326,7 +541,7 @@ var ProjectFiles = class {
|
|
|
326
541
|
kind: info.isDirectory() ? "dir" : "file",
|
|
327
542
|
size: info.isDirectory() ? 0 : info.size,
|
|
328
543
|
mtime: Math.round(info.mtimeMs),
|
|
329
|
-
link,
|
|
544
|
+
link: link2,
|
|
330
545
|
// Кто игнорируется, знает git, а не файловая система: отметку ставит
|
|
331
546
|
// сервер поверх готового списка (см. `markIgnored`).
|
|
332
547
|
ignored: false
|
|
@@ -357,15 +572,15 @@ var ProjectFiles = class {
|
|
|
357
572
|
const walk = async (dir, relative) => {
|
|
358
573
|
if (truncated)
|
|
359
574
|
return;
|
|
360
|
-
const names2 = await
|
|
575
|
+
const names2 = await readdir2(dir, { withFileTypes: true }).catch(() => []);
|
|
361
576
|
for (const dirent of names2) {
|
|
362
577
|
if (truncated)
|
|
363
578
|
return;
|
|
364
579
|
if (SEARCH_SKIP.has(dirent.name))
|
|
365
580
|
continue;
|
|
366
|
-
const full =
|
|
581
|
+
const full = path4.join(dir, dirent.name);
|
|
367
582
|
const rel = join(relative, dirent.name);
|
|
368
|
-
const info = await
|
|
583
|
+
const info = await stat2(full).catch(() => null);
|
|
369
584
|
if (!info)
|
|
370
585
|
continue;
|
|
371
586
|
const isDir = info.isDirectory();
|
|
@@ -412,13 +627,13 @@ var ProjectFiles = class {
|
|
|
412
627
|
const walk = async (dir, relative) => {
|
|
413
628
|
if (truncated)
|
|
414
629
|
return;
|
|
415
|
-
const names2 = await
|
|
630
|
+
const names2 = await readdir2(dir, { withFileTypes: true }).catch(() => []);
|
|
416
631
|
for (const dirent of names2) {
|
|
417
632
|
if (truncated)
|
|
418
633
|
return;
|
|
419
634
|
if (SEARCH_SKIP.has(dirent.name) || dirent.isSymbolicLink())
|
|
420
635
|
continue;
|
|
421
|
-
const full =
|
|
636
|
+
const full = path4.join(dir, dirent.name);
|
|
422
637
|
const rel = join(relative, dirent.name);
|
|
423
638
|
if (dirent.isDirectory()) {
|
|
424
639
|
await walk(full, rel);
|
|
@@ -426,10 +641,10 @@ var ProjectFiles = class {
|
|
|
426
641
|
}
|
|
427
642
|
if (!dirent.isFile())
|
|
428
643
|
continue;
|
|
429
|
-
const info = await
|
|
644
|
+
const info = await stat2(full).catch(() => null);
|
|
430
645
|
if (!info || info.size > MAX_FILE)
|
|
431
646
|
continue;
|
|
432
|
-
const buffer = await
|
|
647
|
+
const buffer = await readFile3(full).catch(() => null);
|
|
433
648
|
if (!buffer)
|
|
434
649
|
continue;
|
|
435
650
|
const decoded = decode(buffer);
|
|
@@ -473,7 +688,7 @@ var ProjectFiles = class {
|
|
|
473
688
|
}
|
|
474
689
|
async read(relative) {
|
|
475
690
|
const file = await this.#resolve(relative);
|
|
476
|
-
const info = await
|
|
691
|
+
const info = await stat2(file);
|
|
477
692
|
if (info.isDirectory())
|
|
478
693
|
throw new Error("\u042D\u0442\u043E \u043A\u0430\u0442\u0430\u043B\u043E\u0433, \u0430 \u043D\u0435 \u0444\u0430\u0439\u043B");
|
|
479
694
|
const blank = {
|
|
@@ -486,7 +701,7 @@ var ProjectFiles = class {
|
|
|
486
701
|
binary: false,
|
|
487
702
|
tooLarge: false
|
|
488
703
|
};
|
|
489
|
-
const mediaMime = MEDIA_MIME[
|
|
704
|
+
const mediaMime = MEDIA_MIME[path4.extname(file).toLowerCase()];
|
|
490
705
|
if (mediaMime) {
|
|
491
706
|
if (info.size > MAX_MEDIA)
|
|
492
707
|
return { ...blank, binary: true, mediaMime, mediaTooLarge: true };
|
|
@@ -494,7 +709,7 @@ var ProjectFiles = class {
|
|
|
494
709
|
}
|
|
495
710
|
if (info.size > MAX_FILE)
|
|
496
711
|
return { ...blank, tooLarge: true };
|
|
497
|
-
const buffer = await
|
|
712
|
+
const buffer = await readFile3(file);
|
|
498
713
|
const decoded = decode(buffer);
|
|
499
714
|
if (!decoded)
|
|
500
715
|
return { ...blank, binary: true };
|
|
@@ -517,15 +732,15 @@ var ProjectFiles = class {
|
|
|
517
732
|
*/
|
|
518
733
|
async readMedia(relative) {
|
|
519
734
|
const file = await this.#resolve(relative);
|
|
520
|
-
const mime = MEDIA_MIME[
|
|
735
|
+
const mime = MEDIA_MIME[path4.extname(file).toLowerCase()];
|
|
521
736
|
if (!mime)
|
|
522
737
|
throw new Error("\u0424\u0430\u0439\u043B \u043D\u0435 \u0440\u0430\u0441\u043F\u043E\u0437\u043D\u0430\u043D \u043A\u0430\u043A \u043A\u0430\u0440\u0442\u0438\u043D\u043A\u0430 \u0438\u043B\u0438 \u0432\u0438\u0434\u0435\u043E");
|
|
523
|
-
const info = await
|
|
738
|
+
const info = await stat2(file);
|
|
524
739
|
if (info.isDirectory())
|
|
525
740
|
throw new Error("\u042D\u0442\u043E \u043A\u0430\u0442\u0430\u043B\u043E\u0433, \u0430 \u043D\u0435 \u0444\u0430\u0439\u043B");
|
|
526
741
|
if (info.size > MAX_MEDIA)
|
|
527
742
|
throw new Error("\u0424\u0430\u0439\u043B \u0441\u043B\u0438\u0448\u043A\u043E\u043C \u0432\u0435\u043B\u0438\u043A \u0434\u043B\u044F \u043F\u0440\u043E\u0441\u043C\u043E\u0442\u0440\u0430");
|
|
528
|
-
const buffer = await
|
|
743
|
+
const buffer = await readFile3(file);
|
|
529
744
|
return { mime, base64: buffer.toString("base64") };
|
|
530
745
|
}
|
|
531
746
|
/**
|
|
@@ -538,7 +753,7 @@ var ProjectFiles = class {
|
|
|
538
753
|
*/
|
|
539
754
|
async write(relative, content, eol, encoding, baseMtime, force = false) {
|
|
540
755
|
const file = await this.#resolve(relative);
|
|
541
|
-
const info = await
|
|
756
|
+
const info = await stat2(file).catch(() => null);
|
|
542
757
|
if (info?.isDirectory())
|
|
543
758
|
throw new Error("\u042D\u0442\u043E \u043A\u0430\u0442\u0430\u043B\u043E\u0433, \u0430 \u043D\u0435 \u0444\u0430\u0439\u043B");
|
|
544
759
|
if (!force) {
|
|
@@ -547,29 +762,29 @@ var ProjectFiles = class {
|
|
|
547
762
|
throw new ConflictError(info ? "\u0424\u0430\u0439\u043B \u043D\u0430 \u0434\u0438\u0441\u043A\u0435 \u0438\u0437\u043C\u0435\u043D\u0438\u043B\u0441\u044F \u043F\u043E\u0441\u043B\u0435 \u0442\u043E\u0433\u043E, \u043A\u0430\u043A \u0435\u0433\u043E \u043E\u0442\u043A\u0440\u044B\u043B\u0438 \u0432 \u0440\u0435\u0434\u0430\u043A\u0442\u043E\u0440\u0435" : "\u0424\u0430\u0439\u043B \u043D\u0430 \u0434\u0438\u0441\u043A\u0435 \u0438\u0441\u0447\u0435\u0437 \u043F\u043E\u0441\u043B\u0435 \u0442\u043E\u0433\u043E, \u043A\u0430\u043A \u0435\u0433\u043E \u043E\u0442\u043A\u0440\u044B\u043B\u0438 \u0432 \u0440\u0435\u0434\u0430\u043A\u0442\u043E\u0440\u0435");
|
|
548
763
|
}
|
|
549
764
|
}
|
|
550
|
-
await
|
|
551
|
-
const saved = await
|
|
765
|
+
await writeFile2(file, encode(content, eol, encoding));
|
|
766
|
+
const saved = await stat2(file);
|
|
552
767
|
return { mtime: Math.round(saved.mtimeMs), size: saved.size };
|
|
553
768
|
}
|
|
554
769
|
async create(relative, kind) {
|
|
555
770
|
const target = await this.#resolve(relative);
|
|
556
|
-
if (await
|
|
771
|
+
if (await exists2(target))
|
|
557
772
|
throw new Error("\u0422\u0430\u043A\u043E\u0439 \u0444\u0430\u0439\u043B \u0438\u043B\u0438 \u043A\u0430\u0442\u0430\u043B\u043E\u0433 \u0443\u0436\u0435 \u0435\u0441\u0442\u044C");
|
|
558
773
|
if (kind === "dir") {
|
|
559
|
-
await
|
|
774
|
+
await mkdir2(target, { recursive: true });
|
|
560
775
|
return;
|
|
561
776
|
}
|
|
562
|
-
await
|
|
563
|
-
await
|
|
777
|
+
await mkdir2(path4.dirname(target), { recursive: true });
|
|
778
|
+
await writeFile2(target, "", { encoding: "utf8", flag: "wx" });
|
|
564
779
|
}
|
|
565
780
|
async rename(relative, to) {
|
|
566
781
|
const from = await this.#resolve(relative);
|
|
567
782
|
const target = await this.#resolve(to);
|
|
568
783
|
if (from === target)
|
|
569
784
|
return;
|
|
570
|
-
if (await
|
|
785
|
+
if (await exists2(target))
|
|
571
786
|
throw new Error("\u041F\u043E \u043D\u043E\u0432\u043E\u043C\u0443 \u043F\u0443\u0442\u0438 \u0443\u0436\u0435 \u0447\u0442\u043E-\u0442\u043E \u0435\u0441\u0442\u044C");
|
|
572
|
-
await
|
|
787
|
+
await mkdir2(path4.dirname(target), { recursive: true });
|
|
573
788
|
await renamePath(from, target);
|
|
574
789
|
}
|
|
575
790
|
/**
|
|
@@ -586,7 +801,7 @@ var ProjectFiles = class {
|
|
|
586
801
|
if (!source)
|
|
587
802
|
throw new Error("\u041A\u043E\u043F\u0438\u0440\u043E\u0432\u0430\u0442\u044C \u043A\u043E\u0440\u0435\u043D\u044C \u043F\u0440\u043E\u0435\u043A\u0442\u0430 \u043D\u0435\u043B\u044C\u0437\u044F");
|
|
588
803
|
const from = await this.#resolve(source);
|
|
589
|
-
const info = await
|
|
804
|
+
const info = await stat2(from);
|
|
590
805
|
const dir = normalize(toDir);
|
|
591
806
|
if (info.isDirectory() && (dir === source || dir.startsWith(`${source}/`))) {
|
|
592
807
|
throw new Error("\u041A\u0430\u0442\u0430\u043B\u043E\u0433 \u043D\u0435\u043B\u044C\u0437\u044F \u0441\u043A\u043E\u043F\u0438\u0440\u043E\u0432\u0430\u0442\u044C \u0432\u043D\u0443\u0442\u0440\u044C \u0441\u0430\u043C\u043E\u0433\u043E \u0441\u0435\u0431\u044F");
|
|
@@ -599,10 +814,10 @@ var ProjectFiles = class {
|
|
|
599
814
|
throw new Error("\u041D\u0435\u043A\u0443\u0434\u0430 \u043F\u043E\u043B\u043E\u0436\u0438\u0442\u044C \u043A\u043E\u043F\u0438\u044E: \u0438\u043C\u0435\u043D\u0430 \u0437\u0430\u043D\u044F\u0442\u044B");
|
|
600
815
|
target = join(dir, copyName(name, attempt, info.isDirectory()));
|
|
601
816
|
to = await this.#resolve(target);
|
|
602
|
-
if (!await
|
|
817
|
+
if (!await exists2(to))
|
|
603
818
|
break;
|
|
604
819
|
}
|
|
605
|
-
await
|
|
820
|
+
await mkdir2(path4.dirname(to), { recursive: true });
|
|
606
821
|
await cp(from, to, { recursive: true, errorOnExist: true, force: false });
|
|
607
822
|
return target;
|
|
608
823
|
}
|
|
@@ -622,15 +837,15 @@ var ProjectFiles = class {
|
|
|
622
837
|
*/
|
|
623
838
|
async #resolve(relative) {
|
|
624
839
|
const clean = normalize(relative);
|
|
625
|
-
if (
|
|
840
|
+
if (path4.isAbsolute(clean) || /^[A-Za-z]:/.test(clean)) {
|
|
626
841
|
throw new Error("\u041F\u0443\u0442\u044C \u0434\u043E\u043B\u0436\u0435\u043D \u0431\u044B\u0442\u044C \u043E\u0442\u043D\u043E\u0441\u0438\u0442\u0435\u043B\u044C\u043D\u044B\u043C \u043E\u0442 \u043A\u043E\u0440\u043D\u044F \u043F\u0440\u043E\u0435\u043A\u0442\u0430");
|
|
627
842
|
}
|
|
628
843
|
if (clean.split("/").includes("..")) {
|
|
629
844
|
throw new Error("\u0412\u044B\u0445\u043E\u0434 \u0437\u0430 \u043F\u0440\u0435\u0434\u0435\u043B\u044B \u043A\u0430\u0442\u0430\u043B\u043E\u0433\u0430 \u043F\u0440\u043E\u0435\u043A\u0442\u0430 \u0437\u0430\u043F\u0440\u0435\u0449\u0451\u043D");
|
|
630
845
|
}
|
|
631
846
|
const root = this.#root ??= await realpath(this.cwd);
|
|
632
|
-
const target =
|
|
633
|
-
const probe = await
|
|
847
|
+
const target = path4.resolve(root, clean);
|
|
848
|
+
const probe = await exists2(target) ? target : path4.dirname(target);
|
|
634
849
|
const real = await realpath(probe).catch(() => probe);
|
|
635
850
|
if (!contains(root, real)) {
|
|
636
851
|
throw new Error("\u0412\u044B\u0445\u043E\u0434 \u0437\u0430 \u043F\u0440\u0435\u0434\u0435\u043B\u044B \u043A\u0430\u0442\u0430\u043B\u043E\u0433\u0430 \u043F\u0440\u043E\u0435\u043A\u0442\u0430 \u0437\u0430\u043F\u0440\u0435\u0449\u0451\u043D");
|
|
@@ -651,11 +866,11 @@ function join(dir, name) {
|
|
|
651
866
|
function contains(root, target) {
|
|
652
867
|
if (target === root)
|
|
653
868
|
return true;
|
|
654
|
-
const prefix = root.endsWith(
|
|
869
|
+
const prefix = root.endsWith(path4.sep) ? root : root + path4.sep;
|
|
655
870
|
return process.platform === "win32" ? target.toLowerCase().startsWith(prefix.toLowerCase()) : target.startsWith(prefix);
|
|
656
871
|
}
|
|
657
|
-
async function
|
|
658
|
-
return
|
|
872
|
+
async function exists2(file) {
|
|
873
|
+
return lstat2(file).then(() => true, () => false);
|
|
659
874
|
}
|
|
660
875
|
var COPY_NAME_LIMIT = 200;
|
|
661
876
|
function copyName(name, attempt, isDir) {
|
|
@@ -955,16 +1170,16 @@ function interfacesSignature() {
|
|
|
955
1170
|
}
|
|
956
1171
|
|
|
957
1172
|
// ../host/dist/settings.js
|
|
958
|
-
import { readFile as
|
|
959
|
-
import { homedir as
|
|
960
|
-
import
|
|
961
|
-
var USER_SETTINGS =
|
|
962
|
-
var PROJECT_SETTINGS =
|
|
963
|
-
var LOCAL_SETTINGS =
|
|
1173
|
+
import { readFile as readFile4 } from "node:fs/promises";
|
|
1174
|
+
import { homedir as homedir3 } from "node:os";
|
|
1175
|
+
import path5 from "node:path";
|
|
1176
|
+
var USER_SETTINGS = path5.join(homedir3(), ".claude", "settings.json");
|
|
1177
|
+
var PROJECT_SETTINGS = path5.join(".claude", "settings.json");
|
|
1178
|
+
var LOCAL_SETTINGS = path5.join(".claude", "settings.local.json");
|
|
964
1179
|
function managedSettingsPath() {
|
|
965
1180
|
switch (process.platform) {
|
|
966
1181
|
case "win32":
|
|
967
|
-
return
|
|
1182
|
+
return path5.join(process.env.PROGRAMDATA ?? "C:\\ProgramData", "ClaudeCode", "managed-settings.json");
|
|
968
1183
|
case "darwin":
|
|
969
1184
|
return "/Library/Application Support/ClaudeCode/managed-settings.json";
|
|
970
1185
|
default:
|
|
@@ -975,8 +1190,8 @@ var EFFORT_LEVELS = ["low", "medium", "high", "xhigh", "max"];
|
|
|
975
1190
|
async function readConfiguredDefaults(cwd) {
|
|
976
1191
|
const files = [
|
|
977
1192
|
USER_SETTINGS,
|
|
978
|
-
|
|
979
|
-
|
|
1193
|
+
path5.join(cwd, PROJECT_SETTINGS),
|
|
1194
|
+
path5.join(cwd, LOCAL_SETTINGS),
|
|
980
1195
|
managedSettingsPath()
|
|
981
1196
|
];
|
|
982
1197
|
const result = {
|
|
@@ -1022,7 +1237,7 @@ async function readConfiguredDefaults(cwd) {
|
|
|
1022
1237
|
}
|
|
1023
1238
|
async function readSettings(file) {
|
|
1024
1239
|
try {
|
|
1025
|
-
const parsed = JSON.parse(await
|
|
1240
|
+
const parsed = JSON.parse(await readFile4(file, "utf8"));
|
|
1026
1241
|
return parsed && typeof parsed === "object" ? parsed : null;
|
|
1027
1242
|
} catch {
|
|
1028
1243
|
return null;
|
|
@@ -1037,10 +1252,10 @@ var CUT = "\n\u2026 (\u043E\u0431\u0440\u0435\u0437\u0430\u043D\u043E)";
|
|
|
1037
1252
|
async function readTranscript(sessionId, options2) {
|
|
1038
1253
|
let messages;
|
|
1039
1254
|
try {
|
|
1040
|
-
messages = await getSessionMessages(sessionId, {
|
|
1255
|
+
messages = await withConfigDir(options2.configDir ?? null, () => getSessionMessages(sessionId, {
|
|
1041
1256
|
dir: options2.dir,
|
|
1042
1257
|
includeSystemMessages: true
|
|
1043
|
-
});
|
|
1258
|
+
}));
|
|
1044
1259
|
} catch {
|
|
1045
1260
|
return [];
|
|
1046
1261
|
}
|
|
@@ -1118,10 +1333,10 @@ async function readTranscript(sessionId, options2) {
|
|
|
1118
1333
|
}
|
|
1119
1334
|
return entries;
|
|
1120
1335
|
}
|
|
1121
|
-
async function locateResumePoint(sessionId, dir, userIndex) {
|
|
1336
|
+
async function locateResumePoint(sessionId, dir, userIndex, configDir = null) {
|
|
1122
1337
|
let messages;
|
|
1123
1338
|
try {
|
|
1124
|
-
messages = await getSessionMessages(sessionId, { dir, includeSystemMessages: true });
|
|
1339
|
+
messages = await withConfigDir(configDir, () => getSessionMessages(sessionId, { dir, includeSystemMessages: true }));
|
|
1125
1340
|
} catch {
|
|
1126
1341
|
return null;
|
|
1127
1342
|
}
|
|
@@ -1553,7 +1768,7 @@ var ClaudeSession = class extends EventEmitter2 {
|
|
|
1553
1768
|
constructor(options2) {
|
|
1554
1769
|
super();
|
|
1555
1770
|
this.#options = options2;
|
|
1556
|
-
this.id = options2.resume && !options2.fork ? options2.resume :
|
|
1771
|
+
this.id = options2.resume && !options2.fork ? options2.resume : randomUUID2();
|
|
1557
1772
|
this.workspaceId = options2.workspaceId;
|
|
1558
1773
|
this.cwd = options2.cwd;
|
|
1559
1774
|
this.#permissionMode = options2.permissionMode ?? "default";
|
|
@@ -1573,6 +1788,13 @@ var ClaudeSession = class extends EventEmitter2 {
|
|
|
1573
1788
|
get claudeSessionId() {
|
|
1574
1789
|
return this.#claudeSessionId;
|
|
1575
1790
|
}
|
|
1791
|
+
get accountId() {
|
|
1792
|
+
return this.#options.accountId ?? MAIN_ACCOUNT_ID;
|
|
1793
|
+
}
|
|
1794
|
+
/** Каталог конфигурации аккаунта сессии; null — унаследованный хостом. */
|
|
1795
|
+
get configDir() {
|
|
1796
|
+
return this.#options.configDir ?? null;
|
|
1797
|
+
}
|
|
1576
1798
|
/** Боковая сессия («вопрос на полях») — у неё есть родитель и нет прав на запись. */
|
|
1577
1799
|
get parentSessionId() {
|
|
1578
1800
|
return this.#options.parentSessionId ?? null;
|
|
@@ -1603,6 +1825,7 @@ var ClaudeSession = class extends EventEmitter2 {
|
|
|
1603
1825
|
workspaceId: this.workspaceId,
|
|
1604
1826
|
cwd: this.cwd,
|
|
1605
1827
|
parentSessionId: this.parentSessionId,
|
|
1828
|
+
accountId: this.#options.accountId ?? MAIN_ACCOUNT_ID,
|
|
1606
1829
|
title: this.#title,
|
|
1607
1830
|
state: this.#state,
|
|
1608
1831
|
lastTurn: this.#lastTurn,
|
|
@@ -1630,7 +1853,11 @@ var ClaudeSession = class extends EventEmitter2 {
|
|
|
1630
1853
|
throw new Error("session already started");
|
|
1631
1854
|
if (this.#options.resume && !this.#options.fork) {
|
|
1632
1855
|
const until = Date.now();
|
|
1633
|
-
this.#history = readTranscript(this.#options.resume, {
|
|
1856
|
+
this.#history = readTranscript(this.#options.resume, {
|
|
1857
|
+
dir: this.cwd,
|
|
1858
|
+
until,
|
|
1859
|
+
configDir: this.#options.configDir ?? null
|
|
1860
|
+
});
|
|
1634
1861
|
}
|
|
1635
1862
|
this.#spawn(false);
|
|
1636
1863
|
}
|
|
@@ -1696,6 +1923,8 @@ var ClaudeSession = class extends EventEmitter2 {
|
|
|
1696
1923
|
if (this.#executable.executable)
|
|
1697
1924
|
options2.executable = this.#executable.executable;
|
|
1698
1925
|
}
|
|
1926
|
+
if (this.#options.configDir)
|
|
1927
|
+
options2.env = accountEnv(this.#options.configDir);
|
|
1699
1928
|
if (this.#model)
|
|
1700
1929
|
options2.model = this.#model;
|
|
1701
1930
|
if (resumeAt !== null) {
|
|
@@ -2018,7 +2247,7 @@ var ClaudeSession = class extends EventEmitter2 {
|
|
|
2018
2247
|
if (this.#state === "running")
|
|
2019
2248
|
await this.interrupt();
|
|
2020
2249
|
const source = this.#claudeSessionId ?? this.#options.resume;
|
|
2021
|
-
const anchor = source ? await locateResumePoint(source, this.cwd, userIndex) : null;
|
|
2250
|
+
const anchor = source ? await locateResumePoint(source, this.cwd, userIndex, this.#options.configDir ?? null) : null;
|
|
2022
2251
|
if (!anchor) {
|
|
2023
2252
|
this.#record({
|
|
2024
2253
|
kind: "error",
|
|
@@ -2456,7 +2685,8 @@ var ClaudeSession = class extends EventEmitter2 {
|
|
|
2456
2685
|
return;
|
|
2457
2686
|
}
|
|
2458
2687
|
try {
|
|
2459
|
-
|
|
2688
|
+
const id = this.#claudeSessionId;
|
|
2689
|
+
await withConfigDir(this.#options.configDir ?? null, () => renameSession(id, title, { dir: this.cwd }));
|
|
2460
2690
|
this.#unpersistedTitle = null;
|
|
2461
2691
|
} catch (error) {
|
|
2462
2692
|
this.#unpersistedTitle = title;
|
|
@@ -2506,7 +2736,7 @@ var ClaudeSession = class extends EventEmitter2 {
|
|
|
2506
2736
|
const target = writeTarget(input.tool_input);
|
|
2507
2737
|
if (!target)
|
|
2508
2738
|
return pass;
|
|
2509
|
-
const absolute =
|
|
2739
|
+
const absolute = path6.resolve(this.cwd, target);
|
|
2510
2740
|
if (roots.some((root) => contains(root, absolute)))
|
|
2511
2741
|
return pass;
|
|
2512
2742
|
return {
|
|
@@ -2562,7 +2792,7 @@ var ClaudeSession = class extends EventEmitter2 {
|
|
|
2562
2792
|
message: "\u0411\u043E\u043A\u043E\u0432\u0430\u044F \u0441\u0435\u0441\u0441\u0438\u044F \u0440\u0430\u0431\u043E\u0442\u0430\u0435\u0442 \u0442\u043E\u043B\u044C\u043A\u043E \u043D\u0430 \u0447\u0442\u0435\u043D\u0438\u0435"
|
|
2563
2793
|
});
|
|
2564
2794
|
}
|
|
2565
|
-
const requestId =
|
|
2795
|
+
const requestId = randomUUID2();
|
|
2566
2796
|
const questions = toolName === ASK_QUESTION_TOOL ? parseQuestions(input) : null;
|
|
2567
2797
|
return new Promise((resolve) => {
|
|
2568
2798
|
this.#pendingPermissions.set(requestId, { resolve, toolName, input, questions });
|
|
@@ -3134,32 +3364,32 @@ function contentToText2(content) {
|
|
|
3134
3364
|
// ../host/dist/antigravity-session.js
|
|
3135
3365
|
import { EventEmitter as EventEmitter3 } from "node:events";
|
|
3136
3366
|
import { spawn as spawn2, execFile as execFile3 } from "node:child_process";
|
|
3137
|
-
import { randomUUID as
|
|
3138
|
-
import { mkdir as
|
|
3367
|
+
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
3368
|
+
import { mkdir as mkdir3, writeFile as writeFile3 } from "node:fs/promises";
|
|
3139
3369
|
import { tmpdir } from "node:os";
|
|
3140
|
-
import
|
|
3370
|
+
import path8 from "node:path";
|
|
3141
3371
|
import { createInterface } from "node:readline";
|
|
3142
3372
|
|
|
3143
3373
|
// ../host/dist/antigravity-cli.js
|
|
3144
3374
|
import { execFile as execFile2 } from "node:child_process";
|
|
3145
3375
|
import { existsSync } from "node:fs";
|
|
3146
|
-
import { homedir as
|
|
3147
|
-
import
|
|
3376
|
+
import { homedir as homedir4 } from "node:os";
|
|
3377
|
+
import path7 from "node:path";
|
|
3148
3378
|
function agyExecutable() {
|
|
3149
3379
|
const forced = process.env.CCV_AGY_PATH;
|
|
3150
3380
|
if (forced && existsSync(forced))
|
|
3151
3381
|
return forced;
|
|
3152
3382
|
const names2 = process.platform === "win32" ? ["agy.exe", "agy"] : ["agy"];
|
|
3153
|
-
const dirs = (process.env.PATH ?? "").split(
|
|
3383
|
+
const dirs = (process.env.PATH ?? "").split(path7.delimiter).filter(Boolean);
|
|
3154
3384
|
if (process.platform === "win32") {
|
|
3155
|
-
const local = process.env.LOCALAPPDATA ??
|
|
3156
|
-
dirs.push(
|
|
3385
|
+
const local = process.env.LOCALAPPDATA ?? path7.join(homedir4(), "AppData", "Local");
|
|
3386
|
+
dirs.push(path7.join(local, "agy", "bin"));
|
|
3157
3387
|
} else {
|
|
3158
|
-
dirs.push(
|
|
3388
|
+
dirs.push(path7.join(homedir4(), ".local", "bin"), "/usr/local/bin", "/opt/homebrew/bin");
|
|
3159
3389
|
}
|
|
3160
3390
|
for (const dir of dirs) {
|
|
3161
3391
|
for (const name of names2) {
|
|
3162
|
-
const candidate =
|
|
3392
|
+
const candidate = path7.join(dir, name);
|
|
3163
3393
|
if (existsSync(candidate))
|
|
3164
3394
|
return candidate;
|
|
3165
3395
|
}
|
|
@@ -3395,7 +3625,7 @@ var AntigravitySession = class extends EventEmitter3 {
|
|
|
3395
3625
|
this.cwd = options2.cwd;
|
|
3396
3626
|
const now = Date.now();
|
|
3397
3627
|
this.#record = options2.record ? { ...options2.record } : {
|
|
3398
|
-
id:
|
|
3628
|
+
id: randomUUID3(),
|
|
3399
3629
|
conversationId: null,
|
|
3400
3630
|
workspaceId: options2.workspaceId,
|
|
3401
3631
|
cwd: options2.cwd,
|
|
@@ -3461,7 +3691,8 @@ var AntigravitySession = class extends EventEmitter3 {
|
|
|
3461
3691
|
createdAt: this.#record.createdAt,
|
|
3462
3692
|
updatedAt: this.#updatedAt,
|
|
3463
3693
|
lastSeq: this.journal.lastSeq,
|
|
3464
|
-
totalCostUsd: 0
|
|
3694
|
+
totalCostUsd: 0,
|
|
3695
|
+
accountId: MAIN_ACCOUNT_ID
|
|
3465
3696
|
};
|
|
3466
3697
|
}
|
|
3467
3698
|
// -------------------------------------------------------------------------
|
|
@@ -3769,7 +4000,7 @@ var AntigravitySession = class extends EventEmitter3 {
|
|
|
3769
4000
|
if (this.#closing)
|
|
3770
4001
|
return;
|
|
3771
4002
|
if (reply)
|
|
3772
|
-
this.#record_({ kind: "assistant.text", text: reply, blockId: `cmd:${
|
|
4003
|
+
this.#record_({ kind: "assistant.text", text: reply, blockId: `cmd:${randomUUID3()}` });
|
|
3773
4004
|
if (error)
|
|
3774
4005
|
this.#record_({ kind: "error", message: error });
|
|
3775
4006
|
if (turnRunning || this.#pendingTurns > 0)
|
|
@@ -3825,13 +4056,13 @@ var AntigravitySession = class extends EventEmitter3 {
|
|
|
3825
4056
|
async #composePrompt(text, images) {
|
|
3826
4057
|
if (!images || images.length === 0)
|
|
3827
4058
|
return text;
|
|
3828
|
-
const dir =
|
|
3829
|
-
await
|
|
4059
|
+
const dir = path8.join(tmpdir(), "ccv-antigravity", this.id);
|
|
4060
|
+
await mkdir3(dir, { recursive: true });
|
|
3830
4061
|
const paths = [];
|
|
3831
4062
|
for (const image of images) {
|
|
3832
4063
|
const ext = image.mediaType.split("/")[1] === "jpeg" ? "jpg" : image.mediaType.split("/")[1];
|
|
3833
|
-
const file =
|
|
3834
|
-
await
|
|
4064
|
+
const file = path8.join(dir, `${randomUUID3()}.${ext}`);
|
|
4065
|
+
await writeFile3(file, Buffer.from(image.data, "base64"));
|
|
3835
4066
|
paths.push(file);
|
|
3836
4067
|
}
|
|
3837
4068
|
return `${text}
|
|
@@ -4218,8 +4449,8 @@ function describe2(error) {
|
|
|
4218
4449
|
}
|
|
4219
4450
|
|
|
4220
4451
|
// ../host/dist/antigravity-store.js
|
|
4221
|
-
import { appendFile, mkdir as
|
|
4222
|
-
import
|
|
4452
|
+
import { appendFile, mkdir as mkdir4, readFile as readFile5, rm as rm2, writeFile as writeFile4 } from "node:fs/promises";
|
|
4453
|
+
import path9 from "node:path";
|
|
4223
4454
|
var AntigravityStore = class {
|
|
4224
4455
|
#dir;
|
|
4225
4456
|
#file;
|
|
@@ -4227,13 +4458,13 @@ var AntigravityStore = class {
|
|
|
4227
4458
|
#loaded = null;
|
|
4228
4459
|
#writing = Promise.resolve();
|
|
4229
4460
|
constructor(dataDir) {
|
|
4230
|
-
this.#dir =
|
|
4231
|
-
this.#file =
|
|
4461
|
+
this.#dir = path9.join(dataDir, "antigravity");
|
|
4462
|
+
this.#file = path9.join(this.#dir, "sessions.json");
|
|
4232
4463
|
}
|
|
4233
4464
|
#load() {
|
|
4234
4465
|
this.#loaded ??= (async () => {
|
|
4235
4466
|
try {
|
|
4236
|
-
const raw = JSON.parse(await
|
|
4467
|
+
const raw = JSON.parse(await readFile5(this.#file, "utf8"));
|
|
4237
4468
|
for (const record of Array.isArray(raw) ? raw : []) {
|
|
4238
4469
|
if (record && typeof record.id === "string")
|
|
4239
4470
|
this.#records.set(record.id, record);
|
|
@@ -4299,7 +4530,7 @@ var AntigravityStore = class {
|
|
|
4299
4530
|
return this.#writing;
|
|
4300
4531
|
const lines = events.map((e) => JSON.stringify(e)).join("\n") + "\n";
|
|
4301
4532
|
return this.#enqueue(async () => {
|
|
4302
|
-
await
|
|
4533
|
+
await mkdir4(this.#dir, { recursive: true });
|
|
4303
4534
|
await appendFile(this.#eventsFile(id), lines, "utf8");
|
|
4304
4535
|
});
|
|
4305
4536
|
}
|
|
@@ -4308,7 +4539,7 @@ var AntigravityStore = class {
|
|
|
4308
4539
|
await this.#writing;
|
|
4309
4540
|
let raw;
|
|
4310
4541
|
try {
|
|
4311
|
-
raw = await
|
|
4542
|
+
raw = await readFile5(this.#eventsFile(id), "utf8");
|
|
4312
4543
|
} catch {
|
|
4313
4544
|
return [];
|
|
4314
4545
|
}
|
|
@@ -4325,13 +4556,13 @@ var AntigravityStore = class {
|
|
|
4325
4556
|
return entries;
|
|
4326
4557
|
}
|
|
4327
4558
|
#eventsFile(id) {
|
|
4328
|
-
return
|
|
4559
|
+
return path9.join(this.#dir, `${id.replace(/[^\w-]/g, "_")}.jsonl`);
|
|
4329
4560
|
}
|
|
4330
4561
|
#persist() {
|
|
4331
4562
|
const snapshot = JSON.stringify([...this.#records.values()], null, 2);
|
|
4332
4563
|
return this.#enqueue(async () => {
|
|
4333
|
-
await
|
|
4334
|
-
await
|
|
4564
|
+
await mkdir4(this.#dir, { recursive: true });
|
|
4565
|
+
await writeFile4(this.#file, snapshot, "utf8");
|
|
4335
4566
|
});
|
|
4336
4567
|
}
|
|
4337
4568
|
/** Записи на диск — строго по очереди: две параллельные испортили бы файл. */
|
|
@@ -4346,9 +4577,9 @@ var AntigravityStore = class {
|
|
|
4346
4577
|
|
|
4347
4578
|
// ../host/dist/git.js
|
|
4348
4579
|
import { execFile as execFile4 } from "node:child_process";
|
|
4349
|
-
import { mkdtemp, readFile as
|
|
4580
|
+
import { mkdtemp, readFile as readFile6, rm as rm3, writeFile as writeFile5 } from "node:fs/promises";
|
|
4350
4581
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
4351
|
-
import
|
|
4582
|
+
import path10 from "node:path";
|
|
4352
4583
|
var TIMEOUT_MS = 2e4;
|
|
4353
4584
|
var NET_TIMEOUT_MS = 5 * 6e4;
|
|
4354
4585
|
var MAX_BUFFER = 32 * 1024 * 1024;
|
|
@@ -4664,7 +4895,7 @@ var GitRepo = class {
|
|
|
4664
4895
|
* важнее всего (см. `checkIgnored`).
|
|
4665
4896
|
*/
|
|
4666
4897
|
async #withoutRepo(args) {
|
|
4667
|
-
const dir = await mkdtemp(
|
|
4898
|
+
const dir = await mkdtemp(path10.join(tmpdir2(), "ccv-git-"));
|
|
4668
4899
|
try {
|
|
4669
4900
|
await this.#run(["init", "--bare", "--quiet", dir]);
|
|
4670
4901
|
return await this.#soft([`--git-dir=${dir}`, `--work-tree=${this.cwd}`, ...args]);
|
|
@@ -4710,14 +4941,14 @@ var GitRepo = class {
|
|
|
4710
4941
|
* исключил. Повторы отсеиваются, чтобы файл не рос от каждой публикации.
|
|
4711
4942
|
*/
|
|
4712
4943
|
async #appendGitignore(paths) {
|
|
4713
|
-
const file =
|
|
4714
|
-
const existing = await
|
|
4944
|
+
const file = path10.join(this.cwd, ".gitignore");
|
|
4945
|
+
const existing = await readFile6(file, "utf8").catch(() => "");
|
|
4715
4946
|
const known = new Set(existing.split(/\r?\n/).map((line) => line.trim()));
|
|
4716
4947
|
const lines = paths.map(ignorePattern).filter((line) => !known.has(line));
|
|
4717
4948
|
if (lines.length === 0)
|
|
4718
4949
|
return;
|
|
4719
4950
|
const prefix = existing === "" || existing.endsWith("\n") ? "" : "\n";
|
|
4720
|
-
await
|
|
4951
|
+
await writeFile5(file, `${existing}${prefix}${lines.join("\n")}
|
|
4721
4952
|
`, "utf8");
|
|
4722
4953
|
}
|
|
4723
4954
|
/** Команда, чей провал — обычное дело (нет upstream, нет коммитов, detached). */
|
|
@@ -4916,9 +5147,9 @@ function parsePatch(raw) {
|
|
|
4916
5147
|
body = "";
|
|
4917
5148
|
}
|
|
4918
5149
|
total += body.length;
|
|
4919
|
-
const
|
|
5150
|
+
const path26 = status === "deleted" ? oldPath : newPath || oldPath;
|
|
4920
5151
|
files.push({
|
|
4921
|
-
path:
|
|
5152
|
+
path: path26,
|
|
4922
5153
|
oldPath: status === "renamed" ? oldPath : "",
|
|
4923
5154
|
status,
|
|
4924
5155
|
added: count(body, "+"),
|
|
@@ -4930,10 +5161,10 @@ function parsePatch(raw) {
|
|
|
4930
5161
|
return { files, truncated };
|
|
4931
5162
|
}
|
|
4932
5163
|
function stripPrefix(value) {
|
|
4933
|
-
const
|
|
4934
|
-
if (
|
|
5164
|
+
const path26 = unquote(value.trim());
|
|
5165
|
+
if (path26 === "/dev/null")
|
|
4935
5166
|
return "";
|
|
4936
|
-
return
|
|
5167
|
+
return path26.replace(/^[ab]\//, "");
|
|
4937
5168
|
}
|
|
4938
5169
|
function count(body, mark) {
|
|
4939
5170
|
let n = 0;
|
|
@@ -4946,8 +5177,8 @@ function count(body, mark) {
|
|
|
4946
5177
|
|
|
4947
5178
|
// ../host/dist/github.js
|
|
4948
5179
|
import { execFile as execFile5 } from "node:child_process";
|
|
4949
|
-
import { mkdir as
|
|
4950
|
-
import
|
|
5180
|
+
import { mkdir as mkdir5, readFile as readFile7, writeFile as writeFile6 } from "node:fs/promises";
|
|
5181
|
+
import path11 from "node:path";
|
|
4951
5182
|
var API = "https://api.github.com";
|
|
4952
5183
|
var API_VERSION = "2022-11-28";
|
|
4953
5184
|
var API_TIMEOUT_MS = 2e4;
|
|
@@ -4968,11 +5199,11 @@ var GitHubAccount = class {
|
|
|
4968
5199
|
*/
|
|
4969
5200
|
#ghInstalled = null;
|
|
4970
5201
|
constructor(dataDir) {
|
|
4971
|
-
this.#storePath =
|
|
5202
|
+
this.#storePath = path11.join(dataDir, "github.json");
|
|
4972
5203
|
}
|
|
4973
5204
|
async load() {
|
|
4974
5205
|
try {
|
|
4975
|
-
const raw = JSON.parse(await
|
|
5206
|
+
const raw = JSON.parse(await readFile7(this.#storePath, "utf8"));
|
|
4976
5207
|
const token = raw.token;
|
|
4977
5208
|
this.#token = typeof token === "string" ? token.trim() : "";
|
|
4978
5209
|
} catch {
|
|
@@ -4982,8 +5213,8 @@ var GitHubAccount = class {
|
|
|
4982
5213
|
/** Сохранить токен или стереть его пустой строкой. */
|
|
4983
5214
|
async setToken(token) {
|
|
4984
5215
|
this.#token = token.trim();
|
|
4985
|
-
await
|
|
4986
|
-
await
|
|
5216
|
+
await mkdir5(path11.dirname(this.#storePath), { recursive: true });
|
|
5217
|
+
await writeFile6(this.#storePath, JSON.stringify({ token: this.#token }, null, 2), {
|
|
4987
5218
|
encoding: "utf8",
|
|
4988
5219
|
mode: 384
|
|
4989
5220
|
});
|
|
@@ -5176,9 +5407,9 @@ function describe4(error) {
|
|
|
5176
5407
|
|
|
5177
5408
|
// ../host/dist/finder.js
|
|
5178
5409
|
import { existsSync as existsSync2, statSync } from "node:fs";
|
|
5179
|
-
import { readdir as
|
|
5410
|
+
import { readdir as readdir3 } from "node:fs/promises";
|
|
5180
5411
|
import os2 from "node:os";
|
|
5181
|
-
import
|
|
5412
|
+
import path12 from "node:path";
|
|
5182
5413
|
import { listSessions } from "@anthropic-ai/claude-agent-sdk";
|
|
5183
5414
|
var CACHE_TTL = 6e4;
|
|
5184
5415
|
var FIND_LIMIT = 50;
|
|
@@ -5186,12 +5417,14 @@ var ROOT_LIMIT = 5;
|
|
|
5186
5417
|
var SKIP_NAMES = /* @__PURE__ */ new Set(["node_modules", ".git", "dist", "build", ".next", "venv"]);
|
|
5187
5418
|
var ProjectFinder = class {
|
|
5188
5419
|
registry;
|
|
5420
|
+
configDirs;
|
|
5189
5421
|
#dirs = [];
|
|
5190
5422
|
#loadedAt = 0;
|
|
5191
5423
|
/** Обновление уже идёт: второй `listSessions()` параллельно первому не нужен. */
|
|
5192
5424
|
#refreshing = null;
|
|
5193
|
-
constructor(registry) {
|
|
5425
|
+
constructor(registry, configDirs = () => [null]) {
|
|
5194
5426
|
this.registry = registry;
|
|
5427
|
+
this.configDirs = configDirs;
|
|
5195
5428
|
}
|
|
5196
5429
|
/**
|
|
5197
5430
|
* Прогреть кэш при старте хоста.
|
|
@@ -5217,7 +5450,7 @@ var ProjectFinder = class {
|
|
|
5217
5450
|
if (needles.length === 0)
|
|
5218
5451
|
return { candidates: [], truncated: false };
|
|
5219
5452
|
const open = new Map(this.registry.list().map((workspace) => [workspace.path.toLowerCase(), workspace]));
|
|
5220
|
-
const byName = this.#dirs.filter((dir) => matches(
|
|
5453
|
+
const byName = this.#dirs.filter((dir) => matches(path12.basename(dir.path), needles));
|
|
5221
5454
|
const matched = byName.length > 0 ? byName : this.#dirs.filter((dir) => matches(dir.path, needles));
|
|
5222
5455
|
const sorted = [...matched].sort((a, b) => {
|
|
5223
5456
|
const aOpen = open.has(a.path.toLowerCase());
|
|
@@ -5228,7 +5461,7 @@ var ProjectFinder = class {
|
|
|
5228
5461
|
return a.sessions > 0 ? -1 : 1;
|
|
5229
5462
|
if (a.lastUsedAt !== b.lastUsedAt)
|
|
5230
5463
|
return b.lastUsedAt - a.lastUsedAt;
|
|
5231
|
-
return
|
|
5464
|
+
return path12.basename(a.path).localeCompare(path12.basename(b.path), void 0, {
|
|
5232
5465
|
numeric: true,
|
|
5233
5466
|
sensitivity: "base"
|
|
5234
5467
|
});
|
|
@@ -5236,7 +5469,7 @@ var ProjectFinder = class {
|
|
|
5236
5469
|
return {
|
|
5237
5470
|
candidates: sorted.slice(0, FIND_LIMIT).map((dir) => ({
|
|
5238
5471
|
path: dir.path,
|
|
5239
|
-
name:
|
|
5472
|
+
name: path12.basename(dir.path) || dir.path,
|
|
5240
5473
|
sessions: dir.sessions,
|
|
5241
5474
|
lastUsedAt: dir.lastUsedAt || null,
|
|
5242
5475
|
open: open.has(dir.path.toLowerCase()),
|
|
@@ -5260,18 +5493,18 @@ var ProjectFinder = class {
|
|
|
5260
5493
|
const candidates = [];
|
|
5261
5494
|
for (const entry of named) {
|
|
5262
5495
|
const absolute = entry.path.trim();
|
|
5263
|
-
if (!absolute || !
|
|
5496
|
+
if (!absolute || !path12.isAbsolute(absolute))
|
|
5264
5497
|
continue;
|
|
5265
5498
|
const key = absolute.toLowerCase();
|
|
5266
5499
|
if (seen.has(key))
|
|
5267
5500
|
continue;
|
|
5268
|
-
if (!
|
|
5501
|
+
if (!isDirectory2(absolute))
|
|
5269
5502
|
continue;
|
|
5270
5503
|
seen.add(key);
|
|
5271
5504
|
const record = known.get(key);
|
|
5272
5505
|
candidates.push({
|
|
5273
5506
|
path: record?.path ?? absolute,
|
|
5274
|
-
name:
|
|
5507
|
+
name: path12.basename(absolute) || absolute,
|
|
5275
5508
|
sessions: record?.sessions ?? 0,
|
|
5276
5509
|
lastUsedAt: record?.lastUsedAt || null,
|
|
5277
5510
|
open: open.has(key),
|
|
@@ -5306,7 +5539,7 @@ var ProjectFinder = class {
|
|
|
5306
5539
|
lastUsedAt: 0
|
|
5307
5540
|
});
|
|
5308
5541
|
}
|
|
5309
|
-
for (const info of await allSessions()) {
|
|
5542
|
+
for (const info of await allSessions(this.configDirs())) {
|
|
5310
5543
|
const cwd = info.cwd;
|
|
5311
5544
|
if (!cwd || !usable(cwd))
|
|
5312
5545
|
continue;
|
|
@@ -5323,12 +5556,12 @@ var ProjectFinder = class {
|
|
|
5323
5556
|
dirs.set(key, { path: cwd, sessions: 1, lastUsedAt: info.lastModified });
|
|
5324
5557
|
}
|
|
5325
5558
|
for (const parent of this.#parents(dirs.values())) {
|
|
5326
|
-
const names2 = await
|
|
5559
|
+
const names2 = await readdir3(parent, { withFileTypes: true }).catch(() => []);
|
|
5327
5560
|
for (const dirent of names2) {
|
|
5328
5561
|
if (!dirent.isDirectory() || SKIP_NAMES.has(dirent.name) || dirent.name.startsWith(".")) {
|
|
5329
5562
|
continue;
|
|
5330
5563
|
}
|
|
5331
|
-
const full =
|
|
5564
|
+
const full = path12.join(parent, dirent.name);
|
|
5332
5565
|
const key = full.toLowerCase();
|
|
5333
5566
|
if (dirs.has(key))
|
|
5334
5567
|
continue;
|
|
@@ -5349,7 +5582,7 @@ var ProjectFinder = class {
|
|
|
5349
5582
|
#parents(dirs) {
|
|
5350
5583
|
const counted = /* @__PURE__ */ new Map();
|
|
5351
5584
|
for (const dir of dirs) {
|
|
5352
|
-
const parent =
|
|
5585
|
+
const parent = path12.dirname(dir.path);
|
|
5353
5586
|
if (parent === dir.path || !usable(parent))
|
|
5354
5587
|
continue;
|
|
5355
5588
|
const key = parent.toLowerCase();
|
|
@@ -5372,19 +5605,22 @@ function matches(value, needles) {
|
|
|
5372
5605
|
const flat = value.toLowerCase().replace(/[^a-z0-9а-яё]+/gi, "");
|
|
5373
5606
|
return needles.every((needle) => flat.includes(needle));
|
|
5374
5607
|
}
|
|
5375
|
-
function
|
|
5608
|
+
function isDirectory2(dir) {
|
|
5376
5609
|
try {
|
|
5377
5610
|
return statSync(dir).isDirectory();
|
|
5378
5611
|
} catch {
|
|
5379
5612
|
return false;
|
|
5380
5613
|
}
|
|
5381
5614
|
}
|
|
5382
|
-
async function allSessions() {
|
|
5383
|
-
|
|
5384
|
-
|
|
5385
|
-
|
|
5386
|
-
|
|
5615
|
+
async function allSessions(configDirs) {
|
|
5616
|
+
const all = [];
|
|
5617
|
+
for (const dir of configDirs) {
|
|
5618
|
+
try {
|
|
5619
|
+
all.push(...await withConfigDir(dir, () => listSessions()));
|
|
5620
|
+
} catch {
|
|
5621
|
+
}
|
|
5387
5622
|
}
|
|
5623
|
+
return all;
|
|
5388
5624
|
}
|
|
5389
5625
|
var FINDER_SCHEMA = {
|
|
5390
5626
|
type: "object",
|
|
@@ -5461,18 +5697,18 @@ function fromText(text) {
|
|
|
5461
5697
|
|
|
5462
5698
|
// ../host/dist/workspaces.js
|
|
5463
5699
|
import { existsSync as existsSync3, statSync as statSync2 } from "node:fs";
|
|
5464
|
-
import { mkdir as
|
|
5465
|
-
import
|
|
5700
|
+
import { mkdir as mkdir6, readFile as readFile8, writeFile as writeFile7 } from "node:fs/promises";
|
|
5701
|
+
import path13 from "node:path";
|
|
5466
5702
|
import { listSessions as listSessions2 } from "@anthropic-ai/claude-agent-sdk";
|
|
5467
5703
|
var WorkspaceRegistry = class {
|
|
5468
5704
|
#entries = [];
|
|
5469
5705
|
#storePath;
|
|
5470
5706
|
constructor(dataDir) {
|
|
5471
|
-
this.#storePath =
|
|
5707
|
+
this.#storePath = path13.join(dataDir, "workspaces.json");
|
|
5472
5708
|
}
|
|
5473
5709
|
async load() {
|
|
5474
5710
|
try {
|
|
5475
|
-
const raw = await
|
|
5711
|
+
const raw = await readFile8(this.#storePath, "utf8");
|
|
5476
5712
|
const parsed = JSON.parse(raw);
|
|
5477
5713
|
if (!Array.isArray(parsed)) {
|
|
5478
5714
|
this.#entries = [];
|
|
@@ -5490,8 +5726,8 @@ var WorkspaceRegistry = class {
|
|
|
5490
5726
|
}
|
|
5491
5727
|
}
|
|
5492
5728
|
async #persist() {
|
|
5493
|
-
await
|
|
5494
|
-
await
|
|
5729
|
+
await mkdir6(path13.dirname(this.#storePath), { recursive: true });
|
|
5730
|
+
await writeFile7(this.#storePath, JSON.stringify(this.#entries, null, 2), "utf8");
|
|
5495
5731
|
}
|
|
5496
5732
|
/** Активные проекты. */
|
|
5497
5733
|
list() {
|
|
@@ -5510,7 +5746,7 @@ var WorkspaceRegistry = class {
|
|
|
5510
5746
|
return entry ? toInfo(entry) : void 0;
|
|
5511
5747
|
}
|
|
5512
5748
|
async open(rawPath) {
|
|
5513
|
-
const absolute =
|
|
5749
|
+
const absolute = path13.resolve(rawPath);
|
|
5514
5750
|
if (!existsSync3(absolute)) {
|
|
5515
5751
|
throw new Error(`\u041A\u0430\u0442\u0430\u043B\u043E\u0433 \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D: ${absolute}`);
|
|
5516
5752
|
}
|
|
@@ -5577,40 +5813,53 @@ var WorkspaceRegistry = class {
|
|
|
5577
5813
|
async create(parentRaw, nameRaw, init) {
|
|
5578
5814
|
const name = nameRaw.trim();
|
|
5579
5815
|
requireName(name);
|
|
5580
|
-
const parent =
|
|
5816
|
+
const parent = path13.resolve(parentRaw.trim());
|
|
5581
5817
|
if (!existsSync3(parent)) {
|
|
5582
5818
|
throw new Error(`\u041A\u0430\u0442\u0430\u043B\u043E\u0433 \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D: ${parent}`);
|
|
5583
5819
|
}
|
|
5584
5820
|
if (!statSync2(parent).isDirectory()) {
|
|
5585
5821
|
throw new Error(`\u042D\u0442\u043E \u043D\u0435 \u043A\u0430\u0442\u0430\u043B\u043E\u0433: ${parent}`);
|
|
5586
5822
|
}
|
|
5587
|
-
const target =
|
|
5823
|
+
const target = path13.join(parent, name);
|
|
5588
5824
|
if (existsSync3(target)) {
|
|
5589
5825
|
throw new Error(`\u0423\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442: ${target} \u2014 \u043E\u0442\u043A\u0440\u043E\u0439\u0442\u0435 \u0435\u0433\u043E \u043A\u0430\u043A \u043F\u0440\u043E\u0435\u043A\u0442`);
|
|
5590
5826
|
}
|
|
5591
|
-
await
|
|
5827
|
+
await mkdir6(target);
|
|
5592
5828
|
const warnings = [];
|
|
5593
5829
|
if (init.claudeMd) {
|
|
5594
|
-
await step(warnings, "CLAUDE.md", () =>
|
|
5830
|
+
await step(warnings, "CLAUDE.md", () => writeFile7(path13.join(target, "CLAUDE.md"), claudeMdStub(name), "utf8"));
|
|
5595
5831
|
}
|
|
5596
5832
|
if (init.readme) {
|
|
5597
|
-
await step(warnings, "README.md", () =>
|
|
5833
|
+
await step(warnings, "README.md", () => writeFile7(path13.join(target, "README.md"), readmeStub(name), "utf8"));
|
|
5598
5834
|
}
|
|
5599
5835
|
if (init.git) {
|
|
5600
5836
|
await step(warnings, "git init", () => new GitRepo(target).init());
|
|
5601
5837
|
}
|
|
5602
5838
|
return { workspace: await this.open(target), warnings };
|
|
5603
5839
|
}
|
|
5604
|
-
/**
|
|
5605
|
-
|
|
5840
|
+
/**
|
|
5841
|
+
* Сессии Claude Code, уже лежащие на диске для этого каталога, — по всем
|
|
5842
|
+
* аккаунтам: у каждого свой каталог конфигурации и свои транскрипты.
|
|
5843
|
+
*/
|
|
5844
|
+
async sessionsOnDisk(workspaceId, accounts = [{ id: MAIN_ACCOUNT_ID, configDir: null }]) {
|
|
5606
5845
|
const workspace = this.find(workspaceId);
|
|
5607
5846
|
if (!workspace)
|
|
5608
5847
|
return [];
|
|
5609
|
-
|
|
5610
|
-
|
|
5611
|
-
|
|
5612
|
-
|
|
5848
|
+
const found = [];
|
|
5849
|
+
const seen = /* @__PURE__ */ new Set();
|
|
5850
|
+
for (const account of accounts) {
|
|
5851
|
+
try {
|
|
5852
|
+
const sessions = await withConfigDir(account.configDir, () => listSessions2({ dir: workspace.path }));
|
|
5853
|
+
for (const info of sessions) {
|
|
5854
|
+
if (seen.has(info.sessionId))
|
|
5855
|
+
continue;
|
|
5856
|
+
seen.add(info.sessionId);
|
|
5857
|
+
found.push({ ...info, accountId: account.id });
|
|
5858
|
+
}
|
|
5859
|
+
} catch {
|
|
5860
|
+
}
|
|
5613
5861
|
}
|
|
5862
|
+
return found;
|
|
5614
5863
|
}
|
|
5615
5864
|
};
|
|
5616
5865
|
var RESERVED = /^(con|prn|aux|nul|com[0-9]|lpt[0-9])(\.|$)/i;
|
|
@@ -5635,9 +5884,9 @@ function requireName(name) {
|
|
|
5635
5884
|
throw new Error(`\xAB${name}\xBB \u2014 \u0437\u0430\u0440\u0435\u0437\u0435\u0440\u0432\u0438\u0440\u043E\u0432\u0430\u043D\u043D\u043E\u0435 \u0438\u043C\u044F \u0443\u0441\u0442\u0440\u043E\u0439\u0441\u0442\u0432\u0430 Windows`);
|
|
5636
5885
|
}
|
|
5637
5886
|
}
|
|
5638
|
-
async function step(warnings, what,
|
|
5887
|
+
async function step(warnings, what, run) {
|
|
5639
5888
|
try {
|
|
5640
|
-
await
|
|
5889
|
+
await run();
|
|
5641
5890
|
} catch (error) {
|
|
5642
5891
|
warnings.push(`${what}: ${error instanceof Error ? error.message : String(error)}`);
|
|
5643
5892
|
}
|
|
@@ -5666,8 +5915,8 @@ function toInfo(entry) {
|
|
|
5666
5915
|
return {
|
|
5667
5916
|
id: workspaceIdFromPath(absolute),
|
|
5668
5917
|
path: absolute,
|
|
5669
|
-
name:
|
|
5670
|
-
hasClaudeMd: existsSync3(
|
|
5918
|
+
name: path13.basename(absolute) || absolute,
|
|
5919
|
+
hasClaudeMd: existsSync3(path13.join(absolute, "CLAUDE.md")),
|
|
5671
5920
|
...archivedAt ? { archivedAt } : {}
|
|
5672
5921
|
};
|
|
5673
5922
|
}
|
|
@@ -5676,18 +5925,18 @@ function isEntry(value) {
|
|
|
5676
5925
|
}
|
|
5677
5926
|
|
|
5678
5927
|
// ../host/dist/archive.js
|
|
5679
|
-
import { mkdir as
|
|
5680
|
-
import
|
|
5928
|
+
import { mkdir as mkdir7, readFile as readFile9, writeFile as writeFile8 } from "node:fs/promises";
|
|
5929
|
+
import path14 from "node:path";
|
|
5681
5930
|
var SessionArchive = class {
|
|
5682
5931
|
#archived = /* @__PURE__ */ new Map();
|
|
5683
5932
|
#restored = /* @__PURE__ */ new Map();
|
|
5684
5933
|
#storePath;
|
|
5685
5934
|
constructor(dataDir) {
|
|
5686
|
-
this.#storePath =
|
|
5935
|
+
this.#storePath = path14.join(dataDir, "session-archive.json");
|
|
5687
5936
|
}
|
|
5688
5937
|
async load() {
|
|
5689
5938
|
try {
|
|
5690
|
-
const raw = await
|
|
5939
|
+
const raw = await readFile9(this.#storePath, "utf8");
|
|
5691
5940
|
const parsed = JSON.parse(raw);
|
|
5692
5941
|
this.#archived = new Map(Object.entries(parsed.archived ?? {}).filter(([, r]) => isRecord(r)));
|
|
5693
5942
|
this.#restored = new Map(Object.entries(parsed.restored ?? {}).filter((entry) => typeof entry[1] === "number"));
|
|
@@ -5795,8 +6044,8 @@ var SessionArchive = class {
|
|
|
5795
6044
|
archived: Object.fromEntries(this.#archived),
|
|
5796
6045
|
restored: Object.fromEntries(this.#restored)
|
|
5797
6046
|
};
|
|
5798
|
-
await
|
|
5799
|
-
await
|
|
6047
|
+
await mkdir7(path14.dirname(this.#storePath), { recursive: true });
|
|
6048
|
+
await writeFile8(this.#storePath, JSON.stringify(file, null, 2), "utf8");
|
|
5800
6049
|
}
|
|
5801
6050
|
};
|
|
5802
6051
|
function isRecord(value) {
|
|
@@ -5804,8 +6053,8 @@ function isRecord(value) {
|
|
|
5804
6053
|
}
|
|
5805
6054
|
|
|
5806
6055
|
// ../host/dist/pins.js
|
|
5807
|
-
import { mkdir as
|
|
5808
|
-
import
|
|
6056
|
+
import { mkdir as mkdir8, readFile as readFile10, writeFile as writeFile9 } from "node:fs/promises";
|
|
6057
|
+
import path15 from "node:path";
|
|
5809
6058
|
var SessionPins = class {
|
|
5810
6059
|
#pinned = /* @__PURE__ */ new Map();
|
|
5811
6060
|
/**
|
|
@@ -5820,11 +6069,11 @@ var SessionPins = class {
|
|
|
5820
6069
|
#moved = /* @__PURE__ */ new Map();
|
|
5821
6070
|
#storePath;
|
|
5822
6071
|
constructor(dataDir) {
|
|
5823
|
-
this.#storePath =
|
|
6072
|
+
this.#storePath = path15.join(dataDir, "session-pins.json");
|
|
5824
6073
|
}
|
|
5825
6074
|
async load() {
|
|
5826
6075
|
try {
|
|
5827
|
-
const raw = await
|
|
6076
|
+
const raw = await readFile10(this.#storePath, "utf8");
|
|
5828
6077
|
const parsed = JSON.parse(raw);
|
|
5829
6078
|
this.#pinned = new Map(Object.entries(parsed.pinned ?? {}).filter(([, r]) => isRecord2(r)));
|
|
5830
6079
|
this.#moved = new Map(Object.entries(parsed.moved ?? {}).filter(([, to]) => typeof to === "string"));
|
|
@@ -5977,8 +6226,8 @@ var SessionPins = class {
|
|
|
5977
6226
|
pinned: Object.fromEntries(this.#pinned),
|
|
5978
6227
|
...this.#moved.size > 0 ? { moved: Object.fromEntries(this.#moved) } : {}
|
|
5979
6228
|
};
|
|
5980
|
-
await
|
|
5981
|
-
await
|
|
6229
|
+
await mkdir8(path15.dirname(this.#storePath), { recursive: true });
|
|
6230
|
+
await writeFile9(this.#storePath, JSON.stringify(file, null, 2), "utf8");
|
|
5982
6231
|
}
|
|
5983
6232
|
};
|
|
5984
6233
|
function isRecord2(value) {
|
|
@@ -5986,17 +6235,17 @@ function isRecord2(value) {
|
|
|
5986
6235
|
}
|
|
5987
6236
|
|
|
5988
6237
|
// ../host/dist/order.js
|
|
5989
|
-
import { mkdir as
|
|
5990
|
-
import
|
|
6238
|
+
import { mkdir as mkdir9, readFile as readFile11, writeFile as writeFile10 } from "node:fs/promises";
|
|
6239
|
+
import path16 from "node:path";
|
|
5991
6240
|
var ListOrderStore = class {
|
|
5992
6241
|
#order = emptyOrder();
|
|
5993
6242
|
#storePath;
|
|
5994
6243
|
constructor(dataDir) {
|
|
5995
|
-
this.#storePath =
|
|
6244
|
+
this.#storePath = path16.join(dataDir, "list-order.json");
|
|
5996
6245
|
}
|
|
5997
6246
|
async load() {
|
|
5998
6247
|
try {
|
|
5999
|
-
const raw = await
|
|
6248
|
+
const raw = await readFile11(this.#storePath, "utf8");
|
|
6000
6249
|
this.#order = sanitize(JSON.parse(raw));
|
|
6001
6250
|
} catch {
|
|
6002
6251
|
this.#order = emptyOrder();
|
|
@@ -6068,8 +6317,8 @@ var ListOrderStore = class {
|
|
|
6068
6317
|
return changed;
|
|
6069
6318
|
}
|
|
6070
6319
|
async #persist() {
|
|
6071
|
-
await
|
|
6072
|
-
await
|
|
6320
|
+
await mkdir9(path16.dirname(this.#storePath), { recursive: true });
|
|
6321
|
+
await writeFile10(this.#storePath, JSON.stringify(this.#order, null, 2), "utf8");
|
|
6073
6322
|
}
|
|
6074
6323
|
};
|
|
6075
6324
|
function emptyOrder() {
|
|
@@ -6098,9 +6347,9 @@ function sanitize(value) {
|
|
|
6098
6347
|
}
|
|
6099
6348
|
|
|
6100
6349
|
// ../host/dist/folders.js
|
|
6101
|
-
import { mkdir as
|
|
6102
|
-
import
|
|
6103
|
-
import { randomUUID as
|
|
6350
|
+
import { mkdir as mkdir10, readFile as readFile12, writeFile as writeFile11 } from "node:fs/promises";
|
|
6351
|
+
import path17 from "node:path";
|
|
6352
|
+
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
6104
6353
|
var COLOR_PATTERN = /^#[0-9a-f]{6}$/i;
|
|
6105
6354
|
var Folders = class {
|
|
6106
6355
|
#workspaceFolders = /* @__PURE__ */ new Map();
|
|
@@ -6111,11 +6360,11 @@ var Folders = class {
|
|
|
6111
6360
|
#pinnedAssignments = /* @__PURE__ */ new Map();
|
|
6112
6361
|
#storePath;
|
|
6113
6362
|
constructor(dataDir) {
|
|
6114
|
-
this.#storePath =
|
|
6363
|
+
this.#storePath = path17.join(dataDir, "folders.json");
|
|
6115
6364
|
}
|
|
6116
6365
|
async load() {
|
|
6117
6366
|
try {
|
|
6118
|
-
const raw = await
|
|
6367
|
+
const raw = await readFile12(this.#storePath, "utf8");
|
|
6119
6368
|
const parsed = JSON.parse(raw);
|
|
6120
6369
|
this.#workspaceFolders = new Map(Object.entries(parsed.workspaceFolders ?? {}).filter(([, r]) => isWorkspaceFolder(r)).map(([id, r]) => [id, withValidColor(r)]));
|
|
6121
6370
|
this.#sessionFolders = new Map(Object.entries(parsed.sessionFolders ?? {}).filter(([, r]) => isSessionFolder(r)).map(([id, r]) => [id, withValidColor(r)]));
|
|
@@ -6200,19 +6449,19 @@ var Folders = class {
|
|
|
6200
6449
|
};
|
|
6201
6450
|
}
|
|
6202
6451
|
async createWorkspaceFolder(name) {
|
|
6203
|
-
const id =
|
|
6452
|
+
const id = randomUUID4();
|
|
6204
6453
|
this.#workspaceFolders.set(id, { name });
|
|
6205
6454
|
await this.#persist();
|
|
6206
6455
|
return id;
|
|
6207
6456
|
}
|
|
6208
6457
|
async createSessionFolder(workspaceId, name) {
|
|
6209
|
-
const id =
|
|
6458
|
+
const id = randomUUID4();
|
|
6210
6459
|
this.#sessionFolders.set(id, { name, workspaceId });
|
|
6211
6460
|
await this.#persist();
|
|
6212
6461
|
return id;
|
|
6213
6462
|
}
|
|
6214
6463
|
async createPinnedFolder(name) {
|
|
6215
|
-
const id =
|
|
6464
|
+
const id = randomUUID4();
|
|
6216
6465
|
this.#pinnedFolders.set(id, { name });
|
|
6217
6466
|
await this.#persist();
|
|
6218
6467
|
return id;
|
|
@@ -6392,8 +6641,8 @@ var Folders = class {
|
|
|
6392
6641
|
sessionAssignments: Object.fromEntries(this.#sessionAssignments),
|
|
6393
6642
|
pinnedAssignments: Object.fromEntries(this.#pinnedAssignments)
|
|
6394
6643
|
};
|
|
6395
|
-
await
|
|
6396
|
-
await
|
|
6644
|
+
await mkdir10(path17.dirname(this.#storePath), { recursive: true });
|
|
6645
|
+
await writeFile11(this.#storePath, JSON.stringify(file, null, 2), "utf8");
|
|
6397
6646
|
}
|
|
6398
6647
|
};
|
|
6399
6648
|
function withValidColor(record) {
|
|
@@ -6414,9 +6663,9 @@ function isPinnedFolder(value) {
|
|
|
6414
6663
|
}
|
|
6415
6664
|
|
|
6416
6665
|
// ../host/dist/app-settings.js
|
|
6417
|
-
import { mkdir as
|
|
6418
|
-
import { homedir as
|
|
6419
|
-
import
|
|
6666
|
+
import { mkdir as mkdir11, readFile as readFile13, writeFile as writeFile12 } from "node:fs/promises";
|
|
6667
|
+
import { homedir as homedir5 } from "node:os";
|
|
6668
|
+
import path18 from "node:path";
|
|
6420
6669
|
var DEFAULT_AUTO_ARCHIVE_AFTER_MS = 2 * 24 * 60 * 60 * 1e3;
|
|
6421
6670
|
var MIN_AUTO_ARCHIVE_AFTER_MS = 60 * 60 * 1e3;
|
|
6422
6671
|
var DEFAULT_AUTO_STOP_AFTER_MS = 10 * 60 * 1e3;
|
|
@@ -6469,11 +6718,11 @@ var AppSettingsStore = class {
|
|
|
6469
6718
|
#settings = { ...DEFAULT_APP_SETTINGS };
|
|
6470
6719
|
#storePath;
|
|
6471
6720
|
constructor(dataDir) {
|
|
6472
|
-
this.#storePath =
|
|
6721
|
+
this.#storePath = path18.join(dataDir, "app-settings.json");
|
|
6473
6722
|
}
|
|
6474
6723
|
async load() {
|
|
6475
6724
|
try {
|
|
6476
|
-
const raw = await
|
|
6725
|
+
const raw = await readFile13(this.#storePath, "utf8");
|
|
6477
6726
|
this.#settings = sanitize2(JSON.parse(raw), DEFAULT_APP_SETTINGS);
|
|
6478
6727
|
} catch {
|
|
6479
6728
|
this.#settings = { ...DEFAULT_APP_SETTINGS };
|
|
@@ -6493,8 +6742,8 @@ var AppSettingsStore = class {
|
|
|
6493
6742
|
async update(patch) {
|
|
6494
6743
|
const next = sanitize2(patch, this.#settings);
|
|
6495
6744
|
this.#settings = next;
|
|
6496
|
-
await
|
|
6497
|
-
await
|
|
6745
|
+
await mkdir11(path18.dirname(this.#storePath), { recursive: true });
|
|
6746
|
+
await writeFile12(this.#storePath, JSON.stringify(next, null, 2), "utf8");
|
|
6498
6747
|
return this.current;
|
|
6499
6748
|
}
|
|
6500
6749
|
};
|
|
@@ -6560,7 +6809,7 @@ function sanitize2(value, fallback) {
|
|
|
6560
6809
|
return result;
|
|
6561
6810
|
}
|
|
6562
6811
|
function claudeHome() {
|
|
6563
|
-
return
|
|
6812
|
+
return path18.join(homedir5(), ".claude");
|
|
6564
6813
|
}
|
|
6565
6814
|
function writableRoots(mode, cwd, workspacePaths) {
|
|
6566
6815
|
if (mode === "all")
|
|
@@ -6570,7 +6819,7 @@ function writableRoots(mode, cwd, workspacePaths) {
|
|
|
6570
6819
|
return [...roots];
|
|
6571
6820
|
for (const workspace of [cwd, ...workspacePaths]) {
|
|
6572
6821
|
roots.add(workspace);
|
|
6573
|
-
const parent =
|
|
6822
|
+
const parent = path18.dirname(workspace);
|
|
6574
6823
|
if (parent !== workspace)
|
|
6575
6824
|
roots.add(parent);
|
|
6576
6825
|
}
|
|
@@ -6578,19 +6827,19 @@ function writableRoots(mode, cwd, workspacePaths) {
|
|
|
6578
6827
|
}
|
|
6579
6828
|
|
|
6580
6829
|
// ../host/dist/handoff-store.js
|
|
6581
|
-
import { mkdir as
|
|
6582
|
-
import
|
|
6830
|
+
import { mkdir as mkdir12, readFile as readFile14, readdir as readdir4, rm as rm4, writeFile as writeFile13 } from "node:fs/promises";
|
|
6831
|
+
import path19 from "node:path";
|
|
6583
6832
|
var HandoffStore = class {
|
|
6584
6833
|
#dir;
|
|
6585
6834
|
constructor(dataDir) {
|
|
6586
|
-
this.#dir =
|
|
6835
|
+
this.#dir = path19.join(dataDir, "handoffs");
|
|
6587
6836
|
}
|
|
6588
6837
|
async get(sessionId) {
|
|
6589
6838
|
const file = this.#file(sessionId);
|
|
6590
6839
|
if (!file)
|
|
6591
6840
|
return null;
|
|
6592
6841
|
try {
|
|
6593
|
-
const parsed = JSON.parse(await
|
|
6842
|
+
const parsed = JSON.parse(await readFile14(file, "utf8"));
|
|
6594
6843
|
return typeof parsed.text === "string" ? parsed : null;
|
|
6595
6844
|
} catch {
|
|
6596
6845
|
return null;
|
|
@@ -6600,8 +6849,8 @@ var HandoffStore = class {
|
|
|
6600
6849
|
const file = this.#file(handoff.sessionId);
|
|
6601
6850
|
if (!file)
|
|
6602
6851
|
return;
|
|
6603
|
-
await
|
|
6604
|
-
await
|
|
6852
|
+
await mkdir12(this.#dir, { recursive: true });
|
|
6853
|
+
await writeFile13(file, JSON.stringify(handoff, null, 2), "utf8");
|
|
6605
6854
|
}
|
|
6606
6855
|
async remove(sessionId) {
|
|
6607
6856
|
const file = this.#file(sessionId);
|
|
@@ -6611,7 +6860,7 @@ var HandoffStore = class {
|
|
|
6611
6860
|
/** id всех сохранённых хэндоффов. */
|
|
6612
6861
|
async list() {
|
|
6613
6862
|
try {
|
|
6614
|
-
return (await
|
|
6863
|
+
return (await readdir4(this.#dir)).filter((name) => name.endsWith(".json")).map((name) => name.slice(0, -".json".length));
|
|
6615
6864
|
} catch {
|
|
6616
6865
|
return [];
|
|
6617
6866
|
}
|
|
@@ -6620,29 +6869,47 @@ var HandoffStore = class {
|
|
|
6620
6869
|
#file(sessionId) {
|
|
6621
6870
|
if (!/^[\w-]{1,128}$/.test(sessionId))
|
|
6622
6871
|
return null;
|
|
6623
|
-
return
|
|
6872
|
+
return path19.join(this.#dir, `${sessionId}.json`);
|
|
6624
6873
|
}
|
|
6625
6874
|
};
|
|
6626
6875
|
var SAME_WINDOW_MS = 5 * 6e4;
|
|
6627
6876
|
var LimitStopState = class {
|
|
6877
|
+
/** Аккаунт → окно → срок. Лимиты у каждого аккаунта свои, и сработавшее окно одного чужому не помеха. */
|
|
6628
6878
|
#fired = {};
|
|
6629
6879
|
#storePath;
|
|
6630
6880
|
constructor(dataDir) {
|
|
6631
|
-
this.#storePath =
|
|
6881
|
+
this.#storePath = path19.join(dataDir, "limit-stop.json");
|
|
6632
6882
|
}
|
|
6633
6883
|
async load() {
|
|
6634
6884
|
try {
|
|
6635
|
-
const parsed = JSON.parse(await
|
|
6885
|
+
const parsed = JSON.parse(await readFile14(this.#storePath, "utf8"));
|
|
6636
6886
|
this.#fired = {};
|
|
6637
|
-
|
|
6638
|
-
const
|
|
6639
|
-
|
|
6640
|
-
|
|
6887
|
+
const read = (source) => {
|
|
6888
|
+
const out = {};
|
|
6889
|
+
for (const key of ["fiveHour", "sevenDay"]) {
|
|
6890
|
+
const until = source[key];
|
|
6891
|
+
if (typeof until === "number" && Number.isFinite(until))
|
|
6892
|
+
out[key] = until;
|
|
6893
|
+
}
|
|
6894
|
+
return out;
|
|
6895
|
+
};
|
|
6896
|
+
this.#fired[MAIN_ACCOUNT_ID] = read(parsed);
|
|
6897
|
+
for (const [account, value] of Object.entries(parsed)) {
|
|
6898
|
+
if (value && typeof value === "object")
|
|
6899
|
+
this.#fired[account] = read(value);
|
|
6641
6900
|
}
|
|
6642
6901
|
} catch {
|
|
6643
6902
|
this.#fired = {};
|
|
6644
6903
|
}
|
|
6645
6904
|
}
|
|
6905
|
+
/** Срабатывания одного аккаунта. */
|
|
6906
|
+
forAccount(account) {
|
|
6907
|
+
return {
|
|
6908
|
+
fired: (limit, resets, now = Date.now()) => this.#isFired(account, limit, resets, now),
|
|
6909
|
+
until: (limit) => this.#fired[account]?.[limit] ?? 0,
|
|
6910
|
+
mark: (limit, until) => this.#mark(account, limit, until)
|
|
6911
|
+
};
|
|
6912
|
+
}
|
|
6646
6913
|
/**
|
|
6647
6914
|
* Окно `limit` со сроком сброса `resets` уже сработало и ещё не сбросилось.
|
|
6648
6915
|
*
|
|
@@ -6651,21 +6918,17 @@ var LimitStopState = class {
|
|
|
6651
6918
|
* 7.10 новое окно до 21:20 пропустили, приняв его за сработавшее до 20:30).
|
|
6652
6919
|
* `null` — срок не разобрать, сверять не с чем, решает только записанный.
|
|
6653
6920
|
*/
|
|
6654
|
-
|
|
6655
|
-
const until = this.#fired[limit] ?? 0;
|
|
6921
|
+
#isFired(account, limit, resets, now) {
|
|
6922
|
+
const until = this.#fired[account]?.[limit] ?? 0;
|
|
6656
6923
|
if (until <= now)
|
|
6657
6924
|
return false;
|
|
6658
6925
|
return resets === null || Math.abs(resets - until) <= SAME_WINDOW_MS;
|
|
6659
6926
|
}
|
|
6660
|
-
|
|
6661
|
-
|
|
6662
|
-
|
|
6663
|
-
|
|
6664
|
-
|
|
6665
|
-
async mark(limit, until) {
|
|
6666
|
-
this.#fired[limit] = until;
|
|
6667
|
-
await mkdir11(path18.dirname(this.#storePath), { recursive: true });
|
|
6668
|
-
await writeFile12(this.#storePath, JSON.stringify(this.#fired, null, 2), "utf8");
|
|
6927
|
+
async #mark(account, limit, until) {
|
|
6928
|
+
this.#fired[account] = { ...this.#fired[account], [limit]: until };
|
|
6929
|
+
await mkdir12(path19.dirname(this.#storePath), { recursive: true });
|
|
6930
|
+
const { [MAIN_ACCOUNT_ID]: main = {}, ...others } = this.#fired;
|
|
6931
|
+
await writeFile13(this.#storePath, JSON.stringify({ ...main, ...others }, null, 2), "utf8");
|
|
6669
6932
|
}
|
|
6670
6933
|
};
|
|
6671
6934
|
|
|
@@ -6769,9 +7032,9 @@ function capitalize(text) {
|
|
|
6769
7032
|
}
|
|
6770
7033
|
|
|
6771
7034
|
// ../host/dist/plugins.js
|
|
6772
|
-
import { readFile as
|
|
6773
|
-
import { homedir as
|
|
6774
|
-
import
|
|
7035
|
+
import { readFile as readFile15 } from "node:fs/promises";
|
|
7036
|
+
import { homedir as homedir6 } from "node:os";
|
|
7037
|
+
import path20 from "node:path";
|
|
6775
7038
|
var TIMEOUT_MS2 = 12e4;
|
|
6776
7039
|
var SAFE_ARG = /^[A-Za-z0-9][A-Za-z0-9._@/-]*$/;
|
|
6777
7040
|
var PluginCli = class {
|
|
@@ -6870,10 +7133,10 @@ async function readCatalog(markets, installed) {
|
|
|
6870
7133
|
return lists.flat().sort((a, b) => a.name.localeCompare(b.name));
|
|
6871
7134
|
}
|
|
6872
7135
|
async function readMarketplace(market, installed) {
|
|
6873
|
-
const root = market.installLocation ||
|
|
7136
|
+
const root = market.installLocation || path20.join(homedir6(), ".claude", "plugins", "marketplaces", market.name);
|
|
6874
7137
|
let manifest;
|
|
6875
7138
|
try {
|
|
6876
|
-
const text = await
|
|
7139
|
+
const text = await readFile15(path20.join(root, ".claude-plugin", "marketplace.json"), "utf8");
|
|
6877
7140
|
manifest = JSON.parse(text);
|
|
6878
7141
|
} catch {
|
|
6879
7142
|
return [];
|
|
@@ -6929,11 +7192,18 @@ var IDLE = {
|
|
|
6929
7192
|
error: null
|
|
6930
7193
|
};
|
|
6931
7194
|
var AuthCli = class extends EventEmitter4 {
|
|
7195
|
+
configDir;
|
|
6932
7196
|
#child = null;
|
|
6933
7197
|
#state = IDLE;
|
|
6934
7198
|
#timer = null;
|
|
6935
|
-
|
|
7199
|
+
/**
|
|
7200
|
+
* `configDir` — каталог конфигурации аккаунта, чей это вход (`null` —
|
|
7201
|
+
* унаследованный). Один `AuthCli` — один аккаунт: у каждого свой вход, своя
|
|
7202
|
+
* ссылка и свой код, и параллельные входы двух аккаунтов не мешают друг другу.
|
|
7203
|
+
*/
|
|
7204
|
+
constructor(configDir = null) {
|
|
6936
7205
|
super();
|
|
7206
|
+
this.configDir = configDir;
|
|
6937
7207
|
void warmClaudeLauncher();
|
|
6938
7208
|
}
|
|
6939
7209
|
get loginState() {
|
|
@@ -6941,7 +7211,7 @@ var AuthCli = class extends EventEmitter4 {
|
|
|
6941
7211
|
}
|
|
6942
7212
|
/** Кто вошёл. Незалогиненный CLI — не ошибка, а обычный ответ. */
|
|
6943
7213
|
async status() {
|
|
6944
|
-
const raw = await run(["auth", "status", "--json"]
|
|
7214
|
+
const raw = await this.#run(["auth", "status", "--json"]).catch(
|
|
6945
7215
|
// Старый CLI мог не знать `auth status`. Показать «не вошёл» честнее,
|
|
6946
7216
|
// чем уронить окно: сессии всё равно расскажут, работает ли ключ.
|
|
6947
7217
|
() => ""
|
|
@@ -6960,7 +7230,7 @@ var AuthCli = class extends EventEmitter4 {
|
|
|
6960
7230
|
if (this.#child)
|
|
6961
7231
|
throw new Error("\u0412\u0445\u043E\u0434 \u0443\u0436\u0435 \u0438\u0434\u0451\u0442 \u2014 \u0434\u043E\u0436\u0434\u0438\u0442\u0435\u0441\u044C \u0438\u043B\u0438 \u043E\u0442\u043C\u0435\u043D\u0438\u0442\u0435 \u0435\u0433\u043E");
|
|
6962
7232
|
if (switchAccount) {
|
|
6963
|
-
const out = await run(["auth", "logout"]
|
|
7233
|
+
const out = await this.#run(["auth", "logout"]).catch(describe5);
|
|
6964
7234
|
this.#push({ ...IDLE, active: true, output: `${out}
|
|
6965
7235
|
` });
|
|
6966
7236
|
this.emit("changed");
|
|
@@ -6968,7 +7238,7 @@ var AuthCli = class extends EventEmitter4 {
|
|
|
6968
7238
|
this.#push({ ...IDLE, active: true });
|
|
6969
7239
|
}
|
|
6970
7240
|
const args = ["auth", "login", mode === "console" ? "--console" : "--claudeai"];
|
|
6971
|
-
const child = await spawnClaude(args);
|
|
7241
|
+
const child = await spawnClaude(args, this.configDir ? accountEnv(this.configDir) : void 0);
|
|
6972
7242
|
if (!this.#state.active) {
|
|
6973
7243
|
child.kill();
|
|
6974
7244
|
return;
|
|
@@ -7020,11 +7290,18 @@ var AuthCli = class extends EventEmitter4 {
|
|
|
7020
7290
|
}
|
|
7021
7291
|
async logout() {
|
|
7022
7292
|
this.cancel();
|
|
7023
|
-
const output = await run(["auth", "logout"]
|
|
7293
|
+
const output = await this.#run(["auth", "logout"]);
|
|
7024
7294
|
this.#push({ ...IDLE, output });
|
|
7025
7295
|
this.emit("changed");
|
|
7026
7296
|
}
|
|
7027
7297
|
// -------------------------------------------------------------------------
|
|
7298
|
+
#run(args) {
|
|
7299
|
+
return runClaude(args, {
|
|
7300
|
+
timeout: QUICK_TIMEOUT_MS,
|
|
7301
|
+
missing: "\u0443\u043F\u0440\u0430\u0432\u043B\u0435\u043D\u0438\u0435 \u0430\u043A\u043A\u0430\u0443\u043D\u0442\u043E\u043C \u043D\u0435\u0434\u043E\u0441\u0442\u0443\u043F\u043D\u043E",
|
|
7302
|
+
...this.configDir ? { env: accountEnv(this.configDir) } : {}
|
|
7303
|
+
});
|
|
7304
|
+
}
|
|
7028
7305
|
#absorb(text) {
|
|
7029
7306
|
const output = this.#state.output + text;
|
|
7030
7307
|
this.#push({
|
|
@@ -7059,9 +7336,6 @@ var AuthCli = class extends EventEmitter4 {
|
|
|
7059
7336
|
this.emit("login", state);
|
|
7060
7337
|
}
|
|
7061
7338
|
};
|
|
7062
|
-
function run(args, timeout) {
|
|
7063
|
-
return runClaude(args, { timeout, missing: "\u0443\u043F\u0440\u0430\u0432\u043B\u0435\u043D\u0438\u0435 \u0430\u043A\u043A\u0430\u0443\u043D\u0442\u043E\u043C \u043D\u0435\u0434\u043E\u0441\u0442\u0443\u043F\u043D\u043E" });
|
|
7064
|
-
}
|
|
7065
7339
|
function normalizeAuthCode(raw) {
|
|
7066
7340
|
const value = raw.trim();
|
|
7067
7341
|
if (!/^https?:\/\//i.test(value))
|
|
@@ -7114,8 +7388,8 @@ function describe5(error) {
|
|
|
7114
7388
|
|
|
7115
7389
|
// ../host/dist/relay-link.js
|
|
7116
7390
|
import { EventEmitter as EventEmitter5 } from "node:events";
|
|
7117
|
-
import { readFile as
|
|
7118
|
-
import
|
|
7391
|
+
import { readFile as readFile16, writeFile as writeFile14, rm as rm5, mkdir as mkdir13 } from "node:fs/promises";
|
|
7392
|
+
import path21 from "node:path";
|
|
7119
7393
|
import { hostname } from "node:os";
|
|
7120
7394
|
import WebSocket from "ws";
|
|
7121
7395
|
|
|
@@ -7170,7 +7444,7 @@ var RelayLink = class extends EventEmitter5 {
|
|
|
7170
7444
|
#log;
|
|
7171
7445
|
constructor(options2) {
|
|
7172
7446
|
super();
|
|
7173
|
-
this.#file =
|
|
7447
|
+
this.#file = path21.join(options2.dataDir, "relay.json");
|
|
7174
7448
|
this.#defaultUrl = options2.defaultUrl.replace(/\/+$/, "");
|
|
7175
7449
|
this.#log = options2.log ?? ((msg) => console.log(`[relay] ${msg}`));
|
|
7176
7450
|
}
|
|
@@ -7251,7 +7525,7 @@ var RelayLink = class extends EventEmitter5 {
|
|
|
7251
7525
|
}
|
|
7252
7526
|
async #read() {
|
|
7253
7527
|
try {
|
|
7254
|
-
const raw = await
|
|
7528
|
+
const raw = await readFile16(this.#file, "utf8");
|
|
7255
7529
|
const parsed = JSON.parse(raw);
|
|
7256
7530
|
if (typeof parsed !== "object" || parsed === null)
|
|
7257
7531
|
return null;
|
|
@@ -7264,8 +7538,8 @@ var RelayLink = class extends EventEmitter5 {
|
|
|
7264
7538
|
}
|
|
7265
7539
|
}
|
|
7266
7540
|
async #write(credentials) {
|
|
7267
|
-
await
|
|
7268
|
-
await
|
|
7541
|
+
await mkdir13(path21.dirname(this.#file), { recursive: true });
|
|
7542
|
+
await writeFile14(this.#file, `${JSON.stringify(credentials, null, 2)}
|
|
7269
7543
|
`, {
|
|
7270
7544
|
encoding: "utf8",
|
|
7271
7545
|
mode: 384
|
|
@@ -7522,8 +7796,8 @@ function humanize(error) {
|
|
|
7522
7796
|
// ../host/dist/terminal.js
|
|
7523
7797
|
import { EventEmitter as EventEmitter6 } from "node:events";
|
|
7524
7798
|
import { access as access2, constants as constants2 } from "node:fs/promises";
|
|
7525
|
-
import
|
|
7526
|
-
import { randomUUID as
|
|
7799
|
+
import path22 from "node:path";
|
|
7800
|
+
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
7527
7801
|
var SCROLLBACK_BYTES = 256 * 1024;
|
|
7528
7802
|
var FLUSH_MS = 12;
|
|
7529
7803
|
var MAX_TERMINALS = 24;
|
|
@@ -7560,7 +7834,7 @@ var TerminalHub = class extends EventEmitter6 {
|
|
|
7560
7834
|
env: environment()
|
|
7561
7835
|
});
|
|
7562
7836
|
const info = {
|
|
7563
|
-
id:
|
|
7837
|
+
id: randomUUID5(),
|
|
7564
7838
|
workspaceId: options2.workspaceId,
|
|
7565
7839
|
title: shell.title,
|
|
7566
7840
|
shell: shell.file,
|
|
@@ -7692,36 +7966,36 @@ async function defaultShell() {
|
|
|
7692
7966
|
if (pwsh)
|
|
7693
7967
|
return { file: pwsh, args: [], title: "pwsh" };
|
|
7694
7968
|
const system = process.env.SystemRoot ?? "C:\\Windows";
|
|
7695
|
-
const powershell =
|
|
7696
|
-
if (await
|
|
7969
|
+
const powershell = path22.join(system, "System32/WindowsPowerShell/v1.0/powershell.exe");
|
|
7970
|
+
if (await exists3(powershell))
|
|
7697
7971
|
return { file: powershell, args: [], title: "powershell" };
|
|
7698
7972
|
return { file: process.env.COMSPEC ?? "cmd.exe", args: [], title: "cmd" };
|
|
7699
7973
|
}
|
|
7700
7974
|
const shell = process.env.SHELL;
|
|
7701
|
-
if (shell && await
|
|
7702
|
-
return { file: shell, args: [], title:
|
|
7703
|
-
if (await
|
|
7975
|
+
if (shell && await exists3(shell))
|
|
7976
|
+
return { file: shell, args: [], title: path22.basename(shell) };
|
|
7977
|
+
if (await exists3("/bin/bash"))
|
|
7704
7978
|
return { file: "/bin/bash", args: [], title: "bash" };
|
|
7705
7979
|
return { file: "/bin/sh", args: [], title: "sh" };
|
|
7706
7980
|
}
|
|
7707
7981
|
async function findOnPath(name) {
|
|
7708
|
-
const dirs = (process.env.PATH ?? "").split(
|
|
7982
|
+
const dirs = (process.env.PATH ?? "").split(path22.delimiter).filter(Boolean);
|
|
7709
7983
|
for (const dir of dirs) {
|
|
7710
|
-
const candidate =
|
|
7711
|
-
if (await
|
|
7984
|
+
const candidate = path22.join(dir, name);
|
|
7985
|
+
if (await exists3(candidate))
|
|
7712
7986
|
return candidate;
|
|
7713
7987
|
}
|
|
7714
7988
|
return null;
|
|
7715
7989
|
}
|
|
7716
|
-
function
|
|
7990
|
+
function exists3(file) {
|
|
7717
7991
|
return access2(file, constants2.X_OK).then(() => true, () => false);
|
|
7718
7992
|
}
|
|
7719
7993
|
|
|
7720
7994
|
// ../host/dist/mcp-config.js
|
|
7721
|
-
import { readFile as
|
|
7722
|
-
import
|
|
7995
|
+
import { readFile as readFile17, writeFile as writeFile15, mkdir as mkdir14 } from "node:fs/promises";
|
|
7996
|
+
import path23 from "node:path";
|
|
7723
7997
|
var MCP_FILE = ".mcp.json";
|
|
7724
|
-
var LOCAL_SETTINGS2 =
|
|
7998
|
+
var LOCAL_SETTINGS2 = path23.join(".claude", "settings.local.json");
|
|
7725
7999
|
var queues = /* @__PURE__ */ new Map();
|
|
7726
8000
|
function serialize(cwd, work) {
|
|
7727
8001
|
const previous = queues.get(cwd) ?? Promise.resolve();
|
|
@@ -7730,7 +8004,7 @@ function serialize(cwd, work) {
|
|
|
7730
8004
|
return next;
|
|
7731
8005
|
}
|
|
7732
8006
|
async function readProjectServers(cwd) {
|
|
7733
|
-
const file = await readJson(
|
|
8007
|
+
const file = await readJson(path23.join(cwd, MCP_FILE));
|
|
7734
8008
|
const servers = file?.mcpServers;
|
|
7735
8009
|
if (!servers || typeof servers !== "object")
|
|
7736
8010
|
return {};
|
|
@@ -7738,23 +8012,23 @@ async function readProjectServers(cwd) {
|
|
|
7738
8012
|
}
|
|
7739
8013
|
function addProjectServer(cwd, name, config) {
|
|
7740
8014
|
return serialize(cwd, async () => {
|
|
7741
|
-
const file = await readJson(
|
|
8015
|
+
const file = await readJson(path23.join(cwd, MCP_FILE)) ?? {};
|
|
7742
8016
|
const servers = file.mcpServers ?? {};
|
|
7743
8017
|
servers[name] = config;
|
|
7744
8018
|
file.mcpServers = servers;
|
|
7745
|
-
await writeJson(
|
|
8019
|
+
await writeJson(path23.join(cwd, MCP_FILE), file);
|
|
7746
8020
|
await approve(cwd, name);
|
|
7747
8021
|
});
|
|
7748
8022
|
}
|
|
7749
8023
|
function removeProjectServer(cwd, name) {
|
|
7750
8024
|
return serialize(cwd, async () => {
|
|
7751
|
-
const file = await readJson(
|
|
8025
|
+
const file = await readJson(path23.join(cwd, MCP_FILE));
|
|
7752
8026
|
const servers = file?.mcpServers;
|
|
7753
8027
|
if (!servers || !(name in servers))
|
|
7754
8028
|
return false;
|
|
7755
8029
|
delete servers[name];
|
|
7756
|
-
await writeJson(
|
|
7757
|
-
const settingsPath =
|
|
8030
|
+
await writeJson(path23.join(cwd, MCP_FILE), file);
|
|
8031
|
+
const settingsPath = path23.join(cwd, LOCAL_SETTINGS2);
|
|
7758
8032
|
const settings = await readJson(settingsPath);
|
|
7759
8033
|
const enabled = settings?.enabledMcpjsonServers;
|
|
7760
8034
|
if (settings && Array.isArray(enabled) && enabled.includes(name)) {
|
|
@@ -7765,7 +8039,7 @@ function removeProjectServer(cwd, name) {
|
|
|
7765
8039
|
});
|
|
7766
8040
|
}
|
|
7767
8041
|
async function approve(cwd, name) {
|
|
7768
|
-
const file =
|
|
8042
|
+
const file = path23.join(cwd, LOCAL_SETTINGS2);
|
|
7769
8043
|
const settings = await readJson(file) ?? {};
|
|
7770
8044
|
const enabled = Array.isArray(settings.enabledMcpjsonServers) ? settings.enabledMcpjsonServers : [];
|
|
7771
8045
|
if (!enabled.includes(name))
|
|
@@ -7804,21 +8078,21 @@ function describeConfig(config) {
|
|
|
7804
8078
|
}
|
|
7805
8079
|
async function readJson(file) {
|
|
7806
8080
|
try {
|
|
7807
|
-
const raw = await
|
|
8081
|
+
const raw = await readFile17(file, "utf8");
|
|
7808
8082
|
const parsed = JSON.parse(raw);
|
|
7809
8083
|
return parsed && typeof parsed === "object" ? parsed : null;
|
|
7810
8084
|
} catch (error) {
|
|
7811
8085
|
if (error.code === "ENOENT")
|
|
7812
8086
|
return null;
|
|
7813
8087
|
if (error instanceof SyntaxError) {
|
|
7814
|
-
throw new Error(`\u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u0440\u0430\u0437\u043E\u0431\u0440\u0430\u0442\u044C ${
|
|
8088
|
+
throw new Error(`\u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u0440\u0430\u0437\u043E\u0431\u0440\u0430\u0442\u044C ${path23.basename(file)}: ${error.message}`);
|
|
7815
8089
|
}
|
|
7816
8090
|
throw error;
|
|
7817
8091
|
}
|
|
7818
8092
|
}
|
|
7819
8093
|
async function writeJson(file, data) {
|
|
7820
|
-
await
|
|
7821
|
-
await
|
|
8094
|
+
await mkdir14(path23.dirname(file), { recursive: true });
|
|
8095
|
+
await writeFile15(file, `${JSON.stringify(data, null, 2)}
|
|
7822
8096
|
`, "utf8");
|
|
7823
8097
|
}
|
|
7824
8098
|
|
|
@@ -7882,8 +8156,8 @@ var HostServer = class {
|
|
|
7882
8156
|
#limitTimer = null;
|
|
7883
8157
|
/** Идёт остановка у лимита — второй снимок лимитов её не запускает. */
|
|
7884
8158
|
#limitStopping = false;
|
|
7885
|
-
/** Последний снимок лимитов Claude — им сверяется ход без промпта. */
|
|
7886
|
-
#lastUsage =
|
|
8159
|
+
/** Последний снимок лимитов Claude по аккаунтам — им сверяется ход без промпта. */
|
|
8160
|
+
#lastUsage = /* @__PURE__ */ new Map();
|
|
7887
8161
|
/**
|
|
7888
8162
|
* Сессии, которым человек сам написал после срабатывания порога: id
|
|
7889
8163
|
* сессии → окно → срок, до которого оно было отмечено сработавшим. Это его
|
|
@@ -7895,9 +8169,13 @@ var HostServer = class {
|
|
|
7895
8169
|
#limitHandoffBusy = /* @__PURE__ */ new Set();
|
|
7896
8170
|
/** Живые id сессий, у которых сейчас пишется ручной хэндофф. */
|
|
7897
8171
|
#handoffBusy = /* @__PURE__ */ new Set();
|
|
7898
|
-
#hostId =
|
|
8172
|
+
#hostId = randomUUID6();
|
|
7899
8173
|
#plugins = new PluginCli();
|
|
7900
|
-
#
|
|
8174
|
+
#accounts;
|
|
8175
|
+
/** Вход у каждого аккаунта свой: у него свой каталог конфигурации и свой разговор с CLI. */
|
|
8176
|
+
#auths = /* @__PURE__ */ new Map();
|
|
8177
|
+
/** Чей транскрипт лежит под дисковым id сессии — заполняется списками сессий. */
|
|
8178
|
+
#diskAccounts = /* @__PURE__ */ new Map();
|
|
7901
8179
|
#relay;
|
|
7902
8180
|
#terminals = new TerminalHub();
|
|
7903
8181
|
#github;
|
|
@@ -7912,6 +8190,7 @@ var HostServer = class {
|
|
|
7912
8190
|
#gitBusy = /* @__PURE__ */ new Set();
|
|
7913
8191
|
constructor(options2) {
|
|
7914
8192
|
this.#options = options2;
|
|
8193
|
+
this.#accounts = new AccountStore(options2.dataDir);
|
|
7915
8194
|
this.#workspaces = new WorkspaceRegistry(options2.dataDir);
|
|
7916
8195
|
this.#archive = new SessionArchive(options2.dataDir);
|
|
7917
8196
|
this.#pins = new SessionPins(options2.dataDir);
|
|
@@ -7921,17 +8200,78 @@ var HostServer = class {
|
|
|
7921
8200
|
this.#antigravity = new AntigravityStore(options2.dataDir);
|
|
7922
8201
|
this.#handoffs = new HandoffStore(options2.dataDir);
|
|
7923
8202
|
this.#limitStop = new LimitStopState(options2.dataDir);
|
|
7924
|
-
this.#finder = new ProjectFinder(this.#workspaces);
|
|
8203
|
+
this.#finder = new ProjectFinder(this.#workspaces, () => this.#accounts.all.map((a) => a.configDir));
|
|
7925
8204
|
this.#relay = new RelayLink({ dataDir: options2.dataDir, defaultUrl: options2.relayUrl });
|
|
7926
8205
|
this.#github = new GitHubAccount(options2.dataDir);
|
|
7927
8206
|
this.#wireRelay();
|
|
7928
8207
|
this.#wireTerminals();
|
|
7929
|
-
|
|
7930
|
-
|
|
7931
|
-
|
|
7932
|
-
this.#
|
|
7933
|
-
|
|
7934
|
-
|
|
8208
|
+
}
|
|
8209
|
+
/** Вход аккаунта; создаётся при первом обращении и живёт, пока жив хост. */
|
|
8210
|
+
#authFor(accountId) {
|
|
8211
|
+
const account = this.#accounts.find(accountId);
|
|
8212
|
+
if (!account)
|
|
8213
|
+
throw new Error("\u0410\u043A\u043A\u0430\u0443\u043D\u0442 \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D");
|
|
8214
|
+
let auth = this.#auths.get(account.id);
|
|
8215
|
+
if (!auth) {
|
|
8216
|
+
auth = new AuthCli(account.configDir);
|
|
8217
|
+
auth.on("login", (state) => {
|
|
8218
|
+
this.#broadcast({ type: "auth.login", accountId: account.id, state });
|
|
8219
|
+
});
|
|
8220
|
+
auth.on("changed", () => {
|
|
8221
|
+
void this.#sendAuthStatus(account.id);
|
|
8222
|
+
});
|
|
8223
|
+
this.#auths.set(account.id, auth);
|
|
8224
|
+
}
|
|
8225
|
+
return auth;
|
|
8226
|
+
}
|
|
8227
|
+
/** Аккаунты для UI: с числом живых сессий, по которому решается, можно ли убрать аккаунт. */
|
|
8228
|
+
#accountList() {
|
|
8229
|
+
const live = [...this.#sessions.values()].filter((s) => s instanceof ClaudeSession && s.state !== "closed" && !s.summary().parentSessionId);
|
|
8230
|
+
return this.#accounts.all.map((a) => ({
|
|
8231
|
+
id: a.id,
|
|
8232
|
+
name: a.name,
|
|
8233
|
+
color: a.color,
|
|
8234
|
+
configDir: a.configDir,
|
|
8235
|
+
dir: this.#accounts.effectiveDir(a.id),
|
|
8236
|
+
main: a.id === MAIN_ACCOUNT_ID,
|
|
8237
|
+
liveSessions: live.filter((s) => s.accountId === a.id).length
|
|
8238
|
+
}));
|
|
8239
|
+
}
|
|
8240
|
+
/** Список аккаунтов и, для каждого, кто в нём вошёл. Вход спрашивается у CLI — это процесс на аккаунт. */
|
|
8241
|
+
async #accountsFrame() {
|
|
8242
|
+
const accounts = this.#accountList();
|
|
8243
|
+
const entries = await Promise.all(accounts.map(async (a) => {
|
|
8244
|
+
const status = await this.#authFor(a.id).status().catch(() => null);
|
|
8245
|
+
return [a.id, status];
|
|
8246
|
+
}));
|
|
8247
|
+
return { type: "accounts.state", accounts, auth: Object.fromEntries(entries) };
|
|
8248
|
+
}
|
|
8249
|
+
/**
|
|
8250
|
+
* Каталоги с входом, найденные на устройстве, и кто в них вошёл.
|
|
8251
|
+
* Кто вошёл — отвечает CLI; каталоги без входа в предложение не идут.
|
|
8252
|
+
*/
|
|
8253
|
+
async #discoverAccounts() {
|
|
8254
|
+
const dirs = await candidateConfigDirs();
|
|
8255
|
+
const results = await Promise.all(dirs.map(async (configDir) => {
|
|
8256
|
+
const status = await new AuthCli(configDir).status().catch(() => null);
|
|
8257
|
+
if (!status?.loggedIn)
|
|
8258
|
+
return null;
|
|
8259
|
+
const used = this.#accounts.all.find((a) => path24.resolve(this.#accounts.effectiveDir(a.id)).toLowerCase() === configDir.toLowerCase());
|
|
8260
|
+
return {
|
|
8261
|
+
configDir,
|
|
8262
|
+
email: status.email,
|
|
8263
|
+
plan: status.plan,
|
|
8264
|
+
organization: status.organization,
|
|
8265
|
+
accountId: used?.id ?? null
|
|
8266
|
+
};
|
|
8267
|
+
}));
|
|
8268
|
+
return results.filter((c) => c !== null);
|
|
8269
|
+
}
|
|
8270
|
+
async #sendAccounts() {
|
|
8271
|
+
this.#broadcast(await this.#accountsFrame());
|
|
8272
|
+
}
|
|
8273
|
+
#diskAccountList() {
|
|
8274
|
+
return this.#accounts.all.map((a) => ({ id: a.id, configDir: a.configDir }));
|
|
7935
8275
|
}
|
|
7936
8276
|
/**
|
|
7937
8277
|
* Перенести всё, что записано под id проектов прежнего формата, на нынешние.
|
|
@@ -7943,7 +8283,7 @@ var HostServer = class {
|
|
|
7943
8283
|
async #carryOverWorkspaceIds() {
|
|
7944
8284
|
const remap = workspaceIdRemap(this.#workspaces.paths(), async (dir) => {
|
|
7945
8285
|
const id = workspaceIdFromPath(dir);
|
|
7946
|
-
const onDisk = await this.#workspaces.sessionsOnDisk(id);
|
|
8286
|
+
const onDisk = await this.#workspaces.sessionsOnDisk(id, this.#diskAccountList());
|
|
7947
8287
|
const antigravity = await this.#antigravity.list(id);
|
|
7948
8288
|
return [...onDisk.map((s) => s.sessionId), ...antigravity.map((r) => r.id)];
|
|
7949
8289
|
});
|
|
@@ -7962,6 +8302,7 @@ var HostServer = class {
|
|
|
7962
8302
|
await this.#carryOverWorkspaceIds();
|
|
7963
8303
|
await this.#settings.load();
|
|
7964
8304
|
this.#wireNetworkGuard();
|
|
8305
|
+
await this.#accounts.load();
|
|
7965
8306
|
await this.#limitStop.load();
|
|
7966
8307
|
await this.#github.load();
|
|
7967
8308
|
await warmClaudeLauncher();
|
|
@@ -8015,7 +8356,8 @@ var HostServer = class {
|
|
|
8015
8356
|
if (this.#limitTimer)
|
|
8016
8357
|
clearInterval(this.#limitTimer);
|
|
8017
8358
|
this.#limitTimer = null;
|
|
8018
|
-
this.#
|
|
8359
|
+
for (const auth of this.#auths.values())
|
|
8360
|
+
auth.cancel();
|
|
8019
8361
|
this.#terminals.closeAll();
|
|
8020
8362
|
await this.#relay.close();
|
|
8021
8363
|
await Promise.all([...this.#sessions.values()].map((s) => s.close("host shutdown")));
|
|
@@ -8174,7 +8516,13 @@ var HostServer = class {
|
|
|
8174
8516
|
this.#sendFolders(socket);
|
|
8175
8517
|
this.#send(socket, { type: "order.state", order: this.#order.current });
|
|
8176
8518
|
this.#sendLive(socket);
|
|
8177
|
-
this.#
|
|
8519
|
+
this.#accountsFrame().then((frame2) => {
|
|
8520
|
+
this.#send(socket, frame2);
|
|
8521
|
+
for (const [accountId, status] of Object.entries(frame2.auth)) {
|
|
8522
|
+
if (status)
|
|
8523
|
+
this.#send(socket, { type: "auth.status", accountId, status });
|
|
8524
|
+
}
|
|
8525
|
+
}).catch(() => void 0);
|
|
8178
8526
|
this.#send(socket, { type: "relay.state", state: this.#relay.state });
|
|
8179
8527
|
this.#send(socket, { type: "network.state", state: networkGuard.state });
|
|
8180
8528
|
return;
|
|
@@ -8874,26 +9222,87 @@ var HostServer = class {
|
|
|
8874
9222
|
}
|
|
8875
9223
|
return;
|
|
8876
9224
|
}
|
|
8877
|
-
case "auth.status":
|
|
8878
|
-
|
|
8879
|
-
|
|
9225
|
+
case "auth.status": {
|
|
9226
|
+
const account = this.#accounts.find(frame.accountId);
|
|
9227
|
+
if (!account)
|
|
9228
|
+
throw new Error("\u0410\u043A\u043A\u0430\u0443\u043D\u0442 \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D");
|
|
9229
|
+
const auth = this.#authFor(account.id);
|
|
9230
|
+
this.#send(socket, {
|
|
9231
|
+
type: "auth.status",
|
|
9232
|
+
accountId: account.id,
|
|
9233
|
+
status: await auth.status()
|
|
9234
|
+
});
|
|
9235
|
+
this.#send(socket, { type: "auth.login", accountId: account.id, state: auth.loginState });
|
|
8880
9236
|
return;
|
|
9237
|
+
}
|
|
8881
9238
|
case "auth.login": {
|
|
8882
9239
|
const blocked = (await networkGuard.ensureFresh()).status === "blocked";
|
|
8883
9240
|
if (blocked)
|
|
8884
9241
|
throw new Error(`${networkGuard.blockedReason()}. \u0412\u0445\u043E\u0434 \u043E\u0442\u043B\u043E\u0436\u0435\u043D.`);
|
|
8885
|
-
await this.#
|
|
9242
|
+
await this.#authFor(frame.accountId).login(frame.mode, frame.switchAccount === true);
|
|
8886
9243
|
return;
|
|
8887
9244
|
}
|
|
8888
9245
|
case "auth.code":
|
|
8889
|
-
this.#
|
|
9246
|
+
this.#authFor(frame.accountId).submitCode(frame.code);
|
|
8890
9247
|
return;
|
|
8891
9248
|
case "auth.cancel":
|
|
8892
|
-
this.#
|
|
9249
|
+
this.#authFor(frame.accountId).cancel();
|
|
8893
9250
|
return;
|
|
8894
9251
|
case "auth.logout":
|
|
8895
|
-
await this.#
|
|
9252
|
+
await this.#authFor(frame.accountId).logout();
|
|
8896
9253
|
return;
|
|
9254
|
+
case "accounts.list":
|
|
9255
|
+
this.#send(socket, await this.#accountsFrame());
|
|
9256
|
+
return;
|
|
9257
|
+
case "accounts.add":
|
|
9258
|
+
await this.#accounts.add({
|
|
9259
|
+
name: frame.name,
|
|
9260
|
+
...frame.color ? { color: frame.color } : {},
|
|
9261
|
+
...frame.configDir ? { configDir: frame.configDir } : {},
|
|
9262
|
+
...frame.shareConfig ? { shareConfig: true } : {}
|
|
9263
|
+
});
|
|
9264
|
+
await this.#sendAccounts();
|
|
9265
|
+
return;
|
|
9266
|
+
case "accounts.update": {
|
|
9267
|
+
if (frame.configDir !== void 0) {
|
|
9268
|
+
const live = this.#accountList().find((a) => a.id === frame.accountId)?.liveSessions ?? 0;
|
|
9269
|
+
if (live > 0) {
|
|
9270
|
+
throw new Error("\u041F\u043E\u0434 \u044D\u0442\u0438\u043C \u0430\u043A\u043A\u0430\u0443\u043D\u0442\u043E\u043C \u0438\u0434\u0443\u0442 \u0441\u0435\u0441\u0441\u0438\u0438 \u2014 \u0437\u0430\u043A\u0440\u043E\u0439\u0442\u0435 \u0438\u0445, \u043F\u043E\u0442\u043E\u043C \u043C\u0435\u043D\u044F\u0439\u0442\u0435 \u043A\u0430\u0442\u0430\u043B\u043E\u0433");
|
|
9271
|
+
}
|
|
9272
|
+
}
|
|
9273
|
+
await this.#accounts.update(frame.accountId, {
|
|
9274
|
+
...frame.name !== void 0 ? { name: frame.name } : {},
|
|
9275
|
+
...frame.color ? { color: frame.color } : {},
|
|
9276
|
+
...frame.configDir !== void 0 ? { configDir: frame.configDir } : {}
|
|
9277
|
+
});
|
|
9278
|
+
if (frame.configDir !== void 0) {
|
|
9279
|
+
this.#authFor(frame.accountId).cancel();
|
|
9280
|
+
this.#auths.delete(frame.accountId);
|
|
9281
|
+
}
|
|
9282
|
+
await this.#sendAccounts();
|
|
9283
|
+
return;
|
|
9284
|
+
}
|
|
9285
|
+
case "accounts.discover":
|
|
9286
|
+
this.#send(socket, {
|
|
9287
|
+
type: "accounts.candidates",
|
|
9288
|
+
candidates: await this.#discoverAccounts()
|
|
9289
|
+
});
|
|
9290
|
+
return;
|
|
9291
|
+
case "accounts.remove": {
|
|
9292
|
+
const account = this.#accountList().find((a) => a.id === frame.accountId);
|
|
9293
|
+
if (!account)
|
|
9294
|
+
return;
|
|
9295
|
+
if (account.main)
|
|
9296
|
+
throw new Error("\u041E\u0441\u043D\u043E\u0432\u043D\u043E\u0439 \u0430\u043A\u043A\u0430\u0443\u043D\u0442 \u0443\u0434\u0430\u043B\u0438\u0442\u044C \u043D\u0435\u043B\u044C\u0437\u044F");
|
|
9297
|
+
if (account.liveSessions > 0) {
|
|
9298
|
+
throw new Error("\u041F\u043E\u0434 \u044D\u0442\u0438\u043C \u0430\u043A\u043A\u0430\u0443\u043D\u0442\u043E\u043C \u0438\u0434\u0443\u0442 \u0441\u0435\u0441\u0441\u0438\u0438 \u2014 \u0437\u0430\u043A\u0440\u043E\u0439\u0442\u0435 \u0438\u0445, \u043F\u043E\u0442\u043E\u043C \u0443\u0434\u0430\u043B\u044F\u0439\u0442\u0435 \u0430\u043A\u043A\u0430\u0443\u043D\u0442");
|
|
9299
|
+
}
|
|
9300
|
+
this.#auths.get(account.id)?.cancel();
|
|
9301
|
+
this.#auths.delete(account.id);
|
|
9302
|
+
await this.#accounts.remove(account.id);
|
|
9303
|
+
await this.#sendAccounts();
|
|
9304
|
+
return;
|
|
9305
|
+
}
|
|
8897
9306
|
case "relay.status":
|
|
8898
9307
|
this.#send(socket, { type: "relay.state", state: this.#relay.state });
|
|
8899
9308
|
return;
|
|
@@ -8952,8 +9361,13 @@ var HostServer = class {
|
|
|
8952
9361
|
return;
|
|
8953
9362
|
throw new Error(`${action} \u043C\u043E\u0436\u043D\u043E \u0442\u043E\u043B\u044C\u043A\u043E \u043D\u0430 \u043D\u0451\u043C \u0441\u0430\u043C\u043E\u043C, \u043D\u0435 \u0443\u0434\u0430\u043B\u0451\u043D\u043D\u043E`);
|
|
8954
9363
|
}
|
|
8955
|
-
async #sendAuthStatus() {
|
|
8956
|
-
this.#broadcast({
|
|
9364
|
+
async #sendAuthStatus(accountId) {
|
|
9365
|
+
this.#broadcast({
|
|
9366
|
+
type: "auth.status",
|
|
9367
|
+
accountId,
|
|
9368
|
+
status: await this.#authFor(accountId).status()
|
|
9369
|
+
});
|
|
9370
|
+
await this.#sendAccounts();
|
|
8957
9371
|
}
|
|
8958
9372
|
// -------------------------------------------------------------------------
|
|
8959
9373
|
// MCP и плагины
|
|
@@ -9019,11 +9433,11 @@ var HostServer = class {
|
|
|
9019
9433
|
* CLI показываем как результат операции, а не роняем кадр: пользователь
|
|
9020
9434
|
* должен увидеть текст «маркетплейс не найден», а не молчание.
|
|
9021
9435
|
*/
|
|
9022
|
-
async #pluginOperation(sessionId,
|
|
9436
|
+
async #pluginOperation(sessionId, run) {
|
|
9023
9437
|
let ok = true;
|
|
9024
9438
|
let message;
|
|
9025
9439
|
try {
|
|
9026
|
-
message = await
|
|
9440
|
+
message = await run() || "\u0413\u043E\u0442\u043E\u0432\u043E";
|
|
9027
9441
|
} catch (error) {
|
|
9028
9442
|
ok = false;
|
|
9029
9443
|
message = error instanceof Error ? error.message : String(error);
|
|
@@ -9201,21 +9615,26 @@ var HostServer = class {
|
|
|
9201
9615
|
* прошёл бы мимо порога. Лимиты общие на аккаунт — спросить одну хватит.
|
|
9202
9616
|
*/
|
|
9203
9617
|
#sweepUsage() {
|
|
9204
|
-
const
|
|
9205
|
-
|
|
9206
|
-
|
|
9618
|
+
const asked = /* @__PURE__ */ new Set();
|
|
9619
|
+
for (const session of this.#claudeUserSessions()) {
|
|
9620
|
+
if (asked.has(session.accountId) || !this.#isBusy(session))
|
|
9621
|
+
continue;
|
|
9622
|
+
asked.add(session.accountId);
|
|
9623
|
+
void session.refreshUsage();
|
|
9624
|
+
}
|
|
9207
9625
|
}
|
|
9208
|
-
async #checkLimit(usage) {
|
|
9209
|
-
this.#lastUsage
|
|
9626
|
+
async #checkLimit(usage, accountId) {
|
|
9627
|
+
this.#lastUsage.set(accountId, usage);
|
|
9210
9628
|
if (this.#limitStopping)
|
|
9211
9629
|
return;
|
|
9212
|
-
const
|
|
9630
|
+
const stops = this.#limitStop.forAccount(accountId);
|
|
9631
|
+
const hit = crossedLimit(usage, this.#settings.current, (limit, resets) => stops.fired(limit, resets));
|
|
9213
9632
|
if (!hit)
|
|
9214
9633
|
return;
|
|
9215
9634
|
this.#limitStopping = true;
|
|
9216
9635
|
try {
|
|
9217
|
-
await
|
|
9218
|
-
await this.#stopAtLimit(hit);
|
|
9636
|
+
await stops.mark(hit.limit, hit.until);
|
|
9637
|
+
await this.#stopAtLimit(hit, accountId);
|
|
9219
9638
|
} catch (error) {
|
|
9220
9639
|
console.error("[limit-stop]", error instanceof Error ? error.message : String(error));
|
|
9221
9640
|
} finally {
|
|
@@ -9231,8 +9650,10 @@ var HostServer = class {
|
|
|
9231
9650
|
#approveAfterLimit(sessionId) {
|
|
9232
9651
|
const now = Date.now();
|
|
9233
9652
|
const approved = {};
|
|
9653
|
+
const accountId = this.#sessions.get(sessionId);
|
|
9654
|
+
const stops = this.#limitStop.forAccount(accountId instanceof ClaudeSession ? accountId.accountId : MAIN_ACCOUNT_ID);
|
|
9234
9655
|
for (const limit of ["fiveHour", "sevenDay"]) {
|
|
9235
|
-
const until =
|
|
9656
|
+
const until = stops.until(limit);
|
|
9236
9657
|
if (until > now)
|
|
9237
9658
|
approved[limit] = until;
|
|
9238
9659
|
}
|
|
@@ -9253,14 +9674,16 @@ var HostServer = class {
|
|
|
9253
9674
|
* срабатывало, здесь не трогаем: его поймает обычный `#checkLimit`.
|
|
9254
9675
|
*/
|
|
9255
9676
|
async #checkUnpromptedTurn(session) {
|
|
9256
|
-
|
|
9677
|
+
const lastUsage = this.#lastUsage.get(session.accountId);
|
|
9678
|
+
if (!lastUsage || this.#limitStopping)
|
|
9257
9679
|
return;
|
|
9680
|
+
const stops = this.#limitStop.forAccount(session.accountId);
|
|
9258
9681
|
if (this.#limitHandoffBusy.has(session.id) || this.#handoffBusy.has(session.id))
|
|
9259
9682
|
return;
|
|
9260
9683
|
if (!this.#claudeUserSessions().includes(session))
|
|
9261
9684
|
return;
|
|
9262
9685
|
const approved = this.#limitApproved.get(session.id) ?? {};
|
|
9263
|
-
const hit = crossedLimit(
|
|
9686
|
+
const hit = crossedLimit(lastUsage, this.#settings.current, (limit, resets) => !stops.fired(limit, resets) || approved[limit] === stops.until(limit));
|
|
9264
9687
|
if (!hit)
|
|
9265
9688
|
return;
|
|
9266
9689
|
const saved = await this.#limitHandoff(session, hit);
|
|
@@ -9280,8 +9703,8 @@ var HostServer = class {
|
|
|
9280
9703
|
* когда из её хэндоффа продолжили в новой (см. `continueFromHandoff` в
|
|
9281
9704
|
* окне).
|
|
9282
9705
|
*/
|
|
9283
|
-
async #stopAtLimit(hit) {
|
|
9284
|
-
const sessions = this.#claudeUserSessions();
|
|
9706
|
+
async #stopAtLimit(hit, accountId) {
|
|
9707
|
+
const sessions = this.#claudeUserSessions().filter((s) => s.accountId === accountId);
|
|
9285
9708
|
if (sessions.length === 0)
|
|
9286
9709
|
return;
|
|
9287
9710
|
const now = Date.now();
|
|
@@ -9441,13 +9864,19 @@ var HostServer = class {
|
|
|
9441
9864
|
this.#send(socket, { type: "session.summary", session: session2.summary() });
|
|
9442
9865
|
return;
|
|
9443
9866
|
}
|
|
9444
|
-
const
|
|
9867
|
+
const onDisk = frame.resume ? (await this.#workspaces.sessionsOnDisk(workspace.id, this.#diskAccountList())).find((info) => info.sessionId === frame.resume) : void 0;
|
|
9868
|
+
const resumed = onDisk && !frame.fork ? onDisk : void 0;
|
|
9445
9869
|
const resumedTitle = resumed ? diskTitle(resumed) : null;
|
|
9870
|
+
const account = this.#accounts.find(onDisk?.accountId ?? frame.accountId);
|
|
9871
|
+
if (!account)
|
|
9872
|
+
throw new Error("\u0410\u043A\u043A\u0430\u0443\u043D\u0442 \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D");
|
|
9446
9873
|
if (frame.resume)
|
|
9447
9874
|
await this.#archive.unarchive([frame.resume]);
|
|
9448
9875
|
const startDefaults = this.#settings.current;
|
|
9449
9876
|
const session = new ClaudeSession({
|
|
9450
9877
|
workspaceId: workspace.id,
|
|
9878
|
+
accountId: account.id,
|
|
9879
|
+
configDir: account.configDir,
|
|
9451
9880
|
cwd: workspace.path,
|
|
9452
9881
|
resume: frame.resume,
|
|
9453
9882
|
fork: frame.fork,
|
|
@@ -9574,7 +10003,7 @@ var HostServer = class {
|
|
|
9574
10003
|
session.on("usage", (usage) => {
|
|
9575
10004
|
this.#broadcast({ type: "usage.state", sessionId: session.id, usage });
|
|
9576
10005
|
if (session instanceof ClaudeSession)
|
|
9577
|
-
void this.#checkLimit(usage);
|
|
10006
|
+
void this.#checkLimit(usage, session.accountId);
|
|
9578
10007
|
});
|
|
9579
10008
|
if (session instanceof ClaudeSession) {
|
|
9580
10009
|
session.on("unpromptedTurn", () => void this.#checkUnpromptedTurn(session));
|
|
@@ -9613,6 +10042,9 @@ var HostServer = class {
|
|
|
9613
10042
|
const claudeId = parent.claudeSessionId;
|
|
9614
10043
|
const side = new ClaudeSession({
|
|
9615
10044
|
workspaceId: parent.workspaceId,
|
|
10045
|
+
// Вопрос на полях — тот же разговор, значит и тот же аккаунт: форк читает
|
|
10046
|
+
// транскрипт родителя из его каталога.
|
|
10047
|
+
...parent instanceof ClaudeSession ? { accountId: parent.accountId, configDir: parent.configDir } : {},
|
|
9616
10048
|
cwd: parent.cwd,
|
|
9617
10049
|
parentSessionId: parent.id,
|
|
9618
10050
|
readOnly: true,
|
|
@@ -9661,7 +10093,7 @@ var HostServer = class {
|
|
|
9661
10093
|
*/
|
|
9662
10094
|
#roots() {
|
|
9663
10095
|
const roots = this.#finder.roots();
|
|
9664
|
-
return roots.length > 0 ? roots : [
|
|
10096
|
+
return roots.length > 0 ? roots : [homedir7()];
|
|
9665
10097
|
}
|
|
9666
10098
|
/**
|
|
9667
10099
|
* Где сессии этого каталога разрешено писать без вопроса.
|
|
@@ -9750,12 +10182,12 @@ var HostServer = class {
|
|
|
9750
10182
|
* его как есть. Своей формулировки у нас нет и быть не должно: git объясняет
|
|
9751
10183
|
* отказ («ваши правки будут перезаписаны», «обновлений нет») точнее.
|
|
9752
10184
|
*/
|
|
9753
|
-
async #gitOperation(workspaceId,
|
|
10185
|
+
async #gitOperation(workspaceId, run) {
|
|
9754
10186
|
let ok = true;
|
|
9755
10187
|
let message = "";
|
|
9756
10188
|
let url2;
|
|
9757
10189
|
try {
|
|
9758
|
-
const outcome = await
|
|
10190
|
+
const outcome = await run(this.#git(workspaceId));
|
|
9759
10191
|
message = outcome.message;
|
|
9760
10192
|
url2 = outcome.url;
|
|
9761
10193
|
} catch (error) {
|
|
@@ -9775,7 +10207,7 @@ var HostServer = class {
|
|
|
9775
10207
|
* рассылается всем по той же причине, по которой рассылается итог, — вкладки
|
|
9776
10208
|
* смотрят в один каталог.
|
|
9777
10209
|
*/
|
|
9778
|
-
async #gitNetwork(workspaceId, label,
|
|
10210
|
+
async #gitNetwork(workspaceId, label, run) {
|
|
9779
10211
|
if (this.#gitBusy.has(workspaceId)) {
|
|
9780
10212
|
this.#broadcast({
|
|
9781
10213
|
type: "git.result",
|
|
@@ -9788,7 +10220,7 @@ var HostServer = class {
|
|
|
9788
10220
|
this.#gitBusy.add(workspaceId);
|
|
9789
10221
|
this.#broadcast({ type: "git.busy", workspaceId, label });
|
|
9790
10222
|
try {
|
|
9791
|
-
await this.#gitOperation(workspaceId,
|
|
10223
|
+
await this.#gitOperation(workspaceId, run);
|
|
9792
10224
|
} finally {
|
|
9793
10225
|
this.#gitBusy.delete(workspaceId);
|
|
9794
10226
|
this.#broadcast({ type: "git.busy", workspaceId, label: "" });
|
|
@@ -9909,7 +10341,8 @@ var HostServer = class {
|
|
|
9909
10341
|
return;
|
|
9910
10342
|
}
|
|
9911
10343
|
const dir = workspaceId ? this.#workspaces.find(workspaceId)?.path : void 0;
|
|
9912
|
-
|
|
10344
|
+
const configDir = this.#accounts.configDir(this.#diskAccounts.get(sessionId));
|
|
10345
|
+
await withConfigDir(configDir, () => renameSession2(sessionId, title, dir ? { dir } : void 0));
|
|
9913
10346
|
if (!workspaceId)
|
|
9914
10347
|
return;
|
|
9915
10348
|
await this.#sendSessionList(workspaceId);
|
|
@@ -9925,11 +10358,14 @@ var HostServer = class {
|
|
|
9925
10358
|
async #listSessions(workspaceId) {
|
|
9926
10359
|
const live = [...this.#sessions.values()].filter((s) => s.workspaceId === workspaceId && !s.parentSessionId).map((s) => s.summary());
|
|
9927
10360
|
const liveIds = new Set(live.flatMap((s) => s.claudeSessionId ? [s.id, s.claudeSessionId] : [s.id]));
|
|
9928
|
-
const onDisk = await this.#workspaces.sessionsOnDisk(workspaceId);
|
|
10361
|
+
const onDisk = await this.#workspaces.sessionsOnDisk(workspaceId, this.#diskAccountList());
|
|
10362
|
+
for (const info of onDisk)
|
|
10363
|
+
this.#diskAccounts.set(info.sessionId, info.accountId);
|
|
9929
10364
|
const workspacePath = this.#workspaces.find(workspaceId)?.path ?? "";
|
|
9930
10365
|
const historical = onDisk.filter((info) => !liveIds.has(info.sessionId) && info.customTitle !== SIDE_TITLE && info.customTitle !== FINDER_TITLE).map((info) => ({
|
|
9931
10366
|
id: info.sessionId,
|
|
9932
10367
|
provider: "claude",
|
|
10368
|
+
accountId: info.accountId,
|
|
9933
10369
|
claudeSessionId: info.sessionId,
|
|
9934
10370
|
workspaceId,
|
|
9935
10371
|
cwd: info.cwd ?? workspacePath,
|
|
@@ -10012,8 +10448,8 @@ var HostServer = class {
|
|
|
10012
10448
|
return;
|
|
10013
10449
|
}
|
|
10014
10450
|
const url2 = new URL(req.url ?? "/", "http://localhost");
|
|
10015
|
-
const requested =
|
|
10016
|
-
const target = requested.startsWith(webRoot) && existsSync4(requested) && statSync3(requested).isFile() ? requested :
|
|
10451
|
+
const requested = path24.join(webRoot, path24.normalize(url2.pathname));
|
|
10452
|
+
const target = requested.startsWith(webRoot) && existsSync4(requested) && statSync3(requested).isFile() ? requested : path24.join(webRoot, "index.html");
|
|
10017
10453
|
if (!existsSync4(target)) {
|
|
10018
10454
|
res.writeHead(404).end("not found");
|
|
10019
10455
|
return;
|
|
@@ -10039,7 +10475,7 @@ function contentType(file) {
|
|
|
10039
10475
|
".svg": "image/svg+xml",
|
|
10040
10476
|
".woff2": "font/woff2"
|
|
10041
10477
|
};
|
|
10042
|
-
return types[
|
|
10478
|
+
return types[path24.extname(file)] ?? "application/octet-stream";
|
|
10043
10479
|
}
|
|
10044
10480
|
function antigravitySummary(record) {
|
|
10045
10481
|
return {
|
|
@@ -10063,13 +10499,14 @@ function antigravitySummary(record) {
|
|
|
10063
10499
|
createdAt: record.createdAt,
|
|
10064
10500
|
updatedAt: record.updatedAt,
|
|
10065
10501
|
lastSeq: 0,
|
|
10066
|
-
totalCostUsd: 0
|
|
10502
|
+
totalCostUsd: 0,
|
|
10503
|
+
accountId: MAIN_ACCOUNT_ID
|
|
10067
10504
|
};
|
|
10068
10505
|
}
|
|
10069
10506
|
|
|
10070
10507
|
// dist/ccv.js
|
|
10071
|
-
var HERE =
|
|
10072
|
-
var PACKAGE_ROOT =
|
|
10508
|
+
var HERE = path25.dirname(fileURLToPath(import.meta.url));
|
|
10509
|
+
var PACKAGE_ROOT = path25.resolve(HERE, "..");
|
|
10073
10510
|
var USAGE = `ccv \u2014 Claude Code Visual: \u043B\u043E\u043A\u0430\u043B\u044C\u043D\u044B\u0439 \u0445\u043E\u0441\u0442 Claude Code \u0441 \u0438\u043D\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043E\u043C \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435.
|
|
10074
10511
|
|
|
10075
10512
|
\u0418\u0441\u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u043D\u0438\u0435:
|
|
@@ -10136,7 +10573,7 @@ var server = new HostServer({
|
|
|
10136
10573
|
dataDir: defaults.dataDir,
|
|
10137
10574
|
// UI лежит в пакете рядом с бандлом — это и есть разница между установленной
|
|
10138
10575
|
// утилитой и запуском из репозитория, где сборка живёт в `apps/web/dist`.
|
|
10139
|
-
webRoot: process.env.CCV_WEB_ROOT ??
|
|
10576
|
+
webRoot: process.env.CCV_WEB_ROOT ?? path25.join(PACKAGE_ROOT, "web"),
|
|
10140
10577
|
version,
|
|
10141
10578
|
relayUrl: defaults.relayUrl
|
|
10142
10579
|
});
|
|
@@ -10165,7 +10602,7 @@ for (const signal of ["SIGINT", "SIGTERM"]) {
|
|
|
10165
10602
|
}
|
|
10166
10603
|
async function packageVersion() {
|
|
10167
10604
|
try {
|
|
10168
|
-
const text = await
|
|
10605
|
+
const text = await readFile18(path25.join(PACKAGE_ROOT, "package.json"), "utf8");
|
|
10169
10606
|
return JSON.parse(text).version ?? "0.0.0";
|
|
10170
10607
|
} catch {
|
|
10171
10608
|
return "0.0.0";
|