opencode-quill 0.2.2 → 0.3.1
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 +18 -0
- package/README.md +25 -7
- package/package.json +6 -6
- package/src/predictor.ts +59 -12
- package/src/prose.ts +3 -3
- package/src/tui.tsx +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,22 @@ All notable changes are documented in this file using
|
|
|
4
4
|
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and
|
|
5
5
|
[Semantic Versioning](https://semver.org/).
|
|
6
6
|
|
|
7
|
+
## [0.3.1] - 2026-10-20
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- **deps:** Require opentui 0.6 for opencode 2.1
|
|
12
|
+
|
|
13
|
+
## [0.3.0] - 2026-10-15
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
|
|
17
|
+
- **prediction:** Learn casing, hide fragments, and decay old counts
|
|
18
|
+
|
|
19
|
+
### Changed
|
|
20
|
+
|
|
21
|
+
- **learning:** Stop re-sorting sessions once the backfill is seeded
|
|
22
|
+
|
|
7
23
|
## [0.2.2] - 2026-10-15
|
|
8
24
|
|
|
9
25
|
### Changed
|
|
@@ -68,6 +84,8 @@ All notable changes are documented in this file using
|
|
|
68
84
|
- `/quill` command and command palette action to toggle autocomplete.
|
|
69
85
|
- Local installer script, full test suite, CI workflows, and release tooling.
|
|
70
86
|
|
|
87
|
+
[0.3.1]: https://github.com/ozandogrultan/opencode-quill/compare/v0.3.0...v0.3.1
|
|
88
|
+
[0.3.0]: https://github.com/ozandogrultan/opencode-quill/compare/v0.2.2...v0.3.0
|
|
71
89
|
[0.2.2]: https://github.com/ozandogrultan/opencode-quill/compare/v0.2.1...v0.2.2
|
|
72
90
|
[0.2.1]: https://github.com/ozandogrultan/opencode-quill/compare/v0.2.0...v0.2.1
|
|
73
91
|
[0.2.0]: https://github.com/ozandogrultan/opencode-quill/compare/v0.1.5...v0.2.0
|
package/README.md
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
<h1 align="center">
|
|
2
|
+
<picture>
|
|
3
|
+
<source media="(prefers-color-scheme: dark)" srcset="assets/logo-dark.svg">
|
|
4
|
+
<img src="assets/logo.svg" alt="quill" height="96">
|
|
5
|
+
</picture>
|
|
6
|
+
</h1>
|
|
7
|
+
|
|
8
|
+
<p align="center">
|
|
9
|
+
<a href="https://github.com/ozandogrultan/opencode-quill/actions/workflows/ci.yml"><img src="https://github.com/ozandogrultan/opencode-quill/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
|
|
10
|
+
<a href="https://www.npmjs.com/package/opencode-quill"><img src="https://img.shields.io/npm/v/opencode-quill" alt="npm"></a>
|
|
11
|
+
<a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License: MIT"></a>
|
|
12
|
+
<a href="#contributing"><img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg" alt="PRs welcome"></a>
|
|
13
|
+
<a href="https://github.com/ozandogrultan/opencode-quill/stargazers"><img src="https://img.shields.io/github/stars/ozandogrultan/opencode-quill.svg?style=social" alt="GitHub stars"></a>
|
|
14
|
+
</p>
|
|
4
15
|
|
|
5
16
|
Local word autocomplete and next-word prediction for the **OpenCode V2** prompt
|
|
6
17
|
composer — inspired by [oh-my-pi (OMP)](https://github.com/can1357/oh-my-pi)'s
|
|
@@ -58,6 +69,9 @@ A correction looks like this, with only ` → complete` dimmed:
|
|
|
58
69
|
First-person contractions use a capital `I` in corrections and next-word
|
|
59
70
|
suggestions (`I'm`, `I'll`, `I've`, `I'd`). Lowercase contraction prefixes
|
|
60
71
|
are replaced on acceptance too (`i'v` → `I've`).
|
|
72
|
+
- **Learned casing is kept.** A word you usually capitalize mid-sentence is
|
|
73
|
+
suggested that way: `oz` shows ` → Ozan` and replaces the word, while `Oz`
|
|
74
|
+
completes with `an`.
|
|
61
75
|
- **Normal completions take precedence.** For example, `whate` completes to
|
|
62
76
|
`whatever` rather than being corrected to `what`. Typo correction is a
|
|
63
77
|
fallback when no confident prefix completion is available; recognized words
|
|
@@ -186,7 +200,10 @@ Quill learns from your own submitted prompts, never from assistant output:
|
|
|
186
200
|
- Punctuation, line breaks and code reset the context, so words separated by
|
|
187
201
|
syntax are never learned as adjacent.
|
|
188
202
|
- A word missing from the base vocabulary becomes suggestible only after it
|
|
189
|
-
has been seen more than once
|
|
203
|
+
has been seen more than once, and not while it is a prefix of a learned word
|
|
204
|
+
you use at least as often (`addr` yields to `addressed`).
|
|
205
|
+
- Casing is learned from words written mid-sentence; sentence-initial
|
|
206
|
+
capitals are ignored.
|
|
190
207
|
|
|
191
208
|
### Prediction
|
|
192
209
|
|
|
@@ -214,7 +231,8 @@ Quill learns from your own submitted prompts, never from assistant output:
|
|
|
214
231
|
and requires repeated learned continuation evidence; not every typo produces
|
|
215
232
|
a suggestion.
|
|
216
233
|
- **Bounded size:** the personal model is pruned to its most frequent entries
|
|
217
|
-
when saved.
|
|
234
|
+
when saved. Once it holds about 100,000 learned words, every count is halved
|
|
235
|
+
and single-use entries are dropped, so recent habits outweigh old ones.
|
|
218
236
|
|
|
219
237
|
### Storage
|
|
220
238
|
|
|
@@ -226,8 +244,8 @@ state directory (`$XDG_STATE_HOME` when set, otherwise `~/.local/state`):
|
|
|
226
244
|
| Learned model | `opencode/<channel>/tui/plugin.quill.learning.json` |
|
|
227
245
|
| Settings | `opencode/<channel>/tui/plugin.quill.settings.json` |
|
|
228
246
|
|
|
229
|
-
The learned model holds only word, bigram and
|
|
230
|
-
message IDs. Raw prompt text is never written to disk. These files stay on your
|
|
247
|
+
The learned model holds only word, bigram, trigram and word-casing counts plus
|
|
248
|
+
processed message IDs. Raw prompt text is never written to disk. These files stay on your
|
|
231
249
|
machine and are never tracked in Git or published to npm.
|
|
232
250
|
|
|
233
251
|
## Development
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-quill",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "OpenCode prompt autocomplete: local n-gram word and next-word prediction shown as inline ghost text in the TUI composer, accepted with Tab.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
},
|
|
40
40
|
"packageManager": "bun@1.4.2",
|
|
41
41
|
"engines": {
|
|
42
|
-
"opencode": ">=2.0
|
|
42
|
+
"opencode": ">=2.1.0"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
45
|
"prepare": "husky",
|
|
@@ -51,8 +51,8 @@
|
|
|
51
51
|
"prepublishOnly": "bun run test && bun run typecheck"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@opentui/core": "^0.
|
|
55
|
-
"@opentui/solid": "^0.
|
|
54
|
+
"@opentui/core": "^0.6.6",
|
|
55
|
+
"@opentui/solid": "^0.6.6",
|
|
56
56
|
"subtlex-word-frequencies": "2.0.0"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
@@ -62,9 +62,9 @@
|
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@commitlint/cli": "^21.2.2",
|
|
64
64
|
"@commitlint/config-conventional": "^21.2.2",
|
|
65
|
-
"@opencode/plugin": "2.0.
|
|
65
|
+
"@opencode/plugin": "2.0.29",
|
|
66
66
|
"@types/bun": "^1.4.2",
|
|
67
|
-
"@types/node": "26.6.
|
|
67
|
+
"@types/node": "26.6.5",
|
|
68
68
|
"husky": "^9.1.7",
|
|
69
69
|
"solid-js": "1.9.12",
|
|
70
70
|
"typescript": "7.0.2"
|
package/src/predictor.ts
CHANGED
|
@@ -6,6 +6,7 @@ export type Snapshot = {
|
|
|
6
6
|
words: [string, number][]
|
|
7
7
|
bigrams: [string, number][]
|
|
8
8
|
trigrams: [string, number][]
|
|
9
|
+
forms?: [string, number][]
|
|
9
10
|
seen: string[]
|
|
10
11
|
}
|
|
11
12
|
export type Prompt = { id: string; text: string }
|
|
@@ -17,9 +18,16 @@ const PRIOR_LIMIT = 20_000
|
|
|
17
18
|
const WORD_LIMIT = 8000
|
|
18
19
|
const CONTEXT_LIMIT = 30_000
|
|
19
20
|
const SEEN_LIMIT = 8000
|
|
21
|
+
const DECAY_TOTAL = 100_000
|
|
20
22
|
|
|
21
23
|
export function emptySnapshot(): Snapshot {
|
|
22
|
-
return { version: 1, words: [], bigrams: [], trigrams: [], seen: [] }
|
|
24
|
+
return { version: 1, words: [], bigrams: [], trigrams: [], forms: [], seen: [] }
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function sentenceStart(text: string, start: number): boolean {
|
|
28
|
+
let index = start - 1
|
|
29
|
+
while (index >= 0 && /[ \t"“‘(\[*>#-]/.test(text[index])) index--
|
|
30
|
+
return index < 0 || /[\n.!?:]/.test(text[index])
|
|
23
31
|
}
|
|
24
32
|
|
|
25
33
|
function restore(rows: [string, number][], limit: number): Map<string, number> {
|
|
@@ -38,12 +46,14 @@ export class PersonalModel {
|
|
|
38
46
|
readonly words: Map<string, number>
|
|
39
47
|
readonly bigrams: Map<string, number>
|
|
40
48
|
readonly trigrams: Map<string, number>
|
|
49
|
+
readonly forms: Map<string, number>
|
|
41
50
|
readonly seen: Set<string>
|
|
42
51
|
|
|
43
52
|
constructor(snapshot: Snapshot = emptySnapshot()) {
|
|
44
53
|
this.words = restore(snapshot.words, WORD_LIMIT)
|
|
45
54
|
this.bigrams = restore(snapshot.bigrams, CONTEXT_LIMIT)
|
|
46
55
|
this.trigrams = restore(snapshot.trigrams, CONTEXT_LIMIT)
|
|
56
|
+
this.forms = restore(snapshot.forms ?? [], WORD_LIMIT)
|
|
47
57
|
this.seen = new Set(snapshot.seen.slice(-SEEN_LIMIT))
|
|
48
58
|
}
|
|
49
59
|
|
|
@@ -55,10 +65,24 @@ export class PersonalModel {
|
|
|
55
65
|
changed = true
|
|
56
66
|
if (prompt.text.length > 4000 || prompt.text.split("\n").length > 12) continue
|
|
57
67
|
for (const sequence of proseSequences(prompt.text)) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
68
|
+
const words = sequence.map((word) => word.text)
|
|
69
|
+
for (let index = 0; index < words.length; index++) {
|
|
70
|
+
const { start, end } = sequence[index]
|
|
71
|
+
increment(this.words, words[index])
|
|
72
|
+
const form = prompt.text.slice(start, end).normalize("NFC").replaceAll("’", "'")
|
|
73
|
+
if (form !== words[index] && !sentenceStart(prompt.text, start)) increment(this.forms, form)
|
|
74
|
+
if (index > 0) increment(this.bigrams, `${words[index - 1]}\0${words[index]}`)
|
|
75
|
+
if (index > 1) increment(this.trigrams, `${words[index - 2]}\0${words[index - 1]}\0${words[index]}`)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
let total = 0
|
|
80
|
+
for (const count of this.words.values()) total += count
|
|
81
|
+
if (total > DECAY_TOTAL) {
|
|
82
|
+
for (const map of [this.words, this.bigrams, this.trigrams, this.forms]) {
|
|
83
|
+
for (const [key, count] of map) {
|
|
84
|
+
if (count > 1) map.set(key, Math.floor(count / 2))
|
|
85
|
+
else map.delete(key)
|
|
62
86
|
}
|
|
63
87
|
}
|
|
64
88
|
}
|
|
@@ -71,6 +95,7 @@ export class PersonalModel {
|
|
|
71
95
|
words: trim(this.words, WORD_LIMIT),
|
|
72
96
|
bigrams: trim(this.bigrams, CONTEXT_LIMIT),
|
|
73
97
|
trigrams: trim(this.trigrams, CONTEXT_LIMIT),
|
|
98
|
+
forms: trim(this.forms, WORD_LIMIT),
|
|
74
99
|
seen: [...this.seen].slice(-SEEN_LIMIT),
|
|
75
100
|
}
|
|
76
101
|
}
|
|
@@ -166,6 +191,7 @@ export class WordPredictor {
|
|
|
166
191
|
private bigramTotals = new Map<string, { total: number; types: number }>()
|
|
167
192
|
private trigramTotals = new Map<string, { total: number; types: number }>()
|
|
168
193
|
private vocabulary: string[] = []
|
|
194
|
+
private forms = new Map<string, string>()
|
|
169
195
|
|
|
170
196
|
constructor(prior: readonly Frequency[]) {
|
|
171
197
|
for (const { word, count } of prior) {
|
|
@@ -183,7 +209,26 @@ export class WordPredictor {
|
|
|
183
209
|
this.personalTotal = [...this.personal.words.values()].reduce((sum, count) => sum + count, 0)
|
|
184
210
|
this.bigramTotals = totals(this.personal.bigrams)
|
|
185
211
|
this.trigramTotals = totals(this.personal.trigrams)
|
|
186
|
-
|
|
212
|
+
const counts = this.personal.words
|
|
213
|
+
const learned = [...counts].filter(([, count]) => count >= 2).map(([word]) => word).sort()
|
|
214
|
+
const fragments = new Set<string>()
|
|
215
|
+
for (let index = 0; index < learned.length; index++) {
|
|
216
|
+
const word = learned[index]
|
|
217
|
+
if (this.prior.has(word)) continue
|
|
218
|
+
for (let next = index + 1; next < learned.length && learned[next].startsWith(word); next++) {
|
|
219
|
+
if (counts.get(learned[next])! >= counts.get(word)!) {
|
|
220
|
+
fragments.add(word)
|
|
221
|
+
break
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
this.vocabulary = [...new Set([...this.prior.keys(), ...learned.filter((word) => !fragments.has(word))])].sort()
|
|
226
|
+
const forms = new Map<string, [string, number]>()
|
|
227
|
+
for (const [form, count] of this.personal.forms) {
|
|
228
|
+
const word = normalizeWord(form)
|
|
229
|
+
if ((forms.get(word)?.[1] ?? 0) < count) forms.set(word, [form, count])
|
|
230
|
+
}
|
|
231
|
+
this.forms = new Map([...forms].filter(([word, [, count]]) => count * 2 > (counts.get(word) ?? 0)).map(([word, [form]]) => [word, form]))
|
|
187
232
|
}
|
|
188
233
|
|
|
189
234
|
private *nearbyWords(prefix: string, wholeWord = false): IterableIterator<string> {
|
|
@@ -278,13 +323,15 @@ export class WordPredictor {
|
|
|
278
323
|
}
|
|
279
324
|
const confidence = bestWeight < 1 ? typoConfidence(bestScore, sum) : query.next ? bestScore : bestScore / (sum || 1)
|
|
280
325
|
if (!best || best === prefix || confidence === undefined || (bestWeight === 1 && confidence < (query.next ? 0.55 : 0.3))) return
|
|
281
|
-
|
|
282
|
-
|
|
326
|
+
const form = this.forms.get(best) ?? best
|
|
327
|
+
const shouting = query.prefix.length > 1 && query.prefix === query.prefix.toUpperCase()
|
|
328
|
+
if (bestWeight < 1 || (!query.next && best.startsWith("i'") && query.prefix[0] === "i") ||
|
|
329
|
+
(!query.next && !shouting && form !== best && !form.startsWith(query.prefix))) {
|
|
330
|
+
return { suffix: applyCase(query.prefix, form), word: best, confidence, replace: query.prefix.length }
|
|
283
331
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
return { suffix, word: best, confidence }
|
|
332
|
+
if (query.next) return { suffix: applyCase("", form), word: best, confidence }
|
|
333
|
+
const suffix = form.slice(prefix.length)
|
|
334
|
+
return { suffix: shouting ? suffix.toUpperCase() : suffix, word: best, confidence }
|
|
288
335
|
}
|
|
289
336
|
const completion = suggest()
|
|
290
337
|
if (completion || query.next || prefix.length < 3 || candidates.has(prefix)) return completion
|
package/src/prose.ts
CHANGED
|
@@ -38,13 +38,13 @@ export function proseWords(text: string, masked = maskProse(text)): Word[] {
|
|
|
38
38
|
.map((match) => ({ text: normalizeWord(match[0]), start: match.index, end: match.index + match[0].length }))
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
export function proseSequences(text: string):
|
|
41
|
+
export function proseSequences(text: string): Word[][] {
|
|
42
42
|
const words = proseWords(text)
|
|
43
|
-
const sequences:
|
|
43
|
+
const sequences: Word[][] = []
|
|
44
44
|
let previous = -1
|
|
45
45
|
for (const word of words) {
|
|
46
46
|
if (previous < 0 || !/^[ \t]+$/.test(text.slice(previous, word.start))) sequences.push([])
|
|
47
|
-
sequences.at(-1)!.push(word
|
|
47
|
+
sequences.at(-1)!.push(word)
|
|
48
48
|
previous = word.end
|
|
49
49
|
}
|
|
50
50
|
return sequences
|
package/src/tui.tsx
CHANGED
|
@@ -139,6 +139,7 @@ export default Plugin.define({
|
|
|
139
139
|
if (!settings.enabled) return
|
|
140
140
|
const route = context.ui.router.current()
|
|
141
141
|
if (route.type === "session") untrack(() => { void learn(route.sessionID, false) })
|
|
142
|
+
if (seeded.size >= 8) return
|
|
142
143
|
for (const session of context.data.session.list().filter((session) => !session.parentID).sort((a, b) => b.time.updated - a.time.updated).slice(0, 8)) {
|
|
143
144
|
if (seeded.has(session.id)) continue
|
|
144
145
|
seeded.add(session.id)
|