engine7 7.1.17 → 7.1.19
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/cli.mjs +22 -8
- package/dist/engine-startup.mjs +915 -561
- package/dist/main.mjs +918 -564
- package/package.json +1 -1
package/dist/main.mjs
CHANGED
|
@@ -2383,9 +2383,9 @@ function isAutoMemPath(absolutePath, workspace) {
|
|
|
2383
2383
|
return normalizedPath.startsWith(getAutoMemPath(workspace));
|
|
2384
2384
|
}
|
|
2385
2385
|
async function ensureMemoryDirExists(memoryDir) {
|
|
2386
|
-
const
|
|
2386
|
+
const fs55 = await import("node:fs");
|
|
2387
2387
|
try {
|
|
2388
|
-
await
|
|
2388
|
+
await fs55.promises.mkdir(memoryDir, { recursive: true });
|
|
2389
2389
|
} catch (e) {
|
|
2390
2390
|
const code = e?.code;
|
|
2391
2391
|
if (code !== "EEXIST") {
|
|
@@ -4758,7 +4758,7 @@ async function acquireLock(inboxPath) {
|
|
|
4758
4758
|
for (let i = 0; i < LOCK_RETRIES; i++) {
|
|
4759
4759
|
if (await isLockStale(lockPath2)) {
|
|
4760
4760
|
try {
|
|
4761
|
-
await import("node:fs/promises").then((
|
|
4761
|
+
await import("node:fs/promises").then((fs55) => fs55.rm(lockPath2, { force: true }));
|
|
4762
4762
|
} catch {
|
|
4763
4763
|
}
|
|
4764
4764
|
}
|
|
@@ -4766,7 +4766,7 @@ async function acquireLock(inboxPath) {
|
|
|
4766
4766
|
await writeFile2(lockPath2, `${process.pid}-${Date.now()}`, { encoding: "utf-8", flag: "wx" });
|
|
4767
4767
|
return async () => {
|
|
4768
4768
|
try {
|
|
4769
|
-
await import("node:fs/promises").then((
|
|
4769
|
+
await import("node:fs/promises").then((fs55) => fs55.rm(lockPath2, { force: true }));
|
|
4770
4770
|
} catch {
|
|
4771
4771
|
}
|
|
4772
4772
|
};
|
|
@@ -5865,11 +5865,11 @@ async function readLastConsolidatedAt(memoryDir) {
|
|
|
5865
5865
|
}
|
|
5866
5866
|
}
|
|
5867
5867
|
async function tryAcquireConsolidationLock(memoryDir) {
|
|
5868
|
-
const
|
|
5868
|
+
const path56 = lockPath(memoryDir);
|
|
5869
5869
|
let mtimeMs;
|
|
5870
5870
|
let holderPid;
|
|
5871
5871
|
try {
|
|
5872
|
-
const [s2, raw] = await Promise.all([stat3(
|
|
5872
|
+
const [s2, raw] = await Promise.all([stat3(path56), readFile5(path56, "utf8")]);
|
|
5873
5873
|
mtimeMs = s2.mtimeMs;
|
|
5874
5874
|
const parsed = parseInt(raw.trim(), 10);
|
|
5875
5875
|
holderPid = Number.isFinite(parsed) ? parsed : void 0;
|
|
@@ -5882,10 +5882,10 @@ async function tryAcquireConsolidationLock(memoryDir) {
|
|
|
5882
5882
|
}
|
|
5883
5883
|
}
|
|
5884
5884
|
await mkdir3(memoryDir, { recursive: true });
|
|
5885
|
-
await writeFile4(
|
|
5885
|
+
await writeFile4(path56, String(process.pid));
|
|
5886
5886
|
let verify2;
|
|
5887
5887
|
try {
|
|
5888
|
-
verify2 = await readFile5(
|
|
5888
|
+
verify2 = await readFile5(path56, "utf8");
|
|
5889
5889
|
} catch {
|
|
5890
5890
|
return null;
|
|
5891
5891
|
}
|
|
@@ -5893,15 +5893,15 @@ async function tryAcquireConsolidationLock(memoryDir) {
|
|
|
5893
5893
|
return mtimeMs ?? 0;
|
|
5894
5894
|
}
|
|
5895
5895
|
async function rollbackConsolidationLock(memoryDir, priorMtime) {
|
|
5896
|
-
const
|
|
5896
|
+
const path56 = lockPath(memoryDir);
|
|
5897
5897
|
try {
|
|
5898
5898
|
if (priorMtime === 0) {
|
|
5899
|
-
await unlink(
|
|
5899
|
+
await unlink(path56);
|
|
5900
5900
|
return;
|
|
5901
5901
|
}
|
|
5902
|
-
await writeFile4(
|
|
5902
|
+
await writeFile4(path56, "");
|
|
5903
5903
|
const t = priorMtime / 1e3;
|
|
5904
|
-
await utimes(
|
|
5904
|
+
await utimes(path56, t, t);
|
|
5905
5905
|
} catch (e) {
|
|
5906
5906
|
console.log(`[autoDream] rollback failed: ${e.message} \u2014 next trigger delayed to minHours`);
|
|
5907
5907
|
}
|
|
@@ -6233,30 +6233,30 @@ __export(TodoWriteTool_exports, {
|
|
|
6233
6233
|
initTodoStore: () => initTodoStore,
|
|
6234
6234
|
loadTodos: () => loadTodos
|
|
6235
6235
|
});
|
|
6236
|
-
import
|
|
6237
|
-
import
|
|
6236
|
+
import fs31 from "node:fs";
|
|
6237
|
+
import path31 from "node:path";
|
|
6238
6238
|
function initTodoStore(stateDir) {
|
|
6239
|
-
todosDir =
|
|
6240
|
-
if (!
|
|
6241
|
-
|
|
6239
|
+
todosDir = path31.join(stateDir, "todos");
|
|
6240
|
+
if (!fs31.existsSync(todosDir)) {
|
|
6241
|
+
fs31.mkdirSync(todosDir, { recursive: true });
|
|
6242
6242
|
}
|
|
6243
6243
|
}
|
|
6244
6244
|
function todoFilePath(sessionId) {
|
|
6245
|
-
return
|
|
6245
|
+
return path31.join(todosDir, `${sessionId}.json`);
|
|
6246
6246
|
}
|
|
6247
6247
|
function loadTodos(sessionId) {
|
|
6248
6248
|
if (!todosDir) return [];
|
|
6249
6249
|
try {
|
|
6250
6250
|
const filePath = todoFilePath(sessionId);
|
|
6251
|
-
if (!
|
|
6252
|
-
return JSON.parse(
|
|
6251
|
+
if (!fs31.existsSync(filePath)) return [];
|
|
6252
|
+
return JSON.parse(fs31.readFileSync(filePath, "utf-8"));
|
|
6253
6253
|
} catch {
|
|
6254
6254
|
return [];
|
|
6255
6255
|
}
|
|
6256
6256
|
}
|
|
6257
6257
|
function saveTodos(sessionId, todos) {
|
|
6258
6258
|
if (!todosDir) return;
|
|
6259
|
-
|
|
6259
|
+
fs31.writeFileSync(todoFilePath(sessionId), JSON.stringify(todos, null, 2), "utf-8");
|
|
6260
6260
|
}
|
|
6261
6261
|
var todosDir;
|
|
6262
6262
|
var init_TodoWriteTool = __esm({
|
|
@@ -6337,28 +6337,28 @@ __export(tasks_exports, {
|
|
|
6337
6337
|
unassignTeammateTasks: () => unassignTeammateTasks,
|
|
6338
6338
|
updateTask: () => updateTask
|
|
6339
6339
|
});
|
|
6340
|
-
import * as
|
|
6341
|
-
import * as
|
|
6340
|
+
import * as fs33 from "node:fs";
|
|
6341
|
+
import * as path33 from "node:path";
|
|
6342
6342
|
function sanitizePathComponent2(input) {
|
|
6343
6343
|
return input.replace(/[^a-zA-Z0-9_-]/g, "-");
|
|
6344
6344
|
}
|
|
6345
6345
|
function getTasksDir2(stateDir, listId) {
|
|
6346
|
-
return
|
|
6346
|
+
return path33.join(stateDir, "tasks", sanitizePathComponent2(listId));
|
|
6347
6347
|
}
|
|
6348
6348
|
function getTaskPath(stateDir, listId, taskId) {
|
|
6349
|
-
return
|
|
6349
|
+
return path33.join(getTasksDir2(stateDir, listId), `${sanitizePathComponent2(taskId)}.json`);
|
|
6350
6350
|
}
|
|
6351
6351
|
function ensureTasksDir2(stateDir, listId) {
|
|
6352
6352
|
const dir = getTasksDir2(stateDir, listId);
|
|
6353
|
-
|
|
6353
|
+
fs33.mkdirSync(dir, { recursive: true });
|
|
6354
6354
|
return dir;
|
|
6355
6355
|
}
|
|
6356
6356
|
function getHighWaterMarkPath(stateDir, listId) {
|
|
6357
|
-
return
|
|
6357
|
+
return path33.join(getTasksDir2(stateDir, listId), HIGH_WATER_MARK_FILE);
|
|
6358
6358
|
}
|
|
6359
6359
|
function readHighWaterMark(stateDir, listId) {
|
|
6360
6360
|
try {
|
|
6361
|
-
const content =
|
|
6361
|
+
const content = fs33.readFileSync(getHighWaterMarkPath(stateDir, listId), "utf-8").trim();
|
|
6362
6362
|
const value = parseInt(content, 10);
|
|
6363
6363
|
return isNaN(value) ? 0 : value;
|
|
6364
6364
|
} catch {
|
|
@@ -6366,13 +6366,13 @@ function readHighWaterMark(stateDir, listId) {
|
|
|
6366
6366
|
}
|
|
6367
6367
|
}
|
|
6368
6368
|
function writeHighWaterMark(stateDir, listId, value) {
|
|
6369
|
-
|
|
6369
|
+
fs33.writeFileSync(getHighWaterMarkPath(stateDir, listId), String(value));
|
|
6370
6370
|
}
|
|
6371
6371
|
function findHighestTaskIdFromFiles(stateDir, listId) {
|
|
6372
6372
|
const dir = getTasksDir2(stateDir, listId);
|
|
6373
6373
|
let files;
|
|
6374
6374
|
try {
|
|
6375
|
-
files =
|
|
6375
|
+
files = fs33.readdirSync(dir);
|
|
6376
6376
|
} catch {
|
|
6377
6377
|
return 0;
|
|
6378
6378
|
}
|
|
@@ -6398,14 +6398,14 @@ function createTask(stateDir, listId, taskData) {
|
|
|
6398
6398
|
const id = String(highestId + 1);
|
|
6399
6399
|
const task = { id, ...taskData };
|
|
6400
6400
|
const filePath = getTaskPath(stateDir, listId, id);
|
|
6401
|
-
|
|
6401
|
+
fs33.writeFileSync(filePath, JSON.stringify(task, null, 2));
|
|
6402
6402
|
return id;
|
|
6403
6403
|
});
|
|
6404
6404
|
}
|
|
6405
6405
|
function getTask2(stateDir, listId, taskId) {
|
|
6406
6406
|
const filePath = getTaskPath(stateDir, listId, taskId);
|
|
6407
6407
|
try {
|
|
6408
|
-
const content =
|
|
6408
|
+
const content = fs33.readFileSync(filePath, "utf-8");
|
|
6409
6409
|
return JSON.parse(content);
|
|
6410
6410
|
} catch {
|
|
6411
6411
|
return null;
|
|
@@ -6415,7 +6415,7 @@ function listTasks2(stateDir, listId) {
|
|
|
6415
6415
|
const dir = getTasksDir2(stateDir, listId);
|
|
6416
6416
|
let files;
|
|
6417
6417
|
try {
|
|
6418
|
-
files =
|
|
6418
|
+
files = fs33.readdirSync(dir);
|
|
6419
6419
|
} catch {
|
|
6420
6420
|
return [];
|
|
6421
6421
|
}
|
|
@@ -6427,7 +6427,7 @@ function updateTask(stateDir, listId, taskId, updates) {
|
|
|
6427
6427
|
if (!existing) return null;
|
|
6428
6428
|
const updated = { ...existing, ...updates, id: taskId };
|
|
6429
6429
|
const filePath = getTaskPath(stateDir, listId, taskId);
|
|
6430
|
-
|
|
6430
|
+
fs33.writeFileSync(filePath, JSON.stringify(updated, null, 2));
|
|
6431
6431
|
return updated;
|
|
6432
6432
|
}
|
|
6433
6433
|
function deleteTask(stateDir, listId, taskId) {
|
|
@@ -6441,7 +6441,7 @@ function deleteTask(stateDir, listId, taskId) {
|
|
|
6441
6441
|
}
|
|
6442
6442
|
}
|
|
6443
6443
|
try {
|
|
6444
|
-
|
|
6444
|
+
fs33.unlinkSync(filePath);
|
|
6445
6445
|
} catch {
|
|
6446
6446
|
return false;
|
|
6447
6447
|
}
|
|
@@ -6559,15 +6559,15 @@ var read_exports = {};
|
|
|
6559
6559
|
__export(read_exports, {
|
|
6560
6560
|
readFileState: () => readFileState
|
|
6561
6561
|
});
|
|
6562
|
-
import * as
|
|
6563
|
-
import * as
|
|
6562
|
+
import * as fs34 from "node:fs";
|
|
6563
|
+
import * as path34 from "node:path";
|
|
6564
6564
|
function isBlockedDevicePath(filePath) {
|
|
6565
6565
|
if (BLOCKED_DEVICE_PATHS.has(filePath)) return true;
|
|
6566
6566
|
if (filePath.startsWith("/proc/") && (filePath.endsWith("/fd/0") || filePath.endsWith("/fd/1") || filePath.endsWith("/fd/2"))) return true;
|
|
6567
6567
|
return false;
|
|
6568
6568
|
}
|
|
6569
6569
|
function checkReadLoop(filePath, offset, limit) {
|
|
6570
|
-
const stat8 =
|
|
6570
|
+
const stat8 = fs34.statSync(filePath);
|
|
6571
6571
|
const mtimeMs = stat8.mtimeMs;
|
|
6572
6572
|
const prev = readHistory.get(filePath);
|
|
6573
6573
|
if (prev && prev.offset === offset && prev.limit === limit && prev.mtimeMs === mtimeMs) {
|
|
@@ -6581,19 +6581,19 @@ function checkReadLoop(filePath, offset, limit) {
|
|
|
6581
6581
|
return null;
|
|
6582
6582
|
}
|
|
6583
6583
|
function readFileContent(filePath) {
|
|
6584
|
-
const fd =
|
|
6584
|
+
const fd = fs34.openSync(filePath, "r");
|
|
6585
6585
|
const bom = Buffer.alloc(2);
|
|
6586
|
-
|
|
6587
|
-
|
|
6586
|
+
fs34.readSync(fd, bom, 0, 2, 0);
|
|
6587
|
+
fs34.closeSync(fd);
|
|
6588
6588
|
let encoding = "utf8";
|
|
6589
6589
|
if (bom[0] === 255 && bom[1] === 254) {
|
|
6590
6590
|
encoding = "utf16le";
|
|
6591
6591
|
}
|
|
6592
|
-
const stat8 =
|
|
6592
|
+
const stat8 = fs34.statSync(filePath);
|
|
6593
6593
|
if (stat8.size > MAX_FILE_SIZE) {
|
|
6594
6594
|
throw new Error(`\u6587\u4EF6\u592A\u5927 (${(stat8.size / 1024).toFixed(1)}KB)\uFF0C\u8D85\u8FC7 ${MAX_FILE_SIZE / 1024}KB \u9650\u5236\u3002\u8BF7\u4F7F\u7528 offset + limit \u5206\u6BB5\u8BFB\u53D6\u3002`);
|
|
6595
6595
|
}
|
|
6596
|
-
const raw =
|
|
6596
|
+
const raw = fs34.readFileSync(filePath, encoding);
|
|
6597
6597
|
const content = raw.toString().replaceAll("\r\n", "\n");
|
|
6598
6598
|
return { content, encoding };
|
|
6599
6599
|
}
|
|
@@ -6735,11 +6735,11 @@ Usage:
|
|
|
6735
6735
|
} catch (e) {
|
|
6736
6736
|
return { content: e.message, isError: true };
|
|
6737
6737
|
}
|
|
6738
|
-
if (!
|
|
6738
|
+
if (!fs34.existsSync(filePath)) {
|
|
6739
6739
|
return { content: `\u6587\u4EF6\u4E0D\u5B58\u5728: ${filePath}`, isError: true };
|
|
6740
6740
|
}
|
|
6741
|
-
const stat8 =
|
|
6742
|
-
const baseName =
|
|
6741
|
+
const stat8 = fs34.statSync(filePath);
|
|
6742
|
+
const baseName = path34.basename(filePath).toUpperCase();
|
|
6743
6743
|
if (BLOCKED_BASENAMES.has(baseName)) {
|
|
6744
6744
|
return { content: `\u8BBE\u5907\u6587\u4EF6\u4E0D\u652F\u6301\u8BFB\u53D6: ${filePath}`, isError: true };
|
|
6745
6745
|
}
|
|
@@ -6747,11 +6747,11 @@ Usage:
|
|
|
6747
6747
|
return { content: `\u8BBE\u5907\u6587\u4EF6\u4F1A\u963B\u585E\u6216\u4EA7\u751F\u65E0\u9650\u8F93\u51FA: ${filePath}`, isError: true };
|
|
6748
6748
|
}
|
|
6749
6749
|
if (stat8.isDirectory()) {
|
|
6750
|
-
const entries =
|
|
6750
|
+
const entries = fs34.readdirSync(filePath);
|
|
6751
6751
|
const items = entries.map((e) => {
|
|
6752
|
-
const full =
|
|
6752
|
+
const full = path34.join(filePath, e);
|
|
6753
6753
|
try {
|
|
6754
|
-
const s2 =
|
|
6754
|
+
const s2 = fs34.statSync(full);
|
|
6755
6755
|
return s2.isDirectory() ? `${e}/` : e;
|
|
6756
6756
|
} catch {
|
|
6757
6757
|
return e;
|
|
@@ -6760,7 +6760,7 @@ Usage:
|
|
|
6760
6760
|
return { content: `\u76EE\u5F55 (${entries.length} \u9879):
|
|
6761
6761
|
${items.join("\n")}` };
|
|
6762
6762
|
}
|
|
6763
|
-
const ext =
|
|
6763
|
+
const ext = path34.extname(filePath).toLowerCase();
|
|
6764
6764
|
if (BINARY_EXTENSIONS.has(ext)) {
|
|
6765
6765
|
return { content: `\u4E8C\u8FDB\u5236\u6587\u4EF6\u4E0D\u652F\u6301\u8BFB\u53D6 (${ext}): ${filePath}`, isError: true };
|
|
6766
6766
|
}
|
|
@@ -6808,22 +6808,22 @@ ${result}` : result };
|
|
|
6808
6808
|
|
|
6809
6809
|
// src/tools/write.ts
|
|
6810
6810
|
var write_exports = {};
|
|
6811
|
-
import * as
|
|
6812
|
-
import * as
|
|
6811
|
+
import * as fs35 from "node:fs";
|
|
6812
|
+
import * as path35 from "node:path";
|
|
6813
6813
|
function isBlockedPath(filePath) {
|
|
6814
6814
|
return BLOCKED_PATTERNS.some((p2) => p2.test(filePath));
|
|
6815
6815
|
}
|
|
6816
6816
|
function atomicWrite(filePath, content) {
|
|
6817
6817
|
const tmpPath = filePath + ".tmp." + Date.now() + ".write";
|
|
6818
|
-
|
|
6818
|
+
fs35.writeFileSync(tmpPath, content, "utf-8");
|
|
6819
6819
|
try {
|
|
6820
|
-
|
|
6820
|
+
fs35.renameSync(tmpPath, filePath);
|
|
6821
6821
|
} catch (e) {
|
|
6822
6822
|
try {
|
|
6823
|
-
|
|
6823
|
+
fs35.unlinkSync(tmpPath);
|
|
6824
6824
|
} catch {
|
|
6825
6825
|
}
|
|
6826
|
-
|
|
6826
|
+
fs35.writeFileSync(filePath, content, "utf-8");
|
|
6827
6827
|
}
|
|
6828
6828
|
}
|
|
6829
6829
|
function simpleDiff(oldContent, newContent) {
|
|
@@ -6917,15 +6917,15 @@ Usage:
|
|
|
6917
6917
|
}
|
|
6918
6918
|
const rawContent = args2.content;
|
|
6919
6919
|
const content = rawContent.replaceAll("\r\n", "\n");
|
|
6920
|
-
if (
|
|
6920
|
+
if (fs35.existsSync(filePath) && fs35.statSync(filePath).isDirectory()) {
|
|
6921
6921
|
return { content: `\u8DEF\u5F84\u662F\u76EE\u5F55\u4E0D\u662F\u6587\u4EF6: ${filePath}`, isError: true };
|
|
6922
6922
|
}
|
|
6923
6923
|
let oldContent = null;
|
|
6924
6924
|
let isCreate = true;
|
|
6925
|
-
if (
|
|
6925
|
+
if (fs35.existsSync(filePath)) {
|
|
6926
6926
|
isCreate = false;
|
|
6927
6927
|
try {
|
|
6928
|
-
oldContent =
|
|
6928
|
+
oldContent = fs35.readFileSync(filePath, "utf-8").replaceAll("\r\n", "\n");
|
|
6929
6929
|
} catch {
|
|
6930
6930
|
isCreate = true;
|
|
6931
6931
|
}
|
|
@@ -6941,10 +6941,10 @@ Usage:
|
|
|
6941
6941
|
isError: true
|
|
6942
6942
|
};
|
|
6943
6943
|
}
|
|
6944
|
-
const currentStat =
|
|
6944
|
+
const currentStat = fs35.statSync(filePath);
|
|
6945
6945
|
const lastWriteTime = Math.floor(currentStat.mtimeMs);
|
|
6946
6946
|
if (lastWriteTime > readState.timestamp) {
|
|
6947
|
-
const currentContent =
|
|
6947
|
+
const currentContent = fs35.readFileSync(filePath, "utf-8").replaceAll("\r\n", "\n");
|
|
6948
6948
|
if (currentContent !== oldContent) {
|
|
6949
6949
|
return {
|
|
6950
6950
|
content: `\u6587\u4EF6\u5728\u8BFB\u53D6\u540E\u88AB\u4FEE\u6539\u3002\u8BF7\u5148\u91CD\u65B0\u8BFB\u53D6\u6587\u4EF6\u518D\u5199\u5165: ${filePath}`,
|
|
@@ -6953,9 +6953,9 @@ Usage:
|
|
|
6953
6953
|
}
|
|
6954
6954
|
}
|
|
6955
6955
|
}
|
|
6956
|
-
const dir =
|
|
6956
|
+
const dir = path35.dirname(filePath);
|
|
6957
6957
|
try {
|
|
6958
|
-
|
|
6958
|
+
fs35.mkdirSync(dir, { recursive: true });
|
|
6959
6959
|
} catch (e) {
|
|
6960
6960
|
return { content: `\u65E0\u6CD5\u521B\u5EFA\u76EE\u5F55: ${dir} \u2014 ${e.message}`, isError: true };
|
|
6961
6961
|
}
|
|
@@ -6964,11 +6964,11 @@ Usage:
|
|
|
6964
6964
|
} catch (e) {
|
|
6965
6965
|
return { content: `\u5199\u5165\u5931\u8D25: ${e.message}`, isError: true };
|
|
6966
6966
|
}
|
|
6967
|
-
readFileState.set(filePath, { timestamp:
|
|
6967
|
+
readFileState.set(filePath, { timestamp: fs35.statSync(filePath).mtimeMs });
|
|
6968
6968
|
const action = isCreate ? "\u521B\u5EFA" : "\u66F4\u65B0";
|
|
6969
6969
|
const lines = content.split("\n").length;
|
|
6970
6970
|
const chars = content.length;
|
|
6971
|
-
const stat8 =
|
|
6971
|
+
const stat8 = fs35.statSync(filePath);
|
|
6972
6972
|
let diff = "";
|
|
6973
6973
|
if (!isCreate && oldContent !== null) {
|
|
6974
6974
|
diff = `
|
|
@@ -6988,8 +6988,8 @@ ${simpleDiff(oldContent, content)}`;
|
|
|
6988
6988
|
|
|
6989
6989
|
// src/tools/edit.ts
|
|
6990
6990
|
var edit_exports = {};
|
|
6991
|
-
import * as
|
|
6992
|
-
import * as
|
|
6991
|
+
import * as fs36 from "node:fs";
|
|
6992
|
+
import * as path36 from "node:path";
|
|
6993
6993
|
function normalizeQuotes(str) {
|
|
6994
6994
|
return str.replaceAll(LEFT_SINGLE_CURLY, "'").replaceAll(RIGHT_SINGLE_CURLY, "'").replaceAll(LEFT_DOUBLE_CURLY, '"').replaceAll(RIGHT_DOUBLE_CURLY, '"');
|
|
6995
6995
|
}
|
|
@@ -7142,7 +7142,7 @@ Usage:
|
|
|
7142
7142
|
}
|
|
7143
7143
|
let fileContent = null;
|
|
7144
7144
|
try {
|
|
7145
|
-
const stat8 =
|
|
7145
|
+
const stat8 = fs36.statSync(filePath);
|
|
7146
7146
|
if (stat8.isDirectory()) {
|
|
7147
7147
|
return { content: `\u8DEF\u5F84\u662F\u76EE\u5F55\u4E0D\u662F\u6587\u4EF6: ${filePath}`, isError: true };
|
|
7148
7148
|
}
|
|
@@ -7152,21 +7152,21 @@ Usage:
|
|
|
7152
7152
|
} catch (e) {
|
|
7153
7153
|
if (e.code === "ENOENT") {
|
|
7154
7154
|
if (oldString === "") {
|
|
7155
|
-
const dir =
|
|
7156
|
-
|
|
7157
|
-
|
|
7158
|
-
readFileState.set(filePath, { timestamp:
|
|
7155
|
+
const dir = path36.dirname(filePath);
|
|
7156
|
+
fs36.mkdirSync(dir, { recursive: true });
|
|
7157
|
+
fs36.writeFileSync(filePath, newString, "utf-8");
|
|
7158
|
+
readFileState.set(filePath, { timestamp: fs36.statSync(filePath).mtimeMs });
|
|
7159
7159
|
return { content: `\u521B\u5EFA\u6587\u4EF6: ${filePath} (${newString.split("\n").length} \u884C)` };
|
|
7160
7160
|
}
|
|
7161
7161
|
return { content: `\u6587\u4EF6\u4E0D\u5B58\u5728: ${filePath}`, isError: true };
|
|
7162
7162
|
}
|
|
7163
7163
|
throw e;
|
|
7164
7164
|
}
|
|
7165
|
-
const rawContent =
|
|
7165
|
+
const rawContent = fs36.readFileSync(filePath, "utf-8");
|
|
7166
7166
|
fileContent = rawContent.replaceAll("\r\n", "\n");
|
|
7167
7167
|
if (oldString === "" && fileContent.trim() === "") {
|
|
7168
|
-
|
|
7169
|
-
readFileState.set(filePath, { timestamp:
|
|
7168
|
+
fs36.writeFileSync(filePath, newString, "utf-8");
|
|
7169
|
+
readFileState.set(filePath, { timestamp: fs36.statSync(filePath).mtimeMs });
|
|
7170
7170
|
return { content: `\u5199\u5165\u7A7A\u6587\u4EF6: ${filePath} (${newString.split("\n").length} \u884C)` };
|
|
7171
7171
|
}
|
|
7172
7172
|
const readState = readFileState.get(filePath);
|
|
@@ -7176,11 +7176,11 @@ Usage:
|
|
|
7176
7176
|
isError: true
|
|
7177
7177
|
};
|
|
7178
7178
|
}
|
|
7179
|
-
const currentStat =
|
|
7179
|
+
const currentStat = fs36.statSync(filePath);
|
|
7180
7180
|
const lastWriteTime = Math.floor(currentStat.mtimeMs);
|
|
7181
7181
|
if (lastWriteTime > readState.timestamp) {
|
|
7182
7182
|
if (fileContent !== rawContent.replaceAll("\r\n", "\n")) {
|
|
7183
|
-
if (fileContent !==
|
|
7183
|
+
if (fileContent !== fs36.readFileSync(filePath, "utf-8").replaceAll("\r\n", "\n")) {
|
|
7184
7184
|
return {
|
|
7185
7185
|
content: `\u6587\u4EF6\u5728\u8BFB\u53D6\u540E\u88AB\u4FEE\u6539\u3002\u8BF7\u5148\u91CD\u65B0\u8BFB\u53D6\u6587\u4EF6\u518D\u7F16\u8F91: ${filePath}`,
|
|
7186
7186
|
isError: true
|
|
@@ -7212,8 +7212,8 @@ ${preview}
|
|
|
7212
7212
|
const actualNewString = preserveQuoteStyle(oldString, actualOldString, newString);
|
|
7213
7213
|
const diffView = generateEditDiff(fileContent, actualOldString, actualNewString);
|
|
7214
7214
|
const newContent = applyEditToFile(fileContent, actualOldString, actualNewString, replaceAll);
|
|
7215
|
-
|
|
7216
|
-
readFileState.set(filePath, { timestamp:
|
|
7215
|
+
fs36.writeFileSync(filePath, newContent, "utf-8");
|
|
7216
|
+
readFileState.set(filePath, { timestamp: fs36.statSync(filePath).mtimeMs });
|
|
7217
7217
|
const strategy = actualOldString === oldString ? "\u7CBE\u786E\u5339\u914D" : "\u5F15\u53F7\u89C4\u8303\u5316\u5339\u914D";
|
|
7218
7218
|
const count = replaceAll ? matchCount : 1;
|
|
7219
7219
|
const diff = `${oldString.length}\u2192${newString.length}\u5B57\u7B26`;
|
|
@@ -7231,8 +7231,8 @@ ${diffView}`
|
|
|
7231
7231
|
|
|
7232
7232
|
// src/tools/glob.ts
|
|
7233
7233
|
var glob_exports = {};
|
|
7234
|
-
import * as
|
|
7235
|
-
import * as
|
|
7234
|
+
import * as fs37 from "node:fs";
|
|
7235
|
+
import * as path37 from "node:path";
|
|
7236
7236
|
function globMatch(pattern, filename) {
|
|
7237
7237
|
const regexStr = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*/g, "{{GLOBSTAR}}").replace(/\*/g, "[^/]*").replace(/\?/g, "[^/]").replace(/\{\{GLOBSTAR\}\}/g, ".*");
|
|
7238
7238
|
try {
|
|
@@ -7252,18 +7252,18 @@ function findFiles(dir, pattern, limit, baseDir) {
|
|
|
7252
7252
|
}
|
|
7253
7253
|
let entries;
|
|
7254
7254
|
try {
|
|
7255
|
-
entries =
|
|
7255
|
+
entries = fs37.readdirSync(currentDir, { withFileTypes: true });
|
|
7256
7256
|
} catch {
|
|
7257
7257
|
return;
|
|
7258
7258
|
}
|
|
7259
7259
|
for (const entry of entries) {
|
|
7260
7260
|
if (truncated) return;
|
|
7261
|
-
const fullPath =
|
|
7261
|
+
const fullPath = path37.join(currentDir, entry.name);
|
|
7262
7262
|
if (entry.isDirectory()) {
|
|
7263
7263
|
if (VCS_DIRS.has(entry.name)) continue;
|
|
7264
7264
|
walk(fullPath);
|
|
7265
7265
|
} else if (entry.isFile()) {
|
|
7266
|
-
const relativePath =
|
|
7266
|
+
const relativePath = path37.relative(baseDir, fullPath).replace(/\\/g, "/");
|
|
7267
7267
|
const patternsToTry = [pattern];
|
|
7268
7268
|
if (pattern.startsWith("**/")) {
|
|
7269
7269
|
patternsToTry.push(pattern.slice(3));
|
|
@@ -7273,7 +7273,7 @@ function findFiles(dir, pattern, limit, baseDir) {
|
|
|
7273
7273
|
);
|
|
7274
7274
|
if (matched) {
|
|
7275
7275
|
try {
|
|
7276
|
-
const stat8 =
|
|
7276
|
+
const stat8 = fs37.statSync(fullPath);
|
|
7277
7277
|
results.push({ path: fullPath, mtimeMs: stat8.mtimeMs });
|
|
7278
7278
|
} catch {
|
|
7279
7279
|
}
|
|
@@ -7290,7 +7290,7 @@ function findFiles(dir, pattern, limit, baseDir) {
|
|
|
7290
7290
|
};
|
|
7291
7291
|
}
|
|
7292
7292
|
function toRelativePath(absolutePath, cwd) {
|
|
7293
|
-
if (absolutePath.startsWith(cwd +
|
|
7293
|
+
if (absolutePath.startsWith(cwd + path37.sep)) {
|
|
7294
7294
|
return absolutePath.slice(cwd.length + 1);
|
|
7295
7295
|
}
|
|
7296
7296
|
return absolutePath;
|
|
@@ -7323,10 +7323,10 @@ var init_glob = __esm({
|
|
|
7323
7323
|
const searchPath = args2.path ? resolvePath(args2.path, ctx.workspace) : ctx.workspace;
|
|
7324
7324
|
const pattern = args2.pattern;
|
|
7325
7325
|
const limit = args2.limit || DEFAULT_LIMIT;
|
|
7326
|
-
if (!
|
|
7326
|
+
if (!fs37.existsSync(searchPath)) {
|
|
7327
7327
|
return { content: `\u76EE\u5F55\u4E0D\u5B58\u5728: ${searchPath}`, isError: true };
|
|
7328
7328
|
}
|
|
7329
|
-
if (!
|
|
7329
|
+
if (!fs37.statSync(searchPath).isDirectory()) {
|
|
7330
7330
|
return { content: `\u8DEF\u5F84\u4E0D\u662F\u76EE\u5F55: ${searchPath}`, isError: true };
|
|
7331
7331
|
}
|
|
7332
7332
|
const start = Date.now();
|
|
@@ -7351,7 +7351,7 @@ ${filenames.join("\n")}${truncatedNote}`
|
|
|
7351
7351
|
// src/tools/grep.ts
|
|
7352
7352
|
var grep_exports = {};
|
|
7353
7353
|
import { execFile as execFile2 } from "node:child_process";
|
|
7354
|
-
import * as
|
|
7354
|
+
import * as path38 from "node:path";
|
|
7355
7355
|
function ripGrep(args2, searchPath, signal) {
|
|
7356
7356
|
return new Promise((resolve12) => {
|
|
7357
7357
|
const fullArgs = [...args2, searchPath];
|
|
@@ -7383,7 +7383,7 @@ function applyHeadLimit(items, limit, offset = 0) {
|
|
|
7383
7383
|
};
|
|
7384
7384
|
}
|
|
7385
7385
|
function toRelativePath2(absolutePath, cwd) {
|
|
7386
|
-
if (absolutePath.startsWith(cwd +
|
|
7386
|
+
if (absolutePath.startsWith(cwd + path38.sep)) {
|
|
7387
7387
|
return absolutePath.slice(cwd.length + 1);
|
|
7388
7388
|
}
|
|
7389
7389
|
if (absolutePath.startsWith(cwd)) {
|
|
@@ -10051,8 +10051,8 @@ var init_web_fetch = __esm({
|
|
|
10051
10051
|
});
|
|
10052
10052
|
|
|
10053
10053
|
// src/cron/tasks.ts
|
|
10054
|
-
import
|
|
10055
|
-
import
|
|
10054
|
+
import fs38 from "node:fs";
|
|
10055
|
+
import path39 from "node:path";
|
|
10056
10056
|
import crypto5 from "node:crypto";
|
|
10057
10057
|
function getStorageDir() {
|
|
10058
10058
|
return storageDir;
|
|
@@ -10060,14 +10060,14 @@ function getStorageDir() {
|
|
|
10060
10060
|
async function withFileLock(lockPath2, fn) {
|
|
10061
10061
|
for (let attempt = 0; attempt < LOCK_RETRY_COUNT; attempt++) {
|
|
10062
10062
|
try {
|
|
10063
|
-
|
|
10063
|
+
fs38.mkdirSync(lockPath2, { recursive: false });
|
|
10064
10064
|
break;
|
|
10065
10065
|
} catch (err) {
|
|
10066
10066
|
if (err.code !== "EEXIST") throw err;
|
|
10067
10067
|
try {
|
|
10068
|
-
const stat8 =
|
|
10068
|
+
const stat8 = fs38.statSync(lockPath2);
|
|
10069
10069
|
if (Date.now() - stat8.mtimeMs > LOCK_STALE_THRESHOLD_MS) {
|
|
10070
|
-
|
|
10070
|
+
fs38.rmSync(lockPath2, { recursive: true, force: true });
|
|
10071
10071
|
continue;
|
|
10072
10072
|
}
|
|
10073
10073
|
} catch {
|
|
@@ -10083,22 +10083,22 @@ async function withFileLock(lockPath2, fn) {
|
|
|
10083
10083
|
return fn();
|
|
10084
10084
|
} finally {
|
|
10085
10085
|
try {
|
|
10086
|
-
|
|
10086
|
+
fs38.rmSync(lockPath2, { recursive: true, force: true });
|
|
10087
10087
|
} catch {
|
|
10088
10088
|
}
|
|
10089
10089
|
}
|
|
10090
10090
|
}
|
|
10091
10091
|
function atomicWriteJSON(filePath, data) {
|
|
10092
10092
|
const tmpPath = filePath + ".tmp";
|
|
10093
|
-
|
|
10094
|
-
|
|
10093
|
+
fs38.writeFileSync(tmpPath, JSON.stringify(data, null, 2), "utf-8");
|
|
10094
|
+
fs38.renameSync(tmpPath, filePath);
|
|
10095
10095
|
}
|
|
10096
10096
|
function readTasksFromDisk() {
|
|
10097
|
-
if (!tasksFilePath || !
|
|
10097
|
+
if (!tasksFilePath || !fs38.existsSync(tasksFilePath)) {
|
|
10098
10098
|
return [];
|
|
10099
10099
|
}
|
|
10100
10100
|
try {
|
|
10101
|
-
const raw =
|
|
10101
|
+
const raw = fs38.readFileSync(tasksFilePath, "utf-8");
|
|
10102
10102
|
const store = JSON.parse(raw);
|
|
10103
10103
|
return store.tasks ?? [];
|
|
10104
10104
|
} catch (err) {
|
|
@@ -10107,7 +10107,7 @@ function readTasksFromDisk() {
|
|
|
10107
10107
|
}
|
|
10108
10108
|
}
|
|
10109
10109
|
async function writeTasksToDisk(tasks2) {
|
|
10110
|
-
const lockPath2 =
|
|
10110
|
+
const lockPath2 = path39.join(storageDir, "tasks.json.lock");
|
|
10111
10111
|
await withFileLock(lockPath2, () => {
|
|
10112
10112
|
const store = {
|
|
10113
10113
|
version: 1,
|
|
@@ -10119,9 +10119,9 @@ async function writeTasksToDisk(tasks2) {
|
|
|
10119
10119
|
}
|
|
10120
10120
|
function initTaskStore(dir) {
|
|
10121
10121
|
storageDir = dir;
|
|
10122
|
-
tasksFilePath =
|
|
10123
|
-
if (!
|
|
10124
|
-
|
|
10122
|
+
tasksFilePath = path39.join(dir, "tasks.json");
|
|
10123
|
+
if (!fs38.existsSync(dir)) {
|
|
10124
|
+
fs38.mkdirSync(dir, { recursive: true });
|
|
10125
10125
|
}
|
|
10126
10126
|
const tasks2 = readTasksFromDisk();
|
|
10127
10127
|
console.log(`[cron] Task store initialized: ${dir} (${tasks2.length} tasks loaded)`);
|
|
@@ -11032,12 +11032,12 @@ async function executeAndDeliver(task, now, deps) {
|
|
|
11032
11032
|
if (promptText.startsWith("@")) {
|
|
11033
11033
|
let filePath = promptText.slice(1).trim();
|
|
11034
11034
|
try {
|
|
11035
|
-
const
|
|
11036
|
-
const
|
|
11037
|
-
if (!
|
|
11038
|
-
filePath =
|
|
11035
|
+
const fs55 = await import("fs");
|
|
11036
|
+
const path56 = await import("path");
|
|
11037
|
+
if (!path56.isAbsolute(filePath)) {
|
|
11038
|
+
filePath = path56.join(deps.sessions["config"].stateDir, filePath);
|
|
11039
11039
|
}
|
|
11040
|
-
promptText =
|
|
11040
|
+
promptText = fs55.readFileSync(filePath, "utf-8");
|
|
11041
11041
|
console.log(`[cron] Loaded prompt from ${filePath} (${promptText.length} chars)`);
|
|
11042
11042
|
} catch (err) {
|
|
11043
11043
|
throw new Error(`Prompt file not found: ${filePath}: ${err.message}`);
|
|
@@ -11064,16 +11064,16 @@ async function executeAndDeliver(task, now, deps) {
|
|
|
11064
11064
|
let finalResult = result;
|
|
11065
11065
|
if (task.postProcess) {
|
|
11066
11066
|
try {
|
|
11067
|
-
const
|
|
11068
|
-
const
|
|
11067
|
+
const path56 = await import("path");
|
|
11068
|
+
const fs55 = await import("fs");
|
|
11069
11069
|
let scriptPath = task.postProcess;
|
|
11070
|
-
if (!
|
|
11071
|
-
scriptPath =
|
|
11070
|
+
if (!path56.isAbsolute(scriptPath)) {
|
|
11071
|
+
scriptPath = path56.join(deps.sessions["config"].stateDir, scriptPath);
|
|
11072
11072
|
}
|
|
11073
|
-
const resultsDirTmp =
|
|
11074
|
-
|
|
11075
|
-
const inputFile =
|
|
11076
|
-
|
|
11073
|
+
const resultsDirTmp = path56.join(getStorageDir(), "results");
|
|
11074
|
+
fs55.mkdirSync(resultsDirTmp, { recursive: true });
|
|
11075
|
+
const inputFile = path56.join(resultsDirTmp, `${task.id}.input.txt`);
|
|
11076
|
+
fs55.writeFileSync(inputFile, result, "utf-8");
|
|
11077
11077
|
const { execFile: execFile3 } = await import("child_process");
|
|
11078
11078
|
await new Promise((resolve12) => {
|
|
11079
11079
|
execFile3("python", [scriptPath, "main", "--file", inputFile], {
|
|
@@ -11100,12 +11100,12 @@ async function executeAndDeliver(task, now, deps) {
|
|
|
11100
11100
|
}
|
|
11101
11101
|
}
|
|
11102
11102
|
try {
|
|
11103
|
-
const
|
|
11104
|
-
const
|
|
11105
|
-
const resultsDir =
|
|
11106
|
-
|
|
11107
|
-
const resultFile =
|
|
11108
|
-
|
|
11103
|
+
const fs55 = await import("fs");
|
|
11104
|
+
const path56 = await import("path");
|
|
11105
|
+
const resultsDir = path56.join(getStorageDir(), "results");
|
|
11106
|
+
fs55.mkdirSync(resultsDir, { recursive: true });
|
|
11107
|
+
const resultFile = path56.join(resultsDir, `${task.id}.json`);
|
|
11108
|
+
fs55.writeFileSync(resultFile, JSON.stringify({
|
|
11109
11109
|
taskId: task.id,
|
|
11110
11110
|
description: task.description,
|
|
11111
11111
|
executedAt: now.toISOString(),
|
|
@@ -11352,30 +11352,30 @@ function registerCronTools() {
|
|
|
11352
11352
|
}
|
|
11353
11353
|
},
|
|
11354
11354
|
handler: async (args2) => {
|
|
11355
|
-
const
|
|
11356
|
-
const
|
|
11357
|
-
const resultsDir =
|
|
11358
|
-
if (!
|
|
11355
|
+
const fs55 = await import("fs");
|
|
11356
|
+
const path56 = await import("path");
|
|
11357
|
+
const resultsDir = path56.join(getStorageDir(), "results");
|
|
11358
|
+
if (!fs55.existsSync(resultsDir)) {
|
|
11359
11359
|
return { content: "\u6682\u65E0cron\u6267\u884C\u7ED3\u679C" };
|
|
11360
11360
|
}
|
|
11361
11361
|
if (args2.task_id) {
|
|
11362
|
-
const file =
|
|
11363
|
-
if (!
|
|
11362
|
+
const file = path56.join(resultsDir, `${args2.task_id}.json`);
|
|
11363
|
+
if (!fs55.existsSync(file)) {
|
|
11364
11364
|
return { content: `\u4EFB\u52A1 ${args2.task_id} \u6682\u65E0\u6267\u884C\u7ED3\u679C`, isError: true };
|
|
11365
11365
|
}
|
|
11366
|
-
const data = JSON.parse(
|
|
11366
|
+
const data = JSON.parse(fs55.readFileSync(file, "utf-8"));
|
|
11367
11367
|
return { content: `## ${data.description}
|
|
11368
11368
|
\u6267\u884C\u65F6\u95F4: ${data.executedAt}
|
|
11369
11369
|
\u7B2C${data.runCount}\u6B21\u6267\u884C
|
|
11370
11370
|
|
|
11371
11371
|
${data.result}` };
|
|
11372
11372
|
}
|
|
11373
|
-
const files =
|
|
11373
|
+
const files = fs55.readdirSync(resultsDir).filter((f2) => f2.endsWith(".json"));
|
|
11374
11374
|
if (files.length === 0) {
|
|
11375
11375
|
return { content: "\u6682\u65E0cron\u6267\u884C\u7ED3\u679C" };
|
|
11376
11376
|
}
|
|
11377
11377
|
const results = files.map((f2) => {
|
|
11378
|
-
const data = JSON.parse(
|
|
11378
|
+
const data = JSON.parse(fs55.readFileSync(path56.join(resultsDir, f2), "utf-8"));
|
|
11379
11379
|
return `### ${data.description} (${data.taskId.slice(0, 8)})
|
|
11380
11380
|
\u6267\u884C: ${data.executedAt} | \u7B2C${data.runCount}\u6B21
|
|
11381
11381
|
${data.result.slice(0, 500)}${data.result.length > 500 ? "..." : ""}`;
|
|
@@ -11491,12 +11491,12 @@ var init_wx_query = __esm({
|
|
|
11491
11491
|
handler: async (args2, _context) => {
|
|
11492
11492
|
const { findShell: findShell2 } = await Promise.resolve().then(() => (init_BashTool(), BashTool_exports));
|
|
11493
11493
|
const shell = findShell2();
|
|
11494
|
-
const { spawn:
|
|
11494
|
+
const { spawn: spawn8 } = await import("node:child_process");
|
|
11495
11495
|
const cmd = args2.command.trim();
|
|
11496
11496
|
const timeout = args2.timeout || 12e4;
|
|
11497
11497
|
const fullCmd = `${PYTHON} "${SCRIPT}" ${cmd.replace(/^python3\s+.*wx_query\.py\s*/, "")}`;
|
|
11498
11498
|
return new Promise((resolve12) => {
|
|
11499
|
-
const child =
|
|
11499
|
+
const child = spawn8(shell.shell, [...shell.args, fullCmd], {
|
|
11500
11500
|
timeout,
|
|
11501
11501
|
env: { ...process.env }
|
|
11502
11502
|
});
|
|
@@ -11757,8 +11757,8 @@ __export(license_exports, {
|
|
|
11757
11757
|
resetLicenseCache: () => resetLicenseCache
|
|
11758
11758
|
});
|
|
11759
11759
|
import * as crypto6 from "node:crypto";
|
|
11760
|
-
import * as
|
|
11761
|
-
import * as
|
|
11760
|
+
import * as fs39 from "node:fs";
|
|
11761
|
+
import * as path40 from "node:path";
|
|
11762
11762
|
function loadLicense(stateDir, devMode) {
|
|
11763
11763
|
if (_licenseChecked) return _cachedLicense;
|
|
11764
11764
|
_licenseChecked = true;
|
|
@@ -11771,13 +11771,13 @@ function loadLicense(stateDir, devMode) {
|
|
|
11771
11771
|
_cachedLicense = allActive;
|
|
11772
11772
|
return allActive;
|
|
11773
11773
|
}
|
|
11774
|
-
const licensePath =
|
|
11775
|
-
if (!
|
|
11774
|
+
const licensePath = path40.join(stateDir, "license.json");
|
|
11775
|
+
if (!fs39.existsSync(licensePath)) {
|
|
11776
11776
|
console.log("[license] No license.json found, running basic engine only");
|
|
11777
11777
|
return null;
|
|
11778
11778
|
}
|
|
11779
11779
|
try {
|
|
11780
|
-
const raw =
|
|
11780
|
+
const raw = fs39.readFileSync(licensePath, "utf-8");
|
|
11781
11781
|
const license = JSON.parse(raw);
|
|
11782
11782
|
const { signature, ...payload } = license;
|
|
11783
11783
|
if (!signature) {
|
|
@@ -11827,12 +11827,12 @@ function isFeatureLicensed(featureId) {
|
|
|
11827
11827
|
return f2?.active === true;
|
|
11828
11828
|
}
|
|
11829
11829
|
function getLicenseStatus(stateDir) {
|
|
11830
|
-
const licensePath =
|
|
11831
|
-
if (!
|
|
11830
|
+
const licensePath = path40.join(stateDir, "license.json");
|
|
11831
|
+
if (!fs39.existsSync(licensePath)) {
|
|
11832
11832
|
return { licensed: false, features: {} };
|
|
11833
11833
|
}
|
|
11834
11834
|
try {
|
|
11835
|
-
const raw =
|
|
11835
|
+
const raw = fs39.readFileSync(licensePath, "utf-8");
|
|
11836
11836
|
const license = JSON.parse(raw);
|
|
11837
11837
|
const active = loadLicense(stateDir);
|
|
11838
11838
|
return {
|
|
@@ -12126,37 +12126,37 @@ var init_memory_host_events = __esm({
|
|
|
12126
12126
|
});
|
|
12127
12127
|
|
|
12128
12128
|
// src/memory/shims/security-runtime.ts
|
|
12129
|
-
import
|
|
12130
|
-
import
|
|
12129
|
+
import path41 from "node:path";
|
|
12130
|
+
import fs40 from "node:fs";
|
|
12131
12131
|
function privateFileStore(rootDir) {
|
|
12132
12132
|
return {
|
|
12133
12133
|
read: (relPath) => {
|
|
12134
|
-
const full =
|
|
12134
|
+
const full = path41.join(rootDir, relPath);
|
|
12135
12135
|
try {
|
|
12136
|
-
return
|
|
12136
|
+
return fs40.readFileSync(full, "utf-8");
|
|
12137
12137
|
} catch {
|
|
12138
12138
|
return null;
|
|
12139
12139
|
}
|
|
12140
12140
|
},
|
|
12141
12141
|
write: (relPath, content) => {
|
|
12142
|
-
const full =
|
|
12143
|
-
|
|
12144
|
-
|
|
12142
|
+
const full = path41.join(rootDir, relPath);
|
|
12143
|
+
fs40.mkdirSync(path41.dirname(full), { recursive: true });
|
|
12144
|
+
fs40.writeFileSync(full, content, "utf-8");
|
|
12145
12145
|
},
|
|
12146
12146
|
readJsonIfExists: (relPath) => {
|
|
12147
|
-
const full =
|
|
12147
|
+
const full = path41.join(rootDir, relPath);
|
|
12148
12148
|
try {
|
|
12149
|
-
const raw =
|
|
12149
|
+
const raw = fs40.readFileSync(full, "utf-8");
|
|
12150
12150
|
return JSON.parse(raw);
|
|
12151
12151
|
} catch {
|
|
12152
12152
|
return null;
|
|
12153
12153
|
}
|
|
12154
12154
|
},
|
|
12155
12155
|
writeJson: (relPath, data, opts) => {
|
|
12156
|
-
const full =
|
|
12157
|
-
|
|
12156
|
+
const full = path41.join(rootDir, relPath);
|
|
12157
|
+
fs40.mkdirSync(path41.dirname(full), { recursive: true });
|
|
12158
12158
|
const content = JSON.stringify(data, null, 2) + (opts?.trailingNewline ? "\n" : "");
|
|
12159
|
-
|
|
12159
|
+
fs40.writeFileSync(full, content, "utf-8");
|
|
12160
12160
|
}
|
|
12161
12161
|
};
|
|
12162
12162
|
}
|
|
@@ -12210,8 +12210,8 @@ var init_memory_budget = __esm({
|
|
|
12210
12210
|
|
|
12211
12211
|
// src/memory/tools/short-term-promotion.ts
|
|
12212
12212
|
import { createHash as createHash2 } from "node:crypto";
|
|
12213
|
-
import
|
|
12214
|
-
import
|
|
12213
|
+
import fs41 from "node:fs/promises";
|
|
12214
|
+
import path42 from "node:path";
|
|
12215
12215
|
function clampScore(value) {
|
|
12216
12216
|
if (!Number.isFinite(value)) {
|
|
12217
12217
|
return 0;
|
|
@@ -12429,10 +12429,10 @@ function normalizeStore(raw, nowIso2) {
|
|
|
12429
12429
|
};
|
|
12430
12430
|
}
|
|
12431
12431
|
function resolveLockPath(workspaceDir) {
|
|
12432
|
-
return
|
|
12432
|
+
return path42.join(workspaceDir, SHORT_TERM_LOCK_RELATIVE_PATH);
|
|
12433
12433
|
}
|
|
12434
12434
|
function resolveShortTermArtifactsDir(workspaceDir) {
|
|
12435
|
-
return
|
|
12435
|
+
return path42.dirname(resolveLockPath(workspaceDir));
|
|
12436
12436
|
}
|
|
12437
12437
|
async function ensureShortTermArtifactsDir(workspaceDir) {
|
|
12438
12438
|
const artifactsDir = resolveShortTermArtifactsDir(workspaceDir);
|
|
@@ -12441,7 +12441,7 @@ async function ensureShortTermArtifactsDir(workspaceDir) {
|
|
|
12441
12441
|
await existing;
|
|
12442
12442
|
return;
|
|
12443
12443
|
}
|
|
12444
|
-
const ensuring =
|
|
12444
|
+
const ensuring = fs41.mkdir(artifactsDir, { recursive: true }).then(() => void 0).catch((err) => {
|
|
12445
12445
|
ensuredShortTermDirs.delete(artifactsDir);
|
|
12446
12446
|
throw err;
|
|
12447
12447
|
});
|
|
@@ -12472,7 +12472,7 @@ function isProcessLikelyAlive(pid) {
|
|
|
12472
12472
|
}
|
|
12473
12473
|
}
|
|
12474
12474
|
async function canStealStaleLock(lockPath2) {
|
|
12475
|
-
const ownerPid = await
|
|
12475
|
+
const ownerPid = await fs41.readFile(lockPath2, "utf-8").then((raw) => parseLockOwnerPid(raw)).catch(() => null);
|
|
12476
12476
|
if (ownerPid === null) {
|
|
12477
12477
|
return true;
|
|
12478
12478
|
}
|
|
@@ -12508,23 +12508,23 @@ async function withShortTermLock(workspaceDir, task) {
|
|
|
12508
12508
|
const startedAt = Date.now();
|
|
12509
12509
|
while (true) {
|
|
12510
12510
|
try {
|
|
12511
|
-
const lockHandle = await
|
|
12511
|
+
const lockHandle = await fs41.open(lockPath2, "wx");
|
|
12512
12512
|
await lockHandle.writeFile(`${process.pid}:${Date.now()}
|
|
12513
12513
|
`, "utf-8").catch(() => void 0);
|
|
12514
12514
|
try {
|
|
12515
12515
|
return await task();
|
|
12516
12516
|
} finally {
|
|
12517
12517
|
await lockHandle.close().catch(() => void 0);
|
|
12518
|
-
await
|
|
12518
|
+
await fs41.unlink(lockPath2).catch(() => void 0);
|
|
12519
12519
|
}
|
|
12520
12520
|
} catch (err) {
|
|
12521
12521
|
if (err?.code !== "EEXIST") {
|
|
12522
12522
|
throw err;
|
|
12523
12523
|
}
|
|
12524
|
-
const ageMs = await
|
|
12524
|
+
const ageMs = await fs41.stat(lockPath2).then((stats2) => Date.now() - stats2.mtimeMs).catch(() => 0);
|
|
12525
12525
|
if (ageMs > SHORT_TERM_LOCK_STALE_MS) {
|
|
12526
12526
|
if (await canStealStaleLock(lockPath2)) {
|
|
12527
|
-
await
|
|
12527
|
+
await fs41.unlink(lockPath2).catch(() => void 0);
|
|
12528
12528
|
continue;
|
|
12529
12529
|
}
|
|
12530
12530
|
}
|
|
@@ -12675,9 +12675,9 @@ var init_short_term_promotion = __esm({
|
|
|
12675
12675
|
DAY_MS = 24 * 60 * 60 * 1e3;
|
|
12676
12676
|
MAX_QUERY_HASHES = 32;
|
|
12677
12677
|
MAX_RECALL_DAYS = 16;
|
|
12678
|
-
SHORT_TERM_STORE_RELATIVE_PATH =
|
|
12679
|
-
SHORT_TERM_PHASE_SIGNAL_RELATIVE_PATH =
|
|
12680
|
-
SHORT_TERM_LOCK_RELATIVE_PATH =
|
|
12678
|
+
SHORT_TERM_STORE_RELATIVE_PATH = path42.join("memory", ".dreams", "short-term-recall.json");
|
|
12679
|
+
SHORT_TERM_PHASE_SIGNAL_RELATIVE_PATH = path42.join("memory", ".dreams", "phase-signals.json");
|
|
12680
|
+
SHORT_TERM_LOCK_RELATIVE_PATH = path42.join("memory", ".dreams", "short-term-promotion.lock");
|
|
12681
12681
|
SHORT_TERM_LOCK_WAIT_TIMEOUT_MS = 1e4;
|
|
12682
12682
|
SHORT_TERM_LOCK_STALE_MS = 6e4;
|
|
12683
12683
|
SHORT_TERM_LOCK_RETRY_DELAY_MS = 40;
|
|
@@ -20089,9 +20089,9 @@ var init_string_utils = __esm({
|
|
|
20089
20089
|
});
|
|
20090
20090
|
|
|
20091
20091
|
// src/memory/host/config-utils.ts
|
|
20092
|
-
import
|
|
20092
|
+
import fs42 from "node:fs";
|
|
20093
20093
|
import os4 from "node:os";
|
|
20094
|
-
import
|
|
20094
|
+
import path43 from "node:path";
|
|
20095
20095
|
function normalizeAgentId(value) {
|
|
20096
20096
|
const trimmed = (value ?? "").trim();
|
|
20097
20097
|
if (!trimmed) {
|
|
@@ -20116,7 +20116,7 @@ function resolveRawOsHomeDir(env, homedir2) {
|
|
|
20116
20116
|
function resolveRequiredHomeDir(env = process.env, homedir2 = os4.homedir) {
|
|
20117
20117
|
const explicitHome = normalizeHomeValue(env.OPENCLAW_HOME);
|
|
20118
20118
|
const rawHome = explicitHome ? explicitHome.replace(/^~(?=$|[\\/])/, resolveRawOsHomeDir(env, homedir2) ?? "") : resolveRawOsHomeDir(env, homedir2);
|
|
20119
|
-
return rawHome ?
|
|
20119
|
+
return rawHome ? path43.resolve(rawHome) : path43.resolve(process.cwd());
|
|
20120
20120
|
}
|
|
20121
20121
|
function resolveUserPath2(input, env = process.env, homedir2 = os4.homedir) {
|
|
20122
20122
|
const trimmed = input.trim();
|
|
@@ -20124,12 +20124,12 @@ function resolveUserPath2(input, env = process.env, homedir2 = os4.homedir) {
|
|
|
20124
20124
|
return trimmed;
|
|
20125
20125
|
}
|
|
20126
20126
|
if (trimmed.startsWith("~")) {
|
|
20127
|
-
return
|
|
20127
|
+
return path43.resolve(trimmed.replace(/^~(?=$|[\\/])/, resolveRequiredHomeDir(env, homedir2)));
|
|
20128
20128
|
}
|
|
20129
|
-
return
|
|
20129
|
+
return path43.resolve(trimmed);
|
|
20130
20130
|
}
|
|
20131
20131
|
function legacyStateDirs(homedir2) {
|
|
20132
|
-
return LEGACY_STATE_DIRNAMES.map((dir) =>
|
|
20132
|
+
return LEGACY_STATE_DIRNAMES.map((dir) => path43.join(homedir2(), dir));
|
|
20133
20133
|
}
|
|
20134
20134
|
function resolveStateDir2(env = process.env, homedir2 = os4.homedir) {
|
|
20135
20135
|
const override = env.OPENCLAW_STATE_DIR?.trim();
|
|
@@ -20137,13 +20137,13 @@ function resolveStateDir2(env = process.env, homedir2 = os4.homedir) {
|
|
|
20137
20137
|
return resolveUserPath2(override, env, homedir2);
|
|
20138
20138
|
}
|
|
20139
20139
|
const effectiveHome = () => resolveRequiredHomeDir(env, homedir2);
|
|
20140
|
-
const nextDir =
|
|
20141
|
-
if (env.OPENCLAW_TEST_FAST === "1" ||
|
|
20140
|
+
const nextDir = path43.join(effectiveHome(), NEW_STATE_DIRNAME);
|
|
20141
|
+
if (env.OPENCLAW_TEST_FAST === "1" || fs42.existsSync(nextDir)) {
|
|
20142
20142
|
return nextDir;
|
|
20143
20143
|
}
|
|
20144
20144
|
const existingLegacy = legacyStateDirs(effectiveHome).find((dir) => {
|
|
20145
20145
|
try {
|
|
20146
|
-
return
|
|
20146
|
+
return fs42.existsSync(dir);
|
|
20147
20147
|
} catch {
|
|
20148
20148
|
return false;
|
|
20149
20149
|
}
|
|
@@ -20154,9 +20154,9 @@ function resolveDefaultAgentWorkspaceDir(env = process.env) {
|
|
|
20154
20154
|
const home = resolveRequiredHomeDir(env, os4.homedir);
|
|
20155
20155
|
const profile = env.OPENCLAW_PROFILE?.trim();
|
|
20156
20156
|
if (profile && normalizeLowercaseStringOrEmpty2(profile) !== "default") {
|
|
20157
|
-
return
|
|
20157
|
+
return path43.join(home, ".openclaw", `workspace-${profile}`);
|
|
20158
20158
|
}
|
|
20159
|
-
return
|
|
20159
|
+
return path43.join(home, ".openclaw", "workspace");
|
|
20160
20160
|
}
|
|
20161
20161
|
function listAgentEntries(cfg) {
|
|
20162
20162
|
return Array.isArray(cfg.agents?.list) ? cfg.agents.list.filter((entry) => Boolean(entry)) : [];
|
|
@@ -20189,9 +20189,9 @@ function resolveAgentWorkspaceDir2(cfg, agentId, env = process.env) {
|
|
|
20189
20189
|
);
|
|
20190
20190
|
}
|
|
20191
20191
|
if (fallback) {
|
|
20192
|
-
return stripNullBytes(
|
|
20192
|
+
return stripNullBytes(path43.join(resolveUserPath2(fallback, env), id));
|
|
20193
20193
|
}
|
|
20194
|
-
return stripNullBytes(
|
|
20194
|
+
return stripNullBytes(path43.join(resolveStateDir2(env), `workspace-${id}`));
|
|
20195
20195
|
}
|
|
20196
20196
|
function resolveAgentContextLimits2(cfg, agentId) {
|
|
20197
20197
|
const defaults = cfg?.agents?.defaults?.contextLimits;
|
|
@@ -20277,12 +20277,12 @@ var init_config4 = __esm({
|
|
|
20277
20277
|
});
|
|
20278
20278
|
|
|
20279
20279
|
// src/memory/shims/fs-safe/root.ts
|
|
20280
|
-
import
|
|
20280
|
+
import path44 from "node:path";
|
|
20281
20281
|
function root(...segments) {
|
|
20282
|
-
const basePath =
|
|
20282
|
+
const basePath = path44.resolve(...segments);
|
|
20283
20283
|
return {
|
|
20284
20284
|
resolve(relPath) {
|
|
20285
|
-
return Promise.resolve(
|
|
20285
|
+
return Promise.resolve(path44.resolve(basePath, relPath));
|
|
20286
20286
|
}
|
|
20287
20287
|
};
|
|
20288
20288
|
}
|
|
@@ -20293,10 +20293,10 @@ var init_root = __esm({
|
|
|
20293
20293
|
});
|
|
20294
20294
|
|
|
20295
20295
|
// src/memory/shims/fs-safe/path.ts
|
|
20296
|
-
import
|
|
20296
|
+
import path45 from "node:path";
|
|
20297
20297
|
function isPathInside(childPath, parentPath) {
|
|
20298
|
-
const relative4 =
|
|
20299
|
-
return !relative4.startsWith("..") && !
|
|
20298
|
+
const relative4 = path45.relative(parentPath, childPath);
|
|
20299
|
+
return !relative4.startsWith("..") && !path45.isAbsolute(relative4);
|
|
20300
20300
|
}
|
|
20301
20301
|
function isPathInsideWithRealpath(childPath, parentPath) {
|
|
20302
20302
|
try {
|
|
@@ -20312,12 +20312,12 @@ var init_path2 = __esm({
|
|
|
20312
20312
|
});
|
|
20313
20313
|
|
|
20314
20314
|
// src/memory/shims/fs-safe/advanced.ts
|
|
20315
|
-
import
|
|
20315
|
+
import fs43 from "node:fs";
|
|
20316
20316
|
function readRegularFile(filePathOrOptions) {
|
|
20317
20317
|
const filePath = typeof filePathOrOptions === "string" ? filePathOrOptions : filePathOrOptions.filePath;
|
|
20318
20318
|
const maxBytes = typeof filePathOrOptions === "string" ? void 0 : filePathOrOptions.maxBytes;
|
|
20319
20319
|
try {
|
|
20320
|
-
const buf =
|
|
20320
|
+
const buf = fs43.readFileSync(filePath);
|
|
20321
20321
|
if (maxBytes && buf.length > maxBytes) {
|
|
20322
20322
|
return { buffer: buf.subarray(0, maxBytes) };
|
|
20323
20323
|
}
|
|
@@ -20328,7 +20328,7 @@ function readRegularFile(filePathOrOptions) {
|
|
|
20328
20328
|
}
|
|
20329
20329
|
function statRegularFile(filePath) {
|
|
20330
20330
|
try {
|
|
20331
|
-
const stat8 =
|
|
20331
|
+
const stat8 = fs43.statSync(filePath);
|
|
20332
20332
|
if (!stat8.isFile()) return { missing: true };
|
|
20333
20333
|
return { missing: false, stat: { size: stat8.size, mtimeMs: stat8.mtimeMs } };
|
|
20334
20334
|
} catch {
|
|
@@ -20344,22 +20344,22 @@ var init_advanced = __esm({
|
|
|
20344
20344
|
});
|
|
20345
20345
|
|
|
20346
20346
|
// src/memory/shims/fs-safe/walk.ts
|
|
20347
|
-
import
|
|
20348
|
-
import
|
|
20347
|
+
import fs44 from "node:fs";
|
|
20348
|
+
import path46 from "node:path";
|
|
20349
20349
|
async function walkDirectory(dir, options) {
|
|
20350
20350
|
const entries = [];
|
|
20351
20351
|
async function walk(d) {
|
|
20352
|
-
if (!
|
|
20352
|
+
if (!fs44.existsSync(d)) return;
|
|
20353
20353
|
let dirents;
|
|
20354
20354
|
try {
|
|
20355
|
-
dirents =
|
|
20355
|
+
dirents = fs44.readdirSync(d, { withFileTypes: true });
|
|
20356
20356
|
} catch {
|
|
20357
20357
|
return;
|
|
20358
20358
|
}
|
|
20359
20359
|
for (const dirent of dirents) {
|
|
20360
20360
|
const kind = dirent.isDirectory() ? "directory" : "file";
|
|
20361
20361
|
const entry = {
|
|
20362
|
-
path:
|
|
20362
|
+
path: path46.join(d, dirent.name),
|
|
20363
20363
|
name: dirent.name,
|
|
20364
20364
|
kind
|
|
20365
20365
|
};
|
|
@@ -20516,8 +20516,8 @@ var init_hash2 = __esm({
|
|
|
20516
20516
|
// src/memory/host/internal.ts
|
|
20517
20517
|
import crypto8 from "node:crypto";
|
|
20518
20518
|
import fsSync from "node:fs";
|
|
20519
|
-
import
|
|
20520
|
-
import
|
|
20519
|
+
import fs45 from "node:fs/promises";
|
|
20520
|
+
import path47 from "node:path";
|
|
20521
20521
|
function ensureDir(dir) {
|
|
20522
20522
|
try {
|
|
20523
20523
|
fsSync.mkdirSync(dir, { recursive: true });
|
|
@@ -20535,7 +20535,7 @@ function normalizeExtraMemoryPaths(_baseDir, extraPaths) {
|
|
|
20535
20535
|
}
|
|
20536
20536
|
const stateDir = process.env.ENGINE_STATE_DIR || process.cwd();
|
|
20537
20537
|
const resolved = extraPaths.map((value) => value.trim()).filter(Boolean).map(
|
|
20538
|
-
(value) =>
|
|
20538
|
+
(value) => path47.isAbsolute(value) ? path47.resolve(value) : path47.resolve(stateDir, value)
|
|
20539
20539
|
);
|
|
20540
20540
|
return Array.from(new Set(resolved));
|
|
20541
20541
|
}
|
|
@@ -20571,7 +20571,7 @@ async function collectMemoryFilesFromDir(dir, files, multimodal, shouldSkipPath)
|
|
|
20571
20571
|
}
|
|
20572
20572
|
async function listMemoryFiles(workspaceDir, extraPaths, multimodal) {
|
|
20573
20573
|
const result = [];
|
|
20574
|
-
const memoryDir =
|
|
20574
|
+
const memoryDir = path47.join(workspaceDir, "memory");
|
|
20575
20575
|
const shouldSkipWorkspaceMemoryPath = (absPath) => shouldSkipRootMemoryAuxiliaryPath({ workspaceDir, absPath });
|
|
20576
20576
|
const addMarkdownFile = async (absPath) => {
|
|
20577
20577
|
try {
|
|
@@ -20591,7 +20591,7 @@ async function listMemoryFiles(workspaceDir, extraPaths, multimodal) {
|
|
|
20591
20591
|
await addMarkdownFile(memoryFile);
|
|
20592
20592
|
}
|
|
20593
20593
|
try {
|
|
20594
|
-
const dirStat = await
|
|
20594
|
+
const dirStat = await fs45.lstat(memoryDir);
|
|
20595
20595
|
if (!dirStat.isSymbolicLink() && dirStat.isDirectory()) {
|
|
20596
20596
|
await collectMemoryFilesFromDir(memoryDir, result, multimodal, shouldSkipWorkspaceMemoryPath);
|
|
20597
20597
|
}
|
|
@@ -20604,7 +20604,7 @@ async function listMemoryFiles(workspaceDir, extraPaths, multimodal) {
|
|
|
20604
20604
|
continue;
|
|
20605
20605
|
}
|
|
20606
20606
|
try {
|
|
20607
|
-
const stat8 = await
|
|
20607
|
+
const stat8 = await fs45.lstat(inputPath);
|
|
20608
20608
|
if (stat8.isSymbolicLink()) {
|
|
20609
20609
|
continue;
|
|
20610
20610
|
}
|
|
@@ -20632,7 +20632,7 @@ async function listMemoryFiles(workspaceDir, extraPaths, multimodal) {
|
|
|
20632
20632
|
for (const entry of result) {
|
|
20633
20633
|
let key = entry;
|
|
20634
20634
|
try {
|
|
20635
|
-
key = await
|
|
20635
|
+
key = await fs45.realpath(entry);
|
|
20636
20636
|
} catch {
|
|
20637
20637
|
}
|
|
20638
20638
|
if (seen.has(key)) {
|
|
@@ -20649,7 +20649,7 @@ async function buildFileEntry(absPath, workspaceDir, multimodal) {
|
|
|
20649
20649
|
return null;
|
|
20650
20650
|
}
|
|
20651
20651
|
const stat8 = regularFile.stat;
|
|
20652
|
-
const normalizedPath =
|
|
20652
|
+
const normalizedPath = path47.relative(workspaceDir, absPath).replace(/\\/g, "/");
|
|
20653
20653
|
const multimodalSettings = multimodal ?? DISABLED_MULTIMODAL_SETTINGS;
|
|
20654
20654
|
const modality = classifyMemoryMultimodalPath(absPath, multimodalSettings);
|
|
20655
20655
|
if (modality) {
|
|
@@ -21012,8 +21012,8 @@ __export(read_file_exports, {
|
|
|
21012
21012
|
readAgentMemoryFile: () => readAgentMemoryFile,
|
|
21013
21013
|
readMemoryFile: () => readMemoryFile
|
|
21014
21014
|
});
|
|
21015
|
-
import
|
|
21016
|
-
import
|
|
21015
|
+
import fs46 from "node:fs/promises";
|
|
21016
|
+
import path48 from "node:path";
|
|
21017
21017
|
async function isAllowedAdditionalDirectoryPath(additionalPath, absPath) {
|
|
21018
21018
|
if (!isPathInside(additionalPath, absPath)) {
|
|
21019
21019
|
return false;
|
|
@@ -21025,7 +21025,7 @@ async function isAllowedAdditionalDirectoryPath(additionalPath, absPath) {
|
|
|
21025
21025
|
}
|
|
21026
21026
|
if (!isPathInsideWithRealpath(additionalPath, absPath)) {
|
|
21027
21027
|
try {
|
|
21028
|
-
await
|
|
21028
|
+
await fs46.lstat(absPath);
|
|
21029
21029
|
} catch (err) {
|
|
21030
21030
|
return isFileMissingError(err);
|
|
21031
21031
|
}
|
|
@@ -21038,22 +21038,22 @@ async function readMemoryFile(params) {
|
|
|
21038
21038
|
if (!rawPath) {
|
|
21039
21039
|
throw new Error("path required");
|
|
21040
21040
|
}
|
|
21041
|
-
const absPath =
|
|
21042
|
-
const relPath =
|
|
21043
|
-
const inWorkspace = relPath.length > 0 && !relPath.startsWith("..") && !
|
|
21041
|
+
const absPath = path48.isAbsolute(rawPath) ? path48.resolve(rawPath) : path48.resolve(params.workspaceDir, rawPath);
|
|
21042
|
+
const relPath = path48.relative(params.workspaceDir, absPath).replace(/\\/g, "/");
|
|
21043
|
+
const inWorkspace = relPath.length > 0 && !relPath.startsWith("..") && !path48.isAbsolute(relPath);
|
|
21044
21044
|
const allowedWorkspace = inWorkspace && isMemoryPath(relPath);
|
|
21045
21045
|
let allowedAdditional = false;
|
|
21046
21046
|
if (!allowedWorkspace && (params.extraPaths?.length ?? 0) > 0) {
|
|
21047
21047
|
const additionalPaths = normalizeExtraMemoryPaths(params.workspaceDir, params.extraPaths);
|
|
21048
21048
|
for (const additionalPath of additionalPaths) {
|
|
21049
21049
|
try {
|
|
21050
|
-
const stat8 = await
|
|
21050
|
+
const stat8 = await fs46.lstat(additionalPath);
|
|
21051
21051
|
if (stat8.isSymbolicLink()) {
|
|
21052
21052
|
continue;
|
|
21053
21053
|
}
|
|
21054
21054
|
if (stat8.isDirectory()) {
|
|
21055
21055
|
if (await isAllowedAdditionalDirectoryPath(additionalPath, absPath)) {
|
|
21056
|
-
const candidateStat = await
|
|
21056
|
+
const candidateStat = await fs46.lstat(absPath).catch(() => null);
|
|
21057
21057
|
if (candidateStat?.isSymbolicLink()) {
|
|
21058
21058
|
continue;
|
|
21059
21059
|
}
|
|
@@ -21523,8 +21523,8 @@ var init_memory_core_host_runtime_files = __esm({
|
|
|
21523
21523
|
});
|
|
21524
21524
|
|
|
21525
21525
|
// src/memory/shims/memory-core-host-engine-qmd.ts
|
|
21526
|
-
import * as
|
|
21527
|
-
import * as
|
|
21526
|
+
import * as path49 from "path";
|
|
21527
|
+
import * as fs47 from "fs/promises";
|
|
21528
21528
|
import { createHash as createHash3 } from "crypto";
|
|
21529
21529
|
function extractKeywords(query) {
|
|
21530
21530
|
return [...new Set(
|
|
@@ -21536,8 +21536,8 @@ async function checkQmdBinaryAvailability() {
|
|
|
21536
21536
|
}
|
|
21537
21537
|
async function buildSessionEntry(filePath) {
|
|
21538
21538
|
try {
|
|
21539
|
-
const stat8 = await
|
|
21540
|
-
const raw = await
|
|
21539
|
+
const stat8 = await fs47.stat(filePath);
|
|
21540
|
+
const raw = await fs47.readFile(filePath, "utf-8");
|
|
21541
21541
|
const contentParts = [];
|
|
21542
21542
|
if (filePath.endsWith(".json")) {
|
|
21543
21543
|
try {
|
|
@@ -21612,13 +21612,13 @@ function isUsageCountedSessionTranscriptFileName(_name) {
|
|
|
21612
21612
|
async function listSessionFilesForAgent(params) {
|
|
21613
21613
|
try {
|
|
21614
21614
|
const sessionsDir = resolveSessionTranscriptsDirForAgent({ agentId: params.agentId ?? "main" });
|
|
21615
|
-
const entries = await
|
|
21616
|
-
const sessionFiles = entries.filter((name) => name.includes(".jsonl") || name.startsWith("session_") && name.endsWith(".json")).map((name) =>
|
|
21615
|
+
const entries = await fs47.readdir(sessionsDir);
|
|
21616
|
+
const sessionFiles = entries.filter((name) => name.includes(".jsonl") || name.startsWith("session_") && name.endsWith(".json")).map((name) => path49.join(sessionsDir, name));
|
|
21617
21617
|
console.log(`[memory-sync] listSessionFilesForAgent: found ${sessionFiles.length} files in ${sessionsDir}`);
|
|
21618
|
-
const archiveDir =
|
|
21618
|
+
const archiveDir = path49.join(sessionsDir, "archive");
|
|
21619
21619
|
try {
|
|
21620
|
-
const archiveEntries = await
|
|
21621
|
-
const archiveFiles = archiveEntries.filter((name) => name.endsWith(".jsonl") || name.endsWith(".json")).map((name) =>
|
|
21620
|
+
const archiveEntries = await fs47.readdir(archiveDir);
|
|
21621
|
+
const archiveFiles = archiveEntries.filter((name) => name.endsWith(".jsonl") || name.endsWith(".json")).map((name) => path49.join(archiveDir, name));
|
|
21622
21622
|
if (archiveFiles.length > 0) {
|
|
21623
21623
|
console.log(`[memory-sync] listSessionFilesForAgent: found ${archiveFiles.length} files in ${archiveDir}`);
|
|
21624
21624
|
sessionFiles.push(...archiveFiles);
|
|
@@ -21627,10 +21627,10 @@ async function listSessionFilesForAgent(params) {
|
|
|
21627
21627
|
}
|
|
21628
21628
|
const legacyDir = params.legacySessionsDir;
|
|
21629
21629
|
if (legacyDir) {
|
|
21630
|
-
const absLegacyDir =
|
|
21630
|
+
const absLegacyDir = path49.isAbsolute(legacyDir) ? legacyDir : path49.join(resolveStateDir(), legacyDir);
|
|
21631
21631
|
try {
|
|
21632
|
-
const legacyEntries = await
|
|
21633
|
-
const legacyFiles = legacyEntries.filter((name) => name.endsWith(".jsonl") || name.startsWith("session_") && name.endsWith(".json")).map((name) =>
|
|
21632
|
+
const legacyEntries = await fs47.readdir(absLegacyDir);
|
|
21633
|
+
const legacyFiles = legacyEntries.filter((name) => name.endsWith(".jsonl") || name.startsWith("session_") && name.endsWith(".json")).map((name) => path49.join(absLegacyDir, name));
|
|
21634
21634
|
if (legacyFiles.length > 0) {
|
|
21635
21635
|
console.log(`[memory-sync] listSessionFilesForAgent: found ${legacyFiles.length} files in ${absLegacyDir}`);
|
|
21636
21636
|
sessionFiles.push(...legacyFiles);
|
|
@@ -22072,8 +22072,8 @@ var init_mmr = __esm({
|
|
|
22072
22072
|
});
|
|
22073
22073
|
|
|
22074
22074
|
// src/memory/tools/memory/temporal-decay.ts
|
|
22075
|
-
import
|
|
22076
|
-
import
|
|
22075
|
+
import fs48 from "node:fs/promises";
|
|
22076
|
+
import path50 from "node:path";
|
|
22077
22077
|
function toDecayLambda(halfLifeDays) {
|
|
22078
22078
|
if (!Number.isFinite(halfLifeDays) || halfLifeDays <= 0) {
|
|
22079
22079
|
return 0;
|
|
@@ -22131,9 +22131,9 @@ async function extractTimestamp(params) {
|
|
|
22131
22131
|
if (!params.workspaceDir) {
|
|
22132
22132
|
return null;
|
|
22133
22133
|
}
|
|
22134
|
-
const absolutePath =
|
|
22134
|
+
const absolutePath = path50.isAbsolute(params.filePath) ? params.filePath : path50.resolve(params.workspaceDir, params.filePath);
|
|
22135
22135
|
try {
|
|
22136
|
-
const stat8 = await
|
|
22136
|
+
const stat8 = await fs48.stat(absolutePath);
|
|
22137
22137
|
if (!Number.isFinite(stat8.mtimeMs)) {
|
|
22138
22138
|
return null;
|
|
22139
22139
|
}
|
|
@@ -22396,9 +22396,9 @@ var init_manager_cache = __esm({
|
|
|
22396
22396
|
});
|
|
22397
22397
|
|
|
22398
22398
|
// src/memory/tools/memory/manager-db.ts
|
|
22399
|
-
import
|
|
22399
|
+
import path51 from "node:path";
|
|
22400
22400
|
function openMemoryDatabaseAtPath(dbPath, allowExtension) {
|
|
22401
|
-
const dir =
|
|
22401
|
+
const dir = path51.dirname(dbPath);
|
|
22402
22402
|
ensureDir(dir);
|
|
22403
22403
|
const { DatabaseSync: DatabaseSync2 } = requireNodeSqlite();
|
|
22404
22404
|
const db = new DatabaseSync2(dbPath, { allowExtension });
|
|
@@ -22703,7 +22703,7 @@ var init_readdirp = __esm({
|
|
|
22703
22703
|
this._directoryFilter = normalizeFilter(opts.directoryFilter);
|
|
22704
22704
|
const statMethod = opts.lstat ? lstat : stat5;
|
|
22705
22705
|
if (wantBigintFsStats) {
|
|
22706
|
-
this._stat = (
|
|
22706
|
+
this._stat = (path56) => statMethod(path56, { bigint: true });
|
|
22707
22707
|
} else {
|
|
22708
22708
|
this._stat = statMethod;
|
|
22709
22709
|
}
|
|
@@ -22728,8 +22728,8 @@ var init_readdirp = __esm({
|
|
|
22728
22728
|
const par = this.parent;
|
|
22729
22729
|
const fil = par && par.files;
|
|
22730
22730
|
if (fil && fil.length > 0) {
|
|
22731
|
-
const { path:
|
|
22732
|
-
const slice = fil.splice(0, batch).map((dirent) => this._formatEntry(dirent,
|
|
22731
|
+
const { path: path56, depth } = par;
|
|
22732
|
+
const slice = fil.splice(0, batch).map((dirent) => this._formatEntry(dirent, path56));
|
|
22733
22733
|
const awaited = await Promise.all(slice);
|
|
22734
22734
|
for (const entry of awaited) {
|
|
22735
22735
|
if (!entry)
|
|
@@ -22769,20 +22769,20 @@ var init_readdirp = __esm({
|
|
|
22769
22769
|
this.reading = false;
|
|
22770
22770
|
}
|
|
22771
22771
|
}
|
|
22772
|
-
async _exploreDir(
|
|
22772
|
+
async _exploreDir(path56, depth) {
|
|
22773
22773
|
let files;
|
|
22774
22774
|
try {
|
|
22775
|
-
files = await readdir3(
|
|
22775
|
+
files = await readdir3(path56, this._rdOptions);
|
|
22776
22776
|
} catch (error) {
|
|
22777
22777
|
this._onError(error);
|
|
22778
22778
|
}
|
|
22779
|
-
return { files, depth, path:
|
|
22779
|
+
return { files, depth, path: path56 };
|
|
22780
22780
|
}
|
|
22781
|
-
async _formatEntry(dirent,
|
|
22781
|
+
async _formatEntry(dirent, path56) {
|
|
22782
22782
|
let entry;
|
|
22783
22783
|
const basename9 = this._isDirent ? dirent.name : dirent;
|
|
22784
22784
|
try {
|
|
22785
|
-
const fullPath = presolve(pjoin(
|
|
22785
|
+
const fullPath = presolve(pjoin(path56, basename9));
|
|
22786
22786
|
entry = { path: prelative(this._root, fullPath), fullPath, basename: basename9 };
|
|
22787
22787
|
entry[this._statsProp] = this._isDirent ? dirent : await this._stat(fullPath);
|
|
22788
22788
|
} catch (err) {
|
|
@@ -22843,16 +22843,16 @@ import { watch as fs_watch, unwatchFile, watchFile } from "node:fs";
|
|
|
22843
22843
|
import { realpath as fsrealpath, lstat as lstat2, open, stat as stat6 } from "node:fs/promises";
|
|
22844
22844
|
import { type as osType } from "node:os";
|
|
22845
22845
|
import * as sp from "node:path";
|
|
22846
|
-
function createFsWatchInstance(
|
|
22846
|
+
function createFsWatchInstance(path56, options, listener, errHandler, emitRaw) {
|
|
22847
22847
|
const handleEvent = (rawEvent, evPath) => {
|
|
22848
|
-
listener(
|
|
22849
|
-
emitRaw(rawEvent, evPath, { watchedPath:
|
|
22850
|
-
if (evPath &&
|
|
22851
|
-
fsWatchBroadcast(sp.resolve(
|
|
22848
|
+
listener(path56);
|
|
22849
|
+
emitRaw(rawEvent, evPath, { watchedPath: path56 });
|
|
22850
|
+
if (evPath && path56 !== evPath) {
|
|
22851
|
+
fsWatchBroadcast(sp.resolve(path56, evPath), KEY_LISTENERS, sp.join(path56, evPath));
|
|
22852
22852
|
}
|
|
22853
22853
|
};
|
|
22854
22854
|
try {
|
|
22855
|
-
return fs_watch(
|
|
22855
|
+
return fs_watch(path56, {
|
|
22856
22856
|
persistent: options.persistent
|
|
22857
22857
|
}, handleEvent);
|
|
22858
22858
|
} catch (error) {
|
|
@@ -23196,12 +23196,12 @@ var init_handler = __esm({
|
|
|
23196
23196
|
listener(val1, val2, val3);
|
|
23197
23197
|
});
|
|
23198
23198
|
};
|
|
23199
|
-
setFsWatchListener = (
|
|
23199
|
+
setFsWatchListener = (path56, fullPath, options, handlers) => {
|
|
23200
23200
|
const { listener, errHandler, rawEmitter } = handlers;
|
|
23201
23201
|
let cont = FsWatchInstances.get(fullPath);
|
|
23202
23202
|
let watcher;
|
|
23203
23203
|
if (!options.persistent) {
|
|
23204
|
-
watcher = createFsWatchInstance(
|
|
23204
|
+
watcher = createFsWatchInstance(path56, options, listener, errHandler, rawEmitter);
|
|
23205
23205
|
if (!watcher)
|
|
23206
23206
|
return;
|
|
23207
23207
|
return watcher.close.bind(watcher);
|
|
@@ -23212,7 +23212,7 @@ var init_handler = __esm({
|
|
|
23212
23212
|
addAndConvert(cont, KEY_RAW, rawEmitter);
|
|
23213
23213
|
} else {
|
|
23214
23214
|
watcher = createFsWatchInstance(
|
|
23215
|
-
|
|
23215
|
+
path56,
|
|
23216
23216
|
options,
|
|
23217
23217
|
fsWatchBroadcast.bind(null, fullPath, KEY_LISTENERS),
|
|
23218
23218
|
errHandler,
|
|
@@ -23227,7 +23227,7 @@ var init_handler = __esm({
|
|
|
23227
23227
|
cont.watcherUnusable = true;
|
|
23228
23228
|
if (isWindows && error.code === "EPERM") {
|
|
23229
23229
|
try {
|
|
23230
|
-
const fd = await open(
|
|
23230
|
+
const fd = await open(path56, "r");
|
|
23231
23231
|
await fd.close();
|
|
23232
23232
|
broadcastErr(error);
|
|
23233
23233
|
} catch (err) {
|
|
@@ -23258,7 +23258,7 @@ var init_handler = __esm({
|
|
|
23258
23258
|
};
|
|
23259
23259
|
};
|
|
23260
23260
|
FsWatchFileInstances = /* @__PURE__ */ new Map();
|
|
23261
|
-
setFsWatchFileListener = (
|
|
23261
|
+
setFsWatchFileListener = (path56, fullPath, options, handlers) => {
|
|
23262
23262
|
const { listener, rawEmitter } = handlers;
|
|
23263
23263
|
let cont = FsWatchFileInstances.get(fullPath);
|
|
23264
23264
|
const copts = cont && cont.options;
|
|
@@ -23280,7 +23280,7 @@ var init_handler = __esm({
|
|
|
23280
23280
|
});
|
|
23281
23281
|
const currmtime = curr.mtimeMs;
|
|
23282
23282
|
if (curr.size !== prev.size || currmtime > prev.mtimeMs || currmtime === 0) {
|
|
23283
|
-
foreach(cont.listeners, (listener2) => listener2(
|
|
23283
|
+
foreach(cont.listeners, (listener2) => listener2(path56, curr));
|
|
23284
23284
|
}
|
|
23285
23285
|
})
|
|
23286
23286
|
};
|
|
@@ -23310,13 +23310,13 @@ var init_handler = __esm({
|
|
|
23310
23310
|
* @param listener on fs change
|
|
23311
23311
|
* @returns closer for the watcher instance
|
|
23312
23312
|
*/
|
|
23313
|
-
_watchWithNodeFs(
|
|
23313
|
+
_watchWithNodeFs(path56, listener) {
|
|
23314
23314
|
const opts = this.fsw.options;
|
|
23315
|
-
const directory = sp.dirname(
|
|
23316
|
-
const basename9 = sp.basename(
|
|
23315
|
+
const directory = sp.dirname(path56);
|
|
23316
|
+
const basename9 = sp.basename(path56);
|
|
23317
23317
|
const parent = this.fsw._getWatchedDir(directory);
|
|
23318
23318
|
parent.add(basename9);
|
|
23319
|
-
const absolutePath = sp.resolve(
|
|
23319
|
+
const absolutePath = sp.resolve(path56);
|
|
23320
23320
|
const options = {
|
|
23321
23321
|
persistent: opts.persistent
|
|
23322
23322
|
};
|
|
@@ -23326,12 +23326,12 @@ var init_handler = __esm({
|
|
|
23326
23326
|
if (opts.usePolling) {
|
|
23327
23327
|
const enableBin = opts.interval !== opts.binaryInterval;
|
|
23328
23328
|
options.interval = enableBin && isBinaryPath(basename9) ? opts.binaryInterval : opts.interval;
|
|
23329
|
-
closer = setFsWatchFileListener(
|
|
23329
|
+
closer = setFsWatchFileListener(path56, absolutePath, options, {
|
|
23330
23330
|
listener,
|
|
23331
23331
|
rawEmitter: this.fsw._emitRaw
|
|
23332
23332
|
});
|
|
23333
23333
|
} else {
|
|
23334
|
-
closer = setFsWatchListener(
|
|
23334
|
+
closer = setFsWatchListener(path56, absolutePath, options, {
|
|
23335
23335
|
listener,
|
|
23336
23336
|
errHandler: this._boundHandleError,
|
|
23337
23337
|
rawEmitter: this.fsw._emitRaw
|
|
@@ -23353,7 +23353,7 @@ var init_handler = __esm({
|
|
|
23353
23353
|
let prevStats = stats2;
|
|
23354
23354
|
if (parent.has(basename9))
|
|
23355
23355
|
return;
|
|
23356
|
-
const listener = async (
|
|
23356
|
+
const listener = async (path56, newStats) => {
|
|
23357
23357
|
if (!this.fsw._throttle(THROTTLE_MODE_WATCH, file, 5))
|
|
23358
23358
|
return;
|
|
23359
23359
|
if (!newStats || newStats.mtimeMs === 0) {
|
|
@@ -23367,11 +23367,11 @@ var init_handler = __esm({
|
|
|
23367
23367
|
this.fsw._emit(EV.CHANGE, file, newStats2);
|
|
23368
23368
|
}
|
|
23369
23369
|
if ((isMacos || isLinux || isFreeBSD) && prevStats.ino !== newStats2.ino) {
|
|
23370
|
-
this.fsw._closeFile(
|
|
23370
|
+
this.fsw._closeFile(path56);
|
|
23371
23371
|
prevStats = newStats2;
|
|
23372
23372
|
const closer2 = this._watchWithNodeFs(file, listener);
|
|
23373
23373
|
if (closer2)
|
|
23374
|
-
this.fsw._addPathCloser(
|
|
23374
|
+
this.fsw._addPathCloser(path56, closer2);
|
|
23375
23375
|
} else {
|
|
23376
23376
|
prevStats = newStats2;
|
|
23377
23377
|
}
|
|
@@ -23403,7 +23403,7 @@ var init_handler = __esm({
|
|
|
23403
23403
|
* @param item basename of this item
|
|
23404
23404
|
* @returns true if no more processing is needed for this entry.
|
|
23405
23405
|
*/
|
|
23406
|
-
async _handleSymlink(entry, directory,
|
|
23406
|
+
async _handleSymlink(entry, directory, path56, item) {
|
|
23407
23407
|
if (this.fsw.closed) {
|
|
23408
23408
|
return;
|
|
23409
23409
|
}
|
|
@@ -23413,7 +23413,7 @@ var init_handler = __esm({
|
|
|
23413
23413
|
this.fsw._incrReadyCount();
|
|
23414
23414
|
let linkPath;
|
|
23415
23415
|
try {
|
|
23416
|
-
linkPath = await fsrealpath(
|
|
23416
|
+
linkPath = await fsrealpath(path56);
|
|
23417
23417
|
} catch (e) {
|
|
23418
23418
|
this.fsw._emitReady();
|
|
23419
23419
|
return true;
|
|
@@ -23423,12 +23423,12 @@ var init_handler = __esm({
|
|
|
23423
23423
|
if (dir.has(item)) {
|
|
23424
23424
|
if (this.fsw._symlinkPaths.get(full) !== linkPath) {
|
|
23425
23425
|
this.fsw._symlinkPaths.set(full, linkPath);
|
|
23426
|
-
this.fsw._emit(EV.CHANGE,
|
|
23426
|
+
this.fsw._emit(EV.CHANGE, path56, entry.stats);
|
|
23427
23427
|
}
|
|
23428
23428
|
} else {
|
|
23429
23429
|
dir.add(item);
|
|
23430
23430
|
this.fsw._symlinkPaths.set(full, linkPath);
|
|
23431
|
-
this.fsw._emit(EV.ADD,
|
|
23431
|
+
this.fsw._emit(EV.ADD, path56, entry.stats);
|
|
23432
23432
|
}
|
|
23433
23433
|
this.fsw._emitReady();
|
|
23434
23434
|
return true;
|
|
@@ -23458,9 +23458,9 @@ var init_handler = __esm({
|
|
|
23458
23458
|
return;
|
|
23459
23459
|
}
|
|
23460
23460
|
const item = entry.path;
|
|
23461
|
-
let
|
|
23461
|
+
let path56 = sp.join(directory, item);
|
|
23462
23462
|
current.add(item);
|
|
23463
|
-
if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory,
|
|
23463
|
+
if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory, path56, item)) {
|
|
23464
23464
|
return;
|
|
23465
23465
|
}
|
|
23466
23466
|
if (this.fsw.closed) {
|
|
@@ -23469,8 +23469,8 @@ var init_handler = __esm({
|
|
|
23469
23469
|
}
|
|
23470
23470
|
if (item === target || !target && !previous.has(item)) {
|
|
23471
23471
|
this.fsw._incrReadyCount();
|
|
23472
|
-
|
|
23473
|
-
this._addToNodeFs(
|
|
23472
|
+
path56 = sp.join(dir, sp.relative(dir, path56));
|
|
23473
|
+
this._addToNodeFs(path56, initialAdd, wh, depth + 1);
|
|
23474
23474
|
}
|
|
23475
23475
|
}).on(EV.ERROR, this._boundHandleError);
|
|
23476
23476
|
return new Promise((resolve12, reject) => {
|
|
@@ -23539,13 +23539,13 @@ var init_handler = __esm({
|
|
|
23539
23539
|
* @param depth Child path actually targeted for watch
|
|
23540
23540
|
* @param target Child path actually targeted for watch
|
|
23541
23541
|
*/
|
|
23542
|
-
async _addToNodeFs(
|
|
23542
|
+
async _addToNodeFs(path56, initialAdd, priorWh, depth, target) {
|
|
23543
23543
|
const ready = this.fsw._emitReady;
|
|
23544
|
-
if (this.fsw._isIgnored(
|
|
23544
|
+
if (this.fsw._isIgnored(path56) || this.fsw.closed) {
|
|
23545
23545
|
ready();
|
|
23546
23546
|
return false;
|
|
23547
23547
|
}
|
|
23548
|
-
const wh = this.fsw._getWatchHelpers(
|
|
23548
|
+
const wh = this.fsw._getWatchHelpers(path56);
|
|
23549
23549
|
if (priorWh) {
|
|
23550
23550
|
wh.filterPath = (entry) => priorWh.filterPath(entry);
|
|
23551
23551
|
wh.filterDir = (entry) => priorWh.filterDir(entry);
|
|
@@ -23561,8 +23561,8 @@ var init_handler = __esm({
|
|
|
23561
23561
|
const follow = this.fsw.options.followSymlinks;
|
|
23562
23562
|
let closer;
|
|
23563
23563
|
if (stats2.isDirectory()) {
|
|
23564
|
-
const absPath = sp.resolve(
|
|
23565
|
-
const targetPath = follow ? await fsrealpath(
|
|
23564
|
+
const absPath = sp.resolve(path56);
|
|
23565
|
+
const targetPath = follow ? await fsrealpath(path56) : path56;
|
|
23566
23566
|
if (this.fsw.closed)
|
|
23567
23567
|
return;
|
|
23568
23568
|
closer = await this._handleDir(wh.watchPath, stats2, initialAdd, depth, target, wh, targetPath);
|
|
@@ -23572,29 +23572,29 @@ var init_handler = __esm({
|
|
|
23572
23572
|
this.fsw._symlinkPaths.set(absPath, targetPath);
|
|
23573
23573
|
}
|
|
23574
23574
|
} else if (stats2.isSymbolicLink()) {
|
|
23575
|
-
const targetPath = follow ? await fsrealpath(
|
|
23575
|
+
const targetPath = follow ? await fsrealpath(path56) : path56;
|
|
23576
23576
|
if (this.fsw.closed)
|
|
23577
23577
|
return;
|
|
23578
23578
|
const parent = sp.dirname(wh.watchPath);
|
|
23579
23579
|
this.fsw._getWatchedDir(parent).add(wh.watchPath);
|
|
23580
23580
|
this.fsw._emit(EV.ADD, wh.watchPath, stats2);
|
|
23581
|
-
closer = await this._handleDir(parent, stats2, initialAdd, depth,
|
|
23581
|
+
closer = await this._handleDir(parent, stats2, initialAdd, depth, path56, wh, targetPath);
|
|
23582
23582
|
if (this.fsw.closed)
|
|
23583
23583
|
return;
|
|
23584
23584
|
if (targetPath !== void 0) {
|
|
23585
|
-
this.fsw._symlinkPaths.set(sp.resolve(
|
|
23585
|
+
this.fsw._symlinkPaths.set(sp.resolve(path56), targetPath);
|
|
23586
23586
|
}
|
|
23587
23587
|
} else {
|
|
23588
23588
|
closer = this._handleFile(wh.watchPath, stats2, initialAdd);
|
|
23589
23589
|
}
|
|
23590
23590
|
ready();
|
|
23591
23591
|
if (closer)
|
|
23592
|
-
this.fsw._addPathCloser(
|
|
23592
|
+
this.fsw._addPathCloser(path56, closer);
|
|
23593
23593
|
return false;
|
|
23594
23594
|
} catch (error) {
|
|
23595
23595
|
if (this.fsw._handleError(error)) {
|
|
23596
23596
|
ready();
|
|
23597
|
-
return
|
|
23597
|
+
return path56;
|
|
23598
23598
|
}
|
|
23599
23599
|
}
|
|
23600
23600
|
}
|
|
@@ -23633,24 +23633,24 @@ function createPattern(matcher) {
|
|
|
23633
23633
|
}
|
|
23634
23634
|
return () => false;
|
|
23635
23635
|
}
|
|
23636
|
-
function normalizePath2(
|
|
23637
|
-
if (typeof
|
|
23636
|
+
function normalizePath2(path56) {
|
|
23637
|
+
if (typeof path56 !== "string")
|
|
23638
23638
|
throw new Error("string expected");
|
|
23639
|
-
|
|
23640
|
-
|
|
23639
|
+
path56 = sp2.normalize(path56);
|
|
23640
|
+
path56 = path56.replace(/\\/g, "/");
|
|
23641
23641
|
let prepend = false;
|
|
23642
|
-
if (
|
|
23642
|
+
if (path56.startsWith("//"))
|
|
23643
23643
|
prepend = true;
|
|
23644
|
-
|
|
23644
|
+
path56 = path56.replace(DOUBLE_SLASH_RE, "/");
|
|
23645
23645
|
if (prepend)
|
|
23646
|
-
|
|
23647
|
-
return
|
|
23646
|
+
path56 = "/" + path56;
|
|
23647
|
+
return path56;
|
|
23648
23648
|
}
|
|
23649
23649
|
function matchPatterns(patterns, testString, stats2) {
|
|
23650
|
-
const
|
|
23650
|
+
const path56 = normalizePath2(testString);
|
|
23651
23651
|
for (let index = 0; index < patterns.length; index++) {
|
|
23652
23652
|
const pattern = patterns[index];
|
|
23653
|
-
if (pattern(
|
|
23653
|
+
if (pattern(path56, stats2)) {
|
|
23654
23654
|
return true;
|
|
23655
23655
|
}
|
|
23656
23656
|
}
|
|
@@ -23708,19 +23708,19 @@ var init_chokidar = __esm({
|
|
|
23708
23708
|
}
|
|
23709
23709
|
return str;
|
|
23710
23710
|
};
|
|
23711
|
-
normalizePathToUnix = (
|
|
23712
|
-
normalizeIgnored = (cwd = "") => (
|
|
23713
|
-
if (typeof
|
|
23714
|
-
return normalizePathToUnix(sp2.isAbsolute(
|
|
23711
|
+
normalizePathToUnix = (path56) => toUnix(sp2.normalize(toUnix(path56)));
|
|
23712
|
+
normalizeIgnored = (cwd = "") => (path56) => {
|
|
23713
|
+
if (typeof path56 === "string") {
|
|
23714
|
+
return normalizePathToUnix(sp2.isAbsolute(path56) ? path56 : sp2.join(cwd, path56));
|
|
23715
23715
|
} else {
|
|
23716
|
-
return
|
|
23716
|
+
return path56;
|
|
23717
23717
|
}
|
|
23718
23718
|
};
|
|
23719
|
-
getAbsolutePath = (
|
|
23720
|
-
if (sp2.isAbsolute(
|
|
23721
|
-
return
|
|
23719
|
+
getAbsolutePath = (path56, cwd) => {
|
|
23720
|
+
if (sp2.isAbsolute(path56)) {
|
|
23721
|
+
return path56;
|
|
23722
23722
|
}
|
|
23723
|
-
return sp2.join(cwd,
|
|
23723
|
+
return sp2.join(cwd, path56);
|
|
23724
23724
|
};
|
|
23725
23725
|
EMPTY_SET = Object.freeze(/* @__PURE__ */ new Set());
|
|
23726
23726
|
DirEntry = class {
|
|
@@ -23785,10 +23785,10 @@ var init_chokidar = __esm({
|
|
|
23785
23785
|
dirParts;
|
|
23786
23786
|
followSymlinks;
|
|
23787
23787
|
statMethod;
|
|
23788
|
-
constructor(
|
|
23788
|
+
constructor(path56, follow, fsw) {
|
|
23789
23789
|
this.fsw = fsw;
|
|
23790
|
-
const watchPath =
|
|
23791
|
-
this.path =
|
|
23790
|
+
const watchPath = path56;
|
|
23791
|
+
this.path = path56 = path56.replace(REPLACER_RE, "");
|
|
23792
23792
|
this.watchPath = watchPath;
|
|
23793
23793
|
this.fullWatchPath = sp2.resolve(watchPath);
|
|
23794
23794
|
this.dirParts = [];
|
|
@@ -23928,20 +23928,20 @@ var init_chokidar = __esm({
|
|
|
23928
23928
|
this._closePromise = void 0;
|
|
23929
23929
|
let paths = unifyPaths(paths_);
|
|
23930
23930
|
if (cwd) {
|
|
23931
|
-
paths = paths.map((
|
|
23932
|
-
const absPath = getAbsolutePath(
|
|
23931
|
+
paths = paths.map((path56) => {
|
|
23932
|
+
const absPath = getAbsolutePath(path56, cwd);
|
|
23933
23933
|
return absPath;
|
|
23934
23934
|
});
|
|
23935
23935
|
}
|
|
23936
|
-
paths.forEach((
|
|
23937
|
-
this._removeIgnoredPath(
|
|
23936
|
+
paths.forEach((path56) => {
|
|
23937
|
+
this._removeIgnoredPath(path56);
|
|
23938
23938
|
});
|
|
23939
23939
|
this._userIgnored = void 0;
|
|
23940
23940
|
if (!this._readyCount)
|
|
23941
23941
|
this._readyCount = 0;
|
|
23942
23942
|
this._readyCount += paths.length;
|
|
23943
|
-
Promise.all(paths.map(async (
|
|
23944
|
-
const res = await this._nodeFsHandler._addToNodeFs(
|
|
23943
|
+
Promise.all(paths.map(async (path56) => {
|
|
23944
|
+
const res = await this._nodeFsHandler._addToNodeFs(path56, !_internal, void 0, 0, _origAdd);
|
|
23945
23945
|
if (res)
|
|
23946
23946
|
this._emitReady();
|
|
23947
23947
|
return res;
|
|
@@ -23963,17 +23963,17 @@ var init_chokidar = __esm({
|
|
|
23963
23963
|
return this;
|
|
23964
23964
|
const paths = unifyPaths(paths_);
|
|
23965
23965
|
const { cwd } = this.options;
|
|
23966
|
-
paths.forEach((
|
|
23967
|
-
if (!sp2.isAbsolute(
|
|
23966
|
+
paths.forEach((path56) => {
|
|
23967
|
+
if (!sp2.isAbsolute(path56) && !this._closers.has(path56)) {
|
|
23968
23968
|
if (cwd)
|
|
23969
|
-
|
|
23970
|
-
|
|
23969
|
+
path56 = sp2.join(cwd, path56);
|
|
23970
|
+
path56 = sp2.resolve(path56);
|
|
23971
23971
|
}
|
|
23972
|
-
this._closePath(
|
|
23973
|
-
this._addIgnoredPath(
|
|
23974
|
-
if (this._watched.has(
|
|
23972
|
+
this._closePath(path56);
|
|
23973
|
+
this._addIgnoredPath(path56);
|
|
23974
|
+
if (this._watched.has(path56)) {
|
|
23975
23975
|
this._addIgnoredPath({
|
|
23976
|
-
path:
|
|
23976
|
+
path: path56,
|
|
23977
23977
|
recursive: true
|
|
23978
23978
|
});
|
|
23979
23979
|
}
|
|
@@ -24037,38 +24037,38 @@ var init_chokidar = __esm({
|
|
|
24037
24037
|
* @param stats arguments to be passed with event
|
|
24038
24038
|
* @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag
|
|
24039
24039
|
*/
|
|
24040
|
-
async _emit(event,
|
|
24040
|
+
async _emit(event, path56, stats2) {
|
|
24041
24041
|
if (this.closed)
|
|
24042
24042
|
return;
|
|
24043
24043
|
const opts = this.options;
|
|
24044
24044
|
if (isWindows)
|
|
24045
|
-
|
|
24045
|
+
path56 = sp2.normalize(path56);
|
|
24046
24046
|
if (opts.cwd)
|
|
24047
|
-
|
|
24048
|
-
const args2 = [
|
|
24047
|
+
path56 = sp2.relative(opts.cwd, path56);
|
|
24048
|
+
const args2 = [path56];
|
|
24049
24049
|
if (stats2 != null)
|
|
24050
24050
|
args2.push(stats2);
|
|
24051
24051
|
const awf = opts.awaitWriteFinish;
|
|
24052
24052
|
let pw;
|
|
24053
|
-
if (awf && (pw = this._pendingWrites.get(
|
|
24053
|
+
if (awf && (pw = this._pendingWrites.get(path56))) {
|
|
24054
24054
|
pw.lastChange = /* @__PURE__ */ new Date();
|
|
24055
24055
|
return this;
|
|
24056
24056
|
}
|
|
24057
24057
|
if (opts.atomic) {
|
|
24058
24058
|
if (event === EVENTS.UNLINK) {
|
|
24059
|
-
this._pendingUnlinks.set(
|
|
24059
|
+
this._pendingUnlinks.set(path56, [event, ...args2]);
|
|
24060
24060
|
setTimeout(() => {
|
|
24061
|
-
this._pendingUnlinks.forEach((entry,
|
|
24061
|
+
this._pendingUnlinks.forEach((entry, path57) => {
|
|
24062
24062
|
this.emit(...entry);
|
|
24063
24063
|
this.emit(EVENTS.ALL, ...entry);
|
|
24064
|
-
this._pendingUnlinks.delete(
|
|
24064
|
+
this._pendingUnlinks.delete(path57);
|
|
24065
24065
|
});
|
|
24066
24066
|
}, typeof opts.atomic === "number" ? opts.atomic : 100);
|
|
24067
24067
|
return this;
|
|
24068
24068
|
}
|
|
24069
|
-
if (event === EVENTS.ADD && this._pendingUnlinks.has(
|
|
24069
|
+
if (event === EVENTS.ADD && this._pendingUnlinks.has(path56)) {
|
|
24070
24070
|
event = EVENTS.CHANGE;
|
|
24071
|
-
this._pendingUnlinks.delete(
|
|
24071
|
+
this._pendingUnlinks.delete(path56);
|
|
24072
24072
|
}
|
|
24073
24073
|
}
|
|
24074
24074
|
if (awf && (event === EVENTS.ADD || event === EVENTS.CHANGE) && this._readyEmitted) {
|
|
@@ -24086,16 +24086,16 @@ var init_chokidar = __esm({
|
|
|
24086
24086
|
this.emitWithAll(event, args2);
|
|
24087
24087
|
}
|
|
24088
24088
|
};
|
|
24089
|
-
this._awaitWriteFinish(
|
|
24089
|
+
this._awaitWriteFinish(path56, awf.stabilityThreshold, event, awfEmit);
|
|
24090
24090
|
return this;
|
|
24091
24091
|
}
|
|
24092
24092
|
if (event === EVENTS.CHANGE) {
|
|
24093
|
-
const isThrottled = !this._throttle(EVENTS.CHANGE,
|
|
24093
|
+
const isThrottled = !this._throttle(EVENTS.CHANGE, path56, 50);
|
|
24094
24094
|
if (isThrottled)
|
|
24095
24095
|
return this;
|
|
24096
24096
|
}
|
|
24097
24097
|
if (opts.alwaysStat && stats2 === void 0 && (event === EVENTS.ADD || event === EVENTS.ADD_DIR || event === EVENTS.CHANGE)) {
|
|
24098
|
-
const fullPath = opts.cwd ? sp2.join(opts.cwd,
|
|
24098
|
+
const fullPath = opts.cwd ? sp2.join(opts.cwd, path56) : path56;
|
|
24099
24099
|
let stats3;
|
|
24100
24100
|
try {
|
|
24101
24101
|
stats3 = await stat7(fullPath);
|
|
@@ -24126,23 +24126,23 @@ var init_chokidar = __esm({
|
|
|
24126
24126
|
* @param timeout duration of time to suppress duplicate actions
|
|
24127
24127
|
* @returns tracking object or false if action should be suppressed
|
|
24128
24128
|
*/
|
|
24129
|
-
_throttle(actionType,
|
|
24129
|
+
_throttle(actionType, path56, timeout) {
|
|
24130
24130
|
if (!this._throttled.has(actionType)) {
|
|
24131
24131
|
this._throttled.set(actionType, /* @__PURE__ */ new Map());
|
|
24132
24132
|
}
|
|
24133
24133
|
const action = this._throttled.get(actionType);
|
|
24134
24134
|
if (!action)
|
|
24135
24135
|
throw new Error("invalid throttle");
|
|
24136
|
-
const actionPath = action.get(
|
|
24136
|
+
const actionPath = action.get(path56);
|
|
24137
24137
|
if (actionPath) {
|
|
24138
24138
|
actionPath.count++;
|
|
24139
24139
|
return false;
|
|
24140
24140
|
}
|
|
24141
24141
|
let timeoutObject;
|
|
24142
24142
|
const clear = () => {
|
|
24143
|
-
const item = action.get(
|
|
24143
|
+
const item = action.get(path56);
|
|
24144
24144
|
const count = item ? item.count : 0;
|
|
24145
|
-
action.delete(
|
|
24145
|
+
action.delete(path56);
|
|
24146
24146
|
clearTimeout(timeoutObject);
|
|
24147
24147
|
if (item)
|
|
24148
24148
|
clearTimeout(item.timeoutObject);
|
|
@@ -24150,7 +24150,7 @@ var init_chokidar = __esm({
|
|
|
24150
24150
|
};
|
|
24151
24151
|
timeoutObject = setTimeout(clear, timeout);
|
|
24152
24152
|
const thr = { timeoutObject, clear, count: 0 };
|
|
24153
|
-
action.set(
|
|
24153
|
+
action.set(path56, thr);
|
|
24154
24154
|
return thr;
|
|
24155
24155
|
}
|
|
24156
24156
|
_incrReadyCount() {
|
|
@@ -24164,44 +24164,44 @@ var init_chokidar = __esm({
|
|
|
24164
24164
|
* @param event
|
|
24165
24165
|
* @param awfEmit Callback to be called when ready for event to be emitted.
|
|
24166
24166
|
*/
|
|
24167
|
-
_awaitWriteFinish(
|
|
24167
|
+
_awaitWriteFinish(path56, threshold, event, awfEmit) {
|
|
24168
24168
|
const awf = this.options.awaitWriteFinish;
|
|
24169
24169
|
if (typeof awf !== "object")
|
|
24170
24170
|
return;
|
|
24171
24171
|
const pollInterval = awf.pollInterval;
|
|
24172
24172
|
let timeoutHandler;
|
|
24173
|
-
let fullPath =
|
|
24174
|
-
if (this.options.cwd && !sp2.isAbsolute(
|
|
24175
|
-
fullPath = sp2.join(this.options.cwd,
|
|
24173
|
+
let fullPath = path56;
|
|
24174
|
+
if (this.options.cwd && !sp2.isAbsolute(path56)) {
|
|
24175
|
+
fullPath = sp2.join(this.options.cwd, path56);
|
|
24176
24176
|
}
|
|
24177
24177
|
const now = /* @__PURE__ */ new Date();
|
|
24178
24178
|
const writes = this._pendingWrites;
|
|
24179
24179
|
function awaitWriteFinishFn(prevStat) {
|
|
24180
24180
|
statcb(fullPath, (err, curStat) => {
|
|
24181
|
-
if (err || !writes.has(
|
|
24181
|
+
if (err || !writes.has(path56)) {
|
|
24182
24182
|
if (err && err.code !== "ENOENT")
|
|
24183
24183
|
awfEmit(err);
|
|
24184
24184
|
return;
|
|
24185
24185
|
}
|
|
24186
24186
|
const now2 = Number(/* @__PURE__ */ new Date());
|
|
24187
24187
|
if (prevStat && curStat.size !== prevStat.size) {
|
|
24188
|
-
writes.get(
|
|
24188
|
+
writes.get(path56).lastChange = now2;
|
|
24189
24189
|
}
|
|
24190
|
-
const pw = writes.get(
|
|
24190
|
+
const pw = writes.get(path56);
|
|
24191
24191
|
const df = now2 - pw.lastChange;
|
|
24192
24192
|
if (df >= threshold) {
|
|
24193
|
-
writes.delete(
|
|
24193
|
+
writes.delete(path56);
|
|
24194
24194
|
awfEmit(void 0, curStat);
|
|
24195
24195
|
} else {
|
|
24196
24196
|
timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval, curStat);
|
|
24197
24197
|
}
|
|
24198
24198
|
});
|
|
24199
24199
|
}
|
|
24200
|
-
if (!writes.has(
|
|
24201
|
-
writes.set(
|
|
24200
|
+
if (!writes.has(path56)) {
|
|
24201
|
+
writes.set(path56, {
|
|
24202
24202
|
lastChange: now,
|
|
24203
24203
|
cancelWait: () => {
|
|
24204
|
-
writes.delete(
|
|
24204
|
+
writes.delete(path56);
|
|
24205
24205
|
clearTimeout(timeoutHandler);
|
|
24206
24206
|
return event;
|
|
24207
24207
|
}
|
|
@@ -24212,8 +24212,8 @@ var init_chokidar = __esm({
|
|
|
24212
24212
|
/**
|
|
24213
24213
|
* Determines whether user has asked to ignore this path.
|
|
24214
24214
|
*/
|
|
24215
|
-
_isIgnored(
|
|
24216
|
-
if (this.options.atomic && DOT_RE.test(
|
|
24215
|
+
_isIgnored(path56, stats2) {
|
|
24216
|
+
if (this.options.atomic && DOT_RE.test(path56))
|
|
24217
24217
|
return true;
|
|
24218
24218
|
if (!this._userIgnored) {
|
|
24219
24219
|
const { cwd } = this.options;
|
|
@@ -24223,17 +24223,17 @@ var init_chokidar = __esm({
|
|
|
24223
24223
|
const list2 = [...ignoredPaths.map(normalizeIgnored(cwd)), ...ignored];
|
|
24224
24224
|
this._userIgnored = anymatch(list2, void 0);
|
|
24225
24225
|
}
|
|
24226
|
-
return this._userIgnored(
|
|
24226
|
+
return this._userIgnored(path56, stats2);
|
|
24227
24227
|
}
|
|
24228
|
-
_isntIgnored(
|
|
24229
|
-
return !this._isIgnored(
|
|
24228
|
+
_isntIgnored(path56, stat8) {
|
|
24229
|
+
return !this._isIgnored(path56, stat8);
|
|
24230
24230
|
}
|
|
24231
24231
|
/**
|
|
24232
24232
|
* Provides a set of common helpers and properties relating to symlink handling.
|
|
24233
24233
|
* @param path file or directory pattern being watched
|
|
24234
24234
|
*/
|
|
24235
|
-
_getWatchHelpers(
|
|
24236
|
-
return new WatchHelper(
|
|
24235
|
+
_getWatchHelpers(path56) {
|
|
24236
|
+
return new WatchHelper(path56, this.options.followSymlinks, this);
|
|
24237
24237
|
}
|
|
24238
24238
|
// Directory helpers
|
|
24239
24239
|
// -----------------
|
|
@@ -24265,63 +24265,63 @@ var init_chokidar = __esm({
|
|
|
24265
24265
|
* @param item base path of item/directory
|
|
24266
24266
|
*/
|
|
24267
24267
|
_remove(directory, item, isDirectory) {
|
|
24268
|
-
const
|
|
24269
|
-
const fullPath = sp2.resolve(
|
|
24270
|
-
isDirectory = isDirectory != null ? isDirectory : this._watched.has(
|
|
24271
|
-
if (!this._throttle("remove",
|
|
24268
|
+
const path56 = sp2.join(directory, item);
|
|
24269
|
+
const fullPath = sp2.resolve(path56);
|
|
24270
|
+
isDirectory = isDirectory != null ? isDirectory : this._watched.has(path56) || this._watched.has(fullPath);
|
|
24271
|
+
if (!this._throttle("remove", path56, 100))
|
|
24272
24272
|
return;
|
|
24273
24273
|
if (!isDirectory && this._watched.size === 1) {
|
|
24274
24274
|
this.add(directory, item, true);
|
|
24275
24275
|
}
|
|
24276
|
-
const wp = this._getWatchedDir(
|
|
24276
|
+
const wp = this._getWatchedDir(path56);
|
|
24277
24277
|
const nestedDirectoryChildren = wp.getChildren();
|
|
24278
|
-
nestedDirectoryChildren.forEach((nested) => this._remove(
|
|
24278
|
+
nestedDirectoryChildren.forEach((nested) => this._remove(path56, nested));
|
|
24279
24279
|
const parent = this._getWatchedDir(directory);
|
|
24280
24280
|
const wasTracked = parent.has(item);
|
|
24281
24281
|
parent.remove(item);
|
|
24282
24282
|
if (this._symlinkPaths.has(fullPath)) {
|
|
24283
24283
|
this._symlinkPaths.delete(fullPath);
|
|
24284
24284
|
}
|
|
24285
|
-
let relPath =
|
|
24285
|
+
let relPath = path56;
|
|
24286
24286
|
if (this.options.cwd)
|
|
24287
|
-
relPath = sp2.relative(this.options.cwd,
|
|
24287
|
+
relPath = sp2.relative(this.options.cwd, path56);
|
|
24288
24288
|
if (this.options.awaitWriteFinish && this._pendingWrites.has(relPath)) {
|
|
24289
24289
|
const event = this._pendingWrites.get(relPath).cancelWait();
|
|
24290
24290
|
if (event === EVENTS.ADD)
|
|
24291
24291
|
return;
|
|
24292
24292
|
}
|
|
24293
|
-
this._watched.delete(
|
|
24293
|
+
this._watched.delete(path56);
|
|
24294
24294
|
this._watched.delete(fullPath);
|
|
24295
24295
|
const eventName = isDirectory ? EVENTS.UNLINK_DIR : EVENTS.UNLINK;
|
|
24296
|
-
if (wasTracked && !this._isIgnored(
|
|
24297
|
-
this._emit(eventName,
|
|
24298
|
-
this._closePath(
|
|
24296
|
+
if (wasTracked && !this._isIgnored(path56))
|
|
24297
|
+
this._emit(eventName, path56);
|
|
24298
|
+
this._closePath(path56);
|
|
24299
24299
|
}
|
|
24300
24300
|
/**
|
|
24301
24301
|
* Closes all watchers for a path
|
|
24302
24302
|
*/
|
|
24303
|
-
_closePath(
|
|
24304
|
-
this._closeFile(
|
|
24305
|
-
const dir = sp2.dirname(
|
|
24306
|
-
this._getWatchedDir(dir).remove(sp2.basename(
|
|
24303
|
+
_closePath(path56) {
|
|
24304
|
+
this._closeFile(path56);
|
|
24305
|
+
const dir = sp2.dirname(path56);
|
|
24306
|
+
this._getWatchedDir(dir).remove(sp2.basename(path56));
|
|
24307
24307
|
}
|
|
24308
24308
|
/**
|
|
24309
24309
|
* Closes only file-specific watchers
|
|
24310
24310
|
*/
|
|
24311
|
-
_closeFile(
|
|
24312
|
-
const closers = this._closers.get(
|
|
24311
|
+
_closeFile(path56) {
|
|
24312
|
+
const closers = this._closers.get(path56);
|
|
24313
24313
|
if (!closers)
|
|
24314
24314
|
return;
|
|
24315
24315
|
closers.forEach((closer) => closer());
|
|
24316
|
-
this._closers.delete(
|
|
24316
|
+
this._closers.delete(path56);
|
|
24317
24317
|
}
|
|
24318
|
-
_addPathCloser(
|
|
24318
|
+
_addPathCloser(path56, closer) {
|
|
24319
24319
|
if (!closer)
|
|
24320
24320
|
return;
|
|
24321
|
-
let list2 = this._closers.get(
|
|
24321
|
+
let list2 = this._closers.get(path56);
|
|
24322
24322
|
if (!list2) {
|
|
24323
24323
|
list2 = [];
|
|
24324
|
-
this._closers.set(
|
|
24324
|
+
this._closers.set(path56, list2);
|
|
24325
24325
|
}
|
|
24326
24326
|
list2.push(closer);
|
|
24327
24327
|
}
|
|
@@ -24349,7 +24349,7 @@ var init_chokidar = __esm({
|
|
|
24349
24349
|
|
|
24350
24350
|
// src/memory/tools/memory/manager-atomic-reindex.ts
|
|
24351
24351
|
import { randomUUID as randomUUID9 } from "node:crypto";
|
|
24352
|
-
import
|
|
24352
|
+
import fs49 from "node:fs/promises";
|
|
24353
24353
|
import { setTimeout as sleep6 } from "node:timers/promises";
|
|
24354
24354
|
function isTransientFileError(err) {
|
|
24355
24355
|
return transientFileErrorCodes.has(err.code ?? "");
|
|
@@ -24389,10 +24389,10 @@ async function moveMemoryIndexFiles(sourceBase, targetBase, options = {}) {
|
|
|
24389
24389
|
await renameWithRetry(source, target, resolvedOptions);
|
|
24390
24390
|
}
|
|
24391
24391
|
}
|
|
24392
|
-
async function rmWithRetry(
|
|
24392
|
+
async function rmWithRetry(path56, options) {
|
|
24393
24393
|
for (let attempt = 1; attempt <= options.maxRemoveAttempts; attempt++) {
|
|
24394
24394
|
try {
|
|
24395
|
-
await options.fileOps.rm(
|
|
24395
|
+
await options.fileOps.rm(path56, { force: true });
|
|
24396
24396
|
return;
|
|
24397
24397
|
} catch (err) {
|
|
24398
24398
|
if (err.code === "ENOENT") {
|
|
@@ -24449,8 +24449,8 @@ var init_manager_atomic_reindex = __esm({
|
|
|
24449
24449
|
"src/memory/tools/memory/manager-atomic-reindex.ts"() {
|
|
24450
24450
|
"use strict";
|
|
24451
24451
|
defaultFileOps = {
|
|
24452
|
-
rename:
|
|
24453
|
-
rm:
|
|
24452
|
+
rename: fs49.rename,
|
|
24453
|
+
rm: fs49.rm,
|
|
24454
24454
|
wait: sleep6
|
|
24455
24455
|
};
|
|
24456
24456
|
transientFileErrorCodes = /* @__PURE__ */ new Set(["EBUSY", "EPERM", "EACCES"]);
|
|
@@ -24732,8 +24732,8 @@ var init_watch_settle = __esm({
|
|
|
24732
24732
|
// src/memory/tools/memory/manager-sync-ops.ts
|
|
24733
24733
|
import { randomUUID as randomUUID10 } from "node:crypto";
|
|
24734
24734
|
import fsSync3 from "node:fs";
|
|
24735
|
-
import
|
|
24736
|
-
import
|
|
24735
|
+
import fs50 from "node:fs/promises";
|
|
24736
|
+
import path52 from "node:path";
|
|
24737
24737
|
function isSyncDisabled(cfg) {
|
|
24738
24738
|
try {
|
|
24739
24739
|
const searchCfg = cfg?.agents?.defaults?.memorySearch;
|
|
@@ -24752,8 +24752,8 @@ function resolveMemoryWatchFactory() {
|
|
|
24752
24752
|
return chokidar_default.watch.bind(chokidar_default);
|
|
24753
24753
|
}
|
|
24754
24754
|
function shouldIgnoreMemoryWatchPath(watchPath, stats2, multimodalSettings) {
|
|
24755
|
-
const normalized =
|
|
24756
|
-
const parts = normalized.split(
|
|
24755
|
+
const normalized = path52.normalize(watchPath);
|
|
24756
|
+
const parts = normalized.split(path52.sep).map((segment) => normalizeLowercaseStringOrEmpty(segment));
|
|
24757
24757
|
if (parts.some((segment) => IGNORED_MEMORY_WATCH_DIR_NAMES.has(segment))) {
|
|
24758
24758
|
return true;
|
|
24759
24759
|
}
|
|
@@ -24763,7 +24763,7 @@ function shouldIgnoreMemoryWatchPath(watchPath, stats2, multimodalSettings) {
|
|
|
24763
24763
|
if (!stats2) {
|
|
24764
24764
|
return false;
|
|
24765
24765
|
}
|
|
24766
|
-
const extension = normalizeLowercaseStringOrEmpty(
|
|
24766
|
+
const extension = normalizeLowercaseStringOrEmpty(path52.extname(normalized));
|
|
24767
24767
|
if (extension.length === 0 || extension === ".md") {
|
|
24768
24768
|
return false;
|
|
24769
24769
|
}
|
|
@@ -25028,8 +25028,8 @@ var init_manager_sync_ops = __esm({
|
|
|
25028
25028
|
return;
|
|
25029
25029
|
}
|
|
25030
25030
|
const watchPaths = /* @__PURE__ */ new Set([
|
|
25031
|
-
|
|
25032
|
-
|
|
25031
|
+
path52.join(this.workspaceDir, "MEMORY.md"),
|
|
25032
|
+
path52.join(this.workspaceDir, "memory")
|
|
25033
25033
|
]);
|
|
25034
25034
|
const additionalPaths = normalizeExtraMemoryPaths(this.workspaceDir, this.settings.extraPaths);
|
|
25035
25035
|
for (const entry of additionalPaths) {
|
|
@@ -25120,7 +25120,7 @@ var init_manager_sync_ops = __esm({
|
|
|
25120
25120
|
const fileStates = (await runWithConcurrency(
|
|
25121
25121
|
files.map((file) => async () => {
|
|
25122
25122
|
try {
|
|
25123
|
-
const stat8 = await
|
|
25123
|
+
const stat8 = await fs50.stat(file);
|
|
25124
25124
|
if (!stat8.isFile()) {
|
|
25125
25125
|
return null;
|
|
25126
25126
|
}
|
|
@@ -25179,7 +25179,7 @@ var init_manager_sync_ops = __esm({
|
|
|
25179
25179
|
this.sessionPendingFiles.clear();
|
|
25180
25180
|
let shouldSync = false;
|
|
25181
25181
|
for (const sessionFile of pending2) {
|
|
25182
|
-
const baseName =
|
|
25182
|
+
const baseName = path52.basename(sessionFile);
|
|
25183
25183
|
if (isSessionArchiveArtifactName(baseName) && isUsageCountedSessionTranscriptFileName(baseName)) {
|
|
25184
25184
|
this.sessionsDirtyFiles.add(sessionFile);
|
|
25185
25185
|
this.sessionsDirty = true;
|
|
@@ -25216,7 +25216,7 @@ var init_manager_sync_ops = __esm({
|
|
|
25216
25216
|
}
|
|
25217
25217
|
let stat8;
|
|
25218
25218
|
try {
|
|
25219
|
-
stat8 = await
|
|
25219
|
+
stat8 = await fs50.stat(sessionFile);
|
|
25220
25220
|
} catch {
|
|
25221
25221
|
return null;
|
|
25222
25222
|
}
|
|
@@ -25264,7 +25264,7 @@ var init_manager_sync_ops = __esm({
|
|
|
25264
25264
|
}
|
|
25265
25265
|
let handle;
|
|
25266
25266
|
try {
|
|
25267
|
-
handle = await
|
|
25267
|
+
handle = await fs50.open(absPath, "r");
|
|
25268
25268
|
} catch (err) {
|
|
25269
25269
|
if (isFileMissingError(err)) {
|
|
25270
25270
|
return 0;
|
|
@@ -25307,9 +25307,9 @@ var init_manager_sync_ops = __esm({
|
|
|
25307
25307
|
return false;
|
|
25308
25308
|
}
|
|
25309
25309
|
const sessionsDir = resolveSessionTranscriptsDirForAgent({ agentId: this.agentId });
|
|
25310
|
-
const resolvedFile =
|
|
25311
|
-
const resolvedDir =
|
|
25312
|
-
return resolvedFile.startsWith(`${resolvedDir}${
|
|
25310
|
+
const resolvedFile = path52.resolve(sessionFile);
|
|
25311
|
+
const resolvedDir = path52.resolve(sessionsDir);
|
|
25312
|
+
return resolvedFile.startsWith(`${resolvedDir}${path52.sep}`);
|
|
25313
25313
|
}
|
|
25314
25314
|
normalizeTargetSessionFiles(sessionFiles) {
|
|
25315
25315
|
if (!sessionFiles || sessionFiles.length === 0) {
|
|
@@ -25321,7 +25321,7 @@ var init_manager_sync_ops = __esm({
|
|
|
25321
25321
|
if (!trimmed) {
|
|
25322
25322
|
continue;
|
|
25323
25323
|
}
|
|
25324
|
-
const resolved =
|
|
25324
|
+
const resolved = path52.resolve(trimmed);
|
|
25325
25325
|
if (this.isSessionFileForAgent(resolved)) {
|
|
25326
25326
|
normalized.add(resolved);
|
|
25327
25327
|
}
|
|
@@ -25968,7 +25968,7 @@ var init_manager_vector_write = __esm({
|
|
|
25968
25968
|
});
|
|
25969
25969
|
|
|
25970
25970
|
// src/memory/tools/memory/manager-embedding-ops.ts
|
|
25971
|
-
import
|
|
25971
|
+
import fs51 from "node:fs/promises";
|
|
25972
25972
|
function resolveEmbeddingTimeoutMs(params) {
|
|
25973
25973
|
if (params.kind === "query") {
|
|
25974
25974
|
const runtimeTimeoutMs2 = params.providerRuntime?.inlineQueryTimeoutMs;
|
|
@@ -26509,7 +26509,7 @@ var init_manager_embedding_ops = __esm({
|
|
|
26509
26509
|
if ("kind" in entry && entry.kind === "multimodal") {
|
|
26510
26510
|
return;
|
|
26511
26511
|
}
|
|
26512
|
-
const content = options.content ?? await
|
|
26512
|
+
const content = options.content ?? await fs51.readFile(entry.absPath, "utf-8");
|
|
26513
26513
|
const chunks2 = filterNonEmptyMemoryChunks(chunkMarkdown(content, this.settings.chunking));
|
|
26514
26514
|
if (options.source === "sessions" && "lineMap" in entry) {
|
|
26515
26515
|
remapChunkLines(chunks2, entry.lineMap);
|
|
@@ -26538,7 +26538,7 @@ var init_manager_embedding_ops = __esm({
|
|
|
26538
26538
|
structuredInputBytes = multimodalChunk.structuredInputBytes;
|
|
26539
26539
|
chunks = [multimodalChunk.chunk];
|
|
26540
26540
|
} else {
|
|
26541
|
-
const content = options.content ?? await
|
|
26541
|
+
const content = options.content ?? await fs51.readFile(entry.absPath, "utf-8");
|
|
26542
26542
|
const baseChunks = filterNonEmptyMemoryChunks(chunkMarkdown(content, this.settings.chunking));
|
|
26543
26543
|
chunks = this.provider ? enforceEmbeddingMaxInputTokens(this.provider, baseChunks, EMBEDDING_BATCH_MAX_TOKENS) : baseChunks;
|
|
26544
26544
|
if (options.source === "sessions" && "lineMap" in entry) {
|
|
@@ -27821,7 +27821,7 @@ var init_qmd_manager = __esm({
|
|
|
27821
27821
|
});
|
|
27822
27822
|
|
|
27823
27823
|
// src/memory/tools/memory/search-manager.ts
|
|
27824
|
-
import
|
|
27824
|
+
import fs52 from "node:fs/promises";
|
|
27825
27825
|
function createMemorySearchManagerCacheStore() {
|
|
27826
27826
|
return {
|
|
27827
27827
|
qmdManagerCache: /* @__PURE__ */ new Map(),
|
|
@@ -27889,7 +27889,7 @@ async function getMemorySearchManager(params) {
|
|
|
27889
27889
|
const identityKey = buildQmdManagerIdentityKey(normalizedAgentId, qmdResolved, runtimeConfig);
|
|
27890
27890
|
const createPrimaryQmdManager = async (mode) => {
|
|
27891
27891
|
try {
|
|
27892
|
-
await
|
|
27892
|
+
await fs52.mkdir(workspaceDir, { recursive: true });
|
|
27893
27893
|
} catch (err) {
|
|
27894
27894
|
const message = formatErrorMessage(err);
|
|
27895
27895
|
log5.warn(
|
|
@@ -28752,8 +28752,8 @@ var manager_exports = {};
|
|
|
28752
28752
|
__export(manager_exports, {
|
|
28753
28753
|
McpManager: () => McpManager
|
|
28754
28754
|
});
|
|
28755
|
-
import * as
|
|
28756
|
-
import * as
|
|
28755
|
+
import * as fs53 from "node:fs";
|
|
28756
|
+
import * as path53 from "node:path";
|
|
28757
28757
|
import { Client as Client3 } from "@modelcontextprotocol/sdk/client/index.js";
|
|
28758
28758
|
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
28759
28759
|
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
@@ -28786,12 +28786,12 @@ function convertInputSchema(inputSchema) {
|
|
|
28786
28786
|
}
|
|
28787
28787
|
function persistBinary(base64Data, mimeType, persistId) {
|
|
28788
28788
|
const ext = mimeType?.split("/")[1] || "bin";
|
|
28789
|
-
const dir =
|
|
28790
|
-
|
|
28791
|
-
const filepath =
|
|
28789
|
+
const dir = path53.join(process.env.ENGINE_STATE_DIR || ".engine", "mcp-blobs");
|
|
28790
|
+
fs53.mkdirSync(dir, { recursive: true });
|
|
28791
|
+
const filepath = path53.join(dir, `${persistId}.${ext}`);
|
|
28792
28792
|
try {
|
|
28793
28793
|
const buf = Buffer.from(base64Data, "base64");
|
|
28794
|
-
|
|
28794
|
+
fs53.writeFileSync(filepath, buf);
|
|
28795
28795
|
return { filepath, size: buf.length };
|
|
28796
28796
|
} catch (err) {
|
|
28797
28797
|
return { error: err.message };
|
|
@@ -29125,7 +29125,7 @@ __export(resources_exports, {
|
|
|
29125
29125
|
registerMcpResourceTools: () => registerMcpResourceTools,
|
|
29126
29126
|
unregisterMcpResourceTools: () => unregisterMcpResourceTools
|
|
29127
29127
|
});
|
|
29128
|
-
import * as
|
|
29128
|
+
import * as path54 from "node:path";
|
|
29129
29129
|
function registerMcpResourceTools(manager) {
|
|
29130
29130
|
mcpManagerRef = manager;
|
|
29131
29131
|
registry.register(listResourcesTool);
|
|
@@ -29143,7 +29143,7 @@ var init_resources = __esm({
|
|
|
29143
29143
|
"use strict";
|
|
29144
29144
|
init_registry();
|
|
29145
29145
|
MAX_RESULT_CHARS2 = 1e5;
|
|
29146
|
-
MEDIA_DIR = process.env.ENGINE_MEDIA_DIR ||
|
|
29146
|
+
MEDIA_DIR = process.env.ENGINE_MEDIA_DIR || path54.join(process.env.ENGINE_STATE_DIR || ".engine", "media", "inbound");
|
|
29147
29147
|
MCP_LIST_RESOURCES_TOOL = "mcp__list_resources";
|
|
29148
29148
|
MCP_READ_RESOURCE_TOOL = "mcp__read_resource";
|
|
29149
29149
|
mcpManagerRef = null;
|
|
@@ -29312,10 +29312,10 @@ function ensureLoaded(workspace, configIds) {
|
|
|
29312
29312
|
if (!state.blockedUserIds.includes(id)) state.blockedUserIds.push(id);
|
|
29313
29313
|
}
|
|
29314
29314
|
}
|
|
29315
|
-
const
|
|
29315
|
+
const path56 = join39(workspace, ".reply-blocklist.json");
|
|
29316
29316
|
try {
|
|
29317
|
-
if (existsSync24(
|
|
29318
|
-
const raw = readFileSync26(
|
|
29317
|
+
if (existsSync24(path56)) {
|
|
29318
|
+
const raw = readFileSync26(path56, "utf-8");
|
|
29319
29319
|
const parsed = JSON.parse(raw);
|
|
29320
29320
|
if (parsed.blockedUserIds) {
|
|
29321
29321
|
for (const id of parsed.blockedUserIds) {
|
|
@@ -29331,9 +29331,9 @@ function ensureLoaded(workspace, configIds) {
|
|
|
29331
29331
|
loaded = true;
|
|
29332
29332
|
}
|
|
29333
29333
|
function save(workspace) {
|
|
29334
|
-
const
|
|
29334
|
+
const path56 = join39(workspace, ".reply-blocklist.json");
|
|
29335
29335
|
try {
|
|
29336
|
-
writeFileSync15(
|
|
29336
|
+
writeFileSync15(path56, JSON.stringify(state, null, 2), "utf-8");
|
|
29337
29337
|
} catch (err) {
|
|
29338
29338
|
console.warn(`[reply-blocklist] Failed to save: ${err.message}`);
|
|
29339
29339
|
}
|
|
@@ -29933,8 +29933,8 @@ var init_cognifold_intent_watcher = __esm({
|
|
|
29933
29933
|
init_loader();
|
|
29934
29934
|
|
|
29935
29935
|
// src/engine-startup.ts
|
|
29936
|
-
import * as
|
|
29937
|
-
import * as
|
|
29936
|
+
import * as path55 from "node:path";
|
|
29937
|
+
import * as fs54 from "node:fs";
|
|
29938
29938
|
import { fileURLToPath } from "node:url";
|
|
29939
29939
|
|
|
29940
29940
|
// src/pid-lock.ts
|
|
@@ -31276,13 +31276,13 @@ var DiscordAdapter = class _DiscordAdapter {
|
|
|
31276
31276
|
}
|
|
31277
31277
|
/** 发送媒体附件(图片/文件/音频)— discord.js channel.send({ files }) */
|
|
31278
31278
|
async sendFile(target, message, attachment) {
|
|
31279
|
-
const
|
|
31280
|
-
const
|
|
31281
|
-
if (!
|
|
31279
|
+
const fs55 = await import("node:fs");
|
|
31280
|
+
const path56 = await import("node:path");
|
|
31281
|
+
if (!fs55.existsSync(attachment.path)) {
|
|
31282
31282
|
throw new Error(`File not found: ${attachment.path}`);
|
|
31283
31283
|
}
|
|
31284
|
-
const filename = attachment.filename ||
|
|
31285
|
-
const fileBuffer =
|
|
31284
|
+
const filename = attachment.filename || path56.basename(attachment.path);
|
|
31285
|
+
const fileBuffer = fs55.readFileSync(attachment.path);
|
|
31286
31286
|
const filePayload = {
|
|
31287
31287
|
attachment: fileBuffer,
|
|
31288
31288
|
name: filename
|
|
@@ -31722,13 +31722,13 @@ var FeishuAdapter = class _FeishuAdapter {
|
|
|
31722
31722
|
}
|
|
31723
31723
|
/** 发送媒体附件(图片/文件) */
|
|
31724
31724
|
async sendFile(target, message, attachment) {
|
|
31725
|
-
const
|
|
31726
|
-
const
|
|
31727
|
-
if (!
|
|
31725
|
+
const fs55 = await import("node:fs");
|
|
31726
|
+
const path56 = await import("node:path");
|
|
31727
|
+
if (!fs55.existsSync(attachment.path)) {
|
|
31728
31728
|
throw new Error(`File not found: ${attachment.path}`);
|
|
31729
31729
|
}
|
|
31730
|
-
const filename = attachment.filename ||
|
|
31731
|
-
const fileBuffer =
|
|
31730
|
+
const filename = attachment.filename || path56.basename(attachment.path);
|
|
31731
|
+
const fileBuffer = fs55.readFileSync(attachment.path);
|
|
31732
31732
|
const receiveIdType = target.startsWith("ou_") ? "open_id" : "chat_id";
|
|
31733
31733
|
const mimeType = attachment.mimeType || "application/octet-stream";
|
|
31734
31734
|
if (mimeType.startsWith("image/")) {
|
|
@@ -35718,18 +35718,18 @@ function truncate(s2, maxLen) {
|
|
|
35718
35718
|
}
|
|
35719
35719
|
var externalChanRulesCache = null;
|
|
35720
35720
|
function loadExternalChanRules(workspace) {
|
|
35721
|
-
const
|
|
35722
|
-
if (externalChanRulesCache && externalChanRulesCache.path ===
|
|
35721
|
+
const path56 = join20(workspace, "prompts", "external-chan-rules.md");
|
|
35722
|
+
if (externalChanRulesCache && externalChanRulesCache.path === path56) return externalChanRulesCache;
|
|
35723
35723
|
let content = "";
|
|
35724
|
-
if (existsSync12(
|
|
35724
|
+
if (existsSync12(path56)) {
|
|
35725
35725
|
try {
|
|
35726
|
-
content = readFileSync15(
|
|
35726
|
+
content = readFileSync15(path56, "utf-8").trim();
|
|
35727
35727
|
} catch (e) {
|
|
35728
35728
|
console.warn(`[external-chan-rules] Failed to load: ${e}`);
|
|
35729
35729
|
}
|
|
35730
35730
|
}
|
|
35731
|
-
externalChanRulesCache = { path:
|
|
35732
|
-
console.log(`[external-chan-rules] Loaded ${content.length} chars from ${
|
|
35731
|
+
externalChanRulesCache = { path: path56, content };
|
|
35732
|
+
console.log(`[external-chan-rules] Loaded ${content.length} chars from ${path56}`);
|
|
35733
35733
|
return externalChanRulesCache;
|
|
35734
35734
|
}
|
|
35735
35735
|
function getExternalChanRulesBlock(inboundMeta, workspace) {
|
|
@@ -40509,11 +40509,11 @@ var CogniFoldClient = class {
|
|
|
40509
40509
|
this.baseUrl = baseUrl.replace(/\/$/, "");
|
|
40510
40510
|
this.timeoutMs = timeoutMs;
|
|
40511
40511
|
}
|
|
40512
|
-
async req(
|
|
40512
|
+
async req(path56, options = {}) {
|
|
40513
40513
|
const ctrl = new AbortController();
|
|
40514
40514
|
const timer = setTimeout(() => ctrl.abort(), this.timeoutMs);
|
|
40515
40515
|
try {
|
|
40516
|
-
const resp = await fetch(`${this.baseUrl}${
|
|
40516
|
+
const resp = await fetch(`${this.baseUrl}${path56}`, {
|
|
40517
40517
|
...options,
|
|
40518
40518
|
signal: ctrl.signal,
|
|
40519
40519
|
headers: {
|
|
@@ -40603,8 +40603,8 @@ var CogniFoldClient = class {
|
|
|
40603
40603
|
});
|
|
40604
40604
|
}
|
|
40605
40605
|
/** 兼容老版命名 */
|
|
40606
|
-
async recl(
|
|
40607
|
-
return this.req(
|
|
40606
|
+
async recl(path56, options = {}) {
|
|
40607
|
+
return this.req(path56, options);
|
|
40608
40608
|
}
|
|
40609
40609
|
};
|
|
40610
40610
|
|
|
@@ -40992,25 +40992,375 @@ var CogniFoldPlugin = class {
|
|
|
40992
40992
|
}
|
|
40993
40993
|
};
|
|
40994
40994
|
|
|
40995
|
+
// src/memory/everos/plugin.ts
|
|
40996
|
+
init_BashTool();
|
|
40997
|
+
import { spawn as spawn6 } from "node:child_process";
|
|
40998
|
+
import net3 from "node:net";
|
|
40999
|
+
import path24 from "node:path";
|
|
41000
|
+
import fs24 from "node:fs";
|
|
41001
|
+
|
|
41002
|
+
// src/memory/everos/config.ts
|
|
41003
|
+
var DEFAULTS4 = {
|
|
41004
|
+
everosUrl: "http://127.0.0.1:8100",
|
|
41005
|
+
agenticUrl: "http://127.0.0.1:8101",
|
|
41006
|
+
agenticPort: 8101,
|
|
41007
|
+
autoStart: true,
|
|
41008
|
+
defaultMode: "hybrid_agentic"
|
|
41009
|
+
};
|
|
41010
|
+
function parseEverosConfig(raw) {
|
|
41011
|
+
if (!raw) {
|
|
41012
|
+
return {
|
|
41013
|
+
enabled: false,
|
|
41014
|
+
...DEFAULTS4,
|
|
41015
|
+
userId: "xiaomei",
|
|
41016
|
+
llm: { model: "glm-5.2", apiKey: "", baseUrl: "https://open.bigmodel.cn/api/coding/paas/v4" },
|
|
41017
|
+
rerank: { model: "Qwen/Qwen3-Reranker-4B", apiKey: "", baseUrl: "https://api.deepinfra.com/v1/inference" },
|
|
41018
|
+
lancedbPath: "",
|
|
41019
|
+
sqlitePath: ""
|
|
41020
|
+
};
|
|
41021
|
+
}
|
|
41022
|
+
return {
|
|
41023
|
+
enabled: raw.enabled === true,
|
|
41024
|
+
everosUrl: raw.everosUrl ?? DEFAULTS4.everosUrl,
|
|
41025
|
+
agenticUrl: raw.agenticUrl ?? DEFAULTS4.agenticUrl,
|
|
41026
|
+
agenticPort: raw.agenticPort ?? DEFAULTS4.agenticPort,
|
|
41027
|
+
userId: raw.userId ?? "xiaomei",
|
|
41028
|
+
autoStart: raw.autoStart !== false,
|
|
41029
|
+
defaultMode: raw.defaultMode ?? DEFAULTS4.defaultMode,
|
|
41030
|
+
llm: raw.llm ?? { model: "glm-5.2", apiKey: "", baseUrl: "https://open.bigmodel.cn/api/coding/paas/v4" },
|
|
41031
|
+
rerank: raw.rerank ?? { model: "Qwen/Qwen3-Reranker-4B", apiKey: "", baseUrl: "https://api.deepinfra.com/v1/inference" },
|
|
41032
|
+
lancedbPath: raw.lancedbPath ?? "",
|
|
41033
|
+
sqlitePath: raw.sqlitePath ?? ""
|
|
41034
|
+
};
|
|
41035
|
+
}
|
|
41036
|
+
|
|
41037
|
+
// src/memory/everos/client.ts
|
|
41038
|
+
var EverosSearchClient = class {
|
|
41039
|
+
agenticUrl;
|
|
41040
|
+
everosUrl;
|
|
41041
|
+
timeoutMs;
|
|
41042
|
+
constructor(agenticUrl, everosUrl, timeoutMs = 12e4) {
|
|
41043
|
+
this.agenticUrl = agenticUrl.replace(/\/$/, "");
|
|
41044
|
+
this.everosUrl = (everosUrl || "http://127.0.0.1:8100").replace(/\/$/, "");
|
|
41045
|
+
this.timeoutMs = timeoutMs;
|
|
41046
|
+
}
|
|
41047
|
+
/** Health check for agentic server */
|
|
41048
|
+
async health() {
|
|
41049
|
+
const ctrl = new AbortController();
|
|
41050
|
+
const timer = setTimeout(() => ctrl.abort(), 5e3);
|
|
41051
|
+
try {
|
|
41052
|
+
const resp = await fetch(`${this.agenticUrl}/health`, { signal: ctrl.signal });
|
|
41053
|
+
if (!resp.ok) throw new Error(`health ${resp.status}`);
|
|
41054
|
+
return await resp.json();
|
|
41055
|
+
} finally {
|
|
41056
|
+
clearTimeout(timer);
|
|
41057
|
+
}
|
|
41058
|
+
}
|
|
41059
|
+
/** Health check for EverOS itself */
|
|
41060
|
+
async healthEveros() {
|
|
41061
|
+
const ctrl = new AbortController();
|
|
41062
|
+
const timer = setTimeout(() => ctrl.abort(), 5e3);
|
|
41063
|
+
try {
|
|
41064
|
+
const resp = await fetch(`${this.everosUrl}/health`, { signal: ctrl.signal });
|
|
41065
|
+
if (!resp.ok) throw new Error(`everos health ${resp.status}`);
|
|
41066
|
+
return await resp.json();
|
|
41067
|
+
} finally {
|
|
41068
|
+
clearTimeout(timer);
|
|
41069
|
+
}
|
|
41070
|
+
}
|
|
41071
|
+
/** Search — 3-mode unified endpoint */
|
|
41072
|
+
async search(params) {
|
|
41073
|
+
const ctrl = new AbortController();
|
|
41074
|
+
const timer = setTimeout(() => ctrl.abort(), this.timeoutMs);
|
|
41075
|
+
try {
|
|
41076
|
+
const resp = await fetch(`${this.agenticUrl}/api/v1/search`, {
|
|
41077
|
+
method: "POST",
|
|
41078
|
+
headers: { "Content-Type": "application/json" },
|
|
41079
|
+
body: JSON.stringify({
|
|
41080
|
+
query: params.query,
|
|
41081
|
+
user_id: params.userId || "xiaomei",
|
|
41082
|
+
mode: params.mode || "hybrid_agentic",
|
|
41083
|
+
top_k: params.topK ?? 5,
|
|
41084
|
+
strategy: params.strategy || "multi_query"
|
|
41085
|
+
}),
|
|
41086
|
+
signal: ctrl.signal
|
|
41087
|
+
});
|
|
41088
|
+
if (!resp.ok) {
|
|
41089
|
+
const text = await resp.text();
|
|
41090
|
+
throw new Error(`EverOS search ${resp.status}: ${text.slice(0, 200)}`);
|
|
41091
|
+
}
|
|
41092
|
+
return await resp.json();
|
|
41093
|
+
} finally {
|
|
41094
|
+
clearTimeout(timer);
|
|
41095
|
+
}
|
|
41096
|
+
}
|
|
41097
|
+
/** Quick hybrid-only search (fast path) */
|
|
41098
|
+
async searchFast(query, userId, topK = 5) {
|
|
41099
|
+
return this.search({ query, userId, mode: "hybrid", topK });
|
|
41100
|
+
}
|
|
41101
|
+
/** Full agentic search (deep path) */
|
|
41102
|
+
async searchDeep(query, userId, topK = 5) {
|
|
41103
|
+
return this.search({ query, userId, mode: "agentic", topK });
|
|
41104
|
+
}
|
|
41105
|
+
};
|
|
41106
|
+
|
|
41107
|
+
// src/memory/everos/plugin.ts
|
|
41108
|
+
var EverosPlugin = class {
|
|
41109
|
+
name = "everos";
|
|
41110
|
+
config;
|
|
41111
|
+
client;
|
|
41112
|
+
agenticProcess = null;
|
|
41113
|
+
healthTimer = null;
|
|
41114
|
+
weStartedAgentic = false;
|
|
41115
|
+
// 我们拉起的才管
|
|
41116
|
+
constructor(rawConfig) {
|
|
41117
|
+
this.config = parseEverosConfig(rawConfig);
|
|
41118
|
+
this.client = new EverosSearchClient(this.config.agenticUrl, this.config.everosUrl);
|
|
41119
|
+
}
|
|
41120
|
+
static shouldEnable(config2) {
|
|
41121
|
+
return config2?.everos?.enabled === true;
|
|
41122
|
+
}
|
|
41123
|
+
async start(ctx) {
|
|
41124
|
+
if (!this.config.enabled) return;
|
|
41125
|
+
try {
|
|
41126
|
+
await this.client.healthEveros();
|
|
41127
|
+
console.log(`[everos] EverOS already running at ${this.config.everosUrl}`);
|
|
41128
|
+
} catch {
|
|
41129
|
+
if (this.config.autoStart) {
|
|
41130
|
+
console.log(`[everos] EverOS not running, starting...`);
|
|
41131
|
+
await this.startEveros();
|
|
41132
|
+
} else {
|
|
41133
|
+
console.warn(`[everos] EverOS not running and autoStart=false`);
|
|
41134
|
+
}
|
|
41135
|
+
}
|
|
41136
|
+
const agenticPort = this.config.agenticPort;
|
|
41137
|
+
const agenticAlive = await this.isPortAlive(agenticPort);
|
|
41138
|
+
if (agenticAlive) {
|
|
41139
|
+
console.log(`[everos] Agentic server already running on port ${agenticPort}`);
|
|
41140
|
+
} else if (this.config.autoStart) {
|
|
41141
|
+
console.log(`[everos] Starting agentic server on port ${agenticPort}...`);
|
|
41142
|
+
this.weStartedAgentic = true;
|
|
41143
|
+
this.agenticProcess = this.startAgenticServer();
|
|
41144
|
+
await this.waitForReady(`${this.config.agenticUrl}/health`, 3e4);
|
|
41145
|
+
}
|
|
41146
|
+
;
|
|
41147
|
+
globalThis.__everosSearchClient = this.client;
|
|
41148
|
+
this.startHealthCheck();
|
|
41149
|
+
}
|
|
41150
|
+
async stop() {
|
|
41151
|
+
if (this.healthTimer) {
|
|
41152
|
+
clearInterval(this.healthTimer);
|
|
41153
|
+
this.healthTimer = null;
|
|
41154
|
+
}
|
|
41155
|
+
if (this.weStartedAgentic && this.agenticProcess) {
|
|
41156
|
+
console.log(`[everos] Stopping agentic server (PID ${this.agenticProcess.pid})`);
|
|
41157
|
+
this.agenticProcess.removeAllListeners();
|
|
41158
|
+
this.agenticProcess.kill("SIGTERM");
|
|
41159
|
+
this.agenticProcess = null;
|
|
41160
|
+
} else {
|
|
41161
|
+
console.log(`[everos] Stop \u2014 agentic server was not started by us, leaving it running`);
|
|
41162
|
+
}
|
|
41163
|
+
}
|
|
41164
|
+
getStatus() {
|
|
41165
|
+
return {
|
|
41166
|
+
everosRunning: true,
|
|
41167
|
+
// simplified
|
|
41168
|
+
agenticRunning: this.agenticProcess !== null,
|
|
41169
|
+
agenticPid: this.agenticProcess?.pid ?? null
|
|
41170
|
+
};
|
|
41171
|
+
}
|
|
41172
|
+
getClient() {
|
|
41173
|
+
return this.client;
|
|
41174
|
+
}
|
|
41175
|
+
// === 私有 ===
|
|
41176
|
+
startHealthCheck() {
|
|
41177
|
+
this.healthTimer = setInterval(async () => {
|
|
41178
|
+
try {
|
|
41179
|
+
await this.client.health();
|
|
41180
|
+
} catch {
|
|
41181
|
+
if (this.weStartedAgentic && !this.agenticProcess) {
|
|
41182
|
+
console.log(`[everos] Agentic server down, attempting restart...`);
|
|
41183
|
+
try {
|
|
41184
|
+
this.agenticProcess = this.startAgenticServer();
|
|
41185
|
+
await this.waitForReady(`${this.config.agenticUrl}/health`, 3e4);
|
|
41186
|
+
console.log(`[everos] Agentic server restarted`);
|
|
41187
|
+
} catch (err) {
|
|
41188
|
+
console.error(`[everos] Restart failed: ${err.message}`);
|
|
41189
|
+
}
|
|
41190
|
+
}
|
|
41191
|
+
}
|
|
41192
|
+
}, 3e5);
|
|
41193
|
+
}
|
|
41194
|
+
async startEveros() {
|
|
41195
|
+
const pythonDir = path24.dirname(this.config.lancedbPath);
|
|
41196
|
+
const configPath2 = path24.join(pythonDir, "config.toml");
|
|
41197
|
+
await this.ensureFcntlCompat();
|
|
41198
|
+
const venvPython = this.findVenvPython();
|
|
41199
|
+
const args2 = ["server", "start"];
|
|
41200
|
+
const cmd = `${venvPython} ${args2.join(" ")}`;
|
|
41201
|
+
console.log(`[everos] Starting EverOS: ${cmd}`);
|
|
41202
|
+
if (process.platform === "win32") {
|
|
41203
|
+
const { shell, args: shellArgs } = findShell();
|
|
41204
|
+
spawn6(shell, [...shellArgs, cmd], {
|
|
41205
|
+
cwd: pythonDir,
|
|
41206
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
41207
|
+
env: { ...process.env, PYTHONUNBUFFERED: "1" }
|
|
41208
|
+
});
|
|
41209
|
+
} else {
|
|
41210
|
+
spawn6(venvPython, args2, {
|
|
41211
|
+
cwd: pythonDir,
|
|
41212
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
41213
|
+
env: { ...process.env, PYTHONUNBUFFERED: "1" }
|
|
41214
|
+
});
|
|
41215
|
+
}
|
|
41216
|
+
await this.waitForReady(`${this.config.everosUrl}/health`, 3e4);
|
|
41217
|
+
}
|
|
41218
|
+
startAgenticServer() {
|
|
41219
|
+
const pythonDir = this.getPythonDir();
|
|
41220
|
+
const port = String(this.config.agenticPort);
|
|
41221
|
+
const venvPython = this.findVenvPython();
|
|
41222
|
+
const args2 = ["agentic_server.py", "--port", port];
|
|
41223
|
+
const cmd = `${venvPython} ${args2.join(" ")}`;
|
|
41224
|
+
console.log(`[everos] Starting agentic server: ${cmd}`);
|
|
41225
|
+
console.log(`[everos] Python dir: ${pythonDir}`);
|
|
41226
|
+
const childEnv = {
|
|
41227
|
+
...process.env,
|
|
41228
|
+
PYTHONUNBUFFERED: "1",
|
|
41229
|
+
EVEROS_URL: this.config.everosUrl,
|
|
41230
|
+
LLM_MODEL: this.config.llm.model,
|
|
41231
|
+
LLM_API_KEY: this.config.llm.apiKey,
|
|
41232
|
+
LLM_BASE_URL: this.config.llm.baseUrl,
|
|
41233
|
+
RERANK_API_KEY: this.config.rerank.apiKey,
|
|
41234
|
+
RERANK_URL: `${this.config.rerank.baseUrl}/${this.config.rerank.model}`,
|
|
41235
|
+
LANCEDB_PATH: this.config.lancedbPath,
|
|
41236
|
+
SQLITE_PATH: this.config.sqlitePath,
|
|
41237
|
+
EVEROS_USER_ID: this.config.userId
|
|
41238
|
+
};
|
|
41239
|
+
let child;
|
|
41240
|
+
if (process.platform === "win32") {
|
|
41241
|
+
const { shell, args: shellArgs } = findShell();
|
|
41242
|
+
child = spawn6(shell, [...shellArgs, cmd], {
|
|
41243
|
+
cwd: pythonDir,
|
|
41244
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
41245
|
+
env: childEnv
|
|
41246
|
+
});
|
|
41247
|
+
} else {
|
|
41248
|
+
child = spawn6(venvPython, args2, {
|
|
41249
|
+
cwd: pythonDir,
|
|
41250
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
41251
|
+
env: childEnv
|
|
41252
|
+
});
|
|
41253
|
+
}
|
|
41254
|
+
child.on("error", (err) => {
|
|
41255
|
+
console.error(`[everos] spawn error: ${err.message}`);
|
|
41256
|
+
});
|
|
41257
|
+
child.stdout?.on("data", (data) => {
|
|
41258
|
+
const lines = data.toString().trim().split("\n");
|
|
41259
|
+
for (const line of lines) console.log(`[everos:py] ${line}`);
|
|
41260
|
+
});
|
|
41261
|
+
child.stderr?.on("data", (data) => {
|
|
41262
|
+
const lines = data.toString().trim().split("\n");
|
|
41263
|
+
for (const line of lines) console.error(`[everos:py] ${line}`);
|
|
41264
|
+
});
|
|
41265
|
+
child.on("exit", (code, signal) => {
|
|
41266
|
+
console.log(`[everos] Agentic server exited (code=${code}, signal=${signal})`);
|
|
41267
|
+
this.agenticProcess = null;
|
|
41268
|
+
});
|
|
41269
|
+
return child;
|
|
41270
|
+
}
|
|
41271
|
+
findVenvPython() {
|
|
41272
|
+
const stateDir = process.env.OPENCLAW_STATE_DIR || path24.join(process.env.HOME || process.env.USERPROFILE || ".", ".openclaw");
|
|
41273
|
+
if (process.platform === "win32") {
|
|
41274
|
+
return path24.join(stateDir, "everos-venv", "Scripts", "python.exe");
|
|
41275
|
+
}
|
|
41276
|
+
return path24.join(stateDir, "everos-venv", "bin", "python");
|
|
41277
|
+
}
|
|
41278
|
+
getPythonDir() {
|
|
41279
|
+
const dir = import.meta.dirname;
|
|
41280
|
+
const candidates = [
|
|
41281
|
+
path24.join(dir, "python"),
|
|
41282
|
+
path24.resolve(dir, "..", "src", "memory", "everos", "python"),
|
|
41283
|
+
path24.resolve(dir, "..", "..", "..", "src", "memory", "everos", "python")
|
|
41284
|
+
];
|
|
41285
|
+
for (const candidate of candidates) {
|
|
41286
|
+
if (fs24.existsSync(path24.join(candidate, "agentic_server.py"))) {
|
|
41287
|
+
return candidate;
|
|
41288
|
+
}
|
|
41289
|
+
}
|
|
41290
|
+
return candidates[0];
|
|
41291
|
+
}
|
|
41292
|
+
async ensureFcntlCompat() {
|
|
41293
|
+
if (process.platform !== "win32") return;
|
|
41294
|
+
const venvPython = this.findVenvPython();
|
|
41295
|
+
const venvDir = path24.dirname(path24.dirname(venvPython));
|
|
41296
|
+
const sitePackages = path24.join(venvDir, "Lib", "site-packages");
|
|
41297
|
+
const target = path24.join(sitePackages, "fcntl.py");
|
|
41298
|
+
if (fs24.existsSync(target)) return;
|
|
41299
|
+
const source = path24.join(this.getPythonDir(), "fcntl_compat.py");
|
|
41300
|
+
if (fs24.existsSync(source)) {
|
|
41301
|
+
try {
|
|
41302
|
+
fs24.copyFileSync(source, target);
|
|
41303
|
+
console.log(`[everos] Installed fcntl compat shim to ${target}`);
|
|
41304
|
+
} catch (err) {
|
|
41305
|
+
console.warn(`[everos] Failed to install fcntl shim: ${err.message}`);
|
|
41306
|
+
}
|
|
41307
|
+
}
|
|
41308
|
+
}
|
|
41309
|
+
async waitForReady(url, timeoutMs) {
|
|
41310
|
+
const start = Date.now();
|
|
41311
|
+
while (Date.now() - start < timeoutMs) {
|
|
41312
|
+
try {
|
|
41313
|
+
const resp = await fetch(url);
|
|
41314
|
+
if (resp.ok) {
|
|
41315
|
+
console.log(`[everos] Service ready at ${url} (${Date.now() - start}ms)`);
|
|
41316
|
+
return;
|
|
41317
|
+
}
|
|
41318
|
+
} catch {
|
|
41319
|
+
}
|
|
41320
|
+
await new Promise((r) => setTimeout(r, 500));
|
|
41321
|
+
}
|
|
41322
|
+
throw new Error(`EverOS service not ready after ${timeoutMs}ms at ${url}`);
|
|
41323
|
+
}
|
|
41324
|
+
async isPortAlive(port) {
|
|
41325
|
+
return new Promise((resolve12) => {
|
|
41326
|
+
const socket = new net3.Socket();
|
|
41327
|
+
socket.setTimeout(2e3);
|
|
41328
|
+
socket.on("connect", () => {
|
|
41329
|
+
socket.destroy();
|
|
41330
|
+
resolve12(true);
|
|
41331
|
+
});
|
|
41332
|
+
socket.on("timeout", () => {
|
|
41333
|
+
socket.destroy();
|
|
41334
|
+
resolve12(false);
|
|
41335
|
+
});
|
|
41336
|
+
socket.on("error", () => {
|
|
41337
|
+
socket.destroy();
|
|
41338
|
+
resolve12(false);
|
|
41339
|
+
});
|
|
41340
|
+
socket.connect(port, "127.0.0.1");
|
|
41341
|
+
});
|
|
41342
|
+
}
|
|
41343
|
+
};
|
|
41344
|
+
|
|
40995
41345
|
// src/engine-startup.ts
|
|
40996
41346
|
init_task_manager();
|
|
40997
41347
|
|
|
40998
41348
|
// src/skills/scanner.ts
|
|
40999
|
-
import * as
|
|
41000
|
-
import * as
|
|
41349
|
+
import * as path25 from "node:path";
|
|
41350
|
+
import * as fs25 from "node:fs";
|
|
41001
41351
|
function scanSkills(skillsDir) {
|
|
41002
|
-
if (!
|
|
41352
|
+
if (!fs25.existsSync(skillsDir)) {
|
|
41003
41353
|
console.log(`[skills] Directory not found: ${skillsDir}`);
|
|
41004
41354
|
return [];
|
|
41005
41355
|
}
|
|
41006
|
-
const entries =
|
|
41356
|
+
const entries = fs25.readdirSync(skillsDir, { withFileTypes: true });
|
|
41007
41357
|
const skills = [];
|
|
41008
41358
|
for (const entry of entries) {
|
|
41009
41359
|
if (!entry.isDirectory()) continue;
|
|
41010
|
-
const skillMdPath =
|
|
41011
|
-
if (!
|
|
41360
|
+
const skillMdPath = path25.join(skillsDir, entry.name, "SKILL.md");
|
|
41361
|
+
if (!fs25.existsSync(skillMdPath)) continue;
|
|
41012
41362
|
try {
|
|
41013
|
-
const content =
|
|
41363
|
+
const content = fs25.readFileSync(skillMdPath, "utf-8");
|
|
41014
41364
|
const frontmatter = parseFrontmatter2(content);
|
|
41015
41365
|
if (!frontmatter.name) {
|
|
41016
41366
|
console.warn(`[skills] Skipping ${entry.name}/SKILL.md: missing 'name' in frontmatter`);
|
|
@@ -41074,8 +41424,8 @@ function parseFrontmatter2(content) {
|
|
|
41074
41424
|
|
|
41075
41425
|
// src/tools/SkillTool/SkillTool.ts
|
|
41076
41426
|
init_registry();
|
|
41077
|
-
import * as
|
|
41078
|
-
import * as
|
|
41427
|
+
import * as fs26 from "node:fs";
|
|
41428
|
+
import * as path26 from "node:path";
|
|
41079
41429
|
|
|
41080
41430
|
// src/tools/SkillTool/constants.ts
|
|
41081
41431
|
var SKILL_TOOL_NAME2 = "Skill";
|
|
@@ -41152,12 +41502,12 @@ Important:
|
|
|
41152
41502
|
`;
|
|
41153
41503
|
}
|
|
41154
41504
|
function loadSkillContent(skillName) {
|
|
41155
|
-
const skillMdPath =
|
|
41156
|
-
if (!
|
|
41157
|
-
const content =
|
|
41505
|
+
const skillMdPath = path26.join(skillsDirPath, skillName, "SKILL.md");
|
|
41506
|
+
if (!fs26.existsSync(skillMdPath)) return null;
|
|
41507
|
+
const content = fs26.readFileSync(skillMdPath, "utf-8");
|
|
41158
41508
|
const bodyMatch = content.match(/^---\s*\n[\s\S]*?\n---\s*\n([\s\S]*)/);
|
|
41159
41509
|
const body = bodyMatch ? bodyMatch[1] : content;
|
|
41160
|
-
const skillDir =
|
|
41510
|
+
const skillDir = path26.dirname(skillMdPath);
|
|
41161
41511
|
const normalizedDir = process.platform === "win32" ? skillDir.replace(/\\/g, "/") : skillDir;
|
|
41162
41512
|
let finalContent = `Base directory for this skill: ${normalizedDir}
|
|
41163
41513
|
|
|
@@ -41431,12 +41781,12 @@ Examples:
|
|
|
41431
41781
|
// src/tools/msg-husband.ts
|
|
41432
41782
|
init_registry();
|
|
41433
41783
|
init_live();
|
|
41434
|
-
import
|
|
41435
|
-
import
|
|
41784
|
+
import fs27 from "node:fs";
|
|
41785
|
+
import path27 from "node:path";
|
|
41436
41786
|
function getHusbandFeishuId(workspace) {
|
|
41437
|
-
const contactsPath =
|
|
41787
|
+
const contactsPath = path27.join(workspace, "prompts", "contacts.md");
|
|
41438
41788
|
try {
|
|
41439
|
-
const text =
|
|
41789
|
+
const text = fs27.readFileSync(contactsPath, "utf-8");
|
|
41440
41790
|
const m2 = text.match(/\|\s*翀哥\s*\|\s*(ou_[a-f0-9]+)\s*\|/);
|
|
41441
41791
|
return m2 ? m2[1] : null;
|
|
41442
41792
|
} catch {
|
|
@@ -41578,8 +41928,8 @@ Examples:
|
|
|
41578
41928
|
if (!to && !resolvedChannelId) {
|
|
41579
41929
|
return { content: "to \u548C channel_id \u4E0D\u80FD\u540C\u65F6\u4E3A\u7A7A\uFF0C\u4E14\u6CA1\u6709\u53EF\u7528\u7684\u6765\u6E90\u9891\u9053", isError: true };
|
|
41580
41930
|
}
|
|
41581
|
-
const
|
|
41582
|
-
if (!
|
|
41931
|
+
const fs55 = await import("node:fs");
|
|
41932
|
+
if (!fs55.existsSync(filePath)) {
|
|
41583
41933
|
return { content: `\u53D1\u9001\u5931\u8D25: \u6587\u4EF6\u4E0D\u5B58\u5728 ${filePath}`, isError: true };
|
|
41584
41934
|
}
|
|
41585
41935
|
const toIds = to ? to.split(",").map((s2) => s2.trim()).filter(Boolean) : [];
|
|
@@ -41607,7 +41957,7 @@ Examples:
|
|
|
41607
41957
|
md: "text/markdown"
|
|
41608
41958
|
};
|
|
41609
41959
|
const mimeType = mimeTypeMap[ext] || "application/octet-stream";
|
|
41610
|
-
const stat8 =
|
|
41960
|
+
const stat8 = fs55.statSync(filePath);
|
|
41611
41961
|
const sizeMB = stat8.size / 1024 / 1024;
|
|
41612
41962
|
if (sizeMB > 25) {
|
|
41613
41963
|
return { content: `\u53D1\u9001\u5931\u8D25: \u6587\u4EF6 ${sizeMB.toFixed(1)}MB \u8D85\u8FC7 Discord 25MB \u9650\u5236`, isError: true };
|
|
@@ -41636,8 +41986,8 @@ Examples:
|
|
|
41636
41986
|
// src/tools/my-eyes.ts
|
|
41637
41987
|
init_live();
|
|
41638
41988
|
init_registry();
|
|
41639
|
-
import * as
|
|
41640
|
-
import * as
|
|
41989
|
+
import * as fs28 from "node:fs";
|
|
41990
|
+
import * as path28 from "node:path";
|
|
41641
41991
|
var MIME_MAP = {
|
|
41642
41992
|
".jpg": "jpeg",
|
|
41643
41993
|
".jpeg": "jpeg",
|
|
@@ -41647,9 +41997,9 @@ var MIME_MAP = {
|
|
|
41647
41997
|
".bmp": "bmp"
|
|
41648
41998
|
};
|
|
41649
41999
|
function resolveLatestImage(specifiedPath, mediaDir) {
|
|
41650
|
-
if (specifiedPath &&
|
|
41651
|
-
if (!
|
|
41652
|
-
const files =
|
|
42000
|
+
if (specifiedPath && fs28.existsSync(specifiedPath)) return specifiedPath;
|
|
42001
|
+
if (!fs28.existsSync(mediaDir)) return null;
|
|
42002
|
+
const files = fs28.readdirSync(mediaDir).filter((f2) => /\.(jpg|jpeg|png|webp|gif|bmp)$/i.test(f2)).map((f2) => ({ name: f2, p: path28.join(mediaDir, f2), mtime: fs28.statSync(path28.join(mediaDir, f2)).mtimeMs })).sort((a, b2) => b2.mtime - a.mtime);
|
|
41653
42003
|
return files[0]?.p || null;
|
|
41654
42004
|
}
|
|
41655
42005
|
registry.register({
|
|
@@ -41673,15 +42023,15 @@ registry.register({
|
|
|
41673
42023
|
if (!provider?.streamChat) {
|
|
41674
42024
|
return { content: "Error: provider \u4E0D\u53EF\u7528\u3002", isError: true };
|
|
41675
42025
|
}
|
|
41676
|
-
const mediaDir =
|
|
42026
|
+
const mediaDir = path28.join(ctx.stateDir, "media", "inbound");
|
|
41677
42027
|
const imagePath = resolveLatestImage(args2.image_path, mediaDir);
|
|
41678
42028
|
if (!imagePath) {
|
|
41679
42029
|
return { content: "Error: no image found. Provide image_path or ensure media/inbound has images.", isError: true };
|
|
41680
42030
|
}
|
|
41681
42031
|
const rawPrompt = args2.prompt?.trim() || "\u63CF\u8FF0\u8FD9\u5F20\u56FE\u7247\u7684\u5185\u5BB9";
|
|
41682
|
-
const ext =
|
|
42032
|
+
const ext = path28.extname(imagePath).toLowerCase();
|
|
41683
42033
|
const mime = MIME_MAP[ext] || "jpeg";
|
|
41684
|
-
const imgB64 =
|
|
42034
|
+
const imgB64 = fs28.readFileSync(imagePath).toString("base64");
|
|
41685
42035
|
const userMsg = {
|
|
41686
42036
|
role: "user",
|
|
41687
42037
|
content: [
|
|
@@ -41718,14 +42068,14 @@ init_live();
|
|
|
41718
42068
|
init_registry();
|
|
41719
42069
|
import { execFile } from "node:child_process";
|
|
41720
42070
|
import { promisify } from "node:util";
|
|
41721
|
-
import * as
|
|
41722
|
-
import * as
|
|
42071
|
+
import * as fs29 from "node:fs";
|
|
42072
|
+
import * as path29 from "node:path";
|
|
41723
42073
|
import * as os3 from "node:os";
|
|
41724
42074
|
var execFileAsync = promisify(execFile);
|
|
41725
|
-
var VOICE_DIR =
|
|
42075
|
+
var VOICE_DIR = path29.join(os3.tmpdir(), "engine-voice");
|
|
41726
42076
|
async function ttsCosyvoice(text, apiKey, model, voice, workspaceId) {
|
|
41727
|
-
|
|
41728
|
-
const output =
|
|
42077
|
+
fs29.mkdirSync(VOICE_DIR, { recursive: true });
|
|
42078
|
+
const output = path29.join(VOICE_DIR, `tts_${Date.now()}.wav`);
|
|
41729
42079
|
const script = `
|
|
41730
42080
|
import sys, json, wave, time, threading
|
|
41731
42081
|
import dashscope
|
|
@@ -41779,7 +42129,7 @@ print(f"OK: {len(pcm)} bytes")
|
|
|
41779
42129
|
`;
|
|
41780
42130
|
const configJson = JSON.stringify({ apiKey, model, voice, workspaceId });
|
|
41781
42131
|
await execFileAsync("python3", ["-c", script, configJson, text, output], { timeout: 3e4 });
|
|
41782
|
-
if (!
|
|
42132
|
+
if (!fs29.existsSync(output) || fs29.statSync(output).size < 100) {
|
|
41783
42133
|
throw new Error("CosyVoice produced empty output");
|
|
41784
42134
|
}
|
|
41785
42135
|
return output;
|
|
@@ -41789,8 +42139,8 @@ var GPTSOVITS_REF_WAV = "/home/chong/voice/ref/shanshan_ref_v2.wav";
|
|
|
41789
42139
|
var GPTSOVITS_REF_TEXT = "\u6625\u7720\u4E0D\u89C9\u6653\uFF0C\u5904\u5904\u95FB\u557C\u9E1F\uFF0C\u591C\u6765\u98CE\u96E8\u58F0\uFF0C\u82B1\u843D\u77E5\u591A\u5C11";
|
|
41790
42140
|
var GPTSOVITS_REF_LANG = "zh";
|
|
41791
42141
|
async function ttsGptsovits(text) {
|
|
41792
|
-
|
|
41793
|
-
const output =
|
|
42142
|
+
fs29.mkdirSync(VOICE_DIR, { recursive: true });
|
|
42143
|
+
const output = path29.join(VOICE_DIR, `tts_${Date.now()}.wav`);
|
|
41794
42144
|
const params = new URLSearchParams({
|
|
41795
42145
|
text,
|
|
41796
42146
|
text_language: "zh",
|
|
@@ -41801,13 +42151,13 @@ async function ttsGptsovits(text) {
|
|
|
41801
42151
|
const res = await fetch(`${GPTSOVITS_API}/?${params}`);
|
|
41802
42152
|
if (!res.ok) throw new Error(`GPT-SoVITS API ${res.status}`);
|
|
41803
42153
|
const buf = Buffer.from(await res.arrayBuffer());
|
|
41804
|
-
|
|
42154
|
+
fs29.writeFileSync(output, buf);
|
|
41805
42155
|
return output;
|
|
41806
42156
|
}
|
|
41807
42157
|
var EDGE_VOICE = "zh-CN-XiaoxiaoNeural";
|
|
41808
42158
|
async function ttsEdge(text) {
|
|
41809
|
-
|
|
41810
|
-
const output =
|
|
42159
|
+
fs29.mkdirSync(VOICE_DIR, { recursive: true });
|
|
42160
|
+
const output = path29.join(VOICE_DIR, `tts_${Date.now()}.mp3`);
|
|
41811
42161
|
const script = `
|
|
41812
42162
|
import asyncio, edge_tts, sys
|
|
41813
42163
|
async def main():
|
|
@@ -41833,7 +42183,7 @@ async function compressWav(wavPath) {
|
|
|
41833
42183
|
"+faststart",
|
|
41834
42184
|
m4aPath
|
|
41835
42185
|
], { timeout: 3e4 });
|
|
41836
|
-
|
|
42186
|
+
fs29.unlinkSync(wavPath);
|
|
41837
42187
|
return m4aPath;
|
|
41838
42188
|
} catch {
|
|
41839
42189
|
return wavPath;
|
|
@@ -41900,10 +42250,10 @@ registry.register({
|
|
|
41900
42250
|
} catch (e) {
|
|
41901
42251
|
return { content: `TTS failed: ${e.message}`, isError: true };
|
|
41902
42252
|
}
|
|
41903
|
-
const ext =
|
|
42253
|
+
const ext = path29.extname(audioPath).toLowerCase();
|
|
41904
42254
|
const mimeMap = { ".mp3": "audio/mpeg", ".wav": "audio/wav", ".m4a": "audio/mp4", ".ogg": "audio/ogg" };
|
|
41905
42255
|
const mimeType = mimeMap[ext] || "audio/mpeg";
|
|
41906
|
-
const sizeKB =
|
|
42256
|
+
const sizeKB = fs29.statSync(audioPath).size / 1024;
|
|
41907
42257
|
const resolvedChannel = args2.channel || ctx.channel || "feishu";
|
|
41908
42258
|
const target = ctx.channelTarget || ctx.from;
|
|
41909
42259
|
try {
|
|
@@ -41913,7 +42263,7 @@ registry.register({
|
|
|
41913
42263
|
filename: `voice_${Date.now()}${ext}`
|
|
41914
42264
|
});
|
|
41915
42265
|
try {
|
|
41916
|
-
|
|
42266
|
+
fs29.unlinkSync(audioPath);
|
|
41917
42267
|
} catch {
|
|
41918
42268
|
}
|
|
41919
42269
|
return { content: `Voice sent! (${actualEngine}, ${sizeKB.toFixed(0)}KB, ${resolvedChannel})` };
|
|
@@ -41930,8 +42280,8 @@ registry.register({
|
|
|
41930
42280
|
// src/tools/my-selfie.ts
|
|
41931
42281
|
init_live();
|
|
41932
42282
|
init_registry();
|
|
41933
|
-
import * as
|
|
41934
|
-
import * as
|
|
42283
|
+
import * as fs30 from "node:fs";
|
|
42284
|
+
import * as path30 from "node:path";
|
|
41935
42285
|
var FAL_KEY = "3b848fc6-bee5-46e5-8db7-ae81ac16dc28:2f1f15cf394db2d32c9bb9a4f23f3bee";
|
|
41936
42286
|
var FAL_ENDPOINT = "https://fal.run/xai/grok-imagine-image/edit";
|
|
41937
42287
|
var DEFAULT_RESOLUTION = "1k";
|
|
@@ -42047,11 +42397,11 @@ registry.register({
|
|
|
42047
42397
|
const REFERENCES = getReferences(ctx);
|
|
42048
42398
|
const refName = args2.reference || "default";
|
|
42049
42399
|
const refEntry = REFERENCES.find((r) => r.name === refName) || REFERENCES[0];
|
|
42050
|
-
const refPath =
|
|
42051
|
-
if (!
|
|
42400
|
+
const refPath = path30.join(ctx.workspace, refEntry.p);
|
|
42401
|
+
if (!fs30.existsSync(refPath)) {
|
|
42052
42402
|
return { content: `Error: reference image not found at ${refPath}`, isError: true };
|
|
42053
42403
|
}
|
|
42054
|
-
const refB64 =
|
|
42404
|
+
const refB64 = fs30.readFileSync(refPath).toString("base64");
|
|
42055
42405
|
const resolution = args2.resolution || DEFAULT_RESOLUTION;
|
|
42056
42406
|
let imageBuffer;
|
|
42057
42407
|
try {
|
|
@@ -42066,11 +42416,11 @@ registry.register({
|
|
|
42066
42416
|
} catch (err) {
|
|
42067
42417
|
return { content: `Selfie generation failed: ${err.message}`, isError: true };
|
|
42068
42418
|
}
|
|
42069
|
-
const imagesDir =
|
|
42070
|
-
if (!
|
|
42419
|
+
const imagesDir = path30.join(ctx.workspace, "images");
|
|
42420
|
+
if (!fs30.existsSync(imagesDir)) fs30.mkdirSync(imagesDir, { recursive: true });
|
|
42071
42421
|
const filename = `selfie_${Date.now()}.jpg`;
|
|
42072
|
-
const outputPath =
|
|
42073
|
-
|
|
42422
|
+
const outputPath = path30.join(imagesDir, filename);
|
|
42423
|
+
fs30.writeFileSync(outputPath, imageBuffer);
|
|
42074
42424
|
const mgr = ctx.channelManager;
|
|
42075
42425
|
if (mgr) {
|
|
42076
42426
|
const resolvedChannel = ctx.channel || "feishu";
|
|
@@ -42081,11 +42431,11 @@ registry.register({
|
|
|
42081
42431
|
mimeType: "image/jpeg"
|
|
42082
42432
|
});
|
|
42083
42433
|
} catch (err) {
|
|
42084
|
-
return { content: `Selfie generated but send failed: ${err.message}. Image: ${
|
|
42434
|
+
return { content: `Selfie generated but send failed: ${err.message}. Image: ${path30.resolve(outputPath)}`, isError: false };
|
|
42085
42435
|
}
|
|
42086
42436
|
return { content: `Selfie sent! Mode: ${mode}, Provider: ${getProvider(ctx)}, Ref: ${refEntry.name}` };
|
|
42087
42437
|
}
|
|
42088
|
-
return { content: `Selfie generated! Mode: ${mode}, Ref: ${refEntry.name}. Image: ${
|
|
42438
|
+
return { content: `Selfie generated! Mode: ${mode}, Ref: ${refEntry.name}. Image: ${path30.resolve(outputPath)}` };
|
|
42089
42439
|
},
|
|
42090
42440
|
isConcurrencySafe: () => false,
|
|
42091
42441
|
interruptBehavior: () => "block",
|
|
@@ -42225,9 +42575,9 @@ registry.register({
|
|
|
42225
42575
|
// src/tools/service.ts
|
|
42226
42576
|
init_registry();
|
|
42227
42577
|
init_live();
|
|
42228
|
-
import { exec as
|
|
42578
|
+
import { exec as exec4, spawn as spawn7 } from "node:child_process";
|
|
42229
42579
|
import { promisify as promisify2 } from "node:util";
|
|
42230
|
-
var execAsync = promisify2(
|
|
42580
|
+
var execAsync = promisify2(exec4);
|
|
42231
42581
|
function getServices() {
|
|
42232
42582
|
return liveConfig.get("services") || {};
|
|
42233
42583
|
}
|
|
@@ -42244,7 +42594,7 @@ function spawnDetached(cmd) {
|
|
|
42244
42594
|
const shell = isWin ? "cmd.exe" : "/bin/sh";
|
|
42245
42595
|
const logFile = `D:/xiaoke/logs/service-${(/* @__PURE__ */ new Date()).toISOString().slice(0, 10).replace(/-/g, "")}.log`;
|
|
42246
42596
|
const wrappedCmd = isWin ? `/c "${cmd.replace(/"/g, '\\"')} > "${logFile}" 2>&1"` : `-c "${cmd} > '${logFile}' 2>&1"`;
|
|
42247
|
-
const child =
|
|
42597
|
+
const child = spawn7(shell, isWin ? [wrappedCmd] : ["-c", `${cmd} > '${logFile}' 2>&1`], {
|
|
42248
42598
|
detached: true,
|
|
42249
42599
|
stdio: "ignore",
|
|
42250
42600
|
windowsHide: true,
|
|
@@ -42551,16 +42901,16 @@ var EXIT_PLAN_MODE_TOOL_NAME = "ExitPlanMode";
|
|
|
42551
42901
|
init_planModeState();
|
|
42552
42902
|
|
|
42553
42903
|
// src/utils/plans.ts
|
|
42554
|
-
import * as
|
|
42555
|
-
import * as
|
|
42904
|
+
import * as fs32 from "node:fs";
|
|
42905
|
+
import * as path32 from "node:path";
|
|
42556
42906
|
import * as crypto4 from "node:crypto";
|
|
42557
42907
|
var MAX_SLUG_RETRIES = 10;
|
|
42558
42908
|
function generateSlug() {
|
|
42559
42909
|
return crypto4.randomBytes(4).toString("hex");
|
|
42560
42910
|
}
|
|
42561
42911
|
function getPlansDirectory(stateDir) {
|
|
42562
|
-
const plansDir =
|
|
42563
|
-
|
|
42912
|
+
const plansDir = path32.join(stateDir, "plans");
|
|
42913
|
+
fs32.mkdirSync(plansDir, { recursive: true });
|
|
42564
42914
|
return plansDir;
|
|
42565
42915
|
}
|
|
42566
42916
|
var planSlugCache = /* @__PURE__ */ new Map();
|
|
@@ -42570,8 +42920,8 @@ function getPlanSlug(sessionId, stateDir) {
|
|
|
42570
42920
|
const plansDir = getPlansDirectory(stateDir);
|
|
42571
42921
|
for (let i = 0; i < MAX_SLUG_RETRIES; i++) {
|
|
42572
42922
|
slug = generateSlug();
|
|
42573
|
-
const filePath =
|
|
42574
|
-
if (!
|
|
42923
|
+
const filePath = path32.join(plansDir, `${slug}.md`);
|
|
42924
|
+
if (!fs32.existsSync(filePath)) {
|
|
42575
42925
|
break;
|
|
42576
42926
|
}
|
|
42577
42927
|
}
|
|
@@ -42582,21 +42932,21 @@ function getPlanSlug(sessionId, stateDir) {
|
|
|
42582
42932
|
function getPlanFilePath(sessionId, stateDir, agentId) {
|
|
42583
42933
|
const slug = getPlanSlug(sessionId, stateDir);
|
|
42584
42934
|
if (!agentId) {
|
|
42585
|
-
return
|
|
42935
|
+
return path32.join(getPlansDirectory(stateDir), `${slug}.md`);
|
|
42586
42936
|
}
|
|
42587
|
-
return
|
|
42937
|
+
return path32.join(getPlansDirectory(stateDir), `${slug}-agent-${agentId}.md`);
|
|
42588
42938
|
}
|
|
42589
42939
|
function getPlan(sessionId, stateDir, agentId) {
|
|
42590
42940
|
const filePath = getPlanFilePath(sessionId, stateDir, agentId);
|
|
42591
42941
|
try {
|
|
42592
|
-
return
|
|
42942
|
+
return fs32.readFileSync(filePath, "utf-8");
|
|
42593
42943
|
} catch {
|
|
42594
42944
|
return null;
|
|
42595
42945
|
}
|
|
42596
42946
|
}
|
|
42597
42947
|
function writePlan(sessionId, stateDir, content, agentId) {
|
|
42598
42948
|
const filePath = getPlanFilePath(sessionId, stateDir, agentId);
|
|
42599
|
-
|
|
42949
|
+
fs32.writeFileSync(filePath, content, "utf-8");
|
|
42600
42950
|
return filePath;
|
|
42601
42951
|
}
|
|
42602
42952
|
|
|
@@ -43796,11 +44146,11 @@ async function startEngine(config2, opts) {
|
|
|
43796
44146
|
process.env.ENGINE_MEDIA_DIR = config2.mediaDir;
|
|
43797
44147
|
process.env.ENGINE7_WORKSPACE = config2.workspace;
|
|
43798
44148
|
process.env.OPENCLAW_WORKSPACE = config2.workspace;
|
|
43799
|
-
|
|
43800
|
-
|
|
43801
|
-
|
|
43802
|
-
|
|
43803
|
-
|
|
44149
|
+
fs54.mkdirSync(path55.join(config2.stateDir, "agents", "main", "memory"), { recursive: true });
|
|
44150
|
+
fs54.mkdirSync(path55.join(config2.stateDir, "agents", "main", "sessions"), { recursive: true });
|
|
44151
|
+
fs54.mkdirSync(path55.join(config2.stateDir, "logs"), { recursive: true });
|
|
44152
|
+
fs54.mkdirSync(config2.workspace, { recursive: true });
|
|
44153
|
+
fs54.mkdirSync(config2.mediaDir, { recursive: true });
|
|
43804
44154
|
try {
|
|
43805
44155
|
process.chdir(config2.workspace);
|
|
43806
44156
|
} catch (e) {
|
|
@@ -43908,7 +44258,7 @@ async function startEngine(config2, opts) {
|
|
|
43908
44258
|
const { initSessionMemory: initSessionMemory2 } = await Promise.resolve().then(() => (init_sessionMemory(), sessionMemory_exports));
|
|
43909
44259
|
initSessionMemory2({
|
|
43910
44260
|
workspace: config2.workspace,
|
|
43911
|
-
stateDir:
|
|
44261
|
+
stateDir: path55.join(config2.stateDir, "session-memory"),
|
|
43912
44262
|
provider,
|
|
43913
44263
|
model: config2.provider.modelId || config2.model || "deepseek-v4-flash",
|
|
43914
44264
|
features: config2.profile.features
|
|
@@ -43938,9 +44288,9 @@ async function startEngine(config2, opts) {
|
|
|
43938
44288
|
if (config2.hooks) {
|
|
43939
44289
|
loadHooksFromConfig({ hooks: config2.hooks });
|
|
43940
44290
|
}
|
|
43941
|
-
const hooksPath =
|
|
44291
|
+
const hooksPath = path55.join(config2.workspace, ".hooks.json");
|
|
43942
44292
|
loadHooksFromFile(hooksPath);
|
|
43943
|
-
const settingsHooksPath =
|
|
44293
|
+
const settingsHooksPath = path55.join(config2.stateDir, "settings.json");
|
|
43944
44294
|
loadHooksFromFile(settingsHooksPath);
|
|
43945
44295
|
console.log(`[hooks] Loaded hooks configuration`);
|
|
43946
44296
|
registerCallbackHook("PreCompact", {
|
|
@@ -43954,18 +44304,18 @@ async function startEngine(config2, opts) {
|
|
|
43954
44304
|
const bjTime = new Date(now.getTime() + (bjOffset + now.getTimezoneOffset()) * 6e4);
|
|
43955
44305
|
const dateStr = `${bjTime.getFullYear()}-${String(bjTime.getMonth() + 1).padStart(2, "0")}-${String(bjTime.getDate()).padStart(2, "0")}`;
|
|
43956
44306
|
const timeStr = `${String(bjTime.getHours()).padStart(2, "0")}:${String(bjTime.getMinutes()).padStart(2, "0")}`;
|
|
43957
|
-
const dailyDir =
|
|
43958
|
-
const dailyPath =
|
|
44307
|
+
const dailyDir = path55.join(workspace, "memory", "daily");
|
|
44308
|
+
const dailyPath = path55.join(dailyDir, `${dateStr}.md`);
|
|
43959
44309
|
try {
|
|
43960
|
-
const
|
|
43961
|
-
if (!
|
|
43962
|
-
|
|
44310
|
+
const fs55 = await import("node:fs");
|
|
44311
|
+
if (!fs55.existsSync(dailyDir)) {
|
|
44312
|
+
fs55.mkdirSync(dailyDir, { recursive: true });
|
|
43963
44313
|
}
|
|
43964
|
-
const sessionsDir =
|
|
43965
|
-
const sessionFile =
|
|
44314
|
+
const sessionsDir = path55.join(config2.stateDir, "agents", "main", "sessions");
|
|
44315
|
+
const sessionFile = path55.join(sessionsDir, `${sessionId}.jsonl`);
|
|
43966
44316
|
const recentLines = [];
|
|
43967
|
-
if (
|
|
43968
|
-
const content =
|
|
44317
|
+
if (fs55.existsSync(sessionFile)) {
|
|
44318
|
+
const content = fs55.readFileSync(sessionFile, "utf-8");
|
|
43969
44319
|
const lines = content.trim().split("\n").filter(Boolean);
|
|
43970
44320
|
const userLines = lines.filter((l) => {
|
|
43971
44321
|
try {
|
|
@@ -43995,10 +44345,10 @@ async function startEngine(config2, opts) {
|
|
|
43995
44345
|
const entry = `${header}
|
|
43996
44346
|
${body}
|
|
43997
44347
|
`;
|
|
43998
|
-
if (
|
|
43999
|
-
|
|
44348
|
+
if (fs55.existsSync(dailyPath)) {
|
|
44349
|
+
fs55.appendFileSync(dailyPath, entry);
|
|
44000
44350
|
} else {
|
|
44001
|
-
|
|
44351
|
+
fs55.writeFileSync(dailyPath, `# ${dateStr} \u65E5\u5FD7
|
|
44002
44352
|
${entry}`);
|
|
44003
44353
|
}
|
|
44004
44354
|
console.log(`[hooks] PreCompact: saved ${recentLines.length} lines to ${dailyPath}`);
|
|
@@ -44014,16 +44364,16 @@ ${entry}`);
|
|
|
44014
44364
|
const workspace = input.cwd || input.workspace || "";
|
|
44015
44365
|
if (!workspace) return { continue: true };
|
|
44016
44366
|
try {
|
|
44017
|
-
const
|
|
44018
|
-
const bufferPath =
|
|
44019
|
-
if (
|
|
44020
|
-
const stat8 =
|
|
44367
|
+
const fs55 = await import("node:fs");
|
|
44368
|
+
const bufferPath = path55.join(workspace, "memory", "working-buffer.md");
|
|
44369
|
+
if (fs55.existsSync(bufferPath)) {
|
|
44370
|
+
const stat8 = fs55.statSync(bufferPath);
|
|
44021
44371
|
const ageMs = Date.now() - stat8.mtimeMs;
|
|
44022
44372
|
const ageMin = Math.round(ageMs / 6e4);
|
|
44023
44373
|
if (ageMin > 10) {
|
|
44024
44374
|
console.warn(`[hooks] PostCompact: \u26A0\uFE0F working-buffer.md is ${ageMin}min old (last modified ${stat8.mtime.toISOString()}) \u2014 content may be stale!`);
|
|
44025
44375
|
}
|
|
44026
|
-
const content =
|
|
44376
|
+
const content = fs55.readFileSync(bufferPath, "utf-8");
|
|
44027
44377
|
if (content.trim()) {
|
|
44028
44378
|
console.log(`[hooks] PostCompact: injecting working-buffer (${content.length} chars, ${ageMin}min old)`);
|
|
44029
44379
|
return {
|
|
@@ -44068,7 +44418,7 @@ ${content}`
|
|
|
44068
44418
|
return `${hr}h ${remMin}m`;
|
|
44069
44419
|
}
|
|
44070
44420
|
if (config2.skills?.enabled !== false) {
|
|
44071
|
-
const skillsDir = config2.skills?.path ?
|
|
44421
|
+
const skillsDir = config2.skills?.path ? path55.isAbsolute(config2.skills.path) ? config2.skills.path : path55.resolve(config2.workspace, config2.skills.path) : path55.resolve(config2.workspace, "skills");
|
|
44072
44422
|
const modelDef2 = config2.provider.models.find((m2) => m2.id === config2.model);
|
|
44073
44423
|
const contextWindowTokens = modelDef2?.contextWindow;
|
|
44074
44424
|
const skills = scanSkills(skillsDir);
|
|
@@ -44087,8 +44437,8 @@ ${content}`
|
|
|
44087
44437
|
workspace: config2.workspace
|
|
44088
44438
|
});
|
|
44089
44439
|
const systemPrompt = [systemStable, systemDynamic].join("\n\n");
|
|
44090
|
-
const promptDumpPath =
|
|
44091
|
-
|
|
44440
|
+
const promptDumpPath = path55.join(config2.workspace, ".system-prompt.txt");
|
|
44441
|
+
fs54.writeFileSync(promptDumpPath, systemPrompt);
|
|
44092
44442
|
console.log(`System prompt: ${systemStable.length} chars stable + ${systemDynamic.length} chars dynamic \u2192 ${promptDumpPath}`);
|
|
44093
44443
|
const modelDef = config2.provider.models.find((m2) => m2.id === config2.model);
|
|
44094
44444
|
const modelContextWindow = modelDef?.contextWindow;
|
|
@@ -44994,15 +45344,15 @@ ${result.changes.map((c) => `- ${c}`).join("\n")}` : `\u274C Reload failed: ${re
|
|
|
44994
45344
|
config2.features[key] = next;
|
|
44995
45345
|
if (deps.features) deps.features[key] = next;
|
|
44996
45346
|
try {
|
|
44997
|
-
const
|
|
45347
|
+
const fs55 = await import("fs");
|
|
44998
45348
|
const pathMod = await import("path");
|
|
44999
45349
|
let cfgPath = config2._configFilePath;
|
|
45000
|
-
if (!cfgPath || !
|
|
45350
|
+
if (!cfgPath || !fs55.existsSync(cfgPath)) {
|
|
45001
45351
|
const __filename = fileURLToPath(import.meta.url);
|
|
45002
45352
|
const __dirname = pathMod.dirname(__filename);
|
|
45003
45353
|
cfgPath = pathMod.resolve(__dirname, "../configs", pathMod.basename(cfgPath || "engine-config.json"));
|
|
45004
45354
|
}
|
|
45005
|
-
const cfg = JSON.parse(
|
|
45355
|
+
const cfg = JSON.parse(fs55.readFileSync(cfgPath, "utf-8"));
|
|
45006
45356
|
let featObj = null;
|
|
45007
45357
|
if (cfg.agents?.defaults?.features) {
|
|
45008
45358
|
featObj = cfg.agents.defaults.features;
|
|
@@ -45012,7 +45362,7 @@ ${result.changes.map((c) => `- ${c}`).join("\n")}` : `\u274C Reload failed: ${re
|
|
|
45012
45362
|
}
|
|
45013
45363
|
if (featObj) {
|
|
45014
45364
|
featObj[key] = next;
|
|
45015
|
-
|
|
45365
|
+
fs55.writeFileSync(cfgPath, JSON.stringify(cfg, null, 2) + "\n", "utf-8");
|
|
45016
45366
|
console.log(`[${ctx.command}] ${key} ${cur} \u2192 ${rawState} (disk persisted)`);
|
|
45017
45367
|
await ctx.reply(`\u2705 ${key}: **${cur}** \u2192 **${rawState}**`);
|
|
45018
45368
|
} else {
|
|
@@ -45138,11 +45488,11 @@ Auto-routing disabled \u2014 all messages use this model.
|
|
|
45138
45488
|
const input = (ctx.args.model || "").trim();
|
|
45139
45489
|
const configPath2 = config2._configFilePath;
|
|
45140
45490
|
let writePath = configPath2;
|
|
45141
|
-
if (configPath2 && !
|
|
45491
|
+
if (configPath2 && !fs54.existsSync(configPath2)) {
|
|
45142
45492
|
const __pFile = fileURLToPath(import.meta.url);
|
|
45143
|
-
const __pDir =
|
|
45144
|
-
const altPath =
|
|
45145
|
-
if (
|
|
45493
|
+
const __pDir = path55.dirname(__pFile);
|
|
45494
|
+
const altPath = path55.join(path55.resolve(__pDir, "../configs"), path55.basename(configPath2));
|
|
45495
|
+
if (fs54.existsSync(altPath)) {
|
|
45146
45496
|
console.warn(`[primary] Config not found at ${configPath2}, falling back to ${altPath}`);
|
|
45147
45497
|
writePath = altPath;
|
|
45148
45498
|
}
|
|
@@ -45186,14 +45536,14 @@ Use full ref like \`/primary ${candidates[0].ref}\``);
|
|
|
45186
45536
|
return;
|
|
45187
45537
|
}
|
|
45188
45538
|
try {
|
|
45189
|
-
const raw = await
|
|
45539
|
+
const raw = await fs54.promises.readFile(writePath, "utf-8");
|
|
45190
45540
|
const cfg = JSON.parse(raw);
|
|
45191
45541
|
if (!cfg.agents?.defaults?.model) {
|
|
45192
45542
|
await ctx.reply(`\u26A0\uFE0F Config structure mismatch: agents.defaults.model not found`);
|
|
45193
45543
|
return;
|
|
45194
45544
|
}
|
|
45195
45545
|
cfg.agents.defaults.model.primary = target;
|
|
45196
|
-
await
|
|
45546
|
+
await fs54.promises.writeFile(writePath, JSON.stringify(cfg, null, 2), "utf-8");
|
|
45197
45547
|
console.log(`[primary] Persisted primary=${target} to ${writePath}`);
|
|
45198
45548
|
await ctx.reply(`\u2705 Primary model set to **${target}** (${candidates[0].name})
|
|
45199
45549
|
Written to config. **Restart required** to take effect.`);
|
|
@@ -45413,7 +45763,7 @@ Use full ref like \`/vision-model ${candidates[0].ref}\``);
|
|
|
45413
45763
|
console.log(`[vision] Downloading image: ${att.filename}`);
|
|
45414
45764
|
let rawBuffer;
|
|
45415
45765
|
if (att.url.startsWith("file://")) {
|
|
45416
|
-
rawBuffer =
|
|
45766
|
+
rawBuffer = fs54.readFileSync(decodeURIComponent(att.url.slice(7)));
|
|
45417
45767
|
} else {
|
|
45418
45768
|
rawBuffer = await downloadImage2(att.url);
|
|
45419
45769
|
}
|
|
@@ -45421,8 +45771,8 @@ Use full ref like \`/vision-model ${candidates[0].ref}\``);
|
|
|
45421
45771
|
const ext = detected.split("/")[1] || "png";
|
|
45422
45772
|
const resized = await maybeResizeAndDownsampleImageBuffer2(rawBuffer, rawBuffer.length, ext);
|
|
45423
45773
|
const imageId = `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
45424
|
-
const savedPath =
|
|
45425
|
-
|
|
45774
|
+
const savedPath = path55.join(config2.mediaDir, `${imageId}.${ext}`);
|
|
45775
|
+
fs54.writeFileSync(savedPath, resized.buffer);
|
|
45426
45776
|
savedPaths.push(savedPath);
|
|
45427
45777
|
console.log(`[vision] Saved: ${savedPath} (${resized.buffer.length}B)`);
|
|
45428
45778
|
imageBlocks.push({
|
|
@@ -45448,8 +45798,8 @@ ${pathStr}` }];
|
|
|
45448
45798
|
}
|
|
45449
45799
|
const nonImageAttachments = inbound.attachments?.filter((a) => !a.contentType.startsWith("image/"));
|
|
45450
45800
|
if (nonImageAttachments && nonImageAttachments.length > 0) {
|
|
45451
|
-
const outDir =
|
|
45452
|
-
|
|
45801
|
+
const outDir = path55.join(config2.mediaDir, sessionId);
|
|
45802
|
+
fs54.mkdirSync(outDir, { recursive: true });
|
|
45453
45803
|
const resolved = [];
|
|
45454
45804
|
for (const att of nonImageAttachments) {
|
|
45455
45805
|
console.log(`[file] Downloading: ${att.filename} (${att.contentType}, ${att.size}B)`);
|
|
@@ -45457,9 +45807,9 @@ ${pathStr}` }];
|
|
|
45457
45807
|
const resp = await fetch(att.url);
|
|
45458
45808
|
if (!resp.ok) throw new Error(`HTTP ${resp.status}`);
|
|
45459
45809
|
const buffer = Buffer.from(await resp.arrayBuffer());
|
|
45460
|
-
const safeName2 =
|
|
45461
|
-
const savedPath =
|
|
45462
|
-
|
|
45810
|
+
const safeName2 = path55.basename(att.filename).replace(/[<>:"/\\|?*\x00-\x1f]/g, "_") || "attachment";
|
|
45811
|
+
const savedPath = path55.join(outDir, safeName2);
|
|
45812
|
+
fs54.writeFileSync(savedPath, buffer);
|
|
45463
45813
|
resolved.push(savedPath);
|
|
45464
45814
|
console.log(`[file] Saved: ${savedPath} (${buffer.length}B)`);
|
|
45465
45815
|
} catch (err) {
|
|
@@ -45677,6 +46027,10 @@ ${pathStr}` }];
|
|
|
45677
46027
|
console.warn("[cognifold] workspace path not found, skipping plugin registration");
|
|
45678
46028
|
}
|
|
45679
46029
|
}
|
|
46030
|
+
if (config2.everos?.enabled) {
|
|
46031
|
+
pluginManager.register(new EverosPlugin(config2.everos));
|
|
46032
|
+
console.log("[everos] Plugin registered");
|
|
46033
|
+
}
|
|
45680
46034
|
globalThis.__pluginManager = pluginManager;
|
|
45681
46035
|
if (visualEmitter && config2.visualization?.guildId) {
|
|
45682
46036
|
const vConfig = config2.visualization;
|
|
@@ -45815,7 +46169,7 @@ ${pathStr}` }];
|
|
|
45815
46169
|
console.warn("[cognifold] watcher: config.workspace \u672A\u914D\u7F6E\uFF0C\u8DF3\u8FC7 proactive \u5199\u5165");
|
|
45816
46170
|
return;
|
|
45817
46171
|
}
|
|
45818
|
-
const pFile =
|
|
46172
|
+
const pFile = path55.join(wsDir, ".cognifold-proactive.json");
|
|
45819
46173
|
const cognifoldBaseUrl = config2.cognifold?.baseUrl || "http://127.0.0.1:9001";
|
|
45820
46174
|
const cognifoldSessionId = cfSessionId;
|
|
45821
46175
|
const rawSuggestions = data.suggestions || data.actions || (data.intent_id ? [data] : []);
|
|
@@ -45863,14 +46217,14 @@ ${pathStr}` }];
|
|
|
45863
46217
|
return s2;
|
|
45864
46218
|
}));
|
|
45865
46219
|
try {
|
|
45866
|
-
|
|
46220
|
+
fs54.writeFileSync(pFile, JSON.stringify(enriched, null, 2));
|
|
45867
46221
|
console.log(`[cognifold] proactive suggestions saved (${enriched.length} total)`);
|
|
45868
46222
|
} catch (e) {
|
|
45869
46223
|
console.error(`[cognifold] failed to save proactive: ${e.message}`);
|
|
45870
46224
|
}
|
|
45871
46225
|
if (enriched.length > 0) {
|
|
45872
|
-
const promptFile =
|
|
45873
|
-
const promptText =
|
|
46226
|
+
const promptFile = path55.join(config2.workspace, "prompts", "cognifold-proactive.md");
|
|
46227
|
+
const promptText = fs54.existsSync(promptFile) ? fs54.readFileSync(promptFile, "utf-8") : "[CogniFold proactive] \u6709 " + enriched.length + " \u4E2A action \u5230\u671F\u4E86";
|
|
45874
46228
|
const actionsJson = JSON.stringify(enriched, null, 2);
|
|
45875
46229
|
const sessionId = cfSessionId;
|
|
45876
46230
|
const mainSessionId = sessions.getSessionId("scope:main");
|
|
@@ -45973,12 +46327,12 @@ async function doReloadConfig(config2, deps, provider) {
|
|
|
45973
46327
|
try {
|
|
45974
46328
|
const savedConfigPath = config2._configFilePath;
|
|
45975
46329
|
let reloadConfigPath = savedConfigPath;
|
|
45976
|
-
if (!
|
|
46330
|
+
if (!fs54.existsSync(reloadConfigPath)) {
|
|
45977
46331
|
const __filename = fileURLToPath(import.meta.url);
|
|
45978
|
-
const __dirname =
|
|
45979
|
-
const engineConfigsDir =
|
|
45980
|
-
const altPath =
|
|
45981
|
-
if (
|
|
46332
|
+
const __dirname = path55.dirname(__filename);
|
|
46333
|
+
const engineConfigsDir = path55.resolve(__dirname, "../configs");
|
|
46334
|
+
const altPath = path55.join(engineConfigsDir, path55.basename(savedConfigPath));
|
|
46335
|
+
if (fs54.existsSync(altPath)) {
|
|
45982
46336
|
console.warn(`[reload] Config not found at ${reloadConfigPath}, falling back to ${altPath} (dev mode)`);
|
|
45983
46337
|
reloadConfigPath = altPath;
|
|
45984
46338
|
}
|
|
@@ -46030,7 +46384,7 @@ async function doReloadConfig(config2, deps, provider) {
|
|
|
46030
46384
|
} catch (err) {
|
|
46031
46385
|
console.error(`[reload] Failed: ${err.message}`);
|
|
46032
46386
|
try {
|
|
46033
|
-
|
|
46387
|
+
fs54.appendFileSync(path55.join(config2.stateDir, "logs", "engine-config-watch.log"), `[${(/* @__PURE__ */ new Date()).toISOString()}] RELOAD FAILED: ${err.message}
|
|
46034
46388
|
${err.stack}
|
|
46035
46389
|
`);
|
|
46036
46390
|
} catch {
|
|
@@ -46041,36 +46395,36 @@ ${err.stack}
|
|
|
46041
46395
|
function startConfigWatcher(config2, deps, provider) {
|
|
46042
46396
|
const raw = config2._configFilePath;
|
|
46043
46397
|
let configPath2 = raw;
|
|
46044
|
-
if (!
|
|
46045
|
-
configPath2 =
|
|
46398
|
+
if (!fs54.existsSync(configPath2)) {
|
|
46399
|
+
configPath2 = path55.resolve(raw);
|
|
46046
46400
|
}
|
|
46047
|
-
if (!
|
|
46401
|
+
if (!fs54.existsSync(configPath2)) {
|
|
46048
46402
|
const __filename2 = fileURLToPath(import.meta.url);
|
|
46049
|
-
const __dirname22 =
|
|
46050
|
-
configPath2 =
|
|
46403
|
+
const __dirname22 = path55.dirname(__filename2);
|
|
46404
|
+
configPath2 = path55.resolve(__dirname22, "..", raw);
|
|
46051
46405
|
}
|
|
46052
|
-
if (!
|
|
46406
|
+
if (!fs54.existsSync(configPath2)) {
|
|
46053
46407
|
console.warn(`[config-watch] config path invalid: ${configPath2}, watcher disabled`);
|
|
46054
46408
|
try {
|
|
46055
|
-
|
|
46409
|
+
fs54.appendFileSync(path55.join(config2.stateDir, "logs", "engine-config-watch.log"), `[${(/* @__PURE__ */ new Date()).toISOString()}] DISABLED: configPath=${configPath2}
|
|
46056
46410
|
`);
|
|
46057
46411
|
} catch {
|
|
46058
46412
|
}
|
|
46059
46413
|
return null;
|
|
46060
46414
|
}
|
|
46061
46415
|
let debounceTimer = null;
|
|
46062
|
-
const watcher =
|
|
46416
|
+
const watcher = fs54.watch(configPath2, { persistent: true }, (eventType) => {
|
|
46063
46417
|
if (debounceTimer) clearTimeout(debounceTimer);
|
|
46064
46418
|
debounceTimer = setTimeout(async () => {
|
|
46065
46419
|
console.log(`[config-watch] file changed (${eventType}), reloading...`);
|
|
46066
46420
|
try {
|
|
46067
|
-
|
|
46421
|
+
fs54.appendFileSync(path55.join(config2.stateDir, "logs", "engine-config-watch.log"), `[${(/* @__PURE__ */ new Date()).toISOString()}] CHANGE eventType=${eventType}, calling doReloadConfig
|
|
46068
46422
|
`);
|
|
46069
46423
|
} catch {
|
|
46070
46424
|
}
|
|
46071
46425
|
const result = await doReloadConfig(config2, deps, provider);
|
|
46072
46426
|
try {
|
|
46073
|
-
|
|
46427
|
+
fs54.appendFileSync(path55.join(config2.stateDir, "logs", "engine-config-watch.log"), `[${(/* @__PURE__ */ new Date()).toISOString()}] RELOAD DONE: ok=${result.ok} changes=${result.changes.join(",")}
|
|
46074
46428
|
`);
|
|
46075
46429
|
} catch {
|
|
46076
46430
|
}
|
|
@@ -46079,14 +46433,14 @@ function startConfigWatcher(config2, deps, provider) {
|
|
|
46079
46433
|
watcher.on("error", (err) => {
|
|
46080
46434
|
console.error(`[config-watch] error: ${err.message}`);
|
|
46081
46435
|
try {
|
|
46082
|
-
|
|
46436
|
+
fs54.appendFileSync(path55.join(config2.stateDir, "logs", "engine-config-watch.log"), `[${(/* @__PURE__ */ new Date()).toISOString()}] ERROR: ${err.message}
|
|
46083
46437
|
`);
|
|
46084
46438
|
} catch {
|
|
46085
46439
|
}
|
|
46086
46440
|
});
|
|
46087
46441
|
console.log(`[config-watch] watching ${configPath2}`);
|
|
46088
46442
|
try {
|
|
46089
|
-
|
|
46443
|
+
fs54.appendFileSync(path55.join(config2.stateDir, "logs", "engine-config-watch.log"), `[${(/* @__PURE__ */ new Date()).toISOString()}] STARTED watching=${configPath2}
|
|
46090
46444
|
`);
|
|
46091
46445
|
} catch {
|
|
46092
46446
|
}
|