@bastani/atomic 0.9.13 → 0.9.14-alpha.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/CHANGELOG.md +12 -0
- package/dist/builtin/i-have-adhd/package.json +1 -1
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/builtin/workflows/CHANGELOG.md +12 -0
- package/dist/builtin/workflows/README.md +9 -0
- package/dist/builtin/workflows/builtin/adversarial-verification.ts +4 -0
- package/dist/builtin/workflows/builtin/classify-and-act.ts +4 -0
- package/dist/builtin/workflows/builtin/fan-out-and-synthesize.ts +4 -0
- package/dist/builtin/workflows/builtin/generate-and-filter.ts +4 -0
- package/dist/builtin/workflows/builtin/goal.ts +4 -0
- package/dist/builtin/workflows/builtin/loop-until-done.ts +4 -0
- package/dist/builtin/workflows/builtin/open-claude-design.ts +4 -0
- package/dist/builtin/workflows/builtin/ralph.ts +4 -0
- package/dist/builtin/workflows/builtin/tournament.ts +4 -0
- package/dist/builtin/workflows/package.json +1 -1
- package/dist/builtin/workflows/src/authoring/workflow.ts +9 -0
- package/dist/builtin/workflows/src/authoring.d.ts +3 -0
- package/dist/builtin/workflows/src/durable/completed-catalog.ts +13 -2
- package/dist/builtin/workflows/src/durable/workflow-heartbeat-anchor.ts +153 -0
- package/dist/builtin/workflows/src/engine/run-durable-stage-session.ts +28 -0
- package/dist/builtin/workflows/src/engine/run.ts +1 -0
- package/dist/builtin/workflows/src/extension/extension-runtime-state.ts +138 -0
- package/dist/builtin/workflows/src/extension/index.bundle.mjs +766 -4
- package/dist/builtin/workflows/src/extension/workflow-heartbeat-delivery.ts +197 -0
- package/dist/builtin/workflows/src/extension/workflow-heartbeat-notice.ts +115 -0
- package/dist/builtin/workflows/src/extension/workflow-heartbeat-scheduler.ts +962 -0
- package/dist/builtin/workflows/src/sdk-surface.ts +9 -0
- package/dist/builtin/workflows/src/shared/authoring-contract-ui.d.ts +1 -0
- package/dist/builtin/workflows/src/shared/authoring-contract-ui.ts +1 -0
- package/dist/builtin/workflows/src/shared/persistence-restore.ts +12 -0
- package/dist/builtin/workflows/src/shared/workflow-authoring-types.d.ts +1 -0
- package/dist/builtin/workflows/src/shared/workflow-authoring-types.ts +1 -0
- package/dist/builtin/workflows/src/shared/workflow-heartbeat-contract.d.ts +21 -0
- package/dist/builtin/workflows/src/shared/workflow-heartbeat-contract.ts +25 -0
- package/dist/core/extensions/index.d.ts +1 -0
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js +1 -0
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/ui-types.d.ts +26 -0
- package/dist/core/extensions/ui-types.d.ts.map +1 -1
- package/dist/core/extensions/ui-types.js +17 -1
- package/dist/core/extensions/ui-types.js.map +1 -1
- package/dist/core/tools/ask-user-question/ask-user-question.d.ts +21 -0
- package/dist/core/tools/ask-user-question/ask-user-question.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/ask-user-question.js +34 -9
- package/dist/core/tools/ask-user-question/ask-user-question.js.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/multi-select-view.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/multi-select-view.js +5 -2
- package/dist/core/tools/ask-user-question/view/components/multi-select-view.js.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/submit-picker.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/submit-picker.js +3 -1
- package/dist/core/tools/ask-user-question/view/components/submit-picker.js.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/wrapping-select.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/wrapping-select.js +8 -1
- package/dist/core/tools/ask-user-question/view/components/wrapping-select.js.map +1 -1
- package/dist/index-extensions.d.ts +1 -1
- package/dist/index-extensions.d.ts.map +1 -1
- package/dist/index-extensions.js +1 -1
- package/dist/index-extensions.js.map +1 -1
- package/dist/modes/interactive/components/reserved-bottom-overlay.d.ts +95 -0
- package/dist/modes/interactive/components/reserved-bottom-overlay.d.ts.map +1 -0
- package/dist/modes/interactive/components/reserved-bottom-overlay.js +234 -0
- package/dist/modes/interactive/components/reserved-bottom-overlay.js.map +1 -0
- package/dist/modes/interactive/interactive-extension-custom-ui.js +94 -6
- package/dist/modes/interactive/interactive-extension-custom-ui.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-base.d.ts +3 -0
- package/dist/modes/interactive/interactive-mode-base.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-base.js +5 -1
- package/dist/modes/interactive/interactive-mode-base.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-surface.d.ts +2 -0
- package/dist/modes/interactive/interactive-mode-surface.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-surface.js.map +1 -1
- package/dist/modes/interactive/interactive-tui.d.ts +3 -0
- package/dist/modes/interactive/interactive-tui.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-tui.js +14 -0
- package/dist/modes/interactive/interactive-tui.js.map +1 -1
- package/dist/modes/interactive-engine/engine-custom-ui.d.ts +2 -0
- package/dist/modes/interactive-engine/engine-custom-ui.d.ts.map +1 -1
- package/dist/modes/interactive-engine/engine-custom-ui.js +1 -0
- package/dist/modes/interactive-engine/engine-custom-ui.js.map +1 -1
- package/dist/modes/interactive-engine/protocol.d.ts +1 -0
- package/dist/modes/interactive-engine/protocol.d.ts.map +1 -1
- package/dist/modes/interactive-engine/protocol.js +1 -0
- package/dist/modes/interactive-engine/protocol.js.map +1 -1
- package/dist/modes/interactive-engine/remote-component.d.ts +3 -1
- package/dist/modes/interactive-engine/remote-component.d.ts.map +1 -1
- package/dist/modes/interactive-engine/remote-component.js +3 -2
- package/dist/modes/interactive-engine/remote-component.js.map +1 -1
- package/docs/extensions.md +27 -0
- package/docs/keybindings.md +1 -0
- package/docs/workflows.md +34 -0
- package/npm-shrinkwrap.json +29 -29
- package/package.json +2 -2
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import type { WorkflowHeartbeatEventDetails } from "../shared/workflow-heartbeat-contract.js";
|
|
2
|
+
|
|
3
|
+
/** Timer seam so the scheduler and its retries are testable without real waiting. */
|
|
4
|
+
export interface WorkflowHeartbeatTimerHandle {
|
|
5
|
+
unref?: () => void;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface WorkflowHeartbeatTimerApi {
|
|
9
|
+
setTimeout(handler: () => void, delayMs: number): WorkflowHeartbeatTimerHandle;
|
|
10
|
+
clearTimeout(handle: WorkflowHeartbeatTimerHandle): void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const defaultWorkflowHeartbeatTimerApi: WorkflowHeartbeatTimerApi = {
|
|
14
|
+
setTimeout: (handler, delayMs) => setTimeout(handler, delayMs) as WorkflowHeartbeatTimerHandle,
|
|
15
|
+
clearTimeout: (handle) => clearTimeout(handle as ReturnType<typeof setTimeout>),
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Attempts a single heartbeat identity is given before its pending slot is
|
|
20
|
+
* released. A heartbeat is a periodic nudge, not an exactly-once terminal
|
|
21
|
+
* notice: retrying forever would hold the run's one pending slot and silence
|
|
22
|
+
* every later boundary on the cadence. Releasing the slot lets the next future
|
|
23
|
+
* boundary arm normally.
|
|
24
|
+
*/
|
|
25
|
+
export const WORKFLOW_HEARTBEAT_MAX_DELIVERY_ATTEMPTS = 5;
|
|
26
|
+
|
|
27
|
+
interface WorkflowHeartbeatDeliveryOptions {
|
|
28
|
+
readonly emit: (details: WorkflowHeartbeatEventDetails) => boolean | Promise<boolean>;
|
|
29
|
+
/**
|
|
30
|
+
* Live re-check taken immediately before every attempt, the retries included.
|
|
31
|
+
* A run that reached a terminal state between attempt 1 and attempt 5 must not
|
|
32
|
+
* be sent, so the guard belongs on the attempt rather than on the enqueue.
|
|
33
|
+
*/
|
|
34
|
+
readonly canDeliver?: (details: WorkflowHeartbeatEventDetails) => boolean;
|
|
35
|
+
/** Called exactly once per identity, after success or after attempts are exhausted. */
|
|
36
|
+
readonly onSettled: (details: WorkflowHeartbeatEventDetails, delivered: boolean) => void;
|
|
37
|
+
readonly timers: WorkflowHeartbeatTimerApi;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface WorkflowHeartbeatDelivery {
|
|
41
|
+
deliver(details: WorkflowHeartbeatEventDetails): void;
|
|
42
|
+
/**
|
|
43
|
+
* Drop every not-yet-attempted identity belonging to one run, and cancel the
|
|
44
|
+
* backoff timer of a head that belongs to it, then start the next identity.
|
|
45
|
+
*
|
|
46
|
+
* Terminal cleanup's queue half (issue #1975). A send already handed to the
|
|
47
|
+
* host cannot be recalled, so an in-flight head stays where it is — but it is
|
|
48
|
+
* marked, so whatever the host answers settles straight through instead of
|
|
49
|
+
* arming a retry for a run that is already finished. Its `onSettled` is inert
|
|
50
|
+
* at the scheduler too, because the pending slot is gone by then. Returns
|
|
51
|
+
* whether anything was dropped, so a spared in-flight head alone reports
|
|
52
|
+
* `false`.
|
|
53
|
+
*/
|
|
54
|
+
discard(runId: string): boolean;
|
|
55
|
+
dispose(): void;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Stable delivery key for one boundary: the slice-1 `runId + scheduledAt` identity. */
|
|
59
|
+
export function workflowHeartbeatIdentityKey(identity: { runId: string; scheduledAt: number }): string {
|
|
60
|
+
return `${identity.runId}:${identity.scheduledAt}`;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Owns heartbeat admission: one identity at a time, in the order handed over,
|
|
65
|
+
* with capped-backoff retry.
|
|
66
|
+
*
|
|
67
|
+
* **Why the queue exists.** The scheduler sorts a due batch by `scheduledAt`
|
|
68
|
+
* then `runId` and hands identities over in that order, but sorting only
|
|
69
|
+
* controls the order attempts *start*. If the first identity's send is rejected
|
|
70
|
+
* it enters backoff, and a later identity admitted in the meantime reaches the
|
|
71
|
+
* parent first — the observed order becomes B, A. Admission order is what the
|
|
72
|
+
* ordering rule is about, so the queue holds later identities until the head
|
|
73
|
+
* reaches a terminal result: admitted, suppressed by its guard, or out of
|
|
74
|
+
* attempts.
|
|
75
|
+
*
|
|
76
|
+
* Every retry re-sends the identical `WorkflowHeartbeatEventDetails`, so the
|
|
77
|
+
* `runId + scheduledAt` identity is reused rather than re-derived from the
|
|
78
|
+
* retry's own clock. Deliberately separate from `createLifecycleNoticeDelivery`:
|
|
79
|
+
* that helper is hard-typed to lifecycle notices and its exact retry/handover
|
|
80
|
+
* semantics are pinned by existing tests.
|
|
81
|
+
*/
|
|
82
|
+
export function createWorkflowHeartbeatDelivery(options: WorkflowHeartbeatDeliveryOptions): WorkflowHeartbeatDelivery {
|
|
83
|
+
const retryTimers = new Set<WorkflowHeartbeatTimerHandle>();
|
|
84
|
+
const queue: WorkflowHeartbeatEventDetails[] = [];
|
|
85
|
+
let attempt = 0;
|
|
86
|
+
let running = false;
|
|
87
|
+
let active = true;
|
|
88
|
+
/**
|
|
89
|
+
* Whether the in-flight head was discarded while its send was outstanding.
|
|
90
|
+
*
|
|
91
|
+
* The send itself cannot be recalled, but its *result* must not start a
|
|
92
|
+
* retry: a rejection arriving after cleanup would otherwise arm a backoff
|
|
93
|
+
* timer, and re-attempt the old identity, for a run whose cleanup already
|
|
94
|
+
* finished. One boolean suffices because only one head is ever in flight,
|
|
95
|
+
* and `settleHead` — the only path that shifts the queue — clears it, so it
|
|
96
|
+
* can never carry over to the next identity or to another run.
|
|
97
|
+
*/
|
|
98
|
+
let headDiscarded = false;
|
|
99
|
+
|
|
100
|
+
/** Finish the head identity and start the next one, in handover order. */
|
|
101
|
+
const settleHead = (details: WorkflowHeartbeatEventDetails, delivered: boolean): void => {
|
|
102
|
+
queue.shift();
|
|
103
|
+
attempt = 0;
|
|
104
|
+
running = false;
|
|
105
|
+
headDiscarded = false;
|
|
106
|
+
options.onSettled(details, delivered);
|
|
107
|
+
runHead();
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const runHead = (): void => {
|
|
111
|
+
if (!active || running || retryTimers.size > 0) return;
|
|
112
|
+
const details = queue[0];
|
|
113
|
+
if (details === undefined) return;
|
|
114
|
+
// The live guard runs immediately before every attempt, including the
|
|
115
|
+
// first attempt of an identity that waited behind another one — the run
|
|
116
|
+
// may have finished or paused while it queued.
|
|
117
|
+
if (options.canDeliver !== undefined && !options.canDeliver(details)) {
|
|
118
|
+
// Suppressed rather than sent, and never retried: the run's state is the
|
|
119
|
+
// reason, and no amount of backoff changes it. Later identities proceed.
|
|
120
|
+
settleHead(details, false);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
running = true;
|
|
124
|
+
attempt += 1;
|
|
125
|
+
const thisAttempt = attempt;
|
|
126
|
+
const settle = (delivered: boolean): void => {
|
|
127
|
+
// A discarded head settles straight through, whatever the host answered:
|
|
128
|
+
// no retry, and the real result is still reported once.
|
|
129
|
+
if (delivered || headDiscarded || thisAttempt >= WORKFLOW_HEARTBEAT_MAX_DELIVERY_ATTEMPTS || !active) {
|
|
130
|
+
settleHead(details, delivered);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
running = false;
|
|
134
|
+
const handle = options.timers.setTimeout(
|
|
135
|
+
() => {
|
|
136
|
+
retryTimers.delete(handle);
|
|
137
|
+
runHead();
|
|
138
|
+
},
|
|
139
|
+
Math.min(20 * 2 ** (thisAttempt - 1), 1_000),
|
|
140
|
+
);
|
|
141
|
+
handle.unref?.();
|
|
142
|
+
retryTimers.add(handle);
|
|
143
|
+
};
|
|
144
|
+
const result = options.emit(details);
|
|
145
|
+
if (typeof result === "boolean") settle(result);
|
|
146
|
+
else void result.then(settle);
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
const deliver = (details: WorkflowHeartbeatEventDetails): void => {
|
|
150
|
+
if (!active) return;
|
|
151
|
+
queue.push(details);
|
|
152
|
+
runHead();
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
const discard = (runId: string): boolean => {
|
|
156
|
+
// An attempt is already with the host and cannot be recalled, so the head
|
|
157
|
+
// is spared only while its send is genuinely in flight. A head sitting in
|
|
158
|
+
// backoff has nothing outstanding and is dropped with its timer.
|
|
159
|
+
const head = queue[0];
|
|
160
|
+
const headInFlight = running && head !== undefined && head.runId === runId;
|
|
161
|
+
let discarded = false;
|
|
162
|
+
// Back to front, so index 0 is decided last and the indices ahead of it
|
|
163
|
+
// stay valid while they are spliced out.
|
|
164
|
+
for (let index = queue.length - 1; index >= 0; index -= 1) {
|
|
165
|
+
if (queue[index]?.runId !== runId) continue;
|
|
166
|
+
if (index === 0 && headInFlight) {
|
|
167
|
+
// Spared, but invalidated: its settlement must not schedule a retry.
|
|
168
|
+
headDiscarded = true;
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
queue.splice(index, 1);
|
|
172
|
+
discarded = true;
|
|
173
|
+
if (index > 0) continue;
|
|
174
|
+
// The dropped head owned the attempt counter and, if it was waiting to
|
|
175
|
+
// retry, the only live backoff timer.
|
|
176
|
+
attempt = 0;
|
|
177
|
+
running = false;
|
|
178
|
+
for (const handle of retryTimers) options.timers.clearTimeout(handle);
|
|
179
|
+
retryTimers.clear();
|
|
180
|
+
}
|
|
181
|
+
if (discarded) runHead();
|
|
182
|
+
return discarded;
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
return {
|
|
186
|
+
deliver,
|
|
187
|
+
discard,
|
|
188
|
+
dispose() {
|
|
189
|
+
active = false;
|
|
190
|
+
for (const handle of retryTimers) options.timers.clearTimeout(handle);
|
|
191
|
+
retryTimers.clear();
|
|
192
|
+
queue.length = 0;
|
|
193
|
+
// An in-flight send is left to settle on its own; `active` keeps it from
|
|
194
|
+
// starting a further retry.
|
|
195
|
+
},
|
|
196
|
+
};
|
|
197
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import {
|
|
2
|
+
WORKFLOW_HEARTBEAT_CUSTOM_TYPE,
|
|
3
|
+
type WorkflowHeartbeatEventDetails,
|
|
4
|
+
} from "../shared/workflow-heartbeat-contract.js";
|
|
5
|
+
import { deriveGraphThemeFromPiTheme, type GraphTheme } from "../tui/graph-theme.js";
|
|
6
|
+
import { renderWorkflowNoticeCard } from "../tui/workflow-notice-card.js";
|
|
7
|
+
import type { ExtensionAPI, PiMessageRenderComponent, PiMessageRenderer } from "./index.js";
|
|
8
|
+
|
|
9
|
+
/** Card title and glyph, both distinct from every lifecycle notice kind. */
|
|
10
|
+
const WORKFLOW_HEARTBEAT_TITLE = "WORKFLOW HEARTBEAT";
|
|
11
|
+
const WORKFLOW_HEARTBEAT_GLYPH = "♥";
|
|
12
|
+
|
|
13
|
+
const rendererRegisteredHosts = new WeakSet<object>();
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Model-facing heartbeat text. Derived only from the five slice-1 payload
|
|
17
|
+
* fields: it names the workflow and run so the parent can identify the work,
|
|
18
|
+
* states the cadence and elapsed time so it can judge drift, and points at the
|
|
19
|
+
* existing status surface so it can inspect rather than guess.
|
|
20
|
+
*/
|
|
21
|
+
export function formatWorkflowHeartbeatNoticeText(details: WorkflowHeartbeatEventDetails): string {
|
|
22
|
+
const workflowName = escapeQuotedText(details.workflowName);
|
|
23
|
+
const elapsed = formatWorkflowHeartbeatElapsed(details);
|
|
24
|
+
const cadence = formatWorkflowHeartbeatCadence(details.intervalMinutes);
|
|
25
|
+
return (
|
|
26
|
+
`${WORKFLOW_HEARTBEAT_GLYPH} Workflow "${workflowName}" heartbeat (run ${details.runId}) — still running` +
|
|
27
|
+
`${elapsed === undefined ? "" : ` after ${elapsed}`}, on a ${cadence} cadence. ` +
|
|
28
|
+
"This is a periodic alignment check, not a failure. Review whether the run is still on goal, then " +
|
|
29
|
+
"continue, steer it, stop and replace it, or ask the user. " +
|
|
30
|
+
`Inspect: /workflow status ${details.runId}`
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface WorkflowHeartbeatRendererOptions {
|
|
35
|
+
readonly registerMessageRenderer?: ExtensionAPI["registerMessageRenderer"];
|
|
36
|
+
readonly rendererHost?: object;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function registerWorkflowHeartbeatRenderer(options: WorkflowHeartbeatRendererOptions): void {
|
|
40
|
+
const register = options.registerMessageRenderer;
|
|
41
|
+
if (typeof register !== "function") return;
|
|
42
|
+
|
|
43
|
+
const host = options.rendererHost ?? register;
|
|
44
|
+
if (rendererRegisteredHosts.has(host)) return;
|
|
45
|
+
|
|
46
|
+
const renderer: PiMessageRenderer = (raw, _options, piTheme) => {
|
|
47
|
+
const message = raw as { details?: WorkflowHeartbeatEventDetails };
|
|
48
|
+
if (!message.details) return undefined;
|
|
49
|
+
return makeWorkflowHeartbeatComponent(message.details, themeFromRenderer(piTheme));
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
register(WORKFLOW_HEARTBEAT_CUSTOM_TYPE, renderer);
|
|
53
|
+
rendererRegisteredHosts.add(host);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function makeWorkflowHeartbeatComponent(
|
|
57
|
+
details: WorkflowHeartbeatEventDetails,
|
|
58
|
+
theme: GraphTheme | undefined,
|
|
59
|
+
): PiMessageRenderComponent {
|
|
60
|
+
const text = formatWorkflowHeartbeatNoticeText(details);
|
|
61
|
+
return {
|
|
62
|
+
render(width: number): string[] {
|
|
63
|
+
return renderWorkflowHeartbeatCard(details, { width, theme, fallbackText: text });
|
|
64
|
+
},
|
|
65
|
+
invalidate() {
|
|
66
|
+
/* delivered heartbeats are immutable */
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function renderWorkflowHeartbeatCard(
|
|
72
|
+
details: WorkflowHeartbeatEventDetails,
|
|
73
|
+
opts: { width: number; theme?: GraphTheme; fallbackText: string },
|
|
74
|
+
): string[] {
|
|
75
|
+
return renderWorkflowNoticeCard({
|
|
76
|
+
title: WORKFLOW_HEARTBEAT_TITLE,
|
|
77
|
+
glyph: WORKFLOW_HEARTBEAT_GLYPH,
|
|
78
|
+
headline: `Workflow "${details.workflowName}" is still running`,
|
|
79
|
+
tone: "mauve",
|
|
80
|
+
fields: [
|
|
81
|
+
{ label: "workflow", value: details.workflowName },
|
|
82
|
+
{ label: "run", value: details.runId },
|
|
83
|
+
{ label: "cadence", value: formatWorkflowHeartbeatCadence(details.intervalMinutes), tone: "muted" },
|
|
84
|
+
{ label: "elapsed", value: formatWorkflowHeartbeatElapsed(details), tone: "muted" },
|
|
85
|
+
],
|
|
86
|
+
hints: [`/workflow status ${details.runId}`],
|
|
87
|
+
fallbackText: opts.fallbackText,
|
|
88
|
+
width: opts.width,
|
|
89
|
+
...(opts.theme ? { theme: opts.theme } : {}),
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function formatWorkflowHeartbeatCadence(intervalMinutes: number): string {
|
|
94
|
+
return `${intervalMinutes}-minute`;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Elapsed run time at the boundary, derived from the payload's own timestamps. */
|
|
98
|
+
function formatWorkflowHeartbeatElapsed(details: WorkflowHeartbeatEventDetails): string | undefined {
|
|
99
|
+
const elapsedMs = details.scheduledAt - details.startedAt;
|
|
100
|
+
if (!Number.isFinite(elapsedMs) || elapsedMs < 0) return undefined;
|
|
101
|
+
const totalMinutes = Math.floor(elapsedMs / 60_000);
|
|
102
|
+
if (totalMinutes < 1) return `${Math.max(0, Math.floor(elapsedMs / 1000))}s`;
|
|
103
|
+
if (totalMinutes < 60) return `${totalMinutes}m`;
|
|
104
|
+
const hours = Math.floor(totalMinutes / 60);
|
|
105
|
+
const minutes = totalMinutes % 60;
|
|
106
|
+
return minutes === 0 ? `${hours}h` : `${hours}h ${minutes}m`;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function escapeQuotedText(value: string): string {
|
|
110
|
+
return value.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function themeFromRenderer(piTheme: unknown): GraphTheme | undefined {
|
|
114
|
+
return piTheme === undefined ? undefined : deriveGraphThemeFromPiTheme(piTheme);
|
|
115
|
+
}
|