Skip to content

Commit 7633386

Browse files
authored
Merge pull request anomalyco#878 from affaan-m/feat/install-catalog-project-config
feat: add install catalog and project config autodetection
2 parents cc60bf6 + b4296c7 commit 7633386

11 files changed

Lines changed: 496 additions & 6 deletions

File tree

‎scripts/catalog.js‎

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
#!/usr/bin/env node
2+
3+
const {
4+
getInstallComponent,
5+
listInstallComponents,
6+
listInstallProfiles,
7+
} = require('./lib/install-manifests');
8+
9+
const FAMILY_ALIASES = Object.freeze({
10+
baseline: 'baseline',
11+
baselines: 'baseline',
12+
language: 'language',
13+
languages: 'language',
14+
lang: 'language',
15+
framework: 'framework',
16+
frameworks: 'framework',
17+
capability: 'capability',
18+
capabilities: 'capability',
19+
agent: 'agent',
20+
agents: 'agent',
21+
skill: 'skill',
22+
skills: 'skill',
23+
});
24+
25+
function showHelp(exitCode = 0) {
26+
console.log(`
27+
Discover ECC install components and profiles
28+
29+
Usage:
30+
node scripts/catalog.js profiles [--json]
31+
node scripts/catalog.js components [--family <family>] [--target <target>] [--json]
32+
node scripts/catalog.js show <component-id> [--json]
33+
34+
Examples:
35+
node scripts/catalog.js profiles
36+
node scripts/catalog.js components --family language
37+
node scripts/catalog.js show framework:nextjs
38+
`);
39+
40+
process.exit(exitCode);
41+
}
42+
43+
function normalizeFamily(value) {
44+
if (!value) {
45+
return null;
46+
}
47+
48+
const normalized = String(value).trim().toLowerCase();
49+
return FAMILY_ALIASES[normalized] || normalized;
50+
}
51+
52+
function parseArgs(argv) {
53+
const args = argv.slice(2);
54+
const parsed = {
55+
command: null,
56+
componentId: null,
57+
family: null,
58+
target: null,
59+
json: false,
60+
help: false,
61+
};
62+
63+
if (args.length === 0 || args[0] === '--help' || args[0] === '-h') {
64+
parsed.help = true;
65+
return parsed;
66+
}
67+
68+
parsed.command = args[0];
69+
70+
for (let index = 1; index < args.length; index += 1) {
71+
const arg = args[index];
72+
73+
if (arg === '--help' || arg === '-h') {
74+
parsed.help = true;
75+
} else if (arg === '--json') {
76+
parsed.json = true;
77+
} else if (arg === '--family') {
78+
if (!args[index + 1]) {
79+
throw new Error('Missing value for --family');
80+
}
81+
parsed.family = normalizeFamily(args[index + 1]);
82+
index += 1;
83+
} else if (arg === '--target') {
84+
if (!args[index + 1]) {
85+
throw new Error('Missing value for --target');
86+
}
87+
parsed.target = args[index + 1];
88+
index += 1;
89+
} else if (parsed.command === 'show' && !parsed.componentId) {
90+
parsed.componentId = arg;
91+
} else {
92+
throw new Error(`Unknown argument: ${arg}`);
93+
}
94+
}
95+
96+
return parsed;
97+
}
98+
99+
function printProfiles(profiles) {
100+
console.log('Install profiles:\n');
101+
for (const profile of profiles) {
102+
console.log(`- ${profile.id} (${profile.moduleCount} modules)`);
103+
console.log(` ${profile.description}`);
104+
}
105+
}
106+
107+
function printComponents(components) {
108+
console.log('Install components:\n');
109+
for (const component of components) {
110+
console.log(`- ${component.id} [${component.family}]`);
111+
console.log(` targets=${component.targets.join(', ')} modules=${component.moduleIds.join(', ')}`);
112+
console.log(` ${component.description}`);
113+
}
114+
}
115+
116+
function printComponent(component) {
117+
console.log(`Install component: ${component.id}\n`);
118+
console.log(`Family: ${component.family}`);
119+
console.log(`Targets: ${component.targets.join(', ')}`);
120+
console.log(`Modules: ${component.moduleIds.join(', ')}`);
121+
console.log(`Description: ${component.description}`);
122+
123+
if (component.modules.length > 0) {
124+
console.log('\nResolved modules:');
125+
for (const module of component.modules) {
126+
console.log(`- ${module.id} [${module.kind}]`);
127+
console.log(
128+
` targets=${module.targets.join(', ')} default=${module.defaultInstall} cost=${module.cost} stability=${module.stability}`
129+
);
130+
console.log(` ${module.description}`);
131+
}
132+
}
133+
}
134+
135+
function main() {
136+
try {
137+
const options = parseArgs(process.argv);
138+
139+
if (options.help) {
140+
showHelp(0);
141+
}
142+
143+
if (options.command === 'profiles') {
144+
const profiles = listInstallProfiles();
145+
if (options.json) {
146+
console.log(JSON.stringify({ profiles }, null, 2));
147+
} else {
148+
printProfiles(profiles);
149+
}
150+
return;
151+
}
152+
153+
if (options.command === 'components') {
154+
const components = listInstallComponents({
155+
family: options.family,
156+
target: options.target,
157+
});
158+
if (options.json) {
159+
console.log(JSON.stringify({ components }, null, 2));
160+
} else {
161+
printComponents(components);
162+
}
163+
return;
164+
}
165+
166+
if (options.command === 'show') {
167+
if (!options.componentId) {
168+
throw new Error('Catalog show requires an install component ID');
169+
}
170+
const component = getInstallComponent(options.componentId);
171+
if (options.json) {
172+
console.log(JSON.stringify(component, null, 2));
173+
} else {
174+
printComponent(component);
175+
}
176+
return;
177+
}
178+
179+
throw new Error(`Unknown catalog command: ${options.command}`);
180+
} catch (error) {
181+
console.error(`Error: ${error.message}`);
182+
process.exit(1);
183+
}
184+
}
185+
186+
main();

‎scripts/ecc.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ const COMMANDS = {
1313
script: 'install-plan.js',
1414
description: 'Inspect selective-install manifests and resolved plans',
1515
},
16+
catalog: {
17+
script: 'catalog.js',
18+
description: 'Discover install profiles and component IDs',
19+
},
1620
'install-plan': {
1721
script: 'install-plan.js',
1822
description: 'Alias for plan',
@@ -50,6 +54,7 @@ const COMMANDS = {
5054
const PRIMARY_COMMANDS = [
5155
'install',
5256
'plan',
57+
'catalog',
5358
'list-installed',
5459
'doctor',
5560
'repair',
@@ -79,6 +84,9 @@ Examples:
7984
ecc typescript
8085
ecc install --profile developer --target claude
8186
ecc plan --profile core --target cursor
87+
ecc catalog profiles
88+
ecc catalog components --family language
89+
ecc catalog show framework:nextjs
8290
ecc list-installed --json
8391
ecc doctor --target cursor
8492
ecc repair --dry-run

‎scripts/install-apply.js‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,18 @@ function main() {
100100
showHelp(0);
101101
}
102102

103-
const { loadInstallConfig } = require('./lib/install/config');
103+
const {
104+
findDefaultInstallConfigPath,
105+
loadInstallConfig,
106+
} = require('./lib/install/config');
104107
const { applyInstallPlan } = require('./lib/install-executor');
105108
const { createInstallPlanFromRequest } = require('./lib/install/runtime');
109+
const defaultConfigPath = options.configPath || options.languages.length > 0
110+
? null
111+
: findDefaultInstallConfigPath({ cwd: process.cwd() });
106112
const config = options.configPath
107113
? loadInstallConfig(options.configPath, { cwd: process.cwd() })
108-
: null;
114+
: (defaultConfigPath ? loadInstallConfig(defaultConfigPath, { cwd: process.cwd() }) : null);
109115
const request = normalizeInstallRequest({
110116
...options,
111117
config,

‎scripts/install-plan.js‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ const {
99
listInstallProfiles,
1010
resolveInstallPlan,
1111
} = require('./lib/install-manifests');
12-
const { loadInstallConfig } = require('./lib/install/config');
12+
const {
13+
findDefaultInstallConfigPath,
14+
loadInstallConfig,
15+
} = require('./lib/install/config');
1316
const { normalizeInstallRequest } = require('./lib/install/request');
1417

1518
function showHelp() {
@@ -186,7 +189,7 @@ function main() {
186189
try {
187190
const options = parseArgs(process.argv);
188191

189-
if (options.help || process.argv.length <= 2) {
192+
if (options.help) {
190193
showHelp();
191194
process.exit(0);
192195
}
@@ -224,9 +227,18 @@ function main() {
224227
return;
225228
}
226229

230+
const defaultConfigPath = options.configPath
231+
? null
232+
: findDefaultInstallConfigPath({ cwd: process.cwd() });
227233
const config = options.configPath
228234
? loadInstallConfig(options.configPath, { cwd: process.cwd() })
229-
: null;
235+
: (defaultConfigPath ? loadInstallConfig(defaultConfigPath, { cwd: process.cwd() }) : null);
236+
237+
if (process.argv.length <= 2 && !config) {
238+
showHelp();
239+
process.exit(0);
240+
}
241+
230242
const request = normalizeInstallRequest({
231243
...options,
232244
languages: [],

‎scripts/lib/install-manifests.js‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,45 @@ function listInstallComponents(options = {}) {
216216
.filter(component => !target || component.targets.includes(target));
217217
}
218218

219+
function getInstallComponent(componentId, options = {}) {
220+
const manifests = loadInstallManifests(options);
221+
const normalizedComponentId = String(componentId || '').trim();
222+
223+
if (!normalizedComponentId) {
224+
throw new Error('An install component ID is required');
225+
}
226+
227+
const component = manifests.componentsById.get(normalizedComponentId);
228+
if (!component) {
229+
throw new Error(`Unknown install component: ${normalizedComponentId}`);
230+
}
231+
232+
const moduleIds = dedupeStrings(component.modules);
233+
const modules = moduleIds
234+
.map(moduleId => manifests.modulesById.get(moduleId))
235+
.filter(Boolean)
236+
.map(module => ({
237+
id: module.id,
238+
kind: module.kind,
239+
description: module.description,
240+
targets: module.targets,
241+
defaultInstall: module.defaultInstall,
242+
cost: module.cost,
243+
stability: module.stability,
244+
dependencies: dedupeStrings(module.dependencies),
245+
}));
246+
247+
return {
248+
id: component.id,
249+
family: component.family,
250+
description: component.description,
251+
moduleIds,
252+
moduleCount: moduleIds.length,
253+
targets: intersectTargets(modules),
254+
modules,
255+
};
256+
}
257+
219258
function expandComponentIdsToModuleIds(componentIds, manifests) {
220259
const expandedModuleIds = [];
221260

@@ -438,6 +477,7 @@ module.exports = {
438477
SUPPORTED_INSTALL_TARGETS,
439478
getManifestPaths,
440479
loadInstallManifests,
480+
getInstallComponent,
441481
listInstallComponents,
442482
listLegacyCompatibilityLanguages,
443483
listInstallModules,

‎scripts/lib/install/config.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ function resolveInstallConfigPath(configPath, options = {}) {
4747
: path.normalize(path.join(cwd, configPath));
4848
}
4949

50+
function findDefaultInstallConfigPath(options = {}) {
51+
const cwd = options.cwd || process.cwd();
52+
const candidatePath = path.join(cwd, DEFAULT_INSTALL_CONFIG);
53+
return fs.existsSync(candidatePath) ? candidatePath : null;
54+
}
55+
5056
function loadInstallConfig(configPath, options = {}) {
5157
const resolvedPath = resolveInstallConfigPath(configPath, options);
5258

@@ -77,6 +83,7 @@ function loadInstallConfig(configPath, options = {}) {
7783

7884
module.exports = {
7985
DEFAULT_INSTALL_CONFIG,
86+
findDefaultInstallConfigPath,
8087
loadInstallConfig,
8188
resolveInstallConfigPath,
8289
};

‎tests/lib/install-config.test.js‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const os = require('os');
88
const path = require('path');
99

1010
const {
11+
findDefaultInstallConfigPath,
1112
loadInstallConfig,
1213
resolveInstallConfigPath,
1314
} = require('../../scripts/lib/install/config');
@@ -49,6 +50,32 @@ function runTests() {
4950
assert.strictEqual(resolved, path.join(cwd, 'configs', 'ecc-install.json'));
5051
})) passed++; else failed++;
5152

53+
if (test('finds the default project install config in the provided cwd', () => {
54+
const cwd = createTempDir('install-config-');
55+
56+
try {
57+
const configPath = path.join(cwd, 'ecc-install.json');
58+
writeJson(configPath, {
59+
version: 1,
60+
profile: 'core',
61+
});
62+
63+
assert.strictEqual(findDefaultInstallConfigPath({ cwd }), configPath);
64+
} finally {
65+
cleanup(cwd);
66+
}
67+
})) passed++; else failed++;
68+
69+
if (test('returns null when no default project install config exists', () => {
70+
const cwd = createTempDir('install-config-');
71+
72+
try {
73+
assert.strictEqual(findDefaultInstallConfigPath({ cwd }), null);
74+
} finally {
75+
cleanup(cwd);
76+
}
77+
})) passed++; else failed++;
78+
5279
if (test('loads and normalizes a valid install config', () => {
5380
const cwd = createTempDir('install-config-');
5481

0 commit comments

Comments
 (0)