@senpi/runtime 3.0.6-dev.skill-manager-v2.20260629194505 → 3.0.9-dev.20260710204324

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 (472) hide show
  1. package/dist/actions/action-events.d.ts +67 -0
  2. package/dist/actions/action-events.d.ts.map +1 -0
  3. package/dist/actions/action-events.js +164 -0
  4. package/dist/actions/action-events.js.map +1 -0
  5. package/dist/actions/close-position/close-position.action.d.ts +1 -1
  6. package/dist/actions/close-position/close-position.action.d.ts.map +1 -1
  7. package/dist/actions/close-position/close-position.action.js +108 -86
  8. package/dist/actions/close-position/close-position.action.js.map +1 -1
  9. package/dist/actions/decision-engine.d.ts.map +1 -1
  10. package/dist/actions/decision-engine.js +40 -28
  11. package/dist/actions/decision-engine.js.map +1 -1
  12. package/dist/actions/event-derivation.d.ts +61 -0
  13. package/dist/actions/event-derivation.d.ts.map +1 -0
  14. package/dist/actions/event-derivation.js +180 -0
  15. package/dist/actions/event-derivation.js.map +1 -0
  16. package/dist/actions/llm-decision/anthropic-llm-decision.d.ts +5 -9
  17. package/dist/actions/llm-decision/anthropic-llm-decision.d.ts.map +1 -1
  18. package/dist/actions/llm-decision/anthropic-llm-decision.js +6 -87
  19. package/dist/actions/llm-decision/anthropic-llm-decision.js.map +1 -1
  20. package/dist/actions/llm-decision/factory.d.ts +0 -6
  21. package/dist/actions/llm-decision/factory.d.ts.map +1 -1
  22. package/dist/actions/llm-decision/factory.js +0 -2
  23. package/dist/actions/llm-decision/factory.js.map +1 -1
  24. package/dist/actions/llm-decision/openclaw-llm-decision.d.ts.map +1 -1
  25. package/dist/actions/llm-decision/openclaw-llm-decision.js +26 -7
  26. package/dist/actions/llm-decision/openclaw-llm-decision.js.map +1 -1
  27. package/dist/actions/open-position/open-position.action.d.ts +1 -1
  28. package/dist/actions/open-position/open-position.action.d.ts.map +1 -1
  29. package/dist/actions/open-position/open-position.action.js +282 -224
  30. package/dist/actions/open-position/open-position.action.js.map +1 -1
  31. package/dist/actions/position-tracker/position-tracker.action.d.ts.map +1 -1
  32. package/dist/actions/position-tracker/position-tracker.action.js +3 -6
  33. package/dist/actions/position-tracker/position-tracker.action.js.map +1 -1
  34. package/dist/cli/guide-commands.d.ts.map +1 -1
  35. package/dist/cli/guide-commands.js +61 -0
  36. package/dist/cli/guide-commands.js.map +1 -1
  37. package/dist/cli/senpi-commands.d.ts +14 -0
  38. package/dist/cli/senpi-commands.d.ts.map +1 -1
  39. package/dist/cli/senpi-commands.js +390 -2
  40. package/dist/cli/senpi-commands.js.map +1 -1
  41. package/dist/dsl/engine-client/event-mapping.d.ts.map +1 -1
  42. package/dist/dsl/engine-client/event-mapping.js +0 -3
  43. package/dist/dsl/engine-client/event-mapping.js.map +1 -1
  44. package/dist/dsl/events/build-closed-event.d.ts.map +1 -1
  45. package/dist/dsl/events/build-closed-event.js +0 -1
  46. package/dist/dsl/events/build-closed-event.js.map +1 -1
  47. package/dist/dsl/events/handlers.d.ts.map +1 -1
  48. package/dist/dsl/events/handlers.js +2 -4
  49. package/dist/dsl/events/handlers.js.map +1 -1
  50. package/dist/dsl/events/initial-state.d.ts.map +1 -1
  51. package/dist/dsl/events/initial-state.js +1 -0
  52. package/dist/dsl/events/initial-state.js.map +1 -1
  53. package/dist/dsl/monitor/create-monitor.d.ts +3 -0
  54. package/dist/dsl/monitor/create-monitor.d.ts.map +1 -1
  55. package/dist/dsl/monitor/create-monitor.js +76 -58
  56. package/dist/dsl/monitor/create-monitor.js.map +1 -1
  57. package/dist/dsl/monitor/dsl-failure-events.d.ts +42 -0
  58. package/dist/dsl/monitor/dsl-failure-events.d.ts.map +1 -0
  59. package/dist/dsl/monitor/dsl-failure-events.js +73 -0
  60. package/dist/dsl/monitor/dsl-failure-events.js.map +1 -0
  61. package/dist/dsl/monitor/process-one-position.d.ts +2 -1
  62. package/dist/dsl/monitor/process-one-position.d.ts.map +1 -1
  63. package/dist/dsl/monitor/process-one-position.js +130 -196
  64. package/dist/dsl/monitor/process-one-position.js.map +1 -1
  65. package/dist/dsl/plugin/index.d.ts +10 -0
  66. package/dist/dsl/plugin/index.d.ts.map +1 -1
  67. package/dist/dsl/plugin/index.js +48 -4
  68. package/dist/dsl/plugin/index.js.map +1 -1
  69. package/dist/dsl/plugin/options.d.ts +3 -0
  70. package/dist/dsl/plugin/options.d.ts.map +1 -1
  71. package/dist/health/types.d.ts +14 -0
  72. package/dist/health/types.d.ts.map +1 -1
  73. package/dist/health/types.js.map +1 -1
  74. package/dist/index.d.ts +1 -0
  75. package/dist/index.d.ts.map +1 -1
  76. package/dist/index.js +264 -79
  77. package/dist/index.js.map +1 -1
  78. package/dist/risk/risk-audit-log.d.ts +7 -0
  79. package/dist/risk/risk-audit-log.d.ts.map +1 -1
  80. package/dist/risk/risk-audit-log.js +48 -1
  81. package/dist/risk/risk-audit-log.js.map +1 -1
  82. package/dist/runtime/__tests__/helpers/runtime-gateway-harness.d.ts +2 -0
  83. package/dist/runtime/__tests__/helpers/runtime-gateway-harness.d.ts.map +1 -1
  84. package/dist/runtime/__tests__/helpers/runtime-gateway-harness.js +24 -3
  85. package/dist/runtime/__tests__/helpers/runtime-gateway-harness.js.map +1 -1
  86. package/dist/runtime/auto-update/coordinator.js +2 -2
  87. package/dist/runtime/auto-update/coordinator.js.map +1 -1
  88. package/dist/runtime/create-actions.d.ts.map +1 -1
  89. package/dist/runtime/create-actions.js +40 -15
  90. package/dist/runtime/create-actions.js.map +1 -1
  91. package/dist/runtime/create-runtime-context.d.ts +1 -1
  92. package/dist/runtime/create-runtime-context.d.ts.map +1 -1
  93. package/dist/runtime/create-scanner-module.d.ts +2 -1
  94. package/dist/runtime/create-scanner-module.d.ts.map +1 -1
  95. package/dist/runtime/create-scanner-module.js +2 -1
  96. package/dist/runtime/create-scanner-module.js.map +1 -1
  97. package/dist/runtime/domain-events.d.ts +43 -0
  98. package/dist/runtime/domain-events.d.ts.map +1 -0
  99. package/dist/runtime/domain-events.js +181 -0
  100. package/dist/runtime/domain-events.js.map +1 -0
  101. package/dist/runtime/lifecycle-events.d.ts +86 -0
  102. package/dist/runtime/lifecycle-events.d.ts.map +1 -0
  103. package/dist/runtime/lifecycle-events.js +200 -0
  104. package/dist/runtime/lifecycle-events.js.map +1 -0
  105. package/dist/runtime/notifications.js +2 -2
  106. package/dist/runtime/notifications.js.map +1 -1
  107. package/dist/{tracking → runtime}/position-id-registry.d.ts +14 -1
  108. package/dist/runtime/position-id-registry.d.ts.map +1 -0
  109. package/dist/{tracking → runtime}/position-id-registry.js +20 -3
  110. package/dist/runtime/position-id-registry.js.map +1 -0
  111. package/dist/runtime/run.d.ts +2 -4
  112. package/dist/runtime/run.d.ts.map +1 -1
  113. package/dist/runtime/run.js.map +1 -1
  114. package/dist/runtime/runtime-schema.d.ts +276 -588
  115. package/dist/runtime/runtime-schema.d.ts.map +1 -1
  116. package/dist/runtime/runtime-schema.js +8 -28
  117. package/dist/runtime/runtime-schema.js.map +1 -1
  118. package/dist/runtime/runtime.d.ts +23 -9
  119. package/dist/runtime/runtime.d.ts.map +1 -1
  120. package/dist/runtime/runtime.js +276 -248
  121. package/dist/runtime/runtime.js.map +1 -1
  122. package/dist/runtime/strategy-lifecycle.d.ts.map +1 -1
  123. package/dist/runtime/strategy-lifecycle.js +13 -1
  124. package/dist/runtime/strategy-lifecycle.js.map +1 -1
  125. package/dist/runtime/supervisor/long-running-supervisor.d.ts +3 -0
  126. package/dist/runtime/supervisor/long-running-supervisor.d.ts.map +1 -1
  127. package/dist/runtime/supervisor/long-running-supervisor.js +27 -53
  128. package/dist/runtime/supervisor/long-running-supervisor.js.map +1 -1
  129. package/dist/runtime-api/config.d.ts +2 -2
  130. package/dist/runtime-api/config.js +4 -4
  131. package/dist/runtime-api/config.js.map +1 -1
  132. package/dist/runtime-api/handlers/ingest-signals.d.ts +5 -3
  133. package/dist/runtime-api/handlers/ingest-signals.d.ts.map +1 -1
  134. package/dist/runtime-api/handlers/ingest-signals.js +14 -5
  135. package/dist/runtime-api/handlers/ingest-signals.js.map +1 -1
  136. package/dist/runtime-api/intake/ingest-mutex.d.ts +16 -0
  137. package/dist/runtime-api/intake/ingest-mutex.d.ts.map +1 -0
  138. package/dist/runtime-api/intake/ingest-mutex.js +18 -0
  139. package/dist/runtime-api/intake/ingest-mutex.js.map +1 -0
  140. package/dist/runtime-api/intake/intake-events.d.ts +44 -0
  141. package/dist/runtime-api/intake/intake-events.d.ts.map +1 -0
  142. package/dist/runtime-api/intake/intake-events.js +131 -0
  143. package/dist/runtime-api/intake/intake-events.js.map +1 -0
  144. package/dist/runtime-api/intake/intake-mount.d.ts.map +1 -1
  145. package/dist/runtime-api/intake/intake-mount.js +8 -2
  146. package/dist/runtime-api/intake/intake-mount.js.map +1 -1
  147. package/dist/runtime-api/intake/scanner-launcher.d.ts +2 -0
  148. package/dist/runtime-api/intake/scanner-launcher.d.ts.map +1 -1
  149. package/dist/runtime-api/intake/scanner-launcher.js +58 -15
  150. package/dist/runtime-api/intake/scanner-launcher.js.map +1 -1
  151. package/dist/runtime-api/intake/scanner-registry.d.ts +3 -0
  152. package/dist/runtime-api/intake/scanner-registry.d.ts.map +1 -1
  153. package/dist/runtime-api/intake/scanner-registry.js +3 -0
  154. package/dist/runtime-api/intake/scanner-registry.js.map +1 -1
  155. package/dist/runtime-api/intake/supervisor-events.d.ts +61 -0
  156. package/dist/runtime-api/intake/supervisor-events.d.ts.map +1 -0
  157. package/dist/runtime-api/intake/supervisor-events.js +173 -0
  158. package/dist/runtime-api/intake/supervisor-events.js.map +1 -0
  159. package/dist/runtime-api/routes/signals.d.ts +1 -1
  160. package/dist/runtime-api/routes/signals.d.ts.map +1 -1
  161. package/dist/runtime-api/routes/signals.js +121 -35
  162. package/dist/runtime-api/routes/signals.js.map +1 -1
  163. package/dist/runtime-api/server.d.ts.map +1 -1
  164. package/dist/runtime-api/server.js +10 -1
  165. package/dist/runtime-api/server.js.map +1 -1
  166. package/dist/scanners/engine/data-providers.d.ts +3 -0
  167. package/dist/scanners/engine/data-providers.d.ts.map +1 -1
  168. package/dist/scanners/engine/data-providers.js.map +1 -1
  169. package/dist/scanners/engine/engine.d.ts +18 -0
  170. package/dist/scanners/engine/engine.d.ts.map +1 -1
  171. package/dist/scanners/engine/engine.js +96 -2
  172. package/dist/scanners/engine/engine.js.map +1 -1
  173. package/dist/scanners/engine/input-resolver.d.ts.map +1 -1
  174. package/dist/scanners/engine/input-resolver.js +9 -7
  175. package/dist/scanners/engine/input-resolver.js.map +1 -1
  176. package/dist/scanners/runtime-module.d.ts +3 -0
  177. package/dist/scanners/runtime-module.d.ts.map +1 -1
  178. package/dist/scanners/runtime-module.js +7 -0
  179. package/dist/scanners/runtime-module.js.map +1 -1
  180. package/dist/senpi/client.d.ts +10 -0
  181. package/dist/senpi/client.d.ts.map +1 -1
  182. package/dist/senpi/client.js +113 -46
  183. package/dist/senpi/client.js.map +1 -1
  184. package/dist/skills-manager/bootstrap.d.ts.map +1 -1
  185. package/dist/skills-manager/bootstrap.js +22 -33
  186. package/dist/skills-manager/bootstrap.js.map +1 -1
  187. package/dist/skills-manager/clone-groups.d.ts +20 -0
  188. package/dist/skills-manager/clone-groups.d.ts.map +1 -0
  189. package/dist/skills-manager/clone-groups.js +45 -0
  190. package/dist/skills-manager/clone-groups.js.map +1 -0
  191. package/dist/skills-manager/coordinator.d.ts.map +1 -1
  192. package/dist/skills-manager/coordinator.js +111 -75
  193. package/dist/skills-manager/coordinator.js.map +1 -1
  194. package/dist/skills-manager/manifest.d.ts +24 -0
  195. package/dist/skills-manager/manifest.d.ts.map +1 -1
  196. package/dist/skills-manager/manifest.js +23 -10
  197. package/dist/skills-manager/manifest.js.map +1 -1
  198. package/dist/skills-manager/skills-manifest.json +12 -7
  199. package/dist/skills-manager/types.d.ts +12 -0
  200. package/dist/skills-manager/types.d.ts.map +1 -1
  201. package/dist/state/state-events.d.ts +13 -0
  202. package/dist/state/state-events.d.ts.map +1 -0
  203. package/dist/state/state-events.js +22 -0
  204. package/dist/state/state-events.js.map +1 -0
  205. package/dist/state/state-manager.d.ts.map +1 -1
  206. package/dist/state/state-manager.js +14 -1
  207. package/dist/state/state-manager.js.map +1 -1
  208. package/dist/telemetry/attributes.d.ts +13 -0
  209. package/dist/telemetry/attributes.d.ts.map +1 -0
  210. package/dist/telemetry/attributes.js +22 -0
  211. package/dist/telemetry/attributes.js.map +1 -0
  212. package/dist/{tracking → telemetry}/context.d.ts +12 -5
  213. package/dist/telemetry/context.d.ts.map +1 -0
  214. package/dist/{tracking → telemetry}/context.js +4 -4
  215. package/dist/telemetry/context.js.map +1 -0
  216. package/dist/{recording/records.d.ts → telemetry/event-builders.d.ts} +145 -33
  217. package/dist/telemetry/event-builders.d.ts.map +1 -0
  218. package/dist/{recording/wiring/record-builders.js → telemetry/event-builders.js} +94 -40
  219. package/dist/telemetry/event-builders.js.map +1 -0
  220. package/dist/telemetry/event-store.d.ts +66 -0
  221. package/dist/telemetry/event-store.d.ts.map +1 -0
  222. package/dist/telemetry/event-store.js +202 -0
  223. package/dist/telemetry/event-store.js.map +1 -0
  224. package/dist/telemetry/identity.d.ts +72 -0
  225. package/dist/telemetry/identity.d.ts.map +1 -0
  226. package/dist/{recording/wiring → telemetry}/identity.js +6 -2
  227. package/dist/telemetry/identity.js.map +1 -0
  228. package/dist/telemetry/metrics.d.ts +169 -0
  229. package/dist/telemetry/metrics.d.ts.map +1 -0
  230. package/dist/telemetry/metrics.js +437 -0
  231. package/dist/telemetry/metrics.js.map +1 -0
  232. package/dist/telemetry/otel-sdk.d.ts +93 -0
  233. package/dist/telemetry/otel-sdk.d.ts.map +1 -0
  234. package/dist/telemetry/otel-sdk.js +297 -0
  235. package/dist/telemetry/otel-sdk.js.map +1 -0
  236. package/dist/telemetry/spans/constants.d.ts +12 -0
  237. package/dist/telemetry/spans/constants.d.ts.map +1 -0
  238. package/dist/telemetry/spans/constants.js +12 -0
  239. package/dist/telemetry/spans/constants.js.map +1 -0
  240. package/dist/telemetry/spans/gen-ai.d.ts +74 -0
  241. package/dist/telemetry/spans/gen-ai.d.ts.map +1 -0
  242. package/dist/telemetry/spans/gen-ai.js +339 -0
  243. package/dist/telemetry/spans/gen-ai.js.map +1 -0
  244. package/dist/telemetry/spans/index.d.ts +11 -0
  245. package/dist/telemetry/spans/index.d.ts.map +1 -0
  246. package/dist/telemetry/spans/index.js +11 -0
  247. package/dist/telemetry/spans/index.js.map +1 -0
  248. package/dist/{tracking → telemetry}/spans/redact-pii.d.ts +19 -21
  249. package/dist/telemetry/spans/redact-pii.d.ts.map +1 -0
  250. package/dist/{tracking → telemetry}/spans/redact-pii.js +35 -32
  251. package/dist/telemetry/spans/redact-pii.js.map +1 -0
  252. package/dist/telemetry/spans/sanitize-payload.d.ts.map +1 -0
  253. package/dist/telemetry/spans/sanitize-payload.js.map +1 -0
  254. package/dist/telemetry/spans/span-hooks.d.ts +18 -0
  255. package/dist/telemetry/spans/span-hooks.d.ts.map +1 -0
  256. package/dist/telemetry/spans/span-hooks.js +764 -0
  257. package/dist/telemetry/spans/span-hooks.js.map +1 -0
  258. package/dist/telemetry/tool-plane.d.ts +31 -0
  259. package/dist/telemetry/tool-plane.d.ts.map +1 -0
  260. package/dist/telemetry/tool-plane.js +70 -0
  261. package/dist/telemetry/tool-plane.js.map +1 -0
  262. package/dist/telemetry/trace-identity.d.ts +32 -0
  263. package/dist/telemetry/trace-identity.d.ts.map +1 -0
  264. package/dist/telemetry/trace-identity.js +62 -0
  265. package/dist/telemetry/trace-identity.js.map +1 -0
  266. package/dist/telemetry/tracing.d.ts +33 -0
  267. package/dist/telemetry/tracing.d.ts.map +1 -0
  268. package/dist/telemetry/tracing.js +70 -0
  269. package/dist/telemetry/tracing.js.map +1 -0
  270. package/dist/types/dsl/index.d.ts +8 -9
  271. package/dist/types/dsl/index.d.ts.map +1 -1
  272. package/dist/types/runtime.d.ts +1 -1
  273. package/dist/types/runtime.d.ts.map +1 -1
  274. package/dist/types/scanner.d.ts +2 -0
  275. package/dist/types/scanner.d.ts.map +1 -1
  276. package/dist/utils/event-catalog.d.ts +506 -0
  277. package/dist/utils/event-catalog.d.ts.map +1 -0
  278. package/dist/utils/event-catalog.js +142 -0
  279. package/dist/utils/event-catalog.js.map +1 -0
  280. package/dist/utils/logger.d.ts +63 -5
  281. package/dist/utils/logger.d.ts.map +1 -1
  282. package/dist/utils/logger.js +360 -27
  283. package/dist/utils/logger.js.map +1 -1
  284. package/dist/utils/wallet-address.d.ts +3 -0
  285. package/dist/utils/wallet-address.d.ts.map +1 -0
  286. package/dist/utils/wallet-address.js +17 -0
  287. package/dist/utils/wallet-address.js.map +1 -0
  288. package/openclaw.plugin.json +20 -6
  289. package/package.json +10 -2
  290. package/dist/actions/tracking-helpers.d.ts +0 -28
  291. package/dist/actions/tracking-helpers.d.ts.map +0 -1
  292. package/dist/actions/tracking-helpers.js +0 -93
  293. package/dist/actions/tracking-helpers.js.map +0 -1
  294. package/dist/recording/emitter.d.ts +0 -27
  295. package/dist/recording/emitter.d.ts.map +0 -1
  296. package/dist/recording/emitter.js +0 -2
  297. package/dist/recording/emitter.js.map +0 -1
  298. package/dist/recording/identity.d.ts +0 -34
  299. package/dist/recording/identity.d.ts.map +0 -1
  300. package/dist/recording/identity.js +0 -2
  301. package/dist/recording/identity.js.map +0 -1
  302. package/dist/recording/index.d.ts +0 -11
  303. package/dist/recording/index.d.ts.map +0 -1
  304. package/dist/recording/index.js +0 -2
  305. package/dist/recording/index.js.map +0 -1
  306. package/dist/recording/noop-emitter.d.ts +0 -23
  307. package/dist/recording/noop-emitter.d.ts.map +0 -1
  308. package/dist/recording/noop-emitter.js +0 -22
  309. package/dist/recording/noop-emitter.js.map +0 -1
  310. package/dist/recording/otel/attributes.d.ts +0 -35
  311. package/dist/recording/otel/attributes.d.ts.map +0 -1
  312. package/dist/recording/otel/attributes.js +0 -131
  313. package/dist/recording/otel/attributes.js.map +0 -1
  314. package/dist/recording/otel/constants.d.ts +0 -123
  315. package/dist/recording/otel/constants.d.ts.map +0 -1
  316. package/dist/recording/otel/constants.js +0 -172
  317. package/dist/recording/otel/constants.js.map +0 -1
  318. package/dist/recording/otel/ids.d.ts +0 -25
  319. package/dist/recording/otel/ids.d.ts.map +0 -1
  320. package/dist/recording/otel/ids.js +0 -37
  321. package/dist/recording/otel/ids.js.map +0 -1
  322. package/dist/recording/otel/index.d.ts +0 -13
  323. package/dist/recording/otel/index.d.ts.map +0 -1
  324. package/dist/recording/otel/index.js +0 -9
  325. package/dist/recording/otel/index.js.map +0 -1
  326. package/dist/recording/otel/mappers.d.ts +0 -100
  327. package/dist/recording/otel/mappers.d.ts.map +0 -1
  328. package/dist/recording/otel/mappers.js +0 -683
  329. package/dist/recording/otel/mappers.js.map +0 -1
  330. package/dist/recording/otel/otel-emitter.d.ts +0 -43
  331. package/dist/recording/otel/otel-emitter.d.ts.map +0 -1
  332. package/dist/recording/otel/otel-emitter.js +0 -99
  333. package/dist/recording/otel/otel-emitter.js.map +0 -1
  334. package/dist/recording/otel/redaction.d.ts +0 -47
  335. package/dist/recording/otel/redaction.d.ts.map +0 -1
  336. package/dist/recording/otel/redaction.js +0 -88
  337. package/dist/recording/otel/redaction.js.map +0 -1
  338. package/dist/recording/records.d.ts.map +0 -1
  339. package/dist/recording/records.js +0 -14
  340. package/dist/recording/records.js.map +0 -1
  341. package/dist/recording/transport/batcher.d.ts +0 -59
  342. package/dist/recording/transport/batcher.d.ts.map +0 -1
  343. package/dist/recording/transport/batcher.js +0 -234
  344. package/dist/recording/transport/batcher.js.map +0 -1
  345. package/dist/recording/transport/client.d.ts +0 -41
  346. package/dist/recording/transport/client.d.ts.map +0 -1
  347. package/dist/recording/transport/client.js +0 -69
  348. package/dist/recording/transport/client.js.map +0 -1
  349. package/dist/recording/transport/config.d.ts +0 -53
  350. package/dist/recording/transport/config.d.ts.map +0 -1
  351. package/dist/recording/transport/config.js +0 -41
  352. package/dist/recording/transport/config.js.map +0 -1
  353. package/dist/recording/transport/index.d.ts +0 -16
  354. package/dist/recording/transport/index.d.ts.map +0 -1
  355. package/dist/recording/transport/index.js +0 -12
  356. package/dist/recording/transport/index.js.map +0 -1
  357. package/dist/recording/transport/rows.d.ts +0 -88
  358. package/dist/recording/transport/rows.d.ts.map +0 -1
  359. package/dist/recording/transport/rows.js +0 -15
  360. package/dist/recording/transport/rows.js.map +0 -1
  361. package/dist/recording/wiring/emitter-factory.d.ts +0 -39
  362. package/dist/recording/wiring/emitter-factory.d.ts.map +0 -1
  363. package/dist/recording/wiring/emitter-factory.js +0 -62
  364. package/dist/recording/wiring/emitter-factory.js.map +0 -1
  365. package/dist/recording/wiring/identity.d.ts +0 -27
  366. package/dist/recording/wiring/identity.d.ts.map +0 -1
  367. package/dist/recording/wiring/identity.js.map +0 -1
  368. package/dist/recording/wiring/index.d.ts +0 -12
  369. package/dist/recording/wiring/index.d.ts.map +0 -1
  370. package/dist/recording/wiring/index.js +0 -9
  371. package/dist/recording/wiring/index.js.map +0 -1
  372. package/dist/recording/wiring/record-builders.d.ts +0 -107
  373. package/dist/recording/wiring/record-builders.d.ts.map +0 -1
  374. package/dist/recording/wiring/record-builders.js.map +0 -1
  375. package/dist/recording/wiring/subscriber.d.ts +0 -28
  376. package/dist/recording/wiring/subscriber.d.ts.map +0 -1
  377. package/dist/recording/wiring/subscriber.js +0 -173
  378. package/dist/recording/wiring/subscriber.js.map +0 -1
  379. package/dist/recording/wiring/values.d.ts +0 -19
  380. package/dist/recording/wiring/values.d.ts.map +0 -1
  381. package/dist/recording/wiring/values.js +0 -49
  382. package/dist/recording/wiring/values.js.map +0 -1
  383. package/dist/tracking/build-rehydrate-items.d.ts +0 -15
  384. package/dist/tracking/build-rehydrate-items.d.ts.map +0 -1
  385. package/dist/tracking/build-rehydrate-items.js +0 -19
  386. package/dist/tracking/build-rehydrate-items.js.map +0 -1
  387. package/dist/tracking/constants.d.ts +0 -24
  388. package/dist/tracking/constants.d.ts.map +0 -1
  389. package/dist/tracking/constants.js +0 -52
  390. package/dist/tracking/constants.js.map +0 -1
  391. package/dist/tracking/context.d.ts.map +0 -1
  392. package/dist/tracking/context.js.map +0 -1
  393. package/dist/tracking/index.d.ts +0 -16
  394. package/dist/tracking/index.d.ts.map +0 -1
  395. package/dist/tracking/index.js +0 -11
  396. package/dist/tracking/index.js.map +0 -1
  397. package/dist/tracking/plugin-event-tracker.d.ts +0 -13
  398. package/dist/tracking/plugin-event-tracker.d.ts.map +0 -1
  399. package/dist/tracking/plugin-event-tracker.js +0 -27
  400. package/dist/tracking/plugin-event-tracker.js.map +0 -1
  401. package/dist/tracking/position-id-registry.d.ts.map +0 -1
  402. package/dist/tracking/position-id-registry.js.map +0 -1
  403. package/dist/tracking/spans/constants.d.ts +0 -19
  404. package/dist/tracking/spans/constants.d.ts.map +0 -1
  405. package/dist/tracking/spans/constants.js +0 -31
  406. package/dist/tracking/spans/constants.js.map +0 -1
  407. package/dist/tracking/spans/fan-out-span-transport.d.ts +0 -22
  408. package/dist/tracking/spans/fan-out-span-transport.d.ts.map +0 -1
  409. package/dist/tracking/spans/fan-out-span-transport.js +0 -49
  410. package/dist/tracking/spans/fan-out-span-transport.js.map +0 -1
  411. package/dist/tracking/spans/index.d.ts +0 -13
  412. package/dist/tracking/spans/index.d.ts.map +0 -1
  413. package/dist/tracking/spans/index.js +0 -16
  414. package/dist/tracking/spans/index.js.map +0 -1
  415. package/dist/tracking/spans/otel/fit-row-budget.d.ts +0 -22
  416. package/dist/tracking/spans/otel/fit-row-budget.d.ts.map +0 -1
  417. package/dist/tracking/spans/otel/fit-row-budget.js +0 -91
  418. package/dist/tracking/spans/otel/fit-row-budget.js.map +0 -1
  419. package/dist/tracking/spans/otel/map-span-to-trace-row.d.ts +0 -16
  420. package/dist/tracking/spans/otel/map-span-to-trace-row.d.ts.map +0 -1
  421. package/dist/tracking/spans/otel/map-span-to-trace-row.js +0 -227
  422. package/dist/tracking/spans/otel/map-span-to-trace-row.js.map +0 -1
  423. package/dist/tracking/spans/otel/recording-span-transport.d.ts +0 -43
  424. package/dist/tracking/spans/otel/recording-span-transport.d.ts.map +0 -1
  425. package/dist/tracking/spans/otel/recording-span-transport.js +0 -67
  426. package/dist/tracking/spans/otel/recording-span-transport.js.map +0 -1
  427. package/dist/tracking/spans/otel/span-ids.d.ts +0 -22
  428. package/dist/tracking/spans/otel/span-ids.d.ts.map +0 -1
  429. package/dist/tracking/spans/otel/span-ids.js +0 -32
  430. package/dist/tracking/spans/otel/span-ids.js.map +0 -1
  431. package/dist/tracking/spans/plugin-span-tracker.d.ts +0 -9
  432. package/dist/tracking/spans/plugin-span-tracker.d.ts.map +0 -1
  433. package/dist/tracking/spans/plugin-span-tracker.js +0 -115
  434. package/dist/tracking/spans/plugin-span-tracker.js.map +0 -1
  435. package/dist/tracking/spans/redact-pii.d.ts.map +0 -1
  436. package/dist/tracking/spans/redact-pii.js.map +0 -1
  437. package/dist/tracking/spans/sanitize-payload.d.ts.map +0 -1
  438. package/dist/tracking/spans/sanitize-payload.js.map +0 -1
  439. package/dist/tracking/spans/span-hooks.d.ts +0 -28
  440. package/dist/tracking/spans/span-hooks.d.ts.map +0 -1
  441. package/dist/tracking/spans/span-hooks.js +0 -409
  442. package/dist/tracking/spans/span-hooks.js.map +0 -1
  443. package/dist/tracking/spans/span-tracker.d.ts +0 -133
  444. package/dist/tracking/spans/span-tracker.d.ts.map +0 -1
  445. package/dist/tracking/spans/span-tracker.js +0 -721
  446. package/dist/tracking/spans/span-tracker.js.map +0 -1
  447. package/dist/tracking/spans/span-transport.d.ts +0 -71
  448. package/dist/tracking/spans/span-transport.d.ts.map +0 -1
  449. package/dist/tracking/spans/span-transport.js +0 -240
  450. package/dist/tracking/spans/span-transport.js.map +0 -1
  451. package/dist/tracking/spans/types.d.ts +0 -101
  452. package/dist/tracking/spans/types.d.ts.map +0 -1
  453. package/dist/tracking/spans/types.js +0 -6
  454. package/dist/tracking/spans/types.js.map +0 -1
  455. package/dist/tracking/tracker.d.ts +0 -30
  456. package/dist/tracking/tracker.d.ts.map +0 -1
  457. package/dist/tracking/tracker.js +0 -66
  458. package/dist/tracking/tracker.js.map +0 -1
  459. package/dist/tracking/tracking-handler.d.ts +0 -12
  460. package/dist/tracking/tracking-handler.d.ts.map +0 -1
  461. package/dist/tracking/tracking-handler.js +0 -148
  462. package/dist/tracking/tracking-handler.js.map +0 -1
  463. package/dist/tracking/transport.d.ts +0 -35
  464. package/dist/tracking/transport.d.ts.map +0 -1
  465. package/dist/tracking/transport.js +0 -133
  466. package/dist/tracking/transport.js.map +0 -1
  467. package/dist/tracking/types.d.ts +0 -21
  468. package/dist/tracking/types.d.ts.map +0 -1
  469. package/dist/tracking/types.js +0 -6
  470. package/dist/tracking/types.js.map +0 -1
  471. /package/dist/{tracking → telemetry}/spans/sanitize-payload.d.ts +0 -0
  472. /package/dist/{tracking → telemetry}/spans/sanitize-payload.js +0 -0
@@ -1,15 +1,33 @@
1
1
  /**
2
- * Recording contract — the record types the runtime hands to a {@link RecordingEmitter}, covering
3
- * domain events and runtime errors.
2
+ * Event contract types + pure builders: bus-event payloads → telemetry records.
4
3
  *
5
4
  * Each record is one atomic "work unit": plain, immutable, serializable data with no methods or
6
5
  * builder dance; variants are modelled with a discriminator field plus optionals. The types are
7
6
  * transport-agnostic — nothing here knows about spans, attributes, or any wire format.
8
7
  *
9
- * Identity (service, recipe, runtime, strategy address, boot id) is stamped by the emitter and is
10
- * never on a record — see {@link IdentityEnvelope}. Timestamps are epoch milliseconds; ISO strings
11
- * from the bus are converted before they reach a record, so consumers never parse dates.
8
+ * The builders read a loosely-typed payload defensively (the `asObject`/`str`/`num`/`bool`/
9
+ * `toEpochMs` helpers below) and return a fully-populated record (or `null` when the event cannot
10
+ * yield one). Redaction is NOT done here — records are populated faithfully; a downstream mapper is
11
+ * the single redaction seam.
12
+ *
13
+ * Identity (service, recipe, runtime, strategy address, boot id) is stamped by the identity layer
14
+ * and is never on a record — see {@link IdentityEnvelope}. Timestamps are epoch milliseconds; ISO
15
+ * strings (and, for a scan result, an epoch-ms number) from the bus are converted once here, so
16
+ * consumers never parse dates.
17
+ */
18
+ /** A plain object, or `undefined` for anything else (null, array, primitive). */
19
+ export declare function asObject(value: unknown): Record<string, unknown> | undefined;
20
+ /** A non-empty string, or `undefined`. */
21
+ export declare function str(value: unknown): string | undefined;
22
+ /** A finite number, coercing numeric strings; `undefined` otherwise. */
23
+ export declare function num(value: unknown): number | undefined;
24
+ /** A boolean, or `undefined` (so absence stays distinct from `false`). */
25
+ export declare function bool(value: unknown): boolean | undefined;
26
+ /**
27
+ * ISO string or epoch-ms number → epoch ms. Falls back to `fallbackMs` when the value is missing
28
+ * or unparseable, so a record always carries a usable timestamp instead of `NaN`.
12
29
  */
30
+ export declare function toEpochMs(value: unknown, fallbackMs: number): number;
13
31
  /**
14
32
  * Trade direction as the bus reports it. The alias itself is non-null; sites that admit a
15
33
  * non-directional signal widen it to `TradeDirection | null` (e.g. {@link SignalSummary}).
@@ -36,7 +54,7 @@ export type ScannerRunOutcome = "complete" | "skipped" | "error";
36
54
  * One scanner execution attempt (the work unit). Folds the bus's `scanner:run:start` +
37
55
  * terminal `scanner:run:{complete,skip,error}` events into a single atomic record so a
38
56
  * duration is always derivable (`endedAt - startedAt`). Skip/error early-exit paths can
39
- * terminate without a paired `scanner:run:start` event; in that case Task 4 fills `startedAt`
57
+ * terminate without a paired `scanner:run:start` event; in that case `startedAt` is filled
40
58
  * with the run's attempt timestamp (which equals `endedAt`), so duration is 0 rather than absent.
41
59
  * The skipped/disabled distinction lives on `outcome`/`statusDetail`, not on a missing start.
42
60
  */
@@ -49,8 +67,8 @@ export interface ScannerRunRecord {
49
67
  /** Raw engine status: `ok`|`heartbeat`|`skipped`|`halted`|`disabled`|`error`. */
50
68
  readonly statusDetail?: string;
51
69
  /**
52
- * Run start, epoch ms (from `scanner:run:start`). Required: on a no-start early-exit path Task 4
53
- * sets it to the attempt timestamp (= `endedAt`), so a `Duration` is always derivable.
70
+ * Run start, epoch ms (from `scanner:run:start`). Required: on a no-start early-exit path it is
71
+ * set to the attempt timestamp (= `endedAt`), so a `Duration` is always derivable.
54
72
  */
55
73
  readonly startedAt: number;
56
74
  /** Run completion, epoch ms (terminal event timestamp). */
@@ -68,7 +86,7 @@ export interface ScannerRunRecord {
68
86
  /** Error class name (`Error.name`) when `outcome === "error"` — the error-grouping key. */
69
87
  readonly errorName?: string;
70
88
  }
71
- /** How the decision was produced (`emitTrackingDecision` reports this). */
89
+ /** How the decision was produced. */
72
90
  export type DecisionMode = "llm" | "script" | "agent" | "rule" | "none";
73
91
  /** Decision produced by the decision layer for an evaluation pass. */
74
92
  export interface SignalDecision {
@@ -87,8 +105,6 @@ export interface SignalDecision {
87
105
  readonly model?: string;
88
106
  readonly tokensUsed?: number | null;
89
107
  readonly durationMs?: number;
90
- /** Epoch ms when the decision phase ended — the llm.decision child's end; its window is `[endedAt − durationMs, endedAt]`. */
91
- readonly endedAt?: number;
92
108
  }
93
109
  /** Coarse result of acting on an evaluated signal. */
94
110
  export type SignalOutcomeResult = "executed" | "rejected" | "skipped" | "below_confidence" | "error";
@@ -122,6 +138,10 @@ export interface SignalOutcome {
122
138
  readonly errorName?: string;
123
139
  readonly leverage?: number;
124
140
  readonly marginAmount?: number;
141
+ /** Which precedence rule sized the margin (the {@link MarginSource} breadcrumb). */
142
+ readonly marginSource?: string;
143
+ /** Applied percent of withdrawable — present only for the percent-based margin sources. */
144
+ readonly marginPct?: number;
125
145
  readonly notionalValue?: number;
126
146
  readonly orderId?: string;
127
147
  readonly entryPrice?: number;
@@ -215,7 +235,7 @@ export interface PositionLifecycleRecord {
215
235
  * Externally-detected vs runtime-opened discriminator (`"runtime_opened"` |
216
236
  * `"externally_detected"`), from the PositionIdRegistry's intent-vs-fresh mint observation.
217
237
  * Populated on `opened` only (the registry surfaces it solely on confirm-open); absent on every
218
- * other lifecycle event. See the Task 8a impl notes.
238
+ * other lifecycle event.
219
239
  */
220
240
  readonly reconciliationSource?: string;
221
241
  }
@@ -410,14 +430,14 @@ export interface RuntimeStateRecord {
410
430
  export type DecisionActionIntent = "open" | "close" | "none";
411
431
  /**
412
432
  * The judgment over one evaluation pass, as a discrete log event (`decision.made`). Derived from
413
- * the same `tracking.action_result` path that builds {@link SignalEvaluatedRecord} — no new bus
414
- * event. The trace view keeps the decision on the `llm.decision` span; this is its logs-only twin so
433
+ * the same action-result payload that builds {@link SignalEvaluatedRecord}. The trace view keeps the
434
+ * decision on the `llm.decision` span; this is its logs-only twin so
415
435
  * a logs-only consumer (the self-learning agent) can read "what the strategy decided and why"
416
436
  * without walking spans.
417
437
  *
418
438
  * `reasoning` is the Body (uncapped free-text). Market-context fields (`fundingRegime`/
419
- * `marketRegime`/`markPrice`) are reserved keys: they are NOT on the `tracking.action_result`
420
- * payload today, so 8a leaves them undefined (absent = NULL) — see the Task 8a implementation notes.
439
+ * `marketRegime`/`markPrice`) are reserved keys: they are NOT on the action-result
440
+ * payload today, so they are left undefined (absent = NULL).
421
441
  */
422
442
  export interface DecisionMadeRecord {
423
443
  readonly type: "decision_made";
@@ -440,8 +460,8 @@ export interface DecisionMadeRecord {
440
460
  export type SignalOutcomeDisposition = "accepted" | "rejected" | "blocked" | "error";
441
461
  /**
442
462
  * One signal's disposition, as a discrete log event (`signal.outcome`). One per evaluation in the
443
- * pass, derived from the same `tracking.action_result` path that builds {@link SignalEvaluatedRecord}
444
- * — no new bus event. The four-value `result` collapses the granular per-signal
463
+ * pass, derived from the same action-result payload that builds {@link SignalEvaluatedRecord}.
464
+ * The four-value `result` collapses the granular per-signal
445
465
  * {@link SignalOutcomeResult}; the open `reasonCode` is kept verbatim for the fine-grained reason.
446
466
  *
447
467
  * `rawSignal` is the variable-shaped scanner evidence → the Body (redacted in the mapper). The
@@ -466,8 +486,10 @@ export interface SignalOutcomeRecord {
466
486
  readonly leverage?: number;
467
487
  readonly notionalValue?: number;
468
488
  readonly size?: number;
469
- /** Reserved — unpopulated in 8a (not on the payload; see impl notes). */
489
+ /** Which precedence rule sized the margin (the {@link MarginSource} breadcrumb). */
470
490
  readonly marginSource?: string;
491
+ /** Applied percent of withdrawable — present only for the percent-based margin sources. */
492
+ readonly marginPct?: number;
471
493
  readonly orderId?: string;
472
494
  readonly errorName?: string;
473
495
  /** The raw scanner signal payload (incl. its `meta`/`factors`) → the Body, redacted in the mapper. */
@@ -475,11 +497,11 @@ export interface SignalOutcomeRecord {
475
497
  }
476
498
  /**
477
499
  * One DSL exit attempt as a discrete log event (`dsl.close_attempt`) — exit attempts / venue
478
- * failures / retries, span-only today. Derived from the existing `tracking.dsl_close_attempt` event
500
+ * failures / retries, span-only today. Derived from the DSL close-attempt payload
479
501
  * (already consumed to build the {@link DslTickRecord} trace) — a second consumer for the log.
480
502
  *
481
503
  * No `errorName`: only `String(e)` is available at the producer emit site, so the error class name
482
- * is omitted (see the Task 8a impl notes).
504
+ * is omitted.
483
505
  */
484
506
  export interface DslCloseAttemptRecord {
485
507
  readonly type: "dsl_close_attempt";
@@ -495,8 +517,8 @@ export interface DslCloseAttemptRecord {
495
517
  }
496
518
  /**
497
519
  * One scan's funnel summary as a discrete log event (`scanner.summary`) — the anti-spam roll-up of
498
- * what a scan considered and dropped. Derived from the SAME `tracking.scanner_run` payload that
499
- * builds {@link ScannerRunRecord} (its `summary.funnel`), so no new bus event. One row per scan: the
520
+ * what a scan considered and dropped. Derived from the SAME scanner-run payload that
521
+ * builds {@link ScannerRunRecord} (its `summary.funnel`). One row per scan: the
500
522
  * dropped candidates are ONE Body array, never one row per drop.
501
523
  *
502
524
  * `passedAssets` is a small linkage list (the survivors, each detailed by its own `signal.outcome`);
@@ -524,15 +546,14 @@ export type OrderEventKind = "placed" | "filled" | "failed";
524
546
  * One order-execution event as a discrete log event (`order.{placed,filled,failed}`) — the venue
525
547
  * execution granularity (placement vs fill, maker/taker, venue rejects) that the position-level
526
548
  * `position_lifecycle` event can't carry. Emitted additively by the open/close actions at the
527
- * submit/success/failure points (the new `tracking.order_*` bus events). `event` discriminates which
549
+ * submit/success/failure points. `event` discriminates which
528
550
  * optional fields apply.
529
551
  *
530
552
  * Overlap with `position_lifecycle.opened`/`.closed` is intentional: the lifecycle event is the
531
553
  * settled position-level fact; `order.*` is the execution-level fact. Both are emitted; no dedupe.
532
554
  *
533
- * `limitPrice`/`fees`/`partial` are reserved-but-unpopulated in 8a — they are not in scope at the
534
- * action's submission point (see the Task 8a impl notes). `error` on `failed` is the optional venue
535
- * raw response → the Body.
555
+ * `limitPrice`/`fees`/`partial` are reserved-but-unpopulated — they are not in scope at the action's
556
+ * submission point. `error` on `failed` is the optional venue raw response → the Body.
536
557
  */
537
558
  export interface OrderEventRecord {
538
559
  readonly type: "order_event";
@@ -545,21 +566,112 @@ export interface OrderEventRecord {
545
566
  readonly direction?: TradeDirection | null;
546
567
  readonly orderType?: string;
547
568
  readonly size?: number;
548
- /** Reserved — unpopulated in 8a (not in scope at the submission point; see impl notes). */
569
+ /** Reserved — unpopulated (not in scope at the submission point). */
549
570
  readonly limitPrice?: number;
550
571
  readonly reduceOnly?: boolean;
551
572
  readonly fillPrice?: number;
552
573
  readonly fillSize?: number;
553
574
  readonly executionAsMaker?: boolean | null;
554
- /** Reserved — unpopulated in 8a (not in scope; see impl notes). */
575
+ /** Reserved — unpopulated (not in scope). */
555
576
  readonly fees?: number;
556
- /** Reserved — unpopulated in 8a (not in scope; see impl notes). */
577
+ /** Reserved — unpopulated (not in scope). */
557
578
  readonly partial?: boolean;
558
579
  readonly reason?: string;
559
580
  readonly errorName?: string;
560
581
  /** The optional venue raw response on `failed` → the Body. */
561
582
  readonly error?: string;
562
583
  }
563
- /** Discriminated union of every record type. */
564
- export type RecordingRecord = ScannerRunRecord | SignalEvaluatedRecord | PositionLifecycleRecord | DslTransitionRecord | DslTickRecord | RuntimeErrorRecord | RuntimeLifecycleRecord | RuntimeStateRecord | DecisionMadeRecord | SignalOutcomeRecord | ScannerSummaryRecord | DslCloseAttemptRecord | OrderEventRecord;
565
- //# sourceMappingURL=records.d.ts.map
584
+ /** From a scanner-run payload (complete / skipped / error): complete runs carry the whole
585
+ * `ScanResult`; skip/error carry status + reason. */
586
+ export declare function buildScannerRun(payload: unknown, nowMs: number): ScannerRunRecord | null;
587
+ /**
588
+ * The `scanner.summary` anti-spam log record, derived from the SAME scanner-run payload
589
+ * that {@link buildScannerRun} reads (its `data.summary.funnel.dropped`).
590
+ *
591
+ * Returns `null` when there is no `data.summary.funnel`: skip/error runs and scanners without a
592
+ * funnel produce no summary event (the survivors are detailed by their own `signal.outcome` events,
593
+ * and "didn't run at all" is `scanner_run.skipped`). One record per scan; the dropped candidates are
594
+ * one Body array, never one row per drop.
595
+ */
596
+ export declare function buildScannerSummary(payload: unknown, nowMs: number): ScannerSummaryRecord | null;
597
+ /**
598
+ * Read-only position.id lookup, (address, dex, asset) → the live id or undefined. Injected by
599
+ * the runtime as a narrow accessor over the PositionIdRegistry — the registry is the single
600
+ * source of truth; builders never receive the registry (or RuntimeContext) itself.
601
+ */
602
+ export type PositionIdResolver = (address: string, dex: string, asset: string) => string | undefined;
603
+ /**
604
+ * Build the whole pass record from an action-result payload alone — the producers echo the scan
605
+ * provenance onto the payload (`scannerId`, `scannerSignals`, `minConfidence`, `runId`), and the
606
+ * decision itself rides `result.data._decisionMeta`, so no pairing is needed.
607
+ *
608
+ * `evaluations` is one entry per per-signal result, each enriched with the matching input signal
609
+ * (or a summary synthesized from the result entry when none matches — e.g. close-position's
610
+ * static-params path, which carries no `scannerSignals`). A pass without `_decisionMeta` yields no
611
+ * `decision` (the contract allows a decision-less pass).
612
+ *
613
+ * The pass window is a point anchored at the action-result timestamp (`startedAt === endedAt`); the
614
+ * decision's own `durationMs` (from `_decisionMeta`) carries the timing.
615
+ */
616
+ export declare function buildSignalEvaluated(actionResultPayload: unknown, nowMs: number, resolvePositionId?: PositionIdResolver): SignalEvaluatedRecord | null;
617
+ /**
618
+ * The pass's `decision.made` log record, derived from the built pass record — `null` when the pass
619
+ * carried no decision (a decision-less pass yields no judgment event). One per pass.
620
+ */
621
+ export declare function buildDecisionMade(record: SignalEvaluatedRecord): DecisionMadeRecord | null;
622
+ /**
623
+ * One `signal.outcome` log record per evaluation in the pass, derived from the built pass record.
624
+ * `rawSignal` is the evaluation's {@link SignalSummary} (incl. its `meta`/`factors`) — the variable
625
+ * scanner evidence; redaction over it happens in the mapper, not here.
626
+ */
627
+ export declare function buildSignalOutcomes(record: SignalEvaluatedRecord): SignalOutcomeRecord[];
628
+ /**
629
+ * From the DSL close-attempt monitor payload — the second consumer (alongside the
630
+ * tick trace). Fields at the payload root: `positionId`, `asset`, `dex`, `closeReason`, `attempt`,
631
+ * `outcome` ("ok"|"error"), `error`, ISO `timestamp`. `null` when the payload is not an object.
632
+ */
633
+ export declare function buildDslCloseAttempt(payload: unknown, nowMs: number): DslCloseAttemptRecord | null;
634
+ /**
635
+ * From the additive order events the open/close actions fire (the HookEvent shape:
636
+ * fields under a `data` envelope). One record per event; `eventKind` discriminates which fields the
637
+ * payload carries (placed: order/size; filled: fill; failed: reason/error). `positionId` maps from
638
+ * `__positionId`. `null` when no `asset` is resolvable — the asset is the one always-present scalar.
639
+ *
640
+ * Faithful population only (no redaction here — the mapper is the single redaction seam).
641
+ */
642
+ export declare function buildOrderEvent(eventKind: OrderEventKind, payload: unknown, nowMs: number): OrderEventRecord | null;
643
+ /**
644
+ * From an `on_position_*` event. Action-driven events arrive as HookEvents (fields under a `data`
645
+ * envelope); the DSL monitor / reconcile paths emit `on_position_closed` flat (fields at the root,
646
+ * always with an `asset`), so a flat payload carrying an `asset` is read as-is. The DSL archive
647
+ * handler's re-broadcast of a close is marked `source: "dsl_archive"` and skipped — the close it
648
+ * mirrors was already recorded from the original emit. (`on_open_order_submitted` is deliberately
649
+ * not recorded — its submit fact is already on the signal-evaluation view, avoiding a double count.)
650
+ */
651
+ export declare function buildPositionLifecycle(event: PositionLifecycleEvent, payload: unknown, nowMs: number): PositionLifecycleRecord | null;
652
+ /** From a `dsl.*` event (fields live at the payload root, with an ISO `timestamp`). */
653
+ export declare function buildDslTransition(transition: DslTransitionKind, payload: unknown, nowMs: number): DslTransitionRecord | null;
654
+ /**
655
+ * From the monitor's DSL tick / position / close-attempt / sl-update payloads (fields at the
656
+ * payload root). Each payload yields one record —
657
+ * the deterministic ids derived from `tickId` (and `tickId:positionKey`, both bootId-scoped by
658
+ * the mapper) thread them into one trace, so no pairing is needed here. Essentials are `tickId`
659
+ * plus a numeric work window; on clock skew (`endedAt < startedAt`) the start is pulled up to the
660
+ * end, matching the pass-window convention. The price-fetch window is kept only when both stamps
661
+ * are present (a half window is fabricated extent). No `nowMs` fallback: work windows are
662
+ * producer-stamped; nothing here is fabricated.
663
+ */
664
+ export declare function buildDslTick(unit: DslTickUnit, payload: unknown): DslTickRecord | null;
665
+ /** From `signal_processing_error` — a bucket-2 error with no specific domain record home. */
666
+ export declare function buildRuntimeError(payload: unknown, nowMs: number): RuntimeErrorRecord | null;
667
+ /**
668
+ * From the runtime-started payload. The `config` blob is the injected **unresolved** config (not the
669
+ * resolved `data.config`): resolving inlines secrets, and the unresolved form is what the
670
+ * `configHash` is computed over, so blob and hash agree.
671
+ */
672
+ export declare function buildRuntimeStarted(payload: unknown, unresolvedConfig: Record<string, unknown> | undefined, nowMs: number): RuntimeLifecycleRecord | null;
673
+ /** From the runtime-stopped payload. */
674
+ export declare function buildRuntimeStopped(payload: unknown, nowMs: number): RuntimeLifecycleRecord | null;
675
+ /** From the self-pause HookEvents (`on_strategy_self_paused`/`on_daily_limit_hit`/`on_drawdown_cap_hit`). */
676
+ export declare function buildRuntimePaused(payload: unknown, fallbackGateId: string, nowMs: number): RuntimeStateRecord | null;
677
+ //# sourceMappingURL=event-builders.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-builders.d.ts","sourceRoot":"","sources":["../../src/telemetry/event-builders.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAOH,iFAAiF;AACjF,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAK5E;AAED,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OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,mBAAmB,GAAG,IAAI,CAgD7H;AASD;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,GAAG,aAAa,GAAG,IAAI,CAkCtF;AAID,6FAA6F;AAC7F,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,kBAAkB,GAAG,IAAI,CA2B5F;AAID;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,sBAAsB,GAAG,IAAI,CAczJ;AAED,wCAAwC;AACxC,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,sBAAsB,GAAG,IAAI,CAWlG;AAID,6GAA6G;AAC7G,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,kBAAkB,GAAG,IAAI,CAcrH"}
@@ -1,13 +1,70 @@
1
1
  /**
2
- * Pure builders: bus-event payloads → recording records. No I/O, no emitter — each function reads a
3
- * loosely-typed payload defensively and returns a fully-populated record (or `null` when the event
4
- * cannot yield one). Redaction is NOT done here — records are populated faithfully; the mapper is the
5
- * single redaction seam.
2
+ * Event contract types + pure builders: bus-event payloads → telemetry records.
6
3
  *
7
- * Timestamps: the bus carries ISO strings (and, for a scan result, an epoch-ms number); every record
8
- * stores epoch ms, converted once here.
4
+ * Each record is one atomic "work unit": plain, immutable, serializable data with no methods or
5
+ * builder dance; variants are modelled with a discriminator field plus optionals. The types are
6
+ * transport-agnostic — nothing here knows about spans, attributes, or any wire format.
7
+ *
8
+ * The builders read a loosely-typed payload defensively (the `asObject`/`str`/`num`/`bool`/
9
+ * `toEpochMs` helpers below) and return a fully-populated record (or `null` when the event cannot
10
+ * yield one). Redaction is NOT done here — records are populated faithfully; a downstream mapper is
11
+ * the single redaction seam.
12
+ *
13
+ * Identity (service, recipe, runtime, strategy address, boot id) is stamped by the identity layer
14
+ * and is never on a record — see {@link IdentityEnvelope}. Timestamps are epoch milliseconds; ISO
15
+ * strings (and, for a scan result, an epoch-ms number) from the bus are converted once here, so
16
+ * consumers never parse dates.
9
17
  */
10
- import { asObject, bool, num, str, toEpochMs } from "./values.js";
18
+ // ─── Defensive payload readers ─────────────────────────────────────────────────
19
+ //
20
+ // The builders read loosely-typed event data and must never throw while doing so, so every accessor
21
+ // coerces or returns `undefined` rather than trusting a shape.
22
+ /** A plain object, or `undefined` for anything else (null, array, primitive). */
23
+ export function asObject(value) {
24
+ if (value !== null && typeof value === "object" && !Array.isArray(value)) {
25
+ return value;
26
+ }
27
+ return undefined;
28
+ }
29
+ /** A non-empty string, or `undefined`. */
30
+ export function str(value) {
31
+ return typeof value === "string" && value.length > 0 ? value : undefined;
32
+ }
33
+ /** A finite number, coercing numeric strings; `undefined` otherwise. */
34
+ export function num(value) {
35
+ if (typeof value === "number")
36
+ return Number.isFinite(value) ? value : undefined;
37
+ if (typeof value === "string" && value.trim() !== "") {
38
+ const n = Number(value);
39
+ return Number.isFinite(n) ? n : undefined;
40
+ }
41
+ return undefined;
42
+ }
43
+ /** A boolean, or `undefined` (so absence stays distinct from `false`). */
44
+ export function bool(value) {
45
+ return typeof value === "boolean" ? value : undefined;
46
+ }
47
+ /**
48
+ * ISO string or epoch-ms number → epoch ms. Falls back to `fallbackMs` when the value is missing
49
+ * or unparseable, so a record always carries a usable timestamp instead of `NaN`.
50
+ */
51
+ export function toEpochMs(value, fallbackMs) {
52
+ if (typeof value === "number")
53
+ return Number.isFinite(value) ? value : fallbackMs;
54
+ if (typeof value === "string") {
55
+ // A purely-numeric string is epoch ms, not a date to parse (Date.parse would mangle it).
56
+ if (/^-?\d+$/.test(value.trim())) {
57
+ const n = Number(value);
58
+ return Number.isFinite(n) ? n : fallbackMs;
59
+ }
60
+ const ms = Date.parse(value);
61
+ return Number.isNaN(ms) ? fallbackMs : ms;
62
+ }
63
+ return fallbackMs;
64
+ }
65
+ // ════════════════════════════════════════════════════════════════════════════════
66
+ // Pure builders: bus-event payloads → records
67
+ // ════════════════════════════════════════════════════════════════════════════════
11
68
  /** `"LONG"`/`"SHORT"` → {@link TradeDirection}, else `null` (non-directional). */
12
69
  function direction(value) {
13
70
  return value === "LONG" || value === "SHORT" ? value : null;
@@ -52,8 +109,8 @@ function buildSignalSummary(raw, fallbackTs) {
52
109
  meta: asObject(s.meta),
53
110
  };
54
111
  }
55
- /** From a `tracking.scanner_run` / `tracking.scanner_run_skipped` / `tracking.scanner_run_error`
56
- * event (complete runs carry the whole `ScanResult`; skip/error carry status + reason). */
112
+ /** From a scanner-run payload (complete / skipped / error): complete runs carry the whole
113
+ * `ScanResult`; skip/error carry status + reason. */
57
114
  export function buildScannerRun(payload, nowMs) {
58
115
  const p = asObject(payload);
59
116
  const data = asObject(p?.data);
@@ -85,10 +142,10 @@ export function buildScannerRun(payload, nowMs) {
85
142
  error: outcome === "error" ? str(data.reason) : undefined,
86
143
  };
87
144
  }
88
- // ─── Scanner funnel summary (Task 8a, derived from `tracking.scanner_run`) ────────
145
+ // ─── Scanner funnel summary (derived from the scanner-run payload) ────────
89
146
  /**
90
- * The `scanner.summary` anti-spam log record, derived from the SAME `tracking.scanner_run` payload
91
- * that {@link buildScannerRun} reads (its `data.summary.funnel.dropped`) — no new bus event.
147
+ * The `scanner.summary` anti-spam log record, derived from the SAME scanner-run payload
148
+ * that {@link buildScannerRun} reads (its `data.summary.funnel.dropped`).
92
149
  *
93
150
  * Returns `null` when there is no `data.summary.funnel`: skip/error runs and scanners without a
94
151
  * funnel produce no summary event (the survivors are detailed by their own `signal.outcome` events,
@@ -141,7 +198,7 @@ export function buildScannerSummary(payload, nowMs) {
141
198
  droppedCandidates: droppedCount > 0 ? droppedCandidates : undefined,
142
199
  };
143
200
  }
144
- // ─── Signal evaluation (single-sourced from `tracking.action_result`) ────────────
201
+ // ─── Signal evaluation (single-sourced from the action-result payload) ────────────
145
202
  /** Reason codes where the system evaluated a trade and actively blocked it (see {@link classifyOutcome}). */
146
203
  const REJECTED_REASONS = new Set(["insufficient_margin", "invalid_direction", "no_margin_configured", "below_min_notional"]);
147
204
  /** Reason codes where no trade was applicable / attempted. */
@@ -185,6 +242,8 @@ function buildOutcome(raw, positionId) {
185
242
  error,
186
243
  leverage: num(r.leverage),
187
244
  marginAmount: num(r.marginAmount),
245
+ marginSource: str(r.marginSource),
246
+ marginPct: num(r.marginPct),
188
247
  notionalValue: num(r.notionalValue),
189
248
  orderId: str(r.orderId),
190
249
  entryPrice: num(r.entryPrice),
@@ -195,7 +254,7 @@ function buildOutcome(raw, positionId) {
195
254
  availableMarginAmount: num(r.availableMarginAmount),
196
255
  };
197
256
  }
198
- /** The `data` envelope, embedded `result`, and per-signal `results[]` entries from a `tracking.action_result` payload. */
257
+ /** The `data` envelope, embedded `result`, and per-signal `results[]` entries from an action-result payload. */
199
258
  function actionResults(actionResultPayload) {
200
259
  const p = asObject(actionResultPayload);
201
260
  const data = asObject(p?.data);
@@ -204,7 +263,7 @@ function actionResults(actionResultPayload) {
204
263
  return { data, result, resultData, results: Array.isArray(resultData?.results) ? resultData.results : [] };
205
264
  }
206
265
  /**
207
- * The V2 stamping rule: every per-signal outcome that pertains to a real position — open,
266
+ * The stamping rule: every per-signal outcome that pertains to a real position — open,
208
267
  * just-submitted, or evaluated on a held asset (even when rejected/skipped) — carries that
209
268
  * position's id; only a signal on an asset with no live position resolves to nothing. The
210
269
  * lookup is deliberately unconditional on the outcome classification. The result entry's own
@@ -248,20 +307,17 @@ function buildEvaluations(results, findSignal, fallbackTs, resolvePositionId, ad
248
307
  });
249
308
  }
250
309
  /**
251
- * Build the whole pass record from a `tracking.action_result` payload alone — the producers echo
252
- * the decision window and scan provenance onto the payload (`scannerId`, `scannerSignals`,
253
- * `minConfidence`, `decisionStartedAt`, `decisionEndedAt`, `runId`), and the decision itself rides
254
- * `result.data._decisionMeta`, so no pairing with `tracking.decision` is needed.
310
+ * Build the whole pass record from an action-result payload alone — the producers echo the scan
311
+ * provenance onto the payload (`scannerId`, `scannerSignals`, `minConfidence`, `runId`), and the
312
+ * decision itself rides `result.data._decisionMeta`, so no pairing is needed.
255
313
  *
256
314
  * `evaluations` is one entry per per-signal result, each enriched with the matching input signal
257
315
  * (or a summary synthesized from the result entry when none matches — e.g. close-position's
258
316
  * static-params path, which carries no `scannerSignals`). A pass without `_decisionMeta` yields no
259
317
  * `decision` (the contract allows a decision-less pass).
260
318
  *
261
- * The pass span runs `decisionStartedAt` → action_result-ts; when the start stamp is absent
262
- * (defensive only — the bus is in-process) `startedAt = endedAt`. On clock skew
263
- * (`endedAt < startedAt`) the start is pulled up to `endedAt`, yielding a zero (never negative)
264
- * duration.
319
+ * The pass window is a point anchored at the action-result timestamp (`startedAt === endedAt`); the
320
+ * decision's own `durationMs` (from `_decisionMeta`) carries the timing.
265
321
  */
266
322
  export function buildSignalEvaluated(actionResultPayload, nowMs, resolvePositionId) {
267
323
  const { data, result, resultData, results } = actionResults(actionResultPayload);
@@ -269,9 +325,7 @@ export function buildSignalEvaluated(actionResultPayload, nowMs, resolvePosition
269
325
  return null;
270
326
  const p = asObject(actionResultPayload);
271
327
  const endedAt = toEpochMs(p?.timestamp, nowMs);
272
- let startedAt = num(data.decisionStartedAt) ?? endedAt;
273
- if (endedAt < startedAt)
274
- startedAt = endedAt;
328
+ const startedAt = endedAt;
275
329
  const signals = Array.isArray(data.scannerSignals)
276
330
  ? data.scannerSignals.map((s) => buildSignalSummary(s, startedAt))
277
331
  : [];
@@ -295,7 +349,6 @@ export function buildSignalEvaluated(actionResultPayload, nowMs, resolvePosition
295
349
  model: str(meta.model),
296
350
  tokensUsed: numOrNull(meta.tokensUsed),
297
351
  durationMs: num(meta.durationMs),
298
- endedAt: num(data.decisionEndedAt),
299
352
  }
300
353
  : undefined;
301
354
  return {
@@ -308,7 +361,7 @@ export function buildSignalEvaluated(actionResultPayload, nowMs, resolvePosition
308
361
  evaluations,
309
362
  };
310
363
  }
311
- // ─── Self-learning event log: decision.made + signal.outcome (Task 8) ─────────────
364
+ // ─── Self-learning event log: decision.made + signal.outcome ─────────────
312
365
  //
313
366
  // Both are DERIVED from the SAME built SignalEvaluatedRecord (single-source, DRY) — no re-parse of
314
367
  // the payload, no new bus event. The mapper does the redaction; these builders populate faithfully.
@@ -354,7 +407,7 @@ export function buildDecisionMade(record) {
354
407
  confidenceThreshold: d.confidenceThreshold,
355
408
  durationMs: d.durationMs,
356
409
  actionIntent: actionIntent(d.actionType),
357
- // Market context + marginSource are NOT on the payload today → left undefined (see impl notes).
410
+ // Market context is NOT on the payload today → left undefined.
358
411
  reasoning: d.reasoning,
359
412
  };
360
413
  }
@@ -380,23 +433,24 @@ export function buildSignalOutcomes(record) {
380
433
  reasonCode: outcome.reasonCode,
381
434
  positionId: outcome.positionId,
382
435
  marginAmount: outcome.marginAmount,
436
+ marginSource: outcome.marginSource,
437
+ marginPct: outcome.marginPct,
383
438
  leverage: outcome.leverage,
384
439
  notionalValue: outcome.notionalValue,
385
440
  size: outcome.size,
386
- // marginSource is NOT on the payload today → left undefined (see impl notes).
387
441
  orderId: outcome.orderId,
388
442
  errorName: outcome.errorName,
389
443
  rawSignal: { ...signal },
390
444
  };
391
445
  });
392
446
  }
393
- // ─── Self-learning event log: dsl.close_attempt (Task 8) ──────────────────────────
447
+ // ─── Self-learning event log: dsl.close_attempt ──────────────────────────
394
448
  /** Coerces the producer's outcome string to the close-attempt result enum; default `error`. */
395
449
  function closeAttemptResult(value) {
396
450
  return value === "ok" ? "ok" : "error";
397
451
  }
398
452
  /**
399
- * From the existing `tracking.dsl_close_attempt` monitor event — the second consumer (alongside the
453
+ * From the DSL close-attempt monitor payload — the second consumer (alongside the
400
454
  * tick trace). Fields at the payload root: `positionId`, `asset`, `dex`, `closeReason`, `attempt`,
401
455
  * `outcome` ("ok"|"error"), `error`, ISO `timestamp`. `null` when the payload is not an object.
402
456
  */
@@ -416,9 +470,9 @@ export function buildDslCloseAttempt(payload, nowMs) {
416
470
  error: str(p.error),
417
471
  };
418
472
  }
419
- // ─── Self-learning event log: order.{placed,filled,failed} (Task 8a) ──────────────
473
+ // ─── Self-learning event log: order.{placed,filled,failed} ────────────────
420
474
  /**
421
- * From the additive `tracking.order_*` events the open/close actions fire (the HookEvent shape:
475
+ * From the additive order events the open/close actions fire (the HookEvent shape:
422
476
  * fields under a `data` envelope). One record per event; `eventKind` discriminates which fields the
423
477
  * payload carries (placed: order/size; filled: fill; failed: reason/error). `positionId` maps from
424
478
  * `__positionId`. `null` when no `asset` is resolvable — the asset is the one always-present scalar.
@@ -570,8 +624,8 @@ function dslTickOutcome(value) {
570
624
  return value === "ok" || value === "error" ? value : undefined;
571
625
  }
572
626
  /**
573
- * From the monitor's `tracking.dsl_tick` / `tracking.dsl_position` / `tracking.dsl_close_attempt`
574
- * / `tracking.dsl_sl_update` events (fields at the payload root). Each event yields one record —
627
+ * From the monitor's DSL tick / position / close-attempt / sl-update payloads (fields at the
628
+ * payload root). Each payload yields one record —
575
629
  * the deterministic ids derived from `tickId` (and `tickId:positionKey`, both bootId-scoped by
576
630
  * the mapper) thread them into one trace, so no pairing is needed here. Essentials are `tickId`
577
631
  * plus a numeric work window; on clock skew (`endedAt < startedAt`) the start is pulled up to the
@@ -651,8 +705,8 @@ export function buildRuntimeError(payload, nowMs) {
651
705
  }
652
706
  // ─── Runtime lifecycle ───────────────────────────────────────────────────────
653
707
  /**
654
- * From `tracking.runtime_started`. The `config` blob is the injected **unresolved** config (not the
655
- * resolved `data.config` on the bus): resolving inlines secrets, and the unresolved form is what the
708
+ * From the runtime-started payload. The `config` blob is the injected **unresolved** config (not the
709
+ * resolved `data.config`): resolving inlines secrets, and the unresolved form is what the
656
710
  * `configHash` is computed over, so blob and hash agree.
657
711
  */
658
712
  export function buildRuntimeStarted(payload, unresolvedConfig, nowMs) {
@@ -671,7 +725,7 @@ export function buildRuntimeStarted(payload, unresolvedConfig, nowMs) {
671
725
  config: unresolvedConfig,
672
726
  };
673
727
  }
674
- /** From `tracking.runtime_stopped`. */
728
+ /** From the runtime-stopped payload. */
675
729
  export function buildRuntimeStopped(payload, nowMs) {
676
730
  const p = asObject(payload);
677
731
  const data = asObject(p?.data);
@@ -703,4 +757,4 @@ export function buildRuntimePaused(payload, fallbackGateId, nowMs) {
703
757
  metrics: asObject(data.metrics) ?? null,
704
758
  };
705
759
  }
706
- //# sourceMappingURL=record-builders.js.map
760
+ //# sourceMappingURL=event-builders.js.map