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.
Files changed (186) hide show
  1. package/.agent/ARCHITECTURE.md +21 -14
  2. package/.agent/agents/swarm-worker-contracts.md +5 -5
  3. package/.agent/agents/ui-ux-auditor.md +292 -0
  4. package/.agent/rules/GEMINI.md +8 -8
  5. package/.agent/scripts/__pycache__/_colors.cpython-311.pyc +0 -0
  6. package/.agent/scripts/__pycache__/_utils.cpython-311.pyc +0 -0
  7. package/.agent/scripts/__pycache__/case_law_manager.cpython-311.pyc +0 -0
  8. package/.agent/scripts/_colors.js +18 -0
  9. package/.agent/scripts/_utils.js +42 -0
  10. package/.agent/scripts/auto_preview.js +197 -0
  11. package/.agent/scripts/bundle_analyzer.js +290 -0
  12. package/.agent/scripts/case_law_manager.js +684 -0
  13. package/.agent/scripts/checklist.js +266 -0
  14. package/.agent/scripts/colors.js +17 -0
  15. package/.agent/scripts/compress_skills.js +141 -0
  16. package/.agent/scripts/consolidate_skills.js +149 -0
  17. package/.agent/scripts/context_broker.js +609 -0
  18. package/.agent/scripts/deep_compress.js +150 -0
  19. package/.agent/scripts/dependency_analyzer.js +272 -0
  20. package/.agent/scripts/graph_builder.js +199 -0
  21. package/.agent/scripts/graph_zoom.js +154 -0
  22. package/.agent/scripts/inner_loop_validator.js +465 -0
  23. package/.agent/scripts/lint_runner.js +187 -0
  24. package/.agent/scripts/minify_context.js +100 -0
  25. package/.agent/scripts/patch_skills_meta.js +156 -0
  26. package/.agent/scripts/patch_skills_output.js +244 -0
  27. package/.agent/scripts/schema_validator.js +297 -0
  28. package/.agent/scripts/security_scan.js +303 -0
  29. package/.agent/scripts/session_manager.js +276 -0
  30. package/.agent/scripts/skill_evolution.js +644 -0
  31. package/.agent/scripts/skill_integrator.js +313 -0
  32. package/.agent/scripts/strengthen_skills.js +193 -0
  33. package/.agent/scripts/strip_tribunal.js +47 -0
  34. package/.agent/scripts/swarm_dispatcher.js +360 -0
  35. package/.agent/scripts/test_runner.js +193 -0
  36. package/.agent/scripts/utils.js +32 -0
  37. package/.agent/scripts/verify_all.js +256 -0
  38. package/.agent/skills/agent-organizer/SKILL.md +12 -4
  39. package/.agent/skills/agentic-patterns/SKILL.md +12 -4
  40. package/.agent/skills/ai-prompt-injection-defense/SKILL.md +12 -4
  41. package/.agent/skills/api-patterns/SKILL.md +209 -201
  42. package/.agent/skills/api-security-auditor/SKILL.md +12 -4
  43. package/.agent/skills/app-builder/SKILL.md +12 -4
  44. package/.agent/skills/app-builder/templates/SKILL.md +76 -68
  45. package/.agent/skills/app-builder/templates/astro-static/TEMPLATE.md +1 -1
  46. package/.agent/skills/app-builder/templates/chrome-extension/TEMPLATE.md +1 -1
  47. package/.agent/skills/app-builder/templates/cli-tool/TEMPLATE.md +1 -1
  48. package/.agent/skills/app-builder/templates/electron-desktop/TEMPLATE.md +1 -1
  49. package/.agent/skills/app-builder/templates/express-api/TEMPLATE.md +1 -1
  50. package/.agent/skills/app-builder/templates/flutter-app/TEMPLATE.md +1 -1
  51. package/.agent/skills/app-builder/templates/monorepo-turborepo/TEMPLATE.md +1 -1
  52. package/.agent/skills/app-builder/templates/nextjs-fullstack/TEMPLATE.md +1 -1
  53. package/.agent/skills/app-builder/templates/nextjs-saas/TEMPLATE.md +1 -1
  54. package/.agent/skills/app-builder/templates/nextjs-static/TEMPLATE.md +1 -1
  55. package/.agent/skills/app-builder/templates/nuxt-app/TEMPLATE.md +1 -1
  56. package/.agent/skills/app-builder/templates/python-fastapi/TEMPLATE.md +1 -1
  57. package/.agent/skills/app-builder/templates/react-native-app/TEMPLATE.md +1 -1
  58. package/.agent/skills/appflow-wireframe/SKILL.md +12 -4
  59. package/.agent/skills/architecture/SKILL.md +12 -4
  60. package/.agent/skills/authentication-best-practices/SKILL.md +12 -4
  61. package/.agent/skills/bash-linux/SKILL.md +12 -4
  62. package/.agent/skills/behavioral-modes/SKILL.md +12 -4
  63. package/.agent/skills/brainstorming/SKILL.md +12 -4
  64. package/.agent/skills/building-native-ui/SKILL.md +12 -4
  65. package/.agent/skills/clean-code/SKILL.md +12 -4
  66. package/.agent/skills/code-review-checklist/SKILL.md +12 -4
  67. package/.agent/skills/config-validator/SKILL.md +12 -4
  68. package/.agent/skills/csharp-developer/SKILL.md +12 -4
  69. package/.agent/skills/data-validation-schemas/SKILL.md +290 -282
  70. package/.agent/skills/database-design/SKILL.md +202 -194
  71. package/.agent/skills/deployment-procedures/SKILL.md +12 -4
  72. package/.agent/skills/devops-engineer/SKILL.md +12 -4
  73. package/.agent/skills/devops-incident-responder/SKILL.md +12 -4
  74. package/.agent/skills/doc.md +1 -1
  75. package/.agent/skills/documentation-templates/SKILL.md +12 -4
  76. package/.agent/skills/edge-computing/SKILL.md +12 -4
  77. package/.agent/skills/error-resilience/SKILL.md +390 -382
  78. package/.agent/skills/extract-design-system/SKILL.md +12 -4
  79. package/.agent/skills/framer-motion-expert/SKILL.md +206 -199
  80. package/.agent/skills/frontend-design/SKILL.md +163 -155
  81. package/.agent/skills/game-design-expert/SKILL.md +12 -4
  82. package/.agent/skills/game-engineering-expert/SKILL.md +12 -4
  83. package/.agent/skills/geo-fundamentals/SKILL.md +12 -4
  84. package/.agent/skills/github-operations/SKILL.md +12 -4
  85. package/.agent/skills/gsap-core/SKILL.md +54 -48
  86. package/.agent/skills/gsap-frameworks/SKILL.md +54 -48
  87. package/.agent/skills/gsap-performance/SKILL.md +54 -48
  88. package/.agent/skills/gsap-plugins/SKILL.md +54 -48
  89. package/.agent/skills/gsap-react/SKILL.md +54 -48
  90. package/.agent/skills/gsap-scrolltrigger/SKILL.md +54 -48
  91. package/.agent/skills/gsap-timeline/SKILL.md +54 -48
  92. package/.agent/skills/gsap-utils/SKILL.md +54 -48
  93. package/.agent/skills/i18n-localization/SKILL.md +12 -4
  94. package/.agent/skills/intelligent-routing/SKILL.md +41 -33
  95. package/.agent/skills/knowledge-graph/SKILL.md +36 -0
  96. package/.agent/skills/lint-and-validate/SKILL.md +12 -4
  97. package/.agent/skills/llm-engineering/SKILL.md +12 -4
  98. package/.agent/skills/local-first/SKILL.md +12 -4
  99. package/.agent/skills/mcp-builder/SKILL.md +12 -4
  100. package/.agent/skills/mobile-design/SKILL.md +225 -217
  101. package/.agent/skills/monorepo-management/SKILL.md +296 -288
  102. package/.agent/skills/motion-engineering/SKILL.md +195 -187
  103. package/.agent/skills/nextjs-react-expert/SKILL.md +196 -188
  104. package/.agent/skills/nodejs-best-practices/SKILL.md +12 -4
  105. package/.agent/skills/observability/SKILL.md +12 -4
  106. package/.agent/skills/parallel-agents/SKILL.md +12 -4
  107. package/.agent/skills/performance-profiling/SKILL.md +12 -4
  108. package/.agent/skills/plan-writing/SKILL.md +12 -4
  109. package/.agent/skills/platform-engineer/SKILL.md +12 -4
  110. package/.agent/skills/playwright-best-practices/SKILL.md +12 -4
  111. package/.agent/skills/powershell-windows/SKILL.md +12 -4
  112. package/.agent/skills/project-idioms/SKILL.md +12 -4
  113. package/.agent/skills/python-patterns/SKILL.md +12 -4
  114. package/.agent/skills/python-pro/SKILL.md +285 -277
  115. package/.agent/skills/react-specialist/SKILL.md +239 -231
  116. package/.agent/skills/readme-builder/SKILL.md +12 -4
  117. package/.agent/skills/realtime-patterns/SKILL.md +12 -4
  118. package/.agent/skills/red-team-tactics/SKILL.md +12 -4
  119. package/.agent/skills/rust-pro/SKILL.md +12 -4
  120. package/.agent/skills/seo-fundamentals/SKILL.md +12 -4
  121. package/.agent/skills/server-management/SKILL.md +12 -4
  122. package/.agent/skills/shadcn-ui-expert/SKILL.md +12 -4
  123. package/.agent/skills/skill-creator/SKILL.md +12 -4
  124. package/.agent/skills/sql-pro/SKILL.md +12 -4
  125. package/.agent/skills/supabase-postgres-best-practices/SKILL.md +12 -4
  126. package/.agent/skills/swiftui-expert/SKILL.md +12 -4
  127. package/.agent/skills/systematic-debugging/SKILL.md +12 -4
  128. package/.agent/skills/tailwind-patterns/SKILL.md +12 -4
  129. package/.agent/skills/tdd-workflow/SKILL.md +12 -4
  130. package/.agent/skills/test-result-analyzer/SKILL.md +12 -4
  131. package/.agent/skills/testing-patterns/SKILL.md +12 -4
  132. package/.agent/skills/trend-researcher/SKILL.md +12 -4
  133. package/.agent/skills/typescript-advanced/SKILL.md +297 -289
  134. package/.agent/skills/ui-ux-pro-max/SKILL.md +12 -4
  135. package/.agent/skills/ui-ux-researcher/SKILL.md +12 -4
  136. package/.agent/skills/vue-expert/SKILL.md +237 -229
  137. package/.agent/skills/vulnerability-scanner/SKILL.md +12 -4
  138. package/.agent/skills/web-accessibility-auditor/SKILL.md +12 -4
  139. package/.agent/skills/web-design-guidelines/SKILL.md +12 -4
  140. package/.agent/skills/webapp-testing/SKILL.md +12 -4
  141. package/.agent/skills/whimsy-injector/SKILL.md +12 -4
  142. package/.agent/skills/workflow-optimizer/SKILL.md +12 -4
  143. package/.agent/workflows/audit.md +6 -6
  144. package/.agent/workflows/deploy.md +1 -1
  145. package/.agent/workflows/generate.md +23 -6
  146. package/.agent/workflows/session.md +5 -5
  147. package/.agent/workflows/swarm.md +2 -2
  148. package/README.md +242 -186
  149. package/bin/tribunal-kit.js +297 -57
  150. package/package.json +81 -77
  151. package/scripts/changelog.js +167 -0
  152. package/scripts/sync-version.js +81 -0
  153. package/scripts/validate-payload.js +73 -0
  154. package/.agent/scripts/__pycache__/auto_preview.cpython-311.pyc +0 -0
  155. package/.agent/scripts/__pycache__/bundle_analyzer.cpython-311.pyc +0 -0
  156. package/.agent/scripts/__pycache__/checklist.cpython-311.pyc +0 -0
  157. package/.agent/scripts/__pycache__/dependency_analyzer.cpython-311.pyc +0 -0
  158. package/.agent/scripts/__pycache__/security_scan.cpython-311.pyc +0 -0
  159. package/.agent/scripts/__pycache__/session_manager.cpython-311.pyc +0 -0
  160. package/.agent/scripts/__pycache__/skill_integrator.cpython-311.pyc +0 -0
  161. package/.agent/scripts/__pycache__/swarm_dispatcher.cpython-311.pyc +0 -0
  162. package/.agent/scripts/__pycache__/test_runner.cpython-311.pyc +0 -0
  163. package/.agent/scripts/__pycache__/verify_all.cpython-311.pyc +0 -0
  164. package/.agent/scripts/auto_preview.py +0 -180
  165. package/.agent/scripts/bundle_analyzer.py +0 -259
  166. package/.agent/scripts/case_law_manager.py +0 -755
  167. package/.agent/scripts/checklist.py +0 -209
  168. package/.agent/scripts/compress_skills.py +0 -167
  169. package/.agent/scripts/consolidate_skills.py +0 -173
  170. package/.agent/scripts/deep_compress.py +0 -202
  171. package/.agent/scripts/dependency_analyzer.py +0 -247
  172. package/.agent/scripts/lint_runner.py +0 -188
  173. package/.agent/scripts/minify_context.py +0 -80
  174. package/.agent/scripts/patch_skills_meta.py +0 -177
  175. package/.agent/scripts/patch_skills_output.py +0 -285
  176. package/.agent/scripts/schema_validator.py +0 -279
  177. package/.agent/scripts/security_scan.py +0 -224
  178. package/.agent/scripts/session_manager.py +0 -261
  179. package/.agent/scripts/skill_evolution.py +0 -563
  180. package/.agent/scripts/skill_integrator.py +0 -234
  181. package/.agent/scripts/strengthen_skills.py +0 -220
  182. package/.agent/scripts/strip_tribunal.py +0 -41
  183. package/.agent/scripts/swarm_dispatcher.py +0 -350
  184. package/.agent/scripts/test_runner.py +0 -192
  185. package/.agent/scripts/test_swarm_dispatcher.py +0 -163
  186. package/.agent/scripts/verify_all.py +0 -195
@@ -0,0 +1,266 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * checklist.js — Priority-based project audit runner for the Tribunal Agent Kit.
4
+ *
5
+ * Runs a tiered audit sequence:
6
+ * Priority 1: Security
7
+ * Priority 2: Lint
8
+ * Priority 3: Schema validation
9
+ * Priority 4: Tests
10
+ * Priority 5: UX / Accessibility
11
+ * Priority 6: SEO
12
+ * Priority 7: Lighthouse / E2E (requires --url)
13
+ *
14
+ * Usage:
15
+ * node .agent/scripts/checklist.js .
16
+ * node .agent/scripts/checklist.js . --url http://localhost:3000
17
+ * node .agent/scripts/checklist.js . --skip security,seo
18
+ */
19
+
20
+ 'use strict';
21
+
22
+ const fs = require('fs');
23
+ const path = require('path');
24
+ const { execFileSync } = require('child_process');
25
+
26
+ // ━━━ ANSI color output ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
27
+ const RED = '\x1b[91m';
28
+ const GREEN = '\x1b[92m';
29
+ const YELLOW = '\x1b[93m';
30
+ const BLUE = '\x1b[94m';
31
+ const BOLD = '\x1b[1m';
32
+ const RESET = '\x1b[0m';
33
+
34
+
35
+ function printHeader(title) {
36
+ console.log(`\n${BOLD}${BLUE}━━━ ${title} ━━━${RESET}`);
37
+ }
38
+
39
+ function printOk(msg) {
40
+ console.log(` ${GREEN}āœ… ${msg}${RESET}`);
41
+ }
42
+
43
+ function printFail(msg) {
44
+ console.log(` ${RED}āŒ ${msg}${RESET}`);
45
+ }
46
+
47
+ function printSkip(msg) {
48
+ console.log(` ${YELLOW}ā­ļø Skipped: ${msg}${RESET}`);
49
+ }
50
+
51
+
52
+ /**
53
+ * Run a shell command and return true if it exits with code 0.
54
+ * @param {string} label - Human-readable label for the check.
55
+ * @param {string[]} cmd - Command and arguments array.
56
+ * @param {string} cwd - Working directory.
57
+ * @returns {boolean}
58
+ */
59
+ function runCheck(label, cmd, cwd) {
60
+ try {
61
+ execFileSync(cmd[0], cmd.slice(1), {
62
+ cwd,
63
+ stdio: 'pipe',
64
+ timeout: 60000,
65
+ encoding: 'utf8',
66
+ });
67
+ printOk(`${label} passed`);
68
+ return true;
69
+ } catch (err) {
70
+ if (err.code === 'ENOENT') {
71
+ printSkip(`${label} — command not found (tool not installed)`);
72
+ return true; // Don't block on tools that aren't installed
73
+ }
74
+ if (err.killed) {
75
+ printFail(`${label} — timed out after 60s`);
76
+ return false;
77
+ }
78
+ printFail(`${label} failed`);
79
+ const output = (err.stdout || '') + (err.stderr || '');
80
+ if (output.trim()) {
81
+ console.log(` ${output.trim().slice(0, 500)}`);
82
+ }
83
+ return false;
84
+ }
85
+ }
86
+
87
+
88
+ /**
89
+ * Scan for hardcoded secrets in source files.
90
+ * @param {string} projectRoot - Project root directory.
91
+ * @returns {boolean} True if no secrets found.
92
+ */
93
+ function checkSecrets(projectRoot) {
94
+ printHeader('Security — Secret Scan');
95
+ const dangerousPatterns = [
96
+ 'password=', 'secret=', 'api_key=',
97
+ 'apikey=', 'auth_token=', 'private_key=',
98
+ ];
99
+ let foundIssues = false;
100
+ const sourceExtensions = new Set(['.ts', '.tsx', '.js', '.jsx', '.py', '.env']);
101
+ const skipDirs = new Set(['node_modules', '.git', '.agent', 'dist', '__pycache__']);
102
+
103
+ function walk(dir) {
104
+ let entries;
105
+ try { entries = fs.readdirSync(dir, { withFileTypes: true }); } catch { return; }
106
+
107
+ for (const entry of entries) {
108
+ const fullPath = path.join(dir, entry.name);
109
+ if (entry.isDirectory()) {
110
+ if (!skipDirs.has(entry.name)) walk(fullPath);
111
+ } else if (entry.isFile()) {
112
+ const ext = path.extname(entry.name);
113
+ if (!sourceExtensions.has(ext)) continue;
114
+ if (entry.name.startsWith('.env')) continue; // .env files are allowed
115
+
116
+ let content;
117
+ try { content = fs.readFileSync(fullPath, 'utf8'); } catch { continue; }
118
+
119
+ const lines = content.split('\n');
120
+ for (let i = 0; i < lines.length; i++) {
121
+ const lineLower = lines[i].toLowerCase().trim();
122
+ const hasPattern = dangerousPatterns.some(p => lineLower.includes(p));
123
+ if (hasPattern && lineLower.includes('=') && !lineLower.startsWith('#')) {
124
+ const rel = path.relative(projectRoot, fullPath);
125
+ printFail(`Possible secret: ${rel}:${i + 1} → ${lines[i].trim().slice(0, 80)}`);
126
+ foundIssues = true;
127
+ }
128
+ }
129
+ }
130
+ }
131
+ }
132
+
133
+ walk(projectRoot);
134
+
135
+ if (!foundIssues) {
136
+ printOk('No hardcoded secrets detected');
137
+ }
138
+ return !foundIssues;
139
+ }
140
+
141
+
142
+ /**
143
+ * Run all checklist tiers. Returns number of failures.
144
+ * @param {string} projectRoot - Project root.
145
+ * @param {string|null} url - URL for Lighthouse/E2E checks.
146
+ * @param {string[]} skip - Tiers to skip.
147
+ * @returns {number}
148
+ */
149
+ function runAll(projectRoot, url, skip) {
150
+ let failures = 0;
151
+
152
+ // Priority 1 — Security
153
+ if (!skip.includes('security')) {
154
+ printHeader('Priority 1 — Security');
155
+ if (!checkSecrets(projectRoot)) failures++;
156
+ } else {
157
+ printSkip('Security tier');
158
+ }
159
+
160
+ // Priority 2 — Lint
161
+ if (!skip.includes('lint')) {
162
+ printHeader('Priority 2 — Lint');
163
+ if (!runCheck('ESLint', ['npx', 'eslint', '.', '--max-warnings=0'], projectRoot)) failures++;
164
+ if (!runCheck('TypeScript', ['npx', 'tsc', '--noEmit'], projectRoot)) failures++;
165
+ } else {
166
+ printSkip('Lint tier');
167
+ }
168
+
169
+ // Priority 3 — Schema
170
+ if (!skip.includes('schema')) {
171
+ printHeader('Priority 3 — Schema');
172
+ printSkip('Schema check — run manually if you have DB migrations');
173
+ } else {
174
+ printSkip('Schema tier');
175
+ }
176
+
177
+ // Priority 4 — Tests
178
+ if (!skip.includes('tests')) {
179
+ printHeader('Priority 4 — Tests');
180
+ if (!runCheck('Test suite', ['npm', 'test', '--', '--passWithNoTests'], projectRoot)) failures++;
181
+ } else {
182
+ printSkip('Tests tier');
183
+ }
184
+
185
+ // Priority 5 — UX
186
+ if (!skip.includes('ux')) {
187
+ printHeader('Priority 5 — UX / Accessibility');
188
+ printSkip('UX audit — run /preview start then check manually or with Lighthouse');
189
+ } else {
190
+ printSkip('UX tier');
191
+ }
192
+
193
+ // Priority 6 — SEO
194
+ if (!skip.includes('seo')) {
195
+ printHeader('Priority 6 — SEO');
196
+ printSkip('SEO check — use /ui-ux-pro-max for SEO-sensitive pages');
197
+ } else {
198
+ printSkip('SEO tier');
199
+ }
200
+
201
+ // Priority 7 — Lighthouse / E2E
202
+ if (url && !skip.includes('e2e')) {
203
+ printHeader('Priority 7 — Lighthouse / E2E');
204
+ if (!runCheck('Playwright E2E', ['npx', 'playwright', 'test'], projectRoot)) failures++;
205
+ } else if (!url) {
206
+ printSkip('E2E / Lighthouse — pass --url to enable');
207
+ }
208
+
209
+ // ━━━ Summary ━━━
210
+ console.log(`\n${BOLD}━━━ Checklist Summary ━━━${RESET}`);
211
+ if (failures === 0) {
212
+ printOk('All checks passed — ready to proceed');
213
+ } else {
214
+ printFail(`${failures} tier(s) failed — fix Critical issues before proceeding`);
215
+ }
216
+
217
+ return failures;
218
+ }
219
+
220
+
221
+ /**
222
+ * Parse CLI arguments manually (no external dependencies).
223
+ */
224
+ function parseArgs(argv) {
225
+ const args = { path: null, url: null, skip: [] };
226
+ const raw = argv.slice(2);
227
+
228
+ for (let i = 0; i < raw.length; i++) {
229
+ if (raw[i] === '--url' && raw[i + 1]) {
230
+ args.url = raw[++i];
231
+ } else if (raw[i] === '--skip' && raw[i + 1]) {
232
+ args.skip = raw[++i].split(',').map(s => s.trim().toLowerCase()).filter(Boolean);
233
+ } else if (!raw[i].startsWith('--') && !args.path) {
234
+ args.path = raw[i];
235
+ }
236
+ }
237
+ return args;
238
+ }
239
+
240
+
241
+ function main() {
242
+ const args = parseArgs(process.argv);
243
+
244
+ if (!args.path) {
245
+ console.error(`Usage: node checklist.js <path> [--url <url>] [--skip security,lint,schema,tests,ux,seo,e2e]`);
246
+ process.exit(1);
247
+ }
248
+
249
+ const projectRoot = path.resolve(args.path);
250
+ if (!fs.existsSync(projectRoot) || !fs.statSync(projectRoot).isDirectory()) {
251
+ printFail(`Directory not found: ${projectRoot}`);
252
+ process.exit(1);
253
+ }
254
+
255
+ console.log(`${BOLD}Tribunal Checklist — ${projectRoot}${RESET}`);
256
+ const failures = runAll(projectRoot, args.url, args.skip);
257
+ process.exit(failures > 0 ? 1 : 0);
258
+ }
259
+
260
+
261
+ // ━━━ Exports for testing & programmatic use ━━━
262
+ module.exports = { runCheck, checkSecrets, runAll };
263
+
264
+ if (require.main === module) {
265
+ main();
266
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * colors.js
3
+ * Shared ANSI color constants for Tribunal Kit Node scripts.
4
+ */
5
+ 'use strict';
6
+
7
+ module.exports = {
8
+ GREEN: "\x1b[92m",
9
+ YELLOW: "\x1b[93m",
10
+ CYAN: "\x1b[96m",
11
+ RED: "\x1b[91m",
12
+ BLUE: "\x1b[94m",
13
+ MAGENTA: "\x1b[95m",
14
+ BOLD: "\x1b[1m",
15
+ DIM: "\x1b[2m",
16
+ RESET: "\x1b[0m"
17
+ };
@@ -0,0 +1,141 @@
1
+ #!/usr/bin/env node
2
+ // compress_skills.js - Aggressive token reduction for .agent/skills/**/*.md files
3
+
4
+ 'use strict';
5
+
6
+ const fs = require('fs');
7
+ const path = require('path');
8
+
9
+ const SECTION_PATTERNS = [
10
+ /^## šŸ›ļø Tribunal Integration[\s\S]*?(?=\n## |\n# |$)/gm,
11
+ /^## Tribunal Integration[\s\S]*?(?=\n## |\n# |$)/gm,
12
+ /^### āœ… Pre-Flight Self-Audit[\s\S]*?(?=\n## |\n### |\n# |$)/gm,
13
+ /^## Pre-Flight Self-Audit[\s\S]*?(?=\n## |\n# |$)/gm,
14
+ /^## Cross-Workflow Navigation[\s\S]*?(?=\n## |\n# |$)/gm,
15
+ /^## Output Format\s*\n```[\s\S]*?```\s*\n/gm,
16
+ /^## VBC Protocol[\s\S]*?(?=\n## |\n# |$)/gm,
17
+ /^## LLM Traps[\s\S]*?(?=\n## |\n# |$)/gm,
18
+ ];
19
+
20
+ const CHATTY_INTRO = /(^# .+\n)\n[A-Z][^#\n]{60,}\n[A-Z][^#\n]{40,}\n\n---/gm;
21
+
22
+ function stripChattyIntro(content) {
23
+ return content.replace(CHATTY_INTRO, '$1\n---');
24
+ }
25
+
26
+ const OBVIOUS_COMMENT = /^(\s*)(\/\/ (default for most properties|shorthand|number of repeats|default: \d+|spring tension|resistance|weight|approximate duration|deceleration rate)[^\n]*)\n/gm;
27
+
28
+ function stripObviousComments(content) {
29
+ return content.replace(OBVIOUS_COMMENT, '');
30
+ }
31
+
32
+ const PERF_TEXT_BLOCK = /^```\n(āœ… Use \w[^\n]*\n → [^\n]*\n\n?){3,}```\n/gm;
33
+
34
+ function compressPerfBlocks(content) {
35
+ return content.replace(PERF_TEXT_BLOCK, (match) => {
36
+ const lines = match.replace(/`|\n$/g, '').split('\n');
37
+ const bullets = [];
38
+ for (const line of lines) {
39
+ const stripped = line.trim();
40
+ if (stripped.startsWith('āœ…') || stripped.startsWith('āŒ')) {
41
+ bullets.push(`- ${stripped}`);
42
+ } else if (stripped.startsWith('→')) {
43
+ bullets[bullets.length - 1] += ` (${stripped.substring(1).trim()})`;
44
+ }
45
+ }
46
+ return bullets.join('\n') + '\n';
47
+ });
48
+ }
49
+
50
+ function collapseBlanks(content) {
51
+ return content.replace(/\n{3,}/g, '\n\n');
52
+ }
53
+
54
+ const FILLER_BEFORE_SECTION = /(^# .+\n\n)([A-Z][^\n]+\n){1,4}(\n---\n)/gm;
55
+
56
+ function removeFillerBetweenTitleAndHr(content) {
57
+ return content.replace(FILLER_BEFORE_SECTION, '$1$3');
58
+ }
59
+
60
+ const REDUNDANT_NOTE = /^\/\/ (motion\.\w+|Any HTML|Note:|Variant names propagate|\/\/ )[^\n]*\n/gm;
61
+
62
+ function stripRedundantNotes(content) {
63
+ return content.replace(REDUNDANT_NOTE, '');
64
+ }
65
+
66
+ function compressFile(filePath) {
67
+ const original = fs.readFileSync(filePath, 'utf8');
68
+ let content = original;
69
+
70
+ for (const pattern of SECTION_PATTERNS) {
71
+ content = content.replace(pattern, '');
72
+ }
73
+
74
+ content = stripChattyIntro(content);
75
+ content = removeFillerBetweenTitleAndHr(content);
76
+ content = stripObviousComments(content);
77
+ content = stripRedundantNotes(content);
78
+ content = compressPerfBlocks(content);
79
+ content = collapseBlanks(content);
80
+
81
+ const originalLen = Buffer.byteLength(original, 'utf8');
82
+ const newLen = Buffer.byteLength(content.trim() + '\n', 'utf8');
83
+
84
+ fs.writeFileSync(filePath, content.trim() + '\n', 'utf8');
85
+ return [originalLen, newLen, originalLen - newLen];
86
+ }
87
+
88
+ function main() {
89
+ const base = '.agent/skills';
90
+ if (!fs.existsSync(base)) {
91
+ console.error(`ERROR: '${base}' not found. Run from tribunal-kit root.`);
92
+ process.exit(1);
93
+ }
94
+
95
+ let totalOrig = 0;
96
+ let totalNew = 0;
97
+ const results = [];
98
+
99
+ function walkDir(dir) {
100
+ const items = fs.readdirSync(dir, { withFileTypes: true });
101
+ for (const item of items) {
102
+ const fpath = path.join(dir, item.name);
103
+ if (item.isDirectory()) {
104
+ walkDir(fpath);
105
+ } else if (item.name.endsWith('.md')) {
106
+ const [orig, newL, saved] = compressFile(fpath);
107
+ totalOrig += orig;
108
+ totalNew += newL;
109
+ if (saved > 0) {
110
+ results.push([saved, fpath]);
111
+ }
112
+ }
113
+ }
114
+ }
115
+
116
+ walkDir(base);
117
+ results.sort((a, b) => b[0] - a[0]);
118
+
119
+ console.log(`\n${'='.repeat(55)}`);
120
+ console.log(` Skill Compression Complete`);
121
+ console.log(`${'='.repeat(55)}`);
122
+ console.log(` Original : ${totalOrig} bytes (${Math.floor(totalOrig / 1024)}KB)`);
123
+ console.log(` After : ${totalNew} bytes (${Math.floor(totalNew / 1024)}KB)`);
124
+
125
+ const savedTotal = totalOrig - totalNew;
126
+ const pct = totalOrig ? (savedTotal / totalOrig * 100) : 0;
127
+ console.log(` Saved : ${savedTotal} bytes (${Math.floor(savedTotal / 1024)}KB) — ${pct.toFixed(1)}%`);
128
+ console.log(`\n Top savings:`);
129
+
130
+ for (const [saved, filePath] of results.slice(0, 15)) {
131
+ const parts = filePath.split(path.sep);
132
+ const skill = parts[parts.length - 2];
133
+ const fname = parts[parts.length - 1];
134
+ console.log(` -${Math.floor(saved / 1024).toString().padStart(2, ' ')}KB ${skill}/${fname}`);
135
+ }
136
+ console.log();
137
+ }
138
+
139
+ if (require.main === module) {
140
+ main();
141
+ }
@@ -0,0 +1,149 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * consolidate_skills.js
4
+ */
5
+
6
+ 'use strict';
7
+
8
+ const fs = require('fs');
9
+ const path = require('path');
10
+
11
+ const BASE = '.agent/skills';
12
+
13
+ const STRIP_PATTERNS = [
14
+ /^## šŸ›ļø Tribunal Integration.*?(?=\n## |$)/gms,
15
+ /^## Tribunal Integration.*?(?=\n## |$)/gms,
16
+ /^### āœ… Pre-Flight Self-Audit.*?(?=\n###|\n## |$)/gms,
17
+ /^## Pre-Flight Self-Audit.*?(?=\n## |$)/gms,
18
+ /^## Output Format\b.*?(?=\n## |$)/gms,
19
+ /^## šŸ”§ Runtime Scripts.*?(?=\n## |$)/gms,
20
+ /^## šŸ”“ MANDATORY.*?(?=\n## |$)/gms,
21
+ /^## āš ļø CRITICAL: ASK BEFORE ASSUMING.*?(?=\n## |$)/gms,
22
+ /^## šŸ“ CHECKPOINT \(MANDATORY.*?(?=\n## |$)/gms,
23
+ /^## Output Format.*?```\n[^`]*```\n?(?=\n## |$)/gms,
24
+ /^\*\*Execute these for validation.*?---\n/gms,
25
+ /^\*\*VBC \(Verification-Before-Completion\).*?\n/gms,
26
+ /^\*\*ā›” DO NOT start.*?---\n?/gms,
27
+ /^> 🧠 \*\*mobile-design.*?\n/gms,
28
+ /^> \*\*STOP.*?\n/gms,
29
+ ];
30
+
31
+ function adjustHeadings(content, offset = 1) {
32
+ const lines = content.split('\n');
33
+ const out = [];
34
+ for (let line of lines) {
35
+ const m = line.match(/^(#{1,5}) /);
36
+ if (m) {
37
+ const level = m[1].length;
38
+ const newLevel = Math.min(level + offset, 6);
39
+ line = '#'.repeat(newLevel) + line.substring(level);
40
+ }
41
+ out.push(line);
42
+ }
43
+ return out.join('\n');
44
+ }
45
+
46
+ function cleanContent(content) {
47
+ for (const p of STRIP_PATTERNS) {
48
+ content = content.replace(p, '');
49
+ }
50
+ content = content.replace(/\n{3,}/g, '\n\n');
51
+ return content.trim();
52
+ }
53
+
54
+ function extractFrontmatter(content) {
55
+ const m = content.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n/);
56
+ if (m) {
57
+ return [m[1], content.substring(m[0].length)];
58
+ }
59
+ return ['', content];
60
+ }
61
+
62
+ function consolidate(skillDir) {
63
+ const skillName = path.basename(skillDir);
64
+ const mainPath = path.join(skillDir, 'SKILL.md');
65
+ if (!fs.existsSync(mainPath)) return false;
66
+
67
+ const files = fs.readdirSync(skillDir);
68
+ const subFiles = files.filter(f => f.endsWith('.md') && f !== 'SKILL.md').sort();
69
+
70
+ if (subFiles.length === 0) return false;
71
+
72
+ console.log(`\n → Consolidating: ${skillName} (${subFiles.length} sub-files)`);
73
+
74
+ const mainContent = fs.readFileSync(mainPath, 'utf8');
75
+ let [frontmatter, mainBody] = extractFrontmatter(mainContent);
76
+
77
+ const fmLines = frontmatter.split('\n');
78
+ const newFm = [];
79
+ for (const line of fmLines) {
80
+ if (line.startsWith('version:')) newFm.push('version: 3.1.0');
81
+ else if (line.startsWith('last-updated:')) newFm.push('last-updated: 2026-04-06');
82
+ else newFm.push(line);
83
+ }
84
+ frontmatter = newFm.join('\n');
85
+
86
+ mainBody = cleanContent(mainBody);
87
+ mainBody = mainBody.replace(/\|.*?\.md.*?\|.*?\|.*?\|\n/g, '');
88
+ mainBody = mainBody.replace(/^\|[-| ]+\|\n/gm, '');
89
+ mainBody = mainBody.replace(/\n{3,}/g, '\n\n');
90
+
91
+ const mergedSections = [];
92
+ for (const fname of subFiles) {
93
+ const fpath = path.join(skillDir, fname);
94
+ const raw = fs.readFileSync(fpath, 'utf8');
95
+ let [, body] = extractFrontmatter(raw);
96
+ body = cleanContent(body);
97
+ body = adjustHeadings(body, 1);
98
+ if (body.trim()) {
99
+ mergedSections.push(body.trim());
100
+ }
101
+ }
102
+
103
+ let combined = `---\n${frontmatter}\n---\n\n${mainBody}`;
104
+ if (mergedSections.length > 0) {
105
+ combined += '\n\n---\n\n' + mergedSections.join('\n\n---\n\n');
106
+ }
107
+
108
+ combined = combined.replace(/\n{3,}/g, '\n\n');
109
+ combined = combined.trim() + '\n';
110
+
111
+ let totalSubBytes = 0;
112
+ for (const f of subFiles) totalSubBytes += fs.statSync(path.join(skillDir, f)).size;
113
+ console.log(` Sub-files total: ${Math.floor(totalSubBytes / 1024)}KB`);
114
+
115
+ fs.writeFileSync(mainPath, combined, 'utf8');
116
+ const newSize = fs.statSync(mainPath).size;
117
+ console.log(` New SKILL.md: ${Math.floor(newSize / 1024)}KB (from ${Math.floor(Buffer.byteLength(mainContent, 'utf8') / 1024)}KB main + ${Math.floor(totalSubBytes / 1024)}KB subs → ${Math.floor(newSize / 1024)}KB)`);
118
+
119
+ for (const fname of subFiles) {
120
+ fs.unlinkSync(path.join(skillDir, fname));
121
+ console.log(` Deleted: ${fname}`);
122
+ }
123
+
124
+ return true;
125
+ }
126
+
127
+ function main() {
128
+ const target = process.argv.length > 2 ? process.argv[2] : null;
129
+
130
+ let processed = 0;
131
+ if (!fs.existsSync(BASE)) return;
132
+
133
+ for (const skillName of fs.readdirSync(BASE)) {
134
+ const skillDir = path.join(BASE, skillName);
135
+ if (!fs.statSync(skillDir).isDirectory()) continue;
136
+ if (target && skillName !== target) continue;
137
+ if (consolidate(skillDir)) processed++;
138
+ }
139
+
140
+ if (processed === 0) {
141
+ console.log('No skills with sub-files found (or target not matched).');
142
+ } else {
143
+ console.log(`\nāœ… Consolidated ${processed} skills.`);
144
+ }
145
+ }
146
+
147
+ if (require.main === module) {
148
+ main();
149
+ }