dsh-client-auto-continue 0.14.1 → 0.14.3
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 +13 -4
- package/README.zh.md +13 -4
- package/lib/client.js +10 -7
- package/lib/client.js.map +2 -2
- package/lib/index.js +105 -65
- package/lib/types/client/dsh-store-compat.d.ts +1 -1
- package/lib/types/client/settings-form.d.ts +3 -1
- package/lib/types/host/engine.d.ts +4 -0
- package/package.json +3 -3
- package/src/client/dsh-store-compat.ts +1 -1
- package/src/client/index.ts +2 -1
- package/src/client/locales.ts +2 -2
- package/src/client/settings-card.tsx +3 -2
- package/src/client/settings-form.ts +8 -3
- package/src/host/engine.ts +113 -62
package/lib/index.js
CHANGED
|
@@ -637,11 +637,19 @@ var MANUAL_NOTIFICATION_REASON = "manual:notification";
|
|
|
637
637
|
var isLoopReason = (reason) => reason === LOOP_COMPLETED_REASON || reason === LOOP_SILENT_REASON;
|
|
638
638
|
var STREAM_NEAR_DUPLICATE_MAX_CHARS = 2048;
|
|
639
639
|
var STREAM_TAIL_MAX_CHARS = 4096;
|
|
640
|
+
var visibleText = (text) => text.replace(/\p{Cf}/gu, "").trim();
|
|
640
641
|
function snapshotSessionEvents(session) {
|
|
641
642
|
const compatible = session;
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
throw new TypeError("session
|
|
643
|
+
const snapshot = compatible.snapshotEvents;
|
|
644
|
+
const events = typeof snapshot === "function" ? snapshot.call(session) : compatible.events;
|
|
645
|
+
if (!Array.isArray(events)) throw new TypeError("session history is not an event array");
|
|
646
|
+
for (let index = 0; index < events.length; index += 1) {
|
|
647
|
+
const event = events[index];
|
|
648
|
+
if (event === null || typeof event !== "object" || Array.isArray(event) || typeof event.type !== "string" || event.type === "" || !Number.isSafeInteger(event.seq) || event.seq < 0 || !Number.isFinite(event.time) || event.time < 0) {
|
|
649
|
+
throw new TypeError(`invalid session event envelope at index ${index}`);
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
return events;
|
|
645
653
|
}
|
|
646
654
|
function parseFailureFacts(value) {
|
|
647
655
|
if (typeof value !== "object" || value === null || Array.isArray(value)) return void 0;
|
|
@@ -683,6 +691,8 @@ var AutoContinueRunner = class {
|
|
|
683
691
|
this.prioritizedFollowups = /* @__PURE__ */ new Set();
|
|
684
692
|
this.disposed = false;
|
|
685
693
|
this.bootScannedSessions = /* @__PURE__ */ new WeakSet();
|
|
694
|
+
/** Also bound diagnostics when even an agent's session getter is unavailable. */
|
|
695
|
+
this.bootScanErrors = /* @__PURE__ */ new WeakSet();
|
|
686
696
|
this.disposeSessionEvents = ctx.on("session/event", (session, event) => {
|
|
687
697
|
try {
|
|
688
698
|
this.onHostEvent(session, event);
|
|
@@ -834,6 +844,8 @@ var AutoContinueRunner = class {
|
|
|
834
844
|
const state = this.state(sessionId);
|
|
835
845
|
if (state.tools.recordCall(event)) {
|
|
836
846
|
state.shortRun = 0;
|
|
847
|
+
state.sameTextRun = 0;
|
|
848
|
+
state.lastAssistantText = "";
|
|
837
849
|
if (this.tracksOutput(state, event)) state.turnOutput = "visible";
|
|
838
850
|
}
|
|
839
851
|
} else if (event.type === "tool/result") {
|
|
@@ -848,7 +860,7 @@ var AutoContinueRunner = class {
|
|
|
848
860
|
const state = this.state(sessionId);
|
|
849
861
|
if (this.tracksOutput(state, event)) {
|
|
850
862
|
const chunk = event.data.chunk;
|
|
851
|
-
const visible = chunk.type === "text-delta" && chunk.text
|
|
863
|
+
const visible = chunk.type === "text-delta" && visibleText(chunk.text) !== "" || chunk.type === "tool-call-delta" || chunk.type === "block-end" && this.hasVisibleContent([chunk.block]) || chunk.type === "block-start" && chunk.blockType !== "reasoning" && chunk.blockType !== "text";
|
|
852
864
|
if (visible) state.turnOutput = "visible";
|
|
853
865
|
else if (state.turnOutput === "empty" && chunk.type !== "usage" && chunk.type !== "finish") state.turnOutput = "silent";
|
|
854
866
|
}
|
|
@@ -873,7 +885,7 @@ var AutoContinueRunner = class {
|
|
|
873
885
|
if (part === null || typeof part !== "object") return true;
|
|
874
886
|
const block = part;
|
|
875
887
|
if (block.type === "reasoning") return false;
|
|
876
|
-
if (block.type === "text") return typeof block.text !== "string" || block.text
|
|
888
|
+
if (block.type === "text") return typeof block.text !== "string" || visibleText(block.text) !== "";
|
|
877
889
|
return true;
|
|
878
890
|
});
|
|
879
891
|
}
|
|
@@ -887,7 +899,7 @@ var AutoContinueRunner = class {
|
|
|
887
899
|
return event.data.chunk.type === "text-delta" ? event.data.chunk.text : "";
|
|
888
900
|
}
|
|
889
901
|
normalizedSegment(text) {
|
|
890
|
-
return text.replace(/\s+/g, " ")
|
|
902
|
+
return visibleText(text).replace(/\s+/g, " ");
|
|
891
903
|
}
|
|
892
904
|
isNearDuplicateSegment(left, right) {
|
|
893
905
|
if (left === right) return true;
|
|
@@ -978,12 +990,12 @@ var AutoContinueRunner = class {
|
|
|
978
990
|
onAssistantMessage(sessionId, state, event) {
|
|
979
991
|
if (!this.getConfig().loopGuard) return;
|
|
980
992
|
const text = this.assistantText(event);
|
|
981
|
-
const trimmed = text
|
|
993
|
+
const trimmed = visibleText(text);
|
|
982
994
|
if (trimmed !== "" && trimmed === state.lastAssistantText) {
|
|
983
995
|
state.sameTextRun += 1;
|
|
984
996
|
} else {
|
|
985
997
|
state.lastAssistantText = trimmed;
|
|
986
|
-
state.sameTextRun = 1;
|
|
998
|
+
state.sameTextRun = trimmed === "" ? 0 : 1;
|
|
987
999
|
}
|
|
988
1000
|
if (trimmed.length < this.getConfig().loopShortChars) {
|
|
989
1001
|
const now = Date.now();
|
|
@@ -1502,80 +1514,108 @@ var AutoContinueRunner = class {
|
|
|
1502
1514
|
const now = Date.now();
|
|
1503
1515
|
const candidates = [];
|
|
1504
1516
|
for (const agent of this.ctx.agents.list()) {
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1517
|
+
let session;
|
|
1518
|
+
let sessionId;
|
|
1519
|
+
try {
|
|
1520
|
+
session = agent.session;
|
|
1521
|
+
if (this.bootScannedSessions.has(session) || session.header?.origin === "subagent") continue;
|
|
1522
|
+
sessionId = session.id;
|
|
1523
|
+
if (typeof sessionId !== "string" || sessionId === "") throw new TypeError("session id is unavailable");
|
|
1524
|
+
const state = this.state(sessionId);
|
|
1525
|
+
if (state.pendingTimer !== void 0 || state.consecutive >= config.maxConsecutive) continue;
|
|
1526
|
+
if (now - state.lastAttemptAt < this.cooldownFor(state)) continue;
|
|
1527
|
+
if (now < (this.pauseUntil.get(sessionId) ?? 0)) continue;
|
|
1528
|
+
const events = snapshotSessionEvents(session);
|
|
1529
|
+
if (events.length === 0) continue;
|
|
1530
|
+
let lastEnd;
|
|
1531
|
+
for (let i = events.length - 1; i >= 0; i -= 1) {
|
|
1532
|
+
const event = events[i];
|
|
1533
|
+
if (event?.type === "turn/end") {
|
|
1534
|
+
lastEnd = event;
|
|
1535
|
+
break;
|
|
1536
|
+
}
|
|
1519
1537
|
}
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
if (lastEnd === void 0 || reasonKind === void 0 || !isNonHumanReason(reasonKind) && !silent || lastEnd.time < now - config.freshMs || superseded) {
|
|
1527
|
-
this.bootScannedSessions.add(session);
|
|
1528
|
-
continue;
|
|
1529
|
-
}
|
|
1530
|
-
let failure;
|
|
1531
|
-
if (reasonKind === "error") {
|
|
1532
|
-
failure = parseFailureFacts(lastEnd.data.reason.error);
|
|
1533
|
-
if (failure === void 0) {
|
|
1538
|
+
const reasonKind = readReasonKind(lastEnd?.data.reason);
|
|
1539
|
+
const silent = reasonKind === "no-visible-output" && config.resumeSilentTurns;
|
|
1540
|
+
const superseded = lastEnd !== void 0 && events.some(
|
|
1541
|
+
(event) => event.seq > lastEnd.seq && (event.type === "turn/start" || event.type === "user/message" && event.data.source.kind === "user")
|
|
1542
|
+
);
|
|
1543
|
+
if (lastEnd === void 0 || reasonKind === void 0 || !isNonHumanReason(reasonKind) && !silent || lastEnd.time < now - config.freshMs || superseded) {
|
|
1534
1544
|
this.bootScannedSessions.add(session);
|
|
1535
|
-
console.error(`[auto-continue] 忽略畸形扫描 turn/end ${session.id}: error details 无法解释`);
|
|
1536
1545
|
continue;
|
|
1537
1546
|
}
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1547
|
+
let failure;
|
|
1548
|
+
if (reasonKind === "error") {
|
|
1549
|
+
failure = parseFailureFacts(lastEnd.data.reason.error);
|
|
1550
|
+
if (failure === void 0) {
|
|
1551
|
+
this.bootScannedSessions.add(session);
|
|
1552
|
+
console.error(`[auto-continue] 忽略畸形扫描 turn/end ${sessionId}: error details 无法解释`);
|
|
1553
|
+
continue;
|
|
1554
|
+
}
|
|
1555
|
+
if (config.classify && !isTransientFailure(failure, config.retryableErrorPatterns)) {
|
|
1556
|
+
this.bootScannedSessions.add(session);
|
|
1557
|
+
this.onTurnFailure(sessionId, "scan:turn/end:error", failure);
|
|
1558
|
+
continue;
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
candidates.push({
|
|
1562
|
+
session,
|
|
1563
|
+
sessionId,
|
|
1564
|
+
events,
|
|
1565
|
+
lastEnd,
|
|
1566
|
+
reasonKind,
|
|
1567
|
+
failure,
|
|
1568
|
+
lastActivityAt: events.reduce((latest, event) => Math.max(latest, event.time), 0),
|
|
1569
|
+
listIndex: candidates.length
|
|
1570
|
+
});
|
|
1571
|
+
} catch (error) {
|
|
1572
|
+
if (session !== null && typeof session === "object") this.bootScannedSessions.add(session);
|
|
1573
|
+
const identity = session ?? agent;
|
|
1574
|
+
if (identity !== null && typeof identity === "object") {
|
|
1575
|
+
if (this.bootScanErrors.has(identity)) continue;
|
|
1576
|
+
this.bootScanErrors.add(identity);
|
|
1542
1577
|
}
|
|
1578
|
+
this.logBootScanFailure(sessionId, error);
|
|
1543
1579
|
}
|
|
1544
|
-
candidates.push({
|
|
1545
|
-
session,
|
|
1546
|
-
events,
|
|
1547
|
-
lastEnd,
|
|
1548
|
-
reasonKind,
|
|
1549
|
-
failure,
|
|
1550
|
-
lastActivityAt: events.reduce((latest, event) => Math.max(latest, event.time), 0),
|
|
1551
|
-
listIndex: candidates.length
|
|
1552
|
-
});
|
|
1553
1580
|
}
|
|
1554
1581
|
candidates.sort((left, right) => right.lastActivityAt - left.lastActivityAt || left.listIndex - right.listIndex);
|
|
1555
|
-
|
|
1582
|
+
let recoveries = 0;
|
|
1583
|
+
for (const candidate of candidates) {
|
|
1584
|
+
if (recoveries >= config.scanLimit) break;
|
|
1556
1585
|
if (this.disposed) return true;
|
|
1557
|
-
const { session, events, lastEnd, reasonKind, failure } = candidate;
|
|
1586
|
+
const { session, sessionId, events, lastEnd, reasonKind, failure } = candidate;
|
|
1558
1587
|
this.bootScannedSessions.add(session);
|
|
1559
|
-
const state = this.state(
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
state.lastFailureAt = lastEnd.time;
|
|
1567
|
-
this.onTurnFailure(session.id, scanReason, failure);
|
|
1568
|
-
} else {
|
|
1569
|
-
if (reasonKind === "no-visible-output") {
|
|
1570
|
-
state.lastFailure = void 0;
|
|
1588
|
+
const state = this.state(sessionId);
|
|
1589
|
+
try {
|
|
1590
|
+
this.applyGuardFromEvents(state, events, lastEnd.seq);
|
|
1591
|
+
const scanReason = `scan:turn/end:${reasonKind}${reasonKind === "no-visible-output" ? ":silent" : ""}`;
|
|
1592
|
+
this.log(`扫描发现中断 ${sessionId}(turn/end:${reasonKind}), 交给恢复策略处理`);
|
|
1593
|
+
if (failure !== void 0) {
|
|
1594
|
+
state.lastFailure = failure;
|
|
1571
1595
|
state.lastTurn = lastEnd.data.turn;
|
|
1572
1596
|
state.lastFailureAt = lastEnd.time;
|
|
1597
|
+
this.onTurnFailure(sessionId, scanReason, failure);
|
|
1598
|
+
} else {
|
|
1599
|
+
if (reasonKind === "no-visible-output") {
|
|
1600
|
+
state.lastFailure = void 0;
|
|
1601
|
+
state.lastTurn = lastEnd.data.turn;
|
|
1602
|
+
state.lastFailureAt = lastEnd.time;
|
|
1603
|
+
}
|
|
1604
|
+
this.schedule(sessionId, scanReason);
|
|
1573
1605
|
}
|
|
1574
|
-
|
|
1606
|
+
recoveries += 1;
|
|
1607
|
+
} catch (error) {
|
|
1608
|
+
state.tools.reset();
|
|
1609
|
+
this.cancelPending(sessionId, "启动扫描失败");
|
|
1610
|
+
this.logBootScanFailure(sessionId, error);
|
|
1575
1611
|
}
|
|
1576
1612
|
}
|
|
1577
1613
|
return false;
|
|
1578
1614
|
}
|
|
1615
|
+
/** Captured identity only: even session.id can throw when the header is damaged. */
|
|
1616
|
+
logBootScanFailure(sessionId, error) {
|
|
1617
|
+
console.error(`[auto-continue] 启动扫描跳过会话 ${sessionId ?? "(id unavailable)"}: ${error instanceof Error ? error.message : String(error)}`);
|
|
1618
|
+
}
|
|
1579
1619
|
/** 从历史事件恢复上一步工具调用状态(扫描路径的幂等护栏)。 */
|
|
1580
1620
|
applyGuardFromEvents(state, events, untilSeq) {
|
|
1581
1621
|
state.tools.restore(events, untilSeq);
|
|
@@ -22,7 +22,7 @@ export interface SettingsScopeSnapshot<T> {
|
|
|
22
22
|
user: unknown;
|
|
23
23
|
revision: number | undefined;
|
|
24
24
|
writable: boolean;
|
|
25
|
-
mode
|
|
25
|
+
mode?: 'host' | 'memory';
|
|
26
26
|
}
|
|
27
27
|
/** Stable subset shared by settings scopes and DSH 0.1.7 configuration forms. */
|
|
28
28
|
export interface SettingsScope<T> {
|
|
@@ -10,7 +10,9 @@
|
|
|
10
10
|
* default — and whether the user layer carries it (presence, not value
|
|
11
11
|
* equality, marks an override).
|
|
12
12
|
*/
|
|
13
|
-
import type { SettingsScope, SnapshotStore } from './dsh-store-compat.ts';
|
|
13
|
+
import type { SettingsScope, SettingsScopeSnapshot, SnapshotStore } from './dsh-store-compat.ts';
|
|
14
|
+
/** Current forms omit mode; legacy memory scopes still cannot persist settings. */
|
|
15
|
+
export declare function canWriteSettings(snapshot: SettingsScopeSnapshot<unknown>): boolean;
|
|
14
16
|
/** The write one field's staged text performs when the card is saved. */
|
|
15
17
|
export type FieldWrite = {
|
|
16
18
|
kind: 'set';
|
|
@@ -42,6 +42,8 @@ export declare class AutoContinueRunner {
|
|
|
42
42
|
private readonly disposeInboxEvents;
|
|
43
43
|
private disposed;
|
|
44
44
|
private readonly bootScannedSessions;
|
|
45
|
+
/** Also bound diagnostics when even an agent's session getter is unavailable. */
|
|
46
|
+
private readonly bootScanErrors;
|
|
45
47
|
private bootScanTimer;
|
|
46
48
|
private wakeBootScan;
|
|
47
49
|
/**
|
|
@@ -135,6 +137,8 @@ export declare class AutoContinueRunner {
|
|
|
135
137
|
private bootScanLoop;
|
|
136
138
|
/** Inspect newly available sessions; process each settled startup history once. */
|
|
137
139
|
private scanInterrupted;
|
|
140
|
+
/** Captured identity only: even session.id can throw when the header is damaged. */
|
|
141
|
+
private logBootScanFailure;
|
|
138
142
|
/** 从历史事件恢复上一步工具调用状态(扫描路径的幂等护栏)。 */
|
|
139
143
|
private applyGuardFromEvents;
|
|
140
144
|
}
|
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.14.
|
|
4
|
+
"version": "0.14.3",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"types": "lib/types/index.d.ts",
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
"build": "node build.mjs && tsc -p tsconfig.build.json",
|
|
47
47
|
"watch": "node build.mjs --watch",
|
|
48
48
|
"typecheck": "tsc --noEmit",
|
|
49
|
-
"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",
|
|
50
|
-
"test": "node tests/scan-on-boot.mjs && node tests/silent-turn-boundaries.mjs && node tests/autonomous-loop.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",
|
|
49
|
+
"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",
|
|
50
|
+
"test": "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/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",
|
|
51
51
|
"prepack": "npm run build"
|
|
52
52
|
},
|
|
53
53
|
"keywords": [
|
|
@@ -24,7 +24,7 @@ export interface SettingsScopeSnapshot<T> {
|
|
|
24
24
|
user: unknown;
|
|
25
25
|
revision: number | undefined;
|
|
26
26
|
writable: boolean;
|
|
27
|
-
mode
|
|
27
|
+
mode?: 'host' | 'memory';
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
/** Stable subset shared by settings scopes and DSH 0.1.7 configuration forms. */
|
package/src/client/index.ts
CHANGED
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
import { startBridge } from './bridge.ts';
|
|
28
28
|
import { AutoContinueComposerToggle } from './composer-toggle.tsx';
|
|
29
29
|
import type { SettingsScope } from './dsh-store-compat.ts';
|
|
30
|
+
import { canWriteSettings } from './settings-form.ts';
|
|
30
31
|
|
|
31
32
|
/** Dictionary namespace owned by this plugin. */
|
|
32
33
|
const NS = 'auto-continue';
|
|
@@ -122,7 +123,7 @@ function mountSettings(ctx: ClientContext, scope: SettingsScope<AutoContinueSett
|
|
|
122
123
|
const syncLocale = (): void => {
|
|
123
124
|
const active = ctx.locale.getLocale().active;
|
|
124
125
|
const snapshot = scope.getSnapshot();
|
|
125
|
-
if (
|
|
126
|
+
if (!canWriteSettings(snapshot)) return;
|
|
126
127
|
// A genuine language switch is the only thing that earns a fresh budget: the
|
|
127
128
|
// attempt count must survive matching snapshots, because the writing page's
|
|
128
129
|
// own acknowledgement arrives as a match (see above). Tracking `mirroredLocale`
|
package/src/client/locales.ts
CHANGED
|
@@ -43,7 +43,7 @@ export const zh = {
|
|
|
43
43
|
'composer.scope': '控制当前配置下所有会话的自动继续,修改立即保存。',
|
|
44
44
|
'composer.saving': '正在保存自动继续设置…',
|
|
45
45
|
'composer.saveFailed': '保存失败,请重试',
|
|
46
|
-
'field.pausedHint': '
|
|
46
|
+
'field.pausedHint': '恢复意外中断的会话。关闭并保存后,全局暂停恢复并取消已排队的继续。循环守卫独立运行;如需停止自动打断,请同时关闭循环守卫。',
|
|
47
47
|
'field.continueText': '继续文本',
|
|
48
48
|
'field.continueTextHint': '中断后自动发送的消息内容。',
|
|
49
49
|
'default.continueText': LOCALIZED_TEXT_DEFAULTS.zh.continueText,
|
|
@@ -180,7 +180,7 @@ export const en: Record<SettingsCardKey, string> = {
|
|
|
180
180
|
'composer.scope': 'Controls auto-continue for all sessions in this profile. Changes save immediately.',
|
|
181
181
|
'composer.saving': 'Saving auto-continue setting…',
|
|
182
182
|
'composer.saveFailed': 'Could not save. Try again.',
|
|
183
|
-
'field.pausedHint': 'Resume interrupted sessions. Turn off and save to pause recovery globally and cancel queued continuations.',
|
|
183
|
+
'field.pausedHint': 'Resume interrupted sessions. Turn off and save to pause recovery globally and cancel queued continuations. The loop guard stays active; turn it off separately to stop automatic interruptions.',
|
|
184
184
|
'field.continueText': 'Continue text',
|
|
185
185
|
'field.continueTextHint': 'Message automatically sent after an interruption.',
|
|
186
186
|
'default.continueText': LOCALIZED_TEXT_DEFAULTS.en.continueText,
|
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
import type { SettingsCardKey } from './locales.ts';
|
|
24
24
|
import {
|
|
25
25
|
booleanField,
|
|
26
|
+
canWriteSettings,
|
|
26
27
|
CardForm,
|
|
27
28
|
numberField,
|
|
28
29
|
textField,
|
|
@@ -186,7 +187,7 @@ export class AutoContinueSettingsCardController {
|
|
|
186
187
|
private async save(): Promise<void> {
|
|
187
188
|
const state = this.form.shell();
|
|
188
189
|
const snapshot = this.scope.getSnapshot();
|
|
189
|
-
if (this.disposed || !state.available || !state.writable || !state.dirty || state.invalid || state.saving
|
|
190
|
+
if (this.disposed || !state.available || !state.writable || !state.dirty || state.invalid || state.saving) return;
|
|
190
191
|
const sequence = ++this.saveSequence;
|
|
191
192
|
const before = snapshot.value?.notify ?? DEFAULT_CONFIG.notify;
|
|
192
193
|
const target = this.form.field('notify').text;
|
|
@@ -212,7 +213,7 @@ export class AutoContinueSettingsCardController {
|
|
|
212
213
|
return {
|
|
213
214
|
visible: snapshot.status === 'ready' && (snapshot.value?.showComposerToggle ?? DEFAULT_CONFIG.showComposerToggle),
|
|
214
215
|
enabled: !(snapshot.value?.paused ?? DEFAULT_CONFIG.paused),
|
|
215
|
-
writable: snapshot
|
|
216
|
+
writable: canWriteSettings(snapshot),
|
|
216
217
|
saving: this.composerSaving,
|
|
217
218
|
failed: this.composerFailed,
|
|
218
219
|
};
|
|
@@ -10,7 +10,12 @@
|
|
|
10
10
|
* default — and whether the user layer carries it (presence, not value
|
|
11
11
|
* equality, marks an override).
|
|
12
12
|
*/
|
|
13
|
-
import type { SettingsScope, SnapshotStore } from './dsh-store-compat.ts';
|
|
13
|
+
import type { SettingsScope, SettingsScopeSnapshot, SnapshotStore } from './dsh-store-compat.ts';
|
|
14
|
+
|
|
15
|
+
/** Current forms omit mode; legacy memory scopes still cannot persist settings. */
|
|
16
|
+
export function canWriteSettings(snapshot: SettingsScopeSnapshot<unknown>): boolean {
|
|
17
|
+
return snapshot.status === 'ready' && snapshot.writable && (snapshot.mode === undefined || snapshot.mode === 'host');
|
|
18
|
+
}
|
|
14
19
|
|
|
15
20
|
/** The write one field's staged text performs when the card is saved. */
|
|
16
21
|
export type FieldWrite = { kind: 'set'; value: unknown } | { kind: 'clear' };
|
|
@@ -162,7 +167,7 @@ export class CardForm<T> {
|
|
|
162
167
|
const snapshot = this.scope.getSnapshot();
|
|
163
168
|
return {
|
|
164
169
|
available: snapshot.status === 'ready',
|
|
165
|
-
writable: snapshot
|
|
170
|
+
writable: canWriteSettings(snapshot),
|
|
166
171
|
dirty: this.plan().length > 0,
|
|
167
172
|
invalid: this.plan().some((item) => item.run === undefined),
|
|
168
173
|
saving: this.saving,
|
|
@@ -214,7 +219,7 @@ export class CardForm<T> {
|
|
|
214
219
|
const plan = this.plan();
|
|
215
220
|
const writes = plan.flatMap((item) => (item.run === undefined ? [] : [item.run]));
|
|
216
221
|
const snapshot = this.scope.getSnapshot();
|
|
217
|
-
if (plan.length === 0 || this.saving || writes.length !== plan.length ||
|
|
222
|
+
if (plan.length === 0 || this.saving || writes.length !== plan.length || !canWriteSettings(snapshot)) return false;
|
|
218
223
|
// Keep the staged edits this save writes. A field can be staged again
|
|
219
224
|
// while a write is pending, so clear it only if that exact edit remains.
|
|
220
225
|
const edits = plan.map(({ field, staged }) => ({ field, staged }));
|