jinzd-ai-cli 0.4.189 → 0.4.190
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{agent-client-25TIQ6AP.js → agent-client-6GX6QQDU.js} +0 -1
- package/dist/{auth-OI4YRVRG.js → auth-FSTAKSYF.js} +2 -2
- package/dist/{batch-FPPAYC6L.js → batch-HF5RWUBL.js} +7 -15
- package/dist/{chat-index-JXTYDRCY.js → chat-index-FDSGKWQV.js} +2 -2
- package/dist/{chat-index-WDMVP7BN.js → chat-index-UBCWHBLR.js} +2 -2
- package/dist/{chunk-RFXZQBU4.js → chunk-4KMDKDAK.js} +1 -1
- package/dist/{chunk-SH73ZVHY.js → chunk-5CLH6XAW.js} +8 -8
- package/dist/chunk-6BUTA5VW.js +38 -0
- package/dist/{chunk-VRCBXH2W.js → chunk-A4GUGWEY.js} +1 -1
- package/dist/{chunk-YKVFZLSI.js → chunk-AEAYUKSY.js} +2 -2
- package/dist/{chunk-ZWVIDFGY.js → chunk-BXP6YZ2P.js} +4 -3
- package/dist/{chunk-OVWE4E46.js → chunk-CKH4KQ4E.js} +4 -3
- package/dist/{chunk-D6U75FHP.js → chunk-IEQAE3QG.js} +4 -3
- package/dist/chunk-IW3Q7AE5.js +40 -0
- package/dist/{chunk-TEJ4HYLM.js → chunk-JATZIZJV.js} +2 -2
- package/dist/{chunk-GXB7YKF2.js → chunk-JVKAL5Q3.js} +5 -12
- package/dist/{chunk-3SZ7SREY.js → chunk-KHS7RSGR.js} +6 -5
- package/dist/{chunk-RIVZNS3K.js → chunk-MC34ISJU.js} +5 -4
- package/dist/{chunk-5FV2V3TB.js → chunk-NV6W7TZW.js} +1 -1
- package/dist/{chunk-VNNYHW6N.js → chunk-O6UFCEUZ.js} +1 -1
- package/dist/{chunk-DQ2OHJNF.js → chunk-RWM2GFRC.js} +5 -3
- package/dist/{chunk-SEFOKYYP.js → chunk-SQB66GP6.js} +1 -1
- package/dist/{chunk-HDSKW7Q3.js → chunk-T2NL5ZIA.js} +2 -2
- package/dist/{chunk-4UZE4ADL.js → chunk-TB4W4Y4T.js} +18 -52
- package/dist/{chunk-MH3AFJGV.js → chunk-UVW3WLSV.js} +1 -1
- package/dist/{chunk-KIGVJVX4.js → chunk-W7UKO3PS.js} +18 -50
- package/dist/{chunk-NBZ443LN.js → chunk-X4J2DZB5.js} +1 -1
- package/dist/{chunk-A3I5WP5L.js → chunk-YUBD7T2R.js} +5 -4
- package/dist/{chunk-UTO2YO3K.js → chunk-ZN5IEPSS.js} +1 -1
- package/dist/{ci-CGNVIV6U.js → ci-X24WFUDF.js} +2 -3
- package/dist/{constants-EJF3DOM5.js → constants-4QBBHLU4.js} +1 -2
- package/dist/{doctor-cli-WFH6DYVL.js → doctor-cli-EUOCY7VN.js} +5 -5
- package/dist/electron-server.js +46 -58
- package/dist/{file-checkpoint-UHSMHCRU.js → file-checkpoint-CGH6OJVI.js} +0 -1
- package/dist/{file-checkpoint-ZN7KE3TN.js → file-checkpoint-NKBHGC7L.js} +0 -1
- package/dist/{git-context-7KIP4X2V.js → git-context-EXOEHQSF.js} +0 -1
- package/dist/{hub-LCB3RGVQ.js → hub-YW3KLBZM.js} +3 -4
- package/dist/{hub-server-GSTG5MNE.js → hub-server-LJ2JSKZ2.js} +0 -1
- package/dist/index.js +36 -36
- package/dist/{indexer-S6UMGQKA.js → indexer-AKWMYNJI.js} +3 -3
- package/dist/indexer-BMYUUDLH.js +10 -0
- package/dist/{persist-A3R2IAYU.js → persist-L54DPLI7.js} +3 -3
- package/dist/{project-trust-EBGHD7LE.js → project-trust-MUG325AW.js} +4 -11
- package/dist/{project-trust-IFM7FXEV.js → project-trust-NKYHL3VZ.js} +4 -11
- package/dist/{run-tests-R7QATG6O.js → run-tests-7ZUNEUEX.js} +2 -3
- package/dist/{run-tests-XANJLGXT.js → run-tests-OTZE5CEN.js} +1 -2
- package/dist/{semantic-GJJWTI3A.js → semantic-FF6DDJI6.js} +4 -4
- package/dist/{semantic-FKOEXY75.js → semantic-PK7AUOJT.js} +4 -4
- package/dist/{server-ULMPX3CS.js → server-WMLZOLD5.js} +26 -26
- package/dist/{server-HYLAZODW.js → server-YMCGJOXV.js} +10 -10
- package/dist/{store-VMK543OQ.js → store-MWNHVGJT.js} +2 -2
- package/dist/{store-A3TZM6PS.js → store-VO37H6LS.js} +2 -2
- package/dist/{task-orchestrator-UKU2O6IE.js → task-orchestrator-DEWKVJGQ.js} +14 -14
- package/dist/{usage-4R36JZFP.js → usage-5LMWDGZ4.js} +4 -4
- package/dist/{vector-store-Z5OF4WWJ.js → vector-store-BBDXB5IQ.js} +2 -2
- package/dist/{vector-store-PLDSXF3V.js → vector-store-JBAE6PS4.js} +2 -2
- package/package.json +1 -1
- package/dist/chunk-3RG5ZIWI.js +0 -10
- package/dist/chunk-PDX44BCA.js +0 -11
- package/dist/indexer-ISSNIFQY.js +0 -10
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
ConfigManager
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-X4J2DZB5.js";
|
|
5
5
|
import "./chunk-TZQHYZKT.js";
|
|
6
|
-
import "./chunk-
|
|
7
|
-
import
|
|
6
|
+
import "./chunk-4KMDKDAK.js";
|
|
7
|
+
import {
|
|
8
|
+
atomicWriteFileSync
|
|
9
|
+
} from "./chunk-IW3Q7AE5.js";
|
|
8
10
|
|
|
9
11
|
// src/cli/batch.ts
|
|
10
12
|
import Anthropic from "@anthropic-ai/sdk";
|
|
11
|
-
import { readFileSync, writeFileSync, existsSync, mkdirSync
|
|
13
|
+
import { readFileSync, writeFileSync, existsSync, mkdirSync } from "fs";
|
|
12
14
|
import { join } from "path";
|
|
13
15
|
function parseBatchInput(jsonl) {
|
|
14
16
|
const lines = jsonl.split("\n").map((l) => l.trim()).filter(Boolean);
|
|
@@ -74,17 +76,7 @@ function loadTrackedBatches(config) {
|
|
|
74
76
|
function saveTrackedBatches(config, batches) {
|
|
75
77
|
mkdirSync(config.getConfigDir(), { recursive: true });
|
|
76
78
|
const finalPath = getBatchesPath(config);
|
|
77
|
-
|
|
78
|
-
try {
|
|
79
|
-
writeFileSync(tmpPath, JSON.stringify({ batches }, null, 2), "utf-8");
|
|
80
|
-
renameSync(tmpPath, finalPath);
|
|
81
|
-
} catch (err) {
|
|
82
|
-
try {
|
|
83
|
-
unlinkSync(tmpPath);
|
|
84
|
-
} catch {
|
|
85
|
-
}
|
|
86
|
-
throw err;
|
|
87
|
-
}
|
|
79
|
+
atomicWriteFileSync(finalPath, JSON.stringify({ batches }, null, 2));
|
|
88
80
|
}
|
|
89
81
|
function getClaudeClient(config) {
|
|
90
82
|
const apiKey = config.getApiKey("claude");
|
|
@@ -6,10 +6,10 @@ import {
|
|
|
6
6
|
getChatIndexStatus,
|
|
7
7
|
loadChatIndex,
|
|
8
8
|
searchChatMemory
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-TB4W4Y4T.js";
|
|
10
10
|
import "./chunk-KHYD3WXE.js";
|
|
11
11
|
import "./chunk-SLSWPBK3.js";
|
|
12
|
-
import "./chunk-
|
|
12
|
+
import "./chunk-IW3Q7AE5.js";
|
|
13
13
|
export {
|
|
14
14
|
buildChatIndex,
|
|
15
15
|
chunkSession,
|
|
@@ -5,9 +5,9 @@ import {
|
|
|
5
5
|
getChatIndexStatus,
|
|
6
6
|
loadChatIndex,
|
|
7
7
|
searchChatMemory
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-W7UKO3PS.js";
|
|
9
9
|
import "./chunk-JV5N65KN.js";
|
|
10
|
-
import "./chunk-
|
|
10
|
+
import "./chunk-6BUTA5VW.js";
|
|
11
11
|
export {
|
|
12
12
|
buildChatIndex,
|
|
13
13
|
chunkSession,
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
import {
|
|
3
3
|
hasSemanticIndex,
|
|
4
4
|
semanticSearch
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-T2NL5ZIA.js";
|
|
6
6
|
import {
|
|
7
7
|
runTestsTool
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-NV6W7TZW.js";
|
|
9
9
|
import {
|
|
10
10
|
runTool
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-KHS7RSGR.js";
|
|
12
12
|
import {
|
|
13
13
|
getDangerLevel,
|
|
14
14
|
isFileWriteTool
|
|
@@ -25,20 +25,20 @@ import {
|
|
|
25
25
|
SUBAGENT_ALLOWED_TOOLS,
|
|
26
26
|
SUBAGENT_DEFAULT_MAX_ROUNDS,
|
|
27
27
|
SUBAGENT_MAX_ROUNDS_LIMIT
|
|
28
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-4KMDKDAK.js";
|
|
29
29
|
import {
|
|
30
30
|
fileCheckpoints
|
|
31
31
|
} from "./chunk-4BKXL7SM.js";
|
|
32
32
|
import {
|
|
33
33
|
loadChatIndex,
|
|
34
34
|
searchChatMemory
|
|
35
|
-
} from "./chunk-
|
|
35
|
+
} from "./chunk-TB4W4Y4T.js";
|
|
36
36
|
import {
|
|
37
37
|
indexProject
|
|
38
|
-
} from "./chunk-
|
|
38
|
+
} from "./chunk-O6UFCEUZ.js";
|
|
39
39
|
import {
|
|
40
40
|
loadIndex
|
|
41
|
-
} from "./chunk-
|
|
41
|
+
} from "./chunk-CKH4KQ4E.js";
|
|
42
42
|
|
|
43
43
|
// src/tools/builtin/bash.ts
|
|
44
44
|
import { spawn } from "child_process";
|
|
@@ -2089,7 +2089,7 @@ Do NOT split a long document into many write_file(append=true) calls. That patte
|
|
|
2089
2089
|
const mode = appendMode ? "appended" : "written";
|
|
2090
2090
|
void (async () => {
|
|
2091
2091
|
try {
|
|
2092
|
-
const { updateFile } = await import("./indexer-
|
|
2092
|
+
const { updateFile } = await import("./indexer-AKWMYNJI.js");
|
|
2093
2093
|
await updateFile(process.cwd(), filePath);
|
|
2094
2094
|
} catch {
|
|
2095
2095
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// src/core/atomic-write.ts
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
var RETRYABLE_CODES = /* @__PURE__ */ new Set(["EPERM", "EACCES", "EBUSY"]);
|
|
4
|
+
var MAX_RENAME_RETRIES = 10;
|
|
5
|
+
function sleepSync(ms) {
|
|
6
|
+
const sab = new Int32Array(new SharedArrayBuffer(4));
|
|
7
|
+
Atomics.wait(sab, 0, 0, ms);
|
|
8
|
+
}
|
|
9
|
+
function atomicWriteFileSync(target, data) {
|
|
10
|
+
const tmp = `${target}.tmp`;
|
|
11
|
+
fs.writeFileSync(tmp, data);
|
|
12
|
+
for (let attempt = 0; ; attempt++) {
|
|
13
|
+
try {
|
|
14
|
+
fs.renameSync(tmp, target);
|
|
15
|
+
return;
|
|
16
|
+
} catch (err) {
|
|
17
|
+
const code = err.code;
|
|
18
|
+
if (attempt < MAX_RENAME_RETRIES && code && RETRYABLE_CODES.has(code)) {
|
|
19
|
+
sleepSync(5 * (attempt + 1));
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
fs.writeFileSync(target, data);
|
|
24
|
+
try {
|
|
25
|
+
fs.unlinkSync(tmp);
|
|
26
|
+
} catch {
|
|
27
|
+
}
|
|
28
|
+
return;
|
|
29
|
+
} catch {
|
|
30
|
+
throw err;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export {
|
|
37
|
+
atomicWriteFileSync
|
|
38
|
+
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
loadIndex
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-RWM2GFRC.js";
|
|
4
4
|
import {
|
|
5
5
|
loadVectorStore,
|
|
6
6
|
saveVectorStore,
|
|
7
7
|
searchVectorStore
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-IEQAE3QG.js";
|
|
9
9
|
import {
|
|
10
10
|
EMBEDDING_DIM,
|
|
11
11
|
embed,
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
import {
|
|
3
3
|
EMBEDDING_DIM
|
|
4
4
|
} from "./chunk-KHYD3WXE.js";
|
|
5
|
+
import {
|
|
6
|
+
atomicWriteFileSync
|
|
7
|
+
} from "./chunk-IW3Q7AE5.js";
|
|
5
8
|
|
|
6
9
|
// src/symbols/vector-store.ts
|
|
7
10
|
import fs from "fs";
|
|
@@ -47,9 +50,7 @@ function saveVectorStore(root, indices, vectors) {
|
|
|
47
50
|
Buffer.from(indices.buffer, indices.byteOffset, indices.byteLength).copy(buf, HEADER_BYTES);
|
|
48
51
|
Buffer.from(vectors.buffer, vectors.byteOffset, vectors.byteLength).copy(buf, HEADER_BYTES + count * 4);
|
|
49
52
|
const target = vecPath(root);
|
|
50
|
-
|
|
51
|
-
fs.writeFileSync(tmp, buf);
|
|
52
|
-
fs.renameSync(tmp, target);
|
|
53
|
+
atomicWriteFileSync(target, buf);
|
|
53
54
|
}
|
|
54
55
|
function loadVectorStore(root) {
|
|
55
56
|
const p = vecPath(root);
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
atomicWriteFileSync
|
|
4
|
+
} from "./chunk-IW3Q7AE5.js";
|
|
2
5
|
|
|
3
6
|
// src/symbols/store.ts
|
|
4
7
|
import fs from "fs";
|
|
@@ -75,9 +78,7 @@ function saveIndex(index) {
|
|
|
75
78
|
const dir = indexDir();
|
|
76
79
|
fs.mkdirSync(dir, { recursive: true });
|
|
77
80
|
const target = indexPath(index.root);
|
|
78
|
-
|
|
79
|
-
fs.writeFileSync(tmp, JSON.stringify(index), "utf-8");
|
|
80
|
-
fs.renameSync(tmp, target);
|
|
81
|
+
atomicWriteFileSync(target, JSON.stringify(index));
|
|
81
82
|
}
|
|
82
83
|
function clearIndex(root) {
|
|
83
84
|
const p = indexPath(root);
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
EMBEDDING_DIM
|
|
3
3
|
} from "./chunk-JV5N65KN.js";
|
|
4
|
+
import {
|
|
5
|
+
atomicWriteFileSync
|
|
6
|
+
} from "./chunk-6BUTA5VW.js";
|
|
4
7
|
|
|
5
8
|
// src/symbols/vector-store.ts
|
|
6
9
|
import fs from "fs";
|
|
@@ -46,9 +49,7 @@ function saveVectorStore(root, indices, vectors) {
|
|
|
46
49
|
Buffer.from(indices.buffer, indices.byteOffset, indices.byteLength).copy(buf, HEADER_BYTES);
|
|
47
50
|
Buffer.from(vectors.buffer, vectors.byteOffset, vectors.byteLength).copy(buf, HEADER_BYTES + count * 4);
|
|
48
51
|
const target = vecPath(root);
|
|
49
|
-
|
|
50
|
-
fs.writeFileSync(tmp, buf);
|
|
51
|
-
fs.renameSync(tmp, target);
|
|
52
|
+
atomicWriteFileSync(target, buf);
|
|
52
53
|
}
|
|
53
54
|
function loadVectorStore(root) {
|
|
54
55
|
const p = vecPath(root);
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/core/atomic-write.ts
|
|
4
|
+
import fs from "fs";
|
|
5
|
+
var RETRYABLE_CODES = /* @__PURE__ */ new Set(["EPERM", "EACCES", "EBUSY"]);
|
|
6
|
+
var MAX_RENAME_RETRIES = 10;
|
|
7
|
+
function sleepSync(ms) {
|
|
8
|
+
const sab = new Int32Array(new SharedArrayBuffer(4));
|
|
9
|
+
Atomics.wait(sab, 0, 0, ms);
|
|
10
|
+
}
|
|
11
|
+
function atomicWriteFileSync(target, data) {
|
|
12
|
+
const tmp = `${target}.tmp`;
|
|
13
|
+
fs.writeFileSync(tmp, data);
|
|
14
|
+
for (let attempt = 0; ; attempt++) {
|
|
15
|
+
try {
|
|
16
|
+
fs.renameSync(tmp, target);
|
|
17
|
+
return;
|
|
18
|
+
} catch (err) {
|
|
19
|
+
const code = err.code;
|
|
20
|
+
if (attempt < MAX_RENAME_RETRIES && code && RETRYABLE_CODES.has(code)) {
|
|
21
|
+
sleepSync(5 * (attempt + 1));
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
fs.writeFileSync(target, data);
|
|
26
|
+
try {
|
|
27
|
+
fs.unlinkSync(tmp);
|
|
28
|
+
} catch {
|
|
29
|
+
}
|
|
30
|
+
return;
|
|
31
|
+
} catch {
|
|
32
|
+
throw err;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export {
|
|
39
|
+
atomicWriteFileSync
|
|
40
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
truncateForPersist
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-5CLH6XAW.js";
|
|
5
5
|
import {
|
|
6
6
|
APP_NAME,
|
|
7
7
|
CONFIG_DIR_NAME,
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
MCP_PROTOCOL_VERSION,
|
|
12
12
|
MCP_TOOL_PREFIX,
|
|
13
13
|
VERSION
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-4KMDKDAK.js";
|
|
15
15
|
|
|
16
16
|
// src/mcp/client.ts
|
|
17
17
|
import { spawn } from "child_process";
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
atomicWriteFileSync
|
|
4
|
+
} from "./chunk-IW3Q7AE5.js";
|
|
2
5
|
|
|
3
6
|
// src/web/auth.ts
|
|
4
|
-
import { existsSync, readFileSync, writeFileSync, mkdirSync, readdirSync, copyFileSync
|
|
7
|
+
import { existsSync, readFileSync, writeFileSync, mkdirSync, readdirSync, copyFileSync } from "fs";
|
|
5
8
|
import { join } from "path";
|
|
6
9
|
import { createHmac, randomBytes, timingSafeEqual, pbkdf2Sync } from "crypto";
|
|
7
10
|
var USERS_FILE = "users.json";
|
|
@@ -255,17 +258,7 @@ var AuthManager = class {
|
|
|
255
258
|
}
|
|
256
259
|
saveDB(db) {
|
|
257
260
|
mkdirSync(this.baseDir, { recursive: true });
|
|
258
|
-
|
|
259
|
-
try {
|
|
260
|
-
writeFileSync(tmp, JSON.stringify(db, null, 2), "utf-8");
|
|
261
|
-
renameSync(tmp, this.usersFile);
|
|
262
|
-
} catch (err) {
|
|
263
|
-
try {
|
|
264
|
-
unlinkSync(tmp);
|
|
265
|
-
} catch {
|
|
266
|
-
}
|
|
267
|
-
throw err;
|
|
268
|
-
}
|
|
261
|
+
atomicWriteFileSync(this.usersFile, JSON.stringify(db, null, 2));
|
|
269
262
|
}
|
|
270
263
|
/** Legacy hash — kept only for migrating old users (v0.2.x) */
|
|
271
264
|
hashPasswordLegacy(password, salt) {
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
CONFIG_DIR_NAME
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-4KMDKDAK.js";
|
|
5
|
+
import {
|
|
6
|
+
atomicWriteFileSync
|
|
7
|
+
} from "./chunk-IW3Q7AE5.js";
|
|
5
8
|
|
|
6
9
|
// src/diagnostics/tool-stats.ts
|
|
7
|
-
import { existsSync, readFileSync,
|
|
10
|
+
import { existsSync, readFileSync, mkdirSync } from "fs";
|
|
8
11
|
import { join, dirname } from "path";
|
|
9
12
|
import { homedir } from "os";
|
|
10
13
|
var STATS_FILE_NAME = "tool-stats.json";
|
|
@@ -83,9 +86,7 @@ function flush() {
|
|
|
83
86
|
const path = statsFilePath();
|
|
84
87
|
try {
|
|
85
88
|
mkdirSync(dirname(path), { recursive: true });
|
|
86
|
-
|
|
87
|
-
writeFileSync(tmp, JSON.stringify(state, null, 2), "utf-8");
|
|
88
|
-
renameSync(tmp, path);
|
|
89
|
+
atomicWriteFileSync(path, JSON.stringify(state, null, 2));
|
|
89
90
|
dirty = false;
|
|
90
91
|
pendingWrites = 0;
|
|
91
92
|
} catch {
|
|
@@ -2,9 +2,12 @@
|
|
|
2
2
|
import {
|
|
3
3
|
redactJson
|
|
4
4
|
} from "./chunk-SLSWPBK3.js";
|
|
5
|
+
import {
|
|
6
|
+
atomicWriteFileSync
|
|
7
|
+
} from "./chunk-IW3Q7AE5.js";
|
|
5
8
|
|
|
6
9
|
// src/session/session-manager.ts
|
|
7
|
-
import { readFileSync,
|
|
10
|
+
import { readFileSync, existsSync, mkdirSync, readdirSync, unlinkSync, openSync, readSync, closeSync } from "fs";
|
|
8
11
|
import { join } from "path";
|
|
9
12
|
import { v4 as uuidv4 } from "uuid";
|
|
10
13
|
|
|
@@ -590,9 +593,7 @@ var SessionManager = class {
|
|
|
590
593
|
const opts = this.redactOptionsForSave();
|
|
591
594
|
const { value: payload, hits } = redactJson(raw, opts);
|
|
592
595
|
this.lastRedactionHits = hits.length;
|
|
593
|
-
|
|
594
|
-
writeFileSync(tmpPath, JSON.stringify(payload, null, 2), "utf-8");
|
|
595
|
-
renameSync(tmpPath, filePath);
|
|
596
|
+
atomicWriteFileSync(filePath, JSON.stringify(payload, null, 2));
|
|
596
597
|
}
|
|
597
598
|
loadSession(id) {
|
|
598
599
|
const filePath = join(this.historyDir, `${id}.json`);
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import {
|
|
2
|
+
atomicWriteFileSync
|
|
3
|
+
} from "./chunk-6BUTA5VW.js";
|
|
4
|
+
|
|
1
5
|
// src/symbols/store.ts
|
|
2
6
|
import fs from "fs";
|
|
3
7
|
import path from "path";
|
|
@@ -73,9 +77,7 @@ function saveIndex(index) {
|
|
|
73
77
|
const dir = indexDir();
|
|
74
78
|
fs.mkdirSync(dir, { recursive: true });
|
|
75
79
|
const target = indexPath(index.root);
|
|
76
|
-
|
|
77
|
-
fs.writeFileSync(tmp, JSON.stringify(index), "utf-8");
|
|
78
|
-
fs.renameSync(tmp, target);
|
|
80
|
+
atomicWriteFileSync(target, JSON.stringify(index));
|
|
79
81
|
}
|
|
80
82
|
function clearIndex(root) {
|
|
81
83
|
const p = indexPath(root);
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
loadVectorStore,
|
|
4
4
|
saveVectorStore,
|
|
5
5
|
searchVectorStore
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-BXP6YZ2P.js";
|
|
7
7
|
import {
|
|
8
8
|
EMBEDDING_DIM,
|
|
9
9
|
embed,
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
} from "./chunk-KHYD3WXE.js";
|
|
12
12
|
import {
|
|
13
13
|
loadIndex
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-CKH4KQ4E.js";
|
|
15
15
|
|
|
16
16
|
// src/symbols/semantic.ts
|
|
17
17
|
function pathTokens(absFile, root) {
|
|
@@ -7,49 +7,15 @@ import {
|
|
|
7
7
|
import {
|
|
8
8
|
redactString
|
|
9
9
|
} from "./chunk-SLSWPBK3.js";
|
|
10
|
+
import {
|
|
11
|
+
atomicWriteFileSync
|
|
12
|
+
} from "./chunk-IW3Q7AE5.js";
|
|
10
13
|
|
|
11
14
|
// src/memory/chat-index.ts
|
|
12
|
-
import
|
|
15
|
+
import fs from "fs";
|
|
13
16
|
import path from "path";
|
|
14
17
|
import os from "os";
|
|
15
18
|
import crypto from "crypto";
|
|
16
|
-
|
|
17
|
-
// src/core/atomic-write.ts
|
|
18
|
-
import fs from "fs";
|
|
19
|
-
var RETRYABLE_CODES = /* @__PURE__ */ new Set(["EPERM", "EACCES", "EBUSY"]);
|
|
20
|
-
var MAX_RENAME_RETRIES = 10;
|
|
21
|
-
function sleepSync(ms) {
|
|
22
|
-
const sab = new Int32Array(new SharedArrayBuffer(4));
|
|
23
|
-
Atomics.wait(sab, 0, 0, ms);
|
|
24
|
-
}
|
|
25
|
-
function atomicWriteFileSync(target, data) {
|
|
26
|
-
const tmp = `${target}.tmp`;
|
|
27
|
-
fs.writeFileSync(tmp, data);
|
|
28
|
-
for (let attempt = 0; ; attempt++) {
|
|
29
|
-
try {
|
|
30
|
-
fs.renameSync(tmp, target);
|
|
31
|
-
return;
|
|
32
|
-
} catch (err) {
|
|
33
|
-
const code = err.code;
|
|
34
|
-
if (attempt < MAX_RENAME_RETRIES && code && RETRYABLE_CODES.has(code)) {
|
|
35
|
-
sleepSync(5 * (attempt + 1));
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
try {
|
|
39
|
-
fs.writeFileSync(target, data);
|
|
40
|
-
try {
|
|
41
|
-
fs.unlinkSync(tmp);
|
|
42
|
-
} catch {
|
|
43
|
-
}
|
|
44
|
-
return;
|
|
45
|
-
} catch {
|
|
46
|
-
throw err;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// src/memory/chat-index.ts
|
|
53
19
|
var MEMORY_DIR_NAME = "memory-index";
|
|
54
20
|
var CHUNKS_FILE = "chunks.json";
|
|
55
21
|
var VECTORS_FILE = "vectors.vec";
|
|
@@ -136,7 +102,7 @@ function writeVectorsFile(chunks, vectors) {
|
|
|
136
102
|
);
|
|
137
103
|
}
|
|
138
104
|
const dir = memoryIndexDir();
|
|
139
|
-
|
|
105
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
140
106
|
const totalBytes = VEC_HEADER_BYTES + vectors.byteLength;
|
|
141
107
|
const buf = Buffer.alloc(totalBytes);
|
|
142
108
|
buf.writeUInt32LE(VEC_MAGIC, 0);
|
|
@@ -148,10 +114,10 @@ function writeVectorsFile(chunks, vectors) {
|
|
|
148
114
|
}
|
|
149
115
|
function readVectorsFile(expectedCount) {
|
|
150
116
|
const p = vectorsPath();
|
|
151
|
-
if (!
|
|
117
|
+
if (!fs.existsSync(p)) return null;
|
|
152
118
|
let buf;
|
|
153
119
|
try {
|
|
154
|
-
buf =
|
|
120
|
+
buf = fs.readFileSync(p);
|
|
155
121
|
} catch {
|
|
156
122
|
return null;
|
|
157
123
|
}
|
|
@@ -170,14 +136,14 @@ function readVectorsFile(expectedCount) {
|
|
|
170
136
|
}
|
|
171
137
|
function writeIndexFile(idx) {
|
|
172
138
|
const dir = memoryIndexDir();
|
|
173
|
-
|
|
139
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
174
140
|
atomicWriteFileSync(chunksPath(), JSON.stringify(idx, null, 2));
|
|
175
141
|
}
|
|
176
142
|
function readIndexFile() {
|
|
177
143
|
const p = chunksPath();
|
|
178
|
-
if (!
|
|
144
|
+
if (!fs.existsSync(p)) return null;
|
|
179
145
|
try {
|
|
180
|
-
const raw =
|
|
146
|
+
const raw = fs.readFileSync(p, "utf-8");
|
|
181
147
|
const data = JSON.parse(raw);
|
|
182
148
|
if (data.version !== 1) return null;
|
|
183
149
|
return data;
|
|
@@ -194,24 +160,24 @@ function loadChatIndex() {
|
|
|
194
160
|
}
|
|
195
161
|
function clearChatIndex() {
|
|
196
162
|
try {
|
|
197
|
-
if (
|
|
163
|
+
if (fs.existsSync(chunksPath())) fs.unlinkSync(chunksPath());
|
|
198
164
|
} catch {
|
|
199
165
|
}
|
|
200
166
|
try {
|
|
201
|
-
if (
|
|
167
|
+
if (fs.existsSync(vectorsPath())) fs.unlinkSync(vectorsPath());
|
|
202
168
|
} catch {
|
|
203
169
|
}
|
|
204
170
|
}
|
|
205
171
|
function listSessionFiles() {
|
|
206
172
|
const dir = historyDir();
|
|
207
|
-
if (!
|
|
173
|
+
if (!fs.existsSync(dir)) return [];
|
|
208
174
|
const out = [];
|
|
209
|
-
for (const name of
|
|
175
|
+
for (const name of fs.readdirSync(dir)) {
|
|
210
176
|
if (!name.endsWith(".json")) continue;
|
|
211
177
|
const id = name.replace(/\.json$/, "");
|
|
212
178
|
const p = path.join(dir, name);
|
|
213
179
|
try {
|
|
214
|
-
const st =
|
|
180
|
+
const st = fs.statSync(p);
|
|
215
181
|
out.push({ id, path: p, mtime: st.mtimeMs });
|
|
216
182
|
} catch {
|
|
217
183
|
}
|
|
@@ -220,7 +186,7 @@ function listSessionFiles() {
|
|
|
220
186
|
}
|
|
221
187
|
function readSession(p) {
|
|
222
188
|
try {
|
|
223
|
-
const data = JSON.parse(
|
|
189
|
+
const data = JSON.parse(fs.readFileSync(p, "utf-8"));
|
|
224
190
|
if (!data.id || !Array.isArray(data.messages)) return null;
|
|
225
191
|
return data;
|
|
226
192
|
} catch {
|
|
@@ -363,8 +329,8 @@ function getChatIndexStatus() {
|
|
|
363
329
|
chunksFileSizeBytes: 0
|
|
364
330
|
};
|
|
365
331
|
try {
|
|
366
|
-
if (
|
|
367
|
-
if (
|
|
332
|
+
if (fs.existsSync(vectorsPath())) status.vecFileSizeBytes = fs.statSync(vectorsPath()).size;
|
|
333
|
+
if (fs.existsSync(chunksPath())) status.chunksFileSizeBytes = fs.statSync(chunksPath()).size;
|
|
368
334
|
} catch {
|
|
369
335
|
}
|
|
370
336
|
const idx = readIndexFile();
|