@keyou007/agent-bot 0.1.25-alpha.1 → 0.1.25
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/CHANGELOG.md +29 -0
- package/README.md +34 -6
- package/README.zh.md +34 -6
- package/config.example.yaml +1 -3
- package/dist/cli/help.js +2 -0
- package/dist/cli/help.js.map +1 -1
- package/dist/codex/CodexRuntime.js +15 -5
- package/dist/codex/CodexRuntime.js.map +1 -1
- package/dist/commands/CommandRouter.js +3 -0
- package/dist/commands/CommandRouter.js.map +1 -1
- package/dist/config/SettingsStore.js +341 -0
- package/dist/config/SettingsStore.js.map +1 -0
- package/dist/config/loadConfig.js +1 -2
- package/dist/config/loadConfig.js.map +1 -1
- package/dist/config/schema.js +0 -1
- package/dist/config/schema.js.map +1 -1
- package/dist/console/ConsoleTurnPresenter.js +3 -0
- package/dist/console/ConsoleTurnPresenter.js.map +1 -1
- package/dist/feishu/CardRenderer.js +34 -99
- package/dist/feishu/CardRenderer.js.map +1 -1
- package/dist/feishu/FeishuConnector.js +9 -0
- package/dist/feishu/FeishuConnector.js.map +1 -1
- package/dist/feishu/FeishuMessageClient.js +23 -18
- package/dist/feishu/FeishuMessageClient.js.map +1 -1
- package/dist/feishu/FeishuTurnPresenter.js +36 -23
- package/dist/feishu/FeishuTurnPresenter.js.map +1 -1
- package/dist/feishu/LocalCardImage.js +0 -4
- package/dist/feishu/LocalCardImage.js.map +1 -1
- package/dist/feishu/LocalImageMarkdown.js +59 -3
- package/dist/feishu/LocalImageMarkdown.js.map +1 -1
- package/dist/feishu/SettingsCard.js +199 -0
- package/dist/feishu/SettingsCard.js.map +1 -0
- package/dist/index.js +3 -6
- package/dist/index.js.map +1 -1
- package/dist/local-files/TurnPreviewPage.js +8 -4
- package/dist/local-files/TurnPreviewPage.js.map +1 -1
- package/dist/presentation/TurnStateReducer.js +21 -2
- package/dist/presentation/TurnStateReducer.js.map +1 -1
- package/dist/presentation/turnStatus.js +34 -0
- package/dist/presentation/turnStatus.js.map +1 -0
- package/dist/proxy/ProxySessionController.js +409 -163
- package/dist/proxy/ProxySessionController.js.map +1 -1
- package/dist/runtime/submissionErrors.js +15 -0
- package/dist/runtime/submissionErrors.js.map +1 -0
- package/dist/state/ExecutionProvenanceStore.js +58 -0
- package/dist/state/ExecutionProvenanceStore.js.map +1 -0
- package/dist/state/StateStore.js +96 -33
- package/dist/state/StateStore.js.map +1 -1
- package/dist/state/migrations.js +12 -0
- package/dist/state/migrations.js.map +1 -1
- package/docs/technical-reference.md +11 -8
- package/docs/technical-reference.zh.md +11 -8
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/skills/agent-bot/SKILL.md +9 -3
- package/src/cli/help.ts +2 -0
- package/src/codex/CodexRuntime.ts +14 -5
- package/src/commands/CommandRouter.ts +3 -0
- package/src/commands/commandTypes.ts +1 -0
- package/src/config/SettingsStore.ts +588 -0
- package/src/config/loadConfig.ts +1 -2
- package/src/config/schema.ts +0 -1
- package/src/console/ConsoleTurnPresenter.ts +2 -0
- package/src/feishu/CardRenderer.ts +35 -114
- package/src/feishu/FeishuConnector.ts +9 -0
- package/src/feishu/FeishuMessageClient.ts +23 -22
- package/src/feishu/FeishuTurnPresenter.ts +33 -22
- package/src/feishu/LocalCardImage.ts +0 -6
- package/src/feishu/LocalImageMarkdown.ts +54 -3
- package/src/feishu/SettingsCard.ts +231 -0
- package/src/index.ts +3 -6
- package/src/local-files/TurnPreviewPage.ts +8 -4
- package/src/presentation/TurnStateReducer.ts +21 -2
- package/src/presentation/turnStatus.ts +38 -0
- package/src/presentation/turnViewTypes.ts +3 -0
- package/src/proxy/ProxySessionController.ts +382 -162
- package/src/runtime/submissionErrors.ts +15 -0
- package/src/runtime/types.ts +1 -0
- package/src/state/ExecutionProvenanceStore.ts +100 -0
- package/src/state/StateStore.ts +118 -33
- package/src/state/migrations.ts +12 -0
|
@@ -4,7 +4,7 @@ import path from "node:path";
|
|
|
4
4
|
import { visibleTurnActivities } from "../presentation/visibleTurnActivities.js";
|
|
5
5
|
import { displayRuntimeError } from "../runtime/responseErrors.js";
|
|
6
6
|
import { truncateMiddle, truncateText } from "../utils/markdown.js";
|
|
7
|
-
import { localCardImage
|
|
7
|
+
import { localCardImage } from "./LocalCardImage.js";
|
|
8
8
|
const EXECUTION_SETTING_EFFECTS = {
|
|
9
9
|
agent: "只影响新建任务,不切换当前任务。",
|
|
10
10
|
provider: "只影响当前任务;运行中选择将在本轮结束后生效。",
|
|
@@ -14,10 +14,6 @@ const EXECUTION_SETTING_EFFECTS = {
|
|
|
14
14
|
};
|
|
15
15
|
const DIRECTORY_BROWSER_ROW_COUNT = 16;
|
|
16
16
|
export class CardRenderer {
|
|
17
|
-
thinkingCardLayout;
|
|
18
|
-
constructor(options = {}) {
|
|
19
|
-
this.thinkingCardLayout = options.thinkingCardLayout ?? "grouped";
|
|
20
|
-
}
|
|
21
17
|
renderThreadWriterConflict(view) {
|
|
22
18
|
if (view.status === "released") {
|
|
23
19
|
return sectionCard("任务占用已解除", [markdown([
|
|
@@ -943,9 +939,7 @@ export class CardRenderer {
|
|
|
943
939
|
};
|
|
944
940
|
}
|
|
945
941
|
renderTurn(state, previewUrl) {
|
|
946
|
-
const elements =
|
|
947
|
-
? renderTurnElements(state, "hidden")
|
|
948
|
-
: renderGroupedTurnElements(state, "hidden");
|
|
942
|
+
const elements = renderGroupedTurnElements(state, "hidden");
|
|
949
943
|
const footerActions = [];
|
|
950
944
|
if (isTurnStoppable(state.status)) {
|
|
951
945
|
footerActions.push({
|
|
@@ -982,11 +976,25 @@ export class CardRenderer {
|
|
|
982
976
|
}
|
|
983
977
|
return turnCard(turnTitle(state.status, state.prompt ?? state.taskTitle), turnTemplate(state.status), elements, renderTurnSubtitle(state));
|
|
984
978
|
}
|
|
985
|
-
renderTurnDetails(state, previewUrl) {
|
|
979
|
+
renderTurnDetails(state, previewUrl, provenance) {
|
|
986
980
|
const title = state.taskTitle
|
|
987
981
|
? `任务执行详情:${truncateText(state.taskTitle.replace(/\s+/g, " ").trim(), 60)}`
|
|
988
982
|
: "任务执行详情";
|
|
989
983
|
const elements = [markdown(`Turn: \`${state.turnId}\``)];
|
|
984
|
+
if (provenance) {
|
|
985
|
+
const labels = {
|
|
986
|
+
user: "用户消息", queue: "排队消息", schedule: "定时任务", recovery: "未提交请求恢复",
|
|
987
|
+
retry: "提交前重试", plan_handoff: "已批准方案续接", response_continuation: "模型空输入续接",
|
|
988
|
+
};
|
|
989
|
+
const settings = provenance.settings;
|
|
990
|
+
elements.push(markdown([
|
|
991
|
+
`**执行来源**:${labels[provenance.trigger]} · ${new Date(provenance.submittedAt).toLocaleString("zh-CN")}`,
|
|
992
|
+
`**原始指令**:${inlineCode(provenance.instructionId)}`,
|
|
993
|
+
provenance.parentSourceTurnId ? `**来源轮次**:${inlineCode(provenance.parentSourceTurnId)}` : undefined,
|
|
994
|
+
provenance.scheduledFor === undefined ? undefined : `**计划时间**:${new Date(provenance.scheduledFor).toLocaleString("zh-CN")}`,
|
|
995
|
+
`**提交设置**:${[settings.agentName, settings.modelProvider ?? "默认", settings.model ?? "默认", settings.reasoningEffort ?? "自动", permissionModeLabel(settings.permissionMode)].map(inlineCode).join(" / ")}`,
|
|
996
|
+
].filter(Boolean).join("\n")));
|
|
997
|
+
}
|
|
990
998
|
if (state.prompt)
|
|
991
999
|
elements.push(markdown(`**Prompt**\n${truncateText(state.prompt, 1_000)}`));
|
|
992
1000
|
if (state.historyDetailError) {
|
|
@@ -995,24 +1003,17 @@ export class CardRenderer {
|
|
|
995
1003
|
else if (state.historyDetail === "summary") {
|
|
996
1004
|
elements.push(markdown("当前仅保存轮次摘要,尚未加载历史执行详情。"));
|
|
997
1005
|
}
|
|
998
|
-
elements.push(...
|
|
1006
|
+
elements.push(...renderGroupedTurnElements(state, "always"));
|
|
999
1007
|
if (previewUrl)
|
|
1000
1008
|
elements.push(taskActionRow([turnPreviewAction(previewUrl)]));
|
|
1001
1009
|
return turnCard(title, "blue", elements, renderTurnSubtitle(state));
|
|
1002
1010
|
}
|
|
1003
1011
|
renderActivityHistory(state, requestedPage) {
|
|
1004
|
-
const grouped = this.thinkingCardLayout === "grouped";
|
|
1005
1012
|
const activities = turnActivities(state);
|
|
1006
|
-
const allGroups =
|
|
1007
|
-
const historyGroups =
|
|
1008
|
-
? groupedLiveActivityPage(groupedActivityPagesFromGroups(allGroups, state.projectCwd), state.projectCwd).historyGroups
|
|
1009
|
-
: [];
|
|
1013
|
+
const allGroups = groupTurnActivities(activities).flatMap(splitGroupedExecutionActivity);
|
|
1014
|
+
const historyGroups = groupedLiveActivityPage(groupedActivityPagesFromGroups(allGroups, state.projectCwd), state.projectCwd).historyGroups;
|
|
1010
1015
|
const usesHistoricalPrefixPages = historyGroups.length > 0;
|
|
1011
|
-
const pages =
|
|
1012
|
-
? groupedActivityPagesFromGroups(usesHistoricalPrefixPages ? historyGroups : allGroups, state.projectCwd, {
|
|
1013
|
-
fullActivityText: true,
|
|
1014
|
-
})
|
|
1015
|
-
: activityPages(activities);
|
|
1016
|
+
const pages = groupedActivityPagesFromGroups(usesHistoricalPrefixPages ? historyGroups : allGroups, state.projectCwd, { fullActivityText: true });
|
|
1016
1017
|
if (pages.length === 0) {
|
|
1017
1018
|
return this.renderSectionsCard("思考活动历史", [{ lines: ["没有保存到活动记录。"] }]);
|
|
1018
1019
|
}
|
|
@@ -1035,11 +1036,9 @@ export class CardRenderer {
|
|
|
1035
1036
|
const elements = [];
|
|
1036
1037
|
if (actions.length > 0)
|
|
1037
1038
|
elements.push(taskActionRow(actions), { tag: "hr" });
|
|
1038
|
-
elements.push(...(
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
})
|
|
1042
|
-
: renderActivities(pages[page] ?? [], state.projectCwd, true)));
|
|
1039
|
+
elements.push(...renderGroupedActivityGroups(pages[page] ?? [], state.projectCwd, {
|
|
1040
|
+
fullActivityText: true,
|
|
1041
|
+
}));
|
|
1043
1042
|
return sectionCard(`思考活动历史 · ${page + 1}/${totalPages}`, elements.length > 0 ? elements : [markdown("无")]);
|
|
1044
1043
|
}
|
|
1045
1044
|
renderSessionStarted(session) {
|
|
@@ -1129,13 +1128,12 @@ export class CardRenderer {
|
|
|
1129
1128
|
if (index > 0)
|
|
1130
1129
|
elements.push({ tag: "hr" });
|
|
1131
1130
|
const content = section.lines.join("\n");
|
|
1132
|
-
const renderMarkdown = section.localImages ? localCardMarkdown : markdown;
|
|
1133
1131
|
if (section.collapsible && section.title) {
|
|
1134
|
-
elements.push(collapsiblePanel(section.title, [
|
|
1132
|
+
elements.push(collapsiblePanel(section.title, [markdown(content)], { elementId: section.elementId }));
|
|
1135
1133
|
}
|
|
1136
1134
|
else {
|
|
1137
1135
|
const heading = section.title ? `**${section.title}**\n` : "";
|
|
1138
|
-
elements.push(
|
|
1136
|
+
elements.push(markdown(`${heading}${content}`));
|
|
1139
1137
|
}
|
|
1140
1138
|
});
|
|
1141
1139
|
if (actions.length > 0)
|
|
@@ -1357,43 +1355,6 @@ function renderTurnDuration(state) {
|
|
|
1357
1355
|
function isTurnStoppable(status) {
|
|
1358
1356
|
return status === "running" || status === "tool_running" || status === "waiting_for_approval";
|
|
1359
1357
|
}
|
|
1360
|
-
function renderTurnElements(state, assistantTextMode) {
|
|
1361
|
-
const elements = [];
|
|
1362
|
-
const allActivities = turnActivities(state);
|
|
1363
|
-
const pages = activityPages(allActivities);
|
|
1364
|
-
const visibleActivities = pages.at(-1) ?? [];
|
|
1365
|
-
if (state.plan.length > 0)
|
|
1366
|
-
elements.push(planPanel(state.plan));
|
|
1367
|
-
if (pages.length > 1 || (state.previewJournal && state.activitiesTruncated)) {
|
|
1368
|
-
elements.push(taskActionRow([{
|
|
1369
|
-
text: state.activitiesTruncated ? "查看历史思考" : `查看历史思考(共 ${pages.length} 页)`,
|
|
1370
|
-
value: {
|
|
1371
|
-
action: "activity_history",
|
|
1372
|
-
turnId: state.turnId,
|
|
1373
|
-
page: String(state.activitiesTruncated ? Number.MAX_SAFE_INTEGER : pages.length - 2),
|
|
1374
|
-
},
|
|
1375
|
-
}]));
|
|
1376
|
-
}
|
|
1377
|
-
if (state.activitiesTruncated || pages.length > 1)
|
|
1378
|
-
elements.push(markdown("…"));
|
|
1379
|
-
elements.push(...renderActivities(visibleActivities, state.projectCwd));
|
|
1380
|
-
if (state.fileSummary.length > 0)
|
|
1381
|
-
elements.push(fileSummaryPanel(state));
|
|
1382
|
-
if (state.approval)
|
|
1383
|
-
elements.push(...renderApprovalElements(state, state.approval));
|
|
1384
|
-
if (state.error)
|
|
1385
|
-
elements.push(markdown(codeBlock(displayRuntimeError(state.error), 2_000)));
|
|
1386
|
-
const showAssistantText = state.assistantText && assistantTextMode === "always";
|
|
1387
|
-
if (showAssistantText) {
|
|
1388
|
-
if (elements.length > 0)
|
|
1389
|
-
elements.push({ tag: "hr" });
|
|
1390
|
-
const heading = state.status === "completed" ? "回答" : "回答生成中";
|
|
1391
|
-
elements.push(markdown(`**${heading}**\n${truncateText(state.assistantText, 3_000)}`));
|
|
1392
|
-
}
|
|
1393
|
-
if (elements.length === 0)
|
|
1394
|
-
elements.push(markdown(emptyTurnText(state.status, state.agentLabel)));
|
|
1395
|
-
return elements;
|
|
1396
|
-
}
|
|
1397
1358
|
function renderGroupedTurnElements(state, assistantTextMode) {
|
|
1398
1359
|
const elements = [];
|
|
1399
1360
|
const allActivities = turnActivities(state);
|
|
@@ -1422,6 +1383,8 @@ function renderGroupedTurnElements(state, assistantTextMode) {
|
|
|
1422
1383
|
elements.push(fileSummaryPanel(state));
|
|
1423
1384
|
if (state.approval)
|
|
1424
1385
|
elements.push(...renderApprovalElements(state, state.approval));
|
|
1386
|
+
if (state.statusMessage)
|
|
1387
|
+
elements.push(markdown(codeBlock(state.statusMessage, 2_000)));
|
|
1425
1388
|
if (state.error)
|
|
1426
1389
|
elements.push(markdown(codeBlock(displayRuntimeError(state.error), 2_000)));
|
|
1427
1390
|
const showAssistantText = state.assistantText && assistantTextMode === "always";
|
|
@@ -1514,6 +1477,8 @@ function escapeApprovalText(value) {
|
|
|
1514
1477
|
return escapeCardHtml(value).replace(/[\\`*_[\]#]/gu, (character) => `&#${character.codePointAt(0)};`);
|
|
1515
1478
|
}
|
|
1516
1479
|
function emptyTurnText(status, agentLabel) {
|
|
1480
|
+
if (status === "unknown")
|
|
1481
|
+
return "执行状态待核实,未自动重发。";
|
|
1517
1482
|
const label = agentLabel?.trim().replace(/[\r\n]+/g, " ") || "Agent";
|
|
1518
1483
|
if (status === "starting")
|
|
1519
1484
|
return `正在连接 ${label}…`;
|
|
@@ -1576,26 +1541,6 @@ function boldUserActivity(text, showIcon) {
|
|
|
1576
1541
|
})
|
|
1577
1542
|
.join("\n");
|
|
1578
1543
|
}
|
|
1579
|
-
function renderActivities(activities, projectCwd, fullAssistantText = false) {
|
|
1580
|
-
const elements = [];
|
|
1581
|
-
let reasoningGroup = [];
|
|
1582
|
-
const flushReasoning = () => {
|
|
1583
|
-
if (reasoningGroup.length === 0)
|
|
1584
|
-
return;
|
|
1585
|
-
elements.push(...renderReasoningGroup(reasoningGroup));
|
|
1586
|
-
reasoningGroup = [];
|
|
1587
|
-
};
|
|
1588
|
-
for (const activity of activities) {
|
|
1589
|
-
if (isRawReasoning(activity)) {
|
|
1590
|
-
reasoningGroup.push(activity);
|
|
1591
|
-
continue;
|
|
1592
|
-
}
|
|
1593
|
-
flushReasoning();
|
|
1594
|
-
elements.push(...renderActivity(activity, projectCwd, fullAssistantText));
|
|
1595
|
-
}
|
|
1596
|
-
flushReasoning();
|
|
1597
|
-
return elements;
|
|
1598
|
-
}
|
|
1599
1544
|
function renderGroupedActivityGroups(groups, projectCwd, options = {}) {
|
|
1600
1545
|
const elements = [];
|
|
1601
1546
|
let previousWasGap = false;
|
|
@@ -1710,26 +1655,12 @@ function renderReasoningGroup(activities) {
|
|
|
1710
1655
|
function isRawReasoning(activity) {
|
|
1711
1656
|
return activity.kind === "reasoning" && !activity.id.startsWith("commentary:");
|
|
1712
1657
|
}
|
|
1713
|
-
const ACTIVITIES_PER_PAGE = 40;
|
|
1714
1658
|
const GROUPED_TOOLS_PER_PANEL = 8;
|
|
1715
1659
|
const GROUPED_PAGE_ACTIVITY_BYTES = 24 * 1024;
|
|
1716
1660
|
const GROUPED_PAGE_ACTIVITY_COMPONENTS = 160;
|
|
1717
1661
|
const PINNED_LIVE_COMMENTARIES = 3;
|
|
1718
1662
|
const MAX_LIVE_ASSISTANT_TEXT = 2_000;
|
|
1719
1663
|
const ACTIVITY_TEXT_CHUNK = 2_500;
|
|
1720
|
-
function activityPages(activities) {
|
|
1721
|
-
if (activities.length === 0)
|
|
1722
|
-
return [];
|
|
1723
|
-
if (activities.length <= ACTIVITIES_PER_PAGE)
|
|
1724
|
-
return [activities];
|
|
1725
|
-
const pages = [];
|
|
1726
|
-
const firstPageSize = activities.length % ACTIVITIES_PER_PAGE || ACTIVITIES_PER_PAGE;
|
|
1727
|
-
pages.push(activities.slice(0, firstPageSize));
|
|
1728
|
-
for (let index = firstPageSize; index < activities.length; index += ACTIVITIES_PER_PAGE) {
|
|
1729
|
-
pages.push(activities.slice(index, index + ACTIVITIES_PER_PAGE));
|
|
1730
|
-
}
|
|
1731
|
-
return pages;
|
|
1732
|
-
}
|
|
1733
1664
|
function groupedActivityPages(activities, projectCwd, renderOptions = {}) {
|
|
1734
1665
|
const groups = groupTurnActivities(activities).flatMap(splitGroupedExecutionActivity);
|
|
1735
1666
|
return groupedActivityPagesFromGroups(groups, projectCwd, renderOptions);
|
|
@@ -2330,6 +2261,8 @@ function persistedTaskStatus(sessionStatus, lastTurnStatus) {
|
|
|
2330
2261
|
return labels[lastTurnStatus ?? sessionStatus] ?? lastTurnStatus ?? sessionStatus;
|
|
2331
2262
|
}
|
|
2332
2263
|
function turnTitle(status, prompt) {
|
|
2264
|
+
if (status === "unknown")
|
|
2265
|
+
return `待核实${prompt ? `:${truncateTurnPrompt(prompt)}` : ""}`;
|
|
2333
2266
|
const reactionEmoji = status === "completed"
|
|
2334
2267
|
? "✅"
|
|
2335
2268
|
: status === "failed"
|
|
@@ -2359,6 +2292,8 @@ function truncateTurnPrompt(prompt) {
|
|
|
2359
2292
|
return `${characters.slice(0, 37).join("")}...`;
|
|
2360
2293
|
}
|
|
2361
2294
|
function turnTemplate(status) {
|
|
2295
|
+
if (status === "unknown")
|
|
2296
|
+
return "orange";
|
|
2362
2297
|
if (status === "completed")
|
|
2363
2298
|
return "green";
|
|
2364
2299
|
if (status === "failed")
|