@martian-engineering/lossless-claw 0.9.0 → 0.9.2

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.
@@ -125,7 +125,7 @@ The assembler runs before each model turn and builds the message array:
125
125
  2. Resolve each item — summaries become user messages with XML wrappers; messages are reconstructed from parts.
126
126
  3. Split into evictable prefix and protected fresh tail (last `freshTailCount` raw messages).
127
127
  4. Compute fresh tail token cost (always included, even if over budget).
128
- 5. Fill remaining budget from the evictable set, keeping newest items and dropping oldest.
128
+ 5. Fill remaining budget from the evictable set. By default this keeps newest older items and drops the oldest; when `promptAwareEviction` is enabled and a searchable prompt is present, the evictable prefix is ranked by prompt relevance first and then restored to chronological order.
129
129
  6. Normalize assistant content to array blocks (Anthropic API compatibility).
130
130
  7. Sanitize tool-use/result pairing (ensures every tool_result has a matching tool_use).
131
131
 
@@ -23,6 +23,7 @@ Most installations only need to override a handful of keys. If you want a comple
23
23
  "contextThreshold": 0.75,
24
24
  "freshTailCount": 64,
25
25
  "freshTailMaxTokens": 24000,
26
+ "promptAwareEviction": false,
26
27
  "newSessionRetainDepth": 2,
27
28
  "leafMinFanout": 8,
28
29
  "condensedMinFanout": 4,
@@ -123,6 +124,7 @@ openclaw plugins install --link /path/to/lossless-claw
123
124
  | `contextThreshold` | `number` | `0.75` | `LCM_CONTEXT_THRESHOLD` | Fraction of the active model context window that triggers compaction. |
124
125
  | `freshTailCount` | `integer` | `64` | `LCM_FRESH_TAIL_COUNT` | Number of newest messages always kept raw. |
125
126
  | `freshTailMaxTokens` | `integer` | unset | `LCM_FRESH_TAIL_MAX_TOKENS` | Optional token cap for the protected fresh tail. The newest message is always preserved even if it exceeds the cap. |
127
+ | `promptAwareEviction` | `boolean` | `false` | `LCM_PROMPT_AWARE_EVICTION_ENABLED` | When enabled, budget-constrained assembly keeps older evictable items by prompt relevance instead of pure chronology. This improves retrieval under tight budgets, but it can reduce prompt-cache hit rates because the preserved prefix changes as prompts change. |
126
128
  | `leafMinFanout` | `integer` | `8` | `LCM_LEAF_MIN_FANOUT` | Minimum number of raw messages required before a leaf pass runs. |
127
129
  | `condensedMinFanout` | `integer` | `4` | `LCM_CONDENSED_MIN_FANOUT` | Number of same-depth summaries needed before condensation is attempted. |
128
130
  | `condensedMinFanoutHard` | `integer` | `2` | `LCM_CONDENSED_MIN_FANOUT_HARD` | Hard floor for condensation grouping during maintenance and repair flows. |
@@ -190,6 +192,21 @@ When cache-aware compaction is enabled:
190
192
 
191
193
  When incremental leaf compaction still runs on a hot cache, follow-on condensed passes are suppressed so the maintenance cycle only pays for the leaf pass that was explicitly justified.
192
194
 
195
+ ### Prompt-aware eviction
196
+
197
+ When `promptAwareEviction` is enabled:
198
+
199
+ - the protected fresh tail is still preserved exactly as usual
200
+ - only the older evictable prefix is affected
201
+ - if the evictable prefix does not fit and the current prompt has searchable terms, lossless-claw keeps the most relevant older items instead of just the newest older items
202
+
203
+ Tradeoff:
204
+
205
+ - this can improve retrieval quality when the prompt is asking about an older topic and the assembled context is tight
206
+ - it also makes the assembled prefix less stable for providers with prefix-based prompt caching, because different prompts can keep different older items
207
+
208
+ If Anthropic prompt-cache stability matters more than topical recall under pressure, set `promptAwareEviction: false`.
209
+
193
210
  ## Behavior notes
194
211
 
195
212
  ### Summary model resolution
package/docs/tui.md CHANGED
@@ -237,6 +237,32 @@ The confirmation screen shows:
237
237
 
238
238
  Each interactive operation also has a standalone CLI equivalent for scripting and batch operations.
239
239
 
240
+ ### `lcm-tui doctor`
241
+
242
+ Scans for genuinely truncated summaries and can rewrite them in place. This is narrower than `repair`: it looks for specific truncation marker shapes instead of the generic fallback-summary marker.
243
+
244
+ ```bash
245
+ # Preview repairs for one conversation
246
+ lcm-tui doctor 44 --show-diff
247
+
248
+ # Apply repairs with an OpenAI-compatible backend
249
+ lcm-tui doctor 44 --apply --provider openai --model gpt-5.3-codex --base-url https://proxy.example.com/openai
250
+
251
+ # Scan only across every conversation
252
+ lcm-tui doctor --all
253
+ ```
254
+
255
+ | Flag | Description |
256
+ |------|-------------|
257
+ | `--apply` | Write repaired summaries to the database |
258
+ | `--summary` | Scan only and show counts |
259
+ | `--all` | Scan all conversations (discovery mode only) |
260
+ | `--provider <id>` | API provider (default: anthropic) |
261
+ | `--model <model>` | API model (default: `claude-haiku-4-5`) |
262
+ | `--base-url <url>` | Custom API base URL (overrides config and env) |
263
+ | `--show-diff` | Show unified diff for each fix |
264
+ | `--timestamps` | Inject timestamps into rewrite source text |
265
+
240
266
  ### `lcm-tui repair`
241
267
 
242
268
  Finds and fixes corrupted summaries (those containing the `[LCM fallback summary]` marker from failed summarization attempts).
@@ -253,6 +279,9 @@ lcm-tui repair 44 --apply
253
279
 
254
280
  # Repair a specific summary
255
281
  lcm-tui repair 44 --summary-id sum_abc123 --apply
282
+
283
+ # Repair through an OpenAI-compatible backend
284
+ lcm-tui repair 44 --apply --provider openai --model gpt-5.3-codex --base-url https://proxy.example.com/openai
256
285
  ```
257
286
 
258
287
  The repair process:
@@ -260,7 +289,7 @@ The repair process:
260
289
  2. Orders them bottom-up: leaves first (in context ordinal order), then condensed nodes by ascending depth
261
290
  3. Reconstructs source material from linked messages (leaves) or child summaries (condensed)
262
291
  4. Resolves `previous_context` for each node (for deduplication in the prompt)
263
- 5. Sends to Anthropic API with the appropriate depth prompt
292
+ 5. Sends to the resolved provider API with the appropriate depth prompt
264
293
  6. Updates the database in a single transaction
265
294
 
266
295
  | Flag | Description |
@@ -268,6 +297,9 @@ The repair process:
268
297
  | `--apply` | Write repairs to database (default: dry run) |
269
298
  | `--all` | Scan all conversations |
270
299
  | `--summary-id <id>` | Target a specific summary |
300
+ | `--provider <id>` | API provider (inferred from `--model` when omitted) |
301
+ | `--model <model>` | API model (default depends on provider) |
302
+ | `--base-url <url>` | Custom API base URL (overrides config and env) |
271
303
  | `--verbose` | Show content hashes and previews |
272
304
 
273
305
  ### `lcm-tui rewrite`
@@ -484,14 +516,15 @@ Resolution order:
484
516
 
485
517
  If the provider auth profile mode is `oauth` (not `api_key`), set the provider API key environment variable explicitly.
486
518
 
487
- Interactive rewrite (`w`/`W`) can be configured with:
519
+ Summary-producing operations (`doctor`, `repair`, `rewrite`, `backfill`, and interactive rewrite `w`/`W`) can be configured with:
488
520
  - `LCM_TUI_SUMMARY_PROVIDER`
489
521
  - `LCM_TUI_SUMMARY_MODEL`
490
522
  - `LCM_TUI_SUMMARY_BASE_URL`
491
- - `LCM_TUI_CONVERSATION_WINDOW_SIZE` (default `200`)
492
523
 
493
524
  It also honors `LCM_SUMMARY_PROVIDER` / `LCM_SUMMARY_MODEL` / `LCM_SUMMARY_BASE_URL` as fallback.
494
525
 
526
+ Separately, the conversation browser window size uses `LCM_TUI_CONVERSATION_WINDOW_SIZE` (default `200`).
527
+
495
528
  ## Database
496
529
 
497
530
  The TUI operates directly on the SQLite database at `~/.openclaw/lcm.db`. All write operations (rewrite, dissolve, repair, transplant, backfill) use transactions. Changes take effect on the next conversation turn — the running OpenClaw instance picks up database changes automatically.
@@ -25,6 +25,10 @@
25
25
  "label": "Fresh Tail Max Tokens",
26
26
  "help": "Optional token cap for the protected fresh tail; the newest message is always preserved"
27
27
  },
28
+ "promptAwareEviction": {
29
+ "label": "Prompt-Aware Eviction",
30
+ "help": "When enabled, budget-constrained assembly keeps older context by prompt relevance instead of pure chronology. This can improve recall under tight budgets, but it can also reduce provider prompt-cache hit rates because the preserved prefix changes as prompts change."
31
+ },
28
32
  "leafChunkTokens": {
29
33
  "label": "Leaf Chunk Tokens",
30
34
  "help": "Maximum source tokens per leaf compaction chunk before summarization"
@@ -226,6 +230,9 @@
226
230
  "type": "integer",
227
231
  "minimum": 0
228
232
  },
233
+ "promptAwareEviction": {
234
+ "type": "boolean"
235
+ },
229
236
  "leafChunkTokens": {
230
237
  "type": "integer",
231
238
  "minimum": 1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@martian-engineering/lossless-claw",
3
- "version": "0.9.0",
3
+ "version": "0.9.2",
4
4
  "description": "Lossless Context Management plugin for OpenClaw — DAG-based conversation summarization with incremental compaction",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -31,8 +31,9 @@
31
31
  "LICENSE"
32
32
  ],
33
33
  "dependencies": {
34
- "@mariozechner/pi-agent-core": "*",
35
- "@mariozechner/pi-ai": "*",
34
+ "@mariozechner/pi-agent-core": "0.66.1",
35
+ "@mariozechner/pi-ai": "0.66.1",
36
+ "@mariozechner/pi-coding-agent": "0.66.1",
36
37
  "@sinclair/typebox": "0.34.48"
37
38
  },
38
39
  "devDependencies": {
@@ -57,6 +57,21 @@ Good starting range:
57
57
  - Leave unset unless large tool outputs are forcing avoidable cost or overflow.
58
58
  - Start around `12000` to `32000` when you want a softer, size-aware fresh tail.
59
59
 
60
+ ### `promptAwareEviction`
61
+
62
+ Controls whether budget-constrained assembly keeps older context by prompt relevance or pure chronology.
63
+
64
+ Why it matters:
65
+
66
+ - when enabled, lossless-claw can keep an older but on-topic summary instead of a newer irrelevant one
67
+ - this can improve retrieval quality when the assembled context is tight
68
+ - it also makes the preserved prompt prefix less stable, which can reduce prefix-based prompt-cache hit rates
69
+
70
+ Good default:
71
+
72
+ - `false`
73
+ - enable it only when topical older-context recall under tight budgets matters more than prompt-cache stability
74
+
60
75
  ### `leafChunkTokens`
61
76
 
62
77
  Caps how much raw material gets summarized into one leaf summary.
@@ -232,6 +247,21 @@ See high-impact settings above.
232
247
 
233
248
  See high-impact settings above.
234
249
 
250
+ ### `promptAwareEviction`
251
+
252
+ Boolean toggle for prompt-sensitive selection inside the evictable prefix during assembly.
253
+
254
+ Why it matters:
255
+
256
+ - only applies when the older evictable prefix does not fit the token budget
257
+ - the protected fresh tail is unaffected
258
+ - `true` keeps the most relevant older items for the current prompt
259
+ - `false` falls back to pure chronological retention for the older prefix
260
+
261
+ Env override:
262
+
263
+ - `LCM_PROMPT_AWARE_EVICTION_ENABLED`
264
+
235
265
  ### `leafChunkTokens`
236
266
 
237
267
  See high-impact settings above.