tribunal-kit 4.4.3 → 4.4.4

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.
@@ -1,149 +0,0 @@
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
- }
@@ -1,150 +0,0 @@
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
- }
@@ -1,156 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * patch_skills_meta.js — Injects version/freshness metadata into SKILL.md frontmatter.
4
- */
5
-
6
- 'use strict';
7
-
8
- const fs = require('fs');
9
- const path = require('path');
10
-
11
- const { RED, GREEN, YELLOW, BLUE, BOLD, RESET } = require('./colors.js');
12
-
13
- const META_FIELDS = {
14
- "version": "1.0.0",
15
- "last-updated": "2026-03-12",
16
- "applies-to-model": "gemini-2.5-pro, claude-3-7-sonnet"
17
- };
18
-
19
- function header(title) { console.log(`\n${BOLD}${BLUE}━━━ ${title} ━━━${RESET}`); }
20
- function ok(msg) { console.log(` ${GREEN}✅ ${msg}${RESET}`); }
21
- function skip(msg) { console.log(` ${YELLOW}⏭️ ${msg}${RESET}`); }
22
- function warn(msg) { console.log(` ${YELLOW}⚠️ ${msg}${RESET}`); }
23
- function fail(msg) { console.log(` ${RED}❌ ${msg}${RESET}`); }
24
-
25
- function patchFrontmatter(content) {
26
- const added = [];
27
- const fmMatch = content.match(/^---\r?\n([\s\S]*?)\r?\n---/);
28
-
29
- if (!fmMatch) {
30
- const newFmLines = ["---"];
31
- for (const [key, value] of Object.entries(META_FIELDS)) {
32
- newFmLines.push(`${key}: ${value}`);
33
- added.push(key);
34
- }
35
- newFmLines.push("---");
36
- return [newFmLines.join("\n") + "\n\n" + content, added];
37
- }
38
-
39
- const fmText = fmMatch[1];
40
- const fmEnd = fmMatch[0].length;
41
-
42
- const existingKeys = new Set();
43
- const lines = fmText.split("\n");
44
- for (const line of lines) {
45
- const m = line.match(/^([a-zA-Z0-9_-]+)\s*:/);
46
- if (m) existingKeys.add(m[1]);
47
- }
48
-
49
- const newFmLines = fmText.trimEnd().split("\n");
50
- for (const [key, value] of Object.entries(META_FIELDS)) {
51
- if (!existingKeys.has(key)) {
52
- newFmLines.push(`${key}: ${value}`);
53
- added.push(key);
54
- }
55
- }
56
-
57
- if (added.length === 0) return [content, []];
58
-
59
- const patched = "---\n" + newFmLines.join("\n") + "\n---" + content.slice(fmEnd);
60
- return [patched, added];
61
- }
62
-
63
- function processSkill(skillPath, dryRun) {
64
- const skillName = path.basename(path.dirname(skillPath));
65
- try {
66
- const content = fs.readFileSync(skillPath, 'utf8');
67
- const [patched, added] = patchFrontmatter(content);
68
-
69
- if (added.length === 0) {
70
- skip(`${skillName} — all meta fields present`);
71
- return "skipped";
72
- }
73
-
74
- const fieldList = added.join(', ');
75
- if (dryRun) {
76
- warn(`[DRY RUN] ${skillName} — would add: ${fieldList}`);
77
- return "updated";
78
- }
79
-
80
- fs.writeFileSync(skillPath, patched, 'utf8');
81
- ok(`${skillName} — added: ${fieldList}`);
82
- return "updated";
83
- } catch (e) {
84
- fail(`${skillName} — ${e.message}`);
85
- return "error";
86
- }
87
- }
88
-
89
- function main() {
90
- const args = process.argv.slice(2);
91
- let targetPath = null;
92
- let dryRun = false;
93
- let skillArg = null;
94
-
95
- let i = 0;
96
- while (i < args.length) {
97
- if (args[i] === '--dry-run') dryRun = true;
98
- else if (args[i] === '--skill' && i + 1 < args.length) skillArg = args[++i];
99
- else if (args[i] === '-h' || args[i] === '--help') {
100
- console.log("Usage: node patch_skills_meta.js <path> [--dry-run] [--skill <name>]");
101
- process.exit(0);
102
- } else if (!args[i].startsWith('-') && !targetPath) {
103
- targetPath = args[i];
104
- }
105
- i++;
106
- }
107
-
108
- if (!targetPath) {
109
- console.log("Usage: node patch_skills_meta.js <path> [--dry-run] [--skill <name>]");
110
- process.exit(1);
111
- }
112
-
113
- const projectRoot = path.resolve(targetPath);
114
- const skillsDir = path.join(projectRoot, ".agent", "skills");
115
-
116
- if (!fs.existsSync(skillsDir) || !fs.statSync(skillsDir).isDirectory()) {
117
- fail(`Skills directory not found: ${skillsDir}`);
118
- process.exit(1);
119
- }
120
-
121
- console.log(`${BOLD}Tribunal — patch_skills_meta.js${RESET}`);
122
- if (dryRun) console.log(` ${YELLOW}DRY RUN — no files will be written${RESET}`);
123
- console.log(`Skills dir: ${skillsDir}\n`);
124
-
125
- const counts = { updated: 0, skipped: 0, error: 0 };
126
- header("Patching Frontmatter");
127
-
128
- const dirs = fs.readdirSync(skillsDir, { withFileTypes: true });
129
- dirs.sort((a, b) => a.name.localeCompare(b.name));
130
-
131
- for (const dir of dirs) {
132
- if (!dir.isDirectory()) continue;
133
- if (skillArg && dir.name !== skillArg) continue;
134
-
135
- const skillMd = path.join(skillsDir, dir.name, "SKILL.md");
136
- if (!fs.existsSync(skillMd)) {
137
- warn(`${dir.name} — no SKILL.md found`);
138
- continue;
139
- }
140
-
141
- const result = processSkill(skillMd, dryRun);
142
- counts[result]++;
143
- }
144
-
145
- console.log(`\n${BOLD}━━━ Summary ━━━${RESET}`);
146
- console.log(` ${GREEN}✅ Updated: ${counts.updated}${RESET}`);
147
- console.log(` ${YELLOW}⏭️ Skipped: ${counts.skipped}${RESET}`);
148
- if (counts.error > 0) console.log(` ${RED}❌ Errors: ${counts.error}${RESET}`);
149
- if (dryRun) console.log(` ${YELLOW}(dry-run — nothing written)${RESET}`);
150
-
151
- process.exit(counts.error > 0 ? 1 : 0);
152
- }
153
-
154
- if (require.main === module) {
155
- main();
156
- }
@@ -1,244 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * patch_skills_output.js — Adds structured Output Format sections to SKILL.md files.
4
- */
5
-
6
- 'use strict';
7
-
8
- const fs = require('fs');
9
- const path = require('path');
10
-
11
- const { RED, GREEN, YELLOW, BLUE, BOLD, RESET } = require('./colors.js');
12
-
13
- const CODE_QUALITY_TEMPLATE = `\\
14
- ## Output Format
15
-
16
- When this skill produces or reviews code, structure your output as follows:
17
-
18
- \`\`\`
19
- ━━━ {skill_name} Report ━━━━━━━━━━━━━━━━━━━━━━━━
20
- Skill: {skill_name}
21
- Language: [detected language / framework]
22
- Scope: [N files · N functions]
23
- ─────────────────────────────────────────────────
24
- ✅ Passed: [checks that passed, or "All clean"]
25
- ⚠️ Warnings: [non-blocking issues, or "None"]
26
- ❌ Blocked: [blocking issues requiring fix, or "None"]
27
- ─────────────────────────────────────────────────
28
- VBC status: PENDING → VERIFIED
29
- Evidence: [test output / lint pass / compile success]
30
- \`\`\`
31
-
32
- **VBC (Verification-Before-Completion) is mandatory.**
33
- Do not mark status as VERIFIED until concrete terminal evidence is provided.
34
-
35
- `;
36
-
37
- const DECISION_CARD_TEMPLATE = `\\
38
- ## Output Format
39
-
40
- When this skill produces a recommendation or design decision, structure your output as:
41
-
42
- \`\`\`
43
- ━━━ {skill_name} Recommendation ━━━━━━━━━━━━━━━━
44
- Decision: [what was chosen / proposed]
45
- Rationale: [why — one concise line]
46
- Trade-offs: [what is consciously accepted]
47
- Next action: [concrete next step for the user]
48
- ─────────────────────────────────────────────────
49
- Pre-Flight: ✅ All checks passed
50
- or ❌ [blocking item that must be resolved first]
51
- \`\`\`
52
-
53
- `;
54
-
55
- const GENERIC_TEMPLATE = `\\
56
- ## Output Format
57
-
58
- When this skill completes a task, structure your output as:
59
-
60
- \`\`\`
61
- ━━━ {skill_name} Output ━━━━━━━━━━━━━━━━━━━━━━━━
62
- Task: [what was performed]
63
- Result: [outcome summary — one line]
64
- ─────────────────────────────────────────────────
65
- Checks: ✅ [N passed] · ⚠️ [N warnings] · ❌ [N blocked]
66
- VBC status: PENDING → VERIFIED
67
- Evidence: [link to terminal output, test result, or file diff]
68
- \`\`\`
69
-
70
- `;
71
-
72
- const CODE_GEN_SKILLS = new Set([
73
- "python-pro", "clean-code", "dotnet-core-expert", "rust-pro",
74
- "nextjs-react-expert", "vue-expert", "react-specialist",
75
- "csharp-developer", "nodejs-best-practices", "python-patterns",
76
- "tailwind-patterns", "bash-linux", "powershell-windows",
77
- "llm-engineering", "mcp-builder", "game-development",
78
- "edge-computing", "local-first", "realtime-patterns",
79
- "tdd-workflow", "testing-patterns", "lint-and-validate",
80
- ]);
81
-
82
- const DECISION_SKILLS = new Set([
83
- "api-patterns", "database-design", "architecture", "observability",
84
- "devops-engineer", "platform-engineer", "deployment-procedures",
85
- "server-management", "security-auditor", "vulnerability-scanner",
86
- "red-team-tactics", "performance-profiling", "i18n-localization",
87
- "geo-fundamentals", "seo-fundamentals", "sql-pro",
88
- "brainstorming", "plan-writing", "behavioral-modes",
89
- "app-builder", "intelligent-routing", "mobile-design",
90
- "frontend-design", "ui-ux-pro-max", "ui-ux-researcher",
91
- "web-design-guidelines", "trend-researcher",
92
- ]);
93
-
94
- const ALREADY_HAVE_OUTPUT = new Set([
95
- "whimsy-injector", "workflow-optimizer",
96
- ]);
97
-
98
- const EXISTING_OUTPUT_MARKERS = [
99
- "## Output Format",
100
- "## Output\n",
101
- "## Report Format",
102
- "## Output Card",
103
- "Whimsy Injection Report",
104
- "Workflow Optimization Report",
105
- ];
106
-
107
- function getTemplate(skillName) {
108
- if (CODE_GEN_SKILLS.has(skillName)) return CODE_QUALITY_TEMPLATE;
109
- if (DECISION_SKILLS.has(skillName)) return DECISION_CARD_TEMPLATE;
110
- return GENERIC_TEMPLATE;
111
- }
112
-
113
- function hasOutputSection(content) {
114
- return EXISTING_OUTPUT_MARKERS.some(m => content.includes(m));
115
- }
116
-
117
- function getSkillNameFromFrontmatter(content) {
118
- const match = content.match(/^name:\s*(.+)$/m);
119
- return match ? match[1].trim() : null;
120
- }
121
-
122
- function buildBlock(template, skillName) {
123
- const display = skillName.split('-').map(word => word.charAt(0).toUpperCase() + word.slice(1)).join(' ');
124
- // Handle the slash escaping issue using regular replace
125
- const tplStr = template.replace(/^\\/, '');
126
- return tplStr.replace(/{skill_name}/g, display);
127
- }
128
-
129
- function injectOutputBlock(content, block) {
130
- const tribunalMarkers = [
131
- "## 🏛️ Tribunal Integration",
132
- "## Tribunal Integration",
133
- ];
134
- for (const marker of tribunalMarkers) {
135
- const idx = content.indexOf(marker);
136
- if (idx !== -1) {
137
- return content.substring(0, idx) + block + "\n---\n\n" + content.substring(idx);
138
- }
139
- }
140
- return content.trimEnd() + "\n\n---\n\n" + block;
141
- }
142
-
143
- function header(title) { console.log(`\n${BOLD}${BLUE}━━━ ${title} ━━━${RESET}`); }
144
- function ok(msg) { console.log(` ${GREEN}✅ ${msg}${RESET}`); }
145
- function skip(msg) { console.log(` ${YELLOW}⏭️ ${msg}${RESET}`); }
146
- function warn(msg) { console.log(` ${YELLOW}⚠️ ${msg}${RESET}`); }
147
- function fail(msg) { console.log(` ${RED}❌ ${msg}${RESET}`); }
148
-
149
- function processSkill(skillDir, dryRun) {
150
- const skillName = path.basename(skillDir);
151
- const skillMd = path.join(skillDir, "SKILL.md");
152
-
153
- if (!fs.existsSync(skillMd)) return "skipped";
154
-
155
- try {
156
- const content = fs.readFileSync(skillMd, 'utf8');
157
-
158
- if (ALREADY_HAVE_OUTPUT.has(skillName) || hasOutputSection(content)) {
159
- skip(`${skillName} — output format already present`);
160
- return "skipped";
161
- }
162
-
163
- const displayName = getSkillNameFromFrontmatter(content) || skillName;
164
- const template = getTemplate(skillName);
165
- const block = buildBlock(template, displayName);
166
- const patched = injectOutputBlock(content, block);
167
-
168
- const templateType = CODE_GEN_SKILLS.has(skillName) ? "Code Quality" : (DECISION_SKILLS.has(skillName) ? "Decision Card" : "Generic");
169
-
170
- if (dryRun) {
171
- warn(`[DRY RUN] ${skillName} — would add Output Format (${templateType})`);
172
- return "updated";
173
- }
174
-
175
- fs.writeFileSync(skillMd, patched, 'utf8');
176
- ok(`${skillName} — added Output Format (${templateType})`);
177
- return "updated";
178
- } catch (e) {
179
- fail(`${skillName} — ${e.message}`);
180
- return "error";
181
- }
182
- }
183
-
184
- function main() {
185
- const args = process.argv.slice(2);
186
- let targetPath = null;
187
- let dryRun = false;
188
- let skillArg = null;
189
-
190
- let i = 0;
191
- while (i < args.length) {
192
- if (args[i] === '--dry-run') dryRun = true;
193
- else if (args[i] === '--skill' && i + 1 < args.length) skillArg = args[++i];
194
- else if (args[i] === '-h' || args[i] === '--help') {
195
- console.log("Usage: node patch_skills_output.js <path> [--dry-run] [--skill <name>]");
196
- process.exit(0);
197
- } else if (!args[i].startsWith('-') && !targetPath) {
198
- targetPath = args[i];
199
- }
200
- i++;
201
- }
202
-
203
- if (!targetPath) {
204
- console.log("Usage: node patch_skills_output.js <path> [--dry-run] [--skill <name>]");
205
- process.exit(1);
206
- }
207
-
208
- const projectRoot = path.resolve(targetPath);
209
- const skillsDir = path.join(projectRoot, ".agent", "skills");
210
-
211
- if (!fs.existsSync(skillsDir) || !fs.statSync(skillsDir).isDirectory()) {
212
- fail(`Skills directory not found: ${skillsDir}`);
213
- process.exit(1);
214
- }
215
-
216
- console.log(`${BOLD}Tribunal — patch_skills_output.js${RESET}`);
217
- if (dryRun) console.log(` ${YELLOW}DRY RUN — no files will be written${RESET}`);
218
- console.log(`Skills dir: ${skillsDir}\n`);
219
-
220
- const counts = { updated: 0, skipped: 0, error: 0 };
221
- header("Patching Output Format Sections");
222
-
223
- const dirs = fs.readdirSync(skillsDir, { withFileTypes: true });
224
- dirs.sort((a, b) => a.name.localeCompare(b.name));
225
-
226
- for (const dir of dirs) {
227
- if (!dir.isDirectory()) continue;
228
- if (skillArg && dir.name !== skillArg) continue;
229
- const result = processSkill(path.join(skillsDir, dir.name), dryRun);
230
- counts[result]++;
231
- }
232
-
233
- console.log(`\n${BOLD}━━━ Summary ━━━${RESET}`);
234
- console.log(` ${GREEN}✅ Updated: ${counts.updated}${RESET}`);
235
- console.log(` ${YELLOW}⏭️ Skipped: ${counts.skipped}${RESET}`);
236
- if (counts.error > 0) console.log(` ${RED}❌ Errors: ${counts.error}${RESET}`);
237
- if (dryRun) console.log(` ${YELLOW}(dry-run — nothing written)${RESET}`);
238
-
239
- process.exit(counts.error > 0 ? 1 : 0);
240
- }
241
-
242
- if (require.main === module) {
243
- main();
244
- }