-
Notifications
You must be signed in to change notification settings - Fork 264
feat(warp): add Warp provider and macOS user defaults host API #527
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
JulianKniephoff
wants to merge
1
commit into
robinebers:main
Choose a base branch
from
JulianKniephoff:feat/warp
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+342
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # Warp | ||
|
|
||
| Tracks AI usage credits for the Warp terminal. | ||
|
|
||
| ## Data Source | ||
|
|
||
| The plugin reads the **AI Credits** quota from Warp's User Defaults System. | ||
|
|
||
| - **Domain**: `dev.warp.Warp-Stable` | ||
| - **Key**: `AIRequestLimitInfo` | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - Warp must be installed. | ||
| - You must be logged into your Warp account. | ||
| - You must have used Warp AI at least once to initialize the local User Defaults System data. | ||
| - If your quota has recently reset, you must use Warp AI again to trigger a local update. | ||
|
|
||
| ## Parsed Fields | ||
|
|
||
| From `AIRequestLimitInfo`: | ||
| - `num_requests_used_since_refresh`: used credits | ||
| - `limit`: total credit limit | ||
| - `next_refresh_time`: reset timestamp | ||
|
|
||
| ## Displayed Lines | ||
|
|
||
| | Line | Scope | Description | | ||
| | :--- | :--- | :--- | | ||
| | AI Credits | Overview | Total AI credits used in the current billing cycle. Includes reset timer. | | ||
|
|
||
| ## Errors | ||
|
|
||
| | Condition | Message | | ||
| | :--- | :--- | | ||
| | Key not found in defaults | "No Warp AI usage data found. Ensure Warp is installed and you have used AI at least once. If you have, this may be a plugin bug." | | ||
| | Data malformed or incomplete | "Warp AI quota data is malformed. This may be a plugin bug." | | ||
| | Data is stale (expired reset time) | "No active Warp AI quota found. Have your credits reset recently? Try using Warp AI once to refresh it." | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| (function () { | ||
| function probe(ctx) { | ||
| // Read the data from user defaults | ||
| let json | ||
| try { | ||
| json = ctx.host.defaults.read("dev.warp.Warp-Stable", "AIRequestLimitInfo") | ||
| } catch (e) { | ||
| ctx.host.log.info("Warp: AIRequestLimitInfo key not found in preferences: " + String(e)) | ||
| throw "No Warp AI usage data found. Ensure Warp is installed and you have used AI at least once. If you have, this may be a plugin bug." | ||
| } | ||
|
|
||
| // Parse and validate the data structure | ||
| const data = ctx.util.tryParseJson(json) | ||
| if (!data || typeof data !== "object") { | ||
| ctx.host.log.error("Warp: Malformed quota data: " + json) | ||
| throw "Warp AI quota data is malformed. This may be a plugin bug." | ||
| } | ||
|
|
||
| const { num_requests_used_since_refresh: used, limit, next_refresh_time: resetsAt } = data | ||
|
|
||
| if ( | ||
| !Number.isFinite(used) || | ||
| !Number.isFinite(limit) || | ||
| limit <= 0 || | ||
| !resetsAt || | ||
| !Number.isFinite(new Date(resetsAt).getTime()) | ||
| ) { | ||
| ctx.host.log.error("Warp: Incomplete quota data: " + json) | ||
| throw "Warp AI quota data is malformed. This may be a plugin bug." | ||
| } | ||
|
|
||
| // Staleness check: Ensure the data belongs to an active cycle | ||
| if (new Date(resetsAt) < new Date(ctx.nowIso)) { | ||
| ctx.host.log.info("Warp: Quota data is stale (expired " + resetsAt + ")") | ||
| throw "No active Warp AI quota found. Have your credits reset recently? Try using Warp AI once to refresh it." | ||
| } | ||
|
|
||
| // Return the formatted usage lines | ||
| return { | ||
| lines: [ | ||
| ctx.line.progress({ | ||
| label: "AI Credits", | ||
| used, | ||
| limit, | ||
| format: { kind: "count", suffix: "credits" }, | ||
| resetsAt: ctx.util.toIso(resetsAt), | ||
| }), | ||
| ], | ||
| } | ||
| } | ||
|
|
||
| globalThis.__openusage_plugin = { id: "warp", probe } | ||
| })() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| { | ||
| "schemaVersion": 1, | ||
| "id": "warp", | ||
| "name": "Warp", | ||
| "version": "0.0.1", | ||
| "entry": "plugin.js", | ||
| "icon": "icon.svg", | ||
| "brandColor": "#000000", | ||
| "links": [ | ||
| { "label": "Warp AI", "url": "https://www.warp.dev/warp-ai" } | ||
| ], | ||
| "lines": [ | ||
| { "type": "progress", "label": "AI Credits", "scope": "overview", "primaryOrder": 1 } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| import { beforeEach, describe, expect, it, vi } from "vitest" | ||
| import { makeCtx } from "../test-helpers.js" | ||
|
|
||
| const loadPlugin = async () => { | ||
| await import("./plugin.js") | ||
| return globalThis.__openusage_plugin | ||
| } | ||
|
|
||
| describe("warp plugin", () => { | ||
| beforeEach(() => { | ||
| delete globalThis.__openusage_plugin | ||
| vi.resetModules() | ||
| }) | ||
|
|
||
| it("throws and logs info if defaults key is not found", async () => { | ||
| const ctx = makeCtx() | ||
| ctx.host.defaults.read.mockImplementation(() => { | ||
| throw new Error("key not found") | ||
| }) | ||
| const plugin = await loadPlugin() | ||
|
|
||
| expect(() => plugin.probe(ctx)).toThrow( | ||
| "No Warp AI usage data found. Ensure Warp is installed and you have used AI at least once. If you have, this may be a plugin bug." | ||
| ) | ||
| expect(ctx.host.log.info).toHaveBeenCalledWith( | ||
| expect.stringContaining("Warp: AIRequestLimitInfo key not found in preferences") | ||
| ) | ||
| }) | ||
|
|
||
| it("throws and logs error if JSON is malformed or not an object", async () => { | ||
| const ctx = makeCtx() | ||
| const plugin = await loadPlugin() | ||
|
|
||
| const malformedInputs = [ | ||
| "invalid json", | ||
| "null", | ||
| "42", | ||
| "true", | ||
| "", | ||
| ] | ||
|
|
||
| for (const input of malformedInputs) { | ||
| ctx.host.defaults.read.mockReturnValue(input) | ||
| expect(() => plugin.probe(ctx)).toThrow("Warp AI quota data is malformed. This may be a plugin bug.") | ||
| expect(ctx.host.log.error).toHaveBeenCalledWith( | ||
| expect.stringContaining("Warp: Malformed quota data") | ||
| ) | ||
| vi.clearAllMocks() | ||
| } | ||
| }) | ||
|
|
||
| it("throws and logs error if quota data fields are invalid or missing", async () => { | ||
| const ctx = makeCtx() | ||
| const plugin = await loadPlugin() | ||
|
|
||
| const invalidPayloads = [ | ||
| {}, // empty object | ||
| [], // array | ||
| { limit: 100, next_refresh_time: "2026-06-01T00:00:00Z" }, // missing used | ||
| { num_requests_used_since_refresh: 10, next_refresh_time: "2026-06-01T00:00:00Z" }, // missing limit | ||
| { num_requests_used_since_refresh: 10, limit: 100 }, // missing resetsAt | ||
| { num_requests_used_since_refresh: "10", limit: 100, next_refresh_time: "2026-06-01T00:00:00Z" }, // used is string | ||
| { num_requests_used_since_refresh: 10, limit: "100", next_refresh_time: "2026-06-01T00:00:00Z" }, // limit is string | ||
| { num_requests_used_since_refresh: 10, limit: 0, next_refresh_time: "2026-06-01T00:00:00Z" }, // limit is 0 | ||
| { num_requests_used_since_refresh: 10, limit: -5, next_refresh_time: "2026-06-01T00:00:00Z" }, // limit is negative | ||
| { num_requests_used_since_refresh: 10, limit: 100, next_refresh_time: "" }, // resetsAt is empty string | ||
| { num_requests_used_since_refresh: 10, limit: 100, next_refresh_time: "not-a-date" }, // resetsAt is invalid date string | ||
| { num_requests_used_since_refresh: NaN, limit: 100, next_refresh_time: "2026-06-01T00:00:00Z" }, // used is NaN | ||
| { num_requests_used_since_refresh: 10, limit: NaN, next_refresh_time: "2026-06-01T00:00:00Z" }, // limit is NaN | ||
| { num_requests_used_since_refresh: Infinity, limit: 100, next_refresh_time: "2026-06-01T00:00:00Z" }, // used is Infinity | ||
| { num_requests_used_since_refresh: 10, limit: Infinity, next_refresh_time: "2026-06-01T00:00:00Z" }, // limit is Infinity | ||
| ] | ||
|
|
||
| for (const payload of invalidPayloads) { | ||
| const json = JSON.stringify(payload) | ||
| ctx.host.defaults.read.mockReturnValue(json) | ||
| expect(() => plugin.probe(ctx)).toThrow("Warp AI quota data is malformed. This may be a plugin bug.") | ||
| expect(ctx.host.log.error).toHaveBeenCalledWith( | ||
| expect.stringContaining("Warp: Incomplete quota data") | ||
| ) | ||
| vi.clearAllMocks() | ||
| } | ||
| }) | ||
|
|
||
| it("throws and logs info if data is stale", async () => { | ||
| const ctx = makeCtx() | ||
| ctx.nowIso = "2026-05-20T12:00:00Z" | ||
| const resetsAt = "2026-05-19T00:00:00Z" | ||
| ctx.host.defaults.read.mockReturnValue( | ||
| JSON.stringify({ | ||
| num_requests_used_since_refresh: 10, | ||
| limit: 100, | ||
| next_refresh_time: resetsAt, | ||
| }) | ||
| ) | ||
| const plugin = await loadPlugin() | ||
|
|
||
| expect(() => plugin.probe(ctx)).toThrow("No active Warp AI quota found. Have your credits reset recently?") | ||
| expect(ctx.host.log.info).toHaveBeenCalledWith( | ||
| expect.stringContaining("Warp: Quota data is stale") | ||
| ) | ||
| }) | ||
|
|
||
| it("parses valid credits data", async () => { | ||
| const ctx = makeCtx() | ||
| ctx.nowIso = "2026-05-20T12:00:00Z" | ||
| ctx.host.defaults.read.mockReturnValue( | ||
| JSON.stringify({ | ||
| num_requests_used_since_refresh: 42, | ||
| limit: 100, | ||
| next_refresh_time: "2026-06-01T00:00:00Z", | ||
| }) | ||
| ) | ||
|
|
||
| const plugin = await loadPlugin() | ||
| const result = plugin.probe(ctx) | ||
|
|
||
| expect(ctx.host.defaults.read).toHaveBeenCalledWith("dev.warp.Warp-Stable", "AIRequestLimitInfo") | ||
| expect(result.lines).toHaveLength(1) | ||
|
|
||
| const credits = result.lines.find((l) => l.label === "AI Credits") | ||
| expect(credits.used).toBe(42) | ||
| expect(credits.limit).toBe(100) | ||
| expect(credits.resetsAt).toBe("2026-06-01T00:00:00.000Z") | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
P2: Warp plugin hardcodes a single defaults domain and fails for Warp Preview users
Prompt for AI agents