@cortexkit/pi-magic-context 0.49.60 → 0.49.62

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 (2) hide show
  1. package/dist/index.js +46 -13
  2. package/package.json +2 -1
package/dist/index.js CHANGED
@@ -3601,7 +3601,7 @@ function startHostStallProfilerSwitch() {
3601
3601
  // package.json
3602
3602
  var package_default = {
3603
3603
  name: "@cortexkit/pi-magic-context",
3604
- version: "0.49.60",
3604
+ version: "0.49.62",
3605
3605
  type: "module",
3606
3606
  description: "Pi and OMP coding agent extension for Magic Context — cross-session memory and context management",
3607
3607
  main: "dist/index.js",
@@ -3670,6 +3670,7 @@ var package_default = {
3670
3670
  "omp-coding-agent-18132": "npm:@oh-my-pi/pi-coding-agent@18.13.2",
3671
3671
  "omp-coding-agent-18186": "npm:@oh-my-pi/pi-coding-agent@18.18.6",
3672
3672
  "omp-coding-agent-18190": "npm:@oh-my-pi/pi-coding-agent@18.19.0",
3673
+ "omp-coding-agent-18220": "npm:@oh-my-pi/pi-coding-agent@18.22.0",
3673
3674
  "omp-pi-ai-171": "npm:@oh-my-pi/pi-ai@17.1.7",
3674
3675
  "omp-pi-ai-1889": "npm:@oh-my-pi/pi-ai@18.8.9",
3675
3676
  "omp-pi-ai-1811": "npm:@oh-my-pi/pi-ai@18.11.3",
@@ -29133,10 +29134,13 @@ function safeJsonStringify(value) {
29133
29134
  function isRecord2(value) {
29134
29135
  return typeof value === "object" && value !== null;
29135
29136
  }
29137
+ function isUntaggedAssistantText(role, text, preserveTagOnlyAssistantText) {
29138
+ return role === "assistant" && (stripWellFormedLeadingTagPrefix(text).trim().length === 0 || preserveTagOnlyAssistantText === true && text.includes("§") && stripPersistedAssistantText(text).length === 0);
29139
+ }
29136
29140
  function tagTextPart(args) {
29137
29141
  const identityStart = args.timing ? performance.now() : 0;
29138
29142
  const text = args.part.getText() ?? "";
29139
- if (args.message.info.role === "assistant" && (stripWellFormedLeadingTagPrefix(text).trim().length === 0 || args.preserveTagOnlyAssistantText && text.includes("§") && stripPersistedAssistantText(text).length === 0)) {
29143
+ if (isUntaggedAssistantText(args.message.info.role, text, args.preserveTagOnlyAssistantText)) {
29140
29144
  if (args.timing)
29141
29145
  args.timing.identity += performance.now() - identityStart;
29142
29146
  return;
@@ -37426,10 +37430,20 @@ function isOmpSideContext(event) {
37426
37430
  return row.role === "developer" && row.attribution === "agent" && textContainsReminder(row.content);
37427
37431
  });
37428
37432
  }
37429
- var ADVISOR_PREFIX = "<conventions>\nRFC 2119 keywords: MUST, REQUIRED, SHOULD, RECOMMENDED, MAY, OPTIONAL. `NEVER`=`MUST NOT`; `AVOID`=`SHOULD NOT`.\n</conventions>\n\nUser, code-quality, robustness advocate; peer-shadow main agent.\n";
37433
+ var ADVISOR_CONVENTIONS = "<conventions>\nRFC 2119 keywords: MUST, REQUIRED, SHOULD, RECOMMENDED, MAY, OPTIONAL. `NEVER`=`MUST NOT`; `AVOID`=`SHOULD NOT`.\n</conventions>\n\n";
37434
+ var ADVISOR_ROLE = `User, code-quality, robustness advocate; peer-shadow main agent.
37435
+ `;
37430
37436
  var ADVISOR_WORKFLOW = `<workflow>
37431
37437
  Receive incremental agent transcript, including thoughts.
37432
37438
  `;
37439
+ var SESSION_UPDATE = `### Session update
37440
+
37441
+ `;
37442
+ var COMPACTION_SUMMARY = `Prior model work/tool state available.
37443
+ MUST build on prior work; NEVER duplicate prior work.
37444
+
37445
+ <summary>
37446
+ `;
37433
37447
  var CAPTURE_PREFIX = "Automated capture turn — not a user reply; user has not responded to your previous turn.";
37434
37448
  function record3(value) {
37435
37449
  return value && typeof value === "object" && !Array.isArray(value) ? value : undefined;
@@ -37509,11 +37523,17 @@ function firstTextBlock(value) {
37509
37523
  const part = record3(value);
37510
37524
  return part?.type === "text" && typeof part.text === "string" ? part.text : undefined;
37511
37525
  }
37526
+ function isOmpStockAdvisorPrompt(text) {
37527
+ if (typeof text !== "string")
37528
+ return false;
37529
+ const body = text.startsWith(ADVISOR_CONVENTIONS) ? text.slice(ADVISOR_CONVENTIONS.length) : text;
37530
+ return body.startsWith(ADVISOR_ROLE) && body.includes(ADVISOR_WORKFLOW);
37531
+ }
37512
37532
  function isOmpAdvisorRequest(payload) {
37513
37533
  const request = providerRequest(payload);
37514
37534
  if (!request?.tools.includes("advise"))
37515
37535
  return false;
37516
- if (!request.system.some((text) => text?.startsWith(ADVISOR_PREFIX) && text.includes(ADVISOR_WORKFLOW)))
37536
+ if (!request.system.some(isOmpStockAdvisorPrompt))
37517
37537
  return false;
37518
37538
  const first = record3(request.messages[0]);
37519
37539
  if (first?.role !== "user")
@@ -37521,9 +37541,7 @@ function isOmpAdvisorRequest(payload) {
37521
37541
  let text = firstText(first.content, request.textType)?.replace(/^<system-reminder>\nToday: [^\n]+\n<\/system-reminder>(?:\n|$)/, "");
37522
37542
  if (text === "" && Array.isArray(first.content))
37523
37543
  text = firstText(first.content.slice(1, 2), request.textType);
37524
- return text?.startsWith(`### Session update
37525
-
37526
- `) === true;
37544
+ return text?.startsWith(SESSION_UPDATE) === true || text?.startsWith(COMPACTION_SUMMARY) === true;
37527
37545
  }
37528
37546
  function isOmpUnmanagedCaptureRequest(payload) {
37529
37547
  return isOmpLegacyCaptureRequest(payload) || isOmpAutolearnCapture(payload);
@@ -48064,13 +48082,27 @@ var piTagTextTokenCacheBySession = new Map;
48064
48082
  var piTagToolTokenCacheBySession = new Map;
48065
48083
  var piTextIdentitySourceCacheBySession = new Map;
48066
48084
  var piFallbackIndexesBySession = new Map;
48085
+ var PI_PRESERVE_TAG_ONLY_ASSISTANT_TEXT = true;
48067
48086
  function buildPiTextIdentityPlan(db, sessionId, tagger, transcript, reuseCandidates = new Set) {
48068
48087
  const currentSourcesByMessageId = new Map;
48088
+ const untaggedOrdinalsByMessageId = new Map;
48069
48089
  for (const message of transcript.messages) {
48070
48090
  const messageId = message.info.id;
48071
48091
  if (messageId === undefined)
48072
48092
  continue;
48073
- currentSourcesByMessageId.set(messageId, message.parts.filter((part) => part.kind === "text").map((part) => withoutPiLeadingTemporalMarker(stripTagPrefix(part.getText() ?? ""))));
48093
+ const sources = [];
48094
+ const untagged = new Set;
48095
+ for (const part of message.parts) {
48096
+ if (part.kind !== "text")
48097
+ continue;
48098
+ const text = part.getText() ?? "";
48099
+ if (isUntaggedAssistantText(message.info.role, text, PI_PRESERVE_TAG_ONLY_ASSISTANT_TEXT))
48100
+ untagged.add(sources.length);
48101
+ sources.push(withoutPiLeadingTemporalMarker(stripTagPrefix(text)));
48102
+ }
48103
+ currentSourcesByMessageId.set(messageId, sources);
48104
+ if (untagged.size > 0)
48105
+ untaggedOrdinalsByMessageId.set(messageId, untagged);
48074
48106
  }
48075
48107
  const legacyRowsByMessageId = new Map;
48076
48108
  const versionedMessageIds = new Set;
@@ -48118,11 +48150,12 @@ function buildPiTextIdentityPlan(db, sessionId, tagger, transcript, reuseCandida
48118
48150
  if (legacyRows.length === 0)
48119
48151
  continue;
48120
48152
  legacyRows.sort((left, right) => left.ordinal - right.ordinal);
48121
- const vectorMatches = legacyRows.length === currentSources.length && legacyRows.every((row, index) => {
48122
- if (row.ordinal !== index)
48123
- return false;
48153
+ const untagged = untaggedOrdinalsByMessageId.get(messageId);
48154
+ const rowOrdinals = new Set(legacyRows.map((row) => row.ordinal));
48155
+ const vectorAligned = rowOrdinals.size === legacyRows.length && legacyRows.every((row) => row.ordinal < currentSources.length) && currentSources.every((_, ordinal) => rowOrdinals.has(ordinal) || untagged?.has(ordinal) === true);
48156
+ const vectorMatches = vectorAligned && legacyRows.every((row) => {
48124
48157
  const stored = withoutPiLeadingTemporalMarker(sourceCache.get(row.tagId) ?? "");
48125
- const current = currentSources[index] ?? "";
48158
+ const current = currentSources[row.ordinal] ?? "";
48126
48159
  if (stored === current)
48127
48160
  return true;
48128
48161
  const strippedCurrent = stripSystemInjection(current);
@@ -52663,7 +52696,7 @@ async function runPipeline(args) {
52663
52696
  args.assertCurrentPass?.();
52664
52697
  return tagTranscript(args.sessionId, { ...transcript, messages: taggingView }, args.tagger, args.db, {
52665
52698
  skipPrefixInjection: !ctxReduceCallable,
52666
- preserveTagOnlyAssistantText: true,
52699
+ preserveTagOnlyAssistantText: PI_PRESERVE_TAG_ONLY_ASSISTANT_TEXT,
52667
52700
  entryFingerprintByMessageId,
52668
52701
  reuseMessageIds: textIdentityPlan.reusableMessageIds,
52669
52702
  reuseTextMessageIds: textIdentityPlan.reusableTextMessageIds,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cortexkit/pi-magic-context",
3
- "version": "0.49.60",
3
+ "version": "0.49.62",
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",
@@ -69,6 +69,7 @@
69
69
  "omp-coding-agent-18132": "npm:@oh-my-pi/pi-coding-agent@18.13.2",
70
70
  "omp-coding-agent-18186": "npm:@oh-my-pi/pi-coding-agent@18.18.6",
71
71
  "omp-coding-agent-18190": "npm:@oh-my-pi/pi-coding-agent@18.19.0",
72
+ "omp-coding-agent-18220": "npm:@oh-my-pi/pi-coding-agent@18.22.0",
72
73
  "omp-pi-ai-171": "npm:@oh-my-pi/pi-ai@17.1.7",
73
74
  "omp-pi-ai-1889": "npm:@oh-my-pi/pi-ai@18.8.9",
74
75
  "omp-pi-ai-1811": "npm:@oh-my-pi/pi-ai@18.11.3",