tribunal-kit 5.7.0 → 5.8.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 +6 -7
- package/.agent/agents/frontend-reviewer.md +13 -0
- package/.agent/agents/frontend-specialist.md +14 -0
- package/.agent/agents/logic-reviewer.md +11 -0
- package/.agent/agents/orchestrator.md +15 -0
- package/.agent/agents/security-auditor.md +13 -0
- package/.agent/agents/ui-ux-auditor.md +7 -31
- package/.agent/history/memory/.memory.idx +766 -0
- package/.agent/history/memory/MEMORY.md +62 -0
- package/.agent/routing_index.json +694 -714
- package/.agent/rules/GEMINI.md +58 -8
- package/.agent/scripts/_colors.js +131 -89
- package/.agent/scripts/_utils.js +163 -128
- package/.agent/scripts/auto_preview.js +207 -197
- package/.agent/scripts/bundle_analyzer.js +227 -192
- package/.agent/scripts/case_law_manager.js +991 -689
- package/.agent/scripts/checklist.js +233 -190
- package/.agent/scripts/context_broker.js +930 -605
- package/.agent/scripts/dependency_analyzer.js +275 -184
- package/.agent/scripts/graph_builder.js +412 -341
- package/.agent/scripts/graph_visualizer.js +392 -390
- package/.agent/scripts/graph_zoom.js +198 -156
- package/.agent/scripts/inner_loop_validator.js +523 -445
- package/.agent/scripts/lint_runner.js +199 -157
- package/.agent/scripts/marathon_harness.js +819 -661
- package/.agent/scripts/minify_context.js +115 -100
- package/.agent/scripts/mutation_runner.js +321 -280
- package/.agent/scripts/prompt_compiler.js +62 -42
- package/.agent/scripts/schema_validator.js +373 -280
- package/.agent/scripts/security_scan.js +333 -190
- package/.agent/scripts/session_manager.js +306 -270
- package/.agent/scripts/skill_evolution.js +810 -637
- package/.agent/scripts/skill_integrator.js +327 -307
- package/.agent/scripts/strengthen_skills.js +203 -193
- package/.agent/scripts/swarm_dispatcher.js +558 -457
- package/.agent/scripts/test_runner.js +178 -152
- package/.agent/scripts/verify_all.js +200 -168
- package/.agent/skills/fabel-protocol/SKILL.md +235 -0
- package/.agent/skills/thinking-protocol/SKILL.md +27 -0
- package/.agent/workflows/generate.md +1 -1
- package/.agent/workflows/tribunal-speed.md +1 -1
- package/README.md +53 -53
- package/bin/mcp-server.js +460 -175
- package/bin/tribunal-kit.js +1245 -987
- package/bin/wrapper.js +104 -74
- package/dist/cli.js +31 -0
- package/dist/commands/case.js +23 -0
- package/dist/commands/compile.js +84 -0
- package/dist/commands/init.js +42 -0
- package/dist/commands/learn.js +57 -0
- package/dist/commands/memory.js +456 -0
- package/package.json +2 -2
- package/scripts/benchmark.js +162 -125
- package/scripts/changelog.js +196 -168
- package/scripts/sync-version.js +94 -81
- package/scripts/validate-payload.js +85 -78
|
@@ -14,221 +14,312 @@
|
|
|
14
14
|
* node .agent/scripts/dependency_analyzer.js . --check-unused
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
"use strict";
|
|
18
18
|
|
|
19
|
-
const fs = require(
|
|
20
|
-
const path = require(
|
|
19
|
+
const fs = require("fs");
|
|
20
|
+
const path = require("path");
|
|
21
21
|
|
|
22
22
|
const {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
BOLD,
|
|
24
|
+
DIM,
|
|
25
|
+
CYAN,
|
|
26
|
+
RESET,
|
|
27
|
+
banner,
|
|
28
|
+
sectionHeader,
|
|
29
|
+
timer,
|
|
30
|
+
formatMs,
|
|
31
|
+
ok,
|
|
32
|
+
fail,
|
|
33
|
+
warn,
|
|
34
|
+
skip,
|
|
35
|
+
} = require("./_colors");
|
|
36
|
+
|
|
37
|
+
const { walkDir, loadJson, runCommand } = require("./_utils");
|
|
38
|
+
|
|
39
|
+
const SOURCE_EXTENSIONS = new Set([
|
|
40
|
+
".ts",
|
|
41
|
+
".tsx",
|
|
42
|
+
".js",
|
|
43
|
+
".jsx",
|
|
44
|
+
".mjs",
|
|
45
|
+
".cjs",
|
|
46
|
+
]);
|
|
31
47
|
|
|
32
48
|
const NODE_BUILTINS = new Set([
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
49
|
+
"fs",
|
|
50
|
+
"path",
|
|
51
|
+
"os",
|
|
52
|
+
"crypto",
|
|
53
|
+
"http",
|
|
54
|
+
"https",
|
|
55
|
+
"url",
|
|
56
|
+
"util",
|
|
57
|
+
"stream",
|
|
58
|
+
"events",
|
|
59
|
+
"child_process",
|
|
60
|
+
"cluster",
|
|
61
|
+
"net",
|
|
62
|
+
"dns",
|
|
63
|
+
"tls",
|
|
64
|
+
"readline",
|
|
65
|
+
"zlib",
|
|
66
|
+
"buffer",
|
|
67
|
+
"querystring",
|
|
68
|
+
"string_decoder",
|
|
69
|
+
"assert",
|
|
70
|
+
"perf_hooks",
|
|
71
|
+
"worker_threads",
|
|
72
|
+
"timers",
|
|
73
|
+
"v8",
|
|
74
|
+
"node:fs",
|
|
75
|
+
"node:path",
|
|
76
|
+
"node:os",
|
|
77
|
+
"node:crypto",
|
|
78
|
+
"node:http",
|
|
79
|
+
"node:https",
|
|
80
|
+
"node:url",
|
|
81
|
+
"node:util",
|
|
82
|
+
"node:stream",
|
|
83
|
+
"node:events",
|
|
84
|
+
"node:child_process",
|
|
85
|
+
"node:net",
|
|
86
|
+
"node:dns",
|
|
87
|
+
"node:tls",
|
|
88
|
+
"node:readline",
|
|
89
|
+
"node:zlib",
|
|
90
|
+
"node:buffer",
|
|
91
|
+
"node:assert",
|
|
92
|
+
"node:perf_hooks",
|
|
93
|
+
"node:worker_threads",
|
|
94
|
+
"node:timers",
|
|
42
95
|
]);
|
|
43
96
|
|
|
44
97
|
function extractImports(projectRoot) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
98
|
+
const imports = new Set();
|
|
99
|
+
const importPatterns = [
|
|
100
|
+
/(?:import|export)\s+.*?\s+from\s+["']([^"'.][^"']*)["']/g,
|
|
101
|
+
/require\s*\(\s*["']([^"'.][^"']*)["']/g,
|
|
102
|
+
/import\s*\(\s*["']([^"'.][^"']*)["']/g,
|
|
103
|
+
];
|
|
104
|
+
|
|
105
|
+
// Use shared walkDir from _utils.js
|
|
106
|
+
const files = walkDir(projectRoot, { extensions: SOURCE_EXTENSIONS });
|
|
107
|
+
|
|
108
|
+
for (const fullPath of files) {
|
|
109
|
+
let content;
|
|
110
|
+
try {
|
|
111
|
+
content = fs.readFileSync(fullPath, "utf8");
|
|
112
|
+
} catch {
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
for (const pattern of importPatterns) {
|
|
117
|
+
// Reset regex state for each file
|
|
118
|
+
pattern.lastIndex = 0;
|
|
119
|
+
let match;
|
|
120
|
+
while ((match = pattern.exec(content)) !== null) {
|
|
121
|
+
let pkg = match[1];
|
|
122
|
+
if (pkg.startsWith("@")) {
|
|
123
|
+
const parts = pkg.split("/");
|
|
124
|
+
pkg = parts.length >= 2 ? `${parts[0]}/${parts[1]}` : pkg;
|
|
125
|
+
} else {
|
|
126
|
+
pkg = pkg.split("/")[0];
|
|
73
127
|
}
|
|
128
|
+
imports.add(pkg);
|
|
129
|
+
}
|
|
74
130
|
}
|
|
131
|
+
}
|
|
75
132
|
|
|
76
|
-
|
|
133
|
+
return imports;
|
|
77
134
|
}
|
|
78
135
|
|
|
79
136
|
function checkUnused(pkg, usedImports) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
137
|
+
const allDeps = new Set([
|
|
138
|
+
...Object.keys(pkg.dependencies || {}),
|
|
139
|
+
...Object.keys(pkg.devDependencies || {}),
|
|
140
|
+
]);
|
|
141
|
+
|
|
142
|
+
const implicitPackages = new Set([
|
|
143
|
+
"typescript",
|
|
144
|
+
"eslint",
|
|
145
|
+
"prettier",
|
|
146
|
+
"vitest",
|
|
147
|
+
"jest",
|
|
148
|
+
"ts-node",
|
|
149
|
+
"@types/node",
|
|
150
|
+
"@types/react",
|
|
151
|
+
"tailwindcss",
|
|
152
|
+
"postcss",
|
|
153
|
+
"autoprefixer",
|
|
154
|
+
"nodemon",
|
|
155
|
+
"tsx",
|
|
156
|
+
"vite",
|
|
157
|
+
"next",
|
|
158
|
+
"webpack",
|
|
159
|
+
"babel",
|
|
160
|
+
"@babel/core",
|
|
161
|
+
]);
|
|
162
|
+
|
|
163
|
+
const unused = [];
|
|
164
|
+
for (const d of allDeps) {
|
|
165
|
+
if (
|
|
166
|
+
!implicitPackages.has(d) &&
|
|
167
|
+
!d.startsWith("@types/") &&
|
|
168
|
+
!usedImports.has(d)
|
|
169
|
+
) {
|
|
170
|
+
unused.push(d);
|
|
96
171
|
}
|
|
97
|
-
|
|
172
|
+
}
|
|
173
|
+
return unused.sort();
|
|
98
174
|
}
|
|
99
175
|
|
|
100
176
|
function checkPhantom(pkg, usedImports) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
177
|
+
const allDeps = new Set([
|
|
178
|
+
...Object.keys(pkg.dependencies || {}),
|
|
179
|
+
...Object.keys(pkg.devDependencies || {}),
|
|
180
|
+
]);
|
|
181
|
+
|
|
182
|
+
const phantom = [];
|
|
183
|
+
for (const imp of usedImports) {
|
|
184
|
+
if (!NODE_BUILTINS.has(imp) && !allDeps.has(imp)) {
|
|
185
|
+
phantom.push(imp);
|
|
111
186
|
}
|
|
112
|
-
|
|
187
|
+
}
|
|
188
|
+
return phantom.sort();
|
|
113
189
|
}
|
|
114
190
|
|
|
115
191
|
function runNpmAudit(projectRoot) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
192
|
+
const result = runCommand("npm", ["audit", "--json"], {
|
|
193
|
+
cwd: projectRoot,
|
|
194
|
+
timeout: 60000,
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
if (result.status === null && !result.stdout) {
|
|
198
|
+
skip("npm not installed — skipping audit");
|
|
199
|
+
return true;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
try {
|
|
203
|
+
const auditData = JSON.parse(result.stdout);
|
|
204
|
+
const vulns =
|
|
205
|
+
(auditData.metadata && auditData.metadata.vulnerabilities) || {};
|
|
206
|
+
const critical = vulns.critical || 0;
|
|
207
|
+
const high = vulns.high || 0;
|
|
208
|
+
const moderate = vulns.moderate || 0;
|
|
209
|
+
const low = vulns.low || 0;
|
|
210
|
+
|
|
211
|
+
if (critical + high > 0) {
|
|
212
|
+
fail(
|
|
213
|
+
`npm audit: ${critical} critical, ${high} high, ${moderate} moderate, ${low} low`,
|
|
214
|
+
);
|
|
215
|
+
return false;
|
|
216
|
+
} else if (moderate + low > 0) {
|
|
217
|
+
warn(`npm audit: ${moderate} moderate, ${low} low vulnerabilities`);
|
|
218
|
+
return true;
|
|
219
|
+
} else {
|
|
220
|
+
ok("npm audit — no known vulnerabilities");
|
|
221
|
+
return true;
|
|
124
222
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const critical = vulns.critical || 0;
|
|
130
|
-
const high = vulns.high || 0;
|
|
131
|
-
const moderate = vulns.moderate || 0;
|
|
132
|
-
const low = vulns.low || 0;
|
|
133
|
-
|
|
134
|
-
if (critical + high > 0) {
|
|
135
|
-
fail(`npm audit: ${critical} critical, ${high} high, ${moderate} moderate, ${low} low`);
|
|
136
|
-
return false;
|
|
137
|
-
} else if (moderate + low > 0) {
|
|
138
|
-
warn(`npm audit: ${moderate} moderate, ${low} low vulnerabilities`);
|
|
139
|
-
return true;
|
|
140
|
-
} else {
|
|
141
|
-
ok("npm audit — no known vulnerabilities");
|
|
142
|
-
return true;
|
|
143
|
-
}
|
|
144
|
-
} catch {
|
|
145
|
-
if (result.ok) {
|
|
146
|
-
ok("npm audit — clean");
|
|
147
|
-
return true;
|
|
148
|
-
}
|
|
149
|
-
fail("npm audit returned errors");
|
|
150
|
-
return false;
|
|
223
|
+
} catch {
|
|
224
|
+
if (result.ok) {
|
|
225
|
+
ok("npm audit — clean");
|
|
226
|
+
return true;
|
|
151
227
|
}
|
|
228
|
+
fail("npm audit returned errors");
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
152
231
|
}
|
|
153
232
|
|
|
154
233
|
function main() {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
if (!targetPath) {
|
|
172
|
-
console.log("Usage: node dependency_analyzer.js <path> [--audit] [--check-unused]");
|
|
173
|
-
process.exit(1);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
const projectRoot = path.resolve(targetPath);
|
|
177
|
-
if (!fs.existsSync(projectRoot) || !fs.statSync(projectRoot).isDirectory()) {
|
|
178
|
-
fail(`Directory not found: ${projectRoot}`);
|
|
179
|
-
process.exit(1);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
console.log(banner('dependency_analyzer.js', { Project: projectRoot }));
|
|
183
|
-
|
|
184
|
-
const pkg = loadJson(path.join(projectRoot, 'package.json'));
|
|
185
|
-
if (!pkg) {
|
|
186
|
-
skip("No package.json found — dependency analysis requires a Node.js project");
|
|
187
|
-
process.exit(0);
|
|
234
|
+
const args = process.argv.slice(2);
|
|
235
|
+
let targetPath = null;
|
|
236
|
+
let auditFlag = false;
|
|
237
|
+
let checkUnusedFlag = false;
|
|
238
|
+
|
|
239
|
+
for (let i = 0; i < args.length; i++) {
|
|
240
|
+
if (args[i] === "--audit") auditFlag = true;
|
|
241
|
+
else if (args[i] === "--check-unused") checkUnusedFlag = true;
|
|
242
|
+
else if (args[i] === "-h" || args[i] === "--help") {
|
|
243
|
+
console.log(
|
|
244
|
+
"Usage: node dependency_analyzer.js <path> [--audit] [--check-unused]",
|
|
245
|
+
);
|
|
246
|
+
process.exit(0);
|
|
247
|
+
} else if (!args[i].startsWith("-") && !targetPath) {
|
|
248
|
+
targetPath = args[i];
|
|
188
249
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if (!targetPath) {
|
|
253
|
+
console.log(
|
|
254
|
+
"Usage: node dependency_analyzer.js <path> [--audit] [--check-unused]",
|
|
255
|
+
);
|
|
256
|
+
process.exit(1);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const projectRoot = path.resolve(targetPath);
|
|
260
|
+
if (!fs.existsSync(projectRoot) || !fs.statSync(projectRoot).isDirectory()) {
|
|
261
|
+
fail(`Directory not found: ${projectRoot}`);
|
|
262
|
+
process.exit(1);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
console.log(banner("dependency_analyzer.js", { Project: projectRoot }));
|
|
266
|
+
|
|
267
|
+
const pkg = loadJson(path.join(projectRoot, "package.json"));
|
|
268
|
+
if (!pkg) {
|
|
269
|
+
skip(
|
|
270
|
+
"No package.json found — dependency analysis requires a Node.js project",
|
|
271
|
+
);
|
|
272
|
+
process.exit(0);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
let issues = 0;
|
|
276
|
+
const elapsed = timer();
|
|
277
|
+
const usedImports = extractImports(projectRoot);
|
|
278
|
+
const scanMs = elapsed();
|
|
279
|
+
|
|
280
|
+
console.log(
|
|
281
|
+
`\n ${DIM}Found ${usedImports.size} unique external imports in ${formatMs(scanMs)}${RESET}`,
|
|
282
|
+
);
|
|
283
|
+
|
|
284
|
+
if (!checkUnusedFlag) {
|
|
285
|
+
console.log(sectionHeader("Phantom Imports (not in package.json)"));
|
|
286
|
+
const phantom = checkPhantom(pkg, usedImports);
|
|
287
|
+
if (phantom.length > 0) {
|
|
288
|
+
for (const p of phantom)
|
|
289
|
+
fail(
|
|
290
|
+
`'${p}' is imported but not in package.json — possible hallucination`,
|
|
291
|
+
);
|
|
292
|
+
issues += phantom.length;
|
|
212
293
|
} else {
|
|
213
|
-
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
if (auditFlag) {
|
|
217
|
-
console.log(sectionHeader('Vulnerability Audit'));
|
|
218
|
-
if (!runNpmAudit(projectRoot)) issues += 1;
|
|
294
|
+
ok("All imports found in package.json");
|
|
219
295
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
console.log(sectionHeader("Unused Dependencies"));
|
|
299
|
+
const unused = checkUnused(pkg, usedImports);
|
|
300
|
+
if (unused.length > 0) {
|
|
301
|
+
for (const u of unused)
|
|
302
|
+
warn(`'${u}' is in package.json but never imported — may be unused`);
|
|
303
|
+
} else {
|
|
304
|
+
ok("No obviously unused dependencies found");
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
if (auditFlag) {
|
|
308
|
+
console.log(sectionHeader("Vulnerability Audit"));
|
|
309
|
+
if (!runNpmAudit(projectRoot)) issues += 1;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
console.log(`\n${BOLD}${CYAN}━━━ Dependency Analysis Summary ━━━${RESET}`);
|
|
313
|
+
if (issues === 0) {
|
|
314
|
+
ok("All dependency checks passed");
|
|
315
|
+
} else {
|
|
316
|
+
fail(`${issues} issue(s) found — review above`);
|
|
317
|
+
}
|
|
318
|
+
console.log();
|
|
319
|
+
|
|
320
|
+
process.exit(issues > 0 ? 1 : 0);
|
|
230
321
|
}
|
|
231
322
|
|
|
232
323
|
if (require.main === module) {
|
|
233
|
-
|
|
324
|
+
main();
|
|
234
325
|
}
|