Render the prompt's "when to hand off" section from the policy's human-label definitions #14

Closed
opened 2026-08-22 11:35:07 +00:00 by ben · 1 comment
Owner

Part of the agent-driven install-session arc (Ben, 2026-08-21/22; docs/superpowers/specs/2026-08-21-vendor-command-design.md §Context records the decomposition: 2 vendor ✅ → 1 policy layer + prompt rendering → 3 host enrolment → 4 the install session). Worked by the factory's own swarm (STATUS.md 2026-08-22 — SELF-HOSTED).

Depends on the policy layer ticket and #1 (the render pipeline). ready-for-session: this edits a prompt skeleton.

Why

Ben's ruling: loop-in granularity lives in the definition and use of the human labels, per repo. Today the hand-off rules are prose in prompt.md (rule 6, "When you are blocked") naming ready-for-human/agent-blocked by hand, with idss label ids in a comment.

Deliverables

  • A skeleton block in prompt.md ({{HANDOFF_RULES}}) that the render step fills from policy_human_labels: one bullet per label — name, its trigger (the fixed trigger vocabulary from the policy ticket, each with one sentence of guidance), and the label swap recipe resolved by name at run time.
  • Rendering with the default policy reproduces today's rule-6 + blocked-path text byte-identical for idss (the cutover proof #1 already demands).
  • onboard.sh policy prompts for the label set (keep/rename/add, e.g. needs-product-owner) and a trigger per label; mints any new label via onboard_mint_labels.
  • Tests: render fixture for the default policy (byte-identical), a policy with an added label produces exactly one more bullet and no other diff.

Acceptance

  • idss's rendered prompt is unchanged; a repo adding needs-product-owner:product-decision gets a hand-off bullet for it and the label exists in its tracker.
_Part of the agent-driven install-session arc (Ben, 2026-08-21/22; `docs/superpowers/specs/2026-08-21-vendor-command-design.md` §Context records the decomposition: 2 vendor ✅ → 1 policy layer + prompt rendering → 3 host enrolment → 4 the install session). Worked by the factory's own swarm (STATUS.md 2026-08-22 — SELF-HOSTED)._ **Depends on** the policy layer ticket and #1 (the render pipeline). `ready-for-session`: this edits a prompt skeleton. ## Why Ben's ruling: *loop-in granularity lives in the definition and use of the human labels*, per repo. Today the hand-off rules are prose in `prompt.md` (rule 6, "When you are blocked") naming `ready-for-human`/`agent-blocked` by hand, with idss label ids in a comment. ## Deliverables - A skeleton block in `prompt.md` (`{{HANDOFF_RULES}}`) that the render step fills from `policy_human_labels`: one bullet per label — name, its trigger (the fixed trigger vocabulary from the policy ticket, each with one sentence of guidance), and the label swap recipe resolved **by name** at run time. - Rendering with the default policy reproduces today's rule-6 + blocked-path text **byte-identical** for idss (the cutover proof #1 already demands). - `onboard.sh policy` prompts for the label set (keep/rename/add, e.g. `needs-product-owner`) and a trigger per label; mints any new label via `onboard_mint_labels`. - Tests: render fixture for the default policy (byte-identical), a policy with an added label produces exactly one more bullet and no other diff. ## Acceptance - idss's rendered prompt is unchanged; a repo adding `needs-product-owner:product-decision` gets a hand-off bullet for it and the label exists in its tracker.

Close report — landed as 5593ba8

Ruled by agent under ADR 0174 — veto anytime. Every change is a commit plus an
offline test; nothing here needed a one-way door.

What landed

{{HANDOFF_RULES}} — the placeholder #1 shipped, deliberately still fed by a
static handoff-rules.md enrichment — is now generated from the per-repo
policy.

  • prompt-render-lib.sh gains prompt_render_handoff_rules <policy-file>:
    policy_load + policy_human_labels → one bullet per hand-off label (name,
    trigger, that trigger's one sentence of guidance), then a swap recipe that
    resolves every label id by name at run time — including agent-working,
    which the old text left as a literal <agent-working-id> placeholder.
    prompt_render_one takes an optional 6th arg, defaulting to
    <enrich-dir>/../swarm-policy.sh (where a consumer's policy actually sits),
    and runs the generation in a subshell so the consumer's SWARM_POLICY_*
    never leak into the renderer.
  • policy-lib.sh gains policy_trigger_guidance <trigger>. The prose
    lives beside the vocabulary itself, not in the renderer, so the trigger set
    and its meaning cannot drift apart — and it carries no product's
    decision-record numbers or paths, since this text renders into every
    consumer's prompt (CLAUDE.md's blast-radius rule; each repo states its own
    two-way-door doctrine in its own rules enrichment).
  • onboard.sh policy --interactive walks the current set (keep / rename /
    drop, then add) asking a trigger per label — re-asking, never silently
    accepting, an out-of-vocabulary answer — mints anything the tracker lacks via
    new onboard_mint_human_labels (which delegates to onboard_mint_labels, so
    the already-there / create / report-the-id mechanics stay in one place), and
    writes a validated swarm-policy.sh.
  • .sandcastle/prompt.md re-rendered; prompt-enrichments/handoff-rules.md
    deleted here and in the idss cutover fixture. Safe at the current pin —
    bd48fd6 has no prompts/ dir and no render block in its drift check;
    .sandcastle/check-harness-drift.sh is still OK.

Two rulings, stated plainly

1. The vocabulary gains a fourth key, product-decision (ADR 0002
amendment, appended to the ADR).

The acceptance names needs-product-owner:product-decision, but
product-decision was not in the fixed three-key vocabulary the deliverables
also point at — the ticket contradicts itself. Resolved in favour of the
acceptance, because the three-key reading is the worse design here: under it,
needs-product-owner's only home is one-way-door, which would print two
bullets reciting identical guidance
and leave a blocked worker no way to
choose between them. The routing prose is only as sharp as the trigger set
behind it. The change is additive and the vocabulary is still closed —
_policy_check_structure refuses anything outside the four, naming all four —
and no existing policy uses the new key, so no repo's behaviour changes until
it opts in. Extending it stays a factory-core change (one place, one commit,
one test), never a per-repo escape hatch.

2. "Byte-identical for idss" is honoured as CLAUDE.md's second option, not
literally
— "deliberately updated with the wording change explained".

It cannot be honoured literally: today's text is a two-label numbered
paragraph, the deliverable is a per-label bullet list, and today's text
hardcodes the very ids ("with idss label ids in a comment") the ticket's own
Why names as the defect. Reproducing it byte-for-byte would have preserved
them. What I did instead:

  • The cutover diff is confined to exactly the ## When you are blocked
    section
    . Both the idss fixture and this repo's own .sandcastle/prompt.md
    are byte-identical everywhere else, and all four other prompts are untouched
    — the onboard-lib-test.sh cutover proof still runs and still passes.
  • The generated tail deliberately does not enumerate the labels, so the
    acceptance holds exactly: adding a label produces one more bullet and no
    other diff
    , asserted by a diff with zero < lines.

A real bug found while driving the interactive path

onboard_write_policy wrote every KEY=value verbatim. The file is
sourced, so a multi-word HUMAN_LABELS= (or PROTECTED_PATHS=) assigned
only its first token and ran the rest as commands —
swarm-policy.sh: line 6: agent-blocked:cannot-proceed: command not found —
and _policy_check_structure then happily accepted the silently-truncated
value. A repo declaring four hand-off labels would have gated on one. It now
quotes any value containing whitespace and refuses one containing ",
$, a backtick or a backslash. docs/GOTCHAS.md 15 records it, with the rule
that a writer emitting a to-be-sourced file owns the quoting and must test the
whole-value round trip.

Proof

Offline suite green — 64 files, including:

  • tests/prompt-render-lib-test.sh 13 → 33: default render, the
    added-label pure-addition diff, empty-HUMAN_LABELS and bad-trigger
    refusals, no SWARM_POLICY_* leak, the <enrich-dir>/../swarm-policy.sh
    default, and a ratchet that no /labels/<n> numeric id survives in the block.
  • tests/policy-lib-test.sh 30 → 43: guidance per trigger, the 68-column
    wrap (so the renderer's 5-space indent still fits the prompt column), and the
    closed-vocabulary refusal listing all four keys.
  • onboarding/tests/onboard-lib-test.sh 137 → 158: the interview's
    keep / rename / drop / add / re-ask / EOF paths, minting, the write_policy
    quoting round trip, and onboard.sh policy --interactive end to end — its
    output feeding prompt_render_handoff_rules to produce exactly the one extra
    needs-product-owner bullet.
  • tests/judgement-call-prompts-test.sh re-pointed at the generated wording
    and ratcheted against a numeric label id ever returning to the blocked path.
  • tests/check-harness-drift-test.sh T7's fixture gains the render lib's two
    vendored siblings (policy-lib.sh, forgejo-lib.sh).

Live proof against this repo's real tracker (onboard.sh policy --interactive, keeping the defaults so nothing is minted and no residue is
left): the three hand-off labels resolved to their real ids 148 / 150 / 146
and policy_validate came back OK against the live label set. Note those ids —
the prose this ticket retires hardcoded 36 / 48, which are not this repo's
ids at all. Label count before and after: 16.

Scope not claimed

The acceptance's second half — "and the label exists in its tracker" for
a repo that actually adds needs-product-owner — is proven here against a
shimmed curl plus the live no-op run above, not by minting into idss or
matou-app: that would be a push into a product repo, which ADR 0001 rules
pull-only. Each consumer runs onboard.sh policy --interactive in its own
repo. Likewise this is root-only — a human re-vendor carries
prompt-render-lib.sh / policy-lib.sh to .sandcastle/, and idss/matou-app
pick up the new hand-off section when they re-render at their next pin bump.

Docs updated in the same commit: STATUS.md (header, three "Where things
stand" rows, and a milestone-log entry closing the policy-layer +
prompt-rendering sub-arc), docs/adr/0002-*.md (amendment),
docs/GOTCHAS.md (15), onboarding/README.md, CLAUDE.md (the blast-radius
paragraph now names swarm-policy.sh and policy_trigger_guidance's prose).

## Close report — landed as `5593ba8` Ruled by agent under ADR 0174 — veto anytime. Every change is a commit plus an offline test; nothing here needed a one-way door. ### What landed `{{HANDOFF_RULES}}` — the placeholder #1 shipped, deliberately still fed by a static `handoff-rules.md` enrichment — is now **generated** from the per-repo policy. - **`prompt-render-lib.sh`** gains `prompt_render_handoff_rules <policy-file>`: `policy_load` + `policy_human_labels` → one bullet per hand-off label (name, trigger, that trigger's one sentence of guidance), then a swap recipe that resolves **every** label id by name at run time — including `agent-working`, which the old text left as a literal `<agent-working-id>` placeholder. `prompt_render_one` takes an optional 6th arg, defaulting to `<enrich-dir>/../swarm-policy.sh` (where a consumer's policy actually sits), and runs the generation in a subshell so the consumer's `SWARM_POLICY_*` never leak into the renderer. - **`policy-lib.sh`** gains `policy_trigger_guidance <trigger>`. The prose lives *beside the vocabulary itself*, not in the renderer, so the trigger set and its meaning cannot drift apart — and it carries no product's decision-record numbers or paths, since this text renders into every consumer's prompt (CLAUDE.md's blast-radius rule; each repo states its own two-way-door doctrine in its own `rules` enrichment). - **`onboard.sh policy --interactive`** walks the current set (keep / rename / drop, then add) asking a trigger per label — **re-asking**, never silently accepting, an out-of-vocabulary answer — mints anything the tracker lacks via new `onboard_mint_human_labels` (which delegates to `onboard_mint_labels`, so the already-there / create / report-the-id mechanics stay in one place), and writes a validated `swarm-policy.sh`. - `.sandcastle/prompt.md` re-rendered; `prompt-enrichments/handoff-rules.md` deleted here and in the idss cutover fixture. Safe at the current pin — `bd48fd6` has no `prompts/` dir and no render block in its drift check; `.sandcastle/check-harness-drift.sh` is still `OK`. ### Two rulings, stated plainly **1. The vocabulary gains a fourth key, `product-decision`** (ADR 0002 amendment, appended to the ADR). The acceptance names `needs-product-owner:product-decision`, but `product-decision` was not in the fixed three-key vocabulary the deliverables also point at — the ticket contradicts itself. Resolved in favour of the acceptance, because the three-key reading is the worse design here: under it, `needs-product-owner`'s only home is `one-way-door`, which would print **two bullets reciting identical guidance** and leave a blocked worker no way to choose between them. The routing prose is only as sharp as the trigger set behind it. The change is additive and the vocabulary is still **closed** — `_policy_check_structure` refuses anything outside the four, naming all four — and no existing policy uses the new key, so no repo's behaviour changes until it opts in. Extending it stays a factory-core change (one place, one commit, one test), never a per-repo escape hatch. **2. "Byte-identical for idss" is honoured as CLAUDE.md's *second* option, not literally** — "deliberately updated with the wording change explained". It cannot be honoured literally: today's text is a two-label numbered paragraph, the deliverable is a per-label bullet list, and today's text hardcodes the very ids ("with idss label ids in a comment") the ticket's own Why names as the defect. Reproducing it byte-for-byte would have preserved them. What I did instead: - The cutover diff is **confined to exactly the `## When you are blocked` section**. Both the idss fixture and this repo's own `.sandcastle/prompt.md` are byte-identical everywhere else, and all four other prompts are untouched — the `onboard-lib-test.sh` cutover proof still runs and still passes. - The generated tail deliberately does **not** enumerate the labels, so the acceptance holds exactly: adding a label produces **one more bullet and no other diff**, asserted by a `diff` with zero `<` lines. ### A real bug found while driving the interactive path `onboard_write_policy` wrote every `KEY=value` verbatim. The file is **sourced**, so a multi-word `HUMAN_LABELS=` (or `PROTECTED_PATHS=`) assigned only its first token and ran the rest as commands — `swarm-policy.sh: line 6: agent-blocked:cannot-proceed: command not found` — and `_policy_check_structure` then happily accepted the silently-truncated value. A repo declaring four hand-off labels would have gated on one. It now quotes any value containing whitespace and **refuses** one containing `"`, `$`, a backtick or a backslash. `docs/GOTCHAS.md` 15 records it, with the rule that a writer emitting a to-be-sourced file owns the quoting and must test the whole-value round trip. ### Proof Offline suite green — **64 files**, including: - `tests/prompt-render-lib-test.sh` 13 → **33**: default render, the added-label pure-addition diff, empty-`HUMAN_LABELS` and bad-trigger refusals, no `SWARM_POLICY_*` leak, the `<enrich-dir>/../swarm-policy.sh` default, and a ratchet that no `/labels/<n>` numeric id survives in the block. - `tests/policy-lib-test.sh` 30 → **43**: guidance per trigger, the 68-column wrap (so the renderer's 5-space indent still fits the prompt column), and the closed-vocabulary refusal listing all four keys. - `onboarding/tests/onboard-lib-test.sh` 137 → **158**: the interview's keep / rename / drop / add / re-ask / EOF paths, minting, the `write_policy` quoting round trip, and `onboard.sh policy --interactive` end to end — its output feeding `prompt_render_handoff_rules` to produce exactly the one extra `needs-product-owner` bullet. - `tests/judgement-call-prompts-test.sh` re-pointed at the generated wording and ratcheted against a numeric label id ever returning to the blocked path. - `tests/check-harness-drift-test.sh` T7's fixture gains the render lib's two vendored siblings (`policy-lib.sh`, `forgejo-lib.sh`). **Live proof** against this repo's real tracker (`onboard.sh policy --interactive`, keeping the defaults so nothing is minted and no residue is left): the three hand-off labels resolved to their **real ids 148 / 150 / 146** and `policy_validate` came back OK against the live label set. Note those ids — the prose this ticket retires hardcoded **36 / 48**, which are not this repo's ids at all. Label count before and after: 16. ### Scope not claimed The acceptance's second half — "*and the label exists in **its** tracker*" for a repo that actually adds `needs-product-owner` — is proven here against a shimmed curl plus the live no-op run above, not by minting into idss or matou-app: that would be a push into a product repo, which ADR 0001 rules pull-only. Each consumer runs `onboard.sh policy --interactive` in its own repo. Likewise this is **root-only** — a human re-vendor carries `prompt-render-lib.sh` / `policy-lib.sh` to `.sandcastle/`, and idss/matou-app pick up the new hand-off section when they re-render at their next pin bump. Docs updated in the same commit: `STATUS.md` (header, three "Where things stand" rows, and a milestone-log entry closing the policy-layer + prompt-rendering sub-arc), `docs/adr/0002-*.md` (amendment), `docs/GOTCHAS.md` (15), `onboarding/README.md`, `CLAUDE.md` (the blast-radius paragraph now names `swarm-policy.sh` and `policy_trigger_guidance`'s prose).
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Matou/dev-factory#14
No description provided.