@keyou007/agent-bot 0.1.13-alpha.0 → 0.1.13-alpha.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.
Files changed (97) hide show
  1. package/.env.example +2 -2
  2. package/CHANGELOG.md +15 -0
  3. package/README.md +107 -98
  4. package/README.zh.md +81 -72
  5. package/dist/acp/AcpProcessManager.js +8 -3
  6. package/dist/acp/AcpProcessManager.js.map +1 -1
  7. package/dist/acp/AcpSessionManager.js +15 -0
  8. package/dist/acp/AcpSessionManager.js.map +1 -1
  9. package/dist/cli/ServerStarter.js +17 -2
  10. package/dist/cli/ServerStarter.js.map +1 -1
  11. package/dist/cli/controlProtocol.js.map +1 -1
  12. package/dist/cli/help.js +16 -4
  13. package/dist/cli/help.js.map +1 -1
  14. package/dist/cli/serverStatus.js +27 -0
  15. package/dist/cli/serverStatus.js.map +1 -1
  16. package/dist/cli/taskListOutput.js +72 -0
  17. package/dist/cli/taskListOutput.js.map +1 -0
  18. package/dist/cli.js +88 -54
  19. package/dist/cli.js.map +1 -1
  20. package/dist/codex/CodexProcessManager.js +34 -4
  21. package/dist/codex/CodexProcessManager.js.map +1 -1
  22. package/dist/codex/CodexRuntime.js +3 -0
  23. package/dist/codex/CodexRuntime.js.map +1 -1
  24. package/dist/commands/CommandRouter.js +5 -0
  25. package/dist/commands/CommandRouter.js.map +1 -1
  26. package/dist/config/FeishuUserOpenIdStore.js +76 -0
  27. package/dist/config/FeishuUserOpenIdStore.js.map +1 -0
  28. package/dist/config/loadConfig.js +3 -0
  29. package/dist/config/loadConfig.js.map +1 -1
  30. package/dist/feishu/CardRenderer.js +123 -22
  31. package/dist/feishu/CardRenderer.js.map +1 -1
  32. package/dist/feishu/FeishuConnector.js +16 -5
  33. package/dist/feishu/FeishuConnector.js.map +1 -1
  34. package/dist/index.js +125 -26
  35. package/dist/index.js.map +1 -1
  36. package/dist/presentation/turnGraph.js +36 -0
  37. package/dist/presentation/turnGraph.js.map +1 -0
  38. package/dist/proxy/ProxySessionController.js +425 -104
  39. package/dist/proxy/ProxySessionController.js.map +1 -1
  40. package/dist/runtime/AcpRuntimeAdapter.js +3 -0
  41. package/dist/runtime/AcpRuntimeAdapter.js.map +1 -1
  42. package/dist/runtime/agentEnvironment.js +24 -4
  43. package/dist/runtime/agentEnvironment.js.map +1 -1
  44. package/dist/runtime/createAgentRuntimeRegistry.js +7 -3
  45. package/dist/runtime/createAgentRuntimeRegistry.js.map +1 -1
  46. package/dist/startup/StartupNotifier.js +16 -7
  47. package/dist/startup/StartupNotifier.js.map +1 -1
  48. package/dist/startup/startFeishu.js +2 -2
  49. package/dist/startup/startFeishu.js.map +1 -1
  50. package/dist/state/StateStore.js +172 -0
  51. package/dist/state/StateStore.js.map +1 -1
  52. package/dist/state/migrations.js +21 -0
  53. package/dist/state/migrations.js.map +1 -1
  54. package/dist/supervision/SafeRestartNotifier.js +46 -3
  55. package/dist/supervision/SafeRestartNotifier.js.map +1 -1
  56. package/dist/supervision/SafeRestartScheduler.js +65 -6
  57. package/dist/supervision/SafeRestartScheduler.js.map +1 -1
  58. package/dist/supervision/replacementSupervisor.js +27 -2
  59. package/dist/supervision/replacementSupervisor.js.map +1 -1
  60. package/dist/supervisor.js +27 -2
  61. package/dist/supervisor.js.map +1 -1
  62. package/docs/technical-reference.md +20 -7
  63. package/docs/technical-reference.zh.md +20 -7
  64. package/npm-shrinkwrap.json +2 -2
  65. package/package.json +1 -1
  66. package/skills/agent-bot/SKILL.md +63 -26
  67. package/src/acp/AcpProcessManager.ts +16 -3
  68. package/src/acp/AcpSessionManager.ts +14 -0
  69. package/src/cli/ServerStarter.ts +25 -2
  70. package/src/cli/controlProtocol.ts +6 -1
  71. package/src/cli/help.ts +16 -4
  72. package/src/cli/serverStatus.ts +28 -0
  73. package/src/cli/taskListOutput.ts +91 -0
  74. package/src/cli.ts +123 -51
  75. package/src/codex/CodexProcessManager.ts +38 -3
  76. package/src/codex/CodexRuntime.ts +6 -0
  77. package/src/commands/CommandRouter.ts +4 -0
  78. package/src/commands/commandTypes.ts +1 -0
  79. package/src/config/FeishuUserOpenIdStore.ts +81 -0
  80. package/src/config/loadConfig.ts +3 -0
  81. package/src/feishu/CardRenderer.ts +169 -22
  82. package/src/feishu/FeishuConnector.ts +13 -4
  83. package/src/index.ts +195 -23
  84. package/src/presentation/turnGraph.ts +48 -0
  85. package/src/proxy/ProxySessionController.ts +507 -112
  86. package/src/runtime/AcpRuntimeAdapter.ts +5 -0
  87. package/src/runtime/agentEnvironment.ts +41 -3
  88. package/src/runtime/createAgentRuntimeRegistry.ts +18 -3
  89. package/src/runtime/types.ts +5 -0
  90. package/src/startup/StartupNotifier.ts +23 -7
  91. package/src/startup/startFeishu.ts +3 -2
  92. package/src/state/StateStore.ts +224 -0
  93. package/src/state/migrations.ts +21 -0
  94. package/src/supervision/SafeRestartNotifier.ts +53 -4
  95. package/src/supervision/SafeRestartScheduler.ts +78 -7
  96. package/src/supervision/replacementSupervisor.ts +27 -1
  97. package/src/supervisor.ts +33 -2
@@ -1,3 +1,4 @@
1
+ import { isThreadContextKey } from "../feishu/contextKey.js";
1
2
  const DEFAULT_INITIAL_CARD_DELAY_MS = 3_000;
2
3
  export class SafeRestartNotifier {
3
4
  store;
@@ -7,6 +8,7 @@ export class SafeRestartNotifier {
7
8
  options;
8
9
  messageIds = new Map();
9
10
  cardHashes = new Map();
11
+ notificationTargets = new Map();
10
12
  activeScheduleId;
11
13
  terminalScheduleId;
12
14
  pendingInitialStatus;
@@ -34,8 +36,10 @@ export class SafeRestartNotifier {
34
36
  this.activeScheduleId = status.scheduleId;
35
37
  this.messageIds.clear();
36
38
  this.cardHashes.clear();
39
+ this.notificationTargets.clear();
37
40
  this.clearInitialCardTimer();
38
41
  this.pendingInitialStatus = status;
42
+ this.collectNotificationTargets(status);
39
43
  const delayMs = status.phase === "cancelled"
40
44
  ? 0
41
45
  : this.options.initialCardDelayMs ?? DEFAULT_INITIAL_CARD_DELAY_MS;
@@ -49,6 +53,7 @@ export class SafeRestartNotifier {
49
53
  }, delayMs);
50
54
  return Promise.resolve();
51
55
  }
56
+ this.collectNotificationTargets(status);
52
57
  if (this.pendingInitialStatus) {
53
58
  this.pendingInitialStatus = status;
54
59
  return Promise.resolve();
@@ -59,6 +64,9 @@ export class SafeRestartNotifier {
59
64
  await this.publishPendingInitialStatus();
60
65
  await this.queue;
61
66
  }
67
+ getNotificationTargets() {
68
+ return [...this.notificationTargets.values()].map((target) => ({ ...target }));
69
+ }
62
70
  publishPendingInitialStatus() {
63
71
  this.clearInitialCardTimer();
64
72
  const status = this.pendingInitialStatus;
@@ -80,7 +88,8 @@ export class SafeRestartNotifier {
80
88
  this.initialCardTimer = undefined;
81
89
  }
82
90
  async publish(status) {
83
- const targets = this.store.listChatContexts("p2p");
91
+ this.collectNotificationTargets(status);
92
+ const targets = this.getNotificationTargets();
84
93
  if (targets.length === 0)
85
94
  return;
86
95
  const waitingTasks = status.phase === "cancelled"
@@ -100,7 +109,7 @@ export class SafeRestartNotifier {
100
109
  waitingTasks,
101
110
  });
102
111
  const cardHash = JSON.stringify(card);
103
- await Promise.all(targets.map(async ({ contextKey }) => {
112
+ await Promise.all(targets.map(async ({ contextKey, replyMessageId }) => {
104
113
  const messageId = this.messageIds.get(contextKey);
105
114
  if (messageId) {
106
115
  if (this.cardHashes.get(contextKey) === cardHash)
@@ -117,7 +126,19 @@ export class SafeRestartNotifier {
117
126
  }
118
127
  }
119
128
  try {
120
- const created = await this.outbound.sendInteractiveCard(contextKey, card);
129
+ let created;
130
+ if (isThreadContextKey(contextKey) && !replyMessageId) {
131
+ throw new Error("The safe-restart topic target has no reply message anchor.");
132
+ }
133
+ if (replyMessageId) {
134
+ if (!this.outbound.replyInteractiveCard) {
135
+ throw new Error("The outbound transport cannot preserve the requesting thread.");
136
+ }
137
+ created = await this.outbound.replyInteractiveCard(contextKey, { messageId: replyMessageId, replyInThread: true }, card);
138
+ }
139
+ else {
140
+ created = await this.outbound.sendInteractiveCard(contextKey, card);
141
+ }
121
142
  if (created && this.activeScheduleId === status.scheduleId) {
122
143
  this.messageIds.set(contextKey, created);
123
144
  this.cardHashes.set(contextKey, cardHash);
@@ -128,5 +149,27 @@ export class SafeRestartNotifier {
128
149
  }
129
150
  }));
130
151
  }
152
+ collectNotificationTargets(status) {
153
+ const requestedTargets = status.notificationTargets
154
+ ?? this.store.listChatContexts("p2p").map(({ contextKey }) => ({ contextKey }));
155
+ const recentTargets = this.store.listRecentlyActiveChatContexts(new Date(Date.now() - 60_000))
156
+ .filter((chat) => !isThreadContextKey(chat.contextKey))
157
+ .map(({ contextKey }) => ({ contextKey }));
158
+ for (const target of [
159
+ ...requestedTargets,
160
+ ...recentTargets,
161
+ ]) {
162
+ const contextKey = target.contextKey.trim();
163
+ if (!contextKey)
164
+ continue;
165
+ const existing = this.notificationTargets.get(contextKey);
166
+ if (!existing || (!existing.replyMessageId && target.replyMessageId)) {
167
+ this.notificationTargets.set(contextKey, {
168
+ contextKey,
169
+ ...(target.replyMessageId?.trim() ? { replyMessageId: target.replyMessageId.trim() } : {}),
170
+ });
171
+ }
172
+ }
173
+ }
131
174
  }
132
175
  //# sourceMappingURL=SafeRestartNotifier.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SafeRestartNotifier.js","sourceRoot":"","sources":["../../src/supervision/SafeRestartNotifier.ts"],"names":[],"mappings":"AAMA,MAAM,6BAA6B,GAAG,KAAK,CAAC;AAM5C,MAAM,OAAO,mBAAmB;IAUX,KAAK;IACL,QAAQ;IACR,QAAQ;IACR,MAAM;IACN,OAAO;IAbT,UAAU,GAAG,IAAI,GAAG,EAAkB,CAAC;IACvC,UAAU,GAAG,IAAI,GAAG,EAAkB,CAAC;IAChD,gBAAgB,CAAU;IAC1B,kBAAkB,CAAU;IAC5B,oBAAoB,CAAqB;IACzC,gBAAgB,CAAkB;IAClC,KAAK,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAElC,YACmB,KAAiB,EACjB,QAAwB,EACxB,Q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nB,GAAG,gBAAgB;YACnB,GAAG,aAAa;SACjB,EAAE,CAAC;YACF,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;YAC5C,IAAI,CAAC,UAAU;gBAAE,SAAS;YAC1B,MAAM,QAAQ,GAAG,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;YAC1D,IAAI,CAAC,QAAQ,IAAI,CAAC,CAAC,QAAQ,CAAC,cAAc,IAAI,MAAM,CAAC,cAAc,CAAC,EAAE,CAAC;gBACrE,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,UAAU,EAAE;oBACvC,UAAU;oBACV,GAAG,CAAC,MAAM,CAAC,cAAc,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;iBAC3F,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
@@ -4,6 +4,7 @@ export class SafeRestartScheduler {
4
4
  polling;
5
5
  pollAgain = false;
6
6
  reason;
7
+ notificationTargets = [];
7
8
  idleSince;
8
9
  idleInboundAt;
9
10
  scheduleId = 0;
@@ -16,10 +17,13 @@ export class SafeRestartScheduler {
16
17
  get pendingReason() {
17
18
  return this.reason;
18
19
  }
19
- schedule(reason) {
20
+ schedule(reason, notificationTarget) {
20
21
  const newlyScheduled = !this.reason;
21
- if (newlyScheduled)
22
+ if (newlyScheduled) {
22
23
  this.scheduleId += 1;
24
+ this.notificationTargets = [];
25
+ }
26
+ this.addNotificationTarget(notificationTarget);
23
27
  this.reason = reason;
24
28
  this.idleSince = undefined;
25
29
  this.idleInboundAt = undefined;
@@ -42,10 +46,12 @@ export class SafeRestartScheduler {
42
46
  if (!reason || this.scheduleId !== expectedScheduleId)
43
47
  return false;
44
48
  const activity = this.options.readActivity();
49
+ const notificationTargets = this.notificationTargetsSnapshot();
45
50
  this.clear();
46
51
  await this.emitStatus({
47
52
  scheduleId: expectedScheduleId,
48
53
  reason,
54
+ notificationTargets,
49
55
  phase: "cancelled",
50
56
  activity,
51
57
  });
@@ -56,6 +62,7 @@ export class SafeRestartScheduler {
56
62
  clearInterval(this.timer);
57
63
  this.timer = undefined;
58
64
  this.reason = undefined;
65
+ this.notificationTargets = [];
59
66
  this.idleSince = undefined;
60
67
  this.idleInboundAt = undefined;
61
68
  }
@@ -70,6 +77,7 @@ export class SafeRestartScheduler {
70
77
  await this.emitStatus({
71
78
  scheduleId: this.scheduleId,
72
79
  reason,
80
+ notificationTargets: this.notificationTargetsSnapshot(),
73
81
  phase: state.runningSessions > 0 ? "waiting_tasks" : "waiting_delivery",
74
82
  activity: state,
75
83
  });
@@ -80,12 +88,26 @@ export class SafeRestartScheduler {
80
88
  if (this.idleSince === undefined || this.idleInboundAt !== latestInboundAt) {
81
89
  this.idleSince = Date.now();
82
90
  this.idleInboundAt = latestInboundAt;
83
- await this.emitStatus({ scheduleId: this.scheduleId, reason, phase: "countdown", activity: state, remainingMs: quietPeriodMs });
91
+ await this.emitStatus({
92
+ scheduleId: this.scheduleId,
93
+ reason,
94
+ notificationTargets: this.notificationTargetsSnapshot(),
95
+ phase: "countdown",
96
+ activity: state,
97
+ remainingMs: quietPeriodMs,
98
+ });
84
99
  return;
85
100
  }
86
101
  const remainingMs = Math.max(0, quietPeriodMs - (Date.now() - this.idleSince));
87
102
  if (remainingMs > 0) {
88
- await this.emitStatus({ scheduleId: this.scheduleId, reason, phase: "countdown", activity: state, remainingMs });
103
+ await this.emitStatus({
104
+ scheduleId: this.scheduleId,
105
+ reason,
106
+ notificationTargets: this.notificationTargetsSnapshot(),
107
+ phase: "countdown",
108
+ activity: state,
109
+ remainingMs,
110
+ });
89
111
  return;
90
112
  }
91
113
  const confirmed = this.options.readActivity();
@@ -98,6 +120,7 @@ export class SafeRestartScheduler {
98
120
  await this.emitStatus({
99
121
  scheduleId: this.scheduleId,
100
122
  reason,
123
+ notificationTargets: this.notificationTargetsSnapshot(),
101
124
  phase: confirmed.runningSessions > 0 ? "waiting_tasks" : "waiting_delivery",
102
125
  activity: confirmed,
103
126
  });
@@ -106,6 +129,7 @@ export class SafeRestartScheduler {
106
129
  await this.emitStatus({
107
130
  scheduleId: this.scheduleId,
108
131
  reason,
132
+ notificationTargets: this.notificationTargetsSnapshot(),
109
133
  phase: "countdown",
110
134
  activity: confirmed,
111
135
  remainingMs: quietPeriodMs,
@@ -114,9 +138,17 @@ export class SafeRestartScheduler {
114
138
  return;
115
139
  }
116
140
  const scheduleId = this.scheduleId;
141
+ const notificationTargets = this.notificationTargetsSnapshot();
117
142
  this.clear();
118
- await this.emitStatus({ scheduleId, reason, phase: "restarting", activity: confirmed, remainingMs: 0 });
119
- await this.options.onReady(reason);
143
+ await this.emitStatus({
144
+ scheduleId,
145
+ reason,
146
+ notificationTargets,
147
+ phase: "restarting",
148
+ activity: confirmed,
149
+ remainingMs: 0,
150
+ });
151
+ await this.options.onReady(reason, notificationTargets);
120
152
  }
121
153
  requestPoll() {
122
154
  if (this.polling) {
@@ -142,5 +174,32 @@ export class SafeRestartScheduler {
142
174
  this.options.onStatusError?.(error);
143
175
  });
144
176
  }
177
+ addNotificationTarget(value) {
178
+ const target = normalizedNotificationTarget(value);
179
+ if (!target)
180
+ return;
181
+ const existingIndex = this.notificationTargets.findIndex((candidate) => candidate.contextKey === target.contextKey);
182
+ if (existingIndex < 0) {
183
+ this.notificationTargets.push(target);
184
+ return;
185
+ }
186
+ const existing = this.notificationTargets[existingIndex];
187
+ if (!existing.replyMessageId && target.replyMessageId) {
188
+ this.notificationTargets[existingIndex] = target;
189
+ }
190
+ }
191
+ notificationTargetsSnapshot() {
192
+ return this.notificationTargets.map((target) => ({ ...target }));
193
+ }
194
+ }
195
+ function normalizedNotificationTarget(value) {
196
+ const contextKey = value?.contextKey.trim();
197
+ if (!contextKey)
198
+ return undefined;
199
+ const replyMessageId = value?.replyMessageId?.trim();
200
+ return {
201
+ contextKey,
202
+ ...(replyMessageId ? { replyMessageId } : {}),
203
+ };
145
204
  }
146
205
  //# sourceMappingURL=SafeRestartScheduler.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SafeRestartScheduler.js","sourceRoot":"","sources":["../../src/supervision/SafeRestartScheduler.ts"],"names":[],"mappings":"AA8BA,MAAM,OAAO,oBAAoB;IASF,OAAO;IAR5B,KAAK,CAAkB;IACvB,OAAO,CAAiB;IACxB,SAAS,GAAG,KAAK,CAAC;IAClB,MAAM,CAAU;IAChB,SAAS,CAAU;IACnB,aAAa,CAAU;IACvB,UAAU,GAAG,CAAC,CAAC;IAEvB,YAA6B,OAAoC;uBAApC,OAAO;IAAgC,CAAC;IAErE,IAAI,SAAS;QACX,OAAO,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC;IAED,IAAI,aAAa;QACf,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,QAAQ,CAAC,MAAc;QACrB,MAAM,cAAc,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC;QACpC,IAAI,cAAc;YAAE,IAAI,CAAC,UAAU,IAAI,CAAC,CAAC;QACzC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,aAAa,GAAG,SAAS,CAAC;QAC/B,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;YAChB,IAAI,CAAC,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,cAAc,IAAI,KAAK,CAAC,CAAC;QAC3F,CAAC;QACD,IAAI,CAAC,WAAW,EAAE,CAAC;QACnB,OAAO,cAAc,CAAC;IACxB,CAAC;IAED,MAAM;QACJ,IAAI,CAAC,KAAK,EAAE,CAAC;IACf,CAAC;IAED,KAAK,CAAC,aAAa;QACjB,IAAI,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,CAAC,mBAAmB,CAAC,aAAa,CAAE,CAAC;QAC1D,IAAI,CAAC,QAAQ,CAAC,cAAc,IAAI,MAAM,CAAC,cAAc,EAAE,CAAC;YACtD,IAAI,CAAC,mBAAmB,CAAC,aAAa,CAAC,GAAG,MAAM,CAAC;QACnD,CAAC;IACH,CAAC;IAEO,2BAA2B;QACjC,OAAO,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC,CAAC;IACnE,CAAC;CACF;AAED,SAAS,4BAA4B,CACnC,KAA4C;IAE5C,MAAM,UAAU,GAAG,KAAK,EAAE,UAAU,CAAC,IAAI,EAAE,CAAC;IAC5C,IAAI,CAAC,UAAU;QAAE,OAAO,SAAS,CAAC;IAClC,MAAM,cAAc,GAAG,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,CAAC;IACrD,OAAO;QACL,UAAU;QACV,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC9C,CAAC;AACJ,CAAC"}
@@ -1,8 +1,33 @@
1
- export function replacementSupervisorEnvironment(restartReason, environment = process.env) {
2
- return {
1
+ export const RESTART_GROUP_CONTEXTS_ENV = "AGENT_BOT_RESTART_GROUP_CONTEXTS";
2
+ export function replacementSupervisorEnvironment(restartReason, environment = process.env, restartGroupContextKeys = []) {
3
+ const result = {
3
4
  ...environment,
4
5
  AGENT_BOT_START_DELAY_MS: "250",
5
6
  AGENT_BOT_RESTART_REASON: restartReason,
6
7
  };
8
+ const normalized = normalizedContextKeys(restartGroupContextKeys);
9
+ if (normalized.length > 0) {
10
+ result[RESTART_GROUP_CONTEXTS_ENV] = JSON.stringify(normalized);
11
+ }
12
+ else {
13
+ delete result[RESTART_GROUP_CONTEXTS_ENV];
14
+ }
15
+ return result;
16
+ }
17
+ export function restartGroupContextKeysFromEnvironment(value) {
18
+ if (!value?.trim())
19
+ return [];
20
+ try {
21
+ const parsed = JSON.parse(value);
22
+ return Array.isArray(parsed)
23
+ ? normalizedContextKeys(parsed.filter((entry) => typeof entry === "string"))
24
+ : [];
25
+ }
26
+ catch {
27
+ return [];
28
+ }
29
+ }
30
+ function normalizedContextKeys(values) {
31
+ return [...new Set(values.map((value) => value.trim()).filter(Boolean))];
7
32
  }
8
33
  //# sourceMappingURL=replacementSupervisor.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"replacementSupervisor.js","sourceRoot":"","sources":["../../src/supervision/replacementSupervisor.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,gCAAgC,CAC9C,aAAqB,EACrB,WAAW,GAAsB,OAAO,CAAC,GAAG;IAE5C,OAAO;QACL,GAAG,WAAW;QACd,wBAAwB,EAAE,KAAK;QAC/B,wBAAwB,EAAE,aAAa;KACxC,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"replacementSupervisor.js","sourceRoot":"","sources":["../../src/supervision/replacementSupervisor.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,0BAA0B,GAAG,kCAAkC,CAAC;AAE7E,MAAM,UAAU,gCAAgC,CAC9C,aAAqB,EACrB,WAAW,GAAsB,OAAO,CAAC,GAAG,EAC5C,uBAAuB,GAAsB,EAAE;IAE/C,MAAM,MAAM,GAAsB;QAChC,GAAG,WAAW;QACd,wBAAwB,EAAE,KAAK;QAC/B,wBAAwB,EAAE,aAAa;KACxC,CAAC;IACF,MAAM,UAAU,GAAG,qBAAqB,CAAC,uBAAuB,CAAC,CAAC;IAClE,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC1B,MAAM,CAAC,0BAA0B,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;IAClE,CAAC;SAAM,CAAC;QACN,OAAO,MAAM,CAAC,0BAA0B,CAAC,CAAC;IAC5C,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,sCAAsC,CAAC,KAAyB;IAC9E,IAAI,CAAC,KAAK,EAAE,IAAI,EAAE;QAAE,OAAO,EAAE,CAAC;IAC9B,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAY,CAAC;QAC5C,OAAO,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;YAC1B,CAAC,CAAC,qBAAqB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAmB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC;YAC7F,CAAC,CAAC,EAAE,CAAC;IACT,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC;AAED,SAAS,qBAAqB,CAAC,MAAyB;IACtD,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAC3E,CAAC"}
@@ -7,6 +7,7 @@ import { requireServerFeishuTransport } from "./feishu/transport.js";
7
7
  import { crashRestartDelayMs, describeRestartReason, INTENTIONAL_RESTART_DELAY_MS, RESTART_EXIT_CODE, STABLE_UPTIME_MS, STOP_EXIT_CODE, } from "./supervision/restartPolicy.js";
8
8
  import { SupervisorDiagnostics, nodeDiagnosticReportArguments } from "./supervision/SupervisorDiagnostics.js";
9
9
  import { refreshedSystemEnvironment } from "./supervision/systemEnvironment.js";
10
+ import { RESTART_GROUP_CONTEXTS_ENV, restartGroupContextKeysFromEnvironment, } from "./supervision/replacementSupervisor.js";
10
11
  const childEntry = fileURLToPath(new URL("./index.js", import.meta.url));
11
12
  const config = loadConfig();
12
13
  requireServerFeishuTransport(config.feishu);
@@ -16,9 +17,11 @@ const diagnostics = new SupervisorDiagnostics(config);
16
17
  diagnostics.initialize();
17
18
  let child;
18
19
  let restartTimer;
20
+ let restartGroupContextExpiryTimer;
19
21
  let stopping = false;
20
22
  let consecutiveFailures = 0;
21
23
  let nextStartReason = process.env.AGENT_BOT_RESTART_REASON?.trim() || "Supervisor 启动";
24
+ let nextRestartGroupContextKeys = restartGroupContextKeysFromEnvironment(process.env[RESTART_GROUP_CONTEXTS_ENV]);
22
25
  async function startChild() {
23
26
  if (stopping || child)
24
27
  return;
@@ -29,6 +32,7 @@ async function startChild() {
29
32
  }
30
33
  const startedAt = Date.now();
31
34
  const restartReason = nextStartReason;
35
+ const restartGroupContextKeys = nextRestartGroupContextKeys;
32
36
  nextStartReason = "Supervisor 重新拉起进程";
33
37
  const workerStderr = diagnostics.openWorkerStderr();
34
38
  const environmentRefresh = refreshedSystemEnvironment();
@@ -44,11 +48,11 @@ async function startChild() {
44
48
  childEntry,
45
49
  ], {
46
50
  cwd: process.cwd(),
47
- env: {
51
+ env: workerEnvironment({
48
52
  ...environmentRefresh.environment,
49
53
  AGENT_BOT_SUPERVISED: "1",
50
54
  AGENT_BOT_RESTART_REASON: restartReason,
51
- },
55
+ }, restartGroupContextKeys),
52
56
  stdio: ["ignore", "ignore", workerStderr],
53
57
  windowsHide: true,
54
58
  });
@@ -60,6 +64,7 @@ async function startChild() {
60
64
  writeSupervisorLog("started", {
61
65
  pid: child.pid,
62
66
  restartReason,
67
+ restartGroupContextKeys,
63
68
  workerStderrPath: diagnostics.paths.workerStderrPath,
64
69
  crashReportDirectory: diagnostics.paths.crashReportDirectory,
65
70
  });
@@ -69,6 +74,24 @@ async function startChild() {
69
74
  child.once("exit", (code, signal) => {
70
75
  void handleChildExit(code, signal, startedAt, workerPid);
71
76
  });
77
+ if (restartGroupContextKeys.length > 0) {
78
+ if (restartGroupContextExpiryTimer)
79
+ clearTimeout(restartGroupContextExpiryTimer);
80
+ restartGroupContextExpiryTimer = setTimeout(() => {
81
+ nextRestartGroupContextKeys = [];
82
+ restartGroupContextExpiryTimer = undefined;
83
+ }, STABLE_UPTIME_MS);
84
+ }
85
+ }
86
+ function workerEnvironment(environment, restartGroupContextKeys) {
87
+ const result = { ...environment };
88
+ if (restartGroupContextKeys.length > 0) {
89
+ result[RESTART_GROUP_CONTEXTS_ENV] = JSON.stringify(restartGroupContextKeys);
90
+ }
91
+ else {
92
+ delete result[RESTART_GROUP_CONTEXTS_ENV];
93
+ }
94
+ return result;
72
95
  }
73
96
  async function handleChildExit(code, signal, startedAt, workerPid) {
74
97
  child = undefined;
@@ -123,6 +146,8 @@ function stop(signal) {
123
146
  stopping = true;
124
147
  if (restartTimer)
125
148
  clearTimeout(restartTimer);
149
+ if (restartGroupContextExpiryTimer)
150
+ clearTimeout(restartGroupContextExpiryTimer);
126
151
  if (child && !child.killed) {
127
152
  child.kill(signal);
128
153
  return;
@@ -1 +1 @@
1
- {"version":3,"file":"supervisor.js","sourceRoot":"","sources":["../src/supervisor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAqB,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EACL,mBAAmB,EACnB,qBAAqB,EACrB,4BAA4B,EAC5B,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,GACf,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,qBAAqB,EAAE,6BAA6B,EAAE,MAAM,wCAAwC,CAAC;AAC9G,OAAO,EAAE,0BAA0B,EAAE,MAAM,oCAAoC,CAAC;AAEhF,MAAM,UAAU,GAAG,aAAa,CAAC,IAAI,GAAG,CAAC,YAAY,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AACzE,MAAM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B,CAAC,CAAC;IACjF,IAAI,KAAK,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;QAC3B,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACnB,OAAO;IACT,CAAC;IACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,SAAS,kBAAkB,CAAC,KAAa,EAAE,IAA6B;IACtE,WAAW,CAAC,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;AACtC,CAAC;AAED,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;AAC3C,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;AAC7C,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,wBAAwB,IAAI,CAAC,CAAC,CAAC;AACzE,IAAI,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAC,IAAI,cAAc,GAAG,CAAC,EAAE,CAAC;IAC1D,YAAY,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,KAAK,UAAU,EAAE,EAAE,cAAc,CAAC,CAAC;AACrE,CAAC;KAAM,CAAC;IACN,KAAK,UAAU,EAAE,CAAC;AACpB,CAAC"}
@@ -35,7 +35,7 @@ The default user-data root is `~/.agent-bot`. `AGENT_BOT_HOME` replaces that roo
35
35
 
36
36
  The CLI also supports explicit directory-based profiles. Without `--profile`, commands use the main profile and the normal environment-based path rules. `--profile <directory>` pins both `AGENT_BOT_HOME` and `AGENT_BOT_CONFIG` for the command and every spawned supervisor or worker, with the configuration fixed at `<directory>/config.yaml`. It also clears inherited Feishu credential variables before loading the selected profile's `.env`, which prevents a secondary service launched from inside the primary Agent Bot process tree from accidentally reusing the primary bot. It cannot be combined with `--config`. Alternative profiles must be selected explicitly on every command; Agent Bot does not maintain a named-profile registry.
37
37
 
38
- The CLI reads the system locale through Node.js internationalization support. Locales beginning with `zh` use Chinese interface text; English and every unsupported locale use English. This applies to help, status, progress, prompts, and CLI-owned errors. JSON field names and enum values are not localized. System-generated restart reasons remain Chinese because they are rendered in Chinese Lark status cards; an explicit `--reason` is preserved verbatim. `agentbot server status` reports the running worker's Lark App ID as `feishuAppId` in JSON; when the server is stopped or predates that health field, the CLI falls back to the selected profile's configured App ID.
38
+ The CLI reads the system locale through Node.js internationalization support. Locales beginning with `zh` use Chinese interface text; English and every unsupported locale use English. This applies to help, status, progress, prompts, and CLI-owned errors. JSON field names and enum values are not localized. System-generated restart reasons remain Chinese because they are rendered in Chinese Lark status cards; an explicit `--reason` is preserved verbatim. `agentbot server status` reports the running worker's Lark App ID as `feishuAppId` in JSON; when the server is stopped or predates that health field, the CLI falls back to the selected profile's configured App ID. Its `agents` array reports each configured Agent process's PID and protocol-reported version; both are `null` until that Agent starts.
39
39
 
40
40
  | Default path | Contents |
41
41
  | ------------------------------------ | ---------------------------------- |
@@ -73,6 +73,7 @@ Credential behavior:
73
73
  - Environment values take precedence over values in `~/.agent-bot/.env`.
74
74
  - Both `FEISHU_APP_ID` and `FEISHU_APP_SECRET` are required.
75
75
  - One-click registration also stores the authorizing user's `open_id` as `FEISHU_USER_OPEN_ID`.
76
+ - When existing app credentials have no user Open ID, the first private-chat message with a valid `ou_` sender persists that sender atomically to the Profile `.env`; group messages and later users never replace it.
76
77
  - Complete credentials are preserved unless `--reconfigure-feishu` is used.
77
78
  - Missing or incomplete credentials cause a new app registration.
78
79
  - Newly registered credentials are fsynced, atomically replaced in `.env`, and read back before configuration begins.
@@ -100,7 +101,7 @@ The generated authorization links do not contain the app secret.
100
101
 
101
102
  `agentbot --profile <directory> init --reset` fully resets an explicitly selected Profile. The Profile server must be stopped first. The command moves the active `config.yaml`, `.env`, `data/`, and `logs/` into a unique timestamped directory under `<profile>/.reset-backups/`, creates clean replacements from the packaged templates, and proceeds through normal initialization. Existing reset backups and unrelated files are retained. Because backups can contain old app secrets and conversation data, protect the Profile directory accordingly. The remote Feishu app is not deleted. `--reset --skip-feishu` creates a clean Console-only Profile, while `--reset` and `--reconfigure-feishu` cannot be combined.
102
103
 
103
- After Feishu initialization succeeds, the CLI releases the initialization lock and starts the detached supervisor through the same readiness path as `agentbot server start`. It waits up to 45 seconds for the worker to connect to Feishu and become ready. If the selected profile is already running, no second supervisor is created. `--skip-feishu` skips automatic server startup, and `--json` includes the resulting `server.status` without adding non-JSON output.
104
+ After Feishu initialization succeeds, the CLI releases the initialization lock and starts the detached supervisor through the same readiness path as `agentbot server start`. It waits up to 45 seconds for the worker to connect to Feishu and become ready. If the selected profile is already running, no second supervisor is created; instead, initialization requests a safe restart so the current installed code and refreshed configuration are loaded after active work and final delivery finish. The JSON result reports this as `server.status: "restart-scheduled"`. `--skip-feishu` skips automatic server startup, and `--json` includes the resulting `server.status` without adding non-JSON output.
104
105
 
105
106
  ## Feishu App Requirements
106
107
 
@@ -171,7 +172,7 @@ logging:
171
172
 
172
173
  `feishu.respondToAllGroupMessages` defaults to `true`. Set it to `false` to ignore group messages unless they mention the current bot. The worker resolves the bot's Open ID at startup so mentioning another member does not trigger it. Private messages are always accepted. Initialization requests all-user group-message delivery regardless of this runtime option, allowing it to be changed later without another authorization.
173
174
 
174
- `agentbot server start` requires both Feishu credentials. The worker starts the SDK's persistent connection without inspecting SDK logs or private connection state, then sends startup status cards as an outbound readiness check. Each startup card includes the Agent Bot version read from the installed package metadata. It normally targets known private chats and recently active groups. If the database has no known chat yet, it sends the card to `feishu.userOpenId` using an `open_id` private message. When notification targets exist, at least one card must be delivered before the server reports ready; individual target failures remain isolated. If neither a known chat nor `feishu.userOpenId` is available, startup continues without the outbound check. Missing credentials still fail startup with an initialization hint. `agentbot console` is the explicit local-only path and does not require Feishu credentials.
175
+ `agentbot server start` requires both Feishu credentials. The worker starts the SDK's persistent connection without inspecting SDK logs or private connection state, then sends startup status cards as an outbound readiness check. Each startup card includes the Agent Bot version read from the installed package metadata. Every startup sends a card to every known private chat, regardless of recent activity, plus each non-topic group active during the minute before this Worker started. After a safe restart, it also sends to every group enrolled in that restart's notification set regardless of activity age. A topic route is normalized to its parent group, so topic contexts are never startup-card targets. If the database has no eligible chat yet, it sends the card to `feishu.userOpenId` using an `open_id` private message. When notification targets exist, at least one card must be delivered before the server reports ready; individual target failures remain isolated. If neither a known chat nor `feishu.userOpenId` is available, startup continues without the outbound check. The first subsequent private message can persist the missing user Open ID for later startup notifications and CLI-created groups. Missing credentials still fail startup with an initialization hint. `agentbot console` is the explicit local-only path and does not require Feishu credentials.
175
176
 
176
177
  At least one agent must be configured. `defaults.agent` must name a configured agent.
177
178
 
@@ -183,13 +184,19 @@ The configured Agent standard name is the runtime isolation key. Every configure
183
184
 
184
185
  An agent with `kind: "acp"`, or without a `kind`, uses its own ACP process. Multiple tasks create separate ACP sessions on that connection. Agent-specific `env` values are added only to that Agent's environment.
185
186
 
186
- Every agent process receives:
187
+ Agent processes inherit ordinary parent-process variables. Before an App Server or ACP process is spawned, Agent Bot removes every inherited or Agent-configured variable whose name case-insensitively matches `FEISHU_*` or `AGENT_BOT_*`. It then injects this controlled, non-secret context:
187
188
 
188
189
  ```text
189
190
  AGENT_BOT=1
191
+ AGENT_BOT_HOME=<active Profile root>
192
+ AGENT_BOT_CONFIG=<active config.yaml path>
193
+ AGENT_BOT_AGENT_NAME=<configured Agent standard name>
194
+ AGENT_BOT_LARK_APP_ID=<Lark App ID>
195
+ AGENT_BOT_LARK_BOT_OPEN_ID=<Lark bot open_id, when available>
196
+ AGENT_BOT_LARK_USER_OPEN_ID=<saved authorizing user open_id, when available>
190
197
  ```
191
198
 
192
- The bundled skill uses this variable to detect that it is running inside Agent Bot.
199
+ The bundled skill uses `AGENT_BOT` to detect that it is running inside Agent Bot. The Lark App Secret, Supervisor state, restart reasons, and restart notification routes are never forwarded. Non-reserved values in `agents.<name>.env` remain the explicit way to configure environment required only by that Agent.
193
200
 
194
201
  ## Chat Routing
195
202
 
@@ -222,13 +229,15 @@ The new group's welcome message reports the persisted fork settings: Provider, m
222
229
 
223
230
  Each turn owns one progress card. Normal updates are throttled to one every two seconds; critical updates have a 500 ms minimum gap. On completion, Agent Bot updates the progress card to a terminal state before sending a separate final Markdown message.
224
231
 
232
+ Successfully completed progress cards include a `Reset` action with its compact effect warning directly below the action. `/turns` places the same effect warning at the top, then presents the current task's completed-turn snapshots in reverse chronological order, 10 per page. Each `turn_started` event persists the previous completed turn as its parent. Existing tasks are backfilled from snapshot timestamps and `session_reset_to_turn` audits, so the first turn after a historical Reset points to the selected turn instead of the time-adjacent abandoned branch. The renderer computes lanes across the complete history before slicing a page, then displays true continuations and merges in the graph column, indented content in the second column, and state or action in the third. The current conversation point is marked instead of showing an action; every other turn has a `Reset` action. Pagination and successful Reset actions update the same card, remain bound to the task that opened it, and move the current marker to the selected turn. The success text identifies the target with its Prompt summary, completion time, and Turn ID. Agent Bot records the App Server thread that originally owned each turn, forks that thread through the selected turn, and replaces the current task's remote thread binding without changing its local task ID, title, Agent, project directory, execution settings, or chat routing. Existing snapshots after the selected turn are not deleted, so the card shows retained turns from the old path together with turns later completed on the new branch. Reset is rejected while the current task is active, and it never reverts local file changes.
233
+
225
234
  After the durable message-deduplication claim, Agent Bot awaits the `OnIt` reaction before chat persistence, image downloads, queue waits, command execution, or runtime calls. It replaces that reaction with `DONE`, `ERROR`, or `CrossMark` when the turn succeeds, fails, or is canceled. Reaction failures are logged but do not block task execution.
226
235
 
227
236
  Incoming rich-text images are downloaded into the inbound image cache and passed to the App Server as `localImage` inputs. An image-only message uses the default Prompt `请查看这张图片`. An ACP runtime that cannot accept image input returns an explicit error.
228
237
 
229
238
  ## Tasks, Projects, And External App Server Work
230
239
 
231
- `/sessions` reads tasks through `thread/list` from every configured App Server Agent. For Codex, this includes tasks created by Codex Desktop, CLI, Agent Bot, or another App Server client under the same `CODEX_HOME`; other Agents expose their own task stores through the same protocol.
240
+ `/sessions` reads tasks through `thread/list` from every configured App Server Agent. For Codex, this includes tasks created by Codex Desktop, CLI, Agent Bot, or another App Server client under the same `CODEX_HOME`; other Agents expose their own task stores through the same protocol. The merged, globally sorted result is displayed five tasks per page. `Previous` and `Next` replace the current card contents instead of appending more tasks, while preserving search terms and stable global task numbers.
232
241
 
233
242
  Each task entry exposes `NewGroup` and `ForkGroup` callbacks. The callback payload keeps the selected task ID and source context, while the Lark operator `open_id` is used to invite the user to the new group. `NewGroup` resolves the selected task's project and execution settings; `ForkGroup` resolves its latest available completed turn.
234
243
 
@@ -290,9 +299,13 @@ A safe restart waits for:
290
299
 
291
300
  The Feishu `/restart` command uses this safe path by default; `/restart --force` restarts immediately and may interrupt active work. The command rejects every other argument. New messages reset the quiet timer. CLI `--immediate` and `--force` also skip these checks. Exit code `75` identifies an intentional worker restart.
292
301
 
302
+ A pending safe-restart schedule accumulates the exact notification route of every conversation that triggers it. Every inbound user message, including slash commands, marks its base private or group conversation active. On every status update the notifier also enrolls every persisted conversation active during the preceding minute. Each enrolled route receives its own status card and final restarting acknowledgement and remains enrolled until the schedule ends, even after its activity becomes older than one minute. Repeated routes are deduplicated; when a topic route was first discovered without a message anchor, a later anchored trigger upgrades it. Topic requests retain the originating message ID and use a thread reply so restart updates cannot fall back to the group body. Recent topic activity is tracked on the parent group, while an explicit topic trigger remains in that topic. Later requests also update the restart reason. Before replacement, Agent Bot extracts and deduplicates the parent group of every enrolled route, passes that list through the replacement Supervisor, and adds those groups to the service-wide startup-card targets. The Supervisor retains the list until the Worker has remained stable for 60 seconds, so an early crash-driven relaunch does not lose required recipients.
303
+
304
+ Use `agentbot server restart --task <task>` when a CLI request belongs to a specific task. Task numbers, full IDs, and unambiguous ID prefixes are resolved before the control request is sent. Without `--task`, the Server infers the safe-restart status route only when all running tasks belong to one conversation; it rejects an ambiguous request spanning multiple running conversations. A CLI restart with no running task has no conversation owner for its waiting status.
305
+
293
306
  The first safe-restart status card is delayed by three seconds so a task's final response can usually arrive first. Status changes during that window are coalesced into the initial card. The delay does not block scheduler polling, and shutdown flushes any pending card immediately.
294
307
 
295
- Pending safe-restart cards include a bottom `Cancel` action. The action carries the scheduler's monotonic schedule ID, so an old card cannot cancel a newer restart. A successful cancellation updates every existing status card in place and removes the action; the action is also absent once the scheduler enters the irreversible restarting phase.
308
+ Pending safe-restart cards include a bottom `Cancel` action. The action carries the scheduler's monotonic schedule ID, so an old card cannot cancel a newer restart. A successful cancellation updates every enrolled conversation's existing status card in place and removes the action; the action is also absent once the scheduler enters the irreversible restarting phase.
296
309
 
297
310
  The local control server implements task mutations, task-targeted NewGroup and ForkGroup operations, and service restart requests. Read-only task queries access SQLite directly.
298
311