@toolbaux/guardian 0.1.5 → 0.1.7
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/commands/context.js
CHANGED
|
@@ -12,11 +12,20 @@ export async function runContext(options) {
|
|
|
12
12
|
loadArchitectureDiff(inputDir),
|
|
13
13
|
loadHeatmap(inputDir)
|
|
14
14
|
]);
|
|
15
|
+
// Load structural intelligence if available
|
|
16
|
+
let si;
|
|
17
|
+
try {
|
|
18
|
+
const siPath = path.join(inputDir, "structural-intelligence.json");
|
|
19
|
+
const siRaw = await fs.readFile(siPath, "utf8");
|
|
20
|
+
si = JSON.parse(siRaw);
|
|
21
|
+
}
|
|
22
|
+
catch { /* not available */ }
|
|
15
23
|
const content = renderContextBlock(architecture, ux, {
|
|
16
24
|
focusQuery: options.focus,
|
|
17
25
|
maxLines: normalizeMaxLines(options.maxLines),
|
|
18
26
|
diff,
|
|
19
|
-
heatmap
|
|
27
|
+
heatmap,
|
|
28
|
+
structuralIntelligence: si
|
|
20
29
|
});
|
|
21
30
|
if (!options.output) {
|
|
22
31
|
console.log(content);
|
|
@@ -144,7 +144,7 @@ function renderAiContextMarkdown(architecture, ux, options) {
|
|
|
144
144
|
}
|
|
145
145
|
lines.push(renderContextBlock(architecture, ux, {
|
|
146
146
|
focusQuery: options?.focusQuery,
|
|
147
|
-
maxLines: options?.maxLines ??
|
|
147
|
+
maxLines: options?.maxLines ?? 200,
|
|
148
148
|
structuralIntelligence: options?.structuralIntelligence
|
|
149
149
|
}));
|
|
150
150
|
lines.push("");
|
|
@@ -8,7 +8,36 @@ export function renderContextBlock(architecture, ux, options) {
|
|
|
8
8
|
lines.push("");
|
|
9
9
|
lines.push(`**Backend:** ${ormModels.length} ORM models + ${schemaModels} schemas · ${architecture.endpoints.length} endpoints · ${architecture.modules.length} modules`);
|
|
10
10
|
lines.push(`**Frontend:** ${ux.components.length} components · ${ux.pages.length} pages`);
|
|
11
|
+
// Show all roots if multi-root project
|
|
12
|
+
const roots = architecture.project.roots;
|
|
13
|
+
if (roots && roots.length > 2) {
|
|
14
|
+
lines.push(`**Roots:** ${roots.join(", ")}`);
|
|
15
|
+
}
|
|
11
16
|
lines.push("");
|
|
17
|
+
// Module map with key exports — the most useful section for AI context
|
|
18
|
+
const modulesWithExports = architecture.modules.filter(m => m.exports.length > 0 || m.files.length > 0);
|
|
19
|
+
if (modulesWithExports.length > 0) {
|
|
20
|
+
lines.push("### Module Map");
|
|
21
|
+
for (const mod of modulesWithExports) {
|
|
22
|
+
const allSymbols = mod.exports.flatMap(e => e.symbols).filter(Boolean);
|
|
23
|
+
const topSymbols = allSymbols.slice(0, 6);
|
|
24
|
+
const symbolStr = topSymbols.length > 0
|
|
25
|
+
? ` — exports: ${topSymbols.join(", ")}${allSymbols.length > 6 ? ` (+${allSymbols.length - 6} more)` : ""}`
|
|
26
|
+
: ` — ${mod.files.length} files`;
|
|
27
|
+
const epCount = mod.endpoints.length > 0 ? ` · ${mod.endpoints.length} endpoints` : "";
|
|
28
|
+
lines.push(`- **${mod.id}** (${mod.layer})${epCount}${symbolStr}`);
|
|
29
|
+
}
|
|
30
|
+
lines.push("");
|
|
31
|
+
}
|
|
32
|
+
// Cross-module dependencies
|
|
33
|
+
const crossEdges = architecture.dependencies.module_graph.filter(e => e.from !== e.to);
|
|
34
|
+
if (crossEdges.length > 0) {
|
|
35
|
+
lines.push("### Module Dependencies");
|
|
36
|
+
for (const edge of crossEdges.slice(0, 10)) {
|
|
37
|
+
lines.push(`- ${edge.from} → ${edge.to}`);
|
|
38
|
+
}
|
|
39
|
+
lines.push("");
|
|
40
|
+
}
|
|
12
41
|
const couplingFiles = pickTopCouplingFiles(architecture, options?.heatmap, 5);
|
|
13
42
|
if (couplingFiles.length > 0) {
|
|
14
43
|
lines.push("### High-Coupling Files");
|
|
@@ -102,12 +131,29 @@ export function renderContextBlock(architecture, ux, options) {
|
|
|
102
131
|
lines.push("");
|
|
103
132
|
}
|
|
104
133
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
134
|
+
// Deep intelligence pointers — tell AI agents where to find more detail
|
|
135
|
+
lines.push("### Deep Intelligence");
|
|
136
|
+
lines.push("");
|
|
137
|
+
lines.push("The above is a summary. For deeper analysis, these files and commands are available:");
|
|
138
|
+
lines.push("");
|
|
139
|
+
lines.push("**Files** (read directly when you need detail):");
|
|
140
|
+
lines.push("- `.specs/machine/architecture.snapshot.yaml` — full module map with every file, export symbol, import edge");
|
|
141
|
+
lines.push("- `.specs/machine/codebase-intelligence.json` — API registry with handler code, service calls, request/response schemas");
|
|
142
|
+
lines.push("- `.specs/machine/structural-intelligence.json` — depth/complexity analysis per module");
|
|
143
|
+
if (architecture.dependencies.file_graph.length > 0) {
|
|
144
|
+
lines.push("- `.specs/machine/architecture.snapshot.yaml → dependencies.file_graph` — file-level dependency edges");
|
|
145
|
+
}
|
|
146
|
+
if (architecture.analysis?.circular_dependencies?.length > 0) {
|
|
147
|
+
lines.push(`- Circular dependencies detected: ${architecture.analysis.circular_dependencies.length} cycles (check snapshot)`);
|
|
109
148
|
}
|
|
110
|
-
|
|
149
|
+
lines.push("");
|
|
150
|
+
lines.push("**Commands** (run in terminal for targeted lookup):");
|
|
151
|
+
lines.push("- `guardian search --query \"<feature>\"` — search endpoints, models, components, modules by keyword");
|
|
152
|
+
lines.push("- `guardian context --focus \"<feature>\"` — generate focused context for a specific area");
|
|
153
|
+
lines.push("- `guardian drift` — check architectural drift metrics");
|
|
154
|
+
lines.push("");
|
|
155
|
+
lines.push("<!-- /guardian:context -->");
|
|
156
|
+
return lines.join("\n");
|
|
111
157
|
}
|
|
112
158
|
function tokenize(value) {
|
|
113
159
|
return value
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toolbaux/guardian",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Architectural intelligence for codebases. Verify that AI-generated code matches your architectural intent.",
|
|
6
6
|
"keywords": [
|
|
@@ -41,7 +41,8 @@
|
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|
|
43
43
|
"build": "tsc -p tsconfig.json",
|
|
44
|
-
"prepublishOnly": "npm run build",
|
|
44
|
+
"prepublishOnly": "npm run test:critical && npm run build",
|
|
45
|
+
"test:critical": "vitest run tests/critical/",
|
|
45
46
|
"dev": "tsx src/cli.ts",
|
|
46
47
|
"start": "node dist/cli.js",
|
|
47
48
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|