--- name: implement description: > Use ONLY when implementing a work item from an approved iteration plan, OR fixing a bug (bugfix mode), OR refactoring code (refactor mode), OR porting a feature (port mode). The Developer (Worker) reads the work item, design sections, and acceptance criteria, writes code, and self-checks against the relevant checklist before handing off to code review. # `stage` is intentionally omitted: `implement` is a production-phase name the # stage registry rules invalid post-[org-internal #3072] phase 3 (see # core/schemas/workflow-routing.schema.json stage enum — production-phase # names are "no longer valid anywhere"). The implement skill has no registry # gate id; the gates it feeds into are `review-code` and `verify`. triggers: - implement - implement work item - implement WI- - work item - 实现工作项 - 开始写代码 - implement the iteration - bugfix - fix a bug - fix bug - fix this bug - 修复 - 修复bug - help me fix - doesn't work - does not work - not working - is broken - stack trace - throws an error - crashes - refactor - 重构 - restructure - 删除死代码 - dead code - improve code structure - 重新组织代码 - graduate experimental - remove experimental guard - 移除实验性 - port - porting - port feature - port this feature - migrate feature - 移植 - 迁移功能 - code change - write code role: Producer --- > Core 中立版(Increment 6a 改写,原 deferHard verbatimDir)。机制、结构与 frontmatter 保持;实例术语(工具名、路径、工单号)按 `core/adapters/TERMINOLOGY.md` 绑定到具体实例。 # Skill: implement ## Mode Selection This skill handles four work modes. The main session identifies the mode from the work item's `type` field or the user's request: | Mode | When to use | Key difference | |---|---|---| | **implement** (default) | Work item from an approved iteration plan | Standard implementation per acceptance criteria | | **bugfix** | User reports a bug / fix request | Reproduce → root cause → regression test (must FAIL first) → minimal fix | | **refactor** | User asks to restructure code (no behavior change) | Establish baseline → transform in ≤10 steps → verify zero regression | | **port** | User asks to port a feature from another project | Read source → map concepts → implement in target conventions → verify fidelity | In **standalone mode** (user-initiated, no iteration plan), skip preconditions about plan/approval and go directly to the mode-specific workflow. In **pipeline mode** (work item from iteration plan), follow the standard preconditions then the mode-specific phases. **On-demand references**: each mode's phase-by-phase detail (templates, prompts, orchestration flows, historical notes) lives in `reference/{mode}-mode.md`, NOT injected — read it at mode entry. Full read-timing table: References section. > **Progressive disclosure ([org-internal #3734])**: when dispatching a Developer scoped to > one mode, pass `skills: ["implement:mode-bugfix"]` (preamble + that > mode's workflow only) instead of the full body; pipeline-mode dispatches > should also carry `pipeline-detection` > (`"implement:mode-implement,pipeline-detection"`). Mode Selection, Agent > Role, Greenfield vs. Brownfield, … are unmarked preamble and always > inject. Full-body remains the default when no selector is passed. ## Agent Role The implementation is owned and produced by the **Developer** (Worker). The Builder delegates each work item to a dedicated Developer sub-agent with the full design and plan context. > **Role naming**: throughout this skill, "Builder", "Orchestrator", and "main session" name the same coordinating role (the main session that dispatches Developer sub-agents and validates output) — not a distinct role from the "Orchestrator" used by `review-code` and the shared review pipeline. The Developer is responsible for: - Reading the assigned work item, design sections, and acceptance criteria. - Writing code that faithfully implements the design. - Running typecheck, lint, and tests to self-verify. - Self-checking against the relevant checklist before handoff. - Persisting the final report to disk before returning — worker-report persistence ([org-internal #2847], see `../_shared/worker-report-persistence.md`). - Writing no more and no less than the work item scope — no opportunistic refactoring of unrelated code. The Builder's role is to validate the implementation output and pass it to code review. The Builder MUST NOT write or revise implementation code. ### Pre-flight checklist injection ([org-internal #2599]) Before dispatching ANY Developer (or Tester) sub-agent — in every mode (implement / bugfix / refactor / port; pipeline or standalone) — the orchestrator resolves the ticket's route (the Process Assessment Gate Step 0 already resolves the Kind/* route) and reads `/workflow-routing.yaml` `routes.{Kind}.preflight`. When the list is non-empty, prepend it to the sub-agent's task prompt as: ``` Pre-flight self-check (evidence-based, from retrospective — verify each BEFORE writing code; if one is already satisfied, note why in impl-notes): 1. {item} (evidence: {evidence}) 2. ... ``` Rules: - The list is a human-landed checklist (retro proposes, a human lands it) — NEVER synthesize or extend items at dispatch time. - Cap at `preflight.max_items` entries; beyond it, drop oldest by `added_cycle`. - Items are self-checks, not gates: an unsatisfied item means the Developer addresses it in the implementation (and says how), not that dispatch aborts. > **Context compaction**: this skill is a pipeline stage boundary. The main session (orchestrator) compacts at this clean boundary ONLY when a capacity/projection trigger holds, per the L1 rule `core/rules/compact.md` §"Stage-boundary compaction" (long multi-stage runs — DAG Epic orchestration — keep the legacy every-boundary compaction; short runs — bugfix / DAG task — and standalone runs default to NOT compacting). The sub-agent this skill dispatches persists its artifacts to the Gitea wiki under `{slug}/` as it goes, so a mid-run compaction loses nothing — re-read the stage's wiki index to resume. ## Role Split: Developer vs Tester Each execution mode below defines its own Tester focus and any mode-specific orchestration overrides. ## Greenfield vs. Brownfield **Greenfield** (new project): Create new files following the design. Project conventions are defined by the design document. **Brownfield** (existing project + new feature): - **Read neighbors first.** Before writing code, read at least 3 existing files in the same module to absorb the project's code patterns. (Shared brownfield rule — canonical statement: `core/skills/review-code/SKILL.md` §"Greenfield vs. Brownfield"; the threshold and same-module scope are defined there.) - Match existing conventions exactly: error handling style, logging format, naming, file structure, import ordering, type declaration placement. - New code MUST follow existing conventions consistently — no style drift. - No opportunistic refactoring of unrelated existing code. If you see a bug or improvement opportunity in unmodified files, log it in the implementation report as a separate observation — do not fix it in this work item. - Phase 1 (Parse Context) includes reading neighboring code files to establish the project's conventions. Phase 4 (Self-Check) compares new code against these conventions. --- ## Execution Modes ### Mode: implement (default) Standard workflow for work items from an approved iteration plan. Full phase detail, templates, prompts: `reference/implement-mode.md` (read at mode entry). #### Preconditions > **DAG-mode input path** (DAG ticket pipeline — `Kind/Epic` / `Kind/Feature` DAG parent, routes-table direct): DAG-routed tickets **ignore `Size/*`** — the tiered Preconditions below are replaced by the node spec: work item + acceptance criteria resolve from the **frozen DAG copy** wiki page `{epic-slug}/dag` (+ `{epic-slug}/dag-nodes/{node-id}` subpages when AC detail is sunk) and the node ticket's issue body — no legacy `{slug}/04-plan-*` page, no `Size/*`-tiered req/design page. The design-space + iteration-plan convergence preconditions are replaced by the **review-dag single-gate convergence**: `octopus review status --stage review-dag` must show `success` before the node is implemented. > **DAG-route read map** (every legacy `{slug}/04-plan-*` / `{slug}/03-design-*` reference below resolves from the frozen DAG copy instead — mirror of `verify/SKILL.md`'s DAG branch; full map: `reference/implement-mode.md` § Preconditions): > > - Work item (`04-plan-04-iteration-assignment` / issue body) → node spec in `{epic-slug}/dag` + node ticket body. > - Acceptance criteria (`04-plan-05-acceptance-criteria` / issue body) → node `acceptance_criteria` (+ sunk subpages) + node ticket body. > - `test_id` (測試用例 ID) → the `test_id` declared on the node AC in `{epic-slug}/dag`. > - Design sections / interface design (`03-design-**`) → node spec + cross-session edge contracts (no design page). > - Component mapping (`03-design-08-traceability`) → node `req_refs` + component field. > > At Phase 6 handoff, pass `mode: "dag-task"` to review-code (its DAG Task Mode keys off the same frozen-DAG-copy detection). > **Legacy pipeline preconditions retired ([org-internal #3072] phase 3, 2026-08-21)**: tiered artifact-existence and review-convergence checks belonged to the archived legacy pipeline. Live input modes: DAG task mode (above) and standalone modes (the request itself is the spec). Historical tiered publish targets: `reference/implement-mode.md` § Legacy notes. Before starting implementation, confirm: - [ ] Work item is specified (DAG node ticket `{node-id}`, or a clear task description in standalone modes). - [ ] `core/checklists/implementation.md` is accessible. - [ ] `slug` matches the run's slug (DAG: `{epic-slug}`). - [ ] 跨阶段门控清单: `core/checklists/pipeline-gate.md` accessible and its DAG 路由变体 section confirmed — frozen DAG copy exists, single gate converged, upstream dependencies at terminal state (`ready`); else abort, listing the blocked nodes. **If any precondition is unmet, abort and inform the user** — list every missing artifact, un-converged review, and blocked dependency (complete gate checklist + Recovery Protocol: `core/checklists/pipeline-gate.md`). When no work item is specified, resolve the ready/pending task nodes from `{epic-slug}/dag` and present them for selection (prompt: `reference/implement-mode.md` § Preconditions — work-item selection). #### Phases skeleton Every gate below is hard — agents rationalize skipping exactly these. Full detail: `reference/implement-mode.md`. 1. **Phase 1 — Parse Context**: read the work item (node spec + node ticket), acceptance criteria (every falsifiable `AC-{n}` / `NFR:` entry and its declared `test_id`), design context (cross-session edge contracts), and the existing codebase; resolve inputs per the DAG-route read map (standalone: the request). Read every referenced design file before writing code. 2. **Phase 2 — Plan Implementation**: brief plan (template: `reference/implement-mode.md` § Phase 2). GATES: **≤ 3 files per work item** (more → the Builder/user MUST split it); every file must map to a design component (else flag the design gap and abort); do NOT invent design decisions. Present the plan and ask: proceed? (yes / no / revise). 3. **Phase 3 — Implement**: design-exact code; tests cover every AC. - **Design discipline**: component interfaces, method signatures, return types, data model fields, API endpoints/schemas/status codes MUST match the design exactly; an impossible design decision → stop and report the gap, never silently deviate. - **Test discipline (Red → Green, declared test_ids)**: write each declared test FIRST and confirm it fails for the intended reason (Red) before writing the implementation (Green); the test's `file-path :: test-name` MUST match the declared `test_id` exactly — the implement-side handshake with `verify` (DOD-1.6). `MANUAL` / `BENCH: