@phantomcodes/cli 1.4.2 → 1.4.3

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.
@@ -46,6 +46,14 @@ function credentials(input) {
46
46
  die('This workspace belongs to a different API address. Run phantom login for this address.', 'workspace_origin');
47
47
  return saved;
48
48
  }
49
+ /** The workspace `phantom login` saved for this API address, or null when it saved none or saved one for another address. */
50
+ export function savedWorkspace(input) {
51
+ const file = credentialPath(input.env);
52
+ if (!existsSync(file))
53
+ return null;
54
+ const saved = JSON.parse(readSecret(input.env, file));
55
+ return saved.base_url === base(input) ? saved : null;
56
+ }
49
57
  /** The management credential `phantom login` saved for this API address, or null when it saved none. */
50
58
  export function savedManagement(input) {
51
59
  return existsSync(credentialPath(input.env)) ? credentials(input).management_credential : null;
@@ -83,7 +91,7 @@ export async function workspaceLogin(input, opts = {}) {
83
91
  value: 'browser',
84
92
  },
85
93
  {
86
- label: 'Just show the link',
94
+ label: 'Show the link',
87
95
  hint: 'to open it yourself, or on another device',
88
96
  value: 'link',
89
97
  },
@@ -121,7 +129,7 @@ export async function workspaceLogin(input, opts = {}) {
121
129
  ` ${p.dim('Open')} ${p.bold(start.verification_uri_complete)}\n` +
122
130
  ` ${p.dim('Code')} ${p.lime(p.bold(start.user_code))} ${p.dim('check that the page shows the same code, then approve')}\n\n` +
123
131
  // In color the spinner below draws this line, so it moves while sign-in waits.
124
- (lit ? '' : ` ${p.dim('Waiting for you to approve...')}\n`) +
132
+ (lit ? '' : ` ${p.dim('Waiting for you to approve…')}\n`) +
125
133
  (pick ? ` ${p.dim('esc or ctrl+c to cancel')}\n` : ''));
126
134
  if (!noBrowser)
127
135
  openUrl(start.verification_uri_complete);
@@ -160,8 +168,8 @@ function alreadySignedIn(input) {
160
168
  io.stdout(JSON.stringify(result) + '\n');
161
169
  return 0;
162
170
  }
163
- /** A spinner on one line: `⠋ Waiting for you to approve...` until stopped, then `✓ Approved.` or nothing. */
164
- function waiting(write, p, words = 'Waiting for you to approve...', doneWords = 'Approved.') {
171
+ /** A spinner on one line: `⠋ Waiting for you to approve…` until stopped, then `✓ Approved.` or nothing. */
172
+ function waiting(write, p, words = 'Waiting for you to approve…', doneWords = 'Approved.') {
165
173
  const frames = '⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏';
166
174
  let k = 0;
167
175
  const draw = () => write(`\r ${p.lime(frames[k++ % frames.length])} ${p.dim(words)}`);
@@ -235,7 +243,7 @@ async function pollForApproval(input, opts, ctx) {
235
243
  saveNamedKey(env, name, token.api_key);
236
244
  }
237
245
  catch (error) {
238
- io.stderr('phantom could not save the connection. Sign in or restore your workspace to revoke the device key and reconnect.\n');
246
+ io.stderr('phantom signed you in but could not save the sign-in on this computer. Fix the error below and run phantom login again. Then revoke the key this sign-in made with phantom keys revoke.\n');
239
247
  throw error;
240
248
  }
241
249
  if (opts.inSetup) {
@@ -253,10 +261,10 @@ async function pollForApproval(input, opts, ctx) {
253
261
  return 0;
254
262
  }
255
263
  io.stdout(JSON.stringify(result) + '\n');
256
- io.stderr('Ready. Run phantom claude, phantom codex or phantom pi. Guests can export recovery with phantom workspace export --file <path>.\n');
264
+ io.stderr('Signed in. Start an agent with phantom claude, phantom codex or phantom pi. A guest workspace can save its recovery file with phantom workspace export --file <path>.\n');
257
265
  return 0;
258
266
  }
259
- die('Device code expired. Run phantom login again.', 'login_expired');
267
+ die('The sign-in code expired before it was approved. Run phantom login again.', 'login_expired');
260
268
  }
261
269
  /** Manage a workspace from the terminal: balance, keys, funding, recovery and revocation. */
262
270
  export async function workspaceCommand(input) {
@@ -284,10 +292,10 @@ export async function workspaceCommand(input) {
284
292
  die('Use phantom workspace import --file <recovery-file>.');
285
293
  const recovery = JSON.parse(readFileSync(flags.file, 'utf8'));
286
294
  if (!recovery || recovery.version !== 1)
287
- die('Invalid recovery file.');
295
+ die(`${flags.file} is not a recovery file from phantom workspace export.`);
288
296
  await wire(base(input), 'GET', '/workspaces/' + encodeURIComponent(recovery.workspace_id), undefined, recovery.management_credential);
289
297
  writeSecret(env, credentialPath(env), JSON.stringify({ ...recovery, base_url: base(input), recovery }));
290
- io.stdout(showsScreen(input) ? `\n ${paint(env, colorOn(env, io.stdoutIsTTY)).lime('✓')} Workspace restored. Make a new key with phantom keys create.\n` : 'Workspace restored. Use phantom keys create to save a new API key.\n');
298
+ io.stdout(showsScreen(input) ? `\n ${paint(env, colorOn(env, io.stdoutIsTTY)).lime('✓')} Workspace restored. Make a new key with phantom keys create.\n` : 'Workspace restored. Make a new key with phantom keys create.\n');
291
299
  return 0;
292
300
  }
293
301
  const saved = credentials(input);
@@ -301,7 +309,7 @@ export async function workspaceCommand(input) {
301
309
  mode: 0o600,
302
310
  flag: 'wx',
303
311
  });
304
- io.stdout(showsScreen(input) ? `\n ${paint(env, colorOn(env, io.stdoutIsTTY)).lime('✓')} Recovery saved to ${flags.file}. Keep that file private: it can manage this workspace.\n` : 'Recovery exported. Keep that file private; it grants workspace management.\n');
312
+ io.stdout(showsScreen(input) ? `\n ${paint(env, colorOn(env, io.stdoutIsTTY)).lime('✓')} Recovery saved to ${flags.file}. Keep that file private: it can manage this workspace.\n` : `Recovery saved to ${flags.file}. Keep that file private: it can manage this workspace.\n`);
305
313
  return 0;
306
314
  }
307
315
  if (command === 'create' || command === 'rotate') {
@@ -476,7 +484,7 @@ export async function workspaceCommand(input) {
476
484
  return leaveFund(input);
477
485
  }
478
486
  if (amount === undefined || !method)
479
- die(`fund needs how much and how to pay. ${FUND_EXAMPLE}`, 'fund_usage');
487
+ die(`fund needs an amount and a way to pay. ${FUND_EXAMPLE}`, 'fund_usage');
480
488
  const result = await wire(saved.base_url, 'POST', endpoint + '/fund', {
481
489
  method: method === 'card' ? 'card' : 'crypto',
482
490
  amount_usd: amount,
@@ -623,7 +631,7 @@ function savedNameFor(env, id) {
623
631
  }
624
632
  /** A limit picker: no limit, or a few round amounts. undefined means Esc. */
625
633
  async function chooseLimit(pick) {
626
- const limit = await choose({ ...pick, esc: 'back' }, 'Spending limit for this key?', [
634
+ const limit = await choose({ ...pick, esc: 'back' }, 'How much may this key spend in total?', [
627
635
  {
628
636
  label: 'No limit',
629
637
  hint: 'it can spend the whole workspace balance',
@@ -721,7 +729,7 @@ async function waitForPayment(input, pick, saved, endpoint, paymentId) {
721
729
  const { env, io } = input;
722
730
  const p = paint(env, colorOn(env, io.isTTY));
723
731
  io.stderr(` ${p.dim('esc to stop waiting')}\n`);
724
- const spinner = colorOn(env, io.isTTY) ? waiting(io.stderr, p, 'Waiting for your payment...', 'Payment received.') : null;
732
+ const spinner = colorOn(env, io.isTTY) ? waiting(io.stderr, p, 'Waiting for your payment…', 'Payment received.') : null;
725
733
  const cancel = cancelKeys((pick.keys ?? keyboard)());
726
734
  const deadline = Date.now() + PAYMENT_WAIT_MS;
727
735
  try {
@@ -741,12 +749,12 @@ async function waitForPayment(input, pick, saved, endpoint, paymentId) {
741
749
  throw new Cancelled();
742
750
  if (key) {
743
751
  spinner?.stop();
744
- io.stderr(` ${p.dim('Stopped waiting. If you finish paying, the credit still lands: check Balance.')}\n`);
752
+ io.stderr(` ${p.dim('Stopped waiting. If you finish paying, the credit still arrives: check Balance.')}\n`);
745
753
  return;
746
754
  }
747
755
  }
748
756
  spinner?.stop();
749
- io.stderr(` ${p.dim('No payment yet. If you finish paying, the credit still lands: check Balance.')}\n`);
757
+ io.stderr(` ${p.dim('No payment yet. If you finish paying, the credit still arrives: check Balance.')}\n`);
750
758
  }
751
759
  finally {
752
760
  spinner?.stop();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@phantomcodes/cli",
3
- "version": "1.4.2",
4
- "description": "AI inference for your coding agents. Route models, control spending, and fund your workspace.",
3
+ "version": "1.4.3",
4
+ "description": "Connects Claude Code, Codex, pi and other coding agents to Phantom AI, an OpenAI-compatible API, and manages your keys, credit and spending caps from the terminal.",
5
5
  "keywords": [
6
6
  "phantom",
7
7
  "api-key",
@@ -9,17 +9,17 @@
9
9
  "llm",
10
10
  "inference",
11
11
  "cli",
12
- "mcp",
12
+ "openai-compatible",
13
13
  "pi-package",
14
14
  "agent-skill",
15
15
  "claude-code",
16
16
  "codex",
17
17
  "cursor",
18
- "model-context-protocol",
18
+ "opencode",
19
19
  "ai-agents",
20
20
  "solana",
21
- "wallet",
22
- "subagents"
21
+ "usdc",
22
+ "wallet"
23
23
  ],
24
24
  "homepage": "https://phantom.codes/",
25
25
  "repository": {
@@ -1,17 +1,13 @@
1
1
  ---
2
2
  name: phantom-ai
3
- description: Use the phantom CLI to connect and run coding agents through Phantom AI, manage workspace funding and spending controls, and route models. Applies when the user requests Phantom inference or payment workflows.
3
+ description: Run the phantom CLI to sign in to Phantom AI, set up or start coding agents on it, add credit, cap what each key spends, and pick models. Use when the user asks for Phantom AI, phantom-1, or a payment or spending task in Phantom.
4
4
  ---
5
5
 
6
6
  # Phantom AI
7
7
 
8
- Phantom AI serves model inference at `https://phantom.codes/v1`. The Phantom CLI connects
9
- existing coding agents to that API, manages model routing to control costs, and
10
- handles workspace funding and controls. Run from an agent (output piped),
11
- commands print JSON; add `--table` for the human-readable screen. Unknown
12
- flags are refused, so check `phantom <command> --help` for the flag names.
8
+ Phantom AI is an OpenAI-compatible API at `https://phantom.codes/v1`. The Phantom CLI (`phantom`) connects coding agents to it, keeps the user's keys, adds credit to their workspace and sets each key's caps and models. When you run it, its output goes through a pipe, so commands print JSON; add `--table` to get the screen a person sees. phantom refuses flags it doesn't know, so check `phantom <command> --help` for the names.
13
9
 
14
- ## Connect and run
10
+ ## Start an agent for one run
15
11
 
16
12
  ```bash
17
13
  phantom login
@@ -21,23 +17,19 @@ phantom claude --key coding
21
17
  phantom pi
22
18
  ```
23
19
 
24
- Login uses browser device approval and saves a key privately; ask the user to
25
- complete approval themselves. For an existing key, have them run
26
- `phantom login --paste` locally, never paste it into chat.
27
- Agent configuration is temporary. The Phantom CLI flags go before agent arguments, or `--`.
20
+ `phantom login` opens a browser page where the user approves a short code, then saves a key on this computer. Ask the user to approve it themselves. If they already have a key, have them run `phantom login --paste` in their own terminal; never ask them to paste a key into chat.
21
+
22
+ `phantom codex`, `phantom claude` and `phantom pi` set the agent up for that run only. phantom's own flags go before the agent's arguments, with `--` between them:
28
23
 
29
24
  ```bash
30
25
  phantom codex --key coding -- exec "review this repository"
31
26
  ```
32
27
 
33
- Named-key selection uses `PHANTOM_KEY_NAME`, then `PHANTOM_API_KEY`, then the
34
- saved login key. An agent's explicit `--key` selects that local named key.
28
+ phantom picks the key in this order: the key saved under the name in `PHANTOM_KEY_NAME`, then `PHANTOM_API_KEY`, then the key `phantom login` saved. `--key <name>` on an agent command runs it on the key saved under that name.
35
29
 
36
- ## Connect existing agents for future runs
30
+ ## Set up the user's agents for later runs
37
31
 
38
- Offer saved setup when the user wants their installed agent to use Phantom AI
39
- without a phantom launcher. Ask whether they want saved setup or a temporary run;
40
- when their request already specifies one, follow it.
32
+ Saved setup changes the agent's own settings, so the user can start it as usual and it calls Phantom AI. Ask whether they want that or a one-run connection, unless their request already says which.
41
33
 
42
34
  ```bash
43
35
  phantom setup --dry-run --table
@@ -45,24 +37,20 @@ phantom setup
45
37
  phantom setup --restore
46
38
  ```
47
39
 
48
- Preview and show the configuration changes before applying the setup the user
49
- approves. Plain setup detects supported agents and asks before writing. Restart
50
- the agent or open a new terminal afterward. It keeps backups for restore.
51
- To connect only Codex, preview the targeted setup first:
40
+ Show the user the dry-run changes and apply only the setup they approve. Plain `phantom setup` finds the agents on the computer and asks before it writes. Afterward the user restarts the agent or opens a new terminal. Setup keeps a copy of each file it changes, and `phantom setup --restore` puts them back.
41
+
42
+ To set up only Codex, preview that first:
52
43
 
53
44
  ```bash
54
45
  phantom setup --agent codex --provider --dry-run --table
55
46
  phantom setup --agent codex --provider
56
47
  ```
57
48
 
58
- Targeted provider setup applies without its own confirmation; run it only after
59
- the user approves the preview. Cursor needs manual settings steps; pi receives
60
- the skill only. Setup wires up a saved key through helpers or environment
61
- variables where supported; Cline stores it in a private config file.
62
- If the user requested a budget, verify that the key the configured agent uses
63
- has that cap. Creating a separate capped key does not change the default key.
49
+ `--agent <name> --provider` writes without asking, so run it only after the user approves the preview. For Cursor, setup prints steps the user follows in Cursor's settings; pi gets the skill only. Most agents read the key through `phantom key show` or the `PHANTOM_API_KEY` line setup adds to the shell startup file. Cline is the exception: setup writes the key into Cline's own settings file, which only the user can read.
50
+
51
+ If the user asked for a budget, check that the key their agent uses has that cap. Making a second key with a cap doesn't change the key the agent already uses.
64
52
 
65
- ## Fund a workspace
53
+ ## Add credit
66
54
 
67
55
  ```bash
68
56
  phantom fund --amount 10 --card
@@ -70,27 +58,23 @@ phantom fund --amount 10 --coin usdc
70
58
  phantom workspace payment --id <payment-id>
71
59
  ```
72
60
 
73
- Card checkout opens the payment URL in your browser. Crypto funding (`--coin usdc` on Solana, `--coin usdc-base` on Base)
74
- provides a Solana pay URL. Credit is available once confirmed. Check pending payments with
75
- `phantom workspace payment --id <id>`. Check balance anytime with `phantom balance`.
61
+ `--card` opens Stripe Checkout in the browser. `--coin usdc` pays in USDC on Solana and `--coin usdc-base` in USDC on Base; both return a payment link and a payment id. The credit appears once Stripe confirms the payment. `phantom workspace payment --id <payment-id>` says whether it has arrived, and `phantom balance` shows the key's credit.
76
62
 
77
- ## Control spending and keys
63
+ ## Cap what keys spend
78
64
 
79
65
  ```bash
80
66
  phantom keys create --save coding --limit 5
81
67
  phantom keys list
82
- phantom keys set --id <key-id> --budget 20 --period 30 --rate 1
83
- phantom keys revoke --id <key-id>
68
+ phantom keys set --id coding --budget 20 --period 30 --rate 1
69
+ phantom keys revoke --id coding
84
70
  phantom keys saved
85
71
  phantom keys rm <name>
86
72
  phantom balance
87
73
  ```
88
74
 
89
- Use the full ID from workspace key metadata. Key controls are enforced by the
90
- server; the rate is dollars per minute. Revocation preserves shared funds.
91
- `keys saved` lists local metadata; `keys rm` only forgets the local copy.
75
+ `--limit` caps a key's total spend, `--budget` its spend per `--period` days, and `--rate` its dollars per minute. The server enforces each cap. `--id` takes the key's name, its id, or the first 4 or more characters of its id, as `phantom keys list` shows them. Revoking a key turns it off for good; its credit stays in the workspace. `keys saved` lists the keys saved on this computer, and `keys rm` forgets one there while the key keeps working.
92
76
 
93
- ## Route models
77
+ ## Set rules for `auto`
94
78
 
95
79
  ```bash
96
80
  phantom route
@@ -99,8 +83,7 @@ phantom route rule add --if has_tools=true --use first
99
83
  phantom route test --table
100
84
  ```
101
85
 
102
- Routing affects `auto` requests. Use `PHANTOM_KEY_NAME=coding` to manage the same
103
- key used by an agent with `--key coding`. Route tests are free.
86
+ A route policy applies to requests for model `auto`. To change the policy of the key an agent runs with `--key coding`, set `PHANTOM_KEY_NAME=coding`. `phantom route test` costs nothing.
104
87
 
105
88
  ## Pick phantom-1, phantom-1:free or phantom-1:zdr
106
89
 
@@ -109,12 +92,9 @@ phantom models
109
92
  phantom models use phantom-1:zdr
110
93
  ```
111
94
 
112
- `phantom models` lists Phantom's three models with the jobs each can do and the
113
- model behind each job. `phantom-1` does every job; `phantom-1:free` is chat at $0;
114
- `phantom-1:zdr` is chat on providers that keep no data. `models use` sets the model
115
- `phantom claude`, `phantom codex`, `phantom pi` and the next `phantom setup` start on.
95
+ `phantom models` lists Phantom's three models, the jobs each can do and the model behind each job. `phantom-1` does every job, `phantom-1:free` is chat at $0, and `phantom-1:zdr` is chat on providers that keep none of the user's data. `models use` sets the model that `phantom claude`, `phantom codex`, `phantom pi` and the next `phantom setup` start on.
116
96
 
117
- ## Pick phantom-1's models
97
+ ## Pick the model in each tier
118
98
 
119
99
  ```bash
120
100
  phantom lineup --table
@@ -122,10 +102,7 @@ phantom lineup set --frontier <model> --economy-fallback <model>
122
102
  phantom lineup reset
123
103
  ```
124
104
 
125
- Each tier (economy, standard, frontier) takes a model from its own choices, which
126
- `phantom lineup` lists. A fallback is the model to try when the tier's model fails.
127
- `default` in place of a model puts that tier back to its default. `lineup set`
128
- keeps the tiers you don't name.
105
+ phantom-1 sorts each request into a tier: economy, standard or frontier. The lineup sets the model each tier runs, from the choices `phantom lineup` lists, and a fallback to try when that model fails. `default` in place of a model puts the tier back to its default. `lineup set` keeps the tiers you don't name.
129
106
 
130
107
  ## See what was spent
131
108
 
@@ -134,24 +111,21 @@ phantom spend --table
134
111
  phantom spend --workspace --from 2026-09-01 --to 2026-09-30
135
112
  ```
136
113
 
137
- `spend` shows what the key spent by model and day, and an estimate of what `phantom-1`
138
- saved against its frontier model. `--workspace` shows every key in the workspace by
139
- name. Dates are UTC days (`YYYY-MM-DD`); the default is this month.
114
+ `phantom spend` shows what the key spent by model and day, and an estimate of what `phantom-1` saved compared with running every call on its frontier model. `--workspace` shows every key in the workspace by name. Dates are UTC days (`YYYY-MM-DD`), and the default is this month.
115
+
116
+ ## Recovery, receipts and deleting a workspace
117
+
118
+ `phantom --help --all` lists every command, including `phantom verify` for receipts, and the environment variables.
140
119
 
141
- ## Advanced tasks
120
+ A guest workspace has no account; whoever holds its recovery file controls it. Save that file with `phantom workspace export --file <path>`, only to a private place.
142
121
 
143
- Use `phantom --help --all` for receipts, MCP and direct-key purchases.
144
- Export guest recovery with `phantom workspace export --file
145
- <path>` only to a private destination. Recovery grants workspace management access.
146
- Delete an empty workspace with `phantom workspace delete`: it takes the workspace's keys
147
- and saved sign-ins with it, asks first (`--yes` skips the question), and refuses while the
148
- workspace holds credit, a running request or a payment in progress.
122
+ `phantom workspace delete` deletes an empty workspace, with its keys and saved sign-ins. It asks first (`--yes` skips the question). The server refuses while the workspace holds credit, has a request running or has a payment in progress.
149
123
 
150
- ## Rules
124
+ ## Rules for running phantom
151
125
 
152
- - Never print, log or repeat API keys, wallet secrets, management credentials or recovery files. `phantom keys show` is for shell integration, not model context.
153
- - Use CLI commands to manage state; do not manually edit or delete its files.
154
- - Ask before payments the user has not requested. Existing task approval covers only the requested payment and amount.
155
- - Run permanent `phantom setup` changes only when requested; otherwise preview with `--dry-run`.
156
- - Use a user's existing subscription agent when they request that workflow. Phantom inference requires their intent.
157
- - Exit code 2 means a rejected key; report it rather than retrying unchanged credentials.
126
+ - Never print, log or repeat API keys, wallet secrets, management credentials or recovery files. `phantom keys show` is for shell use, not for your context.
127
+ - Change phantom's state with its commands. Don't edit or delete its files by hand.
128
+ - Ask before any payment the user hasn't asked for. Their approval covers only the payment and amount they named.
129
+ - Make lasting `phantom setup` changes only when the user asks; otherwise preview with `--dry-run`.
130
+ - If the user wants to keep using their agent's own subscription, do that. Send their agent's calls to Phantom only when they ask for it.
131
+ - Exit code 2 means the server rejected the key. Report it; don't retry with the same key.