@migor/cli 0.2.0 → 0.2.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.
- package/LICENSE +21 -0
- package/README.md +64 -0
- package/dist/AGENTS.md +811 -0
- package/dist/add.js +14 -12
- package/dist/cli.js +25 -15
- package/dist/create.js +47 -7
- package/dist/dev.js +61 -12
- package/dist/doctor.js +60 -32
- package/dist/generate.js +27 -15
- package/dist/inspector/fromTrace.js +144 -0
- package/dist/inspector/index.js +6 -0
- package/dist/inspector/summary.js +106 -0
- package/dist/inspector/trace-view.css +166 -0
- package/dist/inspector/view.js +274 -0
- package/dist/inspector-page.html +157 -0
- package/dist/inspector-preload.js +31 -0
- package/dist/inspector-sink.js +18 -0
- package/dist/inspector.js +166 -0
- package/dist/layout.js +44 -0
- package/dist/registry.js +19 -12
- package/dist/report.js +125 -0
- package/dist/templates.js +56 -31
- package/package.json +9 -3
package/dist/templates.js
CHANGED
|
@@ -14,16 +14,31 @@ export function kebabToPascal(name) {
|
|
|
14
14
|
export function kebabToSnake(name) {
|
|
15
15
|
return name.replace(/-/g, '_');
|
|
16
16
|
}
|
|
17
|
-
export const
|
|
18
|
-
export function
|
|
19
|
-
return
|
|
20
|
-
}
|
|
21
|
-
// ----------
|
|
17
|
+
export const CAPABILITY_TYPES = ['tool', 'skill', 'prompt', 'subagent'];
|
|
18
|
+
export function isCapabilityType(value) {
|
|
19
|
+
return CAPABILITY_TYPES.includes(value);
|
|
20
|
+
}
|
|
21
|
+
// ---------- 目录约定(spec §7:四分类目录,一能力一文件夹,无伞形词) ----------
|
|
22
|
+
/**
|
|
23
|
+
* 能力类型 → 分类目录。目录名即「里面装什么」,不再用一个需要图例解释的伞形词:
|
|
24
|
+
* 用户看一眼 `src/tools/weather/index.ts` 就知道它是工具。
|
|
25
|
+
*/
|
|
26
|
+
export const CAPABILITY_DIRS = {
|
|
27
|
+
tool: 'src/tools',
|
|
28
|
+
skill: 'src/skills',
|
|
29
|
+
prompt: 'src/prompts',
|
|
30
|
+
subagent: 'src/subagents',
|
|
31
|
+
};
|
|
32
|
+
/** 全部能力目录(顺序即 discover 的装配顺序) */
|
|
33
|
+
export const CAPABILITY_DIR_LIST = CAPABILITY_TYPES.map((t) => CAPABILITY_DIRS[t]);
|
|
34
|
+
/** 显式注册表位置(`agentia g` / `agentia add` 维护,`agentia doctor` 校验) */
|
|
35
|
+
export const REGISTRY_PATH = 'src/registry.ts';
|
|
36
|
+
// ---------- 注册表模板 ----------
|
|
22
37
|
export const IMPORTS_END_MARKER = '// @agentia:imports-end';
|
|
23
38
|
export const ENTRIES_END_MARKER = '// @agentia:entries-end';
|
|
24
|
-
/**
|
|
39
|
+
/** 空注册表模板(无任何能力条目) */
|
|
25
40
|
export function emptyRegistryTemplate() {
|
|
26
|
-
return `// Agentia
|
|
41
|
+
return `// Agentia 能力注册表 —— 由 agentia CLI 维护(agentia g 自动更新,也可手工编辑)
|
|
27
42
|
// @agentia:imports
|
|
28
43
|
${IMPORTS_END_MARKER}
|
|
29
44
|
import type { Provider } from '@migor/agentia';
|
|
@@ -45,7 +60,7 @@ export function projectPackageJson(name) {
|
|
|
45
60
|
dev: 'tsx src/main.ts',
|
|
46
61
|
typecheck: 'tsc --noEmit -p tsconfig.json',
|
|
47
62
|
},
|
|
48
|
-
dependencies: { '@migor/agentia': '^0.2.
|
|
63
|
+
dependencies: { '@migor/agentia': '^0.2.2' },
|
|
49
64
|
devDependencies: {
|
|
50
65
|
tsx: '^4.19.0',
|
|
51
66
|
typescript: '^7.0.2',
|
|
@@ -64,7 +79,7 @@ export function projectTsconfig() {
|
|
|
64
79
|
esModuleInterop: true,
|
|
65
80
|
skipLibCheck: true,
|
|
66
81
|
},
|
|
67
|
-
include: ['src'
|
|
82
|
+
include: ['src'],
|
|
68
83
|
}, null, 2)}\n`;
|
|
69
84
|
}
|
|
70
85
|
export function mainTs(name) {
|
|
@@ -72,47 +87,57 @@ export function mainTs(name) {
|
|
|
72
87
|
|
|
73
88
|
const app = await createApp({
|
|
74
89
|
name: '${name}',
|
|
75
|
-
discover: '
|
|
76
|
-
system: new SystemPrompt().add('role', '你是 ${name} 的主 agent
|
|
90
|
+
discover: [${CAPABILITY_DIR_LIST.map((p) => `'${p}'`).join(', ')}], // 四分类目录,顺序即装配顺序
|
|
91
|
+
system: new SystemPrompt().add('role', '你是 ${name} 的主 agent,按任务自主调度菜单里的能力。', true),
|
|
77
92
|
});
|
|
78
93
|
|
|
79
94
|
const { result } = await app.run(
|
|
80
95
|
[{ role: 'user', content: process.argv[2] ?? '介绍一下你自己' }],
|
|
81
96
|
);
|
|
82
|
-
|
|
97
|
+
|
|
98
|
+
// 注意:run 失败**不会抛**(硬失败被记进 result.error 与 trace 后正常返回)—— 不显式检查就会
|
|
99
|
+
// 「打印一行空白 + 退出 0」,让首次运行(比如忘了配 ANTHROPIC_API_KEY)看起来像成功。
|
|
100
|
+
if (result.error) {
|
|
101
|
+
console.error(\`run 失败(stopReason=\${result.stopReason}):\${result.error.message}\`);
|
|
102
|
+
console.error('提示:模型调用默认读 ANTHROPIC_API_KEY;换端点或注入 client 见项目内 AGENTS.md。');
|
|
103
|
+
process.exitCode = 1;
|
|
104
|
+
}
|
|
105
|
+
if (result.finalText) console.log(result.finalText);
|
|
83
106
|
`;
|
|
84
107
|
}
|
|
85
108
|
export function projectReadme(name) {
|
|
86
109
|
return `# ${name}
|
|
87
110
|
|
|
88
|
-
基于 [Agentia](https://github.com/) 框架的 agent 应用。
|
|
111
|
+
基于 [Agentia](https://github.com/retrychx/agentia) 框架的 agent 应用。
|
|
89
112
|
|
|
90
113
|
## 目录约定
|
|
91
114
|
|
|
92
|
-
|
|
115
|
+
四分类目录,一能力一文件夹,每个能力是一个 default export 的类,用装饰器声明:
|
|
116
|
+
|
|
117
|
+
- \`src/tools/<name>/\` —— \`@Tool\` 工具:主 agent 可调用(input → value)
|
|
118
|
+
- \`src/skills/<name>/\` —— \`@Skill\` 技能:方法体内通过 \`ctx.llm()\` 调 LLM
|
|
119
|
+
- \`src/subagents/<name>/\` —— \`@SubAgent\` 子代理:按 system 角色设定独立跑一轮
|
|
120
|
+
- \`src/prompts/<name>/\` —— \`@Prompt\` 文本资产:.md 文件,按需拉取进上下文
|
|
93
121
|
|
|
94
|
-
|
|
95
|
-
- \`@Skill\` 技能:方法体内通过 \`ctx.llm()\` 调 LLM
|
|
96
|
-
- \`@SubAgent\` 子代理:按 system 角色设定独立跑一轮
|
|
97
|
-
- \`@Prompt\` 文本资产:.md 文件,按需拉取进上下文
|
|
122
|
+
目录名就是类型,不用记别名。
|
|
98
123
|
|
|
99
124
|
## 两条装配路线
|
|
100
125
|
|
|
101
|
-
1. **目录扫描**:\`createApp({ discover:
|
|
102
|
-
2. **显式装配**:\`createApp({ providers, system })\`,providers 来自 \`
|
|
126
|
+
1. **目录扫描**:\`createApp({ discover: [...] })\` 启动期按给定顺序扫各目录下的 \`<name>/index.ts\`,default export 为类时以文件夹名为 DI token 注册(见 \`src/main.ts\`)。
|
|
127
|
+
2. **显式装配**:\`createApp({ providers, system })\`,providers 来自 \`src/registry.ts\` 注册表(由 \`agentia g\` 自动维护,也可手工编辑)。
|
|
103
128
|
|
|
104
129
|
两者二选一或混用。
|
|
105
130
|
|
|
106
|
-
##
|
|
131
|
+
## 生成能力
|
|
107
132
|
|
|
108
133
|
\`\`\`bash
|
|
109
|
-
agentia g tool my-tool #
|
|
110
|
-
agentia g skill my-skill #
|
|
111
|
-
agentia g prompt my-prompt #
|
|
112
|
-
agentia g subagent my-agent #
|
|
134
|
+
agentia g tool my-tool # → src/tools/my-tool/
|
|
135
|
+
agentia g skill my-skill # → src/skills/my-skill/
|
|
136
|
+
agentia g prompt my-prompt # → src/prompts/my-prompt/(含 asset.md)
|
|
137
|
+
agentia g subagent my-agent # → src/subagents/my-agent/(含 system.md)
|
|
113
138
|
\`\`\`
|
|
114
139
|
|
|
115
|
-
|
|
140
|
+
生成的能力自动登记到 \`src/registry.ts\`。
|
|
116
141
|
|
|
117
142
|
## 运行
|
|
118
143
|
|
|
@@ -129,13 +154,13 @@ export function projectGitignore() {
|
|
|
129
154
|
dist
|
|
130
155
|
`;
|
|
131
156
|
}
|
|
132
|
-
// ---------- g
|
|
157
|
+
// ---------- g 命令能力模板 ----------
|
|
133
158
|
export function toolIndexTs(name) {
|
|
134
159
|
const cls = kebabToPascal(name);
|
|
135
160
|
const method = kebabToSnake(name);
|
|
136
161
|
return `import { Tool } from '@migor/agentia';
|
|
137
162
|
|
|
138
|
-
/** ${name}
|
|
163
|
+
/** ${name} 工具能力 */
|
|
139
164
|
export default class ${cls} {
|
|
140
165
|
@Tool({
|
|
141
166
|
description: '示例工具:回显输入',
|
|
@@ -158,7 +183,7 @@ export function promptIndexTs(name) {
|
|
|
158
183
|
const method = kebabToSnake(name);
|
|
159
184
|
return `import { Prompt, asset } from '@migor/agentia';
|
|
160
185
|
|
|
161
|
-
/** ${name}
|
|
186
|
+
/** ${name} 文本资产能力 */
|
|
162
187
|
export default class ${cls} {
|
|
163
188
|
@Prompt({ description: '${name} 文本资产(描述何时该拉取)' })
|
|
164
189
|
${method}(): string {
|
|
@@ -178,7 +203,7 @@ export function subagentIndexTs(name) {
|
|
|
178
203
|
const method = kebabToSnake(name);
|
|
179
204
|
return `import { SubAgent, asset } from '@migor/agentia';
|
|
180
205
|
|
|
181
|
-
/** ${name}
|
|
206
|
+
/** ${name} 子代理能力 */
|
|
182
207
|
export default class ${cls} {
|
|
183
208
|
@SubAgent({
|
|
184
209
|
description: '示例子代理:按 system.md 的角色设定独立处理任务',
|
|
@@ -207,7 +232,7 @@ export function skillIndexTs(name) {
|
|
|
207
232
|
return `import { Skill } from '@migor/agentia';
|
|
208
233
|
import type { SkillContext } from '@migor/agentia';
|
|
209
234
|
|
|
210
|
-
/** ${name}
|
|
235
|
+
/** ${name} 技能能力 */
|
|
211
236
|
export default class ${cls} {
|
|
212
237
|
@Skill({
|
|
213
238
|
description: '示例技能:就给定主题调用 LLM 产出要点',
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@migor/cli",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"description": "Agentia 框架命令行工具:create 脚手架 + g
|
|
3
|
+
"version": "0.2.2",
|
|
4
|
+
"description": "Agentia 框架命令行工具:create 脚手架 + g 能力生成 + dev 本地可观测面板(trace inspector)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"agentia": "./dist/cli.js"
|
|
@@ -10,6 +10,11 @@
|
|
|
10
10
|
"dist"
|
|
11
11
|
],
|
|
12
12
|
"repository": "retrychx/agentia",
|
|
13
|
+
"homepage": "https://agentia-web.pages.dev",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/retrychx/agentia/issues"
|
|
16
|
+
},
|
|
17
|
+
"license": "MIT",
|
|
13
18
|
"keywords": [
|
|
14
19
|
"agentia",
|
|
15
20
|
"agent",
|
|
@@ -24,7 +29,8 @@
|
|
|
24
29
|
},
|
|
25
30
|
"scripts": {
|
|
26
31
|
"build": "tsc -p tsconfig.json",
|
|
27
|
-
"
|
|
32
|
+
"test": "node --test \"test/*.test.mjs\"",
|
|
33
|
+
"prepublishOnly": "node ../../scripts/check-release.mjs && npm run build"
|
|
28
34
|
},
|
|
29
35
|
"devDependencies": {
|
|
30
36
|
"@types/node": "^22.0.2",
|