Policy layer: swarm-policy.sh contract + policy-lib.sh loader (landing, merge authority, human labels + triggers) #12

Closed
opened 2026-08-22 11:35:03 +00:00 by ben · 4 comments
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).

Why

Per-repo behaviour today is either prose inside prompt.md or hardcoded in the harness (push to main in run-swarm.sh:608/prompt.md step 6; matou-app's PR-per-issue flow lives in its own .sandcastle/, not here). Ben's rulings: landing and merge authority are per-repo knobs, loop-in is the human-label state machine (per-repo label definitions + trigger rules, not a level ladder), and we build enforcement now, not record-now-enforce-later.

Contract — swarm-policy.sh (consumer identity layer, beside swarm-identity.sh)

Plain KEY=value, sourceable by bash and parseable by node, same discipline as swarm.config:

LANDING=push|pr                      # push: rebase + push HEAD:refs/heads/main (today's behaviour). pr: branch agent/issue-<N> + PR
MERGE_AUTHORITY=human|agent-after-green   # only meaningful when LANDING=pr
HUMAN_LABELS="ready-for-human:one-way-door agent-blocked:cannot-proceed needs-info:missing-context"
                                     # name:trigger pairs; the trigger keys are a fixed vocabulary this ticket defines (document each)
PROTECTED_PATHS=".sandcastle .forgejo"    # overrides PP_PROTECTED_DIRS_DEFAULT

Defaults when the file is absent: LANDING=push, MERGE_AUTHORITY=human, the core label set with today's triggers, today's protected dirs — i.e. byte-identical behaviour for idss.

Deliverables

  • policy-lib.sh: policy_load [file] (sources with defaults, exports SWARM_POLICY_*), policy_validate (unknown key, bad enum, a HUMAN_LABELS name not in the repo's label set → exit 2 with the offending key named — fail LOUD before any worker spawns, like swarm_resolve_model), policy_human_labels (emits name/trigger lines for renderers).
  • run-swarm.sh calls policy_load+policy_validate in preflight (no behaviour change yet — consumers of the knobs are the follow-up tickets).
  • onboarding/vendor-manifest lists policy-lib.sh; vendor-exclude lists swarm-policy.sh; onboard.sh policy <out-file> [KEY=value ...] writes a validated file (pattern: e2e-tier).
  • tests/policy-lib-test.sh: absent file → defaults; each enum rejected/accepted; unknown key rejected; label-not-minted rejected (shimmed curl label list).
  • docs/adr/0002-per-repo-policy-layer.md recording the rulings above.

Acceptance

  • Full offline suite green; run-swarm.sh preflight with no policy file prints policy: defaults (LANDING=push MERGE_AUTHORITY=human).
  • A policy file with LANDING=merge fails preflight with policy: LANDING must be push|pr (got merge).
  • No consumer-specific value anywhere in policy-lib.sh.
_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)._ ## Why Per-repo behaviour today is either prose inside `prompt.md` or hardcoded in the harness (push to main in `run-swarm.sh:608`/`prompt.md` step 6; matou-app's PR-per-issue flow lives in its own `.sandcastle/`, not here). Ben's rulings: **landing and merge authority are per-repo knobs**, **loop-in is the human-label state machine** (per-repo label definitions + trigger rules, not a level ladder), and we **build enforcement now**, not record-now-enforce-later. ## Contract — `swarm-policy.sh` (consumer identity layer, beside `swarm-identity.sh`) Plain `KEY=value`, sourceable by bash and parseable by node, same discipline as `swarm.config`: ``` LANDING=push|pr # push: rebase + push HEAD:refs/heads/main (today's behaviour). pr: branch agent/issue-<N> + PR MERGE_AUTHORITY=human|agent-after-green # only meaningful when LANDING=pr HUMAN_LABELS="ready-for-human:one-way-door agent-blocked:cannot-proceed needs-info:missing-context" # name:trigger pairs; the trigger keys are a fixed vocabulary this ticket defines (document each) PROTECTED_PATHS=".sandcastle .forgejo" # overrides PP_PROTECTED_DIRS_DEFAULT ``` Defaults when the file is absent: `LANDING=push`, `MERGE_AUTHORITY=human`, the core label set with today's triggers, today's protected dirs — i.e. **byte-identical behaviour for idss**. ## Deliverables - `policy-lib.sh`: `policy_load [file]` (sources with defaults, exports `SWARM_POLICY_*`), `policy_validate` (unknown key, bad enum, a `HUMAN_LABELS` name not in the repo's label set → exit 2 with the offending key named — fail LOUD before any worker spawns, like `swarm_resolve_model`), `policy_human_labels` (emits name/trigger lines for renderers). - `run-swarm.sh` calls `policy_load`+`policy_validate` in preflight (no behaviour change yet — consumers of the knobs are the follow-up tickets). - `onboarding/vendor-manifest` lists `policy-lib.sh`; `vendor-exclude` lists `swarm-policy.sh`; `onboard.sh policy <out-file> [KEY=value ...]` writes a validated file (pattern: `e2e-tier`). - `tests/policy-lib-test.sh`: absent file → defaults; each enum rejected/accepted; unknown key rejected; label-not-minted rejected (shimmed `curl` label list). - `docs/adr/0002-per-repo-policy-layer.md` recording the rulings above. ## Acceptance - Full offline suite green; `run-swarm.sh` preflight with no policy file prints `policy: defaults (LANDING=push MERGE_AUTHORITY=human)`. - A policy file with `LANDING=merge` fails preflight with `policy: LANDING must be push|pr (got merge)`. - No consumer-specific value anywhere in `policy-lib.sh`.

swarm-claim host=matou-dev-server-01 run=81
(automated multi-host claim — lowest live claim id works this ticket)

swarm-claim host=matou-dev-server-01 run=81 (automated multi-host claim — lowest live claim id works this ticket)

close-report for #12 — status success

✅ close-report gates passed — every claim verified against main; closing.

envelope
{
  "issue": 12,
  "status": "success",
  "commits": [
    "5d401f4f29801e2164f86fcf7c1db32ca1325a5a"
  ],
  "changed_files": [
    "STATUS.md",
    "docs/adr/0002-per-repo-policy-layer.md",
    "onboarding/onboard-lib.sh",
    "onboarding/onboard.sh",
    "onboarding/tests/onboard-lib-test.sh",
    "onboarding/vendor-exclude",
    "onboarding/vendor-manifest",
    "policy-lib.sh",
    "run-swarm.sh",
    "tests/policy-lib-test.sh"
  ],
  "tests": [
    {
      "command": "bash tests/policy-lib-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash onboarding/tests/onboard-lib-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash onboarding/tests/vendor-manifest-coverage-test.sh",
      "exit_code": 0
    },
    {
      "command": "for t in tests/*.sh onboarding/tests/*.sh; do case \"$t\" in *fakebin*|*fixtures*) continue;; esac; bash \"$t\"; done",
      "exit_code": 0
    }
  ],
  "criteria": {
    "policy-lib.sh: policy_load sources with defaults, exports SWARM_POLICY_*": "policy-lib.sh policy_load(); tests/policy-lib-test.sh absent-file default cases",
    "policy-lib.sh: policy_validate rejects unknown key / bad enum / label-not-minted with exit 2 naming the offending key, fail-LOUD before workers spawn": "policy-lib.sh policy_validate() + _policy_check_structure(); tests/policy-lib-test.sh reject cases (unknown key, both enums, unminted label via shimmed curl)",
    "policy-lib.sh: policy_human_labels emits name/trigger lines for renderers": "policy-lib.sh policy_human_labels(); tests/policy-lib-test.sh human_labels name<TAB>trigger cases",
    "run-swarm.sh calls policy_load+policy_validate in preflight (no behaviour change)": "run-swarm.sh preflight block after preflight self-tests; no knob consumed",
    "onboarding/vendor-manifest lists policy-lib.sh; vendor-exclude lists swarm-policy.sh": "onboarding/vendor-manifest +policy-lib.sh; onboarding/vendor-exclude +swarm-policy.sh; vendor-manifest-coverage-test PASS",
    "onboard.sh policy <out-file> [KEY=value ...] writes a validated file (pattern: e2e-tier)": "onboarding/onboard.sh policy case + onboarding/onboard-lib.sh onboard_write_policy(); onboard-lib-test.sh writer cases",
    "tests/policy-lib-test.sh: absent->defaults; each enum rejected/accepted; unknown key rejected; label-not-minted rejected (shimmed curl)": "tests/policy-lib-test.sh 27 checks passed",
    "docs/adr/0002-per-repo-policy-layer.md recording the rulings": "docs/adr/0002-per-repo-policy-layer.md",
    "Acceptance: preflight with no policy file prints 'policy: defaults (LANDING=push MERGE_AUTHORITY=human)'": "run-swarm.sh preflight else-branch; verified by simulation printing 'run-swarm: policy: defaults (LANDING=push MERGE_AUTHORITY=human)'",
    "Acceptance: LANDING=merge fails preflight with 'policy: LANDING must be push|pr (got merge)'": "policy-lib.sh _policy_check_structure emits exact string; tests/policy-lib-test.sh exact-message reject case; simulation confirmed",
    "Acceptance: no consumer-specific value in policy-lib.sh": "policy-lib.sh defaults are harness-generic (.sandcastle .forgejo via PP_PROTECTED_DIRS_DEFAULT, core labels); no product literal"
  },
  "summary": "Add the per-repo POLICY layer: swarm-policy.sh contract + policy-lib.sh loader/validator, wired into run-swarm preflight (validate-only) with an onboard.sh policy writer, ADR 0002, and offline tests.",
  "reason": "",
  "blockers": [],
  "no_code_change": ""
}
**close-report** for #12 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against main; closing. <details><summary>envelope</summary> ```json { "issue": 12, "status": "success", "commits": [ "5d401f4f29801e2164f86fcf7c1db32ca1325a5a" ], "changed_files": [ "STATUS.md", "docs/adr/0002-per-repo-policy-layer.md", "onboarding/onboard-lib.sh", "onboarding/onboard.sh", "onboarding/tests/onboard-lib-test.sh", "onboarding/vendor-exclude", "onboarding/vendor-manifest", "policy-lib.sh", "run-swarm.sh", "tests/policy-lib-test.sh" ], "tests": [ { "command": "bash tests/policy-lib-test.sh", "exit_code": 0 }, { "command": "bash onboarding/tests/onboard-lib-test.sh", "exit_code": 0 }, { "command": "bash onboarding/tests/vendor-manifest-coverage-test.sh", "exit_code": 0 }, { "command": "for t in tests/*.sh onboarding/tests/*.sh; do case \"$t\" in *fakebin*|*fixtures*) continue;; esac; bash \"$t\"; done", "exit_code": 0 } ], "criteria": { "policy-lib.sh: policy_load sources with defaults, exports SWARM_POLICY_*": "policy-lib.sh policy_load(); tests/policy-lib-test.sh absent-file default cases", "policy-lib.sh: policy_validate rejects unknown key / bad enum / label-not-minted with exit 2 naming the offending key, fail-LOUD before workers spawn": "policy-lib.sh policy_validate() + _policy_check_structure(); tests/policy-lib-test.sh reject cases (unknown key, both enums, unminted label via shimmed curl)", "policy-lib.sh: policy_human_labels emits name/trigger lines for renderers": "policy-lib.sh policy_human_labels(); tests/policy-lib-test.sh human_labels name<TAB>trigger cases", "run-swarm.sh calls policy_load+policy_validate in preflight (no behaviour change)": "run-swarm.sh preflight block after preflight self-tests; no knob consumed", "onboarding/vendor-manifest lists policy-lib.sh; vendor-exclude lists swarm-policy.sh": "onboarding/vendor-manifest +policy-lib.sh; onboarding/vendor-exclude +swarm-policy.sh; vendor-manifest-coverage-test PASS", "onboard.sh policy <out-file> [KEY=value ...] writes a validated file (pattern: e2e-tier)": "onboarding/onboard.sh policy case + onboarding/onboard-lib.sh onboard_write_policy(); onboard-lib-test.sh writer cases", "tests/policy-lib-test.sh: absent->defaults; each enum rejected/accepted; unknown key rejected; label-not-minted rejected (shimmed curl)": "tests/policy-lib-test.sh 27 checks passed", "docs/adr/0002-per-repo-policy-layer.md recording the rulings": "docs/adr/0002-per-repo-policy-layer.md", "Acceptance: preflight with no policy file prints 'policy: defaults (LANDING=push MERGE_AUTHORITY=human)'": "run-swarm.sh preflight else-branch; verified by simulation printing 'run-swarm: policy: defaults (LANDING=push MERGE_AUTHORITY=human)'", "Acceptance: LANDING=merge fails preflight with 'policy: LANDING must be push|pr (got merge)'": "policy-lib.sh _policy_check_structure emits exact string; tests/policy-lib-test.sh exact-message reject case; simulation confirmed", "Acceptance: no consumer-specific value in policy-lib.sh": "policy-lib.sh defaults are harness-generic (.sandcastle .forgejo via PP_PROTECTED_DIRS_DEFAULT, core labels); no product literal" }, "summary": "Add the per-repo POLICY layer: swarm-policy.sh contract + policy-lib.sh loader/validator, wired into run-swarm preflight (validate-only) with an onboard.sh policy writer, ADR 0002, and offline tests.", "reason": "", "blockers": [], "no_code_change": "" } ``` </details>
Author
Owner

Closed by hand (Ben's session) after review: 5d401f4 matches the contract — defaults reproduce today's behaviour, SWARM_POLICY_* exports, exit-2 validation naming the offending key, fixed trigger vocabulary, label-minted check via forgejo-lib.sh, preflight abort with a Mattermost notice, onboard.sh policy writer, ADR 0002, offline tests; no product literal. One doc nit for the next touch: ADR 0002's Context calls this "sub-project 3" — it is sub-project 1 of the arc (vendor was 2). Close PATCH failed for the machines-team permission gap like #19/#20/#11/#18.

Closed by hand (Ben's session) after review: `5d401f4` matches the contract — defaults reproduce today's behaviour, `SWARM_POLICY_*` exports, exit-2 validation naming the offending key, fixed trigger vocabulary, label-minted check via `forgejo-lib.sh`, preflight abort with a Mattermost notice, `onboard.sh policy` writer, ADR 0002, offline tests; no product literal. One doc nit for the next touch: ADR 0002's Context calls this "sub-project 3" — it is sub-project 1 of the arc (vendor was 2). Close PATCH failed for the `machines`-team permission gap like #19/#20/#11/#18.
ben closed this issue 2026-08-22 15:09:28 +00:00

Work complete and merged — but the tracker close is blocked by a permission gap (#20 / GOTCHAS 6)

The implementation for #12 is done, verified, and pushed to origin/main at commit 5d401f4f29801e2164f86fcf7c1db32ca1325a5a:

  • policy-lib.sh — policy_load / policy_validate / policy_human_labels (+ _policy_check_structure), fail-LOUD on unknown key / bad enum / malformed-or-unminted HUMAN_LABELS, exit 2 naming the offending token.
  • run-swarm.sh preflight calls policy_load+policy_validate (validate-only — no knob consumed yet); prints policy: defaults (LANDING=push MERGE_AUTHORITY=human) when absent, policy: LANDING must be push|pr (got merge) on a bad enum.
  • onboard.sh policy <out-file> [KEY=value ...] + onboard_write_policy (structure-validated writer).
  • onboarding/vendor-manifest +policy-lib.sh; vendor-exclude +swarm-policy.sh.
  • docs/adr/0002-per-repo-policy-layer.md; tests/policy-lib-test.sh (27 checks) + onboard-lib-test.sh writer cases. Full offline suite green.

The close-report gate ran, verified every claim against main, and posted its envelope (comment above).

Why this issue is still OPEN

The run's bot token has repo.code write (push + comments land) but not issue-metadata write: a direct probe returns HTTP 403 on both PATCH /issues/12 {state:closed} and POST /issues/12/labels. This is precisely the #20 / GOTCHAS 6 hazard. The gate's "closing" wording is stale because the vendored .sandcastle/close-report.sh sits at FACTORY_REF 1b7abc2, which predates #20's fix (close-first / verify-state==closed / report-reality / exit-non-zero-on-403). So the close silently 403'd and the old copy narrated success.

I cannot swap the labels to agent-blocked either (same 403), so this comment is the durable record.

What a human must do to re-arm / close

  1. Grant the machines team repo.issues (and repo.pulls) write on Matou/dev-factory (GOTCHAS 6).
  2. Re-vendor the factory self-copy to a ref ≥ #20 (5106a1b) so close-report.sh detects a failed close loudly: bash onboarding/onboard.sh vendor .sandcastle <sha>.
  3. Close #12 (the work is already merged; no code change is owed).
## Work complete and merged — but the tracker close is blocked by a permission gap (#20 / GOTCHAS 6) The implementation for #12 is **done, verified, and pushed to `origin/main`** at commit `5d401f4f29801e2164f86fcf7c1db32ca1325a5a`: - `policy-lib.sh` — `policy_load` / `policy_validate` / `policy_human_labels` (+ `_policy_check_structure`), fail-LOUD on unknown key / bad enum / malformed-or-unminted `HUMAN_LABELS`, exit 2 naming the offending token. - `run-swarm.sh` preflight calls `policy_load`+`policy_validate` (validate-only — **no knob consumed yet**); prints `policy: defaults (LANDING=push MERGE_AUTHORITY=human)` when absent, `policy: LANDING must be push|pr (got merge)` on a bad enum. - `onboard.sh policy <out-file> [KEY=value ...]` + `onboard_write_policy` (structure-validated writer). - `onboarding/vendor-manifest` +`policy-lib.sh`; `vendor-exclude` +`swarm-policy.sh`. - `docs/adr/0002-per-repo-policy-layer.md`; `tests/policy-lib-test.sh` (27 checks) + `onboard-lib-test.sh` writer cases. **Full offline suite green.** The close-report gate ran, **verified every claim against `main`, and posted its envelope** (comment above). ### Why this issue is still OPEN The run's bot token has `repo.code` write (push + comments land) but **not** issue-metadata write: a direct probe returns **HTTP 403 on both `PATCH /issues/12 {state:closed}` and `POST /issues/12/labels`**. This is precisely the **#20 / GOTCHAS 6** hazard. The gate's "closing" wording is stale because the vendored `.sandcastle/close-report.sh` sits at `FACTORY_REF 1b7abc2`, which **predates #20's fix** (close-first / verify-`state==closed` / report-reality / exit-non-zero-on-403). So the close silently 403'd and the old copy narrated success. I cannot swap the labels to `agent-blocked` either (same 403), so this comment is the durable record. ### What a human must do to re-arm / close 1. Grant the `machines` team `repo.issues` (and `repo.pulls`) write on `Matou/dev-factory` (GOTCHAS 6). 2. Re-vendor the factory self-copy to a ref ≥ #20 (`5106a1b`) so `close-report.sh` detects a failed close loudly: `bash onboarding/onboard.sh vendor .sandcastle <sha>`. 3. Close #12 (the work is already merged; no code change is owed).
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#12
No description provided.