harnery 0.36.0 → 0.37.0

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 (311) hide show
  1. package/dist/commander.js +4 -0
  2. package/dist/commands/agents.d.ts.map +1 -1
  3. package/dist/commands/agents.js +87 -46
  4. package/dist/commands/artifacts.d.ts.map +1 -1
  5. package/dist/commands/artifacts.js +26 -1
  6. package/dist/commands/browse.d.ts.map +1 -1
  7. package/dist/commands/browse.js +11 -0
  8. package/dist/commands/diagnostics.d.ts +4 -0
  9. package/dist/commands/diagnostics.d.ts.map +1 -0
  10. package/dist/commands/diagnostics.js +229 -0
  11. package/dist/commands/files.d.ts +12 -0
  12. package/dist/commands/files.d.ts.map +1 -1
  13. package/dist/commands/files.js +54 -1
  14. package/dist/commands/governor.d.ts.map +1 -1
  15. package/dist/commands/governor.js +4 -0
  16. package/dist/commands/ledger-v3.d.ts.map +1 -1
  17. package/dist/commands/ledger-v3.js +71 -2
  18. package/dist/commands/qa-run.d.ts +4 -0
  19. package/dist/commands/qa-run.d.ts.map +1 -0
  20. package/dist/commands/qa-run.js +141 -0
  21. package/dist/commands/resources.d.ts +4 -0
  22. package/dist/commands/resources.d.ts.map +1 -0
  23. package/dist/commands/resources.js +29 -0
  24. package/dist/commands/supervisor.d.ts +4 -0
  25. package/dist/commands/supervisor.d.ts.map +1 -0
  26. package/dist/commands/supervisor.js +101 -0
  27. package/dist/commands/web.d.ts.map +1 -1
  28. package/dist/commands/web.js +17 -0
  29. package/dist/commands/workflow.d.ts.map +1 -1
  30. package/dist/commands/workflow.js +4 -0
  31. package/dist/core/agents/cli.js +7 -3
  32. package/dist/core/agents/health.d.ts +17 -0
  33. package/dist/core/agents/health.d.ts.map +1 -0
  34. package/dist/core/agents/health.js +109 -0
  35. package/dist/core/agents/mailbox.d.ts +92 -0
  36. package/dist/core/agents/mailbox.d.ts.map +1 -0
  37. package/dist/core/agents/mailbox.js +325 -0
  38. package/dist/core/agents/reconcile-coordination-v3.d.ts +44 -0
  39. package/dist/core/agents/reconcile-coordination-v3.d.ts.map +1 -0
  40. package/dist/core/agents/reconcile-coordination-v3.js +58 -0
  41. package/dist/core/agents/render/prompt-context.d.ts +5 -0
  42. package/dist/core/agents/render/prompt-context.d.ts.map +1 -1
  43. package/dist/core/agents/render/prompt-context.js +34 -13
  44. package/dist/core/agents/render/session-context.d.ts +8 -0
  45. package/dist/core/agents/render/session-context.d.ts.map +1 -1
  46. package/dist/core/agents/render/session-context.js +34 -3
  47. package/dist/core/agents/rules/commit-conflict.d.ts.map +1 -1
  48. package/dist/core/agents/rules/commit-conflict.js +50 -1
  49. package/dist/core/agents/rules/stop-hook.d.ts.map +1 -1
  50. package/dist/core/agents/rules/stop-hook.js +6 -10
  51. package/dist/core/agents/session-finalizer-v3.js +4 -1
  52. package/dist/core/artifacts/index.d.ts +26 -1
  53. package/dist/core/artifacts/index.d.ts.map +1 -1
  54. package/dist/core/artifacts/index.js +146 -6
  55. package/dist/core/config.d.ts +12 -0
  56. package/dist/core/config.d.ts.map +1 -1
  57. package/dist/core/config.js +43 -0
  58. package/dist/core/diagnostics/advice.d.ts +9 -0
  59. package/dist/core/diagnostics/advice.d.ts.map +1 -0
  60. package/dist/core/diagnostics/advice.js +112 -0
  61. package/dist/core/diagnostics/bundle.d.ts +35 -0
  62. package/dist/core/diagnostics/bundle.d.ts.map +1 -0
  63. package/dist/core/diagnostics/bundle.js +874 -0
  64. package/dist/core/diagnostics/comparison.d.ts +5 -0
  65. package/dist/core/diagnostics/comparison.d.ts.map +1 -0
  66. package/dist/core/diagnostics/comparison.js +444 -0
  67. package/dist/core/diagnostics/contract.d.ts +245 -0
  68. package/dist/core/diagnostics/contract.d.ts.map +1 -0
  69. package/dist/core/diagnostics/contract.js +18 -0
  70. package/dist/core/diagnostics/identity.d.ts +3 -0
  71. package/dist/core/diagnostics/identity.d.ts.map +1 -0
  72. package/dist/core/diagnostics/identity.js +10 -0
  73. package/dist/core/diagnostics/index.d.ts +8 -0
  74. package/dist/core/diagnostics/index.d.ts.map +1 -0
  75. package/dist/core/diagnostics/index.js +7 -0
  76. package/dist/core/diagnostics/replay.d.ts +8 -0
  77. package/dist/core/diagnostics/replay.d.ts.map +1 -0
  78. package/dist/core/diagnostics/replay.js +213 -0
  79. package/dist/core/diagnostics/sanitize.d.ts +9 -0
  80. package/dist/core/diagnostics/sanitize.d.ts.map +1 -0
  81. package/dist/core/diagnostics/sanitize.js +84 -0
  82. package/dist/core/events/legacy-storage/compression.d.ts +13 -0
  83. package/dist/core/events/legacy-storage/compression.d.ts.map +1 -0
  84. package/dist/core/events/legacy-storage/compression.js +107 -0
  85. package/dist/core/events/legacy-storage/index.d.ts +1 -0
  86. package/dist/core/events/legacy-storage/index.d.ts.map +1 -1
  87. package/dist/core/events/legacy-storage/index.js +1 -0
  88. package/dist/core/events/v3/archive-retention.d.ts +33 -0
  89. package/dist/core/events/v3/archive-retention.d.ts.map +1 -0
  90. package/dist/core/events/v3/archive-retention.js +195 -0
  91. package/dist/core/events/v3/capabilities.d.ts +1 -1
  92. package/dist/core/events/v3/capabilities.d.ts.map +1 -1
  93. package/dist/core/events/v3/capabilities.js +1 -0
  94. package/dist/core/events/v3/index.d.ts +1 -0
  95. package/dist/core/events/v3/index.d.ts.map +1 -1
  96. package/dist/core/events/v3/index.js +1 -0
  97. package/dist/core/events/v3/live-routing.d.ts.map +1 -1
  98. package/dist/core/events/v3/live-routing.js +1 -0
  99. package/dist/core/events/v3/producers/hook-base.d.ts +1 -1
  100. package/dist/core/events/v3/producers/hook-base.d.ts.map +1 -1
  101. package/dist/core/events/v3/producers/hook-base.js +13 -2
  102. package/dist/core/events/v3/producers/intake.d.ts.map +1 -1
  103. package/dist/core/events/v3/producers/intake.js +1 -0
  104. package/dist/core/events/v3/producers/recorder.d.ts +16 -0
  105. package/dist/core/events/v3/producers/recorder.d.ts.map +1 -1
  106. package/dist/core/events/v3/producers/recorder.js +88 -1
  107. package/dist/core/hooks/adapter/output.d.ts +8 -0
  108. package/dist/core/hooks/adapter/output.d.ts.map +1 -1
  109. package/dist/core/hooks/adapter/output.js +11 -1
  110. package/dist/core/hooks/cli.js +183 -192
  111. package/dist/core/hooks/health.d.ts +59 -0
  112. package/dist/core/hooks/health.d.ts.map +1 -0
  113. package/dist/core/hooks/health.js +84 -0
  114. package/dist/core/resources/contract.d.ts +90 -0
  115. package/dist/core/resources/contract.d.ts.map +1 -0
  116. package/dist/core/resources/contract.js +2 -0
  117. package/dist/core/resources/index.d.ts +6 -0
  118. package/dist/core/resources/index.d.ts.map +1 -0
  119. package/dist/core/resources/index.js +5 -0
  120. package/dist/core/resources/sampler.d.ts +27 -0
  121. package/dist/core/resources/sampler.d.ts.map +1 -0
  122. package/dist/core/resources/sampler.js +357 -0
  123. package/dist/core/resources/service-status.d.ts +3 -0
  124. package/dist/core/resources/service-status.d.ts.map +1 -0
  125. package/dist/core/resources/service-status.js +48 -0
  126. package/dist/core/resources/service.d.ts +26 -0
  127. package/dist/core/resources/service.d.ts.map +1 -0
  128. package/dist/core/resources/service.js +292 -0
  129. package/dist/core/resources/storage.d.ts +13 -0
  130. package/dist/core/resources/storage.d.ts.map +1 -0
  131. package/dist/core/resources/storage.js +30 -0
  132. package/dist/core/storage/atomic-json.d.ts +3 -0
  133. package/dist/core/storage/atomic-json.d.ts.map +1 -0
  134. package/dist/core/storage/atomic-json.js +15 -0
  135. package/dist/core/storage/builtins.d.ts.map +1 -1
  136. package/dist/core/storage/builtins.js +45 -6
  137. package/dist/core/storage/logger.d.ts +2 -0
  138. package/dist/core/storage/logger.d.ts.map +1 -1
  139. package/dist/core/storage/logger.js +2 -0
  140. package/dist/core/storage/query.d.ts +14 -0
  141. package/dist/core/storage/query.d.ts.map +1 -1
  142. package/dist/core/storage/query.js +51 -0
  143. package/dist/core/supervisor/activity.d.ts +4 -0
  144. package/dist/core/supervisor/activity.d.ts.map +1 -0
  145. package/dist/core/supervisor/activity.js +141 -0
  146. package/dist/core/supervisor/contract.d.ts +268 -0
  147. package/dist/core/supervisor/contract.d.ts.map +1 -0
  148. package/dist/core/supervisor/contract.js +35 -0
  149. package/dist/core/supervisor/explanations.d.ts +4 -0
  150. package/dist/core/supervisor/explanations.d.ts.map +1 -0
  151. package/dist/core/supervisor/explanations.js +71 -0
  152. package/dist/core/supervisor/findings.d.ts +20 -0
  153. package/dist/core/supervisor/findings.d.ts.map +1 -0
  154. package/dist/core/supervisor/findings.js +399 -0
  155. package/dist/core/supervisor/history.d.ts +9 -0
  156. package/dist/core/supervisor/history.d.ts.map +1 -0
  157. package/dist/core/supervisor/history.js +46 -0
  158. package/dist/core/supervisor/hook-health-alerts.d.ts +14 -0
  159. package/dist/core/supervisor/hook-health-alerts.d.ts.map +1 -0
  160. package/dist/core/supervisor/hook-health-alerts.js +70 -0
  161. package/dist/core/supervisor/hook-health-storage.d.ts +5 -0
  162. package/dist/core/supervisor/hook-health-storage.d.ts.map +1 -0
  163. package/dist/core/supervisor/hook-health-storage.js +24 -0
  164. package/dist/core/supervisor/hook-health.d.ts +72 -0
  165. package/dist/core/supervisor/hook-health.d.ts.map +1 -0
  166. package/dist/core/supervisor/hook-health.js +203 -0
  167. package/dist/core/supervisor/hooks.d.ts +10 -0
  168. package/dist/core/supervisor/hooks.d.ts.map +1 -0
  169. package/dist/core/supervisor/hooks.js +28 -0
  170. package/dist/core/supervisor/index.d.ts +15 -0
  171. package/dist/core/supervisor/index.d.ts.map +1 -0
  172. package/dist/core/supervisor/index.js +14 -0
  173. package/dist/core/supervisor/log-feed.d.ts +9 -0
  174. package/dist/core/supervisor/log-feed.d.ts.map +1 -0
  175. package/dist/core/supervisor/log-feed.js +103 -0
  176. package/dist/core/supervisor/service.d.ts +29 -0
  177. package/dist/core/supervisor/service.d.ts.map +1 -0
  178. package/dist/core/supervisor/service.js +450 -0
  179. package/dist/core/supervisor/services.d.ts +11 -0
  180. package/dist/core/supervisor/services.d.ts.map +1 -0
  181. package/dist/core/supervisor/services.js +155 -0
  182. package/dist/core/supervisor/status.d.ts +3 -0
  183. package/dist/core/supervisor/status.d.ts.map +1 -0
  184. package/dist/core/supervisor/status.js +48 -0
  185. package/dist/core/supervisor/storage.d.ts +30 -0
  186. package/dist/core/supervisor/storage.d.ts.map +1 -0
  187. package/dist/core/supervisor/storage.js +73 -0
  188. package/dist/core/supervisor/timeline.d.ts +3 -0
  189. package/dist/core/supervisor/timeline.d.ts.map +1 -0
  190. package/dist/core/supervisor/timeline.js +87 -0
  191. package/dist/core/workflow/admission.d.ts +23 -0
  192. package/dist/core/workflow/admission.d.ts.map +1 -0
  193. package/dist/core/workflow/admission.js +136 -0
  194. package/dist/core/workflow/engine.d.ts.map +1 -1
  195. package/dist/core/workflow/engine.js +77 -2
  196. package/dist/core/workflow/index.d.ts +3 -2
  197. package/dist/core/workflow/index.d.ts.map +1 -1
  198. package/dist/core/workflow/index.js +2 -1
  199. package/dist/core/workflow/proof.d.ts +2 -1
  200. package/dist/core/workflow/proof.d.ts.map +1 -1
  201. package/dist/core/workflow/proof.js +39 -1
  202. package/dist/core/workflow/run-state.d.ts +3 -2
  203. package/dist/core/workflow/run-state.d.ts.map +1 -1
  204. package/dist/core/workflow/run-state.js +8 -1
  205. package/dist/core/workflow/types.d.ts +33 -1
  206. package/dist/core/workflow/types.d.ts.map +1 -1
  207. package/dist/core/workflow/types.js +2 -1
  208. package/dist/lib/browser/client.d.ts +5 -0
  209. package/dist/lib/browser/client.d.ts.map +1 -1
  210. package/dist/lib/browser/client.js +1 -0
  211. package/dist/lib/browser/index.d.ts +2 -0
  212. package/dist/lib/browser/index.d.ts.map +1 -1
  213. package/dist/lib/browser/index.js +2 -0
  214. package/dist/lib/browser/qa-run-contracts.d.ts +173 -0
  215. package/dist/lib/browser/qa-run-contracts.d.ts.map +1 -0
  216. package/dist/lib/browser/qa-run-contracts.js +226 -0
  217. package/dist/lib/browser/qa-run.d.ts +51 -0
  218. package/dist/lib/browser/qa-run.d.ts.map +1 -0
  219. package/dist/lib/browser/qa-run.js +684 -0
  220. package/dist/lib/coord-root-id.d.ts +9 -0
  221. package/dist/lib/coord-root-id.d.ts.map +1 -0
  222. package/dist/lib/coord-root-id.js +17 -0
  223. package/dist/lib/instructions/apply.d.ts +3 -1
  224. package/dist/lib/instructions/apply.d.ts.map +1 -1
  225. package/dist/lib/instructions/apply.js +74 -3
  226. package/dist/lib/instructions/templates.d.ts.map +1 -1
  227. package/dist/lib/instructions/templates.js +6 -0
  228. package/package.json +12 -1
  229. package/src/commander.ts +26 -0
  230. package/src/commands/agents.ts +102 -49
  231. package/src/commands/artifacts.ts +40 -2
  232. package/src/commands/browse.ts +15 -0
  233. package/src/commands/diagnostics.ts +271 -0
  234. package/src/commands/files.ts +102 -2
  235. package/src/commands/governor.ts +8 -0
  236. package/src/commands/ledger-v3.ts +82 -0
  237. package/src/commands/qa-run.ts +184 -0
  238. package/src/commands/resources.ts +38 -0
  239. package/src/commands/supervisor.ts +141 -0
  240. package/src/commands/web.ts +19 -0
  241. package/src/commands/workflow.ts +8 -0
  242. package/src/core/agents/cli.ts +7 -3
  243. package/src/core/agents/health.ts +142 -0
  244. package/src/core/agents/mailbox.ts +373 -0
  245. package/src/core/agents/reconcile-coordination-v3.ts +77 -0
  246. package/src/core/agents/render/prompt-context.ts +42 -12
  247. package/src/core/agents/render/session-context.ts +37 -3
  248. package/src/core/agents/rules/commit-conflict.ts +58 -1
  249. package/src/core/agents/rules/stop-hook.ts +6 -12
  250. package/src/core/agents/session-finalizer-v3.ts +4 -1
  251. package/src/core/artifacts/index.ts +196 -10
  252. package/src/core/config.ts +111 -2
  253. package/src/core/diagnostics/advice.ts +147 -0
  254. package/src/core/diagnostics/bundle.ts +1142 -0
  255. package/src/core/diagnostics/comparison.ts +565 -0
  256. package/src/core/diagnostics/contract.ts +311 -0
  257. package/src/core/diagnostics/identity.ts +11 -0
  258. package/src/core/diagnostics/index.ts +7 -0
  259. package/src/core/diagnostics/replay.ts +314 -0
  260. package/src/core/diagnostics/sanitize.ts +97 -0
  261. package/src/core/events/legacy-storage/compression.ts +130 -0
  262. package/src/core/events/legacy-storage/index.ts +1 -0
  263. package/src/core/events/v3/archive-retention.ts +251 -0
  264. package/src/core/events/v3/capabilities.ts +2 -0
  265. package/src/core/events/v3/index.ts +9 -0
  266. package/src/core/events/v3/live-routing.ts +1 -0
  267. package/src/core/events/v3/producers/hook-base.ts +14 -2
  268. package/src/core/events/v3/producers/intake.ts +1 -0
  269. package/src/core/events/v3/producers/recorder.ts +110 -1
  270. package/src/core/hooks/adapter/output.ts +12 -1
  271. package/src/core/hooks/cli.ts +192 -215
  272. package/src/core/hooks/health.ts +146 -0
  273. package/src/core/resources/contract.ts +98 -0
  274. package/src/core/resources/index.ts +5 -0
  275. package/src/core/resources/sampler.ts +458 -0
  276. package/src/core/resources/service-status.ts +62 -0
  277. package/src/core/resources/service.ts +337 -0
  278. package/src/core/resources/storage.ts +44 -0
  279. package/src/core/storage/atomic-json.ts +15 -0
  280. package/src/core/storage/builtins.ts +62 -6
  281. package/src/core/storage/logger.ts +2 -0
  282. package/src/core/storage/query.ts +58 -0
  283. package/src/core/supervisor/activity.ts +193 -0
  284. package/src/core/supervisor/contract.ts +312 -0
  285. package/src/core/supervisor/explanations.ts +104 -0
  286. package/src/core/supervisor/findings.ts +788 -0
  287. package/src/core/supervisor/history.ts +61 -0
  288. package/src/core/supervisor/hook-health-alerts.ts +108 -0
  289. package/src/core/supervisor/hook-health-storage.ts +25 -0
  290. package/src/core/supervisor/hook-health.ts +301 -0
  291. package/src/core/supervisor/hooks.ts +35 -0
  292. package/src/core/supervisor/index.ts +14 -0
  293. package/src/core/supervisor/log-feed.ts +131 -0
  294. package/src/core/supervisor/service.ts +511 -0
  295. package/src/core/supervisor/services.ts +203 -0
  296. package/src/core/supervisor/status.ts +59 -0
  297. package/src/core/supervisor/storage.ts +126 -0
  298. package/src/core/supervisor/timeline.ts +133 -0
  299. package/src/core/workflow/admission.ts +215 -0
  300. package/src/core/workflow/engine.ts +93 -1
  301. package/src/core/workflow/index.ts +10 -0
  302. package/src/core/workflow/proof.ts +54 -1
  303. package/src/core/workflow/run-state.ts +13 -1
  304. package/src/core/workflow/types.ts +39 -1
  305. package/src/lib/browser/client.ts +6 -0
  306. package/src/lib/browser/index.ts +29 -0
  307. package/src/lib/browser/qa-run-contracts.ts +380 -0
  308. package/src/lib/browser/qa-run.ts +784 -0
  309. package/src/lib/coord-root-id.ts +23 -0
  310. package/src/lib/instructions/apply.ts +81 -2
  311. package/src/lib/instructions/templates.ts +6 -0
@@ -65,6 +65,57 @@ export function rotationFollowCursor(family) {
65
65
  active_offset: existsSync(active) ? regularFileStat(active).size : 0,
66
66
  };
67
67
  }
68
+ /**
69
+ * Read the newest complete records from one family's active segment without
70
+ * walking sealed history. Dashboard-style live views need a cheap bounded
71
+ * snapshot; the full `queryLogs` surface remains the historical query path.
72
+ */
73
+ export function readRecentActiveLogs(family, options) {
74
+ if (!Number.isSafeInteger(options.max_records) ||
75
+ options.max_records <= 0 ||
76
+ !Number.isSafeInteger(options.max_bytes) ||
77
+ options.max_bytes <= 0) {
78
+ throw new Error("recent log read requires positive budgets");
79
+ }
80
+ const active = join(familyLogDirectory(family), "active.jsonl");
81
+ if (!existsSync(active))
82
+ return { records: [], bytes_examined: 0, truncated: false };
83
+ const opened = openRegularNoFollow(active);
84
+ try {
85
+ const size = fstatSync(opened.fd).size;
86
+ const start = Math.max(0, size - options.max_bytes);
87
+ const length = size - start;
88
+ if (length === 0)
89
+ return { records: [], bytes_examined: 0, truncated: false };
90
+ const buffer = Buffer.allocUnsafe(length);
91
+ let consumed = 0;
92
+ while (consumed < length) {
93
+ const count = readSync(opened.fd, buffer, consumed, length - consumed, start + consumed);
94
+ if (count === 0)
95
+ break;
96
+ consumed += count;
97
+ }
98
+ assertOpenFileIdentity(active, opened.fd, opened.parent);
99
+ const text = buffer.subarray(0, consumed).toString("utf8");
100
+ let lines = text.split("\n");
101
+ // A bounded tail can begin in the middle of a record. The active writer
102
+ // can also leave a not-yet-complete final record while this snapshot reads.
103
+ if (start > 0)
104
+ lines = lines.slice(1);
105
+ if (!text.endsWith("\n"))
106
+ lines = lines.slice(0, -1);
107
+ const records = lines.filter((line) => line.trim()).map(parseLogRecord);
108
+ const truncated = start > 0 || records.length > options.max_records;
109
+ return {
110
+ records: records.slice(-options.max_records),
111
+ bytes_examined: consumed,
112
+ truncated,
113
+ };
114
+ }
115
+ finally {
116
+ closeSync(opened.fd);
117
+ }
118
+ }
68
119
  export async function readLogFollow(family, cursor, maxBytes) {
69
120
  if (cursor.family_id !== family.id)
70
121
  throw new Error("follow cursor family mismatch");
@@ -0,0 +1,4 @@
1
+ import { type SupervisorActivitySnapshot } from "./contract.js";
2
+ /** Read a bounded, generation-bound activity projection without loading Event Ledger V3. */
3
+ export declare function collectSupervisorActivitySnapshot(coordRoot: string, now?: Date): SupervisorActivitySnapshot;
4
+ //# sourceMappingURL=activity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"activity.d.ts","sourceRoot":"","sources":["../../../src/core/supervisor/activity.ts"],"names":[],"mappings":"AAGA,OAAO,EAIL,KAAK,0BAA0B,EAGhC,MAAM,eAAe,CAAC;AAoBvB,4FAA4F;AAC5F,wBAAgB,iCAAiC,CAC/C,SAAS,EAAE,MAAM,EACjB,GAAG,OAAa,GACf,0BAA0B,CAoF5B"}
@@ -0,0 +1,141 @@
1
+ import { createHash } from "node:crypto";
2
+ import { existsSync, lstatSync, readdirSync, readFileSync } from "node:fs";
3
+ import { join, resolve } from "node:path";
4
+ import { SUPERVISOR_ACTIVITY_SCHEMA_VERSION, SUPERVISOR_DIAGNOSTIC_LIMITS, SUPERVISOR_FINDING_POLICY, } from "./contract.js";
5
+ /** Read a bounded, generation-bound activity projection without loading Event Ledger V3. */
6
+ export function collectSupervisorActivitySnapshot(coordRoot, now = new Date()) {
7
+ const observedAt = now.toISOString();
8
+ const directory = join(resolve(coordRoot), ".harnery", "active");
9
+ if (!existsSync(directory))
10
+ return unavailable(observedAt, "activity-projection-missing");
11
+ const candidates = [];
12
+ let rejected = 0;
13
+ try {
14
+ for (const entry of readdirSync(directory)) {
15
+ if (!/^[A-Za-z0-9_-]{1,128}\.json$/.test(entry)) {
16
+ rejected += 1;
17
+ continue;
18
+ }
19
+ const path = join(directory, entry);
20
+ const stat = lstatSync(path);
21
+ if (stat.isSymbolicLink() ||
22
+ !stat.isFile() ||
23
+ stat.size < 2 ||
24
+ stat.size > SUPERVISOR_FINDING_POLICY.max_activity_file_bytes) {
25
+ rejected += 1;
26
+ continue;
27
+ }
28
+ candidates.push({ name: entry.slice(0, -5), path, bytes: stat.size, mtimeMs: stat.mtimeMs });
29
+ }
30
+ }
31
+ catch {
32
+ return unavailable(observedAt, "activity-projection-read-failed", "error");
33
+ }
34
+ candidates.sort((left, right) => right.mtimeMs - left.mtimeMs || left.name.localeCompare(right.name));
35
+ const entries = [];
36
+ let totalBytes = 0;
37
+ let stale = 0;
38
+ for (const candidate of candidates) {
39
+ if (entries.length >= SUPERVISOR_DIAGNOSTIC_LIMITS.max_activity_entries ||
40
+ totalBytes + candidate.bytes > SUPERVISOR_FINDING_POLICY.max_activity_total_bytes) {
41
+ rejected += 1;
42
+ continue;
43
+ }
44
+ totalBytes += candidate.bytes;
45
+ let cache;
46
+ try {
47
+ cache = JSON.parse(readFileSync(candidate.path, "utf8"));
48
+ }
49
+ catch {
50
+ rejected += 1;
51
+ continue;
52
+ }
53
+ if (!validCache(cache, candidate.name)) {
54
+ rejected += 1;
55
+ continue;
56
+ }
57
+ const age = now.getTime() - Date.parse(cache.last_heartbeat);
58
+ if (!Number.isFinite(age) ||
59
+ age < -30_000 ||
60
+ age > SUPERVISOR_FINDING_POLICY.activity_freshness_ms) {
61
+ stale += 1;
62
+ continue;
63
+ }
64
+ entries.push(activityEntry(cache));
65
+ }
66
+ const state = rejected > 0 ? "partial" : "supported";
67
+ return {
68
+ schema_version: SUPERVISOR_ACTIVITY_SCHEMA_VERSION,
69
+ observed_at: observedAt,
70
+ max_entries: SUPERVISOR_DIAGNOSTIC_LIMITS.max_activity_entries,
71
+ entries: entries.sort((left, right) => left.scope_id.localeCompare(right.scope_id)),
72
+ omitted_entry_count: rejected + stale,
73
+ capability: {
74
+ source_kind: "coordination.activity-projection",
75
+ state,
76
+ ...(state === "partial" ? { reason_code: "bounded-cache-rejection" } : {}),
77
+ ...(rejected + stale > 0
78
+ ? { detail: `${rejected} invalid or over-budget and ${stale} stale activity rows omitted.` }
79
+ : {}),
80
+ },
81
+ };
82
+ }
83
+ function validCache(cache, fileId) {
84
+ return (cache.schema_version === 2 &&
85
+ cache.instance_id === fileId &&
86
+ typeof cache.session_id === "string" &&
87
+ cache.session_id.length > 0 &&
88
+ isActivity(cache.activity) &&
89
+ isTaskState(cache.task_state) &&
90
+ typeof cache.last_heartbeat === "string" &&
91
+ typeof cache.v3_instance_id === "string" &&
92
+ cache.v3_instance_id.startsWith("inst_") &&
93
+ typeof cache.v3_generation_id === "string" &&
94
+ cache.v3_generation_id.startsWith("gen_"));
95
+ }
96
+ function activityEntry(cache) {
97
+ const source = activitySource(cache);
98
+ return {
99
+ scope_kind: "agent",
100
+ scope_id: cache.instance_id,
101
+ session_id: cache.session_id,
102
+ declared_activity: cache.activity,
103
+ task_state: cache.task_state,
104
+ observed_at: cache.last_heartbeat,
105
+ source,
106
+ };
107
+ }
108
+ function activitySource(cache) {
109
+ const sourceId = `${cache.v3_instance_id}:${cache.v3_generation_id}`;
110
+ return {
111
+ id: `src_${digest(`coordination.activity-projection\u0000${sourceId}\u0000${cache.last_heartbeat}`).slice(0, 24)}`,
112
+ source_kind: "coordination.activity-projection",
113
+ source_id: sourceId,
114
+ observed_at: cache.last_heartbeat,
115
+ schema_version: SUPERVISOR_ACTIVITY_SCHEMA_VERSION,
116
+ capability: "supported",
117
+ };
118
+ }
119
+ function unavailable(observedAt, reasonCode, state = "unsupported") {
120
+ return {
121
+ schema_version: SUPERVISOR_ACTIVITY_SCHEMA_VERSION,
122
+ observed_at: observedAt,
123
+ max_entries: SUPERVISOR_DIAGNOSTIC_LIMITS.max_activity_entries,
124
+ entries: [],
125
+ omitted_entry_count: 0,
126
+ capability: {
127
+ source_kind: "coordination.activity-projection",
128
+ state,
129
+ reason_code: reasonCode,
130
+ },
131
+ };
132
+ }
133
+ function isActivity(value) {
134
+ return value === "working" || value === "needs_input" || value === "idle" || value === "unknown";
135
+ }
136
+ function isTaskState(value) {
137
+ return value === "active" || value === "blocked" || value === "done";
138
+ }
139
+ function digest(value) {
140
+ return createHash("sha256").update(value).digest("hex");
141
+ }
@@ -0,0 +1,268 @@
1
+ import type { ResourceProcessGroup } from "../resources/contract.js";
2
+ import type { HarneryLogRecordV1 } from "../storage/jsonl.js";
3
+ export declare const SUPERVISOR_STATUS_SCHEMA_VERSION: 1;
4
+ export declare const SUPERVISOR_SNAPSHOT_SCHEMA_VERSION: 2;
5
+ export declare const SUPERVISOR_HISTORY_SCHEMA_VERSION: 1;
6
+ export declare const SUPERVISOR_FINDING_SCHEMA_VERSION: 2;
7
+ export declare const SUPERVISOR_ACTIVITY_SCHEMA_VERSION: 1;
8
+ export declare const SUPERVISOR_TIMELINE_SCHEMA_VERSION: 2;
9
+ export declare const SUPERVISOR_EXPLANATION_SCHEMA_VERSION: 1;
10
+ export declare const SUPERVISOR_LOG_FEED_SCHEMA_VERSION: 1;
11
+ export declare const SUPERVISOR_CONSUMER_SCHEMA_VERSION: 1;
12
+ export declare const SUPERVISOR_DIAGNOSTIC_LIMITS: {
13
+ readonly max_findings: 100;
14
+ readonly max_active_findings: 32;
15
+ readonly max_evidence_per_finding: 32;
16
+ readonly max_timeline_entries: 160;
17
+ readonly max_explanation_items: 24;
18
+ readonly max_capabilities: 16;
19
+ readonly max_activity_entries: 64;
20
+ readonly max_bundle_files: 32;
21
+ readonly max_bundle_bytes: number;
22
+ readonly max_summary_chars: 500;
23
+ readonly max_excerpt_chars: 2000;
24
+ };
25
+ export declare const SUPERVISOR_FINDING_POLICY: {
26
+ readonly episode_gap_ms: number;
27
+ readonly activity_freshness_ms: number;
28
+ readonly max_activity_file_bytes: number;
29
+ readonly max_activity_total_bytes: number;
30
+ };
31
+ export declare const SUPERVISOR_RESOURCE_BUDGET: {
32
+ readonly max_rss_bytes: number;
33
+ readonly max_cycle_duration_ms: 50;
34
+ readonly max_startup_duration_ms: 2000;
35
+ readonly max_cache_bytes: number;
36
+ readonly max_regression_ratio: 1.2;
37
+ };
38
+ export type SupervisorProcessState = "starting" | "running" | "stopping" | "stopped" | "error";
39
+ export interface SupervisorServiceStatusRecord {
40
+ schema_version: typeof SUPERVISOR_STATUS_SCHEMA_VERSION;
41
+ pid: number;
42
+ start_token?: string;
43
+ host: string;
44
+ nonce: string;
45
+ state: SupervisorProcessState;
46
+ started_at: string;
47
+ heartbeat_at: string;
48
+ interval_ms: number;
49
+ keep_alive: boolean;
50
+ idle_exit_ms: number;
51
+ cycle_count: number;
52
+ last_cycle_at?: string;
53
+ last_cycle_duration_ms?: number;
54
+ idle_since?: string;
55
+ last_error_code?: string;
56
+ stopped_at?: string;
57
+ }
58
+ export interface SupervisorStatus {
59
+ running: boolean;
60
+ stale: boolean;
61
+ record?: SupervisorServiceStatusRecord;
62
+ status_path: string;
63
+ snapshot_path: string;
64
+ }
65
+ export interface SupervisorConsumerRecord {
66
+ schema_version: typeof SUPERVISOR_CONSUMER_SCHEMA_VERSION;
67
+ id: string;
68
+ pid: number;
69
+ start_token?: string;
70
+ registered_at: string;
71
+ }
72
+ export type ObservedServiceState = "running" | "stopped" | "stale" | "unknown";
73
+ export interface ObservedServiceHealth {
74
+ id: "supervisor" | "semantic-reader" | "presence-relay" | "governor" | "dashboard";
75
+ state: ObservedServiceState;
76
+ pid?: number;
77
+ started_at?: string;
78
+ heartbeat_at?: string;
79
+ reason?: string;
80
+ }
81
+ export interface ObservedHookHealth {
82
+ pid: number;
83
+ owner_id: string;
84
+ state: string;
85
+ age_seconds: number;
86
+ cpu_percent: number | null;
87
+ rss_bytes: number;
88
+ command: string;
89
+ long_running: boolean;
90
+ evidence: "validated-owner-and-exact-entrypoint";
91
+ }
92
+ export interface SupervisorHistoryPoint {
93
+ sampled_at: string;
94
+ machine: {
95
+ cpu_percent: number | null;
96
+ memory_percent: number | null;
97
+ memory_used_bytes: number | null;
98
+ swap_used_bytes: number | null;
99
+ process_count: number;
100
+ };
101
+ groups: readonly ResourceProcessGroup[];
102
+ }
103
+ export interface SupervisorHistory {
104
+ schema_version: typeof SUPERVISOR_HISTORY_SCHEMA_VERSION;
105
+ interval_ms: number;
106
+ max_points: number;
107
+ points: readonly SupervisorHistoryPoint[];
108
+ }
109
+ export type SupervisorCapabilityState = "supported" | "partial" | "unsupported" | "error" | "expired" | "malformed" | "redacted";
110
+ export type SupervisorFindingSeverity = "info" | "warning" | "critical";
111
+ export type SupervisorFindingState = "opened" | "resolved";
112
+ export interface SupervisorCapability {
113
+ source_kind: string;
114
+ state: SupervisorCapabilityState;
115
+ reason_code?: string;
116
+ detail?: string;
117
+ }
118
+ export interface SupervisorSourceReference {
119
+ id: string;
120
+ source_kind: string;
121
+ source_id: string;
122
+ observed_at: string;
123
+ record_id?: string;
124
+ sequence?: number;
125
+ schema_version?: number;
126
+ capability: SupervisorCapabilityState;
127
+ }
128
+ export interface SupervisorFindingEvidence {
129
+ id: string;
130
+ source: SupervisorSourceReference;
131
+ summary: string;
132
+ observed_value?: number;
133
+ unit?: "percent" | "bytes" | "milliseconds" | "seconds" | "processes" | "count";
134
+ }
135
+ export interface SupervisorFindingAttribution {
136
+ state: "attributed" | "unattributed";
137
+ owner_kind?: "agent" | "service";
138
+ owner_id?: string;
139
+ owner_root_pid?: number;
140
+ reason_code?: "no-validated-process-anchor";
141
+ }
142
+ export interface SupervisorFindingWorkloadContext {
143
+ relationship: "active-work" | "unexpected-idle-growth" | "unknown";
144
+ declared_activity: "working" | "needs_input" | "idle" | "unknown";
145
+ task_state: "active" | "blocked" | "done" | "unknown";
146
+ observed_at: string;
147
+ source: SupervisorSourceReference;
148
+ }
149
+ export interface SupervisorFinding {
150
+ schema_version: typeof SUPERVISOR_FINDING_SCHEMA_VERSION;
151
+ id: string;
152
+ fingerprint: string;
153
+ source_kind: string;
154
+ finding_kind: string;
155
+ severity: SupervisorFindingSeverity;
156
+ state: SupervisorFindingState;
157
+ scope_kind: string;
158
+ scope_id: string;
159
+ summary: string;
160
+ opened_at: string;
161
+ observed_at: string;
162
+ resolved_at?: string;
163
+ occurrence_count: number;
164
+ peak_observed_value?: number;
165
+ peak_observed_at?: string;
166
+ peak_unit?: SupervisorFindingEvidence["unit"];
167
+ attribution?: SupervisorFindingAttribution;
168
+ workload_context?: SupervisorFindingWorkloadContext;
169
+ primary_source: SupervisorSourceReference;
170
+ evidence: readonly SupervisorFindingEvidence[];
171
+ capabilities: readonly SupervisorCapability[];
172
+ }
173
+ export interface SupervisorDeclaredActivity {
174
+ scope_kind: "agent";
175
+ scope_id: string;
176
+ session_id: string;
177
+ declared_activity: "working" | "needs_input" | "idle" | "unknown";
178
+ task_state: "active" | "blocked" | "done";
179
+ observed_at: string;
180
+ source: SupervisorSourceReference;
181
+ }
182
+ export interface SupervisorActivitySnapshot {
183
+ schema_version: typeof SUPERVISOR_ACTIVITY_SCHEMA_VERSION;
184
+ observed_at: string;
185
+ max_entries: number;
186
+ entries: readonly SupervisorDeclaredActivity[];
187
+ omitted_entry_count: number;
188
+ capability: SupervisorCapability;
189
+ }
190
+ export interface SupervisorFindings {
191
+ schema_version: typeof SUPERVISOR_FINDING_SCHEMA_VERSION;
192
+ max_findings: number;
193
+ active: readonly SupervisorFinding[];
194
+ transitions: readonly SupervisorFinding[];
195
+ }
196
+ export type SupervisorTimelineRelation = "opened" | "observed" | "related" | "resolved" | "capability" | "missing";
197
+ export interface SupervisorTimelineEntry {
198
+ id: string;
199
+ occurred_at: string;
200
+ first_occurred_at: string;
201
+ last_occurred_at: string;
202
+ occurrence_count: number;
203
+ relation: SupervisorTimelineRelation;
204
+ summary: string;
205
+ source: SupervisorSourceReference;
206
+ evidence_id?: string;
207
+ }
208
+ export interface SupervisorTimeline {
209
+ schema_version: typeof SUPERVISOR_TIMELINE_SCHEMA_VERSION;
210
+ finding_id: string;
211
+ start_at: string;
212
+ end_at: string;
213
+ max_entries: number;
214
+ omitted_entries: number;
215
+ compacted_entries: number;
216
+ entries: readonly SupervisorTimelineEntry[];
217
+ capabilities: readonly SupervisorCapability[];
218
+ }
219
+ export interface SupervisorExplanationStatement {
220
+ id: string;
221
+ code: string;
222
+ summary: string;
223
+ evidence_ids: readonly string[];
224
+ }
225
+ export interface SupervisorPossibleExplanation extends SupervisorExplanationStatement {
226
+ confidence: "low" | "medium" | "high";
227
+ evidence_against_ids: readonly string[];
228
+ }
229
+ export interface SupervisorFindingExplanation {
230
+ schema_version: typeof SUPERVISOR_EXPLANATION_SCHEMA_VERSION;
231
+ finding_id: string;
232
+ generated_at: string;
233
+ observed: readonly SupervisorExplanationStatement[];
234
+ related: readonly SupervisorExplanationStatement[];
235
+ possible: readonly SupervisorPossibleExplanation[];
236
+ missing_capabilities: readonly SupervisorCapability[];
237
+ }
238
+ export interface SupervisorLogLane {
239
+ family_id: string;
240
+ owner: string;
241
+ storage_class: "operational-log" | "debug-log";
242
+ records: readonly HarneryLogRecordV1[];
243
+ truncated: boolean;
244
+ error?: string;
245
+ }
246
+ export interface SupervisorLogFeed {
247
+ schema_version: typeof SUPERVISOR_LOG_FEED_SCHEMA_VERSION;
248
+ captured_at: string;
249
+ sequence: number;
250
+ lanes: readonly SupervisorLogLane[];
251
+ total_records: number;
252
+ unavailable_families: number;
253
+ }
254
+ export interface SupervisorSnapshot {
255
+ schema_version: typeof SUPERVISOR_SNAPSHOT_SCHEMA_VERSION;
256
+ sampled_at: string;
257
+ sequence: number;
258
+ collector_duration_ms: number;
259
+ resource_sample_duration_ms: number;
260
+ services: readonly ObservedServiceHealth[];
261
+ hooks: readonly ObservedHookHealth[];
262
+ active_finding_count: number;
263
+ history_point_count: number;
264
+ log_record_count: number;
265
+ live_consumer_count: number;
266
+ attributed_agent_count: number;
267
+ }
268
+ //# sourceMappingURL=contract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../../../src/core/supervisor/contract.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAE9D,eAAO,MAAM,gCAAgC,EAAG,CAAU,CAAC;AAC3D,eAAO,MAAM,kCAAkC,EAAG,CAAU,CAAC;AAC7D,eAAO,MAAM,iCAAiC,EAAG,CAAU,CAAC;AAC5D,eAAO,MAAM,iCAAiC,EAAG,CAAU,CAAC;AAC5D,eAAO,MAAM,kCAAkC,EAAG,CAAU,CAAC;AAC7D,eAAO,MAAM,kCAAkC,EAAG,CAAU,CAAC;AAC7D,eAAO,MAAM,qCAAqC,EAAG,CAAU,CAAC;AAChE,eAAO,MAAM,kCAAkC,EAAG,CAAU,CAAC;AAC7D,eAAO,MAAM,kCAAkC,EAAG,CAAU,CAAC;AAE7D,eAAO,MAAM,4BAA4B;;;;;;;;;;;;CAY/B,CAAC;AAEX,eAAO,MAAM,yBAAyB;;;;;CAK5B,CAAC;AAEX,eAAO,MAAM,0BAA0B;;;;;;CAM7B,CAAC;AAEX,MAAM,MAAM,sBAAsB,GAAG,UAAU,GAAG,SAAS,GAAG,UAAU,GAAG,SAAS,GAAG,OAAO,CAAC;AAE/F,MAAM,WAAW,6BAA6B;IAC5C,cAAc,EAAE,OAAO,gCAAgC,CAAC;IACxD,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,sBAAsB,CAAC;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAA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const SUPERVISOR_FINDING_SCHEMA_VERSION = 2;
5
+ export const SUPERVISOR_ACTIVITY_SCHEMA_VERSION = 1;
6
+ export const SUPERVISOR_TIMELINE_SCHEMA_VERSION = 2;
7
+ export const SUPERVISOR_EXPLANATION_SCHEMA_VERSION = 1;
8
+ export const SUPERVISOR_LOG_FEED_SCHEMA_VERSION = 1;
9
+ export const SUPERVISOR_CONSUMER_SCHEMA_VERSION = 1;
10
+ export const SUPERVISOR_DIAGNOSTIC_LIMITS = {
11
+ max_findings: 100,
12
+ max_active_findings: 32,
13
+ max_evidence_per_finding: 32,
14
+ max_timeline_entries: 160,
15
+ max_explanation_items: 24,
16
+ max_capabilities: 16,
17
+ max_activity_entries: 64,
18
+ max_bundle_files: 32,
19
+ max_bundle_bytes: 8 * 1_024 * 1_024,
20
+ max_summary_chars: 500,
21
+ max_excerpt_chars: 2_000,
22
+ };
23
+ export const SUPERVISOR_FINDING_POLICY = {
24
+ episode_gap_ms: 5 * 60_000,
25
+ activity_freshness_ms: 2 * 60_000,
26
+ max_activity_file_bytes: 64 * 1_024,
27
+ max_activity_total_bytes: 512 * 1_024,
28
+ };
29
+ export const SUPERVISOR_RESOURCE_BUDGET = {
30
+ max_rss_bytes: 128 * 1_024 * 1_024,
31
+ max_cycle_duration_ms: 50,
32
+ max_startup_duration_ms: 2_000,
33
+ max_cache_bytes: 8 * 1_024 * 1_024,
34
+ max_regression_ratio: 1.2,
35
+ };
@@ -0,0 +1,4 @@
1
+ import { type SupervisorFinding, type SupervisorFindingExplanation } from "./contract.js";
2
+ /** Build evidence-linked statements without presenting correlation as causation. */
3
+ export declare function explainSupervisorFinding(finding: SupervisorFinding): SupervisorFindingExplanation;
4
+ //# sourceMappingURL=explanations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"explanations.d.ts","sourceRoot":"","sources":["../../../src/core/supervisor/explanations.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,KAAK,iBAAiB,EACtB,KAAK,4BAA4B,EAElC,MAAM,eAAe,CAAC;AAEvB,oFAAoF;AACpF,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,iBAAiB,GAAG,4BAA4B,CAiBjG"}
@@ -0,0 +1,71 @@
1
+ import { createHash } from "node:crypto";
2
+ import { SUPERVISOR_DIAGNOSTIC_LIMITS, SUPERVISOR_EXPLANATION_SCHEMA_VERSION, } from "./contract.js";
3
+ /** Build evidence-linked statements without presenting correlation as causation. */
4
+ export function explainSupervisorFinding(finding) {
5
+ const observed = finding.evidence.map((evidence) => statement("observed.source", evidence.summary, [evidence.id]));
6
+ const related = relatedStatements(finding);
7
+ const possible = possibleStatements(finding);
8
+ return {
9
+ schema_version: SUPERVISOR_EXPLANATION_SCHEMA_VERSION,
10
+ finding_id: finding.id,
11
+ generated_at: finding.observed_at,
12
+ observed: observed.slice(0, SUPERVISOR_DIAGNOSTIC_LIMITS.max_explanation_items),
13
+ related: related.slice(0, SUPERVISOR_DIAGNOSTIC_LIMITS.max_explanation_items),
14
+ possible: possible.slice(0, SUPERVISOR_DIAGNOSTIC_LIMITS.max_explanation_items),
15
+ missing_capabilities: finding.capabilities
16
+ .filter((capability) => capability.state !== "supported")
17
+ .slice(0, SUPERVISOR_DIAGNOSTIC_LIMITS.max_capabilities),
18
+ };
19
+ }
20
+ function relatedStatements(finding) {
21
+ const sources = new Set(finding.evidence.map((evidence) => evidence.source.source_kind));
22
+ if (sources.size < 2)
23
+ return [];
24
+ return [
25
+ statement("related.multi-source", `${sources.size} independent source kinds recorded related observations in this finding window.`, finding.evidence.map((evidence) => evidence.id)),
26
+ ];
27
+ }
28
+ function possibleStatements(finding) {
29
+ const evidenceIds = finding.evidence.map((evidence) => evidence.id);
30
+ const possible = [];
31
+ if (finding.finding_kind.includes("memory")) {
32
+ possible.push({
33
+ ...statement("possible.memory-retention-or-workload", "A growing workload, retained objects, or operating-system caching could explain the memory observation; this evidence does not distinguish them.", evidenceIds),
34
+ confidence: "low",
35
+ evidence_against_ids: [],
36
+ });
37
+ }
38
+ else if (finding.finding_kind.includes("process-pressure")) {
39
+ possible.push({
40
+ ...statement("possible.concurrent-work", "Concurrent local work could explain the process count; the finding does not establish which activity caused it.", evidenceIds),
41
+ confidence: "low",
42
+ evidence_against_ids: [],
43
+ });
44
+ }
45
+ else if (finding.finding_kind === "hook.long-running") {
46
+ possible.push({
47
+ ...statement("possible.hook-stall", "The hook may be waiting on I/O or blocked work, but elapsed time alone cannot identify the cause.", evidenceIds),
48
+ confidence: "low",
49
+ evidence_against_ids: [],
50
+ });
51
+ }
52
+ else if (finding.finding_kind === "coordination.ledger-diagnostic") {
53
+ possible.push({
54
+ ...statement("possible.ledger-write-or-read-boundary", "A producer write or reader validation boundary may explain the ledger diagnostic; inspect the referenced V3 record before attributing a cause.", evidenceIds),
55
+ confidence: "low",
56
+ evidence_against_ids: [],
57
+ });
58
+ }
59
+ return possible;
60
+ }
61
+ function statement(code, summary, evidenceIds) {
62
+ return {
63
+ id: `ex_${createHash("sha256")
64
+ .update(`${code}\u0000${summary}\u0000${evidenceIds.join(",")}`)
65
+ .digest("hex")
66
+ .slice(0, 24)}`,
67
+ code,
68
+ summary: summary.slice(0, SUPERVISOR_DIAGNOSTIC_LIMITS.max_summary_chars),
69
+ evidence_ids: [...evidenceIds].slice(0, SUPERVISOR_DIAGNOSTIC_LIMITS.max_evidence_per_finding),
70
+ };
71
+ }
@@ -0,0 +1,20 @@
1
+ import type { CoordinationHealthSnapshot } from "../agents/health.js";
2
+ import type { ResourceSnapshot } from "../resources/contract.js";
3
+ import { type ObservedHookHealth, type ObservedServiceHealth, type SupervisorActivitySnapshot, type SupervisorFinding, type SupervisorFindings, type SupervisorHistory, type SupervisorLogFeed } from "./contract.js";
4
+ import type { SupervisorHookHealth } from "./hook-health.js";
5
+ export interface SupervisorFindingEvaluationInput {
6
+ previous?: SupervisorFindings;
7
+ resource: ResourceSnapshot;
8
+ services: readonly ObservedServiceHealth[];
9
+ hooks: readonly ObservedHookHealth[];
10
+ history: SupervisorHistory;
11
+ logFeed: SupervisorLogFeed;
12
+ hookHealth?: SupervisorHookHealth;
13
+ coordination?: CoordinationHealthSnapshot;
14
+ activity?: SupervisorActivitySnapshot;
15
+ now?: Date;
16
+ }
17
+ /** Pure deterministic evaluator used by the live supervisor and replay. */
18
+ export declare function evaluateSupervisorFindings(input: Omit<SupervisorFindingEvaluationInput, "previous">): readonly SupervisorFinding[];
19
+ export declare function updateSupervisorFindings(input: SupervisorFindingEvaluationInput): SupervisorFindings;
20
+ //# sourceMappingURL=findings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"findings.d.ts","sourceRoot":"","sources":["../../../src/core/supervisor/findings.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AACtE,OAAO,KAAK,EAGV,gBAAgB,EACjB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAI1B,KAAK,0BAA0B,EAE/B,KAAK,iBAAiB,EAItB,KAAK,kBAAkB,EAEvB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EAEvB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AA8B7D,MAAM,WAAW,gCAAgC;IAC/C,QAAQ,CAAC,EAAE,kBAAkB,CAAC;IAC9B,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,QAAQ,EAAE,SAAS,qBAAqB,EAAE,CAAC;IAC3C,KAAK,EAAE,SAAS,kBAAkB,EAAE,CAAC;IACrC,OAAO,EAAE,iBAAiB,CAAC;IAC3B,OAAO,EAAE,iBAAiB,CAAC;IAC3B,UAAU,CAAC,EAAE,oBAAoB,CAAC;IAClC,YAAY,CAAC,EAAE,0BAA0B,CAAC;IAC1C,QAAQ,CAAC,EAAE,0BAA0B,CAAC;IACtC,GAAG,CAAC,EAAE,IAAI,CAAC;CACZ;AAED,2EAA2E;AAC3E,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,IAAI,CAAC,gCAAgC,EAAE,UAAU,CAAC,GACxD,SAAS,iBAAiB,EAAE,CAE9B;AAED,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,gCAAgC,GACtC,kBAAkB,CAwEpB"}