lemma-agent 1.1.1 → 1.1.3
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/admin.js +79 -5
- package/dist/change-ops.js +84 -0
- package/dist/cli-runner.js +34 -0
- package/dist/config.js +44 -0
- package/dist/dispatch.js +15 -1
- package/dist/jobs.js +14 -0
- package/dist/main.js +64 -4
- package/dist/onboarding.js +428 -0
- package/dist/proxy.js +204 -67
- package/dist/terminal.js +59 -31
- package/dist/tools.js +1 -0
- package/package.json +1 -1
- package/web/js/editors.js +96 -0
- package/web/js/gitlens.js +178 -11
- package/web/js/views.js +32 -5
- package/web/style.css +71 -0
package/dist/admin.js
CHANGED
|
@@ -8,7 +8,7 @@ import { extname, join, normalize } from "node:path";
|
|
|
8
8
|
import { fileURLToPath } from "node:url";
|
|
9
9
|
import { agentAdapter } from "./agents.js";
|
|
10
10
|
import { memberKey, memberToolNames } from "./api-member.js";
|
|
11
|
-
import { applyChange, cleanChanges, dropChange } from "./change-ops.js";
|
|
11
|
+
import { applyChange, buildChangeDeliveryDraft, cleanChanges, dropChange, formatChangeRevisionPrompt } from "./change-ops.js";
|
|
12
12
|
import { commitManagedRepo, fetchManagedRepo, GitWorkbench, inspectRepoCommit, inspectRepoGraph, listManagedRepos, pullManagedRepo, pushManagedRepo, resolvePushGate, setGitPushPolicy, } from "./git-workbench.js";
|
|
13
13
|
import { Operations, operationList, resolveOperation } from "./operations.js";
|
|
14
14
|
import { CostLedger, Resources, resourceSnapshot } from "./resources.js";
|
|
@@ -27,6 +27,8 @@ import { Integrations, integrationSummary } from "./integrations.js";
|
|
|
27
27
|
import { readyTasks } from "./task-readiness.js";
|
|
28
28
|
import { Workflow } from "./task-workflow.js";
|
|
29
29
|
import { discoverLocalAccounts } from "./account-discovery.js";
|
|
30
|
+
import { applyOnboardingPlan, ONBOARDING_PRESETS } from "./onboarding.js";
|
|
31
|
+
import { orchestratorKeyWarning } from "./models.js";
|
|
30
32
|
import { parseToolResult, toViewItem, toViewLive } from "./view.js";
|
|
31
33
|
const WEB_DIR = fileURLToPath(new URL("../web/", import.meta.url));
|
|
32
34
|
const HOST = "127.0.0.1";
|
|
@@ -530,11 +532,19 @@ async function createAdminBinding(options, startedAt) {
|
|
|
530
532
|
items.sort((a, b) => a.id - b.id);
|
|
531
533
|
return { items, hasMore };
|
|
532
534
|
}
|
|
533
|
-
/**
|
|
535
|
+
/** 后台派工列表:进行中的在前,带最近的实时输出与运行子状态 */
|
|
534
536
|
function jobList() {
|
|
535
537
|
return Object.values(jobs)
|
|
536
538
|
.sort((a, b) => Number(b.status === "running") - Number(a.status === "running") || b.startedAt - a.startedAt)
|
|
537
|
-
.map((j) =>
|
|
539
|
+
.map((j) => {
|
|
540
|
+
const rt = j.status === "running" ? app.jobs.runtimeState(j.id) : undefined;
|
|
541
|
+
return {
|
|
542
|
+
...j,
|
|
543
|
+
waiter: undefined,
|
|
544
|
+
output: j.status === "running" ? app.jobs.recent(j.id).slice(-20) : undefined,
|
|
545
|
+
...(rt ? { runtimeState: rt.state, runtimeDetail: rt.detail } : {}),
|
|
546
|
+
};
|
|
547
|
+
});
|
|
538
548
|
}
|
|
539
549
|
/**
|
|
540
550
|
* 协作拓扑:总调度 → 成员 → 会话(泳道)→ 每次派工(时间条),加上「基于某次改动」的依赖。
|
|
@@ -785,6 +795,8 @@ async function createAdminBinding(options, startedAt) {
|
|
|
785
795
|
...app.proxy.snapshot(),
|
|
786
796
|
discoveredAccounts: discoverLocalAccounts(config),
|
|
787
797
|
},
|
|
798
|
+
needsOnboarding: Boolean(orchestratorKeyWarning(config.orchestrator)),
|
|
799
|
+
onboardingPresets: ONBOARDING_PRESETS,
|
|
788
800
|
uxTelemetry: computeUxMetrics(((await harness.snapshot(UxTelemetry, context))?.events ?? [])),
|
|
789
801
|
modelStats: modelStats(),
|
|
790
802
|
project: {
|
|
@@ -1324,6 +1336,30 @@ async function createAdminBinding(options, startedAt) {
|
|
|
1324
1336
|
}));
|
|
1325
1337
|
return sendJson(res, 200, out);
|
|
1326
1338
|
}
|
|
1339
|
+
if (url.pathname === "/api/onboarding" && req.method === "POST") {
|
|
1340
|
+
const out = await mutateSettings(req, true, (body, draft, current) => {
|
|
1341
|
+
const mode = body.mode;
|
|
1342
|
+
if (mode !== "native" && mode !== "byok" && mode !== "relay")
|
|
1343
|
+
throw new Error("mode 需要为 native、byok 或 relay");
|
|
1344
|
+
const { next, summary } = applyOnboardingPlan(draft, current, {
|
|
1345
|
+
mode,
|
|
1346
|
+
preset: typeof body.preset === "string" ? body.preset : undefined,
|
|
1347
|
+
type: body.type === "anthropic-compatible" || body.type === "openai-compatible" ? body.type : undefined,
|
|
1348
|
+
baseUrl: typeof body.baseUrl === "string" ? body.baseUrl : undefined,
|
|
1349
|
+
modelId: typeof body.modelId === "string" ? body.modelId : undefined,
|
|
1350
|
+
secret: typeof body.secret === "string" ? body.secret : undefined,
|
|
1351
|
+
relayUrl: typeof body.relayUrl === "string" ? body.relayUrl : undefined,
|
|
1352
|
+
strategy: body.strategy === "order" || body.strategy === "rotate" ? body.strategy : undefined,
|
|
1353
|
+
enableBridge: typeof body.enableBridge === "boolean" ? body.enableBridge : undefined,
|
|
1354
|
+
enableProxy: typeof body.enableProxy === "boolean" ? body.enableProxy : undefined,
|
|
1355
|
+
redactAction: body.redactAction === "mask" || body.redactAction === "warn" || body.redactAction === "block" ? body.redactAction : undefined,
|
|
1356
|
+
compactModel: typeof body.compactModel === "string" ? body.compactModel : undefined,
|
|
1357
|
+
perRunUsd: body.perRunUsd === null || body.perRunUsd === "" ? null : body.perRunUsd === undefined ? undefined : Number(body.perRunUsd),
|
|
1358
|
+
});
|
|
1359
|
+
return { next, notify: `后台网页:${summary}`, result: { summary } };
|
|
1360
|
+
});
|
|
1361
|
+
return sendJson(res, 200, out);
|
|
1362
|
+
}
|
|
1327
1363
|
if (url.pathname === "/api/autonomy" && req.method === "POST") {
|
|
1328
1364
|
const out = await mutateSettings(req, false, (body, draft, current) => {
|
|
1329
1365
|
const checks = body.checks === undefined ? undefined : Array.isArray(body.checks) ? body.checks.map((item) => {
|
|
@@ -1364,10 +1400,48 @@ async function createAdminBinding(options, startedAt) {
|
|
|
1364
1400
|
options.notify?.(`后台网页:${r.message}`);
|
|
1365
1401
|
return sendJson(res, r.ok ? 200 : 409, r);
|
|
1366
1402
|
}
|
|
1367
|
-
const
|
|
1403
|
+
const changeDraft = url.pathname.match(/^\/api\/changes\/([^/]+)\/draft$/);
|
|
1404
|
+
if (changeDraft && req.method === "GET") {
|
|
1405
|
+
const id = decodeURIComponent(changeDraft[1]);
|
|
1406
|
+
const change = changes.get(id);
|
|
1407
|
+
if (!change)
|
|
1408
|
+
throw new HttpError(404, `找不到改动 ${id}`);
|
|
1409
|
+
return sendJson(res, 200, buildChangeDeliveryDraft(change));
|
|
1410
|
+
}
|
|
1411
|
+
const changeAction = url.pathname.match(/^\/api\/changes\/([^/]+)\/(apply|drop|revise)$/);
|
|
1368
1412
|
if (changeAction && req.method === "POST") {
|
|
1369
|
-
await readControlBody(req);
|
|
1413
|
+
const body = await readControlBody(req, 32768);
|
|
1370
1414
|
const id = decodeURIComponent(changeAction[1]);
|
|
1415
|
+
if (changeAction[2] === "revise") {
|
|
1416
|
+
const target = changes.get(id);
|
|
1417
|
+
if (!target)
|
|
1418
|
+
throw new HttpError(404, `找不到改动 ${id}`);
|
|
1419
|
+
if (target.status !== "pending" && target.status !== "conflict") {
|
|
1420
|
+
throw new HttpError(409, `改动 #${id} 当前状态为 ${target.status},无法打回修改`);
|
|
1421
|
+
}
|
|
1422
|
+
const rawComments = Array.isArray(body.comments) ? body.comments.slice(0, 50) : [];
|
|
1423
|
+
const comments = rawComments
|
|
1424
|
+
.map((item) => {
|
|
1425
|
+
if (!item || typeof item !== "object")
|
|
1426
|
+
return undefined;
|
|
1427
|
+
const rec = item;
|
|
1428
|
+
const noteText = typeof rec.note === "string" ? rec.note.trim().slice(0, 1000) : "";
|
|
1429
|
+
if (!noteText)
|
|
1430
|
+
return undefined;
|
|
1431
|
+
const file = typeof rec.file === "string" ? rec.file.trim().slice(0, 300) || undefined : undefined;
|
|
1432
|
+
const line = typeof rec.line === "number" && Number.isFinite(rec.line) && rec.line > 0 ? Math.trunc(rec.line) : undefined;
|
|
1433
|
+
return { file, line, note: noteText };
|
|
1434
|
+
})
|
|
1435
|
+
.filter((x) => Boolean(x));
|
|
1436
|
+
const overallNote = typeof body.note === "string" ? body.note.trim().slice(0, 2000) : "";
|
|
1437
|
+
if (!comments.length && !overallNote) {
|
|
1438
|
+
throw new HttpError(400, "请至少填写一条修改意见或行级批注");
|
|
1439
|
+
}
|
|
1440
|
+
const prompt = formatChangeRevisionPrompt(target, comments, overallNote);
|
|
1441
|
+
await root.submit({ type: "input", content: prompt, whenBusy: "followUp" }, context);
|
|
1442
|
+
options.notify?.(`后台网页:已将改动 #${id} 打回修改(${comments.length} 条批注)`);
|
|
1443
|
+
return sendJson(res, 200, { ok: true, changeId: id, commentCount: comments.length });
|
|
1444
|
+
}
|
|
1371
1445
|
const r = changeAction[2] === "apply" ? await applyChange(changes, id) : await dropChange(changes, id);
|
|
1372
1446
|
if (!r.ok)
|
|
1373
1447
|
throw new HttpError(r.message.startsWith("找不到") ? 404 : 409, r.message);
|
package/dist/change-ops.js
CHANGED
|
@@ -1,5 +1,89 @@
|
|
|
1
1
|
import { applyRange, removeWorktree, git } from "./git.js";
|
|
2
2
|
import { integrationStale, integrationGit } from "./integration-git.js";
|
|
3
|
+
function inferCommitType(task) {
|
|
4
|
+
const t = task.toLowerCase();
|
|
5
|
+
if (/(fix|bug|修复|报错|异常|崩溃|故障)/.test(t))
|
|
6
|
+
return "fix";
|
|
7
|
+
if (/(test|spec|单测|测试|覆盖)/.test(t))
|
|
8
|
+
return "test";
|
|
9
|
+
if (/(doc|readme|文档|说明|注释)/.test(t))
|
|
10
|
+
return "docs";
|
|
11
|
+
if (/(refactor|cleanup|重构|清理|整理|拆分)/.test(t))
|
|
12
|
+
return "refactor";
|
|
13
|
+
if (/(chore|build|ci|deps|升级|依赖|发布)/.test(t))
|
|
14
|
+
return "chore";
|
|
15
|
+
return "feat";
|
|
16
|
+
}
|
|
17
|
+
function shellDoubleQuote(value) {
|
|
18
|
+
return `"${value.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\$/g, "\\$").replace(/`/g, "\\`")}"`;
|
|
19
|
+
}
|
|
20
|
+
/** 根据人工在 Diff 中的行级批注生成结构化打回修改指令 */
|
|
21
|
+
export function formatChangeRevisionPrompt(change, comments, note) {
|
|
22
|
+
const cleaned = comments
|
|
23
|
+
.map((c) => ({
|
|
24
|
+
file: c.file?.trim() || undefined,
|
|
25
|
+
line: typeof c.line === "number" && Number.isFinite(c.line) && c.line > 0 ? Math.trunc(c.line) : undefined,
|
|
26
|
+
note: c.note.trim(),
|
|
27
|
+
}))
|
|
28
|
+
.filter((c) => c.note.length > 0);
|
|
29
|
+
const summary = note?.trim();
|
|
30
|
+
const lines = [
|
|
31
|
+
`[网页 Diff 审查打回] 请针对改动 #${change.id}(成员 ${change.agent} · 分支 ${change.branch})进行定点修改:`,
|
|
32
|
+
`原任务:${change.task}`,
|
|
33
|
+
...(summary ? [`总体审查意见:${summary}`] : []),
|
|
34
|
+
...(cleaned.length
|
|
35
|
+
? [
|
|
36
|
+
"逐行/逐文件批注:",
|
|
37
|
+
...cleaned.map((c) => {
|
|
38
|
+
const loc = c.file ? (c.line ? `\`${c.file}:${c.line}\`` : `\`${c.file}\``) : "整体改动";
|
|
39
|
+
return `- ${loc}: ${c.note}`;
|
|
40
|
+
}),
|
|
41
|
+
]
|
|
42
|
+
: []),
|
|
43
|
+
`请优先续接该任务对应的成员会话或基于改动 #${change.id} 所在范围返工并运行验证,勿修改无关文件。`,
|
|
44
|
+
];
|
|
45
|
+
return lines.join("\n");
|
|
46
|
+
}
|
|
47
|
+
/** 基于改动元信息、盲审/集成报告与文件统计生成 Commit Message 与 PR 草稿 */
|
|
48
|
+
export function buildChangeDeliveryDraft(change) {
|
|
49
|
+
const cleanTask = change.task.replace(/\s+/g, " ").trim() || `apply change #${change.id}`;
|
|
50
|
+
const prefix = inferCommitType(cleanTask);
|
|
51
|
+
const shortSubject = cleanTask.length > 60 ? `${cleanTask.slice(0, 57)}...` : cleanTask;
|
|
52
|
+
const commitTitle = `${prefix}(${change.agent}): ${shortSubject}`;
|
|
53
|
+
const fileSummary = change.files.slice(0, 12).map((f) => `- ${f.path} (+${f.add} -${f.del})`);
|
|
54
|
+
if (change.files.length > 12)
|
|
55
|
+
fileSummary.push(`- ... 其余 ${change.files.length - 12} 个文件`);
|
|
56
|
+
const reports = change.integration?.reports ?? [];
|
|
57
|
+
const reportLines = reports.map((r) => `- [${r.passed ? "PASS" : "FAIL"}] ${r.name}`);
|
|
58
|
+
if (change.verification && !reports.length) {
|
|
59
|
+
reportLines.push(`- [${change.verification.passed ? "PASS" : "FAIL"}] verification (${change.verification.head.slice(0, 7)})`);
|
|
60
|
+
}
|
|
61
|
+
const commitBodyParts = [
|
|
62
|
+
`Change: #${change.id} (${change.agent} · branch ${change.branch})`,
|
|
63
|
+
`Stats: ${change.files.length} files, +${change.add} -${change.del}`,
|
|
64
|
+
...(fileSummary.length ? ["Files:", ...fileSummary] : []),
|
|
65
|
+
...(reportLines.length ? ["Checks:", ...reportLines] : []),
|
|
66
|
+
];
|
|
67
|
+
const commitBody = commitBodyParts.join("\n");
|
|
68
|
+
const commitMessage = `${commitTitle}\n\n${commitBody}`;
|
|
69
|
+
const prTitle = `[Lemma #${change.id}] ${shortSubject}`;
|
|
70
|
+
const prBody = [
|
|
71
|
+
"## 变更目标",
|
|
72
|
+
cleanTask,
|
|
73
|
+
"",
|
|
74
|
+
`## 改动文件 (${change.files.length} 个文件, +${change.add} / -${change.del})`,
|
|
75
|
+
...(fileSummary.length ? fileSummary : ["- (无文件列表)"]),
|
|
76
|
+
"",
|
|
77
|
+
"## 验证与集成报告",
|
|
78
|
+
...(reportLines.length ? reportLines : ["- 已通过人工工作区审查,待合并后提交验证"]),
|
|
79
|
+
"",
|
|
80
|
+
"## 协作来源",
|
|
81
|
+
`- 执行成员:\`${change.agent}\`${change.model ? ` (\`${change.model}\`)` : ""}`,
|
|
82
|
+
`- 改动分支:\`${change.branch}\`(改动 #${change.id})`,
|
|
83
|
+
].join("\n");
|
|
84
|
+
const ghCommand = `gh pr create --title ${shellDoubleQuote(prTitle)} --body ${shellDoubleQuote(prBody.replace(/\r?\n/g, "\\n"))}`;
|
|
85
|
+
return { commitTitle, commitBody, commitMessage, prTitle, prBody, ghCommand };
|
|
86
|
+
}
|
|
3
87
|
function find(store, id) {
|
|
4
88
|
return id ? store.get(id) : undefined;
|
|
5
89
|
}
|
package/dist/cli-runner.js
CHANGED
|
@@ -1,6 +1,40 @@
|
|
|
1
1
|
// 启动本机 AI CLI 子进程:提示词走 stdin(避免 Windows 命令行转义问题),
|
|
2
2
|
// 支持超时、中止(杀整个进程树)和逐行输出回调。
|
|
3
3
|
import { spawn } from "node:child_process";
|
|
4
|
+
const OSC_TITLE_RE = /\x1b\](?:0|2);([^\x07\x1b]*)(?:\x07|\x1b\\)/g;
|
|
5
|
+
const ANSI_ESCAPE_RE = /\x1b(?:\][^\x07\x1b]*(?:\x07|\x1b\\)|\[[0-?]*[ -/]*[@-~]|[@-Z\\-_])/g;
|
|
6
|
+
function cleanCliLine(raw) {
|
|
7
|
+
const titles = [];
|
|
8
|
+
for (const m of raw.matchAll(OSC_TITLE_RE)) {
|
|
9
|
+
const t = m[1]?.trim();
|
|
10
|
+
if (t)
|
|
11
|
+
titles.push(t);
|
|
12
|
+
}
|
|
13
|
+
const text = raw.replace(ANSI_ESCAPE_RE, "").replace(/\s+/g, " ").trim();
|
|
14
|
+
return { text, titles };
|
|
15
|
+
}
|
|
16
|
+
/** 根据 CLI 子进程 stdout/stderr/OSC 标题识别细粒度实时状态 */
|
|
17
|
+
export function detectCliRuntimeState(line, stream) {
|
|
18
|
+
const { text, titles } = cleanCliLine(line);
|
|
19
|
+
const probe = [text, ...titles].filter(Boolean).join(" | ");
|
|
20
|
+
if (!probe)
|
|
21
|
+
return undefined;
|
|
22
|
+
if (/\b(?:not logged in|login required|authentication failed|invalid api key|token expired|unauthorized)\b|please run\b.*\blogin\b|登录已过期|未登录|需要登录/i.test(probe)) {
|
|
23
|
+
return { state: "auth_expired", detail: (text || titles[0] || "登录态失效").slice(0, 140) };
|
|
24
|
+
}
|
|
25
|
+
if (/\b(?:rate[- ]?limit|too many requests|quota exceeded|overloaded|retry-after)\b|\b429\b/i.test(probe)) {
|
|
26
|
+
return { state: "rate_limited", detail: (text || titles[0] || "触发限流").slice(0, 140) };
|
|
27
|
+
}
|
|
28
|
+
if (/\((?:y\/n|Y\/n|y\/N)\)|\[(?:Y\/n|y\/N|y\/n)\]|waiting for input|press enter to|do you want to|allow .*?\?|confirm to proceed|approve\?/i.test(probe)) {
|
|
29
|
+
return { state: "waiting_input", detail: (text || titles[0] || "等待确认/输入").slice(0, 140) };
|
|
30
|
+
}
|
|
31
|
+
if (stream === "stdout" &&
|
|
32
|
+
(/\b(?:reading|writing|editing|running|searching|thinking|tool_use|content_block)\b/i.test(text) ||
|
|
33
|
+
(text.startsWith("{") && text.includes('"type"')))) {
|
|
34
|
+
return { state: "working", detail: text.slice(0, 120) };
|
|
35
|
+
}
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
4
38
|
/** Windows 上 kill() 只杀外层进程,需要 taskkill /T 杀掉整棵进程树 */
|
|
5
39
|
function killTree(pid) {
|
|
6
40
|
if (pid === undefined)
|
package/dist/config.js
CHANGED
|
@@ -373,6 +373,49 @@ export function normalizeProxy(raw) {
|
|
|
373
373
|
const bridgeMap = normalizeModelMap(input.anthropicBridge.modelMap, "proxy.anthropicBridge.modelMap");
|
|
374
374
|
anthropicBridge = { enabled: input.anthropicBridge.enabled, ...up, ...(bridgeMap ? { modelMap: bridgeMap } : {}) };
|
|
375
375
|
}
|
|
376
|
+
let groups;
|
|
377
|
+
if (input.groups !== undefined) {
|
|
378
|
+
if (!input.groups || typeof input.groups !== "object" || Array.isArray(input.groups))
|
|
379
|
+
throw new Error("proxy.groups 需要为对象。");
|
|
380
|
+
const outGroups = {};
|
|
381
|
+
for (const proto of ["anthropic", "openai", "gemini"]) {
|
|
382
|
+
const g = input.groups[proto];
|
|
383
|
+
if (g === undefined)
|
|
384
|
+
continue;
|
|
385
|
+
if (!g || typeof g !== "object" || Array.isArray(g))
|
|
386
|
+
throw new Error(`proxy.groups.${proto} 需要为对象。`);
|
|
387
|
+
if (g.strategy !== "order" && g.strategy !== "rotate")
|
|
388
|
+
throw new Error(`proxy.groups.${proto}.strategy 需要为 order 或 rotate。`);
|
|
389
|
+
if (!Array.isArray(g.targets) || !g.targets.length)
|
|
390
|
+
throw new Error(`proxy.groups.${proto}.targets 需要非空数组。`);
|
|
391
|
+
outGroups[proto] = {
|
|
392
|
+
strategy: g.strategy,
|
|
393
|
+
targets: g.targets.map((t, idx) => {
|
|
394
|
+
const label = `proxy.groups.${proto}.targets[${idx}]`;
|
|
395
|
+
if (!t || typeof t !== "object" || typeof t.baseUrl !== "string")
|
|
396
|
+
throw new Error(`${label} 需要对象及 baseUrl。`);
|
|
397
|
+
if (t.protocol !== undefined && !["anthropic", "openai", "gemini"].includes(t.protocol))
|
|
398
|
+
throw new Error(`${label}.protocol 需要为 anthropic、openai 或 gemini。`);
|
|
399
|
+
if (t.name !== undefined && (typeof t.name !== "string" || !t.name.trim()))
|
|
400
|
+
throw new Error(`${label}.name 需要非空字符串。`);
|
|
401
|
+
if (t.model !== undefined && (typeof t.model !== "string" || !t.model.trim()))
|
|
402
|
+
throw new Error(`${label}.model 需要非空字符串。`);
|
|
403
|
+
const up = normalizeProxyUpstream(t, {}, label);
|
|
404
|
+
return {
|
|
405
|
+
...(t.name ? { name: t.name.trim() } : {}),
|
|
406
|
+
...(t.protocol ? { protocol: t.protocol } : {}),
|
|
407
|
+
baseUrl: validateHttpUrl(t.baseUrl, `${label}.baseUrl`),
|
|
408
|
+
...(t.model ? { model: t.model.trim() } : {}),
|
|
409
|
+
...(up.apiKeyEnv ? { apiKeyEnv: up.apiKeyEnv } : {}),
|
|
410
|
+
...(up.apiKeys ? { apiKeys: up.apiKeys } : {}),
|
|
411
|
+
...(up.credentials ? { credentials: up.credentials } : {}),
|
|
412
|
+
};
|
|
413
|
+
}),
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
if (Object.keys(outGroups).length)
|
|
417
|
+
groups = outGroups;
|
|
418
|
+
}
|
|
376
419
|
const upIn = (input.upstreams ?? {});
|
|
377
420
|
return {
|
|
378
421
|
enabled: input.enabled ?? d.enabled,
|
|
@@ -395,6 +438,7 @@ export function normalizeProxy(raw) {
|
|
|
395
438
|
...(modelMap ? { modelMap } : {}),
|
|
396
439
|
...(input.compactModel ? { compactModel: input.compactModel.trim() } : {}),
|
|
397
440
|
...(anthropicBridge ? { anthropicBridge } : {}),
|
|
441
|
+
...(groups ? { groups } : {}),
|
|
398
442
|
upstreams: {
|
|
399
443
|
anthropic: normalizeProxyUpstream(upIn.anthropic, d.upstreams.anthropic, "proxy.upstreams.anthropic"),
|
|
400
444
|
openai: normalizeProxyUpstream(upIn.openai, d.upstreams.openai, "proxy.upstreams.openai"),
|
package/dist/dispatch.js
CHANGED
|
@@ -7,7 +7,7 @@ import { dirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
|
7
7
|
import { defineDoc, LiveDoc } from "@earendil-works/pi-durable";
|
|
8
8
|
import { agentAdapter } from "./agents.js";
|
|
9
9
|
import { Board, taskBrief } from "./board.js";
|
|
10
|
-
import { cleanEnv, runCli } from "./cli-runner.js";
|
|
10
|
+
import { cleanEnv, detectCliRuntimeState, runCli } from "./cli-runner.js";
|
|
11
11
|
import { autonomyChecksForRoot } from "./config.js";
|
|
12
12
|
import { WORKTREE_CONVENTION_FILES } from "./conventions.js";
|
|
13
13
|
import { addWorktree, commitAll, git, linkIgnoredDirs, numstat, repoRoot, snapshot } from "./git.js";
|
|
@@ -594,6 +594,7 @@ export async function runDispatch(kind, command, deps, args, io, label = kind) {
|
|
|
594
594
|
callId: io.callId,
|
|
595
595
|
model,
|
|
596
596
|
});
|
|
597
|
+
let lastRuntimeAlert;
|
|
597
598
|
try {
|
|
598
599
|
result = await runCli({
|
|
599
600
|
command: command[0],
|
|
@@ -604,6 +605,19 @@ export async function runDispatch(kind, command, deps, args, io, label = kind) {
|
|
|
604
605
|
timeoutMs: agent.timeoutMinutes * 60_000,
|
|
605
606
|
signal: io.signal,
|
|
606
607
|
onLine: (line, stream) => {
|
|
608
|
+
const detected = detectCliRuntimeState(line, stream);
|
|
609
|
+
if (detected) {
|
|
610
|
+
io.onRuntimeState?.(detected.state, detected.detail);
|
|
611
|
+
if (detected.state !== "working" && detected.state !== lastRuntimeAlert) {
|
|
612
|
+
lastRuntimeAlert = detected.state;
|
|
613
|
+
const label = detected.state === "waiting_input"
|
|
614
|
+
? "CLI 等待交互确认"
|
|
615
|
+
: detected.state === "auth_expired"
|
|
616
|
+
? "CLI 登录/凭据异常"
|
|
617
|
+
: "CLI 触发上游限流";
|
|
618
|
+
io.output(`[${label}] ${detected.detail}\n`);
|
|
619
|
+
}
|
|
620
|
+
}
|
|
607
621
|
if (stream !== "stdout")
|
|
608
622
|
return;
|
|
609
623
|
const p = adapter.progress(line);
|
package/dist/jobs.js
CHANGED
|
@@ -43,6 +43,7 @@ export function clip(text, max) {
|
|
|
43
43
|
export class JobHub extends EventEmitter {
|
|
44
44
|
controllers = new Map();
|
|
45
45
|
lines = new Map();
|
|
46
|
+
states = new Map();
|
|
46
47
|
/** 正在执行的会话:同一个会话不能同时被两次派工续接 */
|
|
47
48
|
busySessions = new Map();
|
|
48
49
|
/** 进程正在关闭:被打断的派工不收尾,重启后续接 */
|
|
@@ -56,8 +57,21 @@ export class JobHub extends EventEmitter {
|
|
|
56
57
|
release(id) {
|
|
57
58
|
const entry = this.controllers.get(id);
|
|
58
59
|
this.controllers.delete(id);
|
|
60
|
+
this.states.delete(id);
|
|
59
61
|
return entry?.by;
|
|
60
62
|
}
|
|
63
|
+
setRuntimeState(id, state, detail) {
|
|
64
|
+
const prev = this.states.get(id);
|
|
65
|
+
if (prev?.state === state && prev?.detail === detail)
|
|
66
|
+
return;
|
|
67
|
+
this.states.set(id, { state, ...(detail ? { detail } : {}), updatedAt: Date.now() });
|
|
68
|
+
this.emit("state", id, state, detail);
|
|
69
|
+
if (prev?.state !== state)
|
|
70
|
+
this.changed();
|
|
71
|
+
}
|
|
72
|
+
runtimeState(id) {
|
|
73
|
+
return this.states.get(id);
|
|
74
|
+
}
|
|
61
75
|
running(id) {
|
|
62
76
|
return this.controllers.has(id);
|
|
63
77
|
}
|
package/dist/main.js
CHANGED
|
@@ -18,6 +18,8 @@ import { initRules, scanConventions, syncRules } from "./conventions.js";
|
|
|
18
18
|
import { openApp } from "./app.js";
|
|
19
19
|
import { loadConfig, sameConfigRepoRoot } from "./config.js";
|
|
20
20
|
import { memberSettingsCommand, MEMBER_HELP } from "./member-settings.js";
|
|
21
|
+
import { createBootPrompter, needsFirstRunOnboarding, runTerminalOnboarding } from "./onboarding.js";
|
|
22
|
+
import { editSettings } from "./settings.js";
|
|
21
23
|
import { clip, Jobs } from "./jobs.js";
|
|
22
24
|
import { createOrchestratorModel, orchestratorKeyWarning } from "./models.js";
|
|
23
25
|
import { controllerModels, nativeModelCatalog, selectControllerModel, restoreControllerModel } from "./model-selection.js";
|
|
@@ -169,6 +171,7 @@ export async function startMain(overrides) {
|
|
|
169
171
|
collaboration: next.collaboration,
|
|
170
172
|
execution: next.execution,
|
|
171
173
|
budget: next.budget,
|
|
174
|
+
proxy: next.proxy,
|
|
172
175
|
autonomy: sameConfigRepoRoot(runtime.config.workdir, next) ? next.autonomy : { ...next.autonomy, checks: [] },
|
|
173
176
|
...(controller ? { orchestrator: next.orchestrator } : {}),
|
|
174
177
|
};
|
|
@@ -373,7 +376,7 @@ export async function startMain(overrides) {
|
|
|
373
376
|
log(c.dim(`工作目录:${config.workdir}`));
|
|
374
377
|
log(c.dim(`配置文件:${configPath}`));
|
|
375
378
|
log(c.dim(`会话存储:${config.storage}`));
|
|
376
|
-
log(c.dim("/setup 配置总控 · /agent add 添加成员 · /agents 查看成员 · /help 操作帮助"));
|
|
379
|
+
log(c.dim("/onboarding 引导初始化 · /setup 配置总控 · /agent add 添加成员 · /agents 查看成员 · /help 操作帮助"));
|
|
377
380
|
if (admin)
|
|
378
381
|
log(`${c.dim("后台网页:")}${c.cyan(admin.url)}`);
|
|
379
382
|
for (const a of agents) {
|
|
@@ -381,7 +384,7 @@ export async function startMain(overrides) {
|
|
|
381
384
|
}
|
|
382
385
|
const authWarn = orchestratorKeyWarning(config.orchestrator);
|
|
383
386
|
if (authWarn)
|
|
384
|
-
log(c.yellow(`⚠ ${authWarn}
|
|
387
|
+
log(c.yellow(`⚠ ${authWarn}(可执行 /onboarding 快速初始化)`));
|
|
385
388
|
}
|
|
386
389
|
async function shutdown(code = 0) {
|
|
387
390
|
if (closing)
|
|
@@ -655,6 +658,25 @@ export async function startMain(overrides) {
|
|
|
655
658
|
}
|
|
656
659
|
}
|
|
657
660
|
async function command(line) {
|
|
661
|
+
if (line === "/onboarding") {
|
|
662
|
+
if (configuring || switchingSession || closing)
|
|
663
|
+
throw new Error("当前正在配置、切换或退出。");
|
|
664
|
+
configuring = true;
|
|
665
|
+
try {
|
|
666
|
+
await runTerminalOnboarding({
|
|
667
|
+
config,
|
|
668
|
+
draftFactory: () => editSettings(configPath),
|
|
669
|
+
ask: (prompt) => settingQuestion(prompt),
|
|
670
|
+
select: terminalUI ? (opts) => terminalUI.select(opts) : undefined,
|
|
671
|
+
commit: commitSettings,
|
|
672
|
+
log,
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
finally {
|
|
676
|
+
configuring = false;
|
|
677
|
+
}
|
|
678
|
+
return true;
|
|
679
|
+
}
|
|
658
680
|
if (/^\/fast(?:\s|$)/.test(line)) {
|
|
659
681
|
const rest = line.slice(5).trim();
|
|
660
682
|
if (!rest) {
|
|
@@ -1410,8 +1432,26 @@ export async function startMain(overrides) {
|
|
|
1410
1432
|
const [jobs, budget] = await Promise.all([activeApp.harness.snapshot(Jobs, context), activeApp.harness.snapshot(RunBudget, context)]);
|
|
1411
1433
|
if (!current())
|
|
1412
1434
|
return;
|
|
1413
|
-
|
|
1414
|
-
|
|
1435
|
+
const proxySnap = activeApp.proxy.snapshot();
|
|
1436
|
+
ui.setStatus({
|
|
1437
|
+
busy,
|
|
1438
|
+
jobs: Object.values(jobs?.jobs ?? {})
|
|
1439
|
+
.filter((j) => j.status === "running")
|
|
1440
|
+
.map((j) => {
|
|
1441
|
+
const rt = activeApp.jobs.runtimeState(j.id)?.state;
|
|
1442
|
+
const tag = rt === "waiting_input" ? " [等输入]" : rt === "auth_expired" ? " [需登录]" : rt === "rate_limited" ? " [限流]" : "";
|
|
1443
|
+
return `${j.id} ${j.agent}${tag}`;
|
|
1444
|
+
}),
|
|
1445
|
+
spent: budget?.spent ?? 0,
|
|
1446
|
+
budget: config.budget.perRunUsd,
|
|
1447
|
+
pending: pendingChanges(activeApp.changes).length,
|
|
1448
|
+
proxy: {
|
|
1449
|
+
enabled: proxySnap.enabled,
|
|
1450
|
+
cooled: proxySnap.pool.cooledKeys.length,
|
|
1451
|
+
retries: proxySnap.totals.retries,
|
|
1452
|
+
blocked: proxySnap.totals.blocked,
|
|
1453
|
+
},
|
|
1454
|
+
});
|
|
1415
1455
|
} while (refreshAgain && current());
|
|
1416
1456
|
}
|
|
1417
1457
|
catch (error) {
|
|
@@ -1470,6 +1510,26 @@ export async function startMain(overrides) {
|
|
|
1470
1510
|
}
|
|
1471
1511
|
else {
|
|
1472
1512
|
await startWeb();
|
|
1513
|
+
if (needsFirstRunOnboarding(config, flags)) {
|
|
1514
|
+
const prompter = createBootPrompter();
|
|
1515
|
+
configuring = true;
|
|
1516
|
+
try {
|
|
1517
|
+
await runTerminalOnboarding({
|
|
1518
|
+
config,
|
|
1519
|
+
draftFactory: () => editSettings(configPath),
|
|
1520
|
+
ask: ({ title, secret }) => prompter.question(title, secret),
|
|
1521
|
+
commit: commitSettings,
|
|
1522
|
+
log,
|
|
1523
|
+
});
|
|
1524
|
+
}
|
|
1525
|
+
catch (error) {
|
|
1526
|
+
log(c.yellow(`引导未完成:${error instanceof Error ? error.message : String(error)}(稍后可执行 /onboarding 继续)`));
|
|
1527
|
+
}
|
|
1528
|
+
finally {
|
|
1529
|
+
configuring = false;
|
|
1530
|
+
prompter.close();
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1473
1533
|
const useTui = flags.has("--tui") && !flags.has("--plain") && process.stdin.isTTY && process.stdout.isTTY && process.env.TERM !== "dumb";
|
|
1474
1534
|
if (useTui) {
|
|
1475
1535
|
await startTui().catch(async (error) => {
|