refactor(storage): consolidate external session source parsing
- Dominant language
- TypeScript
- Stars
- 5.4k
- Forks
- 502
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 715
Description
## Problem
Maka has two user-facing paths over the same Codex and Claude session stores:
- `ForeignSession` creates a filtered, untrusted handoff for the current task.
- `ExternalSession` imports a full typed transcript as a new Maka Session.
Their outputs should remain different, but each path currently implements its own discovery, source identity, title and cwd selection, bounded reading, and source-specific parsing. The implementations have already drifted: Codex paths use different presentation records, while Claude handoff does not share the lineage resolution used by full import.
## Desired outcome
Use one package-private source catalog and native parser per external source, followed by two explicit projections: safe handoff and full Session import.
The consolidation should:
- select the same source ID, transcript candidate, title, and cwd under the same query policy;
- use one Codex record authority and one Claude lineage resolver before projection;
- preserve the handoff security boundary, redaction, and hostile-data envelope;
- preserve typed full history, `externalOrigin`, atomic persistence, and replay;
- cover Codex v0.144 and v0.149, Claude rewind and compaction, duplicate IDs, malformed records, and tool call/result pairing with shared fixtures; and
- strictly reduce production code and duplicated tests without adding another facade, compatibility bridge, or generic `ExternalMessage` model.
Coordinate with #1512 and #3520. Preserve #1512's staleness and hostile-path requirements, and reuse #3520's v0.149 fixture and record-selection fix.
## Alternatives or workarounds
Keeping the parsers independent preserves the current duplication and allows source interpretation to drift further. Deriving safe handoff from imported `StoredMessage[]` would also weaken the explicit trust boundary, so the two projections should remain separate after shared source resolution.
AI-assisted analysis: Codex agents traced both consumers, their security boundaries, related pull requests, and checked-in fixtures. A human contributor must review the final design and implementation.
Contributor guide
Assessment
This issue has not been assessed yet.