opencode-ghost 1.3.4 → 1.3.6

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,19 @@ 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.6] - 2026-10-10
9
+
10
+ ### Fixed
11
+
12
+ - **tui:** Report generation stage timings and request bounded responses
13
+
14
+ ## [1.3.5] - 2026-10-10
15
+
16
+ ### Fixed
17
+
18
+ - **tui:** Clean up theme subscriptions and handle cancelled generations
19
+ - **tui:** Handle suggestion acceptance and source registrations safely
20
+
8
21
  ## [1.3.4] - 2026-10-09
9
22
 
10
23
  ### Fixed
@@ -270,6 +283,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
270
283
  - Options for `model`, `acceptKeys`, `maxChars`, `idleDelayMs`,
271
284
  `recentMessages` and `system`.
272
285
 
286
+ [1.3.6]: https://github.com/ozandogrultan/opencode-ghost/compare/v1.3.5...v1.3.6
287
+ [1.3.5]: https://github.com/ozandogrultan/opencode-ghost/compare/v1.3.4...v1.3.5
273
288
  [1.3.4]: https://github.com/ozandogrultan/opencode-ghost/compare/v1.3.3...v1.3.4
274
289
  [1.3.3]: https://github.com/ozandogrultan/opencode-ghost/compare/v1.3.2...v1.3.3
275
290
  [1.3.2]: https://github.com/ozandogrultan/opencode-ghost/compare/v1.3.1...v1.3.2
package/README.md CHANGED
@@ -87,12 +87,17 @@ copy, use `/absolute/path/to/config/plugins/opencode-ghost`.
87
87
  | ---------------- | ---------- | ------------------- | ------------------------------------------------------------- |
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
- | `acceptKeys` | `string[]` | `["tab", "right"]` | Key names as reported by the terminal (`tab`, `right`, ...). Modifier aliases (`meta`, `option`, `cmd`, `control`) are normalised; unknown modifiers are ignored. |
91
- | `maxChars` | `number` | `120` | Maximum suggestion length. |
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` | 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.
@@ -143,7 +148,7 @@ When enabling, a suggestion is generated immediately for the current session.
143
148
  ownership. Host hint/color updates are retained while the ghost is visible;
144
149
  dismissal restores only values still owned by Ghost, including rich hints.
145
150
  - Accepting uses the composer editor's `insertText` directly, without submitting.
146
- - Typing, pasting, navigation, a new execution, disabling and unloading cancel
151
+ - Typing, pasting, undo/redo, leaving the session, a new execution, disabling and unloading cancel
147
152
  pending generation. Duplicate completion events do not generate again.
148
153
  - Retains only one suggestion, bounded by `maxChars`, for the visible session.
149
154
  Acceptance, a new turn, session changes, disabling, model changes and unloading
@@ -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.4",
3
+ "version": "1.3.6",
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/composer.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import type { KeyEvent, KeyHandler, TextareaRenderable } from "@opentui/core"
2
2
 
3
3
  export function editsComposer(event: { name: string; sequence: string; ctrl: boolean; meta: boolean; option?: boolean; super?: boolean; hyper?: boolean }): boolean {
4
- if (event.ctrl && !event.meta && !event.option && !event.super && !event.hyper) return ["v", "h", "d", "k", "u", "w", "j", "m"].includes(event.name)
4
+ if (event.ctrl && !event.meta && !event.option && !event.super && !event.hyper) return ["v", "h", "d", "k", "u", "w", "j", "m", "-", "."].includes(event.name)
5
+ if (event.super && !event.ctrl && !event.meta && !event.option && !event.hyper && event.name === "z") return true
5
6
  if (event.ctrl || event.meta || event.option || event.super || event.hyper) return false
6
7
  if (["return", "enter", "linefeed", "backspace", "delete", "space"].includes(event.name)) return true
7
8
  return [...event.sequence].length === 1 && !/[\u0000-\u001f\u007f]/.test(event.sequence)
@@ -84,11 +85,8 @@ export function composerAction(editor: Editor | undefined, focused: () => unknow
84
85
  if (editor.plainText.length !== 0) return false
85
86
  try {
86
87
  editor.insertText(text)
87
- if (editor.plainText !== text) return false
88
- return true
89
- } catch {
90
- return false
91
- }
88
+ } catch {}
89
+ return true
92
90
  }
93
91
 
94
92
  export function keyName(event: { name: string; ctrl: boolean; meta: boolean; shift: boolean; option?: boolean; super?: boolean; hyper?: boolean }): string {
@@ -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/options.ts CHANGED
@@ -57,7 +57,7 @@ const DEFAULTS = {
57
57
  recentMessages: 10,
58
58
  }
59
59
 
60
- const REMOVED_OPTION_KEYS = ["endpoint", "apiKey", "internalSessionMarkerDir", "argHints", "backOnEmptyLeft"] as const
60
+ const REMOVED_OPTION_KEYS = ["endpoint", "apiKey", "internalSessionMarkerDir", "argHints"] as const
61
61
 
62
62
  export function removedOptionKeys(raw: Readonly<Record<string, unknown>> | undefined): string[] {
63
63
  if (!raw) return []
package/src/text.ts CHANGED
@@ -123,9 +123,13 @@ export async function resolveExplicitModel(
123
123
  ): Promise<SuggestionModel | undefined> {
124
124
  if (signal.aborted) return undefined
125
125
  if (model.variant) return model
126
- const listed = await catalog.list(location, signal)
127
- if (signal.aborted) return undefined
128
- return withLowEffortVariant(model, listed.models.find((info) => info.providerID === model.providerID && info.id === model.modelID))
126
+ try {
127
+ const listed = await catalog.list(location, signal)
128
+ if (signal.aborted) return undefined
129
+ return withLowEffortVariant(model, listed.models.find((info) => info.providerID === model.providerID && info.id === model.modelID))
130
+ } catch {
131
+ return signal.aborted ? undefined : model
132
+ }
129
133
  }
130
134
 
131
135
  const LOW_EFFORT_VARIANTS = ["none", "minimal", "low"]
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
@@ -3,7 +3,7 @@ import { Plugin } from "@opencode/plugin/tui"
3
3
  import { TextareaRenderable, InputRenderable, type BoxRenderable, type Renderable } from "@opentui/core"
4
4
  import { createEffect, createMemo, createRoot, createSignal, on, onCleanup } from "solid-js"
5
5
  import { composerAction, composerBlocker, isEmptyComposer, keyName, locateComposerEditor, observeComposerInput, removesOnly, type ComposerLookup } from "./composer"
6
- import { createDiagnostics, errorDetail, formatDiagnostic, formatDiagnostics, modelLabel, type DiagnosticEntry } from "./diagnostics"
6
+ import { createDiagnostics, errorDetail, formatDiagnostic, formatDiagnostics, modelLabel, type DiagnosticEntry, type StageTimings } from "./diagnostics"
7
7
  import { createLifecycle } from "./lifecycle"
8
8
  import { acceptCommand, acceptShortcuts, ghostBaseLayer, ghostSuggestLayer } from "./keymap"
9
9
  import { parseSuggestCommand, removedOptionKeys, resolveOptions, suggestionModel } from "./options"
@@ -42,7 +42,7 @@ export default Plugin.define({
42
42
  const [suggestion, setSuggestion] = createSignal<Suggestion | undefined>()
43
43
  const [composerRevision, setComposerRevision] = createSignal(0)
44
44
  const inline = createInlinePlaceholder()
45
- const ghostColor = createMemo(() => dimPlaceholderColor(context.theme.text.muted))
45
+ let ghostColor: () => ReturnType<typeof dimPlaceholderColor>
46
46
  const diagnostics = createDiagnostics()
47
47
  const catalog = createCatalog(context.client)
48
48
 
@@ -55,6 +55,7 @@ export default Plugin.define({
55
55
  }
56
56
 
57
57
  let disposed = false
58
+ let syncWarned = false
58
59
  const composers = new Map<string, { marker: BoxRenderable; normal: () => boolean }>()
59
60
 
60
61
  const isCurrentSession = (sessionID: string) => {
@@ -79,10 +80,23 @@ export default Plugin.define({
79
80
  if (!canGenerate(sessionID)) return
80
81
  const started = Date.now()
81
82
  const elapsed = () => Date.now() - started
83
+ const stages: StageTimings = {}
84
+ const measure = async <T,>(stage: keyof StageTimings, run: () => Promise<T>): Promise<T> => {
85
+ const start = Date.now()
86
+ try {
87
+ return await run()
88
+ } finally {
89
+ stages[stage] = Date.now() - start
90
+ }
91
+ }
92
+ const noteGeneration = (entry: Omit<DiagnosticEntry, "at" | "sessionID" | "durationMs" | "stages">) =>
93
+ note({ ...entry, sessionID, durationMs: elapsed(), stages: { ...stages } })
82
94
  let model: SuggestionModel | undefined
83
95
  let failure: unknown
96
+ let syncing = true
84
97
  try {
85
- await context.data.session.message.sync(sessionID)
98
+ await measure("syncMs", () => context.data.session.message.sync(sessionID))
99
+ syncing = false
86
100
  if (signal.aborted || !canGenerate(sessionID)) return
87
101
  const messages = context.data.session.message.list(sessionID) as readonly TranscriptMessage[]
88
102
  const transcript = buildTranscript(messages, opts.recentMessages)
@@ -90,56 +104,58 @@ export default Plugin.define({
90
104
  const session = context.data.session.get(sessionID)
91
105
  const location = session?.location ?? context.location ?? context.data.location.default()
92
106
  const explicit = suggestionModel(state.model, opts.model)
93
- model = explicit
94
- ? await resolveExplicitModel(context.client, location, signal, explicit, catalog)
95
- : await resolveSmallModel(context.client, location, signal, session, catalog)
107
+ model = await measure("modelMs", () => explicit
108
+ ? resolveExplicitModel(context.client, location, signal, explicit, catalog)
109
+ : resolveSmallModel(context.client, location, signal, session, catalog))
96
110
  if (signal.aborted || !canGenerate(sessionID)) return
97
111
  if (!model) return
98
- const raw = await generateSuggestion(
112
+ const raw = await measure("generationMs", () => generateSuggestion(
99
113
  context.client,
100
- suggestionPrompt(opts.system, transcript),
114
+ suggestionPrompt(opts.system, transcript, opts.maxChars),
101
115
  model,
102
116
  signal,
103
117
  (error) => { failure = error; warnGeneration(error) },
104
118
  () => canGenerate(sessionID),
105
- )
119
+ ))
106
120
  const label = modelLabel(model)
107
- if (signal.aborted) {
108
- note({ sessionID, outcome: "aborted", model: label, durationMs: elapsed() })
109
- return
110
- }
121
+ if (signal.aborted) return
111
122
  if (failure) {
112
- note({ sessionID, outcome: "error", model: label, durationMs: elapsed(), detail: errorDetail(failure) })
123
+ noteGeneration({ outcome: "error", model: label, detail: errorDetail(failure) })
113
124
  return
114
125
  }
115
126
  if (!raw) {
116
127
  if (!canGenerate(sessionID)) return
117
- note({ sessionID, outcome: "empty", model: label, durationMs: elapsed() })
128
+ noteGeneration({ outcome: "empty", model: label })
118
129
  return
119
130
  }
120
131
  const clean = normalize(raw, opts.maxChars)
121
132
  if (!clean) {
122
- note({ sessionID, outcome: "empty", model: label, durationMs: elapsed(), chars: raw.length })
133
+ noteGeneration({ outcome: "empty", model: label, chars: raw.length })
123
134
  return
124
135
  }
125
136
  const previous = lastUserText(messages)
126
137
  if (previous && isEcho(clean, previous)) {
127
- note({ sessionID, outcome: "echo", model: label, durationMs: elapsed(), chars: clean.length })
138
+ noteGeneration({ outcome: "echo", model: label, chars: clean.length })
128
139
  return
129
140
  }
130
141
  if (!canGenerate(sessionID)) return
131
142
  setSuggestion({ sessionID, text: clean })
132
- note({ sessionID, outcome: "ok", model: label, durationMs: elapsed(), chars: clean.length })
143
+ noteGeneration({ outcome: "ok", model: label, chars: clean.length })
133
144
  } catch (error) {
134
145
  if (signal.aborted) return
135
- warnGeneration(error)
136
- note({
137
- sessionID,
146
+ if (syncing) {
147
+ if (!disposed && !syncWarned) {
148
+ syncWarned = true
149
+ context.ui.toast.show({ title: "Ghost", message: "Suggestions unavailable: session messages could not sync.", variant: "warning" })
150
+ }
151
+ } else warnGeneration(error)
152
+ noteGeneration({
138
153
  outcome: isNoSmallModel(error) ? "unavailable" : "error",
139
154
  ...(model ? { model: modelLabel(model) } : {}),
140
- durationMs: elapsed(),
141
155
  detail: errorDetail(error),
142
156
  })
157
+ } finally {
158
+ if (signal.aborted) noteGeneration({ outcome: "aborted", ...(model ? { model: modelLabel(model) } : {}) })
143
159
  }
144
160
  }
145
161
 
@@ -218,6 +234,7 @@ export default Plugin.define({
218
234
  }
219
235
 
220
236
  const disposeRouteWatcher = createRoot((dispose) => {
237
+ ghostColor = createMemo(() => dimPlaceholderColor(context.theme.text.muted))
221
238
  createEffect(on(() => {
222
239
  const route = context.ui.router.current()
223
240
  return route.type === "session" ? route.sessionID : route.type