nextclaw 0.6.12 → 0.6.13
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/index.js +42 -75
- package/package.json +2 -2
package/dist/cli/index.js
CHANGED
|
@@ -89,7 +89,6 @@ import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "fs";
|
|
|
89
89
|
import { resolve } from "path";
|
|
90
90
|
import { getDataDir } from "@nextclaw/core";
|
|
91
91
|
var RESTART_SENTINEL_FILENAME = "restart-sentinel.json";
|
|
92
|
-
var PENDING_SYSTEM_EVENTS_KEY = "pending_system_events";
|
|
93
92
|
var RESTART_REASON_MAX_CHARS = 240;
|
|
94
93
|
var RESTART_NOTE_MAX_CHARS = 600;
|
|
95
94
|
var RESTART_OUTBOUND_MAX_CHARS = 1200;
|
|
@@ -180,25 +179,6 @@ function parseSessionKey(sessionKey) {
|
|
|
180
179
|
chatId: value.slice(separator + 1)
|
|
181
180
|
};
|
|
182
181
|
}
|
|
183
|
-
function enqueuePendingSystemEvent(sessionManager, sessionKey, message) {
|
|
184
|
-
const text = message.trim();
|
|
185
|
-
if (!text) {
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
const session = sessionManager.getOrCreate(sessionKey);
|
|
189
|
-
const queueRaw = session.metadata[PENDING_SYSTEM_EVENTS_KEY];
|
|
190
|
-
const queue = Array.isArray(queueRaw) ? queueRaw.filter((item) => typeof item === "string").map((item) => item.trim()).filter(Boolean) : [];
|
|
191
|
-
if (queue.at(-1) === text) {
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
queue.push(text);
|
|
195
|
-
if (queue.length > 20) {
|
|
196
|
-
queue.splice(0, queue.length - 20);
|
|
197
|
-
}
|
|
198
|
-
session.metadata[PENDING_SYSTEM_EVENTS_KEY] = queue;
|
|
199
|
-
session.updatedAt = /* @__PURE__ */ new Date();
|
|
200
|
-
sessionManager.save(session);
|
|
201
|
-
}
|
|
202
182
|
|
|
203
183
|
// src/cli/skills/clawhub.ts
|
|
204
184
|
import { spawnSync } from "child_process";
|
|
@@ -2503,7 +2483,7 @@ var ServiceCommands = class {
|
|
|
2503
2483
|
}
|
|
2504
2484
|
}
|
|
2505
2485
|
await reloader.getChannels().startAll();
|
|
2506
|
-
await this.wakeFromRestartSentinel({
|
|
2486
|
+
await this.wakeFromRestartSentinel({ bus, sessionManager });
|
|
2507
2487
|
await agent.run();
|
|
2508
2488
|
} finally {
|
|
2509
2489
|
await stopPluginChannelGateways(pluginGatewayHandles);
|
|
@@ -2517,9 +2497,6 @@ var ServiceCommands = class {
|
|
|
2517
2497
|
const trimmed = value.trim();
|
|
2518
2498
|
return trimmed || void 0;
|
|
2519
2499
|
}
|
|
2520
|
-
async sleep(ms) {
|
|
2521
|
-
await new Promise((resolve10) => setTimeout(resolve10, ms));
|
|
2522
|
-
}
|
|
2523
2500
|
resolveMostRecentRoutableSessionKey(sessionManager) {
|
|
2524
2501
|
const sessions = sessionManager.listSessions();
|
|
2525
2502
|
let best = null;
|
|
@@ -2546,42 +2523,27 @@ var ServiceCommands = class {
|
|
|
2546
2523
|
}
|
|
2547
2524
|
return best?.key;
|
|
2548
2525
|
}
|
|
2549
|
-
|
|
2550
|
-
const
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
const
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
] : [{ ...outboundBase }];
|
|
2561
|
-
for (let variantIndex = 0; variantIndex < variants.length; variantIndex += 1) {
|
|
2562
|
-
const outbound = variants[variantIndex];
|
|
2563
|
-
const isLastVariant = variantIndex === variants.length - 1;
|
|
2564
|
-
for (let attempt = 1; attempt <= 3; attempt += 1) {
|
|
2565
|
-
try {
|
|
2566
|
-
const delivered = await params.channels.deliver(outbound);
|
|
2567
|
-
if (delivered) {
|
|
2568
|
-
return true;
|
|
2569
|
-
}
|
|
2570
|
-
return false;
|
|
2571
|
-
} catch (error) {
|
|
2572
|
-
if (attempt < 3) {
|
|
2573
|
-
await this.sleep(attempt * 500);
|
|
2574
|
-
continue;
|
|
2575
|
-
}
|
|
2576
|
-
if (isLastVariant) {
|
|
2577
|
-
console.warn(
|
|
2578
|
-
`Warning: restart sentinel notify failed for ${params.channel}:${params.chatId} (attempt ${attempt}): ${String(error)}`
|
|
2579
|
-
);
|
|
2580
|
-
}
|
|
2581
|
-
}
|
|
2582
|
-
}
|
|
2526
|
+
buildRestartWakePrompt(params) {
|
|
2527
|
+
const lines = [
|
|
2528
|
+
"System event: the gateway has restarted successfully.",
|
|
2529
|
+
"Please send one short confirmation to the user that you are back online.",
|
|
2530
|
+
"Do not call any tools.",
|
|
2531
|
+
"Use the same language as the user's recent conversation.",
|
|
2532
|
+
`Reference summary: ${params.summary}`
|
|
2533
|
+
];
|
|
2534
|
+
const reason = this.normalizeOptionalString(params.reason);
|
|
2535
|
+
if (reason) {
|
|
2536
|
+
lines.push(`Restart reason: ${reason}`);
|
|
2583
2537
|
}
|
|
2584
|
-
|
|
2538
|
+
const note = this.normalizeOptionalString(params.note);
|
|
2539
|
+
if (note) {
|
|
2540
|
+
lines.push(`Extra note: ${note}`);
|
|
2541
|
+
}
|
|
2542
|
+
const replyTo = this.normalizeOptionalString(params.replyTo);
|
|
2543
|
+
if (replyTo) {
|
|
2544
|
+
lines.push(`Reply target message id: ${replyTo}. If suitable, include [[reply_to:${replyTo}]].`);
|
|
2545
|
+
}
|
|
2546
|
+
return lines.join("\n");
|
|
2585
2547
|
}
|
|
2586
2548
|
async wakeFromRestartSentinel(params) {
|
|
2587
2549
|
const sentinel = await consumeRestartSentinel();
|
|
@@ -2590,7 +2552,7 @@ var ServiceCommands = class {
|
|
|
2590
2552
|
}
|
|
2591
2553
|
await new Promise((resolve10) => setTimeout(resolve10, 750));
|
|
2592
2554
|
const payload = sentinel.payload;
|
|
2593
|
-
const
|
|
2555
|
+
const summary = formatRestartSentinelMessage(payload);
|
|
2594
2556
|
const sentinelSessionKey = this.normalizeOptionalString(payload.sessionKey);
|
|
2595
2557
|
const fallbackSessionKey = sentinelSessionKey ? void 0 : this.resolveMostRecentRoutableSessionKey(params.sessionManager);
|
|
2596
2558
|
if (!sentinelSessionKey && fallbackSessionKey) {
|
|
@@ -2603,26 +2565,31 @@ var ServiceCommands = class {
|
|
|
2603
2565
|
const chatId = this.normalizeOptionalString(context?.chatId) ?? parsedSession?.chatId ?? this.normalizeOptionalString((params.sessionManager.getIfExists(sessionKey)?.metadata ?? {}).last_to);
|
|
2604
2566
|
const replyTo = this.normalizeOptionalString(context?.replyTo);
|
|
2605
2567
|
const accountId = this.normalizeOptionalString(context?.accountId);
|
|
2606
|
-
const metadataRaw = context?.metadata;
|
|
2607
|
-
const metadata = metadataRaw && typeof metadataRaw === "object" && !Array.isArray(metadataRaw) ? { ...metadataRaw } : {};
|
|
2608
|
-
if (accountId && !this.normalizeOptionalString(metadata.accountId)) {
|
|
2609
|
-
metadata.accountId = accountId;
|
|
2610
|
-
}
|
|
2611
2568
|
if (!channel || !chatId) {
|
|
2612
|
-
|
|
2569
|
+
console.warn(`Warning: restart sentinel cannot resolve route for session ${sessionKey}.`);
|
|
2613
2570
|
return;
|
|
2614
2571
|
}
|
|
2615
|
-
const
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2572
|
+
const prompt2 = this.buildRestartWakePrompt({
|
|
2573
|
+
summary,
|
|
2574
|
+
reason: this.normalizeOptionalString(payload.stats?.reason),
|
|
2575
|
+
note: this.normalizeOptionalString(payload.message),
|
|
2576
|
+
...replyTo ? { replyTo } : {}
|
|
2577
|
+
});
|
|
2578
|
+
const metadata = {
|
|
2579
|
+
source: "restart-sentinel",
|
|
2580
|
+
restart_summary: summary,
|
|
2581
|
+
...replyTo ? { reply_to: replyTo } : {},
|
|
2582
|
+
...accountId ? { account_id: accountId, accountId } : {}
|
|
2583
|
+
};
|
|
2584
|
+
await params.bus.publishInbound({
|
|
2585
|
+
channel: "system",
|
|
2586
|
+
senderId: "restart-sentinel",
|
|
2587
|
+
chatId: `${channel}:${chatId}`,
|
|
2588
|
+
content: prompt2,
|
|
2589
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
2590
|
+
attachments: [],
|
|
2621
2591
|
metadata
|
|
2622
2592
|
});
|
|
2623
|
-
if (!delivered) {
|
|
2624
|
-
enqueuePendingSystemEvent(params.sessionManager, sessionKey, message);
|
|
2625
|
-
}
|
|
2626
2593
|
}
|
|
2627
2594
|
async runForeground(options) {
|
|
2628
2595
|
const config2 = loadConfig5();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nextclaw",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.13",
|
|
4
4
|
"description": "Lightweight personal AI assistant with CLI, multi-provider routing, and channel integrations.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"chokidar": "^3.6.0",
|
|
40
40
|
"commander": "^12.1.0",
|
|
41
|
-
"@nextclaw/core": "^0.6.
|
|
41
|
+
"@nextclaw/core": "^0.6.11",
|
|
42
42
|
"@nextclaw/server": "^0.4.2",
|
|
43
43
|
"@nextclaw/openclaw-compat": "^0.1.5"
|
|
44
44
|
},
|