@oyasmi/pipiclaw 0.9.3-beta.6 → 0.9.4-beta.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.
Files changed (118) hide show
  1. package/README.en.md +1 -1
  2. package/README.md +1 -1
  3. package/dist/agent/channel-runner.js +137 -61
  4. package/dist/agent/command-extension.js +47 -34
  5. package/dist/agent/job-manager.js +31 -11
  6. package/dist/agent/model-fallback.js +1 -1
  7. package/dist/agent/prompt/manifest.d.ts +6 -1
  8. package/dist/agent/prompt/manifest.js +45 -64
  9. package/dist/agent/prompt/resources.js +4 -1
  10. package/dist/agent/run-queue.js +7 -2
  11. package/dist/agent/session-adapter.js +1 -1
  12. package/dist/agent/session-events.js +17 -6
  13. package/dist/agent/session-resource-gate.js +3 -1
  14. package/dist/agent/status-render.d.ts +0 -1
  15. package/dist/agent/status-render.js +4 -16
  16. package/dist/agent/turn-error.d.ts +31 -0
  17. package/dist/agent/turn-error.js +68 -0
  18. package/dist/app-services.js +7 -4
  19. package/dist/channel/channel-index.d.ts +9 -2
  20. package/dist/channel/channel-index.js +29 -7
  21. package/dist/channel/project-scope-store.js +1 -1
  22. package/dist/commands/catalog.d.ts +21 -4
  23. package/dist/commands/catalog.js +88 -41
  24. package/dist/commands/reply-limits.d.ts +6 -0
  25. package/dist/commands/reply-limits.js +24 -0
  26. package/dist/events/event-commands.js +94 -44
  27. package/dist/events/event-validation.d.ts +13 -2
  28. package/dist/events/event-validation.js +17 -9
  29. package/dist/events/events.js +77 -32
  30. package/dist/executor.js +2 -2
  31. package/dist/log.d.ts +12 -2
  32. package/dist/log.js +26 -34
  33. package/dist/main.js +1 -1
  34. package/dist/memory/commands.js +29 -23
  35. package/dist/memory/lifecycle.js +26 -5
  36. package/dist/memory/maintenance-state.js +4 -1
  37. package/dist/memory/scheduler.js +3 -1
  38. package/dist/models/auth-cli.js +3 -2
  39. package/dist/paths.d.ts +2 -0
  40. package/dist/paths.js +9 -0
  41. package/dist/playbooks/agent-delegation.md +2 -2
  42. package/dist/runtime/app-home.d.ts +6 -0
  43. package/dist/runtime/app-home.js +21 -3
  44. package/dist/runtime/bootstrap.js +192 -64
  45. package/dist/runtime/channel-queue.js +1 -1
  46. package/dist/runtime/delivery.js +29 -15
  47. package/dist/runtime/dingtalk.js +96 -42
  48. package/dist/runtime/durable-dispatch.d.ts +27 -1
  49. package/dist/runtime/durable-dispatch.js +111 -3
  50. package/dist/runtime/project-commands.js +16 -15
  51. package/dist/runtime/proxy.js +4 -2
  52. package/dist/runtime/report-commands.js +1 -1
  53. package/dist/runtime/skill-commands.d.ts +1 -1
  54. package/dist/runtime/skill-commands.js +17 -10
  55. package/dist/runtime/subagent-commands.d.ts +5 -4
  56. package/dist/runtime/subagent-commands.js +116 -77
  57. package/dist/runtime/task-commands.d.ts +1 -1
  58. package/dist/runtime/task-commands.js +110 -64
  59. package/dist/runtime/task-driver.d.ts +6 -3
  60. package/dist/runtime/task-driver.js +57 -22
  61. package/dist/runtime/task-migration.d.ts +7 -2
  62. package/dist/runtime/task-migration.js +247 -61
  63. package/dist/runtime/task-spawn.js +12 -5
  64. package/dist/runtime/wake-coalescing.d.ts +18 -0
  65. package/dist/runtime/wake-coalescing.js +29 -0
  66. package/dist/security/block-message.d.ts +22 -1
  67. package/dist/security/block-message.js +66 -1
  68. package/dist/security/network.d.ts +2 -1
  69. package/dist/security/network.js +3 -2
  70. package/dist/security/path-guard-check.js +2 -2
  71. package/dist/settings.d.ts +3 -2
  72. package/dist/settings.js +4 -1
  73. package/dist/shared/format.d.ts +12 -0
  74. package/dist/shared/format.js +37 -0
  75. package/dist/shared/host-process.js +15 -3
  76. package/dist/shared/with-timeout.d.ts +3 -2
  77. package/dist/shared/with-timeout.js +14 -3
  78. package/dist/subagents/external/claude-code.js +23 -1
  79. package/dist/subagents/external/progress-tail.d.ts +17 -0
  80. package/dist/subagents/external/progress-tail.js +64 -17
  81. package/dist/subagents/external/run.d.ts +3 -0
  82. package/dist/subagents/external/run.js +21 -7
  83. package/dist/subagents/external/settlement.d.ts +3 -0
  84. package/dist/subagents/external/settlement.js +1 -1
  85. package/dist/subagents/runs.d.ts +21 -1
  86. package/dist/subagents/runs.js +137 -32
  87. package/dist/subagents/tool.d.ts +22 -15
  88. package/dist/subagents/tool.js +226 -32
  89. package/dist/subagents/workspace-summary.d.ts +16 -4
  90. package/dist/subagents/workspace-summary.js +74 -18
  91. package/dist/tasks/board.d.ts +8 -1
  92. package/dist/tasks/board.js +37 -2
  93. package/dist/tasks/frontmatter.d.ts +5 -0
  94. package/dist/tasks/frontmatter.js +8 -0
  95. package/dist/tasks/log.d.ts +11 -1
  96. package/dist/tasks/log.js +58 -2
  97. package/dist/tasks/store.d.ts +18 -1
  98. package/dist/tasks/store.js +61 -9
  99. package/dist/tasks/ticket.d.ts +3 -1
  100. package/dist/tasks/ticket.js +19 -1
  101. package/dist/tools/bash.js +2 -2
  102. package/dist/tools/index.d.ts +2 -0
  103. package/dist/tools/index.js +1 -0
  104. package/dist/tools/memory-manage.js +4 -1
  105. package/dist/tools/subagent-manage.d.ts +1 -1
  106. package/dist/tools/subagent-manage.js +16 -11
  107. package/dist/tools/task-manage/step-end.js +4 -1
  108. package/dist/tools/tool-details.d.ts +10 -2
  109. package/dist/tools/tool-details.js +39 -2
  110. package/dist/tui/cli.js +2 -2
  111. package/dist/tui/commands.js +4 -4
  112. package/dist/tui/pitui-frontend.js +1 -1
  113. package/dist/tui/renderer.js +3 -2
  114. package/dist/tui/turn-controller.d.ts +2 -0
  115. package/dist/tui/turn-controller.js +36 -21
  116. package/dist/usage/ledger.js +3 -1
  117. package/dist/usage/render.js +3 -1
  118. package/package.json +1 -1
package/README.en.md CHANGED
@@ -22,7 +22,7 @@ In DingTalk daemon mode, external tasks keep running in the background after dis
22
22
 
23
23
  ### Work does not end when a conversation ends
24
24
 
25
- Every channel has its own persistent conversation, long-term memory index, and daily journal. The task ledger stores goals, done criteria, and plans in Markdown contracts, with steps and verification records in JSONL loop logs; the built-in task driver resumes work from waiting tickets and schedules, and stops with a notice when a budget, idle-loop, or repeated-expiry boundary is reached.
25
+ Every channel has its own persistent conversation, long-term memory index, and daily journal. Each task is a one-off project with goals, done criteria, and work items in a Markdown contract, and steps, dispatches, and settlements in a JSONL loop log; the built-in task driver advances runnable tasks, redeems due time tickets, and handles ticket expiry. Scheduled and recurring work uses event templates to create an independent task instance per occurrence. The runtime stops with a notice when a budget, idle-loop, or repeated-expiry boundary is reached.
26
26
 
27
27
  ### Natively at home in DingTalk
28
28
 
package/README.md CHANGED
@@ -22,7 +22,7 @@ Pipiclaw 同时支持两类委派:内置子智能体在进程内完成检索
22
22
 
23
23
  ### 工作不会随着一次对话结束
24
24
 
25
- 每个频道都有独立的持久会话、长期记忆索引和按天日志。任务台账用 Markdown 保存目标、完成标准和计划,用 JSONL 循环日志记录步骤与验收;内建 task driver 根据等待票和周期调度恢复工作,预算耗尽、空转或连续无法兑现等待时会停止并告诉你。
25
+ 每个频道都有独立的持久会话、长期记忆索引和按天日志。任务是一次性项目,用 Markdown 保存目标、完成标准和工作项,用 JSONL 循环日志记录步骤、派发与结算;内建 task driver 推进可运行任务、兑现到期等待票并处理兜底超时,周期与定时工作由事件模板每次生成独立任务实例,预算耗尽、空转或连续无法兑现等待时会停止并告诉你。
26
26
 
27
27
  ### 原生工作在钉钉里
28
28
 
@@ -6,7 +6,7 @@ import { dirname, join, resolve } from "path";
6
6
  import { commitActiveSessionRef, resolveActiveSessionFile } from "../channel/active-session-store.js";
7
7
  import { MAX_INBOUND_IMAGE_BYTES } from "../channel/channel-event.js";
8
8
  import { resolveProjectScope } from "../channel/project-scope-store.js";
9
- import { isKnownCommandName, renderBuiltInHelp, slashCommandName, } from "../commands/catalog.js";
9
+ import { formatMissingQueueMessage, formatNoRunningTurn, isKnownCommandName, renderBuiltInHelp, slashCommandName, } from "../commands/catalog.js";
10
10
  import * as log from "../log.js";
11
11
  import { handleMemoryCommand } from "../memory/commands.js";
12
12
  import { buildChannelIndexForBootstrap, clipJournalTailForBootstrap, clipWorkspaceMemoryForBootstrap, } from "../memory/index-budget.js";
@@ -44,6 +44,7 @@ import { createRunQueue } from "./run-queue.js";
44
44
  import { asSdkSettingsManager, cycleThinkingLevelWithConditionalPersist, DEFAULT_MAIN_THINKING_LEVEL, initializeThinkingLevelCompat, setModelWithThinkingPreservation, setSessionBaseToolsOverride, setThinkingLevelWithConditionalPersist, } from "./session-adapter.js";
45
45
  import { handleSessionEvent } from "./session-events.js";
46
46
  import { SessionResourceGate } from "./session-resource-gate.js";
47
+ import { renderFallbackSwitch, renderTurnErrorReply } from "./turn-error.js";
47
48
  import { assembleTurnPrompt } from "./turn-prompt.js";
48
49
  import { recoverInterruptedTurn } from "./turn-recovery.js";
49
50
  import { TurnStateMachine } from "./turn-state.js";
@@ -103,7 +104,7 @@ export class ChannelRunner {
103
104
  /** Mirror of `tools.tasks.enabled` from the last tools-config load (see buildRuntimeTools). */
104
105
  this.tasksEnabled = true;
105
106
  /** Single owner of turn state; see TurnPhase in types.ts and TurnStateMachine in turn-state.ts. */
106
- this.turnState = new TurnStateMachine((message, detail) => log.logWarning(`[${this.channelId}] ${message}`, detail));
107
+ this.turnState = new TurnStateMachine((message, detail) => log.logWarn("agent.session.warning", message, { channelId: this.channelId, reason: detail }));
107
108
  /** Set once transport-level `/new` replaces this generation. A retired runner is never reused. */
108
109
  this.retired = false;
109
110
  /** When the primary model last failed and we switched to the backup. null = on primary. */
@@ -160,13 +161,22 @@ export class ChannelRunner {
160
161
  `Back up ${join(channelDir, activeSessionFile)} on the host, move it aside, then use /new to start a fresh session.`);
161
162
  }
162
163
  if (recoveryOutcome.kind === "repaired") {
163
- log.logWarning(`[${channelId}] Repaired an interrupted turn on restart`, `toolResults=${recoveryOutcome.appendedToolResults} abortedAssistant=${recoveryOutcome.appendedAbortedAssistant}`);
164
+ log.logWarn("agent.turn.repaired", "Interrupted turn repaired on restart", {
165
+ channelId: channelId,
166
+ fields: {
167
+ toolResults: recoveryOutcome.appendedToolResults,
168
+ abortedAssistant: recoveryOutcome.appendedAbortedAssistant,
169
+ },
170
+ });
164
171
  }
165
172
  this.settingsManager = paths.settingsManager;
166
173
  this.reportSettingsDiagnostics();
167
174
  this.memoryActivityRecorder = createMemoryActivityRecorder({
168
175
  appHomeDir: this.appHomeDir,
169
- onError: (channelId, error) => log.logWarning(`[${channelId}] Failed to record memory maintenance state`, errorMessage(error)),
176
+ onError: (channelId, error) => log.logWarn("memory.state.record_failed", "Memory maintenance state record failed", {
177
+ channelId: channelId,
178
+ reason: errorMessage(error),
179
+ }),
170
180
  });
171
181
  this.activeModel = defaultModel;
172
182
  this.memoryLifecycle = new MemoryLifecycle({
@@ -237,7 +247,7 @@ export class ChannelRunner {
237
247
  if (normalizedInputLength > MAX_USER_MESSAGE_CHARS) {
238
248
  oversizedInputPath = await this.persistOversizedInput(ctx.message.text);
239
249
  await ctx.respondInThread(oversizedInputPath
240
- ? `⚠️ 消息过长(${normalizedInputLength} 字符),已截断至约 ${MAX_USER_MESSAGE_CHARS} 字符后处理;完整内容已存到 \`${oversizedInputPath}\`,可以让我 read 该文件查看被省略的部分。`
250
+ ? `⚠️ 消息过长(${normalizedInputLength} 字符),已截断至约 ${MAX_USER_MESSAGE_CHARS} 字符后处理;完整内容已存到 \`${oversizedInputPath}\`,需要时让我读取这个文件查看被省略的部分。`
241
251
  : `⚠️ 消息过长(${normalizedInputLength} 字符),已截断至约 ${MAX_USER_MESSAGE_CHARS} 字符后处理。`);
242
252
  }
243
253
  const clippedInput = clipUserInput(ctx.message.text, MAX_USER_MESSAGE_CHARS, oversizedInputPath);
@@ -346,12 +356,12 @@ export class ChannelRunner {
346
356
  if (this.runState.logCtx) {
347
357
  log.logModelFallback(this.runState.logCtx, from, to, errorSummary);
348
358
  }
349
- const text = `⚠️ 模型 ${from} 出错(${errorSummary}),切换到 ${to} 重试…`;
359
+ const text = renderFallbackSwitch(from, to, errorSummary);
350
360
  if (ctx.progressStyle !== "none") {
351
361
  runQueue.queue.enqueue(() => ctx.respond(formatProgressEntry("error", text), false), "fallback switch");
352
362
  }
353
363
  else {
354
- runQueue.queue.enqueue(() => ctx.respondInThread(text), "fallback switch");
364
+ runQueue.queue.enqueue(() => ctx.respondInThread(`⚠️ ${text}`), "fallback switch");
355
365
  }
356
366
  },
357
367
  markPrimaryFailed: () => {
@@ -415,13 +425,19 @@ export class ChannelRunner {
415
425
  taskDigest: input.taskDigestText || undefined,
416
426
  newUserMessage: input.promptText,
417
427
  };
418
- await writeFile(join(this.channelDir, "last_prompt.json"), JSON.stringify(debugContext, null, 2)).catch((error) => log.logWarning(`[${this.channelId}] Failed to write last_prompt.json`, errorMessage(error)));
428
+ await writeFile(join(this.channelDir, "last_prompt.json"), JSON.stringify(debugContext, null, 2)).catch((error) => log.logWarn("agent.debug.dump_failed", "last_prompt.json write failed", {
429
+ channelId: this.channelId,
430
+ reason: errorMessage(error),
431
+ }));
419
432
  }
420
433
  if (!promptSubmitted) {
421
434
  const discarded = this.session.clearQueue();
422
435
  const discardedCount = discarded.steering.length + discarded.followUp.length;
423
436
  if (discardedCount > 0) {
424
- log.logWarning(`[${this.channelId}] Discarded ${discardedCount} queued busy message(s) after run setup failed`);
437
+ log.logWarn("agent.turn.queue_discarded", "Queued busy messages discarded after run setup failed", {
438
+ channelId: this.channelId,
439
+ fields: { count: discardedCount },
440
+ });
425
441
  }
426
442
  }
427
443
  await runQueue.drain();
@@ -432,46 +448,45 @@ export class ChannelRunner {
432
448
  this.runState.errorMessage &&
433
449
  !this.runState.finalResponseDelivered) {
434
450
  try {
435
- const baseErrorSummary = this.runState.errorMessage.length > 240
436
- ? `${this.runState.errorMessage.slice(0, 237)}...`
437
- : this.runState.errorMessage;
438
- const compactionSummary = this.runState.lastCompactionError && this.runState.lastCompactionError !== this.runState.errorMessage
439
- ? this.runState.lastCompactionError.length > 240
440
- ? `${this.runState.lastCompactionError.slice(0, 237)}...`
441
- : this.runState.lastCompactionError
442
- : undefined;
443
- const detailLines = [`\`${baseErrorSummary}\``];
444
- if (compactionSummary) {
445
- detailLines.push(`恢复尝试:\`${compactionSummary}\``);
446
- }
447
- if (fallbackAttempted && fallbackTargetRef) {
448
- detailLines.push(`已切换备用模型 \`${fallbackTargetRef}\` 重试,仍失败。`);
449
- }
450
- await ctx.replaceMessage(`_抱歉,出错了。_\n\n${detailLines.join("\n\n")}`);
451
+ const compactionError = this.runState.lastCompactionError;
452
+ await ctx.replaceMessage(renderTurnErrorReply({
453
+ errorMessage: this.runState.errorMessage,
454
+ compactionError: compactionError && compactionError !== this.runState.errorMessage ? compactionError : undefined,
455
+ fallbackRef: fallbackAttempted ? fallbackTargetRef : undefined,
456
+ }));
451
457
  }
452
458
  catch (err) {
453
459
  const errMsg = errorMessage(err);
454
- log.logWarning("Failed to post error message", errMsg);
460
+ log.logWarn("delivery.error_reply.failed", "Error reply failed", {
461
+ channelId: this.channelId,
462
+ reason: errMsg,
463
+ });
455
464
  }
456
465
  }
457
466
  else if (isSilentOutcome(finalOutcome)) {
458
467
  try {
459
468
  await ctx.deleteMessage();
460
- log.logInfo("Silent response - ended progress delivery");
469
+ log.logInfo(`[${this.channelId}] Silent response ended progress delivery`);
461
470
  }
462
471
  catch (err) {
463
472
  const errMsg = errorMessage(err);
464
- log.logWarning("Failed to delete message for silent response", errMsg);
473
+ log.logWarn("delivery.silent_cleanup.failed", "Silent-response cleanup failed", {
474
+ channelId: this.channelId,
475
+ reason: errMsg,
476
+ });
465
477
  }
466
478
  }
467
479
  else if (this.runState.stopReason === "aborted" && !this.runState.finalResponseDelivered) {
468
480
  try {
469
481
  await ctx.deleteMessage();
470
- log.logInfo("Aborted response - discarded active delivery state");
482
+ log.logInfo(`[${this.channelId}] Aborted response discarded active delivery state`);
471
483
  }
472
484
  catch (err) {
473
485
  const errMsg = errorMessage(err);
474
- log.logWarning("Failed to discard active delivery state after abort", errMsg);
486
+ log.logWarn("delivery.abort_cleanup.failed", "Aborted-response cleanup failed", {
487
+ channelId: this.channelId,
488
+ reason: errMsg,
489
+ });
475
490
  }
476
491
  }
477
492
  else if (finalOutcomeText && !this.runState.finalResponseDelivered) {
@@ -480,7 +495,10 @@ export class ChannelRunner {
480
495
  }
481
496
  catch (err) {
482
497
  const errMsg = errorMessage(err);
483
- log.logWarning("Failed to replace message with final text", errMsg);
498
+ log.logWarn("delivery.final_reply.failed", "Final reply replacement failed", {
499
+ channelId: this.channelId,
500
+ reason: errMsg,
501
+ });
484
502
  }
485
503
  }
486
504
  await ctx.flush();
@@ -549,15 +567,15 @@ export class ChannelRunner {
549
567
  await this.sendCommandReply(ctx, this.renderContextReport(command.args), "context");
550
568
  return;
551
569
  case "stop":
552
- await this.sendCommandReply(ctx, "当前没有运行中的回合,`/stop` 只在回合进行中有意义。", "stop");
570
+ await this.sendCommandReply(ctx, formatNoRunningTurn("stop"), "stop");
553
571
  return;
554
572
  case "steer":
555
573
  this.requireQueuedMessage(command.args, "steer");
556
- await this.sendCommandReply(ctx, "当前没有运行中的回合,直接发消息即可,不用 `/steer`。", "steer");
574
+ await this.sendCommandReply(ctx, formatNoRunningTurn("steer"), "steer");
557
575
  return;
558
576
  case "followup":
559
577
  this.requireQueuedMessage(command.args, "followup");
560
- await this.sendCommandReply(ctx, "当前没有运行中的回合,直接发消息即可;`/followup` 用于回合进行中排队。", "followup");
578
+ await this.sendCommandReply(ctx, formatNoRunningTurn("followup"), "followup");
561
579
  return;
562
580
  default: {
563
581
  // The stateless report commands (events/tasks/status/usage/subagents/project — see
@@ -571,7 +589,7 @@ export class ChannelRunner {
571
589
  }
572
590
  catch (err) {
573
591
  const errMsg = errorMessage(err);
574
- log.logWarning(`[${this.channelId}] Built-in command failed`, errMsg);
592
+ log.logWarn("agent.command.failed", "Built-in command failed", { channelId: this.channelId, reason: errMsg });
575
593
  await this.sendCommandReply(ctx, `命令执行失败:${errMsg}`, command.name);
576
594
  }
577
595
  }
@@ -611,7 +629,9 @@ export class ChannelRunner {
611
629
  if (this.isBusy()) {
612
630
  // `session.dispose()` aborts in-flight work; a busy runner keeps its session and
613
631
  // subscription until whoever holds it calls dispose() again once idle.
614
- log.logWarning(`[${this.channelId}] dispose() called while busy; session left intact`, "");
632
+ log.logWarn("agent.session.dispose_skipped", "Dispose skipped while busy; session left intact", {
633
+ channelId: this.channelId,
634
+ });
615
635
  return;
616
636
  }
617
637
  // Guards a dispose() racing construction: initializeSession assigns `this.session`
@@ -623,7 +643,10 @@ export class ChannelRunner {
623
643
  this.session.dispose();
624
644
  }
625
645
  catch (error) {
626
- log.logWarning(`[${this.channelId}] Session dispose failed`, errorMessage(error));
646
+ log.logWarn("agent.session.dispose_failed", "Session dispose failed", {
647
+ channelId: this.channelId,
648
+ reason: errorMessage(error),
649
+ });
627
650
  }
628
651
  }
629
652
  async getMemoryMaintenanceContext() {
@@ -729,9 +752,7 @@ export class ChannelRunner {
729
752
  }
730
753
  const sections = [help];
731
754
  if (this.session.promptTemplates.length > 0) {
732
- sections.push(`**Prompt templates**\n\n${this.session.promptTemplates
733
- .map((template) => `- \`/${template.name}\``)
734
- .join("\n")}`);
755
+ sections.push(`**提示模板**\n\n${this.session.promptTemplates.map((template) => `- \`/${template.name}\``).join("\n")}`);
735
756
  }
736
757
  return sections.join("\n\n");
737
758
  }
@@ -782,13 +803,16 @@ export class ChannelRunner {
782
803
  await this.memoryActivityRecorder.flush(this.channelId);
783
804
  }
784
805
  catch (error) {
785
- log.logWarning(`[${this.channelId}] Failed to flush memory maintenance state`, errorMessage(error));
806
+ log.logWarn("memory.state.flush_failed", "Memory maintenance state flush failed", {
807
+ channelId: this.channelId,
808
+ reason: errorMessage(error),
809
+ });
786
810
  }
787
811
  }
788
812
  requireQueuedMessage(text, commandName) {
789
813
  const trimmedText = text.trim();
790
814
  if (!trimmedText) {
791
- throw new Error(`/${commandName} requires a message.`);
815
+ throw new Error(formatMissingQueueMessage(commandName));
792
816
  }
793
817
  return trimmedText;
794
818
  }
@@ -815,7 +839,10 @@ export class ChannelRunner {
815
839
  return path;
816
840
  }
817
841
  catch (error) {
818
- log.logWarning("Could not persist oversized user message", errorMessage(error));
842
+ log.logWarn("agent.input.persist_failed", "Oversized user message could not be saved", {
843
+ channelId: this.channelId,
844
+ reason: errorMessage(error),
845
+ });
819
846
  return undefined;
820
847
  }
821
848
  }
@@ -856,7 +883,7 @@ export class ChannelRunner {
856
883
  notices: [
857
884
  `⚠️ 当前模型 ${modelRef} 不支持图片输入,收到的图片已保存但未加入本轮上下文:\n` +
858
885
  images.map((image) => `- \`${image.path}\``).join("\n") +
859
- "\n可以切换到支持视觉的模型后让我 read 该文件。",
886
+ "\n用 `/model` 切换到支持图片的模型后,再让我读取这些图片。",
860
887
  ],
861
888
  };
862
889
  }
@@ -866,7 +893,7 @@ export class ChannelRunner {
866
893
  if (image.unsupportedFormat)
867
894
  continue;
868
895
  if (image.byteSize > MAX_INBOUND_IMAGE_BYTES) {
869
- notices.push(`⚠️ 图片 \`${image.path}\`(${formatSize(image.byteSize)})超过 ${formatSize(MAX_INBOUND_IMAGE_BYTES)} 上限,未加入本轮上下文,可以让我 read 该文件查看。`);
896
+ notices.push(`⚠️ 图片 \`${image.path}\`(${formatSize(image.byteSize)})超过 ${formatSize(MAX_INBOUND_IMAGE_BYTES)} 上限,未加入本轮上下文;需要时让我读取这个文件。`);
870
897
  continue;
871
898
  }
872
899
  try {
@@ -901,7 +928,10 @@ export class ChannelRunner {
901
928
  const oversizedPath = oversized ? await this.persistOversizedInput(text) : undefined;
902
929
  const clippedText = clipUserInput(text, MAX_USER_MESSAGE_CHARS, oversizedPath);
903
930
  if (oversized) {
904
- log.logWarning(`[${this.channelId}] Queued message exceeded ${MAX_USER_MESSAGE_CHARS} chars and was clipped`);
931
+ log.logWarn("agent.input.clipped", "Queued message clipped", {
932
+ channelId: this.channelId,
933
+ fields: { limitChars: MAX_USER_MESSAGE_CHARS },
934
+ });
905
935
  }
906
936
  const queuedMessage = this.formatUserMessage(clippedText, userName);
907
937
  const preparedImages = await this.prepareInboundImages(images);
@@ -949,7 +979,10 @@ export class ChannelRunner {
949
979
  log.logInfo(`[${this.channelId}] Restored primary model ${formatModelReference(this.activeModel)}`);
950
980
  }
951
981
  catch (err) {
952
- log.logWarning(`[${this.channelId}] Failed to restore primary model`, errorMessage(err));
982
+ log.logWarn("agent.model.restore_failed", "Primary model restore failed", {
983
+ channelId: this.channelId,
984
+ reason: errorMessage(err),
985
+ });
953
986
  }
954
987
  }
955
988
  async setModelWithThinkingPreservation(model) {
@@ -975,14 +1008,20 @@ export class ChannelRunner {
975
1008
  const available = this.modelRegistry.getAvailable();
976
1009
  const { match, ambiguous } = findExactModelReferenceMatch(reference, available);
977
1010
  if (!match) {
978
- log.logWarning(`[${this.channelId}] fallbackModel "${reference}" ${ambiguous ? "is ambiguous" : "not found"}; skipping fallback`);
1011
+ log.logWarn("agent.model.fallback_unresolved", "Fallback model skipped", {
1012
+ channelId: this.channelId,
1013
+ fields: { reference, problem: ambiguous ? "ambiguous" : "not found" },
1014
+ });
979
1015
  return null;
980
1016
  }
981
1017
  try {
982
1018
  await getApiKeyForModel(this.modelRegistry, match);
983
1019
  }
984
1020
  catch {
985
- log.logWarning(`[${this.channelId}] fallbackModel "${reference}" has no API key; skipping fallback`);
1021
+ log.logWarn("agent.model.fallback_unresolved", "Fallback model skipped", {
1022
+ channelId: this.channelId,
1023
+ fields: { reference, problem: "no API key" },
1024
+ });
986
1025
  return null;
987
1026
  }
988
1027
  return match;
@@ -1045,7 +1084,10 @@ export class ChannelRunner {
1045
1084
  await withTimeout(`[${this.channelId}] session reload`, SESSION_RELOAD_TIMEOUT_MS, () => this.session.reload());
1046
1085
  }
1047
1086
  catch (error) {
1048
- log.logWarning(`[${this.channelId}] Session reload did not settle`, errorMessage(error));
1087
+ log.logWarn("agent.session.reload_unsettled", "Session reload did not settle", {
1088
+ channelId: this.channelId,
1089
+ reason: errorMessage(error),
1090
+ });
1049
1091
  }
1050
1092
  }
1051
1093
  async bindSessionExtensions() {
@@ -1097,7 +1139,10 @@ export class ChannelRunner {
1097
1139
  }
1098
1140
  catch (error) {
1099
1141
  const message = errorMessage(error);
1100
- log.logWarning(`[${this.channelId}] Preventive compaction failed`, message);
1142
+ log.logWarn("agent.compaction.preventive_failed", "Preventive compaction failed", {
1143
+ channelId: this.channelId,
1144
+ reason: message,
1145
+ });
1101
1146
  }
1102
1147
  }
1103
1148
  async refreshSubAgentDiscovery() {
@@ -1109,22 +1154,32 @@ export class ChannelRunner {
1109
1154
  await withTimeout(`[${this.channelId}] model registry refresh`, MODEL_REGISTRY_REFRESH_TIMEOUT_MS, () => this.modelRegistry.refresh());
1110
1155
  }
1111
1156
  catch (error) {
1112
- log.logWarning(`[${this.channelId}] Model registry refresh did not settle; using the previous model snapshot`, errorMessage(error));
1157
+ log.logWarn("agent.models.refresh_unsettled", "Model registry refresh did not settle; using the previous snapshot", { channelId: this.channelId, reason: errorMessage(error) });
1113
1158
  }
1114
1159
  const discovery = discoverSubAgents(this.workspaceDir, this.modelRegistry.getAvailable());
1115
1160
  for (const warning of discovery.warnings) {
1116
- log.logWarning(`Sub-agent config warning (${this.channelId})`, warning);
1161
+ log.logWarn("config.subagents.warning", "Sub-agent config warning", {
1162
+ channelId: this.channelId,
1163
+ reason: warning,
1164
+ });
1117
1165
  }
1118
1166
  return discovery;
1119
1167
  }
1120
1168
  reportSettingsDiagnostics() {
1121
1169
  for (const { scope, error } of this.settingsManager.drainErrors()) {
1122
- log.logWarning(`[${this.channelId}] Failed to load ${scope} settings`, `${error.message}\n${join(this.appHomeDir, "settings.json")}`);
1170
+ log.logWarn("config.settings.load_failed", "Settings load failed", {
1171
+ channelId: this.channelId,
1172
+ reason: error.message,
1173
+ fields: { scope, path: join(this.appHomeDir, "settings.json") },
1174
+ });
1123
1175
  }
1124
1176
  }
1125
1177
  reportConfigDiagnostics(diagnostics) {
1126
1178
  for (const diagnostic of diagnostics) {
1127
- log.logWarning(`[${this.channelId}] ${formatConfigDiagnostic(diagnostic)}`, diagnostic.path);
1179
+ log.logWarn("config.diagnostic", formatConfigDiagnostic(diagnostic), {
1180
+ channelId: this.channelId,
1181
+ fields: { path: diagnostic.path },
1182
+ });
1128
1183
  }
1129
1184
  }
1130
1185
  /**
@@ -1162,7 +1217,11 @@ export class ChannelRunner {
1162
1217
  for (const diagnostic of [...resources.diagnostics, ...build.diagnostics]) {
1163
1218
  if (diagnostic.level === "info")
1164
1219
  continue;
1165
- log.logWarning(`[${this.channelId}] Prompt ${diagnostic.level} (${diagnostic.sectionId})`, diagnostic.message);
1220
+ log.logWarn("agent.prompt.diagnostic", "Prompt section diagnostic", {
1221
+ channelId: this.channelId,
1222
+ reason: diagnostic.message,
1223
+ fields: { level: diagnostic.level, section: diagnostic.sectionId },
1224
+ });
1166
1225
  }
1167
1226
  // Only a real change is worth a line: a reload that produced the same bytes is noise.
1168
1227
  if (this.lastPromptBuild?.fingerprint !== build.fingerprint) {
@@ -1225,7 +1284,11 @@ export class ChannelRunner {
1225
1284
  skillsOverride: (base) => {
1226
1285
  const merged = resolvePipiclawSkills(base, this.currentSkills);
1227
1286
  for (const diagnostic of merged.diagnostics) {
1228
- log.logWarning(`[${this.channelId}] Skill ${diagnostic.type}`, `${diagnostic.message}${diagnostic.path ? ` (${diagnostic.path})` : ""}`);
1287
+ log.logWarn("agent.skills.diagnostic", "Skill diagnostic", {
1288
+ channelId: this.channelId,
1289
+ reason: diagnostic.message,
1290
+ fields: { type: diagnostic.type, path: diagnostic.path },
1291
+ });
1229
1292
  }
1230
1293
  return merged;
1231
1294
  },
@@ -1256,7 +1319,10 @@ export class ChannelRunner {
1256
1319
  await withTimeout(`[${this.channelId}] session resource load`, SESSION_RELOAD_TIMEOUT_MS, () => resourceLoader.reload());
1257
1320
  }
1258
1321
  catch (error) {
1259
- log.logWarning(`[${this.channelId}] Session resources did not load`, errorMessage(error));
1322
+ log.logWarn("agent.session.resources_failed", "Session resources did not load", {
1323
+ channelId: this.channelId,
1324
+ reason: errorMessage(error),
1325
+ });
1260
1326
  }
1261
1327
  }
1262
1328
  /**
@@ -1372,6 +1438,7 @@ export class ChannelRunner {
1372
1438
  channelId: this.channelId,
1373
1439
  getSubAgentDiscovery: () => this.subAgentDiscovery,
1374
1440
  getSubAgentModelReference: () => this.settingsManager.getSubAgentModelReference(),
1441
+ resolveFallbackModel: () => this.resolveFallbackModel(),
1375
1442
  getSessionSearchSettings: () => this.settingsManager.getSessionSearchSettings(),
1376
1443
  securityConfig: securityLoad.config,
1377
1444
  toolsConfig: toolsLoad.config,
@@ -1387,7 +1454,10 @@ export class ChannelRunner {
1387
1454
  // Warn where the prompt's own budget diagnostics are reported, once per tool rebuild.
1388
1455
  const schemas = measureToolSchemas(tools);
1389
1456
  if (schemas.units > TOOL_SCHEMA_TARGET_UNITS) {
1390
- log.logWarning(`[${this.channelId}] Tool schema budget`, toolSchemaBudgetWarning(schemas));
1457
+ log.logWarn("agent.tools.schema_over_budget", "Tool schemas over budget", {
1458
+ channelId: this.channelId,
1459
+ reason: toolSchemaBudgetWarning(schemas),
1460
+ });
1391
1461
  }
1392
1462
  return tools;
1393
1463
  }
@@ -1406,7 +1476,10 @@ export class ChannelRunner {
1406
1476
  this.onSessionEvent?.(event, this.channelId);
1407
1477
  }
1408
1478
  catch (err) {
1409
- log.logWarning(`[${this.channelId}] session observer failed`, errorMessage(err));
1479
+ log.logWarn("agent.session.observer_failed", "Session observer failed", {
1480
+ channelId: this.channelId,
1481
+ reason: errorMessage(err),
1482
+ });
1410
1483
  }
1411
1484
  if (isRecord(event) && event.type === "message_start") {
1412
1485
  this.turnState.markStreaming();
@@ -1442,7 +1515,10 @@ export class ChannelRunner {
1442
1515
  },
1443
1516
  skillsDir: join(this.workspaceDir, "skills"),
1444
1517
  }).catch((err) => {
1445
- log.logWarning(`[${this.channelId}] session event handler failed`, errorMessage(err));
1518
+ log.logWarn("agent.session.handler_failed", "Session event handler failed", {
1519
+ channelId: this.channelId,
1520
+ reason: errorMessage(err),
1521
+ });
1446
1522
  });
1447
1523
  });
1448
1524
  }