@toolbaux/guardian 0.1.18 → 0.1.20

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.js CHANGED
@@ -1,4 +1,7 @@
1
1
  #!/usr/bin/env node
2
+ import { createRequire } from "node:module";
3
+ const _require = createRequire(import.meta.url);
4
+ const { version } = _require("../package.json");
2
5
  import { Command } from "commander";
3
6
  import { runExtract } from "./commands/extract.js";
4
7
  import { runDrift } from "./commands/drift.js";
@@ -24,7 +27,7 @@ const program = new Command();
24
27
  program
25
28
  .name("guardian")
26
29
  .description("Guardian — Architectural intelligence for codebases (by Toolbaux)")
27
- .version("0.1.0");
30
+ .version(version);
28
31
  program
29
32
  .command("generate")
30
33
  .description("Generate compact AI-ready architecture context")
@@ -98,6 +98,26 @@ async function loadIntel() {
98
98
  }
99
99
  return intel;
100
100
  }
101
+ // ── Function intelligence loader ──
102
+ let funcIntel = null;
103
+ let funcIntelPath = "";
104
+ let funcIntelLoadTime = 0;
105
+ async function loadFuncIntel() {
106
+ if (!funcIntelPath)
107
+ return null;
108
+ const now = Date.now();
109
+ if (funcIntel && now - funcIntelLoadTime < 5000)
110
+ return funcIntel;
111
+ try {
112
+ const raw = await fs.readFile(funcIntelPath, "utf8");
113
+ funcIntel = JSON.parse(raw);
114
+ funcIntelLoadTime = now;
115
+ }
116
+ catch {
117
+ // File may not exist yet — not an error
118
+ }
119
+ return funcIntel;
120
+ }
101
121
  // ── Helpers ──
102
122
  const SKIP_SERVICES = new Set(["str", "dict", "int", "len", "float", "max", "join", "getattr", "lower", "open", "params.append", "updates.append"]);
103
123
  function compact(obj) {
@@ -291,11 +311,38 @@ async function search(args) {
291
311
  // Frontend pages: match path or component
292
312
  const pages = (d.frontend_pages || []).filter((p) => p.path?.toLowerCase().includes(q) || p.component?.toLowerCase().includes(q) ||
293
313
  p.api_calls?.some((c) => c.toLowerCase().includes(q))).slice(0, 5).map((p) => `${p.path} → ${p.component}`);
314
+ // Functions: search literal_index (tactic:simp, sorry, string patterns) + function names
315
+ const fnHits = [];
316
+ const fi = await loadFuncIntel();
317
+ if (fi) {
318
+ // Literal index: exact key match + partial key match
319
+ const litIndex = fi.literal_index ?? {};
320
+ for (const [key, hits] of Object.entries(litIndex)) {
321
+ if (key.includes(q)) {
322
+ for (const h of hits.slice(0, 3)) {
323
+ fnHits.push(`${h.function} [${h.file}:${h.line}] (lit:${key})`);
324
+ }
325
+ }
326
+ if (fnHits.length >= 10)
327
+ break;
328
+ }
329
+ // Function names: match by name
330
+ if (fnHits.length < 10) {
331
+ for (const fn of (fi.functions ?? [])) {
332
+ if (fn.name?.toLowerCase().includes(q)) {
333
+ fnHits.push(`${fn.name} [${fn.file}:${fn.lines?.[0]}]`);
334
+ if (fnHits.length >= 10)
335
+ break;
336
+ }
337
+ }
338
+ }
339
+ }
294
340
  return compact({
295
341
  ep: eps, mod: models, m: mods,
296
342
  exports: exports.slice(0, 10),
297
343
  files: files.slice(0, 8),
298
344
  enums, tasks, pages,
345
+ ...(fnHits.length > 0 ? { fns: fnHits } : {}),
299
346
  });
300
347
  }
301
348
  async function model(args) {
@@ -458,8 +505,10 @@ export async function runMcpServe(options) {
458
505
  const specsDir = path.resolve(options.specs);
459
506
  const quiet = options.quiet ?? false;
460
507
  intelPath = path.join(specsDir, "machine", "codebase-intelligence.json");
508
+ funcIntelPath = path.join(specsDir, "machine", "function-intelligence.json");
461
509
  // Pre-load intelligence
462
510
  await loadIntel();
511
+ await loadFuncIntel();
463
512
  // Log to stderr (stdout is for MCP protocol)
464
513
  if (!quiet) {
465
514
  process.stderr.write(`Guardian MCP server started. Intelligence: ${intelPath}\n`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toolbaux/guardian",
3
- "version": "0.1.18",
3
+ "version": "0.1.20",
4
4
  "type": "module",
5
5
  "description": "Architectural intelligence for codebases. Verify that AI-generated code matches your architectural intent.",
6
6
  "keywords": [