tribunal-kit 4.4.0 → 4.4.1

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 (85) hide show
  1. package/.agent/agents/api-architect.md +66 -66
  2. package/.agent/agents/db-latency-auditor.md +216 -216
  3. package/.agent/agents/precedence-reviewer.md +250 -250
  4. package/.agent/agents/resilience-reviewer.md +88 -88
  5. package/.agent/agents/schema-reviewer.md +67 -67
  6. package/.agent/agents/throughput-optimizer.md +299 -299
  7. package/.agent/agents/ui-ux-auditor.md +292 -292
  8. package/.agent/agents/vitals-reviewer.md +223 -223
  9. package/.agent/scripts/_colors.js +18 -18
  10. package/.agent/scripts/_utils.js +42 -42
  11. package/.agent/scripts/append_flow.js +72 -72
  12. package/.agent/scripts/auto_preview.js +197 -197
  13. package/.agent/scripts/bundle_analyzer.js +290 -290
  14. package/.agent/scripts/case_law_manager.js +17 -6
  15. package/.agent/scripts/checklist.js +266 -266
  16. package/.agent/scripts/colors.js +17 -17
  17. package/.agent/scripts/compress_skills.js +141 -141
  18. package/.agent/scripts/consolidate_skills.js +149 -149
  19. package/.agent/scripts/context_broker.js +611 -609
  20. package/.agent/scripts/deep_compress.js +150 -150
  21. package/.agent/scripts/dependency_analyzer.js +272 -272
  22. package/.agent/scripts/graph_builder.js +313 -311
  23. package/.agent/scripts/graph_visualizer.js +384 -384
  24. package/.agent/scripts/inner_loop_validator.js +451 -465
  25. package/.agent/scripts/lint_runner.js +187 -187
  26. package/.agent/scripts/minify_context.js +100 -100
  27. package/.agent/scripts/mutation_runner.js +280 -280
  28. package/.agent/scripts/patch_skills_meta.js +156 -156
  29. package/.agent/scripts/patch_skills_output.js +244 -244
  30. package/.agent/scripts/schema_validator.js +297 -297
  31. package/.agent/scripts/security_scan.js +303 -303
  32. package/.agent/scripts/session_manager.js +276 -276
  33. package/.agent/scripts/skill_evolution.js +644 -644
  34. package/.agent/scripts/skill_integrator.js +313 -313
  35. package/.agent/scripts/strengthen_skills.js +193 -193
  36. package/.agent/scripts/strip_tribunal.js +47 -47
  37. package/.agent/scripts/swarm_dispatcher.js +360 -360
  38. package/.agent/scripts/test_runner.js +193 -193
  39. package/.agent/scripts/utils.js +32 -32
  40. package/.agent/scripts/verify_all.js +257 -256
  41. package/.agent/skills/app-builder/templates/astro-static/TEMPLATE.md +1 -1
  42. package/.agent/skills/app-builder/templates/chrome-extension/TEMPLATE.md +1 -1
  43. package/.agent/skills/app-builder/templates/cli-tool/TEMPLATE.md +1 -1
  44. package/.agent/skills/app-builder/templates/electron-desktop/TEMPLATE.md +1 -1
  45. package/.agent/skills/app-builder/templates/express-api/TEMPLATE.md +1 -1
  46. package/.agent/skills/app-builder/templates/flutter-app/TEMPLATE.md +1 -1
  47. package/.agent/skills/app-builder/templates/monorepo-turborepo/TEMPLATE.md +1 -1
  48. package/.agent/skills/app-builder/templates/nextjs-fullstack/TEMPLATE.md +1 -1
  49. package/.agent/skills/app-builder/templates/nextjs-saas/TEMPLATE.md +1 -1
  50. package/.agent/skills/app-builder/templates/nextjs-static/TEMPLATE.md +1 -1
  51. package/.agent/skills/app-builder/templates/nuxt-app/TEMPLATE.md +1 -1
  52. package/.agent/skills/app-builder/templates/python-fastapi/TEMPLATE.md +1 -1
  53. package/.agent/skills/app-builder/templates/react-native-app/TEMPLATE.md +1 -1
  54. package/.agent/skills/doc.md +1 -1
  55. package/.agent/skills/knowledge-graph/SKILL.md +52 -52
  56. package/.agent/skills/ui-ux-pro-max/SKILL.md +562 -562
  57. package/.agent/workflows/generate.md +183 -183
  58. package/.agent/workflows/tribunal-speed.md +183 -183
  59. package/README.md +1 -1
  60. package/bin/tribunal-kit.js +76 -87
  61. package/package.json +6 -3
  62. package/scripts/changelog.js +167 -167
  63. package/scripts/sync-version.js +81 -81
  64. package/.agent/history/architecture-explorer.html +0 -352
  65. package/.agent/history/architecture-graph.yaml +0 -109
  66. package/.agent/history/graph-cache.json +0 -215
  67. package/.agent/history/snapshots/migrate_refs.js.json +0 -11
  68. package/.agent/history/snapshots/scripts__changelog.js.json +0 -12
  69. package/.agent/history/snapshots/scripts__sync-version.js.json +0 -11
  70. package/.agent/history/snapshots/scripts__validate-payload.js.json +0 -11
  71. package/.agent/history/snapshots/test__integration__bridges.test.js.json +0 -13
  72. package/.agent/history/snapshots/test__integration__init.test.js.json +0 -13
  73. package/.agent/history/snapshots/test__integration__routing.test.js.json +0 -11
  74. package/.agent/history/snapshots/test__integration__swarm_dispatcher.test.js.json +0 -13
  75. package/.agent/history/snapshots/test__integration__wave2.test.js.json +0 -13
  76. package/.agent/history/snapshots/test__unit__args.test.js.json +0 -10
  77. package/.agent/history/snapshots/test__unit__case_law_manager.test.js.json +0 -10
  78. package/.agent/history/snapshots/test__unit__copyDir.test.js.json +0 -13
  79. package/.agent/history/snapshots/test__unit__graph_tools.test.js.json +0 -11
  80. package/.agent/history/snapshots/test__unit__selfInstall.test.js.json +0 -13
  81. package/.agent/history/snapshots/test__unit__semver.test.js.json +0 -10
  82. package/.agent/history/snapshots/test__unit__swarm_dispatcher.test.js.json +0 -11
  83. package/.agent/scripts/__pycache__/_colors.cpython-311.pyc +0 -0
  84. package/.agent/scripts/__pycache__/_utils.cpython-311.pyc +0 -0
  85. package/.agent/scripts/__pycache__/case_law_manager.cpython-311.pyc +0 -0
@@ -1,272 +1,272 @@
1
- #!/usr/bin/env node
2
- /**
3
- * dependency_analyzer.js — Dependency health checker for the Tribunal Agent Kit.
4
- *
5
- * Analyzes project dependencies for:
6
- * - Unused packages (in package.json but never imported)
7
- * - Phantom imports (imported but not in package.json)
8
- * - npm audit / pip-audit results
9
- * - Duplicate/overlapping packages
10
- *
11
- * Usage:
12
- * node .agent/scripts/dependency_analyzer.js .
13
- * node .agent/scripts/dependency_analyzer.js . --audit
14
- * node .agent/scripts/dependency_analyzer.js . --check-unused
15
- */
16
-
17
- 'use strict';
18
-
19
- const fs = require('fs');
20
- const path = require('path');
21
- const { spawnSync } = require('child_process');
22
-
23
- const { RED, GREEN, YELLOW, BLUE, BOLD, RESET } = require('./colors.js');
24
-
25
- const SOURCE_EXTENSIONS = new Set([".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs"]);
26
- const SKIP_DIRS = new Set(["node_modules", ".git", "dist", "build", ".next", ".agent", "__pycache__", "test", "tests", "__tests__"]);
27
-
28
- const NODE_BUILTINS = new Set([
29
- "fs", "path", "os", "crypto", "http", "https", "url", "util",
30
- "stream", "events", "child_process", "cluster", "net", "dns",
31
- "tls", "readline", "zlib", "buffer", "querystring", "string_decoder",
32
- "assert", "perf_hooks", "worker_threads", "timers", "v8",
33
- "node:fs", "node:path", "node:os", "node:crypto", "node:http",
34
- "node:https", "node:url", "node:util", "node:stream", "node:events",
35
- "node:child_process", "node:net", "node:dns", "node:tls",
36
- "node:readline", "node:zlib", "node:buffer", "node:assert",
37
- "node:perf_hooks", "node:worker_threads", "node:timers"
38
- ]);
39
-
40
- function header(title) {
41
- console.log(`\n${BOLD}${BLUE}━━━ ${title} ━━━${RESET}`);
42
- }
43
-
44
- function ok(msg) {
45
- console.log(` ${GREEN}✅ ${msg}${RESET}`);
46
- }
47
-
48
- function fail(msg) {
49
- console.log(` ${RED}❌ ${msg}${RESET}`);
50
- }
51
-
52
- function warn(msg) {
53
- console.log(` ${YELLOW}⚠️ ${msg}${RESET}`);
54
- }
55
-
56
- function skip(msg) {
57
- console.log(` ${YELLOW}⏭️ ${msg}${RESET}`);
58
- }
59
-
60
- function loadPackageJson(projectRoot) {
61
- const pkgPath = path.resolve(projectRoot, "package.json");
62
- if (!fs.existsSync(pkgPath)) return null;
63
- try {
64
- return JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
65
- } catch {
66
- return null;
67
- }
68
- }
69
-
70
- function extractImports(projectRoot) {
71
- const imports = new Set();
72
- const importPatterns = [
73
- /(?:import|export)\s+.*?\s+from\s+["']([^"'.][^"']*)["']/g,
74
- /require\s*\(\s*["']([^"'.][^"']*)["']/g,
75
- /import\s*\(\s*["']([^"'.][^"']*)["']/g
76
- ];
77
-
78
- function walk(dir) {
79
- let items;
80
- try {
81
- items = fs.readdirSync(dir, { withFileTypes: true });
82
- } catch {
83
- return;
84
- }
85
-
86
- for (const item of items) {
87
- if (item.isDirectory()) {
88
- if (!SKIP_DIRS.has(item.name)) walk(path.join(dir, item.name));
89
- } else {
90
- const ext = path.extname(item.name);
91
- if (SOURCE_EXTENSIONS.has(ext)) {
92
- try {
93
- const content = fs.readFileSync(path.join(dir, item.name), 'utf8');
94
- for (const pattern of importPatterns) {
95
- let match;
96
- while ((match = pattern.exec(content)) !== null) {
97
- let pkg = match[1];
98
- if (pkg.startsWith("@")) {
99
- const parts = pkg.split("/");
100
- pkg = parts.length >= 2 ? `${parts[0]}/${parts[1]}` : pkg;
101
- } else {
102
- pkg = pkg.split("/")[0];
103
- }
104
- imports.add(pkg);
105
- }
106
- }
107
- } catch {}
108
- }
109
- }
110
- }
111
- }
112
-
113
- walk(projectRoot);
114
- return imports;
115
- }
116
-
117
- function checkUnused(pkg, usedImports) {
118
- const allDeps = new Set([
119
- ...Object.keys(pkg.dependencies || {}),
120
- ...Object.keys(pkg.devDependencies || {})
121
- ]);
122
-
123
- const implicitPackages = new Set([
124
- "typescript", "eslint", "prettier", "vitest", "jest", "ts-node",
125
- "@types/node", "@types/react", "tailwindcss", "postcss", "autoprefixer",
126
- "nodemon", "tsx", "vite", "next", "webpack", "babel", "@babel/core"
127
- ]);
128
-
129
- const unused = [];
130
- for (const d of allDeps) {
131
- if (!implicitPackages.has(d) && !d.startsWith("@types/") && !usedImports.has(d)) {
132
- unused.push(d);
133
- }
134
- }
135
- return unused.sort();
136
- }
137
-
138
- function checkPhantom(pkg, usedImports) {
139
- const allDeps = new Set([
140
- ...Object.keys(pkg.dependencies || {}),
141
- ...Object.keys(pkg.devDependencies || {})
142
- ]);
143
-
144
- const phantom = [];
145
- for (const imp of usedImports) {
146
- if (!NODE_BUILTINS.has(imp) && !allDeps.has(imp)) {
147
- phantom.push(imp);
148
- }
149
- }
150
- return phantom.sort();
151
- }
152
-
153
- function runNpmAudit(projectRoot) {
154
- try {
155
- const executable = process.platform === 'win32' ? 'npm.cmd' : 'npm';
156
- const result = spawnSync(executable, ["audit", "--json"], {
157
- cwd: projectRoot,
158
- encoding: 'utf8',
159
- timeout: 60000,
160
- shell: process.platform === 'win32'
161
- });
162
-
163
- try {
164
- const auditData = JSON.parse(result.stdout);
165
- const vulns = (auditData.metadata && auditData.metadata.vulnerabilities) || {};
166
- const critical = vulns.critical || 0;
167
- const high = vulns.high || 0;
168
- const moderate = vulns.moderate || 0;
169
- const low = vulns.low || 0;
170
-
171
- if (critical + high > 0) {
172
- fail(`npm audit: ${critical} critical, ${high} high, ${moderate} moderate, ${low} low`);
173
- return false;
174
- } else if (moderate + low > 0) {
175
- warn(`npm audit: ${moderate} moderate, ${low} low vulnerabilities`);
176
- return true;
177
- } else {
178
- ok("npm audit — no known vulnerabilities");
179
- return true;
180
- }
181
- } catch {
182
- if (result.status === 0) {
183
- ok("npm audit — clean");
184
- return true;
185
- }
186
- fail("npm audit returned errors");
187
- return false;
188
- }
189
- } catch {
190
- skip("npm not installed — skipping audit");
191
- return true;
192
- }
193
- }
194
-
195
- function main() {
196
- const args = process.argv.slice(2);
197
- let targetPath = null;
198
- let auditFlag = false;
199
- let checkUnusedFlag = false;
200
-
201
- for (let i = 0; i < args.length; i++) {
202
- if (args[i] === '--audit') auditFlag = true;
203
- else if (args[i] === '--check-unused') checkUnusedFlag = true;
204
- else if (args[i] === '-h' || args[i] === '--help') {
205
- console.log("Usage: node dependency_analyzer.js <path> [--audit] [--check-unused]");
206
- process.exit(0);
207
- } else if (!args[i].startsWith('-') && !targetPath) {
208
- targetPath = args[i];
209
- }
210
- }
211
-
212
- if (!targetPath) {
213
- console.log("Usage: node dependency_analyzer.js <path> [--audit] [--check-unused]");
214
- process.exit(1);
215
- }
216
-
217
- const projectRoot = path.resolve(targetPath);
218
- if (!fs.existsSync(projectRoot) || !fs.statSync(projectRoot).isDirectory()) {
219
- fail(`Directory not found: ${projectRoot}`);
220
- process.exit(1);
221
- }
222
-
223
- console.log(`${BOLD}Tribunal — dependency_analyzer.js${RESET}`);
224
- console.log(`Project: ${projectRoot}`);
225
-
226
- const pkg = loadPackageJson(projectRoot);
227
- if (!pkg) {
228
- skip("No package.json found — dependency analysis requires a Node.js project");
229
- process.exit(0);
230
- }
231
-
232
- let issues = 0;
233
- const usedImports = extractImports(projectRoot);
234
- console.log(`\n Found ${usedImports.size} unique external imports in source code`);
235
-
236
- if (!checkUnusedFlag) {
237
- header("Phantom Imports (not in package.json)");
238
- const phantom = checkPhantom(pkg, usedImports);
239
- if (phantom.length > 0) {
240
- for (const p of phantom) fail(`'${p}' is imported but not in package.json — possible hallucination`);
241
- issues += phantom.length;
242
- } else {
243
- ok("All imports found in package.json");
244
- }
245
- }
246
-
247
- header("Unused Dependencies");
248
- const unused = checkUnused(pkg, usedImports);
249
- if (unused.length > 0) {
250
- for (const u of unused) warn(`'${u}' is in package.json but never imported — may be unused`);
251
- } else {
252
- ok("No obviously unused dependencies found");
253
- }
254
-
255
- if (auditFlag) {
256
- header("Vulnerability Audit");
257
- if (!runNpmAudit(projectRoot)) issues += 1;
258
- }
259
-
260
- console.log(`\n${BOLD}━━━ Dependency Analysis Summary ━━━${RESET}`);
261
- if (issues === 0) {
262
- ok("All dependency checks passed");
263
- } else {
264
- fail(`${issues} issue(s) found — review above`);
265
- }
266
-
267
- process.exit(issues > 0 ? 1 : 0);
268
- }
269
-
270
- if (require.main === module) {
271
- main();
272
- }
1
+ #!/usr/bin/env node
2
+ /**
3
+ * dependency_analyzer.js — Dependency health checker for the Tribunal Agent Kit.
4
+ *
5
+ * Analyzes project dependencies for:
6
+ * - Unused packages (in package.json but never imported)
7
+ * - Phantom imports (imported but not in package.json)
8
+ * - npm audit / pip-audit results
9
+ * - Duplicate/overlapping packages
10
+ *
11
+ * Usage:
12
+ * node .agent/scripts/dependency_analyzer.js .
13
+ * node .agent/scripts/dependency_analyzer.js . --audit
14
+ * node .agent/scripts/dependency_analyzer.js . --check-unused
15
+ */
16
+
17
+ 'use strict';
18
+
19
+ const fs = require('fs');
20
+ const path = require('path');
21
+ const { spawnSync } = require('child_process');
22
+
23
+ const { RED, GREEN, YELLOW, BLUE, BOLD, RESET } = require('./colors.js');
24
+
25
+ const SOURCE_EXTENSIONS = new Set([".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs"]);
26
+ const SKIP_DIRS = new Set(["node_modules", ".git", "dist", "build", ".next", ".agent", "__pycache__", "test", "tests", "__tests__"]);
27
+
28
+ const NODE_BUILTINS = new Set([
29
+ "fs", "path", "os", "crypto", "http", "https", "url", "util",
30
+ "stream", "events", "child_process", "cluster", "net", "dns",
31
+ "tls", "readline", "zlib", "buffer", "querystring", "string_decoder",
32
+ "assert", "perf_hooks", "worker_threads", "timers", "v8",
33
+ "node:fs", "node:path", "node:os", "node:crypto", "node:http",
34
+ "node:https", "node:url", "node:util", "node:stream", "node:events",
35
+ "node:child_process", "node:net", "node:dns", "node:tls",
36
+ "node:readline", "node:zlib", "node:buffer", "node:assert",
37
+ "node:perf_hooks", "node:worker_threads", "node:timers"
38
+ ]);
39
+
40
+ function header(title) {
41
+ console.log(`\n${BOLD}${BLUE}━━━ ${title} ━━━${RESET}`);
42
+ }
43
+
44
+ function ok(msg) {
45
+ console.log(` ${GREEN}✅ ${msg}${RESET}`);
46
+ }
47
+
48
+ function fail(msg) {
49
+ console.log(` ${RED}❌ ${msg}${RESET}`);
50
+ }
51
+
52
+ function warn(msg) {
53
+ console.log(` ${YELLOW}⚠️ ${msg}${RESET}`);
54
+ }
55
+
56
+ function skip(msg) {
57
+ console.log(` ${YELLOW}⏭️ ${msg}${RESET}`);
58
+ }
59
+
60
+ function loadPackageJson(projectRoot) {
61
+ const pkgPath = path.resolve(projectRoot, "package.json");
62
+ if (!fs.existsSync(pkgPath)) return null;
63
+ try {
64
+ return JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
65
+ } catch {
66
+ return null;
67
+ }
68
+ }
69
+
70
+ function extractImports(projectRoot) {
71
+ const imports = new Set();
72
+ const importPatterns = [
73
+ /(?:import|export)\s+.*?\s+from\s+["']([^"'.][^"']*)["']/g,
74
+ /require\s*\(\s*["']([^"'.][^"']*)["']/g,
75
+ /import\s*\(\s*["']([^"'.][^"']*)["']/g
76
+ ];
77
+
78
+ function walk(dir) {
79
+ let items;
80
+ try {
81
+ items = fs.readdirSync(dir, { withFileTypes: true });
82
+ } catch {
83
+ return;
84
+ }
85
+
86
+ for (const item of items) {
87
+ if (item.isDirectory()) {
88
+ if (!SKIP_DIRS.has(item.name)) walk(path.join(dir, item.name));
89
+ } else {
90
+ const ext = path.extname(item.name);
91
+ if (SOURCE_EXTENSIONS.has(ext)) {
92
+ try {
93
+ const content = fs.readFileSync(path.join(dir, item.name), 'utf8');
94
+ for (const pattern of importPatterns) {
95
+ let match;
96
+ while ((match = pattern.exec(content)) !== null) {
97
+ let pkg = match[1];
98
+ if (pkg.startsWith("@")) {
99
+ const parts = pkg.split("/");
100
+ pkg = parts.length >= 2 ? `${parts[0]}/${parts[1]}` : pkg;
101
+ } else {
102
+ pkg = pkg.split("/")[0];
103
+ }
104
+ imports.add(pkg);
105
+ }
106
+ }
107
+ } catch {}
108
+ }
109
+ }
110
+ }
111
+ }
112
+
113
+ walk(projectRoot);
114
+ return imports;
115
+ }
116
+
117
+ function checkUnused(pkg, usedImports) {
118
+ const allDeps = new Set([
119
+ ...Object.keys(pkg.dependencies || {}),
120
+ ...Object.keys(pkg.devDependencies || {})
121
+ ]);
122
+
123
+ const implicitPackages = new Set([
124
+ "typescript", "eslint", "prettier", "vitest", "jest", "ts-node",
125
+ "@types/node", "@types/react", "tailwindcss", "postcss", "autoprefixer",
126
+ "nodemon", "tsx", "vite", "next", "webpack", "babel", "@babel/core"
127
+ ]);
128
+
129
+ const unused = [];
130
+ for (const d of allDeps) {
131
+ if (!implicitPackages.has(d) && !d.startsWith("@types/") && !usedImports.has(d)) {
132
+ unused.push(d);
133
+ }
134
+ }
135
+ return unused.sort();
136
+ }
137
+
138
+ function checkPhantom(pkg, usedImports) {
139
+ const allDeps = new Set([
140
+ ...Object.keys(pkg.dependencies || {}),
141
+ ...Object.keys(pkg.devDependencies || {})
142
+ ]);
143
+
144
+ const phantom = [];
145
+ for (const imp of usedImports) {
146
+ if (!NODE_BUILTINS.has(imp) && !allDeps.has(imp)) {
147
+ phantom.push(imp);
148
+ }
149
+ }
150
+ return phantom.sort();
151
+ }
152
+
153
+ function runNpmAudit(projectRoot) {
154
+ try {
155
+ const executable = process.platform === 'win32' ? 'npm.cmd' : 'npm';
156
+ const result = spawnSync(executable, ["audit", "--json"], {
157
+ cwd: projectRoot,
158
+ encoding: 'utf8',
159
+ timeout: 60000,
160
+ shell: process.platform === 'win32'
161
+ });
162
+
163
+ try {
164
+ const auditData = JSON.parse(result.stdout);
165
+ const vulns = (auditData.metadata && auditData.metadata.vulnerabilities) || {};
166
+ const critical = vulns.critical || 0;
167
+ const high = vulns.high || 0;
168
+ const moderate = vulns.moderate || 0;
169
+ const low = vulns.low || 0;
170
+
171
+ if (critical + high > 0) {
172
+ fail(`npm audit: ${critical} critical, ${high} high, ${moderate} moderate, ${low} low`);
173
+ return false;
174
+ } else if (moderate + low > 0) {
175
+ warn(`npm audit: ${moderate} moderate, ${low} low vulnerabilities`);
176
+ return true;
177
+ } else {
178
+ ok("npm audit — no known vulnerabilities");
179
+ return true;
180
+ }
181
+ } catch {
182
+ if (result.status === 0) {
183
+ ok("npm audit — clean");
184
+ return true;
185
+ }
186
+ fail("npm audit returned errors");
187
+ return false;
188
+ }
189
+ } catch {
190
+ skip("npm not installed — skipping audit");
191
+ return true;
192
+ }
193
+ }
194
+
195
+ function main() {
196
+ const args = process.argv.slice(2);
197
+ let targetPath = null;
198
+ let auditFlag = false;
199
+ let checkUnusedFlag = false;
200
+
201
+ for (let i = 0; i < args.length; i++) {
202
+ if (args[i] === '--audit') auditFlag = true;
203
+ else if (args[i] === '--check-unused') checkUnusedFlag = true;
204
+ else if (args[i] === '-h' || args[i] === '--help') {
205
+ console.log("Usage: node dependency_analyzer.js <path> [--audit] [--check-unused]");
206
+ process.exit(0);
207
+ } else if (!args[i].startsWith('-') && !targetPath) {
208
+ targetPath = args[i];
209
+ }
210
+ }
211
+
212
+ if (!targetPath) {
213
+ console.log("Usage: node dependency_analyzer.js <path> [--audit] [--check-unused]");
214
+ process.exit(1);
215
+ }
216
+
217
+ const projectRoot = path.resolve(targetPath);
218
+ if (!fs.existsSync(projectRoot) || !fs.statSync(projectRoot).isDirectory()) {
219
+ fail(`Directory not found: ${projectRoot}`);
220
+ process.exit(1);
221
+ }
222
+
223
+ console.log(`${BOLD}Tribunal — dependency_analyzer.js${RESET}`);
224
+ console.log(`Project: ${projectRoot}`);
225
+
226
+ const pkg = loadPackageJson(projectRoot);
227
+ if (!pkg) {
228
+ skip("No package.json found — dependency analysis requires a Node.js project");
229
+ process.exit(0);
230
+ }
231
+
232
+ let issues = 0;
233
+ const usedImports = extractImports(projectRoot);
234
+ console.log(`\n Found ${usedImports.size} unique external imports in source code`);
235
+
236
+ if (!checkUnusedFlag) {
237
+ header("Phantom Imports (not in package.json)");
238
+ const phantom = checkPhantom(pkg, usedImports);
239
+ if (phantom.length > 0) {
240
+ for (const p of phantom) fail(`'${p}' is imported but not in package.json — possible hallucination`);
241
+ issues += phantom.length;
242
+ } else {
243
+ ok("All imports found in package.json");
244
+ }
245
+ }
246
+
247
+ header("Unused Dependencies");
248
+ const unused = checkUnused(pkg, usedImports);
249
+ if (unused.length > 0) {
250
+ for (const u of unused) warn(`'${u}' is in package.json but never imported — may be unused`);
251
+ } else {
252
+ ok("No obviously unused dependencies found");
253
+ }
254
+
255
+ if (auditFlag) {
256
+ header("Vulnerability Audit");
257
+ if (!runNpmAudit(projectRoot)) issues += 1;
258
+ }
259
+
260
+ console.log(`\n${BOLD}━━━ Dependency Analysis Summary ━━━${RESET}`);
261
+ if (issues === 0) {
262
+ ok("All dependency checks passed");
263
+ } else {
264
+ fail(`${issues} issue(s) found — review above`);
265
+ }
266
+
267
+ process.exit(issues > 0 ? 1 : 0);
268
+ }
269
+
270
+ if (require.main === module) {
271
+ main();
272
+ }