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

View File

@@ -77,56 +77,38 @@ const ClaudeToolCallPass2Schema = z.discriminatedUnion("toolKind", [
ClaudeToolCallPass2BaseSchema.extend({
toolKind: z.literal("speak"),
name: z.literal("mcp__paseo__speak"),
}).transform((normalized): ToolCallTimelineItem => {
const name = "speak" as const;
const detail = deriveClaudeToolDetail(name, normalized.input, normalized.output);
if (normalized.status === "failed") {
return {
type: "tool_call",
callId: normalized.callId,
name,
detail,
status: "failed",
error: normalized.error ?? { message: "Tool call failed" },
...(normalized.metadata ? { metadata: normalized.metadata } : {}),
};
}
}),
ClaudeToolCallPass2BaseSchema.extend({
toolKind: z.literal("other"),
}),
]);
type ClaudeToolCallPass2 = z.infer<typeof ClaudeToolCallPass2Schema>;
function toToolCallTimelineItem(normalized: ClaudeToolCallPass2): ToolCallTimelineItem {
const name = normalized.toolKind === "speak" ? ("speak" as const) : normalized.name;
const detail = deriveClaudeToolDetail(name, normalized.input, normalized.output);
if (normalized.status === "failed") {
return {
type: "tool_call",
callId: normalized.callId,
name,
detail,
status: normalized.status,
error: null,
status: "failed",
error: normalized.error ?? { message: "Tool call failed" },
...(normalized.metadata ? { metadata: normalized.metadata } : {}),
};
}),
ClaudeToolCallPass2BaseSchema.extend({
toolKind: z.literal("other"),
}).transform((normalized): ToolCallTimelineItem => {
const detail = deriveClaudeToolDetail(normalized.name, normalized.input, normalized.output);
if (normalized.status === "failed") {
return {
type: "tool_call",
callId: normalized.callId,
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 } : {}),
};
}),
]);
}
return {
type: "tool_call",
callId: normalized.callId,
name,
detail,
status: normalized.status,
error: null,
...(normalized.metadata ? { metadata: normalized.metadata } : {}),
};
}
function mapClaudeToolCall(
params: MapperParams,
@@ -152,7 +134,7 @@ function mapClaudeToolCall(
return null;
}
return pass2.data;
return toToolCallTimelineItem(pass2.data);
}
export function mapClaudeRunningToolCall(

View File

@@ -1835,7 +1835,7 @@ class CodexAppServerAgentSession implements AgentSession {
developer_instructions: entry.developer_instructions ?? null,
}));
} catch (error) {
this.logger.debug({ error }, "Failed to load collaboration modes");
this.logger.trace({ error }, "Failed to load collaboration modes");
this.collaborationModes = [];
}
this.resolvedCollaborationMode = this.resolveCollaborationMode(this.currentMode);
@@ -1862,7 +1862,7 @@ class CodexAppServerAgentSession implements AgentSession {
}
this.cachedSkills = skills;
} catch (error) {
this.logger.debug({ error }, "Failed to load skills list");
this.logger.trace({ error }, "Failed to load skills list");
this.cachedSkills = [];
}
}
@@ -2685,7 +2685,7 @@ class CodexAppServerAgentSession implements AgentSession {
return;
}
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 {

View File

@@ -37,10 +37,10 @@ const CodexRolloutToolCallParamsSchema = z
type CodexNormalizedToolCallEnvelope = {
callId: string;
name: string;
input: unknown | null;
output: unknown | null;
status: ToolCallTimelineItem["status"];
error: unknown | null;
input?: unknown | null;
output?: unknown | null;
status?: ToolCallTimelineItem["status"];
error?: unknown | null;
metadata?: Record<string, unknown>;
cwd?: string | null;
};
@@ -116,243 +116,76 @@ const CodexNormalizedToolCallPass2Schema = z.discriminatedUnion("toolKind", [
CodexToolCallPass2BaseSchema.extend({
toolKind: z.literal("shell"),
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({
toolKind: z.literal("read"),
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({
toolKind: z.literal("write"),
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({
toolKind: z.literal("edit"),
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({
toolKind: z.literal("search"),
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({
toolKind: z.literal("speak"),
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({
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") {
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 } : {}),
};
}
type CodexNormalizedToolCallPass2 = z.infer<typeof CodexNormalizedToolCallPass2Schema>;
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 {
type: "tool_call",
callId: envelope.callId,
name: envelope.name,
status: envelope.status,
error: null,
name,
status: "failed",
error: envelope.error ?? { message: "Tool call failed" },
detail,
...(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
@@ -758,7 +591,7 @@ function toToolCallFromNormalizedEnvelope(
if (!parsed.success) {
return null;
}
return parsed.data;
return toToolCallTimelineItem(parsed.data);
}
function mapCommandExecutionItem(

View File

@@ -124,55 +124,37 @@ const OpencodeToolCallPass2Schema = z.discriminatedUnion("toolKind", [
OpencodeToolCallPass2BaseSchema.extend({
toolKind: z.literal("known"),
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({
toolKind: z.literal("other"),
}).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 } : {}),
};
}
}),
]);
type OpencodeToolCallPass2 = z.infer<typeof OpencodeToolCallPass2Schema>;
function toToolCallTimelineItem(normalized: OpencodeToolCallPass2): 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: normalized.status,
status: "failed",
detail,
error: null,
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 } : {}),
};
}
export function mapOpencodeToolCall(params: OpencodeToolCallParams): ToolCallTimelineItem | null {
const pass1 = OpencodeNormalizedToolCallPass1Schema.safeParse(params);
@@ -190,5 +172,5 @@ export function mapOpencodeToolCall(params: OpencodeToolCallParams): ToolCallTim
return null;
}
return pass2.data;
return toToolCallTimelineItem(pass2.data);
}

View File

@@ -323,12 +323,14 @@ type ToolReadOutputValue = {
content?: string;
};
export const ToolReadOutputSchema = ToolReadOutputContentSchema;
export const ToolReadOutputSchema: z.ZodType<ToolReadOutputValue, z.ZodTypeDef, unknown> =
ToolReadOutputContentSchema;
export const ToolReadOutputWithPathSchema = z.union([
ToolReadOutputContentSchema,
ToolReadOutputPathSchema,
]);
export const ToolReadOutputWithPathSchema: z.ZodType<
ToolReadOutputValue,
z.ZodTypeDef,
unknown
> = z.union([ToolReadOutputContentSchema, ToolReadOutputPathSchema]);
export const ToolWriteContentSchema = z
.object({

View File

@@ -57,7 +57,6 @@ import {
encodeOfferToFragmentUrl,
} from "./connection-offer.js";
import { loadOrCreateDaemonKeyPair } from "./daemon-keypair.js";
import { printPairingQrIfEnabled } from "./pairing-qr.js";
import { startRelayTransport, type RelayTransportController } from "./relay-transport.js";
import { getOrCreateServerId } from "./server-id.js";
import type {
@@ -548,7 +547,6 @@ export async function createPaseoDaemon(
const url = encodeOfferToFragmentUrl({ offer, appBaseUrl });
logger.info({ url }, "pairing_offer");
void printPairingQrIfEnabled({ url, logger }).catch(() => undefined);
} else {
logger.info("relay_disabled");
}