@i14ks/ccv 0.44.0 → 0.45.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/THIRD-PARTY-NOTICES.md +1726 -62
- package/bundle/ccv.mjs +2813 -453
- package/package.json +1 -1
- package/web/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
- package/web/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
- package/web/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
- package/web/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
- package/web/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
- package/web/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
- package/web/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
- package/web/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
- package/web/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
- package/web/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
- package/web/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
- package/web/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
- package/web/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
- package/web/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
- package/web/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
- package/web/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
- package/web/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
- package/web/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
- package/web/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
- package/web/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
- package/web/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
- package/web/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
- package/web/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
- package/web/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
- package/web/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
- package/web/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
- package/web/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
- package/web/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
- package/web/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
- package/web/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
- package/web/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
- package/web/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
- package/web/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
- package/web/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
- package/web/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
- package/web/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
- package/web/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
- package/web/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
- package/web/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
- package/web/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
- package/web/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
- package/web/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
- package/web/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
- package/web/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
- package/web/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
- package/web/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
- package/web/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
- package/web/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
- package/web/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
- package/web/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
- package/web/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
- package/web/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
- package/web/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
- package/web/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
- package/web/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
- package/web/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
- package/web/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
- package/web/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
- package/web/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
- package/web/assets/abnfDiagram-S7VZAUFO-CNj02zRV.js +1 -0
- package/web/assets/architectureDiagram-YGSQEFNW-UnapXBnq.js +36 -0
- package/web/assets/blockDiagram-APKKGZFW-By1mA1_j.js +140 -0
- package/web/assets/bpmnIcons-APHXDYXF-ByGoYv9M.js +1 -0
- package/web/assets/c4Diagram-KJ2TOQU5-DxR8Tp-K.js +38 -0
- package/web/assets/chunk-2Q5K7J3B-CfcIu3Ah.js +1 -0
- package/web/assets/chunk-5VM5RSS4-Ddk-Fv2Y.js +15 -0
- package/web/assets/chunk-HFQBQIA3-DqPjzTQu.js +1 -0
- package/web/assets/chunk-JWPE2WC7-VUIzkY_4.js +1 -0
- package/web/assets/chunk-KQLB2F66-Bi85gKHH.js +2 -0
- package/web/assets/chunk-KS47KZWR-BZwBvPDM.js +1 -0
- package/web/assets/chunk-OY52VR5R-B_DWv6kS.js +88 -0
- package/web/assets/chunk-TU62E6Q5-BZ5M8LNU.js +1 -0
- package/web/assets/chunk-XXDRQBXY-DcC5f1oO.js +1 -0
- package/web/assets/classDiagram-v2-L25IHNXF-CiZfI5zH.js +217 -0
- package/web/assets/{codemirror-CpnHxn-s.js → codemirror-B_zWrnLp.js} +1 -1
- package/web/assets/cose-bilkent-JH36ORCC-OecldNrx.js +1 -0
- package/web/assets/cynefin-EF2NZ3EQ-BHDQXZEc.js +141 -0
- package/web/assets/cynefinDiagram-L36ESFBY-COnZzGKx.js +62 -0
- package/web/assets/cytoscape.esm-Bw5aGq32.js +332 -0
- package/web/assets/d3-scale-4DPf7zan.js +1 -0
- package/web/assets/dagre-SPEB5RXH-XxNubJTv.js +4 -0
- package/web/assets/diagram-3B7GL73J-BEpsszbY.js +200 -0
- package/web/assets/diagram-DNEMPZML-DAKChpAZ.js +24 -0
- package/web/assets/diagram-L3MUGCDN-CvDcHjXy.js +41 -0
- package/web/assets/diagram-LA4NIPWU-BO-n7J3S.js +24 -0
- package/web/assets/diagram-MHCOC4E2-BW8MchVY.js +3 -0
- package/web/assets/diagram-XPFHEONP-DjiEBmkx.js +30 -0
- package/web/assets/ebnfDiagram-UZSYDL2S-DKGunvzj.js +1 -0
- package/web/assets/elk-XV6XMXQE-b9lmTG03.js +2 -0
- package/web/assets/erDiagram-EYBAPDEH-DT_k1OGC.js +99 -0
- package/web/assets/flowDiagram-MALGAFMO-BUqGlWOn.js +213 -0
- package/web/assets/ganttDiagram-23REXITY-Cbr_kL7O.js +292 -0
- package/web/assets/gitGraphDiagram-STJD7YCW-Cw6S4Bcr.js +106 -0
- package/web/assets/graph-Bn3Yngep.js +1 -0
- package/web/assets/index-B1IBfUz9.css +1 -0
- package/web/assets/{index-BIaTEYpO.js → index-B5vdEupB.js} +1 -1
- package/web/assets/{index-BjcBtkKx.js → index-BLmLDrEY.js} +1 -1
- package/web/assets/{index-CWyId3-O.js → index-BO8effSp.js} +1 -1
- package/web/assets/index-BYJrmc8N.js +1 -0
- package/web/assets/{index-BCNV5J5e.js → index-B_SP1UWv.js} +1 -1
- package/web/assets/index-BdwT0-rx.js +152 -0
- package/web/assets/index-BoggcMUx.js +7 -0
- package/web/assets/{index-891wE-Rj.js → index-COYbUhJ2.js} +1 -1
- package/web/assets/index-CfWAy0wv.js +1 -0
- package/web/assets/{index-C6vpveFy.js → index-Ch08lakn.js} +1 -1
- package/web/assets/index-Cl3pbMFT.js +1 -0
- package/web/assets/index-CnRY1mXR.js +1 -0
- package/web/assets/index-Ctc6whsQ.js +1 -0
- package/web/assets/{index-BPiJlpKF.js → index-D7DCXKEo.js} +1 -1
- package/web/assets/{index-B6h8VCuY.js → index-DQnArn0a.js} +1 -1
- package/web/assets/{index-BnIobsSF.js → index-DnFYUU1x.js} +1 -1
- package/web/assets/{index-DqFhjq3T.js → index-Du5Qar1T.js} +1 -1
- package/web/assets/{index-CFOaholk.js → index-DvFMS_gT.js} +4 -4
- package/web/assets/{index-6xG2dMZE.js → index-HQJZpoPE.js} +1 -1
- package/web/assets/{index-DOU-NfbM.js → index-dkD_YPIB.js} +2 -2
- package/web/assets/{index-DVVbk6ww.js → index-qkpXZNl3.js} +1 -1
- package/web/assets/infoDiagram-KBXO4MBG-CusT957H.js +2 -0
- package/web/assets/ishikawaDiagram-M35NCXHK-DlxUISb3.js +70 -0
- package/web/assets/journeyDiagram-OPLOXDXO-B7X0y02x.js +139 -0
- package/web/assets/kanban-definition-BZKZHSQY-DzEKGEDz.js +89 -0
- package/web/assets/katex-DFbIS0RS.js +257 -0
- package/web/assets/katex-DxB02YXk.css +1 -0
- package/web/assets/katex-RYEII7GN.js +257 -0
- package/web/assets/mermaid.core-BM9CG8VU.js +312 -0
- package/web/assets/mindmap-definition-I2QAS2VK-DgE3KgdI.js +98 -0
- package/web/assets/pegDiagram-FD4XPPHP-2wTO2ZJT.js +1 -0
- package/web/assets/pieDiagram-J4AKIIQI-CKRDBux_.js +39 -0
- package/web/assets/quadrantDiagram-XTYBLID2-Ceg_KG7b.js +7 -0
- package/web/assets/railroadDiagram-MRQ6NCDL-DkyGV8eQ.js +1 -0
- package/web/assets/requirementDiagram-Y7LWUY3S-DEpWnvQ5.js +84 -0
- package/web/assets/sankeyDiagram-WGJFYUXA-D06-ObVT.js +40 -0
- package/web/assets/sequenceDiagram-5NDRBG5M-CNgwRsPl.js +169 -0
- package/web/assets/sizeCapture-INFHLROL-DLPIeXe1.js +1 -0
- package/web/assets/stateDiagram-v2-FJ4FJNEA-CjTQ5dpG.js +291 -0
- package/web/assets/swimlanes-UMQ2AFYF-eJkqG_t9.js +1 -0
- package/web/assets/swimlanesDiagram-OMPLPG4O-D-nejod0.js +8 -0
- package/web/assets/timeline-definition-SEUHKTQE-CUTdCFpH.js +120 -0
- package/web/assets/usecaseDiagram-AFA6YXN4-BHojL49I.js +370 -0
- package/web/assets/vennDiagram-NNMJR3RB-Bk5isaer.js +34 -0
- package/web/assets/wardleyDiagram-S7YFUSEH-DolRO_uR.js +78 -0
- package/web/assets/xychartDiagram-GGNKY7IX-V3IUgdp-.js +7 -0
- package/web/index.html +2 -2
- package/web/assets/index-BCr4Xq2t.js +0 -1
- package/web/assets/index-BTBYwWBS.js +0 -1
- package/web/assets/index-CBzCYPlp.css +0 -1
- package/web/assets/index-DesNy3O4.js +0 -1
- package/web/assets/index-DmPq7iLF.js +0 -1
- package/web/assets/index-Dxbgrz7x.js +0 -135
- package/web/assets/index-EbSAIVkK.js +0 -1
- package/web/assets/index-Tib36HVB.js +0 -7
package/bundle/ccv.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// dist/ccv.js
|
|
4
|
-
import { spawn as
|
|
5
|
-
import { readFile as
|
|
6
|
-
import
|
|
4
|
+
import { spawn as spawn4 } from "node:child_process";
|
|
5
|
+
import { readFile as readFile21 } from "node:fs/promises";
|
|
6
|
+
import path34 from "node:path";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
8
|
import { parseArgs } from "node:util";
|
|
9
9
|
|
|
@@ -146,10 +146,10 @@ 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
|
|
152
|
-
import { randomUUID as
|
|
149
|
+
import { createReadStream as createReadStream2, existsSync as existsSync7, statSync as statSync3 } from "node:fs";
|
|
150
|
+
import path33 from "node:path";
|
|
151
|
+
import { homedir as homedir9 } from "node:os";
|
|
152
|
+
import { randomUUID as randomUUID9 } from "node:crypto";
|
|
153
153
|
import { WebSocketServer } from "ws";
|
|
154
154
|
import { renameSession as renameSession2 } from "@anthropic-ai/claude-agent-sdk";
|
|
155
155
|
|
|
@@ -168,6 +168,12 @@ var SHARED_CONFIG_ITEMS = [
|
|
|
168
168
|
"keybindings.json"
|
|
169
169
|
];
|
|
170
170
|
var ACCOUNT_COLORS = ["orange", "blue", "green", "purple", "pink", "teal"];
|
|
171
|
+
var ATTACHMENT_LIMITS = {
|
|
172
|
+
/** Картинок и документов вместе в одном промпте. */
|
|
173
|
+
maxCount: 5,
|
|
174
|
+
/** Суммарный размер документов (байты исходных файлов). */
|
|
175
|
+
maxTotalBytes: 5 * 1024 * 1024
|
|
176
|
+
};
|
|
171
177
|
function isClientFrame(value) {
|
|
172
178
|
return typeof value === "object" && value !== null && typeof value.type === "string";
|
|
173
179
|
}
|
|
@@ -455,7 +461,7 @@ async function exists(file) {
|
|
|
455
461
|
return lstat(file).then(() => true, () => false);
|
|
456
462
|
}
|
|
457
463
|
async function isRealEntry(file) {
|
|
458
|
-
return lstat(file).then((
|
|
464
|
+
return lstat(file).then((stat6) => !stat6.isSymbolicLink(), () => false);
|
|
459
465
|
}
|
|
460
466
|
async function candidateConfigDirs() {
|
|
461
467
|
const home = homedir2();
|
|
@@ -535,15 +541,257 @@ function toWindow(raw) {
|
|
|
535
541
|
};
|
|
536
542
|
}
|
|
537
543
|
|
|
544
|
+
// ../host/dist/content-search.js
|
|
545
|
+
import { createReadStream } from "node:fs";
|
|
546
|
+
import { readdir as readdir2, stat as stat2 } from "node:fs/promises";
|
|
547
|
+
import path5 from "node:path";
|
|
548
|
+
import { createInterface } from "node:readline";
|
|
549
|
+
|
|
550
|
+
// ../host/dist/attachments.js
|
|
551
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
552
|
+
import { tmpdir } from "node:os";
|
|
553
|
+
import path4 from "node:path";
|
|
554
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
555
|
+
var ATTACHMENT_NOTE_OPEN = "<ccv-attachments>";
|
|
556
|
+
var ATTACHMENT_NOTE_CLOSE = "</ccv-attachments>";
|
|
557
|
+
function attachmentMeta(attachments) {
|
|
558
|
+
if (!attachments || attachments.length === 0)
|
|
559
|
+
return void 0;
|
|
560
|
+
return attachments.map(({ kind, name, mediaType, size }) => ({ kind, name, mediaType, size }));
|
|
561
|
+
}
|
|
562
|
+
function checkAttachments(images, attachments) {
|
|
563
|
+
const count2 = (images?.length ?? 0) + (attachments?.length ?? 0);
|
|
564
|
+
if (count2 > ATTACHMENT_LIMITS.maxCount) {
|
|
565
|
+
throw new Error(`\u041D\u0435 \u0431\u043E\u043B\u044C\u0448\u0435 ${ATTACHMENT_LIMITS.maxCount} \u0432\u043B\u043E\u0436\u0435\u043D\u0438\u0439 \u0432 \u043E\u0434\u043D\u043E\u043C \u0441\u043E\u043E\u0431\u0449\u0435\u043D\u0438\u0438`);
|
|
566
|
+
}
|
|
567
|
+
let total = 0;
|
|
568
|
+
for (const attachment of attachments ?? []) {
|
|
569
|
+
if (!["pdf", "text", "file"].includes(attachment.kind)) {
|
|
570
|
+
throw new Error(`\u041D\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043D\u044B\u0439 \u0432\u0438\u0434 \u0432\u043B\u043E\u0436\u0435\u043D\u0438\u044F: ${String(attachment.kind)}`);
|
|
571
|
+
}
|
|
572
|
+
total += Buffer.byteLength(attachment.data, "base64");
|
|
573
|
+
}
|
|
574
|
+
if (total > ATTACHMENT_LIMITS.maxTotalBytes) {
|
|
575
|
+
throw new Error("\u0412\u043B\u043E\u0436\u0435\u043D\u0438\u044F \u0431\u043E\u043B\u044C\u0448\u0435 5 \u041C\u0411 \u0432\u043C\u0435\u0441\u0442\u0435 \u2014 \u043D\u0435 \u043E\u0442\u043F\u0440\u0430\u0432\u043B\u0435\u043D\u044B");
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
function safeName(name) {
|
|
579
|
+
const base = path4.basename(name.replace(/\\/g, "/")).replace(/[<>:"/\\|?*\u0000-\u001f]/g, "_").trim();
|
|
580
|
+
return base.slice(0, 120) || "attachment";
|
|
581
|
+
}
|
|
582
|
+
function saveAttachment(attachment, owner) {
|
|
583
|
+
const dir = path4.join(tmpdir(), "ccv-attachments", owner, randomUUID2());
|
|
584
|
+
mkdirSync(dir, { recursive: true });
|
|
585
|
+
const file = path4.join(dir, safeName(attachment.name));
|
|
586
|
+
writeFileSync(file, Buffer.from(attachment.data, "base64"));
|
|
587
|
+
return file;
|
|
588
|
+
}
|
|
589
|
+
function attachmentNote(paths) {
|
|
590
|
+
if (paths.length === 0)
|
|
591
|
+
return "";
|
|
592
|
+
return `
|
|
593
|
+
|
|
594
|
+
${ATTACHMENT_NOTE_OPEN}
|
|
595
|
+
Attached file${paths.length > 1 ? "s" : ""} saved on disk (read with your tools):
|
|
596
|
+
` + paths.map((p) => `- ${p}`).join("\n") + `
|
|
597
|
+
${ATTACHMENT_NOTE_CLOSE}`;
|
|
598
|
+
}
|
|
599
|
+
function attachmentBlocks(attachments, owner) {
|
|
600
|
+
const blocks = [];
|
|
601
|
+
const saved = [];
|
|
602
|
+
for (const attachment of attachments ?? []) {
|
|
603
|
+
if (attachment.kind === "pdf") {
|
|
604
|
+
blocks.push({
|
|
605
|
+
type: "document",
|
|
606
|
+
source: { type: "base64", media_type: "application/pdf", data: attachment.data },
|
|
607
|
+
title: attachment.name
|
|
608
|
+
});
|
|
609
|
+
} else if (attachment.kind === "text") {
|
|
610
|
+
blocks.push({
|
|
611
|
+
type: "document",
|
|
612
|
+
source: {
|
|
613
|
+
type: "text",
|
|
614
|
+
media_type: "text/plain",
|
|
615
|
+
data: Buffer.from(attachment.data, "base64").toString("utf8")
|
|
616
|
+
},
|
|
617
|
+
title: attachment.name
|
|
618
|
+
});
|
|
619
|
+
} else {
|
|
620
|
+
saved.push(saveAttachment(attachment, owner));
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
return { blocks, note: attachmentNote(saved) };
|
|
624
|
+
}
|
|
625
|
+
function stripAttachmentNote(text) {
|
|
626
|
+
const start = text.indexOf(ATTACHMENT_NOTE_OPEN);
|
|
627
|
+
if (start < 0)
|
|
628
|
+
return { text, names: [] };
|
|
629
|
+
const end = text.indexOf(ATTACHMENT_NOTE_CLOSE, start);
|
|
630
|
+
const body = text.slice(start, end < 0 ? void 0 : end);
|
|
631
|
+
const names2 = [...body.matchAll(/^- (.+)$/gm)].map((m) => path4.basename(m[1].trim()));
|
|
632
|
+
const rest = text.slice(0, start) + (end < 0 ? "" : text.slice(end + ATTACHMENT_NOTE_CLOSE.length));
|
|
633
|
+
return { text: rest.trimEnd(), names: names2 };
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
// ../host/dist/content-search.js
|
|
637
|
+
var CONTENT_SEARCH_LIMIT = 50;
|
|
638
|
+
var CONTENT_SEARCH_MIN = 3;
|
|
639
|
+
var MAX_CACHED_CHARS = 2e6;
|
|
640
|
+
var SNIPPET_RADIUS = 90;
|
|
641
|
+
var ContentSearch = class {
|
|
642
|
+
#cache = /* @__PURE__ */ new Map();
|
|
643
|
+
/** sessionId → файл транскрипта; пересобирается, если файл не найден. */
|
|
644
|
+
#files = /* @__PURE__ */ new Map();
|
|
645
|
+
async search(query3, targets) {
|
|
646
|
+
const needle = query3.trim().toLowerCase();
|
|
647
|
+
if (needle.length < CONTENT_SEARCH_MIN)
|
|
648
|
+
return [];
|
|
649
|
+
const ordered = [...targets].sort((a, b) => b.lastModified - a.lastModified);
|
|
650
|
+
const hits = [];
|
|
651
|
+
const indexed = /* @__PURE__ */ new Set();
|
|
652
|
+
for (const target of ordered) {
|
|
653
|
+
if (hits.length >= CONTENT_SEARCH_LIMIT)
|
|
654
|
+
break;
|
|
655
|
+
let file = this.#files.get(target.sessionId);
|
|
656
|
+
if (!file && !indexed.has(target.configDir)) {
|
|
657
|
+
indexed.add(target.configDir);
|
|
658
|
+
await this.#index(target.configDir);
|
|
659
|
+
file = this.#files.get(target.sessionId);
|
|
660
|
+
}
|
|
661
|
+
if (!file)
|
|
662
|
+
continue;
|
|
663
|
+
const messages = await this.#messages(file);
|
|
664
|
+
if (!messages) {
|
|
665
|
+
this.#files.delete(target.sessionId);
|
|
666
|
+
continue;
|
|
667
|
+
}
|
|
668
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
669
|
+
const message = messages[i];
|
|
670
|
+
const at = message.text.toLowerCase().indexOf(needle);
|
|
671
|
+
if (at < 0)
|
|
672
|
+
continue;
|
|
673
|
+
hits.push({
|
|
674
|
+
sessionId: target.sessionId,
|
|
675
|
+
workspaceId: target.workspaceId,
|
|
676
|
+
title: target.title,
|
|
677
|
+
role: message.role,
|
|
678
|
+
...snippet(message.text, at, needle.length),
|
|
679
|
+
timestamp: message.ts
|
|
680
|
+
});
|
|
681
|
+
break;
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
return hits;
|
|
685
|
+
}
|
|
686
|
+
/** Найти все транскрипты каталога аккаунта. */
|
|
687
|
+
async #index(configDir) {
|
|
688
|
+
const root = path5.join(configDir, "projects");
|
|
689
|
+
let dirs;
|
|
690
|
+
try {
|
|
691
|
+
dirs = await readdir2(root);
|
|
692
|
+
} catch {
|
|
693
|
+
return;
|
|
694
|
+
}
|
|
695
|
+
for (const dir of dirs) {
|
|
696
|
+
let names2;
|
|
697
|
+
try {
|
|
698
|
+
names2 = await readdir2(path5.join(root, dir));
|
|
699
|
+
} catch {
|
|
700
|
+
continue;
|
|
701
|
+
}
|
|
702
|
+
for (const name of names2) {
|
|
703
|
+
if (!name.endsWith(".jsonl"))
|
|
704
|
+
continue;
|
|
705
|
+
this.#files.set(name.slice(0, -".jsonl".length), path5.join(root, dir, name));
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
async #messages(file) {
|
|
710
|
+
let mtime;
|
|
711
|
+
try {
|
|
712
|
+
mtime = (await stat2(file)).mtimeMs;
|
|
713
|
+
} catch {
|
|
714
|
+
this.#cache.delete(file);
|
|
715
|
+
return null;
|
|
716
|
+
}
|
|
717
|
+
const cached = this.#cache.get(file);
|
|
718
|
+
if (cached && cached.mtime === mtime)
|
|
719
|
+
return cached.messages;
|
|
720
|
+
const messages = await readMessages(file);
|
|
721
|
+
this.#cache.set(file, { mtime, messages });
|
|
722
|
+
return messages;
|
|
723
|
+
}
|
|
724
|
+
};
|
|
725
|
+
async function readMessages(file) {
|
|
726
|
+
const messages = [];
|
|
727
|
+
let chars = 0;
|
|
728
|
+
const lines = createInterface({ input: createReadStream(file, "utf8"), crlfDelay: Infinity });
|
|
729
|
+
for await (const line of lines) {
|
|
730
|
+
if (chars > MAX_CACHED_CHARS)
|
|
731
|
+
break;
|
|
732
|
+
if (!line.includes('"type":"user"') && !line.includes('"type":"assistant"'))
|
|
733
|
+
continue;
|
|
734
|
+
let entry;
|
|
735
|
+
try {
|
|
736
|
+
entry = JSON.parse(line);
|
|
737
|
+
} catch {
|
|
738
|
+
continue;
|
|
739
|
+
}
|
|
740
|
+
if (entry.type !== "user" && entry.type !== "assistant")
|
|
741
|
+
continue;
|
|
742
|
+
if (entry.isSidechain || entry.isMeta)
|
|
743
|
+
continue;
|
|
744
|
+
const text = textOf(entry.message?.content, entry.type);
|
|
745
|
+
if (!text)
|
|
746
|
+
continue;
|
|
747
|
+
const ts = entry.timestamp ? Date.parse(entry.timestamp) : NaN;
|
|
748
|
+
messages.push({ role: entry.type, text, ts: Number.isFinite(ts) ? ts : null });
|
|
749
|
+
chars += text.length;
|
|
750
|
+
}
|
|
751
|
+
return messages;
|
|
752
|
+
}
|
|
753
|
+
function textOf(content, role) {
|
|
754
|
+
const parts = [];
|
|
755
|
+
if (typeof content === "string")
|
|
756
|
+
parts.push(content);
|
|
757
|
+
else if (Array.isArray(content)) {
|
|
758
|
+
for (const block of content) {
|
|
759
|
+
if (block && typeof block === "object" && block.type === "text" && typeof block.text === "string") {
|
|
760
|
+
parts.push(block.text);
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
let text = parts.join("\n").trim();
|
|
765
|
+
if (role === "user") {
|
|
766
|
+
text = stripAttachmentNote(text).text;
|
|
767
|
+
if (/^<(command-|local-command|system-reminder|bash-)/.test(text))
|
|
768
|
+
return "";
|
|
769
|
+
}
|
|
770
|
+
return text;
|
|
771
|
+
}
|
|
772
|
+
function snippet(text, at, length) {
|
|
773
|
+
const start = Math.max(0, at - SNIPPET_RADIUS);
|
|
774
|
+
const end = Math.min(text.length, at + length + SNIPPET_RADIUS);
|
|
775
|
+
const prefix = start > 0 ? "\u2026" : "";
|
|
776
|
+
const suffix = end < text.length ? "\u2026" : "";
|
|
777
|
+
const body = text.slice(start, end).replace(/\s+/g, " ");
|
|
778
|
+
const beforeMatch = text.slice(start, at).replace(/\s+/g, " ");
|
|
779
|
+
return {
|
|
780
|
+
snippet: prefix + body + suffix,
|
|
781
|
+
matchStart: prefix.length + beforeMatch.length,
|
|
782
|
+
matchLength: text.slice(at, at + length).replace(/\s+/g, " ").length
|
|
783
|
+
};
|
|
784
|
+
}
|
|
785
|
+
|
|
538
786
|
// ../host/dist/workspace-ids.js
|
|
539
787
|
function workspaceIdRemap(paths, sessionsOf) {
|
|
540
788
|
const byLegacy = /* @__PURE__ */ new Map();
|
|
541
|
-
for (const
|
|
542
|
-
const id = workspaceIdFromPath(
|
|
543
|
-
for (const legacy of formerWorkspaceIdsFromPath(
|
|
789
|
+
for (const path35 of paths) {
|
|
790
|
+
const id = workspaceIdFromPath(path35);
|
|
791
|
+
for (const legacy of formerWorkspaceIdsFromPath(path35)) {
|
|
544
792
|
const group = byLegacy.get(legacy) ?? [];
|
|
545
793
|
if (!group.some((target) => target.id === id))
|
|
546
|
-
group.push({ id, path:
|
|
794
|
+
group.push({ id, path: path35 });
|
|
547
795
|
byLegacy.set(legacy, group);
|
|
548
796
|
}
|
|
549
797
|
}
|
|
@@ -575,13 +823,132 @@ function workspaceIdRemap(paths, sessionsOf) {
|
|
|
575
823
|
|
|
576
824
|
// ../host/dist/session.js
|
|
577
825
|
import { EventEmitter as EventEmitter2 } from "node:events";
|
|
578
|
-
import { randomUUID as
|
|
579
|
-
import
|
|
826
|
+
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
827
|
+
import path9 from "node:path";
|
|
580
828
|
import { query as query2, renameSession } from "@anthropic-ai/claude-agent-sdk";
|
|
581
829
|
|
|
582
830
|
// ../host/dist/files.js
|
|
583
|
-
import { cp, lstat as lstat2, mkdir as mkdir2, readFile as readFile3, readdir as
|
|
584
|
-
import
|
|
831
|
+
import { cp, lstat as lstat2, mkdir as mkdir2, readFile as readFile3, readdir as readdir3, realpath, rename as renamePath, rm, stat as stat3, writeFile as writeFile2 } from "node:fs/promises";
|
|
832
|
+
import path7 from "node:path";
|
|
833
|
+
|
|
834
|
+
// ../host/dist/html-preview.js
|
|
835
|
+
import path6 from "node:path";
|
|
836
|
+
var PREVIEW_ASSET_BUDGET = 5 * 1024 * 1024;
|
|
837
|
+
var MIME = {
|
|
838
|
+
".png": "image/png",
|
|
839
|
+
".jpg": "image/jpeg",
|
|
840
|
+
".jpeg": "image/jpeg",
|
|
841
|
+
".gif": "image/gif",
|
|
842
|
+
".webp": "image/webp",
|
|
843
|
+
".avif": "image/avif",
|
|
844
|
+
".bmp": "image/bmp",
|
|
845
|
+
".ico": "image/x-icon",
|
|
846
|
+
".svg": "image/svg+xml",
|
|
847
|
+
".css": "text/css",
|
|
848
|
+
".js": "text/javascript",
|
|
849
|
+
".mjs": "text/javascript",
|
|
850
|
+
".json": "application/json",
|
|
851
|
+
".woff": "font/woff",
|
|
852
|
+
".woff2": "font/woff2",
|
|
853
|
+
".ttf": "font/ttf",
|
|
854
|
+
".otf": "font/otf",
|
|
855
|
+
".mp3": "audio/mpeg",
|
|
856
|
+
".wav": "audio/wav",
|
|
857
|
+
".ogg": "audio/ogg",
|
|
858
|
+
".mp4": "video/mp4",
|
|
859
|
+
".webm": "video/webm",
|
|
860
|
+
".txt": "text/plain"
|
|
861
|
+
};
|
|
862
|
+
var NAVIGATION_TAGS = /* @__PURE__ */ new Set(["a", "area", "base", "form"]);
|
|
863
|
+
async function buildPreview(source, pagePath, assets) {
|
|
864
|
+
const missing = /* @__PURE__ */ new Set();
|
|
865
|
+
const cache = /* @__PURE__ */ new Map();
|
|
866
|
+
let budget = PREVIEW_ASSET_BUDGET;
|
|
867
|
+
const inline = async (reference, baseDir2) => {
|
|
868
|
+
const target = resolveReference(reference, baseDir2);
|
|
869
|
+
if (!target)
|
|
870
|
+
return null;
|
|
871
|
+
if (cache.has(target))
|
|
872
|
+
return cache.get(target);
|
|
873
|
+
let result = null;
|
|
874
|
+
const bytes = await assets.read(target);
|
|
875
|
+
if (bytes && bytes.length <= budget) {
|
|
876
|
+
const ext = path6.posix.extname(target).toLowerCase();
|
|
877
|
+
const mime = MIME[ext] ?? "application/octet-stream";
|
|
878
|
+
let payload = bytes;
|
|
879
|
+
if (ext === ".css") {
|
|
880
|
+
const css = await rewriteCssUrls(bytes.toString("utf8"), path6.posix.dirname(target), inline);
|
|
881
|
+
payload = Buffer.from(css, "utf8");
|
|
882
|
+
}
|
|
883
|
+
if (payload.length <= budget) {
|
|
884
|
+
budget -= payload.length;
|
|
885
|
+
result = `data:${mime};base64,${payload.toString("base64")}`;
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
if (!result)
|
|
889
|
+
missing.add(reference);
|
|
890
|
+
cache.set(target, result);
|
|
891
|
+
return result;
|
|
892
|
+
};
|
|
893
|
+
const baseDir = path6.posix.dirname(pagePath);
|
|
894
|
+
let html = await replaceAsync(source, /<([a-zA-Z][\w:-]*)(\s[^<>]*?)?(\/?)>/g, async (whole, tag, attrs, selfClose) => {
|
|
895
|
+
if (!attrs)
|
|
896
|
+
return whole;
|
|
897
|
+
const name = tag.toLowerCase();
|
|
898
|
+
const rewritten = await replaceAsync(attrs, /(\s(?:xlink:)?(src|href|poster|data))(\s*=\s*)("([^"]*)"|'([^']*)')/gi, async (attr, prefix, key, eq, _q, dq, sq) => {
|
|
899
|
+
if (key.toLowerCase() === "href" && NAVIGATION_TAGS.has(name))
|
|
900
|
+
return attr;
|
|
901
|
+
const value = dq ?? sq ?? "";
|
|
902
|
+
const data = await inline(value, baseDir);
|
|
903
|
+
return data ? `${prefix}${eq}"${data}"` : attr;
|
|
904
|
+
});
|
|
905
|
+
const styled = await rewriteCssUrls(rewritten, baseDir, inline);
|
|
906
|
+
return `<${tag}${styled}${selfClose}>`;
|
|
907
|
+
});
|
|
908
|
+
html = await replaceAsync(html, /(<style\b[^>]*>)([\s\S]*?)(<\/style>)/gi, async (_whole, open, css, close) => `${open}${await rewriteCssUrls(css, baseDir, inline)}${close}`);
|
|
909
|
+
return { html, missing: [...missing] };
|
|
910
|
+
}
|
|
911
|
+
async function rewriteCssUrls(css, baseDir, inline) {
|
|
912
|
+
return replaceAsync(css, /url\(\s*(?:"([^"]*)"|'([^']*)'|([^)'"\s]+))\s*\)/gi, async (whole, dq, sq, bare) => {
|
|
913
|
+
const value = dq ?? sq ?? bare ?? "";
|
|
914
|
+
const data = await inline(value.replace(/"|'/g, ""), baseDir);
|
|
915
|
+
return data ? `url("${data}")` : whole;
|
|
916
|
+
});
|
|
917
|
+
}
|
|
918
|
+
function resolveReference(reference, baseDir) {
|
|
919
|
+
const raw = reference.trim();
|
|
920
|
+
if (!raw || raw.startsWith("#") || raw.startsWith("//"))
|
|
921
|
+
return null;
|
|
922
|
+
if (/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(raw))
|
|
923
|
+
return null;
|
|
924
|
+
const clean = raw.split(/[?#]/)[0];
|
|
925
|
+
let decoded;
|
|
926
|
+
try {
|
|
927
|
+
decoded = decodeURIComponent(clean);
|
|
928
|
+
} catch {
|
|
929
|
+
decoded = clean;
|
|
930
|
+
}
|
|
931
|
+
const joined = decoded.startsWith("/") ? path6.posix.normalize(decoded.slice(1)) : path6.posix.normalize(path6.posix.join(baseDir === "." ? "" : baseDir, decoded));
|
|
932
|
+
if (!joined || joined === "." || joined.startsWith("..") || path6.posix.isAbsolute(joined)) {
|
|
933
|
+
return null;
|
|
934
|
+
}
|
|
935
|
+
return joined;
|
|
936
|
+
}
|
|
937
|
+
async function replaceAsync(input, pattern, replacer) {
|
|
938
|
+
const parts = [];
|
|
939
|
+
let last = 0;
|
|
940
|
+
for (const match of input.matchAll(pattern)) {
|
|
941
|
+
const index = match.index ?? 0;
|
|
942
|
+
parts.push(input.slice(last, index));
|
|
943
|
+
parts.push(await replacer(...match));
|
|
944
|
+
last = index + match[0].length;
|
|
945
|
+
}
|
|
946
|
+
parts.push(input.slice(last));
|
|
947
|
+
return (await Promise.all(parts)).join("");
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
// ../host/dist/files.js
|
|
951
|
+
var PREVIEW_EXTENSIONS = /* @__PURE__ */ new Set([".html", ".htm", ".svg"]);
|
|
585
952
|
var MAX_FILE = 4 * 1024 * 1024;
|
|
586
953
|
var MAX_MEDIA = 64 * 1024 * 1024;
|
|
587
954
|
var MEDIA_MIME = {
|
|
@@ -614,14 +981,14 @@ var ProjectFiles = class {
|
|
|
614
981
|
}
|
|
615
982
|
async list(relative) {
|
|
616
983
|
const dir = await this.#resolve(relative);
|
|
617
|
-
const names2 = await
|
|
984
|
+
const names2 = await readdir3(dir, { withFileTypes: true });
|
|
618
985
|
const entries = [];
|
|
619
986
|
for (const dirent of names2) {
|
|
620
987
|
if (HIDDEN.has(dirent.name))
|
|
621
988
|
continue;
|
|
622
|
-
const full =
|
|
989
|
+
const full = path7.join(dir, dirent.name);
|
|
623
990
|
const link2 = dirent.isSymbolicLink();
|
|
624
|
-
const info = await
|
|
991
|
+
const info = await stat3(full).catch(() => null);
|
|
625
992
|
if (!info)
|
|
626
993
|
continue;
|
|
627
994
|
entries.push({
|
|
@@ -661,15 +1028,15 @@ var ProjectFiles = class {
|
|
|
661
1028
|
const walk = async (dir, relative) => {
|
|
662
1029
|
if (truncated)
|
|
663
1030
|
return;
|
|
664
|
-
const names2 = await
|
|
1031
|
+
const names2 = await readdir3(dir, { withFileTypes: true }).catch(() => []);
|
|
665
1032
|
for (const dirent of names2) {
|
|
666
1033
|
if (truncated)
|
|
667
1034
|
return;
|
|
668
1035
|
if (SEARCH_SKIP.has(dirent.name))
|
|
669
1036
|
continue;
|
|
670
|
-
const full =
|
|
1037
|
+
const full = path7.join(dir, dirent.name);
|
|
671
1038
|
const rel = join(relative, dirent.name);
|
|
672
|
-
const info = await
|
|
1039
|
+
const info = await stat3(full).catch(() => null);
|
|
673
1040
|
if (!info)
|
|
674
1041
|
continue;
|
|
675
1042
|
const isDir = info.isDirectory();
|
|
@@ -716,13 +1083,13 @@ var ProjectFiles = class {
|
|
|
716
1083
|
const walk = async (dir, relative) => {
|
|
717
1084
|
if (truncated)
|
|
718
1085
|
return;
|
|
719
|
-
const names2 = await
|
|
1086
|
+
const names2 = await readdir3(dir, { withFileTypes: true }).catch(() => []);
|
|
720
1087
|
for (const dirent of names2) {
|
|
721
1088
|
if (truncated)
|
|
722
1089
|
return;
|
|
723
1090
|
if (SEARCH_SKIP.has(dirent.name) || dirent.isSymbolicLink())
|
|
724
1091
|
continue;
|
|
725
|
-
const full =
|
|
1092
|
+
const full = path7.join(dir, dirent.name);
|
|
726
1093
|
const rel = join(relative, dirent.name);
|
|
727
1094
|
if (dirent.isDirectory()) {
|
|
728
1095
|
await walk(full, rel);
|
|
@@ -730,7 +1097,7 @@ var ProjectFiles = class {
|
|
|
730
1097
|
}
|
|
731
1098
|
if (!dirent.isFile())
|
|
732
1099
|
continue;
|
|
733
|
-
const info = await
|
|
1100
|
+
const info = await stat3(full).catch(() => null);
|
|
734
1101
|
if (!info || info.size > MAX_FILE)
|
|
735
1102
|
continue;
|
|
736
1103
|
const buffer = await readFile3(full).catch(() => null);
|
|
@@ -777,7 +1144,7 @@ var ProjectFiles = class {
|
|
|
777
1144
|
}
|
|
778
1145
|
async read(relative) {
|
|
779
1146
|
const file = await this.#resolve(relative);
|
|
780
|
-
const info = await
|
|
1147
|
+
const info = await stat3(file);
|
|
781
1148
|
if (info.isDirectory())
|
|
782
1149
|
throw new Error("\u042D\u0442\u043E \u043A\u0430\u0442\u0430\u043B\u043E\u0433, \u0430 \u043D\u0435 \u0444\u0430\u0439\u043B");
|
|
783
1150
|
const blank = {
|
|
@@ -790,7 +1157,7 @@ var ProjectFiles = class {
|
|
|
790
1157
|
binary: false,
|
|
791
1158
|
tooLarge: false
|
|
792
1159
|
};
|
|
793
|
-
const mediaMime = MEDIA_MIME[
|
|
1160
|
+
const mediaMime = MEDIA_MIME[path7.extname(file).toLowerCase()];
|
|
794
1161
|
if (mediaMime) {
|
|
795
1162
|
if (info.size > MAX_MEDIA)
|
|
796
1163
|
return { ...blank, binary: true, mediaMime, mediaTooLarge: true };
|
|
@@ -821,10 +1188,10 @@ var ProjectFiles = class {
|
|
|
821
1188
|
*/
|
|
822
1189
|
async readMedia(relative) {
|
|
823
1190
|
const file = await this.#resolve(relative);
|
|
824
|
-
const mime = MEDIA_MIME[
|
|
1191
|
+
const mime = MEDIA_MIME[path7.extname(file).toLowerCase()];
|
|
825
1192
|
if (!mime)
|
|
826
1193
|
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");
|
|
827
|
-
const info = await
|
|
1194
|
+
const info = await stat3(file);
|
|
828
1195
|
if (info.isDirectory())
|
|
829
1196
|
throw new Error("\u042D\u0442\u043E \u043A\u0430\u0442\u0430\u043B\u043E\u0433, \u0430 \u043D\u0435 \u0444\u0430\u0439\u043B");
|
|
830
1197
|
if (info.size > MAX_MEDIA)
|
|
@@ -832,6 +1199,39 @@ var ProjectFiles = class {
|
|
|
832
1199
|
const buffer = await readFile3(file);
|
|
833
1200
|
return { mime, base64: buffer.toString("base64") };
|
|
834
1201
|
}
|
|
1202
|
+
/**
|
|
1203
|
+
* Превью HTML/SVG-страницы: её текст с ресурсами проекта, подставленными
|
|
1204
|
+
* как `data:` URL (см. `html-preview.ts`). Каждый ресурс проходит через ту
|
|
1205
|
+
* же `#resolve`, что и любой путь из кадра, — ссылка `../../x.png` или
|
|
1206
|
+
* символическая ссылка за пределы проекта ничего не прочитает.
|
|
1207
|
+
*/
|
|
1208
|
+
async preview(relative) {
|
|
1209
|
+
const file = await this.#resolve(relative);
|
|
1210
|
+
const ext = path7.extname(file).toLowerCase();
|
|
1211
|
+
if (!PREVIEW_EXTENSIONS.has(ext))
|
|
1212
|
+
throw new Error("\u041F\u0440\u0435\u0432\u044C\u044E \u0435\u0441\u0442\u044C \u0442\u043E\u043B\u044C\u043A\u043E \u0443 HTML \u0438 SVG");
|
|
1213
|
+
const info = await stat3(file);
|
|
1214
|
+
if (info.isDirectory())
|
|
1215
|
+
throw new Error("\u042D\u0442\u043E \u043A\u0430\u0442\u0430\u043B\u043E\u0433, \u0430 \u043D\u0435 \u0444\u0430\u0439\u043B");
|
|
1216
|
+
if (info.size > MAX_FILE)
|
|
1217
|
+
throw new Error("\u0424\u0430\u0439\u043B \u0441\u043B\u0438\u0448\u043A\u043E\u043C \u0432\u0435\u043B\u0438\u043A \u0434\u043B\u044F \u043F\u0440\u0435\u0432\u044C\u044E");
|
|
1218
|
+
const source = await readFile3(file, "utf8");
|
|
1219
|
+
const pagePath = normalize(relative);
|
|
1220
|
+
const { html, missing } = await buildPreview(source, pagePath, {
|
|
1221
|
+
read: async (target) => {
|
|
1222
|
+
try {
|
|
1223
|
+
const asset = await this.#resolve(target);
|
|
1224
|
+
const assetInfo = await stat3(asset);
|
|
1225
|
+
if (!assetInfo.isFile() || assetInfo.size > PREVIEW_ASSET_BUDGET)
|
|
1226
|
+
return null;
|
|
1227
|
+
return await readFile3(asset);
|
|
1228
|
+
} catch {
|
|
1229
|
+
return null;
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
});
|
|
1233
|
+
return { html, mtime: Math.round(info.mtimeMs), missing };
|
|
1234
|
+
}
|
|
835
1235
|
/**
|
|
836
1236
|
* Записать файл, если его на диске не подменили.
|
|
837
1237
|
*
|
|
@@ -842,7 +1242,7 @@ var ProjectFiles = class {
|
|
|
842
1242
|
*/
|
|
843
1243
|
async write(relative, content, eol, encoding, baseMtime, force = false) {
|
|
844
1244
|
const file = await this.#resolve(relative);
|
|
845
|
-
const info = await
|
|
1245
|
+
const info = await stat3(file).catch(() => null);
|
|
846
1246
|
if (info?.isDirectory())
|
|
847
1247
|
throw new Error("\u042D\u0442\u043E \u043A\u0430\u0442\u0430\u043B\u043E\u0433, \u0430 \u043D\u0435 \u0444\u0430\u0439\u043B");
|
|
848
1248
|
if (!force) {
|
|
@@ -852,7 +1252,7 @@ var ProjectFiles = class {
|
|
|
852
1252
|
}
|
|
853
1253
|
}
|
|
854
1254
|
await writeFile2(file, encode(content, eol, encoding));
|
|
855
|
-
const saved = await
|
|
1255
|
+
const saved = await stat3(file);
|
|
856
1256
|
return { mtime: Math.round(saved.mtimeMs), size: saved.size };
|
|
857
1257
|
}
|
|
858
1258
|
async create(relative, kind) {
|
|
@@ -863,7 +1263,7 @@ var ProjectFiles = class {
|
|
|
863
1263
|
await mkdir2(target, { recursive: true });
|
|
864
1264
|
return;
|
|
865
1265
|
}
|
|
866
|
-
await mkdir2(
|
|
1266
|
+
await mkdir2(path7.dirname(target), { recursive: true });
|
|
867
1267
|
await writeFile2(target, "", { encoding: "utf8", flag: "wx" });
|
|
868
1268
|
}
|
|
869
1269
|
async rename(relative, to) {
|
|
@@ -873,7 +1273,7 @@ var ProjectFiles = class {
|
|
|
873
1273
|
return;
|
|
874
1274
|
if (await exists2(target))
|
|
875
1275
|
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");
|
|
876
|
-
await mkdir2(
|
|
1276
|
+
await mkdir2(path7.dirname(target), { recursive: true });
|
|
877
1277
|
await renamePath(from, target);
|
|
878
1278
|
}
|
|
879
1279
|
/**
|
|
@@ -890,7 +1290,7 @@ var ProjectFiles = class {
|
|
|
890
1290
|
if (!source)
|
|
891
1291
|
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");
|
|
892
1292
|
const from = await this.#resolve(source);
|
|
893
|
-
const info = await
|
|
1293
|
+
const info = await stat3(from);
|
|
894
1294
|
const dir = normalize(toDir);
|
|
895
1295
|
if (info.isDirectory() && (dir === source || dir.startsWith(`${source}/`))) {
|
|
896
1296
|
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");
|
|
@@ -906,7 +1306,7 @@ var ProjectFiles = class {
|
|
|
906
1306
|
if (!await exists2(to))
|
|
907
1307
|
break;
|
|
908
1308
|
}
|
|
909
|
-
await mkdir2(
|
|
1309
|
+
await mkdir2(path7.dirname(to), { recursive: true });
|
|
910
1310
|
await cp(from, to, { recursive: true, errorOnExist: true, force: false });
|
|
911
1311
|
return target;
|
|
912
1312
|
}
|
|
@@ -926,15 +1326,15 @@ var ProjectFiles = class {
|
|
|
926
1326
|
*/
|
|
927
1327
|
async #resolve(relative) {
|
|
928
1328
|
const clean = normalize(relative);
|
|
929
|
-
if (
|
|
1329
|
+
if (path7.isAbsolute(clean) || /^[A-Za-z]:/.test(clean)) {
|
|
930
1330
|
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");
|
|
931
1331
|
}
|
|
932
1332
|
if (clean.split("/").includes("..")) {
|
|
933
1333
|
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");
|
|
934
1334
|
}
|
|
935
1335
|
const root = this.#root ??= await realpath(this.cwd);
|
|
936
|
-
const target =
|
|
937
|
-
const probe = await exists2(target) ? target :
|
|
1336
|
+
const target = path7.resolve(root, clean);
|
|
1337
|
+
const probe = await exists2(target) ? target : path7.dirname(target);
|
|
938
1338
|
const real = await realpath(probe).catch(() => probe);
|
|
939
1339
|
if (!contains(root, real)) {
|
|
940
1340
|
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");
|
|
@@ -955,7 +1355,7 @@ function join(dir, name) {
|
|
|
955
1355
|
function contains(root, target) {
|
|
956
1356
|
if (target === root)
|
|
957
1357
|
return true;
|
|
958
|
-
const prefix = root.endsWith(
|
|
1358
|
+
const prefix = root.endsWith(path7.sep) ? root : root + path7.sep;
|
|
959
1359
|
return process.platform === "win32" ? target.toLowerCase().startsWith(prefix.toLowerCase()) : target.startsWith(prefix);
|
|
960
1360
|
}
|
|
961
1361
|
async function exists2(file) {
|
|
@@ -1261,14 +1661,14 @@ function interfacesSignature() {
|
|
|
1261
1661
|
// ../host/dist/settings.js
|
|
1262
1662
|
import { readFile as readFile4 } from "node:fs/promises";
|
|
1263
1663
|
import { homedir as homedir3 } from "node:os";
|
|
1264
|
-
import
|
|
1265
|
-
var USER_SETTINGS =
|
|
1266
|
-
var PROJECT_SETTINGS =
|
|
1267
|
-
var LOCAL_SETTINGS =
|
|
1664
|
+
import path8 from "node:path";
|
|
1665
|
+
var USER_SETTINGS = path8.join(homedir3(), ".claude", "settings.json");
|
|
1666
|
+
var PROJECT_SETTINGS = path8.join(".claude", "settings.json");
|
|
1667
|
+
var LOCAL_SETTINGS = path8.join(".claude", "settings.local.json");
|
|
1268
1668
|
function managedSettingsPath() {
|
|
1269
1669
|
switch (process.platform) {
|
|
1270
1670
|
case "win32":
|
|
1271
|
-
return
|
|
1671
|
+
return path8.join(process.env.PROGRAMDATA ?? "C:\\ProgramData", "ClaudeCode", "managed-settings.json");
|
|
1272
1672
|
case "darwin":
|
|
1273
1673
|
return "/Library/Application Support/ClaudeCode/managed-settings.json";
|
|
1274
1674
|
default:
|
|
@@ -1279,8 +1679,8 @@ var EFFORT_LEVELS = ["low", "medium", "high", "xhigh", "max"];
|
|
|
1279
1679
|
async function readConfiguredDefaults(cwd) {
|
|
1280
1680
|
const files = [
|
|
1281
1681
|
USER_SETTINGS,
|
|
1282
|
-
|
|
1283
|
-
|
|
1682
|
+
path8.join(cwd, PROJECT_SETTINGS),
|
|
1683
|
+
path8.join(cwd, LOCAL_SETTINGS),
|
|
1284
1684
|
managedSettingsPath()
|
|
1285
1685
|
];
|
|
1286
1686
|
const result = {
|
|
@@ -1374,11 +1774,29 @@ async function readTranscript(sessionId, options2) {
|
|
|
1374
1774
|
record({ kind: "user.message", text }, ts);
|
|
1375
1775
|
continue;
|
|
1376
1776
|
}
|
|
1777
|
+
const files = [];
|
|
1778
|
+
for (const block of content) {
|
|
1779
|
+
if (block.type !== "document")
|
|
1780
|
+
continue;
|
|
1781
|
+
const source = block.source;
|
|
1782
|
+
const isText = source?.type === "text";
|
|
1783
|
+
files.push({
|
|
1784
|
+
kind: isText ? "text" : "pdf",
|
|
1785
|
+
name: typeof block.title === "string" && block.title ? block.title : "\u0434\u043E\u043A\u0443\u043C\u0435\u043D\u0442",
|
|
1786
|
+
mediaType: isText ? "text/plain" : "application/pdf",
|
|
1787
|
+
size: typeof source?.data === "string" ? isText ? Buffer.byteLength(source.data, "utf8") : Buffer.byteLength(source.data, "base64") : 0
|
|
1788
|
+
});
|
|
1789
|
+
}
|
|
1377
1790
|
for (const block of content) {
|
|
1378
1791
|
if (block.type === "text" && typeof block.text === "string") {
|
|
1379
|
-
const
|
|
1380
|
-
|
|
1381
|
-
|
|
1792
|
+
const stripped = stripAttachmentNote(block.text);
|
|
1793
|
+
const text = humanText(stripped.text);
|
|
1794
|
+
for (const name of stripped.names) {
|
|
1795
|
+
files.push({ kind: "file", name, mediaType: "application/octet-stream", size: 0 });
|
|
1796
|
+
}
|
|
1797
|
+
if (text || files.length > 0) {
|
|
1798
|
+
record({ kind: "user.message", text, ...files.length > 0 ? { files: files.splice(0) } : {} }, ts);
|
|
1799
|
+
}
|
|
1382
1800
|
} else if (block.type === "tool_result") {
|
|
1383
1801
|
record({
|
|
1384
1802
|
kind: "tool.result",
|
|
@@ -1436,7 +1854,7 @@ async function locateResumePoint(sessionId, dir, userIndex, configDir = null) {
|
|
|
1436
1854
|
continue;
|
|
1437
1855
|
if (message.type === "user" && isHumanTurn(message)) {
|
|
1438
1856
|
if (seen === userIndex)
|
|
1439
|
-
return { resumeAt: lastUuid };
|
|
1857
|
+
return { resumeAt: lastUuid, userUuid: message.uuid };
|
|
1440
1858
|
seen += 1;
|
|
1441
1859
|
}
|
|
1442
1860
|
lastUuid = message.uuid;
|
|
@@ -1844,6 +2262,8 @@ var ClaudeSession = class extends EventEmitter2 {
|
|
|
1844
2262
|
#lastPrompt = null;
|
|
1845
2263
|
/** Картинки того же хода — идут в повтор вместе с `#lastPrompt`. */
|
|
1846
2264
|
#lastImages = void 0;
|
|
2265
|
+
/** Документы того же хода. */
|
|
2266
|
+
#lastAttachments = void 0;
|
|
1847
2267
|
/**
|
|
1848
2268
|
* Ход успел что-то предпринять: вызвал инструмент или сказал что-то своё.
|
|
1849
2269
|
*
|
|
@@ -1857,7 +2277,7 @@ var ClaudeSession = class extends EventEmitter2 {
|
|
|
1857
2277
|
constructor(options2) {
|
|
1858
2278
|
super();
|
|
1859
2279
|
this.#options = options2;
|
|
1860
|
-
this.id = options2.resume && !options2.fork ? options2.resume :
|
|
2280
|
+
this.id = options2.resume && !options2.fork ? options2.resume : randomUUID3();
|
|
1861
2281
|
this.workspaceId = options2.workspaceId;
|
|
1862
2282
|
this.cwd = options2.cwd;
|
|
1863
2283
|
this.#permissionMode = options2.permissionMode ?? "default";
|
|
@@ -1992,6 +2412,9 @@ var ClaudeSession = class extends EventEmitter2 {
|
|
|
1992
2412
|
allowDangerouslySkipPermissions: true,
|
|
1993
2413
|
// Даёт посимвольный стрим ответа, а не «тишина, потом стена текста».
|
|
1994
2414
|
includePartialMessages: true,
|
|
2415
|
+
// Перед каждой правкой файла CLI сохраняет копию — по ней «Откатить
|
|
2416
|
+
// файлы» (`rewindFiles` ниже) возвращает их к состоянию на реплику.
|
|
2417
|
+
enableFileCheckpointing: true,
|
|
1995
2418
|
canUseTool: this.#canUseTool,
|
|
1996
2419
|
hooks: {
|
|
1997
2420
|
PreToolUse: [
|
|
@@ -2100,9 +2523,10 @@ var ClaudeSession = class extends EventEmitter2 {
|
|
|
2100
2523
|
const last = retry[retry.length - 1];
|
|
2101
2524
|
this.#lastPrompt = last?.text ?? null;
|
|
2102
2525
|
this.#lastImages = last?.images;
|
|
2526
|
+
this.#lastAttachments = last?.attachments;
|
|
2103
2527
|
this.#setState("running");
|
|
2104
2528
|
for (const item of retry)
|
|
2105
|
-
this.#push(item.text, item.images);
|
|
2529
|
+
this.#push(item.text, item.images, item.attachments);
|
|
2106
2530
|
}
|
|
2107
2531
|
/**
|
|
2108
2532
|
* Что известно о сессии до system/init.
|
|
@@ -2287,13 +2711,14 @@ var ClaudeSession = class extends EventEmitter2 {
|
|
|
2287
2711
|
// -------------------------------------------------------------------------
|
|
2288
2712
|
// Ввод от пользователя
|
|
2289
2713
|
// -------------------------------------------------------------------------
|
|
2290
|
-
sendPrompt(text, images, service = false) {
|
|
2714
|
+
sendPrompt(text, images, service = false, attachments) {
|
|
2291
2715
|
if (this.#closing)
|
|
2292
2716
|
throw new Error("session is closed");
|
|
2293
2717
|
const blocked = networkGuard.blockedReason();
|
|
2294
2718
|
if (blocked)
|
|
2295
2719
|
throw new Error(`${blocked}. \u041F\u0440\u043E\u043C\u043F\u0442 \u043D\u0435 \u043E\u0442\u043F\u0440\u0430\u0432\u043B\u0435\u043D.`);
|
|
2296
|
-
|
|
2720
|
+
checkAttachments(images, attachments);
|
|
2721
|
+
this.#record({ kind: "user.message", text, images, files: attachmentMeta(attachments) });
|
|
2297
2722
|
if (!service && (!this.#title || this.#titleIsDefault)) {
|
|
2298
2723
|
this.#title = text.slice(0, 80);
|
|
2299
2724
|
this.#titleIsDefault = false;
|
|
@@ -2302,14 +2727,15 @@ var ClaudeSession = class extends EventEmitter2 {
|
|
|
2302
2727
|
this.#interruptRequested = false;
|
|
2303
2728
|
this.#lastPrompt = text;
|
|
2304
2729
|
this.#lastImages = images;
|
|
2730
|
+
this.#lastAttachments = attachments;
|
|
2305
2731
|
this.#turnDidWork = false;
|
|
2306
2732
|
if (!this.#query) {
|
|
2307
|
-
this.#pendingRetry.push({ text, images });
|
|
2733
|
+
this.#pendingRetry.push({ text, images, attachments });
|
|
2308
2734
|
this.reconnect("\u0441\u0435\u0441\u0441\u0438\u0438 \u043D\u0443\u0436\u0435\u043D \u043F\u0440\u043E\u0446\u0435\u0441\u0441 \u0434\u043B\u044F \u043D\u043E\u0432\u043E\u0433\u043E \u043F\u0440\u043E\u043C\u043F\u0442\u0430");
|
|
2309
2735
|
return;
|
|
2310
2736
|
}
|
|
2311
2737
|
this.#setState("running");
|
|
2312
|
-
this.#push(text, images);
|
|
2738
|
+
this.#push(text, images, attachments);
|
|
2313
2739
|
}
|
|
2314
2740
|
/**
|
|
2315
2741
|
* Отредактировать реплику `userIndex` — как в любом AI-чате: всё, что было
|
|
@@ -2327,7 +2753,7 @@ var ClaudeSession = class extends EventEmitter2 {
|
|
|
2327
2753
|
* `Journal`) — иначе новые события пришли бы с номерами, которые клиент уже
|
|
2328
2754
|
* видел, и дедупликация по `seq` в `timeline.ts` их бы молча съела.
|
|
2329
2755
|
*/
|
|
2330
|
-
async editPrompt(userIndex, text, images) {
|
|
2756
|
+
async editPrompt(userIndex, text, images, attachments, rewindFiles = false) {
|
|
2331
2757
|
if (this.#closing)
|
|
2332
2758
|
throw new Error("session is closed");
|
|
2333
2759
|
const blocked = networkGuard.blockedReason();
|
|
@@ -2344,14 +2770,49 @@ var ClaudeSession = class extends EventEmitter2 {
|
|
|
2344
2770
|
});
|
|
2345
2771
|
return;
|
|
2346
2772
|
}
|
|
2773
|
+
let rewindError = null;
|
|
2774
|
+
if (rewindFiles && this.#query) {
|
|
2775
|
+
try {
|
|
2776
|
+
const result = await this.#query.rewindFiles(anchor.userUuid);
|
|
2777
|
+
if (!result.canRewind)
|
|
2778
|
+
rewindError = result.error ?? "\u0447\u0435\u043A\u043F\u043E\u0438\u043D\u0442 \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D";
|
|
2779
|
+
} catch (error) {
|
|
2780
|
+
rewindError = error instanceof Error ? error.message : String(error);
|
|
2781
|
+
}
|
|
2782
|
+
} else if (rewindFiles) {
|
|
2783
|
+
rewindError = "\u0443 \u0441\u0435\u0441\u0441\u0438\u0438 \u043D\u0435\u0442 \u0437\u0430\u043F\u0443\u0449\u0435\u043D\u043D\u043E\u0433\u043E \u043F\u0440\u043E\u0446\u0435\u0441\u0441\u0430";
|
|
2784
|
+
}
|
|
2347
2785
|
this.journal.clear();
|
|
2348
2786
|
this.#record({ kind: "rewound", toUserIndex: userIndex });
|
|
2787
|
+
if (rewindError) {
|
|
2788
|
+
this.#record({ kind: "error", message: `\u0424\u0430\u0439\u043B\u044B \u043D\u0435 \u043E\u0442\u043A\u0430\u0447\u0435\u043D\u044B: ${rewindError}` });
|
|
2789
|
+
}
|
|
2349
2790
|
this.#teardown("\u0440\u0435\u0434\u0430\u043A\u0442\u0438\u0440\u043E\u0432\u0430\u043D\u0438\u0435 \u0440\u0435\u043F\u043B\u0438\u043A\u0438");
|
|
2350
2791
|
this.#inbox = new AsyncQueue();
|
|
2351
2792
|
this.#streamMessageId = null;
|
|
2352
2793
|
this.#blockCounts.clear();
|
|
2353
2794
|
this.#spawn(true, anchor.resumeAt);
|
|
2354
|
-
this.sendPrompt(text, images);
|
|
2795
|
+
this.sendPrompt(text, images, false, attachments);
|
|
2796
|
+
}
|
|
2797
|
+
/**
|
|
2798
|
+
* Откатить файлы к чекпоинту реплики `userIndex` (см. `prompt.edit` о
|
|
2799
|
+
* нумерации). Разговор не меняется. Во время хода — отказ: агент мог бы
|
|
2800
|
+
* тут же переписать восстановленное.
|
|
2801
|
+
*/
|
|
2802
|
+
async rewindFiles(userIndex, dryRun) {
|
|
2803
|
+
if (this.#closing)
|
|
2804
|
+
throw new Error("session is closed");
|
|
2805
|
+
if (this.#state === "running") {
|
|
2806
|
+
return { canRewind: false, error: "\u0410\u0433\u0435\u043D\u0442 \u0435\u0449\u0451 \u043E\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u2014 \u0434\u043E\u0436\u0434\u0438\u0442\u0435\u0441\u044C \u043A\u043E\u043D\u0446\u0430 \u0445\u043E\u0434\u0430 \u0438\u043B\u0438 \u043E\u0441\u0442\u0430\u043D\u043E\u0432\u0438\u0442\u0435 \u0435\u0433\u043E." };
|
|
2807
|
+
}
|
|
2808
|
+
const q = this.#query;
|
|
2809
|
+
if (!q)
|
|
2810
|
+
return { canRewind: false, error: "\u0423 \u0441\u0435\u0441\u0441\u0438\u0438 \u043D\u0435\u0442 \u0437\u0430\u043F\u0443\u0449\u0435\u043D\u043D\u043E\u0433\u043E \u043F\u0440\u043E\u0446\u0435\u0441\u0441\u0430." };
|
|
2811
|
+
const source = this.#claudeSessionId ?? this.#options.resume;
|
|
2812
|
+
const anchor = source ? await locateResumePoint(source, this.cwd, userIndex, this.#options.configDir ?? null) : null;
|
|
2813
|
+
if (!anchor)
|
|
2814
|
+
return { canRewind: false, error: "\u0420\u0435\u043F\u043B\u0438\u043A\u0430 \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D\u0430 \u0432 \u0436\u0443\u0440\u043D\u0430\u043B\u0435 \u0441\u0435\u0441\u0441\u0438\u0438." };
|
|
2815
|
+
return q.rewindFiles(anchor.userUuid, { dryRun });
|
|
2355
2816
|
}
|
|
2356
2817
|
/**
|
|
2357
2818
|
* Стоит ли вообще переподключаться из-за этого кода ответа.
|
|
@@ -2369,7 +2830,8 @@ var ClaudeSession = class extends EventEmitter2 {
|
|
|
2369
2830
|
* вставке в терминал, а с текстом после — модели проще понять, к чему он
|
|
2370
2831
|
* относится, чем при обратном порядке.
|
|
2371
2832
|
*/
|
|
2372
|
-
#push(text, images) {
|
|
2833
|
+
#push(text, images, attachments) {
|
|
2834
|
+
const { blocks, note } = attachmentBlocks(attachments, this.id);
|
|
2373
2835
|
this.#inbox.push({
|
|
2374
2836
|
type: "user",
|
|
2375
2837
|
message: {
|
|
@@ -2379,7 +2841,10 @@ var ClaudeSession = class extends EventEmitter2 {
|
|
|
2379
2841
|
type: "image",
|
|
2380
2842
|
source: { type: "base64", media_type: image.mediaType, data: image.data }
|
|
2381
2843
|
})),
|
|
2382
|
-
|
|
2844
|
+
// Документы — между картинками и текстом, по той же причине: модели
|
|
2845
|
+
// проще понять вопрос, прочитав сначала то, о чём он.
|
|
2846
|
+
...blocks,
|
|
2847
|
+
{ type: "text", text: text + note }
|
|
2383
2848
|
]
|
|
2384
2849
|
},
|
|
2385
2850
|
parent_tool_use_id: null
|
|
@@ -2825,7 +3290,7 @@ var ClaudeSession = class extends EventEmitter2 {
|
|
|
2825
3290
|
const target = writeTarget(input.tool_input);
|
|
2826
3291
|
if (!target)
|
|
2827
3292
|
return pass;
|
|
2828
|
-
const absolute =
|
|
3293
|
+
const absolute = path9.resolve(this.cwd, target);
|
|
2829
3294
|
if (roots.some((root) => contains(root, absolute)))
|
|
2830
3295
|
return pass;
|
|
2831
3296
|
return {
|
|
@@ -2881,7 +3346,7 @@ var ClaudeSession = class extends EventEmitter2 {
|
|
|
2881
3346
|
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"
|
|
2882
3347
|
});
|
|
2883
3348
|
}
|
|
2884
|
-
const requestId =
|
|
3349
|
+
const requestId = randomUUID3();
|
|
2885
3350
|
const questions = toolName === ASK_QUESTION_TOOL ? parseQuestions(input) : null;
|
|
2886
3351
|
return new Promise((resolve) => {
|
|
2887
3352
|
this.#pendingPermissions.set(requestId, { resolve, toolName, input, questions });
|
|
@@ -3047,7 +3512,11 @@ var ClaudeSession = class extends EventEmitter2 {
|
|
|
3047
3512
|
const status = "api_error_status" in message ? message.api_error_status : void 0;
|
|
3048
3513
|
if (this.#retryable(status ?? void 0)) {
|
|
3049
3514
|
if (!this.#turnDidWork && this.#lastPrompt !== null) {
|
|
3050
|
-
this.#pendingRetry.push({
|
|
3515
|
+
this.#pendingRetry.push({
|
|
3516
|
+
text: this.#lastPrompt,
|
|
3517
|
+
images: this.#lastImages,
|
|
3518
|
+
attachments: this.#lastAttachments
|
|
3519
|
+
});
|
|
3051
3520
|
}
|
|
3052
3521
|
this.#scheduleReconnect(apiErrorReason(status ?? void 0));
|
|
3053
3522
|
break;
|
|
@@ -3453,32 +3922,32 @@ function contentToText2(content) {
|
|
|
3453
3922
|
// ../host/dist/antigravity-session.js
|
|
3454
3923
|
import { EventEmitter as EventEmitter3 } from "node:events";
|
|
3455
3924
|
import { spawn as spawn2, execFile as execFile3 } from "node:child_process";
|
|
3456
|
-
import { randomUUID as
|
|
3925
|
+
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
3457
3926
|
import { mkdir as mkdir3, writeFile as writeFile3 } from "node:fs/promises";
|
|
3458
|
-
import { tmpdir } from "node:os";
|
|
3459
|
-
import
|
|
3460
|
-
import { createInterface } from "node:readline";
|
|
3927
|
+
import { tmpdir as tmpdir2 } from "node:os";
|
|
3928
|
+
import path11 from "node:path";
|
|
3929
|
+
import { createInterface as createInterface2 } from "node:readline";
|
|
3461
3930
|
|
|
3462
3931
|
// ../host/dist/antigravity-cli.js
|
|
3463
3932
|
import { execFile as execFile2 } from "node:child_process";
|
|
3464
3933
|
import { existsSync } from "node:fs";
|
|
3465
3934
|
import { homedir as homedir4 } from "node:os";
|
|
3466
|
-
import
|
|
3935
|
+
import path10 from "node:path";
|
|
3467
3936
|
function agyExecutable() {
|
|
3468
3937
|
const forced = process.env.CCV_AGY_PATH;
|
|
3469
3938
|
if (forced && existsSync(forced))
|
|
3470
3939
|
return forced;
|
|
3471
3940
|
const names2 = process.platform === "win32" ? ["agy.exe", "agy"] : ["agy"];
|
|
3472
|
-
const dirs = (process.env.PATH ?? "").split(
|
|
3941
|
+
const dirs = (process.env.PATH ?? "").split(path10.delimiter).filter(Boolean);
|
|
3473
3942
|
if (process.platform === "win32") {
|
|
3474
|
-
const local = process.env.LOCALAPPDATA ??
|
|
3475
|
-
dirs.push(
|
|
3943
|
+
const local = process.env.LOCALAPPDATA ?? path10.join(homedir4(), "AppData", "Local");
|
|
3944
|
+
dirs.push(path10.join(local, "agy", "bin"));
|
|
3476
3945
|
} else {
|
|
3477
|
-
dirs.push(
|
|
3946
|
+
dirs.push(path10.join(homedir4(), ".local", "bin"), "/usr/local/bin", "/opt/homebrew/bin");
|
|
3478
3947
|
}
|
|
3479
3948
|
for (const dir of dirs) {
|
|
3480
3949
|
for (const name of names2) {
|
|
3481
|
-
const candidate =
|
|
3950
|
+
const candidate = path10.join(dir, name);
|
|
3482
3951
|
if (existsSync(candidate))
|
|
3483
3952
|
return candidate;
|
|
3484
3953
|
}
|
|
@@ -3714,7 +4183,7 @@ var AntigravitySession = class extends EventEmitter3 {
|
|
|
3714
4183
|
this.cwd = options2.cwd;
|
|
3715
4184
|
const now = Date.now();
|
|
3716
4185
|
this.#record = options2.record ? { ...options2.record } : {
|
|
3717
|
-
id:
|
|
4186
|
+
id: randomUUID4(),
|
|
3718
4187
|
conversationId: null,
|
|
3719
4188
|
workspaceId: options2.workspaceId,
|
|
3720
4189
|
cwd: options2.cwd,
|
|
@@ -3891,7 +4360,7 @@ var AntigravitySession = class extends EventEmitter3 {
|
|
|
3891
4360
|
this.#texts.clear();
|
|
3892
4361
|
this.#thinking.clear();
|
|
3893
4362
|
this.#tools.clear();
|
|
3894
|
-
const lines =
|
|
4363
|
+
const lines = createInterface2({ input: child.stdout });
|
|
3895
4364
|
lines.on("line", (line) => {
|
|
3896
4365
|
if (this.#child !== child)
|
|
3897
4366
|
return;
|
|
@@ -4007,18 +4476,19 @@ var AntigravitySession = class extends EventEmitter3 {
|
|
|
4007
4476
|
// -------------------------------------------------------------------------
|
|
4008
4477
|
// Ввод
|
|
4009
4478
|
// -------------------------------------------------------------------------
|
|
4010
|
-
sendPrompt(text, images) {
|
|
4479
|
+
sendPrompt(text, images, _service = false, attachments) {
|
|
4011
4480
|
if (this.#closing)
|
|
4012
4481
|
throw new Error("session is closed");
|
|
4013
4482
|
const blocked = networkGuard.blockedReason();
|
|
4014
4483
|
if (blocked)
|
|
4015
4484
|
throw new Error(`${blocked}. \u041F\u0440\u043E\u043C\u043F\u0442 \u043D\u0435 \u043E\u0442\u043F\u0440\u0430\u0432\u043B\u0435\u043D.`);
|
|
4016
4485
|
const command = /^\/([\w-]+)(?:\s+([\s\S]*))?$/.exec(text.trim());
|
|
4017
|
-
if (command && AGY_CLI_COMMANDS.has(command[1]) && (!images || images.length === 0)) {
|
|
4486
|
+
if (command && AGY_CLI_COMMANDS.has(command[1]) && (!images || images.length === 0) && (!attachments || attachments.length === 0)) {
|
|
4018
4487
|
void this.#runCliCommand(text, command[1], command[2]?.trim() ?? "");
|
|
4019
4488
|
return;
|
|
4020
4489
|
}
|
|
4021
|
-
|
|
4490
|
+
checkAttachments(images, attachments);
|
|
4491
|
+
this.#record_({ kind: "user.message", text, images, files: attachmentMeta(attachments) });
|
|
4022
4492
|
if (!this.#record.title || this.#titleIsDefault) {
|
|
4023
4493
|
this.#record.title = text.slice(0, 80);
|
|
4024
4494
|
this.#titleIsDefault = false;
|
|
@@ -4031,7 +4501,7 @@ var AntigravitySession = class extends EventEmitter3 {
|
|
|
4031
4501
|
this.#pendingTurns += 1;
|
|
4032
4502
|
this.#setState("running");
|
|
4033
4503
|
const child = this.#child;
|
|
4034
|
-
void this.#composePrompt(text, images).then((prompt) => {
|
|
4504
|
+
void this.#composePrompt(text, images, attachments).then((prompt) => {
|
|
4035
4505
|
if (this.#child !== child)
|
|
4036
4506
|
return;
|
|
4037
4507
|
const line = JSON.stringify({
|
|
@@ -4089,7 +4559,7 @@ var AntigravitySession = class extends EventEmitter3 {
|
|
|
4089
4559
|
if (this.#closing)
|
|
4090
4560
|
return;
|
|
4091
4561
|
if (reply)
|
|
4092
|
-
this.#record_({ kind: "assistant.text", text: reply, blockId: `cmd:${
|
|
4562
|
+
this.#record_({ kind: "assistant.text", text: reply, blockId: `cmd:${randomUUID4()}` });
|
|
4093
4563
|
if (error)
|
|
4094
4564
|
this.#record_({ kind: "error", message: error });
|
|
4095
4565
|
if (turnRunning || this.#pendingTurns > 0)
|
|
@@ -4142,22 +4612,23 @@ var AntigravitySession = class extends EventEmitter3 {
|
|
|
4142
4612
|
return { reply: `\u0423\u0441\u0438\u043B\u0438\u0435: **${level}**`, error: null };
|
|
4143
4613
|
}
|
|
4144
4614
|
/** Картинки — файлами во временном каталоге, а в текст — их пути. */
|
|
4145
|
-
async #composePrompt(text, images) {
|
|
4615
|
+
async #composePrompt(text, images, attachments) {
|
|
4616
|
+
const note = attachmentNote((attachments ?? []).map((a) => saveAttachment(a, this.id)));
|
|
4146
4617
|
if (!images || images.length === 0)
|
|
4147
|
-
return text;
|
|
4148
|
-
const dir =
|
|
4618
|
+
return text + note;
|
|
4619
|
+
const dir = path11.join(tmpdir2(), "ccv-antigravity", this.id);
|
|
4149
4620
|
await mkdir3(dir, { recursive: true });
|
|
4150
4621
|
const paths = [];
|
|
4151
4622
|
for (const image of images) {
|
|
4152
4623
|
const ext = image.mediaType.split("/")[1] === "jpeg" ? "jpg" : image.mediaType.split("/")[1];
|
|
4153
|
-
const file =
|
|
4624
|
+
const file = path11.join(dir, `${randomUUID4()}.${ext}`);
|
|
4154
4625
|
await writeFile3(file, Buffer.from(image.data, "base64"));
|
|
4155
4626
|
paths.push(file);
|
|
4156
4627
|
}
|
|
4157
4628
|
return `${text}
|
|
4158
4629
|
|
|
4159
4630
|
Attached image${paths.length > 1 ? "s" : ""} (view them with your file viewing tool):
|
|
4160
|
-
` + paths.map((p) => `- ${p}`).join("\n");
|
|
4631
|
+
` + paths.map((p) => `- ${p}`).join("\n") + note;
|
|
4161
4632
|
}
|
|
4162
4633
|
async editPrompt(_userIndex, _text, _images) {
|
|
4163
4634
|
throw new Error("\u0412 \u0441\u0435\u0441\u0441\u0438\u0438 Antigravity \u043F\u0440\u0430\u0432\u043A\u0430 \u043F\u0440\u043E\u0448\u043B\u044B\u0445 \u0440\u0435\u043F\u043B\u0438\u043A \u043D\u0435 \u043F\u043E\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044F");
|
|
@@ -4539,16 +5010,20 @@ function describe2(error) {
|
|
|
4539
5010
|
|
|
4540
5011
|
// ../host/dist/antigravity-store.js
|
|
4541
5012
|
import { appendFile, mkdir as mkdir4, readFile as readFile5, rm as rm2, writeFile as writeFile4 } from "node:fs/promises";
|
|
4542
|
-
import
|
|
5013
|
+
import path12 from "node:path";
|
|
4543
5014
|
var AntigravityStore = class {
|
|
4544
5015
|
#dir;
|
|
4545
5016
|
#file;
|
|
4546
5017
|
#records = /* @__PURE__ */ new Map();
|
|
4547
5018
|
#loaded = null;
|
|
4548
5019
|
#writing = Promise.resolve();
|
|
4549
|
-
|
|
4550
|
-
|
|
4551
|
-
|
|
5020
|
+
/**
|
|
5021
|
+
* `subdir` — чей реестр: тот же формат ведут и сессии Codex (`codex`),
|
|
5022
|
+
* у которых в `conversationId` лежит id треда `codex app-server`.
|
|
5023
|
+
*/
|
|
5024
|
+
constructor(dataDir, subdir = "antigravity") {
|
|
5025
|
+
this.#dir = path12.join(dataDir, subdir);
|
|
5026
|
+
this.#file = path12.join(this.#dir, "sessions.json");
|
|
4552
5027
|
}
|
|
4553
5028
|
#load() {
|
|
4554
5029
|
this.#loaded ??= (async () => {
|
|
@@ -4645,7 +5120,7 @@ var AntigravityStore = class {
|
|
|
4645
5120
|
return entries;
|
|
4646
5121
|
}
|
|
4647
5122
|
#eventsFile(id) {
|
|
4648
|
-
return
|
|
5123
|
+
return path12.join(this.#dir, `${id.replace(/[^\w-]/g, "_")}.jsonl`);
|
|
4649
5124
|
}
|
|
4650
5125
|
#persist() {
|
|
4651
5126
|
const snapshot = JSON.stringify([...this.#records.values()], null, 2);
|
|
@@ -4664,66 +5139,1390 @@ var AntigravityStore = class {
|
|
|
4664
5139
|
}
|
|
4665
5140
|
};
|
|
4666
5141
|
|
|
4667
|
-
// ../host/dist/
|
|
4668
|
-
import {
|
|
4669
|
-
import {
|
|
4670
|
-
import {
|
|
4671
|
-
import
|
|
4672
|
-
|
|
4673
|
-
|
|
4674
|
-
|
|
4675
|
-
|
|
4676
|
-
|
|
4677
|
-
|
|
4678
|
-
|
|
4679
|
-
|
|
4680
|
-
|
|
4681
|
-
|
|
4682
|
-
|
|
4683
|
-
|
|
4684
|
-
|
|
4685
|
-
|
|
4686
|
-
|
|
4687
|
-
|
|
5142
|
+
// ../host/dist/codex-session.js
|
|
5143
|
+
import { EventEmitter as EventEmitter5 } from "node:events";
|
|
5144
|
+
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
5145
|
+
import { mkdir as mkdir5, writeFile as writeFile5 } from "node:fs/promises";
|
|
5146
|
+
import { tmpdir as tmpdir3 } from "node:os";
|
|
5147
|
+
import path14 from "node:path";
|
|
5148
|
+
|
|
5149
|
+
// ../host/dist/codex-cli.js
|
|
5150
|
+
import { EventEmitter as EventEmitter4 } from "node:events";
|
|
5151
|
+
import { spawn as spawn3, execFile as execFile4 } from "node:child_process";
|
|
5152
|
+
import { existsSync as existsSync2, readdirSync } from "node:fs";
|
|
5153
|
+
import { homedir as homedir5 } from "node:os";
|
|
5154
|
+
import path13 from "node:path";
|
|
5155
|
+
import { createInterface as createInterface3 } from "node:readline";
|
|
5156
|
+
function codexExecutable() {
|
|
5157
|
+
const forced = process.env.CCV_CODEX_PATH;
|
|
5158
|
+
if (forced && existsSync2(forced))
|
|
5159
|
+
return forced;
|
|
5160
|
+
const win = process.platform === "win32";
|
|
5161
|
+
const dirs = (process.env.PATH ?? "").split(path13.delimiter).filter(Boolean);
|
|
5162
|
+
if (win) {
|
|
5163
|
+
const local = process.env.LOCALAPPDATA ?? path13.join(homedir5(), "AppData", "Local");
|
|
5164
|
+
dirs.push(path13.join(local, "Programs", "OpenAI", "Codex", "bin"));
|
|
5165
|
+
} else {
|
|
5166
|
+
dirs.push(path13.join(homedir5(), ".local", "bin"), "/usr/local/bin", "/opt/homebrew/bin");
|
|
4688
5167
|
}
|
|
4689
|
-
|
|
4690
|
-
|
|
4691
|
-
|
|
4692
|
-
|
|
4693
|
-
|
|
4694
|
-
|
|
4695
|
-
|
|
4696
|
-
|
|
4697
|
-
const
|
|
4698
|
-
|
|
4699
|
-
|
|
4700
|
-
|
|
4701
|
-
|
|
4702
|
-
|
|
4703
|
-
|
|
4704
|
-
|
|
4705
|
-
|
|
4706
|
-
|
|
4707
|
-
|
|
4708
|
-
|
|
4709
|
-
|
|
4710
|
-
|
|
4711
|
-
|
|
4712
|
-
|
|
5168
|
+
const name = win ? "codex.exe" : "codex";
|
|
5169
|
+
for (const dir of dirs) {
|
|
5170
|
+
const candidate = path13.join(dir, name);
|
|
5171
|
+
if (existsSync2(candidate))
|
|
5172
|
+
return candidate;
|
|
5173
|
+
}
|
|
5174
|
+
if (win) {
|
|
5175
|
+
const roaming = process.env.APPDATA ?? path13.join(homedir5(), "AppData", "Roaming");
|
|
5176
|
+
const vendor = npmVendorExe(path13.join(roaming, "npm", "node_modules", "@openai", "codex"));
|
|
5177
|
+
if (vendor)
|
|
5178
|
+
return vendor;
|
|
5179
|
+
}
|
|
5180
|
+
return null;
|
|
5181
|
+
}
|
|
5182
|
+
function npmVendorExe(pkg) {
|
|
5183
|
+
const scope = path13.join(pkg, "node_modules", "@openai");
|
|
5184
|
+
let subpackages;
|
|
5185
|
+
try {
|
|
5186
|
+
subpackages = readdirSync(scope).filter((d) => d.startsWith("codex-win32"));
|
|
5187
|
+
} catch {
|
|
5188
|
+
return null;
|
|
5189
|
+
}
|
|
5190
|
+
for (const sub of subpackages) {
|
|
5191
|
+
const vendor = path13.join(scope, sub, "vendor");
|
|
5192
|
+
let triples;
|
|
4713
5193
|
try {
|
|
4714
|
-
|
|
4715
|
-
} catch
|
|
4716
|
-
|
|
4717
|
-
return { ...blank, message: describe3(error), noRepo: runnable2 };
|
|
5194
|
+
triples = readdirSync(vendor);
|
|
5195
|
+
} catch {
|
|
5196
|
+
continue;
|
|
4718
5197
|
}
|
|
4719
|
-
const
|
|
4720
|
-
|
|
4721
|
-
|
|
4722
|
-
|
|
4723
|
-
|
|
4724
|
-
|
|
4725
|
-
|
|
4726
|
-
|
|
5198
|
+
for (const triple of triples) {
|
|
5199
|
+
const exe = path13.join(vendor, triple, "bin", "codex.exe");
|
|
5200
|
+
if (existsSync2(exe))
|
|
5201
|
+
return exe;
|
|
5202
|
+
}
|
|
5203
|
+
}
|
|
5204
|
+
return null;
|
|
5205
|
+
}
|
|
5206
|
+
var CODEX_MISSING_HINT = "Codex CLI \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D. \u0423\u0441\u0442\u0430\u043D\u043E\u0432\u0438\u0442\u0435 \u0435\u0433\u043E (`npm install -g @openai/codex` \u0438\u043B\u0438 \u043F\u0440\u0438\u043B\u043E\u0436\u0435\u043D\u0438\u0435 Codex) \u0438 \u0432\u043E\u0439\u0434\u0438\u0442\u0435, \u0437\u0430\u043F\u0443\u0441\u0442\u0438\u0432 `codex login` \u0432 \u0442\u0435\u0440\u043C\u0438\u043D\u0430\u043B\u0435, \u2014 \u0438\u043B\u0438 \u0443\u043A\u0430\u0436\u0438\u0442\u0435 \u043F\u0443\u0442\u044C \u0432 \u043F\u0435\u0440\u0435\u043C\u0435\u043D\u043D\u043E\u0439 CCV_CODEX_PATH.";
|
|
5207
|
+
var CODEX_LOGIN_HINT = "Codex \u043D\u0435 \u0432\u043E\u0448\u0451\u043B \u0432 \u0430\u043A\u043A\u0430\u0443\u043D\u0442. \u0417\u0430\u043F\u0443\u0441\u0442\u0438\u0442\u0435 \u0432 \u0442\u0435\u0440\u043C\u0438\u043D\u0430\u043B\u0435 `codex login`, \u0437\u0430\u0442\u0435\u043C \u043E\u0442\u043F\u0440\u0430\u0432\u044C\u0442\u0435 \u043F\u0440\u043E\u043C\u043F\u0442 \u0441\u043D\u043E\u0432\u0430.";
|
|
5208
|
+
var CodexRpcError = class extends Error {
|
|
5209
|
+
code;
|
|
5210
|
+
constructor(error) {
|
|
5211
|
+
super(error.message);
|
|
5212
|
+
this.code = error.code;
|
|
5213
|
+
}
|
|
5214
|
+
};
|
|
5215
|
+
var CodexRpc = class extends EventEmitter4 {
|
|
5216
|
+
#child;
|
|
5217
|
+
#nextId = 1;
|
|
5218
|
+
#pending = /* @__PURE__ */ new Map();
|
|
5219
|
+
#exited = false;
|
|
5220
|
+
stderrTail = "";
|
|
5221
|
+
constructor(executable, cwd) {
|
|
5222
|
+
super();
|
|
5223
|
+
this.#child = spawn3(executable, ["app-server"], {
|
|
5224
|
+
cwd,
|
|
5225
|
+
windowsHide: true,
|
|
5226
|
+
env: { ...process.env, NO_COLOR: "1", RUST_LOG: process.env.RUST_LOG ?? "error" }
|
|
5227
|
+
});
|
|
5228
|
+
const lines = createInterface3({ input: this.#child.stdout });
|
|
5229
|
+
lines.on("line", (line) => this.#onLine(line));
|
|
5230
|
+
this.#child.stderr.setEncoding("utf8");
|
|
5231
|
+
this.#child.stderr.on("data", (data) => {
|
|
5232
|
+
this.stderrTail = (this.stderrTail + data).slice(-4e3);
|
|
5233
|
+
this.emit("stderr", data);
|
|
5234
|
+
});
|
|
5235
|
+
this.#child.stdin.on("error", () => void 0);
|
|
5236
|
+
this.#child.on("error", (error) => this.#onExit(null, error));
|
|
5237
|
+
this.#child.on("exit", (code) => this.#onExit(code));
|
|
5238
|
+
}
|
|
5239
|
+
get alive() {
|
|
5240
|
+
return !this.#exited;
|
|
5241
|
+
}
|
|
5242
|
+
request(method, params) {
|
|
5243
|
+
if (this.#exited)
|
|
5244
|
+
return Promise.reject(new Error("codex app-server \u043D\u0435 \u0437\u0430\u043F\u0443\u0449\u0435\u043D"));
|
|
5245
|
+
const id = this.#nextId++;
|
|
5246
|
+
return new Promise((resolve, reject) => {
|
|
5247
|
+
this.#pending.set(id, { resolve, reject });
|
|
5248
|
+
this.#write({ id, method, params });
|
|
5249
|
+
});
|
|
5250
|
+
}
|
|
5251
|
+
notify(method, params) {
|
|
5252
|
+
this.#write(params === void 0 ? { method } : { method, params });
|
|
5253
|
+
}
|
|
5254
|
+
respond(id, result) {
|
|
5255
|
+
this.#write({ id, result });
|
|
5256
|
+
}
|
|
5257
|
+
respondError(id, message) {
|
|
5258
|
+
this.#write({ id, error: { code: -32e3, message } });
|
|
5259
|
+
}
|
|
5260
|
+
/** Инициализация: без неё сервер других запросов не принимает. */
|
|
5261
|
+
async initialize(version2) {
|
|
5262
|
+
await this.request("initialize", {
|
|
5263
|
+
clientInfo: { name: "ccv", title: "Claude Code Visual", version: version2 },
|
|
5264
|
+
capabilities: null
|
|
5265
|
+
});
|
|
5266
|
+
this.notify("initialized");
|
|
5267
|
+
}
|
|
5268
|
+
kill() {
|
|
5269
|
+
if (this.#exited)
|
|
5270
|
+
return;
|
|
5271
|
+
const child = this.#child;
|
|
5272
|
+
try {
|
|
5273
|
+
child.stdin.end();
|
|
5274
|
+
} catch {
|
|
5275
|
+
}
|
|
5276
|
+
if (process.platform === "win32" && child.pid) {
|
|
5277
|
+
execFile4("taskkill", ["/pid", String(child.pid), "/T", "/F"], { windowsHide: true }, () => {
|
|
5278
|
+
if (child.exitCode === null)
|
|
5279
|
+
child.kill();
|
|
5280
|
+
});
|
|
5281
|
+
} else {
|
|
5282
|
+
child.kill("SIGTERM");
|
|
5283
|
+
}
|
|
5284
|
+
}
|
|
5285
|
+
#write(message) {
|
|
5286
|
+
if (this.#exited)
|
|
5287
|
+
return;
|
|
5288
|
+
this.#child.stdin.write(JSON.stringify(message) + "\n");
|
|
5289
|
+
}
|
|
5290
|
+
#onLine(line) {
|
|
5291
|
+
const trimmed = line.trim();
|
|
5292
|
+
if (!trimmed.startsWith("{"))
|
|
5293
|
+
return;
|
|
5294
|
+
let message;
|
|
5295
|
+
try {
|
|
5296
|
+
message = JSON.parse(trimmed);
|
|
5297
|
+
} catch {
|
|
5298
|
+
return;
|
|
5299
|
+
}
|
|
5300
|
+
if (message.method) {
|
|
5301
|
+
if (message.id !== void 0 && message.id !== null) {
|
|
5302
|
+
this.emit("request", message.id, message.method, message.params);
|
|
5303
|
+
} else {
|
|
5304
|
+
this.emit("notification", message.method, message.params);
|
|
5305
|
+
}
|
|
5306
|
+
return;
|
|
5307
|
+
}
|
|
5308
|
+
if (typeof message.id !== "number")
|
|
5309
|
+
return;
|
|
5310
|
+
const pending = this.#pending.get(message.id);
|
|
5311
|
+
if (!pending)
|
|
5312
|
+
return;
|
|
5313
|
+
this.#pending.delete(message.id);
|
|
5314
|
+
if (message.error)
|
|
5315
|
+
pending.reject(new CodexRpcError(message.error));
|
|
5316
|
+
else
|
|
5317
|
+
pending.resolve(message.result);
|
|
5318
|
+
}
|
|
5319
|
+
#onExit(code, error) {
|
|
5320
|
+
if (this.#exited)
|
|
5321
|
+
return;
|
|
5322
|
+
this.#exited = true;
|
|
5323
|
+
const reason = error ?? new Error(`codex app-server \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043B\u0441\u044F (\u043A\u043E\u0434 ${code ?? "\u2014"})`);
|
|
5324
|
+
for (const pending of this.#pending.values())
|
|
5325
|
+
pending.reject(reason);
|
|
5326
|
+
this.#pending.clear();
|
|
5327
|
+
this.emit("exit", code, error);
|
|
5328
|
+
}
|
|
5329
|
+
};
|
|
5330
|
+
var CCV_EFFORTS = ["low", "medium", "high", "xhigh", "max"];
|
|
5331
|
+
function codexModelOptions(models) {
|
|
5332
|
+
return models.filter((m) => !m.hidden).map((m) => {
|
|
5333
|
+
const levels = m.supportedReasoningEfforts.map((e) => e.reasoningEffort).filter((e) => CCV_EFFORTS.includes(e));
|
|
5334
|
+
return {
|
|
5335
|
+
value: m.id,
|
|
5336
|
+
resolvedModel: m.model,
|
|
5337
|
+
displayName: m.displayName,
|
|
5338
|
+
description: m.description,
|
|
5339
|
+
supportsEffort: levels.length > 0,
|
|
5340
|
+
effortLevels: levels,
|
|
5341
|
+
supportsThinking: false,
|
|
5342
|
+
supportsAutoMode: false
|
|
5343
|
+
};
|
|
5344
|
+
});
|
|
5345
|
+
}
|
|
5346
|
+
function windowLabel(mins) {
|
|
5347
|
+
if (mins === null)
|
|
5348
|
+
return { label: "\u041B\u0438\u043C\u0438\u0442", period: "" };
|
|
5349
|
+
if (mins === 10080)
|
|
5350
|
+
return { label: "\u041D\u0435\u0434\u0435\u043B\u044F", period: "weekly" };
|
|
5351
|
+
if (mins === 1440)
|
|
5352
|
+
return { label: "\u0414\u0435\u043D\u044C", period: "daily" };
|
|
5353
|
+
if (mins % 60 === 0)
|
|
5354
|
+
return { label: `${mins / 60} \u0447`, period: `${mins / 60}h` };
|
|
5355
|
+
return { label: `${mins} \u043C\u0438\u043D`, period: `${mins}m` };
|
|
5356
|
+
}
|
|
5357
|
+
function codexUsage(snapshot) {
|
|
5358
|
+
if (!snapshot)
|
|
5359
|
+
return null;
|
|
5360
|
+
const buckets = [];
|
|
5361
|
+
for (const [key, window] of [["primary", snapshot.primary], ["secondary", snapshot.secondary]]) {
|
|
5362
|
+
if (!window)
|
|
5363
|
+
continue;
|
|
5364
|
+
const { label, period } = windowLabel(window.windowDurationMins);
|
|
5365
|
+
buckets.push({
|
|
5366
|
+
id: `codex:${key}`,
|
|
5367
|
+
label,
|
|
5368
|
+
title: `Codex \u2014 ${label.toLowerCase()}`,
|
|
5369
|
+
description: snapshot.limitName ?? "",
|
|
5370
|
+
period,
|
|
5371
|
+
window: {
|
|
5372
|
+
utilization: Math.max(0, Math.min(100, window.usedPercent)),
|
|
5373
|
+
resetsAt: window.resetsAt ? new Date(window.resetsAt * 1e3).toISOString() : ""
|
|
5374
|
+
}
|
|
5375
|
+
});
|
|
5376
|
+
}
|
|
5377
|
+
return {
|
|
5378
|
+
available: buckets.length > 0,
|
|
5379
|
+
plan: snapshot.planType ?? "",
|
|
5380
|
+
fiveHour: null,
|
|
5381
|
+
sevenDay: null,
|
|
5382
|
+
sevenDayOpus: null,
|
|
5383
|
+
buckets,
|
|
5384
|
+
fetchedAt: Date.now()
|
|
5385
|
+
};
|
|
5386
|
+
}
|
|
5387
|
+
|
|
5388
|
+
// ../host/dist/codex-session.js
|
|
5389
|
+
var LOCAL_COMMANDS = [
|
|
5390
|
+
{ name: "model", description: "\u041F\u043E\u043A\u0430\u0437\u0430\u0442\u044C \u0438\u043B\u0438 \u0441\u043C\u0435\u043D\u0438\u0442\u044C \u043C\u043E\u0434\u0435\u043B\u044C Codex", argumentHint: "[\u043C\u043E\u0434\u0435\u043B\u044C]", aliases: [] },
|
|
5391
|
+
{ name: "effort", description: "\u041F\u043E\u043A\u0430\u0437\u0430\u0442\u044C \u0438\u043B\u0438 \u0441\u043C\u0435\u043D\u0438\u0442\u044C \u0443\u0441\u0438\u043B\u0438\u0435 \u0440\u0430\u0437\u043C\u044B\u0448\u043B\u0435\u043D\u0438\u0439", argumentHint: "[low|medium|high|xhigh|max]", aliases: [] },
|
|
5392
|
+
{ name: "compact", description: "\u0421\u0436\u0430\u0442\u044C \u043A\u043E\u043D\u0442\u0435\u043A\u0441\u0442 \u0442\u0440\u0435\u0434\u0430", argumentHint: "", aliases: [] },
|
|
5393
|
+
{ name: "status", description: "\u041C\u043E\u0434\u0435\u043B\u044C, \u0443\u0441\u0438\u043B\u0438\u0435 \u0438 \u043B\u0438\u043C\u0438\u0442\u044B Codex", argumentHint: "", aliases: ["usage", "limits"] }
|
|
5394
|
+
];
|
|
5395
|
+
var LOCAL_NAMES = new Set(LOCAL_COMMANDS.flatMap((c) => [c.name, ...c.aliases]));
|
|
5396
|
+
var TRANSIENT2 = /* @__PURE__ */ new Set(["assistant.delta", "thinking.delta", "state"]);
|
|
5397
|
+
var CodexSession = class extends EventEmitter5 {
|
|
5398
|
+
id;
|
|
5399
|
+
workspaceId;
|
|
5400
|
+
cwd;
|
|
5401
|
+
journal = new Journal();
|
|
5402
|
+
provider = "codex";
|
|
5403
|
+
#store;
|
|
5404
|
+
#version;
|
|
5405
|
+
#record;
|
|
5406
|
+
#history = Promise.resolve([]);
|
|
5407
|
+
#executable = null;
|
|
5408
|
+
#rpc = null;
|
|
5409
|
+
/** Процесс поднят, инициализирован и тред открыт. */
|
|
5410
|
+
#ready = null;
|
|
5411
|
+
#state = "starting";
|
|
5412
|
+
#lastTurn = null;
|
|
5413
|
+
#capabilities = null;
|
|
5414
|
+
#titleIsDefault = false;
|
|
5415
|
+
#closing = false;
|
|
5416
|
+
/** Песочница, с которой открыт тред: иначе — переопределение в `turn/start`. */
|
|
5417
|
+
#threadSandbox = null;
|
|
5418
|
+
#turnId = null;
|
|
5419
|
+
#turnStartedAt = 0;
|
|
5420
|
+
/** Ход отправлен, но `turn/started` ещё не пришёл. */
|
|
5421
|
+
#turnStarting = false;
|
|
5422
|
+
#texts = /* @__PURE__ */ new Map();
|
|
5423
|
+
#reasoning = /* @__PURE__ */ new Map();
|
|
5424
|
+
#openTools = /* @__PURE__ */ new Set();
|
|
5425
|
+
#items = /* @__PURE__ */ new Map();
|
|
5426
|
+
#approvals = /* @__PURE__ */ new Map();
|
|
5427
|
+
#models = [];
|
|
5428
|
+
#skills = [];
|
|
5429
|
+
#usage = null;
|
|
5430
|
+
#context = null;
|
|
5431
|
+
#contextTokens = null;
|
|
5432
|
+
#contextWindow = null;
|
|
5433
|
+
#totalAtTurnStart = null;
|
|
5434
|
+
#lastTotal = null;
|
|
5435
|
+
#unsaved = [];
|
|
5436
|
+
#flushTimer = null;
|
|
5437
|
+
#updatedAt = Date.now();
|
|
5438
|
+
constructor(options2) {
|
|
5439
|
+
super();
|
|
5440
|
+
this.#store = options2.store;
|
|
5441
|
+
this.#version = options2.version ?? "0";
|
|
5442
|
+
this.workspaceId = options2.workspaceId;
|
|
5443
|
+
this.cwd = options2.cwd;
|
|
5444
|
+
const now = Date.now();
|
|
5445
|
+
this.#record = options2.record ? { ...options2.record } : {
|
|
5446
|
+
id: randomUUID5(),
|
|
5447
|
+
conversationId: null,
|
|
5448
|
+
workspaceId: options2.workspaceId,
|
|
5449
|
+
cwd: options2.cwd,
|
|
5450
|
+
title: options2.defaultTitle ?? null,
|
|
5451
|
+
model: options2.model ?? null,
|
|
5452
|
+
permissionMode: options2.permissionMode ?? "default",
|
|
5453
|
+
effort: null,
|
|
5454
|
+
createdAt: now,
|
|
5455
|
+
updatedAt: now
|
|
5456
|
+
};
|
|
5457
|
+
if (!options2.record)
|
|
5458
|
+
this.#titleIsDefault = options2.defaultTitle !== void 0;
|
|
5459
|
+
if (options2.record && options2.permissionMode)
|
|
5460
|
+
this.#record.permissionMode = options2.permissionMode;
|
|
5461
|
+
this.id = this.#record.id;
|
|
5462
|
+
this.#updatedAt = this.#record.updatedAt;
|
|
5463
|
+
}
|
|
5464
|
+
// -------------------------------------------------------------------------
|
|
5465
|
+
// Публичное состояние — та же форма, что у ClaudeSession
|
|
5466
|
+
// -------------------------------------------------------------------------
|
|
5467
|
+
get state() {
|
|
5468
|
+
return this.#state;
|
|
5469
|
+
}
|
|
5470
|
+
get capabilities() {
|
|
5471
|
+
return this.#capabilities;
|
|
5472
|
+
}
|
|
5473
|
+
/** Постоянный id сессии: под ним она в архиве, закреплённых и папках. */
|
|
5474
|
+
get claudeSessionId() {
|
|
5475
|
+
return this.id;
|
|
5476
|
+
}
|
|
5477
|
+
get parentSessionId() {
|
|
5478
|
+
return null;
|
|
5479
|
+
}
|
|
5480
|
+
get usage() {
|
|
5481
|
+
return this.#usage;
|
|
5482
|
+
}
|
|
5483
|
+
get context() {
|
|
5484
|
+
return this.#context;
|
|
5485
|
+
}
|
|
5486
|
+
history() {
|
|
5487
|
+
return this.#history;
|
|
5488
|
+
}
|
|
5489
|
+
summary() {
|
|
5490
|
+
return {
|
|
5491
|
+
id: this.id,
|
|
5492
|
+
provider: "codex",
|
|
5493
|
+
claudeSessionId: this.id,
|
|
5494
|
+
workspaceId: this.workspaceId,
|
|
5495
|
+
cwd: this.cwd,
|
|
5496
|
+
parentSessionId: null,
|
|
5497
|
+
title: this.#record.title,
|
|
5498
|
+
state: this.#state,
|
|
5499
|
+
lastTurn: this.#lastTurn,
|
|
5500
|
+
backgroundWork: false,
|
|
5501
|
+
tasks: [],
|
|
5502
|
+
model: this.#record.model ?? this.#defaultModel()?.id ?? null,
|
|
5503
|
+
permissionMode: this.#record.permissionMode,
|
|
5504
|
+
effort: this.#record.effort,
|
|
5505
|
+
ultracode: false,
|
|
5506
|
+
thinking: true,
|
|
5507
|
+
switchModelsOnFlag: true,
|
|
5508
|
+
createdAt: this.#record.createdAt,
|
|
5509
|
+
updatedAt: this.#updatedAt,
|
|
5510
|
+
lastSeq: this.journal.lastSeq,
|
|
5511
|
+
totalCostUsd: 0,
|
|
5512
|
+
accountId: MAIN_ACCOUNT_ID
|
|
5513
|
+
};
|
|
5514
|
+
}
|
|
5515
|
+
// -------------------------------------------------------------------------
|
|
5516
|
+
// Жизненный цикл
|
|
5517
|
+
// -------------------------------------------------------------------------
|
|
5518
|
+
start() {
|
|
5519
|
+
if (this.#record.conversationId) {
|
|
5520
|
+
this.#history = this.#store.readEvents(this.id);
|
|
5521
|
+
void this.#history.then((entries) => {
|
|
5522
|
+
if (this.#contextTokens !== null)
|
|
5523
|
+
return;
|
|
5524
|
+
for (let i = entries.length - 1; i >= 0; i -= 1) {
|
|
5525
|
+
const event = entries[i].event;
|
|
5526
|
+
if (event.kind === "result" && event.contextTokens !== null) {
|
|
5527
|
+
this.#contextTokens = event.contextTokens;
|
|
5528
|
+
this.#emitContext();
|
|
5529
|
+
return;
|
|
5530
|
+
}
|
|
5531
|
+
}
|
|
5532
|
+
});
|
|
5533
|
+
}
|
|
5534
|
+
void this.#store.save(this.#record);
|
|
5535
|
+
this.#executable = codexExecutable();
|
|
5536
|
+
if (!this.#executable) {
|
|
5537
|
+
this.#record_({ kind: "error", message: CODEX_MISSING_HINT });
|
|
5538
|
+
this.#setState("error");
|
|
5539
|
+
return;
|
|
5540
|
+
}
|
|
5541
|
+
this.#capabilities = this.#baseCapabilities();
|
|
5542
|
+
this.emit("capabilities");
|
|
5543
|
+
if (this.#refuseOffRoute())
|
|
5544
|
+
return;
|
|
5545
|
+
void this.#ensure().then(() => {
|
|
5546
|
+
if (this.#state === "starting")
|
|
5547
|
+
this.#setState("idle");
|
|
5548
|
+
}, () => void 0);
|
|
5549
|
+
}
|
|
5550
|
+
#baseCapabilities() {
|
|
5551
|
+
const skills = this.#skills.filter((s) => s.enabled && !LOCAL_NAMES.has(s.name)).map((s) => ({
|
|
5552
|
+
name: s.name,
|
|
5553
|
+
description: s.shortDescription || s.description,
|
|
5554
|
+
argumentHint: "",
|
|
5555
|
+
aliases: []
|
|
5556
|
+
}));
|
|
5557
|
+
const commands = [...LOCAL_COMMANDS, ...skills];
|
|
5558
|
+
return {
|
|
5559
|
+
cwd: this.cwd,
|
|
5560
|
+
model: this.#record.model ?? this.#defaultModel()?.id ?? "",
|
|
5561
|
+
permissionMode: this.#record.permissionMode,
|
|
5562
|
+
slashCommands: commands.map((c) => c.name),
|
|
5563
|
+
commands,
|
|
5564
|
+
models: codexModelOptions(this.#models),
|
|
5565
|
+
tools: this.#capabilities?.tools ?? [],
|
|
5566
|
+
agents: [],
|
|
5567
|
+
mcpServers: [],
|
|
5568
|
+
flags: []
|
|
5569
|
+
};
|
|
5570
|
+
}
|
|
5571
|
+
#defaultModel() {
|
|
5572
|
+
return this.#models.find((m) => m.isDefault);
|
|
5573
|
+
}
|
|
5574
|
+
/** Режим прав ccv → политика разрешений и песочница Codex. */
|
|
5575
|
+
#policy() {
|
|
5576
|
+
switch (this.#record.permissionMode) {
|
|
5577
|
+
case "plan":
|
|
5578
|
+
return { approvalPolicy: "on-request", sandbox: "read-only" };
|
|
5579
|
+
case "bypassPermissions":
|
|
5580
|
+
return { approvalPolicy: "never", sandbox: "danger-full-access" };
|
|
5581
|
+
case "dontAsk":
|
|
5582
|
+
return { approvalPolicy: "never", sandbox: "workspace-write" };
|
|
5583
|
+
default:
|
|
5584
|
+
return { approvalPolicy: "untrusted", sandbox: "workspace-write" };
|
|
5585
|
+
}
|
|
5586
|
+
}
|
|
5587
|
+
/**
|
|
5588
|
+
* Процесс поднят и тред открыт — или поднять. Одно обещание на процесс:
|
|
5589
|
+
* параллельные промпты ждут одного и того же запуска.
|
|
5590
|
+
*/
|
|
5591
|
+
#ensure() {
|
|
5592
|
+
if (this.#ready && this.#rpc?.alive)
|
|
5593
|
+
return this.#ready;
|
|
5594
|
+
this.#ready = this.#launch();
|
|
5595
|
+
this.#ready.catch(() => {
|
|
5596
|
+
this.#ready = null;
|
|
5597
|
+
});
|
|
5598
|
+
return this.#ready;
|
|
5599
|
+
}
|
|
5600
|
+
async #launch() {
|
|
5601
|
+
if (!this.#executable || this.#closing)
|
|
5602
|
+
throw new Error("session is closed");
|
|
5603
|
+
let rpc;
|
|
5604
|
+
try {
|
|
5605
|
+
rpc = new CodexRpc(this.#executable, this.cwd);
|
|
5606
|
+
} catch (error) {
|
|
5607
|
+
this.#fail(`\u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u0437\u0430\u043F\u0443\u0441\u0442\u0438\u0442\u044C codex: ${describe3(error)}`);
|
|
5608
|
+
throw error;
|
|
5609
|
+
}
|
|
5610
|
+
this.#rpc = rpc;
|
|
5611
|
+
rpc.on("notification", (method, params) => {
|
|
5612
|
+
if (this.#rpc === rpc)
|
|
5613
|
+
this.#onNotification(method, params);
|
|
5614
|
+
});
|
|
5615
|
+
rpc.on("request", (id, method, params) => {
|
|
5616
|
+
if (this.#rpc === rpc)
|
|
5617
|
+
this.#onServerRequest(id, method, params);
|
|
5618
|
+
});
|
|
5619
|
+
rpc.on("stderr", (data) => this.emit("stderr", data));
|
|
5620
|
+
rpc.on("exit", (code) => {
|
|
5621
|
+
if (this.#rpc !== rpc)
|
|
5622
|
+
return;
|
|
5623
|
+
this.#rpc = null;
|
|
5624
|
+
this.#ready = null;
|
|
5625
|
+
this.#onExit(code, rpc.stderrTail);
|
|
5626
|
+
});
|
|
5627
|
+
try {
|
|
5628
|
+
await rpc.initialize(this.#version);
|
|
5629
|
+
const account = await rpc.request("account/read", { refreshToken: false }).catch(() => null);
|
|
5630
|
+
if (account && account.requiresOpenaiAuth && !account.account) {
|
|
5631
|
+
throw new Error(CODEX_LOGIN_HINT);
|
|
5632
|
+
}
|
|
5633
|
+
const { approvalPolicy, sandbox } = this.#policy();
|
|
5634
|
+
const common = { cwd: this.cwd, approvalPolicy, sandbox, model: this.#record.model ?? null };
|
|
5635
|
+
const response = this.#record.conversationId ? await rpc.request("thread/resume", {
|
|
5636
|
+
threadId: this.#record.conversationId,
|
|
5637
|
+
...common
|
|
5638
|
+
}) : await rpc.request("thread/start", common);
|
|
5639
|
+
this.#threadSandbox = sandbox;
|
|
5640
|
+
if (response.thread.id !== this.#record.conversationId) {
|
|
5641
|
+
this.#record.conversationId = response.thread.id;
|
|
5642
|
+
void this.#store.save(this.#record);
|
|
5643
|
+
}
|
|
5644
|
+
} catch (error) {
|
|
5645
|
+
if (this.#rpc === rpc) {
|
|
5646
|
+
this.#rpc = null;
|
|
5647
|
+
rpc.kill();
|
|
5648
|
+
}
|
|
5649
|
+
this.#fail(describe3(error));
|
|
5650
|
+
throw error;
|
|
5651
|
+
}
|
|
5652
|
+
void rpc.request("model/list", {}).then((r) => {
|
|
5653
|
+
this.#models = r.data ?? [];
|
|
5654
|
+
this.#capabilitiesChanged();
|
|
5655
|
+
}).catch(() => void 0);
|
|
5656
|
+
void rpc.request("skills/list", { cwds: [this.cwd] }).then((r) => {
|
|
5657
|
+
this.#skills = (r.data ?? []).flatMap((e) => e.skills ?? []);
|
|
5658
|
+
this.#capabilitiesChanged();
|
|
5659
|
+
}).catch(() => void 0);
|
|
5660
|
+
void this.refreshUsage();
|
|
5661
|
+
}
|
|
5662
|
+
#fail(message) {
|
|
5663
|
+
this.#record_({ kind: "error", message });
|
|
5664
|
+
this.#setState("error");
|
|
5665
|
+
}
|
|
5666
|
+
/** Процесс ушёл сам — не по нашей просьбе. */
|
|
5667
|
+
#onExit(code, stderr) {
|
|
5668
|
+
if (this.#closing)
|
|
5669
|
+
return;
|
|
5670
|
+
const busy = this.#turnId !== null || this.#turnStarting;
|
|
5671
|
+
this.#closeOpen();
|
|
5672
|
+
this.#resetTurn();
|
|
5673
|
+
if (busy)
|
|
5674
|
+
this.#lastTurn = "failed";
|
|
5675
|
+
const tail = stderr.trim().split(/\r?\n/).filter((l) => !/ERROR codex_app_server.*deprecated/.test(l)).slice(-3).join("\n");
|
|
5676
|
+
this.#record_({
|
|
5677
|
+
kind: "error",
|
|
5678
|
+
message: `Codex \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043B\u0441\u044F (\u043A\u043E\u0434 ${code ?? "\u2014"})${tail ? `: ${tail}` : ""}. \u0421\u043B\u0435\u0434\u0443\u044E\u0449\u0438\u0439 \u043F\u0440\u043E\u043C\u043F\u0442 \u043F\u043E\u0434\u043D\u0438\u043C\u0435\u0442 \u0435\u0433\u043E \u0437\u0430\u043D\u043E\u0432\u043E.`
|
|
5679
|
+
});
|
|
5680
|
+
this.#setState("error");
|
|
5681
|
+
}
|
|
5682
|
+
async close(_reason = "closed by client") {
|
|
5683
|
+
this.#closing = true;
|
|
5684
|
+
this.#kill();
|
|
5685
|
+
this.#flush();
|
|
5686
|
+
this.#setState("closed");
|
|
5687
|
+
}
|
|
5688
|
+
#kill() {
|
|
5689
|
+
const rpc = this.#rpc;
|
|
5690
|
+
this.#rpc = null;
|
|
5691
|
+
this.#ready = null;
|
|
5692
|
+
rpc?.kill();
|
|
5693
|
+
}
|
|
5694
|
+
reconnect(_reason) {
|
|
5695
|
+
if (this.#closing)
|
|
5696
|
+
return;
|
|
5697
|
+
this.#kill();
|
|
5698
|
+
this.#closeOpen();
|
|
5699
|
+
this.#resetTurn();
|
|
5700
|
+
if (!this.#executable)
|
|
5701
|
+
return;
|
|
5702
|
+
void this.#ensure().then(() => this.#setState("idle"), () => void 0);
|
|
5703
|
+
}
|
|
5704
|
+
/** Упал VPN (см. network-guard.ts): погасить процесс, не закрывая сессию. */
|
|
5705
|
+
suspend(reason) {
|
|
5706
|
+
if (this.#closing || this.#state === "closed" || !this.#rpc)
|
|
5707
|
+
return;
|
|
5708
|
+
const busy = this.#turnId !== null || this.#turnStarting;
|
|
5709
|
+
this.#kill();
|
|
5710
|
+
this.#closeOpen();
|
|
5711
|
+
this.#resetTurn();
|
|
5712
|
+
if (busy)
|
|
5713
|
+
this.#lastTurn = "interrupted";
|
|
5714
|
+
this.#record_({
|
|
5715
|
+
kind: "error",
|
|
5716
|
+
message: `${reason}. \u041F\u0440\u043E\u0446\u0435\u0441\u0441 Codex \u043E\u0441\u0442\u0430\u043D\u043E\u0432\u043B\u0435\u043D${busy ? ", \u0445\u043E\u0434 \u043F\u0440\u0435\u0440\u0432\u0430\u043D" : ""}. \u0422\u0440\u0435\u0434 \u0441\u043E\u0445\u0440\u0430\u043D\u0451\u043D \u2014 \u043A\u043E\u0433\u0434\u0430 VPN \u0432\u0435\u0440\u043D\u0451\u0442\u0441\u044F, \u043E\u0442\u043F\u0440\u0430\u0432\u044C\u0442\u0435 \u043F\u0440\u043E\u043C\u043F\u0442, \u0438 \u0441\u0435\u0441\u0441\u0438\u044F \u043F\u0440\u043E\u0434\u043E\u043B\u0436\u0438\u0442.`
|
|
5717
|
+
});
|
|
5718
|
+
this.#setState("error");
|
|
5719
|
+
}
|
|
5720
|
+
#refuseOffRoute() {
|
|
5721
|
+
const blocked = networkGuard.blockedReason();
|
|
5722
|
+
if (!blocked)
|
|
5723
|
+
return false;
|
|
5724
|
+
this.#record_({
|
|
5725
|
+
kind: "error",
|
|
5726
|
+
message: `${blocked}. \u041F\u0440\u043E\u0446\u0435\u0441\u0441 Codex \u043D\u0435 \u0437\u0430\u043F\u0443\u0449\u0435\u043D \u2014 \u043E\u0442\u043F\u0440\u0430\u0432\u044C\u0442\u0435 \u043F\u0440\u043E\u043C\u043F\u0442, \u043A\u043E\u0433\u0434\u0430 VPN \u0432\u0435\u0440\u043D\u0451\u0442\u0441\u044F.`
|
|
5727
|
+
});
|
|
5728
|
+
this.#setState("error");
|
|
5729
|
+
return true;
|
|
5730
|
+
}
|
|
5731
|
+
// -------------------------------------------------------------------------
|
|
5732
|
+
// Ввод
|
|
5733
|
+
// -------------------------------------------------------------------------
|
|
5734
|
+
sendPrompt(text, images, _service = false, attachments) {
|
|
5735
|
+
if (this.#closing)
|
|
5736
|
+
throw new Error("session is closed");
|
|
5737
|
+
if (!this.#executable)
|
|
5738
|
+
throw new Error(CODEX_MISSING_HINT);
|
|
5739
|
+
const blocked = networkGuard.blockedReason();
|
|
5740
|
+
if (blocked)
|
|
5741
|
+
throw new Error(`${blocked}. \u041F\u0440\u043E\u043C\u043F\u0442 \u043D\u0435 \u043E\u0442\u043F\u0440\u0430\u0432\u043B\u0435\u043D.`);
|
|
5742
|
+
const command = /^\/([\w:.-]+)(?:\s+([\s\S]*))?$/.exec(text.trim());
|
|
5743
|
+
const bare = (!images || images.length === 0) && (!attachments || attachments.length === 0);
|
|
5744
|
+
if (command && LOCAL_NAMES.has(command[1]) && bare) {
|
|
5745
|
+
void this.#runLocalCommand(text, command[1], command[2]?.trim() ?? "");
|
|
5746
|
+
return;
|
|
5747
|
+
}
|
|
5748
|
+
const skill = command ? this.#skills.find((s) => s.name === command[1]) : void 0;
|
|
5749
|
+
checkAttachments(images, attachments);
|
|
5750
|
+
this.#record_({ kind: "user.message", text, images, files: attachmentMeta(attachments) });
|
|
5751
|
+
if (!this.#record.title || this.#titleIsDefault) {
|
|
5752
|
+
this.#record.title = text.slice(0, 80);
|
|
5753
|
+
this.#titleIsDefault = false;
|
|
5754
|
+
void this.#store.save(this.#record);
|
|
5755
|
+
}
|
|
5756
|
+
const steering = this.#turnId !== null;
|
|
5757
|
+
if (!steering) {
|
|
5758
|
+
this.#lastTurn = null;
|
|
5759
|
+
this.#turnStarting = true;
|
|
5760
|
+
this.#setState("running");
|
|
5761
|
+
}
|
|
5762
|
+
void this.#submit(text, images, attachments, skill, steering).catch((error) => {
|
|
5763
|
+
this.#turnStarting = false;
|
|
5764
|
+
this.#record_({ kind: "error", message: describe3(error) });
|
|
5765
|
+
if (!steering && this.#turnId === null && this.#state !== "error") {
|
|
5766
|
+
this.#lastTurn = "failed";
|
|
5767
|
+
this.#setState("idle");
|
|
5768
|
+
}
|
|
5769
|
+
});
|
|
5770
|
+
}
|
|
5771
|
+
async #submit(text, images, attachments, skill, steering) {
|
|
5772
|
+
await this.#ensure();
|
|
5773
|
+
const rpc = this.#rpc;
|
|
5774
|
+
const threadId = this.#record.conversationId;
|
|
5775
|
+
if (!rpc || !threadId)
|
|
5776
|
+
throw new Error("Codex \u043D\u0435 \u0437\u0430\u043F\u0443\u0449\u0435\u043D");
|
|
5777
|
+
const input = await this.#composeInput(text, images, attachments, skill);
|
|
5778
|
+
if (steering && this.#turnId) {
|
|
5779
|
+
await rpc.request("turn/steer", { threadId, expectedTurnId: this.#turnId, input });
|
|
5780
|
+
return;
|
|
5781
|
+
}
|
|
5782
|
+
const { approvalPolicy, sandbox } = this.#policy();
|
|
5783
|
+
const params = { threadId, input, approvalPolicy };
|
|
5784
|
+
if (this.#record.model)
|
|
5785
|
+
params.model = this.#record.model;
|
|
5786
|
+
if (this.#record.effort)
|
|
5787
|
+
params.effort = this.#record.effort;
|
|
5788
|
+
if (sandbox !== this.#threadSandbox)
|
|
5789
|
+
params.sandboxPolicy = sandboxPolicy(sandbox);
|
|
5790
|
+
this.#totalAtTurnStart = this.#lastTotal;
|
|
5791
|
+
this.#turnStartedAt = Date.now();
|
|
5792
|
+
const response = await rpc.request("turn/start", params);
|
|
5793
|
+
if (response.turn?.id && !this.#turnId)
|
|
5794
|
+
this.#turnId = response.turn.id;
|
|
5795
|
+
this.#turnStarting = false;
|
|
5796
|
+
}
|
|
5797
|
+
/** Текст, вложения, картинки (как `localImage`) и навык — во вход хода. */
|
|
5798
|
+
async #composeInput(text, images, attachments, skill) {
|
|
5799
|
+
const note = attachmentNote((attachments ?? []).map((a) => saveAttachment(a, this.id)));
|
|
5800
|
+
const input = [];
|
|
5801
|
+
if (skill)
|
|
5802
|
+
input.push({ type: "skill", name: skill.name, path: skill.path });
|
|
5803
|
+
input.push({ type: "text", text: text + note, text_elements: [] });
|
|
5804
|
+
if (images && images.length > 0) {
|
|
5805
|
+
const dir = path14.join(tmpdir3(), "ccv-codex", this.id);
|
|
5806
|
+
await mkdir5(dir, { recursive: true });
|
|
5807
|
+
for (const image of images) {
|
|
5808
|
+
const sub = image.mediaType.split("/")[1] ?? "png";
|
|
5809
|
+
const file = path14.join(dir, `${randomUUID5()}.${sub === "jpeg" ? "jpg" : sub}`);
|
|
5810
|
+
await writeFile5(file, Buffer.from(image.data, "base64"));
|
|
5811
|
+
input.push({ type: "localImage", path: file });
|
|
5812
|
+
}
|
|
5813
|
+
}
|
|
5814
|
+
return input;
|
|
5815
|
+
}
|
|
5816
|
+
/**
|
|
5817
|
+
* Команда, которую ccv отвечает сам. Посреди хода она отвечает в ленту, но
|
|
5818
|
+
* ни состояния, ни `result` не трогает: ход закроет его собственный.
|
|
5819
|
+
*/
|
|
5820
|
+
async #runLocalCommand(text, name, arg) {
|
|
5821
|
+
this.#record_({ kind: "user.message", text });
|
|
5822
|
+
const turnRunning = this.#turnId !== null || this.#turnStarting;
|
|
5823
|
+
if (!turnRunning) {
|
|
5824
|
+
this.#lastTurn = null;
|
|
5825
|
+
this.#setState("running");
|
|
5826
|
+
}
|
|
5827
|
+
const started = Date.now();
|
|
5828
|
+
let reply = null;
|
|
5829
|
+
let error = null;
|
|
5830
|
+
try {
|
|
5831
|
+
if (name === "model")
|
|
5832
|
+
({ reply, error } = await this.#modelCommand(arg));
|
|
5833
|
+
else if (name === "effort")
|
|
5834
|
+
({ reply, error } = await this.#effortCommand(arg));
|
|
5835
|
+
else if (name === "compact") {
|
|
5836
|
+
await this.#ensure();
|
|
5837
|
+
await this.#rpc?.request("thread/compact/start", { threadId: this.#record.conversationId });
|
|
5838
|
+
reply = "\u0421\u0436\u0430\u0442\u0438\u0435 \u043A\u043E\u043D\u0442\u0435\u043A\u0441\u0442\u0430 \u0437\u0430\u043F\u0443\u0449\u0435\u043D\u043E.";
|
|
5839
|
+
} else {
|
|
5840
|
+
await this.refreshUsage();
|
|
5841
|
+
reply = this.#formatStatus();
|
|
5842
|
+
}
|
|
5843
|
+
} catch (e) {
|
|
5844
|
+
error = describe3(e);
|
|
5845
|
+
}
|
|
5846
|
+
if (this.#closing)
|
|
5847
|
+
return;
|
|
5848
|
+
if (reply)
|
|
5849
|
+
this.#record_({ kind: "assistant.text", text: reply, blockId: `cmd:${randomUUID5()}` });
|
|
5850
|
+
if (error)
|
|
5851
|
+
this.#record_({ kind: "error", message: error });
|
|
5852
|
+
if (turnRunning || this.#turnId !== null)
|
|
5853
|
+
return;
|
|
5854
|
+
this.#record_({
|
|
5855
|
+
kind: "result",
|
|
5856
|
+
subtype: error ? "error" : "success",
|
|
5857
|
+
isError: Boolean(error),
|
|
5858
|
+
durationMs: Date.now() - started,
|
|
5859
|
+
costUsd: null,
|
|
5860
|
+
usage: null,
|
|
5861
|
+
contextTokens: this.#contextTokens,
|
|
5862
|
+
text: reply
|
|
5863
|
+
});
|
|
5864
|
+
this.#lastTurn = error ? "failed" : "completed";
|
|
5865
|
+
if (this.#state === "running")
|
|
5866
|
+
this.#setState("idle");
|
|
5867
|
+
else
|
|
5868
|
+
this.emit("summary", this.summary());
|
|
5869
|
+
}
|
|
5870
|
+
async #modelCommand(arg) {
|
|
5871
|
+
const label = (id2) => id2 ? this.#models.find((m) => m.id === id2)?.displayName ?? id2 : "\u043F\u043E \u0443\u043C\u043E\u043B\u0447\u0430\u043D\u0438\u044E Codex";
|
|
5872
|
+
if (!arg) {
|
|
5873
|
+
const current = this.#record.model ?? this.#defaultModel()?.id ?? null;
|
|
5874
|
+
return { reply: `\u041C\u043E\u0434\u0435\u043B\u044C: **${label(current)}**${current ? ` (\`${current}\`)` : ""}`, error: null };
|
|
5875
|
+
}
|
|
5876
|
+
const wanted = arg.toLowerCase();
|
|
5877
|
+
const visible = this.#models.filter((m) => !m.hidden);
|
|
5878
|
+
const match = this.#models.find((m) => m.id.toLowerCase() === wanted) ?? this.#models.find((m) => m.displayName.toLowerCase() === wanted);
|
|
5879
|
+
if (this.#models.length > 0 && !match) {
|
|
5880
|
+
return { reply: null, error: `\u041D\u0435\u0442 \u043C\u043E\u0434\u0435\u043B\u0438 \xAB${arg}\xBB. \u0414\u043E\u0441\u0442\u0443\u043F\u043D\u044B: ${visible.map((m) => m.id).join(", ")}` };
|
|
5881
|
+
}
|
|
5882
|
+
const id = match?.id ?? arg;
|
|
5883
|
+
await this.setModel(id);
|
|
5884
|
+
return { reply: `\u041C\u043E\u0434\u0435\u043B\u044C \u043F\u0435\u0440\u0435\u043A\u043B\u044E\u0447\u0435\u043D\u0430: **${label(id)}** (\`${id}\`)`, error: null };
|
|
5885
|
+
}
|
|
5886
|
+
async #effortCommand(arg) {
|
|
5887
|
+
const model = this.#models.find((m) => m.id === (this.#record.model ?? this.#defaultModel()?.id));
|
|
5888
|
+
const levels = model ? codexModelOptions([model])[0]?.effortLevels ?? [] : ["low", "medium", "high", "xhigh", "max"];
|
|
5889
|
+
if (!arg) {
|
|
5890
|
+
const current = this.#record.effort ?? model?.defaultReasoningEffort ?? "\u043F\u043E \u0443\u043C\u043E\u043B\u0447\u0430\u043D\u0438\u044E \u043C\u043E\u0434\u0435\u043B\u0438";
|
|
5891
|
+
return { reply: `\u0423\u0441\u0438\u043B\u0438\u0435: **${current}**`, error: null };
|
|
5892
|
+
}
|
|
5893
|
+
const level = arg.toLowerCase();
|
|
5894
|
+
if (!levels.includes(level)) {
|
|
5895
|
+
return { reply: null, error: `\u0423\u0440\u043E\u0432\u0435\u043D\u044C \u0443\u0441\u0438\u043B\u0438\u044F \u2014 \u043E\u0434\u0438\u043D \u0438\u0437: ${levels.join(", ")}` };
|
|
5896
|
+
}
|
|
5897
|
+
await this.setEffort(level);
|
|
5898
|
+
return { reply: `\u0423\u0441\u0438\u043B\u0438\u0435: **${level}**`, error: null };
|
|
5899
|
+
}
|
|
5900
|
+
#formatStatus() {
|
|
5901
|
+
const modelId = this.#record.model ?? this.#defaultModel()?.id ?? null;
|
|
5902
|
+
const model = modelId ? this.#models.find((m) => m.id === modelId)?.displayName ?? modelId : "\u2014";
|
|
5903
|
+
const effort = this.#record.effort ?? this.#models.find((m) => m.id === modelId)?.defaultReasoningEffort ?? "\u2014";
|
|
5904
|
+
const lines = [
|
|
5905
|
+
"**Codex**",
|
|
5906
|
+
"",
|
|
5907
|
+
`- \u041C\u043E\u0434\u0435\u043B\u044C: **${model}**`,
|
|
5908
|
+
`- \u0423\u0441\u0438\u043B\u0438\u0435: **${effort}**`,
|
|
5909
|
+
`- \u0420\u0435\u0436\u0438\u043C \u043F\u0440\u0430\u0432: **${this.#record.permissionMode}** (\u043F\u0435\u0441\u043E\u0447\u043D\u0438\u0446\u0430 \`${this.#policy().sandbox}\`)`
|
|
5910
|
+
];
|
|
5911
|
+
if (this.#context) {
|
|
5912
|
+
lines.push(`- \u041A\u043E\u043D\u0442\u0435\u043A\u0441\u0442: ${this.#context.tokens.toLocaleString("ru-RU")} \u0438\u0437 ${this.#context.maxTokens.toLocaleString("ru-RU")}`);
|
|
5913
|
+
}
|
|
5914
|
+
const buckets = this.#usage?.buckets ?? [];
|
|
5915
|
+
if (buckets.length > 0) {
|
|
5916
|
+
lines.push("", "| \u041E\u043A\u043D\u043E | \u0418\u0437\u0440\u0430\u0441\u0445\u043E\u0434\u043E\u0432\u0430\u043D\u043E | \u041E\u0431\u043D\u0443\u043B\u0438\u0442\u0441\u044F |", "|---|---|---|");
|
|
5917
|
+
for (const b of buckets) {
|
|
5918
|
+
const reset = b.window.resetsAt ? new Date(b.window.resetsAt).toLocaleString("ru-RU") : "\u2014";
|
|
5919
|
+
lines.push(`| ${b.label} | ${Math.round(b.window.utilization)}% | ${reset} |`);
|
|
5920
|
+
}
|
|
5921
|
+
if (this.#usage?.plan)
|
|
5922
|
+
lines.push("", `\u041F\u043B\u0430\u043D: ${this.#usage.plan}`);
|
|
5923
|
+
} else {
|
|
5924
|
+
lines.push("", "\u041B\u0438\u043C\u0438\u0442\u044B Codex: \u0434\u0430\u043D\u043D\u044B\u0445 \u043D\u0435\u0442.");
|
|
5925
|
+
}
|
|
5926
|
+
return lines.join("\n");
|
|
5927
|
+
}
|
|
5928
|
+
async editPrompt(_userIndex, _text, _images) {
|
|
5929
|
+
throw new Error("\u0412 \u0441\u0435\u0441\u0441\u0438\u0438 Codex \u043F\u0440\u0430\u0432\u043A\u0430 \u043F\u0440\u043E\u0448\u043B\u044B\u0445 \u0440\u0435\u043F\u043B\u0438\u043A \u043D\u0435 \u043F\u043E\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044F");
|
|
5930
|
+
}
|
|
5931
|
+
respondPermission(requestId, decision, reason, _answers, _annotations, _plan) {
|
|
5932
|
+
const pending = this.#approvals.get(requestId);
|
|
5933
|
+
if (!pending)
|
|
5934
|
+
return;
|
|
5935
|
+
this.#approvals.delete(requestId);
|
|
5936
|
+
if (pending.kind === "permissions") {
|
|
5937
|
+
this.#rpc?.respond(pending.rpcId, decision === "allow" ? { permissions: this.#requestedPermissions.get(requestId) ?? {}, scope: "turn" } : { permissions: {}, scope: "turn" });
|
|
5938
|
+
this.#requestedPermissions.delete(requestId);
|
|
5939
|
+
} else {
|
|
5940
|
+
this.#rpc?.respond(pending.rpcId, { decision: decision === "allow" ? "accept" : "decline" });
|
|
5941
|
+
}
|
|
5942
|
+
this.#record_({ kind: "permission.resolved", requestId, decision, ...reason ? { reason } : {} });
|
|
5943
|
+
if (this.#approvals.size === 0 && this.#state === "waiting_permission")
|
|
5944
|
+
this.#setState("running");
|
|
5945
|
+
}
|
|
5946
|
+
#requestedPermissions = /* @__PURE__ */ new Map();
|
|
5947
|
+
async interrupt() {
|
|
5948
|
+
const rpc = this.#rpc;
|
|
5949
|
+
const threadId = this.#record.conversationId;
|
|
5950
|
+
if (!rpc || !threadId || !this.#turnId)
|
|
5951
|
+
return;
|
|
5952
|
+
for (const requestId of [...this.#approvals.keys()])
|
|
5953
|
+
this.respondPermission(requestId, "deny", "\u0425\u043E\u0434 \u043F\u0440\u0435\u0440\u0432\u0430\u043D");
|
|
5954
|
+
try {
|
|
5955
|
+
await rpc.request("turn/interrupt", { threadId, turnId: this.#turnId });
|
|
5956
|
+
} catch (error) {
|
|
5957
|
+
this.#record_({ kind: "error", message: `\u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u043F\u0440\u0435\u0440\u0432\u0430\u0442\u044C \u0445\u043E\u0434: ${describe3(error)}` });
|
|
5958
|
+
}
|
|
5959
|
+
}
|
|
5960
|
+
async setPermissionMode(mode) {
|
|
5961
|
+
if (this.#record.permissionMode === mode)
|
|
5962
|
+
return;
|
|
5963
|
+
this.#record.permissionMode = mode;
|
|
5964
|
+
this.#settingsChanged();
|
|
5965
|
+
}
|
|
5966
|
+
async setModel(model) {
|
|
5967
|
+
if (this.#record.model === model)
|
|
5968
|
+
return;
|
|
5969
|
+
this.#record.model = model;
|
|
5970
|
+
const option = codexModelOptions(this.#models.filter((m) => m.id === model))[0];
|
|
5971
|
+
if (option && this.#record.effort && !option.effortLevels.includes(this.#record.effort)) {
|
|
5972
|
+
this.#record.effort = null;
|
|
5973
|
+
}
|
|
5974
|
+
this.#settingsChanged();
|
|
5975
|
+
}
|
|
5976
|
+
async setEffort(effort) {
|
|
5977
|
+
if (this.#record.effort === effort)
|
|
5978
|
+
return;
|
|
5979
|
+
this.#record.effort = effort;
|
|
5980
|
+
this.#settingsChanged();
|
|
5981
|
+
}
|
|
5982
|
+
/** Настройки применяются переопределениями следующего `turn/start`. */
|
|
5983
|
+
#settingsChanged() {
|
|
5984
|
+
this.#capabilitiesChanged();
|
|
5985
|
+
this.emit("summary", this.summary());
|
|
5986
|
+
void this.#store.save(this.#record);
|
|
5987
|
+
}
|
|
5988
|
+
#capabilitiesChanged() {
|
|
5989
|
+
if (!this.#capabilities)
|
|
5990
|
+
return;
|
|
5991
|
+
this.#capabilities = this.#baseCapabilities();
|
|
5992
|
+
this.emit("capabilities");
|
|
5993
|
+
this.emit("summary", this.summary());
|
|
5994
|
+
}
|
|
5995
|
+
// Claude-only управление: у Codex этого нет — молча ничего не делаем.
|
|
5996
|
+
async setUltracode(_enabled) {
|
|
5997
|
+
}
|
|
5998
|
+
async setThinking(_enabled) {
|
|
5999
|
+
}
|
|
6000
|
+
async setSwitchModelsOnFlag(_enabled) {
|
|
6001
|
+
}
|
|
6002
|
+
/** Лимиты аккаунта Codex — у живого процесса, без нового хода. */
|
|
6003
|
+
async refreshUsage(_force = false) {
|
|
6004
|
+
const rpc = this.#rpc;
|
|
6005
|
+
if (!rpc?.alive || networkGuard.blockedReason())
|
|
6006
|
+
return;
|
|
6007
|
+
try {
|
|
6008
|
+
const response = await rpc.request("account/rateLimits/read", null);
|
|
6009
|
+
this.#setUsage(response.rateLimits);
|
|
6010
|
+
} catch {
|
|
6011
|
+
}
|
|
6012
|
+
}
|
|
6013
|
+
#setUsage(snapshot) {
|
|
6014
|
+
const usage = codexUsage(snapshot);
|
|
6015
|
+
if (!usage)
|
|
6016
|
+
return;
|
|
6017
|
+
this.#usage = usage;
|
|
6018
|
+
this.emit("usage", usage);
|
|
6019
|
+
}
|
|
6020
|
+
async refreshContext(_force = false) {
|
|
6021
|
+
this.#emitContext();
|
|
6022
|
+
}
|
|
6023
|
+
#emitContext() {
|
|
6024
|
+
if (this.#contextTokens === null || !this.#contextWindow)
|
|
6025
|
+
return;
|
|
6026
|
+
this.#context = { tokens: this.#contextTokens, maxTokens: this.#contextWindow, fetchedAt: Date.now() };
|
|
6027
|
+
this.emit("context", this.#context);
|
|
6028
|
+
}
|
|
6029
|
+
async reloadPlugins() {
|
|
6030
|
+
}
|
|
6031
|
+
async mcpServerStatus() {
|
|
6032
|
+
return [];
|
|
6033
|
+
}
|
|
6034
|
+
async addMcpServer(_name, _config) {
|
|
6035
|
+
throw new Error("MCP-\u0441\u0435\u0440\u0432\u0435\u0440\u044B Codex \u043D\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u044E\u0442\u0441\u044F \u0432 \u0441\u0430\u043C\u043E\u043C Codex (`codex mcp`)");
|
|
6036
|
+
}
|
|
6037
|
+
async removeMcpServer(_name) {
|
|
6038
|
+
return false;
|
|
6039
|
+
}
|
|
6040
|
+
async reconnectMcpServer(_name) {
|
|
6041
|
+
throw new Error("MCP-\u0441\u0435\u0440\u0432\u0435\u0440\u044B Codex \u043D\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u044E\u0442\u0441\u044F \u0432 \u0441\u0430\u043C\u043E\u043C Codex (`codex mcp`)");
|
|
6042
|
+
}
|
|
6043
|
+
async toggleMcpServer(_name, _enabled) {
|
|
6044
|
+
throw new Error("MCP-\u0441\u0435\u0440\u0432\u0435\u0440\u044B Codex \u043D\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u044E\u0442\u0441\u044F \u0432 \u0441\u0430\u043C\u043E\u043C Codex (`codex mcp`)");
|
|
6045
|
+
}
|
|
6046
|
+
async authenticateMcpServer(_name) {
|
|
6047
|
+
throw new Error("MCP-\u0441\u0435\u0440\u0432\u0435\u0440\u044B Codex \u043D\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u044E\u0442\u0441\u044F \u0432 \u0441\u0430\u043C\u043E\u043C Codex (`codex mcp`)");
|
|
6048
|
+
}
|
|
6049
|
+
async submitMcpOAuthCallback(_name, _callbackUrl) {
|
|
6050
|
+
throw new Error("MCP-\u0441\u0435\u0440\u0432\u0435\u0440\u044B Codex \u043D\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u044E\u0442\u0441\u044F \u0432 \u0441\u0430\u043C\u043E\u043C Codex (`codex mcp`)");
|
|
6051
|
+
}
|
|
6052
|
+
setTitle(title) {
|
|
6053
|
+
this.#record.title = title;
|
|
6054
|
+
this.#titleIsDefault = false;
|
|
6055
|
+
void this.#store.save(this.#record);
|
|
6056
|
+
this.emit("summary", this.summary());
|
|
6057
|
+
}
|
|
6058
|
+
// -------------------------------------------------------------------------
|
|
6059
|
+
// Поток app-server
|
|
6060
|
+
// -------------------------------------------------------------------------
|
|
6061
|
+
#onNotification(method, params) {
|
|
6062
|
+
if (!params)
|
|
6063
|
+
return;
|
|
6064
|
+
if (typeof params.threadId === "string" && params.threadId !== this.#record.conversationId)
|
|
6065
|
+
return;
|
|
6066
|
+
switch (method) {
|
|
6067
|
+
case "turn/started": {
|
|
6068
|
+
const turn = params.turn;
|
|
6069
|
+
if (turn?.id)
|
|
6070
|
+
this.#turnId = turn.id;
|
|
6071
|
+
this.#turnStarting = false;
|
|
6072
|
+
return;
|
|
6073
|
+
}
|
|
6074
|
+
case "item/started":
|
|
6075
|
+
this.#itemStarted(params.item);
|
|
6076
|
+
return;
|
|
6077
|
+
case "item/completed":
|
|
6078
|
+
this.#itemCompleted(params.item);
|
|
6079
|
+
return;
|
|
6080
|
+
case "item/agentMessage/delta": {
|
|
6081
|
+
const itemId = String(params.itemId);
|
|
6082
|
+
const delta = String(params.delta ?? "");
|
|
6083
|
+
this.#texts.set(itemId, (this.#texts.get(itemId) ?? "") + delta);
|
|
6084
|
+
this.#record_({ kind: "assistant.delta", text: delta, blockId: itemId });
|
|
6085
|
+
return;
|
|
6086
|
+
}
|
|
6087
|
+
case "item/reasoning/summaryTextDelta": {
|
|
6088
|
+
const itemId = String(params.itemId);
|
|
6089
|
+
const delta = String(params.delta ?? "");
|
|
6090
|
+
this.#reasoning.set(itemId, (this.#reasoning.get(itemId) ?? "") + delta);
|
|
6091
|
+
this.#record_({ kind: "thinking.delta", text: delta, blockId: `${itemId}:t` });
|
|
6092
|
+
return;
|
|
6093
|
+
}
|
|
6094
|
+
case "item/reasoning/summaryPartAdded": {
|
|
6095
|
+
const itemId = String(params.itemId);
|
|
6096
|
+
if (this.#reasoning.get(itemId)) {
|
|
6097
|
+
this.#reasoning.set(itemId, `${this.#reasoning.get(itemId)}
|
|
6098
|
+
|
|
6099
|
+
`);
|
|
6100
|
+
this.#record_({ kind: "thinking.delta", text: "\n\n", blockId: `${itemId}:t` });
|
|
6101
|
+
}
|
|
6102
|
+
return;
|
|
6103
|
+
}
|
|
6104
|
+
case "thread/tokenUsage/updated": {
|
|
6105
|
+
const usage = params.tokenUsage;
|
|
6106
|
+
if (!usage)
|
|
6107
|
+
return;
|
|
6108
|
+
this.#lastTotal = usage.total;
|
|
6109
|
+
this.#contextTokens = usage.last.totalTokens;
|
|
6110
|
+
if (usage.modelContextWindow)
|
|
6111
|
+
this.#contextWindow = usage.modelContextWindow;
|
|
6112
|
+
this.#emitContext();
|
|
6113
|
+
return;
|
|
6114
|
+
}
|
|
6115
|
+
case "account/rateLimits/updated":
|
|
6116
|
+
this.#setUsage(params.rateLimits);
|
|
6117
|
+
return;
|
|
6118
|
+
case "turn/completed":
|
|
6119
|
+
this.#turnCompleted(params.turn);
|
|
6120
|
+
return;
|
|
6121
|
+
case "error": {
|
|
6122
|
+
const error = params.error;
|
|
6123
|
+
if (params.willRetry)
|
|
6124
|
+
return;
|
|
6125
|
+
const message = [error?.message, error?.additionalDetails].filter(Boolean).join("\n");
|
|
6126
|
+
if (message)
|
|
6127
|
+
this.#record_({ kind: "error", message });
|
|
6128
|
+
return;
|
|
6129
|
+
}
|
|
6130
|
+
case "serverRequest/resolved": {
|
|
6131
|
+
for (const [requestId, pending] of this.#approvals) {
|
|
6132
|
+
if (pending.rpcId === params.requestId) {
|
|
6133
|
+
this.#approvals.delete(requestId);
|
|
6134
|
+
this.#record_({ kind: "permission.resolved", requestId, decision: "deny", reason: "\u0417\u0430\u043F\u0440\u043E\u0441 \u0441\u043D\u044F\u0442" });
|
|
6135
|
+
}
|
|
6136
|
+
}
|
|
6137
|
+
if (this.#approvals.size === 0 && this.#state === "waiting_permission")
|
|
6138
|
+
this.#setState("running");
|
|
6139
|
+
return;
|
|
6140
|
+
}
|
|
6141
|
+
case "thread/compacted":
|
|
6142
|
+
this.#record_({ kind: "system", subtype: "compact_boundary", data: {} });
|
|
6143
|
+
return;
|
|
6144
|
+
default:
|
|
6145
|
+
return;
|
|
6146
|
+
}
|
|
6147
|
+
}
|
|
6148
|
+
#itemStarted(item) {
|
|
6149
|
+
if (!item?.id)
|
|
6150
|
+
return;
|
|
6151
|
+
this.#items.set(item.id, item);
|
|
6152
|
+
const use = toolUse(item);
|
|
6153
|
+
if (!use)
|
|
6154
|
+
return;
|
|
6155
|
+
this.#openTools.add(item.id);
|
|
6156
|
+
this.#record_({ kind: "tool.use", toolUseId: item.id, name: use.name, input: use.input });
|
|
6157
|
+
}
|
|
6158
|
+
#itemCompleted(item) {
|
|
6159
|
+
if (!item?.id)
|
|
6160
|
+
return;
|
|
6161
|
+
this.#items.delete(item.id);
|
|
6162
|
+
switch (item.type) {
|
|
6163
|
+
case "agentMessage": {
|
|
6164
|
+
const text = item.text ?? this.#texts.get(item.id) ?? "";
|
|
6165
|
+
this.#texts.delete(item.id);
|
|
6166
|
+
if (text)
|
|
6167
|
+
this.#record_({ kind: "assistant.text", text, blockId: item.id });
|
|
6168
|
+
return;
|
|
6169
|
+
}
|
|
6170
|
+
case "reasoning": {
|
|
6171
|
+
const text = (item.summary ?? []).join("\n\n") || this.#reasoning.get(item.id) || "";
|
|
6172
|
+
this.#reasoning.delete(item.id);
|
|
6173
|
+
if (text)
|
|
6174
|
+
this.#record_({ kind: "assistant.thinking", text, blockId: `${item.id}:t` });
|
|
6175
|
+
return;
|
|
6176
|
+
}
|
|
6177
|
+
case "contextCompaction":
|
|
6178
|
+
return;
|
|
6179
|
+
default:
|
|
6180
|
+
break;
|
|
6181
|
+
}
|
|
6182
|
+
const result = toolResult(item);
|
|
6183
|
+
if (!result)
|
|
6184
|
+
return;
|
|
6185
|
+
if (!this.#openTools.has(item.id)) {
|
|
6186
|
+
const use = toolUse(item);
|
|
6187
|
+
if (use)
|
|
6188
|
+
this.#record_({ kind: "tool.use", toolUseId: item.id, name: use.name, input: use.input });
|
|
6189
|
+
}
|
|
6190
|
+
this.#openTools.delete(item.id);
|
|
6191
|
+
this.#record_({ kind: "tool.result", toolUseId: item.id, ...result });
|
|
6192
|
+
}
|
|
6193
|
+
#turnCompleted(turn) {
|
|
6194
|
+
this.#closeOpen();
|
|
6195
|
+
for (const requestId of [...this.#approvals.keys()]) {
|
|
6196
|
+
this.#approvals.delete(requestId);
|
|
6197
|
+
this.#record_({ kind: "permission.resolved", requestId, decision: "deny", reason: "\u0425\u043E\u0434 \u0437\u0430\u0432\u0435\u0440\u0448\u0451\u043D" });
|
|
6198
|
+
}
|
|
6199
|
+
const status = turn?.status ?? "completed";
|
|
6200
|
+
const ok = status === "completed";
|
|
6201
|
+
if (turn?.error?.message && status === "failed")
|
|
6202
|
+
this.#record_({ kind: "error", message: turn.error.message });
|
|
6203
|
+
this.#record_({
|
|
6204
|
+
kind: "result",
|
|
6205
|
+
subtype: status === "interrupted" ? "interrupted" : ok ? "success" : "error",
|
|
6206
|
+
isError: status === "failed",
|
|
6207
|
+
durationMs: turn?.durationMs ?? Date.now() - this.#turnStartedAt,
|
|
6208
|
+
costUsd: null,
|
|
6209
|
+
usage: this.#turnUsage(),
|
|
6210
|
+
contextTokens: this.#contextTokens,
|
|
6211
|
+
text: null
|
|
6212
|
+
});
|
|
6213
|
+
this.#emitContext();
|
|
6214
|
+
this.#lastTurn = status === "interrupted" ? "interrupted" : ok ? "completed" : "failed";
|
|
6215
|
+
this.#resetTurn();
|
|
6216
|
+
this.#setState("idle");
|
|
6217
|
+
}
|
|
6218
|
+
/** Токены хода — разница накопленного счётчика треда до и после. */
|
|
6219
|
+
#turnUsage() {
|
|
6220
|
+
const end = this.#lastTotal;
|
|
6221
|
+
if (!end)
|
|
6222
|
+
return null;
|
|
6223
|
+
const start = this.#totalAtTurnStart;
|
|
6224
|
+
const diff = (key) => Math.max(0, end[key] - (start?.[key] ?? 0));
|
|
6225
|
+
return {
|
|
6226
|
+
inputTokens: diff("inputTokens") - diff("cachedInputTokens"),
|
|
6227
|
+
outputTokens: diff("outputTokens"),
|
|
6228
|
+
cacheReadTokens: diff("cachedInputTokens"),
|
|
6229
|
+
cacheCreationTokens: 0
|
|
6230
|
+
};
|
|
6231
|
+
}
|
|
6232
|
+
#resetTurn() {
|
|
6233
|
+
this.#turnId = null;
|
|
6234
|
+
this.#turnStarting = false;
|
|
6235
|
+
}
|
|
6236
|
+
/** Незакрытое оборванного хода: текст — в ленту, инструменты — с ошибкой. */
|
|
6237
|
+
#closeOpen() {
|
|
6238
|
+
for (const [itemId, text] of this.#texts) {
|
|
6239
|
+
if (text)
|
|
6240
|
+
this.#record_({ kind: "assistant.text", text, blockId: itemId });
|
|
6241
|
+
}
|
|
6242
|
+
for (const [itemId, text] of this.#reasoning) {
|
|
6243
|
+
if (text)
|
|
6244
|
+
this.#record_({ kind: "assistant.thinking", text, blockId: `${itemId}:t` });
|
|
6245
|
+
}
|
|
6246
|
+
for (const itemId of this.#openTools) {
|
|
6247
|
+
this.#record_({ kind: "tool.result", toolUseId: itemId, content: "\u041F\u0440\u0435\u0440\u0432\u0430\u043D\u043E", isError: true });
|
|
6248
|
+
}
|
|
6249
|
+
this.#texts.clear();
|
|
6250
|
+
this.#reasoning.clear();
|
|
6251
|
+
this.#openTools.clear();
|
|
6252
|
+
this.#items.clear();
|
|
6253
|
+
}
|
|
6254
|
+
// -------------------------------------------------------------------------
|
|
6255
|
+
// Запросы сервера — разрешения
|
|
6256
|
+
// -------------------------------------------------------------------------
|
|
6257
|
+
#onServerRequest(id, method, params) {
|
|
6258
|
+
const rpc = this.#rpc;
|
|
6259
|
+
if (!rpc)
|
|
6260
|
+
return;
|
|
6261
|
+
const mode = this.#record.permissionMode;
|
|
6262
|
+
const itemId = String(params?.itemId ?? "");
|
|
6263
|
+
const reason = typeof params?.reason === "string" ? params.reason : void 0;
|
|
6264
|
+
switch (method) {
|
|
6265
|
+
case "item/commandExecution/requestApproval": {
|
|
6266
|
+
if (mode === "bypassPermissions") {
|
|
6267
|
+
rpc.respond(id, { decision: "accept" });
|
|
6268
|
+
return;
|
|
6269
|
+
}
|
|
6270
|
+
this.#askPermission(id, "command", itemId, "Bash", {
|
|
6271
|
+
command: unwrapShell(String(params.command ?? this.#items.get(itemId)?.command ?? "")),
|
|
6272
|
+
cwd: params.cwd ?? this.cwd
|
|
6273
|
+
}, reason);
|
|
6274
|
+
return;
|
|
6275
|
+
}
|
|
6276
|
+
case "item/fileChange/requestApproval": {
|
|
6277
|
+
if (mode === "bypassPermissions" || mode === "acceptEdits") {
|
|
6278
|
+
rpc.respond(id, { decision: "accept" });
|
|
6279
|
+
return;
|
|
6280
|
+
}
|
|
6281
|
+
const item = this.#items.get(itemId);
|
|
6282
|
+
const use = item ? toolUse(item) : null;
|
|
6283
|
+
this.#askPermission(id, "file", itemId, use?.name ?? "apply_patch", use?.input ?? {}, reason);
|
|
6284
|
+
return;
|
|
6285
|
+
}
|
|
6286
|
+
case "item/permissions/requestApproval": {
|
|
6287
|
+
const requestId = this.#askPermission(id, "permissions", itemId, "Permissions", params.permissions ?? {}, reason);
|
|
6288
|
+
this.#requestedPermissions.set(requestId, params.permissions ?? {});
|
|
6289
|
+
return;
|
|
6290
|
+
}
|
|
6291
|
+
case "mcpServer/elicitation/request":
|
|
6292
|
+
rpc.respond(id, { action: "decline", content: null, _meta: null });
|
|
6293
|
+
return;
|
|
6294
|
+
case "item/tool/requestUserInput":
|
|
6295
|
+
rpc.respond(id, { answers: {} });
|
|
6296
|
+
return;
|
|
6297
|
+
default:
|
|
6298
|
+
rpc.respondError(id, `ccv \u043D\u0435 \u043F\u043E\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 ${method}`);
|
|
6299
|
+
return;
|
|
6300
|
+
}
|
|
6301
|
+
}
|
|
6302
|
+
#askPermission(rpcId, kind, itemId, toolName, input, reason) {
|
|
6303
|
+
const requestId = randomUUID5();
|
|
6304
|
+
this.#approvals.set(requestId, { rpcId, kind, itemId });
|
|
6305
|
+
this.#setState("waiting_permission");
|
|
6306
|
+
this.#record_({
|
|
6307
|
+
kind: "permission.request",
|
|
6308
|
+
requestId,
|
|
6309
|
+
toolName,
|
|
6310
|
+
input,
|
|
6311
|
+
...reason ? { reason } : {},
|
|
6312
|
+
...itemId ? { toolUseId: itemId } : {}
|
|
6313
|
+
});
|
|
6314
|
+
return requestId;
|
|
6315
|
+
}
|
|
6316
|
+
// -------------------------------------------------------------------------
|
|
6317
|
+
#record_(event) {
|
|
6318
|
+
this.#updatedAt = Date.now();
|
|
6319
|
+
const entry = this.journal.append(event);
|
|
6320
|
+
this.emit("event", entry);
|
|
6321
|
+
if (TRANSIENT2.has(event.kind))
|
|
6322
|
+
return;
|
|
6323
|
+
this.#unsaved.push({ ts: entry.ts, event });
|
|
6324
|
+
this.#scheduleFlush();
|
|
6325
|
+
}
|
|
6326
|
+
#scheduleFlush() {
|
|
6327
|
+
if (this.#flushTimer)
|
|
6328
|
+
return;
|
|
6329
|
+
this.#flushTimer = setTimeout(() => this.#flush(), 500);
|
|
6330
|
+
this.#flushTimer.unref?.();
|
|
6331
|
+
}
|
|
6332
|
+
#flush() {
|
|
6333
|
+
if (this.#flushTimer) {
|
|
6334
|
+
clearTimeout(this.#flushTimer);
|
|
6335
|
+
this.#flushTimer = null;
|
|
6336
|
+
}
|
|
6337
|
+
const batch = this.#unsaved;
|
|
6338
|
+
this.#unsaved = [];
|
|
6339
|
+
this.#record.updatedAt = this.#updatedAt;
|
|
6340
|
+
void this.#store.appendEvents(this.id, batch);
|
|
6341
|
+
void this.#store.save(this.#record);
|
|
6342
|
+
}
|
|
6343
|
+
#setState(state) {
|
|
6344
|
+
if (this.#state === state)
|
|
6345
|
+
return;
|
|
6346
|
+
this.#state = state;
|
|
6347
|
+
this.#record_({ kind: "state", state });
|
|
6348
|
+
if (state === "idle" || state === "error" || state === "closed")
|
|
6349
|
+
this.#flush();
|
|
6350
|
+
this.emit("summary", this.summary());
|
|
6351
|
+
}
|
|
6352
|
+
};
|
|
6353
|
+
function sandboxPolicy(mode) {
|
|
6354
|
+
switch (mode) {
|
|
6355
|
+
case "read-only":
|
|
6356
|
+
return { type: "readOnly", networkAccess: false };
|
|
6357
|
+
case "danger-full-access":
|
|
6358
|
+
return { type: "dangerFullAccess" };
|
|
6359
|
+
default:
|
|
6360
|
+
return {
|
|
6361
|
+
type: "workspaceWrite",
|
|
6362
|
+
writableRoots: [],
|
|
6363
|
+
networkAccess: false,
|
|
6364
|
+
excludeTmpdirEnvVar: false,
|
|
6365
|
+
excludeSlashTmp: false
|
|
6366
|
+
};
|
|
6367
|
+
}
|
|
6368
|
+
}
|
|
6369
|
+
function toolUse(item) {
|
|
6370
|
+
switch (item.type) {
|
|
6371
|
+
case "commandExecution":
|
|
6372
|
+
return { name: "Bash", input: { command: unwrapShell(item.command ?? ""), cwd: item.cwd } };
|
|
6373
|
+
case "fileChange": {
|
|
6374
|
+
const changes = item.changes ?? [];
|
|
6375
|
+
return {
|
|
6376
|
+
name: "apply_patch",
|
|
6377
|
+
input: {
|
|
6378
|
+
file_path: changes[0]?.path ?? "",
|
|
6379
|
+
changes: changes.map((c) => ({ path: c.path, kind: c.kind?.type ?? "update", diff: c.diff }))
|
|
6380
|
+
}
|
|
6381
|
+
};
|
|
6382
|
+
}
|
|
6383
|
+
case "mcpToolCall":
|
|
6384
|
+
return {
|
|
6385
|
+
name: `mcp__${item.server ?? "mcp"}__${item.tool ?? "tool"}`,
|
|
6386
|
+
input: isRecord(item.arguments) ? item.arguments : { arguments: item.arguments }
|
|
6387
|
+
};
|
|
6388
|
+
case "dynamicToolCall":
|
|
6389
|
+
return { name: item.tool ?? "tool", input: isRecord(item.arguments) ? item.arguments : { arguments: item.arguments } };
|
|
6390
|
+
case "webSearch":
|
|
6391
|
+
return { name: "WebSearch", input: { query: item.query ?? "" } };
|
|
6392
|
+
case "imageView":
|
|
6393
|
+
return { name: "Read", input: { file_path: item.path ?? "" } };
|
|
6394
|
+
default:
|
|
6395
|
+
return null;
|
|
6396
|
+
}
|
|
6397
|
+
}
|
|
6398
|
+
function toolResult(item) {
|
|
6399
|
+
switch (item.type) {
|
|
6400
|
+
case "commandExecution": {
|
|
6401
|
+
const failed = item.status === "failed" || item.status === "declined" || (item.exitCode ?? 0) !== 0;
|
|
6402
|
+
const output = item.aggregatedOutput ?? "";
|
|
6403
|
+
const tail = item.status === "declined" ? "\u041E\u0442\u043A\u043B\u043E\u043D\u0435\u043D\u043E" : item.exitCode ? `
|
|
6404
|
+
(\u043A\u043E\u0434 \u0432\u044B\u0445\u043E\u0434\u0430 ${item.exitCode})` : "";
|
|
6405
|
+
return { content: (output + tail).trim(), isError: failed };
|
|
6406
|
+
}
|
|
6407
|
+
case "fileChange": {
|
|
6408
|
+
const ok = item.status === "completed";
|
|
6409
|
+
const files = (item.changes ?? []).map((c) => `${c.kind?.type ?? "update"} ${c.path}`).join("\n");
|
|
6410
|
+
return { content: ok ? files : `${item.status === "declined" ? "\u041E\u0442\u043A\u043B\u043E\u043D\u0435\u043D\u043E" : "\u041D\u0435 \u043F\u0440\u0438\u043C\u0435\u043D\u0435\u043D\u043E"}
|
|
6411
|
+
${files}`, isError: !ok };
|
|
6412
|
+
}
|
|
6413
|
+
case "mcpToolCall": {
|
|
6414
|
+
if (item.error?.message)
|
|
6415
|
+
return { content: item.error.message, isError: true };
|
|
6416
|
+
return { content: contentText(item.result?.content) || jsonText(item.result?.structuredContent), isError: item.status === "failed" };
|
|
6417
|
+
}
|
|
6418
|
+
case "dynamicToolCall":
|
|
6419
|
+
return { content: contentText(item.contentItems ?? void 0), isError: item.success === false };
|
|
6420
|
+
case "webSearch":
|
|
6421
|
+
return { content: item.query ? `\u041F\u043E\u0438\u0441\u043A: ${item.query}` : "", isError: false };
|
|
6422
|
+
case "imageView":
|
|
6423
|
+
return { content: "", isError: false };
|
|
6424
|
+
default:
|
|
6425
|
+
return null;
|
|
6426
|
+
}
|
|
6427
|
+
}
|
|
6428
|
+
function unwrapShell(command) {
|
|
6429
|
+
const match = /^"?[^"]*?(?:pwsh|powershell|bash|zsh|sh|cmd)(?:\.exe)?"?\s+(?:-NoProfile\s+)?(?:-Command|-lc|-c|\/c)\s+([\s\S]+)$/i.exec(command);
|
|
6430
|
+
if (!match)
|
|
6431
|
+
return command;
|
|
6432
|
+
const inner = match[1].trim();
|
|
6433
|
+
if (inner.startsWith("'") && inner.endsWith("'") || inner.startsWith('"') && inner.endsWith('"')) {
|
|
6434
|
+
return inner.slice(1, -1);
|
|
6435
|
+
}
|
|
6436
|
+
return inner;
|
|
6437
|
+
}
|
|
6438
|
+
function contentText(content) {
|
|
6439
|
+
if (!Array.isArray(content))
|
|
6440
|
+
return "";
|
|
6441
|
+
return content.map((c) => isRecord(c) && typeof c.text === "string" ? c.text : isRecord(c) ? `[${String(c.type ?? "content")}]` : "").filter(Boolean).join("\n");
|
|
6442
|
+
}
|
|
6443
|
+
function jsonText(value) {
|
|
6444
|
+
if (value === null || value === void 0)
|
|
6445
|
+
return "";
|
|
6446
|
+
try {
|
|
6447
|
+
return JSON.stringify(value, null, 2);
|
|
6448
|
+
} catch {
|
|
6449
|
+
return String(value);
|
|
6450
|
+
}
|
|
6451
|
+
}
|
|
6452
|
+
function isRecord(value) {
|
|
6453
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
6454
|
+
}
|
|
6455
|
+
function describe3(error) {
|
|
6456
|
+
return error instanceof Error ? error.message : String(error);
|
|
6457
|
+
}
|
|
6458
|
+
|
|
6459
|
+
// ../host/dist/codex-store.js
|
|
6460
|
+
var CodexStore = class extends AntigravityStore {
|
|
6461
|
+
constructor(dataDir) {
|
|
6462
|
+
super(dataDir, "codex");
|
|
6463
|
+
}
|
|
6464
|
+
};
|
|
6465
|
+
|
|
6466
|
+
// ../host/dist/git.js
|
|
6467
|
+
import { execFile as execFile5 } from "node:child_process";
|
|
6468
|
+
import { mkdtemp, readFile as readFile6, rm as rm3, writeFile as writeFile6 } from "node:fs/promises";
|
|
6469
|
+
import { tmpdir as tmpdir4 } from "node:os";
|
|
6470
|
+
import path15 from "node:path";
|
|
6471
|
+
var TIMEOUT_MS = 2e4;
|
|
6472
|
+
var NET_TIMEOUT_MS = 5 * 6e4;
|
|
6473
|
+
var MAX_BUFFER = 32 * 1024 * 1024;
|
|
6474
|
+
var LOG_LIMIT = 150;
|
|
6475
|
+
var UNPUSHED_LIMIT = 2e3;
|
|
6476
|
+
var MAX_PATCH = 4e5;
|
|
6477
|
+
var MAX_FILE_PATCH = 8e4;
|
|
6478
|
+
var UNIT = "";
|
|
6479
|
+
var RECORD = "";
|
|
6480
|
+
var SAFE_REF = /^[A-Za-z0-9][A-Za-z0-9._/@^~-]*$/;
|
|
6481
|
+
var SAFE_URL = /^(?:https?:\/\/|ssh:\/\/|git:\/\/|[A-Za-z0-9._-]+@[A-Za-z0-9._-]+:)[^\s]+$/;
|
|
6482
|
+
var CANDIDATE_LIMIT = 2e3;
|
|
6483
|
+
var GitRepo = class {
|
|
6484
|
+
cwd;
|
|
6485
|
+
constructor(cwd) {
|
|
6486
|
+
this.cwd = cwd;
|
|
6487
|
+
}
|
|
6488
|
+
/**
|
|
6489
|
+
* Снимок репозитория целиком: статус, ветки и лента коммитов.
|
|
6490
|
+
*
|
|
6491
|
+
* Собирается одним проходом, потому что панель показывает это вместе.
|
|
6492
|
+
* Отдельные части опрашиваются терпимо к ошибкам: в репозитории без единого
|
|
6493
|
+
* коммита `rev-parse HEAD` падает, и это не повод не показать вообще ничего.
|
|
6494
|
+
*/
|
|
6495
|
+
async state() {
|
|
6496
|
+
const blank = {
|
|
6497
|
+
available: false,
|
|
6498
|
+
message: "",
|
|
6499
|
+
noRepo: false,
|
|
6500
|
+
branch: "",
|
|
6501
|
+
head: "",
|
|
6502
|
+
detached: false,
|
|
6503
|
+
upstream: "",
|
|
6504
|
+
hasRemote: false,
|
|
6505
|
+
remoteUrl: "",
|
|
6506
|
+
ahead: 0,
|
|
6507
|
+
behind: 0,
|
|
6508
|
+
changed: [],
|
|
6509
|
+
commits: [],
|
|
6510
|
+
branches: []
|
|
6511
|
+
};
|
|
6512
|
+
try {
|
|
6513
|
+
await this.#run(["rev-parse", "--is-inside-work-tree"]);
|
|
6514
|
+
} catch (error) {
|
|
6515
|
+
const runnable2 = await this.#run(["--version"]).then(() => true, () => false);
|
|
6516
|
+
return { ...blank, message: describe4(error), noRepo: runnable2 };
|
|
6517
|
+
}
|
|
6518
|
+
const branchRaw = await this.#soft(["rev-parse", "--abbrev-ref", "HEAD"]);
|
|
6519
|
+
const detached = branchRaw === "HEAD" || branchRaw === "";
|
|
6520
|
+
const upstream = await this.#soft([
|
|
6521
|
+
"rev-parse",
|
|
6522
|
+
"--abbrev-ref",
|
|
6523
|
+
"--symbolic-full-name",
|
|
6524
|
+
"@{upstream}"
|
|
6525
|
+
]);
|
|
4727
6526
|
const counts = upstream ? await this.#soft(["rev-list", "--left-right", "--count", `${upstream}...HEAD`]) : "";
|
|
4728
6527
|
const [behind = "0", ahead = "0"] = counts.split(/\s+/);
|
|
4729
6528
|
const hasRemote = await this.#soft(["remote"]) !== "";
|
|
@@ -4984,7 +6783,7 @@ var GitRepo = class {
|
|
|
4984
6783
|
* важнее всего (см. `checkIgnored`).
|
|
4985
6784
|
*/
|
|
4986
6785
|
async #withoutRepo(args) {
|
|
4987
|
-
const dir = await mkdtemp(
|
|
6786
|
+
const dir = await mkdtemp(path15.join(tmpdir4(), "ccv-git-"));
|
|
4988
6787
|
try {
|
|
4989
6788
|
await this.#run(["init", "--bare", "--quiet", dir]);
|
|
4990
6789
|
return await this.#soft([`--git-dir=${dir}`, `--work-tree=${this.cwd}`, ...args]);
|
|
@@ -5030,14 +6829,14 @@ var GitRepo = class {
|
|
|
5030
6829
|
* исключил. Повторы отсеиваются, чтобы файл не рос от каждой публикации.
|
|
5031
6830
|
*/
|
|
5032
6831
|
async #appendGitignore(paths) {
|
|
5033
|
-
const file =
|
|
6832
|
+
const file = path15.join(this.cwd, ".gitignore");
|
|
5034
6833
|
const existing = await readFile6(file, "utf8").catch(() => "");
|
|
5035
6834
|
const known = new Set(existing.split(/\r?\n/).map((line) => line.trim()));
|
|
5036
6835
|
const lines = paths.map(ignorePattern).filter((line) => !known.has(line));
|
|
5037
6836
|
if (lines.length === 0)
|
|
5038
6837
|
return;
|
|
5039
6838
|
const prefix = existing === "" || existing.endsWith("\n") ? "" : "\n";
|
|
5040
|
-
await
|
|
6839
|
+
await writeFile6(file, `${existing}${prefix}${lines.join("\n")}
|
|
5041
6840
|
`, "utf8");
|
|
5042
6841
|
}
|
|
5043
6842
|
/** Команда, чей провал — обычное дело (нет upstream, нет коммитов, detached). */
|
|
@@ -5055,7 +6854,7 @@ var GitRepo = class {
|
|
|
5055
6854
|
#run(args, options2 = {}) {
|
|
5056
6855
|
const token = options2.token ?? "";
|
|
5057
6856
|
return new Promise((resolve, reject) => {
|
|
5058
|
-
const child =
|
|
6857
|
+
const child = execFile5(
|
|
5059
6858
|
"git",
|
|
5060
6859
|
// core.quotepath=false — иначе кириллические пути приезжают в виде
|
|
5061
6860
|
// «\320\277\321\200…» и в панели читаются как мусор.
|
|
@@ -5126,7 +6925,7 @@ function requirePath(value) {
|
|
|
5126
6925
|
function ignorePattern(relPath) {
|
|
5127
6926
|
return `/${relPath.replace(/[\\*?[\]]/g, (char) => `\\${char}`)}`;
|
|
5128
6927
|
}
|
|
5129
|
-
function
|
|
6928
|
+
function describe4(error) {
|
|
5130
6929
|
return error instanceof Error ? error.message : String(error);
|
|
5131
6930
|
}
|
|
5132
6931
|
function parseStatus(raw) {
|
|
@@ -5236,9 +7035,9 @@ function parsePatch(raw) {
|
|
|
5236
7035
|
body = "";
|
|
5237
7036
|
}
|
|
5238
7037
|
total += body.length;
|
|
5239
|
-
const
|
|
7038
|
+
const path35 = status === "deleted" ? oldPath : newPath || oldPath;
|
|
5240
7039
|
files.push({
|
|
5241
|
-
path:
|
|
7040
|
+
path: path35,
|
|
5242
7041
|
oldPath: status === "renamed" ? oldPath : "",
|
|
5243
7042
|
status,
|
|
5244
7043
|
added: count(body, "+"),
|
|
@@ -5250,10 +7049,10 @@ function parsePatch(raw) {
|
|
|
5250
7049
|
return { files, truncated };
|
|
5251
7050
|
}
|
|
5252
7051
|
function stripPrefix(value) {
|
|
5253
|
-
const
|
|
5254
|
-
if (
|
|
7052
|
+
const path35 = unquote(value.trim());
|
|
7053
|
+
if (path35 === "/dev/null")
|
|
5255
7054
|
return "";
|
|
5256
|
-
return
|
|
7055
|
+
return path35.replace(/^[ab]\//, "");
|
|
5257
7056
|
}
|
|
5258
7057
|
function count(body, mark) {
|
|
5259
7058
|
let n = 0;
|
|
@@ -5265,9 +7064,9 @@ function count(body, mark) {
|
|
|
5265
7064
|
}
|
|
5266
7065
|
|
|
5267
7066
|
// ../host/dist/github.js
|
|
5268
|
-
import { execFile as
|
|
5269
|
-
import { mkdir as
|
|
5270
|
-
import
|
|
7067
|
+
import { execFile as execFile6 } from "node:child_process";
|
|
7068
|
+
import { mkdir as mkdir6, readFile as readFile7, writeFile as writeFile7 } from "node:fs/promises";
|
|
7069
|
+
import path16 from "node:path";
|
|
5271
7070
|
var API = "https://api.github.com";
|
|
5272
7071
|
var API_VERSION = "2022-11-28";
|
|
5273
7072
|
var API_TIMEOUT_MS = 2e4;
|
|
@@ -5288,7 +7087,7 @@ var GitHubAccount = class {
|
|
|
5288
7087
|
*/
|
|
5289
7088
|
#ghInstalled = null;
|
|
5290
7089
|
constructor(dataDir) {
|
|
5291
|
-
this.#storePath =
|
|
7090
|
+
this.#storePath = path16.join(dataDir, "github.json");
|
|
5292
7091
|
}
|
|
5293
7092
|
async load() {
|
|
5294
7093
|
try {
|
|
@@ -5302,8 +7101,8 @@ var GitHubAccount = class {
|
|
|
5302
7101
|
/** Сохранить токен или стереть его пустой строкой. */
|
|
5303
7102
|
async setToken(token) {
|
|
5304
7103
|
this.#token = token.trim();
|
|
5305
|
-
await
|
|
5306
|
-
await
|
|
7104
|
+
await mkdir6(path16.dirname(this.#storePath), { recursive: true });
|
|
7105
|
+
await writeFile7(this.#storePath, JSON.stringify({ token: this.#token }, null, 2), {
|
|
5307
7106
|
encoding: "utf8",
|
|
5308
7107
|
mode: 384
|
|
5309
7108
|
});
|
|
@@ -5330,7 +7129,7 @@ var GitHubAccount = class {
|
|
|
5330
7129
|
const credential = await this.credential();
|
|
5331
7130
|
return { ...base, connected: true, source: credential.source, login: credential.login };
|
|
5332
7131
|
} catch (error) {
|
|
5333
|
-
return { ...base, message:
|
|
7132
|
+
return { ...base, message: describe5(error) };
|
|
5334
7133
|
}
|
|
5335
7134
|
}
|
|
5336
7135
|
/**
|
|
@@ -5401,104 +7200,436 @@ var GitHubAccount = class {
|
|
|
5401
7200
|
fullName: str2(created.full_name) || `${options2.owner}/${options2.name}`
|
|
5402
7201
|
};
|
|
5403
7202
|
}
|
|
5404
|
-
// ---------------------------------------------------------------- внутреннее
|
|
5405
|
-
/** Логин владельца токена; заодно это и есть проверка токена на живость. */
|
|
5406
|
-
async #login(token) {
|
|
5407
|
-
const user = await this.#api(token, "/user");
|
|
5408
|
-
const login = str2(user.login);
|
|
5409
|
-
if (!login)
|
|
5410
|
-
throw new Error("GitHub \u043D\u0435 \u043D\u0430\u0437\u0432\u0430\u043B \u0443\u0447\u0451\u0442\u043D\u0443\u044E \u0437\u0430\u043F\u0438\u0441\u044C \u2014 \u0442\u043E\u043A\u0435\u043D \u043D\u0435 \u043F\u043E\u0434\u043E\u0448\u0451\u043B");
|
|
5411
|
-
return login;
|
|
7203
|
+
// ---------------------------------------------------------------- внутреннее
|
|
7204
|
+
/** Логин владельца токена; заодно это и есть проверка токена на живость. */
|
|
7205
|
+
async #login(token) {
|
|
7206
|
+
const user = await this.#api(token, "/user");
|
|
7207
|
+
const login = str2(user.login);
|
|
7208
|
+
if (!login)
|
|
7209
|
+
throw new Error("GitHub \u043D\u0435 \u043D\u0430\u0437\u0432\u0430\u043B \u0443\u0447\u0451\u0442\u043D\u0443\u044E \u0437\u0430\u043F\u0438\u0441\u044C \u2014 \u0442\u043E\u043A\u0435\u043D \u043D\u0435 \u043F\u043E\u0434\u043E\u0448\u0451\u043B");
|
|
7210
|
+
return login;
|
|
7211
|
+
}
|
|
7212
|
+
async #api(token, endpoint, init) {
|
|
7213
|
+
let response;
|
|
7214
|
+
try {
|
|
7215
|
+
response = await fetch(`${API}${endpoint}`, {
|
|
7216
|
+
method: init?.method ?? "GET",
|
|
7217
|
+
headers: {
|
|
7218
|
+
Accept: "application/vnd.github+json",
|
|
7219
|
+
Authorization: `Bearer ${token}`,
|
|
7220
|
+
"X-GitHub-Api-Version": API_VERSION,
|
|
7221
|
+
// GitHub отвечает 403 на запрос без User-Agent — это его требование,
|
|
7222
|
+
// а не вежливость.
|
|
7223
|
+
"User-Agent": "claude-code-visual",
|
|
7224
|
+
...init ? { "Content-Type": "application/json" } : {}
|
|
7225
|
+
},
|
|
7226
|
+
body: init ? JSON.stringify(init.body) : void 0,
|
|
7227
|
+
signal: AbortSignal.timeout(API_TIMEOUT_MS)
|
|
7228
|
+
});
|
|
7229
|
+
} catch (error) {
|
|
7230
|
+
throw new Error(`GitHub \u043D\u0435\u0434\u043E\u0441\u0442\u0443\u043F\u0435\u043D: ${describe5(error)}`);
|
|
7231
|
+
}
|
|
7232
|
+
const text = await response.text();
|
|
7233
|
+
if (!response.ok)
|
|
7234
|
+
throw new Error(apiError(response.status, text));
|
|
7235
|
+
try {
|
|
7236
|
+
return JSON.parse(text);
|
|
7237
|
+
} catch {
|
|
7238
|
+
throw new Error(`GitHub \u043E\u0442\u0432\u0435\u0442\u0438\u043B \u043D\u0435 JSON (${response.status})`);
|
|
7239
|
+
}
|
|
7240
|
+
}
|
|
7241
|
+
/** Токен GitHub CLI; пустая строка — `gh` нет или вход в нём не выполнен. */
|
|
7242
|
+
async #ghToken() {
|
|
7243
|
+
if (this.#ghInstalled === false)
|
|
7244
|
+
return "";
|
|
7245
|
+
const token = await gh(["auth", "token"]).catch(() => "");
|
|
7246
|
+
return token.trim();
|
|
7247
|
+
}
|
|
7248
|
+
async #hasGh() {
|
|
7249
|
+
const version2 = await gh(["--version"]).catch(() => "");
|
|
7250
|
+
this.#ghInstalled = version2 !== "";
|
|
7251
|
+
return this.#ghInstalled;
|
|
7252
|
+
}
|
|
7253
|
+
};
|
|
7254
|
+
function gh(args) {
|
|
7255
|
+
return new Promise((resolve, reject) => {
|
|
7256
|
+
execFile6("gh", args, { timeout: GH_TIMEOUT_MS, windowsHide: true, encoding: "utf8" }, (error, stdout, stderr) => {
|
|
7257
|
+
if (error)
|
|
7258
|
+
return reject(new Error(stderr.trim() || error.message));
|
|
7259
|
+
resolve(stdout);
|
|
7260
|
+
});
|
|
7261
|
+
});
|
|
7262
|
+
}
|
|
7263
|
+
function apiError(status, body) {
|
|
7264
|
+
let message = "";
|
|
7265
|
+
let details = "";
|
|
7266
|
+
try {
|
|
7267
|
+
const parsed = JSON.parse(body);
|
|
7268
|
+
message = str2(parsed.message);
|
|
7269
|
+
if (Array.isArray(parsed.errors)) {
|
|
7270
|
+
details = parsed.errors.map((item) => str2(item.message)).filter(Boolean).join("; ");
|
|
7271
|
+
}
|
|
7272
|
+
} catch {
|
|
7273
|
+
message = body.slice(0, 200).trim();
|
|
7274
|
+
}
|
|
7275
|
+
const text = [message, details].filter(Boolean).join(" \u2014 ");
|
|
7276
|
+
switch (status) {
|
|
7277
|
+
case 401:
|
|
7278
|
+
return "GitHub \u043E\u0442\u043A\u043B\u043E\u043D\u0438\u043B \u0442\u043E\u043A\u0435\u043D (401) \u2014 \u043E\u043D \u0438\u0441\u0442\u0451\u043A \u0438\u043B\u0438 \u043E\u0442\u043E\u0437\u0432\u0430\u043D";
|
|
7279
|
+
case 403:
|
|
7280
|
+
return `GitHub \u043E\u0442\u043A\u0430\u0437\u0430\u043B (403): ${text || "\u043D\u0435\u0442 \u043F\u0440\u0430\u0432 \u0438\u043B\u0438 \u043F\u0440\u0435\u0432\u044B\u0448\u0435\u043D \u043B\u0438\u043C\u0438\u0442 \u0437\u0430\u043F\u0440\u043E\u0441\u043E\u0432"}`;
|
|
7281
|
+
case 404:
|
|
7282
|
+
return `GitHub \u043E\u0442\u0432\u0435\u0442\u0438\u043B 404: ${text || "\u043D\u0435\u0442 \u0442\u0430\u043A\u043E\u0439 \u043E\u0440\u0433\u0430\u043D\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u043B\u0438 \u0443 \u0442\u043E\u043A\u0435\u043D\u0430 \u043D\u0435\u0442 \u043F\u0440\u0430\u0432 \u043D\u0430 \u043D\u0435\u0451"}`;
|
|
7283
|
+
case 422:
|
|
7284
|
+
return `GitHub \u043E\u0442\u043A\u0430\u0437\u0430\u043B\u0441\u044F \u0441\u043E\u0437\u0434\u0430\u0432\u0430\u0442\u044C: ${text || "\u0442\u0430\u043A\u043E\u0435 \u0438\u043C\u044F \u0443\u0436\u0435 \u0437\u0430\u043D\u044F\u0442\u043E"}`;
|
|
7285
|
+
default:
|
|
7286
|
+
return `GitHub \u043E\u0442\u0432\u0435\u0442\u0438\u043B ${status}${text ? `: ${text}` : ""}`;
|
|
7287
|
+
}
|
|
7288
|
+
}
|
|
7289
|
+
function str2(value) {
|
|
7290
|
+
return typeof value === "string" ? value : "";
|
|
7291
|
+
}
|
|
7292
|
+
function describe5(error) {
|
|
7293
|
+
return error instanceof Error ? error.message : String(error);
|
|
7294
|
+
}
|
|
7295
|
+
|
|
7296
|
+
// ../host/dist/memory.js
|
|
7297
|
+
import { mkdir as mkdir7, readFile as readFile8, readdir as readdir4, rm as rm4, stat as stat4, writeFile as writeFile8 } from "node:fs/promises";
|
|
7298
|
+
import path17 from "node:path";
|
|
7299
|
+
function projectSlug(cwd) {
|
|
7300
|
+
return cwd.replace(/[^a-zA-Z0-9]/g, "-");
|
|
7301
|
+
}
|
|
7302
|
+
var MEMORY_INDEX = "MEMORY.md";
|
|
7303
|
+
var MAX_SIZE = 1024 * 1024;
|
|
7304
|
+
var MemoryFiles = class {
|
|
7305
|
+
cwd;
|
|
7306
|
+
configDir;
|
|
7307
|
+
constructor(cwd, configDir) {
|
|
7308
|
+
this.cwd = cwd;
|
|
7309
|
+
this.configDir = configDir;
|
|
7310
|
+
}
|
|
7311
|
+
get memoryDir() {
|
|
7312
|
+
return path17.join(this.configDir, "projects", projectSlug(this.cwd), "memory");
|
|
7313
|
+
}
|
|
7314
|
+
async #entries() {
|
|
7315
|
+
const entries = [
|
|
7316
|
+
{
|
|
7317
|
+
id: "user",
|
|
7318
|
+
scope: "user",
|
|
7319
|
+
label: "\u0418\u043D\u0441\u0442\u0440\u0443\u043A\u0446\u0438\u0438 \u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u0442\u0435\u043B\u044F",
|
|
7320
|
+
path: path17.join(this.configDir, "CLAUDE.md"),
|
|
7321
|
+
deletable: false,
|
|
7322
|
+
creatable: true
|
|
7323
|
+
},
|
|
7324
|
+
{
|
|
7325
|
+
id: "project",
|
|
7326
|
+
scope: "project",
|
|
7327
|
+
label: "\u0418\u043D\u0441\u0442\u0440\u0443\u043A\u0446\u0438\u0438 \u043F\u0440\u043E\u0435\u043A\u0442\u0430",
|
|
7328
|
+
path: path17.join(this.cwd, "CLAUDE.md"),
|
|
7329
|
+
deletable: false,
|
|
7330
|
+
creatable: true
|
|
7331
|
+
},
|
|
7332
|
+
{
|
|
7333
|
+
id: "project-dotclaude",
|
|
7334
|
+
scope: "project",
|
|
7335
|
+
label: "\u0418\u043D\u0441\u0442\u0440\u0443\u043A\u0446\u0438\u0438 \u043F\u0440\u043E\u0435\u043A\u0442\u0430 (.claude)",
|
|
7336
|
+
path: path17.join(this.cwd, ".claude", "CLAUDE.md"),
|
|
7337
|
+
deletable: false,
|
|
7338
|
+
creatable: false
|
|
7339
|
+
},
|
|
7340
|
+
{
|
|
7341
|
+
id: "local",
|
|
7342
|
+
scope: "local",
|
|
7343
|
+
label: "\u041B\u0438\u0447\u043D\u044B\u0435 \u0438\u043D\u0441\u0442\u0440\u0443\u043A\u0446\u0438\u0438 \u043F\u0440\u043E\u0435\u043A\u0442\u0430",
|
|
7344
|
+
path: path17.join(this.cwd, "CLAUDE.local.md"),
|
|
7345
|
+
deletable: false,
|
|
7346
|
+
creatable: true
|
|
7347
|
+
}
|
|
7348
|
+
];
|
|
7349
|
+
let names2 = [];
|
|
7350
|
+
try {
|
|
7351
|
+
names2 = (await readdir4(this.memoryDir)).filter((n) => n.toLowerCase().endsWith(".md"));
|
|
7352
|
+
} catch {
|
|
7353
|
+
}
|
|
7354
|
+
if (!names2.includes(MEMORY_INDEX))
|
|
7355
|
+
names2.push(MEMORY_INDEX);
|
|
7356
|
+
names2.sort((a, b) => a === MEMORY_INDEX ? -1 : b === MEMORY_INDEX ? 1 : a.localeCompare(b));
|
|
7357
|
+
for (const name of names2) {
|
|
7358
|
+
entries.push({
|
|
7359
|
+
id: `memory:${name}`,
|
|
7360
|
+
scope: "memory",
|
|
7361
|
+
label: name,
|
|
7362
|
+
path: path17.join(this.memoryDir, name),
|
|
7363
|
+
deletable: true,
|
|
7364
|
+
creatable: name === MEMORY_INDEX
|
|
7365
|
+
});
|
|
7366
|
+
}
|
|
7367
|
+
return entries;
|
|
7368
|
+
}
|
|
7369
|
+
async list() {
|
|
7370
|
+
const files = [];
|
|
7371
|
+
for (const entry of await this.#entries()) {
|
|
7372
|
+
const info = await stat4(entry.path).catch(() => null);
|
|
7373
|
+
const exists4 = Boolean(info?.isFile());
|
|
7374
|
+
if (!exists4 && !entry.creatable)
|
|
7375
|
+
continue;
|
|
7376
|
+
files.push({
|
|
7377
|
+
id: entry.id,
|
|
7378
|
+
scope: entry.scope,
|
|
7379
|
+
label: entry.label,
|
|
7380
|
+
path: entry.path,
|
|
7381
|
+
exists: exists4,
|
|
7382
|
+
size: exists4 ? info.size : 0,
|
|
7383
|
+
mtime: exists4 ? Math.round(info.mtimeMs) : 0,
|
|
7384
|
+
deletable: entry.deletable && exists4
|
|
7385
|
+
});
|
|
7386
|
+
}
|
|
7387
|
+
return files;
|
|
7388
|
+
}
|
|
7389
|
+
async #find(id) {
|
|
7390
|
+
const entry = (await this.#entries()).find((e) => e.id === id);
|
|
7391
|
+
if (!entry)
|
|
7392
|
+
throw new Error("\u041D\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043D\u044B\u0439 \u0444\u0430\u0439\u043B \u043F\u0430\u043C\u044F\u0442\u0438");
|
|
7393
|
+
return entry;
|
|
7394
|
+
}
|
|
7395
|
+
async read(id) {
|
|
7396
|
+
const entry = await this.#find(id);
|
|
7397
|
+
const info = await stat4(entry.path).catch(() => null);
|
|
7398
|
+
if (!info?.isFile())
|
|
7399
|
+
return { content: "", mtime: 0 };
|
|
7400
|
+
if (info.size > MAX_SIZE)
|
|
7401
|
+
throw new Error("\u0424\u0430\u0439\u043B \u0441\u043B\u0438\u0448\u043A\u043E\u043C \u0432\u0435\u043B\u0438\u043A");
|
|
7402
|
+
return { content: await readFile8(entry.path, "utf8"), mtime: Math.round(info.mtimeMs) };
|
|
7403
|
+
}
|
|
7404
|
+
async write(id, content, baseMtime) {
|
|
7405
|
+
const entry = await this.#find(id);
|
|
7406
|
+
const info = await stat4(entry.path).catch(() => null);
|
|
7407
|
+
const current = info?.isFile() ? Math.round(info.mtimeMs) : 0;
|
|
7408
|
+
if (current !== baseMtime) {
|
|
7409
|
+
throw new ConflictError("\u0424\u0430\u0439\u043B \u0438\u0437\u043C\u0435\u043D\u0438\u043B\u0441\u044F, \u043F\u043E\u043A\u0430 \u0435\u0433\u043E \u043F\u0440\u0430\u0432\u0438\u043B\u0438");
|
|
7410
|
+
}
|
|
7411
|
+
if (Buffer.byteLength(content, "utf8") > MAX_SIZE)
|
|
7412
|
+
throw new Error("\u0424\u0430\u0439\u043B \u0441\u043B\u0438\u0448\u043A\u043E\u043C \u0432\u0435\u043B\u0438\u043A");
|
|
7413
|
+
await mkdir7(path17.dirname(entry.path), { recursive: true });
|
|
7414
|
+
await writeFile8(entry.path, content, "utf8");
|
|
7415
|
+
return Math.round((await stat4(entry.path)).mtimeMs);
|
|
7416
|
+
}
|
|
7417
|
+
async delete(id) {
|
|
7418
|
+
const entry = await this.#find(id);
|
|
7419
|
+
if (!entry.deletable)
|
|
7420
|
+
throw new Error("\u042D\u0442\u043E\u0442 \u0444\u0430\u0439\u043B \u043D\u0435\u043B\u044C\u0437\u044F \u0443\u0434\u0430\u043B\u0438\u0442\u044C \u0438\u0437 \u043E\u043A\u043D\u0430");
|
|
7421
|
+
await rm4(entry.path, { force: true });
|
|
7422
|
+
}
|
|
7423
|
+
};
|
|
7424
|
+
|
|
7425
|
+
// ../host/dist/scheduler.js
|
|
7426
|
+
import { mkdir as mkdir8, readFile as readFile9, writeFile as writeFile9 } from "node:fs/promises";
|
|
7427
|
+
import path18 from "node:path";
|
|
7428
|
+
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
7429
|
+
var MIN_INTERVAL_MINUTES = 15;
|
|
7430
|
+
var TICK_MS = 3e4;
|
|
7431
|
+
var Scheduler = class {
|
|
7432
|
+
hooks;
|
|
7433
|
+
#tasks = /* @__PURE__ */ new Map();
|
|
7434
|
+
#timer = null;
|
|
7435
|
+
#running = /* @__PURE__ */ new Set();
|
|
7436
|
+
#storePath;
|
|
7437
|
+
constructor(dataDir, hooks) {
|
|
7438
|
+
this.hooks = hooks;
|
|
7439
|
+
this.#storePath = path18.join(dataDir, "scheduled-tasks.json");
|
|
7440
|
+
}
|
|
7441
|
+
async load() {
|
|
7442
|
+
try {
|
|
7443
|
+
const parsed = JSON.parse(await readFile9(this.#storePath, "utf8"));
|
|
7444
|
+
const now = Date.now();
|
|
7445
|
+
for (const task of parsed.tasks ?? []) {
|
|
7446
|
+
if (!task || typeof task.id !== "string")
|
|
7447
|
+
continue;
|
|
7448
|
+
this.#tasks.set(task.id, { ...task, nextRunAt: nextRun(task, now) });
|
|
7449
|
+
}
|
|
7450
|
+
} catch {
|
|
7451
|
+
}
|
|
7452
|
+
}
|
|
7453
|
+
start() {
|
|
7454
|
+
this.stop();
|
|
7455
|
+
this.#timer = setInterval(() => void this.#tick(), TICK_MS);
|
|
7456
|
+
this.#timer.unref?.();
|
|
7457
|
+
}
|
|
7458
|
+
stop() {
|
|
7459
|
+
if (this.#timer)
|
|
7460
|
+
clearInterval(this.#timer);
|
|
7461
|
+
this.#timer = null;
|
|
7462
|
+
}
|
|
7463
|
+
list() {
|
|
7464
|
+
return [...this.#tasks.values()].sort((a, b) => a.createdAt - b.createdAt);
|
|
7465
|
+
}
|
|
7466
|
+
async save(input) {
|
|
7467
|
+
const clean = validate(input);
|
|
7468
|
+
if (!this.hooks.hasWorkspace(clean.workspaceId))
|
|
7469
|
+
throw new Error("\u041F\u0440\u043E\u0435\u043A\u0442 \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D");
|
|
7470
|
+
const previous = input.id ? this.#tasks.get(input.id) : void 0;
|
|
7471
|
+
if (input.id && !previous)
|
|
7472
|
+
throw new Error("\u0417\u0430\u0434\u0430\u0447\u0430 \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D\u0430");
|
|
7473
|
+
const task = {
|
|
7474
|
+
...clean,
|
|
7475
|
+
id: previous?.id ?? randomUUID6(),
|
|
7476
|
+
createdAt: previous?.createdAt ?? Date.now(),
|
|
7477
|
+
lastRunAt: previous?.lastRunAt ?? null,
|
|
7478
|
+
lastSessionId: previous?.lastSessionId ?? null,
|
|
7479
|
+
lastError: previous?.lastError ?? null,
|
|
7480
|
+
nextRunAt: null
|
|
7481
|
+
};
|
|
7482
|
+
task.nextRunAt = nextRun(task, Date.now());
|
|
7483
|
+
if (task.enabled && task.schedule.kind === "once" && task.nextRunAt === null) {
|
|
7484
|
+
throw new Error("\u0412\u0440\u0435\u043C\u044F \u0440\u0430\u0437\u043E\u0432\u043E\u0433\u043E \u0437\u0430\u043F\u0443\u0441\u043A\u0430 \u0443\u0436\u0435 \u043F\u0440\u043E\u0448\u043B\u043E");
|
|
7485
|
+
}
|
|
7486
|
+
this.#tasks.set(task.id, task);
|
|
7487
|
+
await this.#persist();
|
|
7488
|
+
return task;
|
|
7489
|
+
}
|
|
7490
|
+
async delete(id) {
|
|
7491
|
+
if (!this.#tasks.delete(id))
|
|
7492
|
+
return;
|
|
7493
|
+
await this.#persist();
|
|
7494
|
+
}
|
|
7495
|
+
/** Запустить вне расписания; следующий плановый запуск не сдвигается. */
|
|
7496
|
+
async runNow(id) {
|
|
7497
|
+
const task = this.#tasks.get(id);
|
|
7498
|
+
if (!task)
|
|
7499
|
+
throw new Error("\u0417\u0430\u0434\u0430\u0447\u0430 \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D\u0430");
|
|
7500
|
+
await this.#run(task, false);
|
|
7501
|
+
}
|
|
7502
|
+
/** Проект удалён — его задачи выключаются (не удаляются: их можно перенести). */
|
|
7503
|
+
async workspaceRemoved(workspaceId) {
|
|
7504
|
+
let touched = false;
|
|
7505
|
+
for (const task of this.#tasks.values()) {
|
|
7506
|
+
if (task.workspaceId !== workspaceId || !task.enabled)
|
|
7507
|
+
continue;
|
|
7508
|
+
task.enabled = false;
|
|
7509
|
+
task.nextRunAt = null;
|
|
7510
|
+
task.lastError = "\u041F\u0440\u043E\u0435\u043A\u0442 \u0437\u0430\u043A\u0440\u044B\u0442 \u2014 \u0437\u0430\u0434\u0430\u0447\u0430 \u0432\u044B\u043A\u043B\u044E\u0447\u0435\u043D\u0430";
|
|
7511
|
+
touched = true;
|
|
7512
|
+
}
|
|
7513
|
+
if (touched)
|
|
7514
|
+
await this.#persist();
|
|
5412
7515
|
}
|
|
5413
|
-
async #
|
|
5414
|
-
|
|
7516
|
+
async #tick() {
|
|
7517
|
+
const now = Date.now();
|
|
7518
|
+
for (const task of [...this.#tasks.values()]) {
|
|
7519
|
+
if (!task.enabled || task.nextRunAt === null || task.nextRunAt > now)
|
|
7520
|
+
continue;
|
|
7521
|
+
await this.#run(task, true);
|
|
7522
|
+
}
|
|
7523
|
+
}
|
|
7524
|
+
async #run(task, scheduled) {
|
|
7525
|
+
if (this.#running.has(task.id))
|
|
7526
|
+
return;
|
|
7527
|
+
this.#running.add(task.id);
|
|
7528
|
+
const now = Date.now();
|
|
5415
7529
|
try {
|
|
5416
|
-
|
|
5417
|
-
|
|
5418
|
-
|
|
5419
|
-
|
|
5420
|
-
Authorization: `Bearer ${token}`,
|
|
5421
|
-
"X-GitHub-Api-Version": API_VERSION,
|
|
5422
|
-
// GitHub отвечает 403 на запрос без User-Agent — это его требование,
|
|
5423
|
-
// а не вежливость.
|
|
5424
|
-
"User-Agent": "claude-code-visual",
|
|
5425
|
-
...init ? { "Content-Type": "application/json" } : {}
|
|
5426
|
-
},
|
|
5427
|
-
body: init ? JSON.stringify(init.body) : void 0,
|
|
5428
|
-
signal: AbortSignal.timeout(API_TIMEOUT_MS)
|
|
5429
|
-
});
|
|
7530
|
+
if (!this.hooks.hasWorkspace(task.workspaceId))
|
|
7531
|
+
throw new Error("\u041F\u0440\u043E\u0435\u043A\u0442 \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D");
|
|
7532
|
+
task.lastSessionId = await this.hooks.run(task);
|
|
7533
|
+
task.lastError = null;
|
|
5430
7534
|
} catch (error) {
|
|
5431
|
-
|
|
7535
|
+
task.lastError = error instanceof Error ? error.message : String(error);
|
|
7536
|
+
} finally {
|
|
7537
|
+
this.#running.delete(task.id);
|
|
5432
7538
|
}
|
|
5433
|
-
|
|
5434
|
-
if (
|
|
5435
|
-
|
|
5436
|
-
|
|
5437
|
-
|
|
5438
|
-
} catch {
|
|
5439
|
-
throw new Error(`GitHub \u043E\u0442\u0432\u0435\u0442\u0438\u043B \u043D\u0435 JSON (${response.status})`);
|
|
7539
|
+
task.lastRunAt = now;
|
|
7540
|
+
if (scheduled) {
|
|
7541
|
+
if (task.schedule.kind === "once")
|
|
7542
|
+
task.enabled = false;
|
|
7543
|
+
task.nextRunAt = nextRun(task, Date.now());
|
|
5440
7544
|
}
|
|
7545
|
+
await this.#persist();
|
|
5441
7546
|
}
|
|
5442
|
-
|
|
5443
|
-
|
|
5444
|
-
|
|
5445
|
-
|
|
5446
|
-
const token = await gh(["auth", "token"]).catch(() => "");
|
|
5447
|
-
return token.trim();
|
|
5448
|
-
}
|
|
5449
|
-
async #hasGh() {
|
|
5450
|
-
const version2 = await gh(["--version"]).catch(() => "");
|
|
5451
|
-
this.#ghInstalled = version2 !== "";
|
|
5452
|
-
return this.#ghInstalled;
|
|
7547
|
+
async #persist() {
|
|
7548
|
+
await mkdir8(path18.dirname(this.#storePath), { recursive: true });
|
|
7549
|
+
await writeFile9(this.#storePath, JSON.stringify({ tasks: this.list() }, null, 2), "utf8");
|
|
7550
|
+
this.hooks.changed(this.list());
|
|
5453
7551
|
}
|
|
5454
7552
|
};
|
|
5455
|
-
function
|
|
5456
|
-
|
|
5457
|
-
|
|
5458
|
-
|
|
5459
|
-
|
|
5460
|
-
|
|
5461
|
-
|
|
5462
|
-
|
|
7553
|
+
function validate(input) {
|
|
7554
|
+
const name = input.name?.trim();
|
|
7555
|
+
if (!name)
|
|
7556
|
+
throw new Error("\u0423\u043A\u0430\u0436\u0438\u0442\u0435 \u043D\u0430\u0437\u0432\u0430\u043D\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438");
|
|
7557
|
+
const prompt = input.prompt?.trim();
|
|
7558
|
+
if (!prompt)
|
|
7559
|
+
throw new Error("\u0423\u043A\u0430\u0436\u0438\u0442\u0435 \u043F\u0440\u043E\u043C\u043F\u0442");
|
|
7560
|
+
if (!input.workspaceId)
|
|
7561
|
+
throw new Error("\u0423\u043A\u0430\u0436\u0438\u0442\u0435 \u043F\u0440\u043E\u0435\u043A\u0442");
|
|
7562
|
+
const schedule = validateSchedule(input.schedule);
|
|
7563
|
+
return {
|
|
7564
|
+
name,
|
|
7565
|
+
workspaceId: input.workspaceId,
|
|
7566
|
+
prompt,
|
|
7567
|
+
schedule,
|
|
7568
|
+
enabled: input.enabled !== false,
|
|
7569
|
+
...input.permissionMode ? { permissionMode: input.permissionMode } : {},
|
|
7570
|
+
...input.model?.trim() ? { model: input.model.trim() } : {},
|
|
7571
|
+
...input.accountId ? { accountId: input.accountId } : {}
|
|
7572
|
+
};
|
|
5463
7573
|
}
|
|
5464
|
-
function
|
|
5465
|
-
|
|
5466
|
-
|
|
5467
|
-
|
|
5468
|
-
|
|
5469
|
-
|
|
5470
|
-
|
|
5471
|
-
|
|
7574
|
+
function validateSchedule(schedule) {
|
|
7575
|
+
switch (schedule?.kind) {
|
|
7576
|
+
case "once":
|
|
7577
|
+
if (!Number.isFinite(schedule.at))
|
|
7578
|
+
throw new Error("\u0423\u043A\u0430\u0436\u0438\u0442\u0435 \u0432\u0440\u0435\u043C\u044F \u0437\u0430\u043F\u0443\u0441\u043A\u0430");
|
|
7579
|
+
return { kind: "once", at: schedule.at };
|
|
7580
|
+
case "daily": {
|
|
7581
|
+
const match = /^(\d{1,2}):(\d{2})$/.exec(schedule.time ?? "");
|
|
7582
|
+
if (!match || Number(match[1]) > 23 || Number(match[2]) > 59)
|
|
7583
|
+
throw new Error("\u041D\u0435\u0432\u0435\u0440\u043D\u043E\u0435 \u0432\u0440\u0435\u043C\u044F");
|
|
7584
|
+
const days = [...new Set((schedule.days ?? []).filter((d) => Number.isInteger(d) && d >= 0 && d <= 6))].sort();
|
|
7585
|
+
if (days.length === 0)
|
|
7586
|
+
throw new Error("\u0412\u044B\u0431\u0435\u0440\u0438\u0442\u0435 \u0445\u043E\u0442\u044F \u0431\u044B \u043E\u0434\u0438\u043D \u0434\u0435\u043D\u044C");
|
|
7587
|
+
return { kind: "daily", time: `${match[1].padStart(2, "0")}:${match[2]}`, days };
|
|
7588
|
+
}
|
|
7589
|
+
case "interval": {
|
|
7590
|
+
const minutes = Math.round(schedule.minutes);
|
|
7591
|
+
if (!Number.isFinite(minutes) || minutes < MIN_INTERVAL_MINUTES) {
|
|
7592
|
+
throw new Error(`\u0418\u043D\u0442\u0435\u0440\u0432\u0430\u043B \u2014 \u043D\u0435 \u043C\u0435\u043D\u044C\u0448\u0435 ${MIN_INTERVAL_MINUTES} \u043C\u0438\u043D\u0443\u0442`);
|
|
7593
|
+
}
|
|
7594
|
+
return { kind: "interval", minutes };
|
|
5472
7595
|
}
|
|
5473
|
-
} catch {
|
|
5474
|
-
message = body.slice(0, 200).trim();
|
|
5475
|
-
}
|
|
5476
|
-
const text = [message, details].filter(Boolean).join(" \u2014 ");
|
|
5477
|
-
switch (status) {
|
|
5478
|
-
case 401:
|
|
5479
|
-
return "GitHub \u043E\u0442\u043A\u043B\u043E\u043D\u0438\u043B \u0442\u043E\u043A\u0435\u043D (401) \u2014 \u043E\u043D \u0438\u0441\u0442\u0451\u043A \u0438\u043B\u0438 \u043E\u0442\u043E\u0437\u0432\u0430\u043D";
|
|
5480
|
-
case 403:
|
|
5481
|
-
return `GitHub \u043E\u0442\u043A\u0430\u0437\u0430\u043B (403): ${text || "\u043D\u0435\u0442 \u043F\u0440\u0430\u0432 \u0438\u043B\u0438 \u043F\u0440\u0435\u0432\u044B\u0448\u0435\u043D \u043B\u0438\u043C\u0438\u0442 \u0437\u0430\u043F\u0440\u043E\u0441\u043E\u0432"}`;
|
|
5482
|
-
case 404:
|
|
5483
|
-
return `GitHub \u043E\u0442\u0432\u0435\u0442\u0438\u043B 404: ${text || "\u043D\u0435\u0442 \u0442\u0430\u043A\u043E\u0439 \u043E\u0440\u0433\u0430\u043D\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u043B\u0438 \u0443 \u0442\u043E\u043A\u0435\u043D\u0430 \u043D\u0435\u0442 \u043F\u0440\u0430\u0432 \u043D\u0430 \u043D\u0435\u0451"}`;
|
|
5484
|
-
case 422:
|
|
5485
|
-
return `GitHub \u043E\u0442\u043A\u0430\u0437\u0430\u043B\u0441\u044F \u0441\u043E\u0437\u0434\u0430\u0432\u0430\u0442\u044C: ${text || "\u0442\u0430\u043A\u043E\u0435 \u0438\u043C\u044F \u0443\u0436\u0435 \u0437\u0430\u043D\u044F\u0442\u043E"}`;
|
|
5486
7596
|
default:
|
|
5487
|
-
|
|
7597
|
+
throw new Error("\u041D\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043D\u044B\u0439 \u0432\u0438\u0434 \u0440\u0430\u0441\u043F\u0438\u0441\u0430\u043D\u0438\u044F");
|
|
5488
7598
|
}
|
|
5489
7599
|
}
|
|
5490
|
-
function
|
|
5491
|
-
|
|
5492
|
-
|
|
5493
|
-
|
|
5494
|
-
|
|
7600
|
+
function nextRun(task, now) {
|
|
7601
|
+
if (!task.enabled)
|
|
7602
|
+
return null;
|
|
7603
|
+
const schedule = task.schedule;
|
|
7604
|
+
switch (schedule.kind) {
|
|
7605
|
+
case "once":
|
|
7606
|
+
return schedule.at > now ? schedule.at : null;
|
|
7607
|
+
case "interval": {
|
|
7608
|
+
const step2 = schedule.minutes * 6e4;
|
|
7609
|
+
const base = task.lastRunAt ?? now;
|
|
7610
|
+
const next = base + step2;
|
|
7611
|
+
return next > now ? next : now + step2;
|
|
7612
|
+
}
|
|
7613
|
+
case "daily": {
|
|
7614
|
+
const [hours, minutes] = schedule.time.split(":").map(Number);
|
|
7615
|
+
const candidate = new Date(now);
|
|
7616
|
+
for (let i = 0; i < 8; i++) {
|
|
7617
|
+
candidate.setHours(hours, minutes, 0, 0);
|
|
7618
|
+
if (candidate.getTime() > now && schedule.days.includes(candidate.getDay())) {
|
|
7619
|
+
return candidate.getTime();
|
|
7620
|
+
}
|
|
7621
|
+
candidate.setDate(candidate.getDate() + 1);
|
|
7622
|
+
}
|
|
7623
|
+
return null;
|
|
7624
|
+
}
|
|
7625
|
+
}
|
|
5495
7626
|
}
|
|
5496
7627
|
|
|
5497
7628
|
// ../host/dist/finder.js
|
|
5498
|
-
import { existsSync as
|
|
5499
|
-
import { readdir as
|
|
7629
|
+
import { existsSync as existsSync3, statSync } from "node:fs";
|
|
7630
|
+
import { readdir as readdir5 } from "node:fs/promises";
|
|
5500
7631
|
import os2 from "node:os";
|
|
5501
|
-
import
|
|
7632
|
+
import path19 from "node:path";
|
|
5502
7633
|
import { listSessions } from "@anthropic-ai/claude-agent-sdk";
|
|
5503
7634
|
var CACHE_TTL = 6e4;
|
|
5504
7635
|
var FIND_LIMIT = 50;
|
|
@@ -5539,7 +7670,7 @@ var ProjectFinder = class {
|
|
|
5539
7670
|
if (needles.length === 0)
|
|
5540
7671
|
return { candidates: [], truncated: false };
|
|
5541
7672
|
const open = new Map(this.registry.list().map((workspace) => [workspace.path.toLowerCase(), workspace]));
|
|
5542
|
-
const byName = this.#dirs.filter((dir) => matches(
|
|
7673
|
+
const byName = this.#dirs.filter((dir) => matches(path19.basename(dir.path), needles));
|
|
5543
7674
|
const matched = byName.length > 0 ? byName : this.#dirs.filter((dir) => matches(dir.path, needles));
|
|
5544
7675
|
const sorted = [...matched].sort((a, b) => {
|
|
5545
7676
|
const aOpen = open.has(a.path.toLowerCase());
|
|
@@ -5550,7 +7681,7 @@ var ProjectFinder = class {
|
|
|
5550
7681
|
return a.sessions > 0 ? -1 : 1;
|
|
5551
7682
|
if (a.lastUsedAt !== b.lastUsedAt)
|
|
5552
7683
|
return b.lastUsedAt - a.lastUsedAt;
|
|
5553
|
-
return
|
|
7684
|
+
return path19.basename(a.path).localeCompare(path19.basename(b.path), void 0, {
|
|
5554
7685
|
numeric: true,
|
|
5555
7686
|
sensitivity: "base"
|
|
5556
7687
|
});
|
|
@@ -5558,7 +7689,7 @@ var ProjectFinder = class {
|
|
|
5558
7689
|
return {
|
|
5559
7690
|
candidates: sorted.slice(0, FIND_LIMIT).map((dir) => ({
|
|
5560
7691
|
path: dir.path,
|
|
5561
|
-
name:
|
|
7692
|
+
name: path19.basename(dir.path) || dir.path,
|
|
5562
7693
|
sessions: dir.sessions,
|
|
5563
7694
|
lastUsedAt: dir.lastUsedAt || null,
|
|
5564
7695
|
open: open.has(dir.path.toLowerCase()),
|
|
@@ -5582,7 +7713,7 @@ var ProjectFinder = class {
|
|
|
5582
7713
|
const candidates = [];
|
|
5583
7714
|
for (const entry of named) {
|
|
5584
7715
|
const absolute = entry.path.trim();
|
|
5585
|
-
if (!absolute || !
|
|
7716
|
+
if (!absolute || !path19.isAbsolute(absolute))
|
|
5586
7717
|
continue;
|
|
5587
7718
|
const key = absolute.toLowerCase();
|
|
5588
7719
|
if (seen.has(key))
|
|
@@ -5593,7 +7724,7 @@ var ProjectFinder = class {
|
|
|
5593
7724
|
const record = known.get(key);
|
|
5594
7725
|
candidates.push({
|
|
5595
7726
|
path: record?.path ?? absolute,
|
|
5596
|
-
name:
|
|
7727
|
+
name: path19.basename(absolute) || absolute,
|
|
5597
7728
|
sessions: record?.sessions ?? 0,
|
|
5598
7729
|
lastUsedAt: record?.lastUsedAt || null,
|
|
5599
7730
|
open: open.has(key),
|
|
@@ -5645,12 +7776,12 @@ var ProjectFinder = class {
|
|
|
5645
7776
|
dirs.set(key, { path: cwd, sessions: 1, lastUsedAt: info.lastModified });
|
|
5646
7777
|
}
|
|
5647
7778
|
for (const parent of this.#parents(dirs.values())) {
|
|
5648
|
-
const names2 = await
|
|
7779
|
+
const names2 = await readdir5(parent, { withFileTypes: true }).catch(() => []);
|
|
5649
7780
|
for (const dirent of names2) {
|
|
5650
7781
|
if (!dirent.isDirectory() || SKIP_NAMES.has(dirent.name) || dirent.name.startsWith(".")) {
|
|
5651
7782
|
continue;
|
|
5652
7783
|
}
|
|
5653
|
-
const full =
|
|
7784
|
+
const full = path19.join(parent, dirent.name);
|
|
5654
7785
|
const key = full.toLowerCase();
|
|
5655
7786
|
if (dirs.has(key))
|
|
5656
7787
|
continue;
|
|
@@ -5671,7 +7802,7 @@ var ProjectFinder = class {
|
|
|
5671
7802
|
#parents(dirs) {
|
|
5672
7803
|
const counted = /* @__PURE__ */ new Map();
|
|
5673
7804
|
for (const dir of dirs) {
|
|
5674
|
-
const parent =
|
|
7805
|
+
const parent = path19.dirname(dir.path);
|
|
5675
7806
|
if (parent === dir.path || !usable(parent))
|
|
5676
7807
|
continue;
|
|
5677
7808
|
const key = parent.toLowerCase();
|
|
@@ -5685,7 +7816,7 @@ var ProjectFinder = class {
|
|
|
5685
7816
|
}
|
|
5686
7817
|
};
|
|
5687
7818
|
function usable(dir) {
|
|
5688
|
-
return !contains(os2.tmpdir(), dir) &&
|
|
7819
|
+
return !contains(os2.tmpdir(), dir) && existsSync3(dir);
|
|
5689
7820
|
}
|
|
5690
7821
|
function tokens(query3) {
|
|
5691
7822
|
return query3.toLowerCase().split(/[^a-z0-9а-яё]+/i).filter(Boolean);
|
|
@@ -5785,19 +7916,19 @@ function fromText(text) {
|
|
|
5785
7916
|
}
|
|
5786
7917
|
|
|
5787
7918
|
// ../host/dist/workspaces.js
|
|
5788
|
-
import { existsSync as
|
|
5789
|
-
import { mkdir as
|
|
5790
|
-
import
|
|
7919
|
+
import { existsSync as existsSync4, statSync as statSync2 } from "node:fs";
|
|
7920
|
+
import { mkdir as mkdir9, readFile as readFile10, writeFile as writeFile10 } from "node:fs/promises";
|
|
7921
|
+
import path20 from "node:path";
|
|
5791
7922
|
import { listSessions as listSessions2 } from "@anthropic-ai/claude-agent-sdk";
|
|
5792
7923
|
var WorkspaceRegistry = class {
|
|
5793
7924
|
#entries = [];
|
|
5794
7925
|
#storePath;
|
|
5795
7926
|
constructor(dataDir) {
|
|
5796
|
-
this.#storePath =
|
|
7927
|
+
this.#storePath = path20.join(dataDir, "workspaces.json");
|
|
5797
7928
|
}
|
|
5798
7929
|
async load() {
|
|
5799
7930
|
try {
|
|
5800
|
-
const raw = await
|
|
7931
|
+
const raw = await readFile10(this.#storePath, "utf8");
|
|
5801
7932
|
const parsed = JSON.parse(raw);
|
|
5802
7933
|
if (!Array.isArray(parsed)) {
|
|
5803
7934
|
this.#entries = [];
|
|
@@ -5809,15 +7940,15 @@ var WorkspaceRegistry = class {
|
|
|
5809
7940
|
if (isEntry(item))
|
|
5810
7941
|
return item;
|
|
5811
7942
|
return null;
|
|
5812
|
-
}).filter((e) => e !== null &&
|
|
7943
|
+
}).filter((e) => e !== null && existsSync4(e.path));
|
|
5813
7944
|
this.#entries = collapseDuplicates(this.#entries);
|
|
5814
7945
|
} catch {
|
|
5815
7946
|
this.#entries = [];
|
|
5816
7947
|
}
|
|
5817
7948
|
}
|
|
5818
7949
|
async #persist() {
|
|
5819
|
-
await
|
|
5820
|
-
await
|
|
7950
|
+
await mkdir9(path20.dirname(this.#storePath), { recursive: true });
|
|
7951
|
+
await writeFile10(this.#storePath, JSON.stringify(this.#entries, null, 2), "utf8");
|
|
5821
7952
|
}
|
|
5822
7953
|
/**
|
|
5823
7954
|
* Каталог `from` переехал в `to` — записи проектов внутри него следуют за
|
|
@@ -5828,7 +7959,7 @@ var WorkspaceRegistry = class {
|
|
|
5828
7959
|
for (const entry of this.#entries) {
|
|
5829
7960
|
if (!isUnder(from, entry.path))
|
|
5830
7961
|
continue;
|
|
5831
|
-
const next =
|
|
7962
|
+
const next = path20.join(to, path20.relative(from, entry.path));
|
|
5832
7963
|
moved.push({ from: entry.path, to: next });
|
|
5833
7964
|
entry.path = next;
|
|
5834
7965
|
}
|
|
@@ -5857,8 +7988,8 @@ var WorkspaceRegistry = class {
|
|
|
5857
7988
|
return entry ? toInfo(entry) : void 0;
|
|
5858
7989
|
}
|
|
5859
7990
|
async open(rawPath) {
|
|
5860
|
-
const absolute =
|
|
5861
|
-
if (!
|
|
7991
|
+
const absolute = path20.resolve(rawPath);
|
|
7992
|
+
if (!existsSync4(absolute)) {
|
|
5862
7993
|
throw new Error(`\u041A\u0430\u0442\u0430\u043B\u043E\u0433 \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D: ${absolute}`);
|
|
5863
7994
|
}
|
|
5864
7995
|
const id = workspaceIdFromPath(absolute);
|
|
@@ -5937,24 +8068,24 @@ var WorkspaceRegistry = class {
|
|
|
5937
8068
|
async create(parentRaw, nameRaw, init) {
|
|
5938
8069
|
const name = nameRaw.trim();
|
|
5939
8070
|
requireName(name);
|
|
5940
|
-
const parent =
|
|
5941
|
-
if (!
|
|
8071
|
+
const parent = path20.resolve(parentRaw.trim());
|
|
8072
|
+
if (!existsSync4(parent)) {
|
|
5942
8073
|
throw new Error(`\u041A\u0430\u0442\u0430\u043B\u043E\u0433 \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D: ${parent}`);
|
|
5943
8074
|
}
|
|
5944
8075
|
if (!statSync2(parent).isDirectory()) {
|
|
5945
8076
|
throw new Error(`\u042D\u0442\u043E \u043D\u0435 \u043A\u0430\u0442\u0430\u043B\u043E\u0433: ${parent}`);
|
|
5946
8077
|
}
|
|
5947
|
-
const target =
|
|
5948
|
-
if (
|
|
8078
|
+
const target = path20.join(parent, name);
|
|
8079
|
+
if (existsSync4(target)) {
|
|
5949
8080
|
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`);
|
|
5950
8081
|
}
|
|
5951
|
-
await
|
|
8082
|
+
await mkdir9(target);
|
|
5952
8083
|
const warnings = [];
|
|
5953
8084
|
if (init.claudeMd) {
|
|
5954
|
-
await step(warnings, "CLAUDE.md", () =>
|
|
8085
|
+
await step(warnings, "CLAUDE.md", () => writeFile10(path20.join(target, "CLAUDE.md"), claudeMdStub(name), "utf8"));
|
|
5955
8086
|
}
|
|
5956
8087
|
if (init.readme) {
|
|
5957
|
-
await step(warnings, "README.md", () =>
|
|
8088
|
+
await step(warnings, "README.md", () => writeFile10(path20.join(target, "README.md"), readmeStub(name), "utf8"));
|
|
5958
8089
|
}
|
|
5959
8090
|
if (init.git) {
|
|
5960
8091
|
await step(warnings, "git init", () => new GitRepo(target).init());
|
|
@@ -6039,8 +8170,8 @@ function toInfo(entry) {
|
|
|
6039
8170
|
return {
|
|
6040
8171
|
id: workspaceIdFromPath(absolute),
|
|
6041
8172
|
path: absolute,
|
|
6042
|
-
name:
|
|
6043
|
-
hasClaudeMd:
|
|
8173
|
+
name: path20.basename(absolute) || absolute,
|
|
8174
|
+
hasClaudeMd: existsSync4(path20.join(absolute, "CLAUDE.md")),
|
|
6044
8175
|
...archivedAt ? { archivedAt } : {}
|
|
6045
8176
|
};
|
|
6046
8177
|
}
|
|
@@ -6060,27 +8191,27 @@ function collapseDuplicates(entries) {
|
|
|
6060
8191
|
return [...byId.values()];
|
|
6061
8192
|
}
|
|
6062
8193
|
function isUnder(parent, child) {
|
|
6063
|
-
const norm = (value) =>
|
|
8194
|
+
const norm = (value) => path20.resolve(value).replace(/[\\/]+$/, "").toLowerCase();
|
|
6064
8195
|
const p = norm(parent);
|
|
6065
8196
|
const c = norm(child);
|
|
6066
|
-
return c === p || c.startsWith(`${p}${
|
|
8197
|
+
return c === p || c.startsWith(`${p}${path20.sep}`.toLowerCase()) || c.startsWith(`${p}/`);
|
|
6067
8198
|
}
|
|
6068
8199
|
|
|
6069
8200
|
// ../host/dist/archive.js
|
|
6070
|
-
import { mkdir as
|
|
6071
|
-
import
|
|
8201
|
+
import { mkdir as mkdir10, readFile as readFile11, writeFile as writeFile11 } from "node:fs/promises";
|
|
8202
|
+
import path21 from "node:path";
|
|
6072
8203
|
var SessionArchive = class {
|
|
6073
8204
|
#archived = /* @__PURE__ */ new Map();
|
|
6074
8205
|
#restored = /* @__PURE__ */ new Map();
|
|
6075
8206
|
#storePath;
|
|
6076
8207
|
constructor(dataDir) {
|
|
6077
|
-
this.#storePath =
|
|
8208
|
+
this.#storePath = path21.join(dataDir, "session-archive.json");
|
|
6078
8209
|
}
|
|
6079
8210
|
async load() {
|
|
6080
8211
|
try {
|
|
6081
|
-
const raw = await
|
|
8212
|
+
const raw = await readFile11(this.#storePath, "utf8");
|
|
6082
8213
|
const parsed = JSON.parse(raw);
|
|
6083
|
-
this.#archived = new Map(Object.entries(parsed.archived ?? {}).filter(([, r]) =>
|
|
8214
|
+
this.#archived = new Map(Object.entries(parsed.archived ?? {}).filter(([, r]) => isRecord2(r)));
|
|
6084
8215
|
this.#restored = new Map(Object.entries(parsed.restored ?? {}).filter((entry) => typeof entry[1] === "number"));
|
|
6085
8216
|
} catch {
|
|
6086
8217
|
this.#archived = /* @__PURE__ */ new Map();
|
|
@@ -6186,17 +8317,17 @@ var SessionArchive = class {
|
|
|
6186
8317
|
archived: Object.fromEntries(this.#archived),
|
|
6187
8318
|
restored: Object.fromEntries(this.#restored)
|
|
6188
8319
|
};
|
|
6189
|
-
await
|
|
6190
|
-
await
|
|
8320
|
+
await mkdir10(path21.dirname(this.#storePath), { recursive: true });
|
|
8321
|
+
await writeFile11(this.#storePath, JSON.stringify(file, null, 2), "utf8");
|
|
6191
8322
|
}
|
|
6192
8323
|
};
|
|
6193
|
-
function
|
|
8324
|
+
function isRecord2(value) {
|
|
6194
8325
|
return typeof value === "object" && value !== null && typeof value.workspaceId === "string" && typeof value.at === "number";
|
|
6195
8326
|
}
|
|
6196
8327
|
|
|
6197
8328
|
// ../host/dist/pins.js
|
|
6198
|
-
import { mkdir as
|
|
6199
|
-
import
|
|
8329
|
+
import { mkdir as mkdir11, readFile as readFile12, writeFile as writeFile12 } from "node:fs/promises";
|
|
8330
|
+
import path22 from "node:path";
|
|
6200
8331
|
var SessionPins = class {
|
|
6201
8332
|
#pinned = /* @__PURE__ */ new Map();
|
|
6202
8333
|
/**
|
|
@@ -6211,13 +8342,13 @@ var SessionPins = class {
|
|
|
6211
8342
|
#moved = /* @__PURE__ */ new Map();
|
|
6212
8343
|
#storePath;
|
|
6213
8344
|
constructor(dataDir) {
|
|
6214
|
-
this.#storePath =
|
|
8345
|
+
this.#storePath = path22.join(dataDir, "session-pins.json");
|
|
6215
8346
|
}
|
|
6216
8347
|
async load() {
|
|
6217
8348
|
try {
|
|
6218
|
-
const raw = await
|
|
8349
|
+
const raw = await readFile12(this.#storePath, "utf8");
|
|
6219
8350
|
const parsed = JSON.parse(raw);
|
|
6220
|
-
this.#pinned = new Map(Object.entries(parsed.pinned ?? {}).filter(([, r]) =>
|
|
8351
|
+
this.#pinned = new Map(Object.entries(parsed.pinned ?? {}).filter(([, r]) => isRecord3(r)));
|
|
6221
8352
|
this.#moved = new Map(Object.entries(parsed.moved ?? {}).filter(([, to]) => typeof to === "string"));
|
|
6222
8353
|
} catch {
|
|
6223
8354
|
this.#pinned = /* @__PURE__ */ new Map();
|
|
@@ -6368,26 +8499,26 @@ var SessionPins = class {
|
|
|
6368
8499
|
pinned: Object.fromEntries(this.#pinned),
|
|
6369
8500
|
...this.#moved.size > 0 ? { moved: Object.fromEntries(this.#moved) } : {}
|
|
6370
8501
|
};
|
|
6371
|
-
await
|
|
6372
|
-
await
|
|
8502
|
+
await mkdir11(path22.dirname(this.#storePath), { recursive: true });
|
|
8503
|
+
await writeFile12(this.#storePath, JSON.stringify(file, null, 2), "utf8");
|
|
6373
8504
|
}
|
|
6374
8505
|
};
|
|
6375
|
-
function
|
|
8506
|
+
function isRecord3(value) {
|
|
6376
8507
|
return typeof value === "object" && value !== null && typeof value.workspaceId === "string" && typeof value.at === "number";
|
|
6377
8508
|
}
|
|
6378
8509
|
|
|
6379
8510
|
// ../host/dist/order.js
|
|
6380
|
-
import { mkdir as
|
|
6381
|
-
import
|
|
8511
|
+
import { mkdir as mkdir12, readFile as readFile13, writeFile as writeFile13 } from "node:fs/promises";
|
|
8512
|
+
import path23 from "node:path";
|
|
6382
8513
|
var ListOrderStore = class {
|
|
6383
8514
|
#order = emptyOrder();
|
|
6384
8515
|
#storePath;
|
|
6385
8516
|
constructor(dataDir) {
|
|
6386
|
-
this.#storePath =
|
|
8517
|
+
this.#storePath = path23.join(dataDir, "list-order.json");
|
|
6387
8518
|
}
|
|
6388
8519
|
async load() {
|
|
6389
8520
|
try {
|
|
6390
|
-
const raw = await
|
|
8521
|
+
const raw = await readFile13(this.#storePath, "utf8");
|
|
6391
8522
|
this.#order = sanitize(JSON.parse(raw));
|
|
6392
8523
|
} catch {
|
|
6393
8524
|
this.#order = emptyOrder();
|
|
@@ -6459,8 +8590,8 @@ var ListOrderStore = class {
|
|
|
6459
8590
|
return changed;
|
|
6460
8591
|
}
|
|
6461
8592
|
async #persist() {
|
|
6462
|
-
await
|
|
6463
|
-
await
|
|
8593
|
+
await mkdir12(path23.dirname(this.#storePath), { recursive: true });
|
|
8594
|
+
await writeFile13(this.#storePath, JSON.stringify(this.#order, null, 2), "utf8");
|
|
6464
8595
|
}
|
|
6465
8596
|
};
|
|
6466
8597
|
function emptyOrder() {
|
|
@@ -6489,9 +8620,9 @@ function sanitize(value) {
|
|
|
6489
8620
|
}
|
|
6490
8621
|
|
|
6491
8622
|
// ../host/dist/folders.js
|
|
6492
|
-
import { mkdir as
|
|
6493
|
-
import
|
|
6494
|
-
import { randomUUID as
|
|
8623
|
+
import { mkdir as mkdir13, readFile as readFile14, writeFile as writeFile14 } from "node:fs/promises";
|
|
8624
|
+
import path24 from "node:path";
|
|
8625
|
+
import { randomUUID as randomUUID7 } from "node:crypto";
|
|
6495
8626
|
var COLOR_PATTERN = /^#[0-9a-f]{6}$/i;
|
|
6496
8627
|
var Folders = class {
|
|
6497
8628
|
#workspaceFolders = /* @__PURE__ */ new Map();
|
|
@@ -6502,11 +8633,11 @@ var Folders = class {
|
|
|
6502
8633
|
#pinnedAssignments = /* @__PURE__ */ new Map();
|
|
6503
8634
|
#storePath;
|
|
6504
8635
|
constructor(dataDir) {
|
|
6505
|
-
this.#storePath =
|
|
8636
|
+
this.#storePath = path24.join(dataDir, "folders.json");
|
|
6506
8637
|
}
|
|
6507
8638
|
async load() {
|
|
6508
8639
|
try {
|
|
6509
|
-
const raw = await
|
|
8640
|
+
const raw = await readFile14(this.#storePath, "utf8");
|
|
6510
8641
|
const parsed = JSON.parse(raw);
|
|
6511
8642
|
this.#workspaceFolders = new Map(Object.entries(parsed.workspaceFolders ?? {}).filter(([, r]) => isWorkspaceFolder(r)).map(([id, r]) => [id, withValidColor(r)]));
|
|
6512
8643
|
this.#sessionFolders = new Map(Object.entries(parsed.sessionFolders ?? {}).filter(([, r]) => isSessionFolder(r)).map(([id, r]) => [id, withValidColor(r)]));
|
|
@@ -6632,19 +8763,19 @@ var Folders = class {
|
|
|
6632
8763
|
};
|
|
6633
8764
|
}
|
|
6634
8765
|
async createWorkspaceFolder(name) {
|
|
6635
|
-
const id =
|
|
8766
|
+
const id = randomUUID7();
|
|
6636
8767
|
this.#workspaceFolders.set(id, { name });
|
|
6637
8768
|
await this.#persist();
|
|
6638
8769
|
return id;
|
|
6639
8770
|
}
|
|
6640
8771
|
async createSessionFolder(workspaceId, name) {
|
|
6641
|
-
const id =
|
|
8772
|
+
const id = randomUUID7();
|
|
6642
8773
|
this.#sessionFolders.set(id, { name, workspaceId });
|
|
6643
8774
|
await this.#persist();
|
|
6644
8775
|
return id;
|
|
6645
8776
|
}
|
|
6646
8777
|
async createPinnedFolder(name) {
|
|
6647
|
-
const id =
|
|
8778
|
+
const id = randomUUID7();
|
|
6648
8779
|
this.#pinnedFolders.set(id, { name });
|
|
6649
8780
|
await this.#persist();
|
|
6650
8781
|
return id;
|
|
@@ -6824,8 +8955,8 @@ var Folders = class {
|
|
|
6824
8955
|
sessionAssignments: Object.fromEntries(this.#sessionAssignments),
|
|
6825
8956
|
pinnedAssignments: Object.fromEntries(this.#pinnedAssignments)
|
|
6826
8957
|
};
|
|
6827
|
-
await
|
|
6828
|
-
await
|
|
8958
|
+
await mkdir13(path24.dirname(this.#storePath), { recursive: true });
|
|
8959
|
+
await writeFile14(this.#storePath, JSON.stringify(file, null, 2), "utf8");
|
|
6829
8960
|
}
|
|
6830
8961
|
};
|
|
6831
8962
|
function withValidColor(record) {
|
|
@@ -6846,30 +8977,30 @@ function isPinnedFolder(value) {
|
|
|
6846
8977
|
}
|
|
6847
8978
|
|
|
6848
8979
|
// ../host/dist/project-folders.js
|
|
6849
|
-
import { existsSync as
|
|
6850
|
-
import { mkdir as
|
|
6851
|
-
import
|
|
8980
|
+
import { existsSync as existsSync6, watch } from "node:fs";
|
|
8981
|
+
import { mkdir as mkdir14, readdir as readdir7, rmdir } from "node:fs/promises";
|
|
8982
|
+
import path26 from "node:path";
|
|
6852
8983
|
|
|
6853
8984
|
// ../host/dist/project-move.js
|
|
6854
|
-
import { existsSync as
|
|
6855
|
-
import { readFile as
|
|
6856
|
-
import { homedir as
|
|
6857
|
-
import
|
|
8985
|
+
import { existsSync as existsSync5 } from "node:fs";
|
|
8986
|
+
import { readFile as readFile15, readdir as readdir6, rename as rename2, stat as stat5 } from "node:fs/promises";
|
|
8987
|
+
import { homedir as homedir6 } from "node:os";
|
|
8988
|
+
import path25 from "node:path";
|
|
6858
8989
|
var ACTIVE_WINDOW_MS = 2 * 6e4;
|
|
6859
8990
|
function transcriptDirName(cwd) {
|
|
6860
8991
|
return cwd.replace(/[^a-zA-Z0-9]/g, "-");
|
|
6861
8992
|
}
|
|
6862
8993
|
function isInside(parent, child) {
|
|
6863
|
-
const norm = (value) =>
|
|
8994
|
+
const norm = (value) => path25.resolve(value).replace(/[\\/]+$/, "").toLowerCase();
|
|
6864
8995
|
const p = norm(parent);
|
|
6865
8996
|
const c = norm(child);
|
|
6866
|
-
return c === p || c.startsWith(p +
|
|
8997
|
+
return c === p || c.startsWith(p + path25.sep.toLowerCase()) || c.startsWith(`${p}/`);
|
|
6867
8998
|
}
|
|
6868
8999
|
async function externalAgentActivity(dirs, configDirs, now = Date.now()) {
|
|
6869
9000
|
for (const dir of dirs) {
|
|
6870
9001
|
const name = transcriptDirName(dir);
|
|
6871
9002
|
for (const config of configDirs) {
|
|
6872
|
-
const t = await newestMtime(
|
|
9003
|
+
const t = await newestMtime(path25.join(config, "projects", name), 1);
|
|
6873
9004
|
if (t !== null && now - t < ACTIVE_WINDOW_MS)
|
|
6874
9005
|
return "Claude Code";
|
|
6875
9006
|
}
|
|
@@ -6882,13 +9013,13 @@ async function newestMtime(dir, depth) {
|
|
|
6882
9013
|
let newest = null;
|
|
6883
9014
|
let entries;
|
|
6884
9015
|
try {
|
|
6885
|
-
entries = await
|
|
9016
|
+
entries = await readdir6(dir);
|
|
6886
9017
|
} catch {
|
|
6887
9018
|
return null;
|
|
6888
9019
|
}
|
|
6889
9020
|
for (const entry of entries) {
|
|
6890
|
-
const file =
|
|
6891
|
-
const info = await
|
|
9021
|
+
const file = path25.join(dir, entry);
|
|
9022
|
+
const info = await stat5(file).catch(() => null);
|
|
6892
9023
|
if (!info)
|
|
6893
9024
|
continue;
|
|
6894
9025
|
if (info.isDirectory()) {
|
|
@@ -6905,22 +9036,22 @@ async function newestMtime(dir, depth) {
|
|
|
6905
9036
|
return newest;
|
|
6906
9037
|
}
|
|
6907
9038
|
async function codexActive(dirs, now) {
|
|
6908
|
-
const root =
|
|
9039
|
+
const root = path25.join(process.env.CODEX_HOME?.trim() || path25.join(homedir6(), ".codex"), "sessions");
|
|
6909
9040
|
const days = /* @__PURE__ */ new Set();
|
|
6910
9041
|
for (const offset of [0, 1]) {
|
|
6911
9042
|
const d = new Date(now - offset * 864e5);
|
|
6912
|
-
days.add(
|
|
9043
|
+
days.add(path25.join(root, String(d.getFullYear()), String(d.getMonth() + 1).padStart(2, "0"), String(d.getDate()).padStart(2, "0")));
|
|
6913
9044
|
}
|
|
6914
9045
|
for (const day of days) {
|
|
6915
|
-
const files = await
|
|
9046
|
+
const files = await readdir6(day).catch(() => []);
|
|
6916
9047
|
for (const name of files) {
|
|
6917
9048
|
if (!name.endsWith(".jsonl"))
|
|
6918
9049
|
continue;
|
|
6919
|
-
const file =
|
|
6920
|
-
const info = await
|
|
9050
|
+
const file = path25.join(day, name);
|
|
9051
|
+
const info = await stat5(file).catch(() => null);
|
|
6921
9052
|
if (!info || now - info.mtimeMs >= ACTIVE_WINDOW_MS)
|
|
6922
9053
|
continue;
|
|
6923
|
-
const head = (await
|
|
9054
|
+
const head = (await readFile15(file, "utf8").catch(() => "")).slice(0, 4e3);
|
|
6924
9055
|
const text = head.replace(/\\\\/g, "\\").toLowerCase();
|
|
6925
9056
|
if (dirs.some((dir) => text.includes(dir.toLowerCase()) || head.includes(dir.replace(/\\/g, "\\\\")))) {
|
|
6926
9057
|
return true;
|
|
@@ -6937,19 +9068,19 @@ function busyMessage(error) {
|
|
|
6937
9068
|
return null;
|
|
6938
9069
|
}
|
|
6939
9070
|
async function moveDirectory(from, to, projects, configDirs) {
|
|
6940
|
-
if (
|
|
9071
|
+
if (existsSync5(to))
|
|
6941
9072
|
throw new Error(`\u0423\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442: ${to}`);
|
|
6942
9073
|
if (isInside(from, to))
|
|
6943
9074
|
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");
|
|
6944
9075
|
const transcripts = [];
|
|
6945
9076
|
for (const project of projects) {
|
|
6946
|
-
const next =
|
|
9077
|
+
const next = path25.join(to, path25.relative(from, project));
|
|
6947
9078
|
for (const config of configDirs) {
|
|
6948
|
-
const source =
|
|
6949
|
-
const target =
|
|
6950
|
-
if (!
|
|
9079
|
+
const source = path25.join(config, "projects", transcriptDirName(project));
|
|
9080
|
+
const target = path25.join(config, "projects", transcriptDirName(next));
|
|
9081
|
+
if (!existsSync5(source))
|
|
6951
9082
|
continue;
|
|
6952
|
-
if (
|
|
9083
|
+
if (existsSync5(target)) {
|
|
6953
9084
|
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}`);
|
|
6954
9085
|
}
|
|
6955
9086
|
transcripts.push({ from: source, to: target });
|
|
@@ -6997,45 +9128,45 @@ function cleanFolderName(raw) {
|
|
|
6997
9128
|
return name;
|
|
6998
9129
|
}
|
|
6999
9130
|
async function listDiskFolders(root, projectPaths) {
|
|
7000
|
-
const projects = new Set(projectPaths.map((p) =>
|
|
7001
|
-
const entries = await
|
|
9131
|
+
const projects = new Set(projectPaths.map((p) => path26.resolve(p).toLowerCase()));
|
|
9132
|
+
const entries = await readdir7(root, { withFileTypes: true }).catch(() => []);
|
|
7002
9133
|
const names2 = [];
|
|
7003
9134
|
for (const entry of entries) {
|
|
7004
9135
|
if (!entry.isDirectory() || entry.name.startsWith(".") || SKIP.has(entry.name.toLowerCase()))
|
|
7005
9136
|
continue;
|
|
7006
|
-
const dir =
|
|
7007
|
-
if (projects.has(
|
|
9137
|
+
const dir = path26.join(root, entry.name);
|
|
9138
|
+
if (projects.has(path26.resolve(dir).toLowerCase()))
|
|
7008
9139
|
continue;
|
|
7009
|
-
if (
|
|
9140
|
+
if (existsSync6(path26.join(dir, ".git")))
|
|
7010
9141
|
continue;
|
|
7011
9142
|
names2.push(entry.name);
|
|
7012
9143
|
}
|
|
7013
9144
|
return names2.sort((a, b) => a.localeCompare(b));
|
|
7014
9145
|
}
|
|
7015
9146
|
async function listUnopened(dir, projectPaths, limit = 200) {
|
|
7016
|
-
const projects = new Set(projectPaths.map((p) =>
|
|
7017
|
-
const entries = await
|
|
7018
|
-
return entries.filter((e) => e.isDirectory() && !e.name.startsWith(".") && !SKIP.has(e.name.toLowerCase())).map((e) => ({ name: e.name, path:
|
|
9147
|
+
const projects = new Set(projectPaths.map((p) => path26.resolve(p).toLowerCase()));
|
|
9148
|
+
const entries = await readdir7(dir, { withFileTypes: true }).catch(() => []);
|
|
9149
|
+
return entries.filter((e) => e.isDirectory() && !e.name.startsWith(".") && !SKIP.has(e.name.toLowerCase())).map((e) => ({ name: e.name, path: path26.join(dir, e.name) })).filter((e) => !projects.has(path26.resolve(e.path).toLowerCase())).sort((a, b) => a.name.localeCompare(b.name)).slice(0, limit);
|
|
7019
9150
|
}
|
|
7020
9151
|
function folderOfProject(root, projectPath, folders) {
|
|
7021
|
-
const parent =
|
|
7022
|
-
if (
|
|
9152
|
+
const parent = path26.dirname(path26.resolve(projectPath));
|
|
9153
|
+
if (path26.resolve(path26.dirname(parent)).toLowerCase() !== path26.resolve(root).toLowerCase())
|
|
7023
9154
|
return null;
|
|
7024
|
-
const name =
|
|
9155
|
+
const name = path26.basename(parent);
|
|
7025
9156
|
return folders.has(name) ? folderIdFor(name) : null;
|
|
7026
9157
|
}
|
|
7027
9158
|
async function createDiskFolder(root, rawName) {
|
|
7028
9159
|
const name = cleanFolderName(rawName);
|
|
7029
|
-
const dir =
|
|
7030
|
-
if (
|
|
9160
|
+
const dir = path26.join(root, name);
|
|
9161
|
+
if (existsSync6(dir))
|
|
7031
9162
|
throw new Error(`\u0423\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442: ${dir}`);
|
|
7032
|
-
await
|
|
9163
|
+
await mkdir14(dir, { recursive: true });
|
|
7033
9164
|
return name;
|
|
7034
9165
|
}
|
|
7035
9166
|
async function foreignContent(dir, projectPaths) {
|
|
7036
|
-
const projects = new Set(projectPaths.map((p) =>
|
|
7037
|
-
for (const entry of await
|
|
7038
|
-
if (!projects.has(
|
|
9167
|
+
const projects = new Set(projectPaths.map((p) => path26.resolve(p).toLowerCase()));
|
|
9168
|
+
for (const entry of await readdir7(dir).catch(() => [])) {
|
|
9169
|
+
if (!projects.has(path26.resolve(path26.join(dir, entry)).toLowerCase()))
|
|
7039
9170
|
return entry;
|
|
7040
9171
|
}
|
|
7041
9172
|
return null;
|
|
@@ -7061,9 +9192,9 @@ function watchRoot(root, onChange) {
|
|
|
7061
9192
|
}
|
|
7062
9193
|
|
|
7063
9194
|
// ../host/dist/app-settings.js
|
|
7064
|
-
import { mkdir as
|
|
7065
|
-
import { homedir as
|
|
7066
|
-
import
|
|
9195
|
+
import { mkdir as mkdir15, readFile as readFile16, writeFile as writeFile15 } from "node:fs/promises";
|
|
9196
|
+
import { homedir as homedir7 } from "node:os";
|
|
9197
|
+
import path27 from "node:path";
|
|
7067
9198
|
var DEFAULT_AUTO_ARCHIVE_AFTER_MS = 2 * 24 * 60 * 60 * 1e3;
|
|
7068
9199
|
var MIN_AUTO_ARCHIVE_AFTER_MS = 60 * 60 * 1e3;
|
|
7069
9200
|
var DEFAULT_AUTO_STOP_AFTER_MS = 10 * 60 * 1e3;
|
|
@@ -7071,7 +9202,7 @@ var MIN_AUTO_STOP_AFTER_MS = 60 * 1e3;
|
|
|
7071
9202
|
var MIN_AUTO_SAVE_AFTER_PAUSE_MS = 500;
|
|
7072
9203
|
var DEFAULT_BLOCKED_COUNTRIES = ["RU", "BY", "CN", "IR", "KP", "SY", "CU"];
|
|
7073
9204
|
var FOLDER_ACCESS = ["all", "projects", "project"];
|
|
7074
|
-
var PROVIDERS = ["claude", "antigravity"];
|
|
9205
|
+
var PROVIDERS = ["claude", "antigravity", "codex"];
|
|
7075
9206
|
var PERMISSION_MODES = [
|
|
7076
9207
|
"default",
|
|
7077
9208
|
"acceptEdits",
|
|
@@ -7109,7 +9240,7 @@ var DEFAULT_APP_SETTINGS = {
|
|
|
7109
9240
|
limitStopFiveHourPct: 95,
|
|
7110
9241
|
limitStopSevenDayPct: 99,
|
|
7111
9242
|
// Оба: до появления настройки приложение предлагало обоих агентов.
|
|
7112
|
-
enabledProviders: ["claude", "antigravity"],
|
|
9243
|
+
enabledProviders: ["claude", "antigravity", "codex"],
|
|
7113
9244
|
// Включено: запрос без VPN может стоить аккаунта, а тому, у кого маршрут и
|
|
7114
9245
|
// так из разрешённой страны, защита ничем не мешает.
|
|
7115
9246
|
networkGuardEnabled: true,
|
|
@@ -7120,11 +9251,11 @@ var AppSettingsStore = class {
|
|
|
7120
9251
|
#settings = { ...DEFAULT_APP_SETTINGS };
|
|
7121
9252
|
#storePath;
|
|
7122
9253
|
constructor(dataDir) {
|
|
7123
|
-
this.#storePath =
|
|
9254
|
+
this.#storePath = path27.join(dataDir, "app-settings.json");
|
|
7124
9255
|
}
|
|
7125
9256
|
async load() {
|
|
7126
9257
|
try {
|
|
7127
|
-
const raw = await
|
|
9258
|
+
const raw = await readFile16(this.#storePath, "utf8");
|
|
7128
9259
|
this.#settings = sanitize2(JSON.parse(raw), DEFAULT_APP_SETTINGS);
|
|
7129
9260
|
} catch {
|
|
7130
9261
|
this.#settings = { ...DEFAULT_APP_SETTINGS };
|
|
@@ -7144,8 +9275,8 @@ var AppSettingsStore = class {
|
|
|
7144
9275
|
async update(patch) {
|
|
7145
9276
|
const next = sanitize2(patch, this.#settings);
|
|
7146
9277
|
this.#settings = next;
|
|
7147
|
-
await
|
|
7148
|
-
await
|
|
9278
|
+
await mkdir15(path27.dirname(this.#storePath), { recursive: true });
|
|
9279
|
+
await writeFile15(this.#storePath, JSON.stringify(next, null, 2), "utf8");
|
|
7149
9280
|
return this.current;
|
|
7150
9281
|
}
|
|
7151
9282
|
};
|
|
@@ -7220,7 +9351,7 @@ function sanitize2(value, fallback) {
|
|
|
7220
9351
|
return result;
|
|
7221
9352
|
}
|
|
7222
9353
|
function claudeHome() {
|
|
7223
|
-
return
|
|
9354
|
+
return path27.join(homedir7(), ".claude");
|
|
7224
9355
|
}
|
|
7225
9356
|
function writableRoots(mode, cwd, workspacePaths) {
|
|
7226
9357
|
if (mode === "all")
|
|
@@ -7230,7 +9361,7 @@ function writableRoots(mode, cwd, workspacePaths) {
|
|
|
7230
9361
|
return [...roots];
|
|
7231
9362
|
for (const workspace of [cwd, ...workspacePaths]) {
|
|
7232
9363
|
roots.add(workspace);
|
|
7233
|
-
const parent =
|
|
9364
|
+
const parent = path27.dirname(workspace);
|
|
7234
9365
|
if (parent !== workspace)
|
|
7235
9366
|
roots.add(parent);
|
|
7236
9367
|
}
|
|
@@ -7238,19 +9369,19 @@ function writableRoots(mode, cwd, workspacePaths) {
|
|
|
7238
9369
|
}
|
|
7239
9370
|
|
|
7240
9371
|
// ../host/dist/handoff-store.js
|
|
7241
|
-
import { mkdir as
|
|
7242
|
-
import
|
|
9372
|
+
import { mkdir as mkdir16, readFile as readFile17, readdir as readdir8, rm as rm5, writeFile as writeFile16 } from "node:fs/promises";
|
|
9373
|
+
import path28 from "node:path";
|
|
7243
9374
|
var HandoffStore = class {
|
|
7244
9375
|
#dir;
|
|
7245
9376
|
constructor(dataDir) {
|
|
7246
|
-
this.#dir =
|
|
9377
|
+
this.#dir = path28.join(dataDir, "handoffs");
|
|
7247
9378
|
}
|
|
7248
9379
|
async get(sessionId) {
|
|
7249
9380
|
const file = this.#file(sessionId);
|
|
7250
9381
|
if (!file)
|
|
7251
9382
|
return null;
|
|
7252
9383
|
try {
|
|
7253
|
-
const parsed = JSON.parse(await
|
|
9384
|
+
const parsed = JSON.parse(await readFile17(file, "utf8"));
|
|
7254
9385
|
return typeof parsed.text === "string" ? parsed : null;
|
|
7255
9386
|
} catch {
|
|
7256
9387
|
return null;
|
|
@@ -7260,18 +9391,18 @@ var HandoffStore = class {
|
|
|
7260
9391
|
const file = this.#file(handoff.sessionId);
|
|
7261
9392
|
if (!file)
|
|
7262
9393
|
return;
|
|
7263
|
-
await
|
|
7264
|
-
await
|
|
9394
|
+
await mkdir16(this.#dir, { recursive: true });
|
|
9395
|
+
await writeFile16(file, JSON.stringify(handoff, null, 2), "utf8");
|
|
7265
9396
|
}
|
|
7266
9397
|
async remove(sessionId) {
|
|
7267
9398
|
const file = this.#file(sessionId);
|
|
7268
9399
|
if (file)
|
|
7269
|
-
await
|
|
9400
|
+
await rm5(file, { force: true });
|
|
7270
9401
|
}
|
|
7271
9402
|
/** id всех сохранённых хэндоффов. */
|
|
7272
9403
|
async list() {
|
|
7273
9404
|
try {
|
|
7274
|
-
return (await
|
|
9405
|
+
return (await readdir8(this.#dir)).filter((name) => name.endsWith(".json")).map((name) => name.slice(0, -".json".length));
|
|
7275
9406
|
} catch {
|
|
7276
9407
|
return [];
|
|
7277
9408
|
}
|
|
@@ -7280,7 +9411,7 @@ var HandoffStore = class {
|
|
|
7280
9411
|
#file(sessionId) {
|
|
7281
9412
|
if (!/^[\w-]{1,128}$/.test(sessionId))
|
|
7282
9413
|
return null;
|
|
7283
|
-
return
|
|
9414
|
+
return path28.join(this.#dir, `${sessionId}.json`);
|
|
7284
9415
|
}
|
|
7285
9416
|
};
|
|
7286
9417
|
var SAME_WINDOW_MS = 5 * 6e4;
|
|
@@ -7289,11 +9420,11 @@ var LimitStopState = class {
|
|
|
7289
9420
|
#fired = {};
|
|
7290
9421
|
#storePath;
|
|
7291
9422
|
constructor(dataDir) {
|
|
7292
|
-
this.#storePath =
|
|
9423
|
+
this.#storePath = path28.join(dataDir, "limit-stop.json");
|
|
7293
9424
|
}
|
|
7294
9425
|
async load() {
|
|
7295
9426
|
try {
|
|
7296
|
-
const parsed = JSON.parse(await
|
|
9427
|
+
const parsed = JSON.parse(await readFile17(this.#storePath, "utf8"));
|
|
7297
9428
|
this.#fired = {};
|
|
7298
9429
|
const read = (source) => {
|
|
7299
9430
|
const out = {};
|
|
@@ -7337,9 +9468,9 @@ var LimitStopState = class {
|
|
|
7337
9468
|
}
|
|
7338
9469
|
async #mark(account, limit, until) {
|
|
7339
9470
|
this.#fired[account] = { ...this.#fired[account], [limit]: until };
|
|
7340
|
-
await
|
|
9471
|
+
await mkdir16(path28.dirname(this.#storePath), { recursive: true });
|
|
7341
9472
|
const { [MAIN_ACCOUNT_ID]: main = {}, ...others } = this.#fired;
|
|
7342
|
-
await
|
|
9473
|
+
await writeFile16(this.#storePath, JSON.stringify({ ...main, ...others }, null, 2), "utf8");
|
|
7343
9474
|
}
|
|
7344
9475
|
};
|
|
7345
9476
|
|
|
@@ -7443,9 +9574,9 @@ function capitalize(text) {
|
|
|
7443
9574
|
}
|
|
7444
9575
|
|
|
7445
9576
|
// ../host/dist/plugins.js
|
|
7446
|
-
import { readFile as
|
|
7447
|
-
import { homedir as
|
|
7448
|
-
import
|
|
9577
|
+
import { readFile as readFile18 } from "node:fs/promises";
|
|
9578
|
+
import { homedir as homedir8 } from "node:os";
|
|
9579
|
+
import path29 from "node:path";
|
|
7449
9580
|
var TIMEOUT_MS2 = 12e4;
|
|
7450
9581
|
var SAFE_ARG = /^[A-Za-z0-9][A-Za-z0-9._@/-]*$/;
|
|
7451
9582
|
var PluginCli = class {
|
|
@@ -7544,10 +9675,10 @@ async function readCatalog(markets, installed) {
|
|
|
7544
9675
|
return lists.flat().sort((a, b) => a.name.localeCompare(b.name));
|
|
7545
9676
|
}
|
|
7546
9677
|
async function readMarketplace(market, installed) {
|
|
7547
|
-
const root = market.installLocation ||
|
|
9678
|
+
const root = market.installLocation || path29.join(homedir8(), ".claude", "plugins", "marketplaces", market.name);
|
|
7548
9679
|
let manifest;
|
|
7549
9680
|
try {
|
|
7550
|
-
const text = await
|
|
9681
|
+
const text = await readFile18(path29.join(root, ".claude-plugin", "marketplace.json"), "utf8");
|
|
7551
9682
|
manifest = JSON.parse(text);
|
|
7552
9683
|
} catch {
|
|
7553
9684
|
return [];
|
|
@@ -7590,7 +9721,7 @@ function authorName(raw) {
|
|
|
7590
9721
|
}
|
|
7591
9722
|
|
|
7592
9723
|
// ../host/dist/auth.js
|
|
7593
|
-
import { EventEmitter as
|
|
9724
|
+
import { EventEmitter as EventEmitter6 } from "node:events";
|
|
7594
9725
|
var QUICK_TIMEOUT_MS = 3e4;
|
|
7595
9726
|
var LOGIN_TIMEOUT_MS = 10 * 6e4;
|
|
7596
9727
|
var URL_RE = /https:\/\/\S*\/oauth\/authorize\S*/;
|
|
@@ -7602,7 +9733,7 @@ var IDLE = {
|
|
|
7602
9733
|
output: "",
|
|
7603
9734
|
error: null
|
|
7604
9735
|
};
|
|
7605
|
-
var AuthCli = class extends
|
|
9736
|
+
var AuthCli = class extends EventEmitter6 {
|
|
7606
9737
|
configDir;
|
|
7607
9738
|
#child = null;
|
|
7608
9739
|
#state = IDLE;
|
|
@@ -7641,7 +9772,7 @@ var AuthCli = class extends EventEmitter4 {
|
|
|
7641
9772
|
if (this.#child)
|
|
7642
9773
|
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");
|
|
7643
9774
|
if (switchAccount) {
|
|
7644
|
-
const out = await this.#run(["auth", "logout"]).catch(
|
|
9775
|
+
const out = await this.#run(["auth", "logout"]).catch(describe6);
|
|
7645
9776
|
this.#push({ ...IDLE, active: true, output: `${out}
|
|
7646
9777
|
` });
|
|
7647
9778
|
this.emit("changed");
|
|
@@ -7661,7 +9792,7 @@ var AuthCli = class extends EventEmitter4 {
|
|
|
7661
9792
|
child.stdout?.on("data", (chunk) => this.#absorb(chunk.toString()));
|
|
7662
9793
|
child.stderr?.on("data", (chunk) => this.#absorb(chunk.toString()));
|
|
7663
9794
|
child.on("error", (error) => {
|
|
7664
|
-
this.#fail(error.code === "ENOENT" ? "\u041D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D claude \u0432 PATH \u2014 \u0432\u0445\u043E\u0434 \u043D\u0435\u0434\u043E\u0441\u0442\u0443\u043F\u0435\u043D" :
|
|
9795
|
+
this.#fail(error.code === "ENOENT" ? "\u041D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D claude \u0432 PATH \u2014 \u0432\u0445\u043E\u0434 \u043D\u0435\u0434\u043E\u0441\u0442\u0443\u043F\u0435\u043D" : describe6(error));
|
|
7665
9796
|
});
|
|
7666
9797
|
child.on("close", (code) => {
|
|
7667
9798
|
if (this.#child !== child)
|
|
@@ -7793,14 +9924,14 @@ function parseStatus2(raw) {
|
|
|
7793
9924
|
function str3(value) {
|
|
7794
9925
|
return typeof value === "string" ? value : "";
|
|
7795
9926
|
}
|
|
7796
|
-
function
|
|
9927
|
+
function describe6(error) {
|
|
7797
9928
|
return error instanceof Error ? error.message : String(error);
|
|
7798
9929
|
}
|
|
7799
9930
|
|
|
7800
9931
|
// ../host/dist/relay-link.js
|
|
7801
|
-
import { EventEmitter as
|
|
7802
|
-
import { readFile as
|
|
7803
|
-
import
|
|
9932
|
+
import { EventEmitter as EventEmitter7 } from "node:events";
|
|
9933
|
+
import { readFile as readFile19, writeFile as writeFile17, rm as rm6, mkdir as mkdir17 } from "node:fs/promises";
|
|
9934
|
+
import path30 from "node:path";
|
|
7804
9935
|
import { hostname } from "node:os";
|
|
7805
9936
|
import WebSocket from "ws";
|
|
7806
9937
|
|
|
@@ -7817,7 +9948,7 @@ var SILENCE_TIMEOUT_MS = 95e3;
|
|
|
7817
9948
|
function jitter(delay2) {
|
|
7818
9949
|
return Math.round(delay2 * (0.8 + Math.random() * 0.4));
|
|
7819
9950
|
}
|
|
7820
|
-
var RelayLink = class extends
|
|
9951
|
+
var RelayLink = class extends EventEmitter7 {
|
|
7821
9952
|
#credentials = null;
|
|
7822
9953
|
#socket = null;
|
|
7823
9954
|
#retry = RETRY_MIN_MS;
|
|
@@ -7855,7 +9986,7 @@ var RelayLink = class extends EventEmitter5 {
|
|
|
7855
9986
|
#log;
|
|
7856
9987
|
constructor(options2) {
|
|
7857
9988
|
super();
|
|
7858
|
-
this.#file =
|
|
9989
|
+
this.#file = path30.join(options2.dataDir, "relay.json");
|
|
7859
9990
|
this.#defaultUrl = options2.defaultUrl.replace(/\/+$/, "");
|
|
7860
9991
|
this.#log = options2.log ?? ((msg) => console.log(`[relay] ${msg}`));
|
|
7861
9992
|
}
|
|
@@ -7936,7 +10067,7 @@ var RelayLink = class extends EventEmitter5 {
|
|
|
7936
10067
|
}
|
|
7937
10068
|
async #read() {
|
|
7938
10069
|
try {
|
|
7939
|
-
const raw = await
|
|
10070
|
+
const raw = await readFile19(this.#file, "utf8");
|
|
7940
10071
|
const parsed = JSON.parse(raw);
|
|
7941
10072
|
if (typeof parsed !== "object" || parsed === null)
|
|
7942
10073
|
return null;
|
|
@@ -7949,8 +10080,8 @@ var RelayLink = class extends EventEmitter5 {
|
|
|
7949
10080
|
}
|
|
7950
10081
|
}
|
|
7951
10082
|
async #write(credentials) {
|
|
7952
|
-
await
|
|
7953
|
-
await
|
|
10083
|
+
await mkdir17(path30.dirname(this.#file), { recursive: true });
|
|
10084
|
+
await writeFile17(this.#file, `${JSON.stringify(credentials, null, 2)}
|
|
7954
10085
|
`, {
|
|
7955
10086
|
encoding: "utf8",
|
|
7956
10087
|
mode: 384
|
|
@@ -7974,7 +10105,7 @@ var RelayLink = class extends EventEmitter5 {
|
|
|
7974
10105
|
body: JSON.stringify({ code, name: machine, platform: process.platform })
|
|
7975
10106
|
});
|
|
7976
10107
|
} catch (error) {
|
|
7977
|
-
throw new Error(`\u043D\u0435 \u0434\u043E\u0437\u0432\u043E\u043D\u0438\u043B\u0438\u0441\u044C \u0434\u043E ${url2}: ${
|
|
10108
|
+
throw new Error(`\u043D\u0435 \u0434\u043E\u0437\u0432\u043E\u043D\u0438\u043B\u0438\u0441\u044C \u0434\u043E ${url2}: ${describe7(error)}`);
|
|
7978
10109
|
}
|
|
7979
10110
|
const data = await response.json().catch(() => ({}));
|
|
7980
10111
|
if (!response.ok || !data.token || !data.hostId) {
|
|
@@ -8002,7 +10133,7 @@ var RelayLink = class extends EventEmitter5 {
|
|
|
8002
10133
|
this.#error = null;
|
|
8003
10134
|
this.#clients.clear();
|
|
8004
10135
|
this.#shell = { enabled: false, pending: false, email: null, confirmedAt: null };
|
|
8005
|
-
await
|
|
10136
|
+
await rm6(this.#file, { force: true });
|
|
8006
10137
|
this.#changed();
|
|
8007
10138
|
this.#log("\u0441\u043E\u043F\u0440\u044F\u0436\u0435\u043D\u0438\u0435 \u0441\u043D\u044F\u0442\u043E");
|
|
8008
10139
|
}
|
|
@@ -8193,11 +10324,11 @@ var RelayLink = class extends EventEmitter5 {
|
|
|
8193
10324
|
socket.send(JSON.stringify(frame));
|
|
8194
10325
|
}
|
|
8195
10326
|
};
|
|
8196
|
-
function
|
|
10327
|
+
function describe7(error) {
|
|
8197
10328
|
return error instanceof Error ? error.message : String(error);
|
|
8198
10329
|
}
|
|
8199
10330
|
function humanize(error) {
|
|
8200
|
-
const message =
|
|
10331
|
+
const message = describe7(error);
|
|
8201
10332
|
if (/handshake has timed out/i.test(message)) {
|
|
8202
10333
|
return `relay \u043D\u0435 \u043E\u0442\u0432\u0435\u0442\u0438\u043B \u043D\u0430 \u0440\u0443\u043A\u043E\u043F\u043E\u0436\u0430\u0442\u0438\u0435 \u0437\u0430 ${Math.round(HANDSHAKE_TIMEOUT_MS / 1e3)} \u0441 \u2014 \u043F\u0440\u043E\u0431\u0443\u0435\u043C \u0441\u043D\u043E\u0432\u0430`;
|
|
8203
10334
|
}
|
|
@@ -8205,14 +10336,14 @@ function humanize(error) {
|
|
|
8205
10336
|
}
|
|
8206
10337
|
|
|
8207
10338
|
// ../host/dist/terminal.js
|
|
8208
|
-
import { EventEmitter as
|
|
10339
|
+
import { EventEmitter as EventEmitter8 } from "node:events";
|
|
8209
10340
|
import { access as access2, constants as constants2 } from "node:fs/promises";
|
|
8210
|
-
import
|
|
8211
|
-
import { randomUUID as
|
|
10341
|
+
import path31 from "node:path";
|
|
10342
|
+
import { randomUUID as randomUUID8 } from "node:crypto";
|
|
8212
10343
|
var SCROLLBACK_BYTES = 256 * 1024;
|
|
8213
10344
|
var FLUSH_MS = 12;
|
|
8214
10345
|
var MAX_TERMINALS = 24;
|
|
8215
|
-
var TerminalHub = class extends
|
|
10346
|
+
var TerminalHub = class extends EventEmitter8 {
|
|
8216
10347
|
#terminals = /* @__PURE__ */ new Map();
|
|
8217
10348
|
#module = null;
|
|
8218
10349
|
list(workspaceId) {
|
|
@@ -8245,7 +10376,7 @@ var TerminalHub = class extends EventEmitter6 {
|
|
|
8245
10376
|
env: environment()
|
|
8246
10377
|
});
|
|
8247
10378
|
const info = {
|
|
8248
|
-
id:
|
|
10379
|
+
id: randomUUID8(),
|
|
8249
10380
|
workspaceId: options2.workspaceId,
|
|
8250
10381
|
title: shell.title,
|
|
8251
10382
|
shell: shell.file,
|
|
@@ -8377,22 +10508,22 @@ async function defaultShell() {
|
|
|
8377
10508
|
if (pwsh)
|
|
8378
10509
|
return { file: pwsh, args: [], title: "pwsh" };
|
|
8379
10510
|
const system = process.env.SystemRoot ?? "C:\\Windows";
|
|
8380
|
-
const powershell =
|
|
10511
|
+
const powershell = path31.join(system, "System32/WindowsPowerShell/v1.0/powershell.exe");
|
|
8381
10512
|
if (await exists3(powershell))
|
|
8382
10513
|
return { file: powershell, args: [], title: "powershell" };
|
|
8383
10514
|
return { file: process.env.COMSPEC ?? "cmd.exe", args: [], title: "cmd" };
|
|
8384
10515
|
}
|
|
8385
10516
|
const shell = process.env.SHELL;
|
|
8386
10517
|
if (shell && await exists3(shell))
|
|
8387
|
-
return { file: shell, args: [], title:
|
|
10518
|
+
return { file: shell, args: [], title: path31.basename(shell) };
|
|
8388
10519
|
if (await exists3("/bin/bash"))
|
|
8389
10520
|
return { file: "/bin/bash", args: [], title: "bash" };
|
|
8390
10521
|
return { file: "/bin/sh", args: [], title: "sh" };
|
|
8391
10522
|
}
|
|
8392
10523
|
async function findOnPath(name) {
|
|
8393
|
-
const dirs = (process.env.PATH ?? "").split(
|
|
10524
|
+
const dirs = (process.env.PATH ?? "").split(path31.delimiter).filter(Boolean);
|
|
8394
10525
|
for (const dir of dirs) {
|
|
8395
|
-
const candidate =
|
|
10526
|
+
const candidate = path31.join(dir, name);
|
|
8396
10527
|
if (await exists3(candidate))
|
|
8397
10528
|
return candidate;
|
|
8398
10529
|
}
|
|
@@ -8403,10 +10534,10 @@ function exists3(file) {
|
|
|
8403
10534
|
}
|
|
8404
10535
|
|
|
8405
10536
|
// ../host/dist/mcp-config.js
|
|
8406
|
-
import { readFile as
|
|
8407
|
-
import
|
|
10537
|
+
import { readFile as readFile20, writeFile as writeFile18, mkdir as mkdir18 } from "node:fs/promises";
|
|
10538
|
+
import path32 from "node:path";
|
|
8408
10539
|
var MCP_FILE = ".mcp.json";
|
|
8409
|
-
var LOCAL_SETTINGS2 =
|
|
10540
|
+
var LOCAL_SETTINGS2 = path32.join(".claude", "settings.local.json");
|
|
8410
10541
|
var queues = /* @__PURE__ */ new Map();
|
|
8411
10542
|
function serialize(cwd, work) {
|
|
8412
10543
|
const previous = queues.get(cwd) ?? Promise.resolve();
|
|
@@ -8415,7 +10546,7 @@ function serialize(cwd, work) {
|
|
|
8415
10546
|
return next;
|
|
8416
10547
|
}
|
|
8417
10548
|
async function readProjectServers(cwd) {
|
|
8418
|
-
const file = await readJson(
|
|
10549
|
+
const file = await readJson(path32.join(cwd, MCP_FILE));
|
|
8419
10550
|
const servers = file?.mcpServers;
|
|
8420
10551
|
if (!servers || typeof servers !== "object")
|
|
8421
10552
|
return {};
|
|
@@ -8423,23 +10554,23 @@ async function readProjectServers(cwd) {
|
|
|
8423
10554
|
}
|
|
8424
10555
|
function addProjectServer(cwd, name, config) {
|
|
8425
10556
|
return serialize(cwd, async () => {
|
|
8426
|
-
const file = await readJson(
|
|
10557
|
+
const file = await readJson(path32.join(cwd, MCP_FILE)) ?? {};
|
|
8427
10558
|
const servers = file.mcpServers ?? {};
|
|
8428
10559
|
servers[name] = config;
|
|
8429
10560
|
file.mcpServers = servers;
|
|
8430
|
-
await writeJson(
|
|
10561
|
+
await writeJson(path32.join(cwd, MCP_FILE), file);
|
|
8431
10562
|
await approve(cwd, name);
|
|
8432
10563
|
});
|
|
8433
10564
|
}
|
|
8434
10565
|
function removeProjectServer(cwd, name) {
|
|
8435
10566
|
return serialize(cwd, async () => {
|
|
8436
|
-
const file = await readJson(
|
|
10567
|
+
const file = await readJson(path32.join(cwd, MCP_FILE));
|
|
8437
10568
|
const servers = file?.mcpServers;
|
|
8438
10569
|
if (!servers || !(name in servers))
|
|
8439
10570
|
return false;
|
|
8440
10571
|
delete servers[name];
|
|
8441
|
-
await writeJson(
|
|
8442
|
-
const settingsPath =
|
|
10572
|
+
await writeJson(path32.join(cwd, MCP_FILE), file);
|
|
10573
|
+
const settingsPath = path32.join(cwd, LOCAL_SETTINGS2);
|
|
8443
10574
|
const settings = await readJson(settingsPath);
|
|
8444
10575
|
const enabled = settings?.enabledMcpjsonServers;
|
|
8445
10576
|
if (settings && Array.isArray(enabled) && enabled.includes(name)) {
|
|
@@ -8450,7 +10581,7 @@ function removeProjectServer(cwd, name) {
|
|
|
8450
10581
|
});
|
|
8451
10582
|
}
|
|
8452
10583
|
async function approve(cwd, name) {
|
|
8453
|
-
const file =
|
|
10584
|
+
const file = path32.join(cwd, LOCAL_SETTINGS2);
|
|
8454
10585
|
const settings = await readJson(file) ?? {};
|
|
8455
10586
|
const enabled = Array.isArray(settings.enabledMcpjsonServers) ? settings.enabledMcpjsonServers : [];
|
|
8456
10587
|
if (!enabled.includes(name))
|
|
@@ -8489,21 +10620,21 @@ function describeConfig(config) {
|
|
|
8489
10620
|
}
|
|
8490
10621
|
async function readJson(file) {
|
|
8491
10622
|
try {
|
|
8492
|
-
const raw = await
|
|
10623
|
+
const raw = await readFile20(file, "utf8");
|
|
8493
10624
|
const parsed = JSON.parse(raw);
|
|
8494
10625
|
return parsed && typeof parsed === "object" ? parsed : null;
|
|
8495
10626
|
} catch (error) {
|
|
8496
10627
|
if (error.code === "ENOENT")
|
|
8497
10628
|
return null;
|
|
8498
10629
|
if (error instanceof SyntaxError) {
|
|
8499
|
-
throw new Error(`\u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u0440\u0430\u0437\u043E\u0431\u0440\u0430\u0442\u044C ${
|
|
10630
|
+
throw new Error(`\u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u0440\u0430\u0437\u043E\u0431\u0440\u0430\u0442\u044C ${path32.basename(file)}: ${error.message}`);
|
|
8500
10631
|
}
|
|
8501
10632
|
throw error;
|
|
8502
10633
|
}
|
|
8503
10634
|
}
|
|
8504
10635
|
async function writeJson(file, data) {
|
|
8505
|
-
await
|
|
8506
|
-
await
|
|
10636
|
+
await mkdir18(path32.dirname(file), { recursive: true });
|
|
10637
|
+
await writeFile18(file, `${JSON.stringify(data, null, 2)}
|
|
8507
10638
|
`, "utf8");
|
|
8508
10639
|
}
|
|
8509
10640
|
|
|
@@ -8533,6 +10664,7 @@ var HostServer = class {
|
|
|
8533
10664
|
/** Опросы статуса для идущих OAuth-входов MCP, ключ — сессия и сервер. */
|
|
8534
10665
|
#mcpAuthWatch = /* @__PURE__ */ new Map();
|
|
8535
10666
|
#antigravity;
|
|
10667
|
+
#codex;
|
|
8536
10668
|
/** Боковые сессии («вопрос на полях») по id родителя — не больше одной на разговор. */
|
|
8537
10669
|
#sides = /* @__PURE__ */ new Map();
|
|
8538
10670
|
/**
|
|
@@ -8563,6 +10695,7 @@ var HostServer = class {
|
|
|
8563
10695
|
#draftTouchedAt = /* @__PURE__ */ new Map();
|
|
8564
10696
|
#autoStopTimer = null;
|
|
8565
10697
|
#handoffs;
|
|
10698
|
+
#scheduler;
|
|
8566
10699
|
#limitStop;
|
|
8567
10700
|
#limitTimer = null;
|
|
8568
10701
|
/** Идёт остановка у лимита — второй снимок лимитов её не запускает. */
|
|
@@ -8587,7 +10720,7 @@ var HostServer = class {
|
|
|
8587
10720
|
#limitHandoffBusy = /* @__PURE__ */ new Set();
|
|
8588
10721
|
/** Живые id сессий, у которых сейчас пишется ручной хэндофф. */
|
|
8589
10722
|
#handoffBusy = /* @__PURE__ */ new Set();
|
|
8590
|
-
#hostId =
|
|
10723
|
+
#hostId = randomUUID9();
|
|
8591
10724
|
#plugins = new PluginCli();
|
|
8592
10725
|
#accounts;
|
|
8593
10726
|
/** Вход у каждого аккаунта свой: у него свой каталог конфигурации и свой разговор с CLI. */
|
|
@@ -8606,6 +10739,8 @@ var HostServer = class {
|
|
|
8606
10739
|
* разными проектами при этом остаётся возможной.
|
|
8607
10740
|
*/
|
|
8608
10741
|
#gitBusy = /* @__PURE__ */ new Set();
|
|
10742
|
+
/** Поиск по содержимому разговоров — со своим кешем выжимок транскриптов. */
|
|
10743
|
+
#contentSearch = new ContentSearch();
|
|
8609
10744
|
constructor(options2) {
|
|
8610
10745
|
this.#options = options2;
|
|
8611
10746
|
this.#accounts = new AccountStore(options2.dataDir);
|
|
@@ -8616,7 +10751,13 @@ var HostServer = class {
|
|
|
8616
10751
|
this.#folders = new Folders(options2.dataDir);
|
|
8617
10752
|
this.#settings = new AppSettingsStore(options2.dataDir);
|
|
8618
10753
|
this.#antigravity = new AntigravityStore(options2.dataDir);
|
|
10754
|
+
this.#codex = new CodexStore(options2.dataDir);
|
|
8619
10755
|
this.#handoffs = new HandoffStore(options2.dataDir);
|
|
10756
|
+
this.#scheduler = new Scheduler(options2.dataDir, {
|
|
10757
|
+
run: (task) => this.#runScheduledTask(task),
|
|
10758
|
+
changed: (tasks) => this.#broadcast({ type: "schedule.state", tasks }),
|
|
10759
|
+
hasWorkspace: (workspaceId) => Boolean(this.#workspaces.find(workspaceId))
|
|
10760
|
+
});
|
|
8620
10761
|
this.#limitStop = new LimitStopState(options2.dataDir);
|
|
8621
10762
|
this.#finder = new ProjectFinder(this.#workspaces, () => this.#accounts.all.map((a) => a.configDir));
|
|
8622
10763
|
this.#relay = new RelayLink({ dataDir: options2.dataDir, defaultUrl: options2.relayUrl });
|
|
@@ -8701,7 +10842,7 @@ var HostServer = class {
|
|
|
8701
10842
|
const status = await new AuthCli(configDir).status().catch(() => null);
|
|
8702
10843
|
if (!status?.loggedIn)
|
|
8703
10844
|
return null;
|
|
8704
|
-
const used = this.#accounts.all.find((a) =>
|
|
10845
|
+
const used = this.#accounts.all.find((a) => path33.resolve(this.#accounts.effectiveDir(a.id)).toLowerCase() === configDir.toLowerCase());
|
|
8705
10846
|
return {
|
|
8706
10847
|
configDir,
|
|
8707
10848
|
email: status.email,
|
|
@@ -8715,6 +10856,30 @@ var HostServer = class {
|
|
|
8715
10856
|
async #sendAccounts() {
|
|
8716
10857
|
this.#broadcast(await this.#accountsFrame());
|
|
8717
10858
|
}
|
|
10859
|
+
/**
|
|
10860
|
+
* Поиск по содержимому разговоров открытых проектов (или одного).
|
|
10861
|
+
*
|
|
10862
|
+
* Список сессий — тот же, что у панели проекта (`sessionsOnDisk` по всем
|
|
10863
|
+
* аккаунтам), чтобы в результатах не всплывали сессии чужих каталогов.
|
|
10864
|
+
*/
|
|
10865
|
+
async #searchContent(query3, workspaceId) {
|
|
10866
|
+
const accounts = this.#diskAccountList();
|
|
10867
|
+
const dirOf = new Map(accounts.map((a) => [a.id, a.configDir ?? inheritedDir()]));
|
|
10868
|
+
const workspaces = workspaceId ? this.#workspaces.list().filter((w) => w.id === workspaceId) : this.#workspaces.list();
|
|
10869
|
+
const targets = [];
|
|
10870
|
+
for (const workspace of workspaces) {
|
|
10871
|
+
for (const info of await this.#workspaces.sessionsOnDisk(workspace.id, accounts)) {
|
|
10872
|
+
targets.push({
|
|
10873
|
+
sessionId: info.sessionId,
|
|
10874
|
+
workspaceId: workspace.id,
|
|
10875
|
+
title: diskTitle(info),
|
|
10876
|
+
lastModified: info.lastModified,
|
|
10877
|
+
configDir: dirOf.get(info.accountId) ?? inheritedDir()
|
|
10878
|
+
});
|
|
10879
|
+
}
|
|
10880
|
+
}
|
|
10881
|
+
return this.#contentSearch.search(query3, targets);
|
|
10882
|
+
}
|
|
8718
10883
|
#diskAccountList() {
|
|
8719
10884
|
return this.#accounts.all.map((a) => ({ id: a.id, configDir: a.configDir }));
|
|
8720
10885
|
}
|
|
@@ -8730,9 +10895,11 @@ var HostServer = class {
|
|
|
8730
10895
|
const id = workspaceIdFromPath(dir);
|
|
8731
10896
|
const onDisk = await this.#workspaces.sessionsOnDisk(id, this.#diskAccountList());
|
|
8732
10897
|
const antigravity = await this.#antigravity.list(id);
|
|
8733
|
-
|
|
10898
|
+
const codex = await this.#codex.list(id);
|
|
10899
|
+
return [...onDisk.map((s) => s.sessionId), ...antigravity.map((r) => r.id), ...codex.map((r) => r.id)];
|
|
8734
10900
|
});
|
|
8735
10901
|
await this.#antigravity.remapWorkspaceIds(remap);
|
|
10902
|
+
await this.#codex.remapWorkspaceIds(remap);
|
|
8736
10903
|
await this.#archive.remapWorkspaceIds(remap);
|
|
8737
10904
|
await this.#pins.remapWorkspaceIds(remap);
|
|
8738
10905
|
await this.#order.remapWorkspaceIds(remap);
|
|
@@ -8751,6 +10918,8 @@ var HostServer = class {
|
|
|
8751
10918
|
this.#wireNetworkGuard();
|
|
8752
10919
|
await this.#accounts.load();
|
|
8753
10920
|
await this.#limitStop.load();
|
|
10921
|
+
await this.#scheduler.load();
|
|
10922
|
+
this.#scheduler.start();
|
|
8754
10923
|
await this.#github.load();
|
|
8755
10924
|
await warmClaudeLauncher();
|
|
8756
10925
|
void this.#finder.warm();
|
|
@@ -8797,6 +10966,7 @@ var HostServer = class {
|
|
|
8797
10966
|
}
|
|
8798
10967
|
async shutdown() {
|
|
8799
10968
|
networkGuard.stop();
|
|
10969
|
+
this.#scheduler.stop();
|
|
8800
10970
|
if (this.#autoStopTimer)
|
|
8801
10971
|
clearInterval(this.#autoStopTimer);
|
|
8802
10972
|
this.#autoStopTimer = null;
|
|
@@ -8948,7 +11118,7 @@ var HostServer = class {
|
|
|
8948
11118
|
}
|
|
8949
11119
|
/** Корень проектов: выбранный в настройках или самый обжитой каталог проектов. */
|
|
8950
11120
|
#projectsRoot() {
|
|
8951
|
-
return this.#settings.current.projectsRoot ?? this.#roots()[0] ??
|
|
11121
|
+
return this.#settings.current.projectsRoot ?? this.#roots()[0] ?? homedir9();
|
|
8952
11122
|
}
|
|
8953
11123
|
async #refreshDiskFolders() {
|
|
8954
11124
|
this.#diskFolders = await listDiskFolders(this.#projectsRoot(), this.#workspaces.allPaths());
|
|
@@ -8978,13 +11148,13 @@ var HostServer = class {
|
|
|
8978
11148
|
workspaceFolders: await Promise.all(this.#diskFolders.map(async (name) => {
|
|
8979
11149
|
const id = folderIdFor(name);
|
|
8980
11150
|
const color = this.#folders.diskFolderColor(id);
|
|
8981
|
-
const unopened = await listUnopened(
|
|
11151
|
+
const unopened = await listUnopened(path33.join(this.#projectsRoot(), name), this.#workspaces.allPaths());
|
|
8982
11152
|
return {
|
|
8983
11153
|
id,
|
|
8984
11154
|
name,
|
|
8985
11155
|
...color ? { color } : {},
|
|
8986
11156
|
unopened,
|
|
8987
|
-
path:
|
|
11157
|
+
path: path33.join(this.#projectsRoot(), name)
|
|
8988
11158
|
};
|
|
8989
11159
|
}))
|
|
8990
11160
|
};
|
|
@@ -9031,6 +11201,7 @@ var HostServer = class {
|
|
|
9031
11201
|
owner: async (id) => ids.get(id)
|
|
9032
11202
|
};
|
|
9033
11203
|
await this.#antigravity.remapWorkspaceIds(remap);
|
|
11204
|
+
await this.#codex.remapWorkspaceIds(remap);
|
|
9034
11205
|
await this.#archive.remapWorkspaceIds(remap);
|
|
9035
11206
|
await this.#pins.remapWorkspaceIds(remap);
|
|
9036
11207
|
await this.#order.remapWorkspaceIds(remap);
|
|
@@ -9052,10 +11223,10 @@ var HostServer = class {
|
|
|
9052
11223
|
const name = folderNameOf(folderId);
|
|
9053
11224
|
if (!name || !this.#diskFolders.includes(name))
|
|
9054
11225
|
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");
|
|
9055
|
-
parent =
|
|
11226
|
+
parent = path33.join(root, name);
|
|
9056
11227
|
}
|
|
9057
|
-
const to =
|
|
9058
|
-
if (
|
|
11228
|
+
const to = path33.join(parent, path33.basename(workspace.path));
|
|
11229
|
+
if (path33.resolve(to).toLowerCase() === path33.resolve(workspace.path).toLowerCase())
|
|
9059
11230
|
return;
|
|
9060
11231
|
await this.#relocate(workspace.path, to);
|
|
9061
11232
|
}
|
|
@@ -9067,7 +11238,7 @@ var HostServer = class {
|
|
|
9067
11238
|
if (name === old)
|
|
9068
11239
|
return;
|
|
9069
11240
|
const root = this.#projectsRoot();
|
|
9070
|
-
await this.#relocate(
|
|
11241
|
+
await this.#relocate(path33.join(root, old), path33.join(root, name));
|
|
9071
11242
|
await this.#folders.renameDiskFolder(folderId, folderIdFor(name), name);
|
|
9072
11243
|
this.#sendFolders();
|
|
9073
11244
|
}
|
|
@@ -9075,13 +11246,13 @@ var HostServer = class {
|
|
|
9075
11246
|
const name = folderNameOf(folderId);
|
|
9076
11247
|
if (!name)
|
|
9077
11248
|
return;
|
|
9078
|
-
const dir =
|
|
11249
|
+
const dir = path33.join(this.#projectsRoot(), name);
|
|
9079
11250
|
const foreign = await foreignContent(dir, this.#workspaces.allPaths());
|
|
9080
11251
|
if (foreign) {
|
|
9081
11252
|
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`);
|
|
9082
11253
|
}
|
|
9083
11254
|
for (const project of this.#workspaces.allPaths().filter((p) => isInside(dir, p))) {
|
|
9084
|
-
await this.#relocate(project,
|
|
11255
|
+
await this.#relocate(project, path33.join(this.#projectsRoot(), path33.basename(project)));
|
|
9085
11256
|
}
|
|
9086
11257
|
await removeEmptyDir(dir);
|
|
9087
11258
|
await this.#folders.forgetDiskFolder(folderId);
|
|
@@ -9187,7 +11358,7 @@ var HostServer = class {
|
|
|
9187
11358
|
await this.#refreshDiskFolders();
|
|
9188
11359
|
if (!name || !this.#diskFolders.includes(name))
|
|
9189
11360
|
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");
|
|
9190
|
-
parent =
|
|
11361
|
+
parent = path33.join(this.#projectsRoot(), name);
|
|
9191
11362
|
}
|
|
9192
11363
|
const { workspace, warnings } = await this.#workspaces.create(parent, frame.name, frame.init);
|
|
9193
11364
|
await this.#refreshDiskFolders();
|
|
@@ -9196,6 +11367,16 @@ var HostServer = class {
|
|
|
9196
11367
|
await this.#closeFinder();
|
|
9197
11368
|
return;
|
|
9198
11369
|
}
|
|
11370
|
+
case "session.searchContent": {
|
|
11371
|
+
const hits = await this.#searchContent(frame.query, frame.workspaceId);
|
|
11372
|
+
this.#send(socket, {
|
|
11373
|
+
type: "session.contentResults",
|
|
11374
|
+
query: frame.query,
|
|
11375
|
+
...frame.workspaceId ? { workspaceId: frame.workspaceId } : {},
|
|
11376
|
+
hits
|
|
11377
|
+
});
|
|
11378
|
+
return;
|
|
11379
|
+
}
|
|
9199
11380
|
case "session.list": {
|
|
9200
11381
|
const { sessions, archived } = await this.#listSessions(frame.workspaceId);
|
|
9201
11382
|
this.#send(socket, {
|
|
@@ -9410,19 +11591,43 @@ var HostServer = class {
|
|
|
9410
11591
|
case "prompt.send":
|
|
9411
11592
|
await networkGuard.ensureFresh();
|
|
9412
11593
|
this.#approveAfterLimit(frame.sessionId);
|
|
9413
|
-
this.#requireSession(frame.sessionId).sendPrompt(frame.text, frame.images);
|
|
11594
|
+
this.#requireSession(frame.sessionId).sendPrompt(frame.text, frame.images, false, frame.attachments);
|
|
9414
11595
|
return;
|
|
9415
11596
|
case "prompt.edit":
|
|
9416
11597
|
await networkGuard.ensureFresh();
|
|
9417
11598
|
this.#approveAfterLimit(frame.sessionId);
|
|
9418
|
-
await this.#requireSession(frame.sessionId).editPrompt(frame.userIndex, frame.text, frame.images);
|
|
11599
|
+
await this.#requireSession(frame.sessionId).editPrompt(frame.userIndex, frame.text, frame.images, frame.attachments, frame.rewindFiles === true);
|
|
11600
|
+
return;
|
|
11601
|
+
case "session.rewindFiles": {
|
|
11602
|
+
const session = this.#requireSession(frame.sessionId);
|
|
11603
|
+
const reply = {
|
|
11604
|
+
type: "session.filesRewound",
|
|
11605
|
+
sessionId: frame.sessionId,
|
|
11606
|
+
userIndex: frame.userIndex,
|
|
11607
|
+
dryRun: frame.dryRun
|
|
11608
|
+
};
|
|
11609
|
+
if (!(session instanceof ClaudeSession)) {
|
|
11610
|
+
this.#send(socket, { ...reply, canRewind: false, error: "\u041E\u0442\u043A\u0430\u0442 \u0444\u0430\u0439\u043B\u043E\u0432 \u0435\u0441\u0442\u044C \u0442\u043E\u043B\u044C\u043A\u043E \u0443 \u0441\u0435\u0441\u0441\u0438\u0439 Claude." });
|
|
11611
|
+
return;
|
|
11612
|
+
}
|
|
11613
|
+
try {
|
|
11614
|
+
const result = await session.rewindFiles(frame.userIndex, frame.dryRun);
|
|
11615
|
+
this.#send(socket, { ...reply, ...result });
|
|
11616
|
+
} catch (error) {
|
|
11617
|
+
this.#send(socket, {
|
|
11618
|
+
...reply,
|
|
11619
|
+
canRewind: false,
|
|
11620
|
+
error: error instanceof Error ? error.message : String(error)
|
|
11621
|
+
});
|
|
11622
|
+
}
|
|
9419
11623
|
return;
|
|
11624
|
+
}
|
|
9420
11625
|
case "permission.respond":
|
|
9421
11626
|
this.#requireSession(frame.sessionId).respondPermission(frame.requestId, frame.decision, frame.reason, frame.answers, frame.annotations, frame.plan);
|
|
9422
11627
|
return;
|
|
9423
11628
|
case "side.ask":
|
|
9424
11629
|
await networkGuard.ensureFresh();
|
|
9425
|
-
this.#ensureSide(this.#requireSession(frame.sessionId)).sendPrompt(frame.text);
|
|
11630
|
+
this.#ensureSide(this.#requireSession(frame.sessionId)).sendPrompt(frame.text, frame.images, false, frame.attachments);
|
|
9426
11631
|
return;
|
|
9427
11632
|
// Поднять форк, ничего не спрашивая: клиенту нужен его id, чтобы
|
|
9428
11633
|
// адресовать `control.*` — модель бокового вопроса выбирают до вопроса.
|
|
@@ -9684,6 +11889,78 @@ var HostServer = class {
|
|
|
9684
11889
|
}
|
|
9685
11890
|
return;
|
|
9686
11891
|
}
|
|
11892
|
+
case "fs.preview": {
|
|
11893
|
+
try {
|
|
11894
|
+
const preview = await this.#files(frame.workspaceId).preview(frame.path);
|
|
11895
|
+
this.#send(socket, {
|
|
11896
|
+
type: "fs.previewed",
|
|
11897
|
+
workspaceId: frame.workspaceId,
|
|
11898
|
+
path: normalize(frame.path),
|
|
11899
|
+
...preview
|
|
11900
|
+
});
|
|
11901
|
+
} catch (error) {
|
|
11902
|
+
this.#send(socket, {
|
|
11903
|
+
type: "fs.previewFailed",
|
|
11904
|
+
workspaceId: frame.workspaceId,
|
|
11905
|
+
path: normalize(frame.path),
|
|
11906
|
+
message: error instanceof Error ? error.message : String(error)
|
|
11907
|
+
});
|
|
11908
|
+
}
|
|
11909
|
+
return;
|
|
11910
|
+
}
|
|
11911
|
+
case "memory.list": {
|
|
11912
|
+
await this.#sendMemoryState(socket, frame.workspaceId, frame.accountId);
|
|
11913
|
+
return;
|
|
11914
|
+
}
|
|
11915
|
+
case "memory.read": {
|
|
11916
|
+
const { content, mtime } = await this.#memory(frame.workspaceId, frame.accountId).read(frame.id);
|
|
11917
|
+
this.#send(socket, { type: "memory.file", workspaceId: frame.workspaceId, id: frame.id, content, mtime });
|
|
11918
|
+
return;
|
|
11919
|
+
}
|
|
11920
|
+
case "memory.write":
|
|
11921
|
+
case "memory.delete": {
|
|
11922
|
+
const memory = this.#memory(frame.workspaceId, frame.accountId);
|
|
11923
|
+
try {
|
|
11924
|
+
if (frame.type === "memory.write") {
|
|
11925
|
+
const mtime = await memory.write(frame.id, frame.content, frame.baseMtime);
|
|
11926
|
+
this.#send(socket, { type: "memory.result", workspaceId: frame.workspaceId, id: frame.id, ok: true, mtime });
|
|
11927
|
+
} else {
|
|
11928
|
+
await memory.delete(frame.id);
|
|
11929
|
+
this.#send(socket, { type: "memory.result", workspaceId: frame.workspaceId, id: frame.id, ok: true });
|
|
11930
|
+
}
|
|
11931
|
+
} catch (error) {
|
|
11932
|
+
const conflict = error instanceof ConflictError;
|
|
11933
|
+
const mtime = conflict ? (await memory.read(frame.id).catch(() => null))?.mtime : void 0;
|
|
11934
|
+
this.#send(socket, {
|
|
11935
|
+
type: "memory.result",
|
|
11936
|
+
workspaceId: frame.workspaceId,
|
|
11937
|
+
id: frame.id,
|
|
11938
|
+
ok: false,
|
|
11939
|
+
message: error instanceof Error ? error.message : String(error),
|
|
11940
|
+
...conflict ? { conflict: true } : {},
|
|
11941
|
+
...mtime !== void 0 ? { mtime } : {}
|
|
11942
|
+
});
|
|
11943
|
+
return;
|
|
11944
|
+
}
|
|
11945
|
+
await this.#sendMemoryState(socket, frame.workspaceId, frame.accountId);
|
|
11946
|
+
return;
|
|
11947
|
+
}
|
|
11948
|
+
case "schedule.list": {
|
|
11949
|
+
this.#send(socket, { type: "schedule.state", tasks: this.#scheduler.list() });
|
|
11950
|
+
return;
|
|
11951
|
+
}
|
|
11952
|
+
case "schedule.save": {
|
|
11953
|
+
await this.#scheduler.save(frame.task);
|
|
11954
|
+
return;
|
|
11955
|
+
}
|
|
11956
|
+
case "schedule.delete": {
|
|
11957
|
+
await this.#scheduler.delete(frame.id);
|
|
11958
|
+
return;
|
|
11959
|
+
}
|
|
11960
|
+
case "schedule.run": {
|
|
11961
|
+
await this.#scheduler.runNow(frame.id);
|
|
11962
|
+
return;
|
|
11963
|
+
}
|
|
9687
11964
|
case "fs.write": {
|
|
9688
11965
|
const files = this.#files(frame.workspaceId);
|
|
9689
11966
|
let saved;
|
|
@@ -10489,13 +12766,47 @@ var HostServer = class {
|
|
|
10489
12766
|
sessions.sort((a, b) => (a.pinnedAt ?? 0) - (b.pinnedAt ?? 0));
|
|
10490
12767
|
this.#broadcast({ type: "session.pinned", sessions });
|
|
10491
12768
|
}
|
|
12769
|
+
/**
|
|
12770
|
+
* Запуск запланированной задачи: новая сессия проекта без окна-инициатора
|
|
12771
|
+
* (её увидят все окна через список живых сессий), названная именем задачи,
|
|
12772
|
+
* и промпт задачи в неё.
|
|
12773
|
+
*/
|
|
12774
|
+
async #runScheduledTask(task) {
|
|
12775
|
+
const workspace = this.#workspaces.find(task.workspaceId);
|
|
12776
|
+
if (!workspace)
|
|
12777
|
+
throw new Error("\u041F\u0440\u043E\u0435\u043A\u0442 \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D");
|
|
12778
|
+
if (!this.#settings.current.enabledProviders.includes("claude")) {
|
|
12779
|
+
throw new Error("Claude \u0432\u044B\u043A\u043B\u044E\u0447\u0435\u043D \u0432 \u043D\u0430\u0441\u0442\u0440\u043E\u0439\u043A\u0430\u0445");
|
|
12780
|
+
}
|
|
12781
|
+
const account = this.#accounts.find(task.accountId) ?? this.#accounts.find(void 0);
|
|
12782
|
+
if (!account)
|
|
12783
|
+
throw new Error("\u0410\u043A\u043A\u0430\u0443\u043D\u0442 \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D");
|
|
12784
|
+
const defaults2 = this.#settings.current;
|
|
12785
|
+
const session = new ClaudeSession({
|
|
12786
|
+
workspaceId: workspace.id,
|
|
12787
|
+
accountId: account.id,
|
|
12788
|
+
configDir: account.configDir,
|
|
12789
|
+
cwd: workspace.path,
|
|
12790
|
+
permissionMode: task.permissionMode ?? defaults2.startPermissionMode,
|
|
12791
|
+
model: task.model ?? defaults2.startModel ?? void 0,
|
|
12792
|
+
title: task.name,
|
|
12793
|
+
defaultTitle: workspace.name,
|
|
12794
|
+
writableRoots: () => this.#writableRoots(workspace.path)
|
|
12795
|
+
});
|
|
12796
|
+
this.#wire(session);
|
|
12797
|
+
this.#sessions.set(session.id, session);
|
|
12798
|
+
session.start();
|
|
12799
|
+
this.#sendLive();
|
|
12800
|
+
session.sendPrompt(task.prompt);
|
|
12801
|
+
return session.id;
|
|
12802
|
+
}
|
|
10492
12803
|
async #startSession(socket, frame) {
|
|
10493
12804
|
const workspace = this.#workspaces.find(frame.workspaceId);
|
|
10494
12805
|
if (!workspace)
|
|
10495
12806
|
throw new Error(`\u0412\u043E\u0440\u043A\u0441\u043F\u0435\u0439\u0441 \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D: ${frame.workspaceId}`);
|
|
10496
12807
|
const provider = frame.provider ?? "claude";
|
|
10497
12808
|
if (!frame.resume && !this.#settings.current.enabledProviders.includes(provider)) {
|
|
10498
|
-
throw new Error(`${provider
|
|
12809
|
+
throw new Error(`${PROVIDER_LABEL[provider]} \u0432\u044B\u043A\u043B\u044E\u0447\u0435\u043D \u0432 \u043D\u0430\u0441\u0442\u0440\u043E\u0439\u043A\u0430\u0445`);
|
|
10499
12810
|
}
|
|
10500
12811
|
const agyRecord = frame.resume ? await this.#antigravity.find(frame.resume) : null;
|
|
10501
12812
|
if (agyRecord || !frame.resume && frame.provider === "antigravity") {
|
|
@@ -10517,6 +12828,27 @@ var HostServer = class {
|
|
|
10517
12828
|
this.#send(socket, { type: "session.summary", session: session2.summary() });
|
|
10518
12829
|
return;
|
|
10519
12830
|
}
|
|
12831
|
+
const codexRecord = frame.resume ? await this.#codex.find(frame.resume) : null;
|
|
12832
|
+
if (codexRecord || !frame.resume && frame.provider === "codex") {
|
|
12833
|
+
if (codexRecord)
|
|
12834
|
+
await this.#archive.unarchive([codexRecord.id]);
|
|
12835
|
+
const session2 = new CodexSession({
|
|
12836
|
+
workspaceId: workspace.id,
|
|
12837
|
+
cwd: codexRecord?.cwd ?? workspace.path,
|
|
12838
|
+
store: this.#codex,
|
|
12839
|
+
...codexRecord ? { record: codexRecord } : {},
|
|
12840
|
+
...frame.permissionMode ? { permissionMode: frame.permissionMode } : {},
|
|
12841
|
+
...frame.model ? { model: frame.model } : {},
|
|
12842
|
+
defaultTitle: workspace.name,
|
|
12843
|
+
version: this.#options.version
|
|
12844
|
+
});
|
|
12845
|
+
this.#wire(session2);
|
|
12846
|
+
this.#sessions.set(session2.id, session2);
|
|
12847
|
+
session2.start();
|
|
12848
|
+
this.#sendLive();
|
|
12849
|
+
this.#send(socket, { type: "session.summary", session: session2.summary() });
|
|
12850
|
+
return;
|
|
12851
|
+
}
|
|
10520
12852
|
const onDisk = frame.resume ? (await this.#workspaces.sessionsOnDisk(workspace.id, this.#diskAccountList())).find((info) => info.sessionId === frame.resume) : void 0;
|
|
10521
12853
|
const resumed = onDisk && !frame.fork ? onDisk : void 0;
|
|
10522
12854
|
const resumedTitle = resumed ? diskTitle(resumed) : null;
|
|
@@ -10665,7 +12997,7 @@ var HostServer = class {
|
|
|
10665
12997
|
this.#broadcast({ type: "context.state", sessionId: session.id, context });
|
|
10666
12998
|
});
|
|
10667
12999
|
session.on("stderr", (data) => {
|
|
10668
|
-
const tag = session instanceof AntigravitySession ? "agy" : "claude";
|
|
13000
|
+
const tag = session instanceof AntigravitySession ? "agy" : session instanceof CodexSession ? "codex" : "claude";
|
|
10669
13001
|
process.stderr.write(`[${tag} ${session.id.slice(0, 8)}] ${data}`);
|
|
10670
13002
|
});
|
|
10671
13003
|
}
|
|
@@ -10685,7 +13017,7 @@ var HostServer = class {
|
|
|
10685
13017
|
* разговора пока и не было.
|
|
10686
13018
|
*/
|
|
10687
13019
|
#ensureSide(parent) {
|
|
10688
|
-
if (parent instanceof
|
|
13020
|
+
if (!(parent instanceof ClaudeSession)) {
|
|
10689
13021
|
throw new Error("\u0412\u043E\u043F\u0440\u043E\u0441 \u043D\u0430 \u043F\u043E\u043B\u044F\u0445 \u0434\u043E\u0441\u0442\u0443\u043F\u0435\u043D \u0442\u043E\u043B\u044C\u043A\u043E \u0432 \u0441\u0435\u0441\u0441\u0438\u044F\u0445 Claude");
|
|
10690
13022
|
}
|
|
10691
13023
|
const existing = this.#sides.get(parent.id);
|
|
@@ -10746,7 +13078,7 @@ var HostServer = class {
|
|
|
10746
13078
|
*/
|
|
10747
13079
|
#roots() {
|
|
10748
13080
|
const roots = this.#finder.roots();
|
|
10749
|
-
return roots.length > 0 ? roots : [
|
|
13081
|
+
return roots.length > 0 ? roots : [homedir9()];
|
|
10750
13082
|
}
|
|
10751
13083
|
/**
|
|
10752
13084
|
* Где сессии этого каталога разрешено писать без вопроса.
|
|
@@ -10922,6 +13254,24 @@ var HostServer = class {
|
|
|
10922
13254
|
// -------------------------------------------------------------------------
|
|
10923
13255
|
// Файлы проекта
|
|
10924
13256
|
// -------------------------------------------------------------------------
|
|
13257
|
+
/** Файлы памяти проекта для аккаунта (по умолчанию — основного). */
|
|
13258
|
+
#memory(workspaceId, accountId) {
|
|
13259
|
+
const workspace = this.#workspaces.find(workspaceId);
|
|
13260
|
+
if (!workspace)
|
|
13261
|
+
throw new Error(`\u0412\u043E\u0440\u043A\u0441\u043F\u0435\u0439\u0441 \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D: ${workspaceId}`);
|
|
13262
|
+
const account = this.#accounts.find(accountId) ?? this.#accounts.find(void 0);
|
|
13263
|
+
return new MemoryFiles(workspace.path, this.#accounts.effectiveDir(account?.id));
|
|
13264
|
+
}
|
|
13265
|
+
async #sendMemoryState(socket, workspaceId, accountId) {
|
|
13266
|
+
const account = this.#accounts.find(accountId) ?? this.#accounts.find(void 0);
|
|
13267
|
+
const files = await this.#memory(workspaceId, account?.id).list();
|
|
13268
|
+
this.#send(socket, {
|
|
13269
|
+
type: "memory.state",
|
|
13270
|
+
workspaceId,
|
|
13271
|
+
accountId: account?.id ?? MAIN_ACCOUNT_ID,
|
|
13272
|
+
files
|
|
13273
|
+
});
|
|
13274
|
+
}
|
|
10925
13275
|
#files(workspaceId) {
|
|
10926
13276
|
const workspace = this.#workspaces.find(workspaceId);
|
|
10927
13277
|
if (!workspace)
|
|
@@ -10988,7 +13338,7 @@ var HostServer = class {
|
|
|
10988
13338
|
live.setTitle(title);
|
|
10989
13339
|
return;
|
|
10990
13340
|
}
|
|
10991
|
-
if (await this.#antigravity.rename(sessionId, title)) {
|
|
13341
|
+
if (await this.#antigravity.rename(sessionId, title) || await this.#codex.rename(sessionId, title)) {
|
|
10992
13342
|
if (workspaceId)
|
|
10993
13343
|
await this.#sendSessionList(workspaceId);
|
|
10994
13344
|
return;
|
|
@@ -11049,6 +13399,11 @@ var HostServer = class {
|
|
|
11049
13399
|
continue;
|
|
11050
13400
|
historical.push(antigravitySummary(record));
|
|
11051
13401
|
}
|
|
13402
|
+
for (const record of await this.#codex.list(workspaceId)) {
|
|
13403
|
+
if (liveIds.has(record.id))
|
|
13404
|
+
continue;
|
|
13405
|
+
historical.push(antigravitySummary(record, "codex"));
|
|
13406
|
+
}
|
|
11052
13407
|
const known = /* @__PURE__ */ new Set([...liveIds, ...historical.map((s) => s.id)]);
|
|
11053
13408
|
await this.#archive.sweep(workspaceId, historical.filter((s) => !this.#pins.has(s.id)).map((s) => ({ id: s.id, updatedAt: s.updatedAt })), known, this.#settings.current.autoArchiveAfterMs);
|
|
11054
13409
|
await this.#pins.sweep(workspaceId, known);
|
|
@@ -11095,20 +13450,20 @@ var HostServer = class {
|
|
|
11095
13450
|
}
|
|
11096
13451
|
#serveStatic(req, res) {
|
|
11097
13452
|
const webRoot = this.#options.webRoot;
|
|
11098
|
-
if (!webRoot || !
|
|
13453
|
+
if (!webRoot || !existsSync7(webRoot)) {
|
|
11099
13454
|
res.writeHead(200, { "content-type": "text/plain; charset=utf-8" });
|
|
11100
13455
|
res.end("CCV host is running. UI is served by the Vite dev server.\n");
|
|
11101
13456
|
return;
|
|
11102
13457
|
}
|
|
11103
13458
|
const url2 = new URL(req.url ?? "/", "http://localhost");
|
|
11104
|
-
const requested =
|
|
11105
|
-
const target = requested.startsWith(webRoot) &&
|
|
11106
|
-
if (!
|
|
13459
|
+
const requested = path33.join(webRoot, path33.normalize(url2.pathname));
|
|
13460
|
+
const target = requested.startsWith(webRoot) && existsSync7(requested) && statSync3(requested).isFile() ? requested : path33.join(webRoot, "index.html");
|
|
13461
|
+
if (!existsSync7(target)) {
|
|
11107
13462
|
res.writeHead(404).end("not found");
|
|
11108
13463
|
return;
|
|
11109
13464
|
}
|
|
11110
13465
|
res.writeHead(200, { "content-type": contentType(target) });
|
|
11111
|
-
|
|
13466
|
+
createReadStream2(target).pipe(res);
|
|
11112
13467
|
}
|
|
11113
13468
|
};
|
|
11114
13469
|
function diskTitle(info) {
|
|
@@ -11128,12 +13483,17 @@ function contentType(file) {
|
|
|
11128
13483
|
".svg": "image/svg+xml",
|
|
11129
13484
|
".woff2": "font/woff2"
|
|
11130
13485
|
};
|
|
11131
|
-
return types[
|
|
13486
|
+
return types[path33.extname(file)] ?? "application/octet-stream";
|
|
11132
13487
|
}
|
|
11133
|
-
|
|
13488
|
+
var PROVIDER_LABEL = {
|
|
13489
|
+
claude: "Claude",
|
|
13490
|
+
antigravity: "Antigravity",
|
|
13491
|
+
codex: "Codex"
|
|
13492
|
+
};
|
|
13493
|
+
function antigravitySummary(record, provider = "antigravity") {
|
|
11134
13494
|
return {
|
|
11135
13495
|
id: record.id,
|
|
11136
|
-
provider
|
|
13496
|
+
provider,
|
|
11137
13497
|
claudeSessionId: record.id,
|
|
11138
13498
|
workspaceId: record.workspaceId,
|
|
11139
13499
|
cwd: record.cwd,
|
|
@@ -11158,8 +13518,8 @@ function antigravitySummary(record) {
|
|
|
11158
13518
|
}
|
|
11159
13519
|
|
|
11160
13520
|
// dist/ccv.js
|
|
11161
|
-
var HERE =
|
|
11162
|
-
var PACKAGE_ROOT =
|
|
13521
|
+
var HERE = path34.dirname(fileURLToPath(import.meta.url));
|
|
13522
|
+
var PACKAGE_ROOT = path34.resolve(HERE, "..");
|
|
11163
13523
|
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.
|
|
11164
13524
|
|
|
11165
13525
|
\u0418\u0441\u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u043D\u0438\u0435:
|
|
@@ -11226,7 +13586,7 @@ var server = new HostServer({
|
|
|
11226
13586
|
dataDir: defaults.dataDir,
|
|
11227
13587
|
// UI лежит в пакете рядом с бандлом — это и есть разница между установленной
|
|
11228
13588
|
// утилитой и запуском из репозитория, где сборка живёт в `apps/web/dist`.
|
|
11229
|
-
webRoot: process.env.CCV_WEB_ROOT ??
|
|
13589
|
+
webRoot: process.env.CCV_WEB_ROOT ?? path34.join(PACKAGE_ROOT, "web"),
|
|
11230
13590
|
version,
|
|
11231
13591
|
relayUrl: defaults.relayUrl
|
|
11232
13592
|
});
|
|
@@ -11255,7 +13615,7 @@ for (const signal of ["SIGINT", "SIGTERM"]) {
|
|
|
11255
13615
|
}
|
|
11256
13616
|
async function packageVersion() {
|
|
11257
13617
|
try {
|
|
11258
|
-
const text = await
|
|
13618
|
+
const text = await readFile21(path34.join(PACKAGE_ROOT, "package.json"), "utf8");
|
|
11259
13619
|
return JSON.parse(text).version ?? "0.0.0";
|
|
11260
13620
|
} catch {
|
|
11261
13621
|
return "0.0.0";
|
|
@@ -11299,7 +13659,7 @@ function openBrowser(target) {
|
|
|
11299
13659
|
return;
|
|
11300
13660
|
}
|
|
11301
13661
|
const command = process.platform === "win32" ? { file: "cmd", args: ["/c", "start", "", target] } : process.platform === "darwin" ? { file: "open", args: [target] } : { file: "xdg-open", args: [target] };
|
|
11302
|
-
const child =
|
|
13662
|
+
const child = spawn4(command.file, command.args, {
|
|
11303
13663
|
stdio: "ignore",
|
|
11304
13664
|
detached: true,
|
|
11305
13665
|
windowsHide: true
|