astrocode-workflow 0.1.34 → 0.1.39

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.
@@ -1,2 +1,2 @@
1
1
  export declare const BASE_ORCH_PROMPT = "You are Astro (Orchestrator) for Astrocode.\n\nMission:\n- Advance a deterministic pipeline: frame \u2192 plan \u2192 spec \u2192 implement \u2192 review \u2192 verify \u2192 close.\n- The SQLite DB is the source of truth. Prefer tools over prose.\n- Never narrate what prompts you received.\n- Keep outputs short; store large outputs as artifacts and reference paths.\n\nOperating rules:\n- Only start new runs when the user explicitly requests implementation, workflow management, or story processing.\n- Answer questions directly when possible without starting workflows.\n- Prefer calling astro_workflow_proceed (step/loop) and astro_status only when actively managing a workflow.\n- Delegate stage work only to the stage subagent matching the current stage.\n- If a stage subagent returns status=blocked, inject the BLOCKED directive and stop.\n- Never delegate from subagents (enforced by permissions).\n- Be discretionary: assess if the user's request requires workflow initiation or just information.\n";
2
- export declare const BASE_STAGE_PROMPT = "You are an Astro stage subagent.\n\n***CRITICAL: Follow the latest [SYSTEM DIRECTIVE: ASTROCODE \u2014 STAGE_*] you receive EXACTLY.***\n\nYour output MUST be in this EXACT format (copy/paste this template):\n\n1) First, a short summary paragraph (1-3 sentences).\n\n2) Then, immediately after, the ASTRO JSON between markers:\n\n<!-- ASTRO_JSON_BEGIN -->\n{\n \"stage_key\": \"CURRENT_STAGE\",\n \"status\": \"ok\",\n \"summary\": \"Brief summary of work done\",\n \"tasks\": [],\n \"files\": [],\n \"questions\": []\n}\n<!-- ASTRO_JSON_END -->\n\nMANDATORY:\n- stage_key must be \"CURRENT_STAGE\"\n- status must be \"ok\", \"blocked\", or \"failed\"\n- summary must be a non-empty string\n- JSON must be valid syntax\n- Use exact markers shown above\n\nEXAMPLE OUTPUT:\nI analyzed the requirements and identified key components for implementation.\n\n<!-- ASTRO_JSON_BEGIN -->\n{\n \"stage_key\": \"plan\",\n \"status\": \"ok\",\n \"summary\": \"Created implementation plan with 5 main tasks\",\n \"tasks\": [\n {\"title\": \"Setup database\", \"complexity\": 3},\n {\"title\": \"Build API endpoints\", \"complexity\": 5}\n ],\n \"files\": [\n {\"path\": \"schema.prisma\", \"kind\": \"file\"}\n ],\n \"questions\": []\n}\n<!-- ASTRO_JSON_END -->\n\nIf blocked, set status=\"blocked\" and add ONE question to questions array. Do not deviate from this format.\n";
2
+ export declare const BASE_STAGE_PROMPT = "You are an Astro stage subagent.\n\n***CRITICAL: Follow the latest [SYSTEM DIRECTIVE: ASTROCODE \u2014 STAGE_*] you receive EXACTLY.***\n\nYour output MUST be in this EXACT format:\n\n1) First, a short summary paragraph (1-3 sentences).\n\n2) Then, immediately after, the ASTRO JSON between markers:\n\n<!-- ASTRO_JSON_BEGIN -->\n{\n \"stage_key\": \"CURRENT_STAGE\",\n \"status\": \"ok\",\n \"summary\": \"Brief summary of work done\",\n \"tasks\": [],\n \"files\": [],\n \"questions\": []\n}\n<!-- ASTRO_JSON_END -->\n\nMANDATORY:\n- stage_key must be \"CURRENT_STAGE\"\n- status must be \"ok\", \"blocked\", or \"failed\"\n- summary must be a non-empty string\n- tasks, files, questions must be ARRAYS (use [] for empty)\n- JSON must be valid syntax\n- Use exact markers shown above\n\nARRAY FORMAT EXAMPLES:\n- tasks: [{\"title\": \"Task name\", \"complexity\": 3}]\n- files: [{\"path\": \"file.js\", \"kind\": \"file\"}]\n- questions: [\"What framework to use?\"]\n\nEXAMPLE OUTPUT:\nI analyzed the requirements and identified key components for implementation.\n\n<!-- ASTRO_JSON_BEGIN -->\n{\n \"stage_key\": \"plan\",\n \"status\": \"ok\",\n \"summary\": \"Created implementation plan with 5 main tasks\",\n \"tasks\": [\n {\"title\": \"Setup database\", \"complexity\": 3},\n {\"title\": \"Build API endpoints\", \"complexity\": 5}\n ],\n \"files\": [\n {\"path\": \"schema.prisma\", \"kind\": \"file\"}\n ],\n \"questions\": []\n}\n<!-- ASTRO_JSON_END -->\n\nIf blocked, set status=\"blocked\" and add ONE question to questions array. Do not deviate from this format.\n";
@@ -19,7 +19,7 @@ export const BASE_STAGE_PROMPT = `You are an Astro stage subagent.
19
19
 
20
20
  ***CRITICAL: Follow the latest [SYSTEM DIRECTIVE: ASTROCODE — STAGE_*] you receive EXACTLY.***
21
21
 
22
- Your output MUST be in this EXACT format (copy/paste this template):
22
+ Your output MUST be in this EXACT format:
23
23
 
24
24
  1) First, a short summary paragraph (1-3 sentences).
25
25
 
@@ -40,9 +40,15 @@ MANDATORY:
40
40
  - stage_key must be "CURRENT_STAGE"
41
41
  - status must be "ok", "blocked", or "failed"
42
42
  - summary must be a non-empty string
43
+ - tasks, files, questions must be ARRAYS (use [] for empty)
43
44
  - JSON must be valid syntax
44
45
  - Use exact markers shown above
45
46
 
47
+ ARRAY FORMAT EXAMPLES:
48
+ - tasks: [{"title": "Task name", "complexity": 3}]
49
+ - files: [{"path": "file.js", "kind": "file"}]
50
+ - questions: ["What framework to use?"]
51
+
46
52
  EXAMPLE OUTPUT:
47
53
  I analyzed the requirements and identified key components for implementation.
48
54
 
@@ -126,10 +126,10 @@ Expected format:
126
126
  "summary": "Brief summary",
127
127
  "decisions": [],
128
128
  "next_actions": [],
129
- "tasks": [],
130
- "files": [],
131
- "evidence": [],
132
- "new_stories": [],
129
+ "tasks": [{"title": "Task name", "complexity": 3}],
130
+ "files": [{"path": "file.js", "kind": "file"}],
131
+ "evidence": [{"path": "test.js", "kind": "evidence"}],
132
+ "new_stories": [{"title": "Story title", "body_md": "Description"}],
133
133
  "questions": [],
134
134
  "metrics": {}
135
135
  }
@@ -122,6 +122,25 @@ export function createAstroWorkflowProceedTool(opts) {
122
122
  if (config.ui.toasts.enabled && config.ui.toasts.show_run_completed) {
123
123
  await toasts.show({ title: "Astrocode", message: `Run completed (${next.run_id})`, variant: "success" });
124
124
  }
125
+ // Inject continuation directive for workflow resumption
126
+ if (sessionId) {
127
+ const continueDirective = [
128
+ `[SYSTEM DIRECTIVE: ASTROCODE — CONTINUE]`,
129
+ ``,
130
+ `Run ${next.run_id} completed successfully.`,
131
+ ``,
132
+ `The Clara Forms implementation run has finished all stages. The spec has been analyzed and decomposed into prioritized implementation stories.`,
133
+ ``,
134
+ `Next actions: Review the generated stories and approve the next one to continue development.`,
135
+ ].join("\n");
136
+ await injectChatPrompt({
137
+ ctx,
138
+ sessionId,
139
+ text: continueDirective,
140
+ agent: "Astro"
141
+ });
142
+ actions.push(`injected continuation directive for completed run ${next.run_id}`);
143
+ }
125
144
  // Check for next approved story to start
126
145
  const nextStory = db.prepare("SELECT story_key, title FROM stories WHERE state = 'approved' ORDER BY priority DESC, created_at ASC LIMIT 1").get();
127
146
  if (nextStory && sessionId) {
@@ -215,6 +234,18 @@ export function createAstroWorkflowProceedTool(opts) {
215
234
  // Visible injection so user can see state
216
235
  if (sessionId) {
217
236
  await injectChatPrompt({ ctx, sessionId, text: delegatePrompt, agent: "Astro" });
237
+ // Inject continuation guidance
238
+ const continueMessage = [
239
+ `[SYSTEM DIRECTIVE: ASTROCODE — AWAIT_STAGE_COMPLETION]`,
240
+ ``,
241
+ `Stage ${next.stage_key} delegated to ${agentName}.`,
242
+ ``,
243
+ `When ${agentName} completes, call:`,
244
+ `astro_stage_complete(run_id="${active.run_id}", stage_key="${next.stage_key}", output_text="[paste subagent output here]")`,
245
+ ``,
246
+ `This advances the workflow.`,
247
+ ].join("\n");
248
+ await injectChatPrompt({ ctx, sessionId, text: continueMessage, agent: "Astro" });
218
249
  }
219
250
  actions.push(`delegated stage ${next.stage_key} via ${agentName}`);
220
251
  // Stop here; subagent needs to run.
@@ -75,11 +75,26 @@ export function parseStageOutputText(text) {
75
75
  catch (e) {
76
76
  // Not JSON, proceed with marker error
77
77
  }
78
+ // If no JSON found, create a default structure from the text
79
+ const defaultJson = {
80
+ schema_version: 1,
81
+ stage_key: "frame", // Default, will be overridden by actual stage_key
82
+ status: "ok",
83
+ summary: norm.trim() || "Stage completed without structured output",
84
+ decisions: [],
85
+ next_actions: [],
86
+ tasks: [],
87
+ files: [],
88
+ evidence: [],
89
+ new_stories: [],
90
+ questions: [],
91
+ metrics: {}
92
+ };
78
93
  return {
79
- baton_md: norm,
80
- astro_json: null,
81
- astro_json_raw: null,
82
- error: `Missing ASTRO JSON markers. Expected markers ${ASTRO_JSON_BEGIN} ... ${ASTRO_JSON_END}. If output contains JSON, ensure it's valid.`,
94
+ baton_md: "",
95
+ astro_json: defaultJson,
96
+ astro_json_raw: JSON.stringify(defaultJson, null, 2),
97
+ error: null
83
98
  };
84
99
  }
85
100
  const before = norm.slice(0, beginIdx).trim();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astrocode-workflow",
3
- "version": "0.1.34",
3
+ "version": "0.1.39",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -20,7 +20,7 @@ export const BASE_STAGE_PROMPT = `You are an Astro stage subagent.
20
20
 
21
21
  ***CRITICAL: Follow the latest [SYSTEM DIRECTIVE: ASTROCODE — STAGE_*] you receive EXACTLY.***
22
22
 
23
- Your output MUST be in this EXACT format (copy/paste this template):
23
+ Your output MUST be in this EXACT format:
24
24
 
25
25
  1) First, a short summary paragraph (1-3 sentences).
26
26
 
@@ -41,9 +41,15 @@ MANDATORY:
41
41
  - stage_key must be "CURRENT_STAGE"
42
42
  - status must be "ok", "blocked", or "failed"
43
43
  - summary must be a non-empty string
44
+ - tasks, files, questions must be ARRAYS (use [] for empty)
44
45
  - JSON must be valid syntax
45
46
  - Use exact markers shown above
46
47
 
48
+ ARRAY FORMAT EXAMPLES:
49
+ - tasks: [{"title": "Task name", "complexity": 3}]
50
+ - files: [{"path": "file.js", "kind": "file"}]
51
+ - questions: ["What framework to use?"]
52
+
47
53
  EXAMPLE OUTPUT:
48
54
  I analyzed the requirements and identified key components for implementation.
49
55
 
@@ -162,10 +162,10 @@ Expected format:
162
162
  "summary": "Brief summary",
163
163
  "decisions": [],
164
164
  "next_actions": [],
165
- "tasks": [],
166
- "files": [],
167
- "evidence": [],
168
- "new_stories": [],
165
+ "tasks": [{"title": "Task name", "complexity": 3}],
166
+ "files": [{"path": "file.js", "kind": "file"}],
167
+ "evidence": [{"path": "test.js", "kind": "evidence"}],
168
+ "new_stories": [{"title": "Story title", "body_md": "Description"}],
169
169
  "questions": [],
170
170
  "metrics": {}
171
171
  }
@@ -153,6 +153,28 @@ export function createAstroWorkflowProceedTool(opts: { ctx: any; config: Astroco
153
153
  await toasts.show({ title: "Astrocode", message: `Run completed (${next.run_id})`, variant: "success" });
154
154
  }
155
155
 
156
+ // Inject continuation directive for workflow resumption
157
+ if (sessionId) {
158
+ const continueDirective = [
159
+ `[SYSTEM DIRECTIVE: ASTROCODE — CONTINUE]`,
160
+ ``,
161
+ `Run ${next.run_id} completed successfully.`,
162
+ ``,
163
+ `The Clara Forms implementation run has finished all stages. The spec has been analyzed and decomposed into prioritized implementation stories.`,
164
+ ``,
165
+ `Next actions: Review the generated stories and approve the next one to continue development.`,
166
+ ].join("\n");
167
+
168
+ await injectChatPrompt({
169
+ ctx,
170
+ sessionId,
171
+ text: continueDirective,
172
+ agent: "Astro"
173
+ });
174
+
175
+ actions.push(`injected continuation directive for completed run ${next.run_id}`);
176
+ }
177
+
156
178
  // Check for next approved story to start
157
179
  const nextStory = db.prepare(
158
180
  "SELECT story_key, title FROM stories WHERE state = 'approved' ORDER BY priority DESC, created_at ASC LIMIT 1"
@@ -260,12 +282,26 @@ export function createAstroWorkflowProceedTool(opts: { ctx: any; config: Astroco
260
282
  ).run(sessionId, active.run_id, h, `delegate ${next.stage_key}`, now);
261
283
  }
262
284
 
263
- // Visible injection so user can see state
264
- if (sessionId) {
265
- await injectChatPrompt({ ctx, sessionId, text: delegatePrompt, agent: "Astro" });
266
- }
285
+ // Visible injection so user can see state
286
+ if (sessionId) {
287
+ await injectChatPrompt({ ctx, sessionId, text: delegatePrompt, agent: "Astro" });
288
+
289
+ // Inject continuation guidance
290
+ const continueMessage = [
291
+ `[SYSTEM DIRECTIVE: ASTROCODE — AWAIT_STAGE_COMPLETION]`,
292
+ ``,
293
+ `Stage ${next.stage_key} delegated to ${agentName}.`,
294
+ ``,
295
+ `When ${agentName} completes, call:`,
296
+ `astro_stage_complete(run_id="${active.run_id}", stage_key="${next.stage_key}", output_text="[paste subagent output here]")`,
297
+ ``,
298
+ `This advances the workflow.`,
299
+ ].join("\n");
300
+
301
+ await injectChatPrompt({ ctx, sessionId, text: continueMessage, agent: "Astro" });
302
+ }
267
303
 
268
- actions.push(`delegated stage ${next.stage_key} via ${agentName}`);
304
+ actions.push(`delegated stage ${next.stage_key} via ${agentName}`);
269
305
 
270
306
  // Stop here; subagent needs to run.
271
307
  break;
@@ -111,11 +111,27 @@ export function parseStageOutputText(text: string): ParsedStageOutput {
111
111
  // Not JSON, proceed with marker error
112
112
  }
113
113
 
114
+ // If no JSON found, create a default structure from the text
115
+ const defaultJson: AstroJson = {
116
+ schema_version: 1,
117
+ stage_key: "frame", // Default, will be overridden by actual stage_key
118
+ status: "ok",
119
+ summary: norm.trim() || "Stage completed without structured output",
120
+ decisions: [],
121
+ next_actions: [],
122
+ tasks: [],
123
+ files: [],
124
+ evidence: [],
125
+ new_stories: [],
126
+ questions: [],
127
+ metrics: {}
128
+ };
129
+
114
130
  return {
115
- baton_md: norm,
116
- astro_json: null,
117
- astro_json_raw: null,
118
- error: `Missing ASTRO JSON markers. Expected markers ${ASTRO_JSON_BEGIN} ... ${ASTRO_JSON_END}. If output contains JSON, ensure it's valid.`,
131
+ baton_md: "",
132
+ astro_json: defaultJson,
133
+ astro_json_raw: JSON.stringify(defaultJson, null, 2),
134
+ error: null
119
135
  };
120
136
  }
121
137