@leitwerk-dev/showcase-processes 0.1.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.
Files changed (59) hide show
  1. package/README.md +66 -0
  2. package/dist/LICENSE +13 -0
  3. package/dist/file-action-triggers.d.ts +9 -0
  4. package/dist/file-action-triggers.d.ts.map +1 -0
  5. package/dist/file-action-triggers.js +87 -0
  6. package/dist/file-action-triggers.js.map +1 -0
  7. package/dist/file-external.d.ts +16 -0
  8. package/dist/file-external.d.ts.map +1 -0
  9. package/dist/file-external.js +198 -0
  10. package/dist/file-external.js.map +1 -0
  11. package/dist/index.d.ts +21 -0
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/index.js +55 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/poem-leaf-outcome.d.ts +41 -0
  16. package/dist/poem-leaf-outcome.d.ts.map +1 -0
  17. package/dist/poem-leaf-outcome.js +110 -0
  18. package/dist/poem-leaf-outcome.js.map +1 -0
  19. package/dist/process-definition.d.ts +18 -0
  20. package/dist/process-definition.d.ts.map +1 -0
  21. package/dist/process-definition.js +832 -0
  22. package/dist/process-definition.js.map +1 -0
  23. package/dist/turns/external-complete.d.ts +6 -0
  24. package/dist/turns/external-complete.d.ts.map +1 -0
  25. package/dist/turns/external-complete.js +6 -0
  26. package/dist/turns/external-complete.js.map +1 -0
  27. package/dist/turns/poem-creator.d.ts +15 -0
  28. package/dist/turns/poem-creator.d.ts.map +1 -0
  29. package/dist/turns/poem-creator.js +72 -0
  30. package/dist/turns/poem-creator.js.map +1 -0
  31. package/dist/turns/run-single-prompt.d.ts +8 -0
  32. package/dist/turns/run-single-prompt.d.ts.map +1 -0
  33. package/dist/turns/run-single-prompt.js +57 -0
  34. package/dist/turns/run-single-prompt.js.map +1 -0
  35. package/dist/ui/assets/leaf-outcome-element.js +233 -0
  36. package/dist/ui/assets/leaf-outcome-element.js.map +1 -0
  37. package/dist/ui/assets/poem-leaf-outcome-element.js +328 -0
  38. package/dist/ui/assets/poem-leaf-outcome-element.js.map +1 -0
  39. package/dist/ui/leaf-outcome-element.d.ts +2 -0
  40. package/dist/ui/leaf-outcome-element.d.ts.map +1 -0
  41. package/dist/ui/leaf-outcome-element.js +79 -0
  42. package/dist/ui/leaf-outcome-element.js.map +1 -0
  43. package/dist/ui/manifest.json +24 -0
  44. package/dist/ui/poem-leaf-outcome-element.d.ts +2 -0
  45. package/dist/ui/poem-leaf-outcome-element.d.ts.map +1 -0
  46. package/dist/ui/poem-leaf-outcome-element.js +171 -0
  47. package/dist/ui/poem-leaf-outcome-element.js.map +1 -0
  48. package/package.json +54 -0
  49. package/src/file-action-triggers.ts +120 -0
  50. package/src/file-external.ts +258 -0
  51. package/src/index.ts +76 -0
  52. package/src/poem-leaf-outcome.ts +176 -0
  53. package/src/process-definition.ts +1029 -0
  54. package/src/turns/external-complete.ts +7 -0
  55. package/src/turns/poem-creator.ts +79 -0
  56. package/src/turns/run-single-prompt.ts +70 -0
  57. package/src/ui/leaf-outcome-element.ts +95 -0
  58. package/src/ui/manifest.json +24 -0
  59. package/src/ui/poem-leaf-outcome-element.ts +204 -0
@@ -0,0 +1,7 @@
1
+ export const externalCompleteActionId = "complete_external_prompt";
2
+ export const externalPromptCompletionTurnId = "await_external_prompt_completion";
3
+ export const externalPromptCompletionTurnDescription =
4
+ "Wait for an external completion trigger after the single prompt finishes";
5
+ export const externalPromptCompletionTriggerLabel = "Configured prompt-complete file";
6
+ export const externalPromptCompletionTriggerDescription =
7
+ "Write any content to the configured prompt-complete trigger file (default: /tmp/complete-prompt) to complete the process. The file is removed after a successful completion.";
@@ -0,0 +1,79 @@
1
+ import type { ToolCallRendererDefinition } from "@leitwerk-dev/process-sdk";
2
+
3
+ export const poemCreatorActionIds = {
4
+ completePoem: "complete_poem",
5
+ requestRevision: "request_poem_revision",
6
+ runAutoReview: "run_poem_auto_review",
7
+ acceptReview: "accept_poem_review",
8
+ requestReviewChanges: "request_poem_review_changes",
9
+ dismissReview: "dismiss_poem_review",
10
+ } as const;
11
+
12
+ function formatGermanyDay(now: Date): string {
13
+ return new Intl.DateTimeFormat("en-GB", {
14
+ timeZone: "Europe/Berlin",
15
+ weekday: "long",
16
+ day: "numeric",
17
+ month: "long",
18
+ year: "numeric",
19
+ }).format(now);
20
+ }
21
+
22
+ export function buildDefaultPoemPrompt(now = new Date()): string {
23
+ const germanyDay = formatGermanyDay(now);
24
+ return `Write a short poem in Markdown that is either inspired by ${germanyDay} in Germany or by the craft of building cloud software. Keep it vivid, warm, and concise.`;
25
+ }
26
+
27
+ export function buildDraftPoemInstruction(promptText: string): string {
28
+ return `Write a short poem in Markdown that clearly responds to the operator's prompt.
29
+
30
+ Prompt:
31
+ ${promptText}
32
+
33
+ Requirements:
34
+ - include a title as a Markdown heading
35
+ - keep the poem concise
36
+ - make the imagery clearly connected to the prompt
37
+ - render each poetic line with an explicit HTML <br> so line breaks survive rendering
38
+ - do not rely on single Markdown newlines alone for poem line formatting
39
+ - only the primary branch should write or revise the poem directly`;
40
+ }
41
+
42
+ export function buildRevisePoemInstruction(revisionGuidance: string): string {
43
+ return `Continue from the current poem on this branch and revise it according to this request:
44
+
45
+ ${revisionGuidance}
46
+
47
+ Preserve the parts of the current poem that the request does not ask you to change. Return the complete revised poem in the same Markdown format.`;
48
+ }
49
+
50
+ export function buildReviewPoemInstruction(promptText: string, poemDraftMarkdown: string): string {
51
+ return `Review the latest poem draft against the operator's prompt.
52
+
53
+ Prompt:
54
+ ${promptText}
55
+
56
+ Poem draft to review:
57
+ ${poemDraftMarkdown}
58
+
59
+ You are reviewing the poem only. Do not draft, rewrite, or directly edit the poem. Only produce review feedback.
60
+
61
+ Explicit <br> line breaks in the poem body are expected for rendering and count as correct formatting.
62
+
63
+ If the poem is strong, relevant, and well-formed Markdown, call no_issues with a brief confirmation summary.
64
+ If the poem misses the prompt, needs revision, or is awkwardly structured, call leave_feedback with a brief summary and concise plain-text feedback.`;
65
+ }
66
+
67
+ export const leaveFeedbackToolRenderer: ToolCallRendererDefinition = {
68
+ toolName: "leave_feedback",
69
+ title: "Feedback",
70
+ fields: [
71
+ {
72
+ id: "message",
73
+ label: "Feedback",
74
+ kind: "plaintext",
75
+ source: "arguments",
76
+ path: "message",
77
+ },
78
+ ],
79
+ };
@@ -0,0 +1,70 @@
1
+ import {
2
+ type LlmTurnDefinition,
3
+ llmTurn,
4
+ REQUIRED_MARKDOWN_RESULT_TURN_RESULT,
5
+ } from "@leitwerk-dev/process-sdk";
6
+
7
+ export function buildSinglePromptInstruction(promptText: string): string {
8
+ return `Run the following one-shot operator prompt exactly once.
9
+
10
+ ${promptText}`;
11
+ }
12
+
13
+ export function buildSinglePromptWithToolInstruction(promptText: string): string {
14
+ return `Run the following one-shot operator prompt exactly once.
15
+
16
+ ${promptText}
17
+
18
+ When you are done, call the done tool with a short summary of the result.`;
19
+ }
20
+
21
+ export function createRunSinglePromptTurn(promptText: string): LlmTurnDefinition<"completed"> {
22
+ return llmTurn({
23
+ description: "Run a single operator-provided prompt and finish on turn end",
24
+ availableTools: ["read", "bash", "edit", "write"],
25
+ completionMode: "turn_end",
26
+ branchType: "primary",
27
+ context: "fresh",
28
+ prompt: () => buildSinglePromptInstruction(promptText),
29
+ outcomes: {},
30
+ turnEnd: {
31
+ outcome: "completed",
32
+ params: {},
33
+ complete: true,
34
+ },
35
+ turnResultMarkdown: REQUIRED_MARKDOWN_RESULT_TURN_RESULT,
36
+ });
37
+ }
38
+
39
+ export function createRunSinglePromptWithToolTurn(promptText: string): LlmTurnDefinition<"done"> {
40
+ return llmTurn({
41
+ description: "Run a single operator-provided prompt and require the done tool",
42
+ availableTools: ["read", "bash", "edit", "write"],
43
+ completionMode: "turn_end",
44
+ branchType: "primary",
45
+ context: "fresh",
46
+ prompt: () => buildSinglePromptWithToolInstruction(promptText),
47
+ outcomes: {
48
+ done: {
49
+ description: "Mark the prompt run as complete",
50
+ parameters: {
51
+ summary: {
52
+ type: "string",
53
+ description: "Short summary of the result",
54
+ required: true,
55
+ requiredErrorCode: "summary_required",
56
+ },
57
+ },
58
+ },
59
+ },
60
+ turnResultMarkdown: REQUIRED_MARKDOWN_RESULT_TURN_RESULT,
61
+ });
62
+ }
63
+
64
+ export const runSinglePrompt = createRunSinglePromptTurn(
65
+ "Run the operator-provided single prompt.",
66
+ );
67
+
68
+ export const runSinglePromptWithTool = createRunSinglePromptWithToolTurn(
69
+ "Run the operator-provided single prompt.",
70
+ );
@@ -0,0 +1,95 @@
1
+ import {
2
+ escapeLeafOutcomeHtml,
3
+ LeafOutcomeCustomElement,
4
+ } from "@leitwerk-dev/process-sdk/leaf-outcome-renderer";
5
+
6
+ interface SinglePromptLeafOutcomePayload {
7
+ prompt?: unknown;
8
+ markdown?: unknown;
9
+ leafEntryId?: unknown;
10
+ turnRecordId?: unknown;
11
+ }
12
+
13
+ const TAG_NAME = "o2-showcase-processes-leaf-outcome";
14
+
15
+ class SinglePromptLeafOutcomeElement extends LeafOutcomeCustomElement<SinglePromptLeafOutcomePayload> {
16
+ protected renderContent(): void {
17
+ if (!this.canRender()) {
18
+ return;
19
+ }
20
+ const runtime = this.runtime;
21
+ if (!runtime) {
22
+ return;
23
+ }
24
+ const payload = this.payload;
25
+ const markdown = typeof payload?.markdown === "string" ? payload.markdown.trim() : "";
26
+ if (!markdown) {
27
+ this.emitError(
28
+ "missing_markdown_payload",
29
+ "The selected-leaf snapshot payload did not include markdown content.",
30
+ );
31
+ return;
32
+ }
33
+ const prompt = typeof payload?.prompt === "string" ? payload.prompt.trim() : "";
34
+ const relativeTime =
35
+ this.meta && typeof this.meta.createdAt === "string"
36
+ ? runtime.formatRelativeTime(this.meta.createdAt)
37
+ : null;
38
+ const promptMarkup = prompt ? `<p class="prompt">${escapeLeafOutcomeHtml(prompt)}</p>` : "";
39
+ const metaMarkup = relativeTime
40
+ ? `<p class="meta">Captured ${escapeLeafOutcomeHtml(relativeTime)}</p>`
41
+ : "";
42
+ this.shadowRootRef.innerHTML = `
43
+ <style>
44
+ :host {
45
+ display: block;
46
+ color: var(--o2-text, #1f2933);
47
+ }
48
+
49
+ .wrap {
50
+ display: flex;
51
+ flex-direction: column;
52
+ gap: var(--o2-space-md, 12px);
53
+ }
54
+
55
+ .prompt,
56
+ .meta {
57
+ margin: 0;
58
+ font-size: 12px;
59
+ line-height: 1.5;
60
+ color: var(--o2-text-muted, #667085);
61
+ }
62
+
63
+ .prompt {
64
+ padding: var(--o2-space-sm, 8px) 0;
65
+ border-top: 1px solid color-mix(in srgb, var(--o2-border, #ddd4c8) 78%, white 22%);
66
+ border-bottom: 1px solid color-mix(in srgb, var(--o2-border, #ddd4c8) 54%, white 46%);
67
+ }
68
+
69
+ .markdown {
70
+ color: var(--o2-text, #1f2933);
71
+ font-size: 14px;
72
+ line-height: 1.65;
73
+ }
74
+
75
+ .markdown :where(*:first-child) {
76
+ margin-top: 0;
77
+ }
78
+
79
+ .markdown :where(*:last-child) {
80
+ margin-bottom: 0;
81
+ }
82
+ </style>
83
+ <article class="wrap" data-renderer="showcase-processes-leaf-outcome">
84
+ ${promptMarkup}
85
+ <div class="markdown">${runtime.markdown.render(markdown)}</div>
86
+ ${metaMarkup}
87
+ </article>
88
+ `;
89
+ this.emitReady();
90
+ }
91
+ }
92
+
93
+ if (!customElements.get(TAG_NAME)) {
94
+ customElements.define(TAG_NAME, SinglePromptLeafOutcomeElement);
95
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "apiVersion": 1,
3
+ "extensionManifestId": "showcase-processes",
4
+ "renderers": {
5
+ "@leitwerk-dev/showcase-processes:single_prompt_process.leaf_outcome": {
6
+ "kind": "custom_element",
7
+ "tagName": "o2-showcase-processes-leaf-outcome",
8
+ "module": "./leaf-outcome-element.ts",
9
+ "rendererApiVersion": 1
10
+ },
11
+ "@leitwerk-dev/showcase-processes:single_prompt_with_tool_process.leaf_outcome": {
12
+ "kind": "custom_element",
13
+ "tagName": "o2-showcase-processes-leaf-outcome",
14
+ "module": "./leaf-outcome-element.ts",
15
+ "rendererApiVersion": 1
16
+ },
17
+ "@leitwerk-dev/showcase-processes:poem_creator_process.leaf_outcome": {
18
+ "kind": "custom_element",
19
+ "tagName": "o2-showcase-processes-poem-outcome",
20
+ "module": "./poem-leaf-outcome-element.ts",
21
+ "rendererApiVersion": 1
22
+ }
23
+ }
24
+ }
@@ -0,0 +1,204 @@
1
+ import {
2
+ escapeLeafOutcomeHtml,
3
+ LeafOutcomeCustomElement,
4
+ normalizeLeafOutcomeOptionalText,
5
+ } from "@leitwerk-dev/process-sdk/leaf-outcome-renderer";
6
+
7
+ interface PoemLeafOutcomeReviewPayload {
8
+ outcome?: unknown;
9
+ summary?: unknown;
10
+ feedback?: unknown;
11
+ }
12
+
13
+ interface PoemLeafOutcomePayload {
14
+ prompt?: unknown;
15
+ markdown?: unknown;
16
+ title?: unknown;
17
+ stanzas?: unknown;
18
+ review?: unknown;
19
+ }
20
+
21
+ const TAG_NAME = "o2-showcase-processes-poem-outcome";
22
+ const SUPPORTED_SCHEMA_VERSION = 1;
23
+
24
+ function isRecord(value: unknown): value is Record<string, unknown> {
25
+ return typeof value === "object" && value !== null && !Array.isArray(value);
26
+ }
27
+
28
+ function escapePlaintextWithBreaks(value: string): string {
29
+ return escapeLeafOutcomeHtml(value).replaceAll("\n", "<br>");
30
+ }
31
+
32
+ function parseReview(value: unknown): {
33
+ outcome: "leave_feedback" | "no_issues";
34
+ summary: string | null;
35
+ feedback: string | null;
36
+ } | null {
37
+ if (!isRecord(value)) {
38
+ return null;
39
+ }
40
+ const review = value as PoemLeafOutcomeReviewPayload;
41
+ if (review.outcome !== "leave_feedback" && review.outcome !== "no_issues") {
42
+ return null;
43
+ }
44
+ return {
45
+ outcome: review.outcome,
46
+ summary: normalizeLeafOutcomeOptionalText(review.summary),
47
+ feedback: normalizeLeafOutcomeOptionalText(review.feedback),
48
+ };
49
+ }
50
+
51
+ class SinglePromptPoemOutcomeElement extends LeafOutcomeCustomElement<PoemLeafOutcomePayload> {
52
+ protected renderContent(): void {
53
+ if (!this.canRender()) {
54
+ return;
55
+ }
56
+ const runtime = this.runtime;
57
+ if (!runtime) {
58
+ return;
59
+ }
60
+ if (this.meta?.schemaVersion !== SUPPORTED_SCHEMA_VERSION) {
61
+ this.emitError(
62
+ "unsupported_schema_version",
63
+ `Poem outcome renderer expects schemaVersion=${SUPPORTED_SCHEMA_VERSION}`,
64
+ );
65
+ return;
66
+ }
67
+
68
+ const payload = this.payload;
69
+ const markdown = typeof payload?.markdown === "string" ? payload.markdown.trim() : "";
70
+ const review = parseReview(payload?.review);
71
+ if (!markdown) {
72
+ this.emitError("invalid_poem_payload", "Poem outcome payload must include markdown content.");
73
+ return;
74
+ }
75
+
76
+ const reviewSummaryMarkup = review?.summary
77
+ ? `<p class="review-summary">${escapePlaintextWithBreaks(review.summary)}</p>`
78
+ : "";
79
+ const reviewFeedbackMarkup =
80
+ review?.feedback && review.feedback !== review.summary
81
+ ? `<p class="review-feedback">${escapePlaintextWithBreaks(review.feedback)}</p>`
82
+ : "";
83
+ const reviewMarkup = review
84
+ ? `<section class="review-block ${review.outcome === "no_issues" ? "is-positive" : "is-feedback"}" data-review-outcome="${review.outcome}">
85
+ <p class="review-label">${review.outcome === "no_issues" ? "LLM Opinion" : "Review"}</p>
86
+ ${reviewSummaryMarkup}
87
+ ${reviewFeedbackMarkup}
88
+ </section>`
89
+ : "";
90
+ const capturedMarkup = this.meta?.createdAt
91
+ ? `<p class="meta-copy">Captured ${escapeLeafOutcomeHtml(runtime.formatRelativeTime(this.meta.createdAt))}</p>`
92
+ : "";
93
+ this.shadowRootRef.innerHTML = `
94
+ <style>
95
+ :host {
96
+ display: block;
97
+ color: var(--o2-text, #1f2933);
98
+ }
99
+
100
+ .wrap {
101
+ display: grid;
102
+ gap: var(--o2-space-lg, 18px);
103
+ }
104
+
105
+ .meta-copy,
106
+ .review-label {
107
+ margin: 0;
108
+ font-size: 12px;
109
+ letter-spacing: 0.04em;
110
+ color: var(--o2-text-muted, #667085);
111
+ }
112
+
113
+ .review-label {
114
+ text-transform: uppercase;
115
+ font-weight: 700;
116
+ }
117
+
118
+ .poem-surface {
119
+ padding: 18px 0 20px;
120
+ border-top: 1px solid color-mix(in srgb, var(--o2-border, #ddd4c8) 82%, white 18%);
121
+ background: transparent;
122
+ }
123
+
124
+ .poem-markdown {
125
+ color: var(--o2-text, #1f2933);
126
+ font-size: 16px;
127
+ line-height: 1.75;
128
+ }
129
+
130
+ .poem-markdown :where(*:first-child) {
131
+ margin-top: 0;
132
+ }
133
+
134
+ .poem-markdown :where(*:last-child) {
135
+ margin-bottom: 0;
136
+ }
137
+
138
+ .poem-markdown :where(h1, h2, h3, h4, h5, h6) {
139
+ margin: 0 0 14px;
140
+ font-weight: 650;
141
+ line-height: 1.05;
142
+ letter-spacing: -0.02em;
143
+ color: var(--o2-text, #1f2933);
144
+ }
145
+
146
+ .poem-markdown :where(h1) {
147
+ font-size: 28px;
148
+ }
149
+
150
+ .poem-markdown :where(h2) {
151
+ font-size: 24px;
152
+ }
153
+
154
+ .poem-markdown :where(h3) {
155
+ font-size: 20px;
156
+ }
157
+
158
+ .poem-markdown :where(p) {
159
+ margin: 0;
160
+ }
161
+
162
+ .poem-markdown :where(p + p) {
163
+ margin-top: 14px;
164
+ }
165
+
166
+ .review-block {
167
+ display: grid;
168
+ gap: var(--o2-space-sm, 8px);
169
+ padding: 16px 0 0;
170
+ border-top: 1px solid color-mix(in srgb, var(--o2-border, #ddd4c8) 82%, white 18%);
171
+ background: transparent;
172
+ }
173
+
174
+ .review-block.is-positive {
175
+ border-top-color: color-mix(in srgb, #2f9e5f 30%, var(--o2-border, #ddd4c8) 70%);
176
+ }
177
+
178
+ .review-summary,
179
+ .review-feedback {
180
+ margin: 0;
181
+ font-size: 14px;
182
+ line-height: 1.6;
183
+ color: var(--o2-text, #1f2933);
184
+ }
185
+
186
+ .review-feedback {
187
+ color: var(--o2-text-muted, #53616f);
188
+ }
189
+ </style>
190
+ <article class="wrap" data-renderer="showcase-processes-poem-outcome">
191
+ <section class="poem-surface">
192
+ <div class="poem-markdown">${runtime.markdown.render(markdown)}</div>
193
+ </section>
194
+ ${reviewMarkup}
195
+ ${capturedMarkup}
196
+ </article>
197
+ `;
198
+ this.emitReady();
199
+ }
200
+ }
201
+
202
+ if (!customElements.get(TAG_NAME)) {
203
+ customElements.define(TAG_NAME, SinglePromptPoemOutcomeElement);
204
+ }