agentcn 0.1.0

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/dist/add.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { Command } from "commander";
2
+ export declare const addCommand: Command;
package/dist/add.js ADDED
@@ -0,0 +1,165 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.addCommand = void 0;
37
+ const fs = __importStar(require("fs"));
38
+ const path = __importStar(require("path"));
39
+ const path_exists_1 = require("path-exists");
40
+ const commander_1 = require("commander");
41
+ function getRegistryUrl(registryPath) {
42
+ if (registryPath) {
43
+ if (registryPath.startsWith("http"))
44
+ return registryPath;
45
+ const resolved = path.resolve(process.cwd(), registryPath);
46
+ if ((0, path_exists_1.pathExistsSync)(resolved))
47
+ return resolved;
48
+ }
49
+ // Default: monorepo kit/public/r (packages/agentcn/cli/dist -> ../../../public/r)
50
+ const scriptDir = path.dirname(process.argv[1] || process.cwd());
51
+ const localRegistry = path.resolve(scriptDir, "../../../public/r");
52
+ if ((0, path_exists_1.pathExistsSync)(localRegistry))
53
+ return localRegistry;
54
+ return "http://localhost:3000/r";
55
+ }
56
+ async function fetchRegistryItem(agentName, registryBase) {
57
+ if (registryBase.startsWith("http")) {
58
+ const url = `${registryBase.replace(/\/$/, "")}/${agentName}.json`;
59
+ const res = await fetch(url);
60
+ if (!res.ok)
61
+ throw new Error(`Agent "${agentName}" not found at ${url}`);
62
+ return res.json();
63
+ }
64
+ const filePath = path.join(registryBase, `${agentName}.json`);
65
+ if (!(0, path_exists_1.pathExistsSync)(filePath)) {
66
+ throw new Error(`Agent "${agentName}" not found at ${filePath}`);
67
+ }
68
+ const content = fs.readFileSync(filePath, "utf-8");
69
+ return JSON.parse(content);
70
+ }
71
+ function detectPackageManager(cwd) {
72
+ if ((0, path_exists_1.pathExistsSync)(path.join(cwd, "pnpm-lock.yaml")))
73
+ return "pnpm";
74
+ if ((0, path_exists_1.pathExistsSync)(path.join(cwd, "yarn.lock")))
75
+ return "yarn";
76
+ return "npm";
77
+ }
78
+ function ensureDir(dir) {
79
+ if (!fs.existsSync(dir)) {
80
+ fs.mkdirSync(dir, { recursive: true });
81
+ }
82
+ }
83
+ function mergeEnvExample(cwd, envVars) {
84
+ const envPath = path.join(cwd, ".env.example");
85
+ let existing = "";
86
+ if ((0, path_exists_1.pathExistsSync)(envPath)) {
87
+ existing = fs.readFileSync(envPath, "utf-8");
88
+ }
89
+ const lines = [];
90
+ for (const [key, value] of Object.entries(envVars)) {
91
+ if (!existing.includes(`${key}=`)) {
92
+ lines.push(`# Required for agent\n${key}=${value}`);
93
+ }
94
+ }
95
+ if (lines.length > 0) {
96
+ const toAppend = "\n\n" + lines.join("\n") + "\n";
97
+ fs.appendFileSync(envPath, toAppend);
98
+ }
99
+ }
100
+ function addTsconfigPaths(cwd) {
101
+ const tsconfigPath = path.join(cwd, "tsconfig.json");
102
+ if (!(0, path_exists_1.pathExistsSync)(tsconfigPath))
103
+ return;
104
+ try {
105
+ const content = fs.readFileSync(tsconfigPath, "utf-8");
106
+ const config = JSON.parse(content);
107
+ const comp = config.compilerOptions ?? {};
108
+ const paths = comp.paths ?? {};
109
+ if (!paths["@/agents/*"]) {
110
+ paths["@/agents/*"] = ["./ai/agents/*"];
111
+ }
112
+ if (!paths["@/tools/*"]) {
113
+ paths["@/tools/*"] = ["./ai/tools/*"];
114
+ }
115
+ comp.paths = paths;
116
+ config.compilerOptions = comp;
117
+ fs.writeFileSync(tsconfigPath, JSON.stringify(config, null, 2));
118
+ }
119
+ catch {
120
+ // skip if tsconfig is invalid
121
+ }
122
+ }
123
+ async function runAdd(agentName, options) {
124
+ const cwd = process.cwd();
125
+ const registryBase = getRegistryUrl(options.registry);
126
+ console.log(`\n Adding ${agentName}...\n`);
127
+ const item = await fetchRegistryItem(agentName, registryBase);
128
+ for (const file of item.files) {
129
+ const target = file.target ?? file.path;
130
+ const destPath = path.join(cwd, target);
131
+ ensureDir(path.dirname(destPath));
132
+ fs.writeFileSync(destPath, file.content, "utf-8");
133
+ console.log(` ✓ ${target}`);
134
+ }
135
+ if (item.envVars && Object.keys(item.envVars).length > 0) {
136
+ mergeEnvExample(cwd, item.envVars);
137
+ console.log(` ✓ .env.example updated`);
138
+ }
139
+ addTsconfigPaths(cwd);
140
+ console.log(` ✓ tsconfig paths updated`);
141
+ if (item.dependencies && item.dependencies.length > 0) {
142
+ const pm = detectPackageManager(cwd);
143
+ const deps = item.dependencies.join(" ");
144
+ console.log(`\n Installing dependencies: ${deps}\n`);
145
+ const { execSync } = await import("child_process");
146
+ const cmd = pm === "pnpm"
147
+ ? `pnpm add ${deps}`
148
+ : pm === "yarn"
149
+ ? `yarn add ${deps}`
150
+ : `npm install ${deps}`;
151
+ execSync(cmd, { cwd, stdio: "inherit" });
152
+ }
153
+ const agentVarLower = agentName.split("-")[0] + "Agent";
154
+ console.log(`\n Done! Add an API route to use the agent:\n`);
155
+ console.log(` // app/api/chat/route.ts (Next.js App Router)`);
156
+ console.log(` import { ${agentVarLower} } from "@/agents/${agentName}";`);
157
+ console.log(` import { convertToModelMessages } from "ai";`);
158
+ console.log(` // const result = ${agentVarLower}(modelMessages);`);
159
+ console.log(` // return result.toUIMessageStreamResponse();\n`);
160
+ }
161
+ exports.addCommand = new commander_1.Command("add")
162
+ .description("Add an agent to your project")
163
+ .argument("<agent>", "Agent name (e.g. file-agent)")
164
+ .option("-r, --registry <path|url>", "Registry path or URL (default: kit/public/r when present, else http://localhost:3000/r)")
165
+ .action(runAdd);
@@ -0,0 +1,9 @@
1
+ import { Command } from "commander";
2
+ import type { AddOptionsInput } from "../types.js";
3
+ type ConfirmFn = (message: string, defaultValue?: boolean) => Promise<boolean>;
4
+ type AddRuntimeHooks = {
5
+ confirm?: ConfirmFn;
6
+ };
7
+ export declare function runAddCommand(agentName: string, input: AddOptionsInput, hooks?: AddRuntimeHooks): Promise<void>;
8
+ export declare const addCommand: Command;
9
+ export {};
@@ -0,0 +1,178 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.addCommand = void 0;
7
+ exports.runAddCommand = runAddCommand;
8
+ const commander_1 = require("commander");
9
+ const node_fs_1 = require("node:fs");
10
+ const node_path_1 = __importDefault(require("node:path"));
11
+ const config_js_1 = require("../lib/config.js");
12
+ const deps_js_1 = require("../lib/deps.js");
13
+ const install_plan_js_1 = require("../lib/install-plan.js");
14
+ const registry_js_1 = require("../lib/registry.js");
15
+ const logger_js_1 = require("../utils/logger.js");
16
+ const prompt_js_1 = require("../utils/prompt.js");
17
+ const spinner_js_1 = require("../utils/spinner.js");
18
+ const AGENT_ALIASES = {
19
+ fileagent: "file-agent",
20
+ file_agent: "file-agent",
21
+ webagent: "web-agent",
22
+ web_agent: "web-agent",
23
+ };
24
+ function normalizeAgentName(input) {
25
+ const trimmed = input.trim();
26
+ const alias = AGENT_ALIASES[trimmed.toLowerCase()];
27
+ if (alias)
28
+ return { value: alias, aliased: true };
29
+ const normalized = trimmed.replace(/_/g, "-").toLowerCase();
30
+ if (normalized !== trimmed) {
31
+ return { value: normalized, aliased: true };
32
+ }
33
+ return { value: trimmed, aliased: false };
34
+ }
35
+ function printSection(title) {
36
+ logger_js_1.logger.break();
37
+ logger_js_1.logger.info(title);
38
+ }
39
+ async function runAddCommand(agentName, input, hooks = {}) {
40
+ const confirm = hooks.confirm ?? prompt_js_1.confirmAction;
41
+ const parsed = (0, registry_js_1.parseAddOptions)(input, process.cwd());
42
+ const normalizedAgent = normalizeAgentName(agentName);
43
+ if (normalizedAgent.aliased) {
44
+ logger_js_1.logger.warn(`Using canonical agent name "${normalizedAgent.value}" for "${agentName}".`);
45
+ }
46
+ logger_js_1.logger.break();
47
+ logger_js_1.logger.info(`Adding ${normalizedAgent.value}...`);
48
+ logger_js_1.logger.break();
49
+ printSection("Resolving registry");
50
+ const loadSpin = (0, spinner_js_1.spinner)("Resolving source and loading agent...");
51
+ loadSpin.start();
52
+ const registryBase = (0, registry_js_1.resolveRegistrySource)(parsed.registry, parsed.cwd);
53
+ const item = await (0, registry_js_1.loadRegistryItem)(normalizedAgent.value, registryBase);
54
+ loadSpin.succeed(`Loaded ${item.name} from registry`);
55
+ logger_js_1.logger.info(` Source: ${registryBase}`);
56
+ let actions = (0, install_plan_js_1.planInstall)(item, parsed.cwd, {
57
+ overwrite: parsed.overwrite,
58
+ });
59
+ const summary = {
60
+ create: actions.filter((a) => a.action === "create").map((a) => a.targetPath),
61
+ update: actions.filter((a) => a.action === "update").map((a) => a.targetPath),
62
+ skip: actions.filter((a) => a.action === "skip").map((a) => a.targetPath),
63
+ };
64
+ printSection("Plan summary");
65
+ logger_js_1.logger.info(` Files: ${summary.create.length} create, ${summary.update.length} update, ${summary.skip.length} skip`);
66
+ if (summary.skip.length > 0 && !parsed.overwrite) {
67
+ logger_js_1.logger.info(" Note: existing files are currently marked as skip.");
68
+ }
69
+ if (parsed.verbose) {
70
+ for (const file of summary.create)
71
+ logger_js_1.logger.info(` + create ${file}`);
72
+ for (const file of summary.update)
73
+ logger_js_1.logger.info(` ~ update ${file}`);
74
+ for (const file of summary.skip)
75
+ logger_js_1.logger.info(` - skip ${file}`);
76
+ }
77
+ if (!parsed.dryRun &&
78
+ !parsed.overwrite &&
79
+ summary.skip.length > 0 &&
80
+ !parsed.yes) {
81
+ const shouldOverwrite = await confirm(`Found ${summary.skip.length} existing file(s). Overwrite them?`, false);
82
+ if (shouldOverwrite) {
83
+ actions = (0, install_plan_js_1.planInstall)(item, parsed.cwd, { overwrite: true });
84
+ }
85
+ }
86
+ if (parsed.dryRun) {
87
+ logger_js_1.logger.info(" Dry run enabled: no files were written.");
88
+ }
89
+ else {
90
+ printSection("Applying files");
91
+ const applySpin = (0, spinner_js_1.spinner)("Applying file changes...");
92
+ applySpin.start();
93
+ const applied = (0, install_plan_js_1.applyInstallPlan)(actions);
94
+ applySpin.succeed("Applied file changes");
95
+ logger_js_1.logger.info(` Files: ${applied.created.length} created, ${applied.updated.length} updated, ${applied.skipped.length} skipped`);
96
+ if (parsed.verbose) {
97
+ for (const file of applied.created)
98
+ logger_js_1.logger.info(` ✓ ${file}`);
99
+ for (const file of applied.updated)
100
+ logger_js_1.logger.info(` ✓ ${file} (updated)`);
101
+ for (const file of applied.skipped)
102
+ logger_js_1.logger.info(` - ${file} (skipped)`);
103
+ }
104
+ }
105
+ printSection("Config updates");
106
+ let envAdded = [];
107
+ if (item.envVars && Object.keys(item.envVars).length > 0) {
108
+ const envExamplePath = node_path_1.default.join(parsed.cwd, ".env.example");
109
+ const shouldUpdateEnv = parsed.yes || (0, node_fs_1.existsSync)(envExamplePath)
110
+ ? true
111
+ : await confirm("No .env.example found. Create and append required env keys?", true);
112
+ if (shouldUpdateEnv) {
113
+ envAdded = (0, config_js_1.mergeEnvExample)(parsed.cwd, item.envVars, { dryRun: parsed.dryRun });
114
+ }
115
+ else {
116
+ logger_js_1.logger.info(" Env: skipped");
117
+ }
118
+ }
119
+ if (envAdded.length > 0) {
120
+ logger_js_1.logger.info(parsed.dryRun
121
+ ? ` Env: would add ${envAdded.join(", ")}`
122
+ : ` Env: updated (${envAdded.join(", ")})`);
123
+ }
124
+ const tsconfigUpdated = (0, config_js_1.updateTsconfigPaths)(parsed.cwd, { dryRun: parsed.dryRun });
125
+ if (tsconfigUpdated) {
126
+ logger_js_1.logger.info(parsed.dryRun
127
+ ? " tsconfig: paths would be updated"
128
+ : " tsconfig: paths updated");
129
+ }
130
+ printSection("Installing dependencies");
131
+ const shouldInstallDeps = parsed.dryRun || parsed.yes
132
+ ? true
133
+ : await confirm("Install agent dependencies now?", true);
134
+ let depsInstalled = [];
135
+ if (!shouldInstallDeps) {
136
+ logger_js_1.logger.info(" Dependencies: skipped by user");
137
+ }
138
+ else {
139
+ const depSpin = (0, spinner_js_1.spinner)("Installing dependencies...");
140
+ if (!parsed.verbose && !parsed.dryRun)
141
+ depSpin.start();
142
+ depsInstalled = (0, deps_js_1.installDependencies)(parsed.cwd, item.dependencies, {
143
+ dryRun: parsed.dryRun,
144
+ verbose: parsed.verbose,
145
+ });
146
+ if (!parsed.verbose && !parsed.dryRun)
147
+ depSpin.succeed("Dependencies installed");
148
+ if (depsInstalled.length > 0) {
149
+ logger_js_1.logger.info(parsed.dryRun
150
+ ? ` Dependencies: would install ${depsInstalled.join(", ")}`
151
+ : ` Dependencies: installed ${depsInstalled.join(", ")}`);
152
+ }
153
+ else {
154
+ logger_js_1.logger.info(" Dependencies: none required");
155
+ }
156
+ }
157
+ printSection("Done");
158
+ logger_js_1.logger.break();
159
+ logger_js_1.logger.success("Done!");
160
+ logger_js_1.logger.info("Next steps:");
161
+ logger_js_1.logger.info(" - Review created/updated files and run your formatter if needed.");
162
+ if (envAdded.length > 0) {
163
+ logger_js_1.logger.info(` - Set environment values: ${envAdded.join(", ")}`);
164
+ }
165
+ logger_js_1.logger.info(" - Run your app and test the installed agent flow.");
166
+ logger_js_1.logger.info(" - Use --dry-run and --verbose for troubleshooting.");
167
+ logger_js_1.logger.break();
168
+ }
169
+ exports.addCommand = new commander_1.Command("add")
170
+ .description("Add an agent to your project")
171
+ .argument("<agent>", "Agent name (e.g. file-agent)")
172
+ .option("-r, --registry <path|url>", "Registry path or URL")
173
+ .option("--dry-run", "Preview changes without writing files", false)
174
+ .option("--overwrite", "Overwrite existing files", false)
175
+ .option("--verbose", "Show verbose output", false)
176
+ .option("--yes", "Non-interactive mode", false)
177
+ .option("--cwd <path>", "Run command against a target project directory")
178
+ .action((agent, options) => runAddCommand(agent, options));
@@ -0,0 +1,2 @@
1
+ import { Command } from "commander";
2
+ export declare const infoCommand: Command;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.infoCommand = void 0;
4
+ const commander_1 = require("commander");
5
+ const registry_js_1 = require("../lib/registry.js");
6
+ async function runInfo(agentName, options) {
7
+ const cwd = process.cwd();
8
+ const registryBase = (0, registry_js_1.resolveRegistrySource)(options.registry, cwd);
9
+ const item = await (0, registry_js_1.loadRegistryItem)(agentName, registryBase);
10
+ console.log(`\n${item.title ?? item.name}`);
11
+ console.log(`${item.description}`);
12
+ console.log(`Type: ${item.type}`);
13
+ if (item.categories?.length) {
14
+ console.log(`Categories: ${item.categories.join(", ")}`);
15
+ }
16
+ if (item.dependencies?.length) {
17
+ console.log(`Dependencies: ${item.dependencies.join(", ")}`);
18
+ }
19
+ if (item.envVars && Object.keys(item.envVars).length > 0) {
20
+ console.log(`Env vars: ${Object.keys(item.envVars).join(", ")}`);
21
+ }
22
+ console.log(`Files: ${item.files.length}`);
23
+ for (const file of item.files) {
24
+ console.log(` - ${file.target ?? file.path}`);
25
+ }
26
+ console.log("");
27
+ }
28
+ exports.infoCommand = new commander_1.Command("info")
29
+ .description("Show details for a specific agent")
30
+ .argument("<agent>", "Agent name")
31
+ .option("-r, --registry <path|url>", "Registry path or URL")
32
+ .action(runInfo);
@@ -0,0 +1,2 @@
1
+ import { Command } from "commander";
2
+ export declare const listCommand: Command;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.listCommand = void 0;
4
+ const commander_1 = require("commander");
5
+ const registry_js_1 = require("../lib/registry.js");
6
+ async function runList(options) {
7
+ const cwd = process.cwd();
8
+ const registryBase = (0, registry_js_1.resolveRegistrySource)(options.registry, cwd);
9
+ const index = await (0, registry_js_1.loadRegistryIndex)(registryBase);
10
+ console.log(`\nAvailable agents in ${index.name}:\n`);
11
+ for (const item of index.items) {
12
+ const categories = item.categories?.length
13
+ ? ` (${item.categories.join(", ")})`
14
+ : "";
15
+ console.log(`- ${item.name}${categories}`);
16
+ console.log(` ${item.description}`);
17
+ }
18
+ console.log("");
19
+ }
20
+ exports.listCommand = new commander_1.Command("list")
21
+ .description("List available agents from registry")
22
+ .option("-r, --registry <path|url>", "Registry path or URL")
23
+ .action(runList);
@@ -0,0 +1 @@
1
+ export declare const REGISTRY_SCHEMA_VERSION = 1;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.REGISTRY_SCHEMA_VERSION = void 0;
4
+ exports.REGISTRY_SCHEMA_VERSION = 1;
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const commander_1 = require("commander");
5
+ const add_js_1 = require("./commands/add.js");
6
+ const info_js_1 = require("./commands/info.js");
7
+ const list_js_1 = require("./commands/list.js");
8
+ const program = new commander_1.Command();
9
+ program
10
+ .name("agentcn")
11
+ .description("Install reusable AI agents into your project")
12
+ .version("0.1.0");
13
+ program.addCommand(add_js_1.addCommand);
14
+ program.addCommand(list_js_1.listCommand);
15
+ program.addCommand(info_js_1.infoCommand);
16
+ program.parse();
@@ -0,0 +1,10 @@
1
+ export declare function mergeEnvContent(existing: string, envVars: Record<string, string>): {
2
+ content: string;
3
+ added: string[];
4
+ };
5
+ export declare function mergeEnvExample(cwd: string, envVars: Record<string, string>, options: {
6
+ dryRun: boolean;
7
+ }): string[];
8
+ export declare function updateTsconfigPaths(cwd: string, options: {
9
+ dryRun: boolean;
10
+ }): boolean;
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.mergeEnvContent = mergeEnvContent;
37
+ exports.mergeEnvExample = mergeEnvExample;
38
+ exports.updateTsconfigPaths = updateTsconfigPaths;
39
+ const fs = __importStar(require("fs"));
40
+ const path = __importStar(require("path"));
41
+ const path_exists_1 = require("path-exists");
42
+ function parseEnvKeys(content) {
43
+ const keys = new Set();
44
+ for (const line of content.split(/\r?\n/)) {
45
+ const trimmed = line.trim();
46
+ if (!trimmed || trimmed.startsWith("#"))
47
+ continue;
48
+ const match = /^([A-Za-z_][A-Za-z0-9_]*)=/.exec(trimmed);
49
+ if (match)
50
+ keys.add(match[1]);
51
+ }
52
+ return keys;
53
+ }
54
+ function mergeEnvContent(existing, envVars) {
55
+ const existingKeys = parseEnvKeys(existing);
56
+ const additions = [];
57
+ const added = [];
58
+ for (const [key, value] of Object.entries(envVars)) {
59
+ if (!existingKeys.has(key)) {
60
+ additions.push(`# Required for agent\n${key}=${value}`);
61
+ added.push(key);
62
+ }
63
+ }
64
+ if (additions.length === 0)
65
+ return { content: existing, added };
66
+ const prefix = existing.trim().length > 0 ? `${existing.trimEnd()}\n\n` : "";
67
+ return { content: `${prefix}${additions.join("\n")}\n`, added };
68
+ }
69
+ function mergeEnvExample(cwd, envVars, options) {
70
+ const envPath = path.join(cwd, ".env.example");
71
+ const existing = (0, path_exists_1.pathExistsSync)(envPath) ? fs.readFileSync(envPath, "utf-8") : "";
72
+ const { content, added } = mergeEnvContent(existing, envVars);
73
+ if (!options.dryRun && content !== existing) {
74
+ fs.writeFileSync(envPath, content, "utf-8");
75
+ }
76
+ return added;
77
+ }
78
+ function updateTsconfigPaths(cwd, options) {
79
+ const tsconfigPath = path.join(cwd, "tsconfig.json");
80
+ if (!(0, path_exists_1.pathExistsSync)(tsconfigPath))
81
+ return false;
82
+ try {
83
+ const content = fs.readFileSync(tsconfigPath, "utf-8");
84
+ const config = JSON.parse(content);
85
+ const compilerOptions = config.compilerOptions ?? {};
86
+ const paths = compilerOptions.paths ?? {};
87
+ let changed = false;
88
+ if (!paths["@/agents/*"]) {
89
+ paths["@/agents/*"] = ["./ai/agents/*"];
90
+ changed = true;
91
+ }
92
+ if (!paths["@/tools/*"]) {
93
+ paths["@/tools/*"] = ["./ai/tools/*"];
94
+ changed = true;
95
+ }
96
+ compilerOptions.paths = paths;
97
+ config.compilerOptions = compilerOptions;
98
+ if (changed && !options.dryRun) {
99
+ fs.writeFileSync(tsconfigPath, JSON.stringify(config, null, 2), "utf-8");
100
+ }
101
+ return changed;
102
+ }
103
+ catch {
104
+ return false;
105
+ }
106
+ }
@@ -0,0 +1,6 @@
1
+ export declare function getExecErrorOutput(error: unknown): string;
2
+ export declare function detectPackageManager(cwd: string): "npm" | "pnpm" | "yarn";
3
+ export declare function installDependencies(cwd: string, dependencies: string[] | undefined, options: {
4
+ dryRun: boolean;
5
+ verbose: boolean;
6
+ }): string[];