vibedgames 0.6.3 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -9
- package/dist/THIRD_PARTY_NOTICES.txt +383 -0
- package/dist/chunk-2GL2WJZX.js +172 -0
- package/dist/chunk-2QBYTIMH.js +511 -0
- package/dist/chunk-34AHIMX7.js +466 -0
- package/dist/chunk-6FZPPUQH.js +107 -0
- package/dist/chunk-BVVYDSFJ.js +99 -0
- package/dist/chunk-CAKBGDCY.js +47 -0
- package/dist/chunk-CBKOPVU6.js +1780 -0
- package/dist/chunk-CU7UY5YJ.js +1108 -0
- package/dist/chunk-CZPKN32Z.js +257 -0
- package/dist/chunk-DHEXGWJY.js +111 -0
- package/dist/chunk-FL6IFBUF.js +22 -0
- package/dist/chunk-FLUXEHMU.js +1360 -0
- package/dist/chunk-FNYBZNW2.js +165 -0
- package/dist/chunk-G5FRIFA3.js +22 -0
- package/dist/chunk-HCMTSR7E.js +69 -0
- package/dist/chunk-HKA5LBYW.js +159 -0
- package/dist/chunk-I6O4HIDY.js +1063 -0
- package/dist/chunk-J6PKNPI2.js +26 -0
- package/dist/chunk-JT2AU24K.js +759 -0
- package/dist/chunk-MBXCVCC4.js +478 -0
- package/dist/chunk-MJQSHP3Y.js +415 -0
- package/dist/chunk-MYFLYNPO.js +68 -0
- package/dist/chunk-PEUP4MZR.js +59 -0
- package/dist/chunk-PHEDW6C7.js +32 -0
- package/dist/chunk-PQDBCZRT.js +2017 -0
- package/dist/chunk-QGEITHUP.js +395 -0
- package/dist/chunk-QIVCBUYD.js +273 -0
- package/dist/chunk-RYFO3ZPO.js +71 -0
- package/dist/chunk-RZ4DIJQW.js +68 -0
- package/dist/chunk-SAANBZ25.js +118 -0
- package/dist/chunk-VFFOT7KD.js +2980 -0
- package/dist/chunk-Y552BNFZ.js +41 -0
- package/dist/chunk-Z4Z24FWO.js +39 -0
- package/dist/chunk-ZI6PKVXG.js +64 -0
- package/dist/chunk-ZYCSYJWX.js +87 -0
- package/dist/index.js +67 -60
- package/package.json +13 -16
- package/templates/none/_gitignore +3 -0
- package/templates/none/index.html +29 -0
- package/templates/none/package.json +16 -0
- package/templates/none/src/main.ts +16 -0
- package/templates/none/tsconfig.json +18 -0
- package/templates/none/vite.config.ts +8 -0
- package/templates/phaser/_gitignore +3 -0
- package/templates/phaser/index.html +24 -0
- package/templates/phaser/package.json +19 -0
- package/templates/phaser/src/main.ts +16 -0
- package/templates/phaser/src/scenes/game-scene.ts +65 -0
- package/templates/phaser/tsconfig.json +18 -0
- package/templates/phaser/vite.config.ts +8 -0
- package/templates/react-r3f/_gitignore +3 -0
- package/templates/react-r3f/index.html +24 -0
- package/templates/react-r3f/package.json +27 -0
- package/templates/react-r3f/src/app.tsx +33 -0
- package/templates/react-r3f/src/main.tsx +15 -0
- package/templates/react-r3f/tsconfig.json +19 -0
- package/templates/react-r3f/vite.config.ts +10 -0
- package/templates/threejs/_gitignore +3 -0
- package/templates/threejs/index.html +36 -0
- package/templates/threejs/package.json +20 -0
- package/templates/threejs/src/main.ts +44 -0
- package/templates/threejs/tsconfig.json +18 -0
- package/templates/threejs/vite.config.ts +8 -0
- package/dist/commands/completions.d.ts +0 -7
- package/dist/commands/completions.js +0 -145
- package/dist/commands/credits.d.ts +0 -10
- package/dist/commands/credits.js +0 -136
- package/dist/commands/deploy.d.ts +0 -26
- package/dist/commands/deploy.js +0 -257
- package/dist/commands/factory.d.ts +0 -3
- package/dist/commands/factory.js +0 -73
- package/dist/commands/fork.d.ts +0 -29
- package/dist/commands/fork.js +0 -124
- package/dist/commands/generate.d.ts +0 -1
- package/dist/commands/generate.js +0 -565
- package/dist/commands/init.d.ts +0 -20
- package/dist/commands/init.js +0 -105
- package/dist/commands/login.d.ts +0 -1
- package/dist/commands/login.js +0 -45
- package/dist/commands/logout.d.ts +0 -1
- package/dist/commands/logout.js +0 -13
- package/dist/commands/new.d.ts +0 -26
- package/dist/commands/new.js +0 -318
- package/dist/commands/playtest-run.d.ts +0 -66
- package/dist/commands/playtest-run.js +0 -268
- package/dist/commands/playtest.d.ts +0 -76
- package/dist/commands/playtest.js +0 -372
- package/dist/commands/update.d.ts +0 -13
- package/dist/commands/update.js +0 -82
- package/dist/commands/whoami.d.ts +0 -10
- package/dist/commands/whoami.js +0 -44
- package/dist/index.d.ts +0 -2
- package/dist/lib/api.d.ts +0 -18
- package/dist/lib/api.js +0 -27
- package/dist/lib/archive.d.ts +0 -17
- package/dist/lib/archive.js +0 -228
- package/dist/lib/codex.d.ts +0 -117
- package/dist/lib/codex.js +0 -426
- package/dist/lib/config-file.d.ts +0 -16
- package/dist/lib/config-file.js +0 -54
- package/dist/lib/config.d.ts +0 -11
- package/dist/lib/config.js +0 -54
- package/dist/lib/manifest.d.ts +0 -10
- package/dist/lib/manifest.js +0 -91
- package/dist/lib/media-args.d.ts +0 -30
- package/dist/lib/media-args.js +0 -219
- package/dist/lib/media-download.d.ts +0 -37
- package/dist/lib/media-download.js +0 -268
- package/dist/lib/media-poll.d.ts +0 -18
- package/dist/lib/media-poll.js +0 -86
- package/dist/lib/media-upload.d.ts +0 -12
- package/dist/lib/media-upload.js +0 -52
- package/dist/lib/output.d.ts +0 -68
- package/dist/lib/output.js +0 -102
- package/dist/lib/package-manager.d.ts +0 -25
- package/dist/lib/package-manager.js +0 -77
- package/dist/lib/playtest/agent.d.ts +0 -192
- package/dist/lib/playtest/agent.js +0 -652
- package/dist/lib/playtest/browser.d.ts +0 -109
- package/dist/lib/playtest/browser.js +0 -219
- package/dist/lib/playtest/controls.d.ts +0 -47
- package/dist/lib/playtest/controls.js +0 -218
- package/dist/lib/playtest/errors.d.ts +0 -9
- package/dist/lib/playtest/errors.js +0 -12
- package/dist/lib/playtest/keys.d.ts +0 -41
- package/dist/lib/playtest/keys.js +0 -157
- package/dist/lib/playtest/run.d.ts +0 -195
- package/dist/lib/playtest/run.js +0 -409
- package/dist/lib/run.d.ts +0 -19
- package/dist/lib/run.js +0 -23
- package/dist/lib/strict-args.d.ts +0 -27
- package/dist/lib/strict-args.js +0 -78
- package/dist/lib/types.d.ts +0 -16
- package/dist/lib/types.js +0 -10
- package/dist/lib/update.d.ts +0 -10
- package/dist/lib/update.js +0 -110
- package/dist/lib/upload.d.ts +0 -16
- package/dist/lib/upload.js +0 -41
|
@@ -1,372 +0,0 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
|
-
import { existsSync, mkdirSync, statSync, writeFileSync } from "node:fs";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import { defineCommand } from "citty";
|
|
5
|
-
import { consola } from "consola";
|
|
6
|
-
import spawn from "cross-spawn";
|
|
7
|
-
import { getBaseUrl, getConfigDir } from "../lib/config.js";
|
|
8
|
-
import { isNewerVersion } from "../lib/update.js";
|
|
9
|
-
import { SLUG_RE, findProjectRoot, readProjectConfig } from "../lib/config-file.js";
|
|
10
|
-
/**
|
|
11
|
-
* `vg playtest` — drive a browser to actually play the game.
|
|
12
|
-
*
|
|
13
|
-
* This is a thin passthrough to agent-browser (a native browser-automation CLI
|
|
14
|
-
* built for agents), not a wrapper with its own vocabulary: every argument goes
|
|
15
|
-
* through untouched so the skill can teach upstream's command surface and we
|
|
16
|
-
* inherit its improvements for free. index.ts routes `vg playtest …` here
|
|
17
|
-
* BEFORE citty parses anything, so `--help`/`--version` reach the binary; the
|
|
18
|
-
* citty command below exists only so `vg --help` lists the subcommand.
|
|
19
|
-
*
|
|
20
|
-
* The one thing layered on top is `--game [slug]`, which resolves a deployed
|
|
21
|
-
* game's URL so an agent can playtest what it just shipped with no local setup.
|
|
22
|
-
*
|
|
23
|
-
* A minimum version is enforced: agent-browser is pre-1.0, so a minor bump can
|
|
24
|
-
* move the command surface out from under the playtest skill.
|
|
25
|
-
*/
|
|
26
|
-
const PKG = "agent-browser";
|
|
27
|
-
const MIN_VERSION = "0.34.0";
|
|
28
|
-
const PKG_SPEC = `${PKG}@^${MIN_VERSION}`;
|
|
29
|
-
/** Stands in for a version string we could not read. Always meets the floor. */
|
|
30
|
-
const UNKNOWN_VERSION = "unknown";
|
|
31
|
-
/** How long a failed upgrade suppresses the next attempt. */
|
|
32
|
-
const UPGRADE_RETRY_MS = 24 * 60 * 60_000;
|
|
33
|
-
/**
|
|
34
|
-
* Subcommands that take a URL. Used to decide whether a bare `--game` still
|
|
35
|
-
* needs an `open` in front of it, and — over `bareTokens` — to tell a misplaced
|
|
36
|
-
* `--game` from a well-formed one. An unknown verb still degrades to
|
|
37
|
-
* agent-browser's own error rather than to a wrong guess here.
|
|
38
|
-
*/
|
|
39
|
-
const URL_TAKING = new Set(["open", "goto", "navigate", "url"]);
|
|
40
|
-
/**
|
|
41
|
-
* Verbs this module recognizes, used only to tell a subcommand from a flag's
|
|
42
|
-
* value. `diff` is here because `diff url` is how two URLs are compared.
|
|
43
|
-
*/
|
|
44
|
-
const KNOWN_VERBS = new Set([...URL_TAKING, "diff"]);
|
|
45
|
-
/**
|
|
46
|
-
* The installed agent-browser's version, or null if the binary can't be run.
|
|
47
|
-
*
|
|
48
|
-
* Doubles as the "is it installed?" probe: a version we can read is proof the
|
|
49
|
-
* binary works, which a bare exit code isn't.
|
|
50
|
-
*/
|
|
51
|
-
const installedVersion = (bin) => {
|
|
52
|
-
// cross-spawn's sync sets `error` to null on success (node's spawnSync leaves
|
|
53
|
-
// it undefined), so test truthiness rather than comparing against undefined.
|
|
54
|
-
const res = spawn.sync(bin, ["--version"], { encoding: "utf-8", timeout: 30_000 });
|
|
55
|
-
if (res.status !== 0 || res.error) {
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
const match = /\d+\.\d+\.\d+/u.exec(res.stdout ?? "");
|
|
59
|
-
return match ? match[0] : UNKNOWN_VERSION;
|
|
60
|
-
};
|
|
61
|
-
/**
|
|
62
|
-
* Whether a version is new enough for the playtest skill.
|
|
63
|
-
*
|
|
64
|
-
* A floor, not an exact pin, so a newer agent-browser is left alone: someone
|
|
65
|
-
* running 0.35 installed it for a reason, and downgrading a shared global tool
|
|
66
|
-
* to match this skill would break their other work to fix a risk that may not
|
|
67
|
-
* exist. PKG_SPEC still caps what a *fresh* install pulls in.
|
|
68
|
-
*
|
|
69
|
-
* An unparseable version passes — `isNewerVersion` returns false for anything
|
|
70
|
-
* that isn't `x.y.z` — because a binary from brew or cargo may not report a
|
|
71
|
-
* semver at all, and blocking it would be worse than trusting it.
|
|
72
|
-
*/
|
|
73
|
-
const meetsMinimum = (version) => !isNewerVersion(MIN_VERSION, version);
|
|
74
|
-
/** The agent-browser binary to use. VG_AGENT_BROWSER_BIN overrides (dev). */
|
|
75
|
-
export const resolveBinary = () => {
|
|
76
|
-
const override = process.env.VG_AGENT_BROWSER_BIN;
|
|
77
|
-
// A dev-pointed binary is taken on trust — it is typically a local build with
|
|
78
|
-
// no npm version to read, and `meetsMinimum` waves an unparseable one through.
|
|
79
|
-
if (override) {
|
|
80
|
-
return existsSync(override) ? { bin: override, version: UNKNOWN_VERSION } : null;
|
|
81
|
-
}
|
|
82
|
-
const version = installedVersion(PKG);
|
|
83
|
-
return version === null ? null : { bin: PKG, version };
|
|
84
|
-
};
|
|
85
|
-
/** `npm install -g` the pinned spec, then re-resolve. Null if either step fails. */
|
|
86
|
-
const installGlobal = () => {
|
|
87
|
-
// Bounded so a wedged registry or install script can't hang `vg playtest`
|
|
88
|
-
// forever; generous enough not to cut off a slow but working download.
|
|
89
|
-
const res = spawn.sync("npm", ["install", "-g", PKG_SPEC], {
|
|
90
|
-
stdio: "inherit",
|
|
91
|
-
timeout: 10 * 60_000,
|
|
92
|
-
});
|
|
93
|
-
return res.status === 0 && !res.error ? resolveBinary() : null;
|
|
94
|
-
};
|
|
95
|
-
/**
|
|
96
|
-
* Install agent-browser globally, then provision its browser. Upstream ships
|
|
97
|
-
* these as two steps (`npm i -g` puts the Rust binary in place; `install`
|
|
98
|
-
* fetches Chrome for Testing and reuses an existing Chrome/Brave/Playwright
|
|
99
|
-
* install when it finds one), so a first run pays for both.
|
|
100
|
-
*/
|
|
101
|
-
export const bootstrap = () => {
|
|
102
|
-
consola.start(`Installing the playtest browser (${PKG})…`);
|
|
103
|
-
const resolved = installGlobal();
|
|
104
|
-
if (!resolved) {
|
|
105
|
-
consola.error(`Couldn't install ${PKG}, or it isn't on PATH afterwards. Try manually: npm install -g ${PKG_SPEC} — and check that npm's global bin directory is in your PATH (\`npm bin -g\`).`);
|
|
106
|
-
process.exit(1);
|
|
107
|
-
}
|
|
108
|
-
consola.start("Provisioning the browser (first run only)…");
|
|
109
|
-
const provision = spawn.sync(resolved.bin, ["install"], { stdio: "inherit" });
|
|
110
|
-
if (provision.status !== 0) {
|
|
111
|
-
consola.error(`\`${PKG} install\` failed. On Linux you may need system libraries: ${PKG} install --with-deps`);
|
|
112
|
-
process.exit(1);
|
|
113
|
-
}
|
|
114
|
-
consola.success("Playtest browser ready.");
|
|
115
|
-
return resolved;
|
|
116
|
-
};
|
|
117
|
-
/**
|
|
118
|
-
* Whether an upgrade was already tried recently. Time-boxed rather than
|
|
119
|
-
* permanent: the usual reason one fails is being offline, and a machine that is
|
|
120
|
-
* online tomorrow should get the upgrade rather than stay pinned by a stamp it
|
|
121
|
-
* wrote once.
|
|
122
|
-
*/
|
|
123
|
-
const recentlyFailed = (stamp) => {
|
|
124
|
-
try {
|
|
125
|
-
return Date.now() - statSync(stamp).mtimeMs < UPGRADE_RETRY_MS;
|
|
126
|
-
}
|
|
127
|
-
catch {
|
|
128
|
-
return false;
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
/**
|
|
132
|
-
* Bring an agent-browser older than the minimum up to it.
|
|
133
|
-
*
|
|
134
|
-
* The floor exists because agent-browser is pre-1.0: the playtest skill teaches
|
|
135
|
-
* a command surface, and the bot script depends on response shapes, both of
|
|
136
|
-
* which a minor bump can move. Installing the spec only on first use would
|
|
137
|
-
* leave an older global install — already on PATH from some earlier project —
|
|
138
|
-
* driving every run, which is how a documented contract silently stops holding.
|
|
139
|
-
*/
|
|
140
|
-
export const ensureMinimum = (resolved) => {
|
|
141
|
-
if (meetsMinimum(resolved.version)) {
|
|
142
|
-
return resolved;
|
|
143
|
-
}
|
|
144
|
-
// The bot script runs `vg playtest` once per step, so an upgrade that cannot
|
|
145
|
-
// stick — read-only npm prefix, offline, locked-down CI — would otherwise
|
|
146
|
-
// retry its npm round-trip on every one of them. Recorded per user rather
|
|
147
|
-
// than in a shared /tmp, where one account's stamp would silently suppress
|
|
148
|
-
// everyone else's upgrade.
|
|
149
|
-
const stamp = path.join(getConfigDir(), `${PKG}-upgrade-failed-${resolved.version}`);
|
|
150
|
-
if (recentlyFailed(stamp)) {
|
|
151
|
-
return resolved;
|
|
152
|
-
}
|
|
153
|
-
consola.warn(`Found ${PKG} ${resolved.version}, but the playtest skill needs at least ${MIN_VERSION}. Upgrading…`);
|
|
154
|
-
const upgraded = installGlobal();
|
|
155
|
-
if (!upgraded || !meetsMinimum(upgraded.version)) {
|
|
156
|
-
// Continue anyway: an older binary handles most commands fine, and failing
|
|
157
|
-
// outright would strand anyone who can't write to npm's global prefix.
|
|
158
|
-
try {
|
|
159
|
-
mkdirSync(getConfigDir(), { mode: 0o700, recursive: true });
|
|
160
|
-
writeFileSync(stamp, "");
|
|
161
|
-
}
|
|
162
|
-
catch {
|
|
163
|
-
// A stamp we cannot write only costs a retry next time.
|
|
164
|
-
}
|
|
165
|
-
consola.warn(`Couldn't upgrade ${PKG}. Continuing on ${resolved.version} — run \`npm install -g ${PKG_SPEC}\` if commands misbehave.`);
|
|
166
|
-
return resolved;
|
|
167
|
-
}
|
|
168
|
-
return upgraded;
|
|
169
|
-
};
|
|
170
|
-
/** The current project's slug, from the nearest vibedgames.json. */
|
|
171
|
-
const projectSlug = () => {
|
|
172
|
-
let config = null;
|
|
173
|
-
try {
|
|
174
|
-
config = readProjectConfig(process.cwd());
|
|
175
|
-
}
|
|
176
|
-
catch (error) {
|
|
177
|
-
consola.error(error instanceof Error ? error.message : String(error));
|
|
178
|
-
process.exit(1);
|
|
179
|
-
}
|
|
180
|
-
if (!config) {
|
|
181
|
-
consola.error("`--game` with no slug reads vibedgames.json, and none was found here. Pass a slug (`vg playtest --game my-game`) or run from a deployed project.");
|
|
182
|
-
process.exit(1);
|
|
183
|
-
}
|
|
184
|
-
return config.slug;
|
|
185
|
-
};
|
|
186
|
-
/**
|
|
187
|
-
* The URL a game is served at: a per-slug subdomain of whatever host this CLI
|
|
188
|
-
* is pointed at, so `VG_API_URL=…staging vg playtest --game x` playtests
|
|
189
|
-
* staging rather than silently hitting production the way a hardcoded apex
|
|
190
|
-
* would. Mirrors the derivation the deploy router does server-side.
|
|
191
|
-
*/
|
|
192
|
-
export const resolveGameUrl = (slug) => {
|
|
193
|
-
const resolved = slug ?? projectSlug();
|
|
194
|
-
// The slug lands in the host, so anything outside the deploy grammar could
|
|
195
|
-
// steer the browser off `*.vibedgames.com` entirely — `../`, an embedded
|
|
196
|
-
// `/`, or `evil.com#` would all re-point the origin.
|
|
197
|
-
if (!SLUG_RE.test(resolved)) {
|
|
198
|
-
consola.error(`Invalid game slug "${resolved}". Use lowercase letters, digits, and hyphens.`);
|
|
199
|
-
process.exit(1);
|
|
200
|
-
}
|
|
201
|
-
const base = new URL(getBaseUrl());
|
|
202
|
-
if (base.hostname === "localhost" || base.hostname === "127.0.0.1") {
|
|
203
|
-
consola.error(`\`--game\` resolves a deployed game's subdomain, which a local API URL (${base.host}) doesn't serve. Pass the game's URL directly instead.`);
|
|
204
|
-
process.exit(1);
|
|
205
|
-
}
|
|
206
|
-
return `${base.protocol}//${resolved}.${base.host}`;
|
|
207
|
-
};
|
|
208
|
-
/**
|
|
209
|
-
* The tokens in `args` that aren't flags or flag values — agent-browser's verb
|
|
210
|
-
* and its positional arguments, in order.
|
|
211
|
-
*
|
|
212
|
-
* A bare token is a flag's value if a flag sits immediately before it, and a
|
|
213
|
-
* verb otherwise — `--session p1 snapshot` has `p1` claimed by `--session`,
|
|
214
|
-
* leaving `snapshot`. `--session=p1` carries its own value and claims nothing.
|
|
215
|
-
* That holds for any single-valued flag, known or not, so no mirror of
|
|
216
|
-
* upstream's options can drift here.
|
|
217
|
-
*
|
|
218
|
-
* Deliberately incomplete: agent-browser's boolean flags take an OPTIONAL
|
|
219
|
-
* `true`/`false`, so `--headed snapshot` is genuinely ambiguous without knowing
|
|
220
|
-
* that `--headed` is boolean — and knowing that for ~50 options means mirroring
|
|
221
|
-
* a grammar that moves every release. This catches the shapes people actually
|
|
222
|
-
* type; anything past it reaches agent-browser as before.
|
|
223
|
-
*/
|
|
224
|
-
export const bareTokens = (args) => args.filter((arg, index) => {
|
|
225
|
-
if (arg.startsWith("-")) {
|
|
226
|
-
return false;
|
|
227
|
-
}
|
|
228
|
-
// A token that IS a known verb is one, whatever precedes it. "Preceded by a
|
|
229
|
-
// flag" can't tell a boolean flag from a valued one, so `--headed open`
|
|
230
|
-
// would otherwise read `open` as `--headed`'s value, see no verb at all,
|
|
231
|
-
// and insert a second one — agent-browser then navigates to the literal
|
|
232
|
-
// string "open" and lands on chrome-error://.
|
|
233
|
-
//
|
|
234
|
-
// The cost is a session or profile named exactly after a verb
|
|
235
|
-
// (`--session open`), which is now read as the verb. That is the rarer
|
|
236
|
-
// input by a wide margin, and it fails loudly instead of silently going
|
|
237
|
-
// somewhere wrong.
|
|
238
|
-
// `--game`'s own value is exempt: that flag is ours, so we know it takes a
|
|
239
|
-
// value, and a game may legitimately be called `open` or `diff`.
|
|
240
|
-
const previous = args[index - 1];
|
|
241
|
-
if (KNOWN_VERBS.has(arg) && previous !== "--game") {
|
|
242
|
-
return true;
|
|
243
|
-
}
|
|
244
|
-
return !(previous !== undefined && previous.startsWith("-") && !previous.includes("="));
|
|
245
|
-
});
|
|
246
|
-
export const expandGameFlag = (args, resolveUrl = resolveGameUrl) => {
|
|
247
|
-
if (!args.includes("--game")) {
|
|
248
|
-
return args;
|
|
249
|
-
}
|
|
250
|
-
// Catch `vg playtest snapshot --game x`, where the URL has nowhere to go —
|
|
251
|
-
// agent-browser silently runs the snapshot and ignores the stray URL, so
|
|
252
|
-
// leaving it to upstream costs a wrong answer rather than an error. Skipped
|
|
253
|
-
// when some verb here does take a URL, which is the well-formed case.
|
|
254
|
-
// Both questions — "is a URL-taking verb already here?" and "is some OTHER
|
|
255
|
-
// verb here?" — are read off the same list. Scanning the raw args for the
|
|
256
|
-
// first would also match a flag's value, so `--profile open --game x` would
|
|
257
|
-
// count the profile name as the verb and hand agent-browser a URL with no
|
|
258
|
-
// subcommand at all.
|
|
259
|
-
// Only the VERB decides whether a URL is wanted — `diff` reads its own on the
|
|
260
|
-
// next token. Asking whether ANY bare token is URL-taking lets a positional
|
|
261
|
-
// argument answer for the command: `click open --game x` would pass the guard
|
|
262
|
-
// on the selector named `open` and click the current page.
|
|
263
|
-
const bare = bareTokens(args);
|
|
264
|
-
const [verb] = bare;
|
|
265
|
-
const hasUrlVerb = verb !== undefined &&
|
|
266
|
-
(URL_TAKING.has(verb) || (verb === "diff" && bare[1] !== undefined && URL_TAKING.has(bare[1])));
|
|
267
|
-
// A verb that only appears AFTER the flag can't receive the URL: substituting
|
|
268
|
-
// in place would emit `<url> open`, whose first positional agent-browser
|
|
269
|
-
// reads as the subcommand. Say so rather than hand over a dead command.
|
|
270
|
-
const verbLeads = bareTokens(args.slice(0, args.indexOf("--game"))).some((token) => URL_TAKING.has(token));
|
|
271
|
-
if (hasUrlVerb && !verbLeads) {
|
|
272
|
-
consola.error("`--game` supplies the URL to a verb, so it has to come after one: `vg playtest open --game my-game`.");
|
|
273
|
-
process.exit(1);
|
|
274
|
-
}
|
|
275
|
-
const subcommand = hasUrlVerb ? null : (verb ?? null);
|
|
276
|
-
if (subcommand !== null) {
|
|
277
|
-
consola.error(`\`--game\` supplies a URL, so it only works with \`${[...URL_TAKING].join("`, `")}\` — not \`${subcommand}\`. Open the game first, then run \`vg playtest ${subcommand} …\` against it.`);
|
|
278
|
-
process.exit(1);
|
|
279
|
-
}
|
|
280
|
-
const out = [];
|
|
281
|
-
// `entries()` types each element as string, so no assertion is needed to
|
|
282
|
-
// index the array; `consumed` skips a slug already claimed by its flag.
|
|
283
|
-
let consumed = false;
|
|
284
|
-
let opened = false;
|
|
285
|
-
for (const [index, arg] of args.entries()) {
|
|
286
|
-
if (consumed) {
|
|
287
|
-
consumed = false;
|
|
288
|
-
continue;
|
|
289
|
-
}
|
|
290
|
-
if (arg !== "--game") {
|
|
291
|
-
out.push(arg);
|
|
292
|
-
continue;
|
|
293
|
-
}
|
|
294
|
-
const next = args[index + 1];
|
|
295
|
-
const slug = next !== undefined && !next.startsWith("-") ? next : null;
|
|
296
|
-
consumed = slug !== null;
|
|
297
|
-
// Decided from the whole array rather than from what came before the flag,
|
|
298
|
-
// so `--game x open` substitutes in place instead of emitting a second
|
|
299
|
-
// `open`. Once per expansion, so repeating `--game` yields one verb and
|
|
300
|
-
// several URLs — the shape `diff url` wants.
|
|
301
|
-
if (!hasUrlVerb && !opened) {
|
|
302
|
-
out.push("open");
|
|
303
|
-
opened = true;
|
|
304
|
-
}
|
|
305
|
-
out.push(resolveUrl(slug));
|
|
306
|
-
}
|
|
307
|
-
return out;
|
|
308
|
-
};
|
|
309
|
-
/**
|
|
310
|
-
* agent-browser's session defaults to the literal name `default`, which is
|
|
311
|
-
* shared by every caller on the machine. Two `vg playtest` runs — two projects
|
|
312
|
-
* in two terminals, or two agents on one box — then drive the SAME browser tab:
|
|
313
|
-
* one navigates away mid-run and the other screenshots its page. Scope the
|
|
314
|
-
* session to the project so concurrent playtests can't collide.
|
|
315
|
-
*
|
|
316
|
-
* Left alone when the caller already chose a session, or set one in the
|
|
317
|
-
* environment, or is asking about sessions themselves (`session list` must see
|
|
318
|
-
* every session, not just this project's).
|
|
319
|
-
*/
|
|
320
|
-
export const withScopedSession = (args, sessionId) => {
|
|
321
|
-
if (args.includes("--session") || args.some((a) => a.startsWith("--session="))) {
|
|
322
|
-
return args;
|
|
323
|
-
}
|
|
324
|
-
if (process.env.AGENT_BROWSER_SESSION) {
|
|
325
|
-
return args;
|
|
326
|
-
}
|
|
327
|
-
const [verb] = bareTokens(args);
|
|
328
|
-
// No verb means `--help`/`--version`, and `install`/`session` are machine-wide
|
|
329
|
-
// — `session list` has to see every session, not just this project's.
|
|
330
|
-
if (verb === undefined || verb === "session" || verb === "install") {
|
|
331
|
-
return args;
|
|
332
|
-
}
|
|
333
|
-
return ["--session", sessionId(), ...args];
|
|
334
|
-
};
|
|
335
|
-
/**
|
|
336
|
-
* A stable per-project session name. Keyed on the project root when there is
|
|
337
|
-
* one so every command run from anywhere inside the project shares a browser,
|
|
338
|
-
* and on the cwd otherwise. Hashed because the name lands in a socket path.
|
|
339
|
-
*/
|
|
340
|
-
export const projectSessionId = () => {
|
|
341
|
-
const root = findProjectRoot(process.cwd()) ?? process.cwd();
|
|
342
|
-
const digest = createHash("sha256").update(root).digest("hex").slice(0, 12);
|
|
343
|
-
return `vg-${digest}`;
|
|
344
|
-
};
|
|
345
|
-
/**
|
|
346
|
-
* The agent-browser to drive: installed on first use, upgraded to the floor
|
|
347
|
-
* when older. Bootstrap covers `install` too: on a fresh machine that's the
|
|
348
|
-
* most natural first command, and re-running the provision step it just did
|
|
349
|
-
* is harmless.
|
|
350
|
-
*/
|
|
351
|
-
export const ensureAgentBrowser = () => {
|
|
352
|
-
const resolved = resolveBinary();
|
|
353
|
-
return resolved ? ensureMinimum(resolved) : bootstrap();
|
|
354
|
-
};
|
|
355
|
-
/** Resolve (installing on first use) and exec agent-browser. Never returns. */
|
|
356
|
-
export const runPlaytest = (rawArgs) => {
|
|
357
|
-
const args = withScopedSession(expandGameFlag(rawArgs), projectSessionId);
|
|
358
|
-
const { bin } = ensureAgentBrowser();
|
|
359
|
-
const result = spawn.sync(bin, args, { stdio: "inherit" });
|
|
360
|
-
process.exit(result.status ?? 1);
|
|
361
|
-
};
|
|
362
|
-
export const playtestCommand = defineCommand({
|
|
363
|
-
meta: {
|
|
364
|
-
description: "Drive a real browser to play a game — snapshot, click, hold keys, read state, screenshot, diff (installs the browser on first use). All arguments pass through: `vg playtest open <url>`, `vg playtest --game <slug>` to open a deployed game, `vg playtest --help` for the full command surface. `vg playtest run` is the exception: a model plays the game and reports (`vg playtest run --help`).",
|
|
365
|
-
name: "playtest",
|
|
366
|
-
},
|
|
367
|
-
run: ({ rawArgs }) => {
|
|
368
|
-
// Normally unreachable (index.ts routes `vg playtest` before citty), but
|
|
369
|
-
// keeps the command functional if invoked programmatically.
|
|
370
|
-
runPlaytest(rawArgs);
|
|
371
|
-
},
|
|
372
|
-
});
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export declare const updateCommand: import("citty").CommandDef<{
|
|
2
|
-
readonly auto: {
|
|
3
|
-
readonly default: false;
|
|
4
|
-
readonly description: "(internal) silent background mode: only update when the registry has a newer version";
|
|
5
|
-
readonly type: "boolean";
|
|
6
|
-
};
|
|
7
|
-
readonly global: {
|
|
8
|
-
readonly alias: "g";
|
|
9
|
-
readonly default: false;
|
|
10
|
-
readonly description: "Update skills installed in the user directory instead of the project";
|
|
11
|
-
readonly type: "boolean";
|
|
12
|
-
};
|
|
13
|
-
}>;
|
package/dist/commands/update.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from "node:fs";
|
|
2
|
-
import { defineCommand } from "citty";
|
|
3
|
-
import { consola } from "consola";
|
|
4
|
-
import { detectPackageManager, globalInstallArgs, globalInstallCommand, } from "../lib/package-manager.js";
|
|
5
|
-
import { isMissingCommand, run } from "../lib/run.js";
|
|
6
|
-
import { assertKnownFlags } from "../lib/strict-args.js";
|
|
7
|
-
import { fetchLatestVersion, isNewerVersion } from "../lib/update.js";
|
|
8
|
-
// SAFETY: this is the CLI's own package.json, shipped alongside dist — npm
|
|
9
|
-
// refuses to publish a package without a string `version`.
|
|
10
|
-
const pkg = JSON.parse(readFileSync(new URL("../../package.json", import.meta.url), "utf-8"));
|
|
11
|
-
const skillsUpdateArgs = (global) => {
|
|
12
|
-
const args = ["-y", "skills", "update", "-y"];
|
|
13
|
-
if (global) {
|
|
14
|
-
args.push("-g");
|
|
15
|
-
}
|
|
16
|
-
return args;
|
|
17
|
-
};
|
|
18
|
-
const updateArgs = {
|
|
19
|
-
auto: {
|
|
20
|
-
default: false,
|
|
21
|
-
description: "(internal) silent background mode: only update when the registry has a newer version",
|
|
22
|
-
type: "boolean",
|
|
23
|
-
},
|
|
24
|
-
global: {
|
|
25
|
-
alias: "g",
|
|
26
|
-
default: false,
|
|
27
|
-
description: "Update skills installed in the user directory instead of the project",
|
|
28
|
-
type: "boolean",
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
export const updateCommand = defineCommand({
|
|
32
|
-
args: updateArgs,
|
|
33
|
-
meta: {
|
|
34
|
-
description: "Update the vg CLI and vibedgames skills to latest (runs automatically once a day; disable with VG_NO_AUTO_UPDATE=1)",
|
|
35
|
-
name: "update",
|
|
36
|
-
},
|
|
37
|
-
run: async ({ args, rawArgs }) => {
|
|
38
|
-
assertKnownFlags(rawArgs, updateArgs);
|
|
39
|
-
// Upgrade with whatever installed this CLI: another manager would write a
|
|
40
|
-
// second copy into a different global prefix, leaving the one on PATH stale.
|
|
41
|
-
const manager = detectPackageManager(import.meta.filename);
|
|
42
|
-
if (args.auto) {
|
|
43
|
-
const latest = await fetchLatestVersion();
|
|
44
|
-
if (!latest || !isNewerVersion(latest, pkg.version)) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
await Promise.all([
|
|
48
|
-
run(manager, globalInstallArgs(manager)),
|
|
49
|
-
run("npx", skillsUpdateArgs(args.global)),
|
|
50
|
-
]);
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
consola.start("Updating the vg CLI and vibedgames skills...");
|
|
54
|
-
const [cli, skills] = await Promise.all([
|
|
55
|
-
run(manager, globalInstallArgs(manager)),
|
|
56
|
-
run("npx", skillsUpdateArgs(args.global)),
|
|
57
|
-
]);
|
|
58
|
-
if (cli.code === 0) {
|
|
59
|
-
consola.success(`vg CLI updated to latest with ${manager}`);
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
if (cli.output.trim() && !isMissingCommand(cli)) {
|
|
63
|
-
consola.warn(cli.output.trim());
|
|
64
|
-
}
|
|
65
|
-
consola.warn(isMissingCommand(cli)
|
|
66
|
-
? `Couldn't find ${manager} to update the vg CLI. Update manually: ${globalInstallCommand(manager)}`
|
|
67
|
-
: `Couldn't update the vg CLI (${manager} exit ${cli.code}). Update manually: ${globalInstallCommand(manager)}`);
|
|
68
|
-
}
|
|
69
|
-
if (skills.code === 0) {
|
|
70
|
-
consola.success("Skills updated to latest");
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
if (skills.output.trim()) {
|
|
74
|
-
consola.warn(skills.output.trim());
|
|
75
|
-
}
|
|
76
|
-
consola.warn(`'skills update' exited with code ${skills.code}. If skills aren't installed here yet, run: vg init`);
|
|
77
|
-
}
|
|
78
|
-
if (cli.code !== 0 && skills.code !== 0) {
|
|
79
|
-
throw new Error("update failed for both the CLI and skills");
|
|
80
|
-
}
|
|
81
|
-
},
|
|
82
|
-
});
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export declare const whoamiCommand: import("citty").CommandDef<{
|
|
2
|
-
readonly field: {
|
|
3
|
-
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.";
|
|
4
|
-
readonly type: "string";
|
|
5
|
-
};
|
|
6
|
-
readonly json: {
|
|
7
|
-
readonly description: "Print structured JSON to stdout.";
|
|
8
|
-
readonly type: "boolean";
|
|
9
|
-
};
|
|
10
|
-
}>;
|
package/dist/commands/whoami.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { defineCommand } from "citty";
|
|
2
|
-
import { consola } from "consola";
|
|
3
|
-
import { authErrorCode, createClient } from "../lib/api.js";
|
|
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 };
|
|
8
|
-
export const whoamiCommand = defineCommand({
|
|
9
|
-
args: whoamiArgs,
|
|
10
|
-
meta: {
|
|
11
|
-
description: "Show the currently authenticated user",
|
|
12
|
-
name: "whoami",
|
|
13
|
-
},
|
|
14
|
-
run: async ({ args, rawArgs }) => {
|
|
15
|
-
assertKnownFlags(rawArgs, whoamiArgs);
|
|
16
|
-
const token = getToken();
|
|
17
|
-
if (!token) {
|
|
18
|
-
consola.warn("Not logged in. Run `vg login` to authenticate.");
|
|
19
|
-
process.exit(1);
|
|
20
|
-
}
|
|
21
|
-
// Goes through the API (not the raw better-auth endpoint) so it resolves
|
|
22
|
-
// both session tokens and `vg_…` API keys.
|
|
23
|
-
const client = createClient();
|
|
24
|
-
try {
|
|
25
|
-
const user = await client.auth.me();
|
|
26
|
-
if (writeStructured({ email: user.email, id: user.id, name: user.name }, args)) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
consola.log(`${user.name} (${user.email})`);
|
|
30
|
-
}
|
|
31
|
-
catch (error) {
|
|
32
|
-
// Only an auth error means "log in"; surface network/server failures as
|
|
33
|
-
// themselves so they aren't mistaken for a bad credential.
|
|
34
|
-
const code = authErrorCode(error);
|
|
35
|
-
if (code === "UNAUTHORIZED" || code === "FORBIDDEN") {
|
|
36
|
-
consola.warn("Not authenticated. Run `vg login`, or check your VG_TOKEN / API key.");
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
consola.error(`Failed to fetch current user: ${error instanceof Error ? error.message : String(error)}`);
|
|
40
|
-
}
|
|
41
|
-
process.exit(1);
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
});
|
package/dist/index.d.ts
DELETED
package/dist/lib/api.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { AppRouter, RouterInputs } from "@repo/api";
|
|
2
|
-
import type { RouterClient } from "@orpc/server";
|
|
3
|
-
import type { JsonValue } from "./types.js";
|
|
4
|
-
/** Authenticated client — requires a saved session token. */
|
|
5
|
-
export declare const createClient: () => RouterClient<AppRouter>;
|
|
6
|
-
/** The oRPC error code on a failed call, or null for non-oRPC failures. */
|
|
7
|
-
export declare const authErrorCode: (cause: unknown) => string | null;
|
|
8
|
-
type ForwardInput = RouterInputs["generate"]["forward"];
|
|
9
|
-
/**
|
|
10
|
-
* The single boundary where fal payloads enter the CLI. `generate.forward` is
|
|
11
|
-
* deliberately untyped per endpoint — it resolves to bare `JsonValue` — so
|
|
12
|
-
* everything downstream narrows with the guards in `types.ts` rather than
|
|
13
|
-
* asserting a shape at the call site.
|
|
14
|
-
*/
|
|
15
|
-
export declare const forwardJson: (client: RouterClient<AppRouter>, input: ForwardInput) => Promise<JsonValue>;
|
|
16
|
-
/** Unauthenticated client — for login flow. */
|
|
17
|
-
export declare const createPublicClient: (baseUrl: string) => RouterClient<AppRouter>;
|
|
18
|
-
export {};
|
package/dist/lib/api.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { createORPCClient, ORPCError } from "@orpc/client";
|
|
2
|
-
import { RPCLink } from "@orpc/client/fetch";
|
|
3
|
-
import { getBaseUrl, getToken } from "./config.js";
|
|
4
|
-
const makeClient = (baseUrl, token) => createORPCClient(new RPCLink({
|
|
5
|
-
headers: () => (token ? { Authorization: `Bearer ${token}` } : {}),
|
|
6
|
-
origin: baseUrl,
|
|
7
|
-
url: "/api/orpc",
|
|
8
|
-
}));
|
|
9
|
-
/** Authenticated client — requires a saved session token. */
|
|
10
|
-
export const createClient = () => {
|
|
11
|
-
const token = getToken();
|
|
12
|
-
if (!token) {
|
|
13
|
-
throw new Error("Not logged in. Run `vg login` to authenticate.");
|
|
14
|
-
}
|
|
15
|
-
return makeClient(getBaseUrl(), token);
|
|
16
|
-
};
|
|
17
|
-
/** The oRPC error code on a failed call, or null for non-oRPC failures. */
|
|
18
|
-
export const authErrorCode = (cause) => cause instanceof ORPCError ? cause.code : null;
|
|
19
|
-
/**
|
|
20
|
-
* The single boundary where fal payloads enter the CLI. `generate.forward` is
|
|
21
|
-
* deliberately untyped per endpoint — it resolves to bare `JsonValue` — so
|
|
22
|
-
* everything downstream narrows with the guards in `types.ts` rather than
|
|
23
|
-
* asserting a shape at the call site.
|
|
24
|
-
*/
|
|
25
|
-
export const forwardJson = async (client, input) => await client.generate.forward(input);
|
|
26
|
-
/** Unauthenticated client — for login flow. */
|
|
27
|
-
export const createPublicClient = (baseUrl) => makeClient(baseUrl);
|
package/dist/lib/archive.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export interface SourceArchive {
|
|
2
|
-
/** absolute path to the temp .tgz */
|
|
3
|
-
path: string;
|
|
4
|
-
sha256: string;
|
|
5
|
-
bytes: number;
|
|
6
|
-
/** posix relative paths included, for display */
|
|
7
|
-
files: string[];
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Create a gzipped tar of `root`'s source (respecting .gitignore +
|
|
11
|
-
* HARD_EXCLUDES) at a temp path. Returns the archive path, its sha256, byte
|
|
12
|
-
* size, and the list of included files.
|
|
13
|
-
*/
|
|
14
|
-
export declare const packSource: (root: string, tmpDir: string) => Promise<SourceArchive>;
|
|
15
|
-
/** Extract a gzipped tar into `destDir` (created if needed). tar strips
|
|
16
|
-
* leading slashes and rejects `..` paths, so extraction stays inside dest. */
|
|
17
|
-
export declare const extractSource: (archivePath: string, destDir: string) => Promise<void>;
|