vibedgames 0.4.0 → 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/dist/commands/credits.js +5 -4
- package/dist/commands/deploy.d.ts +8 -0
- package/dist/commands/deploy.js +50 -27
- package/dist/commands/fork.js +26 -23
- package/dist/commands/generate.js +21 -0
- package/dist/commands/init.js +29 -24
- package/dist/commands/new.d.ts +1 -1
- package/dist/commands/new.js +34 -29
- package/dist/commands/playtest.d.ts +12 -0
- package/dist/commands/playtest.js +36 -2
- package/dist/commands/update.js +17 -14
- package/dist/commands/whoami.d.ts +10 -1
- package/dist/commands/whoami.js +8 -1
- package/dist/lib/media-download.d.ts +4 -0
- package/dist/lib/media-download.js +49 -5
- package/dist/lib/run.d.ts +9 -1
- package/dist/lib/run.js +8 -3
- package/dist/lib/strict-args.d.ts +27 -0
- package/dist/lib/strict-args.js +68 -0
- package/package.json +1 -1
package/dist/commands/credits.js
CHANGED
|
@@ -3,6 +3,8 @@ import consola from "consola";
|
|
|
3
3
|
import { createClient } from "../lib/api.js";
|
|
4
4
|
import { getToken } from "../lib/config.js";
|
|
5
5
|
import { outputArgs, writeStructured } from "../lib/output.js";
|
|
6
|
+
import { assertKnownFlags } from "../lib/strict-args.js";
|
|
7
|
+
const creditsArgs = { ...outputArgs };
|
|
6
8
|
const MICRO_PER_USD = 1_000_000;
|
|
7
9
|
const SUB_CENT_MICRO = MICRO_PER_USD / 100;
|
|
8
10
|
const MAX_ENTRIES_SHOWN = 15;
|
|
@@ -68,10 +70,9 @@ export const creditsCommand = defineCommand({
|
|
|
68
70
|
name: "credits",
|
|
69
71
|
description: "Show your credit balance and recent usage.",
|
|
70
72
|
},
|
|
71
|
-
args:
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
run: async ({ args }) => {
|
|
73
|
+
args: creditsArgs,
|
|
74
|
+
run: async ({ args, rawArgs }) => {
|
|
75
|
+
assertKnownFlags(rawArgs, creditsArgs);
|
|
75
76
|
const token = getToken();
|
|
76
77
|
if (!token) {
|
|
77
78
|
consola.warn("Not logged in. Run `vg login` to authenticate.");
|
|
@@ -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";
|
package/dist/commands/deploy.js
CHANGED
|
@@ -7,31 +7,40 @@ import { createClient } from "../lib/api.js";
|
|
|
7
7
|
import { packSource } from "../lib/archive.js";
|
|
8
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";
|
|
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
|
+
};
|
|
11
32
|
export const deployCommand = defineCommand({
|
|
12
33
|
meta: {
|
|
13
34
|
name: "deploy",
|
|
14
35
|
description: "Deploy a game to vibedgames",
|
|
15
36
|
},
|
|
16
|
-
args:
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
slug: {
|
|
24
|
-
type: "string",
|
|
25
|
-
description: "Override the slug (bypasses vibedgames.json)",
|
|
26
|
-
required: false,
|
|
27
|
-
},
|
|
28
|
-
source: {
|
|
29
|
-
type: "boolean",
|
|
30
|
-
description: "Also upload a forkable source archive, letting anyone logged in fork the project.",
|
|
31
|
-
default: false,
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
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);
|
|
35
44
|
const dir = resolve(args.dir);
|
|
36
45
|
if (!existsSync(dir)) {
|
|
37
46
|
consola.error(`Directory does not exist: ${dir}`);
|
|
@@ -47,7 +56,7 @@ export const deployCommand = defineCommand({
|
|
|
47
56
|
for (const name of ["dist", "build", "out"]) {
|
|
48
57
|
if (existsSync(join(dir, name, "index.html"))) {
|
|
49
58
|
deployDir = join(dir, name);
|
|
50
|
-
|
|
59
|
+
say(`Project root detected — deploying its build output ${name}/ instead.`);
|
|
51
60
|
break;
|
|
52
61
|
}
|
|
53
62
|
}
|
|
@@ -86,7 +95,7 @@ export const deployCommand = defineCommand({
|
|
|
86
95
|
name: typeof name === "string" && name.length > 0 ? name : undefined,
|
|
87
96
|
};
|
|
88
97
|
writeProjectConfig(dir, config);
|
|
89
|
-
|
|
98
|
+
say(`Wrote ${projectConfigPath(dir)}`);
|
|
90
99
|
}
|
|
91
100
|
if (!SLUG_RE.test(config.slug)) {
|
|
92
101
|
consola.error(`Invalid slug in vibedgames.json: ${config.slug}`);
|
|
@@ -104,7 +113,7 @@ export const deployCommand = defineCommand({
|
|
|
104
113
|
process.exit(1);
|
|
105
114
|
}
|
|
106
115
|
const totalBytes = manifest.reduce((acc, f) => acc + f.size, 0);
|
|
107
|
-
|
|
116
|
+
say(`Deploying ${config.slug}: ${manifest.length} files, ${formatBytes(totalBytes)}`);
|
|
108
117
|
// ---- Pack forkable source (opt-in: source is a publish, --source) -------
|
|
109
118
|
let sourceArchive = null;
|
|
110
119
|
if (args.source) {
|
|
@@ -115,7 +124,7 @@ export const deployCommand = defineCommand({
|
|
|
115
124
|
else {
|
|
116
125
|
try {
|
|
117
126
|
sourceArchive = await packSource(root, join(tmpdir(), "vibedgames"));
|
|
118
|
-
|
|
127
|
+
say(`Source: ${sourceArchive.files.length} files, ${formatBytes(sourceArchive.bytes)} — forkable via \`vg fork ${config.slug}\``);
|
|
119
128
|
}
|
|
120
129
|
catch (err) {
|
|
121
130
|
consola.error(`Source archive failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
@@ -149,14 +158,15 @@ export const deployCommand = defineCommand({
|
|
|
149
158
|
process.exit(1);
|
|
150
159
|
}
|
|
151
160
|
// ---- Upload to R2 -------------------------------------------------------
|
|
152
|
-
|
|
161
|
+
if (!structured)
|
|
162
|
+
consola.start(`Uploading ${created.uploads.length} files`);
|
|
153
163
|
try {
|
|
154
164
|
await uploadAll({
|
|
155
165
|
files: manifest,
|
|
156
166
|
uploads: created.uploads,
|
|
157
167
|
onProgress: (done, total) => {
|
|
158
168
|
if (done === total || done % 10 === 0) {
|
|
159
|
-
|
|
169
|
+
say(`Uploaded ${done}/${total}`);
|
|
160
170
|
}
|
|
161
171
|
},
|
|
162
172
|
});
|
|
@@ -200,8 +210,21 @@ export const deployCommand = defineCommand({
|
|
|
200
210
|
consola.error(err instanceof Error ? err.message : String(err));
|
|
201
211
|
process.exit(1);
|
|
202
212
|
}
|
|
203
|
-
const
|
|
204
|
-
|
|
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`);
|
|
205
228
|
consola.log(` ${finalized.url}`);
|
|
206
229
|
},
|
|
207
230
|
});
|
package/dist/commands/fork.js
CHANGED
|
@@ -7,34 +7,37 @@ import { createClient } from "../lib/api.js";
|
|
|
7
7
|
import { extractSource } from "../lib/archive.js";
|
|
8
8
|
import { SLUG_RE } from "../lib/config-file.js";
|
|
9
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
|
+
};
|
|
10
33
|
export const forkCommand = defineCommand({
|
|
11
34
|
meta: {
|
|
12
35
|
name: "fork",
|
|
13
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.",
|
|
14
37
|
},
|
|
15
|
-
args:
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
description: "Slug of the project to fork (e.g. bomberman).",
|
|
19
|
-
required: true,
|
|
20
|
-
},
|
|
21
|
-
target: {
|
|
22
|
-
type: "positional",
|
|
23
|
-
description: "New slug + directory for the fork. Defaults to <slug>-fork.",
|
|
24
|
-
required: false,
|
|
25
|
-
},
|
|
26
|
-
name: {
|
|
27
|
-
type: "string",
|
|
28
|
-
description: "Display name for the fork (defaults to the target slug).",
|
|
29
|
-
},
|
|
30
|
-
force: {
|
|
31
|
-
type: "boolean",
|
|
32
|
-
description: "Overwrite the target directory if it exists.",
|
|
33
|
-
default: false,
|
|
34
|
-
},
|
|
35
|
-
...outputArgs,
|
|
36
|
-
},
|
|
37
|
-
run: async ({ args }) => {
|
|
38
|
+
args: forkArgs,
|
|
39
|
+
run: async ({ args, rawArgs }) => {
|
|
40
|
+
assertKnownFlags(rawArgs, forkArgs);
|
|
38
41
|
const source = args.slug.trim().toLowerCase();
|
|
39
42
|
const target = (args.target ?? `${source}-fork`).trim().toLowerCase();
|
|
40
43
|
if (!SLUG_RE.test(target)) {
|
|
@@ -117,6 +117,9 @@ const runCommand = defineCommand({
|
|
|
117
117
|
...(downloaded && downloaded.failed.length > 0
|
|
118
118
|
? { download_failures: downloaded.failed }
|
|
119
119
|
: {}),
|
|
120
|
+
...(downloaded && downloaded.mislabeled.length > 0
|
|
121
|
+
? { download_format_mismatches: downloaded.mislabeled }
|
|
122
|
+
: {}),
|
|
120
123
|
};
|
|
121
124
|
if (!writeStructured(payload, args)) {
|
|
122
125
|
consola.success(`Run completed (${completed.request_id})`);
|
|
@@ -125,6 +128,7 @@ const runCommand = defineCommand({
|
|
|
125
128
|
consola.log(` ${path}`);
|
|
126
129
|
for (const f of downloaded.failed)
|
|
127
130
|
consola.warn(` failed: ${f.url} (${f.error})`);
|
|
131
|
+
warnMislabeled(downloaded.mislabeled);
|
|
128
132
|
}
|
|
129
133
|
if (!downloaded?.downloaded.length) {
|
|
130
134
|
for (const url of extractMediaUrls(completed.result))
|
|
@@ -136,6 +140,19 @@ const runCommand = defineCommand({
|
|
|
136
140
|
}
|
|
137
141
|
},
|
|
138
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
|
+
}
|
|
139
156
|
// Delegate image generation to the local Codex CLI instead of the
|
|
140
157
|
// vibedgames model runner. Produces local files directly (Codex writes
|
|
141
158
|
// to disk), so there's no queue, no request polling, and no vibedgames
|
|
@@ -278,6 +295,9 @@ const statusCommand = defineCommand({
|
|
|
278
295
|
...(downloaded && downloaded.failed.length > 0
|
|
279
296
|
? { download_failures: downloaded.failed }
|
|
280
297
|
: {}),
|
|
298
|
+
...(downloaded && downloaded.mislabeled.length > 0
|
|
299
|
+
? { download_format_mismatches: downloaded.mislabeled }
|
|
300
|
+
: {}),
|
|
281
301
|
};
|
|
282
302
|
if (!writeStructured(payload, args)) {
|
|
283
303
|
if (action === "status") {
|
|
@@ -294,6 +314,7 @@ const statusCommand = defineCommand({
|
|
|
294
314
|
consola.log(` ${p}`);
|
|
295
315
|
for (const f of downloaded.failed)
|
|
296
316
|
consola.warn(` failed: ${f.url} (${f.error})`);
|
|
317
|
+
warnMislabeled(downloaded.mislabeled);
|
|
297
318
|
}
|
|
298
319
|
if (action === "result" && !downloaded?.downloaded.length) {
|
|
299
320
|
for (const url of extractMediaUrls(data))
|
package/dist/commands/init.js
CHANGED
|
@@ -3,6 +3,7 @@ import { defineCommand } from "citty";
|
|
|
3
3
|
import consola from "consola";
|
|
4
4
|
import { detectPackageManager, globalInstallArgs, globalInstallCommand, PKG_NAME, } from "../lib/package-manager.js";
|
|
5
5
|
import { isMissingCommand, run } from "../lib/run.js";
|
|
6
|
+
import { assertKnownFlags } from "../lib/strict-args.js";
|
|
6
7
|
const REPO = "kyh/vibedgames";
|
|
7
8
|
const DEFAULT_AGENTS = "claude-code,cursor,codex";
|
|
8
9
|
const description = "Install/update vibedgames skills and the vg CLI";
|
|
@@ -24,29 +25,31 @@ const skillsUpdateArgs = (global, yes) => {
|
|
|
24
25
|
args.push("-y");
|
|
25
26
|
return args;
|
|
26
27
|
};
|
|
28
|
+
const initArgs = {
|
|
29
|
+
agent: {
|
|
30
|
+
type: "string",
|
|
31
|
+
description: "Comma-separated target agents. Default installs for Claude Code, Cursor, and Codex (symlinked from a shared .agents/skills/ dir). Pass '*' for every supported agent.",
|
|
32
|
+
alias: "a",
|
|
33
|
+
default: DEFAULT_AGENTS,
|
|
34
|
+
},
|
|
35
|
+
global: {
|
|
36
|
+
type: "boolean",
|
|
37
|
+
description: "Install to user directory instead of project",
|
|
38
|
+
default: false,
|
|
39
|
+
alias: "g",
|
|
40
|
+
},
|
|
41
|
+
yes: {
|
|
42
|
+
type: "boolean",
|
|
43
|
+
description: "Skip confirmation prompts",
|
|
44
|
+
default: true,
|
|
45
|
+
alias: "y",
|
|
46
|
+
},
|
|
47
|
+
};
|
|
27
48
|
export const initCommand = defineCommand({
|
|
28
49
|
meta: { name: "init", description },
|
|
29
|
-
args:
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
description: "Comma-separated target agents. Default installs for Claude Code, Cursor, and Codex (symlinked from a shared .agents/skills/ dir). Pass '*' for every supported agent.",
|
|
33
|
-
alias: "a",
|
|
34
|
-
default: DEFAULT_AGENTS,
|
|
35
|
-
},
|
|
36
|
-
global: {
|
|
37
|
-
type: "boolean",
|
|
38
|
-
description: "Install to user directory instead of project",
|
|
39
|
-
default: false,
|
|
40
|
-
alias: "g",
|
|
41
|
-
},
|
|
42
|
-
yes: {
|
|
43
|
-
type: "boolean",
|
|
44
|
-
description: "Skip confirmation prompts",
|
|
45
|
-
default: true,
|
|
46
|
-
alias: "y",
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
run: async ({ args }) => {
|
|
50
|
+
args: initArgs,
|
|
51
|
+
run: async ({ args, rawArgs }) => {
|
|
52
|
+
assertKnownFlags(rawArgs, initArgs);
|
|
50
53
|
const agents = args.agent
|
|
51
54
|
.split(",")
|
|
52
55
|
.map((s) => s.trim())
|
|
@@ -55,9 +58,9 @@ export const initCommand = defineCommand({
|
|
|
55
58
|
// different manager writes a second copy into a prefix the shell may not
|
|
56
59
|
// even be looking at, so `vg --version` would not move.
|
|
57
60
|
const manager = detectPackageManager(fileURLToPath(import.meta.url));
|
|
58
|
-
consola.start("Installing/updating vibedgames skills and the vg CLI...");
|
|
61
|
+
consola.start("Installing/updating vibedgames skills and the vg CLI (this takes a few minutes — `skills` fetches the repo once per skill)...");
|
|
59
62
|
const [add, cli] = await Promise.all([
|
|
60
|
-
run("npx", skillsAddArgs(agents, args.global, args.yes)),
|
|
63
|
+
run("npx", skillsAddArgs(agents, args.global, args.yes), { stream: true }),
|
|
61
64
|
run(manager, globalInstallArgs(manager)),
|
|
62
65
|
]);
|
|
63
66
|
if (add.code !== 0) {
|
|
@@ -71,7 +74,9 @@ export const initCommand = defineCommand({
|
|
|
71
74
|
throw new Error(`skills add exited with code ${add.code}`);
|
|
72
75
|
}
|
|
73
76
|
consola.success(`Installed vibedgames skills for ${agents.join(", ")}`);
|
|
74
|
-
const update = await run("npx", skillsUpdateArgs(args.global, args.yes)
|
|
77
|
+
const update = await run("npx", skillsUpdateArgs(args.global, args.yes), {
|
|
78
|
+
stream: true,
|
|
79
|
+
});
|
|
75
80
|
if (update.code !== 0) {
|
|
76
81
|
if (update.output.trim())
|
|
77
82
|
consola.warn(update.output.trim());
|
package/dist/commands/new.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export declare const newCommand: import("citty").CommandDef<{
|
|
|
6
6
|
};
|
|
7
7
|
readonly engine: {
|
|
8
8
|
readonly type: "string";
|
|
9
|
-
readonly description:
|
|
9
|
+
readonly description: `Engine preset: ${string} (default: phaser).`;
|
|
10
10
|
readonly default: "phaser";
|
|
11
11
|
};
|
|
12
12
|
readonly template: {
|
package/dist/commands/new.js
CHANGED
|
@@ -4,6 +4,7 @@ import { defineCommand } from "citty";
|
|
|
4
4
|
import consola from "consola";
|
|
5
5
|
import tiged from "tiged";
|
|
6
6
|
import { SLUG_RE } from "../lib/config-file.js";
|
|
7
|
+
import { assertKnownFlags } from "../lib/strict-args.js";
|
|
7
8
|
const ENGINES = {
|
|
8
9
|
// phaserjs/template-vite-ts is the official Phaser 4 + Vite + TypeScript
|
|
9
10
|
// starter (despite the description still saying "Phaser 3" — package.json
|
|
@@ -95,38 +96,42 @@ const NONE_FILES = [
|
|
|
95
96
|
},
|
|
96
97
|
{ path: ".gitignore", content: () => `node_modules\ndist\n.DS_Store\n` },
|
|
97
98
|
];
|
|
99
|
+
// Derived so `--help` and the error message can't drift from the presets again.
|
|
100
|
+
const ENGINE_IDS = Object.keys(ENGINES);
|
|
101
|
+
const newArgs = {
|
|
102
|
+
slug: {
|
|
103
|
+
type: "positional",
|
|
104
|
+
description: "Lowercase, hyphenated slug — used as the directory name and deploy subdomain.",
|
|
105
|
+
required: true,
|
|
106
|
+
},
|
|
107
|
+
engine: {
|
|
108
|
+
type: "string",
|
|
109
|
+
description: `Engine preset: ${ENGINE_IDS.join(", ")} (default: phaser).`,
|
|
110
|
+
default: "phaser",
|
|
111
|
+
},
|
|
112
|
+
template: {
|
|
113
|
+
type: "string",
|
|
114
|
+
description: "Override the engine preset and fetch from an arbitrary degit spec (e.g. owner/repo, owner/repo#branch). Skips the engine preset entirely.",
|
|
115
|
+
},
|
|
116
|
+
here: {
|
|
117
|
+
type: "boolean",
|
|
118
|
+
description: "Write into the current directory instead of creating <slug>/.",
|
|
119
|
+
default: false,
|
|
120
|
+
},
|
|
121
|
+
force: {
|
|
122
|
+
type: "boolean",
|
|
123
|
+
description: "Overwrite an existing target directory.",
|
|
124
|
+
default: false,
|
|
125
|
+
},
|
|
126
|
+
};
|
|
98
127
|
export const newCommand = defineCommand({
|
|
99
128
|
meta: {
|
|
100
129
|
name: "new",
|
|
101
|
-
description: "Scaffold a new browser game. Pulls an
|
|
102
|
-
},
|
|
103
|
-
args: {
|
|
104
|
-
slug: {
|
|
105
|
-
type: "positional",
|
|
106
|
-
description: "Lowercase, hyphenated slug — used as the directory name and deploy subdomain.",
|
|
107
|
-
required: true,
|
|
108
|
-
},
|
|
109
|
-
engine: {
|
|
110
|
-
type: "string",
|
|
111
|
-
description: "Engine preset: phaser (default), threejs, or none.",
|
|
112
|
-
default: "phaser",
|
|
113
|
-
},
|
|
114
|
-
template: {
|
|
115
|
-
type: "string",
|
|
116
|
-
description: "Override the engine preset and fetch from an arbitrary degit spec (e.g. owner/repo, owner/repo#branch). Skips the engine preset entirely.",
|
|
117
|
-
},
|
|
118
|
-
here: {
|
|
119
|
-
type: "boolean",
|
|
120
|
-
description: "Write into the current directory instead of creating <slug>/.",
|
|
121
|
-
default: false,
|
|
122
|
-
},
|
|
123
|
-
force: {
|
|
124
|
-
type: "boolean",
|
|
125
|
-
description: "Overwrite an existing target directory.",
|
|
126
|
-
default: false,
|
|
127
|
-
},
|
|
130
|
+
description: "Scaffold a new browser game. Pulls an engine template (phaser, threejs, react-r3f) or generates a minimal canvas starter.",
|
|
128
131
|
},
|
|
129
|
-
|
|
132
|
+
args: newArgs,
|
|
133
|
+
run: async ({ args, rawArgs }) => {
|
|
134
|
+
assertKnownFlags(rawArgs, newArgs);
|
|
130
135
|
const slug = args.slug.trim().toLowerCase();
|
|
131
136
|
if (!SLUG_RE.test(slug)) {
|
|
132
137
|
consola.error(`Invalid slug: ${args.slug}\n Use lowercase letters, digits, and hyphens (e.g. "asteroid-belt").`);
|
|
@@ -140,7 +145,7 @@ export const newCommand = defineCommand({
|
|
|
140
145
|
}
|
|
141
146
|
: ENGINES[args.engine];
|
|
142
147
|
if (!preset) {
|
|
143
|
-
consola.error(`Unknown engine: ${args.engine}. Use one of: ${
|
|
148
|
+
consola.error(`Unknown engine: ${args.engine}. Use one of: ${ENGINE_IDS.join(", ")}.`);
|
|
144
149
|
process.exit(1);
|
|
145
150
|
}
|
|
146
151
|
const target = args.here ? process.cwd() : resolve(process.cwd(), slug);
|
|
@@ -23,6 +23,18 @@ declare function resolveGameUrl(slug: string | null): string;
|
|
|
23
23
|
*/
|
|
24
24
|
export declare function bareTokens(args: string[]): string[];
|
|
25
25
|
export declare function expandGameFlag(args: string[], resolveUrl?: typeof resolveGameUrl): string[];
|
|
26
|
+
/**
|
|
27
|
+
* agent-browser's session defaults to the literal name `default`, which is
|
|
28
|
+
* shared by every caller on the machine. Two `vg playtest` runs — two projects
|
|
29
|
+
* in two terminals, or two agents on one box — then drive the SAME browser tab:
|
|
30
|
+
* one navigates away mid-run and the other screenshots its page. Scope the
|
|
31
|
+
* session to the project so concurrent playtests can't collide.
|
|
32
|
+
*
|
|
33
|
+
* Left alone when the caller already chose a session, or set one in the
|
|
34
|
+
* environment, or is asking about sessions themselves (`session list` must see
|
|
35
|
+
* every session, not just this project's).
|
|
36
|
+
*/
|
|
37
|
+
export declare function withScopedSession(args: string[], sessionId: () => string): string[];
|
|
26
38
|
/** Resolve (installing on first use) and exec agent-browser. Never returns. */
|
|
27
39
|
export declare function runPlaytest(rawArgs: string[]): never;
|
|
28
40
|
export declare const playtestCommand: import("citty").CommandDef<import("citty").ArgsDef>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
1
2
|
import { existsSync, mkdirSync, statSync, writeFileSync } from "node:fs";
|
|
2
3
|
import { join } from "node:path";
|
|
3
4
|
import { defineCommand } from "citty";
|
|
@@ -5,7 +6,7 @@ import consola from "consola";
|
|
|
5
6
|
import spawn from "cross-spawn";
|
|
6
7
|
import { getBaseUrl, getConfigDir } from "../lib/config.js";
|
|
7
8
|
import { isNewerVersion } from "../lib/update.js";
|
|
8
|
-
import { SLUG_RE, readProjectConfig } from "../lib/config-file.js";
|
|
9
|
+
import { SLUG_RE, findProjectRoot, readProjectConfig } from "../lib/config-file.js";
|
|
9
10
|
/**
|
|
10
11
|
* `vg playtest` — drive a browser to actually play the game.
|
|
11
12
|
*
|
|
@@ -302,9 +303,42 @@ export function expandGameFlag(args, resolveUrl = resolveGameUrl) {
|
|
|
302
303
|
}
|
|
303
304
|
return out;
|
|
304
305
|
}
|
|
306
|
+
/**
|
|
307
|
+
* agent-browser's session defaults to the literal name `default`, which is
|
|
308
|
+
* shared by every caller on the machine. Two `vg playtest` runs — two projects
|
|
309
|
+
* in two terminals, or two agents on one box — then drive the SAME browser tab:
|
|
310
|
+
* one navigates away mid-run and the other screenshots its page. Scope the
|
|
311
|
+
* session to the project so concurrent playtests can't collide.
|
|
312
|
+
*
|
|
313
|
+
* Left alone when the caller already chose a session, or set one in the
|
|
314
|
+
* environment, or is asking about sessions themselves (`session list` must see
|
|
315
|
+
* every session, not just this project's).
|
|
316
|
+
*/
|
|
317
|
+
export function withScopedSession(args, sessionId) {
|
|
318
|
+
if (args.includes("--session") || args.some((a) => a.startsWith("--session=")))
|
|
319
|
+
return args;
|
|
320
|
+
if (process.env.AGENT_BROWSER_SESSION)
|
|
321
|
+
return args;
|
|
322
|
+
const verb = bareTokens(args)[0];
|
|
323
|
+
// No verb means `--help`/`--version`, and `install`/`session` are machine-wide
|
|
324
|
+
// — `session list` has to see every session, not just this project's.
|
|
325
|
+
if (verb === undefined || verb === "session" || verb === "install")
|
|
326
|
+
return args;
|
|
327
|
+
return ["--session", sessionId(), ...args];
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* A stable per-project session name. Keyed on the project root when there is
|
|
331
|
+
* one so every command run from anywhere inside the project shares a browser,
|
|
332
|
+
* and on the cwd otherwise. Hashed because the name lands in a socket path.
|
|
333
|
+
*/
|
|
334
|
+
function projectSessionId() {
|
|
335
|
+
const root = findProjectRoot(process.cwd()) ?? process.cwd();
|
|
336
|
+
const digest = createHash("sha256").update(root).digest("hex").slice(0, 12);
|
|
337
|
+
return `vg-${digest}`;
|
|
338
|
+
}
|
|
305
339
|
/** Resolve (installing on first use) and exec agent-browser. Never returns. */
|
|
306
340
|
export function runPlaytest(rawArgs) {
|
|
307
|
-
const args = expandGameFlag(rawArgs);
|
|
341
|
+
const args = withScopedSession(expandGameFlag(rawArgs), projectSessionId);
|
|
308
342
|
// Bootstrap covers `install` too: on a fresh machine that's the most natural
|
|
309
343
|
// first command, and re-running the provision step it just did is harmless.
|
|
310
344
|
const resolved = resolveBinary();
|
package/dist/commands/update.js
CHANGED
|
@@ -4,6 +4,7 @@ import { defineCommand } from "citty";
|
|
|
4
4
|
import consola from "consola";
|
|
5
5
|
import { detectPackageManager, globalInstallArgs, globalInstallCommand, } from "../lib/package-manager.js";
|
|
6
6
|
import { isMissingCommand, run } from "../lib/run.js";
|
|
7
|
+
import { assertKnownFlags } from "../lib/strict-args.js";
|
|
7
8
|
import { fetchLatestVersion, isNewerVersion } from "../lib/update.js";
|
|
8
9
|
const pkg = JSON.parse(readFileSync(new URL("../../package.json", import.meta.url), "utf8"));
|
|
9
10
|
const skillsUpdateArgs = (global) => {
|
|
@@ -12,25 +13,27 @@ const skillsUpdateArgs = (global) => {
|
|
|
12
13
|
args.push("-g");
|
|
13
14
|
return args;
|
|
14
15
|
};
|
|
16
|
+
const updateArgs = {
|
|
17
|
+
global: {
|
|
18
|
+
type: "boolean",
|
|
19
|
+
description: "Update skills installed in the user directory instead of the project",
|
|
20
|
+
default: false,
|
|
21
|
+
alias: "g",
|
|
22
|
+
},
|
|
23
|
+
auto: {
|
|
24
|
+
type: "boolean",
|
|
25
|
+
description: "(internal) silent background mode: only update when the registry has a newer version",
|
|
26
|
+
default: false,
|
|
27
|
+
},
|
|
28
|
+
};
|
|
15
29
|
export const updateCommand = defineCommand({
|
|
16
30
|
meta: {
|
|
17
31
|
name: "update",
|
|
18
32
|
description: "Update the vg CLI and vibedgames skills to latest (runs automatically once a day; disable with VG_NO_AUTO_UPDATE=1)",
|
|
19
33
|
},
|
|
20
|
-
args:
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
description: "Update skills installed in the user directory instead of the project",
|
|
24
|
-
default: false,
|
|
25
|
-
alias: "g",
|
|
26
|
-
},
|
|
27
|
-
auto: {
|
|
28
|
-
type: "boolean",
|
|
29
|
-
description: "(internal) silent background mode: only update when the registry has a newer version",
|
|
30
|
-
default: false,
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
run: async ({ args }) => {
|
|
34
|
+
args: updateArgs,
|
|
35
|
+
run: async ({ args, rawArgs }) => {
|
|
36
|
+
assertKnownFlags(rawArgs, updateArgs);
|
|
34
37
|
// Upgrade with whatever installed this CLI: another manager would write a
|
|
35
38
|
// second copy into a different global prefix, leaving the one on PATH stale.
|
|
36
39
|
const manager = detectPackageManager(fileURLToPath(import.meta.url));
|
|
@@ -1 +1,10 @@
|
|
|
1
|
-
export declare const whoamiCommand: import("citty").CommandDef<
|
|
1
|
+
export declare const whoamiCommand: 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
|
+
};
|
|
10
|
+
}>;
|
package/dist/commands/whoami.js
CHANGED
|
@@ -2,12 +2,17 @@ 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 whoamiArgs = { ...outputArgs };
|
|
5
8
|
export const whoamiCommand = defineCommand({
|
|
6
9
|
meta: {
|
|
7
10
|
name: "whoami",
|
|
8
11
|
description: "Show the currently authenticated user",
|
|
9
12
|
},
|
|
10
|
-
|
|
13
|
+
args: whoamiArgs,
|
|
14
|
+
run: async ({ args, rawArgs }) => {
|
|
15
|
+
assertKnownFlags(rawArgs, whoamiArgs);
|
|
11
16
|
const token = getToken();
|
|
12
17
|
if (!token) {
|
|
13
18
|
consola.warn("Not logged in. Run `vg login` to authenticate.");
|
|
@@ -18,6 +23,8 @@ export const whoamiCommand = defineCommand({
|
|
|
18
23
|
const client = createClient();
|
|
19
24
|
try {
|
|
20
25
|
const user = await client.auth.me.query();
|
|
26
|
+
if (writeStructured({ id: user.id, name: user.name, email: user.email }, args))
|
|
27
|
+
return;
|
|
21
28
|
consola.log(`${user.name} (${user.email})`);
|
|
22
29
|
}
|
|
23
30
|
catch (err) {
|
|
@@ -95,6 +95,46 @@ function extFromUrl(url) {
|
|
|
95
95
|
return "";
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
|
+
// The extension each content type genuinely is. Only formats an agent is
|
|
99
|
+
// likely to hand to a decoder afterwards need an entry; anything absent is
|
|
100
|
+
// left alone rather than guessed at.
|
|
101
|
+
const EXT_FOR_CONTENT_TYPE = {
|
|
102
|
+
"image/png": "png",
|
|
103
|
+
"image/jpeg": "jpg",
|
|
104
|
+
"image/webp": "webp",
|
|
105
|
+
"image/gif": "gif",
|
|
106
|
+
"image/avif": "avif",
|
|
107
|
+
"video/mp4": "mp4",
|
|
108
|
+
"video/webm": "webm",
|
|
109
|
+
"video/quicktime": "mov",
|
|
110
|
+
"audio/mpeg": "mp3",
|
|
111
|
+
"audio/wav": "wav",
|
|
112
|
+
"audio/ogg": "ogg",
|
|
113
|
+
};
|
|
114
|
+
// Extensions that name the same format, so `.jpg` for `image/jpeg` is not a lie.
|
|
115
|
+
const EXT_ALIASES = {
|
|
116
|
+
jpeg: "jpg",
|
|
117
|
+
tif: "tiff",
|
|
118
|
+
htm: "html",
|
|
119
|
+
};
|
|
120
|
+
const canonicalExt = (ext) => EXT_ALIASES[ext] ?? ext;
|
|
121
|
+
/**
|
|
122
|
+
* The extension the caller asked for versus the bytes actually served.
|
|
123
|
+
*
|
|
124
|
+
* `--download board.png` is honoured literally — renaming the path the caller
|
|
125
|
+
* chose would break whatever they wired it into — so when a model returns JPEG
|
|
126
|
+
* the file is a `.png` holding JPEG bytes. Downstream decoders reject it with
|
|
127
|
+
* "bad signature" and nothing points back here, hence the explicit report.
|
|
128
|
+
*/
|
|
129
|
+
function mislabelOf(target, ref) {
|
|
130
|
+
const asked = canonicalExt(extname(target).slice(1).toLowerCase());
|
|
131
|
+
if (!asked)
|
|
132
|
+
return null;
|
|
133
|
+
const actual = ref.contentType ? EXT_FOR_CONTENT_TYPE[ref.contentType] : undefined;
|
|
134
|
+
if (!actual || canonicalExt(actual) === asked)
|
|
135
|
+
return null;
|
|
136
|
+
return { path: target, actual };
|
|
137
|
+
}
|
|
98
138
|
/**
|
|
99
139
|
* Download all extracted media refs to disk, materializing the path from
|
|
100
140
|
* a template. Supported placeholders: {index}, {name}, {ext}, {request_id}.
|
|
@@ -121,7 +161,7 @@ export async function downloadMedia(opts) {
|
|
|
121
161
|
}
|
|
122
162
|
const bytes = new Uint8Array(await res.arrayBuffer());
|
|
123
163
|
writeFileSync(target, bytes);
|
|
124
|
-
return { ok: true, target };
|
|
164
|
+
return { ok: true, target, mislabel: mislabelOf(target, ref) };
|
|
125
165
|
}
|
|
126
166
|
catch (err) {
|
|
127
167
|
return {
|
|
@@ -133,13 +173,17 @@ export async function downloadMedia(opts) {
|
|
|
133
173
|
}));
|
|
134
174
|
const downloaded = [];
|
|
135
175
|
const failed = [];
|
|
176
|
+
const mislabeled = [];
|
|
136
177
|
for (const o of outcomes) {
|
|
137
|
-
if (o.ok)
|
|
138
|
-
downloaded.push(o.target);
|
|
139
|
-
else
|
|
178
|
+
if (!o.ok) {
|
|
140
179
|
failed.push({ url: o.url, error: o.error });
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
downloaded.push(o.target);
|
|
183
|
+
if (o.mislabel)
|
|
184
|
+
mislabeled.push(o.mislabel);
|
|
141
185
|
}
|
|
142
|
-
return { downloaded, failed };
|
|
186
|
+
return { downloaded, failed, mislabeled };
|
|
143
187
|
}
|
|
144
188
|
// Strip any directory components from a fal-provided file_name so a
|
|
145
189
|
// malicious response can't traverse out of the download target dir.
|
package/dist/lib/run.d.ts
CHANGED
|
@@ -2,10 +2,18 @@ export type RunResult = {
|
|
|
2
2
|
code: number;
|
|
3
3
|
output: string;
|
|
4
4
|
};
|
|
5
|
+
export type RunOptions = {
|
|
6
|
+
/**
|
|
7
|
+
* Mirror the child's output to this process as it arrives. Long steps
|
|
8
|
+
* (`npx skills add` clones a repo per skill) otherwise look hung: the
|
|
9
|
+
* buffered output is only readable once the child has already exited.
|
|
10
|
+
*/
|
|
11
|
+
stream?: boolean;
|
|
12
|
+
};
|
|
5
13
|
/**
|
|
6
14
|
* True when the command never started, as opposed to running and failing.
|
|
7
15
|
* `run` turns a spawn error into an exit code, so the message is the only
|
|
8
16
|
* thing that separates "no such binary" from "the binary said no".
|
|
9
17
|
*/
|
|
10
18
|
export declare const isMissingCommand: (result: RunResult) => boolean;
|
|
11
|
-
export declare const run: (cmd: string, args: string[]) => Promise<RunResult>;
|
|
19
|
+
export declare const run: (cmd: string, args: string[], options?: RunOptions) => Promise<RunResult>;
|
package/dist/lib/run.js
CHANGED
|
@@ -5,11 +5,16 @@ import spawn from "cross-spawn";
|
|
|
5
5
|
* thing that separates "no such binary" from "the binary said no".
|
|
6
6
|
*/
|
|
7
7
|
export const isMissingCommand = (result) => result.code !== 0 && /ENOENT|not found|not recognized/i.test(result.output);
|
|
8
|
-
export const run = (cmd, args) => new Promise((resolve) => {
|
|
8
|
+
export const run = (cmd, args, options = {}) => new Promise((resolve) => {
|
|
9
9
|
const chunks = [];
|
|
10
10
|
const child = spawn(cmd, args, { stdio: ["ignore", "pipe", "pipe"] });
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
const collect = (stream) => (c) => {
|
|
12
|
+
chunks.push(c);
|
|
13
|
+
if (options.stream)
|
|
14
|
+
stream.write(c);
|
|
15
|
+
};
|
|
16
|
+
child.stdout?.on("data", collect(process.stderr));
|
|
17
|
+
child.stderr?.on("data", collect(process.stderr));
|
|
13
18
|
child.on("error", (err) => resolve({ code: 1, output: `${err.message}\n` }));
|
|
14
19
|
child.on("close", (code) => resolve({ code: code ?? 1, output: Buffer.concat(chunks).toString("utf8") }));
|
|
15
20
|
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reject flags a command does not declare.
|
|
3
|
+
*
|
|
4
|
+
* citty hard-codes `strict: false` on node's `parseArgs`, so an unknown flag is
|
|
5
|
+
* parsed and then dropped: `vg deploy ./dist --slugg wrong` deploys to the
|
|
6
|
+
* *default* slug and exits 0. A human notices the wrong URL in the output; an
|
|
7
|
+
* agent reads exit 0 and carries on. The skill scripts already fail this way
|
|
8
|
+
* (`unrecognized arguments: …`, exit 2), so this matches them.
|
|
9
|
+
*
|
|
10
|
+
* Only for commands whose flags are a closed set. `vg generate run` forwards
|
|
11
|
+
* arbitrary `--param value` pairs to a model's schema and must stay permissive,
|
|
12
|
+
* and `vg playtest`/`vg factory` are passthroughs to another binary's grammar.
|
|
13
|
+
*/
|
|
14
|
+
/** The subset of citty's `ArgDef` this check reads. */
|
|
15
|
+
type ArgSpec = {
|
|
16
|
+
type?: string;
|
|
17
|
+
alias?: string | string[];
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* The long flags in `rawArgs` that `argsDef` does not declare, in the order
|
|
21
|
+
* they were typed. Everything after a bare `--` is a passthrough payload and is
|
|
22
|
+
* left alone.
|
|
23
|
+
*/
|
|
24
|
+
export declare function unknownFlags(rawArgs: string[], argsDef: Record<string, ArgSpec>): string[];
|
|
25
|
+
/** Exit 2 naming every undeclared flag, or return so the command can run. */
|
|
26
|
+
export declare function assertKnownFlags(rawArgs: string[], argsDef: Record<string, ArgSpec>): void;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reject flags a command does not declare.
|
|
3
|
+
*
|
|
4
|
+
* citty hard-codes `strict: false` on node's `parseArgs`, so an unknown flag is
|
|
5
|
+
* parsed and then dropped: `vg deploy ./dist --slugg wrong` deploys to the
|
|
6
|
+
* *default* slug and exits 0. A human notices the wrong URL in the output; an
|
|
7
|
+
* agent reads exit 0 and carries on. The skill scripts already fail this way
|
|
8
|
+
* (`unrecognized arguments: …`, exit 2), so this matches them.
|
|
9
|
+
*
|
|
10
|
+
* Only for commands whose flags are a closed set. `vg generate run` forwards
|
|
11
|
+
* arbitrary `--param value` pairs to a model's schema and must stay permissive,
|
|
12
|
+
* and `vg playtest`/`vg factory` are passthroughs to another binary's grammar.
|
|
13
|
+
*/
|
|
14
|
+
const UNRECOGNIZED_EXIT = 2;
|
|
15
|
+
function declaredNames(argsDef) {
|
|
16
|
+
const names = new Set();
|
|
17
|
+
for (const [name, spec] of Object.entries(argsDef)) {
|
|
18
|
+
if (spec.type === "positional")
|
|
19
|
+
continue;
|
|
20
|
+
names.add(name);
|
|
21
|
+
// citty accepts a camelCase arg under its kebab spelling too.
|
|
22
|
+
names.add(name.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`));
|
|
23
|
+
const alias = spec.alias;
|
|
24
|
+
if (typeof alias === "string")
|
|
25
|
+
names.add(alias);
|
|
26
|
+
else if (Array.isArray(alias))
|
|
27
|
+
for (const a of alias)
|
|
28
|
+
names.add(a);
|
|
29
|
+
}
|
|
30
|
+
// citty answers these itself; they never reach a command's `args`.
|
|
31
|
+
names.add("help");
|
|
32
|
+
names.add("version");
|
|
33
|
+
return names;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The long flags in `rawArgs` that `argsDef` does not declare, in the order
|
|
37
|
+
* they were typed. Everything after a bare `--` is a passthrough payload and is
|
|
38
|
+
* left alone.
|
|
39
|
+
*/
|
|
40
|
+
export function unknownFlags(rawArgs, argsDef) {
|
|
41
|
+
const known = declaredNames(argsDef);
|
|
42
|
+
const unknown = [];
|
|
43
|
+
for (const raw of rawArgs) {
|
|
44
|
+
if (raw === "--")
|
|
45
|
+
break;
|
|
46
|
+
if (!raw.startsWith("--") || raw.length === 2)
|
|
47
|
+
continue;
|
|
48
|
+
const flag = (raw.slice(2).split("=")[0] ?? "").trim();
|
|
49
|
+
if (flag.length === 0)
|
|
50
|
+
continue;
|
|
51
|
+
// `--no-foo` is citty's negation of the boolean `foo`.
|
|
52
|
+
const negated = flag.startsWith("no-") ? flag.slice(3) : null;
|
|
53
|
+
if (known.has(flag))
|
|
54
|
+
continue;
|
|
55
|
+
if (negated !== null && known.has(negated))
|
|
56
|
+
continue;
|
|
57
|
+
unknown.push(`--${flag}`);
|
|
58
|
+
}
|
|
59
|
+
return unknown;
|
|
60
|
+
}
|
|
61
|
+
/** Exit 2 naming every undeclared flag, or return so the command can run. */
|
|
62
|
+
export function assertKnownFlags(rawArgs, argsDef) {
|
|
63
|
+
const unknown = unknownFlags(rawArgs, argsDef);
|
|
64
|
+
if (unknown.length === 0)
|
|
65
|
+
return;
|
|
66
|
+
process.stderr.write(`unrecognized arguments: ${unknown.join(" ")}\n`);
|
|
67
|
+
process.exit(UNRECOGNIZED_EXIT);
|
|
68
|
+
}
|