@leitwerk-dev/process-sdk 0.1.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 (199) hide show
  1. package/dist/LICENSE +13 -0
  2. package/dist/browser-ui-extension.d.ts +27 -0
  3. package/dist/browser-ui-extension.d.ts.map +1 -0
  4. package/dist/browser-ui-extension.js +2 -0
  5. package/dist/browser-ui-extension.js.map +1 -0
  6. package/dist/capabilities.d.ts +9 -0
  7. package/dist/capabilities.d.ts.map +1 -0
  8. package/dist/capabilities.js +7 -0
  9. package/dist/capabilities.js.map +1 -0
  10. package/dist/chunk-5RJZ2E7D.js +58 -0
  11. package/dist/chunk-5RJZ2E7D.js.map +1 -0
  12. package/dist/chunk-ITPH65G6.js +197 -0
  13. package/dist/chunk-ITPH65G6.js.map +1 -0
  14. package/dist/chunk-LIIP7FMU.js +48 -0
  15. package/dist/chunk-LIIP7FMU.js.map +1 -0
  16. package/dist/codecs.d.ts +3 -0
  17. package/dist/codecs.d.ts.map +1 -0
  18. package/dist/codecs.js +9 -0
  19. package/dist/codecs.js.map +1 -0
  20. package/dist/commit-message.d.ts +7 -0
  21. package/dist/commit-message.d.ts.map +1 -0
  22. package/dist/commit-message.js +3 -0
  23. package/dist/commit-message.js.map +1 -0
  24. package/dist/core-capabilities.d.ts +393 -0
  25. package/dist/core-capabilities.d.ts.map +1 -0
  26. package/dist/core-capabilities.js +6 -0
  27. package/dist/core-capabilities.js.map +1 -0
  28. package/dist/define-process.d.ts +269 -0
  29. package/dist/define-process.d.ts.map +1 -0
  30. package/dist/define-process.js +1040 -0
  31. package/dist/define-process.js.map +1 -0
  32. package/dist/event-bus.d.ts +3 -0
  33. package/dist/event-bus.d.ts.map +1 -0
  34. package/dist/event-bus.js +31 -0
  35. package/dist/event-bus.js.map +1 -0
  36. package/dist/extension-api-CnlL69Tu.d.ts +1281 -0
  37. package/dist/extension-api.d.ts +425 -0
  38. package/dist/extension-api.d.ts.map +1 -0
  39. package/dist/extension-api.js +5 -0
  40. package/dist/extension-api.js.map +1 -0
  41. package/dist/flow.d.ts +456 -0
  42. package/dist/flow.d.ts.map +1 -0
  43. package/dist/flow.js +1557 -0
  44. package/dist/flow.js.map +1 -0
  45. package/dist/form-contract.d.ts +2 -0
  46. package/dist/form-contract.d.ts.map +1 -0
  47. package/dist/form-contract.js +2 -0
  48. package/dist/form-contract.js.map +1 -0
  49. package/dist/fs-utils.d.ts +3 -0
  50. package/dist/fs-utils.d.ts.map +1 -0
  51. package/dist/fs-utils.js +23 -0
  52. package/dist/fs-utils.js.map +1 -0
  53. package/dist/git-binary.d.ts +11 -0
  54. package/dist/git-binary.d.ts.map +1 -0
  55. package/dist/git-binary.js +38 -0
  56. package/dist/git-binary.js.map +1 -0
  57. package/dist/graph-fragments.d.ts +23 -0
  58. package/dist/graph-fragments.d.ts.map +1 -0
  59. package/dist/graph-fragments.js +57 -0
  60. package/dist/graph-fragments.js.map +1 -0
  61. package/dist/host-capabilities.d.ts +12 -0
  62. package/dist/host-capabilities.d.ts.map +1 -0
  63. package/dist/host-capabilities.js +42 -0
  64. package/dist/host-capabilities.js.map +1 -0
  65. package/dist/index.d.ts +35 -0
  66. package/dist/index.d.ts.map +1 -0
  67. package/dist/index.js +29 -0
  68. package/dist/index.js.map +1 -0
  69. package/dist/launcher-contract.d.ts +2 -0
  70. package/dist/launcher-contract.d.ts.map +1 -0
  71. package/dist/launcher-contract.js +2 -0
  72. package/dist/launcher-contract.js.map +1 -0
  73. package/dist/leaf-outcome-renderer.d.ts +48 -0
  74. package/dist/leaf-outcome-renderer.d.ts.map +1 -0
  75. package/dist/leaf-outcome-renderer.js +69 -0
  76. package/dist/leaf-outcome-renderer.js.map +1 -0
  77. package/dist/leaf-outcomes.d.ts +5 -0
  78. package/dist/leaf-outcomes.d.ts.map +1 -0
  79. package/dist/leaf-outcomes.js +52 -0
  80. package/dist/leaf-outcomes.js.map +1 -0
  81. package/dist/model-provider.d.ts +210 -0
  82. package/dist/model-provider.d.ts.map +1 -0
  83. package/dist/model-provider.js +171 -0
  84. package/dist/model-provider.js.map +1 -0
  85. package/dist/pi-config.d.ts +59 -0
  86. package/dist/pi-config.d.ts.map +1 -0
  87. package/dist/pi-config.js +182 -0
  88. package/dist/pi-config.js.map +1 -0
  89. package/dist/process-definition-internals.d.ts +7 -0
  90. package/dist/process-definition-internals.d.ts.map +1 -0
  91. package/dist/process-definition-internals.js +25 -0
  92. package/dist/process-definition-internals.js.map +1 -0
  93. package/dist/process-flow-view.d.ts +20 -0
  94. package/dist/process-flow-view.d.ts.map +1 -0
  95. package/dist/process-flow-view.js +418 -0
  96. package/dist/process-flow-view.js.map +1 -0
  97. package/dist/process-graph.d.ts +45 -0
  98. package/dist/process-graph.d.ts.map +1 -0
  99. package/dist/process-graph.js +213 -0
  100. package/dist/process-graph.js.map +1 -0
  101. package/dist/process-launcher-builder.d.ts +9 -0
  102. package/dist/process-launcher-builder.d.ts.map +1 -0
  103. package/dist/process-launcher-builder.js +43 -0
  104. package/dist/process-launcher-builder.js.map +1 -0
  105. package/dist/process-watcher-builder.d.ts +10 -0
  106. package/dist/process-watcher-builder.d.ts.map +1 -0
  107. package/dist/process-watcher-builder.js +40 -0
  108. package/dist/process-watcher-builder.js.map +1 -0
  109. package/dist/registry-utils.d.ts +8 -0
  110. package/dist/registry-utils.d.ts.map +1 -0
  111. package/dist/registry-utils.js +18 -0
  112. package/dist/registry-utils.js.map +1 -0
  113. package/dist/repository-git-env.d.ts +8 -0
  114. package/dist/repository-git-env.d.ts.map +1 -0
  115. package/dist/repository-git-env.js +26 -0
  116. package/dist/repository-git-env.js.map +1 -0
  117. package/dist/review-flow.d.ts +10 -0
  118. package/dist/review-flow.d.ts.map +1 -0
  119. package/dist/review-flow.js +44 -0
  120. package/dist/review-flow.js.map +1 -0
  121. package/dist/runtime-internals.d.ts +3 -0
  122. package/dist/runtime-internals.d.ts.map +1 -0
  123. package/dist/runtime-internals.js +3 -0
  124. package/dist/runtime-internals.js.map +1 -0
  125. package/dist/server-events.d.ts +84 -0
  126. package/dist/server-events.d.ts.map +1 -0
  127. package/dist/server-events.js +2 -0
  128. package/dist/server-events.js.map +1 -0
  129. package/dist/server-process-builder.d.ts +11 -0
  130. package/dist/server-process-builder.d.ts.map +1 -0
  131. package/dist/server-process-builder.js +52 -0
  132. package/dist/server-process-builder.js.map +1 -0
  133. package/dist/state-helpers.d.ts +9 -0
  134. package/dist/state-helpers.d.ts.map +1 -0
  135. package/dist/state-helpers.js +20 -0
  136. package/dist/state-helpers.js.map +1 -0
  137. package/dist/subprocess-env.d.ts +12 -0
  138. package/dist/subprocess-env.d.ts.map +1 -0
  139. package/dist/subprocess-env.js +34 -0
  140. package/dist/subprocess-env.js.map +1 -0
  141. package/dist/tool-renderers.d.ts +10 -0
  142. package/dist/tool-renderers.d.ts.map +1 -0
  143. package/dist/tool-renderers.js +63 -0
  144. package/dist/tool-renderers.js.map +1 -0
  145. package/dist/turn-semantics.d.ts +22 -0
  146. package/dist/turn-semantics.d.ts.map +1 -0
  147. package/dist/turn-semantics.js +339 -0
  148. package/dist/turn-semantics.js.map +1 -0
  149. package/dist/types.d.ts +295 -0
  150. package/dist/types.d.ts.map +1 -0
  151. package/dist/types.js +12 -0
  152. package/dist/types.js.map +1 -0
  153. package/dist/ui-process-builder.d.ts +9 -0
  154. package/dist/ui-process-builder.d.ts.map +1 -0
  155. package/dist/ui-process-builder.js +30 -0
  156. package/dist/ui-process-builder.js.map +1 -0
  157. package/dist/worker-process-builder.d.ts +10 -0
  158. package/dist/worker-process-builder.d.ts.map +1 -0
  159. package/dist/worker-process-builder.js +22 -0
  160. package/dist/worker-process-builder.js.map +1 -0
  161. package/package.json +72 -0
  162. package/src/browser-ui-extension.ts +32 -0
  163. package/src/capabilities.ts +16 -0
  164. package/src/codecs.ts +10 -0
  165. package/src/commit-message.ts +9 -0
  166. package/src/core-capabilities.ts +526 -0
  167. package/src/define-process.ts +1879 -0
  168. package/src/event-bus.ts +35 -0
  169. package/src/extension-api.ts +600 -0
  170. package/src/flow.ts +2268 -0
  171. package/src/form-contract.ts +11 -0
  172. package/src/fs-utils.ts +28 -0
  173. package/src/git-binary.ts +40 -0
  174. package/src/graph-fragments.ts +110 -0
  175. package/src/host-capabilities.ts +60 -0
  176. package/src/index.ts +468 -0
  177. package/src/launcher-contract.ts +8 -0
  178. package/src/leaf-outcome-renderer.ts +112 -0
  179. package/src/leaf-outcomes.ts +74 -0
  180. package/src/model-provider.ts +461 -0
  181. package/src/pi-config.ts +268 -0
  182. package/src/process-definition-internals.ts +46 -0
  183. package/src/process-flow-view.ts +479 -0
  184. package/src/process-graph.ts +309 -0
  185. package/src/process-launcher-builder.ts +59 -0
  186. package/src/process-watcher-builder.ts +72 -0
  187. package/src/registry-utils.ts +31 -0
  188. package/src/repository-git-env.ts +35 -0
  189. package/src/review-flow.ts +66 -0
  190. package/src/runtime-internals.ts +7 -0
  191. package/src/server-events.ts +105 -0
  192. package/src/server-process-builder.ts +90 -0
  193. package/src/state-helpers.ts +36 -0
  194. package/src/subprocess-env.ts +48 -0
  195. package/src/tool-renderers.ts +92 -0
  196. package/src/turn-semantics.ts +554 -0
  197. package/src/types.ts +391 -0
  198. package/src/ui-process-builder.ts +46 -0
  199. package/src/worker-process-builder.ts +33 -0
@@ -0,0 +1,35 @@
1
+ import type { EventBus } from "./types.js";
2
+
3
+ export function createEventBus<
4
+ TEventMap extends object = Record<string, unknown>,
5
+ >(): EventBus<TEventMap> {
6
+ const listeners = new Map<string, Set<(data: unknown) => void | Promise<void>>>();
7
+
8
+ return {
9
+ emit(event, data) {
10
+ const handlers = listeners.get(event);
11
+ if (!handlers) return;
12
+ for (const handler of handlers) {
13
+ try {
14
+ void handler(data);
15
+ } catch {
16
+ // swallow handler errors to avoid breaking the emit loop
17
+ }
18
+ }
19
+ },
20
+
21
+ on(event, handler) {
22
+ const typedHandler = handler as unknown as (data: unknown) => void | Promise<void>;
23
+ let set = listeners.get(event);
24
+ if (!set) {
25
+ set = new Set();
26
+ listeners.set(event, set);
27
+ }
28
+ set.add(typedHandler);
29
+ },
30
+
31
+ off(event, handler) {
32
+ listeners.get(event)?.delete(handler as unknown as (data: unknown) => void | Promise<void>);
33
+ },
34
+ };
35
+ }
@@ -0,0 +1,600 @@
1
+ import type {
2
+ InputKind,
3
+ InputSource,
4
+ ProcessCustomizableFields,
5
+ ProcessInputTarget,
6
+ ProcessInstance,
7
+ ProcessLifecycleStatus,
8
+ ProcessProject,
9
+ ProcessSemanticEntryRefKey,
10
+ ProcessTurnRecord,
11
+ TurnId,
12
+ } from "@leitwerk-dev/domain";
13
+ import type { ProcessWatcherType } from "@leitwerk-dev/protocol";
14
+ import type { CapabilityToken } from "./capabilities.js";
15
+ import type { FormDefinition } from "./form-contract.js";
16
+
17
+ export type { FormDefinition, FormFieldDefinition } from "./form-contract.js";
18
+
19
+ import type {
20
+ LlmTurnDefinition,
21
+ ProcessEffectPlan,
22
+ ProcessLifecycleEffects,
23
+ TurnDefinition,
24
+ } from "./define-process.js";
25
+ import type {
26
+ LauncherCardMetadata,
27
+ LauncherFieldOptionDefinition,
28
+ LauncherSchemaDefinition,
29
+ LauncherValidationError,
30
+ UiLauncherSummaryBase,
31
+ } from "./launcher-contract.js";
32
+ import type { ModelProviderSet } from "./model-provider.js";
33
+ import type {
34
+ ServerExtensionEventMap,
35
+ ServerExtensionEventPayloadInputMap,
36
+ } from "./server-events.js";
37
+ import type { ToolCallRendererDefinition } from "./tool-renderers.js";
38
+ import type {
39
+ EventBus,
40
+ PiTreeEntry,
41
+ ProcessActionPreviewDefinition,
42
+ ProcessActionSchedulingDefinition,
43
+ ProcessPiConfig,
44
+ TurnOptions,
45
+ } from "./types.js";
46
+
47
+ export interface Codec<T> {
48
+ parse(value: unknown): T;
49
+ serialize(value: T): unknown;
50
+ }
51
+
52
+ export interface LauncherModelProfileSummary {
53
+ readonly id: string;
54
+ readonly provider: string;
55
+ readonly modelId: string;
56
+ readonly thinkingLevel: string;
57
+ }
58
+
59
+ export interface LauncherContext {
60
+ readonly process?: ProcessInstance;
61
+ readonly projects?: readonly ProcessProject[];
62
+ /**
63
+ * Effective model profiles available to this launch path.
64
+ * The server may filter this list per process (for example via process allowlists)
65
+ * before invoking UI launcher or process watcher code.
66
+ */
67
+ readonly modelProfiles?: readonly LauncherModelProfileSummary[];
68
+ }
69
+
70
+ export type LauncherVisibility = "ui";
71
+
72
+ export interface ProcessLaunchProjectConfig {
73
+ key: string;
74
+ repoLocator: string;
75
+ baseBranch: string;
76
+ workBranch?: string | null;
77
+ externalId?: string | null;
78
+ externalUrl?: string | null;
79
+ metadata?: Record<string, unknown> | null;
80
+ }
81
+
82
+ export interface ProcessTitleSourceField {
83
+ /** Short label shown to the title-generation model, e.g. "Prompt" or "Summary". */
84
+ label: string;
85
+ /** Launcher-selected descriptive text to summarize into a short operator-facing title. */
86
+ value: string;
87
+ }
88
+
89
+ export interface ProcessLaunchConfig<TParams = unknown> {
90
+ processId: string;
91
+ params: TParams;
92
+ startTurnId?: TurnId | null;
93
+ /** Explicit operator-facing title. UI launches may override this with the built-in title input before persistence. */
94
+ title?: string | null;
95
+ /** Explicit launcher-selected fields for optional server-side title generation when title is blank. */
96
+ titleSourceFields?: readonly ProcessTitleSourceField[];
97
+ externalId?: string | null;
98
+ externalUrl?: string | null;
99
+ metadata?: Record<string, unknown> | null;
100
+ defaultModelProfileId?: string | null;
101
+ turnConfigs?: Record<string, { modelProfileId?: string | null }>;
102
+ projects?: readonly ProcessLaunchProjectConfig[];
103
+ }
104
+
105
+ export type UiLauncherConfigResolution<TParams = unknown> =
106
+ | {
107
+ ok: true;
108
+ launchConfig: ProcessLaunchConfig<TParams>;
109
+ }
110
+ | {
111
+ ok: false;
112
+ errors: readonly LauncherValidationError[];
113
+ };
114
+
115
+ export interface UiLauncherDefinition<TParams = unknown> {
116
+ card: LauncherCardMetadata;
117
+ launchConfigSchema: LauncherSchemaDefinition;
118
+ resolveDefaults?(
119
+ ctx: LauncherContext,
120
+ ): Record<string, unknown> | Promise<Record<string, unknown>>;
121
+ resolveOptions?(
122
+ input: Record<string, unknown>,
123
+ ctx: LauncherContext,
124
+ ):
125
+ | Record<string, readonly LauncherFieldOptionDefinition[]>
126
+ | Promise<Record<string, readonly LauncherFieldOptionDefinition[]>>;
127
+ /**
128
+ * Convert persisted operator input into a new-launch draft. The default preserves
129
+ * the complete input. Launchers override this only for values that must be rebuilt.
130
+ */
131
+ resolveRelaunchInput?(
132
+ previousInput: Record<string, unknown>,
133
+ ctx: LauncherContext,
134
+ ): Record<string, unknown> | Promise<Record<string, unknown>>;
135
+ resolveLaunchConfig(
136
+ input: Record<string, unknown>,
137
+ ctx: LauncherContext,
138
+ ): UiLauncherConfigResolution<TParams> | Promise<UiLauncherConfigResolution<TParams>>;
139
+ }
140
+
141
+ export interface ProcessWatcherDefinition<
142
+ TParams = unknown,
143
+ TEvent = unknown,
144
+ TType extends ProcessWatcherType = ProcessWatcherType,
145
+ > {
146
+ id: string;
147
+ label: string;
148
+ description: string;
149
+ type: TType;
150
+ matches?(event: TEvent, ctx: LauncherContext): boolean | Promise<boolean>;
151
+ resolveLaunchConfig(
152
+ event: TEvent,
153
+ ctx: LauncherContext,
154
+ ): ProcessLaunchConfig<TParams> | Promise<ProcessLaunchConfig<TParams>>;
155
+ }
156
+
157
+ export interface ProcessLauncherDefinition<TParams = unknown> {
158
+ id: string;
159
+ label: string;
160
+ description: string;
161
+ visibility: LauncherVisibility;
162
+ ui: UiLauncherDefinition<TParams>;
163
+ }
164
+
165
+ export interface ProcessLaunchPlanProcessInput extends ProcessCustomizableFields {
166
+ processId: string;
167
+ selectedTurnId: string | null;
168
+ lifecycleStatus: ProcessLifecycleStatus;
169
+ paramsJson: string | null;
170
+ stateJson: string | null;
171
+ }
172
+
173
+ export interface ProcessLaunchPlan {
174
+ launcherId: string;
175
+ processId: string;
176
+ processInput: ProcessLaunchPlanProcessInput;
177
+ /** Optional server-owned idempotency key for cross-process handoffs. */
178
+ handoffDedupKey?: string | null;
179
+ /** Carry-forward launcher-selected fields for optional server-side title generation. */
180
+ titleSourceFields?: readonly ProcessTitleSourceField[];
181
+ projectInputs: readonly ProcessLaunchProjectConfig[];
182
+ startTurnId: TurnId | null;
183
+ }
184
+
185
+ export interface ResolvedProcessLauncher<TParams = unknown> {
186
+ launcherId: string;
187
+ processId: string;
188
+ displayName: string;
189
+ launchConfig: ProcessLaunchConfig<TParams>;
190
+ launchPlan: ProcessLaunchPlan;
191
+ }
192
+
193
+ export type UiLauncherResolutionResult<TParams = unknown> =
194
+ | {
195
+ ok: true;
196
+ launcher: ResolvedProcessLauncher<TParams>;
197
+ }
198
+ | {
199
+ ok: false;
200
+ errors: readonly LauncherValidationError[];
201
+ };
202
+
203
+ export interface UiLauncherSummary extends UiLauncherSummaryBase {}
204
+
205
+ export interface ProcessLauncherService {
206
+ listUiLaunchers(): readonly UiLauncherSummary[];
207
+ resolveUiDefaults(launcherId: string, ctx?: LauncherContext): Promise<Record<string, unknown>>;
208
+ resolveUiOptions(
209
+ launcherId: string,
210
+ input: Record<string, unknown>,
211
+ ctx?: LauncherContext,
212
+ ): Promise<Record<string, readonly LauncherFieldOptionDefinition[]>>;
213
+ resolveUiRelaunchInput(
214
+ launcherId: string,
215
+ previousInput: Record<string, unknown>,
216
+ ctx?: LauncherContext,
217
+ ): Promise<Record<string, unknown>>;
218
+ resolveUiLauncher(
219
+ launcherId: string,
220
+ input: Record<string, unknown>,
221
+ ctx?: LauncherContext,
222
+ ): Promise<UiLauncherResolutionResult>;
223
+ }
224
+
225
+ /** Resolve a UI launcher summary by id, returning `null` when it is unknown. */
226
+ export function findUiLauncherById(
227
+ launcherService: Pick<ProcessLauncherService, "listUiLaunchers">,
228
+ launcherId: string,
229
+ ): UiLauncherSummary | null {
230
+ return launcherService.listUiLaunchers().find((launcher) => launcher.id === launcherId) ?? null;
231
+ }
232
+
233
+ export interface ProcessTurnOutcomeEvent {
234
+ turnRecordId: string;
235
+ turnId: string;
236
+ outcome: string;
237
+ params: Record<string, unknown>;
238
+ turnResultMarkdown?: string | null;
239
+ }
240
+
241
+ export type ProcessCleanupReason = "abort";
242
+
243
+ export interface ProcessCleanupResult<TState = unknown> extends ProcessLifecycleEffects {
244
+ state?: TState;
245
+ }
246
+
247
+ export interface ProcessCleanupContext<TParams = unknown, TState = unknown>
248
+ extends ProcessSnapshotContext<TParams, TState> {
249
+ readonly reason: ProcessCleanupReason;
250
+ }
251
+
252
+ export type ProcessCleanupHandler<TParams = unknown, TState = unknown> = (
253
+ ctx: ProcessCleanupContext<TParams, TState>,
254
+ ) => undefined | ProcessCleanupResult<TState> | Promise<ProcessCleanupResult<TState> | undefined>;
255
+
256
+ export interface LeafOutcomeCaptureContext<TParams = unknown, TState = unknown>
257
+ extends ProcessSnapshotContext<TParams, TState> {
258
+ readonly leaf: {
259
+ entryId: string;
260
+ turnRecordId: string | null;
261
+ };
262
+ readonly turnRecord: ProcessTurnRecord | null;
263
+ readTreeEntry(entryId: string): PiTreeEntry | null;
264
+ readLeafEntry(): PiTreeEntry | null;
265
+ readTurnRecord(turnRecordId: string): ProcessTurnRecord | null;
266
+ }
267
+
268
+ export interface LeafOutcomeCaptureResult {
269
+ rendererId: string;
270
+ schemaVersion?: number;
271
+ props: Record<string, unknown>;
272
+ fallbackMarkdown?: string | null;
273
+ }
274
+
275
+ export interface ProcessLeafOutcomeDefinition<TParams = unknown, TState = unknown> {
276
+ rendererId: string;
277
+ capture(
278
+ ctx: LeafOutcomeCaptureContext<TParams, TState>,
279
+ ): Promise<LeafOutcomeCaptureResult | null> | LeafOutcomeCaptureResult | null;
280
+ }
281
+
282
+ export interface ProcessActionDefinition<TParams = unknown, TState = unknown> {
283
+ id: string;
284
+ label: string;
285
+ form?: FormDefinition;
286
+ preview?: ProcessActionPreviewDefinition;
287
+ scheduling?: ProcessActionSchedulingDefinition;
288
+ /**
289
+ * Explicitly marks an action as an immediate-only side-effect command. Such
290
+ * actions must declare execute(...), cannot participate in pure preview or
291
+ * scheduling flows, and are run only by immediate action execution.
292
+ */
293
+ executionMode?: "side_effect";
294
+ /**
295
+ * Optional pure planner used for side-effect-free previews, scheduling validation,
296
+ * and immediate execution. The shared server runtime collects the declared
297
+ * transition/input/event plan from this hook without committing side effects
298
+ * while the hook runs.
299
+ */
300
+ plan?(input: Record<string, unknown>, ctx: ServerProcessContext<TParams, TState>): Promise<void>;
301
+ /**
302
+ * Imperative hook for actions with executionMode: "side_effect". Use only for
303
+ * immediate side effects that cannot be represented as a pure plan(...).
304
+ */
305
+ execute?(
306
+ input: Record<string, unknown>,
307
+ ctx: ServerProcessContext<TParams, TState>,
308
+ ): Promise<void>;
309
+ }
310
+
311
+ export type ServerTransitionRuntime = "reconcile" | "restart_worker";
312
+
313
+ export interface ServerTransitionEffect {
314
+ /**
315
+ * Declares how the server runtime should handle the worker context after the
316
+ * durable transition is committed.
317
+ */
318
+ runtime?: ServerTransitionRuntime;
319
+ }
320
+
321
+ export interface ServerTransitionRequest<TState = unknown> {
322
+ lifecycleStatus?: ProcessLifecycleStatus;
323
+ turnId?: TurnId | null;
324
+ state?: TState;
325
+ /** State machine trigger for the selected-turn graph. */
326
+ trigger?: string;
327
+ effect?: ServerTransitionEffect;
328
+ }
329
+
330
+ export interface ProcessSnapshotContext<TParams = unknown, TState = unknown> {
331
+ readonly process: ProcessInstance;
332
+ readonly projects: readonly ProcessProject[];
333
+ readonly params: TParams;
334
+ readonly state: TState;
335
+ }
336
+
337
+ export type ExternalSourceInputMode = "none" | "input" | "instruction";
338
+
339
+ export interface ExternalSourceResolveContext<TParams = unknown, TState = unknown>
340
+ extends ProcessSnapshotContext<TParams, TState> {}
341
+
342
+ export interface ExternalSourceEffectContext<
343
+ TParams = unknown,
344
+ TState = unknown,
345
+ TEvent = unknown,
346
+ TInput extends Record<string, unknown> = Record<string, unknown>,
347
+ > extends ProcessSnapshotContext<TParams, TState> {
348
+ readonly event: TEvent;
349
+ readonly input: TInput;
350
+ }
351
+
352
+ export type ExternalSourceEffect<
353
+ TParams = unknown,
354
+ TState = unknown,
355
+ TEvent = unknown,
356
+ TInput extends Record<string, unknown> = Record<string, unknown>,
357
+ > = (
358
+ ctx: ExternalSourceEffectContext<TParams, TState, TEvent, TInput>,
359
+ ) => ProcessEffectPlan<TState> | Promise<ProcessEffectPlan<TState> | undefined> | undefined;
360
+
361
+ export interface ExternalActionSource<
362
+ TParams = unknown,
363
+ TState = unknown,
364
+ _TEvent = unknown,
365
+ _TInput extends Record<string, unknown> = Record<string, unknown>,
366
+ > {
367
+ kind: string;
368
+ label?: string;
369
+ description?: string;
370
+ /**
371
+ * Extension-owned opaque config. Core may persist, hash, and display it, but must not
372
+ * interpret provider-specific fields.
373
+ */
374
+ config: unknown;
375
+ /** Source-provided input behavior. Provider input is only published when the external action declares publishInput. */
376
+ inputMode?: ExternalSourceInputMode;
377
+ /** Optional extension-owned resolver for process-instance-specific matching. */
378
+ resolve?(ctx: ExternalSourceResolveContext<TParams, TState>): unknown;
379
+ }
380
+
381
+ export interface ServerProcessContext<TParams = unknown, TState = unknown>
382
+ extends ProcessSnapshotContext<TParams, TState> {
383
+ transition(next: ServerTransitionRequest<TState>): Promise<void>;
384
+ emitEvent<K extends keyof ServerExtensionEventMap & string>(
385
+ eventType: K,
386
+ data: ServerExtensionEventPayloadInputMap[K],
387
+ ): void;
388
+ /**
389
+ * Resolves non-empty turn-result markdown for the current semantic ref.
390
+ * Returns `null` when the ref is unset or the referenced turn result does not
391
+ * carry operator-facing markdown. Throws when persisted semantic-ref state is
392
+ * malformed.
393
+ */
394
+ readSemanticTurnResultMarkdown(ref: ProcessSemanticEntryRefKey): string | null;
395
+ /**
396
+ * Resolves non-empty turn-result markdown for a process-defined published product.
397
+ * Returns `null` when the product ref is unset or the referenced turn result does
398
+ * not carry operator-facing markdown. Throws when persisted product-ref state is
399
+ * malformed.
400
+ */
401
+ readProductTurnResultMarkdown(productName: string): string | null;
402
+ /**
403
+ * Queue durable process input for worker delivery.
404
+ * Use `source: "action_prompt"` for action-originated follow-up prompts.
405
+ * When `target` is set, the worker appends the input on the referenced
406
+ * semantic or product branch before the next selected LLM turn continues from
407
+ * that same branch. For `action_prompt` targeted follow-up reruns, that queued
408
+ * input is the only new instruction: the worker does not replay the original
409
+ * kickoff prompt.
410
+ */
411
+ queueInput(input: {
412
+ source: InputSource;
413
+ kind: InputKind;
414
+ bodyMarkdown: string;
415
+ target?: ProcessInputTarget;
416
+ }): void;
417
+ /**
418
+ * Internal SDK lifecycle-effect collector used by high-level process authoring
419
+ * helpers. Raw process definitions should prefer intent helpers instead of
420
+ * constructing these effects directly.
421
+ */
422
+ applyLifecycleEffects?(effects: ProcessLifecycleEffects): void;
423
+ }
424
+
425
+ export interface WorkerProcessContext<TParams = unknown, TState = unknown>
426
+ extends ProcessSnapshotContext<TParams, TState> {
427
+ readonly turnResultMarkdownBySemanticRef?: Partial<Record<ProcessSemanticEntryRefKey, string>>;
428
+ readonly turnResultMarkdownByProduct?: Readonly<Record<string, string>>;
429
+ /** Absolute workspace root for the current process instance, when available. */
430
+ readonly workspaceRoot?: string;
431
+ }
432
+
433
+ export interface WorkerCompleteInput<TOutcome extends string = string> {
434
+ outcome: TOutcome;
435
+ params?: Record<string, unknown>;
436
+ markdown?: string | null;
437
+ }
438
+
439
+ export interface WorkerRunHandle<TParams = unknown, TState = unknown> {
440
+ readonly ctx: WorkerProcessContext<TParams, TState>;
441
+ turn<TOutcome extends string>(
442
+ def: LlmTurnDefinition<TOutcome, TParams, TState>,
443
+ options?: TurnOptions,
444
+ ): Promise<{ outcome: TOutcome; params: Record<string, unknown> }>;
445
+ complete<TOutcome extends string>(input: WorkerCompleteInput<TOutcome>): Promise<void>;
446
+ park(reason?: string): void;
447
+ }
448
+
449
+ export type WorkerTurnHandler<TParams = unknown, TState = unknown> = (
450
+ run: WorkerRunHandle<TParams, TState>,
451
+ ) => Promise<void>;
452
+
453
+ export interface ServerProcessAPI<TParams = unknown, TState = unknown> {
454
+ action(def: ProcessActionDefinition<TParams, TState>): void;
455
+ onTurnOutcome(
456
+ turnId: string,
457
+ handler: (
458
+ event: ProcessTurnOutcomeEvent,
459
+ ctx: ServerProcessContext<TParams, TState>,
460
+ ) => void | Promise<void>,
461
+ ): void;
462
+ onCleanup(handler: ProcessCleanupHandler<TParams, TState>): void;
463
+ }
464
+
465
+ export interface WorkerProcessAPI<TParams = unknown, TState = unknown> {
466
+ start(turnId: TurnId): void;
467
+ turn(turnId: TurnId, handler: WorkerTurnHandler<TParams, TState>): void;
468
+ }
469
+
470
+ export interface UiProcessAPI<TParams = unknown, TState = unknown> {
471
+ leafOutcome(def: ProcessLeafOutcomeDefinition<TParams, TState>): void;
472
+ }
473
+
474
+ export interface ProcessLauncherAPI<TParams = unknown> {
475
+ launcher(def: ProcessLauncherDefinition<TParams>): void;
476
+ }
477
+
478
+ export interface ProcessWatcherAPI<TParams = unknown> {
479
+ watcher<TEvent = unknown, TType extends ProcessWatcherType = ProcessWatcherType>(
480
+ def: ProcessWatcherDefinition<TParams, TEvent, TType>,
481
+ ): void;
482
+ }
483
+
484
+ export interface ProcessTurnBinding<TTurn = TurnDefinition> {
485
+ definition: TTurn;
486
+ }
487
+
488
+ export type RepositoryCredentialKind = "git_ssh";
489
+
490
+ /** Non-secret, code-defined repository authentication request. */
491
+ export interface RepositoryCredentialRequirement {
492
+ readonly projectKey: string;
493
+ readonly kind: RepositoryCredentialKind;
494
+ readonly credentialRef: string;
495
+ }
496
+
497
+ /** Project fields available while deriving repository credential requirements. */
498
+ export interface RepositoryCredentialProject {
499
+ readonly key: string;
500
+ readonly repoLocator: string;
501
+ readonly baseBranch: string;
502
+ readonly workBranch: string | null;
503
+ }
504
+
505
+ /** Secret material is intentionally restricted to server registration and worker.start. */
506
+ export interface GitSshCredentialMaterial {
507
+ readonly privateKey: string;
508
+ readonly knownHosts: string;
509
+ }
510
+
511
+ export interface RepositoryCredentialProvider {
512
+ readonly kind: RepositoryCredentialKind;
513
+ resolve(credentialRef: string): GitSshCredentialMaterial | null;
514
+ }
515
+
516
+ export interface RepositoryCredentialRegistrar {
517
+ register(provider: RepositoryCredentialProvider): void;
518
+ }
519
+
520
+ export interface ExtensionProcessDefinition<TParams = unknown, TState = unknown> {
521
+ id: string;
522
+ displayName: string;
523
+ /** Primary entry used when a launch does not select a start turn explicitly. */
524
+ entryTurnId: TurnId;
525
+ /** Additional entry turns that launchers may select explicitly. */
526
+ alternateEntryTurnIds?: readonly TurnId[];
527
+ /**
528
+ * Optional author-declared happy path: the ordered spine of turns a successful
529
+ * run walks through. Flow diagrams render this as the main line and hang every
530
+ * other turn off it as a branch. When omitted, consumers fall back to a derived
531
+ * best-effort spine.
532
+ */
533
+ happyPath?: readonly TurnId[];
534
+ turns: ReadonlyMap<TurnId, ProcessTurnBinding<TurnDefinition<TParams, TState>>>;
535
+ paramsCodec: Codec<TParams>;
536
+ stateCodec: Codec<TState>;
537
+ initialState(params: TParams): TState;
538
+ /** Runtime-only requirements; references are non-secret and remain in opaque params JSON. */
539
+ repositoryCredentials?(input: {
540
+ params: TParams;
541
+ projects: readonly RepositoryCredentialProject[];
542
+ }): readonly RepositoryCredentialRequirement[];
543
+ piConfig?: ProcessPiConfig;
544
+ server?: (api: ServerProcessAPI<TParams, TState>) => void;
545
+ worker?: (api: WorkerProcessAPI<TParams, TState>) => void;
546
+ ui?: (api: UiProcessAPI<TParams, TState>) => void;
547
+ launchers?: (api: ProcessLauncherAPI<TParams>) => void;
548
+ watchers?: (api: ProcessWatcherAPI<TParams>) => void;
549
+ }
550
+
551
+ export interface CatalogExtensionAPI {
552
+ readonly events: EventBus;
553
+ registerProcess<TParams = unknown, TState = unknown>(
554
+ def: ExtensionProcessDefinition<TParams, TState>,
555
+ ): void;
556
+ registerToolRenderer(def: ToolCallRendererDefinition): void;
557
+ provide<T>(token: CapabilityToken<T>, value: T): void;
558
+ get<T>(token: CapabilityToken<T>): T | T[] | undefined;
559
+ require<T>(token: CapabilityToken<T>): T | T[];
560
+ }
561
+
562
+ export type ExtensionLifecycleHook = () => void | Promise<void>;
563
+
564
+ export interface ServerExtensionLogger {
565
+ info?(payload: Record<string, unknown>, message?: string): void;
566
+ warn?(payload: Record<string, unknown>, message?: string): void;
567
+ error?(payload: Record<string, unknown>, message?: string): void;
568
+ }
569
+
570
+ export interface ServerExtensionAPI {
571
+ readonly events: EventBus<ServerExtensionEventMap>;
572
+ readonly logger?: ServerExtensionLogger;
573
+ provide<T>(token: CapabilityToken<T>, value: T): void;
574
+ get<T>(token: CapabilityToken<T>): T | T[] | undefined;
575
+ require<T>(token: CapabilityToken<T>): T | T[];
576
+ onStart(handler: ExtensionLifecycleHook): void;
577
+ onStop(handler: ExtensionLifecycleHook): void;
578
+ }
579
+
580
+ export interface WorkerExtensionAPI {
581
+ readonly events: EventBus;
582
+ get<T>(token: CapabilityToken<T>): T | T[] | undefined;
583
+ require<T>(token: CapabilityToken<T>): T | T[];
584
+ }
585
+
586
+ export interface LeitwerkExtensionManifest {
587
+ id: string;
588
+ version: string;
589
+ requires?: readonly string[];
590
+ optional?: readonly string[];
591
+ }
592
+
593
+ export interface LeitwerkExtensionModule {
594
+ manifest: LeitwerkExtensionManifest;
595
+ /** Resolves every provider owned by this extension before setupServer. */
596
+ modelProviders?: ModelProviderSet;
597
+ setupCatalog?(api: CatalogExtensionAPI): void | Promise<void>;
598
+ setupServer?(api: ServerExtensionAPI, config: unknown): void | Promise<void>;
599
+ setupWorker?(api: WorkerExtensionAPI, config: unknown): void | Promise<void>;
600
+ }