@deimoscloud/coreai 0.1.10 → 0.1.12

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/cli/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/cli/index.ts
4
- import { join as join13, dirname as dirname6 } from "path";
4
+ import { join as join14, dirname as dirname7 } from "path";
5
5
  import { fileURLToPath as fileURLToPath2 } from "url";
6
6
  import { Command } from "commander";
7
7
 
@@ -588,7 +588,14 @@ function compileAgents(config, options = {}) {
588
588
  return result;
589
589
  }
590
590
  function getCoreAgentsDir() {
591
- return join3(dirname2(dirname2(import.meta.url.replace("file://", ""))), "agents");
591
+ let currentDir = dirname2(import.meta.url.replace("file://", ""));
592
+ for (let i = 0; i < 5; i++) {
593
+ if (existsSync3(join3(currentDir, "package.json"))) {
594
+ return join3(currentDir, "agents");
595
+ }
596
+ currentDir = dirname2(currentDir);
597
+ }
598
+ return join3(dirname2(dirname2(dirname2(import.meta.url.replace("file://", "")))), "agents");
592
599
  }
593
600
 
594
601
  // src/adapters/mcp/types.ts
@@ -4022,11 +4029,227 @@ function formatStatusResult(result) {
4022
4029
  return lines.join("\n");
4023
4030
  }
4024
4031
 
4032
+ // src/cli/commands/agents.ts
4033
+ import { readFileSync as readFileSync8, writeFileSync as writeFileSync5 } from "fs";
4034
+ import { join as join13, dirname as dirname6 } from "path";
4035
+ import { parse as parseYaml3, stringify as stringifyYaml } from "yaml";
4036
+ function readConfigFile(configPath) {
4037
+ const content = readFileSync8(configPath, "utf-8");
4038
+ const parsed = parseYaml3(content);
4039
+ return { content, parsed };
4040
+ }
4041
+ function updateConfigAgents(configPath, agents2) {
4042
+ const content = readFileSync8(configPath, "utf-8");
4043
+ const parsed = parseYaml3(content);
4044
+ if (!parsed.team) {
4045
+ parsed.team = {};
4046
+ }
4047
+ parsed.team.agents = agents2;
4048
+ const newContent = stringifyYaml(parsed, {
4049
+ indent: 2,
4050
+ lineWidth: 0,
4051
+ singleQuote: false
4052
+ });
4053
+ writeFileSync5(configPath, newContent, "utf-8");
4054
+ }
4055
+ function getAvailableAgents(coreAgentsDir, customAgentsDir) {
4056
+ const available = /* @__PURE__ */ new Map();
4057
+ const allAgents = loadAllAgents({
4058
+ coreAgentsDir,
4059
+ customAgentsDir
4060
+ });
4061
+ for (const [role, meta] of allAgents) {
4062
+ available.set(role, meta.source === "core" ? "core" : "custom");
4063
+ }
4064
+ return available;
4065
+ }
4066
+ function agentsAdd(agents2, options = {}) {
4067
+ const projectRoot = options.projectRoot ?? process.cwd();
4068
+ const coreAgentsDir = options.coreAgentsDir ?? join13(dirname6(dirname6(dirname6(__dirname))), "agents");
4069
+ const customAgentsDir = join13(projectRoot, "coreai", "agents");
4070
+ const configPath = findConfigFile(projectRoot);
4071
+ if (!configPath) {
4072
+ return {
4073
+ success: false,
4074
+ added: [],
4075
+ alreadyExists: [],
4076
+ notFound: [],
4077
+ error: "No coreai.config.yaml found. Run `coreai init` first."
4078
+ };
4079
+ }
4080
+ const availableAgents = getAvailableAgents(coreAgentsDir, customAgentsDir);
4081
+ const agentsToAdd = options.all ? Array.from(availableAgents.keys()) : agents2;
4082
+ if (agentsToAdd.length === 0) {
4083
+ return {
4084
+ success: false,
4085
+ added: [],
4086
+ alreadyExists: [],
4087
+ notFound: [],
4088
+ configPath,
4089
+ error: "No agents specified. Use --all to add all agents or provide a comma-separated list."
4090
+ };
4091
+ }
4092
+ const { parsed } = readConfigFile(configPath);
4093
+ const currentAgents = parsed.team?.agents ?? [];
4094
+ const added = [];
4095
+ const alreadyExists = [];
4096
+ const notFound = [];
4097
+ for (const agent of agentsToAdd) {
4098
+ const trimmedAgent = agent.trim();
4099
+ if (!availableAgents.has(trimmedAgent)) {
4100
+ notFound.push(trimmedAgent);
4101
+ continue;
4102
+ }
4103
+ if (currentAgents.includes(trimmedAgent)) {
4104
+ alreadyExists.push(trimmedAgent);
4105
+ continue;
4106
+ }
4107
+ added.push(trimmedAgent);
4108
+ }
4109
+ if (added.length > 0) {
4110
+ const newAgents = [...currentAgents, ...added].sort();
4111
+ try {
4112
+ updateConfigAgents(configPath, newAgents);
4113
+ } catch (error) {
4114
+ return {
4115
+ success: false,
4116
+ added: [],
4117
+ alreadyExists,
4118
+ notFound,
4119
+ configPath,
4120
+ error: `Failed to update config: ${error instanceof Error ? error.message : String(error)}`
4121
+ };
4122
+ }
4123
+ }
4124
+ return {
4125
+ success: notFound.length === 0,
4126
+ added,
4127
+ alreadyExists,
4128
+ notFound,
4129
+ configPath
4130
+ };
4131
+ }
4132
+ function agentsRemove(agents2, options = {}) {
4133
+ const projectRoot = options.projectRoot ?? process.cwd();
4134
+ const configPath = findConfigFile(projectRoot);
4135
+ if (!configPath) {
4136
+ return {
4137
+ success: false,
4138
+ removed: [],
4139
+ notInConfig: [],
4140
+ error: "No coreai.config.yaml found. Run `coreai init` first."
4141
+ };
4142
+ }
4143
+ const { parsed } = readConfigFile(configPath);
4144
+ const currentAgents = parsed.team?.agents ?? [];
4145
+ const agentsToRemove = options.all ? [...currentAgents] : agents2;
4146
+ if (agentsToRemove.length === 0) {
4147
+ return {
4148
+ success: false,
4149
+ removed: [],
4150
+ notInConfig: [],
4151
+ configPath,
4152
+ error: "No agents specified. Use --all to remove all agents or provide a comma-separated list."
4153
+ };
4154
+ }
4155
+ const removed = [];
4156
+ const notInConfig = [];
4157
+ for (const agent of agentsToRemove) {
4158
+ const trimmedAgent = agent.trim();
4159
+ if (!currentAgents.includes(trimmedAgent)) {
4160
+ notInConfig.push(trimmedAgent);
4161
+ continue;
4162
+ }
4163
+ removed.push(trimmedAgent);
4164
+ }
4165
+ if (removed.length > 0) {
4166
+ const newAgents = currentAgents.filter((a) => !removed.includes(a));
4167
+ try {
4168
+ updateConfigAgents(configPath, newAgents);
4169
+ } catch (error) {
4170
+ return {
4171
+ success: false,
4172
+ removed: [],
4173
+ notInConfig,
4174
+ configPath,
4175
+ error: `Failed to update config: ${error instanceof Error ? error.message : String(error)}`
4176
+ };
4177
+ }
4178
+ }
4179
+ return {
4180
+ success: true,
4181
+ removed,
4182
+ notInConfig,
4183
+ configPath
4184
+ };
4185
+ }
4186
+ function formatAgentsAddResult(result) {
4187
+ const lines = [];
4188
+ if (!result.success && result.error) {
4189
+ return `Error: ${result.error}`;
4190
+ }
4191
+ if (result.added.length > 0) {
4192
+ lines.push("Added agents:");
4193
+ for (const agent of result.added) {
4194
+ lines.push(` + ${agent}`);
4195
+ }
4196
+ }
4197
+ if (result.alreadyExists.length > 0) {
4198
+ if (lines.length > 0) lines.push("");
4199
+ lines.push("Already in config:");
4200
+ for (const agent of result.alreadyExists) {
4201
+ lines.push(` = ${agent}`);
4202
+ }
4203
+ }
4204
+ if (result.notFound.length > 0) {
4205
+ if (lines.length > 0) lines.push("");
4206
+ lines.push("Not found (run `coreai agents list` to see available):");
4207
+ for (const agent of result.notFound) {
4208
+ lines.push(` ! ${agent}`);
4209
+ }
4210
+ }
4211
+ if (result.added.length === 0 && result.alreadyExists.length === 0 && result.notFound.length === 0) {
4212
+ lines.push("No changes made.");
4213
+ }
4214
+ if (result.added.length > 0) {
4215
+ lines.push("");
4216
+ lines.push("Run `coreai build` to compile the updated agent list.");
4217
+ }
4218
+ return lines.join("\n");
4219
+ }
4220
+ function formatAgentsRemoveResult(result) {
4221
+ const lines = [];
4222
+ if (!result.success && result.error) {
4223
+ return `Error: ${result.error}`;
4224
+ }
4225
+ if (result.removed.length > 0) {
4226
+ lines.push("Removed agents:");
4227
+ for (const agent of result.removed) {
4228
+ lines.push(` - ${agent}`);
4229
+ }
4230
+ }
4231
+ if (result.notInConfig.length > 0) {
4232
+ if (lines.length > 0) lines.push("");
4233
+ lines.push("Not in config:");
4234
+ for (const agent of result.notInConfig) {
4235
+ lines.push(` ? ${agent}`);
4236
+ }
4237
+ }
4238
+ if (result.removed.length === 0 && result.notInConfig.length === 0) {
4239
+ lines.push("No changes made.");
4240
+ }
4241
+ if (result.removed.length > 0) {
4242
+ lines.push("");
4243
+ lines.push("Run `coreai build` to compile the updated agent list.");
4244
+ }
4245
+ return lines.join("\n");
4246
+ }
4247
+
4025
4248
  // src/cli/index.ts
4026
4249
  var __filename = fileURLToPath2(import.meta.url);
4027
- var __dirname = dirname6(__filename);
4250
+ var __dirname2 = dirname7(__filename);
4028
4251
  function getCoreAgentsPath() {
4029
- return join13(__dirname, "..", "..", "agents");
4252
+ return join14(__dirname2, "..", "..", "agents");
4030
4253
  }
4031
4254
  var program = new Command();
4032
4255
  program.name("coreai").description("A configurable, team-ready AI agent orchestration platform").version(VERSION, "-v, --version", "output the current version");
@@ -4105,7 +4328,7 @@ program.command("validate").description("Validate configuration and project setu
4105
4328
  var agents = program.command("agents").description("Manage agent definitions");
4106
4329
  agents.command("list").description("List available agents").option("--core", "show only core agents").option("--custom", "show only custom agents").action((options) => {
4107
4330
  try {
4108
- const customAgentsDir = join13(process.cwd(), "coreai", "agents");
4331
+ const customAgentsDir = join14(process.cwd(), "coreai", "agents");
4109
4332
  const allAgents = loadAllAgents({
4110
4333
  coreAgentsDir: getCoreAgentsPath(),
4111
4334
  customAgentsDir
@@ -4159,7 +4382,7 @@ agents.command("list").description("List available agents").option("--core", "sh
4159
4382
  });
4160
4383
  agents.command("show <name>").description("Show details for a specific agent").option("--markdown", "output as compiled markdown").option("--json", "output as JSON").action((name, options) => {
4161
4384
  try {
4162
- const customAgentsDir = join13(process.cwd(), "coreai", "agents");
4385
+ const customAgentsDir = join14(process.cwd(), "coreai", "agents");
4163
4386
  const allAgents = loadAllAgents({
4164
4387
  coreAgentsDir: getCoreAgentsPath(),
4165
4388
  customAgentsDir
@@ -4224,6 +4447,61 @@ ${agent.display_name}`);
4224
4447
  process.exit(1);
4225
4448
  }
4226
4449
  });
4450
+ agents.command("add <agents...>").description("Add agents to your project configuration").option("--all", "add all available core agents").option("--no-build", "skip rebuilding agents after adding").action(async (agentNames, options) => {
4451
+ try {
4452
+ const parsedAgents = agentNames.flatMap((a) => a.split(",").map((s) => s.trim()));
4453
+ const result = agentsAdd(parsedAgents, {
4454
+ projectRoot: process.cwd(),
4455
+ coreAgentsDir: getCoreAgentsPath(),
4456
+ all: options.all
4457
+ });
4458
+ console.log(formatAgentsAddResult(result));
4459
+ if (!result.success) {
4460
+ process.exit(1);
4461
+ }
4462
+ if (result.added.length > 0 && options.build !== false) {
4463
+ console.log("\nRebuilding agents...\n");
4464
+ const buildResult = build({
4465
+ projectRoot: process.cwd(),
4466
+ coreAgentsDir: getCoreAgentsPath()
4467
+ });
4468
+ console.log(formatBuildResult(buildResult));
4469
+ if (!buildResult.success) {
4470
+ process.exit(1);
4471
+ }
4472
+ }
4473
+ } catch (error) {
4474
+ console.error(`Failed to add agents: ${error instanceof Error ? error.message : error}`);
4475
+ process.exit(1);
4476
+ }
4477
+ });
4478
+ agents.command("remove <agents...>").description("Remove agents from your project configuration").option("--all", "remove all agents from config").option("--no-build", "skip rebuilding agents after removing").action(async (agentNames, options) => {
4479
+ try {
4480
+ const parsedAgents = agentNames.flatMap((a) => a.split(",").map((s) => s.trim()));
4481
+ const result = agentsRemove(parsedAgents, {
4482
+ projectRoot: process.cwd(),
4483
+ all: options.all
4484
+ });
4485
+ console.log(formatAgentsRemoveResult(result));
4486
+ if (!result.success) {
4487
+ process.exit(1);
4488
+ }
4489
+ if (result.removed.length > 0 && options.build !== false) {
4490
+ console.log("\nRebuilding agents...\n");
4491
+ const buildResult = build({
4492
+ projectRoot: process.cwd(),
4493
+ coreAgentsDir: getCoreAgentsPath()
4494
+ });
4495
+ console.log(formatBuildResult(buildResult));
4496
+ if (!buildResult.success) {
4497
+ process.exit(1);
4498
+ }
4499
+ }
4500
+ } catch (error) {
4501
+ console.error(`Failed to remove agents: ${error instanceof Error ? error.message : error}`);
4502
+ process.exit(1);
4503
+ }
4504
+ });
4227
4505
  var cacheCmd = program.command("cache").description("Manage local cache");
4228
4506
  cacheCmd.command("clear").description("Clear the local cache").option("--expired", "only clear expired entries").option("--json", "output as JSON").action(async (options) => {
4229
4507
  try {