@leitwerk-dev/process-sdk 0.1.9 → 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 (256) hide show
  1. package/dist/browser-ui-extension.d.ts +20 -0
  2. package/dist/browser-ui-extension.d.ts.map +1 -1
  3. package/dist/capabilities.d.ts +6 -0
  4. package/dist/capabilities.d.ts.map +1 -1
  5. package/dist/{chunk-LIIP7FMU.js → chunk-5R6MVLHC.js} +1 -1
  6. package/dist/chunk-5R6MVLHC.js.map +1 -0
  7. package/dist/chunk-DVXW2ZUV.js +1 -0
  8. package/dist/chunk-DVXW2ZUV.js.map +1 -0
  9. package/dist/{chunk-TRQJ5PRM.js → chunk-I7U6HCLN.js} +1 -11
  10. package/dist/chunk-I7U6HCLN.js.map +1 -0
  11. package/dist/{chunk-5RJZ2E7D.js → chunk-TM2LTSW4.js} +2 -6
  12. package/dist/chunk-TM2LTSW4.js.map +1 -0
  13. package/dist/codecs.d.ts +1 -0
  14. package/dist/codecs.d.ts.map +1 -1
  15. package/dist/commit-message.d.ts +5 -0
  16. package/dist/commit-message.d.ts.map +1 -1
  17. package/dist/core-capabilities.d.ts +396 -44
  18. package/dist/core-capabilities.d.ts.map +1 -1
  19. package/dist/define-process.d.ts +209 -64
  20. package/dist/define-process.d.ts.map +1 -1
  21. package/dist/event-bus.d.ts +1 -0
  22. package/dist/event-bus.d.ts.map +1 -1
  23. package/dist/{extension-api-BBcwktmc.d.ts → extension-api-B4gG5w1K.d.ts} +1111 -153
  24. package/dist/extension-api.d.ts +481 -38
  25. package/dist/extension-api.d.ts.map +1 -1
  26. package/dist/external-action-source.d.ts +9 -0
  27. package/dist/external-action-source.d.ts.map +1 -0
  28. package/dist/external-source-poll.d.ts +22 -0
  29. package/dist/external-source-poll.d.ts.map +1 -0
  30. package/dist/flow.d.ts +380 -107
  31. package/dist/flow.d.ts.map +1 -1
  32. package/dist/form-contract.d.ts +1 -1
  33. package/dist/form-contract.d.ts.map +1 -1
  34. package/dist/fs-utils.d.ts +6 -0
  35. package/dist/fs-utils.d.ts.map +1 -1
  36. package/dist/git-binary.d.ts +2 -1
  37. package/dist/git-binary.d.ts.map +1 -1
  38. package/dist/git-binary.js +25 -33
  39. package/dist/git-binary.js.map +1 -1
  40. package/dist/graph-fragments.d.ts +16 -0
  41. package/dist/graph-fragments.d.ts.map +1 -1
  42. package/dist/host-capabilities.d.ts +9 -3
  43. package/dist/host-capabilities.d.ts.map +1 -1
  44. package/dist/index.d.ts +40 -29
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.js +4876 -29
  47. package/dist/index.js.map +1 -1
  48. package/dist/integration-http.d.ts +32 -0
  49. package/dist/integration-http.d.ts.map +1 -0
  50. package/dist/json-data.d.ts +3 -0
  51. package/dist/json-data.d.ts.map +1 -0
  52. package/dist/leaf-outcome-renderer.d.ts +35 -0
  53. package/dist/leaf-outcome-renderer.d.ts.map +1 -1
  54. package/dist/leaf-outcome-renderer.js +86 -64
  55. package/dist/leaf-outcome-renderer.js.map +1 -1
  56. package/dist/leaf-outcomes.d.ts +3 -0
  57. package/dist/leaf-outcomes.d.ts.map +1 -1
  58. package/dist/model-provider.d.ts +144 -12
  59. package/dist/model-provider.d.ts.map +1 -1
  60. package/dist/pi-config-public.d.ts +2 -0
  61. package/dist/pi-config-public.d.ts.map +1 -0
  62. package/dist/pi-config-public.js +15 -0
  63. package/dist/pi-config-public.js.map +1 -0
  64. package/dist/pi-config.d.ts +41 -5
  65. package/dist/pi-config.d.ts.map +1 -1
  66. package/dist/pi-config.js +20 -180
  67. package/dist/pi-config.js.map +1 -1
  68. package/dist/process-definition-internals.d.ts +4 -0
  69. package/dist/process-definition-internals.d.ts.map +1 -1
  70. package/dist/process-flow-view.d.ts +2 -0
  71. package/dist/process-flow-view.d.ts.map +1 -1
  72. package/dist/process-graph.d.ts +34 -0
  73. package/dist/process-graph.d.ts.map +1 -1
  74. package/dist/process-launcher-builder.d.ts +5 -0
  75. package/dist/process-launcher-builder.d.ts.map +1 -1
  76. package/dist/process-watcher-builder.d.ts +5 -0
  77. package/dist/process-watcher-builder.d.ts.map +1 -1
  78. package/dist/process-watcher-source.d.ts +3 -1
  79. package/dist/process-watcher-source.d.ts.map +1 -1
  80. package/dist/project-binding.d.ts +13 -0
  81. package/dist/project-binding.d.ts.map +1 -0
  82. package/dist/registry-utils.d.ts +6 -0
  83. package/dist/registry-utils.d.ts.map +1 -1
  84. package/dist/repository-feedback.d.ts +47 -0
  85. package/dist/repository-feedback.d.ts.map +1 -0
  86. package/dist/repository-git-env.d.ts +8 -2
  87. package/dist/repository-git-env.d.ts.map +1 -1
  88. package/dist/repository-http.d.ts +31 -0
  89. package/dist/repository-http.d.ts.map +1 -0
  90. package/dist/repository-https.d.ts +3 -0
  91. package/dist/repository-https.d.ts.map +1 -0
  92. package/dist/repository-issue-watcher.d.ts +51 -0
  93. package/dist/repository-issue-watcher.d.ts.map +1 -0
  94. package/dist/repository-reconciliation.d.ts +5 -0
  95. package/dist/repository-reconciliation.d.ts.map +1 -0
  96. package/dist/repository-source-config.d.ts +58 -0
  97. package/dist/repository-source-config.d.ts.map +1 -0
  98. package/dist/repository-types.d.ts +63 -0
  99. package/dist/repository-types.d.ts.map +1 -0
  100. package/dist/review-flow-public.d.ts +2 -0
  101. package/dist/review-flow-public.d.ts.map +1 -0
  102. package/dist/review-flow-public.js +11 -0
  103. package/dist/review-flow-public.js.map +1 -0
  104. package/dist/review-flow.d.ts +6 -0
  105. package/dist/review-flow.d.ts.map +1 -1
  106. package/dist/review-flow.js +12 -43
  107. package/dist/review-flow.js.map +1 -1
  108. package/dist/runtime-internals-public.d.ts +2 -0
  109. package/dist/runtime-internals-public.d.ts.map +1 -0
  110. package/dist/runtime-internals-public.js +16 -0
  111. package/dist/runtime-internals-public.js.map +1 -0
  112. package/dist/runtime-internals.js +19 -2
  113. package/dist/runtime-internals.js.map +1 -1
  114. package/dist/server-events.d.ts +67 -0
  115. package/dist/server-events.d.ts.map +1 -1
  116. package/dist/server-process-builder.d.ts +7 -0
  117. package/dist/server-process-builder.d.ts.map +1 -1
  118. package/dist/state-helpers.d.ts +8 -0
  119. package/dist/state-helpers.d.ts.map +1 -1
  120. package/dist/subprocess-env.d.ts +4 -0
  121. package/dist/subprocess-env.d.ts.map +1 -1
  122. package/dist/tool-arguments.d.ts +9 -0
  123. package/dist/tool-arguments.d.ts.map +1 -0
  124. package/dist/tool-renderers.d.ts +6 -0
  125. package/dist/tool-renderers.d.ts.map +1 -1
  126. package/dist/turn-semantics.d.ts +18 -6
  127. package/dist/turn-semantics.d.ts.map +1 -1
  128. package/dist/types.d.ts +209 -38
  129. package/dist/types.d.ts.map +1 -1
  130. package/dist/ui-process-builder.d.ts +5 -0
  131. package/dist/ui-process-builder.d.ts.map +1 -1
  132. package/dist/worker-process-builder.d.ts +5 -0
  133. package/dist/worker-process-builder.d.ts.map +1 -1
  134. package/package.json +17 -15
  135. package/src/browser-ui-extension.ts +20 -0
  136. package/src/capabilities.ts +9 -1
  137. package/src/codecs.ts +1 -0
  138. package/src/commit-message.ts +5 -0
  139. package/src/core-capabilities.ts +464 -59
  140. package/src/define-process.ts +384 -332
  141. package/src/event-bus.ts +1 -0
  142. package/src/extension-api.ts +521 -41
  143. package/src/external-action-source.ts +17 -0
  144. package/src/external-source-poll.ts +61 -0
  145. package/src/flow.ts +674 -677
  146. package/src/form-contract.ts +0 -4
  147. package/src/fs-utils.ts +21 -2
  148. package/src/git-binary.ts +2 -1
  149. package/src/graph-fragments.ts +16 -0
  150. package/src/host-capabilities.ts +9 -6
  151. package/src/index.ts +51 -206
  152. package/src/integration-http.ts +70 -0
  153. package/src/json-data.ts +25 -0
  154. package/src/leaf-outcome-renderer.ts +35 -0
  155. package/src/leaf-outcomes.ts +4 -9
  156. package/src/model-provider.ts +179 -43
  157. package/src/pi-config-public.ts +7 -0
  158. package/src/pi-config.ts +48 -8
  159. package/src/process-definition-internals.ts +4 -0
  160. package/src/process-flow-view.ts +34 -88
  161. package/src/process-graph.ts +59 -51
  162. package/src/process-launcher-builder.ts +5 -0
  163. package/src/process-watcher-builder.ts +5 -0
  164. package/src/process-watcher-source.ts +9 -10
  165. package/src/project-binding.ts +40 -0
  166. package/src/registry-utils.ts +7 -5
  167. package/src/repository-feedback.ts +85 -0
  168. package/src/repository-git-env.ts +40 -2
  169. package/src/repository-http.ts +88 -0
  170. package/src/repository-https.ts +22 -0
  171. package/src/repository-issue-watcher.ts +122 -0
  172. package/src/repository-reconciliation.ts +30 -0
  173. package/src/repository-source-config.ts +79 -0
  174. package/src/repository-types.ts +63 -0
  175. package/src/review-flow-public.ts +5 -0
  176. package/src/review-flow.ts +6 -0
  177. package/src/runtime-internals-public.ts +7 -0
  178. package/src/server-events.ts +67 -0
  179. package/src/server-process-builder.ts +10 -1
  180. package/src/state-helpers.ts +14 -4
  181. package/src/subprocess-env.ts +9 -0
  182. package/src/tool-arguments.ts +39 -0
  183. package/src/tool-renderers.ts +6 -0
  184. package/src/turn-semantics.ts +45 -76
  185. package/src/types.ts +216 -44
  186. package/src/ui-process-builder.ts +8 -1
  187. package/src/worker-process-builder.ts +8 -1
  188. package/dist/browser-ui-extension.js +0 -2
  189. package/dist/browser-ui-extension.js.map +0 -1
  190. package/dist/capabilities.js +0 -7
  191. package/dist/capabilities.js.map +0 -1
  192. package/dist/chunk-5RJZ2E7D.js.map +0 -1
  193. package/dist/chunk-LIIP7FMU.js.map +0 -1
  194. package/dist/chunk-TRQJ5PRM.js.map +0 -1
  195. package/dist/codecs.js +0 -9
  196. package/dist/codecs.js.map +0 -1
  197. package/dist/commit-message.js +0 -3
  198. package/dist/commit-message.js.map +0 -1
  199. package/dist/core-capabilities.js +0 -6
  200. package/dist/core-capabilities.js.map +0 -1
  201. package/dist/define-process.js +0 -1078
  202. package/dist/define-process.js.map +0 -1
  203. package/dist/event-bus.js +0 -31
  204. package/dist/event-bus.js.map +0 -1
  205. package/dist/extension-api.js +0 -5
  206. package/dist/extension-api.js.map +0 -1
  207. package/dist/flow.js +0 -1645
  208. package/dist/flow.js.map +0 -1
  209. package/dist/form-contract.js +0 -2
  210. package/dist/form-contract.js.map +0 -1
  211. package/dist/fs-utils.js +0 -23
  212. package/dist/fs-utils.js.map +0 -1
  213. package/dist/graph-fragments.js +0 -57
  214. package/dist/graph-fragments.js.map +0 -1
  215. package/dist/host-capabilities.js +0 -42
  216. package/dist/host-capabilities.js.map +0 -1
  217. package/dist/launcher-contract.js +0 -2
  218. package/dist/launcher-contract.js.map +0 -1
  219. package/dist/leaf-outcomes.js +0 -52
  220. package/dist/leaf-outcomes.js.map +0 -1
  221. package/dist/model-provider.js +0 -171
  222. package/dist/model-provider.js.map +0 -1
  223. package/dist/process-definition-internals.js +0 -25
  224. package/dist/process-definition-internals.js.map +0 -1
  225. package/dist/process-flow-view.js +0 -418
  226. package/dist/process-flow-view.js.map +0 -1
  227. package/dist/process-graph.js +0 -212
  228. package/dist/process-graph.js.map +0 -1
  229. package/dist/process-launcher-builder.js +0 -43
  230. package/dist/process-launcher-builder.js.map +0 -1
  231. package/dist/process-watcher-builder.js +0 -40
  232. package/dist/process-watcher-builder.js.map +0 -1
  233. package/dist/process-watcher-source.js +0 -52
  234. package/dist/process-watcher-source.js.map +0 -1
  235. package/dist/registry-utils.js +0 -18
  236. package/dist/registry-utils.js.map +0 -1
  237. package/dist/repository-git-env.js +0 -26
  238. package/dist/repository-git-env.js.map +0 -1
  239. package/dist/server-events.js +0 -2
  240. package/dist/server-events.js.map +0 -1
  241. package/dist/server-process-builder.js +0 -52
  242. package/dist/server-process-builder.js.map +0 -1
  243. package/dist/state-helpers.js +0 -18
  244. package/dist/state-helpers.js.map +0 -1
  245. package/dist/subprocess-env.js +0 -34
  246. package/dist/subprocess-env.js.map +0 -1
  247. package/dist/tool-renderers.js +0 -63
  248. package/dist/tool-renderers.js.map +0 -1
  249. package/dist/turn-semantics.js +0 -365
  250. package/dist/turn-semantics.js.map +0 -1
  251. package/dist/types.js +0 -23
  252. package/dist/types.js.map +0 -1
  253. package/dist/ui-process-builder.js +0 -30
  254. package/dist/ui-process-builder.js.map +0 -1
  255. package/dist/worker-process-builder.js +0 -22
  256. package/dist/worker-process-builder.js.map +0 -1
@@ -18,14 +18,17 @@ if (!registryHolder[registryKey]) {
18
18
  }
19
19
  const registry = registryHolder[registryKey];
20
20
 
21
+ /** @internal */
21
22
  export function markDefinedProcess(value: object): void {
22
23
  registry.definedProcesses.add(value);
23
24
  }
24
25
 
26
+ /** @internal */
25
27
  export function isDefinedProcess(value: unknown): boolean {
26
28
  return typeof value === "object" && value !== null && registry.definedProcesses.has(value);
27
29
  }
28
30
 
31
+ /** @internal */
29
32
  export function setProcessTurnTransitions(
30
33
  binding: object,
31
34
  transitions: readonly ProcessTurnTransition[],
@@ -36,6 +39,7 @@ export function setProcessTurnTransitions(
36
39
  );
37
40
  }
38
41
 
42
+ /** @internal */
39
43
  export function getProcessTurnTransitions(
40
44
  binding: ProcessTurnBinding<unknown> | undefined,
41
45
  ): readonly ProcessTurnTransition[] {
@@ -7,17 +7,10 @@ import {
7
7
  type ProcessTurnTerminalLifecycleStatus,
8
8
  type ProcessTurnTransition,
9
9
  type TurnId,
10
+ trimToNull,
10
11
  } from "@leitwerk-dev/domain";
11
12
  import type { ProcessGraphTurnView, ProcessGraphView } from "./process-graph.js";
12
13
 
13
- function trimToNull(value: string | undefined | null): string | null {
14
- if (typeof value !== "string") {
15
- return null;
16
- }
17
- const trimmed = value.trim();
18
- return trimmed === "" ? null : trimmed;
19
- }
20
-
21
14
  /**
22
15
  * Human/operator turns are routing decisions: they pick which path the process
23
16
  * takes but perform no work themselves. They are collapsed out of the flow graph
@@ -52,17 +45,13 @@ function computeRoutingAnchors(
52
45
  graph: ProcessGraphView,
53
46
  routingIds: ReadonlySet<TurnId>,
54
47
  ): Map<TurnId, TurnId> {
55
- const declarationIndex = new Map<TurnId, number>();
56
- [...graph.turns.keys()].forEach((turnId, index) => {
57
- declarationIndex.set(turnId, index);
58
- });
59
-
60
- const happyIndex = new Map<TurnId, number>();
61
- (graph.happyPath ?? []).forEach((turnId, index) => {
62
- if (!happyIndex.has(turnId)) {
63
- happyIndex.set(turnId, index);
64
- }
65
- });
48
+ // Happy-path turns come first, then the remaining turns in declaration order.
49
+ const preferenceIndex = new Map(
50
+ [...new Set([...(graph.happyPath ?? []), ...graph.turns.keys()])].map((turnId, index) => [
51
+ turnId,
52
+ index,
53
+ ]),
54
+ );
66
55
 
67
56
  const workPredecessors = new Map<TurnId, TurnId[]>();
68
57
  const routingPredecessors = new Map<TurnId, TurnId[]>();
@@ -84,22 +73,14 @@ function computeRoutingAnchors(
84
73
  }
85
74
  }
86
75
 
87
- const preferenceKey = (turnId: TurnId): [number, number] => [
88
- happyIndex.get(turnId) ?? Number.POSITIVE_INFINITY,
89
- declarationIndex.get(turnId) ?? Number.POSITIVE_INFINITY,
90
- ];
91
76
  const pickPreferred = (candidates: readonly TurnId[]): TurnId | undefined => {
92
77
  let best: TurnId | undefined;
93
- let bestKey: [number, number] | undefined;
78
+ let bestIndex = Number.POSITIVE_INFINITY;
94
79
  for (const candidate of candidates) {
95
- const key = preferenceKey(candidate);
96
- if (
97
- bestKey === undefined ||
98
- key[0] < bestKey[0] ||
99
- (key[0] === bestKey[0] && key[1] < bestKey[1])
100
- ) {
80
+ const index = preferenceIndex.get(candidate) ?? Number.POSITIVE_INFINITY;
81
+ if (best === undefined || index < bestIndex) {
101
82
  best = candidate;
102
- bestKey = key;
83
+ bestIndex = index;
103
84
  }
104
85
  }
105
86
  return best;
@@ -168,18 +149,16 @@ function redirectTransition(
168
149
  }
169
150
 
170
151
  function dedupeTransitions(transitions: readonly ProcessTurnTransition[]): ProcessTurnTransition[] {
171
- const seen = new Set<string>();
172
- const result: ProcessTurnTransition[] = [];
152
+ const result = new Map<string, ProcessTurnTransition>();
173
153
  for (const transition of transitions) {
174
154
  const label = trimToNull(transition.outcome) ?? trimToNull(transition.trigger);
175
155
  const key = `${transition.nextTurnId ?? ""}|${transition.lifecycleStatus ?? ""}|${label ?? ""}`;
176
- if (seen.has(key)) {
156
+ if (result.has(key)) {
177
157
  continue;
178
158
  }
179
- seen.add(key);
180
- result.push(transition);
159
+ result.set(key, transition);
181
160
  }
182
- return result;
161
+ return [...result.values()];
183
162
  }
184
163
 
185
164
  /**
@@ -190,6 +169,7 @@ function dedupeTransitions(transitions: readonly ProcessTurnTransition[]): Proce
190
169
  * here and dropped later during edge construction. Entry turns and the declared
191
170
  * happy path are remapped/filtered to stay consistent.
192
171
  */
172
+ /** @internal */
193
173
  export function collapseRoutingTurns(graph: ProcessGraphView): ProcessGraphView {
194
174
  const routingIds = new Set<TurnId>();
195
175
  for (const [turnId, turn] of graph.turns) {
@@ -197,10 +177,7 @@ export function collapseRoutingTurns(graph: ProcessGraphView): ProcessGraphView
197
177
  routingIds.add(turnId);
198
178
  }
199
179
  }
200
- if (routingIds.size === 0) {
201
- return graph;
202
- }
203
- if (routingIds.size === graph.turns.size) {
180
+ if (routingIds.size === 0 || routingIds.size === graph.turns.size) {
204
181
  return graph;
205
182
  }
206
183
 
@@ -264,29 +241,18 @@ export function collapseRoutingTurns(graph: ProcessGraphView): ProcessGraphView
264
241
  * completing path exists.
265
242
  */
266
243
  function deriveSpine(graph: ProcessGraphView, entry: TurnId): TurnId[] {
267
- const turnsWithCompletedTerminal = new Set<TurnId>();
268
- for (const [turnId, turn] of graph.turns) {
269
- if (turn.transitions.some((transition) => transition.lifecycleStatus === "completed")) {
270
- turnsWithCompletedTerminal.add(turnId);
271
- }
272
- }
273
- if (turnsWithCompletedTerminal.size === 0) {
274
- return [entry];
275
- }
276
-
277
244
  const predecessor = new Map<TurnId, TurnId | null>([[entry, null]]);
278
245
  const queue: TurnId[] = [entry];
279
246
  let goal: TurnId | null = null;
280
- while (queue.length > 0) {
281
- const current = queue.shift() as TurnId;
282
- if (turnsWithCompletedTerminal.has(current)) {
283
- goal = current;
284
- break;
285
- }
247
+ for (const current of queue) {
286
248
  const turn = graph.turns.get(current);
287
249
  if (!turn) {
288
250
  continue;
289
251
  }
252
+ if (turn.transitions.some((transition) => transition.lifecycleStatus === "completed")) {
253
+ goal = current;
254
+ break;
255
+ }
290
256
  for (const transition of turn.transitions) {
291
257
  const next = transition.nextTurnId;
292
258
  if (next === undefined || predecessor.has(next) || !graph.turns.has(next)) {
@@ -360,24 +326,6 @@ function transitionLabel(transition: { outcome?: string; trigger?: string }): st
360
326
  return raw === null ? null : humanizeProcessLabel(raw);
361
327
  }
362
328
 
363
- function buildNode(input: {
364
- turnId: TurnId;
365
- turn: ProcessGraphTurnView;
366
- spineIndex: number | null;
367
- anchorTurnId: TurnId | null;
368
- isEntry: boolean;
369
- }): ProcessFlowNode {
370
- return {
371
- turnId: input.turnId,
372
- description: trimToNull(input.turn.description) ?? input.turnId,
373
- turnType: input.turn.turnType,
374
- role: input.spineIndex === null ? "branch" : "spine",
375
- spineIndex: input.spineIndex,
376
- anchorTurnId: input.spineIndex === null ? input.anchorTurnId : null,
377
- isEntry: input.isEntry,
378
- };
379
- }
380
-
381
329
  /**
382
330
  * Projects a process graph into a spine-first flow view for operator-facing
383
331
  * diagrams. The spine is the declared happy path (or a derived best-effort path
@@ -385,6 +333,7 @@ function buildNode(input: {
385
333
  * The `aborted` end state is always present because abort is reachable from any
386
334
  * active turn, even when no explicit transition targets it.
387
335
  */
336
+ /** @internal */
388
337
  export function buildProcessFlowView(rawGraph: ProcessGraphView): ProcessFlowView {
389
338
  const graph = collapseRoutingTurns(rawGraph);
390
339
  const entryTurnIds = [...graph.entryTurnIds].filter((turnId) => graph.turns.has(turnId));
@@ -411,15 +360,15 @@ export function buildProcessFlowView(rawGraph: ProcessGraphView): ProcessFlowVie
411
360
  const nodes: ProcessFlowNode[] = [];
412
361
  for (const [turnId, turn] of graph.turns) {
413
362
  const spineIndex = spineIndexByTurn.get(turnId) ?? null;
414
- nodes.push(
415
- buildNode({
416
- turnId,
417
- turn,
418
- spineIndex,
419
- anchorTurnId: anchorByTurn.get(turnId) ?? null,
420
- isEntry: entrySet.has(turnId),
421
- }),
422
- );
363
+ nodes.push({
364
+ turnId,
365
+ description: trimToNull(turn.description) ?? turnId,
366
+ turnType: turn.turnType,
367
+ role: spineIndex === null ? "branch" : "spine",
368
+ spineIndex,
369
+ anchorTurnId: spineIndex === null ? (anchorByTurn.get(turnId) ?? null) : null,
370
+ isEntry: entrySet.has(turnId),
371
+ });
423
372
  }
424
373
 
425
374
  const edges: ProcessFlowEdge[] = [];
@@ -439,12 +388,9 @@ export function buildProcessFlowView(rawGraph: ProcessGraphView): ProcessFlowVie
439
388
  continue;
440
389
  }
441
390
  const next = transition.nextTurnId;
442
- if (next === undefined) {
443
- continue;
444
- }
445
391
  // Skip self-loops: an edge that leaves and re-enters the same box adds
446
392
  // clutter without conveying additional flow.
447
- if (next === turnId) {
393
+ if (next === undefined || next === turnId) {
448
394
  continue;
449
395
  }
450
396
  const fromIndex = spineIndexByTurn.get(turnId);
@@ -10,94 +10,89 @@ import type { TurnDefinition } from "./define-process.js";
10
10
  import type { ExtensionProcessDefinition, ProcessTurnBinding } from "./extension-api.js";
11
11
  import { getProcessTurnTransitions } from "./process-definition-internals.js";
12
12
 
13
+ /** @internal */
13
14
  export type ProcessGraphSource = ExtensionProcessDefinition<unknown, unknown>;
15
+ /** @internal */
14
16
  export type ProcessGraphRegistry = ReadonlyMap<string, ProcessGraphSource>;
15
17
 
18
+ /** @internal */
16
19
  export interface ProcessGraphTurnView {
20
+ /** @internal */
17
21
  turnType: ProcessTurnType;
22
+ /** @internal */
18
23
  description: string;
24
+ /** @internal */
19
25
  transitions: readonly ProcessTurnTransition[];
26
+ /** @internal */
20
27
  reviewProduct?: string;
28
+ /** @internal */
21
29
  resultSemanticRef?: ProcessSemanticEntryRefKey;
30
+ /** @internal */
22
31
  publishedProduct?: string;
32
+ /** @internal */
23
33
  publishedProducts?: readonly string[];
34
+ /** @internal */
24
35
  consumedProducts?: readonly string[];
36
+ /** @internal */
25
37
  optionalConsumedProducts?: readonly string[];
38
+ /** @internal */
26
39
  requiredSemanticMarkdownRefs?: readonly ProcessSemanticEntryRefKey[];
40
+ /** @internal */
27
41
  optionalSemanticMarkdownRefs?: readonly ProcessSemanticEntryRefKey[];
42
+ /** @internal */
28
43
  turnResultMarkdownRequired?: boolean;
29
44
  }
30
45
 
46
+ /** @internal */
31
47
  export interface ProcessGraphView {
48
+ /** @internal */
32
49
  id: string;
50
+ /** @internal */
33
51
  primaryEntryTurnId: TurnId;
52
+ /** @internal */
34
53
  entryTurnIds: ReadonlySet<TurnId>;
54
+ /** @internal */
35
55
  happyPath: readonly TurnId[] | null;
56
+ /** @internal */
36
57
  turns: ReadonlyMap<TurnId, ProcessGraphTurnView>;
37
58
  }
38
59
 
39
- function toTurnType(definition: TurnDefinition<unknown, unknown>): ProcessTurnType {
40
- switch (definition.kind) {
41
- case "llm":
42
- case "human":
43
- case "external":
44
- case "automatic":
45
- case "server_automatic":
46
- return definition.kind;
47
- }
48
- }
49
-
50
- function humanPublishedProducts(definition: TurnDefinition<unknown, unknown>): string[] {
51
- if (definition.kind !== "human") {
52
- return [];
53
- }
54
- const products: string[] = [];
55
- for (const action of Object.values(definition.actions)) {
56
- for (const field of action.form?.fields ?? []) {
57
- if (!field.publish) {
58
- continue;
60
+ function turnPublishedProducts(definition: TurnDefinition<unknown, unknown>): string[] {
61
+ const products = new Set<string>();
62
+ if (definition.kind === "human") {
63
+ for (const action of Object.values(definition.actions)) {
64
+ for (const field of action.form?.fields ?? []) {
65
+ if (field.publish) {
66
+ products.add(
67
+ typeof field.publish === "object" && field.publish.product
68
+ ? field.publish.product
69
+ : field.id,
70
+ );
71
+ }
59
72
  }
60
- products.push(
61
- typeof field.publish === "object" && field.publish.product
62
- ? field.publish.product
63
- : field.id,
64
- );
65
73
  }
66
- }
67
- for (const externalAction of Object.values(definition.externalActions ?? {})) {
68
- if (externalAction.publishInput) {
69
- products.push(externalAction.publishInput.productName);
74
+ for (const action of Object.values(definition.externalActions ?? {})) {
75
+ if (action.publishInput) {
76
+ products.add(action.publishInput.productName);
77
+ }
78
+ }
79
+ } else if (definition.kind === "llm" || definition.kind === "automatic") {
80
+ for (const outcome of Object.values(definition.outcomes ?? {})) {
81
+ if (typeof outcome?.publishedProduct === "string") {
82
+ products.add(outcome.publishedProduct);
83
+ }
70
84
  }
71
85
  }
72
- return [...new Set(products)];
73
- }
74
-
75
- function outcomePublishedProducts(definition: TurnDefinition<unknown, unknown>): string[] {
76
- if (
77
- definition.kind !== "llm" &&
78
- definition.kind !== "automatic" &&
79
- definition.kind !== "server_automatic"
80
- ) {
81
- return [];
82
- }
83
- return [
84
- ...new Set(
85
- Object.values(definition.outcomes ?? {})
86
- .map((outcome) => outcome?.publishedProduct)
87
- .filter((productName): productName is string => typeof productName === "string"),
88
- ),
89
- ];
86
+ return [...products];
90
87
  }
91
88
 
92
89
  function toTurnView(
93
90
  binding: ProcessTurnBinding<TurnDefinition<unknown, unknown>>,
94
91
  ): ProcessGraphTurnView {
95
92
  const definition = binding.definition;
96
- const publishedProducts = [
97
- ...new Set([...humanPublishedProducts(definition), ...outcomePublishedProducts(definition)]),
98
- ];
93
+ const publishedProducts = turnPublishedProducts(definition);
99
94
  return {
100
- turnType: toTurnType(definition),
95
+ turnType: definition.kind,
101
96
  description: definition.description,
102
97
  transitions: getProcessTurnTransitions(binding),
103
98
  ...(definition.kind === "human" && definition.reviewProduct
@@ -136,6 +131,7 @@ function toTurnView(
136
131
  * All server lifecycle, validation, model-selection and serialization code should use this view
137
132
  * instead of maintaining a second graph representation.
138
133
  */
134
+ /** @internal */
139
135
  export function toProcessGraphView(definition: ProcessGraphSource): ProcessGraphView {
140
136
  const turns = new Map<TurnId, ProcessGraphTurnView>();
141
137
  for (const [turnId, binding] of definition.turns) {
@@ -150,10 +146,12 @@ export function toProcessGraphView(definition: ProcessGraphSource): ProcessGraph
150
146
  };
151
147
  }
152
148
 
149
+ /** @internal */
153
150
  export function hasProcessGraph(registry: ProcessGraphRegistry, processId: string): boolean {
154
151
  return registry.has(processId);
155
152
  }
156
153
 
154
+ /** @internal */
157
155
  export function getProcessGraph(
158
156
  registry: ProcessGraphRegistry,
159
157
  processId: string,
@@ -165,10 +163,12 @@ export function getProcessGraph(
165
163
  return toProcessGraphView(definition);
166
164
  }
167
165
 
166
+ /** @internal */
168
167
  export function getAllProcessGraphs(registry: ProcessGraphRegistry): readonly ProcessGraphView[] {
169
168
  return [...registry.values()].map((definition) => toProcessGraphView(definition));
170
169
  }
171
170
 
171
+ /** @internal */
172
172
  export function getProcessTurnGraph(
173
173
  registry: ProcessGraphRegistry,
174
174
  processId: string,
@@ -177,6 +177,7 @@ export function getProcessTurnGraph(
177
177
  return getProcessGraph(registry, processId).turns.get(turnId);
178
178
  }
179
179
 
180
+ /** @internal */
180
181
  export function getTurnTransitionsForProcessGraph(
181
182
  registry: ProcessGraphRegistry,
182
183
  processId: string,
@@ -185,6 +186,7 @@ export function getTurnTransitionsForProcessGraph(
185
186
  return getProcessTurnGraph(registry, processId, turnId)?.transitions ?? [];
186
187
  }
187
188
 
189
+ /** @internal */
188
190
  export function getReachableTurnIdsForProcessGraph(
189
191
  registry: ProcessGraphRegistry,
190
192
  processId: string,
@@ -192,6 +194,7 @@ export function getReachableTurnIdsForProcessGraph(
192
194
  return [...getProcessGraph(registry, processId).turns.keys()];
193
195
  }
194
196
 
197
+ /** @internal */
195
198
  export function isTurnAvailableForProcessGraph(
196
199
  registry: ProcessGraphRegistry,
197
200
  processId: string,
@@ -200,6 +203,7 @@ export function isTurnAvailableForProcessGraph(
200
203
  return getProcessGraph(registry, processId).turns.has(turnId);
201
204
  }
202
205
 
206
+ /** @internal */
203
207
  export function serializeProcessGraph(
204
208
  registry: ProcessGraphRegistry,
205
209
  processId: string,
@@ -217,6 +221,7 @@ export function serializeProcessGraph(
217
221
  };
218
222
  }
219
223
 
224
+ /** @internal */
220
225
  export function listLlmTurnIdsForProcessGraph(
221
226
  registry: ProcessGraphRegistry,
222
227
  processId: string,
@@ -230,6 +235,7 @@ function isTerminalLifecycleStatus(value: string | undefined): value is "complet
230
235
  return value === "completed" || value === "aborted";
231
236
  }
232
237
 
238
+ /** @internal */
233
239
  export function validateProcessGraphEntryTurns(graph: ProcessGraphView): readonly string[] {
234
240
  const errors: string[] = [];
235
241
  for (const turnId of graph.entryTurnIds) {
@@ -240,6 +246,7 @@ export function validateProcessGraphEntryTurns(graph: ProcessGraphView): readonl
240
246
  return errors;
241
247
  }
242
248
 
249
+ /** @internal */
243
250
  export function validateProcessGraphProducts(graph: ProcessGraphView): readonly string[] {
244
251
  const errors: string[] = [];
245
252
  const publishedProducts = new Set<string>();
@@ -275,6 +282,7 @@ export function validateProcessGraphProducts(graph: ProcessGraphView): readonly
275
282
  return errors;
276
283
  }
277
284
 
285
+ /** @internal */
278
286
  export function validateProcessGraphTurnTransitions(graph: ProcessGraphView): readonly string[] {
279
287
  const errors: string[] = [];
280
288
  for (const [turnId, turn] of graph.turns) {
@@ -5,7 +5,9 @@ import type {
5
5
  } from "./extension-api.js";
6
6
  import { cloneMap, registerUnique } from "./registry-utils.js";
7
7
 
8
+ /** @public */
8
9
  export interface BuiltProcessLauncherDefinition<TParams = unknown> {
10
+ /** @public */
9
11
  launchers: ReadonlyMap<string, ProcessLauncherDefinition<TParams>>;
10
12
  }
11
13
 
@@ -27,7 +29,9 @@ function validateLauncherDefinition<TParams>(def: ProcessLauncherDefinition<TPar
27
29
  }
28
30
  }
29
31
 
32
+ /** @internal */
30
33
  export function createProcessLauncherBuilder<TParams = unknown>(): ProcessLauncherAPI<TParams> & {
34
+ /** @internal */
31
35
  getDefinition(): BuiltProcessLauncherDefinition<TParams>;
32
36
  } {
33
37
  const launchers = new Map<string, ProcessLauncherDefinition<TParams>>();
@@ -47,6 +51,7 @@ export function createProcessLauncherBuilder<TParams = unknown>(): ProcessLaunch
47
51
  };
48
52
  }
49
53
 
54
+ /** @public */
50
55
  export function buildProcessLaunchers<TParams = unknown, TState = unknown>(
51
56
  process: ExtensionProcessDefinition<TParams, TState>,
52
57
  ): BuiltProcessLauncherDefinition<TParams> | undefined {
@@ -5,7 +5,9 @@ import type {
5
5
  } from "./extension-api.js";
6
6
  import { cloneMap, registerUnique } from "./registry-utils.js";
7
7
 
8
+ /** @public */
8
9
  export interface BuiltProcessWatcherDefinition<TParams = unknown> {
10
+ /** @public */
9
11
  watchers: ReadonlyMap<string, ProcessWatcherDefinition<TParams, unknown, unknown>>;
10
12
  }
11
13
 
@@ -26,7 +28,9 @@ function validateWatcherDefinition<TParams>(
26
28
  }
27
29
  }
28
30
 
31
+ /** @internal */
29
32
  export function createProcessWatcherBuilder<TParams = unknown>(): ProcessWatcherAPI<TParams> & {
33
+ /** @internal */
30
34
  getDefinition(): BuiltProcessWatcherDefinition<TParams>;
31
35
  } {
32
36
  const watchers = new Map<string, ProcessWatcherDefinition<TParams, unknown, unknown>>();
@@ -53,6 +57,7 @@ export function createProcessWatcherBuilder<TParams = unknown>(): ProcessWatcher
53
57
  };
54
58
  }
55
59
 
60
+ /** @public */
56
61
  export function buildProcessWatchers<TParams = unknown, TState = unknown>(
57
62
  process: ExtensionProcessDefinition<TParams, TState>,
58
63
  ): BuiltProcessWatcherDefinition<TParams> | undefined {
@@ -1,12 +1,9 @@
1
1
  import type { LaunchModelConfigInput } from "@leitwerk-dev/domain";
2
2
  import type { ProcessWatcherSource } from "./extension-api.js";
3
+ import { objectArg } from "./tool-arguments.js";
3
4
 
4
- function record(value: unknown, subject: string): Record<string, unknown> {
5
- if (!value || typeof value !== "object" || Array.isArray(value)) {
6
- throw new Error(`${subject} must be an object`);
7
- }
8
- return value as Record<string, unknown>;
9
- }
5
+ const record = (value: unknown, subject: string) =>
6
+ objectArg(value, `${subject} must be an object`);
10
7
 
11
8
  function nonEmptyString(value: unknown, path: string): string {
12
9
  if (typeof value !== "string" || value.trim() === "") {
@@ -15,10 +12,11 @@ function nonEmptyString(value: unknown, path: string): string {
15
12
  return value;
16
13
  }
17
14
 
18
- /** Parse the shared launch-model fragment nested inside extension-owned watcher config. */
19
- export function parseProcessWatcherLaunchModelConfig(
20
- value: unknown,
21
- ): LaunchModelConfigInput & { skillIds: string[] } {
15
+ /** Parse the shared launch-model fragment nested inside extension-owned watcher config. @public */
16
+ export function parseProcessWatcherLaunchModelConfig(value: unknown): LaunchModelConfigInput & {
17
+ /** @internal */
18
+ skillIds: string[];
19
+ } {
22
20
  if (value === undefined) return { defaultModelProfileId: null, turnConfigs: {}, skillIds: [] };
23
21
  const launch = record(value, "launch");
24
22
  const rawSkills = launch.skills === undefined ? [] : launch.skills;
@@ -51,6 +49,7 @@ export function parseProcessWatcherLaunchModelConfig(
51
49
  };
52
50
  }
53
51
 
52
+ /** @public */
54
53
  export function defineProcessWatcherSource<TConfig, TEvent = unknown>(
55
54
  source: ProcessWatcherSource<TConfig, TEvent>,
56
55
  ): ProcessWatcherSource<TConfig, TEvent> {
@@ -0,0 +1,40 @@
1
+ import type { IntegrationToolExecutionContext } from "./extension-api.js";
2
+ import { objectArg } from "./tool-arguments.js";
3
+
4
+ /** @public */
5
+ export interface RepositoryProjectBinding {
6
+ /** @public */
7
+ owner: string;
8
+ /** @public */
9
+ repo: string;
10
+ /** @public */
11
+ profile: string;
12
+ }
13
+
14
+ /** Validate an authorized project's binding, retaining extension-selected legacy metadata. @public */
15
+ export function resolveRepositoryProjectBinding(
16
+ ctx: Pick<IntegrationToolExecutionContext, "project" | "process">,
17
+ provider: string,
18
+ legacyMetadataKey?: string,
19
+ ): RepositoryProjectBinding {
20
+ const object = (value: unknown) => objectArg(value, `Invalid ${provider} project binding`);
21
+ function text(value: unknown, key: string): string {
22
+ if (typeof value !== "string" || !value.trim())
23
+ throw new Error(`${provider} binding ${key} must be a non-empty string`);
24
+ return value.trim();
25
+ }
26
+ if (!ctx.project || ctx.project.instanceId !== ctx.process.id)
27
+ throw new Error("An authorized process project is required");
28
+ const metadata = object(ctx.project.metadata ?? {});
29
+ const useLegacy = legacyMetadataKey !== undefined && metadata[provider] === undefined;
30
+ const binding = object(metadata[useLegacy ? legacyMetadataKey : provider]);
31
+ const profile =
32
+ useLegacy || (legacyMetadataKey === undefined && binding.profile === undefined)
33
+ ? object(JSON.parse(ctx.process.paramsJson ?? "{}"))[`${provider}Profile`]
34
+ : binding.profile;
35
+ return {
36
+ owner: text(binding.owner, "owner"),
37
+ repo: text(binding.repo, "repo"),
38
+ profile: text(profile, "profile"),
39
+ };
40
+ }
@@ -1,8 +1,12 @@
1
+ /** @internal */
1
2
  export interface UniqueRegistrationOptions<TValue> {
3
+ /** @internal */
2
4
  duplicateMessage: string;
5
+ /** @internal */
3
6
  validate?: (value: TValue) => void;
4
7
  }
5
8
 
9
+ /** @internal */
6
10
  export function registerUnique<TKey, TValue>(
7
11
  registry: Map<TKey, TValue>,
8
12
  key: TKey,
@@ -16,16 +20,14 @@ export function registerUnique<TKey, TValue>(
16
20
  registry.set(key, value);
17
21
  }
18
22
 
23
+ /** @internal */
19
24
  export function cloneMap<TKey, TValue>(registry: ReadonlyMap<TKey, TValue>): Map<TKey, TValue> {
20
25
  return new Map(registry);
21
26
  }
22
27
 
28
+ /** @internal */
23
29
  export function cloneArrayValueMap<TKey, TValue>(
24
30
  registry: ReadonlyMap<TKey, readonly TValue[]>,
25
31
  ): Map<TKey, readonly TValue[]> {
26
- const cloned = new Map<TKey, readonly TValue[]>();
27
- for (const [key, values] of registry) {
28
- cloned.set(key, [...values]);
29
- }
30
- return cloned;
32
+ return new Map(Array.from(registry, ([key, values]) => [key, [...values]]));
31
33
  }