@remnic/core 1.1.9 → 1.1.11

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 (209) hide show
  1. package/dist/access-cli.js +35 -32
  2. package/dist/access-cli.js.map +1 -1
  3. package/dist/access-http.d.ts +8 -7
  4. package/dist/access-http.js +17 -14
  5. package/dist/access-mcp.d.ts +8 -7
  6. package/dist/access-mcp.js +16 -13
  7. package/dist/{access-service-BJCIjVRY.d.ts → access-service-BkXt3di1.d.ts} +11 -9
  8. package/dist/access-service.d.ts +8 -7
  9. package/dist/access-service.js +15 -12
  10. package/dist/active-memory-bridge.d.ts +2 -1
  11. package/dist/active-recall.d.ts +2 -1
  12. package/dist/behavior-learner.d.ts +2 -1
  13. package/dist/behavior-signals.d.ts +2 -1
  14. package/dist/bootstrap.d.ts +7 -6
  15. package/dist/briefing.d.ts +3 -2
  16. package/dist/briefing.js +3 -3
  17. package/dist/buffer-surprise-report.d.ts +2 -1
  18. package/dist/buffer.d.ts +3 -2
  19. package/dist/calibration.d.ts +4 -1
  20. package/dist/calibration.js +10 -5
  21. package/dist/calibration.js.map +1 -1
  22. package/dist/causal-behavior.d.ts +2 -1
  23. package/dist/causal-consolidation.d.ts +5 -2
  24. package/dist/causal-consolidation.js +14 -8
  25. package/dist/causal-consolidation.js.map +1 -1
  26. package/dist/{chunk-ICULSMDG.js → chunk-2YMTO4ZJ.js} +2 -2
  27. package/dist/{chunk-XL3UCAZA.js → chunk-363MWCD3.js} +35 -35
  28. package/dist/{chunk-PHQH2VUO.js → chunk-36CTNQY7.js} +7 -7
  29. package/dist/{chunk-XN4D6Z7X.js → chunk-4DXC6HQQ.js} +5 -3
  30. package/dist/chunk-4DXC6HQQ.js.map +1 -0
  31. package/dist/{chunk-OWGGXPKV.js → chunk-57QNCUEZ.js} +5 -5
  32. package/dist/{chunk-LOBRX7VD.js → chunk-5UM2VJ6D.js} +12 -1
  33. package/dist/chunk-5UM2VJ6D.js.map +1 -0
  34. package/dist/{chunk-KMWZXT5T.js → chunk-6XA7UN4Z.js} +2 -2
  35. package/dist/{chunk-G6NX57V2.js → chunk-C5HUWVH2.js} +2 -2
  36. package/dist/{chunk-NN3TS5BM.js → chunk-D54LZC5L.js} +4 -4
  37. package/dist/{chunk-U4SZXGEO.js → chunk-EYNQTST2.js} +2 -2
  38. package/dist/chunk-HJYHRE4S.js +647 -0
  39. package/dist/chunk-HJYHRE4S.js.map +1 -0
  40. package/dist/{chunk-M3DK45UM.js → chunk-I6BQZSML.js} +4 -4
  41. package/dist/chunk-IBX3VFOM.js +446 -0
  42. package/dist/chunk-IBX3VFOM.js.map +1 -0
  43. package/dist/{chunk-G3G3LY22.js → chunk-KBYWQWSB.js} +7 -7
  44. package/dist/{chunk-FPWUENQH.js → chunk-KUHRUM6B.js} +92 -487
  45. package/dist/chunk-KUHRUM6B.js.map +1 -0
  46. package/dist/chunk-KWBPHZUU.js +83 -0
  47. package/dist/chunk-KWBPHZUU.js.map +1 -0
  48. package/dist/{chunk-CTYRIJ5E.js → chunk-LIO5X3CM.js} +2 -2
  49. package/dist/{chunk-MJLUHRSF.js → chunk-MCC6KDQF.js} +2 -2
  50. package/dist/{chunk-J3P6WSFZ.js → chunk-O4XJUPSF.js} +2 -2
  51. package/dist/{chunk-6OAQEOGV.js → chunk-PB5KW5PL.js} +2 -2
  52. package/dist/{chunk-Y3VT6ZCP.js → chunk-PHNGXFQ6.js} +5 -3
  53. package/dist/chunk-PHNGXFQ6.js.map +1 -0
  54. package/dist/{chunk-2MVUXO4H.js → chunk-RXTFCYQF.js} +2 -2
  55. package/dist/chunk-S2JJBLJG.js +2101 -0
  56. package/dist/chunk-S2JJBLJG.js.map +1 -0
  57. package/dist/{chunk-Q7FJ5ZHM.js → chunk-S3IP6R6K.js} +8 -2
  58. package/dist/{chunk-Q7FJ5ZHM.js.map → chunk-S3IP6R6K.js.map} +1 -1
  59. package/dist/{chunk-ET4BL42V.js → chunk-VQXK37XA.js} +1 -1
  60. package/dist/{chunk-ET4BL42V.js.map → chunk-VQXK37XA.js.map} +1 -1
  61. package/dist/{chunk-FLBYSB2V.js → chunk-VX2IUQFE.js} +94 -8
  62. package/dist/chunk-VX2IUQFE.js.map +1 -0
  63. package/dist/{chunk-QPLYTPYL.js → chunk-WGK4VHGP.js} +77 -15
  64. package/dist/chunk-WGK4VHGP.js.map +1 -0
  65. package/dist/{chunk-7SFAENUZ.js → chunk-WTFWLUSX.js} +2 -2
  66. package/dist/{chunk-A6PGANSE.js → chunk-Y5KDIOKF.js} +3 -3
  67. package/dist/{chunk-KIF7QNKL.js → chunk-Z5S5HNGY.js} +5 -3
  68. package/dist/chunk-Z5S5HNGY.js.map +1 -0
  69. package/dist/{chunk-BIHCWSWA.js → chunk-ZL4S7ARC.js} +3 -3
  70. package/dist/{cli-BojuyOOp.d.ts → cli-Cvy2SNhF.d.ts} +4 -4
  71. package/dist/cli.d.ts +9 -8
  72. package/dist/cli.js +27 -25
  73. package/dist/codex-cli-fallback.d.ts +44 -0
  74. package/dist/codex-cli-fallback.js +12 -0
  75. package/dist/{codex-materialize-YVC2wb6n.d.ts → codex-materialize-CQlLTzke.d.ts} +1 -1
  76. package/dist/compression-optimizer.d.ts +2 -1
  77. package/dist/config.d.ts +2 -1
  78. package/dist/consolidation-provenance-check.d.ts +3 -2
  79. package/dist/consolidation-undo.d.ts +3 -2
  80. package/dist/day-summary.d.ts +2 -1
  81. package/dist/delinearize.d.ts +2 -1
  82. package/dist/direct-answer-wiring.d.ts +2 -1
  83. package/dist/direct-answer.d.ts +2 -1
  84. package/dist/embedding-fallback.d.ts +2 -1
  85. package/dist/{engine-EDFFOWDD.js → engine-FOC3IJLA.js} +4 -4
  86. package/dist/entity-retrieval.d.ts +3 -2
  87. package/dist/entity-retrieval.js +3 -3
  88. package/dist/entity-schema.d.ts +2 -1
  89. package/dist/explicit-capture.d.ts +7 -6
  90. package/dist/explicit-cue-recall.d.ts +16 -1
  91. package/dist/explicit-cue-recall.js +7 -3
  92. package/dist/extraction-judge-telemetry.d.ts +2 -1
  93. package/dist/extraction-judge-training.d.ts +2 -1
  94. package/dist/extraction-judge.d.ts +2 -1
  95. package/dist/extraction.d.ts +2 -1
  96. package/dist/extraction.js +6 -4
  97. package/dist/fallback-llm.d.ts +8 -1
  98. package/dist/fallback-llm.js +5 -3
  99. package/dist/identity-continuity.d.ts +2 -1
  100. package/dist/importance.d.ts +2 -1
  101. package/dist/index-1qIcnbG1.d.ts +34 -0
  102. package/dist/index.d.ts +16 -14
  103. package/dist/index.js +62 -51
  104. package/dist/index.js.map +1 -1
  105. package/dist/intent.d.ts +2 -1
  106. package/dist/lifecycle.d.ts +2 -1
  107. package/dist/live-connectors-runner.d.ts +2 -1
  108. package/dist/local-llm.d.ts +2 -1
  109. package/dist/memory-action-policy.d.ts +2 -1
  110. package/dist/memory-cache.d.ts +2 -1
  111. package/dist/{memory-governance-AAQPBZEP.js → memory-governance-F3QOJGEY.js} +4 -4
  112. package/dist/memory-governance-F3QOJGEY.js.map +1 -0
  113. package/dist/memory-lifecycle-ledger-utils.d.ts +2 -1
  114. package/dist/{memory-projection-store-BW8u5U0u.d.ts → memory-projection-store-CY8TU40w.d.ts} +1 -1
  115. package/dist/memory-projection-store.d.ts +3 -2
  116. package/dist/memory-worth-outcomes.d.ts +3 -2
  117. package/dist/models-json.d.ts +2 -1
  118. package/dist/native-knowledge.d.ts +2 -1
  119. package/dist/objective-state-writers.d.ts +23 -1
  120. package/dist/objective-state-writers.js +10 -306
  121. package/dist/objective-state-writers.js.map +1 -1
  122. package/dist/objective-state.d.ts +7 -1
  123. package/dist/objective-state.js +3 -1
  124. package/dist/operator-toolkit.d.ts +3 -2
  125. package/dist/operator-toolkit.js +6 -6
  126. package/dist/{orchestrator-CYqmqxco.d.ts → orchestrator-AOQMo7QI.d.ts} +5 -3
  127. package/dist/orchestrator.d.ts +7 -6
  128. package/dist/orchestrator.js +29 -27
  129. package/dist/patterns-cli.d.ts +2 -1
  130. package/dist/policy-runtime.d.ts +2 -1
  131. package/dist/{port-Br27H8dy.d.ts → port-B6VEDIkC.d.ts} +1 -1
  132. package/dist/qmd-recall-cache.d.ts +3 -2
  133. package/dist/qmd.d.ts +3 -2
  134. package/dist/recall-disclosure-escalation.d.ts +2 -1
  135. package/dist/recall-explain-renderer.d.ts +2 -1
  136. package/dist/recall-explain-renderer.js +3 -3
  137. package/dist/recall-state.d.ts +2 -1
  138. package/dist/recall-tag-filter.d.ts +2 -1
  139. package/dist/recall-xray-cli.d.ts +2 -1
  140. package/dist/recall-xray-cli.js +4 -4
  141. package/dist/recall-xray-renderer.d.ts +2 -1
  142. package/dist/recall-xray-renderer.js +3 -3
  143. package/dist/recall-xray.d.ts +2 -1
  144. package/dist/recall-xray.js +2 -2
  145. package/dist/resolve-auth-token.d.ts +2 -1
  146. package/dist/resolve-provider-secret.d.ts +2 -1
  147. package/dist/resolve-provider-secret.js +3 -1
  148. package/dist/resume-bundles.js +3 -3
  149. package/dist/retrieval-agents.d.ts +3 -2
  150. package/dist/retrieval-tiers.d.ts +2 -1
  151. package/dist/schemas.d.ts +22 -22
  152. package/dist/sdk-compat.d.ts +3 -2
  153. package/dist/sdk-compat.js.map +1 -1
  154. package/dist/{semantic-consolidation-GPcLr9BQ.d.ts → semantic-consolidation-ByBXb-sf.d.ts} +2 -2
  155. package/dist/semantic-consolidation.d.ts +4 -3
  156. package/dist/semantic-consolidation.js +3 -3
  157. package/dist/semantic-rule-promotion.js +3 -3
  158. package/dist/semantic-rule-verifier.d.ts +2 -1
  159. package/dist/semantic-rule-verifier.js +3 -3
  160. package/dist/session-observer-bands.d.ts +2 -1
  161. package/dist/session-observer-state.d.ts +2 -1
  162. package/dist/signal.d.ts +2 -1
  163. package/dist/storage.d.ts +3 -2
  164. package/dist/storage.js +2 -2
  165. package/dist/summarizer.d.ts +2 -1
  166. package/dist/summarizer.js +6 -4
  167. package/dist/summary-snapshot.d.ts +2 -1
  168. package/dist/temporal-supersession.d.ts +3 -2
  169. package/dist/temporal-validity.d.ts +2 -1
  170. package/dist/threading.d.ts +2 -1
  171. package/dist/tier-migration.d.ts +4 -3
  172. package/dist/tier-routing.d.ts +2 -1
  173. package/dist/topics.d.ts +2 -1
  174. package/dist/transcript.d.ts +2 -1
  175. package/dist/types.d.ts +2693 -1
  176. package/dist/types.js +1 -1
  177. package/dist/utility-runtime.d.ts +2 -1
  178. package/dist/verified-recall.js +3 -3
  179. package/package.json +1 -1
  180. package/dist/chunk-3VRIIII5.js +0 -905
  181. package/dist/chunk-3VRIIII5.js.map +0 -1
  182. package/dist/chunk-FLBYSB2V.js.map +0 -1
  183. package/dist/chunk-FPWUENQH.js.map +0 -1
  184. package/dist/chunk-KIF7QNKL.js.map +0 -1
  185. package/dist/chunk-LOBRX7VD.js.map +0 -1
  186. package/dist/chunk-QPLYTPYL.js.map +0 -1
  187. package/dist/chunk-XN4D6Z7X.js.map +0 -1
  188. package/dist/chunk-Y3VT6ZCP.js.map +0 -1
  189. package/dist/types-Bmp9ssU2.d.ts +0 -2714
  190. /package/dist/{chunk-ICULSMDG.js.map → chunk-2YMTO4ZJ.js.map} +0 -0
  191. /package/dist/{chunk-XL3UCAZA.js.map → chunk-363MWCD3.js.map} +0 -0
  192. /package/dist/{chunk-PHQH2VUO.js.map → chunk-36CTNQY7.js.map} +0 -0
  193. /package/dist/{chunk-OWGGXPKV.js.map → chunk-57QNCUEZ.js.map} +0 -0
  194. /package/dist/{chunk-KMWZXT5T.js.map → chunk-6XA7UN4Z.js.map} +0 -0
  195. /package/dist/{chunk-G6NX57V2.js.map → chunk-C5HUWVH2.js.map} +0 -0
  196. /package/dist/{chunk-NN3TS5BM.js.map → chunk-D54LZC5L.js.map} +0 -0
  197. /package/dist/{chunk-U4SZXGEO.js.map → chunk-EYNQTST2.js.map} +0 -0
  198. /package/dist/{chunk-M3DK45UM.js.map → chunk-I6BQZSML.js.map} +0 -0
  199. /package/dist/{chunk-G3G3LY22.js.map → chunk-KBYWQWSB.js.map} +0 -0
  200. /package/dist/{chunk-CTYRIJ5E.js.map → chunk-LIO5X3CM.js.map} +0 -0
  201. /package/dist/{chunk-MJLUHRSF.js.map → chunk-MCC6KDQF.js.map} +0 -0
  202. /package/dist/{chunk-J3P6WSFZ.js.map → chunk-O4XJUPSF.js.map} +0 -0
  203. /package/dist/{chunk-6OAQEOGV.js.map → chunk-PB5KW5PL.js.map} +0 -0
  204. /package/dist/{chunk-2MVUXO4H.js.map → chunk-RXTFCYQF.js.map} +0 -0
  205. /package/dist/{chunk-7SFAENUZ.js.map → chunk-WTFWLUSX.js.map} +0 -0
  206. /package/dist/{chunk-A6PGANSE.js.map → chunk-Y5KDIOKF.js.map} +0 -0
  207. /package/dist/{chunk-BIHCWSWA.js.map → chunk-ZL4S7ARC.js.map} +0 -0
  208. /package/dist/{engine-EDFFOWDD.js.map → codex-cli-fallback.js.map} +0 -0
  209. /package/dist/{memory-governance-AAQPBZEP.js.map → engine-FOC3IJLA.js.map} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/objective-state-writers.ts"],"sourcesContent":["import crypto from \"node:crypto\";\nimport {\n type ObjectiveStateChangeKind,\n type ObjectiveStateOutcome,\n type ObjectiveStateSnapshot,\n recordObjectiveStateSnapshot,\n} from \"./objective-state.js\";\nimport {\n parseMessageParts,\n type LcmMessagePartInput,\n type MessagePartSourceFormat,\n} from \"./message-parts/index.js\";\n\ninterface ToolCallContext {\n toolName?: string;\n toolCallId?: string;\n args?: Record<string, unknown>;\n}\n\ninterface DerivedObjectiveStateResult {\n snapshots: ObjectiveStateSnapshot[];\n filePaths: string[];\n}\n\ninterface ObservedMessageWithParts {\n role?: string;\n content?: string;\n parts?: LcmMessagePartInput[] | null;\n rawContent?: unknown;\n sourceFormat?: MessagePartSourceFormat;\n}\n\ninterface ObservedPartEntry {\n messageIndex: number;\n partIndex: number;\n part: LcmMessagePartInput;\n}\n\nconst rawProviderParts = new WeakSet<LcmMessagePartInput>();\n\nfunction markRawProviderParts(parts: LcmMessagePartInput[]): LcmMessagePartInput[] {\n for (const part of parts) {\n rawProviderParts.add(part);\n }\n return parts;\n}\n\nfunction isRawProviderPart(part: LcmMessagePartInput): boolean {\n return rawProviderParts.has(part);\n}\n\nfunction hashSha256(value: string): string {\n return crypto.createHash(\"sha256\").update(value).digest(\"hex\");\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction optionalString(value: unknown): string | undefined {\n if (typeof value !== \"string\") return undefined;\n const trimmed = value.trim();\n return trimmed.length > 0 ? trimmed : undefined;\n}\n\nfunction toolNameTokens(toolName: string | undefined): string[] {\n if (!toolName) return [];\n return toolName\n .replace(/([a-z0-9])([A-Z])/g, \"$1_$2\")\n .toLowerCase()\n .split(/[^a-z0-9]+/)\n .filter((token) => token.length > 0);\n}\n\nfunction normalizedToolName(toolName: string | undefined): string {\n return toolNameTokens(toolName).join(\"_\");\n}\n\nfunction parseToolArguments(value: unknown): Record<string, unknown> | undefined {\n if (isRecord(value)) return value;\n if (typeof value !== \"string\") return undefined;\n try {\n const parsed = JSON.parse(value) as unknown;\n return isRecord(parsed) ? parsed : undefined;\n } catch {\n return undefined;\n }\n}\n\nfunction stableStringify(value: unknown): string {\n if (Array.isArray(value)) {\n return `[${value.map((entry) => stableStringify(entry)).join(\",\")}]`;\n }\n if (isRecord(value)) {\n return `{${Object.keys(value)\n .sort()\n .map((key) => `${JSON.stringify(key)}:${stableStringify(value[key])}`)\n .join(\",\")}}`;\n }\n return JSON.stringify(value) ?? String(value);\n}\n\nfunction extractTextContent(value: unknown): string {\n if (typeof value === \"string\") return value.trim();\n if (Array.isArray(value)) {\n return value\n .map((block) => {\n if (typeof block === \"string\") return block.trim();\n if (isRecord(block) && block.type === \"text\" && typeof block.text === \"string\") {\n return block.text.trim();\n }\n return \"\";\n })\n .filter((item) => item.length > 0)\n .join(\"\\n\");\n }\n if (isRecord(value)) {\n return JSON.stringify(value);\n }\n return \"\";\n}\n\nfunction parseToolResultPayload(content: unknown): unknown {\n const text = extractTextContent(content);\n if (text.length === 0) return undefined;\n try {\n return JSON.parse(text) as unknown;\n } catch {\n return text;\n }\n}\n\nfunction resultHash(value: unknown): string | undefined {\n if (value === undefined) return undefined;\n const canonical =\n typeof value === \"string\" ? value : stableStringify(value);\n if (!canonical || canonical.length === 0) return undefined;\n return `sha256:${hashSha256(canonical)}`;\n}\n\nfunction getToolCallContexts(messages: Array<Record<string, unknown>>): Map<string, ToolCallContext> {\n const contexts = new Map<string, ToolCallContext>();\n for (const message of messages) {\n if (message.role !== \"assistant\") continue;\n const toolCalls = message.tool_calls ?? message.toolCalls;\n if (!Array.isArray(toolCalls)) continue;\n for (const call of toolCalls) {\n if (!isRecord(call)) continue;\n const toolCallId = optionalString(call.id) ?? optionalString(call.toolCallId);\n if (!toolCallId) continue;\n const fn = isRecord(call.function) ? call.function : undefined;\n const toolName =\n optionalString(fn?.name) ??\n optionalString(call.name);\n const args =\n parseToolArguments(fn?.arguments) ??\n parseToolArguments(call.arguments) ??\n parseToolArguments(call.args) ??\n parseToolArguments(call.input);\n contexts.set(toolCallId, { toolCallId, toolName, args });\n }\n }\n return contexts;\n}\n\nfunction toolCallIdForMessage(message: Record<string, unknown>): string | undefined {\n return (\n optionalString(message.tool_call_id) ??\n optionalString(message.toolCallId) ??\n optionalString(message.tool_use_id) ??\n optionalString(message.toolUseId)\n );\n}\n\nfunction toolNameForMessage(message: Record<string, unknown>, context?: ToolCallContext): string | undefined {\n return (\n optionalString(message.name) ??\n optionalString(message.toolName) ??\n optionalString(message.tool) ??\n context?.toolName\n );\n}\n\nfunction pickString(args: Record<string, unknown> | undefined, keys: string[]): string | undefined {\n if (!args) return undefined;\n for (const key of keys) {\n const value = optionalString(args[key]);\n if (value) return value;\n }\n return undefined;\n}\n\nfunction pickFirstStringArrayValue(args: Record<string, unknown> | undefined, key: string): string | undefined {\n const value = args?.[key];\n if (!Array.isArray(value)) return undefined;\n for (const item of value) {\n const candidate = optionalString(item);\n if (candidate) return candidate;\n }\n return undefined;\n}\n\nfunction fileScopeFromArgs(args: Record<string, unknown> | undefined): {\n scope?: string;\n sourcePath?: string;\n destinationPath?: string;\n} {\n const destinationPath =\n pickString(args, [\"destination\", \"dest\", \"targetPath\", \"target\", \"to\"]) ??\n pickString(args, [\"path\", \"filePath\", \"workspacePath\", \"projectPath\"]) ??\n pickFirstStringArrayValue(args, \"paths\");\n const sourcePath =\n pickString(args, [\"source\", \"src\", \"from\", \"oldPath\"]);\n const scope = destinationPath ?? sourcePath;\n return { scope, sourcePath, destinationPath };\n}\n\nfunction fileContentHash(args: Record<string, unknown> | undefined): string | undefined {\n const content =\n pickString(args, [\"content\", \"patch\", \"diff\", \"text\", \"value\"]) ??\n args?.updates;\n return resultHash(content);\n}\n\nfunction inferOutcome(message: Record<string, unknown>, parsedPayload: unknown): ObjectiveStateOutcome {\n if (message.isError === true) return \"failure\";\n if (isRecord(parsedPayload)) {\n if (parsedPayload.partial === true || parsedPayload.status === \"partial\") return \"partial\";\n if (parsedPayload.success === false || parsedPayload.ok === false) return \"failure\";\n if (parsedPayload.success === true || parsedPayload.ok === true) return \"success\";\n if (typeof parsedPayload.exitCode === \"number\") {\n return parsedPayload.exitCode === 0 ? \"success\" : \"failure\";\n }\n if (optionalString(parsedPayload.error)) return \"failure\";\n if (parsedPayload.status === \"error\" || parsedPayload.status === \"failed\") return \"failure\";\n if (parsedPayload.status === \"ok\" || parsedPayload.status === \"success\") return \"success\";\n const outputText = [\n optionalString(parsedPayload.stdout),\n optionalString(parsedPayload.stderr),\n ].filter((entry): entry is string => entry !== undefined).join(\"\\n\");\n if (outputText) {\n const outputOutcome = inferOutcome({}, outputText);\n if (outputOutcome !== \"unknown\") return outputOutcome;\n }\n }\n if (typeof parsedPayload === \"string\") {\n const lowered = parsedPayload.toLowerCase();\n const loweredForFailure = lowered\n .replace(/\\b(?:previously\\s+)?failed tests?\\s+now\\s+pass(?:ed|es)?\\b/g, \"\");\n const hasZeroCountMarker = /\\b(?:0|no)\\s+(?:errors?|failures?|exceptions?|timeouts?)\\b/.test(lowered);\n const loweredForFailureCounts = loweredForFailure\n .replace(/\\b(?:0|no)\\s+errors?\\b/g, \"\")\n .replace(/\\b(?:0|no)\\s+failures?\\b/g, \"\")\n .replace(/\\b(?:0|no)\\s+exceptions?\\b/g, \"\")\n .replace(/\\b(?:0|no)\\s+timeouts?\\b/g, \"\");\n const hasNonZeroErrorCounts = /\\b[1-9]\\d*\\s+errors?\\b/.test(loweredForFailureCounts);\n const hasNegatedSuccessMarkers =\n /\\b(?:not|did not|didn't|doesn't|isn't|aren't|wasn't|weren't|won't|can't|couldn't|shouldn't|wouldn't)\\s+(?:ok|pass|passed|passes|succeeded|success)\\b/.test(loweredForFailure);\n const hasSuccessMarkers =\n /\\b(success|succeeded|pass|passes|passed|ok)\\b/.test(lowered) ||\n hasZeroCountMarker;\n const hasFailureMarkers =\n hasNegatedSuccessMarkers ||\n /\\b(exceptions?|failed|failures?|fatal|timeouts?|timed out)\\b/.test(loweredForFailureCounts) ||\n hasNonZeroErrorCounts ||\n /\\berrors?\\b/.test(loweredForFailureCounts) ||\n /\\b[a-z]+error\\b/.test(loweredForFailureCounts) ||\n /\\b[a-z]+exception\\b/.test(loweredForFailureCounts);\n\n if (hasFailureMarkers) return \"failure\";\n if (hasSuccessMarkers) return \"success\";\n }\n return \"unknown\";\n}\n\nfunction isProcessTool(toolName: string | undefined, args: Record<string, unknown> | undefined): boolean {\n const tokens = toolNameTokens(toolName);\n const normalizedName = normalizedToolName(toolName);\n if (pickString(args, [\"cmd\", \"command\", \"script\"])) return true;\n return [\"exec\", \"shell\", \"bash\", \"terminal\", \"run_command\", \"exec_command\"].some((token) =>\n token.includes(\"_\") ? normalizedName === token : tokens.includes(token),\n );\n}\n\nfunction isFileTool(toolName: string | undefined, args: Record<string, unknown> | undefined): boolean {\n const tokens = toolNameTokens(toolName);\n const fileScope = fileScopeFromArgs(args);\n if (fileScope.scope) return true;\n return [\"file\", \"path\", \"patch\", \"directory\", \"mkdir\", \"rename\", \"move\"].some((token) =>\n tokens.includes(token),\n );\n}\n\nfunction inferFileChangeKind(toolName: string | undefined, outcome: ObjectiveStateOutcome): ObjectiveStateChangeKind {\n if (outcome === \"failure\") return \"failed\";\n const tokens = toolNameTokens(toolName);\n if ([\"delete\", \"remove\", \"unlink\"].some((token) => tokens.includes(token))) return \"deleted\";\n if ([\"create\", \"mkdir\", \"new\"].some((token) => tokens.includes(token))) return \"created\";\n if ([\"write\", \"edit\", \"patch\", \"update\", \"append\", \"move\", \"rename\"].some((token) => tokens.includes(token))) {\n return \"updated\";\n }\n return \"observed\";\n}\n\nfunction buildFileValueRefs(\n args: Record<string, unknown> | undefined,\n changeKind: ObjectiveStateChangeKind,\n): Pick<ObjectiveStateSnapshot, \"before\" | \"after\"> {\n const { sourcePath, destinationPath, scope } = fileScopeFromArgs(args);\n const contentHash = fileContentHash(args);\n\n if (changeKind === \"failed\") {\n if (sourcePath && destinationPath && sourcePath !== destinationPath) {\n return {\n before: { ref: sourcePath },\n after: { ref: destinationPath },\n };\n }\n return {\n before: sourcePath ? { ref: sourcePath } : undefined,\n after: scope ? { ref: scope } : undefined,\n };\n }\n\n if (changeKind === \"deleted\") {\n return {\n before: scope ? { exists: true, ref: scope } : undefined,\n after: { exists: false },\n };\n }\n\n if (changeKind === \"created\") {\n return {\n after: {\n exists: true,\n ref: scope,\n valueHash: contentHash,\n },\n };\n }\n\n if (sourcePath && destinationPath && sourcePath !== destinationPath) {\n return {\n before: { exists: true, ref: sourcePath },\n after: {\n exists: true,\n ref: destinationPath,\n },\n };\n }\n\n return {\n after: {\n exists: true,\n ref: scope,\n valueHash: contentHash,\n },\n };\n}\n\nfunction summarizeSnapshot(\n kind: ObjectiveStateSnapshot[\"kind\"],\n changeKind: ObjectiveStateChangeKind,\n toolName: string,\n scope: string,\n): string {\n const action =\n changeKind === \"executed\"\n ? \"Executed\"\n : changeKind === \"failed\"\n ? \"Failed\"\n : changeKind === \"created\"\n ? \"Created\"\n : changeKind === \"deleted\"\n ? \"Deleted\"\n : changeKind === \"updated\"\n ? \"Updated\"\n : \"Observed\";\n if (kind === \"process\") return `${action} process via ${toolName}: ${scope}`;\n if (kind === \"file\") return `${action} file via ${toolName}: ${scope}`;\n return `${action} tool result from ${toolName}: ${scope}`;\n}\n\nfunction buildGenericToolAfterRef(outcome: ObjectiveStateOutcome, parsedPayload: unknown): ObjectiveStateSnapshot[\"after\"] {\n const valueHash = resultHash(parsedPayload);\n return valueHash ? { valueHash } : { exists: outcome !== \"failure\" };\n}\n\nfunction snapshotIdFor(\n sessionKey: string,\n recordedAt: string,\n index: number,\n toolName: string,\n scope: string,\n stableKey?: string,\n): string {\n const digest = crypto\n .createHash(\"sha256\")\n .update(\n stableKey\n ? `${sessionKey}|${recordedAt}|${index}|${toolName}|${scope}|stable|${stableKey}`\n : `${sessionKey}|${recordedAt}|${index}|${toolName}|${scope}`,\n )\n .digest(\"hex\")\n .slice(0, 12);\n return `obj-${digest}`;\n}\n\nfunction objectiveStatePartsForObservedMessage(\n message: ObservedMessageWithParts,\n): LcmMessagePartInput[] {\n if (message.role === \"user\") {\n const explicitParts = Array.isArray(message.parts) && message.parts.length > 0\n ? sanitizeUserRoleToolResultParts(message.parts)\n : [];\n if (Array.isArray(message.parts) && message.parts.length > 0) {\n const rawParts = userRawToolResultParts(message);\n return mergeObservedEvidenceParts(explicitParts, rawParts);\n }\n return userRawToolResultParts(message);\n }\n if (message.role !== \"assistant\") {\n return [];\n }\n const explicitParts = Array.isArray(message.parts) && message.parts.length > 0\n ? message.parts\n : [];\n const rawParts = assistantRawObjectiveStateParts(message);\n return mergeObservedEvidenceParts(explicitParts, rawParts);\n}\n\nfunction userRawToolResultParts(message: ObservedMessageWithParts): LcmMessagePartInput[] {\n const rawContent = message.rawContent ?? message.content;\n if (!containsProviderToolResultBlock(rawContent)) {\n return [];\n }\n return markRawProviderParts(\n sanitizeUserRoleToolResultParts(parseMessageParts(rawContent, {\n sourceFormat: message.sourceFormat,\n allowRenderedFallback: false,\n })),\n );\n}\n\nfunction assistantRawObjectiveStateParts(message: ObservedMessageWithParts): LcmMessagePartInput[] {\n if (message.rawContent === undefined || message.rawContent === null) {\n return [];\n }\n return markRawProviderParts(parseMessageParts(message.rawContent, {\n sourceFormat: message.sourceFormat,\n allowRenderedFallback: false,\n }));\n}\n\nfunction mergeObservedEvidenceParts(\n explicitParts: LcmMessagePartInput[],\n rawParts: LcmMessagePartInput[],\n): LcmMessagePartInput[] {\n if (explicitParts.length === 0) return rawParts;\n if (rawParts.length === 0) return explicitParts;\n\n const merged = [...explicitParts];\n const seen = new Set(\n explicitParts\n .filter(isObjectiveStateEvidencePart)\n .map(objectiveStateEvidencePartKey),\n );\n\n for (const part of rawParts) {\n if (!isObjectiveStateEvidencePart(part)) continue;\n const key = objectiveStateEvidencePartKey(part);\n if (seen.has(key)) continue;\n seen.add(key);\n merged.push(part);\n }\n\n return merged;\n}\n\nfunction isObjectiveStateEvidencePart(part: LcmMessagePartInput): boolean {\n return (\n part.kind === \"tool_call\" ||\n part.kind === \"tool_result\" ||\n part.kind === \"file_write\" ||\n part.kind === \"patch\"\n );\n}\n\nfunction objectiveStateEvidencePartKey(part: LcmMessagePartInput): string {\n const id = partToolCallId(part);\n if (id) return `${part.kind}:id:${id}`;\n const toolName = partToolName(part) ?? \"\";\n const filePath = partFilePath(part) ?? \"\";\n return `${part.kind}:shape:${toolName}:${filePath}:${stableStringify(partPayload(part))}`;\n}\n\nfunction flattenObservedParts(messages: readonly ObservedMessageWithParts[]): ObservedPartEntry[] {\n const entries: ObservedPartEntry[] = [];\n messages.forEach((message, messageIndex) => {\n const parts = objectiveStatePartsForObservedMessage(message);\n parts.forEach((part, partIndex) => {\n entries.push({ messageIndex, partIndex, part });\n });\n });\n return entries.sort((a, b) => {\n if (a.messageIndex !== b.messageIndex) return a.messageIndex - b.messageIndex;\n const aOrdinal = typeof a.part.ordinal === \"number\" ? a.part.ordinal : a.partIndex;\n const bOrdinal = typeof b.part.ordinal === \"number\" ? b.part.ordinal : b.partIndex;\n if (aOrdinal !== bOrdinal) return aOrdinal - bOrdinal;\n return a.partIndex - b.partIndex;\n });\n}\n\nfunction sanitizeUserRoleToolResultParts(parts: LcmMessagePartInput[]): LcmMessagePartInput[] {\n return parts\n .filter((part) => part.kind === \"tool_result\")\n .map((part) => {\n const payload = { ...partPayload(part) };\n delete payload.name;\n delete payload.tool;\n delete payload.toolName;\n delete payload.tool_name;\n return {\n ...part,\n toolName: null,\n tool_name: null,\n payload,\n };\n });\n}\n\nfunction containsProviderToolResultBlock(value: unknown): boolean {\n if (Array.isArray(value)) {\n return value.some(containsProviderToolResultBlock);\n }\n if (!isRecord(value)) return false;\n const type = optionalString(value.type ?? value.kind);\n if (\n type === \"tool_result\" ||\n type === \"function_call_output\"\n ) {\n return true;\n }\n return (\n containsProviderToolResultBlock(value.content) ||\n containsProviderToolResultBlock(value.output) ||\n containsProviderToolResultBlock(value.items)\n );\n}\n\nfunction partPayload(part: LcmMessagePartInput): Record<string, unknown> {\n return isRecord(part.payload) ? part.payload : {};\n}\n\nfunction partToolCallId(part: LcmMessagePartInput): string | undefined {\n const payload = partPayload(part);\n return (\n optionalString(payload.call_id) ??\n optionalString(payload.callId) ??\n optionalString(payload.id) ??\n optionalString(payload.tool_call_id) ??\n optionalString(payload.toolCallId) ??\n optionalString(payload.tool_use_id) ??\n optionalString(payload.toolUseId)\n );\n}\n\nfunction partToolName(part: LcmMessagePartInput): string | undefined {\n const payload = partPayload(part);\n return (\n optionalString(part.toolName) ??\n optionalString(part.tool_name) ??\n optionalString(payload.name) ??\n optionalString(payload.toolName) ??\n optionalString(payload.tool_name) ??\n (part.kind === \"patch\" ? \"apply_patch\" : undefined) ??\n (part.kind === \"file_write\" ? \"file_write\" : undefined)\n );\n}\n\nfunction partFilePath(part: LcmMessagePartInput): string | undefined {\n const payload = partPayload(part);\n return (\n optionalString(part.filePath) ??\n optionalString(part.file_path) ??\n optionalString(payload.path) ??\n optionalString(payload.filePath) ??\n optionalString(payload.file_path)\n );\n}\n\nfunction syntheticPartId(options: {\n sessionKey: string;\n messageIndex: number;\n partIndex: number;\n part: LcmMessagePartInput;\n}): string {\n const digest = hashSha256(\n [\n options.sessionKey,\n String(options.messageIndex),\n String(options.part.ordinal ?? options.partIndex),\n options.part.kind,\n optionalString(options.part.toolName) ?? \"\",\n optionalString(options.part.tool_name) ?? \"\",\n optionalString(options.part.filePath) ?? \"\",\n optionalString(options.part.file_path) ?? \"\",\n stableStringify(options.part.payload),\n ].join(\"|\"),\n ).slice(0, 12);\n return `part-${digest}`;\n}\n\nfunction toolArgumentsFromPart(part: LcmMessagePartInput): Record<string, unknown> {\n const payload = partPayload(part);\n const parsedArgs =\n parseToolArguments(payload.arguments) ??\n parseToolArguments(payload.input) ??\n parseToolArguments(payload.args) ??\n parseToolArguments(payload.params) ??\n payload;\n const args = { ...parsedArgs };\n const filePath = partFilePath(part);\n if (filePath && !pickString(args, [\"path\", \"filePath\", \"file_path\"])) {\n args.path = filePath;\n }\n if (part.kind === \"patch\" && !pickString(args, [\"patch\", \"diff\", \"text\"])) {\n const text = optionalString(payload.text) ?? optionalString(payload.patch);\n if (text) args.patch = text;\n }\n return args;\n}\n\nfunction toolResultContentFromPart(part: LcmMessagePartInput): unknown {\n const payload = partPayload(part);\n if (\"output\" in payload) return payload.output;\n if (\"content\" in payload) return payload.content;\n if (\"result\" in payload) return payload.result;\n if (\"value\" in payload) return payload.value;\n return payload;\n}\n\nfunction inlineToolResultContentFromPart(part: LcmMessagePartInput): unknown {\n const payload = partPayload(part);\n if (hasDefinedPayloadKey(payload, \"output\")) return payload.output;\n if (hasDefinedPayloadKey(payload, \"result\")) return payload.result;\n if (part.kind === \"tool_result\" && hasDefinedPayloadKey(payload, \"value\")) {\n return payload.value;\n }\n\n const statusPayload: Record<string, unknown> = {};\n for (const key of [\"exitCode\", \"ok\", \"success\", \"error\", \"stdout\", \"stderr\"]) {\n if (hasDefinedPayloadKey(payload, key)) {\n statusPayload[key] = payload[key];\n }\n }\n return Object.keys(statusPayload).length > 0 ? statusPayload : payload;\n}\n\nfunction hasDefinedPayloadKey(payload: Record<string, unknown>, key: string): boolean {\n return Object.prototype.hasOwnProperty.call(payload, key) && payload[key] !== undefined;\n}\n\nfunction partHasInlineToolResult(part: LcmMessagePartInput): boolean {\n const payload = partPayload(part);\n return (\n hasDefinedPayloadKey(payload, \"output\") ||\n hasDefinedPayloadKey(payload, \"result\") ||\n (part.kind === \"tool_result\" && hasDefinedPayloadKey(payload, \"value\")) ||\n hasDefinedPayloadKey(payload, \"exitCode\") ||\n hasDefinedPayloadKey(payload, \"ok\") ||\n hasDefinedPayloadKey(payload, \"success\") ||\n hasDefinedPayloadKey(payload, \"error\") ||\n hasDefinedPayloadKey(payload, \"stdout\") ||\n hasDefinedPayloadKey(payload, \"stderr\")\n );\n}\n\nfunction toolResultIsError(part: LcmMessagePartInput): boolean {\n const payload = partPayload(part);\n return payload.isError === true ||\n payload.is_error === true ||\n payload.ok === false ||\n payload.success === false ||\n optionalString(payload.error) !== undefined;\n}\n\nfunction buildSyntheticAssistantToolCall(\n id: string,\n toolName: string,\n args: Record<string, unknown>,\n): Record<string, unknown> {\n return {\n role: \"assistant\",\n tool_calls: [\n {\n id,\n function: {\n name: toolName,\n arguments: JSON.stringify(args),\n },\n },\n ],\n };\n}\n\nfunction observedPartsToAgentMessages(options: {\n sessionKey: string;\n messages: readonly ObservedMessageWithParts[];\n}): Array<Record<string, unknown>> {\n const entries = flattenObservedParts(options.messages);\n const resultIds = new Set(\n entries\n .filter((entry) => entry.part.kind === \"tool_result\")\n .map((entry) => partToolCallId(entry.part))\n .filter((id): id is string => id !== undefined),\n );\n const synthetic: Array<Record<string, unknown>> = [];\n let pendingIdlessToolCallId: string | undefined;\n\n for (let entryIndex = 0; entryIndex < entries.length; entryIndex += 1) {\n const entry = entries[entryIndex]!;\n const { part } = entry;\n if (\n part.kind === \"tool_call\" ||\n part.kind === \"file_write\" ||\n part.kind === \"patch\"\n ) {\n const toolName = partToolName(part);\n if (!toolName) continue;\n const observedToolCallId = partToolCallId(part);\n const id = observedToolCallId ??\n syntheticPartId({\n sessionKey: options.sessionKey,\n messageIndex: entry.messageIndex,\n partIndex: entry.partIndex,\n part,\n });\n const args = toolArgumentsFromPart(part);\n synthetic.push(buildSyntheticAssistantToolCall(id, toolName, args));\n const nextEntry = entries[entryIndex + 1];\n const nextIsIdlessToolResult =\n nextEntry?.part.kind === \"tool_result\" &&\n partToolCallId(nextEntry.part) === undefined;\n pendingIdlessToolCallId = nextIsIdlessToolResult\n ? id\n : undefined;\n\n const hasSeparateToolResult = resultIds.has(id) || nextIsIdlessToolResult;\n if (partHasInlineToolResult(part) && !hasSeparateToolResult) {\n synthetic.push({\n role: \"tool\",\n tool_call_id: id,\n name: toolName,\n content: inlineToolResultContentFromPart(part),\n ...(toolResultIsError(part) ? { isError: true } : {}),\n });\n pendingIdlessToolCallId = undefined;\n continue;\n }\n\n if (\n (part.kind === \"file_write\" || part.kind === \"patch\") &&\n !nextIsIdlessToolResult &&\n !resultIds.has(id) &&\n !isRawProviderPart(part)\n ) {\n synthetic.push({\n role: \"tool\",\n tool_call_id: id,\n name: toolName,\n content: { ok: true, source: \"message_part\" },\n });\n pendingIdlessToolCallId = undefined;\n }\n continue;\n }\n\n if (part.kind === \"tool_result\") {\n const id = partToolCallId(part) ?? pendingIdlessToolCallId;\n const toolName = partToolName(part);\n synthetic.push({\n role: \"tool\",\n ...(id ? { tool_call_id: id } : {}),\n ...(toolName ? { name: toolName } : {}),\n content: toolResultContentFromPart(part),\n ...(toolResultIsError(part) ? { isError: true } : {}),\n });\n pendingIdlessToolCallId = undefined;\n }\n }\n\n return synthetic;\n}\n\nexport function deriveObjectiveStateSnapshotsFromAgentMessages(options: {\n sessionKey: string;\n recordedAt: string;\n messages: Array<Record<string, unknown>>;\n}): ObjectiveStateSnapshot[] {\n const toolCallsById = getToolCallContexts(options.messages);\n const snapshots: ObjectiveStateSnapshot[] = [];\n\n for (const message of options.messages) {\n if (message.role !== \"tool\") continue;\n const toolCallId = toolCallIdForMessage(message);\n const context = toolCallId ? toolCallsById.get(toolCallId) : undefined;\n const toolName = toolNameForMessage(message, context);\n if (!toolName) continue;\n\n const parsedPayload = parseToolResultPayload(message.content);\n const outcome = inferOutcome(message, parsedPayload);\n const args = context?.args;\n const command = pickString(args, [\"cmd\", \"command\", \"script\"]);\n\n let kind: ObjectiveStateSnapshot[\"kind\"] = \"tool\";\n let changeKind: ObjectiveStateChangeKind = outcome === \"failure\" ? \"failed\" : \"observed\";\n let scope = toolName;\n let before: ObjectiveStateSnapshot[\"before\"];\n let after: ObjectiveStateSnapshot[\"after\"];\n\n if (isProcessTool(toolName, args)) {\n kind = \"process\";\n changeKind = outcome === \"failure\" ? \"failed\" : \"executed\";\n scope = command ?? toolName;\n after = { exists: outcome !== \"failure\", valueHash: resultHash(parsedPayload) };\n } else if (isFileTool(toolName, args)) {\n kind = \"file\";\n changeKind = inferFileChangeKind(toolName, outcome);\n const fileScope = fileScopeFromArgs(args);\n scope = fileScope.scope ?? toolName;\n const refs = buildFileValueRefs(args, changeKind);\n before = refs.before;\n after = refs.after;\n } else {\n after = buildGenericToolAfterRef(outcome, parsedPayload);\n }\n\n snapshots.push({\n schemaVersion: 1,\n snapshotId: snapshotIdFor(\n options.sessionKey,\n options.recordedAt,\n snapshots.length,\n toolName,\n scope,\n toolCallId,\n ),\n recordedAt: options.recordedAt,\n sessionKey: options.sessionKey,\n source: \"tool_result\",\n kind,\n changeKind,\n scope,\n summary: summarizeSnapshot(kind, changeKind, toolName, scope),\n toolName,\n command,\n outcome,\n before,\n after,\n tags: [\"agent-end\", `tool:${toolName}`],\n metadata: toolCallId ? { toolCallId } : undefined,\n });\n }\n\n return snapshots;\n}\n\nexport function deriveObjectiveStateSnapshotsFromObservedMessages(options: {\n sessionKey: string;\n recordedAt: string;\n messages: readonly ObservedMessageWithParts[];\n}): ObjectiveStateSnapshot[] {\n const syntheticMessages = observedPartsToAgentMessages({\n sessionKey: options.sessionKey,\n messages: options.messages,\n });\n if (syntheticMessages.length === 0) return [];\n\n return deriveObjectiveStateSnapshotsFromAgentMessages({\n sessionKey: options.sessionKey,\n recordedAt: options.recordedAt,\n messages: syntheticMessages,\n });\n}\n\nexport async function recordObjectiveStateSnapshotsFromAgentMessages(options: {\n memoryDir: string;\n objectiveStateStoreDir?: string;\n objectiveStateMemoryEnabled: boolean;\n objectiveStateSnapshotWritesEnabled: boolean;\n sessionKey: string;\n recordedAt: string;\n messages: Array<Record<string, unknown>>;\n}): Promise<DerivedObjectiveStateResult> {\n if (!options.objectiveStateMemoryEnabled || !options.objectiveStateSnapshotWritesEnabled) {\n return { snapshots: [], filePaths: [] };\n }\n\n const snapshots = deriveObjectiveStateSnapshotsFromAgentMessages({\n sessionKey: options.sessionKey,\n recordedAt: options.recordedAt,\n messages: options.messages,\n });\n\n const filePaths: string[] = [];\n for (const snapshot of snapshots) {\n filePaths.push(\n await recordObjectiveStateSnapshot({\n memoryDir: options.memoryDir,\n objectiveStateStoreDir: options.objectiveStateStoreDir,\n snapshot,\n }),\n );\n }\n\n return { snapshots, filePaths };\n}\n\nexport async function recordObjectiveStateSnapshotsFromObservedMessages(options: {\n memoryDir: string;\n objectiveStateStoreDir?: string;\n objectiveStateMemoryEnabled: boolean;\n objectiveStateSnapshotWritesEnabled: boolean;\n sessionKey: string;\n recordedAt: string;\n messages: readonly ObservedMessageWithParts[];\n}): Promise<DerivedObjectiveStateResult> {\n if (!options.objectiveStateMemoryEnabled || !options.objectiveStateSnapshotWritesEnabled) {\n return { snapshots: [], filePaths: [] };\n }\n\n const snapshots = deriveObjectiveStateSnapshotsFromObservedMessages({\n sessionKey: options.sessionKey,\n recordedAt: options.recordedAt,\n messages: options.messages,\n });\n\n const filePaths: string[] = [];\n for (const snapshot of snapshots) {\n filePaths.push(\n await recordObjectiveStateSnapshot({\n memoryDir: options.memoryDir,\n objectiveStateStoreDir: options.objecti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C,cAAU;AAAA,MACR,MAAM,6BAA6B;AAAA,QACjC,WAAW,QAAQ;AAAA,QACnB,wBAAwB,QAAQ;AAAA,QAChC;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO,EAAE,WAAW,UAAU;AAChC;","names":["explicitParts","rawParts"]}
@@ -7,7 +7,7 @@ import {
7
7
  import {
8
8
  NamespaceStorageRouter,
9
9
  namespaceCollectionName
10
- } from "./chunk-OWGGXPKV.js";
10
+ } from "./chunk-57QNCUEZ.js";
11
11
  import {
12
12
  analyzeSessionIntegrity,
13
13
  applySessionRepair,
@@ -37,7 +37,7 @@ import {
37
37
  import {
38
38
  listMemoryGovernanceRuns,
39
39
  readMemoryGovernanceRunArtifact
40
- } from "./chunk-U4SZXGEO.js";
40
+ } from "./chunk-EYNQTST2.js";
41
41
  import {
42
42
  isSafeRouteNamespace
43
43
  } from "./chunk-2LGMW3DJ.js";
@@ -46,7 +46,7 @@ import {
46
46
  } from "./chunk-RK2Y4XOM.js";
47
47
  import {
48
48
  StorageManager
49
- } from "./chunk-MJLUHRSF.js";
49
+ } from "./chunk-MCC6KDQF.js";
50
50
  import {
51
51
  lintWorkspaceFiles
52
52
  } from "./chunk-DM2T26WE.js";
@@ -1448,4 +1448,4 @@ export {
1448
1448
  runBenchmarkRecall,
1449
1449
  runOperatorRepair
1450
1450
  };
1451
- //# sourceMappingURL=chunk-M3DK45UM.js.map
1451
+ //# sourceMappingURL=chunk-I6BQZSML.js.map
@@ -0,0 +1,446 @@
1
+ // src/message-parts/index.ts
2
+ var LCM_MESSAGE_PART_KINDS = [
3
+ "text",
4
+ "tool_call",
5
+ "tool_result",
6
+ "patch",
7
+ "file_read",
8
+ "file_write",
9
+ "step_start",
10
+ "step_finish",
11
+ "snapshot",
12
+ "retry"
13
+ ];
14
+ var SECRET_KEY_RE = /(api[_-]?key|authorization|bearer|credential|password|secret|token)/i;
15
+ var MAX_PAYLOAD_STRING = 8e3;
16
+ var MAX_FILE_SCAN_CHARS = 2e4;
17
+ function isLcmMessagePartKind(value) {
18
+ return typeof value === "string" && LCM_MESSAGE_PART_KINDS.includes(value);
19
+ }
20
+ function parseMessageParts(input, options = {}) {
21
+ const explicit = normalizeExplicitParts(input);
22
+ if (explicit.length > 0) return explicit;
23
+ const format = options.sourceFormat ?? inferSourceFormat(input);
24
+ switch (format) {
25
+ case "openai":
26
+ return withRenderedFallback(parseOpenAiMessageParts(input, options), options);
27
+ case "anthropic":
28
+ return withRenderedFallback(parseAnthropicMessageParts(input, options), options);
29
+ case "openclaw":
30
+ return withRenderedFallback(parseOpenClawMessageParts(input, options), options);
31
+ case "lossless-claw":
32
+ case "remnic":
33
+ return withRenderedFallback(normalizeExplicitParts(input), options);
34
+ default:
35
+ return renderedFallbackParts(options);
36
+ }
37
+ }
38
+ function normalizeExplicitParts(input) {
39
+ const rawParts = pickArray(input, "parts") ?? pickArray(input, "message_parts");
40
+ if (!rawParts) return [];
41
+ const parts = [];
42
+ rawParts.forEach((raw, index) => {
43
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return;
44
+ const obj = raw;
45
+ const kind = normalizeKind(obj.kind ?? obj.type);
46
+ if (!kind) return;
47
+ const payload = obj.payload && typeof obj.payload === "object" && !Array.isArray(obj.payload) ? obj.payload : { value: sanitizePayload(obj) };
48
+ const toolName = asNonEmptyString(obj.toolName ?? obj.tool_name ?? obj.name);
49
+ const filePath = asNonEmptyString(obj.filePath ?? obj.file_path ?? obj.path);
50
+ const ordinal = typeof obj.ordinal === "number" && Number.isInteger(obj.ordinal) ? Math.max(0, obj.ordinal) : index;
51
+ parts.push({
52
+ ordinal,
53
+ kind,
54
+ payload: sanitizePayload(payload),
55
+ toolName,
56
+ filePath,
57
+ createdAt: asNonEmptyString(obj.createdAt ?? obj.created_at)
58
+ });
59
+ });
60
+ return parts;
61
+ }
62
+ function parseOpenAiMessageParts(input, _options = {}) {
63
+ const items = gatherOpenAiItems(input);
64
+ const parts = [];
65
+ for (const item of items) {
66
+ const type = asNonEmptyString(item.type) ?? asNonEmptyString(item.kind);
67
+ if (!type) continue;
68
+ if (isOpenAiContentBlock(item)) {
69
+ const text = asNonEmptyString(item.text ?? item.content);
70
+ if (text) parts.push(makePart("text", { type, text }, { filePath: firstFilePath(text) }));
71
+ continue;
72
+ }
73
+ if (type === "message") {
74
+ for (const block of gatherContentBlocks(item.content)) {
75
+ const text = asNonEmptyString(block.text ?? block.content);
76
+ if (text) parts.push(makePart("text", { type, text }, { filePath: firstFilePath(text) }));
77
+ }
78
+ continue;
79
+ }
80
+ if (type === "function_call") {
81
+ const toolName = asNonEmptyString(item.name ?? item.tool_name);
82
+ const callId = asNonEmptyString(item.call_id ?? item.callId);
83
+ const itemId = asNonEmptyString(item.id);
84
+ const payload = {
85
+ id: callId ?? itemId,
86
+ ...callId ? { call_id: callId } : {},
87
+ ...itemId && itemId !== callId ? { response_item_id: itemId } : {},
88
+ name: toolName,
89
+ arguments: parseMaybeJson(item.arguments)
90
+ };
91
+ parts.push(classifyToolPart(toolName, payload));
92
+ continue;
93
+ }
94
+ if (type === "function_call_output") {
95
+ const output = asNonEmptyString(item.output) ?? JSON.stringify(sanitizePayload(item.output ?? item));
96
+ const callId = asNonEmptyString(item.call_id ?? item.callId);
97
+ const itemId = asNonEmptyString(item.id);
98
+ parts.push(makePart("tool_result", {
99
+ id: callId ?? itemId,
100
+ ...callId ? { call_id: callId } : {},
101
+ ...itemId && itemId !== callId ? { response_item_id: itemId } : {},
102
+ output
103
+ }, {
104
+ filePath: firstFilePath(output)
105
+ }));
106
+ continue;
107
+ }
108
+ if (type === "reasoning") {
109
+ parts.push(makePart("step_start", { type, summary: sanitizePayload(item.summary ?? item) }));
110
+ continue;
111
+ }
112
+ if (type === "retry") {
113
+ parts.push(makePart("retry", { type, item: sanitizePayload(item) }));
114
+ }
115
+ }
116
+ return withOrdinals(parts);
117
+ }
118
+ function parseAnthropicMessageParts(input, _options = {}) {
119
+ const blocks = gatherContentBlocks(
120
+ Array.isArray(input) ? input : input && typeof input === "object" ? input.content : input
121
+ );
122
+ const parts = [];
123
+ for (const block of blocks) {
124
+ const type = asNonEmptyString(block.type);
125
+ if (type === "text") {
126
+ const text = asNonEmptyString(block.text);
127
+ if (text) parts.push(makePart("text", { type, text }, { filePath: firstFilePath(text) }));
128
+ continue;
129
+ }
130
+ if (type === "tool_use") {
131
+ const toolName = asNonEmptyString(block.name);
132
+ parts.push(classifyToolPart(toolName, {
133
+ id: block.id,
134
+ name: toolName,
135
+ input: sanitizePayload(block.input)
136
+ }));
137
+ continue;
138
+ }
139
+ if (type === "tool_result") {
140
+ const content = block.content;
141
+ const rendered = renderUnknownContent(content);
142
+ parts.push(makePart("tool_result", {
143
+ id: block.tool_use_id,
144
+ content: sanitizePayload(content),
145
+ ...typeof block.is_error === "boolean" ? { is_error: block.is_error } : {},
146
+ ...typeof block.isError === "boolean" ? { isError: block.isError } : {}
147
+ }, {
148
+ filePath: firstFilePath(rendered)
149
+ }));
150
+ continue;
151
+ }
152
+ if (type === "thinking") {
153
+ parts.push(makePart("step_start", {
154
+ type,
155
+ thinking: truncateString(asNonEmptyString(block.thinking) ?? ""),
156
+ signature: asNonEmptyString(block.signature)
157
+ }));
158
+ continue;
159
+ }
160
+ if (type === "redacted_thinking") {
161
+ parts.push(makePart("step_finish", { type }));
162
+ }
163
+ }
164
+ return withOrdinals(parts);
165
+ }
166
+ function parseOpenClawMessageParts(input, options = {}) {
167
+ const explicit = normalizeExplicitParts(input);
168
+ if (explicit.length > 0) return explicit;
169
+ if (!input || typeof input !== "object") return [];
170
+ const obj = input;
171
+ const content = obj.content;
172
+ if (Array.isArray(content)) {
173
+ const hasOpenAiBlocks = content.some(isOpenAiContentBlock);
174
+ if (hasOpenAiBlocks) return parseOpenAiMessageParts(content, options);
175
+ const hasAnthropicBlocks = content.some(
176
+ (block) => block && typeof block === "object" && typeof block.type === "string"
177
+ );
178
+ if (hasAnthropicBlocks) return parseAnthropicMessageParts({ content }, options);
179
+ }
180
+ const toolName = asNonEmptyString(obj.toolName ?? obj.tool_name ?? obj.name);
181
+ if (toolName) {
182
+ return withOrdinals([
183
+ classifyToolPart(toolName, {
184
+ name: toolName,
185
+ input: sanitizePayload(obj.input ?? obj.arguments ?? obj.params),
186
+ output: sanitizePayload(obj.output ?? obj.result)
187
+ })
188
+ ]);
189
+ }
190
+ const rendered = options.allowRenderedFallback === false ? null : options.renderedContent ?? asNonEmptyString(obj.content);
191
+ return rendered ? withOrdinals(partsFromRenderedText(rendered)) : [];
192
+ }
193
+ function partsFromRenderedText(text) {
194
+ if (text.includes("*** Begin Patch")) {
195
+ const paths2 = extractFilePaths(text);
196
+ const patchPaths = extractPatchPaths(text);
197
+ return withOrdinals((patchPaths.length > 0 ? patchPaths : paths2).map(
198
+ (filePath) => makePart("patch", { text: truncateString(text) }, { filePath })
199
+ ));
200
+ }
201
+ const paths = extractFilePaths(text);
202
+ if (paths.length === 0) return [];
203
+ return withOrdinals(paths.map(
204
+ (filePath) => makePart("file_read", { text: truncateString(text) }, { filePath })
205
+ ));
206
+ }
207
+ function inferSourceFormat(input) {
208
+ if (input && typeof input === "object") {
209
+ const obj = input;
210
+ const explicit = asNonEmptyString(obj.sourceFormat ?? obj.source_format);
211
+ if (explicit === "openai" || explicit === "anthropic" || explicit === "openclaw" || explicit === "lossless-claw" || explicit === "remnic") {
212
+ return explicit;
213
+ }
214
+ if (Array.isArray(obj.output)) return "openai";
215
+ if (isOpenAiResponseItem(obj)) return "openai";
216
+ if (Array.isArray(obj.content) && obj.content.some(isOpenAiContentBlock)) return "openai";
217
+ if (Array.isArray(obj.content)) return "anthropic";
218
+ }
219
+ if (Array.isArray(input)) {
220
+ return input.some(
221
+ (item) => isRecord(item) && (isOpenAiResponseItem(item) || isOpenAiContentBlock(item))
222
+ ) ? "openai" : "anthropic";
223
+ }
224
+ return void 0;
225
+ }
226
+ function isOpenAiResponseItem(obj) {
227
+ const type = asNonEmptyString(obj.type ?? obj.kind);
228
+ return type === "message" || type === "function_call" || type === "function_call_output" || type === "reasoning" || type === "retry";
229
+ }
230
+ function isOpenAiContentBlock(value) {
231
+ if (!isRecord(value)) return false;
232
+ const type = asNonEmptyString(value.type);
233
+ return type === "input_text" || type === "output_text" || type === "input_image" || type === "input_file" || type === "refusal";
234
+ }
235
+ function gatherOpenAiItems(input) {
236
+ if (Array.isArray(input)) return input.filter(isRecord);
237
+ if (!isRecord(input)) return [];
238
+ if (Array.isArray(input.output)) return input.output.filter(isRecord);
239
+ if (Array.isArray(input.items)) return input.items.filter(isRecord);
240
+ return [input];
241
+ }
242
+ function gatherContentBlocks(input) {
243
+ if (Array.isArray(input)) return input.filter(isRecord);
244
+ if (typeof input === "string") return [{ type: "text", text: input }];
245
+ if (isRecord(input)) return [input];
246
+ return [];
247
+ }
248
+ function classifyToolPart(toolName, payload) {
249
+ const normalized = (toolName ?? "").toLowerCase();
250
+ const rendered = renderUnknownContent(payload);
251
+ const filePath = firstFilePathFromObject(payload) ?? firstFilePath(rendered) ?? null;
252
+ if (normalized.includes("apply_patch") || rendered.includes("*** Begin Patch")) {
253
+ return makePart("patch", payload, { toolName, filePath: filePath ?? extractPatchPaths(rendered)[0] ?? null });
254
+ }
255
+ if (/(write|edit|multiedit|create|save)/i.test(normalized)) {
256
+ return makePart("file_write", payload, { toolName, filePath });
257
+ }
258
+ if (/(read|grep|glob|search|list|ls)/i.test(normalized)) {
259
+ return makePart("file_read", payload, { toolName, filePath });
260
+ }
261
+ return makePart("tool_call", payload, { toolName, filePath });
262
+ }
263
+ function makePart(kind, payload, options = {}) {
264
+ return {
265
+ kind,
266
+ payload: sanitizePayload(payload),
267
+ toolName: options.toolName ?? null,
268
+ filePath: options.filePath ?? null
269
+ };
270
+ }
271
+ function withOrdinals(parts) {
272
+ return parts.map((part, ordinal) => ({ ...part, ordinal: part.ordinal ?? ordinal }));
273
+ }
274
+ function withRenderedFallback(parts, options) {
275
+ return parts.length > 0 ? parts : renderedFallbackParts(options);
276
+ }
277
+ function renderedFallbackParts(options) {
278
+ if (options.allowRenderedFallback === false) {
279
+ return [];
280
+ }
281
+ const rendered = asNonEmptyString(options.renderedContent);
282
+ return rendered ? partsFromRenderedText(rendered) : [];
283
+ }
284
+ function normalizeKind(value) {
285
+ if (isLcmMessagePartKind(value)) return value;
286
+ if (value === "tool_use" || value === "function_call") return "tool_call";
287
+ if (value === "function_call_output") return "tool_result";
288
+ if (value === "thinking" || value === "reasoning") return "step_start";
289
+ return null;
290
+ }
291
+ function pickArray(input, key) {
292
+ if (!input || typeof input !== "object" || Array.isArray(input)) return null;
293
+ const value = input[key];
294
+ return Array.isArray(value) ? value : null;
295
+ }
296
+ function asNonEmptyString(value) {
297
+ if (typeof value !== "string") return null;
298
+ const trimmed = value.trim();
299
+ return trimmed.length > 0 ? trimmed : null;
300
+ }
301
+ function isRecord(value) {
302
+ return !!value && typeof value === "object" && !Array.isArray(value);
303
+ }
304
+ function parseMaybeJson(value) {
305
+ if (typeof value !== "string") return sanitizePayload(value);
306
+ try {
307
+ return sanitizePayload(JSON.parse(value));
308
+ } catch {
309
+ return truncateString(value);
310
+ }
311
+ }
312
+ function sanitizePayload(value, depth = 0) {
313
+ if (value === null || value === void 0) return value;
314
+ if (typeof value === "string") return truncateString(value);
315
+ if (typeof value === "number" || typeof value === "boolean") return value;
316
+ if (Array.isArray(value)) {
317
+ if (depth >= 4) return "[truncated]";
318
+ return value.slice(0, 100).map((item) => sanitizePayload(item, depth + 1));
319
+ }
320
+ if (typeof value === "object") {
321
+ if (depth >= 4) return "[truncated]";
322
+ const out = {};
323
+ for (const [key, child] of Object.entries(value)) {
324
+ out[key] = SECRET_KEY_RE.test(key) ? "[redacted]" : sanitizePayload(child, depth + 1);
325
+ }
326
+ return out;
327
+ }
328
+ return String(value);
329
+ }
330
+ function truncateString(value) {
331
+ return value.length > MAX_PAYLOAD_STRING ? `${value.slice(0, MAX_PAYLOAD_STRING)}...[truncated]` : value;
332
+ }
333
+ function renderUnknownContent(value) {
334
+ if (typeof value === "string") return value;
335
+ try {
336
+ return JSON.stringify(value ?? "");
337
+ } catch {
338
+ return String(value ?? "");
339
+ }
340
+ }
341
+ function firstFilePathFromObject(value) {
342
+ if (!isRecord(value)) return null;
343
+ const keys = ["file_path", "filePath", "path", "filename", "cwd"];
344
+ for (const key of keys) {
345
+ const candidate = asNonEmptyString(value[key]);
346
+ if (candidate) return candidate;
347
+ }
348
+ for (const child of Object.values(value)) {
349
+ if (typeof child === "string") {
350
+ const fromText = extractPatchPaths(child)[0] ?? firstFilePath(child);
351
+ if (fromText) return fromText;
352
+ }
353
+ if (isRecord(child)) {
354
+ const nested = firstFilePathFromObject(child);
355
+ if (nested) return nested;
356
+ }
357
+ }
358
+ return null;
359
+ }
360
+ function firstFilePath(text) {
361
+ return extractFilePaths(text)[0] ?? null;
362
+ }
363
+ function extractFilePaths(text) {
364
+ const out = /* @__PURE__ */ new Set();
365
+ let token = "";
366
+ const scanLength = Math.min(text.length, MAX_FILE_SCAN_CHARS);
367
+ for (let index = 0; index <= scanLength; index += 1) {
368
+ const char = index < scanLength ? text[index] : " ";
369
+ if (isFilePathTokenSeparator(char)) {
370
+ addFilePathCandidate(out, token);
371
+ token = "";
372
+ continue;
373
+ }
374
+ token += char;
375
+ if (token.length > 512) {
376
+ addFilePathCandidate(out, token);
377
+ token = "";
378
+ }
379
+ }
380
+ return [...out].slice(0, 20);
381
+ }
382
+ function isFilePathTokenSeparator(char) {
383
+ return char === " " || char === "\n" || char === "\r" || char === " " || char === '"' || char === "'" || char === "`" || char === "(" || char === ")" || char === "[" || char === "]" || char === "{" || char === "}" || char === "<" || char === ">" || char === ",";
384
+ }
385
+ function addFilePathCandidate(out, raw) {
386
+ const candidate = trimFilePathPunctuation(raw);
387
+ if (candidate.length === 0 || candidate.includes("://")) return;
388
+ if (isLikelyFilePath(candidate)) out.add(candidate);
389
+ }
390
+ function trimFilePathPunctuation(raw) {
391
+ let start = 0;
392
+ let end = raw.length;
393
+ while (start < end && isLeadingFilePathPunctuation(raw[start])) start += 1;
394
+ while (end > start && isTrailingFilePathPunctuation(raw[end - 1])) end -= 1;
395
+ return raw.slice(start, end);
396
+ }
397
+ function isLeadingFilePathPunctuation(char) {
398
+ return char === ":" || char === ";" || char === "!" || char === "?" || char === "|" || char === "*" || char === "=";
399
+ }
400
+ function isTrailingFilePathPunctuation(char) {
401
+ return char === "." || char === ":" || char === ";" || char === "!" || char === "?" || char === "|" || char === "*" || char === "=";
402
+ }
403
+ function isLikelyFilePath(value) {
404
+ if (value.startsWith("/") || value.startsWith("./") || value.startsWith("../") || value.startsWith("~/")) {
405
+ return hasValidFileExtension(value);
406
+ }
407
+ if (value.includes("/")) return hasValidFileExtension(value);
408
+ return hasValidFileExtension(value);
409
+ }
410
+ function hasValidFileExtension(value) {
411
+ const lastSlash = value.lastIndexOf("/");
412
+ const basename = value.slice(lastSlash + 1);
413
+ const dot = basename.lastIndexOf(".");
414
+ if (dot <= 0 || dot === basename.length - 1) return false;
415
+ const ext = basename.slice(dot + 1);
416
+ if (ext.length < 1 || ext.length > 12) return false;
417
+ for (const char of ext) {
418
+ if (!isFileExtensionChar(char)) return false;
419
+ }
420
+ return true;
421
+ }
422
+ function isFileExtensionChar(char) {
423
+ const code = char.charCodeAt(0);
424
+ return code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122 || char === "_" || char === "+" || char === "-";
425
+ }
426
+ function extractPatchPaths(text) {
427
+ const out = /* @__PURE__ */ new Set();
428
+ for (const line of text.split(/\r?\n/)) {
429
+ const match = line.match(/^\*\*\* (?:Add|Update|Delete) File: (.+)$/);
430
+ if (match?.[1]) out.add(match[1].trim());
431
+ const move = line.match(/^\*\*\* Move to: (.+)$/);
432
+ if (move?.[1]) out.add(move[1].trim());
433
+ }
434
+ return [...out].slice(0, 20);
435
+ }
436
+
437
+ export {
438
+ isLcmMessagePartKind,
439
+ parseMessageParts,
440
+ normalizeExplicitParts,
441
+ parseOpenAiMessageParts,
442
+ parseAnthropicMessageParts,
443
+ parseOpenClawMessageParts,
444
+ partsFromRenderedText
445
+ };
446
+ //# sourceMappingURL=chunk-IBX3VFOM.js.map