@toolbaux/guardian 0.1.2 → 0.1.3

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
@@ -18,6 +18,7 @@ import { runDocGenerate } from "./commands/doc-generate.js";
18
18
  import { runDiscrepancy } from "./commands/discrepancy.js";
19
19
  import { runDocHtml } from "./commands/doc-html.js";
20
20
  import { runInit } from "./commands/init.js";
21
+ import { DEFAULT_SPECS_DIR } from "./config.js";
21
22
  const program = new Command();
22
23
  program
23
24
  .name("guardian")
@@ -30,7 +31,7 @@ program
30
31
  .option("--backend-root <path>", "Path to backend root")
31
32
  .option("--frontend-root <path>", "Path to frontend root")
32
33
  .option("--config <path>", "Path to specguard.config.json")
33
- .option("--output <path>", "Output directory", "specs-out")
34
+ .option("--output <path>", "Output directory", DEFAULT_SPECS_DIR)
34
35
  .option("--focus <text>", "Focus the generated AI context on a feature area")
35
36
  .option("--max-lines <count>", "Maximum lines for the generated context")
36
37
  .option("--ai-context", "Generate architecture-context.md for AI tools", false)
@@ -52,7 +53,7 @@ program
52
53
  .argument("[projectRoot]", "Repo or project root", process.cwd())
53
54
  .option("--backend-root <path>", "Path to backend root")
54
55
  .option("--frontend-root <path>", "Path to frontend root")
55
- .option("--output <path>", "Output directory", "specs-out")
56
+ .option("--output <path>", "Output directory", DEFAULT_SPECS_DIR)
56
57
  .option("--include-file-graph", "Include file-level dependency graph", false)
57
58
  .option("--config <path>", "Path to specguard.config.json")
58
59
  .option("--docs-mode <mode>", "Docs mode (lean|full)")
@@ -61,7 +62,7 @@ program
61
62
  projectRoot,
62
63
  backendRoot: options.backendRoot,
63
64
  frontendRoot: options.frontendRoot,
64
- output: options.output ?? "specs-out",
65
+ output: options.output ?? DEFAULT_SPECS_DIR,
65
66
  includeFileGraph: options.includeFileGraph ?? false,
66
67
  configPath: options.config,
67
68
  docsMode: options.docsMode
@@ -194,24 +195,24 @@ program
194
195
  program
195
196
  .command("summary")
196
197
  .description("Generate a plain-language project summary from existing snapshots")
197
- .option("--input <path>", "Snapshot output directory", "specs-out")
198
+ .option("--input <path>", "Snapshot output directory", DEFAULT_SPECS_DIR)
198
199
  .option("--output <path>", "Summary output path")
199
200
  .action(async (options) => {
200
201
  await runSummary({
201
- input: options.input ?? "specs-out",
202
+ input: options.input ?? DEFAULT_SPECS_DIR,
202
203
  output: options.output
203
204
  });
204
205
  });
205
206
  program
206
207
  .command("search")
207
208
  .description("Search existing snapshots for models, endpoints, components, modules, and tasks")
208
- .option("--input <path>", "Snapshot output directory", "specs-out")
209
+ .option("--input <path>", "Snapshot output directory", DEFAULT_SPECS_DIR)
209
210
  .requiredOption("--query <text>", "Search query")
210
211
  .option("--output <path>", "Write search results to a file")
211
212
  .option("--types <items>", "Comma-separated filters: models,endpoints,components,modules,tasks")
212
213
  .action(async (options) => {
213
214
  await runSearch({
214
- input: options.input ?? "specs-out",
215
+ input: options.input ?? DEFAULT_SPECS_DIR,
215
216
  query: options.query,
216
217
  output: options.output,
217
218
  types: options.types ? [options.types] : undefined
@@ -220,13 +221,13 @@ program
220
221
  program
221
222
  .command("context")
222
223
  .description("Render an AI-ready context block from existing snapshots")
223
- .option("--input <path>", "Snapshot output directory", "specs-out")
224
+ .option("--input <path>", "Snapshot output directory", DEFAULT_SPECS_DIR)
224
225
  .option("--output <path>", "Append the context block to a file")
225
226
  .option("--focus <text>", "Focus the context on a feature area")
226
227
  .option("--max-lines <count>", "Maximum number of lines to include")
227
228
  .action(async (options) => {
228
229
  await runContext({
229
- input: options.input ?? "specs-out",
230
+ input: options.input ?? DEFAULT_SPECS_DIR,
230
231
  output: options.output,
231
232
  focus: options.focus,
232
233
  maxLines: options.maxLines
@@ -258,7 +259,7 @@ program
258
259
  program
259
260
  .command("intel")
260
261
  .description("Build codebase-intelligence.json from existing snapshots")
261
- .option("--specs <dir>", "Snapshot output directory", "specs-out")
262
+ .option("--specs <dir>", "Snapshot output directory", DEFAULT_SPECS_DIR)
262
263
  .option("--output <path>", "Output path for codebase-intelligence.json")
263
264
  .action(async (options) => {
264
265
  await runIntel({
@@ -270,7 +271,7 @@ program
270
271
  .command("feature-context")
271
272
  .description("Generate a filtered context packet for implementing a single feature")
272
273
  .requiredOption("--spec <file>", "Path to feature spec YAML")
273
- .option("--specs <dir>", "Snapshot output directory", "specs-out")
274
+ .option("--specs <dir>", "Snapshot output directory", DEFAULT_SPECS_DIR)
274
275
  .option("--output <path>", "Output path for feature context JSON")
275
276
  .action(async (options) => {
276
277
  await runFeatureContext({
@@ -282,7 +283,7 @@ program
282
283
  program
283
284
  .command("doc-generate")
284
285
  .description("Generate a human-readable product document from codebase intelligence")
285
- .option("--specs <dir>", "Snapshot output directory", "specs-out")
286
+ .option("--specs <dir>", "Snapshot output directory", DEFAULT_SPECS_DIR)
286
287
  .option("--feature-specs <dir>", "Directory of feature spec YAML files")
287
288
  .option("--output <path>", "Output path for product-document.md")
288
289
  .option("--update-baseline", "Freeze current state as new baseline for discrepancy tracking", false)
@@ -297,7 +298,7 @@ program
297
298
  program
298
299
  .command("discrepancy")
299
300
  .description("Diff current codebase intelligence against a committed baseline")
300
- .option("--specs <dir>", "Snapshot output directory", "specs-out")
301
+ .option("--specs <dir>", "Snapshot output directory", DEFAULT_SPECS_DIR)
301
302
  .option("--feature-specs <dir>", "Directory of feature spec YAML files")
302
303
  .option("--output <path>", "Output path (used when --format is json or md)")
303
304
  .option("--format <fmt>", "Output format: json, md, or both (default: both)", "both")
@@ -312,11 +313,11 @@ program
312
313
  program
313
314
  .command("doc-html")
314
315
  .description("Generate a self-contained Javadoc-style HTML viewer from codebase intelligence")
315
- .option("--specs <dir>", "Snapshot output directory", "specs-out")
316
+ .option("--specs <dir>", "Snapshot output directory", DEFAULT_SPECS_DIR)
316
317
  .option("--output <path>", "Output path for index.html")
317
318
  .action(async (options) => {
318
319
  await runDocHtml({
319
- specs: options.specs ?? "specs-out",
320
+ specs: options.specs ?? DEFAULT_SPECS_DIR,
320
321
  output: options.output,
321
322
  });
322
323
  });
@@ -326,7 +327,7 @@ program
326
327
  .argument("[projectRoot]", "Repo or project root", process.cwd())
327
328
  .option("--backend-root <path>", "Path to backend root")
328
329
  .option("--frontend-root <path>", "Path to frontend root")
329
- .option("--output <path>", "Output directory", ".specs")
330
+ .option("--output <path>", "Output directory", DEFAULT_SPECS_DIR)
330
331
  .option("--skip-hook", "Skip pre-commit hook installation", false)
331
332
  .action(async (projectRoot, options) => {
332
333
  await runInit({
@@ -3,12 +3,13 @@ import fs from "node:fs/promises";
3
3
  import yaml from "js-yaml";
4
4
  import { buildSnapshots } from "../extract/index.js";
5
5
  import { analyzeDepth } from "../extract/analyzers/depth.js";
6
+ import { DEFAULT_SPECS_DIR } from "../config.js";
6
7
  export async function runAnalyzeDepth(options) {
7
8
  const { architecture } = await buildSnapshots({
8
9
  projectRoot: options.projectRoot,
9
10
  backendRoot: options.backendRoot,
10
11
  frontendRoot: options.frontendRoot,
11
- output: options.output ?? "specs-out",
12
+ output: options.output ?? DEFAULT_SPECS_DIR,
12
13
  includeFileGraph: true,
13
14
  configPath: options.configPath
14
15
  });
@@ -4,8 +4,9 @@ import yaml from "js-yaml";
4
4
  import { loadArchitectureDiff, loadHeatmap } from "../extract/compress.js";
5
5
  import { renderContextBlock } from "../extract/context-block.js";
6
6
  import { resolveMachineInputDir } from "../output-layout.js";
7
+ import { DEFAULT_SPECS_DIR } from "../config.js";
7
8
  export async function runContext(options) {
8
- const inputDir = await resolveMachineInputDir(options.input || "specs-out");
9
+ const inputDir = await resolveMachineInputDir(options.input || DEFAULT_SPECS_DIR);
9
10
  const { architecture, ux } = await loadSnapshots(inputDir);
10
11
  const [diff, heatmap] = await Promise.all([
11
12
  loadArchitectureDiff(inputDir),
@@ -1,6 +1,9 @@
1
+ import fs from "node:fs/promises";
1
2
  import path from "node:path";
2
3
  import { extractProject } from "../extract/index.js";
3
4
  import { runIntel } from "./intel.js";
5
+ import { runGenerate } from "./generate.js";
6
+ import { runContext } from "./context.js";
4
7
  export async function runExtract(options) {
5
8
  const { architecturePath, uxPath } = await extractProject(options);
6
9
  console.log(`Wrote ${architecturePath}`);
@@ -13,4 +16,26 @@ export async function runExtract(options) {
13
16
  catch {
14
17
  // Non-fatal — intel build failure should not break extract
15
18
  }
19
+ // Auto-generate AI context + inject into CLAUDE.md
20
+ const projectRoot = path.resolve(options.projectRoot || process.cwd());
21
+ try {
22
+ await runGenerate({
23
+ projectRoot,
24
+ backendRoot: options.backendRoot,
25
+ frontendRoot: options.frontendRoot,
26
+ output: specsDir,
27
+ aiContext: true,
28
+ });
29
+ const claudeMdPath = path.join(projectRoot, "CLAUDE.md");
30
+ try {
31
+ await fs.stat(claudeMdPath);
32
+ await runContext({ input: specsDir, output: claudeMdPath });
33
+ }
34
+ catch {
35
+ // No CLAUDE.md — skip context injection
36
+ }
37
+ }
38
+ catch {
39
+ // Non-fatal — context generation failure should not break extract
40
+ }
16
41
  }
@@ -3,12 +3,13 @@ import path from "node:path";
3
3
  import { buildSnapshots } from "../extract/index.js";
4
4
  import { renderContextBlock } from "../extract/context-block.js";
5
5
  import { getOutputLayout } from "../output-layout.js";
6
+ import { DEFAULT_SPECS_DIR } from "../config.js";
6
7
  import { analyzeDepth } from "../extract/analyzers/depth.js";
7
8
  export async function runGenerate(options) {
8
9
  if (!options.aiContext) {
9
10
  throw new Error("`specguard generate` currently supports `--ai-context` only.");
10
11
  }
11
- const outputRoot = path.resolve(options.output ?? "specs-out");
12
+ const outputRoot = path.resolve(options.output ?? DEFAULT_SPECS_DIR);
12
13
  const layout = getOutputLayout(outputRoot);
13
14
  const { architecture, ux } = await buildSnapshots({
14
15
  projectRoot: options.projectRoot,
@@ -6,6 +6,7 @@ import { runSimulate } from "./simulate.js";
6
6
  import { buildSnapshots } from "../extract/index.js";
7
7
  import { renderContextBlock } from "../extract/context-block.js";
8
8
  import { logResolvedProjectPaths, resolveProjectPaths } from "../project-discovery.js";
9
+ import { DEFAULT_SPECS_DIR } from "../config.js";
9
10
  export async function runGuard(options) {
10
11
  const resolved = await resolveProjectPaths({
11
12
  projectRoot: options.projectRoot,
@@ -30,7 +31,7 @@ export async function runGuard(options) {
30
31
  projectRoot: resolved.workspaceRoot,
31
32
  backendRoot: resolved.backendRoot,
32
33
  frontendRoot: resolved.frontendRoot,
33
- output: "specs-out",
34
+ output: DEFAULT_SPECS_DIR,
34
35
  includeFileGraph: true,
35
36
  configPath: options.configPath
36
37
  });
@@ -12,6 +12,7 @@
12
12
  */
13
13
  import fs from "node:fs/promises";
14
14
  import path from "node:path";
15
+ import { DEFAULT_SPECS_DIR } from "../config.js";
15
16
  const DEFAULT_CONFIG = {
16
17
  project: {
17
18
  backendRoot: "./backend",
@@ -47,7 +48,7 @@ exit 0
47
48
  `;
48
49
  export async function runInit(options) {
49
50
  const root = path.resolve(options.projectRoot || process.cwd());
50
- const specsDir = path.join(root, options.output || ".specs");
51
+ const specsDir = path.join(root, options.output || DEFAULT_SPECS_DIR);
51
52
  console.log(`Initializing Guardian in ${root}\n`);
52
53
  // 1. Create .specs/ directory
53
54
  await fs.mkdir(path.join(specsDir, "machine", "docs"), { recursive: true });
@@ -3,8 +3,9 @@ import path from "node:path";
3
3
  import yaml from "js-yaml";
4
4
  import { loadHeatmap } from "../extract/compress.js";
5
5
  import { resolveMachineInputDir } from "../output-layout.js";
6
+ import { DEFAULT_SPECS_DIR } from "../config.js";
6
7
  export async function runSearch(options) {
7
- const inputDir = await resolveMachineInputDir(options.input || "specs-out");
8
+ const inputDir = await resolveMachineInputDir(options.input || DEFAULT_SPECS_DIR);
8
9
  const { architecture, ux } = await loadSnapshots(inputDir);
9
10
  const heatmap = await loadHeatmap(inputDir);
10
11
  const types = normalizeTypes(options.types);
@@ -6,6 +6,7 @@ import { spawn } from "node:child_process";
6
6
  import yaml from "js-yaml";
7
7
  import { buildSnapshots } from "../extract/index.js";
8
8
  import { buildArchitectureSummary, loadArchitectureSummary } from "../extract/compress.js";
9
+ import { DEFAULT_SPECS_DIR } from "../config.js";
9
10
  import { createIgnoreMatcher } from "../extract/ignore.js";
10
11
  import { logResolvedProjectPaths, resolveProjectPaths } from "../project-discovery.js";
11
12
  export async function runSimulate(options) {
@@ -106,7 +107,7 @@ async function resolveBaselineSummaryPath(params) {
106
107
  if (params.override) {
107
108
  candidates.push(params.override);
108
109
  }
109
- candidates.push(path.join(params.projectRoot, "specs-out", "machine", "architecture.summary.json"));
110
+ candidates.push(path.join(params.projectRoot, DEFAULT_SPECS_DIR, "machine", "architecture.summary.json"));
110
111
  for (const candidate of candidates) {
111
112
  const resolved = path.isAbsolute(candidate)
112
113
  ? candidate
@@ -4,8 +4,9 @@ import yaml from "js-yaml";
4
4
  import { renderExecutiveSummary } from "../extract/docs.js";
5
5
  import { loadArchitectureSummary, loadArchitectureDiff, loadHeatmap } from "../extract/compress.js";
6
6
  import { resolveMachineInputDir } from "../output-layout.js";
7
+ import { DEFAULT_SPECS_DIR } from "../config.js";
7
8
  export async function runSummary(options) {
8
- const inputDir = await resolveMachineInputDir(options.input || "specs-out");
9
+ const inputDir = await resolveMachineInputDir(options.input || DEFAULT_SPECS_DIR);
9
10
  const architecturePath = path.join(inputDir, "architecture.snapshot.yaml");
10
11
  const uxPath = path.join(inputDir, "ux.snapshot.yaml");
11
12
  const [architectureRaw, uxRaw] = await Promise.all([
package/dist/config.js CHANGED
@@ -1,5 +1,7 @@
1
1
  import fs from "node:fs/promises";
2
2
  import path from "node:path";
3
+ /** Single source of truth for the default specs output directory */
4
+ export const DEFAULT_SPECS_DIR = ".specs";
3
5
  const DEFAULT_CONFIG = {
4
6
  project: {
5
7
  root: "",
@@ -29,8 +31,13 @@ const DEFAULT_CONFIG = {
29
31
  "log",
30
32
  "tmp",
31
33
  "cache",
32
- "specs-out",
33
- "ghost-out"
34
+ ".specs",
35
+ "ghost-out",
36
+ "ios",
37
+ "android",
38
+ ".expo",
39
+ ".turbo",
40
+ "web-build"
34
41
  ],
35
42
  paths: []
36
43
  },
@@ -77,6 +84,9 @@ const DEFAULT_CONFIG = {
77
84
  timeoutMs: 120000,
78
85
  promptTemplate: ""
79
86
  },
87
+ output: {
88
+ specsDir: DEFAULT_SPECS_DIR
89
+ },
80
90
  docs: {
81
91
  mode: "lean",
82
92
  internalDir: "internal"
@@ -338,6 +348,9 @@ function mergeConfig(base, override) {
338
348
  timeoutMs: override.llm?.timeoutMs ?? base.llm?.timeoutMs ?? 120000,
339
349
  promptTemplate: override.llm?.promptTemplate ?? base.llm?.promptTemplate ?? ""
340
350
  },
351
+ output: {
352
+ specsDir: override.output?.specsDir ?? base.output?.specsDir ?? DEFAULT_SPECS_DIR
353
+ },
341
354
  docs: {
342
355
  mode: override.docs?.mode ?? base.docs?.mode ?? "lean",
343
356
  internalDir: override.docs?.internalDir ?? base.docs?.internalDir ?? "internal"
@@ -1,9 +1,10 @@
1
1
  import crypto from "node:crypto";
2
2
  import fs from "node:fs/promises";
3
3
  import path from "node:path";
4
+ import { DEFAULT_SPECS_DIR } from "../config.js";
4
5
  const BACKEND_CACHE_VERSION = "specguard-backend-cache-v4";
5
6
  export async function loadBackendExtractionCache(params) {
6
- const cachePath = path.join(params.projectRoot, "specs-out", ".cache", "file-hashes.json");
7
+ const cachePath = path.join(params.projectRoot, DEFAULT_SPECS_DIR, ".cache", "file-hashes.json");
7
8
  const configHash = hashObject(params.config);
8
9
  try {
9
10
  const raw = await fs.readFile(cachePath, "utf8");
@@ -1,5 +1,6 @@
1
1
  import path from "node:path";
2
2
  import fs from "node:fs/promises";
3
+ import { DEFAULT_SPECS_DIR } from "./config.js";
3
4
  export function getOutputLayout(outputRoot, internalDir = "internal") {
4
5
  const rootDir = path.resolve(outputRoot);
5
6
  const machineDir = path.join(rootDir, "machine");
@@ -12,7 +13,7 @@ export function getOutputLayout(outputRoot, internalDir = "internal") {
12
13
  };
13
14
  }
14
15
  export async function resolveMachineInputDir(input) {
15
- const resolved = path.resolve(input || "specs-out");
16
+ const resolved = path.resolve(input || DEFAULT_SPECS_DIR);
16
17
  const directSnapshot = await hasMachineSnapshots(resolved);
17
18
  if (directSnapshot) {
18
19
  return resolved;
@@ -1,6 +1,6 @@
1
1
  import fs from "node:fs/promises";
2
2
  import path from "node:path";
3
- import { loadSpecGuardConfig } from "./config.js";
3
+ import { DEFAULT_SPECS_DIR, loadSpecGuardConfig } from "./config.js";
4
4
  const IGNORE_DIRS = new Set([
5
5
  ".git",
6
6
  "node_modules",
@@ -11,7 +11,7 @@ const IGNORE_DIRS = new Set([
11
11
  "__pycache__",
12
12
  ".venv",
13
13
  "venv",
14
- "specs-out",
14
+ DEFAULT_SPECS_DIR,
15
15
  ".pytest_cache",
16
16
  ".mypy_cache",
17
17
  ".turbo"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toolbaux/guardian",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "type": "module",
5
5
  "description": "Architectural intelligence for codebases. Verify that AI-generated code matches your architectural intent.",
6
6
  "keywords": [