@i14ks/ccv 0.40.0 → 0.41.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 +682 -145
- package/package.json +1 -1
- package/web/assets/{codemirror-BFhD_Qok.js → codemirror-C7ncOGRE.js} +1 -1
- package/web/assets/{index-DkREaKVS.js → index-B6SbCHNs.js} +1 -1
- package/web/assets/{index-BfM9EE1E.js → index-ByPaT86Z.js} +1 -1
- package/web/assets/{index-MdNspwJW.js → index-C9SHiRKM.js} +1 -1
- package/web/assets/{index-D6n8Nr5h.js → index-CKUFFbgO.js} +1 -1
- package/web/assets/index-CL7y2p8M.css +1 -0
- package/web/assets/{index-BKQ3S7R4.js → index-CsyDtSOz.js} +1 -1
- package/web/assets/{index-C--xwv_c.js → index-DAhGVz9l.js} +1 -1
- package/web/assets/{index-CO8tJjX2.js → index-DBd39l9w.js} +1 -1
- package/web/assets/{index-BeqGzcF4.js → index-DESWt0J-.js} +1 -1
- package/web/assets/{index-C0UJgxDk.js → index-DIYlBrHM.js} +1 -1
- package/web/assets/{index-DGvQxxdB.js → index-DT87d1u7.js} +1 -1
- package/web/assets/{index-Bng1dR8P.js → index-DUmwyjTs.js} +1 -1
- package/web/assets/{index-DswRCrFR.js → index-DbpgHwuN.js} +1 -1
- package/web/assets/{index-CTd3OD36.js → index-DhAerBFd.js} +1 -1
- package/web/assets/{index-Sbrdg0Zd.js → index-DhgfBw2g.js} +1 -1
- package/web/assets/{index-DwvMx-lF.js → index-DmvmY_EO.js} +1 -1
- package/web/assets/{index-Cp-Vx5md.js → index-FUThRvFr.js} +1 -1
- package/web/assets/{index-BqphMi4s.js → index-ho2UOt4o.js} +1 -1
- package/web/assets/{index-H0NO4iIy.js → index-q4sLKQTB.js} +1 -1
- package/web/assets/{index-Jk59gidx.js → index-u1Bw0k90.js} +1 -1
- package/web/assets/index-wyRPpjK-.js +134 -0
- package/web/index.html +2 -2
- package/web/assets/index-D48z24MD.js +0 -134
- package/web/assets/index-DmlVq6mR.css +0 -1
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 readFile19 } from "node:fs/promises";
|
|
6
|
+
import path27 from "node:path";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
8
|
import { parseArgs } from "node:util";
|
|
9
9
|
|
|
@@ -146,9 +146,9 @@ function envDefaults() {
|
|
|
146
146
|
|
|
147
147
|
// ../host/dist/server.js
|
|
148
148
|
import { createServer } from "node:http";
|
|
149
|
-
import { createReadStream, existsSync as
|
|
150
|
-
import
|
|
151
|
-
import { homedir as
|
|
149
|
+
import { createReadStream, existsSync as existsSync6, statSync as statSync3 } from "node:fs";
|
|
150
|
+
import path26 from "node:path";
|
|
151
|
+
import { homedir as homedir8 } from "node:os";
|
|
152
152
|
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
153
153
|
import { WebSocketServer } from "ws";
|
|
154
154
|
import { renameSession as renameSession2 } from "@anthropic-ai/claude-agent-sdk";
|
|
@@ -198,6 +198,56 @@ function hashText(text) {
|
|
|
198
198
|
return (4294967296 * (2097151 & h2) + (h1 >>> 0)).toString(36);
|
|
199
199
|
}
|
|
200
200
|
|
|
201
|
+
// ../host/dist/usage-probe.js
|
|
202
|
+
import { query } from "@anthropic-ai/claude-agent-sdk";
|
|
203
|
+
|
|
204
|
+
// ../host/dist/async-queue.js
|
|
205
|
+
var AsyncQueue = class {
|
|
206
|
+
#items = [];
|
|
207
|
+
#resolvers = [];
|
|
208
|
+
#closed = false;
|
|
209
|
+
push(item) {
|
|
210
|
+
if (this.#closed)
|
|
211
|
+
return;
|
|
212
|
+
const resolve = this.#resolvers.shift();
|
|
213
|
+
if (resolve) {
|
|
214
|
+
resolve({ value: item, done: false });
|
|
215
|
+
} else {
|
|
216
|
+
this.#items.push(item);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
close() {
|
|
220
|
+
if (this.#closed)
|
|
221
|
+
return;
|
|
222
|
+
this.#closed = true;
|
|
223
|
+
for (const resolve of this.#resolvers) {
|
|
224
|
+
resolve({ value: void 0, done: true });
|
|
225
|
+
}
|
|
226
|
+
this.#resolvers = [];
|
|
227
|
+
}
|
|
228
|
+
get closed() {
|
|
229
|
+
return this.#closed;
|
|
230
|
+
}
|
|
231
|
+
[Symbol.asyncIterator]() {
|
|
232
|
+
return {
|
|
233
|
+
next: () => {
|
|
234
|
+
const item = this.#items.shift();
|
|
235
|
+
if (item !== void 0) {
|
|
236
|
+
return Promise.resolve({ value: item, done: false });
|
|
237
|
+
}
|
|
238
|
+
if (this.#closed) {
|
|
239
|
+
return Promise.resolve({ value: void 0, done: true });
|
|
240
|
+
}
|
|
241
|
+
return new Promise((resolve) => this.#resolvers.push(resolve));
|
|
242
|
+
},
|
|
243
|
+
return: () => {
|
|
244
|
+
this.close();
|
|
245
|
+
return Promise.resolve({ value: void 0, done: true });
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
|
|
201
251
|
// ../host/dist/accounts.js
|
|
202
252
|
import { randomUUID } from "node:crypto";
|
|
203
253
|
import { lstat, mkdir, readFile as readFile2, readdir, rename, stat, symlink, writeFile } from "node:fs/promises";
|
|
@@ -405,7 +455,7 @@ async function exists(file) {
|
|
|
405
455
|
return lstat(file).then(() => true, () => false);
|
|
406
456
|
}
|
|
407
457
|
async function isRealEntry(file) {
|
|
408
|
-
return lstat(file).then((
|
|
458
|
+
return lstat(file).then((stat4) => !stat4.isSymbolicLink(), () => false);
|
|
409
459
|
}
|
|
410
460
|
async function candidateConfigDirs() {
|
|
411
461
|
const home = homedir2();
|
|
@@ -430,15 +480,70 @@ async function isDirectory(file) {
|
|
|
430
480
|
return stat(file).then((s) => s.isDirectory(), () => false);
|
|
431
481
|
}
|
|
432
482
|
|
|
483
|
+
// ../host/dist/usage-probe.js
|
|
484
|
+
var PROBE_TIMEOUT_MS = 2e4;
|
|
485
|
+
async function probeUsage(configDir) {
|
|
486
|
+
const inbox = new AsyncQueue();
|
|
487
|
+
const options2 = { settingSources: [], persistSession: false };
|
|
488
|
+
const executable = claudeExecutable();
|
|
489
|
+
if (executable.path) {
|
|
490
|
+
options2.pathToClaudeCodeExecutable = executable.path;
|
|
491
|
+
if (executable.executable)
|
|
492
|
+
options2.executable = executable.executable;
|
|
493
|
+
}
|
|
494
|
+
if (configDir)
|
|
495
|
+
options2.env = accountEnv(configDir);
|
|
496
|
+
const q = query({ prompt: inbox, options: options2 });
|
|
497
|
+
let timer;
|
|
498
|
+
try {
|
|
499
|
+
const raw = await Promise.race([
|
|
500
|
+
q.usage_EXPERIMENTAL_MAY_CHANGE_DO_NOT_RELY_ON_THIS_API_YET(),
|
|
501
|
+
new Promise((_, reject) => {
|
|
502
|
+
timer = setTimeout(() => reject(new Error("usage probe timeout")), PROBE_TIMEOUT_MS);
|
|
503
|
+
})
|
|
504
|
+
]);
|
|
505
|
+
return toUsageState(raw);
|
|
506
|
+
} catch {
|
|
507
|
+
return null;
|
|
508
|
+
} finally {
|
|
509
|
+
if (timer)
|
|
510
|
+
clearTimeout(timer);
|
|
511
|
+
inbox.close();
|
|
512
|
+
try {
|
|
513
|
+
q.close();
|
|
514
|
+
} catch {
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
function toUsageState(raw) {
|
|
519
|
+
const limits = raw.rate_limits ?? {};
|
|
520
|
+
return {
|
|
521
|
+
available: raw.rate_limits_available === true,
|
|
522
|
+
plan: raw.subscription_type ?? "",
|
|
523
|
+
fiveHour: toWindow(limits.five_hour),
|
|
524
|
+
sevenDay: toWindow(limits.seven_day),
|
|
525
|
+
sevenDayOpus: toWindow(limits.seven_day_opus),
|
|
526
|
+
fetchedAt: Date.now()
|
|
527
|
+
};
|
|
528
|
+
}
|
|
529
|
+
function toWindow(raw) {
|
|
530
|
+
if (!raw || typeof raw.utilization !== "number")
|
|
531
|
+
return null;
|
|
532
|
+
return {
|
|
533
|
+
utilization: Math.min(100, Math.max(0, raw.utilization)),
|
|
534
|
+
resetsAt: typeof raw.resets_at === "string" ? raw.resets_at : ""
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
|
|
433
538
|
// ../host/dist/workspace-ids.js
|
|
434
539
|
function workspaceIdRemap(paths, sessionsOf) {
|
|
435
540
|
const byLegacy = /* @__PURE__ */ new Map();
|
|
436
|
-
for (const
|
|
437
|
-
const id = workspaceIdFromPath(
|
|
438
|
-
for (const legacy of formerWorkspaceIdsFromPath(
|
|
541
|
+
for (const path28 of paths) {
|
|
542
|
+
const id = workspaceIdFromPath(path28);
|
|
543
|
+
for (const legacy of formerWorkspaceIdsFromPath(path28)) {
|
|
439
544
|
const group = byLegacy.get(legacy) ?? [];
|
|
440
545
|
if (!group.some((target) => target.id === id))
|
|
441
|
-
group.push({ id, path:
|
|
546
|
+
group.push({ id, path: path28 });
|
|
442
547
|
byLegacy.set(legacy, group);
|
|
443
548
|
}
|
|
444
549
|
}
|
|
@@ -472,54 +577,7 @@ function workspaceIdRemap(paths, sessionsOf) {
|
|
|
472
577
|
import { EventEmitter as EventEmitter2 } from "node:events";
|
|
473
578
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
474
579
|
import path6 from "node:path";
|
|
475
|
-
import { query, renameSession } from "@anthropic-ai/claude-agent-sdk";
|
|
476
|
-
|
|
477
|
-
// ../host/dist/async-queue.js
|
|
478
|
-
var AsyncQueue = class {
|
|
479
|
-
#items = [];
|
|
480
|
-
#resolvers = [];
|
|
481
|
-
#closed = false;
|
|
482
|
-
push(item) {
|
|
483
|
-
if (this.#closed)
|
|
484
|
-
return;
|
|
485
|
-
const resolve = this.#resolvers.shift();
|
|
486
|
-
if (resolve) {
|
|
487
|
-
resolve({ value: item, done: false });
|
|
488
|
-
} else {
|
|
489
|
-
this.#items.push(item);
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
close() {
|
|
493
|
-
if (this.#closed)
|
|
494
|
-
return;
|
|
495
|
-
this.#closed = true;
|
|
496
|
-
for (const resolve of this.#resolvers) {
|
|
497
|
-
resolve({ value: void 0, done: true });
|
|
498
|
-
}
|
|
499
|
-
this.#resolvers = [];
|
|
500
|
-
}
|
|
501
|
-
get closed() {
|
|
502
|
-
return this.#closed;
|
|
503
|
-
}
|
|
504
|
-
[Symbol.asyncIterator]() {
|
|
505
|
-
return {
|
|
506
|
-
next: () => {
|
|
507
|
-
const item = this.#items.shift();
|
|
508
|
-
if (item !== void 0) {
|
|
509
|
-
return Promise.resolve({ value: item, done: false });
|
|
510
|
-
}
|
|
511
|
-
if (this.#closed) {
|
|
512
|
-
return Promise.resolve({ value: void 0, done: true });
|
|
513
|
-
}
|
|
514
|
-
return new Promise((resolve) => this.#resolvers.push(resolve));
|
|
515
|
-
},
|
|
516
|
-
return: () => {
|
|
517
|
-
this.close();
|
|
518
|
-
return Promise.resolve({ value: void 0, done: true });
|
|
519
|
-
}
|
|
520
|
-
};
|
|
521
|
-
}
|
|
522
|
-
};
|
|
580
|
+
import { query as query2, renameSession } from "@anthropic-ai/claude-agent-sdk";
|
|
523
581
|
|
|
524
582
|
// ../host/dist/files.js
|
|
525
583
|
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";
|
|
@@ -593,8 +651,8 @@ var ProjectFiles = class {
|
|
|
593
651
|
* он один раз проверяет корень, а дальше обход и так не выходит за
|
|
594
652
|
* найденные внутри него каталоги.
|
|
595
653
|
*/
|
|
596
|
-
async search(
|
|
597
|
-
const needle =
|
|
654
|
+
async search(query3) {
|
|
655
|
+
const needle = query3.trim().toLowerCase();
|
|
598
656
|
if (!needle)
|
|
599
657
|
return { entries: [], truncated: false };
|
|
600
658
|
const root = await this.#resolve("");
|
|
@@ -648,8 +706,8 @@ var ProjectFiles = class {
|
|
|
648
706
|
* открыть в редакторе. Симлинки не разворачиваются вовсе: их цель — уже файл
|
|
649
707
|
* где-то в дереве, и он будет прочитан по своему собственному пути.
|
|
650
708
|
*/
|
|
651
|
-
async grep(
|
|
652
|
-
const needle =
|
|
709
|
+
async grep(query3) {
|
|
710
|
+
const needle = query3.trim().toLowerCase();
|
|
653
711
|
if (!needle)
|
|
654
712
|
return { matches: [], truncated: false };
|
|
655
713
|
const root = await this.#resolve("");
|
|
@@ -1975,7 +2033,7 @@ var ClaudeSession = class extends EventEmitter2 {
|
|
|
1975
2033
|
options2.strictMcpConfig = true;
|
|
1976
2034
|
}
|
|
1977
2035
|
this.#resetTasks();
|
|
1978
|
-
const q =
|
|
2036
|
+
const q = query2({ prompt: this.#inbox, options: options2 });
|
|
1979
2037
|
this.#query = q;
|
|
1980
2038
|
void this.#consume(q);
|
|
1981
2039
|
if (restarted)
|
|
@@ -2559,7 +2617,7 @@ var ClaudeSession = class extends EventEmitter2 {
|
|
|
2559
2617
|
this.#usageInFlight = true;
|
|
2560
2618
|
try {
|
|
2561
2619
|
const raw = await q.usage_EXPERIMENTAL_MAY_CHANGE_DO_NOT_RELY_ON_THIS_API_YET();
|
|
2562
|
-
this.#usage =
|
|
2620
|
+
this.#usage = toUsageState2(raw);
|
|
2563
2621
|
this.emit("usage", this.#usage);
|
|
2564
2622
|
} catch {
|
|
2565
2623
|
} finally {
|
|
@@ -3353,7 +3411,7 @@ function toSlashCommand(command) {
|
|
|
3353
3411
|
aliases: command.aliases ?? []
|
|
3354
3412
|
};
|
|
3355
3413
|
}
|
|
3356
|
-
function
|
|
3414
|
+
function toUsageState2(raw) {
|
|
3357
3415
|
const limits = raw.rate_limits ?? {};
|
|
3358
3416
|
return {
|
|
3359
3417
|
available: raw.rate_limits_available === true,
|
|
@@ -5178,9 +5236,9 @@ function parsePatch(raw) {
|
|
|
5178
5236
|
body = "";
|
|
5179
5237
|
}
|
|
5180
5238
|
total += body.length;
|
|
5181
|
-
const
|
|
5239
|
+
const path28 = status === "deleted" ? oldPath : newPath || oldPath;
|
|
5182
5240
|
files.push({
|
|
5183
|
-
path:
|
|
5241
|
+
path: path28,
|
|
5184
5242
|
oldPath: status === "renamed" ? oldPath : "",
|
|
5185
5243
|
status,
|
|
5186
5244
|
added: count(body, "+"),
|
|
@@ -5192,10 +5250,10 @@ function parsePatch(raw) {
|
|
|
5192
5250
|
return { files, truncated };
|
|
5193
5251
|
}
|
|
5194
5252
|
function stripPrefix(value) {
|
|
5195
|
-
const
|
|
5196
|
-
if (
|
|
5253
|
+
const path28 = unquote(value.trim());
|
|
5254
|
+
if (path28 === "/dev/null")
|
|
5197
5255
|
return "";
|
|
5198
|
-
return
|
|
5256
|
+
return path28.replace(/^[ab]\//, "");
|
|
5199
5257
|
}
|
|
5200
5258
|
function count(body, mark) {
|
|
5201
5259
|
let n = 0;
|
|
@@ -5474,10 +5532,10 @@ var ProjectFinder = class {
|
|
|
5474
5532
|
* в следующий ответ. Ждать его здесь нельзя: это две секунды на нажатие
|
|
5475
5533
|
* клавиши.
|
|
5476
5534
|
*/
|
|
5477
|
-
find(
|
|
5535
|
+
find(query3) {
|
|
5478
5536
|
if (Date.now() - this.#loadedAt > CACHE_TTL)
|
|
5479
5537
|
void this.#refresh();
|
|
5480
|
-
const needles = tokens(
|
|
5538
|
+
const needles = tokens(query3);
|
|
5481
5539
|
if (needles.length === 0)
|
|
5482
5540
|
return { candidates: [], truncated: false };
|
|
5483
5541
|
const open = new Map(this.registry.list().map((workspace) => [workspace.path.toLowerCase(), workspace]));
|
|
@@ -5629,8 +5687,8 @@ var ProjectFinder = class {
|
|
|
5629
5687
|
function usable(dir) {
|
|
5630
5688
|
return !contains(os2.tmpdir(), dir) && existsSync2(dir);
|
|
5631
5689
|
}
|
|
5632
|
-
function tokens(
|
|
5633
|
-
return
|
|
5690
|
+
function tokens(query3) {
|
|
5691
|
+
return query3.toLowerCase().split(/[^a-z0-9а-яё]+/i).filter(Boolean);
|
|
5634
5692
|
}
|
|
5635
5693
|
function matches(value, needles) {
|
|
5636
5694
|
const flat = value.toLowerCase().replace(/[^a-z0-9а-яё]+/gi, "");
|
|
@@ -5673,11 +5731,11 @@ var FINDER_SCHEMA = {
|
|
|
5673
5731
|
additionalProperties: false
|
|
5674
5732
|
};
|
|
5675
5733
|
var AGENT_LIMIT = 5;
|
|
5676
|
-
function finderPrompt(
|
|
5734
|
+
function finderPrompt(query3, roots) {
|
|
5677
5735
|
return [
|
|
5678
5736
|
"\u041D\u0430\u0439\u0434\u0438 \u043A\u0430\u0442\u0430\u043B\u043E\u0433 \u043F\u0440\u043E\u0435\u043A\u0442\u0430 \u043D\u0430 \u044D\u0442\u043E\u043C \u043A\u043E\u043C\u043F\u044C\u044E\u0442\u0435\u0440\u0435 \u043F\u043E \u043E\u043F\u0438\u0441\u0430\u043D\u0438\u044E \u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u0442\u0435\u043B\u044F.",
|
|
5679
5737
|
"",
|
|
5680
|
-
`\u041E\u043F\u0438\u0441\u0430\u043D\u0438\u0435: ${
|
|
5738
|
+
`\u041E\u043F\u0438\u0441\u0430\u043D\u0438\u0435: ${query3}`,
|
|
5681
5739
|
"",
|
|
5682
5740
|
"\u0418\u0441\u043A\u0430\u0442\u044C \u0442\u043E\u043B\u044C\u043A\u043E \u0432\u043D\u0443\u0442\u0440\u0438 \u044D\u0442\u0438\u0445 \u043A\u0430\u0442\u0430\u043B\u043E\u0433\u043E\u0432:",
|
|
5683
5741
|
...roots.map((root) => `- ${root}`),
|
|
@@ -5760,6 +5818,27 @@ var WorkspaceRegistry = class {
|
|
|
5760
5818
|
await mkdir6(path13.dirname(this.#storePath), { recursive: true });
|
|
5761
5819
|
await writeFile7(this.#storePath, JSON.stringify(this.#entries, null, 2), "utf8");
|
|
5762
5820
|
}
|
|
5821
|
+
/**
|
|
5822
|
+
* Каталог `from` переехал в `to` — записи проектов внутри него следуют за
|
|
5823
|
+
* ним. Возвращает пары «прежний путь → новый» для всех затронутых проектов.
|
|
5824
|
+
*/
|
|
5825
|
+
async relocate(from, to) {
|
|
5826
|
+
const moved = [];
|
|
5827
|
+
for (const entry of this.#entries) {
|
|
5828
|
+
if (!isUnder(from, entry.path))
|
|
5829
|
+
continue;
|
|
5830
|
+
const next = path13.join(to, path13.relative(from, entry.path));
|
|
5831
|
+
moved.push({ from: entry.path, to: next });
|
|
5832
|
+
entry.path = next;
|
|
5833
|
+
}
|
|
5834
|
+
if (moved.length > 0)
|
|
5835
|
+
await this.#persist();
|
|
5836
|
+
return moved;
|
|
5837
|
+
}
|
|
5838
|
+
/** Все записи реестра, включая архивные, — пути каталогов. */
|
|
5839
|
+
allPaths() {
|
|
5840
|
+
return this.#entries.map((e) => e.path);
|
|
5841
|
+
}
|
|
5763
5842
|
/** Активные проекты. */
|
|
5764
5843
|
list() {
|
|
5765
5844
|
return this.#entries.filter((e) => !e.archivedAt).map((e) => toInfo(e));
|
|
@@ -5954,6 +6033,12 @@ function toInfo(entry) {
|
|
|
5954
6033
|
function isEntry(value) {
|
|
5955
6034
|
return typeof value === "object" && value !== null && typeof value.path === "string" && (value.archivedAt === void 0 || typeof value.archivedAt === "number");
|
|
5956
6035
|
}
|
|
6036
|
+
function isUnder(parent, child) {
|
|
6037
|
+
const norm = (value) => path13.resolve(value).replace(/[\\/]+$/, "").toLowerCase();
|
|
6038
|
+
const p = norm(parent);
|
|
6039
|
+
const c = norm(child);
|
|
6040
|
+
return c === p || c.startsWith(`${p}${path13.sep}`.toLowerCase()) || c.startsWith(`${p}/`);
|
|
6041
|
+
}
|
|
5957
6042
|
|
|
5958
6043
|
// ../host/dist/archive.js
|
|
5959
6044
|
import { mkdir as mkdir7, readFile as readFile9, writeFile as writeFile8 } from "node:fs/promises";
|
|
@@ -6466,6 +6551,47 @@ var Folders = class {
|
|
|
6466
6551
|
await this.#persist();
|
|
6467
6552
|
return changed;
|
|
6468
6553
|
}
|
|
6554
|
+
/**
|
|
6555
|
+
* Папки проектов — каталоги на диске (id `dir:<имя>`), здесь хранится только
|
|
6556
|
+
* их цвет. Прежние метки без каталога отбрасываются: переносить каталоги за
|
|
6557
|
+
* человека без спроса хуже, чем потерять метку.
|
|
6558
|
+
*/
|
|
6559
|
+
async dropLegacyWorkspaceFolders() {
|
|
6560
|
+
let changed = false;
|
|
6561
|
+
for (const id of [...this.#workspaceFolders.keys()]) {
|
|
6562
|
+
if (!id.startsWith("dir:")) {
|
|
6563
|
+
this.#workspaceFolders.delete(id);
|
|
6564
|
+
changed = true;
|
|
6565
|
+
}
|
|
6566
|
+
}
|
|
6567
|
+
if (this.#workspaceAssignments.size > 0) {
|
|
6568
|
+
this.#workspaceAssignments.clear();
|
|
6569
|
+
changed = true;
|
|
6570
|
+
}
|
|
6571
|
+
if (changed)
|
|
6572
|
+
await this.#persist();
|
|
6573
|
+
}
|
|
6574
|
+
diskFolderColor(id) {
|
|
6575
|
+
return this.#workspaceFolders.get(id)?.color;
|
|
6576
|
+
}
|
|
6577
|
+
/** Запомнить цвет папки-каталога; пустая запись появляется при первом цвете. */
|
|
6578
|
+
async setDiskFolderColor(id, name, color) {
|
|
6579
|
+
if (!this.#workspaceFolders.has(id))
|
|
6580
|
+
this.#workspaceFolders.set(id, { name });
|
|
6581
|
+
return this.setColor(id, color);
|
|
6582
|
+
}
|
|
6583
|
+
/** Папку переименовали на диске — цвет едет под новый id. */
|
|
6584
|
+
async renameDiskFolder(oldId, newId, name) {
|
|
6585
|
+
const record = this.#workspaceFolders.get(oldId);
|
|
6586
|
+
this.#workspaceFolders.delete(oldId);
|
|
6587
|
+
if (record)
|
|
6588
|
+
this.#workspaceFolders.set(newId, { ...record, name });
|
|
6589
|
+
await this.#persist();
|
|
6590
|
+
}
|
|
6591
|
+
async forgetDiskFolder(id) {
|
|
6592
|
+
if (this.#workspaceFolders.delete(id))
|
|
6593
|
+
await this.#persist();
|
|
6594
|
+
}
|
|
6469
6595
|
/** Все папки — для кадра `folder.list`. */
|
|
6470
6596
|
list() {
|
|
6471
6597
|
return {
|
|
@@ -6693,10 +6819,217 @@ function isPinnedFolder(value) {
|
|
|
6693
6819
|
return typeof value === "object" && value !== null && typeof value.name === "string";
|
|
6694
6820
|
}
|
|
6695
6821
|
|
|
6696
|
-
// ../host/dist/
|
|
6697
|
-
import {
|
|
6822
|
+
// ../host/dist/project-folders.js
|
|
6823
|
+
import { existsSync as existsSync5, watch } from "node:fs";
|
|
6824
|
+
import { mkdir as mkdir11, readdir as readdir5, rmdir } from "node:fs/promises";
|
|
6825
|
+
import path19 from "node:path";
|
|
6826
|
+
|
|
6827
|
+
// ../host/dist/project-move.js
|
|
6828
|
+
import { existsSync as existsSync4 } from "node:fs";
|
|
6829
|
+
import { readFile as readFile13, readdir as readdir4, rename as rename2, stat as stat3 } from "node:fs/promises";
|
|
6698
6830
|
import { homedir as homedir5 } from "node:os";
|
|
6699
6831
|
import path18 from "node:path";
|
|
6832
|
+
var ACTIVE_WINDOW_MS = 2 * 6e4;
|
|
6833
|
+
function transcriptDirName(cwd) {
|
|
6834
|
+
return cwd.replace(/[^a-zA-Z0-9]/g, "-");
|
|
6835
|
+
}
|
|
6836
|
+
function isInside(parent, child) {
|
|
6837
|
+
const norm = (value) => path18.resolve(value).replace(/[\\/]+$/, "").toLowerCase();
|
|
6838
|
+
const p = norm(parent);
|
|
6839
|
+
const c = norm(child);
|
|
6840
|
+
return c === p || c.startsWith(p + path18.sep.toLowerCase()) || c.startsWith(`${p}/`);
|
|
6841
|
+
}
|
|
6842
|
+
async function externalAgentActivity(dirs, configDirs, now = Date.now()) {
|
|
6843
|
+
for (const dir of dirs) {
|
|
6844
|
+
const name = transcriptDirName(dir);
|
|
6845
|
+
for (const config of configDirs) {
|
|
6846
|
+
const t = await newestMtime(path18.join(config, "projects", name), 1);
|
|
6847
|
+
if (t !== null && now - t < ACTIVE_WINDOW_MS)
|
|
6848
|
+
return "Claude Code";
|
|
6849
|
+
}
|
|
6850
|
+
}
|
|
6851
|
+
if (await codexActive(dirs, now))
|
|
6852
|
+
return "Codex";
|
|
6853
|
+
return null;
|
|
6854
|
+
}
|
|
6855
|
+
async function newestMtime(dir, depth) {
|
|
6856
|
+
let newest = null;
|
|
6857
|
+
let entries;
|
|
6858
|
+
try {
|
|
6859
|
+
entries = await readdir4(dir);
|
|
6860
|
+
} catch {
|
|
6861
|
+
return null;
|
|
6862
|
+
}
|
|
6863
|
+
for (const entry of entries) {
|
|
6864
|
+
const file = path18.join(dir, entry);
|
|
6865
|
+
const info = await stat3(file).catch(() => null);
|
|
6866
|
+
if (!info)
|
|
6867
|
+
continue;
|
|
6868
|
+
if (info.isDirectory()) {
|
|
6869
|
+
if (depth > 0) {
|
|
6870
|
+
const inner = await newestMtime(file, depth - 1);
|
|
6871
|
+
if (inner !== null && (newest === null || inner > newest))
|
|
6872
|
+
newest = inner;
|
|
6873
|
+
}
|
|
6874
|
+
continue;
|
|
6875
|
+
}
|
|
6876
|
+
if (newest === null || info.mtimeMs > newest)
|
|
6877
|
+
newest = info.mtimeMs;
|
|
6878
|
+
}
|
|
6879
|
+
return newest;
|
|
6880
|
+
}
|
|
6881
|
+
async function codexActive(dirs, now) {
|
|
6882
|
+
const root = path18.join(process.env.CODEX_HOME?.trim() || path18.join(homedir5(), ".codex"), "sessions");
|
|
6883
|
+
const days = /* @__PURE__ */ new Set();
|
|
6884
|
+
for (const offset of [0, 1]) {
|
|
6885
|
+
const d = new Date(now - offset * 864e5);
|
|
6886
|
+
days.add(path18.join(root, String(d.getFullYear()), String(d.getMonth() + 1).padStart(2, "0"), String(d.getDate()).padStart(2, "0")));
|
|
6887
|
+
}
|
|
6888
|
+
for (const day of days) {
|
|
6889
|
+
const files = await readdir4(day).catch(() => []);
|
|
6890
|
+
for (const name of files) {
|
|
6891
|
+
if (!name.endsWith(".jsonl"))
|
|
6892
|
+
continue;
|
|
6893
|
+
const file = path18.join(day, name);
|
|
6894
|
+
const info = await stat3(file).catch(() => null);
|
|
6895
|
+
if (!info || now - info.mtimeMs >= ACTIVE_WINDOW_MS)
|
|
6896
|
+
continue;
|
|
6897
|
+
const head = (await readFile13(file, "utf8").catch(() => "")).slice(0, 4e3);
|
|
6898
|
+
const text = head.replace(/\\\\/g, "\\").toLowerCase();
|
|
6899
|
+
if (dirs.some((dir) => text.includes(dir.toLowerCase()) || head.includes(dir.replace(/\\/g, "\\\\")))) {
|
|
6900
|
+
return true;
|
|
6901
|
+
}
|
|
6902
|
+
}
|
|
6903
|
+
}
|
|
6904
|
+
return false;
|
|
6905
|
+
}
|
|
6906
|
+
function busyMessage(error) {
|
|
6907
|
+
const code = error?.code;
|
|
6908
|
+
if (code === "EBUSY" || code === "EPERM" || code === "EACCES") {
|
|
6909
|
+
return "\u041A\u0430\u0442\u0430\u043B\u043E\u0433 \u0437\u0430\u043D\u044F\u0442: \u0432 \u043D\u0451\u043C \u0438\u043B\u0438 \u0432 \u0435\u0433\u043E \u0444\u0430\u0439\u043B\u0430\u0445 \u0447\u0442\u043E-\u0442\u043E \u0440\u0430\u0431\u043E\u0442\u0430\u0435\u0442 (\u0430\u0433\u0435\u043D\u0442, \u0442\u0435\u0440\u043C\u0438\u043D\u0430\u043B, \u0440\u0435\u0434\u0430\u043A\u0442\u043E\u0440). \u0417\u0430\u043A\u0440\u043E\u0439\u0442\u0435 \u044D\u0442\u043E \u0438 \u043F\u043E\u0432\u0442\u043E\u0440\u0438\u0442\u0435.";
|
|
6910
|
+
}
|
|
6911
|
+
return null;
|
|
6912
|
+
}
|
|
6913
|
+
async function moveDirectory(from, to, projects, configDirs) {
|
|
6914
|
+
if (existsSync4(to))
|
|
6915
|
+
throw new Error(`\u0423\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442: ${to}`);
|
|
6916
|
+
if (isInside(from, to))
|
|
6917
|
+
throw new Error("\u041D\u0435\u043B\u044C\u0437\u044F \u043F\u0435\u0440\u0435\u043C\u0435\u0441\u0442\u0438\u0442\u044C \u043A\u0430\u0442\u0430\u043B\u043E\u0433 \u0432\u043D\u0443\u0442\u0440\u044C \u0441\u0430\u043C\u043E\u0433\u043E \u0441\u0435\u0431\u044F");
|
|
6918
|
+
const transcripts = [];
|
|
6919
|
+
for (const project of projects) {
|
|
6920
|
+
const next = path18.join(to, path18.relative(from, project));
|
|
6921
|
+
for (const config of configDirs) {
|
|
6922
|
+
const source = path18.join(config, "projects", transcriptDirName(project));
|
|
6923
|
+
const target = path18.join(config, "projects", transcriptDirName(next));
|
|
6924
|
+
if (!existsSync4(source))
|
|
6925
|
+
continue;
|
|
6926
|
+
if (existsSync4(target)) {
|
|
6927
|
+
throw new Error(`\u0423 \u043D\u043E\u0432\u043E\u0433\u043E \u043F\u0443\u0442\u0438 \u0443\u0436\u0435 \u0435\u0441\u0442\u044C \u0442\u0440\u0430\u043D\u0441\u043A\u0440\u0438\u043F\u0442\u044B Claude Code: ${target}`);
|
|
6928
|
+
}
|
|
6929
|
+
transcripts.push({ from: source, to: target });
|
|
6930
|
+
}
|
|
6931
|
+
}
|
|
6932
|
+
try {
|
|
6933
|
+
await rename2(from, to);
|
|
6934
|
+
} catch (error) {
|
|
6935
|
+
const busy = busyMessage(error);
|
|
6936
|
+
if (error.code === "EXDEV") {
|
|
6937
|
+
throw new Error("\u041F\u0435\u0440\u0435\u043D\u043E\u0441 \u043D\u0430 \u0434\u0440\u0443\u0433\u043E\u0439 \u0434\u0438\u0441\u043A \u043D\u0435 \u043F\u043E\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044F \u2014 \u043F\u0435\u0440\u0435\u043C\u0435\u0441\u0442\u0438\u0442\u0435 \u043A\u0430\u0442\u0430\u043B\u043E\u0433 \u0432\u0440\u0443\u0447\u043D\u0443\u044E");
|
|
6938
|
+
}
|
|
6939
|
+
throw new Error(busy ?? `\u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u043F\u0435\u0440\u0435\u043C\u0435\u0441\u0442\u0438\u0442\u044C \u043A\u0430\u0442\u0430\u043B\u043E\u0433: ${error.message}`);
|
|
6940
|
+
}
|
|
6941
|
+
const done = [];
|
|
6942
|
+
try {
|
|
6943
|
+
for (const move of transcripts) {
|
|
6944
|
+
await rename2(move.from, move.to);
|
|
6945
|
+
done.push(move);
|
|
6946
|
+
}
|
|
6947
|
+
} catch (error) {
|
|
6948
|
+
for (const move of done.reverse())
|
|
6949
|
+
await rename2(move.to, move.from).catch(() => void 0);
|
|
6950
|
+
await rename2(to, from).catch(() => void 0);
|
|
6951
|
+
throw new Error(`\u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u043F\u0435\u0440\u0435\u043D\u0435\u0441\u0442\u0438 \u0442\u0440\u0430\u043D\u0441\u043A\u0440\u0438\u043F\u0442\u044B, \u043A\u0430\u0442\u0430\u043B\u043E\u0433 \u0432\u043E\u0437\u0432\u0440\u0430\u0449\u0451\u043D \u043D\u0430 \u043C\u0435\u0441\u0442\u043E: ${error.message}`);
|
|
6952
|
+
}
|
|
6953
|
+
}
|
|
6954
|
+
|
|
6955
|
+
// ../host/dist/project-folders.js
|
|
6956
|
+
var FOLDER_PREFIX = "dir:";
|
|
6957
|
+
var SKIP = /* @__PURE__ */ new Set(["node_modules", "$recycle.bin", "system volume information"]);
|
|
6958
|
+
function folderIdFor(name) {
|
|
6959
|
+
return `${FOLDER_PREFIX}${name}`;
|
|
6960
|
+
}
|
|
6961
|
+
function folderNameOf(id) {
|
|
6962
|
+
return id.startsWith(FOLDER_PREFIX) ? id.slice(FOLDER_PREFIX.length) : null;
|
|
6963
|
+
}
|
|
6964
|
+
function cleanFolderName(raw) {
|
|
6965
|
+
const name = raw.trim();
|
|
6966
|
+
if (!name)
|
|
6967
|
+
throw new Error("\u0414\u0430\u0439\u0442\u0435 \u043F\u0430\u043F\u043A\u0435 \u0438\u043C\u044F");
|
|
6968
|
+
if (/[\\/:*?"<>|]/.test(name) || name === "." || name === ".." || name.endsWith(".")) {
|
|
6969
|
+
throw new Error('\u0412 \u0438\u043C\u0435\u043D\u0438 \u043F\u0430\u043F\u043A\u0438 \u043D\u0435\u043B\u044C\u0437\u044F \u0438\u0441\u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u0442\u044C \\ / : * ? " < > | \u0438 \u0442\u043E\u0447\u043A\u0443 \u0432 \u043A\u043E\u043D\u0446\u0435');
|
|
6970
|
+
}
|
|
6971
|
+
return name;
|
|
6972
|
+
}
|
|
6973
|
+
async function listDiskFolders(root, projectPaths) {
|
|
6974
|
+
const projects = new Set(projectPaths.map((p) => path19.resolve(p).toLowerCase()));
|
|
6975
|
+
const entries = await readdir5(root, { withFileTypes: true }).catch(() => []);
|
|
6976
|
+
const names2 = [];
|
|
6977
|
+
for (const entry of entries) {
|
|
6978
|
+
if (!entry.isDirectory() || entry.name.startsWith(".") || SKIP.has(entry.name.toLowerCase()))
|
|
6979
|
+
continue;
|
|
6980
|
+
const dir = path19.join(root, entry.name);
|
|
6981
|
+
if (projects.has(path19.resolve(dir).toLowerCase()))
|
|
6982
|
+
continue;
|
|
6983
|
+
if (existsSync5(path19.join(dir, ".git")))
|
|
6984
|
+
continue;
|
|
6985
|
+
names2.push(entry.name);
|
|
6986
|
+
}
|
|
6987
|
+
return names2.sort((a, b) => a.localeCompare(b));
|
|
6988
|
+
}
|
|
6989
|
+
function folderOfProject(root, projectPath, folders) {
|
|
6990
|
+
const parent = path19.dirname(path19.resolve(projectPath));
|
|
6991
|
+
if (path19.resolve(path19.dirname(parent)).toLowerCase() !== path19.resolve(root).toLowerCase())
|
|
6992
|
+
return null;
|
|
6993
|
+
const name = path19.basename(parent);
|
|
6994
|
+
return folders.has(name) ? folderIdFor(name) : null;
|
|
6995
|
+
}
|
|
6996
|
+
async function createDiskFolder(root, rawName) {
|
|
6997
|
+
const name = cleanFolderName(rawName);
|
|
6998
|
+
const dir = path19.join(root, name);
|
|
6999
|
+
if (existsSync5(dir))
|
|
7000
|
+
throw new Error(`\u0423\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442: ${dir}`);
|
|
7001
|
+
await mkdir11(dir, { recursive: true });
|
|
7002
|
+
return name;
|
|
7003
|
+
}
|
|
7004
|
+
async function foreignContent(dir, projectPaths) {
|
|
7005
|
+
const projects = new Set(projectPaths.map((p) => path19.resolve(p).toLowerCase()));
|
|
7006
|
+
for (const entry of await readdir5(dir).catch(() => [])) {
|
|
7007
|
+
if (!projects.has(path19.resolve(path19.join(dir, entry)).toLowerCase()))
|
|
7008
|
+
return entry;
|
|
7009
|
+
}
|
|
7010
|
+
return null;
|
|
7011
|
+
}
|
|
7012
|
+
async function removeEmptyDir(dir) {
|
|
7013
|
+
await rmdir(dir);
|
|
7014
|
+
}
|
|
7015
|
+
function watchRoot(root, onChange) {
|
|
7016
|
+
let timer;
|
|
7017
|
+
try {
|
|
7018
|
+
const watcher = watch(root, { recursive: false }, () => {
|
|
7019
|
+
clearTimeout(timer);
|
|
7020
|
+
timer = setTimeout(onChange, 300);
|
|
7021
|
+
});
|
|
7022
|
+
watcher.on("error", () => watcher.close());
|
|
7023
|
+
return watcher;
|
|
7024
|
+
} catch {
|
|
7025
|
+
return null;
|
|
7026
|
+
}
|
|
7027
|
+
}
|
|
7028
|
+
|
|
7029
|
+
// ../host/dist/app-settings.js
|
|
7030
|
+
import { mkdir as mkdir12, readFile as readFile14, writeFile as writeFile12 } from "node:fs/promises";
|
|
7031
|
+
import { homedir as homedir6 } from "node:os";
|
|
7032
|
+
import path20 from "node:path";
|
|
6700
7033
|
var DEFAULT_AUTO_ARCHIVE_AFTER_MS = 2 * 24 * 60 * 60 * 1e3;
|
|
6701
7034
|
var MIN_AUTO_ARCHIVE_AFTER_MS = 60 * 60 * 1e3;
|
|
6702
7035
|
var DEFAULT_AUTO_STOP_AFTER_MS = 10 * 60 * 1e3;
|
|
@@ -6746,17 +7079,18 @@ var DEFAULT_APP_SETTINGS = {
|
|
|
6746
7079
|
// Включено: запрос без VPN может стоить аккаунта, а тому, у кого маршрут и
|
|
6747
7080
|
// так из разрешённой страны, защита ничем не мешает.
|
|
6748
7081
|
networkGuardEnabled: true,
|
|
6749
|
-
networkGuardBlockedCountries: DEFAULT_BLOCKED_COUNTRIES
|
|
7082
|
+
networkGuardBlockedCountries: DEFAULT_BLOCKED_COUNTRIES,
|
|
7083
|
+
projectsRoot: null
|
|
6750
7084
|
};
|
|
6751
7085
|
var AppSettingsStore = class {
|
|
6752
7086
|
#settings = { ...DEFAULT_APP_SETTINGS };
|
|
6753
7087
|
#storePath;
|
|
6754
7088
|
constructor(dataDir) {
|
|
6755
|
-
this.#storePath =
|
|
7089
|
+
this.#storePath = path20.join(dataDir, "app-settings.json");
|
|
6756
7090
|
}
|
|
6757
7091
|
async load() {
|
|
6758
7092
|
try {
|
|
6759
|
-
const raw = await
|
|
7093
|
+
const raw = await readFile14(this.#storePath, "utf8");
|
|
6760
7094
|
this.#settings = sanitize2(JSON.parse(raw), DEFAULT_APP_SETTINGS);
|
|
6761
7095
|
} catch {
|
|
6762
7096
|
this.#settings = { ...DEFAULT_APP_SETTINGS };
|
|
@@ -6776,7 +7110,7 @@ var AppSettingsStore = class {
|
|
|
6776
7110
|
async update(patch) {
|
|
6777
7111
|
const next = sanitize2(patch, this.#settings);
|
|
6778
7112
|
this.#settings = next;
|
|
6779
|
-
await
|
|
7113
|
+
await mkdir12(path20.dirname(this.#storePath), { recursive: true });
|
|
6780
7114
|
await writeFile12(this.#storePath, JSON.stringify(next, null, 2), "utf8");
|
|
6781
7115
|
return this.current;
|
|
6782
7116
|
}
|
|
@@ -6844,10 +7178,15 @@ function sanitize2(value, fallback) {
|
|
|
6844
7178
|
...new Set(countries.filter((c) => typeof c === "string").map((c) => c.trim().toUpperCase()).filter((c) => /^[A-Z]{2}$/.test(c)))
|
|
6845
7179
|
];
|
|
6846
7180
|
}
|
|
7181
|
+
if (record.projectsRoot === null)
|
|
7182
|
+
result.projectsRoot = null;
|
|
7183
|
+
else if (typeof record.projectsRoot === "string" && record.projectsRoot.trim()) {
|
|
7184
|
+
result.projectsRoot = record.projectsRoot.trim();
|
|
7185
|
+
}
|
|
6847
7186
|
return result;
|
|
6848
7187
|
}
|
|
6849
7188
|
function claudeHome() {
|
|
6850
|
-
return
|
|
7189
|
+
return path20.join(homedir6(), ".claude");
|
|
6851
7190
|
}
|
|
6852
7191
|
function writableRoots(mode, cwd, workspacePaths) {
|
|
6853
7192
|
if (mode === "all")
|
|
@@ -6857,7 +7196,7 @@ function writableRoots(mode, cwd, workspacePaths) {
|
|
|
6857
7196
|
return [...roots];
|
|
6858
7197
|
for (const workspace of [cwd, ...workspacePaths]) {
|
|
6859
7198
|
roots.add(workspace);
|
|
6860
|
-
const parent =
|
|
7199
|
+
const parent = path20.dirname(workspace);
|
|
6861
7200
|
if (parent !== workspace)
|
|
6862
7201
|
roots.add(parent);
|
|
6863
7202
|
}
|
|
@@ -6865,19 +7204,19 @@ function writableRoots(mode, cwd, workspacePaths) {
|
|
|
6865
7204
|
}
|
|
6866
7205
|
|
|
6867
7206
|
// ../host/dist/handoff-store.js
|
|
6868
|
-
import { mkdir as
|
|
6869
|
-
import
|
|
7207
|
+
import { mkdir as mkdir13, readFile as readFile15, readdir as readdir6, rm as rm4, writeFile as writeFile13 } from "node:fs/promises";
|
|
7208
|
+
import path21 from "node:path";
|
|
6870
7209
|
var HandoffStore = class {
|
|
6871
7210
|
#dir;
|
|
6872
7211
|
constructor(dataDir) {
|
|
6873
|
-
this.#dir =
|
|
7212
|
+
this.#dir = path21.join(dataDir, "handoffs");
|
|
6874
7213
|
}
|
|
6875
7214
|
async get(sessionId) {
|
|
6876
7215
|
const file = this.#file(sessionId);
|
|
6877
7216
|
if (!file)
|
|
6878
7217
|
return null;
|
|
6879
7218
|
try {
|
|
6880
|
-
const parsed = JSON.parse(await
|
|
7219
|
+
const parsed = JSON.parse(await readFile15(file, "utf8"));
|
|
6881
7220
|
return typeof parsed.text === "string" ? parsed : null;
|
|
6882
7221
|
} catch {
|
|
6883
7222
|
return null;
|
|
@@ -6887,7 +7226,7 @@ var HandoffStore = class {
|
|
|
6887
7226
|
const file = this.#file(handoff.sessionId);
|
|
6888
7227
|
if (!file)
|
|
6889
7228
|
return;
|
|
6890
|
-
await
|
|
7229
|
+
await mkdir13(this.#dir, { recursive: true });
|
|
6891
7230
|
await writeFile13(file, JSON.stringify(handoff, null, 2), "utf8");
|
|
6892
7231
|
}
|
|
6893
7232
|
async remove(sessionId) {
|
|
@@ -6898,7 +7237,7 @@ var HandoffStore = class {
|
|
|
6898
7237
|
/** id всех сохранённых хэндоффов. */
|
|
6899
7238
|
async list() {
|
|
6900
7239
|
try {
|
|
6901
|
-
return (await
|
|
7240
|
+
return (await readdir6(this.#dir)).filter((name) => name.endsWith(".json")).map((name) => name.slice(0, -".json".length));
|
|
6902
7241
|
} catch {
|
|
6903
7242
|
return [];
|
|
6904
7243
|
}
|
|
@@ -6907,7 +7246,7 @@ var HandoffStore = class {
|
|
|
6907
7246
|
#file(sessionId) {
|
|
6908
7247
|
if (!/^[\w-]{1,128}$/.test(sessionId))
|
|
6909
7248
|
return null;
|
|
6910
|
-
return
|
|
7249
|
+
return path21.join(this.#dir, `${sessionId}.json`);
|
|
6911
7250
|
}
|
|
6912
7251
|
};
|
|
6913
7252
|
var SAME_WINDOW_MS = 5 * 6e4;
|
|
@@ -6916,11 +7255,11 @@ var LimitStopState = class {
|
|
|
6916
7255
|
#fired = {};
|
|
6917
7256
|
#storePath;
|
|
6918
7257
|
constructor(dataDir) {
|
|
6919
|
-
this.#storePath =
|
|
7258
|
+
this.#storePath = path21.join(dataDir, "limit-stop.json");
|
|
6920
7259
|
}
|
|
6921
7260
|
async load() {
|
|
6922
7261
|
try {
|
|
6923
|
-
const parsed = JSON.parse(await
|
|
7262
|
+
const parsed = JSON.parse(await readFile15(this.#storePath, "utf8"));
|
|
6924
7263
|
this.#fired = {};
|
|
6925
7264
|
const read = (source) => {
|
|
6926
7265
|
const out = {};
|
|
@@ -6964,7 +7303,7 @@ var LimitStopState = class {
|
|
|
6964
7303
|
}
|
|
6965
7304
|
async #mark(account, limit, until) {
|
|
6966
7305
|
this.#fired[account] = { ...this.#fired[account], [limit]: until };
|
|
6967
|
-
await
|
|
7306
|
+
await mkdir13(path21.dirname(this.#storePath), { recursive: true });
|
|
6968
7307
|
const { [MAIN_ACCOUNT_ID]: main = {}, ...others } = this.#fired;
|
|
6969
7308
|
await writeFile13(this.#storePath, JSON.stringify({ ...main, ...others }, null, 2), "utf8");
|
|
6970
7309
|
}
|
|
@@ -7070,9 +7409,9 @@ function capitalize(text) {
|
|
|
7070
7409
|
}
|
|
7071
7410
|
|
|
7072
7411
|
// ../host/dist/plugins.js
|
|
7073
|
-
import { readFile as
|
|
7074
|
-
import { homedir as
|
|
7075
|
-
import
|
|
7412
|
+
import { readFile as readFile16 } from "node:fs/promises";
|
|
7413
|
+
import { homedir as homedir7 } from "node:os";
|
|
7414
|
+
import path22 from "node:path";
|
|
7076
7415
|
var TIMEOUT_MS2 = 12e4;
|
|
7077
7416
|
var SAFE_ARG = /^[A-Za-z0-9][A-Za-z0-9._@/-]*$/;
|
|
7078
7417
|
var PluginCli = class {
|
|
@@ -7171,10 +7510,10 @@ async function readCatalog(markets, installed) {
|
|
|
7171
7510
|
return lists.flat().sort((a, b) => a.name.localeCompare(b.name));
|
|
7172
7511
|
}
|
|
7173
7512
|
async function readMarketplace(market, installed) {
|
|
7174
|
-
const root = market.installLocation ||
|
|
7513
|
+
const root = market.installLocation || path22.join(homedir7(), ".claude", "plugins", "marketplaces", market.name);
|
|
7175
7514
|
let manifest;
|
|
7176
7515
|
try {
|
|
7177
|
-
const text = await
|
|
7516
|
+
const text = await readFile16(path22.join(root, ".claude-plugin", "marketplace.json"), "utf8");
|
|
7178
7517
|
manifest = JSON.parse(text);
|
|
7179
7518
|
} catch {
|
|
7180
7519
|
return [];
|
|
@@ -7426,8 +7765,8 @@ function describe5(error) {
|
|
|
7426
7765
|
|
|
7427
7766
|
// ../host/dist/relay-link.js
|
|
7428
7767
|
import { EventEmitter as EventEmitter5 } from "node:events";
|
|
7429
|
-
import { readFile as
|
|
7430
|
-
import
|
|
7768
|
+
import { readFile as readFile17, writeFile as writeFile14, rm as rm5, mkdir as mkdir14 } from "node:fs/promises";
|
|
7769
|
+
import path23 from "node:path";
|
|
7431
7770
|
import { hostname } from "node:os";
|
|
7432
7771
|
import WebSocket from "ws";
|
|
7433
7772
|
|
|
@@ -7482,7 +7821,7 @@ var RelayLink = class extends EventEmitter5 {
|
|
|
7482
7821
|
#log;
|
|
7483
7822
|
constructor(options2) {
|
|
7484
7823
|
super();
|
|
7485
|
-
this.#file =
|
|
7824
|
+
this.#file = path23.join(options2.dataDir, "relay.json");
|
|
7486
7825
|
this.#defaultUrl = options2.defaultUrl.replace(/\/+$/, "");
|
|
7487
7826
|
this.#log = options2.log ?? ((msg) => console.log(`[relay] ${msg}`));
|
|
7488
7827
|
}
|
|
@@ -7563,7 +7902,7 @@ var RelayLink = class extends EventEmitter5 {
|
|
|
7563
7902
|
}
|
|
7564
7903
|
async #read() {
|
|
7565
7904
|
try {
|
|
7566
|
-
const raw = await
|
|
7905
|
+
const raw = await readFile17(this.#file, "utf8");
|
|
7567
7906
|
const parsed = JSON.parse(raw);
|
|
7568
7907
|
if (typeof parsed !== "object" || parsed === null)
|
|
7569
7908
|
return null;
|
|
@@ -7576,7 +7915,7 @@ var RelayLink = class extends EventEmitter5 {
|
|
|
7576
7915
|
}
|
|
7577
7916
|
}
|
|
7578
7917
|
async #write(credentials) {
|
|
7579
|
-
await
|
|
7918
|
+
await mkdir14(path23.dirname(this.#file), { recursive: true });
|
|
7580
7919
|
await writeFile14(this.#file, `${JSON.stringify(credentials, null, 2)}
|
|
7581
7920
|
`, {
|
|
7582
7921
|
encoding: "utf8",
|
|
@@ -7834,7 +8173,7 @@ function humanize(error) {
|
|
|
7834
8173
|
// ../host/dist/terminal.js
|
|
7835
8174
|
import { EventEmitter as EventEmitter6 } from "node:events";
|
|
7836
8175
|
import { access as access2, constants as constants2 } from "node:fs/promises";
|
|
7837
|
-
import
|
|
8176
|
+
import path24 from "node:path";
|
|
7838
8177
|
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
7839
8178
|
var SCROLLBACK_BYTES = 256 * 1024;
|
|
7840
8179
|
var FLUSH_MS = 12;
|
|
@@ -8004,22 +8343,22 @@ async function defaultShell() {
|
|
|
8004
8343
|
if (pwsh)
|
|
8005
8344
|
return { file: pwsh, args: [], title: "pwsh" };
|
|
8006
8345
|
const system = process.env.SystemRoot ?? "C:\\Windows";
|
|
8007
|
-
const powershell =
|
|
8346
|
+
const powershell = path24.join(system, "System32/WindowsPowerShell/v1.0/powershell.exe");
|
|
8008
8347
|
if (await exists3(powershell))
|
|
8009
8348
|
return { file: powershell, args: [], title: "powershell" };
|
|
8010
8349
|
return { file: process.env.COMSPEC ?? "cmd.exe", args: [], title: "cmd" };
|
|
8011
8350
|
}
|
|
8012
8351
|
const shell = process.env.SHELL;
|
|
8013
8352
|
if (shell && await exists3(shell))
|
|
8014
|
-
return { file: shell, args: [], title:
|
|
8353
|
+
return { file: shell, args: [], title: path24.basename(shell) };
|
|
8015
8354
|
if (await exists3("/bin/bash"))
|
|
8016
8355
|
return { file: "/bin/bash", args: [], title: "bash" };
|
|
8017
8356
|
return { file: "/bin/sh", args: [], title: "sh" };
|
|
8018
8357
|
}
|
|
8019
8358
|
async function findOnPath(name) {
|
|
8020
|
-
const dirs = (process.env.PATH ?? "").split(
|
|
8359
|
+
const dirs = (process.env.PATH ?? "").split(path24.delimiter).filter(Boolean);
|
|
8021
8360
|
for (const dir of dirs) {
|
|
8022
|
-
const candidate =
|
|
8361
|
+
const candidate = path24.join(dir, name);
|
|
8023
8362
|
if (await exists3(candidate))
|
|
8024
8363
|
return candidate;
|
|
8025
8364
|
}
|
|
@@ -8030,10 +8369,10 @@ function exists3(file) {
|
|
|
8030
8369
|
}
|
|
8031
8370
|
|
|
8032
8371
|
// ../host/dist/mcp-config.js
|
|
8033
|
-
import { readFile as
|
|
8034
|
-
import
|
|
8372
|
+
import { readFile as readFile18, writeFile as writeFile15, mkdir as mkdir15 } from "node:fs/promises";
|
|
8373
|
+
import path25 from "node:path";
|
|
8035
8374
|
var MCP_FILE = ".mcp.json";
|
|
8036
|
-
var LOCAL_SETTINGS2 =
|
|
8375
|
+
var LOCAL_SETTINGS2 = path25.join(".claude", "settings.local.json");
|
|
8037
8376
|
var queues = /* @__PURE__ */ new Map();
|
|
8038
8377
|
function serialize(cwd, work) {
|
|
8039
8378
|
const previous = queues.get(cwd) ?? Promise.resolve();
|
|
@@ -8042,7 +8381,7 @@ function serialize(cwd, work) {
|
|
|
8042
8381
|
return next;
|
|
8043
8382
|
}
|
|
8044
8383
|
async function readProjectServers(cwd) {
|
|
8045
|
-
const file = await readJson(
|
|
8384
|
+
const file = await readJson(path25.join(cwd, MCP_FILE));
|
|
8046
8385
|
const servers = file?.mcpServers;
|
|
8047
8386
|
if (!servers || typeof servers !== "object")
|
|
8048
8387
|
return {};
|
|
@@ -8050,23 +8389,23 @@ async function readProjectServers(cwd) {
|
|
|
8050
8389
|
}
|
|
8051
8390
|
function addProjectServer(cwd, name, config) {
|
|
8052
8391
|
return serialize(cwd, async () => {
|
|
8053
|
-
const file = await readJson(
|
|
8392
|
+
const file = await readJson(path25.join(cwd, MCP_FILE)) ?? {};
|
|
8054
8393
|
const servers = file.mcpServers ?? {};
|
|
8055
8394
|
servers[name] = config;
|
|
8056
8395
|
file.mcpServers = servers;
|
|
8057
|
-
await writeJson(
|
|
8396
|
+
await writeJson(path25.join(cwd, MCP_FILE), file);
|
|
8058
8397
|
await approve(cwd, name);
|
|
8059
8398
|
});
|
|
8060
8399
|
}
|
|
8061
8400
|
function removeProjectServer(cwd, name) {
|
|
8062
8401
|
return serialize(cwd, async () => {
|
|
8063
|
-
const file = await readJson(
|
|
8402
|
+
const file = await readJson(path25.join(cwd, MCP_FILE));
|
|
8064
8403
|
const servers = file?.mcpServers;
|
|
8065
8404
|
if (!servers || !(name in servers))
|
|
8066
8405
|
return false;
|
|
8067
8406
|
delete servers[name];
|
|
8068
|
-
await writeJson(
|
|
8069
|
-
const settingsPath =
|
|
8407
|
+
await writeJson(path25.join(cwd, MCP_FILE), file);
|
|
8408
|
+
const settingsPath = path25.join(cwd, LOCAL_SETTINGS2);
|
|
8070
8409
|
const settings = await readJson(settingsPath);
|
|
8071
8410
|
const enabled = settings?.enabledMcpjsonServers;
|
|
8072
8411
|
if (settings && Array.isArray(enabled) && enabled.includes(name)) {
|
|
@@ -8077,7 +8416,7 @@ function removeProjectServer(cwd, name) {
|
|
|
8077
8416
|
});
|
|
8078
8417
|
}
|
|
8079
8418
|
async function approve(cwd, name) {
|
|
8080
|
-
const file =
|
|
8419
|
+
const file = path25.join(cwd, LOCAL_SETTINGS2);
|
|
8081
8420
|
const settings = await readJson(file) ?? {};
|
|
8082
8421
|
const enabled = Array.isArray(settings.enabledMcpjsonServers) ? settings.enabledMcpjsonServers : [];
|
|
8083
8422
|
if (!enabled.includes(name))
|
|
@@ -8116,20 +8455,20 @@ function describeConfig(config) {
|
|
|
8116
8455
|
}
|
|
8117
8456
|
async function readJson(file) {
|
|
8118
8457
|
try {
|
|
8119
|
-
const raw = await
|
|
8458
|
+
const raw = await readFile18(file, "utf8");
|
|
8120
8459
|
const parsed = JSON.parse(raw);
|
|
8121
8460
|
return parsed && typeof parsed === "object" ? parsed : null;
|
|
8122
8461
|
} catch (error) {
|
|
8123
8462
|
if (error.code === "ENOENT")
|
|
8124
8463
|
return null;
|
|
8125
8464
|
if (error instanceof SyntaxError) {
|
|
8126
|
-
throw new Error(`\u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u0440\u0430\u0437\u043E\u0431\u0440\u0430\u0442\u044C ${
|
|
8465
|
+
throw new Error(`\u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u0440\u0430\u0437\u043E\u0431\u0440\u0430\u0442\u044C ${path25.basename(file)}: ${error.message}`);
|
|
8127
8466
|
}
|
|
8128
8467
|
throw error;
|
|
8129
8468
|
}
|
|
8130
8469
|
}
|
|
8131
8470
|
async function writeJson(file, data) {
|
|
8132
|
-
await
|
|
8471
|
+
await mkdir15(path25.dirname(file), { recursive: true });
|
|
8133
8472
|
await writeFile15(file, `${JSON.stringify(data, null, 2)}
|
|
8134
8473
|
`, "utf8");
|
|
8135
8474
|
}
|
|
@@ -8196,6 +8535,13 @@ var HostServer = class {
|
|
|
8196
8535
|
#limitStopping = false;
|
|
8197
8536
|
/** Последний снимок лимитов Claude по аккаунтам — им сверяется ход без промпта. */
|
|
8198
8537
|
#lastUsage = /* @__PURE__ */ new Map();
|
|
8538
|
+
/** Снимки лимитов аккаунтов без живой сессии — отдельно от `#lastUsage`: на них не срабатывает остановка по лимиту. */
|
|
8539
|
+
#probedUsage = /* @__PURE__ */ new Map();
|
|
8540
|
+
#usageInFlight = false;
|
|
8541
|
+
/** Имена папок проектов на диске — кэш, чтобы синхронные сборщики списков не ходили на диск. */
|
|
8542
|
+
#diskFolders = [];
|
|
8543
|
+
#rootWatcher = null;
|
|
8544
|
+
#watchedRoot = "";
|
|
8199
8545
|
/**
|
|
8200
8546
|
* Сессии, которым человек сам написал после срабатывания порога: id
|
|
8201
8547
|
* сессии → окно → срок, до которого оно было отмечено сработавшим. Это его
|
|
@@ -8275,6 +8621,33 @@ var HostServer = class {
|
|
|
8275
8621
|
liveSessions: live.filter((s) => s.accountId === a.id).length
|
|
8276
8622
|
}));
|
|
8277
8623
|
}
|
|
8624
|
+
/**
|
|
8625
|
+
* Лимиты всех аккаунтов. С живой сессией — её снимок (заодно освежаем), без
|
|
8626
|
+
* неё — короткий процесс CLI без промпта. Сначала отдаём известное, чтобы
|
|
8627
|
+
* карточки не ждали сети, потом — свежее.
|
|
8628
|
+
*/
|
|
8629
|
+
async #refreshAccountUsage() {
|
|
8630
|
+
if (this.#usageInFlight)
|
|
8631
|
+
return;
|
|
8632
|
+
this.#usageInFlight = true;
|
|
8633
|
+
try {
|
|
8634
|
+
const known = () => Object.fromEntries(this.#accounts.all.map((a) => [a.id, this.#lastUsage.get(a.id) ?? this.#probedUsage.get(a.id) ?? null]));
|
|
8635
|
+
this.#broadcast({ type: "accounts.usage", usage: known() });
|
|
8636
|
+
await Promise.all(this.#accounts.all.map(async (account) => {
|
|
8637
|
+
const live = [...this.#sessions.values()].find((s) => s instanceof ClaudeSession && s.accountId === account.id && s.state !== "closed");
|
|
8638
|
+
if (live) {
|
|
8639
|
+
await live.refreshUsage(true);
|
|
8640
|
+
return;
|
|
8641
|
+
}
|
|
8642
|
+
const fresh = await probeUsage(account.configDir);
|
|
8643
|
+
if (fresh)
|
|
8644
|
+
this.#probedUsage.set(account.id, fresh);
|
|
8645
|
+
}));
|
|
8646
|
+
this.#broadcast({ type: "accounts.usage", usage: known() });
|
|
8647
|
+
} finally {
|
|
8648
|
+
this.#usageInFlight = false;
|
|
8649
|
+
}
|
|
8650
|
+
}
|
|
8278
8651
|
/** Список аккаунтов и, для каждого, кто в нём вошёл. Вход спрашивается у CLI — это процесс на аккаунт. */
|
|
8279
8652
|
async #accountsFrame() {
|
|
8280
8653
|
const accounts = this.#accountList();
|
|
@@ -8294,7 +8667,7 @@ var HostServer = class {
|
|
|
8294
8667
|
const status = await new AuthCli(configDir).status().catch(() => null);
|
|
8295
8668
|
if (!status?.loggedIn)
|
|
8296
8669
|
return null;
|
|
8297
|
-
const used = this.#accounts.all.find((a) =>
|
|
8670
|
+
const used = this.#accounts.all.find((a) => path26.resolve(this.#accounts.effectiveDir(a.id)).toLowerCase() === configDir.toLowerCase());
|
|
8298
8671
|
return {
|
|
8299
8672
|
configDir,
|
|
8300
8673
|
email: status.email,
|
|
@@ -8337,8 +8710,10 @@ var HostServer = class {
|
|
|
8337
8710
|
await this.#pins.load();
|
|
8338
8711
|
await this.#order.load();
|
|
8339
8712
|
await this.#folders.load();
|
|
8713
|
+
await this.#folders.dropLegacyWorkspaceFolders();
|
|
8340
8714
|
await this.#carryOverWorkspaceIds();
|
|
8341
8715
|
await this.#settings.load();
|
|
8716
|
+
await this.#refreshDiskFolders();
|
|
8342
8717
|
this.#wireNetworkGuard();
|
|
8343
8718
|
await this.#accounts.load();
|
|
8344
8719
|
await this.#limitStop.load();
|
|
@@ -8397,6 +8772,7 @@ var HostServer = class {
|
|
|
8397
8772
|
for (const auth of this.#auths.values())
|
|
8398
8773
|
auth.cancel();
|
|
8399
8774
|
this.#terminals.closeAll();
|
|
8775
|
+
this.#rootWatcher?.close();
|
|
8400
8776
|
await this.#relay.close();
|
|
8401
8777
|
await Promise.all([...this.#sessions.values()].map((s) => s.close("host shutdown")));
|
|
8402
8778
|
this.#sessions.clear();
|
|
@@ -8522,7 +8898,7 @@ var HostServer = class {
|
|
|
8522
8898
|
/** Активные и архивные проекты разом, с папкой каждого — для `workspace.list`. */
|
|
8523
8899
|
#workspaceLists() {
|
|
8524
8900
|
const withFolder = (w) => {
|
|
8525
|
-
const folderId = this.#
|
|
8901
|
+
const folderId = folderOfProject(this.#projectsRoot(), w.path, new Set(this.#diskFolders));
|
|
8526
8902
|
return folderId ? { ...w, folderId } : w;
|
|
8527
8903
|
};
|
|
8528
8904
|
return {
|
|
@@ -8534,12 +8910,144 @@ var HostServer = class {
|
|
|
8534
8910
|
this.#broadcast({ type: "workspace.list", ...this.#workspaceLists() });
|
|
8535
8911
|
}
|
|
8536
8912
|
#sendFolders(client) {
|
|
8537
|
-
|
|
8913
|
+
void this.#sendFoldersNow(client);
|
|
8914
|
+
}
|
|
8915
|
+
/** Корень проектов: выбранный в настройках или самый обжитой каталог проектов. */
|
|
8916
|
+
#projectsRoot() {
|
|
8917
|
+
return this.#settings.current.projectsRoot ?? this.#roots()[0] ?? homedir8();
|
|
8918
|
+
}
|
|
8919
|
+
async #refreshDiskFolders() {
|
|
8920
|
+
this.#diskFolders = await listDiskFolders(this.#projectsRoot(), this.#workspaces.allPaths());
|
|
8921
|
+
this.#watchProjectsRoot();
|
|
8922
|
+
}
|
|
8923
|
+
/** Следим за корнем: папки появляются и исчезают и без ccv. */
|
|
8924
|
+
#watchProjectsRoot() {
|
|
8925
|
+
const root = this.#projectsRoot();
|
|
8926
|
+
if (root === this.#watchedRoot)
|
|
8927
|
+
return;
|
|
8928
|
+
this.#rootWatcher?.close();
|
|
8929
|
+
this.#watchedRoot = root;
|
|
8930
|
+
this.#rootWatcher = watchRoot(root, () => {
|
|
8931
|
+
void this.#refreshDiskFolders().then(() => {
|
|
8932
|
+
this.#sendFolders();
|
|
8933
|
+
this.#broadcastWorkspaces();
|
|
8934
|
+
});
|
|
8935
|
+
});
|
|
8936
|
+
}
|
|
8937
|
+
async #sendFoldersNow(client) {
|
|
8938
|
+
await this.#refreshDiskFolders();
|
|
8939
|
+
const lists = this.#folders.list();
|
|
8940
|
+
const frame = {
|
|
8941
|
+
type: "folder.list",
|
|
8942
|
+
...lists,
|
|
8943
|
+
projectsRoot: this.#projectsRoot(),
|
|
8944
|
+
workspaceFolders: this.#diskFolders.map((name) => {
|
|
8945
|
+
const id = folderIdFor(name);
|
|
8946
|
+
const color = this.#folders.diskFolderColor(id);
|
|
8947
|
+
return { id, name, ...color ? { color } : {} };
|
|
8948
|
+
})
|
|
8949
|
+
};
|
|
8538
8950
|
if (client)
|
|
8539
8951
|
this.#send(client, frame);
|
|
8540
8952
|
else
|
|
8541
8953
|
this.#broadcast(frame);
|
|
8542
8954
|
}
|
|
8955
|
+
#configDirs() {
|
|
8956
|
+
return this.#accounts.all.map((a) => this.#accounts.effectiveDir(a.id));
|
|
8957
|
+
}
|
|
8958
|
+
/**
|
|
8959
|
+
* Можно ли трогать каталоги: ни сессия, ни терминал ccv, ни агент, запущенный
|
|
8960
|
+
* снаружи, не должны работать внутри. Отказ — понятной фразой, до любых изменений.
|
|
8961
|
+
*/
|
|
8962
|
+
async #guardMove(dirs) {
|
|
8963
|
+
const inside = (target) => dirs.some((dir) => isInside(dir, target));
|
|
8964
|
+
const affected = new Set([...this.#workspaces.list(), ...this.#workspaces.listArchived()].filter((w) => inside(w.path)).map((w) => w.id));
|
|
8965
|
+
const live = [...this.#sessions.values()].filter((sess) => sess.state !== "closed" && affected.has(sess.workspaceId));
|
|
8966
|
+
if (live.length > 0) {
|
|
8967
|
+
throw new Error(`\u0412 \u043F\u0440\u043E\u0435\u043A\u0442\u0435 \u0438\u0434\u0443\u0442 \u0441\u0435\u0441\u0441\u0438\u0438 (${live.length}) \u2014 \u0437\u0430\u043A\u0440\u043E\u0439\u0442\u0435 \u0438\u0445, \u043F\u043E\u0442\u043E\u043C \u043F\u0435\u0440\u0435\u043D\u043E\u0441\u0438\u0442\u0435`);
|
|
8968
|
+
}
|
|
8969
|
+
if (this.#terminals.list().some((t) => affected.has(t.workspaceId))) {
|
|
8970
|
+
throw new Error("\u0412 \u043F\u0440\u043E\u0435\u043A\u0442\u0435 \u043E\u0442\u043A\u0440\u044B\u0442 \u0442\u0435\u0440\u043C\u0438\u043D\u0430\u043B \u2014 \u0437\u0430\u043A\u0440\u043E\u0439\u0442\u0435 \u0435\u0433\u043E, \u043F\u043E\u0442\u043E\u043C \u043F\u0435\u0440\u0435\u043D\u043E\u0441\u0438\u0442\u0435");
|
|
8971
|
+
}
|
|
8972
|
+
const paths = [.../* @__PURE__ */ new Set([...dirs, ...this.#workspaces.allPaths().filter(inside)])];
|
|
8973
|
+
const agent = await externalAgentActivity(paths, this.#configDirs());
|
|
8974
|
+
if (agent) {
|
|
8975
|
+
throw new Error(`\u041F\u043E\u0445\u043E\u0436\u0435, \u0432 \u043F\u0440\u043E\u0435\u043A\u0442\u0435 \u0441\u0435\u0439\u0447\u0430\u0441 \u0440\u0430\u0431\u043E\u0442\u0430\u0435\u0442 ${agent} (\u0437\u0430\u043F\u0443\u0449\u0435\u043D\u043D\u044B\u0439 \u043D\u0435 \u0438\u0437 ccv). \u0414\u043E\u0436\u0434\u0438\u0442\u0435\u0441\u044C \u043A\u043E\u043D\u0446\u0430 \u0440\u0430\u0431\u043E\u0442\u044B \u0438\u043B\u0438 \u043E\u0441\u0442\u0430\u043D\u043E\u0432\u0438\u0442\u0435 \u0435\u0433\u043E, \u043F\u043E\u0442\u043E\u043C \u043F\u0435\u0440\u0435\u043D\u043E\u0441\u0438\u0442\u0435`);
|
|
8976
|
+
}
|
|
8977
|
+
}
|
|
8978
|
+
/**
|
|
8979
|
+
* Переместить каталог и всё, что к нему привязано: транскрипты Claude Code,
|
|
8980
|
+
* запись реестра и записи под id проектов (архив, закрепления, порядок, папки).
|
|
8981
|
+
*/
|
|
8982
|
+
async #relocate(from, to) {
|
|
8983
|
+
await this.#guardMove([from]);
|
|
8984
|
+
const inside = this.#workspaces.allPaths().filter((p) => isInside(from, p));
|
|
8985
|
+
await moveDirectory(from, to, inside, this.#configDirs());
|
|
8986
|
+
const moved = await this.#workspaces.relocate(from, to);
|
|
8987
|
+
const ids = new Map(moved.map((m) => [workspaceIdFromPath(m.from), workspaceIdFromPath(m.to)]));
|
|
8988
|
+
const remap = {
|
|
8989
|
+
targets: (id) => ids.has(id) ? [ids.get(id)] : [],
|
|
8990
|
+
owner: async (id) => ids.get(id)
|
|
8991
|
+
};
|
|
8992
|
+
await this.#antigravity.remapWorkspaceIds(remap);
|
|
8993
|
+
await this.#archive.remapWorkspaceIds(remap);
|
|
8994
|
+
await this.#pins.remapWorkspaceIds(remap);
|
|
8995
|
+
await this.#order.remapWorkspaceIds(remap);
|
|
8996
|
+
await this.#folders.remapWorkspaceIds(remap);
|
|
8997
|
+
this.#diskAccounts.clear();
|
|
8998
|
+
await this.#refreshDiskFolders();
|
|
8999
|
+
this.#broadcastWorkspaces();
|
|
9000
|
+
this.#sendFolders();
|
|
9001
|
+
for (const move of moved)
|
|
9002
|
+
await this.#sendSessionList(workspaceIdFromPath(move.to));
|
|
9003
|
+
}
|
|
9004
|
+
async #moveProjectToFolder(workspaceId, folderId) {
|
|
9005
|
+
const workspace = this.#workspaces.find(workspaceId);
|
|
9006
|
+
if (!workspace)
|
|
9007
|
+
throw new Error("\u041F\u0440\u043E\u0435\u043A\u0442 \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D");
|
|
9008
|
+
const root = this.#projectsRoot();
|
|
9009
|
+
let parent = root;
|
|
9010
|
+
if (folderId !== null) {
|
|
9011
|
+
const name = folderNameOf(folderId);
|
|
9012
|
+
if (!name || !this.#diskFolders.includes(name))
|
|
9013
|
+
throw new Error("\u041F\u0430\u043F\u043A\u0430 \u043F\u0440\u043E\u0435\u043A\u0442\u043E\u0432 \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D\u0430 \u043D\u0430 \u0434\u0438\u0441\u043A\u0435");
|
|
9014
|
+
parent = path26.join(root, name);
|
|
9015
|
+
}
|
|
9016
|
+
const to = path26.join(parent, path26.basename(workspace.path));
|
|
9017
|
+
if (path26.resolve(to).toLowerCase() === path26.resolve(workspace.path).toLowerCase())
|
|
9018
|
+
return;
|
|
9019
|
+
await this.#relocate(workspace.path, to);
|
|
9020
|
+
}
|
|
9021
|
+
async #renameDiskFolder(folderId, rawName) {
|
|
9022
|
+
const old = folderNameOf(folderId);
|
|
9023
|
+
if (!old)
|
|
9024
|
+
return;
|
|
9025
|
+
const name = cleanFolderName(rawName);
|
|
9026
|
+
if (name === old)
|
|
9027
|
+
return;
|
|
9028
|
+
const root = this.#projectsRoot();
|
|
9029
|
+
await this.#relocate(path26.join(root, old), path26.join(root, name));
|
|
9030
|
+
await this.#folders.renameDiskFolder(folderId, folderIdFor(name), name);
|
|
9031
|
+
this.#sendFolders();
|
|
9032
|
+
}
|
|
9033
|
+
async #deleteDiskFolder(folderId) {
|
|
9034
|
+
const name = folderNameOf(folderId);
|
|
9035
|
+
if (!name)
|
|
9036
|
+
return;
|
|
9037
|
+
const dir = path26.join(this.#projectsRoot(), name);
|
|
9038
|
+
const foreign = await foreignContent(dir, this.#workspaces.allPaths());
|
|
9039
|
+
if (foreign) {
|
|
9040
|
+
throw new Error(`\u0412 \u043F\u0430\u043F\u043A\u0435 \u0435\u0441\u0442\u044C \xAB${foreign}\xBB, \u044D\u0442\u043E \u043D\u0435 \u043F\u0440\u043E\u0435\u043A\u0442 ccv \u2014 \u0443\u0431\u0435\u0440\u0438\u0442\u0435 \u044D\u0442\u043E \u0438 \u0443\u0434\u0430\u043B\u0438\u0442\u0435 \u043F\u0430\u043F\u043A\u0443 \u0441\u043D\u043E\u0432\u0430`);
|
|
9041
|
+
}
|
|
9042
|
+
for (const project of this.#workspaces.allPaths().filter((p) => isInside(dir, p))) {
|
|
9043
|
+
await this.#relocate(project, path26.join(this.#projectsRoot(), path26.basename(project)));
|
|
9044
|
+
}
|
|
9045
|
+
await removeEmptyDir(dir);
|
|
9046
|
+
await this.#folders.forgetDiskFolder(folderId);
|
|
9047
|
+
await this.#refreshDiskFolders();
|
|
9048
|
+
this.#sendFolders();
|
|
9049
|
+
this.#broadcastWorkspaces();
|
|
9050
|
+
}
|
|
8543
9051
|
async #handleFrame(socket, frame) {
|
|
8544
9052
|
switch (frame.type) {
|
|
8545
9053
|
case "hello":
|
|
@@ -8615,7 +9123,16 @@ var HostServer = class {
|
|
|
8615
9123
|
this.#send(socket, { type: "workspace.roots", roots: this.#roots() });
|
|
8616
9124
|
return;
|
|
8617
9125
|
case "workspace.create": {
|
|
8618
|
-
|
|
9126
|
+
let parent = frame.parent;
|
|
9127
|
+
if (frame.folderId) {
|
|
9128
|
+
const name = folderNameOf(frame.folderId);
|
|
9129
|
+
await this.#refreshDiskFolders();
|
|
9130
|
+
if (!name || !this.#diskFolders.includes(name))
|
|
9131
|
+
throw new Error("\u041F\u0430\u043F\u043A\u0430 \u043F\u0440\u043E\u0435\u043A\u0442\u043E\u0432 \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D\u0430 \u043D\u0430 \u0434\u0438\u0441\u043A\u0435");
|
|
9132
|
+
parent = path26.join(this.#projectsRoot(), name);
|
|
9133
|
+
}
|
|
9134
|
+
const { workspace, warnings } = await this.#workspaces.create(parent, frame.name, frame.init);
|
|
9135
|
+
await this.#refreshDiskFolders();
|
|
8619
9136
|
this.#broadcastWorkspaces();
|
|
8620
9137
|
this.#send(socket, { type: "workspace.created", workspace, warnings });
|
|
8621
9138
|
await this.#closeFinder();
|
|
@@ -8709,20 +9226,31 @@ var HostServer = class {
|
|
|
8709
9226
|
} else if (frame.scope === "pinned") {
|
|
8710
9227
|
await this.#folders.createPinnedFolder(frame.name);
|
|
8711
9228
|
} else {
|
|
8712
|
-
await this.#
|
|
9229
|
+
await createDiskFolder(this.#projectsRoot(), frame.name);
|
|
8713
9230
|
}
|
|
8714
9231
|
this.#sendFolders();
|
|
8715
9232
|
return;
|
|
8716
9233
|
}
|
|
8717
9234
|
case "folder.rename":
|
|
9235
|
+
if (folderNameOf(frame.folderId)) {
|
|
9236
|
+
await this.#renameDiskFolder(frame.folderId, frame.name);
|
|
9237
|
+
return;
|
|
9238
|
+
}
|
|
8718
9239
|
if (await this.#folders.rename(frame.folderId, frame.name))
|
|
8719
9240
|
this.#sendFolders();
|
|
8720
9241
|
return;
|
|
8721
|
-
case "folder.setColor":
|
|
8722
|
-
|
|
9242
|
+
case "folder.setColor": {
|
|
9243
|
+
const diskName = folderNameOf(frame.folderId);
|
|
9244
|
+
const changed = diskName ? await this.#folders.setDiskFolderColor(frame.folderId, diskName, frame.color) : await this.#folders.setColor(frame.folderId, frame.color);
|
|
9245
|
+
if (changed)
|
|
8723
9246
|
this.#sendFolders();
|
|
8724
9247
|
return;
|
|
9248
|
+
}
|
|
8725
9249
|
case "folder.delete": {
|
|
9250
|
+
if (folderNameOf(frame.folderId)) {
|
|
9251
|
+
await this.#deleteDiskFolder(frame.folderId);
|
|
9252
|
+
return;
|
|
9253
|
+
}
|
|
8726
9254
|
const removed = await this.#folders.delete(frame.folderId);
|
|
8727
9255
|
if (!removed)
|
|
8728
9256
|
return;
|
|
@@ -8745,8 +9273,7 @@ var HostServer = class {
|
|
|
8745
9273
|
await this.#folders.assignPinnedSession(frame.itemId, frame.folderId);
|
|
8746
9274
|
await this.#sendPinned();
|
|
8747
9275
|
} else {
|
|
8748
|
-
await this.#
|
|
8749
|
-
this.#broadcastWorkspaces();
|
|
9276
|
+
await this.#moveProjectToFolder(frame.itemId, frame.folderId);
|
|
8750
9277
|
}
|
|
8751
9278
|
return;
|
|
8752
9279
|
}
|
|
@@ -9246,6 +9773,11 @@ var HostServer = class {
|
|
|
9246
9773
|
const before = this.#settings.current;
|
|
9247
9774
|
const settings = await this.#settings.update(frame.settings);
|
|
9248
9775
|
this.#broadcast({ type: "settings.state", settings });
|
|
9776
|
+
if (settings.projectsRoot !== before.projectsRoot) {
|
|
9777
|
+
await this.#refreshDiskFolders();
|
|
9778
|
+
this.#sendFolders();
|
|
9779
|
+
this.#broadcastWorkspaces();
|
|
9780
|
+
}
|
|
9249
9781
|
if (settings.autoArchiveAfterMs !== before.autoArchiveAfterMs) {
|
|
9250
9782
|
for (const workspace of this.#workspaces.list()) {
|
|
9251
9783
|
await this.#sendSessionList(workspace.id);
|
|
@@ -9316,6 +9848,8 @@ var HostServer = class {
|
|
|
9316
9848
|
if (frame.configDir !== void 0) {
|
|
9317
9849
|
this.#authFor(frame.accountId).cancel();
|
|
9318
9850
|
this.#auths.delete(frame.accountId);
|
|
9851
|
+
this.#lastUsage.delete(frame.accountId);
|
|
9852
|
+
this.#probedUsage.delete(frame.accountId);
|
|
9319
9853
|
}
|
|
9320
9854
|
await this.#sendAccounts();
|
|
9321
9855
|
return;
|
|
@@ -9340,6 +9874,9 @@ var HostServer = class {
|
|
|
9340
9874
|
await this.#sendSessionList(workspace.id);
|
|
9341
9875
|
return;
|
|
9342
9876
|
}
|
|
9877
|
+
case "accounts.usage":
|
|
9878
|
+
await this.#refreshAccountUsage();
|
|
9879
|
+
return;
|
|
9343
9880
|
case "accounts.discover":
|
|
9344
9881
|
this.#send(socket, {
|
|
9345
9882
|
type: "accounts.candidates",
|
|
@@ -10151,7 +10688,7 @@ var HostServer = class {
|
|
|
10151
10688
|
*/
|
|
10152
10689
|
#roots() {
|
|
10153
10690
|
const roots = this.#finder.roots();
|
|
10154
|
-
return roots.length > 0 ? roots : [
|
|
10691
|
+
return roots.length > 0 ? roots : [homedir8()];
|
|
10155
10692
|
}
|
|
10156
10693
|
/**
|
|
10157
10694
|
* Где сессии этого каталога разрешено писать без вопроса.
|
|
@@ -10163,22 +10700,22 @@ var HostServer = class {
|
|
|
10163
10700
|
#writableRoots(cwd) {
|
|
10164
10701
|
return writableRoots(this.#settings.current.folderAccess, cwd, this.#workspaces.list().map((workspace) => workspace.path));
|
|
10165
10702
|
}
|
|
10166
|
-
#findWithAgent(
|
|
10703
|
+
#findWithAgent(query3) {
|
|
10167
10704
|
const roots = this.#finder.roots();
|
|
10168
10705
|
if (roots.length === 0) {
|
|
10169
10706
|
this.#broadcast({
|
|
10170
10707
|
type: "workspace.candidates",
|
|
10171
|
-
query:
|
|
10708
|
+
query: query3,
|
|
10172
10709
|
source: "agent",
|
|
10173
10710
|
candidates: [],
|
|
10174
10711
|
truncated: false
|
|
10175
10712
|
});
|
|
10176
10713
|
return;
|
|
10177
10714
|
}
|
|
10178
|
-
this.#finderQuery =
|
|
10715
|
+
this.#finderQuery = query3;
|
|
10179
10716
|
const session = this.#ensureFinder(roots);
|
|
10180
10717
|
this.#broadcast({ type: "finder.opened", sessionId: session.id });
|
|
10181
|
-
session.sendPrompt(finderPrompt(
|
|
10718
|
+
session.sendPrompt(finderPrompt(query3, roots));
|
|
10182
10719
|
}
|
|
10183
10720
|
#ensureFinder(roots) {
|
|
10184
10721
|
const existing = this.#finderSession;
|
|
@@ -10500,15 +11037,15 @@ var HostServer = class {
|
|
|
10500
11037
|
}
|
|
10501
11038
|
#serveStatic(req, res) {
|
|
10502
11039
|
const webRoot = this.#options.webRoot;
|
|
10503
|
-
if (!webRoot || !
|
|
11040
|
+
if (!webRoot || !existsSync6(webRoot)) {
|
|
10504
11041
|
res.writeHead(200, { "content-type": "text/plain; charset=utf-8" });
|
|
10505
11042
|
res.end("CCV host is running. UI is served by the Vite dev server.\n");
|
|
10506
11043
|
return;
|
|
10507
11044
|
}
|
|
10508
11045
|
const url2 = new URL(req.url ?? "/", "http://localhost");
|
|
10509
|
-
const requested =
|
|
10510
|
-
const target = requested.startsWith(webRoot) &&
|
|
10511
|
-
if (!
|
|
11046
|
+
const requested = path26.join(webRoot, path26.normalize(url2.pathname));
|
|
11047
|
+
const target = requested.startsWith(webRoot) && existsSync6(requested) && statSync3(requested).isFile() ? requested : path26.join(webRoot, "index.html");
|
|
11048
|
+
if (!existsSync6(target)) {
|
|
10512
11049
|
res.writeHead(404).end("not found");
|
|
10513
11050
|
return;
|
|
10514
11051
|
}
|
|
@@ -10533,7 +11070,7 @@ function contentType(file) {
|
|
|
10533
11070
|
".svg": "image/svg+xml",
|
|
10534
11071
|
".woff2": "font/woff2"
|
|
10535
11072
|
};
|
|
10536
|
-
return types[
|
|
11073
|
+
return types[path26.extname(file)] ?? "application/octet-stream";
|
|
10537
11074
|
}
|
|
10538
11075
|
function antigravitySummary(record) {
|
|
10539
11076
|
return {
|
|
@@ -10563,8 +11100,8 @@ function antigravitySummary(record) {
|
|
|
10563
11100
|
}
|
|
10564
11101
|
|
|
10565
11102
|
// dist/ccv.js
|
|
10566
|
-
var HERE =
|
|
10567
|
-
var PACKAGE_ROOT =
|
|
11103
|
+
var HERE = path27.dirname(fileURLToPath(import.meta.url));
|
|
11104
|
+
var PACKAGE_ROOT = path27.resolve(HERE, "..");
|
|
10568
11105
|
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.
|
|
10569
11106
|
|
|
10570
11107
|
\u0418\u0441\u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u043D\u0438\u0435:
|
|
@@ -10631,7 +11168,7 @@ var server = new HostServer({
|
|
|
10631
11168
|
dataDir: defaults.dataDir,
|
|
10632
11169
|
// UI лежит в пакете рядом с бандлом — это и есть разница между установленной
|
|
10633
11170
|
// утилитой и запуском из репозитория, где сборка живёт в `apps/web/dist`.
|
|
10634
|
-
webRoot: process.env.CCV_WEB_ROOT ??
|
|
11171
|
+
webRoot: process.env.CCV_WEB_ROOT ?? path27.join(PACKAGE_ROOT, "web"),
|
|
10635
11172
|
version,
|
|
10636
11173
|
relayUrl: defaults.relayUrl
|
|
10637
11174
|
});
|
|
@@ -10660,7 +11197,7 @@ for (const signal of ["SIGINT", "SIGTERM"]) {
|
|
|
10660
11197
|
}
|
|
10661
11198
|
async function packageVersion() {
|
|
10662
11199
|
try {
|
|
10663
|
-
const text = await
|
|
11200
|
+
const text = await readFile19(path27.join(PACKAGE_ROOT, "package.json"), "utf8");
|
|
10664
11201
|
return JSON.parse(text).version ?? "0.0.0";
|
|
10665
11202
|
} catch {
|
|
10666
11203
|
return "0.0.0";
|