@ia-qa/cli 1.0.0

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 +51 -0
  2. package/index.js +288 -0
  3. package/package.json +26 -0
package/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # @ia-qa/cli
2
+
3
+ Run [ia-qa.com](https://www.ia-qa.com)'s **148 QA / LLM / dev tools** from your shell — for AI agents
4
+ (Claude Code, Copilot CLI, Cursor agents) and humans. **Zero dependencies. No signup. No API key.**
5
+
6
+ The CLI carries no business logic: it discovers tools from the public MCP manifest and runs them on
7
+ the hosted server (`https://www.ia-qa.com`). Requires **Node ≥ 18**.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ # One-off, no install:
13
+ npx @ia-qa/cli --help
14
+
15
+ # Or global:
16
+ npm install -g @ia-qa/cli
17
+ ia-qa --help
18
+
19
+ # Or download the zip from https://www.ia-qa.com/downloads/ia-qa-cli.zip and:
20
+ node ia-qa.js --help
21
+ ```
22
+
23
+ ## Use
24
+
25
+ ```bash
26
+ ia-qa --help # categories + examples
27
+ ia-qa list [--category encoding] # every tool, one line each
28
+ ia-qa <tool> --help # flags for one tool
29
+
30
+ ia-qa generate_uuid --count 3
31
+ ia-qa base64_encode "hello"
32
+ ia-qa hash_text "secret" --algorithm sha256
33
+ echo '{"b":2,"a":1}' | ia-qa format_json --stdin
34
+
35
+ ia-qa text_stats "hello world" --json # machine JSON to stdout
36
+ ia-qa split_chunks "$(cat doc.txt)" --chunk_size 256 --out chunks.json
37
+ ```
38
+
39
+ - **`--json`** emits machine-parsable JSON (default is human-readable).
40
+ - **Large outputs** are written to a temp file and the path is printed; **`--out <file>`** chooses it.
41
+ - **`--stdin`** (or `-` as the positional) reads the primary input from stdin.
42
+ - **`--server <url>`** / **`$IAQA_SERVER`** point at another server (default `https://www.ia-qa.com`,
43
+ or a self-hosted ia-qa server).
44
+ - **Exit codes**: `0` success · `2` bad input / missing param · `1` unexpected / server error.
45
+
46
+ ## Also available as MCP
47
+
48
+ Every tool here is also callable over the [Model Context Protocol](https://www.ia-qa.com/mcp-server)
49
+ — point Claude Desktop, Cursor, Windsurf, or any MCP client at `https://www.ia-qa.com/mcp`.
50
+
51
+ MIT · Powered by [IA-QA](https://www.ia-qa.com).
package/index.js ADDED
@@ -0,0 +1,288 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ /**
5
+ * @ia-qa/cli — the ia-qa.com toolbox from your shell.
6
+ *
7
+ * A tiny, zero-dependency client for AI agents (Claude Code, Copilot CLI…) and humans.
8
+ * It carries NO business logic: it discovers tools from the public MCP manifest and runs
9
+ * them on the hosted server (https://www.ia-qa.com). 148 QA/LLM/dev tools, no signup, no key.
10
+ *
11
+ * ia-qa <tool> [input] [--flag value] [--json] [--out <file>] [--stdin]
12
+ * ia-qa list [--category <c>]
13
+ * ia-qa <tool> --help
14
+ * ia-qa --help
15
+ *
16
+ * Requires Node >= 18 (global fetch). Override the server with --server or $IAQA_SERVER.
17
+ */
18
+
19
+ const fs = require('fs');
20
+ const os = require('os');
21
+ const path = require('path');
22
+ const crypto = require('crypto');
23
+
24
+ // Param names that carry secrets — exact match only (never substring: `token`
25
+ // must not catch `token_estimate`, `tokens`, etc.).
26
+ const SECRET_PARAMS = new Set(['api_key', 'api_keys', 'access_key', 'secret', 'password', 'passwd', 'token', 'auth_token']);
27
+
28
+ const DEFAULT_SERVER = (process.env.IAQA_SERVER || 'https://www.ia-qa.com').replace(/\/+$/, '');
29
+ const INLINE_MAX_CHARS = 4000;
30
+ const INLINE_MAX_LINES = 100;
31
+
32
+ // ── argv parsing (no dependency) ─────────────────────────────────────────────
33
+
34
+ function parseArgv(argv) {
35
+ const positional = [];
36
+ const flags = {};
37
+ for (let i = 0; i < argv.length; i++) {
38
+ const tok = argv[i];
39
+ if (tok.startsWith('--')) {
40
+ const key = tok.slice(2);
41
+ const next = argv[i + 1];
42
+ if (next === undefined || next.startsWith('--')) {
43
+ flags[key] = flags[key] === undefined ? true : flags[key];
44
+ } else {
45
+ const val = next;
46
+ if (flags[key] === undefined) flags[key] = val;
47
+ else flags[key] = [].concat(flags[key], val); // repeated → array
48
+ i++;
49
+ }
50
+ } else {
51
+ positional.push(tok);
52
+ }
53
+ }
54
+ return { positional, flags };
55
+ }
56
+
57
+ // ── typed coercion from a tool's JSON Schema ─────────────────────────────────
58
+
59
+ function parseBool(v) {
60
+ if (v === true || v === undefined) return true;
61
+ return !/^(false|0|no|off)$/i.test(String(v));
62
+ }
63
+
64
+ function coerce(prop, raw) {
65
+ const type = prop && prop.type;
66
+ if (type === 'boolean') return parseBool(raw);
67
+ if (type === 'integer' || type === 'number') {
68
+ const n = Number(raw);
69
+ if (Number.isNaN(n)) throw new CliError(`expected a number, got: ${raw}`, 2);
70
+ return n;
71
+ }
72
+ if (type === 'array') {
73
+ if (Array.isArray(raw)) return raw;
74
+ const s = String(raw).trim();
75
+ if (s.startsWith('[') || s.startsWith('{')) {
76
+ try { const j = JSON.parse(s); return Array.isArray(j) ? j : [j]; } catch { /* fall through */ }
77
+ }
78
+ return s.split(',').map((x) => x.trim()).filter(Boolean);
79
+ }
80
+ if (type === 'object') {
81
+ try { return JSON.parse(raw); } catch { throw new CliError(`expected JSON object, got: ${String(raw).slice(0, 40)}`, 2); }
82
+ }
83
+ return String(raw);
84
+ }
85
+
86
+ function primaryParam(schema) {
87
+ const props = (schema && schema.properties) || {};
88
+ const required = (schema && schema.required) || [];
89
+ if (props.input) return 'input';
90
+ if (props.text) return 'text';
91
+ const reqStr = required.find((k) => (props[k] && props[k].type || 'string') === 'string');
92
+ if (reqStr) return reqStr;
93
+ return Object.keys(props).find((k) => (props[k].type || 'string') === 'string') || null;
94
+ }
95
+
96
+ // ── HTTP to the public MCP server ────────────────────────────────────────────
97
+
98
+ class CliError extends Error {
99
+ constructor(message, exitCode = 1) { super(message); this.name = 'CliError'; this.exitCode = exitCode; }
100
+ }
101
+
102
+ let _manifest = null;
103
+ async function manifest(server) {
104
+ if (_manifest) return _manifest;
105
+ let res;
106
+ try { res = await fetch(`${server}/mcp?full=1`); }
107
+ catch (e) { throw new CliError(`Cannot reach ia-qa server at ${server} (${e.message}). Set --server or $IAQA_SERVER.`, 1); }
108
+ if (!res.ok) throw new CliError(`Server ${server} returned HTTP ${res.status} for the tool manifest.`, 1);
109
+ _manifest = await res.json();
110
+ return _manifest;
111
+ }
112
+
113
+ async function callTool(server, name, parameters) {
114
+ let res;
115
+ try {
116
+ res = await fetch(`${server}/mcp/call`, {
117
+ method: 'POST',
118
+ headers: { 'Content-Type': 'application/json', 'X-Client': 'ia-qa-cli' },
119
+ body: JSON.stringify({ name, parameters }),
120
+ });
121
+ } catch (e) {
122
+ throw new CliError(`Cannot reach ia-qa server at ${server} (${e.message}). Set --server or $IAQA_SERVER.`, 1);
123
+ }
124
+ let body;
125
+ try { body = await res.json(); } catch { throw new CliError(`Non-JSON response (HTTP ${res.status}) from ${server}.`, 1); }
126
+ if (!res.ok || body.error) throw new CliError(body.error || `HTTP ${res.status}`, res.status >= 400 && res.status < 500 ? 2 : 1);
127
+ return body.result;
128
+ }
129
+
130
+ // ── output formatting ────────────────────────────────────────────────────────
131
+
132
+ function serialize(data, json) {
133
+ if (typeof data === 'string') return data;
134
+ return JSON.stringify(data, null, json ? 0 : 2);
135
+ }
136
+ function isLarge(text) {
137
+ if (text.length > INLINE_MAX_CHARS) return true;
138
+ let lines = 1;
139
+ for (let i = 0; i < text.length; i++) if (text[i] === '\n' && ++lines > INLINE_MAX_LINES) return true;
140
+ return false;
141
+ }
142
+ // Write to a fresh, unpredictable, private temp file. `wx` fails if the path
143
+ // already exists, defeating a symlink/pre-creation attack in a shared tmpdir.
144
+ function writeSecureTmp(toolName, body) {
145
+ const safe = String(toolName).replace(/[^a-z0-9_-]/gi, '_');
146
+ for (let i = 0; i < 5; i++) {
147
+ const dest = path.join(os.tmpdir(), `ia-qa-${safe}-${crypto.randomBytes(9).toString('hex')}.json`);
148
+ try { fs.writeFileSync(dest, body, { encoding: 'utf8', flag: 'wx', mode: 0o600 }); return dest; }
149
+ catch (e) { if (e.code !== 'EEXIST') throw e; }
150
+ }
151
+ throw new CliError('Could not create a temp output file.', 1);
152
+ }
153
+
154
+ function emit(data, { json, out, toolName }) {
155
+ const body = serialize(data, json);
156
+ if (out) {
157
+ fs.writeFileSync(path.resolve(out), body, 'utf8');
158
+ return json ? JSON.stringify({ output_file: path.resolve(out), bytes: Buffer.byteLength(body) })
159
+ : `✓ Wrote ${toolName} output → ${path.resolve(out)} (${Buffer.byteLength(body)} bytes)`;
160
+ }
161
+ if (isLarge(body)) {
162
+ const dest = writeSecureTmp(toolName, body);
163
+ const preview = body.slice(0, 200).replace(/\s+/g, ' ').trim();
164
+ return json ? JSON.stringify({ output_file: dest, bytes: Buffer.byteLength(body), preview })
165
+ : `⧉ ${toolName} output is large (${Buffer.byteLength(body)} bytes) — written to a file:\n ${dest}\n preview: ${preview}…\n (use --out <file> for a path, or --json for machine JSON)`;
166
+ }
167
+ return body;
168
+ }
169
+
170
+ // ── help & list ──────────────────────────────────────────────────────────────
171
+
172
+ function compactHelp(m) {
173
+ const groups = {};
174
+ for (const t of m.tools) (groups[t.category || 'other'] = groups[t.category || 'other'] || []).push(t.name);
175
+ const cats = Object.entries(groups).sort((a, b) => b[1].length - a[1].length)
176
+ .map(([c, n]) => `${c}(${n.length})`).join(' ');
177
+ return [
178
+ 'ia-qa — run ia-qa.com QA/LLM tools from the shell',
179
+ 'Usage: ia-qa <tool> [input] [--flag value] [--json] [--out <file>] [--stdin]',
180
+ '',
181
+ `${m.tools.length} tools. Categories (use "ia-qa list [--category <c>]" for names):`,
182
+ ` ${cats}`,
183
+ '',
184
+ ' ia-qa <tool> --help flags for one tool',
185
+ ' ia-qa list every tool, one line each',
186
+ '',
187
+ 'Examples:',
188
+ ' ia-qa generate_uuid --count 3',
189
+ ' ia-qa base64_encode "hello"',
190
+ " echo '{\"a\":1}' | ia-qa format_json --stdin --json",
191
+ '',
192
+ `Runs on ${DEFAULT_SERVER} (override with --server or $IAQA_SERVER). No key, no signup.`,
193
+ ].join('\n');
194
+ }
195
+
196
+ function listTools(m, category) {
197
+ let tools = m.tools;
198
+ if (category) tools = tools.filter((t) => (t.category || 'other') === category);
199
+ if (!tools.length) {
200
+ const cats = [...new Set(m.tools.map((t) => t.category || 'other'))].sort();
201
+ return `No tools in category "${category}". Available: ${cats.join(', ')}`;
202
+ }
203
+ return tools.map((t) => `${t.name}\t${(t.description || '').split('. ')[0].slice(0, 80)}`).join('\n');
204
+ }
205
+
206
+ function toolHelp(tool) {
207
+ const props = (tool.inputSchema && tool.inputSchema.properties) || {};
208
+ const required = new Set((tool.inputSchema && tool.inputSchema.required) || []);
209
+ const primary = primaryParam(tool.inputSchema);
210
+ const lines = [`Usage: ia-qa ${tool.name} [input] [options]`, '', tool.description || ''];
211
+ if (Object.keys(props).length) {
212
+ lines.push('', 'Options:');
213
+ for (const [k, p] of Object.entries(props)) {
214
+ const req = required.has(k) ? ' (required)' : '';
215
+ const en = Array.isArray(p.enum) ? ` [${p.enum.join('|')}]` : '';
216
+ lines.push(` --${k}${en}\t${p.description || p.type || ''}${req}`);
217
+ }
218
+ }
219
+ if (primary) lines.push('', `Primary input "${primary}" can be given positionally or via --stdin.`);
220
+ lines.push('', 'Common: --json --out <file> --stdin --server <url>');
221
+ return lines.join('\n');
222
+ }
223
+
224
+ // ── main ─────────────────────────────────────────────────────────────────────
225
+
226
+ async function main(argv) {
227
+ const args = argv.slice(2);
228
+ const server = (() => {
229
+ const i = args.indexOf('--server');
230
+ return i !== -1 && args[i + 1] ? args[i + 1].replace(/\/+$/, '') : DEFAULT_SERVER;
231
+ })();
232
+
233
+ if (args.length === 0 || args[0] === '--help' || args[0] === '-h' || args[0] === 'help') {
234
+ process.stdout.write(compactHelp(await manifest(server)) + '\n');
235
+ return;
236
+ }
237
+
238
+ const command = args[0];
239
+ const rest = args.slice(1);
240
+ const { positional, flags } = parseArgv(rest);
241
+
242
+ if (command === 'list') {
243
+ process.stdout.write(listTools(await manifest(server), flags.category) + '\n');
244
+ return;
245
+ }
246
+
247
+ const m = await manifest(server);
248
+ const tool = m.tools.find((t) => t.name === command);
249
+ if (!tool) throw new CliError(`Unknown tool: "${command}". Run "ia-qa list" to see all tools.`, 2);
250
+
251
+ if (flags.help) { process.stdout.write(toolHelp(tool) + '\n'); return; }
252
+
253
+ // Assemble typed parameters from the tool's schema.
254
+ const schema = tool.inputSchema || {};
255
+ const props = schema.properties || {};
256
+ const params = {};
257
+ for (const [k, prop] of Object.entries(props)) {
258
+ if (flags[k] !== undefined) params[k] = coerce(prop, flags[k]);
259
+ }
260
+ const primary = primaryParam(schema);
261
+ if (primary) {
262
+ if (flags.stdin || positional[0] === '-') params[primary] = fs.readFileSync(0, 'utf8').replace(/\n$/, '');
263
+ else if (positional[0] !== undefined && params[primary] === undefined) params[primary] = coerce(props[primary], positional[0]);
264
+ }
265
+ const missing = (schema.required || []).filter((k) => params[k] === undefined || params[k] === '');
266
+ if (missing.length) {
267
+ const hint = primary && missing.includes(primary) ? ` (pass it positionally, with --${primary}, or --stdin)` : '';
268
+ throw new CliError(`${tool.name}: missing required ${missing.length > 1 ? 'params' : 'param'}: ${missing.join(', ')}${hint}`, 2);
269
+ }
270
+
271
+ // Warn before shipping a secret to anywhere other than the default HTTPS server.
272
+ const secretKeys = Object.keys(params).filter((k) => SECRET_PARAMS.has(k) && params[k]);
273
+ if (secretKeys.length && (server !== DEFAULT_SERVER || !server.startsWith('https://'))) {
274
+ process.stderr.write(`⚠ Sending secret param(s) [${secretKeys.join(', ')}] to ${server} — make sure you trust this server (set via --server/$IAQA_SERVER).\n`);
275
+ }
276
+
277
+ const data = await callTool(server, tool.name, params);
278
+ process.stdout.write(emit(data, { json: !!flags.json, out: typeof flags.out === 'string' ? flags.out : null, toolName: tool.name }) + '\n');
279
+ }
280
+
281
+ if (require.main === module) {
282
+ main(process.argv).catch((err) => {
283
+ process.stderr.write(`✗ ${err.message}\n`);
284
+ process.exit(err instanceof CliError ? err.exitCode : 1);
285
+ });
286
+ }
287
+
288
+ module.exports = { main, parseArgv, coerce, parseBool, primaryParam, emit, isLarge, compactHelp, listTools, toolHelp };
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@ia-qa/cli",
3
+ "version": "1.0.0",
4
+ "description": "Run ia-qa.com's 148 QA/LLM/dev tools from your shell — for AI agents (Claude Code, Copilot CLI) and humans. Zero dependencies, no signup, no API key.",
5
+ "keywords": ["ia-qa", "cli", "mcp", "qa", "llm", "testing", "ai-agent", "developer-tools"],
6
+ "homepage": "https://www.ia-qa.com",
7
+ "bugs": "https://www.ia-qa.com/contactUs",
8
+ "license": "MIT",
9
+ "author": "Jean-Christophe Jamet",
10
+ "type": "commonjs",
11
+ "bin": {
12
+ "ia-qa": "./index.js"
13
+ },
14
+ "main": "index.js",
15
+ "files": [
16
+ "index.js",
17
+ "README.md"
18
+ ],
19
+ "engines": {
20
+ "node": ">=18.0.0"
21
+ },
22
+ "publishConfig": {
23
+ "access": "public"
24
+ },
25
+ "dependencies": {}
26
+ }