fix(codex): ignore subagents in transcript fallback

This commit is contained in:
weishu
2026-07-22 09:20:00 +08:00
parent a9115715f8
commit 3208f139b5
5 changed files with 125 additions and 30 deletions
+2 -6
View File
@@ -3,6 +3,7 @@ import { randomUUID } from 'node:crypto'
import { basename, dirname, join, relative } from 'node:path'
import { homedir } from 'node:os'
import { AGENT_MESSAGE_PAYLOAD_TYPE } from '@hapi/protocol'
import { isCodexSubagentSource } from '@/codex/utils/codexSessionMetadata'
const DEFAULT_CODEX_SESSION_SCAN_LIMIT = 200
@@ -78,11 +79,6 @@ function shouldIgnoreSyntheticUserMessage(text: string): boolean {
return normalized.startsWith('# AGENTS.md instructions') || normalized.startsWith('<environment_context>')
}
function isSubagentSource(value: unknown): boolean {
const record = asRecord(value)
return Boolean(record && Object.prototype.hasOwnProperty.call(record, 'subagent'))
}
function inferSessionIdFromFileName(filePath: string): string | null {
return /([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})/.exec(filePath)?.[1] ?? null
}
@@ -338,7 +334,7 @@ function parseCodexLocalSession(
if (!record) continue
if (record.type === 'session_meta') {
const payload = asRecord(record.payload)
if (isSubagentSource(payload?.source)) return null
if (isCodexSubagentSource(payload?.source)) return null
if (!sessionId && typeof payload?.id === 'string') sessionId = payload.id
if (!cwd && typeof payload?.cwd === 'string') cwd = payload.cwd
if (!originator && typeof payload?.originator === 'string') originator = payload.originator