opencode-ghost 1.3.14 → 1.3.16

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.16] - 2026-11-23
9
+
10
+ ### Fixed
11
+
12
+ - **deps:** Require OpenCode 2.4.0 for OpenTUI 0.9 (#30)
13
+
14
+ ## [1.3.15] - 2026-11-08
15
+
16
+ ### Fixed
17
+
18
+ - Harden accept gating, unicode handling and installer for OpenCode 2.2.6 (#20)
19
+
8
20
  ## [1.3.14] - 2026-11-01
9
21
 
10
22
  ### Fixed
@@ -331,6 +343,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
331
343
  - Options for `model`, `acceptKeys`, `maxChars`, `idleDelayMs`,
332
344
  `recentMessages` and `system`.
333
345
 
346
+ [1.3.16]: https://github.com/ozandogrultan/opencode-ghost/compare/v1.3.15...v1.3.16
347
+ [1.3.15]: https://github.com/ozandogrultan/opencode-ghost/compare/v1.3.14...v1.3.15
334
348
  [1.3.14]: https://github.com/ozandogrultan/opencode-ghost/compare/v1.3.13...v1.3.14
335
349
  [1.3.13]: https://github.com/ozandogrultan/opencode-ghost/compare/v1.3.12...v1.3.13
336
350
  [1.3.12]: https://github.com/ozandogrultan/opencode-ghost/compare/v1.3.11...v1.3.12
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-ghost",
3
- "version": "1.3.14",
3
+ "version": "1.3.16",
4
4
  "description": "OpenCode ghost text autosuggest: suggests your next message as dimmed inline ghost text in the empty TUI composer, accepted with Tab or Right arrow.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -46,23 +46,24 @@
46
46
  "test:unit": "bun test",
47
47
  "test:changelog": "bash tests/changelog.sh",
48
48
  "typecheck": "tsc --noEmit",
49
- "lint:sh": "for script in install.sh tests/*.sh scripts/*.sh; do bash -n \"$script\" || exit; done",
49
+ "lint:sh": "for script in install.sh tests/*.sh scripts/*.sh; do bash -n \"$script\" || exit; done && node --check scripts/install.mjs",
50
50
  "prepublishOnly": "bun run test && bun run typecheck"
51
51
  },
52
52
  "dependencies": {
53
- "@opentui/core": "^0.8.0",
54
- "@opentui/solid": "^0.8.0"
53
+ "@opentui/core": "^0.9.7",
54
+ "@opentui/solid": "^0.9.7"
55
55
  },
56
56
  "peerDependencies": {
57
- "@opencode/plugin": "*",
57
+ "@opencode/plugin": ">=2.4.0",
58
58
  "solid-js": "*"
59
59
  },
60
60
  "devDependencies": {
61
61
  "@commitlint/cli": "^21.2.2",
62
62
  "@commitlint/config-conventional": "^21.2.2",
63
- "@opencode/plugin": "2.2.5",
63
+ "@opencode/client": "2.3.2",
64
+ "@opencode/plugin": "2.3.2",
64
65
  "@types/bun": "^1.4.3",
65
- "@types/node": "26.6.5",
66
+ "@types/node": "26.6.6",
66
67
  "husky": "^9.1.7",
67
68
  "solid-js": "1.9.12",
68
69
  "typescript": "7.0.2"
package/src/composer.ts CHANGED
@@ -6,7 +6,7 @@ export function editsComposer(event: { name: string; sequence: string; ctrl: boo
6
6
  if (event.super && !event.ctrl && !event.meta && !event.option && !event.hyper && event.name === "z") return true
7
7
  if (event.ctrl || event.meta || event.option || event.super || event.hyper) return false
8
8
  if (["return", "enter", "linefeed", "space"].includes(event.name)) return true
9
- return [...event.sequence].length === 1 && !/[\u0000-\u001f\u007f]/.test(event.sequence)
9
+ return event.sequence.length > 0 && !/[\u0000-\u001f\u007f-\u009f]/.test(event.sequence)
10
10
  }
11
11
 
12
12
  export function removesOnly(event: { name: string; ctrl: boolean; meta: boolean; option?: boolean; super?: boolean; hyper?: boolean }): boolean {
@@ -79,10 +79,6 @@ export function locateComposerEditor<T extends EditorNode>(marker: EditorNode |
79
79
  return { reason: "no editor found above the marker" }
80
80
  }
81
81
 
82
- export function findComposerEditor<T extends EditorNode>(marker: EditorNode | undefined, isEditor: (node: EditorNode) => node is T, isComposer: (editor: T) => boolean): T | undefined {
83
- return locateComposerEditor(marker, isEditor, isComposer).editor
84
- }
85
-
86
82
  export function composerAction(editor: Editor | undefined, focused: () => unknown, mode: string, normal: boolean, allowed: boolean, text: string | undefined): boolean {
87
83
  if (!allowed || !text || !editor || editor !== focused() || !editor.focused || editor.isDestroyed || mode !== "base" || !normal) return false
88
84
  if (editor.plainText.length !== 0) return false
package/src/keymap.ts CHANGED
@@ -3,11 +3,14 @@ import { canonicalKey } from "./composer"
3
3
 
4
4
  export const acceptCommandId = (key: string) => `ghost.accept.${key}`
5
5
 
6
- export function acceptCommand(key: string, session: () => string | undefined, suggestionSession: () => string | undefined, act: (sessionID: string) => boolean): KeymapCommand {
6
+ export function acceptCommand(key: string, session: () => string | undefined, suggestionSession: () => string | undefined, act: (sessionID: string) => boolean, eligible: (sessionID: string) => boolean = () => true): KeymapCommand {
7
7
  return {
8
8
  id: acceptCommandId(key),
9
9
  bind: key,
10
- enabled: () => Boolean(suggestionSession()),
10
+ enabled: () => {
11
+ const sessionID = session()
12
+ return !!sessionID && suggestionSession() === sessionID && eligible(sessionID)
13
+ },
11
14
  run: () => {
12
15
  const sessionID = session()
13
16
  if (!sessionID || suggestionSession() !== sessionID || !act(sessionID)) return false
@@ -40,11 +43,3 @@ export function ghostSuggestLayer(enabled: boolean, suggest: KeymapCommand["run"
40
43
  }],
41
44
  }
42
45
  }
43
-
44
- export function ghostKeymapLayers(
45
- composerCommands: KeymapCommand[],
46
- enabled: boolean,
47
- suggest: KeymapCommand["run"],
48
- ): KeymapLayer[] {
49
- return [ghostBaseLayer(composerCommands), ghostSuggestLayer(enabled, suggest)]
50
- }
package/src/stateless.ts CHANGED
@@ -32,14 +32,14 @@ function pause(ms: number, signal: AbortSignal): Promise<void> {
32
32
  export async function generateSuggestion(
33
33
  client: GenerateClient,
34
34
  prompt: string,
35
- model: SuggestionModel | undefined | Promise<SuggestionModel | undefined>,
35
+ model: SuggestionModel | undefined,
36
36
  signal: AbortSignal,
37
37
  onError?: (error: unknown) => void,
38
38
  allowed: () => boolean = () => true,
39
39
  retryDelays: readonly number[] = MODEL_UNAVAILABLE_RETRY_MS,
40
40
  ): Promise<string | undefined> {
41
41
  try {
42
- const resolved = await model
42
+ const resolved = model
43
43
  if (signal.aborted || !allowed() || !resolved) return undefined
44
44
  const input = { prompt, model: { id: resolved.modelID, providerID: resolved.providerID, ...(resolved.variant ? { variant: resolved.variant } : {}) } }
45
45
  for (let attempt = 0; ; attempt++) {
package/src/text.ts CHANGED
@@ -15,8 +15,7 @@ export type SmallModelClient = {
15
15
 
16
16
  export function selectSmallModel(models: readonly ModelInfo[], providerID: string): SuggestionModel | undefined {
17
17
  const available = models.filter((model) => model.providerID === providerID && model.enabled &&
18
- model.status === "active" && model.capabilities.input.some((item) => item.startsWith("text")) &&
19
- model.capabilities.output.some((item) => item.startsWith("text")))
18
+ model.status === "active" && isTextModel(model))
20
19
  for (const family of ["gpt-luna", "gemini-flash-lite", "gemini-flash", "claude-haiku"]) {
21
20
  const model = available.find((model) => model.family === family)
22
21
  if (model) return { providerID: model.providerID, modelID: model.id }
@@ -140,7 +139,7 @@ function withLowEffortVariant(model: SuggestionModel, info: ModelInfo | undefine
140
139
  }
141
140
 
142
141
  function isTextModel(model: ModelInfo) {
143
- const text = (items: readonly string[]) => items.length === 0 || items.some((item) => item.startsWith("text"))
142
+ const text = (items: readonly string[]) => items.some((item) => item.startsWith("text"))
144
143
  return text(model.capabilities.input) && text(model.capabilities.output)
145
144
  }
146
145
 
@@ -151,6 +150,21 @@ export function parseModel(spec: string | undefined): { providerID: string; mode
151
150
  return { providerID: spec.slice(0, index), modelID: spec.slice(index + 1) }
152
151
  }
153
152
 
153
+ const segmenter = typeof Intl !== "undefined" && "Segmenter" in Intl ? new Intl.Segmenter(undefined, { granularity: "grapheme" }) : undefined
154
+
155
+ export function graphemeLength(text: string): number {
156
+ return graphemes(text).length
157
+ }
158
+
159
+ function graphemes(text: string): string[] {
160
+ return segmenter ? Array.from(segmenter.segment(text), (part) => part.segment) : [...text]
161
+ }
162
+
163
+ export function clipCodePointsTail(text: string, max: number): string {
164
+ const points = [...text]
165
+ return points.length <= max ? text : points.slice(points.length - max).join("")
166
+ }
167
+
154
168
  export function collapse(text: string): string {
155
169
  return text.replace(/\s+/g, " ").trim()
156
170
  }
@@ -169,6 +183,10 @@ export function clipTail(text: string, max: number): string {
169
183
  return "…" + points.slice(points.length - (max - 1)).join("").trimStart()
170
184
  }
171
185
 
186
+ export function isNone(text: string): boolean {
187
+ return /^none\.?$/i.test(text.trim()) || /^[*_`\s]*NONE(?:[\s.,;:!?\-–—*`]|$)/.test(text)
188
+ }
189
+
172
190
  export function normalize(raw: string, maxChars: number): string | undefined {
173
191
  const first = raw
174
192
  .split(/\r?\n/)
@@ -183,8 +201,8 @@ export function normalize(raw: string, maxChars: number): string | undefined {
183
201
  .replace(/[`"'*_#\s]+$/, "")
184
202
  .replace(/`+/g, "")
185
203
  .trim()
186
- if (!cleaned || /^none\.?$/i.test(cleaned)) return undefined
187
- const points = [...cleaned]
204
+ if (!cleaned || isNone(cleaned)) return undefined
205
+ const points = graphemes(cleaned)
188
206
  if (points.length <= maxChars) return cleaned
189
207
  return points.slice(0, maxChars - 1).join("").trimEnd() + "…"
190
208
  }
package/src/transcript.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { clip, clipTail } from "./text"
1
+ import { clip, clipCodePointsTail, clipTail } from "./text"
2
2
 
3
3
  const MAX_MESSAGE_CHARS = 800
4
4
  const MAX_TRANSCRIPT_CHARS = 6000
@@ -28,7 +28,7 @@ export function buildTranscript(messages: readonly TranscriptMessage[], recentMe
28
28
  lines.push(`${entry.role}: ${(entry.role === "Assistant" ? clipTail : clip)(entry.text, MAX_MESSAGE_CHARS)}`)
29
29
  }
30
30
  if (lines.length === 0) return ""
31
- return `${lines.join("\n").slice(-MAX_TRANSCRIPT_CHARS)}\n\nTask: write the user's next message.`
31
+ return `${clipCodePointsTail(lines.join("\n"), MAX_TRANSCRIPT_CHARS)}\n\nTask: write the user's next message.`
32
32
  }
33
33
 
34
34
  export function lastUserText(messages: readonly TranscriptMessage[]): string {
package/src/tui.tsx CHANGED
@@ -10,7 +10,7 @@ import { acceptCommand, acceptShortcuts, ghostBaseLayer, ghostSuggestLayer } fro
10
10
  import { parseSuggestCommand, removedOptionKeys, resolveOptions, suggestionModel } from "./options"
11
11
  import { createInlinePlaceholder, dimPlaceholderColor } from "./placeholder"
12
12
  import { generateSuggestion } from "./stateless"
13
- import { createCatalog, isEcho, isNoSmallModel, normalize, resolveExplicitModel, resolveSmallModel, type SuggestionModel } from "./text"
13
+ import { createCatalog, graphemeLength, isEcho, isNone, isNoSmallModel, normalize, resolveExplicitModel, resolveSmallModel, type SuggestionModel } from "./text"
14
14
  import { buildTranscript, lastUserText, suggestionPrompt, type TranscriptMessage } from "./transcript"
15
15
 
16
16
  type Suggestion = { sessionID: string; text: string }
@@ -142,17 +142,17 @@ export default Plugin.define({
142
142
  }
143
143
  const clean = normalize(raw, opts.maxChars)
144
144
  if (!clean) {
145
- const none = /^none\.?$/i.test(raw.trim())
146
- noteGeneration({ outcome: "empty", model: label, ...(none ? {} : { chars: raw.length }) })
145
+ const none = isNone(raw.trim().split(/\r?\n/)[0] ?? "")
146
+ noteGeneration({ outcome: "empty", model: label, ...(none ? {} : { chars: graphemeLength(raw) }) })
147
147
  return
148
148
  }
149
149
  const previous = lastUserText(messages)
150
150
  if (previous && isEcho(clean, previous)) {
151
- noteGeneration({ outcome: "echo", model: label, chars: clean.length })
151
+ noteGeneration({ outcome: "echo", model: label, chars: graphemeLength(clean) })
152
152
  return
153
153
  }
154
154
  setSuggestion({ sessionID, text: clean })
155
- noteGeneration({ outcome: "ok", model: label, chars: clean.length })
155
+ noteGeneration({ outcome: "ok", model: label, chars: graphemeLength(clean) })
156
156
  } catch (error) {
157
157
  if (signal.aborted) return
158
158
  if (syncing) {
@@ -220,7 +220,7 @@ export default Plugin.define({
220
220
  const recorded = displayLog.record({
221
221
  sessionID: current.sessionID,
222
222
  outcome: status === "shown" ? "shown" : "hidden",
223
- chars: current.text.length,
223
+ chars: graphemeLength(current.text),
224
224
  ...(status === "shown" ? {} : { detail: status }),
225
225
  })
226
226
  if (state.debug === true) context.ui.toast.show({ title: "Ghost", message: formatDiagnostic(recorded) })
@@ -297,81 +297,92 @@ export default Plugin.define({
297
297
  inline.clear()
298
298
  })
299
299
 
300
+ const canAccept = (sessionID: string) => {
301
+ const current = suggestion()
302
+ if (!current || current.sessionID !== sessionID) return false
303
+ if (!canGenerate(sessionID)) return false
304
+ return inline.visible(getComposer(sessionID).editor, current.text) && isComposerEmpty(sessionID)
305
+ }
306
+
300
307
  const acceptLayer = () => ghostBaseLayer(
301
308
  opts.acceptKeys.map((key) => acceptCommand(key, () => {
302
309
  const route = context.ui.router.current()
303
310
  return route.type === "session" ? route.sessionID : undefined
304
- }, () => suggestion()?.sessionID, act)),
311
+ }, () => suggestion()?.sessionID, act, canAccept)),
305
312
  )
306
313
  const suggestLayer = () => ghostSuggestLayer(state.enabled, async (input) => {
307
- const command = parseSuggestCommand(input)
308
- if (command.type === "model") {
309
- cancelSuggestion()
310
- lifecycle.resetWarning()
311
- catalog.clear()
312
- await updateState((draft) => { draft.model = command.model })
313
- cancelSuggestion()
314
- context.ui.toast.show({ message: `Suggestion model: ${state.model ?? opts.model ?? "OpenCode small default"}` })
315
- return
316
- }
317
- if (command.type === "debug") {
318
- const next = command.value ?? (state.debug !== true)
319
- await updateState((draft) => { draft.debug = next })
320
- context.ui.toast.show({ message: `Ghost debug: ${next ? "on" : "off"}` })
321
- return
322
- }
323
- if (command.type === "log") {
324
- const override = state.model ?? opts.model
325
- const summary = `suggestions ${state.enabled ? "on" : "off"}, debug ${state.debug === true ? "on" : "off"}, model ${override ?? "OpenCode small default"}`
326
- const current = suggestion()
327
- const color = ghostColor()
328
- const route = context.ui.router.current()
329
- const entry = route.type === "session" ? composers.get(route.sessionID) : undefined
330
- const editor = lookupComposer(entry?.marker).editor
331
- const live = [
332
- `route ${route.type}`,
333
- `suggestion ${current ? `retained (${current.text.length} chars)` : "none"}`,
334
- `display ${current ? displayStatus(current) : "n/a"}`,
335
- `focused ${editor ? (editor === context.renderer.currentFocusedEditor && editor.focused ? "yes" : "no") : "n/a"}`,
336
- `mode ${context.keymap.mode.current()}`,
337
- `color rgba(${[color.r, color.g, color.b, color.a].map((value) => value.toFixed(2)).join(", ")})`,
338
- ].join("\n")
339
- 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())}`
340
- context.ui.dialog.set({ size: "large", centered: true })
341
- context.ui.dialog.show(() => {
342
- const dimensions = useTerminalDimensions()
343
- return (
344
- <box id="ghost-diagnostics" width="100%" paddingX={2} paddingY={1} gap={1}>
345
- <box flexDirection="row" justifyContent="space-between" flexShrink={0}>
346
- <text fg={context.theme.text.base}><b>Ghost — diagnostics</b></text>
347
- <text fg={context.theme.text.muted}>esc</text>
348
- </box>
349
- <scrollbox id="ghost-diagnostics-scroll" height={Math.max(1, Math.min(28, dimensions().height - 8))} flexShrink={0} focused scrollX={false} scrollY>
350
- <text id="ghost-diagnostics-body" fg={context.theme.text.base} wrapMode="word" content={message} />
351
- </scrollbox>
352
- </box>
353
- )
354
- })
355
- return
356
- }
357
- if (command.type === "invalid") {
358
- context.ui.toast.show({ message: "Use /suggest, /suggest model provider/model, /suggest model clear, /suggest debug [on|off], or /suggest log", variant: "warning" })
359
- return
360
- }
361
- cancelSuggestion()
362
- const next = !state.enabled
363
- await updateState((draft) => {
364
- draft.enabled = next
365
- })
366
- cancelSuggestion()
367
- if (!next) {
368
- context.ui.toast.show({ message: "Prompt suggestions: off" })
369
- return
370
- }
371
- context.ui.toast.show({ message: "Prompt suggestions: on" })
372
- catalog.clear()
373
- const route = context.ui.router.current()
374
- if (route.type === "session") void lifecycle.run(route.sessionID)
314
+ const command = parseSuggestCommand(input)
315
+ if (command.type === "model") {
316
+ cancelSuggestion()
317
+ lifecycle.resetWarning()
318
+ catalog.clear()
319
+ await updateState((draft) => { draft.model = command.model })
320
+ cancelSuggestion()
321
+ context.ui.toast.show({ message: `Suggestion model: ${state.model ?? opts.model ?? "OpenCode small default"}` })
322
+ return
323
+ }
324
+ if (command.type === "debug") {
325
+ let next = false
326
+ await updateState((draft) => {
327
+ next = command.value ?? (draft.debug !== true)
328
+ draft.debug = next
329
+ })
330
+ context.ui.toast.show({ message: `Ghost debug: ${next ? "on" : "off"}` })
331
+ return
332
+ }
333
+ if (command.type === "log") {
334
+ const override = state.model ?? opts.model
335
+ const summary = `suggestions ${state.enabled ? "on" : "off"}, debug ${state.debug === true ? "on" : "off"}, model ${override ?? "OpenCode small default"}`
336
+ const current = suggestion()
337
+ const color = ghostColor()
338
+ const route = context.ui.router.current()
339
+ const entry = route.type === "session" ? composers.get(route.sessionID) : undefined
340
+ const editor = lookupComposer(entry?.marker).editor
341
+ const live = [
342
+ `route ${route.type}`,
343
+ `suggestion ${current ? `retained (${graphemeLength(current.text)} chars)` : "none"}`,
344
+ `display ${current ? displayStatus(current) : "n/a"}`,
345
+ `focused ${editor ? (editor === context.renderer.currentFocusedEditor && editor.focused ? "yes" : "no") : "n/a"}`,
346
+ `mode ${context.keymap.mode.current()}`,
347
+ `color rgba(${[color.r, color.g, color.b, color.a].map((value) => value.toFixed(2)).join(", ")})`,
348
+ ].join("\n")
349
+ 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())}`
350
+ context.ui.dialog.set({ size: "large", centered: true })
351
+ context.ui.dialog.show(() => {
352
+ const dimensions = useTerminalDimensions()
353
+ return (
354
+ <box id="ghost-diagnostics" width="100%" paddingX={2} paddingY={1} gap={1}>
355
+ <box flexDirection="row" justifyContent="space-between" flexShrink={0}>
356
+ <text fg={context.theme.text.base}><b>Ghost — diagnostics</b></text>
357
+ <text fg={context.theme.text.muted}>esc</text>
358
+ </box>
359
+ <scrollbox id="ghost-diagnostics-scroll" height={Math.max(1, Math.min(28, dimensions().height - 8))} flexShrink={0} focused scrollX={false} scrollY>
360
+ <text id="ghost-diagnostics-body" fg={context.theme.text.base} wrapMode="word" content={message} />
361
+ </scrollbox>
362
+ </box>
363
+ )
364
+ })
365
+ return
366
+ }
367
+ if (command.type === "invalid") {
368
+ context.ui.toast.show({ message: "Use /suggest, /suggest model provider/model, /suggest model clear, /suggest debug [on|off], or /suggest log", variant: "warning" })
369
+ return
370
+ }
371
+ cancelSuggestion()
372
+ let next = false
373
+ await updateState((draft) => {
374
+ next = !draft.enabled
375
+ draft.enabled = next
376
+ })
377
+ cancelSuggestion()
378
+ if (!next) {
379
+ context.ui.toast.show({ message: "Prompt suggestions: off" })
380
+ return
381
+ }
382
+ context.ui.toast.show({ message: "Prompt suggestions: on" })
383
+ catalog.clear()
384
+ const route = context.ui.router.current()
385
+ if (route.type === "session") void lifecycle.run(route.sessionID)
375
386
  })
376
387
  context.keymap.layer(acceptLayer)
377
388
  context.keymap.layer(suggestLayer)