opencode-ghost 1.3.5 → 1.3.7

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.7] - 2026-10-10
9
+
10
+ ### Fixed
11
+
12
+ - **tui:** Center diagnostics and constrain scrollable dialog height
13
+
14
+ ## [1.3.6] - 2026-10-10
15
+
16
+ ### Fixed
17
+
18
+ - **tui:** Report generation stage timings and request bounded responses
19
+
8
20
  ## [1.3.5] - 2026-10-10
9
21
 
10
22
  ### Fixed
@@ -277,6 +289,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
277
289
  - Options for `model`, `acceptKeys`, `maxChars`, `idleDelayMs`,
278
290
  `recentMessages` and `system`.
279
291
 
292
+ [1.3.7]: https://github.com/ozandogrultan/opencode-ghost/compare/v1.3.6...v1.3.7
293
+ [1.3.6]: https://github.com/ozandogrultan/opencode-ghost/compare/v1.3.5...v1.3.6
280
294
  [1.3.5]: https://github.com/ozandogrultan/opencode-ghost/compare/v1.3.4...v1.3.5
281
295
  [1.3.4]: https://github.com/ozandogrultan/opencode-ghost/compare/v1.3.3...v1.3.4
282
296
  [1.3.3]: https://github.com/ozandogrultan/opencode-ghost/compare/v1.3.2...v1.3.3
package/README.md CHANGED
@@ -88,11 +88,16 @@ copy, use `/absolute/path/to/config/plugins/opencode-ghost`.
88
88
  | `enabled` | `boolean` | `true` | Initial state; `/suggest` toggles it at runtime (persisted). |
89
89
  | `model` | `string` | OpenCode small default | Explicit `provider/model` override. Otherwise uses the effective title-agent model or OpenCode's small-model selection policy. |
90
90
  | `acceptKeys` | `string[]` | `["tab", "right"]` | Key names as reported by the terminal (`tab`, `right`, ...). Modifier aliases (`meta`, `option`, `cmd`, `control`) are normalised; keys with unknown modifiers are ignored. |
91
- | `maxChars` | `number` | `120` | Maximum suggestion length. |
91
+ | `maxChars` | `number` | `120` | Requested response character budget and maximum displayed suggestion length. |
92
92
  | `idleDelayMs` | `number` | `500` | Debounce after a turn finishes before generating. |
93
93
  | `recentMessages` | `number` | `10` | How many recent messages feed the suggestion prompt. |
94
94
  | `system` | `string` | built-in | Override the system prompt sent to the suggestion model. |
95
95
 
96
+ `maxChars` is included as a soft character budget in every generation prompt,
97
+ including custom `system` prompts. OpenCode's experimental `generate.text` API
98
+ has no output-token limit; the model can exceed the requested budget. Ghost
99
+ still enforces `maxChars` when normalizing the displayed suggestion.
100
+
96
101
  ## Commands
97
102
 
98
103
  - `/suggest` — toggle suggestions on/off (persisted).
@@ -104,7 +109,7 @@ copy, use `/absolute/path/to/config/plugins/opencode-ghost`.
104
109
  the error.
105
110
  - `/suggest debug on` / `/suggest debug off` — set debug mode explicitly.
106
111
  - `/suggest log` — show the last 20 generation attempts (outcome, model,
107
- latency, length and error detail) in a dialog, regardless of debug mode.
112
+ total and stage latency, length and error detail) in a dialog, regardless of debug mode.
108
113
 
109
114
  Model precedence is the persisted `/suggest model` override, then the `model`
110
115
  option, then the effective title agent's model from OpenCode's public agent API.
@@ -153,7 +158,9 @@ When enabling, a suggestion is generated immediately for the current session.
153
158
 
154
159
  Ghost records every generation attempt to a bounded in-memory history (the last
155
160
  20): outcome (`ok`, `empty`, `echo`, `no model`, `error`, `aborted`), the resolved
156
- model with its variant, latency, suggestion length and error detail. `/suggest log`
161
+ model with its variant, total latency, message-sync/model-resolution/generation
162
+ stage timings, suggestion length and error detail. Latency excludes the debounce;
163
+ only reached stages are recorded, including failures and cancellations. `/suggest log`
157
164
  shows it in a dialog at any time; `aborted` covers attempts cancelled by typing,
158
165
  a newer turn, leaving the session, disabling or unload, so a missing suggestion can
159
166
  be traced to a debounce, an empty or `NONE` reply, an echo filter, or a provider
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-ghost",
3
- "version": "1.3.5",
3
+ "version": "1.3.7",
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",
@@ -1,11 +1,14 @@
1
1
  export type DiagnosticOutcome = "ok" | "empty" | "echo" | "unavailable" | "error" | "aborted" | "shown" | "hidden"
2
2
 
3
+ export type StageTimings = { syncMs?: number; modelMs?: number; generationMs?: number }
4
+
3
5
  export type DiagnosticEntry = {
4
6
  readonly at: number
5
7
  readonly sessionID: string
6
8
  readonly outcome: DiagnosticOutcome
7
9
  readonly model?: string
8
10
  readonly durationMs?: number
11
+ readonly stages?: Readonly<StageTimings>
9
12
  readonly chars?: number
10
13
  readonly detail?: string
11
14
  }
@@ -68,7 +71,9 @@ export function formatDiagnostic(entry: DiagnosticEntry): string {
68
71
  const parts = [clockTime(entry.at), OUTCOME_LABELS[entry.outcome], entry.model ?? "—"]
69
72
  if (entry.durationMs !== undefined) parts.push(`${entry.durationMs}ms`)
70
73
  if (entry.chars !== undefined) parts.push(`${entry.chars} chars`)
71
- const line = parts.join(" ")
74
+ const stages = [["sync", entry.stages?.syncMs], ["model", entry.stages?.modelMs], ["generation", entry.stages?.generationMs]] as const
75
+ const timing = stages.filter(([, ms]) => ms !== undefined).map(([name, ms]) => `${name} ${ms}ms`).join(", ")
76
+ const line = parts.join(" ") + (timing ? `\n ${timing}` : "")
72
77
  return entry.detail ? `${line}\n ${entry.detail}` : line
73
78
  }
74
79
 
package/src/transcript.ts CHANGED
@@ -39,6 +39,6 @@ export function lastUserText(messages: readonly TranscriptMessage[]): string {
39
39
  return ""
40
40
  }
41
41
 
42
- export function suggestionPrompt(system: string, transcript: string): string {
43
- return `${system}\n\n${transcript}`
42
+ export function suggestionPrompt(system: string, transcript: string, maxChars: number): string {
43
+ return `${system}\n\n${transcript}\n\nReturn one line of at most ${maxChars} characters. If no suggestion is appropriate, return NONE. Do not include explanations.`
44
44
  }
package/src/tui.tsx CHANGED
@@ -1,9 +1,10 @@
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
- import { createDiagnostics, errorDetail, formatDiagnostic, formatDiagnostics, modelLabel, type DiagnosticEntry } from "./diagnostics"
7
+ import { createDiagnostics, errorDetail, formatDiagnostic, formatDiagnostics, modelLabel, type DiagnosticEntry, type StageTimings } from "./diagnostics"
7
8
  import { createLifecycle } from "./lifecycle"
8
9
  import { acceptCommand, acceptShortcuts, ghostBaseLayer, ghostSuggestLayer } from "./keymap"
9
10
  import { parseSuggestCommand, removedOptionKeys, resolveOptions, suggestionModel } from "./options"
@@ -80,11 +81,22 @@ export default Plugin.define({
80
81
  if (!canGenerate(sessionID)) return
81
82
  const started = Date.now()
82
83
  const elapsed = () => Date.now() - started
84
+ const stages: StageTimings = {}
85
+ const measure = async <T,>(stage: keyof StageTimings, run: () => Promise<T>): Promise<T> => {
86
+ const start = Date.now()
87
+ try {
88
+ return await run()
89
+ } finally {
90
+ stages[stage] = Date.now() - start
91
+ }
92
+ }
93
+ const noteGeneration = (entry: Omit<DiagnosticEntry, "at" | "sessionID" | "durationMs" | "stages">) =>
94
+ note({ ...entry, sessionID, durationMs: elapsed(), stages: { ...stages } })
83
95
  let model: SuggestionModel | undefined
84
96
  let failure: unknown
85
97
  let syncing = true
86
98
  try {
87
- await context.data.session.message.sync(sessionID)
99
+ await measure("syncMs", () => context.data.session.message.sync(sessionID))
88
100
  syncing = false
89
101
  if (signal.aborted || !canGenerate(sessionID)) return
90
102
  const messages = context.data.session.message.list(sessionID) as readonly TranscriptMessage[]
@@ -93,43 +105,43 @@ export default Plugin.define({
93
105
  const session = context.data.session.get(sessionID)
94
106
  const location = session?.location ?? context.location ?? context.data.location.default()
95
107
  const explicit = suggestionModel(state.model, opts.model)
96
- model = explicit
97
- ? await resolveExplicitModel(context.client, location, signal, explicit, catalog)
98
- : await resolveSmallModel(context.client, location, signal, session, catalog)
108
+ model = await measure("modelMs", () => explicit
109
+ ? resolveExplicitModel(context.client, location, signal, explicit, catalog)
110
+ : resolveSmallModel(context.client, location, signal, session, catalog))
99
111
  if (signal.aborted || !canGenerate(sessionID)) return
100
112
  if (!model) return
101
- const raw = await generateSuggestion(
113
+ const raw = await measure("generationMs", () => generateSuggestion(
102
114
  context.client,
103
- suggestionPrompt(opts.system, transcript),
115
+ suggestionPrompt(opts.system, transcript, opts.maxChars),
104
116
  model,
105
117
  signal,
106
118
  (error) => { failure = error; warnGeneration(error) },
107
119
  () => canGenerate(sessionID),
108
- )
120
+ ))
109
121
  const label = modelLabel(model)
110
122
  if (signal.aborted) return
111
123
  if (failure) {
112
- note({ sessionID, outcome: "error", model: label, durationMs: elapsed(), detail: errorDetail(failure) })
124
+ noteGeneration({ outcome: "error", model: label, detail: errorDetail(failure) })
113
125
  return
114
126
  }
115
127
  if (!raw) {
116
128
  if (!canGenerate(sessionID)) return
117
- note({ sessionID, outcome: "empty", model: label, durationMs: elapsed() })
129
+ noteGeneration({ outcome: "empty", model: label })
118
130
  return
119
131
  }
120
132
  const clean = normalize(raw, opts.maxChars)
121
133
  if (!clean) {
122
- note({ sessionID, outcome: "empty", model: label, durationMs: elapsed(), chars: raw.length })
134
+ noteGeneration({ outcome: "empty", model: label, chars: raw.length })
123
135
  return
124
136
  }
125
137
  const previous = lastUserText(messages)
126
138
  if (previous && isEcho(clean, previous)) {
127
- note({ sessionID, outcome: "echo", model: label, durationMs: elapsed(), chars: clean.length })
139
+ noteGeneration({ outcome: "echo", model: label, chars: clean.length })
128
140
  return
129
141
  }
130
142
  if (!canGenerate(sessionID)) return
131
143
  setSuggestion({ sessionID, text: clean })
132
- note({ sessionID, outcome: "ok", model: label, durationMs: elapsed(), chars: clean.length })
144
+ noteGeneration({ outcome: "ok", model: label, chars: clean.length })
133
145
  } catch (error) {
134
146
  if (signal.aborted) return
135
147
  if (syncing) {
@@ -138,15 +150,13 @@ export default Plugin.define({
138
150
  context.ui.toast.show({ title: "Ghost", message: "Suggestions unavailable: session messages could not sync.", variant: "warning" })
139
151
  }
140
152
  } else warnGeneration(error)
141
- note({
142
- sessionID,
153
+ noteGeneration({
143
154
  outcome: isNoSmallModel(error) ? "unavailable" : "error",
144
155
  ...(model ? { model: modelLabel(model) } : {}),
145
- durationMs: elapsed(),
146
156
  detail: errorDetail(error),
147
157
  })
148
158
  } finally {
149
- if (signal.aborted) note({ sessionID, outcome: "aborted", ...(model ? { model: modelLabel(model) } : {}), durationMs: elapsed() })
159
+ if (signal.aborted) noteGeneration({ outcome: "aborted", ...(model ? { model: modelLabel(model) } : {}) })
150
160
  }
151
161
  }
152
162
 
@@ -314,10 +324,22 @@ export default Plugin.define({
314
324
  `mode ${context.keymap.mode.current()}`,
315
325
  `color rgba(${[color.r, color.g, color.b, color.a].map((value) => value.toFixed(2)).join(", ")})`,
316
326
  ].join("\n")
317
- void context.ui.dialog.alert({
318
- title: "Ghost — diagnostics",
319
- 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())}`,
320
- })
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
+ })
321
343
  return
322
344
  }
323
345
  if (command.type === "invalid") {