opencode-quill 0.2.0 → 0.2.2
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 +15 -4
- package/package.json +1 -1
- package/src/ghost.ts +15 -10
- package/src/predictor.ts +52 -40
- package/src/prose.ts +11 -9
- package/src/tui.tsx +63 -31
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.2.2] - 2026-10-15
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
|
|
11
|
+
- **learning:** Read stored snapshots without store proxies
|
|
12
|
+
|
|
13
|
+
## [0.2.1] - 2026-10-13
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
|
|
17
|
+
- **prediction:** Guard typo corrections and learning races
|
|
18
|
+
|
|
7
19
|
## [0.2.0] - 2026-10-13
|
|
8
20
|
|
|
9
21
|
### Added
|
|
@@ -56,6 +68,8 @@ All notable changes are documented in this file using
|
|
|
56
68
|
- `/quill` command and command palette action to toggle autocomplete.
|
|
57
69
|
- Local installer script, full test suite, CI workflows, and release tooling.
|
|
58
70
|
|
|
71
|
+
[0.2.2]: https://github.com/ozandogrultan/opencode-quill/compare/v0.2.1...v0.2.2
|
|
72
|
+
[0.2.1]: https://github.com/ozandogrultan/opencode-quill/compare/v0.2.0...v0.2.1
|
|
59
73
|
[0.2.0]: https://github.com/ozandogrultan/opencode-quill/compare/v0.1.5...v0.2.0
|
|
60
74
|
[0.1.5]: https://github.com/ozandogrultan/opencode-quill/compare/v0.1.4...v0.1.5
|
|
61
75
|
[0.1.4]: https://github.com/ozandogrultan/opencode-quill/compare/v0.1.3...v0.1.4
|
package/README.md
CHANGED
|
@@ -55,6 +55,9 @@ A correction looks like this, with only ` → complete` dimmed:
|
|
|
55
55
|
- **Completions append** the missing letters or next word.
|
|
56
56
|
- **Corrections replace only the active word**, preserving its initial-capital
|
|
57
57
|
or all-uppercase casing (`Cmplete` → `Complete`, `CMPLETE` → `COMPLETE`).
|
|
58
|
+
First-person contractions use a capital `I` in corrections and next-word
|
|
59
|
+
suggestions (`I'm`, `I'll`, `I've`, `I'd`). Lowercase contraction prefixes
|
|
60
|
+
are replaced on acceptance too (`i'v` → `I've`).
|
|
58
61
|
- **Normal completions take precedence.** For example, `whate` completes to
|
|
59
62
|
`whatever` rather than being corrected to `what`. Typo correction is a
|
|
60
63
|
fallback when no confident prefix completion is available; recognized words
|
|
@@ -198,10 +201,18 @@ Quill learns from your own submitted prompts, never from assistant output:
|
|
|
198
201
|
nothing is shown.
|
|
199
202
|
- **Typo fallback:** when prefix completion is not confident enough, nearby
|
|
200
203
|
words are ranked with an edit penalty and a stricter confidence threshold.
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
for
|
|
204
|
+
Correction confidence is the edit-penalized model score. Suggestions must
|
|
205
|
+
clear an absolute evidence floor and a separate candidate-dominance check.
|
|
206
|
+
Corrections require at least three typed letters. Short words are eligible
|
|
207
|
+
only for whole-word letter swaps that preserve the first letter; other edits
|
|
208
|
+
and mistyped longer prefixes require at least five letters, except for
|
|
209
|
+
apostrophe contractions, including missing apostrophes. Deletions repair only
|
|
210
|
+
doubled letters, not arbitrary extra characters or word endings.
|
|
211
|
+
Unknown tokens such as `json`, `yaml`, `bool`, `opts`,
|
|
212
|
+
and `enum` are left unchanged, and uncertain typos such as `fucn` can produce
|
|
213
|
+
no suggestion. Context repair uses the same edit guards and confidence checks
|
|
214
|
+
and requires repeated learned continuation evidence; not every typo produces
|
|
215
|
+
a suggestion.
|
|
205
216
|
- **Bounded size:** the personal model is pruned to its most frequent entries
|
|
206
217
|
when saved.
|
|
207
218
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-quill",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
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/ghost.ts
CHANGED
|
@@ -15,13 +15,13 @@ export function dimGhostColor(muted: RGBA): RGBA {
|
|
|
15
15
|
return RGBA.fromValues(muted.r, muted.g, muted.b, muted.a * 0.55)
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
export function eligibleComposer(view: Composer): boolean {
|
|
18
|
+
export function eligibleComposer(view: Composer, text?: string): boolean {
|
|
19
19
|
const editor = view.editor
|
|
20
20
|
return view.enabled && view.normal && view.mode === "base" && !view.selected &&
|
|
21
21
|
editor === view.focused && editor.focused && editor.visible && !editor.isDestroyed &&
|
|
22
22
|
!!editor.parent && !editor.parent.isDestroyed && !editor.hasSelection() &&
|
|
23
23
|
!editor.traits.capture?.includes("navigate") &&
|
|
24
|
-
editor.
|
|
24
|
+
(text ?? editor.plainText).trim().length > 0 && editor.extmarks.getAll().length === 0
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
export function findComposer(marker: Renderable | undefined, isEditor: (node: Renderable) => node is TextareaRenderable): TextareaRenderable | undefined {
|
|
@@ -66,11 +66,9 @@ export class ComposerGhost {
|
|
|
66
66
|
if (!this.editor.isDestroyed) this.editor.requestRender()
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
private prediction(): Prediction | undefined {
|
|
70
|
-
const text = this.editor.plainText
|
|
71
|
-
const offset = this.offset()
|
|
69
|
+
private prediction(text: string, offset: number): Prediction | undefined {
|
|
72
70
|
if (this.dismissed !== undefined && this.dismissed !== text) this.dismissed = undefined
|
|
73
|
-
if (!eligibleComposer(this.view()
|
|
71
|
+
if (this.dismissed === text || !eligibleComposer(this.view(), text)) return
|
|
74
72
|
if (this.memo?.text === text && this.memo.offset === offset) return this.memo.prediction
|
|
75
73
|
const query = completionQuery(text, offset)
|
|
76
74
|
let prediction = query && this.predictor.complete(query)
|
|
@@ -86,8 +84,14 @@ export class ComposerGhost {
|
|
|
86
84
|
}
|
|
87
85
|
|
|
88
86
|
private paint(buffer: OptimizedBuffer): void {
|
|
89
|
-
|
|
90
|
-
|
|
87
|
+
if (this.editor.isDestroyed) {
|
|
88
|
+
this.shown = undefined
|
|
89
|
+
return
|
|
90
|
+
}
|
|
91
|
+
const text = this.editor.plainText
|
|
92
|
+
const offset = this.offset()
|
|
93
|
+
const prediction = this.prediction(text, offset)
|
|
94
|
+
if (!prediction) {
|
|
91
95
|
this.shown = undefined
|
|
92
96
|
return
|
|
93
97
|
}
|
|
@@ -106,7 +110,7 @@ export class ComposerGhost {
|
|
|
106
110
|
} finally {
|
|
107
111
|
buffer.popScissorRect()
|
|
108
112
|
}
|
|
109
|
-
this.shown = { text
|
|
113
|
+
this.shown = { text, offset, prediction }
|
|
110
114
|
}
|
|
111
115
|
|
|
112
116
|
accept(): boolean {
|
|
@@ -126,7 +130,8 @@ export class ComposerGhost {
|
|
|
126
130
|
}
|
|
127
131
|
|
|
128
132
|
dismiss(): boolean {
|
|
129
|
-
if (this.disposed || !this.shown || !eligibleComposer(this.view()) ||
|
|
133
|
+
if (this.disposed || !this.shown || !eligibleComposer(this.view()) ||
|
|
134
|
+
this.editor.plainText !== this.shown.text || this.offset() !== this.shown.offset) return false
|
|
130
135
|
this.dismissed = this.editor.plainText
|
|
131
136
|
this.shown = undefined
|
|
132
137
|
this.editor.requestRender()
|
package/src/predictor.ts
CHANGED
|
@@ -12,6 +12,7 @@ export type Prompt = { id: string; text: string }
|
|
|
12
12
|
export type Prediction = { suffix: string; word: string; confidence: number; replace?: number }
|
|
13
13
|
|
|
14
14
|
const DISCOUNT = 0.5
|
|
15
|
+
const MIN_TYPO_SCORE = 0.000001
|
|
15
16
|
const PRIOR_LIMIT = 20_000
|
|
16
17
|
const WORD_LIMIT = 8000
|
|
17
18
|
const CONTEXT_LIMIT = 30_000
|
|
@@ -118,36 +119,43 @@ function editKind(source: string, target: string, targetLength = target.length):
|
|
|
118
119
|
}
|
|
119
120
|
for (let j = i; j < targetLength; j++) if (source.charCodeAt(j + 1) !== target.charCodeAt(j)) return
|
|
120
121
|
const doubled = (i > 0 && source.charCodeAt(i) === source.charCodeAt(i - 1)) || (i + 1 < sourceLength && source.charCodeAt(i) === source.charCodeAt(i + 1))
|
|
121
|
-
return doubled
|
|
122
|
+
return doubled ? "delete" : undefined
|
|
122
123
|
}
|
|
123
124
|
|
|
124
|
-
function typoWeight(prefix: string, word: string): number {
|
|
125
|
+
function typoWeight(prefix: string, word: string, wholeWord = false): number {
|
|
125
126
|
const prefixLength = prefix.length
|
|
126
127
|
const wordLength = word.length
|
|
127
128
|
if (prefixLength < 3) return 0
|
|
129
|
+
const sameHead = prefix[0] === word[0]
|
|
130
|
+
const swappedHead = prefixLength >= 5 && prefix[0] === word[1] && prefix[1] === word[0]
|
|
131
|
+
if (!sameHead && !swappedHead) return 0
|
|
128
132
|
const full = editKind(prefix, word)
|
|
133
|
+
if (wholeWord && !full) return 0
|
|
129
134
|
if (full === "transpose") return 0.25
|
|
130
|
-
if (full
|
|
131
|
-
if (full === "
|
|
132
|
-
if (
|
|
133
|
-
|
|
134
|
-
(prefix.charCodeAt(0) === word.charCodeAt(1) && prefix.charCodeAt(1) === word.charCodeAt(0))
|
|
135
|
-
if (!head) return 0
|
|
135
|
+
if (full && prefixLength < 5 && !word.includes("'")) return 0
|
|
136
|
+
if (full === "insert" || full === "delete") return 0.06
|
|
137
|
+
if (full === "substitute") return 0.04
|
|
138
|
+
if (prefixLength < 5 || wordLength <= prefixLength) return 0
|
|
136
139
|
const partial = editKind(prefix, word, prefixLength)
|
|
137
140
|
if (partial === "transpose") return 0.06
|
|
138
141
|
if (partial === "substitute") return 0.02
|
|
139
142
|
if (wordLength > prefixLength + 1 && editKind(prefix, word, prefixLength + 1) === "insert") return 0.03
|
|
140
|
-
if (
|
|
143
|
+
if (editKind(prefix, word, prefixLength - 1) === "delete") return 0.02
|
|
141
144
|
return 0
|
|
142
145
|
}
|
|
143
146
|
|
|
147
|
+
function typoConfidence(score: number, total: number): number | undefined {
|
|
148
|
+
if (score < MIN_TYPO_SCORE || score / (total || 1) < 0.45) return
|
|
149
|
+
return score
|
|
150
|
+
}
|
|
151
|
+
|
|
144
152
|
function applyCase(source: string, word: string): string {
|
|
145
153
|
if (source.length > 1 && source === source.toUpperCase()) return word.toUpperCase()
|
|
146
154
|
const first = source[0]
|
|
147
155
|
if (first && first === first.toUpperCase() && first !== first.toLowerCase()) {
|
|
148
156
|
return word[0].toUpperCase() + word.slice(1)
|
|
149
157
|
}
|
|
150
|
-
return word === "i"
|
|
158
|
+
return word === "i" || word.startsWith("i'") ? `I${word.slice(1)}` : word
|
|
151
159
|
}
|
|
152
160
|
|
|
153
161
|
export class WordPredictor {
|
|
@@ -158,7 +166,6 @@ export class WordPredictor {
|
|
|
158
166
|
private bigramTotals = new Map<string, { total: number; types: number }>()
|
|
159
167
|
private trigramTotals = new Map<string, { total: number; types: number }>()
|
|
160
168
|
private vocabulary: string[] = []
|
|
161
|
-
private vocabularyByLength = new Map<number, string[]>()
|
|
162
169
|
|
|
163
170
|
constructor(prior: readonly Frequency[]) {
|
|
164
171
|
for (const { word, count } of prior) {
|
|
@@ -177,11 +184,18 @@ export class WordPredictor {
|
|
|
177
184
|
this.bigramTotals = totals(this.personal.bigrams)
|
|
178
185
|
this.trigramTotals = totals(this.personal.trigrams)
|
|
179
186
|
this.vocabulary = [...new Set([...this.prior.keys(), ...[...this.personal.words].filter(([, count]) => count >= 2).map(([word]) => word)])].sort()
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
private *nearbyWords(prefix: string, wholeWord = false): IterableIterator<string> {
|
|
190
|
+
const heads = [prefix[0]]
|
|
191
|
+
if (prefix.length >= 5 && prefix[0] !== prefix[1]) heads.push(prefix[1] + prefix[0])
|
|
192
|
+
const maxLength = wholeWord || prefix.length < 5 ? prefix.length + 1 : Infinity
|
|
193
|
+
for (const head of heads) {
|
|
194
|
+
for (let index = lowerBound(this.vocabulary, head); index < this.vocabulary.length; index++) {
|
|
195
|
+
const word = this.vocabulary[index]
|
|
196
|
+
if (!word.startsWith(head)) break
|
|
197
|
+
if (word.length >= prefix.length - 1 && word.length <= maxLength) yield word
|
|
198
|
+
}
|
|
185
199
|
}
|
|
186
200
|
}
|
|
187
201
|
|
|
@@ -214,28 +228,29 @@ export class WordPredictor {
|
|
|
214
228
|
}
|
|
215
229
|
let best = word
|
|
216
230
|
let bestScore = 0
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
231
|
+
let sum = 0
|
|
232
|
+
for (const candidate of this.nearbyWords(word, true)) {
|
|
233
|
+
if ((this.bigramTotals.get(candidate)?.total ?? 0) < 2) continue
|
|
234
|
+
const weight = typoWeight(word, candidate, true)
|
|
235
|
+
if (!weight) continue
|
|
236
|
+
const score = this.score(candidate, resolved) * weight
|
|
237
|
+
sum += score
|
|
238
|
+
if (score > bestScore) {
|
|
239
|
+
best = candidate
|
|
240
|
+
bestScore = score
|
|
227
241
|
}
|
|
228
242
|
}
|
|
229
|
-
resolved.push(best)
|
|
243
|
+
resolved.push(typoConfidence(bestScore, sum) === undefined ? word : best)
|
|
230
244
|
}
|
|
231
245
|
return resolved
|
|
232
246
|
}
|
|
233
247
|
|
|
234
248
|
complete(query: CompletionQuery): Prediction | undefined {
|
|
235
249
|
const prefix = normalizeWord(query.prefix)
|
|
250
|
+
const words = query.words ?? proseWords(query.before)
|
|
236
251
|
const local = new Map<string, number>()
|
|
237
|
-
for (const word of
|
|
238
|
-
const context = this.resolveContext(leftContext(query.before), local)
|
|
252
|
+
for (const word of words) increment(local, word.text)
|
|
253
|
+
const context = this.resolveContext(leftContext(query.before, words), local)
|
|
239
254
|
const evidence = this.bigramTotals.get(context.at(-1) ?? "")?.total ?? 0
|
|
240
255
|
if (query.next && evidence < 2) return
|
|
241
256
|
if (!query.next && [...prefix].length < 2 && evidence < 2) return
|
|
@@ -261,25 +276,22 @@ export class WordPredictor {
|
|
|
261
276
|
bestWeight = weight
|
|
262
277
|
}
|
|
263
278
|
}
|
|
264
|
-
const confidence = query.next ? bestScore : bestScore / (sum || 1)
|
|
265
|
-
if (!best || best === prefix || confidence
|
|
266
|
-
if (bestWeight < 1) {
|
|
279
|
+
const confidence = bestWeight < 1 ? typoConfidence(bestScore, sum) : query.next ? bestScore : bestScore / (sum || 1)
|
|
280
|
+
if (!best || best === prefix || confidence === undefined || (bestWeight === 1 && confidence < (query.next ? 0.55 : 0.3))) return
|
|
281
|
+
if (bestWeight < 1 || (!query.next && best.startsWith("i'") && query.prefix[0] === "i")) {
|
|
267
282
|
return { suffix: applyCase(query.prefix, best), word: best, confidence, replace: query.prefix.length }
|
|
268
283
|
}
|
|
269
284
|
let suffix = best.slice(prefix.length)
|
|
270
285
|
if (query.prefix.length > 1 && query.prefix === query.prefix.toUpperCase()) suffix = suffix.toUpperCase()
|
|
271
|
-
if (query.next
|
|
286
|
+
if (query.next) suffix = applyCase("", best)
|
|
272
287
|
return { suffix, word: best, confidence }
|
|
273
288
|
}
|
|
274
289
|
const completion = suggest()
|
|
275
290
|
if (completion || query.next || prefix.length < 3 || candidates.has(prefix)) return completion
|
|
276
|
-
for (const
|
|
277
|
-
if (
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
const weight = typoWeight(prefix, word)
|
|
281
|
-
if (weight > 0) candidates.set(word, weight)
|
|
282
|
-
}
|
|
291
|
+
for (const word of this.nearbyWords(prefix)) {
|
|
292
|
+
if (candidates.has(word)) continue
|
|
293
|
+
const weight = typoWeight(prefix, word)
|
|
294
|
+
if (weight > 0) candidates.set(word, weight)
|
|
283
295
|
}
|
|
284
296
|
for (const word of local.keys()) {
|
|
285
297
|
if (candidates.has(word)) continue
|
package/src/prose.ts
CHANGED
|
@@ -3,7 +3,7 @@ const WHOLE_WORD = /^[\p{L}\p{M}]+(?:['’][\p{L}\p{M}]+)*$/u
|
|
|
3
3
|
const WORD_END = /[\p{L}\p{M}]+(?:['’][\p{L}\p{M}]+)*$/u
|
|
4
4
|
|
|
5
5
|
export type Word = { text: string; start: number; end: number }
|
|
6
|
-
export type CompletionQuery = { before: string; prefix: string; next: boolean }
|
|
6
|
+
export type CompletionQuery = { before: string; prefix: string; next: boolean; words?: readonly Word[] }
|
|
7
7
|
|
|
8
8
|
export function normalizeWord(word: string): string {
|
|
9
9
|
return word.normalize("NFC").replaceAll("’", "'").toLowerCase()
|
|
@@ -32,8 +32,7 @@ export function maskProse(text: string): string {
|
|
|
32
32
|
return masked
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
export function proseWords(text: string): Word[] {
|
|
36
|
-
const masked = maskProse(text)
|
|
35
|
+
export function proseWords(text: string, masked = maskProse(text)): Word[] {
|
|
37
36
|
return [...masked.matchAll(WORD)]
|
|
38
37
|
.filter((match) => isWord(match[0]))
|
|
39
38
|
.map((match) => ({ text: normalizeWord(match[0]), start: match.index, end: match.index + match[0].length }))
|
|
@@ -51,8 +50,7 @@ export function proseSequences(text: string): string[][] {
|
|
|
51
50
|
return sequences
|
|
52
51
|
}
|
|
53
52
|
|
|
54
|
-
export function leftContext(before: string): string[] {
|
|
55
|
-
const words = proseWords(before)
|
|
53
|
+
export function leftContext(before: string, words: readonly Word[] = proseWords(before)): string[] {
|
|
56
54
|
const result: string[] = []
|
|
57
55
|
let end = before.length
|
|
58
56
|
for (let index = words.length - 1; index >= 0 && result.length < 2; index--) {
|
|
@@ -68,13 +66,17 @@ export function completionQuery(text: string, characterOffset: number): Completi
|
|
|
68
66
|
if (!text.trim() || characterOffset !== text.length || text.length > 16_000) return
|
|
69
67
|
const masked = maskProse(text)
|
|
70
68
|
const prefix = WORD_END.exec(text)?.[0]
|
|
69
|
+
let end = text.length
|
|
71
70
|
if (prefix) {
|
|
72
71
|
const start = text.length - prefix.length
|
|
73
72
|
if (masked.slice(start) !== prefix || !isWord(prefix)) return
|
|
74
73
|
const preceding = text[start - 1]
|
|
75
74
|
if (preceding && !/[ \t\n"“([{]/.test(preceding)) return
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
|
|
75
|
+
end = start
|
|
76
|
+
} else if (!/[ \t]$/.test(text)) return
|
|
77
|
+
const start = Math.max(0, end - 2000)
|
|
78
|
+
const before = text.slice(start, end)
|
|
79
|
+
const words = proseWords(before, masked.slice(start, end))
|
|
80
|
+
if (!prefix && !leftContext(before, words).length) return
|
|
81
|
+
return { before, prefix: prefix ?? "", next: !prefix, words }
|
|
80
82
|
}
|
package/src/tui.tsx
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { Plugin } from "@opencode/plugin/tui"
|
|
3
3
|
import { InputRenderable, TextareaRenderable, type BoxRenderable } from "@opentui/core"
|
|
4
4
|
import { createEffect, createRoot, createSignal, onCleanup, untrack } from "solid-js"
|
|
5
|
+
import { unwrap } from "solid-js/store"
|
|
5
6
|
import frequencies from "subtlex-word-frequencies"
|
|
6
7
|
import { ComposerGhost, dimGhostColor, findComposer } from "./ghost"
|
|
7
8
|
import { completionLayer } from "./keymap"
|
|
@@ -21,11 +22,12 @@ export default Plugin.define({
|
|
|
21
22
|
const predictor = new WordPredictor(frequencies)
|
|
22
23
|
const composers = new Map<string, { marker: BoxRenderable; normal: () => boolean }>()
|
|
23
24
|
const seeded = new Set<string>()
|
|
24
|
-
const inFlight = new
|
|
25
|
+
const inFlight = new Map<string, { pending: boolean; announce: boolean }>()
|
|
25
26
|
const [revision, setRevision] = createSignal(0)
|
|
26
27
|
let ghost: ComposerGhost | undefined
|
|
27
28
|
let disposed = false
|
|
28
29
|
let warned = false
|
|
30
|
+
let resetVersion = 0
|
|
29
31
|
|
|
30
32
|
const routeKey = () => {
|
|
31
33
|
const route = context.ui.router.current()
|
|
@@ -57,34 +59,72 @@ export default Plugin.define({
|
|
|
57
59
|
}
|
|
58
60
|
|
|
59
61
|
const learn = async (sessionID: string, announce = true) => {
|
|
60
|
-
if (disposed || !settings.enabled
|
|
61
|
-
inFlight.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
.filter((message) => message.type === "user")
|
|
67
|
-
.slice(-200)
|
|
68
|
-
.map((message) => ({ id: `${sessionID}:${message.id}`, text: message.text }))
|
|
69
|
-
const model = new PersonalModel(learning.snapshot)
|
|
70
|
-
if (!model.observe(prompts)) return
|
|
71
|
-
await setLearning((draft) => {
|
|
72
|
-
const latest = new PersonalModel(draft.snapshot)
|
|
73
|
-
if (latest.observe(prompts)) draft.snapshot = latest.snapshot()
|
|
74
|
-
})
|
|
75
|
-
} catch (error) {
|
|
76
|
-
if (announce && !disposed && !warned) {
|
|
77
|
-
warned = true
|
|
78
|
-
context.ui.toast.show({ title: "Quill", message: `History learning unavailable (${sessionID}: ${error instanceof Error ? error.message : String(error)}); vocabulary completion is still active.`, variant: "warning" })
|
|
62
|
+
if (disposed || !settings.enabled) return
|
|
63
|
+
const active = inFlight.get(sessionID)
|
|
64
|
+
if (active) {
|
|
65
|
+
if (announce) {
|
|
66
|
+
active.pending = true
|
|
67
|
+
active.announce = true
|
|
79
68
|
}
|
|
69
|
+
return
|
|
70
|
+
}
|
|
71
|
+
const state = { pending: false, announce }
|
|
72
|
+
inFlight.set(sessionID, state)
|
|
73
|
+
try {
|
|
74
|
+
do {
|
|
75
|
+
state.pending = false
|
|
76
|
+
const version = resetVersion
|
|
77
|
+
const shouldAnnounce = state.announce
|
|
78
|
+
state.announce = false
|
|
79
|
+
try {
|
|
80
|
+
await context.data.session.message.sync(sessionID)
|
|
81
|
+
if (disposed || !settings.enabled) return
|
|
82
|
+
if (version !== resetVersion) continue
|
|
83
|
+
const prompts = context.data.session.message.list(sessionID)
|
|
84
|
+
.filter((message) => message.type === "user")
|
|
85
|
+
.slice(-200)
|
|
86
|
+
.map((message) => ({ id: `${sessionID}:${message.id}`, text: message.text }))
|
|
87
|
+
const snapshot = unwrap(learning.snapshot)
|
|
88
|
+
const seen = new Set(snapshot.seen)
|
|
89
|
+
if (!prompts.some((prompt) => !seen.has(prompt.id))) continue
|
|
90
|
+
const model = new PersonalModel(snapshot)
|
|
91
|
+
if (model.observe(prompts)) {
|
|
92
|
+
await setLearning((draft) => {
|
|
93
|
+
if (disposed || !settings.enabled || version !== resetVersion) return
|
|
94
|
+
const latest = new PersonalModel(unwrap(draft.snapshot))
|
|
95
|
+
if (latest.observe(prompts)) draft.snapshot = latest.snapshot()
|
|
96
|
+
})
|
|
97
|
+
}
|
|
98
|
+
} catch (error) {
|
|
99
|
+
if (shouldAnnounce && !disposed && version === resetVersion && !warned) {
|
|
100
|
+
warned = true
|
|
101
|
+
context.ui.toast.show({ title: "Quill", message: `History learning unavailable (${sessionID}: ${error instanceof Error ? error.message : String(error)}); vocabulary completion is still active.`, variant: "warning" })
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
} while (state.pending && !disposed && settings.enabled)
|
|
80
105
|
} finally {
|
|
81
106
|
inFlight.delete(sessionID)
|
|
82
107
|
}
|
|
83
108
|
}
|
|
84
109
|
|
|
110
|
+
const clearHistory = async () => {
|
|
111
|
+
resetVersion++
|
|
112
|
+
for (const state of inFlight.values()) {
|
|
113
|
+
state.pending = false
|
|
114
|
+
state.announce = false
|
|
115
|
+
}
|
|
116
|
+
predictor.setPersonal(emptySnapshot())
|
|
117
|
+
await setLearning((draft) => { draft.snapshot = emptySnapshot() })
|
|
118
|
+
ghost?.invalidate()
|
|
119
|
+
context.ui.toast.show({ title: "Quill", message: "Word autocomplete history cleared" })
|
|
120
|
+
}
|
|
121
|
+
|
|
85
122
|
const disposeEffects = createRoot((dispose) => {
|
|
86
123
|
createEffect(() => {
|
|
87
|
-
|
|
124
|
+
const snapshot = learning.snapshot
|
|
125
|
+
snapshot.seen.length
|
|
126
|
+
snapshot.seen.at(-1)
|
|
127
|
+
predictor.setPersonal(unwrap(snapshot))
|
|
88
128
|
ghost?.invalidate()
|
|
89
129
|
})
|
|
90
130
|
createEffect(() => {
|
|
@@ -128,10 +168,7 @@ export default Plugin.define({
|
|
|
128
168
|
run: async (input) => {
|
|
129
169
|
const command = parseQuillCommand(input)
|
|
130
170
|
if (command.type === "clear") {
|
|
131
|
-
|
|
132
|
-
await setLearning((draft) => { draft.snapshot = emptySnapshot() })
|
|
133
|
-
ghost?.invalidate()
|
|
134
|
-
context.ui.toast.show({ title: "Quill", message: "Word autocomplete history cleared" })
|
|
171
|
+
await clearHistory()
|
|
135
172
|
return
|
|
136
173
|
}
|
|
137
174
|
if (command.type === "invalid") {
|
|
@@ -150,12 +187,7 @@ export default Plugin.define({
|
|
|
150
187
|
description: "Reset learned vocabulary, n-grams, and prompt transitions",
|
|
151
188
|
group: "Prompt",
|
|
152
189
|
palette: true,
|
|
153
|
-
run:
|
|
154
|
-
predictor.setPersonal(emptySnapshot())
|
|
155
|
-
await setLearning((draft) => { draft.snapshot = emptySnapshot() })
|
|
156
|
-
ghost?.invalidate()
|
|
157
|
-
context.ui.toast.show({ title: "Quill", message: "Word autocomplete history cleared" })
|
|
158
|
-
},
|
|
190
|
+
run: clearHistory,
|
|
159
191
|
},
|
|
160
192
|
],
|
|
161
193
|
}))
|