@squadrules/mcp 5.13.6 → 5.13.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/cli/commands/export.d.ts +1 -0
  3. package/dist/cli/commands/export.d.ts.map +1 -1
  4. package/dist/cli/commands/export.js +23 -0
  5. package/dist/cli/commands/export.js.map +1 -1
  6. package/dist/embed-docs/mem/README.md +32 -14
  7. package/dist/embed-docs/mem/adapter-migration.md +59 -47
  8. package/dist/embed-docs/mem/author-adapter.md +112 -70
  9. package/dist/embed-docs/mem/bulk-insert-adapters-via-cli.md +59 -24
  10. package/dist/embed-docs/mem/challenge-type-guide.md +43 -13
  11. package/dist/embed-docs/mem/critic-loop-guide.md +38 -17
  12. package/dist/embed-docs/mem/critic-loop.md +24 -17
  13. package/dist/embed-docs/mem/protocol-linking-guide.md +10 -3
  14. package/dist/embed-docs/mem/refine-search.md +1 -1
  15. package/dist/resources/embedded-mcp-resources.js +12 -12
  16. package/dist/resources/embedded-mcp-resources.js.map +1 -1
  17. package/dist/tools/activate.d.ts.map +1 -1
  18. package/dist/tools/activate.js +7 -19
  19. package/dist/tools/activate.js.map +1 -1
  20. package/dist/tools/artifact-materialize-command.d.ts +22 -0
  21. package/dist/tools/artifact-materialize-command.d.ts.map +1 -0
  22. package/dist/tools/artifact-materialize-command.js +37 -0
  23. package/dist/tools/artifact-materialize-command.js.map +1 -0
  24. package/dist/tools/review-evidence-check.d.ts +2 -0
  25. package/dist/tools/review-evidence-check.d.ts.map +1 -1
  26. package/dist/tools/review-evidence-check.js +5 -3
  27. package/dist/tools/review-evidence-check.js.map +1 -1
  28. package/dist/ui/assets/{AccountPage-T4SMLR6H.js → AccountPage-Dj5D6Bhr.js} +1 -1
  29. package/dist/ui/assets/{index-C2EWn0mF.js → index-5bncLBJ8.js} +2 -2
  30. package/dist/ui/index.html +1 -1
  31. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  slug: author-adapter
3
- version: "5.13.6"
3
+ version: "5.13.8"
4
4
  title: Author Adapter (Create / Review / Refactor)
5
5
  ---
6
6
 
@@ -30,6 +30,10 @@ Supports three operations:
30
30
  - **update** — apply specific corrections to an existing adapter and
31
31
  save the correction. Also triggered by: edit, fix, modify, change, improve, patch, refactor.
32
32
 
33
+ A fourth lifecycle operation, **delete**, is not run here: follow the Delete flow
34
+ in `docs/adapter-authoring-guide.md` (export, check the slug is not a chain
35
+ dependency, call `delete`, verify it no longer resolves).
36
+
33
37
  **Run this adapter when the user says ANY of:**
34
38
  - "create a new SQUADRULES adapter" / "register a personal adapter"
35
39
  - "train adapter into personal" / "train a workflow"
@@ -45,6 +49,8 @@ Supports three operations:
45
49
  **Must Never:**
46
50
  - Run when the user only asked to execute an existing adapter.
47
51
  - Mutate adapters during a `review` operation.
52
+ - Review your own draft: the critic pass is delegated, never performed on the
53
+ drafting thread.
48
54
  - Optimise only for pretty wording; this adapter designs agent behaviour.
49
55
  - Treat "update", "edit", or "modify an existing adapter" as **create**.
50
56
 
@@ -60,16 +66,15 @@ Supports three operations:
60
66
  Before running authoring actions, verify dependency and auth readiness:
61
67
  1. Required MCP tools are available: `activate`, `forward`, `reward`, and the
62
68
  operation-dependent tool (`train`, `export`, or `tune`).
63
- 2. Required CLI tools for planned shell steps are installed and callable.
69
+ 2. A subagent facility is available in this host for the critic pass. Without it
70
+ this adapter cannot verify its own work: stop and report the blocker rather
71
+ than reviewing the draft yourself.
64
72
  3. Required auth/session state is valid for the target MCP server.
65
73
 
66
74
  If any check fails, attempt AI-assisted remediation automatically, then re-run
67
75
  preflight. Only hard-stop when a required tool or auth genuinely cannot be
68
- established autonomously.
69
-
70
- ```json
71
- {"contract":{"type":"shell","shell":{"cmd":"echo 'preflight: ok'","interpreter":"bash","timeout_seconds":10},"required":true}}
72
- ```
76
+ established autonomously. These are checks you perform, not gates: a failure here
77
+ produces a repair action, so no contract is spent on them.
73
78
 
74
79
  ## Resolve Intent Autonomously
75
80
 
@@ -86,10 +91,6 @@ Resolve the target from context without a confirmation prompt. Record the
86
91
  inferred operation and target, then continue. Escalate to the user only when
87
92
  the request is genuinely ambiguous and no reasonable default exists.
88
93
 
89
- ```json
90
- {"contract":{"type":"subagent","subagent":{"context":"Resolve the authoring operation (create/review/update) and target adapter from user context. Record the decision."},"required":true}}
91
- ```
92
-
93
94
  ## Gather Requirements
94
95
 
95
96
  ### For `create` — collect details for a new adapter
@@ -113,27 +114,62 @@ Export target adapter(s). Check: user-need fit, mode/step clarity,
113
114
  cross-reference completeness, handoff gaps, DRY violations, contract coverage,
114
115
  truth-first behaviour, activation pattern accuracy, structure compliance
115
116
  (first H2 Activation Patterns, last H2 Reward Signal, under 350 lines),
116
- sibling consistency, chained adapter families, critic-loop integration.
117
+ sibling consistency, chained adapter families, and whether every critic hop in
118
+ the audited adapters is a `subagent` contract rather than a `forward` contract.
117
119
 
118
120
  ### For `update` — identify the specific issue
119
121
 
120
122
  Export the target adapter, read the current markdown, identify the exact gap or
121
123
  error, and plan the minimal change.
122
124
 
123
- ```json
124
- {"contract":{"type":"subagent","subagent":{"context":"Gather requirements for the resolved operation: collect pattern/details for create, audit checklist for review, or identify the specific issue for update."},"required":true}}
125
+ ## Draft Markdown
126
+
127
+ ### Allocate the handoff paths first
128
+
129
+ The gates below read files that only exist if you created them. Resolve one hint
130
+ from the `squadrules_local_artifact_dir` field of the latest `activate` or
131
+ `forward` response (`project://<rel>` → this project root, `user://<rel>` → your
132
+ home or `$XDG_CONFIG_HOME`), export the absolute result as
133
+ `SQUADRULES_LOCAL_ARTIFACT_DIR`, then allocate collision-free paths for the
134
+ target slug:
135
+
136
+ ```bash
137
+ export SQUADRULES_LOCAL_ARTIFACT_DIR="<resolved absolute path>"
138
+ D="$SQUADRULES_LOCAL_ARTIFACT_DIR/author-adapter-$SLUG"
139
+ mkdir -p "$D"
140
+ export WORK_MANIFEST="$D/work-manifest.txt" # the critic's submission
141
+ export VERDICT_FILE="$D/verdict.txt" # the critic's verdict
142
+ export REVIEW_FINDINGS_FILE="$D/findings.md" # review operation only
125
143
  ```
126
144
 
127
- ## Draft Markdown
145
+ The server never names a path on your machine; you do.
128
146
 
129
147
  ### MCP / Local-Filesystem Boundary
130
148
 
131
149
  - A personal adapter stored in MCP **cannot** reference local files.
132
- - Only **system adapters** (bundled in the server) can chain to other system
133
- adapters via `forward`.
134
- - Personal adapters must be **self-contained**.
135
- - When a shell contract needs a reusable script, attach it as an **artifact**
136
- via `train` (with `mime`, `artifact_name`, `adapter_uri`).
150
+ - Any adapter — system or personal — may chain to another adapter with a
151
+ `forward` contract naming `squadrules://adapter/<slug>`; slugs are globally
152
+ unique, so resolution is deterministic.
153
+ - A personal adapter must still be **self-contained** in its instructions: it
154
+ cannot rely on files that only exist in one repository.
155
+ - When a `shell` check has more than one condition, parses JSON, or does not fit
156
+ one readable line, put it in a **gate script artifact** — it is stored with the
157
+ adapter and materialized at run time, not read from your local files; never
158
+ escape a program inline into `cmd`.
159
+ - Order: `train` the adapter markdown first, then `train` the script as an
160
+ artifact — an artifact attaches only to an adapter that already exists. Pin the
161
+ script's identity with a `# squadrules-artifact:` header, and pass
162
+ `force_update: true` on a re-train that matches it, so a fix updates
163
+ that artifact instead of adding a second one. Input fields and the refusal
164
+ message: the `train` tool description.
165
+ - The artifact train targets `squadrules://adapter/<slug>`, so pin the adapter's
166
+ slug with frontmatter `slug:` instead of guessing the slug `train` derived from
167
+ the title.
168
+ - Keep the contract one line: `interpreter: "bash"`, `cmd: python3
169
+ "$SQUADRULES_LOCAL_ARTIFACT_DIR/artifacts/<name>.py" --gate <name>`.
170
+ - Verify before shipping: `activate` the adapter and confirm
171
+ `linked_artifacts[].relative_path` is exactly the path `cmd` invokes. Run each
172
+ row's `materialize` command before the contract that needs it.
137
173
 
138
174
  ### Drafting rules (all operations)
139
175
 
@@ -151,81 +187,87 @@ escalation, and observable verification over narrative reassurance.
151
187
  **Slug convention:** Every adapter gets a short, unique, lowercase-hyphenated slug.
152
188
 
153
189
  **Structure:** H1 title, first H2 Activation Patterns, second H2 Preflight
154
- Dependencies, middle H2s one per step with JSON contract block, last H2 Reward
190
+ Dependencies, middle H2s one per stage with JSON contract block, last H2 Reward
155
191
  Signal. Frontmatter: `slug` (required), `version` (optional), `chain_root`
156
192
  (required for mid-chain adapters).
157
193
 
158
- **Challenge types:** Load `challenge-type-guide` for decision rules and JSON
159
- formats (`forward` with `squadrules://adapter/challenge-type-guide`).
194
+ **Contracts:** One per adapter is the default; a second is justified only at a
195
+ boundary that is hard to roll back. Load `challenge-type-guide` for decision
196
+ rules and JSON formats (`forward` with
197
+ `squadrules://adapter/challenge-type-guide`).
160
198
 
161
199
  **Critic-loop and mutation gates:** Load `critic-loop-guide` for placement,
162
- FAIL gate, and solution check rules (`forward` with
200
+ the FAIL gate, and the work-submission rules (`forward` with
163
201
  `squadrules://adapter/critic-loop-guide`).
164
202
 
165
203
  For `create`: draft the full adapter markdown.
166
204
  For `review`: write a structured gap report to `$REVIEW_FINDINGS_FILE`.
167
205
  For `update`: apply the identified change and show a diff-style summary.
168
206
 
169
- ```json
170
- {"contract":{"type":"subagent","subagent":{"context":"Draft the adapter markdown (create), findings report (review), or corrected markdown (update) following all shared drafting rules."},"required":true}}
171
- ```
172
-
173
207
  ## Critic-Loop Review (create and update only)
174
208
 
175
- For `create` and `update`: run critic-loop against the drafted markdown. This is
176
- an autonomous quality loop — the agent owns content, the critic owns quality, and
177
- no human approval is requested at any point.
209
+ For `create` and `update`: have the draft reviewed. This is an autonomous quality
210
+ loop — the agent owns content, the critic owns quality, and no human approval is
211
+ requested at any point. The critic must not be you: you wrote the draft, so your
212
+ own re-reading cannot detect what you did not intend to write.
178
213
 
179
- 1. Invoke critic-loop via `forward` with `squadrules://adapter/critic-loop`.
180
- Submit the drafted markdown as a `file_set` work submission — write
181
- `kind: file_set`, `root: <directory of the draft>`, then the drafted file
182
- under `items:` into the handoff pointed to by `$WORK_MANIFEST` — with the
183
- slug as `calling_protocol_slug` and "structural compliance and agent
184
- behaviour" as `verification_target`.
185
- 2. Run the FAIL gate shell contract on the verdict file:
214
+ Write the submission handoff to `$WORK_MANIFEST` as flat keys — `kind: file_set`,
215
+ `root: <directory of the draft>`, then `items:` with the drafted file's path on
216
+ one line — and delegate the review to a subagent. Delegate it now; do not audit
217
+ the draft on this thread first.
186
218
 
187
219
  ```json
188
- {"contract":{"type":"shell","shell":{"cmd":"head -1 \"$VERDICT_FILE\" | grep -qi '^PASS$'","interpreter":"bash","timeout_seconds":5},"required":true}}
220
+ {"contract":{"type":"subagent","subagent":{"context":"Run the critic on the drafted adapter markdown and return its actual report. Call the forward tool with uri squadrules://adapter/critic-loop and submit: work from $WORK_MANIFEST (kind file_set, the drafted file), the original requirement list, calling_protocol_slug author-adapter, verification_target 'structural compliance and agent behaviour', context.verdict_file $VERDICT_FILE, context.iteration and context.max_iterations (8). Follow critic-loop to its end, let it write $VERDICT_FILE, and report back its findings plus the verdict file's first two lines. Do not review the draft yourself and do not re-delegate the review.","mcp":[{"tool_name":"forward","arguments":{"uri":"squadrules://adapter/critic-loop"}}]},"required":true}}
189
221
  ```
190
222
 
191
- 3. If FAIL: address every finding, then re-invoke critic-loop and re-run the FAIL
192
- gate. **Loop automatically until the verdict is PASS** — do not proceed and do
193
- not ask the user whether to continue.
194
- 4. If PASS: capture the verdict file path for the `review_evidence` field
195
- in the `train` call below.
196
-
197
- For `review`: skip this step (read-only operation).
198
-
199
- ## FinaliseOperation
200
-
201
- No human approval step. The critic-loop PASS verdict is the sole quality gate.
202
-
203
- For `create`: call `train` with the drafted markdown and `review_evidence`
204
- from the critic-loop step. Use `force_update: false` unless overwrite was
205
- explicitly requested.
206
-
207
- For `review`: do not call `train`. Save the findings report only if requested.
208
-
209
- For `update`: use `tune` with the existing adapter URI, corrected content, and
210
- `review_evidence`. Use `train` with `force_update: true` only for a required
211
- structural replacement (changing identity/H1 mapping or layer count). Update the
212
- corresponding repository source when the adapter is repo-managed; make repository
213
- edits in the task's isolated worktree.
214
-
215
- Report the outcome: adapter URI(s) for create/update, or findings summary for
216
- review.
223
+ ## Save After a PASS Verdict
224
+
225
+ Read the verdict the critic left behind and act on it, then save.
226
+
227
+ 1. Run the gate below. `FAIL` → address **every** finding in the report, then
228
+ start a fresh critic pass the same way (a subagent delegating
229
+ `squadrules://adapter/critic-loop` with the corrected draft, the same
230
+ requirements, and `iteration` incremented) and re-run this gate. Loop
231
+ automatically; do not ask the user whether to continue.
232
+ 2. The loop is bounded by `max_iterations`. When `iteration` exceeds it, the
233
+ critic returns `failure_class: iteration_ceiling`: **stop looping**, report the
234
+ unresolved findings, and do not save an unreviewed draft as if it passed.
235
+ 3. On `PASS`, capture the verdict file path and save:
236
+ - `create` — call `train` with the drafted markdown and `review_evidence`
237
+ (verdict file path, exit code, stdout). Use `force_update: false` unless an
238
+ overwrite was explicitly requested.
239
+ - `update` — call `tune` with the existing adapter URI, corrected content, and
240
+ `review_evidence`. Use `train` with `force_update: true` only for a required
241
+ structural replacement (changing identity/H1 mapping or layer count). Update
242
+ the corresponding repository source when the adapter is repo-managed, and
243
+ make repository edits in the task's isolated worktree.
244
+ - `review` — do not call `train`; the operation is read-only and this gate is
245
+ satisfied by the findings report at `$REVIEW_FINDINGS_FILE`.
246
+ 4. Read the stored adapter back (`export` it, or the CLI on a local transport)
247
+ and compare it against what you intended to save; report the URI and any
248
+ difference. This is the run's completion criterion, not a gate: a remote
249
+ store cannot be observed from a shell command, so no contract asserts it.
217
250
 
218
251
  ```json
219
- {"contract":{"type":"comment","comment":{"min_length":80},"required":true}}
252
+ {"contract":{"type":"shell","shell":{"cmd":"head -1 \"$VERDICT_FILE\" | grep -qi '^PASS$'","interpreter":"bash","timeout_seconds":5},"required":true}}
220
253
  ```
221
254
 
222
255
  ## Reward Signal
223
256
 
224
257
  Adapter complete when:
225
- - `create` — adapter(s) stored via `train` (with review_evidence) and URI(s) reported
226
- - `review` — findings report delivered
227
- - `update` — corrected adapter saved via `tune` (or required structural replacement),
228
- read back and verified; repo-managed source updated in the task worktree
258
+ - `create` — a delegated critic returned `PASS`, the adapter is stored via `train`
259
+ with that `review_evidence`, its URI is reported, and the stored copy was read
260
+ back
261
+ - `review` — findings report delivered from `$REVIEW_FINDINGS_FILE`
262
+ - `update` — a delegated critic returned `PASS` on the changed parts, the corrected
263
+ adapter is saved via `tune` (or a required structural replacement), read back and
264
+ reported; repo-managed source updated in the task worktree
265
+
266
+ What this proves: a separate context ran `critic-loop` over the draft and left a
267
+ verdict file that reads `PASS`, and the store accepted that evidence. What it does
268
+ not prove: that the report came from that context, or that the verdict is bound to
269
+ the reviewed content — server-issued review receipts would be needed for that.
270
+ Report the outcome as it stands; a passing gate is not a guarantee of correctness.
229
271
 
230
272
  A successful result means the resulting SQUADRULES adapter is more truthful,
231
273
  step-aware, agent-readable, and aligned with human–AI harmony.
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  slug: bulk-insert-adapters-via-cli
3
- version: "5.13.6"
3
+ version: "5.13.8"
4
4
  title: Bulk Insert Adapters via SQUADRULES CLI
5
5
  ---
6
6
 
@@ -59,12 +59,11 @@ Verify before execution:
59
59
  2. Authentication is valid (`squadrules token` returns a token without error).
60
60
  3. Target directory path exists and contains at least one `.md` file.
61
61
  4. If a space is specified, confirm it exists via `squadrules spaces`.
62
+ 5. A subagent facility is available for the review hop below. Without it the
63
+ store will refuse the upload; report the blocker, do not skip the review.
62
64
 
63
- If any check fails, stop and report the issue with remediation guidance.
64
-
65
- ```json
66
- {"contract":{"type":"shell","shell":{"cmd":"squadrules --version && squadrules token > /dev/null 2>&1 && echo 'auth: ok'","interpreter":"bash","timeout_seconds":15},"required":true}}
67
- ```
65
+ If any check fails, stop and report the issue with remediation guidance. These
66
+ checks are performed, not gated — the gate sits at the write.
68
67
 
69
68
  ## Resolve Scope and Validate
70
69
 
@@ -85,31 +84,54 @@ Validate each `.md` file against SQUADRULES adapter requirements:
85
84
  Skip invalid files, train the valid subset, and document every skipped file with
86
85
  its validation error and a suggested fix. Do not stop to ask the user.
87
86
 
87
+ ## Review the Set Before Uploading
88
+
89
+ `train` refuses a markdown adapter without critic-loop `PASS` evidence, so an
90
+ unreviewed batch uploads nothing. Allocate the handoff paths under
91
+ `$SQUADRULES_LOCAL_ARTIFACT_DIR` — resolve a hint from the
92
+ `squadrules_local_artifact_dir` field of the latest `activate`/`forward` response
93
+ and export it; the server never names a path on your machine. You need
94
+ `$WORK_MANIFEST`, `$VERDICT_FILE`, and `$BULK_LOG_FILE`. List the valid files in
95
+ `$WORK_MANIFEST` as flat keys (`kind: file_set`, `root: <source directory>`, then
96
+ `items:` with one file path per line) and delegate the review:
97
+
88
98
  ```json
89
- {"contract":{"type":"shell","shell":{"cmd":"test -d \"$SOURCE_DIR\" && find \"$SOURCE_DIR\" -name '*.md' | head -1 | grep -q .","interpreter":"bash","timeout_seconds":10},"required":true}}
99
+ {"contract":{"type":"subagent","subagent":{"context":"Run the critic over the adapter files listed in $WORK_MANIFEST and return its actual report. Call the forward tool with uri squadrules://adapter/critic-loop, submitting the file list as work kind file_set with the source directory as root, the requirement list above as requirements, and context.verdict_file $VERDICT_FILE with context.iteration and context.max_iterations (8). Do not review the files yourself.","mcp":[{"tool_name":"forward","arguments":{"uri":"squadrules://adapter/critic-loop"}}]},"required":true}}
90
100
  ```
91
101
 
92
- ## Execute Bulk Train
102
+ ## Prove the Write Boundary
93
103
 
94
- Run the batch train operation using the SQUADRULES CLI:
104
+ A directory batch overwrites adapters in a shared space: hard to roll back, so
105
+ one gate sits in front of it and one behind it. Run the gate below **before** any
106
+ `train` command. If it exits non-zero, nothing has been uploaded — fix the named
107
+ condition (install the CLI, re-authenticate, correct `$SOURCE_DIR`, or obtain a
108
+ `PASS` verdict), then run it again.
95
109
 
96
- ```
97
- squadrules train <directory> --recursive --model <model> --space <space> [--force]
110
+ ```json
111
+ {"contract":{"type":"shell","shell":{"cmd":"squadrules --version && squadrules token > /dev/null && test -d \"$SOURCE_DIR\" && find \"$SOURCE_DIR\" -name '*.md' | head -1 | grep -q . && head -1 \"$VERDICT_FILE\" | grep -qi '^PASS$'","interpreter":"bash","timeout_seconds":30},"required":true}}
98
112
  ```
99
113
 
100
- If the directory contains files that should NOT be trained (README, reference
101
- docs), either train file-by-file for the valid subset, or move non-adapter files
102
- out before running `--recursive`.
114
+ ## Run the Batch and Report
103
115
 
104
- Capture stdout and stderr. The CLI reports per-file status.
116
+ Run the batch and keep its report. The CLI reads review evidence from the
117
+ `SQUADRULES_REVIEW_EVIDENCE` environment variable as one JSON object
118
+ (`verdict_file`, `exit_code`, `stdout`) and reuses it for every file in a
119
+ directory batch. Therefore:
105
120
 
106
- ```json
107
- {"contract":{"type":"shell","shell":{"cmd":"squadrules train \"$SOURCE_DIR\" --recursive --model \"$MODEL_ID\" --space \"$TARGET_SPACE\"","interpreter":"bash","timeout_seconds":120},"required":true}}
108
- ```
121
+ - If the critic reviewed the set as one submission, export that verdict once and
122
+ train the directory, capturing its report:
109
123
 
110
- ## Report Results
124
+ ```
125
+ squadrules train <directory> --recursive --model <model> --space <space> [--force] 2>&1 | tee "$BULK_LOG_FILE"
126
+ ```
111
127
 
112
- Summarise the batch outcome:
128
+ - If the critic reviewed files individually, train file-by-file and re-export
129
+ `SQUADRULES_REVIEW_EVIDENCE` for each file, so no adapter is stored under
130
+ another adapter's verdict; append every run to `$BULK_LOG_FILE`. Move
131
+ non-adapter files (README, reference docs) out of the directory before using
132
+ `--recursive` — the batch skips `README.md` by name and nothing else.
133
+
134
+ Summarise the outcome for the user:
113
135
 
114
136
  | Metric | Value |
115
137
  |--------|-------|
@@ -118,20 +140,33 @@ Summarise the batch outcome:
118
140
  | Failed | N |
119
141
  | Skipped (invalid) | N |
120
142
 
121
- For each failure, report: file path, error message, suggested fix.
122
- If all succeeded, confirm adapter URIs are accessible via `squadrules spaces`.
143
+ For each failure, report: file path, error message, suggested fix. If all
144
+ succeeded, confirm the adapter URIs are accessible via `squadrules spaces`.
145
+ A `REVIEW_EVIDENCE_REQUIRED` failure means the review did not cover that file:
146
+ review it, then retry; never store an unreviewed adapter to clear the error.
147
+
148
+ The batch prints one summary line (`<n> ok, <m> failed (of <total>)`) and one
149
+ `ERR <path>: <error>` line per failure. The gate below reads that captured report
150
+ instead of trusting a recollection of it, so the write is verified by what the
151
+ CLI actually stored:
123
152
 
124
153
  ```json
125
- {"contract":{"type":"comment","comment":{"min_length":80},"required":true}}
154
+ {"contract":{"type":"shell","shell":{"cmd":"test -s \"$BULK_LOG_FILE\" && grep -qE '[1-9][0-9]* ok, 0 failed' \"$BULK_LOG_FILE\" && ! grep -q 'ERR ' \"$BULK_LOG_FILE\"","interpreter":"bash","timeout_seconds":10},"required":true}}
126
155
  ```
127
156
 
128
157
  ## Reward Signal
129
158
 
130
159
  Workflow complete when:
160
+ - A delegated critic returned `PASS` over the files being uploaded.
131
161
  - All valid adapter files in the target directory have been trained to the
132
- specified space.
162
+ specified space, and the captured batch report shows `0 failed`.
133
163
  - Per-file results have been reported.
134
164
  - Any failures have been documented with remediation guidance.
135
165
 
166
+ What this proves: the store accepted the uploads and the CLI reported no failures
167
+ in the captured output. What it does not prove: that the review covered each file
168
+ individually when one verdict served a directory batch, or that the verdict came
169
+ from the delegated context rather than this one.
170
+
136
171
  A successful bulk insert means the user's local adapter library is now
137
172
  registered in SQUADRULES and available for activation by AI agents.
@@ -1,5 +1,5 @@
1
1
  ---
2
- version: "5.13.6"
2
+ version: "5.13.8"
3
3
  slug: challenge-type-guide
4
4
  title: Challenge Type Selection Guide
5
5
  ---
@@ -135,7 +135,7 @@ Every solution follows the same envelope:
135
135
 
136
136
  **forward solution**
137
137
  ```json
138
- {"type":"forward","outcome":"success","evidence":{"target":"squadrules://adapter/critic-loop","success":true}}
138
+ {"type":"forward","outcome":"success","evidence":{"target":"squadrules://adapter/implement-terraform","success":true}}
139
139
  ```
140
140
 
141
141
  **subagent solution**
@@ -168,6 +168,12 @@ Every solution follows the same envelope:
168
168
  data formats, or complex string processing, use `python3`. Use `node` only when
169
169
  the check requires the Node.js runtime.
170
170
 
171
+ `cmd` is always program text: `python3` / `node` receive it as `-c` / `-e` source,
172
+ so these rows describe short inline programs. Once a check needs more than one
173
+ readable line, stop choosing an interpreter and ship the script as an artifact,
174
+ invoked through a `bash` wrapper — see
175
+ [Artifacts for Shell Contracts](#artifacts-for-shell-contracts).
176
+
171
177
  ## Security and Working Directory Rules
172
178
 
173
179
  Use `$SQUADRULES_LOCAL_ARTIFACT_DIR` as the base directory for local handoff
@@ -230,7 +236,8 @@ external worktrees, or open the worktree as a separate project window.
230
236
  **Write-then-grep** — subagent writes a verdict file, main agent checks line 1.
231
237
 
232
238
  **Phase-batch with critic** — batch related items, verify hard artifacts with
233
- shell, then call `critic-loop` for adversarial review.
239
+ shell, then delegate `critic-loop` for adversarial review from a `subagent`
240
+ contract. The review must not run on the thread that produced the work.
234
241
 
235
242
  **Chain-link via forward + slug** — layer N's contract requires `forward` with a
236
243
  specific adapter slug. Use when the adapter exceeds 350 lines or needs
@@ -241,16 +248,38 @@ Example ```json
241
248
 
242
249
  ## Artifacts for Shell Contracts
243
250
 
244
- When a shell contract needs a reusable script, **attach it as an artifact**
245
- rather than inlining it in the contract JSON:
246
-
247
- 1. Write the script file.
248
- 2. `train` with `mime: "text/x-python"`, `artifact_name: "isolation-guard.py"`,
249
- `adapter_uri: "squadrules://adapter/my-adapter"`, and the script content.
250
- 3. In the shell contract, reference it via `export` with
251
- `squadrules://artifact/{uuid}` at execution time.
252
-
253
- This keeps adapter markdown clean and makes scripts independently versionable.
251
+ A gate that needs more than one short command belongs in a **script shipped with
252
+ the adapter**, not in the contract's `cmd`. An artifact keeps the contract
253
+ readable, makes the script independently versionable, and lets one dispatcher
254
+ serve many gates.
255
+
256
+ **Author it in this order** — an artifact attaches to an adapter that already
257
+ exists:
258
+
259
+ 1. Draft the markdown. The contract stays one line and invokes the script by its
260
+ artifact path. `interpreter` names the wrapper that runs that line, because
261
+ `cmd` is program text for every interpreter:
262
+ Example ```json
263
+ {"contract":{"type":"shell","shell":{"cmd":"python3 \"$SQUADRULES_LOCAL_ARTIFACT_DIR/artifacts/my-gates.py\" --gate preflight","interpreter":"bash","timeout_seconds":60},"required":true}}
264
+ ```
265
+ 2. `train` the markdown.
266
+ 3. `train` the script with the `mime` matching its extension (`text/x-python`,
267
+ `text/x-shellscript`, `text/javascript`), `artifact_name`, and that adapter's
268
+ `adapter_uri`. Add `relative_path` only when the default
269
+ `artifacts/<artifact_name>` is not the path you want; the identity header and
270
+ slug rules are in the `train` description.
271
+ 4. Verify before you run it: `activate` the adapter and check that
272
+ `linked_artifacts[].relative_path` equals the path the contract invokes. A
273
+ mismatch surfaces only when the gate runs.
274
+
275
+ **At execution time:** run the `materialize` command carried by that
276
+ `linked_artifacts[]` row — it writes the payload under
277
+ `$SQUADRULES_LOCAL_ARTIFACT_DIR`, verifies the digest, and marks the file
278
+ executable. `forward` responses do not repeat the list, so materialize during the
279
+ run's first step.
280
+
281
+ **One script, many gates:** `--gate <name>` on a single dispatcher replaces one
282
+ inlined program per step. Change the gate once, not seven times.
254
283
 
255
284
  Example ```json
256
285
  {"contract":{"type":"comment","comment":{"min_length":30},"required":true}}
@@ -268,3 +297,4 @@ The agent can now:
268
297
  5. use forward contracts for chain links
269
298
  6. use subagent contracts for delegated work
270
299
  7. apply stronger verification patterns instead of weak comment checks
300
+ 8. ship a multi-step gate as an adapter artifact and keep its contract one line
@@ -1,5 +1,5 @@
1
1
  ---
2
- version: "5.13.6"
2
+ version: "5.13.8"
3
3
  slug: critic-loop-guide
4
4
  title: Critic Loop Integration and Mutation Gate Guide
5
5
  ---
@@ -118,21 +118,34 @@ Example ```json
118
118
  {"contract":{"type":"shell","shell":{"cmd":"test \"$(git rev-parse --abbrev-ref HEAD)\" != main && git rev-parse --git-common-dir | grep -q worktrees","interpreter":"bash","timeout_seconds":5},"required":true}}
119
119
  ```
120
120
 
121
- ## How to Chain Critic-Loop into an Adapter
121
+ ## How to Invoke Critic-Loop from an Adapter
122
122
 
123
- Use `forward` + slug to invoke `critic-loop` at phase boundaries. The standard
124
- pattern is a `forward` contract naming the `critic-loop` slug:
123
+ Reach `critic-loop` at a phase boundary with a **`subagent` contract**, never a
124
+ `forward` contract. A `forward` hop keeps the review on the thread that produced
125
+ the work: the same agent reads the critic's instructions, performs them, and
126
+ writes the verdict it is then gated on. The hop names the call the subagent must
127
+ really make, so it cannot substitute an improvised review:
125
128
 
126
129
  ### After a planning phase
127
130
 
128
131
  Example ```json
129
- {"contract":{"type":"forward","forward":{"target":"squadrules://adapter/critic-loop"},"required":true}}
132
+ {"contract":{"type":"subagent","subagent":{"context":"Run the critic on the plan and return its actual report. Call the forward tool with uri squadrules://adapter/critic-loop, submit the work from $WORK_MANIFEST with the requirement list, and let the critic write $VERDICT_FILE. Do not review it yourself.","mcp":[{"tool_name":"forward","arguments":{"uri":"squadrules://adapter/critic-loop"}}]},"required":true}}
130
133
  ```
131
134
 
132
135
  ### After an implementation phase
133
136
 
134
- Use the same contract. The critic-loop adapter receives the calling protocol's
135
- context and independently verifies the work.
137
+ Use the same contract shape. The subagent receives the calling protocol's
138
+ context, drives `critic-loop` to its end in its own context, and returns only its
139
+ report — the tool transcript never re-enters the caller's reasoning.
140
+
141
+ `forward` + slug stays correct for **chain continuation** — handing work to the
142
+ next stage of the same effort, or to a reusable sub-adapter that is not auditing
143
+ the caller. The test is not "does it link to an adapter" but "is the linked
144
+ adapter the caller's auditor". Separation is the point: a review the audited agent
145
+ runs on itself restates its work instead of checking it.
146
+
147
+ A host with no subagent facility cannot satisfy this hop. Report that as a
148
+ blocker; do not fall back to reviewing your own work.
136
149
 
137
150
  ### What to submit for review
138
151
 
@@ -174,7 +187,8 @@ surfaces the unresolved findings; it prevents a weak agent from thrashing foreve
174
187
 
175
188
  ### Verdict handoff pattern
176
189
 
177
- Critic-loop writes a verdict file. The calling adapter reads it:
190
+ Critic-loop writes a verdict file in the delegated run. The calling adapter reads
191
+ it:
178
192
 
179
193
  1. Critic-loop writes `$VERDICT_FILE` with `PASS`/`FAIL` on line 1.
180
194
  2. Calling adapter's next layer reads the verdict file.
@@ -188,7 +202,7 @@ review. The correct action is to fix the findings and re-invoke critic-loop.
188
202
 
189
203
  ### FAIL gate contract (required after every critic-loop invocation)
190
204
 
191
- Every adapter that chains critic-loop **must** include a shell contract that
205
+ Every adapter that invokes critic-loop **must** include a shell contract that
192
206
  fails when the verdict is not PASS. This is the mechanical guard that prevents
193
207
  weaker agents from proceeding after FAIL:
194
208
 
@@ -250,24 +264,30 @@ confirmation gates for remote mutations.
250
264
  1. **Loop critic-loop until PASS at every major phase boundary** — after planning,
251
265
  after implementation, after validation — feeding it the requirement list and
252
266
  bounding it with an iteration ceiling.
253
- 2. **Do NOT add critic-loop between every layer** — it is a phase-level review,
267
+ 2. **Invoke the critic from a separate context** — a `subagent` contract, never a
268
+ `forward` contract on the thread that produced the work.
269
+ 3. **Do NOT add critic-loop between every layer** — it is a phase-level review,
254
270
  not a step-level check.
255
- 3. **Put one objective proof at each irreversibility boundary** — remote mutation
271
+ 4. **Put one objective proof at each irreversibility boundary** — remote mutation
256
272
  or the local precondition that guards it: pre-mutation readiness +
257
273
  post-mutation verification, never a human confirmation prompt.
258
- 4. **Batch reversible, checkable steps into one aggregate strict-conjunction
274
+ 5. **Batch reversible, checkable steps into one aggregate strict-conjunction
259
275
  proof** instead of one proof per step; never let it degrade to `echo "done"`.
260
- 5. **Never replace a boundary proof with critic-loop** — critic-loop reviews truth
276
+ 6. **Never replace a boundary proof with critic-loop** — critic-loop reviews truth
261
277
  after the fact; it does not block an irreversible step.
262
- 6. **Never add a proof for purely local, reversible operations** — critic-loop
278
+ 7. **Never add a proof for purely local, reversible operations** — critic-loop
263
279
  provides sufficient review.
280
+ 8. **Never gate what you cannot observe** — if no shell command can see the
281
+ outcome, state it as an instruction with a completion criterion instead of
282
+ inventing a command that prints `ok`.
264
283
 
265
284
  ## Adapter Authoring Checklist
266
285
 
267
286
  When drafting a new adapter, apply this checklist:
268
287
 
269
288
  1. Identify all phase boundaries in the adapter flow.
270
- 2. Add a `critic-loop` chain link at each boundary.
289
+ 2. Add a `subagent` critic hop at each boundary — never a `forward` hop to
290
+ `critic-loop`.
271
291
  3. Identify all steps that perform irreversible remote mutations.
272
292
  4. Add objective solution checks (pre-mutation readiness + post-action
273
293
  verification) for each — no `user_input` human-confirmation gate.
@@ -275,7 +295,8 @@ When drafting a new adapter, apply this checklist:
275
295
  6. Verify that the critic-loop verdict handoff pattern is present.
276
296
  7. Verify that a FAIL gate shell contract follows every critic-loop invocation.
277
297
  8. Verify that `train`/`tune` calls include `review_evidence` from the critic.
278
- 9. Ensure the adapter's Reward Signal describes what the critic protects.
298
+ 9. Ensure the adapter's Reward Signal describes what the critic protects, and
299
+ states what the verdict does **not** prove.
279
300
 
280
301
  Example ```json
281
302
  {"contract":{"type":"comment","comment":{"min_length":80},"required":true}}
@@ -288,6 +309,6 @@ Only reachable after all prior steps are solved.
288
309
  The agent can now:
289
310
  1. Decide when to use critic-loop versus solution checks
290
311
  2. Identify irreversible remote mutations that need hard gates
291
- 3. Chain critic-loop into adapters at the correct phase boundaries
312
+ 3. Invoke critic-loop from a delegated subagent at the correct phase boundaries
292
313
  4. Apply the mutation gate pattern for remote-system actions
293
314
  5. Avoid unnecessary solution checks for local or read-only operations