Skip to content

Disable the summarize analyzer for the SDK persona - #703

Merged
anshss merged 1 commit into
mainfrom
summarize-sdk-gate
Aug 7, 2026
Merged

anshss merged 1 commit into
mainfrom
summarize-sdk-gate

Conversation

@anshss

@anshss anshss commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

summarize runs for every persona today, including SDK/API windows where it has nothing to look at. This gates it off for the sdk persona and corrects the surfaces that claimed otherwise.

Summary

  • summarize joins deadweight and subagent under the sdk key of PERSONA_DISABLED_ANALYZERS (tokenjam/core/optimize/runner.py) — a true skip before dispatch, not a run-and-report-disabled finding.
  • The Review inbox's independent selection surface follows automatically: cost_analyzers_for_persona and cost_proposals_from_report's _pick both read the same map, so no summarize card can reach an SDK user's inbox either.
  • Two tj optimize strings that asserted the wrong reason for an SDK reader are now persona-aware.
  • README, docs/agent-capability-matrix.md updated so the published persona tables match the gate.

Why an SDK window has no lever here

summarize prices what a filesystem scan of agent instruction files found. Its population is the catalog in tokenjam/core/summarize/agent_files.toml:

  • CLAUDE.md / CLAUDE.local.md, AGENTS.md / codex.md, GEMINI.md
  • .claude/rules/**/*.md, .claude/skills/*/SKILL.md, .claude/commands/*.md, .claude/agents/*.md
  • the ~/.claude, ~/.codex, ~/.gemini equivalents

It has never read application source. The only widening it offers is the user-invoked tj summarize list --recursive, and that walk admits .md / .markdown (_DEFAULT_EXTS in core/summarize/candidates.py), never the .py / .ts where an SDK workload's prompt templates actually live.

So for an SDK/API-dominant window the scan has no input by construction. Running it can only produce a card with no fix behind it, which is exactly the bar PERSONA_DISABLED_ANALYZERS's sdk key already applies to deadweight (no on-disk Claude Code transcript) and subagent (sub_agent_id never populated). Same mechanism, third entry — no parallel gating scheme.

What now happens for those users

  • summarize is absent from an SDK window's report entirely, rather than rendering a permanently-thin card. A gated analyzer vanishes; it does not render a placeholder.
  • If an SDK user types tj optimize summarize by name, they get the one-line "not run, and why" answer, because silence after a typed command reads as a bug.
  • The Lens Summarize nav child was already conditional on the finding carrying candidates, so it simply stops appearing. No UI change is needed.
  • write_budget.measured_agent_file_tokens reads this finding as the write budget's denominator. With the finding absent it takes its documented None path — leave the lane cap intact rather than invent a footprint — which errs toward more headroom, the conservative direction for a suppression gate.

Nothing changes for Claude Code or Codex users. An interactive coding agent classifies as the claude-code persona (framing.dominant_persona via alerts.is_interactive_coding_agent), never sdk, so Codex and Gemini CLI users keep the analyzer. And tj summarize stays a command anyone can type: the gate drops the analyzer from optimize reports, not the prepare/check/apply lifecycle.

Two CLI strings that were asserting the wrong reason

Both in tokenjam/cli/cmd_optimize.py, both pre-existing and both made more visible by a third sdk gate entry:

  1. The gated-analyzer notice hardcoded the claude-code reason — "No fix for these exists inside an interactive coding-agent session" — and printed it to SDK readers, for whom the reason is a missing input, not a missing lever. It now picks the sentence off the report's persona.
  2. The skipped-filesystem-scan note hardcoded "deadweight, relearn and summarize did not run: <scope reason>". For an SDK window that blamed the scope for absences the persona gate had already caused. _filesystem_scan_note() now filters the names against the gate and prints nothing when the skip cost this reader nothing.

Tests / Verification

tests/unit/test_persona_analyzer_gate.py:

  • The SDK_NO_LEVER pin (derived from the production map, then asserted against an explicit set) now names summarize, so a silent drop from the gate fails immediately.
  • New test_summarize_is_gated_for_sdk_and_untouched_for_claude_code — names the analyzer explicitly rather than relying on set-wise coverage, and asserts both halves: not invoked and absent from report.findings for an SDK window, still invoked for a claude-code window. The second half is what stops the first from passing vacuously if summarize ever stopped being dispatched at all.
  • New test_summarize_card_is_dropped_from_the_review_inbox_for_sdk — hands cost_proposals_from_report a report that carries the finding (a real shape: a cached payload or a wider selection can hold one) and asserts the card exists for claude-code before asserting its absence for sdk, so the fixture's own validity is pinned.
  • test_gate_saves_real_query_work_on_a_claude_code_window compared claude-code's statement count against sdk's, which was a proxy for "the claude-code gate is the only heavy one". Adding a third sdk entry inverted it: it failed while both gates worked perfectly. Replaced by test_gate_saves_real_query_work_for_both_gated_personas, which measures each persona against itself with the gate emptied. A control that can invert without the property under test changing was measuring the wrong thing.

tests/unit/test_optimize_summarize.py: this suite seeded tests.factories' default agent_id="test-agent", which classifies as sdk — so every test built the one window shape in which this analyzer cannot run. Sessions now seed a coding-agent id, with a comment saying why the vehicle has to be a claude-code window. No assertion was weakened.

$ env -u FORCE_COLOR python -m pytest tests/unit -q -p no:randomly
4594 passed, 17 skipped, 2 xfailed, 1 warning in 209.83s

$ env -u FORCE_COLOR python -m pytest tests/synthetic tests/integration -q -p no:randomly
793 passed, 1 warning in 87.68s

$ env -u FORCE_COLOR python -m pytest tests/agents -q -p no:randomly
24 passed in 2.96s

$ ruff check tokenjam/ tests/unit/test_persona_analyzer_gate.py tests/unit/test_optimize_summarize.py
All checks passed!

$ mypy tokenjam/core/optimize/runner.py tokenjam/cli/cmd_optimize.py
Success: no issues found in 2 source files

What's also in this PR

The README analyzer table listed subagent as ✅ for SDK, which contradicts PERSONA_DISABLED_ANALYZERS["sdk"] and predates this change. Corrected to — alongside summarize, because the same table is the subject of this PR and docs/agent-capability-matrix.md's SDK cell — which I had to rewrite anyway, since its "twelve of thirteen" count no longer held — would otherwise have contradicted it. Both are one-cell truth corrections; easy to drop if you would rather they landed separately.

What's NOT in this PR

  • No UI change. ui/index.html already handles an absent summarize finding correctly: the nav child is gated on sf.candidates.length, and the Optimize action row on sf.files > 0. Nothing renders a zero or an empty-state claim.
  • No change to tj summarize itself. The command, its catalog, and the prepare/check/apply lifecycle are untouched and remain available to every persona.
  • summarize.py's module docstring still says the analyzer is "deliberately not a COST_ANALYZERS member", which stopped being true when it got a real peer card. Stale comment, unrelated to persona gating, left alone rather than folded into this diff.

🤖 Generated with Claude Code

Summarize prices what a filesystem scan of AGENT INSTRUCTION FILES found. Its
population is the catalog in `core/summarize/agent_files.toml`: `CLAUDE.md`,
`AGENTS.md`, `GEMINI.md`, the rules / skills / commands / agents markdown beside
them, and the `~/.claude`, `~/.codex`, `~/.gemini` equivalents. It has never read
application source, and the only widening it offers (the user-invoked
`tj summarize list --recursive`) admits more markdown, never the `.py`/`.ts` a
prompt template lives in.

So for an SDK/API-dominant window the scan has no input, and the analyzer can
only produce a card with no fix behind it. That is the same bar the `sdk` key
already applies to `deadweight` and `subagent`, so it joins them in
`PERSONA_DISABLED_ANALYZERS` rather than getting a second gating scheme: a true
skip before dispatch, mirrored automatically into the Review inbox's own
selection surface through `cost_analyzers_for_persona`.

Nothing changes for Claude Code or Codex users. An interactive coding agent
classifies as the `claude-code` persona, never `sdk`, and `tj summarize` stays a
command anyone can type; the gate drops the analyzer from optimize reports, not
the lifecycle.

Two `tj optimize` strings were asserting the wrong reason for an SDK reader and
are now persona-aware: the "Not run:" line hardcoded the claude-code
"no fix inside an interactive coding-agent session" wording, and the skipped-
filesystem-scan note hardcoded three analyzer names, blaming a scope skip for
absences the persona gate had already caused.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@anshss
anshss requested a review from anilmurty as a code owner August 6, 2026 14:04
@greptile-apps

greptile-apps Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR adds summarize to the SDK persona gate and updates CLI explanations, documentation, and persona-gating tests. The gate currently conflates telemetry persona with independently available filesystem inputs, allowing real summarize findings to be omitted.

  • Disables summarize before dispatch for SDK-persona optimize reports.
  • Filters filesystem-scan notices and renders persona-specific gated-analyzer explanations.
  • Updates analyzer capability tables and expands persona-gate test coverage.

Confidence Score: 4/5

The PR should not merge until summarize availability is decoupled from telemetry persona or otherwise preserves findings when cataloged filesystem inputs exist.

The unconditional SDK gate can suppress actionable project or global instruction-file findings because persona classification is based on session agent IDs while summarize inputs come from independent filesystem state.

Files Needing Attention: tokenjam/core/optimize/runner.py

Important Files Changed

Filename Overview
tokenjam/core/optimize/runner.py Adds the SDK summarize gate, but uses a telemetry-derived persona to suppress an analyzer whose inputs are independent filesystem state.
tokenjam/cli/cmd_optimize.py Adds shared persona-aware rendering for filesystem-scan and explicitly requested gated-analyzer notices.
tests/unit/test_persona_analyzer_gate.py Expands gate and downstream-card coverage, but tests only an SDK fixture assumed not to have independently available summarize inputs.
tests/unit/test_optimize_summarize.py Reclassifies summarize analyzer fixtures as Claude Code so existing analyzer behavior remains exercised.
README.md Documents summarize as unavailable for SDK users, inheriting the gate's overly broad filesystem-input assumption.
docs/agent-capability-matrix.md Updates persona capability claims consistently with the new gate.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
    A[Telemetry sessions] --> B[dominant_persona]
    B -->|sdk| C[Remove summarize before dispatch]
    D[Project and global instruction files] -. independent input .-> E[Summarize filesystem scan]
    C -->|scan never runs| F[Finding absent from report and Review]
    E --> G[Potential summarize finding]
Loading
Prompt To Fix All With AI
### Issue 1
tokenjam/core/optimize/runner.py:183
**SDK gate suppresses filesystem findings**

If an SDK-dominant telemetry window is analyzed where cataloged project or global instruction files exist, the unconditional persona gate removes `summarize` before its independent filesystem scan runs, causing actionable instruction-file savings to disappear from the optimize report and Review inbox.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Reviews (1): Last reviewed commit: "Disable the summarize analyzer for the S..." | Re-trigger Greptile

# never `sdk`. `tj summarize` itself stays available to everyone — the
# gate drops the analyzer from optimize reports, not the command.
"summarize",
}),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 SDK gate suppresses filesystem findings

If an SDK-dominant telemetry window is analyzed where cataloged project or global instruction files exist, the unconditional persona gate removes summarize before its independent filesystem scan runs, causing actionable instruction-file savings to disappear from the optimize report and Review inbox.

Knowledge Base Used: Session Analysis and Export

Prompt To Fix With AI
This is a comment left during a code review.
Path: tokenjam/core/optimize/runner.py
Line: 183

Comment:
**SDK gate suppresses filesystem findings**

If an SDK-dominant telemetry window is analyzed where cataloged project or global instruction files exist, the unconditional persona gate removes `summarize` before its independent filesystem scan runs, causing actionable instruction-file savings to disappear from the optimize report and Review inbox.

**Knowledge Base Used:** [Session Analysis and Export](https://app.greptile.com/metabldr/-/custom-context/knowledge-base/metabuilder-labs/tokenjam/-/docs/session-analysis-export.md)

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

@anshss
anshss merged commit f5a4926 into main Aug 7, 2026
4 of 7 checks passed
@anilmurty
anilmurty deleted the summarize-sdk-gate branch September 18, 2026 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant