@leitwerk-dev/showcase-processes 0.3.1 → 0.4.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.
package/dist/index.js CHANGED
@@ -1,245 +1,33 @@
1
1
  // src/index.ts
2
- import { coreHostCapabilities } from "@leitwerk-dev/process-sdk";
3
-
4
- // src/file-external.ts
5
- import { emptyPollResult, parseDurationMs } from "@leitwerk-dev/watcher-utils";
6
-
7
- // src/trigger-files.ts
8
- import { readFile, unlink } from "fs/promises";
9
- function errorCode(error) {
10
- if (typeof error !== "object" || error === null || !("code" in error)) {
11
- return null;
12
- }
13
- const code = error.code;
14
- return typeof code === "string" ? code : null;
15
- }
16
- async function readTriggerFile(filePath) {
17
- try {
18
- return { exists: true, content: await readFile(filePath, "utf8") };
19
- } catch (error) {
20
- if (errorCode(error) === "ENOENT") {
21
- return { exists: false };
22
- }
23
- throw error;
24
- }
25
- }
26
- async function consumeTriggerFile(filePath) {
27
- try {
28
- await unlink(filePath);
29
- } catch (error) {
30
- if (errorCode(error) === "ENOENT") {
31
- return;
32
- }
33
- throw error;
34
- }
35
- }
2
+ import {
3
+ coreHostCapabilities,
4
+ createFileExternalSourceProvider
5
+ } from "@leitwerk-dev/process-sdk";
36
6
 
37
7
  // src/file-external.ts
38
- var FILE_EXTERNAL_PRESENCE_KIND = "@leitwerk-dev/showcase-processes.file.presence";
8
+ import { defineFileExternalSource } from "@leitwerk-dev/process-sdk";
39
9
  var FILE_EXTERNAL_INSTRUCTION_KIND = "@leitwerk-dev/showcase-processes.file.instruction";
40
- function normalizeConfig(input) {
41
- return {
42
- path: input.path,
43
- pollInterval: input.pollInterval,
44
- consume: input.consume
45
- };
46
- }
47
- function interpolateTemplate(template, values) {
48
- return template.replace(/\{([a-zA-Z0-9_]+)\}/g, (match, key) => values[key] ?? match);
49
- }
50
- function resolveFileConfig(input, ctx) {
51
- return {
52
- ...input,
53
- path: interpolateTemplate(input.path, { instanceId: ctx.process.id })
54
- };
55
- }
56
- function fileLabel(kind, path) {
57
- return kind === "presence" ? `File present: ${path}` : `File instruction: ${path}`;
58
- }
59
10
  var fileExternal = {
60
- /** @internal */
61
- presence(input) {
62
- const config = normalizeConfig(input);
63
- return {
64
- kind: FILE_EXTERNAL_PRESENCE_KIND,
65
- label: fileLabel("presence", config.path),
66
- description: `Fires when ${config.path} exists`,
67
- config,
68
- inputMode: "none",
69
- resolve(ctx) {
70
- return resolveFileConfig(config, ctx);
71
- }
72
- };
73
- },
74
11
  /** @internal */
75
12
  instruction(input) {
76
- const config = normalizeConfig(input);
77
- return {
13
+ return defineFileExternalSource(input, {
78
14
  kind: FILE_EXTERNAL_INSTRUCTION_KIND,
79
- label: fileLabel("instruction", config.path),
80
- description: `Reads ${config.path} as instruction text`,
81
- config,
82
- inputMode: "instruction",
83
- resolve(ctx) {
84
- return resolveFileConfig(config, ctx);
85
- }
86
- };
87
- }
88
- };
89
- function parseFileConfig(value) {
90
- if (typeof value !== "object" || value === null || Array.isArray(value)) {
91
- return null;
92
- }
93
- const record2 = value;
94
- if (typeof record2.path !== "string" || record2.path.trim() === "") {
95
- return null;
96
- }
97
- return {
98
- path: record2.path,
99
- pollInterval: typeof record2.pollInterval === "string" ? record2.pollInterval : "1s",
100
- consume: record2.consume === "keep" ? "keep" : "delete"
101
- };
102
- }
103
- async function maybeConsume(config) {
104
- if (config.consume === "delete") {
105
- await consumeTriggerFile(config.path);
106
- }
107
- }
108
- function createDueTracker() {
109
- const nextDueAtByKey = /* @__PURE__ */ new Map();
110
- return {
111
- isDue(key, pollInterval, nowMs = Date.now()) {
112
- const nextDueAt = nextDueAtByKey.get(key) ?? 0;
113
- if (nextDueAt > nowMs) {
114
- return false;
115
- }
116
- const intervalMs = parseDurationMs(pollInterval, 1e3);
117
- nextDueAtByKey.set(key, nowMs + intervalMs);
118
- return true;
119
- },
120
- prune(activeKeys) {
121
- for (const key of [...nextDueAtByKey.keys()]) {
122
- if (!activeKeys.has(key)) {
123
- nextDueAtByKey.delete(key);
124
- }
125
- }
126
- }
127
- };
128
- }
129
- function resolveArmedFileConfig(armed, resolveAlias) {
130
- const parsed = parseFileConfig(armed.resolved) ?? parseFileConfig(armed.source.config);
131
- return parsed ? resolveAlias(parsed) : null;
132
- }
133
- async function pollArmedFileSource(armed, resolveConfig, isDue, activeKeys, result) {
134
- const config = resolveArmedFileConfig(armed, resolveConfig);
135
- if (!config) {
136
- result.errors.push(`${armed.id}:invalid_config`);
137
- return null;
138
- }
139
- const key = `${armed.instanceId}:${armed.id}`;
140
- activeKeys.add(key);
141
- if (!isDue(key, config.pollInterval)) {
142
- return null;
143
- }
144
- const file = await readTriggerFile(config.path);
145
- if (!file.exists) {
146
- return null;
147
- }
148
- return { config, file };
149
- }
150
- async function firePresenceSources(deps, result, resolveConfig, isDue, activeKeys) {
151
- for (const armed of deps.externalSources.listArmed(FILE_EXTERNAL_PRESENCE_KIND)) {
152
- const target = await pollArmedFileSource(armed, resolveConfig, isDue, activeKeys, result);
153
- if (!target) {
154
- continue;
155
- }
156
- const { config } = target;
157
- const fired = await deps.externalSources.fire({
158
- instanceId: armed.instanceId,
159
- armingId: armed.id,
160
- event: { path: config.path, pollInterval: config.pollInterval },
161
- mergeKey: config.path
15
+ label: `File instruction: ${input.path}`,
16
+ description: `Reads ${input.path} as instruction text`,
17
+ inputMode: "instruction"
162
18
  });
163
- if (!fired.ok) {
164
- result.errors.push(`${armed.id}:${fired.code ?? fired.error ?? "fire_failed"}`);
165
- continue;
166
- }
167
- await maybeConsume(config);
168
- result.created.push(armed.id);
169
- }
170
- }
171
- async function fireInstructionSources(deps, result, resolveConfig, isDue, activeKeys) {
172
- for (const armed of deps.externalSources.listArmed(FILE_EXTERNAL_INSTRUCTION_KIND)) {
173
- const target = await pollArmedFileSource(armed, resolveConfig, isDue, activeKeys, result);
174
- if (!target) {
175
- continue;
176
- }
177
- const { config, file } = target;
178
- const instruction = file.content.trim();
179
- if (!instruction) {
180
- continue;
181
- }
182
- const fired = await deps.externalSources.fire({
183
- instanceId: armed.instanceId,
184
- armingId: armed.id,
185
- input: { instruction },
186
- event: { path: config.path, pollInterval: config.pollInterval },
187
- mergeKey: config.path
188
- });
189
- if (!fired.ok) {
190
- result.errors.push(`${armed.id}:${fired.code ?? fired.error ?? "fire_failed"}`);
191
- continue;
192
- }
193
- await maybeConsume(config);
194
- result.created.push(armed.id);
195
19
  }
196
- }
197
- function createFileExternalSourceProvider(deps, aliases = {}) {
198
- function applyAlias(config) {
199
- const exact = aliases[config.path];
200
- if (exact) {
201
- return { ...config, path: exact };
202
- }
203
- for (const [template, replacement] of Object.entries(aliases)) {
204
- if (!replacement || !template.includes("{instanceId}")) {
205
- continue;
206
- }
207
- const [prefix, suffix = ""] = template.split("{instanceId}");
208
- if (!prefix || !config.path.startsWith(prefix) || !config.path.endsWith(suffix)) {
209
- continue;
210
- }
211
- const instanceId = config.path.slice(prefix.length, config.path.length - suffix.length);
212
- return {
213
- ...config,
214
- path: replacement.includes("{instanceId}") ? interpolateTemplate(replacement, { instanceId }) : replacement
215
- };
216
- }
217
- return config;
218
- }
219
- const due = createDueTracker();
220
- return deps.polling.create({
221
- id: "showcase-file-external",
222
- pollInterval: () => "50ms",
223
- isEnabled: () => true,
224
- defaultIntervalMs: 50,
225
- async pollOnce() {
226
- const result = emptyPollResult();
227
- const activeKeys = /* @__PURE__ */ new Set();
228
- await firePresenceSources(deps, result, applyAlias, due.isDue, activeKeys);
229
- await fireInstructionSources(deps, result, applyAlias, due.isDue, activeKeys);
230
- due.prune(activeKeys);
231
- return result;
232
- }
233
- });
234
- }
20
+ };
235
21
 
236
22
  // src/filesystem-watcher.ts
237
23
  import { createHash } from "crypto";
238
24
  import {
25
+ consumeTriggerFile,
239
26
  defineProcessWatcherSource,
240
- parseProcessWatcherLaunchModelConfig
27
+ parseProcessWatcherLaunchModelConfig,
28
+ readTriggerFile
241
29
  } from "@leitwerk-dev/process-sdk";
242
- import { emptyPollResult as emptyPollResult2, parseDurationMs as parseDurationMs2 } from "@leitwerk-dev/watcher-utils";
30
+ import { emptyPollResult, parseDurationMs } from "@leitwerk-dev/watcher-utils";
243
31
  function record(value, subject) {
244
32
  if (!value || typeof value !== "object" || Array.isArray(value)) {
245
33
  throw new Error(`${subject} must be an object`);
@@ -264,7 +52,7 @@ var filesystemWatcherSource = defineProcessWatcherSource({
264
52
  throw new Error("enabled must be a boolean");
265
53
  }
266
54
  const pollInterval = nonEmptyString(config.poll_interval, "poll_interval");
267
- if (parseDurationMs2(pollInterval, -1, { allowHours: true }) <= 0) {
55
+ if (parseDurationMs(pollInterval, -1, { allowHours: true }) <= 0) {
268
56
  throw new Error("poll_interval must be a positive duration");
269
57
  }
270
58
  return {
@@ -295,10 +83,10 @@ function createFilesystemWatcherProvider(deps) {
295
83
  isEnabled: () => watcher.enabled,
296
84
  defaultIntervalMs: 1e3,
297
85
  async pollOnce() {
298
- const result = emptyPollResult2();
86
+ const result = emptyPollResult();
299
87
  const file = await readTriggerFile(watcher.config.filePath);
300
- if (!file.exists || file.content.trim() === "") return result;
301
- const content = file.content.trim();
88
+ if (file === null || file.trim() === "") return result;
89
+ const content = file.trim();
302
90
  const sourceEventKey = createHash("sha256").update(`${watcher.config.filePath}\0${content}`).digest("hex");
303
91
  const launched = await deps.launchRuns.startWatcher(
304
92
  watcher,
@@ -327,13 +115,10 @@ function createFilesystemWatcherProvider(deps) {
327
115
  }
328
116
 
329
117
  // src/process-definition.ts
330
- import { execFileSync } from "child_process";
331
- import { setTimeout as delay } from "timers/promises";
332
118
  import {
333
119
  createEmptyStructuralProcessState,
334
120
  flow,
335
- parseStructuralProcessState,
336
- structuralStateCodec
121
+ parseStructuralProcessState
337
122
  } from "@leitwerk-dev/process-sdk";
338
123
 
339
124
  // src/poem-leaf-outcome.ts
@@ -420,10 +205,6 @@ function buildPoemLeafOutcomeFallbackMarkdown(input) {
420
205
  return [normalizedMarkdown, reviewSection].filter((section) => section.trim() !== "").join("\n\n");
421
206
  }
422
207
 
423
- // src/turns/external-complete.ts
424
- var externalPromptCompletionTurnId = "await_external_prompt_completion";
425
- var externalPromptCompletionTurnDescription = "Wait for an external completion trigger after the single prompt finishes";
426
-
427
208
  // src/turns/poem-creator.ts
428
209
  var poemCreatorActionIds = {
429
210
  /** @internal */
@@ -503,78 +284,11 @@ var leaveFeedbackToolRenderer = {
503
284
  ]
504
285
  };
505
286
 
506
- // src/turns/run-single-prompt.ts
507
- import {
508
- llmTurn,
509
- REQUIRED_MARKDOWN_RESULT_TURN_RESULT
510
- } from "@leitwerk-dev/process-sdk";
511
- function buildSinglePromptInstruction(promptText) {
512
- return `Run the following one-shot operator prompt exactly once.
513
-
514
- ${promptText}`;
515
- }
516
- function buildSinglePromptWithToolInstruction(promptText) {
517
- return `Run the following one-shot operator prompt exactly once.
518
-
519
- ${promptText}
520
-
521
- When you are done, call the done tool with a short summary of the result.`;
522
- }
523
- function createRunSinglePromptTurn(promptText) {
524
- return llmTurn({
525
- description: "Run a single operator-provided prompt and finish on turn end",
526
- availableTools: ["read", "bash", "edit", "write"],
527
- completionMode: "turn_end",
528
- branchType: "primary",
529
- context: "fresh",
530
- prompt: () => buildSinglePromptInstruction(promptText),
531
- outcomes: {},
532
- turnEnd: {
533
- outcome: "completed",
534
- params: {},
535
- complete: true
536
- },
537
- turnResultMarkdown: REQUIRED_MARKDOWN_RESULT_TURN_RESULT
538
- });
539
- }
540
- function createRunSinglePromptWithToolTurn(promptText) {
541
- return llmTurn({
542
- description: "Run a single operator-provided prompt and require the done tool",
543
- availableTools: ["read", "bash", "edit", "write"],
544
- completionMode: "turn_end",
545
- branchType: "primary",
546
- context: "fresh",
547
- prompt: () => buildSinglePromptWithToolInstruction(promptText),
548
- outcomes: {
549
- done: {
550
- description: "Mark the prompt run as complete",
551
- parameters: {
552
- summary: {
553
- type: "string",
554
- description: "Short summary of the result",
555
- required: true,
556
- requiredErrorCode: "summary_required"
557
- }
558
- }
559
- }
560
- },
561
- turnResultMarkdown: REQUIRED_MARKDOWN_RESULT_TURN_RESULT
562
- });
563
- }
564
- var runSinglePrompt = createRunSinglePromptTurn(
565
- "Run the operator-provided single prompt."
566
- );
567
- var runSinglePromptWithTool = createRunSinglePromptWithToolTurn(
568
- "Run the operator-provided single prompt."
569
- );
570
-
571
287
  // src/process-definition.ts
572
288
  var promptProcessParamsCodec = {
573
289
  parse(value) {
574
290
  const record2 = typeof value === "object" && value !== null ? value : {};
575
- return {
576
- prompt: typeof record2.prompt === "string" ? record2.prompt : ""
577
- };
291
+ return { prompt: typeof record2.prompt === "string" ? record2.prompt : "" };
578
292
  },
579
293
  serialize(value) {
580
294
  return value;
@@ -584,7 +298,7 @@ var poemCreatorStateCodec = {
584
298
  parse(value) {
585
299
  const structural = parseStructuralProcessState(value);
586
300
  const record2 = typeof value === "object" && value !== null ? value : {};
587
- const latestReviewOutcome = typeof record2.latestReviewOutcome === "string" ? record2.latestReviewOutcome === "issues_found" ? "leave_feedback" : record2.latestReviewOutcome === "no_issues" || record2.latestReviewOutcome === "leave_feedback" ? record2.latestReviewOutcome : null : null;
301
+ const latestReviewOutcome = record2.latestReviewOutcome === "issues_found" ? "leave_feedback" : record2.latestReviewOutcome === "no_issues" || record2.latestReviewOutcome === "leave_feedback" ? record2.latestReviewOutcome : null;
588
302
  return {
589
303
  ...structural,
590
304
  latestReviewMarkdown: typeof record2.latestReviewMarkdown === "string" ? record2.latestReviewMarkdown : null,
@@ -596,61 +310,21 @@ var poemCreatorStateCodec = {
596
310
  return value;
597
311
  }
598
312
  };
599
- function validateLaunchInput(input, fallbackPrompt) {
600
- const inputPrompt = typeof input.prompt === "string" ? input.prompt.trim() : "";
601
- const prompt = inputPrompt || fallbackPrompt?.trim() || "";
602
- if (!prompt) {
603
- return {
604
- ok: false,
605
- errors: [{ code: "required", fieldId: "prompt", message: "prompt is required" }]
606
- };
607
- }
608
- return {
609
- ok: true,
610
- prompt
611
- };
612
- }
613
- function buildPromptTitleSourceFields(prompt, label = "Prompt") {
614
- return [{ label, value: prompt }];
615
- }
616
- function promptLaunchResolution(options) {
313
+ function poemLaunchConfig(prompt) {
617
314
  return {
618
- resolveDefaults: () => ({ prompt: options.defaultPrompt?.() ?? "" }),
619
- resolveLaunchConfig(input) {
620
- const validated = validateLaunchInput(input, options.defaultPrompt?.());
621
- if (!validated.ok) return validated;
622
- return {
623
- ok: true,
624
- launchConfig: {
625
- processId: options.processId,
626
- params: { prompt: validated.prompt },
627
- titleSourceFields: buildPromptTitleSourceFields(validated.prompt, options.titleLabel),
628
- startTurnId: options.startTurnId
629
- }
630
- };
631
- }
315
+ processId: "poem_creator_process",
316
+ params: { prompt },
317
+ titleSourceFields: [{ label: "Poem Prompt", value: prompt }],
318
+ startTurnId: poemTurnIds.draftPoem
632
319
  };
633
320
  }
634
- function clearReviewRefs(state) {
321
+ function resetPoemReview(state) {
635
322
  return {
636
323
  ...state,
637
- review: null
638
- };
639
- }
640
- function patchPoemCreatorState(state, input) {
641
- const nextState = {
642
- ...state,
643
- ..."latestReviewMarkdown" in input ? { latestReviewMarkdown: input.latestReviewMarkdown ?? null } : {},
644
- ..."latestReviewSummary" in input ? { latestReviewSummary: input.latestReviewSummary ?? null } : {},
645
- ..."latestReviewOutcome" in input ? { latestReviewOutcome: input.latestReviewOutcome ?? null } : {},
646
- ..."semanticEntryRefs" in input ? { semanticEntryRefs: input.semanticEntryRefs } : {}
647
- };
648
- if (!input.clearReviewRefs) {
649
- return nextState;
650
- }
651
- return {
652
- ...nextState,
653
- semanticEntryRefs: clearReviewRefs(nextState.semanticEntryRefs)
324
+ latestReviewMarkdown: null,
325
+ latestReviewSummary: null,
326
+ latestReviewOutcome: null,
327
+ semanticEntryRefs: { ...state.semanticEntryRefs, review: null }
654
328
  };
655
329
  }
656
330
  function buildPoemLeafReview(state) {
@@ -663,25 +337,6 @@ function buildPoemLeafReview(state) {
663
337
  feedback: state.latestReviewOutcome === "leave_feedback" ? state.latestReviewMarkdown : null
664
338
  };
665
339
  }
666
- function createMarkdownLeafOutcome(rendererId) {
667
- return {
668
- rendererId,
669
- capture(ctx) {
670
- const markdown = ctx.turnRecord?.turnResultMarkdown?.trim() ?? "";
671
- return {
672
- rendererId,
673
- schemaVersion: 1,
674
- props: {
675
- prompt: ctx.params.prompt,
676
- markdown: markdown.length > 0 ? markdown : null,
677
- leafEntryId: ctx.leaf.entryId,
678
- turnRecordId: ctx.leaf.turnRecordId
679
- },
680
- fallbackMarkdown: markdown.length > 0 ? markdown : null
681
- };
682
- }
683
- };
684
- }
685
340
  function createPoemLeafOutcome(rendererId) {
686
341
  return {
687
342
  rendererId,
@@ -759,276 +414,6 @@ var poemReviewChangesForm = {
759
414
  ],
760
415
  submitLabel: "Request review changes"
761
416
  };
762
- var singlePromptProcess = flow.process("single_prompt_process").displayName("Single Prompt").entry("run_single_prompt").codecs({
763
- params: promptProcessParamsCodec,
764
- state: structuralStateCodec
765
- }).initialState(() => createEmptyStructuralProcessState()).turn(
766
- flow.llm("run_single_prompt").description("Run Prompt").tools("read", "bash", "edit", "write").prompt(async (ctx) => buildSinglePromptInstruction(ctx.params.prompt)).end("completed").complete()
767
- ).ui((api) => {
768
- api.leafOutcome(
769
- createMarkdownLeafOutcome(
770
- "@leitwerk-dev/showcase-processes:single_prompt_process.leaf_outcome"
771
- )
772
- );
773
- }).launcher({
774
- id: "single_prompt_process.single_prompt_ui",
775
- label: "Single Prompt",
776
- description: "Run one prompt and finish on turn end",
777
- visibility: "ui",
778
- ui: {
779
- card: {
780
- title: "Single Prompt",
781
- description: "Run a one-shot prompt. The shared launcher shell chooses the model configuration."
782
- },
783
- launchConfigSchema: {
784
- id: "single_prompt_form",
785
- title: "Single Prompt",
786
- fields: [
787
- {
788
- id: "prompt",
789
- label: "Prompt",
790
- kind: "textarea",
791
- required: true,
792
- placeholder: "Say hello.",
793
- description: "The exact prompt sent to Pi for this one-shot run. This version finishes when the assistant turn ends normally."
794
- }
795
- ],
796
- submitLabel: "Run Prompt"
797
- },
798
- ...promptLaunchResolution({
799
- processId: "single_prompt_process",
800
- startTurnId: "run_single_prompt"
801
- })
802
- }
803
- }).define();
804
- var singlePromptWithToolProcess = flow.process("single_prompt_with_tool_process").displayName("Single Prompt + Done Tool").entry("run_single_prompt_with_tool").codecs({
805
- params: promptProcessParamsCodec,
806
- state: structuralStateCodec
807
- }).initialState(() => createEmptyStructuralProcessState()).turn(
808
- flow.llm("run_single_prompt_with_tool").description("Run Prompt").tools("read", "bash", "edit", "write").prompt(async (ctx) => buildSinglePromptWithToolInstruction(ctx.params.prompt)).outcomeTool(
809
- "done",
810
- (tool) => tool.description("Mark the prompt run as complete").requiredString("summary", "Short summary of the result").complete()
811
- )
812
- ).ui((api) => {
813
- api.leafOutcome(
814
- createMarkdownLeafOutcome(
815
- "@leitwerk-dev/showcase-processes:single_prompt_with_tool_process.leaf_outcome"
816
- )
817
- );
818
- }).launcher({
819
- id: "single_prompt_with_tool_process.single_prompt_with_tool_ui",
820
- label: "Single Prompt + Done Tool",
821
- description: "Run one prompt and require an explicit done tool",
822
- visibility: "ui",
823
- ui: {
824
- card: {
825
- title: "Single Prompt + Done Tool",
826
- description: "Run a one-shot prompt and force an explicit done tool call. The shared launcher shell chooses the model configuration."
827
- },
828
- launchConfigSchema: {
829
- id: "single_prompt_with_tool_form",
830
- title: "Single Prompt + Done Tool",
831
- fields: [
832
- {
833
- id: "prompt",
834
- label: "Prompt",
835
- kind: "textarea",
836
- required: true,
837
- placeholder: "Say hello, then call the done tool with a short summary.",
838
- description: "The exact prompt sent to Pi for this one-shot run. This version requires the explicit done outcome tool."
839
- }
840
- ],
841
- submitLabel: "Run Prompt + Tool"
842
- },
843
- ...promptLaunchResolution({
844
- processId: "single_prompt_with_tool_process",
845
- startTurnId: "run_single_prompt_with_tool"
846
- })
847
- }
848
- }).define();
849
- function defineK8sSmokeProcess(args) {
850
- const promptField = args.promptField;
851
- const resolveLaunchConfig = promptField ? (input) => {
852
- const validated = validateLaunchInput(input, args.defaultPrompt);
853
- if (!validated.ok) return validated;
854
- return {
855
- ok: true,
856
- launchConfig: {
857
- processId: args.processId,
858
- params: { prompt: validated.prompt },
859
- titleSourceFields: buildPromptTitleSourceFields(validated.prompt, args.titleLabel),
860
- startTurnId: args.runTurnId
861
- }
862
- };
863
- } : () => ({
864
- ok: true,
865
- launchConfig: {
866
- processId: args.processId,
867
- params: { prompt: args.defaultPrompt },
868
- titleSourceFields: buildPromptTitleSourceFields(args.defaultPrompt, args.titleLabel),
869
- startTurnId: args.runTurnId
870
- }
871
- });
872
- const runTurn = flow.automatic(args.runTurnId).description(args.runTurnDescription).run(async (ctx) => {
873
- const result = await args.run(ctx);
874
- return { outcome: "ready", ...result };
875
- }).outcome("ready", (outcome) => {
876
- outcome.description(args.outcomeDescription);
877
- args.describeOutcome?.(outcome);
878
- return outcome.to(args.waitTurnId);
879
- });
880
- const waitTurn = flow.human(args.waitTurnId).description(args.waitDescription);
881
- if (args.waitCommentary) {
882
- waitTurn.commentary(args.waitCommentary);
883
- }
884
- if (args.runAgain) {
885
- const runAgain = args.runAgain;
886
- waitTurn.action(
887
- "run_again",
888
- (action) => action.label(runAgain.label).description(runAgain.description).acceptanceState("neutral").to(args.runTurnId)
889
- );
890
- }
891
- waitTurn.action(
892
- "complete",
893
- (action) => action.label(args.completeLabel).acceptanceState("accepted").complete()
894
- );
895
- return flow.process(args.processId).displayName(args.displayName).entry(args.runTurnId).codecs({ params: promptProcessParamsCodec, state: structuralStateCodec }).initialState(() => createEmptyStructuralProcessState()).turn(runTurn).turn(waitTurn).launcher({
896
- id: args.launcherId,
897
- label: args.displayName,
898
- description: args.launcherDescription,
899
- visibility: "ui",
900
- ui: {
901
- card: { title: args.displayName, description: args.cardDescription },
902
- launchConfigSchema: {
903
- id: args.formId,
904
- title: args.displayName,
905
- fields: promptField ? [{ id: "prompt", label: promptField.label, kind: "text", required: true }] : [],
906
- submitLabel: args.submitLabel
907
- },
908
- ...promptField ? { resolveDefaults: () => ({ prompt: args.defaultPrompt }) } : {},
909
- resolveLaunchConfig
910
- }
911
- }).define();
912
- }
913
- var k8sSmokeProcess = defineK8sSmokeProcess({
914
- processId: "k8s_smoke_process",
915
- displayName: "Kubernetes Smoke",
916
- runTurnId: "k8s_smoke_run",
917
- waitTurnId: "k8s_smoke_wait",
918
- runTurnDescription: "Run a deterministic worker-side Kubernetes smoke step",
919
- outcomeDescription: "The worker-side smoke step completed",
920
- describeOutcome: (outcome) => outcome.string("prompt", "The smoke prompt"),
921
- waitDescription: "Wait after the Kubernetes smoke worker step",
922
- waitCommentary: "The smoke worker is idle; actions can respawn it on the retained PVC.",
923
- runAgain: { label: "Run smoke again", description: "Select the worker-side smoke turn again." },
924
- completeLabel: "Complete smoke",
925
- launcherId: "k8s_smoke_process.k8s_smoke_ui",
926
- launcherDescription: "Run a deterministic worker-backed Kubernetes smoke process",
927
- cardDescription: "Creates a worker pod/PVC and then waits for a follow-up action.",
928
- formId: "k8s_smoke_form",
929
- submitLabel: "Run smoke",
930
- promptField: { label: "Smoke prompt" },
931
- defaultPrompt: "kind smoke",
932
- titleLabel: "Smoke",
933
- run: (ctx) => ({
934
- params: { prompt: ctx.params.prompt },
935
- markdown: `Kubernetes smoke worker ran: ${ctx.params.prompt}`
936
- })
937
- });
938
- var k8sSmokeSpecializedProcess = defineK8sSmokeProcess({
939
- processId: "k8s_smoke_specialized_process",
940
- displayName: "Kubernetes Specialized Smoke",
941
- runTurnId: "k8s_smoke_specialized_run",
942
- waitTurnId: "k8s_smoke_specialized_wait",
943
- runTurnDescription: "Verify the specialized Kubernetes worker image tool path",
944
- outcomeDescription: "The specialized image tool ran",
945
- describeOutcome: (outcome) => outcome.requiredString("output", "Tool output"),
946
- waitDescription: "Wait after specialized image verification",
947
- waitCommentary: "The specialized Kubernetes image was selected and executed its smoke tool.",
948
- completeLabel: "Complete specialized smoke",
949
- launcherId: "k8s_smoke_specialized_process.k8s_smoke_specialized_ui",
950
- launcherDescription: "Run a deterministic worker-backed process on the specialized smoke image",
951
- cardDescription: "Validates runtime-profile image selection with a deterministic tool.",
952
- formId: "k8s_smoke_specialized_form",
953
- submitLabel: "Run specialized smoke",
954
- defaultPrompt: "specialized",
955
- titleLabel: "Smoke",
956
- run: () => {
957
- const output = execFileSync("leitwerk-specialized-tool", { encoding: "utf8" }).trim();
958
- return { params: { output }, markdown: output };
959
- }
960
- });
961
- var k8sSmokeLongProcess = defineK8sSmokeProcess({
962
- processId: "k8s_smoke_long_process",
963
- displayName: "Kubernetes Long Smoke",
964
- runTurnId: "k8s_smoke_long_run",
965
- waitTurnId: "k8s_smoke_long_wait",
966
- runTurnDescription: "Stay busy long enough for server restart adoption tests",
967
- outcomeDescription: "The long smoke step completed",
968
- waitDescription: "Wait after long smoke",
969
- completeLabel: "Complete long smoke",
970
- launcherId: "k8s_smoke_long_process.k8s_smoke_long_ui",
971
- launcherDescription: "Run a long worker-backed process for server restart adoption tests",
972
- cardDescription: "Keeps a worker pod busy while the server restarts.",
973
- formId: "k8s_smoke_long_form",
974
- submitLabel: "Run long smoke",
975
- defaultPrompt: "long",
976
- titleLabel: "Smoke",
977
- run: async () => {
978
- await delay(9e4);
979
- return { params: {}, markdown: "long smoke completed" };
980
- }
981
- });
982
- var singlePromptExternalCompleteProcess = flow.process("single_prompt_external_complete_process").displayName("Single Prompt + External Complete").entry("run_single_prompt").codecs({
983
- params: promptProcessParamsCodec,
984
- state: structuralStateCodec
985
- }).initialState(() => createEmptyStructuralProcessState()).turn(
986
- flow.llm("run_single_prompt").description("Run Prompt").tools("read", "bash", "edit", "write").prompt(async (ctx) => buildSinglePromptInstruction(ctx.params.prompt)).end("completed").to(externalPromptCompletionTurnId)
987
- ).turn(
988
- flow.external(externalPromptCompletionTurnId).description(externalPromptCompletionTurnDescription).from(
989
- fileExternal.presence({
990
- path: "/tmp/complete-prompt",
991
- pollInterval: "1s",
992
- consume: "delete"
993
- })
994
- ).complete()
995
- ).ui((api) => {
996
- api.leafOutcome(
997
- createMarkdownLeafOutcome(
998
- "@leitwerk-dev/showcase-processes:single_prompt_external_complete_process.leaf_outcome"
999
- )
1000
- );
1001
- }).launcher({
1002
- id: "single_prompt_external_complete_process.single_prompt_external_complete_ui",
1003
- label: "Single Prompt + External Complete",
1004
- description: "Run one prompt, then wait for the external complete trigger file",
1005
- visibility: "ui",
1006
- ui: {
1007
- card: {
1008
- title: "Single Prompt + External Complete",
1009
- description: "Run a one-shot prompt, preserve its result in the chronicle, and finish only when the external completion trigger fires."
1010
- },
1011
- launchConfigSchema: {
1012
- id: "single_prompt_external_complete_form",
1013
- title: "Single Prompt + External Complete",
1014
- fields: [
1015
- {
1016
- id: "prompt",
1017
- label: "Prompt",
1018
- kind: "textarea",
1019
- required: true,
1020
- placeholder: "Say hello, then wait for the external completion file.",
1021
- description: "The prompt runs once. After it finishes, the process waits for the configured prompt-complete trigger file (default: /tmp/complete-prompt)."
1022
- }
1023
- ],
1024
- submitLabel: "Run Prompt"
1025
- },
1026
- ...promptLaunchResolution({
1027
- processId: "single_prompt_external_complete_process",
1028
- startTurnId: "run_single_prompt"
1029
- })
1030
- }
1031
- }).define();
1032
417
  var poemDraftReviewSpec = flow.human(poemTurnIds.poemReview).description("Review").reviewProduct("poem-draft").notesFields([
1033
418
  {
1034
419
  id: "message",
@@ -1045,14 +430,7 @@ var poemDraftReviewSpec = flow.human(poemTurnIds.poemReview).description("Review
1045
430
  (action) => action.label("Request revision").description("Send the poem back for another primary-branch draft.").acceptanceState("requires_changes").form(poemRevisionForm).trigger("revision_requested").schedulable().to(poemTurnIds.draftPoem)
1046
431
  ).action(
1047
432
  poemCreatorActionIds.runAutoReview,
1048
- (action) => action.label("Run automated review").description("Send the current poem draft to the LLM reviewer.").acceptanceState("neutral").trigger("operator_re_review").schedulable().to(poemTurnIds.reviewPoemDraft).effect(({ ctx }) => ({
1049
- state: patchPoemCreatorState(ctx.state, {
1050
- latestReviewMarkdown: null,
1051
- latestReviewSummary: null,
1052
- latestReviewOutcome: null,
1053
- clearReviewRefs: true
1054
- })
1055
- }))
433
+ (action) => action.label("Run automated review").description("Send the current poem draft to the LLM reviewer.").acceptanceState("neutral").trigger("operator_re_review").schedulable().to(poemTurnIds.reviewPoemDraft).effect(({ ctx }) => ({ state: resetPoemReview(ctx.state) }))
1056
434
  ).externalAction(
1057
435
  "poem_review_file",
1058
436
  fileExternal.instruction({
@@ -1080,16 +458,9 @@ var poemReviewFeedbackSpec = flow.human(poemTurnIds.poemReviewFeedback).descript
1080
458
  (action) => action.label("Request review changes").description("Ask the LLM reviewer to revise its review on the review branch.").acceptanceState("requires_changes").form(poemReviewChangesForm).trigger("operator_re_review").schedulable().to(poemTurnIds.reviewPoemDraft)
1081
459
  ).action(
1082
460
  poemCreatorActionIds.dismissReview,
1083
- (action) => action.label("Dismiss review").description("Return to the poem decision without applying the review feedback.").acceptanceState("neutral").to(poemTurnIds.poemReview).effect(({ ctx }) => ({
1084
- state: patchPoemCreatorState(ctx.state, {
1085
- latestReviewMarkdown: null,
1086
- latestReviewSummary: null,
1087
- latestReviewOutcome: null,
1088
- clearReviewRefs: true
1089
- })
1090
- }))
461
+ (action) => action.label("Dismiss review").description("Return to the poem decision without applying the review feedback.").acceptanceState("neutral").to(poemTurnIds.poemReview).effect(({ ctx }) => ({ state: resetPoemReview(ctx.state) }))
1091
462
  ).definition;
1092
- var poemCreatorProcessDefinition = flow.process("poem_creator_process").displayName("Poem Creator").entry(poemTurnIds.draftPoem).codecs({
463
+ var poemCreatorProcess = flow.process("poem_creator_process").displayName("Poem Creator").entry(poemTurnIds.draftPoem).codecs({
1093
464
  params: promptProcessParamsCodec,
1094
465
  state: poemCreatorStateCodec
1095
466
  }).initialState(() => ({
@@ -1098,17 +469,10 @@ var poemCreatorProcessDefinition = flow.process("poem_creator_process").displayN
1098
469
  latestReviewSummary: null,
1099
470
  latestReviewOutcome: null
1100
471
  })).turn(
1101
- flow.llm(poemTurnIds.draftPoem).description("Draft Poem").fullPrimary().continueFromPrimaryLeaf().optionalConsume("message").buildPrompt(async (ctx) => {
472
+ flow.llm(poemTurnIds.draftPoem).description("Draft Poem").waitFor(({ params, state }) => !!params.prompt.trim() || !!state.productRefs.message).fullPrimary().continueFromPrimaryLeaf().optionalConsume("message").buildPrompt(async (ctx) => {
1102
473
  const message = ctx.input.message?.trim();
1103
474
  return message ? buildRevisePoemInstruction(message) : buildDraftPoemInstruction(ctx.params.prompt);
1104
- }).publish("poem-draft").to(poemTurnIds.poemReview).state(
1105
- ({ ctx }) => patchPoemCreatorState(ctx.state, {
1106
- latestReviewMarkdown: null,
1107
- latestReviewSummary: null,
1108
- latestReviewOutcome: null,
1109
- clearReviewRefs: true
1110
- })
1111
- )
475
+ }).publish("poem-draft").to(poemTurnIds.poemReview).state(({ ctx }) => resetPoemReview(ctx.state))
1112
476
  ).turn({ id: poemTurnIds.poemReview, definition: poemDraftReviewSpec }).turn(
1113
477
  flow.llm(poemTurnIds.reviewPoemDraft).description("Assess Poem").rootBranchReview().continueFromReviewBranch().consume("poem-draft").optionalConsume("message").buildPrompt(async (ctx) => {
1114
478
  const message = ctx.input.message?.trim();
@@ -1126,25 +490,23 @@ ${message}` : reviewInstruction;
1126
490
  (tool) => tool.description("The poem is ready to publish").resultSummary("summary").requiredString("summary", "Short confirmation summary").markdown("review", {
1127
491
  description: "Concise review opinion confirming the poem is ready",
1128
492
  publish: true
1129
- }).to(poemTurnIds.poemReview).state(
1130
- ({ ctx, event }) => patchPoemCreatorState(ctx.state, {
1131
- latestReviewMarkdown: null,
1132
- latestReviewSummary: typeof event.params.summary === "string" ? event.params.summary : null,
1133
- latestReviewOutcome: "no_issues"
1134
- })
1135
- )
493
+ }).to(poemTurnIds.poemReview).state(({ ctx, event }) => ({
494
+ ...ctx.state,
495
+ latestReviewMarkdown: null,
496
+ latestReviewSummary: typeof event.params.summary === "string" ? event.params.summary : null,
497
+ latestReviewOutcome: "no_issues"
498
+ }))
1136
499
  ).outcomeTool(
1137
500
  "leave_feedback",
1138
501
  (tool) => tool.description("Leave concise feedback for the human reviewer").resultSummary("summary").requiredString("summary", "Short summary of the feedback").markdown("message", {
1139
502
  description: "Concise plain-text feedback describing what to improve",
1140
503
  publish: true
1141
- }).to(poemTurnIds.poemReviewFeedback).state(
1142
- ({ ctx, event }) => patchPoemCreatorState(ctx.state, {
1143
- latestReviewMarkdown: typeof event.params.message === "string" ? event.params.message : ctx.output?.content ?? null,
1144
- latestReviewSummary: typeof event.params.summary === "string" ? event.params.summary : null,
1145
- latestReviewOutcome: "leave_feedback"
1146
- })
1147
- )
504
+ }).to(poemTurnIds.poemReviewFeedback).state(({ ctx, event }) => ({
505
+ ...ctx.state,
506
+ latestReviewMarkdown: typeof event.params.message === "string" ? event.params.message : ctx.output?.content ?? null,
507
+ latestReviewSummary: typeof event.params.summary === "string" ? event.params.summary : null,
508
+ latestReviewOutcome: "leave_feedback"
509
+ }))
1148
510
  )
1149
511
  ).turn({ id: poemTurnIds.poemReviewFeedback, definition: poemReviewFeedbackSpec }).ui((api) => {
1150
512
  api.leafOutcome(
@@ -1175,29 +537,22 @@ ${message}` : reviewInstruction;
1175
537
  ],
1176
538
  submitLabel: "Create Poem"
1177
539
  },
1178
- ...promptLaunchResolution({
1179
- processId: "poem_creator_process",
1180
- startTurnId: poemTurnIds.draftPoem,
1181
- defaultPrompt: buildDefaultPoemPrompt,
1182
- titleLabel: "Poem Prompt"
1183
- })
540
+ resolveDefaults: () => ({ prompt: buildDefaultPoemPrompt() }),
541
+ resolveLaunchConfig(input) {
542
+ const prompt = typeof input.prompt === "string" ? input.prompt.trim() : "";
543
+ return {
544
+ ok: true,
545
+ launchConfig: poemLaunchConfig(prompt || buildDefaultPoemPrompt().trim())
546
+ };
547
+ }
1184
548
  }
1185
549
  }).watcher({
1186
550
  id: "create_poem",
1187
551
  label: "Create Poem from File",
1188
552
  description: "Launch Poem Creator whenever the configured filesystem watcher finds a prompt file",
1189
553
  source: filesystemWatcherSource,
1190
- resolveLaunchConfig(event) {
1191
- const prompt = event.content.trim();
1192
- return {
1193
- processId: "poem_creator_process",
1194
- params: { prompt },
1195
- titleSourceFields: buildPromptTitleSourceFields(prompt, "Poem Prompt"),
1196
- startTurnId: poemTurnIds.draftPoem
1197
- };
1198
- }
554
+ resolveLaunchConfig: (event) => poemLaunchConfig(event.content.trim())
1199
555
  }).define();
1200
- var poemCreatorProcess = poemCreatorProcessDefinition;
1201
556
 
1202
557
  // src/index.ts
1203
558
  var manifest = {
@@ -1206,21 +561,10 @@ var manifest = {
1206
561
  /** @internal */
1207
562
  version: "0.1.0"
1208
563
  };
1209
- var fileTriggerDefaults = {
1210
- poll_interval: "1s",
1211
- poem_review_path: "/tmp/poem-review-{instanceId}",
1212
- complete_prompt_path: "/tmp/complete-prompt"
1213
- };
1214
- var singlePromptExtension = {
564
+ var showcaseProcessesExtension = {
1215
565
  manifest,
1216
566
  setupCatalog(api) {
1217
567
  api.registerToolRenderer(leaveFeedbackToolRenderer);
1218
- api.registerProcess(singlePromptProcess);
1219
- api.registerProcess(singlePromptWithToolProcess);
1220
- api.registerProcess(singlePromptExternalCompleteProcess);
1221
- api.registerProcess(k8sSmokeProcess);
1222
- api.registerProcess(k8sSmokeSpecializedProcess);
1223
- api.registerProcess(k8sSmokeLongProcess);
1224
568
  api.registerProcess(poemCreatorProcess);
1225
569
  },
1226
570
  setupServer(api, rawConfig) {
@@ -1229,18 +573,16 @@ var singlePromptExtension = {
1229
573
  return;
1230
574
  }
1231
575
  const config = rawConfig ?? {};
1232
- const resolvedFileTriggerConfig = {
1233
- ...fileTriggerDefaults,
1234
- ...config.file_triggers
1235
- };
1236
576
  createFileExternalSourceProvider(deps, {
1237
- "/tmp/complete-prompt": resolvedFileTriggerConfig.complete_prompt_path,
1238
- "/tmp/poem-review-{instanceId}": resolvedFileTriggerConfig.poem_review_path
577
+ id: "showcase-file-external",
578
+ kind: FILE_EXTERNAL_INSTRUCTION_KIND,
579
+ inputMode: "instruction",
580
+ aliases: { "/tmp/poem-review-{instanceId}": config.file_triggers?.poem_review_path }
1239
581
  });
1240
582
  createFilesystemWatcherProvider(deps);
1241
583
  }
1242
584
  };
1243
- var index_default = singlePromptExtension;
585
+ var index_default = showcaseProcessesExtension;
1244
586
  export {
1245
587
  buildPoemLeafOutcomeFallbackMarkdown,
1246
588
  buildPoemLeafOutcomePayload,