@martian-engineering/lossless-claw 0.5.3 → 0.6.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.
@@ -15,6 +15,7 @@ import { createLcmDescribeTool } from "../tools/lcm-describe-tool.js";
15
15
  import { createLcmExpandQueryTool } from "../tools/lcm-expand-query-tool.js";
16
16
  import { createLcmExpandTool } from "../tools/lcm-expand-tool.js";
17
17
  import { createLcmGrepTool } from "../tools/lcm-grep-tool.js";
18
+ import { createLcmCommand } from "./lcm-command.js";
18
19
  import type { LcmDependencies } from "../types.js";
19
20
 
20
21
  /** Parse `agent:<agentId>:<suffix...>` session keys. */
@@ -112,6 +113,33 @@ type CompletionBridgeErrorInfo = {
112
113
  message?: string;
113
114
  };
114
115
 
116
+ const LOSSLESS_RECALL_POLICY_PROMPT = [
117
+ "## Lossless Recall Policy",
118
+ "",
119
+ "The lossless-claw plugin is active.",
120
+ "",
121
+ "For compacted conversation history, these instructions supersede generic memory-recall guidance. Prefer lossless-claw recall tools first when answering questions about prior conversation content, decisions made in the conversation, or details that may have been compacted.",
122
+ "",
123
+ "**Conflict handling:** If newer evidence conflicts with an older summary or recollection, prefer the newer evidence. Do not trust a stale summary over fresher contradictory information.",
124
+ "",
125
+ "**Contradictions/uncertainty:** If facts seem contradictory or uncertain, verify with lossless-claw recall tools before answering instead of trusting the summary at face value.",
126
+ "",
127
+ "**Tool escalation:**",
128
+ "Recall order for compacted conversation history:",
129
+ "1. `lcm_grep` — search by regex or full-text across messages and summaries",
130
+ "2. `lcm_describe` — inspect a specific summary (cheap, no sub-agent)",
131
+ "3. `lcm_expand_query` — deep recall: spawns bounded sub-agent, expands DAG, returns answer with cited summary IDs (~120s, don't ration it)",
132
+ "",
133
+ "**`lcm_expand_query` usage** — two patterns (always requires `prompt`):",
134
+ "- With IDs: `lcm_expand_query(summaryIds: [\"sum_xxx\"], prompt: \"What config changes were discussed?\")`",
135
+ "- With search: `lcm_expand_query(query: \"database migration\", prompt: \"What strategy was decided?\")`",
136
+ "- Optional: `maxTokens` (default 2000), `conversationId`, `allConversations: true`",
137
+ "",
138
+ "These precedence rules apply only to compacted conversation history. Lossless-claw does not supersede memory tools globally.",
139
+ "",
140
+ "If a summary conflicts with newer evidence, prefer the newer evidence. Do not guess exact commands, SHAs, paths, timestamps, config values, or causal claims from compacted summaries when expansion is needed.",
141
+ ].join("\n");
142
+
115
143
  /** Capture plugin env values once during initialization. */
116
144
  function snapshotPluginEnv(env: NodeJS.ProcessEnv = process.env): PluginEnvSnapshot {
117
145
  return {
@@ -1523,6 +1551,16 @@ const lcmPlugin = {
1523
1551
  const database = createLcmDatabaseConnection(deps.config.databasePath);
1524
1552
  const lcm = new LcmContextEngine(deps, database);
1525
1553
 
1554
+ api.on("before_reset", async (event, ctx) => {
1555
+ await lcm.handleBeforeReset({
1556
+ reason: event.reason,
1557
+ sessionId: ctx.sessionId,
1558
+ sessionKey: ctx.sessionKey,
1559
+ });
1560
+ });
1561
+ api.on("before_prompt_build", () => ({
1562
+ prependSystemContext: LOSSLESS_RECALL_POLICY_PROMPT,
1563
+ }));
1526
1564
  api.registerContextEngine("lossless-claw", () => lcm);
1527
1565
  api.registerContextEngine("default", () => lcm);
1528
1566
  api.registerTool((ctx) =>
@@ -1554,6 +1592,13 @@ const lcmPlugin = {
1554
1592
  requesterSessionKey: ctx.sessionKey,
1555
1593
  }),
1556
1594
  );
1595
+ api.registerCommand(
1596
+ createLcmCommand({
1597
+ db: database,
1598
+ config: deps.config,
1599
+ deps,
1600
+ }),
1601
+ );
1557
1602
 
1558
1603
  logStartupBannerOnce({
1559
1604
  key: "plugin-loaded",