Skip to content

uf.unleash: move deterministic instruction from command markdown into plugin tools #716

Closed

Description

@jflowers

uf.unleash: move deterministic instruction from command markdown into plugin tools

Summary

An audit of internal/scaffold/assets/opencode/commands/uf.unleash.md
(791 lines, mirrored byte-identically at .opencode/commands/uf.unleash.md)
identified deterministic instruction that belongs in plugin tools under
internal/scaffold/assets/opencode/plugins/, following the established
patterns of uf-workflow, uf-finale, review-dispatch, and
invoke-agent.

Motivation: deterministic logic in command markdown is (a) re-interpreted
by the LLM on every run instead of executed, (b) reconstructed from
memory after context compression (the existing OUTPUT FIDELITY /
SESSION-RESUME guards exist to fight this), and (c) untestable. Plugin
tools make the behavior structural and covered by make plugin-test.

Findings by command section

Section Verdict Proposal
1. Branch Safety Gate 100% movable New uf_unleash_branch_gate tool
2. Resumability Detection Not OBE; movable New uf_unleash_detect_resume tool
3. Step 1 -- Clarify ~60% movable scan_clarifications + resolve_clarification; query formulation/evaluation stays with LLM
4. Step 2 -- Plan 100% movable New uf_delegate_command tool
5. Step 3 -- Tasks 100% movable Same uf_delegate_command tool (parameterized)
6. Step 4 -- Spec Review Replaceable with existing tools Direct dispatch calls; no new tool required
7. Step 5 -- Implement Partial Granular tools; orchestration loop stays in command
8. Step 6 -- Code Review Replaceable with existing tools Same direct dispatch sequence, mode: code

1. Branch Safety Gate

Every element is deterministic: git rev-parse, branch pattern match
(main / opsx/* / NNN-*), FEATURE_DIR derivation, tasks.md existence
check, .specify/scripts/bash/check-prerequisites.sh --json --require-spec execution + JSON parsing. uf_finale_startup
(uf-finale/index.ts:63-78) already implements the identical branch
classification — extract to a shared lib helper. New
uf_unleash_branch_gate returns { ok, branch, workflow_tier, feature_dir, change_name } or a failure envelope carrying the exact STOP
messages. ~55 lines collapse to ~3.

Caveat: do not fold Step 0 (worktree cleanup) into this tool —
forge_worktree_* are Replicator MCP tools, callable by the LLM but not
from plugin code.

2. Resumability Detection — NOT OBE

checkpoint state and filesystem probing are complementary:

  • Checkpoint only records steps /uf.unleash itself completed. A first
    run on a branch where /speckit.clarify, /speckit.plan,
    /speckit.tasks, or /opsx-propose already created artifacts has no
    checkpoint state, yet must skip Steps 1-3.
  • Progress state is cleared on completion and can be lost.

The section's logic is fully deterministic though: uf_unleash_detect_resume
parses spec.md markers, checks plan.md/tasks.md existence, counts
unchecked task boxes, merges get_progress for spec-review/code-review,
and returns { step_statuses, resume_from, all_complete }. ~55 lines →
1 call; also deduplicates the redundant get_progress calls.

3. Clarify

Movable mechanics: marker scanning/extraction and resolution application
(remove marker, insert answer, append the Q: -> A: entry to
## Clarifications). Judgment that stays: Dewey query formulation
(explicitly not verbatim marker text) and answer-sufficiency evaluation.

4/5. Plan and Tasks

Structurally identical: read command file → delegate to
cobalt-crush-dev with feature dir → verify artifact created → STOP on
failure. One uf_delegate_command(agent, command_path, feature_dir, expected_artifact) tool serves both; ~45 lines → 2 calls.

invoke_agent cannot be reused for this: AgentSchema enforces
^divisor-[a-z0-9-]+$ and validateReviewAgent requires
.uf/reviewer-capabilities.yaml membership with capability: review
(invoke-agent/index.ts:45, 111-121). This gate is deliberate
review-council policy. The new tool reuses executeAgentSession from
lib/agent-executor.ts (host model resolution, parenting, abort,
timeout) without the review-manifest gate. Alternative: keep Task-tool
delegation in command text and drop this proposal branch.

6/8. Spec Review and Code Review — direct tool calls, no new tools

The dispatch machinery fully supports both modes. uf.unleash can call
directly:

  1. resolve_base_ref (existing)
  2. Bash: resolve head SHA, compute + save diff (git diff <base_sha> +
    untracked via git ls-files --others; uncommitted: true path per
    review-council's Resolve Immutable Input Context section)
  3. Enumerate reviewers from .uf/reviewer-capabilities.yaml
  4. plan_review_dispatch(mode: specs|code, ...)
  5. dispatch_review_runs(mode, command: review-council, input_context, diff_path, changed_files, plan_entries, session_metadata)
  6. consolidate_dispatch

This eliminates the driver layer: today cobalt-crush-dev is spawned
only to read the 1,145-line uf.review-council.md and drive these tools.
The actual reviewers are the divisor-* agents spawned by
dispatch_review_runs — unchanged. uf.review-council.md remains as-is
for standalone invocations.

Delegation still worth keeping inside the review loops: code-fix
application (Step 6 iterations) → cobalt-crush-dev; spec fixes (Step
4) stay in the parent (lightweight, human-gated).

Optional follow-on optimization: uf_prepare_review(mode) tool to
absorb the bash diff-capture surface (~70 lines of input-resolution
instructions). Not a prerequisite.

7. Implement — partial decomposition

Movable: parse_tasks(feature_dir) (phases, sequential vs [P] split),
mark_task_complete(feature_dir, task_id) (checkbox edits),
scan_conflict_markers(files) (note: git_conflict_files is
insufficient — it reads git diff --diff-filter=U, not cherry-pick
residue), per-task delegation via uf_delegate_command.

Stays in command: phase iteration, batch-of-4, failure-stop, comms
reservation (interleaves Replicator MCP calls, not callable from
plugins), pre-flight hard-gate (already skill-encapsulated). A
whole-phase mega-tool risks tool timeouts (dispatch tools bound at 30
min; phases run longer).

Defects discovered during the audit

  1. Unleash-summary artifact is never written.
    uf_finale_pr_context reads .uf/artifacts/unleash-summary/<slug>.json
    (uf-finale/index.ts:427-443) but nothing in uf.unleash.md writes it
    — /uf.finale's unleash-summary context is always null. Add a
    write_unleash_summary tool at the retrospective/demo step.
  2. Spec auto-fix gate contradiction. uf.unleash Step 4 says
    "If only LOW and MEDIUM findings exist: auto-fix them," but
    uf.review-council.md spec mode has a CRITICAL RULE to never apply
    spec auto-fixes without explicit human confirmation via the question
    tool. Under unleash's "NEVER pause between steps" guardrail, the
    delegated child agent receives contradictory directives. Moving to
    direct calls forces uf.unleash to own this policy explicitly (e.g.,
    an autonomy flag or a legitimate exit reason).

Additional opportunities

  • Checkpoint ceremony: 10+ "CHECKPOINT: call checkpoint…"
    blockquotes (~50 lines). If each step tool auto-records its checkpoint
    on success, they all disappear.
  • Exit/demo template formatters: the 5 repeated
    "## /uf.unleash paused at:" blocks, the Step 10 OUTPUT FIDELITY
    GUARD, and the "re-read before composing" instructions exist to fight
    LLM reconstruction-from-memory. format_unleash_exit(...) /
    format_unleash_demo(tier, ...) tools make verbatim output structural
    instead of instructed.
  • DRY: branch classification shared between uf_finale_startup and
    the new branch-gate tool via lib/.
  • Robustness: speckit.plan.md / speckit.tasks.md are
    Speckit-scaffolded, not uf assets — uf_delegate_command should take
    the path as a parameter rather than assume it.

Execution constraints

  • Any command/plugin change must be made byte-identical in both
    .opencode/ and internal/scaffold/assets/opencode/ (drift tests in
    internal/scaffold/scaffold_test.go:144).
  • make plugin-test (TypeScript) + make test (Go drift) must pass.
  • Requires a spec workflow first; at this scope (5+ new tools across 2
    plugins + command rewrite) this is Speckit tier rather than OpenSpec.
  • Phase boundaries: spec artifacts before implementation.

Suggested increment ordering

  1. Increment 1 (no new tools): rewrite Steps 4/6 as direct dispatch
    calls; uf.unleash owns the fix-gate/iteration policy (resolves
    defect 2).
  2. Increment 2: uf_unleash_branch_gate + uf_delegate_command
    (Steps 1, 2, 3).
  3. Increment 3: uf_unleash_detect_resume + checkpoint
    auto-recording (removes ceremony blockquotes).
  4. Increment 4: formatters, write_unleash_summary (resolves
    defect 1), clarify scan/resolve.
  5. Increment 5: implement-step granular tools + optional
    uf_prepare_review.

Acceptance criteria

  • Deterministic branch/scope/resume decisions execute in tools, not
    LLM interpretation
  • Review steps call dispatch tools directly (no cobalt-crush-dev
    driver layer)
  • Spec auto-fix policy contradiction resolved explicitly
  • Unleash-summary artifact written and consumed by /uf.finale
  • All mirrors byte-identical; make plugin-test and make test
    pass
  • Command shrinks materially (target: majority of section text
    replaced by tool calls)

Activity

  1. self-assigned this
    on Oct 13, 2026
  2. added
    enhancement
    refactor
    llm_assisted
    on Oct 13, 2026
  3. jflowers commented on Oct 17, 2026

    @jflowers
    ContributorAuthor

    #716 closure reconciliation for the 'command shrinks materially' acceptance criterion: the literal size target is not met — the command grows 1006 → 1087 lines (+81) and 4852 → 4857 words (task 7.4 record). The substance target is met: ceremony blockquotes fall 15 → 2 (the two review-loop iteration checkpoints remain by design), and the migrated sections now execute as 11 tested tool calls — the Principle VI outcome (majority of procedural text replaced by tool calls) holds. The growth is the spec-mandated rendered examples at consuming decision points and payload-shape documentation. Recording the criterion explicitly reconciled as substance-met / literal-size-not-met ahead of this issue closing via PR #745.

  4. jflowers commented on Oct 18, 2026

    @jflowers
    ContributorAuthor

    closed by #745

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementllm_assistedrefactor

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions