@chemx/starter-kit 26.10.29-360 → 26.11.15-614

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.
Files changed (103) hide show
  1. package/README.md +106 -433
  2. package/cli/audit/ratchet.js +52 -7
  3. package/cli/commands/cmd-router.js +3 -1
  4. package/cli/commands-schema-commit.js +3 -2
  5. package/cli/commands-schema-search.js +1 -0
  6. package/cli/commands-schema-team.js +11 -4
  7. package/cli/commit/commit-args.js +5 -4
  8. package/cli/commit/commit-hunks.js +108 -0
  9. package/cli/commit/commit-run.js +33 -2
  10. package/cli/config/index.js +28 -0
  11. package/cli/docs-check/command-tree.js +1 -1
  12. package/cli/generator-indexer.js +3 -2
  13. package/cli/index-seed.js +1 -0
  14. package/cli/lang/detect.js +189 -0
  15. package/cli/lang/legacy-extensions.js +9 -0
  16. package/cli/lang/records/c.js +53 -0
  17. package/cli/lang/records/cpp.js +76 -0
  18. package/cli/lang/records/csharp.js +59 -0
  19. package/cli/lang/records/go.js +47 -0
  20. package/cli/lang/records/index.js +18 -0
  21. package/cli/lang/records/java.js +55 -0
  22. package/cli/lang/records/javascript.js +50 -0
  23. package/cli/lang/records/kotlin.js +48 -0
  24. package/cli/lang/records/php.js +54 -0
  25. package/cli/lang/records/python.js +50 -0
  26. package/cli/lang/records/rust.js +47 -0
  27. package/cli/lang/records/svelte.js +45 -0
  28. package/cli/lang/records/typescript.js +66 -0
  29. package/cli/lang/records/vue.js +45 -0
  30. package/cli/lang/registry.js +73 -0
  31. package/cli/lang/rollout.js +114 -0
  32. package/cli/lang/schema.js +288 -0
  33. package/cli/lang/static-table.js +71 -0
  34. package/cli/lang/types.d.ts +142 -0
  35. package/cli/lang/vocab.js +90 -0
  36. package/cli/languages.js +50 -88
  37. package/cli/search-args.js +1 -1
  38. package/cli/search-ast-module.js +26 -3
  39. package/cli/search-ast.js +4 -2
  40. package/cli/search-commands.js +44 -0
  41. package/cli/search-db.js +1 -0
  42. package/cli/search-index-meta.js +23 -7
  43. package/cli/search-index-write.js +5 -2
  44. package/cli/search-literal.js +24 -6
  45. package/cli/search-queries.js +19 -0
  46. package/cli/search-schema-ddl.js +11 -0
  47. package/cli/search-schema.js +6 -3
  48. package/cli/search-sync-paths.js +4 -3
  49. package/cli/search-sync-rows.js +2 -2
  50. package/cli/search-sync.js +2 -0
  51. package/cli/search.js +8 -3
  52. package/cli/team/check-delivery.js +115 -0
  53. package/cli/team/check-drainer.js +288 -0
  54. package/cli/team/check-executor.js +106 -0
  55. package/cli/team/check-fingerprint.js +105 -0
  56. package/cli/team/check-queue.js +114 -0
  57. package/cli/team/help/card-rows.js +2 -1
  58. package/cli/team/help/check.js +6 -0
  59. package/cli/team/team-commands-check.js +142 -0
  60. package/cli/team/team-commands.js +6 -4
  61. package/cli/team/team-db-feed.js +6 -0
  62. package/cli/team/team-db-task-helpers.js +9 -6
  63. package/cli/team/team-dispatch-prompts.js +10 -1
  64. package/cli/team/team-dispatch-select.js +1 -0
  65. package/cli/team/team-dispatch-v2.js +1 -0
  66. package/cli/team/team-dispatch.js +3 -1
  67. package/cli/team/team-help-golden.json +20 -5
  68. package/cli/team/team-schema-checks.js +46 -0
  69. package/cli/team/team-schema.js +2 -0
  70. package/cli/ui-api-index.js +39 -0
  71. package/cli/ui-handlers.js +17 -20
  72. package/cli/ui-html.js +17 -4
  73. package/cli/ui-index.html +298 -107
  74. package/cli/ui-page/components/00-core.css +10 -0
  75. package/cli/ui-page/components/00-core.js +78 -0
  76. package/cli/ui-page/components/xo-agent-profile.js +6 -0
  77. package/cli/ui-page/components/xo-avatar.js +17 -0
  78. package/cli/ui-page/components/xo-composer.js +5 -0
  79. package/cli/ui-page/components/xo-notification-bell.js +5 -0
  80. package/cli/ui-page/components/xo-post-card.js +20 -0
  81. package/cli/ui-page/components/xo-post-permalink.js +5 -0
  82. package/cli/ui-page/components/xo-post-thread.js +5 -0
  83. package/cli/ui-page/components/xo-timeline.js +52 -0
  84. package/cli/ui-page/components/xo-today-card.js +5 -0
  85. package/cli/ui-paging-agents.js +34 -0
  86. package/cli/ui-paging-feed.js +14 -0
  87. package/cli/ui-paging-task-where.js +63 -0
  88. package/cli/ui-paging-tasks.js +68 -0
  89. package/cli/ui-paging.js +35 -0
  90. package/cli/ui-server-routes.js +5 -4
  91. package/cli/ui-server.js +12 -0
  92. package/cli/ui-social-digest.js +12 -0
  93. package/cli/ui-social-feed.js +12 -0
  94. package/cli/ui-social-mentions.js +12 -0
  95. package/cli/ui-social-notify.js +12 -0
  96. package/cli/ui-social-posts.js +12 -0
  97. package/cli/ui-social-profile.js +12 -0
  98. package/cli/ui-social-routes.js +21 -0
  99. package/cli/ui-social-threads.js +12 -0
  100. package/package.json +2 -2
  101. package/scripts/package-json-guard.mjs +35 -0
  102. package/scripts/package-json-guard.spec.mjs +50 -0
  103. package/scripts/publish-both.mjs +25 -7
@@ -0,0 +1,50 @@
1
+ /** Python language record; see design spec 4.2 and 5. */
2
+ export default Object.freeze({
3
+ id: 'python',
4
+ name: 'Python',
5
+ version: 1,
6
+ files: {
7
+ extensions: ['.py'],
8
+ vendorDirs: [{ name: 'venv', when: 'always' }, { name: '__pycache__', when: 'always' }],
9
+ tests: { names: ['test_*.py', '*_test.py'], dirs: ['tests'] }
10
+ },
11
+ syntax: {
12
+ lineComment: ['#'],
13
+ blockComment: [],
14
+ docString: [{ open: '"""', close: '"""' }],
15
+ strings: [
16
+ { open: '"', close: '"', escape: '\\' },
17
+ { open: '\'', close: '\'', escape: '\\' },
18
+ { open: '"""', close: '"""', escape: '\\', multiline: true }
19
+ ],
20
+ blockStyle: 'indent',
21
+ blockOpeners: [':'],
22
+ keywords: ['def', 'class', 'import', 'from', 'return', 'async', 'await'],
23
+ qualifier: '.'
24
+ },
25
+ parse: { grammar: 'python', queries: 'python', grammarStatus: 'vetted', errorPolicy: 'report' },
26
+ engines: {
27
+ index: 'legacy-polyglot',
28
+ outline: 'legacy-polyglot',
29
+ symbol: 'legacy-polyglot',
30
+ logic: 'text',
31
+ audit: 'text',
32
+ editGate: 'text'
33
+ },
34
+ stages: { source: 'on', index: 'text', outline: 'text', imports: 'text' },
35
+ symbols: { exportRule: { kind: 'name-not-prefix', prefix: '_' } },
36
+ imports: { resolver: 'python' },
37
+ layout: {},
38
+ ecosystems: ['python'],
39
+ audit: { analysisRevision: 1, passes: ['text'] },
40
+ notApplicable: {
41
+ forge: 'JS framework feature; not available outside the JS family',
42
+ heal: 'JS framework feature; not available outside the JS family',
43
+ explode: 'JS framework feature; not available outside the JS family',
44
+ generate: 'JS framework feature; not available outside the JS family',
45
+ capsule: 'JS framework feature; not available outside the JS family',
46
+ scaffold: 'JS framework feature; not available outside the JS family',
47
+ lanes: 'JS framework feature; not available outside the JS family',
48
+ mutators: 'JS framework feature; not available outside the JS family'
49
+ }
50
+ });
@@ -0,0 +1,47 @@
1
+ /** Rust language record; see design spec 4.2 and 5. */
2
+ export default Object.freeze({
3
+ id: 'rust',
4
+ name: 'Rust',
5
+ version: 1,
6
+ files: {
7
+ extensions: ['.rs'],
8
+ vendorDirs: [{ name: 'target', when: 'project-root' }],
9
+ tests: { names: ['*_test.rs'], dirs: ['tests'] }
10
+ },
11
+ syntax: {
12
+ lineComment: ['//'],
13
+ blockComment: [{ open: '/*', close: '*/', nests: true }],
14
+ strings: [
15
+ { open: '"', close: '"', escape: '\\' },
16
+ { open: 'r#"', close: '"#', escape: null, raw: true, multiline: true }
17
+ ],
18
+ blockStyle: 'brace',
19
+ keywords: ['fn', 'struct', 'enum', 'trait', 'impl', 'mod', 'use', 'pub', 'let'],
20
+ qualifier: '::'
21
+ },
22
+ parse: { grammar: 'rust', queries: 'rust', grammarStatus: 'vetted', errorPolicy: 'report' },
23
+ engines: {
24
+ index: 'legacy-polyglot',
25
+ outline: 'legacy-polyglot',
26
+ symbol: 'legacy-polyglot',
27
+ logic: 'text',
28
+ audit: 'text',
29
+ editGate: 'text'
30
+ },
31
+ stages: { source: 'on', index: 'text', outline: 'text', imports: 'text' },
32
+ symbols: { exportRule: { kind: 'modifier', anyOf: ['pub'], default: false } },
33
+ imports: { resolver: 'rust-crate', normalize: 'rust-use-tree' },
34
+ layout: {},
35
+ ecosystems: ['cargo'],
36
+ audit: { analysisRevision: 1, passes: ['text'] },
37
+ notApplicable: {
38
+ forge: 'JS framework feature; not available outside the JS family',
39
+ heal: 'JS framework feature; not available outside the JS family',
40
+ explode: 'JS framework feature; not available outside the JS family',
41
+ generate: 'JS framework feature; not available outside the JS family',
42
+ capsule: 'JS framework feature; not available outside the JS family',
43
+ scaffold: 'JS framework feature; not available outside the JS family',
44
+ lanes: 'JS framework feature; not available outside the JS family',
45
+ mutators: 'JS framework feature; not available outside the JS family'
46
+ }
47
+ });
@@ -0,0 +1,45 @@
1
+ /** Svelte language record; see design spec 4.2 and 5. */
2
+ export default Object.freeze({
3
+ id: 'svelte',
4
+ name: 'Svelte',
5
+ version: 1,
6
+ files: {
7
+ extensions: ['.svelte'],
8
+ vendorDirs: [{ name: 'node_modules', when: 'always' }],
9
+ tests: {
10
+ names: ['*.test.js', '*.spec.js', '*.test.ts', '*.spec.ts'],
11
+ dirs: ['tests', '__tests__']
12
+ }
13
+ },
14
+ syntax: {
15
+ lineComment: ['//'],
16
+ blockComment: [{ open: '/*', close: '*/' }],
17
+ blockStyle: 'brace',
18
+ qualifier: '.',
19
+ strings: [
20
+ { open: '"', close: '"', escape: '\\' },
21
+ { open: '\'', close: '\'', escape: '\\' },
22
+ { open: '`', close: '`', escape: '\\', multiline: true }
23
+ ],
24
+ keywords: ['function', 'class', 'const', 'let', 'var', 'import', 'export', 'return', 'async', 'await']
25
+ },
26
+ parse: { grammarStatus: 'none', errorPolicy: 'report' },
27
+ engines: {
28
+ index: 'sfc',
29
+ outline: 'sfc',
30
+ symbol: 'sfc',
31
+ logic: 'sfc',
32
+ audit: 'babel',
33
+ editGate: 'babel'
34
+ },
35
+ stages: { source: 'on', index: 'on', outline: 'on', imports: 'on' },
36
+ symbols: { exportRule: { kind: 'capture' } },
37
+ imports: { resolver: 'js' },
38
+ layout: { viewMarkup: true },
39
+ ecosystems: ['npm'],
40
+ audit: {
41
+ analysisRevision: 1,
42
+ passes: ['text', 'structure', 'complexity', 'errors', 'security', 'logging', 'tests', 'env']
43
+ },
44
+ notApplicable: {}
45
+ });
@@ -0,0 +1,66 @@
1
+ /** TypeScript language record; see design spec 4.2 and 5. */
2
+ export default Object.freeze({
3
+ id: 'typescript',
4
+ name: 'TypeScript',
5
+ version: 1,
6
+ files: {
7
+ extensions: ['.ts', '.tsx'],
8
+ vendorDirs: [{ name: 'node_modules', when: 'always' }],
9
+ tests: {
10
+ names: ['*.test.ts', '*.spec.ts', '*.test.tsx', '*.spec.tsx'],
11
+ dirs: ['tests', '__tests__']
12
+ },
13
+ declaration: ['*.d.ts']
14
+ },
15
+ syntax: {
16
+ lineComment: ['//'],
17
+ blockComment: [{ open: '/*', close: '*/' }],
18
+ blockStyle: 'brace',
19
+ qualifier: '.',
20
+ strings: [
21
+ { open: '"', close: '"', escape: '\\' },
22
+ { open: '\'', close: '\'', escape: '\\' },
23
+ { open: '`', close: '`', escape: '\\', multiline: true }
24
+ ],
25
+ keywords: [
26
+ 'function',
27
+ 'class',
28
+ 'const',
29
+ 'let',
30
+ 'var',
31
+ 'import',
32
+ 'export',
33
+ 'return',
34
+ 'async',
35
+ 'await',
36
+ 'interface',
37
+ 'type',
38
+ 'enum',
39
+ 'namespace'
40
+ ]
41
+ },
42
+ parse: {
43
+ grammar: { '.ts': 'typescript', '.tsx': 'tsx' },
44
+ queries: 'typescript',
45
+ grammarStatus: 'vetted',
46
+ errorPolicy: 'report'
47
+ },
48
+ engines: {
49
+ index: 'babel',
50
+ outline: 'babel',
51
+ symbol: 'babel',
52
+ logic: 'babel',
53
+ audit: 'babel',
54
+ editGate: 'babel'
55
+ },
56
+ stages: { source: 'on', index: 'on', outline: 'on', imports: 'on' },
57
+ symbols: { exportRule: { kind: 'capture' } },
58
+ imports: { resolver: 'js' },
59
+ layout: {},
60
+ ecosystems: ['npm'],
61
+ audit: {
62
+ analysisRevision: 1,
63
+ passes: ['text', 'structure', 'complexity', 'errors', 'security', 'logging', 'tests', 'env']
64
+ },
65
+ notApplicable: {}
66
+ });
@@ -0,0 +1,45 @@
1
+ /** Vue SFC language record; see design spec 4.2 and 5. */
2
+ export default Object.freeze({
3
+ id: 'vue',
4
+ name: 'Vue SFC',
5
+ version: 1,
6
+ files: {
7
+ extensions: ['.vue'],
8
+ vendorDirs: [{ name: 'node_modules', when: 'always' }],
9
+ tests: {
10
+ names: ['*.test.js', '*.spec.js', '*.test.ts', '*.spec.ts'],
11
+ dirs: ['tests', '__tests__']
12
+ }
13
+ },
14
+ syntax: {
15
+ lineComment: ['//'],
16
+ blockComment: [{ open: '/*', close: '*/' }],
17
+ blockStyle: 'brace',
18
+ qualifier: '.',
19
+ strings: [
20
+ { open: '"', close: '"', escape: '\\' },
21
+ { open: '\'', close: '\'', escape: '\\' },
22
+ { open: '`', close: '`', escape: '\\', multiline: true }
23
+ ],
24
+ keywords: ['function', 'class', 'const', 'let', 'var', 'import', 'export', 'return', 'async', 'await']
25
+ },
26
+ parse: { grammarStatus: 'none', errorPolicy: 'report' },
27
+ engines: {
28
+ index: 'sfc',
29
+ outline: 'sfc',
30
+ symbol: 'sfc',
31
+ logic: 'sfc',
32
+ audit: 'babel',
33
+ editGate: 'babel'
34
+ },
35
+ stages: { source: 'on', index: 'on', outline: 'on', imports: 'on' },
36
+ symbols: { exportRule: { kind: 'capture' } },
37
+ imports: { resolver: 'js' },
38
+ layout: { viewMarkup: true },
39
+ ecosystems: ['npm'],
40
+ audit: {
41
+ analysisRevision: 1,
42
+ passes: ['text', 'structure', 'complexity', 'errors', 'security', 'logging', 'tests', 'env']
43
+ },
44
+ notApplicable: {}
45
+ });
@@ -0,0 +1,73 @@
1
+ /**
2
+ * The language registry (design spec 4.1, 4.2): the shipped records plus any a spec registers
3
+ * through the test seam. Guard-safe: it imports records, the schema and the static table only.
4
+ * Consumers that cache derived state (the languages.js facade) subscribe with onRegistryChange.
5
+ */
6
+ import { LANGUAGE_RECORDS } from './records/index.js';
7
+ import { assertLanguageRecord } from './schema.js';
8
+ import { STATIC_TABLE, buildTable } from './static-table.js';
9
+
10
+ const testRecords = new Map();
11
+ const listeners = new Set();
12
+ let current = null;
13
+
14
+ /** Shipped records with test overrides in place (same id), then new test ids in registration order. */
15
+ const compose = () => {
16
+ const isPristine = testRecords.size === 0;
17
+ const shipped = LANGUAGE_RECORDS.map((r) => testRecords.get(r.id) ?? r);
18
+ const shippedIds = new Set(LANGUAGE_RECORDS.map((r) => r.id));
19
+ const added = [...testRecords.values()].filter((r) => !shippedIds.has(r.id));
20
+ const records = Object.freeze([...shipped, ...added]);
21
+ const table = isPristine ? STATIC_TABLE : buildTable(records);
22
+ return { records, table, byId: new Map(records.map((r) => [r.id, r])) };
23
+ };
24
+
25
+ const state = () => {
26
+ current ??= compose();
27
+ return current;
28
+ };
29
+
30
+ const changed = () => {
31
+ current = null;
32
+ listeners.forEach((fn) => fn());
33
+ };
34
+
35
+ /** Every registered record, in registration order. */
36
+ export const allLanguages = () => state().records;
37
+
38
+ /** The record for a language id, or null. */
39
+ export const getLanguage = (id) => state().byId.get(id) ?? null;
40
+
41
+ /** The extension table over the registered records (static-table.js shape). */
42
+ export const languageTable = () => state().table;
43
+
44
+ /** Records claiming an extension (matched lowercase); more than one means the extension is ambiguous. */
45
+ export const languagesForExtension = (ext) => {
46
+ const ids = state().table.byExtension.get(ext.toLowerCase()) ?? [];
47
+ return ids.map(getLanguage);
48
+ };
49
+
50
+ /** Calls `fn` after every registry change; returns the unsubscribe function. */
51
+ export const onRegistryChange = (fn) => {
52
+ listeners.add(fn);
53
+ return () => listeners.delete(fn);
54
+ };
55
+
56
+ /**
57
+ * Test seam: registers a schema-valid record for the current process, replacing a shipped record
58
+ * with the same id. Specs call resetTestLanguages() afterwards; nothing else may call this.
59
+ */
60
+ export const registerTestLanguage = (record) => {
61
+ assertLanguageRecord(record);
62
+ testRecords.set(record.id, record);
63
+ changed();
64
+ return record;
65
+ };
66
+
67
+ /** Test seam: drops every record registered with registerTestLanguage. */
68
+ export const resetTestLanguages = () => {
69
+ const hasTestRecords = testRecords.size > 0;
70
+ if (!hasTestRecords) return;
71
+ testRecords.clear();
72
+ changed();
73
+ };
@@ -0,0 +1,114 @@
1
+ /**
2
+ * Rollout stages (design spec 4.4). effectiveStage(lang, capability, root) resolves the record
3
+ * default, then `.chemxrc` languages, then CHEMX_LANG_STAGE (and withStages overrides in specs),
4
+ * then the kill switch CHEMX_LANG_ENGINE=legacy, which restores the pre-program path.
5
+ * With no config the result is the record default, which is today's behavior.
6
+ */
7
+ import { getLanguage } from './registry.js';
8
+ import { CAPABILITIES, STAGES } from './vocab.js';
9
+ import { loadProjectConfig } from '../config/index.js';
10
+
11
+ const CONFIG_TTL_MS = 1000;
12
+ // Engines that already are today's path: the legacy kill switch leaves their stages alone.
13
+ const NEW_ENGINES = new Set(['tree-sitter', 'regex']);
14
+ const SLOT_FOR_CAPABILITY = { source: 'index', index: 'index', imports: 'index', outline: 'outline', editGate: 'editGate', audit: 'audit' };
15
+
16
+ const configCache = new Map();
17
+ const overrides = [];
18
+
19
+ /** Drops cached `.chemxrc` reads (specs, and callers that just rewrote the file). */
20
+ export const resetRolloutCache = () => configCache.clear();
21
+
22
+ const languagesConfig = (root) => {
23
+ const cached = configCache.get(root);
24
+ const isFresh = cached && Date.now() - cached.at < CONFIG_TTL_MS;
25
+ if (isFresh) return cached.value;
26
+ let value;
27
+ try {
28
+ value = loadProjectConfig(root).languages;
29
+ } catch {
30
+ value = null;
31
+ }
32
+ configCache.set(root, { at: Date.now(), value });
33
+ return value;
34
+ };
35
+
36
+ /** Parses "lang:cap=stage" entries separated by commas or whitespace; malformed entries are skipped. */
37
+ const parseEnvStages = (text = '') => {
38
+ const entries = [];
39
+ for (const part of text.split(/[\s,]+/)) {
40
+ const match = /^([a-z][a-z0-9]*):([A-Za-z]+)=([a-z]+)$/.exec(part);
41
+ const isValid = match && CAPABILITIES.includes(match[2]) && STAGES.includes(match[3]);
42
+ if (isValid) entries.push({ lang: match[1], cap: match[2], stage: match[3] });
43
+ }
44
+ return entries;
45
+ };
46
+
47
+ // requireGrammars means a vetted grammar; an experimental one does not count.
48
+ const hasGrammar = (record) => record.parse.grammarStatus === 'vetted';
49
+
50
+ const isGrammarRequired = (config, id) => config.requireGrammars === true || config.requireGrammars.includes(id);
51
+
52
+ const clampLegacy = (record, capability, stage) => {
53
+ const slot = SLOT_FOR_CAPABILITY[capability];
54
+ const isNewEngine = NEW_ENGINES.has(record.engines[slot]);
55
+ const isRolledOut = stage === 'shadow' || stage === 'on';
56
+ return isNewEngine && isRolledOut ? 'text' : stage;
57
+ };
58
+
59
+ /** The `.chemxrc` layer: configured stage, then requireGrammars, then disable. */
60
+ const applyConfig = (record, capability, base, config) => {
61
+ if (!config) return base;
62
+ if (config.disable.includes(record.id)) return 'off';
63
+ const stage = config.stages[record.id]?.[capability] ?? base;
64
+ const isRolledOut = stage === 'shadow' || stage === 'on';
65
+ const isMissingGrammar = isGrammarRequired(config, record.id) && !hasGrammar(record);
66
+ return isRolledOut && isMissingGrammar ? 'text' : stage;
67
+ };
68
+
69
+ const overrideFor = (lang, capability) => {
70
+ for (let i = overrides.length - 1; i >= 0; i--) {
71
+ const hit = overrides[i][`${lang}:${capability}`] ?? overrides[i][`${lang}:*`];
72
+ if (hit) return hit;
73
+ }
74
+ return null;
75
+ };
76
+
77
+ /** The stage a capability of a language runs at for a project root: 'off' | 'text' | 'shadow' | 'on'. */
78
+ export const effectiveStage = (lang, capability, root = process.cwd()) => {
79
+ const record = getLanguage(lang);
80
+ if (!record) return 'off';
81
+ const base = record.stages[capability] ?? 'off';
82
+ const isKillSwitchOn = process.env.CHEMX_LANG_ENGINE === 'legacy';
83
+ if (isKillSwitchOn) return clampLegacy(record, capability, base);
84
+
85
+ const configured = applyConfig(record, capability, base, languagesConfig(root));
86
+ const fromEnv = parseEnvStages(process.env.CHEMX_LANG_STAGE).findLast((e) => e.lang === lang && e.cap === capability);
87
+ return overrideFor(lang, capability) ?? fromEnv?.stage ?? configured;
88
+ };
89
+
90
+ /** True when the new engine should also run beside today's output and log diffs (`.chemxrc` languages.shadow or CHEMX_LANG_SHADOW=1). */
91
+ export const isShadowLogging = (root = process.cwd()) => process.env.CHEMX_LANG_SHADOW === '1' || Boolean(languagesConfig(root)?.shadow);
92
+
93
+ /**
94
+ * Test helper: forces stages, keyed "lang:capability" or "lang:*". With a callback the override
95
+ * lasts for the call (sync or async) and its result is returned; without one it returns a restore function.
96
+ */
97
+ export const withStages = (map, fn) => {
98
+ overrides.push(map);
99
+ const restore = () => {
100
+ const index = overrides.indexOf(map);
101
+ const isActive = index !== -1;
102
+ if (isActive) overrides.splice(index, 1);
103
+ };
104
+ if (!fn) return restore;
105
+ let result;
106
+ try {
107
+ result = fn();
108
+ } catch (error) {
109
+ restore();
110
+ throw error;
111
+ }
112
+ const isThenable = typeof result?.then === 'function';
113
+ return isThenable ? result.finally(restore) : (restore(), result);
114
+ };