ai-engineering-loop 1.9.4 → 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.
@@ -1168,11 +1168,15 @@ function handleGate() {
1168
1168
  const run = target.workflow
1169
1169
  ? applyWorkflowGate(CWD, gate, { runId: target.runId }).run
1170
1170
  : applyGate(CWD, gate, { runId: target.runId });
1171
+ const runCompleted = run.state === 'DELIVERED' || run.state === 'REPORTED';
1171
1172
  appendRunLifecycle(CWD, target.runId, {
1172
- type: run.state === 'DELIVERED' || run.state === 'REPORTED' ? 'RUN_COMPLETED' : 'NODE_COMPLETED',
1173
- ...(lifecycleNode ? { nodeId: lifecycleNode.id } : {}),
1173
+ type: runCompleted
1174
+ ? 'RUN_COMPLETED'
1175
+ : (lifecycleNode ? 'NODE_COMPLETED' : 'PHASE_COMPLETED'),
1176
+ ...(!runCompleted && lifecycleNode ? { nodeId: lifecycleNode.id } : {}),
1174
1177
  phase: gate,
1175
1178
  actor: 'agent',
1179
+ status: 'PASSED',
1176
1180
  message: `${lifecycleNode?.displayName || gate} completed`
1177
1181
  });
1178
1182
  if (json) {
@@ -1742,7 +1746,7 @@ function handleGoal() {
1742
1746
  expectedHash
1743
1747
  });
1744
1748
  appendRunLifecycle(CWD, runId, {
1745
- type: 'NODE_COMPLETED',
1749
+ type: goalNode ? 'NODE_COMPLETED' : 'GOAL_FROZEN',
1746
1750
  ...(goalNode ? { nodeId: goalNode.id } : {}),
1747
1751
  phase: 'goal',
1748
1752
  actor: argValue('--by') || 'human',
@@ -1769,6 +1773,7 @@ function handleActivity() {
1769
1773
  'node-started': 'NODE_STARTED',
1770
1774
  'node-activity': 'NODE_ACTIVITY',
1771
1775
  'node-completed': 'NODE_COMPLETED',
1776
+ 'node-failed': 'NODE_FAILED',
1772
1777
  'loop-iterated': 'LOOP_ITERATED',
1773
1778
  'run-completed': 'RUN_COMPLETED'
1774
1779
  };
@@ -1786,7 +1791,14 @@ function handleActivity() {
1786
1791
  phase: argValue('--phase'),
1787
1792
  nodeId,
1788
1793
  actor: argValue('--by') || 'agent',
1789
- message: argValue('--message') || 'Agent is working'
1794
+ message: argValue('--message') || 'Agent is working',
1795
+ status: argValue('--status'),
1796
+ ...(argValue('--evidence-path') ? {
1797
+ evidence: {
1798
+ path: argValue('--evidence-path'),
1799
+ sha256: argValue('--evidence-hash')
1800
+ }
1801
+ } : {})
1790
1802
  });
1791
1803
  console.log(JSON.stringify({ ok: true, event, presence: runAgentPresence(CWD, runId) }, null, 2));
1792
1804
  } catch (error) {
@@ -2,9 +2,10 @@
2
2
 
3
3
  const { validateRecipe } = require('./recipe.js');
4
4
  const { stableEdgeId } = require('./recipe-graph.js');
5
+ const { listRunInteractions } = require('./run-interactions.js');
5
6
  const { loadRun } = require('./run-state.js');
6
7
  const { inspectRunArtifact } = require('./run-history.js');
7
- const { redactSecrets } = require('./safe-context.js');
8
+ const { redactHomePaths, redactSecrets } = require('./safe-context.js');
8
9
  const { workflowStatus } = require('./workflow-runtime.js');
9
10
 
10
11
  function checkoutError(message, code = 'RUN_CHECKOUT_ERROR') {
@@ -18,15 +19,42 @@ function fallbackPosition(index) {
18
19
  }
19
20
 
20
21
  function redactedValue(value) {
21
- return JSON.parse(redactSecrets(JSON.stringify(value)).text);
22
+ const redactDeep = (item) => {
23
+ if (typeof item === 'string') return redactHomePaths(item);
24
+ if (Array.isArray(item)) return item.map(redactDeep);
25
+ if (item && typeof item === 'object') {
26
+ return Object.fromEntries(Object.entries(item).map(([key, child]) => [key, redactDeep(child)]));
27
+ }
28
+ return item;
29
+ };
30
+ return JSON.parse(redactSecrets(JSON.stringify(redactDeep(value))).text);
22
31
  }
23
32
 
24
- function edgesFromPlan(plan) {
25
- return plan.nodes.flatMap((node) => (node.dependsOn || []).map((from) => ({
26
- id: stableEdgeId(from, node.id),
27
- from,
28
- to: node.id
29
- })));
33
+ function edgeState(sourceStatus, targetStatus) {
34
+ if (targetStatus === 'RUNNING') return 'active';
35
+ if (targetStatus === 'FAILED') return 'failed';
36
+ if (targetStatus === 'SKIPPED') return 'skipped';
37
+ if (targetStatus === 'READY' || targetStatus === 'BLOCKED') return 'waiting';
38
+ if (['PASSED', 'SKIPPED'].includes(sourceStatus) && targetStatus === 'PASSED') return 'passed';
39
+ return 'idle';
40
+ }
41
+
42
+ function edgesFromPlan(plan, state = null) {
43
+ return plan.nodes.flatMap((node) => (node.dependsOn || []).map((from) => {
44
+ const sourceStatus = state?.nodes[from]?.status;
45
+ const targetStatus = state?.nodes[node.id]?.status;
46
+ const stateName = edgeState(sourceStatus, targetStatus);
47
+ return {
48
+ id: stableEdgeId(from, node.id),
49
+ from,
50
+ to: node.id,
51
+ ...(state ? {
52
+ state: stateName,
53
+ traversed: !['idle', 'waiting'].includes(stateName),
54
+ active: stateName === 'active'
55
+ } : {})
56
+ };
57
+ }));
30
58
  }
31
59
 
32
60
  function publicNode(node, state, index) {
@@ -72,7 +100,7 @@ function runCheckout(rootDir, runId) {
72
100
  run: publicRun,
73
101
  graphHash: workflow.plan.graphHash,
74
102
  nodes: workflow.plan.nodes.map((node, index) => publicNode(node, workflow.state, index)),
75
- edges: edgesFromPlan(workflow.plan),
103
+ edges: edgesFromPlan(workflow.plan, workflow.state),
76
104
  loopGroups: (workflow.plan.loopGroups || []).map((group) => ({
77
105
  ...group,
78
106
  runtime: workflow.state.loopGroups[group.id] || null
@@ -110,9 +138,32 @@ function runNodeIo(rootDir, runId, nodeId) {
110
138
  event.type === 'WORKFLOW_CREATED' ||
111
139
  (event.changes || []).some((change) => change.nodeId === nodeId)
112
140
  ).map(({ initialNodes, ...event }) => event);
141
+ const finishedIndex = relevantEvents.findLastIndex((event) =>
142
+ ['NODE_COMPLETED', 'NODE_FAILED'].includes(event.type)
143
+ );
144
+ const finished = relevantEvents[finishedIndex];
145
+ const started = finishedIndex < 0
146
+ ? null
147
+ : relevantEvents.slice(0, finishedIndex).findLast((event) => event.type === 'NODE_STARTED');
148
+ const durationMs = runtime.status !== 'RUNNING' &&
149
+ started && finished && Date.parse(finished.at) >= Date.parse(started.at)
150
+ ? Date.parse(finished.at) - Date.parse(started.at)
151
+ : null;
152
+ let agentInteractions = [];
153
+ let agentInteractionsAvailable = true;
154
+ try {
155
+ agentInteractions = listRunInteractions(rootDir, runId).interactions.slice(-50);
156
+ } catch {
157
+ agentInteractionsAvailable = false;
158
+ }
113
159
  return redactedValue({
114
160
  runId,
115
161
  node: publicNode(node, workflow.state, workflow.plan.nodes.indexOf(node)),
162
+ durationMs,
163
+ loopIteration: runtime.loopIteration || null,
164
+ agentInteractionScope: 'RUN',
165
+ agentInteractionsAvailable,
166
+ agentInteractions,
116
167
  input: {
117
168
  task: node.dependsOn?.length ? null : run.task,
118
169
  constraints: node.dependsOn?.length ? null : (run.constraints || ''),
@@ -160,6 +211,8 @@ function duplicateRunAsRecipe(rootDir, runId, { recipeId } = {}) {
160
211
  function studioAgentHandoff(rootDir, runId) {
161
212
  const run = loadRun(rootDir, runId);
162
213
  const commandRoot = `npx ai-engineering-loop interaction`;
214
+ const lifecycleCommand = `npx ai-engineering-loop activity heartbeat --run ${runId} --phase <phase> --message "<factual update>"`;
215
+ const goalCommand = `npx ai-engineering-loop goal draft --run ${runId} --file <repository-relative-goal.json> --revision <current-revision>`;
163
216
  return redactedValue({
164
217
  runId,
165
218
  externalDispatch: false,
@@ -167,13 +220,17 @@ function studioAgentHandoff(rootDir, runId) {
167
220
  `Continue AI Engineering Loop Run ${runId}.`,
168
221
  `Task: ${run.task}`,
169
222
  run.constraints ? `Constraints: ${run.constraints}` : null,
170
- 'Read the Run state and evidence before acting.',
223
+ 'From the repository root, read the Run state and evidence before acting.',
224
+ `Draft the Goal through the Run-scoped bridge with: ${goalCommand}`,
225
+ `Report persisted lifecycle progress with: ${lifecycleCommand}`,
171
226
  `When blocked, ask with: ${commandRoot} question --run ${runId} --message "Your question"`,
172
227
  `Poll answers with: ${commandRoot} list --run ${runId} --json`,
173
228
  'Do not create a sibling Run or claim completion without Run-bound evidence.'
174
229
  ].filter(Boolean).join('\n'),
175
230
  commands: {
176
231
  inspect: `npx ai-engineering-loop status --run ${runId}`,
232
+ goalDraft: goalCommand,
233
+ lifecycle: lifecycleCommand,
177
234
  question: `${commandRoot} question --run ${runId} --message "Your question"`,
178
235
  answers: `${commandRoot} list --run ${runId} --json`
179
236
  }
@@ -182,6 +239,9 @@ function studioAgentHandoff(rootDir, runId) {
182
239
 
183
240
  module.exports = {
184
241
  duplicateRunAsRecipe,
242
+ edgeState,
243
+ edgesFromPlan,
244
+ redactedValue,
185
245
  runCheckout,
186
246
  runNodeIo,
187
247
  studioAgentHandoff
@@ -0,0 +1,75 @@
1
+ 'use strict';
2
+
3
+ const { loadGoalDraft } = require('./goal-runtime.js');
4
+ const { listRunInteractions } = require('./run-interactions.js');
5
+ const { readAllRunLifecycle } = require('./run-lifecycle.js');
6
+ const { loadRun } = require('./run-state.js');
7
+
8
+ const JOURNEY_STEPS = [
9
+ 'TASK_RECEIVED',
10
+ 'GOAL_DRAFTING',
11
+ 'WAITING_FOR_ANSWERS',
12
+ 'READY_FOR_GOAL_FREEZE',
13
+ 'WORKFLOW_EXECUTION',
14
+ 'RUN_COMPLETE'
15
+ ];
16
+ const TERMINAL_STATES = new Set(['DELIVERED', 'REPORTED', 'ESCALATED', 'CANCELLED']);
17
+
18
+ function runJourney(rootDir, runId, { workflowState = null } = {}) {
19
+ const run = loadRun(rootDir, runId);
20
+ let draft = null;
21
+ let draftAvailable = true;
22
+ let interactions = { pending: [] };
23
+ let interactionsAvailable = true;
24
+ let lifecycle = [];
25
+ let lifecycleAvailable = true;
26
+ try {
27
+ draft = loadGoalDraft(rootDir, runId);
28
+ } catch {
29
+ draftAvailable = false;
30
+ }
31
+ try {
32
+ interactions = listRunInteractions(rootDir, runId);
33
+ } catch {
34
+ interactionsAvailable = false;
35
+ }
36
+ try {
37
+ lifecycle = readAllRunLifecycle(rootDir, runId);
38
+ } catch {
39
+ lifecycleAvailable = false;
40
+ }
41
+ const workflowStarted = Object.values(workflowState?.nodes || {}).some((node) =>
42
+ ['RUNNING', 'PASSED', 'FAILED', 'SKIPPED'].includes(node.status)
43
+ ) || lifecycle.some((event) =>
44
+ ['NODE_STARTED', 'NODE_ACTIVITY', 'NODE_COMPLETED', 'NODE_FAILED', 'LOOP_ITERATED'].includes(event.type)
45
+ );
46
+ const goalFrozen = run.goal?.frozen === true ||
47
+ lifecycle.some((event) => event.type === 'GOAL_FROZEN');
48
+ const complete = TERMINAL_STATES.has(run.state);
49
+ let current = 'TASK_RECEIVED';
50
+ if (draft || lifecycle.some((event) => event.type === 'GOAL_DRAFTING')) current = 'GOAL_DRAFTING';
51
+ if (draft && interactionsAvailable && interactions.pending.length === 0) current = 'READY_FOR_GOAL_FREEZE';
52
+ if (interactions.pending.length > 0 && !workflowStarted) current = 'WAITING_FOR_ANSWERS';
53
+ if (goalFrozen || workflowStarted) current = 'WORKFLOW_EXECUTION';
54
+ if (complete) current = 'RUN_COMPLETE';
55
+ const currentIndex = JOURNEY_STEPS.indexOf(current);
56
+ return {
57
+ runId,
58
+ current,
59
+ blocked: interactionsAvailable ? interactions.pending.length > 0 : null,
60
+ pendingQuestions: interactionsAvailable ? interactions.pending.length : null,
61
+ degradedSources: [
62
+ draftAvailable ? null : 'Goal draft',
63
+ interactionsAvailable ? null : 'Agent Interaction',
64
+ lifecycleAvailable ? null : 'Lifecycle activity'
65
+ ].filter(Boolean),
66
+ sources: { draftAvailable, interactionsAvailable, lifecycleAvailable },
67
+ steps: JOURNEY_STEPS.map((id, index) => ({
68
+ id,
69
+ status: index < currentIndex ? 'COMPLETE' : (index === currentIndex ? 'ACTIVE' : 'PENDING'),
70
+ ...(id === 'WAITING_FOR_ANSWERS' && interactions.pending.length > 0 ? { blocked: true } : {})
71
+ }))
72
+ };
73
+ }
74
+
75
+ module.exports = { JOURNEY_STEPS, runJourney };
@@ -12,15 +12,20 @@ const TYPES = new Set([
12
12
  'GOAL_DRAFTING',
13
13
  'GOAL_DRAFT_UPDATED',
14
14
  'GOAL_READY',
15
+ 'GOAL_FROZEN',
16
+ 'PHASE_COMPLETED',
15
17
  'AGENT_HEARTBEAT',
16
18
  'AGENT_WAITING',
17
19
  'NODE_STARTED',
18
20
  'NODE_ACTIVITY',
19
21
  'NODE_COMPLETED',
22
+ 'NODE_FAILED',
20
23
  'LOOP_ITERATED',
21
24
  'RUN_COMPLETED'
22
25
  ]);
23
26
  const ID = /^[A-Za-z0-9@._-]{1,64}$/;
27
+ const NODE_TYPES = new Set(['NODE_STARTED', 'NODE_ACTIVITY', 'NODE_COMPLETED', 'NODE_FAILED']);
28
+ const STATUSES = new Set(['WORKING', 'WAITING', 'PASSED', 'FAILED', 'SKIPPED', 'UNKNOWN']);
24
29
  const LOCK_STALE_MS = 60_000;
25
30
 
26
31
  function lifecycleError(message, code) {
@@ -98,6 +103,33 @@ function appendRunLifecycle(rootDir, runId, event, { now = new Date() } = {}) {
98
103
  if ((phase && !ID.test(phase)) || (nodeId && !ID.test(nodeId))) {
99
104
  throw lifecycleError('Lifecycle phase or node is invalid', 'INVALID_LIFECYCLE_SCOPE');
100
105
  }
106
+ const run = loadRun(rootDir, runId);
107
+ if (NODE_TYPES.has(event.type)) {
108
+ if (!nodeId) throw lifecycleError('Node lifecycle events require a node Technical ID', 'INVALID_LIFECYCLE_SCOPE');
109
+ if (!run.workflow) throw lifecycleError('Classic Runs cannot publish node-scoped activity', 'INVALID_LIFECYCLE_SCOPE');
110
+ const { workflowStatus } = require('./workflow-runtime.js');
111
+ const workflow = workflowStatus(rootDir, { runId });
112
+ if (!workflow.plan.nodes.some((node) => node.id === nodeId)) {
113
+ throw lifecycleError(`Node ${nodeId} is not part of Run ${runId}`, 'INVALID_LIFECYCLE_SCOPE');
114
+ }
115
+ } else if (nodeId) {
116
+ throw lifecycleError('Run lifecycle events cannot claim a node scope', 'INVALID_LIFECYCLE_SCOPE');
117
+ }
118
+ const status = event.status == null ? null : String(event.status).trim().toUpperCase();
119
+ if (status && !STATUSES.has(status)) {
120
+ throw lifecycleError('Lifecycle status is invalid', 'INVALID_LIFECYCLE_STATUS');
121
+ }
122
+ let evidence = null;
123
+ if (event.evidence != null) {
124
+ const evidencePath = String(event.evidence.path || '').trim();
125
+ const evidenceHash = event.evidence.sha256 == null ? null : String(event.evidence.sha256).trim();
126
+ if (!evidencePath || evidencePath.length > 240 || path.isAbsolute(evidencePath) ||
127
+ evidencePath.split(/[\\/]/).includes('..') ||
128
+ (evidenceHash && !/^[a-f0-9]{64}$/.test(evidenceHash))) {
129
+ throw lifecycleError('Lifecycle evidence reference is invalid', 'INVALID_LIFECYCLE_EVIDENCE');
130
+ }
131
+ evidence = { path: evidencePath, ...(evidenceHash ? { sha256: evidenceHash } : {}) };
132
+ }
101
133
  const message = redactSecrets(String(event.message || '').trim()).text;
102
134
  if (!message || message.length > 240 ||
103
135
  /[\u0000-\u0008\u000b\u000c\u000e-\u001f]/.test(message)) {
@@ -117,7 +149,9 @@ function appendRunLifecycle(rootDir, runId, event, { now = new Date() } = {}) {
117
149
  actor,
118
150
  message,
119
151
  ...(phase ? { phase } : {}),
120
- ...(nodeId ? { nodeId } : {})
152
+ ...(nodeId ? { nodeId } : {}),
153
+ ...(status ? { status } : {}),
154
+ ...(evidence ? { evidence } : {})
121
155
  };
122
156
  const result = { ...material, hash: sha256(material) };
123
157
  fs.appendFileSync(lifecyclePath(rootDir, runId), `${JSON.stringify(result)}\n`, {
@@ -144,6 +178,10 @@ function listRunLifecycle(rootDir, runId, { after = 0, limit = 100 } = {}) {
144
178
  };
145
179
  }
146
180
 
181
+ function readAllRunLifecycle(rootDir, runId) {
182
+ return readLifecycle(rootDir, runId);
183
+ }
184
+
147
185
  function runAgentPresence(rootDir, runId, { now = new Date() } = {}) {
148
186
  const events = readLifecycle(rootDir, runId);
149
187
  const last = events.findLast((event) => event.type === 'AGENT_HEARTBEAT');
@@ -160,5 +198,6 @@ module.exports = {
160
198
  MAX_EVENTS,
161
199
  appendRunLifecycle,
162
200
  listRunLifecycle,
201
+ readAllRunLifecycle,
163
202
  runAgentPresence
164
203
  };
@@ -89,6 +89,16 @@ function redactSecrets(input) {
89
89
  return { text, categories: [...categories].sort() };
90
90
  }
91
91
 
92
+ function redactHomePaths(input) {
93
+ return String(input ?? '')
94
+ .replace(/(?:file:\/\/)?\/Users\/[A-Za-z0-9._-]+/g, '[REDACTED HOME]')
95
+ .replace(/(?:file:\/\/)?\/home\/[A-Za-z0-9._-]+/g, '[REDACTED HOME]')
96
+ .replace(/(?:file:\/\/)?\/root(?=\/|\\|$)/g, '[REDACTED HOME]')
97
+ .replace(/(?:file:\/\/)?(?:\/private)?\/var\/folders\/[A-Za-z0-9._/-]+/g, '[REDACTED TMP]')
98
+ .replace(/\b[A-Za-z]:\\Users\\[A-Za-z0-9._-]+/g, '[REDACTED HOME]')
99
+ .replace(/\\\\[A-Za-z0-9._-]+\\[A-Za-z0-9._$-]+/g, '[REDACTED HOME]');
100
+ }
101
+
92
102
  function sha256(content) {
93
103
  return crypto.createHash('sha256').update(content).digest('hex');
94
104
  }
@@ -188,6 +198,7 @@ module.exports = {
188
198
  isSensitivePath,
189
199
  resolveSafeRepoFile,
190
200
  redactSecrets,
201
+ redactHomePaths,
191
202
  estimateTokens,
192
203
  createContextPack,
193
204
  contextPackSummary
@@ -56,7 +56,7 @@ function createStudioRun(
56
56
  };
57
57
  throw error;
58
58
  }
59
- const loaded = loadRecipe(rootDir, recipeId);
59
+ const loaded = loadRecipe(rootDir, recipeId || 'default');
60
60
  const plan = compileRecipe(loaded.recipe, { mode: normalizedMode });
61
61
  const runId = newRunId(now);
62
62
  const workflow = createWorkflowBundle(plan, runId, {
@@ -29,6 +29,8 @@ const {
29
29
  const { listRunHistory, runHistoryDetail, inspectRunArtifact } = require('./run-history.js');
30
30
  const {
31
31
  duplicateRunAsRecipe,
32
+ edgesFromPlan,
33
+ redactedValue,
32
34
  runCheckout,
33
35
  runNodeIo,
34
36
  studioAgentHandoff
@@ -40,6 +42,7 @@ const {
40
42
  } = require('./run-interactions.js');
41
43
  const { saveGoalDraft, loadGoalDraft, freezeGoal, unfreezeGoal } = require('./goal-runtime.js');
42
44
  const { appendRunLifecycle, listRunLifecycle, runAgentPresence } = require('./run-lifecycle.js');
45
+ const { runJourney } = require('./run-journey.js');
43
46
  const { cancelStudioRun, createStudioRun, executeStudioRun } = require('./studio-runtime.js');
44
47
  const { createHandoff, handoffBrief, recordDecision } = require('./handoff.js');
45
48
  const { loadStudioLayout, saveStudioLayout } = require('./studio-layout.js');
@@ -105,17 +108,31 @@ function liveSnapshot(rootDir) {
105
108
  const run = getCurrentRun(rootDir);
106
109
  if (!run?.workflow) return null;
107
110
  const workflow = workflowStatus(rootDir, { runId: run.runId });
108
- return {
111
+ return redactedValue({
109
112
  run,
110
113
  plan: workflow.plan,
111
114
  nodes: workflow.state.nodes,
115
+ edges: edgesFromPlan(workflow.plan, workflow.state),
112
116
  loopGroups: workflow.state.loopGroups,
117
+ journey: (() => {
118
+ try {
119
+ return runJourney(rootDir, run.runId, { workflowState: workflow.state });
120
+ } catch {
121
+ return {
122
+ runId: run.runId,
123
+ current: 'UNKNOWN',
124
+ pendingQuestions: 0,
125
+ sources: { available: false },
126
+ steps: []
127
+ };
128
+ }
129
+ })(),
113
130
  budget: budgetStatus(rootDir, { runId: run.runId }),
114
131
  events: workflow.events.slice(-50).map(({ initialNodes, changes, ...event }) => ({
115
132
  ...event,
116
133
  changedNodes: (changes || []).map((change) => change.nodeId)
117
134
  }))
118
- };
135
+ });
119
136
  }
120
137
 
121
138
  function bootstrap(rootDir) {
@@ -366,7 +383,7 @@ function createStudioServer(rootDir, { token = crypto.randomBytes(24).toString('
366
383
  expectedHash: body.expectedHash
367
384
  });
368
385
  appendRunLifecycle(rootDir, runId, {
369
- type: 'NODE_COMPLETED',
386
+ type: 'GOAL_FROZEN',
370
387
  phase: 'goal',
371
388
  actor: body.actor || 'studio-user',
372
389
  message: 'Goal Contract frozen in Studio'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-engineering-loop",
3
- "version": "1.9.4",
3
+ "version": "1.10.0",
4
4
  "description": "A visual workspace that helps AI coding agents plan, build, review, and ship reliable software.",
5
5
  "main": "bin/ai-engineering-loop.js",
6
6
  "bin": {
package/studio/app.js CHANGED
@@ -41,6 +41,9 @@ let agentPresence = { status: 'UNKNOWN', lastHeartbeatAt: null };
41
41
  let followExecution = true;
42
42
  let lastFollowedNode;
43
43
  let lifecycleStream;
44
+ let handoffCopiedRunId;
45
+ let onboardingDismissed = false;
46
+ let liveRenderScheduled = false;
44
47
 
45
48
  const DISPLAY_NAME_MAX = 80;
46
49
  const ROOT_TYPES = new Set(['goal-contract', 'trigger']);
@@ -302,15 +305,10 @@ function renderEdges() {
302
305
  if (!from || !to) return;
303
306
  const path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
304
307
  path.setAttribute('d', edgePath(from, to));
305
- const fromState = catalog.live?.nodes?.[edge.from]?.status;
306
- const toState = catalog.live?.nodes?.[edge.to]?.status;
307
- const liveNodeId = activeLifecycleNodeId();
308
- const active = liveNodeId === edge.to && ['PASSED', 'SKIPPED'].includes(fromState);
309
- const completed = ['PASSED', 'SKIPPED'].includes(fromState) &&
310
- ['PASSED', 'SKIPPED', 'RUNNING'].includes(toState);
308
+ const state = catalog.live?.edges?.find((candidate) => candidate.id === edge.id)?.state || 'idle';
311
309
  path.setAttribute(
312
310
  'class',
313
- `edge${active ? ' active' : ''}${completed ? ' completed' : ''}${selectedEdgeId === edge.id ? ' selected' : ''}`
311
+ `edge edge-${state}${selectedEdgeId === edge.id ? ' selected' : ''}`
314
312
  );
315
313
  path.setAttribute('marker-end', 'url(#arrow)');
316
314
  path.dataset.edgeId = edge.id;
@@ -1196,6 +1194,7 @@ async function ensureStudioRun() {
1196
1194
  });
1197
1195
  }
1198
1196
  activeRunId = created.run.runId;
1197
+ renderHandoffState();
1199
1198
  await refreshLive();
1200
1199
  return activeRunId;
1201
1200
  }
@@ -1203,20 +1202,31 @@ async function ensureStudioRun() {
1203
1202
  function resolveActiveRunConflict(run) {
1204
1203
  return new Promise((resolve) => {
1205
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
+ };
1206
1211
  byId('active-run-message').textContent = `${run.displayName || run.runId} · ${run.state}`;
1207
1212
  byId('continue-active-run').onclick = async () => {
1208
- dialog.close();
1209
1213
  activeRunId = run.runId;
1214
+ renderHandoffState();
1210
1215
  byId('goal-dialog').close();
1211
1216
  showWorkspace('runs');
1212
1217
  await loadRuns();
1213
1218
  await loadRunDetail(run.runId);
1214
- resolve('continue');
1219
+ finish('continue');
1220
+ dialog.close();
1221
+ };
1222
+ byId('cancel-active-run-conflict').onclick = () => {
1223
+ dialog.close();
1215
1224
  };
1216
1225
  byId('replace-active-run').onclick = () => {
1226
+ finish('replace');
1217
1227
  dialog.close();
1218
- resolve('replace');
1219
1228
  };
1229
+ dialog.addEventListener('close', () => finish('cancel'), { once: true });
1220
1230
  dialog.showModal();
1221
1231
  });
1222
1232
  }
@@ -1292,7 +1302,17 @@ async function reviewGoal() {
1292
1302
  byId('goal-review').hidden = false;
1293
1303
  byId('goal-review').innerHTML = `
1294
1304
  <strong>${escapeHtml(contract.objective)}</strong>
1295
- <p>${contract.acceptanceCriteria.length} numbered acceptance failure rows are ready.</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>
1296
1316
  `;
1297
1317
  byId('confirm-freeze').hidden = false;
1298
1318
  }
@@ -1356,6 +1376,7 @@ function syncGoalFromLive() {
1356
1376
  hydratedGoalKey = null;
1357
1377
  }
1358
1378
  activeRunId = nextRunId;
1379
+ renderHandoffState();
1359
1380
  if (!liveGoal) {
1360
1381
  renderGoalState();
1361
1382
  return;
@@ -1431,13 +1452,23 @@ function startLifecycleStream(runId) {
1431
1452
  ).slice(-100);
1432
1453
  lifecycleSequence = Math.max(lifecycleSequence, result.lifecycle.nextSequence);
1433
1454
  agentPresence = result.presence;
1434
- renderLive();
1455
+ scheduleLiveRender();
1435
1456
  } catch {
1436
1457
  // The regular cursor poll remains the recovery path.
1437
1458
  }
1438
1459
  };
1439
1460
  }
1440
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
+
1441
1472
  function setFollowExecution(enabled) {
1442
1473
  followExecution = enabled;
1443
1474
  const button = byId('follow-execution');
@@ -1555,7 +1586,10 @@ async function loadRunDetail(runId) {
1555
1586
  const y1 = from.position.y + NODE_PORT_Y;
1556
1587
  const x2 = to.position.x;
1557
1588
  const y2 = to.position.y + NODE_PORT_Y;
1558
- return `<path d="M ${x1} ${y1} C ${x1 + 70} ${y1}, ${x2 - 70} ${y2}, ${x2} ${y2}"></path>`;
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>`;
1559
1593
  }).join('');
1560
1594
  const checkoutGroups = (checkout.loopGroups || []).map((group) => {
1561
1595
  const members = checkout.nodes.filter((node) => group.nodeIds.includes(node.id));
@@ -1637,14 +1671,32 @@ async function loadNodeIo(runId, nodeId) {
1637
1671
  const panel = byId('node-io-panel');
1638
1672
  try {
1639
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.';
1640
1678
  panel.innerHTML = `
1641
- <header><small>NODE I/O · ${escapeHtml(io.node.status)}</small><h3>${escapeHtml(io.node.displayName)}</h3></header>
1642
- <div class="io-grid">
1643
- <section><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>
1644
- <section><h4>Output</h4><p><b>${escapeHtml(io.output.status)}</b>${io.output.reason ? ` · ${escapeHtml(io.output.reason)}` : ''}</p>${renderArtifactPreview(io.output.artifact)}</section>
1645
- <section><h4>Evidence</h4>${renderArtifactPreview(io.evidence)}</section>
1646
- <section><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>
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>
1647
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
+ });
1648
1700
  panel.querySelectorAll('[data-artifact-download]').forEach((button) => {
1649
1701
  button.onclick = async () => {
1650
1702
  try {
@@ -1744,16 +1796,27 @@ async function refreshSelectedCheckout() {
1744
1796
 
1745
1797
  async function copyAgentHandoff(runId = activeRunId) {
1746
1798
  try {
1747
- if (!runId) await ensureStudioRun();
1748
- const result = await api(`/api/runs/${encodeURIComponent(runId || activeRunId)}/agent-handoff`);
1799
+ const targetRunId = runId || await ensureStudioRun();
1800
+ if (!targetRunId) return;
1801
+ const result = await api(`/api/runs/${encodeURIComponent(targetRunId)}/agent-handoff`);
1749
1802
  await navigator.clipboard.writeText(result.handoff.prompt);
1750
- byId('goal-dialog').close();
1803
+ handoffCopiedRunId = targetRunId;
1804
+ renderHandoffState();
1751
1805
  notify('Run-bound prompt copied. Paste it into your AI coding Agent.');
1752
1806
  } catch (error) {
1753
1807
  byId('goal-validation').textContent = error.message;
1754
1808
  }
1755
1809
  }
1756
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
+
1757
1820
  function showWorkspace(section) {
1758
1821
  const showingRuns = section === 'runs';
1759
1822
  byId('runs-view').hidden = !showingRuns;
@@ -1997,6 +2060,8 @@ function renderLive() {
1997
2060
  byId('meter').style.width = '0';
1998
2061
  byId('agent-presence').textContent = 'Agent unavailable';
1999
2062
  byId('agent-presence').className = 'agent-presence unknown';
2063
+ const dock = byId('run-activity-dock');
2064
+ if (dock) dock.hidden = true;
2000
2065
  updateRuntimePresentation();
2001
2066
  return;
2002
2067
  }
@@ -2010,6 +2075,23 @@ function renderLive() {
2010
2075
  byId('active-stage').textContent = active?.id || 'Run complete';
2011
2076
  byId('activity').textContent = lifecycle?.message ||
2012
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
+ : '');
2013
2095
  const presenceLabel = {
2014
2096
  WORKING: 'Agent working',
2015
2097
  IDLE: 'Agent appears idle',
@@ -2029,10 +2111,34 @@ function renderLive() {
2029
2111
  `).join('') || live.events.slice(-7).reverse().map((event) => `
2030
2112
  <p>${escapeHtml(event.at.slice(11, 19))} · ${escapeHtml(event.type)}</p>
2031
2113
  `).join('');
2114
+ renderRunActivityDock(live, active, runtimeNode, lifecycle);
2032
2115
  updateRuntimePresentation();
2033
2116
  followActiveNode();
2034
2117
  }
2035
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();
2140
+ }
2141
+
2036
2142
  async function refreshLive() {
2037
2143
  try {
2038
2144
  const result = await api('/api/live');
@@ -2041,12 +2147,19 @@ async function refreshLive() {
2041
2147
  await refreshLifecycle(catalog.live?.run?.runId);
2042
2148
  await refreshGoalDraft(catalog.live?.run?.runId);
2043
2149
  await hydrateGoalFromLive();
2150
+ byId('live-connection-state').hidden = true;
2044
2151
  renderLive();
2045
2152
  await refreshSelectedCheckout();
2046
2153
  await refreshCheckoutInteractions();
2047
2154
  if (!byId('runs-view').hidden) await loadRuns();
2155
+ maybeOpenOnboarding();
2156
+ return true;
2048
2157
  } catch {
2049
- // 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;
2050
2163
  }
2051
2164
  }
2052
2165
 
@@ -2348,6 +2461,19 @@ async function initialize() {
2348
2461
  byId('close-inspector').onclick = () => byId('inspector-panel').classList.remove('open');
2349
2462
  byId('toggle-execution').onclick = () => byId('execution-panel').classList.toggle('open');
2350
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
+ });
2351
2477
  await loadRecipe();
2352
2478
  await refreshLive();
2353
2479
  clearInterval(liveTimer);
package/studio/index.html CHANGED
@@ -57,6 +57,20 @@
57
57
  <output id="zoom-level">100%</output>
58
58
  <button id="zoom-in" aria-label="Zoom in">+</button>
59
59
  </div>
60
+ <aside id="run-activity-dock" class="run-activity-dock" aria-live="polite" hidden>
61
+ <span class="activity-orbit" aria-hidden="true"></span>
62
+ <div class="run-activity-copy">
63
+ <small id="run-activity-scope">RUN ACTIVITY</small>
64
+ <strong id="run-activity-title">Waiting for activity</strong>
65
+ <p id="run-activity-message">Persisted Agent activity will appear here.</p>
66
+ </div>
67
+ <div class="run-activity-actions">
68
+ <span id="run-activity-status" class="mono">WAITING</span>
69
+ <button id="inspect-live-node" type="button" hidden>Inspect node</button>
70
+ <button id="open-live-details" type="button">Open live details</button>
71
+ </div>
72
+ <div id="run-activity-timeline" class="run-activity-timeline"></div>
73
+ </aside>
60
74
  <div id="scene">
61
75
  <div id="loop-groups"></div>
62
76
  <svg id="edges" aria-hidden="true">
@@ -105,8 +119,13 @@
105
119
 
106
120
  <aside class="execution-panel" id="execution-panel">
107
121
  <div class="panel-head"><div><small>LIVE EXECUTION</small><h2 id="active-stage">No active run</h2></div><button id="close-execution" aria-label="Close">×</button></div>
122
+ <div id="live-connection-state" class="validation-message" role="status" hidden>
123
+ <span id="live-connection-message"></span>
124
+ <button id="retry-live-connection" type="button">Retry now</button>
125
+ </div>
108
126
  <div class="live-controls"><span id="agent-presence" class="agent-presence unknown">Agent unavailable</span><button id="follow-execution" type="button" aria-pressed="true">Follow execution</button></div>
109
127
  <p id="activity">Waiting for a recipe-bound workflow.</p>
128
+ <ol id="run-journey" class="run-journey" aria-label="Run progress"></ol>
110
129
  <div class="budget-line"><span>Context budget</span><span class="mono" id="budget">—</span></div>
111
130
  <div class="meter"><i id="meter"></i></div>
112
131
  <details>
@@ -162,10 +181,11 @@
162
181
  <form id="goal-form">
163
182
  <header><div><small>GOAL CONTRACT <span id="goal-version">V1</span></small><h2>Start a reliable run</h2></div><div class="dialog-actions"><button type="button" class="dialog-maximize" aria-label="Maximize dialog">□</button><button type="button" data-close="goal-dialog" aria-label="Close">×</button></div></header>
164
183
  <div id="goal-state" class="goal-state draft">Draft · editing allowed</div>
165
- <label for="goal-task">What should the AI Agent deliver?</label><textarea id="goal-task" maxlength="2000" placeholder="Improve Workflow Studio canvas"></textarea>
166
- <label for="goal-constraints">Anything it must keep or avoid? <span class="muted">(optional)</span></label><textarea id="goal-constraints" maxlength="8000" placeholder="Keep existing CLI behavior and do not change the page layout."></textarea>
167
- <details class="advanced-goal">
168
- <summary>Review the Agent's success plan</summary>
184
+ <label for="goal-task">What should the AI Agent deliver?</label><textarea id="goal-task" maxlength="2000" required aria-describedby="goal-task-help" placeholder="Improve Workflow Studio canvas"></textarea>
185
+ <p id="goal-task-help" class="hint">Describe one task. Studio will create one Run and prepare a Run-bound handoff.</p>
186
+ <details id="goal-advanced" class="advanced-goal">
187
+ <summary>Advanced Goal options</summary>
188
+ <label for="goal-constraints">Anything it must keep or avoid? <span class="muted">(optional)</span></label><textarea id="goal-constraints" maxlength="8000" placeholder="Keep existing CLI behavior and do not change the page layout."></textarea>
169
189
  <label for="goal-run-name">Run Display Name</label><input id="goal-run-name" maxlength="100" placeholder="Automatically named from the task">
170
190
  <label for="goal-text">Objective</label><textarea id="goal-text" maxlength="12000" placeholder="The Agent drafts this from your task."></textarea>
171
191
  <label for="goal-criteria">Success checks and failure cases</label>
@@ -173,12 +193,16 @@
173
193
  <p class="hint">The AI Agent drafts these checks. Review them before Freeze.</p>
174
194
  </details>
175
195
  <div id="goal-validation" class="validation-message" aria-live="polite"></div>
196
+ <section id="agent-handoff-state" class="agent-handoff-state" aria-live="polite" hidden>
197
+ <strong>Prompt copied</strong>
198
+ <p id="agent-handoff-instructions">Paste it once into your current AI Agent terminal, then keep Studio open to follow persisted progress.</p>
199
+ </section>
176
200
  <section id="goal-review" class="goal-review" hidden></section>
177
201
  <div id="unfreeze-fields" hidden><label for="unfreeze-reason">Reason for unfreezing</label><textarea id="unfreeze-reason" maxlength="500"></textarea></div>
178
202
  <footer>
179
203
  <button type="button" id="save-goal">Save draft</button>
180
204
  <button type="button" id="unfreeze-goal" hidden>Unfreeze…</button>
181
- <button type="button" id="start-agent" class="primary">Copy for AI Agent</button>
205
+ <button type="button" id="start-agent" class="primary" aria-describedby="agent-handoff-instructions">Start with AI Agent</button>
182
206
  <button type="button" id="review-goal">Review &amp; Freeze</button>
183
207
  <button type="button" id="confirm-freeze" class="primary" hidden>Confirm freeze</button>
184
208
  </footer>
@@ -189,6 +213,7 @@
189
213
  <p id="active-run-message"></p>
190
214
  <div class="goal-state draft">Starting a new Goal will end the current Run. Its history and evidence will remain available.</div>
191
215
  <footer>
216
+ <button type="button" id="cancel-active-run-conflict">Cancel</button>
192
217
  <button type="button" id="continue-active-run">Continue current Run</button>
193
218
  <button type="button" id="replace-active-run" class="primary">End Run &amp; create new Goal</button>
194
219
  </footer>
package/studio/styles.css CHANGED
@@ -50,3 +50,10 @@ dialog{border:1px solid #505057;border-radius:4px;background:var(--panel);color:
50
50
  .wide-dialog{width:min(800px,calc(100vw - 40px))}dialog header{display:flex;align-items:flex-start;justify-content:space-between}dialog header h2{margin:4px 0 18px;font-size:24px;letter-spacing:-.03em}dialog header button{border:0;background:transparent;font-size:20px}dialog label{clear:both;font-size:12px;color:#c7c7cd}dialog input,dialog textarea{width:100%;margin:0 0 18px;padding:12px;border:1px solid #4b4b52;border-radius:3px;background:#19191c;font-size:14px;line-height:1.55}.field-grid{display:grid;grid-template-columns:1fr 1fr;gap:12px}.field-grid.thirds{grid-template-columns:repeat(3,1fr)}.criteria-editor{min-height:170px}.advanced-goal{margin:16px 0;padding:16px;border:1px solid var(--line)}.advanced-goal summary{font-weight:650;margin-bottom:12px}.import-preview,.goal-review{margin:14px 0;padding:16px;border:1px solid var(--line);border-radius:3px;background:#1e1e22}.validation-message{color:#ff9999;line-height:1.55}.goal-state{position:relative;overflow:hidden;margin-bottom:18px;padding:12px;border-radius:3px}.goal-state.draft{background:#493817;color:#f4c46b}.goal-state.frozen{background:var(--accent-soft);color:#91dc7c}.goal-state.frozen::after{content:"❄";position:absolute;right:12px;animation:freeze-pop .7s ease-out both}@keyframes freeze-pop{from{opacity:0;transform:scale(2.4) rotate(-25deg)}to{opacity:1;transform:scale(1) rotate(0)}}.muted{color:var(--muted)}
51
51
  @media(max-width:900px){.run-summary,.secure,#workflow-settings{display:none}.inspector{width:min(360px,calc(100% - 76px))}.library{width:min(300px,calc(100% - 76px))}.canvas-help{display:none}.runs-header{display:block}.run-filters{flex-wrap:wrap}.run-search{width:100%;flex-basis:100%}.runs-layout{grid-template-columns:1fr}.field-grid,.field-grid.thirds,.io-grid{grid-template-columns:1fr}.workspace-tab{padding-inline:8px}.timeline p{grid-template-columns:1fr}.checkout-header{display:block}.checkout-actions{margin-top:14px}.resizable-dialog{min-width:calc(100vw - 24px)}}
52
52
  @media(prefers-reduced-motion:reduce){.edge.active,.goal-state.frozen::after{animation:none}.library,.inspector,.execution-panel,.node{transition:none}}
53
+
54
+ /* Persisted execution states: quiet, legible, and semantic rather than decorative. */
55
+ .node.running,.node.agent-active{border:1px solid var(--accent);box-shadow:0 0 0 1px #28ad0048,0 16px 34px #0008;animation:node-breathe 1.8s ease-in-out infinite}.node.passed{border:1px solid #53614f;box-shadow:0 7px 18px #0005}.node.passed::after,.node.failed::after,.node.skipped::after{position:absolute;right:12px;top:12px;padding:3px 6px;border:1px solid #586154;border-radius:3px;color:#a9c3a2;background:#252a24;content:"✓ PASSED";font:8px ui-monospace,monospace;letter-spacing:.08em}.node.failed::after{content:"× FAILED";border-color:#745150;color:#e09b97;background:#2b2222}.node.skipped::after{content:"— SKIPPED";border-color:#585860;color:#aaaab2;background:#28282d}.node.failed{border-color:#8b4a47}.node.skipped{opacity:.68;border-style:dashed}.node.blocked,.node.waiting{border-color:#806b43;border-style:dashed}.edge.edge-idle{stroke:#66666e}.edge.edge-active{stroke:var(--accent);stroke-width:3;stroke-dasharray:8 10;animation:flow .8s linear infinite}.edge.edge-passed{stroke:#71806d}.edge.edge-failed{stroke:var(--danger);stroke-width:2.5}.edge.edge-skipped{stroke:#696971;stroke-dasharray:4 7}.edge.edge-waiting{stroke:var(--warning);stroke-dasharray:2 7}.checkout-canvas path.edge-active{stroke:var(--accent);stroke-width:3;stroke-dasharray:8 10;animation:flow .8s linear infinite}.checkout-canvas path.edge-passed{stroke:#71806d}.checkout-canvas path.edge-failed{stroke:var(--danger);stroke-width:2.5}.checkout-canvas path.edge-skipped{stroke:#696971;stroke-dasharray:4 7}.checkout-canvas path.edge-waiting{stroke:var(--warning);stroke-dasharray:2 7}.checkout-node.status-running{border:1px solid var(--accent);box-shadow:0 0 0 1px #28ad0048,6px 8px 0 #111114;animation:node-breathe 1.8s ease-in-out infinite}.checkout-node.status-passed{border:1px solid #53614f;box-shadow:6px 6px 0 #111114}.checkout-node.status-passed::after{position:absolute;right:12px;top:12px;padding:3px 6px;border:1px solid #586154;border-radius:3px;color:#a9c3a2;background:#252a24;content:"✓ PASSED";font:8px ui-monospace,monospace;letter-spacing:.08em}@keyframes node-breathe{50%{border-color:#77ce5f;box-shadow:0 0 0 2px #28ad0038,0 18px 38px #0009}}
56
+ .run-activity-dock{position:absolute;z-index:20;top:66px;left:50%;width:min(760px,calc(100% - 64px));transform:translateX(-50%);display:grid;grid-template-columns:auto minmax(0,1fr) auto;gap:12px 16px;align-items:center;padding:13px 15px;border:1px solid #4b4b52;border-radius:7px;background:#252529f7;box-shadow:0 16px 34px #0008}.run-activity-dock[hidden]{display:none}.activity-orbit{width:10px;height:10px;border:2px solid var(--accent);border-radius:50%;box-shadow:0 0 0 4px #28ad0018;animation:activity-orbit 1.5s ease-in-out infinite}.run-activity-copy{min-width:0}.run-activity-copy small{display:block;margin-bottom:3px;color:#91dc7c;font:8px ui-monospace,monospace;letter-spacing:.12em}.run-activity-copy strong,.run-activity-copy p{display:block;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.run-activity-copy p{margin:3px 0 0;color:var(--muted);font-size:11px}.run-activity-actions{display:flex;align-items:center;gap:7px}.run-activity-actions .mono{color:var(--muted);font-size:9px}.run-activity-timeline{grid-column:2/-1;display:flex;gap:12px;min-width:0;overflow:hidden;border-top:1px solid #3d3d43;padding-top:7px}.run-activity-timeline span{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:#aaaab1;font-size:9px}.run-activity-timeline time{margin-right:5px;color:#73737c;font-family:ui-monospace,monospace}@keyframes activity-orbit{50%{transform:scale(.72);opacity:.58}}
57
+ .node-io-head{display:flex;justify-content:space-between;gap:20px;align-items:flex-start}.node-io-head p{margin:2px 0;color:var(--muted);font-size:9px}.io-tabs{display:flex;gap:2px;margin-top:18px;border-bottom:1px solid var(--line);overflow-x:auto}.io-tab{border:0;border-bottom:2px solid transparent;border-radius:0;background:transparent;color:var(--muted);white-space:nowrap}.io-tab[aria-selected=true]{border-bottom-color:var(--accent);color:var(--text)}.node-data-grid{display:grid;grid-template-columns:1fr 1fr;gap:1px;background:var(--line)}.io-pane{display:none;min-width:0;min-height:250px;padding:18px;background:#202024}.io-pane.active{display:block}.io-pane h4{margin-top:0;color:#91dc7c;font-size:10px;letter-spacing:.12em;text-transform:uppercase}.io-pane pre{max-height:280px;overflow:auto;white-space:pre-wrap;background:#151518;padding:13px;font-size:11px}.node-progress{padding:10px;border-left:2px solid var(--accent);background:#242a22;color:#c3d9bd}
58
+ @media(max-width:900px){.run-activity-dock{top:58px;width:calc(100% - 24px);grid-template-columns:auto minmax(0,1fr)}.run-activity-actions,.run-activity-timeline{grid-column:2}.run-activity-actions{flex-wrap:wrap}}
59
+ @media(prefers-reduced-motion:reduce){.edge.edge-active,.checkout-canvas path.edge-active,.node.running,.node.agent-active,.checkout-node.status-running,.activity-orbit{animation:none}}