with one click
ks-implement
// Use this when the current block is already clear and the job is to complete it. Default route comes from test-first; only controlled low-risk exceptions may enter directly.
// Use this when the current block is already clear and the job is to complete it. Default route comes from test-first; only controlled low-risk exceptions may enter directly.
Lightweight task compressor. Turn messy input into a one-page brief that can route to roundtable or writing-plan without replacing direction decisions.
Formal quality gate with multi-persona review, confidence thresholds, and QA routing based on fresh verification evidence.
Direction convergence skill. Use brainstorm, align, or challenge mode to turn messy questions or existing proposals into a clear directional decision.
Use this when direction is already clear and the next job is to compress it into an executable block with scope, done criteria, and routing.
Fast failure classifier. Decide whether the problem is a spec gap, an implementation bug, or a rollback candidate before routing to writing-plan, diagnose, or ship.
Use this when the system is broken, tests are failing, or behavior is abnormal and the root cause is still unknown. No investigation, no fix.
| name | ks-implement |
| description | Use this when the current block is already clear and the job is to complete it. Default route comes from test-first; only controlled low-risk exceptions may enter directly. |
| layer | execution |
| owner | implement |
| inputs | ["current_block","plan_document","test_contract"] |
| outputs | ["implementation_result"] |
| entry_modes | ["plan-ready","build-ready"] |
Preamble: see templates/preamble.md
implement executes the current block. Default path: turn the failing checks from test-first into passing code. Controlled exception path: implement directly against the approved plan scope. Implementation is where discipline erodes fastest. Scope creep, "quick extra fixes", and silent behavior changes happen here. This skill keeps execution inside the block and defines completion as passing the contract, not "the code looks done."
Enter when test-first already produced a test_contract, or writing-plan explicitly approved a low-risk exception with a documented reason. Do not enter when the block boundary is unclear (writing-plan) or the root cause is still unknown (diagnose).
This skill does not expand scope, make direction decisions, self-authorize skipping test-first, replace verify or review, or disguise diagnosis as implementation.
writing-plan or roundtable)test-first (only writing-plan can approve that)verify or review as quality gatesdiagnose)If a requirement appears outside the plan, record it and do not implement it automatically.
Knowing the likely root cause is not enough if
diagnosehas not actually produced the route intoimplement.Implementation is only complete when the contract passes, not when code was written.
Before writing any code, confirm these conditions hold.
Read plan_document. Open it. Confirm the scope is stated and the current block matches. If the file is missing or the scope is ambiguous, stop and return to writing-plan.
Check for test_contract. One of these must be true:
test_contract exists on disk and its scenarios cover the done criteria. Proceed on the default path.writing-plan explicitly approved a low-risk exception and documented why test-first may be skipped. Proceed on the controlled exception path.test-first or writing-plan.Confirm the current block. The block being implemented must match the block named in the plan. If it does not, stop and realign.
Prerequisite checklist:
plan_document exists and the scope is cleartest_contract exists, or writing-plan explicitly approved the low-risk exceptionFor framework-specific command syntax, see templates/test-commands.md.
Default path (test contract exists):
Red. Run the targeted scenario. Confirm it fails. If it passes already, the contract may be stale. Investigate before proceeding.
# Example: pytest -k "scenario_name"
# See test-commands.md for your framework
Green. Write the smallest implementation that satisfies the failing check. One scenario at a time. No gold-plating, no tangential fixes.
Refactor. Improve structure while the tests stay green. Run the full test suite after refactoring.
# Example: pytest
# See test-commands.md for your framework
Repeat for each scenario in the test_contract, until every targeted check passes.
Controlled exception path (no test contract, approved by writing-plan):
verify can still collect fresh evidence for each done criterion.Scope creep is the primary failure mode in implement. Use this protocol to detect and handle it.
Detection rules. Any of these signals means scope is expanding:
Handling rules. When scope expansion is detected:
Stop editing immediately.
Record the discovery in .keystone/out-of-scope.md with this format:
## Out-of-Scope Discovery: [short title]
- **Block**: [current block name]
- **Discovered during**: [what you were doing]
- **Description**: [what the issue or opportunity is]
- **Suggested routing**: [which skill should handle this: writing-plan, diagnose, etc.]
Do not implement the out-of-scope work.
Resume the current block's implementation.
Circuit breaker. Track scope expansions. Each time you record an out-of-scope discovery, increment the counter.
After 3 scope expansions in one block, pause and ask the user:
[context: 3 out-of-scope items were discovered during implementation of the current block.]
The current block keeps uncovering work beyond its scope. How should we proceed?
[recommendation: finish the current block and route discoveries later]
a) finish this block, then route discoveries
b) stop now and return to writing-plan to rescope
c) pause and review discoveries before continuing
Reset the counter after the user responds and you resume.
If the user chooses option b, exit implement and route back to writing-plan.
Before declaring the block complete, verify all of these conditions:
| # | Condition | Path |
|---|---|---|
| 1 | All test_contract checks pass | Default |
| 2 | Code stays inside approved plan scope and verify can collect evidence for each done criterion | Exception |
| 3 | No new compile or syntax errors introduced | Both |
| 4 | Existing checks were not broken (full suite passes) | Both |
| 5 | No uncommitted out-of-scope work was silently included | Both |
Condition 4 detail. Run the full project test suite. If any previously passing test now fails, the implementation broke something. Fix it within the current block's scope, or record it as out-of-scope and investigate.
Condition 5 detail. Review the diff. If any changed file or added function is not justified by the plan or test contract, remove it or record it as out-of-scope.
If any condition fails, do not mark the block complete. Fix the issue or route to the appropriate skill.
After the block is complete, surface any out-of-scope items that were recorded during Step 3.
Review .keystone/out-of-scope.md for entries tagged with the current block.
For each entry, suggest a routing:
| Discovery type | Route to |
|---|---|
| New feature or requirement | writing-plan |
| Bug found in unrelated code | diagnose |
| Refactoring opportunity | writing-plan (new block) |
| Dependency or infrastructure issue | writing-plan |
Include the summary in the implementation result so verify and downstream skills can see it.
If no out-of-scope items were found, state that explicitly: "No out-of-scope discoveries during this block."
When you realize the current implementation requires work beyond the approved scope:
.keystone/out-of-scope.md (Step 3 format).implement and route to writing-plan for rescoping.If plan_document or test_contract is missing and no approved exception exists:
plan_document → writing-plantest_contract and no approved exception → test-firstIf running the full test suite reveals that previously passing tests now fail:
.keystone/out-of-scope.md. Attempt a minimal fix within the current scope. If the fix would itself expand scope, stop and route to diagnose.skip, xfail, or commenting them out.If the block is skipping test-first under an approved low-risk exception:
writing-planverify must already have a clear evidence pathdecision: implement-complete
confidence: 0.9
rationale: The block was implemented inside its approved scope. On the default path, the red-green-refactor loop completed. On the controlled exception path, the change stayed inside the approved boundary and verify can still collect fresh evidence.
fallback: If scope or risk turns out to be wrong during implementation, return to writing-plan or test-first.
escalate: false
next_skill: verify
next_action: Enter verify and collect fresh evidence.
_CURRENT_BLOCK="${CURRENT_BLOCK:?set CURRENT_BLOCK to current block title}"
_KS_CLI="${KEYSTONE_CLI:-./keystone}"
$_KS_CLI state set current_stage "implement" >/dev/null
$_KS_CLI state set current_block "$_CURRENT_BLOCK" >/dev/null
$_KS_CLI state set last_decision "implement-complete" >/dev/null
$_KS_CLI state set exit_code "ok" >/dev/null
$_KS_CLI state set exit_reason "The implementation loop is complete for the current block" >/dev/null
$_KS_CLI state set next_skill "verify" >/dev/null
_SCOPE_EXPANSIONS="${SCOPE_EXPANSIONS:-0}"
echo "{\"skill\":\"implement\",\"ts\":\"$(date -u +%Y-%m-%dT%H:%M:%SZ)\",\"decision\":\"implement-complete\",\"confidence\":0.9,\"block_name\":\"$_CURRENT_BLOCK\",\"scope_expansions\":$_SCOPE_EXPANSIONS}" >> .keystone/telemetry/events/$(date +%Y-%m).jsonl