Implement a specification (or specific phases of a spec) using coordinated subagents. Handles multi-phase spec implementation with unit tests, integration tests, documentation, and code-review compliance. Use when the user says "implement spec", "implement the spec", "implement a dated spec file", "implement phases", "build from spec", or "code the spec". Tracks progress by updating the spec with implementation status.
Implements a specification (or selected phases) end-to-end using a team of coordinated subagents. Every code change MUST pass the code-review checklist before the phase is considered done.
.ai/specs/ or .ai/specs/enterprise/..ai/skills/code-review/references/review-checklist.md — this is the acceptance gate for every phase..ai/lessons.md for known pitfalls.Before writing any code, ask the user:
Where should this feature live?
- External extension (npm package / standalone repo) — uses UMES extension points (widgets, events, enrichers, API interceptors) to add functionality without modifying Open Mercato core. Best for: custom business logic, vertical features, third-party integrations. Preserves upgrade path.
- Core modification (inside
packages/orapps/mercato/) — directly modifies the platform. Best for: foundational platform capabilities that all users need.
create-mercato-app scaffolded repo or wants a standalone npm package in packages/.packages/<extension-name>/ with proper @open-mercato/<extension-name> naming and package.json.apps/mercato/src/modules/<module>/ (or the user's app repo).packages/core/, packages/ui/, packages/shared/ etc. unless absolutely necessary for a missing extension point — and if so, the missing extension point itself becomes a prerequisite spec.Ask a confirmation:
Are you sure? Modifying core means:
- Third-party modules depending on changed surfaces may break
- Backward compatibility contract applies (13 frozen/stable categories)
- Users who forked or extended these files will have merge conflicts on upgrade
- Changes require deprecation protocol if touching any contract surface
Proceed with core modification?
Only continue with core changes after explicit confirmation.
For each phase in the spec, execute these steps:
Read the phase from the spec. For each step within the phase:
BACKWARD_COMPATIBILITY.md contract surfaces)Present a brief plan to the user before coding.
Use subagents liberally to parallelize independent work:
For every piece of code, enforce these code-review rules inline:
| Area | Rule |
|---|---|
| Types | No any — use zod + z.infer |
| API routes | Export openApi and metadata with auth guards |
| Entities | Standard columns, snake_case, UUID PKs |
| Security | findWithDecryption, tenant scoping, zod validation |
| UI | CrudForm/DataTable, apiCall, flash(), LoadingMessage/ErrorMessage |
| Commands | registerCommand, undoable, extractUndoPayload() |
| Events | createModuleEvents() with as const, subscribers export metadata |
| i18n | useT() client, resolveTranslations() server, no hardcoded strings |
| Imports | Package-level @open-mercato/<pkg>/... for cross-module |
| Mutations | useGuardedMutation when not using CrudForm |
| Keyboard | Cmd/Ctrl+Enter submit, Escape cancel on dialogs |
| Naming | Modules plural snake_case, events module.entity.past_tense, features module.action |
For every new feature/function implemented in the phase:
*.test.ts or __tests__/)yarn test --filter <module>If the spec defines integration test scenarios (or the phase adds API endpoints / UI flows):
integration-tests skill workflow (.ai/skills/integration-tests/SKILL.md)<module>/__integration__/TC-{CATEGORY}-{XXX}.spec.tsnpx playwright test --config .ai/qa/tests/playwright.config.ts <path> --retries=0If the spec does not explicitly list integration scenarios but the phase adds significant API or UI behavior, propose test scenarios to the user before writing them.
For each new feature:
translations.tsyarn generate / npm run modules:prepareBefore marking a phase complete, run a self-review against the full checklist:
Fix any violations before proceeding to the next phase.
After completing each phase, update the spec file:
## Implementation Status section at the bottom (or update it if it exists)## Implementation Status
| Phase | Status | Date | Notes |
|-------|--------|------|-------|
| Phase A — Foundation | Done | 2026-02-20 | All steps implemented, tests passing |
| Phase B — Menu Injection | Done | 2026-02-21 | 3/3 steps complete |
| Phase C — Events Bridge | In Progress | 2026-02-22 | Step 1-2 done, step 3 pending |
| Phase D — Enrichers | Not Started | — | — |
### Phase C — Detailed Progress
- [x] Step 1: Create event definitions
- [x] Step 2: Implement SSE bridge
- [ ] Step 3: Add client-side hooks
After all targeted phases are complete:
yarn build:packages — must passyarn lint — must passyarn test — must passnpm run modules:prepare — if any convention files changedyarn db:generate — if any entities changed (verify generated migration is scoped correctly)Report results to the user. If any check fails, fix and re-verify.
| Task | Agent Type | When |
|---|---|---|
| Research existing patterns | Explore | Before implementing unfamiliar patterns |
| Implement independent files | Bash/general-purpose | When files have no dependencies on each other |
| Run tests | Bash | After each phase |
| Self-review | general-purpose | After each phase, against checklist |
| Integration tests | general-purpose | After phases with API/UI changes |
Concurrency rule: Launch parallel subagents only for truly independent work. Sequential for dependent files.
When implementing component replacement features (as in SPEC-041h pattern):
DataTable instance gets a replacement handle: data-table:<module>.<entity>CrudForm instance gets a replacement handle: crud-form:<module>.<entity>NotesSection, ActivitySection) gets a replacement handle: section:<module>.<sectionName>yarn build:packages after final phase to verify no build breaksany types, hardcoded strings, raw fetch, or other anti-patterns