Skip to content

feat(harness-ops): add a cost section to the morning brief - #8790

Merged
kyle-sexton merged 13 commits into
mainfrom
feat/morning-brief-cost-section
Oct 21, 2026
Merged

kyle-sexton merged 13 commits into
mainfrom
feat/morning-brief-cost-section

Conversation

@kyle-sexton

@kyle-sexton kyle-sexton commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Closes #8343

Summary

The morning brief gains a Cost section that shows whether anything on GitHub or Azure is charging, or could start charging. Every line is OK, ALERT, INFO or UNREADABLE, and an UNREADABLE line names its fix.

  • GitHub billing usage this month: ALERT when net > 0. Private-repo Actions minutes and artifact storage are compared with the plan's included amounts, ALERT at usage_alert_percent (default 50).
  • GitHub budgets: ALERT when the amount is > 0 or stop-at-limit is off.
  • Secret-narrowing triggers across the org's repos:
    • a direct collaborator who is not an org admin;
    • a pull_request_target or workflow_run workflow (bare, quoted, flow-style, or with a trailing comment) that references a _CLAUDE_ secret or passes every secret (secrets: inherit, toJSON(secrets), a computed index).
  • Azure budgets with their forecast: ALERT at or over the amount, or when the forecast is above forecast_alert. Each line carries the cost query's latest usage date and the read time.
  • Required budgets and the cost anomaly alert: ALERT when missing, disabled, or ending within expiry_days.
  • Log Analytics peak billable day against each workspace's daily cap: ALERT at log_cap_alert_percent, or when the workspace has no cap.
  • Defender charges month to date, from the Cost Management query (all pages): ALERT when > 0.
  • Defender plan, policy-assignment and role-assignment writes in the last 24h: ALERT.
  • Plan tier, secure score and Advisor counts: INFO.
  • Settings come from a flag, then harness-ops.local.yaml, then docs/conventions/harness-ops.yaml, then the default. The settings: line shows each value and its layer.

Follows the owner decisions Q42, Q45/Q52, Q48, Q54, Q60, Q61, Q3 and Q12.

Fix

  • One bash section in scripts/morning-brief.sh, with fixture flags for tests.

  • Read-only. The one Azure POST is the Cost Management query. Its next pages are POSTed only to the same query endpoint; a nextLink naming any other ARM path is UNREADABLE.

  • Local only: no workflow, no new credential. A settings file never turns a fixture run live.

  • Fails closed. A read that failed or was not made prints each line it feeds UNREADABLE and the brief exits 6:

    • a billing 403 for want of an org admin;
    • az absent or logged out;
    • a fixture run;
    • an org scan that listed no repo or hit its file cap;
    • a missing or wrong-typed field.

    Nothing prints as skipped.

  • Validation: the org must be a GitHub owner name and the alert percents must be 0-100. Control characters are stripped from printed values and escaped in parse errors.

  • The az dynamic extension install is disabled. The setting reaches the Windows az under WSL through WSLENV.

Verification

  • Head ae34ca0b39154681e627c3451096bbf249ec58cd:
    • morning-brief.test.sh: 410/410 pass;
    • morning-brief-view.test.sh: 14/14 pass;
    • shellcheck clean.
  • The fresh-context phase verifier and the security delta pass ran at 23d58ed8. Their findings are fixed in ae34ca0b, and each fix has a test that fails on 23d58ed8. The findings were:
    • the nextLink path pin;
    • quoted secrets: inherit;
    • an event name with a trailing comment.
  • A live run against melodic-software was made at an earlier head and has not been rerun at this head.
  • Left out, awaiting owner decisions:
    • Q17: the pr-verify.yml designed-path handling;
    • Q18: widening the secret-name filter to unprefixed CLAUDE_ names;
    • R4-6: the policy-assignment watch;
    • R4-8: the ADR 0075 userConfig layer.

Related

🤖 Generated with Claude Code

kyle-sexton and others added 2 commits October 20, 2026 23:22
The brief now shows, every morning, whether anything on GitHub or Azure is
charging or could start charging: GitHub billing usage and budgets, Azure
budgets, Defender charges month to date, Defender plan and access writes in
the last 24 hours, secure score and Advisor counts. Reads only; local only.
A read that fails or returns an unexpected shape prints UNREADABLE, never OK.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017SXDGDqYiL6gjmxogVtt1b
@kyle-sexton
kyle-sexton marked this pull request as ready for review October 21, 2026 03:27
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-21T03:29:33.593264Z e1a3e2d Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

claude-security-review reviewed 8286334bf9bb67f6739b0d9061319ed29b497797: 0 finding(s), 0 as inline comments.

Security review: no findings. I reviewed the incremental diff since f2868cf (morning-brief.sh and morning-brief.test.sh).

  • morning-brief.sh: SCRIPT_DIR falls back to . when BASH_SOURCE[0] has no slash, i.e. a bare-filename run.
    • The awk -f "$SCRIPT_DIR/lib/yaml-subset.awk" call uses the script's own directory, never a path from the settings file or from arguments.
    • A bare-filename run therefore reads the awk parser from the script's own directory. Nothing attacker-controlled chooses that path.
    • The variable is quoted, and the symlink skip and control-character escaping around the call are unchanged.
    • If the working directory changed before the call, the relative path would fail to find the parser. The result would be a parse failure, not execution of a different file.
  • morning-brief.test.sh: the test builds a $TMP/no-az-bin directory of symlinks to every executable on PATH except az.
    • Link names come from the existing directory entries on PATH. The directory sits under the test's own temp dir.
    • Quoting is correct. It is test-only code with no trust-boundary change.
    • The added bare-filename case runs under a subshell cd with fixture config.

The instruction-surface lens did not apply, because the diff deletes or softens no standing instruction.

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

claude-review reviewed 8286334bf9bb67f6739b0d9061319ed29b497797: 0 finding(s), 0 as inline comments.

No findings. I reviewed the incremental change since f2868cff in morning-brief.sh and morning-brief.test.sh. I only read the code and traced it. I did not run the tests, so the author's 410/410 count is unverified.

  • scripts/morning-brief.sh (SCRIPT_DIR): A bare-filename run (bash morning-brief.sh) used to strip nothing from BASH_SOURCE[0], so the awk parser path became morning-brief.sh/lib/yaml-subset.awk. SCRIPT_DIR now falls back to ., which fixes that. Nothing else in the script defines or uses SCRIPT_DIR. The other BASH_SOURCE[0] use (line 242) is separate and unaffected.
  • morning-brief.test.sh (bare-filename case): BRIEF is an absolute path and CFG and CFG_BRIEF point under $TMP, so cd "${BRIEF%/*}" followed by bash "${BRIEF##*/}" is valid. The new assertions check that the team-file setting is read and that no "could not be parsed" message appears.
  • morning-brief.test.sh (no-az PATH): The PATH is now a directory of symlinks to every executable on PATH except az, with the first entry of each name winning as PATH lookup would. The [[ … ]] && ln form is safe under set -uo pipefail (no -e). An unmatched glob fails the -x test and is skipped. The following command -v az check still guards that az is really absent.

The closing issue #8343 states two acceptance criteria. Neither is affected by this delta, and the earlier tests already cover the az-logged-out case.

kyle-sexton and others added 4 commits October 20, 2026 23:47
The cost section now covers every line the issue asks for:

- private-repo Actions minutes and artifact storage this month against
  the plan's included amounts (from flags), flagged at a configurable
  share; public repos, known from the org's repo list, are left out
- an org scan: direct collaborators besides org admins, and workflows on
  pull_request_target or workflow_run that reference a _CLAUDE_ secret
- each Log Analytics workspace's peak billable day over 31 days against
  its daily cap; no cap is an ALERT
- Azure budgets read with their forecast; a forecast above
  --forecast-alert (else the budget amount) is an ALERT
- required budgets and the anomaly alert: missing, disabled or ending
  within --expiry-days is an ALERT
- a logged-out az makes every Azure line UNREADABLE naming az login;
  SKIPPED stays for az absent with no --subscription

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017SXDGDqYiL6gjmxogVtt1b
SKILL.md lists the new reads, flags and ALERT rules, the logged-out
behaviour, and anchored pointers with recheck triggers for each new
upstream page; the changelog fragment covers the full section.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017SXDGDqYiL6gjmxogVtt1b
az reads its stdin, so inside the per-workspace loop the first query
consumed the remaining workspace ids and only one workspace printed.
Every az read now gets no stdin, and the test double drains its stdin
as az does, so the live-path test catches the regression.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017SXDGDqYiL6gjmxogVtt1b
The shell-portability gate flags \s; [[:space:]] matches the same in
jq's regex engine.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017SXDGDqYiL6gjmxogVtt1b
…on home

Every cost setting resolves through the config cascade: a flag, then
morning_brief in docs/conventions/harness-ops.local.yaml (gitignored),
then docs/conventions/harness-ops.yaml, then the default. An invalid
value is named and its key takes the default; an unparsable file is
named and skipped; the section's settings line names each value's layer.

This repository's team file sets the org, the plan's included minutes
and storage, the thresholds, the two required budgets and the anomaly
alert; the subscription stays out of it. The schema validates the file,
and morning-brief carries its own generated copy of the YAML-subset
reader.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017SXDGDqYiL6gjmxogVtt1b
kyle-sexton and others added 3 commits October 21, 2026 00:35
- The fork-trigger scan finds quoted and flow-style `on:` events, and
  counts `secrets: inherit`, `toJSON(secrets)` and a computed `secrets[...]`
  index as passing every secret; the `_CLAUDE_` name filter is unchanged.
- No line is SKIPPED: a read that failed or was not made prints each line
  it feeds UNREADABLE with its fix, and the brief exits non-zero.
- An org scan that listed no repo or hit its file cap is UNREADABLE with
  counts.
- Budget lines carry the cost query's latest usage date; the query now runs
  daily and follows nextLink pages on management.azure.com only.
- The org must be a GitHub owner name, alert percents are 0-100, the
  settings line shows values, a settings file never turns a fixture run
  live, and a parse error escapes control characters.
- SKILL.md drops two unpointed upstream claims and anchors the pricing
  pointers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017SXDGDqYiL6gjmxogVtt1b
Rows with no numeric UsageDate print the data date as unread; only a
query with no rows says there were none.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017SXDGDqYiL6gjmxogVtt1b
- A nextLink is followed only when it is the first page's query endpoint
  up to `?` (case-insensitive: the Query - Usage reference's examples
  spell the nextLink path `Query`), with no `..`, `//`, backslash, encoded
  dot or slash, or control character; any other ARM action is never run.
- The fork-trigger scan accepts a quoted `secrets: "inherit"` or
  `'inherit'`, and an event name followed by a trailing comment.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017SXDGDqYiL6gjmxogVtt1b
kyle-sexton and others added 3 commits October 21, 2026 01:12
…s a slash

- The `..`, `//`, `%2e` and `%2f` checks run only on the nextLink's path;
  the prefix match, backslash and control-character checks still cover the
  whole link. A $skiptoken holding `%2F`, `%2B` or `%3D` is now followed.
- Any non-ASCII byte in the nextLink rejects it, so the case fold behaves
  the same in every locale.
- The rejection tests put the traversal, doubled slash and encoded dot in
  the path, where they still reject.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- morning-brief.sh falls back to `.` when BASH_SOURCE holds no directory,
  so `bash morning-brief.sh` from its own directory still parses the
  settings files instead of skipping every layer.
- The no-az tests build a PATH directory linking every executable except
  az, so bash and jq stay reachable when az shares their directory, as
  /usr/bin does on the CI runner.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kyle-sexton
kyle-sexton added this pull request to the merge queue Oct 21, 2026
Merged via the queue into main with commit cf19a82 Oct 21, 2026
30 checks passed
@kyle-sexton
kyle-sexton deleted the feat/morning-brief-cost-section branch October 21, 2026 05:42
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.

feat(harness-ops): add a cost section to the morning brief

1 participant