Repository navigation
Description
Epic: graph-2026-10-consolidation Tier: mechanical Execution: sequant_run
Problem
Five run-log helpers are defined two or three times each in non-test src/: parseLogFile (byte-identical in commands/logs.ts, commands/stats.ts, mcp/tools/logs.ts), listLogFiles (identical in logs.ts, stats.ts), formatDuration (identical in logs.ts, stats.ts, lib/workflow/phase-executor.ts), and the log-directory resolver under two names, resolveLogPath (logs.ts, stats.ts, mcp/tools/logs.ts) and resolveLogDir (lib/merge-check/index.ts, mcp/tools/run.ts), all with the same contract: expand ~ in a custom path, else the project log dir if it exists, else the global one. The MCP copies take no custom path. accretion dups on HEAD (ad71b341) reports all five names (accretion-audit, dogfood/baseline-sequant.md).
Acceptance Criteria
- AC-1: Each of
parseLogFile,listLogFiles,resolveLogDirandformatDurationhas exactly one definition in non-testsrc/, andresolveLogPathhas none. Evidence:for s in parseLogFile listLogFiles resolveLogDir formatDuration; do rg -l "function $s\(" src -g '!*.test.ts' | wc -l; done; rg -l 'function resolveLogPath\(' src -g '!*.test.ts' | wc -l→1 1 1 1then0. - AC-2: The shared module keeps every copy's behaviour: tilde expansion of a custom path, project-over-global precedence when
.sequant/logsexists, global fallback when it does not,nullfromparseLogFileon unreadable or invalid JSON, andformatDuration(65)→1m 5s. Evidence:npx vitest run src/lib/run-logs.test.ts→ ≥ 5 passed, 0 failed. - AC-3: Every former caller compiles against the shared module and the existing command tests still pass. Evidence:
npm run build && npx vitest run src/commands/stats.test.ts src/commands/stats-source.test.ts src/commands/stats-failure-categories.test.ts src/mcp/tools/run.test.ts src/lib/merge-check/watch.test.ts src/lib/workflow/phase-executor.test.ts→ 0 failed. - AC-4: The detector no longer reports the five names on this branch (must run against the real dependency, the accretion CLI on this machine). 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=['parseLogFile','listLogFiles','resolveLogDir','resolveLogPath','formatDuration'].filter(x=>n.has(x));console.log(hit.join(',')||'none');process.exit(hit.length?1:0)})"→ printsnone, exit 0.
Prior fixes / producers
- Prior fixes touching these symbols: Skill output reliability: validation layers, schemas, and structured logging #22, Logging enhancements: rotation, stats, and documentation #28, Add local-first analytics for workflow insights #132, Expose Sequant workflow as MCP server #372, Data-driven workflow optimization: systematic analysis of run logs and conversation data #437, feat(stats): add --label and --since filters for cohort measurement #640 (parse/list/resolve), feat(run): Add batch-level integration QA —
sequant merge --check#313, MCP server: improve sequant_run output structure #391, fix(mcp): log-file lookup races on concurrent runs and stale same-issue logs #631, feat(merge): --watch — wait for CI checks to finish, then run merge-check and report (kills the merge-after-green polling loop) #818 (resolveLogDir), refactor(run): split 3,459-line monolith into focused modules #318, arch: extract RunOrchestrator — decouple execution engine from CLI wiring #503, feat(cli): unified run renderer — two-zone live grid + events #618 (formatDuration). Every copy was added by a feature that re-implemented rather than imported; no earlier consolidation attempt. - Producers of the log directory decision: five (the copies above). Consumers:
sequant logs,sequant stats,sequant_logsandsequant_runMCP tools,merge --check. After this issue: one producer,src/lib/run-logs.ts.
May touch
src/lib/run-logs.ts (new) and its test, src/lib/cli-ui/format.ts (add formatDuration), src/commands/logs.ts, src/commands/stats.ts, src/mcp/tools/logs.ts, src/mcp/tools/run.ts, src/lib/merge-check/index.ts, src/lib/workflow/phase-executor.ts, their tests, the changelog entry. Serialize with #1472 (mcp/tools/run.ts) and #1473 (cli-ui/format.ts): this node first (graph D-6).
Non-Goals
- Changing any output format, log path or precedence (I-3: move and delete only).
formatElapsedTimeincli-ui/format.ts(different contract, §3).- Any edit under
plugin/,.claude/skills/ortemplates/skills/(I-1).
Activity
docs(#1470): graph-2026-10-consolidation founding doc, issue graph an…
admarble commentedon Oct 19, 2026
Runner context, 2026-10-19, before launch (W1 of graph-2026-10-consolidation, with #1474; stop-at-PR).
Changed since filing (10-16): two of this issue's files have moved.
src/mcp/tools/run.ts: fix(mcp): sequant_run reports another run's issues and verdict when its own run log is missing — a runId lookup miss falls back to the time window #1515 (2e887b3) changed how a run's log is located. When the runId lookup misses, it now falls back to the time window.src/mcp/tools/run.test.tscovers this.src/lib/merge-check/index.ts: fix(merge): sequant merge --check hard-codes origin/main in four places, so a master-default repo gets empty diffs and a clean report #1484 (74703cb) stopped hard-codingorigin/main.The consolidated helpers must keep both behaviours. Where
resolveLogDirand the others end up is this issue's design choice. If the tworesolveLogDircopies don't actually agree, stop and surface it rather than picking one.AC-1 smoke on 8d1895c: parseLogFile 3, listLogFiles 2, resolveLogDir 2, formatDuration 3, resolveLogPath 3 (fails today, as filed).
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, notchangelog.d/fragments. #1370 has not merged.Freeze: nothing under
plugin/,.claude/skills/ortemplates/skills/.admarble commentedon Oct 19, 2026
Complexity: Standard (4 ACs, 7 directories)
AC Quality Check
All four ACs carry command-shaped
Evidence:. Checked against base (8d1895c):resolveLogPath3) — not vacuous.src/lib/run-logs.test.tsdoes not exist).parseLogFileunreadable → null, invalid JSON → null,formatDuration(65).Scope Assessment
Non-Goals: present (no format/path/precedence changes;
formatElapsedTimeuntouched; nothing underplugin/,.claude/skills/,templates/skills/).Verdict: ✅ SCOPE_OK
Acceptance Criteria
AC-1: One definition each;
resolveLogPathgoneVerification: Integration Test (the issue's rg loop)
Scenario: Given the refactor → When the rg loop runs → Then
1 1 1 1then0Assumptions: a
export { formatDuration } fromre-export is not matched byfunction formatDuration\(.AC-2: Shared module preserves behaviour
Verification: Unit Test (
src/lib/run-logs.test.ts, real tmpdir, no fs mock)Scenario: Given custom
~/x→ tilde expanded;.sequant/logsexists → project wins; absent → global; bad JSON/unreadable →null;formatDuration(65)→1m 5s.AC-3: Callers compile, existing tests pass
Verification: Integration Test (
npm run build+ the listed vitest files)AC-4: Detector reports none of the five names
Verification: Manual/CLI run against the real accretion CLI at
~/Projects/accretion-audit/dist/cli.js.Implementation Plan
Phase 1: Shared module
src/lib/run-logs.tsexportingresolveLogDir(customPath?),listLogFiles(logDir),parseLogFile(filePath). Bodies are copied verbatim fromsrc/commands/logs.ts:38-85(the superset signature; the MCP copies are the same minuscustomPath).formatDurationtosrc/lib/cli-ui/format.ts(bodies incommands/logs.ts:90,commands/stats.ts:250,phase-executor.ts:818are identical). KeepformatElapsedTimeuntouched.src/lib/run-logs.test.ts(≥ 5 cases from AC-2). Name it so it matches the vitest project that gives it a >5s timeout only if it needs it; it is fs-light, so the default is fine.Phase 2: Migrate callers (delete local copies, import shared)
commands/logs.ts,commands/stats.ts: delete the 4 local helpers each, renameresolveLogPath(call sites toresolveLogDir((stats.ts 1192/1238/1269/1307, logs.ts 341).mcp/tools/logs.ts: deleteresolveLogPath/parseLogFile, import shared (callresolveLogDir()); drop now-unusedLOG_PATHS/RunLogSchema/osimports.mcp/tools/run.ts:149: delete localresolveLogDir, import shared. Keep fix(mcp): sequant_run reports another run's issues and verdict when its own run log is missing — a runId lookup miss falls back to the time window #1515's runId-miss → time-window fallback untouched (only the resolver moves).lib/merge-check/index.ts:44: it is an exported function (commands/merge.ts:23imports it). Delete the body and re-export fromrun-logs.ts(export { resolveLogDir } from "../run-logs.js") or repointmerge.ts; prefer repointing so the module has no pass-through. Keep fix(merge): sequant merge --check hard-codes origin/main in four places, so a master-default repo gets empty diffs and a clean report #1484's base-ref behaviour (it is elsewhere in this file; do not touch).lib/workflow/phase-executor.ts:818: delete the function andexport { formatDuration } from "../cli-ui/format.js"—phase-executor.test.ts:35andcommands/run-compat.ts:11import it from here. Re-export keeps both compiling; a follow-up can repoint them.[Unreleased]line (nochangelog.d/fragment, per runner note).Design Review
src/lib/run-logs.ts, next tolib/workflow/run-log-schema.tswhich ownsLOG_PATHS/RunLogSchema;formatDurationjoins the formatters incli-ui/format.ts.run-log-schema.ts(mixes IO into a schema module) and a pass-through re-export in merge-check.resolveLogDirand notresolveLogPath?" — the name that two of the call sites outside the CLI already use and that describes a directory; AC-1 mandates it.commands/logs.ts,commands/stats.ts,mcp/tools/logs.ts,mcp/tools/run.ts(174, 197),merge-check/index.ts:281,commands/merge.ts(79, 124),commands/run-compat.ts:11,phase-executor.test.ts. Tests that mockfs.existsSync(mcp/tools/run.test.ts:39) still work because the shared module uses the samefsimport path semantics — verify with that file after step 6 (mock is on"fs"; useimport * as fs from "fs"/ namedexistsSyncfrom"fs", notnode:fs, or the mock misses).Q3/Q5 do not contradict the prescribed lever: no divergence.
Feature Quality Planning
All standard checks pass. Notable items:
resolveLogDircopies agree:merge-check/index.ts:44andmcp/tools/run.ts:149differ only incustomPathsupport and inos/homedirimport; precedence (project → global-if-exists → project) is identical to the CLI copies. The runner's "stop if they disagree" condition does not trigger..replace("~", …)(first occurrence, any position). Preserve it exactly — non-goal to fix.fsmock-hazard above is the main regression risk for AC-3.Open Questions
run-compat.ts/phase-executor.test.tsaway from the phase-executor re-export? — Recommendation: no, keep re-export (smaller diff). Impact: one re-export line stays.Recommended Workflow
Phases: exec → qa
Quality Loop: disabled
Reasoning: Mechanical move/delete with one new unit test file; AC-2 declares unit-test evidence, but the stubs are fully specified above, so testgen adds nothing.
Label Review
Current: refactor, graph-2026-10-consolidation
Recommended: + planned
Quality Loop: Won't auto-enable (SCOPE_OK).
admarble commentedon Oct 19, 2026
QA Verdict: NEEDS_VERIFICATION
AC coverage: 4/4 met
Suggestions:
src/lib/workflow/phase-executor.ts:60-61: theexport { formatDuration } …line sits in the middle of the import block, after a blank line. It would read better after the last import.scripts/analytics/analyze-runs.ts:496still has its ownformatDuration. It is outsidesrc/, so AC-1 doesn't cover it, and the detector doesn't report it. I'm noting it, not counting it as a gap.Needs human review:
admarble commentedon Oct 19, 2026
Execution Verification (runner, 2026-10-19), PR #1547 @ d07385d
QA returned NEEDS_VERIFICATION, with one gap: the required
testcheck was still pending. The runner re-ran every Evidence command verbatim in the worktree:1 1 1 1then0src/lib/run-logs.test.ts: 7 passed, 0 failednpm run buildexit 0; the six listed test files: 381 passed, 0 faileddups(real CLI) printsnone, exit 0CI:
testpassed on d07385d, as did every other check.Diff review: every removed copy of
resolveLogDir/resolveLogPath,listLogFiles,parseLogFileandformatDurationwas identical to the shared one. Inrun.ts, only the resolver moved. The #1515 runId-miss fallback and #1484's base-ref handling are unchanged.Follow-up from the spec: point
phase-executor.test.tsandcommands/run-compat.tsatcli-ui/format.tsand drop theformatDurationre-export inphase-executor.ts. This is left open for the owner, becauserun-compat.tsis outside this issue's file scope and the re-export breaks no AC. It is a natural fit for #1473, which also editscli-ui/format.ts.admarble commentedon Oct 19, 2026
Follow-up ledger: the
formatDurationre-export cleanup is folded into #1473 (owner, 2026-10-19); see its May-touch section.chore(#1471): blank line before ### Added after merging main