@mclawnet/agent 0.6.30 → 0.6.32
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/__tests__/hub-connection-preserve-recovery.test.d.ts +2 -0
- package/dist/__tests__/hub-connection-preserve-recovery.test.d.ts.map +1 -0
- package/dist/backend-adapter.d.ts +7 -0
- package/dist/backend-adapter.d.ts.map +1 -1
- package/dist/{chunk-LXSWV3VS.js → chunk-QPLG5WHL.js} +104 -29
- package/dist/chunk-QPLG5WHL.js.map +1 -0
- package/dist/hub-connection.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/session-manager.d.ts +7 -0
- package/dist/session-manager.d.ts.map +1 -1
- package/dist/start.d.ts.map +1 -1
- package/dist/start.js +1 -1
- package/package.json +7 -7
- package/dist/chunk-LXSWV3VS.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hub-connection-preserve-recovery.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/hub-connection-preserve-recovery.test.ts"],"names":[],"mappings":""}
|
|
@@ -46,6 +46,13 @@ export interface SpawnOptions {
|
|
|
46
46
|
mcpConfigPath?: string;
|
|
47
47
|
/** Memory system role ID. When set, SessionManager auto-injects memory prompt + MCP config */
|
|
48
48
|
roleId?: string;
|
|
49
|
+
/**
|
|
50
|
+
* Optional first user input. When set, SessionManager uses this as the
|
|
51
|
+
* semantic-retrieval query for `buildMemorySection` (Pipeline A) so the
|
|
52
|
+
* injected memory section is relevant to what the user is about to ask.
|
|
53
|
+
* Falls back to an empty query (importance-top-K) when omitted.
|
|
54
|
+
*/
|
|
55
|
+
initialUserInput?: string;
|
|
49
56
|
/** Extra directories to mount via --add-dir */
|
|
50
57
|
additionalDirs?: string[];
|
|
51
58
|
/** Optional allowlist of tool names to forward to the backend (PR3.5). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"backend-adapter.d.ts","sourceRoot":"","sources":["../src/backend-ad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ClB,SAAS,EAAE,MAAM,CAAC;QAClB,cAAc,EAAE,MAAM,CAAC;QACvB,eAAe,EAAE,MAAM,CAAC;KACzB,KAAK,IAAI,GACT,IAAI,CAAC;CACT"}
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
MAX_RECONNECT_MS,
|
|
16
16
|
WS_CLOSE_INVALID_TOKEN
|
|
17
17
|
} from "@mclawnet/shared";
|
|
18
|
-
import { listRecoverableSwarms, recoverSwarm, listRoles, loadRole, listRecoverableSwarmIds,
|
|
18
|
+
import { listRecoverableSwarms, recoverSwarm, listRoles, loadRole, listRecoverableSwarmIds, listTemplates, loadTemplate } from "@mclawnet/swarm";
|
|
19
19
|
|
|
20
20
|
// src/fs-handler.ts
|
|
21
21
|
import { readdir } from "fs/promises";
|
|
@@ -470,6 +470,7 @@ async function handleSwarmControl(coord, msg, opts) {
|
|
|
470
470
|
|
|
471
471
|
// src/hub-connection.ts
|
|
472
472
|
import { createLogger as createLogger2, previewFields } from "@mclawnet/logger";
|
|
473
|
+
import { DEFAULT_ASSISTANT_ROLE_ID } from "@mclawnet/memory";
|
|
473
474
|
var log2 = createLogger2({ module: "agent" });
|
|
474
475
|
var HubConnection = class {
|
|
475
476
|
ws = null;
|
|
@@ -598,10 +599,16 @@ var HubConnection = class {
|
|
|
598
599
|
}
|
|
599
600
|
if (this.authState === "authenticated") {
|
|
600
601
|
this.lastAckAt = Date.now();
|
|
602
|
+
if (data && data.type === "heartbeat_ack") {
|
|
603
|
+
return;
|
|
604
|
+
}
|
|
601
605
|
if (this.handleSessionMessage(data)) return;
|
|
602
606
|
this.onMessage?.(data);
|
|
603
607
|
}
|
|
604
608
|
});
|
|
609
|
+
this.ws.on("pong", () => {
|
|
610
|
+
this.lastAckAt = Date.now();
|
|
611
|
+
});
|
|
605
612
|
this.ws.on("close", (code, reason) => {
|
|
606
613
|
log2.warn({ code, reason: reason.toString() }, "disconnected from hub");
|
|
607
614
|
this.stopHeartbeat();
|
|
@@ -1014,10 +1021,12 @@ var HubConnection = class {
|
|
|
1014
1021
|
workDir,
|
|
1015
1022
|
resumeId,
|
|
1016
1023
|
useBrainCore,
|
|
1017
|
-
roleId:
|
|
1024
|
+
roleId: DEFAULT_ASSISTANT_ROLE_ID,
|
|
1018
1025
|
maxOutputTokens
|
|
1019
1026
|
}).then(() => {
|
|
1020
|
-
sm.
|
|
1027
|
+
sm.sendUserInput(sessionId, content).catch((err) => {
|
|
1028
|
+
log2.warn({ err, sessionId }, "sendUserInput failed");
|
|
1029
|
+
});
|
|
1021
1030
|
}).catch((err) => {
|
|
1022
1031
|
this.send({
|
|
1023
1032
|
type: "session.error",
|
|
@@ -1029,7 +1038,9 @@ var HubConnection = class {
|
|
|
1029
1038
|
if (sm.isHealthy(sessionId)) {
|
|
1030
1039
|
log2.info({ sessionId }, "claude.execute: reusing healthy session");
|
|
1031
1040
|
log2.debug({ sessionId, ...previewFields(content) }, "claude.execute: input");
|
|
1032
|
-
sm.
|
|
1041
|
+
sm.sendUserInput(sessionId, content).catch((err) => {
|
|
1042
|
+
log2.warn({ err, sessionId }, "sendUserInput failed");
|
|
1043
|
+
});
|
|
1033
1044
|
} else if (sm.hasSession(sessionId) && claudeSessionId) {
|
|
1034
1045
|
const recommendedMax = sm.getRecommendedMaxOutputTokens(sessionId);
|
|
1035
1046
|
log2.warn({ sessionId, claudeSessionId }, "claude.execute: session unhealthy, recreating with --resume");
|
|
@@ -1069,12 +1080,12 @@ var HubConnection = class {
|
|
|
1069
1080
|
return true;
|
|
1070
1081
|
}
|
|
1071
1082
|
if (msg.type === "session.create") {
|
|
1072
|
-
log2.info({ sessionId: msg.sessionId, roleId:
|
|
1083
|
+
log2.info({ sessionId: msg.sessionId, roleId: DEFAULT_ASSISTANT_ROLE_ID }, "session.create with memory injection");
|
|
1073
1084
|
this.sessionManager.createSession({
|
|
1074
1085
|
sessionId: msg.sessionId,
|
|
1075
1086
|
workDir: msg.workDir,
|
|
1076
1087
|
resumeId: msg.resumeId,
|
|
1077
|
-
roleId:
|
|
1088
|
+
roleId: DEFAULT_ASSISTANT_ROLE_ID
|
|
1078
1089
|
}).then((claudeSessionId) => {
|
|
1079
1090
|
this.send({
|
|
1080
1091
|
type: "session.created",
|
|
@@ -1101,7 +1112,9 @@ var HubConnection = class {
|
|
|
1101
1112
|
{ sessionId: msg.sessionId, ...previewFields(msg.content) },
|
|
1102
1113
|
"claude.input"
|
|
1103
1114
|
);
|
|
1104
|
-
this.sessionManager.
|
|
1115
|
+
this.sessionManager.sendUserInput(msg.sessionId, msg.content).catch((err) => {
|
|
1116
|
+
log2.warn({ err, sessionId: msg.sessionId }, "sendUserInput failed");
|
|
1117
|
+
});
|
|
1105
1118
|
return true;
|
|
1106
1119
|
}
|
|
1107
1120
|
return false;
|
|
@@ -1113,10 +1126,9 @@ var HubConnection = class {
|
|
|
1113
1126
|
const allIds = listRecoverableSwarmIds();
|
|
1114
1127
|
const snapshots = listRecoverableSwarms();
|
|
1115
1128
|
const recoverableIds = new Set(snapshots.map((s) => s.id));
|
|
1116
|
-
for (const {
|
|
1129
|
+
for (const { swarmId } of allIds) {
|
|
1117
1130
|
if (!recoverableIds.has(swarmId)) {
|
|
1118
|
-
|
|
1119
|
-
log2.info({ swarmId }, "cleaned up non-recoverable swarm snapshot");
|
|
1131
|
+
log2.info({ swarmId }, "skipping non-recoverable swarm snapshot (kept on disk)");
|
|
1120
1132
|
}
|
|
1121
1133
|
}
|
|
1122
1134
|
for (const snap of snapshots) {
|
|
@@ -1161,6 +1173,10 @@ var HubConnection = class {
|
|
|
1161
1173
|
return;
|
|
1162
1174
|
}
|
|
1163
1175
|
this.send({ type: "heartbeat", ts: Date.now() });
|
|
1176
|
+
try {
|
|
1177
|
+
this.ws?.ping();
|
|
1178
|
+
} catch {
|
|
1179
|
+
}
|
|
1164
1180
|
}, this.heartbeatInterval);
|
|
1165
1181
|
}
|
|
1166
1182
|
stopHeartbeat() {
|
|
@@ -1694,7 +1710,12 @@ function makeRealSwarmStarter(_deps) {
|
|
|
1694
1710
|
|
|
1695
1711
|
// src/session-manager.ts
|
|
1696
1712
|
import { createLogger as createLogger5, previewFields as previewFields2 } from "@mclawnet/logger";
|
|
1697
|
-
import {
|
|
1713
|
+
import {
|
|
1714
|
+
buildMemorySection,
|
|
1715
|
+
EmbeddingService,
|
|
1716
|
+
createEmbeddingProviders,
|
|
1717
|
+
initDatabase
|
|
1718
|
+
} from "@mclawnet/memory";
|
|
1698
1719
|
import { MAX_TOKENS_LADDER, clampLadderIndex } from "@mclawnet/shared";
|
|
1699
1720
|
|
|
1700
1721
|
// src/skill-loader.ts
|
|
@@ -2056,6 +2077,13 @@ function isPidAlive(pid) {
|
|
|
2056
2077
|
}
|
|
2057
2078
|
|
|
2058
2079
|
// src/session-manager.ts
|
|
2080
|
+
var sharedEmbeddingService = null;
|
|
2081
|
+
function getSharedEmbeddingService() {
|
|
2082
|
+
if (sharedEmbeddingService) return sharedEmbeddingService;
|
|
2083
|
+
const db = initDatabase();
|
|
2084
|
+
sharedEmbeddingService = new EmbeddingService(db, createEmbeddingProviders());
|
|
2085
|
+
return sharedEmbeddingService;
|
|
2086
|
+
}
|
|
2059
2087
|
var log5 = createLogger5({ module: "agent/session-manager" });
|
|
2060
2088
|
var DEFAULT_MAX_PROCESSES = 30;
|
|
2061
2089
|
var MAX_PROCESSES = Number(process.env.CLAWNET_MAX_PROCESSES) || DEFAULT_MAX_PROCESSES;
|
|
@@ -2162,19 +2190,26 @@ var SessionManager = class {
|
|
|
2162
2190
|
if (this.sessions.size >= MAX_PROCESSES) {
|
|
2163
2191
|
throw new SessionLimitReachedError(this.snapshotPoolForError());
|
|
2164
2192
|
}
|
|
2165
|
-
if (options.
|
|
2193
|
+
if (options.workDir) {
|
|
2166
2194
|
try {
|
|
2167
|
-
const
|
|
2168
|
-
const
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2195
|
+
const query = options.initialUserInput ?? "";
|
|
2196
|
+
const memorySection = await buildMemorySection({
|
|
2197
|
+
query,
|
|
2198
|
+
workDir: options.workDir,
|
|
2199
|
+
embeddingService: getSharedEmbeddingService()
|
|
2200
|
+
});
|
|
2201
|
+
options.systemPrompt = options.systemPrompt ? `${memorySection}
|
|
2172
2202
|
|
|
2173
|
-
${options.systemPrompt}` :
|
|
2174
|
-
log5.debug({
|
|
2203
|
+
${options.systemPrompt}` : memorySection;
|
|
2204
|
+
log5.debug({ workDir: options.workDir, sessionId: options.sessionId }, "memory prompt injected");
|
|
2175
2205
|
} catch (err) {
|
|
2176
|
-
log5.warn({ err,
|
|
2206
|
+
log5.warn({ err, workDir: options.workDir }, "failed to build memory section, proceeding without");
|
|
2177
2207
|
}
|
|
2208
|
+
} else {
|
|
2209
|
+
log5.warn(
|
|
2210
|
+
{ sessionId: options.sessionId, roleId: options.roleId },
|
|
2211
|
+
"session created without workDir \u2014 memory injection skipped (all memories would be cross-workdir; pass workDir to enable scoped retrieval)"
|
|
2212
|
+
);
|
|
2178
2213
|
}
|
|
2179
2214
|
try {
|
|
2180
2215
|
const notice = getPendingNotification();
|
|
@@ -2192,6 +2227,12 @@ ${notice.text}`;
|
|
|
2192
2227
|
} catch (err) {
|
|
2193
2228
|
log5.debug({ err }, "failed to inject pending notification");
|
|
2194
2229
|
}
|
|
2230
|
+
if (this.classify(options.sessionId) === "chat") {
|
|
2231
|
+
const ideaHint = `
|
|
2232
|
+
|
|
2233
|
+
[Idea Capture] When you propose a concrete user-actionable idea, feature suggestion, or follow-up TODO, additionally emit a single tag like \`<idea title="short title" body="one-paragraph context"/>\` at the end of that paragraph. Keep it concise and use it sparingly \u2014 only for things the user would plausibly want to save and revisit. The tag itself will be hidden from the chat view.`;
|
|
2234
|
+
options.systemPrompt = options.systemPrompt ? `${options.systemPrompt}${ideaHint}` : ideaHint.trimStart();
|
|
2235
|
+
}
|
|
2195
2236
|
try {
|
|
2196
2237
|
const process2 = await this.adapter.spawn(options);
|
|
2197
2238
|
this.sessions.set(options.sessionId, process2);
|
|
@@ -2344,6 +2385,39 @@ ${notice.text}`;
|
|
|
2344
2385
|
);
|
|
2345
2386
|
this.adapter.send(process2, input);
|
|
2346
2387
|
}
|
|
2388
|
+
/**
|
|
2389
|
+
* User-input variant of sendInput: best-effort prepend a `<memory-context>`
|
|
2390
|
+
* block sourced from semantic retrieval (Pipeline B). Falls back to plain
|
|
2391
|
+
* sendInput if retrieval errors or exceeds the 200ms budget — we never
|
|
2392
|
+
* block the user's turn on memory.
|
|
2393
|
+
*/
|
|
2394
|
+
async sendUserInput(sessionId, content) {
|
|
2395
|
+
const meta = this.sessionMeta.get(sessionId);
|
|
2396
|
+
const workDir = meta?.workDir;
|
|
2397
|
+
let prefixed = content;
|
|
2398
|
+
try {
|
|
2399
|
+
const section = await Promise.race([
|
|
2400
|
+
buildMemorySection({
|
|
2401
|
+
query: content,
|
|
2402
|
+
workDir,
|
|
2403
|
+
embeddingService: getSharedEmbeddingService()
|
|
2404
|
+
}),
|
|
2405
|
+
new Promise(
|
|
2406
|
+
(resolve) => setTimeout(() => resolve(""), 200)
|
|
2407
|
+
)
|
|
2408
|
+
]);
|
|
2409
|
+
if (section && section.trim().length > 0) {
|
|
2410
|
+
prefixed = `<memory-context>
|
|
2411
|
+
${section}
|
|
2412
|
+
</memory-context>
|
|
2413
|
+
|
|
2414
|
+
${content}`;
|
|
2415
|
+
}
|
|
2416
|
+
} catch (err) {
|
|
2417
|
+
log5.debug({ err, sessionId }, "sendUserInput: memory retrieval skipped");
|
|
2418
|
+
}
|
|
2419
|
+
this.sendInput(sessionId, prefixed);
|
|
2420
|
+
}
|
|
2347
2421
|
async abortSession(sessionId) {
|
|
2348
2422
|
const process2 = this.sessions.get(sessionId);
|
|
2349
2423
|
if (!process2) return;
|
|
@@ -3051,11 +3125,12 @@ function createSwarmAwareSessionStartedHandler(deps) {
|
|
|
3051
3125
|
// src/start.ts
|
|
3052
3126
|
import { createLogger as createLogger9 } from "@mclawnet/logger";
|
|
3053
3127
|
import {
|
|
3054
|
-
initDatabase,
|
|
3128
|
+
initDatabase as initDatabase2,
|
|
3055
3129
|
MemoryStore,
|
|
3056
|
-
EmbeddingService,
|
|
3057
|
-
createEmbeddingProviders,
|
|
3058
|
-
distillConversation
|
|
3130
|
+
EmbeddingService as EmbeddingService2,
|
|
3131
|
+
createEmbeddingProviders as createEmbeddingProviders2,
|
|
3132
|
+
distillConversation,
|
|
3133
|
+
DEFAULT_ASSISTANT_ROLE_ID as DEFAULT_ASSISTANT_ROLE_ID2
|
|
3059
3134
|
} from "@mclawnet/memory";
|
|
3060
3135
|
import {
|
|
3061
3136
|
SkillStore,
|
|
@@ -3120,9 +3195,9 @@ async function startAgent(options) {
|
|
|
3120
3195
|
let skillStore = null;
|
|
3121
3196
|
let memoryDb = null;
|
|
3122
3197
|
try {
|
|
3123
|
-
memoryDb =
|
|
3198
|
+
memoryDb = initDatabase2(dbPath);
|
|
3124
3199
|
memoryStore = new MemoryStore(memoryDb);
|
|
3125
|
-
embeddingService = new
|
|
3200
|
+
embeddingService = new EmbeddingService2(memoryDb, createEmbeddingProviders2());
|
|
3126
3201
|
skillStore = new SkillStore(clawnetDir);
|
|
3127
3202
|
evolutionPipeline = new EvolutionPipeline(clawnetDir);
|
|
3128
3203
|
} catch (err) {
|
|
@@ -3134,7 +3209,7 @@ async function startAgent(options) {
|
|
|
3134
3209
|
try {
|
|
3135
3210
|
await distillConversation(
|
|
3136
3211
|
messages,
|
|
3137
|
-
|
|
3212
|
+
DEFAULT_ASSISTANT_ROLE_ID2,
|
|
3138
3213
|
memoryStore,
|
|
3139
3214
|
embeddingService
|
|
3140
3215
|
);
|
|
@@ -3145,7 +3220,7 @@ async function startAgent(options) {
|
|
|
3145
3220
|
if (!skillStore || !evolutionPipeline) return;
|
|
3146
3221
|
const skills = skillStore.scan();
|
|
3147
3222
|
if (skills.length === 0) return;
|
|
3148
|
-
const recent = memoryStore.
|
|
3223
|
+
const recent = memoryStore.getRecentMemoriesByRole(DEFAULT_ASSISTANT_ROLE_ID2, { limit: 50 });
|
|
3149
3224
|
const refs = recent.map((m) => ({
|
|
3150
3225
|
id: m.id,
|
|
3151
3226
|
type: m.type,
|
|
@@ -3265,4 +3340,4 @@ export {
|
|
|
3265
3340
|
FsBridge,
|
|
3266
3341
|
startAgent
|
|
3267
3342
|
};
|
|
3268
|
-
//# sourceMappingURL=chunk-
|
|
3343
|
+
//# sourceMappingURL=chunk-QPLG5WHL.js.map
|