@smallwebco/tinypivot-mcp 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -1,19 +1,24 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
+ CHART_THEME_IDS,
3
4
  DatasetStore,
4
5
  FREE_TIER_ROW_LIMIT,
6
+ TERMINAL_PALETTES,
5
7
  createTinyPivotMcpServer,
6
8
  formatDatasetSummary,
7
9
  formatPivotSummary,
8
10
  formatTerminalChart,
11
+ getPreferencesPath,
9
12
  isMcpLicenseKey,
10
13
  loadAppHtml,
14
+ loadSavedVisualTheme,
11
15
  parseDelimitedText,
12
16
  resolveLicenseKey,
13
17
  runInitCommand,
14
18
  runTuiCommand,
19
+ saveVisualThemePreference,
15
20
  startCompanionServer
16
- } from "./chunk-UNQEXGX2.js";
21
+ } from "./chunk-DPIX36MK.js";
17
22
  import "./chunk-2ESYSVXG.js";
18
23
 
19
24
  // src/cli.ts
@@ -136,8 +141,139 @@ async function readRemainingStdin(initial, alreadyEnded) {
136
141
  process.stdin.resume();
137
142
  });
138
143
  }
144
+ function swatchBlock(rgb) {
145
+ return `\x1B[38;2;${rgb[0]};${rgb[1]};${rgb[2]}m\u2588\u2588\x1B[0m`;
146
+ }
147
+ function formatThemeRow(id, active, selected, useColor) {
148
+ const pal = TERMINAL_PALETTES[id];
149
+ const pointer = selected ? "\u203A" : " ";
150
+ const dot = id === active ? "\u25CF" : " ";
151
+ const swatches = useColor ? `${swatchBlock(pal.series[0])} ${swatchBlock(pal.series[1])} ${swatchBlock(pal.series[2])}` : "\u25A0\u25A0\u25A0";
152
+ const idCol = id.padEnd(11);
153
+ const labelCol = pal.label.padEnd(11);
154
+ const suffix = id === active ? " (active)" : "";
155
+ const line = ` ${pointer} ${dot} ${swatches} ${idCol} ${labelCol}${suffix}`;
156
+ return useColor && selected ? `\x1B[1m${line}\x1B[0m` : line;
157
+ }
158
+ async function runInteractiveThemePicker(active) {
159
+ const themes = CHART_THEME_IDS;
160
+ let cursor = Math.max(0, themes.indexOf(active));
161
+ const useColor = Boolean(process.stdout.isTTY && !process.env.NO_COLOR);
162
+ const totalLines = themes.length + 4;
163
+ let rendered = false;
164
+ const draw = () => {
165
+ if (rendered) {
166
+ process.stdout.write(`\x1B[${totalLines}A`);
167
+ }
168
+ rendered = true;
169
+ const out = [
170
+ "\x1B[2K\x1B[1mTinyPivot MCP \u2014 Choose Visual Theme\x1B[0m (\u2191/\u2193 move, Enter select, q cancel)",
171
+ "\x1B[2K",
172
+ ...themes.map((id, idx) => `\x1B[2K${formatThemeRow(id, active, idx === cursor, useColor)}`),
173
+ "\x1B[2K",
174
+ `\x1B[2K Saves to ${getPreferencesPath()} (applies across all MCP sessions, Companion IDE & TUI)`
175
+ ];
176
+ process.stdout.write(`${out.join("\n")}
177
+ `);
178
+ };
179
+ return new Promise((resolve) => {
180
+ process.stdout.write("\x1B[?25l");
181
+ draw();
182
+ process.stdin.setRawMode(true);
183
+ process.stdin.resume();
184
+ process.stdin.setEncoding("utf8");
185
+ const finish = (choice) => {
186
+ process.stdin.off("data", onKey);
187
+ process.stdin.setRawMode(false);
188
+ process.stdin.pause();
189
+ process.stdout.write("\x1B[?25h");
190
+ resolve(choice);
191
+ };
192
+ const onKey = (key) => {
193
+ if (key === "q" || key === "" || key === "\x1B") {
194
+ finish(null);
195
+ return;
196
+ }
197
+ if (key === "\r" || key === "\n") {
198
+ finish(themes[cursor]);
199
+ return;
200
+ }
201
+ if (key === "\x1B[A" || key === "k") {
202
+ cursor = (cursor - 1 + themes.length) % themes.length;
203
+ draw();
204
+ } else if (key === "\x1B[B" || key === "j") {
205
+ cursor = (cursor + 1) % themes.length;
206
+ draw();
207
+ }
208
+ };
209
+ process.stdin.on("data", onKey);
210
+ });
211
+ }
212
+ async function runThemeCommand(args) {
213
+ const validSet = new Set(CHART_THEME_IDS);
214
+ const requested = args[0]?.trim().toLowerCase();
215
+ const active = process.env.TINYPIVOT_THEME?.trim().toLowerCase() && validSet.has(process.env.TINYPIVOT_THEME.trim().toLowerCase()) ? process.env.TINYPIVOT_THEME.trim().toLowerCase() : loadSavedVisualTheme() ?? "code";
216
+ const useColor = Boolean(process.stdout.isTTY && !process.env.NO_COLOR);
217
+ if (!requested && process.stdin.isTTY && process.stdout.isTTY) {
218
+ console.log("");
219
+ const picked = await runInteractiveThemePicker(active);
220
+ console.log("");
221
+ if (!picked) {
222
+ console.log("Theme unchanged.");
223
+ return;
224
+ }
225
+ saveVisualThemePreference(picked);
226
+ console.log(`\u2713 Default TinyPivot theme set to "${picked}" (${TERMINAL_PALETTES[picked].label})`);
227
+ if (process.env.TINYPIVOT_THEME) {
228
+ console.log(` Note: TINYPIVOT_THEME=${process.env.TINYPIVOT_THEME} in your shell/harness env overrides preferences.json.`);
229
+ }
230
+ return;
231
+ }
232
+ if (!requested || requested === "-h" || requested === "--help" || requested === "list") {
233
+ console.log("\nTinyPivot MCP \u2014 Visual Themes\n");
234
+ for (const id of CHART_THEME_IDS) {
235
+ console.log(formatThemeRow(id, active, false, useColor));
236
+ }
237
+ console.log(`
238
+ Preferences file: ${getPreferencesPath()}`);
239
+ if (process.env.TINYPIVOT_THEME) {
240
+ console.log(`Note: TINYPIVOT_THEME=${process.env.TINYPIVOT_THEME} is set in env and overrides preferences.json.`);
241
+ }
242
+ console.log("\nUsage: npx @smallwebco/tinypivot-mcp theme [theme-id]\n");
243
+ return;
244
+ }
245
+ if (!validSet.has(requested)) {
246
+ console.error(`Unknown theme "${requested}". Available themes: ${CHART_THEME_IDS.join(", ")}`);
247
+ process.exit(1);
248
+ }
249
+ saveVisualThemePreference(requested);
250
+ console.log(`\u2713 Default TinyPivot theme set to "${requested}" (${TERMINAL_PALETTES[requested].label}) \u2014 saved to ${getPreferencesPath()}`);
251
+ console.log(" Applies immediately on next TinyPivot MCP turn, Companion IDE load, or TUI launch.");
252
+ }
253
+ function printRootHelp() {
254
+ console.log(`
255
+ TinyPivot MCP \u2014 Interactive Data IDE & Terminal Charts for AI Agents
256
+
257
+ Commands:
258
+ tinypivot-mcp init [options] Configure Claude Code, Claude Desktop, pi, Cursor, OpenCode, Codex & Antigravity
259
+ tinypivot-mcp theme [id] Interactive arrow-key theme picker (or set theme directly)
260
+ tinypivot-mcp tui Attach a live truecolor split-pane TUI (Ghostty/tmux)
261
+ <cmd> | tinypivot-mcp [options] Pipe CSV/TSV/JSON/JSONL directly from psql, duckdb, bq, etc.
262
+
263
+ Options:
264
+ --theme=<id> Visual theme (${CHART_THEME_IDS.join(", ")})
265
+ --pivot Also print a framed sparkline pivot table on stdin pipe
266
+ --open Open the live Companion Data IDE in your browser
267
+ --port=<n> Bind Companion Data IDE on a specific localhost port
268
+ --name=<title> Dataset title for piped stdin / loaded files
269
+ `.trim());
270
+ }
139
271
  async function main() {
140
272
  const args = process.argv.slice(2);
273
+ if (args[0] === "-h" || args[0] === "--help") {
274
+ printRootHelp();
275
+ return;
276
+ }
141
277
  if (args[0] === "init") {
142
278
  await runInitCommand(args.slice(1));
143
279
  return;
@@ -146,6 +282,10 @@ async function main() {
146
282
  await runTuiCommand(args.slice(1));
147
283
  return;
148
284
  }
285
+ if (args[0] === "theme" || args[0] === "themes") {
286
+ await runThemeCommand(args.slice(1));
287
+ return;
288
+ }
149
289
  const rawLicenseKey = resolveLicenseKey();
150
290
  const licenseKey = isMcpLicenseKey(rawLicenseKey) ? rawLicenseKey : void 0;
151
291
  const demoToken = process.env.TINYPIVOT_DEMO_TOKEN;
@@ -245,11 +385,23 @@ async function main() {
245
385
  });
246
386
  const truncSuffix = ds.truncatedForFreeTier ? ` (truncated from ${ds.sourceTotalRows.toLocaleString()} \u2014 Free tier limit: ${FREE_TIER_ROW_LIMIT.toLocaleString()} rows)` : "";
247
387
  console.error(`[tinypivot-mcp] Loaded ${ds.name} (${ds.rows.length.toLocaleString()} rows)${truncSuffix}`);
248
- const chartCard = formatTerminalChart(ds, ds.chartConfig, { showBranding: !isPro });
388
+ const useTtyColor = Boolean(process.stdout.isTTY && !process.env.NO_COLOR);
389
+ let liveCompanionUrl;
390
+ if ((autoOpen || explicitPort) && !disableCompanion) {
391
+ const handle = await ensureCompanionStarted();
392
+ liveCompanionUrl = handle?.url;
393
+ }
394
+ const fmtOpts = {
395
+ showBranding: !isPro,
396
+ companionUrl: liveCompanionUrl,
397
+ colorTheme: useTtyColor ? store.getVisualTheme() : void 0,
398
+ raw: useTtyColor
399
+ };
400
+ const chartCard = formatTerminalChart(ds, ds.chartConfig, fmtOpts);
249
401
  if (chartCard) {
250
402
  console.log(chartCard);
251
403
  } else {
252
- console.log(formatDatasetSummary(ds, void 0, { showBranding: !isPro }));
404
+ console.log(formatDatasetSummary(ds, liveCompanionUrl, fmtOpts));
253
405
  }
254
406
  if (showPivotOutput && ds.pivotConfig?.valueFields?.length) {
255
407
  const pivotCard = formatPivotSummary(ds, {
@@ -258,17 +410,14 @@ async function main() {
258
410
  valueFields: ds.pivotConfig.valueFields,
259
411
  showRowTotals: ds.pivotConfig.showRowTotals ?? true,
260
412
  showColumnTotals: ds.pivotConfig.showColumnTotals ?? true
261
- }, void 0, { showBranding: !isPro });
413
+ }, liveCompanionUrl, fmtOpts);
262
414
  console.log(`
263
415
  ${pivotCard}`);
264
416
  }
265
- if ((autoOpen || explicitPort) && !disableCompanion) {
266
- const handle = await ensureCompanionStarted();
267
- if (handle) {
268
- console.error(`[tinypivot-mcp] Serving live Companion IDE at ${handle.url} (press Ctrl+C to stop)`);
269
- await new Promise(() => {
270
- });
271
- }
417
+ if (liveCompanionUrl) {
418
+ console.error(`[tinypivot-mcp] Serving live Companion IDE at ${liveCompanionUrl} (press Ctrl+C to stop)`);
419
+ await new Promise(() => {
420
+ });
272
421
  }
273
422
  return;
274
423
  }