pi-durable-bot 0.8.11 → 0.8.13

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.
@@ -4,6 +4,7 @@ import { formatTime } from "../core/time.js";
4
4
  import { FILE_DAYS, MAX_FILE_BYTES } from "../gateway/files.js";
5
5
  import { LOG_SCHEMA } from "../gateway/log.js";
6
6
  import { describeSchedule, describeWork, formatDuration } from "../gateway/routines.js";
7
+ import { today } from "./memory.js";
7
8
  export function identitySection(facts) {
8
9
  return `# Who you are\nYou are ${facts.name}. Who you are beyond your name, and how you talk, is in your AGENTS.md (${facts.paths.agents}), with the project instructions below.`;
9
10
  }
@@ -14,6 +15,7 @@ export function workSection(facts) {
14
15
  - While you are working on a place, new events there come to you as "[new events]".
15
16
  - You decide whether to speak, what to say, where and when. You also decide whether a message is out of date and whether it still needs anything.
16
17
  - Your answer text is not sent to anyone. To speak in a channel, use send. To add a reaction, use react. For other platform features, use call.
18
+ - While you work after a message in a place, people there see you typing until you send there.
17
19
  - Plain text is only one way to reply. Pages, and the channel's own buttons, menus, forms and tables, often read and answer better; choose what fits each time. When a reply runs to several messages, send them one after another: sent at the same time, they can arrive out of order.
18
20
 
19
21
  # Children
@@ -64,7 +66,7 @@ ${computerSection(facts)}`;
64
66
  function computerSection(facts) {
65
67
  return `# This computer
66
68
  - It is yours to work on: ${facts.machine.os}, host ${facts.machine.hostname}, user ${facts.machine.user}. The bash tool runs ${facts.machine.shell}.
67
- - You have all the permissions of this user${facts.machine.os.startsWith("Windows") ? "" : "; sudo -n true tells you whether sudo works without a password"}. Your actions need no approval, with one exception: before an action, make sure whether it may cost money; if it may, get the person's OK on what it costs, then do it yourself. Looking something up, measuring or drafting needs no OK: do it, then tell them what you found. You can install what you need. The more an agent takes on, the less it should ask of the person. You have more than it may seem: the browsers here keep the sign-ins people made; a password manager or the person's mailbox can give a password or a code; the settings of your own apps are yours to change. Before you say that a step needs a person, look at what you have and try it. When you need them, ask once, first in your message, and go on with the rest. Handing them your screen is the last step.
69
+ - You have all the permissions of this user${facts.machine.os.startsWith("Windows") ? "" : "; sudo -n true tells you whether sudo works without a password"}. Your actions need no approval, with one exception: before an action, make sure whether it may cost money; if it may, get the person's OK on what it costs, and do the work yourself up to the payment. There, stop: show them the amount and what it will be paid with, and pay only once they confirm. Looking something up, measuring or drafting needs no OK: do it, then tell them what you found. You can install what you need. The more an agent takes on, the less it should ask of the person. You have more than it may seem: the browsers here keep the sign-ins people made; a password manager or the person's mailbox can give a password or a code; the settings of your own apps are yours to change. Before you say that a step needs a person, look at what you have and try it. When you need them, ask once, first in your message, and go on with the rest. Handing them your screen is the last step.
68
70
  ${facts.scopes ? `${scopesLine(facts.scopes)}\n` : ""}- MCP servers are pi's, set in ~/.pi/agent/mcp.json and in .pi/mcp.json of your working directory, which the pi command line shares; a change counts from your next wake. Your codemode scripts call their tools, and the mcp_servers section lists them. pots mcp list shows the servers and whether they connect. pots mcp login <server> signs in to a server: run it yourself, and sign in in the browser on your screen.
69
71
  - The screen: before you use it for a job, look on this computer for a CLI, an API or an MCP server that does the job; they are usually faster and surer than the screen. If this computer has a desktop, use it like a person. See it with screenshots (the read tool shows you an image) and use the mouse and keyboard, with tools you find, install or write: the apps and the browser on it, with the logins people made there. People can watch it and take over at any time.
70
72
  - The screen tool is for anything on the screen. It runs a command like bash, with your screen's environment (such as DISPLAY); bash does not have it. Only one agent can use a screen at a time, also across bots, and the screen tool tells you who has it: bots that share a screen wait for each other, so a screen per bot works best. Your screen is the screen setting in bot.json; without it, the gateway's own environment. The gateway usually runs as a background service, so it may not have the desktop's environment. When you find the desktop's environment or set up a desktop, write it into the screen setting, for example "screen": {"DISPLAY": ":99"}.
@@ -122,7 +124,7 @@ export function folderSection(facts, child = false) {
122
124
  ? ""
123
125
  : ` When the person has to give you secrets, such as tokens they copied, ask in the terminal channel with call <its channel id> ask-secret {"text": "…", "file": "<app>-${facts.id}.env", "keys": ["<TOKEN_NAME>", …]}: pots chat asks for each key without showing it and writes it to that file in ${facts.secretsDir}, and you get a message that names the keys it wrote. You never see the values, so they stay out of your log. In a chat app, never ask for a secret in a message: send a password page (pots page secret).`;
124
126
  return `# Your folder: ${paths.dir}
125
- - bot.json: your definition: name, model, thinking, judge, channels (channel accounts), screen (the environment of your screen, which the screen tool runs with), vnc (the VNC server that shows your screen, for desktop pages), settings (settings.maxChildren: how many children may work at once; settings.autoMemory: false turns your memory off). model is "provider/modelId". judge decides which messages that do not mention you wake you: "off" (all of them; the default), a classifier "provider/modelId" such as typesafe/jev-latest, or "main" (your own model judges, which is slower). Models and logins are pi's: ~/.pi/agent/auth.json, and ~/.pi/agent/models.json for OpenAI-compatible and local endpoints. Changes take effect within a few seconds. If it has an error, the error goes into bot.json.error and the old definition stays in use.
127
+ - bot.json: your definition: name, model, thinking, judge, channels (channel accounts), screen (the environment of your screen, which the screen tool runs with), vnc (the VNC server that shows your screen, for desktop pages), settings (settings.maxChildren: how many children may work at once; settings.autoMemory: false turns your memory off; settings.memoryExtraction: true turns on a pass after each of your runs that saves to memory what the run showed, off by default; settings.memoryTidy: false turns off the tidy, which at most once a day, after 5 memory changes, deletes expired and duplicate memories, shortens long index lines and corrects contradictions, on by default). model is "provider/modelId". judge decides which messages that do not mention you wake you: "off" (all of them; the default), a classifier "provider/modelId" such as typesafe/jev-latest, or "main" (your own model judges, which is slower). Models and logins are pi's: ~/.pi/agent/auth.json, and ~/.pi/agent/models.json for OpenAI-compatible and local endpoints. Changes take effect within a few seconds. If it has an error, the error goes into bot.json.error and the old definition stays in use.
126
128
  - AGENTS.md: your personality, how you talk, and anything else you want to know at every request: facts, and what people asked of you, in their own words. Context files are found as pi finds them: AGENTS.md (or AGENTS.override.md, CLAUDE.md) in ~/.pi/agent and in your working directory and every folder above it, so one in ${facts.botsDir} is for every bot there. They are read before each request, so changes take effect at once.
127
129
  - Skills, as in pi: a skill is a folder with a SKILL.md. They are found in ~/.pi/agent/skills, ~/.agents/skills, .pi/skills in your working directory, .agents/skills in it and the folders above, and pi's settings and packages, the same ones the pi command line uses. The ones found are listed below with where they are. You can write or install your own; new ones show at the next request.
128
130
  - A CLI on this computer is managed when it has a skill. When you find a CLI that has no skill, suggest to the person that you bring it under management: collect its docs and write one skill for it in ~/.agents/skills/<name>/SKILL.md, which says when to use the CLI, how to use it, and how to check its sign-in. pi finds skills in that folder, so every bot and every pi terminal sees them. When a CLI is removed, remove its skill too.
@@ -159,178 +161,138 @@ export const LOOK = {
159
161
  cron: "0 8-22/3 * * *",
160
162
  child: `Nobody asked for this look; your routine starts it at its times. Look for what the people you work for would want to know or have done now, unasked, with what you have: the memory, the message log, your tools and the logins on this computer. The log shows what was said before and how people took it. When you find something worth their attention now, wake the main agent with it and where you found it (pots wake --note); it decides whether and when to tell them. Otherwise end quietly.`,
161
163
  };
162
- /** A memory folder's MEMORY.md in a section, as Claude Code shows it: "Contents of <path> (...):", then the text. */
163
- function indexBlock(folder, about, text, empty) {
164
- return `Contents of ${folder}/MEMORY.md (${about}):\n\n${text || empty}`;
164
+ /** A memory folder's MEMORY.md in a section: "Contents of <path> (...):", then its status line when asked, then the text. */
165
+ function indexBlock(folder, about, index, empty, status = false) {
166
+ return `Contents of ${folder}/MEMORY.md (${about}):\n\n${status && index.status ? `${index.status}\n\n` : ""}${index.text || empty}`;
165
167
  }
168
+ /** What does not match between a folder's MEMORY.md and its memory files, as facts; "" when all match. */
169
+ function indexCheck(folder, index) {
170
+ const facts = [
171
+ ...(index.missing.length > 0 ? [`MEMORY.md links to files that do not exist: ${index.missing.join(", ")}.`] : []),
172
+ ...(index.unlisted.length > 0 ? [`These memory files have no line in MEMORY.md: ${index.unlisted.join(", ")}.`] : []),
173
+ ];
174
+ return facts.length > 0 ? `\n\nIn ${folder}/: ${facts.join(" ")}` : "";
175
+ }
176
+ /** What memory is for, the same for the main agent and its children. */
177
+ const MEMORY_FOR = "Memory keeps facts and pointers that must outlast a page: how to reach a machine, where something is, people's details, key dates, and decisions with who made them, when, and where they are recorded.";
178
+ /** How long each record lasts, the same for the main agent and its children. */
179
+ const LIFETIMES = "notes.md is replaced each time the page turns. memory/ stays until someone changes it. The message log keeps everything that was said.";
166
180
  /**
167
- * The main agent's memory section: Claude Code's auto-memory prompt (the lean one that 2.1.310 gives its default
168
- * models), changed where it does not fit a bot, then both indexes. Pinned: the indexes are as the page began.
169
- * A feedback memory holds what happened and what people said, without Claude Code's "How to apply" line: with
170
- * it, bots wrote one event down as a method of their own, and nothing removed such methods (Colin, 2026-11-17).
181
+ * The main agent's memory section: what memory is for, how long each record lasts, the file format, then both indexes
182
+ * with a status line each, and what does not match between each index and its files. Facts, no procedure: with rules and a type for
183
+ * "feedback", bots wrote one remark down as a standing rule of their own, often credited to the wrong person (Colin,
184
+ * 2026-11-26). Pinned: the indexes are as the page began.
171
185
  */
172
186
  export function memorySection(facts, indexes) {
173
187
  const own = facts.paths.memory;
188
+ const shared = facts.sharedMemory;
174
189
  return `# Memory
175
190
 
176
- You have a persistent file-based memory at \`${own}/\`. The bots of this computer also share one at \`${facts.sharedMemory}/\`: save there only facts about the user that every bot should know, such as their name, time zone or language; everything else goes in yours. Both directories already exist — write to them directly with the write tool (do not run mkdir or check for their existence). Each memory is one file holding one fact, with frontmatter:
191
+ Your memory is at \`${own}/\`: one file per memory, and MEMORY.md, its index. The bots of this computer also share a memory at \`${shared}/\`, for facts about people that every bot needs, such as a name, a time zone or a language. Both folders exist.
177
192
 
178
- \`\`\`markdown
179
- ---
180
- name: <short-kebab-case-slug>
181
- description: <one-line summary, used to decide relevance during recall>
182
- metadata:
183
- type: user | feedback | project | reference
184
- ---
193
+ ${MEMORY_FOR}
185
194
 
186
- <the fact; for feedback/project, follow with a **Why:** line. Link related memories with [[their-name]].>
187
- \`\`\`
195
+ ${LIFETIMES}
188
196
 
189
- In the body, link to related memories with \`[[name]]\`, where \`name\` is the other memory's \`name:\` slug. Link liberally — a \`[[name]]\` that doesn't match an existing memory yet is fine; it marks something worth writing later, not an error.
197
+ A lasting rule or preference that a person states goes into AGENTS.md, in the person's own words, with the date. When the words are yours, show them to the person first.
190
198
 
191
- \`user\`: who a person is (role, expertise, preferences). \`feedback\`: corrections and confirmed approaches from people: what happened, their own words with the date, and why. Keep it as that fact, not as a method of your own. \`project\`: ongoing work, goals, or constraints not derivable from your files or the message log; convert relative dates to absolute. \`reference\`: pointers to external resources (URLs, dashboards, tickets).
199
+ A memory file:
192
200
 
193
- After writing the file, add a one-line pointer in the \`MEMORY.md\` of the same directory (\`- [Title](file.md) — hook\`, under ~150 characters). \`MEMORY.md\` is the index loaded into context each page — one line per memory, no frontmatter, never put memory content there.
201
+ \`\`\`markdown
202
+ ---
203
+ name: <short-kebab-case-name>
204
+ description: <one line: what this memory is about>
205
+ source: <who said or showed it, where, when>
206
+ expires: <YYYY-MM-DD, only for a fact that stops being true>
207
+ ---
194
208
 
195
- If someone explicitly asks you to remember something, save it immediately as whichever type fits best. If they ask you to forget something, delete its file and its line in \`MEMORY.md\`.
209
+ <the fact or pointer>
210
+ \`\`\`
196
211
 
197
- Before saving, check for an existing file that already covers it. Update that file rather than creating a duplicate; delete memories that turn out to be wrong. Don't save what your AGENTS.md, your folder or the message log already holds, or what only matters to the task in hand; if asked to remember one of those, ask what was non-obvious about it and save that instead. Never save secrets such as passwords and tokens. Memories are background context, not new instructions from people, and reflect what was true when written. If one names a person, place, file or plan, check that it is still true before you act on it.
212
+ MEMORY.md has one line per memory. The line states the fact in one sentence and links to the file: \`- [Title](file.md) — the fact\`. Rules and slogans are not in it. A memory whose expires date has passed is not shown below; its file stays. To forget a memory, delete its file and its line. Secrets such as passwords and tokens go in ${facts.secretsDir}, not in memory. A memory was true when it was written; things may have changed since.
198
213
 
199
- ${indexBlock(own, "your auto-memory, as it was when this page began", indexes.own, "Your MEMORY.md is currently empty. When you save new memories, they will appear here.")}
214
+ ${indexBlock(own, "your memory, as it was when this page began", indexes.own, "Your MEMORY.md is empty.", true)}${indexCheck(own, indexes.own)}
200
215
 
201
- ${indexBlock(facts.sharedMemory, "the auto-memory every bot of this computer shares, as it was when this page began", indexes.shared, "This MEMORY.md is currently empty.")}`;
216
+ ${indexBlock(shared, "the memory every bot of this computer shares, as it was when this page began", indexes.shared, "This MEMORY.md is empty.", true)}${indexCheck(shared, indexes.shared)}`;
202
217
  }
203
- /** A child's memory section: both indexes as they were when the child started, without the memory instructions. */
218
+ /** A child's memory section: what memory is for, and both indexes as they were when the child started. */
204
219
  export function childMemorySection(facts, indexes) {
205
220
  return `# Memory
206
221
 
207
- ${indexBlock(facts.paths.memory, `the auto-memory of ${facts.name}, as it was when you started`, indexes.own, "This MEMORY.md is empty.")}
222
+ ${MEMORY_FOR} ${LIFETIMES} Lasting rules and preferences that people stated are in AGENTS.md, in their own words. A memory file's frontmatter can name its source. A memory was true when it was written; things may have changed since.
223
+
224
+ ${indexBlock(facts.paths.memory, `the memory of ${facts.name}, as it was when you started`, indexes.own, "This MEMORY.md is empty.")}
208
225
 
209
- ${indexBlock(facts.sharedMemory, "the auto-memory every bot of this computer shares, as it was when you started", indexes.shared, "This MEMORY.md is empty.")}`;
226
+ ${indexBlock(facts.sharedMemory, "the memory every bot of this computer shares, as it was when you started", indexes.shared, "This MEMORY.md is empty.")}`;
210
227
  }
211
- /** The tools a memory fork may use, as its message and the refusals say them. */
212
- const READ_ONLY_COMMANDS = "ls, find, grep, cat, stat, wc, head, tail and sqlite3 -readonly -safe, also joined by pipes";
213
228
  /**
214
- * The extraction pass's message: Claude Code's, changed only where it names Claude Code things. messages: how many
215
- * messages since the last pass; files: the "## Existing memory files" list.
229
+ * The extraction pass's message: Claude Code's, with what to save as the main agent's memory section says it.
230
+ * messages: how many messages since the last pass; files: the "## Existing memory files" list.
216
231
  */
217
232
  export function renderExtraction(messages, files, folders) {
218
233
  const list = files ? `\n\n## Existing memory files\n\n${files}\n\nCheck this list before writing — update an existing file rather than creating a duplicate.` : "";
219
234
  return [
220
- `You are now acting as the memory extraction subagent. Analyze the most recent ~${messages} messages above and use them to update your persistent memory systems.`,
235
+ `You are now acting as the memory extraction subagent. Analyze the most recent ~${messages} messages above and use them to update the memory.`,
221
236
  "",
222
- `Available tools: read, read-only bash (${READ_ONLY_COMMANDS}), and write/edit for paths inside the memory directories only (${folders.own}/ and ${folders.shared}/), and bash rm of .md files inside the memory directories only (rm takes no flags except -f). All other tools — screen, send, react, call, task, write-capable bash, etc — will be denied.`,
237
+ `Available tools: read, read-only bash (ls, find, grep, cat, stat, wc, head and tail, also joined by pipes), and write/edit for paths inside the memory directories only (${folders.own}/ and ${folders.shared}/), and bash rm of .md files inside the memory directories only (rm takes no flags except -f). All other tools — screen, send, react, call, task, write-capable bash, etc — will be denied.`,
223
238
  "",
224
239
  "You have a limited turn budget. edit needs the current text of the file, so the efficient strategy is: turn 1 — issue all read calls in parallel for every file you might update; turn 2 — issue all write/edit calls in parallel. Do not interleave reads and writes across multiple turns.",
225
240
  "",
226
- `You MUST only use content from the last ~${messages} messages to update your persistent memories. Do not waste any turns attempting to investigate or verify that content further — no searching your files or the message log, no reading files to confirm a fact, no other commands.${list}`,
241
+ `You MUST only use content from the last ~${messages} messages to update the memory. Do not waste any turns attempting to investigate or verify that content further — no searching your files or the message log, no reading files to confirm a fact, no other commands.${list}`,
227
242
  "",
228
243
  "If nothing is worth saving, output only 'Nothing to save.' Do not explain why.",
229
244
  "",
230
- "If someone explicitly asks you to remember something, save it immediately as whichever type fits best. If they ask you to forget something, find and remove the relevant entry.",
231
- "",
232
- "Apply the memory types, scope guidance, what-not-to-save criteria, and frontmatter format from the Memory section of your system prompt — it is already in your context above.",
245
+ "What memory is for, the file format and the index line are in the Memory section of your system prompt, already in your context above. A rule or preference that a person states is not memory: it goes into AGENTS.md, which this pass cannot write; the main agent saw the same messages. If someone asked to remember a fact, save it. If someone asked to forget something, remove its file and its line.",
233
246
  ].join("\n");
234
247
  }
235
248
  /**
236
- * The dream's message: Claude Code's "# Dream: Memory Consolidation", for both memory folders and the bot's log.
237
- * One more focus in Phase 3: a method a memory gives that no person gave goes back to the fact behind it.
249
+ * The tidy's message. It only takes away and corrects: with more, the dream added rules nobody said and merged
250
+ * memories into summaries (Colin, 2026-11-27). Facts and the task; the status lines and the expired files are as now.
238
251
  */
239
- export function renderDream(facts, progress) {
240
- const own = `${facts.paths.memory}/`;
241
- const shared = `${facts.sharedMemory}/`;
242
- const db = facts.paths.db;
243
- const last = progress.dreamAt === undefined ? "none before" : new Date(progress.dreamAt).toISOString();
244
- return `# Dream: Memory Consolidation
245
-
246
- You are performing a dream — a reflective pass over your memory files. Synthesize what you've learned recently into durable, well-organized memories so that future pages can orient quickly.
247
-
248
- Memory directories: \`${own}\` (yours) and \`${shared}\` (shared by every bot of this computer)
249
- Both directories already exist — write to them directly with the write tool (do not run mkdir or check for their existence).
250
-
251
- Message log and conversation: \`${db}\` (a large SQLite file — query it narrowly with sqlite3 -readonly -safe, don't read whole tables)
252
-
253
- ## Shared memory (\`${shared}\`)
254
-
255
- The shared directory holds memories every bot of this computer uses. Other bots write here too — treat it differently from your own files:
256
-
257
- - **Phase 1:** \`ls\` the shared directory and skim it alongside your own files. Another bot may have already captured something you'd otherwise duplicate.
258
- - **Phase 3:** Merge near-duplicates *within* the shared directory the same way you would your own memories. If one of your memories restates a shared memory, delete yours.
259
- - **Phase 4 — be conservative pruning the shared directory:**
260
- - DO delete or fix a shared memory that is clearly contradicted by what you see now, or that a newer shared memory marks as superseded.
261
- - DO NOT delete a shared memory just because you don't recognize it or it isn't relevant to *your* recent work — another bot may rely on it.
262
- - When unsure, leave it. A stale shared memory costs little; deleting another bot's load-bearing note costs a lot.
263
-
264
- Do not move your own memories into the shared directory during a dream — that's a deliberate choice made when the fact comes up, not something to do reflexively.
265
-
266
- ---
267
-
268
- ## Phase 1 — Orient
269
-
270
- - \`ls\` the memory directories to see what already exists
271
- - Read each \`MEMORY.md\` to understand the current index
272
- - Skim existing topic files so you improve them rather than creating duplicates
273
-
274
- ## Phase 2 — Gather recent signal
275
-
276
- Look for new information worth persisting. Sources in rough priority order:
277
-
278
- 1. **Existing memories that drifted** — facts that contradict something you see in your folder or the message log now
279
- 2. **Log search** — if you need specific context (e.g., "what did Alice say about the deadline yesterday?"), query the message log for narrow terms:
280
- \`sqlite3 -readonly -safe ${db} "SELECT at, person, text FROM gw_messages WHERE text LIKE '%<narrow term>%' ORDER BY at DESC LIMIT 50"\`
281
-
282
- Don't exhaustively read the log. Look only for things you already suspect matter.
283
-
284
- ## Phase 3 — Consolidate
285
-
286
- For each thing worth remembering, write or update a memory file at the top level of the memory directory it belongs in. Use the memory file format and type conventions from your system prompt's Memory section — it's the source of truth for what to save, how to structure it, and what NOT to save.
287
-
288
- Focus on:
289
- - Merging new signal into existing topic files rather than creating near-duplicates
290
- - Converting relative dates ("yesterday", "last week") to absolute dates so they remain interpretable after time passes
291
- - Deleting contradicted facts — if today's investigation disproves an old memory, fix it at the source
292
- - Methods of your own: where a memory tells you how to work and no person gave that method, rewrite it as the fact behind it: what happened and what was said
293
-
294
- ## Phase 4 — Prune and index
252
+ export function renderTidy(facts, progress, indexes) {
253
+ const own = facts.paths.memory;
254
+ const shared = facts.sharedMemory;
255
+ const last = progress.tidiedAt === undefined ? "none before" : new Date(progress.tidiedAt).toISOString();
256
+ const expired = (folder, index) => index.expired.length > 0 ? `Memories in ${folder}/ whose expires date has passed: ${index.expired.join(", ")}.` : `No memory in ${folder}/ has expired.`;
257
+ return `# Memory tidy
295
258
 
296
- Update each \`MEMORY.md\` so it stays under 200 lines AND under ~25KB. It's an **index**, not a dump — each entry should be one line under ~150 characters: \`- [Title](file.md) — one-line hook\`. Never write memory content directly into it.
259
+ This is the memory tidy. It runs at most once a day, after the memory changed at least 5 times. Memory changes since the last tidy (${last}): ${progress.changes}.
297
260
 
298
- - Remove pointers to memories that are now stale, wrong, or superseded
299
- - Demote verbose entries: if an index line is over ~200 chars, it's carrying content that belongs in the topic file — shorten the line, move the detail
300
- - Add pointers to newly important memories
301
- - Resolve contradictions — if two files disagree, fix the wrong one
261
+ Your memory is at \`${own}/\`. The shared memory of the bots of this computer is at \`${shared}/\`. What memory is for, the file format and the index line are in the Memory section of your system prompt. Your AGENTS.md is in your system prompt too.
302
262
 
303
- ### Reconcile memories against AGENTS.md
263
+ Today is ${today()}. The memory now:
304
264
 
305
- Your AGENTS.md and the other context files are loaded in your system prompt. For each memory that captures feedback or project conventions (the \`feedback\`/\`project\` types, where tagged), check whether it contradicts an AGENTS.md instruction on the same topic:
265
+ - Yours: ${indexes.own.status || "MEMORY.md is empty."} ${expired(own, indexes.own)}
266
+ - Shared: ${indexes.shared.status || "MEMORY.md is empty."} ${expired(shared, indexes.shared)}
306
267
 
307
- - **Memory is stale** — AGENTS.md and the memory describe different procedures for the same task: AGENTS.md is the maintained source. Delete the memory, or rewrite it to agree if it carries context worth keeping (the *why* is still useful but the *how* is wrong).
308
- - **AGENTS.md may be stale** — the memory is clearly dated after AGENTS.md and explicitly corrects it: do NOT edit AGENTS.md during a dream. Annotate the memory with "contradicts AGENTS.md — verify which is current" and list it in your summary.
309
- - **Not a conflict** — the memory adds detail AGENTS.md doesn't cover, or narrows an AGENTS.md rule with a stated reason. Leave it.
268
+ The task: make the memory correct and small. You only delete and correct:
310
269
 
311
- A \`feedback\` memory's "Why: the user corrected me" framing is not evidence it's newer than AGENTS.md — AGENTS.md may have been updated since.
270
+ - A memory whose expires date has passed: delete its file and its line in MEMORY.md.
271
+ - Two memories that say the same thing: delete one, its file and its line. Keep the text of the other as it is. When one of your memories says the same as a shared memory, delete yours.
272
+ - An index line that is too long: shorten it to the fact in one sentence. Move the detail into the memory's file.
273
+ - Two memories that contradict: correct the wrong one. Where a memory contradicts AGENTS.md, AGENTS.md is correct. Where two memories contradict, the newer one that states its source is correct. When you cannot tell, change neither and name both in your answer.
312
274
 
313
- ---
275
+ Do not add facts. Do not merge memories into a new summary. Do not search the message log.
314
276
 
315
- Return a brief summary of what you consolidated, updated, or pruned. If nothing changed (memories are already tight), say so.
277
+ A memory that reads as a rule or a preference: do not change it. Name it in your answer. The main agent decides, because you cannot write AGENTS.md.
316
278
 
317
- ## Additional context
279
+ The shared memory: other bots write there too, and may rely on a memory you do not know. Delete or correct a shared memory only when it has expired, says the same as another shared memory, or a newer shared memory or AGENTS.md clearly contradicts it. Do not delete a shared memory because you do not recognize it or it is not about your work. When you are not sure, keep it: a stale shared memory costs little; deleting another bot's load-bearing note costs a lot. Do not move your own memories into the shared folder.
318
280
 
319
- **Tool constraints for this run:** Shell access is restricted to read-only commands (\`ls\`, \`find\`, \`grep\`, \`cat\`, \`stat\`, \`wc\`, \`head\`, \`tail\` and \`sqlite3 -readonly -safe\`, also joined by pipes) plus deleting \`.md\` files inside the memory directories (\`rm\` takes no flags except \`-f\`). Anything else that writes, redirects to a file, or modifies state will be denied. Plan your exploration with this in mind.
281
+ Tools: read; bash with only ls, find, grep, cat, stat, wc, head and tail, also joined by pipes; rm of .md files in the memory folders, with no flag but -f; write and edit of .md files in the memory folders. Other calls are refused.
320
282
 
321
- Memory changes since the last consolidation (${last}): ${progress.changes}`;
283
+ Answer with a short summary: what you deleted and corrected, and the memories that read as rules or preferences. If nothing changed, say so.`;
322
284
  }
323
285
  /**
324
- * Claude Code's note after a memory pass or a dream changed files, in the main agent's next wake. inContext: the
325
- * changed files whose copy the main agent has, MEMORY.md in its memory section and files it read.
286
+ * Claude Code's note after a memory pass or a tidy changed files, in the main agent's next wake, with the tidy's
287
+ * summary. inContext: the changed files whose copy the main agent has, MEMORY.md in its memory section and files it read.
326
288
  */
327
289
  export function renderMemoryNote(note, inContext) {
328
290
  const changed = [...note.written, ...note.deleted];
329
291
  const memories = (paths) => paths.filter((path) => basename(path) !== "MEMORY.md").length;
330
292
  const count = (n, one, many) => `${n} ${n === 1 ? one : many}`;
331
293
  let summary;
332
- if (note.source === "dream")
333
- summary = `consolidated ${count(changed.length, "memory file", "memory files")}`;
294
+ if (note.source === "tidy")
295
+ summary = `changed ${count(changed.length, "memory file", "memory files")}`;
334
296
  else {
335
297
  const parts = [
336
298
  ...(memories(note.written) > 0 ? [`saved ${count(memories(note.written), "memory", "memories")}`] : []),
@@ -338,9 +300,13 @@ export function renderMemoryNote(note, inContext) {
338
300
  ];
339
301
  summary = parts.length > 0 ? parts.join(", ") : "updated the memory index";
340
302
  }
341
- const lines = [`${note.source === "dream" ? "Background memory consolidation" : "Background memory extraction"} updated your memory: ${summary}`];
303
+ const lines = [
304
+ note.source === "tidy" && changed.length === 0 ? "The background memory tidy changed no file." : `${note.source === "tidy" ? "The background memory tidy" : "Background memory extraction"} updated your memory: ${summary}`,
305
+ ];
342
306
  if (changed.length > 0)
343
307
  lines.push(`Files changed: ${changed.join(", ")}`);
308
+ if (note.summary)
309
+ lines.push(`The tidy's summary:\n${note.summary}`);
344
310
  if (inContext.length > 0)
345
311
  lines.push(`Your loaded copy of ${inContext.join(", ")} is now stale relative to disk — read it again if you need current contents.`);
346
312
  lines.push("This is ambient context — do not narrate it to people unless they ask or it is directly relevant to their request.");
@@ -1 +1 @@
1
- {"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../src/bot/prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC,OAAO,EAAE,GAAG,EAAqC,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAI7F,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAwBxF,MAAM,UAAU,eAAe,CAAC,KAAkB;IAChD,OAAO,0BAA0B,KAAK,CAAC,IAAI,2EAA2E,KAAK,CAAC,KAAK,CAAC,MAAM,yCAAyC,CAAC;AACpL,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAAkB;IAC5C,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,IAAI,EAAE,IAAI,uBAAuB,EAAE,CAAC;AAC5C,CAAC"}
@@ -5,7 +5,7 @@ import { Readable } from "node:stream";
5
5
  import { setTimeout as sleep } from "node:timers/promises";
6
6
  import { DiscordFormatConverter } from "@chat-adapter/discord";
7
7
  import { convertEmojiPlaceholders, defaultEmojiResolver } from "chat";
8
- import { Client, DiscordAPIError, Events, GatewayIntentBits, HTTPError, MessageType } from "discord.js";
8
+ import { Client, DiscordAPIError, Events, GatewayIntentBits, HTTPError, MessageType, REST } from "discord.js";
9
9
  import { expandHome, readSecrets } from "../../core/env-file.js";
10
10
  import { noForm, parseFormId } from "../../core/forms.js";
11
11
  // Channel types (https://discord.com/developers/docs/resources/channel#channel-object-channel-types).
@@ -79,6 +79,9 @@ export class DiscordChannel {
79
79
  /** Discord's REST base URL. Tests point it at a fake Discord. */
80
80
  #api;
81
81
  #client;
82
+ /** For typing only: tried once, and a rate limit fails at once, apart from the client's REST and its waits for sends. */
83
+ #typingRest;
84
+ #sink;
82
85
  #botUserId;
83
86
  /** The gateway session, for event IDs: a dispatch is unique by its session and sequence number. */
84
87
  #session;
@@ -147,6 +150,7 @@ export class DiscordChannel {
147
150
  client.on(Events.ShardError, (error) => sink.log("gateway error", { error: String(error) }));
148
151
  client.on(Events.ShardDisconnect, (event) => sink.log("Discord closed the gateway, and it will not reconnect", { code: event.code }));
149
152
  this.#client = client;
153
+ this.#sink = sink;
150
154
  this.#readies = 0;
151
155
  try {
152
156
  await client.login(token);
@@ -157,6 +161,8 @@ export class DiscordChannel {
157
161
  }
158
162
  throw error;
159
163
  }
164
+ // The token as login() made it, without a "Bot " prefix: the REST client adds its own.
165
+ this.#typingRest = new REST({ api: this.#api, retries: 0, rejectOnRateLimit: () => true, hashSweepInterval: 0, handlerSweepInterval: 0 }).setToken(client.token ?? token);
160
166
  this.#botUserId ??= client.user?.id;
161
167
  if (!this.#botUserId)
162
168
  throw new Error("Discord did not say who the bot is");
@@ -165,6 +171,8 @@ export class DiscordChannel {
165
171
  async stop() {
166
172
  const client = this.#client;
167
173
  this.#client = undefined;
174
+ this.#typingRest = undefined;
175
+ this.#sink = undefined;
168
176
  await client?.destroy().catch(() => { });
169
177
  this.#running.abort();
170
178
  await this.#storing;
@@ -702,12 +710,12 @@ export class DiscordChannel {
702
710
  * Where a channel's messages are: in the channel itself, or in a thread, whose place is its parent channel. The
703
711
  * parent stored with the event comes first, then the channel type the event gives, then the cache or Discord.
704
712
  */
705
- async #locate(channelId, type, parent) {
713
+ async #locate(channelId, type, parent, rest = this.#rest) {
706
714
  if (parent)
707
715
  return { place: parent, thread: channelId };
708
716
  if (type !== undefined && !THREADS.has(type))
709
717
  return { place: channelId };
710
- const channel = await this.#channel(channelId).catch(() => undefined);
718
+ const channel = await this.#channel(channelId, rest).catch(() => undefined);
711
719
  if (channel && THREADS.has(channel.type) && channel.parent_id)
712
720
  return { place: channel.parent_id, thread: channel.id };
713
721
  return { place: channelId };
@@ -751,11 +759,11 @@ export class DiscordChannel {
751
759
  return { address: this.person(id) };
752
760
  }
753
761
  }
754
- async #channel(id) {
762
+ async #channel(id, rest = this.#rest) {
755
763
  const cached = this.#channels.get(id);
756
764
  if (cached && Date.now() - cached.at < CACHE_TTL_MS)
757
765
  return cached.channel;
758
- return this.#remember((await this.#rest.get(`/channels/${id}`)));
766
+ return this.#remember((await rest.get(`/channels/${id}`)));
759
767
  }
760
768
  #remember(channel) {
761
769
  this.#channels.set(channel.id, { channel, at: Date.now() });
@@ -915,6 +923,7 @@ export class DiscordChannel {
915
923
  if (refused)
916
924
  throw new Error(refused);
917
925
  const target = await this.#target(to);
926
+ await this.#sink?.sending(this.place(target.place));
918
927
  const message = (await this.#rest.post(`/channels/${target.thread ?? target.place}/messages`, {
919
928
  body: {
920
929
  content,
@@ -926,6 +935,31 @@ export class DiscordChannel {
926
935
  const raw = { source: "sent", sendId, message, ...(target.thread ? { parent: target.place } : {}) };
927
936
  return { message: this.#messageAt(target, message.id), place: this.place(target.place), raw };
928
937
  }
938
+ /**
939
+ * Discord's "<bot> is typing…" line, in the channel or thread of `at`. It lasts 10 seconds; Discord has no call to
940
+ * stop it, so it fades. Not tried again: a rate limit fails at once, and never makes a send wait.
941
+ */
942
+ working = { every: 8_000, show: (at, signal) => explained(this.#typing(at, signal)) };
943
+ /** Where typing shows for an address, found once: finding a message's thread is a request. */
944
+ #typingIn = new Map();
945
+ async #typing(at, signal) {
946
+ const rest = this.#typingRest;
947
+ if (!rest)
948
+ throw new Error(`channel ${this.id} is not started`);
949
+ let channel = this.#typingIn.get(at);
950
+ if (!channel) {
951
+ // Also its lookups are tried once, and never wait in the queue of the client that sends.
952
+ const target = await this.#target(at, rest);
953
+ channel = target.thread ?? target.place;
954
+ if (this.#typingIn.size >= 100)
955
+ this.#typingIn.delete(this.#typingIn.keys().next().value);
956
+ this.#typingIn.set(at, channel);
957
+ // The bot sent there while it looked: typing now would show under the message.
958
+ if (signal?.aborted)
959
+ return;
960
+ }
961
+ await rest.post(`/channels/${channel}/typing`);
962
+ }
929
963
  /** Discord's API does not give nonces back when it lists messages, so a sent message cannot be found by its send ID. */
930
964
  async findSent(_to, _sendId, _since) {
931
965
  return undefined;
@@ -935,32 +969,32 @@ export class DiscordChannel {
935
969
  * or in its thread. A thread's first message (the thread's address): post in the thread, as a reply only when that
936
970
  * message is in the thread (a forum post); a message that has no thread gets a reply in its channel.
937
971
  */
938
- async #target(to) {
972
+ async #target(to, rest = this.#rest) {
939
973
  const parsed = this.#parse(to);
940
974
  if ("user" in parsed) {
941
975
  let dm = this.#dms.get(parsed.user);
942
976
  if (!dm) {
943
- dm = this.#remember((await this.#rest.post("/users/@me/channels", { body: { recipient_id: parsed.user } }))).id;
977
+ dm = this.#remember((await rest.post("/users/@me/channels", { body: { recipient_id: parsed.user } }))).id;
944
978
  this.#dms.set(parsed.user, dm);
945
979
  }
946
980
  return { place: dm };
947
981
  }
948
982
  if (!parsed.message)
949
- return this.#locate(parsed.channel);
983
+ return this.#locate(parsed.channel, undefined, undefined, rest);
950
984
  if (parsed.thread)
951
985
  return { place: parsed.channel, thread: parsed.thread, reply: parsed.message };
952
- const channel = await this.#channel(parsed.channel);
986
+ const channel = await this.#channel(parsed.channel, rest);
953
987
  if (channel.type === DM || channel.type === GROUP_DM)
954
988
  return { place: parsed.channel, reply: parsed.message };
955
- const thread = await this.#threadOf(parsed.message);
989
+ const thread = await this.#threadOf(parsed.message, rest);
956
990
  if (thread?.parent_id === parsed.channel)
957
991
  return { place: parsed.channel, thread: thread.id, ...(FORUMS.has(channel.type) ? { reply: thread.id } : {}) };
958
992
  return { place: parsed.channel, reply: parsed.message };
959
993
  }
960
994
  /** The thread with this ID, if there is one the bot can see. */
961
- async #threadOf(id) {
995
+ async #threadOf(id, rest = this.#rest) {
962
996
  try {
963
- const channel = await this.#channel(id);
997
+ const channel = await this.#channel(id, rest);
964
998
  return THREADS.has(channel.type) ? channel : undefined;
965
999
  }
966
1000
  catch (error) {
@@ -1023,6 +1057,10 @@ export class DiscordChannel {
1023
1057
  }
1024
1058
  else {
1025
1059
  const files = typeof file === "string" ? [{ name: basename(file), data: await readFile(expandHome(file)) }] : undefined;
1060
+ // A message the bot posts: the typing there stops first.
1061
+ const posted = verb === "POST" ? /^\/channels\/(\d+)\/messages$/.exec(request.fullRoute)?.[1] : undefined;
1062
+ if (posted)
1063
+ await this.#sink?.sending(this.place((await this.#locate(posted).catch(() => ({ place: posted }))).place));
1026
1064
  result = await this.#rest.request({ ...request, body, ...(files ? { files } : {}) });
1027
1065
  }
1028
1066
  // An answer with no content (204).
@@ -1062,6 +1100,11 @@ function discordError(error) {
1062
1100
  return new Error(`Discord answered ${error.status}, code ${error.code}: ${error.message}`, { cause: error });
1063
1101
  if (error instanceof HTTPError)
1064
1102
  return new Error(`Discord answered ${error.status} ${error.message}`, { cause: error });
1103
+ // A request that a REST client with rejectOnRateLimit did not wait for. Its message is empty.
1104
+ if (error instanceof Error && error.name.startsWith("RateLimitError")) {
1105
+ const { retryAfter, route } = error;
1106
+ return new Error(`Discord rate limited ${route ?? "the request"}; retry after ${retryAfter ?? "?"} ms`, { cause: error });
1107
+ }
1065
1108
  return error instanceof Error ? error : new Error(String(error));
1066
1109
  }
1067
1110
  /** The work's result, or its failure with what Discord answered. */