@phantomcodes/cli 1.6.2 → 1.7.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.
Files changed (139) hide show
  1. package/README.md +138 -117
  2. package/bin/phantom.mjs +37 -2
  3. package/dist/agents/command.d.mts +8 -27
  4. package/dist/agents/command.mjs +323 -59
  5. package/dist/agents/login.d.mts +3 -0
  6. package/dist/agents/login.mjs +97 -0
  7. package/dist/agents/opencode-check.d.mts +15 -0
  8. package/dist/agents/opencode-check.mjs +193 -0
  9. package/dist/agents/phantom-key.d.mts +7 -0
  10. package/dist/agents/phantom-key.mjs +40 -0
  11. package/dist/agents/proxy.d.mts +26 -28
  12. package/dist/agents/proxy.mjs +225 -33
  13. package/dist/chatgpt/command.d.mts +2 -0
  14. package/dist/chatgpt/command.mjs +119 -0
  15. package/dist/chatgpt/session.d.mts +87 -0
  16. package/dist/chatgpt/session.mjs +253 -0
  17. package/dist/cli/accounts.d.mts +21 -0
  18. package/dist/cli/accounts.mjs +96 -0
  19. package/dist/cli/app.d.mts +4 -24
  20. package/dist/cli/app.mjs +224 -139
  21. package/dist/cli/commands.d.mts +1 -16
  22. package/dist/cli/commands.mjs +144 -239
  23. package/dist/cli/help.d.mts +0 -19
  24. package/dist/cli/help.mjs +30 -55
  25. package/dist/cli/run.mjs +35 -79
  26. package/dist/cli/start.d.mts +2 -31
  27. package/dist/cli/start.mjs +13 -116
  28. package/dist/core/brand.d.mts +0 -7
  29. package/dist/core/brand.mjs +0 -8
  30. package/dist/core/errors.d.mts +0 -16
  31. package/dist/core/errors.mjs +0 -16
  32. package/dist/core/helpers.d.mts +0 -46
  33. package/dist/core/helpers.mjs +1 -64
  34. package/dist/core/node-trust.d.mts +0 -5
  35. package/dist/core/node-trust.mjs +0 -6
  36. package/dist/core/pick.d.mts +7 -55
  37. package/dist/core/pick.mjs +49 -106
  38. package/dist/core/request.d.mts +0 -46
  39. package/dist/core/request.mjs +1 -60
  40. package/dist/core/secrets.d.mts +0 -4
  41. package/dist/core/secrets.mjs +0 -10
  42. package/dist/core/state.d.mts +3 -1
  43. package/dist/core/state.mjs +147 -4
  44. package/dist/core/style.d.mts +0 -27
  45. package/dist/core/style.mjs +0 -20
  46. package/dist/core/version.d.mts +1 -2
  47. package/dist/core/version.mjs +1 -2
  48. package/dist/local/accounts.d.mts +25 -0
  49. package/dist/local/accounts.mjs +40 -0
  50. package/dist/local/agent-headers.d.mts +7 -0
  51. package/dist/local/agent-headers.mjs +44 -0
  52. package/dist/local/chatgpt-plan.d.mts +147 -0
  53. package/dist/local/chatgpt-plan.mjs +384 -0
  54. package/dist/local/command.d.mts +24 -0
  55. package/dist/local/command.mjs +211 -0
  56. package/dist/local/config.d.mts +49 -0
  57. package/dist/local/config.mjs +168 -0
  58. package/dist/local/decide.d.mts +37 -0
  59. package/dist/local/decide.mjs +201 -0
  60. package/dist/local/failure-signs.d.mts +4 -0
  61. package/dist/local/failure-signs.mjs +99 -0
  62. package/dist/local/keys.d.mts +32 -0
  63. package/dist/local/keys.mjs +239 -0
  64. package/dist/local/models.d.mts +53 -0
  65. package/dist/local/models.mjs +117 -0
  66. package/dist/local/replay.d.mts +59 -0
  67. package/dist/local/replay.mjs +143 -0
  68. package/dist/local/report.d.mts +43 -0
  69. package/dist/local/report.mjs +153 -0
  70. package/dist/local/request-log.d.mts +53 -0
  71. package/dist/local/request-log.mjs +69 -0
  72. package/dist/local/retry-after.d.mts +3 -0
  73. package/dist/local/retry-after.mjs +28 -0
  74. package/dist/local/rust-router.d.mts +39 -0
  75. package/dist/local/rust-router.mjs +54 -0
  76. package/dist/local/server.d.mts +27 -0
  77. package/dist/local/server.mjs +449 -0
  78. package/dist/local/status-line.d.mts +17 -0
  79. package/dist/local/status-line.mjs +81 -0
  80. package/dist/local/tiers.d.mts +3 -0
  81. package/dist/local/tiers.mjs +137 -0
  82. package/dist/local/traces.d.mts +69 -0
  83. package/dist/local/traces.mjs +341 -0
  84. package/dist/phantom.d.mts +0 -37
  85. package/dist/phantom.mjs +0 -31
  86. package/package.json +15 -9
  87. package/skills/phantom-ai/SKILL.md +28 -97
  88. package/dist/cli/screens.d.mts +0 -177
  89. package/dist/cli/screens.mjs +0 -398
  90. package/dist/core/free.d.mts +0 -13
  91. package/dist/core/free.mjs +0 -14
  92. package/dist/core/motion.d.mts +0 -47
  93. package/dist/core/motion.mjs +0 -156
  94. package/dist/core/shapes.d.mts +0 -13
  95. package/dist/core/shapes.mjs +0 -1
  96. package/dist/keys/command.d.mts +0 -16
  97. package/dist/keys/command.mjs +0 -143
  98. package/dist/keys/saved.d.mts +0 -96
  99. package/dist/keys/saved.mjs +0 -169
  100. package/dist/models/choice.d.mts +0 -7
  101. package/dist/models/choice.mjs +0 -27
  102. package/dist/models/command.d.mts +0 -8
  103. package/dist/models/command.mjs +0 -66
  104. package/dist/models/list.d.mts +0 -39
  105. package/dist/models/list.mjs +0 -39
  106. package/dist/receipts/command.d.mts +0 -7
  107. package/dist/receipts/command.mjs +0 -41
  108. package/dist/receipts/receipts.d.mts +0 -76
  109. package/dist/receipts/receipts.mjs +0 -114
  110. package/dist/setup/agents.d.mts +0 -149
  111. package/dist/setup/agents.mjs +0 -886
  112. package/dist/setup/apply.d.mts +0 -85
  113. package/dist/setup/apply.mjs +0 -301
  114. package/dist/setup/command.d.mts +0 -12
  115. package/dist/setup/command.mjs +0 -307
  116. package/dist/setup/editors.d.mts +0 -108
  117. package/dist/setup/editors.mjs +0 -500
  118. package/dist/setup/legacy.d.mts +0 -13
  119. package/dist/setup/legacy.mjs +0 -36
  120. package/dist/setup/plan.d.mts +0 -104
  121. package/dist/setup/plan.mjs +0 -132
  122. package/dist/setup/screen.d.mts +0 -30
  123. package/dist/setup/screen.mjs +0 -260
  124. package/dist/setup/shared.d.mts +0 -141
  125. package/dist/setup/shared.mjs +0 -88
  126. package/dist/setup/was.d.mts +0 -42
  127. package/dist/setup/was.mjs +0 -91
  128. package/dist/spend/command.d.mts +0 -5
  129. package/dist/spend/command.mjs +0 -235
  130. package/dist/spend/lineup.d.mts +0 -61
  131. package/dist/spend/lineup.mjs +0 -39
  132. package/dist/spend/reason.d.mts +0 -5
  133. package/dist/spend/reason.mjs +0 -60
  134. package/dist/spend/report.d.mts +0 -105
  135. package/dist/spend/report.mjs +0 -68
  136. package/dist/spend/routing.d.mts +0 -74
  137. package/dist/spend/routing.mjs +0 -57
  138. package/dist/workspace/command.d.mts +0 -59
  139. package/dist/workspace/command.mjs +0 -871
@@ -1,244 +1,149 @@
1
- import { workspaceCommand, workspaceLogin, forgetWorkspace } from "../workspace/command.mjs";
2
1
  import { agentCommand } from "../agents/command.mjs";
3
- import { balanceCommand, keyCommand, loginCommand, logoutCommand } from "../keys/command.mjs";
4
- import { lineupCommand, routeCommand } from "../spend/command.mjs";
5
- import { spendCommand } from "../spend/report.mjs";
6
- import { verifyCommand } from "../receipts/command.mjs";
7
- import { setupCommand } from "../setup/command.mjs";
8
- import { SETUP_MODEL } from "../setup/shared.mjs";
9
- import { modelsCommand } from "../models/command.mjs";
10
- import { SETUP_NAMES } from "../setup/agents.mjs";
11
- /** The short `--help`'s headings, in the order they print. */
12
- export const HELP_GROUPS = ['Start', 'Run', 'Money', 'Keys', 'Routing', 'More'];
13
- async function loginDispatch(input) {
14
- const { subcommand, flags } = input;
15
- // `phantom login google` or `login github`: a word that isn't a key means the usual browser sign-in, not "that is not a key".
16
- if (subcommand && !subcommand.startsWith('sk-'))
17
- return workspaceLogin({ ...input, subcommand: undefined });
18
- return subcommand || flags.paste ? loginCommand(input) : workspaceLogin(input);
19
- }
20
- async function logoutDispatch(input) {
21
- const forgot = await forgetWorkspace(input.env, input.baseUrl);
22
- return logoutCommand(input, forgot);
23
- }
24
- async function fundDispatch(input) {
25
- const { flags } = input;
26
- void flags.amount;
27
- void flags.card;
28
- void flags.coin;
29
- void flags['no-browser'];
30
- return workspaceCommand({ ...input, subcommand: 'fund' });
31
- }
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
- */
2
+ import { loginCommand, logoutCommand } from "../agents/login.mjs";
3
+ import { configCommand, replayCommand, reportCommand } from "../local/command.mjs";
37
4
  export const COMMANDS = [
38
5
  {
39
- name: 'login', handler: loginDispatch, keyless: true,
40
- group: 'Start', summary: 'sign in only, or save a Phantom key you already have',
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`,
47
- },
48
- {
49
- name: 'workspace', handler: workspaceCommand, keyless: true,
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; the start of the id
61
- (4 or more characters) is enough
62
- workspace delete [--yes] delete an empty workspace and forget it here
63
- (--yes: don't ask)`,
64
- },
65
- {
66
- name: 'fund', handler: fundDispatch, keyless: true,
67
- group: 'Money', summary: 'add credit by card or crypto',
68
- help: ` fund --amount <USD> [--card | --coin usdc|usdc-base] [--no-browser]
69
- add credit to your workspace by card (plus
70
- Stripe's fee), or USDC on Solana (usdc) or Base
71
- (usdc-base); pick one of --card and --coin;
72
- --no-browser prints the link`,
73
- },
74
- {
75
- name: 'keys', handler: workspaceCommand, keyless: true,
76
- group: 'Keys', summary: "your workspace's keys: list, create, set limits, revoke",
77
- help: ` keys [list] the workspace's keys: name, id, spend and limit;
78
- never the keys themselves
79
- keys create [--save <name>] [--limit <USD|none>]
80
- make a key and save it on this computer; --limit
81
- caps what it can spend in total
82
- keys set --id <id> [--limit <USD|none>] [--budget <USD|none>]
83
- [--period <days|none>] [--rate <USD|none>] [--name <name>]
84
- [--policy-file <path> | --clear-policy]
85
- change a key: its total limit, a budget for each
86
- period of days, dollars a minute, its name or
87
- its route policy
88
- keys rotate --id <id> [--save <name>]
89
- swap a key for a new one with the same settings;
90
- the old one stops working, and the copy saved
91
- here is replaced
92
- keys revoke --id <id> [--yes] turn a key off for good; its credit stays in the
93
- workspace (--yes: don't ask)
94
- keys saved [--balance] the keys saved on this computer (--balance adds
95
- each one's credit)
96
- keys save <name> [key] check a key and save it by name; it asks for the
97
- key when you leave it out
98
- keys show [name] print a saved key, for PHANTOM_API_KEY=$(...) in
99
- a shell; keep it out of chat and logs
100
- keys show [name] --copy copy it to the clipboard instead (Mac), for an
101
- app's settings
102
- keys rm <name> forget a key saved here; the key keeps working`,
103
- },
104
- {
105
- name: 'claude', handler: agentCommand, keyless: true,
106
- group: 'Run', summary: 'start Claude Code on Phantom AI',
107
- help: ` claude [--key <name>] [--no-browser] -- <agent arguments>
108
- start Claude Code on Phantom AI; --key picks a
109
- key saved by name`,
110
- },
111
- {
112
- name: 'codex', handler: agentCommand, keyless: true,
113
- group: 'Run', summary: 'start Codex on Phantom AI',
114
- help: ` codex [--key <name>] [--no-browser] -- <agent arguments>
115
- start Codex on Phantom AI; --key picks a key
116
- saved by name`,
117
- },
118
- {
119
- name: 'pi', handler: agentCommand, keyless: true,
120
- group: 'Run', summary: 'start pi on Phantom AI',
121
- help: ` pi [--key <name>] [--no-browser] -- <agent arguments>
122
- start pi on Phantom AI; --key picks a key saved
123
- by name`,
124
- },
125
- {
126
- name: 'balance', handler: balanceCommand,
127
- group: 'Money', summary: 'your credit, and when it expires',
128
- help: ` balance what this key can spend, and when it expires`,
129
- },
130
- {
131
- name: 'spend', handler: spendCommand, keyless: ['--workspace'],
132
- group: 'Money', summary: 'what you spent, and what phantom-1 saved',
133
- help: ` spend [--from <date>] [--to <date>]
134
- what this key spent, by model and day, and what
135
- phantom-1 saved; dates are UTC days as
136
- YYYY-MM-DD, this month by default
137
- spend --workspace every key in the workspace by name (needs
138
- phantom login)`,
139
- },
140
- {
141
- name: 'key', advanced: true, handler: keyCommand, keyless: true,
142
- group: 'More', summary: 'older names for keys saved, save, show and rm',
143
- help: ` key list | save | show | rm older names for keys saved, keys save, keys show, keys rm
144
- key list [--balance] saved keys, by name and id
145
- key save <name> [key] save a key by name (prompts if no key is given)
146
- key show [name] print a saved key, for PHANTOM_API_KEY=$(...);
147
- with no name, the key phantom is using
148
- key rm <name> forget a saved key (the key keeps working)`,
149
- },
150
- {
151
- name: 'route', handler: routeCommand,
152
- group: 'Routing', summary: 'which models "auto" runs, and rules for picking',
153
- help: ` route [get] which model "auto" runs for this key, and why
154
- route set --sort fast|cheap|throughput|default
155
- which providers serve this key's models first:
156
- fast starts answering soonest, throughput sends
157
- the most tokens a second, cheap costs least and
158
- is the default; default goes back to cheap
159
- route set --models a,b,c the models "auto" picks from; the first is the
160
- default
161
- [--applies-to auto|all] all: route requests that name a model too
162
- [--on-empty stop|cheapest]
163
- when the cap is used up: refuse requests, or
164
- run them on the cheapest model
165
- [--fallback] try the next model when one fails
166
- [--stick-minutes n] keep a conversation on its model this long
167
- (default 5)
168
- [--stick-by-prompt false]
169
- only x-phantom-session marks a conversation
170
- route set --file policy.json replace the whole policy
171
- route rule add --if <name=value> --use <model|cheapest|first|next> [--at n]
172
- conditions: pace, budget_left_pct_below,
173
- days_left_below, has_tools, input_tokens_over,
174
- reasoning_requested
175
- route rule rm <n> remove rule n
176
- route test [--model auto] which model a request would get now (free)
177
- route clear remove the policy`,
178
- },
179
- {
180
- name: 'lineup', handler: lineupCommand,
181
- group: 'Routing', summary: 'the model phantom-1 runs in each tier',
182
- help: ` lineup [get] the model phantom-1 runs in each tier, and the
183
- models you can pick from
184
- lineup set --standard <model> pick the model for a tier; "default" puts the
185
- [--frontier <model>] tier back to its default
186
- [--standard-fallback <model>]
187
- [--frontier-fallback <model>]
188
- the model to try when a tier's model fails
189
- lineup reset every tier back to its default`,
190
- },
191
- {
192
- name: 'models', handler: modelsCommand, keyless: true,
193
- group: 'Routing', summary: 'phantom-1, free or zdr: what each can do, and which your agents use',
194
- help: ` models what phantom-1, phantom-1:free and phantom-1:zdr
195
- can do, and the model behind each job; at a
196
- terminal, pick one
197
- models use <id> start your agents on it, without the menu`,
198
- },
199
- {
200
- name: 'logout', handler: logoutDispatch, keyless: true,
201
- group: 'More', summary: 'sign out on this computer',
202
- help: ` logout sign out: forget workspace access and the
203
- default saved key
204
- logout --all also forget every key saved here by name`,
205
- },
206
- {
207
- name: 'setup', handler: setupCommand, keyless: true,
208
- group: 'Start', summary: 'sign in and connect your coding agents',
209
- help: ` setup find your agents, install the skill in each, and
210
- point their model calls at Phantom AI; it shows
211
- each file's changes and asks first. With no key
212
- yet, it signs you in first (at a terminal)
213
- [--yes] don't ask
214
- [--no-browser] print the sign-in link instead of opening it
215
- [--dry-run] show the changes without making them
216
- [--diff] show every line each file gains or loses
217
- [--no-shell] leave your shell startup file alone and print
218
- the lines to add yourself
219
- [--limit <USD|none>] cap what this key can spend each month
220
- [--json] print JSON at a terminal too (a pipe always gets JSON)
221
- [--model <id>] the model each agent starts on (default ${SETUP_MODEL})
222
- setup --agent <name> install the skill for one agent, without asking:
223
- ${SETUP_NAMES.join(', ')} or all
224
- setup [--agent <name>] --provider point that agent's model calls at Phantom AI;
225
- --provider off takes phantom's settings out and
226
- puts back what they replaced
227
- setup --restore [--agent <name>] put back the files setup changed, from the
228
- .phantom.bak copies it kept. A file you
229
- edited since keeps your edits: only
230
- Phantom's own lines come out. It also
231
- removes the settings.json.bak copy setup
232
- made for Claude Code and Gemini`,
233
- },
234
- {
235
- name: 'verify', advanced: true, handler: verifyCommand, keyless: ['--receipt'],
236
- group: 'More', summary: 'check a signed receipt',
237
- help: ` verify --model <id> make one small call and check that its signed
238
- receipt names the model you asked for (costs a
239
- fraction of a cent). For phantom-1, phantom-1:free,
240
- phantom-1:zdr or auto it checks the receipt's
241
- requested model, since the model that ran varies
242
- verify --receipt <receipt> check a receipt you already have`,
6
+ name: 'pi', handler: agentCommand,
7
+ summary: 'start pi, routed on this computer by phantom-1',
8
+ help: ` pi [--server] [--key <name>] -- <pi arguments>
9
+ start pi. With routing set up (phantom config),
10
+ phantom-1 on this computer sends each request to
11
+ the account and model local.json names for its
12
+ tier. --server sends it through Phantom's server
13
+ instead, on PHANTOM_API_KEY; --key picks a key an
14
+ older phantom saved by name. phantom/phantom-1
15
+ joins your pi model scope for the run. Ctrl+S
16
+ in /scoped-models saves it into pi's
17
+ settings.json; remove it there for plain pi`,
18
+ },
19
+ {
20
+ name: 'opencode', handler: agentCommand,
21
+ summary: 'start OpenCode, routed on this computer by phantom-1',
22
+ help: ` opencode [--server] [--key <name>] -- <opencode arguments>
23
+ start OpenCode, the same way phantom pi starts
24
+ pi: with routing set up (phantom config),
25
+ phantom-1 on this computer sends each request to
26
+ the account and model local.json names for its
27
+ tier. OpenCode gets a provider for this run
28
+ only, and your OpenCode config file is left as
29
+ it is. phantom stops before starting it when
30
+ your OpenCode settings (in this folder, a
31
+ folder you name, or the folder of a session
32
+ named with -s) would let it call another
33
+ provider, even one with no key yet, or would
34
+ change the run's provider. Not covered:
35
+ OpenCode plugins run their own code and can
36
+ make their own calls, and config you change
37
+ during the run (opencode reload) isn't
38
+ checked. A later plain opencode -c, outside
39
+ phantom, continues on your own default model.
40
+ --server sends it through Phantom's server
41
+ instead, on PHANTOM_API_KEY. For one answer:
42
+ phantom opencode -- run "<prompt>"`,
43
+ },
44
+ {
45
+ name: 'codex', handler: agentCommand,
46
+ summary: "start Codex, through Phantom's server for now",
47
+ help: ` codex [--key <name>] -- <codex arguments>
48
+ start Codex through Phantom's server, on
49
+ PHANTOM_API_KEY (or --key, a key an older phantom
50
+ saved by name). With a ChatGPT sign-in (phantom
51
+ config), openai/ models run on your ChatGPT plan`,
52
+ },
53
+ {
54
+ name: 'claude', handler: agentCommand,
55
+ summary: "start Claude Code, through Phantom's server for now",
56
+ help: ` claude [--key <name>] -- <claude arguments>
57
+ start Claude Code through Phantom's server, on
58
+ PHANTOM_API_KEY (or --key, a key an older phantom
59
+ saved by name)`,
60
+ },
61
+ {
62
+ name: 'login', handler: loginCommand,
63
+ summary: 'sign in to Phantom and save your key',
64
+ help: ` login [--no-browser] sign in to Phantom in the browser and save your
65
+ Phantom key on this computer (the macOS Keychain
66
+ on a Mac). phantom prints a link and a code: check
67
+ the page shows the same code, then approve.
68
+ --no-browser only prints the link, so you can
69
+ open it on another device. phantom claude and
70
+ phantom codex run on this key, and start this
71
+ sign-in themselves when there is none`,
72
+ },
73
+ {
74
+ name: 'logout', handler: logoutCommand,
75
+ summary: 'remove the saved Phantom key from this computer',
76
+ help: ` logout remove the key phantom login saved from this
77
+ computer. The key still works until you revoke
78
+ it on the website (/keys)`,
79
+ },
80
+ {
81
+ name: 'config', handler: configCommand,
82
+ summary: 'Standard, Frontier and providers',
83
+ help: ` config the settings screen, at a terminal: Standard
84
+ and Frontier (one list of every connected
85
+ provider's models, and a fallback), and
86
+ Providers (ChatGPT, Z.ai and the Gateway: sign
87
+ in, or a key)
88
+
89
+ For scripts and agents:
90
+ config --standard <account>:<model> [--frontier <account>:<model>]
91
+ [--standard-fallback <account>:<model>|none]
92
+ [--frontier-fallback <account>:<model>|none]
93
+ set each tier's account and model, such as
94
+ --standard zai:glm-5.4; the model is checked
95
+ against the account's list
96
+ config --sensitivity balanced|conservative|strict
97
+ how soon the router moves a task up to
98
+ Frontier and how long it stays (default
99
+ balanced; strict moves up soonest), from
100
+ the next phantom pi
101
+ config --trial on|off when the router moves a task up to
102
+ Frontier, flip a coin: the task runs
103
+ there or stays on Standard, so whole
104
+ tasks can be compared (default off)
105
+ config --traces on|off save the full prompt and answer of every
106
+ request, on this computer only, in
107
+ local/traces beside local.json (off by
108
+ default), from the next phantom pi. They
109
+ hold your messages and code. Delete them
110
+ with rm -r on that folder
111
+ config show the tiers, where each key comes from and
112
+ whether it is found (never the key), and the
113
+ ChatGPT sign-in
114
+ config models [<account>] the models each account offers
115
+ config key set <account> [--stdin]
116
+ save an account's key in phantom (the macOS
117
+ Keychain on a Mac): asks with hidden typing,
118
+ or reads it from stdin with --stdin
119
+ config key use-keychain <account> --service <name> [--keychain-account <name>]
120
+ read the key from a Keychain item you already
121
+ have, without copying it (macOS)
122
+ config key rm <account> forget the account's key; a Keychain item stays
123
+ config chatgpt login [--no-browser] | logout
124
+ sign in with ChatGPT in the browser, so a tier
125
+ can run on your ChatGPT plan (--no-browser
126
+ prints the link), or sign out`,
127
+ },
128
+ {
129
+ name: 'report', handler: reportCommand,
130
+ summary: 'what routing did',
131
+ help: ` report [--since <when>] sum up the saved requests: tiers, each account
132
+ and model's tokens and times, reasons,
133
+ tasks, fallbacks and failures. <when>
134
+ is 1h, 1d, 7d or a date such as 2026-11-28`,
135
+ },
136
+ {
137
+ name: 'replay', handler: replayCommand,
138
+ summary: 'try other routing settings on saved traces',
139
+ help: ` replay [--since <when>] [--sensitivity balanced|conservative|strict]
140
+ [--max-move-up-tokens <n>]
141
+ run the saved traces (phantom config --traces
142
+ on) through phantom-1's tier decision again,
143
+ on this computer with no model calls: first
144
+ with the settings each was recorded with (a
145
+ self-check), then with the ones given. Prints
146
+ the requests that change tier and the Frontier
147
+ share before and after`,
243
148
  },
244
149
  ];
@@ -1,26 +1,7 @@
1
- /** One entry in {@link ENV_VARS}. */
2
1
  export type EnvVar = {
3
- /** The variable's name. */
4
2
  name: string;
5
- /** What it does, in a few words, for HELP and the reference. */
6
3
  about: string;
7
- /** Holds a secret: keep it out of files, logs and the model's context. */
8
4
  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
5
  };
14
- /**
15
- * Every environment variable phantom reads. The Environment section of HELP is
16
- * built from this list.
17
- */
18
6
  export declare const ENV_VARS: readonly EnvVar[];
19
- /** Full command reference, printed by `phantom --help --all`. */
20
7
  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
@@ -1,62 +1,37 @@
1
+ // docs: `phantom --help`: what phantom is for, one line per command, what it saves on this computer (the request log, and traces only when turned on), and every environment variable phantom reads (ENV_VARS). Each command's own usage is in commands.mts
1
2
  import { DEFAULT_BASE_URL } from "../core/request.mjs";
2
- import { COMMANDS, HELP_GROUPS } from "./commands.mjs";
3
- /**
4
- * Every environment variable phantom reads. The Environment section of HELP is
5
- * built from this list.
6
- */
3
+ import { COMMANDS } from "./commands.mjs";
7
4
  export const ENV_VARS = [
8
- { name: 'PHANTOM_API_KEY', about: 'your Phantom AI API key (or save one with login)', secret: true },
9
- { name: 'PHANTOM_KEY_NAME', about: 'run as a key saved with keys save; wins over PHANTOM_API_KEY' },
10
- { name: 'PHANTOM_BASE_URL', about: `API base, https:// only (default ${DEFAULT_BASE_URL})` },
11
- { name: 'PHANTOM_STATE_DIR', about: 'where phantom keeps keys (default ~/.config/phantom-key)' },
5
+ { name: 'PHANTOM_API_KEY', about: "a Phantom AI key, for codex, claude, and pi or opencode --server, on Phantom's server", secret: true },
6
+ { name: 'PHANTOM_KEY_NAME', about: 'use a key an older phantom saved by name; wins over PHANTOM_API_KEY' },
7
+ { name: 'PHANTOM_BASE_URL', about: `Phantom's server, https:// only (default ${DEFAULT_BASE_URL})` },
8
+ { name: 'PHANTOM_STATE_DIR', about: 'where phantom keeps local.json and keys (default ~/.config/phantom)' },
12
9
  { 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
10
  { name: 'PAI_KEYCHAIN', about: 'the old name of PHANTOM_KEYCHAIN, read when PHANTOM_KEYCHAIN is unset' },
11
+ { name: 'PHANTOM_ROUTER_DIR', about: 'a built routers/phantom-1/router/ folder, for phantom-1 to pick tiers with the router' },
14
12
  ];
15
- /** The first line of both helps: what phantom is for. */
16
- const TITLE = 'phantom: points your coding agents at Phantom AI';
17
- function envHelp() {
18
- const width = Math.max(...ENV_VARS.map((v) => v.name.length)) + 2;
19
- const lines = ENV_VARS.map((v) => ` ${v.name.padEnd(width)}${v.about}${v.envOnly ? ' (environment only)' : ''}`);
20
- return ['Environment:', ...lines].join('\n');
21
- }
22
- /** Full command reference, printed by `phantom --help --all`. */
23
- export const HELP = `
24
- ${TITLE}
25
-
26
- Commands:
27
- ${COMMANDS.map((command) => command.help).join('\n')}
28
-
29
- Flags:
30
- --table draw the screen for people, even in a pipe
31
- --json print JSON, even at a terminal
32
- --help, -h print help and run nothing
33
- --all with --help, also list the advanced commands
34
- --version, -v print the version
35
-
36
- ${envHelp()}
37
- `.trim();
38
- /** The order commands take inside their group in the short help: the one most people need first. Others follow in list order. */
39
- const FIRST = ['setup', 'login', 'claude', 'codex', 'pi', 'balance', 'fund', 'spend'];
40
- const rank = (name) => (FIRST.includes(name) ? FIRST.indexOf(name) : FIRST.length);
41
- /** One row of the short help: a command name in its column, then what it does. */
42
- const helpRow = (name, summary) => ` ${name.padEnd(20)}${summary}`;
43
- /**
44
- * The help printed by default: each command in one line, under a heading for
45
- * what it's for, so it fits on one screen. The three agents share one row.
46
- * `phantom <command> --help` and `--help --all` keep the full usage.
47
- */
48
- export const PRIMARY_HELP = [
49
- TITLE,
13
+ const row = (command, about) => ` ${command.padEnd(22)}${about}`;
14
+ export const HELP = [
15
+ 'phantom: routes your coding agents to your own accounts',
50
16
  '',
51
- ...HELP_GROUPS.flatMap((group) => {
52
- const shown = COMMANDS.filter((command) => command.group === group && !command.advanced).sort((a, b) => rank(a.name) - rank(b.name));
53
- const agents = shown.filter((command) => command.group === 'Run');
54
- const rows = group === 'Run'
55
- ? [helpRow(agents.map((command) => command.name).join(', '), 'start that agent on Phantom AI')]
56
- : shown.map((command) => helpRow(command.name, command.summary));
57
- return rows.length ? [group.toUpperCase(), ...rows, ''] : [];
58
- }),
59
- 'phantom <command> --help shows its flags. phantom --help --all lists every flag,',
60
- 'the advanced commands (verify, for receipts, and the older key commands) and the',
61
- 'environment variables.',
17
+ row('phantom', 'a list to pick from: start pi or OpenCode, Settings, or Report'),
18
+ ...COMMANDS.map((c) => row(`phantom ${c.name}`, c.summary)),
19
+ '',
20
+ 'phantom <command> --help shows its usage and flags.',
21
+ '',
22
+ 'What phantom saves, on this computer only, in ~/.config/phantom/local (or PHANTOM_STATE_DIR/local):',
23
+ ' requests.jsonl one line per request: tiers, models, times, tokens; never message text',
24
+ ' traces/ off unless you run phantom config --traces on: then, from the next',
25
+ ' phantom pi, the full prompt and answer of every request, your code',
26
+ ' included. --traces off stops it from the next phantom pi (one',
27
+ ' already running keeps saving); rm -r that folder deletes them',
28
+ '',
29
+ 'Flags:',
30
+ ' --table draw the screen for people, even in a pipe',
31
+ ' --json print JSON, even at a terminal',
32
+ ' --help, -h print help and run nothing',
33
+ ' --version, -v print the version',
34
+ '',
35
+ 'Environment:',
36
+ ...ENV_VARS.map((v) => ` ${v.name.padEnd(Math.max(...ENV_VARS.map((e) => e.name.length)) + 2)}${v.about}`),
62
37
  ].join('\n');