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/engine-startup.mjs
CHANGED
|
@@ -2124,9 +2124,9 @@ function isAutoMemPath(absolutePath, workspace) {
|
|
|
2124
2124
|
return normalizedPath.startsWith(getAutoMemPath(workspace));
|
|
2125
2125
|
}
|
|
2126
2126
|
async function ensureMemoryDirExists(memoryDir) {
|
|
2127
|
-
const
|
|
2127
|
+
const fs55 = await import("node:fs");
|
|
2128
2128
|
try {
|
|
2129
|
-
await
|
|
2129
|
+
await fs55.promises.mkdir(memoryDir, { recursive: true });
|
|
2130
2130
|
} catch (e) {
|
|
2131
2131
|
const code = e?.code;
|
|
2132
2132
|
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 = args.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 = args.path ? resolvePath(args.path, ctx.workspace) : ctx.workspace;
|
|
7324
7324
|
const pattern = args.pattern;
|
|
7325
7325
|
const limit = args.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(args, searchPath, signal) {
|
|
7356
7356
|
return new Promise((resolve12) => {
|
|
7357
7357
|
const fullArgs = [...args, 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 (args) => {
|
|
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 (args.task_id) {
|
|
11362
|
-
const file =
|
|
11363
|
-
if (!
|
|
11362
|
+
const file = path56.join(resultsDir, `${args.task_id}.json`);
|
|
11363
|
+
if (!fs55.existsSync(file)) {
|
|
11364
11364
|
return { content: `\u4EFB\u52A1 ${args.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 (args, _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 = args.command.trim();
|
|
11496
11496
|
const timeout = args.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
|
});
|
|
@@ -11771,37 +11771,37 @@ var init_memory_host_events = __esm({
|
|
|
11771
11771
|
});
|
|
11772
11772
|
|
|
11773
11773
|
// src/memory/shims/security-runtime.ts
|
|
11774
|
-
import
|
|
11775
|
-
import
|
|
11774
|
+
import path41 from "node:path";
|
|
11775
|
+
import fs40 from "node:fs";
|
|
11776
11776
|
function privateFileStore(rootDir) {
|
|
11777
11777
|
return {
|
|
11778
11778
|
read: (relPath) => {
|
|
11779
|
-
const full =
|
|
11779
|
+
const full = path41.join(rootDir, relPath);
|
|
11780
11780
|
try {
|
|
11781
|
-
return
|
|
11781
|
+
return fs40.readFileSync(full, "utf-8");
|
|
11782
11782
|
} catch {
|
|
11783
11783
|
return null;
|
|
11784
11784
|
}
|
|
11785
11785
|
},
|
|
11786
11786
|
write: (relPath, content) => {
|
|
11787
|
-
const full =
|
|
11788
|
-
|
|
11789
|
-
|
|
11787
|
+
const full = path41.join(rootDir, relPath);
|
|
11788
|
+
fs40.mkdirSync(path41.dirname(full), { recursive: true });
|
|
11789
|
+
fs40.writeFileSync(full, content, "utf-8");
|
|
11790
11790
|
},
|
|
11791
11791
|
readJsonIfExists: (relPath) => {
|
|
11792
|
-
const full =
|
|
11792
|
+
const full = path41.join(rootDir, relPath);
|
|
11793
11793
|
try {
|
|
11794
|
-
const raw =
|
|
11794
|
+
const raw = fs40.readFileSync(full, "utf-8");
|
|
11795
11795
|
return JSON.parse(raw);
|
|
11796
11796
|
} catch {
|
|
11797
11797
|
return null;
|
|
11798
11798
|
}
|
|
11799
11799
|
},
|
|
11800
11800
|
writeJson: (relPath, data, opts) => {
|
|
11801
|
-
const full =
|
|
11802
|
-
|
|
11801
|
+
const full = path41.join(rootDir, relPath);
|
|
11802
|
+
fs40.mkdirSync(path41.dirname(full), { recursive: true });
|
|
11803
11803
|
const content = JSON.stringify(data, null, 2) + (opts?.trailingNewline ? "\n" : "");
|
|
11804
|
-
|
|
11804
|
+
fs40.writeFileSync(full, content, "utf-8");
|
|
11805
11805
|
}
|
|
11806
11806
|
};
|
|
11807
11807
|
}
|
|
@@ -11855,8 +11855,8 @@ var init_memory_budget = __esm({
|
|
|
11855
11855
|
|
|
11856
11856
|
// src/memory/tools/short-term-promotion.ts
|
|
11857
11857
|
import { createHash as createHash2 } from "node:crypto";
|
|
11858
|
-
import
|
|
11859
|
-
import
|
|
11858
|
+
import fs41 from "node:fs/promises";
|
|
11859
|
+
import path42 from "node:path";
|
|
11860
11860
|
function clampScore(value) {
|
|
11861
11861
|
if (!Number.isFinite(value)) {
|
|
11862
11862
|
return 0;
|
|
@@ -12074,10 +12074,10 @@ function normalizeStore(raw, nowIso2) {
|
|
|
12074
12074
|
};
|
|
12075
12075
|
}
|
|
12076
12076
|
function resolveLockPath(workspaceDir) {
|
|
12077
|
-
return
|
|
12077
|
+
return path42.join(workspaceDir, SHORT_TERM_LOCK_RELATIVE_PATH);
|
|
12078
12078
|
}
|
|
12079
12079
|
function resolveShortTermArtifactsDir(workspaceDir) {
|
|
12080
|
-
return
|
|
12080
|
+
return path42.dirname(resolveLockPath(workspaceDir));
|
|
12081
12081
|
}
|
|
12082
12082
|
async function ensureShortTermArtifactsDir(workspaceDir) {
|
|
12083
12083
|
const artifactsDir = resolveShortTermArtifactsDir(workspaceDir);
|
|
@@ -12086,7 +12086,7 @@ async function ensureShortTermArtifactsDir(workspaceDir) {
|
|
|
12086
12086
|
await existing;
|
|
12087
12087
|
return;
|
|
12088
12088
|
}
|
|
12089
|
-
const ensuring =
|
|
12089
|
+
const ensuring = fs41.mkdir(artifactsDir, { recursive: true }).then(() => void 0).catch((err) => {
|
|
12090
12090
|
ensuredShortTermDirs.delete(artifactsDir);
|
|
12091
12091
|
throw err;
|
|
12092
12092
|
});
|
|
@@ -12117,7 +12117,7 @@ function isProcessLikelyAlive(pid) {
|
|
|
12117
12117
|
}
|
|
12118
12118
|
}
|
|
12119
12119
|
async function canStealStaleLock(lockPath2) {
|
|
12120
|
-
const ownerPid = await
|
|
12120
|
+
const ownerPid = await fs41.readFile(lockPath2, "utf-8").then((raw) => parseLockOwnerPid(raw)).catch(() => null);
|
|
12121
12121
|
if (ownerPid === null) {
|
|
12122
12122
|
return true;
|
|
12123
12123
|
}
|
|
@@ -12153,23 +12153,23 @@ async function withShortTermLock(workspaceDir, task) {
|
|
|
12153
12153
|
const startedAt = Date.now();
|
|
12154
12154
|
while (true) {
|
|
12155
12155
|
try {
|
|
12156
|
-
const lockHandle = await
|
|
12156
|
+
const lockHandle = await fs41.open(lockPath2, "wx");
|
|
12157
12157
|
await lockHandle.writeFile(`${process.pid}:${Date.now()}
|
|
12158
12158
|
`, "utf-8").catch(() => void 0);
|
|
12159
12159
|
try {
|
|
12160
12160
|
return await task();
|
|
12161
12161
|
} finally {
|
|
12162
12162
|
await lockHandle.close().catch(() => void 0);
|
|
12163
|
-
await
|
|
12163
|
+
await fs41.unlink(lockPath2).catch(() => void 0);
|
|
12164
12164
|
}
|
|
12165
12165
|
} catch (err) {
|
|
12166
12166
|
if (err?.code !== "EEXIST") {
|
|
12167
12167
|
throw err;
|
|
12168
12168
|
}
|
|
12169
|
-
const ageMs = await
|
|
12169
|
+
const ageMs = await fs41.stat(lockPath2).then((stats2) => Date.now() - stats2.mtimeMs).catch(() => 0);
|
|
12170
12170
|
if (ageMs > SHORT_TERM_LOCK_STALE_MS) {
|
|
12171
12171
|
if (await canStealStaleLock(lockPath2)) {
|
|
12172
|
-
await
|
|
12172
|
+
await fs41.unlink(lockPath2).catch(() => void 0);
|
|
12173
12173
|
continue;
|
|
12174
12174
|
}
|
|
12175
12175
|
}
|
|
@@ -12320,9 +12320,9 @@ var init_short_term_promotion = __esm({
|
|
|
12320
12320
|
DAY_MS = 24 * 60 * 60 * 1e3;
|
|
12321
12321
|
MAX_QUERY_HASHES = 32;
|
|
12322
12322
|
MAX_RECALL_DAYS = 16;
|
|
12323
|
-
SHORT_TERM_STORE_RELATIVE_PATH =
|
|
12324
|
-
SHORT_TERM_PHASE_SIGNAL_RELATIVE_PATH =
|
|
12325
|
-
SHORT_TERM_LOCK_RELATIVE_PATH =
|
|
12323
|
+
SHORT_TERM_STORE_RELATIVE_PATH = path42.join("memory", ".dreams", "short-term-recall.json");
|
|
12324
|
+
SHORT_TERM_PHASE_SIGNAL_RELATIVE_PATH = path42.join("memory", ".dreams", "phase-signals.json");
|
|
12325
|
+
SHORT_TERM_LOCK_RELATIVE_PATH = path42.join("memory", ".dreams", "short-term-promotion.lock");
|
|
12326
12326
|
SHORT_TERM_LOCK_WAIT_TIMEOUT_MS = 1e4;
|
|
12327
12327
|
SHORT_TERM_LOCK_STALE_MS = 6e4;
|
|
12328
12328
|
SHORT_TERM_LOCK_RETRY_DELAY_MS = 40;
|
|
@@ -19734,9 +19734,9 @@ var init_string_utils = __esm({
|
|
|
19734
19734
|
});
|
|
19735
19735
|
|
|
19736
19736
|
// src/memory/host/config-utils.ts
|
|
19737
|
-
import
|
|
19737
|
+
import fs42 from "node:fs";
|
|
19738
19738
|
import os4 from "node:os";
|
|
19739
|
-
import
|
|
19739
|
+
import path43 from "node:path";
|
|
19740
19740
|
function normalizeAgentId(value) {
|
|
19741
19741
|
const trimmed = (value ?? "").trim();
|
|
19742
19742
|
if (!trimmed) {
|
|
@@ -19761,7 +19761,7 @@ function resolveRawOsHomeDir(env, homedir2) {
|
|
|
19761
19761
|
function resolveRequiredHomeDir(env = process.env, homedir2 = os4.homedir) {
|
|
19762
19762
|
const explicitHome = normalizeHomeValue(env.OPENCLAW_HOME);
|
|
19763
19763
|
const rawHome = explicitHome ? explicitHome.replace(/^~(?=$|[\\/])/, resolveRawOsHomeDir(env, homedir2) ?? "") : resolveRawOsHomeDir(env, homedir2);
|
|
19764
|
-
return rawHome ?
|
|
19764
|
+
return rawHome ? path43.resolve(rawHome) : path43.resolve(process.cwd());
|
|
19765
19765
|
}
|
|
19766
19766
|
function resolveUserPath2(input, env = process.env, homedir2 = os4.homedir) {
|
|
19767
19767
|
const trimmed = input.trim();
|
|
@@ -19769,12 +19769,12 @@ function resolveUserPath2(input, env = process.env, homedir2 = os4.homedir) {
|
|
|
19769
19769
|
return trimmed;
|
|
19770
19770
|
}
|
|
19771
19771
|
if (trimmed.startsWith("~")) {
|
|
19772
|
-
return
|
|
19772
|
+
return path43.resolve(trimmed.replace(/^~(?=$|[\\/])/, resolveRequiredHomeDir(env, homedir2)));
|
|
19773
19773
|
}
|
|
19774
|
-
return
|
|
19774
|
+
return path43.resolve(trimmed);
|
|
19775
19775
|
}
|
|
19776
19776
|
function legacyStateDirs(homedir2) {
|
|
19777
|
-
return LEGACY_STATE_DIRNAMES.map((dir) =>
|
|
19777
|
+
return LEGACY_STATE_DIRNAMES.map((dir) => path43.join(homedir2(), dir));
|
|
19778
19778
|
}
|
|
19779
19779
|
function resolveStateDir2(env = process.env, homedir2 = os4.homedir) {
|
|
19780
19780
|
const override = env.OPENCLAW_STATE_DIR?.trim();
|
|
@@ -19782,13 +19782,13 @@ function resolveStateDir2(env = process.env, homedir2 = os4.homedir) {
|
|
|
19782
19782
|
return resolveUserPath2(override, env, homedir2);
|
|
19783
19783
|
}
|
|
19784
19784
|
const effectiveHome = () => resolveRequiredHomeDir(env, homedir2);
|
|
19785
|
-
const nextDir =
|
|
19786
|
-
if (env.OPENCLAW_TEST_FAST === "1" ||
|
|
19785
|
+
const nextDir = path43.join(effectiveHome(), NEW_STATE_DIRNAME);
|
|
19786
|
+
if (env.OPENCLAW_TEST_FAST === "1" || fs42.existsSync(nextDir)) {
|
|
19787
19787
|
return nextDir;
|
|
19788
19788
|
}
|
|
19789
19789
|
const existingLegacy = legacyStateDirs(effectiveHome).find((dir) => {
|
|
19790
19790
|
try {
|
|
19791
|
-
return
|
|
19791
|
+
return fs42.existsSync(dir);
|
|
19792
19792
|
} catch {
|
|
19793
19793
|
return false;
|
|
19794
19794
|
}
|
|
@@ -19799,9 +19799,9 @@ function resolveDefaultAgentWorkspaceDir(env = process.env) {
|
|
|
19799
19799
|
const home = resolveRequiredHomeDir(env, os4.homedir);
|
|
19800
19800
|
const profile = env.OPENCLAW_PROFILE?.trim();
|
|
19801
19801
|
if (profile && normalizeLowercaseStringOrEmpty2(profile) !== "default") {
|
|
19802
|
-
return
|
|
19802
|
+
return path43.join(home, ".openclaw", `workspace-${profile}`);
|
|
19803
19803
|
}
|
|
19804
|
-
return
|
|
19804
|
+
return path43.join(home, ".openclaw", "workspace");
|
|
19805
19805
|
}
|
|
19806
19806
|
function listAgentEntries(cfg) {
|
|
19807
19807
|
return Array.isArray(cfg.agents?.list) ? cfg.agents.list.filter((entry) => Boolean(entry)) : [];
|
|
@@ -19834,9 +19834,9 @@ function resolveAgentWorkspaceDir2(cfg, agentId, env = process.env) {
|
|
|
19834
19834
|
);
|
|
19835
19835
|
}
|
|
19836
19836
|
if (fallback) {
|
|
19837
|
-
return stripNullBytes(
|
|
19837
|
+
return stripNullBytes(path43.join(resolveUserPath2(fallback, env), id));
|
|
19838
19838
|
}
|
|
19839
|
-
return stripNullBytes(
|
|
19839
|
+
return stripNullBytes(path43.join(resolveStateDir2(env), `workspace-${id}`));
|
|
19840
19840
|
}
|
|
19841
19841
|
function resolveAgentContextLimits2(cfg, agentId) {
|
|
19842
19842
|
const defaults = cfg?.agents?.defaults?.contextLimits;
|
|
@@ -19922,12 +19922,12 @@ var init_config4 = __esm({
|
|
|
19922
19922
|
});
|
|
19923
19923
|
|
|
19924
19924
|
// src/memory/shims/fs-safe/root.ts
|
|
19925
|
-
import
|
|
19925
|
+
import path44 from "node:path";
|
|
19926
19926
|
function root(...segments) {
|
|
19927
|
-
const basePath =
|
|
19927
|
+
const basePath = path44.resolve(...segments);
|
|
19928
19928
|
return {
|
|
19929
19929
|
resolve(relPath) {
|
|
19930
|
-
return Promise.resolve(
|
|
19930
|
+
return Promise.resolve(path44.resolve(basePath, relPath));
|
|
19931
19931
|
}
|
|
19932
19932
|
};
|
|
19933
19933
|
}
|
|
@@ -19938,10 +19938,10 @@ var init_root = __esm({
|
|
|
19938
19938
|
});
|
|
19939
19939
|
|
|
19940
19940
|
// src/memory/shims/fs-safe/path.ts
|
|
19941
|
-
import
|
|
19941
|
+
import path45 from "node:path";
|
|
19942
19942
|
function isPathInside(childPath, parentPath) {
|
|
19943
|
-
const relative4 =
|
|
19944
|
-
return !relative4.startsWith("..") && !
|
|
19943
|
+
const relative4 = path45.relative(parentPath, childPath);
|
|
19944
|
+
return !relative4.startsWith("..") && !path45.isAbsolute(relative4);
|
|
19945
19945
|
}
|
|
19946
19946
|
function isPathInsideWithRealpath(childPath, parentPath) {
|
|
19947
19947
|
try {
|
|
@@ -19957,12 +19957,12 @@ var init_path2 = __esm({
|
|
|
19957
19957
|
});
|
|
19958
19958
|
|
|
19959
19959
|
// src/memory/shims/fs-safe/advanced.ts
|
|
19960
|
-
import
|
|
19960
|
+
import fs43 from "node:fs";
|
|
19961
19961
|
function readRegularFile(filePathOrOptions) {
|
|
19962
19962
|
const filePath = typeof filePathOrOptions === "string" ? filePathOrOptions : filePathOrOptions.filePath;
|
|
19963
19963
|
const maxBytes = typeof filePathOrOptions === "string" ? void 0 : filePathOrOptions.maxBytes;
|
|
19964
19964
|
try {
|
|
19965
|
-
const buf =
|
|
19965
|
+
const buf = fs43.readFileSync(filePath);
|
|
19966
19966
|
if (maxBytes && buf.length > maxBytes) {
|
|
19967
19967
|
return { buffer: buf.subarray(0, maxBytes) };
|
|
19968
19968
|
}
|
|
@@ -19973,7 +19973,7 @@ function readRegularFile(filePathOrOptions) {
|
|
|
19973
19973
|
}
|
|
19974
19974
|
function statRegularFile(filePath) {
|
|
19975
19975
|
try {
|
|
19976
|
-
const stat8 =
|
|
19976
|
+
const stat8 = fs43.statSync(filePath);
|
|
19977
19977
|
if (!stat8.isFile()) return { missing: true };
|
|
19978
19978
|
return { missing: false, stat: { size: stat8.size, mtimeMs: stat8.mtimeMs } };
|
|
19979
19979
|
} catch {
|
|
@@ -19989,22 +19989,22 @@ var init_advanced = __esm({
|
|
|
19989
19989
|
});
|
|
19990
19990
|
|
|
19991
19991
|
// src/memory/shims/fs-safe/walk.ts
|
|
19992
|
-
import
|
|
19993
|
-
import
|
|
19992
|
+
import fs44 from "node:fs";
|
|
19993
|
+
import path46 from "node:path";
|
|
19994
19994
|
async function walkDirectory(dir, options) {
|
|
19995
19995
|
const entries = [];
|
|
19996
19996
|
async function walk(d) {
|
|
19997
|
-
if (!
|
|
19997
|
+
if (!fs44.existsSync(d)) return;
|
|
19998
19998
|
let dirents;
|
|
19999
19999
|
try {
|
|
20000
|
-
dirents =
|
|
20000
|
+
dirents = fs44.readdirSync(d, { withFileTypes: true });
|
|
20001
20001
|
} catch {
|
|
20002
20002
|
return;
|
|
20003
20003
|
}
|
|
20004
20004
|
for (const dirent of dirents) {
|
|
20005
20005
|
const kind = dirent.isDirectory() ? "directory" : "file";
|
|
20006
20006
|
const entry = {
|
|
20007
|
-
path:
|
|
20007
|
+
path: path46.join(d, dirent.name),
|
|
20008
20008
|
name: dirent.name,
|
|
20009
20009
|
kind
|
|
20010
20010
|
};
|
|
@@ -20161,8 +20161,8 @@ var init_hash2 = __esm({
|
|
|
20161
20161
|
// src/memory/host/internal.ts
|
|
20162
20162
|
import crypto8 from "node:crypto";
|
|
20163
20163
|
import fsSync from "node:fs";
|
|
20164
|
-
import
|
|
20165
|
-
import
|
|
20164
|
+
import fs45 from "node:fs/promises";
|
|
20165
|
+
import path47 from "node:path";
|
|
20166
20166
|
function ensureDir(dir) {
|
|
20167
20167
|
try {
|
|
20168
20168
|
fsSync.mkdirSync(dir, { recursive: true });
|
|
@@ -20180,7 +20180,7 @@ function normalizeExtraMemoryPaths(_baseDir, extraPaths) {
|
|
|
20180
20180
|
}
|
|
20181
20181
|
const stateDir = process.env.ENGINE_STATE_DIR || process.cwd();
|
|
20182
20182
|
const resolved = extraPaths.map((value) => value.trim()).filter(Boolean).map(
|
|
20183
|
-
(value) =>
|
|
20183
|
+
(value) => path47.isAbsolute(value) ? path47.resolve(value) : path47.resolve(stateDir, value)
|
|
20184
20184
|
);
|
|
20185
20185
|
return Array.from(new Set(resolved));
|
|
20186
20186
|
}
|
|
@@ -20216,7 +20216,7 @@ async function collectMemoryFilesFromDir(dir, files, multimodal, shouldSkipPath)
|
|
|
20216
20216
|
}
|
|
20217
20217
|
async function listMemoryFiles(workspaceDir, extraPaths, multimodal) {
|
|
20218
20218
|
const result = [];
|
|
20219
|
-
const memoryDir =
|
|
20219
|
+
const memoryDir = path47.join(workspaceDir, "memory");
|
|
20220
20220
|
const shouldSkipWorkspaceMemoryPath = (absPath) => shouldSkipRootMemoryAuxiliaryPath({ workspaceDir, absPath });
|
|
20221
20221
|
const addMarkdownFile = async (absPath) => {
|
|
20222
20222
|
try {
|
|
@@ -20236,7 +20236,7 @@ async function listMemoryFiles(workspaceDir, extraPaths, multimodal) {
|
|
|
20236
20236
|
await addMarkdownFile(memoryFile);
|
|
20237
20237
|
}
|
|
20238
20238
|
try {
|
|
20239
|
-
const dirStat = await
|
|
20239
|
+
const dirStat = await fs45.lstat(memoryDir);
|
|
20240
20240
|
if (!dirStat.isSymbolicLink() && dirStat.isDirectory()) {
|
|
20241
20241
|
await collectMemoryFilesFromDir(memoryDir, result, multimodal, shouldSkipWorkspaceMemoryPath);
|
|
20242
20242
|
}
|
|
@@ -20249,7 +20249,7 @@ async function listMemoryFiles(workspaceDir, extraPaths, multimodal) {
|
|
|
20249
20249
|
continue;
|
|
20250
20250
|
}
|
|
20251
20251
|
try {
|
|
20252
|
-
const stat8 = await
|
|
20252
|
+
const stat8 = await fs45.lstat(inputPath);
|
|
20253
20253
|
if (stat8.isSymbolicLink()) {
|
|
20254
20254
|
continue;
|
|
20255
20255
|
}
|
|
@@ -20277,7 +20277,7 @@ async function listMemoryFiles(workspaceDir, extraPaths, multimodal) {
|
|
|
20277
20277
|
for (const entry of result) {
|
|
20278
20278
|
let key = entry;
|
|
20279
20279
|
try {
|
|
20280
|
-
key = await
|
|
20280
|
+
key = await fs45.realpath(entry);
|
|
20281
20281
|
} catch {
|
|
20282
20282
|
}
|
|
20283
20283
|
if (seen.has(key)) {
|
|
@@ -20294,7 +20294,7 @@ async function buildFileEntry(absPath, workspaceDir, multimodal) {
|
|
|
20294
20294
|
return null;
|
|
20295
20295
|
}
|
|
20296
20296
|
const stat8 = regularFile.stat;
|
|
20297
|
-
const normalizedPath =
|
|
20297
|
+
const normalizedPath = path47.relative(workspaceDir, absPath).replace(/\\/g, "/");
|
|
20298
20298
|
const multimodalSettings = multimodal ?? DISABLED_MULTIMODAL_SETTINGS;
|
|
20299
20299
|
const modality = classifyMemoryMultimodalPath(absPath, multimodalSettings);
|
|
20300
20300
|
if (modality) {
|
|
@@ -20657,8 +20657,8 @@ __export(read_file_exports, {
|
|
|
20657
20657
|
readAgentMemoryFile: () => readAgentMemoryFile,
|
|
20658
20658
|
readMemoryFile: () => readMemoryFile
|
|
20659
20659
|
});
|
|
20660
|
-
import
|
|
20661
|
-
import
|
|
20660
|
+
import fs46 from "node:fs/promises";
|
|
20661
|
+
import path48 from "node:path";
|
|
20662
20662
|
async function isAllowedAdditionalDirectoryPath(additionalPath, absPath) {
|
|
20663
20663
|
if (!isPathInside(additionalPath, absPath)) {
|
|
20664
20664
|
return false;
|
|
@@ -20670,7 +20670,7 @@ async function isAllowedAdditionalDirectoryPath(additionalPath, absPath) {
|
|
|
20670
20670
|
}
|
|
20671
20671
|
if (!isPathInsideWithRealpath(additionalPath, absPath)) {
|
|
20672
20672
|
try {
|
|
20673
|
-
await
|
|
20673
|
+
await fs46.lstat(absPath);
|
|
20674
20674
|
} catch (err) {
|
|
20675
20675
|
return isFileMissingError(err);
|
|
20676
20676
|
}
|
|
@@ -20683,22 +20683,22 @@ async function readMemoryFile(params) {
|
|
|
20683
20683
|
if (!rawPath) {
|
|
20684
20684
|
throw new Error("path required");
|
|
20685
20685
|
}
|
|
20686
|
-
const absPath =
|
|
20687
|
-
const relPath =
|
|
20688
|
-
const inWorkspace = relPath.length > 0 && !relPath.startsWith("..") && !
|
|
20686
|
+
const absPath = path48.isAbsolute(rawPath) ? path48.resolve(rawPath) : path48.resolve(params.workspaceDir, rawPath);
|
|
20687
|
+
const relPath = path48.relative(params.workspaceDir, absPath).replace(/\\/g, "/");
|
|
20688
|
+
const inWorkspace = relPath.length > 0 && !relPath.startsWith("..") && !path48.isAbsolute(relPath);
|
|
20689
20689
|
const allowedWorkspace = inWorkspace && isMemoryPath(relPath);
|
|
20690
20690
|
let allowedAdditional = false;
|
|
20691
20691
|
if (!allowedWorkspace && (params.extraPaths?.length ?? 0) > 0) {
|
|
20692
20692
|
const additionalPaths = normalizeExtraMemoryPaths(params.workspaceDir, params.extraPaths);
|
|
20693
20693
|
for (const additionalPath of additionalPaths) {
|
|
20694
20694
|
try {
|
|
20695
|
-
const stat8 = await
|
|
20695
|
+
const stat8 = await fs46.lstat(additionalPath);
|
|
20696
20696
|
if (stat8.isSymbolicLink()) {
|
|
20697
20697
|
continue;
|
|
20698
20698
|
}
|
|
20699
20699
|
if (stat8.isDirectory()) {
|
|
20700
20700
|
if (await isAllowedAdditionalDirectoryPath(additionalPath, absPath)) {
|
|
20701
|
-
const candidateStat = await
|
|
20701
|
+
const candidateStat = await fs46.lstat(absPath).catch(() => null);
|
|
20702
20702
|
if (candidateStat?.isSymbolicLink()) {
|
|
20703
20703
|
continue;
|
|
20704
20704
|
}
|
|
@@ -21168,8 +21168,8 @@ var init_memory_core_host_runtime_files = __esm({
|
|
|
21168
21168
|
});
|
|
21169
21169
|
|
|
21170
21170
|
// src/memory/shims/memory-core-host-engine-qmd.ts
|
|
21171
|
-
import * as
|
|
21172
|
-
import * as
|
|
21171
|
+
import * as path49 from "path";
|
|
21172
|
+
import * as fs47 from "fs/promises";
|
|
21173
21173
|
import { createHash as createHash3 } from "crypto";
|
|
21174
21174
|
function extractKeywords(query) {
|
|
21175
21175
|
return [...new Set(
|
|
@@ -21181,8 +21181,8 @@ async function checkQmdBinaryAvailability() {
|
|
|
21181
21181
|
}
|
|
21182
21182
|
async function buildSessionEntry(filePath) {
|
|
21183
21183
|
try {
|
|
21184
|
-
const stat8 = await
|
|
21185
|
-
const raw = await
|
|
21184
|
+
const stat8 = await fs47.stat(filePath);
|
|
21185
|
+
const raw = await fs47.readFile(filePath, "utf-8");
|
|
21186
21186
|
const contentParts = [];
|
|
21187
21187
|
if (filePath.endsWith(".json")) {
|
|
21188
21188
|
try {
|
|
@@ -21257,13 +21257,13 @@ function isUsageCountedSessionTranscriptFileName(_name) {
|
|
|
21257
21257
|
async function listSessionFilesForAgent(params) {
|
|
21258
21258
|
try {
|
|
21259
21259
|
const sessionsDir = resolveSessionTranscriptsDirForAgent({ agentId: params.agentId ?? "main" });
|
|
21260
|
-
const entries = await
|
|
21261
|
-
const sessionFiles = entries.filter((name) => name.includes(".jsonl") || name.startsWith("session_") && name.endsWith(".json")).map((name) =>
|
|
21260
|
+
const entries = await fs47.readdir(sessionsDir);
|
|
21261
|
+
const sessionFiles = entries.filter((name) => name.includes(".jsonl") || name.startsWith("session_") && name.endsWith(".json")).map((name) => path49.join(sessionsDir, name));
|
|
21262
21262
|
console.log(`[memory-sync] listSessionFilesForAgent: found ${sessionFiles.length} files in ${sessionsDir}`);
|
|
21263
|
-
const archiveDir =
|
|
21263
|
+
const archiveDir = path49.join(sessionsDir, "archive");
|
|
21264
21264
|
try {
|
|
21265
|
-
const archiveEntries = await
|
|
21266
|
-
const archiveFiles = archiveEntries.filter((name) => name.endsWith(".jsonl") || name.endsWith(".json")).map((name) =>
|
|
21265
|
+
const archiveEntries = await fs47.readdir(archiveDir);
|
|
21266
|
+
const archiveFiles = archiveEntries.filter((name) => name.endsWith(".jsonl") || name.endsWith(".json")).map((name) => path49.join(archiveDir, name));
|
|
21267
21267
|
if (archiveFiles.length > 0) {
|
|
21268
21268
|
console.log(`[memory-sync] listSessionFilesForAgent: found ${archiveFiles.length} files in ${archiveDir}`);
|
|
21269
21269
|
sessionFiles.push(...archiveFiles);
|
|
@@ -21272,10 +21272,10 @@ async function listSessionFilesForAgent(params) {
|
|
|
21272
21272
|
}
|
|
21273
21273
|
const legacyDir = params.legacySessionsDir;
|
|
21274
21274
|
if (legacyDir) {
|
|
21275
|
-
const absLegacyDir =
|
|
21275
|
+
const absLegacyDir = path49.isAbsolute(legacyDir) ? legacyDir : path49.join(resolveStateDir(), legacyDir);
|
|
21276
21276
|
try {
|
|
21277
|
-
const legacyEntries = await
|
|
21278
|
-
const legacyFiles = legacyEntries.filter((name) => name.endsWith(".jsonl") || name.startsWith("session_") && name.endsWith(".json")).map((name) =>
|
|
21277
|
+
const legacyEntries = await fs47.readdir(absLegacyDir);
|
|
21278
|
+
const legacyFiles = legacyEntries.filter((name) => name.endsWith(".jsonl") || name.startsWith("session_") && name.endsWith(".json")).map((name) => path49.join(absLegacyDir, name));
|
|
21279
21279
|
if (legacyFiles.length > 0) {
|
|
21280
21280
|
console.log(`[memory-sync] listSessionFilesForAgent: found ${legacyFiles.length} files in ${absLegacyDir}`);
|
|
21281
21281
|
sessionFiles.push(...legacyFiles);
|
|
@@ -21717,8 +21717,8 @@ var init_mmr = __esm({
|
|
|
21717
21717
|
});
|
|
21718
21718
|
|
|
21719
21719
|
// src/memory/tools/memory/temporal-decay.ts
|
|
21720
|
-
import
|
|
21721
|
-
import
|
|
21720
|
+
import fs48 from "node:fs/promises";
|
|
21721
|
+
import path50 from "node:path";
|
|
21722
21722
|
function toDecayLambda(halfLifeDays) {
|
|
21723
21723
|
if (!Number.isFinite(halfLifeDays) || halfLifeDays <= 0) {
|
|
21724
21724
|
return 0;
|
|
@@ -21776,9 +21776,9 @@ async function extractTimestamp(params) {
|
|
|
21776
21776
|
if (!params.workspaceDir) {
|
|
21777
21777
|
return null;
|
|
21778
21778
|
}
|
|
21779
|
-
const absolutePath =
|
|
21779
|
+
const absolutePath = path50.isAbsolute(params.filePath) ? params.filePath : path50.resolve(params.workspaceDir, params.filePath);
|
|
21780
21780
|
try {
|
|
21781
|
-
const stat8 = await
|
|
21781
|
+
const stat8 = await fs48.stat(absolutePath);
|
|
21782
21782
|
if (!Number.isFinite(stat8.mtimeMs)) {
|
|
21783
21783
|
return null;
|
|
21784
21784
|
}
|
|
@@ -22041,9 +22041,9 @@ var init_manager_cache = __esm({
|
|
|
22041
22041
|
});
|
|
22042
22042
|
|
|
22043
22043
|
// src/memory/tools/memory/manager-db.ts
|
|
22044
|
-
import
|
|
22044
|
+
import path51 from "node:path";
|
|
22045
22045
|
function openMemoryDatabaseAtPath(dbPath, allowExtension) {
|
|
22046
|
-
const dir =
|
|
22046
|
+
const dir = path51.dirname(dbPath);
|
|
22047
22047
|
ensureDir(dir);
|
|
22048
22048
|
const { DatabaseSync: DatabaseSync2 } = requireNodeSqlite();
|
|
22049
22049
|
const db = new DatabaseSync2(dbPath, { allowExtension });
|
|
@@ -22348,7 +22348,7 @@ var init_readdirp = __esm({
|
|
|
22348
22348
|
this._directoryFilter = normalizeFilter(opts.directoryFilter);
|
|
22349
22349
|
const statMethod = opts.lstat ? lstat : stat5;
|
|
22350
22350
|
if (wantBigintFsStats) {
|
|
22351
|
-
this._stat = (
|
|
22351
|
+
this._stat = (path56) => statMethod(path56, { bigint: true });
|
|
22352
22352
|
} else {
|
|
22353
22353
|
this._stat = statMethod;
|
|
22354
22354
|
}
|
|
@@ -22373,8 +22373,8 @@ var init_readdirp = __esm({
|
|
|
22373
22373
|
const par = this.parent;
|
|
22374
22374
|
const fil = par && par.files;
|
|
22375
22375
|
if (fil && fil.length > 0) {
|
|
22376
|
-
const { path:
|
|
22377
|
-
const slice = fil.splice(0, batch).map((dirent) => this._formatEntry(dirent,
|
|
22376
|
+
const { path: path56, depth } = par;
|
|
22377
|
+
const slice = fil.splice(0, batch).map((dirent) => this._formatEntry(dirent, path56));
|
|
22378
22378
|
const awaited = await Promise.all(slice);
|
|
22379
22379
|
for (const entry of awaited) {
|
|
22380
22380
|
if (!entry)
|
|
@@ -22414,20 +22414,20 @@ var init_readdirp = __esm({
|
|
|
22414
22414
|
this.reading = false;
|
|
22415
22415
|
}
|
|
22416
22416
|
}
|
|
22417
|
-
async _exploreDir(
|
|
22417
|
+
async _exploreDir(path56, depth) {
|
|
22418
22418
|
let files;
|
|
22419
22419
|
try {
|
|
22420
|
-
files = await readdir3(
|
|
22420
|
+
files = await readdir3(path56, this._rdOptions);
|
|
22421
22421
|
} catch (error) {
|
|
22422
22422
|
this._onError(error);
|
|
22423
22423
|
}
|
|
22424
|
-
return { files, depth, path:
|
|
22424
|
+
return { files, depth, path: path56 };
|
|
22425
22425
|
}
|
|
22426
|
-
async _formatEntry(dirent,
|
|
22426
|
+
async _formatEntry(dirent, path56) {
|
|
22427
22427
|
let entry;
|
|
22428
22428
|
const basename9 = this._isDirent ? dirent.name : dirent;
|
|
22429
22429
|
try {
|
|
22430
|
-
const fullPath = presolve(pjoin(
|
|
22430
|
+
const fullPath = presolve(pjoin(path56, basename9));
|
|
22431
22431
|
entry = { path: prelative(this._root, fullPath), fullPath, basename: basename9 };
|
|
22432
22432
|
entry[this._statsProp] = this._isDirent ? dirent : await this._stat(fullPath);
|
|
22433
22433
|
} catch (err) {
|
|
@@ -22488,16 +22488,16 @@ import { watch as fs_watch, unwatchFile, watchFile } from "node:fs";
|
|
|
22488
22488
|
import { realpath as fsrealpath, lstat as lstat2, open, stat as stat6 } from "node:fs/promises";
|
|
22489
22489
|
import { type as osType } from "node:os";
|
|
22490
22490
|
import * as sp from "node:path";
|
|
22491
|
-
function createFsWatchInstance(
|
|
22491
|
+
function createFsWatchInstance(path56, options, listener, errHandler, emitRaw) {
|
|
22492
22492
|
const handleEvent = (rawEvent, evPath) => {
|
|
22493
|
-
listener(
|
|
22494
|
-
emitRaw(rawEvent, evPath, { watchedPath:
|
|
22495
|
-
if (evPath &&
|
|
22496
|
-
fsWatchBroadcast(sp.resolve(
|
|
22493
|
+
listener(path56);
|
|
22494
|
+
emitRaw(rawEvent, evPath, { watchedPath: path56 });
|
|
22495
|
+
if (evPath && path56 !== evPath) {
|
|
22496
|
+
fsWatchBroadcast(sp.resolve(path56, evPath), KEY_LISTENERS, sp.join(path56, evPath));
|
|
22497
22497
|
}
|
|
22498
22498
|
};
|
|
22499
22499
|
try {
|
|
22500
|
-
return fs_watch(
|
|
22500
|
+
return fs_watch(path56, {
|
|
22501
22501
|
persistent: options.persistent
|
|
22502
22502
|
}, handleEvent);
|
|
22503
22503
|
} catch (error) {
|
|
@@ -22841,12 +22841,12 @@ var init_handler = __esm({
|
|
|
22841
22841
|
listener(val1, val2, val3);
|
|
22842
22842
|
});
|
|
22843
22843
|
};
|
|
22844
|
-
setFsWatchListener = (
|
|
22844
|
+
setFsWatchListener = (path56, fullPath, options, handlers) => {
|
|
22845
22845
|
const { listener, errHandler, rawEmitter } = handlers;
|
|
22846
22846
|
let cont = FsWatchInstances.get(fullPath);
|
|
22847
22847
|
let watcher;
|
|
22848
22848
|
if (!options.persistent) {
|
|
22849
|
-
watcher = createFsWatchInstance(
|
|
22849
|
+
watcher = createFsWatchInstance(path56, options, listener, errHandler, rawEmitter);
|
|
22850
22850
|
if (!watcher)
|
|
22851
22851
|
return;
|
|
22852
22852
|
return watcher.close.bind(watcher);
|
|
@@ -22857,7 +22857,7 @@ var init_handler = __esm({
|
|
|
22857
22857
|
addAndConvert(cont, KEY_RAW, rawEmitter);
|
|
22858
22858
|
} else {
|
|
22859
22859
|
watcher = createFsWatchInstance(
|
|
22860
|
-
|
|
22860
|
+
path56,
|
|
22861
22861
|
options,
|
|
22862
22862
|
fsWatchBroadcast.bind(null, fullPath, KEY_LISTENERS),
|
|
22863
22863
|
errHandler,
|
|
@@ -22872,7 +22872,7 @@ var init_handler = __esm({
|
|
|
22872
22872
|
cont.watcherUnusable = true;
|
|
22873
22873
|
if (isWindows && error.code === "EPERM") {
|
|
22874
22874
|
try {
|
|
22875
|
-
const fd = await open(
|
|
22875
|
+
const fd = await open(path56, "r");
|
|
22876
22876
|
await fd.close();
|
|
22877
22877
|
broadcastErr(error);
|
|
22878
22878
|
} catch (err) {
|
|
@@ -22903,7 +22903,7 @@ var init_handler = __esm({
|
|
|
22903
22903
|
};
|
|
22904
22904
|
};
|
|
22905
22905
|
FsWatchFileInstances = /* @__PURE__ */ new Map();
|
|
22906
|
-
setFsWatchFileListener = (
|
|
22906
|
+
setFsWatchFileListener = (path56, fullPath, options, handlers) => {
|
|
22907
22907
|
const { listener, rawEmitter } = handlers;
|
|
22908
22908
|
let cont = FsWatchFileInstances.get(fullPath);
|
|
22909
22909
|
const copts = cont && cont.options;
|
|
@@ -22925,7 +22925,7 @@ var init_handler = __esm({
|
|
|
22925
22925
|
});
|
|
22926
22926
|
const currmtime = curr.mtimeMs;
|
|
22927
22927
|
if (curr.size !== prev.size || currmtime > prev.mtimeMs || currmtime === 0) {
|
|
22928
|
-
foreach(cont.listeners, (listener2) => listener2(
|
|
22928
|
+
foreach(cont.listeners, (listener2) => listener2(path56, curr));
|
|
22929
22929
|
}
|
|
22930
22930
|
})
|
|
22931
22931
|
};
|
|
@@ -22955,13 +22955,13 @@ var init_handler = __esm({
|
|
|
22955
22955
|
* @param listener on fs change
|
|
22956
22956
|
* @returns closer for the watcher instance
|
|
22957
22957
|
*/
|
|
22958
|
-
_watchWithNodeFs(
|
|
22958
|
+
_watchWithNodeFs(path56, listener) {
|
|
22959
22959
|
const opts = this.fsw.options;
|
|
22960
|
-
const directory = sp.dirname(
|
|
22961
|
-
const basename9 = sp.basename(
|
|
22960
|
+
const directory = sp.dirname(path56);
|
|
22961
|
+
const basename9 = sp.basename(path56);
|
|
22962
22962
|
const parent = this.fsw._getWatchedDir(directory);
|
|
22963
22963
|
parent.add(basename9);
|
|
22964
|
-
const absolutePath = sp.resolve(
|
|
22964
|
+
const absolutePath = sp.resolve(path56);
|
|
22965
22965
|
const options = {
|
|
22966
22966
|
persistent: opts.persistent
|
|
22967
22967
|
};
|
|
@@ -22971,12 +22971,12 @@ var init_handler = __esm({
|
|
|
22971
22971
|
if (opts.usePolling) {
|
|
22972
22972
|
const enableBin = opts.interval !== opts.binaryInterval;
|
|
22973
22973
|
options.interval = enableBin && isBinaryPath(basename9) ? opts.binaryInterval : opts.interval;
|
|
22974
|
-
closer = setFsWatchFileListener(
|
|
22974
|
+
closer = setFsWatchFileListener(path56, absolutePath, options, {
|
|
22975
22975
|
listener,
|
|
22976
22976
|
rawEmitter: this.fsw._emitRaw
|
|
22977
22977
|
});
|
|
22978
22978
|
} else {
|
|
22979
|
-
closer = setFsWatchListener(
|
|
22979
|
+
closer = setFsWatchListener(path56, absolutePath, options, {
|
|
22980
22980
|
listener,
|
|
22981
22981
|
errHandler: this._boundHandleError,
|
|
22982
22982
|
rawEmitter: this.fsw._emitRaw
|
|
@@ -22998,7 +22998,7 @@ var init_handler = __esm({
|
|
|
22998
22998
|
let prevStats = stats2;
|
|
22999
22999
|
if (parent.has(basename9))
|
|
23000
23000
|
return;
|
|
23001
|
-
const listener = async (
|
|
23001
|
+
const listener = async (path56, newStats) => {
|
|
23002
23002
|
if (!this.fsw._throttle(THROTTLE_MODE_WATCH, file, 5))
|
|
23003
23003
|
return;
|
|
23004
23004
|
if (!newStats || newStats.mtimeMs === 0) {
|
|
@@ -23012,11 +23012,11 @@ var init_handler = __esm({
|
|
|
23012
23012
|
this.fsw._emit(EV.CHANGE, file, newStats2);
|
|
23013
23013
|
}
|
|
23014
23014
|
if ((isMacos || isLinux || isFreeBSD) && prevStats.ino !== newStats2.ino) {
|
|
23015
|
-
this.fsw._closeFile(
|
|
23015
|
+
this.fsw._closeFile(path56);
|
|
23016
23016
|
prevStats = newStats2;
|
|
23017
23017
|
const closer2 = this._watchWithNodeFs(file, listener);
|
|
23018
23018
|
if (closer2)
|
|
23019
|
-
this.fsw._addPathCloser(
|
|
23019
|
+
this.fsw._addPathCloser(path56, closer2);
|
|
23020
23020
|
} else {
|
|
23021
23021
|
prevStats = newStats2;
|
|
23022
23022
|
}
|
|
@@ -23048,7 +23048,7 @@ var init_handler = __esm({
|
|
|
23048
23048
|
* @param item basename of this item
|
|
23049
23049
|
* @returns true if no more processing is needed for this entry.
|
|
23050
23050
|
*/
|
|
23051
|
-
async _handleSymlink(entry, directory,
|
|
23051
|
+
async _handleSymlink(entry, directory, path56, item) {
|
|
23052
23052
|
if (this.fsw.closed) {
|
|
23053
23053
|
return;
|
|
23054
23054
|
}
|
|
@@ -23058,7 +23058,7 @@ var init_handler = __esm({
|
|
|
23058
23058
|
this.fsw._incrReadyCount();
|
|
23059
23059
|
let linkPath;
|
|
23060
23060
|
try {
|
|
23061
|
-
linkPath = await fsrealpath(
|
|
23061
|
+
linkPath = await fsrealpath(path56);
|
|
23062
23062
|
} catch (e) {
|
|
23063
23063
|
this.fsw._emitReady();
|
|
23064
23064
|
return true;
|
|
@@ -23068,12 +23068,12 @@ var init_handler = __esm({
|
|
|
23068
23068
|
if (dir.has(item)) {
|
|
23069
23069
|
if (this.fsw._symlinkPaths.get(full) !== linkPath) {
|
|
23070
23070
|
this.fsw._symlinkPaths.set(full, linkPath);
|
|
23071
|
-
this.fsw._emit(EV.CHANGE,
|
|
23071
|
+
this.fsw._emit(EV.CHANGE, path56, entry.stats);
|
|
23072
23072
|
}
|
|
23073
23073
|
} else {
|
|
23074
23074
|
dir.add(item);
|
|
23075
23075
|
this.fsw._symlinkPaths.set(full, linkPath);
|
|
23076
|
-
this.fsw._emit(EV.ADD,
|
|
23076
|
+
this.fsw._emit(EV.ADD, path56, entry.stats);
|
|
23077
23077
|
}
|
|
23078
23078
|
this.fsw._emitReady();
|
|
23079
23079
|
return true;
|
|
@@ -23103,9 +23103,9 @@ var init_handler = __esm({
|
|
|
23103
23103
|
return;
|
|
23104
23104
|
}
|
|
23105
23105
|
const item = entry.path;
|
|
23106
|
-
let
|
|
23106
|
+
let path56 = sp.join(directory, item);
|
|
23107
23107
|
current.add(item);
|
|
23108
|
-
if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory,
|
|
23108
|
+
if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory, path56, item)) {
|
|
23109
23109
|
return;
|
|
23110
23110
|
}
|
|
23111
23111
|
if (this.fsw.closed) {
|
|
@@ -23114,8 +23114,8 @@ var init_handler = __esm({
|
|
|
23114
23114
|
}
|
|
23115
23115
|
if (item === target || !target && !previous.has(item)) {
|
|
23116
23116
|
this.fsw._incrReadyCount();
|
|
23117
|
-
|
|
23118
|
-
this._addToNodeFs(
|
|
23117
|
+
path56 = sp.join(dir, sp.relative(dir, path56));
|
|
23118
|
+
this._addToNodeFs(path56, initialAdd, wh, depth + 1);
|
|
23119
23119
|
}
|
|
23120
23120
|
}).on(EV.ERROR, this._boundHandleError);
|
|
23121
23121
|
return new Promise((resolve12, reject) => {
|
|
@@ -23184,13 +23184,13 @@ var init_handler = __esm({
|
|
|
23184
23184
|
* @param depth Child path actually targeted for watch
|
|
23185
23185
|
* @param target Child path actually targeted for watch
|
|
23186
23186
|
*/
|
|
23187
|
-
async _addToNodeFs(
|
|
23187
|
+
async _addToNodeFs(path56, initialAdd, priorWh, depth, target) {
|
|
23188
23188
|
const ready = this.fsw._emitReady;
|
|
23189
|
-
if (this.fsw._isIgnored(
|
|
23189
|
+
if (this.fsw._isIgnored(path56) || this.fsw.closed) {
|
|
23190
23190
|
ready();
|
|
23191
23191
|
return false;
|
|
23192
23192
|
}
|
|
23193
|
-
const wh = this.fsw._getWatchHelpers(
|
|
23193
|
+
const wh = this.fsw._getWatchHelpers(path56);
|
|
23194
23194
|
if (priorWh) {
|
|
23195
23195
|
wh.filterPath = (entry) => priorWh.filterPath(entry);
|
|
23196
23196
|
wh.filterDir = (entry) => priorWh.filterDir(entry);
|
|
@@ -23206,8 +23206,8 @@ var init_handler = __esm({
|
|
|
23206
23206
|
const follow = this.fsw.options.followSymlinks;
|
|
23207
23207
|
let closer;
|
|
23208
23208
|
if (stats2.isDirectory()) {
|
|
23209
|
-
const absPath = sp.resolve(
|
|
23210
|
-
const targetPath = follow ? await fsrealpath(
|
|
23209
|
+
const absPath = sp.resolve(path56);
|
|
23210
|
+
const targetPath = follow ? await fsrealpath(path56) : path56;
|
|
23211
23211
|
if (this.fsw.closed)
|
|
23212
23212
|
return;
|
|
23213
23213
|
closer = await this._handleDir(wh.watchPath, stats2, initialAdd, depth, target, wh, targetPath);
|
|
@@ -23217,29 +23217,29 @@ var init_handler = __esm({
|
|
|
23217
23217
|
this.fsw._symlinkPaths.set(absPath, targetPath);
|
|
23218
23218
|
}
|
|
23219
23219
|
} else if (stats2.isSymbolicLink()) {
|
|
23220
|
-
const targetPath = follow ? await fsrealpath(
|
|
23220
|
+
const targetPath = follow ? await fsrealpath(path56) : path56;
|
|
23221
23221
|
if (this.fsw.closed)
|
|
23222
23222
|
return;
|
|
23223
23223
|
const parent = sp.dirname(wh.watchPath);
|
|
23224
23224
|
this.fsw._getWatchedDir(parent).add(wh.watchPath);
|
|
23225
23225
|
this.fsw._emit(EV.ADD, wh.watchPath, stats2);
|
|
23226
|
-
closer = await this._handleDir(parent, stats2, initialAdd, depth,
|
|
23226
|
+
closer = await this._handleDir(parent, stats2, initialAdd, depth, path56, wh, targetPath);
|
|
23227
23227
|
if (this.fsw.closed)
|
|
23228
23228
|
return;
|
|
23229
23229
|
if (targetPath !== void 0) {
|
|
23230
|
-
this.fsw._symlinkPaths.set(sp.resolve(
|
|
23230
|
+
this.fsw._symlinkPaths.set(sp.resolve(path56), targetPath);
|
|
23231
23231
|
}
|
|
23232
23232
|
} else {
|
|
23233
23233
|
closer = this._handleFile(wh.watchPath, stats2, initialAdd);
|
|
23234
23234
|
}
|
|
23235
23235
|
ready();
|
|
23236
23236
|
if (closer)
|
|
23237
|
-
this.fsw._addPathCloser(
|
|
23237
|
+
this.fsw._addPathCloser(path56, closer);
|
|
23238
23238
|
return false;
|
|
23239
23239
|
} catch (error) {
|
|
23240
23240
|
if (this.fsw._handleError(error)) {
|
|
23241
23241
|
ready();
|
|
23242
|
-
return
|
|
23242
|
+
return path56;
|
|
23243
23243
|
}
|
|
23244
23244
|
}
|
|
23245
23245
|
}
|
|
@@ -23278,24 +23278,24 @@ function createPattern(matcher) {
|
|
|
23278
23278
|
}
|
|
23279
23279
|
return () => false;
|
|
23280
23280
|
}
|
|
23281
|
-
function normalizePath2(
|
|
23282
|
-
if (typeof
|
|
23281
|
+
function normalizePath2(path56) {
|
|
23282
|
+
if (typeof path56 !== "string")
|
|
23283
23283
|
throw new Error("string expected");
|
|
23284
|
-
|
|
23285
|
-
|
|
23284
|
+
path56 = sp2.normalize(path56);
|
|
23285
|
+
path56 = path56.replace(/\\/g, "/");
|
|
23286
23286
|
let prepend = false;
|
|
23287
|
-
if (
|
|
23287
|
+
if (path56.startsWith("//"))
|
|
23288
23288
|
prepend = true;
|
|
23289
|
-
|
|
23289
|
+
path56 = path56.replace(DOUBLE_SLASH_RE, "/");
|
|
23290
23290
|
if (prepend)
|
|
23291
|
-
|
|
23292
|
-
return
|
|
23291
|
+
path56 = "/" + path56;
|
|
23292
|
+
return path56;
|
|
23293
23293
|
}
|
|
23294
23294
|
function matchPatterns(patterns, testString, stats2) {
|
|
23295
|
-
const
|
|
23295
|
+
const path56 = normalizePath2(testString);
|
|
23296
23296
|
for (let index = 0; index < patterns.length; index++) {
|
|
23297
23297
|
const pattern = patterns[index];
|
|
23298
|
-
if (pattern(
|
|
23298
|
+
if (pattern(path56, stats2)) {
|
|
23299
23299
|
return true;
|
|
23300
23300
|
}
|
|
23301
23301
|
}
|
|
@@ -23353,19 +23353,19 @@ var init_chokidar = __esm({
|
|
|
23353
23353
|
}
|
|
23354
23354
|
return str;
|
|
23355
23355
|
};
|
|
23356
|
-
normalizePathToUnix = (
|
|
23357
|
-
normalizeIgnored = (cwd = "") => (
|
|
23358
|
-
if (typeof
|
|
23359
|
-
return normalizePathToUnix(sp2.isAbsolute(
|
|
23356
|
+
normalizePathToUnix = (path56) => toUnix(sp2.normalize(toUnix(path56)));
|
|
23357
|
+
normalizeIgnored = (cwd = "") => (path56) => {
|
|
23358
|
+
if (typeof path56 === "string") {
|
|
23359
|
+
return normalizePathToUnix(sp2.isAbsolute(path56) ? path56 : sp2.join(cwd, path56));
|
|
23360
23360
|
} else {
|
|
23361
|
-
return
|
|
23361
|
+
return path56;
|
|
23362
23362
|
}
|
|
23363
23363
|
};
|
|
23364
|
-
getAbsolutePath = (
|
|
23365
|
-
if (sp2.isAbsolute(
|
|
23366
|
-
return
|
|
23364
|
+
getAbsolutePath = (path56, cwd) => {
|
|
23365
|
+
if (sp2.isAbsolute(path56)) {
|
|
23366
|
+
return path56;
|
|
23367
23367
|
}
|
|
23368
|
-
return sp2.join(cwd,
|
|
23368
|
+
return sp2.join(cwd, path56);
|
|
23369
23369
|
};
|
|
23370
23370
|
EMPTY_SET = Object.freeze(/* @__PURE__ */ new Set());
|
|
23371
23371
|
DirEntry = class {
|
|
@@ -23430,10 +23430,10 @@ var init_chokidar = __esm({
|
|
|
23430
23430
|
dirParts;
|
|
23431
23431
|
followSymlinks;
|
|
23432
23432
|
statMethod;
|
|
23433
|
-
constructor(
|
|
23433
|
+
constructor(path56, follow, fsw) {
|
|
23434
23434
|
this.fsw = fsw;
|
|
23435
|
-
const watchPath =
|
|
23436
|
-
this.path =
|
|
23435
|
+
const watchPath = path56;
|
|
23436
|
+
this.path = path56 = path56.replace(REPLACER_RE, "");
|
|
23437
23437
|
this.watchPath = watchPath;
|
|
23438
23438
|
this.fullWatchPath = sp2.resolve(watchPath);
|
|
23439
23439
|
this.dirParts = [];
|
|
@@ -23573,20 +23573,20 @@ var init_chokidar = __esm({
|
|
|
23573
23573
|
this._closePromise = void 0;
|
|
23574
23574
|
let paths = unifyPaths(paths_);
|
|
23575
23575
|
if (cwd) {
|
|
23576
|
-
paths = paths.map((
|
|
23577
|
-
const absPath = getAbsolutePath(
|
|
23576
|
+
paths = paths.map((path56) => {
|
|
23577
|
+
const absPath = getAbsolutePath(path56, cwd);
|
|
23578
23578
|
return absPath;
|
|
23579
23579
|
});
|
|
23580
23580
|
}
|
|
23581
|
-
paths.forEach((
|
|
23582
|
-
this._removeIgnoredPath(
|
|
23581
|
+
paths.forEach((path56) => {
|
|
23582
|
+
this._removeIgnoredPath(path56);
|
|
23583
23583
|
});
|
|
23584
23584
|
this._userIgnored = void 0;
|
|
23585
23585
|
if (!this._readyCount)
|
|
23586
23586
|
this._readyCount = 0;
|
|
23587
23587
|
this._readyCount += paths.length;
|
|
23588
|
-
Promise.all(paths.map(async (
|
|
23589
|
-
const res = await this._nodeFsHandler._addToNodeFs(
|
|
23588
|
+
Promise.all(paths.map(async (path56) => {
|
|
23589
|
+
const res = await this._nodeFsHandler._addToNodeFs(path56, !_internal, void 0, 0, _origAdd);
|
|
23590
23590
|
if (res)
|
|
23591
23591
|
this._emitReady();
|
|
23592
23592
|
return res;
|
|
@@ -23608,17 +23608,17 @@ var init_chokidar = __esm({
|
|
|
23608
23608
|
return this;
|
|
23609
23609
|
const paths = unifyPaths(paths_);
|
|
23610
23610
|
const { cwd } = this.options;
|
|
23611
|
-
paths.forEach((
|
|
23612
|
-
if (!sp2.isAbsolute(
|
|
23611
|
+
paths.forEach((path56) => {
|
|
23612
|
+
if (!sp2.isAbsolute(path56) && !this._closers.has(path56)) {
|
|
23613
23613
|
if (cwd)
|
|
23614
|
-
|
|
23615
|
-
|
|
23614
|
+
path56 = sp2.join(cwd, path56);
|
|
23615
|
+
path56 = sp2.resolve(path56);
|
|
23616
23616
|
}
|
|
23617
|
-
this._closePath(
|
|
23618
|
-
this._addIgnoredPath(
|
|
23619
|
-
if (this._watched.has(
|
|
23617
|
+
this._closePath(path56);
|
|
23618
|
+
this._addIgnoredPath(path56);
|
|
23619
|
+
if (this._watched.has(path56)) {
|
|
23620
23620
|
this._addIgnoredPath({
|
|
23621
|
-
path:
|
|
23621
|
+
path: path56,
|
|
23622
23622
|
recursive: true
|
|
23623
23623
|
});
|
|
23624
23624
|
}
|
|
@@ -23682,38 +23682,38 @@ var init_chokidar = __esm({
|
|
|
23682
23682
|
* @param stats arguments to be passed with event
|
|
23683
23683
|
* @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag
|
|
23684
23684
|
*/
|
|
23685
|
-
async _emit(event,
|
|
23685
|
+
async _emit(event, path56, stats2) {
|
|
23686
23686
|
if (this.closed)
|
|
23687
23687
|
return;
|
|
23688
23688
|
const opts = this.options;
|
|
23689
23689
|
if (isWindows)
|
|
23690
|
-
|
|
23690
|
+
path56 = sp2.normalize(path56);
|
|
23691
23691
|
if (opts.cwd)
|
|
23692
|
-
|
|
23693
|
-
const args = [
|
|
23692
|
+
path56 = sp2.relative(opts.cwd, path56);
|
|
23693
|
+
const args = [path56];
|
|
23694
23694
|
if (stats2 != null)
|
|
23695
23695
|
args.push(stats2);
|
|
23696
23696
|
const awf = opts.awaitWriteFinish;
|
|
23697
23697
|
let pw;
|
|
23698
|
-
if (awf && (pw = this._pendingWrites.get(
|
|
23698
|
+
if (awf && (pw = this._pendingWrites.get(path56))) {
|
|
23699
23699
|
pw.lastChange = /* @__PURE__ */ new Date();
|
|
23700
23700
|
return this;
|
|
23701
23701
|
}
|
|
23702
23702
|
if (opts.atomic) {
|
|
23703
23703
|
if (event === EVENTS.UNLINK) {
|
|
23704
|
-
this._pendingUnlinks.set(
|
|
23704
|
+
this._pendingUnlinks.set(path56, [event, ...args]);
|
|
23705
23705
|
setTimeout(() => {
|
|
23706
|
-
this._pendingUnlinks.forEach((entry,
|
|
23706
|
+
this._pendingUnlinks.forEach((entry, path57) => {
|
|
23707
23707
|
this.emit(...entry);
|
|
23708
23708
|
this.emit(EVENTS.ALL, ...entry);
|
|
23709
|
-
this._pendingUnlinks.delete(
|
|
23709
|
+
this._pendingUnlinks.delete(path57);
|
|
23710
23710
|
});
|
|
23711
23711
|
}, typeof opts.atomic === "number" ? opts.atomic : 100);
|
|
23712
23712
|
return this;
|
|
23713
23713
|
}
|
|
23714
|
-
if (event === EVENTS.ADD && this._pendingUnlinks.has(
|
|
23714
|
+
if (event === EVENTS.ADD && this._pendingUnlinks.has(path56)) {
|
|
23715
23715
|
event = EVENTS.CHANGE;
|
|
23716
|
-
this._pendingUnlinks.delete(
|
|
23716
|
+
this._pendingUnlinks.delete(path56);
|
|
23717
23717
|
}
|
|
23718
23718
|
}
|
|
23719
23719
|
if (awf && (event === EVENTS.ADD || event === EVENTS.CHANGE) && this._readyEmitted) {
|
|
@@ -23731,16 +23731,16 @@ var init_chokidar = __esm({
|
|
|
23731
23731
|
this.emitWithAll(event, args);
|
|
23732
23732
|
}
|
|
23733
23733
|
};
|
|
23734
|
-
this._awaitWriteFinish(
|
|
23734
|
+
this._awaitWriteFinish(path56, awf.stabilityThreshold, event, awfEmit);
|
|
23735
23735
|
return this;
|
|
23736
23736
|
}
|
|
23737
23737
|
if (event === EVENTS.CHANGE) {
|
|
23738
|
-
const isThrottled = !this._throttle(EVENTS.CHANGE,
|
|
23738
|
+
const isThrottled = !this._throttle(EVENTS.CHANGE, path56, 50);
|
|
23739
23739
|
if (isThrottled)
|
|
23740
23740
|
return this;
|
|
23741
23741
|
}
|
|
23742
23742
|
if (opts.alwaysStat && stats2 === void 0 && (event === EVENTS.ADD || event === EVENTS.ADD_DIR || event === EVENTS.CHANGE)) {
|
|
23743
|
-
const fullPath = opts.cwd ? sp2.join(opts.cwd,
|
|
23743
|
+
const fullPath = opts.cwd ? sp2.join(opts.cwd, path56) : path56;
|
|
23744
23744
|
let stats3;
|
|
23745
23745
|
try {
|
|
23746
23746
|
stats3 = await stat7(fullPath);
|
|
@@ -23771,23 +23771,23 @@ var init_chokidar = __esm({
|
|
|
23771
23771
|
* @param timeout duration of time to suppress duplicate actions
|
|
23772
23772
|
* @returns tracking object or false if action should be suppressed
|
|
23773
23773
|
*/
|
|
23774
|
-
_throttle(actionType,
|
|
23774
|
+
_throttle(actionType, path56, timeout) {
|
|
23775
23775
|
if (!this._throttled.has(actionType)) {
|
|
23776
23776
|
this._throttled.set(actionType, /* @__PURE__ */ new Map());
|
|
23777
23777
|
}
|
|
23778
23778
|
const action = this._throttled.get(actionType);
|
|
23779
23779
|
if (!action)
|
|
23780
23780
|
throw new Error("invalid throttle");
|
|
23781
|
-
const actionPath = action.get(
|
|
23781
|
+
const actionPath = action.get(path56);
|
|
23782
23782
|
if (actionPath) {
|
|
23783
23783
|
actionPath.count++;
|
|
23784
23784
|
return false;
|
|
23785
23785
|
}
|
|
23786
23786
|
let timeoutObject;
|
|
23787
23787
|
const clear = () => {
|
|
23788
|
-
const item = action.get(
|
|
23788
|
+
const item = action.get(path56);
|
|
23789
23789
|
const count = item ? item.count : 0;
|
|
23790
|
-
action.delete(
|
|
23790
|
+
action.delete(path56);
|
|
23791
23791
|
clearTimeout(timeoutObject);
|
|
23792
23792
|
if (item)
|
|
23793
23793
|
clearTimeout(item.timeoutObject);
|
|
@@ -23795,7 +23795,7 @@ var init_chokidar = __esm({
|
|
|
23795
23795
|
};
|
|
23796
23796
|
timeoutObject = setTimeout(clear, timeout);
|
|
23797
23797
|
const thr = { timeoutObject, clear, count: 0 };
|
|
23798
|
-
action.set(
|
|
23798
|
+
action.set(path56, thr);
|
|
23799
23799
|
return thr;
|
|
23800
23800
|
}
|
|
23801
23801
|
_incrReadyCount() {
|
|
@@ -23809,44 +23809,44 @@ var init_chokidar = __esm({
|
|
|
23809
23809
|
* @param event
|
|
23810
23810
|
* @param awfEmit Callback to be called when ready for event to be emitted.
|
|
23811
23811
|
*/
|
|
23812
|
-
_awaitWriteFinish(
|
|
23812
|
+
_awaitWriteFinish(path56, threshold, event, awfEmit) {
|
|
23813
23813
|
const awf = this.options.awaitWriteFinish;
|
|
23814
23814
|
if (typeof awf !== "object")
|
|
23815
23815
|
return;
|
|
23816
23816
|
const pollInterval = awf.pollInterval;
|
|
23817
23817
|
let timeoutHandler;
|
|
23818
|
-
let fullPath =
|
|
23819
|
-
if (this.options.cwd && !sp2.isAbsolute(
|
|
23820
|
-
fullPath = sp2.join(this.options.cwd,
|
|
23818
|
+
let fullPath = path56;
|
|
23819
|
+
if (this.options.cwd && !sp2.isAbsolute(path56)) {
|
|
23820
|
+
fullPath = sp2.join(this.options.cwd, path56);
|
|
23821
23821
|
}
|
|
23822
23822
|
const now = /* @__PURE__ */ new Date();
|
|
23823
23823
|
const writes = this._pendingWrites;
|
|
23824
23824
|
function awaitWriteFinishFn(prevStat) {
|
|
23825
23825
|
statcb(fullPath, (err, curStat) => {
|
|
23826
|
-
if (err || !writes.has(
|
|
23826
|
+
if (err || !writes.has(path56)) {
|
|
23827
23827
|
if (err && err.code !== "ENOENT")
|
|
23828
23828
|
awfEmit(err);
|
|
23829
23829
|
return;
|
|
23830
23830
|
}
|
|
23831
23831
|
const now2 = Number(/* @__PURE__ */ new Date());
|
|
23832
23832
|
if (prevStat && curStat.size !== prevStat.size) {
|
|
23833
|
-
writes.get(
|
|
23833
|
+
writes.get(path56).lastChange = now2;
|
|
23834
23834
|
}
|
|
23835
|
-
const pw = writes.get(
|
|
23835
|
+
const pw = writes.get(path56);
|
|
23836
23836
|
const df = now2 - pw.lastChange;
|
|
23837
23837
|
if (df >= threshold) {
|
|
23838
|
-
writes.delete(
|
|
23838
|
+
writes.delete(path56);
|
|
23839
23839
|
awfEmit(void 0, curStat);
|
|
23840
23840
|
} else {
|
|
23841
23841
|
timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval, curStat);
|
|
23842
23842
|
}
|
|
23843
23843
|
});
|
|
23844
23844
|
}
|
|
23845
|
-
if (!writes.has(
|
|
23846
|
-
writes.set(
|
|
23845
|
+
if (!writes.has(path56)) {
|
|
23846
|
+
writes.set(path56, {
|
|
23847
23847
|
lastChange: now,
|
|
23848
23848
|
cancelWait: () => {
|
|
23849
|
-
writes.delete(
|
|
23849
|
+
writes.delete(path56);
|
|
23850
23850
|
clearTimeout(timeoutHandler);
|
|
23851
23851
|
return event;
|
|
23852
23852
|
}
|
|
@@ -23857,8 +23857,8 @@ var init_chokidar = __esm({
|
|
|
23857
23857
|
/**
|
|
23858
23858
|
* Determines whether user has asked to ignore this path.
|
|
23859
23859
|
*/
|
|
23860
|
-
_isIgnored(
|
|
23861
|
-
if (this.options.atomic && DOT_RE.test(
|
|
23860
|
+
_isIgnored(path56, stats2) {
|
|
23861
|
+
if (this.options.atomic && DOT_RE.test(path56))
|
|
23862
23862
|
return true;
|
|
23863
23863
|
if (!this._userIgnored) {
|
|
23864
23864
|
const { cwd } = this.options;
|
|
@@ -23868,17 +23868,17 @@ var init_chokidar = __esm({
|
|
|
23868
23868
|
const list2 = [...ignoredPaths.map(normalizeIgnored(cwd)), ...ignored];
|
|
23869
23869
|
this._userIgnored = anymatch(list2, void 0);
|
|
23870
23870
|
}
|
|
23871
|
-
return this._userIgnored(
|
|
23871
|
+
return this._userIgnored(path56, stats2);
|
|
23872
23872
|
}
|
|
23873
|
-
_isntIgnored(
|
|
23874
|
-
return !this._isIgnored(
|
|
23873
|
+
_isntIgnored(path56, stat8) {
|
|
23874
|
+
return !this._isIgnored(path56, stat8);
|
|
23875
23875
|
}
|
|
23876
23876
|
/**
|
|
23877
23877
|
* Provides a set of common helpers and properties relating to symlink handling.
|
|
23878
23878
|
* @param path file or directory pattern being watched
|
|
23879
23879
|
*/
|
|
23880
|
-
_getWatchHelpers(
|
|
23881
|
-
return new WatchHelper(
|
|
23880
|
+
_getWatchHelpers(path56) {
|
|
23881
|
+
return new WatchHelper(path56, this.options.followSymlinks, this);
|
|
23882
23882
|
}
|
|
23883
23883
|
// Directory helpers
|
|
23884
23884
|
// -----------------
|
|
@@ -23910,63 +23910,63 @@ var init_chokidar = __esm({
|
|
|
23910
23910
|
* @param item base path of item/directory
|
|
23911
23911
|
*/
|
|
23912
23912
|
_remove(directory, item, isDirectory) {
|
|
23913
|
-
const
|
|
23914
|
-
const fullPath = sp2.resolve(
|
|
23915
|
-
isDirectory = isDirectory != null ? isDirectory : this._watched.has(
|
|
23916
|
-
if (!this._throttle("remove",
|
|
23913
|
+
const path56 = sp2.join(directory, item);
|
|
23914
|
+
const fullPath = sp2.resolve(path56);
|
|
23915
|
+
isDirectory = isDirectory != null ? isDirectory : this._watched.has(path56) || this._watched.has(fullPath);
|
|
23916
|
+
if (!this._throttle("remove", path56, 100))
|
|
23917
23917
|
return;
|
|
23918
23918
|
if (!isDirectory && this._watched.size === 1) {
|
|
23919
23919
|
this.add(directory, item, true);
|
|
23920
23920
|
}
|
|
23921
|
-
const wp = this._getWatchedDir(
|
|
23921
|
+
const wp = this._getWatchedDir(path56);
|
|
23922
23922
|
const nestedDirectoryChildren = wp.getChildren();
|
|
23923
|
-
nestedDirectoryChildren.forEach((nested) => this._remove(
|
|
23923
|
+
nestedDirectoryChildren.forEach((nested) => this._remove(path56, nested));
|
|
23924
23924
|
const parent = this._getWatchedDir(directory);
|
|
23925
23925
|
const wasTracked = parent.has(item);
|
|
23926
23926
|
parent.remove(item);
|
|
23927
23927
|
if (this._symlinkPaths.has(fullPath)) {
|
|
23928
23928
|
this._symlinkPaths.delete(fullPath);
|
|
23929
23929
|
}
|
|
23930
|
-
let relPath =
|
|
23930
|
+
let relPath = path56;
|
|
23931
23931
|
if (this.options.cwd)
|
|
23932
|
-
relPath = sp2.relative(this.options.cwd,
|
|
23932
|
+
relPath = sp2.relative(this.options.cwd, path56);
|
|
23933
23933
|
if (this.options.awaitWriteFinish && this._pendingWrites.has(relPath)) {
|
|
23934
23934
|
const event = this._pendingWrites.get(relPath).cancelWait();
|
|
23935
23935
|
if (event === EVENTS.ADD)
|
|
23936
23936
|
return;
|
|
23937
23937
|
}
|
|
23938
|
-
this._watched.delete(
|
|
23938
|
+
this._watched.delete(path56);
|
|
23939
23939
|
this._watched.delete(fullPath);
|
|
23940
23940
|
const eventName = isDirectory ? EVENTS.UNLINK_DIR : EVENTS.UNLINK;
|
|
23941
|
-
if (wasTracked && !this._isIgnored(
|
|
23942
|
-
this._emit(eventName,
|
|
23943
|
-
this._closePath(
|
|
23941
|
+
if (wasTracked && !this._isIgnored(path56))
|
|
23942
|
+
this._emit(eventName, path56);
|
|
23943
|
+
this._closePath(path56);
|
|
23944
23944
|
}
|
|
23945
23945
|
/**
|
|
23946
23946
|
* Closes all watchers for a path
|
|
23947
23947
|
*/
|
|
23948
|
-
_closePath(
|
|
23949
|
-
this._closeFile(
|
|
23950
|
-
const dir = sp2.dirname(
|
|
23951
|
-
this._getWatchedDir(dir).remove(sp2.basename(
|
|
23948
|
+
_closePath(path56) {
|
|
23949
|
+
this._closeFile(path56);
|
|
23950
|
+
const dir = sp2.dirname(path56);
|
|
23951
|
+
this._getWatchedDir(dir).remove(sp2.basename(path56));
|
|
23952
23952
|
}
|
|
23953
23953
|
/**
|
|
23954
23954
|
* Closes only file-specific watchers
|
|
23955
23955
|
*/
|
|
23956
|
-
_closeFile(
|
|
23957
|
-
const closers = this._closers.get(
|
|
23956
|
+
_closeFile(path56) {
|
|
23957
|
+
const closers = this._closers.get(path56);
|
|
23958
23958
|
if (!closers)
|
|
23959
23959
|
return;
|
|
23960
23960
|
closers.forEach((closer) => closer());
|
|
23961
|
-
this._closers.delete(
|
|
23961
|
+
this._closers.delete(path56);
|
|
23962
23962
|
}
|
|
23963
|
-
_addPathCloser(
|
|
23963
|
+
_addPathCloser(path56, closer) {
|
|
23964
23964
|
if (!closer)
|
|
23965
23965
|
return;
|
|
23966
|
-
let list2 = this._closers.get(
|
|
23966
|
+
let list2 = this._closers.get(path56);
|
|
23967
23967
|
if (!list2) {
|
|
23968
23968
|
list2 = [];
|
|
23969
|
-
this._closers.set(
|
|
23969
|
+
this._closers.set(path56, list2);
|
|
23970
23970
|
}
|
|
23971
23971
|
list2.push(closer);
|
|
23972
23972
|
}
|
|
@@ -23994,7 +23994,7 @@ var init_chokidar = __esm({
|
|
|
23994
23994
|
|
|
23995
23995
|
// src/memory/tools/memory/manager-atomic-reindex.ts
|
|
23996
23996
|
import { randomUUID as randomUUID9 } from "node:crypto";
|
|
23997
|
-
import
|
|
23997
|
+
import fs49 from "node:fs/promises";
|
|
23998
23998
|
import { setTimeout as sleep6 } from "node:timers/promises";
|
|
23999
23999
|
function isTransientFileError(err) {
|
|
24000
24000
|
return transientFileErrorCodes.has(err.code ?? "");
|
|
@@ -24034,10 +24034,10 @@ async function moveMemoryIndexFiles(sourceBase, targetBase, options = {}) {
|
|
|
24034
24034
|
await renameWithRetry(source, target, resolvedOptions);
|
|
24035
24035
|
}
|
|
24036
24036
|
}
|
|
24037
|
-
async function rmWithRetry(
|
|
24037
|
+
async function rmWithRetry(path56, options) {
|
|
24038
24038
|
for (let attempt = 1; attempt <= options.maxRemoveAttempts; attempt++) {
|
|
24039
24039
|
try {
|
|
24040
|
-
await options.fileOps.rm(
|
|
24040
|
+
await options.fileOps.rm(path56, { force: true });
|
|
24041
24041
|
return;
|
|
24042
24042
|
} catch (err) {
|
|
24043
24043
|
if (err.code === "ENOENT") {
|
|
@@ -24094,8 +24094,8 @@ var init_manager_atomic_reindex = __esm({
|
|
|
24094
24094
|
"src/memory/tools/memory/manager-atomic-reindex.ts"() {
|
|
24095
24095
|
"use strict";
|
|
24096
24096
|
defaultFileOps = {
|
|
24097
|
-
rename:
|
|
24098
|
-
rm:
|
|
24097
|
+
rename: fs49.rename,
|
|
24098
|
+
rm: fs49.rm,
|
|
24099
24099
|
wait: sleep6
|
|
24100
24100
|
};
|
|
24101
24101
|
transientFileErrorCodes = /* @__PURE__ */ new Set(["EBUSY", "EPERM", "EACCES"]);
|
|
@@ -24377,8 +24377,8 @@ var init_watch_settle = __esm({
|
|
|
24377
24377
|
// src/memory/tools/memory/manager-sync-ops.ts
|
|
24378
24378
|
import { randomUUID as randomUUID10 } from "node:crypto";
|
|
24379
24379
|
import fsSync3 from "node:fs";
|
|
24380
|
-
import
|
|
24381
|
-
import
|
|
24380
|
+
import fs50 from "node:fs/promises";
|
|
24381
|
+
import path52 from "node:path";
|
|
24382
24382
|
function isSyncDisabled(cfg) {
|
|
24383
24383
|
try {
|
|
24384
24384
|
const searchCfg = cfg?.agents?.defaults?.memorySearch;
|
|
@@ -24397,8 +24397,8 @@ function resolveMemoryWatchFactory() {
|
|
|
24397
24397
|
return chokidar_default.watch.bind(chokidar_default);
|
|
24398
24398
|
}
|
|
24399
24399
|
function shouldIgnoreMemoryWatchPath(watchPath, stats2, multimodalSettings) {
|
|
24400
|
-
const normalized =
|
|
24401
|
-
const parts = normalized.split(
|
|
24400
|
+
const normalized = path52.normalize(watchPath);
|
|
24401
|
+
const parts = normalized.split(path52.sep).map((segment) => normalizeLowercaseStringOrEmpty(segment));
|
|
24402
24402
|
if (parts.some((segment) => IGNORED_MEMORY_WATCH_DIR_NAMES.has(segment))) {
|
|
24403
24403
|
return true;
|
|
24404
24404
|
}
|
|
@@ -24408,7 +24408,7 @@ function shouldIgnoreMemoryWatchPath(watchPath, stats2, multimodalSettings) {
|
|
|
24408
24408
|
if (!stats2) {
|
|
24409
24409
|
return false;
|
|
24410
24410
|
}
|
|
24411
|
-
const extension = normalizeLowercaseStringOrEmpty(
|
|
24411
|
+
const extension = normalizeLowercaseStringOrEmpty(path52.extname(normalized));
|
|
24412
24412
|
if (extension.length === 0 || extension === ".md") {
|
|
24413
24413
|
return false;
|
|
24414
24414
|
}
|
|
@@ -24673,8 +24673,8 @@ var init_manager_sync_ops = __esm({
|
|
|
24673
24673
|
return;
|
|
24674
24674
|
}
|
|
24675
24675
|
const watchPaths = /* @__PURE__ */ new Set([
|
|
24676
|
-
|
|
24677
|
-
|
|
24676
|
+
path52.join(this.workspaceDir, "MEMORY.md"),
|
|
24677
|
+
path52.join(this.workspaceDir, "memory")
|
|
24678
24678
|
]);
|
|
24679
24679
|
const additionalPaths = normalizeExtraMemoryPaths(this.workspaceDir, this.settings.extraPaths);
|
|
24680
24680
|
for (const entry of additionalPaths) {
|
|
@@ -24765,7 +24765,7 @@ var init_manager_sync_ops = __esm({
|
|
|
24765
24765
|
const fileStates = (await runWithConcurrency(
|
|
24766
24766
|
files.map((file) => async () => {
|
|
24767
24767
|
try {
|
|
24768
|
-
const stat8 = await
|
|
24768
|
+
const stat8 = await fs50.stat(file);
|
|
24769
24769
|
if (!stat8.isFile()) {
|
|
24770
24770
|
return null;
|
|
24771
24771
|
}
|
|
@@ -24824,7 +24824,7 @@ var init_manager_sync_ops = __esm({
|
|
|
24824
24824
|
this.sessionPendingFiles.clear();
|
|
24825
24825
|
let shouldSync = false;
|
|
24826
24826
|
for (const sessionFile of pending2) {
|
|
24827
|
-
const baseName =
|
|
24827
|
+
const baseName = path52.basename(sessionFile);
|
|
24828
24828
|
if (isSessionArchiveArtifactName(baseName) && isUsageCountedSessionTranscriptFileName(baseName)) {
|
|
24829
24829
|
this.sessionsDirtyFiles.add(sessionFile);
|
|
24830
24830
|
this.sessionsDirty = true;
|
|
@@ -24861,7 +24861,7 @@ var init_manager_sync_ops = __esm({
|
|
|
24861
24861
|
}
|
|
24862
24862
|
let stat8;
|
|
24863
24863
|
try {
|
|
24864
|
-
stat8 = await
|
|
24864
|
+
stat8 = await fs50.stat(sessionFile);
|
|
24865
24865
|
} catch {
|
|
24866
24866
|
return null;
|
|
24867
24867
|
}
|
|
@@ -24909,7 +24909,7 @@ var init_manager_sync_ops = __esm({
|
|
|
24909
24909
|
}
|
|
24910
24910
|
let handle;
|
|
24911
24911
|
try {
|
|
24912
|
-
handle = await
|
|
24912
|
+
handle = await fs50.open(absPath, "r");
|
|
24913
24913
|
} catch (err) {
|
|
24914
24914
|
if (isFileMissingError(err)) {
|
|
24915
24915
|
return 0;
|
|
@@ -24952,9 +24952,9 @@ var init_manager_sync_ops = __esm({
|
|
|
24952
24952
|
return false;
|
|
24953
24953
|
}
|
|
24954
24954
|
const sessionsDir = resolveSessionTranscriptsDirForAgent({ agentId: this.agentId });
|
|
24955
|
-
const resolvedFile =
|
|
24956
|
-
const resolvedDir =
|
|
24957
|
-
return resolvedFile.startsWith(`${resolvedDir}${
|
|
24955
|
+
const resolvedFile = path52.resolve(sessionFile);
|
|
24956
|
+
const resolvedDir = path52.resolve(sessionsDir);
|
|
24957
|
+
return resolvedFile.startsWith(`${resolvedDir}${path52.sep}`);
|
|
24958
24958
|
}
|
|
24959
24959
|
normalizeTargetSessionFiles(sessionFiles) {
|
|
24960
24960
|
if (!sessionFiles || sessionFiles.length === 0) {
|
|
@@ -24966,7 +24966,7 @@ var init_manager_sync_ops = __esm({
|
|
|
24966
24966
|
if (!trimmed) {
|
|
24967
24967
|
continue;
|
|
24968
24968
|
}
|
|
24969
|
-
const resolved =
|
|
24969
|
+
const resolved = path52.resolve(trimmed);
|
|
24970
24970
|
if (this.isSessionFileForAgent(resolved)) {
|
|
24971
24971
|
normalized.add(resolved);
|
|
24972
24972
|
}
|
|
@@ -25613,7 +25613,7 @@ var init_manager_vector_write = __esm({
|
|
|
25613
25613
|
});
|
|
25614
25614
|
|
|
25615
25615
|
// src/memory/tools/memory/manager-embedding-ops.ts
|
|
25616
|
-
import
|
|
25616
|
+
import fs51 from "node:fs/promises";
|
|
25617
25617
|
function resolveEmbeddingTimeoutMs(params) {
|
|
25618
25618
|
if (params.kind === "query") {
|
|
25619
25619
|
const runtimeTimeoutMs2 = params.providerRuntime?.inlineQueryTimeoutMs;
|
|
@@ -26154,7 +26154,7 @@ var init_manager_embedding_ops = __esm({
|
|
|
26154
26154
|
if ("kind" in entry && entry.kind === "multimodal") {
|
|
26155
26155
|
return;
|
|
26156
26156
|
}
|
|
26157
|
-
const content = options.content ?? await
|
|
26157
|
+
const content = options.content ?? await fs51.readFile(entry.absPath, "utf-8");
|
|
26158
26158
|
const chunks2 = filterNonEmptyMemoryChunks(chunkMarkdown(content, this.settings.chunking));
|
|
26159
26159
|
if (options.source === "sessions" && "lineMap" in entry) {
|
|
26160
26160
|
remapChunkLines(chunks2, entry.lineMap);
|
|
@@ -26183,7 +26183,7 @@ var init_manager_embedding_ops = __esm({
|
|
|
26183
26183
|
structuredInputBytes = multimodalChunk.structuredInputBytes;
|
|
26184
26184
|
chunks = [multimodalChunk.chunk];
|
|
26185
26185
|
} else {
|
|
26186
|
-
const content = options.content ?? await
|
|
26186
|
+
const content = options.content ?? await fs51.readFile(entry.absPath, "utf-8");
|
|
26187
26187
|
const baseChunks = filterNonEmptyMemoryChunks(chunkMarkdown(content, this.settings.chunking));
|
|
26188
26188
|
chunks = this.provider ? enforceEmbeddingMaxInputTokens(this.provider, baseChunks, EMBEDDING_BATCH_MAX_TOKENS) : baseChunks;
|
|
26189
26189
|
if (options.source === "sessions" && "lineMap" in entry) {
|
|
@@ -27466,7 +27466,7 @@ var init_qmd_manager = __esm({
|
|
|
27466
27466
|
});
|
|
27467
27467
|
|
|
27468
27468
|
// src/memory/tools/memory/search-manager.ts
|
|
27469
|
-
import
|
|
27469
|
+
import fs52 from "node:fs/promises";
|
|
27470
27470
|
function createMemorySearchManagerCacheStore() {
|
|
27471
27471
|
return {
|
|
27472
27472
|
qmdManagerCache: /* @__PURE__ */ new Map(),
|
|
@@ -27534,7 +27534,7 @@ async function getMemorySearchManager(params) {
|
|
|
27534
27534
|
const identityKey = buildQmdManagerIdentityKey(normalizedAgentId, qmdResolved, runtimeConfig);
|
|
27535
27535
|
const createPrimaryQmdManager = async (mode) => {
|
|
27536
27536
|
try {
|
|
27537
|
-
await
|
|
27537
|
+
await fs52.mkdir(workspaceDir, { recursive: true });
|
|
27538
27538
|
} catch (err) {
|
|
27539
27539
|
const message = formatErrorMessage(err);
|
|
27540
27540
|
log5.warn(
|
|
@@ -28397,8 +28397,8 @@ var manager_exports = {};
|
|
|
28397
28397
|
__export(manager_exports, {
|
|
28398
28398
|
McpManager: () => McpManager
|
|
28399
28399
|
});
|
|
28400
|
-
import * as
|
|
28401
|
-
import * as
|
|
28400
|
+
import * as fs53 from "node:fs";
|
|
28401
|
+
import * as path53 from "node:path";
|
|
28402
28402
|
import { Client as Client3 } from "@modelcontextprotocol/sdk/client/index.js";
|
|
28403
28403
|
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
28404
28404
|
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
@@ -28431,12 +28431,12 @@ function convertInputSchema(inputSchema) {
|
|
|
28431
28431
|
}
|
|
28432
28432
|
function persistBinary(base64Data, mimeType, persistId) {
|
|
28433
28433
|
const ext = mimeType?.split("/")[1] || "bin";
|
|
28434
|
-
const dir =
|
|
28435
|
-
|
|
28436
|
-
const filepath =
|
|
28434
|
+
const dir = path53.join(process.env.ENGINE_STATE_DIR || ".engine", "mcp-blobs");
|
|
28435
|
+
fs53.mkdirSync(dir, { recursive: true });
|
|
28436
|
+
const filepath = path53.join(dir, `${persistId}.${ext}`);
|
|
28437
28437
|
try {
|
|
28438
28438
|
const buf = Buffer.from(base64Data, "base64");
|
|
28439
|
-
|
|
28439
|
+
fs53.writeFileSync(filepath, buf);
|
|
28440
28440
|
return { filepath, size: buf.length };
|
|
28441
28441
|
} catch (err) {
|
|
28442
28442
|
return { error: err.message };
|
|
@@ -28770,7 +28770,7 @@ __export(resources_exports, {
|
|
|
28770
28770
|
registerMcpResourceTools: () => registerMcpResourceTools,
|
|
28771
28771
|
unregisterMcpResourceTools: () => unregisterMcpResourceTools
|
|
28772
28772
|
});
|
|
28773
|
-
import * as
|
|
28773
|
+
import * as path54 from "node:path";
|
|
28774
28774
|
function registerMcpResourceTools(manager) {
|
|
28775
28775
|
mcpManagerRef = manager;
|
|
28776
28776
|
registry.register(listResourcesTool);
|
|
@@ -28788,7 +28788,7 @@ var init_resources = __esm({
|
|
|
28788
28788
|
"use strict";
|
|
28789
28789
|
init_registry();
|
|
28790
28790
|
MAX_RESULT_CHARS2 = 1e5;
|
|
28791
|
-
MEDIA_DIR = process.env.ENGINE_MEDIA_DIR ||
|
|
28791
|
+
MEDIA_DIR = process.env.ENGINE_MEDIA_DIR || path54.join(process.env.ENGINE_STATE_DIR || ".engine", "media", "inbound");
|
|
28792
28792
|
MCP_LIST_RESOURCES_TOOL = "mcp__list_resources";
|
|
28793
28793
|
MCP_READ_RESOURCE_TOOL = "mcp__read_resource";
|
|
28794
28794
|
mcpManagerRef = null;
|
|
@@ -28957,10 +28957,10 @@ function ensureLoaded(workspace, configIds) {
|
|
|
28957
28957
|
if (!state.blockedUserIds.includes(id)) state.blockedUserIds.push(id);
|
|
28958
28958
|
}
|
|
28959
28959
|
}
|
|
28960
|
-
const
|
|
28960
|
+
const path56 = join39(workspace, ".reply-blocklist.json");
|
|
28961
28961
|
try {
|
|
28962
|
-
if (existsSync24(
|
|
28963
|
-
const raw = readFileSync26(
|
|
28962
|
+
if (existsSync24(path56)) {
|
|
28963
|
+
const raw = readFileSync26(path56, "utf-8");
|
|
28964
28964
|
const parsed = JSON.parse(raw);
|
|
28965
28965
|
if (parsed.blockedUserIds) {
|
|
28966
28966
|
for (const id of parsed.blockedUserIds) {
|
|
@@ -28976,9 +28976,9 @@ function ensureLoaded(workspace, configIds) {
|
|
|
28976
28976
|
loaded = true;
|
|
28977
28977
|
}
|
|
28978
28978
|
function save(workspace) {
|
|
28979
|
-
const
|
|
28979
|
+
const path56 = join39(workspace, ".reply-blocklist.json");
|
|
28980
28980
|
try {
|
|
28981
|
-
writeFileSync15(
|
|
28981
|
+
writeFileSync15(path56, JSON.stringify(state, null, 2), "utf-8");
|
|
28982
28982
|
} catch (err) {
|
|
28983
28983
|
console.warn(`[reply-blocklist] Failed to save: ${err.message}`);
|
|
28984
28984
|
}
|
|
@@ -29575,8 +29575,8 @@ var init_cognifold_intent_watcher = __esm({
|
|
|
29575
29575
|
});
|
|
29576
29576
|
|
|
29577
29577
|
// src/engine-startup.ts
|
|
29578
|
-
import * as
|
|
29579
|
-
import * as
|
|
29578
|
+
import * as path55 from "node:path";
|
|
29579
|
+
import * as fs54 from "node:fs";
|
|
29580
29580
|
import { fileURLToPath } from "node:url";
|
|
29581
29581
|
|
|
29582
29582
|
// src/pid-lock.ts
|
|
@@ -30918,13 +30918,13 @@ var DiscordAdapter = class _DiscordAdapter {
|
|
|
30918
30918
|
}
|
|
30919
30919
|
/** 发送媒体附件(图片/文件/音频)— discord.js channel.send({ files }) */
|
|
30920
30920
|
async sendFile(target, message, attachment) {
|
|
30921
|
-
const
|
|
30922
|
-
const
|
|
30923
|
-
if (!
|
|
30921
|
+
const fs55 = await import("node:fs");
|
|
30922
|
+
const path56 = await import("node:path");
|
|
30923
|
+
if (!fs55.existsSync(attachment.path)) {
|
|
30924
30924
|
throw new Error(`File not found: ${attachment.path}`);
|
|
30925
30925
|
}
|
|
30926
|
-
const filename = attachment.filename ||
|
|
30927
|
-
const fileBuffer =
|
|
30926
|
+
const filename = attachment.filename || path56.basename(attachment.path);
|
|
30927
|
+
const fileBuffer = fs55.readFileSync(attachment.path);
|
|
30928
30928
|
const filePayload = {
|
|
30929
30929
|
attachment: fileBuffer,
|
|
30930
30930
|
name: filename
|
|
@@ -31364,13 +31364,13 @@ var FeishuAdapter = class _FeishuAdapter {
|
|
|
31364
31364
|
}
|
|
31365
31365
|
/** 发送媒体附件(图片/文件) */
|
|
31366
31366
|
async sendFile(target, message, attachment) {
|
|
31367
|
-
const
|
|
31368
|
-
const
|
|
31369
|
-
if (!
|
|
31367
|
+
const fs55 = await import("node:fs");
|
|
31368
|
+
const path56 = await import("node:path");
|
|
31369
|
+
if (!fs55.existsSync(attachment.path)) {
|
|
31370
31370
|
throw new Error(`File not found: ${attachment.path}`);
|
|
31371
31371
|
}
|
|
31372
|
-
const filename = attachment.filename ||
|
|
31373
|
-
const fileBuffer =
|
|
31372
|
+
const filename = attachment.filename || path56.basename(attachment.path);
|
|
31373
|
+
const fileBuffer = fs55.readFileSync(attachment.path);
|
|
31374
31374
|
const receiveIdType = target.startsWith("ou_") ? "open_id" : "chat_id";
|
|
31375
31375
|
const mimeType = attachment.mimeType || "application/octet-stream";
|
|
31376
31376
|
if (mimeType.startsWith("image/")) {
|
|
@@ -35360,18 +35360,18 @@ function truncate(s2, maxLen) {
|
|
|
35360
35360
|
}
|
|
35361
35361
|
var externalChanRulesCache = null;
|
|
35362
35362
|
function loadExternalChanRules(workspace) {
|
|
35363
|
-
const
|
|
35364
|
-
if (externalChanRulesCache && externalChanRulesCache.path ===
|
|
35363
|
+
const path56 = join20(workspace, "prompts", "external-chan-rules.md");
|
|
35364
|
+
if (externalChanRulesCache && externalChanRulesCache.path === path56) return externalChanRulesCache;
|
|
35365
35365
|
let content = "";
|
|
35366
|
-
if (existsSync12(
|
|
35366
|
+
if (existsSync12(path56)) {
|
|
35367
35367
|
try {
|
|
35368
|
-
content = readFileSync15(
|
|
35368
|
+
content = readFileSync15(path56, "utf-8").trim();
|
|
35369
35369
|
} catch (e) {
|
|
35370
35370
|
console.warn(`[external-chan-rules] Failed to load: ${e}`);
|
|
35371
35371
|
}
|
|
35372
35372
|
}
|
|
35373
|
-
externalChanRulesCache = { path:
|
|
35374
|
-
console.log(`[external-chan-rules] Loaded ${content.length} chars from ${
|
|
35373
|
+
externalChanRulesCache = { path: path56, content };
|
|
35374
|
+
console.log(`[external-chan-rules] Loaded ${content.length} chars from ${path56}`);
|
|
35375
35375
|
return externalChanRulesCache;
|
|
35376
35376
|
}
|
|
35377
35377
|
function getExternalChanRulesBlock(inboundMeta, workspace) {
|
|
@@ -40151,11 +40151,11 @@ var CogniFoldClient = class {
|
|
|
40151
40151
|
this.baseUrl = baseUrl.replace(/\/$/, "");
|
|
40152
40152
|
this.timeoutMs = timeoutMs;
|
|
40153
40153
|
}
|
|
40154
|
-
async req(
|
|
40154
|
+
async req(path56, options = {}) {
|
|
40155
40155
|
const ctrl = new AbortController();
|
|
40156
40156
|
const timer = setTimeout(() => ctrl.abort(), this.timeoutMs);
|
|
40157
40157
|
try {
|
|
40158
|
-
const resp = await fetch(`${this.baseUrl}${
|
|
40158
|
+
const resp = await fetch(`${this.baseUrl}${path56}`, {
|
|
40159
40159
|
...options,
|
|
40160
40160
|
signal: ctrl.signal,
|
|
40161
40161
|
headers: {
|
|
@@ -40245,8 +40245,8 @@ var CogniFoldClient = class {
|
|
|
40245
40245
|
});
|
|
40246
40246
|
}
|
|
40247
40247
|
/** 兼容老版命名 */
|
|
40248
|
-
async recl(
|
|
40249
|
-
return this.req(
|
|
40248
|
+
async recl(path56, options = {}) {
|
|
40249
|
+
return this.req(path56, options);
|
|
40250
40250
|
}
|
|
40251
40251
|
};
|
|
40252
40252
|
|
|
@@ -40634,25 +40634,375 @@ var CogniFoldPlugin = class {
|
|
|
40634
40634
|
}
|
|
40635
40635
|
};
|
|
40636
40636
|
|
|
40637
|
+
// src/memory/everos/plugin.ts
|
|
40638
|
+
init_BashTool();
|
|
40639
|
+
import { spawn as spawn6 } from "node:child_process";
|
|
40640
|
+
import net3 from "node:net";
|
|
40641
|
+
import path24 from "node:path";
|
|
40642
|
+
import fs24 from "node:fs";
|
|
40643
|
+
|
|
40644
|
+
// src/memory/everos/config.ts
|
|
40645
|
+
var DEFAULTS4 = {
|
|
40646
|
+
everosUrl: "http://127.0.0.1:8100",
|
|
40647
|
+
agenticUrl: "http://127.0.0.1:8101",
|
|
40648
|
+
agenticPort: 8101,
|
|
40649
|
+
autoStart: true,
|
|
40650
|
+
defaultMode: "hybrid_agentic"
|
|
40651
|
+
};
|
|
40652
|
+
function parseEverosConfig(raw) {
|
|
40653
|
+
if (!raw) {
|
|
40654
|
+
return {
|
|
40655
|
+
enabled: false,
|
|
40656
|
+
...DEFAULTS4,
|
|
40657
|
+
userId: "xiaomei",
|
|
40658
|
+
llm: { model: "glm-5.2", apiKey: "", baseUrl: "https://open.bigmodel.cn/api/coding/paas/v4" },
|
|
40659
|
+
rerank: { model: "Qwen/Qwen3-Reranker-4B", apiKey: "", baseUrl: "https://api.deepinfra.com/v1/inference" },
|
|
40660
|
+
lancedbPath: "",
|
|
40661
|
+
sqlitePath: ""
|
|
40662
|
+
};
|
|
40663
|
+
}
|
|
40664
|
+
return {
|
|
40665
|
+
enabled: raw.enabled === true,
|
|
40666
|
+
everosUrl: raw.everosUrl ?? DEFAULTS4.everosUrl,
|
|
40667
|
+
agenticUrl: raw.agenticUrl ?? DEFAULTS4.agenticUrl,
|
|
40668
|
+
agenticPort: raw.agenticPort ?? DEFAULTS4.agenticPort,
|
|
40669
|
+
userId: raw.userId ?? "xiaomei",
|
|
40670
|
+
autoStart: raw.autoStart !== false,
|
|
40671
|
+
defaultMode: raw.defaultMode ?? DEFAULTS4.defaultMode,
|
|
40672
|
+
llm: raw.llm ?? { model: "glm-5.2", apiKey: "", baseUrl: "https://open.bigmodel.cn/api/coding/paas/v4" },
|
|
40673
|
+
rerank: raw.rerank ?? { model: "Qwen/Qwen3-Reranker-4B", apiKey: "", baseUrl: "https://api.deepinfra.com/v1/inference" },
|
|
40674
|
+
lancedbPath: raw.lancedbPath ?? "",
|
|
40675
|
+
sqlitePath: raw.sqlitePath ?? ""
|
|
40676
|
+
};
|
|
40677
|
+
}
|
|
40678
|
+
|
|
40679
|
+
// src/memory/everos/client.ts
|
|
40680
|
+
var EverosSearchClient = class {
|
|
40681
|
+
agenticUrl;
|
|
40682
|
+
everosUrl;
|
|
40683
|
+
timeoutMs;
|
|
40684
|
+
constructor(agenticUrl, everosUrl, timeoutMs = 12e4) {
|
|
40685
|
+
this.agenticUrl = agenticUrl.replace(/\/$/, "");
|
|
40686
|
+
this.everosUrl = (everosUrl || "http://127.0.0.1:8100").replace(/\/$/, "");
|
|
40687
|
+
this.timeoutMs = timeoutMs;
|
|
40688
|
+
}
|
|
40689
|
+
/** Health check for agentic server */
|
|
40690
|
+
async health() {
|
|
40691
|
+
const ctrl = new AbortController();
|
|
40692
|
+
const timer = setTimeout(() => ctrl.abort(), 5e3);
|
|
40693
|
+
try {
|
|
40694
|
+
const resp = await fetch(`${this.agenticUrl}/health`, { signal: ctrl.signal });
|
|
40695
|
+
if (!resp.ok) throw new Error(`health ${resp.status}`);
|
|
40696
|
+
return await resp.json();
|
|
40697
|
+
} finally {
|
|
40698
|
+
clearTimeout(timer);
|
|
40699
|
+
}
|
|
40700
|
+
}
|
|
40701
|
+
/** Health check for EverOS itself */
|
|
40702
|
+
async healthEveros() {
|
|
40703
|
+
const ctrl = new AbortController();
|
|
40704
|
+
const timer = setTimeout(() => ctrl.abort(), 5e3);
|
|
40705
|
+
try {
|
|
40706
|
+
const resp = await fetch(`${this.everosUrl}/health`, { signal: ctrl.signal });
|
|
40707
|
+
if (!resp.ok) throw new Error(`everos health ${resp.status}`);
|
|
40708
|
+
return await resp.json();
|
|
40709
|
+
} finally {
|
|
40710
|
+
clearTimeout(timer);
|
|
40711
|
+
}
|
|
40712
|
+
}
|
|
40713
|
+
/** Search — 3-mode unified endpoint */
|
|
40714
|
+
async search(params) {
|
|
40715
|
+
const ctrl = new AbortController();
|
|
40716
|
+
const timer = setTimeout(() => ctrl.abort(), this.timeoutMs);
|
|
40717
|
+
try {
|
|
40718
|
+
const resp = await fetch(`${this.agenticUrl}/api/v1/search`, {
|
|
40719
|
+
method: "POST",
|
|
40720
|
+
headers: { "Content-Type": "application/json" },
|
|
40721
|
+
body: JSON.stringify({
|
|
40722
|
+
query: params.query,
|
|
40723
|
+
user_id: params.userId || "xiaomei",
|
|
40724
|
+
mode: params.mode || "hybrid_agentic",
|
|
40725
|
+
top_k: params.topK ?? 5,
|
|
40726
|
+
strategy: params.strategy || "multi_query"
|
|
40727
|
+
}),
|
|
40728
|
+
signal: ctrl.signal
|
|
40729
|
+
});
|
|
40730
|
+
if (!resp.ok) {
|
|
40731
|
+
const text = await resp.text();
|
|
40732
|
+
throw new Error(`EverOS search ${resp.status}: ${text.slice(0, 200)}`);
|
|
40733
|
+
}
|
|
40734
|
+
return await resp.json();
|
|
40735
|
+
} finally {
|
|
40736
|
+
clearTimeout(timer);
|
|
40737
|
+
}
|
|
40738
|
+
}
|
|
40739
|
+
/** Quick hybrid-only search (fast path) */
|
|
40740
|
+
async searchFast(query, userId, topK = 5) {
|
|
40741
|
+
return this.search({ query, userId, mode: "hybrid", topK });
|
|
40742
|
+
}
|
|
40743
|
+
/** Full agentic search (deep path) */
|
|
40744
|
+
async searchDeep(query, userId, topK = 5) {
|
|
40745
|
+
return this.search({ query, userId, mode: "agentic", topK });
|
|
40746
|
+
}
|
|
40747
|
+
};
|
|
40748
|
+
|
|
40749
|
+
// src/memory/everos/plugin.ts
|
|
40750
|
+
var EverosPlugin = class {
|
|
40751
|
+
name = "everos";
|
|
40752
|
+
config;
|
|
40753
|
+
client;
|
|
40754
|
+
agenticProcess = null;
|
|
40755
|
+
healthTimer = null;
|
|
40756
|
+
weStartedAgentic = false;
|
|
40757
|
+
// 我们拉起的才管
|
|
40758
|
+
constructor(rawConfig) {
|
|
40759
|
+
this.config = parseEverosConfig(rawConfig);
|
|
40760
|
+
this.client = new EverosSearchClient(this.config.agenticUrl, this.config.everosUrl);
|
|
40761
|
+
}
|
|
40762
|
+
static shouldEnable(config) {
|
|
40763
|
+
return config?.everos?.enabled === true;
|
|
40764
|
+
}
|
|
40765
|
+
async start(ctx) {
|
|
40766
|
+
if (!this.config.enabled) return;
|
|
40767
|
+
try {
|
|
40768
|
+
await this.client.healthEveros();
|
|
40769
|
+
console.log(`[everos] EverOS already running at ${this.config.everosUrl}`);
|
|
40770
|
+
} catch {
|
|
40771
|
+
if (this.config.autoStart) {
|
|
40772
|
+
console.log(`[everos] EverOS not running, starting...`);
|
|
40773
|
+
await this.startEveros();
|
|
40774
|
+
} else {
|
|
40775
|
+
console.warn(`[everos] EverOS not running and autoStart=false`);
|
|
40776
|
+
}
|
|
40777
|
+
}
|
|
40778
|
+
const agenticPort = this.config.agenticPort;
|
|
40779
|
+
const agenticAlive = await this.isPortAlive(agenticPort);
|
|
40780
|
+
if (agenticAlive) {
|
|
40781
|
+
console.log(`[everos] Agentic server already running on port ${agenticPort}`);
|
|
40782
|
+
} else if (this.config.autoStart) {
|
|
40783
|
+
console.log(`[everos] Starting agentic server on port ${agenticPort}...`);
|
|
40784
|
+
this.weStartedAgentic = true;
|
|
40785
|
+
this.agenticProcess = this.startAgenticServer();
|
|
40786
|
+
await this.waitForReady(`${this.config.agenticUrl}/health`, 3e4);
|
|
40787
|
+
}
|
|
40788
|
+
;
|
|
40789
|
+
globalThis.__everosSearchClient = this.client;
|
|
40790
|
+
this.startHealthCheck();
|
|
40791
|
+
}
|
|
40792
|
+
async stop() {
|
|
40793
|
+
if (this.healthTimer) {
|
|
40794
|
+
clearInterval(this.healthTimer);
|
|
40795
|
+
this.healthTimer = null;
|
|
40796
|
+
}
|
|
40797
|
+
if (this.weStartedAgentic && this.agenticProcess) {
|
|
40798
|
+
console.log(`[everos] Stopping agentic server (PID ${this.agenticProcess.pid})`);
|
|
40799
|
+
this.agenticProcess.removeAllListeners();
|
|
40800
|
+
this.agenticProcess.kill("SIGTERM");
|
|
40801
|
+
this.agenticProcess = null;
|
|
40802
|
+
} else {
|
|
40803
|
+
console.log(`[everos] Stop \u2014 agentic server was not started by us, leaving it running`);
|
|
40804
|
+
}
|
|
40805
|
+
}
|
|
40806
|
+
getStatus() {
|
|
40807
|
+
return {
|
|
40808
|
+
everosRunning: true,
|
|
40809
|
+
// simplified
|
|
40810
|
+
agenticRunning: this.agenticProcess !== null,
|
|
40811
|
+
agenticPid: this.agenticProcess?.pid ?? null
|
|
40812
|
+
};
|
|
40813
|
+
}
|
|
40814
|
+
getClient() {
|
|
40815
|
+
return this.client;
|
|
40816
|
+
}
|
|
40817
|
+
// === 私有 ===
|
|
40818
|
+
startHealthCheck() {
|
|
40819
|
+
this.healthTimer = setInterval(async () => {
|
|
40820
|
+
try {
|
|
40821
|
+
await this.client.health();
|
|
40822
|
+
} catch {
|
|
40823
|
+
if (this.weStartedAgentic && !this.agenticProcess) {
|
|
40824
|
+
console.log(`[everos] Agentic server down, attempting restart...`);
|
|
40825
|
+
try {
|
|
40826
|
+
this.agenticProcess = this.startAgenticServer();
|
|
40827
|
+
await this.waitForReady(`${this.config.agenticUrl}/health`, 3e4);
|
|
40828
|
+
console.log(`[everos] Agentic server restarted`);
|
|
40829
|
+
} catch (err) {
|
|
40830
|
+
console.error(`[everos] Restart failed: ${err.message}`);
|
|
40831
|
+
}
|
|
40832
|
+
}
|
|
40833
|
+
}
|
|
40834
|
+
}, 3e5);
|
|
40835
|
+
}
|
|
40836
|
+
async startEveros() {
|
|
40837
|
+
const pythonDir = path24.dirname(this.config.lancedbPath);
|
|
40838
|
+
const configPath = path24.join(pythonDir, "config.toml");
|
|
40839
|
+
await this.ensureFcntlCompat();
|
|
40840
|
+
const venvPython = this.findVenvPython();
|
|
40841
|
+
const args = ["server", "start"];
|
|
40842
|
+
const cmd = `${venvPython} ${args.join(" ")}`;
|
|
40843
|
+
console.log(`[everos] Starting EverOS: ${cmd}`);
|
|
40844
|
+
if (process.platform === "win32") {
|
|
40845
|
+
const { shell, args: shellArgs } = findShell();
|
|
40846
|
+
spawn6(shell, [...shellArgs, cmd], {
|
|
40847
|
+
cwd: pythonDir,
|
|
40848
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
40849
|
+
env: { ...process.env, PYTHONUNBUFFERED: "1" }
|
|
40850
|
+
});
|
|
40851
|
+
} else {
|
|
40852
|
+
spawn6(venvPython, args, {
|
|
40853
|
+
cwd: pythonDir,
|
|
40854
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
40855
|
+
env: { ...process.env, PYTHONUNBUFFERED: "1" }
|
|
40856
|
+
});
|
|
40857
|
+
}
|
|
40858
|
+
await this.waitForReady(`${this.config.everosUrl}/health`, 3e4);
|
|
40859
|
+
}
|
|
40860
|
+
startAgenticServer() {
|
|
40861
|
+
const pythonDir = this.getPythonDir();
|
|
40862
|
+
const port = String(this.config.agenticPort);
|
|
40863
|
+
const venvPython = this.findVenvPython();
|
|
40864
|
+
const args = ["agentic_server.py", "--port", port];
|
|
40865
|
+
const cmd = `${venvPython} ${args.join(" ")}`;
|
|
40866
|
+
console.log(`[everos] Starting agentic server: ${cmd}`);
|
|
40867
|
+
console.log(`[everos] Python dir: ${pythonDir}`);
|
|
40868
|
+
const childEnv = {
|
|
40869
|
+
...process.env,
|
|
40870
|
+
PYTHONUNBUFFERED: "1",
|
|
40871
|
+
EVEROS_URL: this.config.everosUrl,
|
|
40872
|
+
LLM_MODEL: this.config.llm.model,
|
|
40873
|
+
LLM_API_KEY: this.config.llm.apiKey,
|
|
40874
|
+
LLM_BASE_URL: this.config.llm.baseUrl,
|
|
40875
|
+
RERANK_API_KEY: this.config.rerank.apiKey,
|
|
40876
|
+
RERANK_URL: `${this.config.rerank.baseUrl}/${this.config.rerank.model}`,
|
|
40877
|
+
LANCEDB_PATH: this.config.lancedbPath,
|
|
40878
|
+
SQLITE_PATH: this.config.sqlitePath,
|
|
40879
|
+
EVEROS_USER_ID: this.config.userId
|
|
40880
|
+
};
|
|
40881
|
+
let child;
|
|
40882
|
+
if (process.platform === "win32") {
|
|
40883
|
+
const { shell, args: shellArgs } = findShell();
|
|
40884
|
+
child = spawn6(shell, [...shellArgs, cmd], {
|
|
40885
|
+
cwd: pythonDir,
|
|
40886
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
40887
|
+
env: childEnv
|
|
40888
|
+
});
|
|
40889
|
+
} else {
|
|
40890
|
+
child = spawn6(venvPython, args, {
|
|
40891
|
+
cwd: pythonDir,
|
|
40892
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
40893
|
+
env: childEnv
|
|
40894
|
+
});
|
|
40895
|
+
}
|
|
40896
|
+
child.on("error", (err) => {
|
|
40897
|
+
console.error(`[everos] spawn error: ${err.message}`);
|
|
40898
|
+
});
|
|
40899
|
+
child.stdout?.on("data", (data) => {
|
|
40900
|
+
const lines = data.toString().trim().split("\n");
|
|
40901
|
+
for (const line of lines) console.log(`[everos:py] ${line}`);
|
|
40902
|
+
});
|
|
40903
|
+
child.stderr?.on("data", (data) => {
|
|
40904
|
+
const lines = data.toString().trim().split("\n");
|
|
40905
|
+
for (const line of lines) console.error(`[everos:py] ${line}`);
|
|
40906
|
+
});
|
|
40907
|
+
child.on("exit", (code, signal) => {
|
|
40908
|
+
console.log(`[everos] Agentic server exited (code=${code}, signal=${signal})`);
|
|
40909
|
+
this.agenticProcess = null;
|
|
40910
|
+
});
|
|
40911
|
+
return child;
|
|
40912
|
+
}
|
|
40913
|
+
findVenvPython() {
|
|
40914
|
+
const stateDir = process.env.OPENCLAW_STATE_DIR || path24.join(process.env.HOME || process.env.USERPROFILE || ".", ".openclaw");
|
|
40915
|
+
if (process.platform === "win32") {
|
|
40916
|
+
return path24.join(stateDir, "everos-venv", "Scripts", "python.exe");
|
|
40917
|
+
}
|
|
40918
|
+
return path24.join(stateDir, "everos-venv", "bin", "python");
|
|
40919
|
+
}
|
|
40920
|
+
getPythonDir() {
|
|
40921
|
+
const dir = import.meta.dirname;
|
|
40922
|
+
const candidates = [
|
|
40923
|
+
path24.join(dir, "python"),
|
|
40924
|
+
path24.resolve(dir, "..", "src", "memory", "everos", "python"),
|
|
40925
|
+
path24.resolve(dir, "..", "..", "..", "src", "memory", "everos", "python")
|
|
40926
|
+
];
|
|
40927
|
+
for (const candidate of candidates) {
|
|
40928
|
+
if (fs24.existsSync(path24.join(candidate, "agentic_server.py"))) {
|
|
40929
|
+
return candidate;
|
|
40930
|
+
}
|
|
40931
|
+
}
|
|
40932
|
+
return candidates[0];
|
|
40933
|
+
}
|
|
40934
|
+
async ensureFcntlCompat() {
|
|
40935
|
+
if (process.platform !== "win32") return;
|
|
40936
|
+
const venvPython = this.findVenvPython();
|
|
40937
|
+
const venvDir = path24.dirname(path24.dirname(venvPython));
|
|
40938
|
+
const sitePackages = path24.join(venvDir, "Lib", "site-packages");
|
|
40939
|
+
const target = path24.join(sitePackages, "fcntl.py");
|
|
40940
|
+
if (fs24.existsSync(target)) return;
|
|
40941
|
+
const source = path24.join(this.getPythonDir(), "fcntl_compat.py");
|
|
40942
|
+
if (fs24.existsSync(source)) {
|
|
40943
|
+
try {
|
|
40944
|
+
fs24.copyFileSync(source, target);
|
|
40945
|
+
console.log(`[everos] Installed fcntl compat shim to ${target}`);
|
|
40946
|
+
} catch (err) {
|
|
40947
|
+
console.warn(`[everos] Failed to install fcntl shim: ${err.message}`);
|
|
40948
|
+
}
|
|
40949
|
+
}
|
|
40950
|
+
}
|
|
40951
|
+
async waitForReady(url, timeoutMs) {
|
|
40952
|
+
const start = Date.now();
|
|
40953
|
+
while (Date.now() - start < timeoutMs) {
|
|
40954
|
+
try {
|
|
40955
|
+
const resp = await fetch(url);
|
|
40956
|
+
if (resp.ok) {
|
|
40957
|
+
console.log(`[everos] Service ready at ${url} (${Date.now() - start}ms)`);
|
|
40958
|
+
return;
|
|
40959
|
+
}
|
|
40960
|
+
} catch {
|
|
40961
|
+
}
|
|
40962
|
+
await new Promise((r) => setTimeout(r, 500));
|
|
40963
|
+
}
|
|
40964
|
+
throw new Error(`EverOS service not ready after ${timeoutMs}ms at ${url}`);
|
|
40965
|
+
}
|
|
40966
|
+
async isPortAlive(port) {
|
|
40967
|
+
return new Promise((resolve12) => {
|
|
40968
|
+
const socket = new net3.Socket();
|
|
40969
|
+
socket.setTimeout(2e3);
|
|
40970
|
+
socket.on("connect", () => {
|
|
40971
|
+
socket.destroy();
|
|
40972
|
+
resolve12(true);
|
|
40973
|
+
});
|
|
40974
|
+
socket.on("timeout", () => {
|
|
40975
|
+
socket.destroy();
|
|
40976
|
+
resolve12(false);
|
|
40977
|
+
});
|
|
40978
|
+
socket.on("error", () => {
|
|
40979
|
+
socket.destroy();
|
|
40980
|
+
resolve12(false);
|
|
40981
|
+
});
|
|
40982
|
+
socket.connect(port, "127.0.0.1");
|
|
40983
|
+
});
|
|
40984
|
+
}
|
|
40985
|
+
};
|
|
40986
|
+
|
|
40637
40987
|
// src/engine-startup.ts
|
|
40638
40988
|
init_task_manager();
|
|
40639
40989
|
|
|
40640
40990
|
// src/skills/scanner.ts
|
|
40641
|
-
import * as
|
|
40642
|
-
import * as
|
|
40991
|
+
import * as path25 from "node:path";
|
|
40992
|
+
import * as fs25 from "node:fs";
|
|
40643
40993
|
function scanSkills(skillsDir) {
|
|
40644
|
-
if (!
|
|
40994
|
+
if (!fs25.existsSync(skillsDir)) {
|
|
40645
40995
|
console.log(`[skills] Directory not found: ${skillsDir}`);
|
|
40646
40996
|
return [];
|
|
40647
40997
|
}
|
|
40648
|
-
const entries =
|
|
40998
|
+
const entries = fs25.readdirSync(skillsDir, { withFileTypes: true });
|
|
40649
40999
|
const skills = [];
|
|
40650
41000
|
for (const entry of entries) {
|
|
40651
41001
|
if (!entry.isDirectory()) continue;
|
|
40652
|
-
const skillMdPath =
|
|
40653
|
-
if (!
|
|
41002
|
+
const skillMdPath = path25.join(skillsDir, entry.name, "SKILL.md");
|
|
41003
|
+
if (!fs25.existsSync(skillMdPath)) continue;
|
|
40654
41004
|
try {
|
|
40655
|
-
const content =
|
|
41005
|
+
const content = fs25.readFileSync(skillMdPath, "utf-8");
|
|
40656
41006
|
const frontmatter = parseFrontmatter2(content);
|
|
40657
41007
|
if (!frontmatter.name) {
|
|
40658
41008
|
console.warn(`[skills] Skipping ${entry.name}/SKILL.md: missing 'name' in frontmatter`);
|
|
@@ -40716,8 +41066,8 @@ function parseFrontmatter2(content) {
|
|
|
40716
41066
|
|
|
40717
41067
|
// src/tools/SkillTool/SkillTool.ts
|
|
40718
41068
|
init_registry();
|
|
40719
|
-
import * as
|
|
40720
|
-
import * as
|
|
41069
|
+
import * as fs26 from "node:fs";
|
|
41070
|
+
import * as path26 from "node:path";
|
|
40721
41071
|
|
|
40722
41072
|
// src/tools/SkillTool/constants.ts
|
|
40723
41073
|
var SKILL_TOOL_NAME2 = "Skill";
|
|
@@ -40794,12 +41144,12 @@ Important:
|
|
|
40794
41144
|
`;
|
|
40795
41145
|
}
|
|
40796
41146
|
function loadSkillContent(skillName) {
|
|
40797
|
-
const skillMdPath =
|
|
40798
|
-
if (!
|
|
40799
|
-
const content =
|
|
41147
|
+
const skillMdPath = path26.join(skillsDirPath, skillName, "SKILL.md");
|
|
41148
|
+
if (!fs26.existsSync(skillMdPath)) return null;
|
|
41149
|
+
const content = fs26.readFileSync(skillMdPath, "utf-8");
|
|
40800
41150
|
const bodyMatch = content.match(/^---\s*\n[\s\S]*?\n---\s*\n([\s\S]*)/);
|
|
40801
41151
|
const body = bodyMatch ? bodyMatch[1] : content;
|
|
40802
|
-
const skillDir =
|
|
41152
|
+
const skillDir = path26.dirname(skillMdPath);
|
|
40803
41153
|
const normalizedDir = process.platform === "win32" ? skillDir.replace(/\\/g, "/") : skillDir;
|
|
40804
41154
|
let finalContent = `Base directory for this skill: ${normalizedDir}
|
|
40805
41155
|
|
|
@@ -41073,12 +41423,12 @@ Examples:
|
|
|
41073
41423
|
// src/tools/msg-husband.ts
|
|
41074
41424
|
init_registry();
|
|
41075
41425
|
init_live();
|
|
41076
|
-
import
|
|
41077
|
-
import
|
|
41426
|
+
import fs27 from "node:fs";
|
|
41427
|
+
import path27 from "node:path";
|
|
41078
41428
|
function getHusbandFeishuId(workspace) {
|
|
41079
|
-
const contactsPath =
|
|
41429
|
+
const contactsPath = path27.join(workspace, "prompts", "contacts.md");
|
|
41080
41430
|
try {
|
|
41081
|
-
const text =
|
|
41431
|
+
const text = fs27.readFileSync(contactsPath, "utf-8");
|
|
41082
41432
|
const m2 = text.match(/\|\s*翀哥\s*\|\s*(ou_[a-f0-9]+)\s*\|/);
|
|
41083
41433
|
return m2 ? m2[1] : null;
|
|
41084
41434
|
} catch {
|
|
@@ -41220,8 +41570,8 @@ Examples:
|
|
|
41220
41570
|
if (!to && !resolvedChannelId) {
|
|
41221
41571
|
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 };
|
|
41222
41572
|
}
|
|
41223
|
-
const
|
|
41224
|
-
if (!
|
|
41573
|
+
const fs55 = await import("node:fs");
|
|
41574
|
+
if (!fs55.existsSync(filePath)) {
|
|
41225
41575
|
return { content: `\u53D1\u9001\u5931\u8D25: \u6587\u4EF6\u4E0D\u5B58\u5728 ${filePath}`, isError: true };
|
|
41226
41576
|
}
|
|
41227
41577
|
const toIds = to ? to.split(",").map((s2) => s2.trim()).filter(Boolean) : [];
|
|
@@ -41249,7 +41599,7 @@ Examples:
|
|
|
41249
41599
|
md: "text/markdown"
|
|
41250
41600
|
};
|
|
41251
41601
|
const mimeType = mimeTypeMap[ext] || "application/octet-stream";
|
|
41252
|
-
const stat8 =
|
|
41602
|
+
const stat8 = fs55.statSync(filePath);
|
|
41253
41603
|
const sizeMB = stat8.size / 1024 / 1024;
|
|
41254
41604
|
if (sizeMB > 25) {
|
|
41255
41605
|
return { content: `\u53D1\u9001\u5931\u8D25: \u6587\u4EF6 ${sizeMB.toFixed(1)}MB \u8D85\u8FC7 Discord 25MB \u9650\u5236`, isError: true };
|
|
@@ -41278,8 +41628,8 @@ Examples:
|
|
|
41278
41628
|
// src/tools/my-eyes.ts
|
|
41279
41629
|
init_live();
|
|
41280
41630
|
init_registry();
|
|
41281
|
-
import * as
|
|
41282
|
-
import * as
|
|
41631
|
+
import * as fs28 from "node:fs";
|
|
41632
|
+
import * as path28 from "node:path";
|
|
41283
41633
|
var MIME_MAP = {
|
|
41284
41634
|
".jpg": "jpeg",
|
|
41285
41635
|
".jpeg": "jpeg",
|
|
@@ -41289,9 +41639,9 @@ var MIME_MAP = {
|
|
|
41289
41639
|
".bmp": "bmp"
|
|
41290
41640
|
};
|
|
41291
41641
|
function resolveLatestImage(specifiedPath, mediaDir) {
|
|
41292
|
-
if (specifiedPath &&
|
|
41293
|
-
if (!
|
|
41294
|
-
const files =
|
|
41642
|
+
if (specifiedPath && fs28.existsSync(specifiedPath)) return specifiedPath;
|
|
41643
|
+
if (!fs28.existsSync(mediaDir)) return null;
|
|
41644
|
+
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);
|
|
41295
41645
|
return files[0]?.p || null;
|
|
41296
41646
|
}
|
|
41297
41647
|
registry.register({
|
|
@@ -41315,15 +41665,15 @@ registry.register({
|
|
|
41315
41665
|
if (!provider?.streamChat) {
|
|
41316
41666
|
return { content: "Error: provider \u4E0D\u53EF\u7528\u3002", isError: true };
|
|
41317
41667
|
}
|
|
41318
|
-
const mediaDir =
|
|
41668
|
+
const mediaDir = path28.join(ctx.stateDir, "media", "inbound");
|
|
41319
41669
|
const imagePath = resolveLatestImage(args.image_path, mediaDir);
|
|
41320
41670
|
if (!imagePath) {
|
|
41321
41671
|
return { content: "Error: no image found. Provide image_path or ensure media/inbound has images.", isError: true };
|
|
41322
41672
|
}
|
|
41323
41673
|
const rawPrompt = args.prompt?.trim() || "\u63CF\u8FF0\u8FD9\u5F20\u56FE\u7247\u7684\u5185\u5BB9";
|
|
41324
|
-
const ext =
|
|
41674
|
+
const ext = path28.extname(imagePath).toLowerCase();
|
|
41325
41675
|
const mime = MIME_MAP[ext] || "jpeg";
|
|
41326
|
-
const imgB64 =
|
|
41676
|
+
const imgB64 = fs28.readFileSync(imagePath).toString("base64");
|
|
41327
41677
|
const userMsg = {
|
|
41328
41678
|
role: "user",
|
|
41329
41679
|
content: [
|
|
@@ -41360,14 +41710,14 @@ init_live();
|
|
|
41360
41710
|
init_registry();
|
|
41361
41711
|
import { execFile } from "node:child_process";
|
|
41362
41712
|
import { promisify } from "node:util";
|
|
41363
|
-
import * as
|
|
41364
|
-
import * as
|
|
41713
|
+
import * as fs29 from "node:fs";
|
|
41714
|
+
import * as path29 from "node:path";
|
|
41365
41715
|
import * as os3 from "node:os";
|
|
41366
41716
|
var execFileAsync = promisify(execFile);
|
|
41367
|
-
var VOICE_DIR =
|
|
41717
|
+
var VOICE_DIR = path29.join(os3.tmpdir(), "engine-voice");
|
|
41368
41718
|
async function ttsCosyvoice(text, apiKey, model, voice, workspaceId) {
|
|
41369
|
-
|
|
41370
|
-
const output =
|
|
41719
|
+
fs29.mkdirSync(VOICE_DIR, { recursive: true });
|
|
41720
|
+
const output = path29.join(VOICE_DIR, `tts_${Date.now()}.wav`);
|
|
41371
41721
|
const script = `
|
|
41372
41722
|
import sys, json, wave, time, threading
|
|
41373
41723
|
import dashscope
|
|
@@ -41421,7 +41771,7 @@ print(f"OK: {len(pcm)} bytes")
|
|
|
41421
41771
|
`;
|
|
41422
41772
|
const configJson = JSON.stringify({ apiKey, model, voice, workspaceId });
|
|
41423
41773
|
await execFileAsync("python3", ["-c", script, configJson, text, output], { timeout: 3e4 });
|
|
41424
|
-
if (!
|
|
41774
|
+
if (!fs29.existsSync(output) || fs29.statSync(output).size < 100) {
|
|
41425
41775
|
throw new Error("CosyVoice produced empty output");
|
|
41426
41776
|
}
|
|
41427
41777
|
return output;
|
|
@@ -41431,8 +41781,8 @@ var GPTSOVITS_REF_WAV = "/home/chong/voice/ref/shanshan_ref_v2.wav";
|
|
|
41431
41781
|
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";
|
|
41432
41782
|
var GPTSOVITS_REF_LANG = "zh";
|
|
41433
41783
|
async function ttsGptsovits(text) {
|
|
41434
|
-
|
|
41435
|
-
const output =
|
|
41784
|
+
fs29.mkdirSync(VOICE_DIR, { recursive: true });
|
|
41785
|
+
const output = path29.join(VOICE_DIR, `tts_${Date.now()}.wav`);
|
|
41436
41786
|
const params = new URLSearchParams({
|
|
41437
41787
|
text,
|
|
41438
41788
|
text_language: "zh",
|
|
@@ -41443,13 +41793,13 @@ async function ttsGptsovits(text) {
|
|
|
41443
41793
|
const res = await fetch(`${GPTSOVITS_API}/?${params}`);
|
|
41444
41794
|
if (!res.ok) throw new Error(`GPT-SoVITS API ${res.status}`);
|
|
41445
41795
|
const buf = Buffer.from(await res.arrayBuffer());
|
|
41446
|
-
|
|
41796
|
+
fs29.writeFileSync(output, buf);
|
|
41447
41797
|
return output;
|
|
41448
41798
|
}
|
|
41449
41799
|
var EDGE_VOICE = "zh-CN-XiaoxiaoNeural";
|
|
41450
41800
|
async function ttsEdge(text) {
|
|
41451
|
-
|
|
41452
|
-
const output =
|
|
41801
|
+
fs29.mkdirSync(VOICE_DIR, { recursive: true });
|
|
41802
|
+
const output = path29.join(VOICE_DIR, `tts_${Date.now()}.mp3`);
|
|
41453
41803
|
const script = `
|
|
41454
41804
|
import asyncio, edge_tts, sys
|
|
41455
41805
|
async def main():
|
|
@@ -41475,7 +41825,7 @@ async function compressWav(wavPath) {
|
|
|
41475
41825
|
"+faststart",
|
|
41476
41826
|
m4aPath
|
|
41477
41827
|
], { timeout: 3e4 });
|
|
41478
|
-
|
|
41828
|
+
fs29.unlinkSync(wavPath);
|
|
41479
41829
|
return m4aPath;
|
|
41480
41830
|
} catch {
|
|
41481
41831
|
return wavPath;
|
|
@@ -41542,10 +41892,10 @@ registry.register({
|
|
|
41542
41892
|
} catch (e) {
|
|
41543
41893
|
return { content: `TTS failed: ${e.message}`, isError: true };
|
|
41544
41894
|
}
|
|
41545
|
-
const ext =
|
|
41895
|
+
const ext = path29.extname(audioPath).toLowerCase();
|
|
41546
41896
|
const mimeMap = { ".mp3": "audio/mpeg", ".wav": "audio/wav", ".m4a": "audio/mp4", ".ogg": "audio/ogg" };
|
|
41547
41897
|
const mimeType = mimeMap[ext] || "audio/mpeg";
|
|
41548
|
-
const sizeKB =
|
|
41898
|
+
const sizeKB = fs29.statSync(audioPath).size / 1024;
|
|
41549
41899
|
const resolvedChannel = args.channel || ctx.channel || "feishu";
|
|
41550
41900
|
const target = ctx.channelTarget || ctx.from;
|
|
41551
41901
|
try {
|
|
@@ -41555,7 +41905,7 @@ registry.register({
|
|
|
41555
41905
|
filename: `voice_${Date.now()}${ext}`
|
|
41556
41906
|
});
|
|
41557
41907
|
try {
|
|
41558
|
-
|
|
41908
|
+
fs29.unlinkSync(audioPath);
|
|
41559
41909
|
} catch {
|
|
41560
41910
|
}
|
|
41561
41911
|
return { content: `Voice sent! (${actualEngine}, ${sizeKB.toFixed(0)}KB, ${resolvedChannel})` };
|
|
@@ -41572,8 +41922,8 @@ registry.register({
|
|
|
41572
41922
|
// src/tools/my-selfie.ts
|
|
41573
41923
|
init_live();
|
|
41574
41924
|
init_registry();
|
|
41575
|
-
import * as
|
|
41576
|
-
import * as
|
|
41925
|
+
import * as fs30 from "node:fs";
|
|
41926
|
+
import * as path30 from "node:path";
|
|
41577
41927
|
var FAL_KEY = "3b848fc6-bee5-46e5-8db7-ae81ac16dc28:2f1f15cf394db2d32c9bb9a4f23f3bee";
|
|
41578
41928
|
var FAL_ENDPOINT = "https://fal.run/xai/grok-imagine-image/edit";
|
|
41579
41929
|
var DEFAULT_RESOLUTION = "1k";
|
|
@@ -41689,11 +42039,11 @@ registry.register({
|
|
|
41689
42039
|
const REFERENCES = getReferences(ctx);
|
|
41690
42040
|
const refName = args.reference || "default";
|
|
41691
42041
|
const refEntry = REFERENCES.find((r) => r.name === refName) || REFERENCES[0];
|
|
41692
|
-
const refPath =
|
|
41693
|
-
if (!
|
|
42042
|
+
const refPath = path30.join(ctx.workspace, refEntry.p);
|
|
42043
|
+
if (!fs30.existsSync(refPath)) {
|
|
41694
42044
|
return { content: `Error: reference image not found at ${refPath}`, isError: true };
|
|
41695
42045
|
}
|
|
41696
|
-
const refB64 =
|
|
42046
|
+
const refB64 = fs30.readFileSync(refPath).toString("base64");
|
|
41697
42047
|
const resolution = args.resolution || DEFAULT_RESOLUTION;
|
|
41698
42048
|
let imageBuffer;
|
|
41699
42049
|
try {
|
|
@@ -41708,11 +42058,11 @@ registry.register({
|
|
|
41708
42058
|
} catch (err) {
|
|
41709
42059
|
return { content: `Selfie generation failed: ${err.message}`, isError: true };
|
|
41710
42060
|
}
|
|
41711
|
-
const imagesDir =
|
|
41712
|
-
if (!
|
|
42061
|
+
const imagesDir = path30.join(ctx.workspace, "images");
|
|
42062
|
+
if (!fs30.existsSync(imagesDir)) fs30.mkdirSync(imagesDir, { recursive: true });
|
|
41713
42063
|
const filename = `selfie_${Date.now()}.jpg`;
|
|
41714
|
-
const outputPath =
|
|
41715
|
-
|
|
42064
|
+
const outputPath = path30.join(imagesDir, filename);
|
|
42065
|
+
fs30.writeFileSync(outputPath, imageBuffer);
|
|
41716
42066
|
const mgr = ctx.channelManager;
|
|
41717
42067
|
if (mgr) {
|
|
41718
42068
|
const resolvedChannel = ctx.channel || "feishu";
|
|
@@ -41723,11 +42073,11 @@ registry.register({
|
|
|
41723
42073
|
mimeType: "image/jpeg"
|
|
41724
42074
|
});
|
|
41725
42075
|
} catch (err) {
|
|
41726
|
-
return { content: `Selfie generated but send failed: ${err.message}. Image: ${
|
|
42076
|
+
return { content: `Selfie generated but send failed: ${err.message}. Image: ${path30.resolve(outputPath)}`, isError: false };
|
|
41727
42077
|
}
|
|
41728
42078
|
return { content: `Selfie sent! Mode: ${mode}, Provider: ${getProvider(ctx)}, Ref: ${refEntry.name}` };
|
|
41729
42079
|
}
|
|
41730
|
-
return { content: `Selfie generated! Mode: ${mode}, Ref: ${refEntry.name}. Image: ${
|
|
42080
|
+
return { content: `Selfie generated! Mode: ${mode}, Ref: ${refEntry.name}. Image: ${path30.resolve(outputPath)}` };
|
|
41731
42081
|
},
|
|
41732
42082
|
isConcurrencySafe: () => false,
|
|
41733
42083
|
interruptBehavior: () => "block",
|
|
@@ -41867,9 +42217,9 @@ registry.register({
|
|
|
41867
42217
|
// src/tools/service.ts
|
|
41868
42218
|
init_registry();
|
|
41869
42219
|
init_live();
|
|
41870
|
-
import { exec as
|
|
42220
|
+
import { exec as exec4, spawn as spawn7 } from "node:child_process";
|
|
41871
42221
|
import { promisify as promisify2 } from "node:util";
|
|
41872
|
-
var execAsync = promisify2(
|
|
42222
|
+
var execAsync = promisify2(exec4);
|
|
41873
42223
|
function getServices() {
|
|
41874
42224
|
return liveConfig.get("services") || {};
|
|
41875
42225
|
}
|
|
@@ -41886,7 +42236,7 @@ function spawnDetached(cmd) {
|
|
|
41886
42236
|
const shell = isWin ? "cmd.exe" : "/bin/sh";
|
|
41887
42237
|
const logFile = `D:/xiaoke/logs/service-${(/* @__PURE__ */ new Date()).toISOString().slice(0, 10).replace(/-/g, "")}.log`;
|
|
41888
42238
|
const wrappedCmd = isWin ? `/c "${cmd.replace(/"/g, '\\"')} > "${logFile}" 2>&1"` : `-c "${cmd} > '${logFile}' 2>&1"`;
|
|
41889
|
-
const child =
|
|
42239
|
+
const child = spawn7(shell, isWin ? [wrappedCmd] : ["-c", `${cmd} > '${logFile}' 2>&1`], {
|
|
41890
42240
|
detached: true,
|
|
41891
42241
|
stdio: "ignore",
|
|
41892
42242
|
windowsHide: true,
|
|
@@ -42193,16 +42543,16 @@ var EXIT_PLAN_MODE_TOOL_NAME = "ExitPlanMode";
|
|
|
42193
42543
|
init_planModeState();
|
|
42194
42544
|
|
|
42195
42545
|
// src/utils/plans.ts
|
|
42196
|
-
import * as
|
|
42197
|
-
import * as
|
|
42546
|
+
import * as fs32 from "node:fs";
|
|
42547
|
+
import * as path32 from "node:path";
|
|
42198
42548
|
import * as crypto4 from "node:crypto";
|
|
42199
42549
|
var MAX_SLUG_RETRIES = 10;
|
|
42200
42550
|
function generateSlug() {
|
|
42201
42551
|
return crypto4.randomBytes(4).toString("hex");
|
|
42202
42552
|
}
|
|
42203
42553
|
function getPlansDirectory(stateDir) {
|
|
42204
|
-
const plansDir =
|
|
42205
|
-
|
|
42554
|
+
const plansDir = path32.join(stateDir, "plans");
|
|
42555
|
+
fs32.mkdirSync(plansDir, { recursive: true });
|
|
42206
42556
|
return plansDir;
|
|
42207
42557
|
}
|
|
42208
42558
|
var planSlugCache = /* @__PURE__ */ new Map();
|
|
@@ -42212,8 +42562,8 @@ function getPlanSlug(sessionId, stateDir) {
|
|
|
42212
42562
|
const plansDir = getPlansDirectory(stateDir);
|
|
42213
42563
|
for (let i = 0; i < MAX_SLUG_RETRIES; i++) {
|
|
42214
42564
|
slug = generateSlug();
|
|
42215
|
-
const filePath =
|
|
42216
|
-
if (!
|
|
42565
|
+
const filePath = path32.join(plansDir, `${slug}.md`);
|
|
42566
|
+
if (!fs32.existsSync(filePath)) {
|
|
42217
42567
|
break;
|
|
42218
42568
|
}
|
|
42219
42569
|
}
|
|
@@ -42224,21 +42574,21 @@ function getPlanSlug(sessionId, stateDir) {
|
|
|
42224
42574
|
function getPlanFilePath(sessionId, stateDir, agentId) {
|
|
42225
42575
|
const slug = getPlanSlug(sessionId, stateDir);
|
|
42226
42576
|
if (!agentId) {
|
|
42227
|
-
return
|
|
42577
|
+
return path32.join(getPlansDirectory(stateDir), `${slug}.md`);
|
|
42228
42578
|
}
|
|
42229
|
-
return
|
|
42579
|
+
return path32.join(getPlansDirectory(stateDir), `${slug}-agent-${agentId}.md`);
|
|
42230
42580
|
}
|
|
42231
42581
|
function getPlan(sessionId, stateDir, agentId) {
|
|
42232
42582
|
const filePath = getPlanFilePath(sessionId, stateDir, agentId);
|
|
42233
42583
|
try {
|
|
42234
|
-
return
|
|
42584
|
+
return fs32.readFileSync(filePath, "utf-8");
|
|
42235
42585
|
} catch {
|
|
42236
42586
|
return null;
|
|
42237
42587
|
}
|
|
42238
42588
|
}
|
|
42239
42589
|
function writePlan(sessionId, stateDir, content, agentId) {
|
|
42240
42590
|
const filePath = getPlanFilePath(sessionId, stateDir, agentId);
|
|
42241
|
-
|
|
42591
|
+
fs32.writeFileSync(filePath, content, "utf-8");
|
|
42242
42592
|
return filePath;
|
|
42243
42593
|
}
|
|
42244
42594
|
|
|
@@ -43076,8 +43426,8 @@ async function setupFeatures(features, licensedFeatures) {
|
|
|
43076
43426
|
|
|
43077
43427
|
// src/license/license.ts
|
|
43078
43428
|
import * as crypto6 from "node:crypto";
|
|
43079
|
-
import * as
|
|
43080
|
-
import * as
|
|
43429
|
+
import * as fs39 from "node:fs";
|
|
43430
|
+
import * as path40 from "node:path";
|
|
43081
43431
|
var EMBEDDED_PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
|
|
43082
43432
|
MCowBQYDK2VwAyEAaKBEX+e8+D59qwtidazsu7WYDglApyvsVI3APwFoakA=
|
|
43083
43433
|
-----END PUBLIC KEY-----`;
|
|
@@ -43108,13 +43458,13 @@ function loadLicense(stateDir, devMode) {
|
|
|
43108
43458
|
_cachedLicense = allActive;
|
|
43109
43459
|
return allActive;
|
|
43110
43460
|
}
|
|
43111
|
-
const licensePath =
|
|
43112
|
-
if (!
|
|
43461
|
+
const licensePath = path40.join(stateDir, "license.json");
|
|
43462
|
+
if (!fs39.existsSync(licensePath)) {
|
|
43113
43463
|
console.log("[license] No license.json found, running basic engine only");
|
|
43114
43464
|
return null;
|
|
43115
43465
|
}
|
|
43116
43466
|
try {
|
|
43117
|
-
const raw =
|
|
43467
|
+
const raw = fs39.readFileSync(licensePath, "utf-8");
|
|
43118
43468
|
const license = JSON.parse(raw);
|
|
43119
43469
|
const { signature, ...payload } = license;
|
|
43120
43470
|
if (!signature) {
|
|
@@ -43730,11 +44080,11 @@ async function startEngine(config, opts) {
|
|
|
43730
44080
|
process.env.ENGINE_MEDIA_DIR = config.mediaDir;
|
|
43731
44081
|
process.env.ENGINE7_WORKSPACE = config.workspace;
|
|
43732
44082
|
process.env.OPENCLAW_WORKSPACE = config.workspace;
|
|
43733
|
-
|
|
43734
|
-
|
|
43735
|
-
|
|
43736
|
-
|
|
43737
|
-
|
|
44083
|
+
fs54.mkdirSync(path55.join(config.stateDir, "agents", "main", "memory"), { recursive: true });
|
|
44084
|
+
fs54.mkdirSync(path55.join(config.stateDir, "agents", "main", "sessions"), { recursive: true });
|
|
44085
|
+
fs54.mkdirSync(path55.join(config.stateDir, "logs"), { recursive: true });
|
|
44086
|
+
fs54.mkdirSync(config.workspace, { recursive: true });
|
|
44087
|
+
fs54.mkdirSync(config.mediaDir, { recursive: true });
|
|
43738
44088
|
try {
|
|
43739
44089
|
process.chdir(config.workspace);
|
|
43740
44090
|
} catch (e) {
|
|
@@ -43842,7 +44192,7 @@ async function startEngine(config, opts) {
|
|
|
43842
44192
|
const { initSessionMemory: initSessionMemory2 } = await Promise.resolve().then(() => (init_sessionMemory(), sessionMemory_exports));
|
|
43843
44193
|
initSessionMemory2({
|
|
43844
44194
|
workspace: config.workspace,
|
|
43845
|
-
stateDir:
|
|
44195
|
+
stateDir: path55.join(config.stateDir, "session-memory"),
|
|
43846
44196
|
provider,
|
|
43847
44197
|
model: config.provider.modelId || config.model || "deepseek-v4-flash",
|
|
43848
44198
|
features: config.profile.features
|
|
@@ -43872,9 +44222,9 @@ async function startEngine(config, opts) {
|
|
|
43872
44222
|
if (config.hooks) {
|
|
43873
44223
|
loadHooksFromConfig({ hooks: config.hooks });
|
|
43874
44224
|
}
|
|
43875
|
-
const hooksPath =
|
|
44225
|
+
const hooksPath = path55.join(config.workspace, ".hooks.json");
|
|
43876
44226
|
loadHooksFromFile(hooksPath);
|
|
43877
|
-
const settingsHooksPath =
|
|
44227
|
+
const settingsHooksPath = path55.join(config.stateDir, "settings.json");
|
|
43878
44228
|
loadHooksFromFile(settingsHooksPath);
|
|
43879
44229
|
console.log(`[hooks] Loaded hooks configuration`);
|
|
43880
44230
|
registerCallbackHook("PreCompact", {
|
|
@@ -43888,18 +44238,18 @@ async function startEngine(config, opts) {
|
|
|
43888
44238
|
const bjTime = new Date(now.getTime() + (bjOffset + now.getTimezoneOffset()) * 6e4);
|
|
43889
44239
|
const dateStr = `${bjTime.getFullYear()}-${String(bjTime.getMonth() + 1).padStart(2, "0")}-${String(bjTime.getDate()).padStart(2, "0")}`;
|
|
43890
44240
|
const timeStr = `${String(bjTime.getHours()).padStart(2, "0")}:${String(bjTime.getMinutes()).padStart(2, "0")}`;
|
|
43891
|
-
const dailyDir =
|
|
43892
|
-
const dailyPath =
|
|
44241
|
+
const dailyDir = path55.join(workspace, "memory", "daily");
|
|
44242
|
+
const dailyPath = path55.join(dailyDir, `${dateStr}.md`);
|
|
43893
44243
|
try {
|
|
43894
|
-
const
|
|
43895
|
-
if (!
|
|
43896
|
-
|
|
44244
|
+
const fs55 = await import("node:fs");
|
|
44245
|
+
if (!fs55.existsSync(dailyDir)) {
|
|
44246
|
+
fs55.mkdirSync(dailyDir, { recursive: true });
|
|
43897
44247
|
}
|
|
43898
|
-
const sessionsDir =
|
|
43899
|
-
const sessionFile =
|
|
44248
|
+
const sessionsDir = path55.join(config.stateDir, "agents", "main", "sessions");
|
|
44249
|
+
const sessionFile = path55.join(sessionsDir, `${sessionId}.jsonl`);
|
|
43900
44250
|
const recentLines = [];
|
|
43901
|
-
if (
|
|
43902
|
-
const content =
|
|
44251
|
+
if (fs55.existsSync(sessionFile)) {
|
|
44252
|
+
const content = fs55.readFileSync(sessionFile, "utf-8");
|
|
43903
44253
|
const lines = content.trim().split("\n").filter(Boolean);
|
|
43904
44254
|
const userLines = lines.filter((l) => {
|
|
43905
44255
|
try {
|
|
@@ -43929,10 +44279,10 @@ async function startEngine(config, opts) {
|
|
|
43929
44279
|
const entry = `${header}
|
|
43930
44280
|
${body}
|
|
43931
44281
|
`;
|
|
43932
|
-
if (
|
|
43933
|
-
|
|
44282
|
+
if (fs55.existsSync(dailyPath)) {
|
|
44283
|
+
fs55.appendFileSync(dailyPath, entry);
|
|
43934
44284
|
} else {
|
|
43935
|
-
|
|
44285
|
+
fs55.writeFileSync(dailyPath, `# ${dateStr} \u65E5\u5FD7
|
|
43936
44286
|
${entry}`);
|
|
43937
44287
|
}
|
|
43938
44288
|
console.log(`[hooks] PreCompact: saved ${recentLines.length} lines to ${dailyPath}`);
|
|
@@ -43948,16 +44298,16 @@ ${entry}`);
|
|
|
43948
44298
|
const workspace = input.cwd || input.workspace || "";
|
|
43949
44299
|
if (!workspace) return { continue: true };
|
|
43950
44300
|
try {
|
|
43951
|
-
const
|
|
43952
|
-
const bufferPath =
|
|
43953
|
-
if (
|
|
43954
|
-
const stat8 =
|
|
44301
|
+
const fs55 = await import("node:fs");
|
|
44302
|
+
const bufferPath = path55.join(workspace, "memory", "working-buffer.md");
|
|
44303
|
+
if (fs55.existsSync(bufferPath)) {
|
|
44304
|
+
const stat8 = fs55.statSync(bufferPath);
|
|
43955
44305
|
const ageMs = Date.now() - stat8.mtimeMs;
|
|
43956
44306
|
const ageMin = Math.round(ageMs / 6e4);
|
|
43957
44307
|
if (ageMin > 10) {
|
|
43958
44308
|
console.warn(`[hooks] PostCompact: \u26A0\uFE0F working-buffer.md is ${ageMin}min old (last modified ${stat8.mtime.toISOString()}) \u2014 content may be stale!`);
|
|
43959
44309
|
}
|
|
43960
|
-
const content =
|
|
44310
|
+
const content = fs55.readFileSync(bufferPath, "utf-8");
|
|
43961
44311
|
if (content.trim()) {
|
|
43962
44312
|
console.log(`[hooks] PostCompact: injecting working-buffer (${content.length} chars, ${ageMin}min old)`);
|
|
43963
44313
|
return {
|
|
@@ -44002,7 +44352,7 @@ ${content}`
|
|
|
44002
44352
|
return `${hr}h ${remMin}m`;
|
|
44003
44353
|
}
|
|
44004
44354
|
if (config.skills?.enabled !== false) {
|
|
44005
|
-
const skillsDir = config.skills?.path ?
|
|
44355
|
+
const skillsDir = config.skills?.path ? path55.isAbsolute(config.skills.path) ? config.skills.path : path55.resolve(config.workspace, config.skills.path) : path55.resolve(config.workspace, "skills");
|
|
44006
44356
|
const modelDef2 = config.provider.models.find((m2) => m2.id === config.model);
|
|
44007
44357
|
const contextWindowTokens = modelDef2?.contextWindow;
|
|
44008
44358
|
const skills = scanSkills(skillsDir);
|
|
@@ -44021,8 +44371,8 @@ ${content}`
|
|
|
44021
44371
|
workspace: config.workspace
|
|
44022
44372
|
});
|
|
44023
44373
|
const systemPrompt = [systemStable, systemDynamic].join("\n\n");
|
|
44024
|
-
const promptDumpPath =
|
|
44025
|
-
|
|
44374
|
+
const promptDumpPath = path55.join(config.workspace, ".system-prompt.txt");
|
|
44375
|
+
fs54.writeFileSync(promptDumpPath, systemPrompt);
|
|
44026
44376
|
console.log(`System prompt: ${systemStable.length} chars stable + ${systemDynamic.length} chars dynamic \u2192 ${promptDumpPath}`);
|
|
44027
44377
|
const modelDef = config.provider.models.find((m2) => m2.id === config.model);
|
|
44028
44378
|
const modelContextWindow = modelDef?.contextWindow;
|
|
@@ -44928,15 +45278,15 @@ ${result.changes.map((c) => `- ${c}`).join("\n")}` : `\u274C Reload failed: ${re
|
|
|
44928
45278
|
config.features[key] = next;
|
|
44929
45279
|
if (deps.features) deps.features[key] = next;
|
|
44930
45280
|
try {
|
|
44931
|
-
const
|
|
45281
|
+
const fs55 = await import("fs");
|
|
44932
45282
|
const pathMod = await import("path");
|
|
44933
45283
|
let cfgPath = config._configFilePath;
|
|
44934
|
-
if (!cfgPath || !
|
|
45284
|
+
if (!cfgPath || !fs55.existsSync(cfgPath)) {
|
|
44935
45285
|
const __filename = fileURLToPath(import.meta.url);
|
|
44936
45286
|
const __dirname = pathMod.dirname(__filename);
|
|
44937
45287
|
cfgPath = pathMod.resolve(__dirname, "../configs", pathMod.basename(cfgPath || "engine-config.json"));
|
|
44938
45288
|
}
|
|
44939
|
-
const cfg = JSON.parse(
|
|
45289
|
+
const cfg = JSON.parse(fs55.readFileSync(cfgPath, "utf-8"));
|
|
44940
45290
|
let featObj = null;
|
|
44941
45291
|
if (cfg.agents?.defaults?.features) {
|
|
44942
45292
|
featObj = cfg.agents.defaults.features;
|
|
@@ -44946,7 +45296,7 @@ ${result.changes.map((c) => `- ${c}`).join("\n")}` : `\u274C Reload failed: ${re
|
|
|
44946
45296
|
}
|
|
44947
45297
|
if (featObj) {
|
|
44948
45298
|
featObj[key] = next;
|
|
44949
|
-
|
|
45299
|
+
fs55.writeFileSync(cfgPath, JSON.stringify(cfg, null, 2) + "\n", "utf-8");
|
|
44950
45300
|
console.log(`[${ctx.command}] ${key} ${cur} \u2192 ${rawState} (disk persisted)`);
|
|
44951
45301
|
await ctx.reply(`\u2705 ${key}: **${cur}** \u2192 **${rawState}**`);
|
|
44952
45302
|
} else {
|
|
@@ -45072,11 +45422,11 @@ Auto-routing disabled \u2014 all messages use this model.
|
|
|
45072
45422
|
const input = (ctx.args.model || "").trim();
|
|
45073
45423
|
const configPath = config._configFilePath;
|
|
45074
45424
|
let writePath = configPath;
|
|
45075
|
-
if (configPath && !
|
|
45425
|
+
if (configPath && !fs54.existsSync(configPath)) {
|
|
45076
45426
|
const __pFile = fileURLToPath(import.meta.url);
|
|
45077
|
-
const __pDir =
|
|
45078
|
-
const altPath =
|
|
45079
|
-
if (
|
|
45427
|
+
const __pDir = path55.dirname(__pFile);
|
|
45428
|
+
const altPath = path55.join(path55.resolve(__pDir, "../configs"), path55.basename(configPath));
|
|
45429
|
+
if (fs54.existsSync(altPath)) {
|
|
45080
45430
|
console.warn(`[primary] Config not found at ${configPath}, falling back to ${altPath}`);
|
|
45081
45431
|
writePath = altPath;
|
|
45082
45432
|
}
|
|
@@ -45120,14 +45470,14 @@ Use full ref like \`/primary ${candidates[0].ref}\``);
|
|
|
45120
45470
|
return;
|
|
45121
45471
|
}
|
|
45122
45472
|
try {
|
|
45123
|
-
const raw = await
|
|
45473
|
+
const raw = await fs54.promises.readFile(writePath, "utf-8");
|
|
45124
45474
|
const cfg = JSON.parse(raw);
|
|
45125
45475
|
if (!cfg.agents?.defaults?.model) {
|
|
45126
45476
|
await ctx.reply(`\u26A0\uFE0F Config structure mismatch: agents.defaults.model not found`);
|
|
45127
45477
|
return;
|
|
45128
45478
|
}
|
|
45129
45479
|
cfg.agents.defaults.model.primary = target;
|
|
45130
|
-
await
|
|
45480
|
+
await fs54.promises.writeFile(writePath, JSON.stringify(cfg, null, 2), "utf-8");
|
|
45131
45481
|
console.log(`[primary] Persisted primary=${target} to ${writePath}`);
|
|
45132
45482
|
await ctx.reply(`\u2705 Primary model set to **${target}** (${candidates[0].name})
|
|
45133
45483
|
Written to config. **Restart required** to take effect.`);
|
|
@@ -45347,7 +45697,7 @@ Use full ref like \`/vision-model ${candidates[0].ref}\``);
|
|
|
45347
45697
|
console.log(`[vision] Downloading image: ${att.filename}`);
|
|
45348
45698
|
let rawBuffer;
|
|
45349
45699
|
if (att.url.startsWith("file://")) {
|
|
45350
|
-
rawBuffer =
|
|
45700
|
+
rawBuffer = fs54.readFileSync(decodeURIComponent(att.url.slice(7)));
|
|
45351
45701
|
} else {
|
|
45352
45702
|
rawBuffer = await downloadImage2(att.url);
|
|
45353
45703
|
}
|
|
@@ -45355,8 +45705,8 @@ Use full ref like \`/vision-model ${candidates[0].ref}\``);
|
|
|
45355
45705
|
const ext = detected.split("/")[1] || "png";
|
|
45356
45706
|
const resized = await maybeResizeAndDownsampleImageBuffer2(rawBuffer, rawBuffer.length, ext);
|
|
45357
45707
|
const imageId = `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
45358
|
-
const savedPath =
|
|
45359
|
-
|
|
45708
|
+
const savedPath = path55.join(config.mediaDir, `${imageId}.${ext}`);
|
|
45709
|
+
fs54.writeFileSync(savedPath, resized.buffer);
|
|
45360
45710
|
savedPaths.push(savedPath);
|
|
45361
45711
|
console.log(`[vision] Saved: ${savedPath} (${resized.buffer.length}B)`);
|
|
45362
45712
|
imageBlocks.push({
|
|
@@ -45382,8 +45732,8 @@ ${pathStr}` }];
|
|
|
45382
45732
|
}
|
|
45383
45733
|
const nonImageAttachments = inbound.attachments?.filter((a) => !a.contentType.startsWith("image/"));
|
|
45384
45734
|
if (nonImageAttachments && nonImageAttachments.length > 0) {
|
|
45385
|
-
const outDir =
|
|
45386
|
-
|
|
45735
|
+
const outDir = path55.join(config.mediaDir, sessionId);
|
|
45736
|
+
fs54.mkdirSync(outDir, { recursive: true });
|
|
45387
45737
|
const resolved = [];
|
|
45388
45738
|
for (const att of nonImageAttachments) {
|
|
45389
45739
|
console.log(`[file] Downloading: ${att.filename} (${att.contentType}, ${att.size}B)`);
|
|
@@ -45391,9 +45741,9 @@ ${pathStr}` }];
|
|
|
45391
45741
|
const resp = await fetch(att.url);
|
|
45392
45742
|
if (!resp.ok) throw new Error(`HTTP ${resp.status}`);
|
|
45393
45743
|
const buffer = Buffer.from(await resp.arrayBuffer());
|
|
45394
|
-
const safeName2 =
|
|
45395
|
-
const savedPath =
|
|
45396
|
-
|
|
45744
|
+
const safeName2 = path55.basename(att.filename).replace(/[<>:"/\\|?*\x00-\x1f]/g, "_") || "attachment";
|
|
45745
|
+
const savedPath = path55.join(outDir, safeName2);
|
|
45746
|
+
fs54.writeFileSync(savedPath, buffer);
|
|
45397
45747
|
resolved.push(savedPath);
|
|
45398
45748
|
console.log(`[file] Saved: ${savedPath} (${buffer.length}B)`);
|
|
45399
45749
|
} catch (err) {
|
|
@@ -45611,6 +45961,10 @@ ${pathStr}` }];
|
|
|
45611
45961
|
console.warn("[cognifold] workspace path not found, skipping plugin registration");
|
|
45612
45962
|
}
|
|
45613
45963
|
}
|
|
45964
|
+
if (config.everos?.enabled) {
|
|
45965
|
+
pluginManager.register(new EverosPlugin(config.everos));
|
|
45966
|
+
console.log("[everos] Plugin registered");
|
|
45967
|
+
}
|
|
45614
45968
|
globalThis.__pluginManager = pluginManager;
|
|
45615
45969
|
if (visualEmitter && config.visualization?.guildId) {
|
|
45616
45970
|
const vConfig = config.visualization;
|
|
@@ -45749,7 +46103,7 @@ ${pathStr}` }];
|
|
|
45749
46103
|
console.warn("[cognifold] watcher: config.workspace \u672A\u914D\u7F6E\uFF0C\u8DF3\u8FC7 proactive \u5199\u5165");
|
|
45750
46104
|
return;
|
|
45751
46105
|
}
|
|
45752
|
-
const pFile =
|
|
46106
|
+
const pFile = path55.join(wsDir, ".cognifold-proactive.json");
|
|
45753
46107
|
const cognifoldBaseUrl = config.cognifold?.baseUrl || "http://127.0.0.1:9001";
|
|
45754
46108
|
const cognifoldSessionId = cfSessionId;
|
|
45755
46109
|
const rawSuggestions = data.suggestions || data.actions || (data.intent_id ? [data] : []);
|
|
@@ -45797,14 +46151,14 @@ ${pathStr}` }];
|
|
|
45797
46151
|
return s2;
|
|
45798
46152
|
}));
|
|
45799
46153
|
try {
|
|
45800
|
-
|
|
46154
|
+
fs54.writeFileSync(pFile, JSON.stringify(enriched, null, 2));
|
|
45801
46155
|
console.log(`[cognifold] proactive suggestions saved (${enriched.length} total)`);
|
|
45802
46156
|
} catch (e) {
|
|
45803
46157
|
console.error(`[cognifold] failed to save proactive: ${e.message}`);
|
|
45804
46158
|
}
|
|
45805
46159
|
if (enriched.length > 0) {
|
|
45806
|
-
const promptFile =
|
|
45807
|
-
const promptText =
|
|
46160
|
+
const promptFile = path55.join(config.workspace, "prompts", "cognifold-proactive.md");
|
|
46161
|
+
const promptText = fs54.existsSync(promptFile) ? fs54.readFileSync(promptFile, "utf-8") : "[CogniFold proactive] \u6709 " + enriched.length + " \u4E2A action \u5230\u671F\u4E86";
|
|
45808
46162
|
const actionsJson = JSON.stringify(enriched, null, 2);
|
|
45809
46163
|
const sessionId = cfSessionId;
|
|
45810
46164
|
const mainSessionId = sessions.getSessionId("scope:main");
|
|
@@ -45907,12 +46261,12 @@ async function doReloadConfig(config, deps, provider) {
|
|
|
45907
46261
|
try {
|
|
45908
46262
|
const savedConfigPath = config._configFilePath;
|
|
45909
46263
|
let reloadConfigPath = savedConfigPath;
|
|
45910
|
-
if (!
|
|
46264
|
+
if (!fs54.existsSync(reloadConfigPath)) {
|
|
45911
46265
|
const __filename = fileURLToPath(import.meta.url);
|
|
45912
|
-
const __dirname =
|
|
45913
|
-
const engineConfigsDir =
|
|
45914
|
-
const altPath =
|
|
45915
|
-
if (
|
|
46266
|
+
const __dirname = path55.dirname(__filename);
|
|
46267
|
+
const engineConfigsDir = path55.resolve(__dirname, "../configs");
|
|
46268
|
+
const altPath = path55.join(engineConfigsDir, path55.basename(savedConfigPath));
|
|
46269
|
+
if (fs54.existsSync(altPath)) {
|
|
45916
46270
|
console.warn(`[reload] Config not found at ${reloadConfigPath}, falling back to ${altPath} (dev mode)`);
|
|
45917
46271
|
reloadConfigPath = altPath;
|
|
45918
46272
|
}
|
|
@@ -45964,7 +46318,7 @@ async function doReloadConfig(config, deps, provider) {
|
|
|
45964
46318
|
} catch (err) {
|
|
45965
46319
|
console.error(`[reload] Failed: ${err.message}`);
|
|
45966
46320
|
try {
|
|
45967
|
-
|
|
46321
|
+
fs54.appendFileSync(path55.join(config.stateDir, "logs", "engine-config-watch.log"), `[${(/* @__PURE__ */ new Date()).toISOString()}] RELOAD FAILED: ${err.message}
|
|
45968
46322
|
${err.stack}
|
|
45969
46323
|
`);
|
|
45970
46324
|
} catch {
|
|
@@ -45975,36 +46329,36 @@ ${err.stack}
|
|
|
45975
46329
|
function startConfigWatcher(config, deps, provider) {
|
|
45976
46330
|
const raw = config._configFilePath;
|
|
45977
46331
|
let configPath = raw;
|
|
45978
|
-
if (!
|
|
45979
|
-
configPath =
|
|
46332
|
+
if (!fs54.existsSync(configPath)) {
|
|
46333
|
+
configPath = path55.resolve(raw);
|
|
45980
46334
|
}
|
|
45981
|
-
if (!
|
|
46335
|
+
if (!fs54.existsSync(configPath)) {
|
|
45982
46336
|
const __filename2 = fileURLToPath(import.meta.url);
|
|
45983
|
-
const __dirname2 =
|
|
45984
|
-
configPath =
|
|
46337
|
+
const __dirname2 = path55.dirname(__filename2);
|
|
46338
|
+
configPath = path55.resolve(__dirname2, "..", raw);
|
|
45985
46339
|
}
|
|
45986
|
-
if (!
|
|
46340
|
+
if (!fs54.existsSync(configPath)) {
|
|
45987
46341
|
console.warn(`[config-watch] config path invalid: ${configPath}, watcher disabled`);
|
|
45988
46342
|
try {
|
|
45989
|
-
|
|
46343
|
+
fs54.appendFileSync(path55.join(config.stateDir, "logs", "engine-config-watch.log"), `[${(/* @__PURE__ */ new Date()).toISOString()}] DISABLED: configPath=${configPath}
|
|
45990
46344
|
`);
|
|
45991
46345
|
} catch {
|
|
45992
46346
|
}
|
|
45993
46347
|
return null;
|
|
45994
46348
|
}
|
|
45995
46349
|
let debounceTimer = null;
|
|
45996
|
-
const watcher =
|
|
46350
|
+
const watcher = fs54.watch(configPath, { persistent: true }, (eventType) => {
|
|
45997
46351
|
if (debounceTimer) clearTimeout(debounceTimer);
|
|
45998
46352
|
debounceTimer = setTimeout(async () => {
|
|
45999
46353
|
console.log(`[config-watch] file changed (${eventType}), reloading...`);
|
|
46000
46354
|
try {
|
|
46001
|
-
|
|
46355
|
+
fs54.appendFileSync(path55.join(config.stateDir, "logs", "engine-config-watch.log"), `[${(/* @__PURE__ */ new Date()).toISOString()}] CHANGE eventType=${eventType}, calling doReloadConfig
|
|
46002
46356
|
`);
|
|
46003
46357
|
} catch {
|
|
46004
46358
|
}
|
|
46005
46359
|
const result = await doReloadConfig(config, deps, provider);
|
|
46006
46360
|
try {
|
|
46007
|
-
|
|
46361
|
+
fs54.appendFileSync(path55.join(config.stateDir, "logs", "engine-config-watch.log"), `[${(/* @__PURE__ */ new Date()).toISOString()}] RELOAD DONE: ok=${result.ok} changes=${result.changes.join(",")}
|
|
46008
46362
|
`);
|
|
46009
46363
|
} catch {
|
|
46010
46364
|
}
|
|
@@ -46013,14 +46367,14 @@ function startConfigWatcher(config, deps, provider) {
|
|
|
46013
46367
|
watcher.on("error", (err) => {
|
|
46014
46368
|
console.error(`[config-watch] error: ${err.message}`);
|
|
46015
46369
|
try {
|
|
46016
|
-
|
|
46370
|
+
fs54.appendFileSync(path55.join(config.stateDir, "logs", "engine-config-watch.log"), `[${(/* @__PURE__ */ new Date()).toISOString()}] ERROR: ${err.message}
|
|
46017
46371
|
`);
|
|
46018
46372
|
} catch {
|
|
46019
46373
|
}
|
|
46020
46374
|
});
|
|
46021
46375
|
console.log(`[config-watch] watching ${configPath}`);
|
|
46022
46376
|
try {
|
|
46023
|
-
|
|
46377
|
+
fs54.appendFileSync(path55.join(config.stateDir, "logs", "engine-config-watch.log"), `[${(/* @__PURE__ */ new Date()).toISOString()}] STARTED watching=${configPath}
|
|
46024
46378
|
`);
|
|
46025
46379
|
} catch {
|
|
46026
46380
|
}
|