@leitwerk-dev/server 0.3.1 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{app-BuJCdkvy.d.ts → app-CtlotzYm.d.ts} +312 -121
- package/dist/app-KR3N2JAE.js +8 -0
- package/dist/app.d.ts +9 -0
- package/dist/app.d.ts.map +1 -1
- package/dist/auth/fastify-auth.d.ts +9 -0
- package/dist/auth/fastify-auth.d.ts.map +1 -1
- package/dist/{chunk-QCHS3X33.js → chunk-OUA5EZS2.js} +3127 -689
- package/dist/chunk-OUA5EZS2.js.map +1 -0
- package/dist/{chunk-HK6BLLHA.js → chunk-YLWY4UTT.js} +2424 -1580
- package/dist/chunk-YLWY4UTT.js.map +1 -0
- package/dist/config/config-loader.d.ts +1 -1
- package/dist/config/config-loader.d.ts.map +1 -1
- package/dist/config/config-types.d.ts +16 -1
- package/dist/config/config-types.d.ts.map +1 -1
- package/dist/config/kubernetes-docker-isolation.d.ts +7 -0
- package/dist/config/kubernetes-docker-isolation.d.ts.map +1 -0
- package/dist/dashboard-model-issues.d.ts +10 -0
- package/dist/dashboard-model-issues.d.ts.map +1 -0
- package/dist/db/database.d.ts.map +1 -1
- package/dist/db/execution-inspection-repo.d.ts +15 -0
- package/dist/db/execution-inspection-repo.d.ts.map +1 -0
- package/dist/db/history-window.d.ts +11 -0
- package/dist/db/history-window.d.ts.map +1 -0
- package/dist/db/process-event-repo.d.ts +2 -0
- package/dist/db/process-event-repo.d.ts.map +1 -1
- package/dist/db/process-instance-repo.d.ts +21 -1
- package/dist/db/process-instance-repo.d.ts.map +1 -1
- package/dist/db/process-leaf-outcome-snapshot-repo.d.ts +2 -1
- package/dist/db/process-leaf-outcome-snapshot-repo.d.ts.map +1 -1
- package/dist/db/process-project-repo.d.ts +2 -0
- package/dist/db/process-project-repo.d.ts.map +1 -1
- package/dist/db/process-skill-repo.d.ts.map +1 -1
- package/dist/db/process-turn-annotation-repo.d.ts +4 -1
- package/dist/db/process-turn-annotation-repo.d.ts.map +1 -1
- package/dist/db/process-turn-record-repo.d.ts +4 -0
- package/dist/db/process-turn-record-repo.d.ts.map +1 -1
- package/dist/db/publication-repo.d.ts +5 -0
- package/dist/db/publication-repo.d.ts.map +1 -0
- package/dist/db/repositories.d.ts +12 -0
- package/dist/db/repositories.d.ts.map +1 -1
- package/dist/db/schema.d.ts +693 -2
- package/dist/db/schema.d.ts.map +1 -1
- package/dist/db/scoped-settings-repo.d.ts +37 -0
- package/dist/db/scoped-settings-repo.d.ts.map +1 -0
- package/dist/db/skill-repo.d.ts +3 -0
- package/dist/db/skill-repo.d.ts.map +1 -1
- package/dist/db/turn-start-record-repo.d.ts +2 -1
- package/dist/db/turn-start-record-repo.d.ts.map +1 -1
- package/dist/db/turn-summary-repo.d.ts +10 -1
- package/dist/db/turn-summary-repo.d.ts.map +1 -1
- package/dist/db/worker-lease-repo.d.ts +2 -1
- package/dist/db/worker-lease-repo.d.ts.map +1 -1
- package/dist/domain-logic/outcome-tools.d.ts.map +1 -1
- package/dist/domain-logic/worker-lease-lifecycle.d.ts.map +1 -1
- package/dist/external-source-service.d.ts.map +1 -1
- package/dist/future-execution/execution.d.ts +4 -1
- package/dist/future-execution/execution.d.ts.map +1 -1
- package/dist/future-execution/launch-lifecycle.d.ts +9 -25
- package/dist/future-execution/launch-lifecycle.d.ts.map +1 -1
- package/dist/future-execution/lifecycle.d.ts +3 -28
- package/dist/future-execution/lifecycle.d.ts.map +1 -1
- package/dist/future-execution/model-projection.d.ts.map +1 -1
- package/dist/future-execution/reconciliation.d.ts +1 -0
- package/dist/future-execution/reconciliation.d.ts.map +1 -1
- package/dist/future-execution-presenter.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/integration-tool-registry.d.ts +11 -2
- package/dist/integration-tool-registry.d.ts.map +1 -1
- package/dist/launch-coordinator.d.ts.map +1 -1
- package/dist/launcher-model-config-service.d.ts +7 -1
- package/dist/launcher-model-config-service.d.ts.map +1 -1
- package/dist/leaf-outcome-snapshot-capture.d.ts +1 -0
- package/dist/leaf-outcome-snapshot-capture.d.ts.map +1 -1
- package/dist/main.js +3 -3
- package/dist/primary-path-snapshot.d.ts.map +1 -1
- package/dist/process-action-presenter.d.ts +1 -6
- package/dist/process-action-presenter.d.ts.map +1 -1
- package/dist/process-action-registry.d.ts.map +1 -1
- package/dist/process-engine/decision.d.ts +2 -0
- package/dist/process-engine/decision.d.ts.map +1 -1
- package/dist/process-engine/engine.d.ts.map +1 -1
- package/dist/process-engine/mapped-turns.d.ts.map +1 -1
- package/dist/process-engine/ops/automatic-retry-startup.d.ts +8 -0
- package/dist/process-engine/ops/automatic-retry-startup.d.ts.map +1 -0
- package/dist/process-engine/ops/continue-failed-turn.d.ts.map +1 -1
- package/dist/process-engine/ops/process-observation.d.ts +6 -0
- package/dist/process-engine/ops/process-observation.d.ts.map +1 -0
- package/dist/process-engine/ops/retry-failed-turn.d.ts.map +1 -1
- package/dist/process-engine/ops/retry-startup.d.ts +2 -0
- package/dist/process-engine/ops/retry-startup.d.ts.map +1 -1
- package/dist/process-engine/ops/start-process.d.ts +2 -0
- package/dist/process-engine/ops/start-process.d.ts.map +1 -1
- package/dist/process-engine/ops/turn-outcome.d.ts.map +1 -1
- package/dist/process-engine/ops/turn-wait.d.ts +30 -0
- package/dist/process-engine/ops/turn-wait.d.ts.map +1 -0
- package/dist/process-engine/ops/update-model-config.d.ts +9 -0
- package/dist/process-engine/ops/update-model-config.d.ts.map +1 -0
- package/dist/process-engine/recorder.d.ts.map +1 -1
- package/dist/process-engine/turn-start-preflight.d.ts +6 -0
- package/dist/process-engine/turn-start-preflight.d.ts.map +1 -1
- package/dist/process-engine/turn-wait-state.d.ts +24 -0
- package/dist/process-engine/turn-wait-state.d.ts.map +1 -0
- package/dist/process-engine/turn-worker-requirement.d.ts +2 -0
- package/dist/process-engine/turn-worker-requirement.d.ts.map +1 -1
- package/dist/process-engine/types.d.ts +13 -2
- package/dist/process-engine/types.d.ts.map +1 -1
- package/dist/process-engine/writes/build-process-abort-writes.d.ts +3 -1
- package/dist/process-engine/writes/build-process-abort-writes.d.ts.map +1 -1
- package/dist/process-engine/writes/build-turn-outcome-writes.d.ts +2 -0
- package/dist/process-engine/writes/build-turn-outcome-writes.d.ts.map +1 -1
- package/dist/process-engine/writes/commit-writes.d.ts +2 -0
- package/dist/process-engine/writes/commit-writes.d.ts.map +1 -1
- package/dist/process-engine/writes/writes.d.ts +28 -60
- package/dist/process-engine/writes/writes.d.ts.map +1 -1
- package/dist/process-graph.d.ts +1 -1
- package/dist/process-graph.d.ts.map +1 -1
- package/dist/process-inspection-reader.d.ts +21 -0
- package/dist/process-inspection-reader.d.ts.map +1 -0
- package/dist/process-inspection-trace.d.ts +13 -0
- package/dist/process-inspection-trace.d.ts.map +1 -0
- package/dist/process-inspection.d.ts +22 -0
- package/dist/process-inspection.d.ts.map +1 -0
- package/dist/process-instance-tree-presenter.d.ts +4 -3
- package/dist/process-instance-tree-presenter.d.ts.map +1 -1
- package/dist/process-launch-executor.d.ts +2 -0
- package/dist/process-launch-executor.d.ts.map +1 -1
- package/dist/process-launch-plan.d.ts +1 -0
- package/dist/process-launch-plan.d.ts.map +1 -1
- package/dist/process-launcher-registry.d.ts.map +1 -1
- package/dist/process-model-availability-recovery.d.ts +1 -1
- package/dist/process-model-availability-recovery.d.ts.map +1 -1
- package/dist/process-model-config.d.ts +19 -0
- package/dist/process-model-config.d.ts.map +1 -0
- package/dist/process-model-policy/construct.d.ts.map +1 -1
- package/dist/process-model-policy/evaluate.d.ts.map +1 -1
- package/dist/process-model-policy/index.d.ts +4 -1
- package/dist/process-model-policy/index.d.ts.map +1 -1
- package/dist/process-model-policy/project.d.ts.map +1 -1
- package/dist/process-model-policy/types.d.ts +18 -0
- package/dist/process-model-policy/types.d.ts.map +1 -1
- package/dist/process-model-policy-presenter.d.ts.map +1 -1
- package/dist/process-runtime-availability.d.ts +2 -1
- package/dist/process-runtime-availability.d.ts.map +1 -1
- package/dist/process-turn-trace.d.ts.map +1 -1
- package/dist/process-ui-snapshot-presenter.d.ts +14 -3
- package/dist/process-ui-snapshot-presenter.d.ts.map +1 -1
- package/dist/routes/dashboard.d.ts +17 -0
- package/dist/routes/dashboard.d.ts.map +1 -0
- package/dist/routes/future-executions.d.ts.map +1 -1
- package/dist/routes/launchers.d.ts.map +1 -1
- package/dist/routes/process-actions.d.ts.map +1 -1
- package/dist/routes/process-detail.d.ts.map +1 -1
- package/dist/routes/process-model-config.d.ts +4 -0
- package/dist/routes/process-model-config.d.ts.map +1 -0
- package/dist/routes/process-route-helpers.d.ts +8 -9
- package/dist/routes/process-route-helpers.d.ts.map +1 -1
- package/dist/routes/processes.d.ts.map +1 -1
- package/dist/routes/settings.d.ts +11 -0
- package/dist/routes/settings.d.ts.map +1 -0
- package/dist/routes/ticket-creation.d.ts.map +1 -1
- package/dist/scoped-settings-service.d.ts +98 -0
- package/dist/scoped-settings-service.d.ts.map +1 -0
- package/dist/server-bootstrap/build-host-capabilities.d.ts +2 -0
- package/dist/server-bootstrap/build-host-capabilities.d.ts.map +1 -1
- package/dist/server-bootstrap/register-http.d.ts.map +1 -1
- package/dist/session-summary-projection.d.ts.map +1 -1
- package/dist/skills/bundled-skills.d.ts +5 -0
- package/dist/skills/bundled-skills.d.ts.map +1 -0
- package/dist/skills/catalog-service.d.ts +1 -0
- package/dist/skills/catalog-service.d.ts.map +1 -1
- package/dist/skills/extension-importer.d.ts +11 -0
- package/dist/skills/extension-importer.d.ts.map +1 -0
- package/dist/skills/launch-skills.d.ts +11 -0
- package/dist/skills/launch-skills.d.ts.map +1 -0
- package/dist/skills/skill-frontmatter.d.ts +7 -0
- package/dist/skills/skill-frontmatter.d.ts.map +1 -1
- package/dist/skills/source-importer.d.ts +3 -0
- package/dist/skills/source-importer.d.ts.map +1 -1
- package/dist/startup-evidence.d.ts +4 -3
- package/dist/startup-evidence.d.ts.map +1 -1
- package/dist/startup-retry-policy.d.ts +8 -0
- package/dist/startup-retry-policy.d.ts.map +1 -0
- package/dist/supervisor/execution-inspection-ingestor.d.ts +9 -0
- package/dist/supervisor/execution-inspection-ingestor.d.ts.map +1 -0
- package/dist/supervisor/ipc-handler.d.ts +2 -0
- package/dist/supervisor/ipc-handler.d.ts.map +1 -1
- package/dist/supervisor/worker-event-ingestor.d.ts +1 -0
- package/dist/supervisor/worker-event-ingestor.d.ts.map +1 -1
- package/dist/supervisor/worker-start-payload-builder.d.ts.map +1 -1
- package/dist/supervisor/worker-supervisor.d.ts +2 -0
- package/dist/supervisor/worker-supervisor.d.ts.map +1 -1
- package/dist/test-helpers/prepared-fixture-start.d.ts.map +1 -1
- package/dist/test-helpers/process-model-fixtures.d.ts +1 -0
- package/dist/test-helpers/process-model-fixtures.d.ts.map +1 -1
- package/dist/test-helpers/scoped-settings-fixtures.d.ts +16 -0
- package/dist/test-helpers/scoped-settings-fixtures.d.ts.map +1 -0
- package/dist/test-helpers/skill-fixtures.d.ts +4 -0
- package/dist/test-helpers/skill-fixtures.d.ts.map +1 -0
- package/dist/testing.js +2 -1
- package/dist/testing.js.map +1 -1
- package/dist/tool-approval-gate.d.ts +3 -0
- package/dist/tool-approval-gate.d.ts.map +1 -1
- package/dist/turn-progress.d.ts.map +1 -1
- package/dist/turn-wait-service.d.ts +28 -0
- package/dist/turn-wait-service.d.ts.map +1 -0
- package/dist/worker-runtime-profile-selection.d.ts +2 -0
- package/dist/worker-runtime-profile-selection.d.ts.map +1 -1
- package/package.json +20 -19
- package/src/app.ts +177 -25
- package/src/auth/fastify-auth.ts +13 -0
- package/src/config/config-loader.ts +42 -2
- package/src/config/config-types.ts +16 -1
- package/src/config/kubernetes-docker-isolation.ts +21 -0
- package/src/dashboard-model-issues.ts +199 -0
- package/src/db/database.ts +131 -40
- package/src/db/execution-inspection-repo.ts +163 -0
- package/src/db/history-window.ts +18 -0
- package/src/db/process-event-repo.ts +88 -10
- package/src/db/process-instance-repo.ts +33 -2
- package/src/db/process-leaf-outcome-snapshot-repo.ts +8 -2
- package/src/db/process-project-repo.ts +4 -0
- package/src/db/process-skill-repo.ts +9 -2
- package/src/db/process-turn-annotation-repo.ts +27 -9
- package/src/db/process-turn-record-repo.ts +45 -12
- package/src/db/publication-repo.ts +63 -0
- package/src/db/repositories.ts +17 -0
- package/src/db/schema.ts +103 -1
- package/src/db/scoped-settings-repo.ts +234 -0
- package/src/db/skill-repo.ts +89 -27
- package/src/db/turn-start-record-repo.ts +13 -3
- package/src/db/turn-summary-repo.ts +36 -4
- package/src/db/worker-lease-repo.ts +8 -2
- package/src/domain-logic/outcome-tools.ts +18 -216
- package/src/domain-logic/worker-lease-lifecycle.ts +2 -1
- package/src/external-source-service.ts +33 -7
- package/src/future-execution/execution.ts +9 -2
- package/src/future-execution/launch-lifecycle.ts +87 -78
- package/src/future-execution/lifecycle.ts +5 -34
- package/src/future-execution/model-projection.ts +2 -0
- package/src/future-execution/reconciliation.ts +7 -0
- package/src/future-execution-presenter.ts +7 -8
- package/src/integration-tool-registry.ts +59 -26
- package/src/launch-coordinator.ts +10 -1
- package/src/launcher-model-config-service.ts +24 -3
- package/src/leaf-outcome-snapshot-capture.ts +2 -0
- package/src/primary-path-snapshot.ts +3 -4
- package/src/process-action-presenter.ts +22 -57
- package/src/process-action-registry.ts +31 -39
- package/src/process-engine/decision.ts +10 -0
- package/src/process-engine/engine.ts +25 -2
- package/src/process-engine/mapped-turns.ts +5 -7
- package/src/process-engine/ops/automatic-retry-startup.ts +93 -0
- package/src/process-engine/ops/continue-failed-turn.ts +2 -13
- package/src/process-engine/ops/process-observation.ts +119 -0
- package/src/process-engine/ops/retry-failed-turn.ts +2 -12
- package/src/process-engine/ops/retry-startup.ts +20 -16
- package/src/process-engine/ops/start-process.ts +34 -2
- package/src/process-engine/ops/turn-outcome.ts +61 -60
- package/src/process-engine/ops/turn-wait.ts +225 -0
- package/src/process-engine/ops/update-model-config.ts +66 -0
- package/src/process-engine/recorder.ts +34 -5
- package/src/process-engine/turn-start-preflight.ts +168 -105
- package/src/process-engine/turn-wait-state.ts +126 -0
- package/src/process-engine/turn-worker-requirement.ts +4 -0
- package/src/process-engine/types.ts +21 -0
- package/src/process-engine/writes/build-process-abort-writes.ts +30 -20
- package/src/process-engine/writes/build-turn-outcome-writes.ts +39 -2
- package/src/process-engine/writes/commit-writes.ts +16 -4
- package/src/process-engine/writes/writes.ts +59 -74
- package/src/process-graph.ts +0 -1
- package/src/process-inspection-reader.ts +305 -0
- package/src/process-inspection-trace.ts +176 -0
- package/src/process-inspection.ts +169 -0
- package/src/process-instance-tree-presenter.ts +56 -216
- package/src/process-launch-executor.ts +5 -2
- package/src/process-launch-plan.ts +17 -2
- package/src/process-launcher-registry.ts +28 -16
- package/src/process-model-availability-recovery.ts +6 -4
- package/src/process-model-config.ts +100 -0
- package/src/process-model-policy/construct.ts +1 -0
- package/src/process-model-policy/evaluate.ts +34 -32
- package/src/process-model-policy/index.ts +45 -3
- package/src/process-model-policy/project.ts +62 -76
- package/src/process-model-policy/types.ts +26 -0
- package/src/process-model-policy-presenter.ts +7 -3
- package/src/process-runtime-availability.ts +9 -4
- package/src/process-turn-trace.ts +12 -24
- package/src/process-ui-snapshot-presenter.ts +210 -295
- package/src/routes/dashboard.ts +106 -0
- package/src/routes/future-executions.ts +5 -5
- package/src/routes/launchers.ts +51 -1
- package/src/routes/process-actions.ts +10 -10
- package/src/routes/process-detail.ts +25 -2
- package/src/routes/process-model-config.ts +70 -0
- package/src/routes/process-route-helpers.ts +153 -162
- package/src/routes/processes.ts +2 -0
- package/src/routes/settings.ts +173 -0
- package/src/routes/ticket-creation.ts +28 -5
- package/src/scoped-settings-service.ts +797 -0
- package/src/server-bootstrap/build-host-capabilities.ts +42 -0
- package/src/server-bootstrap/register-http.ts +12 -1
- package/src/session-summary-projection.ts +1 -2
- package/src/skills/bundled-skills.ts +64 -0
- package/src/skills/catalog-service.ts +35 -6
- package/src/skills/extension-importer.ts +94 -0
- package/src/skills/launch-skills.ts +19 -0
- package/src/skills/skill-frontmatter.ts +19 -6
- package/src/skills/source-importer.ts +7 -13
- package/src/startup-evidence.ts +29 -8
- package/src/startup-retry-policy.ts +106 -0
- package/src/supervisor/execution-inspection-ingestor.ts +55 -0
- package/src/supervisor/ipc-handler.ts +2 -0
- package/src/supervisor/worker-event-ingestor.ts +30 -14
- package/src/supervisor/worker-start-payload-builder.ts +17 -0
- package/src/supervisor/worker-supervisor.ts +26 -1
- package/src/test-helpers/prepared-fixture-start.ts +1 -0
- package/src/test-helpers/process-model-fixtures.ts +2 -0
- package/src/test-helpers/scoped-settings-fixtures.ts +126 -0
- package/src/test-helpers/skill-fixtures.ts +28 -0
- package/src/tool-approval-gate.ts +16 -0
- package/src/turn-progress.ts +3 -2
- package/src/turn-wait-service.ts +228 -0
- package/src/worker-runtime-profile-selection.ts +8 -1
- package/dist/app-MSJXFK33.js +0 -8
- package/dist/chunk-HK6BLLHA.js.map +0 -1
- package/dist/chunk-QCHS3X33.js.map +0 -1
- /package/dist/{app-MSJXFK33.js.map → app-KR3N2JAE.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
|
-
|
|
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
|
-
|
|
25
|
+
leases?: readonly WorkerLease[];
|
|
26
|
+
observations?: readonly InspectionContextObservation[];
|
|
159
27
|
turnDetails?: readonly ProcessRunTurnView[];
|
|
160
28
|
currentPiEntryId?: string | null;
|
|
161
29
|
}): ProcessInstanceTreeResponseBody {
|
|
162
|
-
const
|
|
163
|
-
(
|
|
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
|
|
176
|
-
const
|
|
177
|
-
|
|
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
|
|
189
|
-
const
|
|
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
|
-
|
|
193
|
-
|
|
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
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
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:
|
|
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
|
|
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 (
|
|
400
|
+
if (resourceSelections === undefined) {
|
|
398
401
|
try {
|
|
399
|
-
resourceSelections = deps.
|
|
402
|
+
resourceSelections = resolveLaunchSkills(deps, launchPlan.processId, launchPlan.skillIds);
|
|
400
403
|
} catch (error) {
|
|
401
404
|
return {
|
|
402
405
|
ok: false,
|