@proofoftech/flowsafe 0.4.0 → 0.7.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 (271) hide show
  1. package/CHANGELOG.md +327 -0
  2. package/README.md +295 -251
  3. package/dist/agent-runner/approval-shapes.d.ts +36 -0
  4. package/dist/agent-runner/approval-shapes.d.ts.map +1 -0
  5. package/dist/agent-runner/approval-shapes.js +101 -0
  6. package/dist/agent-runner/approval-shapes.js.map +1 -0
  7. package/dist/agent-runner/durable-agent-runner.d.ts +158 -0
  8. package/dist/agent-runner/durable-agent-runner.d.ts.map +1 -0
  9. package/dist/agent-runner/durable-agent-runner.js +295 -0
  10. package/dist/agent-runner/durable-agent-runner.js.map +1 -0
  11. package/dist/agent-runner/index.d.ts +3 -0
  12. package/dist/agent-runner/index.d.ts.map +1 -0
  13. package/dist/agent-runner/index.js +10 -0
  14. package/dist/agent-runner/index.js.map +1 -0
  15. package/dist/approval-api/contract.d.ts +2 -2
  16. package/dist/approval-api/d1-store.d.ts.map +1 -1
  17. package/dist/approval-api/d1-store.js +87 -19
  18. package/dist/approval-api/d1-store.js.map +1 -1
  19. package/dist/approval-api/grants.d.ts +1 -1
  20. package/dist/approval-api/grants.js +1 -1
  21. package/dist/approval-api/index.d.ts +1 -1
  22. package/dist/approval-api/index.d.ts.map +1 -1
  23. package/dist/approval-api/index.js.map +1 -1
  24. package/dist/approval-api/router.d.ts +2 -2
  25. package/dist/approval-api/router.d.ts.map +1 -1
  26. package/dist/approval-api/router.js +1 -0
  27. package/dist/approval-api/router.js.map +1 -1
  28. package/dist/approval-api/service.d.ts +10 -11
  29. package/dist/approval-api/service.d.ts.map +1 -1
  30. package/dist/approval-api/service.js +22 -9
  31. package/dist/approval-api/service.js.map +1 -1
  32. package/dist/approval-api/store.d.ts +27 -22
  33. package/dist/approval-api/store.d.ts.map +1 -1
  34. package/dist/approval-api/store.js +25 -9
  35. package/dist/approval-api/store.js.map +1 -1
  36. package/dist/approval-api/tenant-context.d.ts +6 -6
  37. package/dist/approval-api/tenant-context.d.ts.map +1 -1
  38. package/dist/approval-api/tenant-context.js +15 -0
  39. package/dist/approval-api/tenant-context.js.map +1 -1
  40. package/dist/approval-api/tenant-store.d.ts +1 -1
  41. package/dist/approval-api/tenant-store.d.ts.map +1 -1
  42. package/dist/approval-api/types.d.ts +13 -4
  43. package/dist/approval-api/types.d.ts.map +1 -1
  44. package/dist/approval-api/types.js +2 -1
  45. package/dist/approval-api/types.js.map +1 -1
  46. package/dist/approval-ui/App.d.ts +2 -2
  47. package/dist/approval-ui/FilterBar.d.ts +3 -3
  48. package/dist/approval-ui/FilterBar.js +3 -3
  49. package/dist/approval-ui/client.d.ts +1 -1
  50. package/dist/approval-ui/components.d.ts +1 -1
  51. package/dist/approval-ui/stream.d.ts +3 -3
  52. package/dist/approval-ui/stream.js +2 -2
  53. package/dist/approval-ui/use-approval-dashboard.d.ts +9 -12
  54. package/dist/approval-ui/use-approval-dashboard.d.ts.map +1 -1
  55. package/dist/approval-ui/use-approval-dashboard.js +6 -9
  56. package/dist/approval-ui/use-approval-dashboard.js.map +1 -1
  57. package/dist/approval-ui/use-web-socket-transport.d.ts +1 -1
  58. package/dist/approval-ui/use-web-socket-transport.js +1 -1
  59. package/dist/background-tasks/d1-storage.d.ts +66 -0
  60. package/dist/background-tasks/d1-storage.d.ts.map +1 -0
  61. package/dist/background-tasks/d1-storage.js +196 -0
  62. package/dist/background-tasks/d1-storage.js.map +1 -0
  63. package/dist/background-tasks/host.d.ts +82 -0
  64. package/dist/background-tasks/host.d.ts.map +1 -0
  65. package/dist/background-tasks/host.js +275 -0
  66. package/dist/background-tasks/host.js.map +1 -0
  67. package/dist/background-tasks/index.d.ts +7 -0
  68. package/dist/background-tasks/index.d.ts.map +1 -0
  69. package/dist/background-tasks/index.js +10 -0
  70. package/dist/background-tasks/index.js.map +1 -0
  71. package/dist/background-tasks/routes.d.ts +15 -0
  72. package/dist/background-tasks/routes.d.ts.map +1 -0
  73. package/dist/background-tasks/routes.js +144 -0
  74. package/dist/background-tasks/routes.js.map +1 -0
  75. package/dist/do-runner/breakwater-keys.d.ts +1 -1
  76. package/dist/do-runner/breakwater-keys.js +1 -1
  77. package/dist/do-runner/cf-types.d.ts +1 -1
  78. package/dist/do-runner/d1-storage.d.ts +347 -5
  79. package/dist/do-runner/d1-storage.d.ts.map +1 -1
  80. package/dist/do-runner/d1-storage.js +571 -17
  81. package/dist/do-runner/d1-storage.js.map +1 -1
  82. package/dist/do-runner/do-error-response.d.ts +29 -0
  83. package/dist/do-runner/do-error-response.d.ts.map +1 -0
  84. package/dist/do-runner/do-error-response.js +73 -0
  85. package/dist/do-runner/do-error-response.js.map +1 -0
  86. package/dist/do-runner/durable-object.d.ts +3 -3
  87. package/dist/do-runner/durable-object.d.ts.map +1 -1
  88. package/dist/do-runner/durable-object.js +7 -21
  89. package/dist/do-runner/durable-object.js.map +1 -1
  90. package/dist/do-runner/hub-do.d.ts +2 -2
  91. package/dist/do-runner/index.d.ts +9 -3
  92. package/dist/do-runner/index.d.ts.map +1 -1
  93. package/dist/do-runner/index.js +8 -2
  94. package/dist/do-runner/index.js.map +1 -1
  95. package/dist/do-runner/init.d.ts +20 -0
  96. package/dist/do-runner/init.d.ts.map +1 -1
  97. package/dist/do-runner/init.js +12 -1
  98. package/dist/do-runner/init.js.map +1 -1
  99. package/dist/do-runner/memory-id.d.ts +3 -3
  100. package/dist/do-runner/memory-id.js +3 -3
  101. package/dist/do-runner/path-safe-id.d.ts +6 -6
  102. package/dist/do-runner/path-safe-id.js +6 -6
  103. package/dist/do-runner/pubsub.d.ts +18 -0
  104. package/dist/do-runner/pubsub.d.ts.map +1 -0
  105. package/dist/do-runner/pubsub.js +42 -0
  106. package/dist/do-runner/pubsub.js.map +1 -0
  107. package/dist/do-runner/runtime.d.ts +24 -1
  108. package/dist/do-runner/runtime.d.ts.map +1 -1
  109. package/dist/do-runner/runtime.js +28 -2
  110. package/dist/do-runner/runtime.js.map +1 -1
  111. package/dist/do-runner/thread-do.d.ts +74 -0
  112. package/dist/do-runner/thread-do.d.ts.map +1 -0
  113. package/dist/do-runner/thread-do.js +156 -0
  114. package/dist/do-runner/thread-do.js.map +1 -0
  115. package/dist/do-runner/thread-header.d.ts +16 -0
  116. package/dist/do-runner/thread-header.d.ts.map +1 -0
  117. package/dist/do-runner/thread-header.js +24 -0
  118. package/dist/do-runner/thread-header.js.map +1 -0
  119. package/dist/goals/index.d.ts +2 -0
  120. package/dist/goals/index.d.ts.map +1 -0
  121. package/dist/goals/index.js +7 -0
  122. package/dist/goals/index.js.map +1 -0
  123. package/dist/goals/objective-routes.d.ts +87 -0
  124. package/dist/goals/objective-routes.d.ts.map +1 -0
  125. package/dist/goals/objective-routes.js +375 -0
  126. package/dist/goals/objective-routes.js.map +1 -0
  127. package/dist/host-kit/approval-bridge.d.ts +28 -8
  128. package/dist/host-kit/approval-bridge.d.ts.map +1 -1
  129. package/dist/host-kit/approval-bridge.js +37 -15
  130. package/dist/host-kit/approval-bridge.js.map +1 -1
  131. package/dist/host-kit/bearer-auth.d.ts +1 -1
  132. package/dist/host-kit/bearer-auth.js +1 -1
  133. package/dist/host-kit/env-vars.d.ts +20 -0
  134. package/dist/host-kit/env-vars.d.ts.map +1 -1
  135. package/dist/host-kit/env-vars.js +30 -0
  136. package/dist/host-kit/env-vars.js.map +1 -1
  137. package/dist/host-kit/flowsafe-worker.d.ts +113 -6
  138. package/dist/host-kit/flowsafe-worker.d.ts.map +1 -1
  139. package/dist/host-kit/flowsafe-worker.js +253 -63
  140. package/dist/host-kit/flowsafe-worker.js.map +1 -1
  141. package/dist/host-kit/host-approval-service.d.ts +13 -13
  142. package/dist/host-kit/host-approval-service.js +10 -10
  143. package/dist/host-kit/index.d.ts +3 -1
  144. package/dist/host-kit/index.d.ts.map +1 -1
  145. package/dist/host-kit/index.js +7 -0
  146. package/dist/host-kit/index.js.map +1 -1
  147. package/dist/host-kit/memory-boundary.d.ts +64 -0
  148. package/dist/host-kit/memory-boundary.d.ts.map +1 -0
  149. package/dist/host-kit/memory-boundary.js +109 -0
  150. package/dist/host-kit/memory-boundary.js.map +1 -0
  151. package/dist/host-kit/route-path.d.ts +17 -0
  152. package/dist/host-kit/route-path.d.ts.map +1 -0
  153. package/dist/host-kit/route-path.js +35 -0
  154. package/dist/host-kit/route-path.js.map +1 -0
  155. package/dist/host-kit/run-router.d.ts +10 -11
  156. package/dist/host-kit/run-router.d.ts.map +1 -1
  157. package/dist/host-kit/run-router.js.map +1 -1
  158. package/dist/host-kit/stream-router.d.ts +1 -1
  159. package/dist/host-kit/stream-router.d.ts.map +1 -1
  160. package/dist/host-kit/stream-ticket.d.ts +3 -3
  161. package/dist/host-kit/stream-ticket.d.ts.map +1 -1
  162. package/dist/host-kit/stream-ticket.js +1 -1
  163. package/dist/host-kit/tenant-registry.d.ts +1 -1
  164. package/dist/host-kit/tenant-registry.js +1 -1
  165. package/dist/host-kit/thread-topology.d.ts +44 -0
  166. package/dist/host-kit/thread-topology.d.ts.map +1 -0
  167. package/dist/host-kit/thread-topology.js +76 -0
  168. package/dist/host-kit/thread-topology.js.map +1 -0
  169. package/dist/host-kit/verifier.d.ts +1 -1
  170. package/dist/host-kit/verifier.js +1 -1
  171. package/dist/index.d.ts +4 -8
  172. package/dist/index.d.ts.map +1 -1
  173. package/dist/index.js +4 -4
  174. package/dist/index.js.map +1 -1
  175. package/dist/internal-error-response.d.ts +3 -0
  176. package/dist/internal-error-response.d.ts.map +1 -0
  177. package/dist/internal-error-response.js +20 -0
  178. package/dist/internal-error-response.js.map +1 -0
  179. package/dist/numeric-config.d.ts +4 -0
  180. package/dist/numeric-config.d.ts.map +1 -0
  181. package/dist/numeric-config.js +23 -0
  182. package/dist/numeric-config.js.map +1 -0
  183. package/dist/schedules/index.d.ts +5 -0
  184. package/dist/schedules/index.d.ts.map +1 -0
  185. package/dist/schedules/index.js +13 -0
  186. package/dist/schedules/index.js.map +1 -0
  187. package/dist/schedules/router.d.ts +66 -0
  188. package/dist/schedules/router.d.ts.map +1 -0
  189. package/dist/schedules/router.js +827 -0
  190. package/dist/schedules/router.js.map +1 -0
  191. package/dist/schedules/schedules-d1.d.ts +30 -0
  192. package/dist/schedules/schedules-d1.d.ts.map +1 -0
  193. package/dist/schedules/schedules-d1.js +374 -0
  194. package/dist/schedules/schedules-d1.js.map +1 -0
  195. package/dist/schedules/storage.d.ts +11 -0
  196. package/dist/schedules/storage.d.ts.map +1 -0
  197. package/dist/schedules/storage.js +34 -0
  198. package/dist/schedules/storage.js.map +1 -0
  199. package/dist/schedules/tick.d.ts +132 -0
  200. package/dist/schedules/tick.d.ts.map +1 -0
  201. package/dist/schedules/tick.js +598 -0
  202. package/dist/schedules/tick.js.map +1 -0
  203. package/dist/signal-providers/delivery.d.ts +24 -0
  204. package/dist/signal-providers/delivery.d.ts.map +1 -0
  205. package/dist/signal-providers/delivery.js +62 -0
  206. package/dist/signal-providers/delivery.js.map +1 -0
  207. package/dist/signal-providers/github-provider.d.ts +33 -0
  208. package/dist/signal-providers/github-provider.d.ts.map +1 -0
  209. package/dist/signal-providers/github-provider.js +116 -0
  210. package/dist/signal-providers/github-provider.js.map +1 -0
  211. package/dist/signal-providers/host-do.d.ts +81 -0
  212. package/dist/signal-providers/host-do.d.ts.map +1 -0
  213. package/dist/signal-providers/host-do.js +229 -0
  214. package/dist/signal-providers/host-do.js.map +1 -0
  215. package/dist/signal-providers/host-topology.d.ts +27 -0
  216. package/dist/signal-providers/host-topology.d.ts.map +1 -0
  217. package/dist/signal-providers/host-topology.js +36 -0
  218. package/dist/signal-providers/host-topology.js.map +1 -0
  219. package/dist/signal-providers/index.d.ts +8 -0
  220. package/dist/signal-providers/index.d.ts.map +1 -0
  221. package/dist/signal-providers/index.js +21 -0
  222. package/dist/signal-providers/index.js.map +1 -0
  223. package/dist/signal-providers/provider.d.ts +93 -0
  224. package/dist/signal-providers/provider.d.ts.map +1 -0
  225. package/dist/signal-providers/provider.js +89 -0
  226. package/dist/signal-providers/provider.js.map +1 -0
  227. package/dist/signal-providers/subscription-d1.d.ts +88 -0
  228. package/dist/signal-providers/subscription-d1.d.ts.map +1 -0
  229. package/dist/signal-providers/subscription-d1.js +259 -0
  230. package/dist/signal-providers/subscription-d1.js.map +1 -0
  231. package/dist/signal-providers/webhook-route.d.ts +96 -0
  232. package/dist/signal-providers/webhook-route.d.ts.map +1 -0
  233. package/dist/signal-providers/webhook-route.js +444 -0
  234. package/dist/signal-providers/webhook-route.js.map +1 -0
  235. package/dist/signals/client.d.ts +72 -0
  236. package/dist/signals/client.d.ts.map +1 -0
  237. package/dist/signals/client.js +87 -0
  238. package/dist/signals/client.js.map +1 -0
  239. package/dist/signals/d1-shared.d.ts +43 -0
  240. package/dist/signals/d1-shared.d.ts.map +1 -0
  241. package/dist/signals/d1-shared.js +46 -0
  242. package/dist/signals/d1-shared.js.map +1 -0
  243. package/dist/signals/index.d.ts +9 -0
  244. package/dist/signals/index.d.ts.map +1 -0
  245. package/dist/signals/index.js +15 -0
  246. package/dist/signals/index.js.map +1 -0
  247. package/dist/signals/notification-dispatch.d.ts +52 -0
  248. package/dist/signals/notification-dispatch.d.ts.map +1 -0
  249. package/dist/signals/notification-dispatch.js +198 -0
  250. package/dist/signals/notification-dispatch.js.map +1 -0
  251. package/dist/signals/notifications-d1.d.ts +27 -0
  252. package/dist/signals/notifications-d1.d.ts.map +1 -0
  253. package/dist/signals/notifications-d1.js +703 -0
  254. package/dist/signals/notifications-d1.js.map +1 -0
  255. package/dist/signals/router.d.ts +73 -0
  256. package/dist/signals/router.d.ts.map +1 -0
  257. package/dist/signals/router.js +240 -0
  258. package/dist/signals/router.js.map +1 -0
  259. package/dist/signals/storage.d.ts +11 -0
  260. package/dist/signals/storage.d.ts.map +1 -0
  261. package/dist/signals/storage.js +27 -0
  262. package/dist/signals/storage.js.map +1 -0
  263. package/dist/signals/thread-do-routes.d.ts +82 -0
  264. package/dist/signals/thread-do-routes.d.ts.map +1 -0
  265. package/dist/signals/thread-do-routes.js +660 -0
  266. package/dist/signals/thread-do-routes.js.map +1 -0
  267. package/dist/signals/thread-state-d1.d.ts +22 -0
  268. package/dist/signals/thread-state-d1.d.ts.map +1 -0
  269. package/dist/signals/thread-state-d1.js +83 -0
  270. package/dist/signals/thread-state-d1.js.map +1 -0
  271. package/package.json +11 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,332 @@
1
1
  # @proofoftech/flowsafe
2
2
 
3
+ ## 0.7.0
4
+
5
+ ### Minor Changes
6
+
7
+ - def3b37: Complete and document the public flowsafe surface. The root entry point now
8
+ re-exports the approval API, Durable Object runner, artifacts, and audit export
9
+ surfaces with parity tests. Signal-provider hosts gain a tenant-safe topology,
10
+ stable polling alarms, and automatic post-mutation polling reconciliation.
11
+ Publish comprehensive package, deployment, approval, durable-agent, operations,
12
+ and API-reference documentation, plus a full advanced starter host.
13
+
14
+ ## 0.6.0
15
+
16
+ > **Final 0.6.0 state:** The `eca3b6e` closeout entry below supersedes earlier
17
+ > statements in this release section that agent schedule targets and durable D1
18
+ > background-task execution were deferred. Both are supported in 0.6.0 when
19
+ > their opt-in host wiring is configured. Durable-agent restart resume and
20
+ > notification dispatch are also closed and verified.
21
+
22
+ ### Minor Changes
23
+
24
+ - eca3b6e: Close the durable-agent, agent-schedule, notification-dispatch, and D1 background-task execution residuals with tenant-safe thread routing and eviction-safe approval resume. Harden stored schedule context and core schedule-contract validation; make D1 notification creation preserve explicit-id coalescing, insertion-order targets, rollback-safe atomic migration, and concurrent partial updates; priority-plan summary and individual delivery across state-stable 100-id batches; accept Mastra's raw constructor pubsub with rollback-safe workers and a synchronous enqueue shutdown gate; close failed resume streams; validate public numeric configuration synchronously; preserve nested Mastra background-task SSE events; and require a proven process shutdown before spike restart.
25
+ - d54d2be: Track D — schedules (`@proofoftech/flowsafe/schedules`, additive, opt-in). A new
26
+ subpath ships the D1 schedules domain, a CAS-driven tick we own, and a tenant
27
+ facade — all on the single DO + D1 RunnerRuntime substrate (P1), no new
28
+ `ApprovalRecord` shape or existing signature changed, unconfigured hosts
29
+ byte-identical.
30
+
31
+ - `D1SchedulesStorage` + `createScheduleStorageDomains` — the flowsafe-owned D1
32
+ domain over `mastra_schedules` / `mastra_schedule_triggers` (the
33
+ `@mastra/cloudflare-d1` adapter ships neither), mirroring core's
34
+ `SchedulesStorage` contract incl. the CAS `updateScheduleNextFire`. Composed
35
+ into `createD1Storage` via the injected `domains` seam.
36
+ - `createScheduleTick` — we OWN the tick (DL-012): `listDueSchedules` → CAS claim
37
+ → workflow targets mint a fresh INV-1 runId and fire through the host's
38
+ run-start seam; agent targets are GUARDED OFF (their only public fire path,
39
+ `schedules.run(id)`, enqueues onto core's pubsub worker loop we do not run, so
40
+ firing is a fail-closed audited skip — agent-target execution is deferred). An
41
+ injectable run-cap seam (DL-007) skips a capped tenant while the schedule stays
42
+ healthy. The P4 stored-context barrier strips reserved keys before any leg.
43
+ - `createScheduleRouter` — the tenant facade (DL-013): server-minted ids,
44
+ `metadata.tenantId` stamping, tenant-filtered reads, ownership 404s (no
45
+ oracle), per-tenant count + fire-rate caps, and P4 reserved-key rejection on
46
+ create/update (the whole `breakwater.` namespace + `mastra:goal`).
47
+ - Storage triad (DL-003): both tables register in the schema-guard inventory
48
+ (8 → 10) with a new metadata-filtered `purgeTenant` kind
49
+ (`TENANT_METADATA_PURGE_TABLES`), plus `purgeExpiredScheduleTriggers` for the
50
+ trigger-history TTL. `createFlowsafeWorker` gains an opt-in `scheduleTick` seam
51
+ (its own failure-isolated cron duty) and a `SCHEDULE_TRIGGER_RETENTION_DAYS`
52
+ purge duty.
53
+
54
+ - 0f4f70a: Track E (M-007) — signal providers: a new subpath `@proofoftech/flowsafe/signal-providers`
55
+ (additive, opt-in, subpath-only). Host external-event providers on a Durable
56
+ Object with alarm-driven polling, terminate provider webhooks on the Worker, and
57
+ persist subscriptions in a flowsafe-owned D1 table.
58
+
59
+ - `SignalProviderHost` — a per-tenant provider host DO (`idFromName(tenantId)`)
60
+ whose alarm rehydrates subscriptions from D1 (core's registry is in-memory,
61
+ lost on eviction) and polls each of the tenant's providers with per-provider +
62
+ per-delivery failure isolation, delivering through Track C's thread-DO topology.
63
+ - `D1SubscriptionStoreFactory` — a flowsafe-owned, tenant-columned
64
+ `flowsafe_signal_subscriptions` store mirroring the approval store's INV-2
65
+ posture (`.forTenant()` tenant-bound, `.system().listByResource()` the webhook's
66
+ cross-tenant authority). Registered in `purgeTenant` (`PurgeTenantResult.subscriptions`);
67
+ retention is `none` (standing config reaped only at offboarding).
68
+ - `createWebhookRouter` — webhook ingress that verifies the provider signature
69
+ over the RAW bytes BEFORE parsing, maps the payload to a tenant via the
70
+ subscription ROW only (never the payload), rate-caps per provider+tenant, and
71
+ audits every ingest with a bounded forgery audit. `createSubscriptionRouter` —
72
+ the human-only HTTP subscribe/unsubscribe surface (never exposed as model
73
+ tools; mints no capability).
74
+ - `githubSignalProvider` — a binding-gated GitHub reference provider
75
+ (`X-Hub-Signature-256` verified constant-time via WebCrypto). `createWebhookSignalProvider`
76
+ is the generic path.
77
+
78
+ Also adds a `subscriptions` counter to `PurgeTenantResult` (the DL-003 offboarding
79
+ coverage for the new flowsafe-owned table).
80
+
81
+ - 6c80e92: Track F (M-005) — goals. New subpath-only export `@proofoftech/flowsafe/goals`:
82
+ `createObjectiveRouter`, a role-gated + audited objective HTTP surface
83
+ (set/get/update/clear over `/api/threads/:threadId/goal`) that writes the
84
+ thread-scoped goal record in Track C's `mastra_thread_state` domain
85
+ (`GOAL_STATE_TYPE` 'goal'). The write path is a P6-lite ingestion boundary
86
+ (auth → coarse role → thread-prefix ownership 404 → size cap →
87
+ `assertNoClientMemoryIds` → field allowlist → maxRuns host cap → audit) and
88
+ persists through `@mastra/core`'s own `writeObjective`/`readObjective`/
89
+ `clearObjective`, so a record it writes is byte-identical to what the durable
90
+ goal step reads via `resolveGoalStore` (DL-018 — no thread-DO affinity needed
91
+ for the write). A requested `maxRuns` above the host cap is rejected, not
92
+ clamped (default the core `DEFAULT_GOAL_MAX_RUNS`, 50; DL-007). Goals never mint
93
+ capability (P8) and Track F starts no runs — per-tenant run budgets stay
94
+ enforced at the existing seams. `GOAL_REQUEST_CONTEXT_KEY` ('mastra:goal') is
95
+ reserved with a no-collision pin against the runtime's requestContext base keys.
96
+ Hosts mount the surface opt-in through `createFlowsafeWorker`'s new
97
+ `buildObjectiveRouter` seam; absent config is byte-identical. Additive only — no
98
+ new table, schema-guard, purge, or TTL change (reuses the Track C thread-state
99
+ domain), and no existing signature or `ApprovalRecord` shape changes.
100
+
101
+ ### Patch Changes
102
+
103
+ - 8e3562f: Make approval filing atomic across terminal and open records for the same captured suspension fingerprint, preventing stale reconciliation from filing over a decision.
104
+ - 97cb097: Harden the P6 ingestion routers against a pre-auth malformed-path fault. The
105
+ signal, goal, and schedule routers decoded the threadId/schedule-id path
106
+ segment with bare `decodeURIComponent` before authentication, and
107
+ `createFlowsafeWorker`'s fetch handler did not wrap the router calls — so an
108
+ unauthenticated request with malformed percent-encoding (e.g.
109
+ `POST /api/threads/%/message`) threw a `URIError` out of `fetch()` as a
110
+ per-request 500. The three routers now use a shared `safeDecodeSegment`
111
+ (host-kit) that treats malformed encoding as route-absent (byte-identical to a
112
+ non-matching path), matching the Track E webhook router; the worker fetch
113
+ handler gains a top-level try/catch that contains any handler throw as a
114
+ generic 500 without leaking `error.message`. The same helper closes the whole
115
+ class: the background-tasks read route (post-auth, DO-mounted) adopts it too, so
116
+ a malformed taskId returns the no-oracle 404 instead of throwing. Additive and
117
+ behavior-preserving for all valid paths.
118
+
119
+ ## Unpublished 0.5.0 draft (included in 0.6.0)
120
+
121
+ No `@proofoftech/flowsafe@0.5.0` package was published. These changes shipped in
122
+ 0.6.0 and remain here as their original generated release notes.
123
+
124
+ ### Minor Changes
125
+
126
+ - 281c6d1: Track 0 (substrate for the long-running-agents program): close the agent-memory
127
+ tenancy obligations and add the seams the agent tracks build on. All additive —
128
+ a host that configures none of it is byte-identical.
129
+
130
+ - **Agent-memory host boundary** (`@proofoftech/flowsafe/host-kit`):
131
+ `assertNoClientMemoryIds(body)` rejects (400) any request body naming
132
+ `threadId`/`resourceId` — memory ids are minted server-side from the
133
+ authenticated tenant via `TenantContext.newThreadId()/newResourceId()`, never
134
+ chosen by a client — and `requireOwnedMemoryId(tenant, id)` answers 404 (not
135
+ 403, so no existence oracle) on a foreign id. Every memory-touching route MUST
136
+ call both (the rule the agent-domain routes in later tracks adopt).
137
+ - **Recall-path proof**: core's own `MastraMemory` implementation over the real
138
+ D1 store, two tenants keyed by the SAME business key, pinning that `recall()`,
139
+ `listThreads({filter:{resourceId}})`, and resource-scoped `getWorkingMemory()`
140
+ never cross tenants.
141
+ - **Thread TTL**: `purgeExpiredThreads(db, { ttlMs, limit, tablePrefix })`, wired
142
+ into `createFlowsafeWorker`'s purge cron behind the new `THREAD_RETENTION_DAYS`
143
+ var with its own failure isolation. Keyed on `mastra_threads.updatedAt`
144
+ (threads are not per-run and have no terminal status); messages go with their
145
+ thread and before it; working-memory rows are untouched. Unset by default — no
146
+ thread expires until an operator names a number.
147
+ - **Extensible purge/guard inventory** (`TENANT_RANGE_PURGE_TABLES`,
148
+ `TenantRangePurgeTable`, `TenantRangePurgeCounter`): adopting a `mastra_*`
149
+ domain is now one additive row plus the counter/result pair the types force in
150
+ the same change; the schema guard still trips on any silently added table, and
151
+ its inventory now also forces each table's retention story — where "no TTL"
152
+ demands a written reason, so an absent decision cannot read as "none needed".
153
+ - **Host pubsub identity** (`createHostPubSub`, `HostPubSub`): the seam for one
154
+ in-process `EventEmitterPubSub` per host DO — passed to `init()` (new
155
+ `InitOptions.pubsub`), taken back off `InitResult.pubsub`, and threaded into
156
+ the runtime (new `RunnerRuntimeOptions.pubsub`, readable as
157
+ `RunnerRuntime.pubsub`) so a host reaches it with no host change. Every
158
+ consumer in the isolate then shares one emitter instead of each letting core
159
+ default its own (two such feeds never see each other's events). The identity
160
+ and the seam only: nothing passes it to core's `createRun` yet, so a configured
161
+ pubsub is an identity the host holds, not yet a feed core publishes on. Opt-in;
162
+ absent leaves polling as the fallback.
163
+ - **`ThreadDurableObject`**: per-thread DO base addressed `idFromName(threadId)`
164
+ where the threadId is tenant-minted, so its name carries the tenant like a
165
+ runId. Every request must state its authenticated tenant
166
+ (`THREAD_TENANT_HEADER`) and is asserted against that prefix before the
167
+ subclass's `route()` runs — fail closed (403). Everything else it throws rides
168
+ the shared `doErrorResponse` taxonomy, so a run driven from a thread route
169
+ keeps its 404/409/400 instead of collapsing to a 500.
170
+ - **`createThreadTopology`** (`@proofoftech/flowsafe/host-kit`): the sanctioned
171
+ way to reach a per-thread DO, and the MINTER for the header
172
+ `ThreadDurableObject` verifies. `send`/`forward` refuse (404) a threadId the
173
+ authenticated tenant does not own — before the DO is addressed — and stamp
174
+ `x-flowsafe-tenant` from the resolved `TenantContext`, `forward` OVERWRITING
175
+ whatever a client's own request carried. Mint and verify ship together:
176
+ forwarding a client Request verbatim (the existing hub idiom) would otherwise
177
+ let the client write the very header the thread DO authenticates on.
178
+
179
+ - 4ea35fd: Track A (durable agents): drive Mastra's durable-agent loop through the one
180
+ RunnerRuntime chokepoint so agent legs inherit the substrate's invariants —
181
+ additive and opt-in, no existing signature or `ApprovalRecord` shape changed.
182
+
183
+ - `@proofoftech/flowsafe/agent-runner` (new subpath): `createFlowsafeDurableAgent`
184
+ returns a `DurableAgent` subclass whose `executeWorkflow(runId, workflowInput)`
185
+ calls `runtime.start('durable-agentic-loop', { runId, inputData })` instead of
186
+ the base `createRun + start` (DL-001/DL-010), so INV-1 (server-minted runId),
187
+ the per-leg `requestContextForRun` grant derivation, and the resume ledger
188
+ apply to agent legs. `stream()`/`generate()`/`prepare()` are overridden to
189
+ REQUIRE a caller-minted runId — closing every inherited minting entry point's
190
+ upstream `crypto.randomUUID()` fallback (INV-1: a durable-agent run must carry
191
+ its tenant everywhere it becomes a key). The shared loop workflow is registered on
192
+ the runtime idempotently; the agent's stream pubsub defaults to the runtime's
193
+ identity (one feed per DO). `resume()` stays non-client-facing — resume flows
194
+ only through the approval-decision path (grant-only doctrine, P8).
195
+ - The durable tool-call step hands `tool.execute` the ENGINE-LEG requestContext
196
+ from its step params (spike S1, verified against `@mastra/core` 1.50.0 dist),
197
+ so the `breakwater.approvedConnectors` grant reaches the connector write gate
198
+ with zero extra wiring and a forged/self resume fails closed there.
199
+ - R-003: the record-creation/bridge path parses BOTH durable approval-suspend
200
+ shapes — nested `{ type:'approval', requireToolApproval:{ toolCallId, toolName,
201
+ args } }` and flat `{ type:'approval', toolCallId, toolName, args }` — and
202
+ derives `connectors:[toolName]` (the connector id the write gate checks) so an
203
+ approved agent gate mints exactly that grant. The resume-routing
204
+ `threadId`-capture seam (DL-002) is deferred to Track C, where the thread-DO
205
+ consumes it.
206
+ - `RunnerRuntime` now threads the host pubsub identity into both `createRun`
207
+ sites (`createRun({ runId, pubsub })`); undefined leaves behavior
208
+ byte-identical (polling fallback).
209
+ - The workerd `spike:verify` grows agent-gate scenarios proving the R-003
210
+ round-trip and forged-resume fail-closed on real workerd + D1.
211
+
212
+ - 15d4ec3: Track B (background tasks): the additive, opt-in substrate + defenses for
213
+ Mastra background tasks on the one Durable-Object + D1 chokepoint. No existing
214
+ signature or the `ApprovalRecord` shape changed; hosts stay byte-identical with
215
+ background tasks unconfigured.
216
+
217
+ - **breakwater `_background` model-override defense (DL-005), the ONE breakwater
218
+ change (MINOR).** `createConnector`'s wrapped `execute`/`dryRunExecute` reject
219
+ tool-call args carrying a `_background` field (core `LLMBackgroundOverride`)
220
+ unless the manifest opts in via `permissions.background` — the argv-flag-
221
+ smuggling posture of the agent-cli `buildFlags` defense. `background: true` is
222
+ allowed only on a read-only connector (a write-class opt-in throws at
223
+ construction); v1 keeps write/approval-carrying connectors foreground-only.
224
+ Plus a `backgroundExecution` tool-policy evaluator (deny-by-default for the
225
+ write class) as the defense-in-depth counterpart at the gate loop. Both are
226
+ DEFENSE-IN-DEPTH for DIRECT / NESTED calls, NOT the agent-path guard: on the
227
+ agent path core deletes `_background` from the args before dispatch (schema or
228
+ not), and core's own `resolveBackgroundConfig` baseEnabled gate — a breakwater
229
+ connector sets no background config — already prevents the model from
230
+ backgrounding an ineligible tool, so the breakwater reads see stripped args and
231
+ fire on nothing there. The real write boundary on every path (including inside
232
+ the background executor) is the requestContext grant.
233
+ - **`mastra_background_tasks` adopted into the D1 substrate in ONE change
234
+ (DL-003).** Registered in the schema-guard inventory (coverage `tenant-range`,
235
+ a new `background-task-ttl` retention kind), in `purgeTenant` (ranged over the
236
+ INV-1 salted `run_id`; new `PurgeTenantResult.backgroundTasks`), and given a
237
+ storage-layer TTL cleanup `purgeExpiredBackgroundTasks` (+
238
+ `BACKGROUND_TASK_TTL_PURGE_TABLES`) mirroring core's two-window
239
+ `BackgroundTaskManager.cleanup` so a purge cron reaps terminal rows without a
240
+ live manager. Surfaced through `FlowsafeWorkerConfig.backgroundTasks` as the
241
+ purge cron's own failure-isolated duty (undefined = no duty, byte-identical).
242
+ - **`@proofoftech/flowsafe/background-tasks` (new subpath):** `backgroundTasksStore`
243
+ (the async accessor onto @mastra/cloudflare-d1's `BackgroundTasksStorageD1` —
244
+ the D1 domain the adapter already ships; not reimplemented, per "what NOT to
245
+ build"), `BackgroundTaskHost` (hosts a `BackgroundTaskManager` on a DO with the
246
+ DL-015 boot/alarm lifecycle), and `createBackgroundTaskRoutes` (READ-only,
247
+ tenant-bound by construction, DL-014: list/stream REQUIRE a runId/threadId
248
+ filter and validate its salted prefix; `getTask` 404s a missing OR foreign
249
+ task with no oracle; the raw manager is never exposed).
250
+ - **Recovery seam pinned (R-002, spike B-S2):** DO eviction is survived by
251
+ re-registering the static tool executors and calling the PUBLIC async
252
+ `manager.init(pubsub)` at DO boot — which fires the manager's own (private)
253
+ `recoverStaleTasks()` internally. No private method is ever called.
254
+
255
+ **Known substrate limitation (spike B-S1 findings R-B1/R-B2/R-B3, documented in
256
+ `background-tasks/host.ts`):** durable background-task _execution_ does not yet
257
+ run on the Cloudflare substrate. Core runs task bodies on the _evented_
258
+ execution engine, which refuses to `createRun` unless the workflows store
259
+ reports `supportsConcurrentUpdates()`. `@mastra/cloudflare-d1` returns `false`
260
+ AND leaves `updateWorkflowResults`/`updateWorkflowState` as unimplemented throws
261
+ ("D1 does not support atomic read-modify-write") — so R-B1 is NOT a flag to
262
+ flip: overriding it passes core's gate then throws on the first step-update,
263
+ stranding the task at `running`. The P9 fix is an adapter that _implements_
264
+ atomic partial-updates (the DO's single-threaded lease makes that safe), plus
265
+ `mastra.startWorkers()` to run the evented workers (R-B2 — the two close
266
+ together). A latent tenant-isolation residual (R-B3) rides along: core keys the
267
+ internal `__background-task` run by the UNSALTED `taskId`, so its snapshot row
268
+ escapes tenant offboarding — inert while execution is blocked, but it MUST be
269
+ closed in the same change that enables execution, and a CI guard
270
+ (`background-tasks/d1-storage.test.ts`) fails the instant
271
+ `supportsConcurrentUpdates()` returns true. Persistence, the recovery seam,
272
+ tenant purge + TTL, the read routes, and the `_background` defense all work
273
+ regardless. `BackgroundTaskHost.boot()` warns once so the limitation is loud,
274
+ not a stray async throw.
275
+
276
+ - 4b953d4: Track C (long-running-agents program, M-004): signals, subscriptions, and
277
+ notifications. All additive and opt-in — a host that configures none of it is
278
+ byte-identical.
279
+
280
+ New subpath `@proofoftech/flowsafe/signals`:
281
+
282
+ - **Thread-DO signal routes** (`createThreadSignalRoutes`) — the
283
+ message/queue/signal/state/notification surface hosted on the per-thread DO.
284
+ Each call stamps the DO's one pubsub identity (`scope.init.pubsub`) onto the
285
+ agent so a send drains IN-PROCESS into an active loop: core keys its signal
286
+ registry by the pubsub instance, so affinity needs both the DO isolate
287
+ (idFromName(threadId)) and the shared pubsub — the DL-002 thesis, proven on
288
+ workerd (spike C-S2). An idle-thread WAKE starts a run, so it requires a
289
+ runtime-driven durable agent (`createFlowsafeDurableAgent`, which carries the
290
+ new `RUNTIME_DRIVEN_AGENT` brand from `@proofoftech/flowsafe/agent-runner`) —
291
+ its stream re-enters RunnerRuntime rather than the default engine; a wake
292
+ requested on a plain agent is refused fail-closed (degraded to a durable
293
+ persist), and every allowed wake consults the per-tenant run cap (DL-007). The
294
+ routes drive the public Agent methods only (`agentThreadStreamRuntime` is not
295
+ on core's exports map).
296
+ - **D1 storage domains** — `D1NotificationsStorage` (over `mastra_notifications`,
297
+ mirroring core's InMemory reference incl. coalescing) and
298
+ `D1ThreadStateStorage` (over `mastra_thread_state`, the state-signal lanes and
299
+ the goal record). `@mastra/cloudflare-d1` ships neither, so they are
300
+ flowsafe-owned; `createSignalStorageDomains` composes them into
301
+ `createD1Storage` (which now accepts injected `domains`) so
302
+ `agent.sendNotificationSignal` persists to D1. Both tables are registered in
303
+ the tenant-range offboarding purge (`purgeTenant`), the schema-guard inventory,
304
+ and their own opt-in TTL purges (`purgeExpiredNotifications`,
305
+ `purgeExpiredThreadState`) — the DL-003 triad, in one change. `PurgeTenantResult`
306
+ gains `notifications` + `threadState` counters (a breaking change only for
307
+ callers that build a `PurgeTenantResult` literal).
308
+ - **P6 ingestion trust boundary** (`createSignalRouter`) — every ingest is
309
+ authenticated → role-gated → thread-prefix-ownership-checked (404, no oracle) →
310
+ size-capped → memory-id-refused → attribute-allowlisted → per-tenant rate-capped
311
+ → forwarded via `createThreadTopology` (which overwrites the tenant header, so a
312
+ forged one cannot ride along; cross-tenant sends fail closed at both the topology
313
+ 404 and the DO 403, spike C-S4). Every ingest is audited (`signal.ingest`),
314
+ accepted OR rejected — including the three post-auth denials that read like an
315
+ attack on this channel (the role 403, the cross-tenant thread 404, the
316
+ memory-id 400); pre-auth failures (401 / resolver throw) are not audited. XML
317
+ injection is neutralized by core's `signalToXmlMarkup`, which entity-escapes
318
+ contents and attribute values and re-validates tag/attribute names — a single
319
+ layer over a soft-pinned core, so a C-S5 render test pins it (a core `escapeXml`
320
+ regression fails flowsafe CI); the route adds its own line at ingest —
321
+ `tagName` XML-name validation, the attribute-key allowlist, and the size cap —
322
+ but does not re-escape the contents. Signals never mint capability —
323
+ `sendToolApproval` is not an approval surface (P8).
324
+ - **`SignalClient`** — a DOM-free client in the `ApprovalApiClient` mold.
325
+
326
+ `createFlowsafeWorker` gains an opt-in signal stage (`buildSignalRouter` seam) and
327
+ two opt-in TTL cron duties (`NOTIFICATION_RETENTION_DAYS`,
328
+ `THREAD_STATE_RETENTION_DAYS`).
329
+
3
330
  ## 0.4.0
4
331
 
5
332
  ### Minor Changes