Repository navigation
[luv-296] fix: populate Transcript field across all harnesses #294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| // @vitest-environment node | ||
| import { describe, it, expect, vi, beforeEach } from "vitest"; | ||
|
|
||
| vi.mock("../../lib/codex-sessions", () => ({ | ||
| findCodexTranscript: vi.fn(), | ||
| })); | ||
| vi.mock("../../lib/copilot-sessions", () => ({ | ||
| findCopilotTranscript: vi.fn(), | ||
| })); | ||
| vi.mock("../../lib/cursor-sessions", () => ({ | ||
| findCursorTranscript: vi.fn(), | ||
| })); | ||
| vi.mock("../../lib/pi-sessions", () => ({ | ||
| findPiTranscript: vi.fn(), | ||
| })); | ||
| vi.mock("../../lib/gemini-sessions", () => ({ | ||
| findGeminiTranscript: vi.fn(), | ||
| })); | ||
|
|
||
| import { resolveTranscriptPath } from "../../src/hooks/resolve-transcript-path"; | ||
| import { findCodexTranscript } from "../../lib/codex-sessions"; | ||
| import { findCopilotTranscript } from "../../lib/copilot-sessions"; | ||
| import { findCursorTranscript } from "../../lib/cursor-sessions"; | ||
| import { findPiTranscript } from "../../lib/pi-sessions"; | ||
| import { findGeminiTranscript } from "../../lib/gemini-sessions"; | ||
| import type { IntegrationType } from "../../src/hooks/types"; | ||
|
|
||
| describe("resolveTranscriptPath", () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| }); | ||
|
|
||
| describe("stdin passthrough (every CLI)", () => { | ||
| const cases: IntegrationType[] = [ | ||
| "claude", | ||
| "codex", | ||
| "copilot", | ||
| "cursor", | ||
| "pi", | ||
| "gemini", | ||
| "opencode", | ||
| ]; | ||
| it.each(cases)( | ||
| "returns parsed.transcript_path verbatim when set (%s)", | ||
| (cli) => { | ||
| const out = resolveTranscriptPath( | ||
| cli, | ||
| { transcript_path: "/explicit/path.jsonl" }, | ||
| "sess-1", | ||
| ); | ||
| expect(out).toBe("/explicit/path.jsonl"); | ||
| }, | ||
| ); | ||
| }); | ||
|
|
||
| describe("missing sessionId", () => { | ||
| const cases: IntegrationType[] = [ | ||
| "claude", | ||
| "codex", | ||
| "copilot", | ||
| "cursor", | ||
| "pi", | ||
| "gemini", | ||
| "opencode", | ||
| ]; | ||
| it.each(cases)("returns undefined when no stdin path AND no sessionId (%s)", (cli) => { | ||
| const out = resolveTranscriptPath(cli, {}, undefined); | ||
| expect(out).toBeUndefined(); | ||
| }); | ||
| }); | ||
|
|
||
| describe("per-CLI fallback discovery (no stdin transcript_path)", () => { | ||
| it("claude → undefined (Claude already provides it on stdin; no disk fallback)", () => { | ||
| const out = resolveTranscriptPath("claude", {}, "sess-claude"); | ||
| expect(out).toBeUndefined(); | ||
| }); | ||
|
|
||
| it("codex → findCodexTranscript(sessionId)", () => { | ||
| vi.mocked(findCodexTranscript).mockReturnValue("/home/u/.codex/sessions/2026/05/05/x.jsonl"); | ||
| const out = resolveTranscriptPath("codex", {}, "sess-codex"); | ||
| expect(findCodexTranscript).toHaveBeenCalledWith("sess-codex"); | ||
| expect(out).toBe("/home/u/.codex/sessions/2026/05/05/x.jsonl"); | ||
| }); | ||
|
|
||
| it("codex → undefined when helper returns null", () => { | ||
| vi.mocked(findCodexTranscript).mockReturnValue(null); | ||
| const out = resolveTranscriptPath("codex", {}, "sess-codex"); | ||
| expect(out).toBeUndefined(); | ||
| }); | ||
|
|
||
| it("copilot → findCopilotTranscript(sessionId)", () => { | ||
| vi.mocked(findCopilotTranscript).mockReturnValue("/home/u/.copilot/session-state/sess-copilot/events.jsonl"); | ||
| const out = resolveTranscriptPath("copilot", {}, "sess-copilot"); | ||
| expect(findCopilotTranscript).toHaveBeenCalledWith("sess-copilot"); | ||
| expect(out).toBe("/home/u/.copilot/session-state/sess-copilot/events.jsonl"); | ||
| }); | ||
|
|
||
| it("cursor → findCursorTranscript(sessionId)", () => { | ||
| vi.mocked(findCursorTranscript).mockReturnValue("/home/u/.cursor/projects/x/agent-transcripts/sess-cursor/sess-cursor.jsonl"); | ||
| const out = resolveTranscriptPath("cursor", {}, "sess-cursor"); | ||
| expect(findCursorTranscript).toHaveBeenCalledWith("sess-cursor"); | ||
| expect(out).toBe("/home/u/.cursor/projects/x/agent-transcripts/sess-cursor/sess-cursor.jsonl"); | ||
| }); | ||
|
|
||
| it("pi → findPiTranscript(sessionId)", () => { | ||
| vi.mocked(findPiTranscript).mockReturnValue("/home/u/.pi/agent/sessions/encoded/2026-05-05_sess-pi.jsonl"); | ||
| const out = resolveTranscriptPath("pi", {}, "sess-pi"); | ||
| expect(findPiTranscript).toHaveBeenCalledWith("sess-pi"); | ||
| expect(out).toBe("/home/u/.pi/agent/sessions/encoded/2026-05-05_sess-pi.jsonl"); | ||
| }); | ||
|
|
||
| it("gemini → findGeminiTranscript(sessionId)", () => { | ||
| vi.mocked(findGeminiTranscript).mockReturnValue("/home/u/.gemini/tmp/projhash/chats/sess-gemini.json"); | ||
| const out = resolveTranscriptPath("gemini", {}, "sess-gemini"); | ||
| expect(findGeminiTranscript).toHaveBeenCalledWith("sess-gemini"); | ||
| expect(out).toBe("/home/u/.gemini/tmp/projhash/chats/sess-gemini.json"); | ||
| }); | ||
|
|
||
| it("opencode → synthetic opencode-db://<sessionId> marker (transcripts live in SQLite)", () => { | ||
| const out = resolveTranscriptPath("opencode", {}, "ses_test_opencode001"); | ||
| expect(out).toBe("opencode-db://ses_test_opencode001"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("stdin precedence beats fallback", () => { | ||
| it("trusts stdin even when discovery would have returned a different path", () => { | ||
| vi.mocked(findCopilotTranscript).mockReturnValue("/from/disk.jsonl"); | ||
| const out = resolveTranscriptPath( | ||
| "copilot", | ||
| { transcript_path: "/from/stdin.jsonl" }, | ||
| "sess-x", | ||
| ); | ||
| expect(out).toBe("/from/stdin.jsonl"); | ||
| expect(findCopilotTranscript).not.toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| /** | ||
| * Per-CLI transcript-path resolver. | ||
| * | ||
| * • Claude Code: `transcript_path` arrives on the hook stdin payload — | ||
| * passthrough. | ||
| * | ||
| * • Codex: stdin doesn't carry transcript_path. Discover via | ||
| * ~/.codex/sessions/<YYYY>/<MM>/<DD>/<file containing sessionId>.jsonl. | ||
| * | ||
| * • Copilot: stdin doesn't carry transcript_path. Discover at | ||
| * ~/.copilot/session-state/<sessionId>/events.jsonl. | ||
| * | ||
| * • Cursor: stdin doesn't carry transcript_path. Discover under | ||
| * ~/.cursor/projects/<encoded-cwd>/agent-transcripts/<sessionId>/<sessionId>.jsonl | ||
| * (with legacy fallbacks). | ||
| * | ||
| * • OpenCode: transcripts live in SQLite at | ||
| * ~/.local/share/opencode/opencode.db, not on disk. Synthesize an | ||
| * `opencode-db://<sessionId>` marker so the dashboard renders something | ||
| * meaningful and the value is distinguishable from a genuine miss. | ||
| * | ||
| * • Pi: shim doesn't forward transcript_path. Discover at | ||
| * ~/.pi/agent/sessions/<encodedCwd>/<isoTimestamp>_<sessionId>.jsonl. | ||
| * | ||
| * • Gemini: docs say stdin carries transcript_path, but coverage is uneven | ||
| * across versions. Trust stdin first; fall back to discovery under | ||
| * ~/.gemini/tmp/<projectHash>/chats/<sessionId>.json. | ||
| * | ||
| * Mirrors the dispatch pattern of `resolve-permission-mode.ts`. Each | ||
| * `find*Transcript` helper performs its own existsSync + path-traversal | ||
| * containment check, so passing in a malformed sessionId is safe (returns | ||
| * null → undefined). | ||
| */ | ||
| import { findCodexTranscript } from "../../lib/codex-sessions"; | ||
| import { findCopilotTranscript } from "../../lib/copilot-sessions"; | ||
| import { findCursorTranscript } from "../../lib/cursor-sessions"; | ||
| import { findPiTranscript } from "../../lib/pi-sessions"; | ||
| import { findGeminiTranscript } from "../../lib/gemini-sessions"; | ||
| import type { IntegrationType } from "./types"; | ||
|
|
||
| export function resolveTranscriptPath( | ||
| integration: IntegrationType, | ||
| parsed: Record<string, unknown>, | ||
| sessionId: string | undefined, | ||
| ): string | undefined { | ||
| const stdinPath = parsed.transcript_path as string | undefined; | ||
| if (stdinPath) return stdinPath; | ||
| if (!sessionId) return undefined; | ||
|
|
||
| switch (integration) { | ||
| case "claude": | ||
| return undefined; | ||
| case "codex": | ||
| return findCodexTranscript(sessionId) ?? undefined; | ||
| case "copilot": | ||
| return findCopilotTranscript(sessionId) ?? undefined; | ||
| case "cursor": | ||
| return findCursorTranscript(sessionId) ?? undefined; | ||
| case "pi": | ||
| return findPiTranscript(sessionId) ?? undefined; | ||
| case "gemini": | ||
| return findGeminiTranscript(sessionId) ?? undefined; | ||
| case "opencode": | ||
| return `opencode-db://${sessionId}`; | ||
| default: | ||
| return undefined; | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.