Skip to content

Inbox: your rules in each agent's own instructions file - #3598

Merged
backnotprop merged 15 commits into
mainfrom
feat/inbox-note-rules
Nov 28, 2026
Merged

backnotprop merged 15 commits into
mainfrom
feat/inbox-note-rules

Conversation

@backnotprop

@backnotprop backnotprop commented Nov 17, 2026 •

Copy link
Copy Markdown
Owner

Your rules from Settings → Prompts → "Rules for your agents" now also go into the Plannotator note in each agent's own instructions file (~/.codex/AGENTS.md, ~/.gemini/GEMINI.md, Claude Code's rules/plannotator-inbox.md and the others), only between Plannotator's own two marker lines. Claude Code, Pi and OpenCode get them once: their session reminder leaves them out while the note holds them. Codex, Gemini CLI and Qwen Code get them in their file and also, when they connect through MCP, in the MCP server's instructions, so twice there, never none.

This push (2026-11-28, fourth): main merged

  • Merged main at 9ecdd463c603 (0.29.7, with Inbox for code review only #4067 "the Inbox for code review only"), a plain merge: 8 conflicts, all resolved by hand. No word a person or agent reads changed, and no new Settings sentence; for the full Inbox the feature works as before.
  • Carried through Inbox for code review only #4067's one notes queue (inbox-review-only-notes.ts), main's structure kept:
    • While code review only, no write puts the person's rules in a file (noteRulesConfig reads main's inboxAgentWords): an add by hand, a refresh and the preview give today's block. The notes are out as main takes them out.
    • A note with the rules counts as Plannotator's own when the mode takes it out (isOwnNoteBlock with the file: the record that names it), so it is never saved as the person's edit, and it goes back with the rules set by then, as the plain note does.
    • A section the person edited in a note with the rules is saved, taken out and put back exactly as they left it, and recorded as their edit, so no refresh writes over it.
    • A save of the rules runs its refresh in the queue (refresh), never beside another writer.
  • Fixed in the merge: both sides had changed the block helpers' arguments; the refresh would have written the new block in LF inside a CRLF file. A new CRLF test guards it.
  • Tests: new packages/server/inbox-review-only-note-rules.test.ts (5 tests, scratch home and data dir, no Inbox), each checked red then green.

This push (2026-11-28, third): the independent review's three changes

An independent review read the whole PR and asked for three changes before merge. The rule behind each one is the PR's own: twice is better than never.

  • M1. The note never takes more than Settings saves, or a file past 1 MiB (packages/server/inbox-agent-notes.ts).

    • noteSafe leaves rules longer than INBOX_REMINDER_MAX_CHARS (9,000 characters) out of the note, the same way as rules that hold a marker. Only a hand-edited config.json has such rules. The note is then today's block. The holds check finds no rules in it, so no host leaves them out of its reminder because of the note.
    • A note is never written where it would take the file past AGENT_FILE_MAX_BYTES (1 MiB). Past that size readAgentFile refuses the file for good, and switching the note off, a refresh or uninstall could not take the note out again. The note goes in without the rules in that case. Where even that does not fit, nothing is written: the add gives the existing "can't be edited: it is larger than 1 MiB", and the refresh gives refused. The records follow the block that is really written.
  • M2. A T3 Code thread keeps the rules in its reminder (apps/hook/hooks/mod/inbox-note-rules.ts, claudeSessionNoteFile). The mod leaves the rules out of the reminder only in a session that is proven to load rules/plannotator-inbox.md: Claude Code's own prompt, or its VS Code panel (claude-vscode). A T3 thread runs Claude through the Agent SDK, which is not proven to load that file. A T3 thread, Orca's panel and any other host keep the rules in the reminder: twice there, never none.

  • M3. The MCP skip is gone. The MCP instructions always carry the rules again, as on main. The push before this one left them out for Codex and Gemini CLI when the note in the Inbox's environment held them. That could give zero, because the Inbox cannot tell which file a connecting agent reads:

    • Codex starts its MCP server with a cleared environment, so its CODEX_HOME never reaches the shim. An Inbox that the shim started has no CODEX_HOME either.
    • inbox/agents.json records only the file that the MCP entry is in, as the Inbox found it. It does not tie a connecting process to a home.
    • Gemini CLI's file also follows a project's context.fileName.

    There is no clean way for the shim to report which file its agent reads, so the skip was removed, not guarded. The /mcp route is main's line again, byte for byte, and inbox-mcp-note-rules.ts is removed.

  • Tests:

    • New cases in inbox-agent-note-rules.test.ts: rules of 9,001 characters; a file near 1 MiB (add, refresh, removal byte for byte); a grown file with a note that has rules; a file that even today's block would push past 1 MiB.
    • The MCP matrix: Codex and Gemini CLI whose note holds the rules still get them in the instructions. An agent run with another CODEX_HOME or GEMINI_CLI_HOME than the Inbox's gets them in the instructions.
    • The mod: a T3 thread, Orca and an SDK host keep the rules; the terminal and the VS Code panel do not.

    Red and green were checked for each new test. Without the writer change, the 4 size tests fail. With the old MCP skip put back, the 2 "note holds" cases and the 2 other-home cases fail. With the mod's session check ignored, the T3 test fails. The /mcp route test in inbox-prompts.test.ts now expects Codex and Gemini CLI to get the rules. That file starts an Inbox, so it runs in CI only.

  • No word that a person or agent reads has changed. The note, its lead, the rules, the MCP instructions, the Settings lines and the CLI lines are byte for byte the same. Only developer docs were corrected (inbox-foundation.md, environment.md).

Earlier push (2026-11-28, second), now withdrawn in part

That push left the rules out of the MCP instructions for Codex and Gemini CLI when the note held them. The review found that this could give zero (see M3 above), so this push removes it.

Earlier push (2026-11-28)

The PR was held on 19 Nov until the Inbox had an opt-in gate (#3729). That gate is on main now, so that push brought the PR up to date and put its new behavior behind the gate.

  • Merged main at 52e35600480d (a plain merge, no rebase): merge commit e8246d14fa7b. Main had not changed the note writer (inbox-agent-notes.ts), so the note's bytes and every word that this PR adds stayed the same. There were 6 conflicts, all of them additions on both sides:
    • the connection contract and its copy in the mod;
    • the imports in inbox-command.ts;
    • Pi's setupPiInbox (main's isInboxTurnedOn gate is kept, and the rules-aware reminder follows it);
    • two doc lines.
  • The gate (e283b499cd04): a note carries the person's rules only after the person has turned the Inbox on (noteRulesConfig in inbox-agent-notes.ts). Before that, three things give today's block byte for byte: a note written with plannotator inbox --notes (main runs this before the gate), a refresh, and the window's preview. Cursor's copy has no rules either. A new test runs the add, the refresh and the preview with no turned-on mark, then turns the Inbox on, and the rules then appear once. With the gate removed, the test fails.
  • Not run locally: Pi's tests and typecheck (they need the vendored generated/ folder), and the two suites that start an Inbox (inbox-prompts.test.ts, inbox-agent-notes-refresh.test.ts). CI runs them.

For #3555

What a person notices

  • Rules that you write in Settings → Prompts → "Rules for your agents" now also go into the Plannotator note that the Inbox writes in each agent's instructions file. Codex and Gemini CLI now read them in their own instructions file. Before this change they got the rules only through the MCP server's instructions (fix(inbox): send the person's Inbox rules and reminder to MCP sessions #3567), and only while connected through MCP.
  • Claude Code (in its own prompt and VS Code panel), Pi and OpenCode leave the rules out of their session reminder when their note file already holds them, so they get the rules once. A T3 Code thread keeps them in its reminder too. Agents connected through MCP get them in the MCP instructions as before, and also in their note.
  • When you change or clear the rules, every note that Plannotator wrote is rewritten at once. With no rules, the note is exactly what it is today.
  • Under the rules box, Settings now says which agents found on this computer will not get the rules, and why:
    • there is no note in their instructions (for Claude Code, Pi and OpenCode, only when their reminder is off too);
    • you edited their note, so Plannotator leaves it alone;
    • Plannotator could not update the note's file.
  • Cursor's copy, both in the window and from plannotator inbox --notes cursor, includes the rules.

What changed

  • The note block (packages/server/inbox-agent-notes.ts). With rules set, the v9 body is followed by a blank line, the reminder's existing INBOX_RULES_LEAD, and the rules, all inside the same markers. No fixed line is new or reworded, and the version is still v9.
    • Claude Code, Pi and OpenCode use their own rules when they are set. The other agents use the shared ones.
    • A file that two agents share holds their common rules, or the shared rules when theirs differ.
    • Some rules stay out of the note, and the reminder and the MCP instructions carry them where they fit: rules that hold <!-- plannotator-inbox: or a Gemini/Qwen memory header anywhere (not only at a line start), and rules longer than 9,000 characters.
    • A note is never written where it would take the file past 1 MiB.
  • Ownership. A block with other rules counts as Plannotator's only through its record, and only while its start line is this version. So a block that a newer version wrote is never rewritten.
    • With the record lost, the block that this Inbox would write now also counts as Plannotator's.
    • Records keep the block they named before (prior_sha256), so a crash between the record write and the note write still repairs itself.
    • All the existing guarantees hold:
      • writes go only inside the markers;
      • read-only, hard-linked and hand-pasted files are left alone;
      • writes compare first and are atomic;
      • removal and uninstall give the file back byte for byte;
      • a note that was turned off or removed is never written;
      • an edited note is never rewritten.
  • Refresh on save. The settings route runs refreshInboxNotes after any rules change, as the Inbox start already does. A refresh that fails cannot fail the save.
  • An unreadable config.json (loadConfigOrNull): the start refresh writes nothing, and an add is refused. A failed read therefore never rewrites notes as if there were no rules.
  • Once. The new contract helper inboxNoteHoldsRules is copied into the mod, as the other contract helpers are.
    • The Claude Code mod reads rules/plannotator-inbox.md at session start, again at a conversation's first prompt, and at each compaction, when Claude Code reads its memory files again. The compact hook's value follows. The mod does this only in Claude Code's own prompt and its VS Code panel (M2).
    • Pi decides once per extension instance, because Pi reads its instructions file once per session.
    • OpenCode decides per request (inboxReminderRulesWatch: one stat, and it reads the file again only when its size, mtime or inode changed).
    • At each of those moments the rules are config.json's as they are then (OpenCode: inboxConfigWatch, one stat, read again only when the file changed; the mod: currentRules). A save rewrites the note, so a comparison with the rules from the session's start would send the old rules again. A read that fails keeps the last rules.
    • MCP: the instructions always carry the rules (M3).
    • The reminder's own text is unchanged.
  • Settings. prompts.rules.unsent lists the agents that miss the rules. note_texts holds per-agent previews (a file that two agents share previews the block it would really get). AgentRules.tsx shows the "Not sent to …" lines. A line never says something false:
    • There is no line for Cursor (a fresh copy cannot be seen), or for an agent the person said no to. inboxAgentNotes.asked also records the files that the automatic add skipped on purpose. The file itself tells those apart (read-only, hard-linked, pasted without markers), and they are still named.
    • Rules that the note cannot carry are named, with no fix.
    • The "Turn it on" or "Turn the note off and on" advice shows only where Settings → Agents can do it (not with PLANNOTATOR_INBOX_NOTES=0, and not for OpenCode with no AGENTS.md).
    • An error while this is worked out shows no line, and Settings still loads.
  • Docs.
    • inbox-foundation.md gets a new bullet.
    • inbox-window.md describes the "Not sent to …" lines.
    • environment.md names Qwen Code with Codex and Gemini CLI.
    • In server-and-storage.md, the settings row and the /api/inbox/agents row (note_texts) are updated.

Who gets the rules how many times (after this push)

Agent Note holds the rules Note does not hold them
Claude Code, its own prompt or VS Code panel once (note) once (reminder)
Claude Code in a T3 thread, Orca's panel twice if that host loads the note, else once (reminder) once (reminder)
Pi, OpenCode once (note) once (reminder)
Codex, Gemini CLI, Qwen Code, through MCP twice (note and MCP instructions) once (MCP instructions), with another CODEX_HOME / GEMINI_CLI_HOME too
Codex, Gemini CLI, not through MCP once (note) none, as on main (they have no reminder)
Cursor its copy by hand, plus the MCP instructions when connected the MCP instructions when connected
A paired cloud agent's door none, as on main (it never answers initialize) none, as on main

Rules over 9,000 characters (only a hand-edited config.json) fit no channel, as on main: the reminder and the MCP instructions leave text that does not fit out whole, and the note now leaves them out too.

Known limits (documented, no code)

  • Twice where the note holds the rules: Codex, Gemini CLI and Qwen Code through MCP, and Claude in a T3 thread or Orca where that host loads the note. Each copy comes under the same lead. Once would need the agent to say which file it reads, and Codex does not pass that to its MCP server.
  • Cursor's copy is made by hand. Plannotator cannot see it, update it or remove it, and it keeps old rules until it is copied again.
  • A paired cloud agent's door gets no rules, as on main.
  • An edited, read-only or hard-linked note keeps the rules it had, while the reminder carries the new ones. Claude Code, Pi and OpenCode then see both. The later ones come under the same lead ("where they differ from the lines above, follow these").
  • Rules that are cleared while a note cannot be rewritten (read-only, hard-linked, edited, PLANNOTATOR_INBOX_NOTES=0, an unreadable config.json) stay in that agent's file. Settings says nothing about it.
  • Rules with an unclosed <!--, an open code fence, a NUL or a lone surrogate go into the note as they are written. Only the marker strings and the memory headers are kept out.
  • Rules that are typed in Settings now land in the agents' own files (~/.codex/AGENTS.md and the others). Those files are often in a dotfiles repository and are written through symlinks.
  • Pi that reads Codex's AGENTS.md and has rules of its own: the note holds the shared rules, and Pi's reminder carries Pi's own.
  • A session connected through MCP keeps what it got at initialize. A rules change reaches it at its next session.
  • Stacked work: Inbox reminder for Qwen Code, Gemini CLI, Amp, Kiro and Codex through their own hooks #3600 adds hook reminders for Codex, Gemini CLI and others, so it must take the holds check (inboxNoteHoldsRules), or those agents read the rules a third time.
  • Stacked work: inbox: the note for every agent whose docs verify a global rules file #3599 adds note agents. Through MCP they get the rules in the instructions too (twice where their note holds them, never none), because the Inbox has no client map any more.

Linked machines: rules live in each machine's own config, and nothing crosses machines.

How it was tested

packages/server/inbox-agent-note-rules.test.ts (59 tests, no Inbox started) covers:

  • the block for each agent and each setting, including today's block byte for byte when there are no rules;
  • removal and uninstall with rules present;
  • a rules change that rewrites untouched notes, and the records that follow them;
  • a note that is turned off, edited, read-only, hard-linked, or pasted without markers;
  • v8 upgrading to v9 with rules;
  • a record left ahead of its note, and a newer version's block;
  • a file shared by Pi and Codex;
  • rules longer than 9,000 characters, and files near 1 MiB;
  • the exactly-once matrix for Claude Code, Pi and OpenCode;
  • the MCP matrix for Codex and Gemini CLI: the note holds the rules, no note, the note turned off, older rules, rules edited out, another CODEX_HOME / GEMINI_CLI_HOME, and every client;
  • the hosts reading the same file that the Inbox writes;
  • what Settings reports, including the cases that show no line and a throw;
  • markers in the rules after U+2028, U+2029, a CR, and mid-line;
  • an unreadable config.json at start and on add;
  • today's block pinned by a literal hash;
  • per-agent previews for a shared file.

Other tests:

  • inbox-prompts.test.ts starts an Inbox, so it runs in CI. Its route tests check four things:
    • saving rules rewrites the note, Back to default restores today's block, and saving the reminder text leaves the note alone;
    • a refresh that fails (a locked folder) cannot fail the save;
    • over /mcp, Codex and Gemini CLI get the rules even while the note holds them;
    • the next connection after a save gets the new rules.
  • A DOM test in promptsSettings.test.tsx for the "Not sent to …" lines. It checks which agents are named, the reason and whether a fix is offered, not the wording.
  • Wiring tests:
    • apps/hook/hooks/mod/inbox-note-rules.test.ts: the path, a failed read, the compact hook's value, and a T3 thread against Claude Code's own prompt;
    • apps/pi-extension/inbox-note-rules.test.ts;
    • apps/opencode-plugin/inbox-note-rules.test.ts, including a note that changes between requests.
  • These pass locally on this push: note rules (59), notes (42), the MCP instructions (47), the turned-on gate (8), the mod's note rules (7), the mod's contract (1), the mod's $.env.get literals (4), OpenCode's note rules (4), the Inbox structure check (5), and the docs size check (3).
  • Typecheck is clean for server, shared and the mod. The hook server's config reports one error in inbox-agent-icon-still.ts, which this PR does not touch and which is the same file as on main.

Clean-room test of the agent-facing text, with a fresh agent and only a Codex-style AGENTS.md in a scratch folder:

  • With the made-up rule "ask me before you delete any file", the agent deleted nothing and asked first.
  • The control, with today's note, deleted the build output, the log and the stale file.

The note block now carries the person's Rules for your agents after its own
lines, under the reminder's existing lead, inside the same v9 markers. With
no rules the block is byte for byte today's. Saving rules in Settings
rewrites every untouched note (refreshInboxNotes, same guarantees). The
Claude Code, Pi and OpenCode reminders leave the rules out when the agent's
own note file holds them. Settings names every agent the rules do not reach.

For #3555
- Rules holding the marker prefix or a memory header anywhere stay out
  of the note (a U+2028/U+2029/CR line start no longer slips a second
  end marker in).
- An unreadable config.json writes no note at start and refuses an add,
  instead of reading as "no rules".
- Settings' "Not sent to" lines: a throw shows none; no line for
  Cursor, a declined agent or rules the note cannot carry; the fix only
  where Settings -> Agents can do it.
- OpenCode decides per request (cached stat); the mod reads its rules
  file again at the first prompt and at compaction.
- Per-agent note previews follow the shared-file rule.
- Tests for the mod, Pi and OpenCode wiring and the save path; docs.
- OpenCode reads config.json's rules again when the file changed (one
  stat per request) and the Claude Code mod at each first prompt and
  compaction, so a saved R2 the Inbox wrote into the note is never
  followed by R1 in the reminder.
- Settings stays silent only for the person's own no: a file the
  automatic add left alone on purpose (read-only, hard-linked, pasted
  without markers) and rules the note cannot carry are named, with no
  fix where nothing can be turned on.
- environment.md: OpenCode 2's bytes change with the rules and the note.
# Conflicts:
#	apps/hook/server/inbox-command.ts
#	docs/agent-guides/server-and-storage.md
…eview points

- The Pi extension decides "the note holds the rules" per host: only Pi's own
  note counts for Pi. Oh My Pi reads its own agent folder, where the Inbox
  writes no note, so its reminder always carries the rules, and each session
  it switches to gets a reminder decided then (piReminderFollower).
- Settings → Prompts: "Turn them on" when the line names several agents.
- The first-run note dialog previews what each agent really gets: its own
  rules where it has them, one block per distinct note, named when they differ.
- The doc comment of inboxNoteHoldsAgentRules sits on its function again.
Takes in #3567 (the person's rules and reminder in the MCP server's
instructions). Settings → Prompts keeps both kinds of line true: an agent
connected through MCP (inbox/agents.json) gets no "Not sent to …: no note"
line while the MCP instructions carry the shared rules; the MCP room lines
are unchanged. The docs say where the rules now reach Codex, Gemini CLI and
Qwen Code twice (note and MCP instructions) as a known limit.
The note's rules now come from config.json only once the Inbox's turned-on
mark says on (noteRulesConfig). Before that, a note added with
plannotator inbox --notes, a refresh and the window's preview are today's
block byte for byte, and Cursor's copy carries no rules. A test runs the
add, the refresh and the preview with the mark absent, then turns it on.
@backnotprop backnotprop added the ci:e2e Run the full browser suite (Inbox window e2e) on this PR label Nov 28, 2026
An initialize on this computer's /mcp leaves the rules out of the MCP
instructions when the client is Codex (codex-mcp-client) or Gemini CLI
(gemini-cli-mcp-client), the Inbox is turned on, and that agent's note
holds exactly those rules (the check the reminders make). Any other
client, note state or connection gets them as before.
…r MCP

The note leaves out rules longer than INBOX_REMINDER_MAX_CHARS, as it
already does for rules with a marker, and is never written where it would
take the file past 1 MiB (without the rules then, else not at all), so the
Inbox can always take it out again.

The Claude Code mod leaves the rules out of its reminder only in a session
proven to load its rules file (Claude Code's own prompt and VS Code panel);
a T3 Code thread, Orca or another host keeps them.

The MCP instructions carry the rules for every client again, as on main:
the Inbox cannot tell which file a connecting agent reads (Codex clears its
MCP server's environment, so CODEX_HOME never reaches the shim), and leaving
them out gave an agent with another home none at all.
# Conflicts:
#	apps/hook/hooks/mod/enabled.ts
#	apps/hook/hooks/mod/register.ts
#	apps/pi-extension/inbox.ts
#	docs/agent-guides/server-and-storage.md
#	packages/inbox/components/AgentsSettings.tsx
#	packages/server/inbox-agent-notes.ts
#	packages/server/inbox.ts
#	packages/shared/config.ts
@backnotprop backnotprop changed the title Inbox: the person's rules in each agent's note, delivered once Inbox: your rules in each agent's own instructions file Nov 28, 2026
Oh My Pi's Inbox tool default (resolvePiInboxTool) now also decides the Pi reminder with the person's rules.
@backnotprop
backnotprop merged commit f322bb9 into main Nov 28, 2026
59 checks passed
DuongCoder04 pushed a commit to DuongCoder04/plannotator that referenced this pull request Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:e2e Run the full browser suite (Inbox window e2e) on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant