@phantomcodes/cli 1.4.1 → 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.
Files changed (69) hide show
  1. package/README.md +99 -133
  2. package/dist/agents/command.d.mts +36 -0
  3. package/dist/agents/command.mjs +22 -10
  4. package/dist/agents/proxy.d.mts +44 -0
  5. package/dist/agents/proxy.mjs +4 -2
  6. package/dist/cli/app.d.mts +25 -0
  7. package/dist/cli/app.mjs +2 -2
  8. package/dist/cli/commands.d.mts +23 -0
  9. package/dist/cli/commands.mjs +106 -54
  10. package/dist/cli/help.d.mts +26 -0
  11. package/dist/cli/help.mjs +10 -6
  12. package/dist/cli/run.d.mts +2 -0
  13. package/dist/cli/screens.d.mts +171 -0
  14. package/dist/cli/screens.mjs +3 -3
  15. package/dist/cli/start.d.mts +34 -0
  16. package/dist/core/brand.d.mts +12 -0
  17. package/dist/core/errors.d.mts +27 -0
  18. package/dist/core/free.d.mts +13 -0
  19. package/dist/core/helpers.d.mts +75 -0
  20. package/dist/core/helpers.mjs +27 -2
  21. package/dist/core/motion.d.mts +47 -0
  22. package/dist/core/node-trust.d.mts +12 -0
  23. package/dist/core/pick.d.mts +86 -0
  24. package/dist/core/request.d.mts +64 -0
  25. package/dist/core/request.mjs +78 -29
  26. package/dist/core/secrets.d.mts +33 -0
  27. package/dist/core/shapes.d.mts +13 -0
  28. package/dist/core/state.d.mts +3 -0
  29. package/dist/core/style.d.mts +49 -0
  30. package/dist/core/version.d.mts +2 -0
  31. package/dist/core/version.mjs +1 -1
  32. package/dist/keys/command.d.mts +16 -0
  33. package/dist/keys/saved.d.mts +90 -0
  34. package/dist/keys/saved.mjs +6 -2
  35. package/dist/models/choice.d.mts +7 -0
  36. package/dist/models/choice.mjs +1 -1
  37. package/dist/models/command.d.mts +8 -0
  38. package/dist/models/list.d.mts +39 -0
  39. package/dist/phantom.d.mts +45 -0
  40. package/dist/receipts/command.d.mts +7 -0
  41. package/dist/receipts/receipts.d.mts +67 -0
  42. package/dist/receipts/receipts.mjs +15 -11
  43. package/dist/setup/agents.d.mts +149 -0
  44. package/dist/setup/agents.mjs +50 -37
  45. package/dist/setup/apply.d.mts +71 -0
  46. package/dist/setup/apply.mjs +7 -2
  47. package/dist/setup/command.d.mts +12 -0
  48. package/dist/setup/command.mjs +32 -5
  49. package/dist/setup/editors.d.mts +101 -0
  50. package/dist/setup/editors.mjs +6 -4
  51. package/dist/setup/legacy.d.mts +13 -0
  52. package/dist/setup/plan.d.mts +104 -0
  53. package/dist/setup/plan.mjs +5 -3
  54. package/dist/setup/screen.d.mts +30 -0
  55. package/dist/setup/screen.mjs +2 -2
  56. package/dist/setup/shared.d.mts +141 -0
  57. package/dist/setup/shared.mjs +8 -2
  58. package/dist/setup/was.d.mts +42 -0
  59. package/dist/setup/was.mjs +91 -0
  60. package/dist/spend/command.d.mts +5 -0
  61. package/dist/spend/lineup.d.mts +54 -0
  62. package/dist/spend/lineup.mjs +3 -2
  63. package/dist/spend/report.d.mts +105 -0
  64. package/dist/spend/report.mjs +2 -2
  65. package/dist/spend/routing.d.mts +72 -0
  66. package/dist/workspace/command.d.mts +59 -0
  67. package/dist/workspace/command.mjs +106 -52
  68. package/package.json +7 -7
  69. package/skills/phantom-ai/SKILL.md +40 -66
@@ -7,7 +7,7 @@ import { verifyCommand } from "../receipts/command.mjs";
7
7
  import { setupCommand } from "../setup/command.mjs";
8
8
  import { SETUP_MODEL } from "../setup/shared.mjs";
9
9
  import { modelsCommand } from "../models/command.mjs";
10
- import { SETUP_NAMES, orList } from "../setup/agents.mjs";
10
+ import { SETUP_NAMES } from "../setup/agents.mjs";
11
11
  /** The short `--help`'s headings, in the order they print. */
12
12
  export const HELP_GROUPS = ['Start', 'Run', 'Money', 'Keys', 'Routing', 'More'];
13
13
  async function loginDispatch(input) {
@@ -29,73 +29,111 @@ async function fundDispatch(input) {
29
29
  void flags['no-browser'];
30
30
  return workspaceCommand({ ...input, subcommand: 'fund' });
31
31
  }
32
- /** The definitions used by CLI dispatch, help, and generated documentation. */
32
+ /**
33
+ * The definitions used by CLI dispatch, help, and generated documentation.
34
+ * `run()` reads each command's flags from its `help`, so every flag a command
35
+ * takes must appear there as `--name`.
36
+ */
33
37
  export const COMMANDS = [
34
38
  {
35
39
  name: 'login', handler: loginDispatch, keyless: true,
36
40
  group: 'Start', summary: 'sign in only, or save a Phantom key you already have',
37
- help: ` login [--save <name>] [--no-browser] sign in by device code: an account or a guest workspace
38
- login --paste save a Phantom key you already have (it asks for it)`,
41
+ help: ` login [--save <name>] [--no-browser]
42
+ sign in by approving a short code in the
43
+ browser, with an account or as a guest;
44
+ --save names the key
45
+ login --paste save a Phantom key you already have; it asks for
46
+ the key, so it stays out of your shell history`,
39
47
  },
40
48
  {
41
49
  name: 'workspace', handler: workspaceCommand, keyless: true,
42
- group: 'More', summary: 'the whole workspace: balance, recovery and access',
43
- help: ` workspace [status] shared balance, keys, recent usage and management access
44
- workspace payment --id <payment-id> check verified funding status
45
- workspace export --file <path> export private guest recovery; refuses overwrites
46
- workspace import --file <path> restore a guest, then issue replacement keys
47
- workspace revoke-access --id <id> revoke a browser, device or recovery credential
48
- workspace delete [--yes] delete an empty workspace and forget it here (--yes: don't ask)`,
50
+ group: 'More', summary: 'the shared balance, keys, recovery and sign-ins',
51
+ help: ` workspace [status] the shared balance, each key, the latest calls
52
+ and the sign-ins that can manage the workspace
53
+ workspace payment --id <payment-id>
54
+ whether a payment has arrived
55
+ workspace export --file <path> save a guest workspace's recovery file; it won't
56
+ overwrite a file that exists
57
+ workspace import --file <path> sign in to a guest workspace from its recovery
58
+ file, then make a key with phantom keys create
59
+ workspace revoke-access --id <id> stop a browser, device or recovery file from
60
+ managing the workspace
61
+ workspace delete [--yes] delete an empty workspace and forget it here
62
+ (--yes: don't ask)`,
49
63
  },
50
64
  {
51
65
  name: 'fund', handler: fundDispatch, keyless: true,
52
66
  group: 'Money', summary: 'add credit by card or crypto',
53
67
  help: ` fund --amount <USD> [--card | --coin usdc|usdc-base] [--no-browser]
54
- fund your workspace balance with card (plus Stripe's fee) or crypto`,
68
+ add credit to your workspace by card (plus
69
+ Stripe's fee), or USDC on Solana (usdc) or Base
70
+ (usdc-base); --no-browser prints the link`,
55
71
  },
56
72
  {
57
73
  name: 'keys', handler: workspaceCommand, keyless: true,
58
74
  group: 'Keys', summary: "your workspace's keys: list, create, set limits, revoke",
59
- help: ` keys [list] remote workspace key metadata, never secrets
60
- keys create [--save <name>] [--limit <USD>]
75
+ help: ` keys [list] the workspace's keys: name, id, spend and limit;
76
+ never the keys themselves
77
+ keys create [--save <name>] [--limit <USD|none>]
78
+ make a key and save it on this computer; --limit
79
+ caps what it can spend in total
61
80
  keys set --id <id> [--limit <USD|none>] [--budget <USD|none>]
62
81
  [--period <days|none>] [--rate <USD|none>] [--name <name>]
63
82
  [--policy-file <path> | --clear-policy]
64
- keys rotate --id <id> [--save <name>] replace only the corresponding saved key
65
- keys revoke --id <id> [--yes] revoke access, keeping workspace credit (--yes: don't ask)
66
- keys saved [--balance] local saved key metadata
67
- keys save <name> [key] validate and save an existing key (prompts if omitted)
68
- keys show [name] print a secret for shell integration only
69
- keys show [name] --copy copy it to the clipboard instead (Mac), for an app's settings
70
- keys rm <name> forget a local copy; remote key keeps working`,
83
+ change a key: its total limit, a budget for each
84
+ period of days, dollars a minute, its name or
85
+ its route policy
86
+ keys rotate --id <id> [--save <name>]
87
+ swap a key for a new one with the same settings;
88
+ the old one stops working, and the copy saved
89
+ here is replaced
90
+ keys revoke --id <id> [--yes] turn a key off for good; its credit stays in the
91
+ workspace (--yes: don't ask)
92
+ keys saved [--balance] the keys saved on this computer (--balance adds
93
+ each one's credit)
94
+ keys save <name> [key] check a key and save it by name; it asks for the
95
+ key when you leave it out
96
+ keys show [name] print a saved key, for PHANTOM_API_KEY=$(...) in
97
+ a shell; keep it out of chat and logs
98
+ keys show [name] --copy copy it to the clipboard instead (Mac), for an
99
+ app's settings
100
+ keys rm <name> forget a key saved here; the key keeps working`,
71
101
  },
72
102
  {
73
103
  name: 'claude', handler: agentCommand, keyless: true,
74
104
  group: 'Run', summary: 'start Claude Code on Phantom AI',
75
- help: ` claude [--key <name>] [--no-browser] -- <agent arguments>`,
105
+ help: ` claude [--key <name>] [--no-browser] -- <agent arguments>
106
+ start Claude Code on Phantom AI; --key picks a
107
+ key saved by name`,
76
108
  },
77
109
  {
78
110
  name: 'codex', handler: agentCommand, keyless: true,
79
111
  group: 'Run', summary: 'start Codex on Phantom AI',
80
- help: ` codex [--key <name>] [--no-browser] -- <agent arguments>`,
112
+ help: ` codex [--key <name>] [--no-browser] -- <agent arguments>
113
+ start Codex on Phantom AI; --key picks a key
114
+ saved by name`,
81
115
  },
82
116
  {
83
117
  name: 'pi', handler: agentCommand, keyless: true,
84
118
  group: 'Run', summary: 'start pi on Phantom AI',
85
119
  help: ` pi [--key <name>] [--no-browser] -- <agent arguments>
86
- run with a saved key`,
120
+ start pi on Phantom AI; --key picks a key saved
121
+ by name`,
87
122
  },
88
123
  {
89
124
  name: 'balance', handler: balanceCommand,
90
125
  group: 'Money', summary: 'your credit, and when it expires',
91
- help: ` balance show credit balance and expiry`,
126
+ help: ` balance what this key can spend, and when it expires`,
92
127
  },
93
128
  {
94
129
  name: 'spend', handler: spendCommand, keyless: ['--workspace'],
95
130
  group: 'Money', summary: 'what you spent, and what phantom-1 saved',
96
- help: ` spend [--from <date>] [--to <date>] what this key spent, by model and day, and what phantom-1
97
- saved; dates are UTC days as YYYY-MM-DD, default this month
98
- spend --workspace every key in the workspace by name (needs phantom login)`,
131
+ help: ` spend [--from <date>] [--to <date>]
132
+ what this key spent, by model and day, and what
133
+ phantom-1 saved; dates are UTC days as
134
+ YYYY-MM-DD, this month by default
135
+ spend --workspace every key in the workspace by name (needs
136
+ phantom login)`,
99
137
  },
100
138
  {
101
139
  name: 'key', advanced: true, handler: keyCommand, keyless: true,
@@ -104,20 +142,29 @@ export const COMMANDS = [
104
142
  key list [--balance] saved keys, by name and id
105
143
  key save <name> [key] save a key by name (prompts if no key is given)
106
144
  key show [name] print a saved key, for PHANTOM_API_KEY=$(...);
107
- no name prints the key phantom is using
145
+ with no name, the key phantom is using
108
146
  key rm <name> forget a saved key (the key keeps working)`,
109
147
  },
110
148
  {
111
149
  name: 'route', handler: routeCommand,
112
150
  group: 'Routing', summary: 'which models "auto" runs, and rules for picking',
113
- help: ` route [get] show which model "auto" runs, and why
151
+ help: ` route [get] which model "auto" runs for this key, and why
114
152
  route set --sort fast|cheap|throughput|default
115
- which providers serve this key's models first: fast
116
- starts answering soonest; cheap is the default
117
- route set --models a,b,c models for "auto", first is the default
118
- [--applies-to auto|all] [--on-empty stop|cheapest] [--fallback]
119
- [--stick-minutes n] keep a conversation's model this long (default 5)
120
- [--stick-by-prompt false] only x-phantom-session marks a conversation
153
+ which providers serve this key's models first:
154
+ fast starts answering soonest, throughput sends
155
+ the most tokens a second, cheap costs least and
156
+ is the default; default goes back to cheap
157
+ route set --models a,b,c the models "auto" picks from; the first is the
158
+ default
159
+ [--applies-to auto|all] all: route requests that name a model too
160
+ [--on-empty stop|cheapest]
161
+ when the cap is used up: refuse requests, or
162
+ run them on the cheapest model
163
+ [--fallback] try the next model when one fails
164
+ [--stick-minutes n] keep a conversation on its model this long
165
+ (default 5)
166
+ [--stick-by-prompt false]
167
+ only x-phantom-session marks a conversation
121
168
  route set --file policy.json replace the whole policy
122
169
  route rule add --if <name=value> --use <model|cheapest|first|next> [--at n]
123
170
  conditions: pace, budget_left_pct_below,
@@ -130,9 +177,11 @@ export const COMMANDS = [
130
177
  {
131
178
  name: 'lineup', handler: lineupCommand,
132
179
  group: 'Routing', summary: 'the model phantom-1 runs in each tier',
133
- help: ` lineup [get] show the model phantom-1 runs in each tier, and the choices
134
- lineup set --economy <model> pick the model for a tier; "default" goes back to the default
135
- [--standard <model>] [--frontier <model>]
180
+ help: ` lineup [get] the model phantom-1 runs in each tier, and the
181
+ models you can pick from
182
+ lineup set --economy <model> pick the model for a tier; "default" puts the
183
+ [--standard <model>] tier back to its default
184
+ [--frontier <model>]
136
185
  [--economy-fallback <model>] [--standard-fallback <model>]
137
186
  [--frontier-fallback <model>]
138
187
  the model to try when a tier's model fails
@@ -141,45 +190,48 @@ export const COMMANDS = [
141
190
  {
142
191
  name: 'models', handler: modelsCommand, keyless: true,
143
192
  group: 'Routing', summary: 'phantom-1, free or zdr: what each can do, and which your agents use',
144
- help: ` models what phantom-1, phantom-1:free and phantom-1:zdr can do,
145
- and the model behind each job; at a terminal, pick one
193
+ help: ` models what phantom-1, phantom-1:free and phantom-1:zdr
194
+ can do, and the model behind each job; at a
195
+ terminal, pick one
146
196
  models use <id> start your agents on it, without the menu`,
147
197
  },
148
198
  {
149
199
  name: 'logout', handler: logoutDispatch, keyless: true,
150
200
  group: 'More', summary: 'sign out on this computer',
151
- help: ` logout sign out: forget workspace access and the default saved key
201
+ help: ` logout sign out: forget workspace access and the
202
+ default saved key
152
203
  logout --all also forget every key saved here by name`,
153
204
  },
154
205
  {
155
206
  name: 'setup', handler: setupCommand, keyless: true,
156
207
  group: 'Start', summary: 'sign in and connect your coding agents',
157
- help: ` setup set up every agent found: install the skill and
158
- point its model calls at Phantom AI; shows each
159
- file's changes and asks first. With no key yet,
160
- signs in first (in a terminal)
208
+ help: ` setup find your agents, install the skill in each, and
209
+ point their model calls at Phantom AI; it shows
210
+ each file's changes and asks first. With no key
211
+ yet, it signs you in first (at a terminal)
161
212
  [--yes] don't ask
162
213
  [--no-browser] print the sign-in link instead of opening it
163
- [--dry-run] preview the changes without making them
214
+ [--dry-run] show the changes without making them
164
215
  [--diff] show every line each file gains or loses
165
- [--no-shell] leave your shell startup file alone and list
216
+ [--no-shell] leave your shell startup file alone and print
166
217
  the lines to add yourself
167
218
  [--limit <USD|none>] cap what this key can spend each month
168
- [--json] print JSON in a terminal too (a pipe always gets JSON)
219
+ [--json] print JSON at a terminal too (a pipe always gets JSON)
169
220
  [--model <id>] the model each agent starts on (default ${SETUP_MODEL})
170
221
  setup --agent <name> install the skill for one agent, without asking:
171
- ${orList(SETUP_NAMES)}
172
- or all
222
+ ${SETUP_NAMES.join(', ')} or all
173
223
  setup [--agent <name>] --provider point that agent's model calls at Phantom AI;
174
- --provider off removes only what phantom wrote
224
+ --provider off takes phantom's settings out and
225
+ puts back what they replaced
175
226
  setup --restore [--agent <name>] put back the files setup changed, from the
176
227
  .phantom.bak copies it kept`,
177
228
  },
178
229
  {
179
230
  name: 'verify', advanced: true, handler: verifyCommand, keyless: ['--receipt'],
180
231
  group: 'More', summary: 'check a signed receipt',
181
- help: ` verify --model <id> make one tiny call and check its signed receipt
182
- names the model you asked for (costs a fraction of a cent)
232
+ help: ` verify --model <id> make one small call and check that its signed
233
+ receipt names the model you asked for (costs a
234
+ fraction of a cent)
183
235
  verify --receipt <receipt> check a receipt you already have`,
184
236
  },
185
237
  ];
@@ -0,0 +1,26 @@
1
+ /** One entry in {@link ENV_VARS}. */
2
+ export type EnvVar = {
3
+ /** The variable's name. */
4
+ name: string;
5
+ /** What it does, in a few words, for HELP and the reference. */
6
+ about: string;
7
+ /** Holds a secret: keep it out of files, logs and the model's context. */
8
+ secret?: boolean;
9
+ /** Read from the environment only, on purpose: no flag or tool argument can set it. */
10
+ envOnly?: boolean;
11
+ /** Limits what an agent can spend. */
12
+ cap?: boolean;
13
+ };
14
+ /**
15
+ * Every environment variable phantom reads. The Environment section of HELP is
16
+ * built from this list.
17
+ */
18
+ export declare const ENV_VARS: readonly EnvVar[];
19
+ /** Full command reference, printed by `phantom --help --all`. */
20
+ export declare const HELP: string;
21
+ /**
22
+ * The help printed by default: each command in one line, under a heading for
23
+ * what it's for, so it fits on one screen. The three agents share one row.
24
+ * `phantom <command> --help` and `--help --all` keep the full usage.
25
+ */
26
+ export declare const PRIMARY_HELP: string;
package/dist/cli/help.mjs CHANGED
@@ -10,8 +10,10 @@ export const ENV_VARS = [
10
10
  { name: 'PHANTOM_BASE_URL', about: `API base, https:// only (default ${DEFAULT_BASE_URL})` },
11
11
  { name: 'PHANTOM_STATE_DIR', about: 'where phantom keeps keys (default ~/.config/phantom-key)' },
12
12
  { name: 'PHANTOM_KEYCHAIN', about: '0 saves keys to files instead of the macOS Keychain; 1 uses the Keychain on any system, which fails where /usr/bin/security is missing' },
13
- { name: 'PAI_KEYCHAIN', about: 'The old name of PHANTOM_KEYCHAIN, read when PHANTOM_KEYCHAIN is unset' },
13
+ { name: 'PAI_KEYCHAIN', about: 'the old name of PHANTOM_KEYCHAIN, read when PHANTOM_KEYCHAIN is unset' },
14
14
  ];
15
+ /** The first line of both helps: what phantom is for. */
16
+ const TITLE = 'phantom: points your coding agents at Phantom AI';
15
17
  function envHelp() {
16
18
  const width = Math.max(...ENV_VARS.map((v) => v.name.length)) + 2;
17
19
  const lines = ENV_VARS.map((v) => ` ${v.name.padEnd(width)}${v.about}${v.envOnly ? ' (environment only)' : ''}`);
@@ -19,15 +21,16 @@ function envHelp() {
19
21
  }
20
22
  /** Full command reference, printed by `phantom --help --all`. */
21
23
  export const HELP = `
22
- phantom — points your coding agents at Phantom AI
24
+ ${TITLE}
23
25
 
24
26
  Commands:
25
27
  ${COMMANDS.map((command) => command.help).join('\n')}
26
28
 
27
29
  Flags:
28
- --table human-readable output instead of JSON
30
+ --table draw the screen for people, even in a pipe
31
+ --json print JSON, even at a terminal
29
32
  --help, -h print help and run nothing
30
- --all include advanced commands in help
33
+ --all with --help, also list the advanced commands
31
34
  --version, -v print the version
32
35
 
33
36
  ${envHelp()}
@@ -43,7 +46,7 @@ const helpRow = (name, summary) => ` ${name.padEnd(20)}${summary}`;
43
46
  * `phantom <command> --help` and `--help --all` keep the full usage.
44
47
  */
45
48
  export const PRIMARY_HELP = [
46
- 'phantom — points your coding agents at Phantom AI',
49
+ TITLE,
47
50
  '',
48
51
  ...HELP_GROUPS.flatMap((group) => {
49
52
  const shown = COMMANDS.filter((command) => command.group === group && !command.advanced).sort((a, b) => rank(a.name) - rank(b.name));
@@ -54,5 +57,6 @@ export const PRIMARY_HELP = [
54
57
  return rows.length ? [group.toUpperCase(), ...rows, ''] : [];
55
58
  }),
56
59
  'phantom <command> --help shows its flags. phantom --help --all lists every flag,',
57
- 'the advanced commands (receipts and verification) and the environment variables.',
60
+ 'the advanced commands (verify, for receipts, and the older key commands) and the',
61
+ 'environment variables.',
58
62
  ].join('\n');
@@ -0,0 +1,2 @@
1
+ import { type CommandInput } from '../core/helpers.mts';
2
+ export declare function run(argv?: string[], env?: Record<string, string | undefined>, io?: CommandInput['io'], node?: string): Promise<number>;
@@ -0,0 +1,171 @@
1
+ import type { Env } from '../core/state.mts';
2
+ import { type Paint } from '../core/style.mts';
3
+ import type { BalanceResult } from '../core/shapes.mts';
4
+ import type { SpendResult } from '../spend/report.mts';
5
+ import { type ModelsView } from '../models/list.mts';
6
+ /** How a screen is drawn: its environment (for colors), whether to color it, and the window's width. */
7
+ export type ScreenStyle = {
8
+ env?: Env;
9
+ color?: boolean;
10
+ columns?: number;
11
+ };
12
+ /** Dollars as people read them: two decimals, or four under a cent so small spend doesn't read as $0.00. */
13
+ export declare function usd(n: number): string;
14
+ /** True while the app runs, so a screen can point at a menu item instead of a command. */
15
+ export declare const inApp: () => boolean;
16
+ /** Hides or shows every screen's "→ type this next" line, and returns what it was, to put back after. The app hides them while it runs. */
17
+ export declare function hideHints(hidden: boolean): boolean;
18
+ /** A thin bar `width` cells long at `share` of full (0 to 1), in `fill`, on a dimmed track: the site's cost bars. */
19
+ export declare function bar(p: Paint, share: number, width: number, fill: (s: string) => string): string;
20
+ /** `phantom balance`: the credit in bold, then what it spent and when the key stops working. */
21
+ export declare function balanceScreen(b: BalanceResult, style?: ScreenStyle): string;
22
+ /**
23
+ * `phantom spend`: the total, what phantom-1 saved, the site's two bars (what
24
+ * the calls cost against what the same calls cost on the frontier model), then
25
+ * each model and each key with a bar for its share.
26
+ */
27
+ export declare function spendScreen(s: SpendResult, style?: ScreenStyle): string;
28
+ /** A key in the workspace view, as the API returns it. */
29
+ type WorkspaceKey = {
30
+ id?: string;
31
+ name?: string;
32
+ prefix?: string;
33
+ is_active?: boolean;
34
+ spent_usd?: number;
35
+ limit_usd?: number | null;
36
+ budget_usd?: number | null;
37
+ period_days?: number | null;
38
+ };
39
+ /** The workspace view from `GET /workspaces/{id}`, the parts these screens read. */
40
+ export type WorkspaceView = {
41
+ name?: string;
42
+ balance_usd: number;
43
+ held_usd?: number;
44
+ account_linked?: boolean;
45
+ keys: WorkspaceKey[];
46
+ charges?: Array<{
47
+ model?: string;
48
+ cost_usd?: number;
49
+ why?: string | null;
50
+ }>;
51
+ };
52
+ /** `phantom workspace`: the shared balance, each key, and the last few charges. */
53
+ export declare function workspaceScreen(view: WorkspaceView, style?: ScreenStyle): string;
54
+ /** `phantom keys`: the workspace's keys alone. */
55
+ export declare function keysScreen(keys: WorkspaceKey[], style?: ScreenStyle): string;
56
+ /** After `phantom login`: signed in, where the key is kept, and the next step. */
57
+ export declare function signedInScreen(saved: {
58
+ saved_as: string;
59
+ storage: string;
60
+ }, style?: ScreenStyle): string;
61
+ /** `phantom login` when this computer already has a key: say so, then how to switch or add one. */
62
+ export declare function alreadySignedInScreen(keyIdShown: string | null, style?: ScreenStyle): string;
63
+ /** The parts of a route policy these screens read (the full type is in spend/routing.mts). */
64
+ type RouteView = {
65
+ route_policy: {
66
+ models: string[];
67
+ applies_to?: 'auto' | 'all';
68
+ on_empty?: 'stop' | 'cheapest';
69
+ fallback_on_error?: boolean;
70
+ stick_minutes?: number;
71
+ stick_by_prompt?: boolean;
72
+ rules?: Array<{
73
+ if: Record<string, unknown>;
74
+ use: string;
75
+ }>;
76
+ sort?: 'cost' | 'ttft' | 'tps';
77
+ zdr?: boolean;
78
+ no_training?: boolean;
79
+ } | null;
80
+ };
81
+ /** `phantom route`: which models "auto" picks from, what it does at the edges, and its rules, in sentences. */
82
+ export declare function routeScreen(r: RouteView, style?: ScreenStyle): string;
83
+ /** `phantom route test`: the model a request would run on right now, and why. */
84
+ export declare function routeTestScreen(t: {
85
+ model: string | null;
86
+ reason: string | null;
87
+ routed: boolean;
88
+ fallbacks?: string[];
89
+ }, style?: ScreenStyle): string;
90
+ /** The parts of a lineup these screens read (the full type is in spend/lineup.mts). */
91
+ export type LineupView = {
92
+ lineup: (Record<string, string | undefined> & {
93
+ fallbacks?: Record<string, string | undefined>;
94
+ }) | null;
95
+ tiers: Record<'economy' | 'standard' | 'frontier', {
96
+ model: string;
97
+ name: string;
98
+ }>;
99
+ choices?: Record<'economy' | 'standard' | 'frontier', Array<{
100
+ model: string;
101
+ name: string;
102
+ input_per_m: number | null;
103
+ output_per_m: number | null;
104
+ context: number | null;
105
+ default: boolean;
106
+ }>>;
107
+ };
108
+ /** What each tier is for, in a few words. */
109
+ export declare const TIER_ABOUT: {
110
+ readonly economy: "short, easy requests";
111
+ readonly standard: "everyday coding";
112
+ readonly frontier: "the hardest work";
113
+ };
114
+ /** `phantom lineup`: the model phantom-1 runs in each tier, whether it's the default or your pick, and its fallback. */
115
+ export declare function lineupScreen(l: LineupView, style?: ScreenStyle): string;
116
+ /** A model's price per million tokens, in and out, for a picker's hint. */
117
+ export declare function priceHint(c: {
118
+ input_per_m: number | null;
119
+ output_per_m: number | null;
120
+ context: number | null;
121
+ default: boolean;
122
+ }): string;
123
+ /** A link to open in the browser (Stripe Checkout, billing, a wallet), with what it's for and the next step. */
124
+ export declare function linkScreen(words: string, url: string, after: [string, string] | null, style?: ScreenStyle & {
125
+ opened?: boolean;
126
+ }): string;
127
+ /** `phantom fund`: the card checkout link, or the wallet payment link with its id to check on. */
128
+ export declare function fundScreen(f: {
129
+ payment_id?: string;
130
+ checkout_url?: string;
131
+ amount_cents?: number;
132
+ solana_pay_url?: string;
133
+ payment_url?: string;
134
+ coin?: string;
135
+ amount?: number | string;
136
+ expires_at?: string;
137
+ }, style?: ScreenStyle & {
138
+ opened?: boolean;
139
+ }): string;
140
+ /** `phantom workspace payment`: whether a payment has come in. */
141
+ export declare function paymentScreen(pay: {
142
+ payment_id: string;
143
+ status: string;
144
+ credit_usd?: number;
145
+ }, style?: ScreenStyle): string;
146
+ /** What a key change did: created, rotated, revoked or updated, and what to do next. */
147
+ export declare function keyChangeScreen(change: 'created' | 'rotated' | 'revoked' | 'updated', name: string | null, style?: ScreenStyle & {
148
+ storage?: string;
149
+ limit?: number | null;
150
+ }): string;
151
+ /** `phantom logout`: signed out on this computer, or nothing to sign out of. */
152
+ export declare function logoutScreen(removed: boolean, style?: ScreenStyle & {
153
+ kept?: string[];
154
+ removedNamed?: string[];
155
+ }): string;
156
+ /** `phantom keys saved`: the keys saved on this computer, by name. */
157
+ export declare function savedKeysScreen(keys: Array<{
158
+ name: string;
159
+ id: string;
160
+ active?: boolean;
161
+ credit_balance_usd?: number;
162
+ }>, style?: ScreenStyle): string;
163
+ /** `phantom keys save <name>`: the key is saved under its name, and how to run an agent on it. */
164
+ export declare function keySavedScreen(name: string, style?: ScreenStyle): string;
165
+ /**
166
+ * `phantom models`: a table of what each of Phantom's own models can do, a
167
+ * column per model, a ✓ per job. Under it, the model behind each job, so you
168
+ * can see what runs before you pick.
169
+ */
170
+ export declare function modelsScreen(v: ModelsView, style?: ScreenStyle): string;
171
+ export {};
@@ -156,7 +156,7 @@ export function workspaceScreen(view, style = {}) {
156
156
  export function keysScreen(keys, style = {}) {
157
157
  const p = paint(style.env ?? {}, Boolean(style.color));
158
158
  const w = ruleWidth(style);
159
- return ['', ...caption(p, w, 'KEYS', p.dim(String(keys.length))), ...keyRows(p, keys), ...next(p, 'Set a spending limit:', 'phantom keys set --id <name or id> --limit <USD>')].join('\n');
159
+ return ['', ...caption(p, w, 'KEYS', p.dim(String(keys.length))), ...keyRows(p, keys), ...next(p, 'Cap what a key can spend:', 'phantom keys set --id <name or id> --limit <USD>')].join('\n');
160
160
  }
161
161
  /** After `phantom login`: signed in, where the key is kept, and the next step. */
162
162
  export function signedInScreen(saved, style = {}) {
@@ -267,7 +267,7 @@ export function fundScreen(f, style = {}) {
267
267
  }
268
268
  const p = paint(style.env ?? {}, Boolean(style.color));
269
269
  const w = ruleWidth(style);
270
- return [linkScreen(`Pay ${f.amount ?? ''} ${(f.coin ?? '').toUpperCase()} from your wallet`.replace(/\s+/g, ' '), f.payment_url ?? f.solana_pay_url ?? '', null, style), ` ${p.dim('payment')} ${f.payment_id ?? ''}${f.expires_at ? p.dim(` · good until ${day(f.expires_at)}`) : ''}`, ...next(p, 'Check it landed:', `phantom workspace payment --id ${f.payment_id ?? '<id>'}`)].join('\n');
270
+ return [linkScreen(`Pay ${f.amount ?? ''} ${(f.coin ?? '').toUpperCase()} from your wallet`.replace(/\s+/g, ' '), f.payment_url ?? f.solana_pay_url ?? '', null, style), ` ${p.dim('payment')} ${f.payment_id ?? ''}${f.expires_at ? p.dim(` · good until ${day(f.expires_at)}`) : ''}`, ...next(p, 'See whether it arrived:', `phantom workspace payment --id ${f.payment_id ?? '<id>'}`)].join('\n');
271
271
  }
272
272
  /** `phantom workspace payment`: whether a payment has come in. */
273
273
  export function paymentScreen(pay, style = {}) {
@@ -350,7 +350,7 @@ export function modelsScreen(v, style = {}) {
350
350
  // Padding goes outside the color, so the row's trailing spaces can be trimmed.
351
351
  const cell = (text, color) => color(text) + ' '.repeat(Math.max(0, COLUMN - text.length));
352
352
  const row = (label, cells) => ` ${label.padEnd(LABEL)}${cells.join('')}`.trimEnd();
353
- const lines = ['', ...caption(p, ruleWidth(style), 'MODELS', p.dim('one name each; your agents send it'))];
353
+ const lines = ['', ...caption(p, ruleWidth(style), 'MODELS', p.dim('each is a model name your agents can send'))];
354
354
  lines.push(row('', v.models.map((m) => cell(m.id, p.bold))));
355
355
  lines.push(row('', v.models.map((m) => cell(m.id === v.using ? 'in use' : '', p.lime))));
356
356
  for (const [job, label] of JOBS) {
@@ -0,0 +1,34 @@
1
+ import type { Env } from '../core/state.mts';
2
+ import type { Choice } from '../core/pick.mts';
3
+ /**
4
+ * The start screen. `signedIn` is whether a key is saved or set, so it shows
5
+ * the first step or the everyday commands.
6
+ */
7
+ export declare function startScreen(env: Env, color: boolean, signedIn: boolean): string;
8
+ /**
9
+ * How many single-letter edits turn `a` into `b`: a letter added, removed or
10
+ * changed, or two neighbours swapped ("yse" is one edit from "yes").
11
+ */
12
+ export declare function editDistance(a: string, b: string): number;
13
+ /**
14
+ * The command `typed` was most likely meant to be: the nearest name at most
15
+ * two edits away, or null. On a tie, the one that starts with the same letter.
16
+ */
17
+ export declare function closestCommand(typed: string, names: readonly string[]): string | null;
18
+ /** The title block over the start menu: the ghost and PHANTOM. */
19
+ export declare function startHeader(env: Env, color: boolean): string;
20
+ /**
21
+ * The start menu's choices, each the command it runs. Without a key, setup
22
+ * comes first. Signed in but never set up, finishing setup comes first.
23
+ * Once set up, the agents and the money do, with undo near the end.
24
+ */
25
+ export declare function startChoices(signedIn: boolean, setUp?: boolean): Choice<string[]>[];
26
+ /** "Unknown <command> subcommand" with the nearest real one, or the list when nothing is close. */
27
+ export declare function unknownSub(command: string, typed: string, subs: readonly string[]): string;
28
+ /**
29
+ * Words people type instead of a command, and the command they mean. These
30
+ * run as that command, and stay out of --help.
31
+ */
32
+ export declare const ALIASES: Record<string, string[]>;
33
+ /** The command a sentence most likely means, from the first word in it that points at one, or null. */
34
+ export declare function commandFromWords(words: string[]): string | null;
@@ -0,0 +1,12 @@
1
+ import type { Paint } from './style.mts';
2
+ /** The ghost in block characters: white, eyes set to the right, a wavy hem, and a thin mint edge on its right side. */
3
+ export declare const GHOST: Array<[body: string, rim: string]>;
4
+ export declare const WORDMARK: string[];
5
+ /** The one line that says what phantom does, everywhere the CLI describes itself. */
6
+ export declare const TAGLINE = "Points your coding agents at Phantom AI.";
7
+ /**
8
+ * A screen's title block: the ghost, PHANTOM beside it, and `label` in lime
9
+ * with `line` along the ghost's hem. For example `setup Points your coding
10
+ * agents at Phantom AI.` Without color, a plain one-line title instead.
11
+ */
12
+ export declare function brandHeader(p: Paint, color: boolean, label: string, line?: string): string[];
@@ -0,0 +1,27 @@
1
+ /** An error answer from the Phantom AI API: 401 or 403 maps to exit code 2. */
2
+ export declare class PhantomApiError extends Error {
3
+ /** The HTTP status code of the answer. */
4
+ readonly status: number;
5
+ /** The API's error code, or the status code as text when the answer carries none. */
6
+ readonly code: string;
7
+ constructor(status: number, code: string, message: string);
8
+ }
9
+ /** An error phantom raises itself, such as a missing flag or a refused payment. */
10
+ export declare class CliError extends Error {
11
+ /** A short code for the error, such as `keychain_failed`. `cli_error` when none is given. */
12
+ readonly code: string;
13
+ /** The process exit code {@link run} returns for it. 1 unless given. */
14
+ readonly exitCode: number;
15
+ constructor(message: string, code?: string, exitCode?: number);
16
+ }
17
+ /**
18
+ * Throws a {@link CliError}. Every refusal in phantom goes through here.
19
+ * @param msg The message the user sees.
20
+ * @param code The error code, printed in the JSON error.
21
+ * @param exitCode The process exit code.
22
+ */
23
+ export declare function die(msg: string, code?: string, exitCode?: number): never;
24
+ /** How to get a key, for every message about a missing one. */
25
+ export declare const GET_A_KEY = "Run phantom login to sign in, or set PHANTOM_API_KEY.";
26
+ /** The message for a command that needs a key and has none. */
27
+ export declare const NO_KEY = "No Phantom key yet. Run phantom login to sign in, or set PHANTOM_API_KEY.";
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Free phantom-1 requests a workspace gets each UTC day, before it has had $10
3
+ * of credit. Phantom's own limit is `FREE_ROUTER_CAPS.perDay` in the Phantom
4
+ * repo's `lib/config.ts`; change both together.
5
+ */
6
+ export declare const FREE_REQUESTS_A_DAY = 50;
7
+ /** The same, for requests a coding agent sends (`FREE_ROUTER_CAPS.perDayAgent` in the Phantom repo). */
8
+ export declare const FREE_AGENT_REQUESTS_A_DAY = 200;
9
+ /**
10
+ * The free offer in one line short enough for an 80-column terminal. It names
11
+ * the coding-agent limit, since the CLI sets up and starts agents.
12
+ */
13
+ export declare const FREE_LINE = "phantom-1 runs free models, 200 a day from agents, no card";