refactor(installer): split init.ts into focused modules#242
Draft
filip131311 wants to merge 1 commit into
Draft
Conversation
Replaces the spaghetti in init/update/uninstall with a topology table +
phase modules.
New modules:
- package-manager.ts PM detection, install/uninstall commands
- topology.ts GLOBAL/LOCAL with probe + install/uninstall/spawnCwd
- preflight.ts hasPackageJson / isYarnPnp
- shell.ts runShellCommand
- install-error.ts manifest-error pattern matching + reporting
- init-args.ts flag parsing + cross-flag validation
- init-mode-prompt.ts Step-0 install-mode selector
- install-runner.ts shared install execution for both topologies
- init-adapters.ts Step-1 adapter universe + multiselect
- init-scope.ts scope prompt (local/global/custom)
- init-mcp-write.ts per-adapter MCP entry writes (with fallbacks)
- init-allowlist.ts tool auto-approval step
- init-skills.ts Step-2 skills install flow
Refactors:
- init.ts: 822 → 345 lines, reads top-to-bottom like a recipe
- update.ts: iterates TOPOLOGIES instead of duplicating per-topology
helpers
- uninstall.ts: collapses the two duplicate topology branches into a
single loop over TOPOLOGIES
- mcp-configs.ts: replaces `adapter.name === "Claude Code"` string
match with a typed `expandsProjectDirVariable` adapter flag
- utils.ts: 646 → 425 lines, PM and topology helpers re-exported from
their new homes for backwards compatibility
All 314 installer tests + 691 tool-server tests still pass.
e18ff5c to
08245e4
Compare
08245e4 to
e18ff5c
Compare
Member
|
Force pushed, apologies. I reverted my changes. |
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
Same feature as #232, restructured. The original PR's
init.tshad grown to 822 lines mixing flag parsing, topology decisions, interactive prompts, install commands, adapter filtering, MCP config writes, allowlist, skills install, and the summary into one long function with deep branching on install mode. This refactor splits it into a thin orchestrator (~345 lines) plus focused modules.No behavior changes. All 314 installer tests + 691 tool-server tests still pass. The visible CLI surface is unchanged —
argent init,argent init --devdep,argent update,argent uninstallall behave exactly as before.What changed
New modules (each 19–192 lines, single responsibility):
package-manager.tsPackageManagertype, lockfile + user-agent detection, install/uninstall command builders for both topologiestopology.tsTopologyinterface +GLOBAL/LOCALobjects withprobe,installCommand,uninstallCommand,spawnCwd.TOPOLOGIEStable that update/uninstall iterate.preflight.tshasPackageJson,isYarnPnpshell.tsrunShellCommandinstall-error.tsreportLocalInstallFailureinit-args.tsparseInitArgs+validateInitArgs(cross-flag invariants like--devdep⊥--scope global)init-mode-prompt.tsinstall-runner.tsinit-adapters.tsinit-scope.tsinit-mcp-write.tsinit-allowlist.tsinit-skills.tsRefactors:
init.ts: 822 → 345 lines. Reads top-to-bottom like a recipe — parse args → decide topology → install → MCP config → allowlist → skills → rules → summary. Each phase is one call into a dedicated module.update.ts: iteratesTOPOLOGIESinstead of bespoke per-topology helpers. The "needs update" loop is now four lines.uninstall.ts: collapses two duplicated topology branches into a single loop overTOPOLOGIES. Tool-server kill happens once via amakeOncehelper.mcp-configs.ts: dropsadapter.name === \"Claude Code\"string match for${CLAUDE_PROJECT_DIR}substitution; replaced with a typedexpandsProjectDirVariableadapter flag (set onclaudeAdapter). This was flagged as fragile in the original review.utils.ts: 646 → 425 lines. PM + topology helpers re-exported from their new homes so external callers keep working.How to review
Start at
init.ts— the diff against #232 is large, but the new file reads sequentially and each function call points at the module that owns the work.Then jump into
topology.tsto see how the GLOBAL/LOCAL split is encoded once and consumed by all three commands. Compareupdate.tsanduninstall.tsto confirm the duplication is gone.The remaining
init-*.tsmodules are each small and self-contained — review individually.Tests
All existing tests pass unchanged:
@argent/installer: 314 passed (7 files)@argent/tool-server: 691 passed (73 files)Existing tests cover:
--devdep/--local-install/--scope globalrejection)npx)isLocallyInstalledtwo-part check (declaration + files)getLocallyInstalledVersionreads disk, not running modulegetMcpEntryfor both modes, Claude vs non-Claude adaptersFollow-up ideas (not in this PR)
topology.test.ts,init-args.test.ts, etc.). The current test surface lives mostly inutils.test.ts/init.test.tsand still passes because the re-exports keep the API stable, but the new modules deserve their own test files for clearer ownership.getMcpEntry'sadapterparameter required in local mode via overloads — currently optional with a fallback to the non-Claude path. Type system can enforce the contract.Why this is a draft
Wanted to get the structure in front of reviewers before adding new tests for each module — happy to mark ready-for-review once the architecture has a 👍.