Plan: freeze the 1.0 public surface

Closes: #701. Relates to: #280, #836, #380. Branches: feat/overlay-unknown-keys, test/surface-contracts, chore/surface-freeze. Status: Done (2026-12-04) — 1.0 public surface frozen (#701)

Context

#701 is the freeze half of #280. What the tree says, by reading:

  • docs/modules/ROOT/pages/public-surface.adoc lists every item with a tier (stable, internal, upstream). tools/lib/test/public-surface.test.mjs fails validate when the page and the code name different items (tools/lib/public-surface.mjs). It compares names. No shape is held.

  • packages/pi-modes/config.ts: six nested blocks (judge, title, shortcuts, unattended, compaction, monitor) refuse an unknown key by name. Five places with a fixed key set do not:

    • validateTopLevel and validateMode check each known key and ignore any other, so "recapp": false loads and does nothing. TOP_LEVEL_KEYS and MODE_KEYS already list every key; they are pinned to ModesConfig and ModeDescriptor at compile time, and to the two summary tables of modes.adoc by the public-surface test (OVERLAY_KEYS).

    • guidance (one key, global) is read field by field in validateTopLevel.

    • subagentPolicy (enforce, profiles) and each subagentPolicy.profiles[<agent>] (tools) are read field by field in validateSubagentPolicy. A profile written { "tool": ["read"] } loads as a profile with no tools, which the delegation gate reads as every tool (the comment on profiles in ModesConfig).

  • Three maps are keyed by names the operator chooses, so no key list exists for them: permission (surface, then pattern), modelRoles (role), and subagentPolicy.profiles (agent).

  • loadModesConfig validates the shipped modes.json, merges the overlay over it, and validates the result. mergeModesConfig spreads the overlay’s keys over the baseline’s at the top level and in each mode, and mergeSubagentPolicy carries each overlay profile whole, so those keys are in the merged object. mergeSubagentPolicy rebuilds the subagentPolicy block itself from enforce and profiles, so any other key the overlay puts there is gone before the merged validation. The shipped modes.json opens with a "//" comment key.

  • loadModesConfig runs in the extension factory (packages/pi-modes/index.ts:74). A throw there is caught by pi’s loader (node_modules/@earendil-works/pi-coding-agent/dist/core/extensions/loader.js:566-568) and reported as Failed to load extension: <message>; the session continues without pi-modes. The permission system then skips its unregistered gadhs-mode-judge link and the ask reaches the terminal (node_modules/@gotgenes/pi-permission-system/src/authority/authorizer-chain-audit.ts:1-12). This is what any invalid overlay does today.

  • Tools and commands are registered through pi.registerTool and pi.registerCommand. pi-modes' test harness records both (fakePi in packages/pi-modes/test/harness.ts); pi-remote registers its command and its five msg_* tools in createRemote (packages/pi-remote/index.ts:881-893).

  • Bus events: some payloads are asserted whole today (gadhs:mode, gadhs:title, gadhs:pending, gadhs-msg:received, gadhs-msg:read), others in part (gadhs:status by toMatchObject, gadhs-hub:facts field by field). No test is named for the item it pins, so nothing can check that each stable item has one.

  • Wires: PROTOCOL_VERSION (pi to its SSH helper) and HUB_PROTOCOL (a session to its box’s hub). Each end refuses another version by name (packages/pi-ssh/connection.ts helloProblem, packages/pi-remote/hub.ts attachProblem), and tests cover it.

  • Package exports: the page’s hand-written list of names a sibling imports has drifted from the code in both directions. The sibling packages are bundled inside @gadhs/pi, pinned exactly, and keep their own 0.x versions.

  • The standards pages are byte-copied from the template and not edited here (ADR-002). standards:git-workflow.adoc already carries SemVer and "API contract stability"; the project’s mapping lives in docs/modules/ROOT/pages/project-conventions.adoc.

Decisions taken with the operator (2026-12-04)

  1. No JSON Schema file. The defect is the silently ignored key; the validator fixes it with the tuples it has. A schema would be a second description of the config to keep in step, and its editor benefit needs a hosted URL. Recorded on #701 at the close.

  2. Every named export of a sibling package is internal. The 1.0 promise covers the distribution: config files and keys, commands, tools, environment variables, bus events, wires, bus-rules.json, and each package’s default export. No export is removed.

  3. The page’s per-name list of sibling imports is dropped. Nothing reads it once every name is internal, and tsc already fails a broken sibling import.

Design

D1. Every block with a fixed key set refuses an unknown key

In packages/pi-modes/config.ts:

/** A key beginning `//` is a comment: the shipped modes.json opens with one. */
const COMMENT_KEY_PREFIX = "//";

/** The keys of `obj` that are neither a comment nor in `known`. */
function unknownKeys(obj: Record<string, unknown>, known: readonly string[]): string[] {
	return Object.keys(obj).filter((k) => !k.startsWith(COMMENT_KEY_PREFIX) && !known.includes(k));
}
  • validateTopLevel begins by throwing ${source}: unknown top-level key(s): <keys> (known: <TOP_LEVEL_KEYS>) when unknownKeys(cfg, TOP_LEVEL_KEYS) is not empty.

  • validateMode begins by throwing ${source}: mode "<id>" has unknown key(s): <keys> (known: <MODE_KEYS>) likewise.

  • Membership is Array.prototype.includes on the tuple, so constructor or proto as a key is unknown like any other (T2).

  • Both run on the baseline pass and on the merged pass, so an overlay’s key is reported with the source <overlay> (merged over <baseline>) (T1).

  • A //-prefixed key is a comment at these two levels only. The nested blocks keep their own checks and take no comment key, as today (T3).

  • The three unchecked nested blocks get the check the six have, with the same message form, ${source}: <label> has unknown key(s): <keys> (known: <tuple>), through one helper refuseUnknownKeys(obj, known, source, label):

    • guidance, label "guidance", against a new GUIDANCE_KEYS = ["global"], in validateTopLevel;

    • subagentPolicy, label "subagentPolicy", against a new SUBAGENT_POLICY_KEYS = ["enforce", "profiles"], in validateSubagentPolicy (which gains the source parameter);

    • each profile, label subagentPolicy.profiles["<agent>"], against a new SUBAGENT_PROFILE_KEYS = ["tools"], in the same function. A misspelt tools is then a refusal, not a profile holding every tool (T1).

  • Each new tuple is pinned to its type at compile time as JUDGE_KEYS is, and joins OVERLAY_KEYS as guidance, subagentPolicy and subagentProfile. The six existing checks are left as written.

  • The overlay’s own subagentPolicy keys are checked before the merge, by a new validateOverlaySubagentPolicy(raw, overlayPath) called in loadModesConfig beside validateOverlayPermissions, which is the existing pre-merge check of the same kind. It applies refuseUnknownKeys with SUBAGENT_POLICY_KEYS when the block is a plain object and leaves any other type to the merged validation. mergeSubagentPolicy is not changed.

  • The doc comment on OVERLAY_KEYS drops "accepted silently today".

  • No alias, warning period or migration: before 1.0 the refusal is the change.

  • A fixture or test config in the tree that carries a stray key is corrected (the key removed, or spelt //… when it is a comment). unknownKeys is not widened for it.

D2. Tools and commands: one recorded registration per package

A new test/surface-contract.test.ts in each package that registers a stable tool or command: pi-modes (17 tools, 7 commands), pi-remote (5 tools, 1 command), pi-ssh (1 command), pi-guidance (1 command). Each:

  1. Loads the package’s real entry against a recording pi: gadhsPiModes(pi) with fakePi(), isolated as wiring.test.ts’s `load() is (a scratch PI_CODING_AGENT_DIR, no GADHS_PI_MODES_CONFIG); createRemote(pi, { wire }) as packages/pi-remote/test/extension.test.ts builds it; the default exports of pi-ssh and pi-guidance. Registration happens in the factory, so no session is started.

  2. Builds { "commands": { "/<name>": <description> }, "tools": { "<name>": <parameters> } }, names sorted.

    • A tool’s value is JSON.parse(JSON.stringify(def.parameters)) with every description key whose value is a string removed, recursively. That strips schema prose and keeps a parameter that is itself named description (its value is an object).

    • A command’s value is its registered description. A command takes one free-text argument, and each stable command that takes one states its usage there (/mode [id|next|models]; /hub and /gadhs-init take none), so the description is the only declared form of its parameters.

    • pi-ssh and pi-guidance record commands only: the tools pi-ssh re-registers are pi’s own (tier upstream).

  3. Compares with await expect(text).toMatchFileSnapshot("./fixtures/surface.json"), as packages/pi-modes/test/gate-characterisation.test.ts:102 does. The records hold no path, so the tests run on every platform.

A change to a stable tool’s parameters or a command’s usage then fails until the record is regenerated (vitest -u), and the regenerated record is a diff in the MR. With CI set, vitest runs snapshots in none mode: a mismatch or a missing record fails. Locally a missing record would be written, which D4 covers.

D3. Bus events and wires: one contract: test each

Convention: a test whose title begins contract: <item> ` (the item, then a space), where the item is the channel name or the wire’s constant. It asserts the whole payload the real emitter produces with `toEqual on a literal, so an added, removed or retyped field fails. Two kinds of value are not written as literals: a clock value is expect.any(Number), and a value that follows the shipped modes.json is not hard-coded, so a rule edit does not fail the contract: gadhs:status’s `modeId and modeLabel are read from the loaded config, ruleCount is expect.any(Number), and text is renderStatus (packages/pi-modes/status.ts) of the event’s own fields. Where the suite below already asserts that, the test is retitled; where it asserts part, a test is added. No assertion is loosened.

Item Suite What the contract test asserts

gadhs:status

pi-modes/test/wiring.test.ts (today :217, toMatchObject)

A fresh session’s event, whole: modeId, modeLabel, judgeEnabled, ruleCount, text, and stats with every non-optional field of SessionStats (packages/pi-modes/status.ts:23).

gadhs:mode

same

{ from, to } on a switch.

gadhs:title

pi-modes/test/session-wiring.test.ts (today inside :660)

{ state, title } for each state.

gadhs:pending

pi-modes/test/pending-wiring.test.ts:351 (exists)

Retitled; extended with a step carrying full and a queued question carrying question (packages/pi-modes/pending-event.ts).

gadhs:hub

pi-modes/test/hub-publish.test.ts

{ part, items, at } for each of the five parts, one item each with every optional field set (packages/pi-modes/hub-publish.ts:36-95).

gadhs-hub:ask

pi-modes/test/hub-wiring.test.ts (near :168)

The payload is {}.

gadhs-hub:facts

pi-remote/test/extension.test.ts (today :317-327) and pi-ssh/test/session.test.ts (near :939)

{ source, lines }, whole, from each emitter.

gadhs-msg:received

pi-remote/test/extension.test.ts:1199 (exists, whole)

Retitled.

gadhs-msg:read

pi-modes/test/msg-wake.test.ts:204 (exists, whole)

Retitled, or a focused test beside it.

PROTOCOL_VERSION

pi-ssh/test/connection.test.ts (today :118) with protocol.test.ts:120

The bump rule’s two halves: helper.mjs and protocol.ts carry one number; a hello on another number is EPROTO naming both.

HUB_PROTOCOL

pi-remote/test/hub.test.ts (today :364)

An attach on another number is refused with protocol <n>; this hub speaks <HUB_PROTOCOL>, and that connection ends.

The bump rule in words goes on the page (D5): a change to a frame that a peer on the previous number does not read bumps the constant; the page’s row and the constant’s comment record it.

D4. validate requires a contract for every stable item

tools/lib/public-surface.mjs gains three readers, in the file’s existing style:

  • stableOf(rows, map): the backticked items of the first cell of each row whose last cell begins stable. For the Wires table, map keeps the name before ` = `.

  • recordedSurface(root): the union of every packages/*/test/fixtures/surface.json, as { tools, commands } sets. A record that does not parse is an error naming the file.

  • contractTitlesIn(root): the item of every title that opens an it( or describe( call with contract: ` in `packages//test/.test.ts. It reads each file through withoutComments, takes either quote or a backtick, and allows whitespace and a line break between the ( and the title, since Biome wraps a long call (gate-characterisation.test.ts:96).

tools/lib/test/public-surface.test.mjs gains, each through difference so both sides are named:

  • the page’s stable tools are exactly the recorded tools; likewise commands;

  • every stable bus channel and stable wire constant on the page is among the contract titles.

Reading the records from disk is what fails a missing record on a developer’s machine.

D5. Named exports are internal; the page states the promise; the conventions state the rule

  • public-surface.adoc:

    • Intro: the page is the freeze. Stable is bound by SemVer from @gadhs/pi 1.0.0; internal changes in any release; upstream is owned elsewhere. It points at the rule in project conventions and at how each kind is held (names, D2 records, D3 tests).

    • Configuration files: "accept one silently today" becomes: every block with a fixed key set refuses an unknown key by name, and the three maps keyed by the operator’s own names (permission, modelRoles, subagentPolicy.profiles) take any key (this sentence moves with D1, in the first unit).

    • Wires: the bump rule.

    • Package exports: an extension package’s tier becomes stable: the default export (for @gadhs/pi-modes, also bus-rules.json) and internal: every named export. The two libraries, @gadhs/pi-bash and @gadhs/pi-workspace, have no extension to load: their tier is internal: every export. The per-name lists and the "stable candidates" paragraph go. One paragraph says siblings import named exports within one release, held by exact pins and tsc.

  • Entry files: every .ts file an exports map targets (25 files: each package’s index.ts; pi-modes’ `ask-broker, config, diagnostics, drop, hub-facts, hub-publish, msg-wake, pending-event, status, title; pi-ssh/extension.ts; pi-workflow/git-guard.ts; pi-workspace’s `contract, process-start, windows-kill) gets one sentence in its header comment: Named exports here are internal to the @gadhs/pi distribution: no semver promise (public-surface.adoc). The public-surface test asserts each target carries internal to the @gadhs/pi distribution, so a new subpath states its tier.

  • project-conventions.adoc, a new section == Stability from 1.0 before == Project Overrides: from @gadhs/pi 1.0.0, SemVer binds the stable tier of the public-surface page. A breaking change to a stable item (removing or renaming it, changing the type of a parameter or payload field, a config loader refusing what it accepted, a wire’s peers refusing each other) needs a major version of @gadhs/pi and an entry under === Breaking in CHANGELOG.adoc that says what to change. An addition is a minor. Internal and upstream items change in any release. The sibling packages keep their 0.x versions. This is the project’s form of the standard’s "API contract stability"; the synced standards pages are not edited.

Units

Unit Branch, MR Changes

U1

feat/overlay-unknown-keys, Relates to #701

D1 in packages/pi-modes/config.ts; T1-T3 in packages/pi-modes/test/config.test.ts; modes.adoc (Configuration resolution: the refusal, which blocks it covers, and // comment keys); the Configuration files sentence of public-surface.adoc; CHANGELOG.adoc Changed. This plan file and its nav.adoc line are committed first on this branch.

U2

test/surface-contracts, Relates to #701

D2 (four tests, four records), D3 (the suites in the table), D4 (tools/lib/public-surface.mjs and its test); public-surface.adoc intro paragraph on how each kind is held; CHANGELOG.adoc Added.

U3

chore/surface-freeze, Closes #701

D5: the page, the 25 entry-file sentences and their check, project-conventions.adoc; CHANGELOG.adoc Changed.

Units land in order, each through the merge train, squash off.

Tests

Regression (the case that would have caught it):

  • T1, config.test.ts: through loadModesConfig with an overlay file, "recapp": false at the top level is refused naming recapp and the overlay’s path; "modle" in an existing mode and in a new, complete mode is refused naming the mode and the key; "guidance": { "globl": "x" } and "subagentPolicy": { "enforec": false } are refused naming the block and the key; a profile { "tool": ["read"] } is refused naming the agent and tool. Before D1 all six load, the last as a profile with every tool.

  • T1b, config.test.ts: the existing test "each nested block’s list is the one its validator refuses unknown keys against" gains guidance, subagentPolicy and subagentProfile, so each new tuple in OVERLAY_KEYS is the list its check reports.

  • T3, config.test.ts: the shipped modes.json loads with its "//" key; an overlay with "// note" at the top level and in a mode loads; "//" inside title is still refused by `title’s own check.

  • T6, tools/lib/test/public-surface.test.mjs, on its temporary tree: a stable tool with no record, a recorded tool the page does not call stable, and a stable channel with no contract: title are each named by difference; an internal row is not required.

Property (fast-check):

  • T2, config.test.ts: for any string that is not in the tuple and does not begin //, the shipped config with that key added at the top level, and separately in its first mode, is refused with a message that starts ${SRC}: ` and contains the key. `constructor and proto are among the fixed examples.

Contract (wire and surface):

  • T4: the four surface-contract.test.ts records (D2).

  • T5: the contract: tests of D3’s eleven items (gadhs-hub:facts has one per emitter), the two wires among them.

  • T7, tools/lib/test/public-surface.test.mjs: the page against the records and the titles (D4); every exports target carries the internal sentence (D5).

No concurrency test: no unit changes ordering, locking or a shared resource.

Risks

  • An operator’s overlay carries a stale or misspelt key in a checked block after the upgrade: fail-closed. loadModesConfig throws, pi reports Failed to load extension with the file and the key, pi-modes does not load, and asks reach the terminal. Mitigation: the CHANGELOG entry says what happens and the fix; the message lists the known keys; it is the path a nested block’s unknown key takes today.

  • A comment key spelt without // ("_comment"): fail-closed, as above. Mitigation: modes.adoc states the comment form; T3 pins it.

  • A record regenerated without thought hides a breaking change: silent. Mitigation: the record is a committed file, so the change is a diff the commit review and the MR reader see beside the rule in project conventions. It is not blocked mechanically.

  • A later contract: title on a test that asserts little: silent. Mitigation: D4 checks presence only; this plan writes the tests of all eleven items to D3’s rule, and review holds later ones to it.

  • A record missing on a developer’s machine is written, not failed, by vitest: silent locally. Mitigation: T7 reads the records from disk and fails on a missing one; CI runs snapshots in none mode.

  • A tool’s parameter schema differs by platform, so a record fails on the Windows or macOS nightly: fail-closed (a red job naming the tool). Mitigation: records hold no path; the fix is in the schema’s source, not a skip.

  • Someone outside the distribution imports a sibling’s named export and a later release changes it without a major: silent for them. Mitigation: none is known (the siblings ship inside @gadhs/pi); bus-rules.json, which pivot-msg pins, stays stable; the entry files and the page say so; #836 tracks standalone publishing.

Out of scope

  • A JSON Schema for the overlay, hosted or not (decision 1).

  • Removing exports or subpaths (decision 2).

  • Key checks for the other config files: each loader’s own validation stands, and the page lists their keys unchecked.

  • A misspelt role name in modelRoles (commitReviwer) is still ignored. Refusing it needs the role grammar (mode:<id>, helper:<name>) in the validator; it gets its own fix: issue when U1 starts.

  • A release prepare guard that a === Breaking section needs a major version.

  • What a session does when pi-modes fails to load.

Delivery

  • Canonical doc pages: modes.adoc (U1), public-surface.adoc (U2, U3), project-conventions.adoc (U3).

  • CHANGELOG.adoc == Unreleased: U1 under Changed (an unknown key at the top level, in a mode, in guidance, in subagentPolicy or in one of its profiles is refused at load by name; remove or correct the key), U2 under Added, U3 under Changed.

  • Each unit: node tools/task.mjs check before the push, then the merge train. The release that carries U1 is the operator’s to name; 1.0.0 also waits on #380.

  • The close: U3’s MR closes #701. One note on the issue with the merge SHA and the two deviations from its text: no schema file (decision 1), and the policy line in project conventions with the synced standards pages unedited.

  • Status moves to In progress when U1 starts and to Done (date) with U3.

Edit this page · latest