@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
@@ -7,99 +7,166 @@ import type {
7
7
  WorkerErrorClass,
8
8
  } from "@leitwerk-dev/domain";
9
9
 
10
+ /** @internal */
10
11
  export interface ProcessCreatedEvent {
12
+ /** @internal */
11
13
  instanceId: string;
14
+ /** @internal */
12
15
  process: ProcessInstance;
16
+ /** @internal */
13
17
  projects: readonly ProcessProject[];
18
+ /** @internal */
14
19
  launcherId?: string | null;
15
20
  }
16
21
 
22
+ /** @internal */
17
23
  export interface ProcessUpdatedEvent {
24
+ /** @internal */
18
25
  instanceId: string;
26
+ /** @internal */
19
27
  process: ProcessInstance;
28
+ /** @internal */
20
29
  changedFields: readonly string[];
21
30
  }
22
31
 
32
+ /** @internal */
23
33
  export interface TurnStartedEvent {
34
+ /** @internal */
24
35
  instanceId: string;
36
+ /** @internal */
25
37
  turnRecord: ProcessTurnRecord;
26
38
  }
27
39
 
40
+ /** @internal */
28
41
  export interface TurnFailedEvent {
42
+ /** @internal */
29
43
  instanceId: string;
44
+ /** @internal */
30
45
  turnRecord: ProcessTurnRecord;
46
+ /** @internal */
31
47
  errorSummary: string;
48
+ /** @internal */
32
49
  errorClass?: WorkerErrorClass | null;
33
50
  }
34
51
 
52
+ /** @internal */
35
53
  export interface LeafOutcomeCapturedEvent {
54
+ /** @internal */
36
55
  instanceId: string;
56
+ /** @internal */
37
57
  snapshot: ProcessLeafOutcomeSnapshot;
38
58
  }
39
59
 
60
+ /** @internal */
40
61
  export interface ReviewRequestedEvent {
62
+ /** @internal */
41
63
  instanceId: string;
64
+ /** @internal */
42
65
  workerId?: string;
66
+ /** @internal */
43
67
  changedProjects: string[];
44
68
  }
45
69
 
70
+ /** @internal */
46
71
  export interface QuestionRequestedEvent {
72
+ /** @internal */
47
73
  instanceId: string;
74
+ /** @internal */
48
75
  request: ProcessQuestionRequest;
49
76
  }
50
77
 
78
+ /** @internal */
51
79
  export interface TurnOutcomeEvent {
80
+ /** @internal */
52
81
  instanceId: string;
82
+ /** @internal */
53
83
  turnRecordId: string;
84
+ /** @internal */
54
85
  turnId: string;
86
+ /** @internal */
55
87
  outcome: string;
88
+ /** @internal */
56
89
  params: Record<string, unknown>;
90
+ /** @internal */
57
91
  turnResultMarkdown?: string | null;
58
92
  }
59
93
 
94
+ /** @internal */
60
95
  export interface PlanApprovedEvent {
96
+ /** @internal */
61
97
  instanceId: string;
98
+ /** @internal */
62
99
  externalId: string | null;
100
+ /** @internal */
63
101
  planRevision: number;
64
102
  }
65
103
 
104
+ /** @internal */
66
105
  export interface PlanRevisionRequestedEvent {
106
+ /** @internal */
67
107
  instanceId: string;
108
+ /** @internal */
68
109
  message: string;
69
110
  }
70
111
 
112
+ /** @internal */
71
113
  export interface PlanSavedEvent {
114
+ /** @internal */
72
115
  instanceId: string;
116
+ /** @internal */
73
117
  planRevision: number;
118
+ /** @internal */
74
119
  summary: string;
120
+ /** @internal */
75
121
  planMarkdown: string;
122
+ /** @internal */
76
123
  acceptanceCriteria: string[];
77
124
  }
78
125
 
126
+ /** @internal */
79
127
  export interface ReviewCompletedEvent {
128
+ /** @internal */
80
129
  instanceId: string;
130
+ /** @internal */
81
131
  hasIssues: boolean;
132
+ /** @internal */
82
133
  issueCount: number;
134
+ /** @internal */
83
135
  reviewMarkdown?: string;
84
136
  }
85
137
 
138
+ /** @internal */
86
139
  export interface ServerExtensionEventMap {
140
+ /** @internal */
87
141
  process_created: ProcessCreatedEvent;
142
+ /** @internal */
88
143
  process_updated: ProcessUpdatedEvent;
144
+ /** @internal */
89
145
  turn_started: TurnStartedEvent;
146
+ /** @internal */
90
147
  turn_failed: TurnFailedEvent;
148
+ /** @internal */
91
149
  leaf_outcome_captured: LeafOutcomeCapturedEvent;
150
+ /** @internal */
92
151
  question_requested: QuestionRequestedEvent;
152
+ /** @internal */
93
153
  review_requested: ReviewRequestedEvent;
154
+ /** @internal */
94
155
  turn_outcome: TurnOutcomeEvent;
156
+ /** @internal */
95
157
  plan_approved: PlanApprovedEvent;
158
+ /** @internal */
96
159
  plan_revision_requested: PlanRevisionRequestedEvent;
160
+ /** @internal */
97
161
  plan_saved: PlanSavedEvent;
162
+ /** @internal */
98
163
  review_completed: ReviewCompletedEvent;
99
164
  }
100
165
 
166
+ /** @internal */
101
167
  export type ServerExtensionEventName = keyof ServerExtensionEventMap;
102
168
 
169
+ /** @internal */
103
170
  export type ServerExtensionEventPayloadInputMap = {
104
171
  [K in keyof ServerExtensionEventMap]: Omit<ServerExtensionEventMap[K], "instanceId">;
105
172
  };
@@ -11,21 +11,30 @@ import {
11
11
  validateProcessActionSchedulingDefinition,
12
12
  } from "./turn-semantics.js";
13
13
 
14
+ /** @internal */
14
15
  export type ServerTurnOutcomeHandler<TParams = unknown, TState = unknown> = (
15
16
  event: ProcessTurnOutcomeEvent,
16
17
  ctx: ServerProcessContext<TParams, TState>,
17
18
  ) => void | Promise<void>;
18
19
 
20
+ /** @internal */
19
21
  export interface BuiltServerProcessDefinition<TParams = unknown, TState = unknown> {
22
+ /** @internal */
20
23
  actions: ReadonlyMap<string, ProcessActionDefinition<TParams, TState>>;
24
+ /** @internal */
21
25
  turnOutcomeHandlers: ReadonlyMap<string, readonly ServerTurnOutcomeHandler<TParams, TState>[]>;
26
+ /** @internal */
22
27
  cleanupHandlers: readonly ProcessCleanupHandler<TParams, TState>[];
23
28
  }
24
29
 
30
+ /** @internal */
25
31
  export function createServerProcessBuilder<TParams = unknown, TState = unknown>(): ServerProcessAPI<
26
32
  TParams,
27
33
  TState
28
- > & { getDefinition(): BuiltServerProcessDefinition<TParams, TState> } {
34
+ > & {
35
+ /** @internal */
36
+ getDefinition(): BuiltServerProcessDefinition<TParams, TState>;
37
+ } {
29
38
  const actions = new Map<string, ProcessActionDefinition<TParams, TState>>();
30
39
  const turnOutcomeHandlers = new Map<string, ServerTurnOutcomeHandler<TParams, TState>[]>();
31
40
  const cleanupHandlers: ProcessCleanupHandler<TParams, TState>[] = [];
@@ -1,4 +1,5 @@
1
1
  import {
2
+ asUnknownRecord,
2
3
  createEmptyProcessProductRefs,
3
4
  createEmptyProcessSemanticEntryRefs,
4
5
  type ProcessProductRefs,
@@ -6,12 +7,23 @@ import {
6
7
  parseProcessProductRefs,
7
8
  parseProcessSemanticEntryRefs,
8
9
  } from "@leitwerk-dev/domain";
10
+ import type { Codec } from "./extension-api.js";
9
11
 
12
+ /** @public */
10
13
  export interface StructuralProcessState {
14
+ /** @internal */
11
15
  semanticEntryRefs: ProcessSemanticEntryRefs;
16
+ /** @internal */
12
17
  productRefs: ProcessProductRefs;
13
18
  }
14
19
 
20
+ /** @internal */
21
+ export const structuralStateCodec: Codec<StructuralProcessState> = {
22
+ parse: parseStructuralProcessState,
23
+ serialize: (value) => value,
24
+ };
25
+
26
+ /** @public */
15
27
  export function createEmptyStructuralProcessState(): StructuralProcessState {
16
28
  return {
17
29
  semanticEntryRefs: createEmptyProcessSemanticEntryRefs(),
@@ -19,11 +31,9 @@ export function createEmptyStructuralProcessState(): StructuralProcessState {
19
31
  };
20
32
  }
21
33
 
34
+ /** @public */
22
35
  export function parseStructuralProcessState(value: unknown): StructuralProcessState {
23
- if (typeof value !== "object" || value === null || Array.isArray(value)) {
24
- return createEmptyStructuralProcessState();
25
- }
26
- const record = value as Record<string, unknown>;
36
+ const record = asUnknownRecord(value) ?? {};
27
37
  return {
28
38
  semanticEntryRefs: parseProcessSemanticEntryRefs(record.semanticEntryRefs),
29
39
  productRefs: parseProcessProductRefs(record.productRefs),
@@ -4,10 +4,13 @@ import {
4
4
  WORKER_SNAPSHOT_TOKEN_ENV,
5
5
  } from "@leitwerk-dev/worker-protocol";
6
6
 
7
+ /** @public */
7
8
  export type SubprocessEnvInput = Record<string, string | undefined>;
8
9
 
9
10
  export const INTERNAL_REPOSITORY_GIT_SSH_ENV_PREFIX = "LEITWERK_INTERNAL_REPOSITORY_GIT_SSH_";
11
+ export const INTERNAL_REPOSITORY_GIT_HTTPS_ENV_PREFIX = "LEITWERK_INTERNAL_REPOSITORY_GIT_HTTPS_";
10
12
 
13
+ /** @internal */
11
14
  export const WORKER_SUBPROCESS_SENSITIVE_ENV_KEYS = [
12
15
  WORKER_IPC_CONNECT_TOKEN_ENV,
13
16
  WORKER_IPC_RECONNECT_ENV,
@@ -20,6 +23,8 @@ const SENSITIVE_ENV_KEYS = new Set<string>([
20
23
  "SSH_AGENT_PID",
21
24
  "GIT_SSH",
22
25
  "GIT_SSH_COMMAND",
26
+ "GIT_ASKPASS",
27
+ "SSH_ASKPASS",
23
28
  ]);
24
29
 
25
30
  /**
@@ -29,6 +34,7 @@ const SENSITIVE_ENV_KEYS = new Set<string>([
29
34
  * process itself. Repository scripts, git hooks, package managers, and other
30
35
  * tool subprocesses must not receive them.
31
36
  */
37
+ /** @internal */
32
38
  export function sanitizeWorkerSubprocessEnv(
33
39
  baseEnv: SubprocessEnvInput = process.env,
34
40
  overrides: SubprocessEnvInput = {},
@@ -38,6 +44,9 @@ export function sanitizeWorkerSubprocessEnv(
38
44
  if (
39
45
  SENSITIVE_ENV_KEYS.has(key) ||
40
46
  key.startsWith(INTERNAL_REPOSITORY_GIT_SSH_ENV_PREFIX) ||
47
+ key.startsWith(INTERNAL_REPOSITORY_GIT_HTTPS_ENV_PREFIX) ||
48
+ key.startsWith("GIT_CONFIG_") ||
49
+ /(?:^|_)(?:TOKEN|API_KEY|PASSWORD|SECRET)$/.test(key) ||
41
50
  value === undefined
42
51
  ) {
43
52
  continue;
@@ -0,0 +1,39 @@
1
+ /** Object parameters for a tool bound to a current process project. @public */
2
+ export function projectParameters(
3
+ properties: Record<string, unknown> = {},
4
+ required: readonly string[] = Object.keys(properties),
5
+ ): Record<string, unknown> {
6
+ return {
7
+ type: "object",
8
+ properties: {
9
+ projectKey: { type: "string", description: "Current process project key" },
10
+ ...properties,
11
+ },
12
+ required: ["projectKey", ...required],
13
+ };
14
+ }
15
+
16
+ /** @internal */
17
+ export function objectArg(
18
+ value: unknown,
19
+ message = "Tool arguments must be an object",
20
+ ): Record<string, unknown> {
21
+ if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error(message);
22
+ return value as Record<string, unknown>;
23
+ }
24
+
25
+ /** Read required integration-tool arguments at the runtime boundary. @internal */
26
+ export function stringArg(args: Record<string, unknown>, name: string): string {
27
+ const value = args[name];
28
+ if (typeof value !== "string" || !value.trim())
29
+ throw new Error(`'${name}' must be a non-empty string`);
30
+ return value.trim();
31
+ }
32
+
33
+ /** @internal */
34
+ export function numberArg(args: Record<string, unknown>, name: string): number {
35
+ const value = args[name];
36
+ if (typeof value !== "number" || !Number.isInteger(value) || value <= 0)
37
+ throw new Error(`'${name}' must be a positive integer`);
38
+ return value;
39
+ }
@@ -17,9 +17,12 @@ export {
17
17
  type ToolCallRendererValueSource,
18
18
  };
19
19
 
20
+ /** @internal */
20
21
  export const MARKDOWN_RESULT_TOOL_NAME = "markdown_result";
22
+ /** @internal */
21
23
  export const MARKDOWN_RESULT_TOOL_MARKDOWN_PATH = "markdown";
22
24
 
25
+ /** @internal */
23
26
  export const MARKDOWN_RESULT_TOOL_RENDERER: ToolCallRendererDefinition = {
24
27
  toolName: MARKDOWN_RESULT_TOOL_NAME,
25
28
  title: "Markdown result",
@@ -34,10 +37,12 @@ export const MARKDOWN_RESULT_TOOL_RENDERER: ToolCallRendererDefinition = {
34
37
  ],
35
38
  };
36
39
 
40
+ /** @internal */
37
41
  export const CORE_TOOL_CALL_RENDERERS: readonly ToolCallRendererDefinition[] = [
38
42
  MARKDOWN_RESULT_TOOL_RENDERER,
39
43
  ];
40
44
 
45
+ /** @public */
41
46
  export const REQUIRED_MARKDOWN_RESULT_TURN_RESULT: TurnResultMarkdownBehavior = {
42
47
  mode: "tool_call",
43
48
  toolName: MARKDOWN_RESULT_TOOL_NAME,
@@ -49,6 +54,7 @@ function isNonEmptyString(value: unknown): value is string {
49
54
  return typeof value === "string" && value.trim() !== "";
50
55
  }
51
56
 
57
+ /** @internal */
52
58
  export function validateToolCallRendererDefinition(def: ToolCallRendererDefinition): string[] {
53
59
  const errors: string[] = [];
54
60
  if (!isNonEmptyString(def.toolName)) {
@@ -1,7 +1,5 @@
1
1
  import {
2
2
  assertValidProcessProductName,
3
- defaultProcessTurnStartSelection,
4
- type ProcessTurnStartFallback,
5
3
  type ProcessTurnStartSelection,
6
4
  resolveProcessTurnStartSelection,
7
5
  } from "@leitwerk-dev/domain";
@@ -11,7 +9,6 @@ import type {
11
9
  HumanTurnDefinition,
12
10
  LlmTurnDefinition,
13
11
  ProcessToolOutcomeSpec,
14
- ServerAutomaticTurnDefinition,
15
12
  TurnDefinition,
16
13
  } from "./define-process.js";
17
14
  import { llmTurn, resolveHumanTurnView } from "./define-process.js";
@@ -22,49 +19,44 @@ import {
22
19
  type ProcessActionPreviewDefinition,
23
20
  type ProcessActionSchedulingDefinition,
24
21
  RESERVED_INTEGRATION_TOOL_NAMES,
25
- type TurnBranchType,
26
22
  } from "./types.js";
27
23
 
24
+ /** @internal */
28
25
  export function isLlmTurnDefinition<TParams = unknown, TState = unknown>(
29
26
  turnDef: TurnDefinition<TParams, TState>,
30
27
  ): turnDef is LlmTurnDefinition<string, TParams, TState> {
31
28
  return turnDef.kind === "llm";
32
29
  }
33
30
 
31
+ /** @internal */
34
32
  export function isAutomaticTurnDefinition<TParams = unknown, TState = unknown>(
35
33
  turnDef: TurnDefinition<TParams, TState>,
36
34
  ): turnDef is AutomaticTurnDefinition<string, TParams, TState> {
37
35
  return turnDef.kind === "automatic";
38
36
  }
39
37
 
40
- export function isServerAutomaticTurnDefinition<TParams = unknown, TState = unknown>(
41
- turnDef: TurnDefinition<TParams, TState>,
42
- ): turnDef is ServerAutomaticTurnDefinition<string, TParams, TState> {
43
- return turnDef.kind === "server_automatic";
44
- }
45
-
38
+ /** @internal */
46
39
  export function isHumanTurnDefinition<TParams = unknown, TState = unknown>(
47
40
  turnDef: TurnDefinition<TParams, TState>,
48
41
  ): turnDef is HumanTurnDefinition<TParams, TState> {
49
42
  return turnDef.kind === "human";
50
43
  }
51
44
 
45
+ /** @internal */
52
46
  export function isExternalTurnDefinition<TParams = unknown, TState = unknown>(
53
47
  turnDef: TurnDefinition<TParams, TState>,
54
48
  ): turnDef is ExternalTurnDefinition<TParams, TState> {
55
49
  return turnDef.kind === "external";
56
50
  }
57
51
 
58
- export function defaultTurnStartSelection(branchType: TurnBranchType): ProcessTurnStartFallback {
59
- return defaultProcessTurnStartSelection(branchType);
60
- }
61
-
52
+ /** @internal */
62
53
  export function resolveLlmTurnStartSelection<TOutcome extends string = string>(
63
54
  turnDef: Pick<LlmTurnDefinition<TOutcome>, "branchType" | "startFrom">,
64
55
  ): ProcessTurnStartSelection {
65
56
  return resolveProcessTurnStartSelection(turnDef);
66
57
  }
67
58
 
59
+ /** @internal */
68
60
  export function resolveLlmTurnRestorePrimaryLeafAfterTurn<TOutcome extends string = string>(
69
61
  turnDef: Pick<LlmTurnDefinition<TOutcome>, "branchType" | "restorePrimaryLeafAfterTurn">,
70
62
  ): boolean {
@@ -81,10 +73,7 @@ export function validateProcessActionPreviewDefinition(
81
73
  if (preview.kind === "trigger") {
82
74
  return preview.trigger.trim() ? [] : [`${context} must declare a non-empty trigger preview`];
83
75
  }
84
- if (preview.kind === "terminal") {
85
- return [];
86
- }
87
- if (preview.turnId === null || preview.turnId.trim()) {
76
+ if (preview.kind === "terminal" || preview.turnId === null || preview.turnId.trim()) {
88
77
  return [];
89
78
  }
90
79
  return [`${context} must declare a non-empty fixed turn id when turnId is not null`];
@@ -97,19 +86,28 @@ export function validateProcessActionSchedulingDefinition(
97
86
  return validateProcessActionPreviewDefinition(scheduling?.preview, context);
98
87
  }
99
88
 
100
- function hasDuplicateBy<TItem>(
89
+ function findDuplicateBy<TItem>(
101
90
  items: readonly TItem[],
102
91
  selectKey: (item: TItem) => string,
103
- ): boolean {
92
+ ): TItem | undefined {
104
93
  const ids = new Set<string>();
105
94
  for (const item of items) {
106
95
  const key = selectKey(item);
107
96
  if (ids.has(key)) {
108
- return true;
97
+ return item;
109
98
  }
110
99
  ids.add(key);
111
100
  }
112
- return false;
101
+ return undefined;
102
+ }
103
+
104
+ function validateProcessProductName(name: string): string[] {
105
+ try {
106
+ assertValidProcessProductName(name);
107
+ return [];
108
+ } catch (error) {
109
+ return [error instanceof Error ? error.message : String(error)];
110
+ }
113
111
  }
114
112
 
115
113
  function validateOutcomeTurnResultContract<TParams = unknown, TState = unknown>(
@@ -146,11 +144,7 @@ function validateOutcomeToolParameters<TParams = unknown, TState = unknown>(
146
144
  [string, ProcessToolOutcomeSpec<TParams, TState>]
147
145
  >) {
148
146
  if (outcomeSpec.publishedProduct) {
149
- try {
150
- assertValidProcessProductName(outcomeSpec.publishedProduct);
151
- } catch (error) {
152
- errors.push(error instanceof Error ? error.message : String(error));
153
- }
147
+ errors.push(...validateProcessProductName(outcomeSpec.publishedProduct));
154
148
  const parameterName = outcomeSpec.turnResultMarkdownParameter?.trim() ?? "";
155
149
  if (!parameterName) {
156
150
  errors.push(
@@ -212,11 +206,7 @@ function validateTurnStartSelection(
212
206
  errors.push(`LLM turn '${turnId}' ${context} entry id must be non-empty`);
213
207
  }
214
208
  if (startFrom.kind === "product_ref") {
215
- try {
216
- assertValidProcessProductName(startFrom.productName);
217
- } catch (error) {
218
- errors.push(error instanceof Error ? error.message : String(error));
219
- }
209
+ errors.push(...validateProcessProductName(startFrom.productName));
220
210
  }
221
211
  if ("fallback" in startFrom && startFrom.fallback) {
222
212
  errors.push(...validateTurnStartSelection(turnId, startFrom.fallback, `${context} fallback`));
@@ -224,6 +214,7 @@ function validateTurnStartSelection(
224
214
  return errors;
225
215
  }
226
216
 
217
+ /** @internal */
227
218
  export function validateLlmTurnDefinition<
228
219
  TOutcome extends string = string,
229
220
  TParams = unknown,
@@ -334,27 +325,19 @@ export function validateLlmTurnDefinition<
334
325
  return errors;
335
326
  }
336
327
 
328
+ /** @internal */
337
329
  export function validateAutomaticTurnDefinition<
338
330
  TOutcome extends string = string,
339
331
  TParams = unknown,
340
332
  TState = unknown,
341
- >(
342
- turnId: string,
343
- turnDef:
344
- | AutomaticTurnDefinition<TOutcome, TParams, TState>
345
- | ServerAutomaticTurnDefinition<TOutcome, TParams, TState>,
346
- ): string[] {
347
- const errors: string[] = [];
348
- const declaredOutcomes = turnDef.outcomes;
349
- const declaredTurnEnd = turnDef.turnEnd;
350
- errors.push(
351
- ...validateOutcomeTurnResultContract("Automatic", turnId, declaredOutcomes, declaredTurnEnd),
352
- );
353
- errors.push(...validateOutcomeToolParameters("Automatic", turnId, declaredOutcomes));
354
-
355
- return errors;
333
+ >(turnId: string, turnDef: AutomaticTurnDefinition<TOutcome, TParams, TState>): string[] {
334
+ return [
335
+ ...validateOutcomeTurnResultContract("Automatic", turnId, turnDef.outcomes, turnDef.turnEnd),
336
+ ...validateOutcomeToolParameters("Automatic", turnId, turnDef.outcomes),
337
+ ];
356
338
  }
357
339
 
340
+ /** @internal */
358
341
  export function validateHumanTurnDefinition<TParams = unknown, TState = unknown>(
359
342
  turnId: string,
360
343
  turnDef: HumanTurnDefinition<TParams, TState>,
@@ -367,11 +350,7 @@ export function validateHumanTurnDefinition<TParams = unknown, TState = unknown>
367
350
  errors.push(error instanceof Error ? error.message : String(error));
368
351
  }
369
352
  if (turnDef.reviewProduct) {
370
- try {
371
- assertValidProcessProductName(turnDef.reviewProduct);
372
- } catch (error) {
373
- errors.push(error instanceof Error ? error.message : String(error));
374
- }
353
+ errors.push(...validateProcessProductName(turnDef.reviewProduct));
375
354
  }
376
355
 
377
356
  const actionEntries = Object.entries(turnDef.actions) as Array<
@@ -395,10 +374,10 @@ export function validateHumanTurnDefinition<TParams = unknown, TState = unknown>
395
374
  const externalTriggers = actionEntries.flatMap(([actionId, action]) =>
396
375
  (action.externalTriggers ?? []).map((trigger) => ({ actionId, trigger })),
397
376
  );
398
- if (hasDuplicateBy(externalTriggers, ({ trigger }) => trigger.id)) {
377
+ if (findDuplicateBy(externalTriggers, ({ trigger }) => trigger.id) !== undefined) {
399
378
  errors.push(`Human turn '${turnId}' contains duplicate external trigger ids`);
400
379
  }
401
- if (hasDuplicateBy(externalTriggers, ({ actionId }) => actionId)) {
380
+ if (findDuplicateBy(externalTriggers, ({ actionId }) => actionId) !== undefined) {
402
381
  errors.push(`Human turn '${turnId}' contains duplicate external trigger action ids`);
403
382
  }
404
383
  for (const { actionId, trigger } of externalTriggers) {
@@ -422,11 +401,7 @@ export function validateHumanTurnDefinition<TParams = unknown, TState = unknown>
422
401
  }
423
402
  }
424
403
 
425
- const externalActionEntries = Object.entries(turnDef.externalActions ?? {});
426
- if (hasDuplicateBy(externalActionEntries, ([externalActionId]) => externalActionId)) {
427
- errors.push(`Human turn '${turnId}' contains duplicate external action ids`);
428
- }
429
- for (const [externalActionId, externalAction] of externalActionEntries) {
404
+ for (const [externalActionId, externalAction] of Object.entries(turnDef.externalActions ?? {})) {
430
405
  if (externalActionId.trim() === "") {
431
406
  errors.push(`Human turn '${turnId}' contains an external action with an empty id`);
432
407
  }
@@ -450,11 +425,7 @@ export function validateHumanTurnDefinition<TParams = unknown, TState = unknown>
450
425
  );
451
426
  }
452
427
  if (externalAction.publishInput) {
453
- try {
454
- assertValidProcessProductName(externalAction.publishInput.productName);
455
- } catch (error) {
456
- errors.push(error instanceof Error ? error.message : String(error));
457
- }
428
+ errors.push(...validateProcessProductName(externalAction.publishInput.productName));
458
429
  if (externalAction.publishInput.inputField.trim() === "") {
459
430
  errors.push(
460
431
  `Human turn '${turnId}' external action '${externalActionId}' publishInput must declare a non-empty inputField`,
@@ -468,21 +439,15 @@ export function validateHumanTurnDefinition<TParams = unknown, TState = unknown>
468
439
  }
469
440
  }
470
441
 
471
- const notesFields = turnDef.notesFields ?? [];
472
- if (hasDuplicateBy(notesFields, (field) => field.id)) {
473
- const noteIds = new Set<string>();
474
- for (const field of notesFields) {
475
- if (noteIds.has(field.id)) {
476
- errors.push(`Human turn '${turnId}' contains duplicate notes field id '${field.id}'`);
477
- break;
478
- }
479
- noteIds.add(field.id);
480
- }
442
+ const duplicateNote = findDuplicateBy(turnDef.notesFields ?? [], (field) => field.id);
443
+ if (duplicateNote !== undefined) {
444
+ errors.push(`Human turn '${turnId}' contains duplicate notes field id '${duplicateNote.id}'`);
481
445
  }
482
446
 
483
447
  return errors;
484
448
  }
485
449
 
450
+ /** @internal */
486
451
  export function validateExternalTurnDefinition<TParams = unknown, TState = unknown>(
487
452
  turnId: string,
488
453
  turnDef: ExternalTurnDefinition<TParams, TState>,
@@ -510,13 +475,16 @@ export function validateExternalTurnDefinition<TParams = unknown, TState = unkno
510
475
  return errors;
511
476
  }
512
477
 
478
+ /** @internal */
513
479
  export function validateTurnDefinition<TParams = unknown, TState = unknown>(
514
480
  turnId: string,
515
481
  turnDef: TurnDefinition<TParams, TState>,
516
482
  ): string[];
483
+ /** @internal */
517
484
  export function validateTurnDefinition<TParams = unknown, TState = unknown>(
518
485
  turnDef: TurnDefinition<TParams, TState>,
519
486
  ): string[];
487
+ /** @internal */
520
488
  export function validateTurnDefinition<TParams = unknown, TState = unknown>(
521
489
  turnIdOrDef: string | TurnDefinition<TParams, TState>,
522
490
  turnDef?: TurnDefinition<TParams, TState>,
@@ -531,14 +499,14 @@ export function validateTurnDefinition<TParams = unknown, TState = unknown>(
531
499
  }
532
500
  return isLlmTurnDefinition(effectiveTurnDef)
533
501
  ? validateLlmTurnDefinition(effectiveTurnId, effectiveTurnDef)
534
- : isAutomaticTurnDefinition(effectiveTurnDef) ||
535
- isServerAutomaticTurnDefinition(effectiveTurnDef)
502
+ : isAutomaticTurnDefinition(effectiveTurnDef)
536
503
  ? validateAutomaticTurnDefinition(effectiveTurnId, effectiveTurnDef)
537
504
  : isHumanTurnDefinition(effectiveTurnDef)
538
505
  ? validateHumanTurnDefinition(effectiveTurnId, effectiveTurnDef)
539
506
  : validateExternalTurnDefinition(effectiveTurnId, effectiveTurnDef);
540
507
  }
541
508
 
509
+ /** @internal */
542
510
  export function assertValidLlmTurnDefinition<
543
511
  TOutcome extends string = string,
544
512
  TParams = unknown,
@@ -547,6 +515,7 @@ export function assertValidLlmTurnDefinition<
547
515
  assertNoValidationErrors(validateLlmTurnDefinition(turnId, turnDef));
548
516
  }
549
517
 
518
+ /** @internal */
550
519
  export function createRootBranchReviewTurn<
551
520
  TOutcome extends string,
552
521
  TParams = unknown,