sigrank-mcp 0.6.3 → 0.6.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.
Files changed (3) hide show
  1. package/cli.mjs +521 -0
  2. package/index.mjs +27 -13
  3. package/package.json +8 -3
package/cli.mjs ADDED
@@ -0,0 +1,521 @@
1
+ /**
2
+ * cli.mjs — SigRank terminal UI.
3
+ *
4
+ * Commands (no external deps — pure Node.js ANSI escape codes):
5
+ *
6
+ * npx sigrank-mcp board live leaderboard, refreshes every 30s
7
+ * npx sigrank-mcp board --window 7d board for a specific window
8
+ * npx sigrank-mcp board --once print once and exit (no live refresh)
9
+ * npx sigrank-mcp me your cascade across all 4 windows
10
+ * npx sigrank-mcp me --platform amp use a different platform adapter
11
+ * npx sigrank-mcp watch RT tune meter — local cascade, refreshes
12
+ * npx sigrank-mcp watch --window 7d watch a specific window
13
+ *
14
+ * Color palette mirrors the SigRank web dark theme:
15
+ * gold = class TRANSMITTER headline + rank #1
16
+ * cyan = active metrics / your row highlight
17
+ * dim = secondary data, separators
18
+ * red = negative movement
19
+ * green = positive movement
20
+ */
21
+
22
+ import { callTool, DEFAULT_API_BASE } from './tools.mjs'
23
+
24
+ // ── ANSI helpers (no chalk dep) ────────────────────────────────────────────
25
+ const ESC = '\x1b['
26
+ const c = {
27
+ reset: `${ESC}0m`,
28
+ bold: `${ESC}1m`,
29
+ dim: `${ESC}2m`,
30
+ gold: `${ESC}33m`,
31
+ boldGold: `${ESC}1;33m`,
32
+ cyan: `${ESC}36m`,
33
+ boldCyan: `${ESC}1;36m`,
34
+ green: `${ESC}32m`,
35
+ red: `${ESC}31m`,
36
+ white: `${ESC}97m`,
37
+ boldWhite:`${ESC}1;97m`,
38
+ magenta: `${ESC}35m`,
39
+ blue: `${ESC}34m`,
40
+ }
41
+ const paint = (color, str) => `${color}${str}${c.reset}`
42
+ const bold = (str) => paint(c.bold, str)
43
+ const dim = (str) => paint(c.dim, str)
44
+ const gold = (str) => paint(c.boldGold, str)
45
+ const cyan = (str) => paint(c.boldCyan, str)
46
+ const green = (str) => paint(c.green, str)
47
+ const red = (str) => paint(c.red, str)
48
+
49
+ // ── Class tier → color ─────────────────────────────────────────────────────
50
+ const CLASS_COLOR = {
51
+ TRANSMITTER: (s) => paint(c.boldGold, s),
52
+ 'ARCH+': (s) => paint(c.boldCyan, s),
53
+ ARCH: (s) => paint(c.cyan, s),
54
+ POWER: (s) => paint(c.boldWhite, s),
55
+ BASE: (s) => paint(c.white, s),
56
+ SEEKER: (s) => paint(c.magenta, s),
57
+ REFINER: (s) => paint(c.blue, s),
58
+ BEARER: (s) => paint(c.dim, s),
59
+ IGNITER: (s) => paint(c.dim, s),
60
+ }
61
+ const colorClass = (cls) => (CLASS_COLOR[cls] ?? ((s) => s))(cls)
62
+
63
+ // ── Terminal utils ──────────────────────────────────────────────────────────
64
+ const CLEAR_SCREEN = `${ESC}2J${ESC}H`
65
+ const CURSOR_UP = (n) => `${ESC}${n}A`
66
+ const ERASE_LINE = `${ESC}2K`
67
+ const HIDE_CURSOR = `${ESC}?25l`
68
+ const SHOW_CURSOR = `${ESC}?25h`
69
+ const termWidth = () => process.stdout.columns || 80
70
+ const write = (s) => process.stdout.write(s)
71
+ const writeln = (s = '') => process.stdout.write(s + '\n')
72
+
73
+ // Right-pad or truncate to exact width (ANSI-escape-aware via strip helper)
74
+ function stripAnsi(s) { return s.replace(/\x1b\[[0-9;]*m/g, '') }
75
+ function padEnd(s, w) {
76
+ const vis = stripAnsi(s).length
77
+ return vis >= w ? s : s + ' '.repeat(w - vis)
78
+ }
79
+ function padStart(s, w) {
80
+ const vis = stripAnsi(s).length
81
+ return vis >= w ? s : ' '.repeat(w - vis) + s
82
+ }
83
+ function trunc(s, w) {
84
+ const stripped = stripAnsi(s)
85
+ if (stripped.length <= w) return s
86
+ // truncate the raw string, not the escape-aware one — safe for plain strings
87
+ return s.slice(0, w - 1) + '…'
88
+ }
89
+
90
+ // ── Number formatters ───────────────────────────────────────────────────────
91
+ const fmtYield = (y) => {
92
+ if (y == null) return '—'
93
+ if (y >= 10000) return `${(y / 1000).toFixed(1)}K`
94
+ if (y >= 1000) return `${(y / 1000).toFixed(2)}K`
95
+ return y.toFixed(1)
96
+ }
97
+ const fmtLev = (l) => {
98
+ if (l == null) return '—'
99
+ if (l >= 1000) return `${(l / 1000).toFixed(1)}K`
100
+ return l.toFixed(0)
101
+ }
102
+ const fmtPct = (n) => n != null ? `${(n * 100).toFixed(0)}%` : '—'
103
+ const fmtSNR = (n) => n != null ? `${(n * 100).toFixed(1)}%` : '—'
104
+ const fmtMove = (n) => {
105
+ if (n == null || n === 0) return dim(' —')
106
+ return n > 0 ? green(`+${n}`) : red(`${n}`)
107
+ }
108
+ const fmtTokens = (n) => {
109
+ if (n == null) return '—'
110
+ if (n >= 1e9) return `${(n / 1e9).toFixed(1)}B`
111
+ if (n >= 1e6) return `${(n / 1e6).toFixed(1)}M`
112
+ if (n >= 1e3) return `${(n / 1e3).toFixed(1)}K`
113
+ return String(n)
114
+ }
115
+
116
+ // ── Header / footer ─────────────────────────────────────────────────────────
117
+ function renderHeader(title, subtitle = '') {
118
+ const w = termWidth()
119
+ const ts = new Date().toLocaleTimeString('en-US', { hour12: false })
120
+ const right = dim(`signalaf.com ${ts}`)
121
+ const rightVis = stripAnsi(right).length
122
+ const leftVis = stripAnsi(title).length
123
+ const gap = Math.max(1, w - leftVis - rightVis)
124
+ writeln()
125
+ writeln(` ${title}${' '.repeat(gap)}${right}`)
126
+ if (subtitle) writeln(` ${dim(subtitle)}`)
127
+ writeln(` ${dim('─'.repeat(w - 4))}`)
128
+ }
129
+
130
+ function renderFooter(hint = '') {
131
+ const w = termWidth()
132
+ writeln(` ${dim('─'.repeat(w - 4))}`)
133
+ if (hint) writeln(` ${dim(hint)}`)
134
+ writeln()
135
+ }
136
+
137
+ // ── BOARD command ────────────────────────────────────────────────────────────
138
+
139
+ const BOARD_COLS = [
140
+ { key: 'rank', label: '#', w: 4, align: 'r' },
141
+ { key: 'codename', label: 'Operator',w: 20, align: 'l' },
142
+ { key: 'class_tier', label: 'Class', w: 13, align: 'l' },
143
+ { key: 'signa_rate', label: 'SIGNA', w: 7, align: 'r' },
144
+ { key: 'compression_ratio', label: 'SNR', w: 6, align: 'r' },
145
+ { key: 'session_depth', label: 'Depth', w: 6, align: 'r' },
146
+ { key: 'token_throughput', label: 'Tokens', w: 8, align: 'r' },
147
+ { key: 'movement_7d', label: '7d Δ', w: 6, align: 'r' },
148
+ ]
149
+
150
+ function renderBoardRow(entry, highlight = false) {
151
+ const rank = entry.rank === 1 ? gold(`#${entry.rank}`) : `#${entry.rank}`
152
+ const name = highlight
153
+ ? cyan(trunc(entry.codename, 19))
154
+ : trunc(entry.codename, 19)
155
+ const cls = colorClass(entry.class_tier ?? '—')
156
+ const sna = (entry.signa_rate ?? 0).toFixed(1)
157
+ const snr = fmtSNR(entry.compression_ratio)
158
+ const dep = entry.session_depth != null ? entry.session_depth.toFixed(1) : '—'
159
+ const tok = fmtTokens(entry.token_throughput)
160
+ const mv = fmtMove(entry.movement_7d)
161
+
162
+ const cols = [
163
+ padStart(rank, 4),
164
+ padEnd(name, 20),
165
+ padEnd(cls, 13),
166
+ padStart(sna, 7),
167
+ padStart(snr, 6),
168
+ padStart(dep, 6),
169
+ padStart(tok, 8),
170
+ padStart(mv, 6),
171
+ ]
172
+ const prefix = highlight ? `${c.boldCyan}▶${c.reset} ` : ' '
173
+ writeln(prefix + cols.join(' '))
174
+ }
175
+
176
+ function renderBoardHeader(window = '30d') {
177
+ renderHeader(
178
+ `${gold('⊙ SigRank')} ${bold('Leaderboard')}`,
179
+ `window: ${window} · sorted by SIGNA rate · top 25 operators`
180
+ )
181
+ // column headers
182
+ const headers = BOARD_COLS.map(col =>
183
+ col.align === 'r'
184
+ ? padStart(dim(col.label), col.w)
185
+ : padEnd(dim(col.label), col.w)
186
+ )
187
+ writeln(` ${headers.join(' ')}`)
188
+ writeln(` ${dim('·'.repeat(termWidth() - 4))}`)
189
+ }
190
+
191
+ async function fetchBoard(window = '30d') {
192
+ const res = await fetch(`${DEFAULT_API_BASE}/api/v1/leaderboard?window=${window}`, {
193
+ headers: { accept: 'application/json' }
194
+ })
195
+ if (!res.ok) throw new Error(`Board API → HTTP ${res.status}`)
196
+ return res.json()
197
+ }
198
+
199
+ async function runBoard({ window = '30d', once = false, refresh = 30 } = {}) {
200
+ let lines = 0
201
+
202
+ const draw = async () => {
203
+ let data
204
+ try { data = await fetchBoard(window) }
205
+ catch (e) {
206
+ writeln(red(` ✗ Could not reach signalaf.com: ${e.message}`))
207
+ return
208
+ }
209
+
210
+ if (!once && lines > 0) {
211
+ // move cursor up and redraw in-place
212
+ write(CURSOR_UP(lines))
213
+ }
214
+
215
+ const out = []
216
+ const push = (s = '') => out.push(s)
217
+
218
+ push()
219
+ const ts = new Date().toLocaleTimeString('en-US', { hour12: false })
220
+ const right = `signalaf.com ${ts}`
221
+ const title = `⊙ SigRank Leaderboard`
222
+ const w = termWidth()
223
+ const gap = Math.max(1, w - 2 - title.length - right.length)
224
+ push(` ${gold('⊙ SigRank')} ${bold('Leaderboard')}${' '.repeat(gap)}${dim(right)}`)
225
+ push(` ${dim(`window: ${data.window ?? window} · ${data.total_operators ?? (data.entries?.length ?? 0)} operators`)}`)
226
+ push(` ${dim('─'.repeat(w - 4))}`)
227
+
228
+ // column header row
229
+ const headers = BOARD_COLS.map(col =>
230
+ col.align === 'r'
231
+ ? padStart(dim(col.label), col.w)
232
+ : padEnd(dim(col.label), col.w)
233
+ ).join(' ')
234
+ push(` ${headers}`)
235
+ push(` ${dim('·'.repeat(w - 4))}`)
236
+
237
+ const entries = data.entries ?? []
238
+ for (const entry of entries) {
239
+ const rank = entry.rank === 1 ? gold(`#${entry.rank}`) : `#${entry.rank}`
240
+ const name = trunc(entry.codename ?? '—', 19)
241
+ const cls = colorClass(entry.class_tier ?? '—')
242
+ const sna = (entry.signa_rate ?? 0).toFixed(1)
243
+ const snr = fmtSNR(entry.compression_ratio)
244
+ const dep = entry.session_depth != null ? entry.session_depth.toFixed(1) : '—'
245
+ const tok = fmtTokens(entry.token_throughput)
246
+ const mv = fmtMove(entry.movement_7d)
247
+ const cols = [
248
+ padStart(rank, 4),
249
+ padEnd(name, 20),
250
+ padEnd(cls, 13),
251
+ padStart(sna, 7),
252
+ padStart(snr, 6),
253
+ padStart(dep, 6),
254
+ padStart(tok, 8),
255
+ padStart(mv, 6),
256
+ ]
257
+ push(` ${cols.join(' ')}`)
258
+ }
259
+
260
+ push(` ${dim('─'.repeat(w - 4))}`)
261
+ if (!once) push(` ${dim(`auto-refresh every ${refresh}s · ctrl+c to exit`)}`)
262
+ push()
263
+
264
+ // write all at once to minimize flicker
265
+ const rendered = out.join('\n')
266
+ write(rendered)
267
+ lines = out.length
268
+ }
269
+
270
+ if (!once) write(HIDE_CURSOR)
271
+ try {
272
+ await draw()
273
+ if (!once) {
274
+ const iv = setInterval(draw, refresh * 1000)
275
+ await new Promise((resolve) => {
276
+ process.on('SIGINT', () => { clearInterval(iv); resolve() })
277
+ })
278
+ }
279
+ } finally {
280
+ if (!once) write(SHOW_CURSOR + '\n')
281
+ }
282
+ }
283
+
284
+ // ── ME command ───────────────────────────────────────────────────────────────
285
+
286
+ async function runMe({ platform = 'claude' } = {}) {
287
+ write(HIDE_CURSOR)
288
+ writeln()
289
+ writeln(` ${gold('⊙ SigRank')} ${bold('Your Cascade')} ${dim(`platform: ${platform}`)}`)
290
+ writeln(` ${dim('reading local token logs…')}`)
291
+
292
+ let pulled
293
+ try {
294
+ pulled = await callTool('tokenpull', { platform })
295
+ } catch (e) {
296
+ write(SHOW_CURSOR)
297
+ writeln(red(` ✗ ${e.message}`))
298
+ process.exit(1)
299
+ }
300
+
301
+ // clear the "reading…" line
302
+ write(CURSOR_UP(1) + ERASE_LINE)
303
+
304
+ const w = termWidth()
305
+ writeln(` ${gold('⊙ SigRank')} ${bold('Your Cascade')} ${dim(`platform: ${pulled.platform ?? platform}`)}`)
306
+ if (pulled.estimated) writeln(` ${dim('⚠ estimated values (cache data unavailable for this platform)')}`)
307
+ writeln(` ${dim('─'.repeat(w - 4))}`)
308
+
309
+ // column headers
310
+ const cols_h = [
311
+ padEnd(dim('Window'), 8),
312
+ padStart(dim('Υ Yield'), 10),
313
+ padStart(dim('SNR'), 7),
314
+ padStart(dim('Leverage'), 9),
315
+ padStart(dim('Velocity'), 9),
316
+ padStart(dim('10xDEV'), 8),
317
+ padStart(dim('Class'), 13),
318
+ padStart(dim('Tokens'), 8),
319
+ ]
320
+ writeln(` ${cols_h.join(' ')}`)
321
+ writeln(` ${dim('·'.repeat(w - 4))}`)
322
+
323
+ const windows = pulled.windows ?? []
324
+ for (const win of windows) {
325
+ const cas = win.cascade
326
+ const isAll = win.window === 'all'
327
+ const wLabel = isAll ? bold('all-time') : win.window
328
+ const yVal = cas?.yield != null ? fmtYield(cas.yield) : '—'
329
+ const snrVal = cas?.snr != null ? fmtSNR(cas.snr) : '—'
330
+ const levVal = cas?.leverage != null ? `${fmtLev(cas.leverage)}×` : '—'
331
+ const velVal = cas?.velocity != null ? cas.velocity.toFixed(2) : '—'
332
+ const devVal = cas?.dev10x != null ? cas.dev10x.toFixed(2) : '—'
333
+ const cls = colorClass(cas?.class ?? '—')
334
+ const tok = fmtTokens(win.pillars?.total ?? (
335
+ (win.pillars?.input ?? 0) + (win.pillars?.output ?? 0) +
336
+ (win.pillars?.cacheCreate ?? 0) + (win.pillars?.cacheRead ?? 0)
337
+ ))
338
+
339
+ const row = [
340
+ padEnd(wLabel, 8),
341
+ padStart(isAll ? gold(yVal) : yVal, 10),
342
+ padStart(snrVal, 7),
343
+ padStart(levVal, 9),
344
+ padStart(velVal, 9),
345
+ padStart(devVal, 8),
346
+ padEnd(cls, 13),
347
+ padStart(tok, 8),
348
+ ]
349
+ writeln(` ${row.join(' ')}`)
350
+ }
351
+
352
+ writeln(` ${dim('─'.repeat(w - 4))}`)
353
+
354
+ // card for the best window (all-time if present, else first)
355
+ const best = windows.find(w => w.window === 'all') ?? windows[0]
356
+ if (best?.card) {
357
+ writeln()
358
+ writeln(` ${dim('cascade read:')}`)
359
+ // wrap card text at terminal width
360
+ const cardText = best.card
361
+ const maxW = w - 6
362
+ const words = cardText.split(' ')
363
+ let line = ''
364
+ for (const word of words) {
365
+ if (line.length + word.length + 1 > maxW) {
366
+ writeln(` ${line}`)
367
+ line = word
368
+ } else {
369
+ line = line ? `${line} ${word}` : word
370
+ }
371
+ }
372
+ if (line) writeln(` ${line}`)
373
+ }
374
+
375
+ writeln()
376
+
377
+ // submit hint
378
+ writeln(` ${dim('to publish:')} ${cyan('npx sigrank-mcp board')} ${dim('after')} ${cyan('tokenpull_submit')} ${dim('via your MCP client')}`)
379
+ writeln()
380
+ write(SHOW_CURSOR)
381
+ }
382
+
383
+ // ── WATCH command ─────────────────────────────────────────────────────────────
384
+
385
+ async function runWatch({ platform = 'claude', window: win = '7d', refresh = 30 } = {}) {
386
+ let prev = null
387
+ let lines = 0
388
+
389
+ write(HIDE_CURSOR)
390
+
391
+ const draw = async () => {
392
+ let result
393
+ try {
394
+ result = await callTool('watch_tokenpull', { platform, window: win })
395
+ } catch (e) {
396
+ writeln(red(` ✗ ${e.message}`))
397
+ return
398
+ }
399
+
400
+ const cas = result.cascade
401
+ const changed = prev !== null && prev !== cas?.yield
402
+
403
+ if (lines > 0) write(CURSOR_UP(lines))
404
+
405
+ const out = []
406
+ const push = (s = '') => out.push(s)
407
+ const w = termWidth()
408
+ const ts = new Date().toLocaleTimeString('en-US', { hour12: false })
409
+
410
+ push()
411
+ push(` ${gold('⊙ SigRank')} ${bold('Watch')} ${dim(`${platform} · window: ${win} · ${ts}`)}`)
412
+ push(` ${dim('─'.repeat(w - 4))}`)
413
+ push()
414
+
415
+ const yDisplay = cas?.yield != null ? fmtYield(cas.yield) : '—'
416
+ const indicator = changed ? green(' ▲ updated') : dim(' · no change')
417
+
418
+ push(` ${bold('Υ Yield')} ${cas?.yield != null ? gold(yDisplay) : '—'}${indicator}`)
419
+ push(` ${bold('SNR')} ${fmtSNR(cas?.snr)}`)
420
+ push(` ${bold('Leverage')} ${cas?.leverage != null ? `${fmtLev(cas.leverage)}×` : '—'}`)
421
+ push(` ${bold('Velocity')} ${cas?.velocity != null ? cas.velocity.toFixed(2) : '—'}`)
422
+ push(` ${bold('10xDEV')} ${cas?.dev10x != null ? cas.dev10x.toFixed(2) : '—'}`)
423
+ push(` ${bold('Class')} ${colorClass(cas?.class ?? '—')}`)
424
+ push()
425
+ push(` ${dim('─'.repeat(w - 4))}`)
426
+ push(` ${dim(`polling every ${refresh}s · tokens stay on your machine · ctrl+c to exit`)}`)
427
+ push()
428
+
429
+ write(out.join('\n'))
430
+ lines = out.length
431
+ prev = cas?.yield ?? null
432
+ }
433
+
434
+ try {
435
+ await draw()
436
+ const iv = setInterval(draw, refresh * 1000)
437
+ await new Promise((resolve) => {
438
+ process.on('SIGINT', () => { clearInterval(iv); resolve() })
439
+ })
440
+ } finally {
441
+ write(SHOW_CURSOR + '\n')
442
+ }
443
+ }
444
+
445
+ // ── HELP ─────────────────────────────────────────────────────────────────────
446
+
447
+ function showHelp() {
448
+ writeln()
449
+ writeln(` ${gold('⊙ SigRank')} ${bold('CLI')} ${dim('v0.6.4')}`)
450
+ writeln()
451
+ writeln(` ${bold('Commands')}`)
452
+ writeln(` ${cyan('board')} live leaderboard (refreshes every 30s)`)
453
+ writeln(` ${cyan('board --window 7d')} board for a specific window (7d, 30d, 90d, all_time)`)
454
+ writeln(` ${cyan('board --once')} print once and exit`)
455
+ writeln(` ${cyan('me')} your cascade across all 4 time windows`)
456
+ writeln(` ${cyan('me --platform amp')} use a different platform adapter`)
457
+ writeln(` ${cyan('watch')} live tune meter — re-reads local logs every 30s`)
458
+ writeln(` ${cyan('watch --window 7d')} watch a specific window`)
459
+ writeln()
460
+ writeln(` ${bold('Options')}`)
461
+ writeln(` ${dim('--window')} 7d · 30d · 90d · all_time (default: 30d for board, 7d for watch)`)
462
+ writeln(` ${dim('--platform')} claude · codex · amp · gemini · opencode · goose · …`)
463
+ writeln(` ${dim('--refresh')} poll interval in seconds (default: 30)`)
464
+ writeln(` ${dim('--once')} print once and exit (board only)`)
465
+ writeln()
466
+ writeln(` ${bold('MCP server mode')} (default when no command given)`)
467
+ writeln(` ${dim('npx sigrank-mcp')} starts the MCP server on stdio`)
468
+ writeln()
469
+ writeln(` ${bold('Examples')}`)
470
+ writeln(` ${dim('npx sigrank-mcp board')}`)
471
+ writeln(` ${dim('npx sigrank-mcp me')}`)
472
+ writeln(` ${dim('npx sigrank-mcp watch --window 7d --refresh 60')}`)
473
+ writeln(` ${dim('npx sigrank-mcp board --window all_time --once')}`)
474
+ writeln()
475
+ }
476
+
477
+ // ── ENTRY POINT ───────────────────────────────────────────────────────────────
478
+
479
+ export async function runCli(argv) {
480
+ const args = argv.slice(2) // strip 'node' + script path
481
+ const cmd = args[0]
482
+
483
+ // parse --key value flags
484
+ const flags = {}
485
+ for (let i = 1; i < args.length; i++) {
486
+ if (args[i].startsWith('--')) {
487
+ const key = args[i].slice(2)
488
+ const val = args[i + 1] && !args[i + 1].startsWith('--') ? args[++i] : true
489
+ flags[key] = val
490
+ }
491
+ }
492
+
493
+ try {
494
+ if (cmd === 'board') {
495
+ await runBoard({
496
+ window: flags.window ?? '30d',
497
+ once: flags.once === true || flags.once === 'true',
498
+ refresh: Number(flags.refresh) || 30,
499
+ })
500
+ } else if (cmd === 'me') {
501
+ await runMe({ platform: flags.platform ?? 'claude' })
502
+ } else if (cmd === 'watch') {
503
+ await runWatch({
504
+ platform: flags.platform ?? 'claude',
505
+ window: flags.window ?? '7d',
506
+ refresh: Number(flags.refresh) || 30,
507
+ })
508
+ } else if (cmd === '--help' || cmd === '-h' || cmd === 'help') {
509
+ showHelp()
510
+ } else if (cmd === '--version' || cmd === '-v') {
511
+ writeln('0.6.4')
512
+ } else {
513
+ // unknown command: show help
514
+ showHelp()
515
+ }
516
+ } catch (e) {
517
+ write(SHOW_CURSOR)
518
+ writeln(red(`\n ✗ ${e.message}`))
519
+ process.exit(1)
520
+ }
521
+ }
package/index.mjs CHANGED
@@ -1,23 +1,30 @@
1
1
  #!/usr/bin/env node
2
2
  /**
3
- * SigRank MCP server — exposes the SigRank yield cascade + live board as MCP tools
4
- * any client (Claude Code, Cursor, …) can call. Token-only, Claude/ccusage-first.
3
+ * SigRank MCP server + CLI entry point.
5
4
  *
6
- * Tools (see ./tools.mjs):
7
- * - rank_paste(text) paste ccusage token counts → Υ/SNR/Leverage/…+class +card
8
- * - get_leaderboard() the live public board (signalaf.com)
9
- * - get_operator(codename) one operator's live profile
10
- * - submit_paste(text, codename) rank AND publish to the board in one call
5
+ * CLI mode — triggered when any command arg is passed:
6
+ * npx sigrank-mcp board live leaderboard (auto-refresh)
7
+ * npx sigrank-mcp me your local cascade across 4 windows
8
+ * npx sigrank-mcp watch RT tune meter, re-reads local logs
9
+ * npx sigrank-mcp --help full command reference
11
10
  *
12
- * Pure cascade math lives in ./cascade.mjs (mirrors lib/ingest/bridge.ts); the
13
- * deterministic card in ./narrate.mjs; the tool table + dispatcher in ./tools.mjs.
14
- * No transcript content, no auth. Reuses the live read/write endpoints over HTTP.
11
+ * MCP server mode triggered when no args (the default for MCP clients):
12
+ * npx sigrank-mcp starts the MCP stdio server
13
+ *
14
+ * Tools exposed in MCP mode (see ./tools.mjs):
15
+ * rank_paste · get_leaderboard · get_operator · submit_paste
16
+ * tokenpull · tokenpull_submit · rank_windows · watch_tokenpull
17
+ *
18
+ * Pure cascade math: ./cascade.mjs | narration card: ./narrate.mjs
19
+ * Tool table + dispatcher: ./tools.mjs | Terminal UI: ./cli.mjs
20
+ * Token-only — no transcript content, no auth.
15
21
  */
16
22
 
17
23
  import { Server } from '@modelcontextprotocol/sdk/server/index.js'
18
24
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
19
25
  import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js'
20
26
  import { TOOLS, callTool } from './tools.mjs'
27
+ import { runCli } from './cli.mjs'
21
28
 
22
29
  // Prevent silent crashes — log to stderr (MCP clients read stdout; stderr is safe for
23
30
  // diagnostics). The process exits so the client can respawn with a clean slate rather
@@ -31,8 +38,8 @@ process.on('unhandledRejection', (reason) => {
31
38
  process.exit(1)
32
39
  })
33
40
 
34
- async function main() {
35
- const server = new Server({ name: 'sigrank', version: '0.6.2' }, { capabilities: { tools: {} } })
41
+ async function startMcpServer() {
42
+ const server = new Server({ name: 'sigrank', version: '0.6.4' }, { capabilities: { tools: {} } })
36
43
  server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: TOOLS }))
37
44
  server.setRequestHandler(CallToolRequestSchema, async (req) => {
38
45
  try {
@@ -45,4 +52,11 @@ async function main() {
45
52
  await server.connect(new StdioServerTransport())
46
53
  }
47
54
 
48
- main()
55
+ // Route: CLI commands → terminal UI; no args → MCP server
56
+ const cliArgs = process.argv.slice(2)
57
+ const CLI_COMMANDS = new Set(['board', 'me', 'watch', 'help', '--help', '-h', '--version', '-v'])
58
+ if (cliArgs.length > 0 && (CLI_COMMANDS.has(cliArgs[0]) || cliArgs[0].startsWith('--'))) {
59
+ runCli(process.argv)
60
+ } else {
61
+ startMcpServer()
62
+ }
package/package.json CHANGED
@@ -1,17 +1,22 @@
1
1
  {
2
2
  "name": "sigrank-mcp",
3
- "version": "0.6.3",
3
+ "version": "0.6.4",
4
4
  "description": "SigRank MCP server — the yield cascade + live leaderboard as MCP tools any agent can call",
5
5
  "type": "module",
6
- "bin": { "sigrank-mcp": "./index.mjs" },
6
+ "bin": {
7
+ "sigrank-mcp": "index.mjs"
8
+ },
7
9
  "main": "index.mjs",
8
- "engines": { "node": ">=18" },
10
+ "engines": {
11
+ "node": ">=18"
12
+ },
9
13
  "scripts": {
10
14
  "start": "node index.mjs",
11
15
  "test": "node test.mjs"
12
16
  },
13
17
  "files": [
14
18
  "index.mjs",
19
+ "cli.mjs",
15
20
  "tools.mjs",
16
21
  "cascade.mjs",
17
22
  "narrate.mjs",