AGENT SKILL

openspec-apply-subagent

Implement tasks from an OpenSpec change by delegating task execution to the spec-coder-sub subagent.

License 许可
MIT
最近更新
2026-09-05
Stars
★ 0
Forks
0

01 前言 Front Matter

name
openspec-apply-subagent
license
MIT
metadata
{ "author": "openspec", "version": "1.0" }
description
Implement tasks from an OpenSpec change by delegating task execution to the spec-coder-sub subagent.
allowed-tools
bash, read, edit, glob, grep, todoread, todowrite, task, question
compatibility
Requires openspec CLI.

03 SKILL.md 正文

Implement tasks from an OpenSpec change via delegated subagent.

Input: Optionally specify a change name. If omitted, check if it can be inferred from conversation context. If vague or ambiguous you MUST prompt for available changes.

Steps

  1. Select the change

    If a name is provided, use it. Otherwise:

    • Infer from conversation context if the user mentioned a change
    • Auto-select if only one active change exists
    • If ambiguous, run openspec list --json to get available changes and use the AskUserQuestion tool to let the user select

    Always announce: "Using change: <name>" and how to override (e.g., /opsx:apply <other>).

  2. Check status to understand the schema

    openspec status --change "<name>" --json
    

    Parse the JSON to understand:

    • schemaName: The workflow being used (e.g., "spec-driven")
    • planningHome, changeRoot, and actionContext: planning scope and edit constraints
    • Which artifact contains the tasks (typically "tasks" for spec-driven, check status for others)
  3. Get apply instructions

    openspec instructions apply --change "<name>" --json
    

    This returns:

    • contextFiles: artifact ID -> array of concrete file paths (varies by schema - could be proposal/specs/design/tasks or spec/tests/implementation/docs)
    • Progress (total, complete, remaining)
    • Task list with status
    • Dynamic instruction based on current state

    Handle states:

    • If state: "blocked" (missing artifacts): show message, suggest using openspec-continue-change
    • If state: "all_done": congratulate, suggest archive
    • Otherwise: proceed to implementation
  4. Read context files

    Read every file path listed under contextFiles from the apply instructions output. The files depend on the schema being used:

    • spec-driven: proposal, specs, design, tasks
    • Other schemas: follow the contextFiles from CLI output
  5. Show current progress

    Display:

    • Schema being used
    • Progress: "N/M tasks complete"
    • Remaining tasks overview
    • Dynamic instruction from CLI
  6. Delegate Task Implementation to spec-coder-sub Subagent

    CRITICAL DELEGATION DIRECTIVE: Do NOT perform code edits or task implementation directly on the primary agent.

    Delegate task execution to the spec-coder-sub subagent (via task / invoke_subagent tool):

    • Subagent Name: spec-coder-sub
    • Instruction Prompt:

      "Implement pending tasks for OpenSpec change '<name>'. Work through remaining tasks in tasks.md sequentially, perform minimal code modifications, run verification commands, and update checkboxes from - [ ] to - [x]."

    • Context to pass:
      1. The complete output from openspec instructions apply --change "<name>" --json.
      2. The target change folder and file paths listed in contextFiles.
    • Subagent Model Hierarchy & Fallback Protocol:
      1. Default (OpenCode Go Subsidized): Delegates to spec-coder-sub (runs opencode-go/deepseek-v4-flash).
      2. Fallback 1 (Direct DeepSeek API Pay-As-You-Go): If OpenCode Go quota or rate limit (429) is hit, re-execute subagent specifying --model deepseek/deepseek-v4-flash.
      3. Fallback 2 (Free Zero-Cost Tier): If direct DeepSeek API limits are reached, re-execute subagent specifying --model opencode/deepseek-v4-flash-free.

    Monitor spec-coder-sub execution until completed or paused due to a blocker/error.

  7. Verify & Sync Specs

    • Automatically trigger openspec-verify-change skill (or /opsx:verify) to validate implementation completeness and correctness.
    • If verification passes with no CRITICAL issues:
      • Sync specs: openspec specs apply --change "<name>"
      • Suggest archiving via openspec archive <name>.
  8. Single-Pass Automated Repair (Max Retries = 1)

    • If CRITICAL issues or failed test verification errors are detected on the first pass:
      1. Announce: "Verification failed on initial pass. Attempting a single bounded repair pass via subagent..."
      2. Delegate a single-pass repair task to spec-coder-sub with the verification failure context:

        "Fix the specific verification failures and test errors reported for change '<name>'. Refer to the error log, make minimal targeted patches to resolve the failures, run verification commands, and update tasks.md."

      3. Re-run verification (openspec-verify-change).
      4. If verification passes after repair:
        • Sync specs: openspec specs apply --change "<name>"
        • Suggest archiving via openspec archive <name>.
      5. If verification STILL fails after the single repair pass:
        • HALT: Do NOT loop or re-run again. Present the Verification Report and remaining blockers to the user for manual guidance.

04 同仓库更多 Skills