Skip to content

feat(opencode): expose running version, provider and model in the env block - #51911

Open
PascalBourdier wants to merge 2 commits into
anomalyco:devfrom
PascalBourdier:feat/env-block-version-model
Open

PascalBourdier wants to merge 2 commits into
anomalyco:devfrom
PascalBourdier:feat/env-block-version-model

Conversation

@PascalBourdier

@PascalBourdier PascalBourdier commented Sep 28, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #51909

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

The model context never includes the running OpenCode version, so agents asked to "state your engine and version" (a common AGENTS.md traceability rule) tend to guess: an opencode 1.18.30 agent was observed writing opencode 0.11.x in a PR description, anchored on a stale doc example. The model id only appears as prose in the main system prompt, which subagents and custom agents may not receive.

This adds three lines to the structured <env> block of the session system prompt:

  • OpenCode version: ${InstallationVersion} — the build-time constant
  • Provider: ${model.providerID} — the canonical form used in opencode.json references
  • Model: ${model.name} (${model.api.id}) — models.dev display name + exact API id

The adjacent prose line is also fixed: it called the API id "the model named" (an id, not a name — e.g. z-ai/glm-5.3); it now uses the display name and keeps providerID/api.id as the "exact model ID".

All values are already in scope of environment(model) — no new service dependency.

Context: #9065 asked for the same (model identity + version); only the model part landed (88bcd04, prose line), then it was stale-closed with an invite to re-open. #51909 is that re-open.

How did you verify your code works?

  • A dedicated test covers environment(model) in packages/opencode/test/session/system.test.ts (asserts the three env lines and the fixed prose line); it runs through the testEffect instance scaffolding, which provides the InstanceState context the function reads.
  • bun run typecheck (turbo, all 30 packages) — green.
  • bun test test/session/system.test.ts — 7 pass, 0 fail (6 existing + the new test; no existing assertion touches the env block or the prose line).
  • bun run lint (oxlint) — no new findings from this change (the reported error and warnings are pre-existing on untouched lines).
  • CI runs the full suite on top of this.

Screenshots / recordings

N/A — not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. needs:title labels Sep 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Hey! Your PR title [draft] feat(opencode): expose running version and model in the env block doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

… block

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 <env> 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 anomalyco#51909
@PascalBourdier
PascalBourdier force-pushed the feat/env-block-version-model branch from 086aca7 to c0df7a6 Compare September 28, 2026 17:18
@PascalBourdier PascalBourdier changed the title [draft] feat(opencode): expose running version and model in the env block feat(opencode): expose running version and model in the env block Sep 28, 2026
@PascalBourdier
PascalBourdier marked this pull request as ready for review September 28, 2026 17:23
@PascalBourdier PascalBourdier changed the title feat(opencode): expose running version and model in the env block feat(opencode): expose running version, provider and model in the env block Sep 28, 2026
Assert that environment(model) exposes the OpenCode version, the
provider and the model identity (display name + exact API id) in the
<env> 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.
@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Sep 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@kvnloo

kvnloo commented Sep 28, 2026

Copy link
Copy Markdown

The <env> block omits the running OpenCode version, provider, and model, so a session cannot tell which binary answered.

Head 9ef6c71f5a132684637380b33ef78e00643f6d02 is unchanged from the tested tip.

Fork leaf kvnloo#189 recorded fail→pass on packages/opencode/test/session/system.test.ts (7 pass, 1 fail with the assertion removed, 7 pass after restore).

That locks those three fields in the env block. It does not cover other system-prompt sections.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: expose the running OpenCode version, provider and model in the agent env block

2 participants