Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions electron.vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { createPlainNodeEntryGuardPlugin } from './config/build-plugins/plain-no
import packageJson from './package.json' with { type: 'json' }

const BUNDLED_MAIN_DEPENDENCIES = new Set([
'@streamparser/json',
'@xterm/headless',
'@xterm/addon-serialize',
'tldts',
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@
"@floating-ui/dom": "1.7.6",
"@linear/sdk": "^82.1.0",
"@parcel/watcher": "^2.5.6",
"@streamparser/json": "0.0.26",
"@xterm/addon-serialize": "0.15.0-beta.300",
"@xterm/headless": "6.1.0-beta.302",
"agent-browser": "~0.27.0",
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 36 additions & 1 deletion src/main/ai-vault/remote-session-content-lines.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { splitTranscriptStreamLines } from '../native-chat/transcript-stream-lines'
import { setImmediate as yieldToEventLoop } from 'node:timers/promises'
import { throwIfAiVaultScanCancelled } from './ai-vault-scan-cancellation'

export type RemoteSessionContent = string | AsyncIterable<string>

const REMOTE_CONTENT_YIELD_LINE_COUNT = 200
const REMOTE_CONTENT_YIELD_CHAR_COUNT = 256 * 1024

Expand All @@ -9,9 +12,12 @@ const REMOTE_CONTENT_YIELD_CHAR_COUNT = 256 * 1024
* cancelled scan stops mid-transcript instead of parsing megabytes for a caller
* that already left. */
export function remoteSessionContentLines(
content: string,
content: RemoteSessionContent,
signal?: AbortSignal
): Iterable<string> | AsyncIterable<string> {
if (typeof content !== 'string') {
return content
}
return signal ? cancellableContentLines(content, signal) : content.split(/\r?\n/)
}

Expand Down Expand Up @@ -61,3 +67,32 @@ async function yieldUnlessCancelled(signal: AbortSignal): Promise<void> {
await yieldToEventLoop()
throwIfAiVaultScanCancelled(signal)
}

export class BinarySessionTranscriptError extends Error {
constructor() {
super('Binary session transcript')
}
}

export async function* streamedSessionContentLines(
bytes: AsyncIterable<Buffer>,
signal?: AbortSignal
): AsyncGenerator<string> {
let count = 0
let chars = 0
for await (const record of splitTranscriptStreamLines(bytes)) {
throwIfAiVaultScanCancelled(signal)
const line =
record.line.endsWith('\r') && (record.terminated || signal)
? record.line.slice(0, -1)
: record.line
yield line
chars += line.length
if (++count >= REMOTE_CONTENT_YIELD_LINE_COUNT || chars >= REMOTE_CONTENT_YIELD_CHAR_COUNT) {
await yieldToEventLoop()
throwIfAiVaultScanCancelled(signal)
count = 0
chars = 0
}
}
}
51 changes: 51 additions & 0 deletions src/main/ai-vault/remote-session-document-parsers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import type { AiVaultAgent } from '../../shared/ai-vault-types'
import { parseDevinSessionDocument } from './session-scanner-devin-parser'
import { parseHermesSessionDocument } from './session-scanner-hermes-parser'
import {
parseGeminiSessionDocument,
parseGeminiJsonlSessionLines
} from './session-scanner-gemini-parsers'
import type { RemoteSessionSource } from './remote-session-scanner-types'

export function remoteSessionDocumentParsers(
agent: AiVaultAgent
): Pick<RemoteSessionSource, 'parseLines' | 'parseDocument'> {
const parse =
agent === 'hermes'
? parseHermesSessionDocument
: agent === 'devin'
? parseDevinSessionDocument
: agent === 'gemini'
? parseGeminiSessionDocument
: null
if (!parse) {
return {}
}
return {
parseDocument: (file, bytes, context) =>
parse(
file,
bytes,
context.hostPlatform.os,
{
executionHostId: context.executionHostId,
executionHostPlatform: context.hostPlatform.os
},
context.signal
),
...(agent === 'gemini'
? {
parseLines: (file, lines, context) =>
parseGeminiJsonlSessionLines({
file,
lines,
platform: context.hostPlatform.os,
options: {
executionHostId: context.executionHostId,
executionHostPlatform: context.hostPlatform.os
}
})
}
: {})
}
}
188 changes: 188 additions & 0 deletions src/main/ai-vault/remote-session-large-transcripts.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
import { mkdtemp, mkdir, writeFile, rm } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { join, dirname } from 'node:path'
import { describe, it, expect } from 'vitest'
import { createRelayAiVaultFilesystemProvider } from '../../relay/ai-vault-service-filesystem'
import { scanRemoteAiVaultSessions } from './remote-session-scanner'
import { getRemoteHostPlatform } from '../ssh/ssh-remote-platform'

const platform = getRemoteHostPlatform(
process.platform === 'win32'
? 'win32-x64'
: process.platform === 'darwin'
? 'darwin-arm64'
: 'linux-x64'
)
const jsonl = (rows: unknown[]) => `${rows.map((row) => JSON.stringify(row)).join('\n')}\n`
const filler = jsonl([{ type: 'irrelevant_event', payload: 'x'.repeat(1024) }]).repeat(11000)

describe('large remote history through real relay filesystem', () => {
it('lists a large Codex rollout with middle messages and usage intact', async () => {
const home = await mkdtemp(join(tmpdir(), 'orca-history-17744-'))
try {
const path = join(home, '.codex', 'sessions', 'large.jsonl')
await mkdir(dirname(path), { recursive: true })
await writeFile(
path,
jsonl([
{
type: 'session_meta',
timestamp: '2026-09-13T01:00:00Z',
payload: { id: 'large', cwd: '/repo' }
},
{
type: 'response_item',
timestamp: '2026-09-13T01:00:01Z',
payload: {
type: 'message',
role: 'user',
content: [{ type: 'input_text', text: 'Keep my history' }]
}
}
]) +
filler.slice(0, filler.length / 2) +
jsonl([
{
type: 'response_item',
timestamp: '2026-09-13T01:02:00Z',
payload: {
type: 'message',
role: 'assistant',
content: [{ type: 'output_text', text: 'Middle answer' }]
}
},
{
type: 'event_msg',
timestamp: '2026-09-13T01:03:00Z',
payload: {
type: 'token_count',
info: {
total_token_usage: { input_tokens: 123, output_tokens: 45, total_tokens: 168 }
}
}
}
]) +
filler.slice(filler.length / 2)
)
const result = await scanRemoteAiVaultSessions({
provider: createRelayAiVaultFilesystemProvider(),
executionHostId: 'ssh:synthetic-17744',
remoteHome: home,
hostPlatform: platform,
unlimited: true
})
expect(result.issues).toEqual([])
expect(result.sessions).toHaveLength(1)
expect(result.sessions[0]).toMatchObject({
sessionId: 'large',
messageCount: 2,
totalTokens: 168,
title: 'Keep my history'
})
} finally {
await rm(home, { recursive: true, force: true })
}
})

it.each(['hermes', 'devin', 'gemini', 'cline'] as const)(
'lists large %s documents with every message counted',
async (agent) => {
const home = await mkdtemp(join(tmpdir(), 'orca-history-17744-document-'))
try {
const messages = Array.from({ length: 11000 }, () => ({
role: 'assistant',
content: 'x'.repeat(1024)
}))
messages.splice(5000, 0, { role: 'user', content: 'A middle user turn' })
let path: string, record: unknown
if (agent === 'hermes') {
path = join(home, '.hermes', 'sessions', 'large.json')
record = { session_id: 'large', cwd: '/repo', model: 'test-model', messages }
} else if (agent === 'devin') {
path = join(home, '.local', 'share', 'devin', 'cli', 'transcripts', 'large.json')
record = {
session_id: 'large',
working_directory: '/repo',
steps: messages.map((message) => ({
...message,
metadata: {
is_user_input: message.role === 'user',
metrics: { input_tokens: 2, output_tokens: 1 }
}
}))
}
} else if (agent === 'gemini') {
path = join(home, '.gemini', 'tmp', 'large.json')
record = {
sessionId: 'large',
messages: messages.map((message) => ({
type: message.role === 'assistant' ? 'gemini' : 'user',
content: message.content
}))
}
} else {
path = join(home, '.cline', 'data', 'sessions', 'large', 'large.json')
record = { session_id: 'large', cwd: '/repo' }
await mkdir(dirname(path), { recursive: true })
await writeFile(path.replace('.json', '.messages.json'), JSON.stringify({ messages }))
}
await mkdir(dirname(path), { recursive: true })
await writeFile(path, JSON.stringify(record))
const result = await scanRemoteAiVaultSessions({
provider: createRelayAiVaultFilesystemProvider(),
executionHostId: `ssh:large-${agent}`,
remoteHome: home,
hostPlatform: platform,
unlimited: true
})
expect(result.issues).toEqual([])
expect(result.sessions).toHaveLength(1)
expect(result.sessions[0]).toMatchObject({ agent, sessionId: 'large', messageCount: 11001 })
if (agent === 'devin') {
expect(result.sessions[0].totalTokens).toBe(33003)
}
} finally {
await rm(home, { recursive: true, force: true })
}
}
)
it('keeps normal-size reads on their existing path and supports providers without streaming', async () => {
const home = await mkdtemp(join(tmpdir(), 'orca-history-legacy-'))
try {
const directory = join(home, '.codex', 'sessions')
await mkdir(directory, { recursive: true })
const content = jsonl([{ type: 'session_meta', payload: { id: 'small', cwd: '/repo' } }])
await writeFile(join(directory, 'small.jsonl'), content)
const provider = createRelayAiVaultFilesystemProvider()
provider.readTranscriptBytes = () => {
throw new Error('Small file must keep its existing read path')
}
const small = await scanRemoteAiVaultSessions({
provider,
executionHostId: 'ssh:small-original',
remoteHome: home,
hostPlatform: platform,
unlimited: true
})
expect(small.issues).toEqual([])
expect(small.sessions.map((session) => session.sessionId)).toEqual(['small'])
await writeFile(join(directory, 'large.jsonl'), content + filler)
const legacy = { readDir: provider.readDir, readFile: provider.readFile, stat: provider.stat }
const fallback = await scanRemoteAiVaultSessions({
provider: legacy,
executionHostId: 'ssh:legacy-original',
remoteHome: home,
hostPlatform: platform,
unlimited: true
})
expect(fallback.sessions.map((session) => session.sessionId)).toEqual(['small'])
expect(
fallback.issues.some(
(issue) => issue.path.endsWith('large.jsonl') && issue.message.includes('10MB limit')
)
).toBe(true)
} finally {
await rm(home, { recursive: true, force: true })
}
})
})
27 changes: 26 additions & 1 deletion src/main/ai-vault/remote-session-scan-concurrency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,32 @@ export function limitRemoteScanFilesystemConcurrency(
return {
readDir: (dirPath) => gate(() => provider.readDir(dirPath)),
readFile: (filePath) => gate(() => provider.readFile(filePath)),
stat: (filePath) => gate(() => provider.stat(filePath))
stat: (filePath) => gate(() => provider.stat(filePath)),
...(provider.readTranscriptBytes
? {
readTranscriptBytes: async function* (path: string, signal?: AbortSignal) {
let enter!: () => void
let release!: () => void
const entered = new Promise<void>((resolve) => {
enter = resolve
})
const released = new Promise<void>((resolve) => {
release = resolve
})
const held = gate(async () => {
enter()
await released
})
await entered
try {
yield* provider.readTranscriptBytes!(path, signal)
} finally {
release()
await held
}
}
}
: {})
}
}

Expand Down
Loading