@bastani/atomic 0.9.16-alpha.7 → 0.9.16-alpha.9
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 +25 -0
- package/dist/builtin/intercom/CHANGELOG.md +6 -0
- package/dist/builtin/intercom/README.md +4 -4
- package/dist/builtin/intercom/broker/broker.ts +617 -22
- package/dist/builtin/intercom/broker/client-message-validation.ts +9 -0
- package/dist/builtin/intercom/broker/client.ts +200 -10
- package/dist/builtin/intercom/broker/pending-send-registry.ts +4 -0
- package/dist/builtin/intercom/broker/send-handler.ts +90 -36
- package/dist/builtin/intercom/broker/send-signature.ts +20 -8
- package/dist/builtin/intercom/group.ts +85 -0
- package/dist/builtin/intercom/index.bundle.mjs +746 -55
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/intercom/session-target.ts +54 -0
- package/dist/builtin/intercom/skills/intercom/SKILL.md +18 -3
- package/dist/builtin/intercom/source-ownership.ts +31 -0
- package/dist/builtin/intercom/types.ts +115 -0
- package/dist/builtin/mcp/index.bundle.mjs +175 -37
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +239 -53
- package/dist/builtin/web-access/index.bundle.mjs +175 -37
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/builtin/workflows/CHANGELOG.md +15 -0
- package/dist/builtin/workflows/README.md +40 -37
- package/dist/builtin/workflows/builtin/adversarial-verification.js +13 -0
- package/dist/builtin/workflows/builtin/{shared-prompts.ts → chunk-0x6e303p.js} +133 -154
- package/dist/builtin/workflows/builtin/chunk-17zk6ffd.js +69794 -0
- package/dist/builtin/workflows/builtin/chunk-29wrp38a.js +199 -0
- package/dist/builtin/workflows/builtin/chunk-2dqb5s2q.js +602 -0
- package/dist/builtin/workflows/builtin/chunk-4febxsv4.js +264 -0
- package/dist/builtin/workflows/builtin/chunk-5wgwscd0.js +4 -0
- package/dist/builtin/workflows/builtin/chunk-6fqs7c01.js +155 -0
- package/dist/builtin/workflows/builtin/chunk-7430zyas.js +126 -0
- package/dist/builtin/workflows/builtin/chunk-7at6dnkr.js +33 -0
- package/dist/builtin/workflows/builtin/chunk-82ha8p41.js +175 -0
- package/dist/builtin/workflows/builtin/chunk-8v8wmb7z.js +529 -0
- package/dist/builtin/workflows/builtin/chunk-bfkmzv9h.js +156 -0
- package/dist/builtin/workflows/builtin/chunk-c53y8bdh.js +345 -0
- package/dist/builtin/workflows/builtin/chunk-cg9tmks0.js +206 -0
- package/dist/builtin/workflows/builtin/chunk-h5e65g7g.js +1080 -0
- package/dist/builtin/workflows/builtin/chunk-hzzn6adg.js +221 -0
- package/dist/builtin/workflows/builtin/chunk-nqr34qp3.js +1061 -0
- package/dist/builtin/workflows/builtin/chunk-qe6bfpbd.js +1207 -0
- package/dist/builtin/workflows/builtin/chunk-qwzvgxnq.js +404 -0
- package/dist/builtin/workflows/builtin/chunk-qx2ptjs3.js +215 -0
- package/dist/builtin/workflows/builtin/chunk-rbnj9621.js +2447 -0
- package/dist/builtin/workflows/builtin/chunk-wpckd35c.js +12 -0
- package/dist/builtin/workflows/builtin/chunk-x2ghn0je.js +4110 -0
- package/dist/builtin/workflows/builtin/classify-and-act.js +12 -0
- package/dist/builtin/workflows/builtin/fan-out-and-synthesize.js +10 -0
- package/dist/builtin/workflows/builtin/generate-and-filter.js +12 -0
- package/dist/builtin/workflows/builtin/goal.js +16 -0
- package/dist/builtin/workflows/builtin/index.js +49 -0
- package/dist/builtin/workflows/builtin/loop-until-done.js +12 -0
- package/dist/builtin/workflows/builtin/open-claude-design.js +11 -0
- package/dist/builtin/workflows/builtin/ralph.js +16 -0
- package/dist/builtin/workflows/builtin/steering-context.d.ts +6 -0
- package/dist/builtin/workflows/builtin/steering-context.js +7 -0
- package/dist/builtin/workflows/builtin/tournament.js +13 -0
- package/dist/builtin/workflows/package.json +10 -7
- package/dist/builtin/workflows/src/authoring/typebox-defaults.d.ts +41 -0
- package/dist/builtin/workflows/src/extension/index.bundle.mjs +1294 -430
- package/dist/builtin/workflows/src/{index.bundle.mjs → index.js} +1022 -429
- package/dist/builtin/workflows/src/shared/authoring-contract-stage.d.ts +403 -0
- package/dist/builtin/workflows/src/shared/authoring-contract-ui.d.ts +327 -0
- package/dist/builtin/workflows/src/shared/budget.d.ts +67 -0
- package/dist/builtin/workflows/src/shared/workflow-authoring-types.d.ts +60 -0
- package/dist/builtin/workflows/src/shared/workflow-heartbeat-contract.d.ts +21 -0
- package/dist/core/agent-session-custom-message-commit.d.ts.map +1 -1
- package/dist/core/agent-session-custom-message-commit.js +12 -5
- package/dist/core/agent-session-custom-message-commit.js.map +1 -1
- package/dist/core/agent-session-persistent-custom-messages.d.ts.map +1 -1
- package/dist/core/agent-session-persistent-custom-messages.js +2 -0
- package/dist/core/agent-session-persistent-custom-messages.js.map +1 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +2 -1
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-storage.d.ts +2 -0
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +4 -0
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/builtin-install-layout.d.ts +1 -1
- package/dist/core/builtin-install-layout.d.ts.map +1 -1
- package/dist/core/builtin-install-layout.js +1 -1
- package/dist/core/builtin-install-layout.js.map +1 -1
- package/dist/core/codex-fast-mode.d.ts +10 -7
- package/dist/core/codex-fast-mode.d.ts.map +1 -1
- package/dist/core/codex-fast-mode.js +31 -13
- package/dist/core/codex-fast-mode.js.map +1 -1
- package/dist/core/extensions/agent-events.d.ts +15 -0
- package/dist/core/extensions/agent-events.d.ts.map +1 -1
- package/dist/core/extensions/agent-events.js.map +1 -1
- package/dist/core/extensions/api-types.d.ts +3 -1
- package/dist/core/extensions/api-types.d.ts.map +1 -1
- package/dist/core/extensions/api-types.js.map +1 -1
- package/dist/core/extensions/context-types.d.ts +35 -0
- package/dist/core/extensions/context-types.d.ts.map +1 -1
- package/dist/core/extensions/context-types.js.map +1 -1
- package/dist/core/extensions/event-types.d.ts +2 -2
- package/dist/core/extensions/event-types.d.ts.map +1 -1
- package/dist/core/extensions/event-types.js.map +1 -1
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/loader-virtual-modules.d.ts.map +1 -1
- package/dist/core/extensions/loader-virtual-modules.js +6 -1
- package/dist/core/extensions/loader-virtual-modules.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +6 -0
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +65 -1
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/model-runtime.d.ts +2 -0
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +4 -0
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/runtime-credentials.d.ts +1 -0
- package/dist/core/runtime-credentials.d.ts.map +1 -1
- package/dist/core/runtime-credentials.js +8 -0
- package/dist/core/runtime-credentials.js.map +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +5 -5
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-manager-storage.d.ts +2 -0
- package/dist/core/session-manager-storage.d.ts.map +1 -1
- package/dist/core/session-manager-storage.js +4 -2
- package/dist/core/session-manager-storage.js.map +1 -1
- package/dist/core/slash-commands.js +1 -1
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/workflow-stage-admission.d.ts +6 -1
- package/dist/core/workflow-stage-admission.d.ts.map +1 -1
- package/dist/core/workflow-stage-admission.js +8 -9
- package/dist/core/workflow-stage-admission.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.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +1 -1
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/interactive-autocomplete.js +1 -1
- package/dist/modes/interactive/interactive-autocomplete.js.map +1 -1
- package/dist/modes/interactive/interactive-extension-runtime.js +1 -1
- package/dist/modes/interactive/interactive-extension-runtime.js.map +1 -1
- package/dist/modes/interactive/interactive-startup.js +1 -1
- package/dist/modes/interactive/interactive-startup.js.map +1 -1
- package/dist/modes/interactive-engine/isolated-runtime.d.ts +4 -0
- package/dist/modes/interactive-engine/isolated-runtime.d.ts.map +1 -1
- package/dist/modes/interactive-engine/isolated-runtime.js +69 -10
- package/dist/modes/interactive-engine/isolated-runtime.js.map +1 -1
- package/dist/modes/rpc/rpc-client-api.d.ts +18 -2
- package/dist/modes/rpc/rpc-client-api.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client-api.js +33 -5
- package/dist/modes/rpc/rpc-client-api.js.map +1 -1
- package/dist/modes/rpc/rpc-command-handler.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-command-handler.js +8 -4
- package/dist/modes/rpc/rpc-command-handler.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +13 -0
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/docs/extensions.md +19 -0
- package/docs/intercom.md +15 -6
- package/docs/packages.md +2 -2
- package/docs/providers.md +8 -3
- package/docs/quickstart.md +2 -2
- package/docs/rpc.md +21 -4
- package/docs/settings.md +6 -4
- package/docs/subagents.md +1 -1
- package/docs/usage.md +1 -1
- package/docs/workflows.md +108 -239
- package/npm-shrinkwrap.json +32 -32
- package/package.json +9 -13
- package/dist/builtin/workflows/ambient.d.ts +0 -61
- package/dist/builtin/workflows/builtin/adversarial-verification-prompts.ts +0 -26
- package/dist/builtin/workflows/builtin/adversarial-verification-runner.ts +0 -391
- package/dist/builtin/workflows/builtin/adversarial-verification.ts +0 -34
- package/dist/builtin/workflows/builtin/classify-and-act-prompts.ts +0 -14
- package/dist/builtin/workflows/builtin/classify-and-act-runner.ts +0 -108
- package/dist/builtin/workflows/builtin/classify-and-act.ts +0 -40
- package/dist/builtin/workflows/builtin/fan-out-and-synthesize-prompts.ts +0 -14
- package/dist/builtin/workflows/builtin/fan-out-and-synthesize-runner.ts +0 -96
- package/dist/builtin/workflows/builtin/fan-out-and-synthesize.ts +0 -37
- package/dist/builtin/workflows/builtin/generate-and-filter-prompts.ts +0 -41
- package/dist/builtin/workflows/builtin/generate-and-filter-runner.ts +0 -90
- package/dist/builtin/workflows/builtin/generate-and-filter.ts +0 -31
- package/dist/builtin/workflows/builtin/goal-artifacts.ts +0 -64
- package/dist/builtin/workflows/builtin/goal-convergence.ts +0 -87
- package/dist/builtin/workflows/builtin/goal-ledger.ts +0 -139
- package/dist/builtin/workflows/builtin/goal-models.ts +0 -72
- package/dist/builtin/workflows/builtin/goal-orchestrator-prompts.ts +0 -94
- package/dist/builtin/workflows/builtin/goal-prompts.ts +0 -217
- package/dist/builtin/workflows/builtin/goal-reducer.ts +0 -176
- package/dist/builtin/workflows/builtin/goal-reports.ts +0 -76
- package/dist/builtin/workflows/builtin/goal-reverify.ts +0 -305
- package/dist/builtin/workflows/builtin/goal-review.ts +0 -139
- package/dist/builtin/workflows/builtin/goal-runner.ts +0 -504
- package/dist/builtin/workflows/builtin/goal-schemas.ts +0 -89
- package/dist/builtin/workflows/builtin/goal-types.ts +0 -164
- package/dist/builtin/workflows/builtin/goal.ts +0 -78
- package/dist/builtin/workflows/builtin/index.ts +0 -16
- package/dist/builtin/workflows/builtin/loop-until-done-prompts.ts +0 -87
- package/dist/builtin/workflows/builtin/loop-until-done-runner.ts +0 -282
- package/dist/builtin/workflows/builtin/loop-until-done.ts +0 -51
- package/dist/builtin/workflows/builtin/open-claude-design-live-protocol.ts +0 -305
- package/dist/builtin/workflows/builtin/open-claude-design-phases.ts +0 -337
- package/dist/builtin/workflows/builtin/open-claude-design-runner.ts +0 -347
- package/dist/builtin/workflows/builtin/open-claude-design-setup.ts +0 -313
- package/dist/builtin/workflows/builtin/open-claude-design-utils.ts +0 -311
- package/dist/builtin/workflows/builtin/open-claude-design.ts +0 -57
- package/dist/builtin/workflows/builtin/pattern-artifact-root.ts +0 -28
- package/dist/builtin/workflows/builtin/progress-scoring.ts +0 -230
- package/dist/builtin/workflows/builtin/ralph-core.ts +0 -449
- package/dist/builtin/workflows/builtin/ralph-forked-prompts.ts +0 -100
- package/dist/builtin/workflows/builtin/ralph-models.ts +0 -183
- package/dist/builtin/workflows/builtin/ralph-review-gate.ts +0 -103
- package/dist/builtin/workflows/builtin/ralph-reviewer-prompt.ts +0 -104
- package/dist/builtin/workflows/builtin/ralph-runner.ts +0 -459
- package/dist/builtin/workflows/builtin/ralph.ts +0 -82
- package/dist/builtin/workflows/builtin/review-convergence.ts +0 -229
- package/dist/builtin/workflows/builtin/selection-math.ts +0 -156
- package/dist/builtin/workflows/builtin/steering-context.ts +0 -51
- package/dist/builtin/workflows/builtin/tournament-prompts.ts +0 -70
- package/dist/builtin/workflows/builtin/tournament-runner.ts +0 -400
- package/dist/builtin/workflows/builtin/tournament.ts +0 -73
- package/dist/builtin/workflows/builtin/verification-criteria.ts +0 -330
- package/dist/builtin/workflows/builtin/verification-prompts.ts +0 -206
- package/dist/builtin/workflows/builtin/verification-usage.ts +0 -44
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// dist/builtin/workflows/src/authoring/workflow.ts
|
|
2
|
+
import { basename } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
|
|
5
|
+
// dist/builtin/workflows/src/shared/budget.ts
|
|
6
|
+
function validateWorkflowBudget(value, label = "budget") {
|
|
7
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
8
|
+
return `"${label}" must be a JSON object, got ${JSON.stringify(typeof value)}`;
|
|
9
|
+
}
|
|
10
|
+
const budget = value;
|
|
11
|
+
for (const field of ["maxDurationMs", "maxTokens"]) {
|
|
12
|
+
const limit = budget[field];
|
|
13
|
+
if (field in budget && (typeof limit !== "number" || !Number.isFinite(limit) || !Number.isInteger(limit) || limit < 0)) {
|
|
14
|
+
return `"${label}.${field}" must be a non-negative finite integer, got ${JSON.stringify(limit)}`;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
for (const field of ["maxCost", "warnAtPercent"]) {
|
|
18
|
+
const limit = budget[field];
|
|
19
|
+
if (field in budget && (typeof limit !== "number" || !Number.isFinite(limit) || limit < 0)) {
|
|
20
|
+
return `"${label}.${field}" must be a non-negative finite number, got ${JSON.stringify(limit)}`;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
function assertWorkflowBudget(value, label = "budget") {
|
|
26
|
+
if (value === undefined)
|
|
27
|
+
return;
|
|
28
|
+
const reason = validateWorkflowBudget(value, label);
|
|
29
|
+
if (reason !== null)
|
|
30
|
+
throw new TypeError(reason);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// dist/builtin/workflows/src/shared/workflow-heartbeat-contract.ts
|
|
34
|
+
var DEFAULT_WORKFLOW_HEARTBEAT_INTERVAL_MINUTES = 15;
|
|
35
|
+
|
|
36
|
+
// dist/builtin/workflows/src/workflows/identity.ts
|
|
37
|
+
function normalizeWorkflowName(name) {
|
|
38
|
+
if (!name || typeof name !== "string") {
|
|
39
|
+
throw new TypeError("normalizeWorkflowName: name must be a non-empty string");
|
|
40
|
+
}
|
|
41
|
+
return name.trim().toLowerCase().replace(/[\s_]+/g, "-").replace(/[^a-z0-9-]/g, "").replace(/-{2,}/g, "-").replace(/^-|-$/g, "");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// dist/builtin/workflows/src/authoring/workflow.ts
|
|
45
|
+
var BRANDED_WORKFLOW_DEFINITIONS = new WeakSet;
|
|
46
|
+
function stampWorkflowDefinition(definition) {
|
|
47
|
+
BRANDED_WORKFLOW_DEFINITIONS.add(definition);
|
|
48
|
+
return definition;
|
|
49
|
+
}
|
|
50
|
+
function requireNonEmptyString(value, label) {
|
|
51
|
+
if (value.trim().length === 0) {
|
|
52
|
+
throw new TypeError(`workflow: ${label} must be a non-empty string`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function freezeSchemaMap(schemas) {
|
|
56
|
+
return Object.freeze({ ...schemas });
|
|
57
|
+
}
|
|
58
|
+
function stackFilePath(line) {
|
|
59
|
+
const fileUrlMatch = line.match(/\(?((?:file:\/\/)[^\s)]+?\.[cm]?[jt]sx?):\d+:\d+\)?/);
|
|
60
|
+
const rawPath = fileUrlMatch?.[1] ?? line.match(/\(?((?:\/|[A-Za-z]:[\\/])[^():]+?\.[cm]?[jt]sx?):\d+:\d+\)?/)?.[1];
|
|
61
|
+
if (rawPath === undefined)
|
|
62
|
+
return;
|
|
63
|
+
if (!rawPath.startsWith("file://"))
|
|
64
|
+
return rawPath;
|
|
65
|
+
try {
|
|
66
|
+
return fileURLToPath(rawPath);
|
|
67
|
+
} catch {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function isWorkflowAuthoringImplementationFrame(filePath) {
|
|
72
|
+
const normalized = filePath.replace(/\\/g, "/");
|
|
73
|
+
if (!/\/authoring\/workflow\.[cm]?[jt]sx?$/.test(normalized))
|
|
74
|
+
return false;
|
|
75
|
+
return normalized.includes("/packages/workflows/") || normalized.includes("/node_modules/@bastani/workflows/") || normalized.includes("/dist/builtin/workflows/") || normalized.includes("/.atomic/agent/extensions/workflows/") || normalized.includes("/.pi/agent/extensions/workflows/");
|
|
76
|
+
}
|
|
77
|
+
function workflowNameFromCaller() {
|
|
78
|
+
const stack = new Error().stack;
|
|
79
|
+
if (stack === undefined)
|
|
80
|
+
return;
|
|
81
|
+
for (const line of stack.split(`
|
|
82
|
+
`)) {
|
|
83
|
+
const filePath = stackFilePath(line);
|
|
84
|
+
if (filePath === undefined)
|
|
85
|
+
continue;
|
|
86
|
+
if (isWorkflowAuthoringImplementationFrame(filePath))
|
|
87
|
+
continue;
|
|
88
|
+
const base = basename(filePath.replace(/\\/g, "/")).replace(/\.[cm]?[jt]sx?$/, "");
|
|
89
|
+
if (base.length > 0)
|
|
90
|
+
return base;
|
|
91
|
+
}
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
function resolveWorkflowName(name) {
|
|
95
|
+
const resolved = name ?? workflowNameFromCaller();
|
|
96
|
+
if (resolved === undefined) {
|
|
97
|
+
throw new TypeError("workflow: name must be provided when caller filename cannot be inferred");
|
|
98
|
+
}
|
|
99
|
+
requireNonEmptyString(resolved, "name");
|
|
100
|
+
return resolved;
|
|
101
|
+
}
|
|
102
|
+
function freezeInputBindings(binding) {
|
|
103
|
+
if (binding === undefined)
|
|
104
|
+
return;
|
|
105
|
+
return Object.freeze({
|
|
106
|
+
worktree: Object.freeze({ ...binding })
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
function freezeBudget(budget) {
|
|
110
|
+
return budget === undefined ? undefined : Object.freeze({ ...budget });
|
|
111
|
+
}
|
|
112
|
+
function workflow(spec) {
|
|
113
|
+
const specRun = spec.run;
|
|
114
|
+
if (typeof spec.description !== "string") {
|
|
115
|
+
throw new TypeError("workflow: description must be a string");
|
|
116
|
+
}
|
|
117
|
+
if (typeof specRun !== "function") {
|
|
118
|
+
throw new TypeError("workflow: run must be a function");
|
|
119
|
+
}
|
|
120
|
+
if (spec.outputs === undefined || spec.outputs === null || typeof spec.outputs !== "object" || Array.isArray(spec.outputs)) {
|
|
121
|
+
throw new TypeError("workflow: outputs must be a schema map");
|
|
122
|
+
}
|
|
123
|
+
if (spec.inputs !== undefined && (spec.inputs === null || typeof spec.inputs !== "object" || Array.isArray(spec.inputs))) {
|
|
124
|
+
throw new TypeError("workflow: inputs must be a schema map");
|
|
125
|
+
}
|
|
126
|
+
const heartbeatIntervalMinutes = spec.heartbeatIntervalMinutes === undefined ? DEFAULT_WORKFLOW_HEARTBEAT_INTERVAL_MINUTES : spec.heartbeatIntervalMinutes;
|
|
127
|
+
if (!Number.isFinite(heartbeatIntervalMinutes) || heartbeatIntervalMinutes < 0) {
|
|
128
|
+
throw new TypeError("workflow: heartbeatIntervalMinutes must be a non-negative finite number");
|
|
129
|
+
}
|
|
130
|
+
assertWorkflowBudget(spec.budget, "workflow: budget");
|
|
131
|
+
const name = resolveWorkflowName(spec.name);
|
|
132
|
+
const normalizedName = normalizeWorkflowName(name);
|
|
133
|
+
requireNonEmptyString(normalizedName, "normalized name");
|
|
134
|
+
const frozenInputs = freezeSchemaMap(spec.inputs ?? {});
|
|
135
|
+
const frozenOutputs = freezeSchemaMap(spec.outputs);
|
|
136
|
+
const inputBindings = freezeInputBindings(spec.worktreeFromInputs);
|
|
137
|
+
const budget = freezeBudget(spec.budget);
|
|
138
|
+
const run = async (ctx) => specRun(ctx);
|
|
139
|
+
const definition = {
|
|
140
|
+
__piWorkflow: true,
|
|
141
|
+
name,
|
|
142
|
+
normalizedName,
|
|
143
|
+
description: spec.description,
|
|
144
|
+
...spec.autoAttach === true ? { autoAttach: true } : {},
|
|
145
|
+
heartbeatIntervalMinutes,
|
|
146
|
+
inputs: frozenInputs,
|
|
147
|
+
outputs: frozenOutputs,
|
|
148
|
+
...inputBindings !== undefined ? { inputBindings } : {},
|
|
149
|
+
...budget !== undefined ? { budget } : {},
|
|
150
|
+
run
|
|
151
|
+
};
|
|
152
|
+
const branded = stampWorkflowDefinition(definition);
|
|
153
|
+
return Object.freeze(branded);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export { workflow };
|
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
import {
|
|
2
|
+
stableArtifactRoot
|
|
3
|
+
} from "./chunk-wpckd35c.js";
|
|
4
|
+
import {
|
|
5
|
+
classify_trend,
|
|
6
|
+
score_progress
|
|
7
|
+
} from "./chunk-6fqs7c01.js";
|
|
8
|
+
import {
|
|
9
|
+
workflow
|
|
10
|
+
} from "./chunk-bfkmzv9h.js";
|
|
11
|
+
import {
|
|
12
|
+
withSteeringPropagationContext
|
|
13
|
+
} from "./chunk-0x6e303p.js";
|
|
14
|
+
|
|
15
|
+
// dist/builtin/workflows/builtin/loop-until-done.ts
|
|
16
|
+
import { Type as Type2 } from "typebox";
|
|
17
|
+
|
|
18
|
+
// dist/builtin/workflows/builtin/loop-until-done-runner.ts
|
|
19
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
20
|
+
import { join } from "node:path";
|
|
21
|
+
import { Type } from "typebox";
|
|
22
|
+
|
|
23
|
+
// dist/builtin/workflows/builtin/loop-until-done-prompts.ts
|
|
24
|
+
var GROUNDED_REPORTING = "Before reporting progress, audit each claim against a tool result from this session. Report only work you can point to evidence for; say so explicitly when something is unverified.";
|
|
25
|
+
var READABLE_REPORT = "Lead with the outcome. Keep facts, decisions, caveats, and next steps; drop background and repetition. Use complete, readable sentences rather than compressed fragments.";
|
|
26
|
+
function taggedPrompt(sections) {
|
|
27
|
+
return sections.map(([tag, content]) => `<${tag}>
|
|
28
|
+
${content.trim()}
|
|
29
|
+
</${tag}>`).join(`
|
|
30
|
+
|
|
31
|
+
`);
|
|
32
|
+
}
|
|
33
|
+
function renderIterationPrompt(options) {
|
|
34
|
+
return taggedPrompt([
|
|
35
|
+
["progress_ledger", `Read ${options.ledgerPath} first. It is the durable source of truth for attempted work, findings, failures, validation evidence, and remaining work.`],
|
|
36
|
+
["role", "You are the active worker in a bounded evidence-driven completion loop."],
|
|
37
|
+
["iteration", `${options.iteration} of ${options.maxIterations}`],
|
|
38
|
+
["success_criteria", "This iteration makes measurable progress or supplies decisive evidence that the explicit objective is complete."],
|
|
39
|
+
["requirements", [
|
|
40
|
+
"Select the highest-value unfinished item supported by the ledger and current state.",
|
|
41
|
+
"Perform concrete work; do not merely restate the objective or ledger.",
|
|
42
|
+
"Avoid repeating failed approaches unless new evidence justifies the retry.",
|
|
43
|
+
"Run the strongest practical validation for the work completed in this iteration.",
|
|
44
|
+
"Report exactly what changed, evidence gathered, failures encountered, and what remains.",
|
|
45
|
+
GROUNDED_REPORTING
|
|
46
|
+
].join(`
|
|
47
|
+
`)],
|
|
48
|
+
["stop_rules", "End this iteration after delivering measurable progress, or after evidence shows the objective is complete."],
|
|
49
|
+
["output_format", `Markdown with Work performed, Changes, Validation evidence, New findings, Failures, and Remaining work. ${READABLE_REPORT}`],
|
|
50
|
+
["objective", options.task]
|
|
51
|
+
]);
|
|
52
|
+
}
|
|
53
|
+
function renderEvaluationPrompt(options) {
|
|
54
|
+
return taggedPrompt([
|
|
55
|
+
["artifacts", [
|
|
56
|
+
`Durable progress ledger: ${options.ledgerPath}`,
|
|
57
|
+
`Current iteration artifact: ${options.iterationPath}`,
|
|
58
|
+
"Read both files before deciding."
|
|
59
|
+
].join(`
|
|
60
|
+
`)],
|
|
61
|
+
["role", "You are an independent completion evaluator. Judge evidence, not the worker's confidence."],
|
|
62
|
+
["stop_condition", [
|
|
63
|
+
"Set done=true only when the objective is fully satisfied and current validation evidence proves it.",
|
|
64
|
+
"Set done=false when any required behavior, validation, cleanup, or evidence remains missing or uncertain.",
|
|
65
|
+
"Do not invent requirements beyond the objective."
|
|
66
|
+
].join(`
|
|
67
|
+
`)],
|
|
68
|
+
["evidence_rules", [
|
|
69
|
+
"List concrete validation evidence supporting the decision, including commands and observed output; cite file:line where applicable.",
|
|
70
|
+
"Record new findings and failures distinctly.",
|
|
71
|
+
"When incomplete, state actionable remaining work for the next iteration.",
|
|
72
|
+
GROUNDED_REPORTING
|
|
73
|
+
].join(`
|
|
74
|
+
`)],
|
|
75
|
+
["success_criteria", `The iteration ${options.iteration} decision is reproducible from cited artifact evidence.`],
|
|
76
|
+
["output_format", `Return only the required structured decision with done, summary, new_findings, failures, validation_evidence, and remaining_work. ${READABLE_REPORT}`],
|
|
77
|
+
["objective", options.task]
|
|
78
|
+
]);
|
|
79
|
+
}
|
|
80
|
+
function renderCompletionPrompt(options) {
|
|
81
|
+
return taggedPrompt([
|
|
82
|
+
["artifacts", `Read the complete ledger at ${options.ledgerPath} and final iteration artifact at ${options.iterationPath}.`],
|
|
83
|
+
["role", "You are the final completion reporter."],
|
|
84
|
+
["requirements", [
|
|
85
|
+
"Summarize the delivered outcome without adding unsupported claims.",
|
|
86
|
+
"Cite the validation evidence that satisfied the stop condition.",
|
|
87
|
+
"List artifact paths needed to audit the work.",
|
|
88
|
+
"Report residual risks even when no work remains.",
|
|
89
|
+
GROUNDED_REPORTING
|
|
90
|
+
].join(`
|
|
91
|
+
`)],
|
|
92
|
+
["success_criteria", "The final report is evidence-backed and independently auditable from the ledger."],
|
|
93
|
+
["stop_rules", "Stop after accounting for the outcome, supporting evidence, audit artifacts, residual risks, and any remaining work."],
|
|
94
|
+
["output_format", `Markdown with Outcome, Evidence, Artifacts, Residual risks, and Remaining work (None). ${READABLE_REPORT}`],
|
|
95
|
+
["objective", options.task]
|
|
96
|
+
]);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// dist/builtin/workflows/builtin/loop-until-done-runner.ts
|
|
100
|
+
var PROGRESS_DISCLAIMER = "Progress scores are a monitoring signal; VOC separation +0.079; never authoritative.";
|
|
101
|
+
var evaluationSchema = Type.Object({
|
|
102
|
+
done: Type.Boolean(),
|
|
103
|
+
summary: Type.String(),
|
|
104
|
+
new_findings: Type.Array(Type.String()),
|
|
105
|
+
failures: Type.Array(Type.String()),
|
|
106
|
+
validation_evidence: Type.Array(Type.String()),
|
|
107
|
+
remaining_work: Type.String()
|
|
108
|
+
}, { additionalProperties: false });
|
|
109
|
+
function progressCurve(entries) {
|
|
110
|
+
return entries.flatMap((entry) => entry.progress === undefined ? [] : [entry.progress.score]);
|
|
111
|
+
}
|
|
112
|
+
function progressReport(entries) {
|
|
113
|
+
const curve = progressCurve(entries);
|
|
114
|
+
return { curve, trend: classify_trend(curve).trend };
|
|
115
|
+
}
|
|
116
|
+
function formatProgressReport(report) {
|
|
117
|
+
return [
|
|
118
|
+
`Progress curve: ${JSON.stringify(report.curve)}`,
|
|
119
|
+
`Final trend: ${report.trend}`,
|
|
120
|
+
PROGRESS_DISCLAIMER
|
|
121
|
+
].join(`
|
|
122
|
+
`);
|
|
123
|
+
}
|
|
124
|
+
function repeatCount(input) {
|
|
125
|
+
const repeats = input.progress_repeats;
|
|
126
|
+
return typeof repeats === "number" && Number.isInteger(repeats) && repeats > 0 ? repeats : 1;
|
|
127
|
+
}
|
|
128
|
+
async function scoreIteration(ctx, task, entries, repeats) {
|
|
129
|
+
try {
|
|
130
|
+
const curve = await score_progress(ctx, {
|
|
131
|
+
problem: task,
|
|
132
|
+
steps: entries.map((entry) => entry.summary),
|
|
133
|
+
checkpoints: [entries.length],
|
|
134
|
+
repeats
|
|
135
|
+
});
|
|
136
|
+
const score = curve.scores[0];
|
|
137
|
+
if (score === null || score === undefined)
|
|
138
|
+
return;
|
|
139
|
+
const trend = classify_trend([...progressCurve(entries), score]);
|
|
140
|
+
return {
|
|
141
|
+
score,
|
|
142
|
+
perRepeat: curve.perRepeat,
|
|
143
|
+
trend: trend.trend,
|
|
144
|
+
window: trend.evidence.window
|
|
145
|
+
};
|
|
146
|
+
} catch {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function serializableObject(value) {
|
|
151
|
+
if (value === null || Array.isArray(value) || typeof value !== "object")
|
|
152
|
+
return;
|
|
153
|
+
return value;
|
|
154
|
+
}
|
|
155
|
+
function stringArray(value) {
|
|
156
|
+
return Array.isArray(value) && value.every((item) => typeof item === "string") ? value : undefined;
|
|
157
|
+
}
|
|
158
|
+
function evaluationFrom(result) {
|
|
159
|
+
const value = serializableObject(result.structured);
|
|
160
|
+
if (value === undefined) {
|
|
161
|
+
throw new Error(`loop-until-done: evaluator ${result.stageName} did not return a structured decision`);
|
|
162
|
+
}
|
|
163
|
+
const done = value.done;
|
|
164
|
+
const summary = value.summary;
|
|
165
|
+
const newFindings = stringArray(value.new_findings);
|
|
166
|
+
const failures = stringArray(value.failures);
|
|
167
|
+
const validationEvidence = stringArray(value.validation_evidence);
|
|
168
|
+
const remainingWork = value.remaining_work;
|
|
169
|
+
if (typeof done !== "boolean" || typeof summary !== "string" || newFindings === undefined || failures === undefined || validationEvidence === undefined || typeof remainingWork !== "string") {
|
|
170
|
+
throw new Error(`loop-until-done: evaluator ${result.stageName} returned an invalid decision`);
|
|
171
|
+
}
|
|
172
|
+
return { done, summary, newFindings, failures, validationEvidence, remainingWork };
|
|
173
|
+
}
|
|
174
|
+
async function writeLedger(path, task, maxIterations, status, entries) {
|
|
175
|
+
const report = progressReport(entries);
|
|
176
|
+
await writeFile(path, `${JSON.stringify({
|
|
177
|
+
task,
|
|
178
|
+
max_iterations: maxIterations,
|
|
179
|
+
status,
|
|
180
|
+
iterations_completed: entries.length,
|
|
181
|
+
entries,
|
|
182
|
+
progress_curve: report.curve,
|
|
183
|
+
final_trend: report.trend,
|
|
184
|
+
progress_disclaimer: PROGRESS_DISCLAIMER
|
|
185
|
+
}, null, 2)}
|
|
186
|
+
`);
|
|
187
|
+
}
|
|
188
|
+
async function runLoopUntilDone(ctx) {
|
|
189
|
+
const artifactDir = await stableArtifactRoot(ctx, "loop-until-done");
|
|
190
|
+
const iterationsDir = join(artifactDir, "iterations");
|
|
191
|
+
const evaluationsDir = join(artifactDir, "evaluations");
|
|
192
|
+
await mkdir(iterationsDir, { recursive: true });
|
|
193
|
+
await mkdir(evaluationsDir, { recursive: true });
|
|
194
|
+
const ledgerPath = join(artifactDir, "progress-ledger.json");
|
|
195
|
+
const entries = [];
|
|
196
|
+
const iterationArtifactPaths = [];
|
|
197
|
+
const evaluationArtifactPaths = [];
|
|
198
|
+
await writeLedger(ledgerPath, ctx.inputs.prompt, ctx.inputs.max_iterations, "active", entries);
|
|
199
|
+
for (let iteration = 1;iteration <= ctx.inputs.max_iterations; iteration += 1) {
|
|
200
|
+
const iterationPath = join(iterationsDir, `iteration-${iteration}.md`);
|
|
201
|
+
const evaluationPath = join(evaluationsDir, `evaluation-${iteration}.json`);
|
|
202
|
+
iterationArtifactPaths.push(iterationPath);
|
|
203
|
+
evaluationArtifactPaths.push(evaluationPath);
|
|
204
|
+
await ctx.task(`iteration-${iteration}`, {
|
|
205
|
+
prompt: renderIterationPrompt({
|
|
206
|
+
task: ctx.inputs.prompt,
|
|
207
|
+
iteration,
|
|
208
|
+
maxIterations: ctx.inputs.max_iterations,
|
|
209
|
+
ledgerPath
|
|
210
|
+
}),
|
|
211
|
+
context: "fresh",
|
|
212
|
+
reads: [ledgerPath, ...iteration > 1 ? [iterationArtifactPaths[iteration - 2]] : []],
|
|
213
|
+
output: iterationPath,
|
|
214
|
+
outputMode: "file-only"
|
|
215
|
+
});
|
|
216
|
+
const evaluator = await ctx.task(`evaluate-${iteration}`, {
|
|
217
|
+
prompt: renderEvaluationPrompt({
|
|
218
|
+
task: ctx.inputs.prompt,
|
|
219
|
+
iteration,
|
|
220
|
+
ledgerPath,
|
|
221
|
+
iterationPath
|
|
222
|
+
}),
|
|
223
|
+
context: "fresh",
|
|
224
|
+
reads: [ledgerPath, iterationPath],
|
|
225
|
+
schema: evaluationSchema
|
|
226
|
+
});
|
|
227
|
+
const decision = evaluationFrom(evaluator);
|
|
228
|
+
await writeFile(evaluationPath, `${JSON.stringify(evaluator.structured, null, 2)}
|
|
229
|
+
`);
|
|
230
|
+
const entry = {
|
|
231
|
+
iteration,
|
|
232
|
+
artifact_path: iterationPath,
|
|
233
|
+
evaluation_artifact_path: evaluationPath,
|
|
234
|
+
summary: decision.summary,
|
|
235
|
+
findings: decision.newFindings,
|
|
236
|
+
failures: decision.failures,
|
|
237
|
+
validation_evidence: decision.validationEvidence,
|
|
238
|
+
done: decision.done,
|
|
239
|
+
remaining_work: decision.remainingWork
|
|
240
|
+
};
|
|
241
|
+
entries.push(entry);
|
|
242
|
+
if (ctx.inputs.progress_scoring !== false) {
|
|
243
|
+
const progress = await scoreIteration(ctx, ctx.inputs.prompt, entries, repeatCount(ctx.inputs));
|
|
244
|
+
if (progress !== undefined)
|
|
245
|
+
entries[entries.length - 1] = { ...entry, progress };
|
|
246
|
+
}
|
|
247
|
+
await writeLedger(ledgerPath, ctx.inputs.prompt, ctx.inputs.max_iterations, decision.done ? "complete" : "active", entries);
|
|
248
|
+
if (decision.done) {
|
|
249
|
+
const report2 = progressReport(entries);
|
|
250
|
+
const resultPath = join(artifactDir, "result.md");
|
|
251
|
+
const final = await ctx.task("completion-summary", {
|
|
252
|
+
prompt: renderCompletionPrompt({ task: ctx.inputs.prompt, ledgerPath, iterationPath }),
|
|
253
|
+
context: "fresh",
|
|
254
|
+
reads: [ledgerPath, iterationPath],
|
|
255
|
+
output: resultPath,
|
|
256
|
+
outputMode: "file-only"
|
|
257
|
+
});
|
|
258
|
+
const result2 = `${final.text ? `${final.text.trimEnd()}
|
|
259
|
+
|
|
260
|
+
` : ""}${formatProgressReport(report2)}
|
|
261
|
+
`;
|
|
262
|
+
return {
|
|
263
|
+
result: result2,
|
|
264
|
+
status: "complete",
|
|
265
|
+
iterations_completed: iteration,
|
|
266
|
+
ledger_path: ledgerPath,
|
|
267
|
+
iteration_artifact_paths: iterationArtifactPaths,
|
|
268
|
+
evaluation_artifact_paths: evaluationArtifactPaths,
|
|
269
|
+
result_path: resultPath,
|
|
270
|
+
remaining_work: "",
|
|
271
|
+
artifact_dir: artifactDir,
|
|
272
|
+
progress_curve: report2.curve,
|
|
273
|
+
final_trend: report2.trend,
|
|
274
|
+
progress_disclaimer: PROGRESS_DISCLAIMER
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
const last = entries.at(-1);
|
|
279
|
+
const report = progressReport(entries);
|
|
280
|
+
await writeLedger(ledgerPath, ctx.inputs.prompt, ctx.inputs.max_iterations, "failed", entries);
|
|
281
|
+
const result = [
|
|
282
|
+
`Iteration limit exhausted after ${ctx.inputs.max_iterations} iterations. Inspect ${ledgerPath}.`,
|
|
283
|
+
formatProgressReport(report)
|
|
284
|
+
].join(`
|
|
285
|
+
|
|
286
|
+
`);
|
|
287
|
+
return {
|
|
288
|
+
result,
|
|
289
|
+
status: "failed",
|
|
290
|
+
iterations_completed: ctx.inputs.max_iterations,
|
|
291
|
+
ledger_path: ledgerPath,
|
|
292
|
+
iteration_artifact_paths: iterationArtifactPaths,
|
|
293
|
+
evaluation_artifact_paths: evaluationArtifactPaths,
|
|
294
|
+
result_path: ledgerPath,
|
|
295
|
+
remaining_work: last.remaining_work,
|
|
296
|
+
artifact_dir: artifactDir,
|
|
297
|
+
progress_curve: report.curve,
|
|
298
|
+
final_trend: report.trend,
|
|
299
|
+
progress_disclaimer: PROGRESS_DISCLAIMER
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// dist/builtin/workflows/builtin/loop-until-done.ts
|
|
304
|
+
var loop_until_done_default = workflow({
|
|
305
|
+
name: "loop-until-done",
|
|
306
|
+
description: "Repeat evidence-producing work and independent completion evaluation against a durable ledger until done or an inspectable iteration-limit failure.",
|
|
307
|
+
heartbeatIntervalMinutes: 15,
|
|
308
|
+
inputs: {
|
|
309
|
+
prompt: Type2.String({ description: "Objective whose explicit completion condition controls the bounded loop." }),
|
|
310
|
+
max_iterations: Type2.Integer({
|
|
311
|
+
minimum: 1,
|
|
312
|
+
maximum: 20,
|
|
313
|
+
default: 5,
|
|
314
|
+
description: "Maximum work/evaluation iterations before returning an inspectable failed status (1-20)."
|
|
315
|
+
}),
|
|
316
|
+
progress_scoring: Type2.Boolean({
|
|
317
|
+
default: true,
|
|
318
|
+
description: "Enable advisory progress scoring after each completed iteration."
|
|
319
|
+
}),
|
|
320
|
+
progress_repeats: Type2.Integer({
|
|
321
|
+
minimum: 1,
|
|
322
|
+
default: 1,
|
|
323
|
+
description: "Number of advisory progress-scoring repeats per iteration."
|
|
324
|
+
})
|
|
325
|
+
},
|
|
326
|
+
outputs: {
|
|
327
|
+
result: Type2.String({ description: "Compact reference to the evidence-backed completion report, or the deterministic exhaustion report; read `result_path` for the full report." }),
|
|
328
|
+
status: Type2.Union([Type2.Literal("complete"), Type2.Literal("failed")], {
|
|
329
|
+
description: "Complete when evidence satisfies the stop condition; failed when max_iterations is exhausted."
|
|
330
|
+
}),
|
|
331
|
+
iterations_completed: Type2.Integer({ description: "Number of completed work/evaluation iterations." }),
|
|
332
|
+
ledger_path: Type2.String({ description: "Path to the durable JSON progress ledger." }),
|
|
333
|
+
iteration_artifact_paths: Type2.Array(Type2.String(), { description: "Ordered paths to per-iteration work artifacts." }),
|
|
334
|
+
evaluation_artifact_paths: Type2.Array(Type2.String(), { description: "Ordered paths to structured evaluation artifacts." }),
|
|
335
|
+
result_path: Type2.String({ description: "Path to the final report, or the ledger on exhausted failure." }),
|
|
336
|
+
remaining_work: Type2.String({ description: "Actionable remaining work; empty only after proven completion." }),
|
|
337
|
+
artifact_dir: Type2.String({ description: "Run-specific directory containing loop artifacts." }),
|
|
338
|
+
progress_curve: Type2.Array(Type2.Number(), { description: "Advisory progress scores in iteration order." }),
|
|
339
|
+
final_trend: Type2.Union([Type2.Literal("rising"), Type2.Literal("flat"), Type2.Literal("regressing")], { description: "Final advisory trend classification; never a stop decision." }),
|
|
340
|
+
progress_disclaimer: Type2.String({ description: "Calibration disclaimer for the advisory progress signal." })
|
|
341
|
+
},
|
|
342
|
+
run: async (ctx) => await runLoopUntilDone(withSteeringPropagationContext(ctx))
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
export { loop_until_done_default };
|