@oyasmi/pipiclaw 0.9.3 → 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.
- package/dist/agent/channel-runner.js +137 -61
- package/dist/agent/command-extension.js +47 -34
- package/dist/agent/job-manager.js +31 -11
- package/dist/agent/model-fallback.js +1 -1
- package/dist/agent/prompt/manifest.d.ts +6 -1
- package/dist/agent/prompt/manifest.js +45 -64
- package/dist/agent/prompt/resources.js +4 -1
- package/dist/agent/run-queue.js +7 -2
- package/dist/agent/session-adapter.js +1 -1
- package/dist/agent/session-events.js +17 -6
- package/dist/agent/session-resource-gate.js +3 -1
- package/dist/agent/status-render.d.ts +0 -1
- package/dist/agent/status-render.js +4 -16
- package/dist/agent/turn-error.d.ts +31 -0
- package/dist/agent/turn-error.js +68 -0
- package/dist/app-services.js +7 -4
- package/dist/channel/channel-index.js +4 -1
- package/dist/channel/project-scope-store.js +1 -1
- package/dist/commands/catalog.d.ts +21 -4
- package/dist/commands/catalog.js +88 -41
- package/dist/commands/reply-limits.d.ts +6 -0
- package/dist/commands/reply-limits.js +24 -0
- package/dist/events/event-commands.js +94 -44
- package/dist/events/event-validation.d.ts +13 -2
- package/dist/events/event-validation.js +17 -9
- package/dist/events/events.js +77 -32
- package/dist/executor.js +2 -2
- package/dist/log.d.ts +12 -2
- package/dist/log.js +26 -34
- package/dist/main.js +1 -1
- package/dist/memory/commands.js +29 -23
- package/dist/memory/lifecycle.js +26 -5
- package/dist/memory/maintenance-state.js +4 -1
- package/dist/memory/scheduler.js +3 -1
- package/dist/models/auth-cli.js +3 -2
- package/dist/paths.d.ts +2 -0
- package/dist/paths.js +9 -0
- package/dist/playbooks/agent-delegation.md +2 -2
- package/dist/runtime/app-home.d.ts +6 -0
- package/dist/runtime/app-home.js +21 -3
- package/dist/runtime/bootstrap.js +189 -60
- package/dist/runtime/channel-queue.js +1 -1
- package/dist/runtime/delivery.js +29 -15
- package/dist/runtime/dingtalk.js +96 -42
- package/dist/runtime/durable-dispatch.d.ts +27 -1
- package/dist/runtime/durable-dispatch.js +111 -3
- package/dist/runtime/project-commands.js +16 -15
- package/dist/runtime/proxy.js +4 -2
- package/dist/runtime/report-commands.js +1 -1
- package/dist/runtime/skill-commands.d.ts +1 -1
- package/dist/runtime/skill-commands.js +17 -10
- package/dist/runtime/subagent-commands.d.ts +5 -4
- package/dist/runtime/subagent-commands.js +116 -77
- package/dist/runtime/task-commands.d.ts +1 -1
- package/dist/runtime/task-commands.js +110 -64
- package/dist/runtime/task-driver.d.ts +4 -2
- package/dist/runtime/task-driver.js +55 -20
- package/dist/runtime/task-migration.js +23 -6
- package/dist/runtime/task-spawn.js +12 -5
- package/dist/runtime/wake-coalescing.d.ts +18 -0
- package/dist/runtime/wake-coalescing.js +29 -0
- package/dist/security/block-message.d.ts +22 -1
- package/dist/security/block-message.js +66 -1
- package/dist/security/network.d.ts +2 -1
- package/dist/security/network.js +3 -2
- package/dist/security/path-guard-check.js +2 -2
- package/dist/settings.d.ts +3 -2
- package/dist/settings.js +4 -1
- package/dist/shared/format.d.ts +12 -0
- package/dist/shared/format.js +37 -0
- package/dist/shared/host-process.js +15 -3
- package/dist/shared/with-timeout.d.ts +3 -2
- package/dist/shared/with-timeout.js +14 -3
- package/dist/subagents/external/claude-code.js +23 -1
- package/dist/subagents/external/progress-tail.d.ts +17 -0
- package/dist/subagents/external/progress-tail.js +64 -17
- package/dist/subagents/external/run.d.ts +3 -0
- package/dist/subagents/external/run.js +21 -7
- package/dist/subagents/external/settlement.d.ts +3 -0
- package/dist/subagents/external/settlement.js +1 -1
- package/dist/subagents/runs.d.ts +21 -1
- package/dist/subagents/runs.js +137 -32
- package/dist/subagents/tool.d.ts +22 -15
- package/dist/subagents/tool.js +226 -32
- package/dist/subagents/workspace-summary.d.ts +16 -4
- package/dist/subagents/workspace-summary.js +74 -18
- package/dist/tasks/board.d.ts +8 -1
- package/dist/tasks/board.js +37 -2
- package/dist/tasks/frontmatter.d.ts +5 -0
- package/dist/tasks/frontmatter.js +8 -0
- package/dist/tasks/log.d.ts +11 -1
- package/dist/tasks/log.js +58 -2
- package/dist/tasks/store.js +4 -2
- package/dist/tasks/ticket.d.ts +3 -1
- package/dist/tasks/ticket.js +19 -1
- package/dist/tools/bash.js +2 -2
- package/dist/tools/index.d.ts +2 -0
- package/dist/tools/index.js +1 -0
- package/dist/tools/memory-manage.js +4 -1
- package/dist/tools/subagent-manage.d.ts +1 -1
- package/dist/tools/subagent-manage.js +16 -11
- package/dist/tools/task-manage/step-end.js +4 -1
- package/dist/tools/tool-details.d.ts +10 -2
- package/dist/tools/tool-details.js +39 -2
- package/dist/tui/cli.js +2 -2
- package/dist/tui/commands.js +4 -4
- package/dist/tui/pitui-frontend.js +1 -1
- package/dist/tui/renderer.js +3 -2
- package/dist/tui/turn-controller.d.ts +2 -0
- package/dist/tui/turn-controller.js +36 -21
- package/dist/usage/ledger.js +3 -1
- package/dist/usage/render.js +3 -1
- package/package.json +1 -1
|
@@ -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.
|
|
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.
|
|
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.
|
|
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}
|
|
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 =
|
|
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.
|
|
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.
|
|
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
|
|
436
|
-
|
|
437
|
-
: this.runState.errorMessage
|
|
438
|
-
|
|
439
|
-
?
|
|
440
|
-
|
|
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.
|
|
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(
|
|
469
|
+
log.logInfo(`[${this.channelId}] Silent response ended progress delivery`);
|
|
461
470
|
}
|
|
462
471
|
catch (err) {
|
|
463
472
|
const errMsg = errorMessage(err);
|
|
464
|
-
log.
|
|
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(
|
|
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.
|
|
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.
|
|
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, "
|
|
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, "
|
|
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, "
|
|
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.
|
|
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.
|
|
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.
|
|
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(
|
|
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.
|
|
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(
|
|
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.
|
|
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
|
|
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)}
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
}
|
|
@@ -1,24 +1,43 @@
|
|
|
1
1
|
import { basename } from "path";
|
|
2
|
-
import { sessionCommandDescription } from "../commands/catalog.js";
|
|
2
|
+
import { formatNewSessionReply, sessionCommandDescription } from "../commands/catalog.js";
|
|
3
|
+
import { capReply } from "../commands/reply-limits.js";
|
|
3
4
|
import { findModelReferenceMatch, formatModelList, formatModelReference } from "../models/utils.js";
|
|
5
|
+
import { estimateTokens } from "../shared/format.js";
|
|
6
|
+
import { truncate } from "../shared/text-utils.js";
|
|
4
7
|
export const COMMAND_RESULT_CUSTOM_TYPE = "pipiclaw.command_result";
|
|
5
8
|
function buildSessionText(stats, currentModel, thinkingLevel, lastResponseModel) {
|
|
6
9
|
const configuredRef = currentModel ? formatModelReference(currentModel) : null;
|
|
7
|
-
const modelText = configuredRef ? `\`${configuredRef}\`` : "
|
|
10
|
+
const modelText = configuredRef ? `\`${configuredRef}\`` : "(无)";
|
|
8
11
|
const actualText = lastResponseModel && configuredRef && lastResponseModel !== configuredRef
|
|
9
|
-
?
|
|
12
|
+
? `(实际响应:\`${lastResponseModel}\`)`
|
|
10
13
|
: "";
|
|
11
|
-
const sessionFile = stats.sessionFile ? `\`${basename(stats.sessionFile)}\`` : "
|
|
14
|
+
const sessionFile = stats.sessionFile ? `\`${basename(stats.sessionFile)}\`` : "(无)";
|
|
15
|
+
const tokens = stats.tokens;
|
|
12
16
|
return `**会话**
|
|
13
17
|
|
|
14
|
-
-
|
|
15
|
-
-
|
|
18
|
+
- 会话 ID:\`${stats.sessionId}\`
|
|
19
|
+
- 会话文件:${sessionFile}
|
|
16
20
|
- 模型:${modelText}${actualText}
|
|
17
|
-
-
|
|
21
|
+
- 思考档位(thinking):\`${thinkingLevel}\`
|
|
18
22
|
- 消息:用户 \`${stats.userMessages}\` · 助手 \`${stats.assistantMessages}\` · 共 \`${stats.totalMessages}\`
|
|
19
23
|
- 工具调用:\`${stats.toolCalls}\` · 工具结果:\`${stats.toolResults}\`
|
|
20
|
-
-
|
|
21
|
-
-
|
|
24
|
+
- token 用量:共 \`${tokens.total}\`(输入 \`${tokens.input}\`,输出 \`${tokens.output}\`,缓存读 \`${tokens.cacheRead}\`,缓存写 \`${tokens.cacheWrite}\`)
|
|
25
|
+
- 花费:\`$${stats.cost.toFixed(4)}\``;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The `/compact` confirmation: sizes and the summary's first line only — the summary itself is
|
|
29
|
+
* the model's working notes and can run to pages (spec 053, D9).
|
|
30
|
+
*/
|
|
31
|
+
function buildCompactText(result) {
|
|
32
|
+
const after = result.estimatedTokensAfter ?? estimateTokens(result.summary);
|
|
33
|
+
const firstLine = result.summary
|
|
34
|
+
.split("\n")
|
|
35
|
+
.map((line) => line.replace(/^#+\s*/, "").trim())
|
|
36
|
+
.find(Boolean) ?? "";
|
|
37
|
+
const lines = [`已压缩当前会话上下文:压缩前 \`${result.tokensBefore}\` tokens,压缩后约 \`${after}\` tokens。`];
|
|
38
|
+
if (firstLine)
|
|
39
|
+
lines.push(`摘要开头:${truncate(firstLine, 120)}`);
|
|
40
|
+
return lines.join("\n");
|
|
22
41
|
}
|
|
23
42
|
async function runCompact(ctx, customInstructions) {
|
|
24
43
|
return await new Promise((resolve, reject) => {
|
|
@@ -37,12 +56,12 @@ function sendCommandResult(sender, text) {
|
|
|
37
56
|
});
|
|
38
57
|
}
|
|
39
58
|
function buildThinkingText(current, available) {
|
|
40
|
-
return
|
|
59
|
+
return `**思考档位**
|
|
41
60
|
|
|
42
61
|
- 当前档位:\`${current}\`
|
|
43
|
-
- 可用档位:${available.map((level) => `\`${level}\``).join("
|
|
62
|
+
- 可用档位:${available.map((level) => `\`${level}\``).join("、")}
|
|
44
63
|
|
|
45
|
-
用 \`/thinking
|
|
64
|
+
用 \`/thinking <档位>\` 设置,或 \`/thinking cycle\` 切到下一个可用档位。`;
|
|
46
65
|
}
|
|
47
66
|
export function createCommandExtension(options) {
|
|
48
67
|
return (pi) => {
|
|
@@ -70,21 +89,21 @@ export function createCommandExtension(options) {
|
|
|
70
89
|
if (normalized === "cycle") {
|
|
71
90
|
const next = options.cycleThinkingLevel();
|
|
72
91
|
if (!next) {
|
|
73
|
-
sendCommandResult(pi, "
|
|
92
|
+
sendCommandResult(pi, "当前模型不支持思考档位。用 `/model` 换一个支持推理的模型。");
|
|
74
93
|
return;
|
|
75
94
|
}
|
|
76
|
-
sendCommandResult(pi,
|
|
95
|
+
sendCommandResult(pi, `思考档位已切换为 \`${next}\`。`);
|
|
77
96
|
return;
|
|
78
97
|
}
|
|
79
98
|
if (!available.includes(normalized)) {
|
|
80
|
-
sendCommandResult(pi,
|
|
99
|
+
sendCommandResult(pi, `当前模型不支持思考档位 \`${args.trim()}\`。可用档位:${available
|
|
81
100
|
.map((level) => `\`${level}\``)
|
|
82
|
-
.join("
|
|
101
|
+
.join("、")}。`);
|
|
83
102
|
return;
|
|
84
103
|
}
|
|
85
104
|
const level = normalized;
|
|
86
105
|
options.setThinkingLevel(level);
|
|
87
|
-
sendCommandResult(pi,
|
|
106
|
+
sendCommandResult(pi, `思考档位已设置为 \`${level}\`。`);
|
|
88
107
|
},
|
|
89
108
|
});
|
|
90
109
|
pi.registerCommand("model", {
|
|
@@ -93,23 +112,24 @@ export function createCommandExtension(options) {
|
|
|
93
112
|
const availableModels = await options.getAvailableModels();
|
|
94
113
|
const currentModel = options.getCurrentModel();
|
|
95
114
|
if (!args.trim()) {
|
|
96
|
-
const current = currentModel ? `\`${formatModelReference(currentModel)}\`` : "
|
|
97
|
-
const available = availableModels.length > 0 ? formatModelList(availableModels, currentModel) : "-
|
|
98
|
-
|
|
115
|
+
const current = currentModel ? `\`${formatModelReference(currentModel)}\`` : "(无)";
|
|
116
|
+
const available = availableModels.length > 0 ? formatModelList(availableModels, currentModel) : "- (无可用模型)";
|
|
117
|
+
const report = `**模型**
|
|
99
118
|
|
|
100
119
|
当前模型:${current}
|
|
101
120
|
|
|
102
|
-
用 \`/model <provider/modelId>\`、\`/model <modelId>\`
|
|
121
|
+
用 \`/model <provider/modelId>\`、\`/model <modelId>\` 或任意能唯一匹配的片段切换。
|
|
103
122
|
|
|
104
123
|
可用模型:
|
|
105
|
-
${available}
|
|
124
|
+
${available}`;
|
|
125
|
+
sendCommandResult(pi, capReply(report, { nextStepHint: "用 `/model <片段>` 按名称直接切换" }).text);
|
|
106
126
|
return;
|
|
107
127
|
}
|
|
108
128
|
const match = findModelReferenceMatch(args, availableModels);
|
|
109
|
-
const available = availableModels.length > 0 ? formatModelList(availableModels, currentModel, 10) : "-
|
|
129
|
+
const available = availableModels.length > 0 ? formatModelList(availableModels, currentModel, 10) : "- (无可用模型)";
|
|
110
130
|
if (match.match) {
|
|
111
131
|
await options.switchModel(match.match);
|
|
112
|
-
sendCommandResult(pi, `已切换模型到 \`${formatModelReference(match.match)}
|
|
132
|
+
sendCommandResult(pi, `已切换模型到 \`${formatModelReference(match.match)}\`。`);
|
|
113
133
|
return;
|
|
114
134
|
}
|
|
115
135
|
if (match.ambiguous) {
|
|
@@ -133,7 +153,7 @@ ${available}`);
|
|
|
133
153
|
withSession: async (nextCtx) => {
|
|
134
154
|
sentFromReplacement = true;
|
|
135
155
|
await options.refreshSessionResources();
|
|
136
|
-
await sendCommandResult(nextCtx,
|
|
156
|
+
await sendCommandResult(nextCtx, formatNewSessionReply(nextCtx.sessionManager.getSessionId()));
|
|
137
157
|
},
|
|
138
158
|
});
|
|
139
159
|
if (result.cancelled) {
|
|
@@ -141,7 +161,7 @@ ${available}`);
|
|
|
141
161
|
}
|
|
142
162
|
else if (!sentFromReplacement) {
|
|
143
163
|
await options.refreshSessionResources();
|
|
144
|
-
sendCommandResult(pi,
|
|
164
|
+
sendCommandResult(pi, formatNewSessionReply(ctx.sessionManager.getSessionId()));
|
|
145
165
|
}
|
|
146
166
|
},
|
|
147
167
|
});
|
|
@@ -150,14 +170,7 @@ ${available}`);
|
|
|
150
170
|
handler: async (args, ctx) => {
|
|
151
171
|
const customInstructions = args.trim() || undefined;
|
|
152
172
|
const result = await runCompact(ctx, customInstructions);
|
|
153
|
-
sendCommandResult(pi,
|
|
154
|
-
|
|
155
|
-
- 压缩前 tokens:\`${result.tokensBefore}\`
|
|
156
|
-
- 摘要:
|
|
157
|
-
|
|
158
|
-
\`\`\`text
|
|
159
|
-
${result.summary}
|
|
160
|
-
\`\`\``);
|
|
173
|
+
sendCommandResult(pi, buildCompactText(result));
|
|
161
174
|
},
|
|
162
175
|
});
|
|
163
176
|
};
|