@cobia/pi-onward 0.5.2 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -161,11 +161,11 @@ export class Recovery {
161
161
  const definition = this.registry.get(hit.stage.action.use)?.definition;
162
162
  const problem = this.registry.check(hit.stage.action);
163
163
  if (problem || !definition) {
164
- this.finish(ctx, { kind: "failed", message: problem ?? "Action is not loaded" }, hit);
164
+ this.finish(ctx, { kind: "failed", message: problem ?? "动作未加载" }, hit);
165
165
  return;
166
166
  }
167
167
  if (!definition.modes.includes(ctx.mode)) {
168
- this.finish(ctx, { kind: "failed", message: `${definition.name} does not support ${ctx.mode} mode` }, hit);
168
+ this.finish(ctx, { kind: "failed", message: `${definition.name} 不支持 ${ctx.mode} 模式` }, hit);
169
169
  return;
170
170
  }
171
171
  const chain = this.episode.chain;
@@ -242,7 +242,7 @@ export class Recovery {
242
242
  );
243
243
  if (!command) {
244
244
  this.pending = undefined;
245
- this.finish(ctx, { kind: "failed", message: "Onward dispatch command is unavailable" }, invocation.hit);
245
+ this.finish(ctx, { kind: "failed", message: "onward 的分派命令不可用" }, invocation.hit);
246
246
  return;
247
247
  }
248
248
  // Pi defers this command until ALL agent_settled handlers finish.
@@ -345,21 +345,19 @@ export class Recovery {
345
345
  return definition.execute(params, { ...context, signal });
346
346
  if (definition.phase === "settled" && context.phase === "settled")
347
347
  return definition.execute(params, { ...context, signal });
348
- return { kind: "failed", message: "Action execution phase does not match its context" };
348
+ return { kind: "failed", message: "动作的执行阶段与当前上下文不符" };
349
349
  };
350
350
  const result = await raceAbort(execute(), signal);
351
351
  if (signal.aborted)
352
352
  return {
353
353
  kind: "unknown",
354
- message: timeout.signal.aborted
355
- ? "Action timed out; outcome unknown; not replayed"
356
- : "Execution cancelled; side-effect outcome unknown",
354
+ message: timeout.signal.aborted ? "动作执行超时,结果未知,不会重放" : "执行已取消,副作用是否发生未知",
357
355
  };
358
356
  if (!validResult(result, invocation.definition))
359
- return { kind: "unknown", message: "Action returned an invalid result; not replayed" };
357
+ return { kind: "unknown", message: "动作返回了无效的结果,不会重放" };
360
358
  return result;
361
359
  } catch (error) {
362
- return { kind: "unknown", message: `Action threw an exception; outcome unknown: ${errorText(error)}` };
360
+ return { kind: "unknown", message: `动作抛出异常,结果未知:${errorText(error)}` };
363
361
  } finally {
364
362
  clearTimeout(timer);
365
363
  }
@@ -414,28 +412,33 @@ export class Recovery {
414
412
  }
415
413
  export function stateText(state: RunState, failures: number): string | undefined {
416
414
  if (state.phase === "idle") return undefined;
417
- const phases = {
418
- waiting: "⏳",
419
- submitted: "⏳",
420
- retrying: "⏩",
421
- queued: "⏳",
422
- executing: "🚀",
423
- stopped: "🛑",
424
- };
425
- const results: Record<ActionResult["kind"], string> = {
426
- continue: "⏩",
427
- completed: "🎉",
428
- dispatched: "📤",
429
- handoff: "🔀",
430
- stopped: "🛑",
431
- failed: "💥",
432
- cancelled: "🚫",
433
- unknown: "🎲",
434
- };
435
415
  const result = state.phase === "stopped" ? state.result : undefined;
436
- const icon = result ? results[result] : phases[state.phase];
437
416
  const detail = result === "failed" ? " 动作失败" : result === "unknown" ? " 结果未知" : "";
438
- return `${icon} onward${detail} · 失败${failures}`;
417
+ return `${stateIcon(state)} onward${detail} · 失败${failures}`;
418
+ }
419
+ const PHASE_ICONS: Record<Exclude<RunState["phase"], "idle">, string> = {
420
+ waiting: "⏳",
421
+ submitted: "⏳",
422
+ retrying: "⏩",
423
+ queued: "⏳",
424
+ executing: "🚀",
425
+ stopped: "🛑",
426
+ };
427
+ const RESULT_ICONS: Record<ActionResult["kind"], string> = {
428
+ continue: "⏩",
429
+ completed: "🎉",
430
+ dispatched: "📤",
431
+ handoff: "🔀",
432
+ stopped: "🛑",
433
+ failed: "💥",
434
+ cancelled: "🚫",
435
+ unknown: "🎲",
436
+ };
437
+ /** 恢复进行中的图标:状态栏和菜单、status 标题共用,同一状态只有一个图标。 */
438
+ export function stateIcon(state: RunState): string {
439
+ if (state.phase === "idle") return "⏩";
440
+ const result = state.phase === "stopped" ? state.result : undefined;
441
+ return result ? RESULT_ICONS[result] : PHASE_ICONS[state.phase];
439
442
  }
440
443
  function validResult(value: unknown, definition: ActionDefinition): value is ActionResult {
441
444
  if (!isRecord(value) || typeof value.kind !== "string") return false;