llmz 0.9.0 → 1.0.2

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 (238) hide show
  1. package/DOCS.md +232 -1794
  2. package/ERRORS.md +101 -0
  3. package/README.md +96 -582
  4. package/dist/chat/chat.d.ts +63 -0
  5. package/dist/chat/component.d.ts +31 -0
  6. package/dist/chat/component.default.d.ts +58 -0
  7. package/dist/chat/response.d.ts +15 -0
  8. package/dist/compiler/compiler.d.ts +2 -7
  9. package/dist/compiler/plugins/dynamic-code.d.ts +7 -0
  10. package/dist/compiler/plugins/replace-comment.d.ts +2 -3
  11. package/dist/compiler/plugins/return-async.d.ts +5 -4
  12. package/dist/compiler/plugins/termination.d.ts +8 -0
  13. package/dist/compiler/plugins/tool-resolution.d.ts +4 -0
  14. package/dist/compiler/plugins/variable-extraction.d.ts +2 -8
  15. package/dist/component-CMFoCHyu.cjs +649 -0
  16. package/dist/component-DncqP4fB.js +614 -0
  17. package/dist/context.d.ts +71 -378
  18. package/dist/custom-client-C-WXvLD9.js +1655 -0
  19. package/dist/custom-client-Cgt9_0r1.cjs +1732 -0
  20. package/dist/custom-client.d.ts +12 -2
  21. package/dist/errors/catalog.d.ts +294 -0
  22. package/dist/errors/hooks.d.ts +2 -0
  23. package/dist/errors-C6ppQUZX.cjs +893 -0
  24. package/dist/errors-Crk5P8jo.js +636 -0
  25. package/dist/errors.d.ts +24 -36
  26. package/dist/execute-CiYvPs5Q.js +2061 -0
  27. package/dist/execute-DTTfacsi.cjs +2062 -0
  28. package/dist/{exit-DUM96DN1.cjs → exit-BOtKWPuT.cjs} +38 -28
  29. package/dist/{exit-CDdxDBRT.js → exit-DMPwCSba.js} +37 -27
  30. package/dist/exit.d.ts +19 -16
  31. package/dist/index.cjs +177 -1237
  32. package/dist/index.d.ts +25 -28
  33. package/dist/index.js +137 -1213
  34. package/dist/index.workerd.js +8974 -11145
  35. package/dist/inspect.d.ts +18 -4
  36. package/dist/inspection.d.ts +40 -0
  37. package/dist/native-0bq5ATZM.cjs +212 -0
  38. package/dist/native-n_718Z-T.js +177 -0
  39. package/dist/objects.d.ts +2 -57
  40. package/dist/prompts/native.d.ts +2 -0
  41. package/dist/prompts/prompt.d.ts +10 -101
  42. package/dist/quickjs-variant-21IO97PF.cjs +1080 -0
  43. package/dist/quickjs-variant-CtuGagsb.js +985 -0
  44. package/dist/result.d.ts +30 -861
  45. package/dist/runtime/execute.d.ts +3 -2
  46. package/dist/runtime/execution-activity.d.ts +11 -0
  47. package/dist/runtime/execution-diagnostics.d.ts +11 -0
  48. package/dist/runtime/execution-report.d.ts +51 -0
  49. package/dist/runtime/fixtures/chat.d.ts +8 -0
  50. package/dist/runtime/fixtures/long-search.d.ts +1 -1
  51. package/dist/runtime/fixtures/native-client.d.ts +33 -0
  52. package/dist/runtime/fixtures/protocol-languages.d.ts +1 -1
  53. package/dist/runtime/forced-inspection.d.ts +13 -0
  54. package/dist/runtime/forced-inspection.test.d.ts +1 -0
  55. package/dist/runtime/generate.d.ts +23 -20
  56. package/dist/runtime/generate.test.d.ts +1 -0
  57. package/dist/runtime/hook-provenance.test.d.ts +1 -0
  58. package/dist/runtime/inspection-hook.test.d.ts +1 -0
  59. package/dist/runtime/inspection-values.d.ts +14 -0
  60. package/dist/runtime/inspection-values.test.d.ts +1 -0
  61. package/dist/runtime/interruption-control-flow.test.d.ts +1 -0
  62. package/dist/runtime/interruption-settings.test.d.ts +1 -0
  63. package/dist/runtime/javascript-api.d.ts +62 -0
  64. package/dist/runtime/javascript-api.test.d.ts +1 -0
  65. package/dist/runtime/native-review.test.d.ts +1 -0
  66. package/dist/runtime/native-tools.d.ts +18 -0
  67. package/dist/runtime/native-tools.test.d.ts +1 -0
  68. package/dist/runtime/object-memory.test.d.ts +1 -0
  69. package/dist/runtime/single-tool.test.d.ts +1 -0
  70. package/dist/runtime/think-signal.test.d.ts +1 -0
  71. package/dist/runtime/token-budget.d.ts +22 -0
  72. package/dist/runtime/token-budget.test.d.ts +1 -0
  73. package/dist/runtime/tool-wrapper.d.ts +6 -5
  74. package/dist/runtime/traces.test.d.ts +1 -0
  75. package/dist/runtime/truncation.test.d.ts +1 -0
  76. package/dist/runtime/types.d.ts +47 -31
  77. package/dist/runtime/variable-recovery.test.d.ts +1 -0
  78. package/dist/runtime/vm-context.d.ts +6 -1
  79. package/dist/runtime/worker-completion.test.d.ts +1 -0
  80. package/dist/runtime-names.d.ts +4 -0
  81. package/dist/schema-CXlnbb3n.cjs +68 -0
  82. package/dist/schema-GE4ISPCR.js +45 -0
  83. package/dist/schema.d.ts +10 -0
  84. package/dist/schema.test.d.ts +1 -0
  85. package/dist/session/compactor.d.ts +51 -0
  86. package/dist/session/compactor.test.d.ts +1 -0
  87. package/dist/session/history.d.ts +36 -0
  88. package/dist/session/history.test.d.ts +1 -0
  89. package/dist/session/json.d.ts +3 -0
  90. package/dist/session/json.test.d.ts +1 -0
  91. package/dist/session/memory-codec.d.ts +9 -0
  92. package/dist/session/memory-codec.test.d.ts +1 -0
  93. package/dist/session/memory-render.d.ts +15 -0
  94. package/dist/session/memory-render.test.d.ts +1 -0
  95. package/dist/session/memory.d.ts +112 -0
  96. package/dist/session/memory.test.d.ts +1 -0
  97. package/dist/session/messages.d.ts +19 -0
  98. package/dist/session/messages.test.d.ts +1 -0
  99. package/dist/session/serialization.d.ts +36 -0
  100. package/dist/session/serialization.test.d.ts +1 -0
  101. package/dist/session/session-memory.test.d.ts +1 -0
  102. package/dist/session/session.d.ts +121 -0
  103. package/dist/session/session.test.d.ts +1 -0
  104. package/dist/session/speaker.test.d.ts +1 -0
  105. package/dist/{transcript.d.ts → session/transcript.d.ts} +4 -8
  106. package/dist/session/transcript.test.d.ts +1 -0
  107. package/dist/{tool-Bv8N4IPj.js → tool-DstssiAs.js} +144 -92
  108. package/dist/{tool-Dy6AJpJH.cjs → tool-_wK9hQOb.cjs} +146 -94
  109. package/dist/tool.d.ts +25 -17
  110. package/dist/truncate-BEKbdo3t.js +79 -0
  111. package/dist/truncate-uomAMGPs.cjs +102 -0
  112. package/dist/truncate.d.ts +24 -0
  113. package/dist/truncate.test.d.ts +1 -0
  114. package/dist/types.d.ts +33 -9
  115. package/dist/{typings-3lsqCbkn.cjs → typings-BA_XxAcY.cjs} +38 -193
  116. package/dist/{typings-CrBa7Tyy.js → typings-BEVDvtuk.js} +38 -175
  117. package/dist/typings-formatter.d.ts +1 -1
  118. package/dist/typings.d.ts +3 -0
  119. package/dist/{uniq-BYQ7GWwb.js → uniq-DfUeSNaX.js} +2 -2
  120. package/dist/{uniq-G872RWmE.cjs → uniq-DiXgysNV.cjs} +6 -18
  121. package/dist/{_baseIteratee-P_firB7b.js → utils-BOFzb8Ok.js} +1134 -16
  122. package/dist/{_baseIteratee-CF4qP2a8.cjs → utils-CTlsXvdj.cjs} +1281 -84
  123. package/dist/vm/drivers/node.d.ts +1 -1
  124. package/dist/vm/drivers/quickjs.d.ts +1 -1
  125. package/dist/vm/errors.d.ts +4 -4
  126. package/dist/vm/index.d.ts +3 -4
  127. package/dist/vm/instrument.d.ts +14 -6
  128. package/dist/vm/member-proxy.d.ts +4 -0
  129. package/dist/vm/member-proxy.test.d.ts +1 -0
  130. package/dist/vm/memory.test.d.ts +1 -0
  131. package/dist/vm/return-semantics.test.d.ts +1 -0
  132. package/dist/vm/types.d.ts +20 -3
  133. package/dist/{vm-BLsHw1da.js → vm-C7SfutHn.js} +1187 -180
  134. package/dist/{vm-D6s1zF6M.cjs → vm-gmekHc0i.cjs} +1221 -207
  135. package/package.json +13 -6
  136. package/dist/_baseForOwn-BfWDTL8L.cjs +0 -53
  137. package/dist/_baseForOwn-CFhWe_W6.js +0 -48
  138. package/dist/_getPrototype-CG7Dxrrz.js +0 -6
  139. package/dist/_getPrototype-DQDlNVVM.cjs +0 -10
  140. package/dist/_overArg-C5Hy7oCi.cjs +0 -196
  141. package/dist/_overArg-CRYbj1NH.js +0 -155
  142. package/dist/chat.d.ts +0 -401
  143. package/dist/common-BlRFtdf2.js +0 -807
  144. package/dist/common-BnvrDnIT.cjs +0 -860
  145. package/dist/compiler/plugins/track-tool-calls.d.ts +0 -33
  146. package/dist/compiler-C-OI9sim.cjs +0 -547
  147. package/dist/compiler-CW1VjQsn.js +0 -473
  148. package/dist/component-C6Agl2ns.cjs +0 -73
  149. package/dist/component-DGG7d_Mz.js +0 -44
  150. package/dist/component.d.ts +0 -88
  151. package/dist/component.default.d.ts +0 -278
  152. package/dist/custom-client-ChuZ63zp.js +0 -2658
  153. package/dist/custom-client-DAsGRnYc.cjs +0 -2729
  154. package/dist/dual-modes-DDkoCp3R.js +0 -3006
  155. package/dist/dual-modes-DPXiuvNe.cjs +0 -3090
  156. package/dist/errors-C962uJdS.cjs +0 -220
  157. package/dist/errors-Cg1G0Awu.js +0 -161
  158. package/dist/example-format.d.ts +0 -8
  159. package/dist/example.d.ts +0 -45
  160. package/dist/execute-BWcdv9so.js +0 -1059
  161. package/dist/execute-DM2-7y86.cjs +0 -1060
  162. package/dist/exit-parser.d.ts +0 -39
  163. package/dist/handlers.d.ts +0 -10
  164. package/dist/hoist.d.ts +0 -2
  165. package/dist/isEmpty-BhJRCqIF.js +0 -52
  166. package/dist/isEmpty-LY533Wmh.cjs +0 -57
  167. package/dist/isPlainObject-CSxXVKCk.cjs +0 -56
  168. package/dist/isPlainObject-D39AzPO2.js +0 -51
  169. package/dist/jsx-CIgdGGVs.js +0 -52
  170. package/dist/jsx-owqxrquU.cjs +0 -75
  171. package/dist/jsx.d.ts +0 -11
  172. package/dist/message-stream/index.d.ts +0 -9
  173. package/dist/message-stream/instructions.d.ts +0 -30
  174. package/dist/message-stream/normalizer.d.ts +0 -21
  175. package/dist/message-stream/parser.d.ts +0 -89
  176. package/dist/message-stream/registry.d.ts +0 -14
  177. package/dist/message-stream/replayable.d.ts +0 -27
  178. package/dist/message-stream/response-parser.d.ts +0 -24
  179. package/dist/message-stream/sanitize.d.ts +0 -10
  180. package/dist/message-stream/stream.d.ts +0 -54
  181. package/dist/message-stream/types.d.ts +0 -97
  182. package/dist/message-stream/validator.d.ts +0 -23
  183. package/dist/prompts/chat-mode/protocol.d.ts +0 -2
  184. package/dist/prompts/chat-mode/system.d.ts +0 -2
  185. package/dist/prompts/chat-mode/system.md.d.ts +0 -2
  186. package/dist/prompts/chat-mode/user.d.ts +0 -2
  187. package/dist/prompts/chat-mode/user.md.d.ts +0 -2
  188. package/dist/prompts/code-examples.d.ts +0 -2
  189. package/dist/prompts/common.d.ts +0 -7
  190. package/dist/prompts/dual-modes.d.ts +0 -2
  191. package/dist/prompts/execution-history.d.ts +0 -6
  192. package/dist/prompts/execution-state.d.ts +0 -3
  193. package/dist/prompts/protocol-basics.d.ts +0 -5
  194. package/dist/prompts/protocol.d.ts +0 -31
  195. package/dist/prompts/worker-mode/protocol.d.ts +0 -2
  196. package/dist/prompts/worker-mode/system.d.ts +0 -2
  197. package/dist/prompts/worker-mode/system.md.d.ts +0 -2
  198. package/dist/prompts/worker-mode/user.d.ts +0 -2
  199. package/dist/prompts/worker-mode/user.md.d.ts +0 -2
  200. package/dist/quickjs-variant-BYhMBpwU.js +0 -45
  201. package/dist/quickjs-variant-CsIwTVFC.cjs +0 -56
  202. package/dist/rolldown-runtime-EAsCxrDo.js +0 -14
  203. package/dist/runtime/fixtures/qwen-protocol-failures.d.ts +0 -29
  204. package/dist/runtime/interpret-result.d.ts +0 -22
  205. package/dist/snapshots.d.ts +0 -249
  206. package/dist/stack-traces-BIE_5Xwf.js +0 -21
  207. package/dist/stack-traces-ntw_qhoy.cjs +0 -26
  208. package/dist/truncator-CLkouTCO.cjs +0 -276
  209. package/dist/truncator-DZqEqnpD.js +0 -253
  210. package/dist/truncator.d.ts +0 -118
  211. package/dist/utils-3ESwP3yg.cjs +0 -1075
  212. package/dist/utils-UBeAFeEI.js +0 -950
  213. /package/dist/{citations.d.ts → chat/citations.d.ts} +0 -0
  214. /package/dist/{citations.test.d.ts → chat/citations.test.d.ts} +0 -0
  215. /package/dist/{component.default.test.d.ts → chat/component.default.test.d.ts} +0 -0
  216. /package/dist/{compiler/plugins/track-tool-calls.test.d.ts → chat/component.test.d.ts} +0 -0
  217. /package/dist/{example.test.d.ts → chat/response.test.d.ts} +0 -0
  218. /package/dist/{exit-parser.test.d.ts → compiler/plugins/dynamic-code.test.d.ts} +0 -0
  219. /package/dist/{handlers.test.d.ts → compiler/plugins/tool-resolution.test.d.ts} +0 -0
  220. /package/dist/{hoist.test.d.ts → errors/catalog.test.d.ts} +0 -0
  221. /package/dist/{message-stream/instructions.test.d.ts → exit.test.d.ts} +0 -0
  222. /package/dist/{message-stream/normalizer.test.d.ts → inspection.test.d.ts} +0 -0
  223. /package/dist/{message-stream/parser.test.d.ts → prompts/native.test.d.ts} +0 -0
  224. /package/dist/{message-stream/response-parser.test.d.ts → result.test.d.ts} +0 -0
  225. /package/dist/{message-stream/stream.test.d.ts → runtime/chat-completion.test.d.ts} +0 -0
  226. /package/dist/{message-stream/validator.test.d.ts → runtime/chat-delivery.test.d.ts} +0 -0
  227. /package/dist/{prompts/adherence.test.d.ts → runtime/chat-last-speaker.test.d.ts} +0 -0
  228. /package/dist/{prompts/catalogue-examples.test.d.ts → runtime/compatibility-regressions.test.d.ts} +0 -0
  229. /package/dist/{prompts/code-examples.test.d.ts → runtime/context-registration.test.d.ts} +0 -0
  230. /package/dist/{prompts/common.test.d.ts → runtime/empty-completion.test.d.ts} +0 -0
  231. /package/dist/{prompts/concrete-patterns.test.d.ts → runtime/error-recovery.test.d.ts} +0 -0
  232. /package/dist/{prompts/long-search.test.d.ts → runtime/errors.test.d.ts} +0 -0
  233. /package/dist/{prompts/protocol-simple.test.d.ts → runtime/execution-activity.test.d.ts} +0 -0
  234. /package/dist/{prompts/protocol.test.d.ts → runtime/execution-diagnostics.test.d.ts} +0 -0
  235. /package/dist/{prompts/sections.test.d.ts → runtime/execution-report.test.d.ts} +0 -0
  236. /package/dist/runtime/{interpret-result.test.d.ts → execution-safety.test.d.ts} +0 -0
  237. /package/dist/{transcript.test.d.ts → runtime/exit-control-flow.test.d.ts} +0 -0
  238. /package/dist/{truncator.test.d.ts → runtime/fixtures/long-search.test.d.ts} +0 -0
package/ERRORS.md ADDED
@@ -0,0 +1,101 @@
1
+ # Errors and recovery
2
+
3
+ Every library failure has a stable `code`, a readable `message`, and a `critical` flag. Each class exports a detachable `.is(value)` type guard. `isLLMzError(value, code)` narrows the same discriminated union by code. Guards use a shared `Symbol.for` brand plus the error code, so they work across independently loaded copies of LLMz and after the runtime restores a QuickJS exception. They do not rely on `instanceof`, class names, or message matching.
4
+
5
+ ```ts
6
+ import { ToolInputError, isLLMzError, isCriticalError, type Iteration } from 'llmz'
7
+
8
+ function observe(iteration: Iteration) {
9
+ // Includes tool failures that generated JavaScript caught and handled itself.
10
+ for (const error of iteration.errors) {
11
+ if (ToolInputError.is(error)) {
12
+ console.log(error.toolName, error.issues, error.expectedInput)
13
+ }
14
+ }
15
+
16
+ const error = iteration.exception
17
+ if (isLLMzError(error, 'EXECUTION_FAILED')) {
18
+ // The wrapper retains source location information and the original typed cause.
19
+ console.log(error.source, error.stacktrace)
20
+ if (ToolInputError.is(error.cause)) {
21
+ console.log(error.cause.expectedInput)
22
+ }
23
+ }
24
+
25
+ if (isCriticalError(error)) {
26
+ console.error('Execution cannot continue:', error.code)
27
+ }
28
+ }
29
+ ```
30
+
31
+ Pass `observe` as `onIterationEnd`. `iteration.error` remains the readable string summary; `iteration.exception` is the typed failure that ended the iteration. `iteration.errors` also includes observed tool/component/exit failures and memory retention errors, including failures handled inside generated code. A recovered execution keeps the failed iterations in `result.iterations`; a successful iteration can have errors in its diagnostics without an `exception`.
32
+
33
+ `result.isError()` exposes a typed `result.error`. An exhausted iteration budget is a run-level `LoopExceededError`; the last iteration keeps its original exception, and its `errors` list also receives the limit error. This limit is detected after that iteration's end hook. Configuration failures can occur before an iteration exists. Constructors, `session.append()`, and standalone session operations throw directly to their caller.
34
+
35
+ A **non-critical** iteration failure produces feedback and permits another model call within the remaining iteration budget. It does not promise that retrying an external action is safe. Feedback records acknowledged tool results and deliveries, discloses uncertain effects, and tells the model not to repeat completed actions blindly. The model may correct its arguments, choose another tool, or complete through an appropriate exit.
36
+
37
+ Original schema refinements are enforced for tool inputs, exit payloads, component props, and object-property assignments. Their issues use the corresponding input/property error below. Async effects are supported for tool inputs; using them on synchronous exit, component, or property APIs raises critical `InvalidConfigurationError`. A schema callback that throws instead of reporting a validation issue is also a configuration failure. Tool output schemas are documentation only: unexpected tool return values do not produce schema-validation errors.
38
+
39
+ A **critical** failure stops the execution without another model call. Critical tool failures remain fatal even if generated JavaScript catches them; later host operations are closed. Examples include provider failures, token overflow, failed compaction, cancellation, and memory capacity exhaustion. A hook can reject an iteration with an ordinary error (reported as `HookError`), or stop execution with a critical typed error or its abort controller. Observational callbacks remain observational; `onIterationEnd` propagates explicitly critical failures.
40
+
41
+ ## Complete catalogue
42
+
43
+ “Recoverable” below means the runtime may continue when the failure occurs in an active iteration. Errors thrown by standalone methods are returned to the caller.
44
+
45
+ | Code | Exported class | Handling and details |
46
+ | ------------------------- | --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
47
+ | `INVALID_CODE` | `InvalidCodeError` | Recoverable. Invalid JavaScript or unsupported dynamic code; `source` retains the program. |
48
+ | `EXECUTION_FAILED` | `CodeExecutionError` | Recoverable unless its cause is critical. `source`, `stacktrace`, `originalErrorName`, and `cause` preserve execution context. |
49
+ | `UNKNOWN_TOOL` | `UnknownToolError` | Recoverable. Missing callable or unrecognized native tool; `toolName`, `availableTools`. |
50
+ | `INVALID_TOOL_INPUT` | `ToolInputError` | Recoverable. Handler never ran; `toolName`, `issues`, `expectedInput`. |
51
+ | `TOOL_EXECUTION_FAILED` | `ToolExecutionError` | Recoverable. Handler failed after its configured retry policy; `toolName`, original `cause`. Effects may have occurred. |
52
+ | `RESERVED_IDENTIFIER` | `ReservedIdentifierError` | Generated variable declarations are recoverable. Registered tools, objects, exits, and components are critical configuration failures. `identifier`, `kind`. The conventional `exit` exit name remains supported. |
53
+ | `INVALID_ASSIGNMENT` | `AssignmentError` | Recoverable. Read-only assignment or generated variable/object namespace collision. |
54
+ | `INVALID_OBJECT_PROPERTY` | `ObjectPropertyError` | Recoverable. Rejected whole-property assignment; `objectName`, `propertyName`, `issues`, `expectedInput`. |
55
+ | `UNKNOWN_EXIT` | `UnknownExitError` | Recoverable. `exitName`, `availableExits`. No exit was applied. |
56
+ | `INVALID_EXIT_INPUT` | `ExitInputError` | Recoverable. `exitName`, `issues`, `expectedInput`. No exit was applied. |
57
+ | `UNKNOWN_COMPONENT` | `UnknownComponentError` | Recoverable. Missing `chat` method, including computed property access; `componentName`, `availableComponents`. No message was sent. |
58
+ | `INVALID_COMPONENT_INPUT` | `ComponentInputError` | Recoverable. `componentName`, `issues`, `expectedInput`. No message was sent. |
59
+ | `INVALID_NATIVE_CALL` | `NativeProtocolError` | Recoverable. Malformed native call, invalid JavaScript envelope, or multiple calls in one response. The rejected batch did not execute. |
60
+ | `HOST_OPERATION_FAILED` | `HostOperationError` | Recoverable. Unawaited tool or operation after JavaScript completion. Started work is joined; feedback distinguishes its effects. |
61
+ | `MISSING_CHAT_RESPONSE` | `MissingChatResponseError` | Recoverable. Chat tried to complete through `listen` while the assistant was not the last participant to speak; disabled by `options.requireChatResponse: false`. |
62
+ | `DELIVERY_FAILED` | `DeliveryError` | Recoverable. Text/component handler failed. Earlier acknowledged sends remain delivered; later queued sends are skipped. Inspect `cause`. |
63
+ | `HOOK_FAILED` | `HookError` | Recoverable. A hook rejected an operation; original `cause` is retained. |
64
+ | `INVALID_MEMORY_VALUE` | `MemoryValueError` | Recoverable. Unsupported/cyclic memory or inspection value. Failed captures also appear in `iteration.errors` and the memory report. |
65
+ | `ITERATION_LIMIT` | `LoopExceededError` | Critical. `limit` is the configured iteration count. |
66
+ | `GENERATION_FAILED` | `CognitiveError` | Critical. Provider failure, malformed generation, content filtering, or incomplete response; original provider failure is retained as `cause` when available. |
67
+ | `TOKEN_OVERFLOW` | `TokenOverflowError` | Critical. `phase` distinguishes input context overflow from output `max_tokens`; `tokens` and `limit` are supplied when known. |
68
+ | `COMPACTION_FAILED` | `CompactionError` | Critical. Summary generation or validation failed; history is preserved. Inspect `cause`. |
69
+ | `MEMORY_CAPACITY` | `MemoryCapacityError` | Critical. Retained memory exceeds `maxBytes`. Completed effects must not be replayed. |
70
+ | `EXECUTION_ABORTED` | `ExecutionAbortedError` | Critical. Cancellation or timeout; `cause` retains the original abort reason. |
71
+ | `INVALID_TOOL` | `InvalidToolError` | Critical. Invalid tool definition or tool configuration. |
72
+ | `INVALID_OBJECT` | `InvalidObjectError` | Critical. Invalid object definition or property registration. |
73
+ | `INVALID_EXIT` | `InvalidExitError` | Critical. Invalid exit definition or exit configuration. |
74
+ | `INVALID_COMPONENT` | `InvalidComponentError` | Critical. Invalid component definition or registration. |
75
+ | `INVALID_CONFIG` | `InvalidConfigurationError` | Critical. Invalid execution/chat/token/compaction settings or conflicting bindings. |
76
+ | `INVALID_MESSAGE` | `InvalidMessageError` | Critical. Invalid user/assistant input or input batch. Nothing is appended. |
77
+ | `INVALID_EVENT` | `InvalidEventError` | Critical. Invalid event name or non-persistable payload. Nothing is appended. |
78
+ | `INVALID_SESSION` | `InvalidSessionError` | Critical. Invalid persisted history, native messages, or serialized session data. |
79
+ | `SESSION_STATE` | `SessionStateError` | Critical. Concurrent execution or an operation incompatible with the current session lifecycle. |
80
+ | `CODE_FORMATTING_FAILED` | `CodeFormattingError` | Critical. Invalid generated API typings; `source` contains the failed type declaration. |
81
+ | `INTERNAL_ERROR` | `InternalError` | Critical. Unexpected library failure outside a recognized boundary; inspect `cause`. |
82
+
83
+ Compaction cannot guarantee that every request fits: instructions, tools, queued input, and mandatory context can exceed the entire budget. Input estimates also cannot predict all provider-specific media usage. Compaction does not prevent an output token limit. These cases must remain detectable by consumers.
84
+
85
+ Validation errors include a path/message list and the expected argument shape as TypeScript. Constraints such as minimum lengths and numeric bounds remain in `issues`; TypeScript shapes alone cannot express them. Error text is for humans and model recovery; use codes and guards for application decisions.
86
+
87
+ `ThinkSignal` is control flow, not a failure. Use `ThinkSignal.is(value)` to detect it across imports. It has no error code and is not collected in `iteration.errors`.
88
+
89
+ ## Inspecting recovery prompts
90
+
91
+ [`src/runtime/error-recovery.test.ts`](./src/runtime/error-recovery.test.ts) runs scripted, mocked LLM responses through the real runtime and both VM drivers. Its `.toMatchInlineSnapshot()` assertions show the tool-result feedback actually present in the next model request, including the expected input types. Memory and iteration-budget footers are excluded from the catalogue snapshot so the failure feedback is easy to review. Critical-error tests in [`src/runtime/errors.test.ts`](./src/runtime/errors.test.ts) assert that no additional provider call or business action occurs.
92
+
93
+ Recovery feedback uses XML-style sections: `<error>` contains the specific error code and readable message, `<stack_trace>` shows source-mapped guest code with line numbers and carets, and `<recovery>` explains how to continue. Tool calls, sent messages, memory changes, and inspection results each have their own section. Section tags are readable separators, not a strict XML document. Content is shown verbatim without entity escaping or CDATA, so code examples, entity literals, and retrieval tags stay unchanged. Validation messages preserve line breaks and the expected TypeScript shape.
94
+
95
+ Source traces are bounded previews around the failure sites, including failures near the end of long programs. The complete annotated source remains available as `CodeExecutionError.stacktrace`. Node and QuickJS may report different column precision; the inline snapshots cover each. Compiler errors show the invalid source. Host failures outside guest execution retain their original `cause` for consumers; the model is not shown a misleading guest stack or internal host paths.
96
+
97
+ A tool's thrown or returned `ThinkSignal` counts as successful execution, with its `context` returned to JavaScript. Multiple signals are collected while code continues. At settlement, they force inspection before any exit hook can run, even when later code raises a recoverable error. The `<forced_inspection>` section groups each tool's name, original call-site line (when available), reason, and result. It explicitly describes this as equivalent to `inspect()` and tells the model not to repeat those calls. Actual downstream failures remain in `iteration.errors` and the report's error sections; cancellation and critical errors still stop execution.
98
+
99
+ `think_signal` traces include the responsible tool name, tool-call ID, source line, reason, context, and optional metadata. Results are captured after output hooks and before guest mutations, and displayed through the normal inspection hooks and token budgets.
100
+
101
+ `toJSON()` and `result.diagnostics()` retain codes, messages, criticality, and nested error diagnostics. They are plain data: JSON does not retain the shared symbol brand or Error prototypes, so class guards intentionally do not accept parsed diagnostic JSON. The VM restores typed errors internally before exposing them on iterations.