@cortexkit/pi-magic-context 0.49.16 → 0.49.18

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 (51) hide show
  1. package/dist/auto-search-worker.js +76 -63
  2. package/dist/chunk-embedding-write-worker.js +10 -10
  3. package/dist/{compaction-marker-candidates-k4tqg4jb.js → compaction-marker-candidates-wjzqbspm.js} +2 -2
  4. package/dist/compaction-marker-candidates-worker.js +2 -2
  5. package/dist/embedding-backfill-vwag34t0.js +23 -0
  6. package/dist/embedding-worker-process.js +1 -1
  7. package/dist/embedding-worker.js +4 -4
  8. package/dist/historian-calibration-extension.js +4 -1
  9. package/dist/{index-g4jf772p.js → index-1kcfwk9c.js} +22 -2
  10. package/dist/{index-657xh9w4.js → index-2mmy81qt.js} +2 -2
  11. package/dist/{index-x3k1530z.js → index-4bv5bttd.js} +3 -3
  12. package/dist/index-4knyh1kt.js +1387 -0
  13. package/dist/{index-ja1c33qa.js → index-d21pdr8v.js} +2 -2
  14. package/dist/{index-xmzhrht0.js → index-d43hmn31.js} +29 -18
  15. package/dist/{index-6dz2ed1v.js → index-d8gc0112.js} +2 -2
  16. package/dist/{index-hy44m6jc.js → index-e1rza8gp.js} +1 -1
  17. package/dist/{index-ajfpyk0x.js → index-fa485mqs.js} +59 -1
  18. package/dist/{index-fhyy4ave.js → index-fvjthct0.js} +851 -73
  19. package/dist/{index-y5c73caa.js → index-g7p75667.js} +32 -3
  20. package/dist/{index-tympym62.js → index-gdjv1nnd.js} +2 -2
  21. package/dist/{index-v8d4vgam.js → index-gp928w10.js} +6 -6
  22. package/dist/{index-46q4e104.js → index-qpq6w67c.js} +1 -1
  23. package/dist/{index-44h64qza.js → index-r9f4f6s1.js} +14 -10
  24. package/dist/{index-dne4ja7a.js → index-rhprywn6.js} +4 -4
  25. package/dist/{index-asrxgdt4.js → index-rrwv9y2k.js} +8 -0
  26. package/dist/{index-mx59cve4.js → index-svgkv4g2.js} +1 -1
  27. package/dist/{index-qqxqwqhp.js → index-vktahpdj.js} +1 -1
  28. package/dist/{index-n3r2d2pr.js → index-vmcgew7x.js} +10 -7
  29. package/dist/{index-afy3dzf9.js → index-xnch62s6.js} +12 -6
  30. package/dist/{index-4178cbfw.js → index-xxn1tpnv.js} +124 -2039
  31. package/dist/{index-s1xn8qfw.js → index-yygsh681.js} +6 -3
  32. package/dist/{index-p3evwech.js → index-z2rkv0mb.js} +3 -3
  33. package/dist/index.js +1109 -355
  34. package/dist/{message-fts-rowid-map-mbanfkt1.js → message-fts-rowid-map-cvpy2dmb.js} +5 -3
  35. package/dist/{message-index-easvmz22.js → message-index-74qdqmq7.js} +11 -11
  36. package/dist/{message-index-bounded-xzerjxmp.js → message-index-bounded-g9hgresf.js} +15 -15
  37. package/dist/{message-time-backfill-3q4kemfc.js → message-time-backfill-ssshbdy8.js} +1 -1
  38. package/dist/migration-worker.js +7 -7
  39. package/dist/{project-embedding-registry-xwnmqmx8.js → project-embedding-registry-vf1ncptn.js} +10 -10
  40. package/dist/raw-ordinal-warmup-worker.js +10 -10
  41. package/dist/{read-session-chunk-1sb5n7zs.js → read-session-chunk-chepqmw5.js} +5 -5
  42. package/dist/{read-session-raw-jz5e9jz0.js → read-session-raw-9s3xn7fc.js} +2 -2
  43. package/dist/{search-x3fa0561.js → search-6ztbx25v.js} +17 -17
  44. package/dist/{search-archive-3ma5n0wr.js → search-archive-jg4a1kcx.js} +6 -6
  45. package/dist/{sqlite-adjpy399.js → sqlite-fsp0sf3r.js} +1 -1
  46. package/dist/{storage-memory-axnsk5t1.js → storage-memory-yxxc5v4n.js} +2 -2
  47. package/dist/{storage-tags-jtessrec.js → storage-tags-1kets0q8.js} +3 -3
  48. package/dist/subagent-entry.js +22 -21
  49. package/dist/tag-snapshot-worker-pi.js +9 -9
  50. package/package.json +6 -1
  51. package/dist/embedding-backfill-c4bdw8pp.js +0 -23
@@ -3,10 +3,10 @@ import {
3
3
  } from "./index-1cvyaw9a.js";
4
4
  import {
5
5
  estimateTokens
6
- } from "./index-g4jf772p.js";
6
+ } from "./index-1kcfwk9c.js";
7
7
  import {
8
8
  readRawSessionMessageIdOrdinalsForRange2
9
- } from "./index-44h64qza.js";
9
+ } from "./index-r9f4f6s1.js";
10
10
 
11
11
  // ../plugin/src/tools/ctx-expand/search-archive.ts
12
12
  var archiveReadsOnThisThread = 0;
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  inRootAsyncContext2,
6
6
  isTransientSqliteError2
7
- } from "./index-asrxgdt4.js";
7
+ } from "./index-rrwv9y2k.js";
8
8
  import {
9
9
  PROMOTABLE_CATEGORIES,
10
10
  CATEGORY_DEFAULT_TTL
@@ -22,17 +22,17 @@ import {
22
22
  resolveStoredPathWorkspaceIdentity,
23
23
  sourceNameForMemory,
24
24
  managedAuthorityNoteRow
25
- } from "./index-tympym62.js";
25
+ } from "./index-gdjv1nnd.js";
26
26
  import {
27
27
  isKnownAutocommit
28
28
  } from "./index-jrap43gc.js";
29
29
  import {
30
30
  SubcClient
31
- } from "./index-6dz2ed1v.js";
31
+ } from "./index-d8gc0112.js";
32
32
  import {
33
33
  buildCanonicalChunkTextFromFts,
34
34
  loadCompartmentChunkEmbeddingsForSearch
35
- } from "./index-afy3dzf9.js";
35
+ } from "./index-xnch62s6.js";
36
36
  import {
37
37
  recordEmbeddingMeasurement,
38
38
  saveCommitEmbedding,
@@ -50,7 +50,7 @@ import {
50
50
  getProjectEmbeddingSnapshot2,
51
51
  embedTextForProject2,
52
52
  embedItemsForProject2
53
- } from "./index-n3r2d2pr.js";
53
+ } from "./index-vmcgew7x.js";
54
54
  import {
55
55
  saveEmbeddingIfHashMatches,
56
56
  getProjectEmbeddings2
@@ -60,7 +60,7 @@ import {
60
60
  isEmbeddingEnabled,
61
61
  embedText,
62
62
  ensureMemoryEmbeddings2
63
- } from "./index-p3evwech.js";
63
+ } from "./index-z2rkv0mb.js";
64
64
  import {
65
65
  getMemorySelectColumns2,
66
66
  isMemoryRow2,
@@ -74,14 +74,17 @@ import {
74
74
  getMemoryById2,
75
75
  updateMemorySeenCount2,
76
76
  updateMemoryRetrievalCount2
77
- } from "./index-hy44m6jc.js";
77
+ } from "./index-e1rza8gp.js";
78
+ import {
79
+ cleanSearchText,
80
+ keywordRelevance,
81
+ matchedSearchSnippet,
82
+ getIndexedMessageCorpusSize2
83
+ } from "./index-fvjthct0.js";
78
84
  import {
79
85
  MESSAGE_FTS_SESSION_FILTER_SQL,
80
86
  withMessageFtsSessionFilter
81
87
  } from "./index-1cvyaw9a.js";
82
- import {
83
- getIndexedMessageCorpusSize2
84
- } from "./index-fhyy4ave.js";
85
88
  import {
86
89
  computeNormalizedHash
87
90
  } from "./index-9x1f96r8.js";
@@ -1499,6 +1502,10 @@ async function indexCommitsForProject(db, projectPath, directory, options) {
1499
1502
  embedded: 0,
1500
1503
  nonIndexable: false
1501
1504
  };
1505
+ if (projectPath.startsWith("dir:")) {
1506
+ result.nonIndexable = true;
1507
+ return result;
1508
+ }
1502
1509
  if (indexInProgress.has(projectPath)) {
1503
1510
  log2(`[git-commits] index already in progress for ${projectPath}, skipping`);
1504
1511
  return result;
@@ -1552,6 +1559,7 @@ async function embedUnembeddedCommits(db, projectPath) {
1552
1559
  embedInProgress.add(projectPath);
1553
1560
  const startedAt = Date.now();
1554
1561
  const deadline = startedAt + EMBED_SWEEP_MAX_WALL_CLOCK_MS;
1562
+ const signal = AbortSignal.timeout(EMBED_SWEEP_MAX_WALL_CLOCK_MS);
1555
1563
  let total = 0;
1556
1564
  try {
1557
1565
  while (Date.now() < deadline && total < EMBED_MAX_PER_SWEEP) {
@@ -1564,7 +1572,7 @@ async function embedUnembeddedCommits(db, projectPath) {
1564
1572
  id: `commit:${row.sha}`,
1565
1573
  text: row.message,
1566
1574
  contentSha256: contentSha2562(row.message)
1567
- })), undefined, db, projectPath);
1575
+ })), signal, db, projectPath);
1568
1576
  if (!result)
1569
1577
  break;
1570
1578
  db.transaction(() => {
@@ -2922,7 +2930,7 @@ function searchMessagesInSnapshot(args, sessionFirst) {
2922
2930
  const filtered = rows.slice(0, limit);
2923
2931
  return filtered.map((row, rank) => ({
2924
2932
  source: "message",
2925
- content: previewText(row.content),
2933
+ content: matchedSearchSnippet(row.content, args.query) || previewText(row.content),
2926
2934
  score: linearDecayScore(rank, filtered.length),
2927
2935
  messageOrdinal: row.messageOrdinal,
2928
2936
  messageId: row.messageId,
@@ -2999,7 +3007,7 @@ function searchMessagesInSnapshot(args, sessionFirst) {
2999
3007
  const ranked = [...fused.values()].sort((a, b) => b.score !== a.score ? b.score - a.score : a.row.messageOrdinal - b.row.messageOrdinal).slice(0, resultLimit);
3000
3008
  return ranked.map((entry, rank) => ({
3001
3009
  source: "message",
3002
- content: previewText(entry.row.content),
3010
+ content: matchedSearchSnippet(entry.row.content, args.query) || previewText(entry.row.content),
3003
3011
  score: linearDecayScore(rank, ranked.length),
3004
3012
  messageOrdinal: entry.row.messageOrdinal,
3005
3013
  messageId: entry.row.messageId,
@@ -3222,10 +3230,7 @@ function mergeMessageAndCompartmentResults(args) {
3222
3230
  }
3223
3231
  }
3224
3232
  const ranked = [...fused.values()].sort((left, right) => right.score !== left.score ? right.score - left.score : left.tieOrdinal - right.tieOrdinal).slice(0, args.limit);
3225
- return ranked.map((entry, rank) => ({
3226
- ...entry.result,
3227
- score: linearDecayScore(rank, ranked.length)
3228
- }));
3233
+ return ranked.map((entry) => entry.result);
3229
3234
  }
3230
3235
  function getSourceBoost(result) {
3231
3236
  switch (result.source) {
@@ -3503,7 +3508,7 @@ async function unifiedSearch2(db, sessionId, projectPath, query, options = {}) {
3503
3508
  if (options.diagnostics) {
3504
3509
  options.diagnostics.suppressedLiveMessageMatches = outcome.suppressedLiveMessageMatches;
3505
3510
  }
3506
- messageResults = outcome.results;
3511
+ messageResults = outcome.results.filter((result) => result.messageId !== options.excludeMessageId);
3507
3512
  if (lanes)
3508
3513
  lanes.message_fts = (outcome.laneResults ?? outcome.results).slice(0, 25);
3509
3514
  }
@@ -3636,6 +3641,12 @@ async function unifiedSearch2(db, sessionId, projectPath, query, options = {}) {
3636
3641
  }).immediate();
3637
3642
  }
3638
3643
  }
3644
+ if (options.autoHint) {
3645
+ return results.map((result) => ({
3646
+ ...result,
3647
+ relevanceScore: cleanSearchText(result.source === "compartment" ? result.title : result.content).length === 0 ? 0 : result.source === "message" || ("matchType" in result) && result.source !== "compartment" && result.matchType !== "semantic" ? keywordRelevance(trimmedQuery, result.content) : result.score
3648
+ }));
3649
+ }
3639
3650
  return results;
3640
3651
  }
3641
3652
  var SEARCH_NOTE_EXPAND_HINT = "Use ctx_expand(start=N-10, end=N) around any note @msg anchor above to read the surrounding conversation context.";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  estimateTokens
3
- } from "./index-g4jf772p.js";
3
+ } from "./index-1kcfwk9c.js";
4
4
  import {
5
5
  getHarness2
6
6
  } from "./index-0h2mkab2.js";
@@ -9,7 +9,7 @@ import {
9
9
  } from "./index-7bqrfyny.js";
10
10
  import {
11
11
  inRootAsyncContext2
12
- } from "./index-asrxgdt4.js";
12
+ } from "./index-rrwv9y2k.js";
13
13
 
14
14
  // ../plugin/src/features/magic-context/memory/embedding-synapse.ts
15
15
  import { createHash } from "node:crypto";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  withPrivilegedWriter2
3
- } from "./index-asrxgdt4.js";
3
+ } from "./index-rrwv9y2k.js";
4
4
  import {
5
5
  MEMORY_CATEGORY_ORDER_SQL
6
6
  } from "./index-135e8hvg.js";
@@ -1,3 +1,7 @@
1
+ import {
2
+ parseTree
3
+ } from "./index-4knyh1kt.js";
4
+
1
5
  // ../plugin/src/agents/permissions.ts
2
6
  var DREAMER_PRIMER_INVESTIGATOR_ALLOWED_TOOLS = [
3
7
  "read",
@@ -9,6 +13,37 @@ var DREAMER_PRIMER_INVESTIGATOR_ALLOWED_TOOLS = [
9
13
  "ctx_search"
10
14
  ];
11
15
 
16
+ // ../plugin/src/shared/historian-cache.ts
17
+ function withoutHistorianTailCache(body) {
18
+ const value = JSON.parse(body);
19
+ if (!value || typeof value.model !== "string" || typeof value.max_tokens !== "number" || !Array.isArray(value.system) || value.system.length === 0 || !value.system.every((part) => part?.type === "text" && typeof part.text === "string") || !value.system.some((part) => part.cache_control) || !Array.isArray(value.messages) || value.cache_control !== undefined)
20
+ return body;
21
+ const root = parseTree(body);
22
+ const property = (node, key) => node?.children?.find((child) => child.children?.[0]?.value === key)?.children?.[1];
23
+ const removals = [];
24
+ for (const message of property(root, "messages")?.children ?? []) {
25
+ for (const block of property(message, "content")?.children ?? []) {
26
+ if (block.type !== "object")
27
+ continue;
28
+ const fields = block.children ?? [];
29
+ fields.forEach((field, index) => {
30
+ if (field.children?.[0]?.value !== "cache_control")
31
+ return;
32
+ const next = fields[index + 1];
33
+ const previous = fields[index - 1];
34
+ removals.push(next ? [field.offset, next.offset] : [
35
+ previous ? previous.offset + previous.length : field.offset,
36
+ field.offset + field.length
37
+ ]);
38
+ });
39
+ }
40
+ }
41
+ for (const [start, end] of removals.sort((a, b) => b[0] - a[0])) {
42
+ body = body.slice(0, start) + body.slice(end);
43
+ }
44
+ return body;
45
+ }
46
+
12
47
  // ../plugin/src/agents/hidden-agent-registrations.ts
13
48
  var HIDDEN_AGENT_DESCRIPTION = "Internal Magic Context maintenance agent. Not for general tasks — do not select for user work.";
14
49
  function buildHiddenAgentRegistrations(args) {
@@ -371,6 +406,7 @@ class SubagentTelemetry {
371
406
 
372
407
  // src/historian-calibration-extension.ts
373
408
  var HISTORIAN_TEMPERATURE_ENV2 = "MAGIC_CONTEXT_HISTORIAN_TEMPERATURE";
409
+ var HISTORIAN_CACHE_TAIL_ENV2 = "MAGIC_CONTEXT_HISTORIAN_CACHE_TAIL";
374
410
  var HISTORIAN_MAX_OUTPUT_TOKENS_ENV2 = "MAGIC_CONTEXT_HISTORIAN_MAX_OUTPUT_TOKENS";
375
411
  var SUBAGENT_OUTPUT_CEILING_ENV2 = "MAGIC_CONTEXT_SUBAGENT_OUTPUT_CEILING";
376
412
  function finiteNumber(value) {
@@ -481,6 +517,28 @@ function withoutProviderTemperature2(payload) {
481
517
  return clean;
482
518
  }
483
519
  function historianCalibrationExtension(pi) {
520
+ if (process.env[HISTORIAN_CACHE_TAIL_ENV2] === "skip") {
521
+ let requests = 0;
522
+ let warned = false;
523
+ pi.on("before_provider_request", (event) => {
524
+ if (requests++ > 0)
525
+ return;
526
+ try {
527
+ const original = JSON.stringify(event.payload);
528
+ const body = withoutHistorianTailCache(original);
529
+ return body === original ? undefined : JSON.parse(body);
530
+ } catch (error) {
531
+ if (!warned) {
532
+ warned = true;
533
+ try {
534
+ process.stderr.write(`Historian cache optimization skipped: ${String(error)}
535
+ `);
536
+ } catch {}
537
+ }
538
+ return;
539
+ }
540
+ });
541
+ }
484
542
  const intendedPath = process.env.MAGIC_CONTEXT_SUBAGENT_PROMPT_FILE;
485
543
  if (intendedPath) {
486
544
  const intended = readFileSync2(intendedPath, "utf8");
@@ -519,4 +577,4 @@ function historianCalibrationExtension(pi) {
519
577
  });
520
578
  }
521
579
 
522
- export { DREAMER_PRIMER_INVESTIGATOR_ALLOWED_TOOLS, buildHiddenAgentRegistrations, logTemperatureDecision, readHostSystemPrompt, subagentStepCap, SubagentTelemetry, HISTORIAN_TEMPERATURE_ENV2, HISTORIAN_MAX_OUTPUT_TOKENS_ENV2, SUBAGENT_OUTPUT_CEILING_ENV2, calibrateHistorianProviderPayload2, ceilProviderOutputTokens2, withoutProviderTemperature2, historianCalibrationExtension };
580
+ export { DREAMER_PRIMER_INVESTIGATOR_ALLOWED_TOOLS, buildHiddenAgentRegistrations, logTemperatureDecision, readHostSystemPrompt, subagentStepCap, SubagentTelemetry, HISTORIAN_TEMPERATURE_ENV2, HISTORIAN_CACHE_TAIL_ENV2, HISTORIAN_MAX_OUTPUT_TOKENS_ENV2, SUBAGENT_OUTPUT_CEILING_ENV2, calibrateHistorianProviderPayload2, ceilProviderOutputTokens2, withoutProviderTemperature2, historianCalibrationExtension };