dsh-client-auto-continue 0.17.0 → 0.17.1-rc.1
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 +17 -0
- package/docs/releases/v0.17.1-rc.1.md +55 -0
- package/lib/client.js.map +2 -2
- package/lib/index.js +25 -10
- package/lib/types/shared/core.d.ts +2 -0
- package/package.json +2 -2
- package/src/host/engine.ts +29 -6
- package/src/shared/core.ts +4 -1
package/lib/index.js
CHANGED
|
@@ -1236,7 +1236,7 @@ function isTransientFailure(failure, retryableErrorPatterns = "") {
|
|
|
1236
1236
|
if (explicitlyRetryable) return true;
|
|
1237
1237
|
const status = failure.status;
|
|
1238
1238
|
if (status !== void 0 && (status === 401 || status === 403)) return false;
|
|
1239
|
-
const permanent = /auth|unauthor|forbidden|credential|api[_-]?key|permission/i.test(haystack) || /insufficient.*(balance|quota)|billing|payment|quota.*exceeded.*(?!retry)/i.test(haystack) || /model.*not[_-]?found|unknown[_-]?model|model[_-]?not[_-]?found|not.*support.*model/i.test(haystack) || /context.*(length|limit|overflow|exceed)|token.*limit|max.*context/i.test(haystack) || /invalid[_-]?request|bad[_-]?request/i.test(haystack);
|
|
1239
|
+
const permanent = /auth|unauthor|forbidden|credential|api[_-]?key|permission/i.test(haystack) || /insufficient.*(balance|quota)|billing|payment|quota.*exceeded.*(?!retry)/i.test(haystack) || /model.*not[_-]?found|unknown[_-]?model|model[_-]?not[_-]?found|not.*support.*model/i.test(haystack) || /context.*(length|limit|overflow|exceed)|token.*limit|max.*context/i.test(haystack) || /invalid[_-]?request|bad[_-]?request/i.test(haystack) || /prompt variable "\{\{[^"\r\n]+\}\}" has no value for this assembly/i.test(haystack);
|
|
1240
1240
|
return !permanent;
|
|
1241
1241
|
}
|
|
1242
1242
|
function formatElapsed(ms) {
|
|
@@ -1689,6 +1689,16 @@ function validateSessionEvents(events) {
|
|
|
1689
1689
|
}
|
|
1690
1690
|
return events;
|
|
1691
1691
|
}
|
|
1692
|
+
function latestTurnStart(events) {
|
|
1693
|
+
for (let i = events.length - 1; i >= 0; i -= 1) {
|
|
1694
|
+
const event = events[i];
|
|
1695
|
+
if (event?.type === "turn/start") return event;
|
|
1696
|
+
}
|
|
1697
|
+
return void 0;
|
|
1698
|
+
}
|
|
1699
|
+
function isMaintenanceTurnStart(event) {
|
|
1700
|
+
return event?.data?.reason === "message-ops";
|
|
1701
|
+
}
|
|
1692
1702
|
function parseFailureFacts(value) {
|
|
1693
1703
|
if (typeof value !== "object" || value === null || Array.isArray(value)) return void 0;
|
|
1694
1704
|
const failure = value;
|
|
@@ -1905,6 +1915,7 @@ var AutoContinueRunner = class {
|
|
|
1905
1915
|
return;
|
|
1906
1916
|
}
|
|
1907
1917
|
if (sessionState?.subagent) return;
|
|
1918
|
+
if (sessionState?.maintenanceTurn !== void 0 && sessionState.maintenanceTurn === event.data.turn && event.type !== "turn/start" && event.type !== "turn/end") return;
|
|
1908
1919
|
if ((event.type === "user/message" || event.type === "assistant/message") && typeof event.surfaceOp === "object" && event.surfaceOp !== null) {
|
|
1909
1920
|
this.state(sessionId).tools.recordSurfaceReplacement(event.seq);
|
|
1910
1921
|
return;
|
|
@@ -2134,6 +2145,8 @@ var AutoContinueRunner = class {
|
|
|
2134
2145
|
switch (event.type) {
|
|
2135
2146
|
case "turn/start":
|
|
2136
2147
|
state.running = true;
|
|
2148
|
+
state.maintenanceTurn = isMaintenanceTurnStart(event) ? event.data.turn : void 0;
|
|
2149
|
+
if (state.maintenanceTurn !== void 0) state.pendingRecoveryAt = 0;
|
|
2137
2150
|
state.tools.startTurn(event.seq);
|
|
2138
2151
|
state.shortRun = 0;
|
|
2139
2152
|
state.lastShortAt = 0;
|
|
@@ -2160,6 +2173,12 @@ var AutoContinueRunner = class {
|
|
|
2160
2173
|
const turnOutput = state.outputTurn === event.data.turn ? state.turnOutput : "unknown";
|
|
2161
2174
|
state.turnOutput = "unknown";
|
|
2162
2175
|
state.outputTurn = void 0;
|
|
2176
|
+
const maintenance = state.maintenanceTurn !== void 0 && state.maintenanceTurn === event.data.turn;
|
|
2177
|
+
state.maintenanceTurn = void 0;
|
|
2178
|
+
if (maintenance) {
|
|
2179
|
+
this.log(`跳过维护回合 ${sessionId}(message-ops): 不触发自动继续`);
|
|
2180
|
+
break;
|
|
2181
|
+
}
|
|
2163
2182
|
const reason = event.data.reason;
|
|
2164
2183
|
const reasonKind = readReasonKind(reason);
|
|
2165
2184
|
if (reasonKind === void 0) {
|
|
@@ -2636,11 +2655,13 @@ var AutoContinueRunner = class {
|
|
|
2636
2655
|
}
|
|
2637
2656
|
}
|
|
2638
2657
|
const reasonKind = readReasonKind(lastEnd?.data.reason);
|
|
2658
|
+
const lastStart = latestTurnStart(events);
|
|
2659
|
+
const maintenance = lastStart?.data.turn === lastEnd?.data.turn && isMaintenanceTurnStart(lastStart);
|
|
2639
2660
|
const silent = reasonKind === "no-visible-output" && config.resumeSilentTurns;
|
|
2640
2661
|
const superseded = lastEnd !== void 0 && events.some(
|
|
2641
2662
|
(event) => event.seq > lastEnd.seq && (event.type === "turn/start" || event.type === "user/message" && event.data.source.kind === "user")
|
|
2642
2663
|
);
|
|
2643
|
-
if (lastEnd === void 0 || reasonKind === void 0 || !isNonHumanReason(reasonKind) && !silent || lastEnd.time < now - config.freshMs || superseded) {
|
|
2664
|
+
if (lastEnd === void 0 || maintenance || reasonKind === void 0 || !isNonHumanReason(reasonKind) && !silent || lastEnd.time < now - config.freshMs || superseded) {
|
|
2644
2665
|
this.bootScannedSessions.add(session);
|
|
2645
2666
|
continue;
|
|
2646
2667
|
}
|
|
@@ -2783,15 +2804,9 @@ var AutoContinueRunner = class {
|
|
|
2783
2804
|
break;
|
|
2784
2805
|
}
|
|
2785
2806
|
}
|
|
2786
|
-
|
|
2787
|
-
for (let i = events.length - 1; i >= 0; i -= 1) {
|
|
2788
|
-
const event = events[i];
|
|
2789
|
-
if (event?.type === "turn/start") {
|
|
2790
|
-
lastStart = event;
|
|
2791
|
-
break;
|
|
2792
|
-
}
|
|
2793
|
-
}
|
|
2807
|
+
const lastStart = latestTurnStart(events);
|
|
2794
2808
|
const openTurn = lastStart !== void 0 && (lastEnd === void 0 || lastStart.seq > lastEnd.seq);
|
|
2809
|
+
if (isMaintenanceTurnStart(lastStart) && (openTurn || lastStart?.data.turn === lastEnd?.data.turn)) continue;
|
|
2795
2810
|
let reasonKind;
|
|
2796
2811
|
let freshAt;
|
|
2797
2812
|
if (openTurn) {
|
|
@@ -330,6 +330,8 @@ export interface SessionState {
|
|
|
330
330
|
turnOutput: 'unknown' | 'empty' | 'silent' | 'visible';
|
|
331
331
|
outputTurn: number | undefined;
|
|
332
332
|
outputStartSeq: number;
|
|
333
|
+
/** message-ops maintenance window, which must not enter model recovery or loop accounting. */
|
|
334
|
+
maintenanceTurn?: number;
|
|
333
335
|
/** 当前连续短句数(loop guard 信号 1: 空转)。 */
|
|
334
336
|
shortRun: number;
|
|
335
337
|
/** 最后一条短句的时间(时间窗判定用)。 */
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-client-auto-continue",
|
|
3
3
|
"description": "DSH Web UI plugin: automatically sends a localized continue prompt when a request is interrupted by network errors or other non-human causes",
|
|
4
|
-
"version": "0.17.
|
|
4
|
+
"version": "0.17.1-rc.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"types": "lib/types/index.d.ts",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"watch": "node build.mjs --watch",
|
|
51
51
|
"typecheck": "tsc --noEmit",
|
|
52
52
|
"test:runtime": "node tests/settings-host-live.mjs 0.1.7 && node tests/settings-host-live.mjs 0.2.0 && node tests/settings-host-live.mjs 0.2.1 && node tests/profile-compatibility.mjs 0.2.0 && node tests/profile-compatibility.mjs 0.2.1 && node tests/client-settings-services.mjs 0.2.0 && node tests/client-settings-services.mjs 0.2.1 && node tests/boot-scan-host-live.mjs 0.2.0-rc.2 && node tests/boot-scan-host-live.mjs 0.2.1 && node tests/settings-host-live.mjs 0.2.1-rc.2 && node tests/profile-compatibility.mjs 0.2.1-rc.2 && node tests/boot-scan-restart-live.mjs && node tests/settings-host-live.mjs 0.2.1-rc.2 mixed && node tests/settings-migration.mjs",
|
|
53
|
-
"test": "node tests/boot-scan-stored-sweep.mjs && node tests/loop-guard-progress.mjs && node tests/scan-on-boot.mjs && node tests/boot-scan-isolation.mjs && node tests/silent-turn-boundaries.mjs && node tests/autonomous-loop.mjs && node tests/session-modes.mjs && node tests/manual-resume-pauses.mjs && node tests/stats-freshness.mjs && node tests/simulate-host.mjs && node tests/settings-host-compat.mjs && node tests/simulate-client-loader.mjs && node tests/client-settings-services.mjs && node tests/client-settings-form.mjs && node tests/locale-mirror-bounded.mjs && node tests/settings-card-ui.mjs && node tests/composer-toggle.mjs && node tests/settings-notifications.mjs && node tests/prepare-github-package.mjs",
|
|
53
|
+
"test": "node tests/boot-scan-stored-sweep.mjs && node tests/loop-guard-progress.mjs && node tests/scan-on-boot.mjs && node tests/boot-scan-isolation.mjs && node tests/silent-turn-boundaries.mjs && node tests/autonomous-loop.mjs && node tests/session-modes.mjs && node tests/manual-resume-pauses.mjs && node tests/stats-freshness.mjs && node tests/simulate-host.mjs && node tests/settings-host-compat.mjs && node tests/simulate-client-loader.mjs && node tests/client-settings-services.mjs && node tests/client-settings-form.mjs && node tests/locale-mirror-bounded.mjs && node tests/settings-card-ui.mjs && node tests/settings-card-native.mjs && node tests/composer-toggle.mjs && node tests/settings-notifications.mjs && node tests/prepare-github-package.mjs && node tests/maintenance-turns.mjs && node tests/publish-prerelease.mjs",
|
|
54
54
|
"prepack": "npm run build"
|
|
55
55
|
},
|
|
56
56
|
"keywords": [
|
package/src/host/engine.ts
CHANGED
|
@@ -173,6 +173,19 @@ function validateSessionEvents(events: unknown): readonly SessionEvent[] {
|
|
|
173
173
|
return events;
|
|
174
174
|
}
|
|
175
175
|
|
|
176
|
+
function latestTurnStart(events: readonly SessionEvent[]): SessionEvent<'turn/start'> | undefined {
|
|
177
|
+
for (let i = events.length - 1; i >= 0; i -= 1) {
|
|
178
|
+
const event = events[i];
|
|
179
|
+
if (event?.type === 'turn/start') return event;
|
|
180
|
+
}
|
|
181
|
+
return undefined;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function isMaintenanceTurnStart(event: SessionEvent<'turn/start'> | undefined): boolean {
|
|
185
|
+
// shortcut: only message-ops defines this marker; extend when another producer has a verified contract.
|
|
186
|
+
return (event?.data as { reason?: unknown } | undefined)?.reason === 'message-ops';
|
|
187
|
+
}
|
|
188
|
+
|
|
176
189
|
/** Interpret host failure payloads without trusting persisted or plugin-provided event shapes. */
|
|
177
190
|
function parseFailureFacts(value: unknown): FailureFacts | undefined {
|
|
178
191
|
if (typeof value !== 'object' || value === null || Array.isArray(value)) return undefined;
|
|
@@ -474,6 +487,9 @@ export class AutoContinueRunner {
|
|
|
474
487
|
return;
|
|
475
488
|
}
|
|
476
489
|
if (sessionState?.subagent) return;
|
|
490
|
+
if (sessionState?.maintenanceTurn !== undefined &&
|
|
491
|
+
sessionState.maintenanceTurn === (event.data as { turn?: number }).turn &&
|
|
492
|
+
event.type !== 'turn/start' && event.type !== 'turn/end') return;
|
|
477
493
|
if (
|
|
478
494
|
(event.type === 'user/message' || event.type === 'assistant/message') &&
|
|
479
495
|
typeof event.surfaceOp === 'object' &&
|
|
@@ -750,6 +766,8 @@ export class AutoContinueRunner {
|
|
|
750
766
|
switch (event.type) {
|
|
751
767
|
case 'turn/start':
|
|
752
768
|
state.running = true;
|
|
769
|
+
state.maintenanceTurn = isMaintenanceTurnStart(event) ? event.data.turn : undefined;
|
|
770
|
+
if (state.maintenanceTurn !== undefined) state.pendingRecoveryAt = 0;
|
|
753
771
|
// 新回合开始: 清空上一步工具调用状态, 避免跨回合误用护栏
|
|
754
772
|
state.tools.startTurn(event.seq);
|
|
755
773
|
// loop guard 状态按回合重置
|
|
@@ -778,6 +796,12 @@ export class AutoContinueRunner {
|
|
|
778
796
|
const turnOutput = state.outputTurn === event.data.turn ? state.turnOutput : 'unknown';
|
|
779
797
|
state.turnOutput = 'unknown';
|
|
780
798
|
state.outputTurn = undefined;
|
|
799
|
+
const maintenance = state.maintenanceTurn !== undefined && state.maintenanceTurn === event.data.turn;
|
|
800
|
+
state.maintenanceTurn = undefined;
|
|
801
|
+
if (maintenance) {
|
|
802
|
+
this.log(`跳过维护回合 ${sessionId}(message-ops): 不触发自动继续`);
|
|
803
|
+
break;
|
|
804
|
+
}
|
|
781
805
|
const reason = event.data.reason;
|
|
782
806
|
const reasonKind = readReasonKind(reason);
|
|
783
807
|
if (reasonKind === undefined) {
|
|
@@ -1352,12 +1376,14 @@ export class AutoContinueRunner {
|
|
|
1352
1376
|
if (event?.type === 'turn/end') { lastEnd = event; break; }
|
|
1353
1377
|
}
|
|
1354
1378
|
const reasonKind = readReasonKind(lastEnd?.data.reason);
|
|
1379
|
+
const lastStart = latestTurnStart(events);
|
|
1380
|
+
const maintenance = lastStart?.data.turn === lastEnd?.data.turn && isMaintenanceTurnStart(lastStart);
|
|
1355
1381
|
const silent = reasonKind === 'no-visible-output' && config.resumeSilentTurns;
|
|
1356
1382
|
const superseded = lastEnd !== undefined && events.some((event) =>
|
|
1357
1383
|
event.seq > lastEnd!.seq && (event.type === 'turn/start' ||
|
|
1358
1384
|
(event.type === 'user/message' && event.data.source.kind === 'user')),
|
|
1359
1385
|
);
|
|
1360
|
-
if (lastEnd === undefined || reasonKind === undefined || (!isNonHumanReason(reasonKind) && !silent) ||
|
|
1386
|
+
if (lastEnd === undefined || maintenance || reasonKind === undefined || (!isNonHumanReason(reasonKind) && !silent) ||
|
|
1361
1387
|
lastEnd.time < now - config.freshMs || superseded) {
|
|
1362
1388
|
this.bootScannedSessions.add(session);
|
|
1363
1389
|
continue;
|
|
@@ -1495,16 +1521,13 @@ export class AutoContinueRunner {
|
|
|
1495
1521
|
const event = events[i];
|
|
1496
1522
|
if (event?.type === 'turn/end') { lastEnd = event; break; }
|
|
1497
1523
|
}
|
|
1498
|
-
|
|
1499
|
-
for (let i = events.length - 1; i >= 0; i -= 1) {
|
|
1500
|
-
const event = events[i];
|
|
1501
|
-
if (event?.type === 'turn/start') { lastStart = event; break; }
|
|
1502
|
-
}
|
|
1524
|
+
const lastStart = latestTurnStart(events);
|
|
1503
1525
|
// 兜底分支: 真实 sessionQuery 冷读会把内存中的 interruptedTurnClosers
|
|
1504
1526
|
// 折叠进返回日志(尾部即合成 turn/end), 上方 closed-tail 才是生产主路
|
|
1505
1527
|
// 径。这里覆盖两种例外——不折叠的宿主实现, 以及 listSessions 快照与
|
|
1506
1528
|
// observeSession 之间客户端刚打开、切在轮次中间的 live 视图。
|
|
1507
1529
|
const openTurn = lastStart !== undefined && (lastEnd === undefined || lastStart.seq > lastEnd.seq);
|
|
1530
|
+
if (isMaintenanceTurnStart(lastStart) && (openTurn || lastStart?.data.turn === lastEnd?.data.turn)) continue;
|
|
1508
1531
|
let reasonKind: string | undefined;
|
|
1509
1532
|
let freshAt: number;
|
|
1510
1533
|
if (openTurn) {
|
package/src/shared/core.ts
CHANGED
|
@@ -288,7 +288,8 @@ export function isTransientFailure(failure: FailureFacts, retryableErrorPatterns
|
|
|
288
288
|
/insufficient.*(balance|quota)|billing|payment|quota.*exceeded.*(?!retry)/i.test(haystack) ||
|
|
289
289
|
/model.*not[_-]?found|unknown[_-]?model|model[_-]?not[_-]?found|not.*support.*model/i.test(haystack) ||
|
|
290
290
|
/context.*(length|limit|overflow|exceed)|token.*limit|max.*context/i.test(haystack) ||
|
|
291
|
-
/invalid[_-]?request|bad[_-]?request/i.test(haystack)
|
|
291
|
+
/invalid[_-]?request|bad[_-]?request/i.test(haystack) ||
|
|
292
|
+
/prompt variable "\{\{[^"\r\n]+\}\}" has no value for this assembly/i.test(haystack);
|
|
292
293
|
return !permanent;
|
|
293
294
|
}
|
|
294
295
|
|
|
@@ -891,6 +892,8 @@ export interface SessionState {
|
|
|
891
892
|
turnOutput: 'unknown' | 'empty' | 'silent' | 'visible';
|
|
892
893
|
outputTurn: number | undefined;
|
|
893
894
|
outputStartSeq: number;
|
|
895
|
+
/** message-ops maintenance window, which must not enter model recovery or loop accounting. */
|
|
896
|
+
maintenanceTurn?: number;
|
|
894
897
|
/** 当前连续短句数(loop guard 信号 1: 空转)。 */
|
|
895
898
|
shortRun: number;
|
|
896
899
|
/** 最后一条短句的时间(时间窗判定用)。 */
|