Skip to content

feat(#505): consolidate phase definitions into PhaseRegistry - #644

Merged
admarble merged 4 commits into
mainfrom
feature/505-arch-phase-plugin-registry-user-extensible-workflo
May 14, 2026
Merged

admarble merged 4 commits into
mainfrom
feature/505-arch-phase-plugin-registry-user-extensible-workflo

Conversation

@admarble

Copy link
Copy Markdown
Contributor

Summary

Implements the descoped phase plugin registry from #505. Replaces the scattered PHASE_PROMPTS / AIDER_PHASE_PROMPTS / ISOLATED_PHASES / UI_LABELS / SECURITY_LABELS constants with a uniform PhaseDefinition record per phase, registered against a single phaseRegistry singleton at module load. All 9 built-in phases register through the same mechanism — no special-casing in consumer code.

User-defined phases (.sequant/phases/ filesystem discovery) and the sequant phases command are deliberately deferred per the 2026-04-09 descoping comment.

AC Verification

AC Description Status Evidence
AC-1 PhaseDefinition interface (name, skill, promptTemplate, requiresWorktree, retryStrategy, detect, driverOverrides, order) ✅ Implemented src/lib/workflow/phase-registry.ts:53-91
AC-2 PhaseRegistry class with register/get/list/has ✅ Implemented src/lib/workflow/phase-registry.ts:93-148 + tests phase-registry.test.ts
AC-3 All 9 built-in phases registered uniformly ✅ Implemented phase-registry.ts:168-323; tested in phase-registry.test.ts:92-176
AC-4 (was AC-7) phase-executor.ts reads from registry ✅ Implemented Deleted PHASE_PROMPTS / AIDER_PHASE_PROMPTS / ISOLATED_PHASES. Prompt lookup at phase-executor.ts:454-462; worktree check at phase-executor.ts:35-44
AC-5 (was AC-6, simplified) phase-mapper.ts consumes registry detect rules ✅ Implemented Removed UI_LABELS / SECURITY_LABELS; new detectPhasesFromRegistry() at phase-mapper.ts:46-55
AC-6 (was AC-5, simplified) --phases CLI validates against registry at runtime ✅ Implemented bin/cli.ts:76-100 + integration test phase-registry.integration.test.ts
AC-8 Driver overrides handled via driverOverrides field ✅ Implemented Aider prompts now live in driverOverrides.aider.promptTemplate; tested at phase-registry.test.ts:141-150

Test plan

  • npm run build — passes (TypeScript clean)
  • npm run lint — passes (no ESLint errors)
  • npm test — 118 files, 3052 tests pass
  • CLI integration tests pass — phase-registry.integration.test.ts covers --phases bogus (rejected), --phases exec,bogus,qa (rejected), --phases spec,exec,qa (accepted)
  • Existing behavioral tests preserved — phase-executor.test.ts's "uses AIDER_PHASE_PROMPTS for non-claude agents" and "uses PHASE_PROMPTS for claude-code agent" both still pass, sourced from the registry
  • phase-mapper.test.ts UI / security / docs / bug label detection tests all pass

Notes

  • Phase type widens from string-literal union to string. The single switch (phase) site in phase-executor.ts (only special-cases qa and exec) keeps working as runtime string comparison.
  • Built-in registrations live colocated at the bottom of phase-registry.ts rather than a separate built-in-phases.ts to avoid an ESM import cycle (same pattern as drivers/index.ts).
  • BUG_LABELS / DOCS_LABELS / COMPLEX_LABELS stay in phase-mapper.ts — they are issue-type / quality-loop metadata, not phase-trigger rules. Code comments document the distinction.

Closes #505

Replace the scattered `PHASE_PROMPTS` / `AIDER_PHASE_PROMPTS` /
`ISOLATED_PHASES` / `UI_LABELS` / `SECURITY_LABELS` constants with a
uniform `PhaseDefinition` record per phase, registered against a single
`phaseRegistry` singleton at module load. All 9 built-in phases register
through the same mechanism — no special-casing inside consumer code.

Per-driver prompts (Aider) move into `PhaseDefinition.driverOverrides`,
worktree-isolation moves into `PhaseDefinition.requiresWorktree`, and
label-based auto-detection moves into `PhaseDefinition.detect.labels`.

`PhaseSchema` switches from `z.enum([...])` to `z.string().refine(...)`
so registry membership becomes the source of truth at runtime. The
`Phase` type widens from a string-literal union to `string`; the four
`.options` call sites (state-schema `WORKFLOW_PHASES`, phase-types
tests, assess-skill test) move to a new `getPhaseNames()` helper.

The `--phases` CLI flag now validates each name against the registry
and exits with `Unknown phase 'X'. Available: ...` on miss.

User-defined phases (`.sequant/phases/` filesystem discovery) and the
`sequant phases` command are deliberately deferred per the 2026-04-09
descoping comment on #505.
admarble added 3 commits May 13, 2026 22:46
QA flagged that `docs/features/phase-type-definitions.md` still described
the pre-registry workflow (z.enum, PHASE_PROMPTS, AIDER_PHASE_PROMPTS,
PhaseSchema.options). Rewrite to reflect the registry pattern: phases
are registered via phaseRegistry.register(...) in phase-registry.ts,
PhaseSchema is a Zod string refinement, and getPhaseNames() replaces
the removed PhaseSchema.options.
Two non-blocking QA observations from the prior review:

1. `retryStrategy` was registered as metadata in `phase-registry.ts` but
   `phase-executor.ts` still used hardcoded `SPEC_RETRY_BACKOFF_MS` /
   `SPEC_EXTRA_RETRIES` literals and a `phase === "loop"` string equality
   check. Wire the constants to the registry's `spec.retryStrategy` fields
   (with legacy literals as misconfiguration fallbacks) and replace the
   loop literal with `retryStrategy.maxRetries === 0` — any future phase
   registered with that setting inherits the skip-cold-start-retries
   behavior without a code change here.

2. `bin/cli.ts:validatePhasesFlag` used `console.error + process.exit(1)`.
   Throwing Commander's `InvalidArgumentError` from an option validator is
   idiomatic and produces a clearer message (Commander prefixes with the
   offending flag name). The existing integration test still passes — its
   assertions match against the preserved message substrings.
PR #504 (typed workflow event system, commit b4e8814) merged to main
during this session and touches several of the same files. Both PRs'
type/import additions in types.ts are independent (registry import vs.
event-emitter re-exports) — kept both. CHANGELOG entries are also
independent (#504 Added, #505 Changed) — kept both, ordered Added before
Changed per Keep-a-Changelog convention. Updated the #505 CHANGELOG
bullet to reflect the new retryStrategy consumption from the registry.

phase-executor.ts, phase-mapper.ts, bin/cli.ts auto-merged. Full
workflow test suite (37 files / 878 tests) passes after merge.
@admarble
admarble merged commit ed1d692 into main May 14, 2026
5 checks passed
@admarble
admarble deleted the feature/505-arch-phase-plugin-registry-user-extensible-workflo branch May 14, 2026 07:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

arch: phase plugin registry — user-extensible workflow phases

1 participant