opencode-quill 0.4.0 → 0.5.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 CHANGED
@@ -4,6 +4,12 @@ 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.0] - 2026-10-22
8
+
9
+ ### Added
10
+
11
+ - **prediction:** Complete learned slash tokens and preserve prior weight
12
+
7
13
  ## [0.4.0] - 2026-10-21
8
14
 
9
15
  ### Added
@@ -109,6 +115,7 @@ All notable changes are documented in this file using
109
115
  - `/quill` command and command palette action to toggle autocomplete.
110
116
  - Local installer script, full test suite, CI workflows, and release tooling.
111
117
 
118
+ [0.5.0]: https://github.com/ozandogrultan/opencode-quill/compare/v0.4.0...v0.5.0
112
119
  [0.4.0]: https://github.com/ozandogrultan/opencode-quill/compare/v0.3.4...v0.4.0
113
120
  [0.3.4]: https://github.com/ozandogrultan/opencode-quill/compare/v0.3.3...v0.3.4
114
121
  [0.3.3]: https://github.com/ozandogrultan/opencode-quill/compare/v0.3.2...v0.3.3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-quill",
3
- "version": "0.4.0",
3
+ "version": "0.5.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
@@ -229,7 +229,7 @@ export class WordPredictor {
229
229
  const word = learned[index]
230
230
  if (this.prior.has(word)) continue
231
231
  for (let next = index + 1; next < learned.length && learned[next].startsWith(word); next++) {
232
- if (counts.get(learned[next])! >= counts.get(word)!) {
232
+ if (learned[next][word.length] !== "/" && counts.get(learned[next])! >= counts.get(word)!) {
233
233
  fragments.add(word)
234
234
  break
235
235
  }
@@ -252,7 +252,7 @@ export class WordPredictor {
252
252
  for (let index = lowerBound(this.vocabulary, head); index < this.vocabulary.length; index++) {
253
253
  const word = this.vocabulary[index]
254
254
  if (!word.startsWith(head)) break
255
- if (word.length >= prefix.length - 1 && word.length <= maxLength) yield word
255
+ if (!word.includes("/") && word.length >= prefix.length - 1 && word.length <= maxLength) yield word
256
256
  }
257
257
  }
258
258
  }
@@ -260,7 +260,7 @@ export class WordPredictor {
260
260
  private score(word: string, context: readonly string[]): number {
261
261
  const prior = (this.prior.get(word) ?? 0) / (this.priorTotal || 1)
262
262
  const personal = (this.personal.words.get(word) ?? 0) / (this.personalTotal || 1)
263
- const weight = this.personalTotal / (this.personalTotal + 100)
263
+ const weight = this.priorTotal ? Math.min(0.7, this.personalTotal / (this.personalTotal + 100)) : 1
264
264
  let score = weight * personal + (1 - weight) * prior
265
265
  const previous = context.at(-1)
266
266
  const bigram = previous && this.bigramTotals.get(previous)
@@ -318,13 +318,14 @@ export class WordPredictor {
318
318
  const evidence = this.bigramTotals.get(context.at(-1) ?? "")?.total ?? 0
319
319
  if (query.next && evidence < 2) return []
320
320
  if (!query.next && [...prefix].length < 2 && evidence < 2) return []
321
+ const slash = prefix.includes("/")
321
322
  const candidates = new Map<string, number>()
322
323
  for (let index = lowerBound(this.vocabulary, prefix); index < this.vocabulary.length; index++) {
323
324
  const word = this.vocabulary[index]
324
325
  if (!word.startsWith(prefix)) break
325
- candidates.set(word, 1)
326
+ if (query.next || slash === word.includes("/")) candidates.set(word, 1)
326
327
  }
327
- for (const word of local.keys()) if (word.startsWith(prefix)) candidates.set(word, 1)
328
+ for (const word of local.keys()) if (!word.includes("/") && word.startsWith(prefix) && (query.next || !slash)) candidates.set(word, 1)
328
329
  const suggest = (): Prediction[] => {
329
330
  const ranked: { word: string; score: number; weight: number }[] = []
330
331
  let sum = 0
@@ -358,14 +359,14 @@ export class WordPredictor {
358
359
  return predictions
359
360
  }
360
361
  const completion = suggest()
361
- if (completion.length || query.next || prefix.length < 3 || candidates.has(prefix)) return completion
362
+ if (completion.length || query.next || prefix.length < 3 || slash || candidates.has(prefix)) return completion
362
363
  for (const word of this.nearbyWords(prefix)) {
363
364
  if (candidates.has(word)) continue
364
365
  const weight = typoWeight(prefix, word)
365
366
  if (weight > 0) candidates.set(word, weight)
366
367
  }
367
368
  for (const word of local.keys()) {
368
- if (candidates.has(word)) continue
369
+ if (candidates.has(word) || word.includes("/")) continue
369
370
  const weight = typoWeight(prefix, word)
370
371
  if (weight > 0) candidates.set(word, weight)
371
372
  }
package/src/prose.ts CHANGED
@@ -1,6 +1,8 @@
1
- const WORD = /[\p{L}\p{M}]+(?:['’][\p{L}\p{M}]+)*/gu
2
- const WHOLE_WORD = /^[\p{L}\p{M}]+(?:['’][\p{L}\p{M}]+)*$/u
3
- const WORD_END = /[\p{L}\p{M}]+(?:['’][\p{L}\p{M}]+)*$/u
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,6 +15,10 @@ 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
  }
@@ -25,7 +31,8 @@ export function maskProse(text: string): string {
25
31
  masked = masked.replace(/^ {4,}.*$/gm, blank)
26
32
  masked = masked.replace(/\S+/g, (token) => {
27
33
  const core = token.replace(/^["“‘([{]+|["”’),;:!?}\]]+$/g, "")
28
- if (/[\/_@=\\<>-]|\d|[\p{Ll}][\p{Lu}]/u.test(core) || /^[.~]/.test(core)) return blank(token)
34
+ if (/[_@=\\<>-]|\d|[\p{Ll}][\p{Lu}]/u.test(core) || /^[.~]/.test(core)) return blank(token)
35
+ if (core.includes("/") && !(core.endsWith(".") ? WHOLE_WORD.test(core.slice(0, -1)) : WORD_PREFIX.test(core))) return blank(token)
29
36
  if (/[^.]+\.[^.]+|\.\.|--/.test(core)) return blank(token)
30
37
  return token
31
38
  })
@@ -34,7 +41,7 @@ export function maskProse(text: string): string {
34
41
 
35
42
  export function proseWords(text: string, masked = maskProse(text)): Word[] {
36
43
  return [...masked.matchAll(WORD)]
37
- .filter((match) => isWord(match[0]))
44
+ .filter((match) => isWord(match[0]) && masked[match.index + match[0].length] !== "/")
38
45
  .map((match) => ({ text: normalizeWord(match[0]), start: match.index, end: match.index + match[0].length }))
39
46
  }
40
47
 
@@ -81,7 +88,7 @@ export function completionQuery(draft: string, characterOffset: number, protecte
81
88
  let end = text.length
82
89
  if (prefix) {
83
90
  const start = text.length - prefix.length
84
- if (masked.slice(start) !== prefix || !isWord(prefix)) return
91
+ if (masked.slice(start) !== prefix || !isPrefix(prefix)) return
85
92
  const preceding = text[start - 1]
86
93
  if (preceding && !/[ \t\n"“([{]/.test(preceding)) return
87
94
  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 (context.data.session.list().find((session) => session.id === sessionID)?.parentID) return
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 (context.data.session.list().find((session) => session.id === sessionID)?.parentID) return
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
- if (context.data.session.list().find((session) => session.id === sessionID)?.parentID) return
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
  })