@mininglamp-oss/octo-runtime 1.1.4 → 1.1.6

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 (177) hide show
  1. package/README.md +61 -37
  2. package/apps/cli/README.md +58 -22
  3. package/apps/cli/dist/adapter-configurations.d.ts +4 -0
  4. package/apps/cli/dist/adapter-configurations.js +102 -0
  5. package/apps/cli/dist/build-info.json +2 -2
  6. package/apps/cli/dist/cli-entrypoint.d.ts +2 -0
  7. package/apps/cli/dist/cli-entrypoint.js +16 -0
  8. package/apps/cli/dist/command-tree.d.ts +20 -0
  9. package/apps/cli/dist/command-tree.js +402 -0
  10. package/apps/cli/dist/extra-command-config.d.ts +4 -0
  11. package/apps/cli/dist/extra-command-config.js +50 -0
  12. package/apps/cli/dist/extra-commands.d.ts +15 -0
  13. package/apps/cli/dist/extra-commands.js +275 -0
  14. package/apps/cli/dist/extras.js +14 -2
  15. package/apps/cli/dist/global-extras.d.ts +16 -0
  16. package/apps/cli/dist/global-extras.js +201 -0
  17. package/apps/cli/dist/help.d.ts +4 -1
  18. package/apps/cli/dist/help.js +31 -79
  19. package/apps/cli/dist/logs.js +8 -4
  20. package/apps/cli/dist/main.d.ts +2 -0
  21. package/apps/cli/dist/main.js +38 -68
  22. package/apps/cli/dist/manifest.json +48 -3
  23. package/apps/cli/dist/module-manifest.d.ts +1 -1
  24. package/apps/cli/dist/module-manifest.js +3 -2
  25. package/apps/cli/dist/output.js +18 -2
  26. package/apps/cli/dist/playboard.js +3 -2
  27. package/apps/cli/dist/service-control.js +2 -2
  28. package/apps/cli/dist/state.js +48 -19
  29. package/dist/public/channel-gateway-commands.d.ts +1 -0
  30. package/dist/public/channel-gateway-commands.js +1 -0
  31. package/dist/public/channel-wecom-commands.d.ts +1 -0
  32. package/dist/public/channel-wecom-commands.js +1 -0
  33. package/dist/public/extra.d.ts +1 -0
  34. package/dist/public/extra.js +1 -0
  35. package/dist/public/host.d.ts +2 -4
  36. package/dist/public/host.js +1 -2
  37. package/dist/public/webui-commands.d.ts +1 -0
  38. package/dist/public/webui-commands.js +1 -0
  39. package/node_modules/@mininglamp-oss/octo-runtime-acp-client/dist/index.js +5 -2
  40. package/node_modules/@mininglamp-oss/octo-runtime-acp-client/package.json +3 -3
  41. package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/package.json +4 -4
  42. package/node_modules/@mininglamp-oss/octo-runtime-adapter-antigravity/package.json +3 -3
  43. package/node_modules/@mininglamp-oss/octo-runtime-adapter-claude-code/package.json +3 -3
  44. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codebuddy/dist/index.d.ts +3 -4
  45. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codebuddy/dist/index.js +161 -26
  46. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codebuddy/package.json +4 -4
  47. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/app-server.js +3 -1
  48. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/package.json +3 -3
  49. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/{chunk-G5PWGRL5.js → chunk-3GXX5VD5.js} +24 -90
  50. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/{chunk-UOQRXV3Q.js → chunk-FWAPYRV2.js} +1 -1
  51. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/{chunk-DYOJCNWF.js → chunk-IW62UM3C.js} +1 -1
  52. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/errors.d.ts +1 -1
  53. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/errors.js +1 -1
  54. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/index.js +3 -3
  55. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/launch.d.ts +1 -1
  56. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/launch.js +2 -2
  57. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/trajectory.js +2 -2
  58. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/package.json +3 -3
  59. package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/dist/client.js +8 -2
  60. package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/package.json +5 -5
  61. package/node_modules/@mininglamp-oss/octo-runtime-adapter-hermes/package.json +2 -2
  62. package/node_modules/@mininglamp-oss/octo-runtime-adapter-kimi-code/package.json +2 -2
  63. package/node_modules/@mininglamp-oss/octo-runtime-adapter-mcode/package.json +2 -2
  64. package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/package.json +3 -3
  65. package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/package.json +4 -4
  66. package/node_modules/@mininglamp-oss/octo-runtime-adapter-qodercli/package.json +2 -2
  67. package/node_modules/@mininglamp-oss/octo-runtime-adapter-qoderclicn/package.json +2 -2
  68. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/index.d.ts +1 -1
  69. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/index.js +8 -4
  70. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/module-manifest.d.ts +6 -0
  71. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/module-manifest.js +16 -4
  72. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/process-launch.d.ts +12 -0
  73. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/process-launch.js +91 -0
  74. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/runtime-log-worker.js +2 -2
  75. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/runtime-log.js +13 -1
  76. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/service-status.d.ts +9 -0
  77. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/service-status.js +40 -0
  78. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/package.json +3 -2
  79. package/node_modules/@mininglamp-oss/octo-runtime-adapter-zcode-gui/package.json +3 -3
  80. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/adapter-configurations.d.ts +4 -0
  81. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/adapter-configurations.js +102 -0
  82. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/build-info.json +2 -2
  83. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/cli-entrypoint.d.ts +2 -0
  84. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/cli-entrypoint.js +16 -0
  85. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/command-tree.d.ts +20 -0
  86. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/command-tree.js +402 -0
  87. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/extra-command-config.d.ts +4 -0
  88. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/extra-command-config.js +50 -0
  89. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/extra-commands.d.ts +15 -0
  90. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/extra-commands.js +275 -0
  91. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/extras.js +14 -2
  92. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/global-extras.d.ts +16 -0
  93. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/global-extras.js +201 -0
  94. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/help.d.ts +4 -1
  95. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/help.js +31 -79
  96. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/logs.js +8 -4
  97. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/main.d.ts +2 -0
  98. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/main.js +38 -68
  99. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/manifest.json +48 -3
  100. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/module-manifest.d.ts +1 -1
  101. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/module-manifest.js +3 -2
  102. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/output.js +18 -2
  103. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/playboard.js +3 -2
  104. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/service-control.js +2 -2
  105. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/state.js +48 -19
  106. package/node_modules/@mininglamp-oss/octo-runtime-cli/package.json +25 -24
  107. package/node_modules/@mininglamp-oss/octo-runtime-cross-service/package.json +1 -1
  108. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/index.js +8 -3
  109. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/watchdog.js +47 -4
  110. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/package.json +3 -3
  111. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/client.js +2 -0
  112. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/invocation-manifest.js +4 -1
  113. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/process.d.ts +7 -0
  114. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/process.js +79 -5
  115. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/server.d.ts +3 -1
  116. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/server.js +22 -6
  117. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/service.js +2 -1
  118. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/submission-error.d.ts +5 -3
  119. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/submission-error.js +12 -6
  120. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/supervisor.d.ts +4 -2
  121. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/supervisor.js +131 -43
  122. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/package.json +4 -4
  123. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/context-gap.js +2 -2
  124. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/im-channel.js +36 -20
  125. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/commands.d.ts +4 -0
  126. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/commands.js +124 -0
  127. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/dispatcher.js +3 -0
  128. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/model-wait.d.ts +29 -0
  129. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/model-wait.js +171 -0
  130. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/task.d.ts +4 -1
  131. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/task.js +48 -6
  132. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/presentation/run-projector.d.ts +2 -0
  133. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/auth.d.ts +1 -1
  134. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/auth.js +2 -2
  135. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/connection-error.d.ts +7 -0
  136. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/connection-error.js +44 -3
  137. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/contexts.js +1 -1
  138. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/reasoning-frame.js +37 -0
  139. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/wukong.js +8 -5
  140. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/package.json +10 -6
  141. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/dist/commands.d.ts +4 -0
  142. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/dist/commands.js +128 -0
  143. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/package.json +9 -5
  144. package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/commands.d.ts +3 -0
  145. package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/commands.js +51 -0
  146. package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/package.json +7 -3
  147. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/endpoint.d.ts +2 -0
  148. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/endpoint.js +5 -3
  149. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/extra-commands.d.ts +70 -0
  150. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/extra-commands.js +16 -0
  151. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/index.d.ts +1 -3
  152. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/index.js +1 -2
  153. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/package.json +8 -4
  154. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/failure.d.ts +2 -1
  155. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/failure.js +9 -1
  156. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/generated/protocol-types.d.ts +9 -0
  157. package/node_modules/@mininglamp-oss/octo-runtime-protocol/package.json +1 -1
  158. package/node_modules/commander/LICENSE +22 -0
  159. package/node_modules/commander/Readme.md +1172 -0
  160. package/node_modules/commander/index.js +21 -0
  161. package/node_modules/commander/lib/argument.js +147 -0
  162. package/node_modules/commander/lib/command.js +2790 -0
  163. package/node_modules/commander/lib/error.js +36 -0
  164. package/node_modules/commander/lib/help.js +731 -0
  165. package/node_modules/commander/lib/option.js +377 -0
  166. package/node_modules/commander/lib/suggestSimilar.js +99 -0
  167. package/node_modules/commander/package-support.json +19 -0
  168. package/node_modules/commander/package.json +64 -0
  169. package/node_modules/commander/typings/index.d.ts +1113 -0
  170. package/package.json +41 -27
  171. package/packages/octo-runtime-protocol/schema/protocol.schema.json +14 -0
  172. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/desktop-entry.d.ts +0 -1
  173. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/desktop-entry.js +0 -16
  174. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/launch.d.ts +0 -15
  175. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/launch.js +0 -22
  176. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/native.d.ts +0 -16
  177. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/native.js +0 -160
@@ -33,6 +33,7 @@ export class InvocationWatchdog {
33
33
  #startedAt;
34
34
  #tools = new Map();
35
35
  #interactions = new Set();
36
+ #activities = new Map();
36
37
  #waitingSince;
37
38
  #nativeProgressSeen = false;
38
39
  #modelStarted = false;
@@ -133,6 +134,21 @@ export class InvocationWatchdog {
133
134
  this.dispose();
134
135
  return;
135
136
  }
137
+ // 统一活动补充执行阶段;与正式工具/交互分别持有暂停原因,不能互相提前解除。
138
+ if (event.type === "activity.started" &&
139
+ ["executing_tool", "waiting_input", "waiting_approval"].includes(event.payload.kind) &&
140
+ !this.#activities.has(event.payload.activityId)) {
141
+ const waitId = event.payload.kind === "executing_tool" ? undefined : Symbol();
142
+ this.#activities.set(event.payload.activityId, {
143
+ subject: event.payload.subject,
144
+ waitId,
145
+ tool: waitId ? undefined : { startedAt: now, progressAt: now }
146
+ });
147
+ if (waitId)
148
+ this.#interaction(waitId, true);
149
+ }
150
+ if (event.type === "activity.finished")
151
+ this.#finishActivity(event.payload.activityId);
136
152
  const rawID = event.payload.toolCallId ?? event.payload.id ?? event.payload.itemId;
137
153
  const id = typeof rawID === "string" && rawID ? rawID : undefined;
138
154
  let toolChanged = false;
@@ -144,12 +160,14 @@ export class InvocationWatchdog {
144
160
  id &&
145
161
  ["completed", "failed", "cancelled", "stopped"].includes(String(event.payload.status))) {
146
162
  toolChanged = this.#tools.delete(id);
163
+ this.#finishSubjectActivities("tool", id);
147
164
  }
148
165
  if (event.type === "interaction.requested" && typeof event.payload.interactionId === "string") {
149
166
  this.#interaction(event.payload.interactionId, true);
150
167
  }
151
168
  if (event.type === "interaction.resolved" && typeof event.payload.interactionId === "string") {
152
169
  this.#interaction(event.payload.interactionId, false);
170
+ this.#finishSubjectActivities("interaction", event.payload.interactionId);
153
171
  }
154
172
  const hasText = (value) => typeof value === "string" && value.length > 0;
155
173
  const toolProgress = event.payload.progress;
@@ -180,6 +198,25 @@ export class InvocationWatchdog {
180
198
  this.#syncPhase();
181
199
  this.#arm();
182
200
  }
201
+ #finishSubjectActivities(type, id) {
202
+ for (const [activityId, activity] of this.#activities)
203
+ if (activity.subject.type === type && activity.subject.id === id)
204
+ this.#finishActivity(activityId);
205
+ }
206
+ #finishActivity(id) {
207
+ const activity = this.#activities.get(id);
208
+ if (!activity)
209
+ return;
210
+ this.#activities.delete(id);
211
+ if (activity.waitId)
212
+ this.#interaction(activity.waitId, false);
213
+ }
214
+ *#toolClocks() {
215
+ yield* this.#tools.values();
216
+ for (const activity of this.#activities.values())
217
+ if (activity.tool)
218
+ yield activity.tool;
219
+ }
183
220
  #interaction(id, pending) {
184
221
  const now = this.time.now();
185
222
  if (pending) {
@@ -192,7 +229,7 @@ export class InvocationWatchdog {
192
229
  if (!this.#interactions.size && this.#waitingSince !== undefined) {
193
230
  // Each timestamp is suspended only for its own overlap with the wait.
194
231
  this.#progressAt += now - Math.max(this.#waitingSince, this.#progressAt);
195
- for (const tool of this.#tools.values()) {
232
+ for (const tool of this.#toolClocks()) {
196
233
  tool.startedAt += now - Math.max(this.#waitingSince, tool.startedAt);
197
234
  tool.progressAt += now - Math.max(this.#waitingSince, tool.progressAt);
198
235
  }
@@ -219,6 +256,7 @@ export class InvocationWatchdog {
219
256
  maxProgressGapMs: Math.floor(Math.max(this.#maxProgressGapMs, now - this.#progressAt)),
220
257
  openToolCount: this.#tools.size,
221
258
  pendingInteractionCount: this.#interactions.size,
259
+ openActivityCount: this.#activities.size,
222
260
  retryCount: this.#retryCount,
223
261
  lastMethod: this.#lastMethod,
224
262
  activitySupport: this.#nativeProgressSeen ? "native_progress" : "canonical_only",
@@ -249,6 +287,10 @@ export class InvocationWatchdog {
249
287
  const tool = toolCallId ? this.#tools.get(toolCallId) : undefined;
250
288
  if (tool)
251
289
  tool.progressAt = now;
290
+ if (toolCallId)
291
+ for (const activity of this.#activities.values())
292
+ if (activity.tool && activity.subject.type === "tool" && activity.subject.id === toolCallId)
293
+ activity.tool.progressAt = now;
252
294
  if (this.#warned) {
253
295
  this.#warned = false;
254
296
  this.#emit("progress_resumed");
@@ -257,7 +299,7 @@ export class InvocationWatchdog {
257
299
  #syncPhase() {
258
300
  const phase = this.#interactions.size
259
301
  ? "waiting_approval"
260
- : this.#tools.size
302
+ : this.#tools.size || this.#activities.size
261
303
  ? "tool_active"
262
304
  : this.#modelStarted
263
305
  ? "model_active"
@@ -284,7 +326,8 @@ export class InvocationWatchdog {
284
326
  ];
285
327
  if (this.#phase === "starting")
286
328
  deadlines.push({
287
- at: this.#startedAt + this.limits.firstFrameTimeoutMs,
329
+ // 工具或人工等待结束后重新进入 starting,从此时重开首帧预算。
330
+ at: this.#phaseAt + this.limits.firstFrameTimeoutMs,
288
331
  reason: "first_frame",
289
332
  budget: this.limits.firstFrameTimeoutMs
290
333
  });
@@ -294,7 +337,7 @@ export class InvocationWatchdog {
294
337
  reason: "model_silence",
295
338
  budget: this.limits.modelIdleTimeoutMs
296
339
  });
297
- for (const tool of this.#phase === "waiting_approval" ? [] : this.#tools.values()) {
340
+ for (const tool of this.#phase === "waiting_approval" ? [] : this.#toolClocks()) {
298
341
  deadlines.push({
299
342
  at: tool.progressAt + this.limits.toolTimeoutMs,
300
343
  reason: "tool_idle",
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@mininglamp-oss/octo-runtime-executor-core",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "exports": "./dist/index.js",
7
7
  "dependencies": {
8
- "@mininglamp-oss/octo-runtime-adapter-sdk": "1.1.4",
9
- "@mininglamp-oss/octo-runtime-protocol": "1.1.4"
8
+ "@mininglamp-oss/octo-runtime-adapter-sdk": "1.1.6",
9
+ "@mininglamp-oss/octo-runtime-protocol": "1.1.6"
10
10
  },
11
11
  "types": "./dist/index.d.ts",
12
12
  "files": [
@@ -3,6 +3,7 @@ import { randomUUID } from "node:crypto";
3
3
  import { assertHostFrame, assertHostFrameIdentity, assertHostRunReceipt, createInputInvoke, identifyInvokeInput, isHostTerminal, HOST_RPC_MAX_LINE_BYTES, INVOKE_REQUEST_MAX_BYTES } from "@mininglamp-oss/octo-runtime-protocol";
4
4
  import { KernelError } from "./types.js";
5
5
  import { InvocationRegistry } from "./invocation-lifecycle.js";
6
+ import { markSubmissionRejected } from "./submission-error.js";
6
7
  /**
7
8
  * 连接本机 socket/Windows Pipe,返回不拥有 Kernel 进程的客户端。
8
9
  * invoke 提供登记、取消和尾流观察;关闭连接或迭代器不会隐式取消已接纳 Run。
@@ -331,6 +332,7 @@ export function attachKernel(options) {
331
332
  catch (error) {
332
333
  if (!submitted)
333
334
  throw error;
335
+ markSubmissionRejected(error, instance);
334
336
  if (error instanceof KernelError &&
335
337
  !["KERNEL_TIMEOUT", "CONNECTION_CLOSED"].includes(error.code))
336
338
  throw error;
@@ -66,7 +66,10 @@ export class InvocationManifest {
66
66
  ...(this.#worker ? { worker: { ...this.#worker } } : {}),
67
67
  invocations: [...this.#invocations.values()].map((entry) => ({ ...entry }))
68
68
  };
69
- this.#writes = this.#writes.then(async () => {
69
+ // 当前调用仍收到自己的 IO 失败;后续完整快照可重试,不能让一次失败毒化整个串行队列。
70
+ this.#writes = this.#writes
71
+ .catch(() => undefined)
72
+ .then(async () => {
70
73
  await writeManifest(this.#path, snapshot);
71
74
  });
72
75
  return this.#writes;
@@ -17,6 +17,13 @@ export interface SpawnWorkerOptions {
17
17
  onSpawn?: (child: ChildProcess) => Promise<void>;
18
18
  }
19
19
  type HostedChild = ChildProcessByStdio<Writable, Readable, Readable>;
20
+ /** 保留失败进程的回收入口;只有重新确认回收成功后,监督器才允许创建替代 worker。 */
21
+ export declare class WorkerCleanupError extends AggregateError {
22
+ readonly retryCleanup: (until: number) => Promise<void>;
23
+ readonly pid?: number | undefined;
24
+ readonly code: string;
25
+ constructor(errors: unknown[], retryCleanup: (until: number) => Promise<void>, pid?: number | undefined);
26
+ }
20
27
  export interface WorkerProcess {
21
28
  client: WorkerRpcClient;
22
29
  child: HostedChild;
@@ -2,6 +2,71 @@ import { createProcessCleanup } from "@mininglamp-oss/octo-runtime-adapter-sdk/p
2
2
  import { execFile, spawn } from "node:child_process";
3
3
  import { setTimeout as delay } from "node:timers/promises";
4
4
  import { WorkerRpcClient } from "./rpc.js";
5
+ /** 保留失败进程的回收入口;只有重新确认回收成功后,监督器才允许创建替代 worker。 */
6
+ export class WorkerCleanupError extends AggregateError {
7
+ retryCleanup;
8
+ pid;
9
+ code;
10
+ constructor(errors, retryCleanup, pid) {
11
+ super(errors, "WORKER_CLEANUP_INCOMPLETE", { cause: errors.at(-1) });
12
+ this.retryCleanup = retryCleanup;
13
+ this.pid = pid;
14
+ const cause = errors.at(-1);
15
+ const code = cause instanceof Error && "code" in cause ? cause.code : undefined;
16
+ this.code =
17
+ typeof code === "string" && /^[A-Z][A-Z0-9_]{0,95}$/.test(code)
18
+ ? code
19
+ : "WORKER_CLEANUP_INCOMPLETE";
20
+ }
21
+ }
22
+ /** 每轮失败后允许重新观测;成功后永不再次向旧 PGID 发信号,避免历史身份被复用。 */
23
+ function workerCleanup(child) {
24
+ let complete = false;
25
+ let pending;
26
+ let failure;
27
+ return () => {
28
+ if (complete)
29
+ return Promise.resolve();
30
+ if (pending)
31
+ return pending;
32
+ // Windows 已观察到树回收失败后,leader 消失也不能抹去未知后代的事实。
33
+ if (process.platform === "win32" &&
34
+ failure &&
35
+ (child.exitCode !== null || child.signalCode !== null))
36
+ return Promise.reject(failure);
37
+ // leader 已退出后,同号 PID 若重新出现就不能再向旧 PGID 发信号。
38
+ // 只在原 PID 仍不存在时确认所属剩余进程组,不扫描或回收其他应用。
39
+ if (process.platform !== "win32" &&
40
+ child.pid !== undefined &&
41
+ (child.exitCode !== null || child.signalCode !== null)) {
42
+ try {
43
+ process.kill(child.pid, 0);
44
+ return Promise.reject(Object.assign(new Error("WORKER_PROCESS_IDENTITY_CONFLICT"), {
45
+ code: "WORKER_PROCESS_IDENTITY_CONFLICT"
46
+ }));
47
+ }
48
+ catch (error) {
49
+ if (error.code !== "ESRCH")
50
+ return Promise.reject(error instanceof Error ? error : new Error("WORKER_IDENTITY_UNKNOWN"));
51
+ }
52
+ }
53
+ pending = createProcessCleanup(child, {
54
+ processGroup: process.platform !== "win32",
55
+ processTree: true
56
+ })()
57
+ .then(() => {
58
+ complete = true;
59
+ })
60
+ .catch((error) => {
61
+ failure = error instanceof Error ? error : new Error("WORKER_CLEANUP_INCOMPLETE");
62
+ throw error;
63
+ })
64
+ .finally(() => {
65
+ pending = undefined;
66
+ });
67
+ return pending;
68
+ };
69
+ }
5
70
  // Reserve more time for tree cleanup until the worker confirms it has started shutdown.
6
71
  // A cooperating worker can use its existing 2.5 s shutdown + 1 s logging bounds.
7
72
  const WINDOWS_CLOSE_GRACE_MS = 4_000;
@@ -37,10 +102,7 @@ export async function spawnWorker({ entrypoint, manifest, adapterModules, env =
37
102
  stdio: ["pipe", "pipe", "pipe", "ipc"],
38
103
  detached: process.platform !== "win32"
39
104
  });
40
- const cleanup = createProcessCleanup(child, {
41
- processGroup: process.platform !== "win32",
42
- processTree: true
43
- });
105
+ const cleanup = workerCleanup(child);
44
106
  let stderr = "";
45
107
  child.stderr.setEncoding("utf8");
46
108
  child.stderr.on("data", (value) => {
@@ -73,7 +135,7 @@ export async function spawnWorker({ entrypoint, manifest, adapterModules, env =
73
135
  await cleanup();
74
136
  }
75
137
  catch (cleanupError) {
76
- throw new AggregateError([error, cleanupError], `${errorMessage(error)}${stderr ? `: ${stderr}` : ""}; cleanup: ${errorMessage(cleanupError)}`, { cause: cleanupError });
138
+ throw new WorkerCleanupError([error, cleanupError], async () => cleanup(), child.pid);
77
139
  }
78
140
  throw new Error(`${errorMessage(error)}${stderr ? `: ${stderr}` : ""}`, { cause: error });
79
141
  }
@@ -108,6 +170,18 @@ export async function spawnWorker({ entrypoint, manifest, adapterModules, env =
108
170
  code: "EXECUTOR_CLEANUP_INCOMPLETE"
109
171
  });
110
172
  }
173
+ catch (error) {
174
+ // 普通 close 仍共享首次结果;恢复专用入口重新执行 OS 确认,不复用 rejected Promise。
175
+ throw new WorkerCleanupError([error], async (retryUntil) => {
176
+ if (drained === "incomplete")
177
+ throw error;
178
+ if (process.platform === "win32" && drained !== "skipped")
179
+ await cleanupWindowsWorker(child, retryUntil);
180
+ else
181
+ await cleanup();
182
+ closing = Promise.resolve();
183
+ }, child.pid);
184
+ }
111
185
  finally {
112
186
  if (process.platform === "win32") {
113
187
  // 正常收尾或 fallback 结束后释放本层管道;回收失败仍向调用方传播。
@@ -1,4 +1,4 @@
1
- import { type AdapterProbeOptions } from "@mininglamp-oss/octo-runtime-adapter-sdk";
1
+ import { type RuntimeLoggingOptions, type AdapterProbeOptions } from "@mininglamp-oss/octo-runtime-adapter-sdk";
2
2
  import { type AdapterModuleEntry } from "@mininglamp-oss/octo-runtime-adapter-sdk/module-manifest";
3
3
  import { type KernelStatus } from "./types.js";
4
4
  export interface KernelServerOptions {
@@ -10,6 +10,8 @@ export interface KernelServerOptions {
10
10
  env?: NodeJS.ProcessEnv;
11
11
  adapterConfigurations?: Record<string, AdapterProbeOptions>;
12
12
  stateDirectory?: string;
13
+ /** 父进程独立记录 worker 监督状态;不依赖 worker 的执行日志,调用方选择日志目录。 */
14
+ logging?: RuntimeLoggingOptions;
13
15
  configurations?: (runtimeId?: string) => Record<string, AdapterProbeOptions>;
14
16
  }
15
17
  /**
@@ -2,7 +2,7 @@ import net from "node:net";
2
2
  import { randomUUID } from "node:crypto";
3
3
  import { chmod, mkdir, rm } from "node:fs/promises";
4
4
  import { dirname, join } from "node:path";
5
- import { readBoundedLines } from "@mininglamp-oss/octo-runtime-adapter-sdk";
5
+ import { readBoundedLines, RuntimeLogging, assertRuntimeLogging } from "@mininglamp-oss/octo-runtime-adapter-sdk";
6
6
  import { assertHostRunReceipt, createInputInvoke, contextItem, INVOKE_REQUEST_MAX_BYTES, HOST_RPC_MAX_LINE_BYTES } from "@mininglamp-oss/octo-runtime-protocol";
7
7
  import { HostRunService } from "./host-run-service.js";
8
8
  import { WorkerSupervisor } from "./supervisor.js";
@@ -72,6 +72,7 @@ function validateParams(method, params) {
72
72
  * 启动失败也执行回收;close 失败会保留所有权证据,客户端断开不等同于 owner 关闭。
73
73
  */
74
74
  export async function startKernelServer(options, signal) {
75
+ assertRuntimeLogging(options.logging);
75
76
  if (options.manifest && options.adapterModules !== undefined)
76
77
  throw new TypeError("manifest and adapterModules are mutually exclusive");
77
78
  // 文件仅在服务启动时读取一次;worker 自动恢复沿用快照,不因磁盘改动改变加载集合。
@@ -79,8 +80,9 @@ export async function startKernelServer(options, signal) {
79
80
  ? resolveAdapterModules(await readModuleManifest(options.manifest, { legacy: true }))
80
81
  : options.adapterModules;
81
82
  const instance = randomUUID();
83
+ const logging = new RuntimeLogging(options.logging);
82
84
  let manifest;
83
- const worker = new WorkerSupervisor({ entrypoint: options.workerEntrypoint, adapterModules, env: options.env }, (pid) => manifest?.setWorker(pid, options.workerEntrypoint) ?? Promise.resolve());
85
+ const worker = new WorkerSupervisor({ entrypoint: options.workerEntrypoint, adapterModules, env: options.env }, (pid) => manifest?.setWorker(pid, options.workerEntrypoint) ?? Promise.resolve(), logging.kernel);
84
86
  const configure = (input) => {
85
87
  const type = contextItem(input.contexts, "octo.execution", "adapter")?.payload.type;
86
88
  return (options.configurations?.(typeof input.runMetadata?.runtimeId === "string" ? input.runMetadata.runtimeId : undefined) ?? options.adapterConfigurations)?.[typeof type === "string" ? type : "codex"];
@@ -187,10 +189,11 @@ export async function startKernelServer(options, signal) {
187
189
  case "agent_run.invoke": {
188
190
  if (params.kernel_instance_id !== undefined && params.kernel_instance_id !== instance)
189
191
  throw new KernelError("KERNEL_INSTANCE_CHANGED");
190
- if (worker.status.state === "exhausted")
191
- throw new KernelError("WORKER_RESTART_EXHAUSTED");
192
+ // 此处尚未调用执行源;专用证据只标记本次拒绝,不能推广到已接纳或 ACK 未知的请求。
192
193
  if (!status().execution_ready)
193
- throw new KernelError("KERNEL_UNAVAILABLE");
194
+ throw new KernelError(worker.status.state === "exhausted"
195
+ ? "WORKER_RESTART_EXHAUSTED"
196
+ : "KERNEL_UNAVAILABLE", { invocation_not_submitted: true });
194
197
  const receipt = await runs.submit(params.input, {
195
198
  executionEnvOverrides: params.executionEnvOverrides
196
199
  });
@@ -292,7 +295,17 @@ export async function startKernelServer(options, signal) {
292
295
  : {
293
296
  jsonrpc: "2.0",
294
297
  id,
295
- error: { code: rpcCode, message: "Kernel request failed", data: { code } }
298
+ error: {
299
+ code: rpcCode,
300
+ message: "Kernel request failed",
301
+ data: {
302
+ code,
303
+ ...(error instanceof KernelError &&
304
+ error.data?.invocation_not_submitted === true
305
+ ? { invocation_not_submitted: true, kernel_instance_id: instance }
306
+ : {})
307
+ }
308
+ }
296
309
  }).catch(() => undefined);
297
310
  socket.end();
298
311
  }
@@ -338,8 +351,11 @@ export async function startKernelServer(options, signal) {
338
351
  await attempt(() => new Promise((resolve) => server.close(() => resolve())));
339
352
  // 先终止 worker 才能让失联的源流结束,再清空 Run 缓存;每个资源仍独立尝试回收并汇总失败。
340
353
  // 内部沿用服务截止时间,为清单和端点收尾预留时间;不重启一份独立关闭预算。
354
+ // 父日志与 worker 独立关闭,重叠使用剩余期限;不能在 worker 排空后再加一秒日志预算。
355
+ const loggingClosed = attempt(() => logging.close());
341
356
  const workerStopped = await attempt(() => worker.close(until - 200));
342
357
  await attempt(() => runs.close());
358
+ await loggingClosed;
343
359
  // An incomplete worker close retains ownership, including an observed executor cleanup failure.
344
360
  if (workerStopped) {
345
361
  await attempt(() => manifest?.close() ?? Promise.resolve());
@@ -7,7 +7,8 @@ export function createKernelService(options) {
7
7
  ...options,
8
8
  adapterModules: options.adapterModules && structuredClone(options.adapterModules),
9
9
  adapterConfigurations: options.adapterConfigurations && structuredClone(options.adapterConfigurations),
10
- env: options.env && { ...options.env }
10
+ env: options.env && { ...options.env },
11
+ logging: options.logging && { ...options.logging }
11
12
  };
12
13
  const owner = new AbortController();
13
14
  let phase = "created";
@@ -1,8 +1,10 @@
1
1
  import { KernelError } from "./types.js";
2
- /** 包内接纳检查专用;只有当前 client 在请求写出前拒绝时才能创建此证据。 */
2
+ /** 包内接纳检查专用;当前 client 在请求写出前拒绝时创建证据。 */
3
3
  export declare function admissionClosedError(): KernelError;
4
+ /** 仅实际 invoke RPC 的拒绝响应、且实例和专用证据均匹配,才标记未进入执行源。 */
5
+ export declare function markSubmissionRejected(error: unknown, instance: string): void;
4
6
  /**
5
- * 判断同一模块实例产生的本地未提交拒绝;包装、序列化及同名错误均返回 false。
6
- * 只证明本次 invoke 未写出,不证明此前业务尝试没有执行,也不授权自动重放。
7
+ * 判断本模块验证的未执行拒绝;包装、序列化及同名错误均返回 false。
8
+ * 只证明本次未进入执行源,不证明此前业务尝试没有执行,也不授权自动重放。
7
9
  */
8
10
  export declare function isInvocationNotSubmitted(error: unknown): boolean;
@@ -1,17 +1,23 @@
1
1
  import { KernelError } from "./types.js";
2
2
  const notSubmitted = new WeakSet();
3
- /** 包内接纳检查专用;只有当前 client 在请求写出前拒绝时才能创建此证据。 */
3
+ /** 包内接纳检查专用;当前 client 在请求写出前拒绝时创建证据。 */
4
4
  export function admissionClosedError() {
5
5
  const error = new KernelError("CLIENT_INVOCATION_ADMISSION_CLOSED");
6
6
  notSubmitted.add(error);
7
7
  return error;
8
8
  }
9
+ /** 仅实际 invoke RPC 的拒绝响应、且实例和专用证据均匹配,才标记未进入执行源。 */
10
+ export function markSubmissionRejected(error, instance) {
11
+ if (error instanceof KernelError &&
12
+ ["KERNEL_UNAVAILABLE", "WORKER_RESTART_EXHAUSTED"].includes(error.code) &&
13
+ error.data?.invocation_not_submitted === true &&
14
+ error.data.kernel_instance_id === instance)
15
+ notSubmitted.add(error);
16
+ }
9
17
  /**
10
- * 判断同一模块实例产生的本地未提交拒绝;包装、序列化及同名错误均返回 false。
11
- * 只证明本次 invoke 未写出,不证明此前业务尝试没有执行,也不授权自动重放。
18
+ * 判断本模块验证的未执行拒绝;包装、序列化及同名错误均返回 false。
19
+ * 只证明本次未进入执行源,不证明此前业务尝试没有执行,也不授权自动重放。
12
20
  */
13
21
  export function isInvocationNotSubmitted(error) {
14
- return (error instanceof KernelError &&
15
- error.code === "CLIENT_INVOCATION_ADMISSION_CLOSED" &&
16
- notSubmitted.has(error));
22
+ return error instanceof KernelError && notSubmitted.has(error);
17
23
  }
@@ -1,11 +1,13 @@
1
1
  import { type SpawnWorkerOptions } from "./process.js";
2
+ import { type RuntimeLog } from "@mininglamp-oss/octo-runtime-adapter-sdk";
2
3
  import type { KernelStatus } from "./types.js";
3
- /** Kernel exclusively owns worker replacement; incomplete cleanup prevents a second owner. */
4
+ /** 监督所属 worker;清理阻塞持续重试,只恢复新请求,不重新执行已丢失的 Run。 */
4
5
  export declare class WorkerSupervisor {
5
6
  #private;
6
7
  private readonly options;
7
8
  private readonly recordWorker?;
8
- constructor(options: SpawnWorkerOptions, recordWorker?: ((pid: number | undefined) => Promise<void>) | undefined);
9
+ private readonly log;
10
+ constructor(options: SpawnWorkerOptions, recordWorker?: ((pid: number | undefined) => Promise<void>) | undefined, log?: RuntimeLog);
9
11
  get status(): KernelStatus["worker"];
10
12
  get client(): import("./rpc.js").WorkerRpcClient;
11
13
  start(signal?: AbortSignal): Promise<void>;