tribunal-kit 5.7.0 → 5.8.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 (59) hide show
  1. package/.agent/ARCHITECTURE.md +6 -7
  2. package/.agent/agents/frontend-reviewer.md +13 -0
  3. package/.agent/agents/frontend-specialist.md +14 -0
  4. package/.agent/agents/logic-reviewer.md +11 -0
  5. package/.agent/agents/orchestrator.md +15 -0
  6. package/.agent/agents/project-planner.md +5 -0
  7. package/.agent/agents/security-auditor.md +13 -0
  8. package/.agent/agents/ui-ux-auditor.md +7 -31
  9. package/.agent/history/memory/.memory.idx +1693 -0
  10. package/.agent/history/memory/MEMORY.md +123 -0
  11. package/.agent/routing_index.json +694 -714
  12. package/.agent/rules/GEMINI.md +88 -13
  13. package/.agent/scripts/_colors.js +131 -89
  14. package/.agent/scripts/_utils.js +163 -128
  15. package/.agent/scripts/auto_preview.js +207 -197
  16. package/.agent/scripts/bundle_analyzer.js +227 -192
  17. package/.agent/scripts/case_law_manager.js +991 -689
  18. package/.agent/scripts/checklist.js +233 -190
  19. package/.agent/scripts/context_broker.js +930 -605
  20. package/.agent/scripts/dependency_analyzer.js +275 -184
  21. package/.agent/scripts/graph_builder.js +412 -341
  22. package/.agent/scripts/graph_visualizer.js +392 -390
  23. package/.agent/scripts/graph_zoom.js +198 -156
  24. package/.agent/scripts/inner_loop_validator.js +523 -445
  25. package/.agent/scripts/lint_runner.js +199 -157
  26. package/.agent/scripts/marathon_harness.js +819 -661
  27. package/.agent/scripts/minify_context.js +115 -100
  28. package/.agent/scripts/mutation_runner.js +321 -280
  29. package/.agent/scripts/prompt_compiler.js +62 -42
  30. package/.agent/scripts/schema_validator.js +373 -280
  31. package/.agent/scripts/security_scan.js +333 -190
  32. package/.agent/scripts/session_manager.js +306 -270
  33. package/.agent/scripts/skill_evolution.js +810 -637
  34. package/.agent/scripts/skill_integrator.js +327 -307
  35. package/.agent/scripts/strengthen_skills.js +203 -193
  36. package/.agent/scripts/swarm_dispatcher.js +558 -457
  37. package/.agent/scripts/test_runner.js +178 -152
  38. package/.agent/scripts/verify_all.js +200 -168
  39. package/.agent/skills/fabel-protocol/SKILL.md +271 -0
  40. package/.agent/skills/thinking-protocol/SKILL.md +27 -0
  41. package/.agent/workflows/generate.md +2 -1
  42. package/.agent/workflows/tribunal-full.md +4 -3
  43. package/.agent/workflows/tribunal-speed.md +1 -1
  44. package/README.md +184 -58
  45. package/bin/mcp-server.js +496 -173
  46. package/bin/tribunal-kit.js +1245 -987
  47. package/bin/wrapper.js +108 -74
  48. package/dist/cli.js +44 -0
  49. package/dist/commands/align.js +201 -0
  50. package/dist/commands/case.js +23 -0
  51. package/dist/commands/compile.js +84 -0
  52. package/dist/commands/init.js +42 -0
  53. package/dist/commands/learn.js +57 -0
  54. package/dist/commands/memory.js +456 -0
  55. package/package.json +22 -10
  56. package/scripts/benchmark.js +162 -125
  57. package/scripts/changelog.js +196 -168
  58. package/scripts/sync-version.js +94 -81
  59. package/scripts/validate-payload.js +85 -78
@@ -1,270 +1,306 @@
1
- #!/usr/bin/env node
2
- /**
3
- * session_manager.js — Agent session state tracking for multi-conversation work.
4
- *
5
- * Usage:
6
- * node .agent/scripts/session_manager.js save "working on auth"
7
- * node .agent/scripts/session_manager.js load
8
- * node .agent/scripts/session_manager.js show
9
- * node .agent/scripts/session_manager.js clear
10
- * node .agent/scripts/session_manager.js status
11
- * node .agent/scripts/session_manager.js tag <label>
12
- * node .agent/scripts/session_manager.js list [--all]
13
- * node .agent/scripts/session_manager.js export [--stdout]
14
- */
15
-
16
- 'use strict';
17
-
18
- const fs = require('fs');
19
- const path = require('path');
20
-
21
- const STATE_FILE = ".agent_session.json";
22
-
23
- const { GREEN, YELLOW, BLUE, CYAN, RED, BOLD, RESET } = require('./_colors');
24
-
25
- const VALID_COMMANDS = new Set(["save", "load", "show", "clear", "status", "tag", "list", "export"]);
26
- const LIST_PAGE_SIZE = 10;
27
-
28
- function loadState() {
29
- if (!fs.existsSync(STATE_FILE)) return {};
30
- try {
31
- const content = fs.readFileSync(STATE_FILE, 'utf8');
32
- return JSON.parse(content);
33
- } catch {
34
- return {};
35
- }
36
- }
37
-
38
- function saveState(state) {
39
- fs.writeFileSync(STATE_FILE, JSON.stringify(state, null, 2), 'utf8');
40
- }
41
-
42
- function cmdSave(note) {
43
- const state = loadState();
44
- const entry = {
45
- timestamp: new Date().toISOString(),
46
- note: note,
47
- session: (state.history || []).length + 1,
48
- tags: []
49
- };
50
- if (!state.history) state.history = [];
51
- state.history.push(entry);
52
- state.current = entry;
53
- saveState(state);
54
-
55
- console.log(`${GREEN}✅ Session saved:${RESET} ${note}`);
56
- console.log(` Time: ${entry.timestamp}`);
57
- console.log(` Session: #${entry.session}`);
58
- }
59
-
60
- function cmdLoad() {
61
- const state = loadState();
62
- const current = state.current;
63
- if (!current) {
64
- console.log(`${YELLOW}No active session — use 'save' first.${RESET}`);
65
- return;
66
- }
67
- const tagsStr = (current.tags || []).join(", ") || "none";
68
- console.log(`${BOLD}Current session:${RESET}`);
69
- console.log(` Session: #${current.session}`);
70
- console.log(` Time: ${current.timestamp}`);
71
- console.log(` Note: ${current.note}`);
72
- console.log(` Tags: ${tagsStr}`);
73
- }
74
-
75
- function cmdShow() {
76
- const state = loadState();
77
- const history = state.history || [];
78
- if (!history.length) {
79
- console.log(`${YELLOW}No session history.${RESET}`);
80
- return;
81
- }
82
- console.log(`${BOLD}Session History (${history.length} total):${RESET}`);
83
- const recent = history.slice(-10).reverse();
84
- for (const entry of recent) {
85
- const tagsStr = (entry.tags || []).join(", ") || "";
86
- const tagsDisplay = tagsStr ? ` [${tagsStr}]` : "";
87
- console.log(`\n ${BLUE}#${entry.session}${RESET} — ${entry.timestamp.slice(0, 16)}${tagsDisplay}`);
88
- console.log(` ${entry.note}`);
89
- }
90
- }
91
-
92
- function cmdClear() {
93
- if (fs.existsSync(STATE_FILE)) {
94
- fs.unlinkSync(STATE_FILE);
95
- console.log(`${GREEN}✅ Session state cleared.${RESET}`);
96
- } else {
97
- console.log(`${YELLOW}No session file found nothing to clear.${RESET}`);
98
- }
99
- }
100
-
101
- function cmdStatus() {
102
- const state = loadState();
103
- const history = state.history || [];
104
- const current = state.current;
105
-
106
- if (!history.length) {
107
- console.log(`${YELLOW}No session history — use 'save' to start tracking.${RESET}`);
108
- return;
109
- }
110
-
111
- const total = history.length;
112
- const recent = history.slice(-3).reverse();
113
-
114
- console.log(`\n${BOLD}${CYAN}━━━ Session Status ━━━━━━━━━━━━━━━━━━━━━━━━${RESET}`);
115
- console.log(` Total sessions: ${total}`);
116
- if (current) {
117
- console.log(` Active: #${current.session} — ${current.note.slice(0, 60)}`);
118
- }
119
- console.log(`\n${BOLD} Last 3 sessions:${RESET}`);
120
- for (const entry of recent) {
121
- const tagsStr = (entry.tags || []).join(", ") || "";
122
- const tagsDisplay = tagsStr ? ` [${tagsStr}]` : "";
123
- const ts = entry.timestamp.slice(0, 16);
124
- console.log(` ${BLUE}#${entry.session}${RESET} ${ts}${tagsDisplay}`);
125
- console.log(` ${entry.note.slice(0, 70)}`);
126
- }
127
- console.log(`${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${RESET}\n`);
128
- }
129
-
130
- function cmdTag(label) {
131
- if (!label) {
132
- console.log(`${RED}Error: provide a tag label. Example: node session_manager.js tag v2-feature${RESET}`);
133
- process.exit(1);
134
- }
135
- const state = loadState();
136
- const current = state.current;
137
- if (!current) {
138
- console.log(`${YELLOW}No active session use 'save' first before tagging.${RESET}`);
139
- process.exit(1);
140
- }
141
- if (!current.tags) current.tags = [];
142
- if (current.tags.includes(label)) {
143
- console.log(`${YELLOW}Tag '${label}' already exists on session #${current.session}.${RESET}`);
144
- return;
145
- }
146
-
147
- current.tags.push(label);
148
- state.current = current;
149
-
150
- if (state.history) {
151
- for (const entry of state.history) {
152
- if (entry.session === current.session) {
153
- if (!entry.tags) entry.tags = [];
154
- if (!entry.tags.includes(label)) {
155
- entry.tags.push(label);
156
- }
157
- break;
158
- }
159
- }
160
- }
161
-
162
- saveState(state);
163
- console.log(`${GREEN}✅ Tagged session #${current.session} with '${label}'.${RESET}`);
164
- }
165
-
166
- function cmdList(showAll) {
167
- const state = loadState();
168
- const history = state.history || [];
169
- if (!history.length) {
170
- console.log(`${YELLOW}No session history.${RESET}`);
171
- return;
172
- }
173
-
174
- const total = history.length;
175
- const pageSize = showAll ? total : LIST_PAGE_SIZE;
176
- const recent = history.slice().reverse().slice(0, pageSize);
177
-
178
- console.log(`\n${BOLD}${CYAN}━━━ Session List (${total} total, showing ${recent.length}) ━━━━━━━${RESET}`);
179
-
180
- for (const entry of recent) {
181
- const tagsStr = (entry.tags || []).join(", ");
182
- const tagsDisplay = tagsStr ? ` [${YELLOW}${tagsStr}${RESET}]` : "";
183
- const ts = entry.timestamp.slice(0, 16);
184
- console.log(`\n ${BOLD}${BLUE}#${entry.session}${RESET} — ${ts}${tagsDisplay}`);
185
- console.log(` ${entry.note}`);
186
- }
187
-
188
- if (!showAll && total > pageSize) {
189
- const remaining = total - pageSize;
190
- console.log(`\n ${YELLOW}... ${remaining} older session(s) not shown. Use '--all' to see all.${RESET}`);
191
- }
192
- console.log(`${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${RESET}\n`);
193
- }
194
-
195
- function cmdExport(toStdout) {
196
- const state = loadState();
197
- const history = state.history || [];
198
- if (!history.length) {
199
- console.log(`${YELLOW}No session history to export.${RESET}`);
200
- return;
201
- }
202
-
203
- const lines = ["# Session Export\n"];
204
- lines.push(`Generated: ${new Date().toISOString().slice(0, 16)}\n`);
205
- lines.push(`Total sessions: ${history.length}\n\n---\n`);
206
-
207
- const reversed = history.slice().reverse();
208
- for (const entry of reversed) {
209
- const sessionNum = entry.session || "?";
210
- const ts = (entry.timestamp || "").slice(0, 16);
211
- const note = entry.note || "";
212
- const tags = entry.tags || [];
213
- const tagsStr = tags.length ? `\n**Tags:** ${tags.join(", ")}` : "";
214
-
215
- lines.push(`## Session #${sessionNum} — ${ts}\n`);
216
- lines.push(`${note}${tagsStr}\n\n---\n`);
217
- }
218
-
219
- const content = lines.join("\n");
220
- if (toStdout) {
221
- console.log(content);
222
- } else {
223
- const exportPath = path.resolve("session_export.md");
224
- fs.writeFileSync(exportPath, content, "utf8");
225
- console.log(`${GREEN}✅ Exported ${history.length} sessions to${RESET} ${exportPath}`);
226
- }
227
- }
228
-
229
- function main() {
230
- const args = process.argv.slice(2);
231
- if (!args.length) {
232
- console.log(`Usage: node session_manager.js [save <note>|load|show|clear|status|tag <label>|list [--all]|export [--stdout]]`);
233
- process.exit(1);
234
- }
235
-
236
- const cmd = args[0].toLowerCase();
237
-
238
- if (!VALID_COMMANDS.has(cmd)) {
239
- console.log(`${RED}Unknown command: '${cmd}'${RESET}`);
240
- console.log(`Valid commands: ${[...VALID_COMMANDS].sort().join(', ')}`);
241
- process.exit(1);
242
- }
243
-
244
- if (cmd === "save") {
245
- let note = args.slice(1).join(" ").trim();
246
- if (!note) note = `session ${new Date().toISOString().slice(0,16).replace('T', ' ')}`;
247
- cmdSave(note);
248
- } else if (cmd === "load") {
249
- cmdLoad();
250
- } else if (cmd === "show") {
251
- cmdShow();
252
- } else if (cmd === "clear") {
253
- cmdClear();
254
- } else if (cmd === "status") {
255
- cmdStatus();
256
- } else if (cmd === "tag") {
257
- const label = args.slice(1).join(" ").trim();
258
- cmdTag(label);
259
- } else if (cmd === "list") {
260
- const showAll = args.includes("--all");
261
- cmdList(showAll);
262
- } else if (cmd === "export") {
263
- const toStdout = args.includes("--stdout");
264
- cmdExport(toStdout);
265
- }
266
- }
267
-
268
- if (require.main === module) {
269
- main();
270
- }
1
+ #!/usr/bin/env node
2
+ /**
3
+ * session_manager.js — Agent session state tracking for multi-conversation work.
4
+ *
5
+ * Usage:
6
+ * node .agent/scripts/session_manager.js save "working on auth"
7
+ * node .agent/scripts/session_manager.js load
8
+ * node .agent/scripts/session_manager.js show
9
+ * node .agent/scripts/session_manager.js clear
10
+ * node .agent/scripts/session_manager.js status
11
+ * node .agent/scripts/session_manager.js tag <label>
12
+ * node .agent/scripts/session_manager.js list [--all]
13
+ * node .agent/scripts/session_manager.js export [--stdout]
14
+ */
15
+
16
+ "use strict";
17
+
18
+ const fs = require("fs");
19
+ const path = require("path");
20
+
21
+ const STATE_FILE = ".agent_session.json";
22
+
23
+ const { GREEN, YELLOW, BLUE, CYAN, RED, BOLD, RESET } = require("./_colors");
24
+
25
+ const VALID_COMMANDS = new Set([
26
+ "save",
27
+ "load",
28
+ "show",
29
+ "clear",
30
+ "status",
31
+ "tag",
32
+ "list",
33
+ "export",
34
+ ]);
35
+ const LIST_PAGE_SIZE = 10;
36
+
37
+ function loadState() {
38
+ if (!fs.existsSync(STATE_FILE)) return {};
39
+ try {
40
+ const content = fs.readFileSync(STATE_FILE, "utf8");
41
+ return JSON.parse(content);
42
+ } catch {
43
+ return {};
44
+ }
45
+ }
46
+
47
+ function saveState(state) {
48
+ fs.writeFileSync(STATE_FILE, JSON.stringify(state, null, 2), "utf8");
49
+ }
50
+
51
+ function cmdSave(note) {
52
+ const state = loadState();
53
+ const entry = {
54
+ timestamp: new Date().toISOString(),
55
+ note: note,
56
+ session: (state.history || []).length + 1,
57
+ tags: [],
58
+ };
59
+ if (!state.history) state.history = [];
60
+ state.history.push(entry);
61
+ state.current = entry;
62
+ saveState(state);
63
+
64
+ console.log(`${GREEN} Session saved:${RESET} ${note}`);
65
+ console.log(` Time: ${entry.timestamp}`);
66
+ console.log(` Session: #${entry.session}`);
67
+ }
68
+
69
+ function cmdLoad() {
70
+ const state = loadState();
71
+ const current = state.current;
72
+ if (!current) {
73
+ console.log(`${YELLOW}No active session — use 'save' first.${RESET}`);
74
+ return;
75
+ }
76
+ const tagsStr = (current.tags || []).join(", ") || "none";
77
+ console.log(`${BOLD}Current session:${RESET}`);
78
+ console.log(` Session: #${current.session}`);
79
+ console.log(` Time: ${current.timestamp}`);
80
+ console.log(` Note: ${current.note}`);
81
+ console.log(` Tags: ${tagsStr}`);
82
+ }
83
+
84
+ function cmdShow() {
85
+ const state = loadState();
86
+ const history = state.history || [];
87
+ if (!history.length) {
88
+ console.log(`${YELLOW}No session history.${RESET}`);
89
+ return;
90
+ }
91
+ console.log(`${BOLD}Session History (${history.length} total):${RESET}`);
92
+ const recent = history.slice(-10).reverse();
93
+ for (const entry of recent) {
94
+ const tagsStr = (entry.tags || []).join(", ") || "";
95
+ const tagsDisplay = tagsStr ? ` [${tagsStr}]` : "";
96
+ console.log(
97
+ `\n ${BLUE}#${entry.session}${RESET} — ${entry.timestamp.slice(0, 16)}${tagsDisplay}`,
98
+ );
99
+ console.log(` ${entry.note}`);
100
+ }
101
+ }
102
+
103
+ function cmdClear() {
104
+ if (fs.existsSync(STATE_FILE)) {
105
+ fs.unlinkSync(STATE_FILE);
106
+ console.log(`${GREEN}✅ Session state cleared.${RESET}`);
107
+ } else {
108
+ console.log(`${YELLOW}No session file found — nothing to clear.${RESET}`);
109
+ }
110
+ }
111
+
112
+ function cmdStatus() {
113
+ const state = loadState();
114
+ const history = state.history || [];
115
+ const current = state.current;
116
+
117
+ if (!history.length) {
118
+ console.log(
119
+ `${YELLOW}No session history — use 'save' to start tracking.${RESET}`,
120
+ );
121
+ return;
122
+ }
123
+
124
+ const total = history.length;
125
+ const recent = history.slice(-3).reverse();
126
+
127
+ console.log(
128
+ `\n${BOLD}${CYAN}━━━ Session Status ━━━━━━━━━━━━━━━━━━━━━━━━${RESET}`,
129
+ );
130
+ console.log(` Total sessions: ${total}`);
131
+ if (current) {
132
+ console.log(
133
+ ` Active: #${current.session} — ${current.note.slice(0, 60)}`,
134
+ );
135
+ }
136
+ console.log(`\n${BOLD} Last 3 sessions:${RESET}`);
137
+ for (const entry of recent) {
138
+ const tagsStr = (entry.tags || []).join(", ") || "";
139
+ const tagsDisplay = tagsStr ? ` [${tagsStr}]` : "";
140
+ const ts = entry.timestamp.slice(0, 16);
141
+ console.log(` ${BLUE}#${entry.session}${RESET} ${ts}${tagsDisplay}`);
142
+ console.log(` ${entry.note.slice(0, 70)}`);
143
+ }
144
+ console.log(`${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${RESET}\n`);
145
+ }
146
+
147
+ function cmdTag(label) {
148
+ if (!label) {
149
+ console.log(
150
+ `${RED}Error: provide a tag label. Example: node session_manager.js tag v2-feature${RESET}`,
151
+ );
152
+ process.exit(1);
153
+ }
154
+ const state = loadState();
155
+ const current = state.current;
156
+ if (!current) {
157
+ console.log(
158
+ `${YELLOW}No active session — use 'save' first before tagging.${RESET}`,
159
+ );
160
+ process.exit(1);
161
+ }
162
+ if (!current.tags) current.tags = [];
163
+ if (current.tags.includes(label)) {
164
+ console.log(
165
+ `${YELLOW}Tag '${label}' already exists on session #${current.session}.${RESET}`,
166
+ );
167
+ return;
168
+ }
169
+
170
+ current.tags.push(label);
171
+ state.current = current;
172
+
173
+ if (state.history) {
174
+ for (const entry of state.history) {
175
+ if (entry.session === current.session) {
176
+ if (!entry.tags) entry.tags = [];
177
+ if (!entry.tags.includes(label)) {
178
+ entry.tags.push(label);
179
+ }
180
+ break;
181
+ }
182
+ }
183
+ }
184
+
185
+ saveState(state);
186
+ console.log(
187
+ `${GREEN}✅ Tagged session #${current.session} with '${label}'.${RESET}`,
188
+ );
189
+ }
190
+
191
+ function cmdList(showAll) {
192
+ const state = loadState();
193
+ const history = state.history || [];
194
+ if (!history.length) {
195
+ console.log(`${YELLOW}No session history.${RESET}`);
196
+ return;
197
+ }
198
+
199
+ const total = history.length;
200
+ const pageSize = showAll ? total : LIST_PAGE_SIZE;
201
+ const recent = history.slice().reverse().slice(0, pageSize);
202
+
203
+ console.log(
204
+ `\n${BOLD}${CYAN}━━━ Session List (${total} total, showing ${recent.length}) ━━━━━━━${RESET}`,
205
+ );
206
+
207
+ for (const entry of recent) {
208
+ const tagsStr = (entry.tags || []).join(", ");
209
+ const tagsDisplay = tagsStr ? ` [${YELLOW}${tagsStr}${RESET}]` : "";
210
+ const ts = entry.timestamp.slice(0, 16);
211
+ console.log(
212
+ `\n ${BOLD}${BLUE}#${entry.session}${RESET} ${ts}${tagsDisplay}`,
213
+ );
214
+ console.log(` ${entry.note}`);
215
+ }
216
+
217
+ if (!showAll && total > pageSize) {
218
+ const remaining = total - pageSize;
219
+ console.log(
220
+ `\n ${YELLOW}... ${remaining} older session(s) not shown. Use '--all' to see all.${RESET}`,
221
+ );
222
+ }
223
+ console.log(`${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${RESET}\n`);
224
+ }
225
+
226
+ function cmdExport(toStdout) {
227
+ const state = loadState();
228
+ const history = state.history || [];
229
+ if (!history.length) {
230
+ console.log(`${YELLOW}No session history to export.${RESET}`);
231
+ return;
232
+ }
233
+
234
+ const lines = ["# Session Export\n"];
235
+ lines.push(`Generated: ${new Date().toISOString().slice(0, 16)}\n`);
236
+ lines.push(`Total sessions: ${history.length}\n\n---\n`);
237
+
238
+ const reversed = history.slice().reverse();
239
+ for (const entry of reversed) {
240
+ const sessionNum = entry.session || "?";
241
+ const ts = (entry.timestamp || "").slice(0, 16);
242
+ const note = entry.note || "";
243
+ const tags = entry.tags || [];
244
+ const tagsStr = tags.length ? `\n**Tags:** ${tags.join(", ")}` : "";
245
+
246
+ lines.push(`## Session #${sessionNum} ${ts}\n`);
247
+ lines.push(`${note}${tagsStr}\n\n---\n`);
248
+ }
249
+
250
+ const content = lines.join("\n");
251
+ if (toStdout) {
252
+ console.log(content);
253
+ } else {
254
+ const exportPath = path.resolve("session_export.md");
255
+ fs.writeFileSync(exportPath, content, "utf8");
256
+ console.log(
257
+ `${GREEN}✅ Exported ${history.length} sessions to${RESET} ${exportPath}`,
258
+ );
259
+ }
260
+ }
261
+
262
+ function main() {
263
+ const args = process.argv.slice(2);
264
+ if (!args.length) {
265
+ console.log(
266
+ `Usage: node session_manager.js [save <note>|load|show|clear|status|tag <label>|list [--all]|export [--stdout]]`,
267
+ );
268
+ process.exit(1);
269
+ }
270
+
271
+ const cmd = args[0].toLowerCase();
272
+
273
+ if (!VALID_COMMANDS.has(cmd)) {
274
+ console.log(`${RED}Unknown command: '${cmd}'${RESET}`);
275
+ console.log(`Valid commands: ${[...VALID_COMMANDS].sort().join(", ")}`);
276
+ process.exit(1);
277
+ }
278
+
279
+ if (cmd === "save") {
280
+ let note = args.slice(1).join(" ").trim();
281
+ if (!note)
282
+ note = `session ${new Date().toISOString().slice(0, 16).replace("T", " ")}`;
283
+ cmdSave(note);
284
+ } else if (cmd === "load") {
285
+ cmdLoad();
286
+ } else if (cmd === "show") {
287
+ cmdShow();
288
+ } else if (cmd === "clear") {
289
+ cmdClear();
290
+ } else if (cmd === "status") {
291
+ cmdStatus();
292
+ } else if (cmd === "tag") {
293
+ const label = args.slice(1).join(" ").trim();
294
+ cmdTag(label);
295
+ } else if (cmd === "list") {
296
+ const showAll = args.includes("--all");
297
+ cmdList(showAll);
298
+ } else if (cmd === "export") {
299
+ const toStdout = args.includes("--stdout");
300
+ cmdExport(toStdout);
301
+ }
302
+ }
303
+
304
+ if (require.main === module) {
305
+ main();
306
+ }