Support real OpenCode sessions in native Chat (#24647)

* Use bounded OpenCode context for vault session continuation

OpenCode database and synthetic row paths are not text transcripts. Use the
vault preview or captured pane context, preserving actual transcript paths
containing a hash and supporting both OpenCode lanes and Windows paths.

Adapted the intent of #11859 and extended it to actual installed v2 vault rows.

Co-authored-by: mrcha033 <mrcha033@users.noreply.github.com>

* Read real OpenCode sessions in terminal-backed native Chat

Reuse the bounded AI Vault SQLite worker for v1 and v2 session pages and live updates. Keep terminal input as the real execution path and pace OpenCode Stop through its two-Escape interrupt.

Co-authored-by: xodmd45-ctrl <xodmd45-ctrl@users.noreply.github.com>

* fix(opencode): publish approval cards for permission requests

* Send OpenCode native approval through its Enter selector

* Resolve mobile Chat readability for folder workspaces

* Bound OpenCode part batches and preserve v2 image attachments

* Prefer live migrated OpenCode sessions over legacy copies

* Consolidate mobile Chat eligibility test imports

* Consolidate OpenCode SQLite protocol type imports

* Update native chat settings contract for both OpenCode agents

* fix(native-chat): reconcile bounded OpenCode transcript reads

* fix(native-chat): dispatch OpenCode questions safely

* fix(native-chat): keep native discovery and transcript windows current

* feat(accounts): link standalone GLM Coding Plans (#24618)

* feat(accounts): link standalone GLM Coding Plans

Adapt the reviewed GLM accounts contribution to current main, retain Antigravity behavior, guard late credential results, expose storage protection, and redact quota errors.

Co-authored-by: Luchong <lu740528977@gmail.com>

* fix(accounts): retain GLM credential results during quota refresh

* fix(accounts): make GLM credential editing desktop-only

* fix(accounts): mirror the host GLM site in paired clients

* fix(accounts): report unknown GLM host details and split web settings tests

Apply the independently reviewed Accounts correction from697284a without the v2 adapter commits. Preserve the saved-key store and serialized write behavior.

* fix(zcode): ship required GLM account translation entries

* chore: record GLM reconciliation hook validation

* chore: validate installed GLM commit hooks

* test: complete GLM account fixtures and web API inventory

---------

Co-authored-by: Luchong <lu740528977@gmail.com>

* fix(native-chat): route transcript requests through shared SQLite worker

* fix(ci): prevent concurrent pnpm refresh during mobile typechecks (#24776)

* fix(ci): run mobile typechecks without concurrent dependency refresh

* test(ci): check effective Linux E2E package list

* test(ci): preserve the mobile production compiler barrier

---------

Co-authored-by: Orca Integration Recovery <orca-validation@invalid.example>

* test(terminal): restore the live fish fixture prerequisites (#24947)

A restored pane waits for the initial status replay before subscribing to
PTY output. This fixture never settled that replay, so fish printed its
mode-2031 arm before the renderer connected. Its PTY API also omitted the
reset-input listener required by the serializer, aborting attachment.

Settle and dispose the existing startup-snapshot registration and provide
the same reset-listener mock used by the other PTY tests. The real fish
child-stdin assertions and timeouts remain unchanged. No production change.

* fix(shortcuts): defer TUI editing chords in terminal-first mode (#24640)

Restack the original focused change onto current main, preserving every owned source and test blob and the merged CI contract and journal cleanup fixes.

Original-commit: f707cde14a
fix(shortcuts): defer TUI editing chords in terminal-first mode

Original-commit: 0c6348e49e
docs(shortcuts): describe deferred preview terminal chords

Original-commit: be62c1b6c6
Align worktree history shortcut metadata with terminal conflict policy

Restacked-from: be62c1b6c6
Restacked-onto: f7b1f9d8be

* Register supervised Qoder China and Qwen Code (#24616)

* Add Qoder session history and search with real CLI coverage

* Allow the real Qoder marker file to end with a newline

* Keep Qoder tool output out of history previews and search

* Keep Qoder search pages readable by older clients

* Verify persisted Qoder history after a real generated and resumed task

* Negotiate Qoder filters before searching an older execution host

* Combine search client imports for the CI plugin gate

* Keep the relay search oracle aligned with legacy agent filtering

* Register supervised Qoder China and Qwen lifecycle integration

* Cover Qoder China mobile assets and mixed-host resume gates

* Verify Qoder provider tags against the older released wire parser

* Verify China and Qwen keep independent Windows hook scripts

* Verify Qoder registrations against the installed older Windows release

* test(qoder): align search capability contracts and pin old-host fencing

* fix(qoder): rank exact picker identities and command aliases first

* test(qoder): preserve the regional CLI shared icon expectation

Keep the full bundled-asset and no-remote-image checks, with an explicit
shared-logo basename for Qoder China. The map also works with older
catalog type unions.

* fix(qoder): align China catalog entry with fallback order

---------

Co-authored-by: Orca Integration Recovery <orca-validation@invalid.example>

* Use the measured pnpm lookup policy automatically in hosted root CI (#24951)

* Select lookup automatically for the measured hosted root-install profile

* Record hosted automatic-mode cold cache publication proof

* fix(native-chat): keep OpenCode history usable at read limits

Continue past failed database probes while preserving discovery cancellation.
Verify rows displaced by a capped tail before deciding whether to replace history.
Represent oversized v1/v2 rows with the existing omission text and stable cursors.

* Continue Antigravity IDE and 2.0 history in new CLI conversations (#24692)

* feat(antigravity): bridge IDE history into new CLI conversations

* fix(antigravity): preserve fresh-launch model and environment for IDE references

* fix(antigravity): forward IDE history opt-in through desktop IPC

* fix(antigravity): rebuild remote IDE reference startup on its host

* fix(antigravity): register IDE continuation action labels

* fix(antigravity): confine IDE references and bound metadata reads

* fix(antigravity): localize IDE continuation badges

* Preserve scanner service cache assertions and refresh Antigravity opening metadata

* Preserve Antigravity opening joins and target folder runtime authority

* fix(opencode): retry timed-out SSH plugin updates (#24666)

Preserve bounded retry behavior and the current-main status-envelope fields.

Original-PR: #24124
Reviewed-source: 103144f9c5

Co-authored-by: Justas Brazauskas <brazauskasjustas@gmail.com>

* fix(opencode): keep Go credentials private and resolve backend keys (#24615)

Preserve the complete credential storage, migration, IPC, Settings and rate-limit refresh change alongside standalone GLM plans, current-main database diagnostics and the reviewed unknown-backend environment correction. Keep native discovery cancellation third and selected environment fourth.

Original-topic-commit: 7903f1cddb
Original-topic-commit: 588117b5cf
Original-topic-commit: dedd4f8c86
Original-topic-commit: 6645dae104
Original-topic-commit: a25b80c02c1af7830b0e6a65e72d965b3ad98276
Restacked-from: a25b80c02c1af7830b0e6a65e72d965b3ad98276
Restacked-onto: b032867021

Co-authored-by: kespineira <kespineira@users.noreply.github.com>
Co-authored-by: kevimux <kevimux@users.noreply.github.com>
Reported-by: pullfrog
Reviewed-full-source: 849fe093073f4c1606bd65d79a0c725d955d0d1f
Native-helper-source: 80dbe23237


Reviewed-full-current-source: 36acb57d44adb3d378c0289c8c15f7da0fda214c

---------

Co-authored-by: mrcha033 <mrcha033@users.noreply.github.com>
Co-authored-by: xodmd45-ctrl <xodmd45-ctrl@users.noreply.github.com>
Co-authored-by: Luchong <lu740528977@gmail.com>
Co-authored-by: Orca Integration Recovery <orca-validation@invalid.example>
Co-authored-by: Justas Brazauskas <brazauskasjustas@gmail.com>
This commit is contained in:
Neil
2026-10-03 01:00:40 -07:00
committed by GitHub
co-authored by Justas Brazauskas kespineira kevimux mrcha033 xodmd45-ctrl Luchong Orca Integration Recovery
parent 4a5f00f46f
commit a2896f5470
62 changed files with 3721 additions and 222 deletions
@@ -0,0 +1,268 @@
import { openOpenCodeDatabaseReadonly } from '../ai-vault/session-scanner-opencode-sqlite-open'
import {
readOpenCode2TranscriptPage,
readOpenCode2TranscriptSignal
} from './transcript-opencode2-sqlite'
import type { NativeChatMessage } from '../../shared/native-chat-types'
import { openCodeTranscriptPageLimit } from '../../shared/opencode-transcript-page-limit'
import { extractString, parseJsonObject } from '../ai-vault/session-scanner-values'
import type SyncDatabase from '../sqlite/sync-database'
type BindValue = SyncDatabase.BindValue
type SqliteStatement = SyncDatabase.Statement
import {
opencodeMessageBlocks,
OPENCODE_TRANSCRIPT_MAX_ROW_BYTES
} from './transcript-opencode-part-blocks'
// Cursors are opaque provider order: SQLite rowid in v1, session sequence in v2.
export type OpenCodeTranscriptItem = {
rowid: number
fingerprint: string
message: NativeChatMessage
}
export type OpenCodeTranscriptPage = {
items: OpenCodeTranscriptItem[]
hasMore: boolean
beforeMessageRowId: number | null
}
export type OpenCodeTranscriptSignal = {
messageCount: number
partCount: number
maxMessageRowId: number
maxPartTimeUpdated: number
}
const PART_ID_BATCH = 100
function sessionExists(db: SyncDatabase, sessionId: string): boolean {
const table = rowsOf<{ name: string }>(
db.prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'session'")
)
return table.length > 0 && db.prepare('SELECT 1 FROM session WHERE id = ?').get(sessionId) != null
}
function rowsOf<T>(statement: SqliteStatement, ...params: BindValue[]): T[] {
return rowsWithinBudget<T>(statement, { bytes: 0 }, ...params)
}
function rowsWithinBudget<T>(
statement: SqliteStatement,
budget: { bytes: number },
...params: BindValue[]
): T[] {
const rows: ReturnType<SqliteStatement['all']> = []
for (const row of statement.iterate(...params)) {
budget.bytes += Object.values(row).reduce<number>(
(size, value) => size + (typeof value === 'string' ? Buffer.byteLength(value) : 0),
0
)
if (rows.length >= 10000 || budget.bytes > 16 * 1024 * 1024) {
throw new Error('OpenCode transcript query exceeds its read limit')
}
rows.push(row)
}
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: Each caller names the columns projected by its internal SQL query.
return rows as T[]
}
export function readOpenCodeTranscriptSignal(
dbPath: string,
sessionId: string
): OpenCodeTranscriptSignal | null {
const db = openOpenCodeDatabaseReadonly(dbPath)
try {
const v2 = readOpenCode2TranscriptSignal(db, sessionId)
if (v2) {
return v2
}
if (!sessionExists(db, sessionId)) {
return null
}
// Aggregates without GROUP BY always yield exactly one row, so [0] is it.
const [messageRow] = rowsOf<{ message_count: number; max_message_rowid: number }>(
db.prepare(
'SELECT COUNT(*) AS message_count, COALESCE(MAX(rowid), 0) AS max_message_rowid FROM message WHERE session_id = ?'
),
sessionId
)
const [partRow] = rowsOf<{ part_count: number; max_part_time_updated: number }>(
db.prepare(
'SELECT COUNT(*) AS part_count, COALESCE(MAX(time_updated), 0) AS max_part_time_updated FROM part WHERE session_id = ?'
),
sessionId
)
return {
messageCount: messageRow?.message_count ?? 0,
partCount: partRow?.part_count ?? 0,
maxMessageRowId: messageRow?.max_message_rowid ?? 0,
maxPartTimeUpdated: partRow?.max_part_time_updated ?? 0
}
} finally {
db.close()
}
}
export function readOpenCodeTranscriptPage(args: {
dbPath: string
sessionId: string
limit: number
beforeMessageRowId?: number
}): OpenCodeTranscriptPage | null {
const db = openOpenCodeDatabaseReadonly(args.dbPath)
try {
const v2 = readOpenCode2TranscriptPage(db, args)
if (v2) {
return v2
}
if (!sessionExists(db, args.sessionId)) {
return null
}
const limit = openCodeTranscriptPageLimit(args.limit)
// The upper bound is always bound: batching advances the cursor mid-page,
// so the statement cannot vary with `beforeMessageRowId`'s presence.
// MAX_SAFE_INTEGER is the "from the newest row" sentinel.
const select = db.prepare(
`SELECT rowid AS message_rowid, id, time_created, time_updated, CASE WHEN length(CAST(data AS BLOB)) <= ${OPENCODE_TRANSCRIPT_MAX_ROW_BYTES} THEN data ELSE NULL END AS data
FROM message
WHERE session_id = ? AND rowid < ?
ORDER BY rowid DESC
LIMIT ?`
)
const collected: OpenCodeTranscriptItem[] = []
let scannedRows = 0
let pageBytes = 0
const rawBudget = { bytes: 0 }
let cursor: number | undefined = args.beforeMessageRowId
let hasMore = false
for (;;) {
const rows = rowsWithinBudget<MessageRow>(
select,
rawBudget,
args.sessionId,
cursor ?? Number.MAX_SAFE_INTEGER,
limit + 1
)
scannedRows += rows.length
if (scannedRows > 10_000) {
throw new Error('OpenCode transcript page exceeds its scan limit')
}
if (rows.length === 0) {
break
}
// The (limit+1)th row is only a hasMore probe — never decoded.
hasMore = rows.length > limit
const selected = hasMore ? rows.slice(0, limit) : rows
cursor = selected.at(-1)!.message_rowid
const mapped = mapMessageRows(db, args.sessionId, selected, rawBudget)
pageBytes += Buffer.byteLength(JSON.stringify(mapped))
if (pageBytes > 16 * 1024 * 1024) {
throw new Error('OpenCode transcript page exceeds its byte limit')
}
collected.push(...mapped)
if (!hasMore || collected.length >= limit) {
break
}
}
const overshot = collected.length > limit
const trimmed = overshot ? collected.slice(0, limit) : collected
const items = trimmed.toReversed()
return {
items,
hasMore: hasMore || overshot,
beforeMessageRowId: overshot ? items[0]!.rowid : (cursor ?? null)
}
} finally {
db.close()
}
}
type MessageRow = {
message_rowid: number
id: string
time_created: number
time_updated: number
data: string | null
}
type PartRow = {
message_id: string
time_updated: number
data: string | null
}
function mapMessageRows(
db: SyncDatabase,
sessionId: string,
rows: MessageRow[],
rawBudget: { bytes: number }
): OpenCodeTranscriptItem[] {
if (rows.length === 0) {
return []
}
const partsByMessage = new Map<string, PartRow[]>()
const ids = rows.map((row) => row.id)
for (let start = 0; start < ids.length; start += PART_ID_BATCH) {
const batch = ids.slice(start, start + PART_ID_BATCH)
const placeholders = batch.map(() => '?').join(', ')
const partRows = rowsWithinBudget<PartRow>(
db.prepare(
`SELECT message_id, time_updated, CASE WHEN length(CAST(data AS BLOB)) <= ${OPENCODE_TRANSCRIPT_MAX_ROW_BYTES} THEN data ELSE NULL END AS data FROM part
WHERE session_id = ? AND message_id IN (${placeholders})
ORDER BY rowid LIMIT 10001`
),
rawBudget,
sessionId,
...batch
)
if (partRows.length > 10000) {
throw new Error('OpenCode transcript parts exceed their read limit')
}
for (const partRow of partRows) {
const list = partsByMessage.get(partRow.message_id)
if (list) {
list.push(partRow)
} else {
partsByMessage.set(partRow.message_id, [partRow])
}
}
}
const items: OpenCodeTranscriptItem[] = []
for (const row of rows) {
const partList = partsByMessage.get(row.id) ?? []
const blocks = opencodeMessageBlocks(
row.data === null
? [{ message_id: row.id, time_updated: row.time_updated, data: null }]
: partList
)
if (blocks.length === 0) {
continue
}
const record = row.data === null ? null : parseJsonObject(row.data)
const role = extractString(record?.role)
items.push({
rowid: row.message_rowid,
fingerprint: `${row.time_updated}:${partList.length}:${maxPartTimeUpdated(partList)}`,
message: {
id: row.id,
role: role === 'user' ? 'user' : role === 'assistant' ? 'assistant' : 'system',
blocks,
timestamp: Number.isFinite(row.time_created) ? row.time_created : null,
source: 'transcript'
}
})
}
return items
}
function maxPartTimeUpdated(partRows: PartRow[]): number {
let max = 0
for (const partRow of partRows) {
if (partRow.time_updated > max) {
max = partRow.time_updated
}
}
return max
}