@cchistory/lite 0.5.0 → 0.7.0

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 (190) hide show
  1. package/INSTALL.md +1 -1
  2. package/apps/lite-cli/dist/agent-contract.d.ts +5 -2
  3. package/apps/lite-cli/dist/agent-contract.d.ts.map +1 -1
  4. package/apps/lite-cli/dist/agent-contract.js +20 -9
  5. package/apps/lite-cli/dist/agent-contract.js.map +1 -1
  6. package/apps/lite-cli/dist/agent-journeys.test.d.ts +2 -0
  7. package/apps/lite-cli/dist/agent-journeys.test.d.ts.map +1 -0
  8. package/apps/lite-cli/dist/agent-journeys.test.js +403 -0
  9. package/apps/lite-cli/dist/agent-journeys.test.js.map +1 -0
  10. package/apps/lite-cli/dist/bin.js +3 -3
  11. package/apps/lite-cli/dist/bin.js.map +1 -1
  12. package/apps/lite-cli/dist/index.d.ts.map +1 -1
  13. package/apps/lite-cli/dist/index.js +55 -13
  14. package/apps/lite-cli/dist/index.js.map +1 -1
  15. package/apps/lite-cli/dist/index.test.js +34 -69
  16. package/apps/lite-cli/dist/index.test.js.map +1 -1
  17. package/apps/lite-cli/dist/query.d.ts +15 -2
  18. package/apps/lite-cli/dist/query.d.ts.map +1 -1
  19. package/apps/lite-cli/dist/query.js +79 -4
  20. package/apps/lite-cli/dist/query.js.map +1 -1
  21. package/apps/lite-cli/dist/shell.d.ts +2 -1
  22. package/apps/lite-cli/dist/shell.d.ts.map +1 -1
  23. package/apps/lite-cli/dist/shell.js +20 -16
  24. package/apps/lite-cli/dist/shell.js.map +1 -1
  25. package/apps/lite-cli/dist/version.d.ts +1 -1
  26. package/apps/lite-cli/dist/version.js +1 -1
  27. package/apps/lite-tui/dist/bin.js +3 -3
  28. package/apps/lite-tui/dist/bin.js.map +1 -1
  29. package/apps/lite-tui/dist/index.d.ts.map +1 -1
  30. package/apps/lite-tui/dist/index.js +4 -0
  31. package/apps/lite-tui/dist/index.js.map +1 -1
  32. package/apps/lite-tui/dist/index.test.js +5 -5
  33. package/apps/lite-tui/dist/index.test.js.map +1 -1
  34. package/apps/lite-tui/dist/model.d.ts.map +1 -1
  35. package/apps/lite-tui/dist/model.js +2 -1
  36. package/apps/lite-tui/dist/model.js.map +1 -1
  37. package/apps/lite-tui/dist/render.d.ts +1 -1
  38. package/apps/lite-tui/dist/version.d.ts +1 -1
  39. package/apps/lite-tui/dist/version.js +1 -1
  40. package/bin/cchistory-lite-tui.mjs +3 -3
  41. package/bin/cchistory-lite.mjs +3 -3
  42. package/docs/guide/agent-evidence.md +154 -0
  43. package/docs/guide/for-agents.md +45 -25
  44. package/docs/guide/lite.md +16 -4
  45. package/docs/guide/query.md +11 -2
  46. package/node_modules/@cchistory/canonical/dist/conversation-evidence.d.ts +85 -0
  47. package/node_modules/@cchistory/canonical/dist/conversation-evidence.d.ts.map +1 -0
  48. package/node_modules/@cchistory/canonical/dist/conversation-evidence.js +191 -0
  49. package/node_modules/@cchistory/canonical/dist/conversation-evidence.js.map +1 -0
  50. package/node_modules/@cchistory/canonical/dist/conversation-evidence.test.d.ts +2 -0
  51. package/node_modules/@cchistory/canonical/dist/conversation-evidence.test.d.ts.map +1 -0
  52. package/node_modules/@cchistory/canonical/dist/conversation-evidence.test.js +105 -0
  53. package/node_modules/@cchistory/canonical/dist/conversation-evidence.test.js.map +1 -0
  54. package/node_modules/@cchistory/canonical/dist/index.d.ts +2 -0
  55. package/node_modules/@cchistory/canonical/dist/index.d.ts.map +1 -1
  56. package/node_modules/@cchistory/canonical/dist/index.js +2 -0
  57. package/node_modules/@cchistory/canonical/dist/index.js.map +1 -1
  58. package/node_modules/@cchistory/canonical/dist/projection-audit.d.ts +4 -3
  59. package/node_modules/@cchistory/canonical/dist/projection-audit.d.ts.map +1 -1
  60. package/node_modules/@cchistory/canonical/dist/projection-audit.js +14 -0
  61. package/node_modules/@cchistory/canonical/dist/projection-audit.js.map +1 -1
  62. package/node_modules/@cchistory/canonical/dist/read-status.d.ts +11 -0
  63. package/node_modules/@cchistory/canonical/dist/read-status.d.ts.map +1 -0
  64. package/node_modules/@cchistory/canonical/dist/read-status.js +14 -0
  65. package/node_modules/@cchistory/canonical/dist/read-status.js.map +1 -0
  66. package/node_modules/@cchistory/canonical/dist/session-family.js +1 -1
  67. package/node_modules/@cchistory/canonical/dist/session-family.js.map +1 -1
  68. package/node_modules/@cchistory/canonical/dist/session-interpreter.d.ts +7 -3
  69. package/node_modules/@cchistory/canonical/dist/session-interpreter.d.ts.map +1 -1
  70. package/node_modules/@cchistory/canonical/dist/session-interpreter.js +15 -13
  71. package/node_modules/@cchistory/canonical/dist/session-interpreter.js.map +1 -1
  72. package/node_modules/@cchistory/canonical/package.json +1 -1
  73. package/node_modules/@cchistory/domain/dist/conversation-evidence.d.ts +24 -0
  74. package/node_modules/@cchistory/domain/dist/conversation-evidence.d.ts.map +1 -0
  75. package/node_modules/@cchistory/domain/dist/conversation-evidence.js +2 -0
  76. package/node_modules/@cchistory/domain/dist/conversation-evidence.js.map +1 -0
  77. package/node_modules/@cchistory/domain/dist/index.d.ts +5 -0
  78. package/node_modules/@cchistory/domain/dist/index.d.ts.map +1 -1
  79. package/node_modules/@cchistory/domain/dist/index.js.map +1 -1
  80. package/node_modules/@cchistory/domain/package.json +1 -1
  81. package/node_modules/@cchistory/live-runtime/dist/bootstrap.d.ts +1 -0
  82. package/node_modules/@cchistory/live-runtime/dist/bootstrap.d.ts.map +1 -1
  83. package/node_modules/@cchistory/live-runtime/dist/bootstrap.js +1 -0
  84. package/node_modules/@cchistory/live-runtime/dist/bootstrap.js.map +1 -1
  85. package/node_modules/@cchistory/live-runtime/dist/bounded-cache.d.ts +15 -0
  86. package/node_modules/@cchistory/live-runtime/dist/bounded-cache.d.ts.map +1 -0
  87. package/node_modules/@cchistory/live-runtime/dist/bounded-cache.js +44 -0
  88. package/node_modules/@cchistory/live-runtime/dist/bounded-cache.js.map +1 -0
  89. package/node_modules/@cchistory/live-runtime/dist/bounded-cache.test.d.ts +2 -0
  90. package/node_modules/@cchistory/live-runtime/dist/bounded-cache.test.d.ts.map +1 -0
  91. package/node_modules/@cchistory/live-runtime/dist/bounded-cache.test.js +45 -0
  92. package/node_modules/@cchistory/live-runtime/dist/bounded-cache.test.js.map +1 -0
  93. package/node_modules/@cchistory/live-runtime/dist/diagnostics.d.ts +7 -0
  94. package/node_modules/@cchistory/live-runtime/dist/diagnostics.d.ts.map +1 -0
  95. package/node_modules/@cchistory/live-runtime/dist/diagnostics.js +2 -0
  96. package/node_modules/@cchistory/live-runtime/dist/diagnostics.js.map +1 -0
  97. package/node_modules/@cchistory/live-runtime/dist/history-reader.d.ts +24 -0
  98. package/node_modules/@cchistory/live-runtime/dist/history-reader.d.ts.map +1 -0
  99. package/node_modules/@cchistory/live-runtime/dist/history-reader.js +155 -0
  100. package/node_modules/@cchistory/live-runtime/dist/history-reader.js.map +1 -0
  101. package/node_modules/@cchistory/live-runtime/dist/index.d.ts +92 -6
  102. package/node_modules/@cchistory/live-runtime/dist/index.d.ts.map +1 -1
  103. package/node_modules/@cchistory/live-runtime/dist/index.js +249 -70
  104. package/node_modules/@cchistory/live-runtime/dist/index.js.map +1 -1
  105. package/node_modules/@cchistory/live-runtime/dist/index.test.js +6 -1
  106. package/node_modules/@cchistory/live-runtime/dist/index.test.js.map +1 -1
  107. package/node_modules/@cchistory/live-runtime/dist/launcher-memory.d.ts +12 -0
  108. package/node_modules/@cchistory/live-runtime/dist/launcher-memory.d.ts.map +1 -0
  109. package/node_modules/@cchistory/live-runtime/dist/launcher-memory.js +44 -0
  110. package/node_modules/@cchistory/live-runtime/dist/launcher-memory.js.map +1 -0
  111. package/node_modules/@cchistory/live-runtime/dist/launcher-memory.test.d.ts +2 -0
  112. package/node_modules/@cchistory/live-runtime/dist/launcher-memory.test.d.ts.map +1 -0
  113. package/node_modules/@cchistory/live-runtime/dist/launcher-memory.test.js +20 -0
  114. package/node_modules/@cchistory/live-runtime/dist/launcher-memory.test.js.map +1 -0
  115. package/node_modules/@cchistory/live-runtime/dist/live-read-recovery.test.d.ts +2 -0
  116. package/node_modules/@cchistory/live-runtime/dist/live-read-recovery.test.d.ts.map +1 -0
  117. package/node_modules/@cchistory/live-runtime/dist/live-read-recovery.test.js +92 -0
  118. package/node_modules/@cchistory/live-runtime/dist/live-read-recovery.test.js.map +1 -0
  119. package/node_modules/@cchistory/live-runtime/dist/scan-guard.d.ts +1 -0
  120. package/node_modules/@cchistory/live-runtime/dist/scan-guard.d.ts.map +1 -1
  121. package/node_modules/@cchistory/live-runtime/dist/scan-guard.js +7 -13
  122. package/node_modules/@cchistory/live-runtime/dist/scan-guard.js.map +1 -1
  123. package/node_modules/@cchistory/live-runtime/dist/scan-guard.test.js +50 -55
  124. package/node_modules/@cchistory/live-runtime/dist/scan-guard.test.js.map +1 -1
  125. package/node_modules/@cchistory/live-runtime/dist/selective-query.d.ts +2 -1
  126. package/node_modules/@cchistory/live-runtime/dist/selective-query.d.ts.map +1 -1
  127. package/node_modules/@cchistory/live-runtime/dist/selective-query.js.map +1 -1
  128. package/node_modules/@cchistory/live-runtime/dist/selective-query.test.js +8 -3
  129. package/node_modules/@cchistory/live-runtime/dist/selective-query.test.js.map +1 -1
  130. package/node_modules/@cchistory/live-runtime/dist/system-memory.test.js +3 -3
  131. package/node_modules/@cchistory/live-runtime/dist/system-memory.test.js.map +1 -1
  132. package/node_modules/@cchistory/live-runtime/package.json +1 -1
  133. package/node_modules/@cchistory/source-adapters/dist/core/conversation-seeds.d.ts +3 -0
  134. package/node_modules/@cchistory/source-adapters/dist/core/conversation-seeds.d.ts.map +1 -1
  135. package/node_modules/@cchistory/source-adapters/dist/core/conversation-seeds.js.map +1 -1
  136. package/node_modules/@cchistory/source-adapters/dist/core/decoded-record.d.ts +12 -0
  137. package/node_modules/@cchistory/source-adapters/dist/core/decoded-record.d.ts.map +1 -0
  138. package/node_modules/@cchistory/source-adapters/dist/core/decoded-record.js +32 -0
  139. package/node_modules/@cchistory/source-adapters/dist/core/decoded-record.js.map +1 -0
  140. package/node_modules/@cchistory/source-adapters/dist/core/decoded-record.test.d.ts +2 -0
  141. package/node_modules/@cchistory/source-adapters/dist/core/decoded-record.test.d.ts.map +1 -0
  142. package/node_modules/@cchistory/source-adapters/dist/core/decoded-record.test.js +21 -0
  143. package/node_modules/@cchistory/source-adapters/dist/core/decoded-record.test.js.map +1 -0
  144. package/node_modules/@cchistory/source-adapters/dist/core/file-read-plan.js +3 -2
  145. package/node_modules/@cchistory/source-adapters/dist/core/file-read-plan.js.map +1 -1
  146. package/node_modules/@cchistory/source-adapters/dist/core/jsonl-records.d.ts +3 -1
  147. package/node_modules/@cchistory/source-adapters/dist/core/jsonl-records.d.ts.map +1 -1
  148. package/node_modules/@cchistory/source-adapters/dist/core/jsonl-records.js +56 -38
  149. package/node_modules/@cchistory/source-adapters/dist/core/jsonl-records.js.map +1 -1
  150. package/node_modules/@cchistory/source-adapters/dist/core/jsonl-records.test.js +76 -1
  151. package/node_modules/@cchistory/source-adapters/dist/core/jsonl-records.test.js.map +1 -1
  152. package/node_modules/@cchistory/source-adapters/dist/core/parser.d.ts +16 -5
  153. package/node_modules/@cchistory/source-adapters/dist/core/parser.d.ts.map +1 -1
  154. package/node_modules/@cchistory/source-adapters/dist/core/parser.js +136 -76
  155. package/node_modules/@cchistory/source-adapters/dist/core/parser.js.map +1 -1
  156. package/node_modules/@cchistory/source-adapters/dist/core/probe.d.ts.map +1 -1
  157. package/node_modules/@cchistory/source-adapters/dist/core/probe.js +75 -54
  158. package/node_modules/@cchistory/source-adapters/dist/core/probe.js.map +1 -1
  159. package/node_modules/@cchistory/source-adapters/dist/core/read-budget.d.ts +4 -1
  160. package/node_modules/@cchistory/source-adapters/dist/core/read-budget.d.ts.map +1 -1
  161. package/node_modules/@cchistory/source-adapters/dist/core/read-budget.js +5 -3
  162. package/node_modules/@cchistory/source-adapters/dist/core/read-budget.js.map +1 -1
  163. package/node_modules/@cchistory/source-adapters/dist/core/read-budget.test.js +61 -2
  164. package/node_modules/@cchistory/source-adapters/dist/core/read-budget.test.js.map +1 -1
  165. package/node_modules/@cchistory/source-adapters/dist/core/source-identity.d.ts +6 -2
  166. package/node_modules/@cchistory/source-adapters/dist/core/source-identity.d.ts.map +1 -1
  167. package/node_modules/@cchistory/source-adapters/dist/core/source-identity.js +5 -5
  168. package/node_modules/@cchistory/source-adapters/dist/core/source-identity.js.map +1 -1
  169. package/node_modules/@cchistory/source-adapters/dist/core/types.d.ts +4 -1
  170. package/node_modules/@cchistory/source-adapters/dist/core/types.d.ts.map +1 -1
  171. package/node_modules/@cchistory/source-adapters/dist/index.test.d.ts +1 -0
  172. package/node_modules/@cchistory/source-adapters/dist/index.test.d.ts.map +1 -1
  173. package/node_modules/@cchistory/source-adapters/dist/index.test.js +1 -0
  174. package/node_modules/@cchistory/source-adapters/dist/index.test.js.map +1 -1
  175. package/node_modules/@cchistory/source-adapters/dist/platforms/amp.test.js +49 -1
  176. package/node_modules/@cchistory/source-adapters/dist/platforms/amp.test.js.map +1 -1
  177. package/node_modules/@cchistory/source-adapters/dist/platforms/zcode/runtime.d.ts +2 -0
  178. package/node_modules/@cchistory/source-adapters/dist/platforms/zcode/runtime.d.ts.map +1 -1
  179. package/node_modules/@cchistory/source-adapters/dist/platforms/zcode/runtime.js +48 -29
  180. package/node_modules/@cchistory/source-adapters/dist/platforms/zcode/runtime.js.map +1 -1
  181. package/node_modules/@cchistory/source-adapters/package.json +1 -1
  182. package/package.json +5 -5
  183. package/schemas/cchistory-lite-agent-v1.schema.json +8 -5
  184. package/schemas/cchistory-lite-canonical-v1.schema.json +82 -0
  185. package/schemas/cchistory-lite-diagnostic-v1.schema.json +27 -0
  186. package/schemas/cchistory-lite-query-result-v2.schema.json +232 -4
  187. package/schemas/cchistory-lite-query-result-v3.schema.json +45 -1
  188. package/schemas/cchistory-lite-query-v2.schema.json +150 -8
  189. package/schemas/cchistory-lite-v2.schema.json +82 -0
  190. package/skills/using-cchistory-lite/SKILL.md +86 -127
@@ -1,8 +1,6 @@
1
- import { SourceReadBudgetExceededError } from "./read-budget.js";
2
1
  import os from "node:os";
3
2
  import path from "node:path";
4
3
  import { readFile, stat } from "node:fs/promises";
5
- import { assertSourceFileReadCurrent, assertSourceFileReadPlanCurrent, SourceFileReadPlanChangedError } from "./file-read-plan.js";
6
4
  import { deriveHostId, selectTailBlob } from "@cchistory/domain";
7
5
  import { nowIso, stableId, pathExists, formatErrorMessage, createLossAudit, dedupeById, listSourceFiles, readGitProjectEvidence, deriveSessionId, extractSourceSessionIdFromCanonicalSessionId, buildSourceResumeCommand, minIso, maxIso, sha1, compareTimeThenSeq, collapseAntigravityUserTurnAtoms, } from "./utils.js";
8
6
  import { getDefaultSources, resolveSourceFormatProfile } from "./discovery.js";
@@ -11,7 +9,7 @@ import { isAntigravityBrainSourceFile, isAntigravityHistoryIndexFile } from "../
11
9
  import { extractCursorChatStoreSeed, clearCursorWorkspaceIndexCache } from "../platforms/cursor/runtime.js";
12
10
  import { getPlatformAdapter } from "../platforms/registry.js";
13
11
  import { deriveSourceFileLogicalSessionKey, inspectSourceFileLogicalSessionMetadata, SESSION_METADATA_MAX_LINE_BYTES, } from "./session-grouping.js";
14
- import { extractRecords, extractMultiSessionSeeds, buildAdapterBlobResult, captureBlob, captureBlobStreaming, fileIdentityFromStats, parseRecord, isOrdinaryResumeEligibleSourceFile, extractGenericSessionMetadata, extractGenericRole, extractGenericContentItems, extractRichTextText, collectConversationSeedsFromValue, dedupeClaudeCodeTokenUsageFragments, } from "./parser.js";
12
+ import { extractRecords, extractMultiSessionSeeds, iterateZcodeSeeds, buildAdapterBlobResult, createAdapterBlobBuilder, captureBlob, captureBlobStreaming, fileIdentityFromStats, parseRecord, isOrdinaryResumeEligibleSourceFile, extractGenericSessionMetadata, extractGenericRole, extractGenericContentItems, extractRichTextText, collectConversationSeedsFromValue, dedupeClaudeCodeTokenUsageFragments, } from "./parser.js";
15
13
  import { collectJsonlRecordsStreaming, isIncrementalJsonlPlatform } from "./jsonl-records.js";
16
14
  import { atomizeFragments, hydrateDraftFromAtoms } from "./atomizer.js";
17
15
  import { splitUserText } from "./user-text.js";
@@ -123,11 +121,14 @@ async function finalizeSourcePayload(interpretSession, state, host, options) {
123
121
  message: `Deriving projections from ${state.sessionsById.size} session candidate(s)`,
124
122
  });
125
123
  const deriveStartedAt = Date.now();
126
- const processingCore = await processCollectedSessions(interpretSession, state.sessionsById, state.orphanBlobs, state.lossAudits, { safeMode: options.safe_mode ?? false });
124
+ const processingCore = await processCollectedSessions(interpretSession, state.sessionsById, state.orphanBlobs, state.lossAudits, { safeMode: options.safe_mode ?? false, retainRawRecords: options.retain_raw_records !== false,
125
+ onInterpretedSession: count => emitProbeProgress(options, state.source, { stage: "derive_progress", count, count_unit: "sessions" }),
126
+ });
127
127
  emitProbeProgress(options, state.source, {
128
128
  stage: "derive_done",
129
129
  message: `Derived ${processingCore.sessions.length} session(s), ${processingCore.turns.length} turn(s)`,
130
130
  count: processingCore.turns.length,
131
+ count_unit: "turns",
131
132
  elapsed_ms: Date.now() - deriveStartedAt,
132
133
  });
133
134
  const uniqueBlobs = dedupeById(processingCore.blobs);
@@ -184,6 +185,7 @@ async function finalizeSourcePayload(interpretSession, state, host, options) {
184
185
  stage: "source_done",
185
186
  message: `Finished ${state.source.display_name}`,
186
187
  count: processingCore.turns.length,
188
+ count_unit: "turns",
187
189
  elapsed_ms: Date.now() - state.monotonicStartedAt,
188
190
  });
189
191
  return payload;
@@ -296,7 +298,9 @@ export async function projectFileSessionInputs(interpretSession, source, session
296
298
  async function* streamCollectedFileInputs(source, host, sourceFormatProfile, options, startedAt) {
297
299
  const captureRunId = stableId("capture-run", source.id, startedAt);
298
300
  const adapter = getPlatformAdapter(source.platform);
299
- const previousIndex = buildPreviousSourceIndex(options.previous_payloads?.[source.id], sourceFormatProfile);
301
+ const previousPayload = options.previous_payloads?.[source.id];
302
+ const previousIndex = previousPayload?.records.some(record => record.raw_text_retained === false)
303
+ ? undefined : buildPreviousSourceIndex(previousPayload, sourceFormatProfile);
300
304
  const changedSinceMs = parseChangedSinceMs(options.changed_since);
301
305
  const capturedCompanionPaths = new Set();
302
306
  let remainingFileLimit = options.limit_files_per_source;
@@ -331,6 +335,7 @@ async function* streamCollectedFileInputs(source, host, sourceFormatProfile, opt
331
335
  stage: "live_probe_done",
332
336
  message: `Collected ${liveCollection?.virtualPaths.length ?? 0} live item(s)`,
333
337
  count: liveCollection?.virtualPaths.length ?? 0,
338
+ count_unit: "files",
334
339
  });
335
340
  }
336
341
  emitProbeProgress(options, source, {
@@ -350,6 +355,7 @@ async function* streamCollectedFileInputs(source, host, sourceFormatProfile, opt
350
355
  stage: "list_files_done",
351
356
  message: `Found ${files.length} source file(s)`,
352
357
  count: files.length,
358
+ count_unit: "files",
353
359
  file_count: files.length,
354
360
  elapsed_ms: Date.now() - listFilesStartedAt,
355
361
  });
@@ -367,12 +373,9 @@ async function* streamSingleFileInputs(source, host, sourceFormatProfile, option
367
373
  file_index: fileIndex + 1,
368
374
  file_count: fileCount,
369
375
  });
370
- // Keep invalidated-budget failures outside the per-file parse-error recovery path.
376
+ // Plans select an inventory. Native writers may keep appending or updating
377
+ // SQLite WAL/SHM; only optimization evidence requires version validation.
371
378
  const readPlan = options.source_file_plans?.[source.id] ?? options.source_file_plans?.[source.slot_id];
372
- if (readPlan)
373
- await assertSourceFileReadCurrent(readPlan, filePath);
374
- if (!isPathBackedSqliteSourceFile(source.platform, filePath))
375
- options.read_budget?.admit(await getFileSize(filePath), filePath);
376
379
  const fileLossAudits = [];
377
380
  const fileOrphanBlobs = [];
378
381
  const fileTrustedBytesByBlobId = new Map();
@@ -388,9 +391,13 @@ async function* streamSingleFileInputs(source, host, sourceFormatProfile, option
388
391
  const isOversized = sizeBytes > maxFileBytes;
389
392
  // Oversized files are skipped only when parsing needs the whole file in
390
393
  // memory. Incremental JSONL streams; path-backed SQLite is opened by path.
391
- const canProcessOversizedWithoutMaterializing = isOversized &&
394
+ const canProcessOversizedWithoutMaterializing = (isOversized || options.retain_raw_records === false &&
395
+ (sizeBytes > 8 * 1024 * 1024 || sizeBytes > (options.read_budget?.maximumUnitBytes?.() ?? Infinity))) &&
392
396
  (isIncrementalJsonlPlatform(source.platform) || isPathBackedSqliteSourceFile(source.platform, filePath));
393
- if (isOversized && !canProcessOversizedWithoutMaterializing) {
397
+ // An explicit cap remains binding. Guarded whole-file readers already price
398
+ // the actual allocation against live headroom; the fallback cap is not RAM capacity.
399
+ const hasAllocationAdmission = options.max_file_bytes === undefined && options.read_budget?.maximumUnitBytes !== undefined;
400
+ if (isOversized && !canProcessOversizedWithoutMaterializing && !hasAllocationAdmission) {
394
401
  const detail = `Skipped oversized source file ${filePath}: ${sizeBytes} bytes exceeds ${maxFileBytes} byte limit`;
395
402
  const blobRef = stableId("blob", source.id, filePath, "oversized");
396
403
  fileLossAudits.push(createLossAudit(source.id, blobRef, "unknown_fragment", detail, {
@@ -446,11 +453,11 @@ async function* streamSingleFileInputs(source, host, sourceFormatProfile, option
446
453
  }
447
454
  else {
448
455
  const captureStartedAt = Date.now();
449
- capturedBlob = canProcessOversizedWithoutMaterializing
450
- ? isPathBackedSqliteSourceFile(source.platform, filePath)
451
- ? await capturePathBackedBlob(source, host.id, filePath, captureRunId)
452
- : await captureBlobStreaming(source, host.id, filePath, captureRunId)
453
- : await captureBlob(source, host.id, filePath, captureRunId);
456
+ capturedBlob = isPathBackedSqliteSourceFile(source.platform, filePath)
457
+ ? await capturePathBackedBlob(source, host.id, filePath, captureRunId)
458
+ : canProcessOversizedWithoutMaterializing
459
+ ? await captureBlobStreaming(source, host.id, filePath, captureRunId, options.read_budget, options.retain_raw_records === false)
460
+ : await captureBlob(source, host.id, filePath, captureRunId, options.read_budget);
454
461
  emitProbeProgress(options, source, {
455
462
  stage: "file_capture_done",
456
463
  message: `Captured ${filePath}`,
@@ -560,9 +567,6 @@ async function* streamSingleFileInputs(source, host, sourceFormatProfile, option
560
567
  };
561
568
  return;
562
569
  }
563
- // Streaming and SQLite parsing may reopen the path after capture.
564
- if (readPlan)
565
- await assertSourceFileReadCurrent(readPlan, filePath);
566
570
  try {
567
571
  const parseStartedAt = Date.now();
568
572
  const previousEntry = previousIndex?.byOriginPath.get(path.normalize(filePath));
@@ -580,10 +584,10 @@ async function* streamSingleFileInputs(source, host, sourceFormatProfile, option
580
584
  }
581
585
  const adapterResults = appendedResults ?? (capturedBlob
582
586
  ? (capturedBlobHasFileBuffer(capturedBlob)
583
- ? await processBlob(source, sourceFormatProfile, filePath, capturedBlob, options.target_session_refs, options.read_budget)
587
+ ? await processBlob(source, sourceFormatProfile, filePath, capturedBlob, options.target_session_refs, options.read_budget, options.retain_raw_records !== false)
584
588
  : capturedBlobIsStreaming(capturedBlob)
585
- ? await processStreamingJsonlBlob(source, sourceFormatProfile, filePath, capturedBlob)
586
- : await processPathBackedSqliteBlob(source, sourceFormatProfile, filePath, capturedBlob.blob, options.target_session_refs, options.read_budget))
589
+ ? await processStreamingJsonlBlob(source, sourceFormatProfile, filePath, capturedBlob, options)
590
+ : await processPathBackedSqliteBlob(source, sourceFormatProfile, filePath, capturedBlob.blob, options.target_session_refs, options.read_budget, options.retain_raw_records !== false, count => emitProbeProgress(options, source, { stage: "file_parse_progress", file_path: filePath, count, count_unit: "sessions" })))
587
591
  : []);
588
592
  const sessionsById = new Map();
589
593
  const targetedResults = options.target_session_refs?.length
@@ -607,18 +611,14 @@ async function* streamSingleFileInputs(source, host, sourceFormatProfile, option
607
611
  if (adapter?.getCompanionEvidencePaths && !options.safe_mode) {
608
612
  const companionPaths = readPlan?.companions[filePath]
609
613
  ?? await adapter.getCompanionEvidencePaths(source.base_dir, filePath);
610
- if (readPlan)
611
- await assertSourceFileReadCurrent(readPlan, filePath);
612
614
  for (const companionPath of companionPaths) {
613
615
  const normalizedCompanionPath = path.normalize(companionPath);
614
616
  if (capturedCompanionPaths.has(normalizedCompanionPath) || !(await pathExists(normalizedCompanionPath))) {
615
617
  continue;
616
618
  }
617
- if (readPlan)
618
- await assertSourceFileReadPlanCurrent(readPlan, [normalizedCompanionPath]);
619
619
  capturedCompanionPaths.add(normalizedCompanionPath);
620
620
  try {
621
- const companionCaptured = await captureBlob(source, host.id, normalizedCompanionPath, captureRunId);
621
+ const companionCaptured = await captureBlob(source, host.id, normalizedCompanionPath, captureRunId, options.read_budget);
622
622
  fileOrphanBlobs.push(companionCaptured.blob);
623
623
  fileTrustedBytesByBlobId.set(companionCaptured.blob.id, companionCaptured.fileBuffer);
624
624
  }
@@ -652,8 +652,6 @@ async function* streamSingleFileInputs(source, host, sourceFormatProfile, option
652
652
  };
653
653
  }
654
654
  catch (error) {
655
- if (error instanceof SourceFileReadPlanChangedError || error instanceof SourceReadBudgetExceededError)
656
- throw error;
657
655
  const orphanBlob = capturedBlob?.blob;
658
656
  if (orphanBlob) {
659
657
  fileOrphanBlobs.push(orphanBlob);
@@ -1548,6 +1546,11 @@ async function processCollectedSessions(interpretSession, sessionsById, orphanBl
1548
1546
  }
1549
1547
  }
1550
1548
  for (const sessionInput of sessionsById.values()) {
1549
+ if (options.retainRawRecords === false) {
1550
+ sessionInput.records = sessionInput.records.map(record => record.raw_text_retained === false ? record : {
1551
+ ...record, raw_size_bytes: Buffer.byteLength(record.raw_json, "utf8"), raw_json: "", raw_text_retained: false,
1552
+ });
1553
+ }
1551
1554
  sessionInput.atoms.sort(compareTimeThenSeq);
1552
1555
  if (sessionInput.draft.source_platform === "antigravity") {
1553
1556
  sessionInput.atoms = collapseAntigravityUserTurnAtoms(sessionInput.atoms);
@@ -1569,6 +1572,7 @@ async function processCollectedSessions(interpretSession, sessionsById, orphanBl
1569
1572
  askUserQuestionTurns.push(...buildAskUserQuestionTurns(sessionInput.draft, sessionInput.atoms, sessionInput.edges));
1570
1573
  }
1571
1574
  lossAudits.push(...sessionInput.loss_audits);
1575
+ options.onInterpretedSession?.(sessions.length);
1572
1576
  }
1573
1577
  blobs.push(...orphanBlobs);
1574
1578
  lossAudits.push(...sourceLossAudits);
@@ -1595,13 +1599,10 @@ function emitProbeProgress(options, source, event) {
1595
1599
  ...event,
1596
1600
  });
1597
1601
  }
1598
- async function getFileSize(filePath) {
1599
- return (await stat(filePath)).size;
1602
+ async function processPathBackedSqliteBlob(source, sourceFormatProfile, filePath, blob, targetSessionRefs, budget, retainRawRecords = true, onSession) {
1603
+ return (await tryProcessPathOpenedContainer(source, sourceFormatProfile, filePath, blob, Buffer.alloc(0), targetSessionRefs, budget, retainRawRecords, onSession)) ?? [];
1600
1604
  }
1601
- async function processPathBackedSqliteBlob(source, sourceFormatProfile, filePath, blob, targetSessionRefs, budget) {
1602
- return (await tryProcessPathOpenedContainer(source, sourceFormatProfile, filePath, blob, Buffer.alloc(0), targetSessionRefs, budget)) ?? [];
1603
- }
1604
- async function tryProcessPathOpenedContainer(source, sourceFormatProfile, filePath, blob, fileBuffer, targetSessionRefs, budget) {
1605
+ async function tryProcessPathOpenedContainer(source, sourceFormatProfile, filePath, blob, fileBuffer, targetSessionRefs, budget, retainRawRecords = true, onSession) {
1605
1606
  const blobId = blob.id;
1606
1607
  if (source.platform === "cursor" && path.basename(filePath) === "store.db") {
1607
1608
  const chatStoreSeed = await extractCursorChatStoreSeed(source.platform, filePath, blob.file_modified_at ?? nowIso(), {
@@ -1657,12 +1658,16 @@ async function tryProcessPathOpenedContainer(source, sourceFormatProfile, filePa
1657
1658
  }
1658
1659
  return [];
1659
1660
  }
1660
- const multiSessionSeeds = await extractMultiSessionSeeds(source, filePath, fileBuffer, blobId, targetSessionRefs, budget);
1661
+ const multiSessionSeeds = source.platform === "zcode"
1662
+ ? iterateZcodeSeeds(source, filePath, targetSessionRefs, budget, retainRawRecords)
1663
+ : await extractMultiSessionSeeds(source, filePath, fileBuffer, blobId, targetSessionRefs, budget);
1661
1664
  if (!multiSessionSeeds) {
1662
1665
  return undefined;
1663
1666
  }
1664
1667
  const results = [];
1665
- for (const seed of multiSessionSeeds.filter((entry) => !targetSessionRefs?.length || targetSessionRefs.some((ref) => targetRefMatchesSession(ref, entry.sessionId)))) {
1668
+ for (const seed of multiSessionSeeds) {
1669
+ if (targetSessionRefs?.length && !targetSessionRefs.some(ref => targetRefMatchesSession(ref, seed.sessionId)))
1670
+ continue;
1666
1671
  results.push(buildAdapterBlobResult(source, sourceFormatProfile, blob.host_id, filePath, blob.capture_run_id, blob, seed.sessionId, seed.records.map((record, ordinal) => ({
1667
1672
  id: stableId("record", source.id, seed.sessionId, blobId, String(ordinal), record.pointer),
1668
1673
  source_id: source.id,
@@ -1673,17 +1678,20 @@ async function tryProcessPathOpenedContainer(source, sourceFormatProfile, filePa
1673
1678
  observed_at: record.observedAt ?? nowIso(),
1674
1679
  parseable: true,
1675
1680
  raw_json: record.rawJson,
1681
+ ...(record.parsedValue ? { parsed_value: record.parsedValue, raw_size_bytes: record.rawSizeBytes,
1682
+ raw_text_retained: false } : {}),
1676
1683
  })), {
1677
1684
  title: seed.title,
1678
1685
  created_at: seed.createdAt,
1679
1686
  updated_at: seed.updatedAt,
1680
1687
  model: seed.model,
1681
1688
  working_directory: seed.workingDirectory,
1682
- }));
1689
+ }, [], retainRawRecords));
1690
+ onSession?.(results.length);
1683
1691
  }
1684
1692
  return results;
1685
1693
  }
1686
- async function processBlob(source, sourceFormatProfile, filePath, capturedBlob, targetSessionRefs, budget) {
1694
+ async function processBlob(source, sourceFormatProfile, filePath, capturedBlob, targetSessionRefs, budget, retainRawRecords = true) {
1687
1695
  const { blob, fileBuffer } = capturedBlob;
1688
1696
  const pathOpened = await tryProcessPathOpenedContainer(source, sourceFormatProfile, filePath, blob, fileBuffer, targetSessionRefs, budget);
1689
1697
  if (pathOpened) {
@@ -1691,7 +1699,16 @@ async function processBlob(source, sourceFormatProfile, filePath, capturedBlob,
1691
1699
  }
1692
1700
  const blobId = blob.id;
1693
1701
  const profileId = sourceFormatProfile.id;
1694
- const sessionId = deriveSessionId(source.platform, filePath, fileBuffer);
1702
+ let decodedRoot;
1703
+ if (source.platform === "amp") {
1704
+ try {
1705
+ decodedRoot = { value: JSON.parse(fileBuffer.toString("utf8")) };
1706
+ }
1707
+ catch {
1708
+ decodedRoot = { value: undefined };
1709
+ }
1710
+ }
1711
+ const sessionId = deriveSessionId(source.platform, filePath, fileBuffer, decodedRoot);
1695
1712
  if (targetSessionRefs?.length &&
1696
1713
  source.platform !== "codex" &&
1697
1714
  !targetSessionRefs.some((ref) => targetRefMatchesSession(ref, sessionId)) &&
@@ -1706,7 +1723,7 @@ async function processBlob(source, sourceFormatProfile, filePath, capturedBlob,
1706
1723
  sessionId,
1707
1724
  captureRunId: blob.capture_run_id,
1708
1725
  };
1709
- const records = await extractRecords(context, blobId, fileBuffer);
1726
+ const records = await extractRecords(context, blobId, fileBuffer, retainRawRecords, decodedRoot);
1710
1727
  const extractionLossAudits = [];
1711
1728
  if (records.length === 0) {
1712
1729
  extractionLossAudits.push(createLossAudit(source.id, blobId, "dropped_for_projection", "Blob was captured but produced no raw records", {
@@ -1746,26 +1763,30 @@ async function processBlob(source, sourceFormatProfile, filePath, capturedBlob,
1746
1763
  // captured from file identity (metadata-only) and opened by path via
1747
1764
  // processPathBackedSqliteBlob instead of being hashed into memory.
1748
1765
  // AMP root-JSON, Gemini, and other non-JSONL shapes still take the oversized skip.
1749
- async function processStreamingJsonlBlob(source, sourceFormatProfile, filePath, capturedBlob) {
1766
+ async function processStreamingJsonlBlob(source, sourceFormatProfile, filePath, capturedBlob, options = {}) {
1750
1767
  const { blob } = capturedBlob;
1751
1768
  const blobId = blob.id;
1752
1769
  const profileId = sourceFormatProfile.id;
1753
1770
  const head = await capturedBlob.prefixReader(SESSION_METADATA_MAX_LINE_BYTES);
1754
1771
  const sessionId = deriveSessionId(source.platform, filePath, head);
1755
- const context = {
1756
- source,
1757
- hostId: blob.host_id,
1758
- filePath,
1759
- profileId,
1760
- sessionId,
1761
- captureRunId: blob.capture_run_id,
1762
- };
1772
+ const builder = createAdapterBlobBuilder(source, sourceFormatProfile, blob.host_id, filePath, blob.capture_run_id, blob, sessionId, {}, [], options.retain_raw_records !== false);
1773
+ let parsedRecords = 0;
1763
1774
  const records = await collectJsonlRecordsStreaming(capturedBlob.streamingLineReader(), {
1764
1775
  sourceId: source.id,
1765
1776
  blobId,
1766
1777
  sessionId,
1767
1778
  }, {
1768
1779
  observedAt: nowIso(),
1780
+ transformRecord: record => {
1781
+ const retained = builder.append(record);
1782
+ if (++parsedRecords % 256 === 0)
1783
+ emitProbeProgress(options, source, {
1784
+ stage: "file_parse_progress", file_path: filePath, count: parsedRecords, count_unit: "records",
1785
+ });
1786
+ return retained;
1787
+ },
1788
+ admitLineBytes: options.retain_raw_records === false
1789
+ ? bytes => options.read_budget?.admit(bytes, `${filePath}:JSONL record`) : undefined,
1769
1790
  sidecars: source.platform === "factory_droid"
1770
1791
  ? [
1771
1792
  {
@@ -1805,9 +1826,9 @@ async function processStreamingJsonlBlob(source, sourceFormatProfile, filePath,
1805
1826
  sourceFormatProfileId: profileId,
1806
1827
  }));
1807
1828
  }
1808
- return [
1809
- buildAdapterBlobResult(source, sourceFormatProfile, blob.host_id, filePath, blob.capture_run_id, blob, sessionId, records, {}, extractionLossAudits),
1810
- ];
1829
+ const result = builder.finish();
1830
+ result.loss_audits.push(...extractionLossAudits);
1831
+ return [result];
1811
1832
  }
1812
1833
  function buildSyntheticSeedAdapterResult(source, sourceFormatProfile, hostId, captureRunId, originPath, seed) {
1813
1834
  const serializedSeed = JSON.stringify(seed.records);