stratagate-dsh 0.3.41 → 0.3.43

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.
package/dist/plugin.js CHANGED
@@ -431,6 +431,28 @@ function formatRawTranscript(messages) {
431
431
  ...(message.toolCalls ?? []).map(renderRawToolTrace)
432
432
  ]).join("\n\n");
433
433
  }
434
+ var ATTACHMENT_REFERENCE_PREFIX = "[StrataGate attachment] ";
435
+ function attachmentReferenceLines(value) {
436
+ return value.split(/\r?\n/u).filter((line) => line.startsWith(ATTACHMENT_REFERENCE_PREFIX));
437
+ }
438
+ function attachmentReferences(messages) {
439
+ const lines = [];
440
+ for (const message of messages) {
441
+ lines.push(...attachmentReferenceLines(message.content));
442
+ for (const trace of message.toolCalls ?? []) {
443
+ if (typeof trace.result === "string") lines.push(...attachmentReferenceLines(trace.result));
444
+ }
445
+ }
446
+ return [...new Set(lines)];
447
+ }
448
+ function preserveAttachmentReferences(content, messages) {
449
+ const missing2 = attachmentReferences(messages).filter((reference) => !content.includes(reference));
450
+ if (missing2.length === 0) return content;
451
+ return `${content}
452
+
453
+ Attachments retained in source:
454
+ ${missing2.join("\n")}`;
455
+ }
434
456
  function estimateTokens(value) {
435
457
  let tokens = 0;
436
458
  let asciiRun = 0;
@@ -6545,18 +6567,28 @@ function renderBlock(block, level) {
6545
6567
  if (block.processingStatus !== "ready" || !block.l0Title || !block.l0Tags || !block.l1Summary || !block.l2Keypoints) {
6546
6568
  throw new Error(`Block ${block.id} is not ready for rendering`);
6547
6569
  }
6548
- if (level === 0) return `${block.l0Title}
6570
+ let body;
6571
+ if (level === 0) body = `${block.l0Title}
6549
6572
  Tags: ${block.l0Tags.join(", ") || "none"}`;
6550
- if (level === 1) return block.l1Summary;
6551
- if (level === 2) return block.l2Keypoints.map((point) => `- ${point}`).join("\n") || block.l1Summary;
6552
- const deterministic = deterministicBlockLayers(block.l5Raw);
6553
- if (level === 3) return deterministic.l3Condensed;
6554
- if (level === 4) return deterministic.l4Readable;
6555
- return formatRawTranscript(block.l5Raw);
6573
+ else if (level === 1) body = block.l1Summary;
6574
+ else if (level === 2) body = block.l2Keypoints.map((point) => `- ${point}`).join("\n") || block.l1Summary;
6575
+ else {
6576
+ const deterministic = deterministicBlockLayers(block.l5Raw);
6577
+ body = level === 3 ? deterministic.l3Condensed : level === 4 ? deterministic.l4Readable : formatRawTranscript(block.l5Raw);
6578
+ }
6579
+ return preserveAttachmentReferences(body, block.l5Raw);
6556
6580
  }
6557
6581
  function sameIds(left, right) {
6558
6582
  return left.length === right.length && left.every((id, index) => id === right[index]);
6559
6583
  }
6584
+ function userTurnHasAssistant(messages, userIndex) {
6585
+ for (let index = userIndex + 1; index < messages.length; index += 1) {
6586
+ const role = messages[index].role;
6587
+ if (role === "user") return false;
6588
+ if (role === "assistant") return true;
6589
+ }
6590
+ return false;
6591
+ }
6560
6592
  function errorMessage(error) {
6561
6593
  if (error && typeof error === "object" && "fullMessage" in error) {
6562
6594
  const fullMessage = error.fullMessage;
@@ -7281,8 +7313,16 @@ var StrataGate = class _StrataGate {
7281
7313
  throw new TypeError("Turn threadId must not be empty");
7282
7314
  }
7283
7315
  const createdAt = toUtc8Iso(input.createdAt ?? this.now());
7284
- const userMessage = {
7285
- id: this.idFactory("msg"),
7316
+ const requestedUserMessageId = input.userMessageId?.trim();
7317
+ if (input.userMessageId !== void 0 && !requestedUserMessageId) {
7318
+ throw new TypeError("Turn userMessageId must not be empty");
7319
+ }
7320
+ const existingUserMessage = requestedUserMessageId ? this.openTail.find((message) => message.id === requestedUserMessageId && message.role === "user") : void 0;
7321
+ if (existingUserMessage && (existingUserMessage.content !== input.user || existingUserMessage.threadId !== threadId)) {
7322
+ throw new Error(`Reserved user message ${requestedUserMessageId} does not match the appended turn`);
7323
+ }
7324
+ const userMessage = existingUserMessage ?? {
7325
+ id: requestedUserMessageId ?? this.idFactory("msg"),
7286
7326
  role: "user",
7287
7327
  content: input.user,
7288
7328
  createdAt,
@@ -7297,30 +7337,42 @@ var StrataGate = class _StrataGate {
7297
7337
  ...threadId ? { threadId } : {},
7298
7338
  ...input.assistantToolCalls ? { toolCalls: structuredClone(input.assistantToolCalls) } : {}
7299
7339
  };
7340
+ const messagesToAppend = existingUserMessage ? [assistantMessage] : [userMessage, assistantMessage];
7341
+ const placeTurnMessages = (tail, capture) => {
7342
+ const assistant = capture ? captureRawMessage(assistantMessage) : assistantMessage;
7343
+ if (!existingUserMessage) {
7344
+ tail.push(capture ? captureRawMessage(userMessage) : userMessage, assistant);
7345
+ return;
7346
+ }
7347
+ const index = tail.findIndex((message) => message.id === existingUserMessage.id);
7348
+ if (index < 0) tail.push(assistant);
7349
+ else tail.splice(index + 1, 0, assistant);
7350
+ };
7300
7351
  const appendInMemory = () => {
7301
7352
  if (receiptId && this.ingestionReceipts.has(receiptId)) return false;
7302
7353
  this.currentTurn += 1;
7303
- this.openTail.push(userMessage, assistantMessage);
7354
+ placeTurnMessages(this.openTail, false);
7304
7355
  if (receiptId) this.ingestionReceipts.set(receiptId, { id: receiptId, createdAt });
7305
7356
  return true;
7306
7357
  };
7307
7358
  const appended = this.storage?.commitRecords ? await this.withMutationQueue(async () => {
7308
- if (this.hasPendingRecordChanges()) return this.applyMutation(appendInMemory);
7359
+ const reservedIsLast = !existingUserMessage || this.openTail.at(-1)?.id === existingUserMessage.id;
7360
+ if (this.hasPendingRecordChanges() || !reservedIsLast) return this.applyMutation(appendInMemory);
7309
7361
  if (receiptId && this.ingestionReceipts.has(receiptId)) return false;
7310
7362
  const receipt = receiptId ? { id: receiptId, createdAt } : void 0;
7311
7363
  const committed = await this.storage.commitRecords(this.namespace, this.revision, {
7312
7364
  kind: "append",
7313
- messages: [userMessage, assistantMessage],
7365
+ messages: messagesToAppend,
7314
7366
  updatedAt: createdAt,
7315
7367
  ...receipt ? { receipt } : {}
7316
7368
  });
7317
7369
  if (committed.changed) {
7318
7370
  this.currentTurn += 1;
7319
- this.openTail.push(userMessage, assistantMessage);
7371
+ placeTurnMessages(this.openTail, false);
7320
7372
  if (receipt) this.ingestionReceipts.set(receipt.id, receipt);
7321
7373
  const baseline = this.committedMetadata;
7322
7374
  baseline.currentTurn = this.currentTurn;
7323
- baseline.openTail.push(captureRawMessage(userMessage), captureRawMessage(assistantMessage));
7375
+ placeTurnMessages(baseline.openTail, true);
7324
7376
  if (receipt) baseline.ingestionReceipts.push(structuredClone(receipt));
7325
7377
  }
7326
7378
  this.revision = committed.revision;
@@ -7330,7 +7382,7 @@ var StrataGate = class _StrataGate {
7330
7382
  if (options.deferProcessing === true) {
7331
7383
  return { sealedBlock: null, readyBlocks: [], extractedEvents: [], projectedElements: [] };
7332
7384
  }
7333
- if (this.threadOpenTail(threadId).filter((message) => message.role === "user").length < this.blockTurnSize) {
7385
+ if (this.completeOpenUserCount(threadId) < this.blockTurnSize) {
7334
7386
  const projectedElements2 = await this.projectEligibleElements() ?? [];
7335
7387
  await this.projectEligibleGraph();
7336
7388
  return { sealedBlock: null, readyBlocks: [], extractedEvents: [], projectedElements: projectedElements2 };
@@ -7346,6 +7398,33 @@ var StrataGate = class _StrataGate {
7346
7398
  await this.projectEligibleGraph();
7347
7399
  return { sealedBlock, readyBlocks, extractedEvents, projectedElements };
7348
7400
  }
7401
+ /**
7402
+ * Persist the current user message before a tool call needs to cite it.
7403
+ * The message stays in the open tail but does not count as a sealable turn
7404
+ * until appendTurn stores its assistant reply immediately after it.
7405
+ * That call reuses this message by userMessageId and counts the turn once.
7406
+ */
7407
+ async reserveUserMessage(input) {
7408
+ const id = input.id.trim();
7409
+ if (!id) throw new TypeError("Reserved user message id must not be empty");
7410
+ const content = input.content;
7411
+ if (!content.trim()) throw new TypeError("Reserved user message content must not be empty");
7412
+ const threadId = input.threadId?.trim();
7413
+ if (input.threadId !== void 0 && !threadId) throw new TypeError("Reserved user message threadId must not be empty");
7414
+ const createdAt = toUtc8Iso(input.createdAt ?? this.now());
7415
+ return this.commitMutation(() => {
7416
+ const existing = this.openTail.find((message2) => message2.id === id);
7417
+ if (existing) {
7418
+ if (existing.role !== "user" || existing.content !== content || existing.threadId !== threadId) {
7419
+ throw new Error(`Reserved user message ${id} already exists with different content`);
7420
+ }
7421
+ return existing;
7422
+ }
7423
+ const message = { id, role: "user", content, createdAt, ...threadId ? { threadId } : {} };
7424
+ this.openTail.push(message);
7425
+ return message;
7426
+ });
7427
+ }
7349
7428
  async resumePendingWork(options = {}) {
7350
7429
  const sealedBlocks = [];
7351
7430
  const readyBlocks = [];
@@ -8863,7 +8942,15 @@ ${duplicate.summary}` : duplicate.summary;
8863
8942
  resolveAgentEventProvenance(candidate, threadId, now) {
8864
8943
  const real = threadId ? this.listOpenTail(threadId).filter((message) => message.role === "user" || message.role === "assistant") : [];
8865
8944
  if (real.length > 0) {
8866
- return { messageIds: real.slice(-AGENT_EVENT_PROVENANCE_LIMIT).map(({ id }) => id), synthetic: false };
8945
+ let latestUser = -1;
8946
+ for (let index = real.length - 1; index >= 0; index -= 1) {
8947
+ if (real[index].role === "user") {
8948
+ latestUser = index;
8949
+ break;
8950
+ }
8951
+ }
8952
+ const currentTurn = latestUser >= 0 ? real.slice(latestUser) : real;
8953
+ return { messageIds: currentTurn.slice(-AGENT_EVENT_PROVENANCE_LIMIT).map(({ id }) => id), synthetic: false };
8867
8954
  }
8868
8955
  const sealed = threadId ? this.blocks.filter((block) => block.threadId === threadId && block.l5Raw.length > 0) : [];
8869
8956
  const last = sealed.at(-1);
@@ -9339,6 +9426,15 @@ ${duplicate.summary}` : duplicate.summary;
9339
9426
  threadOpenTail(threadId) {
9340
9427
  return this.openTail.filter((message) => message.threadId === threadId);
9341
9428
  }
9429
+ /** User messages that already have their assistant reply in this thread. */
9430
+ completeOpenUserCount(threadId) {
9431
+ const messages = this.threadOpenTail(threadId);
9432
+ let count = 0;
9433
+ for (let index = 0; index < messages.length; index += 1) {
9434
+ if (messages[index].role === "user" && userTurnHasAssistant(messages, index)) count += 1;
9435
+ }
9436
+ return count;
9437
+ }
9342
9438
  threadBlocks(threadId) {
9343
9439
  return this.blocks.filter((block) => block.threadId === threadId);
9344
9440
  }
@@ -9351,16 +9447,11 @@ ${duplicate.summary}` : duplicate.summary;
9351
9447
  return this.nextSealableThread() !== null;
9352
9448
  }
9353
9449
  nextSealableThread() {
9354
- const counts = [];
9450
+ const seen = /* @__PURE__ */ new Set();
9355
9451
  for (const message of this.openTail) {
9356
- if (message.role !== "user") continue;
9357
- let entry = counts.find((candidate) => candidate.threadId === message.threadId);
9358
- if (!entry) {
9359
- entry = { threadId: message.threadId, users: 0 };
9360
- counts.push(entry);
9361
- }
9362
- entry.users += 1;
9363
- if (entry.users >= this.blockTurnSize) return { threadId: entry.threadId };
9452
+ if (seen.has(message.threadId)) continue;
9453
+ seen.add(message.threadId);
9454
+ if (this.completeOpenUserCount(message.threadId) >= this.blockTurnSize) return { threadId: message.threadId };
9364
9455
  }
9365
9456
  return null;
9366
9457
  }
@@ -9371,9 +9462,10 @@ ${duplicate.summary}` : duplicate.summary;
9371
9462
  pendingBlockMessages(threadId) {
9372
9463
  const messages = this.threadOpenTail(threadId);
9373
9464
  let users = 0;
9374
- let end = messages.length;
9465
+ let end = 0;
9375
9466
  for (const [index, message] of messages.entries()) {
9376
9467
  if (message.role !== "user") continue;
9468
+ if (!userTurnHasAssistant(messages, index)) break;
9377
9469
  users += 1;
9378
9470
  if (users !== this.blockTurnSize) continue;
9379
9471
  const nextUserOffset = messages.slice(index + 1).findIndex((candidate) => candidate.role === "user");
@@ -10529,6 +10621,7 @@ var STRATAGATE_MESSAGE_SOURCE_KIND = "plugin:stratagate-memory";
10529
10621
  var DSH_RUNTIME_RANGE = "0.1.2-rc.1 || >=0.1.5-rc.2 <0.3.0-0";
10530
10622
  var MODERN_API_RANGE = ">=0.1.7-rc.1";
10531
10623
  var SESSION_FORMAT_RUNTIME_RANGE = ">=0.2.0-0";
10624
+ var DSH_022_VENDOR_RUNTIME_RANGE = ">=0.2.2-0 <0.3.0-0";
10532
10625
  var SEMVER_OPTIONS = { includePrerelease: true };
10533
10626
  function assertDshMethods(scope, value, methods) {
10534
10627
  const target = value;
@@ -10579,13 +10672,14 @@ function classifyDshRuntime(packageVersions) {
10579
10672
  const sameDshFamily = CORE_RUNTIME_PACKAGES.filter((name2) => name2.startsWith("@deepseek-ai/dsh-")).every((name2) => packageVersions[name2] === dshVersion);
10580
10673
  const sameSessionFormatFamily = !satisfies(dshVersion, SESSION_FORMAT_RUNTIME_RANGE, SEMVER_OPTIONS) || SESSION_FORMAT_PACKAGES.every((name2) => packageVersions[name2] === dshVersion);
10581
10674
  const modernApi = satisfies(dshVersion, MODERN_API_RANGE, SEMVER_OPTIONS);
10582
- const compatibleVendors = modernApi ? isCompatiblePatch(packageVersions["@deepseek-ai/cordis"], 4, 0, 4) && isCompatiblePatch(packageVersions["@deepseek-ai/schemastery"], 3, 18, 4) : packageVersions["@deepseek-ai/cordis"] === "4.0.2" && packageVersions["@deepseek-ai/schemastery"] === "3.18.2";
10675
+ const dsh022VendorFamily = satisfies(dshVersion, DSH_022_VENDOR_RUNTIME_RANGE, SEMVER_OPTIONS);
10676
+ const compatibleVendors = modernApi ? dsh022VendorFamily ? isCompatiblePatch(packageVersions["@deepseek-ai/cordis"], 4, 1, 0) && isCompatiblePatch(packageVersions["@deepseek-ai/schemastery"], 3, 19, 0) : isCompatiblePatch(packageVersions["@deepseek-ai/cordis"], 4, 0, 4) && isCompatiblePatch(packageVersions["@deepseek-ai/schemastery"], 3, 18, 4) : packageVersions["@deepseek-ai/cordis"] === "4.0.2" && packageVersions["@deepseek-ai/schemastery"] === "3.18.2";
10583
10677
  if (satisfies(dshVersion, DSH_RUNTIME_RANGE, SEMVER_OPTIONS) && sameDshFamily && sameSessionFormatFamily && compatibleVendors) {
10584
10678
  return { cliVersion: dshVersion === "0.1.5-rc.2" ? "0.1.5-rc.1" : dshVersion, packageVersions };
10585
10679
  }
10586
10680
  const found = RUNTIME_PACKAGES.map((name2) => `${name2}@${packageVersions[name2]}`).join(", ");
10587
10681
  throw new Error(
10588
- `StrataGate cannot start because this DSH profile resolves an unsupported or mixed core runtime. Resolved: ${found}. Supported DSH versions: ${DSH_RUNTIME_RANGE} (including prereleases). Core DSH packages must share one version; DSH 0.2.0 and later also require matching Session Format packages. Modern hosts require Cordis 4.0.x from 4.0.4 and Schemastery 3.18.x from 3.18.4; older hosts use 4.0.2 and 3.18.2. Reinstall or update stratagate-dsh through \`dsh plugin --profile <name> add <package>\` so the host supplies its peers.`
10682
+ `StrataGate cannot start because this DSH profile resolves an unsupported or mixed core runtime. Resolved: ${found}. Supported DSH versions: ${DSH_RUNTIME_RANGE} (including prereleases). Core DSH packages must share one version; DSH 0.2.0 and later also require matching Session Format packages. DSH 0.2.2 and later require Cordis 4.1.x from 4.1.0 and Schemastery 3.19.x from 3.19.0; earlier modern hosts require Cordis 4.0.x from 4.0.4 and Schemastery 3.18.x from 3.18.4, while older hosts use 4.0.2 and 3.18.2. Reinstall or update stratagate-dsh through \`dsh plugin --profile <name> add <package>\` so the host supplies its peers.`
10589
10683
  );
10590
10684
  }
10591
10685
  function assertCompatibleDshRuntime() {
@@ -13137,6 +13231,24 @@ async function listEndpointModels(url, key) {
13137
13231
  }
13138
13232
 
13139
13233
  // src/fold.ts
13234
+ function renderAttachment(block) {
13235
+ const payload = block.type === "image" ? {
13236
+ type: "image",
13237
+ ...block.attachment.name ? { name: block.attachment.name } : {},
13238
+ attachmentId: String(block.attachment.attachmentId),
13239
+ mediaType: block.attachment.mediaType,
13240
+ bytes: block.attachment.bytes,
13241
+ width: block.attachment.width,
13242
+ height: block.attachment.height,
13243
+ ...block.attachment.originalDimensions ? { originalDimensions: block.attachment.originalDimensions } : {}
13244
+ } : {
13245
+ type: "file",
13246
+ name: block.attachment.name,
13247
+ attachmentId: String(block.attachment.attachmentId),
13248
+ bytes: block.attachment.bytes
13249
+ };
13250
+ return `[StrataGate attachment] ${JSON.stringify(payload)}`;
13251
+ }
13140
13252
  function renderBlocks(blocks) {
13141
13253
  const output = [];
13142
13254
  for (const block of blocks) {
@@ -13147,7 +13259,8 @@ function renderBlocks(blocks) {
13147
13259
  case "reasoning":
13148
13260
  break;
13149
13261
  case "image":
13150
- output.push("[image]");
13262
+ case "file":
13263
+ output.push(renderAttachment(block));
13151
13264
  break;
13152
13265
  case "tool-call":
13153
13266
  break;
@@ -13230,6 +13343,7 @@ var TurnFolder = class {
13230
13343
  user: pending.user.join("\n\n"),
13231
13344
  assistant: pending.assistant.join("\n\n") || reasonLabel(event.data.reason),
13232
13345
  threadId: sessionId,
13346
+ userMessageId: pending.userMessageId,
13233
13347
  assistantToolCalls: [...pending.tools.values()],
13234
13348
  createdAt: toUtc8Iso(event.time),
13235
13349
  receiptId: `dsh:${sessionId}:turn:${event.data.turn}`,
@@ -13248,7 +13362,14 @@ var TurnFolder = class {
13248
13362
  }
13249
13363
  let pending = byTurn.get(turn);
13250
13364
  if (!pending) {
13251
- pending = { turn, user: [], assistant: [], tools: /* @__PURE__ */ new Map(), ignoredTools: /* @__PURE__ */ new Set() };
13365
+ pending = {
13366
+ turn,
13367
+ userMessageId: `dsh:${sessionId}:turn:${turn}:user`,
13368
+ user: [],
13369
+ assistant: [],
13370
+ tools: /* @__PURE__ */ new Map(),
13371
+ ignoredTools: /* @__PURE__ */ new Set()
13372
+ };
13252
13373
  byTurn.set(turn, pending);
13253
13374
  }
13254
13375
  return pending;
@@ -15740,6 +15861,8 @@ var StrataGateRuntime = class _StrataGateRuntime {
15740
15861
  throw new Error("StrataGate agent memory is disabled by configuration (agentMemoryEnabled=false).");
15741
15862
  }
15742
15863
  const memory = await this.space(session);
15864
+ const current = currentTurnUserInput(session);
15865
+ if (current) await memory.reserveUserMessage(current);
15743
15866
  const hasDecider = typeof this.models.externalMemoryDecider === "function";
15744
15867
  const deciderBudgetMs = Math.min(this.config.structuredTaskTimeoutMs ?? 12e4, 3e4);
15745
15868
  const result = await this.models.run(session, () => memory.recordAgentEvent({
@@ -17159,31 +17282,40 @@ var StrataGateRuntime = class _StrataGateRuntime {
17159
17282
  ].join(" ");
17160
17283
  }
17161
17284
  };
17285
+ function currentTurnUserInput(session) {
17286
+ const events = session.snapshotEvents();
17287
+ let start = -1;
17288
+ let turn;
17289
+ for (let index = events.length - 1; index >= 0; index -= 1) {
17290
+ const event = events[index];
17291
+ if (event?.type === "turn/start") {
17292
+ start = index;
17293
+ turn = event.data.turn;
17294
+ break;
17295
+ }
17296
+ if (event?.type === "turn/end" || event?.type === "session/end-seed") return null;
17297
+ }
17298
+ if (start < 0 || turn === void 0) return null;
17299
+ const messages = events.slice(start + 1).filter((event) => event.type === "user/message" && event.data.source.kind === "user");
17300
+ const content = messages.map((event) => renderBlocks(event.data.content)).filter(Boolean).join("\n\n").trim();
17301
+ if (!content) return null;
17302
+ const firstTime = messages[0]?.time;
17303
+ return {
17304
+ id: `dsh:${String(session.id)}:turn:${turn}:user`,
17305
+ content,
17306
+ threadId: String(session.id),
17307
+ ...typeof firstTime === "number" && Number.isFinite(firstTime) ? { createdAt: new Date(firstTime).toISOString() } : {}
17308
+ };
17309
+ }
17162
17310
  function currentUserMessage(session) {
17163
17311
  const messages = typeof session.deriveMessages === "function" ? session.deriveMessages() : [];
17164
17312
  for (let index = messages.length - 1; index >= 0; index -= 1) {
17165
17313
  const message = messages[index];
17166
17314
  if (message?.role !== "user" || message.source.kind !== "user") continue;
17167
- return renderContent(message.content);
17315
+ return renderBlocks(message.content);
17168
17316
  }
17169
17317
  return "";
17170
17318
  }
17171
- function renderContent(content) {
17172
- const output = [];
17173
- for (const block of content) {
17174
- if (block.type === "text" && typeof block.text === "string" && block.text.trim()) {
17175
- output.push(block.text.trim());
17176
- } else if (block.type === "image") {
17177
- output.push("[image]");
17178
- } else {
17179
- const legacy = block;
17180
- if (legacy.type === "tool-result" && Array.isArray(legacy.content)) {
17181
- output.push(renderContent(legacy.content));
17182
- }
17183
- }
17184
- }
17185
- return output.filter(Boolean).join("\n");
17186
- }
17187
17319
  function recentTurns(messages, count) {
17188
17320
  let remaining = count;
17189
17321
  for (let index = messages.length - 1; index >= 0; index -= 1) {
@@ -17514,6 +17646,7 @@ function compactEvent2(event, score) {
17514
17646
  temporal: compactTemporal(event),
17515
17647
  ...event.sourceBlockId !== void 0 ? { sourceBlockId: event.sourceBlockId } : {},
17516
17648
  status: event.status,
17649
+ ...event.supersededBy ? { supersededBy: event.supersededBy } : {},
17517
17650
  scope: event.scope,
17518
17651
  criticality: event.criticality,
17519
17652
  ...agentRecorded ? { source: "agent-recorded" } : {},
@@ -17647,9 +17780,12 @@ function renderActivatedMemory(events, graphResults) {
17647
17780
  id: event.id,
17648
17781
  title: event.title,
17649
17782
  summary: event.summary,
17783
+ status: event.status,
17784
+ supersededBy: event.supersededBy,
17785
+ scope: event.scope,
17650
17786
  happenedStart: event.temporal.happenedStart,
17651
17787
  happenedEnd: event.temporal.happenedEnd,
17652
- temporal: { status: event.temporal.status }
17788
+ temporal: event.temporal
17653
17789
  });
17654
17790
  const cost = estimateTokens(`
17655
17791
  Events:
@@ -18603,19 +18739,19 @@ function blockLayers(block) {
18603
18739
  const deterministic = deterministicBlockLayers(block.l5Raw);
18604
18740
  if (block.processingStatus !== "ready" || !block.l0Title || !block.l0Tags || !block.l1Summary || !block.l2Keypoints) {
18605
18741
  return withLayerMetrics([
18606
- { level: 3, content: deterministic.l3Condensed },
18607
- { level: 4, content: deterministic.l4Readable },
18608
- { level: 5, content: formatRawTranscript(block.l5Raw) }
18742
+ { level: 3, content: preserveAttachmentReferences(deterministic.l3Condensed, block.l5Raw) },
18743
+ { level: 4, content: preserveAttachmentReferences(deterministic.l4Readable, block.l5Raw) },
18744
+ { level: 5, content: preserveAttachmentReferences(formatRawTranscript(block.l5Raw), block.l5Raw) }
18609
18745
  ]);
18610
18746
  }
18611
18747
  return withLayerMetrics([
18612
- { level: 0, content: `${block.l0Title}
18613
- Tags: ${block.l0Tags.join(", ") || "none"}` },
18614
- { level: 1, content: block.l1Summary || block.l0Title },
18615
- { level: 2, content: block.l2Keypoints.map((point) => `- ${point}`).join("\n") || block.l1Summary || block.l0Title },
18616
- { level: 3, content: deterministic.l3Condensed || block.l2Keypoints.join("\n") || block.l1Summary },
18617
- { level: 4, content: deterministic.l4Readable || deterministic.l3Condensed },
18618
- { level: 5, content: formatRawTranscript(block.l5Raw) }
18748
+ { level: 0, content: preserveAttachmentReferences(`${block.l0Title}
18749
+ Tags: ${block.l0Tags.join(", ") || "none"}`, block.l5Raw) },
18750
+ { level: 1, content: preserveAttachmentReferences(block.l1Summary || block.l0Title, block.l5Raw) },
18751
+ { level: 2, content: preserveAttachmentReferences(block.l2Keypoints.map((point) => `- ${point}`).join("\n") || block.l1Summary || block.l0Title, block.l5Raw) },
18752
+ { level: 3, content: preserveAttachmentReferences(deterministic.l3Condensed || block.l2Keypoints.join("\n") || block.l1Summary, block.l5Raw) },
18753
+ { level: 4, content: preserveAttachmentReferences(deterministic.l4Readable || deterministic.l3Condensed, block.l5Raw) },
18754
+ { level: 5, content: preserveAttachmentReferences(formatRawTranscript(block.l5Raw), block.l5Raw) }
18619
18755
  ]);
18620
18756
  }
18621
18757
  function sampledEventWeight(event, turn, lastAdoptedTurn, mentionCount) {