harnery 0.35.0 → 0.36.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 (616) hide show
  1. package/dist/commander.d.ts +30 -5
  2. package/dist/commander.d.ts.map +1 -1
  3. package/dist/commander.js +124 -96
  4. package/dist/commands/agents.d.ts +23 -3
  5. package/dist/commands/agents.d.ts.map +1 -1
  6. package/dist/commands/agents.js +379 -198
  7. package/dist/commands/backup.d.ts.map +1 -1
  8. package/dist/commands/backup.js +10 -10
  9. package/dist/commands/browse-session.d.ts.map +1 -1
  10. package/dist/commands/browse-session.js +12 -0
  11. package/dist/commands/browse.d.ts +1 -1
  12. package/dist/commands/browse.d.ts.map +1 -1
  13. package/dist/commands/browse.js +5 -4
  14. package/dist/commands/conversations.d.ts +10 -0
  15. package/dist/commands/conversations.d.ts.map +1 -0
  16. package/dist/commands/conversations.js +201 -0
  17. package/dist/commands/deinit.d.ts.map +1 -1
  18. package/dist/commands/deinit.js +5 -0
  19. package/dist/commands/docs.d.ts.map +1 -1
  20. package/dist/commands/docs.js +13 -2
  21. package/dist/commands/doctor.d.ts +5 -0
  22. package/dist/commands/doctor.d.ts.map +1 -1
  23. package/dist/commands/doctor.js +51 -7
  24. package/dist/commands/fetch.js +6 -5
  25. package/dist/commands/files.d.ts +22 -0
  26. package/dist/commands/files.d.ts.map +1 -0
  27. package/dist/commands/files.js +113 -0
  28. package/dist/commands/governor.js +14 -12
  29. package/dist/commands/inbox.d.ts +5 -0
  30. package/dist/commands/inbox.d.ts.map +1 -0
  31. package/dist/commands/inbox.js +57 -0
  32. package/dist/commands/init.d.ts +4 -5
  33. package/dist/commands/init.d.ts.map +1 -1
  34. package/dist/commands/init.js +63 -13
  35. package/dist/commands/ledger-v3.d.ts.map +1 -1
  36. package/dist/commands/ledger-v3.js +347 -1
  37. package/dist/commands/logs.d.ts +4 -0
  38. package/dist/commands/logs.d.ts.map +1 -0
  39. package/dist/commands/logs.js +169 -0
  40. package/dist/commands/messages.d.ts +5 -0
  41. package/dist/commands/messages.d.ts.map +1 -0
  42. package/dist/commands/messages.js +45 -0
  43. package/dist/commands/outline.d.ts +1 -1
  44. package/dist/commands/outline.d.ts.map +1 -1
  45. package/dist/commands/outline.js +2 -2
  46. package/dist/commands/read.d.ts +1 -1
  47. package/dist/commands/read.d.ts.map +1 -1
  48. package/dist/commands/read.js +2 -2
  49. package/dist/commands/semantic.d.ts.map +1 -1
  50. package/dist/commands/semantic.js +54 -2
  51. package/dist/commands/storage.d.ts +4 -0
  52. package/dist/commands/storage.d.ts.map +1 -0
  53. package/dist/commands/storage.js +238 -0
  54. package/dist/commands/tunnel.d.ts +5 -1
  55. package/dist/commands/tunnel.d.ts.map +1 -1
  56. package/dist/commands/tunnel.js +44 -31
  57. package/dist/commands/web.d.ts +3 -0
  58. package/dist/commands/web.d.ts.map +1 -1
  59. package/dist/commands/web.js +67 -7
  60. package/dist/commands/work.js +3 -3
  61. package/dist/commands/workflow.js +13 -13
  62. package/dist/core/adapters/profiles.d.ts +1 -1
  63. package/dist/core/agents/cli.js +209 -39
  64. package/dist/core/agents/live-authority-v3.d.ts +47 -1
  65. package/dist/core/agents/live-authority-v3.d.ts.map +1 -1
  66. package/dist/core/agents/live-authority-v3.js +244 -10
  67. package/dist/core/agents/live-lifecycle-v3.js +6 -1
  68. package/dist/core/agents/live-observation-v3.d.ts.map +1 -1
  69. package/dist/core/agents/live-observation-v3.js +6 -1
  70. package/dist/core/agents/render/prompt-context.d.ts +9 -3
  71. package/dist/core/agents/render/prompt-context.d.ts.map +1 -1
  72. package/dist/core/agents/render/prompt-context.js +24 -7
  73. package/dist/core/agents/rules/stop-hook.d.ts +2 -0
  74. package/dist/core/agents/rules/stop-hook.d.ts.map +1 -1
  75. package/dist/core/agents/rules/stop-hook.js +94 -13
  76. package/dist/core/agents/rules/verdict.d.ts +1 -0
  77. package/dist/core/agents/rules/verdict.d.ts.map +1 -1
  78. package/dist/core/agents/session-events.d.ts.map +1 -1
  79. package/dist/core/agents/session-events.js +4 -0
  80. package/dist/core/agents/session-finalization-state-v3.js +1 -1
  81. package/dist/core/agents/session-finalizer-v3.js +5 -1
  82. package/dist/core/agents/state/activity-log.d.ts +3 -0
  83. package/dist/core/agents/state/activity-log.d.ts.map +1 -1
  84. package/dist/core/agents/state/activity-log.js +6 -3
  85. package/dist/core/agents/state/heartbeat-writer.d.ts +6 -0
  86. package/dist/core/agents/state/heartbeat-writer.d.ts.map +1 -1
  87. package/dist/core/agents/state/heartbeat-writer.js +18 -0
  88. package/dist/core/agents/state/live-coordination-view.d.ts +5 -7
  89. package/dist/core/agents/state/live-coordination-view.d.ts.map +1 -1
  90. package/dist/core/agents/state/live-coordination-view.js +15 -90
  91. package/dist/core/agents/state/live-coordination-writer.d.ts +12 -0
  92. package/dist/core/agents/state/live-coordination-writer.d.ts.map +1 -0
  93. package/dist/core/agents/state/live-coordination-writer.js +92 -0
  94. package/dist/core/artifacts/index.d.ts +21 -0
  95. package/dist/core/artifacts/index.d.ts.map +1 -1
  96. package/dist/core/artifacts/index.js +46 -1
  97. package/dist/core/config.d.ts +62 -4
  98. package/dist/core/config.d.ts.map +1 -1
  99. package/dist/core/config.js +98 -4
  100. package/dist/core/conversations/archive.d.ts +49 -0
  101. package/dist/core/conversations/archive.d.ts.map +1 -0
  102. package/dist/core/conversations/archive.js +136 -0
  103. package/dist/core/conversations/catalog.d.ts +10 -0
  104. package/dist/core/conversations/catalog.d.ts.map +1 -0
  105. package/dist/core/conversations/catalog.js +72 -0
  106. package/dist/core/conversations/context-pack.d.ts +6 -0
  107. package/dist/core/conversations/context-pack.d.ts.map +1 -0
  108. package/dist/core/conversations/context-pack.js +60 -0
  109. package/dist/core/conversations/contract.d.ts +155 -0
  110. package/dist/core/conversations/contract.d.ts.map +1 -0
  111. package/dist/core/conversations/contract.js +1 -0
  112. package/dist/core/conversations/evaluation.d.ts +16 -0
  113. package/dist/core/conversations/evaluation.d.ts.map +1 -0
  114. package/dist/core/conversations/evaluation.js +9 -0
  115. package/dist/core/conversations/index.d.ts +10 -0
  116. package/dist/core/conversations/index.d.ts.map +1 -0
  117. package/dist/core/conversations/index.js +9 -0
  118. package/dist/core/conversations/lifecycle.d.ts +28 -0
  119. package/dist/core/conversations/lifecycle.d.ts.map +1 -0
  120. package/dist/core/conversations/lifecycle.js +29 -0
  121. package/dist/core/conversations/normalize.d.ts +14 -0
  122. package/dist/core/conversations/normalize.d.ts.map +1 -0
  123. package/dist/core/conversations/normalize.js +82 -0
  124. package/dist/core/conversations/query.d.ts +8 -0
  125. package/dist/core/conversations/query.d.ts.map +1 -0
  126. package/dist/core/conversations/query.js +280 -0
  127. package/dist/core/conversations/search-index.d.ts +9 -0
  128. package/dist/core/conversations/search-index.d.ts.map +1 -0
  129. package/dist/core/conversations/search-index.js +29 -0
  130. package/dist/core/events/legacy-storage/canary.d.ts +18 -0
  131. package/dist/core/events/legacy-storage/canary.d.ts.map +1 -0
  132. package/dist/core/events/legacy-storage/canary.js +150 -0
  133. package/dist/core/events/legacy-storage/fence.d.ts +15 -0
  134. package/dist/core/events/legacy-storage/fence.d.ts.map +1 -0
  135. package/dist/core/events/legacy-storage/fence.js +115 -0
  136. package/dist/core/events/legacy-storage/index.d.ts +6 -0
  137. package/dist/core/events/legacy-storage/index.d.ts.map +1 -0
  138. package/dist/core/events/legacy-storage/index.js +5 -0
  139. package/dist/core/events/legacy-storage/inventory.d.ts +10 -0
  140. package/dist/core/events/legacy-storage/inventory.d.ts.map +1 -0
  141. package/dist/core/events/legacy-storage/inventory.js +40 -0
  142. package/dist/core/events/legacy-storage/manifest.d.ts +23 -0
  143. package/dist/core/events/legacy-storage/manifest.d.ts.map +1 -0
  144. package/dist/core/events/legacy-storage/manifest.js +108 -0
  145. package/dist/core/events/legacy-storage/reader.d.ts +15 -0
  146. package/dist/core/events/legacy-storage/reader.d.ts.map +1 -0
  147. package/dist/core/events/legacy-storage/reader.js +154 -0
  148. package/dist/core/events/v3/authority-outbox.d.ts +7 -2
  149. package/dist/core/events/v3/authority-outbox.d.ts.map +1 -1
  150. package/dist/core/events/v3/authority-outbox.js +16 -3
  151. package/dist/core/events/v3/base-contract.d.ts +81 -41
  152. package/dist/core/events/v3/base-contract.d.ts.map +1 -1
  153. package/dist/core/events/v3/base-contract.js +17 -7
  154. package/dist/core/events/v3/bootstrap.d.ts +39 -0
  155. package/dist/core/events/v3/bootstrap.d.ts.map +1 -1
  156. package/dist/core/events/v3/bootstrap.js +167 -3
  157. package/dist/core/events/v3/capabilities.js +3 -3
  158. package/dist/core/events/v3/control-witness.d.ts +44 -0
  159. package/dist/core/events/v3/control-witness.d.ts.map +1 -0
  160. package/dist/core/events/v3/control-witness.js +233 -0
  161. package/dist/core/events/v3/control-writer.d.ts +4 -0
  162. package/dist/core/events/v3/control-writer.d.ts.map +1 -0
  163. package/dist/core/events/v3/control-writer.js +16 -0
  164. package/dist/core/events/v3/control.d.ts +8 -2
  165. package/dist/core/events/v3/control.d.ts.map +1 -1
  166. package/dist/core/events/v3/control.js +46 -18
  167. package/dist/core/events/v3/coordination-transaction-recovery.d.ts +42 -0
  168. package/dist/core/events/v3/coordination-transaction-recovery.d.ts.map +1 -0
  169. package/dist/core/events/v3/coordination-transaction-recovery.js +342 -0
  170. package/dist/core/events/v3/coordination-view.d.ts.map +1 -1
  171. package/dist/core/events/v3/coordination-view.js +16 -1
  172. package/dist/core/events/v3/generated.d.ts +1 -1
  173. package/dist/core/events/v3/generated.js +1 -1
  174. package/dist/core/events/v3/index.d.ts +4 -2
  175. package/dist/core/events/v3/index.d.ts.map +1 -1
  176. package/dist/core/events/v3/index.js +3 -1
  177. package/dist/core/events/v3/live-route-observer.d.ts +31 -0
  178. package/dist/core/events/v3/live-route-observer.d.ts.map +1 -0
  179. package/dist/core/events/v3/live-route-observer.js +58 -0
  180. package/dist/core/events/v3/live-routing.d.ts +13 -21
  181. package/dist/core/events/v3/live-routing.d.ts.map +1 -1
  182. package/dist/core/events/v3/live-routing.js +45 -41
  183. package/dist/core/events/v3/producers/coordination-recorder.d.ts +11 -1
  184. package/dist/core/events/v3/producers/coordination-recorder.d.ts.map +1 -1
  185. package/dist/core/events/v3/producers/coordination-recorder.js +76 -10
  186. package/dist/core/events/v3/producers/diagnostic-summaries.d.ts +129 -0
  187. package/dist/core/events/v3/producers/diagnostic-summaries.d.ts.map +1 -0
  188. package/dist/core/events/v3/producers/diagnostic-summaries.js +499 -0
  189. package/dist/core/events/v3/producers/hook-base.js +1 -1
  190. package/dist/core/events/v3/producers/intake.d.ts +7 -0
  191. package/dist/core/events/v3/producers/intake.d.ts.map +1 -1
  192. package/dist/core/events/v3/producers/intake.js +25 -2
  193. package/dist/core/events/v3/producers/producer-state-observer.d.ts +8 -0
  194. package/dist/core/events/v3/producers/producer-state-observer.d.ts.map +1 -0
  195. package/dist/core/events/v3/producers/producer-state-observer.js +45 -0
  196. package/dist/core/events/v3/producers/recorder.d.ts +55 -1
  197. package/dist/core/events/v3/producers/recorder.d.ts.map +1 -1
  198. package/dist/core/events/v3/producers/recorder.js +353 -24
  199. package/dist/core/events/v3/reader.d.ts +51 -0
  200. package/dist/core/events/v3/reader.d.ts.map +1 -1
  201. package/dist/core/events/v3/reader.js +181 -1
  202. package/dist/core/events/v3/rotation-config.d.ts +9 -0
  203. package/dist/core/events/v3/rotation-config.d.ts.map +1 -0
  204. package/dist/core/events/v3/rotation-config.js +91 -0
  205. package/dist/core/events/v3/runtime-build.d.ts +11 -0
  206. package/dist/core/events/v3/runtime-build.d.ts.map +1 -0
  207. package/dist/core/events/v3/runtime-build.js +39 -0
  208. package/dist/core/events/v3/runtime-identity.d.ts +5 -0
  209. package/dist/core/events/v3/runtime-identity.d.ts.map +1 -0
  210. package/dist/core/events/v3/runtime-identity.js +18 -0
  211. package/dist/core/events/v3/runtime-telemetry-capabilities.d.ts +6 -5
  212. package/dist/core/events/v3/runtime-telemetry-capabilities.d.ts.map +1 -1
  213. package/dist/core/events/v3/runtime-telemetry-capabilities.js +1 -1
  214. package/dist/core/events/v3/support-storage/classify.d.ts +46 -0
  215. package/dist/core/events/v3/support-storage/classify.d.ts.map +1 -0
  216. package/dist/core/events/v3/support-storage/classify.js +149 -0
  217. package/dist/core/events/v3/support-storage/eligibility.d.ts +29 -0
  218. package/dist/core/events/v3/support-storage/eligibility.d.ts.map +1 -0
  219. package/dist/core/events/v3/support-storage/eligibility.js +35 -0
  220. package/dist/core/events/v3/support-storage/index.d.ts +10 -0
  221. package/dist/core/events/v3/support-storage/index.d.ts.map +1 -0
  222. package/dist/core/events/v3/support-storage/index.js +9 -0
  223. package/dist/core/events/v3/support-storage/inventory.d.ts +30 -0
  224. package/dist/core/events/v3/support-storage/inventory.d.ts.map +1 -0
  225. package/dist/core/events/v3/support-storage/inventory.js +94 -0
  226. package/dist/core/events/v3/support-storage/logical-authority.d.ts +14 -0
  227. package/dist/core/events/v3/support-storage/logical-authority.d.ts.map +1 -0
  228. package/dist/core/events/v3/support-storage/logical-authority.js +104 -0
  229. package/dist/core/events/v3/support-storage/maintenance.d.ts +98 -0
  230. package/dist/core/events/v3/support-storage/maintenance.d.ts.map +1 -0
  231. package/dist/core/events/v3/support-storage/maintenance.js +352 -0
  232. package/dist/core/events/v3/support-storage/pack-contract.d.ts +59 -0
  233. package/dist/core/events/v3/support-storage/pack-contract.d.ts.map +1 -0
  234. package/dist/core/events/v3/support-storage/pack-contract.js +249 -0
  235. package/dist/core/events/v3/support-storage/pack-reader.d.ts +34 -0
  236. package/dist/core/events/v3/support-storage/pack-reader.d.ts.map +1 -0
  237. package/dist/core/events/v3/support-storage/pack-reader.js +258 -0
  238. package/dist/core/events/v3/support-storage/pack-writer.d.ts +30 -0
  239. package/dist/core/events/v3/support-storage/pack-writer.d.ts.map +1 -0
  240. package/dist/core/events/v3/support-storage/pack-writer.js +268 -0
  241. package/dist/core/events/v3/support-storage/recovery.d.ts +15 -0
  242. package/dist/core/events/v3/support-storage/recovery.d.ts.map +1 -0
  243. package/dist/core/events/v3/support-storage/recovery.js +22 -0
  244. package/dist/core/events/v3/turn-telemetry.d.ts +14 -8
  245. package/dist/core/events/v3/turn-telemetry.d.ts.map +1 -1
  246. package/dist/core/events/v3/turn-telemetry.js +32 -2
  247. package/dist/core/events/v3/writer.d.ts +13 -1
  248. package/dist/core/events/v3/writer.d.ts.map +1 -1
  249. package/dist/core/events/v3/writer.js +126 -12
  250. package/dist/core/governor/plan-read.d.ts.map +1 -1
  251. package/dist/core/governor/plan-read.js +5 -21
  252. package/dist/core/governor/planning.js +6 -8
  253. package/dist/core/governor/service-read.d.ts +12 -0
  254. package/dist/core/governor/service-read.d.ts.map +1 -1
  255. package/dist/core/governor/service-read.js +266 -2
  256. package/dist/core/governor/service.d.ts +1 -0
  257. package/dist/core/governor/service.d.ts.map +1 -1
  258. package/dist/core/governor/service.js +53 -18
  259. package/dist/core/guard/evidence-v3.d.ts.map +1 -1
  260. package/dist/core/guard/evidence-v3.js +2 -0
  261. package/dist/core/hooks/adapter/events.d.ts.map +1 -1
  262. package/dist/core/hooks/adapter/events.js +1 -0
  263. package/dist/core/hooks/adapter/output.d.ts +4 -2
  264. package/dist/core/hooks/adapter/output.d.ts.map +1 -1
  265. package/dist/core/hooks/adapter/output.js +13 -5
  266. package/dist/core/hooks/adapter/runtime-telemetry.d.ts +27 -4
  267. package/dist/core/hooks/adapter/runtime-telemetry.d.ts.map +1 -1
  268. package/dist/core/hooks/adapter/runtime-telemetry.js +307 -6
  269. package/dist/core/hooks/cli.js +212 -30
  270. package/dist/core/hooks/effects/image-capture.d.ts +1 -1
  271. package/dist/core/hooks/effects/image-capture.d.ts.map +1 -1
  272. package/dist/core/hooks/effects/image-capture.js +4 -2
  273. package/dist/core/hooks/remediation-cap.d.ts +8 -3
  274. package/dist/core/hooks/remediation-cap.d.ts.map +1 -1
  275. package/dist/core/hooks/remediation-cap.js +3 -11
  276. package/dist/core/hooks/resolve/coord-root.d.ts +22 -9
  277. package/dist/core/hooks/resolve/coord-root.d.ts.map +1 -1
  278. package/dist/core/hooks/resolve/coord-root.js +92 -11
  279. package/dist/core/hooks/resolve/owner.d.ts.map +1 -1
  280. package/dist/core/hooks/resolve/owner.js +5 -0
  281. package/dist/core/hooks/resolve/transcript.d.ts +8 -0
  282. package/dist/core/hooks/resolve/transcript.d.ts.map +1 -1
  283. package/dist/core/hooks/resolve/transcript.js +11 -0
  284. package/dist/core/inbox/contract.d.ts +64 -0
  285. package/dist/core/inbox/contract.d.ts.map +1 -0
  286. package/dist/core/inbox/contract.js +13 -0
  287. package/dist/core/inbox/index.d.ts +5 -0
  288. package/dist/core/inbox/index.d.ts.map +1 -0
  289. package/dist/core/inbox/index.js +4 -0
  290. package/dist/core/inbox/lifecycle.d.ts +22 -0
  291. package/dist/core/inbox/lifecycle.d.ts.map +1 -0
  292. package/dist/core/inbox/lifecycle.js +41 -0
  293. package/dist/core/inbox/service.d.ts +36 -0
  294. package/dist/core/inbox/service.d.ts.map +1 -0
  295. package/dist/core/inbox/service.js +210 -0
  296. package/dist/core/inbox/watcher.d.ts +7 -0
  297. package/dist/core/inbox/watcher.d.ts.map +1 -0
  298. package/dist/core/inbox/watcher.js +26 -0
  299. package/dist/core/presence/codec-digest.d.ts.map +1 -1
  300. package/dist/core/presence/codec-digest.js +14 -3
  301. package/dist/core/presence/relay-client.d.ts +1 -0
  302. package/dist/core/presence/relay-client.d.ts.map +1 -1
  303. package/dist/core/presence/relay-client.js +52 -8
  304. package/dist/core/semantic/adapters.d.ts +11 -8
  305. package/dist/core/semantic/adapters.d.ts.map +1 -1
  306. package/dist/core/semantic/adapters.js +169 -31
  307. package/dist/core/semantic/contract.d.ts +532 -48
  308. package/dist/core/semantic/contract.d.ts.map +1 -1
  309. package/dist/core/semantic/contract.js +104 -3
  310. package/dist/core/semantic/index.d.ts +7 -3
  311. package/dist/core/semantic/index.d.ts.map +1 -1
  312. package/dist/core/semantic/index.js +7 -3
  313. package/dist/core/semantic/once.d.ts +6 -1
  314. package/dist/core/semantic/once.d.ts.map +1 -1
  315. package/dist/core/semantic/once.js +80 -9
  316. package/dist/core/semantic/prompt.d.ts.map +1 -1
  317. package/dist/core/semantic/prompt.js +14 -1
  318. package/dist/core/semantic/review.d.ts +144 -0
  319. package/dist/core/semantic/review.d.ts.map +1 -0
  320. package/dist/core/semantic/review.js +544 -0
  321. package/dist/core/semantic/routes.d.ts +10 -0
  322. package/dist/core/semantic/routes.d.ts.map +1 -0
  323. package/dist/core/semantic/routes.js +21 -0
  324. package/dist/core/semantic/scheduler.d.ts +14 -3
  325. package/dist/core/semantic/scheduler.d.ts.map +1 -1
  326. package/dist/core/semantic/scheduler.js +30 -6
  327. package/dist/core/semantic/service-status.d.ts +20 -0
  328. package/dist/core/semantic/service-status.d.ts.map +1 -1
  329. package/dist/core/semantic/service-status.js +60 -4
  330. package/dist/core/semantic/service.d.ts +1 -0
  331. package/dist/core/semantic/service.d.ts.map +1 -1
  332. package/dist/core/semantic/service.js +104 -15
  333. package/dist/core/semantic/soak.d.ts +75 -0
  334. package/dist/core/semantic/soak.d.ts.map +1 -0
  335. package/dist/core/semantic/soak.js +476 -0
  336. package/dist/core/semantic/storage.d.ts +11 -1
  337. package/dist/core/semantic/storage.d.ts.map +1 -1
  338. package/dist/core/semantic/storage.js +4 -3
  339. package/dist/core/semantic/usage.d.ts +43 -0
  340. package/dist/core/semantic/usage.d.ts.map +1 -0
  341. package/dist/core/semantic/usage.js +193 -0
  342. package/dist/core/semantic/validate.d.ts +3 -1
  343. package/dist/core/semantic/validate.d.ts.map +1 -1
  344. package/dist/core/semantic/validate.js +34 -1
  345. package/dist/core/storage/buffer.d.ts +28 -0
  346. package/dist/core/storage/buffer.d.ts.map +1 -0
  347. package/dist/core/storage/buffer.js +101 -0
  348. package/dist/core/storage/builtins.d.ts +3 -0
  349. package/dist/core/storage/builtins.d.ts.map +1 -0
  350. package/dist/core/storage/builtins.js +683 -0
  351. package/dist/core/storage/catalog.d.ts +19 -0
  352. package/dist/core/storage/catalog.d.ts.map +1 -0
  353. package/dist/core/storage/catalog.js +365 -0
  354. package/dist/core/storage/config.d.ts +16 -0
  355. package/dist/core/storage/config.d.ts.map +1 -0
  356. package/dist/core/storage/config.js +311 -0
  357. package/dist/core/storage/contract.d.ts +275 -0
  358. package/dist/core/storage/contract.d.ts.map +1 -0
  359. package/dist/core/storage/contract.js +3 -0
  360. package/dist/core/storage/durable-history.d.ts +36 -0
  361. package/dist/core/storage/durable-history.d.ts.map +1 -0
  362. package/dist/core/storage/durable-history.js +606 -0
  363. package/dist/core/storage/health.d.ts +4 -0
  364. package/dist/core/storage/health.d.ts.map +1 -0
  365. package/dist/core/storage/health.js +65 -0
  366. package/dist/core/storage/index.d.ts +16 -0
  367. package/dist/core/storage/index.d.ts.map +1 -0
  368. package/dist/core/storage/index.js +15 -0
  369. package/dist/core/storage/inventory.d.ts +25 -0
  370. package/dist/core/storage/inventory.d.ts.map +1 -0
  371. package/dist/core/storage/inventory.js +666 -0
  372. package/dist/core/storage/jsonl.d.ts +52 -0
  373. package/dist/core/storage/jsonl.d.ts.map +1 -0
  374. package/dist/core/storage/jsonl.js +156 -0
  375. package/dist/core/storage/log-retention.d.ts +52 -0
  376. package/dist/core/storage/log-retention.d.ts.map +1 -0
  377. package/dist/core/storage/log-retention.js +419 -0
  378. package/dist/core/storage/logger.d.ts +82 -0
  379. package/dist/core/storage/logger.d.ts.map +1 -0
  380. package/dist/core/storage/logger.js +411 -0
  381. package/dist/core/storage/maintenance-providers.d.ts +26 -0
  382. package/dist/core/storage/maintenance-providers.d.ts.map +1 -0
  383. package/dist/core/storage/maintenance-providers.js +141 -0
  384. package/dist/core/storage/maintenance.d.ts +125 -0
  385. package/dist/core/storage/maintenance.d.ts.map +1 -0
  386. package/dist/core/storage/maintenance.js +609 -0
  387. package/dist/core/storage/metrics.d.ts +60 -0
  388. package/dist/core/storage/metrics.d.ts.map +1 -0
  389. package/dist/core/storage/metrics.js +134 -0
  390. package/dist/core/storage/policy.d.ts +7 -0
  391. package/dist/core/storage/policy.d.ts.map +1 -0
  392. package/dist/core/storage/policy.js +110 -0
  393. package/dist/core/storage/process-log.d.ts +38 -0
  394. package/dist/core/storage/process-log.d.ts.map +1 -0
  395. package/dist/core/storage/process-log.js +165 -0
  396. package/dist/core/storage/query.d.ts +34 -0
  397. package/dist/core/storage/query.d.ts.map +1 -0
  398. package/dist/core/storage/query.js +295 -0
  399. package/dist/core/storage/receipts.d.ts +23 -0
  400. package/dist/core/storage/receipts.d.ts.map +1 -0
  401. package/dist/core/storage/receipts.js +117 -0
  402. package/dist/core/storage/segments.d.ts +84 -0
  403. package/dist/core/storage/segments.d.ts.map +1 -0
  404. package/dist/core/storage/segments.js +542 -0
  405. package/dist/core/storage/sink-graph.d.ts +65 -0
  406. package/dist/core/storage/sink-graph.d.ts.map +1 -0
  407. package/dist/core/storage/sink-graph.js +213 -0
  408. package/dist/core/storage/storm-control.d.ts +23 -0
  409. package/dist/core/storage/storm-control.d.ts.map +1 -0
  410. package/dist/core/storage/storm-control.js +59 -0
  411. package/dist/core/work/state.d.ts.map +1 -1
  412. package/dist/core/work/state.js +10 -14
  413. package/dist/core/workflow/live-session-v3.d.ts.map +1 -1
  414. package/dist/core/workflow/live-session-v3.js +2 -1
  415. package/dist/index.d.ts +2 -0
  416. package/dist/index.d.ts.map +1 -1
  417. package/dist/index.js +2 -0
  418. package/dist/lazy-commands.d.ts +26 -0
  419. package/dist/lazy-commands.d.ts.map +1 -0
  420. package/dist/lazy-commands.js +210 -0
  421. package/dist/lib/docs-lint.d.ts +2 -0
  422. package/dist/lib/docs-lint.d.ts.map +1 -1
  423. package/dist/lib/docs-lint.js +45 -80
  424. package/dist/lib/docs-metadata-audit.d.ts +3 -0
  425. package/dist/lib/docs-metadata-audit.d.ts.map +1 -1
  426. package/dist/lib/docs-metadata-audit.js +13 -23
  427. package/dist/lib/docs-metadata-sync.d.ts +1 -0
  428. package/dist/lib/docs-metadata-sync.d.ts.map +1 -1
  429. package/dist/lib/docs-metadata-sync.js +28 -10
  430. package/dist/lib/docs-repository-view.d.ts +22 -0
  431. package/dist/lib/docs-repository-view.d.ts.map +1 -0
  432. package/dist/lib/docs-repository-view.js +185 -0
  433. package/dist/lib/http/client.d.ts +11 -5
  434. package/dist/lib/http/client.d.ts.map +1 -1
  435. package/dist/lib/http/client.js +22 -4
  436. package/dist/lib/http/index.d.ts +1 -1
  437. package/dist/lib/http/index.d.ts.map +1 -1
  438. package/dist/lib/http/index.js +1 -1
  439. package/dist/lib/indexer-exclusions.d.ts +27 -0
  440. package/dist/lib/indexer-exclusions.d.ts.map +1 -0
  441. package/dist/lib/indexer-exclusions.js +176 -0
  442. package/dist/lib/instructions/templates.d.ts.map +1 -1
  443. package/dist/lib/instructions/templates.js +5 -0
  444. package/dist/lib/local-file-url.d.ts +9 -0
  445. package/dist/lib/local-file-url.d.ts.map +1 -0
  446. package/dist/lib/local-file-url.js +20 -0
  447. package/dist/lib/web-performance.d.ts +118 -0
  448. package/dist/lib/web-performance.d.ts.map +1 -0
  449. package/dist/lib/web-performance.js +192 -0
  450. package/package.json +29 -2
  451. package/schemas/config.schema.json +58 -0
  452. package/schemas/event-v3.schema.json +324 -112
  453. package/src/commander.ts +462 -95
  454. package/src/commands/agents.ts +517 -190
  455. package/src/commands/backup.ts +18 -14
  456. package/src/commands/browse-session.ts +12 -0
  457. package/src/commands/browse.ts +6 -7
  458. package/src/commands/conversations.ts +279 -0
  459. package/src/commands/deinit.ts +6 -0
  460. package/src/commands/docs.ts +25 -6
  461. package/src/commands/doctor.ts +75 -9
  462. package/src/commands/fetch.ts +7 -6
  463. package/src/commands/files.ts +143 -0
  464. package/src/commands/governor.ts +13 -12
  465. package/src/commands/inbox.ts +61 -0
  466. package/src/commands/init.ts +78 -16
  467. package/src/commands/ledger-v3.ts +421 -1
  468. package/src/commands/logs.ts +224 -0
  469. package/src/commands/messages.ts +61 -0
  470. package/src/commands/outline.ts +6 -2
  471. package/src/commands/read.ts +6 -2
  472. package/src/commands/semantic.ts +66 -1
  473. package/src/commands/storage.ts +310 -0
  474. package/src/commands/tunnel.ts +66 -52
  475. package/src/commands/web.ts +77 -7
  476. package/src/commands/work.ts +3 -3
  477. package/src/commands/workflow.ts +13 -13
  478. package/src/core/agents/cli.ts +259 -53
  479. package/src/core/agents/live-authority-v3.ts +341 -10
  480. package/src/core/agents/live-lifecycle-v3.ts +6 -1
  481. package/src/core/agents/live-observation-v3.ts +6 -1
  482. package/src/core/agents/render/prompt-context.ts +27 -6
  483. package/src/core/agents/rules/stop-hook.ts +107 -16
  484. package/src/core/agents/rules/verdict.ts +1 -0
  485. package/src/core/agents/session-events.ts +4 -0
  486. package/src/core/agents/session-finalization-state-v3.ts +1 -1
  487. package/src/core/agents/session-finalizer-v3.ts +4 -1
  488. package/src/core/agents/state/activity-log.ts +7 -2
  489. package/src/core/agents/state/heartbeat-writer.ts +27 -0
  490. package/src/core/agents/state/live-coordination-view.ts +16 -105
  491. package/src/core/agents/state/live-coordination-writer.ts +141 -0
  492. package/src/core/artifacts/index.ts +64 -1
  493. package/src/core/config.ts +126 -5
  494. package/src/core/conversations/archive.ts +237 -0
  495. package/src/core/conversations/catalog.ts +79 -0
  496. package/src/core/conversations/context-pack.ts +72 -0
  497. package/src/core/conversations/contract.ts +178 -0
  498. package/src/core/conversations/evaluation.ts +30 -0
  499. package/src/core/conversations/index.ts +9 -0
  500. package/src/core/conversations/lifecycle.ts +63 -0
  501. package/src/core/conversations/normalize.ts +105 -0
  502. package/src/core/conversations/query.ts +318 -0
  503. package/src/core/conversations/search-index.ts +48 -0
  504. package/src/core/events/legacy-storage/canary.ts +177 -0
  505. package/src/core/events/legacy-storage/fence.ts +129 -0
  506. package/src/core/events/legacy-storage/index.ts +5 -0
  507. package/src/core/events/legacy-storage/inventory.ts +51 -0
  508. package/src/core/events/legacy-storage/manifest.ts +136 -0
  509. package/src/core/events/legacy-storage/reader.ts +178 -0
  510. package/src/core/events/v3/authority-outbox.ts +22 -1
  511. package/src/core/events/v3/base-contract.ts +17 -7
  512. package/src/core/events/v3/bootstrap.ts +195 -2
  513. package/src/core/events/v3/capabilities.ts +3 -3
  514. package/src/core/events/v3/control-witness.ts +339 -0
  515. package/src/core/events/v3/control-writer.ts +16 -0
  516. package/src/core/events/v3/control.ts +54 -18
  517. package/src/core/events/v3/coordination-transaction-recovery.ts +477 -0
  518. package/src/core/events/v3/coordination-view.ts +17 -1
  519. package/src/core/events/v3/generated.ts +1 -1
  520. package/src/core/events/v3/index.ts +5 -2
  521. package/src/core/events/v3/live-route-observer.ts +80 -0
  522. package/src/core/events/v3/live-routing.ts +64 -46
  523. package/src/core/events/v3/producers/coordination-recorder.ts +95 -10
  524. package/src/core/events/v3/producers/diagnostic-summaries.ts +593 -0
  525. package/src/core/events/v3/producers/hook-base.ts +1 -1
  526. package/src/core/events/v3/producers/intake.ts +30 -2
  527. package/src/core/events/v3/producers/producer-state-observer.ts +52 -0
  528. package/src/core/events/v3/producers/recorder.ts +571 -33
  529. package/src/core/events/v3/reader.ts +243 -2
  530. package/src/core/events/v3/rotation-config.ts +98 -0
  531. package/src/core/events/v3/runtime-build.ts +41 -0
  532. package/src/core/events/v3/runtime-identity.ts +16 -0
  533. package/src/core/events/v3/runtime-telemetry-capabilities.ts +14 -8
  534. package/src/core/events/v3/support-storage/classify.ts +209 -0
  535. package/src/core/events/v3/support-storage/eligibility.ts +58 -0
  536. package/src/core/events/v3/support-storage/index.ts +9 -0
  537. package/src/core/events/v3/support-storage/inventory.ts +135 -0
  538. package/src/core/events/v3/support-storage/logical-authority.ts +117 -0
  539. package/src/core/events/v3/support-storage/maintenance.ts +501 -0
  540. package/src/core/events/v3/support-storage/pack-contract.ts +337 -0
  541. package/src/core/events/v3/support-storage/pack-reader.ts +346 -0
  542. package/src/core/events/v3/support-storage/pack-writer.ts +352 -0
  543. package/src/core/events/v3/support-storage/recovery.ts +43 -0
  544. package/src/core/events/v3/turn-telemetry.ts +58 -7
  545. package/src/core/events/v3/writer.ts +168 -16
  546. package/src/core/governor/plan-read.ts +5 -18
  547. package/src/core/governor/planning.ts +5 -8
  548. package/src/core/governor/service-read.ts +320 -2
  549. package/src/core/governor/service.ts +49 -22
  550. package/src/core/guard/evidence-v3.ts +1 -0
  551. package/src/core/hooks/adapter/events.ts +1 -0
  552. package/src/core/hooks/adapter/output.ts +12 -5
  553. package/src/core/hooks/adapter/runtime-telemetry.ts +408 -13
  554. package/src/core/hooks/cli.ts +226 -32
  555. package/src/core/hooks/effects/image-capture.ts +4 -1
  556. package/src/core/hooks/remediation-cap.ts +12 -6
  557. package/src/core/hooks/resolve/coord-root.ts +91 -11
  558. package/src/core/hooks/resolve/owner.ts +4 -0
  559. package/src/core/hooks/resolve/transcript.ts +18 -0
  560. package/src/core/inbox/contract.ts +81 -0
  561. package/src/core/inbox/index.ts +4 -0
  562. package/src/core/inbox/lifecycle.ts +104 -0
  563. package/src/core/inbox/service.ts +305 -0
  564. package/src/core/inbox/watcher.ts +36 -0
  565. package/src/core/presence/codec-digest.ts +15 -9
  566. package/src/core/presence/relay-client.ts +55 -7
  567. package/src/core/semantic/adapters.ts +200 -41
  568. package/src/core/semantic/contract.ts +135 -3
  569. package/src/core/semantic/index.ts +76 -2
  570. package/src/core/semantic/once.ts +93 -7
  571. package/src/core/semantic/prompt.ts +13 -1
  572. package/src/core/semantic/review.ts +803 -0
  573. package/src/core/semantic/routes.ts +30 -0
  574. package/src/core/semantic/scheduler.ts +49 -5
  575. package/src/core/semantic/service-status.ts +99 -5
  576. package/src/core/semantic/service.ts +116 -15
  577. package/src/core/semantic/soak.ts +638 -0
  578. package/src/core/semantic/storage.ts +20 -6
  579. package/src/core/semantic/usage.ts +272 -0
  580. package/src/core/semantic/validate.ts +31 -0
  581. package/src/core/storage/buffer.ts +124 -0
  582. package/src/core/storage/builtins.ts +916 -0
  583. package/src/core/storage/catalog.ts +467 -0
  584. package/src/core/storage/config.ts +423 -0
  585. package/src/core/storage/contract.ts +342 -0
  586. package/src/core/storage/durable-history.ts +738 -0
  587. package/src/core/storage/health.ts +76 -0
  588. package/src/core/storage/index.ts +15 -0
  589. package/src/core/storage/inventory.ts +859 -0
  590. package/src/core/storage/jsonl.ts +213 -0
  591. package/src/core/storage/log-retention.ts +555 -0
  592. package/src/core/storage/logger.ts +546 -0
  593. package/src/core/storage/maintenance-providers.ts +200 -0
  594. package/src/core/storage/maintenance.ts +929 -0
  595. package/src/core/storage/metrics.ts +199 -0
  596. package/src/core/storage/policy.ts +141 -0
  597. package/src/core/storage/process-log.ts +203 -0
  598. package/src/core/storage/query.ts +360 -0
  599. package/src/core/storage/receipts.ts +162 -0
  600. package/src/core/storage/segments.ts +721 -0
  601. package/src/core/storage/sink-graph.ts +343 -0
  602. package/src/core/storage/storm-control.ts +91 -0
  603. package/src/core/work/state.ts +12 -21
  604. package/src/core/workflow/live-session-v3.ts +2 -4
  605. package/src/index.ts +2 -0
  606. package/src/lazy-commands.ts +294 -0
  607. package/src/lib/docs-lint.ts +58 -77
  608. package/src/lib/docs-metadata-audit.ts +26 -21
  609. package/src/lib/docs-metadata-sync.ts +32 -9
  610. package/src/lib/docs-repository-view.ts +220 -0
  611. package/src/lib/http/client.ts +44 -8
  612. package/src/lib/http/index.ts +6 -1
  613. package/src/lib/indexer-exclusions.ts +173 -0
  614. package/src/lib/instructions/templates.ts +5 -0
  615. package/src/lib/local-file-url.ts +31 -0
  616. package/src/lib/web-performance.ts +335 -0
@@ -0,0 +1,859 @@
1
+ import type { Dir, Stats } from "node:fs";
2
+ import {
3
+ lstat as defaultLstat,
4
+ opendir as defaultOpendir,
5
+ realpath as defaultRealpath,
6
+ } from "node:fs/promises";
7
+ import { isAbsolute, join, relative, resolve, sep } from "node:path";
8
+ import type { HarneryStorageCatalog } from "./catalog.ts";
9
+ import {
10
+ HARNERY_STORAGE_INVENTORY_SCHEMA,
11
+ type HarneryRegisteredStorageFamily,
12
+ type HarneryStorageClass,
13
+ type HarneryStorageFamilyInventory,
14
+ type HarneryStorageInventoryReport,
15
+ type HarneryStorageInventoryTotals,
16
+ type HarneryStorageIssueSummary,
17
+ type HarneryStorageMeasurement,
18
+ type HarneryStorageReasonCode,
19
+ type HarneryStorageRoot,
20
+ type HarneryStorageRootInventory,
21
+ } from "./contract.ts";
22
+ import { inspectStructuredLogRetention } from "./log-retention.ts";
23
+
24
+ const MAX_CONCURRENCY = 16;
25
+
26
+ export interface HarneryStorageInventoryOptions {
27
+ now?: () => Date;
28
+ allocatedBytes?: (stats: Stats) => number | undefined;
29
+ fs?: Partial<HarneryStorageInventoryFs>;
30
+ }
31
+
32
+ export interface HarneryStorageInventoryFs {
33
+ lstat(path: string): Promise<Stats>;
34
+ opendir(path: string): Promise<Dir>;
35
+ realpath(path: string): Promise<string>;
36
+ }
37
+
38
+ export interface HarneryStorageInventoryFilter {
39
+ family_id?: string;
40
+ storage_class?: HarneryStorageClass;
41
+ }
42
+
43
+ interface MutableTotals {
44
+ regular_files: number;
45
+ logical_bytes: number;
46
+ allocated_bytes: number;
47
+ allocated_available: boolean;
48
+ allocated_identities: Set<string>;
49
+ }
50
+
51
+ interface RootAccumulator {
52
+ root: HarneryStorageRoot;
53
+ index: number;
54
+ base_present: boolean;
55
+ matched: boolean;
56
+ totals: MutableTotals;
57
+ reasons: Set<HarneryStorageReasonCode>;
58
+ }
59
+
60
+ interface FamilyAccumulator {
61
+ family: HarneryRegisteredStorageFamily;
62
+ roots: RootAccumulator[];
63
+ totals: MutableTotals;
64
+ reasons: Set<HarneryStorageReasonCode>;
65
+ }
66
+
67
+ interface ScanState {
68
+ catalog: HarneryStorageCatalog;
69
+ coordStorageRoot: string;
70
+ families: Map<string, FamilyAccumulator>;
71
+ totals: MutableTotals;
72
+ coordinationRootTotals: MutableTotals;
73
+ externalRootTotals: MutableTotals;
74
+ issues: Map<HarneryStorageReasonCode, number>;
75
+ allocatedBytes: (stats: Stats) => number | undefined;
76
+ fs: HarneryStorageInventoryFs;
77
+ }
78
+
79
+ interface ScanPath {
80
+ physical: string;
81
+ logical: string;
82
+ expectedIdentity?: FileIdentity;
83
+ }
84
+
85
+ interface FileIdentity {
86
+ dev: number;
87
+ ino: number;
88
+ }
89
+
90
+ /**
91
+ * Inventory registered storage with metadata-only, depth-first traversal.
92
+ * The complete `.harnery` root is scanned once; outside it, only explicit
93
+ * registered filesystem roots are visited.
94
+ */
95
+ export async function inventoryStorage(
96
+ catalog: HarneryStorageCatalog,
97
+ options: HarneryStorageInventoryOptions = {},
98
+ ): Promise<HarneryStorageInventoryReport> {
99
+ const coordStorageRoot = resolve(catalog.context.coord_root, ".harnery");
100
+ const capturedAt = (options.now ?? (() => new Date()))();
101
+ const state: ScanState = {
102
+ catalog,
103
+ coordStorageRoot,
104
+ families: new Map(
105
+ catalog.families.map((family) => [
106
+ family.id,
107
+ {
108
+ family,
109
+ roots: family.resolved_roots.map((root, index) => ({
110
+ root,
111
+ index,
112
+ base_present: false,
113
+ matched: false,
114
+ totals: emptyTotals(),
115
+ reasons: new Set(),
116
+ })),
117
+ totals: emptyTotals(),
118
+ reasons: new Set(),
119
+ },
120
+ ]),
121
+ ),
122
+ totals: emptyTotals(),
123
+ coordinationRootTotals: emptyTotals(),
124
+ externalRootTotals: emptyTotals(),
125
+ issues: new Map(),
126
+ allocatedBytes: options.allocatedBytes ?? allocatedBytes,
127
+ fs: {
128
+ lstat: options.fs?.lstat ?? defaultLstat,
129
+ opendir: options.fs?.opendir ?? defaultOpendir,
130
+ realpath: options.fs?.realpath ?? defaultRealpath,
131
+ },
132
+ };
133
+
134
+ await inspectRegisteredRoots(state);
135
+ await scanBoundary(state, coordStorageRoot, true);
136
+ for (const boundary of externalBoundaries(state)) {
137
+ await scanBoundary(state, boundary, false);
138
+ }
139
+
140
+ return {
141
+ schema: HARNERY_STORAGE_INVENTORY_SCHEMA,
142
+ captured_at: capturedAt.toISOString(),
143
+ privacy: { content_read: false, path_mode: "aggregate-labels" },
144
+ scan: {
145
+ mode: "streaming-lstat",
146
+ max_concurrency: MAX_CONCURRENCY,
147
+ project_filesystem_scope: ".harnery-and-registered-external-roots",
148
+ },
149
+ filter: {},
150
+ filesystem_totals: observedTotals(state.totals),
151
+ scope_totals: {
152
+ coordination_root: observedTotals(state.coordinationRootTotals),
153
+ registered_external_roots: observedTotals(state.externalRootTotals),
154
+ },
155
+ families: [...state.families.values()]
156
+ .map((family) => familyInventory(catalog, family, capturedAt))
157
+ .sort((left, right) => left.family_id.localeCompare(right.family_id)),
158
+ issues: issueRows(state.issues),
159
+ };
160
+ }
161
+
162
+ export function filterStorageInventory(
163
+ report: HarneryStorageInventoryReport,
164
+ filter: HarneryStorageInventoryFilter,
165
+ ): HarneryStorageInventoryReport {
166
+ return {
167
+ ...report,
168
+ filter: {
169
+ ...(filter.family_id ? { family_id: filter.family_id } : {}),
170
+ ...(filter.storage_class ? { storage_class: filter.storage_class } : {}),
171
+ },
172
+ families: report.families.filter(
173
+ (family) =>
174
+ (!filter.family_id || family.family_id === filter.family_id) &&
175
+ (!filter.storage_class || family.storage_class === filter.storage_class),
176
+ ),
177
+ };
178
+ }
179
+
180
+ function emptyTotals(): MutableTotals {
181
+ return {
182
+ regular_files: 0,
183
+ logical_bytes: 0,
184
+ allocated_bytes: 0,
185
+ allocated_available: true,
186
+ allocated_identities: new Set(),
187
+ };
188
+ }
189
+
190
+ async function inspectRegisteredRoots(state: ScanState): Promise<void> {
191
+ for (const family of state.families.values()) {
192
+ if (family.family.provider.inventory === "delegated") {
193
+ family.reasons.add("delegated_inventory_unavailable");
194
+ for (const root of family.roots) root.reasons.add("delegated_inventory_unavailable");
195
+ continue;
196
+ }
197
+ for (const root of family.roots) {
198
+ let metadata: Stats;
199
+ try {
200
+ metadata = await state.fs.lstat(root.root.path);
201
+ } catch (error) {
202
+ if (isMissing(error)) root.reasons.add("root_dormant");
203
+ else root.reasons.add("unreadable_path");
204
+ continue;
205
+ }
206
+ if (metadata.isSymbolicLink()) {
207
+ root.reasons.add("symlink_rejected");
208
+ continue;
209
+ }
210
+ const expectedDirectory = root.root.kind === "directory";
211
+ if (
212
+ (expectedDirectory && !metadata.isDirectory()) ||
213
+ (!expectedDirectory && !metadata.isFile())
214
+ ) {
215
+ root.reasons.add("wrong_root_type");
216
+ continue;
217
+ }
218
+ root.base_present = true;
219
+ }
220
+ }
221
+ }
222
+
223
+ function externalBoundaries(state: ScanState): string[] {
224
+ const boundaries = new Set<string>();
225
+ for (const family of state.families.values()) {
226
+ if (family.family.provider.inventory !== "filesystem") continue;
227
+ for (const { root } of family.roots) {
228
+ if (!within(state.coordStorageRoot, root.path)) boundaries.add(resolve(root.path));
229
+ }
230
+ }
231
+ const ordered = [...boundaries].sort(
232
+ (left, right) => left.length - right.length || left.localeCompare(right),
233
+ );
234
+ const collapsed: string[] = [];
235
+ for (const boundary of ordered) {
236
+ if (!collapsed.some((parent) => within(parent, boundary))) collapsed.push(boundary);
237
+ }
238
+ return collapsed;
239
+ }
240
+
241
+ async function scanBoundary(
242
+ state: ScanState,
243
+ boundary: string,
244
+ completeCoordinationRoot: boolean,
245
+ ): Promise<void> {
246
+ let metadata: Stats;
247
+ try {
248
+ metadata = await state.fs.lstat(boundary);
249
+ } catch (error) {
250
+ if (!isMissing(error)) recordIssue(state, "unreadable_path");
251
+ return;
252
+ }
253
+ if (metadata.isSymbolicLink()) {
254
+ recordBoundaryIssue(state, boundary, "symlink_rejected", completeCoordinationRoot);
255
+ return;
256
+ }
257
+ if (!metadata.isFile() && !metadata.isDirectory()) {
258
+ recordBoundaryIssue(state, boundary, "special_file_rejected", completeCoordinationRoot);
259
+ return;
260
+ }
261
+ let safeRoot: string;
262
+ try {
263
+ safeRoot = await state.fs.realpath(boundary);
264
+ } catch {
265
+ recordBoundaryIssue(state, boundary, "unreadable_path", completeCoordinationRoot);
266
+ return;
267
+ }
268
+ let targetMetadata: Stats;
269
+ try {
270
+ targetMetadata = await state.fs.lstat(safeRoot);
271
+ } catch {
272
+ recordBoundaryIssue(state, boundary, "unreadable_path", completeCoordinationRoot);
273
+ return;
274
+ }
275
+ if (
276
+ !sameIdentity(metadata, targetMetadata) ||
277
+ metadata.isDirectory() !== targetMetadata.isDirectory() ||
278
+ metadata.isFile() !== targetMetadata.isFile()
279
+ ) {
280
+ recordBoundaryIssue(state, boundary, "symlink_rejected", completeCoordinationRoot);
281
+ return;
282
+ }
283
+ if (metadata.isFile()) {
284
+ await recordRegularFile(
285
+ state,
286
+ safeRoot,
287
+ boundary,
288
+ metadata,
289
+ completeCoordinationRoot,
290
+ safeRoot,
291
+ );
292
+ return;
293
+ }
294
+ await scanDirectoryTree(state, safeRoot, boundary, metadata, completeCoordinationRoot);
295
+ }
296
+
297
+ async function scanDirectoryTree(
298
+ state: ScanState,
299
+ safeRoot: string,
300
+ logicalRoot: string,
301
+ rootMetadata: Stats,
302
+ completeCoordinationRoot: boolean,
303
+ ): Promise<void> {
304
+ const queue: ScanPath[] = [
305
+ {
306
+ physical: safeRoot,
307
+ logical: logicalRoot,
308
+ expectedIdentity: fileIdentity(rootMetadata),
309
+ },
310
+ ];
311
+ for (let index = 0; index < queue.length; index += 1) {
312
+ const current = queue[index]!;
313
+ const children = await scanDirectory(
314
+ state,
315
+ current.physical,
316
+ current.logical,
317
+ current.expectedIdentity,
318
+ safeRoot,
319
+ completeCoordinationRoot,
320
+ );
321
+ queue.push(...children);
322
+ }
323
+ }
324
+
325
+ async function scanDirectory(
326
+ state: ScanState,
327
+ directoryPath: string,
328
+ logicalDirectoryPath: string,
329
+ expectedIdentity: FileIdentity | undefined,
330
+ safeRoot: string,
331
+ completeCoordinationRoot: boolean,
332
+ ): Promise<ScanPath[]> {
333
+ let metadata: Stats;
334
+ try {
335
+ metadata = await state.fs.lstat(directoryPath);
336
+ } catch {
337
+ recordPathIssue(state, logicalDirectoryPath, "unreadable_path", completeCoordinationRoot);
338
+ return [];
339
+ }
340
+ if (metadata.isSymbolicLink()) {
341
+ recordPathIssue(state, logicalDirectoryPath, "symlink_rejected", completeCoordinationRoot);
342
+ return [];
343
+ }
344
+ if (expectedIdentity && !matchesIdentity(metadata, expectedIdentity)) {
345
+ recordPathIssue(state, logicalDirectoryPath, "symlink_rejected", completeCoordinationRoot);
346
+ return [];
347
+ }
348
+ if (!metadata.isDirectory()) {
349
+ recordPathIssue(state, logicalDirectoryPath, "wrong_root_type", completeCoordinationRoot);
350
+ return [];
351
+ }
352
+ let canonical: string;
353
+ try {
354
+ canonical = await state.fs.realpath(directoryPath);
355
+ } catch {
356
+ recordPathIssue(state, logicalDirectoryPath, "unreadable_path", completeCoordinationRoot);
357
+ return [];
358
+ }
359
+ if (!within(safeRoot, canonical)) {
360
+ recordPathIssue(state, logicalDirectoryPath, "symlink_rejected", completeCoordinationRoot);
361
+ return [];
362
+ }
363
+ let canonicalMetadata: Stats;
364
+ try {
365
+ canonicalMetadata = await state.fs.lstat(canonical);
366
+ } catch {
367
+ recordPathIssue(state, logicalDirectoryPath, "unreadable_path", completeCoordinationRoot);
368
+ return [];
369
+ }
370
+ if (!canonicalMetadata.isDirectory() || !sameIdentity(metadata, canonicalMetadata)) {
371
+ recordPathIssue(state, logicalDirectoryPath, "symlink_rejected", completeCoordinationRoot);
372
+ return [];
373
+ }
374
+ let directory: Dir;
375
+ try {
376
+ directory = await state.fs.opendir(canonical);
377
+ } catch {
378
+ recordPathIssue(state, logicalDirectoryPath, "unreadable_path", completeCoordinationRoot);
379
+ return [];
380
+ }
381
+ try {
382
+ const [revalidatedPath, revalidatedCanonical] = await Promise.all([
383
+ state.fs.lstat(directoryPath),
384
+ state.fs.lstat(canonical),
385
+ ]);
386
+ if (
387
+ revalidatedPath.isSymbolicLink() ||
388
+ !sameIdentity(metadata, revalidatedPath) ||
389
+ !sameIdentity(metadata, revalidatedCanonical)
390
+ ) {
391
+ await closeRejectedDirectory(directory);
392
+ recordPathIssue(state, logicalDirectoryPath, "symlink_rejected", completeCoordinationRoot);
393
+ return [];
394
+ }
395
+ } catch {
396
+ await closeRejectedDirectory(directory);
397
+ recordPathIssue(state, logicalDirectoryPath, "unreadable_path", completeCoordinationRoot);
398
+ return [];
399
+ }
400
+ const childDirectories: ScanPath[] = [];
401
+ let batch: ScanPath[] = [];
402
+ for await (const entry of directory) {
403
+ batch.push({
404
+ physical: join(canonical, entry.name),
405
+ logical: join(logicalDirectoryPath, entry.name),
406
+ });
407
+ if (batch.length === MAX_CONCURRENCY) {
408
+ childDirectories.push(
409
+ ...(await scanEntryBatch(state, batch, safeRoot, completeCoordinationRoot)),
410
+ );
411
+ batch = [];
412
+ }
413
+ }
414
+ if (batch.length > 0) {
415
+ childDirectories.push(
416
+ ...(await scanEntryBatch(state, batch, safeRoot, completeCoordinationRoot)),
417
+ );
418
+ }
419
+ return childDirectories;
420
+ }
421
+
422
+ async function scanEntryBatch(
423
+ state: ScanState,
424
+ paths: readonly ScanPath[],
425
+ safeRoot: string,
426
+ completeCoordinationRoot: boolean,
427
+ ): Promise<ScanPath[]> {
428
+ const children = await Promise.all(
429
+ paths.map((path) => scanEntry(state, path, safeRoot, completeCoordinationRoot)),
430
+ );
431
+ return children.filter((path): path is ScanPath => path !== undefined);
432
+ }
433
+
434
+ async function scanEntry(
435
+ state: ScanState,
436
+ path: ScanPath,
437
+ safeRoot: string,
438
+ completeCoordinationRoot: boolean,
439
+ ): Promise<ScanPath | undefined> {
440
+ let child: Stats;
441
+ try {
442
+ child = await state.fs.lstat(path.physical);
443
+ } catch {
444
+ recordPathIssue(state, path.logical, "unreadable_path", completeCoordinationRoot);
445
+ return undefined;
446
+ }
447
+ if (child.isSymbolicLink()) {
448
+ if (!allowsSymbolicLinkSkip(state, path.logical)) {
449
+ recordPathIssue(state, path.logical, "symlink_rejected", completeCoordinationRoot);
450
+ }
451
+ } else if (child.isDirectory()) {
452
+ return { ...path, expectedIdentity: fileIdentity(child) };
453
+ } else if (child.isFile()) {
454
+ await recordRegularFile(
455
+ state,
456
+ path.physical,
457
+ path.logical,
458
+ child,
459
+ completeCoordinationRoot,
460
+ safeRoot,
461
+ );
462
+ } else {
463
+ recordPathIssue(state, path.logical, "special_file_rejected", completeCoordinationRoot);
464
+ }
465
+ return undefined;
466
+ }
467
+
468
+ async function closeRejectedDirectory(directory: Dir): Promise<void> {
469
+ try {
470
+ await directory.close();
471
+ } catch {
472
+ // Rejection remains fail-closed even when the platform already closed it.
473
+ }
474
+ }
475
+
476
+ function sameIdentity(left: Stats, right: Stats): boolean {
477
+ return left.dev === right.dev && left.ino === right.ino;
478
+ }
479
+
480
+ function fileIdentity(stats: Stats): FileIdentity {
481
+ return { dev: stats.dev, ino: stats.ino };
482
+ }
483
+
484
+ function matchesIdentity(stats: Stats, identity: FileIdentity): boolean {
485
+ return stats.dev === identity.dev && stats.ino === identity.ino;
486
+ }
487
+
488
+ async function recordRegularFile(
489
+ state: ScanState,
490
+ physicalPath: string,
491
+ logicalPath: string,
492
+ metadata: Stats,
493
+ completeCoordinationRoot: boolean,
494
+ safeRoot: string,
495
+ ): Promise<void> {
496
+ let canonical: string;
497
+ let canonicalMetadata: Stats;
498
+ try {
499
+ canonical = await state.fs.realpath(physicalPath);
500
+ canonicalMetadata = await state.fs.lstat(canonical);
501
+ } catch {
502
+ recordPathIssue(state, logicalPath, "unreadable_path", completeCoordinationRoot);
503
+ return;
504
+ }
505
+ if (!within(safeRoot, canonical) || !sameIdentity(metadata, canonicalMetadata)) {
506
+ recordPathIssue(state, logicalPath, "symlink_rejected", completeCoordinationRoot);
507
+ return;
508
+ }
509
+ const matches = filesystemMatches(state, logicalPath);
510
+ if (!completeCoordinationRoot && matches.length === 0) return;
511
+ const hardLinkAmbiguous = metadata.nlink > 1 && !allowsHardLink(state, logicalPath);
512
+ if (hardLinkAmbiguous) recordIssue(state, "hard_link_ambiguous");
513
+ const allocatedCandidate = state.allocatedBytes(metadata);
514
+ const allocated =
515
+ allocatedCandidate !== undefined &&
516
+ Number.isSafeInteger(allocatedCandidate) &&
517
+ allocatedCandidate >= 0
518
+ ? allocatedCandidate
519
+ : undefined;
520
+ const allocationIdentity = metadata.nlink > 1 ? fileIdentity(metadata) : undefined;
521
+ addFile(state.totals, metadata.size, allocated, allocationIdentity);
522
+ addFile(
523
+ completeCoordinationRoot ? state.coordinationRootTotals : state.externalRootTotals,
524
+ metadata.size,
525
+ allocated,
526
+ allocationIdentity,
527
+ );
528
+ if (allocated === undefined) recordIssue(state, "allocated_bytes_unavailable");
529
+ if (matches.length === 0) {
530
+ const exclusion = state.catalog.exclusions.some(({ root }) => rootMatches(root, logicalPath));
531
+ recordIssue(state, exclusion ? "host_exclusion" : "unregistered_path");
532
+ return;
533
+ }
534
+ if (matches.length > 1) {
535
+ recordIssue(state, "overlapping_registration");
536
+ for (const match of matches) match.reasons.add("overlapping_registration");
537
+ return;
538
+ }
539
+ const family = matches[0]!;
540
+ const roots = family.roots.filter(({ root }) => rootMatches(root, logicalPath));
541
+ if (roots.length !== 1) {
542
+ recordIssue(state, "overlapping_registration");
543
+ family.reasons.add("overlapping_registration");
544
+ return;
545
+ }
546
+ addFile(family.totals, metadata.size, allocated, allocationIdentity);
547
+ family.roots[roots[0]!.index]!.matched = true;
548
+ addFile(family.roots[roots[0]!.index]!.totals, metadata.size, allocated, allocationIdentity);
549
+ if (hardLinkAmbiguous) {
550
+ family.reasons.add("hard_link_ambiguous");
551
+ family.roots[roots[0]!.index]!.reasons.add("hard_link_ambiguous");
552
+ }
553
+ if (allocated === undefined) {
554
+ family.reasons.add("allocated_bytes_unavailable");
555
+ family.roots[roots[0]!.index]!.reasons.add("allocated_bytes_unavailable");
556
+ }
557
+ }
558
+
559
+ function recordPathIssue(
560
+ state: ScanState,
561
+ path: string,
562
+ reason: HarneryStorageReasonCode,
563
+ completeCoordinationRoot: boolean,
564
+ ): void {
565
+ const matches = filesystemMatches(state, path);
566
+ if (!completeCoordinationRoot && matches.length === 0) return;
567
+ recordIssue(state, reason);
568
+ if (matches.length === 0 && completeCoordinationRoot) recordIssue(state, "unregistered_path");
569
+ for (const family of matches) {
570
+ family.reasons.add(reason);
571
+ for (const root of family.roots.filter(({ root }) => rootMatches(root, path))) {
572
+ root.reasons.add(reason);
573
+ }
574
+ }
575
+ }
576
+
577
+ function recordBoundaryIssue(
578
+ state: ScanState,
579
+ path: string,
580
+ reason: HarneryStorageReasonCode,
581
+ completeCoordinationRoot: boolean,
582
+ ): void {
583
+ const resolved = resolve(path);
584
+ const matches = [...state.families.values()].filter(
585
+ (family) =>
586
+ family.family.provider.inventory === "filesystem" &&
587
+ family.roots.some(({ root }) => resolve(root.path) === resolved),
588
+ );
589
+ recordIssue(state, reason);
590
+ if (matches.length === 0 && completeCoordinationRoot) recordIssue(state, "unregistered_path");
591
+ for (const family of matches) {
592
+ family.reasons.add(reason);
593
+ for (const root of family.roots.filter(({ root }) => resolve(root.path) === resolved)) {
594
+ root.reasons.add(reason);
595
+ }
596
+ }
597
+ }
598
+
599
+ function filesystemMatches(state: ScanState, path: string): FamilyAccumulator[] {
600
+ return state.catalog
601
+ .familiesForPath(path)
602
+ .filter((family) => family.provider.inventory === "filesystem")
603
+ .map((family) => state.families.get(family.id)!);
604
+ }
605
+
606
+ function addFile(
607
+ totals: MutableTotals,
608
+ logicalBytes: number,
609
+ allocated: number | undefined,
610
+ allocationIdentity: FileIdentity | undefined,
611
+ ): void {
612
+ totals.regular_files += 1;
613
+ totals.logical_bytes += logicalBytes;
614
+ if (allocated === undefined || !Number.isSafeInteger(allocated) || allocated < 0) {
615
+ totals.allocated_available = false;
616
+ } else {
617
+ const key = allocationIdentity
618
+ ? `${allocationIdentity.dev}:${allocationIdentity.ino}`
619
+ : undefined;
620
+ if (key === undefined || !totals.allocated_identities.has(key)) {
621
+ if (key !== undefined) totals.allocated_identities.add(key);
622
+ totals.allocated_bytes += allocated;
623
+ }
624
+ }
625
+ }
626
+
627
+ function allowsSymbolicLinkSkip(state: ScanState, path: string): boolean {
628
+ return matchingRoot(state, path)?.root.link_handling?.symbolic_links === "skip";
629
+ }
630
+
631
+ function allowsHardLink(state: ScanState, path: string): boolean {
632
+ return matchingRoot(state, path)?.root.link_handling?.hard_links === "allow";
633
+ }
634
+
635
+ function matchingRoot(state: ScanState, path: string): RootAccumulator | undefined {
636
+ const families = filesystemMatches(state, path);
637
+ if (families.length !== 1) return undefined;
638
+ const roots = families[0]!.roots.filter(({ root }) => rootMatches(root, path));
639
+ if (roots.length !== 1) return undefined;
640
+ return roots[0]!;
641
+ }
642
+
643
+ function allocatedBytes(stats: Stats): number | undefined {
644
+ if (typeof stats.blocks !== "number" || !Number.isSafeInteger(stats.blocks)) return undefined;
645
+ const bytes = stats.blocks * 512;
646
+ return Number.isSafeInteger(bytes) ? bytes : undefined;
647
+ }
648
+
649
+ function recordIssue(state: ScanState, reason: HarneryStorageReasonCode): void {
650
+ state.issues.set(reason, (state.issues.get(reason) ?? 0) + 1);
651
+ }
652
+
653
+ function familyInventory(
654
+ catalog: HarneryStorageCatalog,
655
+ accumulator: FamilyAccumulator,
656
+ capturedAt: Date,
657
+ ): HarneryStorageFamilyInventory {
658
+ const delegated = accumulator.family.provider.inventory === "delegated";
659
+ const roots = accumulator.roots.map((root) => rootInventory(catalog, accumulator, root));
660
+ const rootStates = new Set(roots.map(({ state }) => state));
661
+ const reasons = new Set(accumulator.reasons);
662
+ for (const root of roots) for (const reason of root.reason_codes) reasons.add(reason);
663
+ let state: HarneryStorageFamilyInventory["state"];
664
+ if (delegated) state = "delegated";
665
+ else if (rootStates.has("unavailable") && rootStates.size === 1) state = "unavailable";
666
+ else if (rootStates.has("unavailable") || rootStates.has("partial")) state = "partial";
667
+ else if (rootStates.has("present") && rootStates.has("dormant")) state = "partial";
668
+ else if (rootStates.has("present")) state = "present";
669
+ else state = "dormant";
670
+ if (state === "dormant" || rootStates.has("dormant")) reasons.add("root_dormant");
671
+ return {
672
+ family_id: accumulator.family.id,
673
+ source: accumulator.family.source,
674
+ storage_class: accumulator.family.storage_class,
675
+ policy_version: accumulator.family.policy.policy_version,
676
+ provider_id: accumulator.family.provider.provider_id,
677
+ inventory: accumulator.family.provider.inventory,
678
+ maintenance: maintenance(accumulator.family, state, reasons),
679
+ state,
680
+ reason_codes: [...reasons].sort(),
681
+ totals: delegated
682
+ ? unavailableTotals("delegated_inventory_unavailable")
683
+ : observedTotals(accumulator.totals),
684
+ roots,
685
+ ...(isLogFamily(accumulator.family)
686
+ ? { log_storage: logStorageStatus(accumulator.family, capturedAt) }
687
+ : {}),
688
+ };
689
+ }
690
+
691
+ function logStorageStatus(family: HarneryRegisteredStorageFamily, now: Date) {
692
+ const inspection = inspectStructuredLogRetention(family, now);
693
+ const effective = family.effective_log_retention;
694
+ return {
695
+ effective_policy: effective
696
+ ? {
697
+ state: effective.state,
698
+ max_bytes: effective.max_bytes,
699
+ max_age_days: effective.max_age_days,
700
+ max_age_ms: effective.max_age_ms,
701
+ fingerprint: effective.effective_policy_fingerprint,
702
+ provenance: effective.provenance,
703
+ diagnostics: effective.diagnostics,
704
+ }
705
+ : null,
706
+ usage: inspection.usage,
707
+ pressure: inspection.pressure,
708
+ retention: inspection.retention,
709
+ };
710
+ }
711
+
712
+ function isLogFamily(family: HarneryRegisteredStorageFamily): boolean {
713
+ return family.storage_class === "operational-log" || family.storage_class === "debug-log";
714
+ }
715
+
716
+ function rootInventory(
717
+ catalog: HarneryStorageCatalog,
718
+ family: FamilyAccumulator,
719
+ root: RootAccumulator,
720
+ ): HarneryStorageRootInventory {
721
+ const delegated = family.family.provider.inventory === "delegated";
722
+ const reasons = new Set(root.reasons);
723
+ let state: HarneryStorageRootInventory["state"];
724
+ if (delegated) state = "delegated";
725
+ else if (reasons.has("unreadable_path") || reasons.has("wrong_root_type")) state = "unavailable";
726
+ else if (reasons.has("symlink_rejected")) state = "unavailable";
727
+ else if (root.matched || (root.base_present && root.root.match === "subtree")) state = "present";
728
+ else if (root.base_present && root.root.match === "exact" && root.root.kind === "directory") {
729
+ state = "present";
730
+ } else {
731
+ state = "dormant";
732
+ reasons.add("root_dormant");
733
+ }
734
+ return {
735
+ root_index: root.index,
736
+ root_label: rootLabel(catalog, family.family.id, root),
737
+ ownership: root.root.ownership ?? "harnery",
738
+ state,
739
+ reason_codes: [...reasons].sort(),
740
+ totals: delegated
741
+ ? unavailableTotals("delegated_inventory_unavailable")
742
+ : observedTotals(root.totals),
743
+ };
744
+ }
745
+
746
+ function rootLabel(
747
+ catalog: HarneryStorageCatalog,
748
+ familyId: string,
749
+ root: RootAccumulator,
750
+ ): string {
751
+ const rel = relative(catalog.context.coord_root, root.root.path);
752
+ if (rel === "") return ".";
753
+ if (!rel.startsWith("..") && !isAbsolute(rel)) return rel.split(sep).join("/");
754
+ return `<external:${familyId}:${root.index + 1}>`;
755
+ }
756
+
757
+ function maintenance(
758
+ family: HarneryRegisteredStorageFamily,
759
+ state: HarneryStorageFamilyInventory["state"],
760
+ reasons: Set<HarneryStorageReasonCode>,
761
+ ): HarneryStorageFamilyInventory["maintenance"] {
762
+ if (family.provider.maintenance === "delegated") {
763
+ return { state: "delegated", reason_code: "maintenance_delegated" };
764
+ }
765
+ if (family.provider.maintenance === "none") {
766
+ return { state: "ineligible", reason_code: "maintenance_not_registered" };
767
+ }
768
+ if (family.policy.retention.status !== "active") {
769
+ return { state: "ineligible", reason_code: "maintenance_policy_inactive" };
770
+ }
771
+ if (state !== "present" || reasons.has("allocated_bytes_unavailable")) {
772
+ return { state: "ineligible", reason_code: "provider_unavailable" };
773
+ }
774
+ if (
775
+ [...reasons].some((reason) =>
776
+ [
777
+ "host_exclusion",
778
+ "hard_link_ambiguous",
779
+ "overlapping_registration",
780
+ "special_file_rejected",
781
+ "symlink_rejected",
782
+ "unreadable_path",
783
+ "unregistered_path",
784
+ "wrong_root_type",
785
+ ].includes(reason),
786
+ )
787
+ ) {
788
+ return { state: "ineligible", reason_code: "provider_unavailable" };
789
+ }
790
+ return { state: "eligible" };
791
+ }
792
+
793
+ function observedTotals(totals: MutableTotals): HarneryStorageInventoryTotals {
794
+ return {
795
+ regular_files: observed("files", totals.regular_files),
796
+ logical_bytes: observed("bytes", totals.logical_bytes),
797
+ allocated_bytes: totals.allocated_available
798
+ ? observed("bytes", totals.allocated_bytes)
799
+ : unavailable("bytes", "allocated_bytes_unavailable"),
800
+ };
801
+ }
802
+
803
+ function unavailableTotals(reason: HarneryStorageReasonCode): HarneryStorageInventoryTotals {
804
+ return {
805
+ regular_files: unavailable("files", reason),
806
+ logical_bytes: unavailable("bytes", reason),
807
+ allocated_bytes: unavailable("bytes", reason),
808
+ };
809
+ }
810
+
811
+ function observed(unit: "files" | "bytes", value: number): HarneryStorageMeasurement {
812
+ return { state: "observed", unit, value };
813
+ }
814
+
815
+ function unavailable(
816
+ unit: "files" | "bytes",
817
+ reason_code: HarneryStorageReasonCode,
818
+ ): HarneryStorageMeasurement {
819
+ return { state: "unavailable", unit, reason_code };
820
+ }
821
+
822
+ function issueRows(issues: Map<HarneryStorageReasonCode, number>): HarneryStorageIssueSummary[] {
823
+ return [...issues.entries()]
824
+ .map(([reason_code, count]) => ({ reason_code, count, maintenance_eligible: false as const }))
825
+ .sort((left, right) => left.reason_code.localeCompare(right.reason_code));
826
+ }
827
+
828
+ function rootMatches(root: HarneryStorageRoot, candidate: string): boolean {
829
+ const path = resolve(candidate);
830
+ if (root.match === "exact") return resolve(root.path) === path;
831
+ const remainder = relative(root.path, path).split(sep).join("/");
832
+ if (remainder === "" || remainder.startsWith("..") || isAbsolute(remainder)) return false;
833
+ if (root.match === "subtree") return true;
834
+ return root.include!.some((pattern) => globRegex(pattern).test(remainder));
835
+ }
836
+
837
+ function globRegex(pattern: string): RegExp {
838
+ let source = "^";
839
+ for (let index = 0; index < pattern.length; index += 1) {
840
+ const character = pattern[index]!;
841
+ if (character === "*") {
842
+ if (pattern[index + 1] === "*") {
843
+ source += ".*";
844
+ index += 1;
845
+ } else source += "[^/]*";
846
+ } else if (character === "?") source += "[^/]";
847
+ else source += character.replace(/[|\\{}()[\]^$+?.]/g, "\\$&");
848
+ }
849
+ return new RegExp(`${source}$`);
850
+ }
851
+
852
+ function within(root: string, candidate: string): boolean {
853
+ const remainder = relative(resolve(root), resolve(candidate));
854
+ return remainder === "" || (!remainder.startsWith("..") && !isAbsolute(remainder));
855
+ }
856
+
857
+ function isMissing(error: unknown): boolean {
858
+ return (error as NodeJS.ErrnoException)?.code === "ENOENT";
859
+ }