astrocode-workflow 0.1.2 → 0.1.4

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\nFollow the latest [SYSTEM DIRECTIVE: ASTROCODE \u2014 STAGE_*] you receive.\n\nOutput exactly:\n1) Baton markdown (short, structured)\n2) Valid ASTRO JSON between markers:\n<!-- ASTRO_JSON_BEGIN -->\n{...}\n<!-- ASTRO_JSON_END -->\n\nDo not narrate. If blocked, ask exactly ONE question and stop.\n";
2
+ export declare const BASE_STAGE_PROMPT = "You are an Astro stage subagent.\n\nFollow the latest [SYSTEM DIRECTIVE: ASTROCODE \u2014 STAGE_*] you receive.\n\nOutput exactly:\n1) Baton markdown (short, structured)\n2) Valid ASTRO JSON between markers with ALL required fields:\n<!-- ASTRO_JSON_BEGIN -->\n{\n \"stage_key\": \"CURRENT_STAGE\",\n \"status\": \"ok\",\n \"summary\": \"Brief summary of work done\",\n \"decisions\": [\"Decision 1\", \"Decision 2\"],\n \"next_actions\": [\"Action 1\", \"Action 2\"],\n \"files\": [{\"path\": \"file.js\", \"kind\": \"file\"}],\n \"evidence\": [{\"path\": \"test.js\", \"kind\": \"evidence\"}],\n \"tasks\": [{\"title\": \"Task\", \"complexity\": 3}],\n \"new_stories\": [{\"title\": \"Story\", \"body_md\": \"Desc\"}],\n \"questions\": [],\n \"metrics\": {\"lines\": 100}\n}\n<!-- ASTRO_JSON_END -->\n\nCRITICAL: Include stage_key, status, and summary in EVERY response. Use \"ok\" status unless blocked/failed.\n\nDo not narrate. If blocked, ask exactly ONE question and stop.\n";
@@ -21,10 +21,24 @@ Follow the latest [SYSTEM DIRECTIVE: ASTROCODE — STAGE_*] you receive.
21
21
 
22
22
  Output exactly:
23
23
  1) Baton markdown (short, structured)
24
- 2) Valid ASTRO JSON between markers:
24
+ 2) Valid ASTRO JSON between markers with ALL required fields:
25
25
  <!-- ASTRO_JSON_BEGIN -->
26
- {...}
26
+ {
27
+ "stage_key": "CURRENT_STAGE",
28
+ "status": "ok",
29
+ "summary": "Brief summary of work done",
30
+ "decisions": ["Decision 1", "Decision 2"],
31
+ "next_actions": ["Action 1", "Action 2"],
32
+ "files": [{"path": "file.js", "kind": "file"}],
33
+ "evidence": [{"path": "test.js", "kind": "evidence"}],
34
+ "tasks": [{"title": "Task", "complexity": 3}],
35
+ "new_stories": [{"title": "Story", "body_md": "Desc"}],
36
+ "questions": [],
37
+ "metrics": {"lines": 100}
38
+ }
27
39
  <!-- ASTRO_JSON_END -->
28
40
 
41
+ CRITICAL: Include stage_key, status, and summary in EVERY response. Use "ok" status unless blocked/failed.
42
+
29
43
  Do not narrate. If blocked, ask exactly ONE question and stop.
30
44
  `;
@@ -81,10 +81,10 @@ export function createAstroStageCompleteTool(opts) {
81
81
  }
82
82
  const parsed = parseStageOutputText(output_text);
83
83
  if (parsed.error || !parsed.astro_json) {
84
- return `❌ Stage completion failed: ${parsed.error ?? "ASTRO JSON missing"}. Please ensure output includes proper JSON markers.`;
84
+ return `❌ JSON Parse Error: ${parsed.error ?? "ASTRO JSON missing"}. Ensure output includes <!-- ASTRO_JSON_BEGIN -->{...}<!-- ASTRO_JSON_END --> markers with valid JSON.`;
85
85
  }
86
86
  if (parsed.astro_json.stage_key !== sk) {
87
- return `❌ Stage completion failed: ASTRO JSON stage_key mismatch (expected ${sk}, got ${parsed.astro_json.stage_key}).`;
87
+ return `❌ Stage Key Mismatch: ASTRO JSON has stage_key="${parsed.astro_json.stage_key}" but expected "${sk}". Update the JSON to match the current stage.`;
88
88
  }
89
89
  // Evidence requirement
90
90
  const evidenceRequired = (sk === "verify" && config.workflow.evidence_required.verify) ||
@@ -7,6 +7,19 @@ import { injectChatPrompt } from "../ui/inject";
7
7
  import { nowISO } from "../shared/time";
8
8
  import { newEventId } from "../state/ids";
9
9
  import { createToastManager } from "../ui/toasts";
10
+ // Agent name mapping for case-sensitive resolution
11
+ const STAGE_TO_AGENT_MAP = {
12
+ frame: "Frame",
13
+ plan: "Plan",
14
+ spec: "Spec",
15
+ implement: "Implement",
16
+ review: "Review",
17
+ verify: "Verify",
18
+ close: "Close"
19
+ };
20
+ function resolveAgentName(stageKey) {
21
+ return STAGE_TO_AGENT_MAP[stageKey] || "General";
22
+ }
10
23
  function stageGoal(stage, cfg) {
11
24
  switch (stage) {
12
25
  case "frame":
@@ -111,7 +124,15 @@ export function createAstroWorkflowProceedTool(opts) {
111
124
  const run = db.prepare("SELECT * FROM runs WHERE run_id=?").get(active.run_id);
112
125
  const story = db.prepare("SELECT * FROM stories WHERE story_key=?").get(run.story_key);
113
126
  // Mark stage started + set subagent_type to the stage agent.
114
- const agentName = next.stage_key;
127
+ let agentName = resolveAgentName(next.stage_key);
128
+ // Validate agent availability (check system config for registered agents)
129
+ const systemConfig = ctx.config; // OpenCode's system config
130
+ if (!systemConfig.agent || !systemConfig.agent[agentName]) {
131
+ console.warn(`Agent ${agentName} not found in system config. Available agents:`, Object.keys(systemConfig.agent || {}));
132
+ // Fallback to General
133
+ agentName = "General";
134
+ }
135
+ console.log(`Delegating stage ${next.stage_key} to agent: ${agentName}`);
115
136
  withTx(db, () => {
116
137
  startStage(db, active.run_id, next.stage_key, { subagent_type: agentName });
117
138
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astrocode-workflow",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -18,7 +18,7 @@
18
18
  "dependencies": {
19
19
  "@opencode-ai/plugin": "^1.1.19",
20
20
  "@opencode-ai/sdk": "^1.1.19",
21
- "astrocode-workflow": "0.1.1",
21
+ "astrocode-workflow": "^0.1.2",
22
22
  "jsonc-parser": "^3.2.0",
23
23
  "zod": "4.1.8"
24
24
  },
@@ -22,10 +22,24 @@ Follow the latest [SYSTEM DIRECTIVE: ASTROCODE — STAGE_*] you receive.
22
22
 
23
23
  Output exactly:
24
24
  1) Baton markdown (short, structured)
25
- 2) Valid ASTRO JSON between markers:
25
+ 2) Valid ASTRO JSON between markers with ALL required fields:
26
26
  <!-- ASTRO_JSON_BEGIN -->
27
- {...}
27
+ {
28
+ "stage_key": "CURRENT_STAGE",
29
+ "status": "ok",
30
+ "summary": "Brief summary of work done",
31
+ "decisions": ["Decision 1", "Decision 2"],
32
+ "next_actions": ["Action 1", "Action 2"],
33
+ "files": [{"path": "file.js", "kind": "file"}],
34
+ "evidence": [{"path": "test.js", "kind": "evidence"}],
35
+ "tasks": [{"title": "Task", "complexity": 3}],
36
+ "new_stories": [{"title": "Story", "body_md": "Desc"}],
37
+ "questions": [],
38
+ "metrics": {"lines": 100}
39
+ }
28
40
  <!-- ASTRO_JSON_END -->
29
41
 
42
+ CRITICAL: Include stage_key, status, and summary in EVERY response. Use "ok" status unless blocked/failed.
43
+
30
44
  Do not narrate. If blocked, ask exactly ONE question and stop.
31
45
  `;
@@ -94,11 +94,11 @@ export function createAstroStageCompleteTool(opts: { ctx: any; config: Astrocode
94
94
 
95
95
  const parsed = parseStageOutputText(output_text);
96
96
  if (parsed.error || !parsed.astro_json) {
97
- return `❌ Stage completion failed: ${parsed.error ?? "ASTRO JSON missing"}. Please ensure output includes proper JSON markers.`;
97
+ return `❌ JSON Parse Error: ${parsed.error ?? "ASTRO JSON missing"}. Ensure output includes <!-- ASTRO_JSON_BEGIN -->{...}<!-- ASTRO_JSON_END --> markers with valid JSON.`;
98
98
  }
99
99
 
100
100
  if (parsed.astro_json.stage_key !== sk) {
101
- return `❌ Stage completion failed: ASTRO JSON stage_key mismatch (expected ${sk}, got ${parsed.astro_json.stage_key}).`;
101
+ return `❌ Stage Key Mismatch: ASTRO JSON has stage_key="${parsed.astro_json.stage_key}" but expected "${sk}". Update the JSON to match the current stage.`;
102
102
  }
103
103
 
104
104
  // Evidence requirement
@@ -11,6 +11,21 @@ import { nowISO } from "../shared/time";
11
11
  import { newEventId } from "../state/ids";
12
12
  import { createToastManager } from "../ui/toasts";
13
13
 
14
+ // Agent name mapping for case-sensitive resolution
15
+ const STAGE_TO_AGENT_MAP: Record<string, string> = {
16
+ frame: "Frame",
17
+ plan: "Plan",
18
+ spec: "Spec",
19
+ implement: "Implement",
20
+ review: "Review",
21
+ verify: "Verify",
22
+ close: "Close"
23
+ };
24
+
25
+ function resolveAgentName(stageKey: string): string {
26
+ return STAGE_TO_AGENT_MAP[stageKey] || "General";
27
+ }
28
+
14
29
  function stageGoal(stage: StageKey, cfg: AstrocodeConfig): string {
15
30
  switch (stage) {
16
31
  case "frame":
@@ -135,8 +150,19 @@ export function createAstroWorkflowProceedTool(opts: { ctx: any; config: Astroco
135
150
  const run = db.prepare("SELECT * FROM runs WHERE run_id=?").get(active.run_id) as any;
136
151
  const story = db.prepare("SELECT * FROM stories WHERE story_key=?").get(run.story_key) as any;
137
152
 
138
- // Mark stage started + set subagent_type to the stage agent.
139
- const agentName = next.stage_key;
153
+ // Mark stage started + set subagent_type to the stage agent.
154
+ let agentName = resolveAgentName(next.stage_key);
155
+
156
+ // Validate agent availability (check system config for registered agents)
157
+ const systemConfig = ctx.config; // OpenCode's system config
158
+ if (!systemConfig.agent || !systemConfig.agent[agentName]) {
159
+ console.warn(`Agent ${agentName} not found in system config. Available agents:`, Object.keys(systemConfig.agent || {}));
160
+ // Fallback to General
161
+ agentName = "General";
162
+ }
163
+
164
+ console.log(`Delegating stage ${next.stage_key} to agent: ${agentName}`);
165
+
140
166
  withTx(db, () => {
141
167
  startStage(db, active.run_id, next.stage_key, { subagent_type: agentName });
142
168
  });