Repository navigation
Description
Epic: graph-2026-10-fundamentals Tier: mechanical Execution: sequant_run Blocked by: #1502
Problem
Five command entry points exceed 200 counted lines (ESLint counting, measured 2026-10-18): initCommand (init.ts:618, 588), doctorCommand (doctor.ts:545, 555), syncCommand (sync.ts:452, 325), updateCommand (update.ts:69, 256), readyCommand (ready.ts, 206). They are linear sequences of steps, each already covered by unit and integration tests (init.test.ts + 3 integration files, doctor.test.ts + 2, sync.test.ts + 2, update.test.ts + 1, ready tests under src/commands/). None of these files is in a consolidation node's scope (#1471 touches commands/logs.ts and commands/stats.ts; #1475 touches commands/locks.ts).
Acceptance Criteria
- AC-1: No function over 200 counted lines in
src/commands. Evidence:npx eslint --rule 'max-lines-per-function: [error, {max: 200, skipBlankLines: true, skipComments: true}]' 'src/commands/**/*.ts' --ignore-pattern '**/*.test.ts' --format json | jq '[.[].messages[] | select(.ruleId=="max-lines-per-function")] | length'→0 - AC-2: The ratchet is in the config for this directory. Evidence:
grep -c "src/commands/\*\*" eslint.config.js→≥ 1 - AC-3: Lint is green with the rule (constraint: green today, must stay green after AC-2). Evidence:
npm run lint > /dev/null 2>&1 && echo green→green - AC-4: No test lines are added (I-3, constraint). Evidence:
git diff --numstat $(git merge-base origin/main HEAD)..HEAD -- '*.test.ts' '*.test.tsx' | awk '{a+=$1} END{print a+0}'→0 - AC-5: The command suites pass unchanged. Evidence:
npx vitest run src/commands/init src/commands/doctor src/commands/sync src/commands/update src/commands/ready→0 failed - AC-6: The baseline moves down with the PR. Evidence:
jq '.functions.over200' scripts/qa/health-baseline.json→≤ 7
Prior fixes / producers
- Prior fixes:
init.tsandsync.tstogether took 18 fix commits in 90 days (git log --since='90 days ago' --format=%s -- src/commands/init.ts src/commands/sync.ts | grep -c '^fix'→ 18 on 2026-10-18). Class, not site: the AC states the outcome for the directory. - Producers: one owner per file;
sync.tsandupdate.tsshare the install-scope logic landed by feat(update): respect the manifest's install scope — update on a skills-only install installs hooks, agents and settings.json #1482 — the split must not duplicate it (accretion'sdupsmust report no new group).
May touch
src/commands/init.ts, src/commands/doctor.ts, src/commands/sync.ts, src/commands/update.ts, src/commands/ready.ts, new sibling modules under src/commands/<name>/ for extracted steps, eslint.config.js (one appended block scoped to src/commands/**), scripts/qa/health-baseline.json (I-4), CHANGELOG entry. No test file (I-3).
Non-Goals
- Any behaviour or output-wording change (the integration tests match output).
- Any new shared helper that already exists (check
src/lib/first; D-C's accretion check applies). - No edits under
plugin/,.claude/skills/,templates/skills/(I-1).
Done when
src/commands has no function over 200 counted lines, the rule enforces it, and no test changed.
Activity
admarble commentedon Oct 19, 2026
Runner context, 2026-10-19, before launch (fundamentals W2, beside #1504 and #1512; stop-at-PR). main = 23a60b3.
Changed since filing:
init.tsgainedwriteIssueFormIfAbsentanddoctor.tsgainedissueFormInfoLinein feat(init): the issue form from the writing-issues guide becomes one template file that init writes to .github/ISSUE_TEMPLATE when the directory is absent; doctor reports its absence #1528 (da9c4fd). Both are small helpers called from the long command functions; keep the behaviour when splitting.eslint.config.jsrelaxed block is gone (chore(lint): end the 2026-01 "temporarily relaxed" rules, add knip as an advisory job with a numeric baseline #1503). Append this issue's block; don't edit others.functions.over200= 12 andover400= 4.#1475 (
src/commands/locks.ts,lib/locks/) may run beside this. Stay within the five named command files.For every phase, and the qa phase by name: run the full suite at most once, in the foreground, under
timeout, after a WIP commit. Each MCP-dispatched phase has a 30-minute wall. Prefer the targetednpx vitest run <files>for the ACs.CHANGELOG: add
[Unreleased]lines under the existing### Added/### Changedheadings, notchangelog.d/fragments, and never add a second heading of the same name.Lint: #1503 made
no-unused-vars,no-empty-object-typeandprefer-consterrors, and knip counts unused exports. Don't export what nothing imports.Health baseline: regenerate
scripts/qa/health-baseline.json(npx tsx scripts/qa/health-report.ts --write-baseline) only to record a metric that went down. Ifnpm run lint:healthreports a rise, restructure so it holds. Otherwise leave the baseline alone and name the rise in the PR body. Owner ruling: aproseGate.linesrise caused by tests in files that mentionSKILL.mdonly as a path may be absorbed, and must be said so.Freeze: nothing under
plugin/,.claude/skills/ortemplates/skills/.admarble commentedon Oct 19, 2026
Complexity: Standard (6 ACs, 1 directory)
AC Quality Check
All six ACs are single-line with an
Evidence:clause. Run against main (23a60b3):5(doctor 573, init 589, sync 325, update 256, ready 206)0012Notes: AC-6 only works out exactly: 12 − 5 = 7, so all five functions must be fixed, and no other function may cross 200. AC-5's path prefixes (
init,doctor,sync,update,ready) also matchinit.*.test.ts,doctor.*.test.ts,ready.*.test.tsand the integration files. No ambiguity.Scope Assessment
Non-Goals: present (no behaviour or wording change, no new duplicate helpers, no edits under
plugin/,.claude/skills/,templates/skills/).src/commands) +eslint.config.js, baseline, CHANGELOGVerdict: ✅ SCOPE_OK. Large diff (~2,000 lines moved), but mechanical.
Acceptance Criteria
AC-1: No function over 200 counted lines in
src/commandsVerification: Integration Test (lint command)
Scenario: Given the five oversize commands → When steps are extracted → Then the ESLint count is
0.Assumptions: The rule counts
skipBlankLinesandskipComments; the heavy comment blocks in these files don't count, so only code lines matter.AC-2: Ratchet in
eslint.config.jsVerification: Integration Test (grep + lint)
Scenario: Given the config has no
max-lines-per-functionblock → When one block scoped tosrc/commands/**/*.tsis appended → Then grep ≥ 1, and a deliberately long function in a scratch file fails lint (mutation check).Assumptions: The
#1503relaxed block is gone (runner comment), so there is nothing to edit — append only.**/*.test.tsis already globally ignored.AC-3: Lint stays green
Verification: Integration Test (
npm run lint)Scenario: Then no new
no-unused-vars/prefer-consterrors; knip doesn't see new unused exports.AC-4: No test lines added
Verification: Integration Test (git numstat)
Scenario: Then added test lines = 0.
AC-5: Command suites pass unchanged
Verification: Integration Test (targeted vitest)
Scenario: Then
0 failedfromnpx vitest run src/commands/init src/commands/doctor src/commands/sync src/commands/update src/commands/ready.Assumptions: Tests mock by module path (
vi.mock("../lib/…")). Moving a call into a new module doesn't break mocks of the callee modules, but a mock of something the command file itself exports, or an orderedchild_processmock queue, would shift. Read the tests before moving any call that spawns processes.AC-6: Baseline moves to ≤ 7
Verification: Integration Test (
jq)Scenario: Then
npx tsx scripts/qa/health-report.ts --write-baselinewritesover200: 7, andnpm run lint:healthpasses.over400should drop from 4 to 0–2 (init, doctor are ≥ 400 today).Implementation Plan
Decision: where do extracted steps live? The issue permits
src/commands/<name>/sibling modules. Recommended: one directory per command, named for the command, with steps as plain functions taking a small context object. Rejected: extracting intosrc/lib/(reaches beyond the "May touch" list and invites the duplicate-helper check) and splitting by closure (same total line count, no gain).Phase 1: Ratchet first, red (1 step)
src/commands/**/*.tsblock toeslint.config.js(max-lines-per-function200,skipBlankLines,skipComments;**/*.test.tsignored already). Lint now reports exactly five errors, which is the work list.Phase 2: Split the five functions (parallel-safe; one file each)
Each split must be a pure move: same call order, same output strings, same exit codes. Keep early-returns and
process.exitin the command function; extract the bodies between them.ready.ts(206, trivial): extract the progress-UI setup (lines ~275–335) into a helper. Needs ~10 lines out.update.ts(256):src/commands/update/with steps:resolveConfigTokens(the legacy-migration block, ~139–200),planChanges(changes + summary),applyChanges. The MCP pin and partial-install refusal stay ordered before any write (feat(update): respect the manifest's install scope — update on a skills-only install installs hooks, agents and settings.json #1482).sync.ts(325):src/commands/sync/withresolveInstallScope,reportDrift/fast-path verify,previewApply,apply. Must reuse the install-scope logic from feat(update): respect the manifest's install scope — update on a skills-only install installs hooks, agents and settings.json #1482 shared withupdate.ts; extract once, import from both, no second copy (accretiondupsmust not report a new group).doctor.ts(573): check list is linear. GroupCheck 0..10intosrc/commands/doctor/modules by theme (install integrity: manifest/skills/hooks/settings; environment: git/gh/claude/agents; extras). Each returns itschecksentries;doctorCommandconcatenates in the original order. KeepissueFormInfoLine(feat(init): the issue form from the writing-issues guide becomes one template file that init writes to .github/ISSUE_TEMPLATE when the directory is absent; doctor reports its absence #1528) where it is called today.init.ts(589):src/commands/init/withrunPreflight(templates-root check,--upgrade-skills,--manifest-only),resolveStacks(the ~120-line stack prompt),scaffold(dirs, gitignore, config, settings),copyAndReport. KeepwriteIssueFormIfAbsentcall order.Phase 3: Baseline, CHANGELOG, verification
--write-baseline) only afterover200is 7 andlint:healthshows nothing rising. Runknip/npm run lintfor unused exports (don't export what nothing imports; use non-exported helpers where the command file is the sole caller).[Unreleased]line under the existing### Changedheading in CHANGELOG (no new heading, nochangelog.d/).timeoutafter a WIP commit (30-min wall).Dependencies: #1502 is closed. Phase 2 steps are independent, so they could be parallel in
/exec, but they share the lint config and baseline; the WIP-commit-per-file rule (commit every 10 min) applies.Design Review
src/commands/<command>/, next to the command that calls it. The commands layer owns orchestration; no newlibsurface.init.ts+sync.tstook 18 fix commits in 90 days (issue's own count), which is a class, not a site. This work addresses the class (size) for the directory; it adds no new fix to any of those 18 bugs. No divergence from the prescribed lever.git diff --color-moved.init.ts←bin/cli.tsand tests;sync.ts/update.tsshare feat(update): respect the manifest's install scope — update on a skills-only install installs hooks, agents and settings.json #1482 install-scope helpers (single owner needed);doctor.tsreusescheckSkillsInstalledwithrunpre-flight (feat(run): pre-flight the skills install — missing .claude/skills/ should fail fast, not flail for 30 minutes as a spec retry #813) — leave it as is.health-baseline.jsonis produced byhealth-report.tsonly.No ADR required: not choosing between competing designs in a way that binds future work.
Feature Quality Planning
All standard checks pass. Notable items:
child_processmocks (reference_ordered_child_process_mocks) shift if an extraction changes the git/gh call order. Preserve order.Mutation-verified: AC-2 — delete the eslint block; <test> failed; restored.only if a test gates it; the AC is a lint command, so proof is the red lint in Phase 1 (the five errors) before the splits.src/commandsfunctions are < 200 today (lint reports exactly five).run.ts/ready.tslarge helper closures are not flagged; no scope widening.Open Questions
src/commands/doctor/next todoctor.ts, ordoctor-checks.tsflat files? Recommendation: directories per the issue. Impact if wrong: only import paths.doctor.tsend up as a one-line wrapper? Recommendation: keep exporteddoctorCommandandDoctorOptionsindoctor.tsso imports andvi.mockpaths in tests don't change. Impact: tests would need edits (violates AC-4).Recommended Workflow
Phases: exec → qa
Quality Loop: enabled
Reasoning: Mechanical refactor with existing test coverage; no new tests are allowed (AC-4), so testgen is skipped. No UI. Quality loop on because the diff is large and the behaviour-preservation check is the main risk.
Label Review
Current: graph-2026-10-fundamentals
Recommended: +
refactor,plannedReason: Refactor label signals the quality loop;
plannedmarks spec done.Quality Loop: Enabled (set above).
admarble commentedon Oct 19, 2026
QA Verdict: AC_MET_BUT_NOT_A_PLUS
AC coverage: 6/6 met
Gaps:
emptyCatch.total: 118andunusedExports: 342. Main lowered those to 117 and 341, so the ratchet would get looser.origin/main, then runnpx tsx scripts/qa/health-report.ts --write-baselineagain so the baseline hasover200: 7together with main's lower counts.Suggestions:
eslint.config.jssays the steps belong in "a sibling module undersrc/commands/<name>/", but this PR keeps them as non-exported helpers in the same file. Either reword the comment or accept both layouts.chore(#1509): the ratchet comment allows same-file step functions (QA…
chore(#1509): merge main; baseline records over200 7 and over400 2 wi…
admarble commentedon Oct 19, 2026
Execution Verification (runner, 2026-10-19), PR #1561 @ f7802c7
After merging main (through #1558), the runner re-ran AC-1..AC-6 verbatim:
01green0templates.test.ts)7The baseline records
functions.over2007 (from 12) andover4002 (from 4), with main's loweremptyCatch/unusedExportscounts kept.Control flow: the runner compared every early
returnin the oldinit/doctor/sync/update/readycommand functions with the split.resolveTokens→if (!tokens) return, andreportVersionCurrentDriftkeeps fix(update/sync): sync reports 'up to date' on content drift; update overwrites in-place customizations (constitution) #708'sexitCode = 1.QA's documentation finding is fixed: the eslint ratchet comment now allows same-file step functions.
chore(#1509): merge main (#1504, #1512); baseline over200 7 / over400 2