@aigne/cli 1.0.0-2 → 1.0.0-20
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.js +2 -4
- package/dist/commands/aigne.js +13 -14
- package/dist/commands/create.js +26 -32
- package/dist/commands/run.js +12 -17
- package/dist/commands/test.js +7 -10
- package/dist/utils/ascii-logo.js +17 -0
- package/package.json +16 -15
- package/templates/default/aigne.yaml +2 -0
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const aigne_js_1 = require("./commands/aigne.js");
|
|
5
|
-
(0, aigne_js_1.createAIGNECommand)().parse();
|
|
2
|
+
import { createAIGNECommand } from "./commands/aigne.js";
|
|
3
|
+
createAIGNECommand().parse();
|
package/dist/commands/aigne.js
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return new commander_1.Command()
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import pkg from "../../package.json" with { type: "json" };
|
|
3
|
+
import { asciiLogo } from "../utils/ascii-logo.js";
|
|
4
|
+
import { createCreateCommand } from "./create.js";
|
|
5
|
+
import { createRunCommand } from "./run.js";
|
|
6
|
+
import { createTestCommand } from "./test.js";
|
|
7
|
+
export function createAIGNECommand() {
|
|
8
|
+
console.log(asciiLogo);
|
|
9
|
+
return new Command()
|
|
11
10
|
.name("aigne")
|
|
12
11
|
.description("CLI for AIGNE framework")
|
|
13
|
-
.version(
|
|
14
|
-
.addCommand(
|
|
15
|
-
.addCommand(
|
|
16
|
-
.addCommand(
|
|
12
|
+
.version(pkg.version)
|
|
13
|
+
.addCommand(createRunCommand())
|
|
14
|
+
.addCommand(createTestCommand())
|
|
15
|
+
.addCommand(createCreateCommand())
|
|
17
16
|
.showHelpAfterError(true)
|
|
18
17
|
.showSuggestionAfterError(true);
|
|
19
18
|
}
|
package/dist/commands/create.js
CHANGED
|
@@ -1,27 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const promises_1 = require("node:fs/promises");
|
|
9
|
-
const node_path_1 = require("node:path");
|
|
10
|
-
const commander_1 = require("commander");
|
|
11
|
-
const inquirer_1 = __importDefault(require("inquirer"));
|
|
12
|
-
function createCreateCommand() {
|
|
13
|
-
return new commander_1.Command("create")
|
|
1
|
+
import { existsSync, mkdirSync, readdirSync } from "node:fs";
|
|
2
|
+
import { cp } from "node:fs/promises";
|
|
3
|
+
import { isAbsolute, join, relative, resolve } from "node:path";
|
|
4
|
+
import { Command } from "commander";
|
|
5
|
+
import inquirer from "inquirer";
|
|
6
|
+
export function createCreateCommand() {
|
|
7
|
+
return new Command("create")
|
|
14
8
|
.description("Create a new aigne project with agent config files")
|
|
15
9
|
.argument("[path]", "Path to create the project directory", ".")
|
|
16
|
-
.action(async (
|
|
17
|
-
let
|
|
18
|
-
if (
|
|
19
|
-
const answers = await
|
|
10
|
+
.action(async (_path) => {
|
|
11
|
+
let path = _path;
|
|
12
|
+
if (path === ".") {
|
|
13
|
+
const answers = await inquirer.prompt([
|
|
20
14
|
{
|
|
21
15
|
type: "input",
|
|
22
16
|
name: "projectName",
|
|
23
17
|
message: "Project name:",
|
|
24
|
-
default:
|
|
18
|
+
default: _path !== "." ? _path : "my-aigne-project",
|
|
25
19
|
validate: (input) => {
|
|
26
20
|
if (input.trim() === "")
|
|
27
21
|
return "Project name cannot be empty.";
|
|
@@ -29,16 +23,16 @@ function createCreateCommand() {
|
|
|
29
23
|
},
|
|
30
24
|
},
|
|
31
25
|
]);
|
|
32
|
-
|
|
26
|
+
path = answers.projectName;
|
|
33
27
|
}
|
|
34
|
-
|
|
35
|
-
const isPathNotEmpty =
|
|
28
|
+
path = isAbsolute(path) ? path : resolve(process.cwd(), path);
|
|
29
|
+
const isPathNotEmpty = existsSync(path) && readdirSync(path).length > 0;
|
|
36
30
|
if (isPathNotEmpty) {
|
|
37
|
-
const answers = await
|
|
31
|
+
const answers = await inquirer.prompt([
|
|
38
32
|
{
|
|
39
33
|
type: "confirm",
|
|
40
34
|
name: "overwrite",
|
|
41
|
-
message: `The directory "${
|
|
35
|
+
message: `The directory "${path}" is not empty. Do you want to remove its contents?`,
|
|
42
36
|
default: false,
|
|
43
37
|
},
|
|
44
38
|
]);
|
|
@@ -48,7 +42,7 @@ function createCreateCommand() {
|
|
|
48
42
|
}
|
|
49
43
|
}
|
|
50
44
|
const templates = [{ name: "default" }];
|
|
51
|
-
const { template } = await
|
|
45
|
+
const { template } = await inquirer.prompt([
|
|
52
46
|
{
|
|
53
47
|
type: "list",
|
|
54
48
|
name: "template",
|
|
@@ -57,18 +51,18 @@ function createCreateCommand() {
|
|
|
57
51
|
default: "default",
|
|
58
52
|
},
|
|
59
53
|
]);
|
|
60
|
-
|
|
61
|
-
const templatePath = (
|
|
62
|
-
if (!
|
|
54
|
+
mkdirSync(path, { recursive: true });
|
|
55
|
+
const templatePath = join(import.meta.dirname, "../../templates", template);
|
|
56
|
+
if (!existsSync(templatePath))
|
|
63
57
|
throw new Error(`Template "${template}" not found.`);
|
|
64
|
-
const files =
|
|
58
|
+
const files = readdirSync(templatePath);
|
|
65
59
|
for (const file of files) {
|
|
66
|
-
const source =
|
|
67
|
-
const destination =
|
|
68
|
-
await
|
|
60
|
+
const source = join(templatePath, file);
|
|
61
|
+
const destination = join(path, file);
|
|
62
|
+
await cp(source, destination, { recursive: true, force: true });
|
|
69
63
|
}
|
|
70
64
|
console.log("\n✅ Aigne project created successfully!");
|
|
71
|
-
console.log(`\nTo use your new agent, run:\n cd ${path} &&
|
|
65
|
+
console.log(`\nTo use your new agent, run:\n cd ${relative(process.cwd(), path)} && aigne run`);
|
|
72
66
|
})
|
|
73
67
|
.showHelpAfterError(true)
|
|
74
68
|
.showSuggestionAfterError(true);
|
package/dist/commands/run.js
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const commander_1 = require("commander");
|
|
8
|
-
function createRunCommand() {
|
|
9
|
-
return new commander_1.Command("run")
|
|
1
|
+
import { isAbsolute, resolve } from "node:path";
|
|
2
|
+
import { ExecutionEngine } from "@aigne/core";
|
|
3
|
+
import { runChatLoopInTerminal } from "@aigne/core/utils/run-chat-loop.js";
|
|
4
|
+
import { Command } from "commander";
|
|
5
|
+
export function createRunCommand() {
|
|
6
|
+
return new Command("run")
|
|
10
7
|
.description("Run a chat loop with the specified agent")
|
|
11
8
|
.argument("[path]", "Path to the agents directory", ".")
|
|
12
9
|
.option("--agent <agent>", "Name of the agent to use (defaults to the first agent found)")
|
|
13
10
|
.action(async (path, options) => {
|
|
14
|
-
const absolutePath =
|
|
15
|
-
const engine = await
|
|
11
|
+
const absolutePath = isAbsolute(path) ? path : resolve(process.cwd(), path);
|
|
12
|
+
const engine = await ExecutionEngine.load({ path: absolutePath });
|
|
16
13
|
let agent;
|
|
17
14
|
if (options.agent) {
|
|
18
15
|
agent = engine.agents[options.agent];
|
|
@@ -22,18 +19,16 @@ function createRunCommand() {
|
|
|
22
19
|
for (const agent of engine.agents) {
|
|
23
20
|
console.log(`- ${agent.name}`);
|
|
24
21
|
}
|
|
25
|
-
|
|
22
|
+
throw new Error(`Agent "${options.agent}" not found`);
|
|
26
23
|
}
|
|
27
24
|
}
|
|
28
25
|
else {
|
|
29
26
|
agent = engine.agents[0];
|
|
30
|
-
if (!agent)
|
|
31
|
-
|
|
32
|
-
process.exit(1);
|
|
33
|
-
}
|
|
27
|
+
if (!agent)
|
|
28
|
+
throw new Error("No agents found in the specified path");
|
|
34
29
|
}
|
|
35
30
|
const user = engine.call(agent);
|
|
36
|
-
await
|
|
31
|
+
await runChatLoopInTerminal(user, {});
|
|
37
32
|
})
|
|
38
33
|
.showHelpAfterError(true)
|
|
39
34
|
.showSuggestionAfterError(true);
|
package/dist/commands/test.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const commander_1 = require("commander");
|
|
7
|
-
function createTestCommand() {
|
|
8
|
-
return new commander_1.Command("test")
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { isAbsolute, resolve } from "node:path";
|
|
3
|
+
import { Command } from "commander";
|
|
4
|
+
export function createTestCommand() {
|
|
5
|
+
return new Command("test")
|
|
9
6
|
.description("Run tests in the specified agents directory")
|
|
10
7
|
.argument("[path]", "Path to the agents directory", ".")
|
|
11
8
|
.action(async (path) => {
|
|
12
|
-
const absolutePath =
|
|
13
|
-
|
|
9
|
+
const absolutePath = isAbsolute(path) ? path : resolve(process.cwd(), path);
|
|
10
|
+
spawnSync("node", ["--test"], { cwd: absolutePath, stdio: "inherit" });
|
|
14
11
|
})
|
|
15
12
|
.showHelpAfterError(true)
|
|
16
13
|
.showSuggestionAfterError(true);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import gradient from "gradient-string";
|
|
3
|
+
import pkg from "../../package.json" with { type: "json" };
|
|
4
|
+
const modernGradient = gradient([
|
|
5
|
+
"#4facfe", // 天蓝色
|
|
6
|
+
"#7367f0", // 紫色
|
|
7
|
+
"#f86aad", // 粉红色
|
|
8
|
+
]);
|
|
9
|
+
const logo = `
|
|
10
|
+
_ ___ ____ _ _ _____
|
|
11
|
+
/ \\ |_ _/ ___| \\ | | ____|
|
|
12
|
+
/ _ \\ | | | _| \\| | _|
|
|
13
|
+
/ ___ \\ | | |_| | |\\ | |___
|
|
14
|
+
/_/ \\_\\___\\____|_| \\_|_____|
|
|
15
|
+
`;
|
|
16
|
+
const frameworkInfo = `v${pkg.version}`;
|
|
17
|
+
export const asciiLogo = `${modernGradient(logo)}\n\t${chalk.cyan(frameworkInfo)}\n\n`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aigne/cli",
|
|
3
|
-
"version": "1.0.0-
|
|
3
|
+
"version": "1.0.0-20",
|
|
4
4
|
"description": "cli for AIGNE framework",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -19,34 +19,35 @@
|
|
|
19
19
|
"CHANGELOG.md",
|
|
20
20
|
"templates"
|
|
21
21
|
],
|
|
22
|
+
"type": "module",
|
|
22
23
|
"bin": {
|
|
23
24
|
"aigne": "dist/cli.js"
|
|
24
25
|
},
|
|
25
26
|
"dependencies": {
|
|
27
|
+
"chalk": "^5.4.1",
|
|
26
28
|
"commander": "^13.1.0",
|
|
29
|
+
"gradient-string": "^3.0.0",
|
|
27
30
|
"inquirer": "^12.5.0",
|
|
28
|
-
"openai": "^4.
|
|
29
|
-
"
|
|
30
|
-
"@aigne/core": "^1.5.0"
|
|
31
|
+
"openai": "^4.91.1",
|
|
32
|
+
"@aigne/core": "^1.5.1-2"
|
|
31
33
|
},
|
|
32
34
|
"devDependencies": {
|
|
33
|
-
"@types/bun": "^1.2.
|
|
34
|
-
"@types/
|
|
35
|
+
"@types/bun": "^1.2.8",
|
|
36
|
+
"@types/gradient-string": "^1.1.6",
|
|
37
|
+
"@types/node": "^22.13.17",
|
|
35
38
|
"npm-run-all": "^4.1.5",
|
|
36
39
|
"rimraf": "^6.0.1",
|
|
37
40
|
"typescript": "^5.8.2"
|
|
38
41
|
},
|
|
39
|
-
"resolutions": {
|
|
40
|
-
"pkce-challenge": "^5.0.0"
|
|
41
|
-
},
|
|
42
|
-
"overrides": {
|
|
43
|
-
"pkce-challenge": "^5.0.0"
|
|
44
|
-
},
|
|
45
42
|
"scripts": {
|
|
46
43
|
"lint": "tsc --noEmit",
|
|
47
44
|
"build": "tsc --build tsconfig.build.json",
|
|
48
|
-
"clean": "rimraf dist coverage",
|
|
49
|
-
"test": "
|
|
50
|
-
"test:coverage": "
|
|
45
|
+
"clean": "rimraf dist test/coverage templates/coverage",
|
|
46
|
+
"test": "run-s test:src test:templates",
|
|
47
|
+
"test:coverage": "run-s test:src:coverage test:templates:coverage",
|
|
48
|
+
"test:src": "cd test && bun test/",
|
|
49
|
+
"test:src:coverage": "cd test && bun test --coverage --coverage-reporter=lcov --coverage-reporter=text",
|
|
50
|
+
"test:templates": "cd templates && node --test",
|
|
51
|
+
"test:templates:coverage": "cd templates && mkdir -p coverage && node --test --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=coverage/lcov.info --test-reporter=spec --test-reporter-destination=stdout"
|
|
51
52
|
}
|
|
52
53
|
}
|