opencode-ghost 1.2.0 → 1.3.0

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,12 @@ 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.0] - 2026-10-09
9
+
10
+ ### Added
11
+
12
+ - **tui:** Explain why the ghost placeholder is not displayed
13
+
8
14
  ## [1.2.0] - 2026-10-09
9
15
 
10
16
  ### Added
@@ -240,6 +246,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
240
246
  - Options for `model`, `acceptKeys`, `maxChars`, `idleDelayMs`,
241
247
  `recentMessages` and `system`.
242
248
 
249
+ [1.3.0]: https://github.com/ozandogrultan/opencode-ghost/compare/v1.2.0...v1.3.0
243
250
  [1.2.0]: https://github.com/ozandogrultan/opencode-ghost/compare/v1.1.0...v1.2.0
244
251
  [1.1.0]: https://github.com/ozandogrultan/opencode-ghost/compare/v1.0.7...v1.1.0
245
252
  [1.0.7]: https://github.com/ozandogrultan/opencode-ghost/compare/v1.0.6...v1.0.7
package/README.md CHANGED
@@ -158,6 +158,15 @@ be traced to a debounce, an empty or `NONE` reply, an echo filter, or a provider
158
158
  error. `/suggest debug` toggles the same data as a toast on each attempt (aborts
159
159
  are logged but not toasted). The history is not written to disk.
160
160
 
161
+ When a generation is `ok` but nothing is visible, `/suggest log` also shows the
162
+ live display state and a bounded history of display changes. Each `shown` or
163
+ `hidden` entry names the reason the placeholder is not applied: no
164
+ `prompt.footer` marker, an unidentified or ambiguous editor, extra sibling nodes in
165
+ the composer, a non-normal prompt or keymap mode, a draft, selection, extmarks,
166
+ a busy or hidden session, or the host overriding the placeholder. The live
167
+ section also reports focus, keymap mode and the placeholder colour. With
168
+ `/suggest debug` on, each change is toasted.
169
+
161
170
  ## Caveats
162
171
 
163
172
  - **No inline typing completions.** V1's slash-argument and history ghosts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-ghost",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
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
@@ -36,24 +36,45 @@ export function isEmptyComposer(editor: TextareaRenderable | undefined, focused:
36
36
  return !!editor && editor === focused && editor.focused && isEligibleComposer(editor, mode, normal, selected)
37
37
  }
38
38
 
39
- export function isEligibleComposer(editor: TextareaRenderable | undefined, mode: string, normal: boolean, selected: boolean): boolean {
40
- if (!editor?.parent || editor.parent.isDestroyed) return false
39
+ export function composerBlocker(editor: TextareaRenderable | undefined, mode: string, normal: boolean, selected: boolean): string | undefined {
40
+ if (!editor) return "no composer editor"
41
+ if (!editor.parent || editor.parent.isDestroyed) return "editor detached"
41
42
  const siblings = editor.parent.getChildren().filter((node) =>
42
43
  !node.id.startsWith("slot-layout-"),
43
44
  )
44
- if (siblings.length !== 1 || siblings[0] !== editor) return false
45
- return normal && mode === "base" && !selected && !editor.isDestroyed && editor.plainText === "" && !editor.hasSelection() && !editor.traits.capture?.includes("navigate") && editor.extmarks.getAll().length === 0
45
+ if (siblings.length !== 1 || siblings[0] !== editor) return `composer has ${siblings.length} sibling nodes (${siblings.map((node) => node.id || "?").join(", ")})`
46
+ if (!normal) return "prompt not in normal mode"
47
+ if (mode !== "base") return `keymap mode is ${mode}`
48
+ if (selected) return "renderer has a selection"
49
+ if (editor.isDestroyed) return "editor destroyed"
50
+ if (editor.plainText !== "") return "composer not empty"
51
+ if (editor.hasSelection()) return "editor has a selection"
52
+ if (editor.traits.capture?.includes("navigate")) return "editor captures navigation"
53
+ const marks = editor.extmarks.getAll().length
54
+ if (marks !== 0) return `editor has ${marks} extmark(s)`
46
55
  }
47
56
 
48
- export function findComposerEditor<T extends EditorNode>(marker: EditorNode | undefined, isEditor: (node: EditorNode) => node is T, isComposer: (editor: T) => boolean): T | undefined {
49
- if (!marker || marker.isDestroyed) return
57
+ export function isEligibleComposer(editor: TextareaRenderable | undefined, mode: string, normal: boolean, selected: boolean): boolean {
58
+ return composerBlocker(editor, mode, normal, selected) === undefined
59
+ }
60
+
61
+ export type ComposerLookup<T> = { editor: T; reason?: undefined } | { editor?: undefined; reason: string }
62
+
63
+ export function locateComposerEditor<T extends EditorNode>(marker: EditorNode | undefined, isEditor: (node: EditorNode) => node is T, isComposer: (editor: T) => boolean): ComposerLookup<T> {
64
+ if (!marker) return { reason: "no prompt.footer marker registered" }
65
+ if (marker.isDestroyed) return { reason: "prompt.footer marker destroyed" }
50
66
  const editors = (node: EditorNode): T[] => isEditor(node) ? [node] : node.getChildren().flatMap(editors)
51
67
  for (let node = marker.parent; node && node.parent; node = node.parent) {
52
- if (node.isDestroyed) return
68
+ if (node.isDestroyed) return { reason: "marker ancestor destroyed" }
53
69
  const found = editors(node)
54
- if (found.length > 1) return
55
- if (found.length === 1) return isComposer(found[0]) ? found[0] : undefined
70
+ if (found.length > 1) return { reason: `${found.length} editors share the marker ancestor` }
71
+ if (found.length === 1) return isComposer(found[0]) ? { editor: found[0] } : { reason: "editor lacks getClipboardText (not the host composer)" }
56
72
  }
73
+ return { reason: "no editor found above the marker" }
74
+ }
75
+
76
+ export function findComposerEditor<T extends EditorNode>(marker: EditorNode | undefined, isEditor: (node: EditorNode) => node is T, isComposer: (editor: T) => boolean): T | undefined {
77
+ return locateComposerEditor(marker, isEditor, isComposer).editor
57
78
  }
58
79
 
59
80
  export function composerAction(editor: Editor | undefined, focused: () => unknown, mode: string, normal: boolean, allowed: boolean, text: string | undefined): boolean {
@@ -1,4 +1,4 @@
1
- export type DiagnosticOutcome = "ok" | "empty" | "echo" | "unavailable" | "error" | "aborted"
1
+ export type DiagnosticOutcome = "ok" | "empty" | "echo" | "unavailable" | "error" | "aborted" | "shown" | "hidden"
2
2
 
3
3
  export type DiagnosticEntry = {
4
4
  readonly at: number
@@ -54,6 +54,8 @@ const OUTCOME_LABELS: Record<DiagnosticOutcome, string> = {
54
54
  unavailable: "no model",
55
55
  error: "error",
56
56
  aborted: "aborted",
57
+ shown: "shown",
58
+ hidden: "hidden",
57
59
  }
58
60
 
59
61
  function clockTime(at: number): string {
package/src/tui.tsx CHANGED
@@ -2,7 +2,7 @@
2
2
  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
- import { composerAction, findComposerEditor, isEligibleComposer, isEmptyComposer, keyName, observeComposerInput } from "./composer"
5
+ import { composerAction, composerBlocker, isEmptyComposer, keyName, locateComposerEditor, observeComposerInput, type ComposerLookup } from "./composer"
6
6
  import { createDiagnostics, errorDetail, formatDiagnostic, formatDiagnostics, modelLabel, type DiagnosticEntry } from "./diagnostics"
7
7
  import { createLifecycle } from "./lifecycle"
8
8
  import { acceptCommand, acceptShortcuts, ghostKeymapLayers } from "./keymap"
@@ -14,8 +14,8 @@ import { buildTranscript, lastUserText, suggestionPrompt, type TranscriptMessage
14
14
 
15
15
  type Suggestion = { sessionID: string; text: string }
16
16
 
17
- function composerEditor(marker: Renderable | undefined): TextareaRenderable | undefined {
18
- return findComposerEditor(marker,
17
+ function lookupComposer(marker: Renderable | undefined): ComposerLookup<TextareaRenderable> {
18
+ return locateComposerEditor(marker,
19
19
  (node): node is TextareaRenderable => node instanceof TextareaRenderable && !(node instanceof InputRenderable),
20
20
  (editor) => typeof (editor as unknown as { getClipboardText?: unknown }).getClipboardText === "function",
21
21
  )
@@ -160,7 +160,38 @@ export default Plugin.define({
160
160
 
161
161
  const getComposer = (sessionID: string) => {
162
162
  const entry = composers.get(sessionID)
163
- return { editor: composerEditor(entry?.marker), normal: entry?.normal() === true }
163
+ return { editor: lookupComposer(entry?.marker).editor, normal: entry?.normal() === true }
164
+ }
165
+
166
+ const displayLog = createDiagnostics()
167
+ let lastDisplay: string | undefined
168
+
169
+ const displayStatus = (current: Suggestion): string => {
170
+ if (!canGenerate(current.sessionID)) return "session busy, hidden or suggestions disabled"
171
+ const entry = composers.get(current.sessionID)
172
+ const found = lookupComposer(entry?.marker)
173
+ if (!found.editor) return found.reason
174
+ const blocker = composerBlocker(found.editor, context.keymap.mode.current(), entry?.normal() === true, context.renderer.hasSelection)
175
+ if (blocker) return blocker
176
+ return inline.visible(found.editor, current.text) ? "shown" : "placeholder not applied (host overrode it)"
177
+ }
178
+
179
+ const trackDisplay = () => {
180
+ const current = suggestion()
181
+ if (!current) {
182
+ lastDisplay = undefined
183
+ return
184
+ }
185
+ const status = displayStatus(current)
186
+ if (status === lastDisplay) return
187
+ lastDisplay = status
188
+ const recorded = displayLog.record({
189
+ sessionID: current.sessionID,
190
+ outcome: status === "shown" ? "shown" : "hidden",
191
+ chars: current.text.length,
192
+ ...(status === "shown" ? {} : { detail: status }),
193
+ })
194
+ if (state.debug === true) context.ui.toast.show({ title: "Ghost", message: formatDiagnostic(recorded) })
164
195
  }
165
196
 
166
197
  const isComposerEmpty = (sessionID: string) => {
@@ -172,7 +203,8 @@ export default Plugin.define({
172
203
  composerRevision()
173
204
  const current = suggestion()
174
205
  const { editor, normal } = current ? getComposer(current.sessionID) : { editor: undefined, normal: false }
175
- inline.sync(editor, current?.text, ghostColor(), !!current && canGenerate(current.sessionID) && isEligibleComposer(editor, context.keymap.mode.current(), normal, context.renderer.hasSelection))
206
+ inline.sync(editor, current?.text, ghostColor(), !!current && canGenerate(current.sessionID) && !composerBlocker(editor, context.keymap.mode.current(), normal, context.renderer.hasSelection))
207
+ trackDisplay()
176
208
  }
177
209
 
178
210
  const disposeRouteWatcher = createRoot((dispose) => {
@@ -231,9 +263,22 @@ export default Plugin.define({
231
263
  if (command.type === "log") {
232
264
  const override = state.model ?? opts.model
233
265
  const summary = `suggestions ${state.enabled ? "on" : "off"}, debug ${state.debug === true ? "on" : "off"}, model ${override ?? "OpenCode small default"}`
266
+ const current = suggestion()
267
+ const color = ghostColor()
268
+ const route = context.ui.router.current()
269
+ const entry = route.type === "session" ? composers.get(route.sessionID) : undefined
270
+ const editor = lookupComposer(entry?.marker).editor
271
+ const live = [
272
+ `route ${route.type}`,
273
+ `suggestion ${current ? `retained (${current.text.length} chars)` : "none"}`,
274
+ `display ${current ? displayStatus(current) : "n/a"}`,
275
+ `focused ${editor ? (editor === context.renderer.currentFocusedEditor && editor.focused ? "yes" : "no") : "n/a"}`,
276
+ `mode ${context.keymap.mode.current()}`,
277
+ `color rgba(${[color.r, color.g, color.b, color.a].map((value) => value.toFixed(2)).join(", ")})`,
278
+ ].join("\n")
234
279
  void context.ui.dialog.alert({
235
- title: "Ghost — recent generations",
236
- message: `${summary}\n\n${formatDiagnostics(diagnostics.list())}`,
280
+ title: "Ghost — diagnostics",
281
+ 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())}`,
237
282
  })
238
283
  return
239
284
  }