opencode-quill 0.2.2 → 0.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 +11 -0
- package/README.md +11 -4
- package/package.json +1 -1
- 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,16 @@ 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.0] - 2026-10-15
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- **prediction:** Learn casing, hide fragments, and decay old counts
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
|
|
15
|
+
- **learning:** Stop re-sorting sessions once the backfill is seeded
|
|
16
|
+
|
|
7
17
|
## [0.2.2] - 2026-10-15
|
|
8
18
|
|
|
9
19
|
### Changed
|
|
@@ -68,6 +78,7 @@ All notable changes are documented in this file using
|
|
|
68
78
|
- `/quill` command and command palette action to toggle autocomplete.
|
|
69
79
|
- Local installer script, full test suite, CI workflows, and release tooling.
|
|
70
80
|
|
|
81
|
+
[0.3.0]: https://github.com/ozandogrultan/opencode-quill/compare/v0.2.2...v0.3.0
|
|
71
82
|
[0.2.2]: https://github.com/ozandogrultan/opencode-quill/compare/v0.2.1...v0.2.2
|
|
72
83
|
[0.2.1]: https://github.com/ozandogrultan/opencode-quill/compare/v0.2.0...v0.2.1
|
|
73
84
|
[0.2.0]: https://github.com/ozandogrultan/opencode-quill/compare/v0.1.5...v0.2.0
|
package/README.md
CHANGED
|
@@ -58,6 +58,9 @@ A correction looks like this, with only ` → complete` dimmed:
|
|
|
58
58
|
First-person contractions use a capital `I` in corrections and next-word
|
|
59
59
|
suggestions (`I'm`, `I'll`, `I've`, `I'd`). Lowercase contraction prefixes
|
|
60
60
|
are replaced on acceptance too (`i'v` → `I've`).
|
|
61
|
+
- **Learned casing is kept.** A word you usually capitalize mid-sentence is
|
|
62
|
+
suggested that way: `oz` shows ` → Ozan` and replaces the word, while `Oz`
|
|
63
|
+
completes with `an`.
|
|
61
64
|
- **Normal completions take precedence.** For example, `whate` completes to
|
|
62
65
|
`whatever` rather than being corrected to `what`. Typo correction is a
|
|
63
66
|
fallback when no confident prefix completion is available; recognized words
|
|
@@ -186,7 +189,10 @@ Quill learns from your own submitted prompts, never from assistant output:
|
|
|
186
189
|
- Punctuation, line breaks and code reset the context, so words separated by
|
|
187
190
|
syntax are never learned as adjacent.
|
|
188
191
|
- A word missing from the base vocabulary becomes suggestible only after it
|
|
189
|
-
has been seen more than once
|
|
192
|
+
has been seen more than once, and not while it is a prefix of a learned word
|
|
193
|
+
you use at least as often (`addr` yields to `addressed`).
|
|
194
|
+
- Casing is learned from words written mid-sentence; sentence-initial
|
|
195
|
+
capitals are ignored.
|
|
190
196
|
|
|
191
197
|
### Prediction
|
|
192
198
|
|
|
@@ -214,7 +220,8 @@ Quill learns from your own submitted prompts, never from assistant output:
|
|
|
214
220
|
and requires repeated learned continuation evidence; not every typo produces
|
|
215
221
|
a suggestion.
|
|
216
222
|
- **Bounded size:** the personal model is pruned to its most frequent entries
|
|
217
|
-
when saved.
|
|
223
|
+
when saved. Once it holds about 100,000 learned words, every count is halved
|
|
224
|
+
and single-use entries are dropped, so recent habits outweigh old ones.
|
|
218
225
|
|
|
219
226
|
### Storage
|
|
220
227
|
|
|
@@ -226,8 +233,8 @@ state directory (`$XDG_STATE_HOME` when set, otherwise `~/.local/state`):
|
|
|
226
233
|
| Learned model | `opencode/<channel>/tui/plugin.quill.learning.json` |
|
|
227
234
|
| Settings | `opencode/<channel>/tui/plugin.quill.settings.json` |
|
|
228
235
|
|
|
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
|
|
236
|
+
The learned model holds only word, bigram, trigram and word-casing counts plus
|
|
237
|
+
processed message IDs. Raw prompt text is never written to disk. These files stay on your
|
|
231
238
|
machine and are never tracked in Git or published to npm.
|
|
232
239
|
|
|
233
240
|
## Development
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-quill",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
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",
|
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)
|