@leitwerk-dev/showcase-processes 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,16 +1,11 @@
1
- import { execFileSync } from "node:child_process";
2
- import { setTimeout as delay } from "node:timers/promises";
3
1
  import {
4
- type AutomaticOutcomeBuilder,
5
2
  type Codec,
6
3
  createEmptyStructuralProcessState,
7
- type ExtensionProcessDefinition,
8
4
  type FormDefinition,
9
5
  flow,
10
- type HumanFlowBuilder,
6
+ type ProcessLeafOutcomeDefinition,
11
7
  parseStructuralProcessState,
12
8
  type StructuralProcessState,
13
- structuralStateCodec,
14
9
  } from "@leitwerk-dev/process-sdk";
15
10
  import { fileExternal } from "./file-external.js";
16
11
  import { filesystemWatcherSource } from "./filesystem-watcher.js";
@@ -19,10 +14,6 @@ import {
19
14
  buildPoemLeafOutcomePayload,
20
15
  resolvePoemLeafMarkdown,
21
16
  } from "./poem-leaf-outcome.js";
22
- import {
23
- externalPromptCompletionTurnDescription,
24
- externalPromptCompletionTurnId,
25
- } from "./turns/external-complete.js";
26
17
  import {
27
18
  buildDefaultPoemPrompt,
28
19
  buildDraftPoemInstruction,
@@ -30,10 +21,6 @@ import {
30
21
  buildRevisePoemInstruction,
31
22
  poemCreatorActionIds,
32
23
  } from "./turns/poem-creator.js";
33
- import {
34
- buildSinglePromptInstruction,
35
- buildSinglePromptWithToolInstruction,
36
- } from "./turns/run-single-prompt.js";
37
24
 
38
25
  /** @internal */
39
26
  interface PromptProcessParams {
@@ -53,13 +40,9 @@ interface PoemCreatorState extends StructuralProcessState {
53
40
 
54
41
  const promptProcessParamsCodec: Codec<PromptProcessParams> = {
55
42
  parse(value) {
56
- const record = typeof value === "object" && value !== null ? value : {};
57
- return {
58
- prompt:
59
- typeof (record as { prompt?: unknown }).prompt === "string"
60
- ? (record as { prompt: string }).prompt
61
- : "",
62
- };
43
+ const record =
44
+ typeof value === "object" && value !== null ? (value as Record<string, unknown>) : {};
45
+ return { prompt: typeof record.prompt === "string" ? record.prompt : "" };
63
46
  },
64
47
  serialize(value) {
65
48
  return value;
@@ -72,14 +55,12 @@ const poemCreatorStateCodec: Codec<PoemCreatorState> = {
72
55
  const record =
73
56
  typeof value === "object" && value !== null ? (value as Record<string, unknown>) : {};
74
57
  const latestReviewOutcome =
75
- typeof record.latestReviewOutcome === "string"
76
- ? record.latestReviewOutcome === "issues_found"
77
- ? "leave_feedback"
78
- : record.latestReviewOutcome === "no_issues" ||
79
- record.latestReviewOutcome === "leave_feedback"
80
- ? record.latestReviewOutcome
81
- : null
82
- : null;
58
+ record.latestReviewOutcome === "issues_found"
59
+ ? "leave_feedback"
60
+ : record.latestReviewOutcome === "no_issues" ||
61
+ record.latestReviewOutcome === "leave_feedback"
62
+ ? record.latestReviewOutcome
63
+ : null;
83
64
  return {
84
65
  ...structural,
85
66
  latestReviewMarkdown:
@@ -94,85 +75,22 @@ const poemCreatorStateCodec: Codec<PoemCreatorState> = {
94
75
  },
95
76
  };
96
77
 
97
- function validateLaunchInput(input: Record<string, unknown>, fallbackPrompt?: string) {
98
- const inputPrompt = typeof input.prompt === "string" ? input.prompt.trim() : "";
99
- const prompt = inputPrompt || fallbackPrompt?.trim() || "";
100
- if (!prompt) {
101
- return {
102
- ok: false as const,
103
- errors: [{ code: "required", fieldId: "prompt", message: "prompt is required" }],
104
- };
105
- }
78
+ function poemLaunchConfig(prompt: string) {
106
79
  return {
107
- ok: true as const,
108
- prompt,
80
+ processId: "poem_creator_process",
81
+ params: { prompt },
82
+ titleSourceFields: [{ label: "Poem Prompt", value: prompt }],
83
+ startTurnId: poemTurnIds.draftPoem,
109
84
  };
110
85
  }
111
86
 
112
- function buildPromptTitleSourceFields(prompt: string, label = "Prompt") {
113
- return [{ label, value: prompt }] as const;
114
- }
115
-
116
- function promptLaunchResolution(options: {
117
- processId: string;
118
- startTurnId: string;
119
- defaultPrompt?: () => string;
120
- titleLabel?: string;
121
- }) {
87
+ function resetPoemReview(state: PoemCreatorState): PoemCreatorState {
122
88
  return {
123
- resolveDefaults: () => ({ prompt: options.defaultPrompt?.() ?? "" }),
124
- resolveLaunchConfig(input: Record<string, unknown>) {
125
- const validated = validateLaunchInput(input, options.defaultPrompt?.());
126
- if (!validated.ok) return validated;
127
- return {
128
- ok: true as const,
129
- launchConfig: {
130
- processId: options.processId,
131
- params: { prompt: validated.prompt },
132
- titleSourceFields: buildPromptTitleSourceFields(validated.prompt, options.titleLabel),
133
- startTurnId: options.startTurnId,
134
- },
135
- };
136
- },
137
- };
138
- }
139
-
140
- function clearReviewRefs(state: PoemCreatorState["semanticEntryRefs"]) {
141
- return {
142
- ...state,
143
- review: null,
144
- };
145
- }
146
-
147
- function patchPoemCreatorState(
148
- state: PoemCreatorState,
149
- input: {
150
- latestReviewMarkdown?: PoemCreatorState["latestReviewMarkdown"];
151
- latestReviewSummary?: PoemCreatorState["latestReviewSummary"];
152
- latestReviewOutcome?: PoemCreatorState["latestReviewOutcome"];
153
- semanticEntryRefs?: PoemCreatorState["semanticEntryRefs"];
154
- clearReviewRefs?: boolean;
155
- },
156
- ): PoemCreatorState {
157
- const nextState: PoemCreatorState = {
158
89
  ...state,
159
- ...("latestReviewMarkdown" in input
160
- ? { latestReviewMarkdown: input.latestReviewMarkdown ?? null }
161
- : {}),
162
- ...("latestReviewSummary" in input
163
- ? { latestReviewSummary: input.latestReviewSummary ?? null }
164
- : {}),
165
- ...("latestReviewOutcome" in input
166
- ? { latestReviewOutcome: input.latestReviewOutcome ?? null }
167
- : {}),
168
- ...("semanticEntryRefs" in input ? { semanticEntryRefs: input.semanticEntryRefs } : {}),
169
- };
170
- if (!input.clearReviewRefs) {
171
- return nextState;
172
- }
173
- return {
174
- ...nextState,
175
- semanticEntryRefs: clearReviewRefs(nextState.semanticEntryRefs),
90
+ latestReviewMarkdown: null,
91
+ latestReviewSummary: null,
92
+ latestReviewOutcome: null,
93
+ semanticEntryRefs: { ...state.semanticEntryRefs, review: null },
176
94
  };
177
95
  }
178
96
 
@@ -187,42 +105,10 @@ function buildPoemLeafReview(state: PoemCreatorState) {
187
105
  };
188
106
  }
189
107
 
190
- function createMarkdownLeafOutcome(rendererId: string) {
191
- return {
192
- rendererId,
193
- capture(ctx: {
194
- params: PromptProcessParams;
195
- leaf: { entryId: string; turnRecordId: string | null };
196
- turnRecord: { turnResultMarkdown: string | null } | null;
197
- }) {
198
- const markdown = ctx.turnRecord?.turnResultMarkdown?.trim() ?? "";
199
- return {
200
- rendererId,
201
- schemaVersion: 1,
202
- props: {
203
- prompt: ctx.params.prompt,
204
- markdown: markdown.length > 0 ? markdown : null,
205
- leafEntryId: ctx.leaf.entryId,
206
- turnRecordId: ctx.leaf.turnRecordId,
207
- },
208
- fallbackMarkdown: markdown.length > 0 ? markdown : null,
209
- };
210
- },
211
- };
212
- }
213
-
214
108
  function createPoemLeafOutcome(rendererId: string) {
215
109
  return {
216
110
  rendererId,
217
- capture(ctx: {
218
- params: PromptProcessParams;
219
- state: PoemCreatorState;
220
- leaf: { entryId: string; turnRecordId: string | null };
221
- turnRecord: { turnResultMarkdown: string | null } | null;
222
- readTreeEntry(entryId: string): { message?: { content?: unknown } } | null;
223
- readLeafEntry(): { message?: { content?: unknown } } | null;
224
- readTurnRecord(turnRecordId: string): { turnResultMarkdown: string | null } | null;
225
- }) {
111
+ capture(ctx) {
226
112
  const reviewLeafEntryId = ctx.state.semanticEntryRefs.review?.entryId ?? null;
227
113
  const review = buildPoemLeafReview(ctx.state);
228
114
  const isReviewLeaf = reviewLeafEntryId !== null && ctx.leaf.entryId === reviewLeafEntryId;
@@ -260,7 +146,7 @@ function createPoemLeafOutcome(rendererId: string) {
260
146
  fallbackMarkdown: fallbackMarkdown || null,
261
147
  };
262
148
  },
263
- };
149
+ } satisfies ProcessLeafOutcomeDefinition<PromptProcessParams, PoemCreatorState>;
264
150
  }
265
151
 
266
152
  const poemTurnIds = {
@@ -304,413 +190,6 @@ const poemReviewChangesForm: FormDefinition = {
304
190
  submitLabel: "Request review changes",
305
191
  };
306
192
 
307
- /** @internal */
308
- export const singlePromptProcess: ExtensionProcessDefinition<
309
- PromptProcessParams,
310
- StructuralProcessState
311
- > = flow
312
- .process<PromptProcessParams, StructuralProcessState>("single_prompt_process")
313
- .displayName("Single Prompt")
314
- .entry("run_single_prompt")
315
- .codecs({
316
- params: promptProcessParamsCodec,
317
- state: structuralStateCodec,
318
- })
319
- .initialState(() => createEmptyStructuralProcessState())
320
- .turn(
321
- flow
322
- .llm<PromptProcessParams, StructuralProcessState>("run_single_prompt")
323
- .description("Run Prompt")
324
- .tools("read", "bash", "edit", "write")
325
- .prompt(async (ctx) => buildSinglePromptInstruction(ctx.params.prompt))
326
- .end("completed")
327
- .complete(),
328
- )
329
- .ui((api) => {
330
- api.leafOutcome(
331
- createMarkdownLeafOutcome(
332
- "@leitwerk-dev/showcase-processes:single_prompt_process.leaf_outcome",
333
- ),
334
- );
335
- })
336
- .launcher({
337
- id: "single_prompt_process.single_prompt_ui",
338
- label: "Single Prompt",
339
- description: "Run one prompt and finish on turn end",
340
- visibility: "ui",
341
- ui: {
342
- card: {
343
- title: "Single Prompt",
344
- description:
345
- "Run a one-shot prompt. The shared launcher shell chooses the model configuration.",
346
- },
347
- launchConfigSchema: {
348
- id: "single_prompt_form",
349
- title: "Single Prompt",
350
- fields: [
351
- {
352
- id: "prompt",
353
- label: "Prompt",
354
- kind: "textarea",
355
- required: true,
356
- placeholder: "Say hello.",
357
- description:
358
- "The exact prompt sent to Pi for this one-shot run. This version finishes when the assistant turn ends normally.",
359
- },
360
- ],
361
- submitLabel: "Run Prompt",
362
- },
363
- ...promptLaunchResolution({
364
- processId: "single_prompt_process",
365
- startTurnId: "run_single_prompt",
366
- }),
367
- },
368
- })
369
- .define();
370
-
371
- /** @internal */
372
- export const singlePromptWithToolProcess: ExtensionProcessDefinition<
373
- PromptProcessParams,
374
- StructuralProcessState
375
- > = flow
376
- .process<PromptProcessParams, StructuralProcessState>("single_prompt_with_tool_process")
377
- .displayName("Single Prompt + Done Tool")
378
- .entry("run_single_prompt_with_tool")
379
- .codecs({
380
- params: promptProcessParamsCodec,
381
- state: structuralStateCodec,
382
- })
383
- .initialState(() => createEmptyStructuralProcessState())
384
- .turn(
385
- flow
386
- .llm<PromptProcessParams, StructuralProcessState>("run_single_prompt_with_tool")
387
- .description("Run Prompt")
388
- .tools("read", "bash", "edit", "write")
389
- .prompt(async (ctx) => buildSinglePromptWithToolInstruction(ctx.params.prompt))
390
- .outcomeTool("done", (tool) =>
391
- tool
392
- .description("Mark the prompt run as complete")
393
- .requiredString("summary", "Short summary of the result")
394
- .complete(),
395
- ),
396
- )
397
- .ui((api) => {
398
- api.leafOutcome(
399
- createMarkdownLeafOutcome(
400
- "@leitwerk-dev/showcase-processes:single_prompt_with_tool_process.leaf_outcome",
401
- ),
402
- );
403
- })
404
- .launcher({
405
- id: "single_prompt_with_tool_process.single_prompt_with_tool_ui",
406
- label: "Single Prompt + Done Tool",
407
- description: "Run one prompt and require an explicit done tool",
408
- visibility: "ui",
409
- ui: {
410
- card: {
411
- title: "Single Prompt + Done Tool",
412
- description:
413
- "Run a one-shot prompt and force an explicit done tool call. The shared launcher shell chooses the model configuration.",
414
- },
415
- launchConfigSchema: {
416
- id: "single_prompt_with_tool_form",
417
- title: "Single Prompt + Done Tool",
418
- fields: [
419
- {
420
- id: "prompt",
421
- label: "Prompt",
422
- kind: "textarea",
423
- required: true,
424
- placeholder: "Say hello, then call the done tool with a short summary.",
425
- description:
426
- "The exact prompt sent to Pi for this one-shot run. This version requires the explicit done outcome tool.",
427
- },
428
- ],
429
- submitLabel: "Run Prompt + Tool",
430
- },
431
- ...promptLaunchResolution({
432
- processId: "single_prompt_with_tool_process",
433
- startTurnId: "run_single_prompt_with_tool",
434
- }),
435
- },
436
- })
437
- .define();
438
-
439
- type SmokeOutcomeBuilder = AutomaticOutcomeBuilder<PromptProcessParams, StructuralProcessState>;
440
- type SmokeRunFn = (ctx: {
441
- params: PromptProcessParams;
442
- }) =>
443
- | { params: Record<string, unknown>; markdown: string }
444
- | Promise<{ params: Record<string, unknown>; markdown: string }>;
445
-
446
- /**
447
- * Builds one of the Kubernetes smoke fixtures: an automatic worker run turn that
448
- * hands off to a wait turn with a `complete` action (and an optional `run_again`
449
- * action), plus a UI launcher. The three fixtures share this skeleton and differ
450
- * only in their ids, run body, and outcome parameter shape.
451
- */
452
- function defineK8sSmokeProcess(args: {
453
- processId: string;
454
- displayName: string;
455
- runTurnId: string;
456
- waitTurnId: string;
457
- runTurnDescription: string;
458
- outcomeDescription: string;
459
- describeOutcome?: (outcome: SmokeOutcomeBuilder) => void;
460
- waitDescription: string;
461
- waitCommentary?: string;
462
- runAgain?: { label: string; description: string };
463
- completeLabel: string;
464
- launcherId: string;
465
- launcherDescription: string;
466
- cardDescription: string;
467
- formId: string;
468
- submitLabel: string;
469
- promptField?: { label: string };
470
- defaultPrompt: string;
471
- titleLabel: string;
472
- run: SmokeRunFn;
473
- }): ExtensionProcessDefinition<PromptProcessParams, StructuralProcessState> {
474
- const promptField = args.promptField;
475
- const resolveLaunchConfig = promptField
476
- ? (input: Record<string, unknown>) => {
477
- const validated = validateLaunchInput(input, args.defaultPrompt);
478
- if (!validated.ok) return validated;
479
- return {
480
- ok: true as const,
481
- launchConfig: {
482
- processId: args.processId,
483
- params: { prompt: validated.prompt },
484
- titleSourceFields: buildPromptTitleSourceFields(validated.prompt, args.titleLabel),
485
- startTurnId: args.runTurnId,
486
- },
487
- };
488
- }
489
- : () => ({
490
- ok: true as const,
491
- launchConfig: {
492
- processId: args.processId,
493
- params: { prompt: args.defaultPrompt },
494
- titleSourceFields: buildPromptTitleSourceFields(args.defaultPrompt, args.titleLabel),
495
- startTurnId: args.runTurnId,
496
- },
497
- });
498
-
499
- const runTurn = flow
500
- .automatic<PromptProcessParams, StructuralProcessState>(args.runTurnId)
501
- .description(args.runTurnDescription)
502
- .run(async (ctx) => {
503
- const result = await args.run(ctx);
504
- return { outcome: "ready" as const, ...result };
505
- })
506
- .outcome("ready", (outcome) => {
507
- outcome.description(args.outcomeDescription);
508
- args.describeOutcome?.(outcome);
509
- return outcome.to(args.waitTurnId);
510
- });
511
-
512
- const waitTurn: HumanFlowBuilder<PromptProcessParams, StructuralProcessState> = flow
513
- .human<PromptProcessParams, StructuralProcessState>(args.waitTurnId)
514
- .description(args.waitDescription);
515
- if (args.waitCommentary) {
516
- waitTurn.commentary(args.waitCommentary);
517
- }
518
- if (args.runAgain) {
519
- const runAgain = args.runAgain;
520
- waitTurn.action("run_again", (action) =>
521
- action
522
- .label(runAgain.label)
523
- .description(runAgain.description)
524
- .acceptanceState("neutral")
525
- .to(args.runTurnId),
526
- );
527
- }
528
- waitTurn.action("complete", (action) =>
529
- action.label(args.completeLabel).acceptanceState("accepted").complete(),
530
- );
531
-
532
- return flow
533
- .process<PromptProcessParams, StructuralProcessState>(args.processId)
534
- .displayName(args.displayName)
535
- .entry(args.runTurnId)
536
- .codecs({ params: promptProcessParamsCodec, state: structuralStateCodec })
537
- .initialState(() => createEmptyStructuralProcessState())
538
- .turn(runTurn)
539
- .turn(waitTurn)
540
- .launcher({
541
- id: args.launcherId,
542
- label: args.displayName,
543
- description: args.launcherDescription,
544
- visibility: "ui",
545
- ui: {
546
- card: { title: args.displayName, description: args.cardDescription },
547
- launchConfigSchema: {
548
- id: args.formId,
549
- title: args.displayName,
550
- fields: promptField
551
- ? [{ id: "prompt", label: promptField.label, kind: "text", required: true }]
552
- : [],
553
- submitLabel: args.submitLabel,
554
- },
555
- ...(promptField ? { resolveDefaults: () => ({ prompt: args.defaultPrompt }) } : {}),
556
- resolveLaunchConfig,
557
- },
558
- })
559
- .define();
560
- }
561
-
562
- /** @internal */
563
- export const k8sSmokeProcess = defineK8sSmokeProcess({
564
- processId: "k8s_smoke_process",
565
- displayName: "Kubernetes Smoke",
566
- runTurnId: "k8s_smoke_run",
567
- waitTurnId: "k8s_smoke_wait",
568
- runTurnDescription: "Run a deterministic worker-side Kubernetes smoke step",
569
- outcomeDescription: "The worker-side smoke step completed",
570
- describeOutcome: (outcome) => outcome.string("prompt", "The smoke prompt"),
571
- waitDescription: "Wait after the Kubernetes smoke worker step",
572
- waitCommentary: "The smoke worker is idle; actions can respawn it on the retained PVC.",
573
- runAgain: { label: "Run smoke again", description: "Select the worker-side smoke turn again." },
574
- completeLabel: "Complete smoke",
575
- launcherId: "k8s_smoke_process.k8s_smoke_ui",
576
- launcherDescription: "Run a deterministic worker-backed Kubernetes smoke process",
577
- cardDescription: "Creates a worker pod/PVC and then waits for a follow-up action.",
578
- formId: "k8s_smoke_form",
579
- submitLabel: "Run smoke",
580
- promptField: { label: "Smoke prompt" },
581
- defaultPrompt: "kind smoke",
582
- titleLabel: "Smoke",
583
- run: (ctx) => ({
584
- params: { prompt: ctx.params.prompt },
585
- markdown: `Kubernetes smoke worker ran: ${ctx.params.prompt}`,
586
- }),
587
- });
588
-
589
- /** @internal */
590
- export const k8sSmokeSpecializedProcess = defineK8sSmokeProcess({
591
- processId: "k8s_smoke_specialized_process",
592
- displayName: "Kubernetes Specialized Smoke",
593
- runTurnId: "k8s_smoke_specialized_run",
594
- waitTurnId: "k8s_smoke_specialized_wait",
595
- runTurnDescription: "Verify the specialized Kubernetes worker image tool path",
596
- outcomeDescription: "The specialized image tool ran",
597
- describeOutcome: (outcome) => outcome.requiredString("output", "Tool output"),
598
- waitDescription: "Wait after specialized image verification",
599
- waitCommentary: "The specialized Kubernetes image was selected and executed its smoke tool.",
600
- completeLabel: "Complete specialized smoke",
601
- launcherId: "k8s_smoke_specialized_process.k8s_smoke_specialized_ui",
602
- launcherDescription: "Run a deterministic worker-backed process on the specialized smoke image",
603
- cardDescription: "Validates runtime-profile image selection with a deterministic tool.",
604
- formId: "k8s_smoke_specialized_form",
605
- submitLabel: "Run specialized smoke",
606
- defaultPrompt: "specialized",
607
- titleLabel: "Smoke",
608
- run: () => {
609
- const output = execFileSync("leitwerk-specialized-tool", { encoding: "utf8" }).trim();
610
- return { params: { output }, markdown: output };
611
- },
612
- });
613
-
614
- /** @internal */
615
- export const k8sSmokeLongProcess = defineK8sSmokeProcess({
616
- processId: "k8s_smoke_long_process",
617
- displayName: "Kubernetes Long Smoke",
618
- runTurnId: "k8s_smoke_long_run",
619
- waitTurnId: "k8s_smoke_long_wait",
620
- runTurnDescription: "Stay busy long enough for server restart adoption tests",
621
- outcomeDescription: "The long smoke step completed",
622
- waitDescription: "Wait after long smoke",
623
- completeLabel: "Complete long smoke",
624
- launcherId: "k8s_smoke_long_process.k8s_smoke_long_ui",
625
- launcherDescription: "Run a long worker-backed process for server restart adoption tests",
626
- cardDescription: "Keeps a worker pod busy while the server restarts.",
627
- formId: "k8s_smoke_long_form",
628
- submitLabel: "Run long smoke",
629
- defaultPrompt: "long",
630
- titleLabel: "Smoke",
631
- run: async () => {
632
- await delay(90_000);
633
- return { params: {}, markdown: "long smoke completed" };
634
- },
635
- });
636
-
637
- /** @internal */
638
- export const singlePromptExternalCompleteProcess: ExtensionProcessDefinition<
639
- PromptProcessParams,
640
- StructuralProcessState
641
- > = flow
642
- .process<PromptProcessParams, StructuralProcessState>("single_prompt_external_complete_process")
643
- .displayName("Single Prompt + External Complete")
644
- .entry("run_single_prompt")
645
- .codecs({
646
- params: promptProcessParamsCodec,
647
- state: structuralStateCodec,
648
- })
649
- .initialState(() => createEmptyStructuralProcessState())
650
- .turn(
651
- flow
652
- .llm<PromptProcessParams, StructuralProcessState>("run_single_prompt")
653
- .description("Run Prompt")
654
- .tools("read", "bash", "edit", "write")
655
- .prompt(async (ctx) => buildSinglePromptInstruction(ctx.params.prompt))
656
- .end("completed")
657
- .to(externalPromptCompletionTurnId),
658
- )
659
- .turn(
660
- flow
661
- .external<PromptProcessParams, StructuralProcessState>(externalPromptCompletionTurnId)
662
- .description(externalPromptCompletionTurnDescription)
663
- .from(
664
- fileExternal.presence({
665
- path: "/tmp/complete-prompt",
666
- pollInterval: "1s",
667
- consume: "delete",
668
- }),
669
- )
670
- .complete(),
671
- )
672
- .ui((api) => {
673
- api.leafOutcome(
674
- createMarkdownLeafOutcome(
675
- "@leitwerk-dev/showcase-processes:single_prompt_external_complete_process.leaf_outcome",
676
- ),
677
- );
678
- })
679
- .launcher({
680
- id: "single_prompt_external_complete_process.single_prompt_external_complete_ui",
681
- label: "Single Prompt + External Complete",
682
- description: "Run one prompt, then wait for the external complete trigger file",
683
- visibility: "ui",
684
- ui: {
685
- card: {
686
- title: "Single Prompt + External Complete",
687
- description:
688
- "Run a one-shot prompt, preserve its result in the chronicle, and finish only when the external completion trigger fires.",
689
- },
690
- launchConfigSchema: {
691
- id: "single_prompt_external_complete_form",
692
- title: "Single Prompt + External Complete",
693
- fields: [
694
- {
695
- id: "prompt",
696
- label: "Prompt",
697
- kind: "textarea",
698
- required: true,
699
- placeholder: "Say hello, then wait for the external completion file.",
700
- description:
701
- "The prompt runs once. After it finishes, the process waits for the configured prompt-complete trigger file (default: /tmp/complete-prompt).",
702
- },
703
- ],
704
- submitLabel: "Run Prompt",
705
- },
706
- ...promptLaunchResolution({
707
- processId: "single_prompt_external_complete_process",
708
- startTurnId: "run_single_prompt",
709
- }),
710
- },
711
- })
712
- .define();
713
-
714
193
  const poemDraftReviewSpec = flow
715
194
  .human<PromptProcessParams, PoemCreatorState>(poemTurnIds.poemReview)
716
195
  .description("Review")
@@ -750,14 +229,7 @@ const poemDraftReviewSpec = flow
750
229
  .trigger("operator_re_review")
751
230
  .schedulable()
752
231
  .to(poemTurnIds.reviewPoemDraft)
753
- .effect(({ ctx }) => ({
754
- state: patchPoemCreatorState(ctx.state, {
755
- latestReviewMarkdown: null,
756
- latestReviewSummary: null,
757
- latestReviewOutcome: null,
758
- clearReviewRefs: true,
759
- }),
760
- })),
232
+ .effect(({ ctx }) => ({ state: resetPoemReview(ctx.state) })),
761
233
  )
762
234
  .externalAction(
763
235
  "poem_review_file",
@@ -813,17 +285,11 @@ const poemReviewFeedbackSpec = flow
813
285
  .description("Return to the poem decision without applying the review feedback.")
814
286
  .acceptanceState("neutral")
815
287
  .to(poemTurnIds.poemReview)
816
- .effect(({ ctx }) => ({
817
- state: patchPoemCreatorState(ctx.state, {
818
- latestReviewMarkdown: null,
819
- latestReviewSummary: null,
820
- latestReviewOutcome: null,
821
- clearReviewRefs: true,
822
- }),
823
- })),
288
+ .effect(({ ctx }) => ({ state: resetPoemReview(ctx.state) })),
824
289
  ).definition;
825
290
 
826
- const poemCreatorProcessDefinition = flow
291
+ /** @internal */
292
+ export const poemCreatorProcess = flow
827
293
  .process<PromptProcessParams, PoemCreatorState>("poem_creator_process")
828
294
  .displayName("Poem Creator")
829
295
  .entry(poemTurnIds.draftPoem)
@@ -841,6 +307,7 @@ const poemCreatorProcessDefinition = flow
841
307
  flow
842
308
  .llm<PromptProcessParams, PoemCreatorState>(poemTurnIds.draftPoem)
843
309
  .description("Draft Poem")
310
+ .waitFor(({ params, state }) => !!params.prompt.trim() || !!state.productRefs.message)
844
311
  .fullPrimary()
845
312
  .continueFromPrimaryLeaf()
846
313
  .optionalConsume("message")
@@ -852,14 +319,7 @@ const poemCreatorProcessDefinition = flow
852
319
  })
853
320
  .publish("poem-draft")
854
321
  .to(poemTurnIds.poemReview)
855
- .state(({ ctx }) =>
856
- patchPoemCreatorState(ctx.state, {
857
- latestReviewMarkdown: null,
858
- latestReviewSummary: null,
859
- latestReviewOutcome: null,
860
- clearReviewRefs: true,
861
- }),
862
- ),
322
+ .state(({ ctx }) => resetPoemReview(ctx.state)),
863
323
  )
864
324
  .turn({ id: poemTurnIds.poemReview, definition: poemDraftReviewSpec })
865
325
  .turn(
@@ -891,14 +351,13 @@ const poemCreatorProcessDefinition = flow
891
351
  publish: true,
892
352
  })
893
353
  .to(poemTurnIds.poemReview)
894
- .state(({ ctx, event }) =>
895
- patchPoemCreatorState(ctx.state, {
896
- latestReviewMarkdown: null,
897
- latestReviewSummary:
898
- typeof event.params.summary === "string" ? event.params.summary : null,
899
- latestReviewOutcome: "no_issues",
900
- }),
901
- ),
354
+ .state(({ ctx, event }) => ({
355
+ ...ctx.state,
356
+ latestReviewMarkdown: null,
357
+ latestReviewSummary:
358
+ typeof event.params.summary === "string" ? event.params.summary : null,
359
+ latestReviewOutcome: "no_issues",
360
+ })),
902
361
  )
903
362
  .outcomeTool("leave_feedback", (tool) =>
904
363
  tool
@@ -910,17 +369,16 @@ const poemCreatorProcessDefinition = flow
910
369
  publish: true,
911
370
  })
912
371
  .to(poemTurnIds.poemReviewFeedback)
913
- .state(({ ctx, event }) =>
914
- patchPoemCreatorState(ctx.state, {
915
- latestReviewMarkdown:
916
- typeof event.params.message === "string"
917
- ? event.params.message
918
- : (ctx.output?.content ?? null),
919
- latestReviewSummary:
920
- typeof event.params.summary === "string" ? event.params.summary : null,
921
- latestReviewOutcome: "leave_feedback",
922
- }),
923
- ),
372
+ .state(({ ctx, event }) => ({
373
+ ...ctx.state,
374
+ latestReviewMarkdown:
375
+ typeof event.params.message === "string"
376
+ ? event.params.message
377
+ : (ctx.output?.content ?? null),
378
+ latestReviewSummary:
379
+ typeof event.params.summary === "string" ? event.params.summary : null,
380
+ latestReviewOutcome: "leave_feedback",
381
+ })),
924
382
  ),
925
383
  )
926
384
  .turn({ id: poemTurnIds.poemReviewFeedback, definition: poemReviewFeedbackSpec })
@@ -958,12 +416,14 @@ const poemCreatorProcessDefinition = flow
958
416
  ],
959
417
  submitLabel: "Create Poem",
960
418
  },
961
- ...promptLaunchResolution({
962
- processId: "poem_creator_process",
963
- startTurnId: poemTurnIds.draftPoem,
964
- defaultPrompt: buildDefaultPoemPrompt,
965
- titleLabel: "Poem Prompt",
966
- }),
419
+ resolveDefaults: () => ({ prompt: buildDefaultPoemPrompt() }),
420
+ resolveLaunchConfig(input) {
421
+ const prompt = typeof input.prompt === "string" ? input.prompt.trim() : "";
422
+ return {
423
+ ok: true,
424
+ launchConfig: poemLaunchConfig(prompt || buildDefaultPoemPrompt().trim()),
425
+ };
426
+ },
967
427
  },
968
428
  })
969
429
  .watcher({
@@ -972,18 +432,6 @@ const poemCreatorProcessDefinition = flow
972
432
  description:
973
433
  "Launch Poem Creator whenever the configured filesystem watcher finds a prompt file",
974
434
  source: filesystemWatcherSource,
975
- resolveLaunchConfig(event) {
976
- const prompt = event.content.trim();
977
- return {
978
- processId: "poem_creator_process",
979
- params: { prompt },
980
- titleSourceFields: buildPromptTitleSourceFields(prompt, "Poem Prompt"),
981
- startTurnId: poemTurnIds.draftPoem,
982
- };
983
- },
435
+ resolveLaunchConfig: (event) => poemLaunchConfig(event.content.trim()),
984
436
  })
985
437
  .define();
986
-
987
- /** @internal */
988
- export const poemCreatorProcess: ExtensionProcessDefinition<PromptProcessParams, PoemCreatorState> =
989
- poemCreatorProcessDefinition;