Next-Step Refactor Checklist
This doc tracks remaining reuse/refactor work now that the original plan is done. Each section lists the goal, why it matters, and the concrete steps/tests needed.
#1. Shared Tool Schema Cache (Completed)
- Problem:
generate-cliandemit-tsboth fetch & serialize tool schemas - What we did:
independently (and mcporter list re-parses them too).
- Added
src/cli/tool-cache.tswithloadToolMetadata()caching tool metadata per runtime/server/options. - Switched
mcporter list(single-server path) andemit-tsto consume the helper, so both reuseToolMetadata. - Added
tests/tool-cache.test.ts+ updated emit-ts tests to ensure the helper is covered.
- Next: Consider integrating the cache into
generate-cliif we ever reuse runtime instances there.
#2. Unified Flag Parsing for Generator-style Commands (Completed)
- Problem:
generate-cli, the (now legacy)regenerate-cliwrapper, andemit-tseach - What we did:
reimplemented --runtime, --timeout, and --include-optional handling.
- Added
extractGeneratorFlags()insrc/cli/generate/flag-parser.tsto - Updated all three commands to call the helper before parsing
- Added
tests/generator-flag-parser.test.tsto cover runtime/timeout and
normalize shared flags while mutating args in place.
command-specific options.
optional flags.
#3. Test Fixture Reuse (Completed)
- Problem: Emit-ts/tool-cache/unit tests each defined their own tool/definition
- What we did:
fixtures, leading to divergence.
- Added
tests/fixtures/tool-fixtures.ts(shared definition + tools). - Updated
tests/emit-ts.test.tsandtests/tool-cache.test.tsto import - Ensured the fixture covers required+optional parameters so both suites hit
the shared fixtures (and reuse them via buildToolMetadata).
the same edge cases.
#4. CallResult Helper Extraction (Completed)
- Problem:
call-command.tsand the emit-ts client template both wrapped - What we did:
results with createCallResult, but there was no shared helper.
- Added
wrapCallResult()toresult-utils.tsand exported it from the - Updated
call-command.tsand the emit-ts template to reuse the helper so - Adjusted emit-ts tests to assert the helper is referenced.
package entry.
they stay in sync.
#5. CLI Docs Consolidation (Completed)
- Problem: CLI usage guidance was scattered across README,
docs/spec.md, - What we did:
and various feature docs.
- Added
docs/cli-reference.mdsummarizinglist,call,generate-cli, - Pointed emit-ts users to that doc so we can converge other references over
and emit-ts flags/modes in one place.
time (no README/spec churn yet to avoid clobbering parallel work).
- Next: Once the other doc changes land, update README/spec to link to the
reference and drop redundant sections.
#6. Runtime Module Split (Completed)
- Problem:
src/runtime.tshad grown bulky (600+ lines) mixing transport setup, OAuth flow control, and small helpers, making tests and reuse harder. - What we did:
- Extracted transport construction/retry logic to
src/runtime/transport.ts. - Moved OAuth helpers (timeouts, connect retry, errors) to
src/runtime/oauth.tsand centralized env-parsed timeouts. - Pulled argument/timeout utilities into
src/runtime/utils.ts. - Made reset-policy logic reusable via
src/runtime/errors.ts. - Switched tests to import helpers directly instead of using
runtime.__test. - Added a targeted transport test to cover SSE fallback and OAuth promotion.
- Next: Keep new helpers in sync as runtime evolves; prefer adding surface to these modules over growing
runtime.tsagain.
Tracking the above here keeps future agents aligned. Update this checklist as items ship (mark sections “Completed” when done, or delete the doc once empty).