Commit graph

13 commits

Author SHA1 Message Date
AgentSeal
77257bcb89
Merge pull request #68 from lfl1337/fix/remove-claudeignore-references
docs(optimize): remove references to .claudeignore (#61)
2026-04-17 14:20:50 +02:00
Ninym
216782391a fix(optimize): use bounded read helpers
All four read paths in the optimizer (async session scan + three sync
config/import/profile scans) now pass through the 128 MB-capped
helpers. JSON.parse in readJsonFile stays wrapped in try/catch.
MEDIUM-1 coverage for the optimize module.
2026-04-17 08:32:20 +02:00
Ninym
bd71377fdd docs(optimize): remove references to non-existent .claudeignore
Claude Code does not document or implement a .claudeignore feature.
The junk-reads detector's fix is now a CLAUDE.md instruction asking
Claude to avoid generated/dependency directories. The separate
detectMissingClaudeignore finding and its tests are removed; checking
for the presence of a non-existent file has no signal.

Closes #61.
2026-04-17 08:32:07 +02:00
AgentSeal
f958756861 chore(optimize): name preview-count literals and drop punctuation dashes
Rename slice(0, N) and length - N literals used in waste-finding
preview strings to GHOST_NAMES_PREVIEW, GHOST_CLEANUP_COMMANDS_LIMIT,
TOP_ITEMS_PREVIEW, MISSING_IGNORE_PATHS_PREVIEW, JUNK_DIRS_IGNORE_PREVIEW.
Drop the punctuation double-hyphen from the config-health header.
2026-04-16 16:20:53 -07:00
AgentSeal
3bd3c0d7b4 chore(optimize): extract trend period magic number to named constant 2026-04-16 16:09:19 -07:00
AgentSeal
b9b2c7a900 chore: remove dead ContextBudgetPanel and unused dateRange parameter
- ContextBudgetPanel in dashboard.tsx was defined but never rendered
  after the per-project overhead column replaced it in Phase 1.
- detectLowReadEditRatio accepted a dateRange parameter that was
  never used inside the function (trend is computed via recent-call
  flags on ToolCall).

Verified with tsc --noUnusedLocals --noUnusedParameters: 0 errors.
160 tests pass.
2026-04-16 09:35:46 -07:00
AgentSeal
b9dffc16ec chore(optimize): remove dead versions plumbing + name remaining magic numbers
- ScanData.versions and ScanFileResult.versions were collected but never
  read in scanAndDetect. Per-call version lives on ApiCallMeta.version
  which is what detectCacheBloat actually uses. Dropped the unused
  aggregation path end-to-end.
- Extract DEFAULT_CACHE_BASELINE_TOKENS, CACHE_BASELINE_QUANTILE,
  CACHE_VERSION_MIN_SAMPLES, CACHE_VERSION_DIFF_THRESHOLD as named
  module-scope constants. Honors the "no magic numbers" project rule
  across the full optimize engine.
2026-04-16 07:09:20 -07:00
AgentSeal
707d2faff1 feat(optimize): UX polish
- Rename "ctx" column to "overhead" with wider padding for legibility
  in the By Project panel.
- Name magic numbers for the project column widths.
- Empty-state now includes a one-line description of what optimize
  does, so first-time users with no findings still understand the
  feature.
2026-04-16 06:59:07 -07:00
AgentSeal
a9ca2a1134 feat(optimize): fix tracking via recent vs baseline split
Solves the problem where users who fixed an issue continued to see
the finding for the remainder of the period. Findings now show
visible progress or disappear entirely.

Mechanism (no state file, no new I/O):
- ToolCall and ApiCallMeta gain a `recent` boolean, set when the
  entry's timestamp falls inside a rolling 48-hour window.
- Each session-based detector counts recent vs total occurrences.
- computeTrend classifies each finding:
    active    -- recent rate matches baseline
    improving -- recent rate under half of baseline (green arrow)
    resolved  -- zero recent waste AND confirmed recent activity
- Resolved findings are suppressed. Improving findings render with
  a green "improving down-arrow" badge next to the impact label.
- When no recent activity exists, findings default to active so a
  user who simply paused is not told everything is fixed.

Applies to the four session-based detectors: junk reads, duplicate
reads, low read:edit ratio, cache bloat. The filesystem detectors
(missing .claudeignore, bloated CLAUDE.md, unused MCP, ghost agents
/ skills / commands, bash limit) already self-heal on next run.

5 new tests cover computeTrend edge cases. 126 tests pass.
2026-04-16 06:53:08 -07:00
AgentSeal
7e4edf66b6 perf(optimize): mtime pre-filter, parallel reads, result cache
- runWithConcurrency helper runs file reads with configurable parallelism
  (default 16) instead of sequential await.
- isFileStaleForRange skips files whose mtime is older than the date range
  start, avoiding unnecessary reads for narrow periods.
- Result-level cache keyed on (dateRange, project fingerprint) with
  60s TTL. Warm dashboard 'o' press now hits cache instead of rescanning.
- Early-return when projects array is empty so empty-state path does not
  trigger filesystem walk.

Measured CLI cold scan on 12K files, 1833 sessions week:
  before: 12-17s
  after: 6-7s
Dashboard warm cache hit: <50ms.
2026-04-16 06:35:39 -07:00
AgentSeal
be45045fd8 refactor(optimize): correctness, constants, and real tests
Phase 1 hardening pass.

Bug fixes:
- Move cwd/version collection inside date-range filter. 7d and 30d
  now produce different findings for filesystem detectors.
- detectGhostSkills threshold aligned with peer detectors.
- detectUnusedMcp gets 24-hour grace period via config file mtime so
  newly added servers are not flagged as unused.
- detectCacheBloat replaces hardcoded 50K baseline with user-derived
  p25 of cache writes. Flags only when median exceeds 1.4x baseline.
- detectBashBloat scans user shell profiles instead of the auditor's
  process.env.
- @-import pattern requires ./ ../ or / to avoid matching email
  addresses or npm scopes.
- Command usage pattern requires leading whitespace/start-of-line
  before /cmd so path references like /tmp are not counted as usage.
- AVG_TOKENS_PER_READ lowered from 1500 to 600 and
  CLAUDEMD_TOKENS_PER_LINE lowered from 25 to 13 for realistic
  prose/config sizing.

Code quality:
- Every magic number extracted to named module-scope constants.
- Dead code removed (IMPACT_ORDER, unused stat import).
- Shared loadMcpConfigs helper deduplicates config walking.
- Shared shortHomePath, isReadTool, inRange helpers.
- All detectors and computeHealth exported for real tests.
- Ghost detectors run in parallel via Promise.all.
- Cost rate defaults to 0 when unknown so UI can suppress instead of
  showing fabricated numbers.

Tests:
- Replaced 17 fake tests that re-implemented detector logic with
  26 tests importing and exercising the real exports.
- Cover threshold boundaries, impact scaling, edge cases.
- 121 tests pass.

UX header: "Setup" renamed to "Health", issue count shown inline.
CLAUDE.md: adds rule against "steal/copy/rip-off" wording in
public-facing text.
2026-04-16 06:30:15 -07:00
AgentSeal
b88f2cd730 feat: ghost detectors, health grade, @-import expansion
Expanded the optimize engine with new detectors and scoring:

1. Health score + letter grade (A-F) in optimize header. Weighted
   per-impact with caps. Gives users an instant "is my setup healthy"
   read that doubles as a shareable number.

2. Urgency score replaces impact-enum sort. Weighted 0.7 * impact
   + 0.3 * normalized tokens. Produces better-ranked findings.

3. Three new ghost detectors:
   - Ghost agents: files in ~/.claude/agents/ never invoked via
     Agent/Task tool
   - Ghost skills: SKILL.md directories never triggered
   - Ghost slash-commands: ~/.claude/commands/ files never referenced
     in user messages

4. @-import chain expansion for CLAUDE.md. Recursively follows
   @path/to/file imports (max depth 5) so bloat detection counts
   transitive load, not just the base file. Fixes undercounting for
   users with modular CLAUDE.md setups.

9 new tests covering health scoring and import expansion.
2026-04-16 05:09:01 -07:00
AgentSeal
710316053e feat: add optimize command, in-TUI optimize view, and per-project context budget
Optimize engine detects 8 waste patterns from Claude Code session data:
- Junk directory reads (node_modules, .git, dist, etc.)
- Duplicate file reads per session
- Unused MCP servers (configured but never called)
- Missing .claudeignore in projects with junk dirs
- Bloated CLAUDE.md files (>200 lines)
- Uncapped BASH_MAX_OUTPUT_LENGTH
- Low Read:Edit ratio (edit-without-reading, per #42796)
- High cache_creation overhead (per #46917)

Each finding includes impact rating, token/cost savings estimate, and
exact fix (paste, command, or file content).

Dashboard integration:
- o key switches to in-TUI optimize view, b key goes back
- Background scan on load, o button only when findings exist
- Per-project Context Budget column in By Project panel showing
  estimated per-call overhead (system + MCP tools + skills + CLAUDE.md)

CLI: codeburn optimize [-p period] [--provider]
2026-04-16 04:04:37 -07:00