fix(P2): align v2 pre-pass placeholder with P2 regex — include skill_view(name='X')

The P2 extraction regex expects skill_view(name='X') but the v2
pre-pass placeholder used 'reload with skill_view before relying on it'.
This mismatch meant _pruned_skill_names was always empty, so the P2
defense (pre-LLM extraction + post-LLM re-injection) never fired.

Align both Phase 1 and pre-pass v2 placeholders to use the callable
skill_view(name='X') format so the regex matches and the agent can
reload the pruned skill directly.

Addresses review comment from @liuhao1024 on PR #44166.
This commit is contained in:
Jonathan Boisson 2026-06-11 15:12:30 +02:00
parent c1b520d165
commit 3d8a31432d

View file

@ -554,7 +554,7 @@ def _summarize_tool_result(tool_name: str, tool_args: str, tool_content: str) ->
if tool_name == "skill_view": if tool_name == "skill_view":
name = args.get("name", "?") name = args.get("name", "?")
if content_len > 5000: if content_len > 5000:
return f"[skill_view] name={name} ({content_len:,} chars) [SKILL_PRUNED: content lost in compression; reload with skill_view before relying on it]" return f"[skill_view] name={name} ({content_len:,} chars) [SKILL_PRUNED: content lost in compression; reload with skill_view(name='{name}')]"
return f"[skill_view] name={name} ({content_len:,} chars)" return f"[skill_view] name={name} ({content_len:,} chars)"
if tool_name in {"skills_list", "skill_manage"}: if tool_name in {"skills_list", "skill_manage"}:
@ -989,7 +989,7 @@ class ContextCompressor(ContextEngine):
f"[skill_view] name={skill_name} " f"[skill_view] name={skill_name} "
f"({len(original_content):,} chars) " f"({len(original_content):,} chars) "
f"[SKILL_PRUNED: content lost in compression; " f"[SKILL_PRUNED: content lost in compression; "
f"reload with skill_view before relying on it]" f"reload with skill_view(name='{skill_name}')]"
) )
result[idx] = {**result[idx], "content": placeholder} result[idx] = {**result[idx], "content": placeholder}
pruned += 1 pruned += 1