open-multi-agent-kit 1.0.0 → 1.2.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 (622) hide show
  1. package/CHANGELOG.md +52 -1
  2. package/README.md +2 -2
  3. package/dist/approval-api.d.ts +5 -0
  4. package/dist/approval-api.d.ts.map +1 -0
  5. package/dist/approval-api.js +5 -0
  6. package/dist/approval-api.js.map +1 -0
  7. package/dist/cli/help.d.ts.map +1 -1
  8. package/dist/cli/help.js +1 -0
  9. package/dist/cli/help.js.map +1 -1
  10. package/dist/cli/session-picker.d.ts +2 -2
  11. package/dist/cli/session-picker.d.ts.map +1 -1
  12. package/dist/cli/session-picker.js.map +1 -1
  13. package/dist/commands/verified-run-cli.d.ts.map +1 -1
  14. package/dist/commands/verified-run-cli.js +69 -22
  15. package/dist/commands/verified-run-cli.js.map +1 -1
  16. package/dist/commands/verified-run-signal.d.ts +3 -0
  17. package/dist/commands/verified-run-signal.d.ts.map +1 -0
  18. package/dist/commands/verified-run-signal.js +15 -0
  19. package/dist/commands/verified-run-signal.js.map +1 -0
  20. package/dist/coordination/awareness.d.ts +32 -0
  21. package/dist/coordination/awareness.d.ts.map +1 -0
  22. package/dist/coordination/awareness.js +55 -0
  23. package/dist/coordination/awareness.js.map +1 -0
  24. package/dist/coordination/broker.d.ts +79 -0
  25. package/dist/coordination/broker.d.ts.map +1 -0
  26. package/dist/coordination/broker.js +202 -0
  27. package/dist/coordination/broker.js.map +1 -0
  28. package/dist/coordination/index.d.ts +16 -0
  29. package/dist/coordination/index.d.ts.map +1 -0
  30. package/dist/coordination/index.js +16 -0
  31. package/dist/coordination/index.js.map +1 -0
  32. package/dist/coordination/integration.d.ts +59 -0
  33. package/dist/coordination/integration.d.ts.map +1 -0
  34. package/dist/coordination/integration.js +126 -0
  35. package/dist/coordination/integration.js.map +1 -0
  36. package/dist/coordination/operation.d.ts +107 -0
  37. package/dist/coordination/operation.d.ts.map +1 -0
  38. package/dist/coordination/operation.js +231 -0
  39. package/dist/coordination/operation.js.map +1 -0
  40. package/dist/coordination/resource.d.ts +33 -0
  41. package/dist/coordination/resource.d.ts.map +1 -0
  42. package/dist/coordination/resource.js +95 -0
  43. package/dist/coordination/resource.js.map +1 -0
  44. package/dist/coordination/session.d.ts +74 -0
  45. package/dist/coordination/session.d.ts.map +1 -0
  46. package/dist/coordination/session.js +143 -0
  47. package/dist/coordination/session.js.map +1 -0
  48. package/dist/coordination/types.d.ts +68 -0
  49. package/dist/coordination/types.d.ts.map +1 -0
  50. package/dist/coordination/types.js +26 -0
  51. package/dist/coordination/types.js.map +1 -0
  52. package/dist/core/adaptorch-bridge.d.ts +1 -1
  53. package/dist/core/adaptorch-bridge.d.ts.map +1 -1
  54. package/dist/core/adaptorch-bridge.js +1 -1
  55. package/dist/core/adaptorch-bridge.js.map +1 -1
  56. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  57. package/dist/core/agent-session-runtime.js +16 -16
  58. package/dist/core/agent-session-runtime.js.map +1 -1
  59. package/dist/core/agent-session.d.ts.map +1 -1
  60. package/dist/core/agent-session.js +35 -15
  61. package/dist/core/agent-session.js.map +1 -1
  62. package/dist/core/canonical-json.d.ts +3 -0
  63. package/dist/core/canonical-json.d.ts.map +1 -0
  64. package/dist/core/canonical-json.js +20 -0
  65. package/dist/core/canonical-json.js.map +1 -0
  66. package/dist/core/compaction/compaction.d.ts +7 -3
  67. package/dist/core/compaction/compaction.d.ts.map +1 -1
  68. package/dist/core/compaction/compaction.js +14 -29
  69. package/dist/core/compaction/compaction.js.map +1 -1
  70. package/dist/core/compaction/control-state.d.ts +41 -0
  71. package/dist/core/compaction/control-state.d.ts.map +1 -0
  72. package/dist/core/compaction/control-state.js +85 -0
  73. package/dist/core/compaction/control-state.js.map +1 -0
  74. package/dist/core/compaction/fallback.d.ts +71 -0
  75. package/dist/core/compaction/fallback.d.ts.map +1 -0
  76. package/dist/core/compaction/fallback.js +118 -0
  77. package/dist/core/compaction/fallback.js.map +1 -0
  78. package/dist/core/compaction/index.d.ts +2 -0
  79. package/dist/core/compaction/index.d.ts.map +1 -1
  80. package/dist/core/compaction/index.js +2 -0
  81. package/dist/core/compaction/index.js.map +1 -1
  82. package/dist/core/compaction/model-failover.d.ts +21 -0
  83. package/dist/core/compaction/model-failover.d.ts.map +1 -0
  84. package/dist/core/compaction/model-failover.js +46 -0
  85. package/dist/core/compaction/model-failover.js.map +1 -0
  86. package/dist/core/compaction/session-summary.d.ts +21 -0
  87. package/dist/core/compaction/session-summary.d.ts.map +1 -0
  88. package/dist/core/compaction/session-summary.js +27 -0
  89. package/dist/core/compaction/session-summary.js.map +1 -0
  90. package/dist/core/context-budget-headroom-candidates.d.ts +16 -1
  91. package/dist/core/context-budget-headroom-candidates.d.ts.map +1 -1
  92. package/dist/core/context-budget-headroom-candidates.js +31 -13
  93. package/dist/core/context-budget-headroom-candidates.js.map +1 -1
  94. package/dist/core/context-budget-headroom-types.d.ts +7 -1
  95. package/dist/core/context-budget-headroom-types.d.ts.map +1 -1
  96. package/dist/core/context-budget-headroom-types.js +0 -1
  97. package/dist/core/context-budget-headroom-types.js.map +1 -1
  98. package/dist/core/context-budget-headroom.d.ts +10 -0
  99. package/dist/core/context-budget-headroom.d.ts.map +1 -1
  100. package/dist/core/context-budget-headroom.js +11 -2
  101. package/dist/core/context-budget-headroom.js.map +1 -1
  102. package/dist/core/context-budget-v2-global-pass.d.ts +21 -0
  103. package/dist/core/context-budget-v2-global-pass.d.ts.map +1 -0
  104. package/dist/core/context-budget-v2-global-pass.js +203 -0
  105. package/dist/core/context-budget-v2-global-pass.js.map +1 -0
  106. package/dist/core/context-budget-v2-planned-items.d.ts +12 -0
  107. package/dist/core/context-budget-v2-planned-items.d.ts.map +1 -1
  108. package/dist/core/context-budget-v2-planned-items.js +21 -2
  109. package/dist/core/context-budget-v2-planned-items.js.map +1 -1
  110. package/dist/core/context-budget-v2-planner.d.ts.map +1 -1
  111. package/dist/core/context-budget-v2-planner.js +18 -19
  112. package/dist/core/context-budget-v2-planner.js.map +1 -1
  113. package/dist/core/context-budget-v2-scoring.d.ts +7 -1
  114. package/dist/core/context-budget-v2-scoring.d.ts.map +1 -1
  115. package/dist/core/context-budget-v2-scoring.js.map +1 -1
  116. package/dist/core/context-budget-v2-selection.d.ts +3 -0
  117. package/dist/core/context-budget-v2-selection.d.ts.map +1 -1
  118. package/dist/core/context-budget-v2-selection.js +6 -2
  119. package/dist/core/context-budget-v2-selection.js.map +1 -1
  120. package/dist/core/context-budget-v2-types.d.ts +6 -1
  121. package/dist/core/context-budget-v2-types.d.ts.map +1 -1
  122. package/dist/core/context-budget-v2-types.js +6 -1
  123. package/dist/core/context-budget-v2-types.js.map +1 -1
  124. package/dist/core/export-html/template.js +14 -0
  125. package/dist/core/extensions/index.d.ts +1 -1
  126. package/dist/core/extensions/index.d.ts.map +1 -1
  127. package/dist/core/extensions/index.js.map +1 -1
  128. package/dist/core/extensions/session-lifecycle-types.d.ts +14 -0
  129. package/dist/core/extensions/session-lifecycle-types.d.ts.map +1 -0
  130. package/dist/core/extensions/session-lifecycle-types.js +2 -0
  131. package/dist/core/extensions/session-lifecycle-types.js.map +1 -0
  132. package/dist/core/extensions/types.d.ts +4 -9
  133. package/dist/core/extensions/types.d.ts.map +1 -1
  134. package/dist/core/extensions/types.js.map +1 -1
  135. package/dist/core/http-dispatcher.d.ts.map +1 -1
  136. package/dist/core/http-dispatcher.js +10 -1
  137. package/dist/core/http-dispatcher.js.map +1 -1
  138. package/dist/core/keybindings.d.ts.map +1 -1
  139. package/dist/core/keybindings.js +3 -6
  140. package/dist/core/keybindings.js.map +1 -1
  141. package/dist/core/legacy-resource-policy.d.ts +7 -0
  142. package/dist/core/legacy-resource-policy.d.ts.map +1 -0
  143. package/dist/core/legacy-resource-policy.js +9 -0
  144. package/dist/core/legacy-resource-policy.js.map +1 -0
  145. package/dist/core/mcp/config.d.ts.map +1 -1
  146. package/dist/core/mcp/config.js +17 -3
  147. package/dist/core/mcp/config.js.map +1 -1
  148. package/dist/core/mcp/connection-queue.d.ts +12 -0
  149. package/dist/core/mcp/connection-queue.d.ts.map +1 -0
  150. package/dist/core/mcp/connection-queue.js +46 -0
  151. package/dist/core/mcp/connection-queue.js.map +1 -0
  152. package/dist/core/mcp/manager-runtime.d.ts +55 -0
  153. package/dist/core/mcp/manager-runtime.d.ts.map +1 -0
  154. package/dist/core/mcp/manager-runtime.js +66 -0
  155. package/dist/core/mcp/manager-runtime.js.map +1 -0
  156. package/dist/core/mcp/manager.d.ts +12 -68
  157. package/dist/core/mcp/manager.d.ts.map +1 -1
  158. package/dist/core/mcp/manager.js +33 -113
  159. package/dist/core/mcp/manager.js.map +1 -1
  160. package/dist/core/mcp/protocol.d.ts.map +1 -1
  161. package/dist/core/mcp/protocol.js +70 -40
  162. package/dist/core/mcp/protocol.js.map +1 -1
  163. package/dist/core/package-manager.d.ts +4 -0
  164. package/dist/core/package-manager.d.ts.map +1 -1
  165. package/dist/core/package-manager.js +59 -129
  166. package/dist/core/package-manager.js.map +1 -1
  167. package/dist/core/package-resource-patterns.d.ts +7 -0
  168. package/dist/core/package-resource-patterns.d.ts.map +1 -0
  169. package/dist/core/package-resource-patterns.js +99 -0
  170. package/dist/core/package-resource-patterns.js.map +1 -0
  171. package/dist/core/provider-default-models.d.ts +1 -0
  172. package/dist/core/provider-default-models.d.ts.map +1 -1
  173. package/dist/core/provider-default-models.js +1 -0
  174. package/dist/core/provider-default-models.js.map +1 -1
  175. package/dist/core/provider-display-names.d.ts.map +1 -1
  176. package/dist/core/provider-display-names.js +1 -0
  177. package/dist/core/provider-display-names.js.map +1 -1
  178. package/dist/core/provider-resilience.d.ts +9 -0
  179. package/dist/core/provider-resilience.d.ts.map +1 -1
  180. package/dist/core/provider-resilience.js +15 -0
  181. package/dist/core/provider-resilience.js.map +1 -1
  182. package/dist/core/reasoning-router-resolver.d.ts +7 -0
  183. package/dist/core/reasoning-router-resolver.d.ts.map +1 -1
  184. package/dist/core/reasoning-router-resolver.js +21 -3
  185. package/dist/core/reasoning-router-resolver.js.map +1 -1
  186. package/dist/core/reasoning-router-v4.d.ts +13 -7
  187. package/dist/core/reasoning-router-v4.d.ts.map +1 -1
  188. package/dist/core/reasoning-router-v4.js +8 -5
  189. package/dist/core/reasoning-router-v4.js.map +1 -1
  190. package/dist/core/resource-loader.d.ts.map +1 -1
  191. package/dist/core/resource-loader.js +4 -8
  192. package/dist/core/resource-loader.js.map +1 -1
  193. package/dist/core/run-execution-api.d.ts +8 -1
  194. package/dist/core/run-execution-api.d.ts.map +1 -1
  195. package/dist/core/run-execution-api.js +4 -0
  196. package/dist/core/run-execution-api.js.map +1 -1
  197. package/dist/core/run-journal.d.ts +1 -2
  198. package/dist/core/run-journal.d.ts.map +1 -1
  199. package/dist/core/run-journal.js +2 -19
  200. package/dist/core/run-journal.js.map +1 -1
  201. package/dist/core/session-compaction-service.d.ts +15 -0
  202. package/dist/core/session-compaction-service.d.ts.map +1 -1
  203. package/dist/core/session-compaction-service.js +17 -4
  204. package/dist/core/session-compaction-service.js.map +1 -1
  205. package/dist/core/session-listing.d.ts +51 -0
  206. package/dist/core/session-listing.d.ts.map +1 -0
  207. package/dist/core/session-listing.js +111 -0
  208. package/dist/core/session-listing.js.map +1 -0
  209. package/dist/core/session-manager.d.ts +12 -37
  210. package/dist/core/session-manager.d.ts.map +1 -1
  211. package/dist/core/session-manager.js +12 -118
  212. package/dist/core/session-manager.js.map +1 -1
  213. package/dist/core/session-message-text.d.ts +5 -0
  214. package/dist/core/session-message-text.d.ts.map +1 -0
  215. package/dist/core/session-message-text.js +9 -0
  216. package/dist/core/session-message-text.js.map +1 -0
  217. package/dist/core/skills-catalog-cache.d.ts +2 -0
  218. package/dist/core/skills-catalog-cache.d.ts.map +1 -1
  219. package/dist/core/skills-catalog-cache.js +71 -17
  220. package/dist/core/skills-catalog-cache.js.map +1 -1
  221. package/dist/core/todo-runtime-state.d.ts +12 -0
  222. package/dist/core/todo-runtime-state.d.ts.map +1 -1
  223. package/dist/core/todo-runtime-state.js +23 -0
  224. package/dist/core/todo-runtime-state.js.map +1 -1
  225. package/dist/core/tools/read.d.ts.map +1 -1
  226. package/dist/core/tools/read.js +1 -1
  227. package/dist/core/tools/read.js.map +1 -1
  228. package/dist/core/verified-run/authority-clock.d.ts +3 -0
  229. package/dist/core/verified-run/authority-clock.d.ts.map +1 -0
  230. package/dist/core/verified-run/authority-clock.js +25 -0
  231. package/dist/core/verified-run/authority-clock.js.map +1 -0
  232. package/dist/core/verified-run/authority-errors.d.ts +10 -0
  233. package/dist/core/verified-run/authority-errors.d.ts.map +1 -0
  234. package/dist/core/verified-run/authority-errors.js +17 -0
  235. package/dist/core/verified-run/authority-errors.js.map +1 -0
  236. package/dist/core/verified-run/authority-events.d.ts +126 -0
  237. package/dist/core/verified-run/authority-events.d.ts.map +1 -0
  238. package/dist/core/verified-run/authority-events.js +482 -0
  239. package/dist/core/verified-run/authority-events.js.map +1 -0
  240. package/dist/core/verified-run/authority-journal.d.ts +27 -0
  241. package/dist/core/verified-run/authority-journal.d.ts.map +1 -0
  242. package/dist/core/verified-run/authority-journal.js +83 -0
  243. package/dist/core/verified-run/authority-journal.js.map +1 -0
  244. package/dist/core/verified-run/authority-meaning.d.ts +13 -0
  245. package/dist/core/verified-run/authority-meaning.d.ts.map +1 -0
  246. package/dist/core/verified-run/authority-meaning.js +40 -0
  247. package/dist/core/verified-run/authority-meaning.js.map +1 -0
  248. package/dist/core/verified-run/authority-runtime.d.ts +82 -0
  249. package/dist/core/verified-run/authority-runtime.d.ts.map +1 -0
  250. package/dist/core/verified-run/authority-runtime.js +169 -0
  251. package/dist/core/verified-run/authority-runtime.js.map +1 -0
  252. package/dist/core/verified-run/authority-store.d.ts +204 -0
  253. package/dist/core/verified-run/authority-store.d.ts.map +1 -0
  254. package/dist/core/verified-run/authority-store.js +852 -0
  255. package/dist/core/verified-run/authority-store.js.map +1 -0
  256. package/dist/core/verified-run/broker.d.ts +8 -1
  257. package/dist/core/verified-run/broker.d.ts.map +1 -1
  258. package/dist/core/verified-run/broker.js +94 -90
  259. package/dist/core/verified-run/broker.js.map +1 -1
  260. package/dist/core/verified-run/candidate-policy.d.ts +10 -0
  261. package/dist/core/verified-run/candidate-policy.d.ts.map +1 -0
  262. package/dist/core/verified-run/candidate-policy.js +33 -0
  263. package/dist/core/verified-run/candidate-policy.js.map +1 -0
  264. package/dist/core/verified-run/candidate.d.ts.map +1 -1
  265. package/dist/core/verified-run/candidate.js +5 -10
  266. package/dist/core/verified-run/candidate.js.map +1 -1
  267. package/dist/core/verified-run/coordinator.d.ts +35 -17
  268. package/dist/core/verified-run/coordinator.d.ts.map +1 -1
  269. package/dist/core/verified-run/coordinator.js +111 -57
  270. package/dist/core/verified-run/coordinator.js.map +1 -1
  271. package/dist/core/verified-run/dag-phase.d.ts.map +1 -1
  272. package/dist/core/verified-run/dag-phase.js +1 -1
  273. package/dist/core/verified-run/dag-phase.js.map +1 -1
  274. package/dist/core/verified-run/dag-recovery.d.ts +5 -1
  275. package/dist/core/verified-run/dag-recovery.d.ts.map +1 -1
  276. package/dist/core/verified-run/dag-recovery.js +10 -4
  277. package/dist/core/verified-run/dag-recovery.js.map +1 -1
  278. package/dist/core/verified-run/event-parser.d.ts.map +1 -1
  279. package/dist/core/verified-run/event-parser.js +33 -0
  280. package/dist/core/verified-run/event-parser.js.map +1 -1
  281. package/dist/core/verified-run/evidence-read-projection.d.ts +4 -0
  282. package/dist/core/verified-run/evidence-read-projection.d.ts.map +1 -0
  283. package/dist/core/verified-run/evidence-read-projection.js +27 -0
  284. package/dist/core/verified-run/evidence-read-projection.js.map +1 -0
  285. package/dist/core/verified-run/evidence.d.ts +12 -1
  286. package/dist/core/verified-run/evidence.d.ts.map +1 -1
  287. package/dist/core/verified-run/evidence.js +51 -2
  288. package/dist/core/verified-run/evidence.js.map +1 -1
  289. package/dist/core/verified-run/git-candidate-preflight.d.ts +4 -0
  290. package/dist/core/verified-run/git-candidate-preflight.d.ts.map +1 -0
  291. package/dist/core/verified-run/git-candidate-preflight.js +34 -0
  292. package/dist/core/verified-run/git-candidate-preflight.js.map +1 -0
  293. package/dist/core/verified-run/git-effect-supervisor.d.ts +24 -0
  294. package/dist/core/verified-run/git-effect-supervisor.d.ts.map +1 -0
  295. package/dist/core/verified-run/git-effect-supervisor.js +174 -0
  296. package/dist/core/verified-run/git-effect-supervisor.js.map +1 -0
  297. package/dist/core/verified-run/git-execution.d.ts +27 -0
  298. package/dist/core/verified-run/git-execution.d.ts.map +1 -0
  299. package/dist/core/verified-run/git-execution.js +118 -0
  300. package/dist/core/verified-run/git-execution.js.map +1 -0
  301. package/dist/core/verified-run/git-plumbing.d.ts +37 -0
  302. package/dist/core/verified-run/git-plumbing.d.ts.map +1 -0
  303. package/dist/core/verified-run/git-plumbing.js +171 -0
  304. package/dist/core/verified-run/git-plumbing.js.map +1 -0
  305. package/dist/core/verified-run/git-publication-worker.d.ts +2 -0
  306. package/dist/core/verified-run/git-publication-worker.d.ts.map +1 -0
  307. package/dist/core/verified-run/git-publication-worker.js +54 -0
  308. package/dist/core/verified-run/git-publication-worker.js.map +1 -0
  309. package/dist/core/verified-run/git-sandbox-layout.d.ts +4 -0
  310. package/dist/core/verified-run/git-sandbox-layout.d.ts.map +1 -0
  311. package/dist/core/verified-run/git-sandbox-layout.js +29 -0
  312. package/dist/core/verified-run/git-sandbox-layout.js.map +1 -0
  313. package/dist/core/verified-run/git-worker-protocol.d.ts +19 -0
  314. package/dist/core/verified-run/git-worker-protocol.d.ts.map +1 -0
  315. package/dist/core/verified-run/git-worker-protocol.js +109 -0
  316. package/dist/core/verified-run/git-worker-protocol.js.map +1 -0
  317. package/dist/core/verified-run/git-worker-runtime.d.ts +19 -0
  318. package/dist/core/verified-run/git-worker-runtime.d.ts.map +1 -0
  319. package/dist/core/verified-run/git-worker-runtime.js +74 -0
  320. package/dist/core/verified-run/git-worker-runtime.js.map +1 -0
  321. package/dist/core/verified-run/journal.d.ts +2 -3
  322. package/dist/core/verified-run/journal.d.ts.map +1 -1
  323. package/dist/core/verified-run/journal.js.map +1 -1
  324. package/dist/core/verified-run/namespace-identity.d.ts.map +1 -1
  325. package/dist/core/verified-run/namespace-identity.js +1 -1
  326. package/dist/core/verified-run/namespace-identity.js.map +1 -1
  327. package/dist/core/verified-run/owned-execution.d.ts +10 -1
  328. package/dist/core/verified-run/owned-execution.d.ts.map +1 -1
  329. package/dist/core/verified-run/owned-execution.js +124 -31
  330. package/dist/core/verified-run/owned-execution.js.map +1 -1
  331. package/dist/core/verified-run/phase-context.d.ts +2 -0
  332. package/dist/core/verified-run/phase-context.d.ts.map +1 -1
  333. package/dist/core/verified-run/phase-context.js.map +1 -1
  334. package/dist/core/verified-run/projection.d.ts.map +1 -1
  335. package/dist/core/verified-run/projection.js +51 -1
  336. package/dist/core/verified-run/projection.js.map +1 -1
  337. package/dist/core/verified-run/publish-preflight.d.ts +12 -0
  338. package/dist/core/verified-run/publish-preflight.d.ts.map +1 -0
  339. package/dist/core/verified-run/publish-preflight.js +38 -0
  340. package/dist/core/verified-run/publish-preflight.js.map +1 -0
  341. package/dist/core/verified-run/publish-start.d.ts +5 -0
  342. package/dist/core/verified-run/publish-start.d.ts.map +1 -0
  343. package/dist/core/verified-run/publish-start.js +7 -0
  344. package/dist/core/verified-run/publish-start.js.map +1 -0
  345. package/dist/core/verified-run/recovery-projection.d.ts.map +1 -1
  346. package/dist/core/verified-run/recovery-projection.js +5 -0
  347. package/dist/core/verified-run/recovery-projection.js.map +1 -1
  348. package/dist/core/verified-run/recovery.d.ts +5 -1
  349. package/dist/core/verified-run/recovery.d.ts.map +1 -1
  350. package/dist/core/verified-run/recovery.js +10 -4
  351. package/dist/core/verified-run/recovery.js.map +1 -1
  352. package/dist/core/verified-run/run-plan.d.ts +17 -0
  353. package/dist/core/verified-run/run-plan.d.ts.map +1 -0
  354. package/dist/core/verified-run/run-plan.js +18 -0
  355. package/dist/core/verified-run/run-plan.js.map +1 -0
  356. package/dist/core/verified-run/run-publish-owned.d.ts +6 -0
  357. package/dist/core/verified-run/run-publish-owned.d.ts.map +1 -0
  358. package/dist/core/verified-run/run-publish-owned.js +199 -0
  359. package/dist/core/verified-run/run-publish-owned.js.map +1 -0
  360. package/dist/core/verified-run/run-publish.d.ts +19 -0
  361. package/dist/core/verified-run/run-publish.d.ts.map +1 -0
  362. package/dist/core/verified-run/run-publish.js +210 -0
  363. package/dist/core/verified-run/run-publish.js.map +1 -0
  364. package/dist/core/verified-run/run-status-owned.d.ts +4 -0
  365. package/dist/core/verified-run/run-status-owned.d.ts.map +1 -0
  366. package/dist/core/verified-run/run-status-owned.js +14 -0
  367. package/dist/core/verified-run/run-status-owned.js.map +1 -0
  368. package/dist/core/verified-run/run-status.d.ts +133 -0
  369. package/dist/core/verified-run/run-status.d.ts.map +1 -0
  370. package/dist/core/verified-run/run-status.js +193 -0
  371. package/dist/core/verified-run/run-status.js.map +1 -0
  372. package/dist/core/verified-run/run-types.d.ts +31 -0
  373. package/dist/core/verified-run/run-types.d.ts.map +1 -1
  374. package/dist/core/verified-run/run-types.js.map +1 -1
  375. package/dist/core/verified-run/storage.d.ts.map +1 -1
  376. package/dist/core/verified-run/storage.js +1 -1
  377. package/dist/core/verified-run/storage.js.map +1 -1
  378. package/dist/core/verified-run/supervisor-adapter.d.ts +77 -0
  379. package/dist/core/verified-run/supervisor-adapter.d.ts.map +1 -0
  380. package/dist/core/verified-run/supervisor-adapter.js +164 -0
  381. package/dist/core/verified-run/supervisor-adapter.js.map +1 -0
  382. package/dist/core/verified-run/verification-phase.d.ts.map +1 -1
  383. package/dist/core/verified-run/verification-phase.js +1 -1
  384. package/dist/core/verified-run/verification-phase.js.map +1 -1
  385. package/dist/core/verified-run/writer-phase.d.ts.map +1 -1
  386. package/dist/core/verified-run/writer-phase.js +1 -0
  387. package/dist/core/verified-run/writer-phase.js.map +1 -1
  388. package/dist/core/verified-run/writer-recovery.d.ts +2 -0
  389. package/dist/core/verified-run/writer-recovery.d.ts.map +1 -1
  390. package/dist/core/verified-run/writer-recovery.js +1 -0
  391. package/dist/core/verified-run/writer-recovery.js.map +1 -1
  392. package/dist/core/workload-shard-execution-types.d.ts +4 -1
  393. package/dist/core/workload-shard-execution-types.d.ts.map +1 -1
  394. package/dist/core/workload-shard-execution-types.js.map +1 -1
  395. package/dist/core/workload-shard-executor.d.ts +2 -2
  396. package/dist/core/workload-shard-executor.d.ts.map +1 -1
  397. package/dist/core/workload-shard-executor.js +16 -37
  398. package/dist/core/workload-shard-executor.js.map +1 -1
  399. package/dist/core/workload-shard-frontier.d.ts +5 -0
  400. package/dist/core/workload-shard-frontier.d.ts.map +1 -0
  401. package/dist/core/workload-shard-frontier.js +47 -0
  402. package/dist/core/workload-shard-frontier.js.map +1 -0
  403. package/dist/core/workload-shard-runner.d.ts.map +1 -1
  404. package/dist/core/workload-shard-runner.js +28 -17
  405. package/dist/core/workload-shard-runner.js.map +1 -1
  406. package/dist/index.d.ts +4 -5
  407. package/dist/index.d.ts.map +1 -1
  408. package/dist/index.js +3 -4
  409. package/dist/index.js.map +1 -1
  410. package/dist/main.d.ts.map +1 -1
  411. package/dist/main.js +2 -1
  412. package/dist/main.js.map +1 -1
  413. package/dist/metacognition/bridge-result.d.ts +148 -0
  414. package/dist/metacognition/bridge-result.d.ts.map +1 -0
  415. package/dist/metacognition/bridge-result.js +46 -0
  416. package/dist/metacognition/bridge-result.js.map +1 -0
  417. package/dist/metacognition/calibration-selective.d.ts +78 -0
  418. package/dist/metacognition/calibration-selective.d.ts.map +1 -0
  419. package/dist/metacognition/calibration-selective.js +167 -0
  420. package/dist/metacognition/calibration-selective.js.map +1 -0
  421. package/dist/metacognition/calibration.d.ts +62 -0
  422. package/dist/metacognition/calibration.d.ts.map +1 -0
  423. package/dist/metacognition/calibration.js +122 -0
  424. package/dist/metacognition/calibration.js.map +1 -0
  425. package/dist/metacognition/checkpoint.d.ts +60 -0
  426. package/dist/metacognition/checkpoint.d.ts.map +1 -0
  427. package/dist/metacognition/checkpoint.js +57 -0
  428. package/dist/metacognition/checkpoint.js.map +1 -0
  429. package/dist/metacognition/context7.d.ts +48 -0
  430. package/dist/metacognition/context7.d.ts.map +1 -0
  431. package/dist/metacognition/context7.js +154 -0
  432. package/dist/metacognition/context7.js.map +1 -0
  433. package/dist/metacognition/decision.d.ts +44 -0
  434. package/dist/metacognition/decision.d.ts.map +1 -0
  435. package/dist/metacognition/decision.js +111 -0
  436. package/dist/metacognition/decision.js.map +1 -0
  437. package/dist/metacognition/evaluation.d.ts +73 -0
  438. package/dist/metacognition/evaluation.d.ts.map +1 -0
  439. package/dist/metacognition/evaluation.js +97 -0
  440. package/dist/metacognition/evaluation.js.map +1 -0
  441. package/dist/metacognition/index.d.ts +32 -0
  442. package/dist/metacognition/index.d.ts.map +1 -0
  443. package/dist/metacognition/index.js +32 -0
  444. package/dist/metacognition/index.js.map +1 -0
  445. package/dist/metacognition/knowledge-action.d.ts +43 -0
  446. package/dist/metacognition/knowledge-action.d.ts.map +1 -0
  447. package/dist/metacognition/knowledge-action.js +60 -0
  448. package/dist/metacognition/knowledge-action.js.map +1 -0
  449. package/dist/metacognition/knowledge.d.ts +84 -0
  450. package/dist/metacognition/knowledge.d.ts.map +1 -0
  451. package/dist/metacognition/knowledge.js +165 -0
  452. package/dist/metacognition/knowledge.js.map +1 -0
  453. package/dist/metacognition/obligations.d.ts +82 -0
  454. package/dist/metacognition/obligations.d.ts.map +1 -0
  455. package/dist/metacognition/obligations.js +139 -0
  456. package/dist/metacognition/obligations.js.map +1 -0
  457. package/dist/metacognition/observation-validity.d.ts +83 -0
  458. package/dist/metacognition/observation-validity.d.ts.map +1 -0
  459. package/dist/metacognition/observation-validity.js +118 -0
  460. package/dist/metacognition/observation-validity.js.map +1 -0
  461. package/dist/metacognition/observe.d.ts +45 -0
  462. package/dist/metacognition/observe.d.ts.map +1 -0
  463. package/dist/metacognition/observe.js +59 -0
  464. package/dist/metacognition/observe.js.map +1 -0
  465. package/dist/metacognition/policy.d.ts +53 -0
  466. package/dist/metacognition/policy.d.ts.map +1 -0
  467. package/dist/metacognition/policy.js +155 -0
  468. package/dist/metacognition/policy.js.map +1 -0
  469. package/dist/metacognition/predictions.d.ts +78 -0
  470. package/dist/metacognition/predictions.d.ts.map +1 -0
  471. package/dist/metacognition/predictions.js +181 -0
  472. package/dist/metacognition/predictions.js.map +1 -0
  473. package/dist/metacognition/retrieval.d.ts +53 -0
  474. package/dist/metacognition/retrieval.d.ts.map +1 -0
  475. package/dist/metacognition/retrieval.js +170 -0
  476. package/dist/metacognition/retrieval.js.map +1 -0
  477. package/dist/metacognition/risk.d.ts +48 -0
  478. package/dist/metacognition/risk.d.ts.map +1 -0
  479. package/dist/metacognition/risk.js +179 -0
  480. package/dist/metacognition/risk.js.map +1 -0
  481. package/dist/metacognition/route-economics.d.ts +95 -0
  482. package/dist/metacognition/route-economics.d.ts.map +1 -0
  483. package/dist/metacognition/route-economics.js +110 -0
  484. package/dist/metacognition/route-economics.js.map +1 -0
  485. package/dist/metacognition/runtime-bridge.d.ts +81 -0
  486. package/dist/metacognition/runtime-bridge.d.ts.map +1 -0
  487. package/dist/metacognition/runtime-bridge.js +458 -0
  488. package/dist/metacognition/runtime-bridge.js.map +1 -0
  489. package/dist/metacognition/skills.d.ts +42 -0
  490. package/dist/metacognition/skills.d.ts.map +1 -0
  491. package/dist/metacognition/skills.js +220 -0
  492. package/dist/metacognition/skills.js.map +1 -0
  493. package/dist/metacognition/state.d.ts +110 -0
  494. package/dist/metacognition/state.d.ts.map +1 -0
  495. package/dist/metacognition/state.js +52 -0
  496. package/dist/metacognition/state.js.map +1 -0
  497. package/dist/metacognition/validation.d.ts +19 -0
  498. package/dist/metacognition/validation.d.ts.map +1 -0
  499. package/dist/metacognition/validation.js +58 -0
  500. package/dist/metacognition/validation.js.map +1 -0
  501. package/dist/metacognition/verification.d.ts +93 -0
  502. package/dist/metacognition/verification.d.ts.map +1 -0
  503. package/dist/metacognition/verification.js +132 -0
  504. package/dist/metacognition/verification.js.map +1 -0
  505. package/dist/metacognition/verifier.d.ts +49 -0
  506. package/dist/metacognition/verifier.d.ts.map +1 -0
  507. package/dist/metacognition/verifier.js +88 -0
  508. package/dist/metacognition/verifier.js.map +1 -0
  509. package/dist/modes/interactive/components/assistant-message.d.ts +2 -0
  510. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  511. package/dist/modes/interactive/components/assistant-message.js +42 -26
  512. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  513. package/dist/modes/interactive/components/chat-container.d.ts +7 -0
  514. package/dist/modes/interactive/components/chat-container.d.ts.map +1 -0
  515. package/dist/modes/interactive/components/chat-container.js +14 -0
  516. package/dist/modes/interactive/components/chat-container.js.map +1 -0
  517. package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -1
  518. package/dist/modes/interactive/components/dynamic-border.js +4 -2
  519. package/dist/modes/interactive/components/dynamic-border.js.map +1 -1
  520. package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
  521. package/dist/modes/interactive/components/login-dialog.js +0 -1
  522. package/dist/modes/interactive/components/login-dialog.js.map +1 -1
  523. package/dist/modes/interactive/components/session-selector-async-search.d.ts +33 -0
  524. package/dist/modes/interactive/components/session-selector-async-search.d.ts.map +1 -0
  525. package/dist/modes/interactive/components/session-selector-async-search.js +109 -0
  526. package/dist/modes/interactive/components/session-selector-async-search.js.map +1 -0
  527. package/dist/modes/interactive/components/session-selector-loaders.d.ts +6 -0
  528. package/dist/modes/interactive/components/session-selector-loaders.d.ts.map +1 -0
  529. package/dist/modes/interactive/components/session-selector-loaders.js +9 -0
  530. package/dist/modes/interactive/components/session-selector-loaders.js.map +1 -0
  531. package/dist/modes/interactive/components/session-selector-search.d.ts +1 -1
  532. package/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -1
  533. package/dist/modes/interactive/components/session-selector-search.js.map +1 -1
  534. package/dist/modes/interactive/components/session-selector-tree.d.ts +16 -0
  535. package/dist/modes/interactive/components/session-selector-tree.d.ts.map +1 -0
  536. package/dist/modes/interactive/components/session-selector-tree.js +46 -0
  537. package/dist/modes/interactive/components/session-selector-tree.js.map +1 -0
  538. package/dist/modes/interactive/components/session-selector.d.ts +6 -1
  539. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  540. package/dist/modes/interactive/components/session-selector.js +36 -76
  541. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  542. package/dist/modes/interactive/components/tool-execution-images.d.ts +32 -0
  543. package/dist/modes/interactive/components/tool-execution-images.d.ts.map +1 -0
  544. package/dist/modes/interactive/components/tool-execution-images.js +144 -0
  545. package/dist/modes/interactive/components/tool-execution-images.js.map +1 -0
  546. package/dist/modes/interactive/components/tool-execution.d.ts +3 -4
  547. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  548. package/dist/modes/interactive/components/tool-execution.js +22 -71
  549. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  550. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  551. package/dist/modes/interactive/interactive-mode.js +7 -9
  552. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  553. package/dist/modes/interactive/tui-diagnostics.d.ts +8 -4
  554. package/dist/modes/interactive/tui-diagnostics.d.ts.map +1 -1
  555. package/dist/modes/interactive/tui-diagnostics.js +35 -1
  556. package/dist/modes/interactive/tui-diagnostics.js.map +1 -1
  557. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  558. package/dist/modes/rpc/rpc-mode.js +14 -17
  559. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  560. package/dist/modes/rpc/rpc-response.d.ts +5 -0
  561. package/dist/modes/rpc/rpc-response.d.ts.map +1 -0
  562. package/dist/modes/rpc/rpc-response.js +17 -0
  563. package/dist/modes/rpc/rpc-response.js.map +1 -0
  564. package/dist/observation/identity.d.ts +14 -0
  565. package/dist/observation/identity.d.ts.map +1 -0
  566. package/dist/observation/identity.js +29 -0
  567. package/dist/observation/identity.js.map +1 -0
  568. package/dist/observation/index.d.ts +13 -0
  569. package/dist/observation/index.d.ts.map +1 -0
  570. package/dist/observation/index.js +13 -0
  571. package/dist/observation/index.js.map +1 -0
  572. package/dist/observation/observe-mode.d.ts +46 -0
  573. package/dist/observation/observe-mode.d.ts.map +1 -0
  574. package/dist/observation/observe-mode.js +83 -0
  575. package/dist/observation/observe-mode.js.map +1 -0
  576. package/dist/observation/store.d.ts +53 -0
  577. package/dist/observation/store.d.ts.map +1 -0
  578. package/dist/observation/store.js +126 -0
  579. package/dist/observation/store.js.map +1 -0
  580. package/dist/observation/types.d.ts +72 -0
  581. package/dist/observation/types.d.ts.map +1 -0
  582. package/dist/observation/types.js +9 -0
  583. package/dist/observation/types.js.map +1 -0
  584. package/dist/observation/view.d.ts +39 -0
  585. package/dist/observation/view.d.ts.map +1 -0
  586. package/dist/observation/view.js +173 -0
  587. package/dist/observation/view.js.map +1 -0
  588. package/dist/utils/exif-orientation.d.ts.map +1 -1
  589. package/dist/utils/exif-orientation.js +2 -3
  590. package/dist/utils/exif-orientation.js.map +1 -1
  591. package/dist/utils/tools-manager.d.ts.map +1 -1
  592. package/dist/utils/tools-manager.js +3 -5
  593. package/dist/utils/tools-manager.js.map +1 -1
  594. package/docs/adaptorch-preview-spec.md +7 -7
  595. package/docs/atomic-commit-planning.md +69 -0
  596. package/docs/compaction.md +26 -1
  597. package/docs/extensions.md +14 -0
  598. package/docs/mcp.md +22 -0
  599. package/docs/metacognition.md +130 -0
  600. package/docs/model-catalog-refresh.md +218 -1
  601. package/docs/models.md +1 -1
  602. package/docs/providers.md +53 -0
  603. package/docs/runtime-algorithms.md +156 -7
  604. package/docs/session-format.md +8 -0
  605. package/docs/sessions.md +19 -0
  606. package/docs/skills.md +19 -0
  607. package/docs/terminal-setup.md +15 -0
  608. package/docs/tui.md +41 -0
  609. package/docs/verified-run-safety.md +75 -0
  610. package/examples/extensions/custom-provider-anthropic/index.ts +1 -1
  611. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  612. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  613. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  614. package/examples/extensions/doom-overlay/wad-finder.ts +7 -3
  615. package/examples/extensions/gondolin/package-lock.json +2 -2
  616. package/examples/extensions/gondolin/package.json +1 -1
  617. package/examples/extensions/sandbox/package-lock.json +2 -2
  618. package/examples/extensions/sandbox/package.json +1 -1
  619. package/examples/extensions/with-deps/package-lock.json +2 -2
  620. package/examples/extensions/with-deps/package.json +1 -1
  621. package/npm-shrinkwrap.json +18 -18
  622. package/package.json +6 -8
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Time-aware independent verification (Jev audit algorithm A7, finding F07).
3
+ *
4
+ * F07 is the confusion between "each condition was satisfied at some point"
5
+ * and "they hold together now". Keeping `CompleteCurrent` and `CompleteEver`
6
+ * apart resolves it without throwing away valid history.
7
+ *
8
+ * `unknown` is a third value, not a synonym for `false`. A missing field or an
9
+ * incomplete collection scope means the evidence is absent; any binary rule
10
+ * that negates it into `true` manufactures a verification that never happened.
11
+ *
12
+ * Evidence strength is ordered but deliberately not a universal trust score:
13
+ * a backend response still has to be matched to the right account and request.
14
+ * The point is to hold a verification signal that does not share the executing
15
+ * model's uncertainty.
16
+ */
17
+ export type ConditionValue = "true" | "false" | "unknown";
18
+ export interface ConditionObservation {
19
+ readonly snapshotId: string;
20
+ /** Target generation this snapshot belongs to. */
21
+ readonly generation: number;
22
+ readonly values: Readonly<Record<string, ConditionValue>>;
23
+ }
24
+ export interface UnsatisfiedCondition {
25
+ readonly condition: string;
26
+ readonly value: ConditionValue;
27
+ }
28
+ export type CompletionResult = {
29
+ readonly complete: true;
30
+ } | {
31
+ readonly complete: false;
32
+ readonly unsatisfied: readonly UnsatisfiedCondition[];
33
+ };
34
+ /**
35
+ * Every current condition must hold in the *same* snapshot.
36
+ *
37
+ * Evaluating them across snapshots would let a condition that has since
38
+ * flipped keep satisfying the gate.
39
+ */
40
+ export declare function completeCurrent(conditions: readonly string[], snapshot: ConditionObservation): CompletionResult;
41
+ /**
42
+ * Each historical condition must have been observed true at least once in the
43
+ * supplied evidence set, which the caller scopes to the current task.
44
+ */
45
+ export declare function completeEver(conditions: readonly string[], history: readonly ConditionObservation[]): CompletionResult;
46
+ export type EvidenceKind = "authoritative-query" | "structured-remote-linked" | "independent-ui" | "page-success-text" | "model-completion-claim";
47
+ export declare function evidenceStrength(kind: EvidenceKind): number;
48
+ export type VerificationLevel = "REMOTE_EFFECT_VERIFIED" | "UI_VERIFIED" | "CLAIMED_ONLY";
49
+ /**
50
+ * Label a result by the strongest evidence actually held.
51
+ *
52
+ * A UI observation is reported as `UI_VERIFIED`, never as
53
+ * `REMOTE_EFFECT_VERIFIED`: if the target system offers no authoritative
54
+ * query, the honest move is to lower the claimed level, not to borrow one.
55
+ */
56
+ export declare function strongestEvidence(kinds: readonly EvidenceKind[]): VerificationLevel;
57
+ export interface EvidenceItem {
58
+ readonly id: string;
59
+ /** Common-cause group, e.g. one DOM snapshot that many readings derive from. */
60
+ readonly sourceGroup: string;
61
+ }
62
+ export interface EvidenceGrouping {
63
+ readonly independentCount: number;
64
+ readonly byGroup: Readonly<Record<string, number>>;
65
+ }
66
+ /**
67
+ * Collapse correlated readings into their source groups.
68
+ *
69
+ * Fifty screenshots of one screen are one witness. Text, accessibility names
70
+ * and rendered copy from the same DOM share a common cause, so counting them
71
+ * separately inflates apparent independent confirmation.
72
+ */
73
+ export declare function independentEvidenceGroups(items: readonly EvidenceItem[]): EvidenceGrouping;
74
+ export interface VerifierSample {
75
+ readonly verdict: ConditionValue;
76
+ /** Externally established truth, not another model's opinion. */
77
+ readonly truth: "true" | "false";
78
+ }
79
+ export interface VerifierQuality {
80
+ /** Undefined when no negative case was sampled; that is absent evidence. */
81
+ readonly falsePositiveRate: number | undefined;
82
+ readonly falseNegativeRate: number | undefined;
83
+ readonly unknownRate: number;
84
+ readonly samples: number;
85
+ }
86
+ /**
87
+ * Measure the verifier before reporting any success rate.
88
+ *
89
+ * A mislabelling verifier contaminates every downstream selector and bandit
90
+ * trained on its labels, so its error rates are the prior question.
91
+ */
92
+ export declare function verifierQuality(samples: readonly VerifierSample[]): VerifierQuality;
93
+ //# sourceMappingURL=verification.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verification.d.ts","sourceRoot":"","sources":["../../src/metacognition/verification.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC;AAE1D,MAAM,WAAW,oBAAoB;IACpC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,kDAAkD;IAClD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC;CAC1D;AAED,MAAM,WAAW,oBAAoB;IACpC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC;CAC/B;AAED,MAAM,MAAM,gBAAgB,GACzB;IAAE,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAA;CAAE,GAC3B;IAAE,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,WAAW,EAAE,SAAS,oBAAoB,EAAE,CAAA;CAAE,CAAC;AAEvF;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,EAAE,QAAQ,EAAE,oBAAoB,GAAG,gBAAgB,CAS/G;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAC3B,UAAU,EAAE,SAAS,MAAM,EAAE,EAC7B,OAAO,EAAE,SAAS,oBAAoB,EAAE,GACtC,gBAAgB,CAWlB;AAED,MAAM,MAAM,YAAY,GACrB,qBAAqB,GACrB,0BAA0B,GAC1B,gBAAgB,GAChB,mBAAmB,GACnB,wBAAwB,CAAC;AAU5B,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM,CAI3D;AAED,MAAM,MAAM,iBAAiB,GAAG,wBAAwB,GAAG,aAAa,GAAG,cAAc,CAAC;AAE1F;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,SAAS,YAAY,EAAE,GAAG,iBAAiB,CAOnF;AAED,MAAM,WAAW,YAAY;IAC5B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,gFAAgF;IAChF,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,WAAW,gBAAgB;IAChC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACnD;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,SAAS,YAAY,EAAE,GAAG,gBAAgB,CAW1F;AAED,MAAM,WAAW,cAAc;IAC9B,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;IACjC,iEAAiE;IACjE,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;CACjC;AAED,MAAM,WAAW,eAAe;IAC/B,4EAA4E;IAC5E,QAAQ,CAAC,iBAAiB,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/C,QAAQ,CAAC,iBAAiB,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/C,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CACzB;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,SAAS,cAAc,EAAE,GAAG,eAAe,CAuBnF","sourcesContent":["/**\n * Time-aware independent verification (Jev audit algorithm A7, finding F07).\n *\n * F07 is the confusion between \"each condition was satisfied at some point\"\n * and \"they hold together now\". Keeping `CompleteCurrent` and `CompleteEver`\n * apart resolves it without throwing away valid history.\n *\n * `unknown` is a third value, not a synonym for `false`. A missing field or an\n * incomplete collection scope means the evidence is absent; any binary rule\n * that negates it into `true` manufactures a verification that never happened.\n *\n * Evidence strength is ordered but deliberately not a universal trust score:\n * a backend response still has to be matched to the right account and request.\n * The point is to hold a verification signal that does not share the executing\n * model's uncertainty.\n */\n\nimport { ensure } from \"./validation.ts\";\n\nexport type ConditionValue = \"true\" | \"false\" | \"unknown\";\n\nexport interface ConditionObservation {\n\treadonly snapshotId: string;\n\t/** Target generation this snapshot belongs to. */\n\treadonly generation: number;\n\treadonly values: Readonly<Record<string, ConditionValue>>;\n}\n\nexport interface UnsatisfiedCondition {\n\treadonly condition: string;\n\treadonly value: ConditionValue;\n}\n\nexport type CompletionResult =\n\t| { readonly complete: true }\n\t| { readonly complete: false; readonly unsatisfied: readonly UnsatisfiedCondition[] };\n\n/**\n * Every current condition must hold in the *same* snapshot.\n *\n * Evaluating them across snapshots would let a condition that has since\n * flipped keep satisfying the gate.\n */\nexport function completeCurrent(conditions: readonly string[], snapshot: ConditionObservation): CompletionResult {\n\tensure(Array.isArray(conditions) && conditions.length > 0, \"current conditions must be non-empty\");\n\tconst unsatisfied: UnsatisfiedCondition[] = [];\n\tfor (const condition of conditions) {\n\t\t// An absent field is unknown, never false.\n\t\tconst value = snapshot.values[condition] ?? \"unknown\";\n\t\tif (value !== \"true\") unsatisfied.push({ condition, value });\n\t}\n\treturn unsatisfied.length === 0 ? { complete: true } : { complete: false, unsatisfied };\n}\n\n/**\n * Each historical condition must have been observed true at least once in the\n * supplied evidence set, which the caller scopes to the current task.\n */\nexport function completeEver(\n\tconditions: readonly string[],\n\thistory: readonly ConditionObservation[],\n): CompletionResult {\n\tensure(Array.isArray(conditions) && conditions.length > 0, \"ever conditions must be non-empty\");\n\tensure(Array.isArray(history) && history.length > 0, \"history must be non-empty to judge an ever condition\");\n\tconst unsatisfied: UnsatisfiedCondition[] = [];\n\tfor (const condition of conditions) {\n\t\tconst seenTrue = history.some((snapshot) => snapshot.values[condition] === \"true\");\n\t\tif (seenTrue) continue;\n\t\tconst anyKnown = history.some((snapshot) => snapshot.values[condition] === \"false\");\n\t\tunsatisfied.push({ condition, value: anyKnown ? \"false\" : \"unknown\" });\n\t}\n\treturn unsatisfied.length === 0 ? { complete: true } : { complete: false, unsatisfied };\n}\n\nexport type EvidenceKind =\n\t| \"authoritative-query\"\n\t| \"structured-remote-linked\"\n\t| \"independent-ui\"\n\t| \"page-success-text\"\n\t| \"model-completion-claim\";\n\nconst EVIDENCE_RANK: Readonly<Record<EvidenceKind, number>> = {\n\t\"authoritative-query\": 4,\n\t\"structured-remote-linked\": 3,\n\t\"independent-ui\": 2,\n\t\"page-success-text\": 1,\n\t\"model-completion-claim\": 0,\n};\n\nexport function evidenceStrength(kind: EvidenceKind): number {\n\tconst rank = EVIDENCE_RANK[kind];\n\tensure(rank !== undefined, `unknown evidence kind: ${String(kind)}`);\n\treturn rank;\n}\n\nexport type VerificationLevel = \"REMOTE_EFFECT_VERIFIED\" | \"UI_VERIFIED\" | \"CLAIMED_ONLY\";\n\n/**\n * Label a result by the strongest evidence actually held.\n *\n * A UI observation is reported as `UI_VERIFIED`, never as\n * `REMOTE_EFFECT_VERIFIED`: if the target system offers no authoritative\n * query, the honest move is to lower the claimed level, not to borrow one.\n */\nexport function strongestEvidence(kinds: readonly EvidenceKind[]): VerificationLevel {\n\tensure(Array.isArray(kinds) && kinds.length > 0, \"evidence set must be non-empty\");\n\tlet best = -1;\n\tfor (const kind of kinds) best = Math.max(best, evidenceStrength(kind));\n\tif (best >= EVIDENCE_RANK[\"structured-remote-linked\"]) return \"REMOTE_EFFECT_VERIFIED\";\n\tif (best >= EVIDENCE_RANK[\"independent-ui\"]) return \"UI_VERIFIED\";\n\treturn \"CLAIMED_ONLY\";\n}\n\nexport interface EvidenceItem {\n\treadonly id: string;\n\t/** Common-cause group, e.g. one DOM snapshot that many readings derive from. */\n\treadonly sourceGroup: string;\n}\n\nexport interface EvidenceGrouping {\n\treadonly independentCount: number;\n\treadonly byGroup: Readonly<Record<string, number>>;\n}\n\n/**\n * Collapse correlated readings into their source groups.\n *\n * Fifty screenshots of one screen are one witness. Text, accessibility names\n * and rendered copy from the same DOM share a common cause, so counting them\n * separately inflates apparent independent confirmation.\n */\nexport function independentEvidenceGroups(items: readonly EvidenceItem[]): EvidenceGrouping {\n\tensure(Array.isArray(items) && items.length > 0, \"evidence items must be non-empty\");\n\tconst byGroup: Record<string, number> = {};\n\tfor (const item of items) {\n\t\tensure(\n\t\t\ttypeof item.sourceGroup === \"string\" && item.sourceGroup.length > 0,\n\t\t\t\"each evidence item needs a declared sourceGroup\",\n\t\t);\n\t\tbyGroup[item.sourceGroup] = (byGroup[item.sourceGroup] ?? 0) + 1;\n\t}\n\treturn { independentCount: Object.keys(byGroup).length, byGroup };\n}\n\nexport interface VerifierSample {\n\treadonly verdict: ConditionValue;\n\t/** Externally established truth, not another model's opinion. */\n\treadonly truth: \"true\" | \"false\";\n}\n\nexport interface VerifierQuality {\n\t/** Undefined when no negative case was sampled; that is absent evidence. */\n\treadonly falsePositiveRate: number | undefined;\n\treadonly falseNegativeRate: number | undefined;\n\treadonly unknownRate: number;\n\treadonly samples: number;\n}\n\n/**\n * Measure the verifier before reporting any success rate.\n *\n * A mislabelling verifier contaminates every downstream selector and bandit\n * trained on its labels, so its error rates are the prior question.\n */\nexport function verifierQuality(samples: readonly VerifierSample[]): VerifierQuality {\n\tensure(Array.isArray(samples) && samples.length > 0, \"verifier samples must be non-empty\");\n\tlet positives = 0;\n\tlet negatives = 0;\n\tlet falsePositives = 0;\n\tlet falseNegatives = 0;\n\tlet unknowns = 0;\n\tfor (const sample of samples) {\n\t\tif (sample.verdict === \"unknown\") unknowns += 1;\n\t\tif (sample.truth === \"true\") {\n\t\t\tpositives += 1;\n\t\t\tif (sample.verdict === \"false\") falseNegatives += 1;\n\t\t} else {\n\t\t\tnegatives += 1;\n\t\t\tif (sample.verdict === \"true\") falsePositives += 1;\n\t\t}\n\t}\n\treturn {\n\t\tfalsePositiveRate: negatives > 0 ? falsePositives / negatives : undefined,\n\t\tfalseNegativeRate: positives > 0 ? falseNegatives / positives : undefined,\n\t\tunknownRate: unknowns / samples.length,\n\t\tsamples: samples.length,\n\t};\n}\n"]}
@@ -0,0 +1,132 @@
1
+ /**
2
+ * Time-aware independent verification (Jev audit algorithm A7, finding F07).
3
+ *
4
+ * F07 is the confusion between "each condition was satisfied at some point"
5
+ * and "they hold together now". Keeping `CompleteCurrent` and `CompleteEver`
6
+ * apart resolves it without throwing away valid history.
7
+ *
8
+ * `unknown` is a third value, not a synonym for `false`. A missing field or an
9
+ * incomplete collection scope means the evidence is absent; any binary rule
10
+ * that negates it into `true` manufactures a verification that never happened.
11
+ *
12
+ * Evidence strength is ordered but deliberately not a universal trust score:
13
+ * a backend response still has to be matched to the right account and request.
14
+ * The point is to hold a verification signal that does not share the executing
15
+ * model's uncertainty.
16
+ */
17
+ import { ensure } from "./validation.js";
18
+ /**
19
+ * Every current condition must hold in the *same* snapshot.
20
+ *
21
+ * Evaluating them across snapshots would let a condition that has since
22
+ * flipped keep satisfying the gate.
23
+ */
24
+ export function completeCurrent(conditions, snapshot) {
25
+ ensure(Array.isArray(conditions) && conditions.length > 0, "current conditions must be non-empty");
26
+ const unsatisfied = [];
27
+ for (const condition of conditions) {
28
+ // An absent field is unknown, never false.
29
+ const value = snapshot.values[condition] ?? "unknown";
30
+ if (value !== "true")
31
+ unsatisfied.push({ condition, value });
32
+ }
33
+ return unsatisfied.length === 0 ? { complete: true } : { complete: false, unsatisfied };
34
+ }
35
+ /**
36
+ * Each historical condition must have been observed true at least once in the
37
+ * supplied evidence set, which the caller scopes to the current task.
38
+ */
39
+ export function completeEver(conditions, history) {
40
+ ensure(Array.isArray(conditions) && conditions.length > 0, "ever conditions must be non-empty");
41
+ ensure(Array.isArray(history) && history.length > 0, "history must be non-empty to judge an ever condition");
42
+ const unsatisfied = [];
43
+ for (const condition of conditions) {
44
+ const seenTrue = history.some((snapshot) => snapshot.values[condition] === "true");
45
+ if (seenTrue)
46
+ continue;
47
+ const anyKnown = history.some((snapshot) => snapshot.values[condition] === "false");
48
+ unsatisfied.push({ condition, value: anyKnown ? "false" : "unknown" });
49
+ }
50
+ return unsatisfied.length === 0 ? { complete: true } : { complete: false, unsatisfied };
51
+ }
52
+ const EVIDENCE_RANK = {
53
+ "authoritative-query": 4,
54
+ "structured-remote-linked": 3,
55
+ "independent-ui": 2,
56
+ "page-success-text": 1,
57
+ "model-completion-claim": 0,
58
+ };
59
+ export function evidenceStrength(kind) {
60
+ const rank = EVIDENCE_RANK[kind];
61
+ ensure(rank !== undefined, `unknown evidence kind: ${String(kind)}`);
62
+ return rank;
63
+ }
64
+ /**
65
+ * Label a result by the strongest evidence actually held.
66
+ *
67
+ * A UI observation is reported as `UI_VERIFIED`, never as
68
+ * `REMOTE_EFFECT_VERIFIED`: if the target system offers no authoritative
69
+ * query, the honest move is to lower the claimed level, not to borrow one.
70
+ */
71
+ export function strongestEvidence(kinds) {
72
+ ensure(Array.isArray(kinds) && kinds.length > 0, "evidence set must be non-empty");
73
+ let best = -1;
74
+ for (const kind of kinds)
75
+ best = Math.max(best, evidenceStrength(kind));
76
+ if (best >= EVIDENCE_RANK["structured-remote-linked"])
77
+ return "REMOTE_EFFECT_VERIFIED";
78
+ if (best >= EVIDENCE_RANK["independent-ui"])
79
+ return "UI_VERIFIED";
80
+ return "CLAIMED_ONLY";
81
+ }
82
+ /**
83
+ * Collapse correlated readings into their source groups.
84
+ *
85
+ * Fifty screenshots of one screen are one witness. Text, accessibility names
86
+ * and rendered copy from the same DOM share a common cause, so counting them
87
+ * separately inflates apparent independent confirmation.
88
+ */
89
+ export function independentEvidenceGroups(items) {
90
+ ensure(Array.isArray(items) && items.length > 0, "evidence items must be non-empty");
91
+ const byGroup = {};
92
+ for (const item of items) {
93
+ ensure(typeof item.sourceGroup === "string" && item.sourceGroup.length > 0, "each evidence item needs a declared sourceGroup");
94
+ byGroup[item.sourceGroup] = (byGroup[item.sourceGroup] ?? 0) + 1;
95
+ }
96
+ return { independentCount: Object.keys(byGroup).length, byGroup };
97
+ }
98
+ /**
99
+ * Measure the verifier before reporting any success rate.
100
+ *
101
+ * A mislabelling verifier contaminates every downstream selector and bandit
102
+ * trained on its labels, so its error rates are the prior question.
103
+ */
104
+ export function verifierQuality(samples) {
105
+ ensure(Array.isArray(samples) && samples.length > 0, "verifier samples must be non-empty");
106
+ let positives = 0;
107
+ let negatives = 0;
108
+ let falsePositives = 0;
109
+ let falseNegatives = 0;
110
+ let unknowns = 0;
111
+ for (const sample of samples) {
112
+ if (sample.verdict === "unknown")
113
+ unknowns += 1;
114
+ if (sample.truth === "true") {
115
+ positives += 1;
116
+ if (sample.verdict === "false")
117
+ falseNegatives += 1;
118
+ }
119
+ else {
120
+ negatives += 1;
121
+ if (sample.verdict === "true")
122
+ falsePositives += 1;
123
+ }
124
+ }
125
+ return {
126
+ falsePositiveRate: negatives > 0 ? falsePositives / negatives : undefined,
127
+ falseNegativeRate: positives > 0 ? falseNegatives / positives : undefined,
128
+ unknownRate: unknowns / samples.length,
129
+ samples: samples.length,
130
+ };
131
+ }
132
+ //# sourceMappingURL=verification.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verification.js","sourceRoot":"","sources":["../../src/metacognition/verification.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAoBzC;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,UAA6B,EAAE,QAA8B,EAAoB;IAChH,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,sCAAsC,CAAC,CAAC;IACnG,MAAM,WAAW,GAA2B,EAAE,CAAC;IAC/C,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACpC,2CAA2C;QAC3C,MAAM,KAAK,GAAG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cAAc,IAAI,CAAC,CAAC;QACpD,CAAC;IACF,CAAC;IACD,OAAO;QACN,iBAAiB,EAAE,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC,cAAc,GAAG,SAAS,CAAC,CAAC,CAAC,SAAS;QACzE,iBAAiB,EAAE,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC,cAAc,GAAG,SAAS,CAAC,CAAC,CAAC,SAAS;QACzE,WAAW,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM;QACtC,OAAO,EAAE,OAAO,CAAC,MAAM;KACvB,CAAC;AAAA,CACF","sourcesContent":["/**\n * Time-aware independent verification (Jev audit algorithm A7, finding F07).\n *\n * F07 is the confusion between \"each condition was satisfied at some point\"\n * and \"they hold together now\". Keeping `CompleteCurrent` and `CompleteEver`\n * apart resolves it without throwing away valid history.\n *\n * `unknown` is a third value, not a synonym for `false`. A missing field or an\n * incomplete collection scope means the evidence is absent; any binary rule\n * that negates it into `true` manufactures a verification that never happened.\n *\n * Evidence strength is ordered but deliberately not a universal trust score:\n * a backend response still has to be matched to the right account and request.\n * The point is to hold a verification signal that does not share the executing\n * model's uncertainty.\n */\n\nimport { ensure } from \"./validation.ts\";\n\nexport type ConditionValue = \"true\" | \"false\" | \"unknown\";\n\nexport interface ConditionObservation {\n\treadonly snapshotId: string;\n\t/** Target generation this snapshot belongs to. */\n\treadonly generation: number;\n\treadonly values: Readonly<Record<string, ConditionValue>>;\n}\n\nexport interface UnsatisfiedCondition {\n\treadonly condition: string;\n\treadonly value: ConditionValue;\n}\n\nexport type CompletionResult =\n\t| { readonly complete: true }\n\t| { readonly complete: false; readonly unsatisfied: readonly UnsatisfiedCondition[] };\n\n/**\n * Every current condition must hold in the *same* snapshot.\n *\n * Evaluating them across snapshots would let a condition that has since\n * flipped keep satisfying the gate.\n */\nexport function completeCurrent(conditions: readonly string[], snapshot: ConditionObservation): CompletionResult {\n\tensure(Array.isArray(conditions) && conditions.length > 0, \"current conditions must be non-empty\");\n\tconst unsatisfied: UnsatisfiedCondition[] = [];\n\tfor (const condition of conditions) {\n\t\t// An absent field is unknown, never false.\n\t\tconst value = snapshot.values[condition] ?? \"unknown\";\n\t\tif (value !== \"true\") unsatisfied.push({ condition, value });\n\t}\n\treturn unsatisfied.length === 0 ? { complete: true } : { complete: false, unsatisfied };\n}\n\n/**\n * Each historical condition must have been observed true at least once in the\n * supplied evidence set, which the caller scopes to the current task.\n */\nexport function completeEver(\n\tconditions: readonly string[],\n\thistory: readonly ConditionObservation[],\n): CompletionResult {\n\tensure(Array.isArray(conditions) && conditions.length > 0, \"ever conditions must be non-empty\");\n\tensure(Array.isArray(history) && history.length > 0, \"history must be non-empty to judge an ever condition\");\n\tconst unsatisfied: UnsatisfiedCondition[] = [];\n\tfor (const condition of conditions) {\n\t\tconst seenTrue = history.some((snapshot) => snapshot.values[condition] === \"true\");\n\t\tif (seenTrue) continue;\n\t\tconst anyKnown = history.some((snapshot) => snapshot.values[condition] === \"false\");\n\t\tunsatisfied.push({ condition, value: anyKnown ? \"false\" : \"unknown\" });\n\t}\n\treturn unsatisfied.length === 0 ? { complete: true } : { complete: false, unsatisfied };\n}\n\nexport type EvidenceKind =\n\t| \"authoritative-query\"\n\t| \"structured-remote-linked\"\n\t| \"independent-ui\"\n\t| \"page-success-text\"\n\t| \"model-completion-claim\";\n\nconst EVIDENCE_RANK: Readonly<Record<EvidenceKind, number>> = {\n\t\"authoritative-query\": 4,\n\t\"structured-remote-linked\": 3,\n\t\"independent-ui\": 2,\n\t\"page-success-text\": 1,\n\t\"model-completion-claim\": 0,\n};\n\nexport function evidenceStrength(kind: EvidenceKind): number {\n\tconst rank = EVIDENCE_RANK[kind];\n\tensure(rank !== undefined, `unknown evidence kind: ${String(kind)}`);\n\treturn rank;\n}\n\nexport type VerificationLevel = \"REMOTE_EFFECT_VERIFIED\" | \"UI_VERIFIED\" | \"CLAIMED_ONLY\";\n\n/**\n * Label a result by the strongest evidence actually held.\n *\n * A UI observation is reported as `UI_VERIFIED`, never as\n * `REMOTE_EFFECT_VERIFIED`: if the target system offers no authoritative\n * query, the honest move is to lower the claimed level, not to borrow one.\n */\nexport function strongestEvidence(kinds: readonly EvidenceKind[]): VerificationLevel {\n\tensure(Array.isArray(kinds) && kinds.length > 0, \"evidence set must be non-empty\");\n\tlet best = -1;\n\tfor (const kind of kinds) best = Math.max(best, evidenceStrength(kind));\n\tif (best >= EVIDENCE_RANK[\"structured-remote-linked\"]) return \"REMOTE_EFFECT_VERIFIED\";\n\tif (best >= EVIDENCE_RANK[\"independent-ui\"]) return \"UI_VERIFIED\";\n\treturn \"CLAIMED_ONLY\";\n}\n\nexport interface EvidenceItem {\n\treadonly id: string;\n\t/** Common-cause group, e.g. one DOM snapshot that many readings derive from. */\n\treadonly sourceGroup: string;\n}\n\nexport interface EvidenceGrouping {\n\treadonly independentCount: number;\n\treadonly byGroup: Readonly<Record<string, number>>;\n}\n\n/**\n * Collapse correlated readings into their source groups.\n *\n * Fifty screenshots of one screen are one witness. Text, accessibility names\n * and rendered copy from the same DOM share a common cause, so counting them\n * separately inflates apparent independent confirmation.\n */\nexport function independentEvidenceGroups(items: readonly EvidenceItem[]): EvidenceGrouping {\n\tensure(Array.isArray(items) && items.length > 0, \"evidence items must be non-empty\");\n\tconst byGroup: Record<string, number> = {};\n\tfor (const item of items) {\n\t\tensure(\n\t\t\ttypeof item.sourceGroup === \"string\" && item.sourceGroup.length > 0,\n\t\t\t\"each evidence item needs a declared sourceGroup\",\n\t\t);\n\t\tbyGroup[item.sourceGroup] = (byGroup[item.sourceGroup] ?? 0) + 1;\n\t}\n\treturn { independentCount: Object.keys(byGroup).length, byGroup };\n}\n\nexport interface VerifierSample {\n\treadonly verdict: ConditionValue;\n\t/** Externally established truth, not another model's opinion. */\n\treadonly truth: \"true\" | \"false\";\n}\n\nexport interface VerifierQuality {\n\t/** Undefined when no negative case was sampled; that is absent evidence. */\n\treadonly falsePositiveRate: number | undefined;\n\treadonly falseNegativeRate: number | undefined;\n\treadonly unknownRate: number;\n\treadonly samples: number;\n}\n\n/**\n * Measure the verifier before reporting any success rate.\n *\n * A mislabelling verifier contaminates every downstream selector and bandit\n * trained on its labels, so its error rates are the prior question.\n */\nexport function verifierQuality(samples: readonly VerifierSample[]): VerifierQuality {\n\tensure(Array.isArray(samples) && samples.length > 0, \"verifier samples must be non-empty\");\n\tlet positives = 0;\n\tlet negatives = 0;\n\tlet falsePositives = 0;\n\tlet falseNegatives = 0;\n\tlet unknowns = 0;\n\tfor (const sample of samples) {\n\t\tif (sample.verdict === \"unknown\") unknowns += 1;\n\t\tif (sample.truth === \"true\") {\n\t\t\tpositives += 1;\n\t\t\tif (sample.verdict === \"false\") falseNegatives += 1;\n\t\t} else {\n\t\t\tnegatives += 1;\n\t\t\tif (sample.verdict === \"true\") falsePositives += 1;\n\t\t}\n\t}\n\treturn {\n\t\tfalsePositiveRate: negatives > 0 ? falsePositives / negatives : undefined,\n\t\tfalseNegativeRate: positives > 0 ? falseNegatives / positives : undefined,\n\t\tunknownRate: unknowns / samples.length,\n\t\tsamples: samples.length,\n\t};\n}\n"]}
@@ -0,0 +1,49 @@
1
+ export type MutantClass = "killed-intended" | "survived" | "equivalent" | "invalid-compile" | "environment-failure" | "timeout" | "killed-unintended";
2
+ export interface MutantRecord {
3
+ readonly mutantId: string;
4
+ readonly obligationId: string;
5
+ /** The host classifies the outcome; this module never guesses. */
6
+ readonly classification: MutantClass;
7
+ /** Whether the intended obligation violation was what the check caught. */
8
+ readonly intendedViolation: boolean;
9
+ }
10
+ export interface VerifierEvaluation {
11
+ readonly obligationId: string;
12
+ /** D_v over valid non-equivalent mutants; "unknown" when empty. */
13
+ readonly detectionRate: number | "unknown";
14
+ readonly evaluated: number;
15
+ readonly excluded: Readonly<Record<Exclude<MutantClass, "killed-intended" | "survived">, number>>;
16
+ readonly survivingMutantIds: readonly string[];
17
+ readonly blindSpots: readonly string[];
18
+ }
19
+ export declare function evaluateVerifier(obligationId: string, mutants: readonly MutantRecord[], checksValidOnHealthy: boolean): VerifierEvaluation;
20
+ /**
21
+ * §7.4 metamorphic relation: Pre(x,T) ⟹ R(f(x), f(T(x))). The relation must
22
+ * be a declared required property of this program — never a universal rule.
23
+ */
24
+ export interface MetamorphicRelation {
25
+ readonly relationId: string;
26
+ readonly description: string;
27
+ readonly precondition: string;
28
+ readonly requiredProperty: boolean;
29
+ }
30
+ export declare function relationApplicable(rel: MetamorphicRelation): boolean;
31
+ /** §10.1 progress key: same key + no new adopted evidence = repetition. */
32
+ export interface ProgressKey {
33
+ readonly goalScope: string;
34
+ readonly candidateFamily: string;
35
+ readonly errorClass: string;
36
+ readonly approach: string;
37
+ readonly checkMethod: string;
38
+ readonly sourceFamily: string;
39
+ }
40
+ export declare function progressKey(k: ProgressKey): string;
41
+ export declare function isStagnant(current: ProgressKey, history: readonly {
42
+ key: string;
43
+ newEvidence: boolean;
44
+ resolvedObligations: number;
45
+ newValidChecks: number;
46
+ }[], maxRepetitions: number): boolean;
47
+ /** §10.2 net strategy-switch score with hysteresis margin. */
48
+ export declare function netSwitchValue(estimatedLossDelta: number, cost: number, switchCost: number): number;
49
+ //# sourceMappingURL=verifier.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verifier.d.ts","sourceRoot":"","sources":["../../src/metacognition/verifier.ts"],"names":[],"mappings":"AAYA,MAAM,MAAM,WAAW,GACpB,iBAAiB,GACjB,UAAU,GACV,YAAY,GACZ,iBAAiB,GACjB,qBAAqB,GACrB,SAAS,GACT,mBAAmB,CAAC;AACvB,MAAM,WAAW,YAAY;IAC5B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,kEAAkE;IAClE,QAAQ,CAAC,cAAc,EAAE,WAAW,CAAC;IACrC,2EAA2E;IAC3E,QAAQ,CAAC,iBAAiB,EAAE,OAAO,CAAC;CACpC;AACD,MAAM,WAAW,kBAAkB;IAClC,QAAQ,CAAC,YAAY,EAAE,MAAM,C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O,EAAE,SAAS;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,OAAO,CAAC;IAAC,mBAAmB,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,MAAM,CAAA;CAAE,EAAE,EAC9G,cAAc,EAAE,MAAM,GACpB,OAAO,CAUT;AAED,+DAA8D;AAC9D,wBAAgB,cAAc,CAAC,kBAAkB,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAKnG","sourcesContent":["/**\n * Algorithm D — meta-verification: checking that a check detects the defect\n * it claims to cover. Spec §7.\n *\n * Obligation-scoped negative controls are evaluated over VALID, non-equivalent\n * mutants only. Environment failures, compile-broken mutants, and timeouts are\n * never counted as semantic detections. An empty denominator is `unknown`,\n * never a score. This is an empirical detection rate for this mutant set,\n * not the probability the code is correct.\n */\nimport { ensure, finite, integer, lexical, member, text, unique } from \"./validation.ts\";\n\nexport type MutantClass =\n\t| \"killed-intended\"\n\t| \"survived\"\n\t| \"equivalent\"\n\t| \"invalid-compile\"\n\t| \"environment-failure\"\n\t| \"timeout\"\n\t| \"killed-unintended\";\nexport interface MutantRecord {\n\treadonly mutantId: string;\n\treadonly obligationId: string;\n\t/** The host classifies the outcome; this module never guesses. */\n\treadonly classification: MutantClass;\n\t/** Whether the intended obligation violation was what the check caught. */\n\treadonly intendedViolation: boolean;\n}\nexport interface VerifierEvaluation {\n\treadonly obligationId: string;\n\t/** D_v over valid non-equivalent mutants; \"unknown\" when empty. */\n\treadonly detectionRate: number | \"unknown\";\n\treadonly evaluated: number;\n\treadonly excluded: Readonly<Record<Exclude<MutantClass, \"killed-intended\" | \"survived\">, number>>;\n\treadonly survivingMutantIds: readonly string[];\n\treadonly blindSpots: readonly string[];\n}\n\nconst MUTANT_BOUND = 1024;\n\nexport function evaluateVerifier(\n\tobligationId: string,\n\tmutants: readonly MutantRecord[],\n\tchecksValidOnHealthy: boolean,\n): VerifierEvaluation {\n\ttext(obligationId, \"obligationId\", 256);\n\tensure(mutants.length <= MUTANT_BOUND, \"too many mutants\");\n\tunique(\n\t\tmutants.map((m) => m.mutantId),\n\t\t\"mutant ids\",\n\t);\n\tconst scoped = mutants.filter((m) => m.obligationId === obligationId);\n\tconst excluded: Record<Exclude<MutantClass, \"killed-intended\" | \"survived\">, number> = {\n\t\tequivalent: 0,\n\t\t\"invalid-compile\": 0,\n\t\t\"environment-failure\": 0,\n\t\ttimeout: 0,\n\t\t\"killed-unintended\": 0,\n\t};\n\tlet detected = 0;\n\tconst survivors: string[] = [];\n\tconst blindSpots: string[] = [];\n\tfor (const m of scoped) {\n\t\tmember(\n\t\t\tm.classification,\n\t\t\t[\n\t\t\t\t\"killed-intended\",\n\t\t\t\t\"survived\",\n\t\t\t\t\"equivalent\",\n\t\t\t\t\"invalid-compile\",\n\t\t\t\t\"environment-failure\",\n\t\t\t\t\"timeout\",\n\t\t\t\t\"killed-unintended\",\n\t\t\t],\n\t\t\t\"mutant classification\",\n\t\t);\n\t\tif (m.classification === \"killed-intended\" && m.intendedViolation) {\n\t\t\tdetected += 1;\n\t\t} else if (m.classification === \"survived\") {\n\t\t\tsurvivors.push(m.mutantId);\n\t\t\tblindSpots.push(`undetected-violation:${m.mutantId}`);\n\t\t} else {\n\t\t\texcluded[m.classification as keyof typeof excluded] += 1;\n\t\t\tif (m.classification === \"invalid-compile\" || m.classification === \"environment-failure\") {\n\t\t\t\tblindSpots.push(`uninformative-mutant:${m.mutantId}`);\n\t\t\t}\n\t\t}\n\t}\n\tif (!checksValidOnHealthy) blindSpots.push(\"check-invalid-on-healthy-candidate\");\n\tconst denominator = detected + survivors.length;\n\treturn {\n\t\tobligationId,\n\t\tdetectionRate: denominator === 0 ? \"unknown\" : detected / denominator,\n\t\tevaluated: denominator,\n\t\texcluded,\n\t\tsurvivingMutantIds: survivors.sort(lexical),\n\t\tblindSpots: blindSpots.sort(lexical),\n\t};\n}\n\n/**\n * §7.4 metamorphic relation: Pre(x,T) ⟹ R(f(x), f(T(x))). The relation must\n * be a declared required property of this program — never a universal rule.\n */\nexport interface MetamorphicRelation {\n\treadonly relationId: string;\n\treadonly description: string;\n\treadonly precondition: string;\n\treadonly requiredProperty: boolean;\n}\nexport function relationApplicable(rel: MetamorphicRelation): boolean {\n\treturn rel.requiredProperty;\n}\n\n/** §10.1 progress key: same key + no new adopted evidence = repetition. */\nexport interface ProgressKey {\n\treadonly goalScope: string;\n\treadonly candidateFamily: string;\n\treadonly errorClass: string;\n\treadonly approach: string;\n\treadonly checkMethod: string;\n\treadonly sourceFamily: string;\n}\nexport function progressKey(k: ProgressKey): string {\n\treturn [k.goalScope, k.candidateFamily, k.errorClass, k.approach, k.checkMethod, k.sourceFamily].join(\"\\u001f\");\n}\nexport function isStagnant(\n\tcurrent: ProgressKey,\n\thistory: readonly { key: string; newEvidence: boolean; resolvedObligations: number; newValidChecks: number }[],\n\tmaxRepetitions: number,\n): boolean {\n\tinteger(maxRepetitions, \"maxRepetitions\", 64);\n\tconst key = progressKey(current);\n\tlet repeats = 0;\n\tfor (const entry of history) {\n\t\tif (entry.key === key && !entry.newEvidence && entry.resolvedObligations === 0 && entry.newValidChecks === 0) {\n\t\t\trepeats += 1;\n\t\t}\n\t}\n\treturn repeats >= maxRepetitions;\n}\n\n/** §10.2 net strategy-switch score with hysteresis margin. */\nexport function netSwitchValue(estimatedLossDelta: number, cost: number, switchCost: number): number {\n\tfinite(estimatedLossDelta, \"estimatedLossDelta\");\n\tfinite(cost, \"cost\");\n\tfinite(switchCost, \"switchCost\");\n\treturn estimatedLossDelta - cost - switchCost;\n}\n"]}
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Algorithm D — meta-verification: checking that a check detects the defect
3
+ * it claims to cover. Spec §7.
4
+ *
5
+ * Obligation-scoped negative controls are evaluated over VALID, non-equivalent
6
+ * mutants only. Environment failures, compile-broken mutants, and timeouts are
7
+ * never counted as semantic detections. An empty denominator is `unknown`,
8
+ * never a score. This is an empirical detection rate for this mutant set,
9
+ * not the probability the code is correct.
10
+ */
11
+ import { ensure, finite, integer, lexical, member, text, unique } from "./validation.js";
12
+ const MUTANT_BOUND = 1024;
13
+ export function evaluateVerifier(obligationId, mutants, checksValidOnHealthy) {
14
+ text(obligationId, "obligationId", 256);
15
+ ensure(mutants.length <= MUTANT_BOUND, "too many mutants");
16
+ unique(mutants.map((m) => m.mutantId), "mutant ids");
17
+ const scoped = mutants.filter((m) => m.obligationId === obligationId);
18
+ const excluded = {
19
+ equivalent: 0,
20
+ "invalid-compile": 0,
21
+ "environment-failure": 0,
22
+ timeout: 0,
23
+ "killed-unintended": 0,
24
+ };
25
+ let detected = 0;
26
+ const survivors = [];
27
+ const blindSpots = [];
28
+ for (const m of scoped) {
29
+ member(m.classification, [
30
+ "killed-intended",
31
+ "survived",
32
+ "equivalent",
33
+ "invalid-compile",
34
+ "environment-failure",
35
+ "timeout",
36
+ "killed-unintended",
37
+ ], "mutant classification");
38
+ if (m.classification === "killed-intended" && m.intendedViolation) {
39
+ detected += 1;
40
+ }
41
+ else if (m.classification === "survived") {
42
+ survivors.push(m.mutantId);
43
+ blindSpots.push(`undetected-violation:${m.mutantId}`);
44
+ }
45
+ else {
46
+ excluded[m.classification] += 1;
47
+ if (m.classification === "invalid-compile" || m.classification === "environment-failure") {
48
+ blindSpots.push(`uninformative-mutant:${m.mutantId}`);
49
+ }
50
+ }
51
+ }
52
+ if (!checksValidOnHealthy)
53
+ blindSpots.push("check-invalid-on-healthy-candidate");
54
+ const denominator = detected + survivors.length;
55
+ return {
56
+ obligationId,
57
+ detectionRate: denominator === 0 ? "unknown" : detected / denominator,
58
+ evaluated: denominator,
59
+ excluded,
60
+ survivingMutantIds: survivors.sort(lexical),
61
+ blindSpots: blindSpots.sort(lexical),
62
+ };
63
+ }
64
+ export function relationApplicable(rel) {
65
+ return rel.requiredProperty;
66
+ }
67
+ export function progressKey(k) {
68
+ return [k.goalScope, k.candidateFamily, k.errorClass, k.approach, k.checkMethod, k.sourceFamily].join("\u001f");
69
+ }
70
+ export function isStagnant(current, history, maxRepetitions) {
71
+ integer(maxRepetitions, "maxRepetitions", 64);
72
+ const key = progressKey(current);
73
+ let repeats = 0;
74
+ for (const entry of history) {
75
+ if (entry.key === key && !entry.newEvidence && entry.resolvedObligations === 0 && entry.newValidChecks === 0) {
76
+ repeats += 1;
77
+ }
78
+ }
79
+ return repeats >= maxRepetitions;
80
+ }
81
+ /** §10.2 net strategy-switch score with hysteresis margin. */
82
+ export function netSwitchValue(estimatedLossDelta, cost, switchCost) {
83
+ finite(estimatedLossDelta, "estimatedLossDelta");
84
+ finite(cost, "cost");
85
+ finite(switchCost, "switchCost");
86
+ return estimatedLossDelta - cost - switchCost;
87
+ }
88
+ //# sourceMappingURL=verifier.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verifier.js","sourceRoot":"","sources":["../../src/metacognition/verifier.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AA4BzF,MAAM,YAAY,GAAG,IAAI,CAAC;AAE1B,MAAM,UAAU,gBAAgB,CAC/B,YAAoB,EACpB,OAAgC,EAChC,oBAA6B,EACR;IACrB,IAAI,CAAC,YAAY,EAAE,cAAc,EAAE,GAAG,CAAC,CAAC;IACxC,MAAM,CAAC,OAAO,CAAC,MAAM,IAAI,YAAY,EAAE,kBAAkB,CAAC,CAAC;IAC3D,MAAM,CACL,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAC9B,YAAY,CACZ,CAAC;IACF,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,YAAY,KAAK,YAAY,CAAC,CAAC;IACtE,MAAM,QAAQ,GAAyE;QACtF,UAAU,EAAE,C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AAkB,EAAE,oBAAoB,CAAC,CAAC;IACjD,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACrB,MAAM,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;IACjC,OAAO,kBAAkB,GAAG,IAAI,GAAG,UAAU,CAAC;AAAA,CAC9C","sourcesContent":["/**\n * Algorithm D — meta-verification: checking that a check detects the defect\n * it claims to cover. Spec §7.\n *\n * Obligation-scoped negative controls are evaluated over VALID, non-equivalent\n * mutants only. Environment failures, compile-broken mutants, and timeouts are\n * never counted as semantic detections. An empty denominator is `unknown`,\n * never a score. This is an empirical detection rate for this mutant set,\n * not the probability the code is correct.\n */\nimport { ensure, finite, integer, lexical, member, text, unique } from \"./validation.ts\";\n\nexport type MutantClass =\n\t| \"killed-intended\"\n\t| \"survived\"\n\t| \"equivalent\"\n\t| \"invalid-compile\"\n\t| \"environment-failure\"\n\t| \"timeout\"\n\t| \"killed-unintended\";\nexport interface MutantRecord {\n\treadonly mutantId: string;\n\treadonly obligationId: string;\n\t/** The host classifies the outcome; this module never guesses. */\n\treadonly classification: MutantClass;\n\t/** Whether the intended obligation violation was what the check caught. */\n\treadonly intendedViolation: boolean;\n}\nexport interface VerifierEvaluation {\n\treadonly obligationId: string;\n\t/** D_v over valid non-equivalent mutants; \"unknown\" when empty. */\n\treadonly detectionRate: number | \"unknown\";\n\treadonly evaluated: number;\n\treadonly excluded: Readonly<Record<Exclude<MutantClass, \"killed-intended\" | \"survived\">, number>>;\n\treadonly survivingMutantIds: readonly string[];\n\treadonly blindSpots: readonly string[];\n}\n\nconst MUTANT_BOUND = 1024;\n\nexport function evaluateVerifier(\n\tobligationId: string,\n\tmutants: readonly MutantRecord[],\n\tchecksValidOnHealthy: boolean,\n): VerifierEvaluation {\n\ttext(obligationId, \"obligationId\", 256);\n\tensure(mutants.length <= MUTANT_BOUND, \"too many mutants\");\n\tunique(\n\t\tmutants.map((m) => m.mutantId),\n\t\t\"mutant ids\",\n\t);\n\tconst scoped = mutants.filter((m) => m.obligationId === obligationId);\n\tconst excluded: Record<Exclude<MutantClass, \"killed-intended\" | \"survived\">, number> = {\n\t\tequivalent: 0,\n\t\t\"invalid-compile\": 0,\n\t\t\"environment-failure\": 0,\n\t\ttimeout: 0,\n\t\t\"killed-unintended\": 0,\n\t};\n\tlet detected = 0;\n\tconst survivors: string[] = [];\n\tconst blindSpots: string[] = [];\n\tfor (const m of scoped) {\n\t\tmember(\n\t\t\tm.classification,\n\t\t\t[\n\t\t\t\t\"killed-intended\",\n\t\t\t\t\"survived\",\n\t\t\t\t\"equivalent\",\n\t\t\t\t\"invalid-compile\",\n\t\t\t\t\"environment-failure\",\n\t\t\t\t\"timeout\",\n\t\t\t\t\"killed-unintended\",\n\t\t\t],\n\t\t\t\"mutant classification\",\n\t\t);\n\t\tif (m.classification === \"killed-intended\" && m.intendedViolation) {\n\t\t\tdetected += 1;\n\t\t} else if (m.classification === \"survived\") {\n\t\t\tsurvivors.push(m.mutantId);\n\t\t\tblindSpots.push(`undetected-violation:${m.mutantId}`);\n\t\t} else {\n\t\t\texcluded[m.classification as keyof typeof excluded] += 1;\n\t\t\tif (m.classification === \"invalid-compile\" || m.classification === \"environment-failure\") {\n\t\t\t\tblindSpots.push(`uninformative-mutant:${m.mutantId}`);\n\t\t\t}\n\t\t}\n\t}\n\tif (!checksValidOnHealthy) blindSpots.push(\"check-invalid-on-healthy-candidate\");\n\tconst denominator = detected + survivors.length;\n\treturn {\n\t\tobligationId,\n\t\tdetectionRate: denominator === 0 ? \"unknown\" : detected / denominator,\n\t\tevaluated: denominator,\n\t\texcluded,\n\t\tsurvivingMutantIds: survivors.sort(lexical),\n\t\tblindSpots: blindSpots.sort(lexical),\n\t};\n}\n\n/**\n * §7.4 metamorphic relation: Pre(x,T) ⟹ R(f(x), f(T(x))). The relation must\n * be a declared required property of this program — never a universal rule.\n */\nexport interface MetamorphicRelation {\n\treadonly relationId: string;\n\treadonly description: string;\n\treadonly precondition: string;\n\treadonly requiredProperty: boolean;\n}\nexport function relationApplicable(rel: MetamorphicRelation): boolean {\n\treturn rel.requiredProperty;\n}\n\n/** §10.1 progress key: same key + no new adopted evidence = repetition. */\nexport interface ProgressKey {\n\treadonly goalScope: string;\n\treadonly candidateFamily: string;\n\treadonly errorClass: string;\n\treadonly approach: string;\n\treadonly checkMethod: string;\n\treadonly sourceFamily: string;\n}\nexport function progressKey(k: ProgressKey): string {\n\treturn [k.goalScope, k.candidateFamily, k.errorClass, k.approach, k.checkMethod, k.sourceFamily].join(\"\\u001f\");\n}\nexport function isStagnant(\n\tcurrent: ProgressKey,\n\thistory: readonly { key: string; newEvidence: boolean; resolvedObligations: number; newValidChecks: number }[],\n\tmaxRepetitions: number,\n): boolean {\n\tinteger(maxRepetitions, \"maxRepetitions\", 64);\n\tconst key = progressKey(current);\n\tlet repeats = 0;\n\tfor (const entry of history) {\n\t\tif (entry.key === key && !entry.newEvidence && entry.resolvedObligations === 0 && entry.newValidChecks === 0) {\n\t\t\trepeats += 1;\n\t\t}\n\t}\n\treturn repeats >= maxRepetitions;\n}\n\n/** §10.2 net strategy-switch score with hysteresis margin. */\nexport function netSwitchValue(estimatedLossDelta: number, cost: number, switchCost: number): number {\n\tfinite(estimatedLossDelta, \"estimatedLossDelta\");\n\tfinite(cost, \"cost\");\n\tfinite(switchCost, \"switchCost\");\n\treturn estimatedLossDelta - cost - switchCost;\n}\n"]}
@@ -10,11 +10,13 @@ export declare class AssistantMessageComponent extends Container {
10
10
  private hiddenThinkingLabel;
11
11
  private lastMessage?;
12
12
  private hasToolCalls;
13
+ private readonly contentViews;
13
14
  constructor(message?: AssistantMessage, hideThinkingBlock?: boolean, markdownTheme?: MarkdownTheme, hiddenThinkingLabel?: string);
14
15
  invalidate(): void;
15
16
  setHideThinkingBlock(hide: boolean): void;
16
17
  setHiddenThinkingLabel(label: string): void;
17
18
  render(width: number): string[];
19
+ private contentView;
18
20
  updateContent(message: AssistantMessage): void;
19
21
  }
20
22
  //# sourceMappingURL=assistant-message.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"assistant-message.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/assistant-message.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAY,KAAK,aAAa,EAAgB,MAAM,SAAS,CAAC;AAOhF;;GAEG;AACH,qBAAa,yBAA0B,SAAQ,SAAS;IACvD,OAAO,CAAC,gBAAgB,CAAY;IACpC,OAAO,CAAC,iBAAiB,CAAU;IACnC,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,mBAAmB,CAAS;IACpC,OAAO,CAAC,WAAW,CAAC,CAAmB;IACvC,OAAO,CAAC,YAAY,CAAS;IAE7B,YACC,OAAO,CAAC,EAAE,gBAAgB,EAC1B,iBAAiB,UAAQ,EACzB,aAAa,GAAE,aAAkC,EACjD,mBAAmB,SAAgB,EAenC;IAEQ,UAAU,IAAI,IAAI,CAK1B;IAED,oBAAoB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAKxC;IAED,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAK1C;IAEQ,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CASvC;IAED,aAAa,CAAC,OAAO,EAAE,gBAAgB,GAAG,IAAI,CAyE7C;CACD","sourcesContent":["import type { AssistantMessage } from \"omk-ai\";\nimport { Container, Markdown, type MarkdownTheme, Spacer, Text } from \"omk-tui\";\nimport { getMarkdownTheme, theme } from \"../theme/theme.ts\";\n\nconst OSC133_ZONE_START = \"\\x1b]133;A\\x07\";\nconst OSC133_ZONE_END = \"\\x1b]133;B\\x07\";\nconst OSC133_ZONE_FINAL = \"\\x1b]133;C\\x07\";\n\n/**\n * Component that renders a complete assistant message\n */\nexport class AssistantMessageComponent extends Container {\n\tprivate contentContainer: Container;\n\tprivate hideThinkingBlock: boolean;\n\tprivate markdownTheme: MarkdownTheme;\n\tprivate hiddenThinkingLabel: string;\n\tprivate lastMessage?: AssistantMessage;\n\tprivate hasToolCalls = false;\n\n\tconstructor(\n\t\tmessage?: AssistantMessage,\n\t\thideThinkingBlock = false,\n\t\tmarkdownTheme: MarkdownTheme = getMarkdownTheme(),\n\t\thiddenThinkingLabel = \"Thinking...\",\n\t) {\n\t\tsuper();\n\n\t\tthis.hideThinkingBlock = hideThinkingBlock;\n\t\tthis.markdownTheme = markdownTheme;\n\t\tthis.hiddenThinkingLabel = hiddenThinkingLabel;\n\n\t\t// Container for text/thinking content\n\t\tthis.contentContainer = new Container();\n\t\tthis.addChild(this.contentContainer);\n\n\t\tif (message) {\n\t\t\tthis.updateContent(message);\n\t\t}\n\t}\n\n\toverride invalidate(): void {\n\t\tsuper.invalidate();\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage);\n\t\t}\n\t}\n\n\tsetHideThinkingBlock(hide: boolean): void {\n\t\tthis.hideThinkingBlock = hide;\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage);\n\t\t}\n\t}\n\n\tsetHiddenThinkingLabel(label: string): void {\n\t\tthis.hiddenThinkingLabel = label;\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage);\n\t\t}\n\t}\n\n\toverride render(width: number): string[] {\n\t\tconst lines = super.render(width);\n\t\tif (this.hasToolCalls || lines.length === 0) {\n\t\t\treturn lines;\n\t\t}\n\n\t\tlines[0] = OSC133_ZONE_START + lines[0];\n\t\tlines[lines.length - 1] = OSC133_ZONE_END + OSC133_ZONE_FINAL + lines[lines.length - 1];\n\t\treturn lines;\n\t}\n\n\tupdateContent(message: AssistantMessage): void {\n\t\tthis.lastMessage = message;\n\n\t\t// Clear content container\n\t\tthis.contentContainer.clear();\n\n\t\tconst hasVisibleContent = message.content.some(\n\t\t\t(c) => (c.type === \"text\" && c.text.trim()) || (c.type === \"thinking\" && c.thinking.trim()),\n\t\t);\n\n\t\tif (hasVisibleContent) {\n\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t}\n\n\t\t// Render content in order\n\t\tfor (let i = 0; i < message.content.length; i++) {\n\t\t\tconst content = message.content[i];\n\t\t\tif (content.type === \"text\" && content.text.trim()) {\n\t\t\t\t// Assistant text messages with no background - trim the text\n\t\t\t\t// Set paddingY=0 to avoid extra spacing before tool executions\n\t\t\t\tthis.contentContainer.addChild(new Markdown(content.text.trim(), 1, 0, this.markdownTheme));\n\t\t\t} else if (content.type === \"thinking\" && content.thinking.trim()) {\n\t\t\t\t// Add spacing only when another visible assistant content block follows.\n\t\t\t\t// This avoids a superfluous blank line before separately-rendered tool execution blocks.\n\t\t\t\tconst hasVisibleContentAfter = message.content\n\t\t\t\t\t.slice(i + 1)\n\t\t\t\t\t.some((c) => (c.type === \"text\" && c.text.trim()) || (c.type === \"thinking\" && c.thinking.trim()));\n\n\t\t\t\tif (this.hideThinkingBlock) {\n\t\t\t\t\t// Show static thinking label when hidden\n\t\t\t\t\tthis.contentContainer.addChild(\n\t\t\t\t\t\tnew Text(theme.italic(theme.fg(\"thinkingText\", this.hiddenThinkingLabel)), 1, 0),\n\t\t\t\t\t);\n\t\t\t\t\tif (hasVisibleContentAfter) {\n\t\t\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// Thinking traces in thinkingText color, italic\n\t\t\t\t\tthis.contentContainer.addChild(\n\t\t\t\t\t\tnew Markdown(content.thinking.trim(), 1, 0, this.markdownTheme, {\n\t\t\t\t\t\t\tcolor: (text: string) => theme.fg(\"thinkingText\", text),\n\t\t\t\t\t\t\titalic: true,\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t\t\tif (hasVisibleContentAfter) {\n\t\t\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Check if aborted - show after partial content\n\t\t// But only if there are no tool calls (tool execution components will show the error)\n\t\tconst hasToolCalls = message.content.some((c) => c.type === \"toolCall\");\n\t\tthis.hasToolCalls = hasToolCalls;\n\t\tif (!hasToolCalls) {\n\t\t\tif (message.stopReason === \"aborted\") {\n\t\t\t\tconst abortMessage =\n\t\t\t\t\tmessage.errorMessage && message.errorMessage !== \"Request was aborted\"\n\t\t\t\t\t\t? message.errorMessage\n\t\t\t\t\t\t: \"Operation aborted\";\n\t\t\t\tif (hasVisibleContent) {\n\t\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\t} else {\n\t\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\t}\n\t\t\t\tthis.contentContainer.addChild(new Text(theme.fg(\"error\", abortMessage), 1, 0));\n\t\t\t} else if (message.stopReason === \"error\") {\n\t\t\t\tconst errorMsg = message.errorMessage || \"Unknown error\";\n\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\tthis.contentContainer.addChild(new Text(theme.fg(\"error\", `Error: ${errorMsg}`), 1, 0));\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"assistant-message.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/assistant-message.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAY,KAAK,aAAa,EAAgB,MAAM,SAAS,CAAC;AAchF;;GAEG;AACH,qBAAa,yBAA0B,SAAQ,SAAS;IACvD,OAAO,CAAC,gBAAgB,CAAY;IACpC,OAAO,CAAC,iBAAiB,CAAU;IACnC,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,mBAAmB,CAAS;IACpC,OAAO,CAAC,WAAW,CAAC,CAAmB;IACvC,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAkC;IAE/D,YACC,OAAO,CAAC,EAAE,gBAAgB,EAC1B,iBAAiB,UAAQ,EACzB,aAAa,GAAE,aAAkC,EACjD,mBAAmB,SAAgB,EAenC;IAEQ,UAAU,IAAI,IAAI,CAO1B;IAED,oBAAoB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAKxC;IAED,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAK1C;IAEQ,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CASvC;IAED,OAAO,CAAC,WAAW;IA2BnB,aAAa,CAAC,OAAO,EAAE,gBAAgB,GAAG,IAAI,CAsE7C;CACD","sourcesContent":["import type { AssistantMessage } from \"omk-ai\";\nimport { Container, Markdown, type MarkdownTheme, Spacer, Text } from \"omk-tui\";\nimport { getMarkdownTheme, theme } from \"../theme/theme.ts\";\n\ntype ContentViewKind = \"text\" | \"thinking\" | \"hidden-thinking\";\ninterface ContentView {\n\tkind: ContentViewKind;\n\ttext: string;\n\tcomponent: Markdown | Text;\n}\n\nconst OSC133_ZONE_START = \"\\x1b]133;A\\x07\";\nconst OSC133_ZONE_END = \"\\x1b]133;B\\x07\";\nconst OSC133_ZONE_FINAL = \"\\x1b]133;C\\x07\";\n\n/**\n * Component that renders a complete assistant message\n */\nexport class AssistantMessageComponent extends Container {\n\tprivate contentContainer: Container;\n\tprivate hideThinkingBlock: boolean;\n\tprivate markdownTheme: MarkdownTheme;\n\tprivate hiddenThinkingLabel: string;\n\tprivate lastMessage?: AssistantMessage;\n\tprivate hasToolCalls = false;\n\tprivate readonly contentViews = new Map<number, ContentView>();\n\n\tconstructor(\n\t\tmessage?: AssistantMessage,\n\t\thideThinkingBlock = false,\n\t\tmarkdownTheme: MarkdownTheme = getMarkdownTheme(),\n\t\thiddenThinkingLabel = \"Thinking...\",\n\t) {\n\t\tsuper();\n\n\t\tthis.hideThinkingBlock = hideThinkingBlock;\n\t\tthis.markdownTheme = markdownTheme;\n\t\tthis.hiddenThinkingLabel = hiddenThinkingLabel;\n\n\t\t// Container for text/thinking content\n\t\tthis.contentContainer = new Container();\n\t\tthis.addChild(this.contentContainer);\n\n\t\tif (message) {\n\t\t\tthis.updateContent(message);\n\t\t}\n\t}\n\n\toverride invalidate(): void {\n\t\tsuper.invalidate();\n\t\t// Theme changes also invalidate pre-styled labels and Markdown style prefixes.\n\t\tthis.contentViews.clear();\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage);\n\t\t}\n\t}\n\n\tsetHideThinkingBlock(hide: boolean): void {\n\t\tthis.hideThinkingBlock = hide;\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage);\n\t\t}\n\t}\n\n\tsetHiddenThinkingLabel(label: string): void {\n\t\tthis.hiddenThinkingLabel = label;\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage);\n\t\t}\n\t}\n\n\toverride render(width: number): string[] {\n\t\tconst lines = super.render(width);\n\t\tif (this.hasToolCalls || lines.length === 0) {\n\t\t\treturn lines;\n\t\t}\n\n\t\tlines[0] = OSC133_ZONE_START + lines[0];\n\t\tlines[lines.length - 1] = OSC133_ZONE_END + OSC133_ZONE_FINAL + lines[lines.length - 1];\n\t\treturn lines;\n\t}\n\n\tprivate contentView(index: number, kind: ContentViewKind, text: string): Markdown | Text {\n\t\tconst previous = this.contentViews.get(index);\n\t\tif (previous?.kind === kind) {\n\t\t\tif (previous.text !== text) {\n\t\t\t\tprevious.component.setText(\n\t\t\t\t\tkind === \"hidden-thinking\" ? theme.italic(theme.fg(\"thinkingText\", text)) : text,\n\t\t\t\t);\n\t\t\t\tprevious.text = text;\n\t\t\t}\n\t\t\treturn previous.component;\n\t\t}\n\t\tconst component =\n\t\t\tkind === \"hidden-thinking\"\n\t\t\t\t? new Text(theme.italic(theme.fg(\"thinkingText\", text)), 1, 0)\n\t\t\t\t: new Markdown(\n\t\t\t\t\t\ttext,\n\t\t\t\t\t\t1,\n\t\t\t\t\t\t0,\n\t\t\t\t\t\tthis.markdownTheme,\n\t\t\t\t\t\tkind === \"thinking\"\n\t\t\t\t\t\t\t? { color: (value: string) => theme.fg(\"thinkingText\", value), italic: true }\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t);\n\t\tthis.contentViews.set(index, { kind, text, component });\n\t\treturn component;\n\t}\n\n\tupdateContent(message: AssistantMessage): void {\n\t\tthis.lastMessage = message;\n\n\t\t// Clear content container\n\t\tthis.contentContainer.clear();\n\n\t\tconst hasVisibleContent = message.content.some(\n\t\t\t(c) => (c.type === \"text\" && c.text.trim()) || (c.type === \"thinking\" && c.thinking.trim()),\n\t\t);\n\n\t\tif (hasVisibleContent) {\n\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t}\n\n\t\tconst usedViews = new Set<number>();\n\t\tconst visibleAfter = new Array<boolean>(message.content.length);\n\t\tlet laterVisible = false;\n\t\tfor (let i = message.content.length - 1; i >= 0; i--) {\n\t\t\tvisibleAfter[i] = laterVisible;\n\t\t\tconst part = message.content[i];\n\t\t\tlaterVisible ||=\n\t\t\t\t(part.type === \"text\" && part.text.trim().length > 0) ||\n\t\t\t\t(part.type === \"thinking\" && part.thinking.trim().length > 0);\n\t\t}\n\n\t\t// Keep unchanged block render caches without relying on message identity.\n\t\tfor (let i = 0; i < message.content.length; i++) {\n\t\t\tconst content = message.content[i];\n\t\t\tif (content.type === \"text\" && content.text.trim()) {\n\t\t\t\tusedViews.add(i);\n\t\t\t\tthis.contentContainer.addChild(this.contentView(i, \"text\", content.text.trim()));\n\t\t\t} else if (content.type === \"thinking\" && content.thinking.trim()) {\n\t\t\t\tusedViews.add(i);\n\t\t\t\tthis.contentContainer.addChild(\n\t\t\t\t\tthis.contentView(\n\t\t\t\t\t\ti,\n\t\t\t\t\t\tthis.hideThinkingBlock ? \"hidden-thinking\" : \"thinking\",\n\t\t\t\t\t\tthis.hideThinkingBlock ? this.hiddenThinkingLabel : content.thinking.trim(),\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t\t// Tool execution blocks are rendered separately and need no trailing spacer.\n\t\t\t\tif (visibleAfter[i]) this.contentContainer.addChild(new Spacer(1));\n\t\t\t}\n\t\t}\n\t\tfor (const index of this.contentViews.keys()) {\n\t\t\tif (!usedViews.has(index)) this.contentViews.delete(index);\n\t\t}\n\n\t\t// Check if aborted - show after partial content\n\t\t// But only if there are no tool calls (tool execution components will show the error)\n\t\tconst hasToolCalls = message.content.some((c) => c.type === \"toolCall\");\n\t\tthis.hasToolCalls = hasToolCalls;\n\t\tif (!hasToolCalls) {\n\t\t\tif (message.stopReason === \"aborted\") {\n\t\t\t\tconst abortMessage =\n\t\t\t\t\tmessage.errorMessage && message.errorMessage !== \"Request was aborted\"\n\t\t\t\t\t\t? message.errorMessage\n\t\t\t\t\t\t: \"Operation aborted\";\n\t\t\t\tif (hasVisibleContent) {\n\t\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\t} else {\n\t\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\t}\n\t\t\t\tthis.contentContainer.addChild(new Text(theme.fg(\"error\", abortMessage), 1, 0));\n\t\t\t} else if (message.stopReason === \"error\") {\n\t\t\t\tconst errorMsg = message.errorMessage || \"Unknown error\";\n\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\tthis.contentContainer.addChild(new Text(theme.fg(\"error\", `Error: ${errorMsg}`), 1, 0));\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
@@ -13,6 +13,7 @@ export class AssistantMessageComponent extends Container {
13
13
  hiddenThinkingLabel;
14
14
  lastMessage;
15
15
  hasToolCalls = false;
16
+ contentViews = new Map();
16
17
  constructor(message, hideThinkingBlock = false, markdownTheme = getMarkdownTheme(), hiddenThinkingLabel = "Thinking...") {
17
18
  super();
18
19
  this.hideThinkingBlock = hideThinkingBlock;
@@ -27,6 +28,8 @@ export class AssistantMessageComponent extends Container {
27
28
  }
28
29
  invalidate() {
29
30
  super.invalidate();
31
+ // Theme changes also invalidate pre-styled labels and Markdown style prefixes.
32
+ this.contentViews.clear();
30
33
  if (this.lastMessage) {
31
34
  this.updateContent(this.lastMessage);
32
35
  }
@@ -52,6 +55,23 @@ export class AssistantMessageComponent extends Container {
52
55
  lines[lines.length - 1] = OSC133_ZONE_END + OSC133_ZONE_FINAL + lines[lines.length - 1];
53
56
  return lines;
54
57
  }
58
+ contentView(index, kind, text) {
59
+ const previous = this.contentViews.get(index);
60
+ if (previous?.kind === kind) {
61
+ if (previous.text !== text) {
62
+ previous.component.setText(kind === "hidden-thinking" ? theme.italic(theme.fg("thinkingText", text)) : text);
63
+ previous.text = text;
64
+ }
65
+ return previous.component;
66
+ }
67
+ const component = kind === "hidden-thinking"
68
+ ? new Text(theme.italic(theme.fg("thinkingText", text)), 1, 0)
69
+ : new Markdown(text, 1, 0, this.markdownTheme, kind === "thinking"
70
+ ? { color: (value) => theme.fg("thinkingText", value), italic: true }
71
+ : undefined);
72
+ this.contentViews.set(index, { kind, text, component });
73
+ return component;
74
+ }
55
75
  updateContent(message) {
56
76
  this.lastMessage = message;
57
77
  // Clear content container
@@ -60,39 +80,35 @@ export class AssistantMessageComponent extends Container {
60
80
  if (hasVisibleContent) {
61
81
  this.contentContainer.addChild(new Spacer(1));
62
82
  }
63
- // Render content in order
83
+ const usedViews = new Set();
84
+ const visibleAfter = new Array(message.content.length);
85
+ let laterVisible = false;
86
+ for (let i = message.content.length - 1; i >= 0; i--) {
87
+ visibleAfter[i] = laterVisible;
88
+ const part = message.content[i];
89
+ laterVisible ||=
90
+ (part.type === "text" && part.text.trim().length > 0) ||
91
+ (part.type === "thinking" && part.thinking.trim().length > 0);
92
+ }
93
+ // Keep unchanged block render caches without relying on message identity.
64
94
  for (let i = 0; i < message.content.length; i++) {
65
95
  const content = message.content[i];
66
96
  if (content.type === "text" && content.text.trim()) {
67
- // Assistant text messages with no background - trim the text
68
- // Set paddingY=0 to avoid extra spacing before tool executions
69
- this.contentContainer.addChild(new Markdown(content.text.trim(), 1, 0, this.markdownTheme));
97
+ usedViews.add(i);
98
+ this.contentContainer.addChild(this.contentView(i, "text", content.text.trim()));
70
99
  }
71
100
  else if (content.type === "thinking" && content.thinking.trim()) {
72
- // Add spacing only when another visible assistant content block follows.
73
- // This avoids a superfluous blank line before separately-rendered tool execution blocks.
74
- const hasVisibleContentAfter = message.content
75
- .slice(i + 1)
76
- .some((c) => (c.type === "text" && c.text.trim()) || (c.type === "thinking" && c.thinking.trim()));
77
- if (this.hideThinkingBlock) {
78
- // Show static thinking label when hidden
79
- this.contentContainer.addChild(new Text(theme.italic(theme.fg("thinkingText", this.hiddenThinkingLabel)), 1, 0));
80
- if (hasVisibleContentAfter) {
81
- this.contentContainer.addChild(new Spacer(1));
82
- }
83
- }
84
- else {
85
- // Thinking traces in thinkingText color, italic
86
- this.contentContainer.addChild(new Markdown(content.thinking.trim(), 1, 0, this.markdownTheme, {
87
- color: (text) => theme.fg("thinkingText", text),
88
- italic: true,
89
- }));
90
- if (hasVisibleContentAfter) {
91
- this.contentContainer.addChild(new Spacer(1));
92
- }
93
- }
101
+ usedViews.add(i);
102
+ this.contentContainer.addChild(this.contentView(i, this.hideThinkingBlock ? "hidden-thinking" : "thinking", this.hideThinkingBlock ? this.hiddenThinkingLabel : content.thinking.trim()));
103
+ // Tool execution blocks are rendered separately and need no trailing spacer.
104
+ if (visibleAfter[i])
105
+ this.contentContainer.addChild(new Spacer(1));
94
106
  }
95
107
  }
108
+ for (const index of this.contentViews.keys()) {
109
+ if (!usedViews.has(index))
110
+ this.contentViews.delete(index);
111
+ }
96
112
  // Check if aborted - show after partial content
97
113
  // But only if there are no tool calls (tool execution components will show the error)
98
114
  const hasToolCalls = message.content.some((c) => c.type === "toolCall");