opencode-ghost 1.3.6 → 1.3.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,18 @@ All notable changes to this project are documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.3.8] - 2026-10-11
9
+
10
+ ### Fixed
11
+
12
+ - **tui:** Retry model-unavailable replies while the server catalog loads
13
+
14
+ ## [1.3.7] - 2026-10-10
15
+
16
+ ### Fixed
17
+
18
+ - **tui:** Center diagnostics and constrain scrollable dialog height
19
+
8
20
  ## [1.3.6] - 2026-10-10
9
21
 
10
22
  ### Fixed
@@ -283,6 +295,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
283
295
  - Options for `model`, `acceptKeys`, `maxChars`, `idleDelayMs`,
284
296
  `recentMessages` and `system`.
285
297
 
298
+ [1.3.8]: https://github.com/ozandogrultan/opencode-ghost/compare/v1.3.7...v1.3.8
299
+ [1.3.7]: https://github.com/ozandogrultan/opencode-ghost/compare/v1.3.6...v1.3.7
286
300
  [1.3.6]: https://github.com/ozandogrultan/opencode-ghost/compare/v1.3.5...v1.3.6
287
301
  [1.3.5]: https://github.com/ozandogrultan/opencode-ghost/compare/v1.3.4...v1.3.5
288
302
  [1.3.4]: https://github.com/ozandogrultan/opencode-ghost/compare/v1.3.3...v1.3.4
package/README.md CHANGED
@@ -29,11 +29,28 @@ a dimmed inline placeholder in the empty composer with
29
29
  ## Requirements
30
30
 
31
31
  - [opencode](https://opencode.ai) v2 (TUI plugins; tested against 2.0.25).
32
- - A provider/model that supports the stateless generation endpoint, or set `model` explicitly.
32
+ - A provider/model and authentication method that support OpenCode's stateless
33
+ `generate.text` endpoint. Set `model` explicitly if no default small model is available.
33
34
 
34
35
  ## Install
35
36
 
36
- ### From this repo (recommended)
37
+ ### From npm (recommended)
38
+
39
+ Add the package to your `cli.json` (normally `~/.config/opencode/cli.json`):
40
+
41
+ ```jsonc
42
+ {
43
+ "$schema": "https://opencode.ai/v2/cli.json",
44
+ "plugins": ["opencode-ghost"]
45
+ }
46
+ ```
47
+
48
+ Then **restart opencode**; it installs the package on startup. Pin a version
49
+ with `"opencode-ghost@1.3.7"`, or change the version and restart to update.
50
+ Pass options with the object form shown under [Manually](#manually), using
51
+ `"package": "opencode-ghost"`.
52
+
53
+ ### From this repo
37
54
 
38
55
  ```sh
39
56
  git clone https://github.com/ozandogrultan/opencode-ghost.git
@@ -41,15 +58,24 @@ cd opencode-ghost
41
58
  ./install.sh
42
59
  ```
43
60
 
44
- Then **restart opencode** — plugins are loaded at startup only. `install.sh`
61
+ Then **restart opencode** to load the installed copy. `install.sh`
45
62
  copies the plugin into `<config>/plugins/opencode-ghost/` and registers it in
46
- `<config>/cli.json`, migrating an existing v1 `tui.json` registration (and its
63
+ `<config>/cli.json`, migrating an existing v1 `tui.json` or `tui.jsonc` registration (and its
47
64
  options) if one is found.
48
65
  Removed options (`apiKey`, `endpoint`, `internalSessionMarkerDir`, `argHints`)
49
66
  are stripped from Ghost registrations. Other configuration is preserved.
50
67
  The installer accepts JSON objects only; JSONC or invalid configuration is
51
68
  left intact along with the installed sources and requires manual registration
52
- using the snippet below. Node is required for the installer.
69
+ using the snippet below. An unrelated, unparseable legacy TUI config is skipped.
70
+ Node is required for the installer; automatic config discovery also requires
71
+ `opencode` on `PATH`.
72
+
73
+ The default target comes from `opencode debug paths`, falling back to
74
+ `$XDG_CONFIG_HOME/opencode` or `~/.config/opencode`. Pass one or more config
75
+ directories explicitly with `./install.sh /path/to/config`; `./install.sh --all`
76
+ also targets an existing `~/.config/opencode` directory. After pulling updates,
77
+ rerun the installer and restart opencode. A manual registration pointing at the
78
+ repo's `src` only needs a restart.
53
79
 
54
80
  ### Manually
55
81
 
@@ -59,6 +85,7 @@ directory containing this file; a project's `.opencode/cli.json` is not loaded.
59
85
 
60
86
  ```jsonc
61
87
  {
88
+ "$schema": "https://opencode.ai/v2/cli.json",
62
89
  "plugins": ["/absolute/path/to/opencode-ghost/src"]
63
90
  }
64
91
  ```
@@ -67,10 +94,11 @@ Pass options with the object form:
67
94
 
68
95
  ```jsonc
69
96
  {
97
+ "$schema": "https://opencode.ai/v2/cli.json",
70
98
  "plugins": [
71
99
  {
72
100
  "package": "/absolute/path/to/opencode-ghost/src",
73
- "options": { "model": "openai/gpt-6-luna-fast" }
101
+ "options": { "model": "openai/gpt-6-luna-fast" }
74
102
  }
75
103
  ]
76
104
  }
@@ -127,12 +155,15 @@ Like OpenCode's title generation, an override, title or small model without a
127
155
  configured variant uses its first supported `none`, `minimal` or `low` variant.
128
156
  Catalog IDs are used directly. The model catalog is cached for five minutes
129
157
  (cleared by `/suggest model` and re-enabling, and refetched once before reporting
130
- no small model); the agent list is read on every generation. No matching small
158
+ no small model when a cached catalog has no match); the agent list is read on
159
+ each default-model resolution. No matching small
131
160
  model means a warning and no suggestion. Ghost never uses the main model as a generation fallback or retries
132
161
  with another provider. An explicit override or configured title model may use
133
162
  a different provider from the session's primary model.
134
163
 
135
- When enabling, a suggestion is generated immediately for the current session.
164
+ When re-enabling with `/suggest`, generation starts without the debounce for the
165
+ current idle session if it has conversation text. Loading the plugin or switching
166
+ sessions does not itself generate a suggestion.
136
167
 
137
168
  ## How it works
138
169
 
@@ -156,15 +187,17 @@ When enabling, a suggestion is generated immediately for the current session.
156
187
 
157
188
  ## Debugging
158
189
 
159
- Ghost records every generation attempt to a bounded in-memory history (the last
190
+ Ghost records generation outcomes in a bounded in-memory history (the last
160
191
  20): outcome (`ok`, `empty`, `echo`, `no model`, `error`, `aborted`), the resolved
161
192
  model with its variant, total latency, message-sync/model-resolution/generation
162
193
  stage timings, suggestion length and error detail. Latency excludes the debounce;
163
194
  only reached stages are recorded, including failures and cancellations. `/suggest log`
164
195
  shows it in a dialog at any time; `aborted` covers attempts cancelled by typing,
165
196
  a newer turn, leaving the session, disabling or unload, so a missing suggestion can
166
- be traced to a debounce, an empty or `NONE` reply, an echo filter, or a provider
167
- error. `/suggest debug` toggles the same data as a toast on each attempt (aborts
197
+ be traced to an empty or `NONE` reply, an echo filter, or a provider
198
+ error. Cancelled debounces and runs skipped for lack of conversation text or an
199
+ ineligible session have no generation entry. `/suggest debug`
200
+ toggles the same data as a toast on each recorded outcome (aborts
168
201
  are logged but not toasted). The history is not written to disk.
169
202
 
170
203
  When a generation is `ok` but nothing is visible, `/suggest log` also shows the
@@ -193,24 +226,33 @@ section also reports focus, keymap mode and the placeholder colour. With
193
226
  OpenTUI's public pre-render callback; host renderer changes need re-verification.
194
227
  - **Key fallthrough.** Without an eligible ghost, Tab/Right fall through to
195
228
  the host. OpenCode V2's default agent-cycle shortcut is Shift+Tab.
196
- - **Cost.** One model call per turn while enabled. Point `model` at a cheap or
197
- free model.
198
- - **Provider compatibility.** OpenAI and google-vertex generation worked in
199
- verification. Anthropic's stateless endpoint failed with plugin-auth OAuth
200
- in verification; choose a supported provider/model. Luna 6.1 is not available.
201
- - Generation errors show one warning toast per plugin load with the model
202
- override command. Aborts and `NONE` replies produce no warning or preview.
203
- - Effective agents and catalogs are read per generation for the session's
204
- location. The stateless endpoint has no location argument; project-only models
229
+ - **Cost.** At most one generation call per debounced completion in the visible,
230
+ idle session. Re-enabling can make an additional call. Point `model` at a cheap
231
+ or free model.
232
+ - **Provider compatibility.** Stateless generation support depends on the
233
+ provider, model and authentication method; normal session generation support
234
+ does not guarantee compatibility. Use `/suggest log` to inspect failures and
235
+ `/suggest model provider/model` to choose a supported model.
236
+ - Generation errors show a warning toast with the model override command,
237
+ once per plugin load or since the last `/suggest model` change. Message-sync
238
+ failures have a separate once-per-load warning. Aborts and `NONE` replies
239
+ produce no warning or preview.
240
+ - Model resolution uses the session's location and a location-scoped catalog
241
+ cache. Default-model resolution also reads effective agents. The stateless
242
+ endpoint has no location argument; project-only models
205
243
  may fail server-global resolution. Invalid overrides and provider failures warn
206
- without retrying through another provider or a session.
244
+ without retrying through another provider or a session. A "Model unavailable"
245
+ reply is retried on the same model with backoff (1s to 8s), since the server
246
+ catalog can still be loading right after startup.
207
247
 
208
248
  ## Development
209
249
 
210
250
  ```sh
211
251
  bun install
212
- bun run typecheck
213
252
  bun run test
253
+ bun run typecheck
254
+ bun run lint:sh
255
+ bash scripts/changelog.sh check
214
256
  ```
215
257
 
216
258
  No build step: like other opencode TUI plugins, the package ships TSX source and
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-ghost",
3
- "version": "1.3.6",
3
+ "version": "1.3.8",
4
4
  "description": "Stateless inline next-prompt ghosts for the empty OpenCode V2 composer, accepted with Tab or Right.",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/stateless.ts CHANGED
@@ -9,6 +9,26 @@ export type GenerateClient = {
9
9
  }
10
10
  }
11
11
 
12
+ export const MODEL_UNAVAILABLE_RETRY_MS: readonly number[] = [1000, 2000, 4000, 8000]
13
+
14
+ function isModelUnavailable(error: unknown): boolean {
15
+ const message = (error as { message?: unknown } | null)?.message
16
+ return typeof message === "string" && /^Model unavailable:/.test(message)
17
+ }
18
+
19
+ function pause(ms: number, signal: AbortSignal): Promise<void> {
20
+ return new Promise((resolve) => {
21
+ if (signal.aborted) return resolve()
22
+ const done = () => {
23
+ clearTimeout(timer)
24
+ signal.removeEventListener("abort", done)
25
+ resolve()
26
+ }
27
+ const timer = setTimeout(done, ms)
28
+ signal.addEventListener("abort", done)
29
+ })
30
+ }
31
+
12
32
  export async function generateSuggestion(
13
33
  client: GenerateClient,
14
34
  prompt: string,
@@ -16,15 +36,21 @@ export async function generateSuggestion(
16
36
  signal: AbortSignal,
17
37
  onError?: (error: unknown) => void,
18
38
  allowed: () => boolean = () => true,
39
+ retryDelays: readonly number[] = MODEL_UNAVAILABLE_RETRY_MS,
19
40
  ): Promise<string | undefined> {
20
41
  try {
21
42
  const resolved = await model
22
43
  if (signal.aborted || !allowed() || !resolved) return undefined
23
- const result = await client.generate.text(
24
- { prompt, model: { id: resolved.modelID, providerID: resolved.providerID, ...(resolved.variant ? { variant: resolved.variant } : {}) } },
25
- { signal },
26
- )
27
- return result.text
44
+ const input = { prompt, model: { id: resolved.modelID, providerID: resolved.providerID, ...(resolved.variant ? { variant: resolved.variant } : {}) } }
45
+ for (let attempt = 0; ; attempt++) {
46
+ try {
47
+ return (await client.generate.text(input, { signal })).text
48
+ } catch (error) {
49
+ if (!isModelUnavailable(error) || attempt >= retryDelays.length) throw error
50
+ await pause(retryDelays[attempt]!, signal)
51
+ if (signal.aborted || !allowed()) return undefined
52
+ }
53
+ }
28
54
  } catch (error) {
29
55
  if (!signal.aborted) onError?.(error)
30
56
  return undefined
package/src/tui.tsx CHANGED
@@ -1,6 +1,7 @@
1
1
  /** @jsxImportSource @opentui/solid */
2
2
  import { Plugin } from "@opencode/plugin/tui"
3
3
  import { TextareaRenderable, InputRenderable, type BoxRenderable, type Renderable } from "@opentui/core"
4
+ import { useTerminalDimensions } from "@opentui/solid"
4
5
  import { createEffect, createMemo, createRoot, createSignal, on, onCleanup } from "solid-js"
5
6
  import { composerAction, composerBlocker, isEmptyComposer, keyName, locateComposerEditor, observeComposerInput, removesOnly, type ComposerLookup } from "./composer"
6
7
  import { createDiagnostics, errorDetail, formatDiagnostic, formatDiagnostics, modelLabel, type DiagnosticEntry, type StageTimings } from "./diagnostics"
@@ -323,10 +324,22 @@ export default Plugin.define({
323
324
  `mode ${context.keymap.mode.current()}`,
324
325
  `color rgba(${[color.r, color.g, color.b, color.a].map((value) => value.toFixed(2)).join(", ")})`,
325
326
  ].join("\n")
326
- void context.ui.dialog.alert({
327
- title: "Ghost — diagnostics",
328
- message: `${summary}\n\nNow\n${live}\n\nDisplay changes\n${displayLog.list().length ? formatDiagnostics(displayLog.list()) : "None recorded yet."}\n\nGenerations\n${formatDiagnostics(diagnostics.list())}`,
329
- })
327
+ const message = `${summary}\n\nNow\n${live}\n\nDisplay changes\n${displayLog.list().length ? formatDiagnostics(displayLog.list()) : "None recorded yet."}\n\nGenerations\n${formatDiagnostics(diagnostics.list())}`
328
+ context.ui.dialog.set({ size: "large", centered: true })
329
+ context.ui.dialog.show(() => {
330
+ const dimensions = useTerminalDimensions()
331
+ return (
332
+ <box id="ghost-diagnostics" width="100%" paddingX={2} paddingY={1} gap={1}>
333
+ <box flexDirection="row" justifyContent="space-between" flexShrink={0}>
334
+ <text fg={context.theme.text.base}><b>Ghost — diagnostics</b></text>
335
+ <text fg={context.theme.text.muted}>esc</text>
336
+ </box>
337
+ <scrollbox id="ghost-diagnostics-scroll" height={Math.max(1, Math.min(28, dimensions().height - 8))} flexShrink={0} focused scrollX={false} scrollY>
338
+ <text id="ghost-diagnostics-body" fg={context.theme.text.base} wrapMode="word" content={message} />
339
+ </scrollbox>
340
+ </box>
341
+ )
342
+ })
330
343
  return
331
344
  }
332
345
  if (command.type === "invalid") {