@leitwerk-dev/showcase-processes 0.1.9 → 0.2.1

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