The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
fix(opencode): show the model and reasoning level a running agent is on
0xdiego2551b1a933d2ff
diff --git a/cli/src/cli.ts b/cli/src/cli.tsindex ce6812090..c6dc8d63a 100644--- a/cli/src/cli.ts+++ b/cli/src/cli.ts@@ -1232,6 +1232,11 @@ async function runForeground(session: AuthSession): Promise<void> {})opencodeReaders.set(session.sessionId, reader)await reader.start()+ // The composer footer is the ONLY place OpenCode names its model and reasoning level, so+ // without this a freshly opened agent showed empty chips until the five-minute reconcile came+ // round — which is exactly how long it looked broken for.+ const ocPane = await captureTerminal(session.agentId, 100)+ if (ocPane) runtimeProfiles.ingestPane(session, ocPane, true)} else if (session.engine === 'kilo') {// Kilo is opencode's fork and keeps the same store shape, so it is polled the same way — but from// its OWN db and through its own reader, so the two can diverge without one breaking the other.@@ -2544,7 +2549,10 @@ async function runForeground(session: AuthSession): Promise<void> {// the device, which is the whole point.// agy joins these three: its model/effort exist only in the hook payload and the pane footer, never// in the transcript, so the chip goes stale without a poll.- const PANE_POLLED_ENGINES = new Set(['devin', 'cursor', 'grok', 'agy'])+ // opencode and its fork kilo belong here for the same stated reason and were simply missing: neither+ // writes its model anywhere but the composer footer, so between reconciles their chips said nothing+ // at all rather than going stale.+ const PANE_POLLED_ENGINES = new Set(['devin', 'cursor', 'grok', 'agy', 'opencode', 'kilo'])const PANE_POLL_MS = 15_000setInterval(() => {for (const session of registry.list()) {diff --git a/cli/src/engines/opencode/runtimeProfile.spec.ts b/cli/src/engines/opencode/runtimeProfile.spec.tsindex 11e18cfbf..58cf70709 100644--- a/cli/src/engines/opencode/runtimeProfile.spec.ts+++ b/cli/src/engines/opencode/runtimeProfile.spec.ts@@ -2,6 +2,7 @@ import { describe, expect, it } from 'vitest'import {countOpencodePickers,opencodeFooterModelId,+ parseOpencodeFooter,opencodeRowMatches,parseOpencodeModelsOutput,parseOpencodePickerRows,@@ -106,4 +107,36 @@ describe('opencode model catalog', () => {.toBe('opencode-go/mimo-v2.5-pro')expect(opencodeFooterModelId('┃ Ask anything...', catalog)).toBeNull()})++ it('keeps the reasoning level out of the model it searches for', () => {+ // Builds that have a reasoning axis print it after a second separator. Taking everything after+ // the FIRST one swallowed the level into the model text, so the catalog was searched for+ // "…OpenCode Zen high" and the level was thrown away.+ expect(opencodeFooterModelId('┃ Build · Ling-3.0-flash Free OpenCode Zen · high', catalog))+ .toBe('opencode/ling-3.0-flash-free')+ })++ it('reads model and level apart, from a real footer', () => {+ expect(parseOpencodeFooter('┃ Build · Ox Alpha Free (Unlimited) OpenCode Zen · high'))+ .toEqual({ target: 'Ox Alpha Free (Unlimited) OpenCode Zen', effort: 'high' })++ // A build with no reasoning axis says nothing about one, and nothing is what it gets.+ expect(parseOpencodeFooter('┃ Build · MiniMax M3 (vibe) Vibe Gateway (Minimax)'))+ .toEqual({ target: 'MiniMax M3 (vibe) Vibe Gateway (Minimax)', effort: null })++ // A trailing segment that is not a single bare word is part of a name, not a level: guessing one+ // would put a wrong value on the chip rather than no value.+ expect(parseOpencodeFooter('┃ Build · Some Model Provider · 2 files')?.effort).toBeNull()++ expect(parseOpencodeFooter('┃ Ask anything...')).toBeNull()+ })++ it('still names the model when the catalog does not list it', () => {+ // Not hypothetical: with no provider connected OpenCode runs a built-in free model that+ // `opencode models` never prints, and insisting on a catalog match left the chips blank while+ // the terminal named the model two lines below.+ const footer = '┃ Build · Ox Alpha Free (Unlimited) OpenCode Zen · high'+ expect(opencodeFooterModelId(footer, catalog)).toBeNull()+ expect(parseOpencodeFooter(footer)?.target).toBe('Ox Alpha Free (Unlimited) OpenCode Zen')+ })})diff --git a/cli/src/engines/opencode/runtimeProfile.ts b/cli/src/engines/opencode/runtimeProfile.tsindex 275fa6a4c..afb83fb11 100644--- a/cli/src/engines/opencode/runtimeProfile.ts+++ b/cli/src/engines/opencode/runtimeProfile.ts@@ -106,11 +106,51 @@ export function opencodeRowMatches(target: OpencodeModelTarget, row: OpencodePic* Both halves are needed: the model name alone is ambiguous across providers, and the provider alone* cannot name a model. The longest model match wins so `MiMo V2.5 Pro` never resolves to `mimo-v2.5`.*/-export function opencodeFooterModelId(capture: string, catalog: OpencodeModelTarget[]): string | null {+/** What OpenCode's composer footer says is running. */+export interface OpencodeFooter {+ /** Model and provider as printed, e.g. `Ox Alpha Free (Unlimited) OpenCode Zen`. */+ target: string+ /** The reasoning level, when the build prints one. */+ effort: string | null+}++/**+ * Read the composer footer: `Build · <model> <provider>` and, on builds that have a reasoning axis,+ * `· <effort>` after it.+ *+ * Build · MiniMax M3 (vibe) Vibe Gateway+ * Build · Ox Alpha Free (Unlimited) OpenCode Zen · high+ *+ * Split on the separator rather than taking everything after the FIRST one, which is what this used+ * to do: on a build that prints an effort, the level was swallowed into the model text, so the+ * catalog was searched for "…OpenCode Zen high" and the level itself was thrown away.+ */+export function parseOpencodeFooter(capture: string): OpencodeFooter | null {const line = capture.split('\n').map((l) => l.trim()).reverse().find((l) => /·/.test(l) && /\b(Build|Plan)\b/i.test(l))if (!line) return null- const tail = squash(line.slice(line.indexOf('·') + 1))+ // [0] is the mode (Build/Plan) and is not ours to report; the chips show model and effort.+ const parts = line.split('·').map((part) => part.trim()).filter(Boolean)+ if (parts.length < 2) return null+ const target = parts[1]+ if (!target) return null+ const trailing = parts[2]?.toLowerCase() ?? null+ // Only a single bare word is treated as a level. Anything longer is part of the name of something,+ // and inventing an effort out of it would put a wrong value on the chip rather than no value.+ const effort = trailing && /^[a-z][a-z-]*$/.test(trailing) ? trailing : null+ return { target, effort }+}++/**+ * The catalog entry the footer names, or null when the footer names something the catalog does not+ * list — which happens for real: with no provider connected, OpenCode runs a built-in free model+ * that `opencode models` does not print. Callers that only want to SHOW what is running should read+ * [parseOpencodeFooter] instead; this answers the narrower question of which switchable option it is.+ */+export function opencodeFooterModelId(capture: string, catalog: OpencodeModelTarget[]): string | null {+ const footer = parseOpencodeFooter(capture)+ if (!footer) return null+ const tail = squash(footer.target)if (!tail) return nulllet best: { id: string; length: number } | null = nulldiff --git a/cli/src/lib/engineBin.ts b/cli/src/lib/engineBin.tsindex 519a166f9..f4d66c855 100644--- a/cli/src/lib/engineBin.ts+++ b/cli/src/lib/engineBin.ts@@ -6,6 +6,7 @@*/import { accessSync, constants, realpathSync, statSync } from 'node:fs'+import { homedir } from 'node:os'import { delimiter, isAbsolute, join, normalize, sep } from 'node:path'import { env } from '../config/env.js'import { ENGINES, type AgentEngine } from '../engines/types.js'@@ -184,6 +185,37 @@ export function cursorRuntimeBin(snapshot = agentCommandOwnershipSnapshot()): streturn null}+/**+ * Where OpenCode is, for the processes this daemon spawns.+ *+ * It installs itself to `~/.opencode/bin` and puts that on PATH by editing the user's SHELL profile —+ * which a GUI-launched process never reads. This daemon is started by the desktop app, so `opencode`+ * is simply not on its PATH: the recap pool logged `spawn opencode ENOENT` once a second and the+ * model catalog came back empty every time, while the same command worked fine from a terminal.+ *+ * ONE answer for the whole daemon, because there were two and they disagreed: the recap path honoured+ * `OPENCODE_PATH` and the catalog fetch did not.+ *+ * `OPENCODE_PATH` wins; a bare `opencode` remains the last answer, so a genuinely missing install+ * still fails with the message it always did.+ */+export function opencodeBin(): string {+ if (env.OPENCODE_PATH) return env.OPENCODE_PATH+ for (const entry of pathEntries()) {+ try {+ accessSync(join(entry, 'opencode'), constants.X_OK)+ return 'opencode'+ } catch { /* keep looking */ }+ }+ const installed = join(homedir(), '.opencode', 'bin', 'opencode')+ try {+ accessSync(installed, constants.X_OK)+ return installed+ } catch {+ return 'opencode'+ }+}+/** Resolve an installed executable for real-engine verification without trusting a colliding alias. */export function installedEngineBin(engine: AgentEngine,diff --git a/cli/src/lib/engineBinOpencode.spec.ts b/cli/src/lib/engineBinOpencode.spec.tsnew file mode 100644index 000000000..589016a68--- /dev/null+++ b/cli/src/lib/engineBinOpencode.spec.ts@@ -0,0 +1,58 @@+import { mkdtempSync, mkdirSync, writeFileSync, chmodSync } from 'fs'+import { tmpdir } from 'os'+import { join } from 'path'+import { afterEach, describe, expect, it, vi } from 'vitest'++const REAL_PATH = process.env.PATH+const REAL_HOME = process.env.HOME++afterEach(() => {+ process.env.PATH = REAL_PATH+ if (REAL_HOME) process.env.HOME = REAL_HOME+ vi.resetModules()+})++function fakeHomeWithOpencode(): string {+ const home = mkdtempSync(join(tmpdir(), 'oc-home-'))+ const bin = join(home, '.opencode', 'bin')+ mkdirSync(bin, { recursive: true })+ const file = join(bin, 'opencode')+ writeFileSync(file, '#!/bin/sh\nexit 0\n')+ chmodSync(file, 0o755)+ return home+}++describe('opencodeBin', () => {+ it('finds the install when PATH does not have it', async () => {+ // The daemon is started by the desktop app, so it gets the GUI's PATH — no shell profile, and+ // therefore not the ~/.opencode/bin entry OpenCode's installer appends there. Every recap spun+ // on `spawn opencode ENOENT` while the same command worked fine from a terminal.+ const home = fakeHomeWithOpencode()+ process.env.HOME = home+ process.env.PATH = '/usr/bin:/bin'++ const { opencodeBin } = await import('./engineBin.js')+ expect(opencodeBin()).toBe(join(home, '.opencode', 'bin', 'opencode'))+ })++ it('leaves a PATH install alone', async () => {+ const home = mkdtempSync(join(tmpdir(), 'oc-empty-'))+ const dir = mkdtempSync(join(tmpdir(), 'oc-path-'))+ const file = join(dir, 'opencode')+ writeFileSync(file, '#!/bin/sh\nexit 0\n')+ chmodSync(file, 0o755)+ process.env.HOME = home+ process.env.PATH = `${dir}:/usr/bin`++ const { opencodeBin } = await import('./engineBin.js')+ expect(opencodeBin()).toBe('opencode')+ })++ it('still says `opencode` when nothing is installed, so the error is the usual one', async () => {+ process.env.HOME = mkdtempSync(join(tmpdir(), 'oc-none-'))+ process.env.PATH = '/nonexistent'++ const { opencodeBin } = await import('./engineBin.js')+ expect(opencodeBin()).toBe('opencode')+ })+})diff --git a/cli/src/lib/oneshot.ts b/cli/src/lib/oneshot.tsindex ae065edbf..dbc201e60 100644--- a/cli/src/lib/oneshot.ts+++ b/cli/src/lib/oneshot.ts@@ -8,7 +8,7 @@ import { randomUUID } from 'crypto'import { homedir, tmpdir, userInfo } from 'os'import { env } from '../config/env.js'import { findCursorTranscript } from '../engines/cursor/discovery.js'-import { cursorRuntimeBin } from './engineBin.js'+import { cursorRuntimeBin, opencodeBin } from './engineBin.js'import {DisposableOneShotPool,type ActiveEngineCounts,@@ -473,9 +473,6 @@ class CursorWorker extends ProcessWorker {}}-function opencodeBin(): string {- return env.OPENCODE_PATH || 'opencode'-}// Recap runs in an isolated OpenCode data dir so ephemeral summary sessions never land in the user's// real opencode.db, while still reading their ~/.config/opencode provider/model config.diff --git a/cli/src/lib/runtimeProfile.spec.ts b/cli/src/lib/runtimeProfile.spec.tsindex 8b91b258d..db1f60d2e 100644--- a/cli/src/lib/runtimeProfile.spec.ts+++ b/cli/src/lib/runtimeProfile.spec.ts@@ -156,6 +156,22 @@ describe('RuntimeProfileManager', () => {})})+ it('names an OpenCode model the catalog does not list, with its reasoning level', () => {+ const value = session('opencode')+ const manager = new RuntimeProfileManager()++ // A real footer from a machine with no provider connected: OpenCode runs a built-in free model+ // that `opencode models` never prints, so there is no catalog entry to resolve against and the+ // chips used to stay blank while the terminal named the model two lines below.+ manager.ingestPane(value, '┃ Build · Ox Alpha Free (Unlimited) OpenCode Zen · high')++ const profile = manager.selectedModel(value)+ expect(profile).not.toBeNull()+ const decoded = parseRuntimeProfile(profile!)+ expect(decoded?.model).toBe('Ox Alpha Free (Unlimited) OpenCode Zen')+ expect(decoded?.effort).toBe('high')+ })+it('observes Grok model metadata and its live footer effort', () => {const manager = new RuntimeProfileManager()const value = session('grok')diff --git a/cli/src/lib/runtimeProfile.ts b/cli/src/lib/runtimeProfile.tsindex 682f360c4..38be5fde2 100644--- a/cli/src/lib/runtimeProfile.ts+++ b/cli/src/lib/runtimeProfile.ts@@ -29,6 +29,7 @@ import {} from '../engines/commandcode/runtimeProfile.js'import {opencodeFooterModelId,+ parseOpencodeFooter,parseOpencodeModelsOutput,type OpencodeModelTarget,} from '../engines/opencode/runtimeProfile.js'@@ -153,6 +154,8 @@ const CURSOR_CONTROLLED_BUILD = '2026.07.20-8cc9c0b'const CURSOR_CATALOG_TTL_MS = 5 * 60_000/** Shared TTL for the stdout catalogs (devin, pi) — same rationale as the cursor one. */const CATALOG_TTL_MS = 5 * 60_000+import { opencodeBin } from './engineBin.js'+const execFileAsync = promisify(execFile)function decode(value: string): string | null {@@ -834,14 +837,26 @@ export class RuntimeProfileManager {void this.ingestConfig(session, true).catch(() => undefined)}} else if (session.engine === 'opencode') {- // OpenCode names the model in its composer footer (`Build · MiniMax M3 (vibe) Vibe Gateway …`), which- // only resolves against the catalog — hence the cached entries rather than a fresh (async) fetch.+ // OpenCode names what is running in its composer footer+ // (`Build · MiniMax M3 (vibe) Vibe Gateway · high`). Prefer the catalog entry it resolves to,+ // because that id is also what a SWITCH is addressed to — the cached entries rather than a+ // fresh (async) fetch, since this runs on the pane poll.+ //+ // Fall back to the footer's own words when the catalog does not list it. That is not a corner+ // case: with no provider connected OpenCode runs a built-in free model that `opencode models`+ // never prints, so insisting on a catalog match left the chips blank on a freshly opened agent+ // — showing nothing about a model the terminal was naming two lines below.+ const footer = parseOpencodeFooter(paneText)const id = opencodeFooterModelId(paneText, this.opencodeCatalogCache?.entries ?? [])- if (id) {- state.model = id- state.effort = 'auto'+ const model = id ?? footer?.target ?? null+ if (model) {+ // 'auto' remains the default: early builds had no reasoning axis at all, and inventing a+ // level for them would put a wrong value on the chip instead of an empty one.+ const effort = footer?.effort ?? 'auto'+ state.model = model+ state.effort = effortstate.observedAt = Date.now()- this.confirmObserved(session.sessionId, id, 'auto')+ this.confirmObserved(session.sessionId, model, effort)}} else if (session.engine === 'kilo') {// Kilo names the model in its composer footer too, but the line is shaped differently enough that@@ -1521,7 +1536,7 @@ export class RuntimeProfileManager {}let entries: OpencodeModelTarget[] = []try {- const result = await execFileAsync('opencode', ['models'], {+ const result = await execFileAsync(opencodeBin(), ['models'], {env: process.env, timeout: 10_000, maxBuffer: 1024 * 1024,})entries = parseOpencodeModelsOutput(result.stdout)