From c0df7a6d7bdfbc2297dd67f42c8cb4d5fe976c2f Mon Sep 17 00:00:00 2001 From: Pascal Bourdier Date: Mon, 28 Sep 2026 19:06:12 +0200 Subject: [PATCH 1/2] feat(opencode): expose running version, provider and model in the env block MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Agents operating under 'state your engine and version' conventions (AGENTS.md PR traceability rules) cannot reliably know their own harness version: it is absent from the model context, which invites hallucinated values (observed: an opencode 1.18.30 agent declared 'opencode 0.11.x', anchored on a stale doc example). Add to the structured block: - OpenCode version: the build-time InstallationVersion (falls back to 'local' in dev builds) - Provider: the provider ID (the canonical, actionable form used in opencode.json provider/model references) - Model: the models.dev display name, with the exact API id in parentheses Also fix the adjacent prose line: it called the API id 'the model named', which is an identifier, not a name (e.g. openrouter z-ai/glm-5.3) — it now uses the display name, keeping the canonical providerID/api.id reference as the 'exact model ID'. Fixes #51909 --- packages/opencode/src/session/system.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/opencode/src/session/system.ts b/packages/opencode/src/session/system.ts index 61ab74d9f158..580c4dfa7d49 100644 --- a/packages/opencode/src/session/system.ts +++ b/packages/opencode/src/session/system.ts @@ -24,6 +24,7 @@ import { LocationServiceMap, locationServiceMapLayer } from "@opencode-ai/core/l import { Reference } from "@opencode-ai/core/reference" import { MCP } from "@/mcp" import { PermissionV1 } from "@opencode-ai/core/v1/permission" +import { InstallationVersion } from "@opencode-ai/core/installation/version" export function provider(model: Provider.Model) { if (model.api.id.includes("muse")) { @@ -73,7 +74,7 @@ const layer = Layer.effect( }).pipe(Effect.provide(locations.get(Location.Ref.make({ directory: AbsolutePath.make(ctx.directory) })))) return [ [ - `You are powered by the model named ${model.api.id}. The exact model ID is ${model.providerID}/${model.api.id}`, + `You are powered by the model named ${model.name}. The exact model ID is ${model.providerID}/${model.api.id}`, `Here is some useful information about the environment you are running in:`, ``, ` Working directory: ${ctx.directory}`, @@ -81,6 +82,9 @@ const layer = Layer.effect( ` Is directory a git repo: ${ctx.project.vcs === "git" ? "yes" : "no"}`, ` Platform: ${process.platform}`, ` Today's date: ${new Date().toDateString()}`, + ` OpenCode version: ${InstallationVersion}`, + ` Provider: ${model.providerID}`, + ` Model: ${model.name} (${model.api.id})`, ``, ].join("\n"), references.length === 0 From 9ef6c71f5a132684637380b33ef78e00643f6d02 Mon Sep 17 00:00:00 2001 From: Pascal Bourdier Date: Mon, 28 Sep 2026 19:40:26 +0200 Subject: [PATCH 2/2] test(opencode): cover the environment system prompt block Assert that environment(model) exposes the OpenCode version, the provider and the model identity (display name + exact API id) in the block, and that the adjacent prose line uses the display name. Runs through the testEffect instance scaffolding (withTmpdirInstance), which provides the InstanceState context environment() reads. --- packages/opencode/test/session/system.test.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/packages/opencode/test/session/system.test.ts b/packages/opencode/test/session/system.test.ts index 09bac3f8c5f7..59708812e5f6 100644 --- a/packages/opencode/test/session/system.test.ts +++ b/packages/opencode/test/session/system.test.ts @@ -7,6 +7,7 @@ import { Skill } from "../../src/skill" import { Permission } from "../../src/permission" import type { Provider } from "../../src/provider/provider" import { SystemPrompt } from "../../src/session/system" +import { InstallationVersion } from "@opencode-ai/core/installation/version" import { MCP } from "../../src/mcp" import { testEffect } from "../lib/effect" @@ -109,6 +110,25 @@ describe("session.system", () => { } }) + it.instance("environment exposes version, provider and model", () => + Effect.gen(function* () { + const prompt = yield* SystemPrompt.Service + const model = { + name: "Test Model", + providerID: "test-provider", + api: { id: "test-model-id" }, + } as unknown as Provider.Model + const parts = yield* prompt.environment(model) + const block = parts.join("\n") + + expect(block).toContain(`OpenCode version: ${InstallationVersion}`) + expect(block).toContain("Provider: test-provider") + expect(block).toContain("Model: Test Model (test-model-id)") + expect(block).toContain("You are powered by the model named Test Model.") + expect(block).toContain("The exact model ID is test-provider/test-model-id") + }), + ) + it.effect("skills output is sorted by name and stable across calls", () => Effect.gen(function* () { const prompt = yield* SystemPrompt.Service