Skip to content

[Rust port] relayburn-analyze: subagent-tree + claude-md attribution #272

@willwashburn

Description

@willwashburn

Parent: #244
Depends on: #242, #266 (foundation), #268 (findings)

Context

Two attribution modules that walk session structure and produce per-node cost rollups. They land together because both produce tree-shaped output and share the "build a hierarchy then attribute cost to each node" pattern.

Scope

subagent_tree.rs (port of subagent-tree.ts, ~640 LoC)

  • Port SubagentTreeNode, BuildSubagentTreeOptions, SubagentTypeStats types.
  • Port buildSubagentTree(turns, options) — walks parent-uuid chains to construct the tree of dispatched subagents per session.
  • Port aggregateSubagentTypeStats(turns) — flat aggregation over subagent type names.
  • Sidechain reconciliation rules (sidechain → parent linkage) are upstream in relayburn-reader; this module just consumes the subagentType / parentUuid fields.

claude_md.rs (port of claude-md.ts, ~402 LoC)

  • Port MarkdownSection, ParsedClaudeMd, SessionClaudeMdCost, SectionCost, ClaudeMdAttributionResult, AttributeClaudeMdInput, TrimRecommendation types.
  • Port findClaudeMdFiles(projectPath) — filesystem walk for CLAUDE.md in cwd + parents + .claude/CLAUDE.md.
  • Port loadClaudeMdFile(path), parseClaudeMd(path, text) — markdown section parser; lines starting with # open new sections, body accumulates until next header, indentation level encodes section nesting.
  • Port attributeClaudeMd(input) — attributes per-session token cost to specific markdown sections weighted by token share.
  • Port buildTrimRecommendations(result) and renderUnifiedDiffForRecommendation(rec, parsed) — produces a unified-diff string for a section to be removed; keep the diff format (---/+++/@@ headers, - line prefixes) byte-identical to TS, since CLI consumers may grep on it.

Conformance gate

  • packages/analyze/src/subagent-tree.test.ts (326 lines)
  • packages/analyze/src/claude-md.test.ts (360 lines)

Acceptance

  • cargo test -p relayburn-analyze green for both modules.
  • Public surface for subagent: buildSubagentTree, aggregateSubagentTypeStats, BuildSubagentTreeOptions, SubagentTreeNode, SubagentTypeStats.
  • Public surface for claude-md: findClaudeMdFiles, loadClaudeMdFile, parseClaudeMd, attributeClaudeMd, buildTrimRecommendations, renderUnifiedDiffForRecommendation, plus all listed types.
  • Tree node ordering deterministic (sort by ts asc, then uuid asc within siblings) and matches TS.
  • Unified-diff output matches TS byte-for-byte on the trim-recommendation fixture corpus.

Files

  • packages/analyze/src/subagent-tree.ts + subagent-tree.test.ts
  • packages/analyze/src/claude-md.ts + claude-md.test.ts

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions