Repository navigation
feat(native-chat): read ZCode session transcripts through the OpenCode SQLite reader #27131
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,18 +20,24 @@ import { openCodeTranscriptPageLimit } from '../../shared/opencode-transcript-pa | |
| // OpenCode SQLite reads use the same bounded worker as AI Vault. | ||
|
|
||
| export type OpenCodeTranscriptDeps = { | ||
| resolveDbPath?: (sessionId?: string, signal?: AbortSignal) => Promise<string | null> | ||
| resolveDbPath?: ( | ||
| sessionId?: string, | ||
| signal?: AbortSignal, | ||
| agent?: 'zcode' | ||
| ) => Promise<string | null> | ||
| readSignal?: ( | ||
| dbPath: string, | ||
| sessionId: string, | ||
| signal?: AbortSignal | ||
| signal?: AbortSignal, | ||
| agent?: 'zcode' | ||
| ) => Promise<OpenCodeTranscriptSignal | null> | ||
| readPage?: ( | ||
| args: { | ||
| dbPath: string | ||
| sessionId: string | ||
| limit: number | ||
| beforeMessageRowId?: number | ||
| agent?: 'zcode' | ||
| }, | ||
| signal?: AbortSignal | ||
| ) => Promise<OpenCodeTranscriptPage | null> | ||
|
|
@@ -43,25 +49,60 @@ export function resolveOpenCodeTranscriptDbPath(sessionId?: string): Promise<str | |
|
|
||
| export const openCodeTranscriptDefaultDeps: Required<OpenCodeTranscriptDeps> = { | ||
| resolveDbPath: discoverOpenCodeTranscriptDatabase, | ||
| readSignal: (dbPath, sessionId, signal) => | ||
| readOpenCodeTranscriptSignalViaWorker({ dbPath, sessionId }, signal), | ||
| readSignal: (dbPath, sessionId, signal, agent) => | ||
| readOpenCodeTranscriptSignalViaWorker({ dbPath, sessionId, agent }, signal), | ||
| readPage: (args, signal) => readOpenCodeTranscriptPageViaWorker(args, signal) | ||
| } | ||
|
|
||
| /** | ||
| * Resolve a subscribe's read legs against its own abort signal, with the agent | ||
| * tag (when any) already applied to every leg. Kept here so the poll loop stays | ||
| * free of default-vs-override plumbing. | ||
| */ | ||
| export function bindOpenCodeTranscriptDeps( | ||
| deps: OpenCodeTranscriptDeps, | ||
| signal: AbortSignal, | ||
| agent?: 'zcode' | ||
| ): { | ||
| resolveDbPath: () => Promise<string | null> | ||
| readSignal: (dbPath: string, sessionId: string) => Promise<OpenCodeTranscriptSignal | null> | ||
| readPage: ( | ||
| page: Parameters<NonNullable<OpenCodeTranscriptDeps['readPage']>>[0] | ||
| ) => Promise<OpenCodeTranscriptPage | null> | ||
| } { | ||
| return { | ||
| resolveDbPath: () => | ||
| (deps.resolveDbPath ?? openCodeTranscriptDefaultDeps.resolveDbPath)(undefined, signal, agent), | ||
| readSignal: (dbPath, sessionId) => | ||
| (deps.readSignal ?? openCodeTranscriptDefaultDeps.readSignal)( | ||
| dbPath, | ||
| sessionId, | ||
| signal, | ||
| agent | ||
| ), | ||
| readPage: (page) => | ||
| (deps.readPage ?? openCodeTranscriptDefaultDeps.readPage)( | ||
| { ...page, ...(agent ? { agent } : {}) }, | ||
| signal | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| export type OpenCodeTailResult = | ||
| | { messages: NativeChatMessage[]; hasMore: boolean; beforeOffset: number } | ||
| | { error: string; notFound?: true } | ||
|
|
||
| export async function readOpenCodeNativeChatTranscriptTail( | ||
| args: { sessionId: string; limit: number; beforeOffset?: number }, | ||
| args: { sessionId: string; limit: number; beforeOffset?: number; agent?: 'zcode' }, | ||
| deps: OpenCodeTranscriptDeps = {}, | ||
| signal?: AbortSignal | ||
| ): Promise<OpenCodeTailResult> { | ||
| const limit = openCodeTranscriptPageLimit(args.limit > 0 ? args.limit : DESKTOP_READ_WINDOW) | ||
| try { | ||
| const dbPath = await (deps.resolveDbPath ?? openCodeTranscriptDefaultDeps.resolveDbPath)( | ||
| args.sessionId, | ||
| signal | ||
| signal, | ||
| args.agent | ||
| ) | ||
| if (!dbPath) { | ||
| return { error: 'Transcript unavailable', notFound: true } | ||
|
|
@@ -71,7 +112,8 @@ export async function readOpenCodeNativeChatTranscriptTail( | |
| dbPath, | ||
| sessionId: args.sessionId, | ||
| limit, | ||
| ...(args.beforeOffset !== undefined ? { beforeMessageRowId: args.beforeOffset } : {}) | ||
| ...(args.beforeOffset !== undefined ? { beforeMessageRowId: args.beforeOffset } : {}), | ||
| ...(args.agent ? { agent: args.agent } : {}) | ||
| }, | ||
| signal | ||
| ) | ||
|
|
@@ -91,7 +133,8 @@ export async function readOpenCodeNativeChatTranscriptTail( | |
| export async function readOpenCodeNativeChatTranscriptFull( | ||
| sessionId: string, | ||
| deps: OpenCodeTranscriptDeps = {}, | ||
| signal?: AbortSignal | ||
| signal?: AbortSignal, | ||
| agent?: 'zcode' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win Pass When |
||
| ): Promise<ReadTranscriptResult> { | ||
| // Pages arrive newest-window first; reverse windows, preserving message order. | ||
| const pages: NativeChatMessage[][] = [] | ||
|
|
@@ -113,7 +156,8 @@ export async function readOpenCodeNativeChatTranscriptFull( | |
| dbPath, | ||
| sessionId, | ||
| limit: 500, | ||
| ...(cursor !== undefined ? { beforeMessageRowId: cursor } : {}) | ||
| ...(cursor !== undefined ? { beforeMessageRowId: cursor } : {}), | ||
| ...(agent ? { agent } : {}) | ||
| }, | ||
| signal | ||
| ) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Probe the native ZCode database before querying WSL homes.
If WSL-home discovery stalls, this await reaches the five-second discovery deadline before
findSessionchecks a usable native ZCode database. The native transcript then fails to open even though it is available. MovegetAiVaultWslHomeDirs()after the native probe, as the existing OpenCode branch does.