ai-engineering-loop 1.2.1 → 1.6.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.
- package/README.md +47 -4
- package/README.npm.md +7 -0
- package/SECURITY.md +3 -1
- package/agents/recipe-builder.md +28 -0
- package/bin/ai-engineering-loop.js +432 -11
- package/core/controlled-workflow-runtime.md +77 -0
- package/core/local-workflow-studio.md +77 -0
- package/core/workflow-recipes.md +140 -0
- package/lib/budget.js +42 -4
- package/lib/doctor.js +26 -2
- package/lib/handoff.js +209 -0
- package/lib/node-registry.js +155 -0
- package/lib/recipe-builder.js +200 -0
- package/lib/recipe.js +495 -0
- package/lib/run-state.js +50 -3
- package/lib/runtime-files.js +2 -0
- package/lib/studio-server.js +183 -0
- package/lib/workflow-runtime.js +718 -0
- package/package.json +3 -1
- package/recipes/audit.json +32 -0
- package/recipes/bugfix.json +63 -0
- package/recipes/default.json +49 -0
- package/recipes/docs-light.json +63 -0
- package/recipes/high-risk.json +69 -0
- package/recipes/refactor.json +63 -0
- package/schemas/compiled-plan.schema.json +19 -0
- package/schemas/handoff.schema.json +36 -0
- package/schemas/node-definition.schema.json +33 -0
- package/schemas/recipe.schema.json +26 -0
- package/schemas/workflow-event.schema.json +29 -0
- package/schemas/workflow-state.schema.json +29 -0
- package/studio/app.js +461 -0
- package/studio/index.html +31 -0
- package/studio/styles.css +75 -0
package/studio/app.js
ADDED
|
@@ -0,0 +1,461 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
let catalog;
|
|
4
|
+
let draft;
|
|
5
|
+
let source;
|
|
6
|
+
let selectedId;
|
|
7
|
+
let liveTimer;
|
|
8
|
+
let validationSequence = 0;
|
|
9
|
+
|
|
10
|
+
const byId = (id) => document.getElementById(id);
|
|
11
|
+
const escapeHtml = (value) => String(value ?? '').replace(
|
|
12
|
+
/[&<>"']/g,
|
|
13
|
+
(character) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[character]
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
async function api(url, options = {}) {
|
|
17
|
+
const response = await fetch(url, {
|
|
18
|
+
...options,
|
|
19
|
+
headers: { 'content-type': 'application/json', ...(options.headers || {}) }
|
|
20
|
+
});
|
|
21
|
+
const payload = await response.json();
|
|
22
|
+
if (!response.ok || !payload.ok) {
|
|
23
|
+
const error = new Error(payload.error || payload.validation?.errors?.join('; ') || 'Request failed');
|
|
24
|
+
error.payload = payload;
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
27
|
+
return payload;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function recipeSummary() {
|
|
31
|
+
return catalog.recipes.find((recipe) => recipe.id === draft.id);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function renderRecipeDetails() {
|
|
35
|
+
const existing = recipeSummary();
|
|
36
|
+
byId('inspector-label').textContent = 'RECIPE INSPECTOR';
|
|
37
|
+
byId('details').innerHTML = `
|
|
38
|
+
<div class="source-line"><span>${source.toUpperCase()}</span><span>${draft.nodes.length} NODES</span></div>
|
|
39
|
+
<label for="recipe-id">RECIPE ID</label>
|
|
40
|
+
<input id="recipe-id" value="${escapeHtml(draft.id)}">
|
|
41
|
+
<label for="recipe-version">VERSION</label>
|
|
42
|
+
<input id="recipe-version" type="number" min="1" value="${escapeHtml(draft.version)}">
|
|
43
|
+
<label for="recipe-description">DESCRIPTION</label>
|
|
44
|
+
<textarea id="recipe-description">${escapeHtml(draft.description)}</textarea>
|
|
45
|
+
<label for="recipe-modes">COMPATIBLE MODES</label>
|
|
46
|
+
<select id="recipe-modes" multiple>
|
|
47
|
+
${['REPORT_ONLY', 'ASSISTED', 'UNATTENDED'].map((mode) => (
|
|
48
|
+
`<option ${draft.compatibleModes.includes(mode) ? 'selected' : ''}>${mode}</option>`
|
|
49
|
+
)).join('')}
|
|
50
|
+
</select>
|
|
51
|
+
${existing?.source === 'builtin' ? '<p class="hint">Change the recipe ID to fork this protected preset.</p>' : ''}
|
|
52
|
+
<button id="apply-recipe">APPLY METADATA</button>
|
|
53
|
+
`;
|
|
54
|
+
byId('apply-recipe').onclick = applyRecipeDetails;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function applyRecipeDetails() {
|
|
58
|
+
draft.id = byId('recipe-id').value.trim();
|
|
59
|
+
draft.version = Number(byId('recipe-version').value);
|
|
60
|
+
draft.description = byId('recipe-description').value.trim();
|
|
61
|
+
draft.compatibleModes = [...byId('recipe-modes').selectedOptions].map((option) => option.value);
|
|
62
|
+
renderGraph();
|
|
63
|
+
renderRecipeDetails();
|
|
64
|
+
validateDraft();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function graphPositions() {
|
|
68
|
+
const depths = new Map();
|
|
69
|
+
const visiting = new Set();
|
|
70
|
+
const depthFor = (node) => {
|
|
71
|
+
if (depths.has(node.id)) return depths.get(node.id);
|
|
72
|
+
if (visiting.has(node.id)) return 0;
|
|
73
|
+
visiting.add(node.id);
|
|
74
|
+
const depth = (node.dependsOn || []).reduce((maximum, dependencyId) => {
|
|
75
|
+
const dependency = draft.nodes.find((candidate) => candidate.id === dependencyId);
|
|
76
|
+
return Math.max(maximum, dependency ? depthFor(dependency) + 1 : 0);
|
|
77
|
+
}, 0);
|
|
78
|
+
visiting.delete(node.id);
|
|
79
|
+
depths.set(node.id, depth);
|
|
80
|
+
return depth;
|
|
81
|
+
};
|
|
82
|
+
const rows = new Map();
|
|
83
|
+
return new Map(draft.nodes.map((node) => {
|
|
84
|
+
const depth = depthFor(node);
|
|
85
|
+
const row = rows.get(depth) || 0;
|
|
86
|
+
rows.set(depth, row + 1);
|
|
87
|
+
return [node.id, { x: 90 + depth * 300, y: 125 + row * 150 }];
|
|
88
|
+
}));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function renderGraph() {
|
|
92
|
+
const positions = graphPositions();
|
|
93
|
+
const container = byId('nodes');
|
|
94
|
+
container.innerHTML = '';
|
|
95
|
+
draft.nodes.forEach((node, index) => {
|
|
96
|
+
const position = positions.get(node.id);
|
|
97
|
+
const runtimeNode = catalog.live?.nodes?.[node.id];
|
|
98
|
+
const element = document.createElement('article');
|
|
99
|
+
element.className = `node ${runtimeNode?.status.toLowerCase() || ''} ${selectedId === node.id ? 'selected' : ''}`;
|
|
100
|
+
element.style.left = `${position.x}px`;
|
|
101
|
+
element.style.top = `${position.y}px`;
|
|
102
|
+
element.innerHTML = `
|
|
103
|
+
<small>${String(index + 1).padStart(2, '0')} / ${escapeHtml(node.type.toUpperCase())}</small>
|
|
104
|
+
<h3>${escapeHtml(node.id)}</h3>
|
|
105
|
+
<span class="status">● ${runtimeNode?.status || 'DRAFT'}</span>
|
|
106
|
+
${runtimeNode?.activity ? `<p class="node-activity">${escapeHtml(runtimeNode.activity)}</p>` : ''}
|
|
107
|
+
`;
|
|
108
|
+
element.onclick = (event) => {
|
|
109
|
+
event.stopPropagation();
|
|
110
|
+
selectNode(node.id);
|
|
111
|
+
};
|
|
112
|
+
container.append(element);
|
|
113
|
+
});
|
|
114
|
+
renderEdges(positions);
|
|
115
|
+
byId('mode').textContent = `${draft.compatibleModes.join(' · ') || 'NO MODE'} / EDIT MODE`;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function renderEdges(positions) {
|
|
119
|
+
const svg = byId('edges');
|
|
120
|
+
const group = byId('edge-paths');
|
|
121
|
+
const coordinates = [...positions.values()];
|
|
122
|
+
const width = Math.max(1200, ...coordinates.map((position) => position.x + 300));
|
|
123
|
+
const height = Math.max(900, ...coordinates.map((position) => position.y + 200));
|
|
124
|
+
svg.style.width = `${width}px`;
|
|
125
|
+
svg.style.height = `${height}px`;
|
|
126
|
+
group.innerHTML = '';
|
|
127
|
+
draft.nodes.forEach((node) => {
|
|
128
|
+
for (const dependencyId of node.dependsOn || []) {
|
|
129
|
+
const from = positions.get(dependencyId);
|
|
130
|
+
const to = positions.get(node.id);
|
|
131
|
+
if (!from || !to) continue;
|
|
132
|
+
const path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
|
|
133
|
+
path.setAttribute(
|
|
134
|
+
'd',
|
|
135
|
+
`M${from.x + 210} ${from.y + 52} C${from.x + 255} ${from.y + 52},${to.x - 45} ${to.y + 52},${to.x} ${to.y + 52}`
|
|
136
|
+
);
|
|
137
|
+
const active = catalog.live?.nodes?.[dependencyId]?.status === 'RUNNING';
|
|
138
|
+
path.setAttribute('class', active ? 'edge active' : 'edge');
|
|
139
|
+
path.setAttribute('marker-end', 'url(#arrow)');
|
|
140
|
+
group.append(path);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function selectNode(nodeId) {
|
|
146
|
+
selectedId = nodeId;
|
|
147
|
+
const node = draft.nodes.find((candidate) => candidate.id === nodeId);
|
|
148
|
+
const runtimeNode = catalog.live?.nodes?.[nodeId];
|
|
149
|
+
byId('inspector-label').textContent = 'NODE INSPECTOR';
|
|
150
|
+
byId('details').innerHTML = `
|
|
151
|
+
<div class="source-line"><span>${escapeHtml(node.type.toUpperCase())}</span><span>${runtimeNode?.status || 'DRAFT'}</span></div>
|
|
152
|
+
<label for="node-id">NODE ID</label>
|
|
153
|
+
<input id="node-id" value="${escapeHtml(node.id)}">
|
|
154
|
+
<label>TYPE</label>
|
|
155
|
+
<input value="${escapeHtml(node.type)}" disabled>
|
|
156
|
+
<label for="node-dependencies">DEPENDENCIES</label>
|
|
157
|
+
<input id="node-dependencies" value="${escapeHtml((node.dependsOn || []).join(', '))}" placeholder="goal, verification">
|
|
158
|
+
${node.type === 'agent' ? `
|
|
159
|
+
<label for="node-extra">ROLE</label><input id="node-extra" value="${escapeHtml(node.role || '')}">
|
|
160
|
+
<label for="node-tokens">MAX TOKENS</label><input id="node-tokens" type="number" min="1" value="${escapeHtml(node.context?.maxTokens || '')}">
|
|
161
|
+
` : node.type === 'approval' ? `
|
|
162
|
+
<label for="node-extra">APPROVAL MESSAGE</label><textarea id="node-extra">${escapeHtml(node.message || '')}</textarea>
|
|
163
|
+
` : node.type === 'condition' ? `
|
|
164
|
+
<label for="condition-field">CONDITION FIELD</label>
|
|
165
|
+
<select id="condition-field">${['run.mode', 'run.state', 'run.iteration', 'run.task'].map((field) => `<option ${node.expression?.field === field ? 'selected' : ''}>${field}</option>`).join('')}</select>
|
|
166
|
+
<label for="condition-operator">OPERATOR</label>
|
|
167
|
+
<select id="condition-operator">${['equals', 'notEquals', 'contains', 'exists', 'isEmpty', 'greaterThan', 'lessThan'].map((operator) => `<option ${node.expression?.operator === operator ? 'selected' : ''}>${operator}</option>`).join('')}</select>
|
|
168
|
+
<label for="condition-value">VALUE</label><input id="condition-value" value="${escapeHtml(node.expression?.value ?? '')}">
|
|
169
|
+
` : ''}
|
|
170
|
+
<div class="button-row"><button id="apply-node">APPLY NODE</button><button id="delete-node" class="danger">DELETE</button></div>
|
|
171
|
+
${runtimeControls(node, runtimeNode)}
|
|
172
|
+
`;
|
|
173
|
+
byId('apply-node').onclick = applyNodeDetails;
|
|
174
|
+
byId('delete-node').onclick = deleteSelectedNode;
|
|
175
|
+
bindRuntimeControls(node, runtimeNode);
|
|
176
|
+
renderGraph();
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function runtimeControls(node, runtimeNode) {
|
|
180
|
+
if (!catalog.live || !runtimeNode) return '';
|
|
181
|
+
const approve = node.type === 'approval' && runtimeNode.status === 'READY'
|
|
182
|
+
? '<button id="approve-node">APPROVE</button>'
|
|
183
|
+
: '';
|
|
184
|
+
const retry = ['FAILED', 'RUNNING'].includes(runtimeNode.status)
|
|
185
|
+
? '<button id="retry-node">RETRY</button>'
|
|
186
|
+
: '';
|
|
187
|
+
const activity = runtimeNode.status === 'RUNNING'
|
|
188
|
+
? '<label for="runtime-activity">SAFE ACTIVITY UPDATE</label><input id="runtime-activity" maxlength="240"><button id="send-activity">REPORT ACTIVITY</button>'
|
|
189
|
+
: '';
|
|
190
|
+
return approve || retry || activity
|
|
191
|
+
? `<section class="runtime-controls"><label>RUNTIME CONTROL</label>${activity}<div class="button-row">${approve}${retry}</div></section>`
|
|
192
|
+
: '';
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function bindRuntimeControls(node, runtimeNode) {
|
|
196
|
+
const runId = catalog.live?.run?.runId;
|
|
197
|
+
if (byId('approve-node')) byId('approve-node').onclick = () => mutateNode('/api/node/approve', { runId, nodeId: node.id });
|
|
198
|
+
if (byId('retry-node')) byId('retry-node').onclick = () => mutateNode('/api/node/retry', { runId, nodeId: node.id });
|
|
199
|
+
if (byId('send-activity')) {
|
|
200
|
+
byId('send-activity').onclick = () => mutateNode('/api/node/activity', {
|
|
201
|
+
runId,
|
|
202
|
+
nodeId: node.id,
|
|
203
|
+
message: byId('runtime-activity').value
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
async function mutateNode(endpoint, body) {
|
|
209
|
+
try {
|
|
210
|
+
await api(endpoint, { method: 'POST', body: JSON.stringify(body) });
|
|
211
|
+
await refreshLive();
|
|
212
|
+
if (selectedId) selectNode(selectedId);
|
|
213
|
+
} catch (error) {
|
|
214
|
+
notify(error.message);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function applyNodeDetails() {
|
|
219
|
+
const node = draft.nodes.find((candidate) => candidate.id === selectedId);
|
|
220
|
+
const previousId = node.id;
|
|
221
|
+
node.id = byId('node-id').value.trim();
|
|
222
|
+
node.dependsOn = byId('node-dependencies').value.split(',').map((value) => value.trim()).filter(Boolean);
|
|
223
|
+
draft.nodes.forEach((candidate) => {
|
|
224
|
+
candidate.dependsOn = (candidate.dependsOn || []).map((dependency) => dependency === previousId ? node.id : dependency);
|
|
225
|
+
});
|
|
226
|
+
if (node.type === 'agent') {
|
|
227
|
+
node.role = byId('node-extra').value.trim();
|
|
228
|
+
node.context = { ...(node.context || {}), maxTokens: Number(byId('node-tokens').value) };
|
|
229
|
+
} else if (node.type === 'approval') {
|
|
230
|
+
node.message = byId('node-extra').value.trim();
|
|
231
|
+
} else if (node.type === 'condition') {
|
|
232
|
+
const field = byId('condition-field').value;
|
|
233
|
+
const operator = byId('condition-operator').value;
|
|
234
|
+
const rawValue = byId('condition-value').value.trim();
|
|
235
|
+
node.expression = { field, operator };
|
|
236
|
+
if (!['exists', 'isEmpty'].includes(operator)) {
|
|
237
|
+
node.expression.value = field === 'run.iteration' || ['greaterThan', 'lessThan'].includes(operator)
|
|
238
|
+
? Number(rawValue)
|
|
239
|
+
: rawValue;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
selectedId = node.id;
|
|
243
|
+
renderGraph();
|
|
244
|
+
selectNode(node.id);
|
|
245
|
+
validateDraft();
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function deleteSelectedNode() {
|
|
249
|
+
if (!selectedId) return;
|
|
250
|
+
draft.nodes = draft.nodes.filter((node) => node.id !== selectedId);
|
|
251
|
+
draft.nodes.forEach((node) => {
|
|
252
|
+
node.dependsOn = (node.dependsOn || []).filter((dependency) => dependency !== selectedId);
|
|
253
|
+
});
|
|
254
|
+
selectedId = null;
|
|
255
|
+
renderGraph();
|
|
256
|
+
renderRecipeDetails();
|
|
257
|
+
validateDraft();
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function addNode(type) {
|
|
261
|
+
let suffix = draft.nodes.length + 1;
|
|
262
|
+
while (draft.nodes.some((node) => node.id === `${type}-${suffix}`)) suffix += 1;
|
|
263
|
+
const id = `${type}-${suffix}`;
|
|
264
|
+
const node = { id, type, dependsOn: [] };
|
|
265
|
+
if (type === 'agent') {
|
|
266
|
+
Object.assign(node, {
|
|
267
|
+
role: 'analyst',
|
|
268
|
+
context: { maxFiles: 10, maxTokens: 4000 },
|
|
269
|
+
output: { artifact: `${id}-output`, schema: 'schemas/report.schema.json' }
|
|
270
|
+
});
|
|
271
|
+
} else if (type === 'approval') {
|
|
272
|
+
node.message = 'Approve continuation.';
|
|
273
|
+
} else if (type === 'condition') {
|
|
274
|
+
node.expression = { field: 'run.mode', operator: 'equals', value: 'ASSISTED' };
|
|
275
|
+
}
|
|
276
|
+
draft.nodes.push(node);
|
|
277
|
+
selectNode(id);
|
|
278
|
+
validateDraft();
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function renderPalette() {
|
|
282
|
+
const excluded = new Set(['goal-contract', 'maker', 'verification', 'devil-advocate', 'judge', 'delivery', 'report']);
|
|
283
|
+
byId('palette').innerHTML = catalog.nodeTypes
|
|
284
|
+
.filter((node) => node.executable && !excluded.has(node.type))
|
|
285
|
+
.map((node) => `
|
|
286
|
+
<button class="palette-item" data-node-type="${escapeHtml(node.type)}">
|
|
287
|
+
<b>${escapeHtml(node.label)}</b><small>${escapeHtml(node.category.toUpperCase())}</small>
|
|
288
|
+
</button>
|
|
289
|
+
`).join('');
|
|
290
|
+
document.querySelectorAll('[data-node-type]').forEach((button) => {
|
|
291
|
+
button.onclick = () => addNode(button.dataset.nodeType);
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
async function validateDraft() {
|
|
296
|
+
const sequence = ++validationSequence;
|
|
297
|
+
try {
|
|
298
|
+
const result = await api('/api/validate', { method: 'POST', body: JSON.stringify({ recipe: draft }) });
|
|
299
|
+
if (sequence !== validationSequence) return;
|
|
300
|
+
const hash = result.plans[0].graphHash;
|
|
301
|
+
byId('integrity').textContent = `VALID / ${hash.slice(0, 8)}…${hash.slice(-4)}`;
|
|
302
|
+
byId('integrity').className = 'valid';
|
|
303
|
+
byId('review').disabled = false;
|
|
304
|
+
byId('review-data').textContent = JSON.stringify({
|
|
305
|
+
recipe: draft.id,
|
|
306
|
+
version: draft.version,
|
|
307
|
+
modes: result.plans.map((plan) => plan.mode),
|
|
308
|
+
nodes: draft.nodes.length,
|
|
309
|
+
graphHashes: result.plans.map((plan) => plan.graphHash)
|
|
310
|
+
}, null, 2);
|
|
311
|
+
} catch (error) {
|
|
312
|
+
if (sequence !== validationSequence) return;
|
|
313
|
+
byId('integrity').textContent = `INVALID / ${error.message}`;
|
|
314
|
+
byId('integrity').className = 'invalid';
|
|
315
|
+
byId('review').disabled = true;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function renderLive() {
|
|
320
|
+
const live = catalog.live;
|
|
321
|
+
if (!live) {
|
|
322
|
+
byId('active-stage').textContent = 'No active run';
|
|
323
|
+
byId('activity').textContent = 'Waiting for a recipe-bound workflow.';
|
|
324
|
+
byId('events').innerHTML = '';
|
|
325
|
+
byId('budget').textContent = '—';
|
|
326
|
+
byId('meter').style.width = '0';
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
const active = live.plan.nodes.find((node) => live.nodes[node.id].status === 'RUNNING')
|
|
330
|
+
|| live.plan.nodes.find((node) => live.nodes[node.id].status === 'READY');
|
|
331
|
+
const runtimeNode = active ? live.nodes[active.id] : null;
|
|
332
|
+
byId('active-stage').textContent = active?.id || 'Run complete';
|
|
333
|
+
byId('activity').textContent = active
|
|
334
|
+
? runtimeNode.activity || `${runtimeNode.status} · attempt ${runtimeNode.attempts}`
|
|
335
|
+
: `Final state: ${live.run.state}`;
|
|
336
|
+
const spent = live.budget.spentThisRun;
|
|
337
|
+
const limit = live.budget.perRunTokenLimit;
|
|
338
|
+
byId('meter').style.width = `${Math.min(100, limit ? (spent / limit) * 100 : 0)}%`;
|
|
339
|
+
byId('budget').textContent = `${spent.toLocaleString()} / ${limit.toLocaleString()} TOKENS`;
|
|
340
|
+
byId('events').innerHTML = live.events.slice(-7).reverse().map((event) => `
|
|
341
|
+
<p class="${event.type === 'NODE_ACTIVITY' || event.type.includes('START') ? 'event-active' : ''}">
|
|
342
|
+
${escapeHtml(event.at.slice(11, 19))} · ${escapeHtml(event.type)} · ${escapeHtml(event.changedNodes.join(', '))}
|
|
343
|
+
</p>
|
|
344
|
+
`).join('');
|
|
345
|
+
renderGraph();
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
async function refreshLive() {
|
|
349
|
+
try {
|
|
350
|
+
const result = await api('/api/live');
|
|
351
|
+
catalog.live = result.live;
|
|
352
|
+
renderLive();
|
|
353
|
+
} catch {
|
|
354
|
+
// A transient refresh failure must not discard the draft.
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
async function loadRecipe() {
|
|
359
|
+
const result = await api(`/api/recipe?id=${encodeURIComponent(byId('recipe').value)}`);
|
|
360
|
+
draft = structuredClone(result.recipe);
|
|
361
|
+
source = result.source;
|
|
362
|
+
selectedId = null;
|
|
363
|
+
renderGraph();
|
|
364
|
+
renderRecipeDetails();
|
|
365
|
+
validateDraft();
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
async function refreshCatalog(selectedRecipe) {
|
|
369
|
+
catalog = await api('/api/bootstrap');
|
|
370
|
+
const selector = byId('recipe');
|
|
371
|
+
selector.innerHTML = catalog.recipes.map((recipe) => (
|
|
372
|
+
`<option value="${escapeHtml(recipe.id)}">${escapeHtml(recipe.id)} · v${escapeHtml(recipe.version)}</option>`
|
|
373
|
+
)).join('');
|
|
374
|
+
if (selectedRecipe && catalog.recipes.some((recipe) => recipe.id === selectedRecipe)) selector.value = selectedRecipe;
|
|
375
|
+
renderPalette();
|
|
376
|
+
renderLive();
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
async function initialize() {
|
|
380
|
+
await refreshCatalog();
|
|
381
|
+
byId('recipe').onchange = loadRecipe;
|
|
382
|
+
byId('canvas').onclick = () => {
|
|
383
|
+
selectedId = null;
|
|
384
|
+
renderGraph();
|
|
385
|
+
renderRecipeDetails();
|
|
386
|
+
};
|
|
387
|
+
await loadRecipe();
|
|
388
|
+
clearInterval(liveTimer);
|
|
389
|
+
liveTimer = setInterval(refreshLive, 1800);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
byId('copy').onclick = async () => {
|
|
393
|
+
try {
|
|
394
|
+
const handoff = await api('/api/handoff?audience=developer');
|
|
395
|
+
await navigator.clipboard.writeText(handoff.brief);
|
|
396
|
+
notify('Redacted developer brief copied.');
|
|
397
|
+
} catch (error) {
|
|
398
|
+
notify(error.message);
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
|
|
402
|
+
byId('download').onclick = async () => {
|
|
403
|
+
try {
|
|
404
|
+
const handoff = await api('/api/handoff?audience=agent');
|
|
405
|
+
const blob = new Blob([JSON.stringify(handoff.bundle, null, 2)], { type: 'application/json' });
|
|
406
|
+
const link = document.createElement('a');
|
|
407
|
+
link.href = URL.createObjectURL(blob);
|
|
408
|
+
link.download = `${handoff.bundle.runId}.ael-handoff.json`;
|
|
409
|
+
link.click();
|
|
410
|
+
URL.revokeObjectURL(link.href);
|
|
411
|
+
notify('Integrity-bound handoff exported.');
|
|
412
|
+
} catch (error) {
|
|
413
|
+
notify(error.message);
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
|
|
417
|
+
byId('record-decision').onclick = async () => {
|
|
418
|
+
if (!catalog.live) return notify('Start a workflow run before recording a decision.');
|
|
419
|
+
try {
|
|
420
|
+
await api('/api/decision', {
|
|
421
|
+
method: 'POST',
|
|
422
|
+
body: JSON.stringify({
|
|
423
|
+
runId: catalog.live.run.runId,
|
|
424
|
+
summary: byId('decision-summary').value,
|
|
425
|
+
rationale: byId('decision-rationale').value,
|
|
426
|
+
consequences: []
|
|
427
|
+
})
|
|
428
|
+
});
|
|
429
|
+
byId('decision-summary').value = '';
|
|
430
|
+
byId('decision-rationale').value = '';
|
|
431
|
+
notify('Redacted decision recorded for handoff.');
|
|
432
|
+
} catch (error) {
|
|
433
|
+
notify(error.message);
|
|
434
|
+
}
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
byId('review').onclick = () => byId('confirm').showModal();
|
|
438
|
+
byId('cancel').onclick = () => byId('confirm').close();
|
|
439
|
+
byId('install').onclick = async () => {
|
|
440
|
+
try {
|
|
441
|
+
await api('/api/install', {
|
|
442
|
+
method: 'POST',
|
|
443
|
+
body: JSON.stringify({ recipe: draft, replace: catalog.recipes.some((recipe) => recipe.id === draft.id) })
|
|
444
|
+
});
|
|
445
|
+
byId('confirm').close();
|
|
446
|
+
notify('Recipe installed atomically.');
|
|
447
|
+
await refreshCatalog(draft.id);
|
|
448
|
+
await loadRecipe();
|
|
449
|
+
} catch (error) {
|
|
450
|
+
notify(error.message);
|
|
451
|
+
}
|
|
452
|
+
};
|
|
453
|
+
|
|
454
|
+
function notify(text) {
|
|
455
|
+
const message = byId('message');
|
|
456
|
+
message.textContent = text;
|
|
457
|
+
message.style.display = 'block';
|
|
458
|
+
setTimeout(() => { message.style.display = 'none'; }, 4000);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
initialize().catch((error) => notify(error.message));
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
6
|
+
<title>AEL Workflow Studio</title>
|
|
7
|
+
<link rel="stylesheet" href="/styles.css">
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<header><b class="mark">A</b><div><strong>AEL / WORKFLOW STUDIO</strong><small>LOCAL CONTROL PLANE</small></div>
|
|
11
|
+
<select id="recipe" aria-label="Recipe"></select><span class="secure">● LOCALHOST / SECURE</span>
|
|
12
|
+
<button id="copy">COPY BRIEF</button><button id="download">EXPORT HANDOFF</button><button class="primary" id="review">REVIEW & INSTALL</button>
|
|
13
|
+
</header>
|
|
14
|
+
<main>
|
|
15
|
+
<aside class="library"><label>WORKFLOW VIEW</label><div class="nav active">Canvas</div><div class="run-state">Current recipe and active run are read directly from the local runtime ledger.</div>
|
|
16
|
+
<hr><label>NODE LIBRARY</label><div id="palette"></div><hr><label>GRAPH INTEGRITY</label><output id="integrity">LOADING</output>
|
|
17
|
+
</aside>
|
|
18
|
+
<section class="canvas" id="canvas"><div class="canvas-head"><span id="mode">WORKFLOW / EDIT MODE</span><span>AUTO-LAYOUT / DAG</span></div><svg id="edges" aria-hidden="true"><defs><marker id="arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="5" markerHeight="5" orient="auto-start-reverse"><path d="M 0 0 L 10 5 L 0 10 z"></path></marker></defs><g id="edge-paths"></g></svg><div id="nodes"></div></section>
|
|
19
|
+
<aside class="inspector"><label id="inspector-label">NODE INSPECTOR</label><div id="details"></div>
|
|
20
|
+
<section class="live"><label>LIVE EXECUTION</label><h2 id="active-stage">No active run</h2><p id="activity">Waiting for a recipe-bound workflow.</p>
|
|
21
|
+
<label>CONTEXT BUDGET</label><div class="meter"><i id="meter"></i></div><p class="mono" id="budget">—</p>
|
|
22
|
+
<label>EVIDENCE STREAM</label><div id="events"></div>
|
|
23
|
+
<label>DECISION MEMORY</label><input id="decision-summary" maxlength="160" placeholder="Decision summary"><textarea id="decision-rationale" maxlength="1000" placeholder="Why this choice was made"></textarea><button id="record-decision">RECORD DECISION</button>
|
|
24
|
+
</section>
|
|
25
|
+
<div id="message"></div>
|
|
26
|
+
</aside>
|
|
27
|
+
</main>
|
|
28
|
+
<dialog id="confirm"><h2>Review installation</h2><pre id="review-data"></pre><p>Validation must pass. Built-in recipes must be forked to a new ID; replacing a project recipe requires a higher version.</p><button id="cancel">CANCEL</button><button class="primary" id="install">INSTALL RECIPE</button></dialog>
|
|
29
|
+
<script type="module" src="/app.js"></script>
|
|
30
|
+
</body>
|
|
31
|
+
</html>
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
:root{color-scheme:dark;--bg:#090a0c;--panel:#101216;--line:#2a2e34;--muted:#777e87;--text:#efede7;--hot:#ff5b35;--ok:#45c486;--danger:#ef6262}
|
|
2
|
+
*{box-sizing:border-box}
|
|
3
|
+
body{margin:0;background:var(--bg);color:var(--text);font:12px ui-sans-serif,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;overflow:hidden}
|
|
4
|
+
button,select,input,textarea{font:inherit}
|
|
5
|
+
header{height:64px;display:flex;align-items:center;gap:14px;padding:0 20px;border-bottom:1px solid var(--line);background:#101216}
|
|
6
|
+
header>div{min-width:270px;letter-spacing:1.5px}
|
|
7
|
+
small,label{display:block;color:var(--muted);font-size:9px;letter-spacing:1.6px;margin-top:5px}
|
|
8
|
+
.mark{display:grid;place-items:center;width:30px;height:30px;background:var(--hot);color:#101216;font-size:18px;border-radius:3px}
|
|
9
|
+
header select{width:320px;background:#17191e;border:1px solid #343840;color:var(--text);padding:10px}
|
|
10
|
+
.secure{margin-left:auto;color:#9da3aa;letter-spacing:1px}
|
|
11
|
+
.secure:first-letter{color:var(--ok)}
|
|
12
|
+
button{border:1px solid #343840;background:#181b20;color:#c9c7c1;padding:10px 14px;letter-spacing:.7px;cursor:pointer}
|
|
13
|
+
button:hover{border-color:#686e77;color:#fff}
|
|
14
|
+
button:disabled{cursor:not-allowed;opacity:.45}
|
|
15
|
+
.primary{background:#f1eee7;color:#111;border-color:#f1eee7;font-weight:700}
|
|
16
|
+
.danger{color:#e58a8a}
|
|
17
|
+
.button-row{display:flex;gap:8px}
|
|
18
|
+
.button-row button{flex:1}
|
|
19
|
+
main{display:grid;grid-template-columns:248px 1fr 370px;height:calc(100vh - 64px)}
|
|
20
|
+
aside{background:var(--panel);padding:26px 18px}
|
|
21
|
+
.library{border-right:1px solid var(--line)}
|
|
22
|
+
.inspector{border-left:1px solid var(--line);overflow:auto}
|
|
23
|
+
hr{border:0;border-top:1px solid var(--line);margin:24px 0}
|
|
24
|
+
.nav{display:block;width:100%;border:0;text-align:left;background:transparent;padding:12px 14px;color:#8d939b}
|
|
25
|
+
.nav.active{border-left:3px solid var(--hot);background:#1a1d22;color:var(--text)}
|
|
26
|
+
.nav i{float:right;color:var(--hot);font-style:normal;font-size:9px}
|
|
27
|
+
.run-state{margin:14px 8px;color:#777e87;line-height:1.6}
|
|
28
|
+
.canvas{position:relative;overflow:auto;background-color:#0c0e11;background-image:radial-gradient(#282c32 1px,transparent 1px);background-size:32px 32px}
|
|
29
|
+
.canvas-head{position:sticky;z-index:4;top:0;padding:25px;color:var(--muted);letter-spacing:1.5px}
|
|
30
|
+
.canvas-head span:last-child{float:right}
|
|
31
|
+
.node{position:absolute;width:210px;min-height:104px;padding:17px;background:#15181c;border:1px solid #3a3f46;border-radius:6px;cursor:pointer;z-index:2;transition:border-color .15s,transform .15s}
|
|
32
|
+
.node:hover,.node.selected{border-color:#a0a5ad;transform:translateY(-2px)}
|
|
33
|
+
.node.running{border:2px solid var(--hot);box-shadow:0 0 22px #ff5b3522}
|
|
34
|
+
.node.passed{border-top:4px solid var(--ok)}
|
|
35
|
+
.node.failed{border-color:var(--danger)}
|
|
36
|
+
.node.blocked{opacity:.58}
|
|
37
|
+
.node h3{margin:13px 0 10px;font-size:14px}
|
|
38
|
+
.node small{margin:0}
|
|
39
|
+
.node-activity{margin:10px 0 0;color:#d9a18f;font:10px/1.4 ui-monospace,monospace}
|
|
40
|
+
.status{font:10px ui-monospace,monospace;color:var(--muted)}
|
|
41
|
+
.running .status{color:#ff7958}
|
|
42
|
+
.passed .status{color:var(--ok)}
|
|
43
|
+
.failed .status{color:var(--danger)}
|
|
44
|
+
#edges{position:absolute;inset:0;min-width:100%;min-height:100%;pointer-events:none}
|
|
45
|
+
#arrow path{fill:#505761}
|
|
46
|
+
.edge{fill:none;stroke:#505761;stroke-width:2}
|
|
47
|
+
.edge.active{stroke:var(--hot);stroke-width:3;stroke-dasharray:9 11;animation:flow .8s linear infinite;filter:drop-shadow(0 0 4px #ff5b35)}
|
|
48
|
+
@keyframes flow{to{stroke-dashoffset:-20}}
|
|
49
|
+
#palette{display:grid;grid-template-columns:1fr 1fr;gap:9px;margin-top:14px}
|
|
50
|
+
.palette-item{padding:12px 10px;background:#15171b;border:1px solid #30343a;border-radius:4px;color:#d5d2cc}
|
|
51
|
+
.palette-item b{display:block;margin-bottom:7px}
|
|
52
|
+
.palette-item small{font-size:8px}
|
|
53
|
+
.inspector label{margin:8px 0 15px}
|
|
54
|
+
.inspector h2{font-size:16px}
|
|
55
|
+
.inspector section{border-top:1px solid var(--line);margin-top:26px;padding-top:20px}
|
|
56
|
+
.inspector input,.inspector textarea,.inspector select{width:100%;background:#17191e;color:var(--text);border:1px solid #343840;padding:10px;margin:5px 0 13px}
|
|
57
|
+
.inspector textarea{height:80px;resize:vertical}
|
|
58
|
+
.inspector select[multiple]{height:86px}
|
|
59
|
+
.source-line{display:flex;justify-content:space-between;color:#90969e;font:10px ui-monospace,monospace;margin:14px 0}
|
|
60
|
+
.hint{border-left:2px solid var(--hot);padding:8px;color:#aaa49c;line-height:1.5}
|
|
61
|
+
.meter{height:7px;background:#292d33;border-radius:4px}
|
|
62
|
+
.meter i{display:block;height:100%;width:0;background:var(--hot);border-radius:4px;transition:width .3s}
|
|
63
|
+
.mono,#events{font:10px ui-monospace,monospace;color:#8d939b;line-height:2}
|
|
64
|
+
#events p{margin:2px 0}
|
|
65
|
+
.event-active{color:#ff7958}
|
|
66
|
+
#integrity{display:block;margin-top:14px;font:11px/1.6 ui-monospace,monospace}
|
|
67
|
+
.valid{color:var(--ok)}
|
|
68
|
+
.invalid{color:var(--danger)}
|
|
69
|
+
#message{position:sticky;bottom:0;background:#181b20;border-left:2px solid var(--hot);margin-top:20px;padding:12px;display:none}
|
|
70
|
+
dialog{border:1px solid #3a3f46;background:#121418;color:var(--text);width:560px;padding:26px}
|
|
71
|
+
dialog::backdrop{background:#000b}
|
|
72
|
+
dialog pre{max-height:340px;overflow:auto;background:#0b0d10;padding:14px;color:#aeb4bb}
|
|
73
|
+
dialog button{float:right;margin-left:8px}
|
|
74
|
+
@media(max-width:1000px){main{grid-template-columns:1fr}.library,.inspector{display:none}header .secure,header>div{display:none}}
|
|
75
|
+
@media(prefers-reduced-motion:reduce){.edge.active{animation:none}.node,.meter i{transition:none}}
|