Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 37 additions & 34 deletions ARCHITECTURE-MAP.md

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@

All notable changes to the **OpenCode Go BYOK Provider** extension are documented here.

## [Unreleased]

### Added

- **`[Auth]` A new "OpenCode Go: Sign In with OpenCode Console" command imports the API key the OpenCode CLI already saved, with explicit consent, or opens the Console key page and stores the pasted key in SecretStorage (issue #286).** OpenCode's `/connect` still requires an API key for Go, so no undocumented OAuth or session-cookie scraping is used. Documented in `docs/issues/127-20261125-issue286-console-sign-in.md`.

### Fixed

- **`[Google]` Gemini tool results use the valid `functionResponse` shape again (issue #283).** A July regression moved `content` to the top level; strict validators such as `gemini-4-argon` rejected every request after the first tool call. The text now lives in the required `response` object while multimodal `parts` stay at `functionResponse` level. Documented in `docs/issues/122-20261125-issue283-gemini-function-response-regression.md`.

- **`[Models]` GPT Luna no longer sends a rejected `temperature` parameter (issue #285).** models.dev reports `temperature: true` for `gpt-6-luna` and `gpt-5.6-luna`, but the Go gateway rejects it. The gateway restriction now overrides live metadata, and the HTTP 400 retry classifier recognizes the `Unsupported parameter` wording. Documented in `docs/issues/123-20261125-issue285-gpt-luna-temperature.md`.

- **`[History]` Viewing figures no longer evicts most of the conversation (issue #287).** The token estimator charged base64 image data as prose, so a few screenshots inflated the prompt estimate past the 70% budget and the trimmer dropped hundreds of text messages. Images are now stripped before token measurement and charged a bounded per-image estimate, matching the byte-cap rule from #173. Documented in `docs/issues/124-20261125-issue287-image-token-accounting.md`.

- **`[Muse]` Repeated-answer loops in Muse Spark agent runs are stopped (issue #284).** Three consecutive identical assistant answers now trigger a tool-free final-answer recovery turn, using the same recovery path as the Beam tool-loop guard. Documented in `docs/issues/125-20261125-issue284-muse-repetition-guard.md`.

- **`[VS Code]` The Agent picker stays visible and the Go privacy gate is explained (issue #282).** The extension pins VS Code's experimental `agentsPickerInAttachContextMenu` setting off (and restores it on cleanup), and the training opt-in 400 now names the Console privacy setting instead of showing a bare failure. Documented in `docs/issues/126-20261125-issue282-agent-mode-picker-and-privacy.md`.

## [0.8.1] — 2026-11-10

### Added
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
**Status:** ✅ Solved
**Related issue:** [#283](https://github.com/ltmoerdani/opencode-copilot-chat/issues/283)
**Introduced by:** `ec92a44` (2026-07-20, PR #79 / issue #34)

# Gemini tool results used an invalid `functionResponse` shape

**Topic:** provider / request / google / tool-calling
**Updated:** 2026-11-25
**Tags:** #provider #google #tool-calling #regression

---

## Problem

`gemini-4-argon` on OpenCode Go returned HTTP 400 for every request after the
first tool call:

```text
Unknown name "content" at 'contents[2].parts[0].function_response': Cannot find field.
```

The same error repeated for every tool result in the conversation, so the model
could never continue an agentic session.

## Root cause

`src/request/google.ts` built tool results as
`functionResponse: { name, content }`. The official Gemini
`generateContent` reference defines `FunctionResponse` as `name` plus a
**required `response` object**; there is no top-level `content` field. Older
Gemini models tolerated the unknown field, but the strict validator on
`gemini-4-argon` rejects it.

Git history confirms a regression. Before `ec92a44` the builder emitted the
valid shape:

```diff
- functionResponse: { name, response: { name, content } }
+ functionResponse: googleFunctionResponseContent(message.content, name)
```

The helper introduced by that commit moved `content` to the top level while
adding multimodal `parts`. `b8f6b45` later moved the helper into
`src/request/google.ts` without changing the shape.

## Fix

`googleFunctionResponseContent()` now returns:

- `{ name, response: { content: text } }` for text-only tool results;
- `{ name, response: { content: text }, parts: [...] }` when the tool result
carries an image — `parts` stays at `functionResponse` level, as documented;
- `{ name, response: { content: JSON.stringify("") } }` for null content.

No top-level `content` is emitted in any branch. The RULES comment above the
helper now states the wire contract explicitly.

## Verification

- `src/test/google-function-response.test.ts` — three cases: text-only shape,
multimodal `parts` with a valid `response`, and null content. Each asserts
that `content` is absent at `functionResponse` level.
- `npm run lint` (compile + unit tests + all strict checks) passes.
54 changes: 54 additions & 0 deletions docs/issues/123-20261125-issue285-gpt-luna-temperature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
**Status:** ✅ Solved
**Related issue:** [#285](https://github.com/ltmoerdani/opencode-copilot-chat/issues/285)

# GPT Luna rejects `temperature` despite models.dev claiming support

**Topic:** models / metadata / request / provider
**Updated:** 2026-11-25
**Tags:** #models #metadata #temperature #provider #go

---

## Problem

Selecting `gpt-6-luna` or `gpt-5.6-luna` on OpenCode Go (extension 0.8.1,
VS Code 1.146) failed immediately with:

```text
OpenCode Go API request failed (HTTP 400) for gpt-6-luna:
Unsupported parameter: 'temperature' is not supported with this model.
```

## Root cause

The request builders include `temperature` unless
`metadata.temperature === false` (`src/request/openai.ts:39`,
`src/request/google.ts:42`, `src/request/anthropic.ts:48`). The default is
`0.2` (`src/provider/settings.ts:136`).

`resolveModelMetadata()` trusted live models.dev data first. The `opencode-go`
provider entry for both Luna models reports `temperature: true`, so the
parameter was always sent. `MODELS_WITHOUT_TEMPERATURE` only contained the
Kimi models, and the HTTP 400 retry classifier only recognised
`invalid temperature...` — not the gateway's `Unsupported parameter: ...`
wording, so there was no self-heal either.

This is a data mismatch, not a regression in the request builders: the
temperature guard has existed since PR #21 (0.2.7).

## Fix

- `src/models/modelTables.ts` — add `gpt-6-luna` and `gpt-5.6-luna` to
`MODELS_WITHOUT_TEMPERATURE`.
- `src/models/metadata.ts` — make that set a **gateway-level override**: it now
wins over live and cached models.dev values, not just the offline fallback.
- `src/retry.ts` — add a recoverable-400 pattern for
`Unsupported parameter: 'temperature'`, which strips the field and retries.

## Verification

- `src/test/metadata.test.ts` — fallback metadata for both Luna models reports
`temperature: false`, and a live `temperature: true` record is overridden.
- `src/test/retry.test.ts` — the gateway wording produces a patch that removes
`temperature` while preserving the rest of the body.
- `npm run lint` (compile + unit tests + all strict checks) passes.
67 changes: 67 additions & 0 deletions docs/issues/124-20261125-issue287-image-token-accounting.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
**Status:** ✅ Solved
**Related issue:** [#287](https://github.com/ltmoerdani/opencode-copilot-chat/issues/287)
**Related docs:** `75-20260821-issue173-vision-byte-cap.md`, `20-20261105-history-trim-context-notice.md`

# Base64 images inflated the token budget and evicted conversation history

**Topic:** provider / history-trim / token-estimate / vision
**Updated:** 2026-11-25
**Tags:** #provider #history-trim #vision #token-estimate #bug

---

## Problem

In a long agentic visualization session, viewing a few figures caused the
trimmer to drop 291 messages at once (455 → 168). The model then re-read files
and redid work it had already validated. The chat transcript still showed the
full history, so the reset looked like a model failure.

The reporter's log showed the extension estimating 538,239 tokens for a
request the provider counted at 91,033, while the byte check passed comfortably.
Their direct gateway probes also showed that DeepSeek/GLM/Qwen accepted prompts
well beyond the extension's 70% budget, so the trim was protecting against a
limit that did not bind.

## Root cause

`estimatePromptTokenCount()` measured `JSON.stringify(prompt)` with
`ceil(chars / 4) × 1.1`. Image parts are base64 data URLs, so a 1 MB figure was
charged roughly 393,000 "tokens" instead of the few hundred the provider
actually counts.

Issue #173 had already fixed the **byte** side by stripping image data in
`stripImageData()` before measuring `MAX_REQUEST_PAYLOAD_BYTES`. The **token**
side kept counting base64, so the two ceilings disagreed: bytes passed, tokens
failed, and the trimmer dropped the oldest text middle in one block. The
`[Context notice]` added by #274 then told the model to re-read files, which
re-added history and made the next figure trigger the same cut again.

A second inconsistency existed on the VS Code-facing side:
`estimateDataPartTokenCount()` reports `IMAGE_TOKEN_ESTIMATE = 1024` per image,
so Copilot Chat never saw the weight the extension was charging internally.

## Fix

- `src/request/shared.ts` — move `stripImageData()` out of `historyTrim.ts` and
export it together with `countImageDataParts()`, so byte and token accounting
use the same image detection.
- `src/tokenEstimate.ts` — `estimatePromptTokenCount()` now strips base64 data
URLs before the character heuristic and charges a bounded
`IMAGE_TOKEN_ESTIMATE` (1024) per stripped image. Hosted URLs remain counted
as text. `estimateMessageTokenCount()` applies the same rule to one message,
used for per-unit trim measurements.
- `src/provider/historyTrim.ts` — imports the shared helper; its contract now
states that images are excluded from both ceilings.

Because `finalTokens` also feeds `calculateModelLimits()`, this removes the
arithmetic path where an inflated prompt estimate collapsed `max_tokens` to 1
(the shape reported in #83 / `docs/issues/37-...`).

## Verification

- `src/test/tokenEstimate.test.ts` — a 400 KB base64 image yields an estimate
under 10,000 tokens instead of ~110,000.
- `src/test/messages.test.ts` — a vision-only payload no longer removes any
text history, and `finalTokens` stays near the real prompt size.
- `npm run lint` (compile + unit tests + all strict checks) passes.
58 changes: 58 additions & 0 deletions docs/issues/125-20261125-issue284-muse-repetition-guard.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
**Status:** ✅ Solved
**Related issue:** [#284](https://github.com/ltmoerdani/opencode-copilot-chat/issues/284)
**Related docs:** `91-20260903-issue207-big-pickle-repetition-loop.md`, `36-20260723-mimo-thinking-infinite-loop.md`

# Muse Spark repeated the same answer across agent turns

**Topic:** provider / tool-calling / thinking / muse
**Updated:** 2026-11-25
**Tags:** #provider #muse #tool-calling #repetition

---

## Problem

In Agent mode with `muse-spark-1.3-contributor`, the same Chinese sentence was
emitted hundreds of times, interleaved with tool calls (`Revert forced
Preinclud...`, `Remove port shim he...`, `Read Bootloader.ewp`, ...). The run
never converged.

## Root cause

This is model-level degenerate repetition, not a transport retry or a stream
duplication bug: each turn was a fresh response with the same text.

The extension had no guard for repeated **visible content**:

- `src/thinking/muse.ts` emits only `reasoning.effort`; unlike `big-pickle`
(#207) and MiMo (#36), Muse has no `repetition_penalty`.
- `src/transports/extractors.ts` suppresses repeated **reasoning** fragments
only; visible text is unaffected.
- `detectBeamToolLoop()` was gated to `beam-*` models.

## Fix

`src/toolLoopGuard.ts` gains `detectMuseRepetitionLoop()`:

- Muse-only (`/^muse-/i`);
- looks at assistant turns after the last user message, including turns with
tool calls in between;
- normalizes visible text and compares a bounded signature (200 chars, minimum
40 chars) across the last three turns;
- returns a warning when the same signature repeats three times consecutively.

`src/provider/chatPrep.ts` combines the Beam and Muse warnings into the existing
`toolLoopWarning` path. That path already appends a recovery instruction and
drops `tools` from the request for that turn (`OpenCodeProvider.ts:339`), so the
model is forced to produce a tool-free final answer instead of continuing the
loop. The log tag is now the generic `[loop-guard]`.

The guard is deliberately conservative: short answers and varying text never
fire, and non-Muse models are untouched.

## Verification

- `src/test/toolLoopGuard.test.ts` — three consecutive identical Muse answers
with tool calls between them trigger the guard; two repeats, varying answers,
short answers, and non-Muse models do not.
- `npm run lint` (compile + unit tests + all strict checks) passes.
65 changes: 65 additions & 0 deletions docs/issues/126-20261125-issue282-agent-mode-picker-and-privacy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
**Status:** ✅ Solved
**Related issue:** [#282](https://github.com/ltmoerdani/opencode-copilot-chat/issues/282)
**Upstream:** [microsoft/vscode#346223](https://github.com/microsoft/vscode/issues/346223) (closed, by design)

# Agent mode: hidden picker and a misleading 400 error

**Topic:** vscode / agents-window / errors / provider
**Updated:** 2026-11-25
**Tags:** #vscode #agents-window #errors #provider

---

## Problem

The reporter had three separate symptoms in one issue:

1. Switching to Agent mode made the "Set agent" dropdown disappear.
2. No `Agent.md` file/folder existed in
`%AppData%\Code\User\globalStorage\github.copilot-chat`.
3. Sending a prompt failed with HTTP 400 for `iceman-contributor-free`:
_"This Go model trains on request data. Turn on 'Allow paid endpoints that
train on request data'..."_

## Analysis

- The hidden picker is a VS Code 1.145 change: the experimental setting
`sessions.chat.experimental.agentsPickerInAttachContextMenu` moves the picker
into the `+` menu. Upstream closed #346223 as by design; the workaround is to
pin the setting to `false`. The setting and its `experiment: { mode: "auto" }`
registration are present in the local VS Code bundle, confirming why some
users get it without opting in.
- Custom agents are a VS Code/Copilot feature (`.github/agents/*.agent.md` or
the Agent Customizations editor). This extension never creates them; there is
no `Agent.md` reference anywhere in `src/`.
- The 400 is a Go workspace privacy gate, not an Agent-mode failure. The log
was from extension 0.7.11 while the report said 0.8.0. The gateway message
already contains a Console URL, but Copilot Chat renders only the short
reason, so users saw "Sorry, your request failed" with no next step.

## Fix

- `src/config.ts` — new setting key and globalState marker for the picker
experiment.
- `src/commands/agentsWindow.ts` — `ensureAgentsWindowSupport()` now pins
`sessions.chat.experimental.agentsPickerInAttachContextMenu` to `false`
alongside the existing `extensions.supportAgentsWindow` and
`chat.agentHost.byokModels.enabled` settings. `revertAgentsWindowSupport()`
restores it (only when the extension set it, unless `force` is used). A
window reload is still required, and the existing notification covers it.
- `src/errors.ts` — `describeTrainingOptInRestriction()` converts the Go
training opt-in rejection into an actionable message naming the exact
Console privacy setting. It is included in both the chat-visible `message`
and the toast `userMessage`; the raw gateway URL stays in the Output channel.

## Verification

- `src/test/errors.test.ts` — the new hint matches the gateway wording, does
not fire on unrelated errors, and reaches both error surfaces.
- `npm run lint` (compile + unit tests + all strict checks) passes.

## User guidance

Custom agents are created through **Chat: Open Customizations → Agents → New
Agent** or by adding `.github/agents/<name>.agent.md` to the workspace. The
extension does not generate those files.
55 changes: 55 additions & 0 deletions docs/issues/127-20261125-issue286-console-sign-in.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
**Status:** ✅ Solved
**Related issue:** [#286](https://github.com/ltmoerdani/opencode-copilot-chat/issues/286)
**Related memory:** `opencode-auth-research.md`

# Sign in with OpenCode Console without manually copying a key

**Topic:** auth / byok / provider / vscode
**Updated:** 2026-11-25
**Tags:** #auth #byok #provider #vscode

---

## Problem

The request was to sign in with OpenCode Console the way `/connect` works in
the OpenCode CLI, so users would not have to enter an API key manually.

## Research

Official OpenCode docs (`/console/go`, `/console/api`, `/cli/providers`) show
that `/connect` for **OpenCode Go still asks for an API key**. OAuth in
`/connect` applies to other providers (ChatGPT/Codex, GitHub Copilot, Azure).
The Console API issues personal or service keys (`oc_sk_...`); there is no
documented third-party OAuth flow for Go.

The OpenCode CLI does save that key locally. On this machine the SQLite store
`~/.local/share/opencode/opencode.db` has a `credential` table with an
`opencode-go` row whose `value` is the API key. The extension already reads the
same database read-only for usage history (`src/usage/history.ts`), so the
credential can be imported with the user's explicit consent instead of being
scraped silently.

## Fix

- `src/openCodeConsoleCredential.ts` — node-only helper that reads the
`opencode-go` credential from the CLI database using `node:sqlite`, falling
back to the `sqlite3` binary. `parseCredentialRows()` accepts both row
shapes. The key is returned to the caller and never logged; read failures
degrade to `undefined`.
- `src/commands/consoleSignIn.ts` — new command
**OpenCode Go: Sign In with OpenCode Console**:
- if a CLI key exists, ask "Import?" with **Import / Open Console / Cancel**;
- otherwise open the Console personal-API-keys page and prompt for the key;
- store the key in VS Code SecretStorage under `secretKeyFor(GO_VENDOR)` and
refresh the model list.
- `src/extension.ts` / `package.json` — command registration and title.

No Console session cookie or OAuth token is handled, and no undocumented RPC
endpoint is used. The user always confirms before a key is copied.

## Verification

- `src/test/openCodeConsoleCredential.test.ts` — both SQLite row shapes, empty
values, and the Console URL.
- `npm run lint` (compile + unit tests + all strict checks) passes.
Loading
Loading