agenr 0.8.11 → 0.8.14

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/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.8.13] - 2026-02-23
4
+
5
+ ### Fixed
6
+ - fix(openclaw-plugin): session-start recall now falls back to reading the most recent archived OpenClaw session file (`*.reset.*`) when webchat `/new` bypasses `before_reset`. If stash-based seeding is unavailable and the opening prompt is short (< 40 characters), recall query text is built from the last 3 user messages in the archived session.
7
+
8
+ ## [0.8.12]
9
+
10
+ ### Fixed
11
+ - fix(openclaw-plugin): strip OpenClaw metadata envelope from `before_prompt_build` prompts before session-start recall query resolution; query seeding now uses the user message after the final timestamp marker instead of prepended metadata, with last-match handling for repeated timestamp patterns
12
+
3
13
  ## [0.8.11]
4
14
 
5
15
  ### Changed
@@ -8,6 +8,7 @@ type BeforeAgentStartEvent = {
8
8
  type PluginHookAgentContext = {
9
9
  sessionKey?: string;
10
10
  sessionId?: string;
11
+ agentId?: string;
11
12
  workspaceDir?: string;
12
13
  [key: string]: unknown;
13
14
  };
@@ -7,6 +7,8 @@ import {
7
7
  } from "../chunk-L7VVZDWF.js";
8
8
 
9
9
  // src/openclaw-plugin/index.ts
10
+ import os from "os";
11
+ import path3 from "path";
10
12
  import { Type } from "@sinclair/typebox";
11
13
 
12
14
  // src/openclaw-plugin/recall.ts
@@ -140,8 +142,11 @@ function formatRecallAsMarkdown(result) {
140
142
  }
141
143
 
142
144
  // src/openclaw-plugin/session-query.ts
145
+ import { readFile, readdir, stat } from "fs/promises";
146
+ import path2 from "path";
143
147
  var SESSION_TOPIC_TTL_MS = 60 * 60 * 1e3;
144
148
  var SESSION_TOPIC_MIN_LENGTH = 40;
149
+ var ARCHIVED_SESSION_MAX_AGE_MS = 24 * 60 * 60 * 1e3;
145
150
  var SESSION_QUERY_LOOKBACK = 3;
146
151
  var sessionTopicStash = /* @__PURE__ */ new Map();
147
152
  function isRecord(value) {
@@ -178,6 +183,25 @@ function isThinPrompt(prompt) {
178
183
  const trimmed = prompt.trim().toLowerCase();
179
184
  return trimmed === "" || trimmed === "/new" || trimmed === "/reset";
180
185
  }
186
+ function stripPromptMetadata(raw) {
187
+ if (!raw) {
188
+ return "";
189
+ }
190
+ try {
191
+ const pattern = /\[\w{3} \d{4}-\d{2}-\d{2} \d{2}:\d{2} (?:[A-Z]{2,5}|GMT[+-]\d{1,2})\] /g;
192
+ let lastMatchEnd = -1;
193
+ let match = null;
194
+ while ((match = pattern.exec(raw)) !== null) {
195
+ lastMatchEnd = match.index + match[0].length;
196
+ }
197
+ if (lastMatchEnd >= 0) {
198
+ return raw.slice(lastMatchEnd).trim();
199
+ }
200
+ return raw.trim();
201
+ } catch {
202
+ return "";
203
+ }
204
+ }
181
205
  function extractLastUserText(messages) {
182
206
  try {
183
207
  const collected = [];
@@ -197,6 +221,58 @@ function extractLastUserText(messages) {
197
221
  return "";
198
222
  }
199
223
  }
224
+ async function readLatestArchivedUserMessages(sessionsDir, maxAgeMs = ARCHIVED_SESSION_MAX_AGE_MS) {
225
+ try {
226
+ const now = Date.now();
227
+ const archivedFiles = [];
228
+ const entries = await readdir(sessionsDir, { withFileTypes: true });
229
+ for (const entry of entries) {
230
+ if (!entry.isFile() || !entry.name.includes(".reset.")) {
231
+ continue;
232
+ }
233
+ const filePath = path2.join(sessionsDir, entry.name);
234
+ const fileStats = await stat(filePath);
235
+ if (now - fileStats.mtimeMs > maxAgeMs) {
236
+ continue;
237
+ }
238
+ archivedFiles.push({ filePath, mtimeMs: fileStats.mtimeMs });
239
+ }
240
+ if (archivedFiles.length === 0) {
241
+ return [];
242
+ }
243
+ archivedFiles.sort((a, b) => b.mtimeMs - a.mtimeMs);
244
+ for (const candidate of archivedFiles) {
245
+ const raw = await readFile(candidate.filePath, "utf8");
246
+ const userMessages = [];
247
+ for (const line of raw.split(/\r?\n/)) {
248
+ const trimmed = line.trim();
249
+ if (!trimmed) {
250
+ continue;
251
+ }
252
+ let parsed;
253
+ try {
254
+ parsed = JSON.parse(trimmed);
255
+ } catch {
256
+ continue;
257
+ }
258
+ if (!isRecord(parsed) || parsed["type"] !== "message") {
259
+ continue;
260
+ }
261
+ const text = extractTextFromUserMessage(parsed["message"]);
262
+ if (!text) {
263
+ continue;
264
+ }
265
+ userMessages.push(text);
266
+ }
267
+ if (userMessages.length > 0) {
268
+ return userMessages.slice(-SESSION_QUERY_LOOKBACK);
269
+ }
270
+ }
271
+ return [];
272
+ } catch {
273
+ return [];
274
+ }
275
+ }
200
276
  function shouldStashTopic(text) {
201
277
  if (text.length < SESSION_TOPIC_MIN_LENGTH) {
202
278
  return false;
@@ -869,8 +945,30 @@ var plugin = {
869
945
  const agenrPath = resolveAgenrPath(config);
870
946
  const budget = resolveBudget(config);
871
947
  const project = config?.project?.trim() || void 0;
872
- const queryText = resolveSessionQuery(event.prompt, ctx.sessionKey);
873
- const recallResult = await runRecall(agenrPath, budget, project, queryText);
948
+ const userPrompt = stripPromptMetadata(event.prompt ?? "");
949
+ const queryText = resolveSessionQuery(userPrompt, ctx.sessionKey);
950
+ let recallQueryText = queryText;
951
+ if (isFirstInSession && queryText === userPrompt && userPrompt.length < SESSION_TOPIC_MIN_LENGTH) {
952
+ const agentId = ctx.agentId?.trim() || "main";
953
+ if (!ctx.agentId?.trim()) {
954
+ api.logger.debug?.("[agenr] session-start: agentId not provided, defaulting to 'main'");
955
+ }
956
+ const sessionsDir = path3.join(
957
+ os.homedir(),
958
+ ".openclaw",
959
+ "agents",
960
+ agentId,
961
+ "sessions"
962
+ );
963
+ const archivedMessages = await readLatestArchivedUserMessages(sessionsDir);
964
+ if (archivedMessages.length > 0) {
965
+ recallQueryText = `${archivedMessages.join(" ")} ${userPrompt}`;
966
+ api.logger.info?.(
967
+ `[agenr] session-start: archived session fallback applied, ${archivedMessages.length} messages`
968
+ );
969
+ }
970
+ }
971
+ const recallResult = await runRecall(agenrPath, budget, project, recallQueryText);
874
972
  if (recallResult) {
875
973
  const formatted = formatRecallAsMarkdown(recallResult);
876
974
  if (formatted.trim()) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agenr",
3
- "version": "0.8.11",
3
+ "version": "0.8.14",
4
4
  "openclaw": {
5
5
  "extensions": [
6
6
  "dist/openclaw-plugin/index.js"