tribunal-kit 4.2.0 → 4.3.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.
- package/.agent/ARCHITECTURE.md +21 -14
- package/.agent/agents/swarm-worker-contracts.md +5 -5
- package/.agent/agents/ui-ux-auditor.md +292 -0
- package/.agent/rules/GEMINI.md +8 -8
- package/.agent/scripts/__pycache__/_colors.cpython-311.pyc +0 -0
- package/.agent/scripts/__pycache__/_utils.cpython-311.pyc +0 -0
- package/.agent/scripts/__pycache__/case_law_manager.cpython-311.pyc +0 -0
- package/.agent/scripts/_colors.js +18 -0
- package/.agent/scripts/_utils.js +42 -0
- package/.agent/scripts/auto_preview.js +197 -0
- package/.agent/scripts/bundle_analyzer.js +290 -0
- package/.agent/scripts/case_law_manager.js +684 -0
- package/.agent/scripts/checklist.js +266 -0
- package/.agent/scripts/colors.js +17 -0
- package/.agent/scripts/compress_skills.js +141 -0
- package/.agent/scripts/consolidate_skills.js +149 -0
- package/.agent/scripts/context_broker.js +609 -0
- package/.agent/scripts/deep_compress.js +150 -0
- package/.agent/scripts/dependency_analyzer.js +272 -0
- package/.agent/scripts/inner_loop_validator.js +465 -0
- package/.agent/scripts/lint_runner.js +187 -0
- package/.agent/scripts/minify_context.js +100 -0
- package/.agent/scripts/patch_skills_meta.js +156 -0
- package/.agent/scripts/patch_skills_output.js +244 -0
- package/.agent/scripts/schema_validator.js +297 -0
- package/.agent/scripts/security_scan.js +303 -0
- package/.agent/scripts/session_manager.js +276 -0
- package/.agent/scripts/skill_evolution.js +644 -0
- package/.agent/scripts/skill_integrator.js +313 -0
- package/.agent/scripts/strengthen_skills.js +193 -0
- package/.agent/scripts/strip_tribunal.js +47 -0
- package/.agent/scripts/swarm_dispatcher.js +360 -0
- package/.agent/scripts/test_runner.js +193 -0
- package/.agent/scripts/utils.js +32 -0
- package/.agent/scripts/verify_all.js +256 -0
- package/.agent/skills/agent-organizer/SKILL.md +3 -3
- package/.agent/skills/agentic-patterns/SKILL.md +3 -3
- package/.agent/skills/ai-prompt-injection-defense/SKILL.md +3 -3
- package/.agent/skills/api-patterns/SKILL.md +3 -3
- package/.agent/skills/api-security-auditor/SKILL.md +3 -3
- package/.agent/skills/app-builder/SKILL.md +3 -3
- package/.agent/skills/app-builder/templates/SKILL.md +1 -1
- package/.agent/skills/app-builder/templates/astro-static/TEMPLATE.md +1 -1
- package/.agent/skills/app-builder/templates/chrome-extension/TEMPLATE.md +1 -1
- package/.agent/skills/app-builder/templates/cli-tool/TEMPLATE.md +1 -1
- package/.agent/skills/app-builder/templates/electron-desktop/TEMPLATE.md +1 -1
- package/.agent/skills/app-builder/templates/express-api/TEMPLATE.md +1 -1
- package/.agent/skills/app-builder/templates/flutter-app/TEMPLATE.md +1 -1
- package/.agent/skills/app-builder/templates/monorepo-turborepo/TEMPLATE.md +1 -1
- package/.agent/skills/app-builder/templates/nextjs-fullstack/TEMPLATE.md +1 -1
- package/.agent/skills/app-builder/templates/nextjs-saas/TEMPLATE.md +1 -1
- package/.agent/skills/app-builder/templates/nextjs-static/TEMPLATE.md +1 -1
- package/.agent/skills/app-builder/templates/nuxt-app/TEMPLATE.md +1 -1
- package/.agent/skills/app-builder/templates/python-fastapi/TEMPLATE.md +1 -1
- package/.agent/skills/app-builder/templates/react-native-app/TEMPLATE.md +1 -1
- package/.agent/skills/appflow-wireframe/SKILL.md +3 -3
- package/.agent/skills/architecture/SKILL.md +3 -3
- package/.agent/skills/authentication-best-practices/SKILL.md +3 -3
- package/.agent/skills/bash-linux/SKILL.md +3 -3
- package/.agent/skills/behavioral-modes/SKILL.md +3 -3
- package/.agent/skills/brainstorming/SKILL.md +3 -3
- package/.agent/skills/building-native-ui/SKILL.md +3 -3
- package/.agent/skills/clean-code/SKILL.md +3 -3
- package/.agent/skills/code-review-checklist/SKILL.md +3 -3
- package/.agent/skills/config-validator/SKILL.md +3 -3
- package/.agent/skills/csharp-developer/SKILL.md +3 -3
- package/.agent/skills/data-validation-schemas/SKILL.md +3 -3
- package/.agent/skills/database-design/SKILL.md +3 -3
- package/.agent/skills/deployment-procedures/SKILL.md +3 -3
- package/.agent/skills/devops-engineer/SKILL.md +3 -3
- package/.agent/skills/devops-incident-responder/SKILL.md +3 -3
- package/.agent/skills/doc.md +1 -1
- package/.agent/skills/documentation-templates/SKILL.md +3 -3
- package/.agent/skills/edge-computing/SKILL.md +3 -3
- package/.agent/skills/error-resilience/SKILL.md +3 -3
- package/.agent/skills/extract-design-system/SKILL.md +3 -3
- package/.agent/skills/framer-motion-expert/SKILL.md +3 -4
- package/.agent/skills/frontend-design/SKILL.md +3 -3
- package/.agent/skills/game-design-expert/SKILL.md +3 -3
- package/.agent/skills/game-engineering-expert/SKILL.md +3 -3
- package/.agent/skills/geo-fundamentals/SKILL.md +3 -3
- package/.agent/skills/github-operations/SKILL.md +3 -3
- package/.agent/skills/gsap-core/SKILL.md +0 -2
- package/.agent/skills/gsap-frameworks/SKILL.md +0 -2
- package/.agent/skills/gsap-performance/SKILL.md +0 -2
- package/.agent/skills/gsap-plugins/SKILL.md +0 -2
- package/.agent/skills/gsap-react/SKILL.md +0 -2
- package/.agent/skills/gsap-scrolltrigger/SKILL.md +0 -2
- package/.agent/skills/gsap-timeline/SKILL.md +0 -2
- package/.agent/skills/gsap-utils/SKILL.md +0 -2
- package/.agent/skills/i18n-localization/SKILL.md +3 -3
- package/.agent/skills/intelligent-routing/SKILL.md +3 -3
- package/.agent/skills/lint-and-validate/SKILL.md +3 -3
- package/.agent/skills/llm-engineering/SKILL.md +3 -3
- package/.agent/skills/local-first/SKILL.md +3 -3
- package/.agent/skills/mcp-builder/SKILL.md +3 -3
- package/.agent/skills/mobile-design/SKILL.md +3 -3
- package/.agent/skills/monorepo-management/SKILL.md +3 -3
- package/.agent/skills/motion-engineering/SKILL.md +4 -4
- package/.agent/skills/nextjs-react-expert/SKILL.md +3 -3
- package/.agent/skills/nodejs-best-practices/SKILL.md +3 -3
- package/.agent/skills/observability/SKILL.md +3 -3
- package/.agent/skills/parallel-agents/SKILL.md +3 -3
- package/.agent/skills/performance-profiling/SKILL.md +3 -3
- package/.agent/skills/plan-writing/SKILL.md +3 -3
- package/.agent/skills/platform-engineer/SKILL.md +3 -3
- package/.agent/skills/playwright-best-practices/SKILL.md +3 -3
- package/.agent/skills/powershell-windows/SKILL.md +3 -3
- package/.agent/skills/project-idioms/SKILL.md +3 -3
- package/.agent/skills/python-patterns/SKILL.md +3 -3
- package/.agent/skills/python-pro/SKILL.md +3 -3
- package/.agent/skills/react-specialist/SKILL.md +3 -3
- package/.agent/skills/readme-builder/SKILL.md +3 -3
- package/.agent/skills/realtime-patterns/SKILL.md +3 -3
- package/.agent/skills/red-team-tactics/SKILL.md +3 -3
- package/.agent/skills/rust-pro/SKILL.md +3 -3
- package/.agent/skills/seo-fundamentals/SKILL.md +3 -3
- package/.agent/skills/server-management/SKILL.md +3 -3
- package/.agent/skills/shadcn-ui-expert/SKILL.md +3 -3
- package/.agent/skills/skill-creator/SKILL.md +3 -3
- package/.agent/skills/sql-pro/SKILL.md +3 -3
- package/.agent/skills/supabase-postgres-best-practices/SKILL.md +3 -3
- package/.agent/skills/swiftui-expert/SKILL.md +3 -3
- package/.agent/skills/systematic-debugging/SKILL.md +3 -3
- package/.agent/skills/tailwind-patterns/SKILL.md +3 -3
- package/.agent/skills/tdd-workflow/SKILL.md +3 -3
- package/.agent/skills/test-result-analyzer/SKILL.md +3 -3
- package/.agent/skills/testing-patterns/SKILL.md +3 -3
- package/.agent/skills/trend-researcher/SKILL.md +3 -3
- package/.agent/skills/typescript-advanced/SKILL.md +3 -3
- package/.agent/skills/ui-ux-pro-max/SKILL.md +3 -3
- package/.agent/skills/ui-ux-researcher/SKILL.md +3 -3
- package/.agent/skills/vue-expert/SKILL.md +3 -3
- package/.agent/skills/vulnerability-scanner/SKILL.md +3 -3
- package/.agent/skills/web-accessibility-auditor/SKILL.md +3 -3
- package/.agent/skills/web-design-guidelines/SKILL.md +3 -3
- package/.agent/skills/webapp-testing/SKILL.md +3 -3
- package/.agent/skills/whimsy-injector/SKILL.md +3 -3
- package/.agent/skills/workflow-optimizer/SKILL.md +3 -3
- package/.agent/workflows/audit.md +6 -6
- package/.agent/workflows/deploy.md +1 -1
- package/.agent/workflows/generate.md +23 -6
- package/.agent/workflows/session.md +5 -5
- package/.agent/workflows/swarm.md +2 -2
- package/README.md +64 -8
- package/bin/tribunal-kit.js +277 -45
- package/package.json +9 -6
- package/scripts/changelog.js +167 -0
- package/scripts/sync-version.js +81 -0
- package/.agent/scripts/__pycache__/auto_preview.cpython-311.pyc +0 -0
- package/.agent/scripts/__pycache__/bundle_analyzer.cpython-311.pyc +0 -0
- package/.agent/scripts/__pycache__/checklist.cpython-311.pyc +0 -0
- package/.agent/scripts/__pycache__/dependency_analyzer.cpython-311.pyc +0 -0
- package/.agent/scripts/__pycache__/security_scan.cpython-311.pyc +0 -0
- package/.agent/scripts/__pycache__/session_manager.cpython-311.pyc +0 -0
- package/.agent/scripts/__pycache__/skill_integrator.cpython-311.pyc +0 -0
- package/.agent/scripts/__pycache__/swarm_dispatcher.cpython-311.pyc +0 -0
- package/.agent/scripts/__pycache__/test_runner.cpython-311.pyc +0 -0
- package/.agent/scripts/__pycache__/verify_all.cpython-311.pyc +0 -0
- package/.agent/scripts/auto_preview.py +0 -180
- package/.agent/scripts/bundle_analyzer.py +0 -259
- package/.agent/scripts/case_law_manager.py +0 -755
- package/.agent/scripts/checklist.py +0 -209
- package/.agent/scripts/compress_skills.py +0 -167
- package/.agent/scripts/consolidate_skills.py +0 -173
- package/.agent/scripts/deep_compress.py +0 -202
- package/.agent/scripts/dependency_analyzer.py +0 -247
- package/.agent/scripts/lint_runner.py +0 -188
- package/.agent/scripts/minify_context.py +0 -80
- package/.agent/scripts/patch_skills_meta.py +0 -177
- package/.agent/scripts/patch_skills_output.py +0 -285
- package/.agent/scripts/schema_validator.py +0 -279
- package/.agent/scripts/security_scan.py +0 -224
- package/.agent/scripts/session_manager.py +0 -261
- package/.agent/scripts/skill_evolution.py +0 -563
- package/.agent/scripts/skill_integrator.py +0 -234
- package/.agent/scripts/strengthen_skills.py +0 -220
- package/.agent/scripts/strip_tribunal.py +0 -41
- package/.agent/scripts/swarm_dispatcher.py +0 -350
- package/.agent/scripts/test_runner.py +0 -192
- package/.agent/scripts/test_swarm_dispatcher.py +0 -163
- package/.agent/scripts/verify_all.py +0 -195
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* deep_compress.js - Deep surgical compression for .agent/ markdown files (skills, agents, workflows).
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
const path = require('path');
|
|
10
|
+
|
|
11
|
+
const BASE_DIRS = ['.agent/skills', '.agent/agents', '.agent/workflows'];
|
|
12
|
+
|
|
13
|
+
const REMOVE_SECTIONS = [
|
|
14
|
+
/^## 🏛️ Tribunal Integration[\s\S]*?(?=\n## |$)/gm,
|
|
15
|
+
/^## Tribunal Integration[\s\S]*?(?=\n## |$)/gm,
|
|
16
|
+
/^### ✅ Pre-Flight Self-Audit[\s\S]*?(?=\n### |\n## |$)/gm,
|
|
17
|
+
/^## Pre-Flight Self-Audit[\s\S]*?(?=\n## |$)/gm,
|
|
18
|
+
/^## Cross-Workflow Navigation[\s\S]*?(?=\n## |$)/gm,
|
|
19
|
+
/^## LLM Traps[\s\S]*?(?=\n## |$)/gm,
|
|
20
|
+
/^## VBC Protocol[\s\S]*?(?=\n## |$)/gm,
|
|
21
|
+
/^## Output Format\n```[\s\S]*?```\n/gm,
|
|
22
|
+
/^## 🤖 LLM-Specific Traps[\s\S]*?(?=\n## |$)/gm,
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
const VERBOSE_COMMENT_PATTERNS = [
|
|
26
|
+
/^(\s*)\/\/\s*(?:Any HTML or SVG element|motion\.div, motion\.span|The MAGIC of|This is the key performance|The pattern that|Compound components share|Note that children|The action receives|Children inherit the|Import first|Parent controls when|It's always motion)\b[^\n]*\n/gm,
|
|
27
|
+
/^(\s*)#\s*(?:TypedDict gives you|Usage:|Note:|Return user|Return None|Automatically)\b[^\n]*\n/gm,
|
|
28
|
+
/^\s*\/\/\s*Usage:\s*\n(?=\s*[<{])/gm,
|
|
29
|
+
/^\s*#\s*Usage:\s*\n(?=\s*[{])/gm,
|
|
30
|
+
/^\s*\/\/\s*When (?:server responds|a component|React can interrupt|the React Compiler)[^\n]*\n/gm,
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
function stripChattyOpeners(content) {
|
|
34
|
+
return content.replace(/(^# .+\n)\n.{60,}\n.{30,}\n(?:\n---)/gm, '$1\n---');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function compressLegacyModernBlocks(content) {
|
|
38
|
+
const pattern = /```(\w+)\n((?:.*\n)*?.*(?:\/\/|#) ❌ LEGACY[^\n]*\n(?:.*\n)*?)```\n\n```\w+\n((?:.*\n)*?.*(?:\/\/|#) ✅ MODERN[^\n]*\n(?:.*\n)*?)```/gm;
|
|
39
|
+
return content.replace(pattern, (match, lang, legacy, modern) => {
|
|
40
|
+
const totalLines = (legacy.match(/\n/g) || []).length + (modern.match(/\n/g) || []).length;
|
|
41
|
+
if (totalLines > 28) return match;
|
|
42
|
+
return `\`\`\`${lang}\n// ❌ LEGACY\n${legacy.trim()}\n\n// ✅ MODERN\n${modern.trim()}\n\`\`\``;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function stripEmptyComments(content) {
|
|
47
|
+
content = content.replace(/^\s*\/\/\s*$\n/gm, '');
|
|
48
|
+
content = content.replace(/^\s*#\s*$\n/gm, '');
|
|
49
|
+
return content;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function dedupBulletPoints(content) {
|
|
53
|
+
const lines = content.split('\n');
|
|
54
|
+
const seenBullets = {};
|
|
55
|
+
const output = [];
|
|
56
|
+
for (let i = 0; i < lines.length; i++) {
|
|
57
|
+
const line = lines[i];
|
|
58
|
+
const stripped = line.trim();
|
|
59
|
+
if (/^(✅|❌|- ✅|- ❌)/.test(stripped)) {
|
|
60
|
+
if (seenBullets[stripped] !== undefined && (i - seenBullets[stripped]) < 80) {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
seenBullets[stripped] = i;
|
|
64
|
+
}
|
|
65
|
+
output.push(line);
|
|
66
|
+
}
|
|
67
|
+
return output.join('\n');
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function collapseBlanks(content) {
|
|
71
|
+
return content.replace(/\n{3,}/g, '\n\n');
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function compressFile(filePath) {
|
|
75
|
+
const original = fs.readFileSync(filePath, 'utf8');
|
|
76
|
+
let content = original;
|
|
77
|
+
|
|
78
|
+
for (const pattern of REMOVE_SECTIONS) {
|
|
79
|
+
content = content.replace(pattern, '');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
content = stripChattyOpeners(content);
|
|
83
|
+
content = compressLegacyModernBlocks(content);
|
|
84
|
+
|
|
85
|
+
for (const pattern of VERBOSE_COMMENT_PATTERNS) {
|
|
86
|
+
content = content.replace(pattern, '');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
content = stripEmptyComments(content);
|
|
90
|
+
content = dedupBulletPoints(content);
|
|
91
|
+
content = collapseBlanks(content);
|
|
92
|
+
|
|
93
|
+
if (content.trim() !== original.trim()) {
|
|
94
|
+
fs.writeFileSync(filePath, content.trim() + '\n', 'utf8');
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return [Buffer.byteLength(original, 'utf8'), Buffer.byteLength(content, 'utf8')];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function main() {
|
|
101
|
+
let totalOrig = 0;
|
|
102
|
+
let totalNew = 0;
|
|
103
|
+
const fileResults = [];
|
|
104
|
+
|
|
105
|
+
function walkDir(dir) {
|
|
106
|
+
let items;
|
|
107
|
+
try { items = fs.readdirSync(dir, { withFileTypes: true }); } catch { return; }
|
|
108
|
+
for (const item of items) {
|
|
109
|
+
const fpath = path.join(dir, item.name);
|
|
110
|
+
if (item.isDirectory()) walkDir(fpath);
|
|
111
|
+
else if (item.name.endsWith('.md')) {
|
|
112
|
+
const [orig, newL] = compressFile(fpath);
|
|
113
|
+
totalOrig += orig;
|
|
114
|
+
totalNew += newL;
|
|
115
|
+
const saved = orig - newL;
|
|
116
|
+
if (saved > 200) {
|
|
117
|
+
fileResults.push([saved, fpath]);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
for (const base of BASE_DIRS) {
|
|
124
|
+
if (fs.existsSync(base)) walkDir(base);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
fileResults.sort((a, b) => b[0] - a[0]);
|
|
128
|
+
|
|
129
|
+
const savedTotal = totalOrig - totalNew;
|
|
130
|
+
const pct = totalOrig ? (savedTotal / totalOrig * 100) : 0;
|
|
131
|
+
|
|
132
|
+
console.log(`\n${'='.repeat(58)}`);
|
|
133
|
+
console.log(` Deep Compression Complete`);
|
|
134
|
+
console.log(`${'='.repeat(58)}`);
|
|
135
|
+
console.log(` Original : ${totalOrig} bytes (${Math.floor(totalOrig / 1024)}KB)`);
|
|
136
|
+
console.log(` After : ${totalNew} bytes (${Math.floor(totalNew / 1024)}KB)`);
|
|
137
|
+
console.log(` Saved : ${savedTotal} bytes (${Math.floor(savedTotal / 1024)}KB) — ${pct.toFixed(1)}%`);
|
|
138
|
+
console.log(`\n Top savings:`);
|
|
139
|
+
|
|
140
|
+
for (const [saved, filePath] of fileResults.slice(0, 20)) {
|
|
141
|
+
const parts = filePath.split(path.sep);
|
|
142
|
+
const skill = parts.length >= 2 ? `${parts[parts.length - 2]}/${parts[parts.length - 1]}` : filePath;
|
|
143
|
+
console.log(` -${Math.floor(saved / 1024).toString().padStart(2, ' ')}KB ${skill}`);
|
|
144
|
+
}
|
|
145
|
+
console.log();
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (require.main === module) {
|
|
149
|
+
main();
|
|
150
|
+
}
|
|
@@ -0,0 +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__"]);
|
|
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
|
+
}
|