opencode-quill 0.5.0 → 0.5.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 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.2] - 2026-10-22
8
+
9
+ ### Fixed
10
+
11
+ - **prediction:** Restore personal completion weight, next-word predictions, and slash-command prose
12
+
13
+ ## [0.5.1] - 2026-10-22
14
+
15
+ ### Fixed
16
+
17
+ - Harden learning persistence and release safety
18
+
7
19
  ## [0.5.0] - 2026-10-22
8
20
 
9
21
  ### Added
@@ -115,6 +127,8 @@ All notable changes are documented in this file using
115
127
  - `/quill` command and command palette action to toggle autocomplete.
116
128
  - Local installer script, full test suite, CI workflows, and release tooling.
117
129
 
130
+ [0.5.2]: https://github.com/ozandogrultan/opencode-quill/compare/v0.5.1...v0.5.2
131
+ [0.5.1]: https://github.com/ozandogrultan/opencode-quill/compare/v0.5.0...v0.5.1
118
132
  [0.5.0]: https://github.com/ozandogrultan/opencode-quill/compare/v0.4.0...v0.5.0
119
133
  [0.4.0]: https://github.com/ozandogrultan/opencode-quill/compare/v0.3.4...v0.4.0
120
134
  [0.3.4]: https://github.com/ozandogrultan/opencode-quill/compare/v0.3.3...v0.3.4
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 size:** the personal model is pruned to its most frequent entries
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.5.0",
3
+ "version": "0.5.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/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(([word, count]) => typeof word === "string" && word.length <= 100 && Number.isFinite(count) && count > 0))
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.slice(-SEEN_LIMIT))
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].slice(-SEEN_LIMIT),
111
+ seen: [...this.seen],
107
112
  ...(this.clearedAt === undefined ? {} : { clearedAt: this.clearedAt }),
108
113
  }
109
114
  }
@@ -257,10 +262,11 @@ export class WordPredictor {
257
262
  }
258
263
  }
259
264
 
260
- private score(word: string, context: readonly string[]): number {
265
+ private score(word: string, context: readonly string[], typo = false): 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.priorTotal ? Math.min(0.7, this.personalTotal / (this.personalTotal + 100)) : 1
268
+ const ratio = this.personalTotal / (this.personalTotal + 100)
269
+ const weight = this.priorTotal ? (typo ? Math.min(0.7, ratio) : ratio) : 1
264
270
  let score = weight * personal + (1 - weight) * prior
265
271
  const previous = context.at(-1)
266
272
  const bigram = previous && this.bigramTotals.get(previous)
@@ -270,7 +276,7 @@ export class WordPredictor {
270
276
  }
271
277
  const pair = context.length === 2 ? context.join("\0") : undefined
272
278
  const trigram = pair && this.trigramTotals.get(pair)
273
- if (trigram) {
279
+ if (trigram && trigram.total >= 2) {
274
280
  const count = this.personal.trigrams.get(`${pair}\0${word}`) ?? 0
275
281
  score = Math.max(count - DISCOUNT, 0) / trigram.total + DISCOUNT * trigram.types / trigram.total * score
276
282
  }
@@ -291,7 +297,7 @@ export class WordPredictor {
291
297
  if ((this.bigramTotals.get(candidate)?.total ?? 0) < 2) continue
292
298
  const weight = typoWeight(word, candidate, true)
293
299
  if (!weight) continue
294
- const score = this.score(candidate, resolved) * weight
300
+ const score = this.score(candidate, resolved, true) * weight
295
301
  sum += score
296
302
  if (score > bestScore) {
297
303
  best = candidate
@@ -315,7 +321,9 @@ export class WordPredictor {
315
321
  const local = new Map<string, number>()
316
322
  for (const word of words) increment(local, word.text)
317
323
  const context = this.resolveContext(leftContext(query.before, words), local)
318
- const evidence = this.bigramTotals.get(context.at(-1) ?? "")?.total ?? 0
324
+ const previous = context.at(-1)
325
+ const pair = context.length === 2 ? context.join("\0") : undefined
326
+ const evidence = this.bigramTotals.get(previous ?? "")?.total ?? 0
319
327
  if (query.next && evidence < 2) return []
320
328
  if (!query.next && [...prefix].length < 2 && evidence < 2) return []
321
329
  const slash = prefix.includes("/")
@@ -326,11 +334,13 @@ export class WordPredictor {
326
334
  if (query.next || slash === word.includes("/")) candidates.set(word, 1)
327
335
  }
328
336
  for (const word of local.keys()) if (!word.includes("/") && word.startsWith(prefix) && (query.next || !slash)) candidates.set(word, 1)
337
+ const followed = (word: string) => (previous ? this.personal.bigrams.get(`${previous}\0${word}`) ?? 0 : 0) >= 2 ||
338
+ (pair ? this.personal.trigrams.get(`${pair}\0${word}`) ?? 0 : 0) >= 2
329
339
  const suggest = (): Prediction[] => {
330
340
  const ranked: { word: string; score: number; weight: number }[] = []
331
341
  let sum = 0
332
342
  for (const [word, weight] of candidates) {
333
- const base = this.score(word, context) + (query.next ? 0 : 0.003 * Math.min(local.get(word) ?? 0, 3))
343
+ const base = this.score(word, context, weight < 1) + (query.next ? 0 : 0.003 * Math.min(local.get(word) ?? 0, 3))
334
344
  const score = base * weight
335
345
  sum += score
336
346
  ranked.push({ word, score, weight })
@@ -340,7 +350,7 @@ export class WordPredictor {
340
350
  const predictions: Prediction[] = []
341
351
  for (const { word: best, score: bestScore, weight: bestWeight } of ranked) {
342
352
  const confidence = bestWeight < 1 ? typoConfidence(bestScore, sum) : query.next ? bestScore : bestScore / (sum || 1)
343
- if (!bestScore || best === prefix || confidence === undefined || (bestWeight === 1 && confidence < (query.next ? 0.55 : 0.3))) {
353
+ if (!bestScore || best === prefix || confidence === undefined || (query.next && !followed(best)) || (bestWeight === 1 && confidence < 0.3)) {
344
354
  if (!predictions.length) return []
345
355
  continue
346
356
  }
package/src/prose.ts CHANGED
@@ -24,11 +24,24 @@ function blank(text: string): string {
24
24
  }
25
25
 
26
26
  export function maskProse(text: string): string {
27
- let masked = text.replace(/(^|\n)[ \t]*(`{3,}|~{3,})[^\n]*\n[\s\S]*?(?:\n[ \t]*\2[^\n]*(?=\n|$)|$)/g, blank)
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
+ })
28
41
  masked = masked.replace(/(`+)[\s\S]*?(?:\1|$)/g, blank)
29
42
  masked = masked.replace(/(?:https?:\/\/|www\.)\S+|\[[^\]\n]*\]\([^\)\n]*\)|<[^>\n]+>/g, blank)
30
- masked = masked.replace(/^[ \t]*(?:[\/!$]|(?:const|let|var|function|class|import|export)\s|(?:Traceback|Error:)\b).*$/gm, blank)
31
- masked = masked.replace(/^ {4,}.*$/gm, blank)
43
+ masked = masked.replace(/^[ \t]*(?:[!$]|(?:const|let|var|function|class|import|export)\s|(?:Traceback|Error:)\b).*$/gm, blank)
44
+ masked = masked.replace(/^(?: {4}| {0,3}\t).*$/gm, blank)
32
45
  masked = masked.replace(/\S+/g, (token) => {
33
46
  const core = token.replace(/^["“‘([{]+|["”’),;:!?}\]]+$/g, "")
34
47
  if (/[_@=\\<>-]|\d|[\p{Ll}][\p{Lu}]/u.test(core) || /^[.~]/.test(core)) return blank(token)