Skip to content

try-works/role-model / .agents/skills/recursive-mode

recursive-mode

Unverified

Repository workflow orchestration skill for staged implementation, locked artifacts, late-phase receipts, and durable memory maintenance. Use when executing recursive-mode runs, resuming a run, locking a phase, or verifying locks.

FileKindSize
.agent/PLANS.mdmarkdown2.6 KB
.codex/AGENTS.mdmarkdown7.5 KB
.gitattributesother522 B
.gitignoreother553 B
.recursive/AGENTS.mdmarkdown3.3 KB
.recursive/DECISIONS.mdmarkdown1.1 KB
.recursive/README.mdmarkdown8.5 KB
.recursive/RECURSIVE.mdmarkdown107.5 KB
.recursive/STATE.mdmarkdown1.6 KB
.recursive/config/recursive-router.jsonconfig1.4 KB
.recursive/memory/MEMORY.mdmarkdown3.3 KB
.recursive/memory/archive/.gitkeepother1 B
.recursive/memory/domains/.gitkeepother1 B
.recursive/memory/episodes/.gitkeepother1 B
.recursive/memory/incidents/.gitkeepother1 B
.recursive/memory/patterns/.gitkeepother1 B
.recursive/memory/skills/SKILLS.mdmarkdown4.3 KB
.recursive/memory/skills/availability/.gitkeepother1 B
.recursive/memory/skills/issues/.gitkeepother1 B
.recursive/memory/skills/patterns/.gitkeepother1 B
.recursive/memory/skills/patterns/delegated-verification-and-refresh.mdmarkdown1.7 KB
.recursive/memory/skills/patterns/phase8-skill-memory-promotion.mdmarkdown1.4 KB
.recursive/memory/skills/usage/.gitkeepother1 B
.recursive/memory/skills/usage/skill-discovery-and-evaluation.mdmarkdown1.6 KB
.recursive/run/.gitkeepother1 B
AGENTS.mdmarkdown7.8 KB
LICENSEother11.1 KB
README.mdmarkdown17.8 KB
SKILL.mdskill md13.1 KB
agents/code-reviewer.mdmarkdown6.1 KB
agents/implementer.mdmarkdown6.3 KB
agents/openai.yamlconfig202 B
docs/templates/commands/check-reusable-repo-hygiene.mdmarkdown1.3 KB
docs/templates/commands/recursive-closeout.mdmarkdown2.8 KB
docs/templates/commands/recursive-init.mdmarkdown2.2 KB
docs/templates/commands/recursive-lock.mdmarkdown1.3 KB
docs/templates/commands/recursive-review-bundle.mdmarkdown3.6 KB
docs/templates/commands/recursive-status.mdmarkdown2.0 KB
docs/templates/commands/recursive-subagent-action.mdmarkdown4.2 KB
docs/templates/commands/test-recursive-mode-smoke.mdmarkdown3.4 KB
docs/templates/hooks/hooks.jsonconfig400 B
docs/templates/hooks/run-hook.cmdscript1.2 KB
docs/templates/hooks/session-start.ps1script3.6 KB
docs/templates/hooks/session-start.shscript3.5 KB
references/agents-block.mdmarkdown7.4 KB
references/artifact-template.mdmarkdown70.7 KB
references/benchmark-addon/recursive-benchmark/BENCHMARK-ADDON.mdmarkdown6.7 KB
references/benchmark-addon/recursive-benchmark/recursive-benchmark/BENCHMARK-ADDON.mdmarkdown6.7 KB
references/benchmark-addon/recursive-benchmark/recursive-benchmark/references/patterns.mdmarkdown4.9 KB
references/benchmark-addon/recursive-benchmark/references/patterns.mdmarkdown4.9 KB
references/benchmarks/README.mdmarkdown1.5 KB
references/benchmarks/local-first-planner/00-requirements.mdmarkdown3.3 KB
references/benchmarks/local-first-planner/README.mdmarkdown1.1 KB
references/benchmarks/local-first-planner/prompt-recursive-off.mdmarkdown1.1 KB
references/benchmarks/local-first-planner/prompt-recursive-on.mdmarkdown14.8 KB
references/benchmarks/local-first-planner/scoring-rubric.mdmarkdown1.3 KB
references/benchmarks/local-first-planner/starter/.gitignoreother30 B
references/benchmarks/local-first-planner/starter/README.mdmarkdown264 B
references/benchmarks/local-first-planner/starter/index.htmlother316 B
references/benchmarks/local-first-planner/starter/package.jsonmanifest628 B
references/benchmarks/local-first-planner/starter/src/App.test.tsxother334 B
references/benchmarks/local-first-planner/starter/src/App.tsxother971 B
references/benchmarks/local-first-planner/starter/src/main.tsxother238 B
references/benchmarks/local-first-planner/starter/src/styles.cssother976 B
references/benchmarks/local-first-planner/starter/src/test-setup.tsscript43 B
references/benchmarks/local-first-planner/starter/src/vite-env.d.tsscript38 B
references/benchmarks/local-first-planner/starter/tsconfig.app.jsonconfig552 B
references/benchmarks/local-first-planner/starter/tsconfig.jsonconfig89 B
references/benchmarks/local-first-planner/starter/vite.config.tsscript214 B
references/benchmarks/release-readiness-dashboard/00-requirements.mdmarkdown5.9 KB
references/benchmarks/release-readiness-dashboard/README.mdmarkdown1.2 KB
references/benchmarks/release-readiness-dashboard/prompt-recursive-off.mdmarkdown1.1 KB
references/benchmarks/release-readiness-dashboard/prompt-recursive-on.mdmarkdown14.8 KB
references/benchmarks/release-readiness-dashboard/scoring-rubric.mdmarkdown1.8 KB
references/benchmarks/release-readiness-dashboard/starter/.gitignoreother30 B
references/benchmarks/release-readiness-dashboard/starter/README.mdmarkdown272 B
references/benchmarks/release-readiness-dashboard/starter/index.htmlother324 B
references/benchmarks/release-readiness-dashboard/starter/package.jsonmanifest628 B
references/benchmarks/release-readiness-dashboard/starter/src/App.test.tsxother342 B
references/benchmarks/release-readiness-dashboard/starter/src/App.tsxother979 B
references/benchmarks/release-readiness-dashboard/starter/src/main.tsxother238 B
references/benchmarks/release-readiness-dashboard/starter/src/styles.cssother976 B
references/benchmarks/release-readiness-dashboard/starter/src/test-setup.tsscript43 B
references/benchmarks/release-readiness-dashboard/starter/src/vite-env.d.tsscript38 B
references/benchmarks/release-readiness-dashboard/starter/tsconfig.app.jsonconfig552 B
references/benchmarks/release-readiness-dashboard/starter/tsconfig.jsonconfig89 B
references/benchmarks/release-readiness-dashboard/starter/vite.config.tsscript214 B
references/benchmarks/scientific-calculator-rust/00-requirements.mdmarkdown4.1 KB
references/benchmarks/scientific-calculator-rust/README.mdmarkdown1.4 KB
references/benchmarks/scientific-calculator-rust/prompt-recursive-off.mdmarkdown1.1 KB
references/benchmarks/scientific-calculator-rust/prompt-recursive-on.mdmarkdown16.6 KB
references/benchmarks/scientific-calculator-rust/scoring-rubric.mdmarkdown1.5 KB
references/benchmarks/scientific-calculator-rust/starter/.gitignoreother14 B
references/benchmarks/scientific-calculator-rust/starter/Cargo.lockmanifest25.7 KB
references/benchmarks/scientific-calculator-rust/starter/Cargo.tomlmanifest226 B
references/benchmarks/team-capacity-board/00-requirements.mdmarkdown3.6 KB
references/benchmarks/team-capacity-board/README.mdmarkdown1.0 KB
references/benchmarks/team-capacity-board/prompt-recursive-off.mdmarkdown1.1 KB
references/benchmarks/team-capacity-board/prompt-recursive-on.mdmarkdown14.8 KB
references/benchmarks/team-capacity-board/scoring-rubric.mdmarkdown1.4 KB
references/benchmarks/team-capacity-board/starter/.gitignoreother30 B
references/benchmarks/team-capacity-board/starter/README.mdmarkdown264 B
references/benchmarks/team-capacity-board/starter/index.htmlother316 B
references/benchmarks/team-capacity-board/starter/package.jsonmanifest628 B
references/benchmarks/team-capacity-board/starter/src/App.test.tsxother334 B
references/benchmarks/team-capacity-board/starter/src/App.tsxother971 B
references/benchmarks/team-capacity-board/starter/src/main.tsxother238 B
references/benchmarks/team-capacity-board/starter/src/styles.cssother976 B
references/benchmarks/team-capacity-board/starter/src/test-setup.tsscript43 B
references/benchmarks/team-capacity-board/starter/src/vite-env.d.tsscript38 B
references/benchmarks/team-capacity-board/starter/tsconfig.app.jsonconfig552 B
references/benchmarks/team-capacity-board/starter/tsconfig.jsonconfig89 B
references/benchmarks/team-capacity-board/starter/vite.config.tsscript214 B
references/bootstrap/RECURSIVE.mdmarkdown109.9 KB
references/fixtures/tiny-tasks-smoke-recipe.mdmarkdown2.6 KB
references/local-first-web-app-checklist.mdmarkdown1.6 KB
references/plans-canonical.mdmarkdown10.8 KB
scripts/check-reusable-repo-hygiene.ps1script625 B
scripts/check-reusable-repo-hygiene.pyscript6.3 KB
scripts/install-recursive-mode.ps1script36.0 KB
scripts/install-recursive-mode.pyscript31.8 KB
scripts/install-recursive-mode.shscript363 B
scripts/lint-recursive-run.ps1script739 B
scripts/lint-recursive-run.pyscript127.4 KB
scripts/recursive-closeout.ps1script1015 B
scripts/recursive-closeout.pyscript24.0 KB
scripts/recursive-init.ps1script18.7 KB
scripts/recursive-init.pyscript12.6 KB
scripts/recursive-lock.ps1script677 B
scripts/recursive-lock.pyscript12.6 KB
scripts/recursive-review-bundle.ps1script2.9 KB
scripts/recursive-review-bundle.pyscript22.1 KB
scripts/recursive-router-cli-configure.ps1script86 B
scripts/recursive-router-cli-configure.pyscript230 B
scripts/recursive-router-cli-init.ps1script81 B
scripts/recursive-router-cli-init.pyscript225 B
scripts/recursive-router-cli-invoke.ps1script83 B
scripts/recursive-router-cli-invoke.pyscript227 B
scripts/recursive-router-cli-probe.ps1script82 B
scripts/recursive-router-cli-probe.pyscript226 B
scripts/recursive-router-cli-resolve.ps1script84 B
scripts/recursive-router-cli-resolve.pyscript228 B
scripts/recursive-router-cli-validate.ps1script85 B
scripts/recursive-router-cli-validate.pyscript229 B
scripts/recursive-router-configure.ps1script798 B
scripts/recursive-router-configure.pyscript2.8 KB
scripts/recursive-router-init.ps1script490 B
scripts/recursive-router-init.pyscript925 B
scripts/recursive-router-invoke.ps1script1.5 KB
scripts/recursive-router-invoke.pyscript4.4 KB
scripts/recursive-router-probe.ps1script735 B
scripts/recursive-router-probe.pyscript1.6 KB
scripts/recursive-router-resolve.ps1script803 B
scripts/recursive-router-resolve.pyscript1.6 KB
scripts/recursive-router-validate.ps1script494 B
scripts/recursive-router-validate.pyscript804 B
scripts/recursive-status.ps1script674 B
scripts/recursive-status.pyscript97.7 KB
scripts/recursive-subagent-action.ps1script5.8 KB
scripts/recursive-subagent-action.pyscript12.4 KB
scripts/recursive-training-extract.ps1script586 B
scripts/recursive-training-extract.pyscript1.0 KB
scripts/recursive-training-grpo.ps1script1.2 KB
scripts/recursive-training-grpo.pyscript47.2 KB
scripts/recursive-training-loader.ps1script2.3 KB
scripts/recursive-training-loader.pyscript20.1 KB
scripts/recursive-training-mcp.ps1script721 B
scripts/recursive-training-mcp.pyscript10.1 KB
scripts/recursive-training-phase8-trigger.ps1script1.4 KB
scripts/recursive-training-phase8-trigger.pyscript4.0 KB
scripts/recursive-training-sync.ps1script735 B
scripts/recursive-training-sync.pyscript6.9 KB
scripts/recursive_phase_rules.pyscript12.7 KB
scripts/recursive_router_cli_lib.pyscript77 B
scripts/recursive_router_lib.pyscript84.5 KB
scripts/run-recursive-benchmark.ps1script2.1 KB
scripts/run-recursive-benchmark.pyscript376.1 KB
scripts/test-recursive-mode-smoke.ps1script1.0 KB
scripts/test-recursive-mode-smoke.pyscript121.0 KB
scripts/test_install_recursive_mode.pyscript38.4 KB
scripts/test_lint_recursive_run.pyscript4.1 KB
scripts/test_recursive_phase_rules.pyscript21.4 KB
scripts/test_recursive_review_bundle.pyscript5.8 KB
scripts/test_recursive_router.pyscript53.3 KB
scripts/test_recursive_subagent_action.pyscript3.2 KB
scripts/test_recursive_training.pyscript12.0 KB
scripts/test_run_recursive_benchmark.pyscript160.0 KB
scripts/verify-locks.ps1script733 B
scripts/verify-locks.pyscript13.8 KB

scripts/recursive-init.ps1

View on GitHub
[CmdletBinding()]
param(
    [Parameter(Mandatory = $true)][string]$RunId,
    [string]$RepoRoot = (Get-Location).Path,
    [ValidateSet("feature", "bugfix", "refactor")][string]$Template = "feature",
    [string]$FromIssue = "",
    [switch]$Force
)

Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"

function Write-Utf8NoBom {
    param(
        [Parameter(Mandatory = $true)][string]$Path,
        [Parameter(Mandatory = $true)][AllowEmptyString()][string]$Content
    )

    $utf8NoBom = New-Object System.Text.UTF8Encoding($false)
    [System.IO.File]::WriteAllText($Path, $Content, $utf8NoBom)
}

function Ensure-Directory {
    param([Parameter(Mandatory = $true)][string]$Path)

    if (-not (Test-Path -LiteralPath $Path)) {
        New-Item -Path $Path -ItemType Directory -Force | Out-Null
        Write-Host ("[OK] Created directory: {0}" -f $Path)
    } else {
        Write-Host ("[OK] Directory exists: {0}" -f $Path)
    }
}

function Run-Git {
    param(
        [Parameter(Mandatory = $true)][string]$RepoRoot,
        [Parameter(ValueFromRemainingArguments = $true)][string[]]$Arguments
    )

    $output = & git -C $RepoRoot @Arguments 2>&1
    if ($LASTEXITCODE -ne 0) {
        return [pscustomobject]@{
            Success = $false
            Output = (($output | Out-String).Trim())
        }
    }

    return [pscustomobject]@{
        Success = $true
        Output = (($output | Out-String).Trim())
    }
}

function Get-MdFieldValue {
    param(
        [Parameter(Mandatory = $true)][string]$Content,
        [Parameter(Mandatory = $true)][string]$FieldName
    )

    $pattern = "(?m)^[ \t]*(?:[-*][ \t]+)?{0}:\s*(.+?)\s*$" -f [regex]::Escape($FieldName)
    $match = [regex]::Match($Content, $pattern)
    if (-not $match.Success) {
        return $null
    }
    return ($match.Groups[1].Value.Trim() -replace '^[`"'']+|[`"'']+$', "")
}

function Normalize-BaselineType {
    param([string]$Value)

    if ([string]::IsNullOrWhiteSpace($Value)) {
        return $null
    }

    $compact = ((($Value.Trim() -replace '^[`"'']+|[`"'']+$', "")).ToLowerInvariant() -replace "-", " ")
    $compact = [regex]::Replace($compact, "\s+", " ")
    $aliases = @{
        "commit" = "local commit"
        "branch" = "local branch"
        "remote" = "remote ref"
        "remote branch" = "remote ref"
        "merge base" = "merge-base derived"
    }
    $allowed = @("local commit", "local branch", "remote ref", "merge-base derived")
    if ($allowed -contains $compact) {
        return $compact
    }
    if ($aliases.ContainsKey($compact)) {
        return $aliases[$compact]
    }
    return $null
}

function Normalize-ComparisonReference {
    param([string]$Value)

    if ([string]::IsNullOrWhiteSpace($Value)) {
        return $null
    }

    $compact = ($Value.Trim() -replace '^[`"'']+|[`"'']+$', "")
    if (@("working-tree", "working-tree@head", "worktree", "working-tree+head") -contains $compact.ToLowerInvariant()) {
        return "working-tree"
    }
    return $compact
}

function New-RequirementsContent {
    param(
        [Parameter(Mandatory = $true)][string]$RunId,
        [Parameter(Mandatory = $true)][string]$Template,
        [string]$FromIssue
    )

    $inputs = @("- [chat summary or source notes if captured in repo]")
    if (-not [string]::IsNullOrWhiteSpace($FromIssue)) {
        $inputs += "- Source: $FromIssue"
    }
    $inputsBlock = ($inputs -join "`r`n")

    return (@'
Run: `/.recursive/run/{0}/`
Phase: `00 Requirements`
Status: `DRAFT`
Workflow version: `recursive-mode-audit-v2`
Inputs:
{1}
Outputs:
- `/.recursive/run/{0}/00-requirements.md`
Scope note: This document defines stable requirement identifiers and acceptance criteria. (Template: {2})

## TODO

- [ ] Elicit requirements from user/context
- [ ] Define requirement identifiers (R1, R2, ...)
- [ ] Write acceptance criteria for each requirement
- [ ] Document out of scope items (OOS1, OOS2, ...)
- [ ] List constraints and assumptions
- [ ] Complete Coverage Gate checklist
- [ ] Complete Approval Gate checklist

## Requirements

### `R1` <short title>

Description:
Acceptance criteria:
- [observable condition 1]
- [observable condition 2]

## Out of Scope

- `OOS1`: ...

## Constraints

- ...

## Coverage Gate
...
Coverage: FAIL

## Approval Gate
...
Approval: FAIL
'@) -f $RunId, $inputsBlock, $Template
}

function Get-GitContext {
    param([Parameter(Mandatory = $true)][string]$RepoRoot)

    $headResult = Run-Git -RepoRoot $RepoRoot "rev-parse" "--verify" "HEAD^{commit}"
    if (-not $headResult.Success -or [string]::IsNullOrWhiteSpace($headResult.Output)) {
        return [pscustomobject]@{
            Context = $null
            Error = "Unable to resolve HEAD commit for Phase 0 diff basis prefill: $($headResult.Output)"
        }
    }

    $branchResult = Run-Git -RepoRoot $RepoRoot "symbolic-ref" "--quiet" "--short" "HEAD"
    $branchName = if ($branchResult.Success -and -not [string]::IsNullOrWhiteSpace($branchResult.Output)) {
        $branchResult.Output
    } else {
        "(detached HEAD)"
    }

    $headSha = $headResult.Output
    return [pscustomobject]@{
        Context = [pscustomobject]@{
            baseline_type = "local commit"
            baseline_reference = $headSha
            comparison_reference = "working-tree"
            normalized_baseline = $headSha
            normalized_comparison = "working-tree"
            normalized_diff_command = "git diff --name-only $headSha"
            base_branch = $branchName
            worktree_branch = $branchName
            base_commit = $headSha
            notes = "recursive-init prefilled this executable diff basis from the current HEAD commit. If Phase 0 later changes the chosen baseline, update every diff-basis field and rerun lint before locking."
        }
        Error = $null
    }
}

function New-WorktreeContent {
    param(
        [Parameter(Mandatory = $true)][string]$RunId,
        [Parameter(Mandatory = $true)][string]$RepoRoot,
        [pscustomobject]$GitContext,
        [string]$PrefillError
    )

    $baseBranch = if ($GitContext) { $GitContext.base_branch } else { "(resolve during Phase 0)" }
    $worktreeBranch = if ($GitContext) { $GitContext.worktree_branch } else { "(resolve during Phase 0)" }
    $baseCommit = if ($GitContext) { $GitContext.base_commit } else { "<resolve-before-locking>" }
    $baselineType = if ($GitContext) { $GitContext.baseline_type } else { "local commit" }
    $baselineReference = if ($GitContext) { $GitContext.baseline_reference } else { "<resolve-before-locking>" }
    $comparisonReference = if ($GitContext) { $GitContext.comparison_reference } else { "working-tree" }
    $normalizedBaseline = if ($GitContext) { $GitContext.normalized_baseline } else { "<resolve-before-locking>" }
    $normalizedComparison = if ($GitContext) { $GitContext.normalized_comparison } else { "working-tree" }
    $normalizedDiffCommand = if ($GitContext) { $GitContext.normalized_diff_command } else { "git diff --name-only <resolve-before-locking>" }
    $notes = if ($GitContext) {
        $GitContext.notes
    } else {
        "Populate an executable diff basis before locking Phase 0. Lint and lock will fail until the normalized basis matches live git state."
    }

    $setupNote = if ([string]::IsNullOrWhiteSpace($PrefillError)) {
        "recursive-init detected the current repository context and prefilled the Phase 0 diff basis."
    } else {
        "recursive-init could not prefill the Phase 0 diff basis automatically: $PrefillError"
    }

    return (@'
Run: `/.recursive/run/{0}/`
Phase: `00 Worktree`
Status: `DRAFT`
Inputs:
- `/.recursive/run/{0}/00-requirements.md`
- Current git repository state
Outputs:
- `/.recursive/run/{0}/00-worktree.md`
Scope note: This document records the Phase 0 worktree context and the executable diff basis that all later audited phases must reuse.

## TODO

- [ ] Confirm the selected worktree location and isolation approach
- [ ] Confirm the base branch and worktree branch values
- [ ] Run setup and verify the clean test baseline
- [ ] Confirm the diff basis fields still match live git state
- [ ] Complete Coverage Gate checklist
- [ ] Complete Approval Gate checklist

## Directory Selection

- Repository root: `{1}`
- Preferred worktree location: `.worktrees/{0}/`
- Update this section with the actual selected location before locking Phase 0.

## Safety Verification

- Original branch / repo state observed at init time: `{2}`
- Isolation still must be confirmed after the actual worktree is created.

## Worktree Creation

- Intended worktree branch: `{3}`
- Record the actual worktree creation command and output before locking.

## Main Branch Protection

- Base branch source of truth at init time: `{2}`
- Explicitly document any deviation from isolated worktree execution before locking.

## Project Setup

- Init-time note: {4}
- Replace this section with the actual setup commands and results during Phase 0.

## Test Baseline Verification

- Record the baseline commands and results after setup completes.

## Worktree Context

- Base branch: `{2}`
- Worktree branch: `{3}`
- Base commit: `{5}`

## Diff Basis For Later Audits

- Baseline type: `{6}`
- Baseline reference: `{7}`
- Comparison reference: `{8}`
- Normalized baseline: `{9}`
- Normalized comparison: `{10}`
- Normalized diff command: `{11}`
- Base branch: `{2}`
- Worktree branch: `{3}`
- Diff basis notes: `{12}`

## Traceability

- Recursive workflow safety -> Phase 0 records a reusable executable diff basis before audited phases begin.

## Coverage Gate

- [ ] Worktree location and branch context are recorded
- [ ] Setup and clean baseline verification are recorded
- [ ] Diff basis fields are executable against live git state

Coverage: FAIL

## Approval Gate

- [ ] Phase 0 context is ready for downstream audited phases
- [ ] No unresolved setup or diff-basis inconsistencies remain

Approval: FAIL
'@) -f $RunId, $RepoRoot, $baseBranch, $worktreeBranch, $setupNote, $baseCommit, $baselineType, $baselineReference, $comparisonReference, $normalizedBaseline, $normalizedComparison, $normalizedDiffCommand, $notes
}

function Test-Phase0DiffBasis {
    param(
        [Parameter(Mandatory = $true)][string]$RepoRoot,
        [Parameter(Mandatory = $true)][string]$RunDir
    )

    $worktreePath = Join-Path $RunDir "00-worktree.md"
    if (-not (Test-Path -LiteralPath $worktreePath)) {
        return "00-worktree.md is missing."
    }

    $content = Get-Content -LiteralPath $worktreePath -Raw -Encoding UTF8
    $baselineType = Normalize-BaselineType (Get-MdFieldValue -Content $content -FieldName "Baseline type")
    $baselineReference = Get-MdFieldValue -Content $content -FieldName "Baseline reference"
    $comparisonReference = Normalize-ComparisonReference (Get-MdFieldValue -Content $content -FieldName "Comparison reference")
    $normalizedBaseline = Get-MdFieldValue -Content $content -FieldName "Normalized baseline"
    $normalizedComparison = Normalize-ComparisonReference (Get-MdFieldValue -Content $content -FieldName "Normalized comparison")
    $normalizedDiffCommand = Get-MdFieldValue -Content $content -FieldName "Normalized diff command"

    $missingFields = @()
    if (-not $baselineType) { $missingFields += "Baseline type" }
    if ([string]::IsNullOrWhiteSpace($baselineReference)) { $missingFields += "Baseline reference" }
    if (-not $comparisonReference) { $missingFields += "Comparison reference" }
    if ([string]::IsNullOrWhiteSpace($normalizedBaseline)) { $missingFields += "Normalized baseline" }
    if (-not $normalizedComparison) { $missingFields += "Normalized comparison" }
    if ([string]::IsNullOrWhiteSpace($normalizedDiffCommand)) { $missingFields += "Normalized diff command" }
    if ($missingFields.Count -gt 0) {
        return "Diff basis is missing required field(s): {0}" -f ($missingFields -join ", ")
    }

    $comparisonGitRef = if ($normalizedComparison -eq "working-tree") { "HEAD" } else { $normalizedComparison }
    if ($baselineType -eq "merge-base derived") {
        $baselineResult = Run-Git -RepoRoot $RepoRoot "merge-base" $comparisonGitRef $baselineReference
        if (-not $baselineResult.Success) {
            return "Unable to compute merge-base for diff basis: $($baselineResult.Output)"
        }
        $computedBaseline = $baselineResult.Output
    } else {
        $baselineResult = Run-Git -RepoRoot $RepoRoot "rev-parse" "--verify" "$baselineReference^{commit}"
        if (-not $baselineResult.Success) {
            return "Unable to resolve baseline reference '$baselineReference': $($baselineResult.Output)"
        }
        $computedBaseline = $baselineResult.Output
    }

    if ($normalizedBaseline -ne $computedBaseline) {
        return "Recorded Normalized baseline does not match the executable diff basis ($normalizedBaseline != $computedBaseline)"
    }

    if ($normalizedComparison -eq "working-tree") {
        $expectedCommand = "git diff --name-only $computedBaseline"
    } else {
        $comparisonResult = Run-Git -RepoRoot $RepoRoot "rev-parse" "--verify" "$normalizedComparison^{commit}"
        if (-not $comparisonResult.Success) {
            return "Unable to resolve comparison reference '$normalizedComparison': $($comparisonResult.Output)"
        }
        $computedComparison = $comparisonResult.Output
        if ($normalizedComparison -ne $computedComparison) {
            return "Recorded Normalized comparison does not match the executable diff basis ($normalizedComparison != $computedComparison)"
        }
        $expectedCommand = "git diff --name-only $computedBaseline..$computedComparison"
    }

    if ($normalizedDiffCommand -ne $expectedCommand) {
        return "Recorded Normalized diff command does not match the executable diff basis ($normalizedDiffCommand != $expectedCommand)"
    }

    return $null
}

function Get-TrainingLoaderQuery {
    param(
        [Parameter(Mandatory = $true)][string]$RunId,
        [Parameter(Mandatory = $true)][string]$Template,
        [string]$FromIssue
    )

    $runPhrase = (($RunId -replace '[-_]+', ' ').Trim())
    $parts = @()
    $base = ("{0} recursive run" -f $Template).Trim()
    if (-not [string]::IsNullOrWhiteSpace($base)) {
        $parts += $base
    }
    if (-not [string]::IsNullOrWhiteSpace($runPhrase)) {
        $parts += $runPhrase
    }
    if (-not [string]::IsNullOrWhiteSpace($FromIssue)) {
        $parts += $FromIssue.Trim()
    }
    return ($parts -join " ")
}

function Invoke-TrainingLoader {
    param(
        [Parameter(Mandatory = $true)][string]$RepoRoot,
        [Parameter(Mandatory = $true)][string]$RunId,
        [Parameter(Mandatory = $true)][string]$Template,
        [string]$FromIssue
    )

    $loaderPath = Join-Path $RepoRoot ".recursive\scripts\recursive-training-loader.py"
    if (-not (Test-Path -LiteralPath $loaderPath)) {
        Write-Host "[INFO] recursive-training loader not installed; skipping experiential memory load."
        return $true
    }

    $python = if ($env:PYTHON) { $env:PYTHON } elseif (Get-Command python -ErrorAction SilentlyContinue) { "python" } else { $null }
    if (-not $python) {
        Write-Host "[WARN] Python executable not found; cannot run recursive-training loader."
        Write-Host "[WARN] Continuing without loaded experiential memory."
        return $true
    }

    $query = Get-TrainingLoaderQuery -RunId $RunId -Template $Template -FromIssue $FromIssue
    $output = & $python $loaderPath "--repo-root" $RepoRoot "--query" $query 2>&1
    if ($LASTEXITCODE -ne 0) {
        $details = (($output | Out-String).Trim())
        if ([string]::IsNullOrWhiteSpace($details)) {
            $details = "no diagnostics emitted"
        }
        Write-Host ("[WARN] recursive-training loader failed: {0}" -f $details)
        Write-Host "[WARN] Continuing without loaded experiential memory."
        return $true
    }

    Write-Host "[OK] Loaded repository memory context via recursive-training."
    $rendered = (($output | Out-String).Trim())
    if (-not [string]::IsNullOrWhiteSpace($rendered)) {
        Write-Host $rendered
    }
    return $true
}

$resolvedRepoRoot = [System.IO.Path]::GetFullPath($RepoRoot)
Write-Host ("[INFO] Repo root: {0}" -f $resolvedRepoRoot)

$runRoot = Join-Path $resolvedRepoRoot ".recursive/run"
$runDir = Join-Path $runRoot $RunId

Ensure-Directory -Path $runRoot
Ensure-Directory -Path $runDir
Ensure-Directory -Path (Join-Path $runDir "addenda")
Ensure-Directory -Path (Join-Path $runDir "subagents")
Ensure-Directory -Path (Join-Path $runDir "router-prompts")

$evidenceDir = Join-Path $runDir "evidence"
Ensure-Directory -Path $evidenceDir
Ensure-Directory -Path (Join-Path $evidenceDir "screenshots")
Ensure-Directory -Path (Join-Path $evidenceDir "logs")
Ensure-Directory -Path (Join-Path $evidenceDir "perf")
Ensure-Directory -Path (Join-Path $evidenceDir "traces")
Ensure-Directory -Path (Join-Path $evidenceDir "review-bundles")
Ensure-Directory -Path (Join-Path $evidenceDir "router")
Ensure-Directory -Path (Join-Path $evidenceDir "other")

$requirementsPath = Join-Path $runDir "00-requirements.md"
if ((Test-Path -LiteralPath $requirementsPath) -and (-not $Force)) {
    Write-Host ("[INFO] Requirements file exists, not overwriting: {0}" -f $requirementsPath)
} else {
    $content = New-RequirementsContent -RunId $RunId -Template $Template -FromIssue $FromIssue
    Write-Utf8NoBom -Path $requirementsPath -Content $content
    Write-Host ("[OK] Wrote requirements template: {0}" -f $requirementsPath)
}

$gitContextResult = Get-GitContext -RepoRoot $resolvedRepoRoot
if ($gitContextResult.Error) {
    Write-Host ("[WARN] {0}" -f $gitContextResult.Error)
}

$worktreePath = Join-Path $runDir "00-worktree.md"
if ((Test-Path -LiteralPath $worktreePath) -and (-not $Force)) {
    Write-Host ("[INFO] Worktree file exists, not overwriting: {0}" -f $worktreePath)
} else {
    $worktreeContent = New-WorktreeContent -RunId $RunId -RepoRoot $resolvedRepoRoot -GitContext $gitContextResult.Context -PrefillError $gitContextResult.Error
    Write-Utf8NoBom -Path $worktreePath -Content $worktreeContent
    Write-Host ("[OK] Wrote Phase 0 worktree template: {0}" -f $worktreePath)
}

$diffBasisError = Test-Phase0DiffBasis -RepoRoot $resolvedRepoRoot -RunDir $runDir
if ($diffBasisError) {
    Write-Host ("[FAIL] 00-worktree.md diff basis is not executable yet: {0}" -f $diffBasisError)
    Write-Host "       Fix the Phase 0 diff-basis fields before locking or relying on downstream audit tooling."
    exit 1
}

Write-Host "[OK] Phase 0 diff basis is executable against live git state."
[void](Invoke-TrainingLoader -RepoRoot $resolvedRepoRoot -RunId $RunId -Template $Template -FromIssue $FromIssue)
Write-Host ""
Write-Host "Next steps:"
Write-Host ("1) Edit: .recursive/run/{0}/00-requirements.md" -f $RunId)
Write-Host ("2) Edit: .recursive/run/{0}/00-worktree.md" -f $RunId)
Write-Host ("3) Run:  Implement requirement '{0}'" -f $RunId)
Write-Host "4) Complete the run through the audited Phase 8 closeout before considering it done."
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 466kUpdated Claude CodeCodexVerifiedInstall
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 466kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 319kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 319kUpdated Claude CodeCodexVerifiedInstall