vibedgames 0.3.1 → 0.4.1

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/README.md CHANGED
@@ -42,7 +42,11 @@ vg generate upload <file> # upload an asset, get a URL
42
42
  vg generate docs <query> # search generative-model documentation
43
43
  ```
44
44
 
45
- Most commands support `--json` for machine-readable output.
45
+ Most commands support `--json` for machine-readable output, and `--field <path>`
46
+ to print one value out of it — `vg generate upload x.png --field url` prints the
47
+ bare URL, ready for `$(...)` capture, so no JSON processor is needed. The path is
48
+ dotted, takes `images[0]` or `images.0`, and counts negative indices from the
49
+ end; a path that doesn't resolve is an error rather than an empty line.
46
50
 
47
51
  `vg init` shells out to `npx skills add kyh/vibedgames` and installs for Claude
48
52
  Code, Cursor and Codex by default (symlinked from a shared `.agents/skills/`);
@@ -50,6 +54,12 @@ Code, Cursor and Codex by default (symlinked from a shared `.agents/skills/`);
50
54
  of the project. `vg update` runs automatically once a day — disable with
51
55
  `VG_NO_AUTO_UPDATE=1`.
52
56
 
57
+ Both self-update with whichever package manager installed the CLI, detected
58
+ from its install path (npm, pnpm, yarn or bun) — installing with a different
59
+ one would write a second copy into a prefix your shell may not be looking at.
60
+ If that manager isn't on PATH, the CLI prints the exact command to run instead
61
+ of failing with a bare exit code.
62
+
53
63
  `vg factory` is a pure passthrough to the [factory](../factory) binary, which is
54
64
  installed as a platform-specific optional package on first use — the CLI itself
55
65
  carries none of it.
@@ -6,8 +6,11 @@ const SUBCOMMANDS = [
6
6
  "login",
7
7
  "logout",
8
8
  "deploy",
9
+ "playtest",
10
+ "factory",
9
11
  "fork",
10
12
  "generate",
13
+ "credits",
11
14
  "update",
12
15
  "completions",
13
16
  "whoami",
@@ -3,4 +3,8 @@ export declare const creditsCommand: import("citty").CommandDef<{
3
3
  readonly type: "boolean";
4
4
  readonly description: "Print structured JSON to stdout.";
5
5
  };
6
+ readonly field: {
7
+ readonly type: "string";
8
+ readonly description: "Print a single value from the JSON result, e.g. --field request_id or --field images[0].url. Prints scalars bare for shell capture.";
9
+ };
6
10
  }>;
@@ -2,15 +2,12 @@ import { defineCommand } from "citty";
2
2
  import consola from "consola";
3
3
  import { createClient } from "../lib/api.js";
4
4
  import { getToken } from "../lib/config.js";
5
+ import { outputArgs, writeStructured } from "../lib/output.js";
6
+ import { assertKnownFlags } from "../lib/strict-args.js";
7
+ const creditsArgs = { ...outputArgs };
5
8
  const MICRO_PER_USD = 1_000_000;
6
9
  const SUB_CENT_MICRO = MICRO_PER_USD / 100;
7
10
  const MAX_ENTRIES_SHOWN = 15;
8
- function isJsonOutput(args) {
9
- return Boolean(args.json) || process.env.VG_JSON_OUTPUT === "1";
10
- }
11
- function writeJson(value) {
12
- process.stdout.write(JSON.stringify(value, null, 2) + "\n");
13
- }
14
11
  // Dollars from integer micro-USD. Two decimals normally; four when the
15
12
  // magnitude is sub-cent so small generation charges don't render as $0.00.
16
13
  function formatUsd(micro) {
@@ -73,10 +70,9 @@ export const creditsCommand = defineCommand({
73
70
  name: "credits",
74
71
  description: "Show your credit balance and recent usage.",
75
72
  },
76
- args: {
77
- json: { type: "boolean", description: "Print structured JSON to stdout." },
78
- },
79
- run: async ({ args }) => {
73
+ args: creditsArgs,
74
+ run: async ({ args, rawArgs }) => {
75
+ assertKnownFlags(rawArgs, creditsArgs);
80
76
  const token = getToken();
81
77
  if (!token) {
82
78
  consola.warn("Not logged in. Run `vg login` to authenticate.");
@@ -85,22 +81,21 @@ export const creditsCommand = defineCommand({
85
81
  const client = createClient();
86
82
  try {
87
83
  const { balanceMicro, entries } = await client.credits.me.query();
88
- if (isJsonOutput(args)) {
89
- writeJson({
90
- balance_micro: balanceMicro,
91
- balance_usd: balanceMicro / MICRO_PER_USD,
92
- entries: entries.map((e) => ({
93
- id: e.id,
94
- delta_micro: e.deltaMicro,
95
- kind: e.kind,
96
- request_id: e.requestId,
97
- endpoint_id: e.endpointId,
98
- note: e.note,
99
- created_at: e.createdAt.toISOString(),
100
- })),
101
- });
84
+ const payload = {
85
+ balance_micro: balanceMicro,
86
+ balance_usd: balanceMicro / MICRO_PER_USD,
87
+ entries: entries.map((e) => ({
88
+ id: e.id,
89
+ delta_micro: e.deltaMicro,
90
+ kind: e.kind,
91
+ request_id: e.requestId,
92
+ endpoint_id: e.endpointId,
93
+ note: e.note,
94
+ created_at: e.createdAt.toISOString(),
95
+ })),
96
+ };
97
+ if (writeStructured(payload, args))
102
98
  return;
103
- }
104
99
  consola.log(`Balance: ${formatUsd(balanceMicro)}`);
105
100
  if (entries.length === 0) {
106
101
  consola.log("No activity yet.");
@@ -1,4 +1,12 @@
1
1
  export declare const deployCommand: import("citty").CommandDef<{
2
+ readonly json: {
3
+ readonly type: "boolean";
4
+ readonly description: "Print structured JSON to stdout.";
5
+ };
6
+ readonly field: {
7
+ readonly type: "string";
8
+ readonly description: "Print a single value from the JSON result, e.g. --field request_id or --field images[0].url. Prints scalars bare for shell capture.";
9
+ };
2
10
  readonly dir: {
3
11
  readonly type: "positional";
4
12
  readonly description: "Directory to deploy";
@@ -5,34 +5,42 @@ import { defineCommand } from "citty";
5
5
  import consola from "consola";
6
6
  import { createClient } from "../lib/api.js";
7
7
  import { packSource } from "../lib/archive.js";
8
- import { findProjectRoot, projectConfigPath, readProjectConfig, writeProjectConfig, } from "../lib/config-file.js";
8
+ import { findProjectRoot, projectConfigPath, readProjectConfig, writeProjectConfig, SLUG_RE, } from "../lib/config-file.js";
9
9
  import { buildManifest } from "../lib/manifest.js";
10
+ import { isJsonOutput, outputArgs, writeStructured } from "../lib/output.js";
11
+ import { assertKnownFlags } from "../lib/strict-args.js";
10
12
  import { uploadAll } from "../lib/upload.js";
11
- const SLUG_RE = /^[a-z0-9][a-z0-9-]*[a-z0-9]$/;
13
+ const deployArgs = {
14
+ dir: {
15
+ type: "positional",
16
+ description: "Directory to deploy",
17
+ required: false,
18
+ default: ".",
19
+ },
20
+ slug: {
21
+ type: "string",
22
+ description: "Override the slug (bypasses vibedgames.json)",
23
+ required: false,
24
+ },
25
+ source: {
26
+ type: "boolean",
27
+ description: "Also upload a forkable source archive, letting anyone logged in fork the project.",
28
+ default: false,
29
+ },
30
+ ...outputArgs,
31
+ };
12
32
  export const deployCommand = defineCommand({
13
33
  meta: {
14
34
  name: "deploy",
15
35
  description: "Deploy a game to vibedgames",
16
36
  },
17
- args: {
18
- dir: {
19
- type: "positional",
20
- description: "Directory to deploy",
21
- required: false,
22
- default: ".",
23
- },
24
- slug: {
25
- type: "string",
26
- description: "Override the slug (bypasses vibedgames.json)",
27
- required: false,
28
- },
29
- source: {
30
- type: "boolean",
31
- description: "Also upload a forkable source archive, letting anyone logged in fork the project.",
32
- default: false,
33
- },
34
- },
35
- run: async ({ args }) => {
37
+ args: deployArgs,
38
+ run: async ({ args, rawArgs }) => {
39
+ assertKnownFlags(rawArgs, deployArgs);
40
+ // Progress narration shares stdout with the payload, so it has to go quiet
41
+ // whenever stdout is the result rather than a story about it.
42
+ const structured = isJsonOutput(args) || Boolean(args.field);
43
+ const say = structured ? () => { } : (message) => consola.info(message);
36
44
  const dir = resolve(args.dir);
37
45
  if (!existsSync(dir)) {
38
46
  consola.error(`Directory does not exist: ${dir}`);
@@ -48,7 +56,7 @@ export const deployCommand = defineCommand({
48
56
  for (const name of ["dist", "build", "out"]) {
49
57
  if (existsSync(join(dir, name, "index.html"))) {
50
58
  deployDir = join(dir, name);
51
- consola.info(`Project root detected — deploying its build output ${name}/ instead.`);
59
+ say(`Project root detected — deploying its build output ${name}/ instead.`);
52
60
  break;
53
61
  }
54
62
  }
@@ -87,7 +95,7 @@ export const deployCommand = defineCommand({
87
95
  name: typeof name === "string" && name.length > 0 ? name : undefined,
88
96
  };
89
97
  writeProjectConfig(dir, config);
90
- consola.info(`Wrote ${projectConfigPath(dir)}`);
98
+ say(`Wrote ${projectConfigPath(dir)}`);
91
99
  }
92
100
  if (!SLUG_RE.test(config.slug)) {
93
101
  consola.error(`Invalid slug in vibedgames.json: ${config.slug}`);
@@ -105,7 +113,7 @@ export const deployCommand = defineCommand({
105
113
  process.exit(1);
106
114
  }
107
115
  const totalBytes = manifest.reduce((acc, f) => acc + f.size, 0);
108
- consola.info(`Deploying ${config.slug}: ${manifest.length} files, ${formatBytes(totalBytes)}`);
116
+ say(`Deploying ${config.slug}: ${manifest.length} files, ${formatBytes(totalBytes)}`);
109
117
  // ---- Pack forkable source (opt-in: source is a publish, --source) -------
110
118
  let sourceArchive = null;
111
119
  if (args.source) {
@@ -116,7 +124,7 @@ export const deployCommand = defineCommand({
116
124
  else {
117
125
  try {
118
126
  sourceArchive = await packSource(root, join(tmpdir(), "vibedgames"));
119
- consola.info(`Source: ${sourceArchive.files.length} files, ${formatBytes(sourceArchive.bytes)} — forkable via \`vg fork ${config.slug}\``);
127
+ say(`Source: ${sourceArchive.files.length} files, ${formatBytes(sourceArchive.bytes)} — forkable via \`vg fork ${config.slug}\``);
120
128
  }
121
129
  catch (err) {
122
130
  consola.error(`Source archive failed: ${err instanceof Error ? err.message : String(err)}`);
@@ -150,14 +158,15 @@ export const deployCommand = defineCommand({
150
158
  process.exit(1);
151
159
  }
152
160
  // ---- Upload to R2 -------------------------------------------------------
153
- consola.start(`Uploading ${created.uploads.length} files`);
161
+ if (!structured)
162
+ consola.start(`Uploading ${created.uploads.length} files`);
154
163
  try {
155
164
  await uploadAll({
156
165
  files: manifest,
157
166
  uploads: created.uploads,
158
167
  onProgress: (done, total) => {
159
168
  if (done === total || done % 10 === 0) {
160
- consola.info(`Uploaded ${done}/${total}`);
169
+ say(`Uploaded ${done}/${total}`);
161
170
  }
162
171
  },
163
172
  });
@@ -201,8 +210,21 @@ export const deployCommand = defineCommand({
201
210
  consola.error(err instanceof Error ? err.message : String(err));
202
211
  process.exit(1);
203
212
  }
204
- const elapsed = ((Date.now() - started) / 1000).toFixed(1);
205
- consola.success(`Deployed ${config.slug} in ${elapsed}s`);
213
+ const elapsedMs = Date.now() - started;
214
+ if (writeStructured({
215
+ slug: config.slug,
216
+ url: finalized.url,
217
+ deployment_id: created.deploymentId,
218
+ files: manifest.length,
219
+ bytes: totalBytes,
220
+ source: sourceArchive
221
+ ? { files: sourceArchive.files.length, bytes: sourceArchive.bytes }
222
+ : null,
223
+ elapsed_ms: elapsedMs,
224
+ }, args)) {
225
+ return;
226
+ }
227
+ consola.success(`Deployed ${config.slug} in ${(elapsedMs / 1000).toFixed(1)}s`);
206
228
  consola.log(` ${finalized.url}`);
207
229
  },
208
230
  });
@@ -1,4 +1,12 @@
1
1
  export declare const forkCommand: import("citty").CommandDef<{
2
+ readonly json: {
3
+ readonly type: "boolean";
4
+ readonly description: "Print structured JSON to stdout.";
5
+ };
6
+ readonly field: {
7
+ readonly type: "string";
8
+ readonly description: "Print a single value from the JSON result, e.g. --field request_id or --field images[0].url. Prints scalars bare for shell capture.";
9
+ };
2
10
  readonly slug: {
3
11
  readonly type: "positional";
4
12
  readonly description: "Slug of the project to fork (e.g. bomberman).";
@@ -18,9 +26,4 @@ export declare const forkCommand: import("citty").CommandDef<{
18
26
  readonly description: "Overwrite the target directory if it exists.";
19
27
  readonly default: false;
20
28
  };
21
- readonly json: {
22
- readonly type: "boolean";
23
- readonly description: "Emit machine-readable JSON (for agents).";
24
- readonly default: false;
25
- };
26
29
  }>;
@@ -5,39 +5,39 @@ import { defineCommand } from "citty";
5
5
  import consola from "consola";
6
6
  import { createClient } from "../lib/api.js";
7
7
  import { extractSource } from "../lib/archive.js";
8
- const SLUG_RE = /^[a-z0-9][a-z0-9-]*[a-z0-9]$/;
8
+ import { SLUG_RE } from "../lib/config-file.js";
9
+ import { isJsonOutput, outputArgs, writeStructured } from "../lib/output.js";
10
+ import { assertKnownFlags } from "../lib/strict-args.js";
11
+ const forkArgs = {
12
+ slug: {
13
+ type: "positional",
14
+ description: "Slug of the project to fork (e.g. bomberman).",
15
+ required: true,
16
+ },
17
+ target: {
18
+ type: "positional",
19
+ description: "New slug + directory for the fork. Defaults to <slug>-fork.",
20
+ required: false,
21
+ },
22
+ name: {
23
+ type: "string",
24
+ description: "Display name for the fork (defaults to the target slug).",
25
+ },
26
+ force: {
27
+ type: "boolean",
28
+ description: "Overwrite the target directory if it exists.",
29
+ default: false,
30
+ },
31
+ ...outputArgs,
32
+ };
9
33
  export const forkCommand = defineCommand({
10
34
  meta: {
11
35
  name: "fork",
12
36
  description: "Fork another project's source so you can build on it. Downloads the source a project shipped with `vg deploy`, extracts it locally, and rewrites it to a new slug.",
13
37
  },
14
- args: {
15
- slug: {
16
- type: "positional",
17
- description: "Slug of the project to fork (e.g. bomberman).",
18
- required: true,
19
- },
20
- target: {
21
- type: "positional",
22
- description: "New slug + directory for the fork. Defaults to <slug>-fork.",
23
- required: false,
24
- },
25
- name: {
26
- type: "string",
27
- description: "Display name for the fork (defaults to the target slug).",
28
- },
29
- force: {
30
- type: "boolean",
31
- description: "Overwrite the target directory if it exists.",
32
- default: false,
33
- },
34
- json: {
35
- type: "boolean",
36
- description: "Emit machine-readable JSON (for agents).",
37
- default: false,
38
- },
39
- },
40
- run: async ({ args }) => {
38
+ args: forkArgs,
39
+ run: async ({ args, rawArgs }) => {
40
+ assertKnownFlags(rawArgs, forkArgs);
41
41
  const source = args.slug.trim().toLowerCase();
42
42
  const target = (args.target ?? `${source}-fork`).trim().toLowerCase();
43
43
  if (!SLUG_RE.test(target)) {
@@ -56,7 +56,7 @@ export const forkCommand = defineCommand({
56
56
  }
57
57
  const client = createClient();
58
58
  // ---- Resolve + download source -----------------------------------------
59
- if (!args.json)
59
+ if (!isJsonOutput(args) && !args.field)
60
60
  consola.start(`Forking ${source}`);
61
61
  let src;
62
62
  try {
@@ -86,10 +86,8 @@ export const forkCommand = defineCommand({
86
86
  const name = args.name ?? target.replace(/-/g, " ");
87
87
  writeFileSync(resolve(dir, "vibedgames.json"), `${JSON.stringify({ slug: target, name }, null, 2)}\n`);
88
88
  rewritePackageName(dir, target);
89
- if (args.json) {
90
- consola.log(JSON.stringify({ slug: target, dir, forkedFrom: source }));
89
+ if (writeStructured({ slug: target, dir, forkedFrom: source }, args))
91
90
  return;
92
- }
93
91
  consola.success(`Forked ${source} → ${target}`);
94
92
  consola.log(` ${dir}`);
95
93
  consola.log("");
@@ -6,6 +6,7 @@ import { parseDownloadFlag, parseRunInput, readExplicitLocalFile } from "../lib/
6
6
  import { downloadMedia, extractMediaRefs } from "../lib/media-download.js";
7
7
  import { endpointPath, queueAppId, waitForCompletion } from "../lib/media-poll.js";
8
8
  import { uploadFile } from "../lib/media-upload.js";
9
+ import { isJsonOutput, outputArgs, writeJson, writeStructured } from "../lib/output.js";
9
10
  import { isRecord } from "../lib/types.js";
10
11
  // Action-specific fields for the status-command payload. `result` wraps
11
12
  // the raw fal payload under `result:` so fal's own keys can't clobber
@@ -23,11 +24,13 @@ function buildActionFields(action, data) {
23
24
  }
24
25
  return {};
25
26
  }
26
- function isJsonOutput(args) {
27
- return Boolean(args.json) || process.env.VG_JSON_OUTPUT === "1";
28
- }
29
- function writeJson(value) {
30
- process.stdout.write(JSON.stringify(value, null, 2) + "\n");
27
+ /**
28
+ * True when stdout is carrying data rather than a progress narrative, so
29
+ * spinners and status lines must stay off it. `--field` counts: its whole
30
+ * point is that the output can be captured by a shell verbatim.
31
+ */
32
+ function isStructuredOutput(args) {
33
+ return isJsonOutput(args) || Boolean(args.field);
31
34
  }
32
35
  function extractMediaUrls(result) {
33
36
  return extractMediaRefs(result).map((r) => r.url);
@@ -53,7 +56,7 @@ const runCommand = defineCommand({
53
56
  type: "string",
54
57
  description: "Download media from result. Optional value is a path or template with {index},{name},{ext},{request_id}.",
55
58
  },
56
- json: { type: "boolean", description: "Print structured JSON to stdout." },
59
+ ...outputArgs,
57
60
  quiet: { type: "boolean", description: "Suppress progress output during sync runs." },
58
61
  },
59
62
  run: async ({ args, rawArgs }) => {
@@ -87,16 +90,14 @@ const runCommand = defineCommand({
87
90
  request_id: requestId,
88
91
  hint: `Check status: vg generate status ${endpoint_id} ${requestId}`,
89
92
  };
90
- if (isJsonOutput(args))
91
- writeJson(payload);
92
- else {
93
+ if (!writeStructured(payload, args)) {
93
94
  consola.success(`Submitted ${endpoint_id}`);
94
95
  consola.log(` request_id: ${requestId}`);
95
96
  }
96
97
  return;
97
98
  }
98
99
  const completed = await waitForCompletion(client, endpoint_id, requestId, {
99
- quiet: Boolean(args.quiet) || isJsonOutput(args),
100
+ quiet: Boolean(args.quiet) || isStructuredOutput(args),
100
101
  });
101
102
  let downloaded;
102
103
  if (downloadFlag.mode === "on") {
@@ -116,17 +117,18 @@ const runCommand = defineCommand({
116
117
  ...(downloaded && downloaded.failed.length > 0
117
118
  ? { download_failures: downloaded.failed }
118
119
  : {}),
120
+ ...(downloaded && downloaded.mislabeled.length > 0
121
+ ? { download_format_mismatches: downloaded.mislabeled }
122
+ : {}),
119
123
  };
120
- if (isJsonOutput(args)) {
121
- writeJson(payload);
122
- }
123
- else {
124
+ if (!writeStructured(payload, args)) {
124
125
  consola.success(`Run completed (${completed.request_id})`);
125
126
  if (downloaded) {
126
127
  for (const path of downloaded.downloaded)
127
128
  consola.log(` ${path}`);
128
129
  for (const f of downloaded.failed)
129
130
  consola.warn(` failed: ${f.url} (${f.error})`);
131
+ warnMislabeled(downloaded.mislabeled);
130
132
  }
131
133
  if (!downloaded?.downloaded.length) {
132
134
  for (const url of extractMediaUrls(completed.result))
@@ -138,6 +140,19 @@ const runCommand = defineCommand({
138
140
  }
139
141
  },
140
142
  });
143
+ /**
144
+ * A downloaded file whose extension does not match the bytes inside it.
145
+ *
146
+ * The model, not the CLI, picks the output format, so asking for `board.png`
147
+ * from an endpoint that returns JPEG produces a `.png` full of JPEG. The next
148
+ * tool in the pipeline reports "bad signature" with no hint of where it came
149
+ * from, so name it here while the cause is still on screen.
150
+ */
151
+ function warnMislabeled(mislabeled) {
152
+ for (const m of mislabeled) {
153
+ consola.warn(` ${m.path} holds ${m.actual.toUpperCase()} data, not what its extension says`);
154
+ }
155
+ }
141
156
  // Delegate image generation to the local Codex CLI instead of the
142
157
  // vibedgames model runner. Produces local files directly (Codex writes
143
158
  // to disk), so there's no queue, no request polling, and no vibedgames
@@ -185,10 +200,7 @@ async function runViaCodex(opts) {
185
200
  ...(failed.length > 0 ? { download_failures: failed } : {}),
186
201
  ...(ignoredReferences.length > 0 ? { ignored_references: ignoredReferences } : {}),
187
202
  };
188
- if (isJsonOutput(args)) {
189
- writeJson(payload);
190
- }
191
- else {
203
+ if (!writeStructured(payload, args)) {
192
204
  consola.success(`Codex generated ${downloaded.length} image(s) (${requestId})`);
193
205
  for (const path of downloaded)
194
206
  consola.log(` ${path}`);
@@ -214,7 +226,7 @@ const statusCommand = defineCommand({
214
226
  type: "string",
215
227
  description: "Download media from the result (implies --result).",
216
228
  },
217
- json: { type: "boolean" },
229
+ ...outputArgs,
218
230
  },
219
231
  run: async ({ args, rawArgs }) => {
220
232
  if (args.result && args.cancel) {
@@ -283,28 +295,31 @@ const statusCommand = defineCommand({
283
295
  ...(downloaded && downloaded.failed.length > 0
284
296
  ? { download_failures: downloaded.failed }
285
297
  : {}),
298
+ ...(downloaded && downloaded.mislabeled.length > 0
299
+ ? { download_format_mismatches: downloaded.mislabeled }
300
+ : {}),
286
301
  };
287
- if (isJsonOutput(args)) {
288
- writeJson(payload);
289
- }
290
- else if (action === "status") {
291
- const status = isRecord(data) && typeof data.status === "string" ? data.status : "?";
292
- consola.log(`status: ${status}`);
293
- if (isRecord(data) && typeof data.queue_position === "number") {
294
- consola.log(`queue_position: ${data.queue_position}`);
295
- }
296
- }
297
- else {
298
- consola.success(`${action} ${args.endpoint_id} ${args.request_id}`);
299
- if (downloaded) {
300
- for (const p of downloaded.downloaded)
301
- consola.log(` ${p}`);
302
- for (const f of downloaded.failed)
303
- consola.warn(` failed: ${f.url} (${f.error})`);
302
+ if (!writeStructured(payload, args)) {
303
+ if (action === "status") {
304
+ const status = isRecord(data) && typeof data.status === "string" ? data.status : "?";
305
+ consola.log(`status: ${status}`);
306
+ if (isRecord(data) && typeof data.queue_position === "number") {
307
+ consola.log(`queue_position: ${data.queue_position}`);
308
+ }
304
309
  }
305
- if (action === "result" && !downloaded?.downloaded.length) {
306
- for (const url of extractMediaUrls(data))
307
- consola.log(` ${url}`);
310
+ else {
311
+ consola.success(`${action} ${args.endpoint_id} ${args.request_id}`);
312
+ if (downloaded) {
313
+ for (const p of downloaded.downloaded)
314
+ consola.log(` ${p}`);
315
+ for (const f of downloaded.failed)
316
+ consola.warn(` failed: ${f.url} (${f.error})`);
317
+ warnMislabeled(downloaded.mislabeled);
318
+ }
319
+ if (action === "result" && !downloaded?.downloaded.length) {
320
+ for (const url of extractMediaUrls(data))
321
+ consola.log(` ${url}`);
322
+ }
308
323
  }
309
324
  }
310
325
  if (downloaded && downloaded.failed.length > 0 && downloaded.downloaded.length === 0) {
@@ -329,7 +344,7 @@ const modelsCommand = defineCommand({
329
344
  type: "string",
330
345
  description: "Expand fields: openapi-3.0, enterprise_status. Repeat or comma-separate.",
331
346
  },
332
- json: { type: "boolean" },
347
+ ...outputArgs,
333
348
  },
334
349
  run: async ({ args }) => {
335
350
  const query = {};
@@ -355,9 +370,7 @@ const modelsCommand = defineCommand({
355
370
  path: "/v1/models",
356
371
  query,
357
372
  });
358
- if (isJsonOutput(args))
359
- writeJson(data);
360
- else
373
+ if (!writeStructured(data, args))
361
374
  printModels(data);
362
375
  },
363
376
  });
@@ -393,7 +406,7 @@ const schemaCommand = defineCommand({
393
406
  args: {
394
407
  endpoint_id: { type: "positional", required: true },
395
408
  format: { type: "string", description: "compact (default) | openapi" },
396
- json: { type: "boolean" },
409
+ ...outputArgs,
397
410
  },
398
411
  run: async ({ args }) => {
399
412
  const expand = args.format === "openapi" ? ["openapi-3.0"] : [];
@@ -408,7 +421,8 @@ const schemaCommand = defineCommand({
408
421
  ...(expand.length > 0 ? { expand } : {}),
409
422
  },
410
423
  });
411
- writeJson(data);
424
+ if (!writeStructured(data, args))
425
+ writeJson(data);
412
426
  },
413
427
  });
414
428
  // ---- pricing ----------------------------------------------------------------
@@ -416,7 +430,7 @@ const pricingCommand = defineCommand({
416
430
  meta: { name: "pricing", description: "Fetch pricing for a model." },
417
431
  args: {
418
432
  endpoint_id: { type: "positional", required: true },
419
- json: { type: "boolean" },
433
+ ...outputArgs,
420
434
  },
421
435
  run: async ({ args }) => {
422
436
  const client = createClient();
@@ -426,7 +440,8 @@ const pricingCommand = defineCommand({
426
440
  path: "/v1/models/pricing",
427
441
  query: { endpoint_id: args.endpoint_id },
428
442
  });
429
- writeJson(data);
443
+ if (!writeStructured(data, args))
444
+ writeJson(data);
430
445
  },
431
446
  });
432
447
  // ---- docs -------------------------------------------------------------------
@@ -434,7 +449,7 @@ const docsCommand = defineCommand({
434
449
  meta: { name: "docs", description: "Search generative-model documentation." },
435
450
  args: {
436
451
  query: { type: "positional", required: true },
437
- json: { type: "boolean" },
452
+ ...outputArgs,
438
453
  },
439
454
  run: async ({ args }) => {
440
455
  const client = createClient();
@@ -449,7 +464,8 @@ const docsCommand = defineCommand({
449
464
  params: { name: "search_fal", arguments: { query: args.query } },
450
465
  },
451
466
  });
452
- writeJson(data);
467
+ if (!writeStructured(data, args))
468
+ writeJson(data);
453
469
  },
454
470
  });
455
471
  // ---- upload -----------------------------------------------------------------
@@ -460,7 +476,7 @@ const uploadCommand = defineCommand({
460
476
  },
461
477
  args: {
462
478
  path: { type: "positional", required: true },
463
- json: { type: "boolean" },
479
+ ...outputArgs,
464
480
  },
465
481
  run: async ({ args }) => {
466
482
  const stat = readExplicitLocalFile(args.path);
@@ -470,9 +486,7 @@ const uploadCommand = defineCommand({
470
486
  }
471
487
  const client = createClient();
472
488
  const url = await uploadFile(client, stat);
473
- if (isJsonOutput(args))
474
- writeJson({ url });
475
- else
489
+ if (!writeStructured({ url }, args))
476
490
  process.stdout.write(url + "\n");
477
491
  },
478
492
  });