Skip to content

feat: persist structured usage telemetry - #2063

Merged
bradygaster merged 3 commits into
github:devfrom
anshi2018:anshi2018/1716-usage-ledger
Oct 2, 2026
Merged

bradygaster merged 3 commits into
github:devfrom
anshi2018:anshi2018/1716-usage-ledger

Conversation

@anshi2018

Copy link
Copy Markdown
Contributor

What

Persist structured runtime usage telemetry in a versioned JSONL ledger and make squad cost prefer that ledger over regex parsing of agent-authored Markdown.

Why

The existing cost report derives spend from unstructured Markdown, so it cannot reliably measure coverage or correlate runtime attempts with completed usage. This change provides a trustworthy data source for evaluating model-routing efficiency.

Closes #1716

How

  • Add .squad/log/usage.jsonl persistence with versioned attempt and completed-usage records.
  • Correlate records by turn ID and capture session, agent, backend, model, tokens, and estimated cost.
  • Record telemetry for direct-agent and coordinator dispatch paths.
  • Prefer structured telemetry in squad cost, with clearly labelled Markdown fallback.
  • Report coverage, support filters, and surface malformed records.
  • Add SDK and CLI tests plus a package changeset.

Validation

  • npm run build -w @bradygaster/squad-sdk
  • npm run build -w @bradygaster/squad-cli
  • npm run lint
  • npx vitest run test/usage-ledger.test.ts test/cli/cost.test.ts — 15 passed

Quick Check

  • SDK/CLI source changes include .changeset/1716-structured-usage-ledger.md

PR Readiness Checklist

Branch & Commit

  • Branch created from and rebased onto dev
  • Verified diff contains only intended changes
  • PR is not in draft mode
  • Commit history is clean

Build & Test

  • SDK and CLI builds pass
  • Focused tests pass
  • npm run lint passes
  • npm run lint:eslint passes

Changeset

  • Changeset added

Breaking Changes

None.

Waivers

None.

Add a backend-aware JSONL ledger for turn attempts and runtime usage, then make squad cost report structured totals and telemetry coverage before using the legacy Markdown fallback.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: c8ae7013-1eb9-4f99-8762-ea407e3633f3
@github-actions

github-actions Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

🛫 PR Readiness Check

ℹ️ This comment updates on each push. Last checked: commit 2eb6d6a

PR Scope: 📦🔧 Mixed (product + infrastructure)

⚠️ 3 item(s) to address before review

Status Check Details
❌ Single commit 3 commits — consider squashing before review
✅ Not in draft Ready for review
✅ Branch up to date Up to date with dev
❌ Copilot review No Copilot review yet — it may still be processing
✅ Changeset present Changeset file found
✅ Scope clean No .squad/ or docs/proposals/ files
✅ No merge conflicts No merge conflicts
✅ Copilot threads resolved No Copilot review threads
❌ CI passing 10 check(s) still running

Files Changed (8 files, +777 −61)

File +/−
.changeset/1716-structured-usage-ledger.md +6 −0
packages/squad-cli/src/cli/commands/cost.ts +189 −53
packages/squad-cli/src/cli/shell/index.ts +45 −3
packages/squad-sdk/src/index.ts +1 −0
packages/squad-sdk/src/runtime/streaming.ts +2 −0
packages/squad-sdk/src/runtime/usage-ledger.ts +176 −0
test/cli/cost.test.ts +229 −5
test/usage-ledger.test.ts +129 −0

Total: +777 −61


This check runs automatically on every push. Fix any ❌ items and push again.
See CONTRIBUTING.md and PR Requirements for details.

@github-actions

github-actions Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

🏗️ Architectural Review

Authoritative evidence: base-controlled pull_request_target reporter.

⚠️ Architectural review: 1 warning(s).

Severity Category Finding Files
🟡 warning export-surface Package entry point(s) modified with 10 new/changed export(s). New public API surface requires careful review for backward compatibility. packages/squad-sdk/src/index.ts

Automated architectural review — informational only.

@github-actions

Copy link
Copy Markdown
Contributor

🟡 Impact Analysis — PR #2063

Risk tier: 🟡 MEDIUM

📊 Summary

Metric Count
Files changed 8
Files added 3
Files modified 5
Files deleted 0
Modules touched 4
Critical files 2

🎯 Risk Factors

  • 8 files changed (6-20 → MEDIUM)
  • 4 modules touched (2-4 → MEDIUM)
  • Critical files touched: packages/squad-cli/src/cli/shell/index.ts, packages/squad-sdk/src/index.ts

📦 Modules Affected

root (1 file)
  • .changeset/1716-structured-usage-ledger.md
squad-cli (2 files)
  • packages/squad-cli/src/cli/commands/cost.ts
  • packages/squad-cli/src/cli/shell/index.ts
squad-sdk (3 files)
  • packages/squad-sdk/src/index.ts
  • packages/squad-sdk/src/runtime/streaming.ts
  • packages/squad-sdk/src/runtime/usage-ledger.ts
tests (2 files)
  • test/cli/cost.test.ts
  • test/usage-ledger.test.ts

⚠️ Critical Files

  • packages/squad-cli/src/cli/shell/index.ts
  • packages/squad-sdk/src/index.ts

This report is generated automatically for every PR. See #733 for details.

@anshi2018
anshi2018 marked this pull request as ready for review September 24, 2026 19:12
@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

👋 Friendly nudge — this PR has had no activity for 7 days.

What needs attention:

  • 👀 No approving reviews yet. Request a review from a teammate.
  • ⬇️ 145 commits behind dev. Rebase to pick up latest changes.

If this PR is abandoned, please close it. If it's blocked on something external, leave a comment so the team knows.
This is an automated check that runs on weekdays. It won't nudge the same PR more than once per week.

bradygaster and others added 2 commits October 2, 2026 16:06
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@bradygaster
bradygaster merged commit b4e7595 into github:dev Oct 2, 2026
17 checks passed
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.

squad cost derives spend by regex over agent-authored markdown instead of the UsageEvent telemetry the runtime already emits

2 participants