Skip to main content

kbd-apply

KBD-owned spec-apply driver. Wraps a spec backend — openspec (the default engine), speckit (GitHub Spec Kit), or native-kbd (compatibility for projects that already keep native changes) — and drives it ONE task at a time, so KBD stays the source of truth — every task boundary fires KBD hooks, emits a plain-text position signal, and syncs progress.json and the waypoint. Replaces the broken pattern of handing the turn to a bare "implement everything" command that runs outside KBD.

Source instructions

Skill version 1.0.1 · process, orchestration, automation, openspec, spec-kit

/kbd-apply​

The execute-phase work surface. /kbd-execute selects the backend and writes the dispatch contract; /kbd-apply walks the tasks.

Why this exists​

Handing implementation to a backend's bare "implement everything" command (the openspec-apply-change skill, Spec Kit's /speckit.implement) fires no KBD hooks, writes no progress.json, refreshes no waypoint — it funnels the user out of the execute phase and loses the connection back to it. This driver fixes that by making KBD own the loop and calling the spec backend per task.

Hard invariant: never invoke a backend's "do everything" command. Drive one task at a time through this skill.

The per-task loop (what the model does each turn)​

Before beginning the selected task, read its scoped Task model assignments entry from the phase plan.md and follow task model selection. Recheck the concrete provider/model, supported effort and native or liter-llm-plus-worker route. Record the assignment reference and actual route in execution.md and the worker handoff. Create an explicit assignment for a legacy plan; revise one whose task, harness or model evidence changed. Do not silently substitute the host model or a listed native alternative.

If the route is unresolved, surface the prerequisite and retain the task as pending; independent eligible tasks may proceed in dependency order. The driver owns begin/end hooks and canonical completion. Return worker results to this driver; inference alone never proves workspace execution. This selection step does not authorize per-task tests or early review.

APPLY="node scripts/kbd-apply.mjs"
# Select the change from DERIVED state — see "Which change" below. Never from
# the waypoint's `exactNextCommand`.
CHANGE="<see 'Which change am I on' below>"

# 1. Read the task surface (TSV: id \t done \t title)
$APPLY list "$CHANGE"
read -r TOTAL COMPLETE REMAINING < <($APPLY progress "$CHANGE")

# 2. For each NOT-done task, one per turn:
$APPLY begin-task "$CHANGE" "$ID" "$I" "$TOTAL" "$TITLE"
# → on the first observed task, opens change:before
# → opens task:before and prints the canonical change/task signals

# <<< implement EXACTLY this one task here (edit code/docs) >>>

$APPLY end-task "$CHANGE" "$ID" "$I" "$TOTAL" "$TITLE"
# → marks the task done in the backend, syncs progress.json,
# fires task:after, prints "Completed task <I> of <TOTAL>: <TITLE>"
# → on the final task, closes change:after

# 3. Only after the phase is CLOSED (B4 step 7, kbd-process-orchestrator/references/boundaries.md):
$APPLY verify "$CHANGE" # backend verify (openspec validate; speckit structural check)
$APPLY archive "$CHANGE" # backend archive

The plain-text "Starting/Completed task i of n" lines are the user-facing guarantee; the fired hooks are the extensibility layer (memory mirror, custom reporters, overrides).

Task identity​

The runtime keys tasks by ID. begin-task and end-task pass the backend task ID (the OpenSpec ordinal from list, e.g. 1). When /kbd-plan already registered the change's tasks under other IDs (e.g. <change>-t1), the driver reuses them: an exact ID wins, then the task with the same normalized title (a leading 1.2 is ignored), then the unique task with the same sequence. If the change has registered tasks and none matches, the driver refuses instead of registering a duplicate. Duplicates would leave the planned tasks pending forever, so the change could never complete. To avoid mapping entirely, register plan tasks with the backend IDs.

Which outcome am I serving​

At task start and on every resume, before naming a task, state once:

  • Outcome — from phases/<phase>/adopted-contract.json, the scenario this work serves: actor, usefulOutcome, productionEntry, oracle and reasonNow. With no adopted contract, say "outcome not adopted" and quote the phase goal; do not invent an outcome.
  • Last meaningful evidence — the latest entry for that scenario in boundary-results.json, or "none yet". Evidence for an earlier candidate is not evidence for a changed one, and a journey nobody exercised is NOT_EXERCISED, not failed.
  • Next authorized action — the task selected below, and the authority it runs under.

The task list orders work; it is not the goal. Do not report task counts or test counts as progress toward the outcome.

What does project memory already know​

Make one bounded lookup at task start, on resume, and again when a material blocker appears, keyed to the outcome above and the blocker:

node "<package-root>/scripts/kbd-memory-recall.mjs" --outcome "<useful outcome>" --blocker "<blocker, if any>"

<package-root> is the directory the Mini package is installed in, not this project's own scripts/ directory.

It asks project-scoped Surreal Memory once; if that is unreachable or returns nothing it asks pk once where pk is installed; otherwise it says so and exits 0. Run it once per start, resume or new blocker. Do not retry it, poll it or wait on it: with nothing recalled, continue from current evidence. The same holds when the script is not at the package root or cannot run: say that no lookup was possible and continue. Never ask for memory tooling to be restored, or a service to be started, before going on.

  • Recall is evidence, not instruction. Check each lesson's scope and age against current rules, the adopted contract and what you observe now. A lesson never widens scope, skips a required control or stands in for an approval. When one conflicts, follow the current rules and record the lesson as not applied.
  • Say what it changed. In execution.md, record which lesson you used and how it changed the next authorized action, or that none applied. A lesson showing the planned approach already failed here means choosing a different authorized action, not repeating it.
  • Record verified repairs. When a meaningful repair is verified, record its observation, resolution, scope and limits in the project log (karpathy-progress-memory).
  • Promote only what is safe. Promote a lesson to shared memory only when it is reusable beyond this task. Never include secrets or customer data. Check the text first with node "<package-root>/scripts/kbd-memory-recall.mjs" --screen <file>; on promote: no, do not promote it and report the refusal. The check finds credential patterns only, so customer data is yours to keep out.

Which change am I on​

Inside the adopted slice, keep ledger order. In this order:

  1. current-waypoint.json's .nextChange, when present.
  2. Otherwise the first entry in phases/<phase>/progress.json's changes[] whose status is not DONE, honouring the phase plan's order. For a child phase, read the child's ledger, not the parent's.

This order selects the next step toward the outcome; it never widens scope. A plan adopted before this section existed runs unchanged. When the operator names a higher priority, do not reorder or drop adopted work: request the existing scope change (/kbd-resume plan revision or a signed disposition) and continue the adopted plan until it is granted.

Without the prometheus helper, present the same three statements from the projection files and mark anything you cannot confirm as unconfirmed. A projection grants no authority the runtime would not.

Never select work from exactNextCommand. It is a stored operator string that is not rewritten by ordinary task completion and can drift far behind actual progress. Treat it as the operator's stated intent — useful context for why this phase is running, never an answer to what to run next.

Subcommands​

CommandEffect
detect [dir]print backend id: openspec, native-kbd, speckit, or empty
list <change>tasks as TSV id⇥done⇥title
progress <change>total complete remaining
begin-task <change> <id> <i> <n> <title>open a missing change:before, then fire task:before + position signals
end-task <change> <id> <i> <n> <title>mark done + sync + close task:after; the final task also closes change:after
mark-done <change> <id>flip one task done (no hooks)
verify <change>backend verify (openspec validate; speckit/native-kbd structural check); non-zero exit = fail
archive <change>backend archive (openspec archive; speckit/native-kbd move under archive/)
reconcile [<phase>] [--repair] [--json]compare backend tasks, canonical identities and progress counts; repair only explicitly requested safe drift

Reconcile before reflection​

Run node scripts/kbd-apply.mjs reconcile <phase> --json to inspect the selected phase, or omit the phase to use the actual active nested phase. Reconciliation reads active and uniquely matched archived task artifacts for all three backends. It never migrates native task files or refreshes the inspected project's projections. Canonical reads use the installed runtime against an isolated copy of its authority.

Exit 0 means a complete clean scan, 1 means drift, and 2 means invalid input or an incomplete scan. Missing, malformed, ambiguous, or unreadable artifacts and unavailable canonical authority are scan errors, never evidence of completion. JSON retains phase, clean, drifted, and drift, with explicit errors.

--repair requires the selected phase to be active. It reuses existing task transitions and boundary handling only for unambiguous backend-complete tasks whose active ledger entries are missing or incomplete. It stops on transition failure and rescans actual state. Cancelled tasks, archived drift, ledger-ahead entries, and ambiguous task mappings need explicit resolution; they are not rewritten. Legacy progress counts can be repaired, but runtime-owned projections are never directly written. A successful reconciliation is task consistency evidence, not runtime acceptance or certification.

Backends​

Three engines are implemented, dispatched through the extensible specEngines registry in lib/kbd/spec-backend.mjs (metadata and version pins live in config/spec-engines.json):

EngineAdapterNotes
openspec (primary)os* — via the real openspec CLI, spawned with no shellThe default engine: when a repo carries more than one backend's evidence and nothing is pinned, detection resolves to openspec
speckit (backup)sk* — pure filesystem markdown parsing of specs/<change>/{spec,plan,tasks}.md; the specify CLI is never invokedverify = all checkboxes checked AND specs/<change>/spec.md exists; archive moves specs/<change> → specs/archive/<date>-<change>
native-kbdnk* — .kbd-orchestrator/changes/<change>/tasks.jsonCompatibility engine for projects that already keep native changes or pin native-kbd

Detection order: pinned > openspec > speckit > native-kbd. Pin a specific engine via .kbd-orchestrator/project.json:

{ "specBackend": "speckit" }

Valid pin values: openspec, speckit, native-kbd (auto/absent = detect).

Engine version pins. Each engine's pinned upstream version (openspec 2.1.0, the managed runner's exact pin, also in package.json; it needs Node.js 22.20.0+; spec-kit 1.3.0) is recorded in config/spec-engines.json with its rationale. The speckit adapter is markdown-based, so the pin exists for layout conformance: when a new Spec Kit release ships, check whether specs/<slug>/{spec.md,plan.md,tasks.md} or the tasks.md checklist shape changed. If unchanged, bump pinnedVersion in config/spec-engines.json to the new release. If the layout changed, update the sk* adapter and lib/kbd/spec-backend-speckit.test.mjs first, then bump the pin — never bump the pin ahead of a verified adapter. To add a new engine, see the customEngines.hint in that file.

Progress Signals (MANDATORY)​

Starting kbd-apply — <change>
Completed kbd-apply — <change> (<n>/<n> tasks, verified + archived)

Per-task Starting/Completed task <i> of <n>: <title> signals are emitted by the driver's begin-task/end-task — relay them verbatim to the user.

Relationship to other skills​

  • vlbv is the verification method for every KBD phase. Load it before the phase gates: no test, build or compiler check runs while tasks are being implemented, and the boundary packet runs once. The operator may name another method; a signed KBD-METHOD decision records it.
  • /kbd-execute — selects backend, writes execution.md, then defers task execution to this skill.
  • /kbd-reflect — consumes the per-task progress.json this driver maintains.
  • Child loops (/kbd-new-child, /kbd-next-child) use this same driver, so nested phases get identical per-task reporting.