ai-engineering-loop 1.9.3 → 1.10.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/.agents/workflows/ai-engineering-loop.md +2 -2
- package/.claude/skills/ai-engineering-loop/SKILL.md +3 -1
- package/.gemini/skills/ai-engineering-loop/SKILL.md +3 -1
- package/.grok/skills/ai-engineering-loop/SKILL.md +3 -1
- package/bin/ai-engineering-loop.js +260 -0
- package/lib/goal-runtime.js +149 -15
- package/lib/run-checkout.js +70 -10
- package/lib/run-journey.js +75 -0
- package/lib/run-lifecycle.js +203 -0
- package/lib/safe-context.js +11 -0
- package/lib/studio-runtime.js +1 -1
- package/lib/studio-server.js +109 -6
- package/lib/workflow-runtime.js +5 -4
- package/package.json +1 -1
- package/studio/app.js +354 -33
- package/studio/index.html +31 -5
- package/studio/styles.css +11 -2
package/studio/app.js
CHANGED
|
@@ -29,11 +29,21 @@ let layoutTimer;
|
|
|
29
29
|
let spacePressed = false;
|
|
30
30
|
let pendingConnectionSource;
|
|
31
31
|
let runs = [];
|
|
32
|
-
let goal = { text: '', version: 1, frozen: false };
|
|
32
|
+
let goal = { text: '', version: 1, frozen: false, draftRevision: 0, draftHash: null };
|
|
33
33
|
let activeRunId;
|
|
34
34
|
let pendingImport;
|
|
35
35
|
let hydratedGoalKey;
|
|
36
36
|
let selectedCheckoutRun;
|
|
37
|
+
let lifecycleRunId;
|
|
38
|
+
let lifecycleSequence = 0;
|
|
39
|
+
let lifecycleEvents = [];
|
|
40
|
+
let agentPresence = { status: 'UNKNOWN', lastHeartbeatAt: null };
|
|
41
|
+
let followExecution = true;
|
|
42
|
+
let lastFollowedNode;
|
|
43
|
+
let lifecycleStream;
|
|
44
|
+
let handoffCopiedRunId;
|
|
45
|
+
let onboardingDismissed = false;
|
|
46
|
+
let liveRenderScheduled = false;
|
|
37
47
|
|
|
38
48
|
const DISPLAY_NAME_MAX = 80;
|
|
39
49
|
const ROOT_TYPES = new Set(['goal-contract', 'trigger']);
|
|
@@ -295,7 +305,11 @@ function renderEdges() {
|
|
|
295
305
|
if (!from || !to) return;
|
|
296
306
|
const path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
|
|
297
307
|
path.setAttribute('d', edgePath(from, to));
|
|
298
|
-
|
|
308
|
+
const state = catalog.live?.edges?.find((candidate) => candidate.id === edge.id)?.state || 'idle';
|
|
309
|
+
path.setAttribute(
|
|
310
|
+
'class',
|
|
311
|
+
`edge edge-${state}${selectedEdgeId === edge.id ? ' selected' : ''}`
|
|
312
|
+
);
|
|
299
313
|
path.setAttribute('marker-end', 'url(#arrow)');
|
|
300
314
|
path.dataset.edgeId = edge.id;
|
|
301
315
|
group.append(path);
|
|
@@ -364,6 +378,9 @@ function renderEdges() {
|
|
|
364
378
|
|
|
365
379
|
function nodeMarkup(node, index) {
|
|
366
380
|
const runtimeNode = catalog.live?.nodes?.[node.id];
|
|
381
|
+
const lifecycleActivity = activeLifecycleNodeId() === node.id
|
|
382
|
+
? activeLifecycleEvent()?.message
|
|
383
|
+
: '';
|
|
367
384
|
const outgoing = draft.edges.some((edge) => edge.from === node.id);
|
|
368
385
|
const root = rootCandidates().length === 1 && rootCandidates()[0].id === node.id;
|
|
369
386
|
return `
|
|
@@ -372,13 +389,34 @@ function nodeMarkup(node, index) {
|
|
|
372
389
|
<button class="node-title" title="Double-click to edit Display Name">${escapeHtml(displayName(node))}</button>
|
|
373
390
|
<span class="technical-id">${escapeHtml(node.id)}</span>
|
|
374
391
|
<span class="status">● ${escapeHtml(runtimeNode?.status || 'DRAFT')}</span>
|
|
375
|
-
${runtimeNode?.activity ? `<p class="node-activity">${escapeHtml(runtimeNode
|
|
392
|
+
${runtimeNode?.activity || lifecycleActivity ? `<p class="node-activity">${escapeHtml(runtimeNode?.activity || lifecycleActivity)}</p>` : ''}
|
|
376
393
|
<button class="port port-out" aria-label="Connect from ${escapeHtml(node.id)}" tabindex="-1"></button>
|
|
377
394
|
${outgoing ? '' : `<button class="output-add" title="Add connected node" aria-label="Add node connected after ${escapeHtml(displayName(node))}">+</button>`}
|
|
378
395
|
${root ? `<div class="execute-pod"><input class="task-input" aria-label="Task for this run" placeholder="Describe this run’s task" value="${escapeHtml(catalog.live?.run?.task || '')}"><button class="execute-trigger">${goal.frozen ? 'Execute' : 'Set Goal'}</button><span class="execute-hint">${goal.frozen ? 'Local runtime only' : 'Freeze Goal first'}</span></div>` : ''}
|
|
379
396
|
`;
|
|
380
397
|
}
|
|
381
398
|
|
|
399
|
+
function activeLifecycleEvent() {
|
|
400
|
+
const latest = lifecycleEvents.at(-1) || null;
|
|
401
|
+
if (!latest || ['NODE_COMPLETED', 'RUN_COMPLETED'].includes(latest.type)) return null;
|
|
402
|
+
return latest;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
function activeLifecycleNodeId() {
|
|
406
|
+
const event = activeLifecycleEvent();
|
|
407
|
+
if (event?.nodeId) return event.nodeId;
|
|
408
|
+
if (event?.phase) {
|
|
409
|
+
const scopedNode = draft?.nodes.find((node) =>
|
|
410
|
+
node.id === event.phase || node.type === event.phase || node.legacyGate === event.phase
|
|
411
|
+
);
|
|
412
|
+
if (scopedNode) return scopedNode.id;
|
|
413
|
+
}
|
|
414
|
+
if (event?.phase === 'goal' || event?.type?.startsWith('GOAL_')) {
|
|
415
|
+
return draft?.nodes.find((node) => node.type === 'goal-contract')?.id || null;
|
|
416
|
+
}
|
|
417
|
+
return null;
|
|
418
|
+
}
|
|
419
|
+
|
|
382
420
|
function renderGraph() {
|
|
383
421
|
ensurePositions();
|
|
384
422
|
renderLoopGroups();
|
|
@@ -389,7 +427,9 @@ function renderGraph() {
|
|
|
389
427
|
const runtimeNode = catalog.live?.nodes?.[node.id];
|
|
390
428
|
const element = document.createElement('article');
|
|
391
429
|
element.dataset.nodeId = node.id;
|
|
392
|
-
|
|
430
|
+
const lifecycleActive = activeLifecycleNodeId() === node.id &&
|
|
431
|
+
!['DISCONNECTED', 'UNKNOWN'].includes(agentPresence.status);
|
|
432
|
+
element.className = `node ${runtimeNode?.status.toLowerCase() || ''} ${lifecycleActive ? 'agent-active' : ''} ${selectedIds.has(node.id) ? 'selected' : ''}`;
|
|
393
433
|
element.style.left = `${position.x}px`;
|
|
394
434
|
element.style.top = `${position.y}px`;
|
|
395
435
|
element.innerHTML = nodeMarkup(node, index);
|
|
@@ -409,17 +449,27 @@ function updateRuntimePresentation() {
|
|
|
409
449
|
for (const element of document.querySelectorAll('.node')) {
|
|
410
450
|
const nodeId = element.dataset.nodeId;
|
|
411
451
|
const runtimeNode = catalog.live?.nodes?.[nodeId];
|
|
412
|
-
element.classList.remove('running', 'passed', 'failed', 'blocked', 'ready', 'pending', 'skipped');
|
|
452
|
+
element.classList.remove('running', 'passed', 'failed', 'blocked', 'ready', 'pending', 'skipped', 'agent-active', 'agent-idle', 'agent-disconnected');
|
|
413
453
|
if (runtimeNode?.status) element.classList.add(runtimeNode.status.toLowerCase());
|
|
454
|
+
if (activeLifecycleNodeId() === nodeId) {
|
|
455
|
+
if (agentPresence.status === 'WORKING') element.classList.add('agent-active');
|
|
456
|
+
if (agentPresence.status === 'IDLE') element.classList.add('agent-idle');
|
|
457
|
+
if (agentPresence.status === 'DISCONNECTED') element.classList.add('agent-disconnected');
|
|
458
|
+
}
|
|
414
459
|
element.querySelector('.status').textContent = `● ${runtimeNode?.status || 'DRAFT'}`;
|
|
415
460
|
const existingActivity = element.querySelector('.node-activity');
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
461
|
+
const lifecycleActivity = activeLifecycleNodeId() === nodeId
|
|
462
|
+
? activeLifecycleEvent()?.message
|
|
463
|
+
: '';
|
|
464
|
+
const activity = runtimeNode?.activity || lifecycleActivity;
|
|
465
|
+
if (activity) {
|
|
466
|
+
if (existingActivity) existingActivity.textContent = activity;
|
|
467
|
+
else element.querySelector('.status').insertAdjacentHTML('afterend', `<p class="node-activity">${escapeHtml(activity)}</p>`);
|
|
419
468
|
} else {
|
|
420
469
|
existingActivity?.remove();
|
|
421
470
|
}
|
|
422
471
|
}
|
|
472
|
+
renderLoopGroups();
|
|
423
473
|
renderEdges();
|
|
424
474
|
}
|
|
425
475
|
|
|
@@ -882,6 +932,7 @@ function renderPalette() {
|
|
|
882
932
|
function beginNodeInteraction(event) {
|
|
883
933
|
if (event.button !== 0 || event.target.closest('.port,.output-add,.execute-pod,.node-title,.inline-rename')) return;
|
|
884
934
|
event.stopPropagation();
|
|
935
|
+
setFollowExecution(false);
|
|
885
936
|
const element = event.currentTarget;
|
|
886
937
|
const nodeId = element.dataset.nodeId;
|
|
887
938
|
if (event.shiftKey) {
|
|
@@ -908,6 +959,7 @@ function beginNodeInteraction(event) {
|
|
|
908
959
|
function beginPan(event) {
|
|
909
960
|
if (event.button !== 0 && event.button !== 1) return;
|
|
910
961
|
event.preventDefault();
|
|
962
|
+
setFollowExecution(false);
|
|
911
963
|
interaction = {
|
|
912
964
|
type: 'pan',
|
|
913
965
|
pointerId: event.pointerId,
|
|
@@ -1007,6 +1059,7 @@ function finishConnection(event) {
|
|
|
1007
1059
|
}
|
|
1008
1060
|
|
|
1009
1061
|
function beginLasso(event) {
|
|
1062
|
+
setFollowExecution(false);
|
|
1010
1063
|
const start = screenToWorld(event.clientX, event.clientY);
|
|
1011
1064
|
interaction = { type: 'lasso', pointerId: event.pointerId, start, current: start, additive: event.shiftKey };
|
|
1012
1065
|
const marquee = byId('selection-marquee');
|
|
@@ -1141,6 +1194,7 @@ async function ensureStudioRun() {
|
|
|
1141
1194
|
});
|
|
1142
1195
|
}
|
|
1143
1196
|
activeRunId = created.run.runId;
|
|
1197
|
+
renderHandoffState();
|
|
1144
1198
|
await refreshLive();
|
|
1145
1199
|
return activeRunId;
|
|
1146
1200
|
}
|
|
@@ -1148,20 +1202,31 @@ async function ensureStudioRun() {
|
|
|
1148
1202
|
function resolveActiveRunConflict(run) {
|
|
1149
1203
|
return new Promise((resolve) => {
|
|
1150
1204
|
const dialog = byId('active-run-dialog');
|
|
1205
|
+
let settled = false;
|
|
1206
|
+
const finish = (outcome) => {
|
|
1207
|
+
if (settled) return;
|
|
1208
|
+
settled = true;
|
|
1209
|
+
resolve(outcome);
|
|
1210
|
+
};
|
|
1151
1211
|
byId('active-run-message').textContent = `${run.displayName || run.runId} · ${run.state}`;
|
|
1152
1212
|
byId('continue-active-run').onclick = async () => {
|
|
1153
|
-
dialog.close();
|
|
1154
1213
|
activeRunId = run.runId;
|
|
1214
|
+
renderHandoffState();
|
|
1155
1215
|
byId('goal-dialog').close();
|
|
1156
1216
|
showWorkspace('runs');
|
|
1157
1217
|
await loadRuns();
|
|
1158
1218
|
await loadRunDetail(run.runId);
|
|
1159
|
-
|
|
1219
|
+
finish('continue');
|
|
1220
|
+
dialog.close();
|
|
1221
|
+
};
|
|
1222
|
+
byId('cancel-active-run-conflict').onclick = () => {
|
|
1223
|
+
dialog.close();
|
|
1160
1224
|
};
|
|
1161
1225
|
byId('replace-active-run').onclick = () => {
|
|
1226
|
+
finish('replace');
|
|
1162
1227
|
dialog.close();
|
|
1163
|
-
resolve('replace');
|
|
1164
1228
|
};
|
|
1229
|
+
dialog.addEventListener('close', () => finish('cancel'), { once: true });
|
|
1165
1230
|
dialog.showModal();
|
|
1166
1231
|
});
|
|
1167
1232
|
}
|
|
@@ -1185,11 +1250,22 @@ async function saveGoalFromForm() {
|
|
|
1185
1250
|
const runId = await ensureStudioRun();
|
|
1186
1251
|
if (!runId) return null;
|
|
1187
1252
|
const contract = goalContractFromForm(runId);
|
|
1188
|
-
await api(`/api/runs/${encodeURIComponent(runId)}/goal`, {
|
|
1253
|
+
const saved = await api(`/api/runs/${encodeURIComponent(runId)}/goal`, {
|
|
1189
1254
|
method: 'PUT',
|
|
1190
|
-
body: JSON.stringify({
|
|
1255
|
+
body: JSON.stringify({
|
|
1256
|
+
goal: contract,
|
|
1257
|
+
actor: 'studio-user',
|
|
1258
|
+
expectedRevision: goal.draftRevision
|
|
1259
|
+
})
|
|
1191
1260
|
});
|
|
1192
|
-
goal = {
|
|
1261
|
+
goal = {
|
|
1262
|
+
text: contract.objective,
|
|
1263
|
+
criteria: contract.acceptanceCriteria,
|
|
1264
|
+
version: goal.version,
|
|
1265
|
+
frozen: false,
|
|
1266
|
+
draftRevision: saved.draft.metadata.revision,
|
|
1267
|
+
draftHash: saved.draft.metadata.contentHash
|
|
1268
|
+
};
|
|
1193
1269
|
byId('goal-validation').textContent = '';
|
|
1194
1270
|
notify('Goal draft saved. It is not frozen yet.');
|
|
1195
1271
|
byId('goal-dialog').close();
|
|
@@ -1226,7 +1302,17 @@ async function reviewGoal() {
|
|
|
1226
1302
|
byId('goal-review').hidden = false;
|
|
1227
1303
|
byId('goal-review').innerHTML = `
|
|
1228
1304
|
<strong>${escapeHtml(contract.objective)}</strong>
|
|
1229
|
-
<p
|
|
1305
|
+
<p class="mono">Revision ${escapeHtml(String(goal.draftRevision))} · ${escapeHtml(goal.draftHash)}</p>
|
|
1306
|
+
<details>
|
|
1307
|
+
<summary>Review all ${contract.acceptanceCriteria.length} criteria</summary>
|
|
1308
|
+
<ol>${contract.acceptanceCriteria.map((criterion) => `
|
|
1309
|
+
<li>
|
|
1310
|
+
<strong>${escapeHtml(criterion.id)} · ${escapeHtml(criterion.statement)}</strong>
|
|
1311
|
+
<p>Evidence: ${escapeHtml(criterion.evidenceRequired)}</p>
|
|
1312
|
+
<p>Failure cases: ${criterion.failureCases.map(escapeHtml).join(' · ')}</p>
|
|
1313
|
+
</li>
|
|
1314
|
+
`).join('')}</ol>
|
|
1315
|
+
</details>
|
|
1230
1316
|
`;
|
|
1231
1317
|
byId('confirm-freeze').hidden = false;
|
|
1232
1318
|
}
|
|
@@ -1235,7 +1321,11 @@ async function freezeGoalFromForm() {
|
|
|
1235
1321
|
try {
|
|
1236
1322
|
const result = await api(`/api/runs/${encodeURIComponent(activeRunId)}/goal/freeze`, {
|
|
1237
1323
|
method: 'POST',
|
|
1238
|
-
body: JSON.stringify({
|
|
1324
|
+
body: JSON.stringify({
|
|
1325
|
+
actor: 'studio-user',
|
|
1326
|
+
expectedRevision: goal.draftRevision,
|
|
1327
|
+
expectedHash: goal.draftHash
|
|
1328
|
+
})
|
|
1239
1329
|
});
|
|
1240
1330
|
catalog.live = catalog.live || {};
|
|
1241
1331
|
catalog.live.run = result.run;
|
|
@@ -1280,8 +1370,17 @@ async function unfreezeGoalFromForm() {
|
|
|
1280
1370
|
|
|
1281
1371
|
function syncGoalFromLive() {
|
|
1282
1372
|
const liveGoal = catalog.live?.run?.goal;
|
|
1283
|
-
|
|
1284
|
-
if (
|
|
1373
|
+
const nextRunId = catalog.live?.run?.runId || null;
|
|
1374
|
+
if (activeRunId !== nextRunId) {
|
|
1375
|
+
goal = { text: '', version: 1, frozen: false, draftRevision: 0, draftHash: null };
|
|
1376
|
+
hydratedGoalKey = null;
|
|
1377
|
+
}
|
|
1378
|
+
activeRunId = nextRunId;
|
|
1379
|
+
renderHandoffState();
|
|
1380
|
+
if (!liveGoal) {
|
|
1381
|
+
renderGoalState();
|
|
1382
|
+
return;
|
|
1383
|
+
}
|
|
1285
1384
|
goal.version = liveGoal.version || 1;
|
|
1286
1385
|
goal.frozen = liveGoal.frozen === true;
|
|
1287
1386
|
if (catalog.live.run.task) byId('goal-task').value = catalog.live.run.task;
|
|
@@ -1290,6 +1389,110 @@ function syncGoalFromLive() {
|
|
|
1290
1389
|
renderGoalState();
|
|
1291
1390
|
}
|
|
1292
1391
|
|
|
1392
|
+
async function refreshGoalDraft(runId) {
|
|
1393
|
+
if (!runId || goal.frozen) return;
|
|
1394
|
+
const result = await api(`/api/runs/${encodeURIComponent(runId)}/goal`);
|
|
1395
|
+
const draftEnvelope = result.draft;
|
|
1396
|
+
if (!draftEnvelope || draftEnvelope.metadata.revision === goal.draftRevision) return;
|
|
1397
|
+
goal.draftRevision = draftEnvelope.metadata.revision;
|
|
1398
|
+
goal.draftHash = draftEnvelope.metadata.contentHash;
|
|
1399
|
+
goal.text = draftEnvelope.contract.objective || '';
|
|
1400
|
+
goal.criteria = draftEnvelope.contract.acceptanceCriteria || [];
|
|
1401
|
+
if (!byId('goal-form').contains(document.activeElement)) {
|
|
1402
|
+
byId('goal-text').value = goal.text;
|
|
1403
|
+
byId('goal-criteria').value = goal.criteria.map((criterion) => (
|
|
1404
|
+
`${criterion.statement} | ${criterion.evidenceRequired} | ${(criterion.failureCases || []).join(' | ')}`
|
|
1405
|
+
)).join('\n');
|
|
1406
|
+
}
|
|
1407
|
+
renderGoalState();
|
|
1408
|
+
}
|
|
1409
|
+
|
|
1410
|
+
async function refreshLifecycle(runId) {
|
|
1411
|
+
if (!runId) {
|
|
1412
|
+
lifecycleStream?.close();
|
|
1413
|
+
lifecycleStream = null;
|
|
1414
|
+
lifecycleRunId = null;
|
|
1415
|
+
lifecycleSequence = 0;
|
|
1416
|
+
lifecycleEvents = [];
|
|
1417
|
+
agentPresence = { status: 'UNKNOWN', lastHeartbeatAt: null };
|
|
1418
|
+
return;
|
|
1419
|
+
}
|
|
1420
|
+
if (lifecycleRunId !== runId) {
|
|
1421
|
+
lifecycleStream?.close();
|
|
1422
|
+
lifecycleStream = null;
|
|
1423
|
+
lifecycleRunId = runId;
|
|
1424
|
+
lifecycleSequence = 0;
|
|
1425
|
+
lifecycleEvents = [];
|
|
1426
|
+
startLifecycleStream(runId);
|
|
1427
|
+
}
|
|
1428
|
+
try {
|
|
1429
|
+
const result = await api(
|
|
1430
|
+
`/api/runs/${encodeURIComponent(runId)}/lifecycle?after=${lifecycleSequence}&limit=100`
|
|
1431
|
+
);
|
|
1432
|
+
lifecycleEvents = lifecycleEvents.concat(
|
|
1433
|
+
result.lifecycle.events.filter((event) => event.sequence > lifecycleSequence)
|
|
1434
|
+
).slice(-100);
|
|
1435
|
+
lifecycleSequence = result.lifecycle.nextSequence;
|
|
1436
|
+
agentPresence = result.presence;
|
|
1437
|
+
} catch {
|
|
1438
|
+
agentPresence = { status: 'UNKNOWN', lastHeartbeatAt: null };
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1441
|
+
|
|
1442
|
+
function startLifecycleStream(runId) {
|
|
1443
|
+
if (!window.EventSource || !runId) return;
|
|
1444
|
+
lifecycleStream = new window.EventSource(
|
|
1445
|
+
`/api/runs/${encodeURIComponent(runId)}/lifecycle/stream?after=${lifecycleSequence}`
|
|
1446
|
+
);
|
|
1447
|
+
lifecycleStream.onmessage = (message) => {
|
|
1448
|
+
try {
|
|
1449
|
+
const result = JSON.parse(message.data);
|
|
1450
|
+
lifecycleEvents = lifecycleEvents.concat(
|
|
1451
|
+
result.lifecycle.events.filter((event) => event.sequence > lifecycleSequence)
|
|
1452
|
+
).slice(-100);
|
|
1453
|
+
lifecycleSequence = Math.max(lifecycleSequence, result.lifecycle.nextSequence);
|
|
1454
|
+
agentPresence = result.presence;
|
|
1455
|
+
scheduleLiveRender();
|
|
1456
|
+
} catch {
|
|
1457
|
+
// The regular cursor poll remains the recovery path.
|
|
1458
|
+
}
|
|
1459
|
+
};
|
|
1460
|
+
}
|
|
1461
|
+
|
|
1462
|
+
function scheduleLiveRender() {
|
|
1463
|
+
if (liveRenderScheduled) return;
|
|
1464
|
+
liveRenderScheduled = true;
|
|
1465
|
+
const schedule = window.requestAnimationFrame || ((callback) => setTimeout(callback, 16));
|
|
1466
|
+
schedule(() => {
|
|
1467
|
+
liveRenderScheduled = false;
|
|
1468
|
+
renderLive();
|
|
1469
|
+
});
|
|
1470
|
+
}
|
|
1471
|
+
|
|
1472
|
+
function setFollowExecution(enabled) {
|
|
1473
|
+
followExecution = enabled;
|
|
1474
|
+
const button = byId('follow-execution');
|
|
1475
|
+
button.classList.toggle('active', enabled);
|
|
1476
|
+
button.setAttribute('aria-pressed', String(enabled));
|
|
1477
|
+
button.textContent = enabled ? 'Following' : 'Follow execution';
|
|
1478
|
+
if (enabled) {
|
|
1479
|
+
lastFollowedNode = null;
|
|
1480
|
+
followActiveNode();
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1483
|
+
|
|
1484
|
+
function followActiveNode() {
|
|
1485
|
+
const nodeId = activeLifecycleNodeId();
|
|
1486
|
+
if (!followExecution || !nodeId || nodeId === lastFollowedNode || interaction) return;
|
|
1487
|
+
const position = positions.get(nodeId);
|
|
1488
|
+
if (!position) return;
|
|
1489
|
+
const canvas = byId('canvas').getBoundingClientRect();
|
|
1490
|
+
viewport.x = canvas.width / 2 - (position.x + NODE_WIDTH / 2) * viewport.scale;
|
|
1491
|
+
viewport.y = canvas.height / 2 - (position.y + 54) * viewport.scale;
|
|
1492
|
+
lastFollowedNode = nodeId;
|
|
1493
|
+
applyViewport();
|
|
1494
|
+
}
|
|
1495
|
+
|
|
1293
1496
|
async function hydrateGoalFromLive() {
|
|
1294
1497
|
const run = catalog.live?.run;
|
|
1295
1498
|
const artifactPath = run?.artifacts?.goalContract?.path;
|
|
@@ -1383,7 +1586,10 @@ async function loadRunDetail(runId) {
|
|
|
1383
1586
|
const y1 = from.position.y + NODE_PORT_Y;
|
|
1384
1587
|
const x2 = to.position.x;
|
|
1385
1588
|
const y2 = to.position.y + NODE_PORT_Y;
|
|
1386
|
-
|
|
1589
|
+
const state = ['idle', 'active', 'passed', 'failed', 'skipped', 'waiting'].includes(edge.state)
|
|
1590
|
+
? edge.state
|
|
1591
|
+
: 'idle';
|
|
1592
|
+
return `<path class="edge-${state}" d="M ${x1} ${y1} C ${x1 + 70} ${y1}, ${x2 - 70} ${y2}, ${x2} ${y2}"></path>`;
|
|
1387
1593
|
}).join('');
|
|
1388
1594
|
const checkoutGroups = (checkout.loopGroups || []).map((group) => {
|
|
1389
1595
|
const members = checkout.nodes.filter((node) => group.nodeIds.includes(node.id));
|
|
@@ -1465,14 +1671,32 @@ async function loadNodeIo(runId, nodeId) {
|
|
|
1465
1671
|
const panel = byId('node-io-panel');
|
|
1466
1672
|
try {
|
|
1467
1673
|
const { io } = await api(`/api/runs/${encodeURIComponent(runId)}/nodes/${encodeURIComponent(nodeId)}`);
|
|
1674
|
+
const running = io.node.status === 'RUNNING';
|
|
1675
|
+
const interactionEmpty = io.agentInteractionsAvailable === false
|
|
1676
|
+
? 'Agent Interaction is temporarily unavailable. Other node evidence remains valid.'
|
|
1677
|
+
: 'No Agent Interaction was recorded for this Run.';
|
|
1468
1678
|
panel.innerHTML = `
|
|
1469
|
-
<header><small>NODE
|
|
1470
|
-
<
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
<section><h4>
|
|
1679
|
+
<header class="node-io-head"><div><small>NODE INSPECTOR · ${escapeHtml(io.node.status)}</small><h3>${escapeHtml(io.node.displayName)}</h3></div><p class="mono">Duration: ${io.durationMs == null ? 'Not available' : `${Number(io.durationMs)} ms`} · Loop Iteration: ${io.loopIteration == null ? 'Not available' : escapeHtml(String(io.loopIteration))}</p></header>
|
|
1680
|
+
<nav class="io-tabs" role="tablist" aria-label="Node details">
|
|
1681
|
+
${['Input', 'Live Activity', 'Output', 'Evidence', 'Timeline'].map((label, index) => `<button class="io-tab" role="tab" aria-selected="${index === 0}" data-io-tab="${slug(label)}">${label}</button>`).join('')}
|
|
1682
|
+
</nav>
|
|
1683
|
+
<div class="node-data-grid">
|
|
1684
|
+
<section class="io-pane active" data-io-pane="input"><h4>Input</h4>${io.input.task ? `<p><b>Task</b><br>${escapeHtml(io.input.task)}</p>` : ''}${io.input.constraints ? `<p><b>Constraints</b><br>${escapeHtml(io.input.constraints)}</p>` : ''}${io.input.dependencies.length ? io.input.dependencies.map((dependency) => `<p><b>${escapeHtml(dependency.nodeId)}</b> · ${escapeHtml(dependency.status)}</p>${renderArtifactPreview(dependency.artifact)}`).join('') : '<p class="muted">Root input from this Run.</p>'}</section>
|
|
1685
|
+
<section class="io-pane" data-io-pane="live-activity"><h4>Live Activity</h4><p class="muted">Interaction scope: ${escapeHtml(io.agentInteractionScope || 'RUN')} — questions and answers belong to the whole Run, not only this node.</p><p class="node-progress">${running ? 'In progress · waiting for persisted output' : escapeHtml(io.node.status)}</p><div class="timeline">${io.agentInteractions.map((event) => `<p><time>${escapeHtml(event.at)}</time><strong>${escapeHtml(event.type)}</strong> ${escapeHtml(String(event.message ?? ''))}</p>`).join('') || `<p class="muted">${escapeHtml(interactionEmpty)}</p>`}</div></section>
|
|
1686
|
+
<section class="io-pane" data-io-pane="output"><h4>Output</h4><p><b>${running ? 'In progress' : escapeHtml(io.output.status)}</b>${io.output.reason ? ` · ${escapeHtml(io.output.reason)}` : ''}</p>${running ? '<p class="muted">Output will appear after the Agent records a terminal node event.</p>' : renderArtifactPreview(io.output.artifact)}</section>
|
|
1687
|
+
<section class="io-pane" data-io-pane="evidence"><h4>Evidence</h4>${renderArtifactPreview(io.evidence)}</section>
|
|
1688
|
+
<section class="io-pane" data-io-pane="timeline"><h4>Timeline</h4><div class="timeline">${io.timeline.map((event) => `<p><time>${escapeHtml(event.at)}</time><strong>${escapeHtml(event.type)}</strong></p>`).join('') || '<p class="muted">No node events yet.</p>'}</div></section>
|
|
1475
1689
|
</div>`;
|
|
1690
|
+
panel.querySelectorAll('[data-io-tab]').forEach((button) => {
|
|
1691
|
+
button.onclick = () => {
|
|
1692
|
+
panel.querySelectorAll('[data-io-tab]').forEach((tab) => {
|
|
1693
|
+
tab.setAttribute('aria-selected', String(tab === button));
|
|
1694
|
+
});
|
|
1695
|
+
panel.querySelectorAll('[data-io-pane]').forEach((pane) => {
|
|
1696
|
+
pane.classList.toggle('active', pane.dataset.ioPane === button.dataset.ioTab);
|
|
1697
|
+
});
|
|
1698
|
+
};
|
|
1699
|
+
});
|
|
1476
1700
|
panel.querySelectorAll('[data-artifact-download]').forEach((button) => {
|
|
1477
1701
|
button.onclick = async () => {
|
|
1478
1702
|
try {
|
|
@@ -1572,16 +1796,27 @@ async function refreshSelectedCheckout() {
|
|
|
1572
1796
|
|
|
1573
1797
|
async function copyAgentHandoff(runId = activeRunId) {
|
|
1574
1798
|
try {
|
|
1575
|
-
|
|
1576
|
-
|
|
1799
|
+
const targetRunId = runId || await ensureStudioRun();
|
|
1800
|
+
if (!targetRunId) return;
|
|
1801
|
+
const result = await api(`/api/runs/${encodeURIComponent(targetRunId)}/agent-handoff`);
|
|
1577
1802
|
await navigator.clipboard.writeText(result.handoff.prompt);
|
|
1578
|
-
|
|
1803
|
+
handoffCopiedRunId = targetRunId;
|
|
1804
|
+
renderHandoffState();
|
|
1579
1805
|
notify('Run-bound prompt copied. Paste it into your AI coding Agent.');
|
|
1580
1806
|
} catch (error) {
|
|
1581
1807
|
byId('goal-validation').textContent = error.message;
|
|
1582
1808
|
}
|
|
1583
1809
|
}
|
|
1584
1810
|
|
|
1811
|
+
function renderHandoffState() {
|
|
1812
|
+
const copied = Boolean(handoffCopiedRunId && handoffCopiedRunId === activeRunId);
|
|
1813
|
+
byId('agent-handoff-state').hidden = !copied;
|
|
1814
|
+
byId('agent-handoff-instructions').textContent = copied
|
|
1815
|
+
? 'Paste it once into your current AI Agent terminal, then keep Studio open to follow persisted progress.'
|
|
1816
|
+
: '';
|
|
1817
|
+
byId('start-agent').textContent = copied ? 'Copy again' : 'Start with AI Agent';
|
|
1818
|
+
}
|
|
1819
|
+
|
|
1585
1820
|
function showWorkspace(section) {
|
|
1586
1821
|
const showingRuns = section === 'runs';
|
|
1587
1822
|
byId('runs-view').hidden = !showingRuns;
|
|
@@ -1706,6 +1941,7 @@ function zoomAt(nextScale, clientX, clientY) {
|
|
|
1706
1941
|
|
|
1707
1942
|
function handleWheel(event) {
|
|
1708
1943
|
event.preventDefault();
|
|
1944
|
+
setFollowExecution(false);
|
|
1709
1945
|
if (event.ctrlKey || event.metaKey) {
|
|
1710
1946
|
zoomAt(viewport.scale * Math.exp(-event.deltaY * 0.002), event.clientX, event.clientY);
|
|
1711
1947
|
} else {
|
|
@@ -1822,25 +2058,85 @@ function renderLive() {
|
|
|
1822
2058
|
byId('events').innerHTML = '';
|
|
1823
2059
|
byId('budget').textContent = '—';
|
|
1824
2060
|
byId('meter').style.width = '0';
|
|
2061
|
+
byId('agent-presence').textContent = 'Agent unavailable';
|
|
2062
|
+
byId('agent-presence').className = 'agent-presence unknown';
|
|
2063
|
+
const dock = byId('run-activity-dock');
|
|
2064
|
+
if (dock) dock.hidden = true;
|
|
1825
2065
|
updateRuntimePresentation();
|
|
1826
2066
|
return;
|
|
1827
2067
|
}
|
|
1828
|
-
const
|
|
2068
|
+
const lifecycleNodeId = activeLifecycleNodeId();
|
|
2069
|
+
const active = live.plan.nodes.find((node) => node.id === lifecycleNodeId)
|
|
2070
|
+
|| live.plan.nodes.find((node) => live.nodes[node.id].status === 'RUNNING')
|
|
1829
2071
|
|| live.plan.nodes.find((node) => live.nodes[node.id].status === 'READY');
|
|
1830
2072
|
const runtimeNode = active ? live.nodes[active.id] : null;
|
|
2073
|
+
const lifecycle = activeLifecycleEvent();
|
|
1831
2074
|
byId('run-summary').textContent = active ? `${active.id} · ${runtimeNode.status}` : `Run ${live.run.state}`;
|
|
1832
2075
|
byId('active-stage').textContent = active?.id || 'Run complete';
|
|
1833
|
-
byId('activity').textContent =
|
|
2076
|
+
byId('activity').textContent = lifecycle?.message ||
|
|
2077
|
+
(active ? runtimeNode.activity || `${runtimeNode.status} · attempt ${runtimeNode.attempts}` : `Final state: ${live.run.state}`);
|
|
2078
|
+
const journeyStatuses = new Set(['pending', 'active', 'complete']);
|
|
2079
|
+
const degradedSources = live.journey?.degradedSources || [];
|
|
2080
|
+
byId('run-journey').dataset.degraded = degradedSources.join(', ');
|
|
2081
|
+
byId('run-journey').innerHTML = (live.journey?.steps || []).map((step) => {
|
|
2082
|
+
const status = String(step?.status || '').toLowerCase();
|
|
2083
|
+
const safeStatus = journeyStatuses.has(status) ? status : 'unknown';
|
|
2084
|
+
const label = String(step?.id || '').replaceAll('_', ' ');
|
|
2085
|
+
const suffix = safeStatus === 'unknown' ? ' (status unavailable)' : '';
|
|
2086
|
+
const blocked = step?.blocked
|
|
2087
|
+
? (live.journey?.pendingQuestions == null
|
|
2088
|
+
? ' · unanswered count unavailable'
|
|
2089
|
+
: ` · ${Number(live.journey.pendingQuestions)} unanswered`)
|
|
2090
|
+
: '';
|
|
2091
|
+
return `<li class="${safeStatus}">${escapeHtml(label + suffix + blocked)}</li>`;
|
|
2092
|
+
}).join('') + (degradedSources.length
|
|
2093
|
+
? `<li class="unknown">${escapeHtml(`${degradedSources.join(' and ')} unavailable — journey may be incomplete`)}</li>`
|
|
2094
|
+
: '');
|
|
2095
|
+
const presenceLabel = {
|
|
2096
|
+
WORKING: 'Agent working',
|
|
2097
|
+
IDLE: 'Agent appears idle',
|
|
2098
|
+
DISCONNECTED: 'Agent disconnected',
|
|
2099
|
+
UNKNOWN: 'Waiting for Agent'
|
|
2100
|
+
}[agentPresence.status] || 'Waiting for Agent';
|
|
2101
|
+
byId('agent-presence').textContent = presenceLabel;
|
|
2102
|
+
byId('agent-presence').className = `agent-presence ${agentPresence.status.toLowerCase()}`;
|
|
1834
2103
|
const spent = live.budget.spentThisRun;
|
|
1835
2104
|
const limit = live.budget.perRunTokenLimit;
|
|
1836
2105
|
byId('meter').style.width = `${Math.min(100, limit ? (spent / limit) * 100 : 0)}%`;
|
|
1837
2106
|
byId('budget').textContent = `${spent.toLocaleString()} / ${limit.toLocaleString()} TOKENS`;
|
|
1838
|
-
byId('events').innerHTML =
|
|
2107
|
+
byId('events').innerHTML = lifecycleEvents.slice(-7).reverse().map((event) => `
|
|
1839
2108
|
<p class="${event.type === 'NODE_ACTIVITY' || event.type.includes('START') ? 'event-active' : ''}">
|
|
1840
|
-
${escapeHtml(event.at.slice(11, 19))} · ${escapeHtml(event.type)} · ${escapeHtml(event.
|
|
2109
|
+
${escapeHtml(event.at.slice(11, 19))} · ${escapeHtml(event.type)} · ${escapeHtml(event.message)}
|
|
1841
2110
|
</p>
|
|
2111
|
+
`).join('') || live.events.slice(-7).reverse().map((event) => `
|
|
2112
|
+
<p>${escapeHtml(event.at.slice(11, 19))} · ${escapeHtml(event.type)}</p>
|
|
1842
2113
|
`).join('');
|
|
2114
|
+
renderRunActivityDock(live, active, runtimeNode, lifecycle);
|
|
1843
2115
|
updateRuntimePresentation();
|
|
2116
|
+
followActiveNode();
|
|
2117
|
+
}
|
|
2118
|
+
|
|
2119
|
+
function renderRunActivityDock(live, active, runtimeNode, lifecycle) {
|
|
2120
|
+
const dock = byId('run-activity-dock');
|
|
2121
|
+
if (!dock) return;
|
|
2122
|
+
dock.hidden = false;
|
|
2123
|
+
byId('run-activity-scope').textContent = active ? 'NODE ACTIVITY' : 'RUN ACTIVITY';
|
|
2124
|
+
byId('run-activity-title').textContent = active ? displayName(active) : `Run ${live.run.state}`;
|
|
2125
|
+
byId('run-activity-message').textContent = lifecycle?.message ||
|
|
2126
|
+
runtimeNode?.activity || (active ? runtimeNode?.status : 'Waiting for the next persisted event.');
|
|
2127
|
+
byId('run-activity-status').textContent = runtimeNode?.status || agentPresence.status || live.run.state;
|
|
2128
|
+
const inspect = byId('inspect-live-node');
|
|
2129
|
+
inspect.hidden = !active;
|
|
2130
|
+
inspect.dataset.nodeId = active?.id || '';
|
|
2131
|
+
byId('run-activity-timeline').innerHTML = lifecycleEvents.slice(-4).reverse().map((event) => `
|
|
2132
|
+
<span><time>${escapeHtml(String(event.at || '').slice(11, 19))}</time>${escapeHtml(event.message || event.type)}</span>
|
|
2133
|
+
`).join('');
|
|
2134
|
+
}
|
|
2135
|
+
|
|
2136
|
+
function maybeOpenOnboarding() {
|
|
2137
|
+
const dialog = byId('goal-dialog');
|
|
2138
|
+
if (catalog.live || dialog.open || onboardingDismissed) return;
|
|
2139
|
+
dialog.showModal();
|
|
1844
2140
|
}
|
|
1845
2141
|
|
|
1846
2142
|
async function refreshLive() {
|
|
@@ -1848,13 +2144,22 @@ async function refreshLive() {
|
|
|
1848
2144
|
const result = await api('/api/live');
|
|
1849
2145
|
catalog.live = result.live;
|
|
1850
2146
|
syncGoalFromLive();
|
|
2147
|
+
await refreshLifecycle(catalog.live?.run?.runId);
|
|
2148
|
+
await refreshGoalDraft(catalog.live?.run?.runId);
|
|
1851
2149
|
await hydrateGoalFromLive();
|
|
2150
|
+
byId('live-connection-state').hidden = true;
|
|
1852
2151
|
renderLive();
|
|
1853
2152
|
await refreshSelectedCheckout();
|
|
1854
2153
|
await refreshCheckoutInteractions();
|
|
1855
2154
|
if (!byId('runs-view').hidden) await loadRuns();
|
|
2155
|
+
maybeOpenOnboarding();
|
|
2156
|
+
return true;
|
|
1856
2157
|
} catch {
|
|
1857
|
-
// A transient refresh failure must not discard the draft.
|
|
2158
|
+
// A transient refresh failure must not discard the last valid draft or Run snapshot.
|
|
2159
|
+
byId('live-connection-message').textContent =
|
|
2160
|
+
'Studio connection lost. Your last valid Run view is preserved.';
|
|
2161
|
+
byId('live-connection-state').hidden = false;
|
|
2162
|
+
return false;
|
|
1858
2163
|
}
|
|
1859
2164
|
}
|
|
1860
2165
|
|
|
@@ -1929,6 +2234,8 @@ function bindCanvas() {
|
|
|
1929
2234
|
byId('zoom-out').onclick = () => zoomAt(viewport.scale / 1.2);
|
|
1930
2235
|
byId('undo').onclick = () => restoreHistory(historyIndex - 1);
|
|
1931
2236
|
byId('redo').onclick = () => restoreHistory(historyIndex + 1);
|
|
2237
|
+
byId('follow-execution').onclick = () => setFollowExecution(!followExecution);
|
|
2238
|
+
setFollowExecution(followExecution);
|
|
1932
2239
|
}
|
|
1933
2240
|
|
|
1934
2241
|
function editableTarget(target) {
|
|
@@ -2154,7 +2461,21 @@ async function initialize() {
|
|
|
2154
2461
|
byId('close-inspector').onclick = () => byId('inspector-panel').classList.remove('open');
|
|
2155
2462
|
byId('toggle-execution').onclick = () => byId('execution-panel').classList.toggle('open');
|
|
2156
2463
|
byId('close-execution').onclick = () => byId('execution-panel').classList.remove('open');
|
|
2464
|
+
byId('open-live-details').onclick = () => byId('execution-panel').classList.add('open');
|
|
2465
|
+
byId('inspect-live-node').onclick = async (event) => {
|
|
2466
|
+
const nodeId = event.currentTarget.dataset.nodeId;
|
|
2467
|
+
if (!activeRunId || !nodeId) return;
|
|
2468
|
+
showWorkspace('runs');
|
|
2469
|
+
await loadRuns();
|
|
2470
|
+
await loadRunDetail(activeRunId);
|
|
2471
|
+
await loadNodeIo(activeRunId, nodeId);
|
|
2472
|
+
};
|
|
2473
|
+
byId('retry-live-connection').onclick = refreshLive;
|
|
2474
|
+
byId('goal-dialog').addEventListener('close', () => {
|
|
2475
|
+
onboardingDismissed = true;
|
|
2476
|
+
});
|
|
2157
2477
|
await loadRecipe();
|
|
2478
|
+
await refreshLive();
|
|
2158
2479
|
clearInterval(liveTimer);
|
|
2159
2480
|
liveTimer = setInterval(refreshLive, 1800);
|
|
2160
2481
|
}
|