refactor(implement-slice): define adaptive workflow contract, execution record, and safeguards
- add preflight branch state classifier (CLEAN_BASE, ADOPTABLE_DIFF, CONFLICTING_STATE, WRONG_BASE) - introduce tripartite workflow contract (Planned Workflow, Execution Record, Deviation Report) - establish canonical 5-tuple workflow node schema with proportional scaling - mandate dynamic Mermaid workflow graph projections exposing rework edges - define strict zero-mutation invariants for --dry-run - add policy-aware integration matrix distinguishing direct merges from PRs - replace deprecated tea references with gt CLI Closes #12
This commit is contained in:
1 parent
67c89ce7fd
commit
83824420d3
3 files changed
+124
-19
No files matched your search
@@ -17,22 +17,22 @@ description: >-
|
||||
- Not inside an already-delegated implementation worker task: follow the assigned worker contract (`tdd`, `git-manager`) without re-invoking `implement-slice`.
|
||||
|
||||
## Steps
|
||||
1. **Verify session mode and read slice context.** Check active session mode per `profile/AGENTS.md`: if `learning` is active, pause so the user can decide whether to switch to `delivery`. Read target Gitea issue/milestone state (`tea issues`, `tea milestones`), canonical direction docs (`ARCHITECTURE.md`, `ROADMAP.md`, ADRs when present), and `git status --short`. Clarify ambiguous intent with the user; hand off to `gitea-plan` if tracking issues must be created first.
|
||||
2. **Select orchestration topology (`complexity x risk`).** Combine planning size (`Small`, `Medium`, `Large` from `gitea-plan`) with assurance risk (`Lightweight`, `Standard`, `High-Assurance` from `code-review` and `verify-slice`) per [orchestration-tiers](references/orchestration-tiers.md), letting high-risk surfaces override size upward. Keep pure-orchestrator and context-budget invariants at every tier: retain only the plan, task status, commit SHAs, QA dispositions, blockers, and decisions; never edit implementation files, repair Git via code edits, self-certify QA, or ingest full test logs unless resolving a failure.
|
||||
3. **Lock plan, workspace topology, and pre-committed QA rubrics.** Decompose the slice into ordered tasks/chunks with explicit scope boundaries, expected `git-manager` checkpoint boundaries, workspace assignment (sequential shared branch vs. isolated `.worktrees/<task>` for concurrent workers), whether a PR applies, and falsifiable QA rubrics written before any worker spawns. Hard gate: pause for human approval before implementation begins.
|
||||
4. **Assign workspaces and delegate implementation.** Govern branch and worktree lifecycle through `git-manager` per [orchestration-tiers](references/orchestration-tiers.md) (orchestrator decides topology and assigns workspaces; `git-manager` executes branch/worktree operations; workers edit and commit checkpoints inside their assigned workspace). Dispatch worker subagent(s) with the Implementation Assignment in [handoff-contracts](references/handoff-contracts.md). Never run concurrent implementation workers in the same working tree.
|
||||
5. **Audit worker reports and run rubric QA.** Verify returned Implementation Reports via concise read-only Git checks (`git status --short`, `git log`, `git show --stat`) to confirm clean trees, commit SHAs, and scope containment. When the tier or chunk boundary requires independent QA, spawn a read-only/isolated QA subagent running `verify-slice` against the pre-committed rubric (withholding author narrative for `High-Assurance` black-box runs).
|
||||
6. **Triage outcomes and route rework.** Classify non-passing outcomes using [handoff-contracts](references/handoff-contracts.md): send code defects or missing seam tests back to the existing worker subagent (`send_message`) when its context remains live; repair or escalate `BLOCKED (env/fixture)`; pause for human authorization on `BLOCKED (out-of-bounds)` (`live-infra`); and if a rubric proves defective, record an explicit justified amendment (pausing for human approval if acceptance criteria or scope change). Loop Steps 4-6 until all slice tasks pass.
|
||||
7. **Enforce final-`HEAD` evidence invariant and finish.** Run `code-review` across `<base>...HEAD` (including strategic project alignment). Enforce the final-`HEAD` invariant in [handoff-contracts](references/handoff-contracts.md): required `code-review` (`Ready`) and `verify-slice` (zero unhandled `FAIL`) evidence must identify the same final `HEAD` and applicable base revision; any diff change invalidates affected evidence and triggers re-verification (completing any new `RV-*` checks on final `HEAD` via valid handshake reuse). Hard gate: never package a ready PR or declare completion until final-`HEAD` evidence is current. If a PR applies, hand off to `gitea-pr`; otherwise present the final-`HEAD` evidence summary, commit range, and open decisions to the user.
|
||||
1. **Preflight branch check and read slice context.** Check session mode per `profile/AGENTS.md`. Classify working tree per [handoff-contracts](references/handoff-contracts.md) (`CLEAN_BASE`, `ADOPTABLE_DIFF`, `CONFLICTING_STATE`, `WRONG_BASE`). Stop on conflicts. Read target Gitea issue/milestone state via `gt issue`, `gt milestone`, direction docs (`ARCHITECTURE.md`, `ROADMAP.md`), and `git status --short`. Clarify ambiguous intent; hand off to `gitea-plan` if tracking issues must be created first.
|
||||
2. **Select orchestration topology (`complexity x risk`).** Combine planning size with assurance risk per [orchestration-tiers](references/orchestration-tiers.md). Keep pure-orchestrator invariants: retain plan, status, commit SHAs, QA dispositions, blockers; never edit implementation files, repair Git via code edits, self-certify QA, or ingest full test logs unless resolving a failure.
|
||||
3. **Lock Planned Workflow and pre-committed rubrics.** Formulate the Planned Workflow using the Canonical Node Schema (5-tuples: `node_id`, `claim`, `method`, `executor`, `pass_condition`). Project a dynamic Mermaid diagram deriving directly from node IDs with visible rework edges. If `--dry-run` is active, halt after displaying the plan (enforce 0 file changes, 0 commits, 0 remote calls). Hard gate: pause for human approval.
|
||||
4. **Assign workspaces and delegate implementation.** Govern branch/worktree lifecycle through `git-manager` per [orchestration-tiers](references/orchestration-tiers.md). Dispatch worker subagent(s) with the Implementation Assignment in [handoff-contracts](references/handoff-contracts.md). Never run concurrent workers in the same working tree. Update the runtime Execution Record table as nodes change state.
|
||||
5. **Audit worker reports and run rubric QA.** Verify worker reports via read-only Git checks. Spawn read-only QA subagents running `verify-slice` against pre-committed rubrics. Update Execution Record with concrete evidence (SHA, exit codes).
|
||||
6. **Triage outcomes and route rework.** Classify failures using [handoff-contracts](references/handoff-contracts.md): route code defects to existing worker via `send_message`; record justified rubric amendments if criteria change. Loop Steps 4-6 until all nodes pass.
|
||||
7. **Enforce final-HEAD evidence, deviation report, and integrate.** Confirm `code-review` (`Ready`) and `verify-slice` match the exact final `HEAD` and base. Present the Execution Deviation Report (skipped/added checks, rework iterations, scope drift). Integrate per [orchestration-tiers](references/orchestration-tiers.md) Policy Matrix: fast-forward merge if repo `AGENTS.md` permits and user approves, else hand off to `gitea-pr`.
|
||||
|
||||
## Your call
|
||||
- **Session mode**: decide whether to switch from `learning` to `delivery` before autonomous delegation.
|
||||
- **Plan and pre-committed rubrics**: approve task decomposition, assurance tier, workspace topology, and QA rubrics before any implementation worker spawns.
|
||||
- **Rubric amendments, `live-infra`, and trade-offs**: approve any rubric change that relaxes criteria or alters scope, authorize `live-infra` checks, and adjudicate unresolved conflicts or review disagreements.
|
||||
- **PR packaging and release**: approve PR creation/updates and authorize merge (or accept local slice delivery when no PR applies).
|
||||
- **Planned workflow and rubrics**: approve task breakdown, node 5-tuples, assurance tier, and QA rubrics before workers spawn.
|
||||
- **Rubric amendments, live-infra, and trade-offs**: approve rubric criteria changes, authorize `live-infra` checks, and adjudicate review conflicts.
|
||||
- **Integration authorization**: authorize direct merge to main or PR creation and merge.
|
||||
|
||||
## Done when
|
||||
- All slice checkpoints are committed on a clean target branch, `code-review` (`Ready`) and `verify-slice` (zero unhandled `FAIL`) match the same final `HEAD` and base revision, and either `gitea-pr` has packaged the PR or final evidence has been delivered directly when no PR applies.
|
||||
- All slice checkpoints are committed on a clean target branch, `code-review` (`Ready`) and `verify-slice` match the same final `HEAD`, the Execution Deviation Report is recorded, and the branch is integrated per policy.
|
||||
|
||||
## Hands off to
|
||||
- `gitea-plan`: when goals or epics require milestone and issue decomposition before slice execution.
|
||||
@@ -41,4 +41,4 @@ description: >-
|
||||
- `verify-slice`: inside QA subagents for pre-committed chunk and final-`HEAD` runtime verification.
|
||||
- `code-review`: for final-slice 4-axis static and strategic alignment inspection.
|
||||
- `diagnose`: when an unexpected failure requires evidence-first root-cause investigation.
|
||||
- `gitea-pr`: when a PR applies and final-`HEAD` review plus verification packets are ready.
|
||||
- `gitea-pr`: when policy or remote CI mandates a pull request and final-`HEAD` packets are ready.
|
||||
@@ -2,7 +2,20 @@
|
||||
|
||||
Reference for `implement-slice`. Every delegation uses explicit, bounded schemas so subagents execute deterministically and return compact evidence packets.
|
||||
|
||||
## 1. Implementation Assignment (Orchestrator -> Worker)
|
||||
## 1. Preflight Branch and Worktree Safeguards
|
||||
|
||||
Before decomposing or delegating work, inspect `git status --short` and `git branch -v`:
|
||||
|
||||
| Working Tree & Branch State | Classification | Orchestrator Action |
|
||||
| :--- | :--- | :--- |
|
||||
| **Clean tree on target base branch** | `CLEAN_BASE` | Proceed directly to plan formulation. |
|
||||
| **Tree contains uncommitted changes matching the target slice** | `ADOPTABLE_DIFF` | Offer to adopt uncommitted changes into the new slice branch. |
|
||||
| **Tree has uncommitted edits to unrelated files or sits on an unmerged PR branch** | `CONFLICTING_STATE` | **Hard Stop.** Report active branch and diff stat. Offer structured options (stash, commit to existing branch, switch). |
|
||||
| **Current branch does not match intended base** | `WRONG_BASE` | **Hard Stop.** Halt and prompt user to switch to target base before branching. |
|
||||
|
||||
---
|
||||
|
||||
## 2. Implementation Assignment (Orchestrator -> Worker)
|
||||
|
||||
Provide before spawning (or messaging) an implementation worker:
|
||||
|
||||
@@ -14,7 +27,7 @@ Provide before spawning (or messaging) an implementation worker:
|
||||
- **Checkpoint Expectation**: Expected coherent commit boundary (or boundaries) following `git-manager` Conventional Commits.
|
||||
- **Required Compact Report**: Request concise structured output (no raw multi-hundred-line logs unless a check fails).
|
||||
|
||||
## 2. Implementation Report (Worker -> Orchestrator)
|
||||
## 3. Implementation Report (Worker -> Orchestrator)
|
||||
|
||||
Require each worker to return:
|
||||
|
||||
@@ -26,7 +39,7 @@ Require each worker to return:
|
||||
|
||||
---
|
||||
|
||||
## 3. Pre-Committed QA Rubric Assignment (Orchestrator -> QA Subagent)
|
||||
## 4. Pre-Committed QA Rubric Assignment (Orchestrator -> QA Subagent)
|
||||
|
||||
The rubric is written and approved during Step 3 (before implementation begins). When spawning the QA subagent:
|
||||
|
||||
@@ -35,7 +48,7 @@ The rubric is written and approved during Step 3 (before implementation begins).
|
||||
- **Pre-Committed Falsifiable Checks**: Numbered checks with scope (`local` vs. `live-infra`), exact pass conditions, `FAIL if ...` signals, and any `code-review` Step 6 `RV-*` checks.
|
||||
- **Authorization Boundary**: Explicitly state whether any `live-infra` check has human owner authorization for this run (default: unauthorized -> record `BLOCKED (out-of-bounds)`).
|
||||
|
||||
## 4. QA Report (QA Subagent -> Orchestrator)
|
||||
## 5. QA Report (QA Subagent -> Orchestrator)
|
||||
|
||||
Follows the `verify-slice` disposition contract:
|
||||
|
||||
@@ -46,7 +59,47 @@ Follows the `verify-slice` disposition contract:
|
||||
|
||||
---
|
||||
|
||||
## 5. Failure Triage and Rubric Amendment Routing
|
||||
## 6. The Tripartite Workflow Contract Schemas
|
||||
|
||||
### A. Planned Workflow Schema (Step 3 Gate)
|
||||
```markdown
|
||||
### Planned Workflow
|
||||
- **Task Breakdown**:
|
||||
- `TASK-01`: <Objective> (Role: Worker, Scope: <files>, Commits: <expected-commits>)
|
||||
- **Verification Plan**:
|
||||
- `CHK-01`: Claim: <invariant>, Method: <cmd>, Executor: <role>, Pass: <condition>, Failure: <route>
|
||||
- **Workflow Graph**:
|
||||
```mermaid
|
||||
<dynamic-projection-from-nodes>
|
||||
```
|
||||
```
|
||||
|
||||
### B. Execution Record Schema (Steps 4–5 Log)
|
||||
Updated dynamically in orchestrator turns:
|
||||
```markdown
|
||||
| Node ID | Claim / Invariant | Method | Executor | Evidence | Pass Condition | Status |
|
||||
| :--- | :--- | :--- | :--- | :--- | :--- | :--- |
|
||||
| `TASK-01` | <claim> | <method> | <role> | Commit `<sha>` | Clean tree | `passed` |
|
||||
| `CHK-01` | <claim> | <method> | <role> | Exit 0 stdout | Exit 0 | `passed` |
|
||||
```
|
||||
|
||||
### C. Deviation Report Schema (Step 6 Handoff)
|
||||
```markdown
|
||||
### Execution Deviation Report
|
||||
- **Skipped Checks**: <None | List of skipped checks with explicit rationale>
|
||||
- **Added Checks**: <None | New checks introduced in response to findings>
|
||||
- **Rework Iterations**: <0 | Details of remediation loops and commit references>
|
||||
- **Scope Drift**: <None | Differences between planned and actual seams>
|
||||
```
|
||||
|
||||
### Dynamic Mermaid Projection Rules
|
||||
- **Derive directly from nodes**: Nodes in the graph must match `node_id`s from the planned workflow table.
|
||||
- **Expose falsification routes**: Graph edges must explicitly show failure paths (e.g. `QA -- "Fail (rework)" --> Worker`).
|
||||
- **Never paste generic templates**: Every diagram must reflect the exact slice tasks and assurance checks.
|
||||
|
||||
---
|
||||
|
||||
## 7. Failure Triage and Rubric Amendment Routing
|
||||
|
||||
Never relay "QA failed" blindly. Classify each non-passing outcome and route to the right owner:
|
||||
|
||||
@@ -61,7 +114,7 @@ Never relay "QA failed" blindly. Classify each non-passing outcome and route to
|
||||
|
||||
---
|
||||
|
||||
## 6. Final-HEAD Evidence Invariant and Terminal Delivery
|
||||
## 8. Final-HEAD Evidence Invariant and Terminal Delivery
|
||||
|
||||
### The Invariant
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ Reference for `implement-slice`. Defines how the orchestrator combines existing
|
||||
|
||||
These boundaries hold across every slice size and risk tier:
|
||||
|
||||
1. **No implementation or self-certified QA**: The orchestrator never edits product or test files, creates ad-hoc fixup commits, executes mutations to repair broken code, or declares runtime QA passing without worker/QA evidence. Read-only inspection (`tea`, `git status`, `git log`, `git diff --stat`, targeted file reads to check a contradiction) is allowed.
|
||||
1. **No implementation or self-certified QA**: The orchestrator never edits product or test files, creates ad-hoc fixup commits, executes mutations to repair broken code, or declares runtime QA passing without worker/QA evidence. Read-only inspection (`gt`, `git status`, `git log`, `git diff --stat`, targeted file reads to check a contradiction) is allowed.
|
||||
2. **Context-budget discipline**:
|
||||
- **Retain in orchestrator context**: approved slice plan, task dependency status, assigned workspace/branch refs, checkpoint commit SHAs, QA check dispositions, active blockers, and open human decisions.
|
||||
- **Delegate out of orchestrator context**: full test suite transcripts, build logs, browser traces, and line-by-line edit narratives. Require concise structured reports with exact references (commit SHAs, `path:line` locations, check IDs, or log/artifact paths) and inspect raw output only when resolving a discrepancy or failure.
|
||||
@@ -46,3 +46,55 @@ Explicit ownership prevents concurrent working-tree corruption and keeps Git rec
|
||||
1. **Sequential default**: Prefer sequential task delegation on a single slice branch when tasks touch related modules or take minutes rather than hours; parallel worktrees pay an integration cost.
|
||||
2. **Mandatory isolation for concurrency**: Never run two implementation subagents concurrently in the same working directory. Concurrent implementation tasks require separate `git-manager` worktrees and an explicit integration step before final-`HEAD` review.
|
||||
3. **Stateful worker reuse**: Retain each worker's subagent `conversationId`. When QA or `code-review` routes actionable rework back on a task, message that existing worker (`send_message`) so it retains design context instead of spawning a cold worker. Spawn a fresh worker only for a distinct new task or when the original worker session is unavailable.
|
||||
|
||||
---
|
||||
|
||||
## 4. Canonical Workflow Node Schema & Proportional Scaling
|
||||
|
||||
Every task, check, and gate in the slice workflow is represented by a structured node to enable inspectability and comparison:
|
||||
|
||||
### Mandatory Core Fields (All Nodes)
|
||||
- **`node_id`**: Stable identifier (e.g. `TASK-01`, `CHK-UNIT-01`, `GATE-MERGE`).
|
||||
- **`claim`**: The observable behavior, contract, or invariant being asserted.
|
||||
- **`method`**: Concrete execution mechanism or harness (e.g. `node:test`, `pytest -m contract`, `git diff --check`, manual user review).
|
||||
- **`executor`**: Specific assigned role (`Implementation Worker`, `Independent QA Subagent`, `Reviewer Subagent`, `Human Owner`).
|
||||
- **`pass_condition`**: Deterministic pass/fail criterion (e.g. exit code 0, regex match, zero uncommitted files).
|
||||
- **`status`**: Evidence-backed execution state:
|
||||
* `planned`: Defined, not yet executed.
|
||||
* `blocked`: Cannot run due to unmet prerequisite.
|
||||
* `skipped`: Deliberately omitted, with recorded rationale.
|
||||
* `failed`: Ran and failed pass condition (failure log recorded).
|
||||
* `passed`: Verified with concrete evidence. Missing evidence strictly prohibits `passed`.
|
||||
|
||||
### Optional / Scaled Fields (Omitted or Simplified for Simple Slices)
|
||||
- **`failure_route`**: For routine/doc tasks, defaults to *"rework in-place and rerun affected check"*; complex slices specify explicit rework loops across delegated subagents.
|
||||
- **`evidence`**: Simple doc/format tasks record exit code and commit SHA; complex code tasks attach stdout, DOM snapshots, or test run logs.
|
||||
- **Separate QA Executor**: Documentation and routine edits use the implementation agent directly; high-risk slices mandate independent verifier subagents.
|
||||
|
||||
---
|
||||
|
||||
## 5. Runtime Observability Timeline & Dry-Run Invariants
|
||||
|
||||
Observability is an active oversight instrument during execution, not a retrospective summary:
|
||||
|
||||
1. **Pre-Execution (Gate 1)**: Orchestrator surfaces the **Planned Workflow** (structured node definitions and dynamic Mermaid projection) in chat prose for human approval before spawning workers.
|
||||
2. **During Execution (Runtime Updates)**: Orchestrator dynamically updates the **Execution Record** as nodes transition states (`planned` -> `passed` / `failed` / `blocked` / `skipped`), exposing progress and failure-rework loops in orchestrator turn updates.
|
||||
3. **Post-Execution (Step 6 Handoff)**: Orchestrator presents the **Deviation Report** comparing actual execution against the plan, alongside links to verified commit SHAs.
|
||||
|
||||
### Dry-Run Mode (`/implement-slice --dry-run`)
|
||||
Dry-run mode is defined strictly by **zero side-effects and zero mutations**:
|
||||
- Produces the complete planned workflow, scope analysis, verification 5-tuples, and proposed diffs.
|
||||
- Enforces 0 uncommitted changes, 0 new Git commits, 0 remote pushes, and 0 Gitea issue/PR/milestone mutations.
|
||||
|
||||
---
|
||||
|
||||
## 6. Policy-Aware Integration Strategy Matrix
|
||||
|
||||
The choice between direct fast-forward merge and opening a Gitea pull request is governed by repository policy and authorization, not developer convenience:
|
||||
|
||||
| Factor | Direct Fast-Forward Merge | Pull Request (`gt pr create`) |
|
||||
| :--- | :--- | :--- |
|
||||
| **Repository `AGENTS.md`** | Must explicitly permit direct commits/merges to `main`. | Mandatory whenever repo policy prohibits direct commits to `main`. |
|
||||
| **CI / Actions Requirement** | Permitted only if no remote CI workflows are required before merge. | Mandatory whenever remote Gitea Actions CI or deployment pipelines must validate branch. |
|
||||
| **Review & QA Status** | Final-`HEAD` `code-review` and `verify-slice` evidence packets must be clean. | Packaged into PR body (`Closes #<id>`, review provenance, verification ledger). |
|
||||
| **Human Authorization** | Explicit human approval required before merging. | Human owner authorizes creation and final merge. |
|
||||
Reference in new issue
Block a user