@wireweave/cli 0.1.0-beta.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 +61 -0
  2. package/dist/index.js +812 -0
  3. package/package.json +77 -0
package/README.md ADDED
@@ -0,0 +1,61 @@
1
+ Beta — Wireweave v2.0 베타 단계
2
+
3
+ # @wireweave/cli
4
+
5
+ Command-line companion for the Wireweave wireframe DSL. Authenticate, render `.wf`
6
+ files, and talk to the Wireweave AI agent from your terminal.
7
+
8
+ > Status: **beta**. Published under the `beta` dist-tag on npm. APIs and command
9
+ > shape may still change before `1.0.0`.
10
+
11
+ ## Install
12
+
13
+ ```bash
14
+ npm install -g @wireweave/cli@beta
15
+ ```
16
+
17
+ Requires Node.js 18+.
18
+
19
+ ## Usage
20
+
21
+ ```bash
22
+ # Sign in (paste an API key from https://dashboard.wireweave.org/dashboard/keys)
23
+ wireweave login
24
+
25
+ # Confirm you are signed in
26
+ wireweave whoami
27
+
28
+ # Render a wireframe file to HTML
29
+ wireweave render design.wf
30
+
31
+ # Ask the Wireweave agent for help
32
+ wireweave agent "make the hero section more compact"
33
+ ```
34
+
35
+ ## Environment
36
+
37
+ | Variable | Default | Purpose |
38
+ | ------------------- | --------------------------- | -------------------------------------- |
39
+ | `WIREWEAVE_API_URL` | `https://api.wireweave.org` | Override the API base (self-hosted). |
40
+ | `WIREWEAVE_API_KEY` | — | Per-shell override of the saved token. |
41
+
42
+ The persistent token lives at `~/.wireweave/config.json` with shape
43
+ `{ "token": string, "apiUrl"?: string }` and is shared with
44
+ `@wireweave/skill-cursor`.
45
+
46
+ ## Beta scope
47
+
48
+ The first public beta ships these subcommands as functional stubs that resolve
49
+ exit code 0 and print a friendly "coming soon" message where the network call
50
+ is not yet wired:
51
+
52
+ - `login` — prints the dashboard URL and the config file location
53
+ - `whoami` — reads the local token and reports the trailing 4 chars
54
+ - `render` — reserved for the local HTML renderer
55
+ - `agent` — reserved for the v2.0 agent stream
56
+
57
+ Each release on the `beta` tag will fill in one of these calls end-to-end.
58
+
59
+ ## License
60
+
61
+ MIT
package/dist/index.js ADDED
@@ -0,0 +1,812 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/index.ts
4
+ import { Command } from "commander";
5
+
6
+ // src/commands/login.ts
7
+ import { promises as fs } from "fs";
8
+
9
+ // src/auth.ts
10
+ import {
11
+ clearToken,
12
+ getConfigPath,
13
+ loadToken,
14
+ saveToken,
15
+ verifyToken
16
+ } from "@wireweave/sdk";
17
+ var DEFAULT_API_URL = "https://api.wireweave.org";
18
+ var VERIFY_ENDPOINT = "/billing/balance";
19
+ var AuthError = class extends Error {
20
+ constructor(message, status) {
21
+ super(message);
22
+ this.status = status;
23
+ this.name = "AuthError";
24
+ }
25
+ status;
26
+ };
27
+ function resolveApiUrl(explicit, stored) {
28
+ return explicit ?? stored?.apiUrl ?? process.env.WIREWEAVE_API_URL ?? DEFAULT_API_URL;
29
+ }
30
+ function parseAccountBody(body) {
31
+ if (body === null || typeof body !== "object") return {};
32
+ const record = body;
33
+ const balance = typeof record.balance === "number" ? record.balance : void 0;
34
+ const subscriptionPlan = typeof record.subscriptionPlan === "string" ? record.subscriptionPlan : void 0;
35
+ const monthlyRemaining = typeof record.monthlyRemaining === "number" ? record.monthlyRemaining : void 0;
36
+ return { balance, subscriptionPlan, monthlyRemaining };
37
+ }
38
+ function verifyResultToAccount(apiUrl, token, result) {
39
+ return {
40
+ apiUrl,
41
+ tokenSuffix: token.slice(-4),
42
+ ...parseAccountBody(result.body)
43
+ };
44
+ }
45
+ function statusToMessage(status, fallback) {
46
+ if (status === 401) return "Invalid API key. Get one at https://wireweave.org";
47
+ if (status === 403) return "API key is not allowed to access this account.";
48
+ if (status === 429) return "Rate limited. Wait a moment and try again.";
49
+ if (status >= 500) return "Service temporarily unavailable. Please retry.";
50
+ return fallback;
51
+ }
52
+ async function login(params, deps = {}) {
53
+ const apiKey = params.apiKey.trim();
54
+ if (apiKey.length === 0) {
55
+ throw new AuthError("API key is empty.");
56
+ }
57
+ const apiUrl = resolveApiUrl(params.apiUrl);
58
+ const result = await verifyToken(apiKey, apiUrl, VERIFY_ENDPOINT, deps.fetchFn);
59
+ if (!result.valid) {
60
+ throw new AuthError(
61
+ statusToMessage(result.status, `Login failed (HTTP ${result.status}).`),
62
+ result.status
63
+ );
64
+ }
65
+ await saveToken({ token: apiKey, apiUrl }, deps.authOptions);
66
+ return verifyResultToAccount(apiUrl, apiKey, result);
67
+ }
68
+ async function whoami(deps = {}) {
69
+ const configPath = getConfigPath(deps.authOptions);
70
+ const stored = await loadToken(deps.authOptions);
71
+ if (!stored) {
72
+ return { loggedIn: false, configPath, reason: "not-logged-in" };
73
+ }
74
+ const apiUrl = resolveApiUrl(void 0, stored);
75
+ const result = await verifyToken(stored.token, apiUrl, VERIFY_ENDPOINT, deps.fetchFn);
76
+ if (!result.valid) {
77
+ return { loggedIn: false, configPath, reason: "invalid-token" };
78
+ }
79
+ return {
80
+ loggedIn: true,
81
+ configPath,
82
+ account: verifyResultToAccount(apiUrl, stored.token, result)
83
+ };
84
+ }
85
+ async function logout(deps = {}) {
86
+ const configPath = getConfigPath(deps.authOptions);
87
+ const stored = await loadToken(deps.authOptions);
88
+ if (!stored) {
89
+ return { removed: false, configPath };
90
+ }
91
+ await clearToken(deps.authOptions);
92
+ return { removed: true, configPath };
93
+ }
94
+
95
+ // src/commands/login.ts
96
+ var writeLine = (stream, text) => {
97
+ stream.write(text);
98
+ stream.write("\n");
99
+ };
100
+ async function readStdin(stream) {
101
+ const chunks = [];
102
+ for await (const chunk of stream) {
103
+ chunks.push(typeof chunk === "string" ? Buffer.from(chunk) : chunk);
104
+ }
105
+ return Buffer.concat(chunks).toString("utf8").trim();
106
+ }
107
+ async function resolveApiKey(opts) {
108
+ if (opts.apiKey && opts.apiKey.length > 0) return opts.apiKey;
109
+ const env = opts.env ?? process.env;
110
+ if (env.WIREWEAVE_API_KEY && env.WIREWEAVE_API_KEY.length > 0) return env.WIREWEAVE_API_KEY;
111
+ const stdin = opts.stdin ?? process.stdin;
112
+ if (!("isTTY" in stdin) || stdin.isTTY === false) {
113
+ const piped = await readStdin(stdin);
114
+ if (piped.length > 0) return piped;
115
+ }
116
+ return null;
117
+ }
118
+ async function loginCommand(opts = {}) {
119
+ const stdout = opts.stdout ?? process.stdout;
120
+ const stderr = opts.stderr ?? process.stderr;
121
+ const fsLike = opts.fsLike ?? fs;
122
+ const apiKey = await resolveApiKey(opts);
123
+ if (apiKey === null) {
124
+ writeLine(
125
+ stderr,
126
+ "No API key supplied. Use --api-key, WIREWEAVE_API_KEY, or pipe the key to stdin."
127
+ );
128
+ return 2;
129
+ }
130
+ const params = { apiKey, apiUrl: opts.apiUrl };
131
+ try {
132
+ const account = await login(params, opts.deps);
133
+ writeLine(stdout, `Signed in to ${account.apiUrl} (token ...${account.tokenSuffix}).`);
134
+ if (account.subscriptionPlan) {
135
+ writeLine(
136
+ stdout,
137
+ ` plan: ${account.subscriptionPlan}` + (typeof account.balance === "number" ? `, balance: ${account.balance}` : "")
138
+ );
139
+ }
140
+ const { getConfigPath: getConfigPath2 } = await import("@wireweave/sdk");
141
+ const configPath = getConfigPath2(opts.deps?.authOptions);
142
+ try {
143
+ const stat = await fsLike.stat(configPath);
144
+ const mode = stat.mode & 511;
145
+ if (mode !== 384) {
146
+ writeLine(stderr, `warning: ${configPath} permission is ${mode.toString(8)}, expected 600.`);
147
+ }
148
+ } catch {
149
+ writeLine(stderr, `warning: cannot stat ${configPath}.`);
150
+ }
151
+ return 0;
152
+ } catch (err) {
153
+ if (err instanceof AuthError) {
154
+ writeLine(stderr, `login failed: ${err.message}`);
155
+ return 1;
156
+ }
157
+ writeLine(stderr, `login failed: ${err instanceof Error ? err.message : String(err)}`);
158
+ return 1;
159
+ }
160
+ }
161
+
162
+ // src/commands/whoami.ts
163
+ var writeLine2 = (stream, text) => {
164
+ stream.write(text);
165
+ stream.write("\n");
166
+ };
167
+ async function whoamiCommand(opts = {}) {
168
+ const stdout = opts.stdout ?? process.stdout;
169
+ const stderr = opts.stderr ?? process.stderr;
170
+ try {
171
+ const result = await whoami(opts.deps);
172
+ if (!result.loggedIn) {
173
+ const reason = result.reason === "invalid-token" ? "Stored token is no longer valid. Run `wireweave login`." : "Not logged in. Run `wireweave login`.";
174
+ writeLine2(stdout, reason);
175
+ return result.reason === "invalid-token" ? 1 : 0;
176
+ }
177
+ const account = result.account;
178
+ writeLine2(stdout, `Logged in to ${account.apiUrl} (token ...${account.tokenSuffix}).`);
179
+ if (account.subscriptionPlan) {
180
+ writeLine2(stdout, ` plan: ${account.subscriptionPlan}`);
181
+ }
182
+ if (typeof account.balance === "number") {
183
+ writeLine2(stdout, ` balance: ${account.balance}`);
184
+ }
185
+ if (typeof account.monthlyRemaining === "number") {
186
+ writeLine2(stdout, ` monthly remaining: ${account.monthlyRemaining}`);
187
+ }
188
+ writeLine2(stdout, ` config: ${result.configPath}`);
189
+ return 0;
190
+ } catch (err) {
191
+ writeLine2(stderr, `whoami failed: ${err instanceof Error ? err.message : String(err)}`);
192
+ return 1;
193
+ }
194
+ }
195
+
196
+ // src/commands/logout.ts
197
+ var writeLine3 = (stream, text) => {
198
+ stream.write(text);
199
+ stream.write("\n");
200
+ };
201
+ async function logoutCommand(opts = {}) {
202
+ const stdout = opts.stdout ?? process.stdout;
203
+ const stderr = opts.stderr ?? process.stderr;
204
+ try {
205
+ const result = await logout(opts.deps);
206
+ if (!result.removed) {
207
+ writeLine3(stdout, `Already logged out (no token at ${result.configPath}).`);
208
+ return 0;
209
+ }
210
+ writeLine3(stdout, `Logged out. Removed ${result.configPath}.`);
211
+ return 0;
212
+ } catch (err) {
213
+ writeLine3(stderr, `logout failed: ${err instanceof Error ? err.message : String(err)}`);
214
+ return 1;
215
+ }
216
+ }
217
+
218
+ // src/commands/render.ts
219
+ import { promises as fs2 } from "fs";
220
+
221
+ // src/dispatch-config.ts
222
+ import {
223
+ dispatch,
224
+ loadToken as loadToken2,
225
+ toolEndpoints
226
+ } from "@wireweave/sdk";
227
+ var DEFAULT_API_URL2 = "https://api.wireweave.org";
228
+ function resolveApiUrl2(explicit, stored) {
229
+ return explicit ?? stored ?? process.env.WIREWEAVE_API_URL ?? DEFAULT_API_URL2;
230
+ }
231
+ async function buildDispatchOptions(params = {}) {
232
+ const stored = await loadToken2(params.authOptions);
233
+ const apiKey = params.apiKey ?? stored?.token ?? "";
234
+ const apiUrl = resolveApiUrl2(params.apiUrl, stored?.apiUrl);
235
+ const apiConfig = { apiUrl, apiKey };
236
+ const options = { apiConfig, endpoints: toolEndpoints };
237
+ if (params.fetchFn) options.fetchFn = params.fetchFn;
238
+ return options;
239
+ }
240
+ async function callTool(toolName, args, params = {}) {
241
+ const options = await buildDispatchOptions(params);
242
+ return dispatch(toolName, args, options);
243
+ }
244
+ function extractText(result) {
245
+ return result.content.filter((block) => block.type === "text").map((block) => block.text).join("\n");
246
+ }
247
+ function parseJsonResult(result) {
248
+ return JSON.parse(extractText(result));
249
+ }
250
+
251
+ // src/commands/render.ts
252
+ var writeLine4 = (stream, text) => {
253
+ stream.write(text);
254
+ stream.write("\n");
255
+ };
256
+ async function renderCommand(opts) {
257
+ const stdout = opts.stdout ?? process.stdout;
258
+ const stderr = opts.stderr ?? process.stderr;
259
+ const fsLike = opts.fsLike ?? fs2;
260
+ let source;
261
+ try {
262
+ source = await fsLike.readFile(opts.file, "utf8");
263
+ } catch (err) {
264
+ writeLine4(stderr, `render failed: cannot read ${opts.file}: ${formatError(err)}`);
265
+ return 1;
266
+ }
267
+ const result = await callTool(
268
+ "wireweave_render_html_code",
269
+ { source, theme: opts.theme ?? "light", fullDocument: opts.fullDocument === true },
270
+ opts.dispatchParams
271
+ );
272
+ if (result.isError) {
273
+ writeLine4(stderr, `render failed: ${extractFirstText(result.content)}`);
274
+ return 1;
275
+ }
276
+ const payload = parseJsonResult(result);
277
+ if (!payload.success) {
278
+ writeLine4(stderr, `render failed: ${payload.error ?? "Unknown error"}`);
279
+ return 1;
280
+ }
281
+ const html = payload.html ?? "";
282
+ if (opts.output) {
283
+ try {
284
+ await fsLike.writeFile(opts.output, html, "utf8");
285
+ writeLine4(stdout, `Wrote ${opts.output} (${html.length} bytes)`);
286
+ } catch (err) {
287
+ writeLine4(stderr, `render failed: cannot write ${opts.output}: ${formatError(err)}`);
288
+ return 1;
289
+ }
290
+ } else {
291
+ stdout.write(html);
292
+ if (!html.endsWith("\n")) stdout.write("\n");
293
+ }
294
+ return 0;
295
+ }
296
+ function formatError(err) {
297
+ return err instanceof Error ? err.message : String(err);
298
+ }
299
+ function extractFirstText(content) {
300
+ const first = content.find((b) => b.type === "text");
301
+ return first?.text ?? "Unknown error";
302
+ }
303
+
304
+ // src/commands/parse.ts
305
+ import { promises as fs3 } from "fs";
306
+ var writeLine5 = (stream, text) => {
307
+ stream.write(text);
308
+ stream.write("\n");
309
+ };
310
+ async function parseCommand(opts) {
311
+ const stdout = opts.stdout ?? process.stdout;
312
+ const stderr = opts.stderr ?? process.stderr;
313
+ const fsLike = opts.fsLike ?? fs3;
314
+ let source;
315
+ try {
316
+ source = await fsLike.readFile(opts.file, "utf8");
317
+ } catch (err) {
318
+ writeLine5(stderr, `parse failed: cannot read ${opts.file}: ${formatError2(err)}`);
319
+ return 1;
320
+ }
321
+ const result = await callTool("wireweave_parse", { source }, opts.dispatchParams);
322
+ const payload = parseJsonResult(result);
323
+ if (!payload.success) {
324
+ writeLine5(stderr, `parse failed: ${payload.error ?? "Unknown error"}`);
325
+ if (payload.location) {
326
+ writeLine5(stderr, ` at: ${JSON.stringify(payload.location)}`);
327
+ }
328
+ return 1;
329
+ }
330
+ writeLine5(stdout, JSON.stringify({ pageCount: payload.pageCount, ast: payload.ast }, null, 2));
331
+ return 0;
332
+ }
333
+ function formatError2(err) {
334
+ return err instanceof Error ? err.message : String(err);
335
+ }
336
+
337
+ // src/commands/validate.ts
338
+ import { promises as fs4 } from "fs";
339
+ var writeLine6 = (stream, text) => {
340
+ stream.write(text);
341
+ stream.write("\n");
342
+ };
343
+ async function validateCommand(opts) {
344
+ const stdout = opts.stdout ?? process.stdout;
345
+ const stderr = opts.stderr ?? process.stderr;
346
+ const fsLike = opts.fsLike ?? fs4;
347
+ let source;
348
+ try {
349
+ source = await fsLike.readFile(opts.file, "utf8");
350
+ } catch (err) {
351
+ writeLine6(stderr, `validate failed: cannot read ${opts.file}: ${formatError3(err)}`);
352
+ return 1;
353
+ }
354
+ const result = await callTool(
355
+ "wireweave_validate",
356
+ { source, strict: opts.strict === true },
357
+ opts.dispatchParams
358
+ );
359
+ const payload = parseJsonResult(result);
360
+ if (!payload.valid) {
361
+ writeLine6(stderr, `validate failed: ${payload.error ?? "Unknown error"}`);
362
+ if (payload.strictErrors && payload.strictErrors.length > 0) {
363
+ for (const message of payload.strictErrors) {
364
+ writeLine6(stderr, ` - ${message}`);
365
+ }
366
+ }
367
+ if (payload.location) {
368
+ writeLine6(stderr, ` at: ${JSON.stringify(payload.location)}`);
369
+ }
370
+ return 1;
371
+ }
372
+ writeLine6(
373
+ stdout,
374
+ `OK: ${opts.file} (pages: ${payload.pageCount ?? 0}, components: ${payload.componentCount ?? 0})`
375
+ );
376
+ return 0;
377
+ }
378
+ function formatError3(err) {
379
+ return err instanceof Error ? err.message : String(err);
380
+ }
381
+
382
+ // src/commands/list-components.ts
383
+ var writeLine7 = (stream, text) => {
384
+ stream.write(text);
385
+ stream.write("\n");
386
+ };
387
+ async function listComponentsCommand(opts) {
388
+ const stdout = opts.stdout ?? process.stdout;
389
+ const stderr = opts.stderr ?? process.stderr;
390
+ const args = {};
391
+ if (opts.category) args.category = opts.category;
392
+ const result = await callTool("wireweave_list_components", args, opts.dispatchParams);
393
+ if (result.isError) {
394
+ writeLine7(stderr, `list-components failed: ${textOf(result.content)}`);
395
+ return 1;
396
+ }
397
+ const payload = parseJsonResult(result);
398
+ if (opts.format === "json") {
399
+ writeLine7(stdout, JSON.stringify(payload, null, 2));
400
+ return 0;
401
+ }
402
+ writeLine7(
403
+ stdout,
404
+ `Components: ${payload.count}${opts.category ? ` (category=${opts.category})` : ""}`
405
+ );
406
+ for (const c of payload.components) {
407
+ const children = c.hasChildren ? " [container]" : "";
408
+ writeLine7(stdout, ` ${c.name.padEnd(20)} ${c.category.padEnd(14)}${children}`);
409
+ }
410
+ return 0;
411
+ }
412
+ function textOf(content) {
413
+ const first = content[0];
414
+ return first ? first.text : "";
415
+ }
416
+
417
+ // src/commands/analyze.ts
418
+ import { promises as fs5 } from "fs";
419
+ var writeLine8 = (stream, text) => {
420
+ stream.write(text);
421
+ stream.write("\n");
422
+ };
423
+ async function analyzeCommand(opts) {
424
+ const stdout = opts.stdout ?? process.stdout;
425
+ const stderr = opts.stderr ?? process.stderr;
426
+ const fsLike = opts.fsLike ?? fs5;
427
+ let source;
428
+ try {
429
+ source = await fsLike.readFile(opts.file, "utf8");
430
+ } catch (err) {
431
+ writeLine8(stderr, `analyze failed: cannot read ${opts.file}: ${formatError4(err)}`);
432
+ return 1;
433
+ }
434
+ const args = { source };
435
+ if (opts.includeComponentBreakdown === false) args.includeComponentBreakdown = false;
436
+ if (opts.includeAccessibility === false) args.includeAccessibility = false;
437
+ if (opts.includeComplexity === false) args.includeComplexity = false;
438
+ if (opts.includeLayout === false) args.includeLayout = false;
439
+ if (opts.includeContent === false) args.includeContent = false;
440
+ const result = await callTool("wireweave_analyze", args, opts.dispatchParams);
441
+ if (result.isError) {
442
+ writeLine8(stderr, `analyze failed: ${extractFirstText2(result.content)}`);
443
+ return 1;
444
+ }
445
+ const payload = parseJsonResult(result);
446
+ if (payload.success === false) {
447
+ writeLine8(stderr, `analyze failed: ${payload.error ?? "Unknown error"}`);
448
+ return 1;
449
+ }
450
+ if (opts.format === "summary") {
451
+ writeLine8(stdout, `Analysis: ${opts.file}`);
452
+ if (typeof payload.pageCount === "number") writeLine8(stdout, ` pages: ${payload.pageCount}`);
453
+ if (typeof payload.componentCount === "number")
454
+ writeLine8(stdout, ` components: ${payload.componentCount}`);
455
+ if (payload.accessibility && typeof payload.accessibility.score === "number")
456
+ writeLine8(stdout, ` accessibility score: ${payload.accessibility.score}`);
457
+ if (payload.complexity)
458
+ writeLine8(
459
+ stdout,
460
+ ` complexity: ${payload.complexity.level ?? "n/a"} (score: ${payload.complexity.score ?? "n/a"})`
461
+ );
462
+ return 0;
463
+ }
464
+ writeLine8(stdout, JSON.stringify(payload, null, 2));
465
+ return 0;
466
+ }
467
+ function formatError4(err) {
468
+ return err instanceof Error ? err.message : String(err);
469
+ }
470
+ function extractFirstText2(content) {
471
+ const first = content.find((b) => b.type === "text");
472
+ return first?.text ?? "Unknown error";
473
+ }
474
+
475
+ // src/commands/diff.ts
476
+ import { promises as fs6 } from "fs";
477
+ var writeLine9 = (stream, text) => {
478
+ stream.write(text);
479
+ stream.write("\n");
480
+ };
481
+ async function diffCommand(opts) {
482
+ const stdout = opts.stdout ?? process.stdout;
483
+ const stderr = opts.stderr ?? process.stderr;
484
+ const fsLike = opts.fsLike ?? fs6;
485
+ let oldSource;
486
+ let newSource;
487
+ try {
488
+ oldSource = await fsLike.readFile(opts.oldFile, "utf8");
489
+ } catch (err) {
490
+ writeLine9(stderr, `diff failed: cannot read ${opts.oldFile}: ${formatError5(err)}`);
491
+ return 1;
492
+ }
493
+ try {
494
+ newSource = await fsLike.readFile(opts.newFile, "utf8");
495
+ } catch (err) {
496
+ writeLine9(stderr, `diff failed: cannot read ${opts.newFile}: ${formatError5(err)}`);
497
+ return 1;
498
+ }
499
+ const args = { oldSource, newSource };
500
+ if (opts.ignoreAttributes === true) args.ignoreAttributes = true;
501
+ if (opts.ignoreOrder === true) args.ignoreOrder = true;
502
+ const result = await callTool("wireweave_diff", args, opts.dispatchParams);
503
+ if (result.isError) {
504
+ writeLine9(stderr, `diff failed: ${extractFirstText3(result.content)}`);
505
+ return 1;
506
+ }
507
+ const payload = parseJsonResult(result);
508
+ if (!payload.success) {
509
+ writeLine9(stderr, `diff failed: ${payload.error ?? "Unknown error"}`);
510
+ return 1;
511
+ }
512
+ if (opts.format === "summary") {
513
+ if (payload.identical) {
514
+ writeLine9(stdout, `Identical: ${opts.oldFile} <-> ${opts.newFile}`);
515
+ return 0;
516
+ }
517
+ const s = payload.summary ?? {};
518
+ writeLine9(stdout, `Diff: ${opts.oldFile} <-> ${opts.newFile}`);
519
+ writeLine9(
520
+ stdout,
521
+ ` added: ${s.added ?? 0}, removed: ${s.removed ?? 0}, modified: ${s.modified ?? 0}`
522
+ );
523
+ if (payload.description) writeLine9(stdout, ` ${payload.description}`);
524
+ return 0;
525
+ }
526
+ writeLine9(stdout, JSON.stringify(payload, null, 2));
527
+ return 0;
528
+ }
529
+ function formatError5(err) {
530
+ return err instanceof Error ? err.message : String(err);
531
+ }
532
+ function extractFirstText3(content) {
533
+ const first = content.find((b) => b.type === "text");
534
+ return first?.text ?? "Unknown error";
535
+ }
536
+
537
+ // src/commands/validate-ux.ts
538
+ import { promises as fs7 } from "fs";
539
+ var writeLine10 = (stream, text) => {
540
+ stream.write(text);
541
+ stream.write("\n");
542
+ };
543
+ async function validateUxCommand(opts) {
544
+ const stdout = opts.stdout ?? process.stdout;
545
+ const stderr = opts.stderr ?? process.stderr;
546
+ const fsLike = opts.fsLike ?? fs7;
547
+ let source;
548
+ try {
549
+ source = await fsLike.readFile(opts.file, "utf8");
550
+ } catch (err) {
551
+ writeLine10(stderr, `validate-ux failed: cannot read ${opts.file}: ${formatError6(err)}`);
552
+ return 1;
553
+ }
554
+ const args = { source };
555
+ if (opts.categories && opts.categories.length > 0) args.categories = opts.categories;
556
+ if (opts.minSeverity) args.minSeverity = opts.minSeverity;
557
+ if (typeof opts.maxIssues === "number") args.maxIssues = opts.maxIssues;
558
+ if (opts.disabledRules && opts.disabledRules.length > 0) args.disabledRules = opts.disabledRules;
559
+ const result = await callTool("wireweave_validate_ux", args, opts.dispatchParams);
560
+ if (result.isError) {
561
+ writeLine10(stderr, `validate-ux failed: ${extractFirstText4(result.content)}`);
562
+ return 1;
563
+ }
564
+ const payload = parseJsonResult(result);
565
+ if (!payload.success) {
566
+ writeLine10(stderr, `validate-ux failed: ${payload.error ?? "Unknown error"}`);
567
+ return 1;
568
+ }
569
+ if (opts.format === "summary") {
570
+ const counts = payload.severityCounts ?? {};
571
+ writeLine10(
572
+ stdout,
573
+ `UX: ${opts.file} \u2014 ${payload.valid ? "OK" : "ISSUES"} (score: ${payload.score ?? "n/a"})`
574
+ );
575
+ writeLine10(
576
+ stdout,
577
+ ` errors: ${counts.error ?? 0}, warnings: ${counts.warning ?? 0}, info: ${counts.info ?? 0}`
578
+ );
579
+ for (const issue of payload.issues ?? []) {
580
+ const sev = (issue.severity ?? "info").toUpperCase();
581
+ writeLine10(stdout, ` [${sev}] ${issue.ruleId ?? "?"}: ${issue.message ?? ""}`);
582
+ }
583
+ return payload.valid ? 0 : 1;
584
+ }
585
+ writeLine10(stdout, JSON.stringify(payload, null, 2));
586
+ return payload.valid ? 0 : 1;
587
+ }
588
+ function formatError6(err) {
589
+ return err instanceof Error ? err.message : String(err);
590
+ }
591
+ function extractFirstText4(content) {
592
+ const first = content.find((b) => b.type === "text");
593
+ return first?.text ?? "Unknown error";
594
+ }
595
+
596
+ // src/commands/export-json.ts
597
+ import { promises as fs8 } from "fs";
598
+ var writeLine11 = (stream, text) => {
599
+ stream.write(text);
600
+ stream.write("\n");
601
+ };
602
+ async function exportJsonCommand(opts) {
603
+ const stdout = opts.stdout ?? process.stdout;
604
+ const stderr = opts.stderr ?? process.stderr;
605
+ const fsLike = opts.fsLike ?? fs8;
606
+ let source;
607
+ try {
608
+ source = await fsLike.readFile(opts.file, "utf8");
609
+ } catch (err) {
610
+ writeLine11(stderr, `export-json failed: cannot read ${opts.file}: ${formatError7(err)}`);
611
+ return 1;
612
+ }
613
+ const args = { source };
614
+ if (opts.includeLocations === true) args.includeLocations = true;
615
+ if (opts.prettyPrint === false) args.prettyPrint = false;
616
+ if (opts.includeEmptyAttributes === true) args.includeEmptyAttributes = true;
617
+ const result = await callTool("wireweave_export_json", args, opts.dispatchParams);
618
+ if (result.isError) {
619
+ writeLine11(stderr, `export-json failed: ${extractFirstText5(result.content)}`);
620
+ return 1;
621
+ }
622
+ const payload = parseJsonResult(result);
623
+ if (!payload.success) {
624
+ writeLine11(stderr, `export-json failed: ${payload.error ?? "Unknown error"}`);
625
+ return 1;
626
+ }
627
+ const text = JSON.stringify(payload, null, opts.prettyPrint === false ? 0 : 2);
628
+ if (opts.output) {
629
+ try {
630
+ await fsLike.writeFile(opts.output, text, "utf8");
631
+ writeLine11(stdout, `Wrote ${opts.output}`);
632
+ } catch (err) {
633
+ writeLine11(stderr, `export-json failed: cannot write ${opts.output}: ${formatError7(err)}`);
634
+ return 1;
635
+ }
636
+ return 0;
637
+ }
638
+ writeLine11(stdout, text);
639
+ return 0;
640
+ }
641
+ function formatError7(err) {
642
+ return err instanceof Error ? err.message : String(err);
643
+ }
644
+ function extractFirstText5(content) {
645
+ const first = content.find((b) => b.type === "text");
646
+ return first?.text ?? "Unknown error";
647
+ }
648
+
649
+ // src/commands/export-figma.ts
650
+ import { promises as fs9 } from "fs";
651
+ var writeLine12 = (stream, text) => {
652
+ stream.write(text);
653
+ stream.write("\n");
654
+ };
655
+ async function exportFigmaCommand(opts) {
656
+ const stdout = opts.stdout ?? process.stdout;
657
+ const stderr = opts.stderr ?? process.stderr;
658
+ const fsLike = opts.fsLike ?? fs9;
659
+ let source;
660
+ try {
661
+ source = await fsLike.readFile(opts.file, "utf8");
662
+ } catch (err) {
663
+ writeLine12(stderr, `export-figma failed: cannot read ${opts.file}: ${formatError8(err)}`);
664
+ return 1;
665
+ }
666
+ const result = await callTool("wireweave_export_figma", { source }, opts.dispatchParams);
667
+ if (result.isError) {
668
+ writeLine12(stderr, `export-figma failed: ${extractFirstText6(result.content)}`);
669
+ return 1;
670
+ }
671
+ const payload = parseJsonResult(result);
672
+ if (!payload.success) {
673
+ writeLine12(stderr, `export-figma failed: ${payload.error ?? "Unknown error"}`);
674
+ return 1;
675
+ }
676
+ const text = JSON.stringify(payload, null, 2);
677
+ if (opts.output) {
678
+ try {
679
+ await fsLike.writeFile(opts.output, text, "utf8");
680
+ writeLine12(stdout, `Wrote ${opts.output}`);
681
+ } catch (err) {
682
+ writeLine12(stderr, `export-figma failed: cannot write ${opts.output}: ${formatError8(err)}`);
683
+ return 1;
684
+ }
685
+ return 0;
686
+ }
687
+ writeLine12(stdout, text);
688
+ return 0;
689
+ }
690
+ function formatError8(err) {
691
+ return err instanceof Error ? err.message : String(err);
692
+ }
693
+ function extractFirstText6(content) {
694
+ const first = content.find((b) => b.type === "text");
695
+ return first?.text ?? "Unknown error";
696
+ }
697
+
698
+ // src/index.ts
699
+ var program = new Command();
700
+ program.name("wireweave").description(
701
+ "Wireweave CLI \u2014 auth, parse, validate, render, analyze, diff, validate-ux, and export .wf files"
702
+ ).version("0.1.0-beta.0");
703
+ program.command("login").description("Verify a Wireweave API key and store it for future sessions").option("--api-key <key>", "API key (otherwise read from WIREWEAVE_API_KEY or stdin)").option("--api-url <url>", "Override API base URL").action(async (opts) => {
704
+ const code = await loginCommand({ apiKey: opts.apiKey, apiUrl: opts.apiUrl });
705
+ process.exit(code);
706
+ });
707
+ program.command("whoami").description("Show the currently configured Wireweave account").action(async () => {
708
+ const code = await whoamiCommand();
709
+ process.exit(code);
710
+ });
711
+ program.command("logout").description("Remove the stored Wireweave API key from disk").action(async () => {
712
+ const code = await logoutCommand();
713
+ process.exit(code);
714
+ });
715
+ program.command("render").argument("<file>", "Path to a .wf or .wireframe file").option("-o, --output <path>", "Write HTML to a file instead of stdout").option("--theme <theme>", "Theme: light or dark", "light").option("--full-document", "Return a complete HTML document (default: fragment)").description("Render a wireframe file to HTML (local \u2014 no network)").action(
716
+ async (file, opts) => {
717
+ const theme = opts.theme === "dark" ? "dark" : "light";
718
+ const code = await renderCommand({
719
+ file,
720
+ output: opts.output,
721
+ theme,
722
+ fullDocument: opts.fullDocument === true
723
+ });
724
+ process.exit(code);
725
+ }
726
+ );
727
+ program.command("parse").argument("<file>", "Path to a .wf or .wireframe file").description("Parse a wireframe file and print its AST as JSON (local \u2014 no network)").action(async (file) => {
728
+ const code = await parseCommand({ file });
729
+ process.exit(code);
730
+ });
731
+ program.command("validate").argument("<file>", "Path to a .wf or .wireframe file").option("--strict", "Reject unknown attributes").description("Validate a wireframe file (local \u2014 no network)").action(async (file, opts) => {
732
+ const code = await validateCommand({ file, strict: opts.strict === true });
733
+ process.exit(code);
734
+ });
735
+ program.command("list-components").option("--category <category>", "Filter by category (layout, navigation, form, ...)").option("--format <format>", "Output format: table or json", "table").description("List Wireweave DSL components (local \u2014 no network)").action(async (opts) => {
736
+ const format = opts.format === "json" ? "json" : "table";
737
+ const code = await listComponentsCommand({ category: opts.category, format });
738
+ process.exit(code);
739
+ });
740
+ program.command("analyze").argument("<file>", "Path to a .wf or .wireframe file").option("--format <format>", "Output format: json or summary", "json").option("--no-component-breakdown", "Skip per-component usage breakdown").option("--no-accessibility", "Skip accessibility analysis").option("--no-complexity", "Skip complexity analysis").option("--no-layout", "Skip layout analysis").option("--no-content", "Skip content analysis").description(
741
+ "Analyze a wireframe for statistics, accessibility, and complexity (local \u2014 no network)"
742
+ ).action(
743
+ async (file, opts) => {
744
+ const format = opts.format === "summary" ? "summary" : "json";
745
+ const code = await analyzeCommand({
746
+ file,
747
+ format,
748
+ includeComponentBreakdown: opts.componentBreakdown,
749
+ includeAccessibility: opts.accessibility,
750
+ includeComplexity: opts.complexity,
751
+ includeLayout: opts.layout,
752
+ includeContent: opts.content
753
+ });
754
+ process.exit(code);
755
+ }
756
+ );
757
+ program.command("diff").argument("<old>", "Path to the original .wf file").argument("<new>", "Path to the modified .wf file").option("--ignore-attributes", "Compare structure only, ignore attribute changes").option("--ignore-order", "Ignore child element order when comparing").option("--format <format>", "Output format: json or summary", "json").description("Compare two wireframe files and report differences (local \u2014 no network)").action(
758
+ async (oldFile, newFile, opts) => {
759
+ const format = opts.format === "summary" ? "summary" : "json";
760
+ const code = await diffCommand({
761
+ oldFile,
762
+ newFile,
763
+ ignoreAttributes: opts.ignoreAttributes === true,
764
+ ignoreOrder: opts.ignoreOrder === true,
765
+ format
766
+ });
767
+ process.exit(code);
768
+ }
769
+ );
770
+ program.command("validate-ux").argument("<file>", "Path to a .wf or .wireframe file").option(
771
+ "--categories <list>",
772
+ "Comma-separated UX rule categories (accessibility,usability,form,...)"
773
+ ).option("--min-severity <severity>", "Minimum severity to report: error, warning, info").option("--max-issues <n>", "Maximum number of issues to return", (v) => Number(v)).option("--disabled-rules <list>", "Comma-separated rule IDs to skip").option("--format <format>", "Output format: json or summary", "json").description("Validate a wireframe against UX best-practice rules (local \u2014 no network)").action(
774
+ async (file, opts) => {
775
+ const format = opts.format === "summary" ? "summary" : "json";
776
+ const minSeverity = opts.minSeverity === "error" || opts.minSeverity === "warning" || opts.minSeverity === "info" ? opts.minSeverity : void 0;
777
+ const code = await validateUxCommand({
778
+ file,
779
+ categories: opts.categories ? opts.categories.split(",").map((s) => s.trim()) : void 0,
780
+ minSeverity,
781
+ maxIssues: typeof opts.maxIssues === "number" ? opts.maxIssues : void 0,
782
+ disabledRules: opts.disabledRules ? opts.disabledRules.split(",").map((s) => s.trim()) : void 0,
783
+ format
784
+ });
785
+ process.exit(code);
786
+ }
787
+ );
788
+ program.command("export-json").argument("<file>", "Path to a .wf or .wireframe file").option("-o, --output <path>", "Write JSON to a file instead of stdout").option("--include-locations", "Include source location metadata in nodes").option("--no-pretty-print", "Emit minified JSON (default: pretty)").option("--include-empty-attributes", "Include attributes whose value is empty").description("Export a wireframe as JSON (local \u2014 no network)").action(
789
+ async (file, opts) => {
790
+ const code = await exportJsonCommand({
791
+ file,
792
+ output: opts.output,
793
+ includeLocations: opts.includeLocations === true,
794
+ prettyPrint: opts.prettyPrint !== false,
795
+ includeEmptyAttributes: opts.includeEmptyAttributes === true
796
+ });
797
+ process.exit(code);
798
+ }
799
+ );
800
+ program.command("export-figma").argument("<file>", "Path to a .wf or .wireframe file").option("-o, --output <path>", "Write Figma JSON to a file instead of stdout").description("Export a wireframe to Figma-compatible JSON (local \u2014 no network)").action(async (file, opts) => {
801
+ const code = await exportFigmaCommand({
802
+ file,
803
+ output: opts.output
804
+ });
805
+ process.exit(code);
806
+ });
807
+ program.parseAsync(process.argv).catch((err) => {
808
+ const message = err instanceof Error ? err.message : String(err);
809
+ process.stderr.write(`wireweave: ${message}
810
+ `);
811
+ process.exit(1);
812
+ });
package/package.json ADDED
@@ -0,0 +1,77 @@
1
+ {
2
+ "name": "@wireweave/cli",
3
+ "version": "0.1.0-beta.0",
4
+ "description": "Wireweave CLI — auth, render, and AI agent for the Wireweave wireframe DSL",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "exports": {
8
+ ".": {
9
+ "import": "./dist/index.js"
10
+ }
11
+ },
12
+ "bin": {
13
+ "wireweave": "./dist/index.js"
14
+ },
15
+ "scripts": {
16
+ "build": "tsup",
17
+ "dev": "tsup --watch",
18
+ "start": "node dist/index.js",
19
+ "typecheck": "tsc --noEmit",
20
+ "test": "vitest run",
21
+ "lint": "eslint .",
22
+ "lint:fix": "eslint . --fix",
23
+ "format": "prettier --write .",
24
+ "format:check": "prettier --check .",
25
+ "knip": "knip",
26
+ "publint": "publint",
27
+ "prepare": "husky"
28
+ },
29
+ "publishConfig": {
30
+ "access": "public",
31
+ "tag": "beta"
32
+ },
33
+ "dependencies": {
34
+ "@wireweave/sdk": "*",
35
+ "commander": "^12.1.0"
36
+ },
37
+ "devDependencies": {
38
+ "@commitlint/cli": "^21.0.1",
39
+ "@commitlint/config-conventional": "^21.0.1",
40
+ "@eslint/js": "^10.0.1",
41
+ "@types/node": "^22.0.0",
42
+ "eslint": "^10.4.0",
43
+ "globals": "^17.6.0",
44
+ "husky": "^9.1.7",
45
+ "knip": "^6.14.1",
46
+ "lint-staged": "^17.0.5",
47
+ "prettier": "^3.8.3",
48
+ "publint": "^0.3.21",
49
+ "tsup": "^8.3.5",
50
+ "typescript": "^5.7.2",
51
+ "typescript-eslint": "^8.59.3",
52
+ "vitest": "^2.1.9"
53
+ },
54
+ "files": [
55
+ "dist"
56
+ ],
57
+ "engines": {
58
+ "node": ">=18"
59
+ },
60
+ "repository": {
61
+ "type": "git",
62
+ "url": "git+https://github.com/wireweave/cli.git"
63
+ },
64
+ "homepage": "https://docs.wireweave.org/cli",
65
+ "bugs": {
66
+ "url": "https://github.com/wireweave/cli/issues"
67
+ },
68
+ "keywords": [
69
+ "wireweave",
70
+ "cli",
71
+ "wireframe",
72
+ "dsl",
73
+ "ai",
74
+ "agent"
75
+ ],
76
+ "license": "MIT"
77
+ }