tribunal-kit 4.3.0 → 4.4.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 (120) hide show
  1. package/.agent/history/architecture-explorer.html +352 -0
  2. package/.agent/history/architecture-graph.yaml +109 -0
  3. package/.agent/history/graph-cache.json +215 -0
  4. package/.agent/history/snapshots/migrate_refs.js.json +11 -0
  5. package/.agent/history/snapshots/scripts__changelog.js.json +12 -0
  6. package/.agent/history/snapshots/scripts__sync-version.js.json +11 -0
  7. package/.agent/history/snapshots/scripts__validate-payload.js.json +11 -0
  8. package/.agent/history/snapshots/test__integration__bridges.test.js.json +13 -0
  9. package/.agent/history/snapshots/test__integration__init.test.js.json +13 -0
  10. package/.agent/history/snapshots/test__integration__routing.test.js.json +11 -0
  11. package/.agent/history/snapshots/test__integration__swarm_dispatcher.test.js.json +13 -0
  12. package/.agent/history/snapshots/test__integration__wave2.test.js.json +13 -0
  13. package/.agent/history/snapshots/test__unit__args.test.js.json +10 -0
  14. package/.agent/history/snapshots/test__unit__case_law_manager.test.js.json +10 -0
  15. package/.agent/history/snapshots/test__unit__copyDir.test.js.json +13 -0
  16. package/.agent/history/snapshots/test__unit__graph_tools.test.js.json +11 -0
  17. package/.agent/history/snapshots/test__unit__selfInstall.test.js.json +13 -0
  18. package/.agent/history/snapshots/test__unit__semver.test.js.json +10 -0
  19. package/.agent/history/snapshots/test__unit__swarm_dispatcher.test.js.json +11 -0
  20. package/.agent/scripts/case_law_manager.js +684 -684
  21. package/.agent/scripts/dependency_analyzer.js +1 -1
  22. package/.agent/scripts/graph_builder.js +311 -0
  23. package/.agent/scripts/graph_visualizer.js +384 -0
  24. package/.agent/scripts/graph_zoom.js +154 -0
  25. package/.agent/scripts/mutation_runner.js +280 -0
  26. package/.agent/skills/agent-organizer/SKILL.md +9 -1
  27. package/.agent/skills/agentic-patterns/SKILL.md +9 -1
  28. package/.agent/skills/ai-prompt-injection-defense/SKILL.md +9 -1
  29. package/.agent/skills/api-patterns/SKILL.md +206 -198
  30. package/.agent/skills/api-security-auditor/SKILL.md +9 -1
  31. package/.agent/skills/app-builder/SKILL.md +9 -1
  32. package/.agent/skills/app-builder/templates/SKILL.md +77 -69
  33. package/.agent/skills/appflow-wireframe/SKILL.md +9 -1
  34. package/.agent/skills/architecture/SKILL.md +9 -1
  35. package/.agent/skills/authentication-best-practices/SKILL.md +9 -1
  36. package/.agent/skills/bash-linux/SKILL.md +9 -1
  37. package/.agent/skills/behavioral-modes/SKILL.md +9 -1
  38. package/.agent/skills/brainstorming/SKILL.md +9 -1
  39. package/.agent/skills/building-native-ui/SKILL.md +9 -1
  40. package/.agent/skills/clean-code/SKILL.md +9 -1
  41. package/.agent/skills/code-review-checklist/SKILL.md +9 -1
  42. package/.agent/skills/config-validator/SKILL.md +9 -1
  43. package/.agent/skills/csharp-developer/SKILL.md +9 -1
  44. package/.agent/skills/data-validation-schemas/SKILL.md +287 -279
  45. package/.agent/skills/database-design/SKILL.md +199 -191
  46. package/.agent/skills/deployment-procedures/SKILL.md +9 -1
  47. package/.agent/skills/devops-engineer/SKILL.md +9 -1
  48. package/.agent/skills/devops-incident-responder/SKILL.md +9 -1
  49. package/.agent/skills/documentation-templates/SKILL.md +9 -1
  50. package/.agent/skills/edge-computing/SKILL.md +9 -1
  51. package/.agent/skills/error-resilience/SKILL.md +387 -379
  52. package/.agent/skills/extract-design-system/SKILL.md +9 -1
  53. package/.agent/skills/framer-motion-expert/SKILL.md +203 -195
  54. package/.agent/skills/frontend-design/SKILL.md +160 -152
  55. package/.agent/skills/game-design-expert/SKILL.md +9 -1
  56. package/.agent/skills/game-engineering-expert/SKILL.md +9 -1
  57. package/.agent/skills/geo-fundamentals/SKILL.md +9 -1
  58. package/.agent/skills/github-operations/SKILL.md +9 -1
  59. package/.agent/skills/gsap-core/SKILL.md +54 -46
  60. package/.agent/skills/gsap-frameworks/SKILL.md +54 -46
  61. package/.agent/skills/gsap-performance/SKILL.md +54 -46
  62. package/.agent/skills/gsap-plugins/SKILL.md +54 -46
  63. package/.agent/skills/gsap-react/SKILL.md +54 -46
  64. package/.agent/skills/gsap-scrolltrigger/SKILL.md +54 -46
  65. package/.agent/skills/gsap-timeline/SKILL.md +54 -46
  66. package/.agent/skills/gsap-utils/SKILL.md +54 -46
  67. package/.agent/skills/i18n-localization/SKILL.md +9 -1
  68. package/.agent/skills/intelligent-routing/SKILL.md +38 -30
  69. package/.agent/skills/knowledge-graph/SKILL.md +52 -0
  70. package/.agent/skills/lint-and-validate/SKILL.md +9 -1
  71. package/.agent/skills/llm-engineering/SKILL.md +9 -1
  72. package/.agent/skills/local-first/SKILL.md +9 -1
  73. package/.agent/skills/mcp-builder/SKILL.md +9 -1
  74. package/.agent/skills/mobile-design/SKILL.md +222 -214
  75. package/.agent/skills/monorepo-management/SKILL.md +293 -285
  76. package/.agent/skills/motion-engineering/SKILL.md +193 -185
  77. package/.agent/skills/nextjs-react-expert/SKILL.md +193 -185
  78. package/.agent/skills/nodejs-best-practices/SKILL.md +9 -1
  79. package/.agent/skills/observability/SKILL.md +9 -1
  80. package/.agent/skills/parallel-agents/SKILL.md +9 -1
  81. package/.agent/skills/performance-profiling/SKILL.md +9 -1
  82. package/.agent/skills/plan-writing/SKILL.md +9 -1
  83. package/.agent/skills/platform-engineer/SKILL.md +9 -1
  84. package/.agent/skills/playwright-best-practices/SKILL.md +9 -1
  85. package/.agent/skills/powershell-windows/SKILL.md +9 -1
  86. package/.agent/skills/project-idioms/SKILL.md +9 -1
  87. package/.agent/skills/python-patterns/SKILL.md +9 -1
  88. package/.agent/skills/python-pro/SKILL.md +282 -274
  89. package/.agent/skills/react-specialist/SKILL.md +236 -228
  90. package/.agent/skills/readme-builder/SKILL.md +9 -1
  91. package/.agent/skills/realtime-patterns/SKILL.md +9 -1
  92. package/.agent/skills/red-team-tactics/SKILL.md +9 -1
  93. package/.agent/skills/rust-pro/SKILL.md +9 -1
  94. package/.agent/skills/seo-fundamentals/SKILL.md +9 -1
  95. package/.agent/skills/server-management/SKILL.md +9 -1
  96. package/.agent/skills/shadcn-ui-expert/SKILL.md +9 -1
  97. package/.agent/skills/skill-creator/SKILL.md +9 -1
  98. package/.agent/skills/sql-pro/SKILL.md +9 -1
  99. package/.agent/skills/supabase-postgres-best-practices/SKILL.md +9 -1
  100. package/.agent/skills/swiftui-expert/SKILL.md +9 -1
  101. package/.agent/skills/systematic-debugging/SKILL.md +9 -1
  102. package/.agent/skills/tailwind-patterns/SKILL.md +9 -1
  103. package/.agent/skills/tdd-workflow/SKILL.md +9 -1
  104. package/.agent/skills/test-result-analyzer/SKILL.md +9 -1
  105. package/.agent/skills/testing-patterns/SKILL.md +28 -3
  106. package/.agent/skills/trend-researcher/SKILL.md +9 -1
  107. package/.agent/skills/typescript-advanced/SKILL.md +294 -286
  108. package/.agent/skills/ui-ux-pro-max/SKILL.md +561 -116
  109. package/.agent/skills/ui-ux-researcher/SKILL.md +9 -1
  110. package/.agent/skills/vue-expert/SKILL.md +234 -226
  111. package/.agent/skills/vulnerability-scanner/SKILL.md +9 -1
  112. package/.agent/skills/web-accessibility-auditor/SKILL.md +9 -1
  113. package/.agent/skills/web-design-guidelines/SKILL.md +9 -1
  114. package/.agent/skills/webapp-testing/SKILL.md +9 -1
  115. package/.agent/skills/whimsy-injector/SKILL.md +9 -1
  116. package/.agent/skills/workflow-optimizer/SKILL.md +9 -1
  117. package/README.md +242 -242
  118. package/bin/tribunal-kit.js +157 -21
  119. package/package.json +81 -80
  120. package/scripts/validate-payload.js +73 -0
@@ -23,7 +23,7 @@ const { spawnSync } = require('child_process');
23
23
  const { RED, GREEN, YELLOW, BLUE, BOLD, RESET } = require('./colors.js');
24
24
 
25
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__"]);
26
+ const SKIP_DIRS = new Set(["node_modules", ".git", "dist", "build", ".next", ".agent", "__pycache__", "test", "tests", "__tests__"]);
27
27
 
28
28
  const NODE_BUILTINS = new Set([
29
29
  "fs", "path", "os", "crypto", "http", "https", "url", "util",
@@ -0,0 +1,311 @@
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
+ * Now includes Blast Radius calculation and robust token stripping.
7
+ */
8
+
9
+ 'use strict';
10
+
11
+ const fs = require('fs');
12
+ const path = require('path');
13
+
14
+ const AGENT_DIR = path.join(process.cwd(), '.agent');
15
+ const HISTORY_DIR = path.join(AGENT_DIR, 'history');
16
+ const CACHE_FILE = path.join(HISTORY_DIR, 'graph-cache.json');
17
+ const GRAPH_FILE = path.join(HISTORY_DIR, 'architecture-graph.yaml');
18
+
19
+ // ── Exclusions & Safety ───────────────────────────────────────────────────────
20
+ const DEFAULT_EXCLUSIONS = new Set([
21
+ 'node_modules', '.git', '.next', 'dist', 'build', 'coverage', '.agent', 'artifacts'
22
+ ]);
23
+
24
+ function loadGitIgnore() {
25
+ const gitignorePath = path.join(process.cwd(), '.gitignore');
26
+ if (!fs.existsSync(gitignorePath)) return [];
27
+
28
+ return fs.readFileSync(gitignorePath, 'utf8')
29
+ .split('\n')
30
+ .map(line => line.trim())
31
+ .filter(line => line && !line.startsWith('#'))
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
+ if (parts.some(p => DEFAULT_EXCLUSIONS.has(p))) return true;
40
+
41
+ const relativePath = path.relative(process.cwd(), filePath).replace(/\\/g, '/');
42
+ for (const pattern of customExclusions) {
43
+ if (relativePath.includes(pattern)) return true;
44
+ }
45
+ return false;
46
+ }
47
+
48
+ // ── Traversal ─────────────────────────────────────────────────────────────────
49
+ function walkDir(dir, fileList = []) {
50
+ if (!fs.existsSync(dir) || isExcluded(dir)) return fileList;
51
+
52
+ let files;
53
+ try {
54
+ files = fs.readdirSync(dir);
55
+ } catch (err) {
56
+ return fileList;
57
+ }
58
+
59
+ for (const file of files) {
60
+ const filePath = path.join(dir, file);
61
+ if (isExcluded(filePath)) continue;
62
+
63
+ if (fs.statSync(filePath).isDirectory()) {
64
+ walkDir(filePath, fileList);
65
+ } else {
66
+ if (/\.(js|jsx|ts|tsx|mjs|cjs)$/.test(file)) {
67
+ fileList.push(filePath);
68
+ }
69
+ }
70
+ }
71
+ return fileList;
72
+ }
73
+
74
+ // ── Regex AST Extraction ──────────────────────────────────────────────────────
75
+ function parseFile(content) {
76
+ const imports = new Set();
77
+ const exports = new Set();
78
+
79
+ const cleanContent = stripStringsAndComments(content);
80
+
81
+ const importRegex = /import(?:(?:[\w*\s{},]*)\sfrom\s+)?([^\s;]+)/g; // Match bare specifier if possible, strings are stripped, but wait...
82
+ // WAIT: If I stripped strings, how do I get the import path?
83
+ // The previous implementation used strings `['"]([^'"]+)['"]`.
84
+ // If I strip strings, the import path is lost!
85
+ // Let's rollback that logic or adapt it.
86
+ // Instead of stripping all strings, we should only strip strings if they are NOT following 'import ' or 'require('
87
+ // To do this simply, let's keep strings, but just be careful.
88
+ // Actually, string literals inside `require("...")` are what we want.
89
+ // So `parseFile` should probably NOT strip strings, but just use a safer regex.
90
+ // The false positive in `dependency_analyzer` was because of `const diff = "import a from 'a'"`.
91
+ // Let's use `stripStringsAndComments` but we DO NOT strip strings.
92
+ // We only strip comments.
93
+
94
+ // I'll define an inner function to just strip comments to be safe for imports.
95
+ // Let's stick to the simple `.replace` for comments for now, and rely on regex boundaries.
96
+ const semiCleanContent = content.replace(/\/\*[\s\S]*?\*\//g, '').replace(/\/\/.*$/gm, '');
97
+
98
+ const importRegex2 = /^[\s]*import(?:(?:[\w*\s{},]*)\sfrom\s+)?['"]([^'"]+)['"]/gm;
99
+ const requireRegex = /require\(['"]([^'"]+)['"]\)/g;
100
+ const dynamicImportRegex = /import\(['"]([^'"]+)['"]\)/g;
101
+
102
+ const exportRegex = /^[\s]*export\s+(?:const|let|var|function|class)\s+([a-zA-Z0-9_]+)/gm;
103
+ const moduleExportRegex = /module\.exports\s*=\s*\{([^}]+)\}/g;
104
+ const defaultExportRegex = /^[\s]*export\s+default\s+([a-zA-Z0-9_]+)/gm;
105
+
106
+ let match;
107
+ while ((match = importRegex2.exec(semiCleanContent)) !== null) imports.add(match[1]);
108
+ while ((match = requireRegex.exec(semiCleanContent)) !== null) imports.add(match[1]);
109
+ while ((match = dynamicImportRegex.exec(semiCleanContent)) !== null) imports.add(match[1]);
110
+
111
+ while ((match = exportRegex.exec(semiCleanContent)) !== null) exports.add(match[1]);
112
+ while ((match = defaultExportRegex.exec(semiCleanContent)) !== null) exports.add(match[1]);
113
+
114
+ while ((match = moduleExportRegex.exec(semiCleanContent)) !== null) {
115
+ const tokens = match[1].split(',').map(s => s.trim().split(':')[0].trim());
116
+ tokens.forEach(t => t && exports.add(t));
117
+ }
118
+
119
+ return {
120
+ imports: Array.from(imports),
121
+ exports: Array.from(exports)
122
+ };
123
+ }
124
+
125
+ // ── YAML Generation ───────────────────────────────────────────────────────────
126
+ function generateYAML(data) {
127
+ let yaml = '# Auto-generated Architecture Graph by Tribunal Kit\n';
128
+ yaml += '# DO NOT EDIT MANUALLY - Auto-updates via incremental cache\n\n';
129
+
130
+ for (const [file, info] of Object.entries(data)) {
131
+ if (info.imports.length === 0 && info.exports.length === 0 && (!info.dependents || info.dependents.length === 0)) continue;
132
+
133
+ yaml += `"${file}":\n`;
134
+ yaml += ` riskScore: "${info.riskScore || 'Low'}"\n`;
135
+ yaml += ` blastRadius: ${info.blastRadius || 0}\n`;
136
+
137
+ if (info.imports && info.imports.length > 0) {
138
+ yaml += ` imports:\n`;
139
+ info.imports.forEach(i => yaml += ` - "${i}"\n`);
140
+ }
141
+ if (info.exports && info.exports.length > 0) {
142
+ yaml += ` exports:\n`;
143
+ info.exports.forEach(e => yaml += ` - "${e}"\n`);
144
+ }
145
+ if (info.dependents && info.dependents.length > 0) {
146
+ yaml += ` dependents:\n`;
147
+ info.dependents.forEach(d => yaml += ` - "${d}"\n`);
148
+ }
149
+ }
150
+ return yaml;
151
+ }
152
+
153
+ // ── Main Execution ────────────────────────────────────────────────────────────
154
+ function main() {
155
+ if (!fs.existsSync(AGENT_DIR)) {
156
+ console.error('\x1b[31m✖ Error: .agent directory not found.\x1b[0m');
157
+ process.exit(1);
158
+ }
159
+
160
+ if (!fs.existsSync(HISTORY_DIR)) fs.mkdirSync(HISTORY_DIR, { recursive: true });
161
+
162
+ let cache = {};
163
+ if (fs.existsSync(CACHE_FILE)) {
164
+ try { cache = JSON.parse(fs.readFileSync(CACHE_FILE, 'utf8')); } catch(e) {}
165
+ }
166
+
167
+ console.log('\x1b[96m✦ Building Architecture Graph...\x1b[0m');
168
+ const files = walkDir(process.cwd());
169
+ const graphData = {};
170
+
171
+ let parsedCount = 0;
172
+ let cachedCount = 0;
173
+
174
+ for (const file of files) {
175
+ const stat = fs.statSync(file);
176
+ const relativePath = path.relative(process.cwd(), file).replace(/\\/g, '/');
177
+
178
+ if (cache[relativePath] && cache[relativePath].mtimeMs === stat.mtimeMs) {
179
+ graphData[relativePath] = { imports: cache[relativePath].imports, exports: cache[relativePath].exports };
180
+ cachedCount++;
181
+ } else {
182
+ try {
183
+ const content = fs.readFileSync(file, 'utf8');
184
+ const parsed = parseFile(content);
185
+ graphData[relativePath] = parsed;
186
+
187
+ cache[relativePath] = {
188
+ mtimeMs: stat.mtimeMs,
189
+ imports: parsed.imports,
190
+ exports: parsed.exports
191
+ };
192
+ parsedCount++;
193
+ } catch (err) {}
194
+ }
195
+ }
196
+
197
+ // Compute Dependents
198
+ for (const [file, info] of Object.entries(graphData)) info.dependents = [];
199
+
200
+ const fileKeys = Object.keys(graphData);
201
+ for (const [file, info] of Object.entries(graphData)) {
202
+ for (const imp of info.imports) {
203
+ if (imp.startsWith('.')) {
204
+ let resolved = path.posix.join(path.dirname(file), imp);
205
+ // Look for direct match or .js / index.js
206
+ let matchingKey = fileKeys.find(k =>
207
+ k === resolved || k === resolved + '.js' || k === resolved + '.ts' || k === resolved + '/index.js'
208
+ );
209
+ if (matchingKey) {
210
+ if (!graphData[matchingKey].dependents.includes(file)) {
211
+ graphData[matchingKey].dependents.push(file);
212
+ }
213
+ }
214
+ }
215
+ }
216
+ }
217
+
218
+ // Compute Risk Score
219
+ function computeRisk(file) {
220
+ const visited = new Set();
221
+ function visit(node) {
222
+ if (visited.has(node)) return;
223
+ visited.add(node);
224
+ const deps = graphData[node]?.dependents || [];
225
+ deps.forEach(visit);
226
+ }
227
+ visit(file);
228
+ const radius = visited.size - 1;
229
+ let score = 'Low';
230
+ if (radius > 10) score = 'Critical';
231
+ else if (radius >= 5) score = 'High';
232
+ else if (radius >= 2) score = 'Medium';
233
+ return { score, count: Math.max(0, radius) };
234
+ }
235
+
236
+ for (const file of fileKeys) {
237
+ const risk = computeRisk(file);
238
+ graphData[file].riskScore = risk.score;
239
+ graphData[file].blastRadius = risk.count;
240
+
241
+ // Update cache with these values so visualizer can use it
242
+ if (cache[file]) {
243
+ cache[file].dependents = graphData[file].dependents;
244
+ cache[file].riskScore = risk.score;
245
+ cache[file].blastRadius = risk.count;
246
+ }
247
+ }
248
+
249
+ fs.writeFileSync(CACHE_FILE, JSON.stringify(cache, null, 2));
250
+ fs.writeFileSync(GRAPH_FILE, generateYAML(graphData));
251
+
252
+ // ── Pre-Computed Context Snapshots (Option C) ───────────────────────────
253
+ const SNAPSHOTS_DIR = path.join(HISTORY_DIR, 'snapshots');
254
+ if (!fs.existsSync(SNAPSHOTS_DIR)) {
255
+ fs.mkdirSync(SNAPSHOTS_DIR, { recursive: true });
256
+ } else {
257
+ // Clear stale snapshots
258
+ try {
259
+ const oldSnapshots = fs.readdirSync(SNAPSHOTS_DIR);
260
+ for (const os of oldSnapshots) fs.unlinkSync(path.join(SNAPSHOTS_DIR, os));
261
+ } catch (e) {}
262
+ }
263
+
264
+ console.log('\x1b[96m✦ Generating Context Snapshots...\x1b[0m');
265
+ for (const file of fileKeys) {
266
+ const info = graphData[file];
267
+ const snapshotFile = file.replace(/[\\/]/g, '__') + '.json';
268
+ const snapshotPath = path.join(SNAPSHOTS_DIR, snapshotFile);
269
+
270
+ let content = '';
271
+ try {
272
+ content = fs.readFileSync(path.join(process.cwd(), file), 'utf8');
273
+ } catch (e) {
274
+ continue;
275
+ }
276
+
277
+ const snapshot = {
278
+ file: file,
279
+ riskScore: info.riskScore,
280
+ blastRadius: info.blastRadius,
281
+ imports: {},
282
+ dependents: info.dependents || [],
283
+ content: content
284
+ };
285
+
286
+ for (const imp of info.imports) {
287
+ if (imp.startsWith('.')) {
288
+ let resolved = path.posix.join(path.dirname(file), imp);
289
+ let matchingKey = fileKeys.find(k =>
290
+ k === resolved || k === resolved + '.js' || k === resolved + '.ts' || k === resolved + '/index.js'
291
+ );
292
+ if (matchingKey && graphData[matchingKey]) {
293
+ snapshot.imports[imp] = graphData[matchingKey].exports;
294
+ } else {
295
+ snapshot.imports[imp] = [];
296
+ }
297
+ } else {
298
+ snapshot.imports[imp] = [];
299
+ }
300
+ }
301
+
302
+ fs.writeFileSync(snapshotPath, JSON.stringify(snapshot, null, 2));
303
+ }
304
+ console.log(` \x1b[2mSaved ${fileKeys.length} snapshots to: ${SNAPSHOTS_DIR}\x1b[0m`);
305
+
306
+ console.log(`\n\x1b[32m✔ Graph successfully built.\x1b[0m`);
307
+ console.log(` \x1b[2mParsed: ${parsedCount} files | Cached: ${cachedCount} files\x1b[0m`);
308
+ console.log(` \x1b[2mSaved to: ${GRAPH_FILE}\x1b[0m`);
309
+ }
310
+
311
+ main();