@xemahq/kernel-contracts 0.1.0 → 0.2.1

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 (280) hide show
  1. package/LICENSE +201 -0
  2. package/dist/agent-tool-inquiry/index.d.ts +2 -0
  3. package/dist/agent-tool-inquiry/index.d.ts.map +1 -0
  4. package/dist/agent-tool-inquiry/index.js +18 -0
  5. package/dist/agent-tool-inquiry/index.js.map +1 -0
  6. package/dist/agent-tool-inquiry/lib/agent-tool-inquiry.d.ts +43 -0
  7. package/dist/agent-tool-inquiry/lib/agent-tool-inquiry.d.ts.map +1 -0
  8. package/dist/agent-tool-inquiry/lib/agent-tool-inquiry.js +32 -0
  9. package/dist/agent-tool-inquiry/lib/agent-tool-inquiry.js.map +1 -0
  10. package/dist/agent-workspace/awp-spec.json +1 -1
  11. package/dist/app-runtime/index.d.ts +9 -0
  12. package/dist/app-runtime/index.d.ts.map +1 -0
  13. package/dist/app-runtime/index.js +25 -0
  14. package/dist/app-runtime/index.js.map +1 -0
  15. package/dist/app-runtime/lib/app-client.d.ts +11 -0
  16. package/dist/app-runtime/lib/app-client.d.ts.map +1 -0
  17. package/dist/app-runtime/lib/app-client.js +23 -0
  18. package/dist/app-runtime/lib/app-client.js.map +1 -0
  19. package/dist/app-runtime/lib/app-lockfile.d.ts +12 -0
  20. package/dist/app-runtime/lib/app-lockfile.d.ts.map +1 -0
  21. package/dist/app-runtime/lib/app-lockfile.js +17 -0
  22. package/dist/app-runtime/lib/app-lockfile.js.map +1 -0
  23. package/dist/app-runtime/lib/app.d.ts +26 -0
  24. package/dist/app-runtime/lib/app.d.ts.map +1 -0
  25. package/dist/app-runtime/lib/app.js +31 -0
  26. package/dist/app-runtime/lib/app.js.map +1 -0
  27. package/dist/app-runtime/lib/audience-policy.d.ts +31 -0
  28. package/dist/app-runtime/lib/audience-policy.d.ts.map +1 -0
  29. package/dist/app-runtime/lib/audience-policy.js +38 -0
  30. package/dist/app-runtime/lib/audience-policy.js.map +1 -0
  31. package/dist/app-runtime/lib/biome-install.d.ts +9 -0
  32. package/dist/app-runtime/lib/biome-install.d.ts.map +1 -0
  33. package/dist/app-runtime/lib/biome-install.js +13 -0
  34. package/dist/app-runtime/lib/biome-install.js.map +1 -0
  35. package/dist/app-runtime/lib/branding-config.d.ts +9 -0
  36. package/dist/app-runtime/lib/branding-config.d.ts.map +1 -0
  37. package/dist/app-runtime/lib/branding-config.js +24 -0
  38. package/dist/app-runtime/lib/branding-config.js.map +1 -0
  39. package/dist/app-runtime/lib/delegated-session.d.ts +15 -0
  40. package/dist/app-runtime/lib/delegated-session.d.ts.map +1 -0
  41. package/dist/app-runtime/lib/delegated-session.js +29 -0
  42. package/dist/app-runtime/lib/delegated-session.js.map +1 -0
  43. package/dist/app-runtime/lib/external-subject.d.ts +9 -0
  44. package/dist/app-runtime/lib/external-subject.d.ts.map +1 -0
  45. package/dist/app-runtime/lib/external-subject.js +19 -0
  46. package/dist/app-runtime/lib/external-subject.js.map +1 -0
  47. package/dist/connector/index.d.ts +9 -0
  48. package/dist/connector/index.d.ts.map +1 -0
  49. package/dist/connector/index.js +25 -0
  50. package/dist/connector/index.js.map +1 -0
  51. package/dist/connector/lib/adapter-kind.d.ts +8 -0
  52. package/dist/connector/lib/adapter-kind.d.ts.map +1 -0
  53. package/dist/connector/lib/adapter-kind.js +14 -0
  54. package/dist/connector/lib/adapter-kind.js.map +1 -0
  55. package/dist/connector/lib/capability-refs.d.ts +14 -0
  56. package/dist/connector/lib/capability-refs.d.ts.map +1 -0
  57. package/dist/connector/lib/capability-refs.js +15 -0
  58. package/dist/connector/lib/capability-refs.js.map +1 -0
  59. package/dist/connector/lib/capability.d.ts +18 -0
  60. package/dist/connector/lib/capability.d.ts.map +1 -0
  61. package/dist/connector/lib/capability.js +24 -0
  62. package/dist/connector/lib/capability.js.map +1 -0
  63. package/dist/connector/lib/credential-kind.d.ts +42 -0
  64. package/dist/connector/lib/credential-kind.d.ts.map +1 -0
  65. package/dist/connector/lib/credential-kind.js +26 -0
  66. package/dist/connector/lib/credential-kind.js.map +1 -0
  67. package/dist/connector/lib/envelope-schema.d.ts +6 -0
  68. package/dist/connector/lib/envelope-schema.d.ts.map +1 -0
  69. package/dist/connector/lib/envelope-schema.js +150 -0
  70. package/dist/connector/lib/envelope-schema.js.map +1 -0
  71. package/dist/connector/lib/filter-expr-schema.d.ts +4 -0
  72. package/dist/connector/lib/filter-expr-schema.d.ts.map +1 -0
  73. package/dist/connector/lib/filter-expr-schema.js +65 -0
  74. package/dist/connector/lib/filter-expr-schema.js.map +1 -0
  75. package/dist/connector/lib/filter-expr-validate.d.ts +10 -0
  76. package/dist/connector/lib/filter-expr-validate.d.ts.map +1 -0
  77. package/dist/connector/lib/filter-expr-validate.js +58 -0
  78. package/dist/connector/lib/filter-expr-validate.js.map +1 -0
  79. package/dist/connector/lib/filter-expr.d.ts +49 -0
  80. package/dist/connector/lib/filter-expr.d.ts.map +1 -0
  81. package/dist/connector/lib/filter-expr.js +135 -0
  82. package/dist/connector/lib/filter-expr.js.map +1 -0
  83. package/dist/connector/lib/onboarding-manifest.d.ts +45 -0
  84. package/dist/connector/lib/onboarding-manifest.d.ts.map +1 -0
  85. package/dist/connector/lib/onboarding-manifest.js +30 -0
  86. package/dist/connector/lib/onboarding-manifest.js.map +1 -0
  87. package/dist/document-render/index.d.ts +7 -0
  88. package/dist/document-render/index.d.ts.map +1 -0
  89. package/dist/document-render/index.js +23 -0
  90. package/dist/document-render/index.js.map +1 -0
  91. package/dist/document-render/lib/measure-layout.d.ts +44 -0
  92. package/dist/document-render/lib/measure-layout.d.ts.map +1 -0
  93. package/dist/document-render/lib/measure-layout.js +16 -0
  94. package/dist/document-render/lib/measure-layout.js.map +1 -0
  95. package/dist/document-render/lib/render-enums.d.ts +18 -0
  96. package/dist/document-render/lib/render-enums.d.ts.map +1 -0
  97. package/dist/document-render/lib/render-enums.js +24 -0
  98. package/dist/document-render/lib/render-enums.js.map +1 -0
  99. package/dist/document-render/lib/render-record.d.ts +22 -0
  100. package/dist/document-render/lib/render-record.d.ts.map +1 -0
  101. package/dist/document-render/lib/render-record.js +3 -0
  102. package/dist/document-render/lib/render-record.js.map +1 -0
  103. package/dist/document-render/lib/render-request.d.ts +24 -0
  104. package/dist/document-render/lib/render-request.d.ts.map +1 -0
  105. package/dist/document-render/lib/render-request.js +12 -0
  106. package/dist/document-render/lib/render-request.js.map +1 -0
  107. package/dist/document-render/lib/render-source.d.ts +43 -0
  108. package/dist/document-render/lib/render-source.d.ts.map +1 -0
  109. package/dist/document-render/lib/render-source.js +31 -0
  110. package/dist/document-render/lib/render-source.js.map +1 -0
  111. package/dist/document-render/lib/xema-prompt.d.ts +11 -0
  112. package/dist/document-render/lib/xema-prompt.d.ts.map +1 -0
  113. package/dist/document-render/lib/xema-prompt.js +46 -0
  114. package/dist/document-render/lib/xema-prompt.js.map +1 -0
  115. package/dist/inquiry/index.d.ts +7 -0
  116. package/dist/inquiry/index.d.ts.map +1 -0
  117. package/dist/inquiry/index.js +23 -0
  118. package/dist/inquiry/index.js.map +1 -0
  119. package/dist/inquiry/lib/enums.d.ts +36 -0
  120. package/dist/inquiry/lib/enums.d.ts.map +1 -0
  121. package/dist/inquiry/lib/enums.js +45 -0
  122. package/dist/inquiry/lib/enums.js.map +1 -0
  123. package/dist/inquiry/lib/inquiry.d.ts +332 -0
  124. package/dist/inquiry/lib/inquiry.d.ts.map +1 -0
  125. package/dist/inquiry/lib/inquiry.js +102 -0
  126. package/dist/inquiry/lib/inquiry.js.map +1 -0
  127. package/dist/inquiry/lib/kind-registry.d.ts +14 -0
  128. package/dist/inquiry/lib/kind-registry.d.ts.map +1 -0
  129. package/dist/inquiry/lib/kind-registry.js +24 -0
  130. package/dist/inquiry/lib/kind-registry.js.map +1 -0
  131. package/dist/inquiry/lib/policy.d.ts +19 -0
  132. package/dist/inquiry/lib/policy.d.ts.map +1 -0
  133. package/dist/inquiry/lib/policy.js +21 -0
  134. package/dist/inquiry/lib/policy.js.map +1 -0
  135. package/dist/inquiry/lib/recipient.d.ts +111 -0
  136. package/dist/inquiry/lib/recipient.d.ts.map +1 -0
  137. package/dist/inquiry/lib/recipient.js +64 -0
  138. package/dist/inquiry/lib/recipient.js.map +1 -0
  139. package/dist/inquiry/lib/workflow-verdict-evaluator.d.ts +15 -0
  140. package/dist/inquiry/lib/workflow-verdict-evaluator.d.ts.map +1 -0
  141. package/dist/inquiry/lib/workflow-verdict-evaluator.js +145 -0
  142. package/dist/inquiry/lib/workflow-verdict-evaluator.js.map +1 -0
  143. package/dist/org-database/index.d.ts +5 -0
  144. package/dist/org-database/index.d.ts.map +1 -0
  145. package/dist/org-database/index.js +21 -0
  146. package/dist/org-database/index.js.map +1 -0
  147. package/dist/org-database/lib/db-result-event.d.ts +24 -0
  148. package/dist/org-database/lib/db-result-event.d.ts.map +1 -0
  149. package/dist/org-database/lib/db-result-event.js +3 -0
  150. package/dist/org-database/lib/db-result-event.js.map +1 -0
  151. package/dist/org-database/lib/driver.d.ts +43 -0
  152. package/dist/org-database/lib/driver.d.ts.map +1 -0
  153. package/dist/org-database/lib/driver.js +3 -0
  154. package/dist/org-database/lib/driver.js.map +1 -0
  155. package/dist/org-database/lib/enums.d.ts +41 -0
  156. package/dist/org-database/lib/enums.d.ts.map +1 -0
  157. package/dist/org-database/lib/enums.js +51 -0
  158. package/dist/org-database/lib/enums.js.map +1 -0
  159. package/dist/org-database/lib/migration-runner.d.ts +15 -0
  160. package/dist/org-database/lib/migration-runner.d.ts.map +1 -0
  161. package/dist/org-database/lib/migration-runner.js +3 -0
  162. package/dist/org-database/lib/migration-runner.js.map +1 -0
  163. package/dist/project-kit/index.d.ts +2 -0
  164. package/dist/project-kit/index.d.ts.map +1 -0
  165. package/dist/project-kit/index.js +18 -0
  166. package/dist/project-kit/index.js.map +1 -0
  167. package/dist/project-kit/lib/project-kit.d.ts +63 -0
  168. package/dist/project-kit/lib/project-kit.d.ts.map +1 -0
  169. package/dist/project-kit/lib/project-kit.js +32 -0
  170. package/dist/project-kit/lib/project-kit.js.map +1 -0
  171. package/dist/provisioning/index.d.ts +2 -0
  172. package/dist/provisioning/index.d.ts.map +1 -0
  173. package/dist/provisioning/index.js +18 -0
  174. package/dist/provisioning/index.js.map +1 -0
  175. package/dist/provisioning/lib/provisioning.d.ts +256 -0
  176. package/dist/provisioning/lib/provisioning.d.ts.map +1 -0
  177. package/dist/provisioning/lib/provisioning.js +221 -0
  178. package/dist/provisioning/lib/provisioning.js.map +1 -0
  179. package/dist/worker-runtime/index.d.ts +6 -0
  180. package/dist/worker-runtime/index.d.ts.map +1 -0
  181. package/dist/worker-runtime/index.js +22 -0
  182. package/dist/worker-runtime/index.js.map +1 -0
  183. package/dist/worker-runtime/lib/capabilities.d.ts +22 -0
  184. package/dist/worker-runtime/lib/capabilities.d.ts.map +1 -0
  185. package/dist/worker-runtime/lib/capabilities.js +3 -0
  186. package/dist/worker-runtime/lib/capabilities.js.map +1 -0
  187. package/dist/worker-runtime/lib/enums.d.ts +10 -0
  188. package/dist/worker-runtime/lib/enums.d.ts.map +1 -0
  189. package/dist/worker-runtime/lib/enums.js +15 -0
  190. package/dist/worker-runtime/lib/enums.js.map +1 -0
  191. package/dist/worker-runtime/lib/messages.d.ts +33 -0
  192. package/dist/worker-runtime/lib/messages.d.ts.map +1 -0
  193. package/dist/worker-runtime/lib/messages.js +3 -0
  194. package/dist/worker-runtime/lib/messages.js.map +1 -0
  195. package/dist/worker-runtime/lib/runtime.d.ts +35 -0
  196. package/dist/worker-runtime/lib/runtime.d.ts.map +1 -0
  197. package/dist/worker-runtime/lib/runtime.js +3 -0
  198. package/dist/worker-runtime/lib/runtime.js.map +1 -0
  199. package/dist/worker-runtime/lib/schemas.d.ts +87 -0
  200. package/dist/worker-runtime/lib/schemas.d.ts.map +1 -0
  201. package/dist/worker-runtime/lib/schemas.js +57 -0
  202. package/dist/worker-runtime/lib/schemas.js.map +1 -0
  203. package/dist/workspace-storage/index.d.ts +4 -0
  204. package/dist/workspace-storage/index.d.ts.map +1 -0
  205. package/dist/workspace-storage/index.js +20 -0
  206. package/dist/workspace-storage/index.js.map +1 -0
  207. package/dist/workspace-storage/lib/enums.d.ts +34 -0
  208. package/dist/workspace-storage/lib/enums.d.ts.map +1 -0
  209. package/dist/workspace-storage/lib/enums.js +42 -0
  210. package/dist/workspace-storage/lib/enums.js.map +1 -0
  211. package/dist/workspace-storage/lib/schemas.d.ts +56 -0
  212. package/dist/workspace-storage/lib/schemas.d.ts.map +1 -0
  213. package/dist/workspace-storage/lib/schemas.js +59 -0
  214. package/dist/workspace-storage/lib/schemas.js.map +1 -0
  215. package/dist/workspace-storage/lib/types.d.ts +71 -0
  216. package/dist/workspace-storage/lib/types.d.ts.map +1 -0
  217. package/dist/workspace-storage/lib/types.js +3 -0
  218. package/dist/workspace-storage/lib/types.js.map +1 -0
  219. package/package.json +22 -153
  220. package/src/agent-composition/lib/composition-workspace.ts +1 -1
  221. package/src/agent-tool-inquiry/index.ts +16 -0
  222. package/src/agent-tool-inquiry/lib/agent-tool-inquiry.ts +82 -0
  223. package/src/agent-workspace/lib/workspace-spec.ts +1 -1
  224. package/src/app-runtime/index.ts +8 -0
  225. package/src/app-runtime/lib/app-client.ts +44 -0
  226. package/src/app-runtime/lib/app-lockfile.ts +54 -0
  227. package/src/app-runtime/lib/app.ts +84 -0
  228. package/src/app-runtime/lib/audience-policy.ts +87 -0
  229. package/src/app-runtime/lib/biome-install.ts +29 -0
  230. package/src/app-runtime/lib/branding-config.ts +54 -0
  231. package/src/app-runtime/lib/delegated-session.ts +69 -0
  232. package/src/app-runtime/lib/external-subject.ts +34 -0
  233. package/src/connector/index.ts +8 -0
  234. package/src/connector/lib/adapter-kind.ts +37 -0
  235. package/src/connector/lib/capability-refs.ts +29 -0
  236. package/src/connector/lib/capability.ts +38 -0
  237. package/src/connector/lib/credential-kind.ts +120 -0
  238. package/src/connector/lib/envelope-schema.ts +256 -0
  239. package/src/connector/lib/filter-expr-schema.ts +75 -0
  240. package/src/connector/lib/filter-expr-validate.ts +91 -0
  241. package/src/connector/lib/filter-expr.ts +208 -0
  242. package/src/connector/lib/onboarding-manifest.ts +167 -0
  243. package/src/document-render/index.ts +25 -0
  244. package/src/document-render/lib/measure-layout.ts +61 -0
  245. package/src/document-render/lib/render-enums.ts +49 -0
  246. package/src/document-render/lib/render-record.ts +38 -0
  247. package/src/document-render/lib/render-request.ts +16 -0
  248. package/src/document-render/lib/render-source.ts +44 -0
  249. package/src/document-render/lib/xema-prompt.ts +100 -0
  250. package/src/inquiry/index.ts +23 -0
  251. package/src/inquiry/lib/enums.ts +103 -0
  252. package/src/inquiry/lib/inquiry.ts +182 -0
  253. package/src/inquiry/lib/kind-registry.ts +57 -0
  254. package/src/inquiry/lib/policy.ts +27 -0
  255. package/src/inquiry/lib/recipient.ts +188 -0
  256. package/src/inquiry/lib/workflow-verdict-evaluator.ts +220 -0
  257. package/src/org-database/index.ts +4 -0
  258. package/src/org-database/lib/db-result-event.ts +59 -0
  259. package/src/org-database/lib/driver.ts +47 -0
  260. package/src/org-database/lib/enums.ts +51 -0
  261. package/src/org-database/lib/migration-runner.ts +17 -0
  262. package/src/project-kit/index.ts +17 -0
  263. package/src/project-kit/lib/project-kit.ts +227 -0
  264. package/src/provisioning/index.ts +17 -0
  265. package/src/provisioning/lib/provisioning.ts +499 -0
  266. package/src/worker-runtime/index.ts +14 -0
  267. package/src/worker-runtime/lib/capabilities.ts +58 -0
  268. package/src/worker-runtime/lib/enums.ts +33 -0
  269. package/src/worker-runtime/lib/messages.ts +49 -0
  270. package/src/worker-runtime/lib/runtime.ts +109 -0
  271. package/src/worker-runtime/lib/schemas.ts +72 -0
  272. package/src/workflow/lib/activity-outputs.ts +1 -1
  273. package/src/workflow/lib/compiled-run.ts +1 -1
  274. package/src/workflow/lib/compiled-workspace-manifest.ts +1 -1
  275. package/src/workflow/lib/model-ref.ts +1 -1
  276. package/src/workflow/lib/workspace-manifest-enums.ts +1 -1
  277. package/src/workspace-storage/index.ts +12 -0
  278. package/src/workspace-storage/lib/enums.ts +78 -0
  279. package/src/workspace-storage/lib/schemas.ts +75 -0
  280. package/src/workspace-storage/lib/types.ts +145 -0
@@ -0,0 +1,109 @@
1
+ // ═══════════════════════════════════════════════════════════════════════════
2
+ // ── Worker runtime — driver contract ──
3
+ //
4
+ // The minimal interface every worker-runtime implementation satisfies. The
5
+ // kernel does NOT know about Kubernetes pod specs — `BuildPodSpecInput` is
6
+ // deliberately schedule-agnostic. Concrete schedulers (k8s, docker-swarm,
7
+ // docker-local) live in the platform/runtime services and translate this
8
+ // abstract spec to their native shapes.
9
+ // ═══════════════════════════════════════════════════════════════════════════
10
+
11
+ import type { AbstractMount } from '../../workspace-storage';
12
+
13
+ import type {
14
+ SchedulerCapabilityRequest,
15
+ WorkerRuntimeCapabilityBits,
16
+ } from './capabilities';
17
+ import type { WorkerRuntimeKind } from './enums';
18
+ import type { RuntimeEvent, UserMessage } from './messages';
19
+
20
+ /**
21
+ * Schedule-agnostic input the composer hands to `buildPodSpec`. Concrete
22
+ * scheduler adapters translate this to their native shape (k8s `PodSpec`,
23
+ * Docker `ContainerCreateOptions`, …). Intentionally minimal — adding a
24
+ * k8s-specific field here would leak scheduler knowledge into the kernel.
25
+ */
26
+ export interface BuildPodSpecInput {
27
+ /** Image reference (registry/name:tag or digest). */
28
+ readonly image: string;
29
+ /** Env vars to set on the worker process. */
30
+ readonly env: Readonly<Record<string, string>>;
31
+ /** Volume mounts produced by storage drivers (`/workspace`, `/templates`). */
32
+ readonly mounts: readonly AbstractMount[];
33
+ /** Optional region hint for co-scheduling with storage pools. */
34
+ readonly region?: string;
35
+ /** Scheduler features the runtime depends on. */
36
+ readonly capabilities: readonly SchedulerCapabilityRequest[];
37
+ }
38
+
39
+ /**
40
+ * Input describing the agent + skills + model configuration to bundle for
41
+ * a worker. `mcpConfig` and `opencodeConfigBase64` are intentionally typed
42
+ * as opaque strings at the kernel level — runtime implementations
43
+ * interpret them. Other runtimes may carry a runtime-specific blob in the
44
+ * same `opencodeConfigBase64` slot under a different conceptual name once
45
+ * the kernel generalizes that field.
46
+ */
47
+ export interface BuildBundleInput {
48
+ /** Slug of the primary agent that owns the turn. */
49
+ readonly primaryAgent: string;
50
+ /** Slugs of sub-agents the primary may delegate to. */
51
+ readonly subAgents: readonly string[];
52
+ /** Per-invocation model override; absent = matrix-resolved default. */
53
+ readonly modelOverride?: string;
54
+ /** Opaque MCP config blob; runtime-specific. */
55
+ readonly mcpConfig?: string;
56
+ /** Opaque base64-encoded OpenCode config; runtime-specific. */
57
+ readonly opencodeConfigBase64?: string;
58
+ }
59
+
60
+ /**
61
+ * A session bundle is an opaque wrapper passed to `applySessionBundle`.
62
+ * The `fingerprint` is a stable content hash callers use to short-circuit
63
+ * re-application; the `payloadBase64` is interpreted only by the runtime
64
+ * implementation that produced it.
65
+ */
66
+ export interface SessionBundle {
67
+ readonly fingerprint: string;
68
+ readonly payloadBase64: string;
69
+ }
70
+
71
+ /**
72
+ * The contract every worker-runtime implementation MUST satisfy. The
73
+ * implementation lives in the appropriate platform/runtime SDK
74
+ * (e.g. opencode-runtime-driver).
75
+ */
76
+ export interface WorkerRuntime {
77
+ readonly kind: WorkerRuntimeKind;
78
+ readonly capabilities: WorkerRuntimeCapabilityBits;
79
+ /**
80
+ * The connector kind (from `@xemahq/connector-contracts`) this runtime
81
+ * must be paired with at session-start. The composer fails fast if a
82
+ * runtime is invoked without a connector of this kind in scope.
83
+ */
84
+ readonly connectorKindRequired: string;
85
+
86
+ /** Build the schedule-agnostic pod spec for a worker. */
87
+ buildPodSpec(input: BuildPodSpecInput): Promise<unknown>;
88
+
89
+ /** Compose a session bundle from the agent/skills/model inputs. */
90
+ buildSessionBundle(input: BuildBundleInput): Promise<SessionBundle>;
91
+
92
+ /** Push a previously-built bundle into a live worker (idempotent). */
93
+ applySessionBundle(bundle: SessionBundle): Promise<void>;
94
+
95
+ /** Send a user message; runtime streams events back. */
96
+ sendUserMessage(message: UserMessage): AsyncIterable<RuntimeEvent>;
97
+
98
+ /** Pause a session — the worker may be scaled to zero. */
99
+ pause(): Promise<void>;
100
+
101
+ /** Resume a previously-paused session — worker comes back online. */
102
+ resume(): Promise<void>;
103
+
104
+ /**
105
+ * True iff this runtime supports a `tool.execute.after` hook that
106
+ * auto-commits workspace changes (used by the workflow surface).
107
+ */
108
+ readonly autoCommitHookSupported: boolean;
109
+ }
@@ -0,0 +1,72 @@
1
+ // ═══════════════════════════════════════════════════════════════════════════
2
+ // ── Worker runtime — zod schemas ──
3
+ //
4
+ // Runtime validators for value-typed shapes that may cross the wire:
5
+ // enums, capability bits, actor/attachment/message, runtime events. We do
6
+ // NOT validate the `WorkerRuntime` interface itself (it's an in-process
7
+ // object with non-serializable methods).
8
+ // ═══════════════════════════════════════════════════════════════════════════
9
+
10
+ import { z } from 'zod';
11
+
12
+ import { HookKind, WorkerRuntimeKind } from './enums';
13
+
14
+ export const workerRuntimeKindSchema = z.nativeEnum(WorkerRuntimeKind);
15
+ export const hookKindSchema = z.nativeEnum(HookKind);
16
+
17
+ export const workerRuntimeCapabilityBitsSchema = z.object({
18
+ hotMcp: z.boolean(),
19
+ hotModelSwap: z.boolean(),
20
+ sessionFork: z.boolean(),
21
+ subAgentCrud: z.boolean(),
22
+ hooks: z.array(hookKindSchema).readonly(),
23
+ previewSupervisor: z.boolean(),
24
+ gatewayAttributedCalls: z.boolean(),
25
+ llmEndpointOverride: z.boolean(),
26
+ });
27
+
28
+ export const schedulerCapabilityBitsSchema = z.object({
29
+ autoRestart: z.boolean(),
30
+ healthCheck: z.boolean(),
31
+ hpa: z.boolean(),
32
+ networkPolicy: z.boolean(),
33
+ });
34
+
35
+ export const schedulerCapabilityRequestSchema = z.object({
36
+ kind: z.enum(['autoRestart', 'healthCheck', 'hpa', 'networkPolicy']),
37
+ optional: z.boolean(),
38
+ });
39
+
40
+ export const actorRefSchema = z.object({
41
+ subjectKind: z.enum(['org_user', 'external_guest']),
42
+ subjectRef: z.string().min(1),
43
+ displayName: z.string().min(1),
44
+ });
45
+
46
+ export const attachmentSchema = z.object({
47
+ kind: z.enum(['file', 'image', 'url']),
48
+ value: z.string().min(1),
49
+ });
50
+
51
+ export const userMessageSchema = z.object({
52
+ actor: actorRefSchema,
53
+ content: z.string(),
54
+ attachments: z.array(attachmentSchema).optional(),
55
+ });
56
+
57
+ export const runtimeEventSchema = z.discriminatedUnion('kind', [
58
+ z.object({ kind: z.literal('text-delta'), text: z.string() }),
59
+ z.object({ kind: z.literal('tool-use'), tool: z.string().min(1), input: z.unknown() }),
60
+ z.object({ kind: z.literal('tool-result'), tool: z.string().min(1), output: z.unknown() }),
61
+ z.object({ kind: z.literal('turn-end') }),
62
+ z.object({
63
+ kind: z.literal('error'),
64
+ message: z.string(),
65
+ retryable: z.boolean(),
66
+ }),
67
+ ]);
68
+
69
+ export const sessionBundleSchema = z.object({
70
+ fingerprint: z.string().min(1),
71
+ payloadBase64: z.string().min(1),
72
+ });
@@ -91,7 +91,7 @@ export interface ActivityOutputDeclaration {
91
91
 
92
92
  // NOTE: per-output deliverable-spec bindings live on the action
93
93
  // MANIFEST (`spec.outputBindings`, see `ActionManifestSpec` in
94
- // `@xemahq/workflow-dsl`) — that's the single source of truth the DSL
94
+ // `@xemahq/dsl/workflow`) — that's the single source of truth the DSL
95
95
  // compiler reads at compile time. `OUTPUT_DECLARATIONS` is a worker-
96
96
  // internal contract used by the output-promotion wrapper, so binding
97
97
  // metadata never has to flow through it.
@@ -38,7 +38,7 @@ export type CompiledManifestSource =
38
38
 
39
39
  /**
40
40
  * A CompiledRun is the IMMUTABLE semantic expansion of a workflow definition
41
- * for one execution. Produced by `@xemahq/workflow-dsl` at run
41
+ * for one execution. Produced by `@xemahq/dsl/workflow` at run
42
42
  * start, written to the snapshot store, referenced by {@link SnapshotRef}
43
43
  * as the input to `rootRunWorkflow`.
44
44
  *
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Compiled output types for WorkspaceManifest — produced by
3
- * `@xemahq/workspace-manifest-dsl`'s `compileManifest()` and embedded
3
+ * `@xemahq/dsl/workspace-manifest`'s `compileManifest()` and embedded
4
4
  * in {@link CompiledRun} for inline-agent steps.
5
5
  *
6
6
  * Defined here (rather than in workspace-manifest-dsl) to avoid a
@@ -30,7 +30,7 @@ import { z } from 'zod';
30
30
  *
31
31
  * Mirrors `biomes/agent-runtime/api/llm-registry-api`'s Prisma `ModelClass` column.
32
32
  *
33
- * IMPORTANT — the one allowed copy is in `@xemahq/biome-builder`'s
33
+ * IMPORTANT — the one allowed copy is in `@xemahq/biome-sdk/builder`'s
34
34
  * `contribution-schemas.ts`, because that package publishes to the
35
35
  * public npm registry and cannot depend on this GitHub-Packages-scoped
36
36
  * package. That copy carries a comment marker; keep both lists
@@ -1,7 +1,7 @@
1
1
  // ═══════════════════════════════════════════════════════════════════════════
2
2
  // ── Workspace Manifest closed-domain enums ──
3
3
  //
4
- // Kernel-tier closed sets consumed by `@xemahq/workspace-manifest-dsl`,
4
+ // Kernel-tier closed sets consumed by `@xemahq/dsl/workspace-manifest`,
5
5
  // `@xemahq/agent-session-runtime`, the workflow DSL compiler, the
6
6
  // llm-registry-api composition seeder, and frontend manifest editors.
7
7
  // Each enum keeps the manifest contract auditable end-to-end —
@@ -0,0 +1,12 @@
1
+ // ═══════════════════════════════════════════════════════════════════════════
2
+ // ── Workspace Storage Contracts — Barrel Export ──
3
+ //
4
+ // Kernel (Layer 1) contracts for the storage-pool / allocator abstraction.
5
+ // Pure types + closed enums + zod schemas. Zero NestJS, zero Prisma,
6
+ // zero platform assumptions (no k8s, no docker-specifics). Concrete
7
+ // driver implementations live in the storage-pool service.
8
+ // ═══════════════════════════════════════════════════════════════════════════
9
+
10
+ export * from './lib/enums';
11
+ export * from './lib/types';
12
+ export * from './lib/schemas';
@@ -0,0 +1,78 @@
1
+ // ═══════════════════════════════════════════════════════════════════════════
2
+ // ── Workspace storage — closed-domain enums ──
3
+ //
4
+ // Kernel-level enums shared across every consumer of the StorageDriver
5
+ // abstraction: the storage-pool service, workspace allocator, and worker
6
+ // runtime. NO platform-specific assumptions live here — every enum value
7
+ // describes a generic concept.
8
+ // ═══════════════════════════════════════════════════════════════════════════
9
+
10
+ /**
11
+ * The role an attachment plays inside a worker pod. Storage drivers may
12
+ * mount the same underlying pool for either purpose; the kind dictates the
13
+ * mount path convention used by the workspace composer.
14
+ */
15
+ export enum AttachmentKind {
16
+ /** Read-write per-session workspace (`/workspace`). */
17
+ Workspace = 'workspace',
18
+ /** Read-only template share (`/templates`). */
19
+ Templates = 'templates',
20
+ }
21
+
22
+ /**
23
+ * Closed set of storage backends Xema knows how to drive. New backends MUST
24
+ * be added here AND implement the `StorageDriver` interface; consumers MUST
25
+ * `switch` exhaustively.
26
+ */
27
+ export enum StorageDriverKind {
28
+ Longhorn = 'longhorn',
29
+ EFS = 'efs',
30
+ Filestore = 'filestore',
31
+ AzureFiles = 'azure_files',
32
+ DockerLocal = 'docker_local',
33
+ DockerSwarmCsi = 'docker_swarm_csi',
34
+ Nfs = 'nfs',
35
+ HostPath = 'host_path',
36
+ }
37
+
38
+ /**
39
+ * Lifecycle of a managed storage pool. Pools progress provisioning → active
40
+ * → draining → decommissioned. A pool in any non-`active` state must refuse
41
+ * new allocations.
42
+ */
43
+ export enum PoolStatus {
44
+ Provisioning = 'provisioning',
45
+ Active = 'active',
46
+ Draining = 'draining',
47
+ Decommissioned = 'decommissioned',
48
+ }
49
+
50
+ /**
51
+ * Who an allocation belongs to.
52
+ *
53
+ * The `template_*` scopes are read-only template shares mounted under
54
+ * `/templates` (the system tier is platform-shipped; the org tier is
55
+ * tenant-curated). They are distinct from the per-session/project/org
56
+ * workspace scopes so the allocator can route them to different driver
57
+ * configs (e.g. a read-only PV vs a read-write PVC).
58
+ */
59
+ export enum AllocationScope {
60
+ Org = 'org',
61
+ Project = 'project',
62
+ Session = 'session',
63
+ TemplateOrg = 'template_org',
64
+ TemplateSystem = 'template_system',
65
+ }
66
+
67
+ /**
68
+ * Lifecycle of a single storage allocation. `pending` allocations have no
69
+ * mounted volume yet; `ready` means the sub-path exists and can be mounted.
70
+ * `archived` keeps the sub-path on the pool but disallows new mounts;
71
+ * `deleted` removes the sub-path entirely.
72
+ */
73
+ export enum AllocationStatus {
74
+ Pending = 'pending',
75
+ Ready = 'ready',
76
+ Archived = 'archived',
77
+ Deleted = 'deleted',
78
+ }
@@ -0,0 +1,75 @@
1
+ // ═══════════════════════════════════════════════════════════════════════════
2
+ // ── Workspace storage — zod schemas ──
3
+ //
4
+ // Runtime validators mirroring the enums and DTOs in this package. Kept in
5
+ // a separate file so type-only consumers can tree-shake them out.
6
+ // ═══════════════════════════════════════════════════════════════════════════
7
+
8
+ import { z } from 'zod';
9
+
10
+ import {
11
+ AllocationScope,
12
+ AllocationStatus,
13
+ AttachmentKind,
14
+ PoolStatus,
15
+ StorageDriverKind,
16
+ } from './enums';
17
+
18
+ export const attachmentKindSchema = z.nativeEnum(AttachmentKind);
19
+ export const storageDriverKindSchema = z.nativeEnum(StorageDriverKind);
20
+ export const poolStatusSchema = z.nativeEnum(PoolStatus);
21
+ export const allocationScopeSchema = z.nativeEnum(AllocationScope);
22
+ export const allocationStatusSchema = z.nativeEnum(AllocationStatus);
23
+
24
+ export const abstractMountSchema = z.object({
25
+ poolId: z.string().min(1),
26
+ subPath: z.string().min(1),
27
+ mountPath: z.string().min(1),
28
+ readOnly: z.boolean().optional(),
29
+ driverHandle: z.string().min(1),
30
+ });
31
+
32
+ export const poolSpecSchema = z.object({
33
+ slug: z.string().min(1),
34
+ driverKind: storageDriverKindSchema,
35
+ driverConfig: z.record(z.string(), z.unknown()),
36
+ capacityBytes: z.bigint().nonnegative(),
37
+ region: z.string().min(1),
38
+ environment: z.string().min(1).optional(),
39
+ costClass: z.string().min(1).optional(),
40
+ });
41
+
42
+ export const ensuredPoolSchema = z.object({
43
+ poolId: z.string().min(1),
44
+ pvcName: z.string().min(1),
45
+ pvcNamespace: z.string().min(1),
46
+ status: poolStatusSchema,
47
+ });
48
+
49
+ export const storagePoolSchema = z.object({
50
+ id: z.string().min(1),
51
+ slug: z.string().min(1),
52
+ driverKind: storageDriverKindSchema,
53
+ region: z.string().min(1),
54
+ environment: z.string().min(1).optional(),
55
+ capacityBytes: z.bigint().nonnegative(),
56
+ costClass: z.string().min(1).optional(),
57
+ status: poolStatusSchema,
58
+ createdAt: z.string().min(1),
59
+ updatedAt: z.string().min(1),
60
+ });
61
+
62
+ export const storageAllocationSchema = z.object({
63
+ id: z.string().min(1),
64
+ poolId: z.string().min(1),
65
+ scope: allocationScopeSchema,
66
+ orgId: z.string().min(1).optional(),
67
+ projectId: z.string().min(1).optional(),
68
+ sessionId: z.string().min(1).optional(),
69
+ region: z.string().min(1),
70
+ subPath: z.string().min(1),
71
+ bytesUsed: z.bigint().nonnegative(),
72
+ status: allocationStatusSchema,
73
+ lastTouchedAt: z.string().min(1),
74
+ createdAt: z.string().min(1),
75
+ });
@@ -0,0 +1,145 @@
1
+ // ═══════════════════════════════════════════════════════════════════════════
2
+ // ── Workspace storage — driver & mount types ──
3
+ //
4
+ // Abstract types every storage driver implementation must satisfy. The
5
+ // kernel is platform-agnostic: nothing here knows about Kubernetes, Docker
6
+ // Swarm, or any specific filesystem — those concerns live in concrete
7
+ // driver implementations under apps/<storage-pool-api>/drivers/*.
8
+ // ═══════════════════════════════════════════════════════════════════════════
9
+
10
+ import type {
11
+ AllocationScope,
12
+ AllocationStatus,
13
+ AttachmentKind,
14
+ PoolStatus,
15
+ StorageDriverKind,
16
+ } from './enums';
17
+
18
+ /**
19
+ * A mount the worker-runtime composer will attach to a pod. The
20
+ * `driverHandle` is an opaque token whose meaning is interpreted by the
21
+ * storage driver that produced it (e.g. a PVC name for k8s, a host path
22
+ * for docker-local). Consumers MUST NOT parse it.
23
+ */
24
+ export interface AbstractMount {
25
+ /** Storage pool that backs this mount. */
26
+ readonly poolId: string;
27
+ /** Sub-path inside the pool (e.g. `org/<id>/project/<id>/session/<id>`). */
28
+ readonly subPath: string;
29
+ /** Path inside the worker container (e.g. `/workspace`, `/templates`). */
30
+ readonly mountPath: string;
31
+ /** Defaults to false (read-write). Template mounts are typically true. */
32
+ readonly readOnly?: boolean;
33
+ /** Opaque driver-defined handle; never inspected by callers. */
34
+ readonly driverHandle: string;
35
+ }
36
+
37
+ /**
38
+ * Desired-state input for `ensurePool`. The driver MUST be idempotent on
39
+ * `slug`: re-calling with the same slug returns the same pool.
40
+ */
41
+ export interface PoolSpec {
42
+ readonly slug: string;
43
+ readonly driverKind: StorageDriverKind;
44
+ /**
45
+ * Driver-specific config. The driver implementation validates its own
46
+ * shape; the kernel only guarantees it is a JSON-serializable object.
47
+ */
48
+ readonly driverConfig: Record<string, unknown>;
49
+ readonly capacityBytes: bigint;
50
+ /** Required for region-aware co-scheduling (see plan §15). */
51
+ readonly region: string;
52
+ readonly environment?: string;
53
+ /** Free-form cost class label for billing/observability dashboards. */
54
+ readonly costClass?: string;
55
+ }
56
+
57
+ /**
58
+ * Output of `ensurePool`. The pvc fields are populated for backends that
59
+ * project pools as Kubernetes PVCs; other drivers may return synthetic
60
+ * names — they remain opaque to callers.
61
+ */
62
+ export interface EnsuredPool {
63
+ readonly poolId: string;
64
+ readonly pvcName: string;
65
+ readonly pvcNamespace: string;
66
+ readonly status: PoolStatus;
67
+ }
68
+
69
+ /**
70
+ * Storage driver interface — implemented by one concrete driver per
71
+ * `StorageDriverKind`. Methods are idempotent and safe to call from
72
+ * multiple coordinator replicas (the driver is responsible for advisory
73
+ * locking around physical operations).
74
+ */
75
+ export interface StorageDriver {
76
+ readonly kind: StorageDriverKind;
77
+
78
+ /** Create or update a pool to match `spec`. Idempotent on `spec.slug`. */
79
+ ensurePool(spec: PoolSpec): Promise<EnsuredPool>;
80
+
81
+ /** Mark a pool as draining; refuse new allocations; await zero mounts. */
82
+ drainPool(poolId: string): Promise<void>;
83
+
84
+ /** Ensure a sub-path exists inside a pool. Idempotent. */
85
+ ensureSubPath(input: {
86
+ readonly poolId: string;
87
+ readonly subPath: string;
88
+ readonly scope: AllocationScope;
89
+ }): Promise<void>;
90
+
91
+ /** Remove a sub-path. Idempotent — absent path is a no-op. */
92
+ deleteSubPath(input: {
93
+ readonly poolId: string;
94
+ readonly subPath: string;
95
+ }): Promise<void>;
96
+
97
+ /**
98
+ * Build the AbstractMount that a worker-runtime composer can hand to its
99
+ * scheduler. Pure description — no side effects, no I/O.
100
+ */
101
+ describeAttachment(input: {
102
+ readonly poolId: string;
103
+ readonly subPath: string;
104
+ readonly mountPath: string;
105
+ readonly kind: AttachmentKind;
106
+ readonly readOnly?: boolean;
107
+ }): AbstractMount;
108
+ }
109
+
110
+ /**
111
+ * Cross-service DTO for a managed pool. Mirrors the Prisma row shape in
112
+ * the storage-pool service so callers (worker-runtime, allocator,
113
+ * frontend) can share one type.
114
+ */
115
+ export interface StoragePool {
116
+ readonly id: string;
117
+ readonly slug: string;
118
+ readonly driverKind: StorageDriverKind;
119
+ readonly region: string;
120
+ readonly environment?: string;
121
+ readonly capacityBytes: bigint;
122
+ readonly costClass?: string;
123
+ readonly status: PoolStatus;
124
+ readonly createdAt: string;
125
+ readonly updatedAt: string;
126
+ }
127
+
128
+ /**
129
+ * Cross-service DTO for a single allocation. `bytesUsed` is a best-effort
130
+ * snapshot — callers must not gate hard limits on this value alone.
131
+ */
132
+ export interface StorageAllocation {
133
+ readonly id: string;
134
+ readonly poolId: string;
135
+ readonly scope: AllocationScope;
136
+ readonly orgId?: string;
137
+ readonly projectId?: string;
138
+ readonly sessionId?: string;
139
+ readonly region: string;
140
+ readonly subPath: string;
141
+ readonly bytesUsed: bigint;
142
+ readonly status: AllocationStatus;
143
+ readonly lastTouchedAt: string;
144
+ readonly createdAt: string;
145
+ }