@lsctech/polaris 0.3.7 → 0.3.8
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 +68 -0
- package/dist/cli/adopt-command.js +171 -0
- package/dist/cli/adopt-rules.js +2 -0
- package/dist/cli/index.js +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.enrichCanonFiles = enrichCanonFiles;
|
|
4
|
+
const node_fs_1 = require("node:fs");
|
|
5
|
+
const node_path_1 = require("node:path");
|
|
6
|
+
const SKIP_DIRS = new Set(["node_modules", ".git", "dist", "build", ".polaris", "smartdocs"]);
|
|
7
|
+
function normalizeRoute(route) {
|
|
8
|
+
return route.replace(/^\.\//, "").replace(/\/$/, "");
|
|
9
|
+
}
|
|
10
|
+
function walkForSummaryDirs(dir, repoRoot, results) {
|
|
11
|
+
let entries;
|
|
12
|
+
try {
|
|
13
|
+
entries = (0, node_fs_1.readdirSync)(dir, { withFileTypes: true });
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const hasSummary = entries.some((e) => e.isFile() && e.name === "SUMMARY.md");
|
|
19
|
+
if (hasSummary && dir !== repoRoot) {
|
|
20
|
+
results.push(dir);
|
|
21
|
+
}
|
|
22
|
+
for (const entry of entries) {
|
|
23
|
+
if (!entry.isDirectory())
|
|
24
|
+
continue;
|
|
25
|
+
if (SKIP_DIRS.has(entry.name))
|
|
26
|
+
continue;
|
|
27
|
+
walkForSummaryDirs((0, node_path_1.join)(dir, entry.name), repoRoot, results);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function buildLinkedDocsBlock(entries) {
|
|
31
|
+
const lines = ["linked_docs:"];
|
|
32
|
+
for (const entry of entries) {
|
|
33
|
+
const path = entry.doc_path.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
34
|
+
const title = (entry.title ?? "").replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
35
|
+
lines.push(` - path: "${path}"`);
|
|
36
|
+
lines.push(` title: "${title}"`);
|
|
37
|
+
}
|
|
38
|
+
return lines;
|
|
39
|
+
}
|
|
40
|
+
function injectLinkedDocs(content, entries) {
|
|
41
|
+
const lines = content.split("\n");
|
|
42
|
+
const headingIdx = lines.findIndex((l) => l.startsWith("#"));
|
|
43
|
+
if (headingIdx === -1)
|
|
44
|
+
return content;
|
|
45
|
+
const yamlLines = ["", "---", ...buildLinkedDocsBlock(entries), "---"];
|
|
46
|
+
const before = lines.slice(0, headingIdx + 1);
|
|
47
|
+
const after = lines.slice(headingIdx + 1);
|
|
48
|
+
return [...before, ...yamlLines, ...after].join("\n");
|
|
49
|
+
}
|
|
50
|
+
async function enrichCanonFiles(repoRoot) {
|
|
51
|
+
const indexPath = (0, node_path_1.join)(repoRoot, ".polaris", "map", "index.json");
|
|
52
|
+
if (!(0, node_fs_1.existsSync)(indexPath))
|
|
53
|
+
return;
|
|
54
|
+
const { entries } = JSON.parse((0, node_fs_1.readFileSync)(indexPath, "utf-8"));
|
|
55
|
+
const summaryDirs = [];
|
|
56
|
+
walkForSummaryDirs(repoRoot, repoRoot, summaryDirs);
|
|
57
|
+
for (const dir of summaryDirs) {
|
|
58
|
+
const route = normalizeRoute((0, node_path_1.relative)(repoRoot, dir));
|
|
59
|
+
const matched = entries.filter((e) => normalizeRoute(e.route) === route);
|
|
60
|
+
if (matched.length === 0)
|
|
61
|
+
continue;
|
|
62
|
+
const summaryPath = (0, node_path_1.join)(dir, "SUMMARY.md");
|
|
63
|
+
const content = (0, node_fs_1.readFileSync)(summaryPath, "utf-8");
|
|
64
|
+
if (!content.includes("<!-- polaris:draft -->"))
|
|
65
|
+
continue;
|
|
66
|
+
(0, node_fs_1.writeFileSync)(summaryPath, injectLinkedDocs(content, matched), "utf-8");
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runAdoptPhase = runAdoptPhase;
|
|
4
|
+
exports.runFullAdoption = runFullAdoption;
|
|
5
|
+
exports.createAdoptCommand = createAdoptCommand;
|
|
6
|
+
const node_path_1 = require("node:path");
|
|
7
|
+
const commander_1 = require("commander");
|
|
8
|
+
const adopt_scan_js_1 = require("./adopt-scan.js");
|
|
9
|
+
const adoption_plan_js_1 = require("./adoption-plan.js");
|
|
10
|
+
const agent_setup_js_1 = require("./agent-setup.js");
|
|
11
|
+
const adopt_smartdocs_js_1 = require("./adopt-smartdocs.js");
|
|
12
|
+
const adopt_assets_js_1 = require("./adopt-assets.js");
|
|
13
|
+
const adopt_rules_js_1 = require("./adopt-rules.js");
|
|
14
|
+
const adopt_cognition_js_1 = require("./adopt-cognition.js");
|
|
15
|
+
const adopt_canon_js_1 = require("./adopt-canon.js");
|
|
16
|
+
const adopt_genesis_js_1 = require("./adopt-genesis.js");
|
|
17
|
+
function estimateTokenCost(inventory) {
|
|
18
|
+
const total = inventory.smartdocs_candidates.length +
|
|
19
|
+
inventory.likely_canonical_folders.length;
|
|
20
|
+
if (total === 0)
|
|
21
|
+
return "minimal";
|
|
22
|
+
if (total < 20)
|
|
23
|
+
return "low (~50k tokens)";
|
|
24
|
+
if (total < 100)
|
|
25
|
+
return "moderate (~200k tokens)";
|
|
26
|
+
return "high (500k+ tokens) — consider running phases separately";
|
|
27
|
+
}
|
|
28
|
+
async function runAdoptPhase(phase, repoRoot, options = {}) {
|
|
29
|
+
switch (phase) {
|
|
30
|
+
case "scan": {
|
|
31
|
+
const inventory = await (0, adopt_scan_js_1.scanRepo)(repoRoot, { rescan: true });
|
|
32
|
+
const plan = (0, adoption_plan_js_1.generateAdoptionPlan)(inventory);
|
|
33
|
+
(0, adoption_plan_js_1.generateAdoptionPlanArtifacts)(repoRoot, inventory);
|
|
34
|
+
console.log(`Scan complete: ${inventory.smartdocs_candidates.length} doc(s), ${inventory.likely_canonical_folders.length} folder(s).`);
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
case "agents": {
|
|
38
|
+
if (options.inventory) {
|
|
39
|
+
const cost = estimateTokenCost(options.inventory);
|
|
40
|
+
process.stdout.write(`\nToken cost estimate for this repo: ${cost}\nAgent-assisted phases (consolidate, canon) will use your configured provider.\n\n`);
|
|
41
|
+
}
|
|
42
|
+
if (!options.skipAgents) {
|
|
43
|
+
await (0, agent_setup_js_1.runAgentSetup)(repoRoot);
|
|
44
|
+
}
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
case "consolidate": {
|
|
48
|
+
if (!options.inventory || !options.plan) {
|
|
49
|
+
throw new Error("consolidate requires inventory and plan");
|
|
50
|
+
}
|
|
51
|
+
await (0, adopt_smartdocs_js_1.migrateSmartDocs)(options.plan, repoRoot);
|
|
52
|
+
await (0, adopt_genesis_js_1.reconcileAgentFiles)(repoRoot);
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
case "map": {
|
|
56
|
+
const result = (0, adopt_assets_js_1.runGraphBuild)(repoRoot);
|
|
57
|
+
if (result.status === "graph-failed") {
|
|
58
|
+
const msg = `Map build failed: ${result.reason ?? "unknown error"}`;
|
|
59
|
+
process.stderr.write(`${msg}\n`);
|
|
60
|
+
if (result.followUpCommand) {
|
|
61
|
+
process.stderr.write(`Run: ${result.followUpCommand}\n`);
|
|
62
|
+
}
|
|
63
|
+
throw new Error(msg);
|
|
64
|
+
}
|
|
65
|
+
process.stdout.write("Map built successfully.\n");
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
case "skills": {
|
|
69
|
+
const workspaceDir = (0, node_path_1.join)(repoRoot, ".polaris", "workspace");
|
|
70
|
+
const result = (0, adopt_assets_js_1.installWorkspaceAssets)(repoRoot, workspaceDir);
|
|
71
|
+
console.log(`Skills: ${result.installed.length} installed, ${result.alreadyPresent.length} already present.`);
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
case "rules": {
|
|
75
|
+
const inventory = options.inventory ?? (await (0, adopt_scan_js_1.scanRepo)(repoRoot, { rescan: false }));
|
|
76
|
+
await (0, adopt_rules_js_1.generatePolarisRules)(repoRoot, inventory);
|
|
77
|
+
console.log("POLARIS_RULES.md written.");
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
case "canon": {
|
|
81
|
+
const inventory = options.inventory ?? (await (0, adopt_scan_js_1.scanRepo)(repoRoot, { rescan: false }));
|
|
82
|
+
const plan = options.plan ?? (0, adoption_plan_js_1.generateAdoptionPlan)(inventory);
|
|
83
|
+
await (0, adopt_cognition_js_1.generateFolderCognition)(plan, inventory, repoRoot);
|
|
84
|
+
await (0, adopt_canon_js_1.enrichCanonFiles)(repoRoot);
|
|
85
|
+
console.log("POLARIS.md and SUMMARY.md files written and enriched.");
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
default: {
|
|
89
|
+
throw new Error(`Unknown adopt phase: ${String(phase)}`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
async function runFullAdoption(repoRoot, options = {}) {
|
|
94
|
+
console.log("[1/7] scan");
|
|
95
|
+
await runAdoptPhase("scan", repoRoot);
|
|
96
|
+
// Re-read inventory and plan for later phases
|
|
97
|
+
const inventory = await (0, adopt_scan_js_1.scanRepo)(repoRoot, { rescan: false });
|
|
98
|
+
const plan = (0, adoption_plan_js_1.generateAdoptionPlan)(inventory);
|
|
99
|
+
console.log("[2/7] agents");
|
|
100
|
+
await runAdoptPhase("agents", repoRoot, {
|
|
101
|
+
inventory,
|
|
102
|
+
skipAgents: options.skipAgents,
|
|
103
|
+
});
|
|
104
|
+
console.log("[3/7] consolidate");
|
|
105
|
+
await runAdoptPhase("consolidate", repoRoot, { inventory, plan });
|
|
106
|
+
console.log("[4/7] map");
|
|
107
|
+
await runAdoptPhase("map", repoRoot);
|
|
108
|
+
console.log("[5/7] skills");
|
|
109
|
+
await runAdoptPhase("skills", repoRoot);
|
|
110
|
+
console.log("[6/7] rules");
|
|
111
|
+
await runAdoptPhase("rules", repoRoot, { inventory });
|
|
112
|
+
console.log("[7/7] canon");
|
|
113
|
+
await runAdoptPhase("canon", repoRoot, { inventory, plan });
|
|
114
|
+
}
|
|
115
|
+
function createAdoptCommand(opts) {
|
|
116
|
+
const { repoRoot } = opts;
|
|
117
|
+
const cmd = new commander_1.Command("adopt").description("Onboard this repository to Polaris — run all adoption phases in sequence");
|
|
118
|
+
cmd.action(async () => {
|
|
119
|
+
await runFullAdoption(repoRoot);
|
|
120
|
+
});
|
|
121
|
+
cmd
|
|
122
|
+
.command("scan")
|
|
123
|
+
.description("Scan the repository and generate adoption plan")
|
|
124
|
+
.action(async () => {
|
|
125
|
+
await runAdoptPhase("scan", repoRoot);
|
|
126
|
+
});
|
|
127
|
+
cmd
|
|
128
|
+
.command("agents")
|
|
129
|
+
.description("Set up agent instruction files")
|
|
130
|
+
.option("--skip", "skip running agent setup")
|
|
131
|
+
.action(async (cmdOpts) => {
|
|
132
|
+
await runAdoptPhase("agents", repoRoot, { skipAgents: cmdOpts.skip });
|
|
133
|
+
});
|
|
134
|
+
cmd
|
|
135
|
+
.command("consolidate")
|
|
136
|
+
.description("Migrate SmartDocs and reconcile agent files")
|
|
137
|
+
.option("--dry-run", "preview changes without writing")
|
|
138
|
+
.action(async (cmdOpts) => {
|
|
139
|
+
const inventory = await (0, adopt_scan_js_1.scanRepo)(repoRoot, { rescan: false });
|
|
140
|
+
const plan = (0, adoption_plan_js_1.generateAdoptionPlan)(inventory);
|
|
141
|
+
if (cmdOpts.dryRun) {
|
|
142
|
+
plan.dry_run = true;
|
|
143
|
+
}
|
|
144
|
+
await runAdoptPhase("consolidate", repoRoot, { inventory, plan });
|
|
145
|
+
});
|
|
146
|
+
cmd
|
|
147
|
+
.command("map")
|
|
148
|
+
.description("Build the file route map")
|
|
149
|
+
.action(async () => {
|
|
150
|
+
await runAdoptPhase("map", repoRoot);
|
|
151
|
+
});
|
|
152
|
+
cmd
|
|
153
|
+
.command("skills")
|
|
154
|
+
.description("Install workspace assets and skills")
|
|
155
|
+
.action(async () => {
|
|
156
|
+
await runAdoptPhase("skills", repoRoot);
|
|
157
|
+
});
|
|
158
|
+
cmd
|
|
159
|
+
.command("rules")
|
|
160
|
+
.description("Generate POLARIS_RULES.md")
|
|
161
|
+
.action(async () => {
|
|
162
|
+
await runAdoptPhase("rules", repoRoot);
|
|
163
|
+
});
|
|
164
|
+
cmd
|
|
165
|
+
.command("canon")
|
|
166
|
+
.description("Generate POLARIS.md and SUMMARY.md cognition files")
|
|
167
|
+
.action(async () => {
|
|
168
|
+
await runAdoptPhase("canon", repoRoot);
|
|
169
|
+
});
|
|
170
|
+
return cmd;
|
|
171
|
+
}
|
package/dist/cli/adopt-rules.js
CHANGED
|
@@ -97,6 +97,8 @@ async function generatePolarisRules(repoRoot, inventory, options = {}) {
|
|
|
97
97
|
"- `polaris-finalize` / `run polaris-finalize`",
|
|
98
98
|
"- `polaris-status` / `run polaris-status`",
|
|
99
99
|
"- `docs-ingest` / `run docs-ingest`",
|
|
100
|
+
"- `docs-review` / `run docs-review`",
|
|
101
|
+
"- `docs-triage` / `run docs-triage`",
|
|
100
102
|
"- `polaris-reconcile <CLUSTER-ID>` / `run polaris-reconcile on [issue] <CLUSTER-ID>`",
|
|
101
103
|
"- `polaris-catalog <CLUSTER-ID>` / `run polaris-catalog on [issue] <CLUSTER-ID>`",
|
|
102
104
|
"",
|
package/dist/cli/index.js
CHANGED
|
@@ -26,6 +26,7 @@ const index_js_7 = require("../skill-packet/index.js");
|
|
|
26
26
|
const librarian_js_1 = require("./librarian.js");
|
|
27
27
|
const medic_js_1 = require("./medic.js");
|
|
28
28
|
const welfare_js_1 = require("../map/welfare.js");
|
|
29
|
+
const adopt_command_js_1 = require("./adopt-command.js");
|
|
29
30
|
function resolveStateFile(repoRoot, explicit) {
|
|
30
31
|
if (explicit)
|
|
31
32
|
return (0, node_path_1.resolve)(explicit);
|
|
@@ -106,6 +107,7 @@ function createPolarisCommand(options = {}) {
|
|
|
106
107
|
program.addCommand((0, medic_js_1.createMedicCommand)({
|
|
107
108
|
repoRoot,
|
|
108
109
|
}));
|
|
110
|
+
program.addCommand((0, adopt_command_js_1.createAdoptCommand)({ repoRoot }));
|
|
109
111
|
const agentCmd = new commander_1.Command("agent").description("Manage Polaris agent provider configuration");
|
|
110
112
|
agentCmd.addCommand(new commander_1.Command("setup")
|
|
111
113
|
.description("Configure agent providers per role (librarian, foreman, worker, analyst)")
|