Repository navigation
Description
Epic: graph-2026-10-consolidation Tier: mechanical Execution: sequant_run
- Blocked by: tracker: graph-2026-10-consolidation — one definition per helper for the 16 duplicate groups the accretion audit found at ad71b341 #1470
- Blocked by: refactor(logs): one run-log module — parseLogFile, listLogFiles, resolveLogDir, formatDuration defined once #1471
Problem
Five small helpers are defined twice or three times in non-test src/: ensureDir (lib/fs.ts exported and correct; relay/writer.ts a sync copy taking a file path; upstream/assessment.ts an async copy that swallows every error), escapeRegex (byte-identical in heuristics/behavior-rule-detector.ts, test-tautology-detector.ts, upstream/relevance.ts), formatTimestamp (commands/watch.ts takes an ISO string, lib/cli-ui/format.ts takes a Date, same hh:mm:ss), truncateToWidth (ui/tui/truncate.ts exported; lib/assess/renderer.ts a second width algorithm), and parseIssue (commands/locks.ts and commands/worktree.ts, identical except process.exitCode 1 vs 2).
Acceptance Criteria
- AC-1: Each of
ensureDir,escapeRegex,formatTimestamp,truncateToWidthandparseIssueNumberhas exactly one definition in non-testsrc/, andparseIssuehas none. Evidence:for s in ensureDir escapeRegex formatTimestamp truncateToWidth parseIssueNumber; do rg -l "function $s\(" src -g '!*.test.ts' | wc -l; done; rg -l 'function parseIssue\(' src -g '!*.test.ts' | wc -l→ five lines of1then0(today:3 3 2 2 0then2). - AC-2:
ensureDirerrors propagate from the upstream assessment writer with themkdirdiagnostic rather than the laterwriteFileone (D-2), and the relay writer still creates the parent directory of its file path. Note the module trap:src/lib/fs.tsimportsfs/promiseswhilesrc/lib/upstream/__tests__/assessment.test.ts:57mocksnode:fs/promises; vitest treats them as different modules, so normalisefs.tstonode:fs/promisesor mock both. Evidence:npx vitest run src/lib/upstream/__tests__/assessment.test.ts src/lib/relay/__tests__/writer.test.ts -t "ensureDir"→ ≥ 2 passed, 0 failed (writer.test.tsis new; an injected EACCES rejects the assessment write; the relay path's parent exists after a write); mutation-verified: restoring the swallowingcatch {}inassessment.tsmakessrc/lib/upstream/__tests__/assessment.test.ts > ensureDir > a write error rejectsfail. - AC-3:
formatTimestampaccepts aDateor an ISO string and returns the samehh:mm:ssfor both; an unparsable string returns the input unchanged (thewatch.tsbehaviour). Evidence:npx vitest run src/lib/cli-ui/format.test.ts -t "formatTimestamp"→ ≥ 3 passed, 0 failed (new test file). - AC-4:
src/lib/cli-ui/truncate.tsexportstruncateToWidth(the TUI's hard cut: one column reserved for the ellipsis,…at width 1) andtruncateAtWord(the assess renderer's word-boundary rule, moved unchanged). The TUI imports the first and the assess renderer the second, and neither one's output changes (D-3 as amended by the owner on 2026-10-19: the renderer's output is pinned byte for byte by frozen SKILL.md examples). Evidence:rg -l 'cli-ui/truncate.js' src/ui/tui src/lib/assess -g '!*.test.ts' | wc -l→2,rg -c 'export function truncateAtWord\(' src/lib/cli-ui/truncate.ts→1,npx vitest run src/lib/assess/renderer.test.ts src/lib/assess/skill-examples.test.ts src/ui/tui/truncate.test.ts→ 0 failed, andgit diff --name-only origin/main...HEAD | grep -cE '__snapshots__|SKILL\.md'→0. - AC-5:
parseIssueNumberinsrc/lib/cli-flags.tsreturnsnumber | nullwithout touchingprocess.exitCode, andlocksstill exits 1 whileworktreestill exits 2 on a bad argument. Evidence:npx vitest run src/lib/cli-flags.test.ts -t "parseIssueNumber"→ ≥ 3 passed, 0 failed (valid, zero and non-numeric inputs;process.exitCodeuntouched), andrg -q 'process.exitCode = 1' src/commands/locks.ts && rg -q 'process.exitCode = 2' src/commands/worktree.ts && echo kept→kept. Mutation-verified: deleting the null branch ofparseIssueNumbermakessrc/lib/cli-flags.test.ts > parseIssueNumber > non-numeric input returns nullfail (thecli-flagspath trips the parser's gate keyword, so the record is required). - AC-6: The detector no longer reports the five names on this branch (must run against the real dependency). Evidence:
ACCRETION_HOME=$(mktemp -d) node ~/Projects/accretion-audit/dist/cli.js dups --repo "$PWD" --json | node -e "let s='';process.stdin.on('data',d=>s+=d).on('end',()=>{const n=new Set(JSON.parse(s).groups.map(g=>g.name));const hit=['ensureDir','escapeRegex','formatTimestamp','truncateToWidth','parseIssue'].filter(x=>n.has(x));console.log(hit.join(',')||'none');process.exit(hit.length?1:0)})"→none, exit 0.
Prior fixes / producers
- Prior fixes:
ensureDirfeat: add opencode agent driver — first backend that can inherit the full skill methodology #862, feat: opencode fidelity — hook shim (fail closed), subagent defs, MCP translation, error classes, CI smoke (#862 P1) #996, fix(sync): dry-run lists files apply never writes — the template walk maps templates/opencode/** to .claude/opencode/** (phantom drift nag in serve; update plants unrendered {{PHASE}} files) #1030, feat: add OpenAI Codex CLI agent driver #497;escapeRegexfeat(spec,qa): detect behavior-rule implementations across skill+runtime touchpoints #552, fix(qa): tautology detector still flags a subprocess-driven CLI test file — __dirname-built paths evade #885's build-output heuristic #956, fix(upstream): file a finding issue only when the change touches something sequant uses; refresh the stale dependency map #1186, fix(skills): Claude Code ≥2.1.286 tells Claude to run any project skill namedverifybefore every commit — Sequant's verify expects an issue number and posts to GitHub #1345;truncateToWidthLive multi-issue dashboard forsequant run— concurrent box rendering (read-only TUI) #540, fix(assess): dashboard silently replaced by prose, and every table example is misaligned — render via CLI subcommand instead of hand-drawn ASCII #823;parseIssuerefactor(state-utils): split 943-line file into focused modules #319, GitHub Actions integration for CI/CD-driven workflows #370, feat(state): prevent concurrent sequant sessions from targeting the same issue #625, bug(fullsolve/exec): the worktree is never created and never verified — skill-driven runs execute in the main checkout, or in another repo's worktree #899;formatTimestampInteractive relay: bidirectional communication with headless runs #383, feat(cli): unified run renderer — two-zone live grid + events #618. Each copy arrived with a feature; none was a fix to the helper itself, so there is no behaviour a caller depends on beyond what AC-2 to AC-5 pin. - Producers after this issue:
lib/fs.ts,lib/regex.ts(new),lib/cli-ui/format.ts,lib/cli-ui/truncate.ts(new),lib/cli-flags.ts.parseWholeNumberincli-flags.tsis a different contract (throws for commander) and stays.
May touch
src/lib/fs.ts, src/lib/regex.ts (new), src/lib/cli-flags.ts, src/lib/cli-ui/format.ts, src/lib/cli-ui/truncate.ts (new), src/ui/tui/truncate.ts, src/lib/relay/writer.ts, src/lib/upstream/assessment.ts, src/lib/heuristics/behavior-rule-detector.ts, src/lib/test-tautology-detector.ts, src/lib/upstream/relevance.ts, src/commands/watch.ts, src/commands/locks.ts, src/commands/worktree.ts, src/lib/assess/renderer.ts, their tests, the changelog entry. Serialize after #1471 (cli-ui/format.ts) and before #1474 (commands/locks.ts).
Folded in from #1471 (owner, 2026-10-19): src/lib/workflow/phase-executor.ts (drop the export { formatDuration } from "../cli-ui/format.js" re-export), src/commands/run-compat.ts and src/lib/workflow/phase-executor.test.ts (import formatDuration from cli-ui/format.ts).
Non-Goals
- Changing the exit codes of
locksorworktree, or any CLI message text. - The
githelper inmerge-check,skills-commit-state.tsandworktree-isolation.ts(different signatures, allowlisted noise per the Phase 0 labels). - Any edit under
plugin/,.claude/skills/ortemplates/skills/(I-1).
Activity
admarble commentedon Oct 19, 2026
Runner context, 2026-10-19, before launch (consolidation W2, beside #1472; stop-at-PR). main = ec9d583.
Changed since filing:
formatDurationintosrc/lib/cli-ui/format.ts.phase-executor.tsstill re-exports it.run-compat.tsandphase-executor.test.tsatcli-ui/format.ts.cli-ui/format.tsandcommands/locks.tsagain.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, and this wave runs 7 issues at once. Prefer the targetednpx vitest run <files>for the ACs.CHANGELOG: add
[Unreleased]lines, notchangelog.d/fragments. #1370 has not merged.Freeze: nothing under
plugin/,.claude/skills/ortemplates/skills/.Health baseline: if this PR changes a measured metric, regenerate
scripts/qa/health-baseline.jsonwithnpx tsx scripts/qa/health-report.ts --write-baselineafter the last source change. Never hand-edit it.npm run lint:healthmust print "no metric rose".admarble commentedon Oct 19, 2026
Complexity: Standard (6 ACs, 12 directories)
AC Quality Check
All six ACs are single-line with an
Evidence:clause. The commands are non-vacuous: AC-1 reads3 3 2 2 0/2on main (confirmed by grep), and the vitest targets (writer.test.ts,format.test.ts, theensureDirandparseIssueNumbercases) do not exist yet.watch.ts.new Date("garbage")does not throw, so thetry/catchnever fires and today's output isNaN:NaN:NaN. "Returns the input unchanged" is new behaviour, not the existing behaviour. Implement an explicitNumber.isNaN(date.getTime())guard and test it. The AC text should drop "(thewatch.tsbehaviour)".IssueBox.tsxas one of the two importers.src/ui/tui/IssueBox.tsxmust importcli-ui/truncate.jsdirectly.src/ui/tui/truncate.tsis then deleted (or the AC-1 count stays 1 only via a re-export; deleting is cleaner).src/ui/tui/truncate.test.tsis kept and repointed at the new module (the AC runs it by that path).fs.tstonode:fs/promiseswould breakdoctor.test.ts,stacks.test.tsandmcp/tools/run.test.ts, which mock"fs/promises". See Open Question 1.~/Projects/accretion-audit/dist/cli.js, which exists.Scope Assessment
Non-Goals: present (exit codes, CLI text,
githelper,plugin//.claude/skills//templates/skills/).Verdict: ✅ SCOPE_OK (wide but mechanical)
Acceptance Criteria
AC-1: One definition per helper
Verification: Integration Test (the shell loop in
Evidence:)Scenario: Given main (
3 3 2 2 0,2) → When the five dedupes land → Then1 1 1 1 1and0.Assumptions:
parseIssueNumberis afunctiondeclaration, not aconstarrow, because the grep matchesfunction parseIssueNumber(.AC-2:
ensureDirerrors propagate; relay still creates the parentVerification: Unit Test
Scenario: Given
mkdirrejects EACCES → When the assessment writer runs → Then it rejects with the mkdir error. Given a relay file path → When it is written → Then its parent dir exists.Assumptions: The relay writer is sync (
mkdirSync) and takes a file path.fs.ts#ensureDiris async and takes a dir. See Phase 1, step 2.AC-3:
formatTimestamp(Date | string)Verification: Unit Test (new
src/lib/cli-ui/format.test.ts)Scenario: Given a Date and its ISO string → Then identical
hh:mm:ss. Given"garbage"→ Then"garbage".AC-4: Shared
truncateToWidthVerification: Unit Test + snapshot
Scenario: Given the assess renderer → When it uses the TUI algorithm → Then renderer tests pass. The
…snapshots (3 in__snapshots__/renderer.test.ts.snap) may change, and the PR body lists any changes.Assumptions: The renderer currently prefers word boundaries (
WORD_BOUNDARY_MIN_FILL = 0.7) and the TUI version hard-cuts. D-3 says to use the TUI algorithm, so the renderer loses word-boundary truncation. That is a visible behaviour change in/assessoutput.AC-5:
parseIssueNumberincli-flags.tsVerification: Unit Test
Scenario: Given
"12","0","abc"→ Then12,null,null, withprocess.exitCodeuntouched.lockssets 1 andworktreesets 2 at the call site.Note: The caller prints
Invalid issue number: <arg>and sets the exit code. Keep the message in each caller or in a tiny shared line. Do not change the text.worktree.ts:98also calls it (the verify path), so all five call sites need the update.AC-6: Detector reports none of the five names
Verification: Integration Test (the
accretion-auditcommand inEvidence:)Scenario: Given the branch after AC-1..5 → Then it prints
noneand exits 0.Implementation Plan
Phase 1: Shared helpers (sequential; the first four steps touch disjoint files)
escapeRegex: createsrc/lib/regex.tsand export it. Import it inbehavior-rule-detector.ts,test-tautology-detector.tsandupstream/relevance.ts, and delete the three local copies. Add a small unit test, since the file is new.ensureDir: delete the swallowing copy inupstream/assessment.tsand importensureDirfrom../fs.js. Drop themkdirimport if it becomes unused. Forrelay/writer.ts, the sync file-path variant is the only non-duplicate shape. Either addensureParentDirSync(filePath)tofs.tsand call it from the writer, or have the writer callmkdirSync(dirname(path), {recursive:true})inline. The grep counts onlyfunction ensureDir(, so either satisfies AC-1. Prefer thefs.tshelper so there is one home. Addsrc/lib/relay/__tests__/writer.test.ts(new) and anensureDirdescribe inassessment.test.ts.formatTimestamp: widencli-ui/format.tstoDate | stringwith the NaN guard.watch.tsimports it and drops its copy. Newformat.test.ts.parseIssueNumber: add it tocli-flags.tsreturningnumber | null.locks.ts(3 sites) andworktree.ts(2 sites) becomeparseIssueNumber(arg), which on null prints the same error and sets their own exit code. Delete bothparseIssuecopies.truncateToWidth:git mv src/ui/tui/truncate.ts src/lib/cli-ui/truncate.ts. RepointIssueBox.tsx,truncate.test.tsandassess/renderer.ts. Delete the renderer copy. Runrenderer.test.tsand update the snapshots deliberately. If word-boundary tests assert specific output, review each diff rather than blindly running-u.Phase 2: #1471 fold-in and hygiene
export { formatDuration } ...atphase-executor.ts:61. Pointrun-compat.ts:11andphase-executor.test.ts:35atcli-ui/format.ts. Grep the whole repo for other importers offormatDurationfromphase-executor.[Unreleased]lines to CHANGELOG.md (notchangelog.d/). Runnpx tsx scripts/qa/health-report.ts --write-baselineafter the last source change if a metric moved.npm run lint:healthmust print "no metric rose". Run AC-6 last.Verification order:
tsc, the targetednpx vitest run <files>, the AC-1 loop, the AC-6 command, then one foreground full-suite run undertimeoutafter a WIP commit.Design Review
lib/(fs.ts,regex.ts,cli-flags.ts) and UI helpers inlib/cli-ui/. Wide TUI-only helpers do not belong inui/, becauselib/assesswould depend upward on it.utils.ts(hides ownership), and keeping a re-export atui/tui/truncate.ts(leaves a second path that the detector may flag).ensureDirfeat: add opencode agent driver — first backend that can inherit the full skill methodology #862 feat: opencode fidelity — hook shim (fail closed), subagent defs, MCP translation, error classes, CI smoke (#862 P1) #996 fix(sync): dry-run lists files apply never writes — the template walk maps templates/opencode/** to .claude/opencode/** (phantom drift nag in serve; update plants unrendered {{PHASE}} files) #1030 feat: add OpenAI Codex CLI agent driver #497,escapeRegexfeat(spec,qa): detect behavior-rule implementations across skill+runtime touchpoints #552 fix(qa): tautology detector still flags a subprocess-driven CLI test file — __dirname-built paths evade #885's build-output heuristic #956 fix(upstream): file a finding issue only when the change touches something sequant uses; refresh the stale dependency map #1186 fix(skills): Claude Code ≥2.1.286 tells Claude to run any project skill namedverifybefore every commit — Sequant's verify expects an issue number and posts to GitHub #1345, and so on) added copies with features, not fixes to the helper, so this fixes the class rather than the site. The recurrence is the reason for AC-6 as a standing detector check.ensureDir: consumers ininit.ts,templates.ts,stack-config.ts,settings.ts,fs.tsitself. After the change the producers arefs.tsplus the relay sync helper.escapeRegex: 3 consumers, 1 producer.formatTimestamp:run-renderer.ts,watch.ts.truncateToWidth:IssueBox.tsx,renderer.ts.parseIssueNumber: 5 call sites inlocks.tsandworktree.ts. No cross-package mirrors (plugin/, skills) are touched.Feature Quality Planning
All standard checks pass. Notable items:
mkdirin a test would create directories on disk rather than fail.Mutation-verified: AC-N — ...; <test file path> failed; restored.with the FILE path first.false &&).src/lib/cli-flags.tstrips the parser's gate keyword, so the mutation record is required for AC-5.watch.tswas the only non-Datecaller offormatTimestamp.src/commands/locks.tsis edited again by refactor(ready-gate,scope): one non-goals scanner with the gate's heading rules, fenced blocks stripped #1474 and refactor(workflow,locks): worktreeStatus tri-state replaces both isWorktreeDirty copies; one formatSignalLine #1475, so keep the diff there minimal to ease the merge.Open Questions
fs.tsmodule specifier. Normalisefs.tstonode:fs/promises(the AC's first option), or mock both specifiers inassessment.test.ts? Recommendation: mock both inassessment.test.ts, because three other suites (doctor,stacks,mcp/tools/run) mock plain"fs/promises"and normalising could break them. Impact if wrong: unrelated test failures, or the realmkdirruns in tests.watch.tsbehaviour" (the existing guard never fires). Recommendation: yes; behaviour is the same intent either way. Impact: none.fs.tsensureParentDirSync, but an inlinemkdirSyncalso satisfies AC-1.Recommended Workflow
Phases: exec → qa
Quality Loop: disabled
Reasoning: Mechanical refactor, tier
mechanical. AC-2, AC-3 and AC-5 declare unit-test evidence, which would normally suggest testgen, but each names its test cases exactly, so exec can write them directly. Stop-at-PR per the runner comment.Label Review
Current: refactor, graph-2026-10-consolidation
Recommended: refactor, graph-2026-10-consolidation (no change)
Quality Loop: Won't auto-enable; 6 ACs, SCOPE_OK.
admarble commentedon Oct 19, 2026
Owner decision, 2026-10-19: D-3 amended, and AC-4 rewritten in the body above. Exec halted with SPEC_DIVERGENCE because the original AC-4 would change the assess renderer's output, which frozen SKILL.md pins byte for byte (
skill-examples.test.ts). The runner checked this: the renderer's copy prefers a word boundary and the TUI's cuts hard.Now:
src/lib/cli-ui/truncate.tsexports two functions.truncateToWidth, the TUI's hard cut, imported bysrc/ui/tui.truncateAtWord, the renderer's word-boundary rule moved unchanged, imported bysrc/lib/assess/renderer.ts.Neither one's output changes, and there are no snapshot or SKILL.md edits. AC-1's "one definition of
truncateToWidth" and AC-6's detector check hold, because the renderer's copy now has a different name. IftruncateAtWordcan calltruncateToWidthfor the hard cut without changing any renderer output, prefer that; otherwise keep it self-contained.For the re-run: commit 4e7bffa on this branch already holds the work for the other ACs. Build on it, and merge
origin/mainfirst; it is one commit behind. All the earlier runner context still applies, including the health-baseline correction and the qa-phase test note.refactor(#1473): truncateAtWord keeps the assess renderer's word-boun…
admarble commentedon Oct 19, 2026
QA Verdict: AC_MET_BUT_NOT_A_PLUS
AC coverage: 6/6 met
Gaps:
src/commands/locks.ts:610:locksCheckBatchCommandstill has a third copy of the parse-issue logic, written inline in a loop, so AC-1'sfunctiongrep doesn't catch it. Replacing it withparseIssueNumberwould be trivial.ensureParentDirSyncis a new name next toensureDir. That is acceptable because it is a different contract (sync, takes a file path), and its doc comment says so.watchnow prints the raw timestamp string for an unparsable timestamp instead ofNaN:NaN:NaN. This is the behaviour the AC prescribes.refactor(#1473): locks check-batch uses parseIssueNumber (the third i…
chore(#1473): CHANGELOG entry; baseline records emptyCatch 118 and un…
chore(#1473): merge main; baseline records emptyCatch 117 and unusedE…