Reduce local debug detail in mailbox and session helpers

This commit is contained in:
2026-04-04 09:34:41 +08:00
parent 7cf8afab73
commit 02f22d80bd
6 changed files with 40 additions and 50 deletions

View File

@@ -40,7 +40,7 @@ export function maybePersistTokenForSubprocesses(
mkdirSync(CCR_TOKEN_DIR, { recursive: true, mode: 0o700 })
// eslint-disable-next-line custom-rules/no-sync-fs -- one-shot startup write in CCR, caller is sync
writeFileSync(path, token, { encoding: 'utf8', mode: 0o600 })
logForDebugging(`Persisted ${tokenName} to ${path} for subprocess access`)
logForDebugging(`Persisted ${tokenName} for subprocess access`)
} catch (error) {
logForDebugging(
`Failed to persist ${tokenName} to disk (non-fatal): ${errorMessage(error)}`,
@@ -65,7 +65,7 @@ export function readTokenFromWellKnownFile(
if (!token) {
return null
}
logForDebugging(`Read ${tokenName} from well-known file ${path}`)
logForDebugging(`Read ${tokenName} from well-known file`)
return token
} catch (error) {
// ENOENT is the expected outcome outside CCR — stay silent. Anything
@@ -73,7 +73,7 @@ export function readTokenFromWellKnownFile(
// debug log so subprocess auth failures aren't mysterious.
if (!isENOENT(error)) {
logForDebugging(
`Failed to read ${tokenName} from ${path}: ${errorMessage(error)}`,
`Failed to read ${tokenName} from well-known file: ${errorMessage(error)}`,
{ level: 'debug' },
)
}
@@ -124,7 +124,7 @@ function getCredentialFromFd({
const fd = parseInt(fdEnv, 10)
if (Number.isNaN(fd)) {
logForDebugging(
`${envVar} must be a valid file descriptor number, got: ${fdEnv}`,
`${envVar} must be a valid file descriptor number`,
{ level: 'error' },
)
setCached(null)
@@ -148,13 +148,13 @@ function getCredentialFromFd({
setCached(null)
return null
}
logForDebugging(`Successfully read ${label} from file descriptor ${fd}`)
logForDebugging(`Successfully read ${label} from file descriptor`)
setCached(token)
maybePersistTokenForSubprocesses(wellKnownPath, token, label)
return token
} catch (error) {
logForDebugging(
`Failed to read ${label} from file descriptor ${fd}: ${errorMessage(error)}`,
`Failed to read ${label} from file descriptor: ${errorMessage(error)}`,
{ level: 'error' },
)
// FD env var was set but read failed — typically a subprocess that

View File

@@ -78,13 +78,13 @@ export async function getSessionEnvironmentScript(): Promise<string | null> {
if (envScript) {
scripts.push(envScript)
logForDebugging(
`Session environment loaded from CLAUDE_ENV_FILE: ${envFile} (${envScript.length} chars)`,
`Session environment loaded from CLAUDE_ENV_FILE (${envScript.length} chars)`,
)
}
} catch (e: unknown) {
const code = getErrnoCode(e)
if (code !== 'ENOENT') {
logForDebugging(`Failed to read CLAUDE_ENV_FILE: ${errorMessage(e)}`)
logForDebugging('Failed to read CLAUDE_ENV_FILE')
}
}
}
@@ -109,9 +109,7 @@ export async function getSessionEnvironmentScript(): Promise<string | null> {
} catch (e: unknown) {
const code = getErrnoCode(e)
if (code !== 'ENOENT') {
logForDebugging(
`Failed to read hook file ${filePath}: ${errorMessage(e)}`,
)
logForDebugging(`Failed to read hook env file ${file}`)
}
}
}

View File

@@ -37,7 +37,7 @@ function getTokenFromFileDescriptor(): string | null {
const fd = parseInt(fdEnv, 10)
if (Number.isNaN(fd)) {
logForDebugging(
`CLAUDE_CODE_WEBSOCKET_AUTH_FILE_DESCRIPTOR must be a valid file descriptor number, got: ${fdEnv}`,
'CLAUDE_CODE_WEBSOCKET_AUTH_FILE_DESCRIPTOR must be a valid file descriptor number',
{ level: 'error' },
)
setSessionIngressToken(null)
@@ -61,7 +61,7 @@ function getTokenFromFileDescriptor(): string | null {
setSessionIngressToken(null)
return null
}
logForDebugging(`Successfully read token from file descriptor ${fd}`)
logForDebugging('Successfully read token from file descriptor')
setSessionIngressToken(token)
maybePersistTokenForSubprocesses(
CCR_SESSION_INGRESS_TOKEN_PATH,
@@ -71,7 +71,7 @@ function getTokenFromFileDescriptor(): string | null {
return token
} catch (error) {
logForDebugging(
`Failed to read token from file descriptor ${fd}: ${errorMessage(error)}`,
`Failed to read token from file descriptor: ${errorMessage(error)}`,
{ level: 'error' },
)
// FD env var was set but read failed — typically a subprocess that

View File

@@ -57,11 +57,7 @@ export function getInboxPath(agentName: string, teamName?: string): string {
const safeTeam = sanitizePathComponent(team)
const safeAgentName = sanitizePathComponent(agentName)
const inboxDir = join(getTeamsDir(), safeTeam, 'inboxes')
const fullPath = join(inboxDir, `${safeAgentName}.json`)
logForDebugging(
`[TeammateMailbox] getInboxPath: agent=${agentName}, team=${team}, fullPath=${fullPath}`,
)
return fullPath
return join(inboxDir, `${safeAgentName}.json`)
}
/**
@@ -72,7 +68,7 @@ async function ensureInboxDir(teamName?: string): Promise<void> {
const safeTeam = sanitizePathComponent(team)
const inboxDir = join(getTeamsDir(), safeTeam, 'inboxes')
await mkdir(inboxDir, { recursive: true })
logForDebugging(`[TeammateMailbox] Ensured inbox directory: ${inboxDir}`)
logForDebugging('[TeammateMailbox] Ensured inbox directory')
}
/**
@@ -85,7 +81,6 @@ export async function readMailbox(
teamName?: string,
): Promise<TeammateMessage[]> {
const inboxPath = getInboxPath(agentName, teamName)
logForDebugging(`[TeammateMailbox] readMailbox: path=${inboxPath}`)
try {
const content = await readFile(inboxPath, 'utf-8')
@@ -100,7 +95,7 @@ export async function readMailbox(
logForDebugging(`[TeammateMailbox] readMailbox: file does not exist`)
return []
}
logForDebugging(`Failed to read inbox for ${agentName}: ${error}`)
logForDebugging(`[TeammateMailbox] Failed to read inbox for ${agentName}`)
logError(error)
return []
}
@@ -141,7 +136,7 @@ export async function writeToMailbox(
const lockFilePath = `${inboxPath}.lock`
logForDebugging(
`[TeammateMailbox] writeToMailbox: recipient=${recipientName}, from=${message.from}, path=${inboxPath}`,
`[TeammateMailbox] writeToMailbox: recipient=${recipientName}, from=${message.from}`,
)
// Ensure the inbox file exists before locking (proper-lockfile requires the file to exist)
@@ -152,7 +147,7 @@ export async function writeToMailbox(
const code = getErrnoCode(error)
if (code !== 'EEXIST') {
logForDebugging(
`[TeammateMailbox] writeToMailbox: failed to create inbox file: ${error}`,
`[TeammateMailbox] writeToMailbox: failed to create inbox file`,
)
logError(error)
return
@@ -181,7 +176,9 @@ export async function writeToMailbox(
`[TeammateMailbox] Wrote message to ${recipientName}'s inbox from ${message.from}`,
)
} catch (error) {
logForDebugging(`Failed to write to inbox for ${recipientName}: ${error}`)
logForDebugging(
`[TeammateMailbox] Failed to write to inbox for ${recipientName}`,
)
logError(error)
} finally {
if (release) {
@@ -204,7 +201,7 @@ export async function markMessageAsReadByIndex(
): Promise<void> {
const inboxPath = getInboxPath(agentName, teamName)
logForDebugging(
`[TeammateMailbox] markMessageAsReadByIndex called: agentName=${agentName}, teamName=${teamName}, index=${messageIndex}, path=${inboxPath}`,
`[TeammateMailbox] markMessageAsReadByIndex called: agentName=${agentName}, index=${messageIndex}`,
)
const lockFilePath = `${inboxPath}.lock`
@@ -256,13 +253,11 @@ export async function markMessageAsReadByIndex(
} catch (error) {
const code = getErrnoCode(error)
if (code === 'ENOENT') {
logForDebugging(
`[TeammateMailbox] markMessageAsReadByIndex: file does not exist at ${inboxPath}`,
)
logForDebugging(`[TeammateMailbox] markMessageAsReadByIndex: file missing`)
return
}
logForDebugging(
`[TeammateMailbox] markMessageAsReadByIndex FAILED for ${agentName}: ${error}`,
`[TeammateMailbox] markMessageAsReadByIndex failed for ${agentName}`,
)
logError(error)
} finally {
@@ -296,7 +291,7 @@ export async function clearMailbox(
if (code === 'ENOENT') {
return
}
logForDebugging(`Failed to clear inbox for ${agentName}: ${error}`)
logForDebugging(`[TeammateMailbox] Failed to clear inbox for ${agentName}`)
logError(error)
}
}
@@ -1108,7 +1103,7 @@ export function getLastPeerDmSummary(messages: Message[]): string | undefined {
const summary =
'summary' in block.input && typeof block.input.summary === 'string'
? block.input.summary
: block.input.message.slice(0, 80)
: 'sent update'
return `[to ${to}] ${summary}`
}
}