dsh-composer-quill 0.31.8 → 0.31.9

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.
Files changed (3) hide show
  1. package/client.js +1 -1
  2. package/index.js +52 -1
  3. package/package.json +1 -1
package/client.js CHANGED
@@ -26,7 +26,7 @@ window.__ModuleLoader__.load({
26
26
  const h = React.createElement
27
27
 
28
28
  const NS = 'composer-quill'
29
- const BUILD = '0.31.8'
29
+ const BUILD = '0.31.9'
30
30
  const ROUTE = '/composer-quill/predict'
31
31
  const BEACON = '/composer-quill/beacon'
32
32
  /** The browser's own language, used when the Host has no style profile. */
package/index.js CHANGED
@@ -453,6 +453,40 @@ function groundedness(candidate, contextText) {
453
453
  return shared / candidateGrams.size
454
454
  }
455
455
 
456
+ /** Shorter than this and a "repeat" is just a short phrase both sides share. */
457
+ const REPEAT_MIN_CHARS = 8
458
+
459
+ /** Every user message already in the transcript, in comparable form. */
460
+ function priorUserMessages(events) {
461
+ const seen = []
462
+ for (const event of events ?? []) {
463
+ if (event?.type !== 'user/message') continue
464
+ const text = normalizeForCompare(textOfBlocks(event?.data?.content ?? event?.data?.message?.content))
465
+ if (text.length >= REPEAT_MIN_CHARS) seen.push(text)
466
+ }
467
+ return seen
468
+ }
469
+
470
+ /**
471
+ * Is this candidate something the user already sent?
472
+ *
473
+ * Groundedness cannot answer that: a recycled earlier question matches the
474
+ * transcript perfectly and scores ~1.0, which is exactly the report "the
475
+ * suggestion is content from many turns ago". A prediction has to be new.
476
+ */
477
+ function repeatsEarlierUser(candidate, priorNormalised) {
478
+ const value = normalizeForCompare(candidate)
479
+ if (value.length < REPEAT_MIN_CHARS) return false
480
+ for (const other of priorNormalised ?? []) {
481
+ if (other === value) return true
482
+ // One containing the other means the same question asked again with a prefix
483
+ // or a trailing clause — near-duplicates count as repeats.
484
+ if (other.length >= REPEAT_MIN_CHARS && value.includes(other)) return true
485
+ if (value.length >= REPEAT_MIN_CHARS && other.includes(value)) return true
486
+ }
487
+ return false
488
+ }
489
+
456
490
  /**
457
491
  * A next-message that touches none of the conversation's wording is almost always
458
492
  * about something else entirely (the "this has nothing to do with the session"
@@ -1390,6 +1424,22 @@ async function computePrediction(ctx, { session, events, hasTurns, kind, cleanDr
1390
1424
  const lastUser = [...events].reverse().find((event) => event?.type === 'user/message')
1391
1425
  const lastUserText = textOfBlocks(lastUser?.data?.content ?? lastUser?.data?.message?.content)
1392
1426
  let candidates = rankCandidates(parseCandidates(text), { profile, lastAssistant: assistant, lastUser: lastUserText, locale, forced })
1427
+ // A prediction that repeats an earlier user message is not a prediction: the
1428
+ // conversation has moved on. Drop those before the grounding gate, which would
1429
+ // otherwise score them highest precisely because they already exist.
1430
+ if (kind === 'next' && candidates.length > 0) {
1431
+ const prior = priorUserMessages(events)
1432
+ const fresh = candidates.filter((candidate) => !repeatsEarlierUser(candidate, prior))
1433
+ if (fresh.length !== candidates.length) {
1434
+ trace('next-repeated', {
1435
+ kept: fresh.length,
1436
+ dropped: candidates.length - fresh.length,
1437
+ candidates: candidates.length,
1438
+ priorMessages: prior.length,
1439
+ })
1440
+ candidates = fresh
1441
+ }
1442
+ }
1393
1443
  // Grounding check: only for the next-message prediction, where an off-topic
1394
1444
  // guess has no anchor at all. A completion always has the draft to anchor on.
1395
1445
  if (kind === 'next' && candidates.length > 0 && context !== '[]') {
@@ -1811,7 +1861,8 @@ export function apply(ctx) {
1811
1861
  }
1812
1862
 
1813
1863
  /** Pure helpers exposed for the offline smoke test. */
1814
- export const __test = { cacheFile, loadCache, rotateLog, LOG_MAX_BYTES, buildShortDraftPrompt, eventsOf, resolveLanguage, wrongLanguage, latinShareOf, groundedness, MIN_GROUNDEDNESS, styleProfile, rankCandidates, looksLikeMeta, isPunctuationOnly, scriptOf, sessionDigest, size: () => cache.size, shorten, parseCandidates, parseComposed, parseComposeReply, parseSentence, joinSentence, transcriptOf, historyOf, maskSecrets, cleanLine, authorized }
1864
+ export const __test = { cacheFile, loadCache, rotateLog, LOG_MAX_BYTES, buildShortDraftPrompt, eventsOf, resolveLanguage, wrongLanguage, latinShareOf, groundedness, MIN_GROUNDEDNESS, priorUserMessages, repeatsEarlierUser, REPEAT_MIN_CHARS, styleProfile, rankCandidates, looksLikeMeta, isPunctuationOnly, scriptOf, sessionDigest, size: () => cache.size, shorten, parseCandidates, parseComposed, parseComposeReply, parseSentence, joinSentence, transcriptOf, historyOf, maskSecrets, cleanLine, authorized }
1865
+
1815
1866
 
1816
1867
 
1817
1868
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-composer-quill",
3
- "version": "0.31.8",
3
+ "version": "0.31.9",
4
4
  "type": "module",
5
5
  "description": "Quill: completion for the DeepSeek Harness composer: predicts your next message and completes what you are typing.",
6
6
  "license": "MIT",