Repository navigation
Closed
Labels
enhancementNew feature or requestplannedImplementation plan approvedready-for-reviewReady for code reviewroadmapFuture plans and roadmap items
Description
Problem (User Impact)
Users who want to invoke Sequant programmatically (from MCP, CI scripts, or other tools) must go through the CLI entry point — there's no clean API boundary. Internally, run.ts (1,171 lines) mixes CLI flag parsing, configuration merging, branch detection, execution orchestration, and progress reporting in a single file. This makes the core engine untestable without mocking Commander.js and creates friction for every downstream improvement.
This is the foundational issue. Nearly every architectural improvement depends on having a clean orchestration layer separated from CLI concerns.
Why Now
- MCP server currently spawns a subprocess to run workflows (Interactive relay: bidirectional communication with headless runs #383 interactive relay is blocked by this)
- Testing the execution engine requires mocking 14+ imports because business logic is entangled with CLI wiring
- Adding new frontends (dashboard, SDK, CI integration) requires duplicating orchestration logic
batch-executor.ts(736 lines) andphase-executor.ts(458 lines) are well-factored but their caller (run.ts) is not
Acceptance Criteria
- AC-1: New
RunOrchestratorclass insrc/lib/workflow/run-orchestrator.tsowns the full execution lifecycle: config resolution → issue discovery → batch/chain/sequential dispatch → worktree management → result aggregation - AC-2:
src/commands/run.tsbecomes a thin adapter: parse CLI flags → normalize options → constructRunOrchestrator→ callorchestrator.execute()→ format output. Target: under 200 lines - AC-3:
RunOrchestratoraccepts a typedRunConfig(not CLI options) — no Commander.js types leak into the engine - AC-4:
RunOrchestratoris importable and usable without CLI context:import { RunOrchestrator } from 'sequant'works from Node.js - AC-5: Configuration merge logic (settings defaults → project settings → env → explicit config) extracted into a
ConfigResolverclass/function with its own unit tests - AC-6: All existing
runcommand tests pass; new unit tests forRunOrchestratorcover batch, sequential, and chain modes without mocking Commander.js - AC-7:
normalizeCommanderOptions()eliminated or reduced to a 1-line adapter at the CLI boundary
Scope & Gaps to Watch
- Gap: MCP integration — The MCP server (
src/mcp/tools/run.ts) currently spawns a subprocess. This issue does NOT change MCP to use in-process execution (that's a follow-up), but theRunOrchestratorAPI must be designed so MCP can call it directly - Gap: Progress reporting —
run.tscurrently mixes progress display with execution. The orchestrator should accept an optional progress callback or event listener, but a full event system is a separate issue - Gap: Settings validation — Config merge is extracted but schema validation is a separate concern (tracked separately)
- Risk: Behavioral regression — The 4-layer config merge has undocumented edge cases (e.g.,
--no-mcpCommander negation). Integration tests must verify flag behavior end-to-end
Technical Notes
run.tsimports:batch-executor,phase-executor,worktree-manager,state-manager,log-writer,metrics-writer,settings,config,cli-ui,shutdown,tty,phase-detection,scope-assessment, plus Commander- The
normalizeCommanderOptions()function (run.ts:135) handles Commander's--no-X→{ X: false }quirk — this logic should stay at the CLI boundary, not move into the orchestrator detectDefaultBranch()in run.ts usesspawnSync— the orchestrator version should accept base branch as config, with detection as a default
Dependencies
- Blocks: Event system, phase registry, async I/O modernization, in-process MCP engine
- Related: Interactive relay: bidirectional communication with headless runs #383 (interactive relay), Multi-agent support: expand Sequant beyond Claude Code #373 (multi-agent support)
Batch Group
sequant run batch 1 (parallel with config/error hardening issue — no shared dependencies)
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestplannedImplementation plan approvedready-for-reviewReady for code reviewroadmapFuture plans and roadmap items
Activity
admarble commentedon Apr 8, 2026
Spec Plan — #503: Extract RunOrchestrator
AC Quality Check
✅ All 7 acceptance criteria are clear and testable.
Scope Assessment
Non-Goals (from issue body):
AC Checklist with Verification Criteria
AC-1: RunOrchestrator class owns full execution lifecycle
Verification: Integration Test
RunOrchestratorwith validOrchestratorConfigand mocked servicesorchestrator.execute([123])calledexecuteBatch(), returnsIssueResult[]with correct structureAC-2: run.ts becomes thin adapter (< 200 lines)
Verification: Unit Test + Manual (
wc -l)src/commands/run.tsrunCommand()delegates toRunOrchestrator.execute()AC-3: RunOrchestrator accepts typed config (no Commander.js types)
Verification: Unit Test (compile-time)
run-orchestrator.tsimportsRunOptionsreferencesOrchestratorConfigAC-4: Importable without CLI context
Verification: Integration Test
import { RunOrchestrator } from 'sequant'.execute(), no CLI side effectsAC-5: ConfigResolver extracted with unit tests
Verification: Unit Test
ConfigResolver.resolve({ settings, env, explicit })AC-6: Existing tests pass + new orchestrator tests
Verification: Unit Test + Integration Test
vitest runrun-orchestrator.test.tstestsAC-7: normalizeCommanderOptions eliminated or reduced
Verification: Unit Test
run.tsImplementation Plan
Phase 1: Extract ConfigResolver (AC-5, AC-7)
src/lib/workflow/config-resolver.tsrun.ts:249-278ExecutionConfigconstruction fromrun.ts:414-431normalizeCommanderOptionsas 1-liner at CLI boundaryconfig-resolver.test.tsPhase 2: Extract RunOrchestrator (AC-1, AC-3)
src/lib/workflow/run-orchestrator.tswithRunOrchestratorclassOrchestratorConfig(CLI-free) andOrchestratorServices(injectable deps)ProgressCallbackpatternPhase 3: Slim down run.ts (AC-2)
runCommand(): parse CLI → ConfigResolver → RunOrchestrator → format outputPhase 4: Public API export (AC-4)
RunOrchestrator,ConfigResolver, types tosrc/index.ts'sequant'worksPhase 5: Tests (AC-6)
run-orchestrator.test.ts: batch, sequential, chain, shutdownDesign Decisions
ProgressCallbackpattern; EventEmitter deferredDerived ACs
process.exit--no-mcp/--no-retrynegationOpen Questions
{ execution, logging, state, worktree }). Flat is simpler but mixes concerns.Conflict Risk
#507 (config schema validation) has a worktree but no changes yet. Concerns are orthogonal — #503 extracts merge logic, #507 adds schema validation. Low risk.
Recommended Workflow
Phases: spec → testgen → exec → qa
Quality Loop: enabled (auto-enabled due to scope)
Reasoning: Major refactor of 1,171-line file. Unit test ACs warrant testgen. Quality loop ensures regression-free extraction.
Label Review
Current: enhancement, roadmap
Recommended: + refactor
→
gh issue edit 503 --add-label refactoradmarble commentedon Apr 8, 2026
Test Stubs Generated
__tests__/run-orchestrator.test.ts__tests__/integration/run-orchestrator.integration.test.ts__tests__/run-orchestrator.test.ts__tests__/integration/run-orchestrator.integration.test.ts__tests__/config-resolver.test.ts__tests__/run-orchestrator.test.ts__tests__/config-resolver.test.ts__tests__/run-orchestrator.test.ts__tests__/run-orchestrator.test.ts__tests__/config-resolver.test.tsTotals: 64 test stubs across 3 files (1,185 lines)
Unit Test Stubs
__tests__/config-resolver.test.ts(509 lines, 24 stubs)__tests__/run-orchestrator.test.ts(514 lines, 31 stubs)Integration Test Stubs
__tests__/integration/run-orchestrator.integration.test.ts(162 lines, 9 stubs)Next steps:
/exec 503to implement the featurethrow new Error(...)with actual test logic)npm testGenerated with Claude Code
docs: add target architecture diagram for #503-#508
feat(#503): extract RunOrchestrator to decouple execution engine from…
admarble commentedon Apr 8, 2026
Exec Phase — Progress Update
AC Coverage
Key Files Changed
src/lib/workflow/run-orchestrator.tssrc/lib/workflow/config-resolver.tssrc/commands/run.tssrc/commands/run-compat.tssrc/index.ts__tests__/config-resolver.test.ts__tests__/run-orchestrator.test.ts__tests__/integration/run-orchestrator.integration.test.tsQuality Gates
npm run build— passesnpm run lint— 0 errors, 0 warningsnpm test— all tests passPR
→ #510
Quality Plan Alignment
N/A — No quality plan in spec comment. Derived ACs (AC-8, AC-9, AC-10) addressed.
admarble commentedon Apr 8, 2026
QA Review for Issue #503 — Extract RunOrchestrator
Stale Branch Check
Feature branch is 2 commits behind main. Consider rebasing before merge.
Size Gate
AC Coverage
RunOrchestratorclass withexecute()for low-level andstatic run()for full lifecycle. Covers config → issue discovery → batch/chain/sequential dispatch → worktree management → result aggregation.RunOrchestrator.run(), formats summary output.commanderimports and nobin/clireferences. UsesOrchestratorConfigexclusively.src/index.ts. Integration test confirms import, constructability,.execute()and.run()availability, and no CLI side effects on import.ConfigResolverclass inconfig-resolver.ts(231 lines) with 24 unit tests covering 4-layer priority merge, type coercion, edge cases.run.test.tstests pass. 53 new tests across 3 files pass. Build succeeds.config-resolver.ts. Only used at CLI boundary viaresolveRunOptions(). Programmatic callers bypass it.configpresence andphasesnon-empty array. 3 tests verify.process.exitonly inrun.ts:119(CLI adapter, appropriate).normalizeCommanderOptionsflag mapping andConfigResolvernegation handling.Coverage: 10/10 AC items fully met
Original ACs: 7/7 met
Derived ACs: 3/3 met
Quality Plan Verification
Quality Plan found: Yes (from spec comment)
any, noprocess.exitDerived ACs: 3/3 addressed
Quality Plan Status: Complete
CI Status
PR #510 exists. No CI checks configured (
statusCheckRollupis empty).Quality Metrics
any)Build Verification
N/A — Build passed (
tscclean, zero errors).Test Coverage Analysis
src/lib/workflow/run-orchestrator.ts__tests__/run-orchestrator.test.ts,integration/run-orchestrator.integration.test.tssrc/lib/workflow/config-resolver.ts__tests__/config-resolver.test.tssrc/commands/run.tssrc/commands/run.test.ts(131 existing tests), integration testsrc/commands/run-compat.tssrc/index.tsCoverage: 3/3 changed source files with logic have tests
Critical paths without tests: None
Code Review
Strengths:
RunOrchestratorowns lifecycle,ConfigResolverowns merge logic,run.tsis a pure CLI adapterrun()for full lifecycle, instanceexecute()for low-level) — well-designed for MCP follow-upOrchestratorServicesenable clean testing without mocking 14+ importsRunResultstruct returns exit code instead of callingprocess.exit— orchestrator stays composablerun-compat.tspreserves backward compatibility for existing consumers ofcommands/runimportstry/finallycleanupIssues:
config-resolver.ts:109comment says "env is present but settings overrode it" — this is backwards. Env overrides settings in the priority order. The code is correct; only the comment is misleading.RunOrchestrator.run()is a 300-line static method. While it logically belongs here, it could be split into smaller private static helpers for readability. Not blocking.Suggestions:
config-resolver.ts:109(cosmetic, non-blocking)Test Quality Review
Issues Found: None
Anti-Pattern Detection
Code Patterns
No anti-patterns detected:
Critical Issues: 0
Warnings: 0
Call-Site Review
New exported functions detected: 4
resolveRunOptions()run-orchestrator.ts:153RunOrchestrator.run()buildExecutionConfig()run-orchestrator.ts:186,198normalizeCommanderOptions()config-resolver.ts:160(viaresolveRunOptions)logNonFatalWarning()run-orchestrator.ts:265,429All call sites match AC constraints. No mismatches found.
CLI Registration Verification
N/A — No option interface changes to
RunOptions. The interface was moved, not modified.CHANGELOG Verification
Result: CHANGELOG requirements met
Self-Evaluation
--no-Xflag interactions with env vars). Mitigated by 131 existing tests passing + 24 new ConfigResolver tests.Verdict: READY_FOR_MERGE
All 10 acceptance criteria (7 original + 3 derived) are fully met. The implementation cleanly separates the execution engine from CLI wiring:
RunOrchestrator(737 lines) owns the full lifecycle with no CLI dependenciesrun.tsreduced from 1,171 to 184 lines as a thin adapterConfigResolverextracted with 24 tests for the 4-layer config mergeDocumentation
Next Steps
config-resolver.ts:109(cosmetic)/docs 503if admin documentation is desired before mergeDocumentation: Before merging, run
/docs 503to generate feature documentation.admarble commentedon Apr 9, 2026
QA Review for Issue #503
Size Gate
AC Coverage
RunOrchestratorclass insrc/lib/workflow/run-orchestrator.tsowns full execution lifecyclestatic run()(full lifecycle) andexecute()(low-level). Handles config resolution → issue discovery → batch/chain/sequential dispatch → worktree management → result aggregation.src/commands/run.tsbecomes thin adapter under 200 linesRunOrchestrator.run()→ formats output viadisplaySummary().RunOrchestratoraccepts typedRunConfig— no Commander.js typesimportfromcommanderin run-orchestrator.ts. UsesOrchestratorConfig/RunInitinterfaces withExecutionConfigandRunOptions— all project types. Verified by test (reads source, asserts no commander import).RunOrchestratorimportable without CLI contextsrc/index.tsat line 132. Integration test verifiesimport { RunOrchestrator }works, class is constructable, and import causes no CLI side effects.ConfigResolverclass/function with unit testsConfigResolverclass (line 52) andresolveRunOptions()function (line 156) inconfig-resolver.ts. 23 unit tests inconfig-resolver.test.tscovering 4-layer priority, type coercion, boolean negation, edge cases.runcommand tests pass; new unit tests cover batch, sequential, chain modesrun.test.tstests pass (backward compat viarun-compat.tsre-exports). 53 new tests across 3 files covering batch (parallel), sequential (stop-on-failure), chain (qa-gate), config validation, shutdown, importability.normalizeCommanderOptions()eliminated or reduced to 1-line adapterconfig-resolver.ts:139-150). Maps Commander's--no-X→{ noX: true }. Not used by programmatic callers —ConfigResolverhandles raw keys directly.Coverage: 7/7 AC items fully met
Quality Metrics
any)as anyin testsBuild Verification
Test Coverage Analysis
src/lib/workflow/run-orchestrator.ts__tests__/run-orchestrator.test.ts+__tests__/integration/run-orchestrator.integration.test.tssrc/lib/workflow/config-resolver.ts__tests__/config-resolver.test.tssrc/commands/run.tssrc/commands/run.test.ts(131 existing tests)src/commands/run-compat.tsrun.test.ts(imports via compat re-exports)src/index.ts__tests__/integration/run-orchestrator.integration.test.ts(importability tests)Coverage: 5/5 changed source files have corresponding tests
Critical paths without tests: None
Code Review
Strengths:
run-compat.tsre-exports — all 131 existing tests pass untouchedRunOrchestrator.run()for full lifecycle,new RunOrchestrator(config).execute()for low-level) is well-designed for MCP/SDK consumersprocess.exitin orchestrator — returns structuredRunResultwithexitCode, letting callers decideOrchestratorServicesuses optional injection — degrades gracefully when services are absentIssues:
run.tson main is 1,171 lines. Should say "from 1,171 to 184 lines."sourcefield in ConfigResolver:layersarray objects include{ source, value }butsourceis never read (config-resolver.ts:78-83). Minor dead code.Suggestions (non-blocking):
ConfigResolverclass is exported but never instantiated in production code —resolveRunOptions()does the actual work via??coalescing. Consider whether the class adds value beyond being a test utility, or document that it's the generic building block for external consumers.logNonFatalWarninghelper is exported from bothrun-orchestrator.tsandrun-compat.ts— consumers should prefer the orchestrator import path.Test Quality Review
Anti-Pattern Detection
Dependency Audit
N/A — No dependency changes
Code Patterns
sourcein layers arrayCritical Issues: 0
Warnings: 2 (minor readability)
Call-Site Review
New exported functions detected: 4
resolveRunOptions()run-orchestrator.ts:153RunOrchestrator.run()buildExecutionConfig()run-orchestrator.ts:186,198normalizeCommanderOptions()config-resolver.ts:160resolveRunOptionslogNonFatalWarning()run-orchestrator.ts:265,292,429Findings: All call sites match AC constraints. No unused exports (all called).
CI Status
PR #510 exists. No CI checks configured (
statusCheckRollup: []).Quality Plan Verification
N/A — No quality plan found in issue comments
Cache Status
N/A — Fresh run
CHANGELOG Verification
Result: CHANGELOG present but has a factual inaccuracy in the line count
Self-Evaluation
commands/run.tsthat weren't included inrun-compat.tsre-exports. The existing 131 tests passing mitigates this risk significantly.Verdict: READY_FOR_MERGE
All 7 ACs fully met.
run.tsreduced from 1,171 to 184 lines.RunOrchestratorcleanly separated from CLI with typed interfaces. 184 tests passing (131 existing + 53 new). No regressions, noanytypes, no security issues.Minor items to address (non-blocking):
sourcefield in ConfigResolver layers (cosmetic)Documentation
Next Steps
/docs 503if documentation is desireddocs: descope target architecture after overcomplexity review
fix(#503): filter undefined spread in resolveRunOptions + add direct …
Merge pull request #510 from sequant-io/feature/503-arch-extract-runo…
admarble commentedon Apr 9, 2026
Documentation Generated
File:
docs/features/run-orchestrator.mdSections Included:
RunOrchestrator.run())new RunOrchestrator().execute())Next Steps:
Ready to merge!
fix(#494): /assess batch output formatting + label-priority spec-skip (…
docs(#503): add RunOrchestrator programmatic usage documentation
fix: update assess-skill test regex for 3-column label→phase table
fix: restore pre-run config display regressed by #503 refactor
feat(#618): unified run renderer — two-zone live grid + events log (#620
chore(#689): ready-gate backtest driver script (#691)
fix(#705): trim run.ts comments to stay under 200-LOC cap (#503 AC-2)
feat(#705): fix -q/-Q flag collision, make boxed Ink TUI the default …
chore(#795): deprecate --qa-gate, an inert no-op flag (#807)
fix(#848): keep run.ts under the 200-line thin-adapter cap after exit…
fix(#848): pre-flight rejections exit non-zero across run/update/stat…