@bitmagic/cli 0.1.46-dev.2 → 0.1.46-dev.4
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 +46 -0
- package/dist/auth/session.js +1 -1
- package/dist/auth/session.js.map +1 -1
- package/dist/auth/subscribe-flow.d.ts +30 -6
- package/dist/auth/subscribe-flow.js +64 -29
- package/dist/auth/subscribe-flow.js.map +1 -1
- package/dist/bin.js +6 -2
- package/dist/bin.js.map +1 -1
- package/dist/cli.d.ts +43 -2
- package/dist/cli.js +78 -7
- package/dist/cli.js.map +1 -1
- package/dist/commands/dev.js +9 -0
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/forge.js +1 -1
- package/dist/commands/forge.js.map +1 -1
- package/dist/commands/generate.js +9 -1
- package/dist/commands/generate.js.map +1 -1
- package/dist/commands/init.js +6 -0
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/login.js +15 -11
- package/dist/commands/login.js.map +1 -1
- package/dist/commands/reset-account.d.ts +103 -0
- package/dist/commands/reset-account.js +227 -0
- package/dist/commands/reset-account.js.map +1 -0
- package/dist/commands/subscribe.d.ts +13 -1
- package/dist/commands/subscribe.js +21 -17
- package/dist/commands/subscribe.js.map +1 -1
- package/dist/commands/upgrade.d.ts +2 -1
- package/dist/commands/upgrade.js +12 -5
- package/dist/commands/upgrade.js.map +1 -1
- package/dist/config/environments.d.ts +14 -0
- package/dist/config/environments.js +22 -0
- package/dist/config/environments.js.map +1 -1
- package/dist/errors.d.ts +10 -1
- package/dist/errors.js +11 -1
- package/dist/errors.js.map +1 -1
- package/dist/forge/run-pipeline.js +1 -1
- package/dist/forge/run-pipeline.js.map +1 -1
- package/dist/forge/stream.js +10 -5
- package/dist/forge/stream.js.map +1 -1
- package/dist/forge/upload-proxy.js +2 -0
- package/dist/forge/upload-proxy.js.map +1 -1
- package/dist/generate/stream.js +10 -5
- package/dist/generate/stream.js.map +1 -1
- package/dist/http/client.d.ts +6 -2
- package/dist/http/client.js +22 -12
- package/dist/http/client.js.map +1 -1
- package/dist/http/spark-refusal.d.ts +11 -0
- package/dist/http/spark-refusal.js +13 -0
- package/dist/http/spark-refusal.js.map +1 -1
- package/dist/publish/client.js +3 -1
- package/dist/publish/client.js.map +1 -1
- package/dist/scaffold/agents-md.d.ts +2 -1
- package/dist/scaffold/agents-md.js +7 -2
- package/dist/scaffold/agents-md.js.map +1 -1
- package/dist/scaffold/engine-download.js +5 -18
- package/dist/scaffold/engine-download.js.map +1 -1
- package/dist/scaffold/project-files.d.ts +3 -2
- package/dist/scaffold/project-files.js +46 -2
- package/dist/scaffold/project-files.js.map +1 -1
- package/dist/scaffold/project.d.ts +30 -0
- package/dist/scaffold/project.js +55 -29
- package/dist/scaffold/project.js.map +1 -1
- package/dist/scaffold/upgrade-project.js +19 -33
- package/dist/scaffold/upgrade-project.js.map +1 -1
- package/dist/telemetry/command-context.d.ts +73 -0
- package/dist/telemetry/command-context.js +114 -0
- package/dist/telemetry/command-context.js.map +1 -0
- package/dist/telemetry/report.d.ts +43 -0
- package/dist/telemetry/report.js +123 -0
- package/dist/telemetry/report.js.map +1 -0
- package/dist/telemetry/request-headers.d.ts +14 -0
- package/dist/telemetry/request-headers.js +48 -0
- package/dist/telemetry/request-headers.js.map +1 -0
- package/dist/update/check.d.ts +14 -0
- package/dist/update/check.js +17 -1
- package/dist/update/check.js.map +1 -1
- package/dist/update/notice.d.ts +40 -0
- package/dist/update/notice.js +53 -0
- package/dist/update/notice.js.map +1 -1
- package/package.json +4 -4
|
@@ -106,8 +106,9 @@ const THREE_SHIM = [
|
|
|
106
106
|
`export{ShaderLib}from'https://esm.sh/three@${THREE_VERSION}/src/renderers/shaders/ShaderLib.js';`,
|
|
107
107
|
`export{UniformsLib}from'https://esm.sh/three@${THREE_VERSION}/src/renderers/shaders/UniformsLib.js'`,
|
|
108
108
|
].join('');
|
|
109
|
-
/** Resolved in the browser from a CDN, not from node_modules — see the design's import-map note. */
|
|
110
109
|
/**
|
|
110
|
+
* Resolved in the browser from a CDN, not from node_modules — see the design's import-map note.
|
|
111
|
+
*
|
|
111
112
|
* Exported so the dev view's asset-preview page builds its map from this one definition rather
|
|
112
113
|
* than a sixth hand-typed copy. See `editor/asset-preview-page.ts`.
|
|
113
114
|
*/
|
|
@@ -374,7 +375,48 @@ export function renderGitignore() {
|
|
|
374
375
|
export function renderBitmagicJson(metadata) {
|
|
375
376
|
return renderJson(metadata);
|
|
376
377
|
}
|
|
377
|
-
|
|
378
|
+
/**
|
|
379
|
+
* The "Updating the bitmagic CLI" section, which exists because the answer is written down and was
|
|
380
|
+
* still being asked.
|
|
381
|
+
*
|
|
382
|
+
* An agent told to update the CLI in a project directory has two published lines to choose from and,
|
|
383
|
+
* before this, nothing in the project that named one — so it asked the creator "dev or prod?", which
|
|
384
|
+
* is a question the project already answers. The pin decides it (see `updateTagForEnvironment`), so
|
|
385
|
+
* the section states the command outright rather than describing how to work it out.
|
|
386
|
+
*
|
|
387
|
+
* The rule is spelled out under the command anyway, for the one case the baked value can be wrong:
|
|
388
|
+
* this file is written at scaffold time and refreshed by `bitmagic upgrade`, so a creator who edits
|
|
389
|
+
* `environment` in between has a project whose pin has moved and whose AGENTS.md has not.
|
|
390
|
+
*
|
|
391
|
+
* `environment` is undefined for a project scaffolded before the pin existed. That project has no
|
|
392
|
+
* answer to bake, so the section gives it the rule and the command that produces the pin instead of
|
|
393
|
+
* guessing a line on its behalf.
|
|
394
|
+
*/
|
|
395
|
+
function renderCliUpdateSection(environment) {
|
|
396
|
+
const install = environment === 'prod' ? 'npm i -g @bitmagic/cli' : 'npm i -g @bitmagic/cli@dev';
|
|
397
|
+
const here = environment === undefined
|
|
398
|
+
? `This project predates the \`environment\` field of \`bitmagic.json\` and so has no pin yet.
|
|
399
|
+
Run \`bitmagic upgrade\` once to stamp one; \`bitmagic whoami\` prints what the CLI resolves in the
|
|
400
|
+
meantime, and that environment decides the line by the rule below.`
|
|
401
|
+
: `This project is on the **${environment}** environment (\`environment\` in
|
|
402
|
+
\`bitmagic.json\`), so exactly one command updates the CLI here:
|
|
403
|
+
|
|
404
|
+
\`\`\`
|
|
405
|
+
${install}
|
|
406
|
+
\`\`\``;
|
|
407
|
+
return `## Updating the bitmagic CLI
|
|
408
|
+
|
|
409
|
+
${here}
|
|
410
|
+
|
|
411
|
+
**Never ask which line to install, and never offer the choice** — the environment decides it.
|
|
412
|
+
\`dev\` and \`local\` projects take \`npm i -g @bitmagic/cli@dev\`, the prerelease line developed
|
|
413
|
+
against the dev api-server; \`prod\` projects take the plain \`npm i -g @bitmagic/cli\`. They are not
|
|
414
|
+
interchangeable — the wrong one calls endpoints that do not exist yet, or lags the engine its
|
|
415
|
+
environment serves, and both fail as opaque command errors rather than version warnings. Run the
|
|
416
|
+
wrong one here and every command opens with a notice saying so. If \`bitmagic.json\` ever disagrees
|
|
417
|
+
with this paragraph, the file is right. The engine is a separate command: \`bitmagic upgrade\`.`;
|
|
418
|
+
}
|
|
419
|
+
export function renderAgentsMd(environment) {
|
|
378
420
|
return `# Working on this Bitmagic game
|
|
379
421
|
|
|
380
422
|
## Start \`bitmagic dev\` before you build anything
|
|
@@ -788,6 +830,8 @@ Five things worth knowing:
|
|
|
788
830
|
Afterwards actually walk the level in the dev view — one that loads is not necessarily one you can
|
|
789
831
|
move through. (You should already have \`bitmagic dev\` running; a forge takes twenty minutes, and
|
|
790
832
|
its progress shows there.)
|
|
833
|
+
|
|
834
|
+
${renderCliUpdateSection(environment)}
|
|
791
835
|
`;
|
|
792
836
|
}
|
|
793
837
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project-files.js","sourceRoot":"","sources":["../../src/scaffold/project-files.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAE/D,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAKjF;;;;;;;;;;;;;;;;GAgBG;AACH,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;;;;;;;;;;;;;CAc3E,CAAC;AACF,CAAC;AAED,MAAM,UAAU,cAAc;IAC5B,OAAO,cAAc,CAAC;AACxB,CAAC;AAED,MAAM,UAAU,kBAAkB;IAChC,OAAO;;;;;;;;;;;;;;;;;;;;;;CAsBR,CAAC;AACF,CAAC"}
|
|
@@ -68,6 +68,36 @@ export declare const OPTIONAL_VENDORED_DIRS: string[];
|
|
|
68
68
|
* there as soon as the project moves to a version that ships it. See docs/engine-license.md.
|
|
69
69
|
*/
|
|
70
70
|
export declare const OPTIONAL_VENDORED_FILES: string[];
|
|
71
|
+
/**
|
|
72
|
+
* Copies every OPTIONAL_VENDORED_DIRS / OPTIONAL_VENDORED_FILES entry the extracted tree happens
|
|
73
|
+
* to carry into the project's `engine/`, and silently skips the ones it does not.
|
|
74
|
+
*
|
|
75
|
+
* `scaffoldProject` and `upgradeProject` share this so the "missing is not a corrupt tarball"
|
|
76
|
+
* allowance — and the nightly-tarball-vs-npm-release window that forces it, documented on the two
|
|
77
|
+
* constants above — is implemented once rather than twice. `cpSync`'s `recursive` flag is
|
|
78
|
+
* meaningless for a single file, so directories and files need no separate passes.
|
|
79
|
+
*/
|
|
80
|
+
export declare function copyOptionalEngineEntries(extractedEngineDir: string, engineDir: string): void;
|
|
81
|
+
/**
|
|
82
|
+
* Copies the engine's service worker to the project ROOT when the tarball carries one, and reports
|
|
83
|
+
* whether it did.
|
|
84
|
+
*
|
|
85
|
+
* AutoCacheBuster.ts registers it at the absolute path /sw-cache-buster.js, so it cannot be
|
|
86
|
+
* vendored under `engine/` — a service worker cannot control scopes above its own path. Absence is
|
|
87
|
+
* the same "not a corrupt tarball" allowance as `copyOptionalEngineEntries`: every tarball
|
|
88
|
+
* published before this feature shipped lacks it, and init and upgrade must both keep working
|
|
89
|
+
* against those.
|
|
90
|
+
*/
|
|
91
|
+
export declare function copyServiceWorker(extractedEngineDir: string, root: string): boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Writes one file into a project, creating its parent directories first.
|
|
94
|
+
*
|
|
95
|
+
* The mkdir is load-bearing for the nested entries — `.claude/skills/<name>/SKILL.md` — in a
|
|
96
|
+
* project that predates them: without it `writeFileSync` ENOENTs, and in `upgradeProject` it does
|
|
97
|
+
* so AFTER `engine/` has been replaced, leaving the project half-upgraded. mkdir on an existing
|
|
98
|
+
* directory is a no-op, so the top-level entries pay nothing for it.
|
|
99
|
+
*/
|
|
100
|
+
export declare function writeProjectFile(root: string, relativePath: string, contents: string): void;
|
|
71
101
|
/**
|
|
72
102
|
* The subset of the generated files that are pure platform output: regenerated byte-for-byte
|
|
73
103
|
* from these renderers with no creator content ever entering them. `bitmagic upgrade` overwrites
|
package/dist/scaffold/project.js
CHANGED
|
@@ -75,6 +75,53 @@ export const OPTIONAL_VENDORED_DIRS = ['agent-docs'];
|
|
|
75
75
|
* there as soon as the project moves to a version that ships it. See docs/engine-license.md.
|
|
76
76
|
*/
|
|
77
77
|
export const OPTIONAL_VENDORED_FILES = ['LICENSE.md', 'THIRD-PARTY-NOTICES.md'];
|
|
78
|
+
/**
|
|
79
|
+
* Copies every OPTIONAL_VENDORED_DIRS / OPTIONAL_VENDORED_FILES entry the extracted tree happens
|
|
80
|
+
* to carry into the project's `engine/`, and silently skips the ones it does not.
|
|
81
|
+
*
|
|
82
|
+
* `scaffoldProject` and `upgradeProject` share this so the "missing is not a corrupt tarball"
|
|
83
|
+
* allowance — and the nightly-tarball-vs-npm-release window that forces it, documented on the two
|
|
84
|
+
* constants above — is implemented once rather than twice. `cpSync`'s `recursive` flag is
|
|
85
|
+
* meaningless for a single file, so directories and files need no separate passes.
|
|
86
|
+
*/
|
|
87
|
+
export function copyOptionalEngineEntries(extractedEngineDir, engineDir) {
|
|
88
|
+
for (const entry of [...OPTIONAL_VENDORED_DIRS, ...OPTIONAL_VENDORED_FILES]) {
|
|
89
|
+
const source = path.join(extractedEngineDir, entry);
|
|
90
|
+
if (fs.existsSync(source)) {
|
|
91
|
+
fs.cpSync(source, path.join(engineDir, entry), { recursive: true });
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Copies the engine's service worker to the project ROOT when the tarball carries one, and reports
|
|
97
|
+
* whether it did.
|
|
98
|
+
*
|
|
99
|
+
* AutoCacheBuster.ts registers it at the absolute path /sw-cache-buster.js, so it cannot be
|
|
100
|
+
* vendored under `engine/` — a service worker cannot control scopes above its own path. Absence is
|
|
101
|
+
* the same "not a corrupt tarball" allowance as `copyOptionalEngineEntries`: every tarball
|
|
102
|
+
* published before this feature shipped lacks it, and init and upgrade must both keep working
|
|
103
|
+
* against those.
|
|
104
|
+
*/
|
|
105
|
+
export function copyServiceWorker(extractedEngineDir, root) {
|
|
106
|
+
const source = path.join(extractedEngineDir, 'sw-cache-buster.js');
|
|
107
|
+
if (!fs.existsSync(source))
|
|
108
|
+
return false;
|
|
109
|
+
fs.cpSync(source, path.join(root, 'sw-cache-buster.js'));
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Writes one file into a project, creating its parent directories first.
|
|
114
|
+
*
|
|
115
|
+
* The mkdir is load-bearing for the nested entries — `.claude/skills/<name>/SKILL.md` — in a
|
|
116
|
+
* project that predates them: without it `writeFileSync` ENOENTs, and in `upgradeProject` it does
|
|
117
|
+
* so AFTER `engine/` has been replaced, leaving the project half-upgraded. mkdir on an existing
|
|
118
|
+
* directory is a no-op, so the top-level entries pay nothing for it.
|
|
119
|
+
*/
|
|
120
|
+
export function writeProjectFile(root, relativePath, contents) {
|
|
121
|
+
const filePath = path.join(root, relativePath);
|
|
122
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
123
|
+
fs.writeFileSync(filePath, contents);
|
|
124
|
+
}
|
|
78
125
|
/**
|
|
79
126
|
* The subset of the generated files that are pure platform output: regenerated byte-for-byte
|
|
80
127
|
* from these renderers with no creator content ever entering them. `bitmagic upgrade` overwrites
|
|
@@ -170,18 +217,7 @@ export function scaffoldProject(options) {
|
|
|
170
217
|
}
|
|
171
218
|
fs.cpSync(source, path.join(engineDir, dir), { recursive: true });
|
|
172
219
|
}
|
|
173
|
-
|
|
174
|
-
const source = path.join(extractedEngineDir, dir);
|
|
175
|
-
if (fs.existsSync(source)) {
|
|
176
|
-
fs.cpSync(source, path.join(engineDir, dir), { recursive: true });
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
for (const file of OPTIONAL_VENDORED_FILES) {
|
|
180
|
-
const source = path.join(extractedEngineDir, file);
|
|
181
|
-
if (fs.existsSync(source)) {
|
|
182
|
-
fs.cpSync(source, path.join(engineDir, file));
|
|
183
|
-
}
|
|
184
|
-
}
|
|
220
|
+
copyOptionalEngineEntries(extractedEngineDir, engineDir);
|
|
185
221
|
// The game: the genre baseline, then the template overlaid on top. Contents are copied, not
|
|
186
222
|
// the directory itself — a nested src/work/<genre>/ would break every relative import in
|
|
187
223
|
// Game.ts. This is a second copy of the same baseline vendored above as engine/genres/: that
|
|
@@ -201,21 +237,15 @@ export function scaffoldProject(options) {
|
|
|
201
237
|
if (fs.existsSync(overlayDir)) {
|
|
202
238
|
copyContents(overlayDir, srcDir);
|
|
203
239
|
}
|
|
204
|
-
|
|
205
|
-
// /sw-cache-buster.js, so it must be served from the project root, not vendored under
|
|
206
|
-
// engine/ — a service worker cannot control scopes above its own path. Unlike VENDORED_DIRS
|
|
207
|
-
// above, a missing file here is not treated as a corrupt tarball: every tarball published
|
|
208
|
-
// before this feature shipped lacks it, and `init` must keep scaffolding against those.
|
|
209
|
-
const serviceWorker = path.join(extractedEngineDir, 'sw-cache-buster.js');
|
|
210
|
-
if (fs.existsSync(serviceWorker)) {
|
|
211
|
-
fs.cpSync(serviceWorker, path.join(targetDir, 'sw-cache-buster.js'));
|
|
212
|
-
}
|
|
240
|
+
copyServiceWorker(extractedEngineDir, targetDir);
|
|
213
241
|
// Stamped as it is written, so a later `bitmagic upgrade` can tell whether the creator has
|
|
214
|
-
// edited it since — see scaffold/agents-md.ts for what that decides.
|
|
215
|
-
|
|
242
|
+
// edited it since — see scaffold/agents-md.ts for what that decides. The pin goes in because the
|
|
243
|
+
// file tells the agent which npm line this project's CLI comes from, and that is the environment's
|
|
244
|
+
// answer, not a choice to put to the creator.
|
|
245
|
+
const agentsMd = renderAgentsMd(metadata.environment);
|
|
216
246
|
const files = [
|
|
217
247
|
['package.json', renderPackageJson(projectName)],
|
|
218
|
-
...PLATFORM_GENERATED_FILES.map((
|
|
248
|
+
...PLATFORM_GENERATED_FILES.map(([name, render]) => [name, render()]),
|
|
219
249
|
['bitmagic.json', renderBitmagicJson({ ...metadata, agentsMdHash: hashAgentsMd(agentsMd) })],
|
|
220
250
|
['AGENTS.md', agentsMd],
|
|
221
251
|
// Creator-owned from here on (see PLATFORM_GENERATED_FILES): the agent rewrites it as the
|
|
@@ -229,11 +259,7 @@ export function scaffoldProject(options) {
|
|
|
229
259
|
[CLAUDE_SETTINGS_FILE, renderClaudeSettings()],
|
|
230
260
|
];
|
|
231
261
|
for (const [name, contents] of files) {
|
|
232
|
-
|
|
233
|
-
// .claude/skills/README.md nests two directories deep; every other entry is a top-level
|
|
234
|
-
// file, for which mkdir on the already-existing targetDir is a harmless no-op.
|
|
235
|
-
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
236
|
-
fs.writeFileSync(filePath, contents);
|
|
262
|
+
writeProjectFile(targetDir, name, contents);
|
|
237
263
|
}
|
|
238
264
|
}
|
|
239
265
|
//# sourceMappingURL=project.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project.js","sourceRoot":"","sources":["../../src/scaffold/project.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EACL,iBAAiB,EACjB,c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AK,EAAE,CAAC;QACrC,gBAAgB,CAAC,SAAS,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;IAC9C,CAAC;AACH,CAAC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as fs from 'fs';
|
|
2
2
|
import * as path from 'path';
|
|
3
3
|
import { CliError } from '../errors.js';
|
|
4
|
-
import { VENDORED_DIRS,
|
|
4
|
+
import { VENDORED_DIRS, PLATFORM_GENERATED_FILES, copyOptionalEngineEntries, copyServiceWorker, writeProjectFile, } from './project.js';
|
|
5
|
+
import { isEnvironmentName } from '../config/environments.js';
|
|
5
6
|
import { reconcileAgentsMd, AGENTS_MD_FILE } from './agents-md.js';
|
|
6
7
|
import { CLAUDE_SETTINGS_FILE, mergeReloadHook } from './claude-settings.js';
|
|
7
8
|
/**
|
|
@@ -52,39 +53,18 @@ export function upgradeProject(options) {
|
|
|
52
53
|
for (const dir of VENDORED_DIRS) {
|
|
53
54
|
fs.cpSync(path.join(extractedEngineDir, dir), path.join(engineDir, dir), { recursive: true });
|
|
54
55
|
}
|
|
55
|
-
// Copied only when present
|
|
56
|
-
// the
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
// Same allowance, same reason — and this is how a project scaffolded before the licence shipped
|
|
64
|
-
// acquires engine/LICENSE.md: the rmSync above took the old engine/ with it, so upgrading onto a
|
|
65
|
-
// tarball that carries the terms puts them in place without the creator doing anything.
|
|
66
|
-
for (const file of OPTIONAL_VENDORED_FILES) {
|
|
67
|
-
const source = path.join(extractedEngineDir, file);
|
|
68
|
-
if (fs.existsSync(source)) {
|
|
69
|
-
fs.cpSync(source, path.join(engineDir, file));
|
|
70
|
-
}
|
|
71
|
-
}
|
|
56
|
+
// Copied only when present, exactly as at init — upgrading onto a tarball that predates the docs
|
|
57
|
+
// corpus or the licence files must leave a working project, not a half-replaced engine/ and an
|
|
58
|
+
// error. This is also how a project scaffolded before the licence shipped acquires
|
|
59
|
+
// engine/LICENSE.md: the rmSync above took the old engine/ with it, so upgrading onto a tarball
|
|
60
|
+
// that carries the terms puts them in place without the creator doing anything.
|
|
61
|
+
copyOptionalEngineEntries(extractedEngineDir, engineDir);
|
|
72
62
|
replaced.push('engine/');
|
|
73
|
-
|
|
74
|
-
// feature shipped simply won't have it, and upgrade must not fail a project onto that tarball.
|
|
75
|
-
const serviceWorker = path.join(extractedEngineDir, 'sw-cache-buster.js');
|
|
76
|
-
if (fs.existsSync(serviceWorker)) {
|
|
77
|
-
fs.cpSync(serviceWorker, path.join(root, 'sw-cache-buster.js'));
|
|
63
|
+
if (copyServiceWorker(extractedEngineDir, root)) {
|
|
78
64
|
replaced.push('sw-cache-buster.js');
|
|
79
65
|
}
|
|
80
66
|
for (const [name, render] of PLATFORM_GENERATED_FILES) {
|
|
81
|
-
|
|
82
|
-
// The skills nest two directories deep, and a project scaffolded before they existed — or
|
|
83
|
-
// before a newly added one existed — has no such directory. Without this, writeFileSync ENOENTs
|
|
84
|
-
// and the upgrade dies AFTER engine/ has already been replaced. mkdir on an existing directory
|
|
85
|
-
// is a no-op, so the flat entries pay nothing for it.
|
|
86
|
-
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
87
|
-
fs.writeFileSync(filePath, render());
|
|
67
|
+
writeProjectFile(root, name, render());
|
|
88
68
|
replaced.push(name);
|
|
89
69
|
}
|
|
90
70
|
// Merged, never rewritten — the creator's permissions and their own hooks live in this file, and
|
|
@@ -94,8 +74,7 @@ export function upgradeProject(options) {
|
|
|
94
74
|
const existingSettings = fs.existsSync(settingsPath) ? fs.readFileSync(settingsPath, 'utf-8') : undefined;
|
|
95
75
|
const settings = mergeReloadHook(existingSettings);
|
|
96
76
|
if (settings.contents !== null) {
|
|
97
|
-
|
|
98
|
-
fs.writeFileSync(settingsPath, settings.contents);
|
|
77
|
+
writeProjectFile(root, CLAUDE_SETTINGS_FILE, settings.contents);
|
|
99
78
|
replaced.push(CLAUDE_SETTINGS_FILE);
|
|
100
79
|
}
|
|
101
80
|
// Read-modify-write, not re-rendered from renderBitmagicJson: re-rendering would discard any
|
|
@@ -112,8 +91,15 @@ export function upgradeProject(options) {
|
|
|
112
91
|
meta.environment = environmentPinned;
|
|
113
92
|
// AGENTS.md last, because it is the one file here whose treatment depends on reading the stamp
|
|
114
93
|
// out of the metadata above — and whose result is written back into it below.
|
|
94
|
+
//
|
|
95
|
+
// The pin goes in too: the template's CLI-update section names the npm line this project's
|
|
96
|
+
// environment implies, so it is read AFTER the backfill above (a project that just gained a pin
|
|
97
|
+
// gets an AGENTS.md that knows it). An unrecognised hand-edited value renders as unpinned rather
|
|
98
|
+
// than throwing — refusing to refresh the guidance would be a strange way to report a typo, and
|
|
99
|
+
// the environment resolution the command already did says it far better.
|
|
115
100
|
const storedHash = typeof meta.agentsMdHash === 'string' ? meta.agentsMdHash : undefined;
|
|
116
|
-
const
|
|
101
|
+
const pinned = typeof meta.environment === 'string' && isEnvironmentName(meta.environment) ? meta.environment : undefined;
|
|
102
|
+
const agentsMd = reconcileAgentsMd(root, storedHash, pinned);
|
|
117
103
|
if (agentsMd.hashToStore !== undefined)
|
|
118
104
|
meta.agentsMdHash = agentsMd.hashToStore;
|
|
119
105
|
if (agentsMd.action === 'created' || agentsMd.action === 'rewritten')
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upgrade-project.js","sourceRoot":"","sources":["../../src/scaffold/upgrade-project.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EACL,aAAa,EACb,
|
|
1
|
+
{"version":3,"file":"upgrade-project.js","sourceRoot":"","sources":["../../src/scaffold/upgrade-project.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,I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AAC,WAAW,CAAC;IACjF,IAAI,QAAQ,CAAC,MAAM,KAAK,SAAS,IAAI,QAAQ,CAAC,MAAM,KAAK,WAAW;QAAE,QAAQ,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IAEpG,EAAE,CAAC,aAAa,CAAC,gBAAgB,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC;IACzE,QAAQ,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IAE/B,OAAO;QACL,aAAa;QACb,qBAAqB;QACrB,QAAQ;QACR,QAAQ;QACR,GAAG,CAAC,QAAQ,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,qBAAqB,EAAE,QAAQ,CAAC,OAAO,EAAE,CAAC;QACtF,GAAG,CAAC,iBAAiB,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,iBAAiB,EAAE,CAAC;KAClE,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { type Environment } from '../config/environments.js';
|
|
2
|
+
/**
|
|
3
|
+
* What is driving the CLI.
|
|
4
|
+
*
|
|
5
|
+
* - `claude-code` — a Claude Code session (its `CLAUDECODE` env var, verified).
|
|
6
|
+
* - `json` — some agent, unidentified: `--json` is the flag agents pass.
|
|
7
|
+
* - `tty` — a person at a terminal.
|
|
8
|
+
* - `pipe` — a script or CI: no `--json`, no terminal.
|
|
9
|
+
*
|
|
10
|
+
* Add an agent here only once its marker is verified against the real thing; a
|
|
11
|
+
* guessed env var never fires and just misleads whoever reads the table.
|
|
12
|
+
*/
|
|
13
|
+
export type CliDriver = 'claude-code' | 'json' | 'tty' | 'pipe';
|
|
14
|
+
export declare function detectDriver(input: {
|
|
15
|
+
json: boolean;
|
|
16
|
+
env: Record<string, string | undefined>;
|
|
17
|
+
isTTY: boolean;
|
|
18
|
+
}): CliDriver;
|
|
19
|
+
/**
|
|
20
|
+
* `DO_NOT_TRACK` set to anything but `0`/`false`/empty. The convention says
|
|
21
|
+
* `1`; being generous about the spelling is the polite reading of a signal
|
|
22
|
+
* that only ever means "please don't".
|
|
23
|
+
*
|
|
24
|
+
* Lives here rather than in report.ts because it is consulted BEFORE anything
|
|
25
|
+
* is collected — `beginCommand` skips the whole snapshot when it is set — and
|
|
26
|
+
* report.ts already imports this module, so the other direction would close a
|
|
27
|
+
* cycle. Re-exported from report.ts, which is where callers expect it.
|
|
28
|
+
*/
|
|
29
|
+
export declare function isTelemetryDisabled(env: Record<string, string | undefined>): boolean;
|
|
30
|
+
export interface TokenSnapshot {
|
|
31
|
+
accessToken: string;
|
|
32
|
+
/** Epoch milliseconds, as stored. */
|
|
33
|
+
expiresAt: number;
|
|
34
|
+
}
|
|
35
|
+
export interface CommandContext {
|
|
36
|
+
/** As typed, so a report reads the way the creator invoked it: `publish`, `generate skybox`. */
|
|
37
|
+
name: string;
|
|
38
|
+
json: boolean;
|
|
39
|
+
driver: CliDriver;
|
|
40
|
+
/**
|
|
41
|
+
* Where this command is talking to, resolved ONCE here through the same
|
|
42
|
+
* precedence every command uses (`--env` > BITMAGIC_ENV > the project's
|
|
43
|
+
* bitmagic.json > the stored default). `report.ts` reads it rather than
|
|
44
|
+
* resolving again: a second resolution is a second chance to disagree, and
|
|
45
|
+
* one that skipped the project tier would send a project's beacons to a
|
|
46
|
+
* different environment than the work they describe.
|
|
47
|
+
*
|
|
48
|
+
* Null only when resolution threw — an unknown `--env`, or a project whose
|
|
49
|
+
* `environment` field is not a valid name. The command itself fails with
|
|
50
|
+
* that message moments later; there is simply nowhere to report it to.
|
|
51
|
+
*/
|
|
52
|
+
environment: Environment | null;
|
|
53
|
+
/** Epoch milliseconds when the command began. */
|
|
54
|
+
startedAt: number;
|
|
55
|
+
/** See the module header: the stored access token at start, for the one command that removes it. */
|
|
56
|
+
tokenSnapshot: TokenSnapshot | null;
|
|
57
|
+
}
|
|
58
|
+
export interface BeginCommandInput {
|
|
59
|
+
name: string;
|
|
60
|
+
json: boolean;
|
|
61
|
+
explicitEnv?: string;
|
|
62
|
+
env?: Record<string, string | undefined>;
|
|
63
|
+
isTTY?: boolean;
|
|
64
|
+
now?: () => number;
|
|
65
|
+
baseDir?: string;
|
|
66
|
+
/** Where to look for the project's own environment pin; defaults to process.cwd(). */
|
|
67
|
+
cwd?: string;
|
|
68
|
+
}
|
|
69
|
+
export declare function beginCommand(input: BeginCommandInput): CommandContext;
|
|
70
|
+
/** The running command, or null before `beginCommand` — e.g. under a test that calls a module directly. */
|
|
71
|
+
export declare function currentCommand(): CommandContext | null;
|
|
72
|
+
/** Test seam: forget the running command, so one test's context cannot leak into the next. */
|
|
73
|
+
export declare function resetCommandContextForTests(): void;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which command this process is running — the one piece of state the CLI's usage
|
|
3
|
+
* reporting is built on.
|
|
4
|
+
*
|
|
5
|
+
* One process runs one command, so this is process-scoped: cli.ts's wrapper calls
|
|
6
|
+
* {@link beginCommand} once before the command's `run`, and two readers use it —
|
|
7
|
+
* `request-headers.ts`, which names the command on every api-server call, and
|
|
8
|
+
* `report.ts`, which sends the outcome when the command ends. It is the CLI's
|
|
9
|
+
* equivalent of a request context, and it lives here rather than being threaded
|
|
10
|
+
* through every command signature because there are five separate fetch sites and
|
|
11
|
+
* eighteen commands, and a parameter every one of them must remember to pass is
|
|
12
|
+
* how one of them ends up unlabelled.
|
|
13
|
+
*
|
|
14
|
+
* Nothing here reaches the network. The token snapshot is a file read, and it
|
|
15
|
+
* exists for exactly one command: `logout` removes the stored credentials, so by
|
|
16
|
+
* the time its outcome is reported there is nothing to authenticate the report
|
|
17
|
+
* with — except what was there when it started.
|
|
18
|
+
*/
|
|
19
|
+
import { readCredentials } from '../config/credentials.js';
|
|
20
|
+
import { resolveEnvironmentForCommand } from '../config/environments.js';
|
|
21
|
+
const AGENT_ENV_MARKERS = [['CLAUDECODE', 'claude-code']];
|
|
22
|
+
export function detectDriver(input) {
|
|
23
|
+
for (const [marker, driver] of AGENT_ENV_MARKERS) {
|
|
24
|
+
if (input.env[marker])
|
|
25
|
+
return driver;
|
|
26
|
+
}
|
|
27
|
+
if (input.json)
|
|
28
|
+
return 'json';
|
|
29
|
+
return input.isTTY ? 'tty' : 'pipe';
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* `DO_NOT_TRACK` set to anything but `0`/`false`/empty. The convention says
|
|
33
|
+
* `1`; being generous about the spelling is the polite reading of a signal
|
|
34
|
+
* that only ever means "please don't".
|
|
35
|
+
*
|
|
36
|
+
* Lives here rather than in report.ts because it is consulted BEFORE anything
|
|
37
|
+
* is collected — `beginCommand` skips the whole snapshot when it is set — and
|
|
38
|
+
* report.ts already imports this module, so the other direction would close a
|
|
39
|
+
* cycle. Re-exported from report.ts, which is where callers expect it.
|
|
40
|
+
*/
|
|
41
|
+
export function isTelemetryDisabled(env) {
|
|
42
|
+
const value = env.DO_NOT_TRACK?.trim().toLowerCase();
|
|
43
|
+
return value !== undefined && value !== '' && value !== '0' && value !== 'false';
|
|
44
|
+
}
|
|
45
|
+
let current = null;
|
|
46
|
+
/**
|
|
47
|
+
* The environment this command targets, or null if it cannot be resolved.
|
|
48
|
+
*
|
|
49
|
+
* `resolveEnvironmentForCommand` is the same entry point the commands use, so
|
|
50
|
+
* a project pinned to an environment reports there too. It throws for an
|
|
51
|
+
* unknown name typed right now (a bad `--env`, a bad `bitmagic.json`), which
|
|
52
|
+
* the command surfaces properly — here it only means "no environment to report
|
|
53
|
+
* to", never a failed command.
|
|
54
|
+
*/
|
|
55
|
+
function snapshotEnvironment(input, env) {
|
|
56
|
+
try {
|
|
57
|
+
return resolveEnvironmentForCommand({
|
|
58
|
+
explicit: input.explicitEnv,
|
|
59
|
+
cwd: input.cwd,
|
|
60
|
+
baseDir: input.baseDir,
|
|
61
|
+
env,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The stored access token for `environment`, or null.
|
|
70
|
+
*
|
|
71
|
+
* Every failure collapses to null on purpose: no environment, an unreadable
|
|
72
|
+
* credentials file, nothing stored — the command itself will report whichever
|
|
73
|
+
* of those matters, in its own words. This is a snapshot for a report, and a
|
|
74
|
+
* report is never worth failing a command over.
|
|
75
|
+
*/
|
|
76
|
+
function snapshotToken(environment, baseDir) {
|
|
77
|
+
if (environment === null)
|
|
78
|
+
return null;
|
|
79
|
+
try {
|
|
80
|
+
const stored = readCredentials(environment.name, baseDir);
|
|
81
|
+
return stored ? { accessToken: stored.accessToken, expiresAt: stored.expiresAt } : null;
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
export function beginCommand(input) {
|
|
88
|
+
const env = input.env ?? process.env;
|
|
89
|
+
// Nothing is collected for a creator who opted out. Both snapshots below are
|
|
90
|
+
// filesystem work — a walk up the tree for the project's bitmagic.json, then
|
|
91
|
+
// credentials.json — done on every one of the eighteen commands, including
|
|
92
|
+
// the offline ones and the `reload` hook that runs after every agent turn.
|
|
93
|
+
// None of it has a purpose if no report will be sent.
|
|
94
|
+
const collect = !isTelemetryDisabled(env);
|
|
95
|
+
const environment = collect ? snapshotEnvironment(input, env) : null;
|
|
96
|
+
current = {
|
|
97
|
+
name: input.name,
|
|
98
|
+
json: input.json,
|
|
99
|
+
driver: detectDriver({ json: input.json, env, isTTY: input.isTTY ?? process.stdout.isTTY === true }),
|
|
100
|
+
environment,
|
|
101
|
+
startedAt: (input.now ?? Date.now)(),
|
|
102
|
+
tokenSnapshot: collect ? snapshotToken(environment, input.baseDir) : null,
|
|
103
|
+
};
|
|
104
|
+
return current;
|
|
105
|
+
}
|
|
106
|
+
/** The running command, or null before `beginCommand` — e.g. under a test that calls a module directly. */
|
|
107
|
+
export function currentCommand() {
|
|
108
|
+
return current;
|
|
109
|
+
}
|
|
110
|
+
/** Test seam: forget the running command, so one test's context cannot leak into the next. */
|
|
111
|
+
export function resetCommandContextForTests() {
|
|
112
|
+
current = null;
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=command-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command-context.js","sourceRoot":"","sources":["../../src/telemetry/command-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,4BAA4B,EAAoB,MAAM,2BAA2B,CAAC;AAe3F,MAAM,iBAAiB,GAAgD,CAAC,CAAC,YAAY,EAAE,aAAa,CAAC,CAAC,CAAC;AAEvG,MAAM,UAAU,YAAY,CAAC,KAI5B;IACC,KAAK,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,iBAAiB,EAAE,CAAC;QACjD,IAAI,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC;YAAE,OAAO,MAAM,CAAC;IACvC,CAAC;IACD,IAAI,KAAK,CAAC,IAAI;QAAE,OAAO,MAAM,CAAC;IAC9B,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC;AACtC,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,mBAAmB,CAAC,GAAuC;IACzE,MAAM,KAAK,GAAG,GAAG,CAAC,YAAY,EAAE,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IACrD,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,EAAE,IAAI,KAAK,KAAK,GAAG,IAAI,KAAK,KAAK,OAAO,CAAC;AACnF,CAAC;AA4CD,IAAI,OAAO,GAA0B,IAAI,CAAC;AAE1C;;;;;;;;GAQG;AACH,SAAS,mBAAmB,CAAC,KAAwB,EAAE,GAAuC;IAC5F,IA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AAK,CAAC,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC,KAAK,KAAK,IAAI,EAAE,CAAC;QACpG,WAAW;QACX,SAAS,EAAE,CAAC,KAAK,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE;QACpC,aAAa,EAAE,OAAO,CAAC,CAAC,CAAC,aAAa,CAAC,WAAW,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI;KAC1E,CAAC;IACF,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,2GAA2G;AAC3G,MAAM,UAAU,cAAc;IAC5B,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,8FAA8F;AAC9F,MAAM,UAAU,2BAA2B;IACzC,OAAO,GAAG,IAAI,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { isTelemetryDisabled } from './command-context.js';
|
|
2
|
+
export { isTelemetryDisabled };
|
|
3
|
+
/**
|
|
4
|
+
* Cap on each request the report makes (the token refresh, when one is due, and
|
|
5
|
+
* the POST itself). A pending fetch keeps Node alive, so an unbounded one would
|
|
6
|
+
* hold a finished command open for as long as the network sulks.
|
|
7
|
+
*/
|
|
8
|
+
export declare const REPORT_TIMEOUT_MS = 1500;
|
|
9
|
+
export declare const CLI_EVENTS_PATH = "/api/cli/v1/events";
|
|
10
|
+
export interface CommandReport {
|
|
11
|
+
/** `finished` for every command's end; `started` for a long-running command once it is up. */
|
|
12
|
+
stage: 'started' | 'finished';
|
|
13
|
+
ok?: boolean;
|
|
14
|
+
durationMs?: number;
|
|
15
|
+
exitCode?: number;
|
|
16
|
+
/** A category — `CliError.code`, `cli_error`, `crash:TypeError` — never a message. */
|
|
17
|
+
failure?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface ReportDeps {
|
|
20
|
+
fetch: typeof globalThis.fetch;
|
|
21
|
+
env: Record<string, string | undefined>;
|
|
22
|
+
now?: () => number;
|
|
23
|
+
/** Where credentials live; tests point this at a temp dir. */
|
|
24
|
+
baseDir?: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The failure category for an error that is not a CliError — a genuine bug, not
|
|
28
|
+
* a refusal we wrote a message for. `crash:TypeError`, `crash:RangeError`: the
|
|
29
|
+
* error's class, which says what kind of bug without saying anything about the
|
|
30
|
+
* creator's machine. Anything odd in the name is folded to `_` so the value
|
|
31
|
+
* always fits the shape api-server accepts.
|
|
32
|
+
*/
|
|
33
|
+
export declare function crashCategory(error: unknown): string;
|
|
34
|
+
/**
|
|
35
|
+
* Report the running command's `report` to api-server. Resolves when the report
|
|
36
|
+
* has been sent, refused, or given up on — always, and never by throwing.
|
|
37
|
+
*
|
|
38
|
+
* Callers `await` it (bounded, see above) rather than fire and forget: on the
|
|
39
|
+
* failure path cli.ts calls `process.exit` next, which would otherwise cut the
|
|
40
|
+
* request off mid-flight, and on the success path the pending fetch would keep
|
|
41
|
+
* the process alive for the same time either way.
|
|
42
|
+
*/
|
|
43
|
+
export declare function reportCommandEvent(report: CommandReport, deps?: ReportDeps): Promise<void>;
|