Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
bump: minor
---

### Added

- `/harness-ops:morning-brief` prints a `SPEND:` line in the Lanes section for each credential role whose API-key legs it read, from the lane-outcome records' `costUsd` (the CLI's list-price estimate, not billing): a per-day estimate from the median cost of the role's successful key legs, credit stops left out, times the runs of the lanes those legs ran in, with the number of key legs read and their sum. Subscription-token legs are left out, and a role whose key legs carry no cost prints `cost not recorded`. It makes no new API calls.
7 changes: 4 additions & 3 deletions plugins/harness-ops/skills/morning-brief/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ Upstream facts the script restates, each with its verification record:
| Parked decisions | open issues with the decision label (default `status: needs-decision`) | Surfaces each one's RECOMMENDED line, the uppercase marker wins over an incidental lowercase mention; a case-insensitive fallback catches lowercase markers; pass `--decision-label` to pin |
| Lane telemetry | the loop-lane telemetry issue's per-lane comments | Each lane's `last-cycle` age (marked `STALE` past `--stale-hours`, default 6) and any `flags:` |
| Stranded findings | merged PRs whose unresolved review threads were **created after the merge** | One line per PR at its worst severity, with a finding count. The header prints the window: merges since the older of `--stranded-days` ago (default 3) and the repo's bookmark. Paging stops at that cutoff |
| Lanes | the last 7 days of runs of each lane workflow, and the check-run annotations of their jobs | One row per lane: runs, failures by class (rate-limit, max-turns, auth, other), limit stops, restarts (a run on an item whose previous run was a limit stop), and items with 3+ limit stops. Then turns used (max, p90) against the cap, with `CHECK` and run links when a run hit max-turns or the p90 is at or above 80% of the cap. Class, turns and cap come from the lane record when it carries them, else from the SDK result and the action's turn-cap annotation; a turn-cap stop counts as max-turns whatever class the record gives. Lanes default to the Claude workflows the repo has; `--lane-workflows` pins them. Annotations are read for `--lane-read-limit` runs (default 200): the newest 3 of each lane whatever their conclusion, then failed runs; past it the row says `unread` and the section `PARTIAL`. Then one `KEY:` line per credential role whose API key needs the owner, from the runs' lane-outcome records: `auth` when a run fell back off a refused key or a key leg failed with class auth, naming the key secret to replace; `credit-stop` when a run fell back on a credit stop, naming the role to rotate a spare key into. Each counts the flagged runs against the runs read for that role, and a role with no key problem prints nothing. The fallback reason marks a credit stop, never the class. Then a model-usage table, the baseline before model routing changes anything: one row per activity and profile over the runs whose annotations carry a lane record, with runs, passes (run conclusion success), median turns, max-turns hits and the models the records name, never sizes or costs. The activity is a pipeline lane's activity (`<lane> / <activity>`), else the lane; the profile is the record's `profile=`, else `unknown`. A row whose max-turns hits exceed `--max-turns-hits` gets a `RECOMMENDED` line; with the flag unset (the default) the table says no threshold is set |
| Lanes | the last 7 days of runs of each lane workflow, and the check-run annotations of their jobs | One row per lane: runs, failures by class (rate-limit, max-turns, auth, other), limit stops, restarts (a run on an item whose previous run was a limit stop), and items with 3+ limit stops. Then turns used (max, p90) against the cap, with `CHECK` and run links when a run hit max-turns or the p90 is at or above 80% of the cap. Class, turns and cap come from the lane record when it carries them, else from the SDK result and the action's turn-cap annotation; a turn-cap stop counts as max-turns whatever class the record gives. Lanes default to the Claude workflows the repo has; `--lane-workflows` pins them. Annotations are read for `--lane-read-limit` runs (default 200): the newest 3 of each lane whatever their conclusion, then failed runs; past it the row says `unread` and the section `PARTIAL`. Then one `KEY:` line per credential role whose API key needs the owner, from the runs' lane-outcome records: `auth` when a run fell back off a refused key or a key leg failed with class auth, naming the key secret to replace; `credit-stop` when a run fell back on a credit stop, naming the role to rotate a spare key into. Each counts the flagged runs against the runs read for that role, and a role with no key problem prints nothing. The fallback reason marks a credit stop, never the class. Then one `SPEND:` line per credential role whose API-key legs were read, from the records' `costUsd`, whose meaning the lane-outcome pointer below names (for how cost is tracked, [Manage costs](https://code.claude.com/docs/en/costs#track-your-costs)): a per-day estimate, the median cost of the role's successful key legs (credit stops left out) times the runs of the lanes those legs ran in, divided by the days read, with the key legs read as `n=` and their sum. Subscription-token legs are left out, and a role whose key legs carry no cost prints `cost not recorded`. Then a model-usage table, the baseline before model routing changes anything: one row per activity and profile over the runs whose annotations carry a lane record, with runs, passes (run conclusion success), median turns, max-turns hits and the models the records name; it shows no sizes. The activity is a pipeline lane's activity (`<lane> / <activity>`), else the lane; the profile is the record's `profile=`, else `unknown`. A row whose max-turns hits exceed `--max-turns-hits` gets a `RECOMMENDED` line; with the flag unset (the default) the table says no threshold is set |
| Cost | GitHub: `gh api` org billing usage (this month) and budgets; the org's repos and admins, and per live repo its direct collaborators and default-branch workflow files. Azure, when `az account show` succeeds: budgets with their forecast and the Cost Management scheduled actions (`az rest` GETs), `az security pricing list`, a month-to-date Cost Management query (`az rest` POST), `az monitor log-analytics workspace list` and one Usage-table query per workspace, `az monitor activity-log list --offset 1d`, `az security secure-scores list`, and `az advisor recommendation list --category Security` and `--category Cost` | One line per check, each `OK`, `ALERT`, `INFO` or `UNREADABLE`. `ALERT`: a product whose net this month is above 0; private-repo Actions minutes or artifact storage at `--usage-alert-percent` (default 50) of `--actions-included-minutes` or `--actions-included-storage-gb` (unset: the line is `INFO` with the amount used); a GitHub budget above 0 or not stopping at its limit; a direct collaborator who is not an org admin or in `--allowed-collaborators`; a workflow on `pull_request_target` or `workflow_run` (the event key bare, quoted, or in a flow sequence or mapping) that references a secret whose name contains `_CLAUDE_`, or passes every secret (`secrets: inherit`, `toJSON(secrets)`, a computed `secrets[...]` index); an Azure budget whose spend reached its amount or whose forecast is above `--forecast-alert` (default: the budget's amount); a `--required-budgets` budget that is missing, or the `--anomaly-alert` alert (default: any cost anomaly alert) missing or disabled, or either ending within `--expiry-days` (default 30); a workspace whose peak billable day over 31 days is at `--log-cap-alert-percent` (default 50) of its daily cap, or that has no cap; a month-to-date actual cost above 0 on any cost row whose service or meter category names Defender or Security Center; a Defender plan, policy assignment or role assignment write in the last day. A repo's Actions usage counts as private unless the org's repo list says it is public; with no repo list read, the line says every repo was counted as private. Budget lines print the latest usage date in the month-to-date cost query (its daily `UsageDate` column) as the data date, beside the read time; with the query unread they say the data date is unread. The Defender plans line lists any plan not on Free as `INFO`, never `ALERT`. The secure score and Advisor counts are `INFO`. The org is `--org`, else the repo's owner, and must be a GitHub owner name; the subscription is `--subscription`, else az's current one. A fixture run reads neither live unless `--org` or `--subscription` is passed as a flag; a settings file never makes it live |

The Stuck section depends on two GraphQL facts, the result cap of a search and the fields of a
Expand All @@ -216,13 +216,14 @@ wrong, read the current shapes live:
- **Pointer**: the lane record and its classes, ci-workflows
[`report-lane-outcome/action.yml`](https://github.com/melodic-software/ci-workflows/blob/main/.github/actions/report-lane-outcome/action.yml)
and [`classify.cjs`](https://github.com/melodic-software/ci-workflows/blob/main/.github/actions/report-lane-outcome/classify.cjs);
the lane-outcome record's fields (`credential`, `fallback`), ci-workflows
the lane-outcome record's fields (`credential`, `fallback`, `costUsd`), ci-workflows
[`docs/lane-outcome.md` § Fields](https://github.com/melodic-software/ci-workflows/blob/main/docs/lane-outcome.md#fields);
the turn-cap annotation, claude-code-action
[`base-action/src/run-claude-sdk.ts`](https://github.com/anthropics/claude-code-action/blob/main/base-action/src/run-claude-sdk.ts).
- **As of**: 2026-10-23
- **Recheck trigger**: a ci-workflows release changes the lane record's fields, class names,
fallback reasons or record version, or a claude-code-action release changes its turn-cap message.
fallback reasons, what `costUsd` measures, or the record version, or a claude-code-action
release changes its turn-cap message.

A pipeline lane's activity is read from the name of the job that carries the record, which the
pipeline lanes name after the activity, so it costs no read beyond the jobs read. The
Expand Down
63 changes: 63 additions & 0 deletions plugins/harness-ops/skills/morning-brief/morning-brief.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1679,6 +1679,69 @@ assert_not_contains "keys live: a later record in one message flags no role" "$K
assert_contains "keys live: the cap's overflow is reported" "$KEYS_LIVE" \
" PARTIAL: annotations read for 200 runs, the newest 3 of each lane and then failed runs first; 3 more were not read (raise --lane-read-limit)"

# --- Lanes: per-role spend from the records' costUsd ----------------------------
# Fixture amounts are synthetic round numbers, not rates. AUTOMATIONS spans two
# lanes: pr-verify runs 100 and 101 are successful key legs (1 and 3), run
# 102's key leg hit a credit stop (4, left out of the median) and its
# subscription leg carries a cost (9, a token leg, ignored), and run 103 was
# not read; intake-triage run 110 is a successful key leg (2) and run 111 was
# not read. Median 2 per key leg times the 6 runs of those lanes, over 7 days;
# the sum covers every key leg read, the credit stop's included (1+3+4+2).
# REVIEWS run 120's key leg has no costUsd. EVEN's successful legs in runs 121
# and 122 cost 1 and 4 (median 2.5 over pr-review-hosted's 3 runs); its
# credit-stop leg (100) counts only in the sum, and its -1 and "2" costs are not
# costs. HUGE's cost is past the bound; role "bad" is not a role. PR_UNBLOCK
# run 130 is a token leg.
cat >"$TMP/spend-runs.json" <<'EOF'
{
"pr-verify.yml": [
{"id": 100, "html_url": "http://x/runs/100", "event": "workflow_run", "display_title": "PR S1", "head_sha": "s1", "status": "completed", "conclusion": "success", "created_at": "2026-07-19T10:00:00Z"},
{"id": 101, "html_url": "http://x/runs/101", "event": "workflow_run", "display_title": "PR S2", "head_sha": "s2", "status": "completed", "conclusion": "success", "created_at": "2026-07-19T11:00:00Z"},
{"id": 102, "html_url": "http://x/runs/102", "event": "workflow_run", "display_title": "PR S3", "head_sha": "s3", "status": "completed", "conclusion": "success", "created_at": "2026-07-19T12:00:00Z"},
{"id": 103, "html_url": "http://x/runs/103", "event": "workflow_run", "display_title": "PR S4", "head_sha": "s4", "status": "completed", "conclusion": "success", "created_at": "2026-07-19T13:00:00Z"}
],
"intake-triage.yml": [
{"id": 110, "html_url": "http://x/runs/110", "event": "issues", "display_title": "Issue S", "head_sha": "t1", "status": "completed", "conclusion": "success", "created_at": "2026-07-19T10:00:00Z"},
{"id": 111, "html_url": "http://x/runs/111", "event": "issues", "display_title": "Issue T", "head_sha": "t2", "status": "completed", "conclusion": "success", "created_at": "2026-07-19T11:00:00Z"}
],
"pr-review-hosted.yml": [
{"id": 120, "html_url": "http://x/runs/120", "event": "pull_request", "display_title": "PR R", "head_sha": "r1", "status": "completed", "conclusion": "success", "created_at": "2026-07-19T10:00:00Z"},
{"id": 121, "html_url": "http://x/runs/121", "event": "pull_request", "display_title": "PR R2", "head_sha": "r2", "status": "completed", "conclusion": "success", "created_at": "2026-07-19T11:00:00Z"},
{"id": 122, "html_url": "http://x/runs/122", "event": "pull_request", "display_title": "PR R3", "head_sha": "r3", "status": "completed", "conclusion": "success", "created_at": "2026-07-19T12:00:00Z"}
],
"pr-unblock.yml": [
{"id": 130, "html_url": "http://x/runs/130", "event": "workflow_dispatch", "display_title": "Fix #9", "head_sha": "u1", "status": "completed", "conclusion": "success", "created_at": "2026-07-19T10:00:00Z"}
]
}
EOF
cat >"$TMP/spend-annotations.json" <<'EOF'
{
"100": "pr-verify completed: credential=AUTOMATIONS_CLAUDE_API_KEY turns=5. lane-outcome {\"v\":1,\"lane\":\"pr-verify\",\"outcome\":\"success\",\"credential\":{\"secret\":\"AUTOMATIONS_CLAUDE_API_KEY\",\"kind\":\"api-key\",\"role\":\"AUTOMATIONS\"},\"turns\":5,\"costUsd\":1}",
"101": "pr-verify completed: credential=AUTOMATIONS_CLAUDE_API_KEY turns=5. lane-outcome {\"v\":1,\"lane\":\"pr-verify\",\"outcome\":\"success\",\"credential\":{\"secret\":\"AUTOMATIONS_CLAUDE_API_KEY\",\"kind\":\"api-key\",\"role\":\"AUTOMATIONS\"},\"turns\":5,\"costUsd\":3}",
"102": "pr-verify exited with: failure class=credit-stop credential=AUTOMATIONS_CLAUDE_API_KEY. lane-outcome {\"v\":1,\"lane\":\"pr-verify\",\"outcome\":\"failure\",\"class\":\"credit-stop\",\"credential\":{\"secret\":\"AUTOMATIONS_CLAUDE_API_KEY\",\"kind\":\"api-key\",\"role\":\"AUTOMATIONS\"},\"handoff\":true,\"costUsd\":4}\npr-verify completed: credential=AUTOMATIONS_CLAUDE_CODE_OAUTH_TOKEN fallback=credit-stop turns=4. lane-outcome {\"v\":1,\"lane\":\"pr-verify\",\"outcome\":\"success\",\"credential\":{\"secret\":\"AUTOMATIONS_CLAUDE_CODE_OAUTH_TOKEN\",\"kind\":\"oauth-token\",\"role\":\"AUTOMATIONS\"},\"fallback\":{\"reason\":\"credit-stop\"},\"turns\":4,\"costUsd\":9}",
"110": "Claude intake triage completed: credential=AUTOMATIONS_CLAUDE_API_KEY turns=3. lane-outcome {\"v\":1,\"lane\":\"intake-triage\",\"outcome\":\"success\",\"credential\":{\"secret\":\"AUTOMATIONS_CLAUDE_API_KEY\",\"kind\":\"api-key\",\"role\":\"AUTOMATIONS\"},\"turns\":3,\"costUsd\":2}",
"120": "pr-review completed: credential=REVIEWS_CLAUDE_API_KEY turns=7. lane-outcome {\"v\":1,\"lane\":\"pr-review\",\"outcome\":\"success\",\"credential\":{\"secret\":\"REVIEWS_CLAUDE_API_KEY\",\"kind\":\"api-key\",\"role\":\"REVIEWS\"},\"turns\":7}",
"121": "pr-review completed. lane-outcome {\"v\":1,\"lane\":\"pr-review\",\"outcome\":\"success\",\"credential\":{\"secret\":\"EVEN_CLAUDE_API_KEY\",\"kind\":\"api-key\",\"role\":\"EVEN\"},\"costUsd\":1}\nother leg. lane-outcome {\"v\":1,\"lane\":\"pr-review\",\"outcome\":\"success\",\"credential\":{\"secret\":\"bad_CLAUDE_API_KEY\",\"kind\":\"api-key\",\"role\":\"bad\"},\"costUsd\":1}\nother leg. lane-outcome {\"v\":1,\"lane\":\"pr-review\",\"outcome\":\"success\",\"credential\":{\"secret\":\"HUGE_CLAUDE_API_KEY\",\"kind\":\"api-key\",\"role\":\"HUGE\"},\"costUsd\":1e17}",
"122": "pr-review completed. lane-outcome {\"v\":1,\"lane\":\"pr-review\",\"outcome\":\"success\",\"credential\":{\"secret\":\"EVEN_CLAUDE_API_KEY\",\"kind\":\"api-key\",\"role\":\"EVEN\"},\"costUsd\":4}\nother leg. lane-outcome {\"v\":1,\"lane\":\"pr-review\",\"outcome\":\"success\",\"credential\":{\"secret\":\"EVEN_CLAUDE_API_KEY\",\"kind\":\"api-key\",\"role\":\"EVEN\"},\"class\":\"credit-stop\",\"costUsd\":100}\nother leg. lane-outcome {\"v\":1,\"lane\":\"pr-review\",\"outcome\":\"success\",\"credential\":{\"secret\":\"EVEN_CLAUDE_API_KEY\",\"kind\":\"api-key\",\"role\":\"EVEN\"},\"costUsd\":-1}\nother leg. lane-outcome {\"v\":1,\"lane\":\"pr-review\",\"outcome\":\"success\",\"credential\":{\"secret\":\"EVEN_CLAUDE_API_KEY\",\"kind\":\"api-key\",\"role\":\"EVEN\"},\"costUsd\":\"2\"}",
"130": "pr-unblock completed: credential=PR_UNBLOCK_CLAUDE_CODE_OAUTH_TOKEN fallback=no-key turns=6. lane-outcome {\"v\":1,\"lane\":\"fix-ci\",\"outcome\":\"success\",\"credential\":{\"secret\":\"PR_UNBLOCK_CLAUDE_CODE_OAUTH_TOKEN\",\"kind\":\"oauth-token\",\"role\":\"PR_UNBLOCK\"},\"fallback\":{\"reason\":\"no-key\"},\"turns\":6,\"costUsd\":5}\nactivity=fix-ci"
}
EOF
SPEND="$(section "$(bash "$BRIEF" --now "$NOW" --counts-json "$TMP/counts.json" --pr-json "$TMP/pr.json" \
--decisions-json "$TMP/decisions.json" --telemetry-json "$TMP/telemetry.json" --merged-json "$TMP/merged-clean.json" \
--lane-runs-json "$TMP/spend-runs.json" --lane-annotations-json "$TMP/spend-annotations.json" "${CLEAR_COST_ARGS[@]}" 2>&1)" "== Lanes")"
assert_contains "spend: the median successful key leg, scaled by the role's lane runs per day, labeled a list-price estimate" "$SPEND" \
" SPEND: AUTOMATIONS ~\$1.71/day (list price, n=4) — estimate: median \$2.00 per successful key leg × 6 runs over 7d; \$10.00 summed over the legs read"
assert_eq "spend: one line per role prefix, across lanes and secrets" "1" "$(grep -c "^ SPEND: AUTOMATIONS " <<<"$SPEND")"
assert_not_contains "spend: never grouped by lane id" "$SPEND" "SPEND: pr-verify"
assert_contains "spend: a key leg with no costUsd says so" "$SPEND" " SPEND: REVIEWS cost not recorded (n=1)"
assert_not_contains "spend: a role with only token legs prints no spend line" "$SPEND" "SPEND: PR_UNBLOCK"
assert_contains "spend: an even count takes the mean of the middle two; a successful credit-stop leg and a negative or string cost are left out" "$SPEND" \
" SPEND: EVEN ~\$1.07/day (list price, n=5) — estimate: median \$2.50 per successful key leg × 3 runs over 7d; \$105.00 summed over the legs read"
assert_contains "spend: a cost past the bound is not a cost" "$SPEND" " SPEND: HUGE cost not recorded (n=1)"
assert_not_contains "spend: a role outside the role pattern prints nothing" "$SPEND" "SPEND: bad"
assert_not_contains "spend: the section stays readable" "$SPEND" "UNREADABLE"
assert_contains "spend: legs without costUsd elsewhere print cost not recorded" "$KEYS" " SPEND: INTAKE cost not recorded (n=1)"

# --- Lanes: model usage by activity and profile ---------------------------------
# pr-unblock runs 30-36: resolve-conflicts with no profile= runs 30, 31, 34 and
# 36 (two pass, two max-turns failures, turns 8, 40, 40, 10, so the median is
Expand Down
Loading
Loading