keel-agent 0.129.0 → 0.130.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/CHANGELOG.md +31 -1
- package/README.md +12 -16
- package/README.zh-CN.md +12 -16
- package/README.zh-TW.md +74 -189
- package/bin/keel.mjs +295 -55
- package/dist/packages/keel/src/adapters/sdk/prompt-render.js +3 -1
- package/dist/packages/keel/src/adapters/sdk/session-opener.js +2 -1
- package/dist/packages/keel/src/adapters/tools/guarded.js +31 -4
- package/dist/packages/keel/src/adapters/tools/patch.js +16 -0
- package/dist/packages/keel/src/app/client-assembly.js +43 -24
- package/dist/packages/keel/src/app/client-runtime.js +37 -2
- package/dist/packages/keel/src/app/connection-init.js +4 -2
- package/dist/packages/keel/src/app/conversation-content.js +14 -0
- package/dist/packages/keel/src/app/core-engine.js +6 -2
- package/dist/packages/keel/src/app/engine-coordination.js +4 -0
- package/dist/packages/keel/src/app/engine-elsewhere.js +8 -2
- package/dist/packages/keel/src/app/engine-orphans.js +8 -1
- package/dist/packages/keel/src/app/engine-sessions.js +26 -22
- package/dist/packages/keel/src/app/engine-takeover.js +13 -8
- package/dist/packages/keel/src/app/extra-handlers.js +8 -5
- package/dist/packages/keel/src/app/host-faces.js +1 -0
- package/dist/packages/keel/src/app/host-tool-mounts.js +12 -0
- package/dist/packages/keel/src/app/note-delivery.js +2 -2
- package/dist/packages/keel/src/app/session-registry.js +3 -1
- package/dist/packages/keel/src/app/session-surface.js +2 -1
- package/dist/packages/keel/src/app/subagent-model-choice.js +44 -30
- package/dist/packages/keel/src/bg-job-notice.js +1 -0
- package/dist/packages/keel/src/composer-complete-settings.js +43 -0
- package/dist/packages/keel/src/conversation-rows.js +8 -0
- package/dist/packages/keel/src/domains/background/handlers.js +1 -0
- package/dist/packages/keel/src/domains/bots/chat.js +1 -1
- package/dist/packages/keel/src/domains/snapshots/builders.js +4 -0
- package/dist/packages/keel/src/domains/turns/turn-runner.js +18 -0
- package/dist/packages/keel/src/settings-schema.js +9 -0
- package/dist/packages/keel/src/subagent-model-policy.js +49 -0
- package/dist/packages/keel/src/subagent-templates-hant.js +3 -3
- package/dist/packages/keel/src/subagent-templates.js +6 -6
- package/dist/packages/keel/src/tool-catalog.js +9 -0
- package/dist/packages/keel/src/tool-names.js +2 -0
- package/dist/server/background-task-service.js +61 -22
- package/dist/server/bg-tasks/client.js +5 -4
- package/dist/server/bg-tasks/registry.js +29 -18
- package/dist/server/bot-memory-tool.js +15 -3
- package/dist/server/client-state.js +65 -0
- package/dist/server/composer-complete-settings.js +1 -0
- package/dist/server/composer-complete.js +243 -0
- package/dist/server/control-socket.js +13 -1
- package/dist/server/conversation-import/engines/agy.js +222 -0
- package/dist/server/conversation-import/engines/claude.js +171 -0
- package/dist/server/conversation-import/engines/codex.js +178 -0
- package/dist/server/conversation-import/engines/dsh.js +240 -0
- package/dist/server/conversation-import/engines/opencode.js +160 -0
- package/dist/server/conversation-import/index.js +183 -0
- package/dist/server/conversation-import/jsonl.js +100 -0
- package/dist/server/conversation-import/messages.js +147 -0
- package/dist/server/conversation-import/sqlite.js +47 -0
- package/dist/server/conversation-import/types.js +8 -0
- package/dist/server/conversation-import-routes.js +53 -0
- package/dist/server/core-bot-adapter.js +5 -1
- package/dist/server/core-plugin-adapter.js +4 -1
- package/dist/server/core-settings-adapter.js +19 -9
- package/dist/server/custom-cli-routes.js +59 -0
- package/dist/server/custom-cli-store.js +134 -0
- package/dist/server/delegate-task.js +18 -7
- package/dist/server/device-center/bot-chat.js +34 -17
- package/dist/server/device-center/bot-creation-tool.js +8 -64
- package/dist/server/device-center/bot-drafts.js +24 -0
- package/dist/server/device-center/bot-memory.js +101 -12
- package/dist/server/device-center/bot-tool-face.js +24 -20
- package/dist/server/device-center/local.js +59 -9
- package/dist/server/durable/durable-agent-service.js +27 -0
- package/dist/server/engine-owner-route.js +43 -0
- package/dist/server/files-service.js +10 -6
- package/dist/server/index.js +236 -47
- package/dist/server/marker-service.js +19 -0
- package/dist/server/message-window.js +2 -2
- package/dist/server/multi-engine.js +1 -0
- package/dist/server/native-cli.js +3 -1
- package/dist/server/obs-recall-tool.js +173 -0
- package/dist/server/plugin-facilities.js +9 -1
- package/dist/server/plugins.js +11 -4
- package/dist/server/preset-fields.js +9 -0
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/remote-ssh-service.js +13 -0
- package/dist/server/schedule-agent-tool.js +2 -0
- package/dist/server/scheduler-tasks.js +5 -0
- package/dist/server/settings-commit.js +2 -0
- package/dist/server/settings-service.js +2 -0
- package/dist/server/shell-activate.js +118 -1
- package/dist/server/slash-commands.js +48 -12
- package/dist/server/tool-bridge-host.js +5 -0
- package/dist/server/universal/acp/acp-driver.js +96 -22
- package/dist/server/universal/drivers/claude-acp-driver.js +3 -0
- package/dist/server/universal/internal-mcp.js +7 -3
- package/dist/server/universal/seat-takeover.js +145 -0
- package/dist/server/universal/subagent-slash.js +54 -0
- package/dist/server/universal/universal-service.js +28 -0
- package/dist/server/universal/universal-session.js +242 -88
- package/dist/server/update-service.js +12 -8
- package/package.json +20 -15
- package/plugins/catalog.json +128 -90
- package/plugins/superagent/manifest.json +2 -2
- package/themes/flow-zurich.css +2 -2
- package/web/dist/.build-assets.json +1 -1
- package/web/dist/assets/ApprovalRulesTab-QmzsJItk.js +1 -0
- package/web/dist/assets/BgTasksModal-COLmy-4E.js +1 -0
- package/web/dist/assets/{BotDraftSettings-BcXWHOSd.js → BotDraftSettings-nP4g1fge.js} +1 -1
- package/web/dist/assets/BottomDock-BZXSlOom.js +1 -0
- package/web/dist/assets/{CanvasStudio-KZ0MmCL7.js → CanvasStudio-BL1BWXpp.js} +3 -3
- package/web/dist/assets/CommunityThemesSection-BLd_oox1.js +1 -0
- package/web/dist/assets/DesktopAppSettings-Dn18vrLK.js +1 -0
- package/web/dist/assets/DeviceCenter-DxoAwlTt.js +3 -0
- package/web/dist/assets/{DeviceExecutionSettings-VONJ-2Ns.js → DeviceExecutionSettings-B1mya5TJ.js} +1 -1
- package/web/dist/assets/{DeviceGroups-DUq2YZ8O.js → DeviceGroups-C-xwewog.js} +1 -1
- package/web/dist/assets/DisplayTab-DRGFt78v.js +1 -0
- package/web/dist/assets/{FieldRow-CHxkNX2z.js → FieldRow-DHxAXFtL.js} +1 -1
- package/web/dist/assets/FilePreview-DcyP9paf.js +2 -0
- package/web/dist/assets/GlobalSearchModal-Cs6hB5KO.js +1 -0
- package/web/dist/assets/GroupConversation-B7NfTB89.js +9 -0
- package/web/dist/assets/{GroupWorkItems-B-wweVMR.js → GroupWorkItems-CSUjIxDT.js} +1 -1
- package/web/dist/assets/{HintTip-lXOOr9p3.js → HintTip-CKxIx9CD.js} +1 -1
- package/web/dist/assets/LayoutTab-9popvCLQ.js +1 -0
- package/web/dist/assets/McpServersPanel-dRwq7Wjq.js +1 -0
- package/web/dist/assets/ModelConfigModal-C0CXhSl0.js +2 -0
- package/web/dist/assets/{ModelsTab-CMSi1MT-.js → ModelsTab-CyG2rYeY.js} +1 -1
- package/web/dist/assets/{NativeCliPanel-DotHqKv_.js → NativeCliPanel-mlB4dw42.js} +2 -2
- package/web/dist/assets/{PiSetupModal-Dd0w2Koi.js → PiSetupModal-D7PjlTVx.js} +1 -1
- package/web/dist/assets/PluginsTab-0s0qClcC.js +2 -0
- package/web/dist/assets/PresetShareModal-Dw4t6p6s.js +11 -0
- package/web/dist/assets/{PresetsTab-BnFFB24b.js → PresetsTab-DdXvpc2d.js} +1 -1
- package/web/dist/assets/{PromptHistoryTab-CNUzjdJl.js → PromptHistoryTab-DirJHaH6.js} +1 -1
- package/web/dist/assets/{PromptOverrideEditor-DZOQdWy3.js → PromptOverrideEditor-ldLRCp0e.js} +1 -1
- package/web/dist/assets/PromptTab-SV01BMC0.js +11 -0
- package/web/dist/assets/{ProviderOAuthControls-BSqBp-QA.js → ProviderOAuthControls-Clyn3fnw.js} +1 -1
- package/web/dist/assets/QuestionTab-Bi1NYK5U.js +1 -0
- package/web/dist/assets/{QuickAskSettings-DICkDFsE.js → QuickAskSettings-dzG95DYl.js} +2 -2
- package/web/dist/assets/QuickTab-C8bknYDU.js +5 -0
- package/web/dist/assets/{ReviewTab-DRMQoVjL.js → ReviewTab-D9lbphZe.js} +1 -1
- package/web/dist/assets/SCMPanel-BfrlvHxI.js +7 -0
- package/web/dist/assets/SchedulerPanel-DDDWOSsw.js +2 -0
- package/web/dist/assets/SettingsModal-BqzfvDlI.js +2 -0
- package/web/dist/assets/SkillsTab-D8C-kghN.js +1 -0
- package/web/dist/assets/{SoundTab-BR6gVIOZ.js → SoundTab-CXcWmvkX.js} +1 -1
- package/web/dist/assets/{SubagentTemplatesTab-BonIA-lD.js → SubagentTemplatesTab-KjPMnYN4.js} +1 -1
- package/web/dist/assets/{TermXterm-EHBR2avX.js → TermXterm-B7klZwgq.js} +1 -1
- package/web/dist/assets/TerminalDockControls-lbPY2V5U.js +1 -0
- package/web/dist/assets/TerminalPanel-ERotdy8I.js +1 -0
- package/web/dist/assets/{ThemeMarketModal-CGaoF3NZ.js → ThemeMarketModal-BZJZ7doZ.js} +1 -1
- package/web/dist/assets/{ToggleRow-DvouPLLK.js → ToggleRow-irywH1NJ.js} +1 -1
- package/web/dist/assets/ToolBridgeSettings-CG1HleEp.js +1 -0
- package/web/dist/assets/ToolsTab-_OJA76Sw.js +4 -0
- package/web/dist/assets/TuiOverlayModal-CDqXNwW-.js +1 -0
- package/web/dist/assets/{VisionTab-HDlpKVeq.js → VisionTab-B580SGpU.js} +1 -1
- package/web/dist/assets/{api-client-J4QrjRw8.js → api-client-B2iSv9kK.js} +1 -1
- package/web/dist/assets/{canvas-client-BsNp2mr3.js → canvas-client-DRiwRbfy.js} +1 -1
- package/web/dist/assets/{desktop-BcTQigaN.js → desktop-DRyQQXnx.js} +1 -1
- package/web/dist/assets/host-icon-DMg5PU4C.js +1 -0
- package/web/dist/assets/i18n-D2DJ-AHq.js +225 -0
- package/web/dist/assets/index-CP0EEOA0.js +423 -0
- package/web/dist/assets/index-Ds_pheLF.css +1 -0
- package/web/dist/assets/plugin-host-VU6JOOPu.js +1 -0
- package/web/dist/assets/{theme-7DF4yEv3.js → theme-ZteIcUdF.js} +1 -1
- package/web/dist/assets/{tool-inventory-D2UKR8Ja.js → tool-inventory-DnzKVLYq.js} +1 -1
- package/web/dist/index.html +10 -9
- package/web/dist/sw.js +1 -1
- package/web/dist/assets/ApprovalRulesTab-BlcxVgms.js +0 -1
- package/web/dist/assets/BgTasksModal-wL4p27CE.js +0 -1
- package/web/dist/assets/BottomDock-CUnQsIDW.js +0 -1
- package/web/dist/assets/CommunityThemesSection-BAcS2VQK.js +0 -1
- package/web/dist/assets/DesktopAppSettings-BeikxSqV.js +0 -1
- package/web/dist/assets/DeviceCenter-BWKRVpWt.js +0 -3
- package/web/dist/assets/DisplayTab-B5x4nQh5.js +0 -1
- package/web/dist/assets/FilePreview-0IDddE5F.js +0 -2
- package/web/dist/assets/GlobalSearchModal-BaXs1zRG.js +0 -1
- package/web/dist/assets/GroupConversation-EaMawnF-.js +0 -9
- package/web/dist/assets/LayoutTab-8N74U83U.js +0 -1
- package/web/dist/assets/McpServersPanel-BAhwoE87.js +0 -1
- package/web/dist/assets/ModelConfigModal-i3m9glTy.js +0 -2
- package/web/dist/assets/PluginsTab-DL8j6LEI.js +0 -2
- package/web/dist/assets/PresetShareModal-BGhCpas6.js +0 -11
- package/web/dist/assets/PromptTab-DPYuPM07.js +0 -11
- package/web/dist/assets/QuestionTab-C7oF1MYO.js +0 -1
- package/web/dist/assets/QuickTab-DDaxH3XV.js +0 -1
- package/web/dist/assets/SCMPanel-CfOxsL8H.js +0 -7
- package/web/dist/assets/SchedulerPanel-BLaVSPXj.js +0 -2
- package/web/dist/assets/SettingsModal-6jgsnLF0.js +0 -2
- package/web/dist/assets/SkillsTab-C5XuZ4a-.js +0 -1
- package/web/dist/assets/TerminalDockControls-Dn51FqM9.js +0 -1
- package/web/dist/assets/TerminalPanel-D2Bpt0f_.js +0 -1
- package/web/dist/assets/ToolBridgeSettings-8vlLWWvW.js +0 -1
- package/web/dist/assets/ToolsTab-Byx7wDZe.js +0 -4
- package/web/dist/assets/TuiOverlayModal-Bj6jyAvr.js +0 -1
- package/web/dist/assets/i18n-CaWsBwiA.js +0 -225
- package/web/dist/assets/index-2jVkYOYt.css +0 -1
- package/web/dist/assets/index-KuttBaFw.js +0 -420
- package/web/dist/assets/plugin-host-C2Iki5ig.js +0 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { parseModelId } from "../domains/models/project-memory.js";
|
|
2
|
+
import { applySubagentModelPolicy, normalizeSubagentModelId } from "../subagent-model-policy.js";
|
|
2
3
|
export function createSubagentModelChoice(deps) {
|
|
3
4
|
const { runtime, sessions } = deps;
|
|
4
5
|
const templateOf = (spec) => spec.templateName ? deps.templateRows().find((row) => row.name === spec.templateName) : undefined;
|
|
@@ -11,48 +12,61 @@ export function createSubagentModelChoice(deps) {
|
|
|
11
12
|
* - **继承来的默认值**(全局默认模型或派发者模型)解析不到 → warning + 跟随派发者模型(非退化)。
|
|
12
13
|
*/
|
|
13
14
|
const applyModel = async (session, ownerRuntime, parentId, spec) => {
|
|
14
|
-
|
|
15
|
+
const setModel = session.setModel;
|
|
16
|
+
if (!setModel)
|
|
15
17
|
return;
|
|
16
|
-
// 显式来源:调用方传的 model 或模板绑定的 model;继承来源:全局默认或派发者模型。
|
|
17
|
-
const explicitId = spec.model?.trim() || templateOf(spec)?.model?.trim() || "";
|
|
18
|
-
const wantedId = explicitId || defaultModelOf(ownerRuntime);
|
|
19
|
-
const isExplicit = Boolean(explicitId);
|
|
20
18
|
const parentSession = (ownerRuntime.options.sessions ?? sessions).get(parentId)?.session;
|
|
21
|
-
|
|
19
|
+
const resolve = ownerRuntime.options.resolveModel ?? runtime.options.resolveModel;
|
|
20
|
+
const resolveOrThrow = async (wantedId, isExplicit) => {
|
|
22
21
|
const parsed = parseModelId(wantedId);
|
|
23
|
-
const resolve = ownerRuntime.options.resolveModel ?? runtime.options.resolveModel;
|
|
24
22
|
const resolved = parsed && resolve ? await resolve(parsed.provider, parsed.id) : undefined;
|
|
25
|
-
if (resolved) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
catch (error) {
|
|
31
|
-
const reason = error instanceof Error ? error.message : String(error);
|
|
32
|
-
if (isExplicit) {
|
|
33
|
-
throw new Error(`子代理指定的模型设置失败:${wantedId}(${reason})` +
|
|
34
|
-
`\nFailed to apply the requested subagent model: ${wantedId} (${reason})`);
|
|
23
|
+
if (!resolved) {
|
|
24
|
+
if (isExplicit) {
|
|
25
|
+
if (!parsed) {
|
|
26
|
+
throw new Error(`子代理指定的模型 id 缺少供应商前缀:${wantedId}(应写成 provider/model,例如 liteLLM/${wantedId})` +
|
|
27
|
+
`\nSubagent model id is missing the provider prefix: ${wantedId} (expected format: provider/model, e.g. liteLLM/${wantedId})`);
|
|
35
28
|
}
|
|
36
|
-
|
|
29
|
+
throw new Error(`子代理指定的模型不存在或供应商未注册:${wantedId}(用 /models 确认可用模型)` +
|
|
30
|
+
`\nSubagent model not found or provider not registered: ${wantedId} (use /models to list available models)`);
|
|
37
31
|
}
|
|
32
|
+
const err = new Error(`unavailable:${wantedId}`);
|
|
33
|
+
err.name = "SubagentDefaultModelUnavailableError";
|
|
34
|
+
throw err;
|
|
38
35
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (!parsed) {
|
|
42
|
-
throw new Error(`子代理指定的模型 id 缺少供应商前缀:${wantedId}(应写成 provider/model,例如 liteLLM/${wantedId})` +
|
|
43
|
-
`\nSubagent model id is missing the provider prefix: ${wantedId} (expected format: provider/model, e.g. liteLLM/${wantedId})`);
|
|
44
|
-
}
|
|
45
|
-
throw new Error(`子代理指定的模型不存在或供应商未注册:${wantedId}(用 /models 确认可用模型)` +
|
|
46
|
-
`\nSubagent model not found or provider not registered: ${wantedId} (use /models to list available models)`);
|
|
36
|
+
try {
|
|
37
|
+
await setModel(resolved);
|
|
47
38
|
}
|
|
48
|
-
|
|
49
|
-
|
|
39
|
+
catch (error) {
|
|
40
|
+
if (isExplicit) {
|
|
41
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
42
|
+
throw new Error(`子代理指定的模型设置失败:${wantedId}(${reason})` +
|
|
43
|
+
`\nFailed to apply the requested subagent model: ${wantedId} (${reason})`);
|
|
44
|
+
}
|
|
45
|
+
throw error;
|
|
50
46
|
}
|
|
51
|
-
}
|
|
47
|
+
};
|
|
48
|
+
const result = await applySubagentModelPolicy({
|
|
49
|
+
input: {
|
|
50
|
+
requestedModel: normalizeSubagentModelId(spec.model),
|
|
51
|
+
templateModel: normalizeSubagentModelId(templateOf(spec)?.model),
|
|
52
|
+
defaultModel: normalizeSubagentModelId(defaultModelOf(ownerRuntime)),
|
|
53
|
+
},
|
|
54
|
+
tryApply: (wantedId, source) => resolveOrThrow(wantedId, source === "explicit"),
|
|
55
|
+
onFallbackWarning: (_source, wantedId, error) => {
|
|
56
|
+
if (error instanceof Error && error.name === "SubagentDefaultModelUnavailableError") {
|
|
57
|
+
deps.sendWarning(`子代理默认模型不可用(将尝试跟随主对话):${wantedId}`, `Subagent default model unavailable, falling back to parent: ${wantedId}`);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
61
|
+
deps.sendWarning(`子代理模型设置失败(将尝试跟随主对话):${wantedId}(${reason})`, `Failed to set subagent model, falling back to parent: ${wantedId} (${reason})`);
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
if (result.appliedModel)
|
|
65
|
+
return;
|
|
52
66
|
if (!parentSession?.model)
|
|
53
67
|
return;
|
|
54
68
|
try {
|
|
55
|
-
await
|
|
69
|
+
await setModel(parentSession.model);
|
|
56
70
|
}
|
|
57
71
|
catch (error) {
|
|
58
72
|
const reason = error instanceof Error ? error.message : String(error);
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export const DEFAULT_COMPOSER_COMPLETE_PROMPT = [
|
|
2
|
+
"你是聊天输入框的智能续写助手。根据当前对话上下文、工作区背景和用户提供的参考依据,自然续写用户正在输入的文本。",
|
|
3
|
+
"规则:",
|
|
4
|
+
"1. 只输出续写部分,不要重复用户已经输入的文字。",
|
|
5
|
+
"2. 不要加引号、前缀、解释或 Markdown 代码块包裹。",
|
|
6
|
+
"3. 保持简洁自然,通常 1~2 句话即可;如果无法合理续写,输出空字符串。",
|
|
7
|
+
].join("\n");
|
|
8
|
+
export const MAX_COMPOSER_COMPLETE_PROMPT_LENGTH = 16_384;
|
|
9
|
+
export const MAX_COMPOSER_COMPLETE_REFERENCE_LENGTH = 16_384;
|
|
10
|
+
export const DEFAULT_COMPOSER_COMPLETE_MIN_CHARS = 2;
|
|
11
|
+
export const MIN_COMPOSER_COMPLETE_MIN_CHARS = 0;
|
|
12
|
+
export const MAX_COMPOSER_COMPLETE_MIN_CHARS = 20;
|
|
13
|
+
const CONTEXT_SCOPES = new Set(["off", "recent", "last_assistant"]);
|
|
14
|
+
export function isComposerCompleteModel(value) {
|
|
15
|
+
return typeof value === "string" && /^[^\s/]+\/\S+$/.test(value) && value.length <= 512;
|
|
16
|
+
}
|
|
17
|
+
export function normalizeComposerCompleteSettings(value) {
|
|
18
|
+
const model = typeof value.composerCompleteModel === "string" ? value.composerCompleteModel.trim() : null;
|
|
19
|
+
const prompt = value.composerCompletePrompt;
|
|
20
|
+
const reference = value.composerCompleteReference;
|
|
21
|
+
const rawMinChars = value.composerCompleteMinChars;
|
|
22
|
+
const minChars = typeof rawMinChars === "number" && Number.isFinite(rawMinChars)
|
|
23
|
+
? Math.min(MAX_COMPOSER_COMPLETE_MIN_CHARS, Math.max(MIN_COMPOSER_COMPLETE_MIN_CHARS, Math.round(rawMinChars)))
|
|
24
|
+
: DEFAULT_COMPOSER_COMPLETE_MIN_CHARS;
|
|
25
|
+
return {
|
|
26
|
+
composerCompleteEnabled: typeof value.composerCompleteEnabled === "boolean" ? value.composerCompleteEnabled : true,
|
|
27
|
+
composerCompleteModel: isComposerCompleteModel(model) ? model : null,
|
|
28
|
+
composerCompleteMinChars: minChars,
|
|
29
|
+
composerCompleteAutoContinue: typeof value.composerCompleteAutoContinue === "boolean" ? value.composerCompleteAutoContinue : false,
|
|
30
|
+
composerCompletePrompt: typeof prompt === "string" && prompt.trim() && prompt.length <= MAX_COMPOSER_COMPLETE_PROMPT_LENGTH
|
|
31
|
+
? prompt
|
|
32
|
+
: DEFAULT_COMPOSER_COMPLETE_PROMPT,
|
|
33
|
+
composerCompleteReference: typeof reference === "string" && reference.length <= MAX_COMPOSER_COMPLETE_REFERENCE_LENGTH ? reference : "",
|
|
34
|
+
composerCompleteContextScope: CONTEXT_SCOPES.has(value.composerCompleteContextScope)
|
|
35
|
+
? value.composerCompleteContextScope
|
|
36
|
+
: "recent",
|
|
37
|
+
composerCompleteWorkspaceContext: typeof value.composerCompleteWorkspaceContext === "boolean" ? value.composerCompleteWorkspaceContext : true,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export function mergeComposerCompleteSettings(current, patch) {
|
|
41
|
+
const defined = Object.fromEntries(Object.entries(patch).filter(([, value]) => value !== undefined));
|
|
42
|
+
return normalizeComposerCompleteSettings({ ...current, ...defined });
|
|
43
|
+
}
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 还没被命名过的默认标题(引擎按首条用户消息改写标题之前的样子)。
|
|
3
|
+
* 单源:左栏「空白对话不出行」的判定(`app/conversation-content.ts`)、universal 席位的行判定都读它。
|
|
4
|
+
*/
|
|
5
|
+
export function isDefaultConversationTitle(title) {
|
|
6
|
+
const t = (title ?? "").trim();
|
|
7
|
+
return !t || t === "新对话" || t === "New chat" || t === "New Chat" || t === "对话" || t === "Chat";
|
|
8
|
+
}
|
|
1
9
|
/** `open` = 对话自占一行;`history` = 由历史会话行代表(只有明确知道有历史行时才这么判)。 */
|
|
2
10
|
export function conversationRowKind(input) {
|
|
3
11
|
if (input.forceOpen)
|
|
@@ -50,6 +50,7 @@ export function createBackgroundHandlers(options) {
|
|
|
50
50
|
return deliver(conversationId, message.text, {
|
|
51
51
|
customType: message.customType || BG_TASK_NOTIFICATION_TYPE,
|
|
52
52
|
details: message.details,
|
|
53
|
+
...(message.triggerTurn !== undefined ? { triggerTurn: message.triggerTurn } : {}),
|
|
53
54
|
});
|
|
54
55
|
},
|
|
55
56
|
};
|
|
@@ -77,7 +77,7 @@ export function createBotChatHandlers(deps) {
|
|
|
77
77
|
if (conv && target.name)
|
|
78
78
|
conv.setBot(target.id, target.name);
|
|
79
79
|
await port.rebindIfStale?.(opened, target.id, target);
|
|
80
|
-
deps.dispatch().flushSnapshot(
|
|
80
|
+
deps.dispatch().flushSnapshot();
|
|
81
81
|
deps.dispatch().pushConversations?.();
|
|
82
82
|
return true;
|
|
83
83
|
};
|
|
@@ -71,6 +71,10 @@ export function buildSnapshotState(rev, env, conv) {
|
|
|
71
71
|
...(conv.pendingApprovals && conv.pendingApprovals.length > 0 ? { pendingApprovals: conv.pendingApprovals } : {}),
|
|
72
72
|
...sandboxAndWorktree(env),
|
|
73
73
|
pendingQuestion: conv.pendingQuestion ?? null,
|
|
74
|
+
// 建议按钮:只在有内容时出键(旧帧形状不变)。
|
|
75
|
+
...(conv.actionSuggestions && conv.actionSuggestions.length > 0
|
|
76
|
+
? { actionSuggestions: conv.actionSuggestions }
|
|
77
|
+
: {}),
|
|
74
78
|
bot: conv.bot ?? null,
|
|
75
79
|
...(conv.nativeCli ? { nativeCli: conv.nativeCli } : {}),
|
|
76
80
|
tools: [...conv.tools],
|
|
@@ -66,6 +66,24 @@ export class TurnRunner {
|
|
|
66
66
|
}
|
|
67
67
|
await feedSteer(session, text);
|
|
68
68
|
}
|
|
69
|
+
/** 以结构化自定义消息开启一轮(如后台任务完成通知),复用统一的相位与 streaming 生命周期。 */
|
|
70
|
+
async startCustom(conv, deliver) {
|
|
71
|
+
this.assertAcceptsTurns(conv);
|
|
72
|
+
if (conv.phase !== "idle")
|
|
73
|
+
throw new TurnRejectedError(conv.id, `a turn is already running in phase ${conv.phase}`);
|
|
74
|
+
const at = this.deps.clock.now();
|
|
75
|
+
conv.beginTurn(at);
|
|
76
|
+
this.setStreaming(conv.id, true, at);
|
|
77
|
+
let outcome = "failed";
|
|
78
|
+
try {
|
|
79
|
+
await deliver();
|
|
80
|
+
outcome = "done";
|
|
81
|
+
return "done";
|
|
82
|
+
}
|
|
83
|
+
finally {
|
|
84
|
+
this.settle(conv, outcome);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
69
87
|
settle(conv, outcome) {
|
|
70
88
|
const at = this.deps.clock.now();
|
|
71
89
|
// 相位可能已被退役路径带走(running → retiring):跳过 endTurn,别让它掩盖原始错误。
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DEFAULT_COMPOSER_COMPLETE_MIN_CHARS, DEFAULT_COMPOSER_COMPLETE_PROMPT, } from "./composer-complete-settings.js";
|
|
1
2
|
import { DEFAULT_TOOL_LAZY_LOADING, DEFAULT_TOOL_WATCHDOG_TIMEOUT_MS } from "./settings-normalize.js";
|
|
2
3
|
import { DEFAULT_UI_LAYOUT } from "./ui-layout.js";
|
|
3
4
|
export const DEFAULT_DARK_MINIMAL_SETTINGS = Object.freeze({
|
|
@@ -219,6 +220,14 @@ export const DEFAULT_DARK_MINIMAL_SETTINGS = Object.freeze({
|
|
|
219
220
|
quickAskReferenceMenus: true,
|
|
220
221
|
quickAskConversationScope: "recent",
|
|
221
222
|
quickAskFolderScope: "listing",
|
|
223
|
+
composerCompleteEnabled: true,
|
|
224
|
+
composerCompleteModel: null,
|
|
225
|
+
composerCompleteMinChars: DEFAULT_COMPOSER_COMPLETE_MIN_CHARS,
|
|
226
|
+
composerCompleteAutoContinue: false,
|
|
227
|
+
composerCompletePrompt: DEFAULT_COMPOSER_COMPLETE_PROMPT,
|
|
228
|
+
composerCompleteReference: "",
|
|
229
|
+
composerCompleteContextScope: "recent",
|
|
230
|
+
composerCompleteWorkspaceContext: true,
|
|
222
231
|
planModePromptMode: "append",
|
|
223
232
|
planModePrompt: "",
|
|
224
233
|
subagentDefaultModel: null,
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 子代理模型选择的单源策略(pi 引擎与 universal 引擎共用)。
|
|
3
|
+
*
|
|
4
|
+
* 优先级:`显式请求 (requestedModel / templateModel)` → `全局默认 (defaultModel)` → `派发者模型 (parentModel)`。
|
|
5
|
+
* 失败语义(#1060 / #1079 / #1108):
|
|
6
|
+
* - 显式指定失败 → 抛错(fail-closed);
|
|
7
|
+
* - 继承来源(全局默认或派发者模型)失败 → 告警并继续向下回退;
|
|
8
|
+
* - 空白或字面量 `"default"` 统一视作未指定,不传给 `setModel`。
|
|
9
|
+
*/
|
|
10
|
+
/** 归一化模型 ID:空白或字面量 `"default"` 均视作未指定(`null`)。 */
|
|
11
|
+
export function normalizeSubagentModelId(raw) {
|
|
12
|
+
const trimmed = raw?.trim();
|
|
13
|
+
if (!trimmed || trimmed === "default")
|
|
14
|
+
return null;
|
|
15
|
+
return trimmed;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* 按统一优先级与失败语义尝试应用子代理模型。
|
|
19
|
+
* 返回最终生效的模型 ID 与来源;若全部未指定或非显式项均回退,则返回 `{ appliedModel: null, source: null }`。
|
|
20
|
+
*/
|
|
21
|
+
export async function applySubagentModelPolicy(opts) {
|
|
22
|
+
const { input, tryApply, onFallbackWarning } = opts;
|
|
23
|
+
const explicitId = normalizeSubagentModelId(input.requestedModel) ?? normalizeSubagentModelId(input.templateModel);
|
|
24
|
+
if (explicitId) {
|
|
25
|
+
await tryApply(explicitId, "explicit");
|
|
26
|
+
return { appliedModel: explicitId, source: "explicit" };
|
|
27
|
+
}
|
|
28
|
+
const defaultId = normalizeSubagentModelId(input.defaultModel);
|
|
29
|
+
const parentId = normalizeSubagentModelId(input.parentModel);
|
|
30
|
+
if (defaultId) {
|
|
31
|
+
try {
|
|
32
|
+
await tryApply(defaultId, "default");
|
|
33
|
+
return { appliedModel: defaultId, source: "default" };
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
onFallbackWarning("default", defaultId, error);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (parentId && parentId !== defaultId) {
|
|
40
|
+
try {
|
|
41
|
+
await tryApply(parentId, "parent");
|
|
42
|
+
return { appliedModel: parentId, source: "parent" };
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
onFallbackWarning("parent", parentId, error);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return { appliedModel: null, source: null };
|
|
49
|
+
}
|
|
@@ -120,7 +120,7 @@ export const BUILTIN_TEMPLATES_HANT = {
|
|
|
120
120
|
"- 給出結構化分析:現狀、候選方案與權衡、推薦方案及理由。\n" +
|
|
121
121
|
"- 只描述該改什麼、怎麼改,不直接做檔案編輯——執行留給主 agent 或 implement。\n" +
|
|
122
122
|
"- 結尾給可執行的建議清單,主 agent 看完就能動手。\n\n" +
|
|
123
|
-
"你是經
|
|
123
|
+
"你是經 conversation 派生的子代理:彙報要簡潔具體,主 agent 會基於你的結論決策。",
|
|
124
124
|
},
|
|
125
125
|
librarian: {
|
|
126
126
|
description: "外部研究專員:不熟的函式庫/API/文件、開源實作參考,多儲存庫找資料",
|
|
@@ -130,7 +130,7 @@ export const BUILTIN_TEMPLATES_HANT = {
|
|
|
130
130
|
"- 廣撒網:文件、官方範例、開源實作多角度找,交叉驗證後再下結論。\n" +
|
|
131
131
|
"- 每條結論給出來源(連結或套件路徑+版本),區分「文件原話」和「你的推斷」。\n" +
|
|
132
132
|
"- 結尾給綜合結論:可直接用的 API/模式 + 最小範例 + 注意事項。\n\n" +
|
|
133
|
-
"你是經
|
|
133
|
+
"你是經 conversation 派生的子代理:彙報要簡潔具體,附來源。",
|
|
134
134
|
},
|
|
135
135
|
explore: {
|
|
136
136
|
description: "程式碼庫快速偵察:「X 在哪、Y 在哪個檔案」,給路徑+關鍵程式碼",
|
|
@@ -191,7 +191,7 @@ export const BUILTIN_TEMPLATES_HANT = {
|
|
|
191
191
|
"- 圖片/圖表:描述視覺內容(佈局、關鍵元素、資料趨勢),再給結論。\n" +
|
|
192
192
|
"- 文字類 PDF:給出結構化摘要 + 關鍵原文引用(含頁碼/位置)。\n" +
|
|
193
193
|
"- 讀不到或格式不支援時如實說,不要編造內容。\n\n" +
|
|
194
|
-
"你是經
|
|
194
|
+
"你是經 conversation 派生的子代理:彙報簡潔,結論先行。",
|
|
195
195
|
},
|
|
196
196
|
"sisyphus-junior": {
|
|
197
197
|
description: "單點執行:範圍已定好的實作任務,同等紀律、不再委派",
|
|
@@ -294,7 +294,7 @@ export const DEFAULT_TEMPLATES = [
|
|
|
294
294
|
"- 给出结构化分析:现状、候选方案与权衡、推荐方案及理由。\n" +
|
|
295
295
|
"- 只描述该改什么、怎么改,不直接做文件编辑——执行留给主 agent 或 implement。\n" +
|
|
296
296
|
"- 结尾给可执行的建议清单,主 agent 看完就能动手。\n\n" +
|
|
297
|
-
"你是经
|
|
297
|
+
"你是经 conversation 派生的子代理:汇报要简洁具体,主 agent 会基于你的结论决策。",
|
|
298
298
|
systemPromptEn: "You are an oracle specialist subagent: a read-only, high-IQ consultant. Analyze and recommend; do not edit files directly.\n\n" +
|
|
299
299
|
"Use for: complex architecture design, bugs that survived 2+ fix attempts, unfamiliar code patterns, security/performance concerns, multi-system tradeoffs.\n" +
|
|
300
300
|
"Simple file operations, first-attempt fixes, or questions answerable from code already read do not need you.\n\n" +
|
|
@@ -303,7 +303,7 @@ export const DEFAULT_TEMPLATES = [
|
|
|
303
303
|
"- Deliver structured analysis: current state, candidate options with trade-offs, recommended option with reasons.\n" +
|
|
304
304
|
"- Describe what should change and how; leave the edits to the main agent or implement.\n" +
|
|
305
305
|
"- End with an actionable recommendation list the main agent can execute.\n\n" +
|
|
306
|
-
"You are a subagent spawned via
|
|
306
|
+
"You are a subagent spawned via conversation: report back concisely; the main agent decides based on your conclusions.",
|
|
307
307
|
enabledSkills: [],
|
|
308
308
|
enabledExtensions: [],
|
|
309
309
|
model: "",
|
|
@@ -322,14 +322,14 @@ export const DEFAULT_TEMPLATES = [
|
|
|
322
322
|
"- 广撒网:文档、官方示例、开源实现多角度找,交叉验证后再下结论。\n" +
|
|
323
323
|
"- 每条结论给出来源(链接或包路径+版本),区分“文档原话”和“你的推断”。\n" +
|
|
324
324
|
"- 结尾给综合结论:可直接用的 API/模式 + 最小示例 + 注意事项。\n\n" +
|
|
325
|
-
"你是经
|
|
325
|
+
"你是经 conversation 派生的子代理:汇报要简洁具体,附来源。",
|
|
326
326
|
systemPromptEn: "You are a librarian specialist subagent: an external-research specialist. Deliver research conclusions; do not edit local files directly.\n\n" +
|
|
327
327
|
"Use for: unfamiliar third-party libraries, framework best practices, odd external-dependency behavior, open-source usage examples.\n\n" +
|
|
328
328
|
"Working rules:\n" +
|
|
329
329
|
"- Cast a wide net: docs, official examples, and open-source implementations; cross-check before concluding.\n" +
|
|
330
330
|
"- Cite a source (link or package path + version) per conclusion; separate what the docs say from your inferences.\n" +
|
|
331
331
|
"- End with a synthesis: directly usable API/pattern + minimal example + caveats.\n\n" +
|
|
332
|
-
"You are a subagent spawned via
|
|
332
|
+
"You are a subagent spawned via conversation: report back concisely, with sources.",
|
|
333
333
|
enabledSkills: [],
|
|
334
334
|
enabledExtensions: [],
|
|
335
335
|
model: "",
|
|
@@ -444,14 +444,14 @@ export const DEFAULT_TEMPLATES = [
|
|
|
444
444
|
"- 图片/图表:描述视觉内容(布局、关键元素、数据趋势),再给结论。\n" +
|
|
445
445
|
"- 文本类 PDF:给出结构化摘要 + 关键原文引用(含页码/位置)。\n" +
|
|
446
446
|
"- 读不到或格式不支持时如实说,不要编造内容。\n\n" +
|
|
447
|
-
"你是经
|
|
447
|
+
"你是经 conversation 派生的子代理:汇报简洁,结论先行。",
|
|
448
448
|
systemPromptEn: "You are a multimodal-looker specialist subagent: interpret PDFs, images, and diagrams.\n\n" +
|
|
449
449
|
"Working rules:\n" +
|
|
450
450
|
"- Stick to the extraction goal given in the task; extract only what was asked, do not transcribe everything.\n" +
|
|
451
451
|
"- Images/diagrams: describe the visual content (layout, key elements, data trends), then conclude.\n" +
|
|
452
452
|
"- Text PDFs: structured summary + key verbatim quotes (with page/location).\n" +
|
|
453
453
|
"- If a file cannot be read or the format is unsupported, say so honestly; never fabricate content.\n\n" +
|
|
454
|
-
"You are a subagent spawned via
|
|
454
|
+
"You are a subagent spawned via conversation: report concisely, conclusion first.",
|
|
455
455
|
enabledSkills: [],
|
|
456
456
|
enabledExtensions: [],
|
|
457
457
|
model: "",
|
|
@@ -154,6 +154,15 @@ export const AGENT_TOOL_CATALOG = [
|
|
|
154
154
|
descKey: "compactContextEnabledDesc",
|
|
155
155
|
offHintKey: "compactContextOffHint",
|
|
156
156
|
},
|
|
157
|
+
{
|
|
158
|
+
// 只读:把被 Sol-Pi 打包外置的工具输出取回来(占位符里给了 `obs_…` id)。
|
|
159
|
+
// 默认开:关掉之后模型只能看到一个「调不存在的工具」的占位符提示,等于逼它重跑命令。
|
|
160
|
+
name: toolNames.OBS_RECALL_TOOL_NAME,
|
|
161
|
+
group: "other",
|
|
162
|
+
defaultOn: true,
|
|
163
|
+
descKey: "obsRecallEnabledDesc",
|
|
164
|
+
offHintKey: "obsRecallOffHint",
|
|
165
|
+
},
|
|
157
166
|
{
|
|
158
167
|
name: toolNames.MCP_MANAGE_TOOL_NAME,
|
|
159
168
|
group: "other",
|
|
@@ -46,6 +46,8 @@ export const PRESENT_FILES_TOOL_NAME = "present_files";
|
|
|
46
46
|
export const CLAIM_FILES_TOOL_NAME = "claim_files";
|
|
47
47
|
export const PLAN_UPDATE_TOOL_NAME = "plan_update";
|
|
48
48
|
export const COMPACT_CONTEXT_TOOL_NAME = "compact_context";
|
|
49
|
+
/** 取回被上下文打包层外置的工具输出原文(占位符里给的 `obs_…` id)。 */
|
|
50
|
+
export const OBS_RECALL_TOOL_NAME = "obs_recall";
|
|
49
51
|
export const PATCH_TOOL_NAME = "patch";
|
|
50
52
|
export const LSP_TOOL_NAME = "lsp";
|
|
51
53
|
export const MCP_MANAGE_TOOL_NAME = "mcp_manage";
|
|
@@ -25,12 +25,39 @@ const SCRIPT_NAME_MAX = 80;
|
|
|
25
25
|
export class BackgroundTaskService {
|
|
26
26
|
options;
|
|
27
27
|
views = new Map();
|
|
28
|
+
/** 孤儿运行时过户映射:`oldClientId -> newClientId`,避免过户前启动的任务终态找不到会话。 */
|
|
29
|
+
rebinds = new Map();
|
|
28
30
|
constructor(options) {
|
|
29
31
|
this.options = options;
|
|
30
32
|
}
|
|
33
|
+
/** 孤儿运行时过户给新 clientId 时迁移视图并记录映射,确保此前在跑的任务终态仍能回调到新会话。 */
|
|
34
|
+
rebindClient(oldId, newId) {
|
|
35
|
+
if (!oldId || !newId || oldId === newId)
|
|
36
|
+
return;
|
|
37
|
+
this.rebinds.set(oldId, newId);
|
|
38
|
+
const oldView = this.views.get(oldId);
|
|
39
|
+
if (oldView) {
|
|
40
|
+
this.views.delete(oldId);
|
|
41
|
+
if (!this.views.has(newId))
|
|
42
|
+
this.views.set(newId, oldView);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
resolveClientId(clientId) {
|
|
46
|
+
let cur = clientId;
|
|
47
|
+
const seen = new Set();
|
|
48
|
+
while (cur && !seen.has(cur)) {
|
|
49
|
+
seen.add(cur);
|
|
50
|
+
const next = this.rebinds.get(cur);
|
|
51
|
+
if (!next)
|
|
52
|
+
break;
|
|
53
|
+
cur = next;
|
|
54
|
+
}
|
|
55
|
+
return cur;
|
|
56
|
+
}
|
|
31
57
|
/** 该客户端的任务视图(共享注册表 + `clientId` 过滤)。 */
|
|
32
|
-
registryFor(clientId) {
|
|
33
|
-
const
|
|
58
|
+
registryFor(clientId, getClientId) {
|
|
59
|
+
const resolved = this.resolveClientId(clientId);
|
|
60
|
+
const existing = this.views.get(resolved);
|
|
34
61
|
if (existing)
|
|
35
62
|
return existing;
|
|
36
63
|
const registry = backgroundTaskHost(this.options.dataDir, {
|
|
@@ -45,8 +72,8 @@ export class BackgroundTaskService {
|
|
|
45
72
|
this.notifyProgress(task.clientId, { ...toJobSnapshot(task), tail });
|
|
46
73
|
},
|
|
47
74
|
});
|
|
48
|
-
const view = new ClientJobs(registry,
|
|
49
|
-
this.views.set(
|
|
75
|
+
const view = new ClientJobs(registry, getClientId ?? resolved);
|
|
76
|
+
this.views.set(resolved, view);
|
|
50
77
|
return view;
|
|
51
78
|
}
|
|
52
79
|
/** 注册表变化时刷新所有在线客户端的面板(任务归属由各自的视图隔离)。 */
|
|
@@ -169,17 +196,21 @@ export class BackgroundTaskService {
|
|
|
169
196
|
const origin = snapshot?.origin ?? session.activeConversationId?.();
|
|
170
197
|
if (!origin)
|
|
171
198
|
return;
|
|
172
|
-
const notice =
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
199
|
+
const notice = {
|
|
200
|
+
...(snapshot
|
|
201
|
+
? jobExitNotice({ ...snapshot, origin }, jobs.tail(id, 40) || undefined)
|
|
202
|
+
: jobExitNotice({
|
|
203
|
+
id,
|
|
204
|
+
command: id,
|
|
205
|
+
origin,
|
|
206
|
+
status: "killed",
|
|
207
|
+
reason: "killed",
|
|
208
|
+
endTime: Date.now(),
|
|
209
|
+
error: "Background job does not exist or has ended",
|
|
210
|
+
})),
|
|
211
|
+
// 仅补写转录让面板不再卡在 running,不唤醒 AI。
|
|
212
|
+
triggerTurn: false,
|
|
213
|
+
};
|
|
183
214
|
try {
|
|
184
215
|
await session.noteStructured(origin, notice);
|
|
185
216
|
}
|
|
@@ -190,25 +221,28 @@ export class BackgroundTaskService {
|
|
|
190
221
|
this.views.clear();
|
|
191
222
|
}
|
|
192
223
|
refresh(clientId) {
|
|
224
|
+
const targetId = this.resolveClientId(clientId);
|
|
193
225
|
try {
|
|
194
226
|
void this.options
|
|
195
|
-
.getSession(
|
|
227
|
+
.getSession(targetId)
|
|
196
228
|
?.listBgServers()
|
|
197
229
|
?.catch(() => { });
|
|
198
230
|
}
|
|
199
231
|
catch { }
|
|
200
232
|
}
|
|
201
233
|
notice(clientId, level, text, textEn) {
|
|
202
|
-
this.options.getSession(clientId)?.emitNotice(level, text, textEn);
|
|
234
|
+
this.options.getSession(this.resolveClientId(clientId))?.emitNotice(level, text, textEn);
|
|
203
235
|
}
|
|
204
236
|
notifyExit(clientId, job) {
|
|
237
|
+
const targetId = this.resolveClientId(clientId);
|
|
205
238
|
const reason = job.reason ?? "exit";
|
|
206
|
-
this.notice(
|
|
239
|
+
this.notice(targetId, reason === "spawn-error" ? "error" : "info", `后台任务 ${job.id} 已结束(${reason},退出码 ${job.exitCode ?? "null"}):${job.command}`, `Background job ${job.id} finished (${reason}, exit=${job.exitCode ?? "null"}): ${job.command}`);
|
|
207
240
|
this.noteTranscript(job, jobExitNotice(job, job.tail));
|
|
208
241
|
}
|
|
209
242
|
notifyProgress(clientId, job) {
|
|
243
|
+
const targetId = this.resolveClientId(clientId);
|
|
210
244
|
const elapsed = Math.max(1, Math.round((Date.now() - job.since) / 1000));
|
|
211
|
-
this.notice(
|
|
245
|
+
this.notice(targetId, "info", `后台任务 ${job.id} 已运行 ${elapsed} 秒:${job.command}`, `Background job ${job.id} has been running for ${elapsed}s: ${job.command}`);
|
|
212
246
|
this.noteTranscript(job, jobProgressNotice(job, elapsed, job.tail));
|
|
213
247
|
}
|
|
214
248
|
/**
|
|
@@ -222,13 +256,18 @@ export class BackgroundTaskService {
|
|
|
222
256
|
const origin = job.origin;
|
|
223
257
|
if (!origin)
|
|
224
258
|
return;
|
|
225
|
-
const
|
|
259
|
+
const targetId = this.resolveClientId(job.clientId ?? "");
|
|
260
|
+
const session = this.options.getSession(targetId);
|
|
226
261
|
if (!session?.noteStructured)
|
|
227
262
|
return;
|
|
228
263
|
try {
|
|
229
|
-
void session.noteStructured(origin, notice).catch(() => {
|
|
264
|
+
void session.noteStructured(origin, notice).catch((err) => {
|
|
265
|
+
console.error("[bg-tasks] noteStructured failed:", err);
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
catch (err) {
|
|
269
|
+
console.error("[bg-tasks] noteStructured threw:", err);
|
|
230
270
|
}
|
|
231
|
-
catch { }
|
|
232
271
|
}
|
|
233
272
|
}
|
|
234
273
|
/** 这些消息由宿主直接处理,不能进入引擎的可选实现,否则换引擎就会失效。 */
|
|
@@ -40,20 +40,21 @@ export function toJobSpec(spec, clientId) {
|
|
|
40
40
|
}
|
|
41
41
|
export class ClientJobs {
|
|
42
42
|
registry;
|
|
43
|
-
|
|
43
|
+
resolveClientId;
|
|
44
44
|
constructor(registry, clientId) {
|
|
45
45
|
this.registry = registry;
|
|
46
|
-
this.
|
|
46
|
+
this.resolveClientId = typeof clientId === "function" ? clientId : () => clientId;
|
|
47
47
|
}
|
|
48
48
|
/** 这个客户端能不能看见这条任务(没有 clientId 视图 = 全看得见)。 */
|
|
49
49
|
visible(task) {
|
|
50
|
-
|
|
50
|
+
const id = this.resolveClientId();
|
|
51
|
+
return id === undefined || task.clientId === id;
|
|
51
52
|
}
|
|
52
53
|
mine() {
|
|
53
54
|
return this.registry.listAll().filter((task) => this.visible(task));
|
|
54
55
|
}
|
|
55
56
|
start(spec) {
|
|
56
|
-
return toJobSnapshot(this.registry.start(toJobSpec(spec, this.
|
|
57
|
+
return toJobSnapshot(this.registry.start(toJobSpec(spec, this.resolveClientId())));
|
|
57
58
|
}
|
|
58
59
|
list() {
|
|
59
60
|
return this.registry
|
|
@@ -417,30 +417,38 @@ export class BgTaskRegistry {
|
|
|
417
417
|
}
|
|
418
418
|
finalize(record, status, extra = {}) {
|
|
419
419
|
const snapshot = record.snapshot;
|
|
420
|
-
if (isTerminalStatus(snapshot.status))
|
|
420
|
+
if (isTerminalStatus(snapshot.status) || record.closing)
|
|
421
421
|
return;
|
|
422
|
+
record.closing = true;
|
|
422
423
|
if (record.timer) {
|
|
423
424
|
clearInterval(record.timer);
|
|
424
425
|
record.timer = null;
|
|
425
426
|
}
|
|
426
|
-
//
|
|
427
|
+
// 收场行必须在把状态改成终态**之前**写进日志(`writeOutput` 会拒绝终态后的写入)。
|
|
427
428
|
this.writeOutput(record, `\n[bg-task] ${status} exit=${extra.exitCode === null ? "null" : (extra.exitCode ?? "?")}\n`);
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
if (extra.signal !== undefined && extra.signal !== null)
|
|
433
|
-
snapshot.signal = extra.signal;
|
|
434
|
-
if (extra.error)
|
|
435
|
-
snapshot.error = extra.error;
|
|
436
|
-
else if (status === "failed" && !snapshot.error) {
|
|
437
|
-
snapshot.error = `exited with code ${snapshot.exitCode === null ? "null" : (snapshot.exitCode ?? "unknown")}`;
|
|
438
|
-
}
|
|
439
|
-
snapshot.bytesWritten = outputSize(snapshot.outputPath);
|
|
440
|
-
const tail = readTailText(snapshot.outputPath, 20);
|
|
441
|
-
const waiters = record.waiters.splice(0);
|
|
442
|
-
const hadWaiters = waiters.length > 0;
|
|
429
|
+
// 真值口径:**终态 ⇒ 日志已落盘**。状态在 `end()` 的 flush 回调里才翻,落盘前谁读快照都还是「运行中」,
|
|
430
|
+
// 于是 `bytesWritten` 与尾部输出(通知卡片、面板行)不会再读到 0 或半截——收场行与最后几笔输出还在
|
|
431
|
+
// 写缓冲里时,`statSync` / 读文件只看得到前半截(`bg-tasks-registry` 的单测此前就被这条竞态偶发打红)。
|
|
432
|
+
let settled = false;
|
|
443
433
|
const done = () => {
|
|
434
|
+
if (settled)
|
|
435
|
+
return;
|
|
436
|
+
settled = true;
|
|
437
|
+
snapshot.status = status;
|
|
438
|
+
snapshot.endTime = this.now();
|
|
439
|
+
if (extra.exitCode !== undefined)
|
|
440
|
+
snapshot.exitCode = extra.exitCode;
|
|
441
|
+
if (extra.signal !== undefined && extra.signal !== null)
|
|
442
|
+
snapshot.signal = extra.signal;
|
|
443
|
+
if (extra.error)
|
|
444
|
+
snapshot.error = extra.error;
|
|
445
|
+
else if (status === "failed" && !snapshot.error) {
|
|
446
|
+
snapshot.error = `exited with code ${snapshot.exitCode === null ? "null" : (snapshot.exitCode ?? "unknown")}`;
|
|
447
|
+
}
|
|
448
|
+
snapshot.bytesWritten = outputSize(snapshot.outputPath);
|
|
449
|
+
const tail = readTailText(snapshot.outputPath, 20);
|
|
450
|
+
const waiters = record.waiters.splice(0);
|
|
451
|
+
const hadWaiters = waiters.length > 0;
|
|
444
452
|
void this.persist(record);
|
|
445
453
|
this.pruneTerminal();
|
|
446
454
|
for (const wake of waiters) {
|
|
@@ -457,8 +465,11 @@ export class BgTaskRegistry {
|
|
|
457
465
|
catch { }
|
|
458
466
|
}
|
|
459
467
|
};
|
|
460
|
-
if (record.stream && !record.stream.writableEnded)
|
|
468
|
+
if (record.stream && !record.stream.writableEnded) {
|
|
469
|
+
// `close` 是兜底(日志流盘满 / 被回收时 `finish` 不一定来),否则这条会永远卡在「运行中」。
|
|
470
|
+
record.stream.once("close", done);
|
|
461
471
|
record.stream.end(done);
|
|
472
|
+
}
|
|
462
473
|
else
|
|
463
474
|
done();
|
|
464
475
|
}
|