chore(opencode): move the typed OpenCode SDK to the 2.1.2 pin

The runtime pin moved to 2.1.2 while @opencode/client stayed at 2.0.15, so
the shared typed contract no longer matched the server.

- @opencode/client and @opencode/plugin move to 2.1.2
- session projection follows the 2.1 event shape (native replaces
  providerState and state, compaction drops recent)
- worktree error stubs carry the _tag discriminator
- the contract test fails when the SDK version drifts from the pin
This commit is contained in:
Chris Scott committed 2026-10-23 15:45:36 -04:00
1 parent 0c4c024dcc
commit 20017d2f7d
8 files changed
+294 -354

No files matched your search

+10 -2
View File
@@ -424,7 +424,11 @@ describe('DELETE /api/repos/:id/workspaces', () => {
const client = createStubOpenCodeClient()
client.api.worktree.list = mock(async () => ([{ directory: worktreeDir, strategy: 'git' }])) as any
client.api.worktree.remove = mock(async () => {
throw Object.assign(new Error('cannot remove'), { name: 'WorktreeError', data: { message: 'cannot remove' } })
throw Object.assign(new Error('cannot remove'), {
_tag: 'WorktreeError',
name: 'WorktreeError',
data: { message: 'cannot remove' },
})
}) as any
const app = createTestApp(db, client)
@@ -519,7 +523,11 @@ describe('POST /api/repos/:id/workspaces', () => {
createRepo(db, { localPath: 'repo-a', defaultBranch: 'main', cloneStatus: 'ready', clonedAt: Date.now(), isLocal: true })
const client = createStubOpenCodeClient()
client.api.worktree.create = mock(async () => {
throw Object.assign(new Error('cannot create'), { name: 'WorktreeError', data: { message: 'cannot create' } })
throw Object.assign(new Error('cannot create'), {
_tag: 'WorktreeError',
name: 'WorktreeError',
data: { message: 'cannot create' },
})
}) as any
const app = createTestApp(db, client)
@@ -26,6 +26,10 @@ interface CapturedRequest {
headers: Record<string, string>
}
interface PackageManifest {
dependencies: Record<string, string>
}
function createFetchSpy() {
const calls: CapturedRequest[] = []
const fetchSpy = (async (input: Parameters<typeof fetch>[0], init?: Parameters<typeof fetch>[1]) => {
@@ -145,6 +149,13 @@ describe('OpenCode v2 contract', () => {
expect(dockerfile).toMatch(/^ENV OPENCODE_BUNDLED_VERSION=\$\{OPENCODE_VERSION\}$/m)
})
it('keeps the shared SDK dependency in sync with the pin', () => {
const manifest = JSON.parse(
readFileSync(join(REPO_ROOT, 'shared', 'package.json'), 'utf8'),
) as PackageManifest
expect(manifest.dependencies['@opencode/client']).toBe(OPENCODE_PINNED_VERSION)
})
it('makes the shell scripts derive the pin from the Dockerfile or the bundled version instead of hardcoding it', () => {
const entrypoint = readFileSync(join(REPO_ROOT, 'scripts', 'docker-entrypoint.sh'), 'utf8')
const setupDev = readFileSync(join(REPO_ROOT, 'scripts', 'setup-dev.sh'), 'utf8')
@@ -233,7 +233,6 @@ describe('applySessionEvent', () => {
type: 'compaction',
status: 'running',
summary: 'Summarizing',
recent: 'previous turn',
},
])
@@ -245,7 +244,6 @@ describe('applySessionEvent', () => {
type: 'compaction',
status: 'completed',
summary: 'Summarizing the previous turn.',
recent: 'previous turn',
reason: 'auto',
cost: 0.02,
tokens: { input: 900, output: 60, reasoning: 0, cache: { read: 0, write: 0 } },
@@ -504,7 +504,7 @@ function applyEventToDraft(draft: TranscriptDraft, event: V2Event): void {
error: undefined,
finish: undefined,
rawFinish: undefined,
providerState: undefined,
native: undefined,
time: { created: started, streamed: undefined, completed: undefined },
...(snapshot ? { snapshot: { ...current.snapshot, start: snapshot } } : {}),
}
@@ -539,7 +539,7 @@ function applyEventToDraft(draft: TranscriptDraft, event: V2Event): void {
time: { ...assistant.time, completed: event.created },
finish: event.data.finish,
rawFinish: event.data.rawFinish,
providerState: event.data.providerState,
native: event.data.native,
cost: event.data.cost,
tokens: event.data.tokens,
...(event.data.snapshot || event.data.files
@@ -559,7 +559,7 @@ function applyEventToDraft(draft: TranscriptDraft, event: V2Event): void {
time: { ...assistant.time, completed: event.created },
finish: event.data.finish ?? 'error',
rawFinish: event.data.rawFinish,
providerState: event.data.providerState,
native: event.data.native,
error: event.data.error,
retry: undefined,
...(event.data.cost !== undefined && event.data.tokens !== undefined
@@ -592,7 +592,7 @@ function applyEventToDraft(draft: TranscriptDraft, event: V2Event): void {
editText(assistant, (text) => ({
...text,
text: event.data.text,
...(event.data.state === undefined ? {} : { state: event.data.state }),
...(event.data.native === undefined ? {} : { native: event.data.native }),
})),
)
return
@@ -604,7 +604,7 @@ function applyEventToDraft(draft: TranscriptDraft, event: V2Event): void {
{
type: 'reasoning',
text: '',
...(event.data.state === undefined ? {} : { state: event.data.state }),
...(event.data.native === undefined ? {} : { native: event.data.native }),
time: { created: event.created },
},
],
@@ -623,7 +623,7 @@ function applyEventToDraft(draft: TranscriptDraft, event: V2Event): void {
editReasoning(assistant, (reasoning) => ({
...reasoning,
text: event.data.text,
...(event.data.state === undefined ? {} : { state: event.data.state }),
...(event.data.native === undefined ? {} : { native: event.data.native }),
time: { created: reasoning.time?.created ?? event.created, completed: event.created },
})),
)
@@ -666,7 +666,7 @@ function applyEventToDraft(draft: TranscriptDraft, event: V2Event): void {
editTool(assistant, event.data.id, (tool) => ({
...tool,
executed: event.data.executed,
providerState: event.data.state,
native: event.data.native,
time: { ...tool.time, ran: event.created },
state: { status: 'running', input: event.data.input, metadata: {} },
})),
@@ -688,7 +688,9 @@ function applyEventToDraft(draft: TranscriptDraft, event: V2Event): void {
return {
...tool,
executed: event.data.executed || tool.executed === true,
providerResultState: event.data.resultState,
...(tool.native || event.data.native
? { native: { ...tool.native, ...event.data.native } }
: {}),
time: { ...tool.time, completed: event.created },
state: {
status: 'completed',
@@ -707,7 +709,9 @@ function applyEventToDraft(draft: TranscriptDraft, event: V2Event): void {
return {
...tool,
executed: event.data.executed || tool.executed === true,
providerResultState: event.data.resultState,
...(tool.native || event.data.native
? { native: { ...tool.native, ...event.data.native } }
: {}),
time: { ...tool.time, completed: event.created },
state: {
status: 'error',
@@ -827,7 +831,6 @@ function applyEventToDraft(draft: TranscriptDraft, event: V2Event): void {
status: 'running',
reason: event.data.reason,
summary: '',
recent: event.data.recent ?? '',
time: { created: event.created },
})
return
@@ -847,8 +850,7 @@ function applyEventToDraft(draft: TranscriptDraft, event: V2Event): void {
if (
latest?.type === 'compaction' &&
latest.status === 'completed' &&
latest.summary === event.data.text &&
latest.recent === event.data.recent
latest.summary === event.data.text
) {
return
}
@@ -858,9 +860,8 @@ function applyEventToDraft(draft: TranscriptDraft, event: V2Event): void {
status: 'completed',
reason: event.data.reason,
model: event.data.model,
providerState: event.data.providerState,
native: event.data.native,
summary: event.data.text,
recent: event.data.recent,
cost: event.data.cost,
tokens: event.data.tokens,
time: { created: event.created },
@@ -872,9 +873,8 @@ function applyEventToDraft(draft: TranscriptDraft, event: V2Event): void {
status: 'completed',
reason: event.data.reason,
model: event.data.model,
providerState: event.data.providerState,
native: event.data.native,
summary: event.data.text,
recent: event.data.recent,
cost: event.data.cost,
tokens: event.data.tokens,
metadata: event.metadata ? { ...current.metadata, ...event.metadata } : current.metadata,
+2 -3
View File
@@ -335,7 +335,7 @@ export const compactionSequence: V2Event[] = [
created: 5000,
type: 'session.compaction.started',
durable: durable(50),
data: { sessionID: SESSION_ID, reason: 'auto', recent: 'previous turn' },
data: { sessionID: SESSION_ID, reason: 'auto' },
},
{
id: eventID(51),
@@ -352,7 +352,6 @@ export const compactionSequence: V2Event[] = [
sessionID: SESSION_ID,
reason: 'auto',
text: 'Summarizing the previous turn.',
recent: 'previous turn',
cost: 0.02,
tokens: { input: 900, output: 60, reasoning: 0, cache: { read: 0, write: 0 } },
},
@@ -365,7 +364,7 @@ export const failedCompactionSequence: V2Event[] = [
created: 5030,
type: 'session.compaction.started',
durable: durable(53),
data: { sessionID: SESSION_ID, reason: 'manual', recent: 'previous turn' },
data: { sessionID: SESSION_ID, reason: 'manual' },
},
{
id: eventID(54),
+1 -1
View File
@@ -54,7 +54,7 @@
},
"devDependencies": {
"@eslint/js": "^9.36.0",
"@opencode/plugin": "2.0.15",
"@opencode/plugin": "2.1.2",
"@opencode-manager/shared": "workspace:*",
"@opentui/core": "^0.5.12",
"@opentui/solid": "^0.5.12",
+253 -329
View File
File diff suppressed because it is too large. Load diff
+1 -1
View File
@@ -21,7 +21,7 @@
"./themes": "./src/themes/index.ts"
},
"dependencies": {
"@opencode/client": "2.0.15",
"@opencode/client": "2.1.2",
"jsonc-parser": "^3.3.1",
"zod": "^4.1.12"
},