minimal-agent 0.18.20 → 0.18.22
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/README.md +16 -3
- package/package.json +1 -1
- package/plugins/cron-runner/README.md +23 -0
- package/plugins/cron-runner/commands/cron.md +7 -1
- package/plugins/cron-runner/plugin.js +9 -2
- package/plugins/cron-runner/plugin.ts +10 -2
- package/plugins/cron-runner/src/commands.js +112 -25
- package/plugins/cron-runner/src/commands.ts +154 -33
- package/plugins/cron-runner/src/contract.js +70 -0
- package/plugins/cron-runner/src/contract.ts +70 -0
- package/plugins/cron-runner/src/requests.js +22 -13
- package/plugins/cron-runner/src/requests.ts +34 -14
- package/plugins/cron-runner/src/runs.js +63 -10
- package/plugins/cron-runner/src/runs.ts +107 -15
- package/plugins/cron-runner/src/scheduler.js +188 -76
- package/plugins/cron-runner/src/scheduler.ts +277 -94
- package/plugins/cron-runner/src/schema.js +52 -17
- package/plugins/cron-runner/src/schema.ts +73 -22
- package/plugins/cron-runner/src/service.js +29 -8
- package/plugins/cron-runner/src/service.ts +71 -18
- package/plugins/cron-runner/src/store.js +92 -30
- package/plugins/cron-runner/src/store.ts +156 -53
- package/plugins/cron-runner/src/transaction.js +24 -0
- package/plugins/cron-runner/src/transaction.ts +36 -0
- package/plugins/cron-runner/src/types.ts +30 -4
- package/plugins/cron-runner/test/lifecycle.test.ts +419 -0
- package/plugins/cron-runner/test/plugin-integration.test.ts +3 -2
- package/plugins/cron-runner/test/reliability.test.ts +2 -2
- package/plugins/cron-runner/test/store-and-scheduler.test.ts +9 -7
- package/plugins/workflow-runner/plugin.js +1 -0
- package/plugins/workflow-runner/plugin.ts +1 -0
- package/plugins/workflow-runner/src/index.js +1 -0
- package/plugins/workflow-runner/src/index.ts +2 -0
- package/plugins/workflow-runner/src/runner.js +6 -1
- package/plugins/workflow-runner/src/runner.ts +5 -1
- package/plugins/workflow-runner/src/types.ts +1 -0
- package/plugins/workflow-runner/test/api.test.ts +1 -0
- package/plugins/workflow-runner/test/apiCapabilities.test.ts +4 -0
- package/plugins/workflow-runner/test/apiConcurrencyGate.test.ts +1 -0
- package/plugins/workflow-runner/test/childWorkflow.test.ts +19 -0
- package/plugins/workflow-runner/test/embeddedExecution.test.ts +23 -3
- package/src/advisor/README.md +17 -6
- package/src/advisor/advisorNudge.js +23 -3
- package/src/advisor/advisorNudge.ts +20 -3
- package/src/advisor/deliveryReview.js +9 -2
- package/src/advisor/deliveryReview.ts +10 -2
- package/src/cli/args.js +1 -0
- package/src/cli/args.ts +1 -0
- package/src/cli/headlessTurn.js +143 -0
- package/src/cli/headlessTurn.ts +187 -0
- package/src/cli/lifecycle.js +52 -0
- package/src/cli/lifecycle.ts +59 -0
- package/src/cli/print.js +91 -240
- package/src/cli/print.ts +99 -301
- package/src/cli/quickModelSetup.js +3 -0
- package/src/cli/quickModelSetup.tsx +3 -0
- package/src/cli/streamJson.js +244 -334
- package/src/cli/streamJson.ts +248 -416
- package/src/cli/wizards/contextAdvisorWizard.js +0 -7
- package/src/cli/wizards/contextAdvisorWizard.tsx +0 -11
- package/src/cli/wizards/providerPresets.js +25 -14
- package/src/cli/wizards/providerPresets.ts +25 -14
- package/src/cli/wizards/providerWizard.js +29 -11
- package/src/cli/wizards/providerWizard.tsx +29 -11
- package/src/config/configDefaults.js +2 -2
- package/src/config/configDefaults.ts +2 -2
- package/src/config/configDiagnostics.js +7 -3
- package/src/config/configDiagnostics.ts +6 -3
- package/src/config/configFile.ts +1 -1
- package/src/context/compact.js +40 -10
- package/src/context/compact.ts +51 -12
- package/src/context/compactResources.js +39 -0
- package/src/context/compactResources.ts +35 -0
- package/src/context/manualCompact.js +20 -0
- package/src/context/manualCompact.ts +28 -0
- package/src/llm/client.js +4 -0
- package/src/llm/client.ts +4 -0
- package/src/llm/messageProvenance.js +1 -1
- package/src/llm/messageProvenance.ts +1 -1
- package/src/loop/README.md +4 -2
- package/src/loop/deliveryIntent.js +3 -2
- package/src/loop/deliveryIntent.ts +4 -2
- package/src/loop/messages.js +1 -0
- package/src/loop/messages.ts +1 -0
- package/src/loop/options.ts +2 -0
- package/src/loop.js +10 -2
- package/src/loop.ts +9 -2
- package/src/main.js +40 -45
- package/src/main.tsx +33 -52
- package/src/plugin-sdk.js +1 -1
- package/src/plugin-sdk.ts +1 -1
- package/src/plugins/artifactDelivery.js +76 -0
- package/src/plugins/artifactDelivery.ts +76 -0
- package/src/plugins/pluginApi.ts +4 -0
- package/src/plugins/pluginRunner.js +2 -0
- package/src/plugins/pluginRunner.ts +3 -0
- package/src/prompts/delegation.js +2 -2
- package/src/prompts/delegation.ts +2 -2
- package/src/prompts/policyRegistry.js +7 -5
- package/src/prompts/policyRegistry.ts +7 -5
- package/src/prompts/promptAssembly.js +2 -2
- package/src/prompts/promptAssembly.ts +2 -2
- package/src/runtime/requestIntent.js +86 -0
- package/src/runtime/requestIntent.ts +66 -0
- package/src/runtime/systemEvents.js +10 -1
- package/src/runtime/systemEvents.ts +9 -1
- package/src/session/commandTranscript.js +76 -0
- package/src/session/commandTranscript.ts +77 -0
- package/src/session/executionOutcome.js +25 -0
- package/src/session/executionOutcome.ts +34 -0
- package/src/session/runAgentTurn.js +8 -1
- package/src/session/runAgentTurn.ts +10 -1
- package/src/session/runTurn.js +40 -15
- package/src/session/runTurn.ts +38 -12
- package/src/session/sessionState.js +7 -2
- package/src/session/sessionState.ts +7 -2
- package/src/team/onlineToolContract.js +1 -0
- package/src/team/onlineToolContract.ts +1 -0
- package/src/tools/advisor/advisor.js +73 -30
- package/src/tools/advisor/advisor.ts +73 -33
- package/src/tools/advisor/advisorCoordination.js +44 -0
- package/src/tools/advisor/advisorCoordination.ts +45 -0
- package/src/tools/advisor/advisorDescription.js +1 -1
- package/src/tools/advisor/advisorDescription.ts +1 -1
- package/src/tools/agent/README.md +2 -0
- package/src/tools/agent/agent.js +7 -3
- package/src/tools/agent/agent.ts +7 -3
- package/src/tools/agent/agentHandoff.js +2 -1
- package/src/tools/agent/agentHandoff.ts +2 -1
- package/src/tools/agent/agentTaskService.js +26 -5
- package/src/tools/agent/agentTaskService.ts +25 -5
- package/src/tools/agent/agentTypes.js +2 -2
- package/src/tools/agent/agentTypes.ts +2 -2
- package/src/tools/agent/baselineAttach.js +14 -7
- package/src/tools/agent/baselineAttach.ts +14 -7
- package/src/tools/applypatch/applyPatch.js +39 -13
- package/src/tools/applypatch/applyPatch.ts +35 -15
- package/src/tools/bash/bash.js +3 -0
- package/src/tools/bash/bash.ts +3 -0
- package/src/tools/capabilities.js +1 -0
- package/src/tools/capabilities.ts +1 -0
- package/src/tools/download/download.js +147 -11
- package/src/tools/download/download.ts +193 -17
- package/src/tools/edit/edit.js +4 -4
- package/src/tools/edit/edit.ts +4 -4
- package/src/tools/edit/multi-edit.js +2 -2
- package/src/tools/edit/multi-edit.ts +2 -2
- package/src/tools/index.js +2 -0
- package/src/tools/index.ts +2 -0
- package/src/tools/powershell/powershell.js +2 -0
- package/src/tools/powershell/powershell.ts +2 -0
- package/src/tools/schedule/schedule.js +184 -0
- package/src/tools/schedule/schedule.ts +214 -0
- package/src/tools/shared/fileUtils.js +16 -6
- package/src/tools/shared/fileUtils.ts +15 -6
- package/src/tools/tasks/backgroundTaskService.js +108 -12
- package/src/tools/tasks/backgroundTaskService.ts +106 -14
- package/src/tools/tasks/taskOutput.js +15 -5
- package/src/tools/tasks/taskOutput.ts +13 -5
- package/src/tools/tasks/taskStop.js +2 -2
- package/src/tools/tasks/taskStop.ts +2 -2
- package/src/tools/toolPromptGuides.js +4 -3
- package/src/tools/toolPromptGuides.ts +4 -3
- package/src/tools/webfetch/webfetch.js +1 -1
- package/src/tools/webfetch/webfetch.ts +1 -1
- package/src/types.ts +6 -0
- package/src/ui/App.js +3 -1
- package/src/ui/App.tsx +2 -0
- package/src/ui/InputBox.js +2 -2
- package/src/ui/InputBox.tsx +2 -2
- package/src/ui/LiveArea.js +6 -1
- package/src/ui/LiveArea.tsx +6 -1
- package/src/ui/MessageList.js +2 -0
- package/src/ui/MessageList.tsx +2 -0
- package/src/ui/README.md +8 -2
- package/src/ui/activityPresentation.js +23 -3
- package/src/ui/activityPresentation.ts +22 -3
- package/src/ui/backgroundWake.js +20 -4
- package/src/ui/backgroundWake.ts +19 -4
- package/src/ui/commandTranscript.js +2 -69
- package/src/ui/commandTranscript.ts +2 -71
- package/src/ui/hooks/useBackgroundAgents.js +33 -0
- package/src/ui/hooks/useBackgroundAgents.ts +36 -0
- package/src/ui/hooks/useChat.js +46 -25
- package/src/ui/hooks/useChat.ts +36 -23
- package/src/web/protocol.ts +5 -2
- package/src/cli/wizards/advisorWizard.js +0 -152
- package/src/cli/wizards/advisorWizard.tsx +0 -203
package/src/ui/hooks/useChat.js
CHANGED
|
@@ -20,6 +20,7 @@ import { createTurnSummary } from '../turnSummary.js';
|
|
|
20
20
|
import { isRecoverableLoopError } from '../../runtime/eventSemantics.js';
|
|
21
21
|
import { isWorkflowMilestone, projectWorkflowProgress, projectPluginProgress } from '../../runtime/workflowPresentation.js';
|
|
22
22
|
import { captureCommandReply, commandRequest } from '../commandTranscript.js';
|
|
23
|
+
import { useBackgroundAgents } from './useBackgroundAgents.js';
|
|
23
24
|
import { createPublicTextStream } from '../publicText.js';
|
|
24
25
|
import { createLearningModel } from '../../memory/learningModel.js';
|
|
25
26
|
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
@@ -27,7 +28,8 @@ import { createAskCoordinator, setAskHandler, } from '../../askBridge.js';
|
|
|
27
28
|
import { getWorkingDir, setWorkingDir } from '../../bootstrap/workingDir.js';
|
|
28
29
|
import { createCliComputerRun, createComputerUseHostGate, } from '../../cli/computerUse.js';
|
|
29
30
|
import { resolveLocalBrowserRun } from '../../cli/browser.js';
|
|
30
|
-
import {
|
|
31
|
+
import { manualCompactNotice } from '../../context/compact.js';
|
|
32
|
+
import { compactSession } from '../../context/manualCompact.js';
|
|
31
33
|
import { acquireContextLock } from '../../context/contextLock.js';
|
|
32
34
|
import { clearContext, loadContext, saveContext, } from '../../context/persistContext.js';
|
|
33
35
|
import { resetReactiveCompactState } from '../../context/reactiveCompact.js';
|
|
@@ -255,6 +257,8 @@ export function useChat(args) {
|
|
|
255
257
|
const activeSessionIdRef = useRef('default');
|
|
256
258
|
const initialSessionReadyRef = useRef(Promise.resolve());
|
|
257
259
|
const [activeSessionId, setActiveSessionId] = useState('default');
|
|
260
|
+
const [agentBinding, setAgentBinding] = useState(null);
|
|
261
|
+
const backgroundAgents = useBackgroundAgents(agentBinding, JSON.stringify([getWorkingDir(), activeSessionId]));
|
|
258
262
|
/** 当前 active session 对应的持久化文件路径(同步,按 ref 取) */
|
|
259
263
|
const sessionFile = useCallback(() => {
|
|
260
264
|
return sessionFileFor(getWorkingDir(), activeSessionIdRef.current);
|
|
@@ -448,8 +452,7 @@ export function useChat(args) {
|
|
|
448
452
|
if (!isWake)
|
|
449
453
|
backgroundWake.notifyUserInput();
|
|
450
454
|
if (isLoadingRef.current) {
|
|
451
|
-
//
|
|
452
|
-
// 而且没必要——回合在跑时 loop 自己会在模型边界取走完成通知。
|
|
455
|
+
// 系统接续只留在后台信箱中;绝不进入会打断真人回合的输入队列。
|
|
453
456
|
if (isWake)
|
|
454
457
|
return;
|
|
455
458
|
inputQueue.enqueue(trimmed, 'next');
|
|
@@ -498,6 +501,8 @@ export function useChat(args) {
|
|
|
498
501
|
releaseContextLock = await acquireContextLock(activeFile, ac.signal);
|
|
499
502
|
if (isWake && !backgroundWake.isPending(options.identity, options.continuation.taskIds))
|
|
500
503
|
return;
|
|
504
|
+
if (isWake)
|
|
505
|
+
backgroundWake.begin(options.identity, options.continuation.taskIds);
|
|
501
506
|
// Gateway/Cron may have written this cwd since the TUI rendered its last frame.
|
|
502
507
|
// Reload after acquiring the cross-process lock so this turn extends the newest history.
|
|
503
508
|
const latest = await loadContext(activeFile);
|
|
@@ -543,6 +548,7 @@ export function useChat(args) {
|
|
|
543
548
|
sessionId: activeSessionIdRef.current,
|
|
544
549
|
}));
|
|
545
550
|
backgroundWake.bind(wakeIdentity(), turnSessionState.backgroundTasks);
|
|
551
|
+
setAgentBinding({ key: wakeIdentity(), state: turnSessionState.agentTasks });
|
|
546
552
|
await hydrateSessionWorktree({
|
|
547
553
|
sessionState: turnSessionState,
|
|
548
554
|
workspaceId: workspace?.id,
|
|
@@ -645,6 +651,7 @@ export function useChat(args) {
|
|
|
645
651
|
userMessageId,
|
|
646
652
|
chat: args.chat,
|
|
647
653
|
backgroundContinuation: options?.continuation,
|
|
654
|
+
deferBackgroundNotifications: true,
|
|
648
655
|
provider: turnProvider,
|
|
649
656
|
history: historyRef.current,
|
|
650
657
|
signal: ac.signal,
|
|
@@ -772,6 +779,8 @@ export function useChat(args) {
|
|
|
772
779
|
// 中断/失败后不再自动唤醒,等真人再说话:用户刚按下 ESC,紧接着自己
|
|
773
780
|
// 又跑起来是敌意行为。排队里有真人输入时,它的 notifyUserInput 会把
|
|
774
781
|
// 这里刚安排上的唤醒撤掉(防抖窗口远长于一个微任务)。
|
|
782
|
+
if (isWake)
|
|
783
|
+
backgroundWake.finish(options.identity, options.continuation.taskIds, !ac.signal.aborted && turnOutcome === 'completed');
|
|
775
784
|
finishHostOperation(ac.signal.aborted ? 'interrupted' : turnOutcome);
|
|
776
785
|
}
|
|
777
786
|
}, [
|
|
@@ -929,7 +938,7 @@ export function useChat(args) {
|
|
|
929
938
|
*
|
|
930
939
|
* ✅ 关键改进:压缩失败时不保存 history(可能包含损坏数据)
|
|
931
940
|
*/
|
|
932
|
-
const compactNow = useCallback(async () => {
|
|
941
|
+
const compactNow = useCallback(async (customInstructions) => {
|
|
933
942
|
if (isLoadingRef.current)
|
|
934
943
|
return;
|
|
935
944
|
setIsLoading(true);
|
|
@@ -938,6 +947,8 @@ export function useChat(args) {
|
|
|
938
947
|
setError(null);
|
|
939
948
|
// 压缩前清掉任何待 flush 的 streaming buffer(避免压缩中 timer 触发干扰)
|
|
940
949
|
cancelAllThrottles();
|
|
950
|
+
const ac = new AbortController();
|
|
951
|
+
abortRef.current = ac;
|
|
941
952
|
let success = false;
|
|
942
953
|
try {
|
|
943
954
|
await initialSessionReadyRef.current;
|
|
@@ -945,39 +956,48 @@ export function useChat(args) {
|
|
|
945
956
|
const workspace = await workspaceIndexService
|
|
946
957
|
.findByPath(cwd)
|
|
947
958
|
.catch(() => null);
|
|
948
|
-
const r = await
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
959
|
+
const r = await compactSession({
|
|
960
|
+
history: historyRef.current,
|
|
961
|
+
sessionFile: sessionFile(),
|
|
962
|
+
// ⚠️ 用 providerRef.current 而非 args.provider:后者是 useChat 挂载时的
|
|
963
|
+
// 初始 prop,全程冻结不变;/model 切换只更新 providerRef,若这里继续用
|
|
964
|
+
// args.provider,切换模型后手动 /compact 仍会按旧模型的 contextWindow/
|
|
965
|
+
// compactRatio 算阈值和输出预算。
|
|
966
|
+
provider: providerRef.current,
|
|
967
|
+
signal: ac.signal,
|
|
968
|
+
customInstructions,
|
|
969
|
+
promptCache: createPromptCacheContext(`workspace:${workspace?.id ?? cwd}:session:${activeSessionIdRef.current}`),
|
|
970
|
+
});
|
|
954
971
|
historyRef.current.length = 0;
|
|
955
972
|
historyRef.current.push(...r.messages);
|
|
956
973
|
// 压缩后 MessageList 要 remount,丢掉旧 <Static> 缓存
|
|
957
974
|
setCompactGeneration((g) => g + 1);
|
|
958
975
|
bump();
|
|
976
|
+
setProgressNotice(manualCompactNotice(r));
|
|
959
977
|
success = true; // ✅ 标记成功
|
|
978
|
+
// The transaction is already committed; a presentation callback cannot
|
|
979
|
+
// turn this into a claim that the original context was retained.
|
|
980
|
+
if (!r.unchangedReason) {
|
|
981
|
+
try {
|
|
982
|
+
args.onCompactDone?.();
|
|
983
|
+
}
|
|
984
|
+
catch {
|
|
985
|
+
setProgressNotice(`${manualCompactNotice(r)} 界面通知未完成,请重新打开会话。`);
|
|
986
|
+
}
|
|
987
|
+
}
|
|
960
988
|
}
|
|
961
989
|
catch (e) {
|
|
962
|
-
|
|
990
|
+
if (ac.signal.aborted)
|
|
991
|
+
setProgressNotice('压缩已取消,原上下文保持不变。');
|
|
992
|
+
else
|
|
993
|
+
setError(`手动压缩失败,原上下文保持不变:${e.message}`);
|
|
963
994
|
// ❌ 不修改 historyRef.current,保持原样(不保存可能损坏的数据)
|
|
964
995
|
}
|
|
965
996
|
finally {
|
|
966
997
|
setProgressStage('idle');
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
await saveContext(historyRef.current, sessionFile());
|
|
971
|
-
args.onCompactDone?.();
|
|
972
|
-
}
|
|
973
|
-
}
|
|
974
|
-
catch (error) {
|
|
975
|
-
success = false;
|
|
976
|
-
setError(`压缩后保存失败:${error.message}`);
|
|
977
|
-
}
|
|
978
|
-
finally {
|
|
979
|
-
finishHostOperation(success ? 'completed' : 'failed');
|
|
980
|
-
}
|
|
998
|
+
if (abortRef.current === ac)
|
|
999
|
+
abortRef.current = null;
|
|
1000
|
+
finishHostOperation(success ? 'completed' : ac.signal.aborted ? 'interrupted' : 'failed');
|
|
981
1001
|
}
|
|
982
1002
|
}, [
|
|
983
1003
|
args.onCompactDone,
|
|
@@ -1175,6 +1195,7 @@ export function useChat(args) {
|
|
|
1175
1195
|
progressStage,
|
|
1176
1196
|
reasoningActive,
|
|
1177
1197
|
runningTools,
|
|
1198
|
+
backgroundAgents,
|
|
1178
1199
|
contextUsage,
|
|
1179
1200
|
computerUseMode,
|
|
1180
1201
|
setComputerUseMode,
|
package/src/ui/hooks/useChat.ts
CHANGED
|
@@ -21,6 +21,7 @@ import { createTurnSummary } from '../turnSummary.js';
|
|
|
21
21
|
import { isRecoverableLoopError } from '../../runtime/eventSemantics.js';
|
|
22
22
|
import { isWorkflowMilestone, projectWorkflowProgress, projectPluginProgress, type WorkflowPresentation } from '../../runtime/workflowPresentation.js';
|
|
23
23
|
import { captureCommandReply, commandRequest } from '../commandTranscript.js';
|
|
24
|
+
import { useBackgroundAgents } from './useBackgroundAgents.js';
|
|
24
25
|
import { createPublicTextStream } from '../publicText.js';
|
|
25
26
|
import { createLearningModel } from '../../memory/learningModel.js';
|
|
26
27
|
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
@@ -39,7 +40,8 @@ import {
|
|
|
39
40
|
createComputerUseHostGate,
|
|
40
41
|
} from '../../cli/computerUse.js';
|
|
41
42
|
import { resolveLocalBrowserRun } from '../../cli/browser.js';
|
|
42
|
-
import {
|
|
43
|
+
import { manualCompactNotice } from '../../context/compact.js';
|
|
44
|
+
import { compactSession } from '../../context/manualCompact.js';
|
|
43
45
|
import { acquireContextLock } from '../../context/contextLock.js';
|
|
44
46
|
import {
|
|
45
47
|
clearContext,
|
|
@@ -161,6 +163,7 @@ export interface UseChatResult {
|
|
|
161
163
|
reasoningActive: boolean;
|
|
162
164
|
/** 当前所有运行中工具(用数组而不是 Map,便于 React render;按 callId 顺序稳定) */
|
|
163
165
|
runningTools: ToolStatusState[];
|
|
166
|
+
backgroundAgents: ToolStatusState[];
|
|
164
167
|
/**
|
|
165
168
|
* 内核最近一次 yield 的真实上下文用量;启动后/尚未跑过一轮时为 null,
|
|
166
169
|
* StatusLine 此时降级回本地 useTokenUsage 估算。
|
|
@@ -190,7 +193,7 @@ export interface UseChatResult {
|
|
|
190
193
|
/** 清空对话上下文(保留 system prompt);isLoading 时无效 */
|
|
191
194
|
clearHistory: () => Promise<void>;
|
|
192
195
|
/** 手动压缩对话上下文(不看阈值);isLoading 时无效 */
|
|
193
|
-
compactNow: () => Promise<void>;
|
|
196
|
+
compactNow: (instructions?: string) => Promise<void>;
|
|
194
197
|
/**
|
|
195
198
|
* `/advisor ask` 手动咨询顾问模型。与工具路径共用过程显示(LiveArea 进度行)
|
|
196
199
|
* 并可被 ESC 中断;isLoading 时拒绝执行并返回带原因的失败结果。
|
|
@@ -513,6 +516,8 @@ export function useChat(args: {
|
|
|
513
516
|
const activeSessionIdRef = useRef<string>('default');
|
|
514
517
|
const initialSessionReadyRef = useRef<Promise<void>>(Promise.resolve());
|
|
515
518
|
const [activeSessionId, setActiveSessionId] = useState<string>('default');
|
|
519
|
+
const [agentBinding, setAgentBinding] = useState<Parameters<typeof useBackgroundAgents>[0]>(null);
|
|
520
|
+
const backgroundAgents = useBackgroundAgents(agentBinding, JSON.stringify([getWorkingDir(), activeSessionId]));
|
|
516
521
|
|
|
517
522
|
/** 当前 active session 对应的持久化文件路径(同步,按 ref 取) */
|
|
518
523
|
const sessionFile = useCallback(() => {
|
|
@@ -727,8 +732,7 @@ export function useChat(args: {
|
|
|
727
732
|
if (!isWake) backgroundWake.notifyUserInput();
|
|
728
733
|
|
|
729
734
|
if (isLoadingRef.current) {
|
|
730
|
-
//
|
|
731
|
-
// 而且没必要——回合在跑时 loop 自己会在模型边界取走完成通知。
|
|
735
|
+
// 系统接续只留在后台信箱中;绝不进入会打断真人回合的输入队列。
|
|
732
736
|
if (isWake) return;
|
|
733
737
|
inputQueue.enqueue(trimmed, 'next');
|
|
734
738
|
const running = Array.from(runningToolsRef.current.values());
|
|
@@ -787,6 +791,7 @@ export function useChat(args: {
|
|
|
787
791
|
);
|
|
788
792
|
releaseContextLock = await acquireContextLock(activeFile, ac.signal);
|
|
789
793
|
if (isWake && !backgroundWake.isPending(options!.identity!, options!.continuation!.taskIds)) return;
|
|
794
|
+
if (isWake) backgroundWake.begin(options!.identity!, options!.continuation!.taskIds);
|
|
790
795
|
// Gateway/Cron may have written this cwd since the TUI rendered its last frame.
|
|
791
796
|
// Reload after acquiring the cross-process lock so this turn extends the newest history.
|
|
792
797
|
const latest = await loadContext(activeFile);
|
|
@@ -841,6 +846,7 @@ export function useChat(args: {
|
|
|
841
846
|
}),
|
|
842
847
|
);
|
|
843
848
|
backgroundWake.bind(wakeIdentity(), turnSessionState.backgroundTasks);
|
|
849
|
+
setAgentBinding({ key: wakeIdentity(), state: turnSessionState.agentTasks });
|
|
844
850
|
await hydrateSessionWorktree({
|
|
845
851
|
sessionState: turnSessionState,
|
|
846
852
|
workspaceId: workspace?.id,
|
|
@@ -965,6 +971,7 @@ export function useChat(args: {
|
|
|
965
971
|
userMessageId,
|
|
966
972
|
chat: args.chat,
|
|
967
973
|
backgroundContinuation: options?.continuation,
|
|
974
|
+
deferBackgroundNotifications: true,
|
|
968
975
|
provider: turnProvider,
|
|
969
976
|
history: historyRef.current,
|
|
970
977
|
signal: ac.signal,
|
|
@@ -1087,6 +1094,8 @@ export function useChat(args: {
|
|
|
1087
1094
|
// 中断/失败后不再自动唤醒,等真人再说话:用户刚按下 ESC,紧接着自己
|
|
1088
1095
|
// 又跑起来是敌意行为。排队里有真人输入时,它的 notifyUserInput 会把
|
|
1089
1096
|
// 这里刚安排上的唤醒撤掉(防抖窗口远长于一个微任务)。
|
|
1097
|
+
if (isWake) backgroundWake.finish(options!.identity!, options!.continuation!.taskIds,
|
|
1098
|
+
!ac.signal.aborted && turnOutcome === 'completed');
|
|
1090
1099
|
finishHostOperation(
|
|
1091
1100
|
ac.signal.aborted ? 'interrupted' : turnOutcome,
|
|
1092
1101
|
);
|
|
@@ -1267,7 +1276,7 @@ export function useChat(args: {
|
|
|
1267
1276
|
*
|
|
1268
1277
|
* ✅ 关键改进:压缩失败时不保存 history(可能包含损坏数据)
|
|
1269
1278
|
*/
|
|
1270
|
-
const compactNow = useCallback(async () => {
|
|
1279
|
+
const compactNow = useCallback(async (customInstructions?: string) => {
|
|
1271
1280
|
if (isLoadingRef.current) return;
|
|
1272
1281
|
setIsLoading(true);
|
|
1273
1282
|
// 手动压缩仍然把 progressStage 切到 compacting,给 LiveArea 显示用
|
|
@@ -1275,6 +1284,8 @@ export function useChat(args: {
|
|
|
1275
1284
|
setError(null);
|
|
1276
1285
|
// 压缩前清掉任何待 flush 的 streaming buffer(避免压缩中 timer 触发干扰)
|
|
1277
1286
|
cancelAllThrottles();
|
|
1287
|
+
const ac = new AbortController();
|
|
1288
|
+
abortRef.current = ac;
|
|
1278
1289
|
let success = false;
|
|
1279
1290
|
try {
|
|
1280
1291
|
await initialSessionReadyRef.current;
|
|
@@ -1282,40 +1293,41 @@ export function useChat(args: {
|
|
|
1282
1293
|
const workspace = await workspaceIndexService
|
|
1283
1294
|
.findByPath(cwd)
|
|
1284
1295
|
.catch(() => null);
|
|
1285
|
-
const r = await
|
|
1286
|
-
historyRef.current,
|
|
1296
|
+
const r = await compactSession({
|
|
1297
|
+
history: historyRef.current,
|
|
1298
|
+
sessionFile: sessionFile(),
|
|
1287
1299
|
// ⚠️ 用 providerRef.current 而非 args.provider:后者是 useChat 挂载时的
|
|
1288
1300
|
// 初始 prop,全程冻结不变;/model 切换只更新 providerRef,若这里继续用
|
|
1289
1301
|
// args.provider,切换模型后手动 /compact 仍会按旧模型的 contextWindow/
|
|
1290
1302
|
// compactRatio 算阈值和输出预算。
|
|
1291
|
-
providerRef.current,
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
createPromptCacheContext(
|
|
1303
|
+
provider: providerRef.current,
|
|
1304
|
+
signal: ac.signal,
|
|
1305
|
+
customInstructions,
|
|
1306
|
+
promptCache: createPromptCacheContext(
|
|
1295
1307
|
`workspace:${workspace?.id ?? cwd}:session:${activeSessionIdRef.current}`,
|
|
1296
1308
|
),
|
|
1297
|
-
);
|
|
1309
|
+
});
|
|
1298
1310
|
historyRef.current.length = 0;
|
|
1299
1311
|
historyRef.current.push(...r.messages);
|
|
1300
1312
|
// 压缩后 MessageList 要 remount,丢掉旧 <Static> 缓存
|
|
1301
1313
|
setCompactGeneration((g) => g + 1);
|
|
1302
1314
|
bump();
|
|
1315
|
+
setProgressNotice(manualCompactNotice(r));
|
|
1303
1316
|
success = true; // ✅ 标记成功
|
|
1317
|
+
// The transaction is already committed; a presentation callback cannot
|
|
1318
|
+
// turn this into a claim that the original context was retained.
|
|
1319
|
+
if (!r.unchangedReason) {
|
|
1320
|
+
try { args.onCompactDone?.(); }
|
|
1321
|
+
catch { setProgressNotice(`${manualCompactNotice(r)} 界面通知未完成,请重新打开会话。`); }
|
|
1322
|
+
}
|
|
1304
1323
|
} catch (e) {
|
|
1305
|
-
|
|
1324
|
+
if (ac.signal.aborted) setProgressNotice('压缩已取消,原上下文保持不变。');
|
|
1325
|
+
else setError(`手动压缩失败,原上下文保持不变:${(e as Error).message}`);
|
|
1306
1326
|
// ❌ 不修改 historyRef.current,保持原样(不保存可能损坏的数据)
|
|
1307
1327
|
} finally {
|
|
1308
1328
|
setProgressStage('idle');
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
if (success) {
|
|
1312
|
-
await saveContext(historyRef.current, sessionFile());
|
|
1313
|
-
args.onCompactDone?.();
|
|
1314
|
-
}
|
|
1315
|
-
} catch (error) {
|
|
1316
|
-
success = false;
|
|
1317
|
-
setError(`压缩后保存失败:${(error as Error).message}`);
|
|
1318
|
-
} finally { finishHostOperation(success ? 'completed' : 'failed'); }
|
|
1329
|
+
if (abortRef.current === ac) abortRef.current = null;
|
|
1330
|
+
finishHostOperation(success ? 'completed' : ac.signal.aborted ? 'interrupted' : 'failed');
|
|
1319
1331
|
}
|
|
1320
1332
|
}, [
|
|
1321
1333
|
args.onCompactDone,
|
|
@@ -1531,6 +1543,7 @@ export function useChat(args: {
|
|
|
1531
1543
|
progressStage,
|
|
1532
1544
|
reasoningActive,
|
|
1533
1545
|
runningTools,
|
|
1546
|
+
backgroundAgents,
|
|
1534
1547
|
contextUsage,
|
|
1535
1548
|
computerUseMode,
|
|
1536
1549
|
setComputerUseMode,
|
package/src/web/protocol.ts
CHANGED
|
@@ -356,6 +356,7 @@ export interface WebchatConfig {
|
|
|
356
356
|
/** 引用 models[].id;null = 未选。顾问不再自带一整套独立凭据。 */
|
|
357
357
|
modelId: string | null;
|
|
358
358
|
contextPolicy: 'full-relevant';
|
|
359
|
+
/** @deprecated Compatibility only; runtime capacity follows the selected model. */
|
|
359
360
|
inputTokenBudget: number;
|
|
360
361
|
timeoutMs: number;
|
|
361
362
|
};
|
|
@@ -440,6 +441,7 @@ export interface WebchatConfigPatch {
|
|
|
440
441
|
mode?: 'auto' | 'manual';
|
|
441
442
|
enforcement?: 'remind' | 'followup';
|
|
442
443
|
modelId?: string | null;
|
|
444
|
+
/** @deprecated Accepted for old clients, but never limits advisor requests. */
|
|
443
445
|
inputTokenBudget?: number;
|
|
444
446
|
timeoutMs?: number;
|
|
445
447
|
};
|
|
@@ -1913,7 +1915,7 @@ export type ClientFrame =
|
|
|
1913
1915
|
modelId?: string;
|
|
1914
1916
|
}
|
|
1915
1917
|
| { t: 'plain/clear'; sessionId: string }
|
|
1916
|
-
| { t: 'plain/compact'; sessionId: string; requestId?: string }
|
|
1918
|
+
| { t: 'plain/compact'; sessionId: string; requestId?: string; customInstructions?: string }
|
|
1917
1919
|
| { t: 'plain/rename'; sessionId: string; title: string }
|
|
1918
1920
|
| { t: 'plain/delete'; sessionId: string }
|
|
1919
1921
|
| { t: 'resource/files/list'; dir: string; sessionId: string }
|
|
@@ -2205,7 +2207,7 @@ export type ClientFrame =
|
|
|
2205
2207
|
| { t: 'abort' }
|
|
2206
2208
|
| { t: 'compact/abort'; requestId: string }
|
|
2207
2209
|
| { t: 'new'; dir: string; sessionId?: string }
|
|
2208
|
-
| { t: 'compact'; dir: string; sessionId?: string; requestId?: string }
|
|
2210
|
+
| { t: 'compact'; dir: string; sessionId?: string; requestId?: string; customInstructions?: string }
|
|
2209
2211
|
| { t: 'listDirs' }
|
|
2210
2212
|
/** 探测局域网内的 minimal-server(UDP 只能在本机 Runtime 里发,浏览器上下文发不了)。 */
|
|
2211
2213
|
| { t: 'server/discover' }
|
|
@@ -2810,6 +2812,7 @@ export type ServerFrame =
|
|
|
2810
2812
|
t: 'conversation/view/opened';
|
|
2811
2813
|
requestId: string;
|
|
2812
2814
|
conversationKey: string;
|
|
2815
|
+
session?: SessionSummary;
|
|
2813
2816
|
historyRevision: string;
|
|
2814
2817
|
messages: Message[];
|
|
2815
2818
|
deliveries?: ConversationDelivery[];
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
/**
|
|
3
|
-
* ============================================================
|
|
4
|
-
* src/cli/wizards/advisorWizard.tsx —— 顾问模型子向导
|
|
5
|
-
* ------------------------------------------------------------
|
|
6
|
-
* v4 模型列表 schema 下,顾问不再自带一整套独立凭据——默认从已配置的模型列表
|
|
7
|
-
* 选一个复用。但顾问常常需要一个跟基座完全不同的 provider(对比不同模型的
|
|
8
|
-
* 第二意见才有意义),而 CLI 的「配置基座模型」向导只管理基座这一个槽位、
|
|
9
|
-
* 没有别的入口能新增模型——所以这里的模型选择字段里多一项「+ 新建模型」,
|
|
10
|
-
* 选它会先走一小段收集新模型字段的表单,新建成功后再回落到常规的顾问行为
|
|
11
|
-
* 字段(启用/调用模式/预算/超时/敏感共享)。三阶段状态机,全部落盘只发生在
|
|
12
|
-
* 最后一步提交时(ESC 在任何阶段取消都不留半成品模型)。
|
|
13
|
-
* ============================================================
|
|
14
|
-
*/
|
|
15
|
-
import { useState } from 'react';
|
|
16
|
-
import { configService } from '../../config/configService.js';
|
|
17
|
-
import { DEFAULT_ADVISOR_CONFIG } from '../../config/configDefaults.js';
|
|
18
|
-
import { CONFIG_LIMITS, normalizeLimited } from '../../config/numericLimits.js';
|
|
19
|
-
import { FieldForm } from './fieldForm.js';
|
|
20
|
-
const NEW_MODEL_OPTION = '+ 新建模型(作为顾问专用,可与基座用不同 provider)';
|
|
21
|
-
function parsePositiveInt(value, fallback) {
|
|
22
|
-
const parsed = Number.parseInt(String(value ?? ''), 10);
|
|
23
|
-
return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;
|
|
24
|
-
}
|
|
25
|
-
export function AdvisorWizard({ existing, models, onDone, onCancel }) {
|
|
26
|
-
const enabledModels = models.filter((m) => m.enabled);
|
|
27
|
-
const labelFor = (m, index) => `${index + 1}. ${m.displayName || m.model}`;
|
|
28
|
-
const existingOptions = enabledModels.map(labelFor);
|
|
29
|
-
const labelToId = new Map(enabledModels.map((m, i) => [labelFor(m, i), m.id]));
|
|
30
|
-
const currentLabel = (() => {
|
|
31
|
-
const index = enabledModels.findIndex((m) => m.id === existing?.modelId);
|
|
32
|
-
return index >= 0 ? labelFor(enabledModels[index], index) : undefined;
|
|
33
|
-
})();
|
|
34
|
-
const [phase, setPhase] = useState('model-choice');
|
|
35
|
-
const [chosenModelId, setChosenModelId] = useState(null);
|
|
36
|
-
const [newModelDraft, setNewModelDraft] = useState(null);
|
|
37
|
-
if (phase === 'model-choice') {
|
|
38
|
-
return (_jsx(FieldForm, { title: "\u914D\u7F6E\u987E\u95EE\u6A21\u578B\uFF08Advisor \u5DE5\u5177\uFF09", fields: [
|
|
39
|
-
{
|
|
40
|
-
key: 'modelLabel',
|
|
41
|
-
label: '使用哪个模型',
|
|
42
|
-
type: 'select',
|
|
43
|
-
options: [...existingOptions, NEW_MODEL_OPTION],
|
|
44
|
-
default: currentLabel ?? (existingOptions[0] ?? NEW_MODEL_OPTION),
|
|
45
|
-
hint: enabledModels.length === 0
|
|
46
|
-
? '还没有已配置的模型,只能新建'
|
|
47
|
-
: '可以直接复用基座模型,也可以新建一个专属 provider',
|
|
48
|
-
},
|
|
49
|
-
], onSubmit: async (values) => {
|
|
50
|
-
const label = String(values.modelLabel ?? '');
|
|
51
|
-
if (label === NEW_MODEL_OPTION) {
|
|
52
|
-
setPhase('new-model');
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
const id = labelToId.get(label);
|
|
56
|
-
if (!id)
|
|
57
|
-
throw new Error('请选择一个模型');
|
|
58
|
-
setChosenModelId(id);
|
|
59
|
-
setPhase('advisor-fields');
|
|
60
|
-
}, onCancel: onCancel }));
|
|
61
|
-
}
|
|
62
|
-
if (phase === 'new-model') {
|
|
63
|
-
return (_jsx(FieldForm, { title: "\u65B0\u5EFA\u987E\u95EE\u4E13\u7528\u6A21\u578B\uFF08\u56FA\u5B9A OpenAI \u517C\u5BB9\u683C\u5F0F\uFF1BAnthropic \u683C\u5F0F\u8BF7\u7528 Desktop \u6DFB\u52A0\uFF09", fields: [
|
|
64
|
-
{ key: 'baseURL', label: 'API 完整端点地址(含 /chat/completions 后缀)', type: 'text', default: '' },
|
|
65
|
-
{ key: 'apiKey', label: 'API Key', type: 'password', default: '' },
|
|
66
|
-
{ key: 'model', label: 'Model', type: 'text', default: '' },
|
|
67
|
-
{ key: 'contextWindow', label: 'Context Window(token 数)', type: 'text', default: '1000000', optional: true },
|
|
68
|
-
], onSubmit: async (values) => {
|
|
69
|
-
const baseURL = String(values.baseURL ?? '').trim();
|
|
70
|
-
const apiKey = String(values.apiKey ?? '').trim();
|
|
71
|
-
const model = String(values.model ?? '').trim();
|
|
72
|
-
if (!baseURL || !apiKey || !model)
|
|
73
|
-
throw new Error('Base URL / API Key / Model 均不能为空');
|
|
74
|
-
setNewModelDraft({
|
|
75
|
-
baseURL,
|
|
76
|
-
apiKey,
|
|
77
|
-
model,
|
|
78
|
-
contextWindow: parsePositiveInt(values.contextWindow, 1_000_000),
|
|
79
|
-
supportsVision: true,
|
|
80
|
-
});
|
|
81
|
-
setPhase('advisor-fields');
|
|
82
|
-
}, onCancel: onCancel }));
|
|
83
|
-
}
|
|
84
|
-
// phase === 'advisor-fields'
|
|
85
|
-
return (_jsx(FieldForm, { title: "\u914D\u7F6E\u987E\u95EE\u6A21\u578B \u00B7 \u884C\u4E3A\u8BBE\u7F6E", fields: [
|
|
86
|
-
{ key: 'enabled', label: '是否启用', type: 'boolean', default: existing?.enabled ?? true },
|
|
87
|
-
{
|
|
88
|
-
key: 'mode',
|
|
89
|
-
label: '调用模式',
|
|
90
|
-
type: 'select',
|
|
91
|
-
options: ['auto', 'manual'],
|
|
92
|
-
default: existing?.mode ?? 'auto',
|
|
93
|
-
hint: 'auto=主循环自主判断时机调用 · manual=仅 /advisor ask 手动触发',
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
key: 'enforcement',
|
|
97
|
-
label: '补问方式',
|
|
98
|
-
type: 'select',
|
|
99
|
-
options: ['remind', 'followup'],
|
|
100
|
-
default: existing?.enforcement ?? 'remind',
|
|
101
|
-
hint: 'remind=只提醒 · followup=实质回答未复核时再发一次请求,让模型自己补问顾问(弱基座模型用)',
|
|
102
|
-
},
|
|
103
|
-
{
|
|
104
|
-
key: 'timeoutSeconds',
|
|
105
|
-
label: '最长等待(秒)',
|
|
106
|
-
type: 'text',
|
|
107
|
-
default: String(Math.round((existing?.timeoutMs ?? DEFAULT_ADVISOR_CONFIG.timeoutMs) / 1000)),
|
|
108
|
-
optional: true,
|
|
109
|
-
},
|
|
110
|
-
], onSubmit: async (values) => {
|
|
111
|
-
// 只在这最后一步才真正落盘——ESC 在任何前置阶段取消都不留半成品模型。
|
|
112
|
-
// newModelDraft 在 add 成功后立即清空 + 把新 id 记入 chosenModelId:若紧接着
|
|
113
|
-
// 的顾问 patch 失败,FieldForm 在同一 phase 内回到第 1 项重试会重新调这个
|
|
114
|
-
// onSubmit,若不清空 newModelDraft 会重新执行一次 add,产生重复模型。
|
|
115
|
-
let modelId = chosenModelId;
|
|
116
|
-
if (!modelId && newModelDraft) {
|
|
117
|
-
const beforeIds = new Set(models.map((m) => m.id));
|
|
118
|
-
const saved = await configService.savePatch({
|
|
119
|
-
models: [{
|
|
120
|
-
op: 'add',
|
|
121
|
-
model: {
|
|
122
|
-
apiFormat: 'openai',
|
|
123
|
-
baseURL: newModelDraft.baseURL,
|
|
124
|
-
apiKey: newModelDraft.apiKey,
|
|
125
|
-
model: newModelDraft.model,
|
|
126
|
-
contextWindow: newModelDraft.contextWindow,
|
|
127
|
-
supportsVision: newModelDraft.supportsVision,
|
|
128
|
-
promptCache: { mode: 'auto' },
|
|
129
|
-
enabled: true,
|
|
130
|
-
},
|
|
131
|
-
}],
|
|
132
|
-
});
|
|
133
|
-
modelId = saved.config?.models.find((m) => !beforeIds.has(m.id))?.id ?? null;
|
|
134
|
-
if (modelId) {
|
|
135
|
-
setChosenModelId(modelId);
|
|
136
|
-
setNewModelDraft(null);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
if (!modelId)
|
|
140
|
-
throw new Error('未能确定要使用的模型');
|
|
141
|
-
await configService.savePatch({
|
|
142
|
-
advisor: {
|
|
143
|
-
enabled: values.enabled,
|
|
144
|
-
mode: values.mode === 'manual' ? 'manual' : 'auto',
|
|
145
|
-
enforcement: values.enforcement === 'followup' ? 'followup' : 'remind',
|
|
146
|
-
modelId,
|
|
147
|
-
timeoutMs: normalizeLimited(parsePositiveInt(values.timeoutSeconds, DEFAULT_ADVISOR_CONFIG.timeoutMs / 1000) * 1000, CONFIG_LIMITS.advisorTimeoutMs, DEFAULT_ADVISOR_CONFIG.timeoutMs),
|
|
148
|
-
},
|
|
149
|
-
});
|
|
150
|
-
onDone();
|
|
151
|
-
}, onCancel: onCancel }));
|
|
152
|
-
}
|