Skip to content

relayburn-sdk: implement five sync query verbs#301

Merged
willwashburn merged 1 commit intomainfrom
claude/sdk-query-verbs
May 5, 2026
Merged

relayburn-sdk: implement five sync query verbs#301
willwashburn merged 1 commit intomainfrom
claude/sdk-query-verbs

Conversation

@willwashburn
Copy link
Copy Markdown
Member

Summary

Fill in crates/relayburn-sdk/src/query_verbs.rs with the five sync query verbs:
summary, session_cost, overhead, overhead_trim, hotspots. Each is callable both as a LedgerHandle method and as a free function (which opens its own ledger from LedgerOpenOptions).

The verbs are thin wrappers over relayburn-analyze + relayburn-ledger. Behavior mirrors the TS sibling in packages/sdk/index.js. since accepts both ISO timestamps and CLI-style relative ranges (24h, 7d, 4w, 2m); a small proleptic-Gregorian helper avoids pulling in chrono/time.

hotspots returns a discriminated union (HotspotsResult) covering attribution + the four narrow group-by axes + the findings shape. ghost-surface pattern is intentionally deferred — the TS sibling drives an async filesystem-mining pipeline that's outside the ledger surface and would balloon this PR.

Part of #246.

Test plan

  • `cargo test -p relayburn-sdk` — 16 passed
  • `cargo test --workspace` green
  • `cargo doc --no-deps -p relayburn-sdk` clean

Stacking

Stacked on #300 (module stubs) — base is `claude/sdk-module-stubs` and will rebase to `main` once that lands.

🤖 Generated with Claude Code

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 5, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

The module-level documentation in query_verbs.rs is updated from a hotspots-focused header to a generalized "Query verbs" description, imports are expanded to include standard library utilities and external dependencies (relayburn_analyze, relayburn_ledger, relayburn_reader), and section headers are added for organizational clarity. No public API changes or runtime behavior modifications.

Changes

Module Documentation & Organization

Layer / File(s) Summary
Documentation & Headers
crates/relayburn-sdk/src/query_verbs.rs
Module header changed from hotspots-focused to generalized "Query verbs" with expanded preface describing layout and exports. Section headers added for "since-string parsing" and related concerns.
Import Expansion
crates/relayburn-sdk/src/query_verbs.rs
Standard library imports (HashMap, HashSet, fs, Path, PathBuf) and external crate dependencies (relayburn_analyze, relayburn_ledger, relayburn_reader) are introduced or broadened to clarify module dependencies.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

Possibly related PRs

  • AgentWorkforce/burn#300: Introduced the initial stub for this module; this PR expands its documentation and organizes imports.

Poem

🐰 Query verbs in order bloom,
Clearing hotspots from the room,
Imports gathered, headers bright,
Organization feels just right!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 55.32% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main change: implementing five sync query verbs (summary, session_cost, overhead, overhead_trim, hotspots) in the relayburn-sdk.
Description check ✅ Passed The description provides comprehensive and relevant details about the changeset, including what was implemented, design decisions, testing performed, and PR dependencies.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/sdk-query-verbs

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 969affebb6

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +72 to +77
if !looks_like_iso(raw) {
anyhow::bail!(
"invalid since: {raw} (expected ISO timestamp or relative range like 7d)"
);
}
Ok(Some(raw.to_string()))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Canonicalize since timestamps before storing in query

normalize_since accepts any string with a YYYY-MM-DD prefix and returns it unchanged, but ledger filtering is a lexical string comparison on turn.ts. This means valid inputs that are not in canonical ledger format (for example 2026-04-01T00:00:00Z without milliseconds, or timestamps with timezone offsets) can be ordered incorrectly and silently include/exclude the wrong turns near the boundary. The TS SDK normalizes parsed timestamps to UTC ISO (toISOString()), so this Rust path should parse and re-emit canonical ISO (or reject invalid dates) instead of passing raw input through.

Useful? React with 👍 / 👎.

Base automatically changed from claude/sdk-module-stubs to main May 5, 2026 21:38
@willwashburn willwashburn deleted the branch main May 5, 2026 21:38
@willwashburn willwashburn reopened this May 5, 2026
Fill in `query_verbs.rs` with the embedding-API surface for `summary`,
`session_cost`, `overhead`, `overhead_trim`, and `hotspots`. Each verb
appears in two forms:

- `impl LedgerHandle { fn <verb>(&self, opts) -> Result<…> }` for
  callers that already hold a handle (the common embedding path).
- A free function that opens its own `LedgerHandle` from
  `LedgerOpenOptions::with_home(opts.ledger_home)`, mirroring the TS
  `withHome(opts.ledgerHome, …)` wrapper without mutating process env.

Result types derive `Serialize` + `#[serde(rename_all = "camelCase")]`
so the JSON shape matches `@relayburn/sdk` byte-for-byte; the discriminated
`HotspotsResult` uses `#[serde(tag = "kind")]` to mirror the TS union.

`normalize_since` accepts both ISO timestamps and the relative ranges
(`24h`, `7d`, `4w`, `2m`) the CLI/SDK take, formatting via a hand-rolled
proleptic-Gregorian helper to avoid pulling in chrono. The hotspots
findings path runs the core `detect_patterns` pipeline plus the
side-channel `tool-output-bloat` and `tool-call-pattern` detectors;
`ghost-surface` is deferred (its TS sibling drives a filesystem-mining
pipeline that goes beyond the ledger surface).

Unit tests inside `query_verbs.rs` build a fixture ledger via
`tempfile::TempDir`, append a couple of synthetic `TurnRecord`s, and
assert each verb's wrapper plumbs through with structurally non-empty
results — coverage of the JS sibling's behavioral parity is left for
the integration test in PR5.

Part of #246.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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