@bonesofspring/ai-rules 0.2.36 → 0.2.37
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.
- package/package.json +4 -1
- package/presets/_shared/hooks/README.md +137 -0
- package/presets/_shared/hooks/chain-team-phases.sh.tmpl +1288 -0
- package/presets/claude/android-kotlin/MCP.md +2 -2
- package/presets/claude/android-kotlin/hooks/chain-team-phases.sh +171 -10
- package/presets/claude/android-kotlin/mcp.json +1 -1
- package/presets/claude/android-kotlin/rules/tooling-and-review/agent-team-orchestrator.md +6 -153
- package/presets/claude/android-kotlin/team/README.md +2 -6
- package/presets/claude/android-kotlin/team/fixtures/artifact-manifest.example.json +1 -0
- package/presets/claude/go/MCP.md +2 -2
- package/presets/claude/go/hooks/chain-team-phases.sh +183 -16
- package/presets/claude/go/mcp.json +1 -1
- package/presets/claude/go/rules/tooling-and-review/agent-team-orchestrator.md +6 -11
- package/presets/claude/go/team/README.md +2 -6
- package/presets/claude/ios-swift/MCP.md +2 -2
- package/presets/claude/ios-swift/hooks/chain-team-phases.sh +178 -17
- package/presets/claude/ios-swift/mcp.json +1 -1
- package/presets/claude/ios-swift/rules/tooling-and-review/agent-team-orchestrator.md +6 -153
- package/presets/claude/ios-swift/team/README.md +2 -6
- package/presets/claude/ios-swift/team/fixtures/artifact-manifest.example.json +1 -0
- package/presets/claude/java/hooks/chain-team-phases.sh +183 -16
- package/presets/claude/java/rules/tooling-and-review/agent-team-orchestrator.md +6 -28
- package/presets/claude/java/team/README.md +2 -6
- package/presets/claude/mcp-ts/hooks/chain-team-phases.sh +182 -13
- package/presets/claude/mcp-ts/rules/tooling-and-review/agent-team-orchestrator.md +6 -14
- package/presets/claude/mcp-ts/team/README.md +2 -6
- package/presets/claude/next/MCP.md +2 -2
- package/presets/claude/next/hooks/chain-team-phases.sh +102 -6
- package/presets/claude/next/mcp.json +1 -1
- package/presets/claude/next/rules/tooling-and-review/agent-team-orchestrator.md +6 -226
- package/presets/claude/next/team/README.md +2 -6
- package/presets/claude/next/team/fixtures/artifact-manifest.example.json +1 -0
- package/presets/claude/nuxt/MCP.md +2 -2
- package/presets/claude/nuxt/hooks/chain-team-phases.sh +148 -7
- package/presets/claude/nuxt/mcp.json +1 -1
- package/presets/claude/nuxt/rules/tooling-and-review/agent-team-orchestrator.md +6 -223
- package/presets/claude/nuxt/team/README.md +2 -6
- package/presets/claude/nuxt/team/fixtures/artifact-manifest.example.json +1 -0
- package/presets/claude/php-hexagonal/hooks/chain-team-phases.sh +183 -16
- package/presets/claude/php-hexagonal/rules/tooling-and-review/agent-team-orchestrator.md +6 -28
- package/presets/claude/php-hexagonal/team/README.md +2 -6
- package/presets/claude/php-laravel/hooks/chain-team-phases.sh +183 -16
- package/presets/claude/php-laravel/rules/tooling-and-review/agent-team-orchestrator.md +6 -29
- package/presets/claude/php-laravel/team/README.md +2 -6
- package/presets/claude/svelte/MCP.md +2 -2
- package/presets/claude/svelte/hooks/chain-team-phases.sh +148 -7
- package/presets/claude/svelte/mcp.json +1 -1
- package/presets/claude/svelte/rules/tooling-and-review/agent-team-orchestrator.md +6 -223
- package/presets/claude/svelte/team/README.md +2 -6
- package/presets/claude/svelte/team/fixtures/artifact-manifest.example.json +1 -0
- package/presets/cursor/android-kotlin/MCP.md +2 -2
- package/presets/cursor/android-kotlin/hooks/chain-team-phases.sh +150 -7
- package/presets/cursor/android-kotlin/mcp.json +1 -1
- package/presets/cursor/android-kotlin/team/README.md +2 -0
- package/presets/cursor/android-kotlin/team/fixtures/artifact-manifest.example.json +1 -0
- package/presets/cursor/go/MCP.md +2 -2
- package/presets/cursor/go/hooks/chain-team-phases.sh +175 -8
- package/presets/cursor/go/mcp.json +1 -1
- package/presets/cursor/go/team/README.md +2 -0
- package/presets/cursor/ios-swift/MCP.md +2 -2
- package/presets/cursor/ios-swift/hooks/chain-team-phases.sh +150 -7
- package/presets/cursor/ios-swift/mcp.json +1 -1
- package/presets/cursor/ios-swift/team/README.md +2 -0
- package/presets/cursor/ios-swift/team/fixtures/artifact-manifest.example.json +1 -0
- package/presets/cursor/java/hooks/chain-team-phases.sh +175 -8
- package/presets/cursor/java/team/README.md +2 -0
- package/presets/cursor/mcp-ts/hooks/chain-team-phases.sh +179 -10
- package/presets/cursor/mcp-ts/team/README.md +2 -0
- package/presets/cursor/next/MCP.md +2 -2
- package/presets/cursor/next/hooks/chain-team-phases.sh +99 -5
- package/presets/cursor/next/mcp.json +1 -1
- package/presets/cursor/next/team/README.md +2 -0
- package/presets/cursor/next/team/fixtures/artifact-manifest.example.json +1 -0
- package/presets/cursor/nuxt/MCP.md +2 -2
- package/presets/cursor/nuxt/hooks/chain-team-phases.sh +145 -6
- package/presets/cursor/nuxt/mcp.json +1 -1
- package/presets/cursor/nuxt/team/README.md +2 -0
- package/presets/cursor/nuxt/team/fixtures/artifact-manifest.example.json +1 -0
- package/presets/cursor/php-hexagonal/hooks/chain-team-phases.sh +175 -8
- package/presets/cursor/php-hexagonal/team/README.md +2 -0
- package/presets/cursor/php-laravel/hooks/chain-team-phases.sh +175 -8
- package/presets/cursor/php-laravel/team/README.md +2 -0
- package/presets/cursor/svelte/MCP.md +2 -2
- package/presets/cursor/svelte/hooks/chain-team-phases.sh +145 -6
- package/presets/cursor/svelte/mcp.json +1 -1
- package/presets/cursor/svelte/team/README.md +2 -0
- package/presets/cursor/svelte/team/fixtures/artifact-manifest.example.json +1 -0
- package/presets/mavis/android-kotlin/MCP.md +2 -2
- package/presets/mavis/android-kotlin/adapter-map.json +1 -1
- package/presets/mavis/android-kotlin/hooks/chain-team-phases.sh +150 -7
- package/presets/mavis/android-kotlin/mcp.json +1 -1
- package/presets/mavis/android-kotlin/team/README.md +2 -0
- package/presets/mavis/android-kotlin/team/fixtures/artifact-manifest.example.json +1 -0
- package/presets/mavis/go/MCP.md +2 -2
- package/presets/mavis/go/adapter-map.json +1 -1
- package/presets/mavis/go/hooks/chain-team-phases.sh +175 -8
- package/presets/mavis/go/mcp.json +1 -1
- package/presets/mavis/go/team/README.md +2 -0
- package/presets/mavis/ios-swift/MCP.md +2 -2
- package/presets/mavis/ios-swift/adapter-map.json +1 -1
- package/presets/mavis/ios-swift/hooks/chain-team-phases.sh +150 -7
- package/presets/mavis/ios-swift/mcp.json +1 -1
- package/presets/mavis/ios-swift/team/README.md +2 -0
- package/presets/mavis/ios-swift/team/fixtures/artifact-manifest.example.json +1 -0
- package/presets/mavis/java/adapter-map.json +1 -1
- package/presets/mavis/java/hooks/chain-team-phases.sh +175 -8
- package/presets/mavis/java/team/README.md +2 -0
- package/presets/mavis/mcp-ts/adapter-map.json +1 -1
- package/presets/mavis/mcp-ts/hooks/chain-team-phases.sh +179 -10
- package/presets/mavis/mcp-ts/team/README.md +2 -0
- package/presets/mavis/next/MCP.md +2 -2
- package/presets/mavis/next/adapter-map.json +1 -1
- package/presets/mavis/next/hooks/chain-team-phases.sh +99 -5
- package/presets/mavis/next/mcp.json +1 -1
- package/presets/mavis/next/team/README.md +2 -0
- package/presets/mavis/next/team/fixtures/artifact-manifest.example.json +1 -0
- package/presets/mavis/nuxt/MCP.md +2 -2
- package/presets/mavis/nuxt/adapter-map.json +1 -1
- package/presets/mavis/nuxt/hooks/chain-team-phases.sh +145 -6
- package/presets/mavis/nuxt/mcp.json +1 -1
- package/presets/mavis/nuxt/team/README.md +2 -0
- package/presets/mavis/nuxt/team/fixtures/artifact-manifest.example.json +1 -0
- package/presets/mavis/php-hexagonal/adapter-map.json +1 -1
- package/presets/mavis/php-hexagonal/hooks/chain-team-phases.sh +175 -8
- package/presets/mavis/php-hexagonal/team/README.md +2 -0
- package/presets/mavis/php-laravel/adapter-map.json +1 -1
- package/presets/mavis/php-laravel/hooks/chain-team-phases.sh +175 -8
- package/presets/mavis/php-laravel/team/README.md +2 -0
- package/presets/mavis/svelte/MCP.md +2 -2
- package/presets/mavis/svelte/adapter-map.json +1 -1
- package/presets/mavis/svelte/hooks/chain-team-phases.sh +145 -6
- package/presets/mavis/svelte/mcp.json +1 -1
- package/presets/mavis/svelte/team/README.md +2 -0
- package/presets/mavis/svelte/team/fixtures/artifact-manifest.example.json +1 -0
- package/presets/opencode/android-kotlin/MCP.md +2 -2
- package/presets/opencode/android-kotlin/adapter-map.json +1 -1
- package/presets/opencode/android-kotlin/hooks/chain-team-phases.sh +150 -7
- package/presets/opencode/android-kotlin/opencode.json +1 -1
- package/presets/opencode/android-kotlin/team/README.md +2 -0
- package/presets/opencode/android-kotlin/team/fixtures/artifact-manifest.example.json +1 -0
- package/presets/opencode/go/MCP.md +2 -2
- package/presets/opencode/go/adapter-map.json +1 -1
- package/presets/opencode/go/hooks/chain-team-phases.sh +175 -8
- package/presets/opencode/go/opencode.json +1 -1
- package/presets/opencode/go/team/README.md +2 -0
- package/presets/opencode/ios-swift/MCP.md +2 -2
- package/presets/opencode/ios-swift/adapter-map.json +1 -1
- package/presets/opencode/ios-swift/hooks/chain-team-phases.sh +150 -7
- package/presets/opencode/ios-swift/opencode.json +1 -1
- package/presets/opencode/ios-swift/team/README.md +2 -0
- package/presets/opencode/ios-swift/team/fixtures/artifact-manifest.example.json +1 -0
- package/presets/opencode/java/adapter-map.json +1 -1
- package/presets/opencode/java/hooks/chain-team-phases.sh +175 -8
- package/presets/opencode/java/team/README.md +2 -0
- package/presets/opencode/mcp-ts/adapter-map.json +1 -1
- package/presets/opencode/mcp-ts/hooks/chain-team-phases.sh +179 -10
- package/presets/opencode/mcp-ts/team/README.md +2 -0
- package/presets/opencode/next/MCP.md +2 -2
- package/presets/opencode/next/adapter-map.json +1 -1
- package/presets/opencode/next/hooks/chain-team-phases.sh +99 -5
- package/presets/opencode/next/opencode.json +1 -1
- package/presets/opencode/next/team/README.md +2 -0
- package/presets/opencode/next/team/fixtures/artifact-manifest.example.json +1 -0
- package/presets/opencode/nuxt/MCP.md +2 -2
- package/presets/opencode/nuxt/adapter-map.json +1 -1
- package/presets/opencode/nuxt/hooks/chain-team-phases.sh +145 -6
- package/presets/opencode/nuxt/opencode.json +1 -1
- package/presets/opencode/nuxt/team/README.md +2 -0
- package/presets/opencode/nuxt/team/fixtures/artifact-manifest.example.json +1 -0
- package/presets/opencode/php-hexagonal/adapter-map.json +1 -1
- package/presets/opencode/php-hexagonal/hooks/chain-team-phases.sh +175 -8
- package/presets/opencode/php-hexagonal/team/README.md +2 -0
- package/presets/opencode/php-laravel/adapter-map.json +1 -1
- package/presets/opencode/php-laravel/hooks/chain-team-phases.sh +175 -8
- package/presets/opencode/php-laravel/team/README.md +2 -0
- package/presets/opencode/svelte/MCP.md +2 -2
- package/presets/opencode/svelte/adapter-map.json +1 -1
- package/presets/opencode/svelte/hooks/chain-team-phases.sh +145 -6
- package/presets/opencode/svelte/opencode.json +1 -1
- package/presets/opencode/svelte/team/README.md +2 -0
- package/presets/opencode/svelte/team/fixtures/artifact-manifest.example.json +1 -0
|
@@ -32,10 +32,14 @@ Roster of specialists is **stack-specific** (agent names and write scopes differ
|
|
|
32
32
|
| Tests | unit planner/generator/healer; e2e/UI planner/generator/healer (stack-native) |
|
|
33
33
|
| Docs | `tech-writer` |
|
|
34
34
|
|
|
35
|
-
**
|
|
35
|
+
**Claude packaging:** team pipeline agents are Markdown files with YAML frontmatter under `.claude/agents/`; subagents are invoked with the Task tool and start with no always-on context, so each prompt re-declares the rules it needs. Production/app restrictions live in the agent prompt body. See `agents/README.md`.
|
|
36
36
|
|
|
37
37
|
Full prompts: stack `agents/*.md`. Artifact conventions: stack `team/README.md`; schema SoT: **agent-artifact-contracts**.
|
|
38
38
|
|
|
39
|
+
## Stack notes
|
|
40
|
+
|
|
41
|
+
Roles, write scopes, and Claude `tools` / frontmatter packaging — **`agents/README.md`**.
|
|
42
|
+
|
|
39
43
|
## Dynamic pipeline
|
|
40
44
|
|
|
41
45
|
```mermaid
|
|
@@ -203,7 +207,7 @@ On each `subagentStop`, the hook reconciles `status.state` from the completing p
|
|
|
203
207
|
12. **Invoke the ready set, and never advance before reconciliation.** In graph mode the hook computes the ready queue; invoke exactly the handoff's agent list (a wave in one assistant turn, multiple Task calls) and do not start any next step from your own reasoning until the hook records the join and emits the next handoff. The wave is the join unit; `status.joinedSlots` is the satisfaction ledger.
|
|
204
208
|
13. **Only a proven conflict-free set is `parallel: true`.** Disjoint declared `writeScopes`, distinct agents, distinct `artifactOutputIds`, no shared lifecycle file; `mockup-reviewer` is never parallel (its FAIL gate is serial). See **plan-graph** § Conflict model.
|
|
205
209
|
|
|
206
|
-
## Team artifact I/O
|
|
210
|
+
## Team artifact I/O
|
|
207
211
|
|
|
208
212
|
- **Persist the original prompt.** For **every** task — `/task` or a routed work request — write the user's **verbatim** prompt to `.ai.local/team/tasks/<slug>/prompt.md` during slug bootstrap (write-if-absent; never overwrite on resume). The header is additive provenance only; the fenced text block holds the user's words unchanged. It is not a manifest `artifacts[]` body — the path lives on the `routing` entry. See **agent-artifact-contracts** § Prompt artifact.
|
|
209
213
|
- **Append follow-up prompts.** When a user-authored prompt arrives for an active slug (new message, `/task-continue` args, gate feedback, clarification), append it verbatim to `.ai.local/team/tasks/<slug>/prompt-log.md` — `seq` = current max + 1, create on first append, never rewrite or duplicate an entry, never touch `prompt.md`. Exclude hook `followup_message` and empty/argument-less invocations. Not a manifest `artifacts[]` body — the path lives on the `routing` entry. See **agent-artifact-contracts** § Prompt log.
|
|
@@ -249,227 +253,3 @@ When user describes a **non-trivial task** (not a question), suggest `/task <mes
|
|
|
249
253
|
## Preset authoring
|
|
250
254
|
|
|
251
255
|
When the work edits `packages/ai-rules/presets/**` (or dogfood `.cursor/` sync of presets), follow meta-rules: **preset-goals**, **preset-pr-checklist**, **preset-twin-sync**, **preset-layering**, **preset-token-budget**, **preset-no-cross-stack-leakage**.
|
|
252
|
-
|
|
253
|
-
## Stack notes
|
|
254
|
-
|
|
255
|
-
### Roles
|
|
256
|
-
|
|
257
|
-
| Agent | App / prod writes | Typical intent |
|
|
258
|
-
|-------|-------------------|----------------|
|
|
259
|
-
| `task-router` | no (team only) | Every `/task` — writes `pipeline.json` |
|
|
260
|
-
| `task-analyst` | no (team only) | feature, refactor, test-only, a11y, docs-only, migration, ux-design, spec-gen |
|
|
261
|
-
| `solution-architect` | no (team only) | spike, complex cross-layer feature |
|
|
262
|
-
| `migration-specialist` | no (team only) | migration — phased upgrade plan |
|
|
263
|
-
| `api-contract-reviewer` | no (team only) | new/changed backend API contracts |
|
|
264
|
-
| `debugger` | minimal fix | bugfix |
|
|
265
|
-
| `ci-investigator` | minimal CI fix | ci-fix — minimal CI repair |
|
|
266
|
-
| `feature-developer` | yes | feature, bugfix, refactor, migration, a11y |
|
|
267
|
-
| `build-verifier` | no (team only) | lint/type-check/unit gate after developer |
|
|
268
|
-
| `accessibility-reviewer` | no (team only) | a11y, UI-heavy feature |
|
|
269
|
-
| `performance-auditor` | no (team only) | perf-audit, perf-sensitive feature |
|
|
270
|
-
| `mockup-reviewer` | no (team only) | mockup-review, feature/refactor/spike/spec-gen with `figma.com` |
|
|
271
|
-
| `code-reviewer` | no (team only) | most pipelines, review-only |
|
|
272
|
-
| `security-reviewer` | no (team only) | auth, forms, sensitive data |
|
|
273
|
-
| `qa-tester` | tests only | feature, bugfix, test-only |
|
|
274
|
-
| `unit-test-planner` | no (team only) | unit-only — coverage plan |
|
|
275
|
-
| `unit-test-generator` | tests only | unit-only — spec generation |
|
|
276
|
-
| `unit-test-healer` | tests only | failing/flaky unit tests |
|
|
277
|
-
| `playwright-test-planner` | e2e plans | e2e scenario planning |
|
|
278
|
-
| `playwright-test-generator` | e2e tests | e2e spec generation |
|
|
279
|
-
| `playwright-test-healer` | e2e fixes | failing/flaky e2e fixes |
|
|
280
|
-
| `tech-writer` | docs / team | docs-only, feature/migration docs |
|
|
281
|
-
|
|
282
|
-
**Cursor frontmatter:** all team pipeline agents use `readonly: false` so they can write `.ai.local/team/**`. Production/app restrictions live in the agent prompt body — do **not** set `readonly: true` (Cursor blocks *all* file writes, including team artifacts).
|
|
283
|
-
|
|
284
|
-
Full prompts: `.cursor/agents/*.md`. Artifact conventions: `.ai.local/team/README.md`; schema SoT: **agent-artifact-contracts**.
|
|
285
|
-
|
|
286
|
-
**Behavioral UX:** `task-analyst` loads requestable skill `ux-design` for standalone intent `ux-design` and embedded required-signal / advisory UI AC. No `ux-designer` agent in v1.
|
|
287
|
-
|
|
288
|
-
**Product specs:** When `/task` or `/spec-start` touches pages/features/`docs/specs`: if INDEX exists and no generate intent → instruct next agent to load requestable **`product-specs`** (consume; soft-fail; never invent). If generate/bootstrap/`spec-gen` → load **`product-specs-authoring`** + skill **`spec-authoring`** inside **task-analyst** (not a separate pipeline step); pass created spec paths + INDEX diff in handoff; human gate must approve before feature-developer. No-op if INDEX absent and no author intent.
|
|
289
|
-
|
|
290
|
-
### UI / Figma parity routing
|
|
291
|
-
|
|
292
|
-
A `mockup-reviewer` verdict **`mockup-change-requested`** (a Figma-side defect whose fix belongs in Figma) routes exactly like the embedded `mockup-reviewer` FAIL: receipt `changes_requested`, artifact `blocked` → the hook sets `awaiting_approval` (`/task-continue`), and there is **no** `feature-developer` retry. Standalone report → receipt `completed`. The human action is named in the `## Mockup change requests` handoff (fix Figma → re-run `mockup-review` → new `specVersion` → `/task-continue`). This adds **no** hook/gate/retry change.
|
|
293
|
-
|
|
294
|
-
When editing `packages/ai-rules/presets/**`, follow **`tooling-and-review/preset-goals.md`** + **`tooling-and-review/preset-pr-checklist.md`** (+ twin-sync / layering / token-budget / leakage meta-rules).
|
|
295
|
-
|
|
296
|
-
## Dynamic pipeline
|
|
297
|
-
|
|
298
|
-
```mermaid
|
|
299
|
-
flowchart TD
|
|
300
|
-
task["/task prompt"]
|
|
301
|
-
router["task-router"]
|
|
302
|
-
pipeline["pipeline.json"]
|
|
303
|
-
step0["steps 0..N"]
|
|
304
|
-
gate{"humanGates?"}
|
|
305
|
-
hook["subagentStop hook"]
|
|
306
|
-
retro["/technical-retro"]
|
|
307
|
-
|
|
308
|
-
task --> router
|
|
309
|
-
router --> pipeline
|
|
310
|
-
pipeline --> step0
|
|
311
|
-
step0 --> gate
|
|
312
|
-
gate -->|"/task-continue"| step0
|
|
313
|
-
step0 --> hook
|
|
314
|
-
hook --> step0
|
|
315
|
-
step0 --> retro
|
|
316
|
-
```
|
|
317
|
-
|
|
318
|
-
**Source of truth for order:** `pipeline.json` → `steps[]`. Never hardcode analyst → dev → review → QA when `pipeline.json` exists.
|
|
319
|
-
|
|
320
|
-
New pipelines retain top-level `profile` and include `routingDecision` with `complexity`, `riskFlags`, non-empty `routingReasons`, `estimatedWorkPackages`, and `openDecisionCount`. The stack `task-router` owns heuristics; this metadata is auditable evidence and does not change hook semantics.
|
|
321
|
-
|
|
322
|
-
## Metrics lifecycle
|
|
323
|
-
|
|
324
|
-
Use the local `metrics.json` ledger described by **agent-task-metrics**: the orchestration runtime initializes attempts before invocation, hooks record host-clock ends, and agents never guess a parallel completion from `currentAgent`.
|
|
325
|
-
|
|
326
|
-
## Artifact context index and receipts
|
|
327
|
-
|
|
328
|
-
Each slug has one `artifact-manifest.json` at `.ai.local/team/tasks/<slug>/`. Schema SoT: **agent-artifact-contracts**.
|
|
329
|
-
|
|
330
|
-
- Read the manifest before broad prior-artifact discovery. Each step receives authoritative input entry IDs, owns named output entry IDs, and finishes with one terminal receipt linked to AC/task IDs.
|
|
331
|
-
- Markdown remains detailed evidence; the manifest records producer, status, authoritative paths, timestamps, outcome, and evidence paths.
|
|
332
|
-
- Agents upsert only the items they own in `manifest.artifacts[]` and preserve all foreign items in that array. Parallel agents use distinct IDs; the parent/orchestrator serializes manifest merges. The top-level array key is `artifacts` — not `entries`; see `agent-artifact-contracts.md` for the schema callout.
|
|
333
|
-
- The orchestration runtime/hook is the single writer for `status.json` lifecycle fields and `metrics.json`. Agents read status for eligibility but never rewrite state, gate, retry, attempt, timestamp, or metrics fields.
|
|
334
|
-
- Missing/stale manifests are reported as a handoff gap; fall back to `brief.md`, `decomposition.md`, and `pipeline.json` rather than inventing authority.
|
|
335
|
-
|
|
336
|
-
## Plan revision
|
|
337
|
-
|
|
338
|
-
Replanning is a named, auditable operation — never a silent reorder. When an evaluation oracle fails twice on a task, scope or requirements change, or a new dependency/consumer is discovered: append `decision: replan rev N → N+1` to `.memlog.md`, update `decomposition.md` (and any optional `planRevision` / `epics[]` fields), then **re-run the affected gate**. Scope-changing revisions return to the human gate.
|
|
339
|
-
|
|
340
|
-
## Self-review & context hygiene
|
|
341
|
-
|
|
342
|
-
Each producing agent runs a **pre-receipt self-review** of its own output — goal/AC coverage, evidence presence, and alignment/drift — **before** it emits its terminal receipt. It is a producer-side step, **not** a new pipeline agent or step, and it does not replace the evidence gate (`verification-before-completion`), the independent `code-reviewer`, or the `build-verifier` project gate.
|
|
343
|
-
|
|
344
|
-
- **Context loss vs excess/noise.** *Loss* = a dropped/misattributed AC or constraint, a stale plan vs the current request, a forgotten prior decision. *Excess/noise* = irrelevant/tangent reads, scope creep beyond the frame, duplicated or bloated artifacts, chat state that belongs on disk.
|
|
345
|
-
- **Re-anchor.** On detected drift, return the run to the framed task: re-read the `task-framing` goal frame + the current `decomposition.md` → repair the drift → re-run the affected gate → record append-only in `.memlog.md` (`event:` line; `decision: replan rev N → N+1` when the plan changes). Re-anchor is a **trigger source of the existing `plan-graph` `replan`** — no second orchestrator, no `status.json`/`metrics.json` field.
|
|
346
|
-
- **Recording & ratchet.** The producer writes a `## Self-review` block in the artifact it owns; the correction lives only in `.memlog.md` (hook-only lifecycle preserved). No self-review, context-health pass, or re-anchor for `bounded`/`spike` tasks (or the `light` profile) — ratchet up for `standard`/`architectural`, never down past a required verification gate. See the requestable `quality/self-review-and-context-hygiene` contract — including the optional rule-improvement loop (append wrong-turn signals to `.ai.local/signals.jsonl` and run `.ai.local/scripts/rule-improver.mjs`) when that script exists.
|
|
347
|
-
|
|
348
|
-
## Context budget & checkpoint/resume
|
|
349
|
-
|
|
350
|
-
Work in bounded waves (one artifact class across the surface). **Checkpoint** each completed wave to `.memlog.md` (`## <date>` + an `event:` line) and record produced paths on the `implementation` manifest entry `authoritativePaths`. A resumed run (e.g. `/task-continue`) reads `artifact-manifest.json` + `.memlog.md` and continues at the first stage whose exit criteria are unmet — never re-derive state from the chat. Mechanical waves (generation, embed sync) are delegated to repo scripts.
|
|
351
|
-
|
|
352
|
-
## status.json (pipeline mode)
|
|
353
|
-
|
|
354
|
-
```json
|
|
355
|
-
{
|
|
356
|
-
"slug": "...",
|
|
357
|
-
"intent": "feature",
|
|
358
|
-
"pipelineIndex": 0,
|
|
359
|
-
"currentAgent": "task-analyst",
|
|
360
|
-
"phase": "executing",
|
|
361
|
-
"state": "in_progress",
|
|
362
|
-
"awaitingHumanGate": false,
|
|
363
|
-
"activeAttempts": {},
|
|
364
|
-
"lastCompletedAttempt": null,
|
|
365
|
-
"parallelCompleted": [],
|
|
366
|
-
"parallelOutcomes": {}
|
|
367
|
-
}
|
|
368
|
-
```
|
|
369
|
-
|
|
370
|
-
| Field | Meaning |
|
|
371
|
-
|-------|---------|
|
|
372
|
-
| `activeAttempts` | Transient timing bridge keyed by `attemptId` |
|
|
373
|
-
| `lastCompletedAttempt` | Diagnostic pointer to the latest finished attempt |
|
|
374
|
-
| `parallelCompleted` | Agents that have stopped in the current parallel step |
|
|
375
|
-
| `parallelOutcomes` | Per-agent `{ outcome, attemptId, confidence }` for the current parallel join; cleared when the step advances or retries |
|
|
376
|
-
|
|
377
|
-
On each `subagentStop`, the hook reconciles `status.state` from the completing producer's terminal `artifact-manifest.json` receipt when agents left lifecycle fields untouched. Wait for that handoff before invoking the next step.
|
|
378
|
-
|
|
379
|
-
| state | Meaning |
|
|
380
|
-
|-------|---------|
|
|
381
|
-
| `in_progress` | Current step running |
|
|
382
|
-
| `completed` | Current step done; hook advances |
|
|
383
|
-
| `awaiting_approval` | Human gate; wait for `/task-continue` |
|
|
384
|
-
| `changes_requested` | Reviewer blocked; re-run developer (`retryAfterFix`) |
|
|
385
|
-
| `validation_failed` | build-verifier failed; re-run developer then build-verifier |
|
|
386
|
-
| `blocked` | Pipeline / step cannot proceed (e.g. `pipeline_parse_error`, completion of a parallel step whose producer's receipt was missing — see `agent-artifact-contracts.md` § Completion receipts) |
|
|
387
|
-
| `awaiting_artifact_receipt` | Producer stopped but the bound or assigned-output receipt was missing or stale; hook keeps the attempt active and does not advance. See `agent-artifact-contracts.md` (Schema field name + Receipt binding) for the silent-bug class that lands here. |
|
|
388
|
-
|
|
389
|
-
## Pipeline step options
|
|
390
|
-
|
|
391
|
-
| Field | Use |
|
|
392
|
-
|-------|-----|
|
|
393
|
-
| `skipIf` | `debugger.fixed` / `ci-investigator.resolved` — hook skips step when artifact says fix applied |
|
|
394
|
-
| `parallel: true` | `agent` is array — invoke **all** agents in one parent turn; each appends to `parallelCompleted` |
|
|
395
|
-
| `scope` | e.g. `unit-in-dev`, `e2e-only` — passed to developer/qa |
|
|
396
|
-
| `model` | `cheap` \| `standard` \| `strong` — optional tier override (see below) |
|
|
397
|
-
|
|
398
|
-
## Parallel scheduling (graph mode)
|
|
399
|
-
|
|
400
|
-
`pipeline.json` may carry an optional step graph: `steps[].id`, `steps[].taskIds[]`, `steps[].dependsOn[]`, `steps[].writeScopes[]`. While no step declares `dependsOn`, the hook keeps the legacy linear advance; any occurrence switches it to graph mode.
|
|
401
|
-
|
|
402
|
-
- The hook recomputes the **ready queue** on every stop: steps whose `dependsOn` are satisfied, not yet satisfied, not in flight, not skipped, not blocked.
|
|
403
|
-
- The **wave** is the join unit; a single `parallel: true` step is a one-step wave. `status.joinedSlots` is the persistent satisfaction ledger; `status.waveSteps`/`waveId` name the in-flight wave; `status.blockedSteps` excludes a blocked step.
|
|
404
|
-
- Set `parallel: true` only for a set proven conflict-free (disjoint `writeScopes`, distinct agents and `artifactOutputIds`); never place `mockup-reviewer` in a parallel group.
|
|
405
|
-
- **No advance before reconciliation.** Invoke exactly the handoff's agent list (a wave in one turn, multiple Task calls) and do not start a next step from your own reasoning until the hook records the join.
|
|
406
|
-
- A retry re-dispatches only unsatisfied slots: a satisfied sibling keeps its entry and terminal metric and is never re-invoked.
|
|
407
|
-
|
|
408
|
-
## Rules (strict)
|
|
409
|
-
|
|
410
|
-
1. **`/task` always starts with task-router** (except user says "skip router" with documented pipeline).
|
|
411
|
-
2. Read `pipeline.json` before every subagent invocation.
|
|
412
|
-
3. One role per Task call — **except** parallel steps: multiple Task calls in one message.
|
|
413
|
-
4. **Never** skip `humanGates` without `/task-continue` or explicit user approval.
|
|
414
|
-
5. Persist handoffs to disk (including `mockup-review.md` and `ux-design.md` when those producers ran) and update the producer-owned terminal receipt in `artifact-manifest.json`; Markdown remains detailed evidence.
|
|
415
|
-
6. On `changes_requested` from reviewers: hook sets `retryAfterFix` → developer → same reviewer. Exception: embedded `mockup-reviewer` FAIL → `awaiting_approval` / `/task-continue` only — do **not** retry `feature-developer`.
|
|
416
|
-
7. On `validation_failed` from `build-verifier`: hook sets `retryAfterFix: build-verifier` → developer → build-verifier.
|
|
417
|
-
8. When all steps complete, suggest `/technical-retro <slug>`.
|
|
418
|
-
9. If `autoChain: false` in pipeline, do not rely on hook — manual step only.
|
|
419
|
-
10. **Persist the verbatim original prompt.** Every `/task` and every routed work request writes the user's raw prompt to `.ai.local/team/tasks/<slug>/prompt.md` during slug bootstrap (write-if-absent; never overwrite on resume). Not a manifest `artifacts[]` body — register the path on the `routing` entry. See **agent-artifact-contracts** § Prompt artifact. Also append every **subsequent user-authored** prompt for the same slug — a new user message while the slug is active, `/task-continue` arguments, human-gate feedback, a clarification answer — to the append-only `.ai.local/team/tasks/<slug>/prompt-log.md` (`seq` = max + 1; never rewrite or duplicate an entry; never log machine-generated hook `followup_message` or empty/argument-less invocations). Register its path on the `routing` entry. See **agent-artifact-contracts** § Prompt log.
|
|
420
|
-
11. **Answer the user in the resolved dialogue language for the whole task.** Resolve once at task start
|
|
421
|
-
(`.ai.local` `## Language` → prompt language → English) and pass it to every step; `/task-continue` keeps
|
|
422
|
-
it. Never ask the user to pick a language. Development, reasoning, and artifacts stay English. See
|
|
423
|
-
**language-policy**.
|
|
424
|
-
|
|
425
|
-
## Team artifact I/O (Cursor Shell sandbox)
|
|
426
|
-
|
|
427
|
-
- **Persist the original prompt.** For **every** task — `/task` or a routed work request — write the user's **verbatim** prompt to `.ai.local/team/tasks/<slug>/prompt.md` during slug bootstrap (write-if-absent; never overwrite on resume). The header is additive provenance only; the fenced text block holds the user's words unchanged. Not a manifest `artifacts[]` body — the path lives on the `routing` entry. See **agent-artifact-contracts** § Prompt artifact.
|
|
428
|
-
- **Append follow-up prompts.** When a user-authored prompt arrives for an active slug (new message, `/task-continue` args, gate feedback, clarification), append it verbatim to `.ai.local/team/tasks/<slug>/prompt-log.md` — `seq` = current max + 1, create on first append, never rewrite or duplicate an entry, never touch `prompt.md`. Exclude hook `followup_message` and empty/argument-less invocations. Not a manifest `artifacts[]` body — the path lives on the `routing` entry. See **agent-artifact-contracts** § Prompt log.
|
|
429
|
-
- **Answer in the resolved dialogue language.** Resolve once at task start (`.ai.local` `## Language` →
|
|
430
|
-
prompt language → English; mixed → dominant; nearest `.ai.local` wins) and reuse it for every user-facing
|
|
431
|
-
message and `/task-continue`. Record the tag in the `prompt.md` header (`language: <BCP-47>`) + a
|
|
432
|
-
`.memlog.md` `event:` line; a later correction is an append-only memlog event. Development, reasoning, and
|
|
433
|
-
artifacts stay **English**. See **language-policy**.
|
|
434
|
-
|
|
435
|
-
- Create/update `.ai.local/team/tasks/<slug>/**` with the **Write** tool (parents are created automatically). Do **not** bootstrap slug dirs with Shell `mkdir -p` — default sandbox returns `Operation not permitted` (worse on macOS Desktop/Documents with TCC `com.apple.macl`).
|
|
436
|
-
- If Shell must touch team paths and fails with EPERM, retry with `required_permissions: ["all"]`. Prefer Write for artifacts.
|
|
437
|
-
- Prefer repo under `~/Projects` / `WebstormProjects` over `~/Desktop` when using agent team heavily.
|
|
438
|
-
|
|
439
|
-
## Invoking agents
|
|
440
|
-
|
|
441
|
-
Use Task tool or `/agent-name`. Pass: slug, artifact paths, step `scope` if set.
|
|
442
|
-
|
|
443
|
-
### Model when invoking (Task)
|
|
444
|
-
|
|
445
|
-
1. Read `steps[i].model` if present; else use the agent’s frontmatter `model` (see `agents/README.md` matrix).
|
|
446
|
-
2. Map abstract tiers:
|
|
447
|
-
- **`cheap`** → pass Task `model: "fast"` when the tool accepts it (or rely on agent `fast`).
|
|
448
|
-
- **`standard`** → omit Task `model` (frontmatter `inherit` / mid default).
|
|
449
|
-
- **`strong`** → **never** pass `fast`; rely on agent pin (`claude-opus-4-8[effort=high]`) or parent Max model. If Task allows an explicit model ID from the allowed list, prefer the strong agent’s frontmatter ID.
|
|
450
|
-
3. Parallel steps: apply the step-level `model` to **each** agent in the array (or omit → each agent’s own frontmatter).
|
|
451
|
-
|
|
452
|
-
After each agent completes, verify its terminal manifest receipt, then let the orchestration runtime/hook reconcile `status.json` (`completed`, a blocking outcome, or `awaiting_approval`) from that receipt. Do not ask the agent to mutate shared lifecycle fields, and do not invoke the next specialist until the hook has written the handoff / updated `status.json`.
|
|
453
|
-
|
|
454
|
-
## Legacy mode
|
|
455
|
-
|
|
456
|
-
If `pipeline.json` is missing, fall back to fixed phases: analysis → development → review → testing. Hook supports both.
|
|
457
|
-
|
|
458
|
-
## Skip pipeline when
|
|
459
|
-
|
|
460
|
-
Do **not** run `/task` + router for:
|
|
461
|
-
|
|
462
|
-
- Pure questions («как работает X» (how does X work), «объясни» (explain)) — prefer agent **`codebase-analyzer`** for deep traces; inline OK for trivial one-liners. <!-- i18n-keep: E4 -->
|
|
463
|
-
- Typo / one-file fix / trivial config with no architecture risk.
|
|
464
|
-
- User explicitly says «без pipeline» (no pipeline), «просто сделай» (just do it), or continues an active slug. <!-- i18n-keep: E4 -->
|
|
465
|
-
- Single-line `docs-only` with no code impact.
|
|
466
|
-
|
|
467
|
-
Borderline work requests — see **`tooling-and-review/agent-team-intake.md`**.
|
|
468
|
-
|
|
469
|
-
## Auto-detection (optional)
|
|
470
|
-
|
|
471
|
-
When user describes a **non-trivial task** (not a question), suggest `/task <message>` or run router if they agree.
|
|
472
|
-
|
|
473
|
-
## Preset authoring
|
|
474
|
-
|
|
475
|
-
When the work edits `packages/ai-rules/presets/**` (or dogfood `.cursor/` sync of presets), follow meta-rules: **preset-goals**, **preset-pr-checklist**, **preset-twin-sync**, **preset-layering**, **preset-token-budget**, **preset-no-cross-stack-leakage**.
|
|
@@ -75,6 +75,8 @@ Same JSON on Claude, Mavis, or OpenCode: `bash .<tool>/hooks/chain-team-phases.s
|
|
|
75
75
|
|
|
76
76
|
## Contracts
|
|
77
77
|
|
|
78
|
+
- **Manifest field name:** receipts go in `artifacts[]`. Anything written under `entries` is ignored — the hook reads only `artifacts` and prints a dual-read warning naming the file. See `agent-team/agent-artifact-contracts.md` § Schema field name.
|
|
79
|
+
- **Evidence paths:** `authoritativePaths[]` must be task-relative (`.ai.local/team/tasks/<slug>/…`). Put anything outside the task directory — e.g. `openspec/changes/**` — in `evidencePaths[]`.
|
|
78
80
|
- Manifest schema: shared core `agent-team/agent-artifact-contracts.md`. Read it first; producers upsert only their IDs.
|
|
79
81
|
- Metrics: append-only allowlisted events — `agent-team/agent-task-metrics.md`. Aggregate: `node node_modules/@bonesofspring/ai-rules/scripts/aggregate-agent-task-metrics.mjs --team-root .ai.local/team`.
|
|
80
82
|
- Commit `.ai.local/team/` templates (and slugs if you want them in clones).
|
|
@@ -90,9 +92,3 @@ Same JSON on Claude, Mavis, or OpenCode: `bash .<tool>/hooks/chain-team-phases.s
|
|
|
90
92
|
**Checkpoint / resume:** progress is checkpointed to `tasks/<slug>/.memlog.md` (`## <date>` + `event:` entries) and the `artifact-manifest.json` `implementation` entry (`authoritativePaths`). A resumed run reads both and continues at the first stage whose exit criteria are unmet.
|
|
91
93
|
|
|
92
94
|
**Self-review / re-anchor:** each producing agent records a `## Self-review` block in the artifact it owns (`brief.md` / `implementation.md` / `debug-report.md` / `validation-report.md` / `review.md`) and, on detected context loss / excess, a re-anchor line in `.memlog.md` — `event:` (no plan change) or `decision: replan rev N → N+1` (plan change). No hook/lifecycle field is added.
|
|
93
|
-
|
|
94
|
-
## Contracts
|
|
95
|
-
|
|
96
|
-
- Manifest schema: shared core `agent-team/agent-artifact-contracts.md`. Read it first; producers upsert only their IDs.
|
|
97
|
-
- Metrics: append-only allowlisted events — `agent-team/agent-task-metrics.md`. Aggregate: `node node_modules/@bonesofspring/ai-rules/scripts/aggregate-agent-task-metrics.mjs --team-root .ai.local/team`.
|
|
98
|
-
- Commit `.ai.local/team/` templates (and slugs if you want them in clones).
|
|
@@ -9,9 +9,9 @@ Copied to the **project root** as `.mcp.json` on `ai-rules init claude --preset
|
|
|
9
9
|
| `context7` | `@upstash/context7-mcp` | Up-to-date Vue/Nuxt/TS docs |
|
|
10
10
|
| `playwright-test` | `@playwright/mcp` | Browser MCP; server name matches `mcp__playwright-test__*` in agents |
|
|
11
11
|
| `chrome-devtools` | `chrome-devtools-mcp` | Live DOM/network/performance |
|
|
12
|
-
| `figma` |
|
|
12
|
+
| `figma` | desktop `http://127.0.0.1:3845/mcp` | Design context → code; local desktop server (enable in Figma Desktop, Dev/Full seat) |
|
|
13
13
|
|
|
14
|
-
Do not commit secrets. Optional: `CONTEXT7_API_KEY`. Figma —
|
|
14
|
+
Do not commit secrets. Optional: `CONTEXT7_API_KEY`. Figma — local desktop server (enable in Figma Desktop, Dev/Full seat). After clone/init Claude Code will ask to approve project MCP (`/mcp`).
|
|
15
15
|
|
|
16
16
|
For the full Playwright Test Agents loop (`planner_*` / `generator_*` / `test_*`) additionally: `npx playwright init-agents --loop=claude` in the app with `@playwright/test`.
|
|
17
17
|
|
|
@@ -172,7 +172,21 @@ function mutateMetrics(mutator) {
|
|
|
172
172
|
try { metrics = JSON.parse(fs.readFileSync(METRICS_PATH, 'utf8')); } catch {
|
|
173
173
|
const runId = status.metricsRunId || `${slug}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
174
174
|
status.metricsRunId = runId;
|
|
175
|
-
|
|
175
|
+
// Resolve profile from pipeline.json (preferred) or status.json, falling back to 'unknown'.
|
|
176
|
+
// The router/agent must never write profile into status.json — pipeline.json is the SoT.
|
|
177
|
+
let profile = 'unknown';
|
|
178
|
+
try {
|
|
179
|
+
if (fs.existsSync(pipelinePath)) {
|
|
180
|
+
const pipe = JSON.parse(fs.readFileSync(pipelinePath, 'utf8'));
|
|
181
|
+
if (pipe && (pipe.profile === 'light' || pipe.profile === 'standard' || pipe.profile === 'full')) {
|
|
182
|
+
profile = pipe.profile;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
} catch {}
|
|
186
|
+
if (profile === 'unknown' && (status.profile === 'light' || status.profile === 'standard' || status.profile === 'full')) {
|
|
187
|
+
profile = status.profile;
|
|
188
|
+
}
|
|
189
|
+
metrics = { schemaVersion: 1, task: { runId, slug, preset: 'ai-rules', stack: STACK, platform: PLATFORM, intent: status.intent || 'unknown', profile }, events: [] };
|
|
176
190
|
metrics.events.push({ eventId: `${runId}:task_started`, type: 'task_started', at: now, source: 'hook', attributionConfidence: 'high' });
|
|
177
191
|
}
|
|
178
192
|
mutator(metrics);
|
|
@@ -245,21 +259,119 @@ function resolvedAttempt() {
|
|
|
245
259
|
const active = status.activeAttempts || {}; const entries = Object.entries(active);
|
|
246
260
|
const stableAttemptId = hookInput.attemptId;
|
|
247
261
|
if (stableAttemptId) {
|
|
248
|
-
return active[stableAttemptId]
|
|
262
|
+
return active[stableAttemptId]
|
|
263
|
+
? { attemptId: stableAttemptId, entry: active[stableAttemptId], confidence: 'high' }
|
|
264
|
+
: null;
|
|
249
265
|
}
|
|
250
266
|
if (entries.length === 1) return { attemptId: entries[0][0], entry: entries[0][1], confidence: 'high' };
|
|
251
267
|
try { const receipts = JSON.parse(fs.readFileSync(path.join(taskDir, '.metrics-receipts.json'), 'utf8')); const receipt = Array.isArray(receipts) ? receipts.find((item) => active[item.attemptId]) : null; if (receipt) return { attemptId: receipt.attemptId, entry: active[receipt.attemptId], confidence: 'fallback', source: 'agent' }; } catch {}
|
|
252
268
|
return null;
|
|
253
269
|
}
|
|
270
|
+
let artifactStallMessage = null;
|
|
271
|
+
|
|
272
|
+
// A1: seed the manifest a modern pipeline expects instead of advancing without
|
|
273
|
+
// one. Exclusive publish via hard link so a producer that wrote the file in the
|
|
274
|
+
// meantime is never overwritten; returns null on success (or when the file
|
|
275
|
+
// appeared) and the fs error otherwise.
|
|
276
|
+
function writeSkeletonManifest(manifestPath) {
|
|
277
|
+
const temporary = `${manifestPath}.${process.pid}.${Date.now()}.seed`;
|
|
278
|
+
const body = JSON.stringify({ schemaVersion: 1, slug, artifacts: [] }, null, 2) + '\n';
|
|
279
|
+
let descriptor = null;
|
|
280
|
+
try {
|
|
281
|
+
descriptor = fs.openSync(temporary, 'wx');
|
|
282
|
+
try { fs.writeSync(descriptor, body); try { fs.fsyncSync(descriptor); } catch {} } finally { fs.closeSync(descriptor); descriptor = null; }
|
|
283
|
+
fs.linkSync(temporary, manifestPath);
|
|
284
|
+
fs.unlinkSync(temporary);
|
|
285
|
+
return null;
|
|
286
|
+
} catch (error) {
|
|
287
|
+
if (descriptor !== null) { try { fs.closeSync(descriptor); } catch {} }
|
|
288
|
+
try { fs.unlinkSync(temporary); } catch {}
|
|
289
|
+
if (error && error.code === 'EEXIST' && fs.existsSync(manifestPath)) return null;
|
|
290
|
+
return String(error && error.message ? error.message : error);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// A2: a `completed` receipt must cite evidence the harness can inspect. Order is
|
|
295
|
+
// the message order — the first failing predicate wins, so the operator sees one
|
|
296
|
+
// actionable line. `authoritativePaths[]` stays task-dir-relative; external
|
|
297
|
+
// references belong in `evidencePaths[]`.
|
|
298
|
+
function validateCompletedArtifact(entry) {
|
|
299
|
+
const artifactId = entry && entry.id ? entry.id : '(unnamed)';
|
|
300
|
+
const entryStatus = entry && entry.status;
|
|
301
|
+
if (entryStatus !== 'completed') {
|
|
302
|
+
return `[chain-team-phases] ${slug}: receipt "${artifactId}" has receipt.outcome "completed" but entry status "${entryStatus}". Make entry.status and receipt.outcome agree, then resume with: /task-continue ${slug}`;
|
|
303
|
+
}
|
|
304
|
+
const authoritativePaths = entry && Array.isArray(entry.authoritativePaths) ? entry.authoritativePaths : [];
|
|
305
|
+
if (authoritativePaths.length === 0) {
|
|
306
|
+
return `[chain-team-phases] ${slug}: receipt "${artifactId}" is "completed" but authoritativePaths[] is empty. Record at least one file you produced under .ai.local/team/tasks/${slug}/, then resume with: /task-continue ${slug}`;
|
|
307
|
+
}
|
|
308
|
+
for (const cited of authoritativePaths) {
|
|
309
|
+
const value = typeof cited === 'string' ? cited.trim() : '';
|
|
310
|
+
const resolvedPath = value ? path.resolve(taskDir, value) : taskDir;
|
|
311
|
+
const relative = path.relative(taskDir, resolvedPath);
|
|
312
|
+
const escapes = !value || path.isAbsolute(value) || relative === '' || relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative);
|
|
313
|
+
if (escapes) {
|
|
314
|
+
return `[chain-team-phases] ${slug}: receipt "${artifactId}" cites "${value}", which resolves outside .ai.local/team/tasks/${slug}/ (relative: "${relative}"). Cite a task-relative path; keep external references in evidencePaths[]. Then resume with: /task-continue ${slug}`;
|
|
315
|
+
}
|
|
316
|
+
let stat = null;
|
|
317
|
+
try { stat = fs.statSync(resolvedPath); } catch {}
|
|
318
|
+
if (!stat || !stat.isFile()) {
|
|
319
|
+
return `[chain-team-phases] ${slug}: receipt "${artifactId}" cites "${value}" but no such file exists under .ai.local/team/tasks/${slug}/. Write the file, then resume with: /task-continue ${slug}`;
|
|
320
|
+
}
|
|
321
|
+
if (/\.md[c]?$/i.test(value)) {
|
|
322
|
+
let content = '';
|
|
323
|
+
try { content = fs.readFileSync(resolvedPath, 'utf8'); } catch {}
|
|
324
|
+
if (!/\S/.test(content)) {
|
|
325
|
+
return `[chain-team-phases] ${slug}: receipt "${artifactId}" is "completed" but authoritative path "${value}" has no non-whitespace content. Produce the artifact, then resume with: /task-continue ${slug}`;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
return null;
|
|
330
|
+
}
|
|
331
|
+
|
|
254
332
|
function readBoundReceiptOutcome(agent, step, resolved) {
|
|
255
333
|
if (!agent || !resolved) return { outcome: null, receiptRequired: false };
|
|
256
334
|
const manifestPath = path.join(taskDir, 'artifact-manifest.json');
|
|
257
|
-
|
|
335
|
+
const expectedOutputId = artifactOutputIdFor(step, agent);
|
|
336
|
+
if (!fs.existsSync(manifestPath)) {
|
|
337
|
+
// A1: absent manifest + a parsed modern pipeline denies silent advancement.
|
|
338
|
+
// Legacy/step-less pipelines keep their previous behaviour (legacyFlow owns them).
|
|
339
|
+
if (!(Array.isArray(steps) && steps.length > 0)) return { outcome: null, receiptRequired: false };
|
|
340
|
+
const seeded = writeSkeletonManifest(manifestPath);
|
|
341
|
+
const stepIndex = typeof resolved.entry.stepIndex === 'number' ? resolved.entry.stepIndex : 0;
|
|
342
|
+
if (seeded) {
|
|
343
|
+
return { outcome: null, receiptRequired: true, stallMessage: `[chain-team-phases] ${slug}: artifact-manifest.json is missing and the skeleton could not be written (${seeded}). Create .ai.local/team/tasks/${slug}/artifact-manifest.json with {schemaVersion:1, slug, artifacts:[]}, add the receipt for artifactOutputId "${expectedOutputId}", then resume with: /task-continue ${slug}` };
|
|
344
|
+
}
|
|
345
|
+
return { outcome: null, receiptRequired: true, stallMessage: `[chain-team-phases] ${slug}: no artifact-manifest.json for step ${stepIndex} (${agent}). Wrote a skeleton {schemaVersion:1, slug, artifacts:[]}. Expected artifactOutputId "${expectedOutputId}". Write the artifact and its receipt, then resume with: /task-continue ${slug}` };
|
|
346
|
+
}
|
|
258
347
|
try {
|
|
259
348
|
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
|
|
349
|
+
// Guard: the schema key is `artifacts` (see agent-artifact-contracts.md). A top-level
|
|
350
|
+
// `entries` key is a silent bug — producer wrote to a wrong field, hook would not
|
|
351
|
+
// see the receipt, and the step hangs in `awaiting_artifact_receipt`. Warn loudly.
|
|
352
|
+
if (manifest && typeof manifest === 'object' && !Array.isArray(manifest.artifacts) && Array.isArray(manifest.entries)) {
|
|
353
|
+
process.stderr.write(`WARNING: ${manifestPath} has top-level "entries" but no "artifacts" array; reading only "artifacts" per schema. The producer likely upserted into the wrong key. See agent-artifact-contracts.md (Schema field name).` + '\n');
|
|
354
|
+
} else if (manifest && typeof manifest === 'object' && Array.isArray(manifest.entries) && Array.isArray(manifest.artifacts)) {
|
|
355
|
+
process.stderr.write(`WARNING: ${manifestPath} has both "artifacts" and "entries" keys; reading only "artifacts" per schema. Foreign "entries" content is ignored.` + '\n');
|
|
356
|
+
}
|
|
260
357
|
const artifacts = Array.isArray(manifest.artifacts) ? manifest.artifacts : [];
|
|
261
|
-
const expectedOutputId = artifactOutputIdFor(step, agent);
|
|
262
358
|
const attemptStartedAt = Date.parse(resolved.entry.startedAt);
|
|
359
|
+
// Pre-scan: warn on the silent-bug classes the filter below would otherwise drop.
|
|
360
|
+
// A receipt with a non-matching attemptId is dropped silently; without this warning,
|
|
361
|
+
// the step hangs in `awaiting_artifact_receipt` with no signal of why. Same for
|
|
362
|
+
// receipts whose terminal timestamp is older than the active attempt (stale retry).
|
|
363
|
+
const activeIds = new Set(Object.keys(status.activeAttempts || {}));
|
|
364
|
+
for (const entry of artifacts) {
|
|
365
|
+
if (!entry || entry.producer !== agent || !entry.receipt || typeof entry.receipt.outcome !== 'string') continue;
|
|
366
|
+
const rid = entry.receipt.attemptId;
|
|
367
|
+
if (typeof rid === 'string' && rid !== resolved.attemptId && !activeIds.has(rid)) {
|
|
368
|
+
process.stderr.write(`WARNING: ${manifestPath} receipt for producer "${agent}" id "${entry.id}" carries attemptId "${rid}" that does not match the active attempt "${resolved.attemptId}". The receipt is being dropped; step will hang in \`awaiting_artifact_receipt\` unless the producer retries. Common cause: agent reused an attemptId from a prior failed attempt. See agent-artifact-contracts.md (Receipt binding).` + '\n');
|
|
369
|
+
}
|
|
370
|
+
const terminalAt = Date.parse(entry.timestamps?.completedAt || entry.timestamps?.updatedAt || '');
|
|
371
|
+
if (Number.isFinite(attemptStartedAt) && Number.isFinite(terminalAt) && terminalAt < attemptStartedAt) {
|
|
372
|
+
process.stderr.write(`WARNING: ${manifestPath} receipt for producer "${agent}" id "${entry.id}" has timestamps.completedAt older than the active attempt's startedAt. Likely a stale receipt from a previous attempt; it is being dropped. See agent-artifact-contracts.md (Receipt binding).` + '\n');
|
|
373
|
+
}
|
|
374
|
+
}
|
|
263
375
|
const owned = artifacts
|
|
264
376
|
.filter((entry) => {
|
|
265
377
|
if (!entry || entry.producer !== agent || !entry.receipt || typeof entry.receipt.outcome !== 'string') return false;
|
|
@@ -274,19 +386,33 @@ function readBoundReceiptOutcome(agent, step, resolved) {
|
|
|
274
386
|
const tb = Date.parse(b.timestamps?.completedAt || b.timestamps?.updatedAt || 0) || 0;
|
|
275
387
|
return tb - ta;
|
|
276
388
|
});
|
|
277
|
-
|
|
389
|
+
// Bonus: warn if the active attempt's receipts all lack attemptId in a non-parallel step.
|
|
390
|
+
// The orchestrator always provides attemptId, so a missing one means the agent dropped it
|
|
391
|
+
// (model output, JSON.stringify omission, etc.). boundByOutput still binds the receipt by
|
|
392
|
+
// expectedOutputId, so this is not fatal — but it is a contract violation worth flagging.
|
|
393
|
+
if (owned.length > 0 && owned[0].receipt.attemptId == null && !(step && step.parallel && Array.isArray(getStepAgents(step)) && getStepAgents(step).length > 1)) {
|
|
394
|
+
process.stderr.write(`WARNING: ${manifestPath} receipt for producer "${agent}" id "${owned[0].id}" lacks entry.receipt.attemptId on a non-parallel step. The receipt is bound by output-id fallback; the agent should always include the attemptId the orchestrator provides. See agent-artifact-contracts.md (Receipt binding).` + '\n');
|
|
395
|
+
}
|
|
396
|
+
const outcome = owned[0]?.receipt?.outcome || null;
|
|
397
|
+
if (outcome === 'completed') {
|
|
398
|
+
const stallMessage = validateCompletedArtifact(owned[0]);
|
|
399
|
+
if (stallMessage) return { outcome: null, receiptRequired: true, stallMessage };
|
|
400
|
+
}
|
|
401
|
+
return { outcome, receiptRequired: true };
|
|
278
402
|
} catch {
|
|
279
403
|
return { outcome: null, receiptRequired: false };
|
|
280
404
|
}
|
|
281
405
|
}
|
|
282
406
|
function reconcileStatusFromManifest(agent, step, resolved) {
|
|
283
407
|
const terminal = new Set(['completed', 'blocked', 'changes_requested', 'validation_failed']);
|
|
284
|
-
|
|
408
|
+
artifactStallMessage = null;
|
|
409
|
+
const { outcome, receiptRequired, stallMessage } = readBoundReceiptOutcome(agent, step, resolved);
|
|
285
410
|
if (terminal.has(outcome)) {
|
|
286
411
|
status.state = outcome;
|
|
287
412
|
return outcome;
|
|
288
413
|
}
|
|
289
414
|
if (receiptRequired) {
|
|
415
|
+
artifactStallMessage = stallMessage || null;
|
|
290
416
|
status.state = 'awaiting_artifact_receipt';
|
|
291
417
|
status.phase = 'blocked';
|
|
292
418
|
return status.state;
|
|
@@ -345,6 +471,15 @@ function out(message) {
|
|
|
345
471
|
process.stdout.write(JSON.stringify({ followup_message: message }));
|
|
346
472
|
}
|
|
347
473
|
|
|
474
|
+
// The stall text always reaches stderr so a second, different rejection is never
|
|
475
|
+
// silent; `out()` fires only when the stop enters the stall, so the follow-up
|
|
476
|
+
// message cannot loop.
|
|
477
|
+
function emitArtifactStall(message, announce) {
|
|
478
|
+
if (message) process.stderr.write(message + '\n');
|
|
479
|
+
if (message && announce) out(message);
|
|
480
|
+
else process.stdout.write('{}');
|
|
481
|
+
}
|
|
482
|
+
|
|
348
483
|
function readArtifact(name) {
|
|
349
484
|
const p = path.join(taskDir, name);
|
|
350
485
|
if (!fs.existsSync(p)) return '';
|
|
@@ -924,10 +1059,11 @@ const completingAgentHint = (() => {
|
|
|
924
1059
|
return getStepAgents(initialStep)[0];
|
|
925
1060
|
})();
|
|
926
1061
|
const reconcilingAttempt = resolvedAttempt();
|
|
1062
|
+
const wasWaitingForReceipt = status.state === 'awaiting_artifact_receipt';
|
|
927
1063
|
reconcileStatusFromManifest(completingAgentHint, initialStep, reconcilingAttempt);
|
|
928
1064
|
if (status.state === 'awaiting_artifact_receipt') {
|
|
929
1065
|
writeStatus({});
|
|
930
|
-
|
|
1066
|
+
emitArtifactStall(artifactStallMessage, !wasWaitingForReceipt);
|
|
931
1067
|
process.exit(0);
|
|
932
1068
|
}
|
|
933
1069
|
let finishedAttempt = finishActiveAttempt();
|
|
@@ -937,6 +1073,11 @@ if (!finishedAttempt && activeAttemptCountBeforeFinish > 0) {
|
|
|
937
1073
|
if (repaired) {
|
|
938
1074
|
appendMetric({ type: 'parallel_attribution_repair', at: now, attemptIds: [repaired.attemptId], source: 'hook', attributionConfidence: 'fallback' });
|
|
939
1075
|
reconcileStatusFromManifest(repaired.entry.agent, steps[repaired.entry.stepIndex], repaired);
|
|
1076
|
+
if (status.state === 'awaiting_artifact_receipt') {
|
|
1077
|
+
writeStatus({});
|
|
1078
|
+
emitArtifactStall(artifactStallMessage, true);
|
|
1079
|
+
process.exit(0);
|
|
1080
|
+
}
|
|
940
1081
|
finishedAttempt = finishActiveAttempt(repaired);
|
|
941
1082
|
} else {
|
|
942
1083
|
writeStatus({});
|