feat(trace): parse Pi coding sessions

Merged
WA
2mo ago
+1408-5

Summary

Implements the provider/parser slice of spec issue-3520:

  • copies the hook-reported Pi JSONL through a temporary file and atomically publishes successful refreshes to Trace state;
  • keeps the last usable private copy when refresh fails so pre-push can still send the best session version available;
  • validates Pi JSONL v3, follows the last persisted session-tree branch, and rejects duplicate IDs, cycles, selected orphans, invalid headers, and malformed interior lines;
  • retains valid native and unknown selected entries while excluding Chainloop tree markers;
  • maps deterministic model, token, cost, tool, conversation, timing, warning, and raw-session evidence; and
  • ignores invalid usage values without making the resulting evidence uncraftable.

This PR implements R-006, R-007, and the provider-copy portion of R-005. After maintainer review, it intentionally departs from R-005's stale-copy invalidation rule: a failed refresh now retains and uses the best previously copied session version. It intentionally does not register Pi or add extension/hooks/CLI flags; those remain a separate implementation slice.

Compatibility and safety

  • Refresh errors no longer suppress an existing usable Pi copy; sessions without any usable copy still fail with sanitized, non-blocking warnings.
  • Pi requires the transcript path reported by its future extension and does not guess from the working directory.
  • The parser still reads Trace's private copy rather than the live Pi transcript.
  • Copy and parse errors omit local transcript paths.
  • No control-plane API, protobuf, evidence-schema, provider registry, or CLI changes are included.

Verification

  • go test -race -shuffle=on -count=1 ./app/cli/internal/trace/pi ./app/cli/pkg/action
  • make -C app/cli build
  • go vet ./... from app/cli
  • manual provider driver: successful refresh, failed-refresh cached fallback, and sanitized no-cache failure
  • git diff --check
  • local make -C app/cli lint was attempted, but golangci-lint 2.11.1's available toolchains cannot parse this repository's Go 1.27 export data; the post-push lint (cli) check is authoritative

Refs #3520

AI assistance

Vibhav's Pi assisted with implementation and review. The maintainer-fix commit carries an Assisted-by: Vibhav's Pi trailer.