@cortexkit/magic-context 0.49.22 → 0.49.24

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 +79 -3
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -34245,6 +34245,73 @@ var init_historian_tool_expansions = __esm(() => {
34245
34245
  init_historian_tool_template();
34246
34246
  });
34247
34247
 
34248
+ // ../plugin/src/hooks/magic-context/ask-answer-notice.ts
34249
+ function reminderBodies(text) {
34250
+ reminderEnvelopePattern.lastIndex = 0;
34251
+ const bodies = [];
34252
+ for (const match of text.matchAll(reminderEnvelopePattern)) {
34253
+ const body = match[1];
34254
+ if (body !== undefined)
34255
+ bodies.push(body);
34256
+ }
34257
+ return bodies;
34258
+ }
34259
+ function parseAnswerBody(body) {
34260
+ const lines = body.replace(/\r\n/g, `
34261
+ `).replace(/^\n+|\n+$/g, "");
34262
+ if (!ANSWER_HEADER_PREFIX.test(lines))
34263
+ return null;
34264
+ if (lines.includes("The user dismissed this question"))
34265
+ return null;
34266
+ const framed = ANSWER_TRAILER.exec(lines);
34267
+ if (framed === null)
34268
+ return null;
34269
+ const content = framed[1] ?? "";
34270
+ const narrated = ANSWER_ANSWER_LINE.exec(content);
34271
+ if (narrated !== null) {
34272
+ const question = narrated[2] ?? "";
34273
+ const answer = content.slice(narrated[0].length);
34274
+ return closedAnswer(question, answer);
34275
+ }
34276
+ const bare = ANSWER_QUESTION_LINE.exec(content);
34277
+ if (bare !== null) {
34278
+ const question = bare[1] ?? "";
34279
+ const answer = content.slice(bare[0].length);
34280
+ return closedAnswer(question, answer);
34281
+ }
34282
+ return null;
34283
+ }
34284
+ function closedAnswer(question, answer) {
34285
+ if (question.trim().length === 0)
34286
+ return null;
34287
+ if (answer.trim().length === 0)
34288
+ return null;
34289
+ return { question, answer };
34290
+ }
34291
+ function extractAskAnswerNotices(text) {
34292
+ const notices = [];
34293
+ for (const body of reminderBodies(text)) {
34294
+ const notice = parseAnswerBody(body);
34295
+ if (notice !== null)
34296
+ notices.push(notice);
34297
+ }
34298
+ return notices;
34299
+ }
34300
+ function formatAskAnswerNotice(notice) {
34301
+ return `U (answered "${notice.question}"): ${notice.answer}`;
34302
+ }
34303
+ function askAnswerLines(text) {
34304
+ return extractAskAnswerNotices(text).map(formatAskAnswerNotice);
34305
+ }
34306
+ var ANSWER_HEADER_PREFIX, ANSWER_TRAILER, ANSWER_ANSWER_LINE, ANSWER_QUESTION_LINE, reminderEnvelopePattern;
34307
+ var init_ask_answer_notice = __esm(() => {
34308
+ ANSWER_HEADER_PREFIX = /^Inbox [^\n]* notice from user via user_answer \(user_answer\)/;
34309
+ ANSWER_TRAILER = /\n([\s\S]*?)\nThis ask is now closed; no dismiss is needed\. Continue accordingly\.$/;
34310
+ ANSWER_ANSWER_LINE = /^The user answered your parked question (\S+)\.\nQuestion: ([^\n]+)\nAnswer: /;
34311
+ ANSWER_QUESTION_LINE = /^Question: ([^\n]+)\nAnswer: /;
34312
+ reminderEnvelopePattern = /<system-reminder>([\s\S]*?)<\/system-reminder>/gi;
34313
+ });
34314
+
34248
34315
  // ../plugin/src/hooks/magic-context/host-served-rows.ts
34249
34316
  function markHostUnservedRow(target) {
34250
34317
  Object.defineProperty(target, HOST_UNSERVED_ROW, {
@@ -34939,6 +35006,9 @@ function withRawMessageProvider(sessionId, provider, fn) {
34939
35006
  function cleanUserText(text) {
34940
35007
  return stripOutsideSteeringWrappers(text, (segment) => removeSystemReminders(segment).replace(OMO_INTERNAL_INITIATOR_MARKER, "")).trim();
34941
35008
  }
35009
+ function answerLineParts(rawText) {
35010
+ return askAnswerLines(rawText).map(normalizeText).filter((value) => value.length > 0);
35011
+ }
34942
35012
  function hasMeaningfulChunkUserText(parts) {
34943
35013
  for (const part of parts) {
34944
35014
  if (part === null || typeof part !== "object")
@@ -34955,7 +35025,7 @@ function hasMeaningfulChunkUserText(parts) {
34955
35025
  continue;
34956
35026
  return true;
34957
35027
  }
34958
- return false;
35028
+ return parts.some((part) => part !== null && typeof part === "object" && part.type === "text" && typeof part.text === "string" && part.ignored !== true && askAnswerLines(part.text).length > 0);
34959
35029
  }
34960
35030
  function withRawSessionMessageCache(fn) {
34961
35031
  const outerCache = activeRawMessageCache;
@@ -35701,8 +35771,10 @@ function readSessionChunk(sessionId, tokenBudget, offset = 1, eligibleEndOrdinal
35701
35771
  }
35702
35772
  const role = compactRole(msg.role);
35703
35773
  const textParts = extractTexts(msg.parts).map((t) => msg.role === "user" ? cleanUserText(t) : t).map(normalizeText).filter((value) => value.length > 0);
35774
+ const answerParts = msg.role === "user" ? extractTexts(msg.parts).flatMap((text) => answerLineParts(text)) : [];
35775
+ const userParts = answerParts.length > 0 ? [...textParts, ...answerParts] : textParts;
35704
35776
  const allParts = options.expand === false ? [
35705
- ...textParts,
35777
+ ...userParts,
35706
35778
  ...textParts.length === 0 ? extractToolCallSummaries(msg.parts) : []
35707
35779
  ] : msg.parts.flatMap((part) => {
35708
35780
  if (expandedResults.has(part))
@@ -35711,6 +35783,9 @@ function readSessionChunk(sessionId, tokenBudget, offset = 1, eligibleEndOrdinal
35711
35783
  if (expansion !== null)
35712
35784
  return [`TC: ${expansion}`];
35713
35785
  const texts = extractTexts([part]).map((t) => msg.role === "user" ? cleanUserText(t) : t).map(normalizeText).filter(Boolean);
35786
+ if (msg.role === "user") {
35787
+ texts.push(...extractTexts([part]).flatMap((text) => answerLineParts(text)));
35788
+ }
35714
35789
  return texts.length ? texts : textParts.length === 0 ? extractToolCallSummaries([part]) : [];
35715
35790
  });
35716
35791
  const compacted = compactTextForSummary(allParts.join(" / "), msg.role);
@@ -35719,7 +35794,7 @@ function readSessionChunk(sessionId, tokenBudget, offset = 1, eligibleEndOrdinal
35719
35794
  recordFilteredNoise(meta);
35720
35795
  continue;
35721
35796
  }
35722
- const msgHasNarrative = textParts.length > 0;
35797
+ const msgHasNarrative = userParts.length > 0;
35723
35798
  if (currentBlock && currentBlock.role === role) {
35724
35799
  currentBlock.endOrdinal = msg.ordinal;
35725
35800
  currentBlock.parts.push(text);
@@ -35824,6 +35899,7 @@ var BLOCK_TOKEN_MEMO_MAX = 2048, blockTokenMemo, activeRawMessageCache = null, a
35824
35899
  var init_read_session_chunk = __esm(async () => {
35825
35900
  init_historian_tool_expansions();
35826
35901
  init_logger();
35902
+ init_ask_answer_notice();
35827
35903
  init_read_session_formatting();
35828
35904
  init_read_session_true_raw_tokens();
35829
35905
  init_system_injection_stripper();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cortexkit/magic-context",
3
- "version": "0.49.22",
3
+ "version": "0.49.24",
4
4
  "description": "Unified CLI for Magic Context — setup, doctor, and migration across OpenCode, Pi, and OMP",
5
5
  "keywords": [
6
6
  "opencode",