mirror of
https://github.com/stablyai/orca.git
synced 2026-11-04 19:17:28 +00:00
* feat(opencode): run OpenCode 2.x in the structured chat too `opencode acp` on stable 2.x starts its own private `opencode serve --stdio` child with the chat's environment and ends it when stdin closes, so the chat's account pin reaches it just as it does on 1.x. Admit stable 2.x from 2.0.14 beside stable 1.x from 1.18.31; pre-releases, older releases, and other major lines keep the terminal chat. The `opencode2` agent is unchanged. Restart recovery already reads a 2.x session's own tables first; tests now cover a database an upgrade left with both generations, and one whose 2.x message table has an unknown shape (nothing found, no error). * fix(opencode): show OpenCode's own permission option names * test(opencode): run the 2.x recovery tests with the real-SQLite Node project
39 lines
1.6 KiB
TypeScript
39 lines
1.6 KiB
TypeScript
import { homedir } from 'node:os'
|
|
import { OPENCODE_TRANSCRIPT_MAX_WINDOW } from '../../shared/opencode-transcript-page-limit'
|
|
import type { AcpStoredUserMessagesReader } from '../acp/acp-recovery-history'
|
|
import { resolveOpenCodeDatabasePath } from './opencode-data-directory'
|
|
import type { readOpenCodeTranscriptPageViaWorker } from '../ai-vault/session-scanner-opencode-sqlite-worker-spawn'
|
|
|
|
export type OpenCodeTranscriptPageReader = typeof readOpenCodeTranscriptPageViaWorker
|
|
|
|
/** The latest user messages of an OpenCode session, read from the database its pinned account
|
|
* selects, through the existing bounded reader: 2.x's `session_v2` rows first, else 1.x's. */
|
|
export function openCodeStoredUserMessagesReader(
|
|
readPage?: OpenCodeTranscriptPageReader
|
|
): AcpStoredUserMessagesReader {
|
|
return async ({ env, providerSessionId, signal }) => {
|
|
// The child's own home, which its account may name, not this process's.
|
|
const home = (process.platform === 'win32' ? env.USERPROFILE : env.HOME) || homedir()
|
|
const dbPath = resolveOpenCodeDatabasePath(env, home)
|
|
if (!dbPath) {
|
|
return null
|
|
}
|
|
const read =
|
|
readPage ??
|
|
(await import('../ai-vault/session-scanner-opencode-sqlite-worker-spawn'))
|
|
.readOpenCodeTranscriptPageViaWorker
|
|
const page = await read(
|
|
{ dbPath, sessionId: providerSessionId, limit: OPENCODE_TRANSCRIPT_MAX_WINDOW },
|
|
signal
|
|
)
|
|
if (!page) {
|
|
return null
|
|
}
|
|
return page.items.flatMap(({ message }) =>
|
|
message.role === 'user' && message.timestamp !== null
|
|
? [{ id: message.id, blocks: message.blocks, createdAt: message.timestamp }]
|
|
: []
|
|
)
|
|
}
|
|
}
|