dsh-client-auto-continue 0.19.0 → 0.20.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 +13 -0
- package/README.md +3 -3
- package/README.ru.md +3 -3
- package/README.zh.md +3 -3
- package/docs/releases/v0.20.0.md +46 -0
- package/lib/client.js +3 -3
- package/lib/client.js.map +2 -2
- package/lib/index.js +240 -2
- package/lib/types/host/engine.d.ts +41 -0
- package/lib/types/shared/core.d.ts +6 -0
- package/package.json +1 -1
- package/src/client/locales.ts +3 -3
- package/src/host/engine.ts +290 -2
- package/src/index.ts +11 -0
- package/src/shared/core.ts +6 -0
package/lib/index.js
CHANGED
|
@@ -20,6 +20,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
import z2 from "@deepseek-ai/schemastery";
|
|
22
22
|
|
|
23
|
+
// src/host/engine.ts
|
|
24
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
25
|
+
|
|
23
26
|
// node_modules/@deepseek-ai/dsh-llm/lib/index.js
|
|
24
27
|
import { createRequire } from "node:module";
|
|
25
28
|
|
|
@@ -1785,6 +1788,13 @@ var RESTART_CANCEL_CAUSES = /* @__PURE__ */ new Set(["disposed", "legacy"]);
|
|
|
1785
1788
|
var DECISION_CANCEL_CAUSES = /* @__PURE__ */ new Set(["user", "parent", "hook"]);
|
|
1786
1789
|
var CHILD_SWEEP_LIMIT = 8;
|
|
1787
1790
|
var CHILD_ROOT_MAX_DEPTH = 8;
|
|
1791
|
+
var HANDOFF_COOLDOWN_MS = 5 * 60 * 1e3;
|
|
1792
|
+
var REVIVE_TIMEOUT_MS = 15e3;
|
|
1793
|
+
var HANDOFF_COPY = {
|
|
1794
|
+
zh: (child, code) => `子代理会话 ${child} 因 ${code} 中断, 已无法直接续跑。请检查它的状态, 然后继续或收尾。`,
|
|
1795
|
+
en: (child, code) => `Child session ${child} was interrupted by ${code} and can no longer be resumed directly. Check its state, then continue it or wrap it up.`,
|
|
1796
|
+
ru: (child, code) => `Дочерняя сессия ${child} прервалась из-за ${code} и больше не может быть продолжена напрямую. Проверь её состояние и продолжи или заверши.`
|
|
1797
|
+
};
|
|
1788
1798
|
var GOALS_SERVICE_KEY = "goals";
|
|
1789
1799
|
var CHILD_CAUSE_COPY = {
|
|
1790
1800
|
zh: {
|
|
@@ -1946,6 +1956,10 @@ var AutoContinueRunner = class {
|
|
|
1946
1956
|
this.noticeListeners = /* @__PURE__ */ new Set();
|
|
1947
1957
|
this.stateListeners = /* @__PURE__ */ new Set();
|
|
1948
1958
|
this.prioritizedFollowups = /* @__PURE__ */ new Set();
|
|
1959
|
+
/** In-flight cold-resume calls, aborted when the plugin unloads. */
|
|
1960
|
+
this.reviveControllers = /* @__PURE__ */ new Set();
|
|
1961
|
+
/** Hand-offs waiting for a live main conversation: parent -> child -> text. */
|
|
1962
|
+
this.deferredHandoffs = /* @__PURE__ */ new Map();
|
|
1949
1963
|
this.disposed = false;
|
|
1950
1964
|
this.bootScannedSessions = /* @__PURE__ */ new WeakSet();
|
|
1951
1965
|
/** Also bound diagnostics when even an agent's session getter is unavailable. */
|
|
@@ -2112,6 +2126,9 @@ var AutoContinueRunner = class {
|
|
|
2112
2126
|
this.wakeBootScan = void 0;
|
|
2113
2127
|
this.disposeSessionEvents();
|
|
2114
2128
|
this.disposeInboxEvents();
|
|
2129
|
+
for (const controller of this.reviveControllers) controller.abort();
|
|
2130
|
+
this.reviveControllers.clear();
|
|
2131
|
+
this.deferredHandoffs.clear();
|
|
2115
2132
|
this.prioritizedFollowups.clear();
|
|
2116
2133
|
for (const state of this.states.values()) {
|
|
2117
2134
|
if (state.pendingTimer !== void 0) clearTimeout(state.pendingTimer);
|
|
@@ -2289,6 +2306,7 @@ var AutoContinueRunner = class {
|
|
|
2289
2306
|
*/
|
|
2290
2307
|
onHostEvent(session, event) {
|
|
2291
2308
|
const sessionId = session.id;
|
|
2309
|
+
this.flushDeferredHandoffs(sessionId);
|
|
2292
2310
|
const sessionState = this.states.get(sessionId);
|
|
2293
2311
|
if (session.header?.origin === "subagent") {
|
|
2294
2312
|
this.markSubagent(sessionId, sessionState ?? this.state(sessionId), session.header.parentSession);
|
|
@@ -2581,12 +2599,14 @@ var AutoContinueRunner = class {
|
|
|
2581
2599
|
if (this.sessionConfig(sessionId).resumeCompletedTurns) {
|
|
2582
2600
|
if (turnOutput === "visible") {
|
|
2583
2601
|
state.consecutive = 0;
|
|
2602
|
+
state.recovering = false;
|
|
2584
2603
|
state.lastFailure = void 0;
|
|
2585
2604
|
this.noteRecovery(sessionId, "completed");
|
|
2586
2605
|
}
|
|
2587
2606
|
this.schedule(sessionId, LOOP_COMPLETED_REASON, true);
|
|
2588
2607
|
} else if (turnOutput === "visible") {
|
|
2589
2608
|
state.consecutive = 0;
|
|
2609
|
+
state.recovering = false;
|
|
2590
2610
|
state.lastFailure = void 0;
|
|
2591
2611
|
this.noteRecovery(sessionId, "completed");
|
|
2592
2612
|
}
|
|
@@ -2621,6 +2641,7 @@ var AutoContinueRunner = class {
|
|
|
2621
2641
|
}
|
|
2622
2642
|
} else {
|
|
2623
2643
|
state.consecutive = 0;
|
|
2644
|
+
state.recovering = false;
|
|
2624
2645
|
state.pendingRecoveryAt = 0;
|
|
2625
2646
|
}
|
|
2626
2647
|
} else if (reasonKind === "blocked") {
|
|
@@ -2649,6 +2670,7 @@ var AutoContinueRunner = class {
|
|
|
2649
2670
|
if (isOurEcho(state, event)) break;
|
|
2650
2671
|
if (event.data.source.kind === "user") {
|
|
2651
2672
|
state.consecutive = 0;
|
|
2673
|
+
state.recovering = false;
|
|
2652
2674
|
this.resetLoopIterations(state);
|
|
2653
2675
|
this.cancelPending(sessionId, "用户手动发送消息");
|
|
2654
2676
|
}
|
|
@@ -2661,7 +2683,13 @@ var AutoContinueRunner = class {
|
|
|
2661
2683
|
onTurnFailure(sessionId, reason, failure) {
|
|
2662
2684
|
const config = this.getConfig();
|
|
2663
2685
|
if (this.isSubagentSession(sessionId)) {
|
|
2664
|
-
if (!this.subagentRecoveryEnabled(sessionId))
|
|
2686
|
+
if (!this.subagentRecoveryEnabled(sessionId)) {
|
|
2687
|
+
const parent = this.parentOf(sessionId);
|
|
2688
|
+
if (parent !== void 0 && parent !== "" && this.ctx.agents.get(parent) === void 0) {
|
|
2689
|
+
this.deferHandoff(parent, sessionId, this.handoffText(sessionId, reason));
|
|
2690
|
+
}
|
|
2691
|
+
return;
|
|
2692
|
+
}
|
|
2665
2693
|
} else if (sessionMode(config.sessionModes, sessionId) === "off") return;
|
|
2666
2694
|
if (config.classify && !isTransientFailure(failure, config.retryableErrorPatterns)) {
|
|
2667
2695
|
const copy = NOTICE_COPY[config.locale];
|
|
@@ -2806,6 +2834,7 @@ var AutoContinueRunner = class {
|
|
|
2806
2834
|
}, config.graceMs);
|
|
2807
2835
|
state.pendingTimer = timer;
|
|
2808
2836
|
state.pendingReason = reason;
|
|
2837
|
+
state.recovering = true;
|
|
2809
2838
|
const template = this.templateFor(config, reason);
|
|
2810
2839
|
this.log(
|
|
2811
2840
|
`检测到非人为中断 ${sessionId}(${reason}), ${config.graceMs}ms 后自动发送「${template}」`
|
|
@@ -2819,6 +2848,7 @@ var AutoContinueRunner = class {
|
|
|
2819
2848
|
const state = this.state(sessionId);
|
|
2820
2849
|
if (state.cooldownRetryTimer !== void 0) clearTimeout(state.cooldownRetryTimer);
|
|
2821
2850
|
state.pendingReason = reason;
|
|
2851
|
+
state.recovering = true;
|
|
2822
2852
|
state.cooldownRetryTimer = setTimeout(() => {
|
|
2823
2853
|
state.cooldownRetryTimer = void 0;
|
|
2824
2854
|
state.pendingReason = void 0;
|
|
@@ -2867,6 +2897,197 @@ var AutoContinueRunner = class {
|
|
|
2867
2897
|
}
|
|
2868
2898
|
if (cancelled) this.log(`取消 ${sessionId} 的自动继续(${why})`);
|
|
2869
2899
|
}
|
|
2900
|
+
/** Attach the loader-provided subagent service; it may load after this plugin. */
|
|
2901
|
+
setSubagentPromptProvider(provider) {
|
|
2902
|
+
this.subagentPromptProvider = provider;
|
|
2903
|
+
}
|
|
2904
|
+
subagentPrompts() {
|
|
2905
|
+
const provided = this.subagentPromptProvider?.();
|
|
2906
|
+
if (provided !== void 0 && provided !== null) return provided;
|
|
2907
|
+
try {
|
|
2908
|
+
return this.ctx.get("subagents");
|
|
2909
|
+
} catch {
|
|
2910
|
+
return void 0;
|
|
2911
|
+
}
|
|
2912
|
+
}
|
|
2913
|
+
/** Copy for one child hand-off, built once so a deferred delivery matches. */
|
|
2914
|
+
handoffText(sessionId, reason) {
|
|
2915
|
+
const code = this.state(sessionId).lastFailure?.code ?? reason;
|
|
2916
|
+
return HANDOFF_COPY[this.sessionConfig(sessionId).locale](sessionId, code);
|
|
2917
|
+
}
|
|
2918
|
+
/**
|
|
2919
|
+
* Revive a disposed child through the host's cold resume and deliver the
|
|
2920
|
+
* continuation to it. Falls back to the main-conversation hand-off when the
|
|
2921
|
+
* host cannot resume (no persistence, no live parent, not a direct child).
|
|
2922
|
+
* The child's own recovery mode decides; the parent only has to be alive to
|
|
2923
|
+
* authorize the call.
|
|
2924
|
+
*/
|
|
2925
|
+
async reviveChild(sessionId, reason, text, force) {
|
|
2926
|
+
if (this.disposed || this.getConfig().paused) return;
|
|
2927
|
+
if (!this.subagentRecoveryEnabled(sessionId)) return;
|
|
2928
|
+
const state = this.state(sessionId);
|
|
2929
|
+
if (state.reviveInFlight === true) {
|
|
2930
|
+
this.log(`冷恢复跳过 ${sessionId}: 已有请求在途中`);
|
|
2931
|
+
return;
|
|
2932
|
+
}
|
|
2933
|
+
const config = this.sessionConfig(sessionId);
|
|
2934
|
+
if (!force) {
|
|
2935
|
+
if (Date.now() - state.lastAttemptAt < this.cooldownFor(state)) {
|
|
2936
|
+
this.log(`冷恢复跳过 ${sessionId}: 处于冷却期`);
|
|
2937
|
+
return;
|
|
2938
|
+
}
|
|
2939
|
+
if (state.consecutive >= config.maxConsecutive) {
|
|
2940
|
+
this.log(`冷恢复跳过 ${sessionId}: 已连续自动继续 ${state.consecutive} 次`);
|
|
2941
|
+
return;
|
|
2942
|
+
}
|
|
2943
|
+
}
|
|
2944
|
+
const parent = this.parentOf(sessionId);
|
|
2945
|
+
if (parent === void 0 || parent === "") return;
|
|
2946
|
+
const handoff = this.handoffText(sessionId, reason);
|
|
2947
|
+
const parentAgent = this.ctx.agents.get(parent);
|
|
2948
|
+
if (parentAgent === void 0) {
|
|
2949
|
+
this.deferHandoff(parent, sessionId, handoff);
|
|
2950
|
+
return;
|
|
2951
|
+
}
|
|
2952
|
+
const prompts = this.subagentPrompts();
|
|
2953
|
+
if (typeof prompts?.prompt !== "function") {
|
|
2954
|
+
this.handOffToParent(sessionId, reason, handoff);
|
|
2955
|
+
return;
|
|
2956
|
+
}
|
|
2957
|
+
state.lastAttemptAt = Date.now();
|
|
2958
|
+
state.consecutive += 1;
|
|
2959
|
+
state.reviveInFlight = true;
|
|
2960
|
+
const controller = new AbortController();
|
|
2961
|
+
this.reviveControllers.add(controller);
|
|
2962
|
+
let timedOut = false;
|
|
2963
|
+
const timeout = setTimeout(() => {
|
|
2964
|
+
timedOut = true;
|
|
2965
|
+
controller.abort();
|
|
2966
|
+
}, REVIVE_TIMEOUT_MS);
|
|
2967
|
+
try {
|
|
2968
|
+
await prompts.prompt(
|
|
2969
|
+
{
|
|
2970
|
+
parentSessionId: parent,
|
|
2971
|
+
childSessionId: sessionId,
|
|
2972
|
+
mode: "continuable",
|
|
2973
|
+
requestId: randomUUID2(),
|
|
2974
|
+
content: [{ type: "text", text }],
|
|
2975
|
+
delivery: "queue"
|
|
2976
|
+
},
|
|
2977
|
+
controller.signal
|
|
2978
|
+
);
|
|
2979
|
+
this.log(`已冷恢复子代理 ${sessionId}`);
|
|
2980
|
+
} catch (error) {
|
|
2981
|
+
if (this.disposed) return;
|
|
2982
|
+
this.log(`冷恢复 ${sessionId} 失败${timedOut ? "(超时)" : ""}: ${error instanceof Error ? error.message : String(error)}`);
|
|
2983
|
+
this.handOffToParent(sessionId, reason, handoff);
|
|
2984
|
+
} finally {
|
|
2985
|
+
clearTimeout(timeout);
|
|
2986
|
+
this.reviveControllers.delete(controller);
|
|
2987
|
+
state.reviveInFlight = false;
|
|
2988
|
+
}
|
|
2989
|
+
}
|
|
2990
|
+
/** Existing state of a session, without materializing one just to read it. */
|
|
2991
|
+
parentState(sessionId) {
|
|
2992
|
+
return this.states.get(sessionId);
|
|
2993
|
+
}
|
|
2994
|
+
/** Whether this session already has a continuation on the way. */
|
|
2995
|
+
hasPendingSend(state) {
|
|
2996
|
+
return state.pendingTimer !== void 0 || state.cooldownRetryTimer !== void 0 || state.loopRetryTimer !== void 0 || state.offlineWait !== void 0 || state.offlineTimer !== void 0;
|
|
2997
|
+
}
|
|
2998
|
+
/**
|
|
2999
|
+
* Ask the child's main conversation to take over a failure the plugin cannot
|
|
3000
|
+
* repair itself: the child handle is gone, so only the root can continue it.
|
|
3001
|
+
* The main conversation's Off is respected because this writes a user message
|
|
3002
|
+
* into it; a child's own mode is never overridden by that Off for cold resume.
|
|
3003
|
+
*/
|
|
3004
|
+
handOffToParent(sessionId, reason, text) {
|
|
3005
|
+
if (this.disposed || this.getConfig().paused) return;
|
|
3006
|
+
if (!this.subagentRecoveryEnabled(sessionId)) return;
|
|
3007
|
+
const parent = this.parentOf(sessionId);
|
|
3008
|
+
if (parent === void 0 || parent === "") return;
|
|
3009
|
+
if (this.explicitMode(parent) === "off") return;
|
|
3010
|
+
const state = this.state(sessionId);
|
|
3011
|
+
const now = Date.now();
|
|
3012
|
+
if (state.handedOffAt !== void 0 && now - state.handedOffAt < HANDOFF_COOLDOWN_MS) return;
|
|
3013
|
+
const handoff = text ?? this.handoffText(sessionId, reason);
|
|
3014
|
+
const parentAgent = this.ctx.agents.get(parent);
|
|
3015
|
+
if (parentAgent === void 0) {
|
|
3016
|
+
this.deferHandoff(parent, sessionId, handoff);
|
|
3017
|
+
return;
|
|
3018
|
+
}
|
|
3019
|
+
const parentState = this.parentState(parent);
|
|
3020
|
+
if (parentState !== void 0 && (parentState.recovering === true || this.hasPendingSend(parentState))) {
|
|
3021
|
+
this.log(`移交跳过 ${sessionId}: 主会话 ${parent} 正在自行恢复`);
|
|
3022
|
+
return;
|
|
3023
|
+
}
|
|
3024
|
+
try {
|
|
3025
|
+
this.sendHandoff(parent, parentAgent, handoff);
|
|
3026
|
+
state.handedOffAt = now;
|
|
3027
|
+
this.log(`已将子代理 ${sessionId} 的失败移交主会话 ${parent}`);
|
|
3028
|
+
} catch (error) {
|
|
3029
|
+
this.log(`移交 ${sessionId} 失败: ${error instanceof Error ? error.message : String(error)}`);
|
|
3030
|
+
}
|
|
3031
|
+
}
|
|
3032
|
+
/**
|
|
3033
|
+
* Post a hand-off into the main conversation the same way a continuation is
|
|
3034
|
+
* sent: with the configured message source, and registered as our own echo so
|
|
3035
|
+
* the parent does not read it as the user stepping in (which would reset its
|
|
3036
|
+
* retry and loop counters and cancel whatever it had queued).
|
|
3037
|
+
*/
|
|
3038
|
+
sendHandoff(parent, parentAgent, text) {
|
|
3039
|
+
const parentState = this.state(parent);
|
|
3040
|
+
const message = createUserMessage({
|
|
3041
|
+
content: [{ type: "text", text }],
|
|
3042
|
+
source: { kind: this.getConfig().usePluginSource ? AUTO_CONTINUE_SOURCE_KIND : "user" }
|
|
3043
|
+
});
|
|
3044
|
+
trackPendingEcho(parentState, message.id);
|
|
3045
|
+
try {
|
|
3046
|
+
parentAgent.followup(message);
|
|
3047
|
+
} catch (error) {
|
|
3048
|
+
forgetPendingEcho(parentState, message.id);
|
|
3049
|
+
throw error;
|
|
3050
|
+
}
|
|
3051
|
+
}
|
|
3052
|
+
/** Keep one hand-off until its main conversation has a live agent again. */
|
|
3053
|
+
deferHandoff(parent, sessionId, text) {
|
|
3054
|
+
if (!this.getConfig().resumeSubagentSessions) return;
|
|
3055
|
+
const state = this.state(sessionId);
|
|
3056
|
+
const now = Date.now();
|
|
3057
|
+
if (state.handedOffAt !== void 0 && now - state.handedOffAt < HANDOFF_COOLDOWN_MS) return;
|
|
3058
|
+
let pending = this.deferredHandoffs.get(parent);
|
|
3059
|
+
if (pending === void 0) {
|
|
3060
|
+
pending = /* @__PURE__ */ new Map();
|
|
3061
|
+
this.deferredHandoffs.set(parent, pending);
|
|
3062
|
+
}
|
|
3063
|
+
pending.set(sessionId, text);
|
|
3064
|
+
this.log(`移交暂存 ${sessionId}: 主会话 ${parent} 无 live agent`);
|
|
3065
|
+
}
|
|
3066
|
+
/** Deliver queued hand-offs once their main conversation is live again. */
|
|
3067
|
+
flushDeferredHandoffs(parent) {
|
|
3068
|
+
const pending = this.deferredHandoffs.get(parent);
|
|
3069
|
+
if (pending === void 0 || pending.size === 0) return;
|
|
3070
|
+
if (this.explicitMode(parent) === "off") {
|
|
3071
|
+
this.deferredHandoffs.delete(parent);
|
|
3072
|
+
return;
|
|
3073
|
+
}
|
|
3074
|
+
const parentAgent = this.ctx.agents.get(parent);
|
|
3075
|
+
if (parentAgent === void 0) return;
|
|
3076
|
+
this.deferredHandoffs.delete(parent);
|
|
3077
|
+
const now = Date.now();
|
|
3078
|
+
for (const [child, text] of pending) {
|
|
3079
|
+
if (!this.subagentRecoveryEnabled(child)) continue;
|
|
3080
|
+
const state = this.state(child);
|
|
3081
|
+
if (state.handedOffAt !== void 0 && now - state.handedOffAt < HANDOFF_COOLDOWN_MS) continue;
|
|
3082
|
+
try {
|
|
3083
|
+
this.sendHandoff(parent, parentAgent, text);
|
|
3084
|
+
state.handedOffAt = now;
|
|
3085
|
+
this.log(`已移交暂存子代理 ${child} 给主会话 ${parent}`);
|
|
3086
|
+
} catch (error) {
|
|
3087
|
+
this.log(`暂存移交 ${child} 失败: ${error instanceof Error ? error.message : String(error)}`);
|
|
3088
|
+
}
|
|
3089
|
+
}
|
|
3090
|
+
}
|
|
2870
3091
|
fire(sessionId, reason, force = false) {
|
|
2871
3092
|
if (this.disposed) return;
|
|
2872
3093
|
const state = this.state(sessionId);
|
|
@@ -2874,7 +3095,13 @@ var AutoContinueRunner = class {
|
|
|
2874
3095
|
const manualResume = force && reason === MANUAL_NOTIFICATION_REASON;
|
|
2875
3096
|
if (reason.endsWith(":silent") && !config.resumeSilentTurns) return;
|
|
2876
3097
|
if (isLoopReason(reason) && !config.resumeCompletedTurns) return;
|
|
2877
|
-
if (this.isSubagentSession(sessionId) && !this.subagentRecoveryEnabled(sessionId))
|
|
3098
|
+
if (this.isSubagentSession(sessionId) && !this.subagentRecoveryEnabled(sessionId)) {
|
|
3099
|
+
const parent = this.parentOf(sessionId);
|
|
3100
|
+
if (parent !== void 0 && parent !== "" && this.ctx.agents.get(parent) === void 0) {
|
|
3101
|
+
this.deferHandoff(parent, sessionId, this.handoffText(sessionId, reason));
|
|
3102
|
+
}
|
|
3103
|
+
return;
|
|
3104
|
+
}
|
|
2878
3105
|
if (config.paused && !manualResume) {
|
|
2879
3106
|
this.log(`跳过 ${sessionId}(${reason}): 自动继续已暂停`);
|
|
2880
3107
|
return;
|
|
@@ -2895,6 +3122,9 @@ var AutoContinueRunner = class {
|
|
|
2895
3122
|
const text = this.buildContinueText(config, state, template);
|
|
2896
3123
|
const agent = this.ctx.agents.get(sessionId);
|
|
2897
3124
|
if (agent === void 0) {
|
|
3125
|
+
if (this.isSubagentSession(sessionId) && this.subagentRecoveryEnabled(sessionId)) {
|
|
3126
|
+
void this.reviveChild(sessionId, reason, text, manualResume);
|
|
3127
|
+
}
|
|
2898
3128
|
this.log(`跳过 ${sessionId}(${reason}): 无 live agent`);
|
|
2899
3129
|
return;
|
|
2900
3130
|
}
|
|
@@ -2915,6 +3145,7 @@ var AutoContinueRunner = class {
|
|
|
2915
3145
|
this.prioritizedFollowups.delete(message.id);
|
|
2916
3146
|
}
|
|
2917
3147
|
const now = Date.now();
|
|
3148
|
+
state.recovering = true;
|
|
2918
3149
|
this.rearmGoal(sessionId, config);
|
|
2919
3150
|
if (reason !== LOOP_COMPLETED_REASON) state.consecutive += 1;
|
|
2920
3151
|
if (isLoopReason(reason)) state.loopIterations += 1;
|
|
@@ -3004,6 +3235,7 @@ var AutoContinueRunner = class {
|
|
|
3004
3235
|
const token = {};
|
|
3005
3236
|
state.offlineWait = token;
|
|
3006
3237
|
state.pendingReason = reason;
|
|
3238
|
+
state.recovering = true;
|
|
3007
3239
|
void this.checkConnectivity().then((online) => {
|
|
3008
3240
|
if (this.disposed || state.offlineWait !== token) return;
|
|
3009
3241
|
if (online) {
|
|
@@ -10096,6 +10328,12 @@ function apply(ctx, config) {
|
|
|
10096
10328
|
disposeEngine?.();
|
|
10097
10329
|
const readConfig = () => resolveConfig(legacyConfig?.() ?? readEntry());
|
|
10098
10330
|
const runner = new AutoContinueRunner(engineCtx, readConfig);
|
|
10331
|
+
engineCtx.inject(["subagents"], (subagentCtx) => {
|
|
10332
|
+
runner.setSubagentPromptProvider(
|
|
10333
|
+
() => subagentCtx.subagents
|
|
10334
|
+
);
|
|
10335
|
+
subagentCtx.effect(() => () => runner.setSubagentPromptProvider(void 0));
|
|
10336
|
+
});
|
|
10099
10337
|
const writableSettings = () => {
|
|
10100
10338
|
const settings = engineCtx.get("settings");
|
|
10101
10339
|
return settings?.writable && typeof settings.mutate === "function" ? settings : void 0;
|
|
@@ -44,6 +44,10 @@ export declare class AutoContinueRunner {
|
|
|
44
44
|
private readonly noticeListeners;
|
|
45
45
|
private readonly stateListeners;
|
|
46
46
|
private readonly prioritizedFollowups;
|
|
47
|
+
/** In-flight cold-resume calls, aborted when the plugin unloads. */
|
|
48
|
+
private readonly reviveControllers;
|
|
49
|
+
/** Hand-offs waiting for a live main conversation: parent -> child -> text. */
|
|
50
|
+
private readonly deferredHandoffs;
|
|
47
51
|
private readonly disposeSessionEvents;
|
|
48
52
|
private readonly disposeInboxEvents;
|
|
49
53
|
private disposed;
|
|
@@ -191,6 +195,43 @@ export declare class AutoContinueRunner {
|
|
|
191
195
|
/** 按调度原因选择续跑模板: loop 重启、无输出回合、max-tokens、自主循环, 其余用通用继续文本。 */
|
|
192
196
|
private templateFor;
|
|
193
197
|
private cancelPending;
|
|
198
|
+
/** Host-service facade used to cold-resume a disposed direct child. */
|
|
199
|
+
private subagentPromptProvider;
|
|
200
|
+
/** Attach the loader-provided subagent service; it may load after this plugin. */
|
|
201
|
+
setSubagentPromptProvider(provider: (() => unknown) | undefined): void;
|
|
202
|
+
private subagentPrompts;
|
|
203
|
+
/** Copy for one child hand-off, built once so a deferred delivery matches. */
|
|
204
|
+
private handoffText;
|
|
205
|
+
/**
|
|
206
|
+
* Revive a disposed child through the host's cold resume and deliver the
|
|
207
|
+
* continuation to it. Falls back to the main-conversation hand-off when the
|
|
208
|
+
* host cannot resume (no persistence, no live parent, not a direct child).
|
|
209
|
+
* The child's own recovery mode decides; the parent only has to be alive to
|
|
210
|
+
* authorize the call.
|
|
211
|
+
*/
|
|
212
|
+
private reviveChild;
|
|
213
|
+
/** Existing state of a session, without materializing one just to read it. */
|
|
214
|
+
private parentState;
|
|
215
|
+
/** Whether this session already has a continuation on the way. */
|
|
216
|
+
private hasPendingSend;
|
|
217
|
+
/**
|
|
218
|
+
* Ask the child's main conversation to take over a failure the plugin cannot
|
|
219
|
+
* repair itself: the child handle is gone, so only the root can continue it.
|
|
220
|
+
* The main conversation's Off is respected because this writes a user message
|
|
221
|
+
* into it; a child's own mode is never overridden by that Off for cold resume.
|
|
222
|
+
*/
|
|
223
|
+
private handOffToParent;
|
|
224
|
+
/**
|
|
225
|
+
* Post a hand-off into the main conversation the same way a continuation is
|
|
226
|
+
* sent: with the configured message source, and registered as our own echo so
|
|
227
|
+
* the parent does not read it as the user stepping in (which would reset its
|
|
228
|
+
* retry and loop counters and cancel whatever it had queued).
|
|
229
|
+
*/
|
|
230
|
+
private sendHandoff;
|
|
231
|
+
/** Keep one hand-off until its main conversation has a live agent again. */
|
|
232
|
+
private deferHandoff;
|
|
233
|
+
/** Deliver queued hand-offs once their main conversation is live again. */
|
|
234
|
+
private flushDeferredHandoffs;
|
|
194
235
|
private fire;
|
|
195
236
|
private resetLoopIterations;
|
|
196
237
|
/** 自主循环轮数上限: 触顶后静默停下, 每次触顶只提示一次。 */
|
|
@@ -362,6 +362,12 @@ export interface SessionState {
|
|
|
362
362
|
lastFailure: FailureFacts | undefined;
|
|
363
363
|
/** 最近一次失败的发生时间(模板 {elapsed} 与恢复统计用)。 */
|
|
364
364
|
lastFailureAt: number;
|
|
365
|
+
/** 最近一次把子代理失败移交主会话的时间戳(去重)。 */
|
|
366
|
+
handedOffAt?: number;
|
|
367
|
+
/** 冷恢复请求正在途中(去重, 防止重复 prompt)。 */
|
|
368
|
+
reviveInFlight?: boolean;
|
|
369
|
+
/** 主会话正在自行恢复: 由插件自己的调度/发送显式维护, 不用时间戳猜测。 */
|
|
370
|
+
recovering?: boolean;
|
|
365
371
|
/** callId 精确配对的工具调用、幂等护栏与 loop 重复态。 */
|
|
366
372
|
tools: ToolInvocationTracker;
|
|
367
373
|
/** 失败回合的编号(模板 {turn})。 */
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-client-auto-continue",
|
|
3
3
|
"description": "Automatically resume interrupted DSH conversations, with an optional autonomous loop.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.20.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"types": "lib/types/index.d.ts",
|
package/src/client/locales.ts
CHANGED
|
@@ -58,7 +58,7 @@ export const zh = {
|
|
|
58
58
|
'field.resumeSilentTurns': '续跑无输出回合',
|
|
59
59
|
'field.resumeSilentTurnsHint': '已观察到模型活动但没有可见输出时续跑;不把空回合、图片或扩展内容误判为静默,冷却与连续上限照常生效。',
|
|
60
60
|
'field.resumeSubagentSessions': '续跑子代理会话',
|
|
61
|
-
'field.resumeSubagentSessionsHint': '
|
|
61
|
+
'field.resumeSubagentSessionsHint': '当子代理所属主会话启用自动继续时,自动续跑其中断的子代理会话。子代理不会进入自主循环、不会被循环守卫重启,也不会由启动扫描恢复。默认关闭。DSH 已释放子代理时,引擎会通过宿主的子代理服务从持久化会话冷恢复它;宿主无法恢复时,把失败交给主会话处理,并在主会话自行恢复期间保持安静。',
|
|
62
62
|
'field.resumeCompletedTurns': '默认会话模式',
|
|
63
63
|
'field.resumeCompletedTurnsHint': '用于未单独设置模式的会话。仅故障恢复继续中断和无输出回合;自主循环还会在正常完成后继续。无输出和失败回合仍计入连续重试次数。',
|
|
64
64
|
'field.resumeInterruptedChildren': '重启后唤醒子代理会话',
|
|
@@ -230,7 +230,7 @@ export const en: Record<SettingsCardKey, string> = {
|
|
|
230
230
|
'field.resumeSilentTurns': 'Resume silent turns',
|
|
231
231
|
'field.resumeSilentTurnsHint': 'Resume observed model activity without visible output. No-op turns, images and extension blocks are not treated as silent; cooldown and retry limits still apply.',
|
|
232
232
|
'field.resumeSubagentSessions': 'Resume subagent sessions',
|
|
233
|
-
'field.resumeSubagentSessionsHint': 'Auto-continue interrupted subagent sessions when their main conversation has auto-continue enabled. Subagents never start the autonomous loop, are never loop-guard restarted, and are not recovered by the startup scan. Off by default.
|
|
233
|
+
'field.resumeSubagentSessionsHint': 'Auto-continue interrupted subagent sessions when their main conversation has auto-continue enabled. Subagents never start the autonomous loop, are never loop-guard restarted, and are not recovered by the startup scan. Off by default. When DSH already disposed the subagent, the engine cold-resumes it from its persisted session through the host subagent service; if the host cannot resume it, the failure is handed to the main conversation, staying silent while that conversation recovers itself.',
|
|
234
234
|
'field.resumeCompletedTurns': 'Default session mode',
|
|
235
235
|
'field.resumeCompletedTurnsHint': 'Applies to sessions without their own mode. Recovery only resumes interruptions and silent turns; autonomous loop also continues after normal completions. Silent and failed turns still count toward the consecutive retry limit.',
|
|
236
236
|
'field.resumeInterruptedChildren': 'Wake child sessions after restart',
|
|
@@ -397,7 +397,7 @@ export const ru: Record<SettingsCardKey, string> = {
|
|
|
397
397
|
'field.resumeSilentTurns': 'Продолжать ходы без вывода',
|
|
398
398
|
'field.resumeSilentTurnsHint': 'Продолжать при наблюдаемой активности модели без видимого вывода. Пустые ходы, изображения и блоки расширений тихими не считаются; задержка и лимиты повторов действуют.',
|
|
399
399
|
'field.resumeSubagentSessions': 'Продолжать сессии субагентов',
|
|
400
|
-
'field.resumeSubagentSessionsHint': 'Автоматически продолжать прерванные сессии субагентов, если в их основном диалоге включено авто-продолжение. Субагенты не запускают автономный цикл, не перезапускаются защитой от циклов и не восстанавливаются сканированием при запуске. По умолчанию выключено.
|
|
400
|
+
'field.resumeSubagentSessionsHint': 'Автоматически продолжать прерванные сессии субагентов, если в их основном диалоге включено авто-продолжение. Субагенты не запускают автономный цикл, не перезапускаются защитой от циклов и не восстанавливаются сканированием при запуске. По умолчанию выключено. Если DSH уже освободил субагент, движок холодно поднимает его из сохранённой сессии через сервис субагентов хоста; когда хост не может его поднять, сбой передаётся основному диалогу, и пока тот восстанавливается сам, передача молчит.',
|
|
401
401
|
'field.resumeCompletedTurns': 'Режим сессии по умолчанию',
|
|
402
402
|
'field.resumeCompletedTurnsHint': 'Для сессий без собственного режима. «Только восстановление» не трогает обычные завершения; «Автономный цикл» продолжает после них. Тихие и неудачные ходы по-прежнему расходуют бюджет повторов.',
|
|
403
403
|
'field.continueTextLoop': 'Текст продолжения (автономный цикл)',
|