tribunal-kit 4.2.0 → 4.3.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.
- 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/graph_builder.js +199 -0
- package/.agent/scripts/graph_zoom.js +154 -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 +12 -4
- package/.agent/skills/agentic-patterns/SKILL.md +12 -4
- package/.agent/skills/ai-prompt-injection-defense/SKILL.md +12 -4
- package/.agent/skills/api-patterns/SKILL.md +209 -201
- package/.agent/skills/api-security-auditor/SKILL.md +12 -4
- package/.agent/skills/app-builder/SKILL.md +12 -4
- package/.agent/skills/app-builder/templates/SKILL.md +76 -68
- 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 +12 -4
- package/.agent/skills/architecture/SKILL.md +12 -4
- package/.agent/skills/authentication-best-practices/SKILL.md +12 -4
- package/.agent/skills/bash-linux/SKILL.md +12 -4
- package/.agent/skills/behavioral-modes/SKILL.md +12 -4
- package/.agent/skills/brainstorming/SKILL.md +12 -4
- package/.agent/skills/building-native-ui/SKILL.md +12 -4
- package/.agent/skills/clean-code/SKILL.md +12 -4
- package/.agent/skills/code-review-checklist/SKILL.md +12 -4
- package/.agent/skills/config-validator/SKILL.md +12 -4
- package/.agent/skills/csharp-developer/SKILL.md +12 -4
- package/.agent/skills/data-validation-schemas/SKILL.md +290 -282
- package/.agent/skills/database-design/SKILL.md +202 -194
- package/.agent/skills/deployment-procedures/SKILL.md +12 -4
- package/.agent/skills/devops-engineer/SKILL.md +12 -4
- package/.agent/skills/devops-incident-responder/SKILL.md +12 -4
- package/.agent/skills/doc.md +1 -1
- package/.agent/skills/documentation-templates/SKILL.md +12 -4
- package/.agent/skills/edge-computing/SKILL.md +12 -4
- package/.agent/skills/error-resilience/SKILL.md +390 -382
- package/.agent/skills/extract-design-system/SKILL.md +12 -4
- package/.agent/skills/framer-motion-expert/SKILL.md +206 -199
- package/.agent/skills/frontend-design/SKILL.md +163 -155
- package/.agent/skills/game-design-expert/SKILL.md +12 -4
- package/.agent/skills/game-engineering-expert/SKILL.md +12 -4
- package/.agent/skills/geo-fundamentals/SKILL.md +12 -4
- package/.agent/skills/github-operations/SKILL.md +12 -4
- package/.agent/skills/gsap-core/SKILL.md +54 -48
- package/.agent/skills/gsap-frameworks/SKILL.md +54 -48
- package/.agent/skills/gsap-performance/SKILL.md +54 -48
- package/.agent/skills/gsap-plugins/SKILL.md +54 -48
- package/.agent/skills/gsap-react/SKILL.md +54 -48
- package/.agent/skills/gsap-scrolltrigger/SKILL.md +54 -48
- package/.agent/skills/gsap-timeline/SKILL.md +54 -48
- package/.agent/skills/gsap-utils/SKILL.md +54 -48
- package/.agent/skills/i18n-localization/SKILL.md +12 -4
- package/.agent/skills/intelligent-routing/SKILL.md +41 -33
- package/.agent/skills/knowledge-graph/SKILL.md +36 -0
- package/.agent/skills/lint-and-validate/SKILL.md +12 -4
- package/.agent/skills/llm-engineering/SKILL.md +12 -4
- package/.agent/skills/local-first/SKILL.md +12 -4
- package/.agent/skills/mcp-builder/SKILL.md +12 -4
- package/.agent/skills/mobile-design/SKILL.md +225 -217
- package/.agent/skills/monorepo-management/SKILL.md +296 -288
- package/.agent/skills/motion-engineering/SKILL.md +195 -187
- package/.agent/skills/nextjs-react-expert/SKILL.md +196 -188
- package/.agent/skills/nodejs-best-practices/SKILL.md +12 -4
- package/.agent/skills/observability/SKILL.md +12 -4
- package/.agent/skills/parallel-agents/SKILL.md +12 -4
- package/.agent/skills/performance-profiling/SKILL.md +12 -4
- package/.agent/skills/plan-writing/SKILL.md +12 -4
- package/.agent/skills/platform-engineer/SKILL.md +12 -4
- package/.agent/skills/playwright-best-practices/SKILL.md +12 -4
- package/.agent/skills/powershell-windows/SKILL.md +12 -4
- package/.agent/skills/project-idioms/SKILL.md +12 -4
- package/.agent/skills/python-patterns/SKILL.md +12 -4
- package/.agent/skills/python-pro/SKILL.md +285 -277
- package/.agent/skills/react-specialist/SKILL.md +239 -231
- package/.agent/skills/readme-builder/SKILL.md +12 -4
- package/.agent/skills/realtime-patterns/SKILL.md +12 -4
- package/.agent/skills/red-team-tactics/SKILL.md +12 -4
- package/.agent/skills/rust-pro/SKILL.md +12 -4
- package/.agent/skills/seo-fundamentals/SKILL.md +12 -4
- package/.agent/skills/server-management/SKILL.md +12 -4
- package/.agent/skills/shadcn-ui-expert/SKILL.md +12 -4
- package/.agent/skills/skill-creator/SKILL.md +12 -4
- package/.agent/skills/sql-pro/SKILL.md +12 -4
- package/.agent/skills/supabase-postgres-best-practices/SKILL.md +12 -4
- package/.agent/skills/swiftui-expert/SKILL.md +12 -4
- package/.agent/skills/systematic-debugging/SKILL.md +12 -4
- package/.agent/skills/tailwind-patterns/SKILL.md +12 -4
- package/.agent/skills/tdd-workflow/SKILL.md +12 -4
- package/.agent/skills/test-result-analyzer/SKILL.md +12 -4
- package/.agent/skills/testing-patterns/SKILL.md +12 -4
- package/.agent/skills/trend-researcher/SKILL.md +12 -4
- package/.agent/skills/typescript-advanced/SKILL.md +297 -289
- package/.agent/skills/ui-ux-pro-max/SKILL.md +12 -4
- package/.agent/skills/ui-ux-researcher/SKILL.md +12 -4
- package/.agent/skills/vue-expert/SKILL.md +237 -229
- package/.agent/skills/vulnerability-scanner/SKILL.md +12 -4
- package/.agent/skills/web-accessibility-auditor/SKILL.md +12 -4
- package/.agent/skills/web-design-guidelines/SKILL.md +12 -4
- package/.agent/skills/webapp-testing/SKILL.md +12 -4
- package/.agent/skills/whimsy-injector/SKILL.md +12 -4
- package/.agent/skills/workflow-optimizer/SKILL.md +12 -4
- 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 +242 -186
- package/bin/tribunal-kit.js +297 -57
- package/package.json +81 -77
- package/scripts/changelog.js +167 -0
- package/scripts/sync-version.js +81 -0
- package/scripts/validate-payload.js +73 -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
|
+
}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* graph_builder.js — Tribunal Kit Macro Graph Mapper
|
|
4
|
+
* Parses project structure for imports, exports, and dependencies
|
|
5
|
+
* using incremental caching and zero external dependencies.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
const fs = require('fs');
|
|
11
|
+
const path = require('path');
|
|
12
|
+
|
|
13
|
+
const AGENT_DIR = path.join(process.cwd(), '.agent');
|
|
14
|
+
const HISTORY_DIR = path.join(AGENT_DIR, 'history');
|
|
15
|
+
const CACHE_FILE = path.join(HISTORY_DIR, 'graph-cache.json');
|
|
16
|
+
const GRAPH_FILE = path.join(HISTORY_DIR, 'architecture-graph.yaml');
|
|
17
|
+
|
|
18
|
+
// ── Exclusions & Safety ───────────────────────────────────────────────────────
|
|
19
|
+
const DEFAULT_EXCLUSIONS = new Set([
|
|
20
|
+
'node_modules', '.git', '.next', 'dist', 'build', 'coverage', '.agent', 'artifacts'
|
|
21
|
+
]);
|
|
22
|
+
|
|
23
|
+
function loadGitIgnore() {
|
|
24
|
+
const gitignorePath = path.join(process.cwd(), '.gitignore');
|
|
25
|
+
if (!fs.existsSync(gitignorePath)) return [];
|
|
26
|
+
|
|
27
|
+
return fs.readFileSync(gitignorePath, 'utf8')
|
|
28
|
+
.split('\n')
|
|
29
|
+
.map(line => line.trim())
|
|
30
|
+
.filter(line => line && !line.startsWith('#'))
|
|
31
|
+
// simplistic conversion from gitignore line to path check
|
|
32
|
+
.map(line => line.replace(/\/$/, '').replace(/^\//, ''));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const customExclusions = loadGitIgnore();
|
|
36
|
+
|
|
37
|
+
function isExcluded(filePath) {
|
|
38
|
+
const parts = filePath.split(path.sep);
|
|
39
|
+
|
|
40
|
+
// 1. Check against critical defaults (OOM prevention)
|
|
41
|
+
if (parts.some(p => DEFAULT_EXCLUSIONS.has(p))) return true;
|
|
42
|
+
|
|
43
|
+
// 2. Check against .gitignore rules
|
|
44
|
+
const relativePath = path.relative(process.cwd(), filePath).replace(/\\/g, '/');
|
|
45
|
+
for (const pattern of customExclusions) {
|
|
46
|
+
if (relativePath.includes(pattern)) return true;
|
|
47
|
+
}
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// ── Traversal ─────────────────────────────────────────────────────────────────
|
|
52
|
+
function walkDir(dir, fileList = []) {
|
|
53
|
+
if (!fs.existsSync(dir) || isExcluded(dir)) return fileList;
|
|
54
|
+
|
|
55
|
+
let files;
|
|
56
|
+
try {
|
|
57
|
+
files = fs.readdirSync(dir);
|
|
58
|
+
} catch (err) {
|
|
59
|
+
return fileList; // Permission denied or similar
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
for (const file of files) {
|
|
63
|
+
const filePath = path.join(dir, file);
|
|
64
|
+
if (isExcluded(filePath)) continue;
|
|
65
|
+
|
|
66
|
+
if (fs.statSync(filePath).isDirectory()) {
|
|
67
|
+
walkDir(filePath, fileList);
|
|
68
|
+
} else {
|
|
69
|
+
// Target standard JS/TS ecosystem files
|
|
70
|
+
if (/\.(js|jsx|ts|tsx|mjs|cjs)$/.test(file)) {
|
|
71
|
+
fileList.push(filePath);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return fileList;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// ── Regex AST Extraction ──────────────────────────────────────────────────────
|
|
79
|
+
function parseFile(content) {
|
|
80
|
+
const imports = new Set();
|
|
81
|
+
const exports = new Set();
|
|
82
|
+
|
|
83
|
+
// Strip comments to prevent false positives in regex
|
|
84
|
+
const cleanContent = content.replace(/\/\*[\s\S]*?\*\//g, '').replace(/\/\/.*$/gm, '');
|
|
85
|
+
|
|
86
|
+
// Import extractors
|
|
87
|
+
const importRegex = /import(?:(?:[\w*\s{},]*)\sfrom\s+)?['"]([^'"]+)['"]/g;
|
|
88
|
+
const requireRegex = /require\(['"]([^'"]+)['"]\)/g;
|
|
89
|
+
const dynamicImportRegex = /import\(['"]([^'"]+)['"]\)/g;
|
|
90
|
+
|
|
91
|
+
// Export extractors
|
|
92
|
+
const exportRegex = /export\s+(?:const|let|var|function|class)\s+([a-zA-Z0-9_]+)/g;
|
|
93
|
+
const moduleExportRegex = /module\.exports\s*=\s*\{([^}]+)\}/g;
|
|
94
|
+
const defaultExportRegex = /export\s+default\s+([a-zA-Z0-9_]+)/g;
|
|
95
|
+
|
|
96
|
+
let match;
|
|
97
|
+
while ((match = importRegex.exec(cleanContent)) !== null) imports.add(match[1]);
|
|
98
|
+
while ((match = requireRegex.exec(cleanContent)) !== null) imports.add(match[1]);
|
|
99
|
+
while ((match = dynamicImportRegex.exec(cleanContent)) !== null) imports.add(match[1]);
|
|
100
|
+
|
|
101
|
+
while ((match = exportRegex.exec(cleanContent)) !== null) exports.add(match[1]);
|
|
102
|
+
while ((match = defaultExportRegex.exec(cleanContent)) !== null) exports.add(match[1]);
|
|
103
|
+
|
|
104
|
+
// Extractor for module.exports = { a, b, c }
|
|
105
|
+
while ((match = moduleExportRegex.exec(cleanContent)) !== null) {
|
|
106
|
+
const tokens = match[1].split(',').map(s => s.trim().split(':')[0].trim());
|
|
107
|
+
tokens.forEach(t => t && exports.add(t));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return {
|
|
111
|
+
imports: Array.from(imports),
|
|
112
|
+
exports: Array.from(exports)
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// ── YAML Generation ───────────────────────────────────────────────────────────
|
|
117
|
+
function generateYAML(data) {
|
|
118
|
+
let yaml = '# Auto-generated Architecture Graph by Tribunal Kit\n';
|
|
119
|
+
yaml += '# DO NOT EDIT MANUALLY - Auto-updates via incremental cache\n\n';
|
|
120
|
+
|
|
121
|
+
for (const [file, info] of Object.entries(data)) {
|
|
122
|
+
// Only include files that actually export or import things to reduce noise
|
|
123
|
+
if (info.imports.length === 0 && info.exports.length === 0) continue;
|
|
124
|
+
|
|
125
|
+
yaml += `"${file}":\n`;
|
|
126
|
+
if (info.imports && info.imports.length > 0) {
|
|
127
|
+
yaml += ` imports:\n`;
|
|
128
|
+
info.imports.forEach(i => yaml += ` - "${i}"\n`);
|
|
129
|
+
}
|
|
130
|
+
if (info.exports && info.exports.length > 0) {
|
|
131
|
+
yaml += ` exports:\n`;
|
|
132
|
+
info.exports.forEach(e => yaml += ` - "${e}"\n`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return yaml;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// ── Main Execution ────────────────────────────────────────────────────────────
|
|
139
|
+
function main() {
|
|
140
|
+
if (!fs.existsSync(AGENT_DIR)) {
|
|
141
|
+
console.error('\x1b[31m✖ Error: .agent directory not found. Please run tribunal-kit init first.\x1b[0m');
|
|
142
|
+
process.exit(1);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (!fs.existsSync(HISTORY_DIR)) {
|
|
146
|
+
fs.mkdirSync(HISTORY_DIR, { recursive: true });
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// 1. Load incremental cache
|
|
150
|
+
let cache = {};
|
|
151
|
+
if (fs.existsSync(CACHE_FILE)) {
|
|
152
|
+
try { cache = JSON.parse(fs.readFileSync(CACHE_FILE, 'utf8')); } catch(e) {}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
console.log('\x1b[96m✦ Building Architecture Graph...\x1b[0m');
|
|
156
|
+
const files = walkDir(process.cwd());
|
|
157
|
+
const graphData = {};
|
|
158
|
+
|
|
159
|
+
let parsedCount = 0;
|
|
160
|
+
let cachedCount = 0;
|
|
161
|
+
|
|
162
|
+
// 2. Parse or hit cache
|
|
163
|
+
for (const file of files) {
|
|
164
|
+
const stat = fs.statSync(file);
|
|
165
|
+
const relativePath = path.relative(process.cwd(), file).replace(/\\/g, '/');
|
|
166
|
+
|
|
167
|
+
if (cache[relativePath] && cache[relativePath].mtimeMs === stat.mtimeMs) {
|
|
168
|
+
graphData[relativePath] = { imports: cache[relativePath].imports, exports: cache[relativePath].exports };
|
|
169
|
+
cachedCount++;
|
|
170
|
+
} else {
|
|
171
|
+
try {
|
|
172
|
+
const content = fs.readFileSync(file, 'utf8');
|
|
173
|
+
const parsed = parseFile(content);
|
|
174
|
+
graphData[relativePath] = parsed;
|
|
175
|
+
|
|
176
|
+
cache[relativePath] = {
|
|
177
|
+
mtimeMs: stat.mtimeMs,
|
|
178
|
+
imports: parsed.imports,
|
|
179
|
+
exports: parsed.exports
|
|
180
|
+
};
|
|
181
|
+
parsedCount++;
|
|
182
|
+
} catch (err) {
|
|
183
|
+
// Graceful fallback on unreadable files
|
|
184
|
+
console.warn(`\x1b[33m ⚠ Skipping unreadable file: ${relativePath}\x1b[0m`);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// 3. Save states
|
|
190
|
+
fs.writeFileSync(CACHE_FILE, JSON.stringify(cache, null, 2));
|
|
191
|
+
const yamlOutput = generateYAML(graphData);
|
|
192
|
+
fs.writeFileSync(GRAPH_FILE, yamlOutput);
|
|
193
|
+
|
|
194
|
+
console.log(`\n\x1b[32m✔ Graph successfully built.\x1b[0m`);
|
|
195
|
+
console.log(` \x1b[2mParsed: ${parsedCount} files | Cached: ${cachedCount} files\x1b[0m`);
|
|
196
|
+
console.log(` \x1b[2mSaved to: ${GRAPH_FILE}\x1b[0m`);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
main();
|