GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(usage): read Cursor and Grok plan quota from their TUIs by juliusmarminge · Pull Request #9532 · pingdotgg/t3code

Conversation

@juliusmarminge

@juliusmarminge juliusmarminge commented Sep 4, 2026 •
edited by macroscopeapp Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Reference port of the Cursor and Grok usage probes from #1732 onto the model that landed in #9507. Kept as a draft: the data source is the interactive /usage TUI driven in a PTY, which is fragile by nature (copy changes in either CLI break the parse) and adds a 10–25s PTY session to every status check. It lives here so the work is preserved against main and can land the day either CLI exposes quota over ACP or a JSON command — at which point the parser swaps and the wiring stays.

What changed

  • cursorUsageProbe.ts, grokTuiUsageProbe.ts, ptyProbeSupport.ts and their tests, from feat: display provider usage limits in settings #1732, retargeted onto ServerProviderUsageLimits: stable window ids (monthly_1_auto / monthly_2_api, weekly), typed unavailable.reason, no source enum.
  • CursorProvider and GrokProvider call the probe from their own checkProvider and return usageLimits on the snapshot — the one-driver-change shape feat(usage): show Codex and Claude subscription limits on a Limits tab #9507 was built for. A Grok API-key session reports unsupported.
  • PtyAdapter is threaded into both drivers as an optional service; without it the probe reports limits unavailable rather than failing the provider.

Nothing central changes. OpenCode, the Claude PTY probe, and the terminal-adapter changes from #1732 are not carried (superseded, replaced by the SDK read, and out of scope respectively).

Verification

  • 73 tests across the two probe suites and the Cursor/Grok provider suites, typecheck clean with the repo's Effect diagnostics.
  • Not exercised against real CLIs on this pass; feat: display provider usage limits in settings #1732's fixtures were captured from real output at the time.

Authored by @Aditya190803 in #1732; ported by Claude Fable 5 via Claude Code.

Note

Add PTY-backed usage probes for Cursor and Grok providers

  • Adds PTY-backed usage probes to parse monthly plan limits from the Cursor TUI and weekly limits from the Grok TUI.
  • Introduces shared utilities in ptyProbeSupport.ts for ANSI stripping, Windows command resolution, bounded retries, and process cleanup.
  • Driver status checks in CursorDriver.ts and GrokDriver.ts pass the server working directory and optional PtyAdapter to the new probes.
  • Risk: Status checks spawn external processes via probeCursorUsageLimits and probeGrokUsageLimits; if PTY output hangs past the configured timeout or cleanup logic fails, it could leave orphaned child processes.

Macroscope summarized e37dd9d.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Aditya190803 @juliusmarminge @claude
feat(usage): read Cursor and Grok plan quota from their TUIs
e37dd9d
Neither CLI exposes plan quota over ACP or a JSON command; the only place
it appears is the interactive `/usage` panel. These probes drive that panel
in a PTY during the status check — waiting for the composer, sending
`/usage`, retrying on a dropped keystroke — and parse the percentages and
reset date out of the ANSI stream. Cursor reports Auto and API as monthly
windows, Grok a single weekly one.

Ported from #1732 onto the landed usage-limit model: each driver returns
`usageLimits` from its own `checkProvider`, the PTY adapter is threaded
in as an optional service, and the probe output maps onto
`ServerProviderUsageWindow` with stable ids. The PTY support module and
its Windows `.cmd` shim handling come across unchanged.

Co-authored-by: Julius Marminge <[email protected]>
Co-Authored-By: Claude Code <[email protected]>
@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:XL 500-999 changed lines (additions + deletions). labels Sep 4, 2026
@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Thread transfer impact

✅ Thread transfer remains within every enforced ceiling.

Provider Metric Main baseline This PR Impact PR ceiling
Codex Total thread wire 13.5 KiB 13.7 KiB +223 B (+1.6%) 15.1 KiB ✅
Codex Thread snapshot wire 7.0 KiB 7.0 KiB −8 B (−0.1%) 7.3 KiB ✅
Codex Live turn WebSocket wire 6.5 KiB 6.7 KiB +231 B (+3.5%) 7.8 KiB ✅
Codex Live turn WebSocket decoded 57.0 KiB 58.5 KiB +1.5 KiB (+2.6%) 66.4 KiB ✅
Codex Live turn messages 8 10 +2 (+25.0%) 21 ✅
Claude Total thread wire 13.6 KiB 13.7 KiB +135 B (+1.0%) 15.1 KiB ✅
Claude Thread snapshot wire 7.0 KiB 7.0 KiB −1 B (−0.0%) 7.3 KiB ✅
Claude Live turn WebSocket wire 6.6 KiB 6.7 KiB +136 B (+2.0%) 7.8 KiB ✅
Claude Live turn WebSocket decoded 57.9 KiB 59.3 KiB +1.4 KiB (+2.5%) 66.4 KiB ✅
Claude Live turn messages 10 10 0 (0.0%) 21 ✅

Baseline: 343db2c · PR result: e37dd9d · Source CI: success

Scenario and decoded snapshot size

10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

  • Codex decoded thread snapshot: 113.8 KiB
  • Claude decoded thread snapshot: 114.5 KiB

Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

macroscopeapp[bot]
macroscopeapp Bot reviewed Sep 4, 2026
View reviewed changes

@macroscopeapp macroscopeapp Bot left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The four inline findings share one root cause outside this diff: PtyAdapterLive is only Layer.provided into TerminalManager.layer in apps/server/src/server.ts, so it never reaches the layer that runs driver.create. Completing the fix means merging that adapter into the driver-side layer graph (or providing it there) once the requirement is visible in the types.

Posted via Macroscope — Effect Service Conventions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread apps/server/src/provider/Drivers/CursorDriver.ts
Comment on lines +126 to +134
const ptyAdapter = Option.getOrUndefined(yield* Effect.serviceOption(PtyAdapter.PtyAdapter));
const checkProvider = checkCursorProviderStatus(effectiveConfig, processEnv, cwd).pipe(
Effect.map(stampIdentity),
Effect.provideService(Crypto.Crypto, crypto),
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
Effect.provideService(FileSystem.FileSystem, fileSystem),
Effect.provideService(Path.Path, path),
(effect) =>
ptyAdapter ? Effect.provideService(effect, PtyAdapter.PtyAdapter, ptyAdapter) : effect,

@macroscopeapp macroscopeapp Bot Sep 4, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This hand-rolls optional dependency plumbing around the layer boundary: PtyAdapter is not part of CursorDriverEnv, so the type system never requires it, and the ternary provideService is either redundant (a provided adapter is already visible to the probe's serviceOption through the inherited fiber context) or a silent no-op (nothing provides PtyAdapter to the driver layer today, so the probe always reports limits unavailable).

Consider acquiring it as a normal dependency — const ptyAdapter = yield* PtyAdapter.PtyAdapter; plus an unconditional Effect.provideService(PtyAdapter.PtyAdapter, ptyAdapter) — and adding PtyAdapter.PtyAdapter to the CursorDriverEnv union so the missing wiring becomes a type error instead of a runtime degradation.

Posted via Macroscope — Effect Service Conventions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread apps/server/src/provider/grokTuiUsageProbe.ts
Comment on lines +148 to +165
}

export function probeGrokUsageLimits(
input: GrokUsageProbeInput,
clock: ProbeClock = defaultProbeClock,
): Effect.Effect<GrokUsageProbeResult> {
return Effect.gen(function* () {
const ptyAdapter = Option.getOrUndefined(yield* Effect.serviceOption(PtyAdapter.PtyAdapter));
if (!ptyAdapter) {
return {
usageLimits: makeUnavailableUsageLimits({
checkedAt: input.checkedAt,
reason: "probeFailed",
message: "Usage limits unavailable for this Grok instance in the current runtime.",
}),
rawOutput: "",
};
}

@macroscopeapp macroscopeapp Bot Sep 4, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Same requirement erasure as in cursorUsageProbe.ts: Effect.serviceOption hides PtyAdapter from probeGrokUsageLimits's type, so the dependency is invisible to GrokDriverEnv and to the layer graph. Consider yield* PtyAdapter.PtyAdapter and letting the requirement surface in the signature.

 export function probeGrokUsageLimits(
   input: GrokUsageProbeInput,
   clock: ProbeClock = defaultProbeClock,
-): Effect.Effect<GrokUsageProbeResult> {
+): Effect.Effect<GrokUsageProbeResult, never, PtyAdapter.PtyAdapter> {
   return Effect.gen(function* () {
-    const ptyAdapter = Option.getOrUndefined(yield* Effect.serviceOption(PtyAdapter.PtyAdapter));
-    if (!ptyAdapter) {
-      return {
-        usageLimits: makeUnavailableUsageLimits({
-          checkedAt: input.checkedAt,
-          reason: "probeFailed",
-          message: "Usage limits unavailable for this Grok instance in the current runtime.",
-        }),
-        rawOutput: "",
-      };
-    }
+    const ptyAdapter = yield* PtyAdapter.PtyAdapter;

Posted via Macroscope — Effect Service Conventions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread apps/server/src/provider/Drivers/GrokDriver.ts
Comment on lines +107 to +113
const ptyAdapter = Option.getOrUndefined(yield* Effect.serviceOption(PtyAdapter.PtyAdapter));
const checkProvider = checkGrokProviderStatus(effectiveConfig, processEnv, cwd).pipe(
Effect.map(stampIdentity),
Effect.provideService(Crypto.Crypto, crypto),
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
(effect) =>
ptyAdapter ? Effect.provideService(effect, PtyAdapter.PtyAdapter, ptyAdapter) : effect,

@macroscopeapp macroscopeapp Bot Sep 4, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Same conditional-provide bypass as in CursorDriver.ts: PtyAdapter is absent from GrokDriverEnv, so the ternary silently skips providing it and the usage probe degrades to probeFailed with no compile-time signal. Consider const ptyAdapter = yield* PtyAdapter.PtyAdapter;, an unconditional Effect.provideService(...), and adding PtyAdapter.PtyAdapter to GrokDriverEnv.

Posted via Macroscope — Effect Service Conventions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread apps/server/src/provider/cursorUsageProbe.ts
Comment on lines +279 to +291
): Effect.Effect<CursorUsageProbeResult> {
return Effect.gen(function* () {
const ptyAdapter = Option.getOrUndefined(yield* Effect.serviceOption(PtyAdapter.PtyAdapter));
if (!ptyAdapter) {
return {
usageLimits: makeUnavailableUsageLimits({
checkedAt: input.checkedAt,
reason: "probeFailed",
message: "Usage limits are unavailable in this runtime.",
}),
rawOutput: "",
};
}

@macroscopeapp macroscopeapp Bot Sep 4, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Effect.serviceOption erases the PtyAdapter dependency from the returned type (Effect.Effect<CursorUsageProbeResult>), so no layer is ever forced to supply it and the missing-service case degrades silently instead of being caught at composition time. Consider acquiring it with yield* PtyAdapter.PtyAdapter so the requirement shows up in the signature and propagates into CursorDriverEnv; if graceful degradation is still wanted, express it as an explicit optional-service layer rather than an in-function fallback.

 export function probeCursorUsageLimits(
   input: CursorUsageProbeInput,
   clock: ProbeClock = defaultProbeClock,
-): Effect.Effect<CursorUsageProbeResult> {
+): Effect.Effect<CursorUsageProbeResult, never, PtyAdapter.PtyAdapter> {
   return Effect.gen(function* () {
-    const ptyAdapter = Option.getOrUndefined(yield* Effect.serviceOption(PtyAdapter.PtyAdapter));
-    if (!ptyAdapter) {
-      return {
-        usageLimits: makeUnavailableUsageLimits({
-          checkedAt: input.checkedAt,
-          reason: "probeFailed",
-          message: "Usage limits are unavailable in this runtime.",
-        }),
-        rawOutput: "",
-      };
-    }
+    const ptyAdapter = yield* PtyAdapter.PtyAdapter;

Posted via Macroscope — Effect Service Conventions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@juliusmarminge

juliusmarminge commented Sep 16, 2026

Copy link
Copy Markdown
Member Author

Superseded by merged #12115, which shows Cursor and Grok subscription limits on Usage → Limits via provider APIs (plus OpenCode Go). This draft's PTY TUI probe path is no longer needed.

Closing this PR as leftover hygiene.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@juliusmarminge juliusmarminge closed this Sep 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@macroscopeapp macroscopeapp[bot] macroscopeapp[bot] left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

size:XL 500-999 changed lines (additions + deletions). vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@juliusmarminge @Aditya190803
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.