Reduce daemon startup noise and normalize tool-call mappers

This commit is contained in:
Mohamed Boudra
2026-02-12 18:16:36 +07:00
parent 50acf2dd44
commit 972895d855
6 changed files with 102 additions and 305 deletions
@@ -77,56 +77,38 @@ const ClaudeToolCallPass2Schema = z.discriminatedUnion("toolKind", [
ClaudeToolCallPass2BaseSchema.extend({ ClaudeToolCallPass2BaseSchema.extend({
toolKind: z.literal("speak"), toolKind: z.literal("speak"),
name: z.literal("mcp__paseo__speak"), name: z.literal("mcp__paseo__speak"),
}).transform((normalized): ToolCallTimelineItem => { }),
const name = "speak" as const; ClaudeToolCallPass2BaseSchema.extend({
const detail = deriveClaudeToolDetail(name, normalized.input, normalized.output); toolKind: z.literal("other"),
if (normalized.status === "failed") { }),
return { ]);
type: "tool_call",
callId: normalized.callId, type ClaudeToolCallPass2 = z.infer<typeof ClaudeToolCallPass2Schema>;
name,
detail, function toToolCallTimelineItem(normalized: ClaudeToolCallPass2): ToolCallTimelineItem {
status: "failed", const name = normalized.toolKind === "speak" ? ("speak" as const) : normalized.name;
error: normalized.error ?? { message: "Tool call failed" }, const detail = deriveClaudeToolDetail(name, normalized.input, normalized.output);
...(normalized.metadata ? { metadata: normalized.metadata } : {}), if (normalized.status === "failed") {
};
}
return { return {
type: "tool_call", type: "tool_call",
callId: normalized.callId, callId: normalized.callId,
name, name,
detail, detail,
status: normalized.status, status: "failed",
error: null, error: normalized.error ?? { message: "Tool call failed" },
...(normalized.metadata ? { metadata: normalized.metadata } : {}), ...(normalized.metadata ? { metadata: normalized.metadata } : {}),
}; };
}), }
ClaudeToolCallPass2BaseSchema.extend({ return {
toolKind: z.literal("other"), type: "tool_call",
}).transform((normalized): ToolCallTimelineItem => { callId: normalized.callId,
const detail = deriveClaudeToolDetail(normalized.name, normalized.input, normalized.output); name,
if (normalized.status === "failed") { detail,
return { status: normalized.status,
type: "tool_call", error: null,
callId: normalized.callId, ...(normalized.metadata ? { metadata: normalized.metadata } : {}),
name: normalized.name, };
detail, }
status: "failed",
error: normalized.error ?? { message: "Tool call failed" },
...(normalized.metadata ? { metadata: normalized.metadata } : {}),
};
}
return {
type: "tool_call",
callId: normalized.callId,
name: normalized.name,
detail,
status: normalized.status,
error: null,
...(normalized.metadata ? { metadata: normalized.metadata } : {}),
};
}),
]);
function mapClaudeToolCall( function mapClaudeToolCall(
params: MapperParams, params: MapperParams,
@@ -152,7 +134,7 @@ function mapClaudeToolCall(
return null; return null;
} }
return pass2.data; return toToolCallTimelineItem(pass2.data);
} }
export function mapClaudeRunningToolCall( export function mapClaudeRunningToolCall(
@@ -1835,7 +1835,7 @@ class CodexAppServerAgentSession implements AgentSession {
developer_instructions: entry.developer_instructions ?? null, developer_instructions: entry.developer_instructions ?? null,
})); }));
} catch (error) { } catch (error) {
this.logger.debug({ error }, "Failed to load collaboration modes"); this.logger.trace({ error }, "Failed to load collaboration modes");
this.collaborationModes = []; this.collaborationModes = [];
} }
this.resolvedCollaborationMode = this.resolveCollaborationMode(this.currentMode); this.resolvedCollaborationMode = this.resolveCollaborationMode(this.currentMode);
@@ -1862,7 +1862,7 @@ class CodexAppServerAgentSession implements AgentSession {
} }
this.cachedSkills = skills; this.cachedSkills = skills;
} catch (error) { } catch (error) {
this.logger.debug({ error }, "Failed to load skills list"); this.logger.trace({ error }, "Failed to load skills list");
this.cachedSkills = []; this.cachedSkills = [];
} }
} }
@@ -2685,7 +2685,7 @@ class CodexAppServerAgentSession implements AgentSession {
return; return;
} }
this.warnedUnknownNotificationMethods.add(method); this.warnedUnknownNotificationMethods.add(method);
this.logger.warn({ method, params }, "Unhandled Codex app-server notification method"); this.logger.trace({ method, params }, "Unhandled Codex app-server notification method");
} }
private warnInvalidNotificationPayload(method: string, params: unknown): void { private warnInvalidNotificationPayload(method: string, params: unknown): void {
@@ -37,10 +37,10 @@ const CodexRolloutToolCallParamsSchema = z
type CodexNormalizedToolCallEnvelope = { type CodexNormalizedToolCallEnvelope = {
callId: string; callId: string;
name: string; name: string;
input: unknown | null; input?: unknown | null;
output: unknown | null; output?: unknown | null;
status: ToolCallTimelineItem["status"]; status?: ToolCallTimelineItem["status"];
error: unknown | null; error?: unknown | null;
metadata?: Record<string, unknown>; metadata?: Record<string, unknown>;
cwd?: string | null; cwd?: string | null;
}; };
@@ -116,243 +116,76 @@ const CodexNormalizedToolCallPass2Schema = z.discriminatedUnion("toolKind", [
CodexToolCallPass2BaseSchema.extend({ CodexToolCallPass2BaseSchema.extend({
toolKind: z.literal("shell"), toolKind: z.literal("shell"),
name: CodexShellToolNameSchema, name: CodexShellToolNameSchema,
}).transform((envelope): ToolCallTimelineItem => {
const detail = deriveCodexToolDetail({
name: envelope.name,
input: envelope.input,
output: envelope.output,
cwd: envelope.cwd ?? null,
});
if (envelope.status === "failed") {
return {
type: "tool_call",
callId: envelope.callId,
name: envelope.name,
status: "failed",
error: envelope.error ?? { message: "Tool call failed" },
detail,
...(envelope.metadata ? { metadata: envelope.metadata } : {}),
};
}
return {
type: "tool_call",
callId: envelope.callId,
name: envelope.name,
status: envelope.status,
error: null,
detail,
...(envelope.metadata ? { metadata: envelope.metadata } : {}),
};
}), }),
CodexToolCallPass2BaseSchema.extend({ CodexToolCallPass2BaseSchema.extend({
toolKind: z.literal("read"), toolKind: z.literal("read"),
name: CodexReadToolNameSchema, name: CodexReadToolNameSchema,
}).transform((envelope): ToolCallTimelineItem => {
const detail = deriveCodexToolDetail({
name: envelope.name,
input: envelope.input,
output: envelope.output,
cwd: envelope.cwd ?? null,
});
if (envelope.status === "failed") {
return {
type: "tool_call",
callId: envelope.callId,
name: envelope.name,
status: "failed",
error: envelope.error ?? { message: "Tool call failed" },
detail,
...(envelope.metadata ? { metadata: envelope.metadata } : {}),
};
}
return {
type: "tool_call",
callId: envelope.callId,
name: envelope.name,
status: envelope.status,
error: null,
detail,
...(envelope.metadata ? { metadata: envelope.metadata } : {}),
};
}), }),
CodexToolCallPass2BaseSchema.extend({ CodexToolCallPass2BaseSchema.extend({
toolKind: z.literal("write"), toolKind: z.literal("write"),
name: CodexWriteToolNameSchema, name: CodexWriteToolNameSchema,
}).transform((envelope): ToolCallTimelineItem => {
const detail = deriveCodexToolDetail({
name: envelope.name,
input: envelope.input,
output: envelope.output,
cwd: envelope.cwd ?? null,
});
if (envelope.status === "failed") {
return {
type: "tool_call",
callId: envelope.callId,
name: envelope.name,
status: "failed",
error: envelope.error ?? { message: "Tool call failed" },
detail,
...(envelope.metadata ? { metadata: envelope.metadata } : {}),
};
}
return {
type: "tool_call",
callId: envelope.callId,
name: envelope.name,
status: envelope.status,
error: null,
detail,
...(envelope.metadata ? { metadata: envelope.metadata } : {}),
};
}), }),
CodexToolCallPass2BaseSchema.extend({ CodexToolCallPass2BaseSchema.extend({
toolKind: z.literal("edit"), toolKind: z.literal("edit"),
name: CodexEditToolNameSchema, name: CodexEditToolNameSchema,
}).transform((envelope): ToolCallTimelineItem => {
const parsedDetail = deriveCodexToolDetail({
name: envelope.name,
input: envelope.input,
output: envelope.output,
cwd: envelope.cwd ?? null,
});
const detail: ToolCallTimelineItem["detail"] =
envelope.status === "running" || hasRenderableEditDetail(parsedDetail)
? parsedDetail
: {
type: "unknown",
input: envelope.input,
output: envelope.output,
};
if (envelope.status === "failed") {
return {
type: "tool_call",
callId: envelope.callId,
name: envelope.name,
status: "failed",
error: envelope.error ?? { message: "Tool call failed" },
detail,
...(envelope.metadata ? { metadata: envelope.metadata } : {}),
};
}
return {
type: "tool_call",
callId: envelope.callId,
name: envelope.name,
status: envelope.status,
error: null,
detail,
...(envelope.metadata ? { metadata: envelope.metadata } : {}),
};
}), }),
CodexToolCallPass2BaseSchema.extend({ CodexToolCallPass2BaseSchema.extend({
toolKind: z.literal("search"), toolKind: z.literal("search"),
name: CodexSearchToolNameSchema, name: CodexSearchToolNameSchema,
}).transform((envelope): ToolCallTimelineItem => {
const detail = deriveCodexToolDetail({
name: envelope.name,
input: envelope.input,
output: envelope.output,
cwd: envelope.cwd ?? null,
});
if (envelope.status === "failed") {
return {
type: "tool_call",
callId: envelope.callId,
name: envelope.name,
status: "failed",
error: envelope.error ?? { message: "Tool call failed" },
detail,
...(envelope.metadata ? { metadata: envelope.metadata } : {}),
};
}
return {
type: "tool_call",
callId: envelope.callId,
name: envelope.name,
status: envelope.status,
error: null,
detail,
...(envelope.metadata ? { metadata: envelope.metadata } : {}),
};
}), }),
CodexToolCallPass2BaseSchema.extend({ CodexToolCallPass2BaseSchema.extend({
toolKind: z.literal("speak"), toolKind: z.literal("speak"),
name: CodexSpeakToolNameSchema, name: CodexSpeakToolNameSchema,
}).transform((envelope): ToolCallTimelineItem => {
const canonicalName = "speak";
const detail = deriveCodexToolDetail({
name: canonicalName,
input: envelope.input,
output: envelope.output,
cwd: envelope.cwd ?? null,
});
if (envelope.status === "failed") {
return {
type: "tool_call",
callId: envelope.callId,
name: canonicalName,
status: "failed",
error: envelope.error ?? { message: "Tool call failed" },
detail,
...(envelope.metadata ? { metadata: envelope.metadata } : {}),
};
}
return {
type: "tool_call",
callId: envelope.callId,
name: canonicalName,
status: envelope.status,
error: null,
detail,
...(envelope.metadata ? { metadata: envelope.metadata } : {}),
};
}), }),
CodexToolCallPass2BaseSchema.extend({ CodexToolCallPass2BaseSchema.extend({
toolKind: z.literal("unknown"), toolKind: z.literal("unknown"),
}).transform((envelope): ToolCallTimelineItem => { }),
const detail = deriveCodexToolDetail({ ]);
name: envelope.name,
input: envelope.input,
output: envelope.output,
cwd: envelope.cwd ?? null,
});
if (envelope.status === "failed") { type CodexNormalizedToolCallPass2 = z.infer<typeof CodexNormalizedToolCallPass2Schema>;
return {
type: "tool_call",
callId: envelope.callId,
name: envelope.name,
status: "failed",
error: envelope.error ?? { message: "Tool call failed" },
detail,
...(envelope.metadata ? { metadata: envelope.metadata } : {}),
};
}
function toToolCallTimelineItem(envelope: CodexNormalizedToolCallPass2): ToolCallTimelineItem {
const name = envelope.toolKind === "speak" ? ("speak" as const) : envelope.name;
const parsedDetail = deriveCodexToolDetail({
name,
input: envelope.input,
output: envelope.output,
cwd: envelope.cwd ?? null,
});
const detail: ToolCallTimelineItem["detail"] =
envelope.toolKind === "edit" &&
envelope.status !== "running" &&
!hasRenderableEditDetail(parsedDetail)
? {
type: "unknown",
input: envelope.input,
output: envelope.output,
}
: parsedDetail;
if (envelope.status === "failed") {
return { return {
type: "tool_call", type: "tool_call",
callId: envelope.callId, callId: envelope.callId,
name: envelope.name, name,
status: envelope.status, status: "failed",
error: null, error: envelope.error ?? { message: "Tool call failed" },
detail, detail,
...(envelope.metadata ? { metadata: envelope.metadata } : {}), ...(envelope.metadata ? { metadata: envelope.metadata } : {}),
}; };
}), }
]);
return {
type: "tool_call",
callId: envelope.callId,
name,
status: envelope.status,
error: null,
detail,
...(envelope.metadata ? { metadata: envelope.metadata } : {}),
};
}
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Thread-item parsing // Thread-item parsing
@@ -758,7 +591,7 @@ function toToolCallFromNormalizedEnvelope(
if (!parsed.success) { if (!parsed.success) {
return null; return null;
} }
return parsed.data; return toToolCallTimelineItem(parsed.data);
} }
function mapCommandExecutionItem( function mapCommandExecutionItem(
@@ -124,55 +124,37 @@ const OpencodeToolCallPass2Schema = z.discriminatedUnion("toolKind", [
OpencodeToolCallPass2BaseSchema.extend({ OpencodeToolCallPass2BaseSchema.extend({
toolKind: z.literal("known"), toolKind: z.literal("known"),
name: OpencodeKnownToolNameSchema, name: OpencodeKnownToolNameSchema,
}).transform((normalized): ToolCallTimelineItem => {
const detail = deriveOpencodeToolDetail(normalized.name, normalized.input, normalized.output);
if (normalized.status === "failed") {
return {
type: "tool_call",
callId: normalized.callId,
name: normalized.name,
status: "failed",
detail,
error: normalized.error ?? { message: "Tool call failed" },
...(normalized.metadata ? { metadata: normalized.metadata } : {}),
};
}
return {
type: "tool_call",
callId: normalized.callId,
name: normalized.name,
status: normalized.status,
detail,
error: null,
...(normalized.metadata ? { metadata: normalized.metadata } : {}),
};
}), }),
OpencodeToolCallPass2BaseSchema.extend({ OpencodeToolCallPass2BaseSchema.extend({
toolKind: z.literal("other"), toolKind: z.literal("other"),
}).transform((normalized): ToolCallTimelineItem => { }),
const detail = deriveOpencodeToolDetail(normalized.name, normalized.input, normalized.output); ]);
if (normalized.status === "failed") {
return { type OpencodeToolCallPass2 = z.infer<typeof OpencodeToolCallPass2Schema>;
type: "tool_call",
callId: normalized.callId, function toToolCallTimelineItem(normalized: OpencodeToolCallPass2): ToolCallTimelineItem {
name: normalized.name, const detail = deriveOpencodeToolDetail(normalized.name, normalized.input, normalized.output);
status: "failed", if (normalized.status === "failed") {
detail,
error: normalized.error ?? { message: "Tool call failed" },
...(normalized.metadata ? { metadata: normalized.metadata } : {}),
};
}
return { return {
type: "tool_call", type: "tool_call",
callId: normalized.callId, callId: normalized.callId,
name: normalized.name, name: normalized.name,
status: normalized.status, status: "failed",
detail, detail,
error: null, error: normalized.error ?? { message: "Tool call failed" },
...(normalized.metadata ? { metadata: normalized.metadata } : {}), ...(normalized.metadata ? { metadata: normalized.metadata } : {}),
}; };
}), }
]); return {
type: "tool_call",
callId: normalized.callId,
name: normalized.name,
status: normalized.status,
detail,
error: null,
...(normalized.metadata ? { metadata: normalized.metadata } : {}),
};
}
export function mapOpencodeToolCall(params: OpencodeToolCallParams): ToolCallTimelineItem | null { export function mapOpencodeToolCall(params: OpencodeToolCallParams): ToolCallTimelineItem | null {
const pass1 = OpencodeNormalizedToolCallPass1Schema.safeParse(params); const pass1 = OpencodeNormalizedToolCallPass1Schema.safeParse(params);
@@ -190,5 +172,5 @@ export function mapOpencodeToolCall(params: OpencodeToolCallParams): ToolCallTim
return null; return null;
} }
return pass2.data; return toToolCallTimelineItem(pass2.data);
} }
@@ -323,12 +323,14 @@ type ToolReadOutputValue = {
content?: string; content?: string;
}; };
export const ToolReadOutputSchema = ToolReadOutputContentSchema; export const ToolReadOutputSchema: z.ZodType<ToolReadOutputValue, z.ZodTypeDef, unknown> =
ToolReadOutputContentSchema;
export const ToolReadOutputWithPathSchema = z.union([ export const ToolReadOutputWithPathSchema: z.ZodType<
ToolReadOutputContentSchema, ToolReadOutputValue,
ToolReadOutputPathSchema, z.ZodTypeDef,
]); unknown
> = z.union([ToolReadOutputContentSchema, ToolReadOutputPathSchema]);
export const ToolWriteContentSchema = z export const ToolWriteContentSchema = z
.object({ .object({
-2
View File
@@ -57,7 +57,6 @@ import {
encodeOfferToFragmentUrl, encodeOfferToFragmentUrl,
} from "./connection-offer.js"; } from "./connection-offer.js";
import { loadOrCreateDaemonKeyPair } from "./daemon-keypair.js"; import { loadOrCreateDaemonKeyPair } from "./daemon-keypair.js";
import { printPairingQrIfEnabled } from "./pairing-qr.js";
import { startRelayTransport, type RelayTransportController } from "./relay-transport.js"; import { startRelayTransport, type RelayTransportController } from "./relay-transport.js";
import { getOrCreateServerId } from "./server-id.js"; import { getOrCreateServerId } from "./server-id.js";
import type { import type {
@@ -548,7 +547,6 @@ export async function createPaseoDaemon(
const url = encodeOfferToFragmentUrl({ offer, appBaseUrl }); const url = encodeOfferToFragmentUrl({ offer, appBaseUrl });
logger.info({ url }, "pairing_offer"); logger.info({ url }, "pairing_offer");
void printPairingQrIfEnabled({ url, logger }).catch(() => undefined);
} else { } else {
logger.info("relay_disabled"); logger.info("relay_disabled");
} }