@monotykamary/pi-better-grok 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +65 -0
- package/THIRD_PARTY_NOTICES.md +19 -0
- package/index.ts +666 -0
- package/package.json +66 -0
- package/src/config.ts +314 -0
- package/src/fast-controller.ts +82 -0
- package/src/format.ts +66 -0
- package/src/grok-auth.ts +242 -0
- package/src/identity.ts +7 -0
- package/src/paths.ts +17 -0
- package/src/usage-controller.ts +210 -0
- package/src/usage.ts +351 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 monotykamary
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# pi-better-grok
|
|
2
|
+
|
|
3
|
+
Better Grok/xAI for [pi](https://pi.dev) — mirrors the [pi-better-openai](https://github.com/monotykamary/pi-better-openai) UX for SuperGrok subscribers: fast mode, subscription usage in the footer, footer polish, and a settings picker.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pi install git:github.com/monotykamary/pi-better-grok
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Commands
|
|
12
|
+
|
|
13
|
+
| Command | What it does |
|
|
14
|
+
| ------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
|
|
15
|
+
| `/grok-fast` | Toggle fast mode (`reasoning_effort: "low"` injected into xAI provider payloads while enabled and the model is allow-listed) |
|
|
16
|
+
| `pi --grok-fast` | Start with fast mode enabled |
|
|
17
|
+
| `/grok-usage` | Force-refresh and show SuperGrok subscription usage |
|
|
18
|
+
| `/grok-usage debug` | Show diagnostics (auth source, last fetch, config path) |
|
|
19
|
+
| `/grok-settings` | Open the settings picker (footer, usage, fast mode) |
|
|
20
|
+
|
|
21
|
+
## Usage widget
|
|
22
|
+
|
|
23
|
+
Piggybacks pi's native xAI login (`/login xai` → **Use a subscription**; tokens in `~/.pi/agent/auth.json` under `xai`). Falls back to `xai-oauth` / `xai-auth` auth-file entries and the official Grok CLI store at `~/.grok/auth.json`.
|
|
24
|
+
|
|
25
|
+
Data comes from the same revision-pinned Grok subscription surface used by the community `pi-grok-usage` extensions:
|
|
26
|
+
|
|
27
|
+
1. `GET https://cli-chat-proxy.grok.com/v1/user` (identity)
|
|
28
|
+
2. `GET https://cli-chat-proxy.grok.com/v1/billing?format=credits` (with the `x-userid` header)
|
|
29
|
+
|
|
30
|
+
Status widget line: `Usage: 66% left · ↺ 5d5h - Mon 5:34 PM` (weekly period + reset clock). Defaults to the widget area below the editor, like pi-better-openai; set `"footer": {"mode": "replace"}` for the full custom footer.
|
|
31
|
+
|
|
32
|
+
## Configuration
|
|
33
|
+
|
|
34
|
+
JSON config at `~/.pi/agent/extensions/pi-better-grok.json` (global) or `<project>/.pi/extensions/pi-better-grok.json` (project):
|
|
35
|
+
|
|
36
|
+
```json
|
|
37
|
+
{
|
|
38
|
+
"persistState": true,
|
|
39
|
+
"supportedModels": ["xai/grok-4.6", "xai/grok-4.5"],
|
|
40
|
+
"fast": { "effort": "low" },
|
|
41
|
+
"usage": {
|
|
42
|
+
"enabled": true,
|
|
43
|
+
"refreshIntervalMs": 60000,
|
|
44
|
+
"showOnlyOnSubscriptionModels": true,
|
|
45
|
+
"showResetTimes": true
|
|
46
|
+
},
|
|
47
|
+
"footer": { "mode": "status" }
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Unknown fields are preserved on write.
|
|
52
|
+
|
|
53
|
+
## Roadmap
|
|
54
|
+
|
|
55
|
+
- `/imagine` via `api.x.ai/v1/images/generations` (API-key accounts)
|
|
56
|
+
- Live Search web tool (SuperGrok `x_search`)
|
|
57
|
+
- Footer pets (port from pi-better-openai)
|
|
58
|
+
|
|
59
|
+
## Acknowledgments
|
|
60
|
+
|
|
61
|
+
Protocol contracts and prior art: [stnly/pi-grok](https://github.com/stnly/pi-grok), [puetsua/pi-grok-usage](https://github.com/puetsua/pi-grok-usage), [apoapostolov/pi-grok-usage](https://github.com/apoapostolov/pi-grok-usage), [luxus/pi-xai](https://github.com/luxus/pi-xai). See `THIRD_PARTY_NOTICES.md`.
|
|
62
|
+
|
|
63
|
+
## Security
|
|
64
|
+
|
|
65
|
+
The `cli-chat-proxy.grok.com` surface is unofficial and reverse-engineered from the Grok CLI; treat schema drift as expected. This extension never logs or stores token contents and masks account IDs in diagnostics.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Third-party notices
|
|
2
|
+
|
|
3
|
+
This project's xAI/Grok subscription contract (endpoints, headers, and payload
|
|
4
|
+
shapes) was established by prior MIT-licensed work in the pi ecosystem. The
|
|
5
|
+
following projects were used as protocol references:
|
|
6
|
+
|
|
7
|
+
- **stnly/pi-grok** — OAuth 2.0 + PKCE / device-flow provider, cli-chat-proxy
|
|
8
|
+
header parity (`x-grok-client-*`, `X-XAI-Token-Auth`, `x-authenticateresponse`).
|
|
9
|
+
MIT License. Copyright (c) stnly.
|
|
10
|
+
- **puetsua/pi-grok-usage** — identity-first billing lookup
|
|
11
|
+
(`GET /v1/user` → `GET /v1/billing?format=credits` with `x-userid`) and the
|
|
12
|
+
`UsageSnapshot` contract this extension mirrors. MIT License.
|
|
13
|
+
- **apoapostolov/pi-grok-usage** — Grok CLI `~/.grok/auth.json` reuse and
|
|
14
|
+
powerbar integration patterns. MIT License.
|
|
15
|
+
- **luxus/pi-xai** — Grok Build billing/usage surface (`BillingUsage`) and
|
|
16
|
+
xAI imagine/video/web tooling references. MIT License.
|
|
17
|
+
|
|
18
|
+
All trademarks belong to their respective owners. These projects are not
|
|
19
|
+
affiliated with or endorsed by xAI.
|