Skip to content

feat: v0.3.0 — policy engine, suggestion comments, 14-region ledger#9

Merged
omrdev1 merged 1 commit into
mainfrom
feat/v0.3.0
Mar 27, 2026
Merged

feat: v0.3.0 — policy engine, suggestion comments, 14-region ledger#9
omrdev1 merged 1 commit into
mainfrom
feat/v0.3.0

Conversation

@omrdev1
Copy link
Copy Markdown
Owner

@omrdev1 omrdev1 commented Mar 27, 2026

Summary

Three additive features built on top of the existing offline-first, zero-dependency architecture. Nothing deleted, everything strengthened.


1. .greenops.yml Policy Engine

Teams can now define carbon budgets that are enforced on every PR:

version: 1
budgets:
  max_pr_co2e_increase_kg: 10
  max_pr_cost_increase_usd: 500
fail_on_violation: true
  • Zero-dependency YAML parser — no new runtime dependencies
  • Fail-open: no .greenops.yml = always passes; parse errors are warnings not fatal
  • fail_on_violation: true exits with code 1, blocking the PR
  • All violations collected in a single pass — engineers see the full picture

2. GitHub Inline Suggestion Comments

When --post-suggestions is enabled, GreenOps posts suggestion comments directly on the Terraform lines that need changing. The developer clicks Commit suggestion and the instance_type is rewritten in-place:

- name: GreenOps Carbon Lint
  uses: omrdev1/greenops-cli@v0
  with:
    plan-file: plan.json
    github-token: ${{ secrets.GITHUB_TOKEN }}
    post-suggestions: true
  • Zero runtime dependencies — Node 20 native fetch exclusively
  • Idempotent — existing suggestion comments are updated, not duplicated
  • Fail-open — suggestion errors never block the CLI

3. Expanded Methodology Ledger (v1.2.0)

Before After
Instances 12 40
Regions 5 14

New families: t3a, m5a, m7g, c7g, r6g, c5a, r5, m5.2xlarge, c5.2xlarge

New regions: us-east-2, us-west-1, eu-west-2, eu-north-1 (Stockholm, 8.8 gCO2e/kWh), ap-southeast-1, ap-northeast-1, ap-south-1, ca-central-1, sa-east-1

Tests

60 tests, 60 passing. Includes 9 new policy engine tests.

npm license fix

package.json was missing the license field, causing npm to display None. Fixed.

## Policy Engine (policy.ts)
- Zero-dependency YAML parser for .greenops.yml
- Budget constraints: max_pr_co2e_increase_kg, max_pr_cost_increase_usd, max_total_co2e_kg
- Fail-open: missing policy file always passes; parse errors are warnings not fatal
- fail_on_violation flag controls exit code (1 = block PR, 0 = warn only)
- 9 new tests covering all constraint paths, multi-violation collection, and error handling

## GitHub Suggestion Comments (suggestions.ts)
- Posts inline Terraform suggestion comments using GitHub's suggestion syntax
- Developer clicks 'Commit suggestion' to rewrite instance_type in-place
- Zero runtime dependencies — uses Node 20 native fetch exclusively
- Idempotent: existing GreenOps suggestion comments are updated, not duplicated
- Fail-open: suggestion errors never block the CLI (exit 0 with warning)
- Region-shift suggestions gracefully degrade with a warning (no single line to target)

## Expanded Methodology Ledger (factors.json v1.2.0)
- Instances: 12 → 40 (adds t3a, m5a, m5.2xlarge, c5a, r5, t4g.micro/small/xlarge,
  m6g.medium/2xlarge, m7g family, c6g.medium/2xlarge, c7g family, r6g family)
- Regions: 5 → 14 (adds us-east-2, us-west-1, eu-west-2, eu-north-1, ap-southeast-1,
  ap-northeast-1, ap-south-1, ca-central-1, sa-east-1)
- eu-north-1 (Stockholm, 8.8 gCO2e/kWh) is now the cleanest supported region
- All grid intensity values sourced from Electricity Maps 2024 annual averages
- All pricing from AWS public pricing API Q1 2026

## CLI updates (cli.ts)
- New flags: --github-token, --repo, --pr-number, --commit-sha, --post-suggestions
- Policy evaluation runs automatically when .greenops.yml is present
- --help output updated with all new flags

## Action updates (action.yml)
- New input: post-suggestions (default: false) — enables one-click Terraform patches
- Updated description to reflect full capabilities

## Test updates
- recommendation.test.ts: updated to reflect new 14-region ledger behaviour
  (eu-north-1 now wins scoring over ARM for high-carbon regions — correct behaviour)
- integration.test.ts: updated math traces and assertions for v1.2.0 ledger
- Total: 60 tests, 60 passing

## npm fix
- package.json: license field now present (was missing, causing npm to show 'None')
@github-actions
Copy link
Copy Markdown

🌱 GreenOps Infrastructure Impact

Total Current Footprint: 7.06kg CO2e/month | $126.29/month
Potential Savings: -6.90kg CO2e/month (97.7%) | -$5.11/month
💡 Found 2 optimization recommendations.

Resource Breakdown

Resource Type Region CO2e/month Cost/month Action
aws_instance.web m5.large us-east-1 4.31kg $70.08 💡 View Recommendation
aws_instance.worker m6g.large us-east-1 2.74kg $56.21 💡 View Recommendation

Recommendations

aws_instance.web

  • Current: m5.large in us-east-1
  • Suggested: m5.large in eu-north-1
  • Impact: -4.21kg CO2e/month | +$2.92/month
  • Rationale: Moving m5.large from us-east-1 to Europe (Stockholm) (eu-north-1) reduces grid carbon intensity from 384.5g to 8.8g CO2e/kWh, saving 4215g CO2e/month (note: cost increases by $2.92/month).

aws_instance.worker

  • Current: m6g.large in us-east-1
  • Suggested: m6g.large in eu-north-1
  • Impact: -2.68kg CO2e/month | +$2.19/month
  • Rationale: Moving m6g.large from us-east-1 to Europe (Stockholm) (eu-north-1) reduces grid carbon intensity from 384.5g to 8.8g CO2e/kWh, saving 2681g CO2e/month (note: cost increases by $2.19/month).

Emissions calculated using the Open GreenOps Methodology Ledger (v1.2.0). Scope 2 operational emissions only — embodied carbon and water are not tracked. Math is MIT-licensed and auditable. Analysed at 2026-03-27T18:09:42.900Z. Learn more.

🏢 Managing green-ops across dozens of repositories? Upgrade to GreenOps Dashboard to aggregate CI/CD carbon data natively.

@omrdev1 omrdev1 merged commit 83d9851 into main Mar 27, 2026
2 checks passed
@omrdev1 omrdev1 deleted the feat/v0.3.0 branch March 28, 2026 10:48
omrdev1 added a commit that referenced this pull request May 19, 2026
## Policy Engine (policy.ts)
- Zero-dependency YAML parser for .greenops.yml
- Budget constraints: max_pr_co2e_increase_kg, max_pr_cost_increase_usd, max_total_co2e_kg
- Fail-open: missing policy file always passes; parse errors are warnings not fatal
- fail_on_violation flag controls exit code (1 = block PR, 0 = warn only)
- 9 new tests covering all constraint paths, multi-violation collection, and error handling

## GitHub Suggestion Comments (suggestions.ts)
- Posts inline Terraform suggestion comments using GitHub's suggestion syntax
- Developer clicks 'Commit suggestion' to rewrite instance_type in-place
- Zero runtime dependencies — uses Node 20 native fetch exclusively
- Idempotent: existing GreenOps suggestion comments are updated, not duplicated
- Fail-open: suggestion errors never block the CLI (exit 0 with warning)
- Region-shift suggestions gracefully degrade with a warning (no single line to target)

## Expanded Methodology Ledger (factors.json v1.2.0)
- Instances: 12 → 40 (adds t3a, m5a, m5.2xlarge, c5a, r5, t4g.micro/small/xlarge,
  m6g.medium/2xlarge, m7g family, c6g.medium/2xlarge, c7g family, r6g family)
- Regions: 5 → 14 (adds us-east-2, us-west-1, eu-west-2, eu-north-1, ap-southeast-1,
  ap-northeast-1, ap-south-1, ca-central-1, sa-east-1)
- eu-north-1 (Stockholm, 8.8 gCO2e/kWh) is now the cleanest supported region
- All grid intensity values sourced from Electricity Maps 2024 annual averages
- All pricing from AWS public pricing API Q1 2026

## CLI updates (cli.ts)
- New flags: --github-token, --repo, --pr-number, --commit-sha, --post-suggestions
- Policy evaluation runs automatically when .greenops.yml is present
- --help output updated with all new flags

## Action updates (action.yml)
- New input: post-suggestions (default: false) — enables one-click Terraform patches
- Updated description to reflect full capabilities

## Test updates
- recommendation.test.ts: updated to reflect new 14-region ledger behaviour
  (eu-north-1 now wins scoring over ARM for high-carbon regions — correct behaviour)
- integration.test.ts: updated math traces and assertions for v1.2.0 ledger
- Total: 60 tests, 60 passing

## npm fix
- package.json: license field now present (was missing, causing npm to show 'None')

Co-authored-by: GreenOps E2E <greenops-e2e@test.local>
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