dsh-agent-enhancer 0.5.0 → 0.5.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/lib/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/host/index.ts
2
- import { existsSync as existsSync20, mkdirSync as mkdirSync15, readdirSync as readdirSync7, renameSync as renameSync11, rmdirSync } from "node:fs";
2
+ import { existsSync as existsSync21, mkdirSync as mkdirSync15, readdirSync as readdirSync7, renameSync as renameSync11, rmdirSync } from "node:fs";
3
3
  import { homedir as homedir5 } from "node:os";
4
4
  import { join as join33 } from "node:path";
5
5
  import z5 from "@deepseek-ai/schemastery";
@@ -20352,6 +20352,7 @@ async function showOsNotificationNow(input) {
20352
20352
  }
20353
20353
 
20354
20354
  // src/host/remote/hub.ts
20355
+ import { appendFileSync, existsSync as existsSync20 } from "node:fs";
20355
20356
  import { join as join32 } from "node:path";
20356
20357
 
20357
20358
  // src/host/remote/bindings.ts
@@ -21056,6 +21057,19 @@ var RemoteController = class {
21056
21057
  }
21057
21058
  return false;
21058
21059
  }
21060
+ /**
21061
+ * Another surface (the desktop card) resolved this ask: drop its remote card
21062
+ * and waiter so the remote chat cannot approve an already-finished decision.
21063
+ */
21064
+ dropPending(code) {
21065
+ this.approvalWaiters.delete(code);
21066
+ this.questionWaiters.delete(code);
21067
+ for (const [approvalId, pendingCode] of this.codeByApprovalId) {
21068
+ if (pendingCode === code) this.codeByApprovalId.delete(approvalId);
21069
+ }
21070
+ const task = this.board.list().find((entry) => entry.pending?.code === code);
21071
+ if (task !== void 0) this.board.clearPending(task.id);
21072
+ }
21059
21073
  /** Drop expired codes so the board does not keep stale cards. */
21060
21074
  expire(at = this.now()) {
21061
21075
  const dropped = this.board.expire(at);
@@ -21122,7 +21136,7 @@ var RemoteController = class {
21122
21136
  return task === void 0 ? { text: "\u4EFB\u52A1\u5DF2\u4E0D\u5B58\u5728\u3002\u56DE\u300C\u4EFB\u52A1\u300D\u770B\u5217\u8868\u3002" } : this.focusedReply(task, capabilities, at);
21123
21137
  }
21124
21138
  if (command.kind === "approve" || command.kind === "reject") {
21125
- return this.decide(command.kind, command.code, at);
21139
+ return this.decide(command.kind, command.code, at, chatId);
21126
21140
  }
21127
21141
  if (command.kind === "answer") {
21128
21142
  const route = routeAnswer(this.board.list(), command, at);
@@ -21132,6 +21146,7 @@ var RemoteController = class {
21132
21146
  const waiter = this.questionWaiters.get(route.pending.code);
21133
21147
  this.questionWaiters.delete(route.pending.code);
21134
21148
  waiter?.(route.text);
21149
+ this.options.onDecision?.({ chatId, sessionId: route.taskId, decision: "answered" });
21135
21150
  return { text: `\u5DF2\u56DE\u590D\u3010${this.numbers.get(route.taskId) ?? 0}\u3011${this.taskTitle(route.taskId)}` };
21136
21151
  }
21137
21152
  if (command.kind === "pause" || command.kind === "resume") {
@@ -21192,7 +21207,7 @@ var RemoteController = class {
21192
21207
  const buttons = taskActionButtons(task);
21193
21208
  return buttons.length === 0 ? { text: text3 } : { text: text3, buttons };
21194
21209
  }
21195
- decide(kind, code, at) {
21210
+ decide(kind, code, at, chatId) {
21196
21211
  const tasks = this.board.list();
21197
21212
  const route = kind === "approve" ? routeDecision(tasks, code === void 0 ? { kind: "approve" } : { kind: "approve", code }, at) : routeDecision(tasks, code === void 0 ? { kind: "reject" } : { kind: "reject", code }, at);
21198
21213
  if (!route.ok) return { text: this.routeFailureText(route.reason, route.codes) };
@@ -21201,6 +21216,7 @@ var RemoteController = class {
21201
21216
  const waiter = this.approvalWaiters.get(route.pending.code);
21202
21217
  this.approvalWaiters.delete(route.pending.code);
21203
21218
  if (route.pending.kind === "approval") waiter?.(route.decision);
21219
+ this.options.onDecision?.({ chatId, sessionId: route.taskId, decision: route.decision });
21204
21220
  const label = route.decision === "approve" ? "\u5DF2\u6279\u51C6" : "\u5DF2\u62D2\u7EDD";
21205
21221
  return { text: `${label}\u3010${this.numbers.get(route.taskId) ?? 0}\u3011${this.taskTitle(route.taskId)}` };
21206
21222
  }
@@ -21323,25 +21339,57 @@ function pickAnswer(labels, text3) {
21323
21339
  const match = labels.find((label) => label.trim() === text3.trim());
21324
21340
  return match === void 0 ? { selected: [], custom: text3 } : { selected: [match] };
21325
21341
  }
21342
+ function never() {
21343
+ return new Promise(() => {
21344
+ });
21345
+ }
21346
+ function hasAnswer(value) {
21347
+ if (value === null || typeof value !== "object") return false;
21348
+ const answers = value.answers;
21349
+ if (!Array.isArray(answers)) return false;
21350
+ return answers.some((item) => {
21351
+ if (item === null || typeof item !== "object") return false;
21352
+ const record2 = item;
21353
+ return Array.isArray(record2.selected) && record2.selected.length > 0 || typeof record2.custom === "string" && record2.custom.trim() !== "";
21354
+ });
21355
+ }
21356
+ function callNext(next) {
21357
+ let result;
21358
+ try {
21359
+ result = next();
21360
+ } catch {
21361
+ return void 0;
21362
+ }
21363
+ if (result === null || typeof result !== "object") return void 0;
21364
+ const then = result.then;
21365
+ return typeof then === "function" ? result : void 0;
21366
+ }
21326
21367
  function installRemoteHostBridge(ctx, options) {
21368
+ const notify = (notice) => {
21369
+ options.debugLog?.(JSON.stringify({ kind: notice.kind, sessionId: notice.sessionId }));
21370
+ try {
21371
+ options.ports.notify?.(notice);
21372
+ } catch {
21373
+ }
21374
+ };
21327
21375
  const controller = new RemoteController({
21328
21376
  actions: {
21329
21377
  sendPrompt: (sessionId, text3) => options.ports.prompt(sessionId, text3, "queue"),
21330
21378
  setPaused: (sessionId, paused) => options.ports.setPaused(sessionId, paused),
21331
21379
  stop: (sessionId) => options.ports.cancel(sessionId)
21332
21380
  },
21381
+ onDecision: (info) => notify({
21382
+ kind: "decided",
21383
+ sessionId: info.sessionId,
21384
+ decision: info.decision,
21385
+ chatId: info.chatId
21386
+ }),
21333
21387
  ...options.ports.readAnswer === void 0 ? {} : { readAnswer: options.ports.readAnswer },
21334
21388
  ...options.now === void 0 ? {} : { now: options.now },
21335
21389
  ...options.ttlMs === void 0 ? {} : { ttlMs: options.ttlMs }
21336
21390
  });
21337
21391
  const known = (sessionId) => controller.tasks().some((task) => task.id === sessionId);
21338
21392
  const lastAssistant = /* @__PURE__ */ new Map();
21339
- const notify = (notice) => {
21340
- try {
21341
- options.ports.notify?.(notice);
21342
- } catch {
21343
- }
21344
- };
21345
21393
  let refreshing;
21346
21394
  let lastEventRefresh = 0;
21347
21395
  const refreshSessions = async () => {
@@ -21422,10 +21470,14 @@ function installRemoteHostBridge(ctx, options) {
21422
21470
  }
21423
21471
  };
21424
21472
  const canAnswer = () => options.shouldHold?.() !== false;
21425
- const onApprovalRequest = (request, next) => {
21473
+ const onApprovalRequest = async (request, next) => {
21426
21474
  if (!canAnswer()) return next();
21427
21475
  const sessionId = sessionIdOf2(request?.agent);
21428
- if (sessionId === void 0 || !known(sessionId)) return next();
21476
+ if (sessionId === void 0) return next();
21477
+ if (!known(sessionId)) {
21478
+ await refreshSessions().catch(() => 0);
21479
+ if (!known(sessionId)) return next();
21480
+ }
21429
21481
  try {
21430
21482
  const handle = controller.askApproval(sessionId, {
21431
21483
  prompt: describeApproval(request),
@@ -21433,15 +21485,32 @@ function installRemoteHostBridge(ctx, options) {
21433
21485
  risk: "other"
21434
21486
  });
21435
21487
  notify({ kind: "approval", sessionId, code: handle.code });
21436
- return handle.wait;
21488
+ const remote = handle.wait.then((decision) => decision === "approve" ? "allowed-once" : "rejected");
21489
+ const desktop = callNext(next);
21490
+ if (desktop === void 0) return remote;
21491
+ const fromDesktop = Promise.resolve(desktop).then(
21492
+ (outcome) => {
21493
+ if (outcome !== "allowed-once" && outcome !== "rejected") return never();
21494
+ controller.dropPending(handle.code);
21495
+ const decision = outcome === "allowed-once" ? "approve" : "reject";
21496
+ notify({ kind: "decided", sessionId, decision });
21497
+ return outcome;
21498
+ },
21499
+ () => never()
21500
+ );
21501
+ return Promise.race([remote, fromDesktop]);
21437
21502
  } catch {
21438
21503
  return next();
21439
21504
  }
21440
21505
  };
21441
- const onQuestionRequest = (request, next) => {
21506
+ const onQuestionRequest = async (request, next) => {
21442
21507
  if (!canAnswer()) return next();
21443
21508
  const sessionId = sessionIdOf2(request?.agent) ?? (typeof request?.sessionId === "string" ? request.sessionId : void 0);
21444
- if (sessionId === void 0 || !known(sessionId)) return next();
21509
+ if (sessionId === void 0) return next();
21510
+ if (!known(sessionId)) {
21511
+ await refreshSessions().catch(() => 0);
21512
+ if (!known(sessionId)) return next();
21513
+ }
21445
21514
  const questions = Array.isArray(request.questions) ? request.questions : [];
21446
21515
  if (questions.length !== 1) return next();
21447
21516
  const question = questions[0];
@@ -21456,9 +21525,21 @@ function installRemoteHostBridge(ctx, options) {
21456
21525
  ...labels.length === 0 ? {} : { options: labels }
21457
21526
  });
21458
21527
  notify({ kind: "question", sessionId, code: handle.code });
21459
- return handle.wait.then((text3) => ({
21528
+ const remote = handle.wait.then((text3) => ({
21460
21529
  answers: [{ id: questionId, ...pickAnswer(labels, text3) }]
21461
21530
  }));
21531
+ const desktop = callNext(next);
21532
+ if (desktop === void 0) return remote;
21533
+ const fromDesktop = Promise.resolve(desktop).then(
21534
+ (answer) => {
21535
+ if (!hasAnswer(answer)) return never();
21536
+ controller.dropPending(handle.code);
21537
+ notify({ kind: "decided", sessionId, decision: "answered" });
21538
+ return answer;
21539
+ },
21540
+ () => never()
21541
+ );
21542
+ return Promise.race([remote, fromDesktop]);
21462
21543
  } catch {
21463
21544
  return next();
21464
21545
  }
@@ -21705,6 +21786,7 @@ var ChannelPoller = class {
21705
21786
  }
21706
21787
  }
21707
21788
  async handle(message) {
21789
+ this.options.onInbound?.();
21708
21790
  const chatId = message.fromUserId;
21709
21791
  if (message.contextToken !== void 0 && message.contextToken !== "") {
21710
21792
  this.contexts.set(chatId, message.contextToken);
@@ -22099,6 +22181,10 @@ var TelegramChannel = class {
22099
22181
  this.credentialsValue = void 0;
22100
22182
  this.phaseValue = "off";
22101
22183
  }
22184
+ /** A proactive push failed: inbound can still work, but the UI must say so. */
22185
+ reportSendError(error) {
22186
+ this.errorValue = error.code === "network-error" ? "\u63A8\u9001\u53D7\u9650\uFF1A\u6682\u65F6\u8FDE\u4E0D\u4E0A Telegram API\uFF0C\u6D88\u606F\u672A\u53D1\u51FA\u3002" : `\u63A8\u9001\u5931\u8D25\uFF1A${messageOf(error)}`;
22187
+ }
22102
22188
  async send(chatId, text3, buttons) {
22103
22189
  const credentials = this.credentialsValue;
22104
22190
  if (this.phaseValue !== "running" || credentials === void 0) return;
@@ -22675,6 +22761,10 @@ var FeishuChannel = class {
22675
22761
  this.credentialsValue = void 0;
22676
22762
  this.phaseValue = "off";
22677
22763
  }
22764
+ /** A proactive push failed: keep the connection, surface the reason. */
22765
+ reportSendError(error) {
22766
+ this.errorValue = `\u63A8\u9001\u5931\u8D25\uFF1A${messageOf2(error)}`;
22767
+ }
22678
22768
  async send(chatId, text3, buttons) {
22679
22769
  const credentials = this.credentialsValue;
22680
22770
  if (this.phaseValue !== "running" || credentials === void 0) return;
@@ -23134,6 +23224,7 @@ var WeixinAdapter = class {
23134
23224
  ...options.refresh === void 0 ? {} : { refresh: options.refresh },
23135
23225
  ...options.emptyPageDelayMs === void 0 ? {} : { emptyPageDelayMs: options.emptyPageDelayMs },
23136
23226
  isFatal: (error) => error instanceof WeixinTransportError && error.code === "stale-token",
23227
+ ...options.onInbound === void 0 ? {} : { onInbound: options.onInbound },
23137
23228
  hints: WEIXIN_HINTS
23138
23229
  });
23139
23230
  }
@@ -23283,11 +23374,26 @@ var WeixinChannel = class {
23283
23374
  credentialsValue;
23284
23375
  phaseValue = "off";
23285
23376
  errorValue;
23377
+ /** Timestamp of the last inbound message: WeChat push rights come from it. */
23378
+ lastInboundAt = 0;
23286
23379
  /** Bumped by stop/logout so an in-flight scan result cannot reconnect. */
23287
23380
  generation = 0;
23288
23381
  get running() {
23289
23382
  return this.phaseValue === "running";
23290
23383
  }
23384
+ /** Timestamp of the last inbound message that renewed WeChat push rights. */
23385
+ get lastInbound() {
23386
+ return this.lastInboundAt;
23387
+ }
23388
+ /** Warn before the user walks away; a fresh inbound message clears it. */
23389
+ reportStale() {
23390
+ this.errorValue = "\u63A8\u9001\u53EF\u80FD\u5DF2\u8FC7\u671F\uFF1A\u79BB\u5F00\u7535\u8111\u524D\u7ED9\u673A\u5668\u4EBA\u53D1\u4E00\u6761\u6D88\u606F\uFF0C\u5426\u5219\u5BA1\u6279 / \u56DE\u7B54\u63A8\u4E0D\u5230\u5FAE\u4FE1\u3002";
23391
+ }
23392
+ /** A proactive push failed: keep inbound alive but make the reason visible. */
23393
+ reportSendError(error) {
23394
+ const providerCode = error.detail?.providerCode;
23395
+ this.errorValue = providerCode === "-2" ? "\u63A8\u9001\u53D7\u9650\uFF1A\u5FAE\u4FE1\u4F1A\u8BDD\u5DF2\u8FC7\u671F\u3002\u5728\u5FAE\u4FE1\u91CC\u7ED9\u673A\u5668\u4EBA\u53D1\u4E00\u6761\u6D88\u606F\u5373\u53EF\u6062\u590D\u3002" : `\u63A8\u9001\u5931\u8D25\uFF1A${messageOf3(error)}`;
23396
+ }
23291
23397
  status() {
23292
23398
  const devices = this.options.bindings.list().filter((binding) => binding.channel === this.id).map((binding) => ({ chatId: binding.chatId, boundAt: binding.boundAt }));
23293
23399
  return {
@@ -23362,6 +23468,9 @@ var WeixinChannel = class {
23362
23468
  contextToken === void 0 ? {} : { contextToken }
23363
23469
  );
23364
23470
  }
23471
+ if (this.errorValue?.startsWith("\u63A8\u9001\u53D7\u9650") === true || this.errorValue?.startsWith("\u63A8\u9001\u53EF\u80FD\u5DF2\u8FC7\u671F") === true) {
23472
+ this.errorValue = void 0;
23473
+ }
23365
23474
  }
23366
23475
  contextFor(chatId) {
23367
23476
  return this.adapter?.contextFor(chatId);
@@ -23386,6 +23495,12 @@ var WeixinChannel = class {
23386
23495
  capabilities: this.options.capabilities,
23387
23496
  cursor,
23388
23497
  refresh: this.options.refresh,
23498
+ onInbound: () => {
23499
+ this.lastInboundAt = Date.now();
23500
+ if (this.errorValue?.startsWith("\u63A8\u9001\u53D7\u9650") === true || this.errorValue?.startsWith("\u63A8\u9001\u53EF\u80FD\u5DF2\u8FC7\u671F") === true) {
23501
+ this.errorValue = void 0;
23502
+ }
23503
+ },
23389
23504
  ...this.options.emptyPageDelayMs === void 0 ? {} : { emptyPageDelayMs: this.options.emptyPageDelayMs },
23390
23505
  onError: (error) => this.options.onError?.(error),
23391
23506
  onFatal: (error) => {
@@ -23521,6 +23636,7 @@ var RemoteHub = class {
23521
23636
  retryTimer;
23522
23637
  retries = 0;
23523
23638
  generation = 0;
23639
+ lastWechatWarnAt = 0;
23524
23640
  weixinCapabilities;
23525
23641
  telegramCapabilities;
23526
23642
  feishuCapabilities;
@@ -23534,6 +23650,7 @@ var RemoteHub = class {
23534
23650
  return this.weixin?.running === true || this.telegram?.running === true || this.feishu?.running === true;
23535
23651
  }
23536
23652
  status() {
23653
+ this.checkWechatFreshness();
23537
23654
  const weixin = this.weixin;
23538
23655
  const telegram = this.telegram;
23539
23656
  const feishu = this.feishu;
@@ -23584,7 +23701,13 @@ var RemoteHub = class {
23584
23701
  this.bridge = installRemoteHostBridge(this.options.ctx, {
23585
23702
  ports,
23586
23703
  capabilities: this.weixinCapabilities,
23587
- shouldHold: () => bindings.list().length > 0 && this.anyRunning()
23704
+ shouldHold: () => bindings.list().length > 0 && this.anyRunning(),
23705
+ debugLog: (line) => {
23706
+ try {
23707
+ this.debugNotice({ stage: "bridge", detail: JSON.parse(line) });
23708
+ } catch {
23709
+ }
23710
+ }
23588
23711
  });
23589
23712
  this.controller = this.bridge.controller;
23590
23713
  try {
@@ -23728,6 +23851,42 @@ var RemoteHub = class {
23728
23851
  }
23729
23852
  this.phaseValue = channels.length > 0 && channels.every((channel) => channel.status().phase === "failed") ? "failed" : "unbound";
23730
23853
  }
23854
+ /**
23855
+ * WeChat only allows proactive sends while a recent inbound message has
23856
+ * renewed the session. Warn while the user is still at the desktop instead
23857
+ * of failing silently after they walk away.
23858
+ */
23859
+ checkWechatFreshness() {
23860
+ const weixin = this.weixin;
23861
+ if (weixin === void 0 || !weixin.running) return;
23862
+ if (!(this.bindings?.list().some((binding) => binding.channel === "weixin") ?? false)) return;
23863
+ const last = weixin.lastInbound;
23864
+ if (last === 0 || Date.now() - last < 2 * 60 * 6e4) return;
23865
+ weixin.reportStale();
23866
+ this.warnWechatStale("idle");
23867
+ }
23868
+ warnWechatStale(reason) {
23869
+ const now = Date.now();
23870
+ if (now - this.lastWechatWarnAt < 12 * 60 * 6e4) return;
23871
+ this.lastWechatWarnAt = now;
23872
+ this.options.desktopNotify?.({
23873
+ title: "\u5FAE\u4FE1\u8FDC\u7A0B\u63A8\u9001\u53EF\u80FD\u6536\u4E0D\u5230",
23874
+ body: reason === "expired" ? "\u5FAE\u4FE1\u4F1A\u8BDD\u5DF2\u8FC7\u671F\u3002\u79BB\u5F00\u7535\u8111\u524D\u7ED9\u673A\u5668\u4EBA\u53D1\u4E00\u6761\u6D88\u606F\uFF0C\u5426\u5219\u5BA1\u6279\u548C\u56DE\u7B54\u63A8\u4E0D\u5230\u5FAE\u4FE1\u3002" : "\u8D85\u8FC7 2 \u5C0F\u65F6\u6CA1\u6709\u5FAE\u4FE1\u6D88\u606F\u3002\u79BB\u5F00\u7535\u8111\u524D\u7ED9\u673A\u5668\u4EBA\u53D1\u4E00\u6761\u6D88\u606F\uFF0C\u786E\u4FDD\u8FD8\u80FD\u6536\u5230\u5BA1\u6279\u3002",
23875
+ tag: "remote-wechat-stale"
23876
+ });
23877
+ }
23878
+ /** Opt-in diagnostics: create `remote/debug-notices.enabled` in plugin-data. */
23879
+ debugNotice(entry) {
23880
+ try {
23881
+ if (!existsSync20(join32(this.options.rootDir, "debug-notices.enabled"))) return;
23882
+ appendFileSync(
23883
+ join32(this.options.rootDir, "notice-log.jsonl"),
23884
+ `${JSON.stringify({ at: Date.now(), ...entry })}
23885
+ `
23886
+ );
23887
+ } catch {
23888
+ }
23889
+ }
23731
23890
  /** Send one notice to every paired chat on a channel that can answer. */
23732
23891
  pushNotice(notice) {
23733
23892
  const controller = this.controller;
@@ -23747,6 +23906,14 @@ ${clip2(notice.error, 300)}`;
23747
23906
  if (answer !== "") text3 += `
23748
23907
 
23749
23908
  ${answer}`;
23909
+ }
23910
+ if (notice.kind === "decided") {
23911
+ const channel2 = notice.chatId === void 0 ? void 0 : this.bindings?.binding(notice.chatId)?.channel;
23912
+ const where = channel2 === void 0 ? "\u684C\u9762" : channel2 === "weixin" ? "\u5FAE\u4FE1" : channel2 === "telegram" ? "Telegram" : "\u98DE\u4E66";
23913
+ const verb = notice.decision === "approve" ? "\u6279\u51C6" : notice.decision === "reject" ? "\u62D2\u7EDD" : "\u56DE\u7B54";
23914
+ text3 += `
23915
+
23916
+ \u5DF2\u7531${where}${verb}`;
23750
23917
  }
23751
23918
  const task = controller.tasks().find((entry) => entry.id === notice.sessionId);
23752
23919
  const pending = task?.pending;
@@ -23766,11 +23933,42 @@ ${answer}`;
23766
23933
  command: `\u56DE\u7B54 ${pending.code} ${option}`
23767
23934
  }));
23768
23935
  }
23769
- } else if (notice.kind === "done" || notice.kind === "failed") {
23936
+ } else if (notice.kind === "done" || notice.kind === "failed" || notice.kind === "decided") {
23770
23937
  buttons = [{ label: "\u8BE6\u60C5", command: number === void 0 ? "\u8BE6\u60C5" : `\u8BE6\u60C5 ${number}` }];
23771
23938
  }
23772
23939
  }
23773
- void channel.send(binding.chatId, text3, buttons).catch((error) => this.options.onError?.(error));
23940
+ this.debugNotice({
23941
+ stage: "queued",
23942
+ kind: notice.kind,
23943
+ channel: binding.channel,
23944
+ chatId: binding.chatId,
23945
+ sessionId: notice.sessionId
23946
+ });
23947
+ void channel.send(binding.chatId, text3, buttons).then(() => {
23948
+ this.debugNotice({
23949
+ stage: "sent",
23950
+ kind: notice.kind,
23951
+ channel: binding.channel,
23952
+ chatId: binding.chatId,
23953
+ sessionId: notice.sessionId
23954
+ });
23955
+ }).catch((error) => {
23956
+ this.debugNotice({
23957
+ stage: "error",
23958
+ kind: notice.kind,
23959
+ channel: binding.channel,
23960
+ chatId: binding.chatId,
23961
+ sessionId: notice.sessionId,
23962
+ error: messageOf4(error),
23963
+ code: error.code,
23964
+ detail: error.detail
23965
+ });
23966
+ channel.reportSendError(error);
23967
+ if (binding.channel === "weixin" && error.detail?.providerCode === "-2") {
23968
+ this.warnWechatStale("expired");
23969
+ }
23970
+ this.options.onError?.(error);
23971
+ });
23774
23972
  }
23775
23973
  }
23776
23974
  scheduleRetry() {
@@ -24884,12 +25082,12 @@ function resolveCheckpointRoot(dshHome2) {
24884
25082
  const nextPkg = join33(base, PACKAGE_NAME);
24885
25083
  const next = join33(nextPkg, "checkpoint");
24886
25084
  const prev = join33(base, LEGACY_PACKAGE_NAME, "checkpoint");
24887
- if (!existsSync20(next) && existsSync20(prev)) {
25085
+ if (!existsSync21(next) && existsSync21(prev)) {
24888
25086
  mkdirSync15(nextPkg, { recursive: true });
24889
25087
  renameSync11(prev, next);
24890
25088
  const prevPkg = join33(base, LEGACY_PACKAGE_NAME);
24891
25089
  try {
24892
- if (existsSync20(prevPkg) && readdirSync7(prevPkg).length === 0) rmdirSync(prevPkg);
25090
+ if (existsSync21(prevPkg) && readdirSync7(prevPkg).length === 0) rmdirSync(prevPkg);
24893
25091
  } catch {
24894
25092
  }
24895
25093
  }
@@ -25095,6 +25293,10 @@ function apply(ctx, config) {
25095
25293
  onError: (error) => {
25096
25294
  const detail = error instanceof Error ? error.message : String(error);
25097
25295
  ctx.logger.warn(`agent-enhancer: remote control: ${detail}`);
25296
+ },
25297
+ desktopNotify: (input) => {
25298
+ void showOsNotificationNow(input).catch(() => {
25299
+ });
25098
25300
  }
25099
25301
  });
25100
25302
  let remoteRunning = false;