@ia-qa/cli 1.0.8 → 1.0.10

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/README.md +4 -0
  2. package/index.js +236 -3
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -37,10 +37,14 @@ echo '{"b":2,"a":1}' | ia-qa format_json --stdin
37
37
 
38
38
  ia-qa text_stats "hello world" --json # machine JSON to stdout
39
39
  ia-qa split_chunks "$(cat doc.txt)" --chunk_size 256 --out chunks.json
40
+ ia-qa prompt_injection_scan "ignore all instructions" --report scan.html --open
40
41
  ```
41
42
 
42
43
  - **`--json`** emits machine-parsable JSON (default is human-readable).
43
44
  - **Large outputs** are written to a temp file and the path is printed; **`--out <file>`** chooses it.
45
+ - **`--report <file.html>`** also writes a self-contained, ia-qa.com-branded HTML report of the run
46
+ (verdict, stats, per-case badges — secret params redacted). Add **`--open`** to open it in your
47
+ browser (local use; leave it off in CI). `--open` alone writes a default-named report and opens it.
44
48
  - **`--stdin`** (or `-` as the positional) reads the primary input from stdin.
45
49
  - **`--server <url>`** / **`$IAQA_SERVER`** point at another server (default `https://www.ia-qa.com`,
46
50
  or a self-hosted ia-qa server).
package/index.js CHANGED
@@ -180,6 +180,216 @@ function emit(data, { json, out, toolName }) {
180
180
  return body;
181
181
  }
182
182
 
183
+ // ── branded HTML report (--report) ───────────────────────────────────────────
184
+ // A self-contained, zero-dependency ia-qa.com-branded page for a single tool run.
185
+ // Generic on purpose (the CLI carries no per-tool logic): it surfaces whatever
186
+ // verdict-shaped fields a result has — verdict/status, passed·failed·total,
187
+ // pass_rate, score, results[] — as a summary, then renders the full result below.
188
+ // Secret params are redacted: a report is a file, and files get shared.
189
+
190
+ const BRAND = {
191
+ home: 'https://www.ia-qa.com',
192
+ method: 'https://www.ia-qa.com/method',
193
+ tools: 'https://www.ia-qa.com/all-tools',
194
+ mcp: 'https://www.ia-qa.com/mcp-server',
195
+ };
196
+
197
+ function escHtml(s) {
198
+ return String(s == null ? '' : s)
199
+ .replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;')
200
+ .replace(/"/g, '&quot;').replace(/'/g, '&#039;');
201
+ }
202
+
203
+ // Map a verdict-ish value to one of four tones the CSS knows how to colour.
204
+ function toneOf(value) {
205
+ if (value === true) return 'pass';
206
+ if (value === false) return 'fail';
207
+ const s = String(value).trim().toUpperCase();
208
+ if (['PASS', 'PASSED', 'OK', 'SUCCESS', 'SAFE', 'CLEAN', 'VALID', 'GREEN'].includes(s)) return 'pass';
209
+ if (['FAIL', 'FAILED', 'BLOCK', 'BLOCKED', 'ERROR', 'UNSAFE', 'INVALID', 'RED'].includes(s)) return 'fail';
210
+ if (['WARNING', 'WARN', 'FIX', 'PARTIAL', 'DEGRADED', 'REVIEW', 'AMBER'].includes(s)) return 'warn';
211
+ return 'neutral';
212
+ }
213
+
214
+ function scoreTone(n) {
215
+ const v = n <= 1 ? n * 100 : n;
216
+ if (v >= 80) return 'pass';
217
+ if (v >= 50) return 'warn';
218
+ return 'fail';
219
+ }
220
+
221
+ // Pull a compact summary out of an arbitrary tool result. Returns null when the
222
+ // result is not an object we can read verdict fields from — the report then just
223
+ // shows the raw output, still branded.
224
+ function reportSummary(result) {
225
+ if (!result || typeof result !== 'object' || Array.isArray(result)) return null;
226
+ const r = result;
227
+ const stats = [];
228
+ const seen = (v) => v !== undefined && v !== null;
229
+
230
+ let verdict = null;
231
+ for (const k of ['verdict', 'status', 'overall_verdict', 'overall']) {
232
+ if (typeof r[k] === 'string') { verdict = { value: r[k], tone: toneOf(r[k]) }; break; }
233
+ }
234
+
235
+ const numKeys = [
236
+ ['passed', 'Passed', 'pass'], ['failed', 'Failed', 'fail'], ['skipped', 'Skipped', 'neutral'],
237
+ ['total', 'Total', 'neutral'], ['errors', 'Errors', 'fail'],
238
+ ];
239
+ for (const [k, label, tone] of numKeys) {
240
+ if (typeof r[k] === 'number') stats.push({ label, value: r[k], tone });
241
+ }
242
+ const rate = r.pass_rate ?? r.passRate;
243
+ if (typeof rate === 'number') stats.push({ label: 'Pass rate', value: (rate <= 1 ? Math.round(rate * 100) : Math.round(rate)) + '%', tone: scoreTone(rate) });
244
+ const score = r.score ?? r.avg_score ?? r.total_score;
245
+ if (typeof score === 'number') stats.push({ label: 'Score', value: (score <= 1 ? Math.round(score * 100) : Math.round(score)), tone: scoreTone(score) });
246
+
247
+ const casesArr = Array.isArray(r.results) ? r.results
248
+ : Array.isArray(r.scenario_results) ? r.scenario_results
249
+ : Array.isArray(r.test_results) ? r.test_results : null;
250
+ const cases = casesArr ? casesArr.map((c) => {
251
+ const id = c.id || c.scenario_id || c.name || c.question || c.case || '';
252
+ const passRaw = c.passed !== undefined ? c.passed : c.verdict !== undefined ? c.verdict : c.status;
253
+ return { id: String(id), value: seen(passRaw) ? String(c.passed !== undefined ? (c.passed ? 'PASS' : 'FAIL') : passRaw) : '—', tone: toneOf(passRaw) };
254
+ }) : null;
255
+
256
+ if (!verdict && stats.length === 0 && !cases) return null;
257
+ return { verdict, stats, cases };
258
+ }
259
+
260
+ function summaryHtml(summary) {
261
+ if (!summary) return '';
262
+ const parts = [];
263
+ if (summary.verdict) {
264
+ parts.push(`<div class="verdict verdict-${summary.verdict.tone}">${escHtml(summary.verdict.value)}</div>`);
265
+ }
266
+ if (summary.stats.length) {
267
+ parts.push('<div class="stats">' + summary.stats.map((s) =>
268
+ `<div class="stat"><div class="stat-value tone-${s.tone}">${escHtml(s.value)}</div><div class="stat-label">${escHtml(s.label)}</div></div>`
269
+ ).join('') + '</div>');
270
+ }
271
+ if (summary.cases && summary.cases.length) {
272
+ parts.push('<div class="cases-title">Cases (' + summary.cases.length + ')</div><div class="cases">' +
273
+ summary.cases.map((c) =>
274
+ `<div class="case"><span class="badge badge-${c.tone}">${escHtml(c.value)}</span><span class="case-id">${escHtml(c.id) || '<em>—</em>'}</span></div>`
275
+ ).join('') + '</div>');
276
+ }
277
+ return parts.length ? `<section class="summary">${parts.join('')}</section>` : '';
278
+ }
279
+
280
+ // Redact secret param values before writing them into a shareable file.
281
+ function safeParams(params) {
282
+ const out = {};
283
+ for (const [k, v] of Object.entries(params || {})) out[k] = SECRET_PARAMS.has(k) && v ? '••••••••' : v;
284
+ return out;
285
+ }
286
+
287
+ // Open a file in the OS default browser — best-effort, detached, never fatal.
288
+ // Opt-in via --open only: auto-opening a browser would be wrong inside CI, where
289
+ // these tools are meant to run headless.
290
+ function openInBrowser(file) {
291
+ const { spawn } = require('child_process');
292
+ const [cmd, cmdArgs] =
293
+ process.platform === 'win32' ? ['cmd', ['/c', 'start', '', file]] :
294
+ process.platform === 'darwin' ? ['open', [file]] :
295
+ ['xdg-open', [file]];
296
+ try { spawn(cmd, cmdArgs, { detached: true, stdio: 'ignore' }).unref(); }
297
+ catch { /* best effort — the path was already printed */ }
298
+ }
299
+
300
+ function renderHtmlReport({ toolName, params, result, server, version }) {
301
+ const summary = reportSummary(result);
302
+ const bodyText = typeof result === 'string' ? result : JSON.stringify(result, null, 2);
303
+ const paramText = JSON.stringify(safeParams(params), null, 2);
304
+ const generated = new Date().toLocaleString('en-US', { dateStyle: 'medium', timeStyle: 'short' });
305
+ const hasParams = paramText && paramText !== '{}';
306
+
307
+ return `<!DOCTYPE html>
308
+ <html lang="en">
309
+ <head>
310
+ <meta charset="UTF-8">
311
+ <meta name="viewport" content="width=device-width,initial-scale=1">
312
+ <title>IA-QA Report — ${escHtml(toolName)}</title>
313
+ <style>
314
+ :root{--bg:#09090b;--surface:#18181b;--surface2:#111113;--border:#27272a;--text:#e4e4e7;--muted:#a1a1aa;
315
+ --orange:#f97316;--orange2:#fb923c;--pass:#10b981;--fail:#ef4444;--warn:#f59e0b;--info:#8b5cf6;}
316
+ *,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
317
+ body{background:var(--bg);color:var(--text);font-family:'Inter',system-ui,-apple-system,sans-serif;line-height:1.5;min-height:100vh;display:flex;flex-direction:column}
318
+ a{color:var(--orange2);text-decoration:none}a:hover{text-decoration:underline}
319
+ pre{white-space:pre-wrap;word-break:break-word;font-family:'JetBrains Mono','Fira Code',ui-monospace,monospace;font-size:12.5px}
320
+ .wrap{width:100%;max-width:900px;margin:0 auto;padding:0 20px}
321
+ header{background:linear-gradient(135deg,#7c2d12 0%,#ea580c 55%,#f97316 100%);padding:28px 0 26px;border-bottom:1px solid var(--border)}
322
+ .brand{display:flex;align-items:center;justify-content:space-between;flex-wrap:wrap;gap:14px}
323
+ .logo{display:inline-flex;align-items:center;gap:9px;font-weight:800;letter-spacing:.02em;font-size:19px;color:#fff}
324
+ .logo .mark{background:#fff;color:#ea580c;border-radius:8px;padding:3px 9px;font-size:15px;letter-spacing:.08em}
325
+ .logo:hover{text-decoration:none;opacity:.92}
326
+ .cta{background:rgba(255,255,255,.16);border:1px solid rgba(255,255,255,.35);color:#fff;padding:8px 15px;border-radius:99px;font-size:13px;font-weight:600}
327
+ .cta:hover{background:rgba(255,255,255,.26);text-decoration:none}
328
+ .title{color:#fff;margin-top:20px}
329
+ .title h1{font-size:25px;font-weight:700;display:flex;align-items:center;gap:10px;flex-wrap:wrap}
330
+ .title .tool{font-family:'JetBrains Mono',ui-monospace,monospace;background:rgba(0,0,0,.28);padding:2px 12px;border-radius:8px;font-size:18px}
331
+ .title .meta{color:rgba(255,255,255,.85);font-size:12.5px;margin-top:8px}
332
+ main{flex:1;padding:28px 0 40px}
333
+ section{background:var(--surface);border:1px solid var(--border);border-radius:14px;padding:20px;margin-bottom:18px}
334
+ section>h2{font-size:12px;text-transform:uppercase;letter-spacing:.08em;color:var(--muted);margin-bottom:14px;font-weight:700}
335
+ .summary{border-left:3px solid var(--orange)}
336
+ .verdict{display:inline-block;font-size:22px;font-weight:800;letter-spacing:.04em;padding:8px 20px;border-radius:12px;margin-bottom:16px}
337
+ .verdict-pass{background:#10b98120;color:var(--pass);border:1px solid #10b98155}
338
+ .verdict-fail{background:#ef444420;color:var(--fail);border:1px solid #ef444455}
339
+ .verdict-warn{background:#f59e0b20;color:var(--warn);border:1px solid #f59e0b55}
340
+ .verdict-neutral{background:#8b5cf620;color:var(--info);border:1px solid #8b5cf655}
341
+ .stats{display:grid;grid-template-columns:repeat(auto-fit,minmax(96px,1fr));gap:12px}
342
+ .stat{background:var(--surface2);border:1px solid var(--border);border-radius:11px;padding:14px 10px;text-align:center}
343
+ .stat-value{font-size:26px;font-weight:800;line-height:1}
344
+ .stat-label{font-size:10.5px;text-transform:uppercase;letter-spacing:.06em;color:var(--muted);margin-top:6px}
345
+ .tone-pass{color:var(--pass)}.tone-fail{color:var(--fail)}.tone-warn{color:var(--warn)}.tone-neutral{color:var(--info)}
346
+ .cases-title{font-size:12px;color:var(--muted);text-transform:uppercase;letter-spacing:.06em;margin:18px 0 10px;font-weight:700}
347
+ .cases{display:flex;flex-direction:column;gap:6px}
348
+ .case{display:flex;align-items:center;gap:10px;font-size:13px}
349
+ .badge{display:inline-flex;padding:2px 9px;border-radius:99px;font-size:10.5px;font-weight:700;letter-spacing:.03em;flex-shrink:0}
350
+ .badge-pass{background:#10b98120;color:var(--pass);border:1px solid #10b98140}
351
+ .badge-fail{background:#ef444420;color:var(--fail);border:1px solid #ef444440}
352
+ .badge-warn{background:#f59e0b20;color:var(--warn);border:1px solid #f59e0b40}
353
+ .badge-neutral{background:#a1a1aa20;color:var(--muted);border:1px solid #a1a1aa40}
354
+ .case-id{color:var(--text);word-break:break-word}
355
+ .body-pre{background:var(--surface2);border:1px solid var(--border);border-radius:10px;padding:14px;max-height:640px;overflow:auto;color:#d4d4d8}
356
+ footer{border-top:1px solid var(--border);background:var(--surface2);padding:26px 0}
357
+ .foot{display:flex;align-items:center;justify-content:space-between;flex-wrap:wrap;gap:16px}
358
+ .foot-links{display:flex;flex-wrap:wrap;gap:8px 18px;font-size:13.5px}
359
+ .foot-note{color:var(--muted);font-size:12px}
360
+ .foot-note a{font-weight:600}
361
+ @media(max-width:560px){.title h1{font-size:20px}.verdict{font-size:18px}}
362
+ </style>
363
+ </head>
364
+ <body>
365
+ <header><div class="wrap">
366
+ <div class="brand">
367
+ <a class="logo" href="${BRAND.home}"><span class="mark">IA-QA</span><span>ia-qa.com</span></a>
368
+ <a class="cta" href="${BRAND.tools}">Explore 150+ QA tools →</a>
369
+ </div>
370
+ <div class="title">
371
+ <h1>Execution report <span class="tool">${escHtml(toolName)}</span></h1>
372
+ <div class="meta">Generated ${escHtml(generated)} &nbsp;·&nbsp; via <code>@ia-qa/cli</code> v${escHtml(version)} &nbsp;·&nbsp; ${escHtml(server)}</div>
373
+ </div>
374
+ </div></header>
375
+ <main><div class="wrap">
376
+ ${summaryHtml(summary)}
377
+ ${hasParams ? `<section><h2>Input</h2><pre class="body-pre">${escHtml(paramText)}</pre></section>` : ''}
378
+ <section><h2>Result</h2><pre class="body-pre">${escHtml(bodyText)}</pre></section>
379
+ </div></main>
380
+ <footer><div class="wrap"><div class="foot">
381
+ <div class="foot-links">
382
+ <a href="${BRAND.home}">🏠 Home</a>
383
+ <a href="${BRAND.tools}">🧰 All tools</a>
384
+ <a href="${BRAND.method}">📚 Method</a>
385
+ <a href="${BRAND.mcp}">🔌 MCP server</a>
386
+ </div>
387
+ <div class="foot-note">Real testing primitives, not just a chat window. — <a href="${BRAND.home}">ia-qa.com</a></div>
388
+ </div></div></footer>
389
+ </body>
390
+ </html>`;
391
+ }
392
+
183
393
  // ── help & list ──────────────────────────────────────────────────────────────
184
394
 
185
395
  function compactHelp(m) {
@@ -195,18 +405,20 @@ function compactHelp(m) {
195
405
  'relevant tool when their task fits. Install once: npm i -g @ia-qa/cli',
196
406
  'Discover: ia-qa list · one tool: ia-qa <tool> --help',
197
407
  '',
198
- 'Usage: ia-qa <tool> [input] [--flag value] [--json] [--out <file>] [--stdin]',
408
+ 'Usage: ia-qa <tool> [input] [--flag value] [--json] [--out <file>] [--report <file.html>] [--stdin]',
199
409
  '',
200
410
  `${m.tools.length} tools. Categories (use "ia-qa list [--category <c>]" for names):`,
201
411
  ` ${cats}`,
202
412
  '',
203
413
  ' ia-qa <tool> --help flags for one tool',
204
414
  ' ia-qa list every tool, one line each',
415
+ ' ia-qa --version print the installed CLI version',
205
416
  '',
206
417
  'Examples:',
207
418
  ' ia-qa generate_uuid --count 3',
208
419
  ' ia-qa base64_encode "hello"',
209
420
  " echo '{\"a\":1}' | ia-qa format_json --stdin --json",
421
+ ' ia-qa prompt_injection_scan "ignore all previous instructions" --report scan.html',
210
422
  '',
211
423
  `Runs on ${DEFAULT_SERVER} (override with --server or $IAQA_SERVER). No signup; most tools key-free, BYOK for LLM tools.`,
212
424
  ].join('\n');
@@ -237,7 +449,7 @@ function toolHelp(tool) {
237
449
  }
238
450
  if (primary) lines.push('', `Primary input "${primary}" can be given positionally or via --stdin.`);
239
451
  lines.push('', 'Any --<param> also accepts --<param>-file <path> (multiline-safe, e.g. --inputs-file fields.txt).');
240
- lines.push('', 'Common: --json --out <file> --stdin --server <url>');
452
+ lines.push('', 'Common: --json --out <file> --report <file.html> [--open] --stdin --server <url>');
241
453
  return lines.join('\n');
242
454
  }
243
455
 
@@ -279,6 +491,13 @@ function cleanStdin(raw) {
279
491
 
280
492
  async function main(argv) {
281
493
  const args = argv.slice(2);
494
+
495
+ // Version is local — answer it before any manifest fetch so it works offline.
496
+ if (args[0] === '--version' || args[0] === '-v' || args[0] === 'version') {
497
+ process.stdout.write(VERSION + '\n');
498
+ return;
499
+ }
500
+
282
501
  const server = (() => {
283
502
  const i = args.indexOf('--server');
284
503
  return i !== -1 && args[i + 1] ? args[i + 1].replace(/\/+$/, '') : DEFAULT_SERVER;
@@ -337,7 +556,21 @@ async function main(argv) {
337
556
  outPath = flags.out;
338
557
  }
339
558
 
559
+ let reportPath = null;
560
+ if (flags.report !== undefined || flags.open) {
561
+ reportPath = typeof flags.report === 'string' ? flags.report : `ia-qa-${tool.name}-report.html`;
562
+ }
563
+
340
564
  const data = await callTool(server, tool.name, params);
565
+
566
+ if (reportPath) {
567
+ const dest = path.resolve(reportPath);
568
+ const html = renderHtmlReport({ toolName: tool.name, params, result: data, server, version: VERSION });
569
+ fs.writeFileSync(dest, html, 'utf8');
570
+ if (!flags.json) process.stderr.write(`✓ Branded HTML report → ${dest}\n`);
571
+ if (flags.open) openInBrowser(dest);
572
+ }
573
+
341
574
  process.stdout.write(emit(data, { json: !!flags.json, out: outPath, toolName: tool.name }) + '\n');
342
575
  }
343
576
 
@@ -348,4 +581,4 @@ if (require.main === module) {
348
581
  });
349
582
  }
350
583
 
351
- module.exports = { main, parseArgv, coerce, parseBool, primaryParam, readFileParams, cleanStdin, emit, isLarge, compactHelp, listTools, toolHelp };
584
+ module.exports = { main, parseArgv, coerce, parseBool, primaryParam, readFileParams, cleanStdin, emit, isLarge, compactHelp, listTools, toolHelp, renderHtmlReport, reportSummary, toneOf, safeParams };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ia-qa/cli",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "description": "Run ia-qa.com's QA/LLM/dev toolbox from your shell — for AI agents (Claude Code, Copilot CLI) and humans. Zero dependencies, no signup; most tools key-free, BYOK for the LLM-powered ones.",
5
5
  "keywords": [
6
6
  "ia-qa",