astrocode-workflow 0.4.2 → 0.4.3
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/dist/src/hooks/inject-provider.js +23 -0
- package/dist/src/tools/workflow.js +24 -27
- package/package.json +1 -1
- package/src/hooks/inject-provider.ts +24 -0
- package/src/tools/workflow.ts +24 -27
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { selectEligibleInjects } from "../tools/injects";
|
|
2
2
|
import { injectChatPrompt } from "../ui/inject";
|
|
3
3
|
import { nowISO } from "../shared/time";
|
|
4
|
+
import { getActiveRun } from "../workflow/state-machine";
|
|
4
5
|
export function createInjectProvider(opts) {
|
|
5
6
|
const { ctx, config, runtime } = opts;
|
|
6
7
|
const { db } = runtime;
|
|
@@ -184,6 +185,28 @@ export function createInjectProvider(opts) {
|
|
|
184
185
|
await maybeAutoApprove(sessionId);
|
|
185
186
|
// Inject eligible injects after workflow tool execution
|
|
186
187
|
await injectEligibleInjects(sessionId, `tool_after:${input.tool}`);
|
|
188
|
+
// Inject Workflow Pulse if a run is active
|
|
189
|
+
await maybeInjectWorkflowPulse(sessionId);
|
|
187
190
|
},
|
|
188
191
|
};
|
|
192
|
+
async function maybeInjectWorkflowPulse(sessionId) {
|
|
193
|
+
if (!db)
|
|
194
|
+
return;
|
|
195
|
+
try {
|
|
196
|
+
const active = getActiveRun(db);
|
|
197
|
+
if (!active)
|
|
198
|
+
return;
|
|
199
|
+
const agentSuffix = active.current_stage_key ? ` (Agent: ${active.current_stage_key})` : "";
|
|
200
|
+
const pulseText = `📡 **ASTRO PULSE:** Run \`${active.run_id}\` is \`${active.status}\`${agentSuffix}.`;
|
|
201
|
+
await injectChatPrompt({
|
|
202
|
+
ctx,
|
|
203
|
+
sessionId,
|
|
204
|
+
text: pulseText,
|
|
205
|
+
agent: "Astro"
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
catch {
|
|
209
|
+
// Ignore pulse errors
|
|
210
|
+
}
|
|
211
|
+
}
|
|
189
212
|
}
|
|
@@ -110,36 +110,33 @@ function buildUiMessage(e) {
|
|
|
110
110
|
case "stage_started": {
|
|
111
111
|
const agent = e.agent_name ? ` (${e.agent_name})` : "";
|
|
112
112
|
const title = "Astrocode";
|
|
113
|
-
const message =
|
|
113
|
+
const message = `▶ Stage started: ${e.stage_key}${agent}`;
|
|
114
114
|
const chatText = [
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
`Stage: ${e.stage_key}${agent}`,
|
|
115
|
+
`### ▶ ASTROCODE: STAGE_STARTED`,
|
|
116
|
+
`**Run:** \`${e.run_id}\` `,
|
|
117
|
+
`**Stage:** \`${e.stage_key}\`${agent}`,
|
|
119
118
|
].join("\n");
|
|
120
119
|
return { title, message, variant: "info", chatText };
|
|
121
120
|
}
|
|
122
121
|
case "run_completed": {
|
|
123
122
|
const title = "Astrocode";
|
|
124
|
-
const message =
|
|
123
|
+
const message = `✓ Run completed: ${e.run_id}`;
|
|
125
124
|
const chatText = [
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
`Story: ${e.story_key}`,
|
|
125
|
+
`### ✓ ASTROCODE: RUN_COMPLETED`,
|
|
126
|
+
`**Run:** \`${e.run_id}\` `,
|
|
127
|
+
`**Story:** \`${e.story_key}\``,
|
|
130
128
|
].join("\n");
|
|
131
129
|
return { title, message, variant: "success", chatText };
|
|
132
130
|
}
|
|
133
131
|
case "run_failed": {
|
|
134
132
|
const title = "Astrocode";
|
|
135
|
-
const message =
|
|
133
|
+
const message = `✖ Run failed: ${e.run_id} (${e.stage_key})`;
|
|
136
134
|
const chatText = [
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
`Error: ${e.error_text}`,
|
|
135
|
+
`### ✖ ASTROCODE: RUN_FAILED`,
|
|
136
|
+
`**Run:** \`${e.run_id}\` `,
|
|
137
|
+
`**Story:** \`${e.story_key}\` `,
|
|
138
|
+
`**Stage:** \`${e.stage_key}\` `,
|
|
139
|
+
`**Error:** ${e.error_text}`,
|
|
143
140
|
].join("\n");
|
|
144
141
|
return { title, message, variant: "error", chatText };
|
|
145
142
|
}
|
|
@@ -257,14 +254,14 @@ export function createAstroWorkflowProceedTool(opts) {
|
|
|
257
254
|
if (sessionId) {
|
|
258
255
|
await injectChatPrompt({ ctx, sessionId, text: delegatePrompt, agent: "Astro" });
|
|
259
256
|
const continueMessage = [
|
|
260
|
-
|
|
261
|
-
``,
|
|
257
|
+
`### ⏳ ASTROCODE: AWAITING COMPLETION`,
|
|
262
258
|
`Stage \`${next.stage_key}\` delegated to \`${agentName}\`.`,
|
|
263
259
|
``,
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
260
|
+
`**Action Required:** When \`${agentName}\` completes, call:`,
|
|
261
|
+
`\`\`\`bash`,
|
|
262
|
+
`astro_stage_complete(run_id="${active.run_id}", stage_key="${next.stage_key}", output_text="...")`,
|
|
263
|
+
`\`\`\``,
|
|
264
|
+
`*Then run \`astro_workflow_proceed\` to continue.*`,
|
|
268
265
|
].join("\n");
|
|
269
266
|
await injectChatPrompt({ ctx, sessionId, text: continueMessage, agent: "Astro" });
|
|
270
267
|
}
|
|
@@ -282,12 +279,12 @@ export function createAstroWorkflowProceedTool(opts) {
|
|
|
282
279
|
next_action: `complete stage ${next.stage_key}`,
|
|
283
280
|
});
|
|
284
281
|
const prompt = [
|
|
285
|
-
|
|
286
|
-
``,
|
|
282
|
+
`### 📥 ASTROCODE: AWAITING OUTPUT`,
|
|
287
283
|
`Run \`${next.run_id}\` is waiting for stage \`${next.stage_key}\` output.`,
|
|
288
|
-
`If you have the subagent output, call astro_stage_complete with output_text=the FULL output.`,
|
|
289
284
|
``,
|
|
290
|
-
|
|
285
|
+
`**Action Required:** If you have the subagent output, call \`astro_stage_complete\` with \`output_text=the FULL output\`.`,
|
|
286
|
+
``,
|
|
287
|
+
`#### Context Snapshot`,
|
|
291
288
|
context,
|
|
292
289
|
].join("\n").trim();
|
|
293
290
|
const h = directiveHash(prompt);
|
package/package.json
CHANGED
|
@@ -3,6 +3,7 @@ import type { SqliteDb } from "../state/db";
|
|
|
3
3
|
import { selectEligibleInjects } from "../tools/injects";
|
|
4
4
|
import { injectChatPrompt } from "../ui/inject";
|
|
5
5
|
import { nowISO } from "../shared/time";
|
|
6
|
+
import { getActiveRun } from "../workflow/state-machine";
|
|
6
7
|
|
|
7
8
|
type ChatMessageInput = {
|
|
8
9
|
sessionID: string;
|
|
@@ -235,6 +236,29 @@ export function createInjectProvider(opts: {
|
|
|
235
236
|
|
|
236
237
|
// Inject eligible injects after workflow tool execution
|
|
237
238
|
await injectEligibleInjects(sessionId, `tool_after:${input.tool}`);
|
|
239
|
+
|
|
240
|
+
// Inject Workflow Pulse if a run is active
|
|
241
|
+
await maybeInjectWorkflowPulse(sessionId);
|
|
238
242
|
},
|
|
239
243
|
};
|
|
244
|
+
|
|
245
|
+
async function maybeInjectWorkflowPulse(sessionId: string) {
|
|
246
|
+
if (!db) return;
|
|
247
|
+
try {
|
|
248
|
+
const active = getActiveRun(db);
|
|
249
|
+
if (!active) return;
|
|
250
|
+
|
|
251
|
+
const agentSuffix = active.current_stage_key ? ` (Agent: ${active.current_stage_key})` : "";
|
|
252
|
+
const pulseText = `📡 **ASTRO PULSE:** Run \`${active.run_id}\` is \`${active.status}\`${agentSuffix}.`;
|
|
253
|
+
|
|
254
|
+
await injectChatPrompt({
|
|
255
|
+
ctx,
|
|
256
|
+
sessionId,
|
|
257
|
+
text: pulseText,
|
|
258
|
+
agent: "Astro"
|
|
259
|
+
});
|
|
260
|
+
} catch {
|
|
261
|
+
// Ignore pulse errors
|
|
262
|
+
}
|
|
263
|
+
}
|
|
240
264
|
}
|
package/src/tools/workflow.ts
CHANGED
|
@@ -138,36 +138,33 @@ function buildUiMessage(e: UiEmitEvent): { title: string; message: string; varia
|
|
|
138
138
|
case "stage_started": {
|
|
139
139
|
const agent = e.agent_name ? ` (${e.agent_name})` : "";
|
|
140
140
|
const title = "Astrocode";
|
|
141
|
-
const message =
|
|
141
|
+
const message = `▶ Stage started: ${e.stage_key}${agent}`;
|
|
142
142
|
const chatText = [
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
`Stage: ${e.stage_key}${agent}`,
|
|
143
|
+
`### ▶ ASTROCODE: STAGE_STARTED`,
|
|
144
|
+
`**Run:** \`${e.run_id}\` `,
|
|
145
|
+
`**Stage:** \`${e.stage_key}\`${agent}`,
|
|
147
146
|
].join("\n");
|
|
148
147
|
return { title, message, variant: "info", chatText };
|
|
149
148
|
}
|
|
150
149
|
case "run_completed": {
|
|
151
150
|
const title = "Astrocode";
|
|
152
|
-
const message =
|
|
151
|
+
const message = `✓ Run completed: ${e.run_id}`;
|
|
153
152
|
const chatText = [
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
`Story: ${e.story_key}`,
|
|
153
|
+
`### ✓ ASTROCODE: RUN_COMPLETED`,
|
|
154
|
+
`**Run:** \`${e.run_id}\` `,
|
|
155
|
+
`**Story:** \`${e.story_key}\``,
|
|
158
156
|
].join("\n");
|
|
159
157
|
return { title, message, variant: "success", chatText };
|
|
160
158
|
}
|
|
161
159
|
case "run_failed": {
|
|
162
160
|
const title = "Astrocode";
|
|
163
|
-
const message =
|
|
161
|
+
const message = `✖ Run failed: ${e.run_id} (${e.stage_key})`;
|
|
164
162
|
const chatText = [
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
`Error: ${e.error_text}`,
|
|
163
|
+
`### ✖ ASTROCODE: RUN_FAILED`,
|
|
164
|
+
`**Run:** \`${e.run_id}\` `,
|
|
165
|
+
`**Story:** \`${e.story_key}\` `,
|
|
166
|
+
`**Stage:** \`${e.stage_key}\` `,
|
|
167
|
+
`**Error:** ${e.error_text}`,
|
|
171
168
|
].join("\n");
|
|
172
169
|
return { title, message, variant: "error", chatText };
|
|
173
170
|
}
|
|
@@ -308,14 +305,14 @@ export function createAstroWorkflowProceedTool(opts: { ctx: any; config: Astroco
|
|
|
308
305
|
await injectChatPrompt({ ctx, sessionId, text: delegatePrompt, agent: "Astro" });
|
|
309
306
|
|
|
310
307
|
const continueMessage = [
|
|
311
|
-
|
|
312
|
-
``,
|
|
308
|
+
`### ⏳ ASTROCODE: AWAITING COMPLETION`,
|
|
313
309
|
`Stage \`${next.stage_key}\` delegated to \`${agentName}\`.`,
|
|
314
310
|
``,
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
311
|
+
`**Action Required:** When \`${agentName}\` completes, call:`,
|
|
312
|
+
`\`\`\`bash`,
|
|
313
|
+
`astro_stage_complete(run_id="${active.run_id}", stage_key="${next.stage_key}", output_text="...")`,
|
|
314
|
+
`\`\`\``,
|
|
315
|
+
`*Then run \`astro_workflow_proceed\` to continue.*`,
|
|
319
316
|
].join("\n");
|
|
320
317
|
|
|
321
318
|
await injectChatPrompt({ ctx, sessionId, text: continueMessage, agent: "Astro" });
|
|
@@ -339,12 +336,12 @@ export function createAstroWorkflowProceedTool(opts: { ctx: any; config: Astroco
|
|
|
339
336
|
});
|
|
340
337
|
|
|
341
338
|
const prompt = [
|
|
342
|
-
|
|
343
|
-
``,
|
|
339
|
+
`### 📥 ASTROCODE: AWAITING OUTPUT`,
|
|
344
340
|
`Run \`${next.run_id}\` is waiting for stage \`${next.stage_key}\` output.`,
|
|
345
|
-
`If you have the subagent output, call astro_stage_complete with output_text=the FULL output.`,
|
|
346
341
|
``,
|
|
347
|
-
|
|
342
|
+
`**Action Required:** If you have the subagent output, call \`astro_stage_complete\` with \`output_text=the FULL output\`.`,
|
|
343
|
+
``,
|
|
344
|
+
`#### Context Snapshot`,
|
|
348
345
|
context,
|
|
349
346
|
].join("\n").trim();
|
|
350
347
|
|