@cortexkit/opencode-magic-context 0.49.77 → 0.49.79

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 (80) hide show
  1. package/dist/auto-search-worker.js +1 -1
  2. package/dist/chunk-embedding-write-worker.js +1 -1
  3. package/dist/{context-8zhjv9tj.js → context-gb3gjahp.js} +63 -143
  4. package/dist/features/magic-context/dreamer/curate-category-rotation.d.ts +1 -1
  5. package/dist/features/magic-context/dreamer/curate-category-rotation.d.ts.map +1 -1
  6. package/dist/features/magic-context/dreamer/curate-memory-safety.d.ts +5 -1
  7. package/dist/features/magic-context/dreamer/curate-memory-safety.d.ts.map +1 -1
  8. package/dist/features/magic-context/dreamer/task-executor.d.ts +2 -0
  9. package/dist/features/magic-context/dreamer/task-executor.d.ts.map +1 -1
  10. package/dist/hooks/magic-context/image-token-estimate.d.ts.map +1 -1
  11. package/dist/{index-5jtq51xv.js → index-2dadxknq.js} +110 -59
  12. package/dist/{index-8mt6vvwx.js → index-2q0t43fy.js} +1 -1
  13. package/dist/{index-1pfjvk89.js → index-8ykmp4jv.js} +6 -6
  14. package/dist/{index-kn23xzst.js → index-aawwdt26.js} +1 -1
  15. package/dist/{index-ng6gfs0y.js → index-enpatj5k.js} +120 -14
  16. package/dist/{index-xkn7vq89.js → index-f619wjj9.js} +3 -3
  17. package/dist/{index-swfwxev1.js → index-hgdkwp21.js} +2 -2
  18. package/dist/{index-72qk8fs8.js → index-m0tbtzqh.js} +3 -3
  19. package/dist/{index-r865s8hf.js → index-m6rkq3t4.js} +1 -1
  20. package/dist/{index-dcdk1thy.js → index-sy5wbbw6.js} +5 -5
  21. package/dist/{index-7jj5jk78.js → index-tvkzkk4s.js} +5 -5
  22. package/dist/{index-k6b1av2m.js → index-twmeey4h.js} +2 -2
  23. package/dist/{index-bw3pmrtk.js → index-v8x07j6c.js} +4 -4
  24. package/dist/{index-rjm4hjyb.js → index-xsdaz3mq.js} +1 -1
  25. package/dist/{index-bdnak4d0.js → index-y208s7zx.js} +5 -3
  26. package/dist/{index-vr6t0y4w.js → index-zzvd4a9z.js} +1 -1
  27. package/dist/index.js +18 -18
  28. package/dist/{message-index-bounded-s0bckzqz.js → message-index-bounded-cfkeyf72.js} +3 -3
  29. package/dist/migration-worker.js +1 -1
  30. package/dist/raw-ordinal-warmup-worker.js +4 -4
  31. package/dist/{read-session-chunk-kqyb1y8c.js → read-session-chunk-s3qac56g.js} +2 -2
  32. package/dist/{recomp-orchestrator-38ed4yhj.js → recomp-orchestrator-jf60eef6.js} +7 -7
  33. package/dist/{render-8s531gd5.js → render-bjxgkrk6.js} +6 -6
  34. package/dist/{search-archive-4vcfm0wv.js → search-archive-a60k0x2n.js} +4 -4
  35. package/dist/{search-m4r4v4aw.js → search-mpde08f1.js} +5 -5
  36. package/dist/shared/subagent-runner.d.ts +9 -0
  37. package/dist/shared/subagent-runner.d.ts.map +1 -1
  38. package/dist/{storage-tags-d3nqrva7.js → storage-tags-6e83pvff.js} +1 -1
  39. package/dist/{store-h2a1g3wh.js → store-j5rvve3v.js} +1 -1
  40. package/dist/{transform-postprocess-phase-ch5fsw7h.js → transform-postprocess-phase-m1be339w.js} +8 -8
  41. package/dist/v2/auto-search-worker.js +1 -1
  42. package/dist/v2/chunk-embedding-write-worker.js +1 -1
  43. package/dist/v2/{context-9nm9edea.js → context-fzp6ynz4.js} +156 -185
  44. package/dist/v2/fold/host-media.d.ts +16 -11
  45. package/dist/v2/fold/host-media.d.ts.map +1 -1
  46. package/dist/v2/fold/native-replay.d.ts.map +1 -1
  47. package/dist/v2/fold/restore.d.ts +7 -5
  48. package/dist/v2/fold/restore.d.ts.map +1 -1
  49. package/dist/v2/hooks/context.d.ts.map +1 -1
  50. package/dist/v2/hooks/payload.d.ts +8 -0
  51. package/dist/v2/hooks/payload.d.ts.map +1 -1
  52. package/dist/v2/hooks/store.d.ts.map +1 -1
  53. package/dist/v2/{message-index-bounded-vfx2zx9y.js → message-index-bounded-0xy4dn04.js} +3 -3
  54. package/dist/v2/migration-worker.js +1 -1
  55. package/dist/v2/raw-ordinal-warmup-worker.js +4 -4
  56. package/dist/v2/{read-session-chunk-bh402br0.js → read-session-chunk-6mt2t6dy.js} +2 -2
  57. package/dist/v2/{recomp-orchestrator-43grkr1k.js → recomp-orchestrator-4r63zen2.js} +6 -6
  58. package/dist/v2/{render-90pve6jf.js → render-7tr9d67f.js} +6 -6
  59. package/dist/v2/{search-archive-9sx7fn3t.js → search-archive-2ck9sbsc.js} +4 -4
  60. package/dist/v2/{search-xr5wb3a3.js → search-y01mww69.js} +4 -4
  61. package/dist/v2/{server-86vydsx9.js → server-0dmzr7f9.js} +2 -2
  62. package/dist/v2/{server-92fhew3p.js → server-1svqwm7m.js} +5 -5
  63. package/dist/v2/{server-6jxvkyrr.js → server-2gcfmd47.js} +1 -1
  64. package/dist/v2/{server-b0k0cfkd.js → server-d7dbk2h6.js} +2 -2
  65. package/dist/v2/{server-gsz7h1zr.js → server-dhdn8mwq.js} +1 -1
  66. package/dist/v2/{server-06ew2dbf.js → server-qpnjsg1v.js} +4 -4
  67. package/dist/v2/{server-fw2sjpkx.js → server-r00xyx66.js} +1 -1
  68. package/dist/v2/{server-b8qp1ark.js → server-r9xsgnez.js} +1 -1
  69. package/dist/v2/{server-65r7p1z4.js → server-tkznm2j9.js} +2 -2
  70. package/dist/v2/{server-474m6n9v.js → server-wc0bb04b.js} +120 -14
  71. package/dist/v2/{server-cxkb9725.js → server-xdh4r20h.js} +5 -3
  72. package/dist/v2/server.js +2 -2
  73. package/dist/v2/{storage-tags-j4he6hwe.js → storage-tags-z8j8wq34.js} +1 -1
  74. package/dist/v2/{store-4se2a0n0.js → store-1fax2zhj.js} +1 -1
  75. package/dist/v2/{v2-archive-reader-rm5qkv00.js → v2-archive-reader-jatkdt2s.js} +1 -1
  76. package/dist/v2/{wrapup-orchestrator-ghbsa00k.js → wrapup-orchestrator-z91sebhb.js} +6 -6
  77. package/dist/{v2-archive-reader-gwe0ry1a.js → v2-archive-reader-sw01917z.js} +1 -1
  78. package/dist/{wrapup-orchestrator-q12ejyw9.js → wrapup-orchestrator-1k48hzxg.js} +8 -8
  79. package/package.json +1 -1
  80. package/src/shared/subagent-runner.ts +10 -0
@@ -196,7 +196,7 @@ import {
196
196
  snapRangeToCompartments,
197
197
  getActiveCompartmentRun,
198
198
  startCompartmentAgent
199
- } from "./index-dcdk1thy.js";
199
+ } from "./index-sy5wbbw6.js";
200
200
  import {
201
201
  hasTrustedAbsoluteWall,
202
202
  applyProvenInputFloor,
@@ -355,7 +355,7 @@ import {
355
355
  getTagsByNumbers2,
356
356
  getDroppedTagsByNumbers2,
357
357
  getMaxDroppedTagNumber2
358
- } from "./index-bdnak4d0.js";
358
+ } from "./index-y208s7zx.js";
359
359
  import {
360
360
  BoundedSessionMap,
361
361
  observeTemporalDecisions,
@@ -427,7 +427,7 @@ import {
427
427
  readRawSessionMessageById2,
428
428
  readSessionChunk2,
429
429
  readRawSessionSeedTail2
430
- } from "./index-8mt6vvwx.js";
430
+ } from "./index-2q0t43fy.js";
431
431
  import {
432
432
  isFailClosedBlockingError,
433
433
  shouldBypassFailClosedBlock,
@@ -453,7 +453,7 @@ import {
453
453
  runSqliteOptimize,
454
454
  openDatabase,
455
455
  openCurrentDatabase
456
- } from "./index-kn23xzst.js";
456
+ } from "./index-aawwdt26.js";
457
457
  import {
458
458
  unescapeXml,
459
459
  resolveWorkspaceShareCategories,
@@ -569,10 +569,10 @@ import {
569
569
  GLOBAL_USER_PROFILE_PROJECT_PATH,
570
570
  getProjectState,
571
571
  bumpProjectUserProfileVersion
572
- } from "./index-rjm4hjyb.js";
572
+ } from "./index-xsdaz3mq.js";
573
573
  import {
574
574
  getLastIndexedOrdinal
575
- } from "./index-vr6t0y4w.js";
575
+ } from "./index-zzvd4a9z.js";
576
576
  import {
577
577
  SESSION_NOTE_CONDITION_ERROR,
578
578
  getNoteByIdInScope,
@@ -704,13 +704,13 @@ import {
704
704
  resolveMemoriesByIdsForSearch2,
705
705
  unifiedSearch2,
706
706
  formatSearchResults2
707
- } from "./index-72qk8fs8.js";
707
+ } from "./index-m0tbtzqh.js";
708
708
  import {
709
709
  scheduleReconciliation,
710
710
  scheduleIncrementalIndex,
711
711
  getMessageIndexQueueHeapStats,
712
712
  clearSessionTracking
713
- } from "./index-r865s8hf.js";
713
+ } from "./index-m6rkq3t4.js";
714
714
  import {
715
715
  flushIgnoredMessages2,
716
716
  clearIgnoredMessages2,
@@ -720,7 +720,7 @@ import {
720
720
  import {
721
721
  setRecompStarting2,
722
722
  setRecompTerminal2
723
- } from "./index-xkn7vq89.js";
723
+ } from "./index-f619wjj9.js";
724
724
  import {
725
725
  makeToolCompositeKey,
726
726
  searchMessageHistoryOffThread,
@@ -805,7 +805,7 @@ import {
805
805
  abortSessionFailClosed2,
806
806
  evaluateEmergencyFailClosed2,
807
807
  runPostTransformPhase2
808
- } from "./index-1pfjvk89.js";
808
+ } from "./index-8ykmp4jv.js";
809
809
  import {
810
810
  ANNOUNCEMENT_VERSION2,
811
811
  ANNOUNCEMENT_FEATURES2,
@@ -820,13 +820,13 @@ import {
820
820
  renderMessageByOrdinal2,
821
821
  renderVerboseRangeForTool2,
822
822
  renderItemByTag2
823
- } from "./index-k6b1av2m.js";
823
+ } from "./index-twmeey4h.js";
824
824
  import {
825
825
  readV2ArchiveOffThread2
826
- } from "./index-bw3pmrtk.js";
826
+ } from "./index-v8x07j6c.js";
827
827
  import {
828
828
  renderSearchArchiveOffThread2
829
- } from "./index-swfwxev1.js";
829
+ } from "./index-hgdkwp21.js";
830
830
  import {
831
831
  COMPACTION_ENABLED_PATH,
832
832
  isDreamerRunnable,
@@ -4011,7 +4011,7 @@ function beginCurateCategoryRun(db, projectIdentity, memories) {
4011
4011
  }));
4012
4012
  return scope;
4013
4013
  }
4014
- function curateTaskStateAfterSuccess(db, projectIdentity, category) {
4014
+ function curateTaskStateAfterCategoryTurn(db, projectIdentity, category) {
4015
4015
  const state = readState(db, projectIdentity);
4016
4016
  return JSON.stringify({
4017
4017
  ...state,
@@ -4055,6 +4055,22 @@ function isDirectiveShapedProjectRule(category, content) {
4055
4055
  // src/features/magic-context/dreamer/curate-memory-safety.ts
4056
4056
  var PROJECT_SCOPED_CATEGORIES = new Set(V2_MEMORY_CATEGORIES);
4057
4057
  var USER_PROFILE_REFERENCE = /\buser(?:[\s_-]+)(?:profile|preferences?)\b|\bU\d+\b/i;
4058
+ var CURATE_SAFETY_REFUSAL_REASONS = [
4059
+ "missing-active-same-category-successor",
4060
+ "user-profile-is-not-project-memory",
4061
+ "directive-shaped-project-rule",
4062
+ "content-loss"
4063
+ ];
4064
+ var refusalReasons = new Set(CURATE_SAFETY_REFUSAL_REASONS);
4065
+ function parseCurateSafetyRefusal(action, output) {
4066
+ if (action !== "archive" && action !== "update")
4067
+ return null;
4068
+ const refusal = /^Skipped (archive|update) for memory \[ID: -?\d+(?:, -?\d+)*\]: curate safety refusal \(([a-z,-]+)\); refused=[1-9]\d*\.$/.exec(output);
4069
+ if (refusal?.[1] !== action || !refusal[2])
4070
+ return null;
4071
+ const reasons = [...new Set(refusal[2].split(","))];
4072
+ return reasons.every((reason) => refusalReasons.has(reason)) ? reasons : null;
4073
+ }
4058
4074
  var refusalCountsBySession = new Map;
4059
4075
  function isSurvivingConsolidationTarget(memory, successor, projectIdentity) {
4060
4076
  return successor !== null && successor.id !== memory.id && successor.status === "active" && successor.supersededByMemoryId === null && (successor.expiresAt === null || successor.expiresAt > Date.now()) && projectIdentity(successor) === projectIdentity(memory) && successor.category === memory.category;
@@ -10053,8 +10069,11 @@ function validateCurateAssistantText(text) {
10053
10069
  }
10054
10070
  return text;
10055
10071
  }
10072
+ function emptyCurateMemoryOperations() {
10073
+ return { totalCalls: 0, completedActions: [], refusals: [] };
10074
+ }
10056
10075
  function inspectCurateMemoryOperations(messages) {
10057
- const summary = { totalCalls: 0, completedActions: [] };
10076
+ const summary = emptyCurateMemoryOperations();
10058
10077
  if (!Array.isArray(messages))
10059
10078
  return summary;
10060
10079
  for (const message of messages) {
@@ -10069,28 +10088,69 @@ function inspectCurateMemoryOperations(messages) {
10069
10088
  const toolName = part.tool ?? part.name;
10070
10089
  if (toolName !== "ctx_memory")
10071
10090
  continue;
10091
+ const state = isRecord(part.state) ? part.state : null;
10092
+ const input = isRecord(state?.input) ? state.input : null;
10093
+ const action = input?.action;
10094
+ const output = state?.status === "completed" && typeof state.output === "string" ? state.output : null;
10095
+ if (output && (action === "get" || action === "list") && /^(?:Found \d+ (?:active )?memor(?:y|ies):|No active memories found\.$|id -?\d+: not found or not visible from this project)/.test(output))
10096
+ continue;
10072
10097
  summary.totalCalls += 1;
10073
- if (!isRecord(part.state) || part.state.status !== "completed")
10098
+ if (!output)
10074
10099
  continue;
10075
- const input = isRecord(part.state.input) ? part.state.input : null;
10076
- const action = input?.action;
10077
- const output = typeof part.state.output === "string" ? part.state.output : "";
10078
- if (output === "completed" && (action === "merge" || action === "archive" || action === "update") || action === "merge" && output.startsWith("Merged memories") || action === "archive" && output.startsWith("Archived memor") || action === "update" && output.startsWith("Updated memory"))
10100
+ if (action === "merge" && output.startsWith("Merged memories") || action === "archive" && output.startsWith("Archived memor") || action === "update" && output.startsWith("Updated memory")) {
10079
10101
  summary.completedActions.push(action);
10102
+ } else {
10103
+ const reasons = parseCurateSafetyRefusal(action, output);
10104
+ if (reasons)
10105
+ summary.refusals.push(reasons);
10106
+ }
10080
10107
  }
10081
10108
  }
10082
10109
  return summary;
10083
10110
  }
10111
+ function unrecognisedCurateOperations(operations) {
10112
+ return operations.totalCalls - operations.completedActions.length - operations.refusals.length;
10113
+ }
10114
+ function validateCurateOutput(messages, text, transport) {
10115
+ const operations = inspectCurateMemoryOperations(messages);
10116
+ if (text)
10117
+ validateCurateAssistantText(text);
10118
+ if (operations.completedActions.length || operations.refusals.length && !unrecognisedCurateOperations(operations))
10119
+ return operations;
10120
+ if (!text && transport === "child")
10121
+ throw new Error("Dreamer returned no assistant output.");
10122
+ if (operations.totalCalls > 0)
10123
+ throw new Error("Curate returned no completed ctx_memory tool result.");
10124
+ if (!text)
10125
+ throw new Error("Dreamer returned no assistant output.");
10126
+ return operations;
10127
+ }
10084
10128
  function formatExpiredArchiveProgress(count) {
10085
10129
  return `curate: archived ${count} expired ${count === 1 ? "memory" : "memories"}`;
10086
10130
  }
10087
- function formatCurateMemoryOperations(actions) {
10131
+ function formatCurateMemoryOperations(operations) {
10132
+ const { completedActions: actions, refusals } = operations;
10133
+ if (!actions.length && !refusals.length)
10134
+ return null;
10088
10135
  const actionCounts = new Map;
10089
10136
  for (const action of actions)
10090
10137
  actionCounts.set(action, (actionCounts.get(action) ?? 0) + 1);
10091
10138
  const actionDetail = [...actionCounts].map(([action, count]) => count === 1 ? action : `${action} ×${count}`).join(", ");
10092
- const noun = actions.length === 1 ? "operation" : "operations";
10093
- return `curate: ${actions.length} memory ${noun} applied${actionDetail ? ` (${actionDetail})` : ""}`;
10139
+ const applied = actions.length ? `${actions.length} memory ${actions.length === 1 ? "operation" : "operations"} applied (${actionDetail})` : "no changes";
10140
+ const detail = [`curate: ${applied}`];
10141
+ if (refusals.length) {
10142
+ const reasonCounts = new Map;
10143
+ for (const reasons of refusals) {
10144
+ for (const reason of reasons)
10145
+ reasonCounts.set(reason, (reasonCounts.get(reason) ?? 0) + 1);
10146
+ }
10147
+ const countedReasons = [...reasonCounts].sort(([a], [b]) => a.localeCompare(b)).map(([reason, count]) => `${reason} ×${count}`).join(", ");
10148
+ detail.push(`${refusals.length} ${refusals.length === 1 ? "operation" : "operations"} refused (${countedReasons})`);
10149
+ }
10150
+ const unrecognised = unrecognisedCurateOperations(operations);
10151
+ if (unrecognised)
10152
+ detail.push(`${unrecognised} with an unrecognised result`);
10153
+ return detail.join("; ");
10094
10154
  }
10095
10155
  function requireDreamClient(client) {
10096
10156
  if (!client)
@@ -10298,6 +10358,7 @@ function createDreamTaskExecutor(deps) {
10298
10358
  };
10299
10359
  return writtenIds.length || deletedIds.length || archivedIds.length || mergedIds.length ? changes : null;
10300
10360
  }
10361
+ let curateCategory;
10301
10362
  try {
10302
10363
  const skip = (reason) => {
10303
10364
  log2(`[dreamer] ${config.task}: skipped (${reason})`);
@@ -10609,7 +10670,10 @@ function createDreamTaskExecutor(deps) {
10609
10670
  computeMemoryDelta,
10610
10671
  reportProgress,
10611
10672
  leaseAcquisition,
10612
- moduleRoute
10673
+ moduleRoute,
10674
+ onCurateCategory: (category) => {
10675
+ curateCategory = category;
10676
+ }
10613
10677
  });
10614
10678
  } catch (error) {
10615
10679
  if (error instanceof DreamTokenBudgetExceeded) {
@@ -10627,7 +10691,11 @@ function createDreamTaskExecutor(deps) {
10627
10691
  transient,
10628
10692
  error: brief,
10629
10693
  failureDetail: formatDreamRunFailure(failure),
10630
- ...retrospectiveOverflow ? { schedulePatch: retrospectiveOverflow.schedulePatch } : {}
10694
+ ...retrospectiveOverflow ? { schedulePatch: retrospectiveOverflow.schedulePatch } : curateCategory && !transient ? {
10695
+ schedulePatch: {
10696
+ taskStateJson: curateTaskStateAfterCategoryTurn(db, projectIdentity, curateCategory)
10697
+ }
10698
+ } : {}
10631
10699
  };
10632
10700
  } finally {
10633
10701
  deps.onProgress?.(null, config.task);
@@ -11134,6 +11202,8 @@ async function runAgenticTask(config, ctx, helpers) {
11134
11202
  const scope = beginCurateCategoryRun(db, projectIdentity, loadActiveMemoryPromptMemories(db, projectIdentity));
11135
11203
  curateMemories = scope?.memories ?? [];
11136
11204
  curateCategory = scope?.category;
11205
+ if (curateCategory)
11206
+ helpers.onCurateCategory(curateCategory);
11137
11207
  log2(`[dreamer] curate pool: category=${curateCategory ?? "none"} in_scope=${curateMemories.length} expired_archived=${expiredArchived}`);
11138
11208
  if (curateMemories.length === 0) {
11139
11209
  const progress = expiredArchived > 0 ? formatExpiredArchiveProgress(expiredArchived) : "curate: no populated project-memory category";
@@ -11169,7 +11239,7 @@ async function runAgenticTask(config, ctx, helpers) {
11169
11239
  }
11170
11240
  const curateChunks = curateMemories ? chunkCurateMemories(curateMemories, Math.max(4000, Math.floor(resolveRetrospectiveUsableInputTokens(config, deps) * 2))) : [];
11171
11241
  const batches = task === "curate" ? curateChunks : [{ memories: [], crossChunkCandidates: [] }];
11172
- const completedActions = [];
11242
+ const curateOperations = emptyCurateMemoryOperations();
11173
11243
  let curateRefused = 0;
11174
11244
  let run = {
11175
11245
  output: [],
@@ -11218,14 +11288,7 @@ async function runAgenticTask(config, ctx, helpers) {
11218
11288
  parseDocsProposalOutput(text);
11219
11289
  if (task !== "curate")
11220
11290
  return text;
11221
- const memoryOperations = inspectCurateMemoryOperations(completion.messages);
11222
- if (text)
11223
- validateCurateAssistantText(text);
11224
- if (memoryOperations.totalCalls > 0 && memoryOperations.completedActions.length === 0)
11225
- throw new Error("Curate returned no completed ctx_memory tool result.");
11226
- if (!text && memoryOperations.completedActions.length === 0)
11227
- throw new Error("Dreamer returned no assistant output.");
11228
- return { text: text || null, memoryOperations };
11291
+ return validateCurateOutput(completion.messages, text, "hidden");
11229
11292
  }
11230
11293
  });
11231
11294
  childSessionId = hidden.childSessionId;
@@ -11284,24 +11347,15 @@ async function runAgenticTask(config, ctx, helpers) {
11284
11347
  parseDocsProposalOutput(text);
11285
11348
  return text;
11286
11349
  }
11287
- const memoryOperations = inspectCurateMemoryOperations(messages);
11288
- if (text)
11289
- validateCurateAssistantText(text);
11290
- if (memoryOperations.completedActions.length > 0) {
11291
- return { text, memoryOperations };
11292
- }
11293
- if (!text)
11294
- throw new Error("Dreamer returned no assistant output.");
11295
- if (memoryOperations.totalCalls > 0) {
11296
- throw new Error("Curate returned no completed ctx_memory tool result.");
11297
- }
11298
- return { text, memoryOperations };
11350
+ return validateCurateOutput(messages, text, "child");
11299
11351
  }
11300
11352
  });
11301
11353
  promptSettled = true;
11302
11354
  }
11303
- if (task === "curate") {
11304
- completedActions.push(...run.validated.memoryOperations.completedActions);
11355
+ if (typeof run.validated !== "string") {
11356
+ curateOperations.totalCalls += run.validated.totalCalls;
11357
+ curateOperations.completedActions.push(...run.validated.completedActions);
11358
+ curateOperations.refusals.push(...run.validated.refusals);
11305
11359
  curateRefused += takeCurateSafetyRefusalCount(childSessionId ?? "");
11306
11360
  }
11307
11361
  if (childSessionId && !deps.hiddenCompletionExecutor) {
@@ -11317,17 +11371,15 @@ async function runAgenticTask(config, ctx, helpers) {
11317
11371
  childSessionId = null;
11318
11372
  }
11319
11373
  }
11320
- if (task === "curate")
11321
- run.validated = {
11322
- text: null,
11323
- memoryOperations: { totalCalls: completedActions.length, completedActions }
11324
- };
11325
11374
  if (leaseLost)
11326
11375
  throw new Error("Dream lease lost during task");
11327
11376
  if (curateRefused > 0) {
11328
11377
  helpers.reportProgress(curateRefused, curateRefused);
11329
11378
  log2(`[dreamer] curate safety summary: refused=${curateRefused}`);
11330
11379
  }
11380
+ const unrecognised = unrecognisedCurateOperations(curateOperations);
11381
+ if (unrecognised > 0)
11382
+ log2(`[dreamer] curate result summary: unrecognised=${unrecognised}`);
11331
11383
  recordInvocation("completed", run.output);
11332
11384
  if (task === "maintain-docs" && docsHashes && changes) {
11333
11385
  try {
@@ -11347,13 +11399,12 @@ async function runAgenticTask(config, ctx, helpers) {
11347
11399
  return { status: "failed", error: reason };
11348
11400
  }
11349
11401
  }
11350
- const curateOutput = task === "curate" ? run.validated : undefined;
11351
11402
  const curateScopeProgress = task === "curate" && curateCategory && curateMemories ? `curate: ${curateCategory} (${curateMemories.length})` : null;
11352
11403
  const progress = [
11353
11404
  curateScopeProgress,
11354
11405
  expiredArchived > 0 ? formatExpiredArchiveProgress(expiredArchived) : null,
11355
- curateOutput && curateOutput.memoryOperations.completedActions.length > 0 ? formatCurateMemoryOperations(curateOutput.memoryOperations.completedActions) : null,
11356
- curateRefused > 0 ? `curate: refused ${curateRefused} unsafe mutation(s)` : null
11406
+ formatCurateMemoryOperations(curateOperations),
11407
+ curateRefused > 0 && !curateOperations.refusals.length ? `curate: refused ${curateRefused} unsafe mutation(s)` : null
11357
11408
  ].filter((value) => Boolean(value)).join("; ");
11358
11409
  const curateCount = task === "curate" && curateCategory ? loadActiveMemoryPromptMemories(db, projectIdentity).filter((memory) => curateCategoryForMemoryCategory(memory.category) === curateCategory).length : undefined;
11359
11410
  const curateBacklog = curateCount !== undefined && curateCategory ? {
@@ -11372,7 +11423,7 @@ async function runAgenticTask(config, ctx, helpers) {
11372
11423
  ...curateBacklog ? { backlog: curateBacklog } : {},
11373
11424
  ...curateCategory ? {
11374
11425
  schedulePatch: {
11375
- taskStateJson: curateTaskStateAfterSuccess(db, projectIdentity, curateCategory)
11426
+ taskStateJson: curateTaskStateAfterCategoryTurn(db, projectIdentity, curateCategory)
11376
11427
  }
11377
11428
  } : {}
11378
11429
  };
@@ -16568,7 +16619,7 @@ function registerRpcHandlers(rpcServer, args) {
16568
16619
  const db = readDatabase();
16569
16620
  if (!db)
16570
16621
  return { ok: false, error: "db unavailable" };
16571
- const { runManagedRecomp } = await importPluginModule(() => import("./recomp-orchestrator-38ed4yhj.js"));
16622
+ const { runManagedRecomp } = await importPluginModule(() => import("./recomp-orchestrator-jf60eef6.js"));
16572
16623
  const { sendIgnoredMessage } = await importPluginModule(() => import("./send-session-notification-ykvt5k2s.js"));
16573
16624
  log2(`[rpc] recomp requested for session ${sessionId}`);
16574
16625
  if (!args.client && !args.hiddenCompletionExecutor) {
@@ -16653,7 +16704,7 @@ function registerRpcHandlers(rpcServer, args) {
16653
16704
  const db = readDatabase();
16654
16705
  if (!db)
16655
16706
  return { ok: false, error: "db unavailable" };
16656
- const { runManagedWrapup } = await importPluginModule(() => import("./wrapup-orchestrator-q12ejyw9.js"));
16707
+ const { runManagedWrapup } = await importPluginModule(() => import("./wrapup-orchestrator-1k48hzxg.js"));
16657
16708
  const model = await args.readSelectedSessionModel?.(sessionId) ?? liveSessionState.liveModelBySession.get(sessionId);
16658
16709
  const window = resolveOpenCodeWrapupWindow(db, sessionId, model);
16659
16710
  if (!window)
@@ -9,7 +9,7 @@ import {
9
9
  estimateMessageTokens,
10
10
  getCandidateToolOwners2,
11
11
  pickNearestPriorOwner2
12
- } from "./index-bdnak4d0.js";
12
+ } from "./index-y208s7zx.js";
13
13
  import {
14
14
  OMO_INTERNAL_INITIATOR_MARKER,
15
15
  isSystemDirective,
@@ -171,7 +171,7 @@ import {
171
171
  adoptNullOwnerToolTag2,
172
172
  getCandidateToolOwners2,
173
173
  pickNearestPriorOwner2
174
- } from "./index-bdnak4d0.js";
174
+ } from "./index-y208s7zx.js";
175
175
  import {
176
176
  textMentionsRecentCommit,
177
177
  hasMeaningfulUserText2,
@@ -225,11 +225,11 @@ import {
225
225
  saveSourceContent,
226
226
  replaceSourceContent,
227
227
  getSourceContents
228
- } from "./index-rjm4hjyb.js";
228
+ } from "./index-xsdaz3mq.js";
229
229
  import {
230
230
  cleanSearchText,
231
231
  matchedSearchSnippet
232
- } from "./index-vr6t0y4w.js";
232
+ } from "./index-zzvd4a9z.js";
233
233
  import {
234
234
  getProjectEmbeddingSnapshot2,
235
235
  embedTextForProject2,
@@ -245,7 +245,7 @@ import {
245
245
  getMessageIndexEpoch,
246
246
  isMessageIndexSearchable,
247
247
  createAutoSearchDiagnostics
248
- } from "./index-r865s8hf.js";
248
+ } from "./index-m6rkq3t4.js";
249
249
  import {
250
250
  openCodeDbExists,
251
251
  withReadOnlySessionDb,
@@ -263,7 +263,7 @@ import {
263
263
  extractToolCallObservation,
264
264
  ToolMutationBatch,
265
265
  createToolDropTarget
266
- } from "./index-8mt6vvwx.js";
266
+ } from "./index-2q0t43fy.js";
267
267
  import {
268
268
  compareOpenCodeMessagesByCanonicalOrder,
269
269
  startCompactionMarkerCandidatePreparation,
@@ -285,7 +285,7 @@ import {
285
285
  peekNoteNudgeText,
286
286
  markNoteNudgeDelivered,
287
287
  getActiveCompartmentRun
288
- } from "./index-dcdk1thy.js";
288
+ } from "./index-sy5wbbw6.js";
289
289
  import {
290
290
  getErrorMessage
291
291
  } from "./index-y8v6yerm.js";
@@ -1021,7 +1021,7 @@ function finishDatabaseOpen(db, dbPath, explicitDbPath, latestSupportedVersion)
1021
1021
  state.running = startMessageFtsRowidMapBackfill2(db, signal).then(async () => {
1022
1022
  if (signal.aborted || !readsOpenCodeStore)
1023
1023
  return;
1024
- const { readRawSessionMessagePage, readRawSessionMessages } = await importPluginModule(() => import("./read-session-chunk-kqyb1y8c.js"));
1024
+ const { readRawSessionMessagePage, readRawSessionMessages } = await importPluginModule(() => import("./read-session-chunk-s3qac56g.js"));
1025
1025
  const { startMessageTimeBackfill } = await importPluginModule(() => import("./message-time-backfill-pz5981mf.js"));
1026
1026
  if (signal.aborted)
1027
1027
  return;
@@ -45,7 +45,120 @@ async function dropStorageNotices(messages, isAdmittedSynthetic) {
45
45
  return drop.size;
46
46
  }
47
47
 
48
+ // src/v2/fold/host-media.ts
49
+ var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
50
+ function isClassInstance(value) {
51
+ if (!isRecord(value))
52
+ return false;
53
+ const prototype = Object.getPrototypeOf(value);
54
+ return prototype !== Object.prototype && prototype !== null;
55
+ }
56
+ var rememberedAssetClass;
57
+ var rememberedAssetSchema;
58
+ var assetSchemaByClass = new WeakMap;
59
+ function assetSchemaOf(messageClass) {
60
+ const known = assetSchemaByClass.get(messageClass);
61
+ if (known !== undefined)
62
+ return known ?? undefined;
63
+ const fields = messageClass.fields;
64
+ const union = fields?.content?.value;
65
+ const members = union?.members;
66
+ const mediaPart = Array.isArray(members) ? members.find((member) => {
67
+ const memberFields = member?.fields;
68
+ const literal = memberFields?.type?.ast?.literal;
69
+ return literal === "media";
70
+ }) : undefined;
71
+ const media = mediaPart?.fields?.media;
72
+ const schema = typeof media === "object" && media !== null || typeof media === "function" ? media : undefined;
73
+ assetSchemaByClass.set(messageClass, schema ?? null);
74
+ return schema;
75
+ }
76
+ function rememberHostMedia(messages) {
77
+ for (const message of messages) {
78
+ if (rememberedAssetClass && rememberedAssetSchema)
79
+ return;
80
+ if (!isClassInstance(message))
81
+ continue;
82
+ rememberedAssetSchema ??= assetSchemaOf(Object.getPrototypeOf(message).constructor);
83
+ if (rememberedAssetClass)
84
+ continue;
85
+ const content = message.content;
86
+ if (!Array.isArray(content))
87
+ continue;
88
+ for (const part of content) {
89
+ if (!isRecord(part) || part.type !== "media")
90
+ continue;
91
+ const media = part.media;
92
+ if (isClassInstance(media) && isRecord(media.source)) {
93
+ rememberedAssetClass = Object.getPrototypeOf(media).constructor;
94
+ break;
95
+ }
96
+ }
97
+ }
98
+ }
99
+ function decodeThroughHostSchema(encoded) {
100
+ const source = encoded.source;
101
+ const assetSchema = rememberedAssetSchema;
102
+ if (!assetSchema)
103
+ return "no host message schema with a media member seen";
104
+ const encoding = assetSchema.ast?.encoding;
105
+ const decode = Array.isArray(encoding) ? encoding[0]?.transformation?.decode : undefined;
106
+ const getter = decode;
107
+ let asset;
108
+ if (getter?._tag === "Transform") {
109
+ if (typeof getter.transform !== "function")
110
+ return "host media schema has no decode transformation";
111
+ asset = getter.transform(encoded);
112
+ } else {
113
+ if (getter?._tag !== undefined)
114
+ return `host media schema has unsupported decode transformation: ${String(getter._tag)}`;
115
+ const run = getter?.run;
116
+ if (typeof run !== "function")
117
+ return "host media schema has no decode transformation";
118
+ const result = run.call(decode, { _tag: "Some", value: encoded }, {});
119
+ const option = result?._tag === "Success" ? result.value : undefined;
120
+ asset = option?._tag === "Some" ? option.value : undefined;
121
+ }
122
+ if (!isClassInstance(asset) || asset.source !== source)
123
+ return "host media schema decode did not return an asset";
124
+ return asset;
125
+ }
126
+ function hostMediaAsset(data, mediaType) {
127
+ return hostMediaFromEncoded({ source: { type: "base64", data, mediaType } });
128
+ }
129
+ function hostMediaFromEncoded(value) {
130
+ if (!isRecord(value.source))
131
+ return "missing Media.Asset source";
132
+ const encoded = structuredClone(value);
133
+ if (encoded.source.type === "bytes") {
134
+ if (typeof encoded.source.data !== "string")
135
+ return "bytes media has no JSON codec payload";
136
+ encoded.source.data = new Uint8Array(Buffer.from(encoded.source.data, "base64"));
137
+ }
138
+ if (!["bytes", "base64", "url", "ref"].includes(String(encoded.source.type)))
139
+ return "unknown Media.Asset source";
140
+ let first = "no Media.Asset seen in this process";
141
+ if (rememberedAssetClass) {
142
+ try {
143
+ return new rememberedAssetClass(encoded);
144
+ } catch (error) {
145
+ first = `remembered asset class threw: ${String(error)}`;
146
+ }
147
+ }
148
+ let second;
149
+ try {
150
+ const decoded = decodeThroughHostSchema(encoded);
151
+ if (typeof decoded !== "string")
152
+ return decoded;
153
+ second = decoded;
154
+ } catch (error) {
155
+ second = `host media schema decode threw: ${String(error)}`;
156
+ }
157
+ return `${first}; ${second}`;
158
+ }
159
+
48
160
  // src/v2/fold/restore.ts
161
+ var HOST_RESTORE_MEDIA = { asset: hostMediaAsset, unavailable: () => {} };
49
162
  function unavailableAttachmentNote(name, mediaType) {
50
163
  return `[Attachment ${name ? `"${name}" ` : ""}(${mediaType}) is not available in this restored history]`;
51
164
  }
@@ -96,17 +209,6 @@ ${[
96
209
  return [];
97
210
  const metadata = file.description === undefined ? undefined : { description: file.description };
98
211
  const located = location ? [{ type: "text", text: `Attached file: ${location}` }] : [];
99
- if (!media)
100
- return [
101
- ...located,
102
- {
103
- type: "media",
104
- mediaType: file.mime,
105
- data: file.data,
106
- filename: file.name,
107
- metadata
108
- }
109
- ];
110
212
  const asset = media.asset(file.data, file.mime);
111
213
  if (typeof asset === "string") {
112
214
  media.unavailable({ rowID, name: file.name, mediaType: file.mime, reason: asset });
@@ -118,7 +220,7 @@ ${[
118
220
  return [...located, { type: "media", media: asset, filename: file.name, metadata }];
119
221
  });
120
222
  }
121
- function restoreRow(row, model, media) {
223
+ function restoreRow(row, model, media = HOST_RESTORE_MEDIA) {
122
224
  const data = row.data;
123
225
  const make = (role, content, metadata = data.metadata) => ({
124
226
  id: row.id,
@@ -282,8 +384,12 @@ function toolStateContent(state) {
282
384
  var rawMessageTypes = new Set(RAW_MESSAGE_TYPES2);
283
385
  var isRawRow = (row) => rawMessageTypes.has(row.type);
284
386
  var NO_MODEL = { providerID: "", id: "" };
387
+ var NO_MEDIA = {
388
+ asset: () => "rendered only to read message ids",
389
+ unavailable: () => {}
390
+ };
285
391
  function hostServesRowById(row) {
286
- return isRawRow(row) && restoreRow(row, NO_MODEL).some((message) => message.id === row.id);
392
+ return isRawRow(row) && restoreRow(row, NO_MODEL, NO_MEDIA).some((message) => message.id === row.id);
287
393
  }
288
394
  function projectRawMessages(rows, ordinalFor) {
289
395
  return rows.filter(isRawRow).map((row, index) => {
@@ -531,4 +637,4 @@ function createV2RawMessageProvider2(reader, sessionID) {
531
637
  };
532
638
  }
533
639
 
534
- export { STORAGE_NOTICE_PREFIX, formatStorageRefusalNotice, formatStorageRecoveryNotice, hasStorageNoticeShape, dropStorageNotices, restoreRow, isToolError, toolErrorText, toolStateContent, servedBoundaryRow2, resolveV2BoundaryUserMessage2, readAllV2RawMessagesForConversion2, readV2RawMessagePagesForConversion2, createV2RawMessageReader2, createV2RawMessageProvider2 };
640
+ export { STORAGE_NOTICE_PREFIX, formatStorageRefusalNotice, formatStorageRecoveryNotice, hasStorageNoticeShape, dropStorageNotices, rememberHostMedia, hostMediaAsset, hostMediaFromEncoded, HOST_RESTORE_MEDIA, restoreRow, isToolError, toolErrorText, toolStateContent, servedBoundaryRow2, resolveV2BoundaryUserMessage2, readAllV2RawMessagesForConversion2, readV2RawMessagePagesForConversion2, createV2RawMessageReader2, createV2RawMessageProvider2 };
@@ -3,14 +3,14 @@ import {
3
3
  } from "./index-ywrz4wy2.js";
4
4
  import {
5
5
  clearEmergencyRecovery
6
- } from "./index-bdnak4d0.js";
6
+ } from "./index-y208s7zx.js";
7
7
  import {
8
8
  requestPendingMaterialization,
9
9
  dropSlot
10
- } from "./index-rjm4hjyb.js";
10
+ } from "./index-xsdaz3mq.js";
11
11
  import {
12
12
  executeContextRecomp
13
- } from "./index-dcdk1thy.js";
13
+ } from "./index-sy5wbbw6.js";
14
14
  import {
15
15
  renderUserFacingFailure,
16
16
  userFacingFailureCode
@@ -19,10 +19,10 @@ import {
19
19
  rawMessageWorkerSource2,
20
20
  rawMessageOffThreadRangeReader2,
21
21
  readRawSessionMessageIdOrdinalsForRange2
22
- } from "./index-8mt6vvwx.js";
22
+ } from "./index-2q0t43fy.js";
23
23
  import {
24
24
  readV2ArchiveOffThread2
25
- } from "./index-bw3pmrtk.js";
25
+ } from "./index-v8x07j6c.js";
26
26
 
27
27
  // src/tools/ctx-expand/search-archive.ts
28
28
  var archiveReadsOnThisThread = 0;
@@ -64,14 +64,14 @@ import {
64
64
  import {
65
65
  matchedSearchSnippet,
66
66
  getIndexedMessageCorpusSize
67
- } from "./index-vr6t0y4w.js";
67
+ } from "./index-zzvd4a9z.js";
68
68
  import {
69
69
  getMessageIndexEpoch,
70
70
  isMessageIndexSearchable,
71
71
  withMemoryHintContent,
72
72
  autoSearchRelevance,
73
73
  recordAutoSearchLane
74
- } from "./index-r865s8hf.js";
74
+ } from "./index-m6rkq3t4.js";
75
75
  import {
76
76
  ensureMemoryEmbeddings2
77
77
  } from "./index-16h5fhem.js";
@@ -81,7 +81,7 @@ import {
81
81
  } from "./index-52x68mj4.js";
82
82
  import {
83
83
  isRecord
84
- } from "./index-bdnak4d0.js";
84
+ } from "./index-y208s7zx.js";
85
85
  import {
86
86
  resolveWorkspaceShareCategories,
87
87
  resolveWorkspaceIdentitySet,