Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .planning/STATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ See: .planning/PROJECT.md (updated 2026-03-25)
Phase: 53 of 53 (Skill Deprecation) — COMPLETED
Plan: 53-01 of 1 — COMPLETED
Status: All phases complete — /nf:model-driven-fix deprecated, all consumers rewired to /nf:debug
Last activity: 2026-03-26 - Completed quick task 361: Add automation-first bias to verify-work and execute-phase workflows
Last activity: 2026-03-27 - Completed quick task 363: Push Loop 2 + debug_context into execute-plan.md Pattern A

Progress: [██████████] 100% (Phase 50 done; Phase 51 done; Phase 52 done; Phase 53 done)

Expand Down Expand Up @@ -79,6 +79,8 @@ None yet.
| 359 | Close gap: allow formal_artifacts create when scope-scan empty | 2026-03-26 | afdea71c | Verified | [359-close-the-gap-when-formal-scope-scan-fin](./quick/359-close-the-gap-when-formal-scope-scan-fin/) |
| 360 | Add risk-based adaptive quorum fan-out: risk classifier, adaptive dispatch, audit logging | 2026-03-26 | 8e27fe35 | Verified | [360-add-risk-based-adaptive-quorum-fan-out-r](./quick/360-add-risk-based-adaptive-quorum-fan-out-r/) |
| 361 | Add automation-first bias to verify-work and execute-phase workflows | 2026-03-26 | afbeac9e | Verified | [361-add-automation-first-bias-to-verify-work](./quick/361-add-automation-first-bias-to-verify-work/) |
| 362 | Wire debug routing (Loop 1 + task classification + debug_context injection) into execute-phase.md | 2026-03-27 | 813c1d77 | Verified | [362-wire-debug-routing-into-execute-phase-md](./quick/362-wire-debug-routing-into-execute-phase-md/) |
| 363 | Push Loop 2 + debug_context into execute-plan.md Pattern A spawn prompt | 2026-03-27 | 72bbe22d | Verified | [363-push-loop-2-and-debug-context-into-execu](./quick/363-push-loop-2-and-debug-context-into-execu/) |

### Blockers/Concerns

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
task_id: 362
description: "Wire debug routing (Loop 1 + task classification + autoresearch-refine + debug_context injection) into execute-phase.md"
formal_artifacts: none
---

# Plan: Wire Debug Routing into execute-phase.md

## Objective

Add per-plan task classification and debug routing to `execute-phase.md` so that bug-fix plans get routed through `/nf:debug` (Loop 1 autoresearch-refine) before execution, with constraints injected into executor prompts — matching the `quick.md` Step 5.8 pattern.

## Must-Haves

1. Per-plan Haiku task classification (bug_fix/feature/refactor) in the execute_waves step, before spawning each executor
2. Debug routing: bug_fix plans (confidence >= 0.7) dispatched through `/nf:debug` before executor spawn
3. Debug context injection: `<debug_context>` block conditionally injected into executor prompt with constraints, verdict, and reproducing model
4. Fail-open: all new logic skips silently on Haiku unavailability, debug errors, or missing modules
5. Sync repo source → installed copy after edit

## Tasks

### Task 1: Add per-plan task classification to execute_waves step

In `core/workflows/execute-phase.md`, inside `<step name="execute_waves">`, add a classification sub-step BEFORE spawning executor agents (before item 2 "Spawn executor agents"). For each plan in the wave:

1. Read the plan's `<objective>` text
2. Spawn Haiku subagent to classify the plan objective as bug_fix/feature/refactor (same prompt as quick.md Step 2.7 sub-step 1.5)
3. Store `$PLAN_CLASSIFICATION` per plan
4. Fail-open: default to `{ type: "feature", confidence: 0.0 }` if Haiku unavailable

### Task 2: Add debug routing step between classification and executor spawn

Add a new sub-step after classification, before executor spawn:

1. **Skip if:** `$PLAN_CLASSIFICATION.type` is NOT `bug_fix`, OR confidence < 0.7
2. **If routing:** Spawn `/nf:debug` as Task subagent with the plan objective as failure context (same pattern as quick.md Step 5.8 item 2)
3. Parse debug output → extract `$DEBUG_CONSTRAINTS`, `$DEBUG_FORMAL_VERDICT`, `$DEBUG_REPRODUCING_MODEL`
4. Fail-open: on error, set all debug vars to null and continue

### Task 3: Inject debug_context block into executor prompt

Modify the executor Task spawn (item 2 in execute_waves) to conditionally include a `<debug_context>` block after the `</formal_coverage_auto_detection>` section:

```
${DEBUG_CONSTRAINTS || DEBUG_FORMAL_VERDICT || DEBUG_REPRODUCING_MODEL ?
`<debug_context>
This plan was routed through /nf:debug before execution...
</debug_context>` : ''}
```

Same template as quick.md lines 877-886.

### Task 4: Sync to installed copy

```bash
cp core/workflows/execute-phase.md ~/.claude/nf/workflows/execute-phase.md
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Verification: Quick Task 362

## Must-Haves

| # | Requirement | Status | Evidence |
|---|---|---|---|
| 1 | Per-plan Haiku task classification before executor spawn | PASS | Step 1.5a at line 108 — Haiku classifies plan objective as bug_fix/feature/refactor |
| 2 | Debug routing for bug_fix plans (confidence >= 0.7) | PASS | Step 1.5b at line 145 — spawns /nf:debug before executor |
| 3 | debug_context block injected into executor prompt | PASS | Lines 253-262 — conditional block with constraints, verdict, reproducing model |
| 4 | Fail-open on all new logic | PASS | Line 139 (classification fallback), line 148 (debug vars null on skip), line 185 (debug error → null + continue) |
| 5 | Sync repo source → installed copy | PASS | `cp core/workflows/execute-phase.md ~/.claude/nf/workflows/execute-phase.md` — verified via diff |

## Pattern Match with quick.md

| Element | quick.md | execute-phase.md | Match |
|---|---|---|---|
| Classification | Step 2.7 sub-step 1.5 | Step 1.5a | Yes — same Haiku prompt, same JSON schema |
| Debug routing | Step 5.8 | Step 1.5b | Yes — same skip condition, same /nf:debug prompt |
| Debug context injection | Lines 877-886 | Lines 253-262 | Yes — same template |
| Fail-open | Fallback to feature/0.0 | Fallback to feature/0.0 | Yes |

## Status: Verified
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"nf/quick-362-wire-debug-routing-into-execute-phase-md": {
"task_id": 362,
"task_description": "Wire debug routing (Loop 1 + task classification + autoresearch-refine + debug_context injection) into execute-phase.md — matching the quick.md Step 5.8 pattern",
"approach": "Add phase-level task classification and debug routing to execute-phase.md's plan execution loop, dispatching bug-fix phases through /nf:debug before execution and injecting formal constraints into executor prompts, matching the quick.md Step 5.8 pattern.",
"out_of_scope": [
"Rewriting the /nf:debug skill itself — only phase-level routing and constraint injection are in scope",
"Cross-phase bug-fix dependencies — phase classification is per-plan, not per-milestone",
"Modifying quick.md — only execute-phase.md is in scope"
],
"classification": {
"type": "feature",
"confidence": 0.85,
"routed_through_debug": false
},
"risk_level": "high",
"risk_reason": "Workflow file modification (execute-phase.md) — guardrail-protected",
"branches_affected": ["nf/quick-362-wire-debug-routing-into-execute-phase-md"],
"created_at": "2026-03-27T12:46:04.416Z",
"planner_model": "inherit",
"created_by": "quick-orchestrator"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
task_id: 363
description: "Push Loop 2 and debug_context into execute-plan.md Pattern A spawn prompt"
formal_artifacts: none
---

# Plan: Push Loop 2 + debug_context into Pattern A

## Objective

Expand the Pattern A spawn prompt in `execute-plan.md` to include `<formal_coverage_auto_detection>` (Loop 2) and `<debug_context>` blocks, so the nested child nf-executor inherits both verification loops when committing.

## Must-Haves

1. Pattern A spawn prompt includes `<formal_coverage_auto_detection>` block with Loop 2 (solution-simulation-loop)
2. Pattern A spawn prompt includes conditional `<debug_context>` passthrough from parent context
3. Pattern B confirmed safe (orchestrator commits, not subagent) — no changes needed
4. Fail-open preserved on all new blocks
5. Sync repo source → installed copy

## Analysis

- **Pattern A** (line 121): Currently a one-liner prose description. Expand to include formal blocks in the prompt specification.
- **Pattern B** (line 123): Segment subagents do NOT commit — orchestrator (main context) commits. Orchestrator has Loop 2. **No change needed.**
- **Pattern C** (line 125): Executes in main context. Has Loop 2. **No change needed.**
- **Pattern D** (lines 130+): Worktree executors with minimal prompts. Opt-in only (--parallel flag). **Defer to separate task.**

## Tasks

### Task 1: Expand Pattern A spawn description to include formal blocks

Replace the Pattern A one-liner at line 121 with an expanded prompt specification that includes:
1. The existing instructions (execute plan, autonomous, all tasks, SUMMARY, commit, deviation/auth rules)
2. `<formal_coverage_auto_detection>` block (same as execute-phase.md lines 217-251)
3. `<debug_context>` passthrough: `${PARENT_DEBUG_CONTEXT || ''}` — the parent executor passes any debug_context it received from the orchestrator

Note: The parent nf-executor (spawned by execute-phase.md) receives `$DEBUG_CONSTRAINTS`, `$DEBUG_FORMAL_VERDICT`, `$DEBUG_REPRODUCING_MODEL` from the orchestrator's debug routing. When spawning the Pattern A child, the parent must forward these as a `<debug_context>` block in the child's prompt.

### Task 2: Sync to installed copy

```bash
cp core/workflows/execute-plan.md ~/.claude/nf/workflows/execute-plan.md
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Verification: Quick Task 363

## Must-Haves

| # | Requirement | Status | Evidence |
|---|---|---|---|
| 1 | Pattern A includes formal_coverage_auto_detection (Loop 2) | PASS | Lines 132-154 — full block with simulateSolutionLoop, gates, fail-open |
| 2 | Pattern A includes debug_context passthrough | PASS | Line 156 — `${PARENT_DEBUG_CONTEXT || ''}` + line 161 passthrough docs |
| 3 | Pattern B confirmed safe (orchestrator commits) | PASS | Line 123 — "Autonomous segments: NO SUMMARY/commit", orchestrator does final commit |
| 4 | Fail-open preserved | PASS | Lines 140, 152, 153 — skip silently on errors/missing modules |
| 5 | Sync repo → installed copy | PASS | `cp` verified via diff |

## End-to-End Trace

```
User runs /nf:execute-phase
→ execute-phase.md Step 1.5: Classify plan → route bug_fix through /nf:debug (Loop 1)
→ execute-phase.md Step 2: Spawn nf-executor with <formal_coverage_auto_detection> + <debug_context>
→ nf-executor reads execute-plan.md
→ Pattern C: executes in main context → has Loop 2 + debug_context ✓
→ Pattern A: spawns child nf-executor with Loop 2 + debug_context passthrough ✓ (NEW)
→ Pattern B: segment subagents don't commit, orchestrator commits with Loop 2 ✓
→ Pattern D: worktree executors — no loops (opt-in only, deferred)
```

## Status: Verified
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"nf/quick-362-wire-debug-routing-into-execute-phase-md": {
"task_id": 363,
"task_description": "Push Loop 2 (formal_coverage_auto_detection + solution-simulation-loop) and debug_context into execute-plan.md Pattern A spawn prompt",
"approach": "Inject formal_coverage_auto_detection, solution-simulation-loop, and debug_context constraint blocks into the Pattern A nf-executor spawn prompt in execute-plan.md so nested child executors inherit both verification loops.",
"out_of_scope": [
"Implementation of Loop modules (already exist)",
"Changes to Pattern B, C, or D routing",
"Loop 1 debug routing integration (already handled at orchestrator level)"
],
"classification": {
"type": "feature",
"confidence": 0.85,
"routed_through_debug": false
},
"risk_level": "high",
"risk_reason": "Workflow file modification (execute-plan.md) — guardrail-protected",
"branches_affected": ["nf/quick-362-wire-debug-routing-into-execute-phase-md"],
"created_at": "2026-03-27T13:46:18.360Z",
"planner_model": "inherit",
"created_by": "quick-orchestrator"
}
}
94 changes: 94 additions & 0 deletions core/workflows/execute-phase.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,89 @@ node ~/.claude/nf/bin/gsd-tools.cjs activity-set \
- Bad: "Executing terrain generation plan"
- Good: "Procedural terrain generator using Perlin noise — creates height maps, biome zones, and collision meshes. Required before vehicle physics can interact with ground."

1.5. **Classify plan type and debug routing (ROUTE-02, ROUTE-03):**

For each plan, classify its objective and optionally route through `/nf:debug` before execution.

**1.5a. Classify plan type via Haiku subagent:**

Spawn a Haiku subagent to classify the plan's objective:

```
Task(
subagent_type="general-purpose",
model="haiku",
description="Classify plan type for debug routing",
prompt="
You are classifying a development plan into exactly one category.

## Plan Objective
{plan_objective_text from <objective> tag}

## Categories
- bug_fix: The plan fixes a bug, error, regression, crash, or broken behavior.
- feature: The plan adds new functionality or capability.
- refactor: The plan reorganizes, renames, cleans up, or simplifies existing code without changing behavior.

Respond with ONLY a JSON object:
{
\"type\": \"bug_fix\" | \"feature\" | \"refactor\",
\"confidence\": 0.0-1.0
}
"
)
```

Parse response as JSON. Store as `$PLAN_CLASSIFICATION`.

**Fail-open:** If Haiku is unavailable or JSON parse fails, use `{ "type": "feature", "confidence": 0.0 }`.

Log: `"Plan classification: ${PLAN_CLASSIFICATION.type} (confidence: ${PLAN_CLASSIFICATION.confidence})"`

**1.5b. Debug routing:**

**Skip if:** `$PLAN_CLASSIFICATION.type` is NOT `bug_fix`, OR `$PLAN_CLASSIFICATION.confidence` < 0.7.

If skipped, log: `"Debug routing: skipped (type: ${PLAN_CLASSIFICATION.type}, confidence: ${PLAN_CLASSIFICATION.confidence})"`
Set `$DEBUG_CONSTRAINTS = null`, `$DEBUG_FORMAL_VERDICT = null`, `$DEBUG_REPRODUCING_MODEL = null`.

**If routing:**

1. Log: `"Debug routing: bug_fix detected (confidence: ${PLAN_CLASSIFICATION.confidence}) — routing through /nf:debug"`

2. Spawn `/nf:debug` as a Task subagent:

```
Task(
prompt="
Run /nf:debug with the following failure context.

## Plan Objective (from phase plan)
{plan_objective_text}

## Instructions
- Run the full debug pipeline (Steps A through A.8: collect context, discovery, reproduction, refinement, constraint extraction)
- Return the debug output including:
- \$CONSTRAINTS (extracted constraints from Loop 1, if any)
- \$FORMAL_VERDICT (pass/fail/skip from formal model checking, if any)
- \$REPRODUCING_MODEL (path to reproducing formal model, if any)
- If any step fails or produces no output, continue with remaining steps (fail-open)
- Do NOT fix the bug — only diagnose and extract constraints. The executor will apply the fix.
",
subagent_type="general-purpose",
description="Debug routing for plan {plan_number}: {plan_objective_summary}"
)
```

3. Parse debug output. Extract and store:
- `$DEBUG_CONSTRAINTS` — constraints from Loop 1 refinement (may be empty)
- `$DEBUG_FORMAL_VERDICT` — formal model check result (may be "skipped")
- `$DEBUG_REPRODUCING_MODEL` — path to reproducing model (may be null)

4. Log: `"Debug routing complete. Constraints: ${DEBUG_CONSTRAINTS ? 'found' : 'none'}, Verdict: ${DEBUG_FORMAL_VERDICT || 'skipped'}"`

**Fail-open:** If the debug subagent errors or times out, log a warning and proceed without debug context. Set all debug vars to null.

2. **Spawn executor agents:**

Pass paths only — executors read files themselves with their fresh 200k context.
Expand Down Expand Up @@ -167,6 +250,17 @@ node ~/.claude/nf/bin/gsd-tools.cjs activity-set \
6. If step 2 found NO intersections: skip Loop 2 entirely (GATE-03) — silent, no log
</formal_coverage_auto_detection>

${DEBUG_CONSTRAINTS || DEBUG_FORMAL_VERDICT || DEBUG_REPRODUCING_MODEL ?
`<debug_context>
This plan was routed through /nf:debug before execution. Use the following debug output as supplementary context for your implementation:

${DEBUG_CONSTRAINTS ? '**Constraints from formal model refinement:**\n' + DEBUG_CONSTRAINTS : ''}
${DEBUG_FORMAL_VERDICT ? '**Formal verdict:** ' + DEBUG_FORMAL_VERDICT : ''}
${DEBUG_REPRODUCING_MODEL ? '**Reproducing model:** ' + DEBUG_REPRODUCING_MODEL : ''}

These constraints inform the fix but do not gate it. If constraints conflict with the plan, follow the plan.
</debug_context>` : ''}

<success_criteria>
- [ ] All tasks executed
- [ ] Each task committed individually
Expand Down
Loading
Loading