teapot-coding-agent 0.29.25 → 0.29.26

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.
@@ -191,7 +191,12 @@ Most session state is not injected into prompts — fetch it with tools instead:
191
191
  - finish(goalComplete=true, summary) → goal fully achieved.
192
192
  - ask_user(question, options?) → park the loop and wait for the operator's
193
193
  decision (plan confirmation, ambiguity). One concrete question at a time.
194
- - read_memory() / set_memory(content) → your durable notes (memory.md).
194
+ - read_memory(query?) / add_memory(text) / forget_memory(query) / set_memory(content)
195
+ → your durable notes (memory.md). add_memory appends and cannot lose earlier
196
+ notes; forget_memory removes the lines matching a substring, so a stale note can
197
+ be corrected instead of piling up; set_memory REPLACES the whole file. Pass a
198
+ query to read_memory to search rather than dumping everything. The notes are NOT
199
+ in your prompt — read them.
195
200
  - get_todo() / set_todo(content) → the operator-maintained task list
196
201
  (todo.md); check it when picking up work, keep it current as you go.
197
202
  - When corrected, add_feedback(rule) so it sticks; review via get_feedback().
@@ -219,7 +224,11 @@ Most session state is not injected into prompts — fetch it with tools instead:
219
224
  shown to the operator directly (rendered as markdown in the progress
220
225
  panel) — do NOT also repeat the same content as a chat message; end the
221
226
  turn right after the call (a short "reported." is fine).
222
- - Be frugal: prefer small precise edits, avoid runaway loops.`;
227
+ - Be frugal: prefer small precise edits, avoid runaway loops.
228
+ - When the operator asks you to remember something, WRITE it with add_memory. When
229
+ earlier context might be relevant again (a decision, a gotcha, where you left off),
230
+ SEARCH it with read_memory(query) and use what you find. Nothing is injected: an
231
+ unread note is an unwritten note.`;
223
232
  /**
224
233
  * A message whose ENTIRE text is parenthesised is an acknowledgement, not work.
225
234
  *
@@ -2483,8 +2492,38 @@ export class Agent {
2483
2492
  continue;
2484
2493
  }
2485
2494
  if (call.function.name === "read_memory") {
2495
+ const a = safeParse(call.function.arguments);
2496
+ const query = String(a.query ?? "").trim();
2486
2497
  const mem = await fs.readFile(this.memoryFile, "utf8").catch(() => "");
2487
- await this.answerMeta(call, mem.trim() || "(memory.md is empty — nothing noted yet)");
2498
+ if (!mem.trim()) {
2499
+ await this.answerMeta(call, "(memory.md is empty — nothing noted yet)");
2500
+ continue;
2501
+ }
2502
+ // #48: `query` searches instead of dumping the whole file.
2503
+ //
2504
+ // This is the one idea worth taking from the ecosystem. MCP's reference memory
2505
+ // server (the de-facto standard, used by Claude and offered by DSH as a
2506
+ // reference) exposes `search` alongside `read`, and its search is deliberately
2507
+ // a case-insensitive substring match — no embeddings, no model, no provider
2508
+ // dependency. DSH's guidance to the model is the same shape: "when historical
2509
+ // information may be relevant, search memory and use relevant results".
2510
+ //
2511
+ // MEASURED why it matters here: `set_memory` was called 181 times but
2512
+ // `read_memory` only 97 times across every session, and only 13 of those reads
2513
+ // came after a write. Dumping a growing file gives the model no way to ask a
2514
+ // QUESTION, so a big file is all-or-nothing — either burn the whole thing into
2515
+ // the context or do not look at all.
2516
+ if (!query) {
2517
+ await this.answerMeta(call, mem.trim());
2518
+ continue;
2519
+ }
2520
+ const needle = query.toLowerCase();
2521
+ const hits = mem
2522
+ .split(/\r?\n/)
2523
+ .filter((line) => line.toLowerCase().includes(needle));
2524
+ await this.answerMeta(call, hits.length
2525
+ ? `${hits.length} line(s) matching ${JSON.stringify(query)}:\n${hits.join("\n")}`
2526
+ : `(no line in memory.md matches ${JSON.stringify(query)} — ${mem.split(/\r?\n/).length} lines searched; call read_memory with no query to see all of it)`);
2488
2527
  continue;
2489
2528
  }
2490
2529
  if (call.function.name === "list_skills") {
@@ -2499,7 +2538,70 @@ export class Agent {
2499
2538
  const a = safeParse(call.function.arguments);
2500
2539
  const content = String(a.content ?? "").slice(0, 32_000);
2501
2540
  await fs.writeFile(this.memoryFile, content, "utf8");
2502
- await this.answerMeta(call, "memory saved (injected into future prompts)");
2541
+ // #48: this used to say "injected into future prompts", which was false —
2542
+ // memory.md is never injected. The model then behaved as if it already held
2543
+ // its notes. Say what actually happened, and what the model must do instead.
2544
+ await this.answerMeta(call, `memory.md REPLACED (${content.length} bytes). It is not in your prompt — call read_memory when you need it.`);
2545
+ continue;
2546
+ }
2547
+ if (call.function.name === "forget_memory") {
2548
+ const a = safeParse(call.function.arguments);
2549
+ const query = String(a.query ?? "").trim();
2550
+ if (!query) {
2551
+ await this.answerMeta(call, "forget_memory needs a `query` — nothing removed");
2552
+ continue;
2553
+ }
2554
+ // #48: notes must be REMOVABLE, not only appendable.
2555
+ //
2556
+ // MCP's reference memory makes observations "added or removed
2557
+ // independently" for exactly this reason: an append-only store accumulates
2558
+ // stale facts ("the build takes 4 minutes" stays long after it takes 40
2559
+ // seconds), and a memory that is confidently wrong is worse than one that is
2560
+ // silent. Without a delete, the only way to correct a file was `set_memory`
2561
+ // with the whole content re-typed — which is how 1028 bytes became 83.
2562
+ const prev = await fs.readFile(this.memoryFile, "utf8").catch(() => "");
2563
+ if (!prev.trim()) {
2564
+ await this.answerMeta(call, "(memory.md is empty — nothing to forget)");
2565
+ continue;
2566
+ }
2567
+ const needle = query.toLowerCase();
2568
+ const kept = [];
2569
+ const removed = [];
2570
+ for (const line of prev.split(/\r?\n/)) {
2571
+ if (line.toLowerCase().includes(needle))
2572
+ removed.push(line);
2573
+ else
2574
+ kept.push(line);
2575
+ }
2576
+ if (removed.length === 0) {
2577
+ await this.answerMeta(call, `(no line in memory.md matches ${JSON.stringify(query)} — nothing removed)`);
2578
+ continue;
2579
+ }
2580
+ // collapse the blank runs a deletion leaves behind, so the file does not
2581
+ // grow holes
2582
+ const next = kept.join("\n").replace(/\n{3,}/g, "\n\n").trimEnd() + "\n";
2583
+ await fs.writeFile(this.memoryFile, next, "utf8");
2584
+ await this.answerMeta(call, `removed ${removed.length} line(s) from memory.md:\n${removed.join("\n").slice(0, 1_500)}\n` +
2585
+ `(memory.md is now ${next.length} bytes — re-add with add_memory if that was wrong)`);
2586
+ continue;
2587
+ }
2588
+ if (call.function.name === "add_memory") {
2589
+ const a = safeParse(call.function.arguments);
2590
+ const text = String(a.text ?? "").trim().slice(0, 8_000);
2591
+ if (!text) {
2592
+ await this.answerMeta(call, "add_memory needs non-empty `text` — nothing appended");
2593
+ continue;
2594
+ }
2595
+ // APPEND rather than replace (#48). `set_memory` overwrites the whole file,
2596
+ // so a model that had not just read it silently ERASED everything it did not
2597
+ // re-send — MEASURED on a real session: 21 writes, with the content dropping
2598
+ // from 1028 to 83 bytes. Appending is the operation "remember this" actually
2599
+ // wants, and it cannot lose what is already there.
2600
+ const prev = await fs.readFile(this.memoryFile, "utf8").catch(() => "");
2601
+ const sep = prev && !prev.endsWith("\n") ? "\n" : "";
2602
+ const next = `${prev}${sep}${text}\n`;
2603
+ await fs.writeFile(this.memoryFile, next.slice(0, 32_000), "utf8");
2604
+ await this.answerMeta(call, `appended to memory.md (now ${next.length} bytes). Not in your prompt — call read_memory to see it.`);
2503
2605
  continue;
2504
2606
  }
2505
2607
  await this.log.append("tool_call", this.currentSession, this.currentBranch, {
@@ -3532,7 +3634,8 @@ export class Agent {
3532
3634
  {
3533
3635
  role: "user",
3534
3636
  content: `[harness] Context was compacted: ${oldCount} earlier messages were summarized. ` +
3535
- "Goal and notes are managed by the harness (AGENTS.md / memory.md are injected into your prompt when present).\n\n" +
3637
+ "AGENTS.md is embedded in your system prompt; memory.md, todo.md and decisions.md are NOT — "
3638
+ + "call read_memory / get_todo / get_decisions if you need them.\n\n" +
3536
3639
  `## Summary of earlier conversation\n${summary}`,
3537
3640
  },
3538
3641
  ...this.messages.slice(cut),
@@ -3551,6 +3654,32 @@ export class Agent {
3551
3654
  // Post-compact file restore (Claude Code style): re-attach the most
3552
3655
  // recently read files so the model doesn't burn its first turns re-reading
3553
3656
  // exactly what it had in context a moment ago. Budget: 3 files × 400 lines.
3657
+ if (mode === "summarize") {
3658
+ // #48: the durable notes go back in HERE, and only here.
3659
+ //
3660
+ // MEASURED before this: `set_memory` 181 times across every session but a
3661
+ // `read_memory` AFTER writing only 13 times — the notes were written and
3662
+ // never consulted, so the whole system was decoration. The prompt made it
3663
+ // worse by claiming memory.md was injected when it never was.
3664
+ //
3665
+ // Compaction is the one moment where re-attaching is free and obviously
3666
+ // right: the history that held the notes has just been summarised away, and
3667
+ // the prompt has to move anyway. Everywhere else they stay behind
3668
+ // `read_memory()` so the prefix cache is never disturbed.
3669
+ try {
3670
+ const notes = (await fs.readFile(this.memoryFile, "utf8")).trim();
3671
+ if (notes) {
3672
+ this.messages.splice(1, 0, {
3673
+ role: "user",
3674
+ content: `[harness] Your durable notes (memory.md), re-attached after compaction — ` +
3675
+ `this is what earlier you chose to remember:\n\n${notes.slice(0, 8_000)}`,
3676
+ });
3677
+ }
3678
+ }
3679
+ catch {
3680
+ /* no notes yet — nothing to re-attach */
3681
+ }
3682
+ }
3554
3683
  if (this.recentReads.length && mode === "summarize") {
3555
3684
  const restored = [];
3556
3685
  const restoredPaths = new Set();
@@ -4018,15 +4147,37 @@ function allToolSpecs() {
4018
4147
  type: "function",
4019
4148
  function: {
4020
4149
  name: "read_memory",
4021
- description: "Read your durable notes (memory.md).",
4022
- parameters: { type: "object", properties: {} },
4150
+ description: "Read your durable notes (memory.md). Pass `query` to search for the lines that mention something — cheaper than reading the whole file, and the right call when you only need to check one fact.",
4151
+ parameters: {
4152
+ type: "object",
4153
+ properties: {
4154
+ query: {
4155
+ type: "string",
4156
+ description: "case-insensitive substring; omit it to get the whole file",
4157
+ },
4158
+ },
4159
+ },
4160
+ },
4161
+ },
4162
+ {
4163
+ type: "function",
4164
+ function: {
4165
+ name: "forget_memory",
4166
+ description: "Delete the lines of memory.md that match a substring. Use it to remove a note that became wrong, or to consolidate duplicates. Returns what was removed, so a mistake is visible and re-addable.",
4167
+ parameters: {
4168
+ type: "object",
4169
+ properties: {
4170
+ query: { type: "string", description: "case-insensitive substring of the line(s) to delete" },
4171
+ },
4172
+ required: ["query"],
4173
+ },
4023
4174
  },
4024
4175
  },
4025
4176
  {
4026
4177
  type: "function",
4027
4178
  function: {
4028
4179
  name: "set_memory",
4029
- description: "Overwrite your durable notes (memory.md). Keep them terse: decisions, gotchas, where you left off.",
4180
+ description: "REPLACE your durable notes (memory.md) entirely — anything you do not include is lost. Prefer add_memory unless you are rewriting the whole file. Keep notes terse: decisions, gotchas, where you left off.",
4030
4181
  parameters: {
4031
4182
  type: "object",
4032
4183
  properties: { content: { type: "string" } },
@@ -4034,6 +4185,18 @@ function allToolSpecs() {
4034
4185
  },
4035
4186
  },
4036
4187
  },
4188
+ {
4189
+ type: "function",
4190
+ function: {
4191
+ name: "add_memory",
4192
+ description: "Append one note to memory.md without touching what is already there. Use this to remember a decision, a gotcha, or where you left off — it cannot lose earlier notes (#48).",
4193
+ parameters: {
4194
+ type: "object",
4195
+ properties: { text: { type: "string", description: "the note to append, one or two lines" } },
4196
+ required: ["text"],
4197
+ },
4198
+ },
4199
+ },
4037
4200
  {
4038
4201
  type: "function",
4039
4202
  function: {
@@ -4084,7 +4247,7 @@ function rebuildMessagesFrom(list) {
4084
4247
  const msgs = [];
4085
4248
  const META_TOOLS = new Set([
4086
4249
  "finish", "report_progress", "set_goal", "get_goal",
4087
- "read_memory", "set_memory", "list_skills", "get_todo", "set_todo",
4250
+ "read_memory", "set_memory", "add_memory", "forget_memory", "list_skills", "get_todo", "set_todo",
4088
4251
  "get_feedback", "add_feedback", "record_decision", "get_decisions",
4089
4252
  ]);
4090
4253
  const openCalls = new Map(); // real tool_call id -> name
@@ -4240,7 +4403,8 @@ function rebuildMessagesFrom(list) {
4240
4403
  msgs.splice(0, summarized, {
4241
4404
  role: "user",
4242
4405
  content: `[harness] Context was compacted: ${summarized} earlier messages were summarized. ` +
4243
- "Goal and notes are managed by the harness (AGENTS.md / memory.md are injected into your prompt when present).\n\n" +
4406
+ "AGENTS.md is embedded in your system prompt; memory.md, todo.md and decisions.md are NOT — "
4407
+ + "call read_memory / get_todo / get_decisions if you need them.\n\n" +
4244
4408
  `## Summary of earlier conversation\n${sum}`,
4245
4409
  });
4246
4410
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teapot-coding-agent",
3
- "version": "0.29.25",
3
+ "version": "0.29.26",
4
4
  "description": "A lightweight, always-on multi-agent harness for AI coding agents",
5
5
  "type": "module",
6
6
  "license": "AGPL-3.0-or-later",