fix: add nested agent log context
This commit is contained in:
@@ -79,6 +79,7 @@ Docs: https://docs.clawd.bot
|
|||||||
- Tools: include provider/session context in elevated exec denial errors.
|
- Tools: include provider/session context in elevated exec denial errors.
|
||||||
- Tools: normalize exec tool alias naming in tool error logs.
|
- Tools: normalize exec tool alias naming in tool error logs.
|
||||||
- Logging: reuse shared ANSI stripping to keep console capture lint-clean.
|
- Logging: reuse shared ANSI stripping to keep console capture lint-clean.
|
||||||
|
- Logging: prefix nested agent output with session/run/channel context.
|
||||||
- Telegram: accept tg/group/telegram prefixes + topic targets for inline button validation. (#1072) — thanks @danielz1z.
|
- Telegram: accept tg/group/telegram prefixes + topic targets for inline button validation. (#1072) — thanks @danielz1z.
|
||||||
- Telegram: split long captions into follow-up messages.
|
- Telegram: split long captions into follow-up messages.
|
||||||
- Config: block startup on invalid config, preserve best-effort doctor config, and keep rolling config backups. (#1083) — thanks @mukhtharcm.
|
- Config: block startup on invalid config, preserve best-effort doctor config, and keep rolling config backups. (#1083) — thanks @mukhtharcm.
|
||||||
|
|||||||
@@ -219,4 +219,43 @@ describe("deliverAgentCommandResult", () => {
|
|||||||
expect.objectContaining({ channel: "telegram", to: "123" }),
|
expect.objectContaining({ channel: "telegram", to: "123" }),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("prefixes nested agent outputs with context", async () => {
|
||||||
|
const cfg = {} as ClawdbotConfig;
|
||||||
|
const deps = {} as CliDeps;
|
||||||
|
const runtime = {
|
||||||
|
log: vi.fn(),
|
||||||
|
error: vi.fn(),
|
||||||
|
} as unknown as RuntimeEnv;
|
||||||
|
const result = {
|
||||||
|
payloads: [{ text: "ANNOUNCE_SKIP" }],
|
||||||
|
meta: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
const { deliverAgentCommandResult } = await import("./agent/delivery.js");
|
||||||
|
await deliverAgentCommandResult({
|
||||||
|
cfg,
|
||||||
|
deps,
|
||||||
|
runtime,
|
||||||
|
opts: {
|
||||||
|
message: "hello",
|
||||||
|
deliver: false,
|
||||||
|
lane: "nested",
|
||||||
|
sessionKey: "agent:main:main",
|
||||||
|
runId: "run-announce",
|
||||||
|
messageChannel: "webchat",
|
||||||
|
},
|
||||||
|
sessionEntry: undefined,
|
||||||
|
result,
|
||||||
|
payloads: result.payloads,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(runtime.log).toHaveBeenCalledTimes(1);
|
||||||
|
const line = String(runtime.log.mock.calls[0]?.[0]);
|
||||||
|
expect(line).toContain("[agent:nested]");
|
||||||
|
expect(line).toContain("session=agent:main:main");
|
||||||
|
expect(line).toContain("run=run-announce");
|
||||||
|
expect(line).toContain("channel=webchat");
|
||||||
|
expect(line).toContain("ANNOUNCE_SKIP");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { AGENT_LANE_NESTED } from "../../agents/lanes.js";
|
||||||
import { getChannelPlugin, normalizeChannelId } from "../../channels/plugins/index.js";
|
import { getChannelPlugin, normalizeChannelId } from "../../channels/plugins/index.js";
|
||||||
import { createOutboundSendDeps, type CliDeps } from "../../cli/outbound-send-deps.js";
|
import { createOutboundSendDeps, type CliDeps } from "../../cli/outbound-send-deps.js";
|
||||||
import type { ClawdbotConfig } from "../../config/config.js";
|
import type { ClawdbotConfig } from "../../config/config.js";
|
||||||
@@ -22,6 +23,28 @@ type RunResult = Awaited<
|
|||||||
ReturnType<(typeof import("../../agents/pi-embedded.js"))["runEmbeddedPiAgent"]>
|
ReturnType<(typeof import("../../agents/pi-embedded.js"))["runEmbeddedPiAgent"]>
|
||||||
>;
|
>;
|
||||||
|
|
||||||
|
const NESTED_LOG_PREFIX = "[agent:nested]";
|
||||||
|
|
||||||
|
function formatNestedLogPrefix(opts: AgentCommandOpts): string {
|
||||||
|
const parts = [NESTED_LOG_PREFIX];
|
||||||
|
const session = opts.sessionKey ?? opts.sessionId;
|
||||||
|
if (session) parts.push(`session=${session}`);
|
||||||
|
if (opts.runId) parts.push(`run=${opts.runId}`);
|
||||||
|
const channel = opts.messageChannel ?? opts.channel;
|
||||||
|
if (channel) parts.push(`channel=${channel}`);
|
||||||
|
if (opts.to) parts.push(`to=${opts.to}`);
|
||||||
|
if (opts.accountId) parts.push(`account=${opts.accountId}`);
|
||||||
|
return parts.join(" ");
|
||||||
|
}
|
||||||
|
|
||||||
|
function logNestedOutput(runtime: RuntimeEnv, opts: AgentCommandOpts, output: string) {
|
||||||
|
const prefix = formatNestedLogPrefix(opts);
|
||||||
|
for (const line of output.split(/\r?\n/)) {
|
||||||
|
if (!line) continue;
|
||||||
|
runtime.log(`${prefix} ${line}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function deliverAgentCommandResult(params: {
|
export async function deliverAgentCommandResult(params: {
|
||||||
cfg: ClawdbotConfig;
|
cfg: ClawdbotConfig;
|
||||||
deps: CliDeps;
|
deps: CliDeps;
|
||||||
@@ -112,7 +135,12 @@ export async function deliverAgentCommandResult(params: {
|
|||||||
const logPayload = (payload: NormalizedOutboundPayload) => {
|
const logPayload = (payload: NormalizedOutboundPayload) => {
|
||||||
if (opts.json) return;
|
if (opts.json) return;
|
||||||
const output = formatOutboundPayloadLog(payload);
|
const output = formatOutboundPayloadLog(payload);
|
||||||
if (output) runtime.log(output);
|
if (!output) return;
|
||||||
|
if (opts.lane === AGENT_LANE_NESTED) {
|
||||||
|
logNestedOutput(runtime, opts, output);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
runtime.log(output);
|
||||||
};
|
};
|
||||||
if (!deliver) {
|
if (!deliver) {
|
||||||
for (const payload of deliveryPayloads) logPayload(payload);
|
for (const payload of deliveryPayloads) logPayload(payload);
|
||||||
|
|||||||
Reference in New Issue
Block a user