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 +11 -1
- package/dist/commands/completions.js +3 -0
- package/dist/commands/credits.d.ts +4 -0
- package/dist/commands/credits.js +20 -25
- package/dist/commands/deploy.d.ts +8 -0
- package/dist/commands/deploy.js +51 -29
- package/dist/commands/fork.d.ts +8 -5
- package/dist/commands/fork.js +30 -32
- package/dist/commands/generate.js +67 -53
- package/dist/commands/init.js +47 -30
- package/dist/commands/new.d.ts +1 -1
- package/dist/commands/new.js +35 -30
- package/dist/commands/playtest.d.ts +41 -0
- package/dist/commands/playtest.js +359 -0
- package/dist/commands/update.d.ts +1 -1
- package/dist/commands/update.js +30 -21
- package/dist/commands/whoami.d.ts +10 -1
- package/dist/commands/whoami.js +8 -1
- package/dist/index.js +9 -3
- package/dist/lib/config-file.d.ts +6 -0
- package/dist/lib/config-file.js +6 -0
- package/dist/lib/manifest.js +2 -0
- package/dist/lib/media-download.d.ts +4 -0
- package/dist/lib/media-download.js +49 -5
- package/dist/lib/output.d.ts +45 -0
- package/dist/lib/output.js +94 -0
- package/dist/lib/package-manager.d.ts +25 -0
- package/dist/lib/package-manager.js +72 -0
- package/dist/lib/run.d.ts +15 -1
- package/dist/lib/run.js +14 -3
- package/dist/lib/strict-args.d.ts +27 -0
- package/dist/lib/strict-args.js +68 -0
- package/package.json +4 -4
package/dist/commands/update.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
2
3
|
import { defineCommand } from "citty";
|
|
3
4
|
import consola from "consola";
|
|
4
|
-
import {
|
|
5
|
+
import { detectPackageManager, globalInstallArgs, globalInstallCommand, } from "../lib/package-manager.js";
|
|
6
|
+
import { isMissingCommand, run } from "../lib/run.js";
|
|
7
|
+
import { assertKnownFlags } from "../lib/strict-args.js";
|
|
5
8
|
import { fetchLatestVersion, isNewerVersion } from "../lib/update.js";
|
|
6
|
-
const PKG = "vibedgames";
|
|
7
9
|
const pkg = JSON.parse(readFileSync(new URL("../../package.json", import.meta.url), "utf8"));
|
|
8
10
|
const skillsUpdateArgs = (global) => {
|
|
9
11
|
const args = ["-y", "skills", "update", "-y"];
|
|
@@ -11,47 +13,54 @@ const skillsUpdateArgs = (global) => {
|
|
|
11
13
|
args.push("-g");
|
|
12
14
|
return args;
|
|
13
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
|
+
};
|
|
14
29
|
export const updateCommand = defineCommand({
|
|
15
30
|
meta: {
|
|
16
31
|
name: "update",
|
|
17
32
|
description: "Update the vg CLI and vibedgames skills to latest (runs automatically once a day; disable with VG_NO_AUTO_UPDATE=1)",
|
|
18
33
|
},
|
|
19
|
-
args:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
},
|
|
26
|
-
auto: {
|
|
27
|
-
type: "boolean",
|
|
28
|
-
description: "(internal) silent background mode: only update when npm has a newer version",
|
|
29
|
-
default: false,
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
run: async ({ args }) => {
|
|
34
|
+
args: updateArgs,
|
|
35
|
+
run: async ({ args, rawArgs }) => {
|
|
36
|
+
assertKnownFlags(rawArgs, updateArgs);
|
|
37
|
+
// Upgrade with whatever installed this CLI: another manager would write a
|
|
38
|
+
// second copy into a different global prefix, leaving the one on PATH stale.
|
|
39
|
+
const manager = detectPackageManager(fileURLToPath(import.meta.url));
|
|
33
40
|
if (args.auto) {
|
|
34
41
|
const latest = await fetchLatestVersion();
|
|
35
42
|
if (!latest || !isNewerVersion(latest, pkg.version))
|
|
36
43
|
return;
|
|
37
44
|
await Promise.all([
|
|
38
|
-
run(
|
|
45
|
+
run(manager, globalInstallArgs(manager)),
|
|
39
46
|
run("npx", skillsUpdateArgs(args.global)),
|
|
40
47
|
]);
|
|
41
48
|
return;
|
|
42
49
|
}
|
|
43
50
|
consola.start("Updating the vg CLI and vibedgames skills...");
|
|
44
51
|
const [cli, skills] = await Promise.all([
|
|
45
|
-
run(
|
|
52
|
+
run(manager, globalInstallArgs(manager)),
|
|
46
53
|
run("npx", skillsUpdateArgs(args.global)),
|
|
47
54
|
]);
|
|
48
55
|
if (cli.code === 0) {
|
|
49
|
-
consola.success(
|
|
56
|
+
consola.success(`vg CLI updated to latest with ${manager}`);
|
|
50
57
|
}
|
|
51
58
|
else {
|
|
52
|
-
if (cli.output.trim())
|
|
59
|
+
if (cli.output.trim() && !isMissingCommand(cli))
|
|
53
60
|
consola.warn(cli.output.trim());
|
|
54
|
-
consola.warn(
|
|
61
|
+
consola.warn(isMissingCommand(cli)
|
|
62
|
+
? `Couldn't find ${manager} to update the vg CLI. Update manually: ${globalInstallCommand(manager)}`
|
|
63
|
+
: `Couldn't update the vg CLI (${manager} exit ${cli.code}). Update manually: ${globalInstallCommand(manager)}`);
|
|
55
64
|
}
|
|
56
65
|
if (skills.code === 0) {
|
|
57
66
|
consola.success("Skills updated to latest");
|
|
@@ -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) {
|
package/dist/index.js
CHANGED
|
@@ -11,6 +11,7 @@ import { initCommand } from "./commands/init.js";
|
|
|
11
11
|
import { loginCommand } from "./commands/login.js";
|
|
12
12
|
import { logoutCommand } from "./commands/logout.js";
|
|
13
13
|
import { newCommand } from "./commands/new.js";
|
|
14
|
+
import { playtestCommand, runPlaytest } from "./commands/playtest.js";
|
|
14
15
|
import { updateCommand } from "./commands/update.js";
|
|
15
16
|
import { whoamiCommand } from "./commands/whoami.js";
|
|
16
17
|
import { maybeScheduleAutoUpdate } from "./lib/update.js";
|
|
@@ -27,6 +28,7 @@ const main = defineCommand({
|
|
|
27
28
|
login: loginCommand,
|
|
28
29
|
logout: logoutCommand,
|
|
29
30
|
deploy: deployCommand,
|
|
31
|
+
playtest: playtestCommand,
|
|
30
32
|
factory: factoryCommand,
|
|
31
33
|
fork: forkCommand,
|
|
32
34
|
generate: generateCommand,
|
|
@@ -42,10 +44,14 @@ const subcommand = process.argv[2];
|
|
|
42
44
|
if (subcommand && !["update", "init", "completions"].includes(subcommand)) {
|
|
43
45
|
maybeScheduleAutoUpdate();
|
|
44
46
|
}
|
|
45
|
-
// `vg factory`
|
|
46
|
-
// before citty runs so flags like --help/--version reach the binary
|
|
47
|
-
// of being intercepted here. (The registered
|
|
47
|
+
// `vg factory` and `vg playtest` are pure passthroughs to their binaries —
|
|
48
|
+
// route them before citty runs so flags like --help/--version reach the binary
|
|
49
|
+
// instead of being intercepted here. (The registered commands keep them in
|
|
50
|
+
// `vg --help`.)
|
|
48
51
|
if (subcommand === "factory") {
|
|
49
52
|
runFactory(process.argv.slice(3));
|
|
50
53
|
}
|
|
54
|
+
if (subcommand === "playtest") {
|
|
55
|
+
runPlaytest(process.argv.slice(3));
|
|
56
|
+
}
|
|
51
57
|
runMain(main);
|
|
@@ -2,6 +2,12 @@ export type ProjectConfig = {
|
|
|
2
2
|
slug: string;
|
|
3
3
|
name?: string;
|
|
4
4
|
};
|
|
5
|
+
/**
|
|
6
|
+
* The slug grammar every surface must agree on — it is the deploy target, the
|
|
7
|
+
* fork target, and the label in `{slug}.vibedgames.com`. Kept here rather than
|
|
8
|
+
* per-command so a validator can't drift and reject a slug that deploy accepts.
|
|
9
|
+
*/
|
|
10
|
+
export declare const SLUG_RE: RegExp;
|
|
5
11
|
/** The directory containing the nearest vibedgames.json at or above `dir`,
|
|
6
12
|
* or null if none — i.e. the project root to archive as forkable source. */
|
|
7
13
|
export declare function findProjectRoot(dir: string): string | null;
|
package/dist/lib/config-file.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { dirname, join, resolve } from "node:path";
|
|
3
3
|
const FILENAME = "vibedgames.json";
|
|
4
|
+
/**
|
|
5
|
+
* The slug grammar every surface must agree on — it is the deploy target, the
|
|
6
|
+
* fork target, and the label in `{slug}.vibedgames.com`. Kept here rather than
|
|
7
|
+
* per-command so a validator can't drift and reject a slug that deploy accepts.
|
|
8
|
+
*/
|
|
9
|
+
export const SLUG_RE = /^[a-z0-9][a-z0-9-]*[a-z0-9]$/;
|
|
4
10
|
// Walk from `dir` up toward the filesystem root, stopping at the first
|
|
5
11
|
// vibedgames.json. Lets `vg deploy ./dist` pick up the config from the
|
|
6
12
|
// project root even when the build step doesn't copy it into the output.
|
package/dist/lib/manifest.js
CHANGED
|
@@ -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.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared stdout helpers for machine-readable output.
|
|
3
|
+
*
|
|
4
|
+
* The skills are written for an agent, so nearly every command grew a
|
|
5
|
+
* `--json` flag and the docs then piped it through `jq` to pull out a single
|
|
6
|
+
* value. That made `jq` a hard prerequisite for following the generate
|
|
7
|
+
* skill at all. `--field` removes it: the CLI does the selection itself and
|
|
8
|
+
* prints a bare scalar that a shell can capture directly.
|
|
9
|
+
*/
|
|
10
|
+
export type OutputArgs = {
|
|
11
|
+
json?: boolean;
|
|
12
|
+
field?: string;
|
|
13
|
+
};
|
|
14
|
+
export declare function isJsonOutput(args: OutputArgs): boolean;
|
|
15
|
+
export declare function writeJson(value: unknown): void;
|
|
16
|
+
/**
|
|
17
|
+
* Resolve a dotted path against a decoded JSON value. Supports array indexing
|
|
18
|
+
* in both `items[0]` and `items.0` spellings, since agents write both.
|
|
19
|
+
* Returns `undefined` for any path that doesn't resolve.
|
|
20
|
+
*/
|
|
21
|
+
export declare function selectField(value: unknown, path: string): unknown;
|
|
22
|
+
/**
|
|
23
|
+
* Render one selected value for shell capture. Scalars print bare so
|
|
24
|
+
* `$(vg ... --field url)` needs no unquoting; arrays of scalars print one per
|
|
25
|
+
* line so they can be looped over; anything structural falls back to JSON.
|
|
26
|
+
*/
|
|
27
|
+
export declare function formatField(value: unknown): string;
|
|
28
|
+
/**
|
|
29
|
+
* The standard exit path for a command that produced structured data.
|
|
30
|
+
* `--field` wins over `--json` when both are passed, since asking for one
|
|
31
|
+
* value is the more specific request. Returns false when neither flag was
|
|
32
|
+
* given, so the caller can fall through to its human-readable rendering.
|
|
33
|
+
*/
|
|
34
|
+
export declare function writeStructured(value: unknown, args: OutputArgs): boolean;
|
|
35
|
+
/** The `--json`/`--field` arg pair, for spreading into a citty `args` block. */
|
|
36
|
+
export declare const outputArgs: {
|
|
37
|
+
readonly json: {
|
|
38
|
+
readonly type: "boolean";
|
|
39
|
+
readonly description: "Print structured JSON to stdout.";
|
|
40
|
+
};
|
|
41
|
+
readonly field: {
|
|
42
|
+
readonly type: "string";
|
|
43
|
+
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.";
|
|
44
|
+
};
|
|
45
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared stdout helpers for machine-readable output.
|
|
3
|
+
*
|
|
4
|
+
* The skills are written for an agent, so nearly every command grew a
|
|
5
|
+
* `--json` flag and the docs then piped it through `jq` to pull out a single
|
|
6
|
+
* value. That made `jq` a hard prerequisite for following the generate
|
|
7
|
+
* skill at all. `--field` removes it: the CLI does the selection itself and
|
|
8
|
+
* prints a bare scalar that a shell can capture directly.
|
|
9
|
+
*/
|
|
10
|
+
export function isJsonOutput(args) {
|
|
11
|
+
return Boolean(args.json) || process.env.VG_JSON_OUTPUT === "1";
|
|
12
|
+
}
|
|
13
|
+
export function writeJson(value) {
|
|
14
|
+
process.stdout.write(`${JSON.stringify(value, null, 2)}\n`);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Resolve a dotted path against a decoded JSON value. Supports array indexing
|
|
18
|
+
* in both `items[0]` and `items.0` spellings, since agents write both.
|
|
19
|
+
* Returns `undefined` for any path that doesn't resolve.
|
|
20
|
+
*/
|
|
21
|
+
export function selectField(value, path) {
|
|
22
|
+
const segments = path
|
|
23
|
+
.replace(/\[(-?\d+)\]/g, ".$1")
|
|
24
|
+
.split(".")
|
|
25
|
+
.filter(Boolean);
|
|
26
|
+
let current = value;
|
|
27
|
+
for (const segment of segments) {
|
|
28
|
+
if (current === null || current === undefined)
|
|
29
|
+
return undefined;
|
|
30
|
+
if (Array.isArray(current)) {
|
|
31
|
+
const index = Number(segment);
|
|
32
|
+
if (!Number.isInteger(index))
|
|
33
|
+
return undefined;
|
|
34
|
+
// Negative indices count from the end, which is handy for "the last
|
|
35
|
+
// frame" style selections.
|
|
36
|
+
current = current.at(index);
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if (typeof current !== "object")
|
|
40
|
+
return undefined;
|
|
41
|
+
current = current[segment];
|
|
42
|
+
}
|
|
43
|
+
return current;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Render one selected value for shell capture. Scalars print bare so
|
|
47
|
+
* `$(vg ... --field url)` needs no unquoting; arrays of scalars print one per
|
|
48
|
+
* line so they can be looped over; anything structural falls back to JSON.
|
|
49
|
+
*/
|
|
50
|
+
export function formatField(value) {
|
|
51
|
+
if (value === null || value === undefined)
|
|
52
|
+
return "";
|
|
53
|
+
if (Array.isArray(value)) {
|
|
54
|
+
if (value.every((v) => v === null || ["string", "number", "boolean"].includes(typeof v))) {
|
|
55
|
+
return value.map((v) => (v === null ? "" : String(v))).join("\n");
|
|
56
|
+
}
|
|
57
|
+
return JSON.stringify(value, null, 2);
|
|
58
|
+
}
|
|
59
|
+
if (typeof value === "object")
|
|
60
|
+
return JSON.stringify(value, null, 2);
|
|
61
|
+
return String(value);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The standard exit path for a command that produced structured data.
|
|
65
|
+
* `--field` wins over `--json` when both are passed, since asking for one
|
|
66
|
+
* value is the more specific request. Returns false when neither flag was
|
|
67
|
+
* given, so the caller can fall through to its human-readable rendering.
|
|
68
|
+
*/
|
|
69
|
+
export function writeStructured(value, args) {
|
|
70
|
+
if (args.field) {
|
|
71
|
+
const selected = selectField(value, args.field);
|
|
72
|
+
if (selected === undefined) {
|
|
73
|
+
// Silence here would look like an empty result rather than a typo, and
|
|
74
|
+
// an agent would happily carry the empty string forward.
|
|
75
|
+
process.stderr.write(`No such field: ${args.field}\n`);
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
process.stdout.write(`${formatField(selected)}\n`);
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
if (isJsonOutput(args)) {
|
|
82
|
+
writeJson(value);
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
/** The `--json`/`--field` arg pair, for spreading into a citty `args` block. */
|
|
88
|
+
export const outputArgs = {
|
|
89
|
+
json: { type: "boolean", description: "Print structured JSON to stdout." },
|
|
90
|
+
field: {
|
|
91
|
+
type: "string",
|
|
92
|
+
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.",
|
|
93
|
+
},
|
|
94
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Work out which package manager installed this CLI, so a self-update uses it.
|
|
3
|
+
*
|
|
4
|
+
* `vg init` and `vg update` both used to shell out to `npm install -g
|
|
5
|
+
* vibedgames` unconditionally. On a machine where the CLI came from pnpm, bun
|
|
6
|
+
* or yarn, that is wrong twice over: npm may not be installed at all, and if it
|
|
7
|
+
* is, it installs a *second* copy into a different global prefix — so the
|
|
8
|
+
* update silently lands somewhere the shell isn't looking and `vg --version`
|
|
9
|
+
* doesn't move.
|
|
10
|
+
*
|
|
11
|
+
* The install path is the evidence. Each manager puts globals somewhere
|
|
12
|
+
* recognisable, so the directory this file was loaded from names the manager
|
|
13
|
+
* that put it there.
|
|
14
|
+
*/
|
|
15
|
+
export type PackageManager = "npm" | "pnpm" | "yarn" | "bun";
|
|
16
|
+
export declare const PKG_NAME = "vibedgames";
|
|
17
|
+
/**
|
|
18
|
+
* `installPath` is where the CLI is installed — normally the directory this
|
|
19
|
+
* module resolves from. Bun's own runtime is a signal in its own right.
|
|
20
|
+
*/
|
|
21
|
+
export declare function detectPackageManager(installPath: string, env?: NodeJS.ProcessEnv): PackageManager;
|
|
22
|
+
/** The argv that installs or upgrades a package globally, per manager. */
|
|
23
|
+
export declare function globalInstallArgs(manager: PackageManager, pkg?: string): string[];
|
|
24
|
+
/** The command a user can copy-paste when the automatic update can't run. */
|
|
25
|
+
export declare function globalInstallCommand(manager: PackageManager, pkg?: string): string;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Work out which package manager installed this CLI, so a self-update uses it.
|
|
3
|
+
*
|
|
4
|
+
* `vg init` and `vg update` both used to shell out to `npm install -g
|
|
5
|
+
* vibedgames` unconditionally. On a machine where the CLI came from pnpm, bun
|
|
6
|
+
* or yarn, that is wrong twice over: npm may not be installed at all, and if it
|
|
7
|
+
* is, it installs a *second* copy into a different global prefix — so the
|
|
8
|
+
* update silently lands somewhere the shell isn't looking and `vg --version`
|
|
9
|
+
* doesn't move.
|
|
10
|
+
*
|
|
11
|
+
* The install path is the evidence. Each manager puts globals somewhere
|
|
12
|
+
* recognisable, so the directory this file was loaded from names the manager
|
|
13
|
+
* that put it there.
|
|
14
|
+
*/
|
|
15
|
+
export const PKG_NAME = "vibedgames";
|
|
16
|
+
/**
|
|
17
|
+
* Global install directory fingerprints, most specific first.
|
|
18
|
+
*
|
|
19
|
+
* The npm entries come last because they are the loosest: `lib/node_modules`
|
|
20
|
+
* is npm's global prefix on unix and `npm\node_modules` is its Windows one,
|
|
21
|
+
* but neither is distinctive enough to check before the managers that have a
|
|
22
|
+
* directory named after them.
|
|
23
|
+
*/
|
|
24
|
+
const SIGNATURES = [
|
|
25
|
+
["bun", /[/\\]\.bun[/\\]/],
|
|
26
|
+
// pnpm's global store, not a project-local `node_modules/.pnpm`.
|
|
27
|
+
["pnpm", /[/\\](?:pnpm[/\\]global|\.pnpm-global|Library[/\\]pnpm)[/\\]/],
|
|
28
|
+
["yarn", /[/\\](?:\.yarn|yarn[/\\]global|\.config[/\\]yarn)[/\\]/],
|
|
29
|
+
["npm", /[/\\]lib[/\\]node_modules[/\\]/],
|
|
30
|
+
["npm", /[/\\]npm[/\\]node_modules[/\\]/],
|
|
31
|
+
];
|
|
32
|
+
/**
|
|
33
|
+
* `npm_config_user_agent` is set by whichever manager is running us — reliable
|
|
34
|
+
* when `vg` was invoked through a script (`pnpm vg …`), absent otherwise.
|
|
35
|
+
*/
|
|
36
|
+
function fromUserAgent(userAgent) {
|
|
37
|
+
if (!userAgent)
|
|
38
|
+
return null;
|
|
39
|
+
const name = userAgent.split("/")[0];
|
|
40
|
+
return name === "npm" || name === "pnpm" || name === "yarn" || name === "bun" ? name : null;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* `installPath` is where the CLI is installed — normally the directory this
|
|
44
|
+
* module resolves from. Bun's own runtime is a signal in its own right.
|
|
45
|
+
*/
|
|
46
|
+
export function detectPackageManager(installPath, env = process.env) {
|
|
47
|
+
for (const [manager, signature] of SIGNATURES) {
|
|
48
|
+
if (signature.test(installPath))
|
|
49
|
+
return manager;
|
|
50
|
+
}
|
|
51
|
+
// Bun reports itself in versions; running under it means `bun add` works.
|
|
52
|
+
if (typeof globalThis.Bun !== "undefined")
|
|
53
|
+
return "bun";
|
|
54
|
+
return fromUserAgent(env.npm_config_user_agent) ?? "npm";
|
|
55
|
+
}
|
|
56
|
+
/** The argv that installs or upgrades a package globally, per manager. */
|
|
57
|
+
export function globalInstallArgs(manager, pkg = PKG_NAME) {
|
|
58
|
+
switch (manager) {
|
|
59
|
+
case "pnpm":
|
|
60
|
+
return ["add", "-g", pkg];
|
|
61
|
+
case "yarn":
|
|
62
|
+
return ["global", "add", pkg];
|
|
63
|
+
case "bun":
|
|
64
|
+
return ["add", "-g", pkg];
|
|
65
|
+
case "npm":
|
|
66
|
+
return ["install", "-g", pkg];
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/** The command a user can copy-paste when the automatic update can't run. */
|
|
70
|
+
export function globalInstallCommand(manager, pkg = PKG_NAME) {
|
|
71
|
+
return `${manager} ${globalInstallArgs(manager, pkg).join(" ")}`;
|
|
72
|
+
}
|
package/dist/lib/run.d.ts
CHANGED
|
@@ -2,4 +2,18 @@ export type RunResult = {
|
|
|
2
2
|
code: number;
|
|
3
3
|
output: string;
|
|
4
4
|
};
|
|
5
|
-
export
|
|
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
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* True when the command never started, as opposed to running and failing.
|
|
15
|
+
* `run` turns a spawn error into an exit code, so the message is the only
|
|
16
|
+
* thing that separates "no such binary" from "the binary said no".
|
|
17
|
+
*/
|
|
18
|
+
export declare const isMissingCommand: (result: RunResult) => boolean;
|
|
19
|
+
export declare const run: (cmd: string, args: string[], options?: RunOptions) => Promise<RunResult>;
|
package/dist/lib/run.js
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
import spawn from "cross-spawn";
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* True when the command never started, as opposed to running and failing.
|
|
4
|
+
* `run` turns a spawn error into an exit code, so the message is the only
|
|
5
|
+
* thing that separates "no such binary" from "the binary said no".
|
|
6
|
+
*/
|
|
7
|
+
export const isMissingCommand = (result) => result.code !== 0 && /ENOENT|not found|not recognized/i.test(result.output);
|
|
8
|
+
export const run = (cmd, args, options = {}) => new Promise((resolve) => {
|
|
3
9
|
const chunks = [];
|
|
4
10
|
const child = spawn(cmd, args, { stdio: ["ignore", "pipe", "pipe"] });
|
|
5
|
-
|
|
6
|
-
|
|
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));
|
|
7
18
|
child.on("error", (err) => resolve({ code: 1, output: `${err.message}\n` }));
|
|
8
19
|
child.on("close", (code) => resolve({ code: code ?? 1, output: Buffer.concat(chunks).toString("utf8") }));
|
|
9
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 {};
|