@codemcp/ade-cli 0.0.2

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.
@@ -0,0 +1,4 @@
1
+
2
+ > @codemcp/ade-cli@0.0.2 typecheck /home/runner/work/ade/ade/packages/cli
3
+ > tsc
4
+
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Luke Baker
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ export declare function runInstall(projectRoot: string, harnessIds?: string[]): Promise<void>;
@@ -0,0 +1,33 @@
1
+ import * as clack from "@clack/prompts";
2
+ import { readLockFile } from "@codemcp/ade-core";
3
+ import { getHarnessWriter, getHarnessIds, installSkills } from "@codemcp/ade-harnesses";
4
+ export async function runInstall(projectRoot, harnessIds) {
5
+ clack.intro("ade install");
6
+ const lockFile = await readLockFile(projectRoot);
7
+ if (!lockFile) {
8
+ throw new Error("config.lock.yaml not found. Run `ade setup` first.");
9
+ }
10
+ // Determine which harnesses to install for:
11
+ // 1. --harness flag (comma-separated)
12
+ // 2. harnesses saved in the lock file
13
+ // 3. default: universal
14
+ const ids = harnessIds ?? lockFile.harnesses ?? ["universal"];
15
+ const validIds = getHarnessIds();
16
+ for (const id of ids) {
17
+ if (!validIds.includes(id)) {
18
+ throw new Error(`Unknown harness "${id}". Available: ${validIds.join(", ")}`);
19
+ }
20
+ }
21
+ const logicalConfig = lockFile.logical_config;
22
+ for (const id of ids) {
23
+ const writer = getHarnessWriter(id);
24
+ if (writer) {
25
+ await writer.install(logicalConfig, projectRoot);
26
+ }
27
+ }
28
+ await installSkills(logicalConfig.skills, projectRoot);
29
+ if (logicalConfig.knowledge_sources.length > 0) {
30
+ clack.log.info("Knowledge sources configured. Initialize them separately:\n npx @codemcp/knowledge init");
31
+ }
32
+ clack.outro("Install complete!");
33
+ }
@@ -0,0 +1,2 @@
1
+ import { type Catalog } from "@codemcp/ade-core";
2
+ export declare function runSetup(projectRoot: string, catalog: Catalog): Promise<void>;
@@ -0,0 +1,171 @@
1
+ import * as clack from "@clack/prompts";
2
+ import { readUserConfig, writeUserConfig, writeLockFile, resolve, collectDocsets, createDefaultRegistry, getFacet, getOption, sortFacets, getVisibleOptions } from "@codemcp/ade-core";
3
+ import { allHarnessWriters, getHarnessWriter, installSkills } from "@codemcp/ade-harnesses";
4
+ export async function runSetup(projectRoot, catalog) {
5
+ clack.intro("ade setup");
6
+ const existingConfig = await readUserConfig(projectRoot);
7
+ const existingChoices = existingConfig?.choices ?? {};
8
+ // Warn about stale choices that reference options no longer in the catalog
9
+ for (const [facetId, value] of Object.entries(existingChoices)) {
10
+ const facet = getFacet(catalog, facetId);
11
+ if (!facet)
12
+ continue;
13
+ const ids = Array.isArray(value) ? value : [value];
14
+ for (const optionId of ids) {
15
+ if (!getOption(facet, optionId)) {
16
+ clack.log.warn(`Previously selected option "${optionId}" is no longer available in facet "${facet.label}".`);
17
+ }
18
+ }
19
+ }
20
+ const choices = {};
21
+ const sortedFacets = sortFacets(catalog);
22
+ for (const facet of sortedFacets) {
23
+ const visibleOptions = getVisibleOptions(facet, choices, catalog);
24
+ if (visibleOptions.length === 0)
25
+ continue;
26
+ const visibleFacet = { ...facet, options: visibleOptions };
27
+ if (facet.multiSelect) {
28
+ const selected = await promptMultiSelect(visibleFacet, existingChoices);
29
+ if (typeof selected === "symbol") {
30
+ clack.cancel("Setup cancelled.");
31
+ return;
32
+ }
33
+ if (selected.length > 0) {
34
+ choices[facet.id] = selected;
35
+ }
36
+ }
37
+ else {
38
+ const selected = await promptSelect(visibleFacet, existingChoices);
39
+ if (typeof selected === "symbol") {
40
+ clack.cancel("Setup cancelled.");
41
+ return;
42
+ }
43
+ if (selected !== "__skip__") {
44
+ choices[facet.id] = selected;
45
+ }
46
+ }
47
+ }
48
+ // Docset confirmation step: collect implied docsets, let user deselect
49
+ const impliedDocsets = collectDocsets(choices, catalog);
50
+ let excludedDocsets;
51
+ if (impliedDocsets.length > 0) {
52
+ const selected = await clack.multiselect({
53
+ message: "Documentation — deselect any you don't need",
54
+ options: impliedDocsets.map((d) => ({
55
+ value: d.id,
56
+ label: d.label,
57
+ hint: d.description
58
+ })),
59
+ initialValues: impliedDocsets.map((d) => d.id),
60
+ required: false
61
+ });
62
+ if (typeof selected === "symbol") {
63
+ clack.cancel("Setup cancelled.");
64
+ return;
65
+ }
66
+ const selectedSet = new Set(selected);
67
+ const excluded = impliedDocsets
68
+ .filter((d) => !selectedSet.has(d.id))
69
+ .map((d) => d.id);
70
+ if (excluded.length > 0) {
71
+ excludedDocsets = excluded;
72
+ }
73
+ }
74
+ // Harness selection — multi-select from all available harnesses
75
+ const existingHarnesses = existingConfig?.harnesses;
76
+ const harnessOptions = allHarnessWriters.map((w) => ({
77
+ value: w.id,
78
+ label: w.label,
79
+ hint: w.description
80
+ }));
81
+ const validExistingHarnesses = existingHarnesses?.filter((h) => allHarnessWriters.some((w) => w.id === h));
82
+ const selectedHarnesses = await clack.multiselect({
83
+ message: "Harnesses — which coding agents should receive config?",
84
+ options: harnessOptions,
85
+ initialValues: validExistingHarnesses && validExistingHarnesses.length > 0
86
+ ? validExistingHarnesses
87
+ : ["universal"],
88
+ required: false
89
+ });
90
+ if (typeof selectedHarnesses === "symbol") {
91
+ clack.cancel("Setup cancelled.");
92
+ return;
93
+ }
94
+ const harnesses = selectedHarnesses;
95
+ const userConfig = {
96
+ choices,
97
+ ...(excludedDocsets && { excluded_docsets: excludedDocsets }),
98
+ ...(harnesses.length > 0 && { harnesses })
99
+ };
100
+ const registry = createDefaultRegistry();
101
+ const logicalConfig = await resolve(userConfig, catalog, registry);
102
+ await writeUserConfig(projectRoot, userConfig);
103
+ const lockFile = {
104
+ version: 1,
105
+ generated_at: new Date().toISOString(),
106
+ choices: userConfig.choices,
107
+ ...(harnesses.length > 0 && { harnesses }),
108
+ logical_config: logicalConfig
109
+ };
110
+ await writeLockFile(projectRoot, lockFile);
111
+ // Install to all selected harnesses
112
+ for (const harnessId of harnesses) {
113
+ const writer = getHarnessWriter(harnessId);
114
+ if (writer) {
115
+ await writer.install(logicalConfig, projectRoot);
116
+ }
117
+ }
118
+ await installSkills(logicalConfig.skills, projectRoot);
119
+ if (logicalConfig.knowledge_sources.length > 0) {
120
+ clack.log.info("Knowledge sources selected. Initialize them separately:\n npx @codemcp/knowledge init");
121
+ }
122
+ for (const note of logicalConfig.setup_notes) {
123
+ clack.log.info(note);
124
+ }
125
+ clack.outro("Setup complete!");
126
+ }
127
+ function getValidInitialValue(facet, existingChoices) {
128
+ const value = existingChoices[facet.id];
129
+ if (typeof value !== "string")
130
+ return undefined;
131
+ // Only set initialValue if the option still exists in the catalog
132
+ return facet.options.some((o) => o.id === value) ? value : undefined;
133
+ }
134
+ function getValidInitialValues(facet, existingChoices) {
135
+ const value = existingChoices[facet.id];
136
+ if (!Array.isArray(value))
137
+ return undefined;
138
+ // Only include options that still exist in the catalog
139
+ const valid = value.filter((v) => facet.options.some((o) => o.id === v));
140
+ return valid.length > 0 ? valid : undefined;
141
+ }
142
+ function promptSelect(facet, existingChoices) {
143
+ const options = facet.options.map((o) => ({
144
+ value: o.id,
145
+ label: o.label,
146
+ hint: o.description
147
+ }));
148
+ if (!facet.required) {
149
+ options.push({ value: "__skip__", label: "Skip", hint: "" });
150
+ }
151
+ const initialValue = getValidInitialValue(facet, existingChoices);
152
+ return clack.select({
153
+ message: facet.label,
154
+ options,
155
+ ...(initialValue !== undefined && { initialValue })
156
+ });
157
+ }
158
+ function promptMultiSelect(facet, existingChoices) {
159
+ const options = facet.options.map((o) => ({
160
+ value: o.id,
161
+ label: o.label,
162
+ hint: o.description
163
+ }));
164
+ const initialValues = getValidInitialValues(facet, existingChoices);
165
+ return clack.multiselect({
166
+ message: facet.label,
167
+ options,
168
+ required: false,
169
+ ...(initialValues !== undefined && { initialValues })
170
+ });
171
+ }
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env node
2
+ import { version } from "./version.js";
3
+ import { runSetup } from "./commands/setup.js";
4
+ import { runInstall } from "./commands/install.js";
5
+ import { getDefaultCatalog } from "@codemcp/ade-core";
6
+ import { getHarnessIds } from "@codemcp/ade-harnesses";
7
+ const args = process.argv.slice(2);
8
+ const command = args[0];
9
+ if (command === "setup") {
10
+ const projectRoot = args[1] ?? process.cwd();
11
+ const catalog = getDefaultCatalog();
12
+ await runSetup(projectRoot, catalog);
13
+ }
14
+ else if (command === "install") {
15
+ const projectRoot = args[1] ?? process.cwd();
16
+ let harnessIds;
17
+ // Support --harness flag (comma-separated)
18
+ if (args.includes("--harness")) {
19
+ const val = args[args.indexOf("--harness") + 1];
20
+ if (val) {
21
+ harnessIds = val.split(",").map((s) => s.trim());
22
+ }
23
+ }
24
+ await runInstall(projectRoot, harnessIds);
25
+ }
26
+ else if (command === "--version" || command === "-v") {
27
+ console.log(version);
28
+ }
29
+ else {
30
+ const allIds = getHarnessIds();
31
+ console.log(`ade v${version}`);
32
+ console.log();
33
+ console.log("Usage: ade <command> [options]");
34
+ console.log();
35
+ console.log("Commands:");
36
+ console.log(" setup [dir] Interactive setup wizard (re-run to change selections)");
37
+ console.log(" install [dir] Apply lock file to generate agent files (idempotent)");
38
+ console.log();
39
+ console.log("Options:");
40
+ console.log(` --harness <ids> Comma-separated harnesses (${allIds.join(", ")})`);
41
+ console.log(" -v, --version Show version");
42
+ process.exitCode = command ? 1 : 0;
43
+ }
@@ -0,0 +1,12 @@
1
+ import type { KnowledgeSource } from "@codemcp/ade-core";
2
+ /**
3
+ * Install knowledge sources using the @codemcp/knowledge programmatic API.
4
+ *
5
+ * For each knowledge source:
6
+ * 1. Creates a docset config entry via `createDocset`
7
+ * 2. Initializes (downloads) the docset via `initDocset`
8
+ *
9
+ * Errors on individual sources are logged and skipped so that one failure
10
+ * doesn't block the rest.
11
+ */
12
+ export declare function installKnowledge(sources: KnowledgeSource[], projectRoot: string): Promise<void>;
@@ -0,0 +1,38 @@
1
+ import { createDocset, initDocset } from "@codemcp/knowledge/packages/cli/dist/exports.js";
2
+ /**
3
+ * Install knowledge sources using the @codemcp/knowledge programmatic API.
4
+ *
5
+ * For each knowledge source:
6
+ * 1. Creates a docset config entry via `createDocset`
7
+ * 2. Initializes (downloads) the docset via `initDocset`
8
+ *
9
+ * Errors on individual sources are logged and skipped so that one failure
10
+ * doesn't block the rest.
11
+ */
12
+ export async function installKnowledge(sources, projectRoot) {
13
+ if (sources.length === 0)
14
+ return;
15
+ for (const source of sources) {
16
+ try {
17
+ await createDocset({
18
+ id: source.name,
19
+ name: source.description,
20
+ preset: "git-repo",
21
+ url: source.origin
22
+ }, { cwd: projectRoot });
23
+ }
24
+ catch (err) {
25
+ console.warn(`Warning: failed to create docset "${source.name}":`, err instanceof Error ? err.message : err);
26
+ continue;
27
+ }
28
+ try {
29
+ await initDocset({
30
+ docsetId: source.name,
31
+ cwd: projectRoot
32
+ });
33
+ }
34
+ catch (err) {
35
+ console.warn(`Warning: failed to initialize docset "${source.name}":`, err instanceof Error ? err.message : err);
36
+ }
37
+ }
38
+ }
@@ -0,0 +1 @@
1
+ export declare const version = "0.0.0-development";
@@ -0,0 +1 @@
1
+ export const version = "0.0.0-development";
@@ -0,0 +1,40 @@
1
+ import js from "@eslint/js";
2
+ import { parser, configs } from "typescript-eslint";
3
+ import prettier from "eslint-config-prettier";
4
+
5
+ export default [
6
+ js.configs.recommended,
7
+ ...configs.recommended,
8
+ prettier,
9
+ {
10
+ // Config for TypeScript files
11
+ files: ["**/*.{ts,tsx}"],
12
+ languageOptions: {
13
+ parser,
14
+ parserOptions: {
15
+ project: ["./tsconfig.json", "./tsconfig.vitest.json"]
16
+ }
17
+ }
18
+ },
19
+ {
20
+ // Config for JavaScript files - no TypeScript parsing
21
+ files: ["**/*.{js,jsx}"],
22
+ ...js.configs.recommended
23
+ },
24
+ {
25
+ // Relaxed rules for test files
26
+ files: ["**/*.test.ts", "**/*.spec.ts"],
27
+ rules: {
28
+ "@typescript-eslint/no-explicit-any": "off",
29
+ "@typescript-eslint/no-unused-vars": "off"
30
+ }
31
+ },
32
+ {
33
+ ignores: [
34
+ "**/node_modules/**",
35
+ "**/dist/**",
36
+ ".pnpm-store/**",
37
+ "pnpm-lock.yaml"
38
+ ]
39
+ }
40
+ ];
package/nodemon.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/nodemon.json",
3
+ "watch": ["./src/**", "./node_modules/@mme/**/dist/**"],
4
+ "ignoreRoot": [],
5
+ "ext": "ts,js",
6
+ "exec": "pnpm typecheck && pnpm build"
7
+ }
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@codemcp/ade-cli",
3
+ "main": "dist/index.js",
4
+ "types": "dist/index.d.ts",
5
+ "type": "module",
6
+ "bin": {
7
+ "ade": "dist/index.js"
8
+ },
9
+ "publishConfig": {
10
+ "access": "public"
11
+ },
12
+ "dependencies": {
13
+ "@clack/prompts": "^1.1.0",
14
+ "@codemcp/ade-core": "0.0.2",
15
+ "@codemcp/ade-harnesses": "0.0.2"
16
+ },
17
+ "devDependencies": {
18
+ "@codemcp/knowledge": "2.1.0",
19
+ "@typescript-eslint/eslint-plugin": "^8.21.0",
20
+ "@typescript-eslint/parser": "^8.21.0",
21
+ "eslint": "^9.18.0",
22
+ "eslint-config-prettier": "^10.0.1",
23
+ "prettier": "^3.4.2",
24
+ "rimraf": "^6.0.1",
25
+ "typescript": "^5.7.3"
26
+ },
27
+ "version": "0.0.2",
28
+ "scripts": {
29
+ "build": "tsc -p tsconfig.build.json",
30
+ "clean:build": "rimraf ./dist",
31
+ "dev": "nodemon",
32
+ "lint": "eslint .",
33
+ "lint:fix": "eslint --fix .",
34
+ "format": "prettier --check .",
35
+ "format:fix": "prettier --write .",
36
+ "test": "vitest --run",
37
+ "test:watch": "vitest",
38
+ "typecheck": "tsc"
39
+ }
40
+ }