@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
@@ -2,7 +2,6 @@ import {
2
2
  CONTINUE_PROMPT_METADATA_KEY,
3
3
  DEFAULT_CONTINUE_PROMPT,
4
4
  isProcessTurnType,
5
- isWorkerOwnedTurnType,
6
5
  normalizeContinuePrompt,
7
6
  type ProcessEvent,
8
7
  type ProcessInput,
@@ -60,6 +59,7 @@ import {
60
59
  processDefinesLeafOutcome,
61
60
  type RouteDeps,
62
61
  } from "./routes/process-route-helpers.js";
62
+ import { normalizeTurnProgressReport } from "./turn-progress.js";
63
63
 
64
64
  const COMPACT_DETAIL_EVENT_TYPES = [
65
65
  "turn_outcome_recorded",
@@ -83,9 +83,10 @@ function sortEventsAscending(events: readonly ProcessEvent[]): ProcessEvent[] {
83
83
  }
84
84
 
85
85
  function compactDetailEvents(deps: RouteDeps, instanceId: string): ProcessEvent[] {
86
- return sortEventsAscending(
87
- deps.events.listByInstanceEventTypes(instanceId, COMPACT_DETAIL_EVENT_TYPES, 1_000),
88
- );
86
+ return sortEventsAscending([
87
+ ...deps.events.listByInstanceEventTypes(instanceId, COMPACT_DETAIL_EVENT_TYPES, 1_000),
88
+ ...deps.events.listByInstanceEventTypes(instanceId, ["turn.progress"], 10_000),
89
+ ]);
89
90
  }
90
91
 
91
92
  function compactPrimaryPathSnapshot(snapshot: PrimaryPathSnapshot): PrimaryPathUiSnapshot {
@@ -331,6 +332,17 @@ function annotationOutput(annotation: ProcessTurnAnnotation): string {
331
332
 
332
333
  type TimelineActionSource = ProcessTimelineTurnSummary["actionSource"];
333
334
 
335
+ function buildTurnProgressIndex(events: readonly ProcessEvent[]) {
336
+ const index = new Map<string, NonNullable<ProcessTimelineTurnSummary["progress"]>>();
337
+ for (const event of events) {
338
+ if (event.eventType !== "turn.progress") continue;
339
+ const turnRecordId = stringValue(event.data.turnRecordId);
340
+ const report = normalizeTurnProgressReport(event.data.report);
341
+ if (turnRecordId && report) index.set(turnRecordId, report);
342
+ }
343
+ return index;
344
+ }
345
+
334
346
  function actionSourceFromAnnotation(annotation: ProcessTurnAnnotation): TimelineActionSource {
335
347
  const source = annotation.payload.actionSource;
336
348
  return source === "ui" || source === "external" || source === "scheduled" ? source : null;
@@ -416,6 +428,7 @@ function createCompletedTurnRecord(args: {
416
428
  turnResultMarkdown: string;
417
429
  createdAt: string;
418
430
  actionSource: TimelineActionSource;
431
+ progress: ProcessTimelineTurnSummary["progress"];
419
432
  }): ProcessTimelineTurnSummary {
420
433
  return {
421
434
  id: args.turnRecord.id,
@@ -432,6 +445,7 @@ function createCompletedTurnRecord(args: {
432
445
  status: "completed",
433
446
  modelProfileId: args.turnRecord.modelProfileId ?? null,
434
447
  actionSource: args.actionSource,
448
+ progress: args.progress,
435
449
  ...durableTurnLineage(args.turnRecord),
436
450
  };
437
451
  }
@@ -447,6 +461,7 @@ export function presentProcessTimelineTurns(input: {
447
461
  activeModelProfileId?: string | null;
448
462
  }): ProcessTimelineTurnSummary[] {
449
463
  const outcomeEventsByTurnRecordId = createTurnOutcomeEventMap(input.events);
464
+ const progressByTurnRecordId = buildTurnProgressIndex(input.events);
450
465
  const milestoneAnnotationsByTurnRecordId = createTurnAnnotationMap(
451
466
  input.turnAnnotations,
452
467
  "turn_milestone",
@@ -505,6 +520,7 @@ export function presentProcessTimelineTurns(input: {
505
520
  status: "in_progress",
506
521
  modelProfileId: turnRecord.modelProfileId ?? null,
507
522
  actionSource: actionSourceByTurnRecordId.get(turnRecord.id) ?? null,
523
+ progress: progressByTurnRecordId.get(turnRecord.id) ?? null,
508
524
  ...durableTurnLineage(turnRecord),
509
525
  });
510
526
  continue;
@@ -518,7 +534,7 @@ export function presentProcessTimelineTurns(input: {
518
534
  externalTriggerAnnotationsByTurnRecordId.get(turnRecord.id);
519
535
  let presentation: Omit<
520
536
  Parameters<typeof createCompletedTurnRecord>[0],
521
- "turnRecord" | "turnResultMarkdown" | "actionSource"
537
+ "turnRecord" | "turnResultMarkdown" | "actionSource" | "progress"
522
538
  >;
523
539
 
524
540
  if (outcomeEvent) {
@@ -573,6 +589,7 @@ export function presentProcessTimelineTurns(input: {
573
589
  turnRecord,
574
590
  turnResultMarkdown,
575
591
  actionSource: actionSourceByTurnRecordId.get(turnRecord.id) ?? null,
592
+ progress: progressByTurnRecordId.get(turnRecord.id) ?? null,
576
593
  }),
577
594
  );
578
595
  }
@@ -616,6 +633,7 @@ export function presentProcessTimelineTurns(input: {
616
633
  startedAt: input.process.updatedAt,
617
634
  endedAt: null,
618
635
  actionSource: null,
636
+ progress: null,
619
637
  });
620
638
  }
621
639
 
@@ -825,7 +843,6 @@ export function buildCurrentTurnRecovery(input: {
825
843
  if (
826
844
  !failedTurnRecord ||
827
845
  failedTurnRecord.status !== "failed" ||
828
- !isWorkerOwnedTurnType(failedTurnRecord.turnType) ||
829
846
  failedTurnRecord.turnId !== input.process.selectedTurnId
830
847
  ) {
831
848
  return null;
@@ -861,6 +878,7 @@ export function buildCurrentTurnRecovery(input: {
861
878
  recoveryContext?.suggestedContinuePrompt ??
862
879
  DEFAULT_CONTINUE_PROMPT,
863
880
  canContinue,
881
+ supportsModelOverride: failedTurnRecord.turnType === "llm",
864
882
  defaultModelProfileId: acceptedLlmStart?.model.profileId ?? failedTurnRecord.modelProfileId,
865
883
  providerOptions: acceptedLlmStart ? { ...acceptedLlmStart.providerOptions } : {},
866
884
  };
@@ -29,6 +29,7 @@ interface RegisteredProcessWatcher {
29
29
  presentation: ProcessWatcherPresentation;
30
30
  configPath: string;
31
31
  launchModelConfig: LaunchModelConfigInputLike;
32
+ launchSkillIds: readonly string[];
32
33
  }
33
34
 
34
35
  interface ProcessWatcherRegistryOptions {
@@ -50,7 +51,7 @@ function buildLaunchPlan(
50
51
  ): ProcessLaunchPlan {
51
52
  return buildProcessLaunchPlan({
52
53
  processDef: watcher.processDef,
53
- launchConfig,
54
+ launchConfig: { ...launchConfig, skillIds: watcher.launchSkillIds },
54
55
  launcherId: `${watcher.processId}.${watcher.definition.id}`,
55
56
  metadataAdditions: {
56
57
  processWatcherId: watcher.definition.id,
@@ -79,6 +80,14 @@ function parseConfiguredWatcher(input: {
79
80
  if (presentation.targetSummary.trim() === "") {
80
81
  throw new Error("presentConfig() must return a non-empty targetSummary");
81
82
  }
83
+ const parsedLaunch = parsed.launchModelConfig ?? {
84
+ defaultModelProfileId: null,
85
+ turnConfigs: {},
86
+ };
87
+ const launchModelConfig = {
88
+ defaultModelProfileId: parsedLaunch.defaultModelProfileId ?? null,
89
+ turnConfigs: parsedLaunch.turnConfigs ?? {},
90
+ };
82
91
  return {
83
92
  processId: input.processId,
84
93
  processDisplayName: input.processDisplayName,
@@ -88,10 +97,11 @@ function parseConfiguredWatcher(input: {
88
97
  enabled: parsed.enabled,
89
98
  presentation,
90
99
  configPath: input.configPath,
91
- launchModelConfig: parsed.launchModelConfig ?? {
92
- defaultModelProfileId: null,
93
- turnConfigs: {},
94
- },
100
+ launchModelConfig,
101
+ launchSkillIds:
102
+ "skillIds" in parsedLaunch && Array.isArray(parsedLaunch.skillIds)
103
+ ? parsedLaunch.skillIds
104
+ : [],
95
105
  };
96
106
  } catch (error) {
97
107
  const message = error instanceof Error ? error.message : String(error);
@@ -35,9 +35,7 @@ export function registerSkillRoutes(app: FastifyInstance, deps: SkillRouteDeps):
35
35
  return { revisionId };
36
36
  } catch (error) {
37
37
  const message = error instanceof Error ? error.message : "Skill could not be registered";
38
- const conflict =
39
- message.includes("conflicting") || message.includes("managed by configuration");
40
- return reply.code(conflict ? 409 : 404).send({ error: message });
38
+ return reply.code(message.includes("conflicting") ? 409 : 404).send({ error: message });
41
39
  }
42
40
  },
43
41
  );
@@ -1,8 +1,14 @@
1
- import type { ProcessInstance, ProcessTurnRecord } from "@leitwerk-dev/domain";
1
+ import {
2
+ failActiveTurnProgress,
3
+ type ProcessInstance,
4
+ type ProcessTurnRecord,
5
+ type TurnProgressReport,
6
+ } from "@leitwerk-dev/domain";
2
7
  import { isServerAutomaticTurnDefinition } from "@leitwerk-dev/process-sdk";
3
8
  import type { EngineResult, ProcessEngine, ProcessEngineDeps } from "./process-engine/types.js";
4
9
  import { resolveProductTurnResultMarkdown } from "./product-turn-result-markdown.js";
5
10
  import { resolveSemanticTurnResultMarkdown } from "./semantic-turn-result-markdown.js";
11
+ import { recordTurnProgress } from "./turn-progress.js";
6
12
 
7
13
  export interface ServerAutomaticTurnDrainer {
8
14
  requestDrain(instanceId: string, options?: { freshTurnRecordId?: string | null }): Promise<void>;
@@ -209,6 +215,7 @@ export function createServerAutomaticTurnDrainer(
209
215
  const { params, state } = deps
210
216
  .getProcessActionRegistry?.()
211
217
  ?.resolveContextData(current.processId, current) ?? { params: {}, state: {} };
218
+ let latestProgressReport: TurnProgressReport | null = null;
212
219
  try {
213
220
  const result = await turnDef.run({
214
221
  process: current,
@@ -221,6 +228,10 @@ export function createServerAutomaticTurnDrainer(
221
228
  readProductTurnResultMarkdown(productName) {
222
229
  return resolveProductMarkdownForServerAutomatic(deps, current, productName);
223
230
  },
231
+ reportProgress(report) {
232
+ latestProgressReport = report;
233
+ recordTurnProgress(deps, { instanceId, turnRecordId, report });
234
+ },
224
235
  });
225
236
  const recorded = await service.recordTurnOutcome(instanceId, {
226
237
  instanceId,
@@ -248,6 +259,14 @@ export function createServerAutomaticTurnDrainer(
248
259
  return;
249
260
  }
250
261
  } catch (error) {
262
+ const failedProgressReport = latestProgressReport as TurnProgressReport | null;
263
+ if (failedProgressReport) {
264
+ recordTurnProgress(deps, {
265
+ instanceId,
266
+ turnRecordId,
267
+ report: failActiveTurnProgress(failedProgressReport),
268
+ });
269
+ }
251
270
  await service.recordTurnFailed(instanceId, {
252
271
  instanceId,
253
272
  turnRecordId,
@@ -53,6 +53,7 @@ export function buildHostCapabilities(input: {
53
53
  commitMessages: input.config.commit_messages,
54
54
  processes: input.baseDeps.processes,
55
55
  projects: input.baseDeps.projects,
56
+ skills: input.baseDeps.skills,
56
57
  processSkills: input.baseDeps.processSkills,
57
58
  handoffDedupKeys: input.baseDeps.handoffDedupKeys,
58
59
  futureExecutions: input.baseDeps.futureExecutions,
@@ -0,0 +1,13 @@
1
+ import { parseFrontmatter, type SkillFrontmatter } from "@earendil-works/pi-coding-agent";
2
+
3
+ export function skillFrontmatter(markdown: string): SkillFrontmatter {
4
+ try {
5
+ return parseFrontmatter<SkillFrontmatter>(markdown).frontmatter;
6
+ } catch {
7
+ return {};
8
+ }
9
+ }
10
+
11
+ export function isSkillModelInvocable(markdown: string): boolean {
12
+ return skillFrontmatter(markdown)["disable-model-invocation"] !== true;
13
+ }
@@ -7,12 +7,9 @@ import {
7
7
  createCanonicalPiResourceBundle,
8
8
  type PiResourceBundle,
9
9
  } from "@leitwerk-dev/worker-protocol";
10
- import type {
11
- SkillConfig,
12
- SkillRepositoryConfig,
13
- SkillSourceConfig,
14
- } from "../config/config-types.js";
10
+ import type { SkillRepositoryConfig } from "../config/config-types.js";
15
11
  import { ResourceCollector, SKILL_RESOURCE_OWNER } from "../pi-resources/resource-collector.js";
12
+ import { skillFrontmatter } from "./skill-frontmatter.js";
16
13
  import { SAFE_SKILL_ID_PATTERN } from "./skill-id.js";
17
14
 
18
15
  const execFileAsync = promisify(execFile);
@@ -24,7 +21,7 @@ export interface ImportedSkill {
24
21
  label: string;
25
22
  description: string | null;
26
23
  bundle: PiResourceBundle;
27
- sourceRevision: string | null;
24
+ sourceRevision: string;
28
25
  }
29
26
 
30
27
  export interface ImportedRepositorySkill extends ImportedSkill {
@@ -38,28 +35,31 @@ function isWithin(root: string, candidate: string): boolean {
38
35
 
39
36
  async function importSkillDirectory(
40
37
  root: string,
41
- skill: SkillConfig,
42
- sourceRevision: string | null,
43
- ): Promise<ImportedSkill> {
38
+ checkoutRoot: string,
39
+ sourceRevision: string,
40
+ ): Promise<ImportedRepositorySkill> {
41
+ const skillId = path.basename(root);
42
+ const metadata = skillFrontmatter(await readFile(path.join(root, "SKILL.md"), "utf8"));
44
43
  const collector = new ResourceCollector();
45
- await collector.addDirectory(path.resolve(root), `skills/${skill.id}`, SKILL_RESOURCE_OWNER, {
44
+ await collector.addDirectory(path.resolve(root), `skills/${skillId}`, SKILL_RESOURCE_OWNER, {
46
45
  forbiddenNames: FORBIDDEN_SKILL_NAMES,
47
46
  });
48
47
  const files = collector.toResourceFiles();
49
- if (!files.some((file) => file.path === `skills/${skill.id}/SKILL.md`)) {
50
- throw new Error(`Skill '${skill.id}' must contain a regular root SKILL.md`);
48
+ if (!files.some((file) => file.path === `skills/${skillId}/SKILL.md`)) {
49
+ throw new Error(`Skill '${skillId}' must contain a regular root SKILL.md`);
51
50
  }
52
51
  return {
53
- skillId: skill.id,
54
- label: skill.label ?? skill.id,
55
- description: skill.description ?? null,
52
+ skillId,
53
+ label: metadataText(metadata.name) ?? fallbackLabel(skillId),
54
+ description: metadataText(metadata.description),
56
55
  bundle: createCanonicalPiResourceBundle(files),
57
56
  sourceRevision,
57
+ sourcePath: repositorySourcePath(checkoutRoot, root),
58
58
  };
59
59
  }
60
60
 
61
61
  async function checkoutGitSource(
62
- source: Extract<SkillSourceConfig, { kind: "git" }>,
62
+ source: { url: string; ref: string },
63
63
  root: string,
64
64
  ): Promise<{ root: string; commit: string }> {
65
65
  await execFileAsync(
@@ -74,14 +74,8 @@ async function checkoutGitSource(
74
74
  return { root, commit: stdout.trim() };
75
75
  }
76
76
 
77
- function metadataValue(markdown: string, key: string): string | null {
78
- if (!markdown.startsWith("---")) return null;
79
- const end = markdown.indexOf("\n---", 3);
80
- if (end < 0) return null;
81
- const match = markdown
82
- .slice(3, end)
83
- .match(new RegExp(`^${key}:\\s*["']?([^\\n"']+)["']?\\s*$`, "m"));
84
- return match?.[1]?.trim() || null;
77
+ function metadataText(value: unknown): string | null {
78
+ return typeof value === "string" ? value.trim() || null : null;
85
79
  }
86
80
 
87
81
  function fallbackLabel(id: string): string {
@@ -100,7 +94,6 @@ async function discoverSkillRoots(catalogRoot: string): Promise<string[]> {
100
94
  );
101
95
  const skillId = path.basename(directory);
102
96
  if (
103
- directory !== catalogRoot &&
104
97
  SAFE_SKILL_ID_PATTERN.test(skillId) &&
105
98
  entries.some((entry) => entry.name === "SKILL.md" && entry.isFile())
106
99
  ) {
@@ -126,10 +119,7 @@ export async function importSkillRepository(
126
119
  ): Promise<{ commit: string; skills: ImportedRepositorySkill[] }> {
127
120
  const tempRoot = await mkdtemp(path.join(tmpdir(), "leitwerk-skill-repository-"));
128
121
  try {
129
- const checkout = await checkoutGitSource(
130
- { kind: "git", url: repository.url, ref: repository.ref, path: repository.path ?? "skills" },
131
- path.join(tempRoot, "checkout"),
132
- );
122
+ const checkout = await checkoutGitSource(repository, path.join(tempRoot, "checkout"));
133
123
  const catalogRoot = path.resolve(checkout.root, repository.path ?? "skills");
134
124
  if (!isWithin(checkout.root, catalogRoot)) {
135
125
  throw new Error(`Skill repository '${repository.id}' path escapes its checkout`);
@@ -148,62 +138,10 @@ export async function importSkillRepository(
148
138
  }
149
139
  const skills: ImportedRepositorySkill[] = [];
150
140
  for (const skillRoot of skillRoots) {
151
- const skillId = path.basename(skillRoot);
152
- const markdown = await readFile(path.join(skillRoot, "SKILL.md"), "utf8");
153
- const imported = await importSkillDirectory(
154
- skillRoot,
155
- {
156
- id: skillId,
157
- label: metadataValue(markdown, "name") ?? fallbackLabel(skillId),
158
- description: metadataValue(markdown, "description") ?? undefined,
159
- source: { kind: "local", path: skillRoot },
160
- },
161
- checkout.commit,
162
- );
163
- skills.push({
164
- ...imported,
165
- sourcePath: repositorySourcePath(checkout.root, skillRoot),
166
- });
141
+ skills.push(await importSkillDirectory(skillRoot, checkout.root, checkout.commit));
167
142
  }
168
143
  return { commit: checkout.commit, skills };
169
144
  } finally {
170
145
  await rm(tempRoot, { recursive: true, force: true });
171
146
  }
172
147
  }
173
-
174
- export async function importConfiguredSkills(
175
- skills: readonly SkillConfig[],
176
- configRoot: string,
177
- ): Promise<ImportedSkill[]> {
178
- let tempRoot: string | null = null;
179
- const checkouts = new Map<string, { root: string; commit: string }>();
180
- try {
181
- const result: ImportedSkill[] = [];
182
- for (const skill of skills) {
183
- if (skill.source.kind === "local") {
184
- result.push(
185
- await importSkillDirectory(path.resolve(configRoot, skill.source.path), skill, null),
186
- );
187
- continue;
188
- }
189
- const key = `${skill.source.url}\0${skill.source.ref}`;
190
- let checkout = checkouts.get(key);
191
- if (!checkout) {
192
- tempRoot ??= await mkdtemp(path.join(tmpdir(), "leitwerk-skills-"));
193
- checkout = await checkoutGitSource(
194
- skill.source,
195
- path.join(tempRoot, String(checkouts.size)),
196
- );
197
- checkouts.set(key, checkout);
198
- }
199
- const selected = path.resolve(checkout.root, skill.source.path);
200
- if (!isWithin(checkout.root, selected)) {
201
- throw new Error(`Skill '${skill.id}' Git path escapes its checkout`);
202
- }
203
- result.push(await importSkillDirectory(selected, skill, checkout.commit));
204
- }
205
- return result;
206
- } finally {
207
- if (tempRoot) await rm(tempRoot, { recursive: true, force: true });
208
- }
209
- }
@@ -0,0 +1,40 @@
1
+ import type { RepositoryBundle } from "../db/repositories.js";
2
+
3
+ export interface AcceptedTurnStartReplay {
4
+ startRecordId: string;
5
+ turnRecordId: string;
6
+ startedAt: string;
7
+ }
8
+
9
+ /** Resolve the durable accepted start that an idle owning worker must activate. */
10
+ export function resolveAcceptedTurnStartReplay(
11
+ deps: Pick<RepositoryBundle, "leases" | "processes" | "turnRecords" | "turnStarts">,
12
+ instanceId: string,
13
+ workerId: string,
14
+ ): AcceptedTurnStartReplay | null {
15
+ const lease = deps.leases.getByInstance(instanceId);
16
+ if (!lease || lease.workerId !== workerId || lease.state !== "idle") return null;
17
+
18
+ const process = deps.processes.getById(instanceId);
19
+ if (!process || process.currentExecution?.kind !== "worker_start") return null;
20
+
21
+ const start = deps.turnStarts.getById(process.currentExecution.id);
22
+ if (
23
+ !start ||
24
+ start.instanceId !== instanceId ||
25
+ start.state.kind !== "accepted" ||
26
+ start.state.acceptedWorkerLeaseId !== lease.id
27
+ )
28
+ return null;
29
+
30
+ const turnRecord = deps.turnRecords.getById(start.state.turnRecordId);
31
+ if (
32
+ !turnRecord ||
33
+ turnRecord.instanceId !== instanceId ||
34
+ turnRecord.status !== "running" ||
35
+ turnRecord.acceptedWorkerLeaseId !== lease.id
36
+ )
37
+ return null;
38
+
39
+ return { startRecordId: start.id, turnRecordId: turnRecord.id, startedAt: turnRecord.startedAt };
40
+ }
@@ -69,6 +69,15 @@ export interface IpcHandlerCallbacks {
69
69
  outcome: string,
70
70
  params: Record<string, unknown>,
71
71
  ) => void;
72
+ onTurnTerminalRecorded?: (instanceId: string, workerId: string, turnRecordId: string) => void;
73
+ onTurnTerminalRecordingFailed?: (input: {
74
+ instanceId: string;
75
+ workerId: string;
76
+ turnRecordId: string;
77
+ terminalType: "outcome" | "failure";
78
+ code: string;
79
+ message: string;
80
+ }) => void;
72
81
  onCleanupCompleted?: (instanceId: string, workerId: string) => void;
73
82
  onWorkerTurnStartAccepted?: (
74
83
  instanceId: string,
@@ -92,11 +101,15 @@ export function createIpcHandler(deps: IpcHandlerDeps, callbacks: IpcHandlerCall
92
101
  const inputAckHandler = createWorkerInputAckHandler(deps);
93
102
  const turnRecorder = createWorkerTurnIpcRecorder(
94
103
  {
95
- processes: deps.processes,
104
+ turnRecords: deps.turnRecords,
96
105
  commands: deps.commands,
97
106
  eventIngestor,
98
107
  },
99
- { onTurnOutcomeRecorded: callbacks.onTurnOutcomeRecorded },
108
+ {
109
+ onTurnOutcomeRecorded: callbacks.onTurnOutcomeRecorded,
110
+ onTurnTerminalRecorded: callbacks.onTurnTerminalRecorded,
111
+ onTurnTerminalRecordingFailed: callbacks.onTurnTerminalRecordingFailed,
112
+ },
100
113
  );
101
114
 
102
115
  return {
@@ -181,6 +194,7 @@ export function createIpcHandler(deps: IpcHandlerDeps, callbacks: IpcHandlerCall
181
194
  }
182
195
  const result = observeWorkerLease("bootstrap_completed", "worker.ready");
183
196
  if (result.kind === "applied") {
197
+ deps.leases.updateHeartbeat(activeLease.workerId);
184
198
  void deps.commands
185
199
  .updateSemanticEntryRefs(instanceId, {
186
200
  rootEntry:
@@ -250,11 +264,11 @@ export function createIpcHandler(deps: IpcHandlerDeps, callbacks: IpcHandlerCall
250
264
  break;
251
265
  }
252
266
  case "worker.turn_outcome": {
253
- turnRecorder.recordTurnOutcome(instanceId, msg.payload);
267
+ turnRecorder.recordTurnOutcome(instanceId, workerId, msg.payload);
254
268
  break;
255
269
  }
256
270
  case "worker.turn_failed": {
257
- turnRecorder.recordTurnFailed(instanceId, msg.payload);
271
+ turnRecorder.recordTurnFailed(instanceId, workerId, msg.payload);
258
272
  break;
259
273
  }
260
274
  case "worker.lifecycle_parked": {
@@ -1,10 +1,12 @@
1
1
  import { parseDurationMs } from "@leitwerk-dev/watcher-utils";
2
2
  import type { RepositoryBundle } from "../db/repositories.js";
3
+ import { resolveAcceptedTurnStartReplay } from "./accepted-turn-start-replay.js";
3
4
  import type { IpcHandler } from "./ipc-handler.js";
4
5
  import { createServerObservedWorkerFailedMessage } from "./synthetic-worker-failure.js";
5
6
  import type { WorkerSupervisor } from "./worker-supervisor.js";
6
7
 
7
- export interface StaleHeartbeatWatchdogDeps extends Pick<RepositoryBundle, "leases" | "processes"> {
8
+ export interface StaleHeartbeatWatchdogDeps
9
+ extends Pick<RepositoryBundle, "leases" | "processes" | "turnRecords" | "turnStarts"> {
8
10
  ipcHandler: IpcHandler;
9
11
  supervisor: WorkerSupervisor;
10
12
  staleHeartbeatTimeout: string;
@@ -27,8 +29,13 @@ export function startStaleHeartbeatWatchdog(
27
29
  const now = deps.now ?? (() => Date.now());
28
30
  const setIntervalImpl = deps.setIntervalImpl ?? setInterval;
29
31
  const clearIntervalImpl = deps.clearIntervalImpl ?? clearInterval;
32
+ const acceptedStartReconciliations = new Map<
33
+ string,
34
+ { turnRecordId: string; startedAtMs: number }
35
+ >();
30
36
 
31
37
  const tick = () => {
38
+ const observedReconciliations = new Set<string>();
32
39
  for (const lease of deps.leases.listActive()) {
33
40
  if (deps.supervisor.isAdoptionPending?.(lease.instanceId)) {
34
41
  continue;
@@ -36,14 +43,51 @@ export function startStaleHeartbeatWatchdog(
36
43
  if (lease.state !== "idle" && lease.state !== "busy" && lease.state !== "draining") {
37
44
  continue;
38
45
  }
39
- const heartbeatAt = lease.lastHeartbeatAt ?? lease.startedAt;
40
- const lastSeenMs = Date.parse(heartbeatAt);
41
- if (!Number.isFinite(lastSeenMs) || now() - lastSeenMs < timeoutMs) {
46
+ const process = deps.processes.getById(lease.instanceId);
47
+ if (!process) {
42
48
  continue;
43
49
  }
44
50
 
45
- const process = deps.processes.getById(lease.instanceId);
46
- if (!process) {
51
+ const acceptedStart =
52
+ lease.state === "idle"
53
+ ? resolveAcceptedTurnStartReplay(deps, lease.instanceId, lease.workerId)
54
+ : null;
55
+ const acceptedAtMs = acceptedStart ? Date.parse(acceptedStart.startedAt) : Number.NaN;
56
+ if (acceptedStart && Number.isFinite(acceptedAtMs) && now() - acceptedAtMs >= timeoutMs) {
57
+ observedReconciliations.add(lease.instanceId);
58
+ const reconciliation = acceptedStartReconciliations.get(lease.instanceId);
59
+ if (!reconciliation || reconciliation.turnRecordId !== acceptedStart.turnRecordId) {
60
+ if (deps.supervisor.reconcileAcceptedTurnStart(lease.instanceId, lease.workerId)) {
61
+ acceptedStartReconciliations.set(lease.instanceId, {
62
+ turnRecordId: acceptedStart.turnRecordId,
63
+ startedAtMs: now(),
64
+ });
65
+ continue;
66
+ }
67
+ } else if (now() - reconciliation.startedAtMs < timeoutMs) {
68
+ continue;
69
+ }
70
+ acceptedStartReconciliations.delete(lease.instanceId);
71
+ deps.ipcHandler.handleMessage(
72
+ createServerObservedWorkerFailedMessage({
73
+ instanceId: lease.instanceId,
74
+ workerId: lease.workerId,
75
+ state: lease.state,
76
+ errorCode: "idle_worker_running_turn",
77
+ message: `Worker ${lease.workerId} reported idle while turn ${acceptedStart.turnRecordId} remained running`,
78
+ errorClass: "infrastructure",
79
+ selectedTurnId: process.selectedTurnId,
80
+ }),
81
+ );
82
+ deps.supervisor.getWorker(lease.instanceId)?.kill();
83
+ continue;
84
+ }
85
+
86
+ if (!lease.lastHeartbeatAt) {
87
+ continue;
88
+ }
89
+ const lastSeenMs = Date.parse(lease.lastHeartbeatAt);
90
+ if (!Number.isFinite(lastSeenMs) || now() - lastSeenMs < timeoutMs) {
47
91
  continue;
48
92
  }
49
93
 
@@ -60,6 +104,11 @@ export function startStaleHeartbeatWatchdog(
60
104
  );
61
105
  deps.supervisor.getWorker(lease.instanceId)?.kill();
62
106
  }
107
+ for (const instanceId of acceptedStartReconciliations.keys()) {
108
+ if (!observedReconciliations.has(instanceId)) {
109
+ acceptedStartReconciliations.delete(instanceId);
110
+ }
111
+ }
63
112
  };
64
113
 
65
114
  const timer = setIntervalImpl(tick, intervalMs);
@@ -21,6 +21,7 @@ import {
21
21
  type MutableLiveTurnProjection,
22
22
  snapshotLiveTurnProjection,
23
23
  } from "../live-turn-projection.js";
24
+ import { recordTurnProgress } from "../turn-progress.js";
24
25
  import type { Broadcaster } from "../ws/broadcast.js";
25
26
 
26
27
  const LIVE_TURN_EVENT_LOOKBACK_LIMIT = 1000;
@@ -131,8 +132,22 @@ export function createWorkerEventIngestor(deps: WorkerEventIngestorDeps) {
131
132
  const currentTurnRecordId =
132
133
  (process.currentExecution?.kind === "server_turn" ? process.currentExecution.id : null) ??
133
134
  liveTurnRecordIds.get(instanceId) ??
135
+ deps.turnRecords
136
+ .listByInstance(instanceId)
137
+ .find((record) => record.status === "running" && record.turnId === process.selectedTurnId)
138
+ ?.id ??
134
139
  null;
135
140
  const data = asWsEventPayloadRecord(payload.data);
141
+ if (payload.eventType === "turn.progress") {
142
+ const reportedTurnRecordId = readWsEventNonEmptyString(data.turnRecordId);
143
+ if (!reportedTurnRecordId || reportedTurnRecordId !== currentTurnRecordId) return;
144
+ recordTurnProgress(deps, {
145
+ instanceId,
146
+ turnRecordId: reportedTurnRecordId,
147
+ report: data.report,
148
+ });
149
+ return;
150
+ }
136
151
  const projection = getLiveTurnProjection(instanceId, currentTurnRecordId);
137
152
  const appliedProjectionEvent = applyPiEventToLiveTurnProjection(projection, {
138
153
  eventType: payload.eventType,
@@ -17,6 +17,7 @@ import {
17
17
  } from "@leitwerk-dev/worker-protocol";
18
18
  import type { LeitwerkConfig } from "../config/config-types.js";
19
19
  import type { RepositoryBundle } from "../db/repositories.js";
20
+ import type { ResolvedProviderCredential } from "../model-providers/credentials.js";
20
21
  import type { ProcessActionRegistry } from "../process-action-registry.js";
21
22
  import { getProcessTurnGraph, type ProcessGraphRegistry } from "../process-graph.js";
22
23
  import { toInputDelivery } from "../process-input-dispatch.js";
@@ -46,7 +47,7 @@ export interface WorkerStartPayloadBuilderDeps
46
47
  resolveCredential?(
47
48
  providerId: string,
48
49
  options: Readonly<Record<string, string>>,
49
- ): { revision: number; values: Record<string, string> } | null;
50
+ ): Pick<ResolvedProviderCredential, "revision" | "values"> | null;
50
51
  integrationTools?: {
51
52
  declarations(
52
53
  names: readonly string[],
@@ -306,7 +307,9 @@ export function createWorkerStartPayloadBuilder(deps: WorkerStartPayloadBuilderD
306
307
  start.turnId,
307
308
  );
308
309
  const integrationToolNames =
309
- selectedTurn?.kind === "llm" ? (selectedTurn.integrationTools ?? []) : [];
310
+ selectedTurn?.kind === "llm" || selectedTurn?.kind === "automatic"
311
+ ? (selectedTurn.integrationTools ?? [])
312
+ : [];
310
313
  const integrationTools =
311
314
  integrationToolNames.length > 0
312
315
  ? deps.integrationTools?.declarations(integrationToolNames)