dsh-client-auto-continue 0.14.1 → 0.14.2

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 CHANGED
@@ -80,6 +80,8 @@ The host-side engine subscribes to the session event firehose inside the dsh hos
80
80
 
81
81
  On host boot it also scans the live sessions: a session whose last turn ended with a non-human reason **within the scan window** (default 15 minutes), with no later `turn/start` or user message, gets resumed automatically too (e.g. the host crashed while the browser was closed — the agent-loop resumes the session and the engine picks it up).
82
82
 
83
+ Startup recovery isolates failures per session. If history cannot be read or contains invalid events, that session is skipped for the current startup scan and an error is logged; other sessions can still recover, without losing a recovery slot. Invalid entries are not silently removed, since they could hide a manual stop or a newer turn. Valid empty histories and a registry that is still loading remain retryable within the scan window. Reloading a repaired session as a new session object also makes it eligible for scanning again. See [#58](https://github.com/HsiangNianian/dsh-auto-continue/issues/58).
84
+
83
85
  The browser provides the settings card and composer switch, plus a status bridge that shows notifications (with Resume now / Pause this session 1h buttons, routed back to the host engine) and feeds the card's stats / paused-sessions panels.
84
86
 
85
87
  ### Recovery workflow
@@ -96,12 +98,12 @@ DSH plugins install into a **profile** (`dsh web` → `web` profile). The comman
96
98
 
97
99
  | DSH runtime | Plugin version | Configuration entry point |
98
100
  | --- | --- | --- |
99
- | **0.2.1-alpha.1** | **0.14.1 verified** | **Plugins → dsh-client-auto-continue** |
101
+ | **0.2.1-alpha.1** | **0.14.2 verified** | **Plugins → dsh-client-auto-continue** |
100
102
  | **0.2.0-rc.1** | **0.12.1 or newer** | **Plugins → dsh-client-auto-continue** |
101
103
  | **0.1.7-rc.2** | **0.11.9 or newer** | Same Plugins page |
102
104
  | Older hosts with the legacy settings API | Legacy UI retained | **Settings → Plugins → Plugin configuration** |
103
105
 
104
- DSH 0.1.0-rc.6 and earlier are unsupported. Automated runtime checks cover **0.1.7-rc.2**, **0.2.0-rc.1** and **0.2.1-alpha.1**. Desktop app versions and embedded DSH runtime versions are different; use the runtime version when checking compatibility. For the CLI, run `dsh --version`; see [official DSH releases](https://github.com/deepseek-ai/deepseek-harness/releases) for available versions.
106
+ DSH 0.1.0-rc.6 and earlier are unsupported. Automated settings and compatibility checks cover **0.1.7-rc.2**, **0.2.0-rc.1** and **0.2.1-alpha.1**; startup failure isolation is also checked against **0.2.0-rc.2** and **0.2.1-alpha.1**. Desktop app versions and embedded DSH runtime versions are different; use the runtime version when checking compatibility. For the CLI, run `dsh --version`; see [official DSH releases](https://github.com/deepseek-ai/deepseek-harness/releases) for available versions.
105
107
 
106
108
  **Plugins 0.11.9 and 0.12.0 are rejected by DSH 0.2.0-rc.1’s version check.** Upgrade the plugin to 0.12.1 or newer; its existing configuration-form integration works on this runtime. See [#50](https://github.com/HsiangNianian/dsh-auto-continue/issues/50).
107
109
 
@@ -351,19 +353,21 @@ The recovery engine runs inside the DSH host. The browser provides the configura
351
353
 
352
354
  ## Development
353
355
 
354
- Use Node.js 22. Install both pinned runtime fixtures to reproduce CI locally:
356
+ Use Node.js 22. Install the pinned runtime fixtures to reproduce CI locally:
355
357
 
356
358
  ```bash
357
359
  npm ci
358
360
  npm ci --prefix tests/fixtures/dsh-0.1.7
359
361
  npm ci --prefix tests/fixtures/dsh-0.2.0
362
+ npm ci --prefix tests/fixtures/dsh-0.2.0-rc.2
363
+ npm ci --prefix tests/fixtures/dsh-0.2.1
360
364
  npm run typecheck
361
365
  npm run build
362
366
  npm test
363
367
  npm run test:runtime
364
368
  ```
365
369
 
366
- `npm test` covers recovery, autonomous-loop limits and toggles, child-session exclusion, manual resume during pauses, startup scanning, queue ordering, statistics, localization, settings UI lifecycle and edits made during pending saves. `npm run test:runtime` uses published DSH **0.1.7-rc.2** and **0.2.0-rc.1** Settings, Loader and HTTP services. It also runs the actual 0.2 profile compatibility gate and checks client activation with Cordis 4.0.4 when one settings provider is absent. The runtime harness controls agent events; it does not send requests to a model provider.
370
+ `npm test` covers recovery, autonomous-loop limits and toggles, child-session exclusion, manual resume during pauses, startup scanning and malformed-session isolation, queue ordering, statistics, localization, settings UI lifecycle and edits made during pending saves. `npm run test:runtime` uses published DSH **0.1.7-rc.2**, **0.2.0-rc.1** and **0.2.1-alpha.1** Settings, Loader and HTTP services. It also runs the actual 0.2 profile compatibility gate and checks client activation when one settings provider is absent. Startup recovery tests inject session read failures into real **0.2.0-rc.2** and **0.2.1-alpha.1** Session/Cordis/HTTP components and verify that healthy sessions still recover. These controlled faults do not imply that normal DSH loading produces malformed logs. The runtime harness controls agent events; it does not send requests to a model provider.
367
371
 
368
372
  After editing a linked checkout, run `npm run build` to write the updated `lib/` files, then restart DSH and refresh the browser. Hosts with client HMR enabled can reload a rebuilt client bundle automatically.
369
373
 
package/README.zh.md CHANGED
@@ -80,6 +80,8 @@
80
80
 
81
81
  宿主启动时还会扫描存活会话: 最后一个回合在**扫描时间窗**(默认 15 分钟)内以非人为原因结束、且其后没有新回合或用户消息的会话, 会被自动续跑(例如浏览器关闭期间宿主崩溃——agent-loop 恢复会话后引擎接着接手)。
82
82
 
83
+ 启动恢复按会话隔离异常。历史无法读取或含有无效事件时,只在本次启动扫描中跳过该会话并记录错误,其他会话仍可恢复,也不会被它占用恢复名额。插件不会静默删除损坏记录,以免漏掉人工停止或更新的回合。合法的空历史、尚未就绪的会话注册表仍会在扫描窗口内重试;修复后的会话若重新加载为新的 Session 对象,也可再次参与扫描。详见 [#58](https://github.com/HsiangNianian/dsh-auto-continue/issues/58)。
84
+
83
85
  浏览器负责设置卡片、会话区开关和一条状态桥(展示通知, 带「立即续跑 / 暂停该会话 1 小时」按钮并把动作回传给宿主引擎; 驱动卡片里的统计与暂停面板)。
84
86
 
85
87
  ### 恢复流程
@@ -96,12 +98,12 @@ DSH 插件安装进 **profile**(`dsh web` 对应 `web` profile)。下面的命
96
98
 
97
99
  | DSH 内核 | 插件版本 | 配置入口 |
98
100
  | --- | --- | --- |
99
- | **0.2.1-alpha.1** | **已验证 0.14.1** | **插件 → dsh-client-auto-continue** |
101
+ | **0.2.1-alpha.1** | **已验证 0.14.2** | **插件 → dsh-client-auto-continue** |
100
102
  | **0.2.0-rc.1** | **0.12.1 或更新版本** | **插件 → dsh-client-auto-continue** |
101
103
  | **0.1.7-rc.2** | **0.11.9 或更新版本** | 同上,从主侧栏的插件页进入 |
102
104
  | 使用旧设置 API 的宿主 | 保留旧版设置界面兼容 | **设置 → 插件 → 插件配置** |
103
105
 
104
- 不支持 DSH 0.1.0-rc.6 及更早版本。自动化运行时测试覆盖 **0.1.7-rc.2**、**0.2.0-rc.1** 和 **0.2.1-alpha.1**。桌面应用版本不等于内置的 DSH 内核版本,请按内核版本判断兼容性;CLI 可运行 `dsh --version`,可用版本见 [DSH 官方 Releases](https://github.com/deepseek-ai/deepseek-harness/releases)。
106
+ 不支持 DSH 0.1.0-rc.6 及更早版本。自动化设置与兼容测试覆盖 **0.1.7-rc.2**、**0.2.0-rc.1** 和 **0.2.1-alpha.1**,另在 **0.2.0-rc.2** 和 **0.2.1-alpha.1** 上验证启动扫描的异常隔离。桌面应用版本不等于内置的 DSH 内核版本,请按内核版本判断兼容性;CLI 可运行 `dsh --version`,可用版本见 [DSH 官方 Releases](https://github.com/deepseek-ai/deepseek-harness/releases)。
105
107
 
106
108
  **插件 0.11.9 和 0.12.0 会被 DSH 0.2.0-rc.1 的版本检查拦截。** 请升级到 0.12.1 或更新版本;现有配置表单接口可在该内核正常工作。详见 [#50](https://github.com/HsiangNianian/dsh-auto-continue/issues/50)。
107
109
 
@@ -351,19 +353,21 @@ auto-continue:
351
353
 
352
354
  ## 开发
353
355
 
354
- 使用 Node.js 22,安装两个锁定版本的运行时测试环境,即可在本地执行 CI 检查:
356
+ 使用 Node.js 22,安装锁定版本的运行时测试环境,即可在本地执行 CI 检查:
355
357
 
356
358
  ```bash
357
359
  npm ci
358
360
  npm ci --prefix tests/fixtures/dsh-0.1.7
359
361
  npm ci --prefix tests/fixtures/dsh-0.2.0
362
+ npm ci --prefix tests/fixtures/dsh-0.2.0-rc.2
363
+ npm ci --prefix tests/fixtures/dsh-0.2.1
360
364
  npm run typecheck
361
365
  npm run build
362
366
  npm test
363
367
  npm run test:runtime
364
368
  ```
365
369
 
366
- `npm test` 覆盖错误恢复、自主循环上限与开关、子会话排除、暂停期间手动续跑、启动扫描、队列顺序、统计、本地化、设置界面生命周期及保存期间继续编辑的情况。`npm run test:runtime` 使用已发布的 DSH **0.1.7-rc.2** 和 **0.2.0-rc.1** Settings、Loader、HTTP 组件,并运行真实的 0.2 profile 兼容检查,以及 Cordis 4.0.4 中缺少其中一种设置服务时的客户端激活测试。运行时测试使用受控的 agent 事件,不会向模型服务发送请求。
370
+ `npm test` 覆盖错误恢复、自主循环上限与开关、子会话排除、暂停期间手动续跑、启动扫描及畸形会话隔离、队列顺序、统计、本地化、设置界面生命周期及保存期间继续编辑的情况。`npm run test:runtime` 使用已发布的 DSH **0.1.7-rc.2**、**0.2.0-rc.1** 和 **0.2.1-alpha.1** Settings、Loader、HTTP 组件,并运行真实的 0.2 profile 兼容检查及缺少其中一种设置服务时的客户端激活测试。启动恢复测试在真实的 **0.2.0-rc.2** 和 **0.2.1-alpha.1** Session、Cordis、HTTP 组件中注入会话读取故障,验证健康会话仍能恢复;这不代表正常的 DSH 加载流程会产生损坏日志。运行时测试使用受控的 agent 事件,不会向模型服务发送请求。
367
371
 
368
372
  修改链接的本地仓库后,运行 `npm run build` 写入最新的 `lib/` 产物,再重启 DSH 并刷新浏览器。开启 client HMR 的宿主可自动重新加载已构建的客户端包。
369
373
 
package/lib/index.js CHANGED
@@ -639,9 +639,16 @@ var STREAM_NEAR_DUPLICATE_MAX_CHARS = 2048;
639
639
  var STREAM_TAIL_MAX_CHARS = 4096;
640
640
  function snapshotSessionEvents(session) {
641
641
  const compatible = session;
642
- if (typeof compatible.snapshotEvents === "function") return compatible.snapshotEvents();
643
- if (compatible.events !== void 0) return compatible.events;
644
- throw new TypeError("session exposes neither snapshotEvents() nor events");
642
+ const snapshot = compatible.snapshotEvents;
643
+ const events = typeof snapshot === "function" ? snapshot.call(session) : compatible.events;
644
+ if (!Array.isArray(events)) throw new TypeError("session history is not an event array");
645
+ for (let index = 0; index < events.length; index += 1) {
646
+ const event = events[index];
647
+ 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) {
648
+ throw new TypeError(`invalid session event envelope at index ${index}`);
649
+ }
650
+ }
651
+ return events;
645
652
  }
646
653
  function parseFailureFacts(value) {
647
654
  if (typeof value !== "object" || value === null || Array.isArray(value)) return void 0;
@@ -683,6 +690,8 @@ var AutoContinueRunner = class {
683
690
  this.prioritizedFollowups = /* @__PURE__ */ new Set();
684
691
  this.disposed = false;
685
692
  this.bootScannedSessions = /* @__PURE__ */ new WeakSet();
693
+ /** Also bound diagnostics when even an agent's session getter is unavailable. */
694
+ this.bootScanErrors = /* @__PURE__ */ new WeakSet();
686
695
  this.disposeSessionEvents = ctx.on("session/event", (session, event) => {
687
696
  try {
688
697
  this.onHostEvent(session, event);
@@ -1502,80 +1511,108 @@ var AutoContinueRunner = class {
1502
1511
  const now = Date.now();
1503
1512
  const candidates = [];
1504
1513
  for (const agent of this.ctx.agents.list()) {
1505
- const session = agent.session;
1506
- if (session.header.origin === "subagent" || this.bootScannedSessions.has(session)) continue;
1507
- const state = this.state(session.id);
1508
- if (state.pendingTimer !== void 0 || state.consecutive >= config.maxConsecutive) continue;
1509
- if (now - state.lastAttemptAt < this.cooldownFor(state)) continue;
1510
- if (now < (this.pauseUntil.get(session.id) ?? 0)) continue;
1511
- const events = snapshotSessionEvents(session);
1512
- if (events.length === 0) continue;
1513
- let lastEnd;
1514
- for (let i = events.length - 1; i >= 0; i -= 1) {
1515
- const event = events[i];
1516
- if (event?.type === "turn/end") {
1517
- lastEnd = event;
1518
- break;
1514
+ let session;
1515
+ let sessionId;
1516
+ try {
1517
+ session = agent.session;
1518
+ if (this.bootScannedSessions.has(session) || session.header?.origin === "subagent") continue;
1519
+ sessionId = session.id;
1520
+ if (typeof sessionId !== "string" || sessionId === "") throw new TypeError("session id is unavailable");
1521
+ const state = this.state(sessionId);
1522
+ if (state.pendingTimer !== void 0 || state.consecutive >= config.maxConsecutive) continue;
1523
+ if (now - state.lastAttemptAt < this.cooldownFor(state)) continue;
1524
+ if (now < (this.pauseUntil.get(sessionId) ?? 0)) continue;
1525
+ const events = snapshotSessionEvents(session);
1526
+ if (events.length === 0) continue;
1527
+ let lastEnd;
1528
+ for (let i = events.length - 1; i >= 0; i -= 1) {
1529
+ const event = events[i];
1530
+ if (event?.type === "turn/end") {
1531
+ lastEnd = event;
1532
+ break;
1533
+ }
1519
1534
  }
1520
- }
1521
- const reasonKind = readReasonKind(lastEnd?.data.reason);
1522
- const silent = reasonKind === "no-visible-output" && config.resumeSilentTurns;
1523
- const superseded = lastEnd !== void 0 && events.some(
1524
- (event) => event.seq > lastEnd.seq && (event.type === "turn/start" || event.type === "user/message" && event.data.source.kind === "user")
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) {
1535
+ const reasonKind = readReasonKind(lastEnd?.data.reason);
1536
+ const silent = reasonKind === "no-visible-output" && config.resumeSilentTurns;
1537
+ const superseded = lastEnd !== void 0 && events.some(
1538
+ (event) => event.seq > lastEnd.seq && (event.type === "turn/start" || event.type === "user/message" && event.data.source.kind === "user")
1539
+ );
1540
+ if (lastEnd === void 0 || reasonKind === void 0 || !isNonHumanReason(reasonKind) && !silent || lastEnd.time < now - config.freshMs || superseded) {
1534
1541
  this.bootScannedSessions.add(session);
1535
- console.error(`[auto-continue] 忽略畸形扫描 turn/end ${session.id}: error details 无法解释`);
1536
1542
  continue;
1537
1543
  }
1538
- if (config.classify && !isTransientFailure(failure, config.retryableErrorPatterns)) {
1539
- this.bootScannedSessions.add(session);
1540
- this.onTurnFailure(session.id, "scan:turn/end:error", failure);
1541
- continue;
1544
+ let failure;
1545
+ if (reasonKind === "error") {
1546
+ failure = parseFailureFacts(lastEnd.data.reason.error);
1547
+ if (failure === void 0) {
1548
+ this.bootScannedSessions.add(session);
1549
+ console.error(`[auto-continue] 忽略畸形扫描 turn/end ${sessionId}: error details 无法解释`);
1550
+ continue;
1551
+ }
1552
+ if (config.classify && !isTransientFailure(failure, config.retryableErrorPatterns)) {
1553
+ this.bootScannedSessions.add(session);
1554
+ this.onTurnFailure(sessionId, "scan:turn/end:error", failure);
1555
+ continue;
1556
+ }
1542
1557
  }
1558
+ candidates.push({
1559
+ session,
1560
+ sessionId,
1561
+ events,
1562
+ lastEnd,
1563
+ reasonKind,
1564
+ failure,
1565
+ lastActivityAt: events.reduce((latest, event) => Math.max(latest, event.time), 0),
1566
+ listIndex: candidates.length
1567
+ });
1568
+ } catch (error) {
1569
+ if (session !== null && typeof session === "object") this.bootScannedSessions.add(session);
1570
+ const identity = session ?? agent;
1571
+ if (identity !== null && typeof identity === "object") {
1572
+ if (this.bootScanErrors.has(identity)) continue;
1573
+ this.bootScanErrors.add(identity);
1574
+ }
1575
+ this.logBootScanFailure(sessionId, error);
1543
1576
  }
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
1577
  }
1554
1578
  candidates.sort((left, right) => right.lastActivityAt - left.lastActivityAt || left.listIndex - right.listIndex);
1555
- for (const candidate of candidates.slice(0, config.scanLimit)) {
1579
+ let recoveries = 0;
1580
+ for (const candidate of candidates) {
1581
+ if (recoveries >= config.scanLimit) break;
1556
1582
  if (this.disposed) return true;
1557
- const { session, events, lastEnd, reasonKind, failure } = candidate;
1583
+ const { session, sessionId, events, lastEnd, reasonKind, failure } = candidate;
1558
1584
  this.bootScannedSessions.add(session);
1559
- const state = this.state(session.id);
1560
- this.applyGuardFromEvents(state, events, lastEnd.seq);
1561
- const scanReason = `scan:turn/end:${reasonKind}${reasonKind === "no-visible-output" ? ":silent" : ""}`;
1562
- this.log(`扫描发现中断 ${session.id}(turn/end:${reasonKind}), 交给恢复策略处理`);
1563
- if (failure !== void 0) {
1564
- state.lastFailure = failure;
1565
- state.lastTurn = lastEnd.data.turn;
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;
1585
+ const state = this.state(sessionId);
1586
+ try {
1587
+ this.applyGuardFromEvents(state, events, lastEnd.seq);
1588
+ const scanReason = `scan:turn/end:${reasonKind}${reasonKind === "no-visible-output" ? ":silent" : ""}`;
1589
+ this.log(`扫描发现中断 ${sessionId}(turn/end:${reasonKind}), 交给恢复策略处理`);
1590
+ if (failure !== void 0) {
1591
+ state.lastFailure = failure;
1571
1592
  state.lastTurn = lastEnd.data.turn;
1572
1593
  state.lastFailureAt = lastEnd.time;
1594
+ this.onTurnFailure(sessionId, scanReason, failure);
1595
+ } else {
1596
+ if (reasonKind === "no-visible-output") {
1597
+ state.lastFailure = void 0;
1598
+ state.lastTurn = lastEnd.data.turn;
1599
+ state.lastFailureAt = lastEnd.time;
1600
+ }
1601
+ this.schedule(sessionId, scanReason);
1573
1602
  }
1574
- this.schedule(session.id, scanReason);
1603
+ recoveries += 1;
1604
+ } catch (error) {
1605
+ state.tools.reset();
1606
+ this.cancelPending(sessionId, "启动扫描失败");
1607
+ this.logBootScanFailure(sessionId, error);
1575
1608
  }
1576
1609
  }
1577
1610
  return false;
1578
1611
  }
1612
+ /** Captured identity only: even session.id can throw when the header is damaged. */
1613
+ logBootScanFailure(sessionId, error) {
1614
+ console.error(`[auto-continue] 启动扫描跳过会话 ${sessionId ?? "(id unavailable)"}: ${error instanceof Error ? error.message : String(error)}`);
1615
+ }
1579
1616
  /** 从历史事件恢复上一步工具调用状态(扫描路径的幂等护栏)。 */
1580
1617
  applyGuardFromEvents(state, events, untilSeq) {
1581
1618
  state.tools.restore(events, untilSeq);
@@ -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.1",
4
+ "version": "0.14.2",
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",
50
+ "test": "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": [
@@ -128,9 +128,21 @@ type CompatibleSession = Session & {
128
128
  /** Read one stable event-log snapshot on both legacy and DSH 0.1.2 hosts. */
129
129
  function snapshotSessionEvents(session: Session): readonly SessionEvent[] {
130
130
  const compatible = session as CompatibleSession;
131
- if (typeof compatible.snapshotEvents === 'function') return compatible.snapshotEvents();
132
- if (compatible.events !== undefined) return compatible.events;
133
- throw new TypeError('session exposes neither snapshotEvents() nor events');
131
+ const snapshot = compatible.snapshotEvents;
132
+ const events = typeof snapshot === 'function' ? snapshot.call(session) : compatible.events;
133
+ if (!Array.isArray(events)) throw new TypeError('session history is not an event array');
134
+ // Do not filter damaged entries: one could have been a manual stop, newer turn,
135
+ // or tool result. An incomplete history is not safe evidence for a continuation.
136
+ for (let index = 0; index < events.length; index += 1) {
137
+ const event = events[index];
138
+ if (event === null || typeof event !== 'object' || Array.isArray(event) ||
139
+ typeof event.type !== 'string' || event.type === '' ||
140
+ !Number.isSafeInteger(event.seq) || event.seq < 0 ||
141
+ !Number.isFinite(event.time) || event.time < 0) {
142
+ throw new TypeError(`invalid session event envelope at index ${index}`);
143
+ }
144
+ }
145
+ return events;
134
146
  }
135
147
 
136
148
  /** Interpret host failure payloads without trusting persisted or plugin-provided event shapes. */
@@ -219,6 +231,8 @@ export class AutoContinueRunner {
219
231
  private readonly disposeInboxEvents: () => void;
220
232
  private disposed = false;
221
233
  private readonly bootScannedSessions = new WeakSet<Session>();
234
+ /** Also bound diagnostics when even an agent's session getter is unavailable. */
235
+ private readonly bootScanErrors = new WeakSet<object>();
222
236
  private bootScanTimer: ReturnType<typeof setTimeout> | undefined;
223
237
  private wakeBootScan: (() => void) | undefined;
224
238
 
@@ -1207,6 +1221,7 @@ export class AutoContinueRunner {
1207
1221
  const now = Date.now();
1208
1222
  const candidates: {
1209
1223
  session: Session;
1224
+ sessionId: SessionId;
1210
1225
  events: readonly SessionEvent[];
1211
1226
  lastEnd: SessionEvent<'turn/end'>;
1212
1227
  reasonKind: string;
@@ -1215,78 +1230,109 @@ export class AutoContinueRunner {
1215
1230
  listIndex: number;
1216
1231
  }[] = [];
1217
1232
  for (const agent of this.ctx.agents.list()) {
1218
- const session = agent.session;
1219
- if (session.header.origin === 'subagent' || this.bootScannedSessions.has(session)) continue;
1220
- const state = this.state(session.id);
1221
- if (state.pendingTimer !== undefined || state.consecutive >= config.maxConsecutive) continue;
1222
- if (now - state.lastAttemptAt < this.cooldownFor(state)) continue;
1223
- if (now < (this.pauseUntil.get(session.id) ?? 0)) continue;
1224
- const events = snapshotSessionEvents(session);
1225
- // A published session may still be waiting for its first history snapshot.
1226
- if (events.length === 0) continue;
1227
- let lastEnd: SessionEvent<'turn/end'> | undefined;
1228
- for (let i = events.length - 1; i >= 0; i -= 1) {
1229
- const event = events[i];
1230
- if (event?.type === 'turn/end') { lastEnd = event; break; }
1231
- }
1232
- const reasonKind = readReasonKind(lastEnd?.data.reason);
1233
- const silent = reasonKind === 'no-visible-output' && config.resumeSilentTurns;
1234
- const superseded = lastEnd !== undefined && events.some((event) =>
1235
- event.seq > lastEnd!.seq && (event.type === 'turn/start' ||
1236
- (event.type === 'user/message' && event.data.source.kind === 'user')),
1237
- );
1238
- if (lastEnd === undefined || reasonKind === undefined || (!isNonHumanReason(reasonKind) && !silent) ||
1239
- lastEnd.time < now - config.freshMs || superseded) {
1240
- this.bootScannedSessions.add(session);
1241
- continue;
1242
- }
1243
- let failure: FailureFacts | undefined;
1244
- if (reasonKind === 'error') {
1245
- failure = parseFailureFacts((lastEnd.data.reason as { error?: unknown }).error);
1246
- if (failure === undefined) {
1247
- this.bootScannedSessions.add(session);
1248
- console.error(`[auto-continue] 忽略畸形扫描 turn/end ${session.id}: error details 无法解释`);
1249
- continue;
1233
+ let session: Session | undefined;
1234
+ let sessionId: SessionId | undefined;
1235
+ try {
1236
+ session = agent.session;
1237
+ // Check quarantine before reading metadata that may have failed previously.
1238
+ if (this.bootScannedSessions.has(session) || session.header?.origin === 'subagent') continue;
1239
+ sessionId = session.id;
1240
+ if (typeof sessionId !== 'string' || sessionId === '') throw new TypeError('session id is unavailable');
1241
+ const state = this.state(sessionId);
1242
+ if (state.pendingTimer !== undefined || state.consecutive >= config.maxConsecutive) continue;
1243
+ if (now - state.lastAttemptAt < this.cooldownFor(state)) continue;
1244
+ if (now < (this.pauseUntil.get(sessionId) ?? 0)) continue;
1245
+ const events = snapshotSessionEvents(session);
1246
+ // An empty, valid snapshot may still be waiting for history hydration.
1247
+ if (events.length === 0) continue;
1248
+ let lastEnd: SessionEvent<'turn/end'> | undefined;
1249
+ for (let i = events.length - 1; i >= 0; i -= 1) {
1250
+ const event = events[i];
1251
+ if (event?.type === 'turn/end') { lastEnd = event; break; }
1250
1252
  }
1251
- if (config.classify && !isTransientFailure(failure, config.retryableErrorPatterns)) {
1253
+ const reasonKind = readReasonKind(lastEnd?.data.reason);
1254
+ const silent = reasonKind === 'no-visible-output' && config.resumeSilentTurns;
1255
+ const superseded = lastEnd !== undefined && events.some((event) =>
1256
+ event.seq > lastEnd!.seq && (event.type === 'turn/start' ||
1257
+ (event.type === 'user/message' && event.data.source.kind === 'user')),
1258
+ );
1259
+ if (lastEnd === undefined || reasonKind === undefined || (!isNonHumanReason(reasonKind) && !silent) ||
1260
+ lastEnd.time < now - config.freshMs || superseded) {
1252
1261
  this.bootScannedSessions.add(session);
1253
- this.onTurnFailure(session.id, 'scan:turn/end:error', failure);
1254
1262
  continue;
1255
1263
  }
1264
+ let failure: FailureFacts | undefined;
1265
+ if (reasonKind === 'error') {
1266
+ failure = parseFailureFacts((lastEnd.data.reason as { error?: unknown }).error);
1267
+ if (failure === undefined) {
1268
+ this.bootScannedSessions.add(session);
1269
+ console.error(`[auto-continue] 忽略畸形扫描 turn/end ${sessionId}: error details 无法解释`);
1270
+ continue;
1271
+ }
1272
+ if (config.classify && !isTransientFailure(failure, config.retryableErrorPatterns)) {
1273
+ this.bootScannedSessions.add(session);
1274
+ this.onTurnFailure(sessionId, 'scan:turn/end:error', failure);
1275
+ continue;
1276
+ }
1277
+ }
1278
+ candidates.push({
1279
+ session, sessionId, events, lastEnd, reasonKind, failure,
1280
+ lastActivityAt: events.reduce((latest, event) => Math.max(latest, event.time), 0),
1281
+ listIndex: candidates.length,
1282
+ });
1283
+ } catch (error) {
1284
+ if (session !== null && typeof session === 'object') this.bootScannedSessions.add(session);
1285
+ const identity = session ?? agent;
1286
+ if (identity !== null && typeof identity === 'object') {
1287
+ if (this.bootScanErrors.has(identity)) continue;
1288
+ this.bootScanErrors.add(identity);
1289
+ }
1290
+ this.logBootScanFailure(sessionId, error);
1256
1291
  }
1257
- candidates.push({
1258
- session, events, lastEnd, reasonKind, failure,
1259
- lastActivityAt: events.reduce((latest, event) => Math.max(latest, event.time), 0),
1260
- listIndex: candidates.length,
1261
- });
1262
1292
  }
1263
1293
  // Limit recoveries, not healthy/permanent histories that cannot be resumed.
1264
1294
  candidates.sort((left, right) => right.lastActivityAt - left.lastActivityAt || left.listIndex - right.listIndex);
1265
- for (const candidate of candidates.slice(0, config.scanLimit)) {
1295
+ let recoveries = 0;
1296
+ for (const candidate of candidates) {
1297
+ if (recoveries >= config.scanLimit) break;
1266
1298
  if (this.disposed) return true;
1267
- const { session, events, lastEnd, reasonKind, failure } = candidate;
1299
+ const { session, sessionId, events, lastEnd, reasonKind, failure } = candidate;
1268
1300
  this.bootScannedSessions.add(session);
1269
- const state = this.state(session.id);
1270
- this.applyGuardFromEvents(state, events, lastEnd.seq);
1271
- const scanReason = `scan:turn/end:${reasonKind}${reasonKind === 'no-visible-output' ? ':silent' : ''}`;
1272
- this.log(`扫描发现中断 ${session.id}(turn/end:${reasonKind}), 交给恢复策略处理`);
1273
- if (failure !== undefined) {
1274
- state.lastFailure = failure;
1275
- state.lastTurn = lastEnd.data.turn;
1276
- state.lastFailureAt = lastEnd.time;
1277
- this.onTurnFailure(session.id, scanReason, failure);
1278
- } else {
1279
- if (reasonKind === 'no-visible-output') {
1280
- state.lastFailure = undefined;
1301
+ const state = this.state(sessionId);
1302
+ try {
1303
+ this.applyGuardFromEvents(state, events, lastEnd.seq);
1304
+ const scanReason = `scan:turn/end:${reasonKind}${reasonKind === 'no-visible-output' ? ':silent' : ''}`;
1305
+ this.log(`扫描发现中断 ${sessionId}(turn/end:${reasonKind}), 交给恢复策略处理`);
1306
+ if (failure !== undefined) {
1307
+ state.lastFailure = failure;
1281
1308
  state.lastTurn = lastEnd.data.turn;
1282
1309
  state.lastFailureAt = lastEnd.time;
1310
+ this.onTurnFailure(sessionId, scanReason, failure);
1311
+ } else {
1312
+ if (reasonKind === 'no-visible-output') {
1313
+ state.lastFailure = undefined;
1314
+ state.lastTurn = lastEnd.data.turn;
1315
+ state.lastFailureAt = lastEnd.time;
1316
+ }
1317
+ this.schedule(sessionId, scanReason);
1283
1318
  }
1284
- this.schedule(session.id, scanReason);
1319
+ recoveries += 1;
1320
+ } catch (error) {
1321
+ state.tools.reset();
1322
+ this.cancelPending(sessionId, '启动扫描失败');
1323
+ this.logBootScanFailure(sessionId, error);
1285
1324
  }
1286
1325
  }
1287
1326
  return false;
1288
1327
  }
1289
1328
 
1329
+ /** Captured identity only: even session.id can throw when the header is damaged. */
1330
+ private logBootScanFailure(sessionId: SessionId | undefined, error: unknown): void {
1331
+ console.error(`[auto-continue] 启动扫描跳过会话 ${sessionId ?? '(id unavailable)'}: ${
1332
+ error instanceof Error ? error.message : String(error)
1333
+ }`);
1334
+ }
1335
+
1290
1336
  /** 从历史事件恢复上一步工具调用状态(扫描路径的幂等护栏)。 */
1291
1337
  private applyGuardFromEvents(
1292
1338
  state: SessionState,