@caupulican/pi-adaptative 0.81.39 → 0.81.40

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 (667) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/README.md +2 -0
  3. package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.d.ts +2 -0
  4. package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.d.ts.map +1 -1
  5. package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.js +2 -0
  6. package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.js.map +1 -1
  7. package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.ts +3 -0
  8. package/dist/bundled-resources/extensions/tmux-agent-manager/index.d.ts +9 -0
  9. package/dist/bundled-resources/extensions/tmux-agent-manager/index.d.ts.map +1 -1
  10. package/dist/bundled-resources/extensions/tmux-agent-manager/index.js +290 -107
  11. package/dist/bundled-resources/extensions/tmux-agent-manager/index.js.map +1 -1
  12. package/dist/bundled-resources/extensions/tmux-agent-manager/index.ts +357 -122
  13. package/dist/bundled-resources/skills/tool-call-repair/references/repair-catalogue.md +2 -2
  14. package/dist/cli/args.d.ts +2 -0
  15. package/dist/cli/args.d.ts.map +1 -1
  16. package/dist/cli/args.js +9 -0
  17. package/dist/cli/args.js.map +1 -1
  18. package/dist/core/agent-directory-layout.d.ts +15 -0
  19. package/dist/core/agent-directory-layout.d.ts.map +1 -0
  20. package/dist/core/agent-directory-layout.js +72 -0
  21. package/dist/core/agent-directory-layout.js.map +1 -0
  22. package/dist/core/agent-paths.d.ts +19 -2
  23. package/dist/core/agent-paths.d.ts.map +1 -1
  24. package/dist/core/agent-paths.js +67 -4
  25. package/dist/core/agent-paths.js.map +1 -1
  26. package/dist/core/agent-session-runtime.d.ts +52 -8
  27. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  28. package/dist/core/agent-session-runtime.js +397 -79
  29. package/dist/core/agent-session-runtime.js.map +1 -1
  30. package/dist/core/agent-session-services.d.ts +1 -0
  31. package/dist/core/agent-session-services.d.ts.map +1 -1
  32. package/dist/core/agent-session-services.js +1 -0
  33. package/dist/core/agent-session-services.js.map +1 -1
  34. package/dist/core/agent-session.d.ts +71 -136
  35. package/dist/core/agent-session.d.ts.map +1 -1
  36. package/dist/core/agent-session.js +477 -1318
  37. package/dist/core/agent-session.js.map +1 -1
  38. package/dist/core/autonomy/approval-gate.d.ts +3 -2
  39. package/dist/core/autonomy/approval-gate.d.ts.map +1 -1
  40. package/dist/core/autonomy/approval-gate.js +6 -28
  41. package/dist/core/autonomy/approval-gate.js.map +1 -1
  42. package/dist/core/autonomy/bounded-completion.d.ts +1 -1
  43. package/dist/core/autonomy/bounded-completion.d.ts.map +1 -1
  44. package/dist/core/autonomy/bounded-completion.js +1 -1
  45. package/dist/core/autonomy/bounded-completion.js.map +1 -1
  46. package/dist/core/autonomy/contracts.d.ts +20 -12
  47. package/dist/core/autonomy/contracts.d.ts.map +1 -1
  48. package/dist/core/autonomy/contracts.js.map +1 -1
  49. package/dist/core/autonomy/foreground-envelope.d.ts +8 -2
  50. package/dist/core/autonomy/foreground-envelope.d.ts.map +1 -1
  51. package/dist/core/autonomy/foreground-envelope.js +8 -25
  52. package/dist/core/autonomy/foreground-envelope.js.map +1 -1
  53. package/dist/core/autonomy/gates.d.ts.map +1 -1
  54. package/dist/core/autonomy/gates.js +8 -10
  55. package/dist/core/autonomy/gates.js.map +1 -1
  56. package/dist/core/autonomy/lane-private-paths.d.ts +2 -0
  57. package/dist/core/autonomy/lane-private-paths.d.ts.map +1 -0
  58. package/dist/core/autonomy/lane-private-paths.js +16 -0
  59. package/dist/core/autonomy/lane-private-paths.js.map +1 -0
  60. package/dist/core/autonomy/lane-tool-surface.d.ts +10 -0
  61. package/dist/core/autonomy/lane-tool-surface.d.ts.map +1 -1
  62. package/dist/core/autonomy/lane-tool-surface.js +46 -8
  63. package/dist/core/autonomy/lane-tool-surface.js.map +1 -1
  64. package/dist/core/autonomy/lane-tracker.d.ts +14 -0
  65. package/dist/core/autonomy/lane-tracker.d.ts.map +1 -1
  66. package/dist/core/autonomy/lane-tracker.js +38 -0
  67. package/dist/core/autonomy/lane-tracker.js.map +1 -1
  68. package/dist/core/autonomy/risk-assessment.d.ts +1 -2
  69. package/dist/core/autonomy/risk-assessment.d.ts.map +1 -1
  70. package/dist/core/autonomy/risk-assessment.js +1 -123
  71. package/dist/core/autonomy/risk-assessment.js.map +1 -1
  72. package/dist/core/autonomy/session-lane-record.d.ts +4 -4
  73. package/dist/core/autonomy/session-lane-record.d.ts.map +1 -1
  74. package/dist/core/autonomy/session-lane-record.js +16 -29
  75. package/dist/core/autonomy/session-lane-record.js.map +1 -1
  76. package/dist/core/autonomy/telemetry-events.d.ts +1 -1
  77. package/dist/core/autonomy/telemetry-events.d.ts.map +1 -1
  78. package/dist/core/autonomy/telemetry-events.js +1 -1
  79. package/dist/core/autonomy/telemetry-events.js.map +1 -1
  80. package/dist/core/autonomy-telemetry.d.ts +7 -7
  81. package/dist/core/autonomy-telemetry.d.ts.map +1 -1
  82. package/dist/core/autonomy-telemetry.js +9 -9
  83. package/dist/core/autonomy-telemetry.js.map +1 -1
  84. package/dist/core/background-lane-controller.d.ts +54 -236
  85. package/dist/core/background-lane-controller.d.ts.map +1 -1
  86. package/dist/core/background-lane-controller.js +140 -1273
  87. package/dist/core/background-lane-controller.js.map +1 -1
  88. package/dist/core/capability-contract.d.ts +4 -0
  89. package/dist/core/capability-contract.d.ts.map +1 -0
  90. package/dist/core/capability-contract.js +28 -0
  91. package/dist/core/capability-contract.js.map +1 -0
  92. package/dist/core/compaction-controller.d.ts +90 -0
  93. package/dist/core/compaction-controller.d.ts.map +1 -0
  94. package/dist/core/compaction-controller.js +452 -0
  95. package/dist/core/compaction-controller.js.map +1 -0
  96. package/dist/core/compaction-support.d.ts +12 -11
  97. package/dist/core/compaction-support.d.ts.map +1 -1
  98. package/dist/core/compaction-support.js.map +1 -1
  99. package/dist/core/context/context-artifacts.d.ts +6 -2
  100. package/dist/core/context/context-artifacts.d.ts.map +1 -1
  101. package/dist/core/context/context-artifacts.js +34 -2
  102. package/dist/core/context/context-artifacts.js.map +1 -1
  103. package/dist/core/context/context-store-retention.d.ts +8 -2
  104. package/dist/core/context/context-store-retention.d.ts.map +1 -1
  105. package/dist/core/context/context-store-retention.js +158 -35
  106. package/dist/core/context/context-store-retention.js.map +1 -1
  107. package/dist/core/context/okf-memory.d.ts.map +1 -1
  108. package/dist/core/context/okf-memory.js +9 -11
  109. package/dist/core/context/okf-memory.js.map +1 -1
  110. package/dist/core/context/sqlite-runtime-index.d.ts.map +1 -1
  111. package/dist/core/context/sqlite-runtime-index.js +6 -8
  112. package/dist/core/context/sqlite-runtime-index.js.map +1 -1
  113. package/dist/core/context-gc.d.ts +3 -0
  114. package/dist/core/context-gc.d.ts.map +1 -1
  115. package/dist/core/context-gc.js +10 -5
  116. package/dist/core/context-gc.js.map +1 -1
  117. package/dist/core/context-pipeline.d.ts.map +1 -1
  118. package/dist/core/context-pipeline.js +9 -4
  119. package/dist/core/context-pipeline.js.map +1 -1
  120. package/dist/core/default-tool-surface.d.ts.map +1 -1
  121. package/dist/core/default-tool-surface.js +1 -0
  122. package/dist/core/default-tool-surface.js.map +1 -1
  123. package/dist/core/delegation/managed-lane-controller.d.ts +34 -0
  124. package/dist/core/delegation/managed-lane-controller.d.ts.map +1 -0
  125. package/dist/core/delegation/managed-lane-controller.js +217 -0
  126. package/dist/core/delegation/managed-lane-controller.js.map +1 -0
  127. package/dist/core/delegation/session-worker-claim.d.ts +44 -0
  128. package/dist/core/delegation/session-worker-claim.d.ts.map +1 -0
  129. package/dist/core/delegation/session-worker-claim.js +98 -0
  130. package/dist/core/delegation/session-worker-claim.js.map +1 -0
  131. package/dist/core/delegation/worker-actions.d.ts +7 -5
  132. package/dist/core/delegation/worker-actions.d.ts.map +1 -1
  133. package/dist/core/delegation/worker-actions.js +20 -4
  134. package/dist/core/delegation/worker-actions.js.map +1 -1
  135. package/dist/core/delegation/{worker-result.d.ts → worker-claim.d.ts} +13 -13
  136. package/dist/core/delegation/worker-claim.d.ts.map +1 -0
  137. package/dist/core/delegation/{worker-result.js → worker-claim.js} +61 -51
  138. package/dist/core/delegation/worker-claim.js.map +1 -0
  139. package/dist/core/delegation/worker-delegation-controller.d.ts +110 -0
  140. package/dist/core/delegation/worker-delegation-controller.d.ts.map +1 -0
  141. package/dist/core/delegation/worker-delegation-controller.js +861 -0
  142. package/dist/core/delegation/worker-delegation-controller.js.map +1 -0
  143. package/dist/core/delegation/worker-delegation-request.d.ts +11 -0
  144. package/dist/core/delegation/worker-delegation-request.d.ts.map +1 -0
  145. package/dist/core/delegation/worker-delegation-request.js +2 -0
  146. package/dist/core/delegation/worker-delegation-request.js.map +1 -0
  147. package/dist/core/delegation/worker-dispatch-scheduler.d.ts +40 -0
  148. package/dist/core/delegation/worker-dispatch-scheduler.d.ts.map +1 -0
  149. package/dist/core/delegation/worker-dispatch-scheduler.js +93 -0
  150. package/dist/core/delegation/worker-dispatch-scheduler.js.map +1 -0
  151. package/dist/core/delegation/worker-execution-policy.d.ts +62 -0
  152. package/dist/core/delegation/worker-execution-policy.d.ts.map +1 -0
  153. package/dist/core/delegation/worker-execution-policy.js +160 -0
  154. package/dist/core/delegation/worker-execution-policy.js.map +1 -0
  155. package/dist/core/delegation/worker-lane-projection.d.ts +14 -0
  156. package/dist/core/delegation/worker-lane-projection.d.ts.map +1 -0
  157. package/dist/core/delegation/worker-lane-projection.js +100 -0
  158. package/dist/core/delegation/worker-lane-projection.js.map +1 -0
  159. package/dist/core/delegation/worker-lifecycle.d.ts +97 -0
  160. package/dist/core/delegation/worker-lifecycle.d.ts.map +1 -0
  161. package/dist/core/delegation/worker-lifecycle.js +339 -0
  162. package/dist/core/delegation/worker-lifecycle.js.map +1 -0
  163. package/dist/core/delegation/worker-notification-coordinator.d.ts +36 -0
  164. package/dist/core/delegation/worker-notification-coordinator.d.ts.map +1 -0
  165. package/dist/core/delegation/worker-notification-coordinator.js +90 -0
  166. package/dist/core/delegation/worker-notification-coordinator.js.map +1 -0
  167. package/dist/core/delegation/worker-profile-resolver.d.ts +55 -0
  168. package/dist/core/delegation/worker-profile-resolver.d.ts.map +1 -0
  169. package/dist/core/delegation/worker-profile-resolver.js +113 -0
  170. package/dist/core/delegation/worker-profile-resolver.js.map +1 -0
  171. package/dist/core/delegation/worker-runner.d.ts +25 -14
  172. package/dist/core/delegation/worker-runner.d.ts.map +1 -1
  173. package/dist/core/delegation/worker-runner.js +122 -53
  174. package/dist/core/delegation/worker-runner.js.map +1 -1
  175. package/dist/core/delegation/worker-task-label.d.ts +3 -0
  176. package/dist/core/delegation/worker-task-label.d.ts.map +1 -0
  177. package/dist/core/delegation/worker-task-label.js +11 -0
  178. package/dist/core/delegation/worker-task-label.js.map +1 -0
  179. package/dist/core/doctor.d.ts +8 -0
  180. package/dist/core/doctor.d.ts.map +1 -1
  181. package/dist/core/doctor.js +32 -1
  182. package/dist/core/doctor.js.map +1 -1
  183. package/dist/core/extensions/index.d.ts +1 -1
  184. package/dist/core/extensions/index.d.ts.map +1 -1
  185. package/dist/core/extensions/index.js.map +1 -1
  186. package/dist/core/extensions/loader.d.ts +5 -1
  187. package/dist/core/extensions/loader.d.ts.map +1 -1
  188. package/dist/core/extensions/loader.js +50 -15
  189. package/dist/core/extensions/loader.js.map +1 -1
  190. package/dist/core/extensions/runner.d.ts.map +1 -1
  191. package/dist/core/extensions/runner.js +6 -0
  192. package/dist/core/extensions/runner.js.map +1 -1
  193. package/dist/core/extensions/storage.d.ts +8 -0
  194. package/dist/core/extensions/storage.d.ts.map +1 -0
  195. package/dist/core/extensions/storage.js +28 -0
  196. package/dist/core/extensions/storage.js.map +1 -0
  197. package/dist/core/extensions/types.d.ts +70 -21
  198. package/dist/core/extensions/types.d.ts.map +1 -1
  199. package/dist/core/extensions/types.js.map +1 -1
  200. package/dist/core/failure-corpus.d.ts +1 -15
  201. package/dist/core/failure-corpus.d.ts.map +1 -1
  202. package/dist/core/failure-corpus.js +9 -37
  203. package/dist/core/failure-corpus.js.map +1 -1
  204. package/dist/core/foreground-recovery-controller.d.ts +52 -0
  205. package/dist/core/foreground-recovery-controller.d.ts.map +1 -0
  206. package/dist/core/foreground-recovery-controller.js +111 -0
  207. package/dist/core/foreground-recovery-controller.js.map +1 -0
  208. package/dist/core/gateways/channel-provider.d.ts +3 -0
  209. package/dist/core/gateways/channel-provider.d.ts.map +1 -1
  210. package/dist/core/gateways/channel-provider.js +31 -6
  211. package/dist/core/gateways/channel-provider.js.map +1 -1
  212. package/dist/core/goals/goal-acceptance.d.ts +11 -0
  213. package/dist/core/goals/goal-acceptance.d.ts.map +1 -0
  214. package/dist/core/goals/goal-acceptance.js +25 -0
  215. package/dist/core/goals/goal-acceptance.js.map +1 -0
  216. package/dist/core/goals/goal-auto-continue-controller.d.ts +27 -0
  217. package/dist/core/goals/goal-auto-continue-controller.d.ts.map +1 -0
  218. package/dist/core/goals/goal-auto-continue-controller.js +93 -0
  219. package/dist/core/goals/goal-auto-continue-controller.js.map +1 -0
  220. package/dist/core/goals/goal-continuation-controller.d.ts +1 -1
  221. package/dist/core/goals/goal-continuation-controller.d.ts.map +1 -1
  222. package/dist/core/goals/goal-continuation-controller.js +10 -0
  223. package/dist/core/goals/goal-continuation-controller.js.map +1 -1
  224. package/dist/core/goals/goal-continuation-prompt.d.ts +1 -1
  225. package/dist/core/goals/goal-continuation-prompt.d.ts.map +1 -1
  226. package/dist/core/goals/goal-continuation-prompt.js +6 -6
  227. package/dist/core/goals/goal-continuation-prompt.js.map +1 -1
  228. package/dist/core/goals/goal-lifecycle.d.ts +20 -0
  229. package/dist/core/goals/goal-lifecycle.d.ts.map +1 -0
  230. package/dist/core/goals/goal-lifecycle.js +17 -0
  231. package/dist/core/goals/goal-lifecycle.js.map +1 -0
  232. package/dist/core/goals/goal-runtime-snapshot.d.ts +11 -9
  233. package/dist/core/goals/goal-runtime-snapshot.d.ts.map +1 -1
  234. package/dist/core/goals/goal-runtime-snapshot.js +10 -8
  235. package/dist/core/goals/goal-runtime-snapshot.js.map +1 -1
  236. package/dist/core/goals/goal-state.d.ts +1 -0
  237. package/dist/core/goals/goal-state.d.ts.map +1 -1
  238. package/dist/core/goals/goal-state.js +7 -10
  239. package/dist/core/goals/goal-state.js.map +1 -1
  240. package/dist/core/goals/goal-tool-core.d.ts +8 -6
  241. package/dist/core/goals/goal-tool-core.d.ts.map +1 -1
  242. package/dist/core/goals/goal-tool-core.js +11 -41
  243. package/dist/core/goals/goal-tool-core.js.map +1 -1
  244. package/dist/core/goals/session-goal-state.d.ts +2 -4
  245. package/dist/core/goals/session-goal-state.d.ts.map +1 -1
  246. package/dist/core/goals/session-goal-state.js +10 -33
  247. package/dist/core/goals/session-goal-state.js.map +1 -1
  248. package/dist/core/human-input.d.ts +100 -0
  249. package/dist/core/human-input.d.ts.map +1 -0
  250. package/dist/core/human-input.js +362 -0
  251. package/dist/core/human-input.js.map +1 -0
  252. package/dist/core/index.d.ts +9 -1
  253. package/dist/core/index.d.ts.map +1 -1
  254. package/dist/core/index.js +9 -1
  255. package/dist/core/index.js.map +1 -1
  256. package/dist/core/{telemetry.d.ts → install-telemetry.d.ts} +1 -1
  257. package/dist/core/install-telemetry.d.ts.map +1 -0
  258. package/dist/core/{telemetry.js → install-telemetry.js} +1 -1
  259. package/dist/core/install-telemetry.js.map +1 -0
  260. package/dist/core/keybindings.d.ts +17 -1
  261. package/dist/core/keybindings.d.ts.map +1 -1
  262. package/dist/core/keybindings.js +24 -6
  263. package/dist/core/keybindings.js.map +1 -1
  264. package/dist/core/learning/learning-audit.d.ts +2 -4
  265. package/dist/core/learning/learning-audit.d.ts.map +1 -1
  266. package/dist/core/learning/learning-audit.js +9 -29
  267. package/dist/core/learning/learning-audit.js.map +1 -1
  268. package/dist/core/learning/learning-gate.d.ts.map +1 -1
  269. package/dist/core/learning/learning-gate.js +1 -6
  270. package/dist/core/learning/learning-gate.js.map +1 -1
  271. package/dist/core/learning/session-learning-decision.d.ts +2 -4
  272. package/dist/core/learning/session-learning-decision.d.ts.map +1 -1
  273. package/dist/core/learning/session-learning-decision.js +9 -29
  274. package/dist/core/learning/session-learning-decision.js.map +1 -1
  275. package/dist/core/memory-controller.d.ts.map +1 -1
  276. package/dist/core/memory-controller.js +4 -4
  277. package/dist/core/memory-controller.js.map +1 -1
  278. package/dist/core/model-capability.d.ts.map +1 -1
  279. package/dist/core/model-capability.js +1 -0
  280. package/dist/core/model-capability.js.map +1 -1
  281. package/dist/core/model-resolver.d.ts +1 -1
  282. package/dist/core/model-resolver.d.ts.map +1 -1
  283. package/dist/core/model-resolver.js +6 -9
  284. package/dist/core/model-resolver.js.map +1 -1
  285. package/dist/core/model-router/intent-classifier.d.ts +1 -4
  286. package/dist/core/model-router/intent-classifier.d.ts.map +1 -1
  287. package/dist/core/model-router/intent-classifier.js +1 -156
  288. package/dist/core/model-router/intent-classifier.js.map +1 -1
  289. package/dist/core/model-router-controller.d.ts.map +1 -1
  290. package/dist/core/model-router-controller.js +2 -2
  291. package/dist/core/model-router-controller.js.map +1 -1
  292. package/dist/core/model-selection-controller.d.ts +4 -4
  293. package/dist/core/model-selection-controller.d.ts.map +1 -1
  294. package/dist/core/model-selection-controller.js.map +1 -1
  295. package/dist/core/model-tool-protocol.d.ts +23 -0
  296. package/dist/core/model-tool-protocol.d.ts.map +1 -0
  297. package/dist/core/model-tool-protocol.js +43 -0
  298. package/dist/core/model-tool-protocol.js.map +1 -0
  299. package/dist/core/models/adaptation-store.d.ts +4 -6
  300. package/dist/core/models/adaptation-store.d.ts.map +1 -1
  301. package/dist/core/models/adaptation-store.js +95 -83
  302. package/dist/core/models/adaptation-store.js.map +1 -1
  303. package/dist/core/models/fitness-store.d.ts +2 -12
  304. package/dist/core/models/fitness-store.d.ts.map +1 -1
  305. package/dist/core/models/fitness-store.js +84 -57
  306. package/dist/core/models/fitness-store.js.map +1 -1
  307. package/dist/core/models/host-state-store.d.ts +34 -0
  308. package/dist/core/models/host-state-store.d.ts.map +1 -0
  309. package/dist/core/models/host-state-store.js +86 -0
  310. package/dist/core/models/host-state-store.js.map +1 -0
  311. package/dist/core/orchestration/agent-resume.d.ts +24 -0
  312. package/dist/core/orchestration/agent-resume.d.ts.map +1 -0
  313. package/dist/core/orchestration/agent-resume.js +90 -0
  314. package/dist/core/orchestration/agent-resume.js.map +1 -0
  315. package/dist/core/orchestration/capability-gateway.d.ts +61 -0
  316. package/dist/core/orchestration/capability-gateway.d.ts.map +1 -0
  317. package/dist/core/orchestration/capability-gateway.js +152 -0
  318. package/dist/core/orchestration/capability-gateway.js.map +1 -0
  319. package/dist/core/orchestration/contracts.d.ts +343 -0
  320. package/dist/core/orchestration/contracts.d.ts.map +1 -0
  321. package/dist/core/orchestration/contracts.js +135 -0
  322. package/dist/core/orchestration/contracts.js.map +1 -0
  323. package/dist/core/orchestration/delegation-ledger.d.ts +56 -0
  324. package/dist/core/orchestration/delegation-ledger.d.ts.map +1 -0
  325. package/dist/core/orchestration/delegation-ledger.js +197 -0
  326. package/dist/core/orchestration/delegation-ledger.js.map +1 -0
  327. package/dist/core/orchestration/event-store.d.ts +83 -0
  328. package/dist/core/orchestration/event-store.d.ts.map +1 -0
  329. package/dist/core/orchestration/event-store.js +560 -0
  330. package/dist/core/orchestration/event-store.js.map +1 -0
  331. package/dist/core/orchestration/lane-tool-manifests.d.ts +9 -0
  332. package/dist/core/orchestration/lane-tool-manifests.d.ts.map +1 -0
  333. package/dist/core/orchestration/lane-tool-manifests.js +37 -0
  334. package/dist/core/orchestration/lane-tool-manifests.js.map +1 -0
  335. package/dist/core/orchestration/model-binding.d.ts +15 -0
  336. package/dist/core/orchestration/model-binding.d.ts.map +1 -0
  337. package/dist/core/orchestration/model-binding.js +29 -0
  338. package/dist/core/orchestration/model-binding.js.map +1 -0
  339. package/dist/core/orchestration/policy-compiler.d.ts +49 -0
  340. package/dist/core/orchestration/policy-compiler.d.ts.map +1 -0
  341. package/dist/core/orchestration/policy-compiler.js +191 -0
  342. package/dist/core/orchestration/policy-compiler.js.map +1 -0
  343. package/dist/core/orchestration/policy-gate.d.ts +18 -0
  344. package/dist/core/orchestration/policy-gate.d.ts.map +1 -0
  345. package/dist/core/orchestration/policy-gate.js +24 -0
  346. package/dist/core/orchestration/policy-gate.js.map +1 -0
  347. package/dist/core/orchestration/profile-registry.d.ts +51 -0
  348. package/dist/core/orchestration/profile-registry.d.ts.map +1 -0
  349. package/dist/core/orchestration/profile-registry.js +393 -0
  350. package/dist/core/orchestration/profile-registry.js.map +1 -0
  351. package/dist/core/orchestration/profile-store.d.ts +31 -0
  352. package/dist/core/orchestration/profile-store.d.ts.map +1 -0
  353. package/dist/core/orchestration/profile-store.js +136 -0
  354. package/dist/core/orchestration/profile-store.js.map +1 -0
  355. package/dist/core/orchestration/risk-budget.d.ts +9 -0
  356. package/dist/core/orchestration/risk-budget.d.ts.map +1 -0
  357. package/dist/core/orchestration/risk-budget.js +48 -0
  358. package/dist/core/orchestration/risk-budget.js.map +1 -0
  359. package/dist/core/orchestration/task-runtime.d.ts +168 -0
  360. package/dist/core/orchestration/task-runtime.d.ts.map +1 -0
  361. package/dist/core/orchestration/task-runtime.js +1600 -0
  362. package/dist/core/orchestration/task-runtime.js.map +1 -0
  363. package/dist/core/orchestration/work-state-projection.d.ts +32 -0
  364. package/dist/core/orchestration/work-state-projection.d.ts.map +1 -0
  365. package/dist/core/orchestration/work-state-projection.js +116 -0
  366. package/dist/core/orchestration/work-state-projection.js.map +1 -0
  367. package/dist/core/orchestration/worker-execution-contract.d.ts +21 -0
  368. package/dist/core/orchestration/worker-execution-contract.d.ts.map +1 -0
  369. package/dist/core/orchestration/worker-execution-contract.js +179 -0
  370. package/dist/core/orchestration/worker-execution-contract.js.map +1 -0
  371. package/dist/core/orchestration/worker-result-adapter.d.ts +21 -0
  372. package/dist/core/orchestration/worker-result-adapter.d.ts.map +1 -0
  373. package/dist/core/orchestration/worker-result-adapter.js +109 -0
  374. package/dist/core/orchestration/worker-result-adapter.js.map +1 -0
  375. package/dist/core/process-identity.d.ts +11 -0
  376. package/dist/core/process-identity.d.ts.map +1 -0
  377. package/dist/core/process-identity.js +26 -0
  378. package/dist/core/process-identity.js.map +1 -0
  379. package/dist/core/process-matrix/codes.d.ts +14 -3
  380. package/dist/core/process-matrix/codes.d.ts.map +1 -1
  381. package/dist/core/process-matrix/codes.js.map +1 -1
  382. package/dist/core/process-matrix/resume-launcher.d.ts +26 -0
  383. package/dist/core/process-matrix/resume-launcher.d.ts.map +1 -0
  384. package/dist/core/process-matrix/resume-launcher.js +62 -0
  385. package/dist/core/process-matrix/resume-launcher.js.map +1 -0
  386. package/dist/core/process-matrix/runtime.d.ts +37 -22
  387. package/dist/core/process-matrix/runtime.d.ts.map +1 -1
  388. package/dist/core/process-matrix/runtime.js +399 -76
  389. package/dist/core/process-matrix/runtime.js.map +1 -1
  390. package/dist/core/process-matrix/store.d.ts +5 -2
  391. package/dist/core/process-matrix/store.d.ts.map +1 -1
  392. package/dist/core/process-matrix/store.js +123 -14
  393. package/dist/core/process-matrix/store.js.map +1 -1
  394. package/dist/core/process-matrix/supervisor.d.ts +10 -7
  395. package/dist/core/process-matrix/supervisor.d.ts.map +1 -1
  396. package/dist/core/process-matrix/supervisor.js +45 -14
  397. package/dist/core/process-matrix/supervisor.js.map +1 -1
  398. package/dist/core/profile-registry.d.ts.map +1 -1
  399. package/dist/core/profile-registry.js +6 -8
  400. package/dist/core/profile-registry.js.map +1 -1
  401. package/dist/core/reflection-controller.d.ts +4 -4
  402. package/dist/core/reflection-controller.d.ts.map +1 -1
  403. package/dist/core/reflection-controller.js +2 -1
  404. package/dist/core/reflection-controller.js.map +1 -1
  405. package/dist/core/reload-blockers.d.ts.map +1 -1
  406. package/dist/core/reload-blockers.js +6 -8
  407. package/dist/core/reload-blockers.js.map +1 -1
  408. package/dist/core/research/evidence-bundle.d.ts.map +1 -1
  409. package/dist/core/research/evidence-bundle.js +1 -6
  410. package/dist/core/research/evidence-bundle.js.map +1 -1
  411. package/dist/core/research/lane-model-resolver.d.ts +33 -0
  412. package/dist/core/research/lane-model-resolver.d.ts.map +1 -0
  413. package/dist/core/research/lane-model-resolver.js +65 -0
  414. package/dist/core/research/lane-model-resolver.js.map +1 -0
  415. package/dist/core/research/model-fitness-controller.d.ts +38 -0
  416. package/dist/core/research/model-fitness-controller.d.ts.map +1 -0
  417. package/dist/core/research/model-fitness-controller.js +106 -0
  418. package/dist/core/research/model-fitness-controller.js.map +1 -0
  419. package/dist/core/research/model-fitness.d.ts +1 -1
  420. package/dist/core/research/model-fitness.d.ts.map +1 -1
  421. package/dist/core/research/model-fitness.js +4 -4
  422. package/dist/core/research/model-fitness.js.map +1 -1
  423. package/dist/core/research/research-gate.d.ts.map +1 -1
  424. package/dist/core/research/research-gate.js +7 -7
  425. package/dist/core/research/research-gate.js.map +1 -1
  426. package/dist/core/research/research-lane-controller.d.ts +62 -0
  427. package/dist/core/research/research-lane-controller.d.ts.map +1 -0
  428. package/dist/core/research/research-lane-controller.js +292 -0
  429. package/dist/core/research/research-lane-controller.js.map +1 -0
  430. package/dist/core/research/session-evidence-bundle.d.ts +2 -4
  431. package/dist/core/research/session-evidence-bundle.d.ts.map +1 -1
  432. package/dist/core/research/session-evidence-bundle.js +10 -46
  433. package/dist/core/research/session-evidence-bundle.js.map +1 -1
  434. package/dist/core/resource-loader.d.ts.map +1 -1
  435. package/dist/core/resource-loader.js +7 -2
  436. package/dist/core/resource-loader.js.map +1 -1
  437. package/dist/core/risk-classifier.d.ts +6 -0
  438. package/dist/core/risk-classifier.d.ts.map +1 -0
  439. package/dist/core/risk-classifier.js +225 -0
  440. package/dist/core/risk-classifier.js.map +1 -0
  441. package/dist/core/runtime-builder.d.ts +26 -20
  442. package/dist/core/runtime-builder.d.ts.map +1 -1
  443. package/dist/core/runtime-builder.js +237 -178
  444. package/dist/core/runtime-builder.js.map +1 -1
  445. package/dist/core/sdk.d.ts +6 -3
  446. package/dist/core/sdk.d.ts.map +1 -1
  447. package/dist/core/sdk.js +61 -24
  448. package/dist/core/sdk.js.map +1 -1
  449. package/dist/core/session-analytics.d.ts.map +1 -1
  450. package/dist/core/session-analytics.js +28 -1
  451. package/dist/core/session-analytics.js.map +1 -1
  452. package/dist/core/session-image-store.d.ts +33 -0
  453. package/dist/core/session-image-store.d.ts.map +1 -0
  454. package/dist/core/session-image-store.js +283 -0
  455. package/dist/core/session-image-store.js.map +1 -0
  456. package/dist/core/session-role.d.ts +6 -4
  457. package/dist/core/session-role.d.ts.map +1 -1
  458. package/dist/core/session-role.js +10 -4
  459. package/dist/core/session-role.js.map +1 -1
  460. package/dist/core/session-snapshot.d.ts +34 -0
  461. package/dist/core/session-snapshot.d.ts.map +1 -0
  462. package/dist/core/session-snapshot.js +68 -0
  463. package/dist/core/session-snapshot.js.map +1 -0
  464. package/dist/core/session-supervision-runtime.d.ts +31 -0
  465. package/dist/core/session-supervision-runtime.d.ts.map +1 -0
  466. package/dist/core/session-supervision-runtime.js +97 -0
  467. package/dist/core/session-supervision-runtime.js.map +1 -0
  468. package/dist/core/settings-manager.d.ts +9 -4
  469. package/dist/core/settings-manager.d.ts.map +1 -1
  470. package/dist/core/settings-manager.js +80 -28
  471. package/dist/core/settings-manager.js.map +1 -1
  472. package/dist/core/tasks/session-task-state.d.ts +2 -4
  473. package/dist/core/tasks/session-task-state.d.ts.map +1 -1
  474. package/dist/core/tasks/session-task-state.js +10 -28
  475. package/dist/core/tasks/session-task-state.js.map +1 -1
  476. package/dist/core/tasks/task-projection.d.ts +20 -0
  477. package/dist/core/tasks/task-projection.d.ts.map +1 -0
  478. package/dist/core/tasks/task-projection.js +47 -0
  479. package/dist/core/tasks/task-projection.js.map +1 -0
  480. package/dist/core/tasks/task-state.d.ts +4 -0
  481. package/dist/core/tasks/task-state.d.ts.map +1 -1
  482. package/dist/core/tasks/task-state.js +28 -11
  483. package/dist/core/tasks/task-state.js.map +1 -1
  484. package/dist/core/tool-capability-policy.d.ts +13 -0
  485. package/dist/core/tool-capability-policy.d.ts.map +1 -0
  486. package/dist/core/tool-capability-policy.js +85 -0
  487. package/dist/core/tool-capability-policy.js.map +1 -0
  488. package/dist/core/tool-protocol-controller.d.ts +91 -0
  489. package/dist/core/tool-protocol-controller.d.ts.map +1 -0
  490. package/dist/core/tool-protocol-controller.js +512 -0
  491. package/dist/core/tool-protocol-controller.js.map +1 -0
  492. package/dist/core/tool-recovery-log-records.d.ts +2 -3
  493. package/dist/core/tool-recovery-log-records.d.ts.map +1 -1
  494. package/dist/core/tool-recovery-log-records.js +9 -35
  495. package/dist/core/tool-recovery-log-records.js.map +1 -1
  496. package/dist/core/tool-selection/tool-performance-store.d.ts +3 -7
  497. package/dist/core/tool-selection/tool-performance-store.d.ts.map +1 -1
  498. package/dist/core/tool-selection/tool-performance-store.js +97 -138
  499. package/dist/core/tool-selection/tool-performance-store.js.map +1 -1
  500. package/dist/core/tools/ask-question.d.ts +124 -0
  501. package/dist/core/tools/ask-question.d.ts.map +1 -0
  502. package/dist/core/tools/ask-question.js +693 -0
  503. package/dist/core/tools/ask-question.js.map +1 -0
  504. package/dist/core/tools/delegate-status.d.ts +31 -3
  505. package/dist/core/tools/delegate-status.d.ts.map +1 -1
  506. package/dist/core/tools/delegate-status.js +149 -29
  507. package/dist/core/tools/delegate-status.js.map +1 -1
  508. package/dist/core/tools/delegate.d.ts +15 -13
  509. package/dist/core/tools/delegate.d.ts.map +1 -1
  510. package/dist/core/tools/delegate.js +108 -23
  511. package/dist/core/tools/delegate.js.map +1 -1
  512. package/dist/core/tools/extensionify.d.ts.map +1 -1
  513. package/dist/core/tools/extensionify.js +1 -0
  514. package/dist/core/tools/extensionify.js.map +1 -1
  515. package/dist/core/tools/goal.d.ts +5 -5
  516. package/dist/core/tools/goal.d.ts.map +1 -1
  517. package/dist/core/tools/goal.js +10 -10
  518. package/dist/core/tools/goal.js.map +1 -1
  519. package/dist/core/tools/model-fitness.d.ts.map +1 -1
  520. package/dist/core/tools/model-fitness.js +2 -2
  521. package/dist/core/tools/model-fitness.js.map +1 -1
  522. package/dist/core/tools/orchestration-panel.d.ts +43 -0
  523. package/dist/core/tools/orchestration-panel.d.ts.map +1 -0
  524. package/dist/core/tools/orchestration-panel.js +168 -0
  525. package/dist/core/tools/orchestration-panel.js.map +1 -0
  526. package/dist/core/tools/run-process.d.ts +26 -0
  527. package/dist/core/tools/run-process.d.ts.map +1 -0
  528. package/dist/core/tools/run-process.js +138 -0
  529. package/dist/core/tools/run-process.js.map +1 -0
  530. package/dist/core/tools/task-steps.d.ts +2 -0
  531. package/dist/core/tools/task-steps.d.ts.map +1 -1
  532. package/dist/core/tools/task-steps.js +102 -0
  533. package/dist/core/tools/task-steps.js.map +1 -1
  534. package/dist/core/tools/tmux-dispatch.d.ts +3 -5
  535. package/dist/core/tools/tmux-dispatch.d.ts.map +1 -1
  536. package/dist/core/tools/tmux-dispatch.js +4 -4
  537. package/dist/core/tools/tmux-dispatch.js.map +1 -1
  538. package/dist/core/tools/windows-shell-engine.d.ts.map +1 -1
  539. package/dist/core/tools/windows-shell-engine.js +4 -6
  540. package/dist/core/tools/windows-shell-engine.js.map +1 -1
  541. package/dist/core/util/bounded-jsonl.d.ts +10 -0
  542. package/dist/core/util/bounded-jsonl.d.ts.map +1 -0
  543. package/dist/core/util/bounded-jsonl.js +75 -0
  544. package/dist/core/util/bounded-jsonl.js.map +1 -0
  545. package/dist/core/util/value-guards.d.ts +5 -0
  546. package/dist/core/util/value-guards.d.ts.map +1 -0
  547. package/dist/core/util/value-guards.js +12 -0
  548. package/dist/core/util/value-guards.js.map +1 -0
  549. package/dist/core/worktree-sync/store.d.ts +3 -3
  550. package/dist/core/worktree-sync/store.d.ts.map +1 -1
  551. package/dist/core/worktree-sync/store.js +10 -5
  552. package/dist/core/worktree-sync/store.js.map +1 -1
  553. package/dist/index.d.ts +13 -3
  554. package/dist/index.d.ts.map +1 -1
  555. package/dist/index.js +12 -2
  556. package/dist/index.js.map +1 -1
  557. package/dist/main.d.ts.map +1 -1
  558. package/dist/main.js +128 -44
  559. package/dist/main.js.map +1 -1
  560. package/dist/migrations.d.ts +4 -6
  561. package/dist/migrations.d.ts.map +1 -1
  562. package/dist/migrations.js +186 -28
  563. package/dist/migrations.js.map +1 -1
  564. package/dist/modes/interactive/clipboard-input.d.ts +7 -1
  565. package/dist/modes/interactive/clipboard-input.d.ts.map +1 -1
  566. package/dist/modes/interactive/clipboard-input.js +44 -6
  567. package/dist/modes/interactive/clipboard-input.js.map +1 -1
  568. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  569. package/dist/modes/interactive/components/settings-selector.js +2 -2
  570. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  571. package/dist/modes/interactive/config-backup.d.ts.map +1 -1
  572. package/dist/modes/interactive/config-backup.js +5 -4
  573. package/dist/modes/interactive/config-backup.js.map +1 -1
  574. package/dist/modes/interactive/extension-ui-host.d.ts +14 -0
  575. package/dist/modes/interactive/extension-ui-host.d.ts.map +1 -1
  576. package/dist/modes/interactive/extension-ui-host.js +76 -15
  577. package/dist/modes/interactive/extension-ui-host.js.map +1 -1
  578. package/dist/modes/interactive/interactive-mode.d.ts +3 -0
  579. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  580. package/dist/modes/interactive/interactive-mode.js +63 -1
  581. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  582. package/dist/modes/interactive/key-handlers.d.ts.map +1 -1
  583. package/dist/modes/interactive/key-handlers.js +1 -1
  584. package/dist/modes/interactive/key-handlers.js.map +1 -1
  585. package/dist/modes/interactive/profile-menu-controller.d.ts.map +1 -1
  586. package/dist/modes/interactive/profile-menu-controller.js +7 -7
  587. package/dist/modes/interactive/profile-menu-controller.js.map +1 -1
  588. package/dist/modes/interactive/report-commands.d.ts.map +1 -1
  589. package/dist/modes/interactive/report-commands.js +21 -0
  590. package/dist/modes/interactive/report-commands.js.map +1 -1
  591. package/dist/modes/interactive/session-flow-commands.d.ts +17 -2
  592. package/dist/modes/interactive/session-flow-commands.d.ts.map +1 -1
  593. package/dist/modes/interactive/session-flow-commands.js +50 -17
  594. package/dist/modes/interactive/session-flow-commands.js.map +1 -1
  595. package/dist/modes/interactive/session-io-commands.d.ts.map +1 -1
  596. package/dist/modes/interactive/session-io-commands.js +16 -6
  597. package/dist/modes/interactive/session-io-commands.js.map +1 -1
  598. package/dist/modes/interactive/session-replacement-errors.d.ts +7 -0
  599. package/dist/modes/interactive/session-replacement-errors.d.ts.map +1 -0
  600. package/dist/modes/interactive/session-replacement-errors.js +15 -0
  601. package/dist/modes/interactive/session-replacement-errors.js.map +1 -0
  602. package/dist/modes/interactive/startup-checks.d.ts.map +1 -1
  603. package/dist/modes/interactive/startup-checks.js +1 -1
  604. package/dist/modes/interactive/startup-checks.js.map +1 -1
  605. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  606. package/dist/modes/rpc/rpc-mode.js +82 -23
  607. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  608. package/dist/modes/rpc/rpc-types.d.ts +15 -0
  609. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  610. package/dist/modes/rpc/rpc-types.js +138 -1
  611. package/dist/modes/rpc/rpc-types.js.map +1 -1
  612. package/dist/utils/clipboard-image.d.ts.map +1 -1
  613. package/dist/utils/clipboard-image.js +2 -13
  614. package/dist/utils/clipboard-image.js.map +1 -1
  615. package/dist/utils/clipboard-native.d.ts +1 -0
  616. package/dist/utils/clipboard-native.d.ts.map +1 -1
  617. package/dist/utils/clipboard-native.js.map +1 -1
  618. package/dist/utils/clipboard.d.ts +1 -0
  619. package/dist/utils/clipboard.d.ts.map +1 -1
  620. package/dist/utils/clipboard.js +52 -1
  621. package/dist/utils/clipboard.js.map +1 -1
  622. package/dist/utils/platform.d.ts +3 -0
  623. package/dist/utils/platform.d.ts.map +1 -0
  624. package/dist/utils/platform.js +8 -0
  625. package/dist/utils/platform.js.map +1 -0
  626. package/dist/utils/work-directory.d.ts +11 -0
  627. package/dist/utils/work-directory.d.ts.map +1 -1
  628. package/dist/utils/work-directory.js +30 -9
  629. package/dist/utils/work-directory.js.map +1 -1
  630. package/docs/UI_POLISH_ORCHESTRATION.md +44 -0
  631. package/docs/UI_QUALITY_ORCHESTRATION.md +30 -0
  632. package/docs/docs.json +4 -0
  633. package/docs/extensions.md +62 -2
  634. package/docs/harness-architecture.md +156 -0
  635. package/docs/keybindings.md +11 -1
  636. package/docs/process-matrix.md +59 -26
  637. package/docs/rpc.md +45 -2
  638. package/docs/sessions.md +15 -0
  639. package/docs/settings.md +125 -11
  640. package/docs/task-steps.md +8 -0
  641. package/docs/telemetry.md +19 -0
  642. package/docs/tmux-agent-manager.md +10 -3
  643. package/docs/ui-reference/README.md +9 -0
  644. package/docs/ui-reference/orchestration-after.txt +7 -0
  645. package/docs/ui-reference/orchestration-before.txt +7 -0
  646. package/docs/ui-reference/orchestration-reference.txt +6 -0
  647. package/docs/usage.md +14 -2
  648. package/docs/work-directory.md +19 -8
  649. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  650. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  651. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  652. package/examples/extensions/question.ts +34 -245
  653. package/examples/extensions/questionnaire.ts +41 -407
  654. package/examples/extensions/sandbox/package-lock.json +2 -2
  655. package/examples/extensions/sandbox/package.json +1 -1
  656. package/examples/extensions/with-deps/package-lock.json +2 -2
  657. package/examples/extensions/with-deps/package.json +1 -1
  658. package/npm-shrinkwrap.json +12 -12
  659. package/package.json +4 -4
  660. package/dist/core/delegation/session-worker-result.d.ts +0 -46
  661. package/dist/core/delegation/session-worker-result.d.ts.map +0 -1
  662. package/dist/core/delegation/session-worker-result.js +0 -113
  663. package/dist/core/delegation/session-worker-result.js.map +0 -1
  664. package/dist/core/delegation/worker-result.d.ts.map +0 -1
  665. package/dist/core/delegation/worker-result.js.map +0 -1
  666. package/dist/core/telemetry.d.ts.map +0 -1
  667. package/dist/core/telemetry.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"risk-assessment.d.ts","sourceRoot":"","sources":["../../../src/core/autonomy/risk-assessment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AA8B1E,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,mBAAmB,GAAG,cAAc,CAoH9E","sourcesContent":["import type { RiskAssessment, RiskAssessmentInput } from \"./contracts.ts\";\n\nconst RELEASE_PUBLISH_RE = /\\b(publish|release|push|deploy|tag)\\b/i;\nconst SECURITY_AUTH_RE = /\\b(auth|token|credential|credentials|secret|api[-_]key)\\b/i;\nconst DESTRUCTIVE_RE = /\\b(delete|reset|rm\\s+-rf|clean)\\b/i;\n\nconst SELF_MOD_MUTATE_RE =\n\t/\\b(modify|change|write|update|edit|delete|add|remove|set)\\s+.*\\b(skills|prompts|settings|tools|behavior)\\b|self[-_]modification/i;\nconst ARCHITECTURE_MUTATE_RE = /\\b(rewrite|redesign|change|modify|rearchitect)\\s+.*\\b(architecture|architect)\\b/i;\n\nconst READ_ONLY_QUESTION_RE =\n\t/^(?:(?:can you|could you|please|pls|go ahead and|let'?s|i need you to|we need to|you should)\\s+)?(?:how|what|why|when|where|which|who|explain|summarize|compare|describe|list|show|search|find|view|read|locate)\\b/i;\n\nconst EXPLICIT_MODIFY_REQUEST_RE =\n\t/^(?:can you|could you|please|pls|go ahead and|let'?s|i need you to|we need to|you should)\\s+.*\\b(add|apply|build|change|commit|create|delete|edit|fix|generate|implement|install|modify|patch|refactor|remove|rename|replace|run|test|update|write|publish|release|push|deploy|tag|reset|clean|rewrite)\\b/i;\n\n// Shell parsing helpers\nconst DESTRUCTIVE_CMD_RE =\n\t/\\b(rm(\\s+-r|\\s+-f|\\s+-rf|\\s+-fr)?|mv|cp|chmod|chown|install)\\b|>\\s*\\/dev\\/(sda|hda|vda)|\\b(dd\\s+if=)/i;\nconst GIT_MUTATE_CMD_RE = /\\bgit\\s+(commit|push|reset|clean|stash|rebase)\\b/i;\nconst PKG_MUTATE_CMD_RE = /\\b(npm|pnpm|yarn|bun)\\s+(install|i|update|up|publish|run|remove|rm|uninstall)\\b/i;\nconst RELEASE_DEPLOY_CMD_RE = /\\b(release|deploy)\\b/i;\nconst PYTHON_HIGH_IMPACT_RE =\n\t/\\b(?:shutil\\.(?:rmtree|move|copy|copy2|copytree)|os\\.(?:remove|unlink|rmdir|removedirs|system)|subprocess\\.(?:run|call|check_call|check_output|Popen)|Path\\([^)]*\\)\\.(?:unlink|rmdir))\\b/i;\nconst REDIRECTION_RE = /[<>]/;\n\nfunction stripSingleQuotes(cmd: string): string {\n\treturn cmd.replace(/'[^']*'/g, \"''\");\n}\n\nexport function assessOperationRisk(input: RiskAssessmentInput): RiskAssessment {\n\tconst operation = input.operation.trim();\n\tconst command = input.command?.trim() ?? \"\";\n\tconst cleanCommand = command ? stripSingleQuotes(command) : \"\";\n\tconst fullText = `${operation} ${command}`.trim();\n\tconst cleanFullText = `${operation} ${cleanCommand}`.trim();\n\n\tif (fullText.length === 0) {\n\t\treturn {\n\t\t\trisk: \"read-only\",\n\t\t\treasonCode: \"empty_operation\",\n\t\t\treasons: [\"Empty operation\"],\n\t\t\trequiresApproval: false,\n\t\t};\n\t}\n\n\t// 1. Explicit read-only operations\n\tif (READ_ONLY_QUESTION_RE.test(operation) && !EXPLICIT_MODIFY_REQUEST_RE.test(operation)) {\n\t\treturn {\n\t\t\trisk: \"read-only\",\n\t\t\treasonCode: \"read_only_operation\",\n\t\t\treasons: [\"Operation is explicitly read-only (list/show/read/search)\"],\n\t\t\trequiresApproval: false,\n\t\t};\n\t}\n\n\t// 2. High-risk actions\n\tif (RELEASE_PUBLISH_RE.test(cleanFullText)) {\n\t\treturn {\n\t\t\trisk: \"approval-required\",\n\t\t\treasonCode: \"release_publish_operation\",\n\t\t\treasons: [\"Operation mentions releasing, publishing, or deploying\"],\n\t\t\trequiresApproval: true,\n\t\t};\n\t}\n\tif (SECURITY_AUTH_RE.test(cleanFullText)) {\n\t\treturn {\n\t\t\trisk: \"approval-required\", // updated based on user instruction: \"high-impact or approval-required\"\n\t\t\treasonCode: \"security_auth_operation\",\n\t\t\treasons: [\"Operation mentions authentication or credentials\"],\n\t\t\trequiresApproval: true,\n\t\t};\n\t}\n\tif (DESTRUCTIVE_RE.test(cleanFullText)) {\n\t\treturn {\n\t\t\trisk: \"approval-required\",\n\t\t\treasonCode: \"destructive_operation\",\n\t\t\treasons: [\"Operation involves deleting, resetting, or cleaning\"],\n\t\t\trequiresApproval: true,\n\t\t};\n\t}\n\tif (SELF_MOD_MUTATE_RE.test(cleanFullText)) {\n\t\treturn {\n\t\t\trisk: \"approval-required\",\n\t\t\treasonCode: \"self_modification_operation\",\n\t\t\treasons: [\"Operation modifies settings, tools, skills, or prompts\"],\n\t\t\trequiresApproval: true,\n\t\t};\n\t}\n\tif (ARCHITECTURE_MUTATE_RE.test(cleanFullText)) {\n\t\treturn {\n\t\t\trisk: \"high-impact\",\n\t\t\treasonCode: \"architecture_mutation_operation\",\n\t\t\treasons: [\"Operation mentions rewriting or rearchitecting core parts\"],\n\t\t\trequiresApproval: false,\n\t\t};\n\t}\n\n\t// 3. Command risks\n\tif (command) {\n\t\tconst cleanCmd = stripSingleQuotes(command);\n\t\tif (\n\t\t\tDESTRUCTIVE_CMD_RE.test(cleanCmd) ||\n\t\t\tGIT_MUTATE_CMD_RE.test(cleanCmd) ||\n\t\t\tPKG_MUTATE_CMD_RE.test(cleanCmd) ||\n\t\t\tRELEASE_DEPLOY_CMD_RE.test(cleanCmd) ||\n\t\t\tPYTHON_HIGH_IMPACT_RE.test(cleanCmd) ||\n\t\t\tREDIRECTION_RE.test(cleanCmd)\n\t\t) {\n\t\t\treturn {\n\t\t\t\trisk: \"approval-required\",\n\t\t\t\treasonCode: \"mutating_command\",\n\t\t\t\treasons: [\"Command executes a destructive, mutating, or publish operation\"],\n\t\t\t\trequiresApproval: true,\n\t\t\t};\n\t\t}\n\t}\n\n\t// Default to scoped-write for any generic mutating tool action if it has a toolName or isn't read-only\n\t// or read-only if it's purely a non-mutating intent (but since it didn't match read-only above, we default to scoped-write)\n\tif (\n\t\tinput.toolName &&\n\t\t![\"read_file\", \"search_web\", \"list_dir\", \"grep_search\", \"view_file\", \"memory\"].includes(input.toolName)\n\t) {\n\t\treturn {\n\t\t\trisk: \"scoped-write\",\n\t\t\treasonCode: \"generic_mutation\",\n\t\t\treasons: [\"Generic mutating operation or command\"],\n\t\t\trequiresApproval: false,\n\t\t};\n\t}\n\n\tif (command) {\n\t\t// Even if not explicitly destructive, shell commands could be anything, but we assume read-only if it's just 'ls', 'git status' etc.\n\t\t// For now, if no mutating patterns matched, we assume read-only if there's no toolName, but wait, normal file edits are scoped-write.\n\t\t// If there is a command, and it doesn't match the mutating patterns, we fall through to read-only.\n\t\t// Wait, user says \"Risk shell read-only commands like git status, rg, ls, npm view do not require approval.\"\n\t\t// And \"ordinary file edits inside allowed scope are scoped-write.\" (Handled by tools)\n\t}\n\n\treturn {\n\t\trisk: \"read-only\",\n\t\treasonCode: \"default_read_only\",\n\t\treasons: [\"No mutating or high-risk patterns detected\"],\n\t\trequiresApproval: false,\n\t};\n}\n"]}
1
+ {"version":3,"file":"risk-assessment.d.ts","sourceRoot":"","sources":["../../../src/core/autonomy/risk-assessment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC","sourcesContent":["export { assessOperationRisk } from \"../risk-classifier.ts\";\n"]}
@@ -1,124 +1,2 @@
1
- const RELEASE_PUBLISH_RE = /\b(publish|release|push|deploy|tag)\b/i;
2
- const SECURITY_AUTH_RE = /\b(auth|token|credential|credentials|secret|api[-_]key)\b/i;
3
- const DESTRUCTIVE_RE = /\b(delete|reset|rm\s+-rf|clean)\b/i;
4
- const SELF_MOD_MUTATE_RE = /\b(modify|change|write|update|edit|delete|add|remove|set)\s+.*\b(skills|prompts|settings|tools|behavior)\b|self[-_]modification/i;
5
- const ARCHITECTURE_MUTATE_RE = /\b(rewrite|redesign|change|modify|rearchitect)\s+.*\b(architecture|architect)\b/i;
6
- const READ_ONLY_QUESTION_RE = /^(?:(?:can you|could you|please|pls|go ahead and|let'?s|i need you to|we need to|you should)\s+)?(?:how|what|why|when|where|which|who|explain|summarize|compare|describe|list|show|search|find|view|read|locate)\b/i;
7
- const EXPLICIT_MODIFY_REQUEST_RE = /^(?:can you|could you|please|pls|go ahead and|let'?s|i need you to|we need to|you should)\s+.*\b(add|apply|build|change|commit|create|delete|edit|fix|generate|implement|install|modify|patch|refactor|remove|rename|replace|run|test|update|write|publish|release|push|deploy|tag|reset|clean|rewrite)\b/i;
8
- // Shell parsing helpers
9
- const DESTRUCTIVE_CMD_RE = /\b(rm(\s+-r|\s+-f|\s+-rf|\s+-fr)?|mv|cp|chmod|chown|install)\b|>\s*\/dev\/(sda|hda|vda)|\b(dd\s+if=)/i;
10
- const GIT_MUTATE_CMD_RE = /\bgit\s+(commit|push|reset|clean|stash|rebase)\b/i;
11
- const PKG_MUTATE_CMD_RE = /\b(npm|pnpm|yarn|bun)\s+(install|i|update|up|publish|run|remove|rm|uninstall)\b/i;
12
- const RELEASE_DEPLOY_CMD_RE = /\b(release|deploy)\b/i;
13
- const PYTHON_HIGH_IMPACT_RE = /\b(?:shutil\.(?:rmtree|move|copy|copy2|copytree)|os\.(?:remove|unlink|rmdir|removedirs|system)|subprocess\.(?:run|call|check_call|check_output|Popen)|Path\([^)]*\)\.(?:unlink|rmdir))\b/i;
14
- const REDIRECTION_RE = /[<>]/;
15
- function stripSingleQuotes(cmd) {
16
- return cmd.replace(/'[^']*'/g, "''");
17
- }
18
- export function assessOperationRisk(input) {
19
- const operation = input.operation.trim();
20
- const command = input.command?.trim() ?? "";
21
- const cleanCommand = command ? stripSingleQuotes(command) : "";
22
- const fullText = `${operation} ${command}`.trim();
23
- const cleanFullText = `${operation} ${cleanCommand}`.trim();
24
- if (fullText.length === 0) {
25
- return {
26
- risk: "read-only",
27
- reasonCode: "empty_operation",
28
- reasons: ["Empty operation"],
29
- requiresApproval: false,
30
- };
31
- }
32
- // 1. Explicit read-only operations
33
- if (READ_ONLY_QUESTION_RE.test(operation) && !EXPLICIT_MODIFY_REQUEST_RE.test(operation)) {
34
- return {
35
- risk: "read-only",
36
- reasonCode: "read_only_operation",
37
- reasons: ["Operation is explicitly read-only (list/show/read/search)"],
38
- requiresApproval: false,
39
- };
40
- }
41
- // 2. High-risk actions
42
- if (RELEASE_PUBLISH_RE.test(cleanFullText)) {
43
- return {
44
- risk: "approval-required",
45
- reasonCode: "release_publish_operation",
46
- reasons: ["Operation mentions releasing, publishing, or deploying"],
47
- requiresApproval: true,
48
- };
49
- }
50
- if (SECURITY_AUTH_RE.test(cleanFullText)) {
51
- return {
52
- risk: "approval-required", // updated based on user instruction: "high-impact or approval-required"
53
- reasonCode: "security_auth_operation",
54
- reasons: ["Operation mentions authentication or credentials"],
55
- requiresApproval: true,
56
- };
57
- }
58
- if (DESTRUCTIVE_RE.test(cleanFullText)) {
59
- return {
60
- risk: "approval-required",
61
- reasonCode: "destructive_operation",
62
- reasons: ["Operation involves deleting, resetting, or cleaning"],
63
- requiresApproval: true,
64
- };
65
- }
66
- if (SELF_MOD_MUTATE_RE.test(cleanFullText)) {
67
- return {
68
- risk: "approval-required",
69
- reasonCode: "self_modification_operation",
70
- reasons: ["Operation modifies settings, tools, skills, or prompts"],
71
- requiresApproval: true,
72
- };
73
- }
74
- if (ARCHITECTURE_MUTATE_RE.test(cleanFullText)) {
75
- return {
76
- risk: "high-impact",
77
- reasonCode: "architecture_mutation_operation",
78
- reasons: ["Operation mentions rewriting or rearchitecting core parts"],
79
- requiresApproval: false,
80
- };
81
- }
82
- // 3. Command risks
83
- if (command) {
84
- const cleanCmd = stripSingleQuotes(command);
85
- if (DESTRUCTIVE_CMD_RE.test(cleanCmd) ||
86
- GIT_MUTATE_CMD_RE.test(cleanCmd) ||
87
- PKG_MUTATE_CMD_RE.test(cleanCmd) ||
88
- RELEASE_DEPLOY_CMD_RE.test(cleanCmd) ||
89
- PYTHON_HIGH_IMPACT_RE.test(cleanCmd) ||
90
- REDIRECTION_RE.test(cleanCmd)) {
91
- return {
92
- risk: "approval-required",
93
- reasonCode: "mutating_command",
94
- reasons: ["Command executes a destructive, mutating, or publish operation"],
95
- requiresApproval: true,
96
- };
97
- }
98
- }
99
- // Default to scoped-write for any generic mutating tool action if it has a toolName or isn't read-only
100
- // or read-only if it's purely a non-mutating intent (but since it didn't match read-only above, we default to scoped-write)
101
- if (input.toolName &&
102
- !["read_file", "search_web", "list_dir", "grep_search", "view_file", "memory"].includes(input.toolName)) {
103
- return {
104
- risk: "scoped-write",
105
- reasonCode: "generic_mutation",
106
- reasons: ["Generic mutating operation or command"],
107
- requiresApproval: false,
108
- };
109
- }
110
- if (command) {
111
- // Even if not explicitly destructive, shell commands could be anything, but we assume read-only if it's just 'ls', 'git status' etc.
112
- // For now, if no mutating patterns matched, we assume read-only if there's no toolName, but wait, normal file edits are scoped-write.
113
- // If there is a command, and it doesn't match the mutating patterns, we fall through to read-only.
114
- // Wait, user says "Risk shell read-only commands like git status, rg, ls, npm view do not require approval."
115
- // And "ordinary file edits inside allowed scope are scoped-write." (Handled by tools)
116
- }
117
- return {
118
- risk: "read-only",
119
- reasonCode: "default_read_only",
120
- reasons: ["No mutating or high-risk patterns detected"],
121
- requiresApproval: false,
122
- };
123
- }
1
+ export { assessOperationRisk } from "../risk-classifier.js";
124
2
  //# sourceMappingURL=risk-assessment.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"risk-assessment.js","sourceRoot":"","sources":["../../../src/core/autonomy/risk-assessment.ts"],"names":[],"mappings":"AAEA,MAAM,kBAAkB,GAAG,wCAAwC,CAAC;AACpE,MAAM,gBAAgB,GAAG,4DAA4D,CAAC;AACtF,MAAM,cAAc,GAAG,oCAAoC,CAAC;AAE5D,MAAM,kBAAkB,GACvB,kIAAkI,CAAC;AACpI,MAAM,sBAAsB,GAAG,kFAAkF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import type { RiskAssessment, RiskAssessmentInput } from \"./contracts.ts\";\n\nconst RELEASE_PUBLISH_RE = /\\b(publish|release|push|deploy|tag)\\b/i;\nconst SECURITY_AUTH_RE = /\\b(auth|token|credential|credentials|secret|api[-_]key)\\b/i;\nconst DESTRUCTIVE_RE = /\\b(delete|reset|rm\\s+-rf|clean)\\b/i;\n\nconst SELF_MOD_MUTATE_RE =\n\t/\\b(modify|change|write|update|edit|delete|add|remove|set)\\s+.*\\b(skills|prompts|settings|tools|behavior)\\b|self[-_]modification/i;\nconst ARCHITECTURE_MUTATE_RE = /\\b(rewrite|redesign|change|modify|rearchitect)\\s+.*\\b(architecture|architect)\\b/i;\n\nconst READ_ONLY_QUESTION_RE =\n\t/^(?:(?:can you|could you|please|pls|go ahead and|let'?s|i need you to|we need to|you should)\\s+)?(?:how|what|why|when|where|which|who|explain|summarize|compare|describe|list|show|search|find|view|read|locate)\\b/i;\n\nconst EXPLICIT_MODIFY_REQUEST_RE =\n\t/^(?:can you|could you|please|pls|go ahead and|let'?s|i need you to|we need to|you should)\\s+.*\\b(add|apply|build|change|commit|create|delete|edit|fix|generate|implement|install|modify|patch|refactor|remove|rename|replace|run|test|update|write|publish|release|push|deploy|tag|reset|clean|rewrite)\\b/i;\n\n// Shell parsing helpers\nconst DESTRUCTIVE_CMD_RE =\n\t/\\b(rm(\\s+-r|\\s+-f|\\s+-rf|\\s+-fr)?|mv|cp|chmod|chown|install)\\b|>\\s*\\/dev\\/(sda|hda|vda)|\\b(dd\\s+if=)/i;\nconst GIT_MUTATE_CMD_RE = /\\bgit\\s+(commit|push|reset|clean|stash|rebase)\\b/i;\nconst PKG_MUTATE_CMD_RE = /\\b(npm|pnpm|yarn|bun)\\s+(install|i|update|up|publish|run|remove|rm|uninstall)\\b/i;\nconst RELEASE_DEPLOY_CMD_RE = /\\b(release|deploy)\\b/i;\nconst PYTHON_HIGH_IMPACT_RE =\n\t/\\b(?:shutil\\.(?:rmtree|move|copy|copy2|copytree)|os\\.(?:remove|unlink|rmdir|removedirs|system)|subprocess\\.(?:run|call|check_call|check_output|Popen)|Path\\([^)]*\\)\\.(?:unlink|rmdir))\\b/i;\nconst REDIRECTION_RE = /[<>]/;\n\nfunction stripSingleQuotes(cmd: string): string {\n\treturn cmd.replace(/'[^']*'/g, \"''\");\n}\n\nexport function assessOperationRisk(input: RiskAssessmentInput): RiskAssessment {\n\tconst operation = input.operation.trim();\n\tconst command = input.command?.trim() ?? \"\";\n\tconst cleanCommand = command ? stripSingleQuotes(command) : \"\";\n\tconst fullText = `${operation} ${command}`.trim();\n\tconst cleanFullText = `${operation} ${cleanCommand}`.trim();\n\n\tif (fullText.length === 0) {\n\t\treturn {\n\t\t\trisk: \"read-only\",\n\t\t\treasonCode: \"empty_operation\",\n\t\t\treasons: [\"Empty operation\"],\n\t\t\trequiresApproval: false,\n\t\t};\n\t}\n\n\t// 1. Explicit read-only operations\n\tif (READ_ONLY_QUESTION_RE.test(operation) && !EXPLICIT_MODIFY_REQUEST_RE.test(operation)) {\n\t\treturn {\n\t\t\trisk: \"read-only\",\n\t\t\treasonCode: \"read_only_operation\",\n\t\t\treasons: [\"Operation is explicitly read-only (list/show/read/search)\"],\n\t\t\trequiresApproval: false,\n\t\t};\n\t}\n\n\t// 2. High-risk actions\n\tif (RELEASE_PUBLISH_RE.test(cleanFullText)) {\n\t\treturn {\n\t\t\trisk: \"approval-required\",\n\t\t\treasonCode: \"release_publish_operation\",\n\t\t\treasons: [\"Operation mentions releasing, publishing, or deploying\"],\n\t\t\trequiresApproval: true,\n\t\t};\n\t}\n\tif (SECURITY_AUTH_RE.test(cleanFullText)) {\n\t\treturn {\n\t\t\trisk: \"approval-required\", // updated based on user instruction: \"high-impact or approval-required\"\n\t\t\treasonCode: \"security_auth_operation\",\n\t\t\treasons: [\"Operation mentions authentication or credentials\"],\n\t\t\trequiresApproval: true,\n\t\t};\n\t}\n\tif (DESTRUCTIVE_RE.test(cleanFullText)) {\n\t\treturn {\n\t\t\trisk: \"approval-required\",\n\t\t\treasonCode: \"destructive_operation\",\n\t\t\treasons: [\"Operation involves deleting, resetting, or cleaning\"],\n\t\t\trequiresApproval: true,\n\t\t};\n\t}\n\tif (SELF_MOD_MUTATE_RE.test(cleanFullText)) {\n\t\treturn {\n\t\t\trisk: \"approval-required\",\n\t\t\treasonCode: \"self_modification_operation\",\n\t\t\treasons: [\"Operation modifies settings, tools, skills, or prompts\"],\n\t\t\trequiresApproval: true,\n\t\t};\n\t}\n\tif (ARCHITECTURE_MUTATE_RE.test(cleanFullText)) {\n\t\treturn {\n\t\t\trisk: \"high-impact\",\n\t\t\treasonCode: \"architecture_mutation_operation\",\n\t\t\treasons: [\"Operation mentions rewriting or rearchitecting core parts\"],\n\t\t\trequiresApproval: false,\n\t\t};\n\t}\n\n\t// 3. Command risks\n\tif (command) {\n\t\tconst cleanCmd = stripSingleQuotes(command);\n\t\tif (\n\t\t\tDESTRUCTIVE_CMD_RE.test(cleanCmd) ||\n\t\t\tGIT_MUTATE_CMD_RE.test(cleanCmd) ||\n\t\t\tPKG_MUTATE_CMD_RE.test(cleanCmd) ||\n\t\t\tRELEASE_DEPLOY_CMD_RE.test(cleanCmd) ||\n\t\t\tPYTHON_HIGH_IMPACT_RE.test(cleanCmd) ||\n\t\t\tREDIRECTION_RE.test(cleanCmd)\n\t\t) {\n\t\t\treturn {\n\t\t\t\trisk: \"approval-required\",\n\t\t\t\treasonCode: \"mutating_command\",\n\t\t\t\treasons: [\"Command executes a destructive, mutating, or publish operation\"],\n\t\t\t\trequiresApproval: true,\n\t\t\t};\n\t\t}\n\t}\n\n\t// Default to scoped-write for any generic mutating tool action if it has a toolName or isn't read-only\n\t// or read-only if it's purely a non-mutating intent (but since it didn't match read-only above, we default to scoped-write)\n\tif (\n\t\tinput.toolName &&\n\t\t![\"read_file\", \"search_web\", \"list_dir\", \"grep_search\", \"view_file\", \"memory\"].includes(input.toolName)\n\t) {\n\t\treturn {\n\t\t\trisk: \"scoped-write\",\n\t\t\treasonCode: \"generic_mutation\",\n\t\t\treasons: [\"Generic mutating operation or command\"],\n\t\t\trequiresApproval: false,\n\t\t};\n\t}\n\n\tif (command) {\n\t\t// Even if not explicitly destructive, shell commands could be anything, but we assume read-only if it's just 'ls', 'git status' etc.\n\t\t// For now, if no mutating patterns matched, we assume read-only if there's no toolName, but wait, normal file edits are scoped-write.\n\t\t// If there is a command, and it doesn't match the mutating patterns, we fall through to read-only.\n\t\t// Wait, user says \"Risk shell read-only commands like git status, rg, ls, npm view do not require approval.\"\n\t\t// And \"ordinary file edits inside allowed scope are scoped-write.\" (Handled by tools)\n\t}\n\n\treturn {\n\t\trisk: \"read-only\",\n\t\treasonCode: \"default_read_only\",\n\t\treasons: [\"No mutating or high-risk patterns detected\"],\n\t\trequiresApproval: false,\n\t};\n}\n"]}
1
+ {"version":3,"file":"risk-assessment.js","sourceRoot":"","sources":["../../../src/core/autonomy/risk-assessment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC","sourcesContent":["export { assessOperationRisk } from \"../risk-classifier.ts\";\n"]}
@@ -1,10 +1,10 @@
1
1
  import type { SessionEntry, SessionManager } from "@caupulican/pi-agent-core/node";
2
+ import { type SessionSnapshotPayload } from "../session-snapshot.ts";
2
3
  import { type LaneRecord } from "./lane-tracker.ts";
3
4
  export declare const LANE_RECORD_CUSTOM_TYPE = "lane_record";
4
- export interface LaneRecordSnapshotPayload {
5
- version: 1;
6
- record: LaneRecord;
7
- }
5
+ export type LaneRecordSnapshotPayload = SessionSnapshotPayload<"record", LaneRecord>;
8
6
  export declare function appendLaneRecordSnapshot(sessionManager: Pick<SessionManager, "appendCustomEntry">, record: LaneRecord): string;
9
7
  export declare function getLaneRecordSnapshots(entries: readonly SessionEntry[]): LaneRecord[];
8
+ /** Latest durable projection per logical lane id, preserving first-seen lane order. */
9
+ export declare function getLatestLaneRecordSnapshots(entries: readonly SessionEntry[]): LaneRecord[];
10
10
  //# sourceMappingURL=session-lane-record.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"session-lane-record.d.ts","sourceRoot":"","sources":["../../../src/core/autonomy/session-lane-record.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AACnF,OAAO,EAA2C,KAAK,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE7F,eAAO,MAAM,uBAAuB,gBAAgB,CAAC;AAErD,MAAM,WAAW,yBAAyB;IACzC,OAAO,EAAE,CAAC,CAAC;IACX,MAAM,EAAE,UAAU,CAAC;CACnB;AAED,wBAAgB,wBAAwB,CACvC,cAAc,EAAE,IAAI,CAAC,cAAc,EAAE,mBAAmB,CAAC,EACzD,MAAM,EAAE,UAAU,GAChB,MAAM,CAMR;AAQD,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,SAAS,YAAY,EAAE,GAAG,UAAU,EAAE,CAmBrF","sourcesContent":["import type { SessionEntry, SessionManager } from \"@caupulican/pi-agent-core/node\";\nimport { cloneLaneRecordForStorage, isLaneRecord, type LaneRecord } from \"./lane-tracker.ts\";\n\nexport const LANE_RECORD_CUSTOM_TYPE = \"lane_record\";\n\nexport interface LaneRecordSnapshotPayload {\n\tversion: 1;\n\trecord: LaneRecord;\n}\n\nexport function appendLaneRecordSnapshot(\n\tsessionManager: Pick<SessionManager, \"appendCustomEntry\">,\n\trecord: LaneRecord,\n): string {\n\tconst payload: LaneRecordSnapshotPayload = {\n\t\tversion: 1,\n\t\trecord: cloneLaneRecordForStorage(record),\n\t};\n\treturn sessionManager.appendCustomEntry(LANE_RECORD_CUSTOM_TYPE, payload);\n}\n\nfunction isPlainRecord(value: unknown): value is Record<string, unknown> {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) return false;\n\tconst prototype = Object.getPrototypeOf(value);\n\treturn prototype === Object.prototype || prototype === null;\n}\n\nexport function getLaneRecordSnapshots(entries: readonly SessionEntry[]): LaneRecord[] {\n\tconst records: LaneRecord[] = [];\n\n\tfor (const entry of entries) {\n\t\tif (entry.type !== \"custom\" || entry.customType !== LANE_RECORD_CUSTOM_TYPE) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst payload = entry.data;\n\t\tif (!isPlainRecord(payload)) continue;\n\t\tif (payload.version !== 1) continue;\n\t\tif (!(\"record\" in payload)) continue;\n\t\tconst record = payload.record;\n\t\tif (isLaneRecord(record)) {\n\t\t\trecords.push(cloneLaneRecordForStorage(record));\n\t\t}\n\t}\n\n\treturn records;\n}\n"]}
1
+ {"version":3,"file":"session-lane-record.d.ts","sourceRoot":"","sources":["../../../src/core/autonomy/session-lane-record.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AACnF,OAAO,EAIN,KAAK,sBAAsB,EAC3B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAA2C,KAAK,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE7F,eAAO,MAAM,uBAAuB,gBAAgB,CAAC;AAErD,MAAM,MAAM,yBAAyB,GAAG,sBAAsB,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;AASrF,wBAAgB,wBAAwB,CACvC,cAAc,EAAE,IAAI,CAAC,cAAc,EAAE,mBAAmB,CAAC,EACzD,MAAM,EAAE,UAAU,GAChB,MAAM,CAER;AAED,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,SAAS,YAAY,EAAE,GAAG,UAAU,EAAE,CAErF;AAED,uFAAuF;AACvF,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,SAAS,YAAY,EAAE,GAAG,UAAU,EAAE,CAI3F","sourcesContent":["import type { SessionEntry, SessionManager } from \"@caupulican/pi-agent-core/node\";\nimport {\n\tappendSessionSnapshot,\n\tgetSessionSnapshots,\n\ttype SessionSnapshotCodec,\n\ttype SessionSnapshotPayload,\n} from \"../session-snapshot.ts\";\nimport { cloneLaneRecordForStorage, isLaneRecord, type LaneRecord } from \"./lane-tracker.ts\";\n\nexport const LANE_RECORD_CUSTOM_TYPE = \"lane_record\";\n\nexport type LaneRecordSnapshotPayload = SessionSnapshotPayload<\"record\", LaneRecord>;\n\nconst LANE_RECORD_SNAPSHOT_CODEC: SessionSnapshotCodec<LaneRecord, \"record\"> = {\n\tcustomType: LANE_RECORD_CUSTOM_TYPE,\n\tvalueKey: \"record\",\n\tisValue: isLaneRecord,\n\tclone: cloneLaneRecordForStorage,\n};\n\nexport function appendLaneRecordSnapshot(\n\tsessionManager: Pick<SessionManager, \"appendCustomEntry\">,\n\trecord: LaneRecord,\n): string {\n\treturn appendSessionSnapshot(sessionManager, LANE_RECORD_SNAPSHOT_CODEC, record);\n}\n\nexport function getLaneRecordSnapshots(entries: readonly SessionEntry[]): LaneRecord[] {\n\treturn getSessionSnapshots(entries, LANE_RECORD_SNAPSHOT_CODEC);\n}\n\n/** Latest durable projection per logical lane id, preserving first-seen lane order. */\nexport function getLatestLaneRecordSnapshots(entries: readonly SessionEntry[]): LaneRecord[] {\n\tconst latest = new Map<string, LaneRecord>();\n\tfor (const record of getLaneRecordSnapshots(entries)) latest.set(record.laneId, record);\n\treturn [...latest.values()].map(cloneLaneRecordForStorage);\n}\n"]}
@@ -1,36 +1,23 @@
1
+ import { appendSessionSnapshot, getSessionSnapshots, } from "../session-snapshot.js";
1
2
  import { cloneLaneRecordForStorage, isLaneRecord } from "./lane-tracker.js";
2
3
  export const LANE_RECORD_CUSTOM_TYPE = "lane_record";
4
+ const LANE_RECORD_SNAPSHOT_CODEC = {
5
+ customType: LANE_RECORD_CUSTOM_TYPE,
6
+ valueKey: "record",
7
+ isValue: isLaneRecord,
8
+ clone: cloneLaneRecordForStorage,
9
+ };
3
10
  export function appendLaneRecordSnapshot(sessionManager, record) {
4
- const payload = {
5
- version: 1,
6
- record: cloneLaneRecordForStorage(record),
7
- };
8
- return sessionManager.appendCustomEntry(LANE_RECORD_CUSTOM_TYPE, payload);
9
- }
10
- function isPlainRecord(value) {
11
- if (!value || typeof value !== "object" || Array.isArray(value))
12
- return false;
13
- const prototype = Object.getPrototypeOf(value);
14
- return prototype === Object.prototype || prototype === null;
11
+ return appendSessionSnapshot(sessionManager, LANE_RECORD_SNAPSHOT_CODEC, record);
15
12
  }
16
13
  export function getLaneRecordSnapshots(entries) {
17
- const records = [];
18
- for (const entry of entries) {
19
- if (entry.type !== "custom" || entry.customType !== LANE_RECORD_CUSTOM_TYPE) {
20
- continue;
21
- }
22
- const payload = entry.data;
23
- if (!isPlainRecord(payload))
24
- continue;
25
- if (payload.version !== 1)
26
- continue;
27
- if (!("record" in payload))
28
- continue;
29
- const record = payload.record;
30
- if (isLaneRecord(record)) {
31
- records.push(cloneLaneRecordForStorage(record));
32
- }
33
- }
34
- return records;
14
+ return getSessionSnapshots(entries, LANE_RECORD_SNAPSHOT_CODEC);
15
+ }
16
+ /** Latest durable projection per logical lane id, preserving first-seen lane order. */
17
+ export function getLatestLaneRecordSnapshots(entries) {
18
+ const latest = new Map();
19
+ for (const record of getLaneRecordSnapshots(entries))
20
+ latest.set(record.laneId, record);
21
+ return [...latest.values()].map(cloneLaneRecordForStorage);
35
22
  }
36
23
  //# sourceMappingURL=session-lane-record.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"session-lane-record.js","sourceRoot":"","sources":["../../../src/core/autonomy/session-lane-record.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,YAAY,EAAmB,MAAM,mBAAmB,CAAC;AAE7F,MAAM,CAAC,MAAM,uBAAuB,GAAG,aAAa,CAAC;AAOrD,MAAM,UAAU,wBAAwB,CACvC,cAAyD,EACzD,MAAkB,EACT;IACT,MAAM,OAAO,GAA8B;QAC1C,OAAO,EAAE,CAAC;QACV,MAAM,EAAE,yBAAyB,CAAC,MAAM,CAAC;KACzC,CAAC;IACF,OAAO,cAAc,CAAC,iBAAiB,CAAC,uBAAuB,EAAE,OAAO,CAAC,CAAC;AAAA,CAC1E;AAED,SAAS,aAAa,CAAC,KAAc,EAAoC;IACxE,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAC9E,MAAM,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IAC/C,OAAO,SAAS,KAAK,MAAM,CAAC,SAAS,IAAI,SAAS,KAAK,IAAI,CAAC;AAAA,CAC5D;AAED,MAAM,UAAU,sBAAsB,CAAC,OAAgC,EAAgB;IACtF,MAAM,OAAO,GAAiB,EAAE,CAAC;IAEjC,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC7B,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,UAAU,KAAK,uBAAuB,EAAE,CAAC;YAC7E,SAAS;QACV,CAAC;QAED,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC;QAC3B,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC;YAAE,SAAS;QACtC,IAAI,OAAO,CAAC,OAAO,KAAK,CAAC;YAAE,SAAS;QACpC,IAAI,CAAC,CAAC,QAAQ,IAAI,OAAO,CAAC;YAAE,SAAS;QACrC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC9B,IAAI,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC;YAC1B,OAAO,CAAC,IAAI,CAAC,yBAAyB,CAAC,MAAM,CAAC,CAAC,CAAC;QACjD,CAAC;IACF,CAAC;IAED,OAAO,OAAO,CAAC;AAAA,CACf","sourcesContent":["import type { SessionEntry, SessionManager } from \"@caupulican/pi-agent-core/node\";\nimport { cloneLaneRecordForStorage, isLaneRecord, type LaneRecord } from \"./lane-tracker.ts\";\n\nexport const LANE_RECORD_CUSTOM_TYPE = \"lane_record\";\n\nexport interface LaneRecordSnapshotPayload {\n\tversion: 1;\n\trecord: LaneRecord;\n}\n\nexport function appendLaneRecordSnapshot(\n\tsessionManager: Pick<SessionManager, \"appendCustomEntry\">,\n\trecord: LaneRecord,\n): string {\n\tconst payload: LaneRecordSnapshotPayload = {\n\t\tversion: 1,\n\t\trecord: cloneLaneRecordForStorage(record),\n\t};\n\treturn sessionManager.appendCustomEntry(LANE_RECORD_CUSTOM_TYPE, payload);\n}\n\nfunction isPlainRecord(value: unknown): value is Record<string, unknown> {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) return false;\n\tconst prototype = Object.getPrototypeOf(value);\n\treturn prototype === Object.prototype || prototype === null;\n}\n\nexport function getLaneRecordSnapshots(entries: readonly SessionEntry[]): LaneRecord[] {\n\tconst records: LaneRecord[] = [];\n\n\tfor (const entry of entries) {\n\t\tif (entry.type !== \"custom\" || entry.customType !== LANE_RECORD_CUSTOM_TYPE) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst payload = entry.data;\n\t\tif (!isPlainRecord(payload)) continue;\n\t\tif (payload.version !== 1) continue;\n\t\tif (!(\"record\" in payload)) continue;\n\t\tconst record = payload.record;\n\t\tif (isLaneRecord(record)) {\n\t\t\trecords.push(cloneLaneRecordForStorage(record));\n\t\t}\n\t}\n\n\treturn records;\n}\n"]}
1
+ {"version":3,"file":"session-lane-record.js","sourceRoot":"","sources":["../../../src/core/autonomy/session-lane-record.ts"],"names":[],"mappings":"AACA,OAAO,EACN,qBAAqB,EACrB,mBAAmB,GAGnB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,yBAAyB,EAAE,YAAY,EAAmB,MAAM,mBAAmB,CAAC;AAE7F,MAAM,CAAC,MAAM,uBAAuB,GAAG,aAAa,CAAC;AAIrD,MAAM,0BAA0B,GAA+C;IAC9E,UAAU,EAAE,uBAAuB;IACnC,QAAQ,EAAE,QAAQ;IAClB,OAAO,EAAE,YAAY;IACrB,KAAK,EAAE,yBAAyB;CAChC,CAAC;AAEF,MAAM,UAAU,wBAAwB,CACvC,cAAyD,EACzD,MAAkB,EACT;IACT,OAAO,qBAAqB,CAAC,cAAc,EAAE,0BAA0B,EAAE,MAAM,CAAC,CAAC;AAAA,CACjF;AAED,MAAM,UAAU,sBAAsB,CAAC,OAAgC,EAAgB;IACtF,OAAO,mBAAmB,CAAC,OAAO,EAAE,0BAA0B,CAAC,CAAC;AAAA,CAChE;AAED,uFAAuF;AACvF,MAAM,UAAU,4BAA4B,CAAC,OAAgC,EAAgB;IAC5F,MAAM,MAAM,GAAG,IAAI,GAAG,EAAsB,CAAC;IAC7C,KAAK,MAAM,MAAM,IAAI,sBAAsB,CAAC,OAAO,CAAC;QAAE,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxF,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;AAAA,CAC3D","sourcesContent":["import type { SessionEntry, SessionManager } from \"@caupulican/pi-agent-core/node\";\nimport {\n\tappendSessionSnapshot,\n\tgetSessionSnapshots,\n\ttype SessionSnapshotCodec,\n\ttype SessionSnapshotPayload,\n} from \"../session-snapshot.ts\";\nimport { cloneLaneRecordForStorage, isLaneRecord, type LaneRecord } from \"./lane-tracker.ts\";\n\nexport const LANE_RECORD_CUSTOM_TYPE = \"lane_record\";\n\nexport type LaneRecordSnapshotPayload = SessionSnapshotPayload<\"record\", LaneRecord>;\n\nconst LANE_RECORD_SNAPSHOT_CODEC: SessionSnapshotCodec<LaneRecord, \"record\"> = {\n\tcustomType: LANE_RECORD_CUSTOM_TYPE,\n\tvalueKey: \"record\",\n\tisValue: isLaneRecord,\n\tclone: cloneLaneRecordForStorage,\n};\n\nexport function appendLaneRecordSnapshot(\n\tsessionManager: Pick<SessionManager, \"appendCustomEntry\">,\n\trecord: LaneRecord,\n): string {\n\treturn appendSessionSnapshot(sessionManager, LANE_RECORD_SNAPSHOT_CODEC, record);\n}\n\nexport function getLaneRecordSnapshots(entries: readonly SessionEntry[]): LaneRecord[] {\n\treturn getSessionSnapshots(entries, LANE_RECORD_SNAPSHOT_CODEC);\n}\n\n/** Latest durable projection per logical lane id, preserving first-seen lane order. */\nexport function getLatestLaneRecordSnapshots(entries: readonly SessionEntry[]): LaneRecord[] {\n\tconst latest = new Map<string, LaneRecord>();\n\tfor (const record of getLaneRecordSnapshots(entries)) latest.set(record.laneId, record);\n\treturn [...latest.values()].map(cloneLaneRecordForStorage);\n}\n"]}
@@ -5,7 +5,7 @@ export declare const AUTONOMY_TELEMETRY_EVENT_TYPES: {
5
5
  readonly approvalRequest: "autonomy.approval_request";
6
6
  readonly evidenceBundle: "autonomy.evidence_bundle";
7
7
  readonly workerRequest: "autonomy.worker_request";
8
- readonly workerResult: "autonomy.worker_result";
8
+ readonly workerTerminal: "autonomy.worker_terminal";
9
9
  readonly learningDecision: "autonomy.learning_decision";
10
10
  };
11
11
  export type AutonomyTelemetryEventType = (typeof AUTONOMY_TELEMETRY_EVENT_TYPES)[keyof typeof AUTONOMY_TELEMETRY_EVENT_TYPES];
@@ -1 +1 @@
1
- {"version":3,"file":"telemetry-events.d.ts","sourceRoot":"","sources":["../../../src/core/autonomy/telemetry-events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,eAAO,MAAM,8BAA8B;;;;;;;;CAQjC,CAAC;AAEX,MAAM,MAAM,0BAA0B,GACrC,CAAC,OAAO,8BAA8B,CAAC,CAAC,MAAM,OAAO,8BAA8B,CAAC,CAAC;AAEtF,MAAM,WAAW,sBAAsB;IACtC,IAAI,EAAE,0BAA0B,CAAC;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,SAAS,CAAC;CACnB;AAiBD,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,SAAI,GAAG,OAAO,CAyCvE","sourcesContent":["import type { JsonValue } from \"./contracts.ts\";\n\nexport const AUTONOMY_TELEMETRY_EVENT_TYPES = {\n\trouteDecision: \"autonomy.route_decision\",\n\tgateOutcome: \"autonomy.gate_outcome\",\n\tapprovalRequest: \"autonomy.approval_request\",\n\tevidenceBundle: \"autonomy.evidence_bundle\",\n\tworkerRequest: \"autonomy.worker_request\",\n\tworkerResult: \"autonomy.worker_result\",\n\tlearningDecision: \"autonomy.learning_decision\",\n} as const;\n\nexport type AutonomyTelemetryEventType =\n\t(typeof AUTONOMY_TELEMETRY_EVENT_TYPES)[keyof typeof AUTONOMY_TELEMETRY_EVENT_TYPES];\n\nexport interface AutonomyTelemetryEvent {\n\ttype: AutonomyTelemetryEventType;\n\ttimestamp: string;\n\tpayload: JsonValue;\n}\n\nconst SECRET_KEYS = new Set([\n\t\"apikey\",\n\t\"api_key\",\n\t\"token\",\n\t\"accesstoken\",\n\t\"refreshtoken\",\n\t\"secret\",\n\t\"password\",\n\t\"authorization\",\n\t\"credential\",\n\t\"credentials\",\n]);\n\nconst BEARER_RE = /bearer\\s+\\S+/i;\n\nexport function redactTelemetryValue(value: unknown, depth = 0): unknown {\n\tif (depth > 20) {\n\t\treturn \"[Depth Limit Exceeded]\";\n\t}\n\n\tif (typeof value === \"string\") {\n\t\tif (BEARER_RE.test(value)) {\n\t\t\treturn \"[REDACTED BEARER TOKEN]\";\n\t\t}\n\t\tif (value.startsWith(\"sk-\")) {\n\t\t\treturn \"[REDACTED API KEY]\";\n\t\t}\n\t\treturn value;\n\t}\n\n\tif (value === null || typeof value !== \"object\") {\n\t\treturn value;\n\t}\n\n\tif (Array.isArray(value)) {\n\t\tconst result: unknown[] = [];\n\t\tfor (const item of value) {\n\t\t\tresult.push(redactTelemetryValue(item, depth + 1));\n\t\t}\n\t\treturn result;\n\t}\n\n\t// It is an object\n\tconst obj = value as Record<string, unknown>;\n\tconst result: Record<string, unknown> = {};\n\n\tfor (const key of Object.keys(obj)) {\n\t\tconst lowercaseKey = key.toLowerCase();\n\t\tif (SECRET_KEYS.has(lowercaseKey)) {\n\t\t\tresult[key] = \"[REDACTED]\";\n\t\t} else {\n\t\t\tresult[key] = redactTelemetryValue(obj[key], depth + 1);\n\t\t}\n\t}\n\n\treturn result;\n}\n"]}
1
+ {"version":3,"file":"telemetry-events.d.ts","sourceRoot":"","sources":["../../../src/core/autonomy/telemetry-events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,eAAO,MAAM,8BAA8B;;;;;;;;CAQjC,CAAC;AAEX,MAAM,MAAM,0BAA0B,GACrC,CAAC,OAAO,8BAA8B,CAAC,CAAC,MAAM,OAAO,8BAA8B,CAAC,CAAC;AAEtF,MAAM,WAAW,sBAAsB;IACtC,IAAI,EAAE,0BAA0B,CAAC;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,SAAS,CAAC;CACnB;AAiBD,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,SAAI,GAAG,OAAO,CAyCvE","sourcesContent":["import type { JsonValue } from \"./contracts.ts\";\n\nexport const AUTONOMY_TELEMETRY_EVENT_TYPES = {\n\trouteDecision: \"autonomy.route_decision\",\n\tgateOutcome: \"autonomy.gate_outcome\",\n\tapprovalRequest: \"autonomy.approval_request\",\n\tevidenceBundle: \"autonomy.evidence_bundle\",\n\tworkerRequest: \"autonomy.worker_request\",\n\tworkerTerminal: \"autonomy.worker_terminal\",\n\tlearningDecision: \"autonomy.learning_decision\",\n} as const;\n\nexport type AutonomyTelemetryEventType =\n\t(typeof AUTONOMY_TELEMETRY_EVENT_TYPES)[keyof typeof AUTONOMY_TELEMETRY_EVENT_TYPES];\n\nexport interface AutonomyTelemetryEvent {\n\ttype: AutonomyTelemetryEventType;\n\ttimestamp: string;\n\tpayload: JsonValue;\n}\n\nconst SECRET_KEYS = new Set([\n\t\"apikey\",\n\t\"api_key\",\n\t\"token\",\n\t\"accesstoken\",\n\t\"refreshtoken\",\n\t\"secret\",\n\t\"password\",\n\t\"authorization\",\n\t\"credential\",\n\t\"credentials\",\n]);\n\nconst BEARER_RE = /bearer\\s+\\S+/i;\n\nexport function redactTelemetryValue(value: unknown, depth = 0): unknown {\n\tif (depth > 20) {\n\t\treturn \"[Depth Limit Exceeded]\";\n\t}\n\n\tif (typeof value === \"string\") {\n\t\tif (BEARER_RE.test(value)) {\n\t\t\treturn \"[REDACTED BEARER TOKEN]\";\n\t\t}\n\t\tif (value.startsWith(\"sk-\")) {\n\t\t\treturn \"[REDACTED API KEY]\";\n\t\t}\n\t\treturn value;\n\t}\n\n\tif (value === null || typeof value !== \"object\") {\n\t\treturn value;\n\t}\n\n\tif (Array.isArray(value)) {\n\t\tconst result: unknown[] = [];\n\t\tfor (const item of value) {\n\t\t\tresult.push(redactTelemetryValue(item, depth + 1));\n\t\t}\n\t\treturn result;\n\t}\n\n\t// It is an object\n\tconst obj = value as Record<string, unknown>;\n\tconst result: Record<string, unknown> = {};\n\n\tfor (const key of Object.keys(obj)) {\n\t\tconst lowercaseKey = key.toLowerCase();\n\t\tif (SECRET_KEYS.has(lowercaseKey)) {\n\t\t\tresult[key] = \"[REDACTED]\";\n\t\t} else {\n\t\t\tresult[key] = redactTelemetryValue(obj[key], depth + 1);\n\t\t}\n\t}\n\n\treturn result;\n}\n"]}
@@ -4,7 +4,7 @@ export const AUTONOMY_TELEMETRY_EVENT_TYPES = {
4
4
  approvalRequest: "autonomy.approval_request",
5
5
  evidenceBundle: "autonomy.evidence_bundle",
6
6
  workerRequest: "autonomy.worker_request",
7
- workerResult: "autonomy.worker_result",
7
+ workerTerminal: "autonomy.worker_terminal",
8
8
  learningDecision: "autonomy.learning_decision",
9
9
  };
10
10
  const SECRET_KEYS = new Set([
@@ -1 +1 @@
1
- {"version":3,"file":"telemetry-events.js","sourceRoot":"","sources":["../../../src/core/autonomy/telemetry-events.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,8BAA8B,GAAG;IAC7C,aAAa,EAAE,yBAAyB;IACxC,WAAW,EAAE,uBAAuB;IACpC,eAAe,EAAE,2BAA2B;IAC5C,cAAc,EAAE,0BAA0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,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QACpC,MAAM,YAAY,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC;QACvC,IAAI,WAAW,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,CAAC;YACnC,MAAM,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC;QAC5B,CAAC;aAAM,CAAC;YACP,MAAM,CAAC,GAAG,CAAC,GAAG,oBAAoB,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;QACzD,CAAC;IACF,CAAC;IAED,OAAO,MAAM,CAAC;AAAA,CACd","sourcesContent":["import type { JsonValue } from \"./contracts.ts\";\n\nexport const AUTONOMY_TELEMETRY_EVENT_TYPES = {\n\trouteDecision: \"autonomy.route_decision\",\n\tgateOutcome: \"autonomy.gate_outcome\",\n\tapprovalRequest: \"autonomy.approval_request\",\n\tevidenceBundle: \"autonomy.evidence_bundle\",\n\tworkerRequest: \"autonomy.worker_request\",\n\tworkerResult: \"autonomy.worker_result\",\n\tlearningDecision: \"autonomy.learning_decision\",\n} as const;\n\nexport type AutonomyTelemetryEventType =\n\t(typeof AUTONOMY_TELEMETRY_EVENT_TYPES)[keyof typeof AUTONOMY_TELEMETRY_EVENT_TYPES];\n\nexport interface AutonomyTelemetryEvent {\n\ttype: AutonomyTelemetryEventType;\n\ttimestamp: string;\n\tpayload: JsonValue;\n}\n\nconst SECRET_KEYS = new Set([\n\t\"apikey\",\n\t\"api_key\",\n\t\"token\",\n\t\"accesstoken\",\n\t\"refreshtoken\",\n\t\"secret\",\n\t\"password\",\n\t\"authorization\",\n\t\"credential\",\n\t\"credentials\",\n]);\n\nconst BEARER_RE = /bearer\\s+\\S+/i;\n\nexport function redactTelemetryValue(value: unknown, depth = 0): unknown {\n\tif (depth > 20) {\n\t\treturn \"[Depth Limit Exceeded]\";\n\t}\n\n\tif (typeof value === \"string\") {\n\t\tif (BEARER_RE.test(value)) {\n\t\t\treturn \"[REDACTED BEARER TOKEN]\";\n\t\t}\n\t\tif (value.startsWith(\"sk-\")) {\n\t\t\treturn \"[REDACTED API KEY]\";\n\t\t}\n\t\treturn value;\n\t}\n\n\tif (value === null || typeof value !== \"object\") {\n\t\treturn value;\n\t}\n\n\tif (Array.isArray(value)) {\n\t\tconst result: unknown[] = [];\n\t\tfor (const item of value) {\n\t\t\tresult.push(redactTelemetryValue(item, depth + 1));\n\t\t}\n\t\treturn result;\n\t}\n\n\t// It is an object\n\tconst obj = value as Record<string, unknown>;\n\tconst result: Record<string, unknown> = {};\n\n\tfor (const key of Object.keys(obj)) {\n\t\tconst lowercaseKey = key.toLowerCase();\n\t\tif (SECRET_KEYS.has(lowercaseKey)) {\n\t\t\tresult[key] = \"[REDACTED]\";\n\t\t} else {\n\t\t\tresult[key] = redactTelemetryValue(obj[key], depth + 1);\n\t\t}\n\t}\n\n\treturn result;\n}\n"]}
1
+ {"version":3,"file":"telemetry-events.js","sourceRoot":"","sources":["../../../src/core/autonomy/telemetry-events.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,8BAA8B,GAAG;IAC7C,aAAa,EAAE,yBAAyB;IACxC,WAAW,EAAE,uBAAuB;IACpC,eAAe,EAAE,2BAA2B;IAC5C,cAAc,EAAE,0BAA0B;IAC1C,aAAa,EAAE,yBAAyB;IACxC,cAAc,EAAE,0BAA0B;IAC1C,gBAAgB,EAAE,4BAA4B;CACrC,CAAC;AAWX,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC;IAC3B,QAAQ;IACR,SAAS;IACT,OAAO;IACP,aAAa;IACb,cAAc;IACd,QAAQ;IACR,UAAU;IACV,eAAe;IACf,YAAY;IACZ,aAAa;CACb,CAAC,CAAC;AAEH,MAAM,SAAS,GAAG,eAAe,CAAC;AAElC,MAAM,UAAU,oBAAoB,CAAC,KAAc,EAAE,KAAK,GAAG,CAAC,EAAW;IACxE,IAAI,KAAK,GAAG,EAAE,EAAE,C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AA,CACd","sourcesContent":["import type { JsonValue } from \"./contracts.ts\";\n\nexport const AUTONOMY_TELEMETRY_EVENT_TYPES = {\n\trouteDecision: \"autonomy.route_decision\",\n\tgateOutcome: \"autonomy.gate_outcome\",\n\tapprovalRequest: \"autonomy.approval_request\",\n\tevidenceBundle: \"autonomy.evidence_bundle\",\n\tworkerRequest: \"autonomy.worker_request\",\n\tworkerTerminal: \"autonomy.worker_terminal\",\n\tlearningDecision: \"autonomy.learning_decision\",\n} as const;\n\nexport type AutonomyTelemetryEventType =\n\t(typeof AUTONOMY_TELEMETRY_EVENT_TYPES)[keyof typeof AUTONOMY_TELEMETRY_EVENT_TYPES];\n\nexport interface AutonomyTelemetryEvent {\n\ttype: AutonomyTelemetryEventType;\n\ttimestamp: string;\n\tpayload: JsonValue;\n}\n\nconst SECRET_KEYS = new Set([\n\t\"apikey\",\n\t\"api_key\",\n\t\"token\",\n\t\"accesstoken\",\n\t\"refreshtoken\",\n\t\"secret\",\n\t\"password\",\n\t\"authorization\",\n\t\"credential\",\n\t\"credentials\",\n]);\n\nconst BEARER_RE = /bearer\\s+\\S+/i;\n\nexport function redactTelemetryValue(value: unknown, depth = 0): unknown {\n\tif (depth > 20) {\n\t\treturn \"[Depth Limit Exceeded]\";\n\t}\n\n\tif (typeof value === \"string\") {\n\t\tif (BEARER_RE.test(value)) {\n\t\t\treturn \"[REDACTED BEARER TOKEN]\";\n\t\t}\n\t\tif (value.startsWith(\"sk-\")) {\n\t\t\treturn \"[REDACTED API KEY]\";\n\t\t}\n\t\treturn value;\n\t}\n\n\tif (value === null || typeof value !== \"object\") {\n\t\treturn value;\n\t}\n\n\tif (Array.isArray(value)) {\n\t\tconst result: unknown[] = [];\n\t\tfor (const item of value) {\n\t\t\tresult.push(redactTelemetryValue(item, depth + 1));\n\t\t}\n\t\treturn result;\n\t}\n\n\t// It is an object\n\tconst obj = value as Record<string, unknown>;\n\tconst result: Record<string, unknown> = {};\n\n\tfor (const key of Object.keys(obj)) {\n\t\tconst lowercaseKey = key.toLowerCase();\n\t\tif (SECRET_KEYS.has(lowercaseKey)) {\n\t\t\tresult[key] = \"[REDACTED]\";\n\t\t} else {\n\t\t\tresult[key] = redactTelemetryValue(obj[key], depth + 1);\n\t\t}\n\t}\n\n\treturn result;\n}\n"]}
@@ -8,7 +8,7 @@
8
8
  * rather than the whole AgentSession — they never mutate anything but the owned gate-outcome fields.
9
9
  */
10
10
  import type { SessionManager } from "@caupulican/pi-agent-core/node";
11
- import type { EvidenceBundle, GateOutcome, LearningDecision, WorkerResult } from "./autonomy/contracts.ts";
11
+ import type { EvidenceBundle, GateOutcome, LearningDecision, WorkerClaim } from "./autonomy/contracts.ts";
12
12
  import type { AutonomyDiagnosticSnapshot, AutonomyStatusSnapshot, GateOutcomeHistoryEntry } from "./autonomy/status.ts";
13
13
  import { type AutonomyTelemetryEvent } from "./autonomy/telemetry-events.ts";
14
14
  import { type SessionCostSummary } from "./cost/cost-summary.ts";
@@ -28,12 +28,12 @@ export interface AutonomyTelemetryDeps {
28
28
  getGoalStateSnapshot(): GoalState | undefined;
29
29
  /** Live count of active lanes from the lane tracker — never inferred from historical snapshots. */
30
30
  getActiveLaneCount(): number;
31
- /** Research evidence bundles recorded this session. */
32
- getEvidenceBundleSnapshots(): EvidenceBundle[];
33
- /** Worker-delegation result snapshots recorded this session. */
34
- getWorkerResultSnapshots(): WorkerResult[];
35
- /** Learning decision snapshots recorded this session. */
36
- getLearningDecisionSnapshots(): LearningDecision[];
31
+ /** Research evidence bundles across the complete session tree, including sibling branches. */
32
+ getSessionEvidenceBundleHistory(): EvidenceBundle[];
33
+ /** Worker-delegation claims across the complete session tree, including sibling branches. */
34
+ getSessionWorkerClaimHistory(): WorkerClaim[];
35
+ /** Learning decisions across the complete session tree, including sibling branches. */
36
+ getSessionLearningDecisionHistory(): LearningDecision[];
37
37
  /** Learning audit records recorded this session. */
38
38
  getLearningAuditRecords(): LearningAuditRecord[];
39
39
  }
@@ -1 +1 @@
1
- {"version":3,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mBAAmB,EAAE,CAAC;CACjD;AAED,qBAAa,iBAAiB;IAC7B,OAAO,CAAC,wBAAwB,CAAC,CAAc;IAC/C,qGAAqG;IACrG,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAiC;IAErE,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAwB;IAE7C,YAAY,IAAI,EAAE,qBAAqB,EAEtC;IAED;;;;;;OAMG;IACH,aAAa,CAAC,KAAK,EAAE,sBAAsB,GAAG,IAAI,CAOjD;IAED;;;;;;OAMG;IACH,iBAAiB,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,CAsB5C;IAED,iFAAiF;IACjF,qBAAqB,IAAI,uBAAuB,EAAE,CAEjD;IAED,iBAAiB,IAAI,sBAAsB,CA2C1C;IAED;;;;;OAKG;IACH,qBAAqB,CAAC,OAAO,CAAC,EAAE;QAAE,mBAAmB,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,0BAA0B,CA0J5F;CACD","sourcesContent":["/**\n * Autonomy telemetry sink + status/diagnostic snapshots.\n *\n * Extracted verbatim from agent-session.ts (god-file decomposition). Owns the latest gate outcome\n * and the bounded gate-outcome history, and is the single sink for G3 autonomy-telemetry custom\n * entries. The two snapshot builders READ broadly across live session state (router decision, cost,\n * goal, lanes, and the research/delegation/learning/goal getters) through narrow deps accessors\n * rather than the whole AgentSession — they never mutate anything but the owned gate-outcome fields.\n */\n\nimport type { SessionManager } from \"@caupulican/pi-agent-core/node\";\nimport { getProcessMemoryMb } from \"../utils/process-memory.ts\";\nimport type { EvidenceBundle, GateOutcome, LearningDecision, WorkerResult } from \"./autonomy/contracts.ts\";\nimport { getLaneRecordSnapshots } from \"./autonomy/session-lane-record.ts\";\nimport type {\n\tAutonomyDiagnosticSnapshot,\n\tAutonomyStatusSnapshot,\n\tDiagnosticEntry,\n\tGateOutcomeHistoryEntry,\n} from \"./autonomy/status.ts\";\nimport {\n\tAUTONOMY_TELEMETRY_EVENT_TYPES,\n\ttype AutonomyTelemetryEvent,\n\tredactTelemetryValue,\n} from \"./autonomy/telemetry-events.ts\";\nimport { hasCostSummarySignal, hasSubagentCostSignal, type SessionCostSummary } from \"./cost/cost-summary.ts\";\nimport type { GoalState } from \"./goals/goal-state.ts\";\nimport type { LearningAuditRecord } from \"./learning/learning-audit.ts\";\nimport { getRecentModelRouterDecisions, type ModelRouterDecisionStatus } from \"./model-router/status.ts\";\n\n/** Custom-entry type for G3 autonomy telemetry. Distinct from the router/lane record types so a\n * telemetry consumer can filter on it without decoding operational snapshots. */\nconst AUTONOMY_TELEMETRY_CUSTOM_TYPE = \"autonomy-telemetry\";\n\n/** G8: bound on the in-memory gate-outcome history. Oldest entries evict once the cap is reached. */\nconst GATE_OUTCOME_HISTORY_LIMIT = 50;\n\nexport interface AutonomyTelemetryDeps {\n\t/** Session log: `appendCustomEntry` is the telemetry sink; `getEntries` feeds diagnostic aggregation. */\n\tgetSessionManager(): Pick<SessionManager, \"appendCustomEntry\" | \"getEntries\">;\n\t/** Latest model-router decision, for the snapshot's `latestRoute` — owned by the router, not this sink. */\n\tgetLastModelRouterDecision(): ModelRouterDecisionStatus | undefined;\n\t/** Reason the last research lane was skipped, if any — surfaced in the diagnostic's research family. */\n\tgetLastResearchLaneSkipReason(): string | undefined;\n\t/** Single source of truth for CURRENT/TODAY/SUBAGENTS display costs. */\n\tgetCostSummary(): SessionCostSummary;\n\t/** Current goal state, if a goal is active. */\n\tgetGoalStateSnapshot(): GoalState | undefined;\n\t/** Live count of active lanes from the lane tracker — never inferred from historical snapshots. */\n\tgetActiveLaneCount(): number;\n\t/** Research evidence bundles recorded this session. */\n\tgetEvidenceBundleSnapshots(): EvidenceBundle[];\n\t/** Worker-delegation result snapshots recorded this session. */\n\tgetWorkerResultSnapshots(): WorkerResult[];\n\t/** Learning decision snapshots recorded this session. */\n\tgetLearningDecisionSnapshots(): LearningDecision[];\n\t/** Learning audit records recorded this session. */\n\tgetLearningAuditRecords(): LearningAuditRecord[];\n}\n\nexport class AutonomyTelemetry {\n\tprivate _lastAutonomyGateOutcome?: GateOutcome;\n\t/** G8: bounded (cap {@link GATE_OUTCOME_HISTORY_LIMIT}) history of gate outcomes; tail is latest. */\n\tprivate readonly _gateOutcomeHistory: GateOutcomeHistoryEntry[] = [];\n\n\tprivate readonly deps: AutonomyTelemetryDeps;\n\n\tconstructor(deps: AutonomyTelemetryDeps) {\n\t\tthis.deps = deps;\n\t}\n\n\t/**\n\t * G3: bounded autonomy-telemetry sink. Passes the whole event through {@link redactTelemetryValue}\n\t * (the taxonomy's redaction contract) before storing it, so a secret that leaked into a payload\n\t * field never lands in the session log. Observe-only: a failure here can never surface into the\n\t * turn it is measuring, so the whole body is swallowed. Payloads MUST stay small (ids, codes,\n\t * numbers) — never prompt/summary text; callers own that discipline.\n\t */\n\temitTelemetry(event: AutonomyTelemetryEvent): void {\n\t\ttry {\n\t\t\tconst redacted = redactTelemetryValue(event) as Record<string, unknown>;\n\t\t\tthis.deps.getSessionManager().appendCustomEntry(AUTONOMY_TELEMETRY_CUSTOM_TYPE, { version: 1, ...redacted });\n\t\t} catch {\n\t\t\t// Telemetry is best-effort: swallow so a sink failure cannot break the observed turn.\n\t\t}\n\t}\n\n\t/**\n\t * G8: single sink for a gate outcome. Keeps the latest-outcome getter behavior identical (the\n\t * full {@link GateOutcome} still lands in `_lastAutonomyGateOutcome`), and additionally appends a\n\t * bounded codes-only entry to {@link _gateOutcomeHistory} (oldest evicted at\n\t * {@link GATE_OUTCOME_HISTORY_LIMIT}) and emits the `gate_outcome` telemetry event. The history\n\t * tail therefore always mirrors the latest outcome. Only called with an active envelope.\n\t */\n\trecordGateOutcome(outcome: GateOutcome): void {\n\t\tthis._lastAutonomyGateOutcome = outcome;\n\t\tconst at = new Date().toISOString();\n\t\tthis._gateOutcomeHistory.push({\n\t\t\toutcome: outcome.outcome,\n\t\t\tgate: outcome.gate,\n\t\t\treasonCode: outcome.reasonCode,\n\t\t\tat,\n\t\t});\n\t\twhile (this._gateOutcomeHistory.length > GATE_OUTCOME_HISTORY_LIMIT) {\n\t\t\tthis._gateOutcomeHistory.shift();\n\t\t}\n\t\t// G8: gate outcome event. Codes/ids only — never the gate's human-facing message.\n\t\tthis.emitTelemetry({\n\t\t\ttype: AUTONOMY_TELEMETRY_EVENT_TYPES.gateOutcome,\n\t\t\ttimestamp: at,\n\t\t\tpayload: {\n\t\t\t\toutcome: outcome.outcome,\n\t\t\t\tgate: outcome.gate,\n\t\t\t\treasonCode: outcome.reasonCode,\n\t\t\t},\n\t\t});\n\t}\n\n\t/** G8: copies of the bounded gate-outcome history, oldest first, latest last. */\n\tgetGateOutcomeHistory(): GateOutcomeHistoryEntry[] {\n\t\treturn this._gateOutcomeHistory.map((entry) => ({ ...entry }));\n\t}\n\n\tgetStatusSnapshot(): AutonomyStatusSnapshot {\n\t\tconst snapshot: AutonomyStatusSnapshot = {};\n\n\t\tconst lastRouterDecision = this.deps.getLastModelRouterDecision();\n\t\tif (lastRouterDecision?.route) {\n\t\t\tsnapshot.latestRoute = {\n\t\t\t\ttier: lastRouterDecision.route.tier,\n\t\t\t\treasonCode: lastRouterDecision.route.reasonCode,\n\t\t\t\trisk: lastRouterDecision.route.risk,\n\t\t\t};\n\t\t}\n\n\t\tif (this._lastAutonomyGateOutcome) {\n\t\t\tsnapshot.latestGate = {\n\t\t\t\toutcome: this._lastAutonomyGateOutcome.outcome,\n\t\t\t\tgate: this._lastAutonomyGateOutcome.gate,\n\t\t\t\treasonCode: this._lastAutonomyGateOutcome.reasonCode,\n\t\t\t};\n\t\t}\n\n\t\tconst costSummary = this.deps.getCostSummary();\n\t\tif (hasCostSummarySignal(costSummary)) {\n\t\t\tsnapshot.costSummary = costSummary;\n\t\t}\n\n\t\tconst goal = this.deps.getGoalStateSnapshot();\n\t\tif (goal) {\n\t\t\tsnapshot.activeGoal = {\n\t\t\t\tgoalId: goal.goalId,\n\t\t\t\tstatus: goal.status,\n\t\t\t\topenRequirements: goal.requirements.filter((requirement) => requirement.status === \"open\").length,\n\t\t\t\tstallTurns: goal.stallTurns,\n\t\t\t};\n\t\t}\n\n\t\t// Real live count from the lane tracker — never inferred from historical snapshots. Absent\n\t\t// while zero, matching the presence-means-signal convention of the sibling fields.\n\t\tconst activeLaneCount = this.deps.getActiveLaneCount();\n\t\tif (activeLaneCount > 0) {\n\t\t\tsnapshot.activeLaneCount = activeLaneCount;\n\t\t}\n\n\t\treturn snapshot;\n\t}\n\n\t/**\n\t * Aggregate an effectiveness/autonomy dashboard: what Pi has actually been doing (recent\n\t * route choices, latest gate outcome, cost, and any research/delegation/learning/goal\n\t * activity). Read-only — combines existing session-log getters, never mutates state or\n\t * recomputes a route/gate decision.\n\t */\n\tgetDiagnosticSnapshot(options?: { maxEntriesPerFamily?: number }): AutonomyDiagnosticSnapshot {\n\t\tconst maxEntriesPerFamily = options?.maxEntriesPerFamily ?? 10;\n\t\tconst snapshot: AutonomyDiagnosticSnapshot = {};\n\t\tconst goal = this.deps.getGoalStateSnapshot();\n\n\t\tconst recentDecisions = getRecentModelRouterDecisions(\n\t\t\tthis.deps.getSessionManager().getEntries(),\n\t\t\tmaxEntriesPerFamily,\n\t\t);\n\t\tif (recentDecisions.length > 0) {\n\t\t\tsnapshot.routes = recentDecisions.map(\n\t\t\t\t(decision): DiagnosticEntry => ({\n\t\t\t\t\ttitle: decision.route.tier,\n\t\t\t\t\tsummary: decision.routedModel,\n\t\t\t\t\treasonCode: decision.route.reasonCode,\n\t\t\t\t\tmetadata: { risk: decision.route.risk, outcome: decision.outcome, intent: decision.intent },\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\tif (this._lastAutonomyGateOutcome) {\n\t\t\tconst gate = this._lastAutonomyGateOutcome;\n\t\t\tsnapshot.gates = [\n\t\t\t\t{\n\t\t\t\t\ttitle: gate.gate,\n\t\t\t\t\tsummary: gate.message,\n\t\t\t\t\treasonCode: gate.reasonCode,\n\t\t\t\t\tmetadata: { outcome: gate.outcome, reversible: gate.reversible },\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\n\t\tconst costs: DiagnosticEntry[] = [];\n\t\tconst costSummary = this.deps.getCostSummary();\n\t\tif (costSummary.currentCost > 0 || hasSubagentCostSignal(costSummary)) {\n\t\t\tcosts.push({ title: \"CURRENT\", summary: `$${costSummary.currentCost.toFixed(4)}` });\n\t\t}\n\t\tif (costSummary.todayCost > 0) {\n\t\t\tcosts.push({ title: \"TODAY\", summary: `$${costSummary.todayCost.toFixed(4)}` });\n\t\t}\n\t\tif (hasSubagentCostSignal(costSummary)) {\n\t\t\tcosts.push({\n\t\t\t\ttitle: \"SUBAGENTS\",\n\t\t\t\tsummary: `$${costSummary.subagentCost.toFixed(4)} included in CURRENT`,\n\t\t\t});\n\t\t}\n\t\tif (costs.length > 0) snapshot.costs = costs;\n\n\t\tconst researchEntries: DiagnosticEntry[] = [];\n\t\tconst researchLaneRecords = getLaneRecordSnapshots(this.deps.getSessionManager().getEntries()).filter(\n\t\t\t(record) => record.type === \"research\",\n\t\t);\n\t\tfor (const record of researchLaneRecords.slice(-maxEntriesPerFamily)) {\n\t\t\tresearchEntries.push({\n\t\t\t\ttitle: `Lane ${record.laneId} (${record.status})`,\n\t\t\t\treasonCode: record.reasonCode,\n\t\t\t\tmetadata: {\n\t\t\t\t\tcostUsd: record.costUsd,\n\t\t\t\t\tstartedAt: record.startedAt,\n\t\t\t\t\tcompletedAt: record.completedAt,\n\t\t\t\t\tgoalId: record.goalId,\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t\tfor (const bundle of this.deps.getEvidenceBundleSnapshots().slice(-maxEntriesPerFamily)) {\n\t\t\tresearchEntries.push({\n\t\t\t\ttitle: `Research: ${bundle.query}`,\n\t\t\t\tmetadata: { sourceCount: bundle.sources.length, findingCount: bundle.findings.length },\n\t\t\t});\n\t\t}\n\t\tif (this.deps.getLastResearchLaneSkipReason()) {\n\t\t\tresearchEntries.push({ title: \"Last skip\", reasonCode: this.deps.getLastResearchLaneSkipReason() });\n\t\t}\n\t\tif (researchEntries.length > 0) {\n\t\t\tsnapshot.research = researchEntries;\n\t\t}\n\n\t\tconst delegationEntries: DiagnosticEntry[] = [];\n\t\tconst workerLaneRecords = getLaneRecordSnapshots(this.deps.getSessionManager().getEntries()).filter(\n\t\t\t(record) => record.type === \"worker\",\n\t\t);\n\t\tfor (const record of workerLaneRecords.slice(-maxEntriesPerFamily)) {\n\t\t\tdelegationEntries.push({\n\t\t\t\ttitle: `Lane ${record.laneId} (${record.status})`,\n\t\t\t\treasonCode: record.reasonCode,\n\t\t\t\tmetadata: { costUsd: record.costUsd, startedAt: record.startedAt, completedAt: record.completedAt },\n\t\t\t});\n\t\t}\n\t\tconst workerResults = this.deps.getWorkerResultSnapshots();\n\t\tfor (const result of workerResults.slice(-maxEntriesPerFamily)) {\n\t\t\tdelegationEntries.push({\n\t\t\t\ttitle: `Worker ${result.requestId} (${result.status})`,\n\t\t\t\tsummary: result.summary,\n\t\t\t\tmetadata: {\n\t\t\t\t\tchangedFileCount: result.changedFiles.length,\n\t\t\t\t\tblockerCount: result.blockers?.length ?? 0,\n\t\t\t\t\tusageReportId: result.usageReportId,\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t\tif (delegationEntries.length > 0) {\n\t\t\tsnapshot.delegation = delegationEntries;\n\t\t}\n\n\t\tconst learningEntries: DiagnosticEntry[] = [];\n\t\tconst learningDecisions = this.deps.getLearningDecisionSnapshots();\n\t\tfor (const decision of learningDecisions.slice(-maxEntriesPerFamily)) {\n\t\t\tlearningEntries.push({\n\t\t\t\ttitle: `Learning (${decision.kind})`,\n\t\t\t\tsummary: decision.summary,\n\t\t\t\treasonCode: decision.reasonCode,\n\t\t\t\tmetadata: { confidence: decision.confidence, requiresApproval: decision.requiresApproval },\n\t\t\t});\n\t\t}\n\t\tfor (const audit of this.deps.getLearningAuditRecords().slice(-maxEntriesPerFamily)) {\n\t\t\tlearningEntries.push({\n\t\t\t\ttitle: `Audit ${audit.id} (${audit.action})`,\n\t\t\t\tsummary: audit.summary,\n\t\t\t\treasonCode: audit.reasonCode,\n\t\t\t\tmetadata: { layer: audit.layer, proposalId: audit.proposalId, rollbackOf: audit.rollbackOf },\n\t\t\t});\n\t\t}\n\t\tif (learningEntries.length > 0) {\n\t\t\tsnapshot.learning = learningEntries;\n\t\t}\n\n\t\tif (goal) {\n\t\t\tsnapshot.goals = [\n\t\t\t\t{\n\t\t\t\t\ttitle: `Goal ${goal.goalId}`,\n\t\t\t\t\tsummary: goal.userGoal,\n\t\t\t\t\treasonCode: goal.status,\n\t\t\t\t\tmetadata: {\n\t\t\t\t\t\topenRequirementCount: goal.requirements.filter((requirement) => requirement.status === \"open\").length,\n\t\t\t\t\t\tstallTurns: goal.stallTurns,\n\t\t\t\t\t\tblockedReason: goal.blockedReason,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\n\t\tconst processMemory = getProcessMemoryMb();\n\t\tsnapshot.processMemory = [\n\t\t\t{\n\t\t\t\ttitle: \"process\",\n\t\t\t\tmetadata: {\n\t\t\t\t\trssMb: processMemory.rssMb,\n\t\t\t\t\theapUsedMb: processMemory.heapUsedMb,\n\t\t\t\t\texternalMb: processMemory.externalMb,\n\t\t\t\t},\n\t\t\t},\n\t\t];\n\n\t\treturn snapshot;\n\t}\n}\n"]}
1
+ {"version":3,"file":"autonomy-telemetry.d.ts","sourceRoot":"","sources":["../../src/core/autonomy-telemetry.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAErE,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAE1G,OAAO,KAAK,EACX,0BAA0B,EAC1B,sBAAsB,EAEtB,uBAAuB,EACvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAEN,KAAK,sBAAsB,EAE3B,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAA+C,KAAK,kBAAkB,EAAE,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IAED,iBAAiB,IAAI,sBAAsB,CA2C1C;IAED;;;;;OAKG;IACH,qBAAqB,CAAC,OAAO,CAAC,EAAE;QAAE,mBAAmB,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,0BAA0B,CA0J5F;CACD","sourcesContent":["/**\n * Autonomy telemetry sink + status/diagnostic snapshots.\n *\n * Extracted verbatim from agent-session.ts (god-file decomposition). Owns the latest gate outcome\n * and the bounded gate-outcome history, and is the single sink for G3 autonomy-telemetry custom\n * entries. The two snapshot builders READ broadly across live session state (router decision, cost,\n * goal, lanes, and the research/delegation/learning/goal getters) through narrow deps accessors\n * rather than the whole AgentSession — they never mutate anything but the owned gate-outcome fields.\n */\n\nimport type { SessionManager } from \"@caupulican/pi-agent-core/node\";\nimport { getProcessMemoryMb } from \"../utils/process-memory.ts\";\nimport type { EvidenceBundle, GateOutcome, LearningDecision, WorkerClaim } from \"./autonomy/contracts.ts\";\nimport { getLaneRecordSnapshots } from \"./autonomy/session-lane-record.ts\";\nimport type {\n\tAutonomyDiagnosticSnapshot,\n\tAutonomyStatusSnapshot,\n\tDiagnosticEntry,\n\tGateOutcomeHistoryEntry,\n} from \"./autonomy/status.ts\";\nimport {\n\tAUTONOMY_TELEMETRY_EVENT_TYPES,\n\ttype AutonomyTelemetryEvent,\n\tredactTelemetryValue,\n} from \"./autonomy/telemetry-events.ts\";\nimport { hasCostSummarySignal, hasSubagentCostSignal, type SessionCostSummary } from \"./cost/cost-summary.ts\";\nimport type { GoalState } from \"./goals/goal-state.ts\";\nimport type { LearningAuditRecord } from \"./learning/learning-audit.ts\";\nimport { getRecentModelRouterDecisions, type ModelRouterDecisionStatus } from \"./model-router/status.ts\";\n\n/** Custom-entry type for G3 autonomy telemetry. Distinct from the router/lane record types so a\n * telemetry consumer can filter on it without decoding operational snapshots. */\nconst AUTONOMY_TELEMETRY_CUSTOM_TYPE = \"autonomy-telemetry\";\n\n/** G8: bound on the in-memory gate-outcome history. Oldest entries evict once the cap is reached. */\nconst GATE_OUTCOME_HISTORY_LIMIT = 50;\n\nexport interface AutonomyTelemetryDeps {\n\t/** Session log: `appendCustomEntry` is the telemetry sink; `getEntries` feeds diagnostic aggregation. */\n\tgetSessionManager(): Pick<SessionManager, \"appendCustomEntry\" | \"getEntries\">;\n\t/** Latest model-router decision, for the snapshot's `latestRoute` — owned by the router, not this sink. */\n\tgetLastModelRouterDecision(): ModelRouterDecisionStatus | undefined;\n\t/** Reason the last research lane was skipped, if any — surfaced in the diagnostic's research family. */\n\tgetLastResearchLaneSkipReason(): string | undefined;\n\t/** Single source of truth for CURRENT/TODAY/SUBAGENTS display costs. */\n\tgetCostSummary(): SessionCostSummary;\n\t/** Current goal state, if a goal is active. */\n\tgetGoalStateSnapshot(): GoalState | undefined;\n\t/** Live count of active lanes from the lane tracker — never inferred from historical snapshots. */\n\tgetActiveLaneCount(): number;\n\t/** Research evidence bundles across the complete session tree, including sibling branches. */\n\tgetSessionEvidenceBundleHistory(): EvidenceBundle[];\n\t/** Worker-delegation claims across the complete session tree, including sibling branches. */\n\tgetSessionWorkerClaimHistory(): WorkerClaim[];\n\t/** Learning decisions across the complete session tree, including sibling branches. */\n\tgetSessionLearningDecisionHistory(): LearningDecision[];\n\t/** Learning audit records recorded this session. */\n\tgetLearningAuditRecords(): LearningAuditRecord[];\n}\n\nexport class AutonomyTelemetry {\n\tprivate _lastAutonomyGateOutcome?: GateOutcome;\n\t/** G8: bounded (cap {@link GATE_OUTCOME_HISTORY_LIMIT}) history of gate outcomes; tail is latest. */\n\tprivate readonly _gateOutcomeHistory: GateOutcomeHistoryEntry[] = [];\n\n\tprivate readonly deps: AutonomyTelemetryDeps;\n\n\tconstructor(deps: AutonomyTelemetryDeps) {\n\t\tthis.deps = deps;\n\t}\n\n\t/**\n\t * G3: bounded autonomy-telemetry sink. Passes the whole event through {@link redactTelemetryValue}\n\t * (the taxonomy's redaction contract) before storing it, so a secret that leaked into a payload\n\t * field never lands in the session log. Observe-only: a failure here can never surface into the\n\t * turn it is measuring, so the whole body is swallowed. Payloads MUST stay small (ids, codes,\n\t * numbers) — never prompt/summary text; callers own that discipline.\n\t */\n\temitTelemetry(event: AutonomyTelemetryEvent): void {\n\t\ttry {\n\t\t\tconst redacted = redactTelemetryValue(event) as Record<string, unknown>;\n\t\t\tthis.deps.getSessionManager().appendCustomEntry(AUTONOMY_TELEMETRY_CUSTOM_TYPE, { version: 1, ...redacted });\n\t\t} catch {\n\t\t\t// Telemetry is best-effort: swallow so a sink failure cannot break the observed turn.\n\t\t}\n\t}\n\n\t/**\n\t * G8: single sink for a gate outcome. Keeps the latest-outcome getter behavior identical (the\n\t * full {@link GateOutcome} still lands in `_lastAutonomyGateOutcome`), and additionally appends a\n\t * bounded codes-only entry to {@link _gateOutcomeHistory} (oldest evicted at\n\t * {@link GATE_OUTCOME_HISTORY_LIMIT}) and emits the `gate_outcome` telemetry event. The history\n\t * tail therefore always mirrors the latest outcome. Only called with an active envelope.\n\t */\n\trecordGateOutcome(outcome: GateOutcome): void {\n\t\tthis._lastAutonomyGateOutcome = outcome;\n\t\tconst at = new Date().toISOString();\n\t\tthis._gateOutcomeHistory.push({\n\t\t\toutcome: outcome.outcome,\n\t\t\tgate: outcome.gate,\n\t\t\treasonCode: outcome.reasonCode,\n\t\t\tat,\n\t\t});\n\t\twhile (this._gateOutcomeHistory.length > GATE_OUTCOME_HISTORY_LIMIT) {\n\t\t\tthis._gateOutcomeHistory.shift();\n\t\t}\n\t\t// G8: gate outcome event. Codes/ids only — never the gate's human-facing message.\n\t\tthis.emitTelemetry({\n\t\t\ttype: AUTONOMY_TELEMETRY_EVENT_TYPES.gateOutcome,\n\t\t\ttimestamp: at,\n\t\t\tpayload: {\n\t\t\t\toutcome: outcome.outcome,\n\t\t\t\tgate: outcome.gate,\n\t\t\t\treasonCode: outcome.reasonCode,\n\t\t\t},\n\t\t});\n\t}\n\n\t/** G8: copies of the bounded gate-outcome history, oldest first, latest last. */\n\tgetGateOutcomeHistory(): GateOutcomeHistoryEntry[] {\n\t\treturn this._gateOutcomeHistory.map((entry) => ({ ...entry }));\n\t}\n\n\tgetStatusSnapshot(): AutonomyStatusSnapshot {\n\t\tconst snapshot: AutonomyStatusSnapshot = {};\n\n\t\tconst lastRouterDecision = this.deps.getLastModelRouterDecision();\n\t\tif (lastRouterDecision?.route) {\n\t\t\tsnapshot.latestRoute = {\n\t\t\t\ttier: lastRouterDecision.route.tier,\n\t\t\t\treasonCode: lastRouterDecision.route.reasonCode,\n\t\t\t\trisk: lastRouterDecision.route.risk,\n\t\t\t};\n\t\t}\n\n\t\tif (this._lastAutonomyGateOutcome) {\n\t\t\tsnapshot.latestGate = {\n\t\t\t\toutcome: this._lastAutonomyGateOutcome.outcome,\n\t\t\t\tgate: this._lastAutonomyGateOutcome.gate,\n\t\t\t\treasonCode: this._lastAutonomyGateOutcome.reasonCode,\n\t\t\t};\n\t\t}\n\n\t\tconst costSummary = this.deps.getCostSummary();\n\t\tif (hasCostSummarySignal(costSummary)) {\n\t\t\tsnapshot.costSummary = costSummary;\n\t\t}\n\n\t\tconst goal = this.deps.getGoalStateSnapshot();\n\t\tif (goal) {\n\t\t\tsnapshot.activeGoal = {\n\t\t\t\tgoalId: goal.goalId,\n\t\t\t\tstatus: goal.status,\n\t\t\t\topenRequirements: goal.requirements.filter((requirement) => requirement.status === \"open\").length,\n\t\t\t\tstallTurns: goal.stallTurns,\n\t\t\t};\n\t\t}\n\n\t\t// Real live count from the lane tracker — never inferred from historical snapshots. Absent\n\t\t// while zero, matching the presence-means-signal convention of the sibling fields.\n\t\tconst activeLaneCount = this.deps.getActiveLaneCount();\n\t\tif (activeLaneCount > 0) {\n\t\t\tsnapshot.activeLaneCount = activeLaneCount;\n\t\t}\n\n\t\treturn snapshot;\n\t}\n\n\t/**\n\t * Aggregate an effectiveness/autonomy dashboard: what Pi has actually been doing (recent\n\t * route choices, latest gate outcome, cost, and any research/delegation/learning/goal\n\t * activity). Read-only — combines existing session-log getters, never mutates state or\n\t * recomputes a route/gate decision.\n\t */\n\tgetDiagnosticSnapshot(options?: { maxEntriesPerFamily?: number }): AutonomyDiagnosticSnapshot {\n\t\tconst maxEntriesPerFamily = options?.maxEntriesPerFamily ?? 10;\n\t\tconst snapshot: AutonomyDiagnosticSnapshot = {};\n\t\tconst goal = this.deps.getGoalStateSnapshot();\n\n\t\tconst recentDecisions = getRecentModelRouterDecisions(\n\t\t\tthis.deps.getSessionManager().getEntries(),\n\t\t\tmaxEntriesPerFamily,\n\t\t);\n\t\tif (recentDecisions.length > 0) {\n\t\t\tsnapshot.routes = recentDecisions.map(\n\t\t\t\t(decision): DiagnosticEntry => ({\n\t\t\t\t\ttitle: decision.route.tier,\n\t\t\t\t\tsummary: decision.routedModel,\n\t\t\t\t\treasonCode: decision.route.reasonCode,\n\t\t\t\t\tmetadata: { risk: decision.route.risk, outcome: decision.outcome, intent: decision.intent },\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\tif (this._lastAutonomyGateOutcome) {\n\t\t\tconst gate = this._lastAutonomyGateOutcome;\n\t\t\tsnapshot.gates = [\n\t\t\t\t{\n\t\t\t\t\ttitle: gate.gate,\n\t\t\t\t\tsummary: gate.message,\n\t\t\t\t\treasonCode: gate.reasonCode,\n\t\t\t\t\tmetadata: { outcome: gate.outcome, reversible: gate.reversible },\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\n\t\tconst costs: DiagnosticEntry[] = [];\n\t\tconst costSummary = this.deps.getCostSummary();\n\t\tif (costSummary.currentCost > 0 || hasSubagentCostSignal(costSummary)) {\n\t\t\tcosts.push({ title: \"CURRENT\", summary: `$${costSummary.currentCost.toFixed(4)}` });\n\t\t}\n\t\tif (costSummary.todayCost > 0) {\n\t\t\tcosts.push({ title: \"TODAY\", summary: `$${costSummary.todayCost.toFixed(4)}` });\n\t\t}\n\t\tif (hasSubagentCostSignal(costSummary)) {\n\t\t\tcosts.push({\n\t\t\t\ttitle: \"SUBAGENTS\",\n\t\t\t\tsummary: `$${costSummary.subagentCost.toFixed(4)} included in CURRENT`,\n\t\t\t});\n\t\t}\n\t\tif (costs.length > 0) snapshot.costs = costs;\n\n\t\tconst researchEntries: DiagnosticEntry[] = [];\n\t\tconst researchLaneRecords = getLaneRecordSnapshots(this.deps.getSessionManager().getEntries()).filter(\n\t\t\t(record) => record.type === \"research\",\n\t\t);\n\t\tfor (const record of researchLaneRecords.slice(-maxEntriesPerFamily)) {\n\t\t\tresearchEntries.push({\n\t\t\t\ttitle: `Lane ${record.laneId} (${record.status})`,\n\t\t\t\treasonCode: record.reasonCode,\n\t\t\t\tmetadata: {\n\t\t\t\t\tcostUsd: record.costUsd,\n\t\t\t\t\tstartedAt: record.startedAt,\n\t\t\t\t\tcompletedAt: record.completedAt,\n\t\t\t\t\tgoalId: record.goalId,\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t\tfor (const bundle of this.deps.getSessionEvidenceBundleHistory().slice(-maxEntriesPerFamily)) {\n\t\t\tresearchEntries.push({\n\t\t\t\ttitle: `Research: ${bundle.query}`,\n\t\t\t\tmetadata: { sourceCount: bundle.sources.length, findingCount: bundle.findings.length },\n\t\t\t});\n\t\t}\n\t\tif (this.deps.getLastResearchLaneSkipReason()) {\n\t\t\tresearchEntries.push({ title: \"Last skip\", reasonCode: this.deps.getLastResearchLaneSkipReason() });\n\t\t}\n\t\tif (researchEntries.length > 0) {\n\t\t\tsnapshot.research = researchEntries;\n\t\t}\n\n\t\tconst delegationEntries: DiagnosticEntry[] = [];\n\t\tconst workerLaneRecords = getLaneRecordSnapshots(this.deps.getSessionManager().getEntries()).filter(\n\t\t\t(record) => record.type === \"worker\",\n\t\t);\n\t\tfor (const record of workerLaneRecords.slice(-maxEntriesPerFamily)) {\n\t\t\tdelegationEntries.push({\n\t\t\t\ttitle: `Lane ${record.laneId} (${record.status})`,\n\t\t\t\treasonCode: record.reasonCode,\n\t\t\t\tmetadata: { costUsd: record.costUsd, startedAt: record.startedAt, completedAt: record.completedAt },\n\t\t\t});\n\t\t}\n\t\tconst workerClaims = this.deps.getSessionWorkerClaimHistory();\n\t\tfor (const claim of workerClaims.slice(-maxEntriesPerFamily)) {\n\t\t\tdelegationEntries.push({\n\t\t\t\ttitle: `Worker ${claim.requestId} (${claim.status})`,\n\t\t\t\tsummary: claim.summary,\n\t\t\t\tmetadata: {\n\t\t\t\t\tchangedFileCount: claim.changedFiles.length,\n\t\t\t\t\tblockerCount: claim.blockers?.length ?? 0,\n\t\t\t\t\tusageReportId: claim.usageReportId,\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t\tif (delegationEntries.length > 0) {\n\t\t\tsnapshot.delegation = delegationEntries;\n\t\t}\n\n\t\tconst learningEntries: DiagnosticEntry[] = [];\n\t\tconst learningDecisions = this.deps.getSessionLearningDecisionHistory();\n\t\tfor (const decision of learningDecisions.slice(-maxEntriesPerFamily)) {\n\t\t\tlearningEntries.push({\n\t\t\t\ttitle: `Learning (${decision.kind})`,\n\t\t\t\tsummary: decision.summary,\n\t\t\t\treasonCode: decision.reasonCode,\n\t\t\t\tmetadata: { confidence: decision.confidence, requiresApproval: decision.requiresApproval },\n\t\t\t});\n\t\t}\n\t\tfor (const audit of this.deps.getLearningAuditRecords().slice(-maxEntriesPerFamily)) {\n\t\t\tlearningEntries.push({\n\t\t\t\ttitle: `Audit ${audit.id} (${audit.action})`,\n\t\t\t\tsummary: audit.summary,\n\t\t\t\treasonCode: audit.reasonCode,\n\t\t\t\tmetadata: { layer: audit.layer, proposalId: audit.proposalId, rollbackOf: audit.rollbackOf },\n\t\t\t});\n\t\t}\n\t\tif (learningEntries.length > 0) {\n\t\t\tsnapshot.learning = learningEntries;\n\t\t}\n\n\t\tif (goal) {\n\t\t\tsnapshot.goals = [\n\t\t\t\t{\n\t\t\t\t\ttitle: `Goal ${goal.goalId}`,\n\t\t\t\t\tsummary: goal.userGoal,\n\t\t\t\t\treasonCode: goal.status,\n\t\t\t\t\tmetadata: {\n\t\t\t\t\t\topenRequirementCount: goal.requirements.filter((requirement) => requirement.status === \"open\").length,\n\t\t\t\t\t\tstallTurns: goal.stallTurns,\n\t\t\t\t\t\tblockedReason: goal.blockedReason,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\n\t\tconst processMemory = getProcessMemoryMb();\n\t\tsnapshot.processMemory = [\n\t\t\t{\n\t\t\t\ttitle: \"process\",\n\t\t\t\tmetadata: {\n\t\t\t\t\trssMb: processMemory.rssMb,\n\t\t\t\t\theapUsedMb: processMemory.heapUsedMb,\n\t\t\t\t\texternalMb: processMemory.externalMb,\n\t\t\t\t},\n\t\t\t},\n\t\t];\n\n\t\treturn snapshot;\n\t}\n}\n"]}
@@ -173,7 +173,7 @@ export class AutonomyTelemetry {
173
173
  },
174
174
  });
175
175
  }
176
- for (const bundle of this.deps.getEvidenceBundleSnapshots().slice(-maxEntriesPerFamily)) {
176
+ for (const bundle of this.deps.getSessionEvidenceBundleHistory().slice(-maxEntriesPerFamily)) {
177
177
  researchEntries.push({
178
178
  title: `Research: ${bundle.query}`,
179
179
  metadata: { sourceCount: bundle.sources.length, findingCount: bundle.findings.length },
@@ -194,15 +194,15 @@ export class AutonomyTelemetry {
194
194
  metadata: { costUsd: record.costUsd, startedAt: record.startedAt, completedAt: record.completedAt },
195
195
  });
196
196
  }
197
- const workerResults = this.deps.getWorkerResultSnapshots();
198
- for (const result of workerResults.slice(-maxEntriesPerFamily)) {
197
+ const workerClaims = this.deps.getSessionWorkerClaimHistory();
198
+ for (const claim of workerClaims.slice(-maxEntriesPerFamily)) {
199
199
  delegationEntries.push({
200
- title: `Worker ${result.requestId} (${result.status})`,
201
- summary: result.summary,
200
+ title: `Worker ${claim.requestId} (${claim.status})`,
201
+ summary: claim.summary,
202
202
  metadata: {
203
- changedFileCount: result.changedFiles.length,
204
- blockerCount: result.blockers?.length ?? 0,
205
- usageReportId: result.usageReportId,
203
+ changedFileCount: claim.changedFiles.length,
204
+ blockerCount: claim.blockers?.length ?? 0,
205
+ usageReportId: claim.usageReportId,
206
206
  },
207
207
  });
208
208
  }
@@ -210,7 +210,7 @@ export class AutonomyTelemetry {
210
210
  snapshot.delegation = delegationEntries;
211
211
  }
212
212
  const learningEntries = [];
213
- const learningDecisions = this.deps.getLearningDecisionSnapshots();
213
+ const learningDecisions = this.deps.getSessionLearningDecisionHistory();
214
214
  for (const decision of learningDecisions.slice(-maxEntriesPerFamily)) {
215
215
  learningEntries.push({
216
216
  title: `Learning (${decision.kind})`,
@@ -1 +1 @@
1
- {"version":3,"file":"autonomy-telemetry.js","sourceRoot":"","sources":["../../src/core/autonomy-telemetry.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAEhE,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAO3E,OAAO,EACN,8BAA8B,EAE9B,oBAAoB,GACpB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAA2B,MAAM,wBAAwB,CAAC;AAG9G,OAAO,EAAE,6BAA6B,EAAkC,MAAM,0BAA0B,CAAC;AAEzG;iFACiF;AACjF,MAAM,8BAA8B,GAAG,oBAAoB,CAAC;AAE5D,qGAAqG;AACrG,MAAM,0BAA0B,GAAG,EAAE,CAAC;AAyBtC,MAAM,OAAO,iBAAiB;IACrB,wBAAwB,CAAe;IAC/C,qGAAqG;IACpF,mBAAmB,GAA8B,EAAE,CAAC;IAEpD,IAAI,CAAwB;IAE7C,YAAY,IAA2B,EAAE;QACxC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAAA,CACjB;IAED;;;;;;OAMG;IACH,aAAa,CAAC,KAA6B,EAAQ;QAClD,IAAI,CAAC;YACJ,MAAM,QAAQ,GAAG,oBAAoB,CAAC,KAAK,CAA4B,CAAC;YACxE,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC,iBAAiB,CAAC,8BAA8B,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,GAAG,QAA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AAC;QACH,CAAC;QAED,MAAM,aAAa,GAAG,kBAAkB,EAAE,CAAC;QAC3C,QAAQ,CAAC,aAAa,GAAG;YACxB;gBACC,KAAK,EAAE,SAAS;gBAChB,QAAQ,EAAE;oBACT,KAAK,EAAE,aAAa,CAAC,KAAK;oBAC1B,UAAU,EAAE,aAAa,CAAC,UAAU;oBACpC,UAAU,EAAE,aAAa,CAAC,UAAU;iBACpC;aACD;SACD,CAAC;QAEF,OAAO,QAAQ,CAAC;IAAA,CAChB;CACD","sourcesContent":["/**\n * Autonomy telemetry sink + status/diagnostic snapshots.\n *\n * Extracted verbatim from agent-session.ts (god-file decomposition). Owns the latest gate outcome\n * and the bounded gate-outcome history, and is the single sink for G3 autonomy-telemetry custom\n * entries. The two snapshot builders READ broadly across live session state (router decision, cost,\n * goal, lanes, and the research/delegation/learning/goal getters) through narrow deps accessors\n * rather than the whole AgentSession — they never mutate anything but the owned gate-outcome fields.\n */\n\nimport type { SessionManager } from \"@caupulican/pi-agent-core/node\";\nimport { getProcessMemoryMb } from \"../utils/process-memory.ts\";\nimport type { EvidenceBundle, GateOutcome, LearningDecision, WorkerResult } from \"./autonomy/contracts.ts\";\nimport { getLaneRecordSnapshots } from \"./autonomy/session-lane-record.ts\";\nimport type {\n\tAutonomyDiagnosticSnapshot,\n\tAutonomyStatusSnapshot,\n\tDiagnosticEntry,\n\tGateOutcomeHistoryEntry,\n} from \"./autonomy/status.ts\";\nimport {\n\tAUTONOMY_TELEMETRY_EVENT_TYPES,\n\ttype AutonomyTelemetryEvent,\n\tredactTelemetryValue,\n} from \"./autonomy/telemetry-events.ts\";\nimport { hasCostSummarySignal, hasSubagentCostSignal, type SessionCostSummary } from \"./cost/cost-summary.ts\";\nimport type { GoalState } from \"./goals/goal-state.ts\";\nimport type { LearningAuditRecord } from \"./learning/learning-audit.ts\";\nimport { getRecentModelRouterDecisions, type ModelRouterDecisionStatus } from \"./model-router/status.ts\";\n\n/** Custom-entry type for G3 autonomy telemetry. Distinct from the router/lane record types so a\n * telemetry consumer can filter on it without decoding operational snapshots. */\nconst AUTONOMY_TELEMETRY_CUSTOM_TYPE = \"autonomy-telemetry\";\n\n/** G8: bound on the in-memory gate-outcome history. Oldest entries evict once the cap is reached. */\nconst GATE_OUTCOME_HISTORY_LIMIT = 50;\n\nexport interface AutonomyTelemetryDeps {\n\t/** Session log: `appendCustomEntry` is the telemetry sink; `getEntries` feeds diagnostic aggregation. */\n\tgetSessionManager(): Pick<SessionManager, \"appendCustomEntry\" | \"getEntries\">;\n\t/** Latest model-router decision, for the snapshot's `latestRoute` — owned by the router, not this sink. */\n\tgetLastModelRouterDecision(): ModelRouterDecisionStatus | undefined;\n\t/** Reason the last research lane was skipped, if any — surfaced in the diagnostic's research family. */\n\tgetLastResearchLaneSkipReason(): string | undefined;\n\t/** Single source of truth for CURRENT/TODAY/SUBAGENTS display costs. */\n\tgetCostSummary(): SessionCostSummary;\n\t/** Current goal state, if a goal is active. */\n\tgetGoalStateSnapshot(): GoalState | undefined;\n\t/** Live count of active lanes from the lane tracker — never inferred from historical snapshots. */\n\tgetActiveLaneCount(): number;\n\t/** Research evidence bundles recorded this session. */\n\tgetEvidenceBundleSnapshots(): EvidenceBundle[];\n\t/** Worker-delegation result snapshots recorded this session. */\n\tgetWorkerResultSnapshots(): WorkerResult[];\n\t/** Learning decision snapshots recorded this session. */\n\tgetLearningDecisionSnapshots(): LearningDecision[];\n\t/** Learning audit records recorded this session. */\n\tgetLearningAuditRecords(): LearningAuditRecord[];\n}\n\nexport class AutonomyTelemetry {\n\tprivate _lastAutonomyGateOutcome?: GateOutcome;\n\t/** G8: bounded (cap {@link GATE_OUTCOME_HISTORY_LIMIT}) history of gate outcomes; tail is latest. */\n\tprivate readonly _gateOutcomeHistory: GateOutcomeHistoryEntry[] = [];\n\n\tprivate readonly deps: AutonomyTelemetryDeps;\n\n\tconstructor(deps: AutonomyTelemetryDeps) {\n\t\tthis.deps = deps;\n\t}\n\n\t/**\n\t * G3: bounded autonomy-telemetry sink. Passes the whole event through {@link redactTelemetryValue}\n\t * (the taxonomy's redaction contract) before storing it, so a secret that leaked into a payload\n\t * field never lands in the session log. Observe-only: a failure here can never surface into the\n\t * turn it is measuring, so the whole body is swallowed. Payloads MUST stay small (ids, codes,\n\t * numbers) — never prompt/summary text; callers own that discipline.\n\t */\n\temitTelemetry(event: AutonomyTelemetryEvent): void {\n\t\ttry {\n\t\t\tconst redacted = redactTelemetryValue(event) as Record<string, unknown>;\n\t\t\tthis.deps.getSessionManager().appendCustomEntry(AUTONOMY_TELEMETRY_CUSTOM_TYPE, { version: 1, ...redacted });\n\t\t} catch {\n\t\t\t// Telemetry is best-effort: swallow so a sink failure cannot break the observed turn.\n\t\t}\n\t}\n\n\t/**\n\t * G8: single sink for a gate outcome. Keeps the latest-outcome getter behavior identical (the\n\t * full {@link GateOutcome} still lands in `_lastAutonomyGateOutcome`), and additionally appends a\n\t * bounded codes-only entry to {@link _gateOutcomeHistory} (oldest evicted at\n\t * {@link GATE_OUTCOME_HISTORY_LIMIT}) and emits the `gate_outcome` telemetry event. The history\n\t * tail therefore always mirrors the latest outcome. Only called with an active envelope.\n\t */\n\trecordGateOutcome(outcome: GateOutcome): void {\n\t\tthis._lastAutonomyGateOutcome = outcome;\n\t\tconst at = new Date().toISOString();\n\t\tthis._gateOutcomeHistory.push({\n\t\t\toutcome: outcome.outcome,\n\t\t\tgate: outcome.gate,\n\t\t\treasonCode: outcome.reasonCode,\n\t\t\tat,\n\t\t});\n\t\twhile (this._gateOutcomeHistory.length > GATE_OUTCOME_HISTORY_LIMIT) {\n\t\t\tthis._gateOutcomeHistory.shift();\n\t\t}\n\t\t// G8: gate outcome event. Codes/ids only — never the gate's human-facing message.\n\t\tthis.emitTelemetry({\n\t\t\ttype: AUTONOMY_TELEMETRY_EVENT_TYPES.gateOutcome,\n\t\t\ttimestamp: at,\n\t\t\tpayload: {\n\t\t\t\toutcome: outcome.outcome,\n\t\t\t\tgate: outcome.gate,\n\t\t\t\treasonCode: outcome.reasonCode,\n\t\t\t},\n\t\t});\n\t}\n\n\t/** G8: copies of the bounded gate-outcome history, oldest first, latest last. */\n\tgetGateOutcomeHistory(): GateOutcomeHistoryEntry[] {\n\t\treturn this._gateOutcomeHistory.map((entry) => ({ ...entry }));\n\t}\n\n\tgetStatusSnapshot(): AutonomyStatusSnapshot {\n\t\tconst snapshot: AutonomyStatusSnapshot = {};\n\n\t\tconst lastRouterDecision = this.deps.getLastModelRouterDecision();\n\t\tif (lastRouterDecision?.route) {\n\t\t\tsnapshot.latestRoute = {\n\t\t\t\ttier: lastRouterDecision.route.tier,\n\t\t\t\treasonCode: lastRouterDecision.route.reasonCode,\n\t\t\t\trisk: lastRouterDecision.route.risk,\n\t\t\t};\n\t\t}\n\n\t\tif (this._lastAutonomyGateOutcome) {\n\t\t\tsnapshot.latestGate = {\n\t\t\t\toutcome: this._lastAutonomyGateOutcome.outcome,\n\t\t\t\tgate: this._lastAutonomyGateOutcome.gate,\n\t\t\t\treasonCode: this._lastAutonomyGateOutcome.reasonCode,\n\t\t\t};\n\t\t}\n\n\t\tconst costSummary = this.deps.getCostSummary();\n\t\tif (hasCostSummarySignal(costSummary)) {\n\t\t\tsnapshot.costSummary = costSummary;\n\t\t}\n\n\t\tconst goal = this.deps.getGoalStateSnapshot();\n\t\tif (goal) {\n\t\t\tsnapshot.activeGoal = {\n\t\t\t\tgoalId: goal.goalId,\n\t\t\t\tstatus: goal.status,\n\t\t\t\topenRequirements: goal.requirements.filter((requirement) => requirement.status === \"open\").length,\n\t\t\t\tstallTurns: goal.stallTurns,\n\t\t\t};\n\t\t}\n\n\t\t// Real live count from the lane tracker — never inferred from historical snapshots. Absent\n\t\t// while zero, matching the presence-means-signal convention of the sibling fields.\n\t\tconst activeLaneCount = this.deps.getActiveLaneCount();\n\t\tif (activeLaneCount > 0) {\n\t\t\tsnapshot.activeLaneCount = activeLaneCount;\n\t\t}\n\n\t\treturn snapshot;\n\t}\n\n\t/**\n\t * Aggregate an effectiveness/autonomy dashboard: what Pi has actually been doing (recent\n\t * route choices, latest gate outcome, cost, and any research/delegation/learning/goal\n\t * activity). Read-only — combines existing session-log getters, never mutates state or\n\t * recomputes a route/gate decision.\n\t */\n\tgetDiagnosticSnapshot(options?: { maxEntriesPerFamily?: number }): AutonomyDiagnosticSnapshot {\n\t\tconst maxEntriesPerFamily = options?.maxEntriesPerFamily ?? 10;\n\t\tconst snapshot: AutonomyDiagnosticSnapshot = {};\n\t\tconst goal = this.deps.getGoalStateSnapshot();\n\n\t\tconst recentDecisions = getRecentModelRouterDecisions(\n\t\t\tthis.deps.getSessionManager().getEntries(),\n\t\t\tmaxEntriesPerFamily,\n\t\t);\n\t\tif (recentDecisions.length > 0) {\n\t\t\tsnapshot.routes = recentDecisions.map(\n\t\t\t\t(decision): DiagnosticEntry => ({\n\t\t\t\t\ttitle: decision.route.tier,\n\t\t\t\t\tsummary: decision.routedModel,\n\t\t\t\t\treasonCode: decision.route.reasonCode,\n\t\t\t\t\tmetadata: { risk: decision.route.risk, outcome: decision.outcome, intent: decision.intent },\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\tif (this._lastAutonomyGateOutcome) {\n\t\t\tconst gate = this._lastAutonomyGateOutcome;\n\t\t\tsnapshot.gates = [\n\t\t\t\t{\n\t\t\t\t\ttitle: gate.gate,\n\t\t\t\t\tsummary: gate.message,\n\t\t\t\t\treasonCode: gate.reasonCode,\n\t\t\t\t\tmetadata: { outcome: gate.outcome, reversible: gate.reversible },\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\n\t\tconst costs: DiagnosticEntry[] = [];\n\t\tconst costSummary = this.deps.getCostSummary();\n\t\tif (costSummary.currentCost > 0 || hasSubagentCostSignal(costSummary)) {\n\t\t\tcosts.push({ title: \"CURRENT\", summary: `$${costSummary.currentCost.toFixed(4)}` });\n\t\t}\n\t\tif (costSummary.todayCost > 0) {\n\t\t\tcosts.push({ title: \"TODAY\", summary: `$${costSummary.todayCost.toFixed(4)}` });\n\t\t}\n\t\tif (hasSubagentCostSignal(costSummary)) {\n\t\t\tcosts.push({\n\t\t\t\ttitle: \"SUBAGENTS\",\n\t\t\t\tsummary: `$${costSummary.subagentCost.toFixed(4)} included in CURRENT`,\n\t\t\t});\n\t\t}\n\t\tif (costs.length > 0) snapshot.costs = costs;\n\n\t\tconst researchEntries: DiagnosticEntry[] = [];\n\t\tconst researchLaneRecords = getLaneRecordSnapshots(this.deps.getSessionManager().getEntries()).filter(\n\t\t\t(record) => record.type === \"research\",\n\t\t);\n\t\tfor (const record of researchLaneRecords.slice(-maxEntriesPerFamily)) {\n\t\t\tresearchEntries.push({\n\t\t\t\ttitle: `Lane ${record.laneId} (${record.status})`,\n\t\t\t\treasonCode: record.reasonCode,\n\t\t\t\tmetadata: {\n\t\t\t\t\tcostUsd: record.costUsd,\n\t\t\t\t\tstartedAt: record.startedAt,\n\t\t\t\t\tcompletedAt: record.completedAt,\n\t\t\t\t\tgoalId: record.goalId,\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t\tfor (const bundle of this.deps.getEvidenceBundleSnapshots().slice(-maxEntriesPerFamily)) {\n\t\t\tresearchEntries.push({\n\t\t\t\ttitle: `Research: ${bundle.query}`,\n\t\t\t\tmetadata: { sourceCount: bundle.sources.length, findingCount: bundle.findings.length },\n\t\t\t});\n\t\t}\n\t\tif (this.deps.getLastResearchLaneSkipReason()) {\n\t\t\tresearchEntries.push({ title: \"Last skip\", reasonCode: this.deps.getLastResearchLaneSkipReason() });\n\t\t}\n\t\tif (researchEntries.length > 0) {\n\t\t\tsnapshot.research = researchEntries;\n\t\t}\n\n\t\tconst delegationEntries: DiagnosticEntry[] = [];\n\t\tconst workerLaneRecords = getLaneRecordSnapshots(this.deps.getSessionManager().getEntries()).filter(\n\t\t\t(record) => record.type === \"worker\",\n\t\t);\n\t\tfor (const record of workerLaneRecords.slice(-maxEntriesPerFamily)) {\n\t\t\tdelegationEntries.push({\n\t\t\t\ttitle: `Lane ${record.laneId} (${record.status})`,\n\t\t\t\treasonCode: record.reasonCode,\n\t\t\t\tmetadata: { costUsd: record.costUsd, startedAt: record.startedAt, completedAt: record.completedAt },\n\t\t\t});\n\t\t}\n\t\tconst workerResults = this.deps.getWorkerResultSnapshots();\n\t\tfor (const result of workerResults.slice(-maxEntriesPerFamily)) {\n\t\t\tdelegationEntries.push({\n\t\t\t\ttitle: `Worker ${result.requestId} (${result.status})`,\n\t\t\t\tsummary: result.summary,\n\t\t\t\tmetadata: {\n\t\t\t\t\tchangedFileCount: result.changedFiles.length,\n\t\t\t\t\tblockerCount: result.blockers?.length ?? 0,\n\t\t\t\t\tusageReportId: result.usageReportId,\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t\tif (delegationEntries.length > 0) {\n\t\t\tsnapshot.delegation = delegationEntries;\n\t\t}\n\n\t\tconst learningEntries: DiagnosticEntry[] = [];\n\t\tconst learningDecisions = this.deps.getLearningDecisionSnapshots();\n\t\tfor (const decision of learningDecisions.slice(-maxEntriesPerFamily)) {\n\t\t\tlearningEntries.push({\n\t\t\t\ttitle: `Learning (${decision.kind})`,\n\t\t\t\tsummary: decision.summary,\n\t\t\t\treasonCode: decision.reasonCode,\n\t\t\t\tmetadata: { confidence: decision.confidence, requiresApproval: decision.requiresApproval },\n\t\t\t});\n\t\t}\n\t\tfor (const audit of this.deps.getLearningAuditRecords().slice(-maxEntriesPerFamily)) {\n\t\t\tlearningEntries.push({\n\t\t\t\ttitle: `Audit ${audit.id} (${audit.action})`,\n\t\t\t\tsummary: audit.summary,\n\t\t\t\treasonCode: audit.reasonCode,\n\t\t\t\tmetadata: { layer: audit.layer, proposalId: audit.proposalId, rollbackOf: audit.rollbackOf },\n\t\t\t});\n\t\t}\n\t\tif (learningEntries.length > 0) {\n\t\t\tsnapshot.learning = learningEntries;\n\t\t}\n\n\t\tif (goal) {\n\t\t\tsnapshot.goals = [\n\t\t\t\t{\n\t\t\t\t\ttitle: `Goal ${goal.goalId}`,\n\t\t\t\t\tsummary: goal.userGoal,\n\t\t\t\t\treasonCode: goal.status,\n\t\t\t\t\tmetadata: {\n\t\t\t\t\t\topenRequirementCount: goal.requirements.filter((requirement) => requirement.status === \"open\").length,\n\t\t\t\t\t\tstallTurns: goal.stallTurns,\n\t\t\t\t\t\tblockedReason: goal.blockedReason,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\n\t\tconst processMemory = getProcessMemoryMb();\n\t\tsnapshot.processMemory = [\n\t\t\t{\n\t\t\t\ttitle: \"process\",\n\t\t\t\tmetadata: {\n\t\t\t\t\trssMb: processMemory.rssMb,\n\t\t\t\t\theapUsedMb: processMemory.heapUsedMb,\n\t\t\t\t\texternalMb: processMemory.externalMb,\n\t\t\t\t},\n\t\t\t},\n\t\t];\n\n\t\treturn snapshot;\n\t}\n}\n"]}
1
+ {"version":3,"file":"autonomy-telemetry.js","sourceRoot":"","sources":["../../src/core/autonomy-telemetry.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAEhE,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAO3E,OAAO,EACN,8BAA8B,EAE9B,oBAAoB,GACpB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAA2B,MAAM,wBAAwB,CAAC;AAG9G,OAAO,EAAE,6BAA6B,EAAkC,MAAM,0BAA0B,CAAC;AAEzG;iFACiF;AACjF,MAAM,8BAA8B,GAAG,oBAAoB,CAAC;AAE5D,qGAAqG;AACrG,MAAM,0BAA0B,GAAG,EAAE,CAAC;AAyBtC,MAAM,OAAO,iBAAiB;IACrB,wBAAwB,CAAe;IAC/C,qGAAqG;IACpF,mBAAmB,GAA8B,EAAE,CAAC;IAEpD,IAAI,CAAwB;IAE7C,YAAY,IAA2B,EAAE;QACxC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAAA,CACjB;IAED;;;;;;OAMG;I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ACT,oBAAoB,EAAE,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC,MAAM;wBACrG,UAAU,EAAE,IAAI,CAAC,UAAU;wBAC3B,aAAa,EAAE,IAAI,CAAC,aAAa;qBACjC;iBACD;aACD,CAAC;QACH,CAAC;QAED,MAAM,aAAa,GAAG,kBAAkB,EAAE,CAAC;QAC3C,QAAQ,CAAC,aAAa,GAAG;YACxB;gBACC,KAAK,EAAE,SAAS;gBAChB,QAAQ,EAAE;oBACT,KAAK,EAAE,aAAa,CAAC,KAAK;oBAC1B,UAAU,EAAE,aAAa,CAAC,UAAU;oBACpC,UAAU,EAAE,aAAa,CAAC,UAAU;iBACpC;aACD;SACD,CAAC;QAEF,OAAO,QAAQ,CAAC;IAAA,CAChB;CACD","sourcesContent":["/**\n * Autonomy telemetry sink + status/diagnostic snapshots.\n *\n * Extracted verbatim from agent-session.ts (god-file decomposition). Owns the latest gate outcome\n * and the bounded gate-outcome history, and is the single sink for G3 autonomy-telemetry custom\n * entries. The two snapshot builders READ broadly across live session state (router decision, cost,\n * goal, lanes, and the research/delegation/learning/goal getters) through narrow deps accessors\n * rather than the whole AgentSession — they never mutate anything but the owned gate-outcome fields.\n */\n\nimport type { SessionManager } from \"@caupulican/pi-agent-core/node\";\nimport { getProcessMemoryMb } from \"../utils/process-memory.ts\";\nimport type { EvidenceBundle, GateOutcome, LearningDecision, WorkerClaim } from \"./autonomy/contracts.ts\";\nimport { getLaneRecordSnapshots } from \"./autonomy/session-lane-record.ts\";\nimport type {\n\tAutonomyDiagnosticSnapshot,\n\tAutonomyStatusSnapshot,\n\tDiagnosticEntry,\n\tGateOutcomeHistoryEntry,\n} from \"./autonomy/status.ts\";\nimport {\n\tAUTONOMY_TELEMETRY_EVENT_TYPES,\n\ttype AutonomyTelemetryEvent,\n\tredactTelemetryValue,\n} from \"./autonomy/telemetry-events.ts\";\nimport { hasCostSummarySignal, hasSubagentCostSignal, type SessionCostSummary } from \"./cost/cost-summary.ts\";\nimport type { GoalState } from \"./goals/goal-state.ts\";\nimport type { LearningAuditRecord } from \"./learning/learning-audit.ts\";\nimport { getRecentModelRouterDecisions, type ModelRouterDecisionStatus } from \"./model-router/status.ts\";\n\n/** Custom-entry type for G3 autonomy telemetry. Distinct from the router/lane record types so a\n * telemetry consumer can filter on it without decoding operational snapshots. */\nconst AUTONOMY_TELEMETRY_CUSTOM_TYPE = \"autonomy-telemetry\";\n\n/** G8: bound on the in-memory gate-outcome history. Oldest entries evict once the cap is reached. */\nconst GATE_OUTCOME_HISTORY_LIMIT = 50;\n\nexport interface AutonomyTelemetryDeps {\n\t/** Session log: `appendCustomEntry` is the telemetry sink; `getEntries` feeds diagnostic aggregation. */\n\tgetSessionManager(): Pick<SessionManager, \"appendCustomEntry\" | \"getEntries\">;\n\t/** Latest model-router decision, for the snapshot's `latestRoute` — owned by the router, not this sink. */\n\tgetLastModelRouterDecision(): ModelRouterDecisionStatus | undefined;\n\t/** Reason the last research lane was skipped, if any — surfaced in the diagnostic's research family. */\n\tgetLastResearchLaneSkipReason(): string | undefined;\n\t/** Single source of truth for CURRENT/TODAY/SUBAGENTS display costs. */\n\tgetCostSummary(): SessionCostSummary;\n\t/** Current goal state, if a goal is active. */\n\tgetGoalStateSnapshot(): GoalState | undefined;\n\t/** Live count of active lanes from the lane tracker — never inferred from historical snapshots. */\n\tgetActiveLaneCount(): number;\n\t/** Research evidence bundles across the complete session tree, including sibling branches. */\n\tgetSessionEvidenceBundleHistory(): EvidenceBundle[];\n\t/** Worker-delegation claims across the complete session tree, including sibling branches. */\n\tgetSessionWorkerClaimHistory(): WorkerClaim[];\n\t/** Learning decisions across the complete session tree, including sibling branches. */\n\tgetSessionLearningDecisionHistory(): LearningDecision[];\n\t/** Learning audit records recorded this session. */\n\tgetLearningAuditRecords(): LearningAuditRecord[];\n}\n\nexport class AutonomyTelemetry {\n\tprivate _lastAutonomyGateOutcome?: GateOutcome;\n\t/** G8: bounded (cap {@link GATE_OUTCOME_HISTORY_LIMIT}) history of gate outcomes; tail is latest. */\n\tprivate readonly _gateOutcomeHistory: GateOutcomeHistoryEntry[] = [];\n\n\tprivate readonly deps: AutonomyTelemetryDeps;\n\n\tconstructor(deps: AutonomyTelemetryDeps) {\n\t\tthis.deps = deps;\n\t}\n\n\t/**\n\t * G3: bounded autonomy-telemetry sink. Passes the whole event through {@link redactTelemetryValue}\n\t * (the taxonomy's redaction contract) before storing it, so a secret that leaked into a payload\n\t * field never lands in the session log. Observe-only: a failure here can never surface into the\n\t * turn it is measuring, so the whole body is swallowed. Payloads MUST stay small (ids, codes,\n\t * numbers) — never prompt/summary text; callers own that discipline.\n\t */\n\temitTelemetry(event: AutonomyTelemetryEvent): void {\n\t\ttry {\n\t\t\tconst redacted = redactTelemetryValue(event) as Record<string, unknown>;\n\t\t\tthis.deps.getSessionManager().appendCustomEntry(AUTONOMY_TELEMETRY_CUSTOM_TYPE, { version: 1, ...redacted });\n\t\t} catch {\n\t\t\t// Telemetry is best-effort: swallow so a sink failure cannot break the observed turn.\n\t\t}\n\t}\n\n\t/**\n\t * G8: single sink for a gate outcome. Keeps the latest-outcome getter behavior identical (the\n\t * full {@link GateOutcome} still lands in `_lastAutonomyGateOutcome`), and additionally appends a\n\t * bounded codes-only entry to {@link _gateOutcomeHistory} (oldest evicted at\n\t * {@link GATE_OUTCOME_HISTORY_LIMIT}) and emits the `gate_outcome` telemetry event. The history\n\t * tail therefore always mirrors the latest outcome. Only called with an active envelope.\n\t */\n\trecordGateOutcome(outcome: GateOutcome): void {\n\t\tthis._lastAutonomyGateOutcome = outcome;\n\t\tconst at = new Date().toISOString();\n\t\tthis._gateOutcomeHistory.push({\n\t\t\toutcome: outcome.outcome,\n\t\t\tgate: outcome.gate,\n\t\t\treasonCode: outcome.reasonCode,\n\t\t\tat,\n\t\t});\n\t\twhile (this._gateOutcomeHistory.length > GATE_OUTCOME_HISTORY_LIMIT) {\n\t\t\tthis._gateOutcomeHistory.shift();\n\t\t}\n\t\t// G8: gate outcome event. Codes/ids only — never the gate's human-facing message.\n\t\tthis.emitTelemetry({\n\t\t\ttype: AUTONOMY_TELEMETRY_EVENT_TYPES.gateOutcome,\n\t\t\ttimestamp: at,\n\t\t\tpayload: {\n\t\t\t\toutcome: outcome.outcome,\n\t\t\t\tgate: outcome.gate,\n\t\t\t\treasonCode: outcome.reasonCode,\n\t\t\t},\n\t\t});\n\t}\n\n\t/** G8: copies of the bounded gate-outcome history, oldest first, latest last. */\n\tgetGateOutcomeHistory(): GateOutcomeHistoryEntry[] {\n\t\treturn this._gateOutcomeHistory.map((entry) => ({ ...entry }));\n\t}\n\n\tgetStatusSnapshot(): AutonomyStatusSnapshot {\n\t\tconst snapshot: AutonomyStatusSnapshot = {};\n\n\t\tconst lastRouterDecision = this.deps.getLastModelRouterDecision();\n\t\tif (lastRouterDecision?.route) {\n\t\t\tsnapshot.latestRoute = {\n\t\t\t\ttier: lastRouterDecision.route.tier,\n\t\t\t\treasonCode: lastRouterDecision.route.reasonCode,\n\t\t\t\trisk: lastRouterDecision.route.risk,\n\t\t\t};\n\t\t}\n\n\t\tif (this._lastAutonomyGateOutcome) {\n\t\t\tsnapshot.latestGate = {\n\t\t\t\toutcome: this._lastAutonomyGateOutcome.outcome,\n\t\t\t\tgate: this._lastAutonomyGateOutcome.gate,\n\t\t\t\treasonCode: this._lastAutonomyGateOutcome.reasonCode,\n\t\t\t};\n\t\t}\n\n\t\tconst costSummary = this.deps.getCostSummary();\n\t\tif (hasCostSummarySignal(costSummary)) {\n\t\t\tsnapshot.costSummary = costSummary;\n\t\t}\n\n\t\tconst goal = this.deps.getGoalStateSnapshot();\n\t\tif (goal) {\n\t\t\tsnapshot.activeGoal = {\n\t\t\t\tgoalId: goal.goalId,\n\t\t\t\tstatus: goal.status,\n\t\t\t\topenRequirements: goal.requirements.filter((requirement) => requirement.status === \"open\").length,\n\t\t\t\tstallTurns: goal.stallTurns,\n\t\t\t};\n\t\t}\n\n\t\t// Real live count from the lane tracker — never inferred from historical snapshots. Absent\n\t\t// while zero, matching the presence-means-signal convention of the sibling fields.\n\t\tconst activeLaneCount = this.deps.getActiveLaneCount();\n\t\tif (activeLaneCount > 0) {\n\t\t\tsnapshot.activeLaneCount = activeLaneCount;\n\t\t}\n\n\t\treturn snapshot;\n\t}\n\n\t/**\n\t * Aggregate an effectiveness/autonomy dashboard: what Pi has actually been doing (recent\n\t * route choices, latest gate outcome, cost, and any research/delegation/learning/goal\n\t * activity). Read-only — combines existing session-log getters, never mutates state or\n\t * recomputes a route/gate decision.\n\t */\n\tgetDiagnosticSnapshot(options?: { maxEntriesPerFamily?: number }): AutonomyDiagnosticSnapshot {\n\t\tconst maxEntriesPerFamily = options?.maxEntriesPerFamily ?? 10;\n\t\tconst snapshot: AutonomyDiagnosticSnapshot = {};\n\t\tconst goal = this.deps.getGoalStateSnapshot();\n\n\t\tconst recentDecisions = getRecentModelRouterDecisions(\n\t\t\tthis.deps.getSessionManager().getEntries(),\n\t\t\tmaxEntriesPerFamily,\n\t\t);\n\t\tif (recentDecisions.length > 0) {\n\t\t\tsnapshot.routes = recentDecisions.map(\n\t\t\t\t(decision): DiagnosticEntry => ({\n\t\t\t\t\ttitle: decision.route.tier,\n\t\t\t\t\tsummary: decision.routedModel,\n\t\t\t\t\treasonCode: decision.route.reasonCode,\n\t\t\t\t\tmetadata: { risk: decision.route.risk, outcome: decision.outcome, intent: decision.intent },\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\tif (this._lastAutonomyGateOutcome) {\n\t\t\tconst gate = this._lastAutonomyGateOutcome;\n\t\t\tsnapshot.gates = [\n\t\t\t\t{\n\t\t\t\t\ttitle: gate.gate,\n\t\t\t\t\tsummary: gate.message,\n\t\t\t\t\treasonCode: gate.reasonCode,\n\t\t\t\t\tmetadata: { outcome: gate.outcome, reversible: gate.reversible },\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\n\t\tconst costs: DiagnosticEntry[] = [];\n\t\tconst costSummary = this.deps.getCostSummary();\n\t\tif (costSummary.currentCost > 0 || hasSubagentCostSignal(costSummary)) {\n\t\t\tcosts.push({ title: \"CURRENT\", summary: `$${costSummary.currentCost.toFixed(4)}` });\n\t\t}\n\t\tif (costSummary.todayCost > 0) {\n\t\t\tcosts.push({ title: \"TODAY\", summary: `$${costSummary.todayCost.toFixed(4)}` });\n\t\t}\n\t\tif (hasSubagentCostSignal(costSummary)) {\n\t\t\tcosts.push({\n\t\t\t\ttitle: \"SUBAGENTS\",\n\t\t\t\tsummary: `$${costSummary.subagentCost.toFixed(4)} included in CURRENT`,\n\t\t\t});\n\t\t}\n\t\tif (costs.length > 0) snapshot.costs = costs;\n\n\t\tconst researchEntries: DiagnosticEntry[] = [];\n\t\tconst researchLaneRecords = getLaneRecordSnapshots(this.deps.getSessionManager().getEntries()).filter(\n\t\t\t(record) => record.type === \"research\",\n\t\t);\n\t\tfor (const record of researchLaneRecords.slice(-maxEntriesPerFamily)) {\n\t\t\tresearchEntries.push({\n\t\t\t\ttitle: `Lane ${record.laneId} (${record.status})`,\n\t\t\t\treasonCode: record.reasonCode,\n\t\t\t\tmetadata: {\n\t\t\t\t\tcostUsd: record.costUsd,\n\t\t\t\t\tstartedAt: record.startedAt,\n\t\t\t\t\tcompletedAt: record.completedAt,\n\t\t\t\t\tgoalId: record.goalId,\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t\tfor (const bundle of this.deps.getSessionEvidenceBundleHistory().slice(-maxEntriesPerFamily)) {\n\t\t\tresearchEntries.push({\n\t\t\t\ttitle: `Research: ${bundle.query}`,\n\t\t\t\tmetadata: { sourceCount: bundle.sources.length, findingCount: bundle.findings.length },\n\t\t\t});\n\t\t}\n\t\tif (this.deps.getLastResearchLaneSkipReason()) {\n\t\t\tresearchEntries.push({ title: \"Last skip\", reasonCode: this.deps.getLastResearchLaneSkipReason() });\n\t\t}\n\t\tif (researchEntries.length > 0) {\n\t\t\tsnapshot.research = researchEntries;\n\t\t}\n\n\t\tconst delegationEntries: DiagnosticEntry[] = [];\n\t\tconst workerLaneRecords = getLaneRecordSnapshots(this.deps.getSessionManager().getEntries()).filter(\n\t\t\t(record) => record.type === \"worker\",\n\t\t);\n\t\tfor (const record of workerLaneRecords.slice(-maxEntriesPerFamily)) {\n\t\t\tdelegationEntries.push({\n\t\t\t\ttitle: `Lane ${record.laneId} (${record.status})`,\n\t\t\t\treasonCode: record.reasonCode,\n\t\t\t\tmetadata: { costUsd: record.costUsd, startedAt: record.startedAt, completedAt: record.completedAt },\n\t\t\t});\n\t\t}\n\t\tconst workerClaims = this.deps.getSessionWorkerClaimHistory();\n\t\tfor (const claim of workerClaims.slice(-maxEntriesPerFamily)) {\n\t\t\tdelegationEntries.push({\n\t\t\t\ttitle: `Worker ${claim.requestId} (${claim.status})`,\n\t\t\t\tsummary: claim.summary,\n\t\t\t\tmetadata: {\n\t\t\t\t\tchangedFileCount: claim.changedFiles.length,\n\t\t\t\t\tblockerCount: claim.blockers?.length ?? 0,\n\t\t\t\t\tusageReportId: claim.usageReportId,\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t\tif (delegationEntries.length > 0) {\n\t\t\tsnapshot.delegation = delegationEntries;\n\t\t}\n\n\t\tconst learningEntries: DiagnosticEntry[] = [];\n\t\tconst learningDecisions = this.deps.getSessionLearningDecisionHistory();\n\t\tfor (const decision of learningDecisions.slice(-maxEntriesPerFamily)) {\n\t\t\tlearningEntries.push({\n\t\t\t\ttitle: `Learning (${decision.kind})`,\n\t\t\t\tsummary: decision.summary,\n\t\t\t\treasonCode: decision.reasonCode,\n\t\t\t\tmetadata: { confidence: decision.confidence, requiresApproval: decision.requiresApproval },\n\t\t\t});\n\t\t}\n\t\tfor (const audit of this.deps.getLearningAuditRecords().slice(-maxEntriesPerFamily)) {\n\t\t\tlearningEntries.push({\n\t\t\t\ttitle: `Audit ${audit.id} (${audit.action})`,\n\t\t\t\tsummary: audit.summary,\n\t\t\t\treasonCode: audit.reasonCode,\n\t\t\t\tmetadata: { layer: audit.layer, proposalId: audit.proposalId, rollbackOf: audit.rollbackOf },\n\t\t\t});\n\t\t}\n\t\tif (learningEntries.length > 0) {\n\t\t\tsnapshot.learning = learningEntries;\n\t\t}\n\n\t\tif (goal) {\n\t\t\tsnapshot.goals = [\n\t\t\t\t{\n\t\t\t\t\ttitle: `Goal ${goal.goalId}`,\n\t\t\t\t\tsummary: goal.userGoal,\n\t\t\t\t\treasonCode: goal.status,\n\t\t\t\t\tmetadata: {\n\t\t\t\t\t\topenRequirementCount: goal.requirements.filter((requirement) => requirement.status === \"open\").length,\n\t\t\t\t\t\tstallTurns: goal.stallTurns,\n\t\t\t\t\t\tblockedReason: goal.blockedReason,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\n\t\tconst processMemory = getProcessMemoryMb();\n\t\tsnapshot.processMemory = [\n\t\t\t{\n\t\t\t\ttitle: \"process\",\n\t\t\t\tmetadata: {\n\t\t\t\t\trssMb: processMemory.rssMb,\n\t\t\t\t\theapUsedMb: processMemory.heapUsedMb,\n\t\t\t\t\texternalMb: processMemory.externalMb,\n\t\t\t\t},\n\t\t\t},\n\t\t];\n\n\t\treturn snapshot;\n\t}\n}\n"]}