@workermill/agent 0.7.9 → 0.7.10

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.
@@ -25,16 +25,73 @@ const AUTO_APPROVAL_THRESHOLD = 80;
25
25
  * Mirrors server-side parseExecutionPlan() in planning-agent-local.ts.
26
26
  */
27
27
  export function parseExecutionPlan(output) {
28
- const jsonMatch = output.match(/```json\s*([\s\S]*?)\s*```/);
29
- if (jsonMatch) {
30
- return JSON.parse(jsonMatch[1]);
28
+ // Strategy 1: Find ```json ... ``` block using bracket-matching instead of regex.
29
+ // The lazy regex ([\s\S]*?) fails when JSON string values contain ``` (e.g., code
30
+ // blocks in story descriptions from PRDs with CI/CD YAML examples).
31
+ const jsonFenceStart = output.indexOf("```json");
32
+ if (jsonFenceStart !== -1) {
33
+ // Find the opening { after ```json
34
+ const searchFrom = jsonFenceStart + 7; // length of "```json"
35
+ const braceStart = output.indexOf("{", searchFrom);
36
+ if (braceStart !== -1) {
37
+ const extracted = extractBalancedJson(output, braceStart);
38
+ if (extracted) {
39
+ return JSON.parse(extracted);
40
+ }
41
+ }
31
42
  }
32
- const rawJsonMatch = output.match(/\{[\s\S]*"stories"[\s\S]*\}/);
33
- if (rawJsonMatch) {
34
- return JSON.parse(rawJsonMatch[0]);
43
+ // Strategy 2: Find raw JSON with "stories" key using bracket-matching
44
+ const storiesIdx = output.indexOf('"stories"');
45
+ if (storiesIdx !== -1) {
46
+ // Walk backwards to find the opening {
47
+ const before = output.substring(0, storiesIdx);
48
+ const braceStart = before.lastIndexOf("{");
49
+ if (braceStart !== -1) {
50
+ const extracted = extractBalancedJson(output, braceStart);
51
+ if (extracted) {
52
+ return JSON.parse(extracted);
53
+ }
54
+ }
35
55
  }
36
56
  throw new Error("Could not find JSON execution plan in output");
37
57
  }
58
+ /**
59
+ * Extract a balanced JSON object from a string starting at the given position.
60
+ * Properly handles nested braces, strings with escaped characters, and code
61
+ * blocks embedded in JSON string values (which contain triple backticks).
62
+ */
63
+ function extractBalancedJson(text, start) {
64
+ let depth = 0;
65
+ let inString = false;
66
+ let escape = false;
67
+ for (let i = start; i < text.length; i++) {
68
+ const ch = text[i];
69
+ if (escape) {
70
+ escape = false;
71
+ continue;
72
+ }
73
+ if (ch === "\\") {
74
+ if (inString)
75
+ escape = true;
76
+ continue;
77
+ }
78
+ if (ch === '"') {
79
+ inString = !inString;
80
+ continue;
81
+ }
82
+ if (inString)
83
+ continue;
84
+ if (ch === "{")
85
+ depth++;
86
+ else if (ch === "}") {
87
+ depth--;
88
+ if (depth === 0) {
89
+ return text.substring(start, i + 1);
90
+ }
91
+ }
92
+ }
93
+ return null; // Unbalanced
94
+ }
38
95
  // ============================================================================
39
96
  // FILE CAP
40
97
  // ============================================================================
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workermill/agent",
3
- "version": "0.7.9",
3
+ "version": "0.7.10",
4
4
  "description": "WorkerMill Remote Agent - Run AI workers locally with your Claude Max subscription",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",