@nowcrew/daemon 0.6.92 → 0.6.93-beta.1
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/execution-journal.js +3 -1
- package/dist/execution-protocol.js +1 -1
- package/dist/execution-runner.js +3 -1
- package/dist/local-execution-prompt.js +8 -3
- package/dist/local-executor.js +64 -35
- package/dist/local-memory/execution-workspace.js +55 -0
- package/dist/local-memory/full-index-search.js +47 -0
- package/dist/local-memory/index-budget.js +9 -3
- package/dist/local-memory/initialization-identity.js +23 -0
- package/dist/local-memory/inventory-cli.js +23 -1
- package/dist/local-memory/inventory-source.js +15 -8
- package/dist/local-memory/legacy-adapter.js +233 -0
- package/dist/local-memory/migration-access.js +184 -0
- package/dist/local-memory/migration-cli.js +54 -0
- package/dist/local-memory/migration-io.js +199 -0
- package/dist/local-memory/migration-plan.js +283 -0
- package/dist/local-memory/migration-schema.js +55 -0
- package/dist/local-memory/migration-store.js +429 -0
- package/dist/local-memory/migration-tool-entry.js +21 -0
- package/dist/local-memory/prompt.js +20 -4
- package/dist/local-memory/read-cli.js +75 -77
- package/dist/local-memory/rollout.js +54 -8
- package/dist/local-memory/runtime.js +148 -13
- package/dist/local-memory/storage-format.js +152 -0
- package/dist/local-memory/write.js +125 -19
- package/dist/local-memory-diagnostics.js +41 -2
- package/dist/local-memory-telemetry.js +19 -2
- package/dist/machine-info.js +3 -0
- package/dist/memory-migration-controller.js +84 -0
- package/dist/memory-migration-inspect.js +75 -0
- package/dist/memory-migration-journal.js +14 -0
- package/dist/memory-migration-protocol.js +14 -0
- package/dist/memory-migration-runtime.js +305 -0
- package/dist/memory-prune-diagnostics.js +60 -4
- package/dist/message-file-preview.js +11 -1
- package/dist/prompt.js +5 -1
- package/dist/runner.js +1 -1
- package/dist/serve.js +36 -3
- package/dist/token.js +1 -0
- package/dist/workspace-control-handler.js +16 -3
- package/dist/workspace.js +10 -2
- package/package.json +1 -1
package/dist/prompt.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* claim-before-work、freshness/draft、"做完所有事再停"、inbox notice 语义、
|
|
6
6
|
* 分层记忆与压缩安全、协作礼仪。措辞为本项目原创。
|
|
7
7
|
*/
|
|
8
|
+
import { detectLocalMemoryStorageVersion, selectLocalMemoryPreview } from "./local-memory/storage-format.js";
|
|
8
9
|
/** work-log 注入上限(字符):防冷启动注入随文件膨胀。超限保头(目标/结论)+尾(最近进展),
|
|
9
10
|
* 截中段并提示读全文——全文仍在盘上,只限"默认推送量"不限"可获取量"。纯函数。 */
|
|
10
11
|
export const WORKLOG_INJECT_CAP = 8000;
|
|
@@ -67,7 +68,10 @@ export function capWorkLogForInject(workLog, cap = WORKLOG_INJECT_CAP) {
|
|
|
67
68
|
const tail = workLog.slice(-WORKLOG_TAIL);
|
|
68
69
|
return `${head}\n…(work-log 过长已截去中段,全文用 Read 读 $CREW_TASK_LOG)\n${tail}`;
|
|
69
70
|
}
|
|
70
|
-
export function capMemoryForInject(memory, cap = MEMORY_INJECT_CAP, maxBytes = Number.POSITIVE_INFINITY) {
|
|
71
|
+
export function capMemoryForInject(memory, cap = MEMORY_INJECT_CAP, maxBytes = Number.POSITIVE_INFINITY, query = "") {
|
|
72
|
+
if (detectLocalMemoryStorageVersion(memory) === 2) {
|
|
73
|
+
return selectLocalMemoryPreview(memory, query, { maxCodePoints: cap, maxBytes }).memory;
|
|
74
|
+
}
|
|
71
75
|
if (memory.length <= cap && Buffer.byteLength(memory, "utf8") <= maxBytes)
|
|
72
76
|
return memory;
|
|
73
77
|
const notice = "[MEMORY.md preview truncated; use crew-memory search/read for more.]\n";
|
package/dist/runner.js
CHANGED
|
@@ -80,7 +80,7 @@ async function runAgentWithMachineEnvironment(config, input, onActivity = defaul
|
|
|
80
80
|
? { scheduledExternalNotificationPolicy: input.scheduled.externalNotificationPolicy }
|
|
81
81
|
: {}),
|
|
82
82
|
...(input.wakeOrigin ? { wakeOrigin: input.wakeOrigin } : {}),
|
|
83
|
-
memory: capMemoryForInject(workspace.memory),
|
|
83
|
+
memory: capMemoryForInject(workspace.memory, undefined, undefined, baseWake),
|
|
84
84
|
...(resuming ? {} : { workLog: capWorkLogForInject(workspace.workLog) }),
|
|
85
85
|
collaborationToolsEnabled: config.codexCollaborationTools && runtime === "codex",
|
|
86
86
|
localMemoryV2Enabled: workspace.localMemoryV2Enabled ?? localMemoryV2Enabled,
|
package/dist/serve.js
CHANGED
|
@@ -14,6 +14,7 @@ import { reconcileExecutionJournal } from "./execution-recovery.js";
|
|
|
14
14
|
import { initReleaseSlog, reportDaemonConnectionClose, reportReleaseError } from "./release-channel-guard.js";
|
|
15
15
|
import { handleWorkspaceControlRequest } from "./workspace-control-handler.js";
|
|
16
16
|
import { inspectRaftWorkspace, importRaftWorkspace } from "./workspace-import.js";
|
|
17
|
+
import { withMemoryAccess } from "./local-memory/migration-access.js";
|
|
17
18
|
import { normalizeScheduledContext } from "./scheduled-report.js";
|
|
18
19
|
import { formatDaemonLogLine } from "./log-format.js";
|
|
19
20
|
import { reportAgentRunComplete } from "./scheduled-run-report.js";
|
|
@@ -50,6 +51,8 @@ import { probeRuntimeHealth } from "./runtime-health.js";
|
|
|
50
51
|
import { createServeMarketplace } from "./marketplace-serve.js";
|
|
51
52
|
import { buildControlPlaneUrl } from "./control-plane-url.js";
|
|
52
53
|
import { resolveDaemonLocalStateRootFromEnv } from "./daemon-local-home.js";
|
|
54
|
+
import { createMemoryMigrationController } from "./memory-migration-controller.js";
|
|
55
|
+
import { createMemoryMigrationJournal, replayExecutionJournals } from "./memory-migration-journal.js";
|
|
53
56
|
import { bindStorageServerIdentity, createStorageIdentityAdmission, } from "./storage-serve-adapter.js";
|
|
54
57
|
export { buildControlPlaneUrl } from "./control-plane-url.js";
|
|
55
58
|
// normalize.ts 的活动种类 → activity 枚举
|
|
@@ -71,6 +74,8 @@ export function serve(config, opts = {}) {
|
|
|
71
74
|
let reconnectTimer = null;
|
|
72
75
|
let stopPromise = null;
|
|
73
76
|
let executionJournal;
|
|
77
|
+
let migrationExecutionJournal;
|
|
78
|
+
let migrationJournalReady = false;
|
|
74
79
|
const injectedExecutionJournal = opts.execution?.journal;
|
|
75
80
|
const agentMemory = opts.execution?.dependencies?.agentMemory
|
|
76
81
|
?? (config.agentMemory === null ? undefined : createAgentMemoryBridge(config.agentMemory));
|
|
@@ -85,6 +90,15 @@ export function serve(config, opts = {}) {
|
|
|
85
90
|
startupGapMs: config.executionLimits.startupGapMs,
|
|
86
91
|
});
|
|
87
92
|
const localSlots = createSharedSlotManager(config.executionLimits);
|
|
93
|
+
const memoryMigrations = createMemoryMigrationController({ config, coordinator: hostCoordinator,
|
|
94
|
+
isAdmissionClosed: () => stopped || storageIdentityAdmission.isAdmissionClosed(),
|
|
95
|
+
journal: () => { if (!migrationJournalReady)
|
|
96
|
+
throw new Error("memory_migration_journal_unavailable"); return migrationExecutionJournal; }, send: frame => {
|
|
97
|
+
if (frame.type === "execution:completed")
|
|
98
|
+
completionRetransmitter.track(frame);
|
|
99
|
+
else if (ws?.readyState === WebSocket.OPEN)
|
|
100
|
+
ws.send(JSON.stringify(frame));
|
|
101
|
+
} });
|
|
88
102
|
const sharedSlots = hostCoordinatedSlotManager(localSlots, hostCoordinator);
|
|
89
103
|
const concurrencyTelemetry = createExecutionConcurrencyTelemetry(sharedSlots, {
|
|
90
104
|
...(opts.execution?.concurrencySnapshotIntervalMs === undefined
|
|
@@ -232,7 +246,7 @@ export function serve(config, opts = {}) {
|
|
|
232
246
|
return null;
|
|
233
247
|
};
|
|
234
248
|
const sendSnapshot = async (reqId) => {
|
|
235
|
-
const entries = (await executionJournal
|
|
249
|
+
const entries = (await replayExecutionJournals(executionJournal, migrationExecutionJournal)).map(snapshotEntry).filter((entry) => entry !== null);
|
|
236
250
|
safeExecutionSend(ExecutionSnapshotSchema.parse({
|
|
237
251
|
type: "execution:snapshot", protocolVersion: 1, reqId, entries,
|
|
238
252
|
}));
|
|
@@ -313,6 +327,12 @@ export function serve(config, opts = {}) {
|
|
|
313
327
|
machineRuntime.open(openedSocket, { capabilities: capabilities.machineHello, beforePublish: Promise.resolve(), connectionId });
|
|
314
328
|
opts.onOpen?.(ws);
|
|
315
329
|
void sendSnapshot(`reconnect-${randomUUID()}`);
|
|
330
|
+
// 普通回执不等待维护日志IO;两类记录分别重放到同一发送器。
|
|
331
|
+
void migrationExecutionJournal.replay().then(entries => {
|
|
332
|
+
for (const entry of entries)
|
|
333
|
+
if (entry.completion && !entry.completionAcknowledged)
|
|
334
|
+
completionRetransmitter.track(entry.completion);
|
|
335
|
+
}).catch(() => dslog("memory_migration.journal_unavailable", "维护回执重放失败,普通回执继续", { level: "ERROR" }));
|
|
316
336
|
void executionJournal.replay()
|
|
317
337
|
.then((entries) => {
|
|
318
338
|
for (const entry of entries) {
|
|
@@ -387,7 +407,8 @@ export function serve(config, opts = {}) {
|
|
|
387
407
|
return;
|
|
388
408
|
if (frame.type === "execution:completion-ack") {
|
|
389
409
|
try {
|
|
390
|
-
await executionJournal.
|
|
410
|
+
const journal = await executionJournal.get(frame.executionId) ? executionJournal : migrationExecutionJournal;
|
|
411
|
+
await journal.acknowledgeCompletion(frame.executionId);
|
|
391
412
|
const attempts = completionRetransmitter.acknowledge(frame.executionId);
|
|
392
413
|
dslog("execution.completion_acknowledged", "execution completion ACK 已持久化", {
|
|
393
414
|
execution_id: frame.executionId,
|
|
@@ -413,6 +434,8 @@ export function serve(config, opts = {}) {
|
|
|
413
434
|
return;
|
|
414
435
|
}
|
|
415
436
|
if (frame.type === "execution:cancel") {
|
|
437
|
+
if (memoryMigrations.cancel(frame.executionId))
|
|
438
|
+
return;
|
|
416
439
|
if (!knownExecutionHashes.has(frame.executionId)
|
|
417
440
|
&& !executionRuns.has(frame.executionId)
|
|
418
441
|
&& await executionJournal.get(frame.executionId) === null)
|
|
@@ -735,6 +758,8 @@ export function serve(config, opts = {}) {
|
|
|
735
758
|
// ready 帧带 server 视角的 machineId/workspaceId → 作为后续所有日志的默认关联键
|
|
736
759
|
const r = msg;
|
|
737
760
|
setSlogDefaults({ machine_id: r.machineId, workspace_id: r.workspaceId });
|
|
761
|
+
if (r.workspaceId && r.machineId)
|
|
762
|
+
memoryMigrations.setIdentity({ workspaceId: r.workspaceId, machineId: r.machineId });
|
|
738
763
|
if (opts.storageRuntime !== undefined && typeof r.workspaceId === "string" && typeof r.machineId === "string") {
|
|
739
764
|
const bindingSocket = ws;
|
|
740
765
|
bindStorageServerIdentity(opts.storageRuntime, { workspaceId: r.workspaceId, machineId: r.machineId }, {
|
|
@@ -801,6 +826,8 @@ export function serve(config, opts = {}) {
|
|
|
801
826
|
}
|
|
802
827
|
catch { /* server 会按请求超时处理 */ } }))
|
|
803
828
|
return;
|
|
829
|
+
if (await memoryMigrations.handle(msg))
|
|
830
|
+
return;
|
|
804
831
|
if (await agentAbilityRuntime.tryHandleControlMessage(msg, serverCapabilities, (frame) => ws?.send(JSON.stringify(frame))))
|
|
805
832
|
return;
|
|
806
833
|
// 导入 raft agent 工作区:inspect 反填 name/description;import 复制用户内容
|
|
@@ -815,7 +842,7 @@ export function serve(config, opts = {}) {
|
|
|
815
842
|
try {
|
|
816
843
|
const data2 = req.type === "raft:inspect"
|
|
817
844
|
? await inspectRaftWorkspace(req.path)
|
|
818
|
-
: await importRaftWorkspace(req.path, join(config.agentsRoot, req.handle));
|
|
845
|
+
: await withMemoryAccess(join(config.agentsRoot, req.handle), () => importRaftWorkspace(req.path, join(config.agentsRoot, req.handle)), { create: true });
|
|
819
846
|
if (req.type === "raft:import") {
|
|
820
847
|
log(`📦 已导入 raft 工作区 → ${req.handle}: 复制 ${data2.copied.length} 项`);
|
|
821
848
|
}
|
|
@@ -1259,6 +1286,9 @@ export function serve(config, opts = {}) {
|
|
|
1259
1286
|
writeStderr: (line) => process.stderr.write(line),
|
|
1260
1287
|
});
|
|
1261
1288
|
await runProjectSkillStartupCleanup(config.agentsRoot, executionJournal, dslog);
|
|
1289
|
+
migrationExecutionJournal = createMemoryMigrationJournal(config.agentsRoot);
|
|
1290
|
+
await migrationExecutionJournal.reconcileAfterRestart().then(() => { migrationJournalReady = true; })
|
|
1291
|
+
.catch(() => dslog("memory_migration.journal_unavailable", "迁移日志恢复失败,普通执行继续,迁移请求单独报错", { level: "ERROR" }));
|
|
1262
1292
|
await connect();
|
|
1263
1293
|
})();
|
|
1264
1294
|
const stop = () => {
|
|
@@ -1276,6 +1306,7 @@ export function serve(config, opts = {}) {
|
|
|
1276
1306
|
const webSocketClosed = closeWebSocketWithinDeadline(ws, deadline.signal);
|
|
1277
1307
|
const pending = [
|
|
1278
1308
|
machineRuntime.stop(),
|
|
1309
|
+
memoryMigrations.stop(),
|
|
1279
1310
|
webSocketClosed,
|
|
1280
1311
|
updateController.drain(),
|
|
1281
1312
|
marketplace.stop(),
|
|
@@ -1294,6 +1325,8 @@ export function serve(config, opts = {}) {
|
|
|
1294
1325
|
if (executionJournal !== undefined) {
|
|
1295
1326
|
await executionJournal.close({ signal: deadline.signal });
|
|
1296
1327
|
}
|
|
1328
|
+
if (migrationExecutionJournal !== undefined)
|
|
1329
|
+
await migrationExecutionJournal.close({ signal: deadline.signal });
|
|
1297
1330
|
}
|
|
1298
1331
|
finally {
|
|
1299
1332
|
deadline.dispose();
|
package/dist/token.js
CHANGED
|
@@ -7,6 +7,7 @@ export async function mintAgentToken(serverUrl, machineToken, handle, displayNam
|
|
|
7
7
|
},
|
|
8
8
|
// 把本轮唤醒的线程根钉到 per-launch 令牌:服务端据此让 task/消息默认绑/回当前线程。
|
|
9
9
|
body: JSON.stringify({
|
|
10
|
+
memoryStateGuardVersion: 1,
|
|
10
11
|
handle,
|
|
11
12
|
...(displayName ? { displayName } : {}),
|
|
12
13
|
...(options.wakeThreadRoot ? { wakeThreadRoot: options.wakeThreadRoot } : {}),
|
|
@@ -1,9 +1,22 @@
|
|
|
1
1
|
/** 控制面文件/技能查看的按需处理,独立于执行生命周期。 */
|
|
2
|
-
import {
|
|
2
|
+
import { lstat } from "node:fs/promises";
|
|
3
|
+
import { join, resolve } from "node:path";
|
|
3
4
|
import { readSharedMessageFile } from "./message-file-preview.js";
|
|
4
5
|
import { listWorkspace, readWorkspaceFile } from "./workspace-fs.js";
|
|
5
6
|
import { listSkills } from "./skills.js";
|
|
6
7
|
import { listRuntimeModels } from "./list-models.js";
|
|
8
|
+
import { withMemoryAccess } from "./local-memory/migration-access.js";
|
|
9
|
+
async function listProtectedWorkspace(root, path) {
|
|
10
|
+
try {
|
|
11
|
+
await lstat(root);
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
if (error.code !== "ENOENT")
|
|
15
|
+
throw error;
|
|
16
|
+
return { root: resolve(root), path: path.replace(/^\/+/, ""), entries: [] };
|
|
17
|
+
}
|
|
18
|
+
return withMemoryAccess(root, () => listWorkspace(root, path));
|
|
19
|
+
}
|
|
7
20
|
export async function handleWorkspaceControlRequest(raw, agentsRoot, registry, models = listRuntimeModels) {
|
|
8
21
|
if (!raw || typeof raw !== "object")
|
|
9
22
|
return null;
|
|
@@ -15,8 +28,8 @@ export async function handleWorkspaceControlRequest(raw, agentsRoot, registry, m
|
|
|
15
28
|
try {
|
|
16
29
|
const root = join(agentsRoot, request.handle);
|
|
17
30
|
const data = request.type === "fs:read-shared" ? await readSharedMessageFile(agentsRoot, raw, registry)
|
|
18
|
-
: request.type === "fs:list" ? await
|
|
19
|
-
: request.type === "fs:read" ? await readWorkspaceFile(root, request.path)
|
|
31
|
+
: request.type === "fs:list" ? await listProtectedWorkspace(root, request.path)
|
|
32
|
+
: request.type === "fs:read" ? await withMemoryAccess(root, () => readWorkspaceFile(root, request.path))
|
|
20
33
|
: request.type === "skills:list" ? await listSkills(request.runtime)
|
|
21
34
|
: { models: await models(request.runtime ?? "") };
|
|
22
35
|
return { type: "fs:result", reqId: request.reqId, ok: true, data };
|
package/dist/workspace.js
CHANGED
|
@@ -8,12 +8,14 @@
|
|
|
8
8
|
*
|
|
9
9
|
* spawn runtime 时把 <ws>/.crew 置于 PATH 最前,于是 agent 的 `crew ...` 命中 wrapper。
|
|
10
10
|
*/
|
|
11
|
-
import { mkdir, writeFile, readFile, chmod, access, lstat } from "node:fs/promises";
|
|
11
|
+
import { mkdir, writeFile, readFile, chmod, access, lstat, realpath } from "node:fs/promises";
|
|
12
12
|
import { createHash, randomUUID } from "node:crypto";
|
|
13
13
|
import { dirname, join } from "node:path";
|
|
14
14
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
15
15
|
import { createRequire } from "node:module";
|
|
16
16
|
import { dslog } from "./slog.js";
|
|
17
|
+
import { MigrationStateSchema } from "./local-memory/migration-schema.js";
|
|
18
|
+
import { detectLocalMemoryStorageVersion } from "./local-memory/storage-format.js";
|
|
17
19
|
/** 文件系统安全的 taskKey:仅留 [\w.-],其余转 _,截断,避免路径穿越/超长。 */
|
|
18
20
|
export function safeKey(key) {
|
|
19
21
|
return key.replace(/[^\w.-]+/g, "_").replace(/^[-.]+/, "").slice(0, 80) || "default";
|
|
@@ -49,7 +51,13 @@ async function hasLocalMemoryV2Marker(agentDir) {
|
|
|
49
51
|
const stat = await lstat(markerPath);
|
|
50
52
|
if (!stat.isFile() || stat.isSymbolicLink())
|
|
51
53
|
return false;
|
|
52
|
-
|
|
54
|
+
if ((await readFile(markerPath, "utf8")) !== "1\n")
|
|
55
|
+
return false;
|
|
56
|
+
const root = await realpath(agentDir);
|
|
57
|
+
const state = MigrationStateSchema.parse(JSON.parse(await readFile(join(memoryDir, "migration.v1.json"), "utf8")));
|
|
58
|
+
return state.phase === "committed" && state.storageVersion === 2
|
|
59
|
+
&& state.identity.rootFingerprint === createHash("sha256").update(root).digest("hex")
|
|
60
|
+
&& detectLocalMemoryStorageVersion(await readFile(join(root, "MEMORY.md"), "utf8")) === 2;
|
|
53
61
|
}
|
|
54
62
|
catch {
|
|
55
63
|
return false;
|