Refactor: Extract bootstrap and command handlers into separate modules#26
Merged
Refactor: Extract bootstrap and command handlers into separate modules#26
Conversation
…used modules Split the 570-line monolithic index.ts into clean, single-responsibility modules: - src/bootstrap.ts: wires up provider, tools, middleware, skills, memory, MCP, observability - src/interfaces/commands.ts: skill management, memory CLI, context display, exec script - src/interfaces/help.ts: help text constant - src/index.ts: thin orchestrator with named launcher functions per interface Also improved signal handler cleanup (use process.off instead of removeAllListeners) and deduplicated the sidecar MCP startup pattern. https://claude.ai/code/session_01RVH28SjMU97CoJVbkfWK8T
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This refactor extracts the monolithic
src/index.tsinto focused, single-responsibility modules to improve maintainability and testability. The main entry point now orchestrates three distinct phases: early exits (help, version, exec), bootstrap (config + subsystem initialization), and interface launching.Key Changes
New
src/bootstrap.ts: Centralizes all subsystem initialization (provider, tools, middleware, skills, memory, MCP, observability) into a singlebootstrap()function that returns anAppContextobject. This eliminates ~200 lines of setup code from the main entry point and makes the initialization sequence explicit and reusable.New
src/interfaces/commands.ts: Extracts standalone command handlers (runExecScript,runSkillCommand,showContext,runMemoryCommand) that don't require a full interface loop. These were previously inline inmain().New
src/interfaces/help.ts: Moves the HELP text constant to a dedicated module for better organization and to reduce clutter in the main entry point.Refactored
src/index.ts: Restructured into three logical phases:handleEarlyExits): Version, help, exec, skill commands — no config/bootstrap neededhandleStandaloneCommands): Show context, memory operations — need bootstrap but no interfaceAppContextSignal handling: Extracted
onSignals()helper to centralize SIGINT/SIGTERM registration and removal, making cleanup more consistent across interfaces.Implementation Details
AppContexttype encapsulates all state needed by interface layers, eliminating the need to pass dozens of individual parameters.https://claude.ai/code/session_01RVH28SjMU97CoJVbkfWK8T