Commit graph

152 commits

Author SHA1 Message Date
Ninym
9f6827d528 fix(copilot): use bounded readSessionFile helper
Events JSONL and workspace.yaml reads now pass through the 128 MB-capped
helper. The workspace.yaml path stays non-fatal: a null read skips cwd
derivation but still pushes the session with sessionId as the fallback
project label. MEDIUM-1 coverage for the Copilot provider.
2026-04-17 08:32:19 +02:00
Ninym
1de0baf329 fix(codex): use bounded readSessionFile helper
Both Codex session read paths (first-line meta and full-session parse)
now pass through the 128 MB-capped helper. MEDIUM-1 coverage for the
Codex provider.
2026-04-17 08:32:19 +02:00
Ninym
ee738a1b26 fix(parser): use bounded readSessionFile helper
Replaces the unbounded readFile in parseSessionFile with the 128 MB-capped
helper from src/fs-utils. Addresses MEDIUM-1 for the Claude provider
hot path.

Verbose-mode stderr output replaces the previous silent catch,
closing LOW-1 as a side effect.
2026-04-17 08:32:19 +02:00
Ninym
82c3125638 feat(fs-utils): bounded session-file read helper
Adds readSessionFile / readSessionFileSync / readSessionLines with a
128 MB hard cap and 8 MB streaming threshold. Verbose mode
(CODEBURN_VERBOSE=1) logs skipped and failed reads to stderr.

Prepares the MEDIUM-1 migration of all provider read paths.
2026-04-17 08:32:19 +02:00
Ninym
0ab66f6fe9 test(fs-utils): add failing test for bounded read helper
Tests the to-be-built readSessionFile helper: under-cap fast path,
at-threshold stream path, over-cap null+skip, verbose stderr warning,
and stat-failure graceful fallback. Fails against missing module --
Task 5 will implement src/fs-utils.ts to flip GREEN.
2026-04-17 08:32:18 +02:00
Ninym
5b810161e7 fix(parser): block prototype pollution via Object.create(null)
Initialize the four breakdown maps (model, tool, mcp, bash) with null
prototype so attacker-controlled keys named __proto__ create own
properties on the map instead of mutating Object.prototype.

Closes the HIGH-1 finding from the 2026-04-16 external security audit.
2026-04-17 08:32:18 +02:00
Ninym
e890d9bfc3 test(security): add failing test for HIGH-1 prototype pollution
Three PoC fixtures (tool name, bash command, model name) reproduce
the audit's HIGH-1 attack. Tests assert Object.prototype.calls stays
undefined after parsing. They fail against current parser.ts -- Task 3
will close the pollution sink with Object.create(null).
2026-04-17 08:32:18 +02:00
AgentSeal
f2d1753d3a
Merge pull request #60 from AgentSeal/feat/optimize
feat: codeburn optimize -- find waste and get copy-paste fixes
2026-04-17 01:31:52 +02:00
AgentSeal
005bdaaf07 chore: release 0.7.0 -- codeburn optimize
New top-level command plus in-TUI view for finding token waste and
getting copy-paste fixes. 11 detectors, A-F setup health grade,
recent-vs-baseline trend tracking, per-project context budget column.
198 tests.
2026-04-16 16:31:19 -07:00
AgentSeal
40b7de6841 docs: add optimize section with screenshot and command reference
Sits between 'Reading the dashboard' (what the numbers mean) and
'How it reads data' (where the data comes from) so the feature lands
as the natural next step: here is how to act on the patterns you saw.
2026-04-16 16:27:33 -07: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
1cd96ea19f Merge origin/main into feat/optimize
Resolve conflicts in src/dashboard.tsx: keep optimize view plumbing
(setOptimizeResult, OptimizeResult state, o/b keys) while integrating
project/exclude filters on reloadData and renderDashboard entry.
2026-04-16 16:08:20 -07:00
AgentSeal
3ea2c0b255 chore: release 0.6.1 -- JSON output, project filters, claude-opus-4-7, Top Sessions fix 2026-04-16 15:55:29 -07:00
AgentSeal
87210da598 Merge pull request #52 from mallek/feature/project-filter
feat: add --project and --exclude filters for project-level filtering
2026-04-16 15:52:57 -07:00
AgentSeal
d15532af0b fix: apply --project/--exclude to menubar per-provider today totals
The menubar status output computes per-provider today costs by iterating
all providers after the main period blocks. That loop bypassed the
project filter, so --project/--exclude affected the main totals but not
the provider breakdown shown below them.
2026-04-16 15:50:00 -07:00
AgentSeal
98c1e266d7 test: cover filterProjectsByName include/exclude semantics
Adds unit tests for the project-filter helper: include OR semantics,
exclude AND-negation, case-insensitive matching against both project name
and projectPath, ordering (exclude applied after include), empty-string
edge case, and input immutability.
2026-04-16 15:49:57 -07:00
AgentSeal
d90042ec3c fix: stop Top Sessions panel from truncating the calls column
The TopSessions row layout summed to the full panel width without
leaving room for the Box border (round) + paddingX, so Ink truncated
the last 4 characters -- landing exactly on the calls column and
producing rows like "$182.58 ..." with no calls value.

Introduce PANEL_CHROME = 4 and subtract it from the name column so the
row fits inside the panel's inner area.
2026-04-16 15:44:39 -07:00
Travis Haley
67c504a60a feat: add --project and --exclude filters for project-level filtering
Adds two new repeatable flags to all commands (report, today, month, status, export):
- --project <name>: include only projects matching name (substring, case-insensitive)
- --exclude <name>: exclude projects matching name (substring, case-insensitive)

Both flags can be specified multiple times to match multiple projects.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 15:54:37 -06:00
AgentSeal
4154413e59 chore: DRY json report branches and drop unused import
- extract Period type alias
- hoist repeated json action body into runJsonReport helper
- remove unused getCostColumnHeader import
2026-04-16 14:43:03 -07:00
AgentSeal
f3482de33d
Merge pull request #53 from mallek/feature/json-output
feat: add --format json to report, today, and month commands
2026-04-16 23:39:25 +02:00
AgentSeal
b0d7a8b678
Merge pull request #57 from Galeas/main
fix: respect SwiftBar settings when installing the menu bar
2026-04-16 22:10:21 +02:00
AgentSeal
bd90d9c412
Merge pull request #58 from mallek/fix/claude-opus-4-7-model-mapping
fix: add claude-opus-4-7 model mapping and pricing
2026-04-16 22:04:49 +02:00
AgentSeal
21444df2bf merge main into feat/optimize
- resolve dashboard.tsx conflicts: keep optimize view + context budget column alongside main's all-time period and TopSessions panel
- ProjectBreakdown: add avg/s column from main plus overhead column from optimize, widths 30/40
- StatusBar: 1-5 periods including all-time, plus o-optimize when findings exist
- DashboardContent: all-time period handling and TopSessions panel preserved

Copilot provider and its 253 tests from main merged cleanly as additions.
2026-04-16 12:56:53 -07:00
Travis Haley
634a8f11ab fix: add claude-opus-4-7 model mapping and pricing 2026-04-16 13:48:58 -06:00
akki
9b6a9e8fc3 fix: respect SwiftBar settings when installing the menu bar 2026-04-16 22:39:51 +03:00
Travis Haley
7a061ea679 feat: add periodKey and topSessions to JSON output 2026-04-16 13:13:09 -06:00
Travis Haley
60712785d7 style: remove section-label comments per repo convention 2026-04-16 13:10:05 -06:00
Travis Haley
fad21f3097 fix: destructure cost before spread so convertCost isn't overwritten in models JSON output 2026-04-16 13:08:46 -06:00
Travis Haley
09139b1d92 feat: add --format json to report, today, and month commands
Outputs full dashboard data as structured JSON to stdout, including:
overview, daily breakdown, projects, models with token counts,
activities with one-shot rates, core tools, MCP servers, and
shell commands.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 12:21:51 -06:00
AgentSeal
b1818263cc
Merge pull request #54 from AgentSeal/chore/0.6.0-release
chore: release 0.6.0
2026-04-16 19:30:43 +02:00
AgentSeal
6258d01b2f chore: release 0.6.0 -- Copilot provider, All Time, avg/s, Top Sessions
Release notes cover the two merged PRs:

- #44: GitHub Copilot provider parsing ~/.copilot/session-state/ with
  model tracking via session.model_change events. Adds fallback pricing
  for six gpt/o3/o4 models. Copilot logs only output tokens, so cost
  rows sit below actual API cost; documented in README and CHANGELOG.
- #51: All Time period (key 5, -p all), avg/s column in By Project,
  and a new Top Sessions panel showing the five most expensive sessions
  across all projects.

README: provider list updated (Copilot added, output-tokens-only caveat
alongside Cursor's Auto-mode estimation note), usage examples include
`-p all` and key `5`, provider filter list includes `copilot`.

CHANGELOG: 0.6.0 entry lists both features with contributor credits,
plus two fixes (longest-key-first model display sort and empty
firstTimestamp placeholder).

114 tests pass. Build succeeds at 132KB.
2026-04-16 10:18:14 -07:00
AgentSeal
1e01020ee9
Merge pull request #44 from theodorosD/feat/copilot-provider
feat: add GitHub Copilot provider
2026-04-16 19:02:57 +02:00
AgentSeal
e228903d68
Merge pull request #51 from lfl1337/feat/power-user-stats
feat: All Time period, avg/s per project, Top Sessions panel
2026-04-16 18:54:30 +02: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
c02f63235a test(optimize): add 34 filesystem-mocking tests
Covers previously untested detectors and helpers with real temp-dir
fixtures (not stubs) to verify behavior against actual file I/O.

New coverage:
- detectMissingClaudeignore: project with/without junk dirs and
  .claudeignore, impact scaling.
- detectBloatedClaudeMd: plain oversized file, @-import expansion,
  circular import safety, email/npm-scope @-token filtering.
- loadMcpConfigs: project reads, colon-to-underscore normalization,
  malformed JSON tolerance.
- detectUnusedMcp: 24-hour grace period, config vs invocation merge.
- detectBashBloat: env var unset, configured under/over limit.
- detectGhostCommands: path prefixes are not commands, <command-name>
  tag parsing.
- scanJsonlFile: missing file, tool_use parsing, malformed line
  skipping, date-range filter.
- scanAndDetect: empty projects returns healthy result.
- estimateContextBudget: system base, MCP tools, memory files.
- discoverProjectCwd: empty dir, no jsonl, cwd extraction.

Uses vi.mock to redirect os.homedir() to a disposable temp directory,
so tests do not read the tester's real ~/.claude. 34 tests, <30ms
wall time. Total suite now 160 tests.
2026-04-16 09:33:03 -07:00
Teo Delis
e7633d932b fix: address PR review feedback on Copilot provider
- init currentModel to '' and skip assistant messages before first
  session.model_change to avoid silent misattribution
- add comment documenting why inputTokens is always 0
- fix delete_file tool mapping ('Edit' -> 'Delete')
- add schema doc comment to ToolRequest optional fields
- remove catch-all from CopilotEvent union for proper TS narrowing
- add tests: pre-model-change skip, workspace.yaml quote/comment strip,
  longest-prefix model display name match
2026-04-16 19:30:08 +03: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
Ninym
0461193819 fix: handle empty firstTimestamp in TopSessions, add dashboard tests
- TopSessions: show '----------' placeholder when session.firstTimestamp
  is empty (Copilot provider yields '' when timestamp is missing)
- DashboardContent: add comment explaining undefined days tri-state
- tests/dashboard.test.ts: cover top-5 selection (fewer than 5 sessions,
  tied costs, descending sort) and avg/s returning '-' for zero sessions

Authored-by: AgentSeal <hello@agentseal.org>
2026-04-16 15:48:24 +02: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
Teo Delis
a8517d3235 feat: add GitHub Copilot provider
- Parse ~/.copilot/session-state/*/events.jsonl
- Track model via session.model_change events
- Extract tools from assistant.message toolRequests
- Add fallback pricing for gpt-4.1, gpt-4.1-mini, gpt-4.1-nano, gpt-5-mini, o3, o4-mini
- Factory function createCopilotProvider(sessionStateDir?) for testability
- Typed event variants (ModelChangeData, UserMessageData, AssistantMessageData)
- bashCommands: [] in yield (Copilot does not log bash commands)
- 13 tests covering parsing, model tracking, tool extraction, dedup, discoverSessions
- Note: only outputTokens available (Copilot does not log input tokens)
2026-04-16 15:40:22 +03: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
Ninym
cfd046a95c feat: add All Time period, avg/s per project, and Top Sessions panel
- Add 'all' period (key 5) to dashboard showing data from all time
- Daily Activity panel shows all available days when All Time is active
- Add avg cost per session column to Project breakdown
- Add Top Sessions panel highlighting the 5 most expensive sessions
2026-04-16 13:14:34 +02: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
AgentSeal
9794b5450a 0.5.7 2026-04-16 02:21:48 -07:00
AgentSeal
22b096a841 docs: add reading-the-dashboard guide to README
Lists common signals in the dashboard (cache hit, retry rate,
model mix, tool patterns) and what each typically means.
Points readers toward interpreting their own data without
overpromising automatic diagnosis.
2026-04-16 02:15:19 -07:00
AgentSeal
55d82a4526 Merge branch 'feat/pi-provider' 2026-04-16 02:14:53 -07:00