@toolbaux/guardian 0.1.0

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.
Files changed (78) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +366 -0
  3. package/dist/adapters/csharp-adapter.js +149 -0
  4. package/dist/adapters/go-adapter.js +96 -0
  5. package/dist/adapters/index.js +16 -0
  6. package/dist/adapters/java-adapter.js +122 -0
  7. package/dist/adapters/python-adapter.js +183 -0
  8. package/dist/adapters/runner.js +69 -0
  9. package/dist/adapters/types.js +1 -0
  10. package/dist/adapters/typescript-adapter.js +179 -0
  11. package/dist/benchmarking/framework.js +91 -0
  12. package/dist/cli.js +343 -0
  13. package/dist/commands/analyze-depth.js +43 -0
  14. package/dist/commands/api-spec-extractor.js +52 -0
  15. package/dist/commands/breaking-change-analyzer.js +334 -0
  16. package/dist/commands/config-compliance.js +219 -0
  17. package/dist/commands/constraints.js +221 -0
  18. package/dist/commands/context.js +101 -0
  19. package/dist/commands/data-flow-tracer.js +291 -0
  20. package/dist/commands/dependency-impact-analyzer.js +27 -0
  21. package/dist/commands/diff.js +146 -0
  22. package/dist/commands/discrepancy.js +71 -0
  23. package/dist/commands/doc-generate.js +163 -0
  24. package/dist/commands/doc-html.js +120 -0
  25. package/dist/commands/drift.js +88 -0
  26. package/dist/commands/extract.js +16 -0
  27. package/dist/commands/feature-context.js +116 -0
  28. package/dist/commands/generate.js +339 -0
  29. package/dist/commands/guard.js +182 -0
  30. package/dist/commands/init.js +209 -0
  31. package/dist/commands/intel.js +20 -0
  32. package/dist/commands/license-dependency-auditor.js +33 -0
  33. package/dist/commands/performance-hotspot-profiler.js +42 -0
  34. package/dist/commands/search.js +314 -0
  35. package/dist/commands/security-boundary-auditor.js +359 -0
  36. package/dist/commands/simulate.js +294 -0
  37. package/dist/commands/summary.js +27 -0
  38. package/dist/commands/test-coverage-mapper.js +264 -0
  39. package/dist/commands/verify-drift.js +62 -0
  40. package/dist/config.js +441 -0
  41. package/dist/extract/ai-context-hints.js +107 -0
  42. package/dist/extract/analyzers/backend.js +1704 -0
  43. package/dist/extract/analyzers/depth.js +264 -0
  44. package/dist/extract/analyzers/frontend.js +2221 -0
  45. package/dist/extract/api-usage-tracker.js +19 -0
  46. package/dist/extract/cache.js +53 -0
  47. package/dist/extract/codebase-intel.js +190 -0
  48. package/dist/extract/compress.js +452 -0
  49. package/dist/extract/context-block.js +356 -0
  50. package/dist/extract/contracts.js +183 -0
  51. package/dist/extract/discrepancies.js +233 -0
  52. package/dist/extract/docs-loader.js +110 -0
  53. package/dist/extract/docs.js +2379 -0
  54. package/dist/extract/drift.js +1578 -0
  55. package/dist/extract/duplicates.js +435 -0
  56. package/dist/extract/feature-arcs.js +138 -0
  57. package/dist/extract/graph.js +76 -0
  58. package/dist/extract/html-doc.js +1409 -0
  59. package/dist/extract/ignore.js +45 -0
  60. package/dist/extract/index.js +455 -0
  61. package/dist/extract/llm-client.js +159 -0
  62. package/dist/extract/pattern-registry.js +141 -0
  63. package/dist/extract/product-doc.js +497 -0
  64. package/dist/extract/python.js +1202 -0
  65. package/dist/extract/runtime.js +193 -0
  66. package/dist/extract/schema-evolution-validator.js +35 -0
  67. package/dist/extract/test-gap-analyzer.js +20 -0
  68. package/dist/extract/tests.js +74 -0
  69. package/dist/extract/types.js +1 -0
  70. package/dist/extract/validate-backend.js +30 -0
  71. package/dist/extract/writer.js +11 -0
  72. package/dist/output-layout.js +37 -0
  73. package/dist/project-discovery.js +309 -0
  74. package/dist/schema/architecture.js +350 -0
  75. package/dist/schema/feature-spec.js +89 -0
  76. package/dist/schema/index.js +8 -0
  77. package/dist/schema/ux.js +46 -0
  78. package/package.json +75 -0
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Feature Spec Schema — Zod schema for feature spec YAML files.
3
+ *
4
+ * Analogous to the compression block in the book workflow:
5
+ * a structured, machine-readable spec for a single feature/ticket/PR that
6
+ * declares exactly which endpoints, models, and patterns are involved.
7
+ *
8
+ * Example feature spec file (feature-specs/auth-refresh.yaml):
9
+ *
10
+ * feature: "JWT Refresh Token"
11
+ * description: "Add refresh token rotation to the auth flow"
12
+ * affected_endpoints:
13
+ * - POST /api/auth/refresh
14
+ * - POST /api/auth/logout
15
+ * affected_models:
16
+ * - RefreshToken
17
+ * - Session
18
+ * pattern: P2
19
+ * tradeoff: "Security vs. UX: shorter-lived tokens mean more frequent refreshes"
20
+ * failure_risk: "Token replay if refresh not rotated on use"
21
+ * maps_to: "AuthService.rotate_refresh_token()"
22
+ * sprint: 8
23
+ */
24
+ import { z } from "zod";
25
+ export const FeatureSpecSchema = z.object({
26
+ /** Short name of the feature — used as the context packet filename */
27
+ feature: z.string().min(1),
28
+ /** One or two sentence description of what this feature does */
29
+ description: z.string().default(""),
30
+ /**
31
+ * Endpoints this feature adds or modifies.
32
+ * Format: "METHOD /path" e.g. "POST /api/auth/refresh"
33
+ */
34
+ affected_endpoints: z.array(z.string()).default([]),
35
+ /**
36
+ * ORM models this feature reads from or writes to.
37
+ */
38
+ affected_models: z.array(z.string()).default([]),
39
+ /**
40
+ * Pattern ID(s) this feature uses (from the pattern registry).
41
+ * Single string or array: "P1" or ["P1", "P2"]
42
+ */
43
+ pattern: z
44
+ .union([z.string(), z.array(z.string())])
45
+ .transform((v) => (Array.isArray(v) ? v : [v]))
46
+ .default([]),
47
+ /**
48
+ * Architectural tradeoff involved (free text or AT-code if using DNCF series).
49
+ */
50
+ tradeoff: z.string().default(""),
51
+ /**
52
+ * Failure risk / failure mode to watch for.
53
+ */
54
+ failure_risk: z.string().default(""),
55
+ /**
56
+ * Primary service method or function this feature maps to.
57
+ * e.g. "AuthService.rotate_refresh_token()"
58
+ */
59
+ maps_to: z.string().default(""),
60
+ /**
61
+ * Sprint or version when this feature was / will be implemented.
62
+ * Used to build feature arc timelines.
63
+ */
64
+ sprint: z.union([z.number(), z.string()]).optional(),
65
+ /**
66
+ * Optional tags for grouping features (e.g. "auth", "billing", "core").
67
+ */
68
+ tags: z.array(z.string()).default([]),
69
+ });
70
+ /**
71
+ * Parse and validate a raw YAML-loaded object as a FeatureSpec.
72
+ * Throws a ZodError on invalid input.
73
+ */
74
+ export function parseFeatureSpec(raw) {
75
+ return FeatureSpecSchema.parse(raw);
76
+ }
77
+ /**
78
+ * Safe parse — returns { success, data } without throwing.
79
+ */
80
+ export function safeParseFeatureSpec(raw) {
81
+ const result = FeatureSpecSchema.safeParse(raw);
82
+ if (result.success) {
83
+ return { success: true, data: result.data };
84
+ }
85
+ return {
86
+ success: false,
87
+ error: result.error.issues.map((i) => `${i.path.join(".")}: ${i.message}`).join("; "),
88
+ };
89
+ }
@@ -0,0 +1,8 @@
1
+ import { architectureSnapshotSchema } from "./architecture.js";
2
+ import { uxSnapshotSchema } from "./ux.js";
3
+ export function validateArchitectureSnapshot(snapshot) {
4
+ architectureSnapshotSchema.parse(snapshot);
5
+ }
6
+ export function validateUxSnapshot(snapshot) {
7
+ uxSnapshotSchema.parse(snapshot);
8
+ }
@@ -0,0 +1,46 @@
1
+ import { z } from "zod";
2
+ export const uxPageSummarySchema = z.object({
3
+ path: z.string(),
4
+ component: z.string(),
5
+ component_id: z.string(),
6
+ components: z.array(z.string()),
7
+ components_direct: z.array(z.string()),
8
+ components_descendants: z.array(z.string()),
9
+ components_direct_ids: z.array(z.string()),
10
+ components_descendants_ids: z.array(z.string()),
11
+ local_state_variables: z.array(z.string()),
12
+ api_calls: z.array(z.string()),
13
+ component_api_calls: z.array(z.object({
14
+ component: z.string(),
15
+ component_id: z.string(),
16
+ api_calls: z.array(z.string())
17
+ })),
18
+ component_state_variables: z.array(z.object({
19
+ component: z.string(),
20
+ component_id: z.string(),
21
+ local_state_variables: z.array(z.string())
22
+ })),
23
+ possible_navigation: z.array(z.string())
24
+ });
25
+ export const uxSnapshotSchema = z.object({
26
+ version: z.literal("0.2"),
27
+ components: z.array(z.object({
28
+ id: z.string(),
29
+ name: z.string(),
30
+ file: z.string(),
31
+ kind: z.enum(["page", "component"]),
32
+ export_kind: z.enum(["default", "named"]),
33
+ props: z
34
+ .array(z.object({
35
+ name: z.string(),
36
+ type: z.string(),
37
+ optional: z.boolean()
38
+ }))
39
+ .optional()
40
+ })),
41
+ component_graph: z.array(z.object({
42
+ from: z.string(),
43
+ to: z.string()
44
+ })),
45
+ pages: z.array(uxPageSummarySchema)
46
+ });
package/package.json ADDED
@@ -0,0 +1,75 @@
1
+ {
2
+ "name": "@toolbaux/guardian",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "description": "Architectural intelligence for codebases. Verify that AI-generated code matches your architectural intent.",
6
+ "keywords": [
7
+ "architecture",
8
+ "ai",
9
+ "code-generation",
10
+ "drift",
11
+ "verification",
12
+ "guardian",
13
+ "specguard",
14
+ "ast",
15
+ "tree-sitter",
16
+ "claude",
17
+ "cursor",
18
+ "copilot"
19
+ ],
20
+ "license": "MIT",
21
+ "author": "Harish Kumar",
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "https://github.com/idocoding/guardian"
25
+ },
26
+ "homepage": "https://github.com/idocoding/guardian#readme",
27
+ "bugs": {
28
+ "url": "https://github.com/idocoding/guardian/issues"
29
+ },
30
+ "bin": {
31
+ "guardian": "dist/cli.js",
32
+ "specguard": "dist/cli.js"
33
+ },
34
+ "files": [
35
+ "dist/",
36
+ "README.md",
37
+ "LICENSE"
38
+ ],
39
+ "engines": {
40
+ "node": ">=18.0.0"
41
+ },
42
+ "scripts": {
43
+ "build": "tsc -p tsconfig.json",
44
+ "prepublishOnly": "npm run build",
45
+ "dev": "tsx src/cli.ts",
46
+ "start": "node dist/cli.js",
47
+ "typecheck": "tsc -p tsconfig.json --noEmit",
48
+ "test": "vitest run",
49
+ "test:watch": "vitest",
50
+ "test:hallucination": "tsx scripts/test-hallucination-prevention.ts",
51
+ "benchmark:cto": "tsx scripts/cto-pitch-benchmark.ts",
52
+ "benchmark:llm": "tsx scripts/benchmark-llm-context/index.ts"
53
+ },
54
+ "dependencies": {
55
+ "commander": "^12.1.0",
56
+ "dotenv": "^17.3.1",
57
+ "js-yaml": "^4.1.0",
58
+ "openai": "^6.32.0",
59
+ "tree-sitter": "^0.21.0",
60
+ "tree-sitter-c-sharp": "^0.21.1",
61
+ "tree-sitter-go": "^0.21.0",
62
+ "tree-sitter-java": "^0.23.5",
63
+ "tree-sitter-python": "^0.21.0",
64
+ "tree-sitter-typescript": "^0.23.2",
65
+ "typescript": "^5.6.3",
66
+ "zod": "^3.23.8"
67
+ },
68
+ "devDependencies": {
69
+ "@types/js-yaml": "^4.0.9",
70
+ "@types/node": "^20.11.30",
71
+ "@vitest/coverage-v8": "^4.1.0",
72
+ "tsx": "^4.19.2",
73
+ "vitest": "^4.1.0"
74
+ }
75
+ }