@leitwerk-dev/server 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (309) hide show
  1. package/dist/{app-BuJCdkvy.d.ts → app-CsuxFZT5.d.ts} +262 -121
  2. package/dist/app-JM4CBTND.js +8 -0
  3. package/dist/app.d.ts +9 -0
  4. package/dist/app.d.ts.map +1 -1
  5. package/dist/auth/fastify-auth.d.ts +9 -0
  6. package/dist/auth/fastify-auth.d.ts.map +1 -1
  7. package/dist/{chunk-QCHS3X33.js → chunk-FPMDWQF7.js} +2617 -562
  8. package/dist/chunk-FPMDWQF7.js.map +1 -0
  9. package/dist/{chunk-HK6BLLHA.js → chunk-MBHRCQFE.js} +2303 -1576
  10. package/dist/chunk-MBHRCQFE.js.map +1 -0
  11. package/dist/config/config-loader.d.ts +1 -1
  12. package/dist/config/config-loader.d.ts.map +1 -1
  13. package/dist/config/config-types.d.ts +14 -1
  14. package/dist/config/config-types.d.ts.map +1 -1
  15. package/dist/config/kubernetes-docker-isolation.d.ts +7 -0
  16. package/dist/config/kubernetes-docker-isolation.d.ts.map +1 -0
  17. package/dist/db/database.d.ts.map +1 -1
  18. package/dist/db/execution-inspection-repo.d.ts +15 -0
  19. package/dist/db/execution-inspection-repo.d.ts.map +1 -0
  20. package/dist/db/history-window.d.ts +11 -0
  21. package/dist/db/history-window.d.ts.map +1 -0
  22. package/dist/db/process-event-repo.d.ts +2 -0
  23. package/dist/db/process-event-repo.d.ts.map +1 -1
  24. package/dist/db/process-instance-repo.d.ts +4 -1
  25. package/dist/db/process-instance-repo.d.ts.map +1 -1
  26. package/dist/db/process-leaf-outcome-snapshot-repo.d.ts +2 -1
  27. package/dist/db/process-leaf-outcome-snapshot-repo.d.ts.map +1 -1
  28. package/dist/db/process-project-repo.d.ts +2 -0
  29. package/dist/db/process-project-repo.d.ts.map +1 -1
  30. package/dist/db/process-skill-repo.d.ts.map +1 -1
  31. package/dist/db/process-turn-annotation-repo.d.ts +4 -1
  32. package/dist/db/process-turn-annotation-repo.d.ts.map +1 -1
  33. package/dist/db/process-turn-record-repo.d.ts +4 -0
  34. package/dist/db/process-turn-record-repo.d.ts.map +1 -1
  35. package/dist/db/publication-repo.d.ts +5 -0
  36. package/dist/db/publication-repo.d.ts.map +1 -0
  37. package/dist/db/repositories.d.ts +12 -0
  38. package/dist/db/repositories.d.ts.map +1 -1
  39. package/dist/db/schema.d.ts +693 -2
  40. package/dist/db/schema.d.ts.map +1 -1
  41. package/dist/db/scoped-settings-repo.d.ts +37 -0
  42. package/dist/db/scoped-settings-repo.d.ts.map +1 -0
  43. package/dist/db/skill-repo.d.ts +3 -0
  44. package/dist/db/skill-repo.d.ts.map +1 -1
  45. package/dist/db/turn-start-record-repo.d.ts +2 -1
  46. package/dist/db/turn-start-record-repo.d.ts.map +1 -1
  47. package/dist/db/turn-summary-repo.d.ts +1 -1
  48. package/dist/db/turn-summary-repo.d.ts.map +1 -1
  49. package/dist/db/worker-lease-repo.d.ts +2 -1
  50. package/dist/db/worker-lease-repo.d.ts.map +1 -1
  51. package/dist/domain-logic/outcome-tools.d.ts.map +1 -1
  52. package/dist/external-source-service.d.ts.map +1 -1
  53. package/dist/future-execution/execution.d.ts +4 -1
  54. package/dist/future-execution/execution.d.ts.map +1 -1
  55. package/dist/future-execution/launch-lifecycle.d.ts +9 -25
  56. package/dist/future-execution/launch-lifecycle.d.ts.map +1 -1
  57. package/dist/future-execution/lifecycle.d.ts +3 -28
  58. package/dist/future-execution/lifecycle.d.ts.map +1 -1
  59. package/dist/future-execution/model-projection.d.ts.map +1 -1
  60. package/dist/future-execution/reconciliation.d.ts +1 -0
  61. package/dist/future-execution/reconciliation.d.ts.map +1 -1
  62. package/dist/future-execution-presenter.d.ts.map +1 -1
  63. package/dist/index.js +2 -2
  64. package/dist/integration-tool-registry.d.ts +11 -2
  65. package/dist/integration-tool-registry.d.ts.map +1 -1
  66. package/dist/launch-coordinator.d.ts.map +1 -1
  67. package/dist/launcher-model-config-service.d.ts +7 -1
  68. package/dist/launcher-model-config-service.d.ts.map +1 -1
  69. package/dist/leaf-outcome-snapshot-capture.d.ts +1 -0
  70. package/dist/leaf-outcome-snapshot-capture.d.ts.map +1 -1
  71. package/dist/main.js +3 -3
  72. package/dist/primary-path-snapshot.d.ts.map +1 -1
  73. package/dist/process-action-presenter.d.ts +1 -6
  74. package/dist/process-action-presenter.d.ts.map +1 -1
  75. package/dist/process-action-registry.d.ts.map +1 -1
  76. package/dist/process-engine/decision.d.ts +2 -0
  77. package/dist/process-engine/decision.d.ts.map +1 -1
  78. package/dist/process-engine/engine.d.ts.map +1 -1
  79. package/dist/process-engine/mapped-turns.d.ts.map +1 -1
  80. package/dist/process-engine/ops/continue-failed-turn.d.ts.map +1 -1
  81. package/dist/process-engine/ops/process-observation.d.ts +6 -0
  82. package/dist/process-engine/ops/process-observation.d.ts.map +1 -0
  83. package/dist/process-engine/ops/retry-failed-turn.d.ts.map +1 -1
  84. package/dist/process-engine/ops/retry-startup.d.ts.map +1 -1
  85. package/dist/process-engine/ops/start-process.d.ts +2 -0
  86. package/dist/process-engine/ops/start-process.d.ts.map +1 -1
  87. package/dist/process-engine/ops/turn-outcome.d.ts.map +1 -1
  88. package/dist/process-engine/ops/turn-wait.d.ts +30 -0
  89. package/dist/process-engine/ops/turn-wait.d.ts.map +1 -0
  90. package/dist/process-engine/ops/update-model-config.d.ts +9 -0
  91. package/dist/process-engine/ops/update-model-config.d.ts.map +1 -0
  92. package/dist/process-engine/recorder.d.ts.map +1 -1
  93. package/dist/process-engine/turn-start-preflight.d.ts +6 -0
  94. package/dist/process-engine/turn-start-preflight.d.ts.map +1 -1
  95. package/dist/process-engine/turn-wait-state.d.ts +24 -0
  96. package/dist/process-engine/turn-wait-state.d.ts.map +1 -0
  97. package/dist/process-engine/turn-worker-requirement.d.ts +2 -0
  98. package/dist/process-engine/turn-worker-requirement.d.ts.map +1 -1
  99. package/dist/process-engine/types.d.ts +5 -1
  100. package/dist/process-engine/types.d.ts.map +1 -1
  101. package/dist/process-engine/writes/build-process-abort-writes.d.ts +3 -1
  102. package/dist/process-engine/writes/build-process-abort-writes.d.ts.map +1 -1
  103. package/dist/process-engine/writes/build-turn-outcome-writes.d.ts +2 -0
  104. package/dist/process-engine/writes/build-turn-outcome-writes.d.ts.map +1 -1
  105. package/dist/process-engine/writes/commit-writes.d.ts +2 -0
  106. package/dist/process-engine/writes/commit-writes.d.ts.map +1 -1
  107. package/dist/process-engine/writes/writes.d.ts +28 -60
  108. package/dist/process-engine/writes/writes.d.ts.map +1 -1
  109. package/dist/process-graph.d.ts +1 -1
  110. package/dist/process-graph.d.ts.map +1 -1
  111. package/dist/process-inspection-reader.d.ts +21 -0
  112. package/dist/process-inspection-reader.d.ts.map +1 -0
  113. package/dist/process-inspection-trace.d.ts +13 -0
  114. package/dist/process-inspection-trace.d.ts.map +1 -0
  115. package/dist/process-inspection.d.ts +22 -0
  116. package/dist/process-inspection.d.ts.map +1 -0
  117. package/dist/process-instance-tree-presenter.d.ts +4 -3
  118. package/dist/process-instance-tree-presenter.d.ts.map +1 -1
  119. package/dist/process-launch-executor.d.ts +2 -0
  120. package/dist/process-launch-executor.d.ts.map +1 -1
  121. package/dist/process-launch-plan.d.ts +1 -0
  122. package/dist/process-launch-plan.d.ts.map +1 -1
  123. package/dist/process-launcher-registry.d.ts.map +1 -1
  124. package/dist/process-model-config.d.ts +19 -0
  125. package/dist/process-model-config.d.ts.map +1 -0
  126. package/dist/process-model-policy/construct.d.ts.map +1 -1
  127. package/dist/process-model-policy/evaluate.d.ts.map +1 -1
  128. package/dist/process-model-policy/index.d.ts +4 -1
  129. package/dist/process-model-policy/index.d.ts.map +1 -1
  130. package/dist/process-model-policy/project.d.ts.map +1 -1
  131. package/dist/process-model-policy/types.d.ts +18 -0
  132. package/dist/process-model-policy/types.d.ts.map +1 -1
  133. package/dist/process-model-policy-presenter.d.ts.map +1 -1
  134. package/dist/process-runtime-availability.d.ts +2 -1
  135. package/dist/process-runtime-availability.d.ts.map +1 -1
  136. package/dist/process-turn-trace.d.ts.map +1 -1
  137. package/dist/process-ui-snapshot-presenter.d.ts +14 -3
  138. package/dist/process-ui-snapshot-presenter.d.ts.map +1 -1
  139. package/dist/routes/future-executions.d.ts.map +1 -1
  140. package/dist/routes/launchers.d.ts.map +1 -1
  141. package/dist/routes/process-actions.d.ts.map +1 -1
  142. package/dist/routes/process-detail.d.ts.map +1 -1
  143. package/dist/routes/process-model-config.d.ts +4 -0
  144. package/dist/routes/process-model-config.d.ts.map +1 -0
  145. package/dist/routes/process-route-helpers.d.ts +8 -9
  146. package/dist/routes/process-route-helpers.d.ts.map +1 -1
  147. package/dist/routes/processes.d.ts.map +1 -1
  148. package/dist/routes/settings.d.ts +11 -0
  149. package/dist/routes/settings.d.ts.map +1 -0
  150. package/dist/routes/ticket-creation.d.ts.map +1 -1
  151. package/dist/scoped-settings-service.d.ts +83 -0
  152. package/dist/scoped-settings-service.d.ts.map +1 -0
  153. package/dist/server-bootstrap/build-host-capabilities.d.ts +2 -0
  154. package/dist/server-bootstrap/build-host-capabilities.d.ts.map +1 -1
  155. package/dist/server-bootstrap/register-http.d.ts.map +1 -1
  156. package/dist/session-summary-projection.d.ts.map +1 -1
  157. package/dist/skills/bundled-skills.d.ts +5 -0
  158. package/dist/skills/bundled-skills.d.ts.map +1 -0
  159. package/dist/skills/catalog-service.d.ts +1 -0
  160. package/dist/skills/catalog-service.d.ts.map +1 -1
  161. package/dist/skills/extension-importer.d.ts +11 -0
  162. package/dist/skills/extension-importer.d.ts.map +1 -0
  163. package/dist/skills/launch-skills.d.ts +11 -0
  164. package/dist/skills/launch-skills.d.ts.map +1 -0
  165. package/dist/skills/skill-frontmatter.d.ts +5 -0
  166. package/dist/skills/skill-frontmatter.d.ts.map +1 -1
  167. package/dist/skills/source-importer.d.ts +3 -0
  168. package/dist/skills/source-importer.d.ts.map +1 -1
  169. package/dist/startup-evidence.d.ts +3 -0
  170. package/dist/startup-evidence.d.ts.map +1 -1
  171. package/dist/supervisor/execution-inspection-ingestor.d.ts +9 -0
  172. package/dist/supervisor/execution-inspection-ingestor.d.ts.map +1 -0
  173. package/dist/supervisor/ipc-handler.d.ts +2 -0
  174. package/dist/supervisor/ipc-handler.d.ts.map +1 -1
  175. package/dist/supervisor/worker-event-ingestor.d.ts +1 -0
  176. package/dist/supervisor/worker-event-ingestor.d.ts.map +1 -1
  177. package/dist/supervisor/worker-start-payload-builder.d.ts.map +1 -1
  178. package/dist/supervisor/worker-supervisor.d.ts +2 -0
  179. package/dist/supervisor/worker-supervisor.d.ts.map +1 -1
  180. package/dist/test-helpers/prepared-fixture-start.d.ts.map +1 -1
  181. package/dist/test-helpers/process-model-fixtures.d.ts +1 -0
  182. package/dist/test-helpers/process-model-fixtures.d.ts.map +1 -1
  183. package/dist/test-helpers/scoped-settings-fixtures.d.ts +16 -0
  184. package/dist/test-helpers/scoped-settings-fixtures.d.ts.map +1 -0
  185. package/dist/test-helpers/skill-fixtures.d.ts +4 -0
  186. package/dist/test-helpers/skill-fixtures.d.ts.map +1 -0
  187. package/dist/testing.js +2 -1
  188. package/dist/testing.js.map +1 -1
  189. package/dist/tool-approval-gate.d.ts +3 -0
  190. package/dist/tool-approval-gate.d.ts.map +1 -1
  191. package/dist/turn-progress.d.ts.map +1 -1
  192. package/dist/turn-wait-service.d.ts +28 -0
  193. package/dist/turn-wait-service.d.ts.map +1 -0
  194. package/dist/worker-runtime-profile-selection.d.ts +2 -0
  195. package/dist/worker-runtime-profile-selection.d.ts.map +1 -1
  196. package/package.json +20 -19
  197. package/src/app.ts +115 -5
  198. package/src/auth/fastify-auth.ts +13 -0
  199. package/src/config/config-loader.ts +40 -2
  200. package/src/config/config-types.ts +14 -1
  201. package/src/config/kubernetes-docker-isolation.ts +21 -0
  202. package/src/db/database.ts +131 -40
  203. package/src/db/execution-inspection-repo.ts +163 -0
  204. package/src/db/history-window.ts +18 -0
  205. package/src/db/process-event-repo.ts +88 -10
  206. package/src/db/process-instance-repo.ts +9 -2
  207. package/src/db/process-leaf-outcome-snapshot-repo.ts +8 -2
  208. package/src/db/process-project-repo.ts +4 -0
  209. package/src/db/process-skill-repo.ts +9 -2
  210. package/src/db/process-turn-annotation-repo.ts +27 -9
  211. package/src/db/process-turn-record-repo.ts +45 -12
  212. package/src/db/publication-repo.ts +63 -0
  213. package/src/db/repositories.ts +17 -0
  214. package/src/db/schema.ts +103 -1
  215. package/src/db/scoped-settings-repo.ts +234 -0
  216. package/src/db/skill-repo.ts +89 -27
  217. package/src/db/turn-start-record-repo.ts +8 -2
  218. package/src/db/turn-summary-repo.ts +12 -3
  219. package/src/db/worker-lease-repo.ts +8 -2
  220. package/src/domain-logic/outcome-tools.ts +4 -193
  221. package/src/external-source-service.ts +33 -7
  222. package/src/future-execution/execution.ts +9 -2
  223. package/src/future-execution/launch-lifecycle.ts +87 -78
  224. package/src/future-execution/lifecycle.ts +5 -34
  225. package/src/future-execution/model-projection.ts +2 -0
  226. package/src/future-execution/reconciliation.ts +7 -0
  227. package/src/future-execution-presenter.ts +7 -8
  228. package/src/integration-tool-registry.ts +59 -26
  229. package/src/launch-coordinator.ts +10 -1
  230. package/src/launcher-model-config-service.ts +24 -3
  231. package/src/leaf-outcome-snapshot-capture.ts +2 -0
  232. package/src/primary-path-snapshot.ts +3 -4
  233. package/src/process-action-presenter.ts +22 -57
  234. package/src/process-action-registry.ts +31 -39
  235. package/src/process-engine/decision.ts +10 -0
  236. package/src/process-engine/engine.ts +11 -2
  237. package/src/process-engine/mapped-turns.ts +5 -7
  238. package/src/process-engine/ops/continue-failed-turn.ts +2 -13
  239. package/src/process-engine/ops/process-observation.ts +119 -0
  240. package/src/process-engine/ops/retry-failed-turn.ts +2 -12
  241. package/src/process-engine/ops/retry-startup.ts +9 -13
  242. package/src/process-engine/ops/start-process.ts +34 -2
  243. package/src/process-engine/ops/turn-outcome.ts +61 -60
  244. package/src/process-engine/ops/turn-wait.ts +225 -0
  245. package/src/process-engine/ops/update-model-config.ts +66 -0
  246. package/src/process-engine/recorder.ts +21 -5
  247. package/src/process-engine/turn-start-preflight.ts +168 -105
  248. package/src/process-engine/turn-wait-state.ts +126 -0
  249. package/src/process-engine/turn-worker-requirement.ts +4 -0
  250. package/src/process-engine/types.ts +9 -0
  251. package/src/process-engine/writes/build-process-abort-writes.ts +30 -20
  252. package/src/process-engine/writes/build-turn-outcome-writes.ts +39 -2
  253. package/src/process-engine/writes/commit-writes.ts +15 -2
  254. package/src/process-engine/writes/writes.ts +59 -74
  255. package/src/process-graph.ts +0 -1
  256. package/src/process-inspection-reader.ts +305 -0
  257. package/src/process-inspection-trace.ts +176 -0
  258. package/src/process-inspection.ts +169 -0
  259. package/src/process-instance-tree-presenter.ts +56 -216
  260. package/src/process-launch-executor.ts +5 -2
  261. package/src/process-launch-plan.ts +17 -2
  262. package/src/process-launcher-registry.ts +28 -16
  263. package/src/process-model-config.ts +100 -0
  264. package/src/process-model-policy/construct.ts +1 -0
  265. package/src/process-model-policy/evaluate.ts +34 -32
  266. package/src/process-model-policy/index.ts +45 -3
  267. package/src/process-model-policy/project.ts +62 -76
  268. package/src/process-model-policy/types.ts +26 -0
  269. package/src/process-model-policy-presenter.ts +7 -3
  270. package/src/process-runtime-availability.ts +9 -4
  271. package/src/process-turn-trace.ts +12 -24
  272. package/src/process-ui-snapshot-presenter.ts +210 -295
  273. package/src/routes/future-executions.ts +5 -5
  274. package/src/routes/launchers.ts +51 -1
  275. package/src/routes/process-actions.ts +9 -9
  276. package/src/routes/process-detail.ts +25 -2
  277. package/src/routes/process-model-config.ts +70 -0
  278. package/src/routes/process-route-helpers.ts +153 -162
  279. package/src/routes/processes.ts +2 -0
  280. package/src/routes/settings.ts +173 -0
  281. package/src/routes/ticket-creation.ts +28 -5
  282. package/src/scoped-settings-service.ts +736 -0
  283. package/src/server-bootstrap/build-host-capabilities.ts +42 -0
  284. package/src/server-bootstrap/register-http.ts +7 -1
  285. package/src/session-summary-projection.ts +1 -2
  286. package/src/skills/bundled-skills.ts +64 -0
  287. package/src/skills/catalog-service.ts +35 -6
  288. package/src/skills/extension-importer.ts +97 -0
  289. package/src/skills/launch-skills.ts +19 -0
  290. package/src/skills/skill-frontmatter.ts +13 -0
  291. package/src/skills/source-importer.ts +3 -0
  292. package/src/startup-evidence.ts +20 -0
  293. package/src/supervisor/execution-inspection-ingestor.ts +55 -0
  294. package/src/supervisor/ipc-handler.ts +2 -0
  295. package/src/supervisor/worker-event-ingestor.ts +30 -14
  296. package/src/supervisor/worker-start-payload-builder.ts +17 -0
  297. package/src/supervisor/worker-supervisor.ts +3 -0
  298. package/src/test-helpers/prepared-fixture-start.ts +1 -0
  299. package/src/test-helpers/process-model-fixtures.ts +2 -0
  300. package/src/test-helpers/scoped-settings-fixtures.ts +126 -0
  301. package/src/test-helpers/skill-fixtures.ts +28 -0
  302. package/src/tool-approval-gate.ts +16 -0
  303. package/src/turn-progress.ts +3 -2
  304. package/src/turn-wait-service.ts +228 -0
  305. package/src/worker-runtime-profile-selection.ts +8 -1
  306. package/dist/app-MSJXFK33.js +0 -8
  307. package/dist/chunk-HK6BLLHA.js.map +0 -1
  308. package/dist/chunk-QCHS3X33.js.map +0 -1
  309. /package/dist/{app-MSJXFK33.js.map → app-JM4CBTND.js.map} +0 -0
@@ -0,0 +1,176 @@
1
+ import { createHash } from "node:crypto";
2
+ import {
3
+ asUnknownRecord,
4
+ type ExecutionInspectionRecord,
5
+ type ProcessEvent,
6
+ type ProcessTurnRecord,
7
+ } from "@leitwerk-dev/domain";
8
+ import type {
9
+ InspectionTraceBlock,
10
+ InspectionTraceMessage,
11
+ PiSessionContentBlock,
12
+ } from "@leitwerk-dev/protocol";
13
+ import type { ReadonlyPiSessionTree } from "./pi-session-tree.js";
14
+
15
+ function blocks(messageId: string, content: unknown): InspectionTraceBlock[] {
16
+ const raw =
17
+ typeof content === "string"
18
+ ? [{ type: "text", text: content }]
19
+ : Array.isArray(content)
20
+ ? content
21
+ : [];
22
+ const occurrences = new Map<string, number>();
23
+ return raw.flatMap((value) => {
24
+ const block = asUnknownRecord(value);
25
+ if (!block) return [];
26
+ let safe: PiSessionContentBlock;
27
+ if (block.type === "text" && typeof block.text === "string")
28
+ safe = { type: "text", text: block.text };
29
+ else if (block.type === "thinking" && typeof block.thinking === "string")
30
+ safe = {
31
+ type: "thinking",
32
+ thinking: block.thinking,
33
+ ...(block.redacted === true ? { redacted: true } : {}),
34
+ };
35
+ else if (
36
+ block.type === "toolCall" &&
37
+ typeof block.id === "string" &&
38
+ typeof block.name === "string"
39
+ )
40
+ safe = {
41
+ type: "toolCall",
42
+ id: block.id,
43
+ name: block.name,
44
+ arguments: asUnknownRecord(block.arguments) ?? {},
45
+ };
46
+ else if (
47
+ block.type === "image" &&
48
+ typeof block.data === "string" &&
49
+ typeof block.mimeType === "string"
50
+ )
51
+ safe = { type: "image", data: block.data, mimeType: block.mimeType };
52
+ else
53
+ safe = {
54
+ type: "text",
55
+ text: `[Unsupported recorded ${String(block.type ?? "content")} block]`,
56
+ };
57
+ const fingerprint = createHash("sha256").update(JSON.stringify(safe)).digest("hex");
58
+ const occurrence = occurrences.get(fingerprint) ?? 0;
59
+ occurrences.set(fingerprint, occurrence + 1);
60
+ const id = createHash("sha256")
61
+ .update(`${messageId}\0${fingerprint}\0${occurrence}`)
62
+ .digest("hex")
63
+ .slice(0, 24);
64
+ return [{ id: `block:${id}`, content: safe }];
65
+ });
66
+ }
67
+
68
+ /** Preserve session roles, message order and model-facing blocks. @internal */
69
+ export function buildInspectionTraceMessages(input: {
70
+ tree: ReadonlyPiSessionTree;
71
+ record: ProcessTurnRecord;
72
+ scope?: "execution" | "unassigned_branch";
73
+ owner(entryId: string): string | null;
74
+ captures: readonly ExecutionInspectionRecord[];
75
+ events: readonly ProcessEvent[];
76
+ }): InspectionTraceMessage[] {
77
+ const messages: InspectionTraceMessage[] = [];
78
+ const included = new Set<string>();
79
+ const unassigned = input.scope === "unassigned_branch";
80
+ const entries = unassigned
81
+ ? input.record.resultPiEntryId
82
+ ? input.tree.getBranch(input.record.resultPiEntryId)
83
+ : []
84
+ : input.tree.entries;
85
+ for (const entry of entries) {
86
+ if (unassigned) {
87
+ if (input.owner(entry.id) !== null || !["message", "custom_message"].includes(entry.type))
88
+ continue;
89
+ } else if (input.owner(entry.id) !== input.record.id) continue;
90
+ const message =
91
+ entry.type === "message"
92
+ ? entry.message
93
+ : entry.type === "custom_message"
94
+ ? { role: "user", content: entry.content }
95
+ : {
96
+ role: entry.type,
97
+ content:
98
+ entry.type === "compaction"
99
+ ? entry.summary
100
+ : entry.type === "model_change"
101
+ ? `Model changed to ${entry.provider}/${entry.modelId}`
102
+ : `Recorded ${entry.type.replaceAll("_", " ")} session entry`,
103
+ };
104
+ const record = message as unknown as Record<string, unknown>;
105
+ const id = `entry:${entry.id}`;
106
+ const link = input.captures.find(
107
+ (item) => item.fact.kind === "entry_link" && item.fact.entryId === entry.id,
108
+ );
109
+ const piTurnId = link?.fact.kind === "entry_link" ? link.fact.piTurnId : null;
110
+ const aliases =
111
+ link && piTurnId
112
+ ? input.events
113
+ .filter((event) => {
114
+ if (event.data.workerLeaseId !== link.workerLeaseId || event.data.turnId !== piTurnId)
115
+ return false;
116
+ if (message.role === "assistant")
117
+ return (
118
+ event.eventType === "pi.stream.delta" ||
119
+ (["pi.tool.call", "pi.tool.started"].includes(event.eventType) &&
120
+ Array.isArray(record.content) &&
121
+ record.content.some(
122
+ (block) => block.type === "toolCall" && block.id === event.data.toolCallId,
123
+ ))
124
+ );
125
+ return (
126
+ message.role === "toolResult" &&
127
+ ["pi.tool.result", "pi.tool.completed"].includes(event.eventType) &&
128
+ event.data.toolCallId === record.toolCallId
129
+ );
130
+ })
131
+ .map((event) => `event:${event.eventSequence}`)
132
+ : [];
133
+ messages.push({
134
+ id,
135
+ entryId: entry.id,
136
+ aliases,
137
+ role: message.role,
138
+ timestamp: entry.timestamp,
139
+ blocks: blocks(id, record.content),
140
+ toolCallId: typeof record.toolCallId === "string" ? record.toolCallId : null,
141
+ toolName: typeof record.toolName === "string" ? record.toolName : null,
142
+ isError: record.isError === true,
143
+ });
144
+ included.add(entry.id);
145
+ }
146
+ if (unassigned) return messages;
147
+ // Prompt evidence is available before the next session upload. Do not copy
148
+ // inherited messages out of a model input into this execution's activity.
149
+ for (const capture of input.captures) {
150
+ if (capture.fact.kind !== "model_input") continue;
151
+ for (const message of capture.fact.messages) {
152
+ if (
153
+ message.role !== "user" ||
154
+ !message.entryId ||
155
+ included.has(message.entryId) ||
156
+ input.owner(message.entryId) !== input.record.id
157
+ )
158
+ continue;
159
+ if (message.content.state !== "recorded" && message.content.state !== "redacted") continue;
160
+ const id = `entry:${message.entryId}`;
161
+ messages.push({
162
+ id,
163
+ entryId: message.entryId,
164
+ aliases: [],
165
+ role: message.role,
166
+ timestamp: capture.timestamp,
167
+ blocks: blocks(id, message.content.value),
168
+ toolCallId: null,
169
+ toolName: null,
170
+ isError: false,
171
+ });
172
+ included.add(message.entryId);
173
+ }
174
+ }
175
+ return messages.sort((a, b) => a.timestamp.localeCompare(b.timestamp));
176
+ }
@@ -0,0 +1,169 @@
1
+ import type {
2
+ InspectionContextObservation,
3
+ InspectionEvidence,
4
+ PreparedTurnStart,
5
+ ProcessTurnRecord,
6
+ WorkerLease,
7
+ } from "@leitwerk-dev/domain";
8
+ import type { ExecutionContextOrigin, InspectionBoundary } from "@leitwerk-dev/protocol";
9
+ import type { ReadonlyPiSessionTree } from "./pi-session-tree.js";
10
+
11
+ interface LineageInput {
12
+ records: readonly ProcessTurnRecord[];
13
+ leases: readonly WorkerLease[];
14
+ observations: readonly InspectionContextObservation[];
15
+ tree?: ReadonlyPiSessionTree;
16
+ }
17
+
18
+ /** Recorded start receipts remain usable for executions predating inspection capture. */
19
+ function preparedStart(input: LineageInput, record: ProcessTurnRecord): PreparedTurnStart | null {
20
+ const supplied = input.observations.find(
21
+ (item) => item.turnRecordId === record.id && item.fact.kind === "supplied_context",
22
+ );
23
+ if (supplied?.fact.kind === "supplied_context" && supplied.fact.origin)
24
+ return supplied.fact.origin;
25
+ const receipt = input.leases.find(
26
+ (lease) => lease.id === record.acceptedWorkerLeaseId,
27
+ )?.bootstrapReceipt;
28
+ return receipt?.kind === "llm" && receipt.startRecordId === record.turnStartRecordId
29
+ ? receipt.preparedStart
30
+ : null;
31
+ }
32
+
33
+ /** Pure ownership and ancestry projection; current workflow definitions are not an input. @internal */
34
+ export function createInspectionLineage(input: LineageInput) {
35
+ const records = new Map(input.records.map((record) => [record.id, record]));
36
+ const starts = new Map(
37
+ input.records
38
+ .filter((record) => record.turnStartRecordId)
39
+ .map((record) => [record.turnStartRecordId, record.id]),
40
+ );
41
+ const candidates = new Map<string, Set<string>>();
42
+ const boundaryFor = (record: ProcessTurnRecord): string | null => {
43
+ const prepared = preparedStart(input, record);
44
+ return prepared?.forkPiEntryId ?? record.forkPiEntryId;
45
+ };
46
+ const claim = (entryId: string, recordId: string) => {
47
+ if (!records.has(recordId)) return;
48
+ const owners = candidates.get(entryId) ?? new Set<string>();
49
+ owners.add(recordId);
50
+ candidates.set(entryId, owners);
51
+ };
52
+ for (const record of input.records) {
53
+ // A failure before writing an entry can retain the inherited leaf as its result.
54
+ // That reference does not transfer ownership of the parent's entry.
55
+ if (record.resultPiEntryId && record.resultPiEntryId !== boundaryFor(record))
56
+ claim(record.resultPiEntryId, record.id);
57
+ }
58
+ for (const item of input.observations)
59
+ if (item.fact.kind === "entry_link") claim(item.fact.entryId, item.turnRecordId);
60
+ for (const entry of input.tree?.entries ?? []) {
61
+ if (entry.type !== "custom_message" && entry.type !== "compaction") continue;
62
+ const details = entry.details as Record<string, unknown> | undefined;
63
+ if (
64
+ details &&
65
+ (details.kind === "turn_prompt" || details.kind === "turn_compaction") &&
66
+ typeof details.startRecordId === "string"
67
+ ) {
68
+ const owner = starts.get(details.startRecordId);
69
+ if (owner) claim(entry.id, owner);
70
+ }
71
+ }
72
+ const explicit = new Set(candidates.keys());
73
+ // Bound legacy ownership by recorded start/result entries. Extending the owner
74
+ // of an earlier result to arbitrary later descendants would invent lineage.
75
+ for (const record of input.records) {
76
+ if (!record.resultPiEntryId || !input.tree?.getEntry(record.resultPiEntryId)) continue;
77
+ const branch = input.tree.getBranch(record.resultPiEntryId);
78
+ const prepared = preparedStart(input, record);
79
+ const boundary = prepared?.forkPiEntryId ?? record.forkPiEntryId;
80
+ const boundaryIndex = boundary ? branch.findIndex((entry) => entry.id === boundary) : -1;
81
+ const promptIndex = branch.findIndex((entry) => {
82
+ if (entry.type !== "custom_message") return false;
83
+ const details = entry.details as Record<string, unknown> | undefined;
84
+ return details?.kind === "turn_prompt" && details.startRecordId === record.turnStartRecordId;
85
+ });
86
+ const first =
87
+ promptIndex >= 0
88
+ ? promptIndex
89
+ : boundaryIndex >= 0
90
+ ? boundaryIndex + 1
91
+ : prepared?.startTarget.kind === "root"
92
+ ? 0
93
+ : -1;
94
+ if (first < 0) continue;
95
+ for (const entry of branch.slice(first))
96
+ if (!explicit.has(entry.id)) claim(entry.id, record.id);
97
+ }
98
+ const inheritedOwner = (entryId: string): string | null => {
99
+ const owners = candidates.get(entryId);
100
+ return owners?.size === 1 ? [...owners][0] : null;
101
+ };
102
+ const origin = (record: ProcessTurnRecord): ExecutionContextOrigin => {
103
+ const unknown = {
104
+ state: "not_recorded",
105
+ reason: "Historical context origin was not recorded",
106
+ } as const;
107
+ if (record.turnType !== "llm") {
108
+ const none = {
109
+ state: "not_applicable",
110
+ reason: `This ${record.turnType} execution does not invoke a model`,
111
+ } as const;
112
+ return {
113
+ authoredMode: none,
114
+ startTarget: none,
115
+ conversation: none,
116
+ structuralPath: record.pathType,
117
+ summary: none.reason,
118
+ };
119
+ }
120
+ const prepared = preparedStart(input, record);
121
+ const boundaryId = boundaryFor(record);
122
+ let conversation: InspectionEvidence<InspectionBoundary | null> = unknown;
123
+ if (boundaryId)
124
+ conversation = {
125
+ state: "recorded",
126
+ value: { entryId: boundaryId, turnRecordId: inheritedOwner(boundaryId) },
127
+ };
128
+ else if (
129
+ prepared &&
130
+ (prepared.startTarget.kind === "root" || prepared.startTarget.kind === "current_leaf")
131
+ )
132
+ conversation = { state: "recorded", value: null };
133
+ const source = conversation.state === "recorded" ? conversation.value : undefined;
134
+ const summary =
135
+ source === null
136
+ ? "No inherited conversation · supplied inputs may still apply"
137
+ : source
138
+ ? `${prepared?.contextMode === "compacted" ? "Compacted conversation" : "Conversation inherited"} through ${source.entryId}${source.turnRecordId ? "" : " · source execution unknown"}`
139
+ : "Conversation origin not recorded";
140
+ return {
141
+ authoredMode: prepared ? { state: "recorded", value: prepared.contextMode } : unknown,
142
+ startTarget: prepared ? { state: "recorded", value: prepared.startTarget } : unknown,
143
+ conversation,
144
+ structuralPath: record.pathType,
145
+ summary,
146
+ };
147
+ };
148
+ const ancestry = (record: ProcessTurnRecord) => {
149
+ const result: Array<{ turnRecordId: string; turnId: string; boundaryEntryId: string }> = [];
150
+ const visited = new Set([record.id]);
151
+ let current = record;
152
+ while (true) {
153
+ const context = origin(current).conversation;
154
+ const source = context.state === "recorded" ? context.value : null;
155
+ if (!source?.turnRecordId || visited.has(source.turnRecordId)) break;
156
+ const parent = records.get(source.turnRecordId);
157
+ if (!parent) break;
158
+ visited.add(parent.id);
159
+ result.push({
160
+ turnRecordId: parent.id,
161
+ turnId: parent.turnId,
162
+ boundaryEntryId: source.entryId,
163
+ });
164
+ current = parent;
165
+ }
166
+ return result;
167
+ };
168
+ return { owner: inheritedOwner, origin, ancestry, boundaryFor };
169
+ }
@@ -1,7 +1,8 @@
1
1
  import type {
2
+ InspectionContextObservation,
2
3
  ProcessInstance,
3
- ProcessTurnAnnotation,
4
4
  ProcessTurnRecord,
5
+ WorkerLease,
5
6
  } from "@leitwerk-dev/domain";
6
7
  import type {
7
8
  InstanceTreeEdgeSummary,
@@ -9,8 +10,7 @@ import type {
9
10
  ProcessInstanceTreeResponseBody,
10
11
  ProcessRunTurnView,
11
12
  } from "@leitwerk-dev/protocol/http-contracts";
12
-
13
- type Decision = InstanceTreeEdgeSummary & { timestamp: string };
13
+ import { createInspectionLineage } from "./process-inspection.js";
14
14
 
15
15
  function titleCase(value: string): string {
16
16
  return value
@@ -18,179 +18,31 @@ function titleCase(value: string): string {
18
18
  .replaceAll(/\b\w/g, (character) => character.toUpperCase());
19
19
  }
20
20
 
21
- function payloadString(annotation: ProcessTurnAnnotation, key: string): string | null {
22
- const value = annotation.payload[key];
23
- return typeof value === "string" && value.trim() ? value.trim() : null;
24
- }
25
-
26
- function nextLlmAfterAutomatic(
27
- automatic: ProcessTurnRecord,
28
- allRecords: readonly ProcessTurnRecord[],
29
- ): ProcessTurnRecord | undefined {
30
- const start = allRecords.findIndex((record) => record.id === automatic.id) + 1;
31
- for (let index = start; index > 0 && index < allRecords.length; index += 1) {
32
- const record = allRecords[index];
33
- if (record.turnType === "human" || record.turnType === "external") return undefined;
34
- if (record.turnType === "llm") return record;
35
- }
36
- return undefined;
37
- }
38
-
39
- function actionDecisions(
40
- process: ProcessInstance,
41
- annotations: readonly ProcessTurnAnnotation[],
42
- allRecords: readonly ProcessTurnRecord[],
43
- llmRecords: readonly ProcessTurnRecord[],
44
- ): Decision[] {
45
- const llmById = new Map(llmRecords.map((record) => [record.id, record]));
46
- const claimedTargets = new Set<string>();
47
- const decisions: Decision[] = [];
48
- const candidates = annotations
49
- .filter(
50
- (annotation) =>
51
- annotation.annotationType === "acceptance_state" ||
52
- annotation.annotationType === "external_trigger",
53
- )
54
- .sort(
55
- (left, right) =>
56
- left.createdAt.localeCompare(right.createdAt) || left.id.localeCompare(right.id),
57
- );
58
- for (const annotation of candidates) {
59
- const actionLabel =
60
- payloadString(annotation, "actionLabel") ?? payloadString(annotation, "triggerLabel");
61
- if (!actionLabel) continue;
62
-
63
- const recordedSourceId = payloadString(annotation, "sourceTurnRecordId");
64
- const source =
65
- (recordedSourceId ? llmById.get(recordedSourceId) : undefined) ??
66
- llmRecords.findLast((record) => record.startedAt.localeCompare(annotation.createdAt) <= 0);
67
- if (!source) continue;
68
-
69
- const causedTurnId = payloadString(annotation, "causedSelectedTurnId");
70
- const causedTurnType = annotation.payload.causedSelectedTurnType;
71
- const findCaused = (turnType: string) =>
72
- causedTurnId
73
- ? allRecords.find(
74
- (record) =>
75
- record.turnType === turnType &&
76
- record.turnId === causedTurnId &&
77
- record.startedAt.localeCompare(annotation.createdAt) >= 0 &&
78
- !claimedTargets.has(record.id),
79
- )
80
- : undefined;
81
- const directTarget =
82
- causedTurnType === undefined || causedTurnType === "llm" ? findCaused("llm") : undefined;
83
- const causedAutomatic = causedTurnType === "automatic" ? findCaused(causedTurnType) : undefined;
84
- const target =
85
- directTarget ??
86
- (causedAutomatic ? nextLlmAfterAutomatic(causedAutomatic, allRecords) : undefined);
87
- if (target) claimedTargets.add(target.id);
88
- const isUnapplied = causedTurnType === "human" || causedTurnType === "external";
89
- decisions.push({
90
- id: annotation.id,
91
- sourceNodeId: source.id,
92
- targetNodeId: target?.id ?? null,
93
- hasContext: false,
94
- productLabels: [],
95
- actionLabel,
96
- endState: isUnapplied
97
- ? "not_applied"
98
- : causedAutomatic && !target && process.lifecycleStatus === "completed"
99
- ? "completed"
100
- : null,
101
- timestamp: annotation.createdAt,
102
- });
103
- }
104
- return decisions;
105
- }
106
-
107
- function automaticTransitions(
108
- process: ProcessInstance,
109
- annotations: readonly ProcessTurnAnnotation[],
110
- allRecords: readonly ProcessTurnRecord[],
111
- llmRecords: readonly ProcessTurnRecord[],
112
- ): Decision[] {
113
- const actionCausedAutomaticIds = new Set<string>();
114
- for (const annotation of annotations) {
115
- const causedTurnId = annotation.payload.causedSelectedTurnId;
116
- const causedTurnType = annotation.payload.causedSelectedTurnType;
117
- if (typeof causedTurnId !== "string" || causedTurnType !== "automatic") {
118
- continue;
119
- }
120
- const caused = allRecords.find(
121
- (record) =>
122
- record.turnType === causedTurnType &&
123
- record.turnId === causedTurnId &&
124
- record.startedAt.localeCompare(annotation.createdAt) >= 0,
125
- );
126
- if (caused) actionCausedAutomaticIds.add(caused.id);
127
- }
128
-
129
- const transitions: Decision[] = [];
130
- for (const automatic of allRecords.filter((record) => record.turnType === "automatic")) {
131
- if (actionCausedAutomaticIds.has(automatic.id)) continue;
132
- const source = llmRecords.findLast(
133
- (record) => record.startedAt.localeCompare(automatic.startedAt) < 0,
134
- );
135
- if (!source) continue;
136
- const target = nextLlmAfterAutomatic(automatic, allRecords);
137
- const completesProcess =
138
- allRecords.at(-1)?.id === automatic.id && process.lifecycleStatus === "completed";
139
- if (!target && !completesProcess) continue;
140
- transitions.push({
141
- id: `automatic:${automatic.id}`,
142
- sourceNodeId: source.id,
143
- targetNodeId: target?.id ?? null,
144
- hasContext: false,
145
- productLabels: [],
146
- actionLabel: titleCase(automatic.turnId),
147
- endState: target ? null : "completed",
148
- timestamp: automatic.startedAt,
149
- });
150
- }
151
- return transitions;
152
- }
153
-
154
- /** Projects actual Pi turn lineage and redacted prompt/product provenance. */
21
+ /** Compact recorded context relationships. Current definitions supply labels only. @internal */
155
22
  export function presentProcessInstanceTree(input: {
156
23
  process: ProcessInstance;
157
24
  turnRecords: readonly ProcessTurnRecord[];
158
- turnAnnotations?: readonly ProcessTurnAnnotation[];
25
+ leases?: readonly WorkerLease[];
26
+ observations?: readonly InspectionContextObservation[];
159
27
  turnDetails?: readonly ProcessRunTurnView[];
160
28
  currentPiEntryId?: string | null;
161
29
  }): ProcessInstanceTreeResponseBody {
162
- const allRecords = [...input.turnRecords].sort(
163
- (left, right) =>
164
- left.startedAt.localeCompare(right.startedAt) || left.id.localeCompare(right.id),
165
- );
166
- const records = allRecords.filter((record) => record.turnType === "llm");
167
- const detailsByTurnId = new Map(
168
- (input.turnDetails ?? []).map((detail) => [detail.turnId, detail] as const),
169
- );
170
- const byResultEntryId = new Map(
171
- records
172
- .filter((record) => record.resultPiEntryId)
173
- .map((record) => [record.resultPiEntryId as string, record] as const),
30
+ const records = [...input.turnRecords].sort(
31
+ (a, b) => a.startedAt.localeCompare(b.startedAt) || a.id.localeCompare(b.id),
174
32
  );
175
- const annotations = input.turnAnnotations ?? [];
176
- const decisions = [
177
- ...actionDecisions(input.process, annotations, allRecords, records),
178
- ...automaticTransitions(input.process, annotations, allRecords, records),
179
- ].sort(
180
- (left, right) =>
181
- left.timestamp.localeCompare(right.timestamp) || left.id.localeCompare(right.id),
182
- );
183
- const current =
184
- input.process.lifecycleStatus === "completed" || input.process.lifecycleStatus === "aborted"
185
- ? null
186
- : (byResultEntryId.get(input.currentPiEntryId ?? "")?.id ?? records.at(-1)?.id ?? null);
33
+ const observations = input.observations ?? [];
34
+ const lineage = createInspectionLineage({ records, observations, leases: input.leases ?? [] });
35
+ const labels = new Map(input.turnDetails?.map((turn) => [turn.turnId, turn.description]));
187
36
  const nodes: InstanceTreeNodeSummary[] = records.map((record) => {
188
- const detail = detailsByTurnId.get(record.turnId);
189
- const parent = record.forkPiEntryId ? byResultEntryId.get(record.forkPiEntryId) : undefined;
37
+ const origin = lineage.origin(record);
38
+ const source = origin.conversation.state === "recorded" ? origin.conversation.value : null;
190
39
  return {
191
40
  id: record.id,
192
- parentId: parent?.id ?? null,
193
- label: detail?.description ?? titleCase(record.turnId),
41
+ turnId: record.turnId,
42
+ turnType: record.turnType,
43
+ origin,
44
+ parentId: source?.turnRecordId === record.id ? null : (source?.turnRecordId ?? null),
45
+ label: labels.get(record.turnId) ?? titleCase(record.turnId),
194
46
  pathType: record.pathType,
195
47
  resultState:
196
48
  record.status === "succeeded"
@@ -203,60 +55,48 @@ export function presentProcessInstanceTree(input: {
203
55
  timestamp: record.startedAt,
204
56
  };
205
57
  });
206
-
207
- type MutableEdge = Omit<InstanceTreeEdgeSummary, "productLabels"> & {
208
- productLabels: string[];
209
- };
210
- const edgesByKey = new Map<string, MutableEdge>();
211
- const connect = (sourceNodeId: string, targetNodeId: string): MutableEdge => {
212
- const key = `${sourceNodeId}->${targetNodeId}`;
213
- const existing = edgesByKey.get(key);
214
- if (existing) return existing;
215
- const edge: MutableEdge = {
216
- id: key,
217
- sourceNodeId,
218
- targetNodeId,
219
- hasContext: false,
220
- productLabels: [],
221
- actionLabel: null,
222
- endState: null,
223
- };
224
- edgesByKey.set(key, edge);
225
- return edge;
226
- };
227
-
228
- for (const [index, node] of nodes.entries()) {
229
- const record = records[index];
230
- if (node.parentId) connect(node.parentId, node.id).hasContext = true;
231
- const detail = detailsByTurnId.get(record.turnId);
232
- for (const productName of detail?.consumedProducts ?? []) {
233
- const publisher = records.findLast(
234
- (candidate) =>
235
- candidate.startedAt.localeCompare(record.startedAt) < 0 &&
236
- candidate.status === "succeeded" &&
237
- (detailsByTurnId.get(candidate.turnId)?.publishedProducts ?? []).includes(productName),
238
- );
239
- if (publisher) connect(publisher.id, record.id).productLabels.push(titleCase(productName));
240
- }
241
- }
242
-
243
- const terminalEdges: InstanceTreeEdgeSummary[] = [];
244
- for (const { timestamp: _, ...decision } of decisions) {
245
- if (!decision.targetNodeId) {
246
- terminalEdges.push(decision);
58
+ const edges: InstanceTreeEdgeSummary[] = nodes.flatMap((node) =>
59
+ node.parentId
60
+ ? [
61
+ {
62
+ id: `conversation:${node.id}`,
63
+ sourceNodeId: node.parentId,
64
+ targetNodeId: node.id,
65
+ hasContext: true,
66
+ productLabels: [],
67
+ actionLabel: null,
68
+ endState: null,
69
+ },
70
+ ]
71
+ : [],
72
+ );
73
+ const byId = new Map(records.map((record) => [record.id, record]));
74
+ for (const observation of observations) {
75
+ if (observation.fact.kind !== "supplied_context" || !byId.has(observation.turnRecordId))
247
76
  continue;
77
+ for (const product of observation.fact.products) {
78
+ const producer = byId.get(product.producerTurnRecordId);
79
+ if (!producer || producer.resultPiEntryId !== product.entryId) continue;
80
+ edges.push({
81
+ id: `product:${observation.id}:${product.name}`,
82
+ sourceNodeId: producer.id,
83
+ targetNodeId: observation.turnRecordId,
84
+ hasContext: false,
85
+ productLabels: [product.name],
86
+ actionLabel: null,
87
+ endState: null,
88
+ });
248
89
  }
249
- const target = nodes.find((node) => node.id === decision.targetNodeId);
250
- const input = target?.parentId
251
- ? connect(target.parentId, target.id)
252
- : [...edgesByKey.values()].find((edge) => edge.targetNodeId === target?.id);
253
- (input ?? connect(decision.sourceNodeId, decision.targetNodeId)).actionLabel =
254
- decision.actionLabel;
255
90
  }
256
-
257
91
  return {
258
- currentLeafId: current,
92
+ currentLeafId:
93
+ input.process.lifecycleStatus === "completed" || input.process.lifecycleStatus === "aborted"
94
+ ? null
95
+ : (records.find((record) => record.turnStartRecordId === input.process.currentExecution?.id)
96
+ ?.id ??
97
+ records.find((record) => record.status === "running")?.id ??
98
+ (input.currentPiEntryId ? lineage.owner(input.currentPiEntryId) : null)),
259
99
  nodes,
260
- edges: [...edgesByKey.values(), ...terminalEdges],
100
+ edges,
261
101
  };
262
102
  }
@@ -16,6 +16,7 @@ import {
16
16
  import type { EngineFailure, ProcessEngine, ProcessEngineLogger } from "./process-engine/types.js";
17
17
  import type { ProcessTitleGenerator } from "./process-title-generator.js";
18
18
  import { buildProjectUpdatedEffect } from "./project-mutation-service.js";
19
+ import { type LaunchSkillDefaults, resolveLaunchSkills } from "./skills/launch-skills.js";
19
20
  import type { WorkerSupervisor } from "./supervisor/worker-supervisor.js";
20
21
  import type { Broadcaster } from "./ws/broadcast.js";
21
22
 
@@ -57,6 +58,7 @@ export interface ProcessLaunchExecutorDeps
57
58
  repositoryCredentials?: import("./repository-credentials/service.js").RepositoryCredentialService;
58
59
  /** Runner requirement check executed before the durable launch transaction. */
59
60
  assertRuntimeAvailable?: (processId: string) => Promise<void>;
61
+ skillDefaults?: LaunchSkillDefaults;
60
62
  }
61
63
 
62
64
  /** @internal */
@@ -191,6 +193,7 @@ export function commitProcessLaunch(
191
193
  relation?: ProcessLaunchRelationInput,
192
194
  actor?: Actor,
193
195
  ): ProcessLaunchCommit {
196
+ if (launchPlan.preview) throw new Error("Launcher previews cannot be committed");
194
197
  return deps.transaction((repos) => {
195
198
  if (launchRunId) {
196
199
  repos.launchRuns.saveReplay(launchRunId, {
@@ -394,9 +397,9 @@ async function createProcessFromLaunchPlanWithDisposition(
394
397
  };
395
398
  }
396
399
  let resourceSelections = opts?.resourceSelections;
397
- if (!resourceSelections && launchPlan.skillIds) {
400
+ if (resourceSelections === undefined) {
398
401
  try {
399
- resourceSelections = deps.skills.resolveActive(launchPlan.skillIds);
402
+ resourceSelections = resolveLaunchSkills(deps, launchPlan.processId, launchPlan.skillIds);
400
403
  } catch (error) {
401
404
  return {
402
405
  ok: false,