opencode-ghost 1.3.10 → 1.3.12
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 +14 -0
- package/README.md +21 -12
- package/package.json +12 -10
- package/src/composer.ts +9 -4
- package/src/options.ts +3 -3
- package/src/placeholder.ts +5 -3
- package/src/text.ts +8 -5
- package/src/tui.tsx +18 -5
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.12] - 2026-10-22
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- Harden option validation, text normalization, cancellation and installer
|
|
13
|
+
|
|
14
|
+
## [1.3.11] - 2026-10-20
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
|
|
18
|
+
- **deps:** Require opentui 0.6 for opencode 2.1
|
|
19
|
+
|
|
8
20
|
## [1.3.10] - 2026-10-11
|
|
9
21
|
|
|
10
22
|
### Fixed
|
|
@@ -307,6 +319,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
307
319
|
- Options for `model`, `acceptKeys`, `maxChars`, `idleDelayMs`,
|
|
308
320
|
`recentMessages` and `system`.
|
|
309
321
|
|
|
322
|
+
[1.3.12]: https://github.com/ozandogrultan/opencode-ghost/compare/v1.3.11...v1.3.12
|
|
323
|
+
[1.3.11]: https://github.com/ozandogrultan/opencode-ghost/compare/v1.3.10...v1.3.11
|
|
310
324
|
[1.3.10]: https://github.com/ozandogrultan/opencode-ghost/compare/v1.3.9...v1.3.10
|
|
311
325
|
[1.3.9]: https://github.com/ozandogrultan/opencode-ghost/compare/v1.3.8...v1.3.9
|
|
312
326
|
[1.3.8]: https://github.com/ozandogrultan/opencode-ghost/compare/v1.3.7...v1.3.8
|
package/README.md
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
<h1 align="center">
|
|
2
|
+
<img src="assets/logo.svg" alt="ghost — next-prompt suggestions for OpenCode" height="96">
|
|
3
|
+
</h1>
|
|
4
|
+
|
|
5
|
+
<p align="center">
|
|
6
|
+
<a href="https://github.com/ozandogrultan/opencode-ghost/actions/workflows/ci.yml"><img src="https://github.com/ozandogrultan/opencode-ghost/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
|
|
7
|
+
<a href="https://www.npmjs.com/package/opencode-ghost"><img src="https://img.shields.io/npm/v/opencode-ghost" alt="npm"></a>
|
|
8
|
+
<a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License: MIT"></a>
|
|
9
|
+
<a href="#contributing"><img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg" alt="PRs welcome"></a>
|
|
10
|
+
<a href="https://github.com/ozandogrultan/opencode-ghost/stargazers"><img src="https://img.shields.io/github/stars/ozandogrultan/opencode-ghost.svg?style=social" alt="GitHub stars"></a>
|
|
11
|
+
</p>
|
|
4
12
|
|
|
5
13
|
An **OpenCode V2 TUI plugin** providing next-prompt suggestions, in the
|
|
6
14
|
style of Claude Code: after each turn a small model reads the recent
|
|
@@ -24,11 +32,12 @@ a dimmed inline placeholder in the empty composer with
|
|
|
24
32
|
- **Hides as you type.** Typing and pasting abort pending generation and hide the
|
|
25
33
|
preview. Emptying the composer restores the same suggestion without another
|
|
26
34
|
API call; focus changes also reuse it. Navigation keys leave it intact.
|
|
27
|
-
- **`/suggest`
|
|
35
|
+
- **`/suggest` controls it.** Toggle suggestions, set a runtime model override,
|
|
36
|
+
or inspect live state and diagnostics; settings persist via the plugin's storage.
|
|
28
37
|
|
|
29
38
|
## Requirements
|
|
30
39
|
|
|
31
|
-
- [opencode](https://opencode.ai) v2 (TUI plugins
|
|
40
|
+
- [opencode](https://opencode.ai) v2 (TUI plugins).
|
|
32
41
|
- A provider/model and authentication method that support OpenCode's stateless
|
|
33
42
|
`generate.text` endpoint. Set `model` explicitly if no default small model is available.
|
|
34
43
|
|
|
@@ -46,7 +55,7 @@ Add the package to your `cli.json` (normally `~/.config/opencode/cli.json`):
|
|
|
46
55
|
```
|
|
47
56
|
|
|
48
57
|
Then **restart opencode**; it installs the package on startup. Pin a version
|
|
49
|
-
with `"opencode-ghost
|
|
58
|
+
with `"opencode-ghost@<version>"`, or change the version and restart to update.
|
|
50
59
|
Pass options with the object form shown under [Manually](#manually), using
|
|
51
60
|
`"package": "opencode-ghost"`.
|
|
52
61
|
|
|
@@ -132,12 +141,12 @@ still enforces `maxChars` when normalizing the displayed suggestion.
|
|
|
132
141
|
- `/suggest model openai/gpt-6-luna-fast` — set a persisted runtime model override.
|
|
133
142
|
- `/suggest model clear` — clear the override and use the configured `model`,
|
|
134
143
|
or the OpenCode small default, never the main model.
|
|
135
|
-
- `/suggest debug` — toggle debug mode (persisted). While on, each
|
|
136
|
-
|
|
137
|
-
the error.
|
|
144
|
+
- `/suggest debug` — toggle debug mode (persisted). While on, each non-aborted
|
|
145
|
+
generation outcome and each display change shows a toast.
|
|
138
146
|
- `/suggest debug on` / `/suggest debug off` — set debug mode explicitly.
|
|
139
|
-
- `/suggest log` — show the last 20
|
|
140
|
-
total and stage latency, length and error
|
|
147
|
+
- `/suggest log` — show live state, the last 20 display changes, and the last 20
|
|
148
|
+
generation attempts (outcome, model, total and stage latency, length and error
|
|
149
|
+
detail) in a dialog, regardless of debug mode.
|
|
141
150
|
|
|
142
151
|
Model precedence is the persisted `/suggest model` override, then the `model`
|
|
143
152
|
option, then the effective title agent's model from OpenCode's public agent API.
|
|
@@ -145,7 +154,7 @@ OpenCode resolves inherited `agents.title.model`, migrated legacy `small_model`,
|
|
|
145
154
|
and directory definitions such as `agents/title.md` and `agent/title.md`, including
|
|
146
155
|
agent deletion/recreation. Explicitly configured variants are preserved.
|
|
147
156
|
Without a configured title model, or when the title agent is disabled, Ghost
|
|
148
|
-
mirrors OpenCode
|
|
157
|
+
mirrors OpenCode's internal small-model policy until a public API exists:
|
|
149
158
|
within the session model's provider (or the session agent model's provider,
|
|
150
159
|
then the location's default provider, then the first enabled text model's
|
|
151
160
|
provider when no default exists), choose
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-ghost",
|
|
3
|
-
"version": "1.3.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.3.12",
|
|
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",
|
|
7
7
|
"author": "Ozan Dogrultan",
|
|
@@ -20,7 +20,9 @@
|
|
|
20
20
|
"ghost-text",
|
|
21
21
|
"autosuggest",
|
|
22
22
|
"prompt",
|
|
23
|
-
"suggestion"
|
|
23
|
+
"suggestion",
|
|
24
|
+
"next-prompt",
|
|
25
|
+
"opencode-tui"
|
|
24
26
|
],
|
|
25
27
|
"exports": {
|
|
26
28
|
"./tui": "./src/tui.tsx"
|
|
@@ -36,7 +38,7 @@
|
|
|
36
38
|
},
|
|
37
39
|
"packageManager": "bun@1.4.2",
|
|
38
40
|
"engines": {
|
|
39
|
-
"opencode": ">=2.0
|
|
41
|
+
"opencode": ">=2.1.0"
|
|
40
42
|
},
|
|
41
43
|
"scripts": {
|
|
42
44
|
"prepare": "husky",
|
|
@@ -48,8 +50,8 @@
|
|
|
48
50
|
"prepublishOnly": "bun run test && bun run typecheck"
|
|
49
51
|
},
|
|
50
52
|
"dependencies": {
|
|
51
|
-
"@opentui/core": "^0.
|
|
52
|
-
"@opentui/solid": "^0.
|
|
53
|
+
"@opentui/core": "^0.6.6",
|
|
54
|
+
"@opentui/solid": "^0.6.6"
|
|
53
55
|
},
|
|
54
56
|
"peerDependencies": {
|
|
55
57
|
"@opencode/plugin": "*",
|
|
@@ -58,11 +60,11 @@
|
|
|
58
60
|
"devDependencies": {
|
|
59
61
|
"@commitlint/cli": "^21.2.2",
|
|
60
62
|
"@commitlint/config-conventional": "^21.2.2",
|
|
61
|
-
"@opencode/plugin": "2.0.
|
|
62
|
-
"@types/bun": "^1.4.
|
|
63
|
-
"@types/node": "
|
|
63
|
+
"@opencode/plugin": "2.0.32",
|
|
64
|
+
"@types/bun": "^1.4.3",
|
|
65
|
+
"@types/node": "26.6.5",
|
|
64
66
|
"husky": "^9.1.7",
|
|
65
|
-
"solid-js": "
|
|
67
|
+
"solid-js": "1.9.12",
|
|
66
68
|
"typescript": "7.0.2"
|
|
67
69
|
}
|
|
68
70
|
}
|
package/src/composer.ts
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
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
|
|
4
|
+
if (removesOnly(event)) return true
|
|
5
|
+
if (event.ctrl && !event.meta && !event.option && !event.super && !event.hyper) return ["v", "j", "m", "-", "."].includes(event.name)
|
|
5
6
|
if (event.super && !event.ctrl && !event.meta && !event.option && !event.hyper && event.name === "z") return true
|
|
6
7
|
if (event.ctrl || event.meta || event.option || event.super || event.hyper) return false
|
|
7
|
-
if (["return", "enter", "linefeed", "
|
|
8
|
+
if (["return", "enter", "linefeed", "space"].includes(event.name)) return true
|
|
8
9
|
return [...event.sequence].length === 1 && !/[\u0000-\u001f\u007f]/.test(event.sequence)
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
export function removesOnly(event: { name: string; ctrl: boolean; meta: boolean; option?: boolean; super?: boolean; hyper?: boolean }): boolean {
|
|
12
13
|
if (event.ctrl && !event.meta && !event.option && !event.super && !event.hyper) return ["h", "d", "k", "u", "w"].includes(event.name)
|
|
14
|
+
if ((event.meta || event.option) && !event.ctrl && !event.super && !event.hyper) return ["backspace", "delete", "d"].includes(event.name)
|
|
15
|
+
if (event.super && !event.ctrl && !event.meta && !event.option && !event.hyper) return event.name === "backspace"
|
|
13
16
|
if (event.ctrl || event.meta || event.option || event.super || event.hyper) return false
|
|
14
17
|
return event.name === "backspace" || event.name === "delete"
|
|
15
18
|
}
|
|
@@ -85,8 +88,10 @@ export function composerAction(editor: Editor | undefined, focused: () => unknow
|
|
|
85
88
|
if (editor.plainText.length !== 0) return false
|
|
86
89
|
try {
|
|
87
90
|
editor.insertText(text)
|
|
88
|
-
|
|
89
|
-
|
|
91
|
+
return true
|
|
92
|
+
} catch {
|
|
93
|
+
return false
|
|
94
|
+
}
|
|
90
95
|
}
|
|
91
96
|
|
|
92
97
|
export function keyName(event: { name: string; ctrl: boolean; meta: boolean; shift: boolean; option?: boolean; super?: boolean; hyper?: boolean }): string {
|
package/src/options.ts
CHANGED
|
@@ -76,11 +76,11 @@ export function resolveOptions(options: Readonly<Record<string, unknown>> | unde
|
|
|
76
76
|
enabled: typeof input.enabled === "boolean" ? input.enabled : DEFAULTS.enabled,
|
|
77
77
|
model: typeof input.model === "string" && input.model.trim() ? input.model.trim() : undefined,
|
|
78
78
|
acceptKeys: acceptKeys.length > 0 ? acceptKeys : [...DEFAULTS.acceptKeys],
|
|
79
|
-
maxChars: typeof maxChars === "number" && maxChars > 0 ? maxChars : DEFAULTS.maxChars,
|
|
79
|
+
maxChars: typeof maxChars === "number" && Number.isInteger(maxChars) && maxChars > 0 ? maxChars : DEFAULTS.maxChars,
|
|
80
80
|
idleDelayMs:
|
|
81
|
-
typeof idleDelayMs === "number" && idleDelayMs >= 0 ? idleDelayMs : DEFAULTS.idleDelayMs,
|
|
81
|
+
typeof idleDelayMs === "number" && Number.isFinite(idleDelayMs) && idleDelayMs >= 0 ? idleDelayMs : DEFAULTS.idleDelayMs,
|
|
82
82
|
recentMessages:
|
|
83
|
-
typeof recentMessages === "number" && recentMessages > 0
|
|
83
|
+
typeof recentMessages === "number" && Number.isInteger(recentMessages) && recentMessages > 0
|
|
84
84
|
? recentMessages
|
|
85
85
|
: DEFAULTS.recentMessages,
|
|
86
86
|
system: typeof input.system === "string" && input.system.trim() ? input.system : DEFAULT_SYSTEM,
|
package/src/placeholder.ts
CHANGED
|
@@ -6,6 +6,8 @@ export function dimPlaceholderColor(muted: RGBA): RGBA {
|
|
|
6
6
|
return RGBA.fromValues(muted.r, muted.g, muted.b, muted.a * 0.55)
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
+
const sameColor = (a: RGBA, b: RGBA) => a.equals(b)
|
|
10
|
+
|
|
9
11
|
export function createInlinePlaceholder() {
|
|
10
12
|
let owned: {
|
|
11
13
|
editor: PlaceholderEditor
|
|
@@ -21,7 +23,7 @@ export function createInlinePlaceholder() {
|
|
|
21
23
|
owned = undefined
|
|
22
24
|
if (editor.isDestroyed) return
|
|
23
25
|
if (editor.placeholder === text) editor.placeholder = original
|
|
24
|
-
if (editor.placeholderColor
|
|
26
|
+
if (sameColor(editor.placeholderColor, color)) editor.placeholderColor = originalColor
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
return {
|
|
@@ -39,10 +41,10 @@ export function createInlinePlaceholder() {
|
|
|
39
41
|
owned = { editor, original: editor.placeholder, originalColor: editor.placeholderColor, text, color }
|
|
40
42
|
} else {
|
|
41
43
|
if (editor.placeholder !== owned.text) owned.original = editor.placeholder
|
|
42
|
-
if (editor.placeholderColor
|
|
44
|
+
if (!sameColor(editor.placeholderColor, owned.color)) owned.originalColor = editor.placeholderColor
|
|
43
45
|
owned.text = text
|
|
44
46
|
}
|
|
45
|
-
if (editor.placeholderColor
|
|
47
|
+
if (!sameColor(editor.placeholderColor, color)) editor.placeholderColor = color
|
|
46
48
|
owned.color = editor.placeholderColor
|
|
47
49
|
if (editor.placeholder !== text) editor.placeholder = text
|
|
48
50
|
},
|
package/src/text.ts
CHANGED
|
@@ -157,14 +157,16 @@ export function collapse(text: string): string {
|
|
|
157
157
|
|
|
158
158
|
export function clip(text: string, max: number): string {
|
|
159
159
|
const value = collapse(text)
|
|
160
|
-
|
|
161
|
-
|
|
160
|
+
const points = [...value]
|
|
161
|
+
if (points.length <= max) return value
|
|
162
|
+
return points.slice(0, max - 1).join("").trimEnd() + "…"
|
|
162
163
|
}
|
|
163
164
|
|
|
164
165
|
export function clipTail(text: string, max: number): string {
|
|
165
166
|
const value = collapse(text)
|
|
166
|
-
|
|
167
|
-
|
|
167
|
+
const points = [...value]
|
|
168
|
+
if (points.length <= max) return value
|
|
169
|
+
return "…" + points.slice(points.length - (max - 1)).join("").trimStart()
|
|
168
170
|
}
|
|
169
171
|
|
|
170
172
|
export function normalize(raw: string, maxChars: number): string | undefined {
|
|
@@ -176,9 +178,10 @@ export function normalize(raw: string, maxChars: number): string | undefined {
|
|
|
176
178
|
const cleaned = first
|
|
177
179
|
.replace(/\*\*([^*]+)\*\*/g, "$1")
|
|
178
180
|
.replace(/^[`"'*\-_#\s]+/, "")
|
|
181
|
+
.replace(/^next user message:\s*/i, "")
|
|
182
|
+
.replace(/^[`"'*\-_#\s]+/, "")
|
|
179
183
|
.replace(/[`"'*_#\s]+$/, "")
|
|
180
184
|
.replace(/`+/g, "")
|
|
181
|
-
.replace(/^next user message:\s*/i, "")
|
|
182
185
|
.trim()
|
|
183
186
|
if (!cleaned || /^none\.?$/i.test(cleaned)) return undefined
|
|
184
187
|
const points = [...cleaned]
|
package/src/tui.tsx
CHANGED
|
@@ -98,7 +98,11 @@ export default Plugin.define({
|
|
|
98
98
|
try {
|
|
99
99
|
await measure("syncMs", () => context.data.session.message.sync(sessionID))
|
|
100
100
|
syncing = false
|
|
101
|
-
if (signal.aborted
|
|
101
|
+
if (signal.aborted) return
|
|
102
|
+
if (!canGenerate(sessionID)) {
|
|
103
|
+
cancelSuggestion()
|
|
104
|
+
return
|
|
105
|
+
}
|
|
102
106
|
const messages = context.data.session.message.list(sessionID) as readonly TranscriptMessage[]
|
|
103
107
|
const transcript = buildTranscript(messages, opts.recentMessages)
|
|
104
108
|
if (!transcript) return
|
|
@@ -108,7 +112,11 @@ export default Plugin.define({
|
|
|
108
112
|
model = await measure("modelMs", () => explicit
|
|
109
113
|
? resolveExplicitModel(context.client, location, signal, explicit, catalog)
|
|
110
114
|
: resolveSmallModel(context.client, location, signal, session, catalog))
|
|
111
|
-
if (signal.aborted
|
|
115
|
+
if (signal.aborted) return
|
|
116
|
+
if (!canGenerate(sessionID)) {
|
|
117
|
+
cancelSuggestion()
|
|
118
|
+
return
|
|
119
|
+
}
|
|
112
120
|
if (!model) return
|
|
113
121
|
const raw = await measure("generationMs", () => generateSuggestion(
|
|
114
122
|
context.client,
|
|
@@ -124,14 +132,18 @@ export default Plugin.define({
|
|
|
124
132
|
noteGeneration({ outcome: "error", model: label, detail: errorDetail(failure) })
|
|
125
133
|
return
|
|
126
134
|
}
|
|
135
|
+
if (!canGenerate(sessionID)) {
|
|
136
|
+
cancelSuggestion()
|
|
137
|
+
return
|
|
138
|
+
}
|
|
127
139
|
if (!raw) {
|
|
128
|
-
if (!canGenerate(sessionID)) return
|
|
129
140
|
noteGeneration({ outcome: "empty", model: label })
|
|
130
141
|
return
|
|
131
142
|
}
|
|
132
143
|
const clean = normalize(raw, opts.maxChars)
|
|
133
144
|
if (!clean) {
|
|
134
|
-
|
|
145
|
+
const none = /^none\.?$/i.test(raw.trim())
|
|
146
|
+
noteGeneration({ outcome: "empty", model: label, ...(none ? {} : { chars: raw.length }) })
|
|
135
147
|
return
|
|
136
148
|
}
|
|
137
149
|
const previous = lastUserText(messages)
|
|
@@ -139,7 +151,6 @@ export default Plugin.define({
|
|
|
139
151
|
noteGeneration({ outcome: "echo", model: label, chars: clean.length })
|
|
140
152
|
return
|
|
141
153
|
}
|
|
142
|
-
if (!canGenerate(sessionID)) return
|
|
143
154
|
setSuggestion({ sessionID, text: clean })
|
|
144
155
|
noteGeneration({ outcome: "ok", model: label, chars: clean.length })
|
|
145
156
|
} catch (error) {
|
|
@@ -299,6 +310,7 @@ export default Plugin.define({
|
|
|
299
310
|
lifecycle.resetWarning()
|
|
300
311
|
catalog.clear()
|
|
301
312
|
await updateState((draft) => { draft.model = command.model })
|
|
313
|
+
cancelSuggestion()
|
|
302
314
|
context.ui.toast.show({ message: `Suggestion model: ${state.model ?? opts.model ?? "OpenCode small default"}` })
|
|
303
315
|
return
|
|
304
316
|
}
|
|
@@ -351,6 +363,7 @@ export default Plugin.define({
|
|
|
351
363
|
await updateState((draft) => {
|
|
352
364
|
draft.enabled = next
|
|
353
365
|
})
|
|
366
|
+
cancelSuggestion()
|
|
354
367
|
if (!next) {
|
|
355
368
|
context.ui.toast.show({ message: "Prompt suggestions: off" })
|
|
356
369
|
return
|