opencode-quill 0.4.0 → 0.5.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 +14 -0
- package/README.md +10 -2
- package/package.json +1 -1
- package/src/predictor.ts +21 -15
- package/src/prose.ts +28 -8
- package/src/tui.tsx +8 -4
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,18 @@ 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.5.1] - 2026-10-22
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- Harden learning persistence and release safety
|
|
12
|
+
|
|
13
|
+
## [0.5.0] - 2026-10-22
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
|
|
17
|
+
- **prediction:** Complete learned slash tokens and preserve prior weight
|
|
18
|
+
|
|
7
19
|
## [0.4.0] - 2026-10-21
|
|
8
20
|
|
|
9
21
|
### Added
|
|
@@ -109,6 +121,8 @@ All notable changes are documented in this file using
|
|
|
109
121
|
- `/quill` command and command palette action to toggle autocomplete.
|
|
110
122
|
- Local installer script, full test suite, CI workflows, and release tooling.
|
|
111
123
|
|
|
124
|
+
[0.5.1]: https://github.com/ozandogrultan/opencode-quill/compare/v0.5.0...v0.5.1
|
|
125
|
+
[0.5.0]: https://github.com/ozandogrultan/opencode-quill/compare/v0.4.0...v0.5.0
|
|
112
126
|
[0.4.0]: https://github.com/ozandogrultan/opencode-quill/compare/v0.3.4...v0.4.0
|
|
113
127
|
[0.3.4]: https://github.com/ozandogrultan/opencode-quill/compare/v0.3.3...v0.3.4
|
|
114
128
|
[0.3.3]: https://github.com/ozandogrultan/opencode-quill/compare/v0.3.2...v0.3.3
|
package/README.md
CHANGED
|
@@ -228,7 +228,9 @@ Quill learns from your own submitted prompts, never from assistant output:
|
|
|
228
228
|
`session.execution.succeeded`, `session.inbox.delivered`).
|
|
229
229
|
- On startup and when you open a session, it also backfills from the user
|
|
230
230
|
messages of the current and most recently updated sessions.
|
|
231
|
-
- Each message is ingested once, tracked by `<sessionID>:<messageID>`.
|
|
231
|
+
- Each message is ingested once, tracked by `<sessionID>:<messageID>`. All
|
|
232
|
+
processed IDs, including those of ignored pastes, are retained until
|
|
233
|
+
`/quill clear`.
|
|
232
234
|
- Only prose is learned. Code blocks, inline code, URLs, file paths,
|
|
233
235
|
identifiers, slash commands, shell lines, indented blocks and very large
|
|
234
236
|
pastes are ignored.
|
|
@@ -265,7 +267,7 @@ Quill learns from your own submitted prompts, never from assistant output:
|
|
|
265
267
|
no suggestion. Context repair uses the same edit guards and confidence checks
|
|
266
268
|
and requires repeated learned continuation evidence; not every typo produces
|
|
267
269
|
a suggestion.
|
|
268
|
-
- **Bounded
|
|
270
|
+
- **Bounded counts:** the personal model is pruned to its most frequent entries
|
|
269
271
|
when saved. Once it holds about 100,000 learned words, every count is halved
|
|
270
272
|
and single-use entries are dropped, so recent habits outweigh old ones.
|
|
271
273
|
|
|
@@ -286,6 +288,12 @@ raw prompts or full message bodies. These files stay on your machine and are
|
|
|
286
288
|
never tracked in Git or published to npm. `/quill clear` erases the learned
|
|
287
289
|
model; the persisted on/off setting is separate.
|
|
288
290
|
|
|
291
|
+
The processed-ID ledger is not pruned: its memory usage, stored size, and full
|
|
292
|
+
serialization cost grow with the number of processed messages. Word and context
|
|
293
|
+
counts remain bounded. Existing version-1 snapshots keep their counts and
|
|
294
|
+
retained IDs without a reset. IDs absent from older capped snapshots cannot be
|
|
295
|
+
recovered, so those messages may be learned again when backfilled.
|
|
296
|
+
|
|
289
297
|
## Development
|
|
290
298
|
|
|
291
299
|
```sh
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-quill",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.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",
|
package/src/predictor.ts
CHANGED
|
@@ -18,7 +18,6 @@ const MIN_TYPO_SCORE = 0.000001
|
|
|
18
18
|
const PRIOR_LIMIT = 20_000
|
|
19
19
|
const WORD_LIMIT = 8000
|
|
20
20
|
const CONTEXT_LIMIT = 30_000
|
|
21
|
-
const SEEN_LIMIT = 8000
|
|
22
21
|
const DECAY_TOTAL = 100_000
|
|
23
22
|
|
|
24
23
|
export function emptySnapshot(): Snapshot {
|
|
@@ -31,8 +30,14 @@ function sentenceStart(text: string, start: number): boolean {
|
|
|
31
30
|
return index < 0 || /[\n.!?:]/.test(text[index])
|
|
32
31
|
}
|
|
33
32
|
|
|
34
|
-
function restore(rows: [string, number][], limit: number): Map<string, number> {
|
|
35
|
-
return new Map(rows.slice(0, limit).filter(([
|
|
33
|
+
function restore(rows: [string, number][], limit: number, parts = 1, forms = false): Map<string, number> {
|
|
34
|
+
return new Map(rows.slice(0, limit).filter(([key, count]) => {
|
|
35
|
+
if (typeof key !== "string" || key.length > parts * 64 + parts - 1 || !Number.isFinite(count) || count <= 0) return false
|
|
36
|
+
const words = key.split("\0")
|
|
37
|
+
return words.length === parts && words.every((word) => isWord(word) && (forms
|
|
38
|
+
? word === word.normalize("NFC").replaceAll("’", "'")
|
|
39
|
+
: word === normalizeWord(word)))
|
|
40
|
+
}))
|
|
36
41
|
}
|
|
37
42
|
|
|
38
43
|
const byCount = (a: [string, number], b: [string, number]) => b[1] - a[1]
|
|
@@ -58,10 +63,10 @@ export class PersonalModel {
|
|
|
58
63
|
constructor(snapshot: Snapshot = emptySnapshot()) {
|
|
59
64
|
this.clearedAt = Number.isFinite(snapshot.clearedAt) ? snapshot.clearedAt : undefined
|
|
60
65
|
this.words = restore(snapshot.words, WORD_LIMIT)
|
|
61
|
-
this.bigrams = restore(snapshot.bigrams, CONTEXT_LIMIT)
|
|
62
|
-
this.trigrams = restore(snapshot.trigrams, CONTEXT_LIMIT)
|
|
63
|
-
this.forms = restore(snapshot.forms ?? [], WORD_LIMIT)
|
|
64
|
-
this.seen = new Set(snapshot.seen
|
|
66
|
+
this.bigrams = restore(snapshot.bigrams, CONTEXT_LIMIT, 2)
|
|
67
|
+
this.trigrams = restore(snapshot.trigrams, CONTEXT_LIMIT, 3)
|
|
68
|
+
this.forms = restore(snapshot.forms ?? [], WORD_LIMIT, 1, true)
|
|
69
|
+
this.seen = new Set(snapshot.seen)
|
|
65
70
|
}
|
|
66
71
|
|
|
67
72
|
observe(prompts: readonly Prompt[]): boolean {
|
|
@@ -103,7 +108,7 @@ export class PersonalModel {
|
|
|
103
108
|
bigrams: trim(this.bigrams, CONTEXT_LIMIT),
|
|
104
109
|
trigrams: trim(this.trigrams, CONTEXT_LIMIT),
|
|
105
110
|
forms: trim(this.forms, WORD_LIMIT),
|
|
106
|
-
seen: [...this.seen]
|
|
111
|
+
seen: [...this.seen],
|
|
107
112
|
...(this.clearedAt === undefined ? {} : { clearedAt: this.clearedAt }),
|
|
108
113
|
}
|
|
109
114
|
}
|
|
@@ -229,7 +234,7 @@ export class WordPredictor {
|
|
|
229
234
|
const word = learned[index]
|
|
230
235
|
if (this.prior.has(word)) continue
|
|
231
236
|
for (let next = index + 1; next < learned.length && learned[next].startsWith(word); next++) {
|
|
232
|
-
if (counts.get(learned[next])! >= counts.get(word)!) {
|
|
237
|
+
if (learned[next][word.length] !== "/" && counts.get(learned[next])! >= counts.get(word)!) {
|
|
233
238
|
fragments.add(word)
|
|
234
239
|
break
|
|
235
240
|
}
|
|
@@ -252,7 +257,7 @@ export class WordPredictor {
|
|
|
252
257
|
for (let index = lowerBound(this.vocabulary, head); index < this.vocabulary.length; index++) {
|
|
253
258
|
const word = this.vocabulary[index]
|
|
254
259
|
if (!word.startsWith(head)) break
|
|
255
|
-
if (word.length >= prefix.length - 1 && word.length <= maxLength) yield word
|
|
260
|
+
if (!word.includes("/") && word.length >= prefix.length - 1 && word.length <= maxLength) yield word
|
|
256
261
|
}
|
|
257
262
|
}
|
|
258
263
|
}
|
|
@@ -260,7 +265,7 @@ export class WordPredictor {
|
|
|
260
265
|
private score(word: string, context: readonly string[]): number {
|
|
261
266
|
const prior = (this.prior.get(word) ?? 0) / (this.priorTotal || 1)
|
|
262
267
|
const personal = (this.personal.words.get(word) ?? 0) / (this.personalTotal || 1)
|
|
263
|
-
const weight = this.personalTotal / (this.personalTotal + 100)
|
|
268
|
+
const weight = this.priorTotal ? Math.min(0.7, this.personalTotal / (this.personalTotal + 100)) : 1
|
|
264
269
|
let score = weight * personal + (1 - weight) * prior
|
|
265
270
|
const previous = context.at(-1)
|
|
266
271
|
const bigram = previous && this.bigramTotals.get(previous)
|
|
@@ -318,13 +323,14 @@ export class WordPredictor {
|
|
|
318
323
|
const evidence = this.bigramTotals.get(context.at(-1) ?? "")?.total ?? 0
|
|
319
324
|
if (query.next && evidence < 2) return []
|
|
320
325
|
if (!query.next && [...prefix].length < 2 && evidence < 2) return []
|
|
326
|
+
const slash = prefix.includes("/")
|
|
321
327
|
const candidates = new Map<string, number>()
|
|
322
328
|
for (let index = lowerBound(this.vocabulary, prefix); index < this.vocabulary.length; index++) {
|
|
323
329
|
const word = this.vocabulary[index]
|
|
324
330
|
if (!word.startsWith(prefix)) break
|
|
325
|
-
candidates.set(word, 1)
|
|
331
|
+
if (query.next || slash === word.includes("/")) candidates.set(word, 1)
|
|
326
332
|
}
|
|
327
|
-
for (const word of local.keys()) if (word.startsWith(prefix)) candidates.set(word, 1)
|
|
333
|
+
for (const word of local.keys()) if (!word.includes("/") && word.startsWith(prefix) && (query.next || !slash)) candidates.set(word, 1)
|
|
328
334
|
const suggest = (): Prediction[] => {
|
|
329
335
|
const ranked: { word: string; score: number; weight: number }[] = []
|
|
330
336
|
let sum = 0
|
|
@@ -358,14 +364,14 @@ export class WordPredictor {
|
|
|
358
364
|
return predictions
|
|
359
365
|
}
|
|
360
366
|
const completion = suggest()
|
|
361
|
-
if (completion.length || query.next || prefix.length < 3 || candidates.has(prefix)) return completion
|
|
367
|
+
if (completion.length || query.next || prefix.length < 3 || slash || candidates.has(prefix)) return completion
|
|
362
368
|
for (const word of this.nearbyWords(prefix)) {
|
|
363
369
|
if (candidates.has(word)) continue
|
|
364
370
|
const weight = typoWeight(prefix, word)
|
|
365
371
|
if (weight > 0) candidates.set(word, weight)
|
|
366
372
|
}
|
|
367
373
|
for (const word of local.keys()) {
|
|
368
|
-
if (candidates.has(word)) continue
|
|
374
|
+
if (candidates.has(word) || word.includes("/")) continue
|
|
369
375
|
const weight = typoWeight(prefix, word)
|
|
370
376
|
if (weight > 0) candidates.set(word, weight)
|
|
371
377
|
}
|
package/src/prose.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
3
|
-
const
|
|
1
|
+
const PART = "[\\p{L}\\p{M}]+(?:['’][\\p{L}\\p{M}]+)*"
|
|
2
|
+
const WORD = new RegExp(`${PART}(?:\\/${PART})?`, "gu")
|
|
3
|
+
const WHOLE_WORD = new RegExp(`^${PART}(?:\\/${PART})?$`, "u")
|
|
4
|
+
const WORD_PREFIX = new RegExp(`^${PART}(?:\\/(?:${PART})?)?$`, "u")
|
|
5
|
+
const WORD_END = new RegExp(`${PART}(?:\\/(?:${PART})?)?$`, "u")
|
|
4
6
|
|
|
5
7
|
export type Word = { text: string; start: number; end: number }
|
|
6
8
|
export type CompletionQuery = { before: string; prefix: string; next: boolean; words?: readonly Word[] }
|
|
@@ -13,19 +15,37 @@ export function isWord(word: string): boolean {
|
|
|
13
15
|
return WHOLE_WORD.test(word) && [...word].length <= 32
|
|
14
16
|
}
|
|
15
17
|
|
|
18
|
+
function isPrefix(prefix: string): boolean {
|
|
19
|
+
return WORD_PREFIX.test(prefix) && [...prefix].length <= 32
|
|
20
|
+
}
|
|
21
|
+
|
|
16
22
|
function blank(text: string): string {
|
|
17
23
|
return text.replace(/[^\n]/g, " ")
|
|
18
24
|
}
|
|
19
25
|
|
|
20
26
|
export function maskProse(text: string): string {
|
|
21
|
-
let
|
|
27
|
+
let fence: string | undefined
|
|
28
|
+
let masked = text.replace(/[^\n]+/g, (line) => {
|
|
29
|
+
if (fence) {
|
|
30
|
+
const closing = /^ {0,3}(`{3,}|~{3,})[ \t\r]*$/.exec(line)?.[1]
|
|
31
|
+
if (closing && closing[0] === fence[0] && closing.length >= fence.length) fence = undefined
|
|
32
|
+
return blank(line)
|
|
33
|
+
}
|
|
34
|
+
const opening = /^ {0,3}(`{3,}|~{3,})(.*)$/.exec(line)
|
|
35
|
+
if (opening && (opening[1][0] !== "`" || !opening[2].includes("`"))) {
|
|
36
|
+
fence = opening[1]
|
|
37
|
+
return blank(line)
|
|
38
|
+
}
|
|
39
|
+
return line
|
|
40
|
+
})
|
|
22
41
|
masked = masked.replace(/(`+)[\s\S]*?(?:\1|$)/g, blank)
|
|
23
42
|
masked = masked.replace(/(?:https?:\/\/|www\.)\S+|\[[^\]\n]*\]\([^\)\n]*\)|<[^>\n]+>/g, blank)
|
|
24
43
|
masked = masked.replace(/^[ \t]*(?:[\/!$]|(?:const|let|var|function|class|import|export)\s|(?:Traceback|Error:)\b).*$/gm, blank)
|
|
25
|
-
masked = masked.replace(/^ {4,}.*$/gm, blank)
|
|
44
|
+
masked = masked.replace(/^(?: {4}| {0,3}\t).*$/gm, blank)
|
|
26
45
|
masked = masked.replace(/\S+/g, (token) => {
|
|
27
46
|
const core = token.replace(/^["“‘([{]+|["”’),;:!?}\]]+$/g, "")
|
|
28
|
-
if (/[
|
|
47
|
+
if (/[_@=\\<>-]|\d|[\p{Ll}][\p{Lu}]/u.test(core) || /^[.~]/.test(core)) return blank(token)
|
|
48
|
+
if (core.includes("/") && !(core.endsWith(".") ? WHOLE_WORD.test(core.slice(0, -1)) : WORD_PREFIX.test(core))) return blank(token)
|
|
29
49
|
if (/[^.]+\.[^.]+|\.\.|--/.test(core)) return blank(token)
|
|
30
50
|
return token
|
|
31
51
|
})
|
|
@@ -34,7 +54,7 @@ export function maskProse(text: string): string {
|
|
|
34
54
|
|
|
35
55
|
export function proseWords(text: string, masked = maskProse(text)): Word[] {
|
|
36
56
|
return [...masked.matchAll(WORD)]
|
|
37
|
-
.filter((match) => isWord(match[0]))
|
|
57
|
+
.filter((match) => isWord(match[0]) && masked[match.index + match[0].length] !== "/")
|
|
38
58
|
.map((match) => ({ text: normalizeWord(match[0]), start: match.index, end: match.index + match[0].length }))
|
|
39
59
|
}
|
|
40
60
|
|
|
@@ -81,7 +101,7 @@ export function completionQuery(draft: string, characterOffset: number, protecte
|
|
|
81
101
|
let end = text.length
|
|
82
102
|
if (prefix) {
|
|
83
103
|
const start = text.length - prefix.length
|
|
84
|
-
if (masked.slice(start) !== prefix || !
|
|
104
|
+
if (masked.slice(start) !== prefix || !isPrefix(prefix)) return
|
|
85
105
|
const preceding = text[start - 1]
|
|
86
106
|
if (preceding && !/[ \t\n"“([{]/.test(preceding)) return
|
|
87
107
|
end = start
|
package/src/tui.tsx
CHANGED
|
@@ -58,9 +58,12 @@ export default Plugin.define({
|
|
|
58
58
|
}, () => dimGhostColor(context.theme.text.muted), context.renderer, options.completeAtLineEnd)
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
+
const sessionInfo = (sessionID: string) =>
|
|
62
|
+
context.data.session.get?.(sessionID) ?? context.data.session.list().find((session) => session.id === sessionID)
|
|
63
|
+
|
|
61
64
|
const learn = async (sessionID: string, announce = true) => {
|
|
62
65
|
if (disposed || !settings.enabled) return
|
|
63
|
-
if (
|
|
66
|
+
if (sessionInfo(sessionID)?.parentID) return
|
|
64
67
|
const active = inFlight.get(sessionID)
|
|
65
68
|
if (active) {
|
|
66
69
|
if (announce) {
|
|
@@ -78,9 +81,9 @@ export default Plugin.define({
|
|
|
78
81
|
const shouldAnnounce = state.announce
|
|
79
82
|
state.announce = false
|
|
80
83
|
try {
|
|
81
|
-
await context.data.session.message.sync(sessionID)
|
|
84
|
+
await Promise.all([context.data.session.sync?.(sessionID), context.data.session.message.sync(sessionID)])
|
|
82
85
|
if (disposed || !settings.enabled) return
|
|
83
|
-
if (
|
|
86
|
+
if (sessionInfo(sessionID)?.parentID) return
|
|
84
87
|
if (version !== resetVersion) continue
|
|
85
88
|
const candidates = context.data.session.message.list(sessionID)
|
|
86
89
|
.filter((message) => message.type === "user")
|
|
@@ -97,7 +100,8 @@ export default Plugin.define({
|
|
|
97
100
|
if (model.observe(prompts)) {
|
|
98
101
|
await setLearning((draft) => {
|
|
99
102
|
if (disposed || !settings.enabled || version !== resetVersion) return
|
|
100
|
-
|
|
103
|
+
const session = sessionInfo(sessionID)
|
|
104
|
+
if (!session || session.parentID) return
|
|
101
105
|
const latest = new PersonalModel(unwrap(draft.snapshot))
|
|
102
106
|
if (latest.observe(promptsFor(latest.clearedAt))) draft.snapshot = latest.snapshot()
|
|
103
107
|
})
|