@lsctech/polaris 0.3.11 → 0.3.13
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 +48 -6
- package/package.json +1 -1
package/dist/cli/adopt-canon.js
CHANGED
|
@@ -7,6 +7,32 @@ const node_child_process_1 = require("node:child_process");
|
|
|
7
7
|
const loader_js_1 = require("../config/loader.js");
|
|
8
8
|
const librarian_dispatch_js_1 = require("../smartdocs-engine/librarian-dispatch.js");
|
|
9
9
|
const SKIP_DIRS = new Set(["node_modules", ".git", "dist", "build", ".polaris", "smartdocs"]);
|
|
10
|
+
function loadInventoryCanonicalFolders(repoRoot) {
|
|
11
|
+
const inventoryPath = (0, node_path_1.join)(repoRoot, ".polaris", "adoption-inventory.json");
|
|
12
|
+
if (!(0, node_fs_1.existsSync)(inventoryPath))
|
|
13
|
+
return [];
|
|
14
|
+
try {
|
|
15
|
+
const raw = JSON.parse((0, node_fs_1.readFileSync)(inventoryPath, "utf-8"));
|
|
16
|
+
const folders = raw["likely_canonical_folders"];
|
|
17
|
+
return Array.isArray(folders) ? folders : [];
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function scaffoldDraftSummaryFiles(repoRoot, canonicalFolders) {
|
|
24
|
+
for (const folder of canonicalFolders) {
|
|
25
|
+
const dir = (0, node_path_1.join)(repoRoot, folder);
|
|
26
|
+
if (!(0, node_fs_1.existsSync)(dir))
|
|
27
|
+
continue;
|
|
28
|
+
const summaryPath = (0, node_path_1.join)(dir, "SUMMARY.md");
|
|
29
|
+
if ((0, node_fs_1.existsSync)(summaryPath))
|
|
30
|
+
continue;
|
|
31
|
+
(0, node_fs_1.mkdirSync)(dir, { recursive: true });
|
|
32
|
+
(0, node_fs_1.writeFileSync)(summaryPath, `# ${folder}\n\n<!-- polaris:draft -->\n`, "utf-8");
|
|
33
|
+
console.log(` Scaffolded draft SUMMARY.md: ${folder}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
10
36
|
function walkForSummaryDirs(dir, repoRoot, results) {
|
|
11
37
|
let entries;
|
|
12
38
|
try {
|
|
@@ -106,18 +132,30 @@ If no doctrine docs are relevant, return an empty array for relevant_docs.`;
|
|
|
106
132
|
cwd: repoRoot,
|
|
107
133
|
});
|
|
108
134
|
const stdout = (result.stdout ?? "").trim();
|
|
135
|
+
// Try single-line JSON first (ideal case)
|
|
109
136
|
const jsonLine = stdout
|
|
110
137
|
.split("\n")
|
|
111
138
|
.reverse()
|
|
112
139
|
.find((l) => l.trim().startsWith("{") && l.includes("relevant_docs"));
|
|
113
|
-
if (
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
140
|
+
if (jsonLine) {
|
|
141
|
+
try {
|
|
142
|
+
return JSON.parse(jsonLine);
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
// fall through to block extraction
|
|
146
|
+
}
|
|
117
147
|
}
|
|
118
|
-
|
|
119
|
-
|
|
148
|
+
// Try extracting JSON block (handles multi-line or code-fenced output)
|
|
149
|
+
const blockMatch = stdout.match(/\{[\s\S]*"relevant_docs"[\s\S]*\}/);
|
|
150
|
+
if (blockMatch) {
|
|
151
|
+
try {
|
|
152
|
+
return JSON.parse(blockMatch[0]);
|
|
153
|
+
}
|
|
154
|
+
catch {
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
120
157
|
}
|
|
158
|
+
return null;
|
|
121
159
|
}
|
|
122
160
|
async function enrichCanonFiles(repoRoot) {
|
|
123
161
|
let config = null;
|
|
@@ -144,6 +182,10 @@ async function enrichCanonFiles(repoRoot) {
|
|
|
144
182
|
"Run `polaris agent setup` to configure an available agent.");
|
|
145
183
|
}
|
|
146
184
|
const doctrineDocs = listActiveDoctrineDocs(repoRoot);
|
|
185
|
+
const canonicalFolders = loadInventoryCanonicalFolders(repoRoot);
|
|
186
|
+
if (canonicalFolders.length > 0) {
|
|
187
|
+
scaffoldDraftSummaryFiles(repoRoot, canonicalFolders);
|
|
188
|
+
}
|
|
147
189
|
const summaryDirs = [];
|
|
148
190
|
walkForSummaryDirs(repoRoot, repoRoot, summaryDirs);
|
|
149
191
|
let enrichedCount = 0;
|