Plan: the modes reference split into nine pages by feature

Closes: #903. Relates to: #884 (the audit that ruled it). Branch: docs/split-modes-page. Status: Done (2026-11-23) — as planned, with the erratum below

Erratum (2026-11-23): a backtick span is not a passthrough in AsciiDoc, so an xref: or <<...>> inside one is a link. The check reads code spans, blanks passthroughs (+ spans, , an escaped macro) instead, and recognises a reference as Asciidoctor does. Two backticked examples in plan pages rendered as broken links (plans/review-context.adoc, plans/remote-6-release.adoc) and are written as passthroughs, as are this plan’s own.

Context

docs/modules/ROOT/pages/modes.adoc is one page of 4,999 lines (286,512 bytes), of about 12,800 across the docs. The operator ruled (2026-11-22): split it by feature; anchors that other pages and the CHANGELOG link to must keep resolving. On 2026-11-23 he approved the nine pages tabled below.

Measured on main 8e8ca3b66 (line numbers below are that commit’s):

  • The docs hold 122 pages and 438 xref: links outside listings and code spans: 345 to a page, 87 to a page and an anchor, 6 in other forms (xref:pi::x.adoc[, xref:ROOT:x.adoc[, xref:#id[); and 51 in-page <<...>> references, 49 by id and 2 by a section’s title (<<Context Hygiene>>, in the standards module).

  • 36 links from seven pages name an anchor of modes.adoc (22 distinct anchors); 34 of them name one that moves. No plan page and no CHANGELOG entry links to an anchor of it.

  • 69 links name modes.adoc alone: 53 in public-surface.adoc (52 table rows and one sentence), 16 elsewhere.

  • Of the page’s own 39 <<id>> references, 25 cross one of the new page boundaries.

  • Loading every page with the site build’s own Asciidoctor (2.2.9, reached through @antora/site-generator → @antora/asciidoc-loader → @asciidoctor/core, each a declared dependency of the one before; the root package.json declares the first) takes 540 ms and yields the ids the links are checked against; every one of the 22 anchors is among them.

  • Two links are broken today, in plan pages, each naming a sibling plan without its directory: plans/remote-rpc-state.adoc:9 (xref:remote-rpc-control.adoc[]) and plans/review-pane.adoc:169 (xref:close-review-pane.adoc[the acceptance plan]). Antora reads a link’s path from the module’s pages/ directory. Nothing checks links: the pages job in .gitlab-ci.yml runs npx antora antora-playbook.yml, which logs an unresolved link and exits 0.

Design

The nine pages

The file is cut at thirteen lines, each of which occurs once in it and follows a blank line. A segment runs from its first line to the line before the next cut.

Segment starts at Line Goes to

the file’s first line

1

modes.adoc

[#judge]

551

judge.adoc

[#workflow-guards]

1475

workflow-guards.adoc

[#reflection-pause]

2134

commit-review.adoc

[#interaction-tools]

2690

plan-mode.adoc

[#yield]

3187

helpers.adoc

[#generate-image]

3297

tools.adoc

[#model-roles]

3884

modes.adoc

[#delegation-gate]

3931

helpers.adoc

[#scratch-root]

4055

modes.adoc

[#helper-worktree]

4100

helpers.adoc

== Guidance injection

4157

session.adoc

[#observability]

4750

diagnostics.adoc

[#first-run-bootstrap]

4944

modes.adoc

Segments keep their order within a page. Sizes: modes.adoc about 715 lines, judge.adoc 924, workflow-guards.adoc 659, commit-review.adoc 556, plan-mode.adoc 497, helpers.adoc 291, tools.adoc 587, session.adoc 593, diagnostics.adoc 194.

Why three segments stay in modes.adoc: "Model roles" is configuration (it sits under Jobs today by accident of history); "Scratch root" because packages/pi-modes/scratch-root.ts writes see modes.adoc § Scratch root (#738) into a repository’s .git/info/exclude; and the two summary tables in segment one because tools/lib/test/public-surface.test.mjs ("the modes overlay’s keys are modes.adoc’s two summary tables") reads them from that file.

Heading levels: in the [#reflection-pause] segment every heading loses one = (=== The reflection pause becomes ==, its fifteen ==== become ===); in the [#model-roles] and [#scratch-root] segments the one === heading becomes ==. No other heading changes. Explicit anchors move with their lines. Asciidoctor’s automatic ids come from the title, not the level, so they are unchanged, with one exception: Pins occurs twice today (_pins, _pins_2) and once on each of two pages afterwards (_pins on both); nothing links to either.

Each new page begins with these lines, then its segments:

// SPDX-License-Identifier: AGPL-3.0-or-later
= <title>
:description: <description>

Part of the xref:modes.adoc[Workflow Modes] reference.
Page Title Description

judge.adoc

The judge, the pending queue and the safety valve

What happens to a tool call no rule decides: the safety-only judge, the steps that wait on you, the hub, and the valve that stops a runaway session.

workflow-guards.adoc

Workflow guards

The deterministic guards on every tool call, whatever the mode, and how they read a command line.

commit-review.adoc

The commit review

Every commit is reviewed once before it lands, by a model that did not write it: what it reads, the questions, who reviews, retries and answers.

plan-mode.adoc

Asking the human: ask and plan mode

The tools that put a question or a plan in front of you, and what they do with no terminal or with a paired phone.

helpers.adoc

Helpers: results, the delegation gate and worktrees

How a subagent returns a checked result, which helpers a session may spawn, and a helper in its own git worktree.

tools.adoc

Tools: images, counting, monitors and jobs

The tools for work beyond one command: generate_image, count, the monitor that wakes the agent, and jobs that outlive the session.

session.adoc

The session: guidance, compaction and the terminal

What pi-modes does around a session: injected guidance, compaction, switching models, dropped files, the turn recap, the working line, the tab title, stray mouse and Escape input.

diagnostics.adoc

Observability and diagnostics

What a session shows and records about its own decisions: the status line and bus channels, the diagnostics stream, OpenTelemetry export, review-log events.

modes.adoc keeps its title. Its :description: becomes Modes, who decides what, the configuration files and their keys, and model roles; the rest of the reference is one page a feature. After its line 14 (the blank line that follows JSON.) this is inserted, with a blank line after it:

The reference is split by feature:

* xref:judge.adoc[The judge, the pending queue and the safety valve] -- what happens to a call no rule decides.
* xref:workflow-guards.adoc[Workflow guards] -- the deterministic checks on every tool call.
* xref:commit-review.adoc[The commit review] -- the cold read every commit gets.
* xref:plan-mode.adoc[Asking the human: ask and plan mode] -- `ask`, plan mode and its approval.
* xref:helpers.adoc[Helpers] -- checked results, the delegation gate, worktrees.
* xref:tools.adoc[Tools] -- images, counting, monitors, jobs.
* xref:session.adoc[The session] -- guidance, compaction, the terminal.
* xref:diagnostics.adoc[Observability and diagnostics] -- what a session shows and records.

docs/modules/ROOT/nav.adoc gains the same eight, in that order and with those link texts, as * entries directly under ** xref:modes.adoc[Workflow Modes].

What is rewritten in the moved text

Nothing but these:

  • The 25 <<id>> references whose target is on another page become xref:<page>.adoc#<id>[<text>]. <text> is the reference’s own text when it has one (<<safety-valve,valve list>>), else the target heading’s title as written, shortened at its first colon or parenthesis (<<monitor>> gives The monitor; <<judge>> gives The judge). <<registry-facts>> (line 230) names a paragraph, not a heading: its text is the registry check. A reference whose target is on its own page is untouched.

  • Line 3465, the page’s one link to itself: xref:modes.adoc#windows-shell[#652] becomes xref:workflow-guards.adoc#windows-shell[#652].

  • Line 1219: (§ Observability) becomes (xref:diagnostics.adoc#observability[Observability]).

  • Line 1281: (`gadhs-hub:ask, below)` becomes (`gadhs-hub:ask, xref:diagnostics.adoc#observability[Observability])`. The 56 lines that say above, below or this page were each read against the cuts; this is the one whose referent lands on another page.

  • Lines 1480-1481: They are documented here because this page is where the enforcement story reads as one piece; becomes They are documented beside xref:modes.adoc[the modes] because the enforcement story reads as one piece;.

  • With an anchor (34 of 36): xref:modes.adoc#<id>[ becomes xref:<page>.adoc#<id>[ by this table; model-roles and scratch-root stay. To judge.adoc: hub, pending-queue, registry-facts, safety-valve. To workflow-guards.adoc: windows-shell. To plan-mode.adoc: ask-broker, headless-hosts. To tools.adoc: generate-image, monitor, remote-jobs, shell-timeout. To session.adoc: drop-to-attach, recap, title, working-line, _switching_to_a_model_the_context_does_not_fit, _time_on_the_issue, _when_the_provider_refuses_the_request. To diagnostics.adoc: diagnostics, observability.

  • public-surface.adoc’s 52 rows each link the page that documents the row’s item, with the page’s short name as text (xref:judge.adoc[judge], `xref:diagnostics.adoc[diagnostics], xref:plan-mode.adoc[plan mode], xref:tools.adoc[tools], xref:helpers.adoc[helpers], xref:session.adoc[session], xref:workflow-guards.adoc[workflow guards]). Unchanged, 9: gadhs-pi-modes.json, gadhs-memory.json, /mode, /gadhs-reset, /remember, /memory, remember, forget, GADHS_PI_MODES_CONFIG. Judge, 3: /hub, /pending, pending_withdraw. Diagnostics, 20: /diag, GADHS_PI_DIAGNOSTICS, the nine OTEL_*, TERM, the eight bus channels (gadhs:*, gadhs-hub:*, gadhs-msg:*). Plan mode, 3: ask, enter_plan_mode, exit_plan_mode. Tools, 11: count, generate_image, monitor, monitor_stop, monitor_list, monitor_restore, job, job_stop, job_list, PYTHON_BASIC_REPL, WSLENV. Helpers, 1: yield. Session, 2: /gadhs-init, GADHS_PI_TUI_PATCH. Workflow guards, 3: GITLAB_TOKEN, GITLAB_ACCESS_TOKEN, GLAB_CONFIG_DIR. The sentence at its line 50, about the two summary tables, is unchanged. tools/lib/public-surface.mjs reads each row’s first cell and not this one.

  • The other page-level links, by what the sentence is about: remote.adoc:480 to xref:workflow-guards.adoc[secret redaction]; :583 to xref:judge.adoc#hub[the hub]; :696 to xref:diagnostics.adoc[]; :802 to xref:session.adoc[]; :824 to xref:judge.adoc[]; ssh.adoc:213 to xref:helpers.adoc#helper-worktree[Helpers]; shell-guard.adoc:75 to xref:workflow-guards.adoc#windows-shell[workflow guards]; tuning.adoc:1016 and :1088 to xref:commit-review.adoc[]; :1033 to xref:plan-mode.adoc[]; :1052 to xref:workflow-guards.adoc[]. Unchanged, because their subject stays: ssh.adoc:251 (workspaceWrites), packages.adoc:49, index.adoc:54 and :96, the nav’s own entry.

  • Outside the docs: packages/pi-modes/README.md:68 becomes docs/modules/ROOT/pages/modes.adoc and the pages it lists are the reference for everything here. ; the comment at packages/pi-modes/test/job-registry.test.ts:448 names tools.adoc (Jobs) for modes.adoc. The other mentions point at text that stays in modes.adoc (judge.ts, bootstrap.ts, config.ts, scratch-root.ts, modes.json) or are recorded data (tools/shell-spike/corpus.jsonl, plan fixtures in tests) and are not touched. The battery’s questions about this repository read a pinned commit (tools/model-battery/cases/explore/pi/pin.json), not this tree.

The check

New tools/lib/docs-links.mjs, run by tools/lib/test/docs-links.test.mjs in the tools/lib suite, which validate already runs (tools/task.mjs).

  • loadAsciidoctor() - the Asciidoctor the site build uses, by createRequire along the declared chain named in Context. When a step does not resolve it throws an Error naming that step.

  • linkableText(text: string): string - the text with every line between ---- or …​. fences, and every inline backtick span, blanked.

  • docsLinkProblems(root: string): string[] - one string a problem, <file>: <what>, in file order; empty when there are none. It reads, under root, every .adoc below docs/modules/<module>/pages/ and each docs/modules/<module>/nav.adoc, as files of that module, and CHANGELOG.adoc and README.adoc, as files of the ROOT module. With refs = loadAsciidoctor().load(text, { safe: "safe" }).getRefs(), a page’s ids are Object.keys(refs) and its section titles are each ref’s getTitle() where that is a string, tags removed.

    • In linkableText, each xref: up to its [ is read as: an optional <component>:: (the name: of docs/antora.yml; module ROOT) or <module>: (a directory of docs/modules), then <path>.adoc with an optional <id>, or <id> alone (the same page). The path is taken from that module’s pages/ directory. Problems: no page <module>:<path>; <path>#<id>: no such anchor.

    • Each <<target>> or <<target,text>> in a page (<<, then characters other than <, > and a line end, then >>), target being what precedes the first comma, trimmed: it resolves when it is one of the page’s ids or one of its section titles; otherwise <<target>>: no such anchor or section title on this page. Nothing of that shape is skipped as prose.

    • Anything else that begins xref: and is not read above (a path beginning ./ or ../, an attribute in the target), and a <<target>> whose target names a file (.adoc): a link form this check does not read: <raw>.

    • Each .adoc directly in docs/modules/ROOT/pages/ that docs/modules/ROOT/nav.adoc does not link: <page> is not in nav.adoc.

Scope

  • Docs: docs/modules/ROOT/pages/modes.adoc; new judge.adoc, workflow-guards.adoc, commit-review.adoc, plan-mode.adoc, helpers.adoc, tools.adoc, session.adoc, diagnostics.adoc beside it; docs/modules/ROOT/nav.adoc; public-surface.adoc, tuning.adoc, remote.adoc, ssh.adoc, vertex.adoc, architecture.adoc, security.adoc, shell-guard.adoc (links only); testing.adoc (one bullet under "Structural guards in the unit suite"); CHANGELOG.adoc; this plan as docs/modules/ROOT/pages/plans/split-modes-page.adoc with its nav entry.

  • Tools: new tools/lib/docs-links.mjs and tools/lib/test/docs-links.test.mjs.

  • packages/pi-modes/README.md (one sentence), packages/pi-modes/test/job-registry.test.ts (one comment).

  • Not touched: tools/lib/public-surface.mjs and its test, packages/pi-modes/scratch-root.ts, any plan page’s text, tools/model-battery, .gitlab-ci.yml.

  • Not in this plan: the two broken plan links (their own fix: issue, below); old anchors kept in modes.adoc as stubs for links from outside the repository; a new page for memory, which modes.adoc does not document today.

Risks

  • A link lands on a page without its anchor, or on no page - silent today (the site builds). Mitigation: the check in validate (T1), and the site build compared before and after (Delivery).

  • Text is lost or doubled in the move - silent. Mitigation: the line account (Delivery): every line of the old page is on one new page, bar the rewrites listed above.

  • A word of position points across a page - silent. Mitigation: the 56 such lines were read against the cuts; the ones whose referent moves are in the rewrite list (lines 1219, 1281, 1480).

  • A link from outside the repository (an issue note, a bookmark) names modes.html#<anchor> - silent: it lands at the top of modes.html. Mitigation: the list of pages there. No stub anchors.

  • The summary tables or "Scratch root" leave modes.adoc - fail-closed for the tables (public-surface.test.mjs fails); silent for the exclude file’s pointer. Both stay, by the cut table.

  • The check’s ids differ from the site’s - fail-open. Mitigation: it loads the build’s own Asciidoctor; the built site’s headings carry the same _-prefixed ids; the site build at Delivery is the comparison.

  • A later Antora drops a step of the dependency chain - fail-closed: the test throws naming the step (T8).

  • A link form the check does not read - fail-closed: a problem, never a skip (T5).

  • An anchor defined in an `include::`d file - fail-closed: the check would call its links unresolved. No page includes one today.

  • Another branch edits modes.adoc meanwhile - fail-closed (a merge conflict). Mitigation: pi-win’s pushes are held from the split commit to the merge.

Tests

Contract, tools/lib/test/docs-links.test.mjs:

  • T1 "every link in this repository’s docs names a page and an anchor that exist, and every top-level page is in the nav": docsLinkProblems(<repository root>) equals [].

Unit, the same file, each on a small tree written under a temporary directory, asserting the exact strings:

  • T2 "a missing page, a missing anchor and a missing in-page anchor are each named; an in-page reference by a section’s title resolves, and one by a title the page lacks is named".

  • T3 (regression) "a path is read from the module’s pages directory: a sibling named without its directory is a missing page" - the form of the two links broken today.

  • T4 "a link in a listing block or a code span is not a link".

  • T5 "a link form the check does not read is a problem, not a skip": xref:./a.adoc[], xref:{page}.adoc[], <<a.adoc#b>>.

  • T6 "a top-level page the nav does not link is named".

  • T7 "another module, this component’s own name and a same-page link are followed, and a module’s nav is read from its own module": xref:ROOT:a.adoc[] from the standards module, xref:pi::a.adoc[], xref:#b[], and a standards nav.adoc whose xref:a.adoc[] is found in the standards pages and not in ROOT’s.

  • T8 "an unresolvable step of the Asciidoctor chain is named in the error".

Existing pins that must stay green unchanged: tools/lib/test/public-surface.test.mjs; packages/pi-modes/test/scratch-root.test.ts.

Negative controls: with the check in place and before the split is finished, three deliberate faults in the working tree (one moved anchor’s link left on modes.adoc, one <<id>> left pointing across a page, one new page left out of the nav), each failing T1 with its line; then mutants of docs-links.mjs (fences not blanked, the fragment not checked, an unread form skipped, a title reference skipped, a nav read as ROOT’s).

Delivery

  1. Before this branch: a fix: issue, filed at approval, for the two broken plan links (xref:plans/remote-rpc-control.adoc[], xref:plans/close-review-pane.adoc[the acceptance plan]), merged on its own, so the check lands green.

  2. This plan committed as docs/modules/ROOT/pages/plans/split-modes-page.adoc, with its nav entry after the last Active plan, before any other change; Status to In progress at the next commit.

  3. Commit one: the check and its tests, green on main’s docs. Commit two: the split, done by a script over the cut table (kept under .pi/scratch/, not committed), with every rewrite, the pointer edits, the testing.adoc bullet and the CHANGELOG.adoc entry under == Unreleased, Changed. Commit two’s diff is about 580,000 characters, under the commit review’s 1,500,000 and inside each reviewer’s window (one million tokens for Carbon and for the fallback, by pi --list-models).

  4. Measured rows for the MR: the line account (old lines 4,999; each on exactly one page; the differences are the rewrites, the heading levels and the new header lines, counted); npx antora antora-playbook.yml on main and on the branch, the two outputs compared, with no unresolved-link message on the branch.

  5. validate, both runs. No consumer-sim: no extension code changes. The patch to pi-win for the tools/lib suite on Windows, where the check’s paths and the Asciidoctor chain are the things to see.

  6. MR with Closes #903, squash off; the merge SHA on the issue; Status to Done (date).

Edit this page · latest