@cortexkit/pi-magic-context 0.49.37 → 0.49.39

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.
@@ -31,7 +31,7 @@ serveWorkerJobs(async (initial, port) => {
31
31
  import("./embedding-cache-7rp4gqzr.js"),
32
32
  import("./storage-memory-0ndn65fm.js"),
33
33
  import("./project-embedding-registry-16pj4vyf.js"),
34
- import("./search-3p18trsb.js"),
34
+ import("./search-45wknkb6.js"),
35
35
  import("./compartment-chunk-embedding-jpcme6tz.js"),
36
36
  import("./embedding-activity-ew6dshfd.js"),
37
37
  import("./harness-9872e0ym.js"),
@@ -80,7 +80,7 @@ import {
80
80
  } from "./index-29nw7n1r.js";
81
81
  import {
82
82
  cleanSearchText,
83
- keywordRelevance,
83
+ hintKeywordRelevance,
84
84
  matchedSearchSnippet,
85
85
  getMessageIndexSourceIdentity,
86
86
  isMessageIndexSourceCurrent,
@@ -91,7 +91,7 @@ import {
91
91
  clearIndexedMessages,
92
92
  indexSingleMessage,
93
93
  indexMessagesAfterOrdinal
94
- } from "./index-kj49vs41.js";
94
+ } from "./index-j0h89gxy.js";
95
95
  import {
96
96
  MESSAGE_FTS_SESSION_FILTER_SQL,
97
97
  withMessageFtsSessionFilter
@@ -1697,6 +1697,11 @@ function invalidateIncrementalWork(sessionId) {
1697
1697
  }
1698
1698
 
1699
1699
  // ../plugin/src/features/magic-context/auto-search-diagnostics.ts
1700
+ var memoryHintContent = new WeakMap;
1701
+ function withMemoryHintContent(result, fullContent) {
1702
+ memoryHintContent.set(result, fullContent);
1703
+ return result;
1704
+ }
1700
1705
  function createAutoSearchDiagnostics(threshold) {
1701
1706
  return {
1702
1707
  threshold,
@@ -1708,9 +1713,10 @@ function createAutoSearchDiagnostics(threshold) {
1708
1713
  };
1709
1714
  }
1710
1715
  function autoSearchRelevance(query, result) {
1711
- if (cleanSearchText(result.source === "compartment" ? result.title : result.content).length === 0)
1716
+ const content = result.source === "memory" ? memoryHintContent.get(result) ?? result.content : result.source === "compartment" ? result.title : result.content;
1717
+ if (cleanSearchText(content).length === 0)
1712
1718
  return 0;
1713
- return result.source === "message" || "matchType" in result && result.source !== "compartment" && result.matchType !== "semantic" ? keywordRelevance(query, result.content) : result.score;
1719
+ return result.source === "message" || "matchType" in result && result.source !== "compartment" && result.matchType !== "semantic" ? hintKeywordRelevance(query, content) : result.score;
1714
1720
  }
1715
1721
  function recordAutoSearchLane(diagnostics, lane, query, results) {
1716
1722
  if (!diagnostics)
@@ -2064,19 +2070,15 @@ async function remoteScores(config, query, documents, signal) {
2064
2070
  "Content-Type": "application/json",
2065
2071
  ...config.api_key ? { Authorization: `Bearer ${config.api_key}` } : {}
2066
2072
  },
2067
- body: JSON.stringify(tei ? { query, texts: documents } : {
2068
- model: config.model,
2069
- query,
2070
- documents,
2071
- top_n: documents.length
2072
- }),
2073
+ body: JSON.stringify(tei ? { query, texts: documents } : { model: config.model, query, documents }),
2073
2074
  signal: controller.signal,
2074
2075
  redirect: "error"
2075
2076
  });
2076
2077
  if (!response.ok)
2077
2078
  throw new RerankFailure(`http_${response.status}`);
2078
2079
  const body = await response.json();
2079
- const rows = tei ? body : body?.results;
2080
+ const reply = body;
2081
+ const rows = tei ? body : reply?.results ?? reply?.data;
2080
2082
  if (!Array.isArray(rows) || rows.length !== documents.length)
2081
2083
  throw new RerankFailure("invalid_reply");
2082
2084
  const scores = new Array(documents.length);
@@ -2678,7 +2680,7 @@ function mergeMemoryResults(args) {
2678
2680
  suppressedVisibleIds.push(id);
2679
2681
  continue;
2680
2682
  }
2681
- results.push({
2683
+ results.push(withMemoryHintContent({
2682
2684
  source: "memory",
2683
2685
  content: previewText(memory.content),
2684
2686
  score,
@@ -2686,7 +2688,7 @@ function mergeMemoryResults(args) {
2686
2688
  category: memory.category,
2687
2689
  matchType,
2688
2690
  sourceName: args.sourceNameByMemoryId?.get(memory.id)
2689
- });
2691
+ }, memory.content));
2690
2692
  }
2691
2693
  return {
2692
2694
  results: results.sort((left, right) => {
@@ -66,6 +66,39 @@ function keywordRelevance(query, content) {
66
66
  const words = new Set(terms(cleanSearchText(content)));
67
67
  return 0.8 * needles.filter((term) => words.has(term)).length / needles.length;
68
68
  }
69
+ var CJK_RUN = /^[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}]+$/u;
70
+ var CJK_RUN_SPLIT = /([\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}]+)/u;
71
+ function hintTerms(text) {
72
+ return [
73
+ ...new Set(terms(text).flatMap((term) => term.split(CJK_RUN_SPLIT)).filter((term) => term.length > 0 && !QUERY_STOP_WORDS.has(term)))
74
+ ];
75
+ }
76
+ function characterBigrams(run) {
77
+ const characters = [...run];
78
+ return characters.length === 1 ? characters : characters.slice(1).map((character, index) => characters[index] + character);
79
+ }
80
+ function hintKeywordRelevance(query, content) {
81
+ const needles = hintTerms(query);
82
+ if (needles.length === 0)
83
+ return 0;
84
+ const words = new Set(hintTerms(cleanSearchText(content)));
85
+ const runs = [...words].filter((word) => CJK_RUN.test(word));
86
+ const bigrams = new Set(runs.flatMap(characterBigrams));
87
+ let matched = 0;
88
+ for (const needle of needles) {
89
+ if (!CJK_RUN.test(needle)) {
90
+ matched += Number(words.has(needle));
91
+ continue;
92
+ }
93
+ const grams = characterBigrams(needle);
94
+ if ([...needle].length === 1) {
95
+ matched += Number(runs.some((run) => run.includes(needle)));
96
+ continue;
97
+ }
98
+ matched += Math.min(1, grams.filter((gram) => bigrams.has(gram)).length / Math.ceil(grams.length / 2));
99
+ }
100
+ return 0.8 * matched / needles.length;
101
+ }
69
102
  function matchedSearchSnippet(content, query, cap = 220) {
70
103
  const text = cleanSearchText(content);
71
104
  const needles = new Set(terms(query));
@@ -546,4 +579,4 @@ function indexItemsAfterOrdinal(db, sessionId, items, finalWatermark, toSource)
546
579
  return inserted;
547
580
  }
548
581
 
549
- export { clearCompressionDepth, clearCompressionDepthRange, cleanSearchText, keywordRelevance, matchedSearchSnippet, MESSAGE_INDEX_MAX_FTS_BYTES, messageIndexSkipKey, getMessageIndexSourceIdentity, isMessageIndexSourceCurrent, getLastIndexedOrdinal, getIndexedMessageCorpusSize, markMessageIndexDirty, getMessageIndexReconciliationStartOrdinal, isMessageIndexReconciledThrough, clearIndexedMessages, getIndexableContent, indexSingleMessage, indexMessagesAfterOrdinal };
582
+ export { clearCompressionDepth, clearCompressionDepthRange, cleanSearchText, hintKeywordRelevance, matchedSearchSnippet, MESSAGE_INDEX_MAX_FTS_BYTES, messageIndexSkipKey, getMessageIndexSourceIdentity, isMessageIndexSourceCurrent, getLastIndexedOrdinal, getIndexedMessageCorpusSize, markMessageIndexDirty, getMessageIndexReconciliationStartOrdinal, isMessageIndexReconciledThrough, clearIndexedMessages, getIndexableContent, indexSingleMessage, indexMessagesAfterOrdinal };
@@ -140,8 +140,8 @@ async function serveV2ArchiveReads2(port, openConnections) {
140
140
  import("./store-reader-2m80zs5z.js"),
141
141
  import("./store-v60q7dje.js"),
142
142
  import("./read-session-chunk-jxq427v6.js"),
143
- import("./render-2wan3bfh.js"),
144
- import("./search-archive-pgrv04gv.js"),
143
+ import("./render-6bhqgkpq.js"),
144
+ import("./search-archive-yvdq2nfp.js"),
145
145
  import("./expand-attachments-8sxeyj26.js")
146
146
  ]);
147
147
  const pool = new V2StoreReaderPool;
@@ -73,7 +73,7 @@ import {
73
73
  } from "./index-p9jfa33t.js";
74
74
  import {
75
75
  getLastIndexedOrdinal
76
- } from "./index-kj49vs41.js";
76
+ } from "./index-j0h89gxy.js";
77
77
  import {
78
78
  setNoteLastReadAt,
79
79
  getPersistedCompactionMarkerState,
@@ -133,7 +133,7 @@ import {
133
133
  resolveMemoriesByIdsForSearch2,
134
134
  unifiedSearch2,
135
135
  formatSearchResults2
136
- } from "./index-f6y7mdq9.js";
136
+ } from "./index-g2j58qpq.js";
137
137
  import {
138
138
  TODO_STATUSES,
139
139
  TODO_PRIORITIES,
package/dist/index.js CHANGED
@@ -150,7 +150,7 @@ import {
150
150
  registerTodoStateLifecycle,
151
151
  syncCtxMemoryToolEnabled,
152
152
  registerMagicContextTools
153
- } from "./index-dgqjq8sg.js";
153
+ } from "./index-rtg4a0sg.js";
154
154
  import"./index-4knyh1kt.js";
155
155
  import {
156
156
  canonicalModelIdentity,
@@ -665,7 +665,7 @@ import {
665
665
  clearCompressionDepthRange,
666
666
  cleanSearchText,
667
667
  matchedSearchSnippet
668
- } from "./index-kj49vs41.js";
668
+ } from "./index-j0h89gxy.js";
669
669
  import {
670
670
  rememberV1HiddenRun
671
671
  } from "./index-6x556c2q.js";
@@ -797,7 +797,7 @@ import {
797
797
  scheduleClearAndReindex,
798
798
  clearSessionTracking,
799
799
  createAutoSearchDiagnostics
800
- } from "./index-f6y7mdq9.js";
800
+ } from "./index-g2j58qpq.js";
801
801
  import"./index-y90fxz4t.js";
802
802
  import {
803
803
  DREAMER_PRIMER_INVESTIGATOR_ALLOWED_TOOLS,
@@ -828,7 +828,7 @@ import {
828
828
  } from "./index-wwsfevck.js";
829
829
  import"./index-cq71g4dk.js";
830
830
  import"./index-1cvyaw9a.js";
831
- import"./index-gxqmh9hq.js";
831
+ import"./index-k0csz6pb.js";
832
832
  import"./index-ry84c8dr.js";
833
833
  import {
834
834
  __toESM
@@ -3584,7 +3584,7 @@ function startHostStallProfilerSwitch() {
3584
3584
  // package.json
3585
3585
  var package_default = {
3586
3586
  name: "@cortexkit/pi-magic-context",
3587
- version: "0.49.37",
3587
+ version: "0.49.39",
3588
3588
  type: "module",
3589
3589
  description: "Pi and OMP coding agent extension for Magic Context — cross-session memory and context management",
3590
3590
  main: "dist/index.js",
@@ -21912,7 +21912,14 @@ function resolveProviderModelAttempt(model, targetHarness) {
21912
21912
  };
21913
21913
  }
21914
21914
  function isProviderCredentialFailure(result, attempt) {
21915
- return attempt.translated && !result.ok && result.reason === "non_zero_exit" && getResultStderr(result).includes(`No API key found for ${attempt.attemptedProvider}`);
21915
+ if (!attempt.translated || result.ok)
21916
+ return false;
21917
+ const missingKey = `No API key found for ${attempt.attemptedProvider}`;
21918
+ if (result.reason === "non_zero_exit")
21919
+ return getResultStderr(result).includes(missingKey);
21920
+ if (result.reason === "model_failed")
21921
+ return (result.error ?? "").includes(missingKey);
21922
+ return false;
21916
21923
  }
21917
21924
  var PROMPT_ARGV_MAX_BYTES = 96 * 1024;
21918
21925
  function buildArgs(options, opts) {
@@ -25,7 +25,7 @@ import {
25
25
  markMessageIndexDirty,
26
26
  getIndexableContent,
27
27
  indexSingleMessage
28
- } from "./index-kj49vs41.js";
28
+ } from "./index-j0h89gxy.js";
29
29
  import"./index-ck8wj35v.js";
30
30
  import"./index-0wtm7g7f.js";
31
31
 
@@ -19,7 +19,7 @@ serveWorkerJobs(async (input, port) => {
19
19
  await main();
20
20
  async function main() {
21
21
  if (input.v2ArchiveReader) {
22
- const { serveV2ArchiveReads } = await import("./v2-archive-reader-5zpj8hrg.js");
22
+ const { serveV2ArchiveReads } = await import("./v2-archive-reader-bd94n954.js");
23
23
  await serveV2ArchiveReads(port, openConnections);
24
24
  return;
25
25
  }
@@ -51,7 +51,7 @@ serveWorkerJobs(async (input, port) => {
51
51
  await runMessageFtsRowidMapBackfill(db);
52
52
  reply = { kind: "fts-rowid-backfill" };
53
53
  } else if (input.searchArchive) {
54
- const { renderSearchArchive } = await import("./search-archive-pgrv04gv.js");
54
+ const { renderSearchArchive } = await import("./search-archive-yvdq2nfp.js");
55
55
  const { readRawSessionMessageIdOrdinalsForRangeFromDb } = await import("./read-session-raw-a9ntjqap.js");
56
56
  const archive = input.searchArchive;
57
57
  let raw;
@@ -81,7 +81,7 @@ serveWorkerJobs(async (input, port) => {
81
81
  const { setHarness } = await import("./harness-9872e0ym.js");
82
82
  setHarness(input.harness ?? "opencode");
83
83
  const [{ indexMessageInShortChunks }, { configureContextDatabasePragmas }] = await Promise.all([
84
- import("./message-index-bounded-82sergz7.js"),
84
+ import("./message-index-bounded-39z2atfj.js"),
85
85
  import("./sqlite-context-pragmas-gcgch6qz.js")
86
86
  ]);
87
87
  configureContextDatabasePragmas(db);
@@ -5,7 +5,7 @@ import {
5
5
  renderItemByTag2
6
6
  } from "./index-p9jfa33t.js";
7
7
  import"./index-w26zvs1q.js";
8
- import"./index-kj49vs41.js";
8
+ import"./index-j0h89gxy.js";
9
9
  import"./index-hgd00nas.js";
10
10
  import"./index-ea37qn4x.js";
11
11
  import"./index-f9qet7y8.js";
@@ -5,9 +5,9 @@ import {
5
5
  resolveMemoriesByIdsForSearch2,
6
6
  unifiedSearch2,
7
7
  formatSearchResults2
8
- } from "./index-f6y7mdq9.js";
8
+ } from "./index-g2j58qpq.js";
9
9
  import"./index-w26zvs1q.js";
10
- import"./index-kj49vs41.js";
10
+ import"./index-j0h89gxy.js";
11
11
  import"./index-1cvyaw9a.js";
12
12
  import"./index-jbkwszd5.js";
13
13
  import"./index-29nw7n1r.js";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  renderSearchArchive2
3
3
  } from "./index-ry84c8dr.js";
4
- import"./index-gxqmh9hq.js";
4
+ import"./index-k0csz6pb.js";
5
5
  import"./index-1cvyaw9a.js";
6
6
  import"./index-mx757f3g.js";
7
7
  import"./index-pwp6zyx3.js";
@@ -34,7 +34,7 @@ import {
34
34
  ensureProjectRegisteredFromPiDirectory,
35
35
  resolvePiHarnessKind,
36
36
  registerMagicContextTools
37
- } from "./index-dgqjq8sg.js";
37
+ } from "./index-rtg4a0sg.js";
38
38
  import"./index-ccanzg8p.js";
39
39
  import"./index-rzfr7wdv.js";
40
40
  import"./index-f9qet7y8.js";
@@ -46,16 +46,16 @@ import"./index-mp0gh04g.js";
46
46
  import"./index-yhzhdp3m.js";
47
47
  import"./index-jbkwszd5.js";
48
48
  import"./index-p9jfa33t.js";
49
- import"./index-kj49vs41.js";
49
+ import"./index-j0h89gxy.js";
50
50
  import"./index-pwp6zyx3.js";
51
51
  import"./index-6x556c2q.js";
52
52
  import"./index-ea37qn4x.js";
53
53
  import"./index-w26zvs1q.js";
54
54
  import"./index-1cvyaw9a.js";
55
- import"./index-gxqmh9hq.js";
55
+ import"./index-k0csz6pb.js";
56
56
  import"./index-ry84c8dr.js";
57
57
  import"./index-29nw7n1r.js";
58
- import"./index-f6y7mdq9.js";
58
+ import"./index-g2j58qpq.js";
59
59
  import"./index-y90fxz4t.js";
60
60
  import"./index-0wtm7g7f.js";
61
61
  import {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  readV2ArchiveOffThread2,
3
3
  serveV2ArchiveReads2
4
- } from "./index-gxqmh9hq.js";
4
+ } from "./index-k0csz6pb.js";
5
5
  import"./index-8sqebjzk.js";
6
6
  import"./index-2qtx0q6h.js";
7
7
  import"./index-x2n261wp.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cortexkit/pi-magic-context",
3
- "version": "0.49.37",
3
+ "version": "0.49.39",
4
4
  "type": "module",
5
5
  "description": "Pi and OMP coding agent extension for Magic Context — cross-session memory and context management",
6
6
  "main": "dist/index.js",