@astryxdesign/cli 0.7.2 → 0.7.3-canary.b74cf21
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 +99 -66
- package/api/build/_adapter.d.mts +58 -0
- package/api/build/_adapter.mjs +115 -3
- package/api/build/blocks/blocks.d.mts +42 -0
- package/api/build/blocks/blocks.mjs +169 -0
- package/api/build/blocks/blocks.test.mjs +108 -0
- package/api/build/blocks/blocks.weights.json +1 -0
- package/api/build/build.mjs +25 -6
- package/api/build/kit/answer.d.mts +14 -0
- package/api/build/kit/answer.mjs +85 -0
- package/api/build/kit/answer.test.mjs +38 -0
- package/api/build/kit/kind.d.mts +25 -0
- package/api/build/kit/kind.mjs +170 -0
- package/api/build/kit/kit.d.mts +2 -4
- package/api/build/kit/kit.mjs +8 -398
- package/api/build/kit/rank.d.mts +3 -32
- package/api/build/kit/rank.mjs +25 -342
- package/api/build/kit/rank.test.mjs +2 -1
- package/api/build/kit/signals.d.mts +60 -0
- package/api/build/kit/signals.mjs +284 -0
- package/api/build/kit/start.d.mts +32 -0
- package/api/build/kit/start.mjs +163 -0
- package/api/build/kit/words.d.mts +72 -0
- package/api/build/kit/words.mjs +202 -0
- package/api/build/tree.d.mts +20 -0
- package/api/build/tree.mjs +52 -0
- package/api/build/tree.test.mjs +177 -0
- package/api/build/tree.weights.json +1 -0
- package/api/discover/_adapter.mjs +36 -9
- package/api/discover/_adapter.test.mjs +42 -0
- package/api/docs/_adapter.mjs +17 -5
- package/api/docs/docs.test.mjs +7 -1
- package/api/doctor/doctor.mjs +86 -12
- package/api/init/init.doc.mjs +20 -6
- package/api/init/init.test.mjs +18 -2
- package/api/init/init.type.d.mts +3 -3
- package/api/init/init.type.mjs +3 -3
- package/api/init/remove/remove.mjs +17 -4
- package/api/init/remove/remove.test.mjs +114 -2
- package/api/init/run/run.mjs +69 -6
- package/api/integration/authoring-checks.mjs +83 -9
- package/api/integration/pack-check.mjs +14 -1
- package/api/integration/pack-check.test.mjs +18 -0
- package/api/integration/validate-integration-case-disk.test.mjs +111 -0
- package/api/integration/validate-integration-gaps.test.mjs +1672 -0
- package/api/integration/validate-integration.d.mts +9 -1
- package/api/integration/validate-integration.mjs +216 -26
- package/api/integration/validate-integration.type.d.mts +57 -1
- package/api/integration/validate-integration.type.mjs +44 -2
- package/api/integration/validateIntegration.doc.mjs +1 -1
- package/api/search/ORDERING.md +28 -0
- package/api/search/_adapter.d.mts +66 -2
- package/api/search/_adapter.mjs +118 -10
- package/api/search/_candidate-score.d.mts +40 -0
- package/api/search/_candidate-score.mjs +238 -0
- package/api/search/_cards.json +6098 -0
- package/api/search/_compound.d.mts +50 -0
- package/api/search/_compound.mjs +170 -0
- package/api/search/_doc-searcher.d.mts +4 -0
- package/api/search/_doc-searcher.mjs +23 -0
- package/api/search/_doc-searcher.test.mjs +36 -0
- package/api/search/_doc-searcher.weights.json +1 -0
- package/api/search/_doc-text.d.mts +30 -0
- package/api/search/_doc-text.mjs +87 -0
- package/api/search/_entries.d.mts +52 -0
- package/api/search/_entries.mjs +158 -0
- package/api/search/_features.d.mts +35 -0
- package/api/search/_features.mjs +155 -0
- package/api/search/_gather-components.d.mts +26 -0
- package/api/search/_gather-components.mjs +284 -0
- package/api/search/_gather-docs.d.mts +20 -0
- package/api/search/_gather-docs.mjs +254 -0
- package/api/search/_gather-hooks.d.mts +12 -0
- package/api/search/_gather-hooks.mjs +52 -0
- package/api/search/_gather-templates.d.mts +25 -0
- package/api/search/_gather-templates.mjs +107 -0
- package/api/search/_lexical.d.mts +135 -0
- package/api/search/_lexical.mjs +351 -0
- package/api/search/_main-searcher.d.mts +19 -0
- package/api/search/_main-searcher.mjs +115 -0
- package/api/search/_main-searcher.test.mjs +106 -0
- package/api/search/_main-searcher.weights.json +1 -0
- package/api/search/_module-doc.d.mts +32 -0
- package/api/search/_module-doc.mjs +78 -0
- package/api/search/_order.d.mts +32 -0
- package/api/search/_order.mjs +162 -0
- package/api/search/_order.test.mjs +72 -0
- package/api/search/_priority.d.mts +50 -0
- package/api/search/_priority.mjs +139 -0
- package/api/search/_query-words.d.mts +25 -0
- package/api/search/_query-words.mjs +92 -0
- package/api/search/_query.d.mts +65 -0
- package/api/search/_query.mjs +176 -0
- package/api/search/_result.d.mts +97 -0
- package/api/search/_result.mjs +150 -0
- package/api/search/_score.d.mts +60 -0
- package/api/search/_score.mjs +283 -0
- package/api/search/_synonyms.d.mts +21 -0
- package/api/search/_synonyms.mjs +67 -0
- package/api/search/_template-searcher.d.mts +4 -0
- package/api/search/_template-searcher.mjs +23 -0
- package/api/search/_template-searcher.test.mjs +40 -0
- package/api/search/_template-searcher.weights.json +1 -0
- package/api/search/_titles.d.mts +33 -0
- package/api/search/_titles.mjs +65 -0
- package/api/search/_words.d.mts +64 -0
- package/api/search/_words.mjs +157 -0
- package/api/search/search.d.mts +22 -305
- package/api/search/search.doc.mjs +7 -5
- package/api/search/search.mjs +53 -2483
- package/api/search/search.type.d.mts +6 -1
- package/api/search/search.type.mjs +6 -1
- package/api/search/tree.d.mts +15 -0
- package/api/search/tree.mjs +40 -0
- package/api/search/tree.test.mjs +66 -0
- package/api/search/tree.weights.json +1 -0
- package/api/theme/build/build.packed-old-core.test.mjs +1 -0
- package/api/upgrade/_adapter.d.mts +0 -6
- package/api/upgrade/_adapter.mjs +52 -4
- package/api/upgrade/upgrade.test.mjs +194 -0
- package/assets/codemods/transforms/v0.7.0/__tests__/validate-data-token-ownership.test.mjs +11 -0
- package/assets/codemods/transforms/v0.7.0/validate-data-token-ownership.mjs +3 -3
- package/assets/docs/tree/api.doc.mjs +6 -0
- package/assets/docs/tree/host-entry.doc.mjs +128 -0
- package/assets/docs/tree/tokens-data.doc.mjs +2 -2
- package/assets/docs/working-with-ai.doc.mjs +6 -2
- package/authoring/debug/parse.d.mts +1 -1
- package/clients/cli/bin/astryx.mjs +7 -78
- package/clients/cli/commands/doctor.mjs +30 -0
- package/clients/cli/commands/doctor.test.mjs +65 -0
- package/clients/cli/commands/init.behavior.test.mjs +230 -1
- package/clients/cli/commands/init.doc.mjs +28 -9
- package/clients/cli/commands/init.flag-help.test.mjs +1 -0
- package/clients/cli/commands/init.mjs +2 -2
- package/clients/cli/commands/outside-project.test.mjs +2 -1
- package/clients/cli/commands/setup-nudge.test.mjs +61 -0
- package/clients/cli/index.mjs +19 -1
- package/clients/cli/run.mjs +108 -0
- package/foundation/agent-docs/agent-doc-state.d.mts +20 -7
- package/foundation/agent-docs/agent-doc-state.mjs +35 -8
- package/foundation/agent-docs/agent-docs.d.mts +100 -12
- package/foundation/agent-docs/agent-docs.mjs +1010 -99
- package/foundation/agent-docs/agent-docs.path-safety.test.mjs +1239 -17
- package/foundation/agent-docs/agent-docs.test.mjs +678 -35
- package/foundation/config/project.mjs +15 -2
- package/foundation/discovery/component-discovery.d.mts +37 -0
- package/foundation/discovery/component-discovery.mjs +80 -5
- package/foundation/discovery/component-loader.d.mts +1 -1
- package/foundation/discovery/docs-discovery.mjs +14 -1
- package/foundation/discovery/module-exports.d.mts +41 -0
- package/foundation/discovery/module-exports.mjs +253 -0
- package/foundation/doc-compiler/doc-loads.test.mjs +8 -0
- package/foundation/fs/paths.mjs +30 -3
- package/foundation/integrations/computer-integrations.d.mts +6 -3
- package/foundation/integrations/computer-integrations.mjs +38 -9
- package/foundation/integrations/contribution-inventory.d.mts +15 -20
- package/foundation/integrations/contribution-inventory.mjs +41 -5
- package/foundation/integrations/integrations.d.mts +7 -0
- package/foundation/integrations/integrations.mjs +2 -0
- package/foundation/integrations/validate-contributions.d.mts +96 -0
- package/foundation/integrations/validate-contributions.mjs +996 -10
- package/foundation/release/handoff.d.mts +23 -4
- package/foundation/release/handoff.mjs +175 -8
- package/foundation/release/run-context.mjs +14 -0
- package/foundation/response/response-types.doc.mjs +1 -1
- package/foundation/route/route.d.mts +285 -0
- package/foundation/route/route.mjs +324 -0
- package/foundation/route/route.test.mjs +153 -0
- package/foundation/runtime/hosted-runtime.test.mjs +403 -0
- package/foundation/runtime/locked-versions.d.mts +32 -0
- package/foundation/runtime/locked-versions.mjs +65 -0
- package/foundation/runtime/package-root.d.mts +91 -0
- package/foundation/runtime/package-root.mjs +174 -0
- package/foundation/runtime/package-set.d.mts +62 -0
- package/foundation/runtime/package-set.mjs +130 -0
- package/foundation/runtime/package-set.test.mjs +432 -0
- package/host/door-conformance.test.mjs +274 -0
- package/host/index.d.ts +116 -0
- package/host/index.mjs +295 -0
- package/host/index.test.mjs +302 -0
- package/package.json +14 -9
|
@@ -84,12 +84,6 @@ export function runPostCodemodHooks(hooks: import("../../authoring/config/type")
|
|
|
84
84
|
files: string[];
|
|
85
85
|
apply: boolean;
|
|
86
86
|
}): Promise<void>;
|
|
87
|
-
/**
|
|
88
|
-
* @typedef {object} AgentDocsRefreshPlan
|
|
89
|
-
* @property {string} cwd
|
|
90
|
-
* @property {string|null} renderedBlock
|
|
91
|
-
* @property {import('./upgrade.type.mjs').AgentDocsSummary} summary
|
|
92
|
-
*/
|
|
93
87
|
/**
|
|
94
88
|
* Compute the expected managed block and report staleness without writing.
|
|
95
89
|
* Apply-mode callers commit the prepared bytes only after codemods and hooks
|
package/api/upgrade/_adapter.mjs
CHANGED
|
@@ -30,6 +30,8 @@ import {
|
|
|
30
30
|
} from '../../assets/codemods/integration-discovery.mjs';
|
|
31
31
|
import {runIntegrationCodemods} from '../../assets/codemods/integration-runner.mjs';
|
|
32
32
|
import {
|
|
33
|
+
AgentDocsHomeError,
|
|
34
|
+
assertAgentDocsTarget,
|
|
33
35
|
installAgentDocs,
|
|
34
36
|
inspectAgentDocs,
|
|
35
37
|
renderAgentDocsBlock,
|
|
@@ -286,6 +288,21 @@ export async function runPostCodemodHooks(hooks, context) {
|
|
|
286
288
|
* @property {import('./upgrade.type.mjs').AgentDocsSummary} summary
|
|
287
289
|
*/
|
|
288
290
|
|
|
291
|
+
/**
|
|
292
|
+
* Why upgrade leaves the agent docs of a project at the home folder or the
|
|
293
|
+
* top of a settings folder, and what to do instead. init refuses the same
|
|
294
|
+
* folder, so the line never points at it.
|
|
295
|
+
* @param {AgentDocsHomeError} err
|
|
296
|
+
* @param {'stale' | 'missing'} [state] whether a block is there to refresh
|
|
297
|
+
* @returns {string}
|
|
298
|
+
*/
|
|
299
|
+
function homeRefusalLine(err, state = 'stale') {
|
|
300
|
+
const where = `${err.dir} is the home folder or a settings folder in it, which every project's agents read.`;
|
|
301
|
+
return state === 'missing'
|
|
302
|
+
? `Agent docs not installed: ${where} To have agent docs, move the project into a folder of its own, or add the Astryx block to its agent file by hand.`
|
|
303
|
+
: `Agent docs not refreshed: ${where} To keep agent docs, move the project into a folder of its own; otherwise update or remove the Astryx block there by hand.`;
|
|
304
|
+
}
|
|
305
|
+
|
|
289
306
|
/**
|
|
290
307
|
* Compute the expected managed block and report staleness without writing.
|
|
291
308
|
* Apply-mode callers commit the prepared bytes only after codemods and hooks
|
|
@@ -312,6 +329,16 @@ export async function prepareAgentDocsRefresh({
|
|
|
312
329
|
};
|
|
313
330
|
|
|
314
331
|
if (initial.status === 'missing') {
|
|
332
|
+
// init writes nothing in a project at the home folder or the top of a
|
|
333
|
+
// settings folder, so it is not the remedy there (INV31).
|
|
334
|
+
try {
|
|
335
|
+
assertAgentDocsTarget(cwd);
|
|
336
|
+
} catch (err) {
|
|
337
|
+
if (!(err instanceof AgentDocsHomeError)) throw err;
|
|
338
|
+
summary.action = 'error';
|
|
339
|
+
logger.warn(homeRefusalLine(err, 'missing'));
|
|
340
|
+
return {cwd, renderedBlock: null, summary};
|
|
341
|
+
}
|
|
315
342
|
summary.action = 'nudge-init';
|
|
316
343
|
logger.warn(
|
|
317
344
|
`No Astryx agent-docs block found - AI agents have no component index. Run \`${formatCliCommand('astryx init --features agents')}\` to install it.`,
|
|
@@ -340,6 +367,18 @@ export async function prepareAgentDocsRefresh({
|
|
|
340
367
|
summary.files = inspection.staleFiles;
|
|
341
368
|
if (inspection.status === 'current') return {cwd, renderedBlock, summary};
|
|
342
369
|
|
|
370
|
+
// A project at the home folder or the top of a settings folder is never
|
|
371
|
+
// refreshed (INV31): the dry run says so, as --apply does, rather than
|
|
372
|
+
// offering a refresh that would be refused.
|
|
373
|
+
try {
|
|
374
|
+
assertAgentDocsTarget(cwd);
|
|
375
|
+
} catch (err) {
|
|
376
|
+
if (!(err instanceof AgentDocsHomeError)) throw err;
|
|
377
|
+
summary.action = 'error';
|
|
378
|
+
logger.warn(homeRefusalLine(err));
|
|
379
|
+
return {cwd, renderedBlock: null, summary};
|
|
380
|
+
}
|
|
381
|
+
|
|
343
382
|
summary.action = 'would-refresh';
|
|
344
383
|
if (!apply) {
|
|
345
384
|
logger.warn(
|
|
@@ -363,6 +402,9 @@ export function applyAgentDocsRefresh(plan) {
|
|
|
363
402
|
const written = installAgentDocs(cwd, {
|
|
364
403
|
onlyReplace: true,
|
|
365
404
|
renderedBlock,
|
|
405
|
+
// A GEMINI.md that resolves outside the project is left as it is.
|
|
406
|
+
onSkipped: (file, reason) =>
|
|
407
|
+
logger.warn(`Note: ${file} left as it is (${reason}).`),
|
|
366
408
|
});
|
|
367
409
|
summary.refreshed = written.length > 0;
|
|
368
410
|
summary.files = written;
|
|
@@ -374,12 +416,18 @@ export function applyAgentDocsRefresh(plan) {
|
|
|
374
416
|
`Agent docs look stale but couldn't be refreshed. Run \`${formatCliCommand('astryx init --features agents')}\` to reinstall the block.`,
|
|
375
417
|
);
|
|
376
418
|
}
|
|
377
|
-
} catch {
|
|
419
|
+
} catch (err) {
|
|
378
420
|
summary.action = 'error';
|
|
379
421
|
summary.refreshed = false;
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
422
|
+
if (err instanceof AgentDocsHomeError) {
|
|
423
|
+
// init refuses this folder too, so pointing at it would loop: say why,
|
|
424
|
+
// and what to do instead.
|
|
425
|
+
logger.warn(homeRefusalLine(err));
|
|
426
|
+
} else {
|
|
427
|
+
logger.warn(
|
|
428
|
+
`Could not refresh agent docs. Run \`${formatCliCommand('astryx init --features agents')}\` to update them manually.`,
|
|
429
|
+
);
|
|
430
|
+
}
|
|
383
431
|
}
|
|
384
432
|
return summary;
|
|
385
433
|
}
|
|
@@ -246,6 +246,200 @@ describe('upgrade() — receipts', () => {
|
|
|
246
246
|
expect(content).not.toMatch(/Astryx v0\.0\.1 ·/);
|
|
247
247
|
});
|
|
248
248
|
|
|
249
|
+
it('leaves the block of a project at the top of a home settings folder, saying why and not pointing at init', async () => {
|
|
250
|
+
const saved = {
|
|
251
|
+
HOME: process.env.HOME,
|
|
252
|
+
USERPROFILE: process.env.USERPROFILE,
|
|
253
|
+
};
|
|
254
|
+
process.env.HOME = tmpDir;
|
|
255
|
+
process.env.USERPROFILE = tmpDir;
|
|
256
|
+
const warned = [];
|
|
257
|
+
const warn = vi
|
|
258
|
+
.spyOn(console, 'error')
|
|
259
|
+
.mockImplementation((...a) => warned.push(a.join(' ')));
|
|
260
|
+
logger.setSilent(false);
|
|
261
|
+
try {
|
|
262
|
+
const project = path.join(tmpDir, '.dotfiles');
|
|
263
|
+
fs.mkdirSync(project, {recursive: true});
|
|
264
|
+
writePkg(project, {'@astryxdesign/core': '0.0.15'});
|
|
265
|
+
writeInstalledCore(project, '0.0.15');
|
|
266
|
+
writeAgentBlock(project, 'AGENTS.md', '0.0.1');
|
|
267
|
+
|
|
268
|
+
const res = await upgrade({from: '0.0.15', apply: true}, {cwd: project});
|
|
269
|
+
|
|
270
|
+
expect(res.data.agentDocs.action).toBe('error');
|
|
271
|
+
expect(res.data.agentDocs.refreshed).toBe(false);
|
|
272
|
+
expect(fs.readFileSync(path.join(project, 'AGENTS.md'), 'utf-8')).toMatch(
|
|
273
|
+
/Astryx v0\.0\.1 ·/,
|
|
274
|
+
);
|
|
275
|
+
const text = warned.join('\n');
|
|
276
|
+
expect(text).toContain(
|
|
277
|
+
`Agent docs not refreshed: ${fs.realpathSync(project)} is the home folder or a settings folder in it, which every project's agents read. To keep agent docs, move the project into a folder of its own; otherwise update or remove the Astryx block there by hand.`,
|
|
278
|
+
);
|
|
279
|
+
expect(text).not.toContain('init --features agents');
|
|
280
|
+
} finally {
|
|
281
|
+
logger.setSilent(true);
|
|
282
|
+
warn.mockRestore();
|
|
283
|
+
for (const [key, value] of Object.entries(saved)) {
|
|
284
|
+
if (value === undefined) delete process.env[key];
|
|
285
|
+
else process.env[key] = value;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
it('with no block, in a project at the top of a home settings folder, says why instead of pointing at init', async () => {
|
|
291
|
+
const saved = {
|
|
292
|
+
HOME: process.env.HOME,
|
|
293
|
+
USERPROFILE: process.env.USERPROFILE,
|
|
294
|
+
};
|
|
295
|
+
process.env.HOME = tmpDir;
|
|
296
|
+
process.env.USERPROFILE = tmpDir;
|
|
297
|
+
const warned = [];
|
|
298
|
+
const warn = vi
|
|
299
|
+
.spyOn(console, 'error')
|
|
300
|
+
.mockImplementation((...a) => warned.push(a.join(' ')));
|
|
301
|
+
logger.setSilent(false);
|
|
302
|
+
try {
|
|
303
|
+
const project = path.join(tmpDir, '.dotfiles');
|
|
304
|
+
fs.mkdirSync(project, {recursive: true});
|
|
305
|
+
writePkg(project, {'@astryxdesign/core': '0.0.15'});
|
|
306
|
+
writeInstalledCore(project, '0.0.15');
|
|
307
|
+
|
|
308
|
+
const res = await upgrade({from: '0.0.15'}, {cwd: project});
|
|
309
|
+
|
|
310
|
+
expect(res.data.agentDocs.action).toBe('error');
|
|
311
|
+
const text = warned.join('\n');
|
|
312
|
+
expect(text).toContain(
|
|
313
|
+
`Agent docs not installed: ${fs.realpathSync(project)} is the home folder or a settings folder in it, which every project's agents read. To have agent docs, move the project into a folder of its own, or add the Astryx block to its agent file by hand.`,
|
|
314
|
+
);
|
|
315
|
+
expect(text).not.toContain('init --features agents');
|
|
316
|
+
} finally {
|
|
317
|
+
logger.setSilent(true);
|
|
318
|
+
warn.mockRestore();
|
|
319
|
+
for (const [key, value] of Object.entries(saved)) {
|
|
320
|
+
if (value === undefined) delete process.env[key];
|
|
321
|
+
else process.env[key] = value;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
it('a dry run in a project at the top of a home settings folder reports the refusal, not a refresh to apply', async () => {
|
|
327
|
+
const saved = {
|
|
328
|
+
HOME: process.env.HOME,
|
|
329
|
+
USERPROFILE: process.env.USERPROFILE,
|
|
330
|
+
};
|
|
331
|
+
process.env.HOME = tmpDir;
|
|
332
|
+
process.env.USERPROFILE = tmpDir;
|
|
333
|
+
const warned = [];
|
|
334
|
+
const warn = vi
|
|
335
|
+
.spyOn(console, 'error')
|
|
336
|
+
.mockImplementation((...a) => warned.push(a.join(' ')));
|
|
337
|
+
logger.setSilent(false);
|
|
338
|
+
try {
|
|
339
|
+
const project = path.join(tmpDir, '.dotfiles');
|
|
340
|
+
fs.mkdirSync(project, {recursive: true});
|
|
341
|
+
writePkg(project, {'@astryxdesign/core': '0.0.15'});
|
|
342
|
+
writeInstalledCore(project, '0.0.15');
|
|
343
|
+
writeAgentBlock(project, 'AGENTS.md', '0.0.1');
|
|
344
|
+
|
|
345
|
+
const res = await upgrade({from: '0.0.15'}, {cwd: project});
|
|
346
|
+
|
|
347
|
+
expect(res.data.agentDocs.action).toBe('error');
|
|
348
|
+
expect(res.data.agentDocs.refreshed).toBe(false);
|
|
349
|
+
const text = warned.join('\n');
|
|
350
|
+
expect(text).toContain(
|
|
351
|
+
`Agent docs not refreshed: ${fs.realpathSync(project)} is the home folder or a settings folder in it`,
|
|
352
|
+
);
|
|
353
|
+
expect(text).not.toContain('--apply to refresh');
|
|
354
|
+
expect(text).not.toContain('init --features agents');
|
|
355
|
+
} finally {
|
|
356
|
+
logger.setSilent(true);
|
|
357
|
+
warn.mockRestore();
|
|
358
|
+
for (const [key, value] of Object.entries(saved)) {
|
|
359
|
+
if (value === undefined) delete process.env[key];
|
|
360
|
+
else process.env[key] = value;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
it('refreshes the agent docs of a project in an agent worktree inside a home settings folder', async () => {
|
|
366
|
+
const saved = {
|
|
367
|
+
HOME: process.env.HOME,
|
|
368
|
+
USERPROFILE: process.env.USERPROFILE,
|
|
369
|
+
};
|
|
370
|
+
process.env.HOME = tmpDir;
|
|
371
|
+
process.env.USERPROFILE = tmpDir;
|
|
372
|
+
try {
|
|
373
|
+
const project = path.join(tmpDir, '.codex', 'worktrees', 'a1b2c3', 'web');
|
|
374
|
+
fs.mkdirSync(project, {recursive: true});
|
|
375
|
+
writePkg(project, {'@astryxdesign/core': '0.0.15'});
|
|
376
|
+
writeInstalledCore(project, '0.0.15');
|
|
377
|
+
writeAgentBlock(project, 'AGENTS.md', '0.0.1');
|
|
378
|
+
|
|
379
|
+
const res = await upgrade({from: '0.0.15', apply: true}, {cwd: project});
|
|
380
|
+
|
|
381
|
+
expect(res.data.agentDocs.action).toBe('refreshed');
|
|
382
|
+
expect(fs.readFileSync(path.join(project, 'AGENTS.md'), 'utf-8')).toMatch(
|
|
383
|
+
/Astryx v0\.0\.15 ·/,
|
|
384
|
+
);
|
|
385
|
+
} finally {
|
|
386
|
+
for (const [key, value] of Object.entries(saved)) {
|
|
387
|
+
if (value === undefined) delete process.env[key];
|
|
388
|
+
else process.env[key] = value;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
it('refreshes the managed block in an ignored .claude/CLAUDE.md and keeps the text around it (INV31)', async () => {
|
|
394
|
+
writePkg(tmpDir);
|
|
395
|
+
writeInstalledCore(tmpDir, '0.0.15');
|
|
396
|
+
writeAgentBlock(tmpDir, 'AGENTS.md', '0.0.1');
|
|
397
|
+
fs.mkdirSync(path.join(tmpDir, '.claude'));
|
|
398
|
+
writeAgentBlock(tmpDir, '.claude/CLAUDE.md', '0.0.1');
|
|
399
|
+
const claude = path.join(tmpDir, '.claude', 'CLAUDE.md');
|
|
400
|
+
fs.writeFileSync(
|
|
401
|
+
claude,
|
|
402
|
+
`# Team notes\n\n${fs.readFileSync(claude, 'utf-8')}\nMore notes.\n`,
|
|
403
|
+
);
|
|
404
|
+
fs.writeFileSync(path.join(tmpDir, '.gitignore'), '.claude/\n');
|
|
405
|
+
|
|
406
|
+
const res = await upgrade({from: '0.0.15', apply: true}, {cwd: tmpDir});
|
|
407
|
+
|
|
408
|
+
expect(res.data.agentDocs.action).toBe('refreshed');
|
|
409
|
+
expect(res.data.agentDocs.files).toEqual([
|
|
410
|
+
'AGENTS.md',
|
|
411
|
+
'.claude/CLAUDE.md',
|
|
412
|
+
]);
|
|
413
|
+
expect(res.data.agentDocs).not.toHaveProperty('protectedFiles');
|
|
414
|
+
const content = fs.readFileSync(claude, 'utf-8');
|
|
415
|
+
expect(content).toMatch(/^# Team notes\n/u);
|
|
416
|
+
expect(content).toMatch(/Astryx v0\.0\.15 ·/u);
|
|
417
|
+
expect(content).toMatch(/More notes\.\n$/u);
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
it('refreshes a committed .claude/CLAUDE.md that imports AGENTS.md and keeps a copy beside an ignored root CLAUDE.md', async () => {
|
|
421
|
+
writePkg(tmpDir);
|
|
422
|
+
writeInstalledCore(tmpDir, '0.0.15');
|
|
423
|
+
writeAgentBlock(tmpDir, 'AGENTS.md', '0.0.1');
|
|
424
|
+
writeAgentBlock(tmpDir, 'CLAUDE.md', '0.0.1');
|
|
425
|
+
fs.writeFileSync(path.join(tmpDir, '.gitignore'), '/CLAUDE.md\n');
|
|
426
|
+
fs.mkdirSync(path.join(tmpDir, '.claude'));
|
|
427
|
+
const copy = path.join(tmpDir, '.claude', 'CLAUDE.md');
|
|
428
|
+
fs.writeFileSync(
|
|
429
|
+
copy,
|
|
430
|
+
`@../AGENTS.md\n\n${generateCompressedIndex('0.0.1')}\n`,
|
|
431
|
+
);
|
|
432
|
+
|
|
433
|
+
for (let round = 0; round < 2; round++) {
|
|
434
|
+
await upgrade({from: '0.0.15', apply: true}, {cwd: tmpDir});
|
|
435
|
+
const content = fs.readFileSync(copy, 'utf-8');
|
|
436
|
+
expect(content, `round ${round}`).toMatch(/^@\.\.\/AGENTS\.md\n/u);
|
|
437
|
+
expect(content, `round ${round}`).toMatch(/Astryx v0\.0\.15 ·/u);
|
|
438
|
+
}
|
|
439
|
+
const dry = await upgrade({from: '0.0.15'}, {cwd: tmpDir});
|
|
440
|
+
expect(dry.data.agentDocs.status).toBe('current');
|
|
441
|
+
});
|
|
442
|
+
|
|
249
443
|
it('reports would-refresh on a dry run without writing (honors cwd)', async () => {
|
|
250
444
|
writePkg(tmpDir);
|
|
251
445
|
writeInstalledCore(tmpDir, '0.0.15');
|
|
@@ -29,6 +29,17 @@ describe('validate-data-token-ownership', () => {
|
|
|
29
29
|
}
|
|
30
30
|
});
|
|
31
31
|
|
|
32
|
+
it('reports prebuilt CSS availability without requiring a source compile step', async () => {
|
|
33
|
+
await expect(
|
|
34
|
+
run('const fill = "var(--color-data-categorical-blue)";'),
|
|
35
|
+
).rejects.toThrow(
|
|
36
|
+
/in prebuilt mode, loads @astryxdesign\/core\/astryx\.css/,
|
|
37
|
+
);
|
|
38
|
+
await expect(
|
|
39
|
+
run('.bar { fill: var(--color-data-categorical-blue); }', 'chart.css'),
|
|
40
|
+
).rejects.toThrow(/load @astryxdesign\/core\/astryx\.css in prebuilt mode/);
|
|
41
|
+
});
|
|
42
|
+
|
|
32
43
|
it('leaves fallbacks, dataVars access, and comments unchanged', async () => {
|
|
33
44
|
const source = `
|
|
34
45
|
// var(--color-data-categorical-green)
|
|
@@ -56,7 +56,7 @@ export default function validateDataTokenOwnership(file, api) {
|
|
|
56
56
|
ROOT_DATA_DECLARATION.test(file.source)
|
|
57
57
|
) {
|
|
58
58
|
throw new Error(
|
|
59
|
-
'This generated theme CSS still emits canonical data defaults at :root. Rebuild it with `astryx theme build`; defaults
|
|
59
|
+
'This generated theme CSS still emits canonical data defaults at :root. Rebuild it with `astryx theme build`; defaults come from source-compiled dataVars consumers or @astryxdesign/core/astryx.css in prebuilt mode.',
|
|
60
60
|
);
|
|
61
61
|
}
|
|
62
62
|
const uncommented = file.source.replace(CSS_COMMENT, comment =>
|
|
@@ -66,7 +66,7 @@ export default function validateDataTokenOwnership(file, api) {
|
|
|
66
66
|
if (cssMatch) {
|
|
67
67
|
const line = uncommented.slice(0, cssMatch.index).split('\n').length;
|
|
68
68
|
throw new Error(
|
|
69
|
-
`Raw var(${cssMatch[1]}) without a fallback at line ${line} needs
|
|
69
|
+
`Raw var(${cssMatch[1]}) without a fallback at line ${line} needs an availability check: load @astryxdesign/core/astryx.css in prebuilt mode, ensure a source-compiled dataVars consumer retains the group, or add an explicit fallback. CSS-capable code imports dataVars from @astryxdesign/core/theme/dataTokens.stylex.`,
|
|
70
70
|
);
|
|
71
71
|
}
|
|
72
72
|
return undefined;
|
|
@@ -95,7 +95,7 @@ export default function validateDataTokenOwnership(file, api) {
|
|
|
95
95
|
if (found) {
|
|
96
96
|
const {token, line} = found;
|
|
97
97
|
throw new Error(
|
|
98
|
-
`Direct var(${token})${line == null ? '' : ` at line ${line}`} needs manual migration: CSS-capable code imports dataVars from @astryxdesign/core/theme/dataTokens.stylex; Canvas and other non-CSS APIs use resolveThemeToken() or useTheme().token().`,
|
|
98
|
+
`Direct var(${token})${line == null ? '' : ` at line ${line}`} needs manual migration: CSS-capable code imports dataVars from @astryxdesign/core/theme/dataTokens.stylex and, in prebuilt mode, loads @astryxdesign/core/astryx.css; Canvas and other non-CSS APIs use resolveThemeToken() or useTheme().token().`,
|
|
99
99
|
);
|
|
100
100
|
}
|
|
101
101
|
return undefined;
|
|
@@ -20,6 +20,12 @@ export const docs = {
|
|
|
20
20
|
slots: {
|
|
21
21
|
kinds: {title: 'Reference', accepts: {kinds: ['namespace']}},
|
|
22
22
|
},
|
|
23
|
+
blocks: [
|
|
24
|
+
{
|
|
25
|
+
type: 'prose',
|
|
26
|
+
text: 'To run the whole CLI from your own command-line tool, with its arguments, folder, and command name, use the host entry: {@link generic:host-entry}.',
|
|
27
|
+
},
|
|
28
|
+
],
|
|
23
29
|
adopts: [
|
|
24
30
|
{
|
|
25
31
|
source: {group: 'cli/api', kinds: ['function', 'schema', 'enum']},
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file `astryx docs cli/host-entry`: run the CLI from a tool that carries it,
|
|
5
|
+
* through `@astryxdesign/cli/host` (spec AST-081 FR1,
|
|
6
|
+
* architecture:cli-surface INV30).
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** @type {import('@astryxdesign/cli/authoring').ReferenceDoc} */
|
|
10
|
+
export const docs = {
|
|
11
|
+
type: 'generic',
|
|
12
|
+
name: 'host-entry',
|
|
13
|
+
placement: {parent: 'namespace:cli', slot: 'guides', order: 15},
|
|
14
|
+
title: 'Host entry',
|
|
15
|
+
category: 'guide',
|
|
16
|
+
keywords: [
|
|
17
|
+
'host entry',
|
|
18
|
+
'runHostedCli',
|
|
19
|
+
'@astryxdesign/cli/host',
|
|
20
|
+
'carry the cli',
|
|
21
|
+
'embed the cli',
|
|
22
|
+
'programmatic run',
|
|
23
|
+
'package sets',
|
|
24
|
+
'cliCommand',
|
|
25
|
+
],
|
|
26
|
+
description:
|
|
27
|
+
'Run the Astryx CLI from your own command-line tool: the inputs `runHostedCli` takes, what it returns, and when the process ends instead.',
|
|
28
|
+
sections: [
|
|
29
|
+
{
|
|
30
|
+
id: 'start',
|
|
31
|
+
title: 'Start a run',
|
|
32
|
+
content: [
|
|
33
|
+
{
|
|
34
|
+
type: 'prose',
|
|
35
|
+
text: "A tool that carries the CLI for its own users starts one run per process with `runHostedCli` from `@astryxdesign/cli/host`. The run behaves as the CLI's own command does with the same arguments in the same folder, and the commands it prints start with your tool's command.",
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
type: 'code',
|
|
39
|
+
lang: 'javascript',
|
|
40
|
+
code: "import {runHostedCli} from '@astryxdesign/cli/host';\n\nconst {status} = await runHostedCli({\n argv: process.argv.slice(2),\n cwd: process.cwd(),\n cliCommand: 'acme astryx',\n});\nprocess.exitCode = status;",
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
id: 'options',
|
|
46
|
+
title: 'Options',
|
|
47
|
+
content: [
|
|
48
|
+
{
|
|
49
|
+
type: 'table',
|
|
50
|
+
headers: ['Option', 'Default', 'Meaning'],
|
|
51
|
+
rows: [
|
|
52
|
+
[
|
|
53
|
+
'`argv`',
|
|
54
|
+
'none',
|
|
55
|
+
'The command-line arguments, without the command name.',
|
|
56
|
+
],
|
|
57
|
+
[
|
|
58
|
+
'`cwd`',
|
|
59
|
+
"the process's working folder",
|
|
60
|
+
'The folder the run works in. It must exist.',
|
|
61
|
+
],
|
|
62
|
+
[
|
|
63
|
+
'`cliCommand`',
|
|
64
|
+
"the package manager's name",
|
|
65
|
+
'The command your users type, such as `acme astryx`: a non-blank single line of at most 120 characters, with no surrounding spaces.',
|
|
66
|
+
],
|
|
67
|
+
[
|
|
68
|
+
'`declinedProjectCli`',
|
|
69
|
+
'none',
|
|
70
|
+
"Why you did not run the project's own CLI, such as `untrusted`: a non-blank single line of at most 120 characters. That CLI then never runs.",
|
|
71
|
+
],
|
|
72
|
+
[
|
|
73
|
+
'`roots`',
|
|
74
|
+
'none',
|
|
75
|
+
'Your package sets, in order of preference: folders whose `node_modules` each hold a CLI, the Core of the same release, and integrations. A run never installs a release; it takes the release a project needs from the first set that holds it.',
|
|
76
|
+
],
|
|
77
|
+
[
|
|
78
|
+
'`integrations`',
|
|
79
|
+
'none',
|
|
80
|
+
'Integrations you approve for use outside a project, by package name.',
|
|
81
|
+
],
|
|
82
|
+
[
|
|
83
|
+
'`discoverSources`',
|
|
84
|
+
'none',
|
|
85
|
+
"Your own discover sources. `astryx discover` reports each as the host's.",
|
|
86
|
+
],
|
|
87
|
+
],
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
id: 'result',
|
|
93
|
+
title: 'Result and errors',
|
|
94
|
+
content: [
|
|
95
|
+
{
|
|
96
|
+
type: 'list',
|
|
97
|
+
style: 'unordered',
|
|
98
|
+
items: [
|
|
99
|
+
"It resolves with `{status, packages}`: the exit status the CLI's own command would exit with, and each package the run used, with its version and whether it came from the project or a package set.",
|
|
100
|
+
'When another release answers from one of your package sets through its own host entry, that entry runs in the same process with the same inputs, and the call resolves with its result.',
|
|
101
|
+
'It rejects with a `TypeError`, before anything runs, for an unknown option or an invalid value, and with an `Error` when a run already started in the process. Start each run in a new process.',
|
|
102
|
+
],
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
id: 'process-ends',
|
|
108
|
+
title: 'When the process ends instead',
|
|
109
|
+
content: [
|
|
110
|
+
{
|
|
111
|
+
type: 'prose',
|
|
112
|
+
text: "Like the CLI's own command, a run ends the process with its exit status, and the call never resolves, when it:",
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
type: 'list',
|
|
116
|
+
style: 'unordered',
|
|
117
|
+
items: [
|
|
118
|
+
'prints help or the version (`--help`, `-h`, `help`, `--version`, `-V`, `--version --json`);',
|
|
119
|
+
'rejects the command line, such as an unknown command or option;',
|
|
120
|
+
'reports an error it stops on, including every error in `--json` mode;',
|
|
121
|
+
'meets an unexpected error;',
|
|
122
|
+
"hands the run to another CLI's own command: the project's CLI when you pass no `declinedProjectCli`, or a package set whose CLI has no host entry.",
|
|
123
|
+
],
|
|
124
|
+
},
|
|
125
|
+
],
|
|
126
|
+
},
|
|
127
|
+
],
|
|
128
|
+
};
|
|
@@ -17,14 +17,14 @@ export const docs = {
|
|
|
17
17
|
"order": 20
|
|
18
18
|
},
|
|
19
19
|
"category": "foundations",
|
|
20
|
-
"description": "Colors for charts and graphs: one categorical accent per series, a neutral for labels and reference lines, and sequential ramps from 5 (darkest) to 1 (lightest) for ordered scales and heatmaps. Import dataVars from @astryxdesign/core/theme/dataTokens.stylex for CSS-capable code.
|
|
20
|
+
"description": "Colors for charts and graphs: one categorical accent per series, a neutral for labels and reference lines, and sequential ramps from 5 (darkest) to 1 (lightest) for ordered scales and heatmaps. Import dataVars from @astryxdesign/core/theme/dataTokens.stylex for CSS-capable code. Source compilation emits the complete 56-variable group when any member is retained and none for an unused graph. Prebuilt CSS consumers load @astryxdesign/core/astryx.css, which defines the complete group for the already-compiled dataVars entry.",
|
|
21
21
|
"sections": [
|
|
22
22
|
{
|
|
23
23
|
"title": "Data Visualization Tokens",
|
|
24
24
|
"content": [
|
|
25
25
|
{
|
|
26
26
|
"type": "prose",
|
|
27
|
-
"text": "Colors for charts and graphs: one categorical accent per series, a neutral for labels and reference lines, and sequential ramps from 5 (darkest) to 1 (lightest) for ordered scales and heatmaps. Import dataVars from @astryxdesign/core/theme/dataTokens.stylex for CSS-capable code.
|
|
27
|
+
"text": "Colors for charts and graphs: one categorical accent per series, a neutral for labels and reference lines, and sequential ramps from 5 (darkest) to 1 (lightest) for ordered scales and heatmaps. Import dataVars from @astryxdesign/core/theme/dataTokens.stylex for CSS-capable code. Source compilation emits the complete 56-variable group when any member is retained and none for an unused graph. Prebuilt CSS consumers load @astryxdesign/core/astryx.css, which defines the complete group for the already-compiled dataVars entry."
|
|
28
28
|
},
|
|
29
29
|
{
|
|
30
30
|
"type": "table",
|
|
@@ -44,7 +44,7 @@ export const docs = {
|
|
|
44
44
|
},
|
|
45
45
|
{
|
|
46
46
|
type: 'prose',
|
|
47
|
-
text: "By default this
|
|
47
|
+
text: "By default this writes the instructions to `AGENTS.md` (the tool-agnostic standard most agents read), in the project root: the nearest folder whose `package.json` declares an Astryx package, else the nearest with any `package.json`. The search stops at the repository root. In the home folder, or in a settings folder in it outside a project, init writes no agent docs: every folder of the home folder whose name starts with a dot (`~/.claude`, `~/.gemini`, `~/.codex`) is a settings folder, and such a folder itself never counts as a project, even with a `package.json`; a project below it with its own `package.json`, such as an agent worktree, is set up normally. Claude Code skips `AGENTS.md` when the project has a `CLAUDE.md` or `.claude/CLAUDE.md`, so init also writes them to that file, even when it imports `AGENTS.md`: Claude Code does not follow that import in a session started in a subfolder. When both files exist, root `CLAUDE.md` gets the copy and a copy in `.claude/CLAUDE.md` is removed, unless the project ignores `CLAUDE.md`, in which case a `.claude/CLAUDE.md` the project commits keeps a copy. Gemini CLI reads only `GEMINI.md`, so init adds a one-line import of `AGENTS.md` there, unless `GEMINI.md` already imports it. `upgrade` keeps the copies in sync. The block between the Astryx markers belongs to Astryx: init and `upgrade` write, refresh, and remove it whatever the project's ignore rules or generated markers say, and never change the text around it. To target a specific tool's file instead:",
|
|
48
48
|
},
|
|
49
49
|
{
|
|
50
50
|
type: 'code',
|
|
@@ -55,7 +55,11 @@ astryx init --features agents --agent cursor # .cursorrules if present, else
|
|
|
55
55
|
astryx init --features agents --agent codex # AGENTS.md (Copilot, Codex, etc.)
|
|
56
56
|
astryx init --features agents --agent hermes # .hermes.md or HERMES.md if present, else AGENTS.md
|
|
57
57
|
astryx init --features agents --agent muse # AGENTS.md (Muse)
|
|
58
|
-
astryx init --features agents --agent all # every agent file present, else AGENTS.md and .claude/CLAUDE.md`,
|
|
58
|
+
astryx init --features agents --agent all # every agent file present except GEMINI.md, else AGENTS.md and .claude/CLAUDE.md`,
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
type: 'prose',
|
|
62
|
+
text: 'With `--agent all`, `GEMINI.md` keeps its one-line import of `AGENTS.md`. With `--agent claude` or `--agent all`, as by default, when `CLAUDE.md` gets the instructions, `.claude/CLAUDE.md` gets none and a copy already there is removed, unless the project ignores `CLAUDE.md`: a fresh clone does not have it, so a `.claude/CLAUDE.md` the project commits gets a copy too, with `--agent claude` and `--agent all` alike. `init --remove-agents` removes them at the project root and in the folder it runs in.',
|
|
59
63
|
},
|
|
60
64
|
{
|
|
61
65
|
type: 'prose',
|
|
@@ -79,9 +79,9 @@ declare const eventSchema: z.ZodObject<{
|
|
|
79
79
|
none: "none";
|
|
80
80
|
component: "component";
|
|
81
81
|
hook: "hook";
|
|
82
|
+
theme: "theme";
|
|
82
83
|
doc: "doc";
|
|
83
84
|
template: "template";
|
|
84
|
-
theme: "theme";
|
|
85
85
|
integration: "integration";
|
|
86
86
|
migration: "migration";
|
|
87
87
|
mixed: "mixed";
|
|
@@ -53,84 +53,13 @@ if (!isNodeVersionSupported(process.versions.node)) {
|
|
|
53
53
|
process.exit(1);
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
// Global mode:
|
|
57
|
-
// not this copy,
|
|
58
|
-
// astryx.config, integrations, or Core) is loaded
|
|
59
|
-
//
|
|
60
|
-
|
|
61
|
-
await
|
|
56
|
+
// Global mode: the run chooses the release that answers this folder and, when
|
|
57
|
+
// it is not this copy, hands the run to it before anything the project
|
|
58
|
+
// provides (its astryx.config, integrations, or Core) is loaded; only then
|
|
59
|
+
// does it load and dispatch the command. See clients/cli/run.mjs,
|
|
60
|
+
// foundation/release/handoff.mjs, and spec AST-081 FR2 and FR9.
|
|
61
|
+
const {runCli} = await importSrc('run.mjs');
|
|
62
|
+
await runCli({
|
|
62
63
|
cliRoot: join(binDir, '..', '..', '..'),
|
|
63
64
|
argv: process.argv.slice(2),
|
|
64
65
|
});
|
|
65
|
-
|
|
66
|
-
// Imports that transitively load `styleText` must happen AFTER the gate above,
|
|
67
|
-
// so they are dynamically imported here rather than at the top of the module.
|
|
68
|
-
const {
|
|
69
|
-
program,
|
|
70
|
-
loadProjectDebugHandler,
|
|
71
|
-
loadProjectForHelp,
|
|
72
|
-
handleVersionJsonPreflight,
|
|
73
|
-
} = await importSrc('index.mjs');
|
|
74
|
-
const {isJsonMode, toErrorEnvelope} = await importSrc('../../foundation/response/json.mjs');
|
|
75
|
-
const {handleCommanderError} = await importSrc('lib/json-shim.mjs');
|
|
76
|
-
const {setOutcome} = await importSrc('../../foundation/debug/index.mjs');
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Top-level error boundary (contract guarantee #4): an uncaught throw must
|
|
80
|
-
* never reach a --json consumer as a raw stack trace. If we're in JSON mode,
|
|
81
|
-
* convert it to the contract's error envelope on stdout and exit 1; otherwise
|
|
82
|
-
* preserve the normal human-facing behavior.
|
|
83
|
-
*
|
|
84
|
-
* We detect JSON mode two ways: the global flag (set once root options are
|
|
85
|
-
* parsed) and a raw argv check, since a throw can occur during parsing/command
|
|
86
|
-
* load — before the preAction hook engages the flag.
|
|
87
|
-
*/
|
|
88
|
-
function inJsonMode() {
|
|
89
|
-
return isJsonMode() || process.argv.slice(2).includes('--json');
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/** @param {unknown} err */
|
|
93
|
-
function handleFatal(err) {
|
|
94
|
-
// CommanderError (parse errors, --help, unknown command) routes
|
|
95
|
-
// through the JSON shim so that a --json consumer always gets a
|
|
96
|
-
// valid envelope and the right exit code. handleCommanderError
|
|
97
|
-
// calls process.exit when it owns the error.
|
|
98
|
-
if (handleCommanderError(err)) return;
|
|
99
|
-
|
|
100
|
-
// Anything still here is an uncaught throw or an unhandled rejection —
|
|
101
|
-
// a bug rather than a user error, and the class of failure most worth
|
|
102
|
-
// having a record of.
|
|
103
|
-
setOutcome('fatal', {exitCode: 1, error: err});
|
|
104
|
-
|
|
105
|
-
if (inJsonMode()) {
|
|
106
|
-
// Only emit if a command didn't already produce an envelope.
|
|
107
|
-
if (!process.__xdsJsonHandled) {
|
|
108
|
-
process.__xdsJsonHandled = true;
|
|
109
|
-
console.log(JSON.stringify(toErrorEnvelope(err), null, 2));
|
|
110
|
-
}
|
|
111
|
-
process.exit(1);
|
|
112
|
-
}
|
|
113
|
-
// Human mode: preserve Commander/Node default-ish behavior.
|
|
114
|
-
console.error(err instanceof Error ? err.stack || err.message : String(err));
|
|
115
|
-
process.exit(1);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
process.on('unhandledRejection', handleFatal);
|
|
119
|
-
process.on('uncaughtException', handleFatal);
|
|
120
|
-
|
|
121
|
-
// Pick up the project's `debug` function before parsing, so parse errors and
|
|
122
|
-
// `--help` — which short-circuit before any hook runs — are reported too.
|
|
123
|
-
await loadProjectDebugHandler();
|
|
124
|
-
// Help prints its commands while Commander parses, so a help run reads the
|
|
125
|
-
// project's declared `cliCommand` here.
|
|
126
|
-
await loadProjectForHelp();
|
|
127
|
-
|
|
128
|
-
// `--version --json` answers and exits without Commander, so it runs here —
|
|
129
|
-
// after the handler exists, or the run would go unrecorded.
|
|
130
|
-
handleVersionJsonPreflight();
|
|
131
|
-
|
|
132
|
-
try {
|
|
133
|
-
await program.parseAsync(process.argv);
|
|
134
|
-
} catch (err) {
|
|
135
|
-
handleFatal(err);
|
|
136
|
-
}
|