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