@leitwerk-dev/showcase-processes 0.1.0 → 0.1.2

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 (41) hide show
  1. package/dist/index.d.ts +106 -11
  2. package/dist/index.js +1240 -53
  3. package/dist/index.js.map +1 -1
  4. package/package.json +4 -4
  5. package/dist/file-action-triggers.d.ts +0 -9
  6. package/dist/file-action-triggers.d.ts.map +0 -1
  7. package/dist/file-action-triggers.js +0 -87
  8. package/dist/file-action-triggers.js.map +0 -1
  9. package/dist/file-external.d.ts +0 -16
  10. package/dist/file-external.d.ts.map +0 -1
  11. package/dist/file-external.js +0 -198
  12. package/dist/file-external.js.map +0 -1
  13. package/dist/index.d.ts.map +0 -1
  14. package/dist/poem-leaf-outcome.d.ts +0 -41
  15. package/dist/poem-leaf-outcome.d.ts.map +0 -1
  16. package/dist/poem-leaf-outcome.js +0 -110
  17. package/dist/poem-leaf-outcome.js.map +0 -1
  18. package/dist/process-definition.d.ts +0 -18
  19. package/dist/process-definition.d.ts.map +0 -1
  20. package/dist/process-definition.js +0 -832
  21. package/dist/process-definition.js.map +0 -1
  22. package/dist/turns/external-complete.d.ts +0 -6
  23. package/dist/turns/external-complete.d.ts.map +0 -1
  24. package/dist/turns/external-complete.js +0 -6
  25. package/dist/turns/external-complete.js.map +0 -1
  26. package/dist/turns/poem-creator.d.ts +0 -15
  27. package/dist/turns/poem-creator.d.ts.map +0 -1
  28. package/dist/turns/poem-creator.js +0 -72
  29. package/dist/turns/poem-creator.js.map +0 -1
  30. package/dist/turns/run-single-prompt.d.ts +0 -8
  31. package/dist/turns/run-single-prompt.d.ts.map +0 -1
  32. package/dist/turns/run-single-prompt.js +0 -57
  33. package/dist/turns/run-single-prompt.js.map +0 -1
  34. package/dist/ui/leaf-outcome-element.d.ts +0 -2
  35. package/dist/ui/leaf-outcome-element.d.ts.map +0 -1
  36. package/dist/ui/leaf-outcome-element.js +0 -79
  37. package/dist/ui/leaf-outcome-element.js.map +0 -1
  38. package/dist/ui/poem-leaf-outcome-element.d.ts +0 -2
  39. package/dist/ui/poem-leaf-outcome-element.d.ts.map +0 -1
  40. package/dist/ui/poem-leaf-outcome-element.js +0 -171
  41. package/dist/ui/poem-leaf-outcome-element.js.map +0 -1
@@ -1,832 +0,0 @@
1
- import { execFileSync } from "node:child_process";
2
- import { setTimeout as delay } from "node:timers/promises";
3
- import { createReviewSubject } from "@leitwerk-dev/domain";
4
- import { createEmptyStructuralProcessState, flow, parseStructuralProcessState, } from "@leitwerk-dev/process-sdk";
5
- import { fileExternal } from "./file-external.js";
6
- import { buildPoemLeafOutcomeFallbackMarkdown, buildPoemLeafOutcomePayload, resolvePoemLeafMarkdown, } from "./poem-leaf-outcome.js";
7
- import { externalPromptCompletionTurnDescription, externalPromptCompletionTurnId, } from "./turns/external-complete.js";
8
- import { buildDefaultPoemPrompt, buildDraftPoemInstruction, buildReviewPoemInstruction, buildRevisePoemInstruction, poemCreatorActionIds, } from "./turns/poem-creator.js";
9
- import { buildSinglePromptInstruction, buildSinglePromptWithToolInstruction, } from "./turns/run-single-prompt.js";
10
- const promptProcessParamsCodec = {
11
- parse(value) {
12
- const record = typeof value === "object" && value !== null ? value : {};
13
- return {
14
- prompt: typeof record.prompt === "string"
15
- ? record.prompt
16
- : "",
17
- };
18
- },
19
- serialize(value) {
20
- return value;
21
- },
22
- };
23
- const structuralStateCodec = {
24
- parse(value) {
25
- return parseStructuralProcessState(value);
26
- },
27
- serialize(value) {
28
- return value;
29
- },
30
- };
31
- const poemCreatorStateCodec = {
32
- parse(value) {
33
- const structural = parseStructuralProcessState(value);
34
- const record = typeof value === "object" && value !== null ? value : {};
35
- const latestReviewOutcome = typeof record.latestReviewOutcome === "string"
36
- ? record.latestReviewOutcome === "issues_found"
37
- ? "leave_feedback"
38
- : record.latestReviewOutcome === "no_issues" ||
39
- record.latestReviewOutcome === "leave_feedback"
40
- ? record.latestReviewOutcome
41
- : null
42
- : null;
43
- return {
44
- ...structural,
45
- latestReviewMarkdown: typeof record.latestReviewMarkdown === "string" ? record.latestReviewMarkdown : null,
46
- latestReviewSummary: typeof record.latestReviewSummary === "string" ? record.latestReviewSummary : null,
47
- latestReviewOutcome,
48
- };
49
- },
50
- serialize(value) {
51
- return value;
52
- },
53
- };
54
- function validateLaunchInput(input, fallbackPrompt) {
55
- const inputPrompt = typeof input.prompt === "string" ? input.prompt.trim() : "";
56
- const prompt = inputPrompt || fallbackPrompt?.trim() || "";
57
- if (!prompt) {
58
- return {
59
- ok: false,
60
- errors: [{ code: "required", fieldId: "prompt", message: "prompt is required" }],
61
- };
62
- }
63
- return {
64
- ok: true,
65
- prompt,
66
- };
67
- }
68
- function buildPromptTitleSourceFields(prompt, label = "Prompt") {
69
- return [{ label, value: prompt }];
70
- }
71
- function clearReviewRefs(state) {
72
- return {
73
- ...state,
74
- review: null,
75
- };
76
- }
77
- function patchPoemCreatorState(state, input) {
78
- const nextState = {
79
- ...state,
80
- ...("reviewSubject" in input ? { reviewSubject: input.reviewSubject ?? null } : {}),
81
- ...("latestReviewMarkdown" in input
82
- ? { latestReviewMarkdown: input.latestReviewMarkdown ?? null }
83
- : {}),
84
- ...("latestReviewSummary" in input
85
- ? { latestReviewSummary: input.latestReviewSummary ?? null }
86
- : {}),
87
- ...("latestReviewOutcome" in input
88
- ? { latestReviewOutcome: input.latestReviewOutcome ?? null }
89
- : {}),
90
- ...("semanticEntryRefs" in input ? { semanticEntryRefs: input.semanticEntryRefs } : {}),
91
- };
92
- if (!input.clearReviewRefs) {
93
- return nextState;
94
- }
95
- return {
96
- ...nextState,
97
- semanticEntryRefs: clearReviewRefs(nextState.semanticEntryRefs),
98
- };
99
- }
100
- function buildPoemLeafReview(state) {
101
- if (!state.latestReviewOutcome) {
102
- return null;
103
- }
104
- return {
105
- outcome: state.latestReviewOutcome,
106
- summary: state.latestReviewSummary,
107
- feedback: state.latestReviewOutcome === "leave_feedback" ? state.latestReviewMarkdown : null,
108
- };
109
- }
110
- function createMarkdownLeafOutcome(rendererId) {
111
- return {
112
- rendererId,
113
- capture(ctx) {
114
- const markdown = ctx.turnRecord?.turnResultMarkdown?.trim() ?? "";
115
- return {
116
- rendererId,
117
- schemaVersion: 1,
118
- props: {
119
- prompt: ctx.params.prompt,
120
- markdown: markdown.length > 0 ? markdown : null,
121
- leafEntryId: ctx.leaf.entryId,
122
- turnRecordId: ctx.leaf.turnRecordId,
123
- },
124
- fallbackMarkdown: markdown.length > 0 ? markdown : null,
125
- };
126
- },
127
- };
128
- }
129
- function createPoemLeafOutcome(rendererId) {
130
- return {
131
- rendererId,
132
- capture(ctx) {
133
- const reviewLeafEntryId = ctx.state.semanticEntryRefs.review?.entryId ?? null;
134
- const review = buildPoemLeafReview(ctx.state);
135
- const isReviewLeaf = reviewLeafEntryId !== null && ctx.leaf.entryId === reviewLeafEntryId;
136
- const primaryPoemLeafRef = ctx.state.semanticEntryRefs.currentPrimaryPathLeaf;
137
- const primaryPoemTurnRecord = primaryPoemLeafRef?.turnRecordId
138
- ? ctx.readTurnRecord(primaryPoemLeafRef.turnRecordId)
139
- : null;
140
- const markdown = isReviewLeaf
141
- ? resolvePoemLeafMarkdown({
142
- turnResultMarkdown: primaryPoemTurnRecord?.turnResultMarkdown,
143
- leafEntry: primaryPoemLeafRef ? ctx.readTreeEntry(primaryPoemLeafRef.entryId) : null,
144
- })
145
- : resolvePoemLeafMarkdown({
146
- turnResultMarkdown: ctx.turnRecord?.turnResultMarkdown,
147
- leafEntry: ctx.readLeafEntry(),
148
- });
149
- if (isReviewLeaf && !review) {
150
- throw new Error("Poem review leaf outcome requires latestReviewOutcome state");
151
- }
152
- if (isReviewLeaf && !markdown) {
153
- throw new Error("Poem review leaf outcome requires a readable primary poem leaf");
154
- }
155
- const fallbackMarkdown = buildPoemLeafOutcomeFallbackMarkdown({
156
- markdown,
157
- review: isReviewLeaf ? review : null,
158
- });
159
- return {
160
- rendererId,
161
- schemaVersion: 1,
162
- props: buildPoemLeafOutcomePayload({
163
- prompt: ctx.params.prompt,
164
- markdown,
165
- review: isReviewLeaf ? review : null,
166
- }),
167
- fallbackMarkdown: fallbackMarkdown || null,
168
- };
169
- },
170
- };
171
- }
172
- const poemTurnIds = {
173
- draftPoem: "draft_poem",
174
- poemReview: "poem_review",
175
- reviewPoemDraft: "review_poem_draft",
176
- poemReviewFeedback: "poem_review_feedback",
177
- };
178
- const poemDraftReviewSubject = { kind: "plan" };
179
- const poemFeedbackReviewSubject = { kind: "implementation" };
180
- const poemRevisionForm = {
181
- id: poemCreatorActionIds.requestRevision,
182
- title: "Request poem revision",
183
- fields: [
184
- {
185
- id: "message",
186
- label: "Revision request",
187
- kind: "textarea",
188
- primaryPrompt: true,
189
- required: true,
190
- publish: true,
191
- description: "Tell the next primary-branch poem draft what should change.",
192
- },
193
- ],
194
- submitLabel: "Request revision",
195
- };
196
- const poemReviewChangesForm = {
197
- id: poemCreatorActionIds.requestReviewChanges,
198
- title: "Request review changes",
199
- fields: [
200
- {
201
- id: "message",
202
- label: "Review revision request",
203
- kind: "textarea",
204
- primaryPrompt: true,
205
- required: true,
206
- publish: true,
207
- description: "Tell the review branch how to revise its review output.",
208
- },
209
- ],
210
- submitLabel: "Request review changes",
211
- };
212
- export const singlePromptProcess = flow
213
- .process("single_prompt_process")
214
- .displayName("Single Prompt")
215
- .entry("run_single_prompt")
216
- .codecs({
217
- params: promptProcessParamsCodec,
218
- state: structuralStateCodec,
219
- })
220
- .initialState(() => createEmptyStructuralProcessState())
221
- .turn(flow
222
- .llm("run_single_prompt")
223
- .description("Run a single operator-provided prompt and finish on turn end")
224
- .tools("read", "bash", "edit", "write")
225
- .prompt(async (ctx) => buildSinglePromptInstruction(ctx.params.prompt))
226
- .end("completed")
227
- .complete())
228
- .ui((api) => {
229
- api.leafOutcome(createMarkdownLeafOutcome("@leitwerk-dev/showcase-processes:single_prompt_process.leaf_outcome"));
230
- })
231
- .launcher({
232
- id: "single_prompt_process.single_prompt_ui",
233
- label: "Single Prompt",
234
- description: "Run one prompt and finish on turn end",
235
- visibility: "ui",
236
- ui: {
237
- card: {
238
- title: "Single Prompt",
239
- description: "Run a one-shot prompt. The shared launcher shell chooses the model configuration.",
240
- },
241
- launchConfigSchema: {
242
- id: "single_prompt_form",
243
- title: "Single Prompt",
244
- fields: [
245
- {
246
- id: "prompt",
247
- label: "Prompt",
248
- kind: "textarea",
249
- required: true,
250
- placeholder: "Say hello.",
251
- description: "The exact prompt sent to Pi for this one-shot run. This version finishes when the assistant turn ends normally.",
252
- },
253
- ],
254
- submitLabel: "Run Prompt",
255
- },
256
- resolveDefaults() {
257
- return {
258
- prompt: "",
259
- };
260
- },
261
- resolveLaunchConfig(input) {
262
- const validated = validateLaunchInput(input);
263
- if (!validated.ok) {
264
- return validated;
265
- }
266
- return {
267
- ok: true,
268
- launchConfig: {
269
- processId: "single_prompt_process",
270
- params: { prompt: validated.prompt },
271
- titleSourceFields: buildPromptTitleSourceFields(validated.prompt),
272
- startTurnId: "run_single_prompt",
273
- },
274
- };
275
- },
276
- },
277
- })
278
- .define();
279
- export const singlePromptWithToolProcess = flow
280
- .process("single_prompt_with_tool_process")
281
- .displayName("Single Prompt + Done Tool")
282
- .entry("run_single_prompt_with_tool")
283
- .codecs({
284
- params: promptProcessParamsCodec,
285
- state: structuralStateCodec,
286
- })
287
- .initialState(() => createEmptyStructuralProcessState())
288
- .turn(flow
289
- .llm("run_single_prompt_with_tool")
290
- .description("Run a single operator-provided prompt and require the done tool")
291
- .tools("read", "bash", "edit", "write")
292
- .prompt(async (ctx) => buildSinglePromptWithToolInstruction(ctx.params.prompt))
293
- .outcomeTool("done", (tool) => tool
294
- .description("Mark the prompt run as complete")
295
- .requiredString("summary", "Short summary of the result")
296
- .complete()))
297
- .ui((api) => {
298
- api.leafOutcome(createMarkdownLeafOutcome("@leitwerk-dev/showcase-processes:single_prompt_with_tool_process.leaf_outcome"));
299
- })
300
- .launcher({
301
- id: "single_prompt_with_tool_process.single_prompt_with_tool_ui",
302
- label: "Single Prompt + Done Tool",
303
- description: "Run one prompt and require an explicit done tool",
304
- visibility: "ui",
305
- ui: {
306
- card: {
307
- title: "Single Prompt + Done Tool",
308
- description: "Run a one-shot prompt and force an explicit done tool call. The shared launcher shell chooses the model configuration.",
309
- },
310
- launchConfigSchema: {
311
- id: "single_prompt_with_tool_form",
312
- title: "Single Prompt + Done Tool",
313
- fields: [
314
- {
315
- id: "prompt",
316
- label: "Prompt",
317
- kind: "textarea",
318
- required: true,
319
- placeholder: "Say hello, then call the done tool with a short summary.",
320
- description: "The exact prompt sent to Pi for this one-shot run. This version requires the explicit done outcome tool.",
321
- },
322
- ],
323
- submitLabel: "Run Prompt + Tool",
324
- },
325
- resolveDefaults() {
326
- return {
327
- prompt: "",
328
- };
329
- },
330
- resolveLaunchConfig(input) {
331
- const validated = validateLaunchInput(input);
332
- if (!validated.ok) {
333
- return validated;
334
- }
335
- return {
336
- ok: true,
337
- launchConfig: {
338
- processId: "single_prompt_with_tool_process",
339
- params: { prompt: validated.prompt },
340
- titleSourceFields: buildPromptTitleSourceFields(validated.prompt),
341
- startTurnId: "run_single_prompt_with_tool",
342
- },
343
- };
344
- },
345
- },
346
- })
347
- .define();
348
- /**
349
- * Builds one of the Kubernetes smoke fixtures: an automatic worker run turn that
350
- * hands off to a wait turn with a `complete` action (and an optional `run_again`
351
- * action), plus a UI launcher. The three fixtures share this skeleton and differ
352
- * only in their ids, run body, and outcome parameter shape.
353
- */
354
- function defineK8sSmokeProcess(args) {
355
- const promptField = args.promptField;
356
- const resolveLaunchConfig = promptField
357
- ? (input) => {
358
- const validated = validateLaunchInput(input, args.defaultPrompt);
359
- if (!validated.ok)
360
- return validated;
361
- return {
362
- ok: true,
363
- launchConfig: {
364
- processId: args.processId,
365
- params: { prompt: validated.prompt },
366
- titleSourceFields: buildPromptTitleSourceFields(validated.prompt, args.titleLabel),
367
- startTurnId: args.runTurnId,
368
- },
369
- };
370
- }
371
- : () => ({
372
- ok: true,
373
- launchConfig: {
374
- processId: args.processId,
375
- params: { prompt: args.defaultPrompt },
376
- titleSourceFields: buildPromptTitleSourceFields(args.defaultPrompt, args.titleLabel),
377
- startTurnId: args.runTurnId,
378
- },
379
- });
380
- const runTurn = flow
381
- .automatic(args.runTurnId)
382
- .description(args.runTurnDescription)
383
- .run(async (ctx) => {
384
- const result = await args.run(ctx);
385
- return { outcome: "ready", ...result };
386
- })
387
- .outcome("ready", (outcome) => {
388
- outcome.description(args.outcomeDescription);
389
- args.describeOutcome?.(outcome);
390
- return outcome.to(args.waitTurnId);
391
- });
392
- const waitTurn = flow
393
- .human(args.waitTurnId)
394
- .description(args.waitDescription);
395
- if (args.waitCommentary) {
396
- waitTurn.commentary(args.waitCommentary);
397
- }
398
- if (args.runAgain) {
399
- const runAgain = args.runAgain;
400
- waitTurn.action("run_again", (action) => action
401
- .label(runAgain.label)
402
- .description(runAgain.description)
403
- .acceptanceState("neutral")
404
- .to(args.runTurnId));
405
- }
406
- waitTurn.action("complete", (action) => action.label(args.completeLabel).acceptanceState("accepted").complete());
407
- return flow
408
- .process(args.processId)
409
- .displayName(args.displayName)
410
- .entry(args.runTurnId)
411
- .codecs({ params: promptProcessParamsCodec, state: structuralStateCodec })
412
- .initialState(() => createEmptyStructuralProcessState())
413
- .turn(runTurn)
414
- .turn(waitTurn)
415
- .launcher({
416
- id: args.launcherId,
417
- label: args.displayName,
418
- description: args.launcherDescription,
419
- visibility: "ui",
420
- ui: {
421
- card: { title: args.displayName, description: args.cardDescription },
422
- launchConfigSchema: {
423
- id: args.formId,
424
- title: args.displayName,
425
- fields: promptField
426
- ? [{ id: "prompt", label: promptField.label, kind: "text", required: true }]
427
- : [],
428
- submitLabel: args.submitLabel,
429
- },
430
- ...(promptField ? { resolveDefaults: () => ({ prompt: args.defaultPrompt }) } : {}),
431
- resolveLaunchConfig,
432
- },
433
- })
434
- .define();
435
- }
436
- export const k8sSmokeProcess = defineK8sSmokeProcess({
437
- processId: "k8s_smoke_process",
438
- displayName: "Kubernetes Smoke",
439
- runTurnId: "k8s_smoke_run",
440
- waitTurnId: "k8s_smoke_wait",
441
- runTurnDescription: "Run a deterministic worker-side Kubernetes smoke step",
442
- outcomeDescription: "The worker-side smoke step completed",
443
- describeOutcome: (outcome) => outcome.string("prompt", "The smoke prompt"),
444
- waitDescription: "Wait after the Kubernetes smoke worker step",
445
- waitCommentary: "The smoke worker is idle; actions can respawn it on the retained PVC.",
446
- runAgain: { label: "Run smoke again", description: "Select the worker-side smoke turn again." },
447
- completeLabel: "Complete smoke",
448
- launcherId: "k8s_smoke_process.k8s_smoke_ui",
449
- launcherDescription: "Run a deterministic worker-backed Kubernetes smoke process",
450
- cardDescription: "Creates a worker pod/PVC and then waits for a follow-up action.",
451
- formId: "k8s_smoke_form",
452
- submitLabel: "Run smoke",
453
- promptField: { label: "Smoke prompt" },
454
- defaultPrompt: "kind smoke",
455
- titleLabel: "Smoke",
456
- run: (ctx) => ({
457
- params: { prompt: ctx.params.prompt },
458
- markdown: `Kubernetes smoke worker ran: ${ctx.params.prompt}`,
459
- }),
460
- });
461
- export const k8sSmokeSpecializedProcess = defineK8sSmokeProcess({
462
- processId: "k8s_smoke_specialized_process",
463
- displayName: "Kubernetes Specialized Smoke",
464
- runTurnId: "k8s_smoke_specialized_run",
465
- waitTurnId: "k8s_smoke_specialized_wait",
466
- runTurnDescription: "Verify the specialized Kubernetes worker image tool path",
467
- outcomeDescription: "The specialized image tool ran",
468
- describeOutcome: (outcome) => outcome.requiredString("output", "Tool output"),
469
- waitDescription: "Wait after specialized image verification",
470
- waitCommentary: "The specialized Kubernetes image was selected and executed its smoke tool.",
471
- completeLabel: "Complete specialized smoke",
472
- launcherId: "k8s_smoke_specialized_process.k8s_smoke_specialized_ui",
473
- launcherDescription: "Run a deterministic worker-backed process on the specialized smoke image",
474
- cardDescription: "Validates runtime-profile image selection with a deterministic tool.",
475
- formId: "k8s_smoke_specialized_form",
476
- submitLabel: "Run specialized smoke",
477
- defaultPrompt: "specialized",
478
- titleLabel: "Smoke",
479
- run: () => {
480
- const output = execFileSync("leitwerk-specialized-tool", { encoding: "utf8" }).trim();
481
- return { params: { output }, markdown: output };
482
- },
483
- });
484
- export const k8sSmokeLongProcess = defineK8sSmokeProcess({
485
- processId: "k8s_smoke_long_process",
486
- displayName: "Kubernetes Long Smoke",
487
- runTurnId: "k8s_smoke_long_run",
488
- waitTurnId: "k8s_smoke_long_wait",
489
- runTurnDescription: "Stay busy long enough for server restart adoption tests",
490
- outcomeDescription: "The long smoke step completed",
491
- waitDescription: "Wait after long smoke",
492
- completeLabel: "Complete long smoke",
493
- launcherId: "k8s_smoke_long_process.k8s_smoke_long_ui",
494
- launcherDescription: "Run a long worker-backed process for server restart adoption tests",
495
- cardDescription: "Keeps a worker pod busy while the server restarts.",
496
- formId: "k8s_smoke_long_form",
497
- submitLabel: "Run long smoke",
498
- defaultPrompt: "long",
499
- titleLabel: "Smoke",
500
- run: async () => {
501
- await delay(90_000);
502
- return { params: {}, markdown: "long smoke completed" };
503
- },
504
- });
505
- export const singlePromptExternalCompleteProcess = flow
506
- .process("single_prompt_external_complete_process")
507
- .displayName("Single Prompt + External Complete")
508
- .entry("run_single_prompt")
509
- .codecs({
510
- params: promptProcessParamsCodec,
511
- state: structuralStateCodec,
512
- })
513
- .initialState(() => createEmptyStructuralProcessState())
514
- .turn(flow
515
- .llm("run_single_prompt")
516
- .description("Run a single operator-provided prompt and finish on turn end")
517
- .tools("read", "bash", "edit", "write")
518
- .prompt(async (ctx) => buildSinglePromptInstruction(ctx.params.prompt))
519
- .end("completed")
520
- .to(externalPromptCompletionTurnId))
521
- .turn(flow
522
- .external(externalPromptCompletionTurnId)
523
- .description(externalPromptCompletionTurnDescription)
524
- .from(fileExternal.presence({
525
- path: "/tmp/complete-prompt",
526
- pollInterval: "1s",
527
- consume: "delete",
528
- }))
529
- .complete())
530
- .ui((api) => {
531
- api.leafOutcome(createMarkdownLeafOutcome("@leitwerk-dev/showcase-processes:single_prompt_external_complete_process.leaf_outcome"));
532
- })
533
- .launcher({
534
- id: "single_prompt_external_complete_process.single_prompt_external_complete_ui",
535
- label: "Single Prompt + External Complete",
536
- description: "Run one prompt, then wait for the external complete trigger file",
537
- visibility: "ui",
538
- ui: {
539
- card: {
540
- title: "Single Prompt + External Complete",
541
- description: "Run a one-shot prompt, preserve its result in the chronicle, and finish only when the external completion trigger fires.",
542
- },
543
- launchConfigSchema: {
544
- id: "single_prompt_external_complete_form",
545
- title: "Single Prompt + External Complete",
546
- fields: [
547
- {
548
- id: "prompt",
549
- label: "Prompt",
550
- kind: "textarea",
551
- required: true,
552
- placeholder: "Say hello, then wait for the external completion file.",
553
- description: "The prompt runs once. After it finishes, the process waits for the configured prompt-complete trigger file (default: /tmp/complete-prompt).",
554
- },
555
- ],
556
- submitLabel: "Run Prompt",
557
- },
558
- resolveDefaults() {
559
- return {
560
- prompt: "",
561
- };
562
- },
563
- resolveLaunchConfig(input) {
564
- const validated = validateLaunchInput(input);
565
- if (!validated.ok) {
566
- return validated;
567
- }
568
- return {
569
- ok: true,
570
- launchConfig: {
571
- processId: "single_prompt_external_complete_process",
572
- params: { prompt: validated.prompt },
573
- titleSourceFields: buildPromptTitleSourceFields(validated.prompt),
574
- startTurnId: "run_single_prompt",
575
- },
576
- };
577
- },
578
- },
579
- })
580
- .define();
581
- const poemDraftReviewSpec = flow
582
- .human(poemTurnIds.poemReview)
583
- .description("Human review of the drafted poem on the primary branch")
584
- .reviewProduct("poem-draft", { subject: "plan" })
585
- .notesFields([
586
- {
587
- id: "message",
588
- label: "Revision notes",
589
- placeholder: "Ask for a different tone, tighter rhythm, or stronger imagery",
590
- },
591
- ])
592
- .commentary("Review the poem on the primary branch, complete it, request another draft, or send it to automated review.")
593
- .action(poemCreatorActionIds.completePoem, (action) => action
594
- .label("Complete poem")
595
- .description("Accept the current poem and finish the process.")
596
- .acceptanceState("accepted")
597
- .complete()
598
- .effect(({ ctx }) => ({
599
- state: patchPoemCreatorState(ctx.state, {
600
- reviewSubject: null,
601
- }),
602
- })))
603
- .action(poemCreatorActionIds.requestRevision, (action) => action
604
- .label("Request revision")
605
- .description("Send the poem back for another primary-branch draft.")
606
- .acceptanceState("requires_changes")
607
- .form(poemRevisionForm)
608
- .trigger("revision_requested")
609
- .schedulable()
610
- .to(poemTurnIds.draftPoem))
611
- .action(poemCreatorActionIds.runAutoReview, (action) => action
612
- .label("Run automated review")
613
- .description("Send the current poem draft to the LLM reviewer.")
614
- .acceptanceState("neutral")
615
- .trigger("operator_re_review")
616
- .schedulable()
617
- .to(poemTurnIds.reviewPoemDraft)
618
- .effect(({ ctx }) => ({
619
- state: patchPoemCreatorState(ctx.state, {
620
- reviewSubject: createReviewSubject(poemFeedbackReviewSubject.kind),
621
- latestReviewMarkdown: null,
622
- latestReviewSummary: null,
623
- latestReviewOutcome: null,
624
- clearReviewRefs: true,
625
- }),
626
- })))
627
- .externalAction("poem_review_file", fileExternal.instruction({
628
- path: "/tmp/poem-review-{instanceId}",
629
- pollInterval: "1s",
630
- consume: "delete",
631
- }), (external) => external
632
- .label("Configured poem review file")
633
- .description("Write revision feedback to the configured poem-review file")
634
- .publishInput("message", { inputField: "instruction" })
635
- .to(poemTurnIds.draftPoem)).definition;
636
- const poemReviewFeedbackSpec = flow
637
- .human(poemTurnIds.poemReviewFeedback)
638
- .description("Human review of the LLM review output")
639
- .reviewProduct("message", { subject: "implementation" })
640
- .notesFields([
641
- {
642
- id: "message",
643
- label: "Review feedback notes",
644
- placeholder: "Explain what the LLM reviewer should change in its review",
645
- },
646
- ])
647
- .commentary("Review the review output itself. Accept it to pass the feedback to the primary branch, request changes to continue on the same review branch, or dismiss it and return to the poem decision.")
648
- .action(poemCreatorActionIds.acceptReview, (action) => action
649
- .label("Accept review")
650
- .description("Accept the current review outcome and continue with the primary-branch poem flow.")
651
- .acceptanceState("accepted")
652
- .to(poemTurnIds.draftPoem))
653
- .action(poemCreatorActionIds.requestReviewChanges, (action) => action
654
- .label("Request review changes")
655
- .description("Ask the LLM reviewer to revise its review on the review branch.")
656
- .acceptanceState("requires_changes")
657
- .form(poemReviewChangesForm)
658
- .trigger("operator_re_review")
659
- .schedulable()
660
- .to(poemTurnIds.reviewPoemDraft))
661
- .action(poemCreatorActionIds.dismissReview, (action) => action
662
- .label("Dismiss review")
663
- .description("Return to the poem decision without applying the review feedback.")
664
- .acceptanceState("neutral")
665
- .to(poemTurnIds.poemReview)
666
- .effect(({ ctx }) => ({
667
- state: patchPoemCreatorState(ctx.state, {
668
- reviewSubject: createReviewSubject(poemDraftReviewSubject.kind),
669
- latestReviewMarkdown: null,
670
- latestReviewSummary: null,
671
- latestReviewOutcome: null,
672
- clearReviewRefs: true,
673
- }),
674
- }))).definition;
675
- export const poemCreatorProcess = flow
676
- .process("poem_creator_process")
677
- .displayName("Poem Creator")
678
- .entry(poemTurnIds.draftPoem)
679
- .codecs({
680
- params: promptProcessParamsCodec,
681
- state: poemCreatorStateCodec,
682
- })
683
- .initialState(() => ({
684
- ...createEmptyStructuralProcessState(),
685
- latestReviewMarkdown: null,
686
- latestReviewSummary: null,
687
- latestReviewOutcome: null,
688
- }))
689
- .turn(flow
690
- .llm(poemTurnIds.draftPoem)
691
- .description("Draft poem")
692
- .fullPrimary()
693
- .continueFromPrimaryLeaf()
694
- .optionalConsume("message")
695
- .buildPrompt(async (ctx) => {
696
- const message = ctx.input.message?.trim();
697
- return message
698
- ? buildRevisePoemInstruction(message)
699
- : buildDraftPoemInstruction(ctx.params.prompt);
700
- })
701
- .publish("poem-draft")
702
- .to(poemTurnIds.poemReview)
703
- .state(({ ctx }) => patchPoemCreatorState(ctx.state, {
704
- reviewSubject: createReviewSubject(poemDraftReviewSubject.kind),
705
- latestReviewMarkdown: null,
706
- latestReviewSummary: null,
707
- latestReviewOutcome: null,
708
- clearReviewRefs: true,
709
- })))
710
- .turn({ id: poemTurnIds.poemReview, definition: poemDraftReviewSpec })
711
- .turn(flow
712
- .llm(poemTurnIds.reviewPoemDraft)
713
- .description("Review poem")
714
- .rootBranchReview()
715
- .continueFromReviewBranch()
716
- .reviews(createReviewSubject("plan"))
717
- .consume("poem-draft")
718
- .optionalConsume("message")
719
- .buildPrompt(async (ctx) => {
720
- const message = ctx.input.message?.trim();
721
- const poemDraft = ctx.input["poem-draft"];
722
- if (!poemDraft) {
723
- throw new Error("Review poem turn requires poem-draft input");
724
- }
725
- const reviewInstruction = buildReviewPoemInstruction(ctx.params.prompt, poemDraft);
726
- return message
727
- ? `${reviewInstruction}\n\nReviewer revision guidance:\n${message}`
728
- : reviewInstruction;
729
- })
730
- .outcomeTool("no_issues", (tool) => tool
731
- .description("The poem is ready to publish")
732
- .requiredString("summary", "Short confirmation summary")
733
- .markdown("review", {
734
- description: "Concise review opinion confirming the poem is ready",
735
- publish: true,
736
- })
737
- .to(poemTurnIds.poemReview)
738
- .state(({ ctx, event }) => patchPoemCreatorState(ctx.state, {
739
- reviewSubject: createReviewSubject(poemDraftReviewSubject.kind),
740
- latestReviewMarkdown: null,
741
- latestReviewSummary: typeof event.params.summary === "string" ? event.params.summary : null,
742
- latestReviewOutcome: "no_issues",
743
- })))
744
- .outcomeTool("leave_feedback", (tool) => tool
745
- .description("Leave concise feedback for the human reviewer")
746
- .requiredString("summary", "Short summary of the feedback")
747
- .markdown("message", {
748
- description: "Concise plain-text feedback describing what to improve",
749
- publish: true,
750
- })
751
- .to(poemTurnIds.poemReviewFeedback)
752
- .state(({ ctx, event }) => patchPoemCreatorState(ctx.state, {
753
- reviewSubject: createReviewSubject(poemFeedbackReviewSubject.kind),
754
- latestReviewMarkdown: typeof event.params.message === "string"
755
- ? event.params.message
756
- : (ctx.output?.content ?? null),
757
- latestReviewSummary: typeof event.params.summary === "string" ? event.params.summary : null,
758
- latestReviewOutcome: "leave_feedback",
759
- }))))
760
- .turn({ id: poemTurnIds.poemReviewFeedback, definition: poemReviewFeedbackSpec })
761
- .ui((api) => {
762
- api.leafOutcome(createPoemLeafOutcome("@leitwerk-dev/showcase-processes:poem_creator_process.leaf_outcome"));
763
- })
764
- .launcher({
765
- id: "poem_creator_process.poem_creator_ui",
766
- label: "Poem Creator",
767
- description: "Create a poem, review it on the primary branch, and optionally send it through a human-gated llm review loop",
768
- visibility: "ui",
769
- ui: {
770
- card: {
771
- title: "Poem Creator",
772
- description: "A fast multi-step demo: poem drafting on the primary branch plus a human-gated llm review branch.",
773
- },
774
- launchConfigSchema: {
775
- id: "poem_creator_form",
776
- title: "Poem Creator",
777
- fields: [
778
- {
779
- id: "prompt",
780
- label: "Poem Prompt",
781
- kind: "textarea",
782
- required: true,
783
- placeholder: "Write a short poem about the weather in Berlin or the joy of shipping cloud software.",
784
- description: "Leave the prefilled prompt as-is to try the feature immediately, or replace it with your own poem idea.",
785
- },
786
- ],
787
- submitLabel: "Create Poem",
788
- },
789
- resolveDefaults() {
790
- return {
791
- prompt: buildDefaultPoemPrompt(),
792
- };
793
- },
794
- resolveLaunchConfig(input) {
795
- const validated = validateLaunchInput(input, buildDefaultPoemPrompt());
796
- if (!validated.ok) {
797
- return validated;
798
- }
799
- return {
800
- ok: true,
801
- launchConfig: {
802
- processId: "poem_creator_process",
803
- params: { prompt: validated.prompt },
804
- titleSourceFields: buildPromptTitleSourceFields(validated.prompt, "Poem Prompt"),
805
- startTurnId: poemTurnIds.draftPoem,
806
- },
807
- };
808
- },
809
- },
810
- })
811
- .watcher({
812
- id: "create_poem",
813
- label: "Create Poem from File",
814
- description: "Launch Poem Creator whenever the configured filesystem watcher finds a prompt file",
815
- type: "filesystem",
816
- matches(event) {
817
- return typeof event.content === "string";
818
- },
819
- resolveLaunchConfig(event) {
820
- const prompt = typeof event.content === "string"
821
- ? event.content.trim()
822
- : "";
823
- return {
824
- processId: "poem_creator_process",
825
- params: { prompt },
826
- titleSourceFields: buildPromptTitleSourceFields(prompt, "Poem Prompt"),
827
- startTurnId: poemTurnIds.draftPoem,
828
- };
829
- },
830
- })
831
- .define();
832
- //# sourceMappingURL=process-definition.js.map