fix(observabilidade): parser extrai skills de tool_result.content (string e array)
Antes: skills_invoked vazio em 1608/1608 sessões porque detectSkillInvoked apenas era aplicado ao text extraído de content[type=text]. A string 'Launching skill: X' vive dentro de tool_result.content (string ou array de text blocks), que era ignorada. Fix: adicionar helper extractResultText(r) que trata ambos os casos e aplicar detectSkillInvoked + detectHook também ao tool_result. Após re-indexação full, 526/1616 sessões têm agora skills detectadas e o detector de padrões devolve 6 padrões (vs 2 baseline), incluindo skills_with_high_error_rate reais. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -19,6 +19,21 @@ function detectHook(text: string | null): string | null {
|
||||
return m ? m[1] : null
|
||||
}
|
||||
|
||||
function extractResultText(r: unknown): string | null {
|
||||
if (r == null) return null
|
||||
if (typeof r === 'string') return r
|
||||
if (Array.isArray(r)) {
|
||||
const parts: string[] = []
|
||||
for (const p of r) {
|
||||
if (p && typeof p === 'object' && 'text' in p && typeof (p as { text: unknown }).text === 'string') {
|
||||
parts.push((p as { text: string }).text)
|
||||
}
|
||||
}
|
||||
return parts.length ? parts.join('\n') : null
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
function extractText(rawMsg: unknown): string | null {
|
||||
if (!rawMsg || typeof rawMsg !== 'object') return null
|
||||
const msg = rawMsg as { content?: unknown }
|
||||
@@ -132,9 +147,12 @@ export async function parseSessionFile(jsonlPath: string): Promise<ParseResult>
|
||||
}
|
||||
}
|
||||
|
||||
const resultText = extractResultText(toolResult)
|
||||
const skill = detectSkillInvoked(text)
|
||||
if (skill) skillsInvoked.add(skill)
|
||||
const hook = detectHook(text)
|
||||
const skillFromResult = detectSkillInvoked(resultText)
|
||||
const finalSkill = skill ?? skillFromResult
|
||||
if (finalSkill) skillsInvoked.add(finalSkill)
|
||||
const hook = detectHook(text) ?? detectHook(resultText)
|
||||
|
||||
events.push({
|
||||
index: idx++,
|
||||
@@ -145,7 +163,7 @@ export async function parseSessionFile(jsonlPath: string): Promise<ParseResult>
|
||||
tool_name: toolName,
|
||||
tool_input: toolInput,
|
||||
tool_result: toolResult,
|
||||
skill_invoked: skill,
|
||||
skill_invoked: finalSkill,
|
||||
hook_name: hook,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user