@leitwerk-dev/process-sdk 0.1.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.
- package/dist/LICENSE +13 -0
- package/dist/browser-ui-extension.d.ts +27 -0
- package/dist/browser-ui-extension.d.ts.map +1 -0
- package/dist/browser-ui-extension.js +2 -0
- package/dist/browser-ui-extension.js.map +1 -0
- package/dist/capabilities.d.ts +9 -0
- package/dist/capabilities.d.ts.map +1 -0
- package/dist/capabilities.js +7 -0
- package/dist/capabilities.js.map +1 -0
- package/dist/chunk-5RJZ2E7D.js +58 -0
- package/dist/chunk-5RJZ2E7D.js.map +1 -0
- package/dist/chunk-ITPH65G6.js +197 -0
- package/dist/chunk-ITPH65G6.js.map +1 -0
- package/dist/chunk-LIIP7FMU.js +48 -0
- package/dist/chunk-LIIP7FMU.js.map +1 -0
- package/dist/codecs.d.ts +3 -0
- package/dist/codecs.d.ts.map +1 -0
- package/dist/codecs.js +9 -0
- package/dist/codecs.js.map +1 -0
- package/dist/commit-message.d.ts +7 -0
- package/dist/commit-message.d.ts.map +1 -0
- package/dist/commit-message.js +3 -0
- package/dist/commit-message.js.map +1 -0
- package/dist/core-capabilities.d.ts +393 -0
- package/dist/core-capabilities.d.ts.map +1 -0
- package/dist/core-capabilities.js +6 -0
- package/dist/core-capabilities.js.map +1 -0
- package/dist/define-process.d.ts +269 -0
- package/dist/define-process.d.ts.map +1 -0
- package/dist/define-process.js +1040 -0
- package/dist/define-process.js.map +1 -0
- package/dist/event-bus.d.ts +3 -0
- package/dist/event-bus.d.ts.map +1 -0
- package/dist/event-bus.js +31 -0
- package/dist/event-bus.js.map +1 -0
- package/dist/extension-api-CnlL69Tu.d.ts +1281 -0
- package/dist/extension-api.d.ts +425 -0
- package/dist/extension-api.d.ts.map +1 -0
- package/dist/extension-api.js +5 -0
- package/dist/extension-api.js.map +1 -0
- package/dist/flow.d.ts +456 -0
- package/dist/flow.d.ts.map +1 -0
- package/dist/flow.js +1557 -0
- package/dist/flow.js.map +1 -0
- package/dist/form-contract.d.ts +2 -0
- package/dist/form-contract.d.ts.map +1 -0
- package/dist/form-contract.js +2 -0
- package/dist/form-contract.js.map +1 -0
- package/dist/fs-utils.d.ts +3 -0
- package/dist/fs-utils.d.ts.map +1 -0
- package/dist/fs-utils.js +23 -0
- package/dist/fs-utils.js.map +1 -0
- package/dist/git-binary.d.ts +11 -0
- package/dist/git-binary.d.ts.map +1 -0
- package/dist/git-binary.js +38 -0
- package/dist/git-binary.js.map +1 -0
- package/dist/graph-fragments.d.ts +23 -0
- package/dist/graph-fragments.d.ts.map +1 -0
- package/dist/graph-fragments.js +57 -0
- package/dist/graph-fragments.js.map +1 -0
- package/dist/host-capabilities.d.ts +12 -0
- package/dist/host-capabilities.d.ts.map +1 -0
- package/dist/host-capabilities.js +42 -0
- package/dist/host-capabilities.js.map +1 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/launcher-contract.d.ts +2 -0
- package/dist/launcher-contract.d.ts.map +1 -0
- package/dist/launcher-contract.js +2 -0
- package/dist/launcher-contract.js.map +1 -0
- package/dist/leaf-outcome-renderer.d.ts +48 -0
- package/dist/leaf-outcome-renderer.d.ts.map +1 -0
- package/dist/leaf-outcome-renderer.js +69 -0
- package/dist/leaf-outcome-renderer.js.map +1 -0
- package/dist/leaf-outcomes.d.ts +5 -0
- package/dist/leaf-outcomes.d.ts.map +1 -0
- package/dist/leaf-outcomes.js +52 -0
- package/dist/leaf-outcomes.js.map +1 -0
- package/dist/model-provider.d.ts +210 -0
- package/dist/model-provider.d.ts.map +1 -0
- package/dist/model-provider.js +171 -0
- package/dist/model-provider.js.map +1 -0
- package/dist/pi-config.d.ts +59 -0
- package/dist/pi-config.d.ts.map +1 -0
- package/dist/pi-config.js +182 -0
- package/dist/pi-config.js.map +1 -0
- package/dist/process-definition-internals.d.ts +7 -0
- package/dist/process-definition-internals.d.ts.map +1 -0
- package/dist/process-definition-internals.js +25 -0
- package/dist/process-definition-internals.js.map +1 -0
- package/dist/process-flow-view.d.ts +20 -0
- package/dist/process-flow-view.d.ts.map +1 -0
- package/dist/process-flow-view.js +418 -0
- package/dist/process-flow-view.js.map +1 -0
- package/dist/process-graph.d.ts +45 -0
- package/dist/process-graph.d.ts.map +1 -0
- package/dist/process-graph.js +213 -0
- package/dist/process-graph.js.map +1 -0
- package/dist/process-launcher-builder.d.ts +9 -0
- package/dist/process-launcher-builder.d.ts.map +1 -0
- package/dist/process-launcher-builder.js +43 -0
- package/dist/process-launcher-builder.js.map +1 -0
- package/dist/process-watcher-builder.d.ts +10 -0
- package/dist/process-watcher-builder.d.ts.map +1 -0
- package/dist/process-watcher-builder.js +40 -0
- package/dist/process-watcher-builder.js.map +1 -0
- package/dist/registry-utils.d.ts +8 -0
- package/dist/registry-utils.d.ts.map +1 -0
- package/dist/registry-utils.js +18 -0
- package/dist/registry-utils.js.map +1 -0
- package/dist/repository-git-env.d.ts +8 -0
- package/dist/repository-git-env.d.ts.map +1 -0
- package/dist/repository-git-env.js +26 -0
- package/dist/repository-git-env.js.map +1 -0
- package/dist/review-flow.d.ts +10 -0
- package/dist/review-flow.d.ts.map +1 -0
- package/dist/review-flow.js +44 -0
- package/dist/review-flow.js.map +1 -0
- package/dist/runtime-internals.d.ts +3 -0
- package/dist/runtime-internals.d.ts.map +1 -0
- package/dist/runtime-internals.js +3 -0
- package/dist/runtime-internals.js.map +1 -0
- package/dist/server-events.d.ts +84 -0
- package/dist/server-events.d.ts.map +1 -0
- package/dist/server-events.js +2 -0
- package/dist/server-events.js.map +1 -0
- package/dist/server-process-builder.d.ts +11 -0
- package/dist/server-process-builder.d.ts.map +1 -0
- package/dist/server-process-builder.js +52 -0
- package/dist/server-process-builder.js.map +1 -0
- package/dist/state-helpers.d.ts +9 -0
- package/dist/state-helpers.d.ts.map +1 -0
- package/dist/state-helpers.js +20 -0
- package/dist/state-helpers.js.map +1 -0
- package/dist/subprocess-env.d.ts +12 -0
- package/dist/subprocess-env.d.ts.map +1 -0
- package/dist/subprocess-env.js +34 -0
- package/dist/subprocess-env.js.map +1 -0
- package/dist/tool-renderers.d.ts +10 -0
- package/dist/tool-renderers.d.ts.map +1 -0
- package/dist/tool-renderers.js +63 -0
- package/dist/tool-renderers.js.map +1 -0
- package/dist/turn-semantics.d.ts +22 -0
- package/dist/turn-semantics.d.ts.map +1 -0
- package/dist/turn-semantics.js +339 -0
- package/dist/turn-semantics.js.map +1 -0
- package/dist/types.d.ts +295 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +12 -0
- package/dist/types.js.map +1 -0
- package/dist/ui-process-builder.d.ts +9 -0
- package/dist/ui-process-builder.d.ts.map +1 -0
- package/dist/ui-process-builder.js +30 -0
- package/dist/ui-process-builder.js.map +1 -0
- package/dist/worker-process-builder.d.ts +10 -0
- package/dist/worker-process-builder.d.ts.map +1 -0
- package/dist/worker-process-builder.js +22 -0
- package/dist/worker-process-builder.js.map +1 -0
- package/package.json +72 -0
- package/src/browser-ui-extension.ts +32 -0
- package/src/capabilities.ts +16 -0
- package/src/codecs.ts +10 -0
- package/src/commit-message.ts +9 -0
- package/src/core-capabilities.ts +526 -0
- package/src/define-process.ts +1879 -0
- package/src/event-bus.ts +35 -0
- package/src/extension-api.ts +600 -0
- package/src/flow.ts +2268 -0
- package/src/form-contract.ts +11 -0
- package/src/fs-utils.ts +28 -0
- package/src/git-binary.ts +40 -0
- package/src/graph-fragments.ts +110 -0
- package/src/host-capabilities.ts +60 -0
- package/src/index.ts +468 -0
- package/src/launcher-contract.ts +8 -0
- package/src/leaf-outcome-renderer.ts +112 -0
- package/src/leaf-outcomes.ts +74 -0
- package/src/model-provider.ts +461 -0
- package/src/pi-config.ts +268 -0
- package/src/process-definition-internals.ts +46 -0
- package/src/process-flow-view.ts +479 -0
- package/src/process-graph.ts +309 -0
- package/src/process-launcher-builder.ts +59 -0
- package/src/process-watcher-builder.ts +72 -0
- package/src/registry-utils.ts +31 -0
- package/src/repository-git-env.ts +35 -0
- package/src/review-flow.ts +66 -0
- package/src/runtime-internals.ts +7 -0
- package/src/server-events.ts +105 -0
- package/src/server-process-builder.ts +90 -0
- package/src/state-helpers.ts +36 -0
- package/src/subprocess-env.ts +48 -0
- package/src/tool-renderers.ts +92 -0
- package/src/turn-semantics.ts +554 -0
- package/src/types.ts +391 -0
- package/src/ui-process-builder.ts +46 -0
- package/src/worker-process-builder.ts +33 -0
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ProcessSemanticEntryRefKey,
|
|
3
|
+
ProcessTurnTransition,
|
|
4
|
+
ProcessTurnType,
|
|
5
|
+
ReviewSubject,
|
|
6
|
+
SerializedProcessGraph,
|
|
7
|
+
TurnId,
|
|
8
|
+
} from "@leitwerk-dev/domain";
|
|
9
|
+
import { isValidProcessProductName } from "@leitwerk-dev/domain";
|
|
10
|
+
import type { TurnDefinition } from "./define-process.js";
|
|
11
|
+
import type { ExtensionProcessDefinition, ProcessTurnBinding } from "./extension-api.js";
|
|
12
|
+
import { getProcessTurnTransitions } from "./process-definition-internals.js";
|
|
13
|
+
|
|
14
|
+
export type ProcessGraphSource = ExtensionProcessDefinition<unknown, unknown>;
|
|
15
|
+
export type ProcessGraphRegistry = ReadonlyMap<string, ProcessGraphSource>;
|
|
16
|
+
|
|
17
|
+
export interface ProcessGraphTurnView {
|
|
18
|
+
turnType: ProcessTurnType;
|
|
19
|
+
description: string;
|
|
20
|
+
transitions: readonly ProcessTurnTransition[];
|
|
21
|
+
reviewSubject?: ReviewSubject;
|
|
22
|
+
reviewProduct?: string;
|
|
23
|
+
resultSemanticRef?: ProcessSemanticEntryRefKey;
|
|
24
|
+
publishedProduct?: string;
|
|
25
|
+
publishedProducts?: readonly string[];
|
|
26
|
+
consumedProducts?: readonly string[];
|
|
27
|
+
optionalConsumedProducts?: readonly string[];
|
|
28
|
+
requiredSemanticMarkdownRefs?: readonly ProcessSemanticEntryRefKey[];
|
|
29
|
+
optionalSemanticMarkdownRefs?: readonly ProcessSemanticEntryRefKey[];
|
|
30
|
+
turnResultMarkdownRequired?: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface ProcessGraphView {
|
|
34
|
+
id: string;
|
|
35
|
+
primaryEntryTurnId: TurnId;
|
|
36
|
+
entryTurnIds: ReadonlySet<TurnId>;
|
|
37
|
+
happyPath: readonly TurnId[] | null;
|
|
38
|
+
turns: ReadonlyMap<TurnId, ProcessGraphTurnView>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function toTurnType(definition: TurnDefinition<unknown, unknown>): ProcessTurnType {
|
|
42
|
+
switch (definition.kind) {
|
|
43
|
+
case "llm":
|
|
44
|
+
case "human":
|
|
45
|
+
case "external":
|
|
46
|
+
case "automatic":
|
|
47
|
+
case "server_automatic":
|
|
48
|
+
return definition.kind;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function humanPublishedProducts(definition: TurnDefinition<unknown, unknown>): string[] {
|
|
53
|
+
if (definition.kind !== "human") {
|
|
54
|
+
return [];
|
|
55
|
+
}
|
|
56
|
+
const products: string[] = [];
|
|
57
|
+
for (const action of Object.values(definition.actions)) {
|
|
58
|
+
for (const field of action.form?.fields ?? []) {
|
|
59
|
+
if (!field.publish) {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
products.push(
|
|
63
|
+
typeof field.publish === "object" && field.publish.product
|
|
64
|
+
? field.publish.product
|
|
65
|
+
: field.id,
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
for (const externalAction of Object.values(definition.externalActions ?? {})) {
|
|
70
|
+
if (externalAction.publishInput) {
|
|
71
|
+
products.push(externalAction.publishInput.productName);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return [...new Set(products)];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function outcomePublishedProducts(definition: TurnDefinition<unknown, unknown>): string[] {
|
|
78
|
+
if (
|
|
79
|
+
definition.kind !== "llm" &&
|
|
80
|
+
definition.kind !== "automatic" &&
|
|
81
|
+
definition.kind !== "server_automatic"
|
|
82
|
+
) {
|
|
83
|
+
return [];
|
|
84
|
+
}
|
|
85
|
+
return [
|
|
86
|
+
...new Set(
|
|
87
|
+
Object.values(definition.outcomes ?? {})
|
|
88
|
+
.map((outcome) => outcome?.publishedProduct)
|
|
89
|
+
.filter((productName): productName is string => typeof productName === "string"),
|
|
90
|
+
),
|
|
91
|
+
];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function toTurnView(
|
|
95
|
+
binding: ProcessTurnBinding<TurnDefinition<unknown, unknown>>,
|
|
96
|
+
): ProcessGraphTurnView {
|
|
97
|
+
const definition = binding.definition;
|
|
98
|
+
const publishedProducts = [
|
|
99
|
+
...new Set([...humanPublishedProducts(definition), ...outcomePublishedProducts(definition)]),
|
|
100
|
+
];
|
|
101
|
+
return {
|
|
102
|
+
turnType: toTurnType(definition),
|
|
103
|
+
description: definition.description,
|
|
104
|
+
transitions: getProcessTurnTransitions(binding),
|
|
105
|
+
...(definition.reviewSubject ? { reviewSubject: { ...definition.reviewSubject } } : {}),
|
|
106
|
+
...(definition.kind === "human" && definition.reviewProduct
|
|
107
|
+
? { reviewProduct: definition.reviewProduct }
|
|
108
|
+
: {}),
|
|
109
|
+
...(definition.kind === "llm" && definition.resultSemanticRef
|
|
110
|
+
? { resultSemanticRef: definition.resultSemanticRef }
|
|
111
|
+
: {}),
|
|
112
|
+
...(definition.kind === "llm" && definition.publishedProduct
|
|
113
|
+
? { publishedProduct: definition.publishedProduct }
|
|
114
|
+
: {}),
|
|
115
|
+
...(publishedProducts.length > 0 ? { publishedProducts } : {}),
|
|
116
|
+
...(definition.kind === "llm" && definition.consumedProducts?.length
|
|
117
|
+
? { consumedProducts: [...definition.consumedProducts] }
|
|
118
|
+
: {}),
|
|
119
|
+
...(definition.kind === "llm" && definition.optionalConsumedProducts?.length
|
|
120
|
+
? { optionalConsumedProducts: [...definition.optionalConsumedProducts] }
|
|
121
|
+
: {}),
|
|
122
|
+
...(definition.kind === "llm" && definition.requiredSemanticMarkdownRefs?.length
|
|
123
|
+
? { requiredSemanticMarkdownRefs: [...definition.requiredSemanticMarkdownRefs] }
|
|
124
|
+
: {}),
|
|
125
|
+
...(definition.kind === "llm" && definition.optionalSemanticMarkdownRefs?.length
|
|
126
|
+
? { optionalSemanticMarkdownRefs: [...definition.optionalSemanticMarkdownRefs] }
|
|
127
|
+
: {}),
|
|
128
|
+
...(definition.kind === "llm" &&
|
|
129
|
+
definition.turnResultMarkdown &&
|
|
130
|
+
"required" in definition.turnResultMarkdown &&
|
|
131
|
+
definition.turnResultMarkdown.required === true
|
|
132
|
+
? { turnResultMarkdownRequired: true }
|
|
133
|
+
: {}),
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Runtime adapter from an extension process definition to the internal graph view.
|
|
139
|
+
* All server lifecycle, validation, model-selection and serialization code should use this view
|
|
140
|
+
* instead of maintaining a second graph representation.
|
|
141
|
+
*/
|
|
142
|
+
export function toProcessGraphView(definition: ProcessGraphSource): ProcessGraphView {
|
|
143
|
+
const turns = new Map<TurnId, ProcessGraphTurnView>();
|
|
144
|
+
for (const [turnId, binding] of definition.turns) {
|
|
145
|
+
turns.set(turnId, toTurnView(binding));
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
id: definition.id,
|
|
149
|
+
primaryEntryTurnId: definition.entryTurnId,
|
|
150
|
+
entryTurnIds: new Set([definition.entryTurnId, ...(definition.alternateEntryTurnIds ?? [])]),
|
|
151
|
+
happyPath: definition.happyPath ? [...definition.happyPath] : null,
|
|
152
|
+
turns,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export function hasProcessGraph(registry: ProcessGraphRegistry, processId: string): boolean {
|
|
157
|
+
return registry.has(processId);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export function getProcessGraph(
|
|
161
|
+
registry: ProcessGraphRegistry,
|
|
162
|
+
processId: string,
|
|
163
|
+
): ProcessGraphView {
|
|
164
|
+
const definition = registry.get(processId);
|
|
165
|
+
if (!definition) {
|
|
166
|
+
throw new Error(`Unknown process definition: ${processId}`);
|
|
167
|
+
}
|
|
168
|
+
return toProcessGraphView(definition);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export function getAllProcessGraphs(registry: ProcessGraphRegistry): readonly ProcessGraphView[] {
|
|
172
|
+
return [...registry.values()].map((definition) => toProcessGraphView(definition));
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export function getProcessTurnGraph(
|
|
176
|
+
registry: ProcessGraphRegistry,
|
|
177
|
+
processId: string,
|
|
178
|
+
turnId: TurnId,
|
|
179
|
+
): ProcessGraphTurnView | undefined {
|
|
180
|
+
return getProcessGraph(registry, processId).turns.get(turnId);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export function getTurnTransitionsForProcessGraph(
|
|
184
|
+
registry: ProcessGraphRegistry,
|
|
185
|
+
processId: string,
|
|
186
|
+
turnId: TurnId,
|
|
187
|
+
): readonly ProcessTurnTransition[] {
|
|
188
|
+
return getProcessTurnGraph(registry, processId, turnId)?.transitions ?? [];
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export function getReachableTurnIdsForProcessGraph(
|
|
192
|
+
registry: ProcessGraphRegistry,
|
|
193
|
+
processId: string,
|
|
194
|
+
): readonly TurnId[] {
|
|
195
|
+
return [...getProcessGraph(registry, processId).turns.keys()];
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export function isTurnAvailableForProcessGraph(
|
|
199
|
+
registry: ProcessGraphRegistry,
|
|
200
|
+
processId: string,
|
|
201
|
+
turnId: TurnId,
|
|
202
|
+
): boolean {
|
|
203
|
+
return getProcessGraph(registry, processId).turns.has(turnId);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export function serializeProcessGraph(
|
|
207
|
+
registry: ProcessGraphRegistry,
|
|
208
|
+
processId: string,
|
|
209
|
+
): SerializedProcessGraph {
|
|
210
|
+
const definition = getProcessGraph(registry, processId);
|
|
211
|
+
const turnTransitions: Record<TurnId, ProcessTurnTransition[]> = {};
|
|
212
|
+
for (const [turnId, turn] of definition.turns) {
|
|
213
|
+
turnTransitions[turnId] = turn.transitions.map((transition) => ({ ...transition }));
|
|
214
|
+
}
|
|
215
|
+
return {
|
|
216
|
+
id: definition.id,
|
|
217
|
+
entryTurnIds: [...definition.entryTurnIds],
|
|
218
|
+
reachableTurnIds: [...definition.turns.keys()],
|
|
219
|
+
turnTransitions,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export function listLlmTurnIdsForProcessGraph(
|
|
224
|
+
registry: ProcessGraphRegistry,
|
|
225
|
+
processId: string,
|
|
226
|
+
): readonly TurnId[] {
|
|
227
|
+
return [...getProcessGraph(registry, processId).turns.entries()]
|
|
228
|
+
.filter(([, turn]) => turn.turnType === "llm")
|
|
229
|
+
.map(([turnId]) => turnId);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function isTerminalLifecycleStatus(value: string | undefined): value is "completed" | "aborted" {
|
|
233
|
+
return value === "completed" || value === "aborted";
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export function validateProcessGraphEntryTurns(graph: ProcessGraphView): readonly string[] {
|
|
237
|
+
const errors: string[] = [];
|
|
238
|
+
for (const turnId of graph.entryTurnIds) {
|
|
239
|
+
if (!graph.turns.has(turnId)) {
|
|
240
|
+
errors.push(`Entry turn '${turnId}' is not declared in turns`);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return errors;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export function validateProcessGraphProducts(graph: ProcessGraphView): readonly string[] {
|
|
247
|
+
const errors: string[] = [];
|
|
248
|
+
const publishedProducts = new Set<string>();
|
|
249
|
+
for (const [turnId, turn] of graph.turns) {
|
|
250
|
+
const productNames = [
|
|
251
|
+
...(turn.publishedProduct ? [turn.publishedProduct] : []),
|
|
252
|
+
...(turn.publishedProducts ?? []),
|
|
253
|
+
];
|
|
254
|
+
for (const productName of productNames) {
|
|
255
|
+
if (!isValidProcessProductName(productName)) {
|
|
256
|
+
errors.push(`Turn '${turnId}' publishes invalid product '${productName}'`);
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
259
|
+
publishedProducts.add(productName);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
for (const [turnId, turn] of graph.turns) {
|
|
263
|
+
for (const productName of [
|
|
264
|
+
...(turn.consumedProducts ?? []),
|
|
265
|
+
...(turn.optionalConsumedProducts ?? []),
|
|
266
|
+
]) {
|
|
267
|
+
if (!isValidProcessProductName(productName)) {
|
|
268
|
+
errors.push(`Turn '${turnId}' consumes invalid product '${productName}'`);
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
if (!publishedProducts.has(productName)) {
|
|
272
|
+
errors.push(
|
|
273
|
+
`Turn '${turnId}' consumes product '${productName}' that is never published by this process`,
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return errors;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export function validateProcessGraphTurnTransitions(graph: ProcessGraphView): readonly string[] {
|
|
282
|
+
const errors: string[] = [];
|
|
283
|
+
for (const [turnId, turn] of graph.turns) {
|
|
284
|
+
for (const transition of turn.transitions) {
|
|
285
|
+
const hasNextTurn = transition.nextTurnId !== undefined;
|
|
286
|
+
const hasLifecycleStatus = transition.lifecycleStatus !== undefined;
|
|
287
|
+
if (hasNextTurn === hasLifecycleStatus) {
|
|
288
|
+
errors.push(
|
|
289
|
+
`Turn transition from '${turnId}' must declare exactly one target: nextTurnId or lifecycleStatus`,
|
|
290
|
+
);
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
if (transition.nextTurnId !== undefined && !graph.turns.has(transition.nextTurnId)) {
|
|
294
|
+
errors.push(
|
|
295
|
+
`Turn transition from '${turnId}' references undeclared nextTurnId '${transition.nextTurnId}'`,
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
if (
|
|
299
|
+
transition.lifecycleStatus !== undefined &&
|
|
300
|
+
!isTerminalLifecycleStatus(transition.lifecycleStatus)
|
|
301
|
+
) {
|
|
302
|
+
errors.push(
|
|
303
|
+
`Turn transition from '${turnId}' references invalid lifecycleStatus '${transition.lifecycleStatus}'`,
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
return errors;
|
|
309
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ExtensionProcessDefinition,
|
|
3
|
+
ProcessLauncherAPI,
|
|
4
|
+
ProcessLauncherDefinition,
|
|
5
|
+
} from "./extension-api.js";
|
|
6
|
+
import { cloneMap, registerUnique } from "./registry-utils.js";
|
|
7
|
+
|
|
8
|
+
export interface BuiltProcessLauncherDefinition<TParams = unknown> {
|
|
9
|
+
launchers: ReadonlyMap<string, ProcessLauncherDefinition<TParams>>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function validateLauncherDefinition<TParams>(def: ProcessLauncherDefinition<TParams>): void {
|
|
13
|
+
if (!def.id.trim()) {
|
|
14
|
+
throw new Error("Launcher id is required");
|
|
15
|
+
}
|
|
16
|
+
if (!def.label.trim()) {
|
|
17
|
+
throw new Error(`Launcher '${def.id}' must define a non-empty label`);
|
|
18
|
+
}
|
|
19
|
+
if (!def.description.trim()) {
|
|
20
|
+
throw new Error(`Launcher '${def.id}' must define a non-empty description`);
|
|
21
|
+
}
|
|
22
|
+
if (def.visibility !== "ui") {
|
|
23
|
+
throw new Error(`Launcher '${def.id}' has unsupported visibility`);
|
|
24
|
+
}
|
|
25
|
+
if (!def.ui) {
|
|
26
|
+
throw new Error(`UI launcher '${def.id}' must define a ui block`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function createProcessLauncherBuilder<TParams = unknown>(): ProcessLauncherAPI<TParams> & {
|
|
31
|
+
getDefinition(): BuiltProcessLauncherDefinition<TParams>;
|
|
32
|
+
} {
|
|
33
|
+
const launchers = new Map<string, ProcessLauncherDefinition<TParams>>();
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
launcher(def: ProcessLauncherDefinition<TParams>) {
|
|
37
|
+
registerUnique(launchers, def.id, def, {
|
|
38
|
+
duplicateMessage: `Launcher '${def.id}' is already registered`,
|
|
39
|
+
validate: validateLauncherDefinition,
|
|
40
|
+
});
|
|
41
|
+
},
|
|
42
|
+
getDefinition() {
|
|
43
|
+
return {
|
|
44
|
+
launchers: cloneMap(launchers),
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function buildProcessLaunchers<TParams = unknown, TState = unknown>(
|
|
51
|
+
process: ExtensionProcessDefinition<TParams, TState>,
|
|
52
|
+
): BuiltProcessLauncherDefinition<TParams> | undefined {
|
|
53
|
+
if (!process.launchers) {
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
const builder = createProcessLauncherBuilder<TParams>();
|
|
57
|
+
process.launchers(builder);
|
|
58
|
+
return builder.getDefinition();
|
|
59
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { ProcessWatcherType } from "@leitwerk-dev/protocol";
|
|
2
|
+
import type {
|
|
3
|
+
ExtensionProcessDefinition,
|
|
4
|
+
ProcessWatcherAPI,
|
|
5
|
+
ProcessWatcherDefinition,
|
|
6
|
+
} from "./extension-api.js";
|
|
7
|
+
import { cloneMap, registerUnique } from "./registry-utils.js";
|
|
8
|
+
|
|
9
|
+
export interface BuiltProcessWatcherDefinition<
|
|
10
|
+
TParams = unknown,
|
|
11
|
+
TType extends ProcessWatcherType = ProcessWatcherType,
|
|
12
|
+
> {
|
|
13
|
+
watchers: ReadonlyMap<string, ProcessWatcherDefinition<TParams, unknown, TType>>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function validateWatcherDefinition<TParams, TType extends ProcessWatcherType>(
|
|
17
|
+
def: ProcessWatcherDefinition<TParams, unknown, TType>,
|
|
18
|
+
): void {
|
|
19
|
+
if (!def.id.trim()) {
|
|
20
|
+
throw new Error("Process watcher id is required");
|
|
21
|
+
}
|
|
22
|
+
if (!def.label.trim()) {
|
|
23
|
+
throw new Error(`Process watcher '${def.id}' must define a non-empty label`);
|
|
24
|
+
}
|
|
25
|
+
if (!def.description.trim()) {
|
|
26
|
+
throw new Error(`Process watcher '${def.id}' must define a non-empty description`);
|
|
27
|
+
}
|
|
28
|
+
if (def.type !== "jira" && def.type !== "gitlab_mr" && def.type !== "filesystem") {
|
|
29
|
+
throw new Error(`Process watcher '${def.id}' has unsupported type '${String(def.type)}'`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function createProcessWatcherBuilder<
|
|
34
|
+
TParams = unknown,
|
|
35
|
+
TType extends ProcessWatcherType = ProcessWatcherType,
|
|
36
|
+
>(): ProcessWatcherAPI<TParams> & {
|
|
37
|
+
getDefinition(): BuiltProcessWatcherDefinition<TParams, TType>;
|
|
38
|
+
} {
|
|
39
|
+
const watchers = new Map<string, ProcessWatcherDefinition<TParams, unknown, TType>>();
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
watcher<TEvent = unknown, TWatcherType extends ProcessWatcherType = ProcessWatcherType>(
|
|
43
|
+
def: ProcessWatcherDefinition<TParams, TEvent, TWatcherType>,
|
|
44
|
+
) {
|
|
45
|
+
registerUnique(
|
|
46
|
+
watchers,
|
|
47
|
+
def.id,
|
|
48
|
+
def as unknown as ProcessWatcherDefinition<TParams, unknown, TType>,
|
|
49
|
+
{
|
|
50
|
+
duplicateMessage: `Process watcher '${def.id}' is already registered`,
|
|
51
|
+
validate: validateWatcherDefinition,
|
|
52
|
+
},
|
|
53
|
+
);
|
|
54
|
+
},
|
|
55
|
+
getDefinition() {
|
|
56
|
+
return {
|
|
57
|
+
watchers: cloneMap(watchers),
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function buildProcessWatchers<TParams = unknown, TState = unknown>(
|
|
64
|
+
process: ExtensionProcessDefinition<TParams, TState>,
|
|
65
|
+
): BuiltProcessWatcherDefinition<TParams> | undefined {
|
|
66
|
+
if (!process.watchers) {
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
const builder = createProcessWatcherBuilder<TParams>();
|
|
70
|
+
process.watchers(builder);
|
|
71
|
+
return builder.getDefinition();
|
|
72
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface UniqueRegistrationOptions<TValue> {
|
|
2
|
+
duplicateMessage: string;
|
|
3
|
+
validate?: (value: TValue) => void;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export function registerUnique<TKey, TValue>(
|
|
7
|
+
registry: Map<TKey, TValue>,
|
|
8
|
+
key: TKey,
|
|
9
|
+
value: TValue,
|
|
10
|
+
options: UniqueRegistrationOptions<TValue>,
|
|
11
|
+
): void {
|
|
12
|
+
if (registry.has(key)) {
|
|
13
|
+
throw new Error(options.duplicateMessage);
|
|
14
|
+
}
|
|
15
|
+
options.validate?.(value);
|
|
16
|
+
registry.set(key, value);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function cloneMap<TKey, TValue>(registry: ReadonlyMap<TKey, TValue>): Map<TKey, TValue> {
|
|
20
|
+
return new Map(registry);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function cloneArrayValueMap<TKey, TValue>(
|
|
24
|
+
registry: ReadonlyMap<TKey, readonly TValue[]>,
|
|
25
|
+
): Map<TKey, readonly TValue[]> {
|
|
26
|
+
const cloned = new Map<TKey, readonly TValue[]>();
|
|
27
|
+
for (const [key, values] of registry) {
|
|
28
|
+
cloned.set(key, [...values]);
|
|
29
|
+
}
|
|
30
|
+
return cloned;
|
|
31
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
INTERNAL_REPOSITORY_GIT_SSH_ENV_PREFIX,
|
|
3
|
+
type SubprocessEnvInput,
|
|
4
|
+
sanitizeWorkerSubprocessEnv,
|
|
5
|
+
} from "./subprocess-env.js";
|
|
6
|
+
|
|
7
|
+
function wrapperKey(projectKey: string): string {
|
|
8
|
+
return `${INTERNAL_REPOSITORY_GIT_SSH_ENV_PREFIX}${encodeURIComponent(projectKey).replace(/%/g, "_")}`;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Worker-internal registration; the wrapper path is never copied to ordinary subprocesses. */
|
|
12
|
+
export function setRepositoryGitSshWrapper(projectKey: string, wrapperPath: string): void {
|
|
13
|
+
process.env[wrapperKey(projectKey)] = wrapperPath;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function clearRepositoryGitSshWrappers(): void {
|
|
17
|
+
for (const key of Object.keys(process.env)) {
|
|
18
|
+
if (key.startsWith(INTERNAL_REPOSITORY_GIT_SSH_ENV_PREFIX)) delete process.env[key];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Safe environment for a trusted Git invocation for one process project. */
|
|
23
|
+
export function repositoryGitSubprocessEnv(
|
|
24
|
+
projectKey: string,
|
|
25
|
+
overrides: SubprocessEnvInput = {},
|
|
26
|
+
): NodeJS.ProcessEnv {
|
|
27
|
+
const env = sanitizeWorkerSubprocessEnv(process.env, overrides);
|
|
28
|
+
const wrapper = process.env[wrapperKey(projectKey)];
|
|
29
|
+
if (wrapper) env.GIT_SSH = wrapper;
|
|
30
|
+
return env;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function repositoryGitArgs(args: readonly string[]): string[] {
|
|
34
|
+
return ["-c", "core.hooksPath=/dev/null", ...args];
|
|
35
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { ProcessTurnOutcomeEvent } from "./extension-api.js";
|
|
2
|
+
import type {
|
|
3
|
+
PlanSavedEvent,
|
|
4
|
+
ReviewCompletedEvent,
|
|
5
|
+
ReviewRequestedEvent,
|
|
6
|
+
} from "./server-events.js";
|
|
7
|
+
|
|
8
|
+
export function filterStringArray(value: unknown): string[] {
|
|
9
|
+
return Array.isArray(value)
|
|
10
|
+
? value.filter((entry): entry is string => typeof entry === "string")
|
|
11
|
+
: [];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function normalizeMessage(value: unknown): string {
|
|
15
|
+
return typeof value === "string" ? value : "";
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function resolveOutcomeMarkdown(
|
|
19
|
+
event: Pick<ProcessTurnOutcomeEvent, "params" | "turnResultMarkdown">,
|
|
20
|
+
paramKey: string,
|
|
21
|
+
): string | undefined {
|
|
22
|
+
if (typeof event.turnResultMarkdown === "string") {
|
|
23
|
+
return event.turnResultMarkdown;
|
|
24
|
+
}
|
|
25
|
+
const value = event.params[paramKey];
|
|
26
|
+
return typeof value === "string" ? value : undefined;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function buildPlanSavedEventPayload(input: {
|
|
30
|
+
planRevision: number;
|
|
31
|
+
event: Pick<ProcessTurnOutcomeEvent, "params" | "turnResultMarkdown">;
|
|
32
|
+
}): Omit<PlanSavedEvent, "instanceId"> {
|
|
33
|
+
return {
|
|
34
|
+
planRevision: input.planRevision,
|
|
35
|
+
summary: normalizeMessage(input.event.params.summary),
|
|
36
|
+
planMarkdown: resolveOutcomeMarkdown(input.event, "planMarkdown") ?? "",
|
|
37
|
+
acceptanceCriteria: filterStringArray(input.event.params.acceptanceCriteria),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function buildReviewRequestedEventPayload(
|
|
42
|
+
event: Pick<ProcessTurnOutcomeEvent, "params">,
|
|
43
|
+
): Omit<ReviewRequestedEvent, "instanceId"> {
|
|
44
|
+
return {
|
|
45
|
+
changedProjects: filterStringArray(event.params.changedProjects),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function buildReviewCompletedEventPayload(
|
|
50
|
+
event: Pick<ProcessTurnOutcomeEvent, "outcome" | "params" | "turnResultMarkdown">,
|
|
51
|
+
): Omit<ReviewCompletedEvent, "instanceId"> {
|
|
52
|
+
if (event.outcome === "issues_found") {
|
|
53
|
+
return {
|
|
54
|
+
hasIssues: true,
|
|
55
|
+
issueCount: typeof event.params.issueCount === "number" ? event.params.issueCount : 1,
|
|
56
|
+
...(resolveOutcomeMarkdown(event, "reviewMarkdown")
|
|
57
|
+
? { reviewMarkdown: resolveOutcomeMarkdown(event, "reviewMarkdown") }
|
|
58
|
+
: {}),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
hasIssues: false,
|
|
64
|
+
issueCount: 0,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ProcessInstance,
|
|
3
|
+
ProcessLeafOutcomeSnapshot,
|
|
4
|
+
ProcessProject,
|
|
5
|
+
ProcessQuestionRequest,
|
|
6
|
+
ProcessTurnRecord,
|
|
7
|
+
WorkerErrorClass,
|
|
8
|
+
} from "@leitwerk-dev/domain";
|
|
9
|
+
|
|
10
|
+
export interface ProcessCreatedEvent {
|
|
11
|
+
instanceId: string;
|
|
12
|
+
process: ProcessInstance;
|
|
13
|
+
projects: readonly ProcessProject[];
|
|
14
|
+
launcherId?: string | null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface ProcessUpdatedEvent {
|
|
18
|
+
instanceId: string;
|
|
19
|
+
process: ProcessInstance;
|
|
20
|
+
changedFields: readonly string[];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface TurnStartedEvent {
|
|
24
|
+
instanceId: string;
|
|
25
|
+
turnRecord: ProcessTurnRecord;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface TurnFailedEvent {
|
|
29
|
+
instanceId: string;
|
|
30
|
+
turnRecord: ProcessTurnRecord;
|
|
31
|
+
errorSummary: string;
|
|
32
|
+
errorClass?: WorkerErrorClass | null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface LeafOutcomeCapturedEvent {
|
|
36
|
+
instanceId: string;
|
|
37
|
+
snapshot: ProcessLeafOutcomeSnapshot;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface ReviewRequestedEvent {
|
|
41
|
+
instanceId: string;
|
|
42
|
+
workerId?: string;
|
|
43
|
+
changedProjects: string[];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface QuestionRequestedEvent {
|
|
47
|
+
instanceId: string;
|
|
48
|
+
request: ProcessQuestionRequest;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface TurnOutcomeEvent {
|
|
52
|
+
instanceId: string;
|
|
53
|
+
turnRecordId: string;
|
|
54
|
+
turnId: string;
|
|
55
|
+
outcome: string;
|
|
56
|
+
params: Record<string, unknown>;
|
|
57
|
+
turnResultMarkdown?: string | null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface PlanApprovedEvent {
|
|
61
|
+
instanceId: string;
|
|
62
|
+
externalId: string | null;
|
|
63
|
+
planRevision: number;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface PlanRevisionRequestedEvent {
|
|
67
|
+
instanceId: string;
|
|
68
|
+
message: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface PlanSavedEvent {
|
|
72
|
+
instanceId: string;
|
|
73
|
+
planRevision: number;
|
|
74
|
+
summary: string;
|
|
75
|
+
planMarkdown: string;
|
|
76
|
+
acceptanceCriteria: string[];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface ReviewCompletedEvent {
|
|
80
|
+
instanceId: string;
|
|
81
|
+
hasIssues: boolean;
|
|
82
|
+
issueCount: number;
|
|
83
|
+
reviewMarkdown?: string;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface ServerExtensionEventMap {
|
|
87
|
+
process_created: ProcessCreatedEvent;
|
|
88
|
+
process_updated: ProcessUpdatedEvent;
|
|
89
|
+
turn_started: TurnStartedEvent;
|
|
90
|
+
turn_failed: TurnFailedEvent;
|
|
91
|
+
leaf_outcome_captured: LeafOutcomeCapturedEvent;
|
|
92
|
+
question_requested: QuestionRequestedEvent;
|
|
93
|
+
review_requested: ReviewRequestedEvent;
|
|
94
|
+
turn_outcome: TurnOutcomeEvent;
|
|
95
|
+
plan_approved: PlanApprovedEvent;
|
|
96
|
+
plan_revision_requested: PlanRevisionRequestedEvent;
|
|
97
|
+
plan_saved: PlanSavedEvent;
|
|
98
|
+
review_completed: ReviewCompletedEvent;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export type ServerExtensionEventName = keyof ServerExtensionEventMap;
|
|
102
|
+
|
|
103
|
+
export type ServerExtensionEventPayloadInputMap = {
|
|
104
|
+
[K in keyof ServerExtensionEventMap]: Omit<ServerExtensionEventMap[K], "instanceId">;
|
|
105
|
+
};
|