Skip to content

Add packages/analyzers with the runner and the first rule - #5

Open
masaok wants to merge 1 commit into
workspace-corefrom
analyzers
Open

masaok wants to merge 1 commit into
workspace-corefrom
analyzers

Conversation

@masaok

@masaok masaok commented Oct 2, 2026

Copy link
Copy Markdown
Owner

Why

The plan's engine is a set of rules that all implement one Analyzer interface, public and premium alike. This adds that interface, the runner and the first rule, so the shape an adapter has to produce is fixed by a rule that reads it.

Scope

  • packages/analyzers (@costexplorer/analyzers, private for now):
    • Analyzer: an id, catalog text (title, category, tier, signal, fix) and analyze(input), a pure function.
    • ScanInput: asOf, costRecords and resources. Rules measure age against asOf, never the clock.
    • runAnalyzers: validates each finding against findingSchema, rejects a finding filed under another rule's id, reports a rule that throws and keeps the others, and returns findings ranked by saving. Two rules with one id is an error.
    • runRate: the monthly cost of a resource from its usage charges in the export.
    • aws.ebs.unattached: an available volume unattached for 14 full days or more.
  • packages/core gains resourceSchema, with aws.ebs.volume as its first member.
  • CONTRIBUTING.md gains the steps to add an analyzer.

Stacked on #4.

Tradeoffs

These are judgment calls in the first rule. They set the pattern for the other thirteen, so they are worth a look.

  • The saving comes from the bill, not a price list. A volume's saving is what the export charged for it, scaled to a 730-hour month. There is no pricing dataset yet. A volume with no charge in the export is reported with a saving of 0 and low confidence.
  • Confidence drops when the detach time is unknown. The EC2 inventory API does not say when a volume was detached. Without it the rule measures from the creation time and reports medium, because the volume may have been in use until yesterday.
  • The snapshot is not subtracted. The fix is "snapshot, then delete". A kept snapshot is billed separately, and the finding says so in evidence.note instead of guessing its size.
  • Order of the list. The status list has the AWS adapter before the analyzers. This went first because the adapter's output is whatever ScanInput needs.

Verification

VERIFIED. pnpm verify on Node 24.21.0.

$ next typegen && tsc --noEmit && pnpm -r typecheck
$ eslint --max-warnings 0
All matched files use Prettier code style!
PASS feature-map (2 surfaces in code, 2 rows)
PASS docs-links (30 relative links in 11 markdown files)
PASS versions (Node 24, 2 workflow files)
ℹ tests 13
ℹ pass 13
ℹ fail 0
 Test Files  8 passed (8)
      Tests  43 passed (43)
Statements   : 100% ( 82/82 )
Branches     : 100% ( 41/41 )
Functions    : 100% ( 25/25 )
Lines        : 100% ( 69/69 )
PASS GET / 200, text "To get started, edit the"
PASS GET /favicon.ico 200, type "image/x-icon"
2 surfaces requested, 0 failures

index.test.ts runs the public rule set end to end over a scan with one idle and one busy volume and gets exactly one finding, vol-idle at $7.30 a month.

NOT VERIFIED: the rule has only run on fixtures. No real export or AWS inventory has been through it, because no adapter exists yet. The aws ec2 commands in the remediation were not executed.

https://claude.ai/code/session_01WTtRZcdke1yYdYUAanaf7V

An Analyzer is metadata for the rule catalog plus a pure function of
the scan input. runAnalyzers validates every finding, isolates a rule
that fails and returns the findings ranked by saving.

The first rule, aws.ebs.unattached, prices a volume from what the export
actually charged for it. core gains the resource inventory types the
rule reads.

Claude-Session: https://claude.ai/code/session_01WTtRZcdke1yYdYUAanaf7V
Copilot AI balanced review requested due to automatic review settings October 2, 2026 00:07
@vercel

vercel Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
costexplorer Ready Ready Preview Oct 2, 2026 12:07am UTC

Request Review

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

This branch was successfully deployed

1 active deployment
Preview — beabd9ec Deployed Oct 2, 2026 by vercel[bot]
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.

2 participants