@unblocklabs/unblock-memory 0.12.2 → 0.12.3
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/src/memory-whisperer.js +6 -2
- package/dist/src/people-learning-runtime.js +72 -10
- package/dist/src/query-generator.d.ts +1 -1
- package/dist/src/query-generator.js +15 -8
- package/dist/src/response-text.d.ts +2 -0
- package/dist/src/response-text.js +182 -36
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
|
@@ -18,7 +18,7 @@ export function registerMemoryWhisperer(api, runtime, config, typesafe, diagnost
|
|
|
18
18
|
const beforePrompt = async (event, context) => {
|
|
19
19
|
const { agentId, runId, sessionId, sessionKey } = context;
|
|
20
20
|
const scope = sessionId || sessionKey;
|
|
21
|
-
if (context.trigger !== "user" || !agentId || !runId || !scope
|
|
21
|
+
if (context.trigger !== "user" || !agentId || !runId || !scope)
|
|
22
22
|
return;
|
|
23
23
|
const corpora = config.corpora;
|
|
24
24
|
if (!corpora.length)
|
|
@@ -27,6 +27,10 @@ export function registerMemoryWhisperer(api, runtime, config, typesafe, diagnost
|
|
|
27
27
|
const previous = sessions.get(key);
|
|
28
28
|
if (previous?.runId === runId)
|
|
29
29
|
return previous.result;
|
|
30
|
+
const currentUserMessage = typeof event.currentUserMessage === "string" ? event.currentUserMessage : undefined;
|
|
31
|
+
const rawCurrent = currentUserMessage !== undefined ? currentUserMessage : event.prompt;
|
|
32
|
+
if (!rawCurrent.replace(/^\s*From: [^\r\n]+ \([^()\r\n]+\)\s*$/, "").trim())
|
|
33
|
+
return;
|
|
30
34
|
const started = performance.now();
|
|
31
35
|
const asOf = new Date().toISOString();
|
|
32
36
|
const measurement = { outcome: "skipped", elapsedMs: 0 };
|
|
@@ -55,7 +59,7 @@ export function registerMemoryWhisperer(api, runtime, config, typesafe, diagnost
|
|
|
55
59
|
signal.addEventListener("abort", onAbort, { once: true });
|
|
56
60
|
});
|
|
57
61
|
const run = async () => {
|
|
58
|
-
const conversation = queryConversation(event.prompt, event.messages);
|
|
62
|
+
const conversation = queryConversation(event.prompt, event.messages, currentUserMessage);
|
|
59
63
|
stage = "credentials";
|
|
60
64
|
const apiKey = await timeStage("setupMs", measurement, signal, () => resolveTypeSafeApiKey(typesafe));
|
|
61
65
|
if (signal.aborted)
|
|
@@ -135,32 +135,80 @@ function reviewCohort(manifest) {
|
|
|
135
135
|
function analysisBasis(config, manifest) {
|
|
136
136
|
return jsonHash([responseCohort(config.responseAudit), config.responseAudit.lookbackDays, manifest]);
|
|
137
137
|
}
|
|
138
|
+
const STARTUP_RETRY_DELAY_MS = 5_000;
|
|
139
|
+
const RETRY_DELAY_MS = 60_000;
|
|
140
|
+
const MAX_QUIET_STARTUP_RETRIES = 8;
|
|
141
|
+
function isStartupPrepError(error) {
|
|
142
|
+
return /not completed startup inspection and preparation/i.test(String(error));
|
|
143
|
+
}
|
|
138
144
|
export function registerPeopleLearning(api, initial, stores) {
|
|
139
145
|
let cfg = api.config, config = initial, stateRoot = resolveStateDir(), live = false;
|
|
140
|
-
let jobs = [], reconciliation;
|
|
146
|
+
let jobs = [], reconciliation, followUp;
|
|
147
|
+
let rerun = false, startupRetries = 0;
|
|
141
148
|
let getCron;
|
|
142
149
|
let generation = 0;
|
|
143
150
|
let scheduler;
|
|
151
|
+
let retryTask;
|
|
152
|
+
const clearRetry = () => { retryTask?.cancel?.(); retryTask = undefined; };
|
|
153
|
+
const scheduleRetry = (delayMs) => {
|
|
154
|
+
clearRetry();
|
|
155
|
+
if (!live || !scheduler || scheduler.signal?.aborted)
|
|
156
|
+
return;
|
|
157
|
+
try {
|
|
158
|
+
retryTask = scheduler.schedule({ id: "people-learning-reconcile", delayMs, run: reconcile });
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
// Host scheduler can close concurrently during gateway shutdown or reload.
|
|
162
|
+
}
|
|
163
|
+
};
|
|
144
164
|
const reconcile = () => {
|
|
145
165
|
if (!live)
|
|
146
166
|
return Promise.resolve();
|
|
147
|
-
if (reconciliation)
|
|
148
|
-
|
|
167
|
+
if (reconciliation) {
|
|
168
|
+
rerun = true;
|
|
169
|
+
if (!followUp) {
|
|
170
|
+
const next = () => {
|
|
171
|
+
followUp = undefined;
|
|
172
|
+
if (!live || !rerun)
|
|
173
|
+
return;
|
|
174
|
+
rerun = false;
|
|
175
|
+
return reconcile();
|
|
176
|
+
};
|
|
177
|
+
followUp = reconciliation.then(next, next);
|
|
178
|
+
}
|
|
179
|
+
return followUp;
|
|
180
|
+
}
|
|
149
181
|
const cron = getCron?.();
|
|
150
182
|
if (!cron) {
|
|
151
183
|
api.logger.warn("unblock-memory people learning incomplete: this host does not expose service getCron; upgrade the host");
|
|
152
184
|
return Promise.resolve();
|
|
153
185
|
}
|
|
186
|
+
rerun = false;
|
|
154
187
|
const version = generation;
|
|
155
188
|
const learning = config.people.enabled && config.people.whisperer.enabled ? config.people.learning
|
|
156
189
|
: { ...config.people.learning, enabled: false, agents: {} };
|
|
157
190
|
reconciliation = reconcilePeopleLearning(cron, cfg, learning, () => live && version === generation)
|
|
158
|
-
.then(result => {
|
|
159
|
-
|
|
191
|
+
.then(result => {
|
|
192
|
+
if (live && version === generation) {
|
|
193
|
+
jobs = result;
|
|
194
|
+
startupRetries = 0;
|
|
195
|
+
clearRetry();
|
|
196
|
+
}
|
|
197
|
+
})
|
|
160
198
|
.catch(error => {
|
|
199
|
+
if (!live || version !== generation)
|
|
200
|
+
return;
|
|
201
|
+
rerun = false;
|
|
202
|
+
if (isStartupPrepError(error) && scheduler && !scheduler.signal?.aborted && startupRetries < MAX_QUIET_STARTUP_RETRIES) {
|
|
203
|
+
startupRetries++;
|
|
204
|
+
if (startupRetries === 1) {
|
|
205
|
+
api.logger.info?.("unblock-memory people learning scheduling deferred until agent startup preparation completes");
|
|
206
|
+
}
|
|
207
|
+
scheduleRetry(STARTUP_RETRY_DELAY_MS);
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
161
210
|
api.logger.warn(`unblock-memory people learning scheduling incomplete: ${String(error)}`);
|
|
162
|
-
|
|
163
|
-
scheduler?.schedule({ id: "people-learning-reconcile", delayMs: 60_000, run: reconcile });
|
|
211
|
+
scheduleRetry(RETRY_DELAY_MS);
|
|
164
212
|
})
|
|
165
213
|
.finally(() => { reconciliation = undefined; });
|
|
166
214
|
return reconciliation;
|
|
@@ -173,21 +221,35 @@ export function registerPeopleLearning(api, initial, stores) {
|
|
|
173
221
|
stateRoot = context.stateDir;
|
|
174
222
|
const entry = cfg.plugins?.entries?.["unblock-memory"];
|
|
175
223
|
config = resolveConfig(entry ? entry.config : api.pluginConfig);
|
|
224
|
+
clearRetry();
|
|
176
225
|
live = true;
|
|
177
226
|
generation++;
|
|
227
|
+
startupRetries = 0;
|
|
228
|
+
rerun = false;
|
|
178
229
|
getCron = context.getCron?.bind(context);
|
|
179
230
|
scheduler = context.scheduler;
|
|
180
231
|
void reconcile();
|
|
181
232
|
},
|
|
182
|
-
async stop() {
|
|
233
|
+
async stop() {
|
|
234
|
+
live = false;
|
|
235
|
+
const stopVersion = ++generation;
|
|
236
|
+
rerun = false;
|
|
237
|
+
startupRetries = 0;
|
|
238
|
+
clearRetry();
|
|
239
|
+
await reconciliation?.catch(() => { });
|
|
240
|
+
await followUp?.catch(() => { });
|
|
241
|
+
if (stopVersion === generation)
|
|
242
|
+
jobs = [];
|
|
243
|
+
},
|
|
183
244
|
});
|
|
184
245
|
api.on("gateway_start", () => reconcile());
|
|
185
246
|
api.on("cron_reconciled", (_event, context) => {
|
|
186
247
|
if (context.config) {
|
|
248
|
+
const entry = context.config.plugins?.entries?.["unblock-memory"];
|
|
249
|
+
const nextConfig = resolveConfig(entry ? entry.config : api.pluginConfig);
|
|
187
250
|
generation++;
|
|
188
251
|
cfg = context.config;
|
|
189
|
-
|
|
190
|
-
config = resolveConfig(entry ? entry.config : api.pluginConfig);
|
|
252
|
+
config = nextConfig;
|
|
191
253
|
}
|
|
192
254
|
return reconcile();
|
|
193
255
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { UnblockMemoryConfig } from "./config.js";
|
|
2
2
|
import { type QueryConversation, type QueryPair } from "./query-contract.js";
|
|
3
3
|
/** Preserve whole visible messages and the complete current request, never tool/thinking text. */
|
|
4
|
-
export declare function queryConversation(prompt: string, messages: readonly unknown[]): QueryConversation;
|
|
4
|
+
export declare function queryConversation(prompt: string, messages: readonly unknown[], currentUserMessage?: string): QueryConversation;
|
|
5
5
|
/** Deterministic query pair used when the resident query API fails or times out. */
|
|
6
6
|
export declare function fallbackQueries(conversation: QueryConversation): QueryPair;
|
|
7
7
|
/** Bound conversation context repeated across automatic passage usefulness judgments. */
|
|
@@ -2,12 +2,12 @@ import { randomUUID } from "node:crypto";
|
|
|
2
2
|
import { readFile } from "node:fs/promises";
|
|
3
3
|
import { abortable, abortedByTimeout } from "./abortable.js";
|
|
4
4
|
import { messageText } from "./whisperer-context.js";
|
|
5
|
-
import {
|
|
5
|
+
import { CONVERSATION_INFO, queryUserText } from "./response-text.js";
|
|
6
6
|
import { parseQueryPair, prepareQueryConversation } from "./query-contract.js";
|
|
7
|
-
import { record } from "./guards.js";
|
|
7
|
+
import { nonBlank, record } from "./guards.js";
|
|
8
8
|
/** Preserve whole visible messages and the complete current request, never tool/thinking text. */
|
|
9
|
-
export function queryConversation(prompt, messages) {
|
|
10
|
-
const currentRequest =
|
|
9
|
+
export function queryConversation(prompt, messages, currentUserMessage) {
|
|
10
|
+
const currentRequest = queryUserText(currentUserMessage !== undefined ? currentUserMessage : prompt) ?? "";
|
|
11
11
|
const visible = [];
|
|
12
12
|
const assistantTexts = new Map();
|
|
13
13
|
for (const item of messages) {
|
|
@@ -31,11 +31,17 @@ export function queryConversation(prompt, messages) {
|
|
|
31
31
|
(mirror && record(message.openclawDeliveryMirror)?.kind === "channel-final-suppressed")))
|
|
32
32
|
continue;
|
|
33
33
|
const text = messageText(message);
|
|
34
|
-
const
|
|
35
|
-
const
|
|
34
|
+
const sender = nonBlank(meta?.senderId) ?? nonBlank(message.senderId);
|
|
35
|
+
const upstream = typeof meta?.upstreamUserText === "string" ? meta.upstreamUserText : undefined;
|
|
36
|
+
const content = text?.role === "user"
|
|
37
|
+
? (upstream ? queryUserText(upstream, sender) : undefined) ??
|
|
38
|
+
// Fall back to canonical message.content only when upstreamUserText is absent or has a decorated non-envelope prefix,
|
|
39
|
+
// never to bypass a rejected Conversation info envelope.
|
|
40
|
+
(upstream && CONVERSATION_INFO.test(upstream.trim()) ? undefined : (text.text ? queryUserText(text.text, sender) : undefined))
|
|
41
|
+
: text?.text;
|
|
36
42
|
if (message.role === "user") {
|
|
37
43
|
assistantTexts.clear();
|
|
38
|
-
if (!content || /^(?:\[OpenClaw heartbeat poll\]|\[Queued messages while agent was busy\]|\[Subagent Context\]
|
|
44
|
+
if (!content || /^(?:\[cron:|\[OpenClaw heartbeat poll\]|\[Inter-session message\]|\[Queued messages while agent was busy\]|\[Subagent Context\]|<<<BEGIN_OPENCLAW_INTERNAL_CONTEXT>>>|<relevant-memories>|<unblock_memory>|<conversation_context>)/.test(content)) {
|
|
39
45
|
visible.length = 0;
|
|
40
46
|
continue;
|
|
41
47
|
}
|
|
@@ -50,7 +56,8 @@ export function queryConversation(prompt, messages) {
|
|
|
50
56
|
}
|
|
51
57
|
visible.push({ role: text.role, content });
|
|
52
58
|
}
|
|
53
|
-
|
|
59
|
+
const last = visible.at(-1);
|
|
60
|
+
if (last?.role === "user" && last.content.replaceAll("\r\n", "\n") === currentRequest.replaceAll("\r\n", "\n"))
|
|
54
61
|
visible.pop();
|
|
55
62
|
return prepareQueryConversation(visible, currentRequest).conversation;
|
|
56
63
|
}
|
|
@@ -4,6 +4,8 @@ export declare function conversationUserText(raw: string, sender?: unknown): {
|
|
|
4
4
|
text: string;
|
|
5
5
|
contextLimited: boolean;
|
|
6
6
|
} | undefined;
|
|
7
|
+
/** Unwrap human text for recall query generation, including non-Slack OpenClaw inbound envelopes. */
|
|
8
|
+
export declare function queryUserText(raw: string, sender?: unknown): string | undefined;
|
|
7
9
|
/** Like conversationUserText, plus the untrusted inbound context (thread starter, reply target,
|
|
8
10
|
* chat history) that a recognized envelope carries before the current message. */
|
|
9
11
|
export declare function conversationEnvelope(raw: string, sender?: unknown): {
|
|
@@ -1,10 +1,170 @@
|
|
|
1
|
-
export const CONVERSATION_INFO = /^Conversation info: ⟦openclaw:ctx⟧\r?\n```json\r?\n([^]*?)\r?\n```\r?\n/;
|
|
2
|
-
const FROM_HEADER = /^From: [^\r\n]+ \(([^()\r\n]+)\)
|
|
1
|
+
export const CONVERSATION_INFO = /^(?:\[OpenClaw conversation info: [^\r\n]*\]\r?\n)?Conversation info: ⟦openclaw:ctx⟧\r?\n```json\r?\n([^]*?)\r?\n```\r?\n/;
|
|
2
|
+
const FROM_HEADER = /^From: [^\r\n]+ \(([^()\r\n]+)\)(?:\r?\n|$)/;
|
|
3
|
+
const SLACK_MESSAGE_LINE = /^System: \[[^\]\r\n]+\] Slack (?:message in [^\r\n]+|DM) from ([^\r\n]+)$/gm;
|
|
4
|
+
const SYSTEM_EVENT_LINE = /^System: \[[^\]\r\n]+\] [^\r\n]+$/;
|
|
5
|
+
const INBOUND_HISTORY_MARKER = /^(?:Chat history since last reply|Recent chat history)(?: \(untrusted, for context\))?:/m;
|
|
6
|
+
const INBOUND_CTX_HEADER = /^[A-Za-z][A-Za-z0-9 _()/-]*: ⟦openclaw:ctx⟧$/;
|
|
7
|
+
const INBOUND_DELIVERY_HINT = /^Delivery: (?:to send a message, use the `message` tool\.|Final assistant text is not automatically delivered in this run\.[^\r\n]*|No visible reply is delivered automatically in this run[^\r\n]*)$/;
|
|
8
|
+
const LEGACY_REQUESTER_PROFILE_HINT = 'requester_profile is the verified linked requester. For "assign to me", use sessions assign_owner with ownerType="human" and ownerId=requester_profile.id, if available.';
|
|
9
|
+
const ACTIVE_GOAL_LINE = /^Active goal: [^\r\n]+$/;
|
|
10
|
+
const CURRENT_MESSAGE_MARKER = "[Current message - respond to this]";
|
|
11
|
+
function readLine(text, start) {
|
|
12
|
+
if (start >= text.length)
|
|
13
|
+
return undefined;
|
|
14
|
+
const lf = text.indexOf("\n", start);
|
|
15
|
+
const end = lf < 0 ? text.length : lf;
|
|
16
|
+
const next = lf < 0 ? text.length : lf + 1;
|
|
17
|
+
return { start, end, next, trimmed: text.slice(start, end).trim() };
|
|
18
|
+
}
|
|
19
|
+
function parseConversationHeader(rawJson) {
|
|
20
|
+
let meta;
|
|
21
|
+
try {
|
|
22
|
+
meta = JSON.parse(rawJson);
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
if (!meta || typeof meta !== "object" || Array.isArray(meta))
|
|
28
|
+
return undefined;
|
|
29
|
+
return {
|
|
30
|
+
senderId: typeof meta.sender?.id === "string" ? meta.sender.id : undefined,
|
|
31
|
+
senderName: typeof meta.sender?.name === "string" ? meta.sender.name : undefined,
|
|
32
|
+
historyTruncated: meta.history_truncated === true,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function stripChannelContextSuffix(text) {
|
|
36
|
+
const contexts = [...text.matchAll(/\r?\n\r?\nContext: ⟦openclaw:ctx⟧\r?\n/g)];
|
|
37
|
+
if (!contexts.length)
|
|
38
|
+
return { text, stripped: false };
|
|
39
|
+
if (contexts.length !== 1)
|
|
40
|
+
return undefined;
|
|
41
|
+
const context = contexts[0];
|
|
42
|
+
const suffix = text.slice(context.index + context[0].length);
|
|
43
|
+
if (!suffix.trim() || suffix.includes("⟦openclaw:ctx⟧") || INBOUND_HISTORY_MARKER.test(suffix))
|
|
44
|
+
return undefined;
|
|
45
|
+
return { text: text.slice(0, context.index).trim(), stripped: true };
|
|
46
|
+
}
|
|
47
|
+
/** Advance past one validated Slack message line, any adjacent non-message System lines, and the required blank separator line. */
|
|
48
|
+
function slackMarkerBodyStart(rest, markerEnd) {
|
|
49
|
+
let pos = markerEnd;
|
|
50
|
+
if (rest[pos] === "\r")
|
|
51
|
+
pos++;
|
|
52
|
+
if (rest[pos] !== "\n")
|
|
53
|
+
return undefined;
|
|
54
|
+
pos++;
|
|
55
|
+
while (pos < rest.length) {
|
|
56
|
+
const line = readLine(rest, pos);
|
|
57
|
+
if (!line)
|
|
58
|
+
return undefined;
|
|
59
|
+
if (line.trimmed === "")
|
|
60
|
+
return line.next;
|
|
61
|
+
if (!SYSTEM_EVENT_LINE.test(line.trimmed))
|
|
62
|
+
return undefined;
|
|
63
|
+
pos = line.next;
|
|
64
|
+
}
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
3
67
|
/** Infer legacy transport sender metadata only to unwrap visible conversation text. */
|
|
4
68
|
export function conversationUserText(raw, sender) {
|
|
5
69
|
const parsed = conversationEnvelope(raw, sender);
|
|
6
70
|
return parsed && { text: parsed.text, contextLimited: parsed.contextLimited };
|
|
7
71
|
}
|
|
72
|
+
/** Unwrap human text for recall query generation, including non-Slack OpenClaw inbound envelopes. */
|
|
73
|
+
export function queryUserText(raw, sender) {
|
|
74
|
+
const standard = conversationUserText(raw, sender);
|
|
75
|
+
if (standard)
|
|
76
|
+
return standard.text;
|
|
77
|
+
const trimmed = raw.trim();
|
|
78
|
+
const header = CONVERSATION_INFO.exec(trimmed);
|
|
79
|
+
if (!header)
|
|
80
|
+
return undefined;
|
|
81
|
+
const meta = parseConversationHeader(header[1]);
|
|
82
|
+
if (!meta || (typeof sender === "string" && meta.senderId !== sender))
|
|
83
|
+
return undefined;
|
|
84
|
+
const rest = trimmed.slice(header[0].length);
|
|
85
|
+
// Slack envelopes must pass strict speaker-marker validation in userEnvelope.
|
|
86
|
+
if ([...rest.matchAll(SLACK_MESSAGE_LINE)].length > 0)
|
|
87
|
+
return undefined;
|
|
88
|
+
let pos = 0;
|
|
89
|
+
while (pos < rest.length) {
|
|
90
|
+
let line = readLine(rest, pos);
|
|
91
|
+
while (line && line.trimmed === "") {
|
|
92
|
+
pos = line.next;
|
|
93
|
+
line = readLine(rest, pos);
|
|
94
|
+
}
|
|
95
|
+
if (!line)
|
|
96
|
+
break;
|
|
97
|
+
if (line.trimmed === "Conversation info: ⟦openclaw:ctx⟧")
|
|
98
|
+
return undefined;
|
|
99
|
+
if (INBOUND_CTX_HEADER.test(line.trimmed) && line.trimmed !== "Context: ⟦openclaw:ctx⟧") {
|
|
100
|
+
const label = line.trimmed;
|
|
101
|
+
pos = line.next;
|
|
102
|
+
const open = readLine(rest, pos);
|
|
103
|
+
if (open?.trimmed === "```json") {
|
|
104
|
+
pos = open.next;
|
|
105
|
+
const jsonStart = pos;
|
|
106
|
+
let close = readLine(rest, pos);
|
|
107
|
+
while (close && close.trimmed !== "```") {
|
|
108
|
+
pos = close.next;
|
|
109
|
+
close = readLine(rest, pos);
|
|
110
|
+
}
|
|
111
|
+
if (!close)
|
|
112
|
+
return undefined;
|
|
113
|
+
if (label === "Sender: ⟦openclaw:ctx⟧" && meta.senderId !== undefined) {
|
|
114
|
+
let senderMeta;
|
|
115
|
+
try {
|
|
116
|
+
senderMeta = JSON.parse(rest.slice(jsonStart, close.start));
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
if (typeof senderMeta?.id === "string" && senderMeta.id !== meta.senderId)
|
|
122
|
+
return undefined;
|
|
123
|
+
}
|
|
124
|
+
pos = close.next;
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
let content = open;
|
|
128
|
+
while (content && content.trimmed !== "") {
|
|
129
|
+
pos = content.next;
|
|
130
|
+
content = readLine(rest, pos);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
if (line.trimmed === "Context:") {
|
|
136
|
+
const open = readLine(rest, line.next);
|
|
137
|
+
if (open?.trimmed === "<active_memory_plugin>") {
|
|
138
|
+
let scan = readLine(rest, open.next);
|
|
139
|
+
while (scan && scan.trimmed !== "</active_memory_plugin>")
|
|
140
|
+
scan = readLine(rest, scan.next);
|
|
141
|
+
if (!scan)
|
|
142
|
+
return undefined;
|
|
143
|
+
pos = scan.next;
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (INBOUND_DELIVERY_HINT.test(line.trimmed) || line.trimmed === CURRENT_MESSAGE_MARKER ||
|
|
148
|
+
line.trimmed === LEGACY_REQUESTER_PROFILE_HINT || ACTIVE_GOAL_LINE.test(line.trimmed)) {
|
|
149
|
+
pos = line.next;
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
const stripped = stripChannelContextSuffix(rest.slice(pos).trim());
|
|
155
|
+
if (!stripped)
|
|
156
|
+
return undefined;
|
|
157
|
+
let body = stripped.text;
|
|
158
|
+
const from = FROM_HEADER.exec(body);
|
|
159
|
+
if (from) {
|
|
160
|
+
if (meta.senderId === undefined || from[1] !== meta.senderId)
|
|
161
|
+
return undefined;
|
|
162
|
+
body = body.slice(from[0].length).trim();
|
|
163
|
+
}
|
|
164
|
+
if (!body || body.includes("⟦openclaw:ctx⟧") || INBOUND_HISTORY_MARKER.test(body))
|
|
165
|
+
return undefined;
|
|
166
|
+
return body;
|
|
167
|
+
}
|
|
8
168
|
/** Like conversationUserText, plus the untrusted inbound context (thread starter, reply target,
|
|
9
169
|
* chat history) that a recognized envelope carries before the current message. */
|
|
10
170
|
export function conversationEnvelope(raw, sender) {
|
|
@@ -12,17 +172,10 @@ export function conversationEnvelope(raw, sender) {
|
|
|
12
172
|
if (senderId === undefined) {
|
|
13
173
|
const header = CONVERSATION_INFO.exec(raw.trim());
|
|
14
174
|
if (header) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
metadata = JSON.parse(header[1]);
|
|
18
|
-
}
|
|
19
|
-
catch {
|
|
175
|
+
const meta = parseConversationHeader(header[1]);
|
|
176
|
+
if (!meta || meta.senderId === undefined)
|
|
20
177
|
return;
|
|
21
|
-
|
|
22
|
-
if (metadata && typeof metadata === "object" && "sender" in metadata && metadata.sender &&
|
|
23
|
-
typeof metadata.sender === "object" && "id" in metadata.sender && typeof metadata.sender.id === "string") {
|
|
24
|
-
senderId = metadata.sender.id;
|
|
25
|
-
}
|
|
178
|
+
senderId = meta.senderId;
|
|
26
179
|
}
|
|
27
180
|
senderId ??= FROM_HEADER.exec(raw.trim())?.[1];
|
|
28
181
|
}
|
|
@@ -40,36 +193,29 @@ function userEnvelope(input, senderId) {
|
|
|
40
193
|
let context;
|
|
41
194
|
const header = CONVERSATION_INFO.exec(text);
|
|
42
195
|
if (header) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
meta = JSON.parse(header[1]);
|
|
46
|
-
}
|
|
47
|
-
catch {
|
|
48
|
-
return undefined;
|
|
49
|
-
}
|
|
50
|
-
if (!meta || meta.sender?.id !== senderId || typeof meta.sender.name !== "string")
|
|
196
|
+
const meta = parseConversationHeader(header[1]);
|
|
197
|
+
if (!meta || meta.senderId !== senderId || meta.senderName === undefined)
|
|
51
198
|
return undefined;
|
|
52
199
|
const rest = text.slice(header[0].length);
|
|
53
|
-
const markers = [...rest.matchAll(
|
|
54
|
-
if (markers.length !== 1 || markers[0][1] !== meta.
|
|
200
|
+
const markers = [...rest.matchAll(SLACK_MESSAGE_LINE)];
|
|
201
|
+
if (markers.length !== 1 || markers[0][1] !== meta.senderName)
|
|
55
202
|
return undefined;
|
|
56
203
|
const marker = markers[0];
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
204
|
+
const bodyStart = slackMarkerBodyStart(rest, marker.index + marker[0].length);
|
|
205
|
+
if (bodyStart === undefined)
|
|
206
|
+
return undefined;
|
|
207
|
+
const prefix = rest.slice(0, marker.index);
|
|
208
|
+
context = prefix.trim() || undefined;
|
|
209
|
+
contextLimited = meta.historyTruncated || INBOUND_HISTORY_MARKER.test(prefix);
|
|
210
|
+
text = rest.slice(bodyStart).trim();
|
|
60
211
|
// OpenClaw appends channel metadata after the current Slack message. Only
|
|
61
212
|
// recognize its exact boundary inside an already validated envelope.
|
|
62
|
-
const
|
|
63
|
-
if (
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const suffix = text.slice(context.index + context[0].length);
|
|
68
|
-
if (!suffix.trim() || suffix.includes("⟦openclaw:ctx⟧") || /^Chat history since last reply:/m.test(suffix))
|
|
69
|
-
return undefined;
|
|
70
|
-
text = text.slice(0, context.index).trim();
|
|
213
|
+
const stripped = stripChannelContextSuffix(text);
|
|
214
|
+
if (!stripped)
|
|
215
|
+
return undefined;
|
|
216
|
+
text = stripped.text;
|
|
217
|
+
if (stripped.stripped)
|
|
71
218
|
contextLimited = true;
|
|
72
|
-
}
|
|
73
219
|
}
|
|
74
220
|
else {
|
|
75
221
|
const from = FROM_HEADER.exec(text);
|
|
@@ -80,7 +226,7 @@ function userEnvelope(input, senderId) {
|
|
|
80
226
|
}
|
|
81
227
|
}
|
|
82
228
|
// Unrecognized/nested envelopes cannot safely supply the current human text.
|
|
83
|
-
if (!text || text.includes("⟦openclaw:ctx⟧") ||
|
|
229
|
+
if (!text || text.includes("⟦openclaw:ctx⟧") || INBOUND_HISTORY_MARKER.test(text))
|
|
84
230
|
return undefined;
|
|
85
231
|
return { text, contextLimited, ...(context ? { context } : {}) };
|
|
86
232
|
}
|
package/openclaw.plugin.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "unblock-memory",
|
|
3
3
|
"name": "Unblock Memory",
|
|
4
|
-
"version": "0.12.
|
|
4
|
+
"version": "0.12.3",
|
|
5
5
|
"description": "Indexes, retrieves, and analyzes configured workspace memory with existing QMD vectors.",
|
|
6
6
|
"kind": "memory",
|
|
7
7
|
"activation": { "onStartup": true },
|