Files
orca/src/main/foreign-sqlite-readers/foreign-sqlite-reader-spawn.ts
T
OrcaWinandOrcaWin 4687e90a16 [comment audit] Continue main-process comment cleanup (#32946)
* [comment audit] Shorten daemon, hook, and emulator comments [skip ci]

* [comment audit] Shorten VM, conversation, SQLite, and theme-import comments [skip ci]

* [comment audit] Tighten Git execution and source-control comment contracts [skip ci]

* [comment audit] Clarify repository probes and maintenance comments [skip ci]

* [comment audit] Shorten status, diff-cache, and checkout comments [skip ci]

* [comment audit] Clarify worktree lifecycle and WSL routing comments [skip ci]

* [comment audit] Shorten forge identity and review-refresh comments [skip ci]

* [comment audit] Tighten hosted-review client comment contracts [skip ci]

* [comment audit] Clarify GitLab compatibility and review comments [skip ci]

* [comment audit] Tighten hook ownership and watchdog rationale [skip ci]

* [comment audit] Condense host and integration compatibility comments [skip ci]

* [comment audit] Clarify IPC authority and remote-routing rationale [skip ci]

* [comment audit] Finalize file-import and containment comment cleanup

* [comment audit] Fix stale Jira type imports blocking full CI

---------

Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
2026-10-23 16:27:37 -07:00

49 lines
1.8 KiB
TypeScript

import { existsSync } from 'node:fs'
import { stat } from 'node:fs/promises'
import { Worker } from 'node:worker_threads'
import { currentWorkerEntryLayout } from '../worker-thread-entry-path'
import type { CursorDesktopProfileReadResult } from './cursor-profile-result'
import { ForeignSqliteReaderClient } from './foreign-sqlite-reader-client'
import { resolveForeignSqliteReaderEntryPath } from './foreign-sqlite-reader-entry-path'
import type { BinderSessionRow, OpenCodeSessionCursor } from './opencode-binder-sessions-result'
function defaultWorkerFactory(): Worker {
const workerPath = resolveForeignSqliteReaderEntryPath(currentWorkerEntryLayout(__dirname))
if (!existsSync(workerPath)) {
throw new Error(`Foreign SQLite reader entry not found: ${workerPath}`)
}
return new Worker(workerPath)
}
let sharedClient: ForeignSqliteReaderClient | null = null
function getSharedClient(): ForeignSqliteReaderClient {
sharedClient ??= new ForeignSqliteReaderClient({ workerFactory: defaultWorkerFactory })
return sharedClient
}
export function readCursorDesktopProfile(dbPath: string): Promise<CursorDesktopProfileReadResult> {
return getSharedClient().readCursorProfile(dbPath)
}
/** Return oldest-first rows after cursor; unreadable or unavailable readers answer []. */
export async function readOpenCodeBinderSessions(
dbPath: string,
cursor: OpenCodeSessionCursor
): Promise<BinderSessionRow[]> {
try {
// Skip absent stores before waking a worker on every binder poll.
await stat(dbPath)
} catch (error) {
if (
error instanceof Error &&
'code' in error &&
(error.code === 'ENOENT' || error.code === 'ENOTDIR')
) {
return []
}
// Other stat failures still go through worker error reporting and its fresh open.
}
return getSharedClient().readOpenCodeBinderSessions(dbPath, cursor)
}