@lsctech/polaris 0.3.16 → 0.3.21
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/adopt-canon.js +23 -30
- package/package.json +1 -1
package/dist/cli/adopt-canon.js
CHANGED
|
@@ -98,6 +98,24 @@ function injectLinkedDocs(content, docs, summaryLines) {
|
|
|
98
98
|
: lines.slice(headingIdx + 1);
|
|
99
99
|
return [...before, ...yamlLines, ...after].join("\n");
|
|
100
100
|
}
|
|
101
|
+
function parseCanonResponse(text) {
|
|
102
|
+
const trimmed = text.trim();
|
|
103
|
+
const jsonLine = trimmed.split("\n").reverse().find((l) => l.trim().startsWith("{") && l.includes("relevant_docs"));
|
|
104
|
+
if (jsonLine) {
|
|
105
|
+
try {
|
|
106
|
+
return JSON.parse(jsonLine);
|
|
107
|
+
}
|
|
108
|
+
catch { /* fall through */ }
|
|
109
|
+
}
|
|
110
|
+
const blockMatch = trimmed.match(/\{[\s\S]*"relevant_docs"[\s\S]*\}/);
|
|
111
|
+
if (blockMatch) {
|
|
112
|
+
try {
|
|
113
|
+
return JSON.parse(blockMatch[0]);
|
|
114
|
+
}
|
|
115
|
+
catch { /* fall through */ }
|
|
116
|
+
}
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
101
119
|
// Strip flags that require worker permissions and aren't needed for reasoning-only calls.
|
|
102
120
|
function stripWorkerFlags(args) {
|
|
103
121
|
const stripped = [];
|
|
@@ -147,11 +165,10 @@ Respond with ONLY valid JSON on a single line:
|
|
|
147
165
|
{"relevant_docs":[{"path":"<doc path>","title":"<doc title>"}],"summary_lines":["line1","line2"],"polaris_lines":["line1","line2"]}
|
|
148
166
|
|
|
149
167
|
If no doctrine docs are relevant, return an empty array for relevant_docs.`;
|
|
150
|
-
//
|
|
151
|
-
//
|
|
152
|
-
const
|
|
153
|
-
const
|
|
154
|
-
const result = (0, node_child_process_1.spawnSync)(cfg.command, args, {
|
|
168
|
+
// Same dispatch pattern as dispatchLibrarianReview — pass args straight through,
|
|
169
|
+
// letting the provider config (e.g. env CLAUDE_CODE_SUBPROCESS_ENV_SCRUB=0) handle auth.
|
|
170
|
+
const args = (cfg.args ?? []).map((a) => (a === "{{worker_prompt}}" ? prompt : a));
|
|
171
|
+
const result = (0, node_child_process_1.spawnSync)(cfg.command, stripWorkerFlags(args), {
|
|
155
172
|
encoding: "utf-8",
|
|
156
173
|
timeout: 120000,
|
|
157
174
|
cwd: repoRoot,
|
|
@@ -164,31 +181,7 @@ If no doctrine docs are relevant, return an empty array for relevant_docs.`;
|
|
|
164
181
|
console.log(` agent stderr: ${result.stderr.trim().slice(0, 200)}`);
|
|
165
182
|
}
|
|
166
183
|
const stdout = (result.stdout ?? "").trim();
|
|
167
|
-
|
|
168
|
-
// Try single-line JSON first (ideal case)
|
|
169
|
-
const jsonLine = stdout
|
|
170
|
-
.split("\n")
|
|
171
|
-
.reverse()
|
|
172
|
-
.find((l) => l.trim().startsWith("{") && l.includes("relevant_docs"));
|
|
173
|
-
if (jsonLine) {
|
|
174
|
-
try {
|
|
175
|
-
return JSON.parse(jsonLine);
|
|
176
|
-
}
|
|
177
|
-
catch {
|
|
178
|
-
// fall through to block extraction
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
// Try extracting JSON block (handles multi-line or code-fenced output)
|
|
182
|
-
const blockMatch = stdout.match(/\{[\s\S]*"relevant_docs"[\s\S]*\}/);
|
|
183
|
-
if (blockMatch) {
|
|
184
|
-
try {
|
|
185
|
-
return JSON.parse(blockMatch[0]);
|
|
186
|
-
}
|
|
187
|
-
catch {
|
|
188
|
-
return null;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
return null;
|
|
184
|
+
return parseCanonResponse(stdout);
|
|
192
185
|
}
|
|
193
186
|
async function enrichCanonFiles(repoRoot) {
|
|
194
187
|
let config = null;
|