Skip to content

build: update gunshi to 0.31#1040

Merged
ryoppippi merged 7 commits into
mainfrom
codex/update-gunshi-0-31
May 17, 2026
Merged

build: update gunshi to 0.31#1040
ryoppippi merged 7 commits into
mainfrom
codex/update-gunshi-0-31

Conversation

@ryoppippi
Copy link
Copy Markdown
Owner

@ryoppippi ryoppippi commented May 17, 2026

Summary

  • update gunshi and @gunshi/docs catalog entries to 0.31.0
  • adapt command typing to GunshiParams-based Command generics
  • use Gunshi nested subCommands for agent report namespaces and keep config schema generation aligned with nested commands

Version check

  • current locked gunshi: 0.26.3
  • current locked @gunshi/docs: 0.27.6
  • latest npm dist-tag for both packages: 0.31.0
  • notable upstream changes checked: v0.27 plugin system and @gunshi/docs, v0.28 nested sub-commands, v0.29 experimental parser combinators, v0.30 Node.js >=22 requirement, v0.31 lazy command argument parsing fix and gunshi/agent entry point

Validation

  • pnpm run format
  • pnpm typecheck
  • pnpm run test

Summary by cubic

Upgraded gunshi and @gunshi/docs to 0.31.0, moved agent reports to nested subCommands with a daily default, and kept legacy agent:report aliases working. This also simplifies command typing via inference and keeps config schema generation aligned.

  • Bug Fixes

    • Normalize legacy agent:report invocations to nested commands (e.g., codex:monthly -> codex monthly) to avoid a CLI compatibility break.
  • Refactors

    • Switched agent reports to nested subCommands; removed argument rewriting and replaced it with a small pre-dispatch normalizer only for legacy colon aliases.
    • Let command factories infer return types and removed the GunshiCommand alias; the config wrapper uses define(...) with a local cast at the boundary.
    • Updated JSON schema generation to walk nested agent subCommands (Map/Object) and emit per-agent report schemas.
    • Switched ESLint preset to app and refreshed local TypeScript guidance.

Written for commit efc1cf2. Summary will update on new commits. Review in cubic

Summary by CodeRabbit

  • New Features

    • CLI now exposes nested agent subcommands (e.g., ccusage codex daily) instead of flat agent:report names.
  • Behavior Changes

    • Legacy colon-style invocations (e.g., codex:monthly) are accepted and normalized to the new nested form.
  • Documentation

    • Updated guidance on type inference and command factory patterns.
  • Tests

    • CLI integration tests adjusted to use the new nested invocation style.
  • Dependencies

    • Bumped gunshi-related packages to v0.31.0.

Review Change Stack

Update gunshi and @gunshi/docs to 0.31.0 so ccusage uses the latest CLI API and bundled Gunshi docs.

Adapt command typings to GunshiParams-based Command generics introduced after 0.27, and use Gunshi nested subCommands for agent report namespaces instead of rewriting agent/report arguments to flat internal command keys.

Gunshi 0.31 requires Node.js >=22; ccusage already requires Node >=22.11.0, so this stays within the package engine range.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 17, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Refactors the ccusage CLI from flat agent:report tuples to agent-root commands with nested report subCommands; upgrades Gunshi ranges to 0.31.0; simplifies command factory typings to rely on define() inference or GunshiCommand; updates JSON schema generation to iterate nested subcommands and adds legacy colon-form arg normalization.

Changes

Gunshi CLI Refactor to Nested Subcommands

Layer / File(s) Summary
Gunshi library and docs upgrade to 0.31.0
pnpm-workspace.yaml
Workspace catalog dependency ranges for @gunshi/docs and gunshi bumped to ^0.31.0.
Command factory type refinement
apps/ccusage/src/commands/agent.ts, apps/ccusage/src/commands/all.ts, apps/ccusage/src/commands/codex.ts, .agents/skills/typescript-style/references/gunshi.md
Removed explicit Command type imports and annotations; some factories now use GunshiCommand<...> or let return types be inferred from define(); updated style guidance to prefer inference.
CLI architecture refactor: flat → nested subcommands
apps/ccusage/src/commands/index.ts, apps/ccusage/test/cli-output.test.ts
Introduced withSubCommands and adjusted withCcusageConfig to preserve nested subCommands; built per-agent Maps for reports; rewrote subCommandUnion to expose agent-root commands; added normalizeLegacyAgentCommandArgs and wired it into run(); updated tests to match new arg forms.
JSON schema generation for nested subcommands
apps/ccusage/scripts/generate-json-schema.ts
Added SchemaCommand to model optional args/subCommands, getSubCommandEntries to normalize subCommands, and updated createConfigSchemaJson to special-case agent commands and iterate nested subcommands to emit per-agent/per-report schemas.

Sequence Diagram

sequenceDiagram
  participant CLI as CLI Invocation
  participant Agent as Agent Root Command
  participant Report as Report Subcommand
  participant Config as withCcusageConfig
  participant Run as Command run()

  CLI->>Agent: invoke agent (e.g., codex)
  Agent->>Report: dispatch to report subcommand (e.g., daily)
  Report->>Config: execute wrapped command
  Config->>Config: load config and merge CLI args
  Config->>Run: invoke report.run() with merged values
  Run->>Run: execute report logic
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~40 minutes

Possibly related PRs

  • ryoppippi/ccusage#1000: Overlaps on agent-first namespaces and agent/report command wiring via subCommandUnion.
  • ryoppippi/ccusage#1008: Related changes to generate-json-schema.ts for agent-namespaced command/schema emission.

Poem

🐰 I hopped through code to nest each command,
Agents first, reports tucked safe in hand.
Types now infer where annotations fell,
Schemas learned the nested tale to tell.
A tiny hop — the CLI sings well.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.76% 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 'build: update gunshi to 0.31' accurately and concisely describes the primary change—upgrading the gunshi dependency to version 0.31.0 across the codebase.
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ 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 codex/update-gunshi-0-31

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@socket-security
Copy link
Copy Markdown

socket-security Bot commented May 17, 2026

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​gunshi/​docs@​0.31.0711008495100
Addedgunshi@​0.31.08410010096100

View full report

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented May 17, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
ccusage-guide efc1cf2 Commit Preview URL

Branch Preview URL
May 17 2026, 07:11 PM

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 17, 2026

Open in StackBlitz

npx https://pkg.pr.new/ryoppippi/ccusage@1040

commit: efc1cf2

@ryoppippi ryoppippi marked this pull request as ready for review May 17, 2026 18:34
@ryoppippi ryoppippi changed the title [codex] update gunshi to 0.31 build: update gunshi to 0.31 May 17, 2026
@ryoppippi
Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 17, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 17, 2026

ccusage performance comparison

This compares the PR build against the base branch build on the same CI runner.

Committed fixture performance

Committed small fixtures for stable PR-to-PR feedback and explicit Claude/Codex command coverage.

Fixtures: Claude apps/ccusage/test/fixtures/claude (0.00 MiB, 2 files), Codex apps/ccusage/test/fixtures/codex (0.00 MiB, 1 files)
Runtime: package ccusage bin from apps/ccusage/package.json through bun -b, --offline --json, measured by hyperfine with 2 warmups and 7 runs.

Command Input Base median PR median PR vs base Base throughput PR throughput
claude daily --offline --json 0.00 MiB 57.2ms 58.7ms 0.97x 0.03 MiB/s 0.03 MiB/s
claude session --offline --json 0.00 MiB 56.5ms 58.8ms 0.96x 0.03 MiB/s 0.03 MiB/s
codex daily --offline --json 0.00 MiB 57.9ms 58.0ms 1.00x 0.01 MiB/s 0.01 MiB/s
codex session --offline --json 0.00 MiB 57.4ms 58.7ms 0.98x 0.01 MiB/s 0.01 MiB/s

Large real-world-shaped fixture performance

Generated fixtures shaped from aggregate local log statistics: thousands of JSONL files, many small sessions, and a long tail of larger sessions. No real prompts, paths, or outputs are stored in the fixtures.

Fixtures: Claude /home/runner/work/_temp/ccusage-large-fixture (1.01 GiB, 2,597 files), Codex /home/runner/work/_temp/ccusage-large-codex-fixture (1.01 GiB, 2,597 files)
Runtime: package ccusage bin from apps/ccusage/package.json through bun -b, --offline --json, measured by hyperfine with 0 warmups and 1 runs.

Command Input Base median PR median PR vs base Base throughput PR throughput
claude --offline --json 1.01 GiB 1.475s 1.470s 1.00x 699.04 MiB/s 701.14 MiB/s
codex --offline --json 1.01 GiB 1.856s 1.949s 0.95x 555.44 MiB/s 528.98 MiB/s

Package size

Package artifact Base PR Delta Ratio
packed ccusage-*.tgz 68.13 KiB 70.43 KiB +2.31 KiB 0.97x

Lower medians and smaller packed package sizes are better. CI runner noise still applies; use same-run ratios as directional PR feedback, not release guarantees.

Switch the ccusage package ESLint preset to app mode now that the package is used as the bundled CLI rather than a library surface.

This lets direct define() command factories keep Gunshi inferred command types instead of carrying redundant explicit GunshiCommand return annotations. Keep the explicit GunshiCommand helper only at the config wrapper boundary where the wrapper adds a config argument and forwards a merged context to another command runner.

Also update the repo-local Gunshi TypeScript guidance so future command factories do not reintroduce unnecessary return annotations.
@ryoppippi
Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 17, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/ccusage/src/commands/index.ts`:
- Around line 160-192: Top-level agent entries (codex/opencode/amp/pi) are wired
to the daily leaf runners (codexDailyCommand, opencodeDailyCommand,
ampDailyCommand, piDailyCommand) so invoking e.g. "ccusage codex" immediately
runs the report; change this by either replacing those bindings with a dedicated
parent command that only declares subcommands (no run handler) or by adding an
omitted-guard in the existing handlers: inside withCcusageConfig or inside each
of codexDailyCommand/opencodeDailyCommand/ampDailyCommand/piDailyCommand check
ctx.omitted (or equivalent) and only delegate to the daily runner when a
subcommand was provided, otherwise return/print help; update references where
withCommandName(withSubCommands(...), 'codex'|'opencode'|'amp'|'pi') is created
so the parent no longer unconditionally executes the daily run.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e4aa7490-131f-4b38-a980-5924ec04255d

📥 Commits

Reviewing files that changed from the base of the PR and between 2533c23 and f68e1ae.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (6)
  • apps/ccusage/scripts/generate-json-schema.ts
  • apps/ccusage/src/commands/agent.ts
  • apps/ccusage/src/commands/all.ts
  • apps/ccusage/src/commands/codex.ts
  • apps/ccusage/src/commands/index.ts
  • pnpm-workspace.yaml

Comment thread apps/ccusage/src/commands/index.ts
Remove the reusable GunshiCommand alias and direct SubCommandable imports from the nested command wiring and schema generator.

The config wrapper now keeps inference through define() and uses only a local replay cast at the runner adapter boundary. The TypeScript skill now records the rule as guidance instead of teaching agents to copy a concrete Command helper type.
@ryoppippi
Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 17, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Exercise ccusage codex without an explicit report so the CLI test suite documents that agent namespaces keep the existing daily default while using Gunshi nested subcommands.
@ryoppippi
Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 17, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

# Conflicts:
#	pnpm-lock.yaml
#	pnpm-workspace.yaml
@ryoppippi
Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 17, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Keep the pre-nested agent:report command names working by normalizing them to the new Gunshi nested command path before validation and dispatch.

This avoids a CLI compatibility regression for users who invoked the old flat subcommand names directly while retaining the documented ccusage <agent> <report> interface.
@ryoppippi
Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 17, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Use typos accepted wording in the compatibility comment added for legacy agent command aliases.
@ryoppippi
Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 17, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@ryoppippi ryoppippi merged commit a291981 into main May 17, 2026
23 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.

1 participant