@lasso-ai/cli 1.0.14 → 1.0.15
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/cli/agent.js +51 -8
- package/package.json +1 -1
package/dist/cli/agent.js
CHANGED
|
@@ -91,17 +91,60 @@ async function contextFor(cwd, element) {
|
|
|
91
91
|
}
|
|
92
92
|
return snippets.join("\n\n---\n\n");
|
|
93
93
|
}
|
|
94
|
+
function jsonObjectCandidates(text) {
|
|
95
|
+
const candidates = [];
|
|
96
|
+
for (let start = 0; start < text.length; start += 1) {
|
|
97
|
+
if (text[start] !== "{")
|
|
98
|
+
continue;
|
|
99
|
+
let depth = 0;
|
|
100
|
+
let inString = false;
|
|
101
|
+
let escaped = false;
|
|
102
|
+
for (let index = start; index < text.length; index += 1) {
|
|
103
|
+
const character = text[index];
|
|
104
|
+
if (inString) {
|
|
105
|
+
if (escaped)
|
|
106
|
+
escaped = false;
|
|
107
|
+
else if (character === "\\")
|
|
108
|
+
escaped = true;
|
|
109
|
+
else if (character === '"')
|
|
110
|
+
inString = false;
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
if (character === '"') {
|
|
114
|
+
inString = true;
|
|
115
|
+
}
|
|
116
|
+
else if (character === "{") {
|
|
117
|
+
depth += 1;
|
|
118
|
+
}
|
|
119
|
+
else if (character === "}" && --depth === 0) {
|
|
120
|
+
candidates.push(text.slice(start, index + 1));
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return candidates;
|
|
126
|
+
}
|
|
94
127
|
function jsonFrom(text) {
|
|
95
|
-
const fenced = text.match(/```(?:json)?\s*([\s\S]*?)```/i)?.[1]
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
128
|
+
const fenced = text.match(/```(?:json)?\s*([\s\S]*?)```/i)?.[1];
|
|
129
|
+
const candidates = [...(fenced ? [fenced] : []), ...jsonObjectCandidates(text)];
|
|
130
|
+
for (const candidate of candidates) {
|
|
131
|
+
try {
|
|
132
|
+
const parsed = JSON.parse(candidate.trim());
|
|
133
|
+
if (!Array.isArray(parsed.changes))
|
|
134
|
+
continue;
|
|
135
|
+
for (const change of parsed.changes) {
|
|
136
|
+
if (!change.filePath || typeof change.oldString !== "string" || typeof change.newString !== "string") {
|
|
137
|
+
throw new Error("The agent returned an invalid file change.");
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return { summary: parsed.summary || "The proposed source changes are ready for review.", changes: parsed.changes };
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
if (error instanceof Error && error.message === "The agent returned an invalid file change.")
|
|
144
|
+
throw error;
|
|
102
145
|
}
|
|
103
146
|
}
|
|
104
|
-
|
|
147
|
+
throw new Error("The agent returned no valid reviewable changes. Progress output may have been mixed with the final JSON.");
|
|
105
148
|
}
|
|
106
149
|
function extractLocalAgentText(raw, provider) {
|
|
107
150
|
if (provider === "claude-code") {
|
package/package.json
CHANGED