agency-orchestrator 0.5.2 → 0.6.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/cli/compose.js +7 -4
- package/dist/cli.js +79 -73
- package/dist/connectors/claude-code.js +2 -1
- package/dist/connectors/cli-base.js +2 -1
- package/dist/core/dag.js +7 -6
- package/dist/core/parser.js +9 -11
- package/dist/i18n.d.ts +19 -0
- package/dist/i18n.js +258 -0
- package/dist/utils/env-loader.d.ts +9 -0
- package/dist/utils/env-loader.js +110 -0
- package/package.json +1 -1
- package/workflows/academic-paper-outline.yaml +168 -0
- package/workflows/douyin-script.yaml +137 -0
- package/workflows/investment-analysis.yaml +128 -0
- package/workflows/legal-consultation.yaml +143 -0
- package/workflows/resume-and-interview-prep.yaml +116 -0
- package/workflows//345/210/206/346/236/220/346/212/226/351/237/263/347/237/255/350/247/206/351/242/221/350/265/233/351/201/223/347/232/204/345/210/233/344/270/232/346/234/272/344/274/232/347/273/231/345/207/272/345/256/214/346/225/264/345/225/206/344/270/232/346/226/271/346/241/210.yaml +0 -190
- package/workflows//345/220/210/345/220/214/345/256/241/346/237/245.yaml +0 -106
- package/workflows//346/210/221/346/230/257/344/270/200/344/270/252/347/250/213/345/272/217/345/221/230/346/203/263/347/224/250ai/345/201/232/350/207/252/345/252/222/344/275/223/345/211/257/344/270/232/347/233/256/346/240/207/346/234/210/345/205/2452/344/270/207/345/270/256/346/210/221/345/201/232/345/256/214/346/225/264/347/232/204/345/217/257/350/241/214/346/200/247/345/210/206/346/236/220/345/271/263/345/217/260/351/200/211/346/213/251/345/206/205/345/256/271.yaml +0 -116
- package/workflows//346/210/221/346/230/257/344/270/200/344/270/252/347/250/213/345/272/217/345/221/230/346/203/263/347/224/250ai/345/201/232/350/207/252/345/252/222/344/275/223/345/211/257/344/270/232/347/233/256/346/240/207/346/234/210/345/205/2452/344/270/207/345/270/256/346/210/221/345/201/232/345/256/214/346/225/264/350/247/204/345/210/222.yaml +0 -98
- package/workflows//346/210/221/346/234/210/350/226/2521/344/270/207/344/270/213/347/217/255/345/220/216/346/203/263/346/220/236/345/211/257/344/270/232/345/270/256/346/210/221/345/210/206/346/236/220/351/200/202/345/220/210/346/210/221/347/232/204/346/226/271/345/220/221/345/271/266/347/273/231/345/207/272/345/205/267/344/275/223/346/211/247/350/241/214/350/256/241/345/210/222.yaml +0 -136
package/dist/cli/compose.js
CHANGED
|
@@ -8,6 +8,7 @@ import { listAgents } from '../agents/loader.js';
|
|
|
8
8
|
import { existsSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
9
9
|
import { resolve, relative } from 'node:path';
|
|
10
10
|
import { createConnector } from '../connectors/factory.js';
|
|
11
|
+
import { t } from '../i18n.js';
|
|
11
12
|
/**
|
|
12
13
|
* 从 agents 目录构建精简的角色目录
|
|
13
14
|
*/
|
|
@@ -299,7 +300,7 @@ export async function composeWorkflow(options) {
|
|
|
299
300
|
// 1. 构建角色目录
|
|
300
301
|
const roles = buildRoleCatalog(agentsDir);
|
|
301
302
|
if (roles.length === 0) {
|
|
302
|
-
throw new Error(
|
|
303
|
+
throw new Error(t('compose.empty_catalog', { dir: agentsDir }));
|
|
303
304
|
}
|
|
304
305
|
const catalog = formatCatalogForPrompt(roles);
|
|
305
306
|
// 2. 构建 prompt
|
|
@@ -311,7 +312,7 @@ export async function composeWorkflow(options) {
|
|
|
311
312
|
});
|
|
312
313
|
const userPrompt = buildComposeUserPrompt(description, lang);
|
|
313
314
|
// 3. 调用 LLM
|
|
314
|
-
console.log(`
|
|
315
|
+
console.log(` ${t('compose.generating', { n: roles.length })}\n`);
|
|
315
316
|
const connector = createConnector(llmConfig);
|
|
316
317
|
const result = await connector.chat(systemPrompt, userPrompt, {
|
|
317
318
|
...llmConfig,
|
|
@@ -320,7 +321,7 @@ export async function composeWorkflow(options) {
|
|
|
320
321
|
// 4. 提取 YAML
|
|
321
322
|
const yaml = extractYamlFromResponse(result.content);
|
|
322
323
|
if (!yaml || !yaml.includes('steps:')) {
|
|
323
|
-
throw new Error('
|
|
324
|
+
throw new Error(t('compose.invalid_yaml'));
|
|
324
325
|
}
|
|
325
326
|
// 5. 保存(避免覆盖)
|
|
326
327
|
const workflowsDir = resolve('workflows');
|
|
@@ -333,7 +334,9 @@ export async function composeWorkflow(options) {
|
|
|
333
334
|
const savedPath = resolve(workflowsDir, fileName);
|
|
334
335
|
writeFileSync(savedPath, yaml + '\n', 'utf-8');
|
|
335
336
|
const relativePath = relative(process.cwd(), savedPath);
|
|
336
|
-
|
|
337
|
+
if (process.env.AO_VERBOSE) {
|
|
338
|
+
console.log(` ${t('compose.tokens', { in: result.usage.input_tokens, out: result.usage.output_tokens })}`);
|
|
339
|
+
}
|
|
337
340
|
// 6. 校验生成的 YAML(含角色路径真实性校验,防 LLM 幻觉)
|
|
338
341
|
const warnings = [];
|
|
339
342
|
const validRolePaths = new Set(roles.map(r => r.path));
|
package/dist/cli.js
CHANGED
|
@@ -16,8 +16,20 @@ import { buildDAG, formatDAG } from './core/dag.js';
|
|
|
16
16
|
import { listAgents } from './agents/loader.js';
|
|
17
17
|
import { run } from './index.js';
|
|
18
18
|
import { scheduleUpdateCheck } from './utils/version-check.js';
|
|
19
|
+
import { t, detectLang } from './i18n.js';
|
|
20
|
+
import { loadEnvFile, writeEnvFile, ensureEnvGitignored } from './utils/env-loader.js';
|
|
21
|
+
// Auto-load ./.env (shell env wins; no overwrite)
|
|
22
|
+
loadEnvFile();
|
|
23
|
+
// Suppress Node's DEP0190 warning from legitimate shell:true on Windows (.cmd shims).
|
|
24
|
+
const origEmit = process.emit.bind(process);
|
|
25
|
+
process.emit = function (name, data, ...rest) {
|
|
26
|
+
if (name === 'warning' && data && data.code === 'DEP0190')
|
|
27
|
+
return false;
|
|
28
|
+
return origEmit(name, data, ...rest);
|
|
29
|
+
};
|
|
19
30
|
const args = process.argv.slice(2);
|
|
20
31
|
const command = args[0];
|
|
32
|
+
detectLang(process.argv);
|
|
21
33
|
async function main() {
|
|
22
34
|
// 启动时提示新版本(仅 TTY,24h 缓存,失败静默)
|
|
23
35
|
scheduleUpdateCheck(getVersion());
|
|
@@ -84,8 +96,9 @@ async function handleRun() {
|
|
|
84
96
|
const watch = args.includes('--watch');
|
|
85
97
|
let resumeDir = getArgValue('--resume');
|
|
86
98
|
const fromStep = getArgValue('--from');
|
|
87
|
-
|
|
88
|
-
const
|
|
99
|
+
// Precedence: CLI flag > .env (AO_PROVIDER/AO_MODEL) > YAML
|
|
100
|
+
const provider = (getArgValue('--provider') || process.env.AO_PROVIDER);
|
|
101
|
+
const model = getArgValue('--model') || process.env.AO_MODEL;
|
|
89
102
|
// --resume last: 自动找最近一次的输出目录
|
|
90
103
|
if (resumeDir === 'last') {
|
|
91
104
|
const { findLatestOutput } = await import('./output/reporter.js');
|
|
@@ -123,18 +136,18 @@ async function handleRun() {
|
|
|
123
136
|
function handleValidate() {
|
|
124
137
|
const filePath = args[1];
|
|
125
138
|
if (!filePath) {
|
|
126
|
-
console.error('
|
|
139
|
+
console.error(t('validate.usage'));
|
|
127
140
|
process.exit(1);
|
|
128
141
|
}
|
|
129
142
|
try {
|
|
130
143
|
const workflow = parseWorkflow(resolve(filePath));
|
|
131
144
|
const errors = validateWorkflow(workflow);
|
|
132
145
|
if (errors.length === 0) {
|
|
133
|
-
console.log(` ${workflow.name}
|
|
134
|
-
console.log(` ${workflow.steps.length
|
|
146
|
+
console.log(` ${t('validate.ok', { name: workflow.name })}`);
|
|
147
|
+
console.log(` ${t('validate.stats', { steps: workflow.steps.length, inputs: (workflow.inputs || []).length })}`);
|
|
135
148
|
}
|
|
136
149
|
else {
|
|
137
|
-
console.error(` ${workflow.name}
|
|
150
|
+
console.error(` ${t('validate.failed', { name: workflow.name })}\n`);
|
|
138
151
|
for (const err of errors) {
|
|
139
152
|
console.error(` - ${err}`);
|
|
140
153
|
}
|
|
@@ -142,21 +155,21 @@ function handleValidate() {
|
|
|
142
155
|
}
|
|
143
156
|
}
|
|
144
157
|
catch (err) {
|
|
145
|
-
console.error(
|
|
158
|
+
console.error(`${t('error.prefix')}: ${err instanceof Error ? err.message : err}`);
|
|
146
159
|
process.exit(1);
|
|
147
160
|
}
|
|
148
161
|
}
|
|
149
162
|
function handlePlan() {
|
|
150
163
|
const filePath = args[1];
|
|
151
164
|
if (!filePath) {
|
|
152
|
-
console.error('
|
|
165
|
+
console.error(t('plan.usage'));
|
|
153
166
|
process.exit(1);
|
|
154
167
|
}
|
|
155
168
|
try {
|
|
156
169
|
const workflow = parseWorkflow(resolve(filePath));
|
|
157
170
|
const errors = validateWorkflow(workflow);
|
|
158
171
|
if (errors.length > 0) {
|
|
159
|
-
console.error(
|
|
172
|
+
console.error(`${t('plan.validate_failed')}\n${errors.map(e => ` - ${e}`).join('\n')}`);
|
|
160
173
|
process.exit(1);
|
|
161
174
|
}
|
|
162
175
|
const dag = buildDAG(workflow);
|
|
@@ -164,7 +177,7 @@ function handlePlan() {
|
|
|
164
177
|
console.log(formatDAG(dag));
|
|
165
178
|
}
|
|
166
179
|
catch (err) {
|
|
167
|
-
console.error(
|
|
180
|
+
console.error(`${t('error.prefix')}: ${err instanceof Error ? err.message : err}`);
|
|
168
181
|
process.exit(1);
|
|
169
182
|
}
|
|
170
183
|
}
|
|
@@ -242,10 +255,10 @@ async function handleCompose() {
|
|
|
242
255
|
autoRun,
|
|
243
256
|
lang: composeLang,
|
|
244
257
|
});
|
|
245
|
-
console.log(`\n
|
|
258
|
+
console.log(`\n ${t('compose.generated', { path: relativePath })}\n`);
|
|
246
259
|
// 校验警告
|
|
247
260
|
if (warnings.length > 0) {
|
|
248
|
-
console.log(
|
|
261
|
+
console.log(` ${t('compose.warnings_header')}`);
|
|
249
262
|
for (const w of warnings) {
|
|
250
263
|
console.log(` - ${w}`);
|
|
251
264
|
}
|
|
@@ -253,13 +266,13 @@ async function handleCompose() {
|
|
|
253
266
|
}
|
|
254
267
|
if (autoRun) {
|
|
255
268
|
// --run 模式:校验有严重问题时不执行
|
|
256
|
-
if (warnings.some(w => w.includes('解析失败'))) {
|
|
257
|
-
console.error(
|
|
269
|
+
if (warnings.some(w => w.includes('解析失败') || w.toLowerCase().includes('parse failed'))) {
|
|
270
|
+
console.error(` ${t('compose.retry_yaml_bad')}`);
|
|
258
271
|
console.error(` ao run ${relativePath}`);
|
|
259
272
|
process.exit(1);
|
|
260
273
|
}
|
|
261
274
|
console.log('─'.repeat(50));
|
|
262
|
-
console.log(
|
|
275
|
+
console.log(` ${t('compose.auto_running')}\n`);
|
|
263
276
|
// 保底:如果 LLM 仍然生成了 required inputs,用用户描述填充
|
|
264
277
|
const { parseWorkflow } = await import('./core/parser.js');
|
|
265
278
|
const workflow = parseWorkflow(resolve(savedPath));
|
|
@@ -278,7 +291,7 @@ async function handleCompose() {
|
|
|
278
291
|
process.exit(result.success ? 0 : 1);
|
|
279
292
|
}
|
|
280
293
|
// 非 --run 模式:显示预览和下一步提示
|
|
281
|
-
console.log(
|
|
294
|
+
console.log(` ${t('compose.preview')}`);
|
|
282
295
|
const previewLines = yaml.split('\n').slice(0, 30);
|
|
283
296
|
for (const line of previewLines) {
|
|
284
297
|
console.log(` ${line}`);
|
|
@@ -287,14 +300,14 @@ async function handleCompose() {
|
|
|
287
300
|
console.log(' ...');
|
|
288
301
|
}
|
|
289
302
|
console.log('');
|
|
290
|
-
console.log(
|
|
291
|
-
console.log(` ao validate ${relativePath}
|
|
292
|
-
console.log(` ao plan ${relativePath}
|
|
293
|
-
console.log(` ao run ${relativePath}
|
|
303
|
+
console.log(` ${t('compose.next_steps')}`);
|
|
304
|
+
console.log(` ao validate ${relativePath} ${t('compose.next.validate')}`);
|
|
305
|
+
console.log(` ao plan ${relativePath} ${t('compose.next.plan')}`);
|
|
306
|
+
console.log(` ao run ${relativePath} ${t('compose.next.run')}`);
|
|
294
307
|
console.log('');
|
|
295
308
|
}
|
|
296
309
|
catch (err) {
|
|
297
|
-
console.error(`\n
|
|
310
|
+
console.error(`\n${t('error.prefix')}: ${err instanceof Error ? err.message : err}`);
|
|
298
311
|
process.exit(1);
|
|
299
312
|
}
|
|
300
313
|
}
|
|
@@ -326,6 +339,50 @@ async function handleInit() {
|
|
|
326
339
|
await interactiveInitWorkflow();
|
|
327
340
|
return;
|
|
328
341
|
}
|
|
342
|
+
// ao init --provider X --model Y --base-url Z --api-key K → write ./.env
|
|
343
|
+
const cfgProvider = getArgValue('--provider');
|
|
344
|
+
const cfgModel = getArgValue('--model');
|
|
345
|
+
const cfgBaseUrl = getArgValue('--base-url') || getArgValue('--baseurl');
|
|
346
|
+
const cfgApiKey = getArgValue('--api-key') || getArgValue('--apikey');
|
|
347
|
+
if (cfgProvider || cfgModel || cfgBaseUrl || cfgApiKey) {
|
|
348
|
+
const updates = {};
|
|
349
|
+
if (cfgProvider)
|
|
350
|
+
updates.AO_PROVIDER = cfgProvider;
|
|
351
|
+
if (cfgModel)
|
|
352
|
+
updates.AO_MODEL = cfgModel;
|
|
353
|
+
if (cfgBaseUrl) {
|
|
354
|
+
// Route to the env var the matching connector already reads
|
|
355
|
+
const p = (cfgProvider || '').toLowerCase();
|
|
356
|
+
const urlVar = p === 'ollama' ? 'OLLAMA_BASE_URL' :
|
|
357
|
+
'OPENAI_BASE_URL';
|
|
358
|
+
updates[urlVar] = cfgBaseUrl;
|
|
359
|
+
}
|
|
360
|
+
if (cfgApiKey) {
|
|
361
|
+
// Route api key to the provider-specific var the connectors already read
|
|
362
|
+
const p = (cfgProvider || process.env.AO_PROVIDER || '').toLowerCase();
|
|
363
|
+
const keyVar = p === 'deepseek' ? 'DEEPSEEK_API_KEY' :
|
|
364
|
+
p === 'openai' ? 'OPENAI_API_KEY' :
|
|
365
|
+
p === 'anthropic' || p === 'claude' ? 'ANTHROPIC_API_KEY' :
|
|
366
|
+
p === 'zhipu' || p === 'glm' ? 'ZHIPU_API_KEY' :
|
|
367
|
+
p === 'qwen' || p === 'dashscope' ? 'DASHSCOPE_API_KEY' :
|
|
368
|
+
p === 'moonshot' || p === 'kimi' ? 'MOONSHOT_API_KEY' :
|
|
369
|
+
'AO_API_KEY';
|
|
370
|
+
updates[keyVar] = cfgApiKey;
|
|
371
|
+
}
|
|
372
|
+
const envPath = resolve(process.cwd(), '.env');
|
|
373
|
+
writeEnvFile(updates);
|
|
374
|
+
const gitignoreUpdated = ensureEnvGitignored();
|
|
375
|
+
console.log(` ✅ 已写入 ${envPath}`);
|
|
376
|
+
for (const [k, v] of Object.entries(updates)) {
|
|
377
|
+
const shown = /KEY|TOKEN|SECRET/i.test(k) ? v.slice(0, 6) + '…' : v;
|
|
378
|
+
console.log(` ${k}=${shown}`);
|
|
379
|
+
}
|
|
380
|
+
if (gitignoreUpdated)
|
|
381
|
+
console.log(` 🔒 已将 .env 加入 .gitignore`);
|
|
382
|
+
console.log(`\n 下次运行 ao 时会自动加载这些配置。`);
|
|
383
|
+
console.log(` 也可手动编辑 .env 或复制到其他项目复用。`);
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
329
386
|
const lang = getArgValue('--lang') === 'en' ? 'en' : 'zh';
|
|
330
387
|
const pkgName = lang === 'en' ? 'agency-agents' : 'agency-agents-zh';
|
|
331
388
|
const gitRepo = lang === 'en'
|
|
@@ -512,57 +569,6 @@ function getVersion() {
|
|
|
512
569
|
}
|
|
513
570
|
}
|
|
514
571
|
function printHelp() {
|
|
515
|
-
console.log(
|
|
516
|
-
agency-orchestrator — Multi-Agent Workflow Engine
|
|
517
|
-
基于 agency-agents-zh 的多智能体编排引擎
|
|
518
|
-
|
|
519
|
-
Quick Start:
|
|
520
|
-
ao demo 零配置体验多智能体协作
|
|
521
|
-
ao init 下载 AI 角色定义(中文)
|
|
522
|
-
ao init --lang en Download English AI roles
|
|
523
|
-
ao roles 查看所有可用角色
|
|
524
|
-
ao plan <workflow.yaml> 查看执行计划 (DAG)
|
|
525
|
-
ao run <workflow.yaml> [options] 执行工作流
|
|
526
|
-
|
|
527
|
-
Commands:
|
|
528
|
-
demo 零配置体验多智能体协作(mock + 真实 AI)
|
|
529
|
-
init 下载/更新角色库 (--lang en 下载英文版)
|
|
530
|
-
init --workflow 交互式创建新工作流
|
|
531
|
-
compose "描述" AI 智能编排工作流(一句话生成 YAML)
|
|
532
|
-
compose "描述" --run 生成并立即运行(一句话出结果)
|
|
533
|
-
serve 启动 MCP Server(供 Claude Code / Cursor 调用)
|
|
534
|
-
run <workflow.yaml> 执行工作流
|
|
535
|
-
validate <workflow.yaml> 校验工作流定义
|
|
536
|
-
plan <workflow.yaml> 查看执行计划
|
|
537
|
-
explain <workflow.yaml> 用自然语言解释执行计划
|
|
538
|
-
roles [--agents-dir path] 列出可用角色
|
|
539
|
-
|
|
540
|
-
Options:
|
|
541
|
-
--input, -i key=value 传入输入变量
|
|
542
|
-
--input, -i key=@file 从文件读取变量值
|
|
543
|
-
--provider <name> 覆盖 YAML 中的 LLM provider (如 claude-code, deepseek)
|
|
544
|
-
--model <name> 覆盖 YAML 中的模型名
|
|
545
|
-
--output dir 输出目录 (默认 ao-output/)
|
|
546
|
-
--resume <dir|last> 从上次运行恢复(加载已完成步骤的输出)
|
|
547
|
-
--from <step-id> 配合 --resume,从指定步骤重新执行
|
|
548
|
-
--watch 实时进度显示(终端 UI)
|
|
549
|
-
--quiet, -q 静默模式
|
|
550
|
-
--version, -v 版本号
|
|
551
|
-
|
|
552
|
-
Examples:
|
|
553
|
-
ao init
|
|
554
|
-
ao compose "PR 代码审查,覆盖安全和性能"
|
|
555
|
-
ao run workflows/story-creation.yaml -i premise='一个时间旅行的故事' -i style='悬疑'
|
|
556
|
-
ao run workflows/product-review.yaml -i prd_content=@prd.md
|
|
557
|
-
ao plan workflows/content-pipeline.yaml
|
|
558
|
-
|
|
559
|
-
Resume (基于上次结果迭代):
|
|
560
|
-
ao run workflow.yaml --resume last # 跳过上次已完成的步骤
|
|
561
|
-
ao run workflow.yaml --resume last --from summary # 从 summary 步骤重新执行
|
|
562
|
-
ao run workflow.yaml --resume ao-output/xxx/ # 指定具体输出目录
|
|
563
|
-
|
|
564
|
-
Agents (中文): https://github.com/jnMetaCode/agency-agents-zh
|
|
565
|
-
Agents (English): https://github.com/msitarzewski/agency-agents
|
|
566
|
-
`);
|
|
572
|
+
console.log(t('help.text'));
|
|
567
573
|
}
|
|
568
574
|
main();
|
|
@@ -13,6 +13,7 @@ import { spawn } from 'node:child_process';
|
|
|
13
13
|
import { writeFileSync, unlinkSync } from 'node:fs';
|
|
14
14
|
import { tmpdir } from 'node:os';
|
|
15
15
|
import { join } from 'node:path';
|
|
16
|
+
import { t } from '../i18n.js';
|
|
16
17
|
export class ClaudeCodeConnector {
|
|
17
18
|
async chat(systemPrompt, userMessage, config) {
|
|
18
19
|
const timeout = config.timeout || 600_000; // 默认 10 分钟
|
|
@@ -69,7 +70,7 @@ export class ClaudeCodeConnector {
|
|
|
69
70
|
if (now - lastProgressTime > 10_000) {
|
|
70
71
|
lastProgressTime = now;
|
|
71
72
|
const kb = (receivedBytes / 1024).toFixed(1);
|
|
72
|
-
process.stderr.write(`
|
|
73
|
+
process.stderr.write(` ${t('stream.received', { size: kb })}\n`);
|
|
73
74
|
}
|
|
74
75
|
});
|
|
75
76
|
child.stderr.on('data', (chunk) => { stderr += chunk.toString(); });
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* 避免 ENAMETOOLONG 错误(GitHub issue #1)
|
|
9
9
|
*/
|
|
10
10
|
import { spawn } from 'node:child_process';
|
|
11
|
+
import { t } from '../i18n.js';
|
|
11
12
|
/**
|
|
12
13
|
* 命令行参数安全长度上限
|
|
13
14
|
* claude -p 等 CLI 工具通过命令行参数传大 prompt 会严重变慢
|
|
@@ -60,7 +61,7 @@ export class CLIBaseConnector {
|
|
|
60
61
|
if (now - lastProgressTime > 10_000) {
|
|
61
62
|
lastProgressTime = now;
|
|
62
63
|
const kb = (receivedBytes / 1024).toFixed(1);
|
|
63
|
-
process.stderr.write(`
|
|
64
|
+
process.stderr.write(` ${t('stream.received', { size: kb })}\n`);
|
|
64
65
|
}
|
|
65
66
|
});
|
|
66
67
|
child.stderr.on('data', (chunk) => { stderr += chunk.toString(); });
|
package/dist/core/dag.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { t } from '../i18n.js';
|
|
1
2
|
/**
|
|
2
3
|
* 从 WorkflowDefinition 构建 DAG
|
|
3
4
|
*/
|
|
@@ -82,7 +83,7 @@ function topologicalLevels(nodes) {
|
|
|
82
83
|
* 格式化 DAG 为可读文本(用于 `ao plan` 命令)
|
|
83
84
|
*/
|
|
84
85
|
export function formatDAG(dag) {
|
|
85
|
-
const lines = ['
|
|
86
|
+
const lines = [`${t('dag.title')}\n`];
|
|
86
87
|
for (let i = 0; i < dag.levels.length; i++) {
|
|
87
88
|
const level = dag.levels[i];
|
|
88
89
|
const parallel = level.length > 1;
|
|
@@ -90,16 +91,16 @@ export function formatDAG(dag) {
|
|
|
90
91
|
const node = dag.nodes.get(level[j]);
|
|
91
92
|
const step = node.step;
|
|
92
93
|
const prefix = parallel ? (j === 0 ? '┌' : j === level.length - 1 ? '└' : '├') : '→';
|
|
93
|
-
const tag = parallel ? '
|
|
94
|
-
lines.push(`
|
|
94
|
+
const tag = parallel ? t('dag.parallel') : '';
|
|
95
|
+
lines.push(` ${t('dag.layer', { n: i + 1 })} ${prefix} [${step.id}] ${step.role || step.type}${tag}`);
|
|
95
96
|
if (node.dependencies.length > 0) {
|
|
96
|
-
lines.push(`
|
|
97
|
+
lines.push(` ${t('dag.deps')}: ${node.dependencies.join(', ')}`);
|
|
97
98
|
}
|
|
98
99
|
if (step.condition) {
|
|
99
|
-
lines.push(`
|
|
100
|
+
lines.push(` ${t('dag.condition')}: ${step.condition}`);
|
|
100
101
|
}
|
|
101
102
|
if (step.loop) {
|
|
102
|
-
lines.push(`
|
|
103
|
+
lines.push(` ${t('dag.loop', { to: step.loop.back_to, n: step.loop.max_iterations })}`);
|
|
103
104
|
}
|
|
104
105
|
}
|
|
105
106
|
if (i < dag.levels.length - 1)
|
package/dist/core/parser.js
CHANGED
|
@@ -3,37 +3,38 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { readFileSync } from 'node:fs';
|
|
5
5
|
import yaml from 'js-yaml';
|
|
6
|
+
import { t } from '../i18n.js';
|
|
6
7
|
export function parseWorkflow(filePath) {
|
|
7
8
|
const raw = readFileSync(filePath, 'utf-8');
|
|
8
9
|
const doc = yaml.load(raw);
|
|
9
10
|
// 基本校验
|
|
10
11
|
if (!doc || typeof doc !== 'object') {
|
|
11
|
-
throw new Error(
|
|
12
|
+
throw new Error(t('parse.bad_yaml', { path: filePath }));
|
|
12
13
|
}
|
|
13
14
|
if (!doc.name || typeof doc.name !== 'string') {
|
|
14
|
-
throw new Error('
|
|
15
|
+
throw new Error(t('parse.missing_name'));
|
|
15
16
|
}
|
|
16
17
|
if (!doc.steps || !Array.isArray(doc.steps) || doc.steps.length === 0) {
|
|
17
|
-
throw new Error('
|
|
18
|
+
throw new Error(t('parse.missing_steps'));
|
|
18
19
|
}
|
|
19
20
|
if (!doc.llm || typeof doc.llm !== 'object') {
|
|
20
|
-
throw new Error('
|
|
21
|
+
throw new Error(t('parse.missing_llm'));
|
|
21
22
|
}
|
|
22
23
|
const llm = doc.llm;
|
|
23
24
|
if (!llm.provider) {
|
|
24
|
-
throw new Error('
|
|
25
|
+
throw new Error(t('parse.missing_provider'));
|
|
25
26
|
}
|
|
26
27
|
// CLI providers (claude-code, gemini-cli, copilot-cli, codex-cli, openclaw-cli, hermes-cli) 和 ollama 不需要 model
|
|
27
28
|
const cliProviders = ['claude-code', 'gemini-cli', 'copilot-cli', 'codex-cli', 'openclaw-cli', 'hermes-cli', 'ollama'];
|
|
28
29
|
if (!llm.model && !cliProviders.includes(llm.provider)) {
|
|
29
|
-
throw new Error('
|
|
30
|
+
throw new Error(t('parse.missing_model'));
|
|
30
31
|
}
|
|
31
32
|
// 校验每个 step
|
|
32
33
|
const stepIds = new Set();
|
|
33
34
|
const steps = doc.steps;
|
|
34
35
|
for (const step of steps) {
|
|
35
36
|
if (!step.id)
|
|
36
|
-
throw new Error('
|
|
37
|
+
throw new Error(t('parse.missing_step_id'));
|
|
37
38
|
if (stepIds.has(step.id))
|
|
38
39
|
throw new Error(`step id 重复: ${step.id}`);
|
|
39
40
|
stepIds.add(step.id);
|
|
@@ -101,10 +102,7 @@ export function validateWorkflow(workflow) {
|
|
|
101
102
|
if (!inputDef && !isOutput && varName !== '_loop_iteration') {
|
|
102
103
|
errors.push(`step "${step.id}" 引用了未定义的变量: {{${varName}}}`);
|
|
103
104
|
}
|
|
104
|
-
//
|
|
105
|
-
if (inputDef && !inputDef.required && inputDef.default === undefined) {
|
|
106
|
-
errors.push(`step "${step.id}" 使用了可选输入 {{${varName}}},但未设置默认值(未提供时为空字符串)`);
|
|
107
|
-
}
|
|
105
|
+
// 可选输入无默认值时,运行时自动填空字符串 — 非错误,不再警告
|
|
108
106
|
}
|
|
109
107
|
}
|
|
110
108
|
// 检查循环依赖
|
package/dist/i18n.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal i18n for CLI user-facing strings.
|
|
3
|
+
*
|
|
4
|
+
* Language detection priority:
|
|
5
|
+
* 1. --lang=en CLI flag
|
|
6
|
+
* 2. AO_LANG env var
|
|
7
|
+
* 3. LANG env var (en_US.UTF-8 → en)
|
|
8
|
+
* 4. Default: zh
|
|
9
|
+
*/
|
|
10
|
+
type Lang = 'zh' | 'en';
|
|
11
|
+
export declare function detectLang(argv?: string[]): Lang;
|
|
12
|
+
export declare function setLang(lang: Lang): void;
|
|
13
|
+
type Dict = Record<string, {
|
|
14
|
+
zh: string;
|
|
15
|
+
en: string;
|
|
16
|
+
}>;
|
|
17
|
+
declare const dict: Dict;
|
|
18
|
+
export declare function t(key: keyof typeof dict, params?: Record<string, string | number>): string;
|
|
19
|
+
export {};
|