WORK-145
ID:WORK-145Status:done

Extract pure diffing functions into diff module

Extract the pure diffing and parsing functions from history.ts into a new diff.ts module with zero Node.js imports. The existing history.ts re-imports from diff.ts for its git-based history extraction.

Priority:highComplexity:simpleSource:SPEC-040

Criteria completion

Criteria completion: 10 of 10 (100%) checked; history from Apr 14 to Apr 140%25%50%75%100%Apr 14Apr 14
Branches 1
History 3
  1. e900a90
    Created (done)by bjornolofandersson
  2. 888d791
    • ☑ New file `runes/plan/src/diff.ts` exists and contains all pure diffing functions
    • ☑ `diff.ts` has zero imports from `node:fs`, `node:path`, or `node:child_process`
    • ☑ `diffAttributes(prev, curr)` is exported from `diff.ts` with `AttributeChange` type
    • ☑ `diffCriteria(prev, curr)` is exported from `diff.ts` with `CriteriaChange` type
    • ☑ `parseTagAttributes(line)` is exported from `diff.ts`
    • ☑ `parseCheckboxes(content)` is exported from `diff.ts` with `ParsedCheckbox` type
    • ☑ `hasResolutionSection(content)` is exported from `diff.ts`
    • ☑ `history.ts` imports from `diff.ts` and re-exports the types for backwards compatibility
    • ☑ All existing imports from `./history` continue to work (no breaking changes)
    • ☑ Existing history tests pass without modification
    by Claude
  3. 7340389
    Created (ready)by Claude
    Add SPEC-040 and WORK-144–148 for edge runtime plan package refactoring

Acceptance Criteria

  • New file runes/plan/src/diff.ts exists and contains all pure diffing functions
  • diff.ts has zero imports from node:fs, node:path, or node:child_process
  • diffAttributes(prev, curr) is exported from diff.ts with AttributeChange type
  • diffCriteria(prev, curr) is exported from diff.ts with CriteriaChange type
  • parseTagAttributes(line) is exported from diff.ts
  • parseCheckboxes(content) is exported from diff.ts with ParsedCheckbox type
  • hasResolutionSection(content) is exported from diff.ts
  • history.ts imports from diff.ts and re-exports the types for backwards compatibility
  • All existing imports from ./history continue to work (no breaking changes)
  • Existing history tests pass without modification

Approach

  1. Create diff.ts and move the five pure functions plus their types (AttributeChange, CriteriaChange, ParsedCheckbox) and supporting regex constants (TAG_ATTR_RE, CHECKBOX_RE, RESOLUTION_RE).
  2. In history.ts, replace the moved code with imports: import { diffAttributes, diffCriteria, parseTagAttributes, parseCheckboxes, hasResolutionSection, type AttributeChange, type CriteriaChange, type ParsedCheckbox } from './diff.js' and re-export them.
  3. Git transport functions (getFileCommits, getFileAtCommit, extractEntityHistory, getBatchCommits, extractBatchHistory, isShallowClone) and cache functions stay in history.ts.
  4. Run existing tests to confirm no regressions.

Dependencies

None — independent of the scanner-core extraction.

References

  • SPEC-040 — Edge Runtime Compatibility for Plan Package
  • SPEC-038 — Git-Native Entity History

Resolution

Completed: 2026-04-14

Branch: claude/edge-runtime-refactor-HOg8v

What was done

  • Created runes/plan/src/diff.ts with all pure diffing functions (diffAttributes, diffCriteria, parseTagAttributes, parseCheckboxes, hasResolutionSection) and their types (AttributeChange, CriteriaChange, ParsedCheckbox)
  • Updated runes/plan/src/history.ts to import from diff.ts and re-export all functions and types for backwards compatibility

Notes

  • diff.ts has zero dependencies on Node.js APIs — only pure TypeScript
  • All 31 history tests pass without modification