@leitwerk-dev/server 0.1.7 → 0.1.9

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 (192) hide show
  1. package/dist/app.d.ts.map +1 -1
  2. package/dist/app.js +24 -15
  3. package/dist/app.js.map +1 -1
  4. package/dist/{chunk-GIWHTJSL.js → chunk-2ESDXLNE.js} +228 -101
  5. package/dist/chunk-2ESDXLNE.js.map +1 -0
  6. package/dist/{chunk-OO6VH4FX.js → chunk-DFHOPJRZ.js} +405 -259
  7. package/dist/chunk-DFHOPJRZ.js.map +1 -0
  8. package/dist/config/config-loader.d.ts.map +1 -1
  9. package/dist/config/config-loader.js +14 -25
  10. package/dist/config/config-loader.js.map +1 -1
  11. package/dist/config/config-types.d.ts +5 -17
  12. package/dist/config/config-types.d.ts.map +1 -1
  13. package/dist/db/skill-repo.d.ts +2 -2
  14. package/dist/db/skill-repo.d.ts.map +1 -1
  15. package/dist/db/skill-repo.js +24 -32
  16. package/dist/db/skill-repo.js.map +1 -1
  17. package/dist/external-source-service.d.ts.map +1 -1
  18. package/dist/external-source-service.js +5 -2
  19. package/dist/external-source-service.js.map +1 -1
  20. package/dist/future-execution/execution.d.ts +1 -1
  21. package/dist/future-execution/execution.d.ts.map +1 -1
  22. package/dist/future-execution/execution.js +1 -13
  23. package/dist/future-execution/execution.js.map +1 -1
  24. package/dist/integration-tool-registry.js +1 -1
  25. package/dist/integration-tool-registry.js.map +1 -1
  26. package/dist/model-providers/builtin-server-adapter.d.ts.map +1 -1
  27. package/dist/model-providers/builtin-server-adapter.js +10 -2
  28. package/dist/model-providers/builtin-server-adapter.js.map +1 -1
  29. package/dist/process-action-registry.d.ts +2 -4
  30. package/dist/process-action-registry.d.ts.map +1 -1
  31. package/dist/process-action-registry.js +31 -28
  32. package/dist/process-action-registry.js.map +1 -1
  33. package/dist/process-engine/engine.d.ts.map +1 -1
  34. package/dist/process-engine/engine.js +4 -4
  35. package/dist/process-engine/engine.js.map +1 -1
  36. package/dist/process-engine/operation.d.ts +4 -0
  37. package/dist/process-engine/operation.d.ts.map +1 -1
  38. package/dist/process-engine/ops/execute-action.d.ts.map +1 -1
  39. package/dist/process-engine/ops/execute-action.js +0 -3
  40. package/dist/process-engine/ops/execute-action.js.map +1 -1
  41. package/dist/process-engine/ops/worker-failure.d.ts +2 -0
  42. package/dist/process-engine/ops/worker-failure.d.ts.map +1 -1
  43. package/dist/process-engine/ops/worker-failure.js +2 -0
  44. package/dist/process-engine/ops/worker-failure.js.map +1 -1
  45. package/dist/process-engine/runner.d.ts +2 -2
  46. package/dist/process-engine/runner.d.ts.map +1 -1
  47. package/dist/process-engine/runner.js +13 -1
  48. package/dist/process-engine/runner.js.map +1 -1
  49. package/dist/process-engine/types.d.ts +10 -4
  50. package/dist/process-engine/types.d.ts.map +1 -1
  51. package/dist/process-engine/writes/build-server-transition-writes.d.ts.map +1 -1
  52. package/dist/process-engine/writes/build-server-transition-writes.js +2 -8
  53. package/dist/process-engine/writes/build-server-transition-writes.js.map +1 -1
  54. package/dist/process-engine/writes/build-turn-outcome-writes.d.ts.map +1 -1
  55. package/dist/process-engine/writes/build-turn-outcome-writes.js +1 -2
  56. package/dist/process-engine/writes/build-turn-outcome-writes.js.map +1 -1
  57. package/dist/process-engine/writes/build-turn-selection-writes.d.ts +1 -2
  58. package/dist/process-engine/writes/build-turn-selection-writes.d.ts.map +1 -1
  59. package/dist/process-engine/writes/build-turn-selection-writes.js +1 -57
  60. package/dist/process-engine/writes/build-turn-selection-writes.js.map +1 -1
  61. package/dist/process-engine/writes/build-worker-failure-writes.d.ts +3 -1
  62. package/dist/process-engine/writes/build-worker-failure-writes.d.ts.map +1 -1
  63. package/dist/process-engine/writes/build-worker-failure-writes.js +2 -1
  64. package/dist/process-engine/writes/build-worker-failure-writes.js.map +1 -1
  65. package/dist/process-launch-executor.d.ts +6 -4
  66. package/dist/process-launch-executor.d.ts.map +1 -1
  67. package/dist/process-launch-executor.js +16 -1
  68. package/dist/process-launch-executor.js.map +1 -1
  69. package/dist/process-launch-plan.d.ts.map +1 -1
  70. package/dist/process-launch-plan.js +1 -0
  71. package/dist/process-launch-plan.js.map +1 -1
  72. package/dist/process-operator-attention.d.ts +1 -1
  73. package/dist/process-operator-attention.d.ts.map +1 -1
  74. package/dist/process-operator-attention.js +1 -1
  75. package/dist/process-operator-attention.js.map +1 -1
  76. package/dist/process-ui-snapshot-presenter.d.ts.map +1 -1
  77. package/dist/process-ui-snapshot-presenter.js +24 -3
  78. package/dist/process-ui-snapshot-presenter.js.map +1 -1
  79. package/dist/process-watcher-registry.d.ts.map +1 -1
  80. package/dist/process-watcher-registry.js +13 -5
  81. package/dist/process-watcher-registry.js.map +1 -1
  82. package/dist/routes/skills.d.ts.map +1 -1
  83. package/dist/routes/skills.js +1 -2
  84. package/dist/routes/skills.js.map +1 -1
  85. package/dist/server-automatic-turn-drainer.d.ts.map +1 -1
  86. package/dist/server-automatic-turn-drainer.js +15 -0
  87. package/dist/server-automatic-turn-drainer.js.map +1 -1
  88. package/dist/server-bootstrap/build-host-capabilities.d.ts.map +1 -1
  89. package/dist/server-bootstrap/build-host-capabilities.js +1 -0
  90. package/dist/server-bootstrap/build-host-capabilities.js.map +1 -1
  91. package/dist/skills/skill-frontmatter.d.ts +4 -0
  92. package/dist/skills/skill-frontmatter.d.ts.map +1 -0
  93. package/dist/skills/skill-frontmatter.js +13 -0
  94. package/dist/skills/skill-frontmatter.js.map +1 -0
  95. package/dist/skills/source-importer.d.ts +2 -3
  96. package/dist/skills/source-importer.d.ts.map +1 -1
  97. package/dist/skills/source-importer.js +16 -62
  98. package/dist/skills/source-importer.js.map +1 -1
  99. package/dist/supervisor/accepted-turn-start-replay.d.ts +9 -0
  100. package/dist/supervisor/accepted-turn-start-replay.d.ts.map +1 -0
  101. package/dist/supervisor/accepted-turn-start-replay.js +23 -0
  102. package/dist/supervisor/accepted-turn-start-replay.js.map +1 -0
  103. package/dist/supervisor/ipc-handler.d.ts +9 -0
  104. package/dist/supervisor/ipc-handler.d.ts.map +1 -1
  105. package/dist/supervisor/ipc-handler.js +9 -4
  106. package/dist/supervisor/ipc-handler.js.map +1 -1
  107. package/dist/supervisor/stale-heartbeat-watchdog.d.ts +1 -1
  108. package/dist/supervisor/stale-heartbeat-watchdog.d.ts.map +1 -1
  109. package/dist/supervisor/stale-heartbeat-watchdog.js +47 -5
  110. package/dist/supervisor/stale-heartbeat-watchdog.js.map +1 -1
  111. package/dist/supervisor/worker-event-ingestor.d.ts.map +1 -1
  112. package/dist/supervisor/worker-event-ingestor.js +16 -0
  113. package/dist/supervisor/worker-event-ingestor.js.map +1 -1
  114. package/dist/supervisor/worker-start-payload-builder.d.ts +2 -4
  115. package/dist/supervisor/worker-start-payload-builder.d.ts.map +1 -1
  116. package/dist/supervisor/worker-start-payload-builder.js +3 -1
  117. package/dist/supervisor/worker-start-payload-builder.js.map +1 -1
  118. package/dist/supervisor/worker-supervisor.d.ts +4 -5
  119. package/dist/supervisor/worker-supervisor.d.ts.map +1 -1
  120. package/dist/supervisor/worker-supervisor.js +31 -0
  121. package/dist/supervisor/worker-supervisor.js.map +1 -1
  122. package/dist/supervisor/worker-turn-ipc-recorder.d.ts +12 -3
  123. package/dist/supervisor/worker-turn-ipc-recorder.d.ts.map +1 -1
  124. package/dist/supervisor/worker-turn-ipc-recorder.js +129 -33
  125. package/dist/supervisor/worker-turn-ipc-recorder.js.map +1 -1
  126. package/dist/supervisor/worker-websocket-ipc.d.ts.map +1 -1
  127. package/dist/supervisor/worker-websocket-ipc.js +20 -10
  128. package/dist/supervisor/worker-websocket-ipc.js.map +1 -1
  129. package/dist/test-helpers/fake-worker-supervisor.d.ts.map +1 -1
  130. package/dist/test-helpers/fake-worker-supervisor.js +4 -0
  131. package/dist/test-helpers/fake-worker-supervisor.js.map +1 -1
  132. package/dist/test-helpers/ipc-handler-harness.d.ts.map +1 -1
  133. package/dist/test-helpers/ipc-handler-harness.js +1 -20
  134. package/dist/test-helpers/ipc-handler-harness.js.map +1 -1
  135. package/dist/test-helpers/process-fixtures.d.ts +1 -1
  136. package/dist/test-helpers/process-fixtures.d.ts.map +1 -1
  137. package/dist/test-helpers/process-fixtures.js +0 -6
  138. package/dist/test-helpers/process-fixtures.js.map +1 -1
  139. package/dist/turn-progress.d.ts +12 -0
  140. package/dist/turn-progress.d.ts.map +1 -0
  141. package/dist/turn-progress.js +108 -0
  142. package/dist/turn-progress.js.map +1 -0
  143. package/dist/{writes-DUwQe8MD.d.ts → writes-DNXpryd0.d.ts} +68 -36
  144. package/package.json +10 -10
  145. package/src/app.ts +25 -15
  146. package/src/config/config-loader.ts +33 -25
  147. package/src/config/config-types.ts +6 -13
  148. package/src/db/skill-repo.ts +26 -36
  149. package/src/external-source-service.ts +5 -2
  150. package/src/future-execution/execution.ts +2 -13
  151. package/src/integration-tool-registry.ts +1 -1
  152. package/src/model-providers/builtin-server-adapter.ts +10 -2
  153. package/src/process-action-registry.ts +48 -40
  154. package/src/process-engine/engine.ts +6 -4
  155. package/src/process-engine/operation.ts +5 -0
  156. package/src/process-engine/ops/execute-action.ts +0 -3
  157. package/src/process-engine/ops/worker-failure.ts +4 -0
  158. package/src/process-engine/runner.ts +13 -0
  159. package/src/process-engine/types.ts +14 -2
  160. package/src/process-engine/writes/build-server-transition-writes.ts +1 -14
  161. package/src/process-engine/writes/build-turn-outcome-writes.ts +1 -2
  162. package/src/process-engine/writes/build-turn-selection-writes.ts +0 -75
  163. package/src/process-engine/writes/build-worker-failure-writes.ts +4 -1
  164. package/src/process-launch-executor.ts +24 -15
  165. package/src/process-launch-plan.ts +1 -0
  166. package/src/process-operator-attention.ts +7 -3
  167. package/src/process-ui-snapshot-presenter.ts +24 -6
  168. package/src/process-watcher-registry.ts +15 -5
  169. package/src/routes/skills.ts +1 -3
  170. package/src/server-automatic-turn-drainer.ts +20 -1
  171. package/src/server-bootstrap/build-host-capabilities.ts +1 -0
  172. package/src/skills/skill-frontmatter.ts +13 -0
  173. package/src/skills/source-importer.ts +20 -82
  174. package/src/supervisor/accepted-turn-start-replay.ts +40 -0
  175. package/src/supervisor/ipc-handler.ts +18 -4
  176. package/src/supervisor/stale-heartbeat-watchdog.ts +55 -6
  177. package/src/supervisor/worker-event-ingestor.ts +15 -0
  178. package/src/supervisor/worker-start-payload-builder.ts +5 -2
  179. package/src/supervisor/worker-supervisor.ts +43 -4
  180. package/src/supervisor/worker-turn-ipc-recorder.ts +185 -46
  181. package/src/supervisor/worker-websocket-ipc.ts +28 -13
  182. package/src/test-helpers/fake-worker-supervisor.ts +4 -0
  183. package/src/test-helpers/ipc-handler-harness.ts +1 -22
  184. package/src/test-helpers/process-fixtures.ts +1 -6
  185. package/src/turn-progress.ts +114 -0
  186. package/dist/chunk-GIWHTJSL.js.map +0 -1
  187. package/dist/chunk-OO6VH4FX.js.map +0 -1
  188. package/dist/skills/catalog-sync.d.ts +0 -9
  189. package/dist/skills/catalog-sync.d.ts.map +0 -1
  190. package/dist/skills/catalog-sync.js +0 -7
  191. package/dist/skills/catalog-sync.js.map +0 -1
  192. package/src/skills/catalog-sync.ts +0 -13
@@ -1,9 +1,9 @@
1
1
  import type {
2
2
  ProcessInstance,
3
+ ProcessProject,
3
4
  ProcessSemanticEntryRefKey,
4
5
  ProcessTurnTerminalLifecycleStatus,
5
6
  ProcessTurnTransition,
6
- ReviewSubject,
7
7
  } from "@leitwerk-dev/domain";
8
8
  import type { ExtensionCatalog } from "@leitwerk-dev/extension-runtime";
9
9
  import type {
@@ -19,7 +19,9 @@ import type {
19
19
  } from "@leitwerk-dev/process-sdk";
20
20
  import {
21
21
  createServerProcessBuilder,
22
+ getExternalActionArmingId,
22
23
  getExternalSourceTransitionId,
24
+ isAutomaticTurnDefinition,
23
25
  isExternalTurnDefinition,
24
26
  isHumanTurnDefinition,
25
27
  resolveHumanTurnView,
@@ -39,7 +41,6 @@ export interface ResolvedUiHumanTurnAction {
39
41
  kind: "ui_human_action";
40
42
  turnId: string;
41
43
  turnType: "human";
42
- reviewSubject: ReviewSubject | null;
43
44
  semanticEntryRefKey: ProcessSemanticEntryRefKey | null;
44
45
  acceptanceState: TurnAcceptanceState;
45
46
  }
@@ -48,7 +49,6 @@ export interface ResolvedExternalHumanTriggerAction {
48
49
  kind: "external_human_trigger";
49
50
  turnId: string;
50
51
  turnType: "external";
51
- reviewSubject: ReviewSubject | null;
52
52
  semanticEntryRefKey: ProcessSemanticEntryRefKey | null;
53
53
  acceptanceState: TurnAcceptanceState;
54
54
  externalTrigger: { id: string; actionId: string; label: string; description: string };
@@ -84,7 +84,8 @@ export interface ProcessActionRegistry {
84
84
  listVisibleActions(processId: string, ctx: ServerProcessContext): VisibleProcessActionSummary[];
85
85
  getSelectedTurnSummary(
86
86
  processId: string,
87
- process: Pick<ProcessInstance, "selectedTurnId" | "paramsJson" | "stateJson">,
87
+ process: ProcessInstance,
88
+ projects?: readonly ProcessProject[],
88
89
  ): ProcessSelectedTurnSummary | null;
89
90
  getServerDefinition(processId: string): BuiltServerProcessDefinition | undefined;
90
91
  getTurnDefinition(
@@ -138,16 +139,6 @@ function getTurnReviewSemanticRef(
138
139
  return "reviewSemanticRef" in turnDef ? (turnDef.reviewSemanticRef ?? null) : null;
139
140
  }
140
141
 
141
- function getTurnReviewSubject(turnDef: TurnDefinition<unknown, unknown>): ReviewSubject | null {
142
- if (isHumanTurnDefinition(turnDef)) {
143
- return turnDef.reviewSubject ?? null;
144
- }
145
- if (isExternalTurnDefinition(turnDef)) {
146
- return turnDef.reviewSubject ?? null;
147
- }
148
- return turnDef.reviewSubject ?? null;
149
- }
150
-
151
142
  function getProcessTurnBinding(processDef: ExtensionProcessDefinition | undefined, turnId: string) {
152
143
  return processDef?.turns.get(turnId);
153
144
  }
@@ -165,23 +156,18 @@ function resolveCurrentTurnForProcess(
165
156
  return null;
166
157
  }
167
158
 
168
- const selectedTurnReviewSubject = getTurnReviewSubject(selectedTurn);
169
- if (!selectedTurnReviewSubject) {
170
- return { turnId: process.selectedTurnId, turnDef: selectedTurn };
171
- }
172
-
173
- const { state } = resolveProcessContextData(processDef, process);
174
- const currentReviewSubject =
175
- (state as { reviewSubject?: ReviewSubject | null }).reviewSubject ?? null;
176
- if (!currentReviewSubject || currentReviewSubject.kind === selectedTurnReviewSubject.kind) {
177
- return { turnId: process.selectedTurnId, turnDef: selectedTurn };
178
- }
179
- return null;
159
+ return { turnId: process.selectedTurnId, turnDef: selectedTurn };
180
160
  }
181
161
 
182
162
  function listExternalTriggers(
183
163
  turnId: string,
184
164
  turnDef: TurnDefinition<unknown, unknown>,
165
+ ctx: {
166
+ process: ProcessInstance;
167
+ projects: readonly ProcessProject[];
168
+ params: unknown;
169
+ state: unknown;
170
+ },
185
171
  ): ProcessExternalSourceSummary[] {
186
172
  if (isHumanTurnDefinition(turnDef)) {
187
173
  const view = resolveHumanTurnView({ turnId, turn: turnDef });
@@ -192,14 +178,19 @@ function listExternalTriggers(
192
178
  label: trigger.label,
193
179
  description: trigger.description,
194
180
  })),
195
- ...view.externalActions.map((action) => ({
196
- id: action.id,
197
- externalActionId: action.externalActionId,
198
- kind: action.sourceKind,
199
- sourceKind: action.sourceKind,
200
- label: action.label,
201
- description: action.description,
202
- })),
181
+ ...view.externalActions
182
+ .filter((action) => {
183
+ const definition = turnDef.externalActions?.[action.externalActionId];
184
+ return !definition?.when || definition.when(ctx);
185
+ })
186
+ .map((action) => ({
187
+ id: action.id,
188
+ externalActionId: action.externalActionId,
189
+ kind: action.sourceKind,
190
+ sourceKind: action.sourceKind,
191
+ label: action.label,
192
+ description: action.description,
193
+ })),
203
194
  ];
204
195
  }
205
196
  if (isExternalTurnDefinition(turnDef)) {
@@ -210,6 +201,18 @@ function listExternalTriggers(
210
201
  description: transition.source.description ?? null,
211
202
  }));
212
203
  }
204
+ if (isAutomaticTurnDefinition(turnDef) && ctx.process.lifecycleStatus === "waiting") {
205
+ return Object.entries(turnDef.externalActions ?? {})
206
+ .filter(([, action]) => !action.when || action.when(ctx))
207
+ .map(([externalActionId, action]) => ({
208
+ id: getExternalActionArmingId({ turnId, externalActionId }),
209
+ externalActionId,
210
+ kind: action.source.kind,
211
+ sourceKind: action.source.kind,
212
+ label: action.label ?? action.source.label ?? null,
213
+ description: action.description ?? action.source.description ?? null,
214
+ }));
215
+ }
213
216
  return [];
214
217
  }
215
218
 
@@ -249,12 +252,14 @@ function isTurnScopedActionForProcess(
249
252
 
250
253
  function buildSelectedTurnSummaryForProcess(
251
254
  processDef: ExtensionProcessDefinition | undefined,
252
- process: Pick<ProcessInstance, "selectedTurnId" | "paramsJson" | "stateJson">,
255
+ process: ProcessInstance,
256
+ projects: readonly ProcessProject[] = [],
253
257
  ): ProcessSelectedTurnSummary | null {
254
258
  const currentTurn = resolveCurrentTurnForProcess(processDef, process);
255
259
  if (!currentTurn) {
256
260
  return null;
257
261
  }
262
+ const { params, state } = resolveProcessContextData(processDef, process);
258
263
  return {
259
264
  turnId: currentTurn.turnId,
260
265
  kind: currentTurn.turnDef.kind,
@@ -262,7 +267,12 @@ function buildSelectedTurnSummaryForProcess(
262
267
  commentary: isHumanTurnDefinition(currentTurn.turnDef)
263
268
  ? (currentTurn.turnDef.commentary ?? null)
264
269
  : null,
265
- externalTriggers: listExternalTriggers(currentTurn.turnId, currentTurn.turnDef),
270
+ externalTriggers: listExternalTriggers(currentTurn.turnId, currentTurn.turnDef, {
271
+ process,
272
+ projects,
273
+ params,
274
+ state,
275
+ }),
266
276
  };
267
277
  }
268
278
 
@@ -423,7 +433,6 @@ function resolveTurnScopedActionForProcess(
423
433
  kind: "ui_human_action",
424
434
  turnId: currentTurn.turnId,
425
435
  turnType: "human",
426
- reviewSubject: currentTurn.turnDef.reviewSubject ?? null,
427
436
  semanticEntryRefKey: getTurnReviewSemanticRef(currentTurn.turnDef),
428
437
  acceptanceState: turnAction.acceptanceState,
429
438
  };
@@ -441,7 +450,6 @@ function resolveTurnScopedActionForProcess(
441
450
  kind: "external_human_trigger",
442
451
  turnId: currentTurn.turnId,
443
452
  turnType: "external",
444
- reviewSubject: currentTurn.turnDef.reviewSubject ?? null,
445
453
  semanticEntryRefKey: getTurnReviewSemanticRef(currentTurn.turnDef),
446
454
  acceptanceState: matchingVisibleAction.acceptanceState,
447
455
  externalTrigger: {
@@ -512,8 +520,8 @@ export function buildProcessActionRegistry(
512
520
  return visible;
513
521
  },
514
522
 
515
- getSelectedTurnSummary(processId, process) {
516
- return buildSelectedTurnSummaryForProcess(processDefs.get(processId), process);
523
+ getSelectedTurnSummary(processId, process, projects) {
524
+ return buildSelectedTurnSummaryForProcess(processDefs.get(processId), process, projects);
517
525
  },
518
526
 
519
527
  getServerDefinition(processId) {
@@ -191,12 +191,14 @@ export function createProcessEngine(deps: ProcessEngineDeps): ProcessEngine {
191
191
  return run(AcceptWorkerTurnStart, { instanceId, ...input });
192
192
  },
193
193
 
194
- async recordTurnOutcome(instanceId, payload) {
195
- return maybeBroadcastActionRequiredToast(await run(TurnOutcome, { instanceId, payload }));
194
+ async recordTurnOutcome(instanceId, payload, options) {
195
+ return maybeBroadcastActionRequiredToast(
196
+ await run(TurnOutcome, { instanceId, payload }, { afterRecord: options?.onRecorded }),
197
+ );
196
198
  },
197
199
 
198
- recordTurnFailed(instanceId, payload) {
199
- return run(TurnFailed, { instanceId, payload });
200
+ recordTurnFailed(instanceId, payload, options) {
201
+ return run(TurnFailed, { instanceId, payload }, { afterRecord: options?.onRecorded });
200
202
  },
201
203
 
202
204
  updateSemanticEntryRefs(instanceId, patch) {
@@ -53,3 +53,8 @@ export type OperationInput<TOp> =
53
53
 
54
54
  export type OperationData<TOp> =
55
55
  TOp extends OperationSpec<string, OperationInputBase, infer TData> ? TData : never;
56
+
57
+ export interface OperationRunOptions<TData> {
58
+ /** Runs after the transaction and process lock complete, before reactions are dispatched. */
59
+ afterRecord?: (data: TData) => void;
60
+ }
@@ -305,9 +305,6 @@ export const ExecuteAction = defineOperation<
305
305
  actionId: input.actionId,
306
306
  actionLabel,
307
307
  ...(sourceTurnRecordId ? { sourceTurnRecordId } : {}),
308
- ...(resolvedTurnAction.reviewSubject
309
- ? { reviewSubject: resolvedTurnAction.reviewSubject.kind }
310
- : {}),
311
308
  selectedTurnId: ctx.process.selectedTurnId,
312
309
  selectedTurnIdBefore: ctx.process.selectedTurnId,
313
310
  ...(causedSelectedTurnId
@@ -10,6 +10,8 @@ export interface WorkerFailureInput {
10
10
  message: string;
11
11
  errorClass?: import("@leitwerk-dev/domain").WorkerErrorClass;
12
12
  workerLeaseId?: string | null;
13
+ resultPiEntryId?: string | null;
14
+ recoveryContext?: import("@leitwerk-dev/domain").TurnFailedPayload["recoveryContext"];
13
15
  };
14
16
  }
15
17
 
@@ -86,6 +88,8 @@ export const WorkerFailure = defineOperation<"worker_failure", WorkerFailureInpu
86
88
  errorCode: input.payload.errorCode,
87
89
  errorClass: input.payload.errorClass,
88
90
  activeTurnRecord: runningTurnRecord,
91
+ resultPiEntryId: input.payload.resultPiEntryId,
92
+ recoveryContext: input.payload.recoveryContext,
89
93
  }),
90
94
  });
91
95
  },
@@ -10,6 +10,7 @@ import type {
10
10
  OperationInput,
11
11
  OperationInputBase,
12
12
  OperationMessages,
13
+ OperationRunOptions,
13
14
  OperationSpec,
14
15
  } from "./operation.js";
15
16
  import { dispatchReactions } from "./reactions.js";
@@ -89,6 +90,7 @@ export function createEngineRunner(
89
90
  return async function run<TOp extends OperationSpec<string, OperationInputBase, unknown>>(
90
91
  operation: TOp,
91
92
  input: OperationInput<TOp>,
93
+ runOptions: OperationRunOptions<OperationData<TOp>> = {},
92
94
  ): Promise<EngineResult<OperationData<TOp>>> {
93
95
  /**
94
96
  * Engine invariant: one operation for a process instance is serialized from
@@ -216,6 +218,17 @@ export function createEngineRunner(
216
218
  }
217
219
 
218
220
  const { recorded } = lockedOutcome;
221
+ try {
222
+ runOptions.afterRecord?.(recorded.data);
223
+ } catch (error) {
224
+ logProcessEngineError(deps.logger, {
225
+ err: error,
226
+ operationKind: operation.kind,
227
+ instanceId: input.instanceId,
228
+ stage: "post_commit",
229
+ code: "after_record_callback_failed",
230
+ });
231
+ }
219
232
  try {
220
233
  await deps.afterRecord?.(recorded.process);
221
234
  } catch (error) {
@@ -39,6 +39,7 @@ import type {
39
39
  OperationData,
40
40
  OperationInput,
41
41
  OperationInputBase,
42
+ OperationRunOptions,
42
43
  OperationSpec,
43
44
  } from "./operation.js";
44
45
  import type { Writes } from "./writes/writes.js";
@@ -192,6 +193,7 @@ export interface ProcessEngine {
192
193
  run<TOp extends OperationSpec<string, OperationInputBase, unknown>>(
193
194
  operation: TOp,
194
195
  input: OperationInput<TOp>,
196
+ options?: OperationRunOptions<OperationData<TOp>>,
195
197
  ): Promise<EngineResult<OperationData<TOp>>>;
196
198
 
197
199
  startProcess(
@@ -241,14 +243,24 @@ export interface ProcessEngine {
241
243
  message: string;
242
244
  errorClass?: WorkerErrorClass;
243
245
  workerLeaseId?: string | null;
246
+ resultPiEntryId?: string | null;
247
+ recoveryContext?: TurnFailedPayload["recoveryContext"];
244
248
  },
245
249
  ): Promise<EngineResult<void>>;
246
250
  acceptWorkerTurnStart(
247
251
  instanceId: string,
248
252
  input: { startRecordId: string; proposedTurnRecordId: string; workerLeaseId: string },
249
253
  ): Promise<EngineResult<{ turnRecordId: string }>>;
250
- recordTurnOutcome(instanceId: string, payload: TurnOutcomePayload): Promise<EngineResult<void>>;
251
- recordTurnFailed(instanceId: string, payload: TurnFailedPayload): Promise<EngineResult<void>>;
254
+ recordTurnOutcome(
255
+ instanceId: string,
256
+ payload: TurnOutcomePayload,
257
+ options?: { onRecorded?: () => void },
258
+ ): Promise<EngineResult<void>>;
259
+ recordTurnFailed(
260
+ instanceId: string,
261
+ payload: TurnFailedPayload,
262
+ options?: { onRecorded?: () => void },
263
+ ): Promise<EngineResult<void>>;
252
264
  updateSemanticEntryRefs(
253
265
  instanceId: string,
254
266
  patch: ProcessSemanticEntryRefPatch,
@@ -5,7 +5,6 @@ import { selectedTurnRequiresWorker } from "../turn-worker-requirement.js";
5
5
  import {
6
6
  buildTurnSelectionWrites,
7
7
  deriveLifecycleStatusForSelectedTurn,
8
- validateReviewSubjectTurnInvariant,
9
8
  } from "./build-turn-selection-writes.js";
10
9
  import {
11
10
  applyProcessPatchField,
@@ -96,18 +95,6 @@ export function buildServerTransitionWrites<TState = unknown>(
96
95
  ? (request.lifecycleStatus ?? process.lifecycleStatus)
97
96
  : targetLifecycleStatus;
98
97
 
99
- if (effectiveTargetTurnId !== undefined) {
100
- const reviewSubjectValidation = validateReviewSubjectTurnInvariant(
101
- processGraphs,
102
- process,
103
- effectiveTargetTurnId,
104
- request.state,
105
- );
106
- if (reviewSubjectValidation) {
107
- return reviewSubjectValidation;
108
- }
109
- }
110
-
111
98
  const resolvedWorkerIntent = resolveRuntimeWorkerIntent(
112
99
  processGraphs,
113
100
  process,
@@ -120,7 +107,7 @@ export function buildServerTransitionWrites<TState = unknown>(
120
107
  return resolvedWorkerIntent;
121
108
  }
122
109
 
123
- if (targetTurnId !== undefined && turnChanged) {
110
+ if (targetTurnId !== undefined) {
124
111
  const selectionWrites = buildTurnSelectionWrites(processGraphs, process, {
125
112
  fromTurnId: process.selectedTurnId,
126
113
  toTurnId: targetTurnId,
@@ -237,8 +237,7 @@ export async function buildTurnOutcomeWrites(
237
237
 
238
238
  if (
239
239
  candidateProcess.selectedTurnId === input.payload.turnId &&
240
- candidateProcess.lifecycleStatus !== "completed" &&
241
- candidateProcess.lifecycleStatus !== "aborted" &&
240
+ candidateProcess.lifecycleStatus === "active" &&
242
241
  !hasExplicitTurnSelectionChange(input.process, effectWrites)
243
242
  ) {
244
243
  const outcomeTransition = findOutcomeTransition(
@@ -1,5 +1,4 @@
1
1
  import {
2
- isWaitingTurnType,
3
2
  lifecycleStatusForSelectedTurnType,
4
3
  type ProcessInstance,
5
4
  type ProcessLifecycleStatus,
@@ -57,70 +56,6 @@ function validateTurnSelectionWorkerIntent(
57
56
  return null;
58
57
  }
59
58
 
60
- function parseReviewSubjectFromState(value: unknown) {
61
- if (typeof value !== "object" || value === null || Array.isArray(value)) {
62
- return null;
63
- }
64
- const reviewSubject = (value as Record<string, unknown>).reviewSubject;
65
- if (typeof reviewSubject !== "object" || reviewSubject === null || Array.isArray(reviewSubject)) {
66
- return null;
67
- }
68
- const kind = (reviewSubject as Record<string, unknown>).kind;
69
- return typeof kind === "string" ? { kind } : null;
70
- }
71
-
72
- function parseReviewSubjectFromStateJson(stateJson: string | null | undefined) {
73
- if (!stateJson) {
74
- return null;
75
- }
76
- try {
77
- return parseReviewSubjectFromState(JSON.parse(stateJson));
78
- } catch {
79
- return null;
80
- }
81
- }
82
-
83
- export function validateReviewSubjectTurnInvariant(
84
- processGraphs: ProcessGraphRegistry,
85
- process: Pick<ProcessInstance, "processId" | "selectedTurnId" | "lifecycleStatus" | "stateJson">,
86
- targetTurnId: TurnId | null,
87
- nextState: unknown = undefined,
88
- ): WriteBuildFailure | null {
89
- if (!targetTurnId) {
90
- return null;
91
- }
92
-
93
- const targetTurn = getProcessTurnGraph(processGraphs, process.processId, targetTurnId);
94
- if (!targetTurn?.reviewSubject) {
95
- return null;
96
- }
97
-
98
- const reviewSubject =
99
- nextState === undefined
100
- ? parseReviewSubjectFromStateJson(process.stateJson)
101
- : parseReviewSubjectFromState(nextState);
102
- if (isWaitingTurnType(targetTurn.turnType)) {
103
- if (reviewSubject?.kind === targetTurn.reviewSubject.kind) {
104
- return null;
105
- }
106
-
107
- return {
108
- ok: false,
109
- code: "invalid_transition",
110
- message: `Transition into '${targetTurnId}' requires reviewSubject.kind '${targetTurn.reviewSubject.kind}'`,
111
- };
112
- }
113
- if (reviewSubject) {
114
- return null;
115
- }
116
-
117
- return {
118
- ok: false,
119
- code: "invalid_transition",
120
- message: `Transition into '${targetTurnId}' requires a non-null reviewSubject`,
121
- };
122
- }
123
-
124
59
  export function deriveLifecycleStatusForSelectedTurn(
125
60
  processGraphs: ProcessGraphRegistry,
126
61
  processId: string,
@@ -191,16 +126,6 @@ export function buildTurnSelectionWrites(
191
126
  }
192
127
  }
193
128
 
194
- const reviewSubjectValidation = validateReviewSubjectTurnInvariant(
195
- processGraphs,
196
- process,
197
- input.toTurnId,
198
- input.state,
199
- );
200
- if (reviewSubjectValidation) {
201
- return reviewSubjectValidation;
202
- }
203
-
204
129
  const writes = createWrites({ workerIntent: input.workerIntent ?? { kind: "reconcile" } });
205
130
  applyProcessPatchField(writes, process, "selectedTurnId", input.toTurnId);
206
131
  applyProcessPatchField(writes, process, "lifecycleStatus", targetLifecycleStatus);
@@ -14,6 +14,8 @@ export interface WorkerFailureWritesInput {
14
14
  errorCode: string;
15
15
  errorClass?: WorkerErrorClass;
16
16
  activeTurnRecord?: ProcessTurnRecord | null;
17
+ resultPiEntryId?: string | null;
18
+ recoveryContext?: TurnFailedPayload["recoveryContext"];
17
19
  endedAt?: string;
18
20
  }
19
21
 
@@ -46,9 +48,10 @@ function toTurnFailedPayload(input: WorkerFailureWritesInput): TurnFailedPayload
46
48
  turnType: input.activeTurnRecord.turnType,
47
49
  pathType: input.activeTurnRecord.pathType,
48
50
  forkPiEntryId: input.activeTurnRecord.forkPiEntryId,
49
- resultPiEntryId: input.activeTurnRecord.resultPiEntryId,
51
+ resultPiEntryId: input.resultPiEntryId ?? input.activeTurnRecord.resultPiEntryId,
50
52
  errorSummary: input.message,
51
53
  errorClass: input.errorClass,
54
+ recoveryContext: input.recoveryContext,
52
55
  };
53
56
  }
54
57
 
@@ -30,6 +30,7 @@ export interface ProcessLaunchExecutorDeps
30
30
  RepositoryBundle,
31
31
  | "processes"
32
32
  | "projects"
33
+ | "skills"
33
34
  | "processSkills"
34
35
  | "handoffDedupKeys"
35
36
  | "futureExecutions"
@@ -41,8 +42,8 @@ export interface ProcessLaunchExecutorDeps
41
42
  extensionHost?: ExtensionHost;
42
43
  logger?: ProcessEngineLogger;
43
44
  getSupervisor?: () => undefined;
44
- processDefinitions?: ReadonlyMap<string, ExtensionProcessDefinition>;
45
45
  repositoryCredentials?: import("./repository-credentials/service.js").RepositoryCredentialService;
46
+ processDefinitions?: ReadonlyMap<string, ExtensionProcessDefinition>;
46
47
  commitMessages?: CommitMessageConfig;
47
48
  }
48
49
 
@@ -100,7 +101,7 @@ function mapLaunchStartFailure<T>(result: EngineFailure<T>): {
100
101
  }
101
102
 
102
103
  function createLaunchProjects(
103
- deps: Pick<ProcessLaunchExecutorDeps, "projects">,
104
+ deps: Pick<RepositoryBundle, "projects">,
104
105
  process: ProcessInstance,
105
106
  launchPlan: ProcessLaunchPlan,
106
107
  ): ProcessProject[] {
@@ -152,7 +153,7 @@ function toLaunchFailureBody(
152
153
  export type ProcessLaunchExecutionResult = ProcessLaunchExecutionResultLike;
153
154
 
154
155
  export function commitProcessLaunch(
155
- deps: ProcessLaunchExecutorDeps,
156
+ deps: Pick<RepositoryBundle, "transaction">,
156
157
  launchPlan: ProcessLaunchPlan,
157
158
  futureExecutionPlan?: FutureExecutionTransitionPlan,
158
159
  resourceSelections: readonly SkillSelection[] = [],
@@ -181,10 +182,7 @@ export function commitProcessLaunch(
181
182
  }
182
183
 
183
184
  function reuseDeduplicatedCommit(
184
- repos: Pick<
185
- ProcessLaunchExecutorDeps,
186
- "processes" | "projects" | "handoffDedupKeys" | "futureExecutions"
187
- >,
185
+ repos: Pick<RepositoryBundle, "processes" | "projects" | "handoffDedupKeys" | "futureExecutions">,
188
186
  dedupKey: string,
189
187
  futureExecutionPlan?: FutureExecutionTransitionPlan,
190
188
  ): ProcessLaunchCommit | null {
@@ -202,10 +200,7 @@ function reuseDeduplicatedCommit(
202
200
  }
203
201
 
204
202
  function createProcessLaunchCommit(
205
- repos: Pick<
206
- ProcessLaunchExecutorDeps,
207
- "processes" | "projects" | "processSkills" | "handoffDedupKeys"
208
- >,
203
+ repos: Pick<RepositoryBundle, "processes" | "projects" | "processSkills" | "handoffDedupKeys">,
209
204
  launchPlan: ProcessLaunchPlan,
210
205
  dedupKey: string | null,
211
206
  resourceSelections: readonly SkillSelection[],
@@ -315,13 +310,13 @@ export async function createScheduledProcessFromLaunchPlan(
315
310
  deps: ProcessLaunchExecutorDeps,
316
311
  launchPlan: ProcessLaunchPlan,
317
312
  futureExecutionPlan: FutureExecutionTransitionPlan,
318
- opts?: ProcessLaunchOptions,
313
+ opts: ProcessLaunchOptions & { resourceSelections: readonly SkillSelection[] },
319
314
  ): Promise<ProcessLaunchExecutionResult> {
320
315
  return createProcessFromLaunchPlanWithDisposition(deps, launchPlan, opts, futureExecutionPlan);
321
316
  }
322
317
 
323
318
  function recoverDeduplicatedCommit(
324
- deps: ProcessLaunchExecutorDeps,
319
+ deps: Pick<RepositoryBundle, "transaction">,
325
320
  dedupKey: string,
326
321
  futureExecutionPlan?: FutureExecutionTransitionPlan,
327
322
  ): ProcessLaunchCommit | null {
@@ -354,6 +349,20 @@ async function createProcessFromLaunchPlanWithDisposition(
354
349
  opts?: ProcessLaunchOptions,
355
350
  futureExecutionPlan?: FutureExecutionTransitionPlan,
356
351
  ): Promise<ProcessLaunchExecutionResult> {
352
+ let resourceSelections = opts?.resourceSelections;
353
+ if (!resourceSelections && launchPlan.skillIds) {
354
+ try {
355
+ resourceSelections = deps.skills.resolveActive(launchPlan.skillIds);
356
+ } catch (error) {
357
+ return {
358
+ ok: false,
359
+ stage: "pre_commit",
360
+ status: 400,
361
+ body: { error: error instanceof Error ? error.message : String(error) },
362
+ };
363
+ }
364
+ }
365
+ opts = { ...opts, resourceSelections: resourceSelections ?? [] };
357
366
  if (deps.repositoryCredentials) {
358
367
  try {
359
368
  deps.repositoryCredentials.validateLaunch({
@@ -376,8 +385,8 @@ async function createProcessFromLaunchPlanWithDisposition(
376
385
  deps,
377
386
  launchPlan,
378
387
  futureExecutionPlan,
379
- opts?.resourceSelections,
380
- opts?.launchIntent,
388
+ opts.resourceSelections,
389
+ opts.launchIntent,
381
390
  );
382
391
  } catch (error) {
383
392
  const dedupKey =
@@ -86,5 +86,6 @@ export function buildProcessLaunchPlan(input: BuildProcessLaunchPlanInput): Proc
86
86
  titleSourceFields: input.launchConfig.titleSourceFields?.map((field) => ({ ...field })),
87
87
  projectInputs: normalizeProjectInputs(input.launchConfig, input.commitMessages),
88
88
  startTurnId: input.launchConfig.startTurnId ?? null,
89
+ ...(input.launchConfig.skillIds ? { skillIds: [...input.launchConfig.skillIds] } : {}),
89
90
  };
90
91
  }
@@ -83,17 +83,21 @@ export function listVisibleActionsForProcess(
83
83
  }
84
84
 
85
85
  export function getSelectedTurnSummaryForProcess(
86
- deps: Pick<ProcessOperatorAttentionDeps, "processActionRegistry">,
86
+ deps: Pick<ProcessOperatorAttentionDeps, "processActionRegistry" | "projects">,
87
87
  process: ProcessInstance,
88
88
  ): ProcessSelectedTurnSummary | null {
89
89
  if (!deps.processActionRegistry) {
90
90
  return null;
91
91
  }
92
- return deps.processActionRegistry.getSelectedTurnSummary(process.processId, process);
92
+ return deps.processActionRegistry.getSelectedTurnSummary(
93
+ process.processId,
94
+ process,
95
+ deps.projects.listByInstance(process.id),
96
+ );
93
97
  }
94
98
 
95
99
  function getSelectedTurnDescription(
96
- deps: Pick<ProcessOperatorAttentionDeps, "processActionRegistry">,
100
+ deps: Pick<ProcessOperatorAttentionDeps, "processActionRegistry" | "projects">,
97
101
  process: ProcessInstance,
98
102
  ): string {
99
103
  const selectedTurnSummary = getSelectedTurnSummaryForProcess(deps, process);