@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.
- package/README.md +138 -117
- package/bin/phantom.mjs +37 -2
- package/dist/agents/command.d.mts +8 -27
- package/dist/agents/command.mjs +323 -59
- package/dist/agents/login.d.mts +3 -0
- package/dist/agents/login.mjs +97 -0
- package/dist/agents/opencode-check.d.mts +15 -0
- package/dist/agents/opencode-check.mjs +193 -0
- package/dist/agents/phantom-key.d.mts +7 -0
- package/dist/agents/phantom-key.mjs +40 -0
- package/dist/agents/proxy.d.mts +26 -28
- package/dist/agents/proxy.mjs +225 -33
- package/dist/chatgpt/command.d.mts +2 -0
- package/dist/chatgpt/command.mjs +119 -0
- package/dist/chatgpt/session.d.mts +87 -0
- package/dist/chatgpt/session.mjs +253 -0
- package/dist/cli/accounts.d.mts +21 -0
- package/dist/cli/accounts.mjs +96 -0
- package/dist/cli/app.d.mts +4 -24
- package/dist/cli/app.mjs +224 -139
- package/dist/cli/commands.d.mts +1 -16
- package/dist/cli/commands.mjs +144 -239
- package/dist/cli/help.d.mts +0 -19
- package/dist/cli/help.mjs +30 -55
- package/dist/cli/run.mjs +35 -79
- package/dist/cli/start.d.mts +2 -31
- package/dist/cli/start.mjs +13 -116
- package/dist/core/brand.d.mts +0 -7
- package/dist/core/brand.mjs +0 -8
- package/dist/core/errors.d.mts +0 -16
- package/dist/core/errors.mjs +0 -16
- package/dist/core/helpers.d.mts +0 -46
- package/dist/core/helpers.mjs +1 -64
- package/dist/core/node-trust.d.mts +0 -5
- package/dist/core/node-trust.mjs +0 -6
- package/dist/core/pick.d.mts +7 -55
- package/dist/core/pick.mjs +49 -106
- package/dist/core/request.d.mts +0 -46
- package/dist/core/request.mjs +1 -60
- package/dist/core/secrets.d.mts +0 -4
- package/dist/core/secrets.mjs +0 -10
- package/dist/core/state.d.mts +3 -1
- package/dist/core/state.mjs +147 -4
- package/dist/core/style.d.mts +0 -27
- package/dist/core/style.mjs +0 -20
- package/dist/core/version.d.mts +1 -2
- package/dist/core/version.mjs +1 -2
- package/dist/local/accounts.d.mts +25 -0
- package/dist/local/accounts.mjs +40 -0
- package/dist/local/agent-headers.d.mts +7 -0
- package/dist/local/agent-headers.mjs +44 -0
- package/dist/local/chatgpt-plan.d.mts +147 -0
- package/dist/local/chatgpt-plan.mjs +384 -0
- package/dist/local/command.d.mts +24 -0
- package/dist/local/command.mjs +211 -0
- package/dist/local/config.d.mts +49 -0
- package/dist/local/config.mjs +168 -0
- package/dist/local/decide.d.mts +37 -0
- package/dist/local/decide.mjs +201 -0
- package/dist/local/failure-signs.d.mts +4 -0
- package/dist/local/failure-signs.mjs +99 -0
- package/dist/local/keys.d.mts +32 -0
- package/dist/local/keys.mjs +239 -0
- package/dist/local/models.d.mts +53 -0
- package/dist/local/models.mjs +117 -0
- package/dist/local/replay.d.mts +59 -0
- package/dist/local/replay.mjs +143 -0
- package/dist/local/report.d.mts +43 -0
- package/dist/local/report.mjs +153 -0
- package/dist/local/request-log.d.mts +53 -0
- package/dist/local/request-log.mjs +69 -0
- package/dist/local/retry-after.d.mts +3 -0
- package/dist/local/retry-after.mjs +28 -0
- package/dist/local/rust-router.d.mts +39 -0
- package/dist/local/rust-router.mjs +54 -0
- package/dist/local/server.d.mts +27 -0
- package/dist/local/server.mjs +449 -0
- package/dist/local/status-line.d.mts +17 -0
- package/dist/local/status-line.mjs +81 -0
- package/dist/local/tiers.d.mts +3 -0
- package/dist/local/tiers.mjs +137 -0
- package/dist/local/traces.d.mts +69 -0
- package/dist/local/traces.mjs +341 -0
- package/dist/phantom.d.mts +0 -37
- package/dist/phantom.mjs +0 -31
- package/package.json +15 -9
- package/skills/phantom-ai/SKILL.md +28 -97
- package/dist/cli/screens.d.mts +0 -177
- package/dist/cli/screens.mjs +0 -398
- package/dist/core/free.d.mts +0 -13
- package/dist/core/free.mjs +0 -14
- package/dist/core/motion.d.mts +0 -47
- package/dist/core/motion.mjs +0 -156
- package/dist/core/shapes.d.mts +0 -13
- package/dist/core/shapes.mjs +0 -1
- package/dist/keys/command.d.mts +0 -16
- package/dist/keys/command.mjs +0 -143
- package/dist/keys/saved.d.mts +0 -96
- package/dist/keys/saved.mjs +0 -169
- package/dist/models/choice.d.mts +0 -7
- package/dist/models/choice.mjs +0 -27
- package/dist/models/command.d.mts +0 -8
- package/dist/models/command.mjs +0 -66
- package/dist/models/list.d.mts +0 -39
- package/dist/models/list.mjs +0 -39
- package/dist/receipts/command.d.mts +0 -7
- package/dist/receipts/command.mjs +0 -41
- package/dist/receipts/receipts.d.mts +0 -76
- package/dist/receipts/receipts.mjs +0 -114
- package/dist/setup/agents.d.mts +0 -149
- package/dist/setup/agents.mjs +0 -886
- package/dist/setup/apply.d.mts +0 -85
- package/dist/setup/apply.mjs +0 -301
- package/dist/setup/command.d.mts +0 -12
- package/dist/setup/command.mjs +0 -307
- package/dist/setup/editors.d.mts +0 -108
- package/dist/setup/editors.mjs +0 -500
- package/dist/setup/legacy.d.mts +0 -13
- package/dist/setup/legacy.mjs +0 -36
- package/dist/setup/plan.d.mts +0 -104
- package/dist/setup/plan.mjs +0 -132
- package/dist/setup/screen.d.mts +0 -30
- package/dist/setup/screen.mjs +0 -260
- package/dist/setup/shared.d.mts +0 -141
- package/dist/setup/shared.mjs +0 -88
- package/dist/setup/was.d.mts +0 -42
- package/dist/setup/was.mjs +0 -91
- package/dist/spend/command.d.mts +0 -5
- package/dist/spend/command.mjs +0 -235
- package/dist/spend/lineup.d.mts +0 -61
- package/dist/spend/lineup.mjs +0 -39
- package/dist/spend/reason.d.mts +0 -5
- package/dist/spend/reason.mjs +0 -60
- package/dist/spend/report.d.mts +0 -105
- package/dist/spend/report.mjs +0 -68
- package/dist/spend/routing.d.mts +0 -74
- package/dist/spend/routing.mjs +0 -57
- package/dist/workspace/command.d.mts +0 -59
- package/dist/workspace/command.mjs +0 -871
package/dist/cli/screens.mjs
DELETED
|
@@ -1,398 +0,0 @@
|
|
|
1
|
-
import { paint } from "../core/style.mjs";
|
|
2
|
-
import { reasonInWords } from "../spend/reason.mjs";
|
|
3
|
-
import { JOBS } from "../models/list.mjs";
|
|
4
|
-
import { FREE_AGENT_REQUESTS_A_DAY, FREE_REQUESTS_A_DAY } from "../core/free.mjs";
|
|
5
|
-
/** The window's width: given, or the terminal's, or 100 for a pipe. */
|
|
6
|
-
const widthOf = (style) => style.columns ?? process.stdout.columns ?? 100;
|
|
7
|
-
/** How long a caption's rule is: 66, or less in a narrow window. */
|
|
8
|
-
const ruleWidth = (style) => Math.max(20, Math.min(66, widthOf(style) - 4));
|
|
9
|
-
/** Dollars as people read them: two decimals, or four under a cent so small spend doesn't read as $0.00. */
|
|
10
|
-
export function usd(n) {
|
|
11
|
-
const abs = Math.abs(n);
|
|
12
|
-
return `${n < 0 ? '-' : ''}$${abs > 0 && abs < 0.01 ? abs.toFixed(4) : abs.toFixed(2)}`;
|
|
13
|
-
}
|
|
14
|
-
const plural = (n, one) => `${n} ${one}${n === 1 ? '' : 's'}`;
|
|
15
|
-
/** Spend rows line up: a label column, then a bar, then the dollars; both shrink to fit a narrow window. */
|
|
16
|
-
const spendColumns = (style) => (widthOf(style) < 80 ? { LABEL: 22, BAR: 10 } : { LABEL: 30, BAR: 20 });
|
|
17
|
-
/** An uppercase caption, an optional detail beside it, and a thin rule under both. */
|
|
18
|
-
function caption(p, w, text, detail = '') {
|
|
19
|
-
const width = w;
|
|
20
|
-
// The heading in bold, so it's the easiest thing to find, not the quietest.
|
|
21
|
-
return [` ${p.bold(text)}${detail ? ` ${detail}` : ''}`, ` ${p.dim('─'.repeat(width))}`];
|
|
22
|
-
}
|
|
23
|
-
/** True inside the app (phantom alone), which offers next steps as choices, so the typed hint isn't needed. */
|
|
24
|
-
let hintsHidden = false;
|
|
25
|
-
/** True while the app runs, so a screen can point at a menu item instead of a command. */
|
|
26
|
-
export const inApp = () => hintsHidden;
|
|
27
|
-
/** 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. */
|
|
28
|
-
export function hideHints(hidden) {
|
|
29
|
-
const was = hintsHidden;
|
|
30
|
-
hintsHidden = hidden;
|
|
31
|
-
return was;
|
|
32
|
-
}
|
|
33
|
-
/** The last line of a screen: the one command to type next, in cyan. Not shown inside the app. */
|
|
34
|
-
function next(p, words, command) {
|
|
35
|
-
return hintsHidden ? [] : ['', ` ${p.lime('→')} ${words} ${p.cyan(command)}`];
|
|
36
|
-
}
|
|
37
|
-
/** A thin bar `width` cells long at `share` of full (0 to 1), in `fill`, on a dimmed track: the site's cost bars. */
|
|
38
|
-
export function bar(p, share, width, fill) {
|
|
39
|
-
const cells = Math.max(0, Math.min(width, Math.round(share * width)));
|
|
40
|
-
// A share above zero always shows at least a sliver, so a small spender isn't drawn as nothing.
|
|
41
|
-
const shown = share > 0 && cells === 0 ? 1 : cells;
|
|
42
|
-
return fill('━'.repeat(shown)) + p.dim('─'.repeat(width - shown));
|
|
43
|
-
}
|
|
44
|
-
/** A moment as `Nov 13, 2026, 4:29 PM EST`, in this computer's time zone, or the text as given when it isn't one. */
|
|
45
|
-
function dayAndTime(iso) {
|
|
46
|
-
const d = new Date(iso);
|
|
47
|
-
if (Number.isNaN(d.getTime()))
|
|
48
|
-
return iso;
|
|
49
|
-
const date = d.toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' });
|
|
50
|
-
// Newer ICU puts a narrow no-break space before AM and PM; a plain space copies and wraps better.
|
|
51
|
-
const time = d.toLocaleTimeString('en-US', { hour: 'numeric', minute: '2-digit', timeZoneName: 'short' }).replace(/\u202f/g, ' ');
|
|
52
|
-
return `${date}, ${time}`;
|
|
53
|
-
}
|
|
54
|
-
/** A date as `Nov 1, 2026`, read as UTC, or the text as given when it isn't one. */
|
|
55
|
-
function day(iso) {
|
|
56
|
-
const d = new Date(iso.length === 10 ? `${iso}T00:00:00Z` : iso);
|
|
57
|
-
return Number.isNaN(d.getTime())
|
|
58
|
-
? iso
|
|
59
|
-
: d.toLocaleDateString('en-US', {
|
|
60
|
-
month: 'short',
|
|
61
|
-
day: 'numeric',
|
|
62
|
-
year: 'numeric',
|
|
63
|
-
timeZone: 'UTC',
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
/** `phantom balance`: the credit in bold, then what it spent and when the key stops working. */
|
|
67
|
-
export function balanceScreen(b, style = {}) {
|
|
68
|
-
const p = paint(style.env ?? {}, Boolean(style.color));
|
|
69
|
-
const w = ruleWidth(style);
|
|
70
|
-
const lines = ['', ...caption(p, w, 'BALANCE'), ` ${p.bold(usd(b.credit_balance_usd))} ${p.dim('this key can spend')}`, ` ${p.dim('the workspace balance, or less when the key has a limit')}`, ''];
|
|
71
|
-
lines.push(` ${p.dim('spent'.padEnd(10))}${usd(b.credit_spent_usd)}`);
|
|
72
|
-
lines.push(` ${p.dim('expires'.padEnd(10))}${day(b.expires_at)}`);
|
|
73
|
-
if (!b.active)
|
|
74
|
-
lines.push('', ` ${p.red('✗')} This key is switched off or past its expiry.`);
|
|
75
|
-
if (b.active && b.credit_balance_usd <= 0) {
|
|
76
|
-
lines.push('', ` ${p.lime('✓')} phantom-1 still runs on free models while you have no credit.`);
|
|
77
|
-
lines.push(...next(p, 'Add credit:', 'phantom fund --amount 10 --card'));
|
|
78
|
-
}
|
|
79
|
-
else if (b.active) {
|
|
80
|
-
lines.push(...next(p, 'See what it went on:', 'phantom spend'));
|
|
81
|
-
}
|
|
82
|
-
return lines.join('\n');
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* `phantom spend`: the total, what phantom-1 saved, the site's two bars (what
|
|
86
|
-
* the calls cost against what the same calls cost on the frontier model), then
|
|
87
|
-
* each model and each key with a bar for its share.
|
|
88
|
-
*/
|
|
89
|
-
export function spendScreen(s, style = {}) {
|
|
90
|
-
const p = paint(style.env ?? {}, Boolean(style.color));
|
|
91
|
-
const w = ruleWidth(style);
|
|
92
|
-
const { LABEL, BAR } = spendColumns(style);
|
|
93
|
-
const range = `${day(s.from)} to ${day(s.to)}, UTC`;
|
|
94
|
-
const lines = ['', ...caption(p, w, s.scope === 'workspace' ? 'WORKSPACE SPEND' : 'SPEND', p.dim(range))];
|
|
95
|
-
lines.push(` ${p.bold(usd(s.total.spent_usd))} ${p.dim(`spent on ${plural(s.total.calls, 'call')}`)}`);
|
|
96
|
-
const r = s.routing;
|
|
97
|
-
if (r.available && r.calls > 0) {
|
|
98
|
-
// The site's comparison: what phantom-1 cost, in lime, against the same calls on the frontier model.
|
|
99
|
-
const most = Math.max(r.spent_usd, r.baseline_usd) || 1;
|
|
100
|
-
lines.push('', ` ${p.lime(p.bold(`phantom-1 saved ${usd(r.saved_usd)}`))} ${p.dim(`on ${plural(r.calls, 'call')}`)}`);
|
|
101
|
-
// Labelled by what they mean, with the model the comparison uses said once underneath.
|
|
102
|
-
lines.push(` ${'You paid'.padEnd(LABEL)}${bar(p, r.spent_usd / most, BAR, p.lime)} ${usd(r.spent_usd).padStart(8)}`);
|
|
103
|
-
lines.push(` ${'Without phantom-1'.padEnd(LABEL)}${bar(p, r.baseline_usd / most, BAR, p.white)} ${usd(r.baseline_usd).padStart(8)}`);
|
|
104
|
-
lines.push(` ${p.dim(`without phantom-1: the same calls, all on ${r.baseline_model}`)}`);
|
|
105
|
-
}
|
|
106
|
-
else if (!r.available) {
|
|
107
|
-
lines.push('', ` ${p.dim(`phantom-1 savings not shown: ${r.reason}`)}`);
|
|
108
|
-
}
|
|
109
|
-
if (s.models.length) {
|
|
110
|
-
const top = s.models[0].spent_usd || 1;
|
|
111
|
-
lines.push('', ...caption(p, w, 'BY MODEL'));
|
|
112
|
-
for (const m of s.models.slice(0, 8)) {
|
|
113
|
-
lines.push(` ${m.model.slice(0, LABEL - 1).padEnd(LABEL)}${bar(p, m.spent_usd / top, BAR, p.cyan)} ${usd(m.spent_usd).padStart(8)} ${p.dim(plural(m.calls, 'call'))}`);
|
|
114
|
-
}
|
|
115
|
-
if (s.models.length > 8)
|
|
116
|
-
lines.push(` ${p.dim(`and ${plural(s.models.length - 8, 'more model')}`)}`);
|
|
117
|
-
}
|
|
118
|
-
if (s.keys.length > 1) {
|
|
119
|
-
lines.push('', ...caption(p, w, 'BY KEY'));
|
|
120
|
-
for (const k of s.keys) {
|
|
121
|
-
const savedText = k.saved_usd ? ` saved ${usd(k.saved_usd)}` : '';
|
|
122
|
-
const offText = k.active ? '' : ' revoked or rotated';
|
|
123
|
-
// The dollars line up with the model rows above, unless that pushes the row past the window's edge.
|
|
124
|
-
const tail = 8 + 2 + plural(k.calls, 'call').length + savedText.length + offText.length;
|
|
125
|
-
const pad = Math.max(LABEL, Math.min(LABEL + BAR + 2, widthOf(style) - 2 - tail));
|
|
126
|
-
lines.push(` ${k.name.slice(0, LABEL - 1).padEnd(pad)}${usd(k.spent_usd).padStart(8)} ${p.dim(plural(k.calls, 'call'))}${savedText ? p.lime(savedText) : ''}${offText ? p.dim(offText) : ''}`);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
if (!s.total.calls)
|
|
130
|
-
lines.push('', ` ${p.dim('No calls in this range yet.')}`);
|
|
131
|
-
lines.push(...(s.scope === 'workspace' ? next(p, 'Pick the models phantom-1 runs:', 'phantom lineup') : next(p, 'Every key in the workspace:', 'phantom spend --workspace')));
|
|
132
|
-
return lines.join('\n');
|
|
133
|
-
}
|
|
134
|
-
/** `text` cut to `width` characters, ending in … when it was longer. */
|
|
135
|
-
const clip = (text, width) => (text.length > width ? `${text.slice(0, width - 1)}…` : text);
|
|
136
|
-
/** The keys, one row each: name, the start of the key, what it spent, and its limit. */
|
|
137
|
-
function keyRows(p, keys) {
|
|
138
|
-
if (!keys.length)
|
|
139
|
-
return [` ${p.dim('No keys yet.')}`];
|
|
140
|
-
return keys.map((k) => {
|
|
141
|
-
const limit = k.limit_usd != null ? `limit ${usd(k.limit_usd)}` : k.budget_usd != null ? `${usd(k.budget_usd)} per ${plural(k.period_days ?? 30, 'day')}` : 'no limit';
|
|
142
|
-
// A revoked or rotated key gets a hollow mark and the word off at the end, so the columns stay in line.
|
|
143
|
-
const off = k.is_active === false;
|
|
144
|
-
const mark = off ? p.dim('○') : p.lime('●');
|
|
145
|
-
// The id's first 8 characters: enough for --id, which also takes the name.
|
|
146
|
-
return ` ${mark} ${clip(k.name ?? 'Key', 20).padEnd(21)}${p.dim((k.id ?? '').slice(0, 8).padEnd(9))}${p.dim((k.prefix ?? '').slice(0, 18).padEnd(20))}${usd(k.spent_usd ?? 0).padStart(8)} ${p.dim(limit)}${off ? ` ${p.dim('off')}` : ''}`;
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
/** `phantom workspace`: the shared balance, each key, and the last few charges. */
|
|
150
|
-
export function workspaceScreen(view, style = {}) {
|
|
151
|
-
const p = paint(style.env ?? {}, Boolean(style.color));
|
|
152
|
-
const w = ruleWidth(style);
|
|
153
|
-
const lines = ['', ...caption(p, w, 'WORKSPACE', p.dim(`${view.name ?? ''}${view.account_linked ? ' · signed-in account' : ' · guest'}`))];
|
|
154
|
-
lines.push(` ${p.bold(usd(view.balance_usd))} ${p.dim('shared balance')}${view.held_usd ? p.dim(` ${usd(view.held_usd)} held for requests running now`) : ''}`);
|
|
155
|
-
lines.push('', ...caption(p, w, 'KEYS', p.dim(String(view.keys.length))), ...keyRows(p, view.keys));
|
|
156
|
-
const access = view.access ?? [];
|
|
157
|
-
if (access.length) {
|
|
158
|
-
// What each kind is, in words: a "session" is a browser sign-in, a "device" is phantom login on a computer.
|
|
159
|
-
const kinds = { session: 'browser', device: 'device', recovery: 'recovery file' };
|
|
160
|
-
lines.push('', ...caption(p, w, 'SIGN-INS', p.dim(String(access.length))));
|
|
161
|
-
for (const a of access) {
|
|
162
|
-
const ends = a.expires_at ? `expires ${day(a.expires_at)}` : 'never expires';
|
|
163
|
-
lines.push(` ${(kinds[a.kind ?? ''] ?? a.kind ?? 'sign-in').padEnd(14)}${p.dim(a.id.slice(0, 8).padEnd(10))}${p.dim(`${a.created_at ? `since ${day(a.created_at)} ` : ''}${ends}`)}`);
|
|
164
|
-
}
|
|
165
|
-
lines.push(` ${p.dim('Stop one with')} ${p.cyan('phantom workspace revoke-access --id <id>')}`);
|
|
166
|
-
}
|
|
167
|
-
const charges = (view.charges ?? []).slice(0, 5);
|
|
168
|
-
if (charges.length) {
|
|
169
|
-
lines.push('', ...caption(p, w, 'LATEST CALLS'));
|
|
170
|
-
// Single calls cost fractions of a cent, so this column always shows four places and lines up.
|
|
171
|
-
for (const c of charges)
|
|
172
|
-
lines.push(` ${(c.model ?? '').slice(0, 33).padEnd(34)}${`$${(c.cost_usd ?? 0).toFixed(4)}`.padStart(8)} ${p.dim(c.why ?? '')}`.trimEnd());
|
|
173
|
-
}
|
|
174
|
-
lines.push(...next(p, 'Make a key for another agent:', 'phantom keys create --save <name>'));
|
|
175
|
-
return lines.join('\n');
|
|
176
|
-
}
|
|
177
|
-
/** `phantom keys`: the workspace's keys alone. */
|
|
178
|
-
export function keysScreen(keys, style = {}) {
|
|
179
|
-
const p = paint(style.env ?? {}, Boolean(style.color));
|
|
180
|
-
const w = ruleWidth(style);
|
|
181
|
-
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');
|
|
182
|
-
}
|
|
183
|
-
/** After `phantom login`: signed in, where the key is kept, and the next step. */
|
|
184
|
-
export function signedInScreen(saved, style = {}) {
|
|
185
|
-
const p = paint(style.env ?? {}, Boolean(style.color));
|
|
186
|
-
const w = ruleWidth(style);
|
|
187
|
-
const where = saved.saved_as === 'default' ? 'Your key is' : `Key "${saved.saved_as}" is`;
|
|
188
|
-
return ['', ` ${p.lime('✓')} ${p.bold('Signed in.')} ${p.dim(`${where} saved in your ${saved.storage}.`)}`, ...next(p, 'Connect your coding agents:', 'phantom setup')].join('\n');
|
|
189
|
-
}
|
|
190
|
-
/** `phantom login` when this computer already has a key: say so, then how to switch or add one. */
|
|
191
|
-
export function alreadySignedInScreen(keyIdShown, style = {}) {
|
|
192
|
-
const p = paint(style.env ?? {}, Boolean(style.color));
|
|
193
|
-
return ['', ` ${p.lime('✓')} ${p.bold('You are already signed in on this computer.')}${keyIdShown ? ` ${p.dim(`key ${keyIdShown}`)}` : ''}`, ...next(p, 'Use another workspace: run phantom logout, then', 'phantom login'), ...next(p, 'Add a second key here:', 'phantom login --save <name>')].join('\n');
|
|
194
|
-
}
|
|
195
|
-
/** A ✓ line with an optional dim detail, for a change that worked. */
|
|
196
|
-
function done(p, words, detail = '') {
|
|
197
|
-
return ` ${p.lime('✓')} ${words}${detail ? ` ${p.dim(detail)}` : ''}`;
|
|
198
|
-
}
|
|
199
|
-
/** `phantom route`: which models "auto" picks from, what it does at the edges, and its rules, in sentences. */
|
|
200
|
-
export function routeScreen(r, style = {}) {
|
|
201
|
-
const p = paint(style.env ?? {}, Boolean(style.color));
|
|
202
|
-
const w = ruleWidth(style);
|
|
203
|
-
const lines = ['', ...caption(p, w, 'ROUTING', p.dim('how model "auto" picks for this key'))];
|
|
204
|
-
const policy = r.route_policy;
|
|
205
|
-
const row = (label, value) => ` ${p.dim(label.padEnd(14))}${value}`;
|
|
206
|
-
// Which providers serve first holds for every request, routed or not.
|
|
207
|
-
const sortWords = {
|
|
208
|
-
cost: 'cheapest first',
|
|
209
|
-
ttft: 'fastest to start answering first',
|
|
210
|
-
tps: 'most tokens a second first',
|
|
211
|
-
};
|
|
212
|
-
const providers = row('providers', `${sortWords[policy?.sort ?? 'cost']}${policy?.sort ? '' : p.dim(' (the default)')}${policy?.zdr ? ', zero data retention only' : ''}${policy?.no_training ? ', no training on prompts' : ''}`);
|
|
213
|
-
if (!policy || !policy.models.length) {
|
|
214
|
-
lines.push(' No route policy, so model "auto" runs phantom-1, which picks a model for each request.', '', providers);
|
|
215
|
-
lines.push(...(policy?.sort ? next(p, 'Back to cheapest first:', 'phantom route set --sort default') : next(p, 'Providers that start answering soonest:', 'phantom route set --sort fast')));
|
|
216
|
-
return lines.join('\n');
|
|
217
|
-
}
|
|
218
|
-
// One model a line, in the order "auto" tries them, so a long list doesn't wrap.
|
|
219
|
-
policy.models.forEach((m, k) => lines.push(row(k === 0 ? 'models' : '', `${p.dim(`${k + 1}.`)} ${k === 0 ? `${p.bold(m)} ${p.dim('the default')}` : m}`)));
|
|
220
|
-
lines.push(row('applies to', policy.applies_to === 'all' ? 'every request' : 'requests for model "auto"'));
|
|
221
|
-
lines.push(row('cap used up', policy.on_empty === 'cheapest' ? 'keep going on the cheapest model' : 'stop and refuse requests'));
|
|
222
|
-
lines.push(row('a model fails', policy.fallback_on_error ? 'try the next one' : 'stop there'));
|
|
223
|
-
const stick = policy.stick_minutes ?? 5;
|
|
224
|
-
lines.push(row('conversations', stick ? `stay on their model for ${plural(stick, 'minute')}${policy.stick_by_prompt === false ? ' (by x-phantom-session only)' : ''}` : 'can change model every request'));
|
|
225
|
-
lines.push(providers);
|
|
226
|
-
const rules = policy.rules ?? [];
|
|
227
|
-
lines.push('', ...caption(p, w, 'RULES', p.dim(rules.length ? 'checked in order; the first that matches picks' : '')));
|
|
228
|
-
if (!rules.length)
|
|
229
|
-
lines.push(` ${p.dim('None: "auto" runs the first model.')}`);
|
|
230
|
-
rules.forEach((rule, k) => {
|
|
231
|
-
const when = Object.entries(rule.if)
|
|
232
|
-
.map(([name, value]) => `${name} = ${value}`)
|
|
233
|
-
.join(' and ');
|
|
234
|
-
lines.push(` ${p.dim(`${k + 1}.`)} if ${when}, use ${p.bold(rule.use)}`);
|
|
235
|
-
});
|
|
236
|
-
lines.push(...next(p, 'See what a request would get now:', 'phantom route test'));
|
|
237
|
-
return lines.join('\n');
|
|
238
|
-
}
|
|
239
|
-
/** `phantom route test`: the model a request would run on right now, and why. */
|
|
240
|
-
export function routeTestScreen(t, style = {}) {
|
|
241
|
-
const p = paint(style.env ?? {}, Boolean(style.color));
|
|
242
|
-
const w = ruleWidth(style);
|
|
243
|
-
const lines = [''];
|
|
244
|
-
if (!t.model)
|
|
245
|
-
lines.push(` ${p.red('✗')} A request now would be refused: this key's cap is used up.`);
|
|
246
|
-
else
|
|
247
|
-
lines.push(` ${p.lime('→')} A request now would run on ${p.bold(t.model)}`, ` ${p.dim(t.routed === false ? 'it names its own model, so the route policy is not used' : `because: ${reasonInWords(t.reason ?? 'default')}`)}`);
|
|
248
|
-
if (t.fallbacks?.length)
|
|
249
|
-
lines.push(` ${p.dim(`then, if it fails: ${t.fallbacks.join(', ')}`)}`);
|
|
250
|
-
return lines.join('\n');
|
|
251
|
-
}
|
|
252
|
-
/** What each tier is for, in a few words. */
|
|
253
|
-
export const TIER_ABOUT = {
|
|
254
|
-
standard: 'where every task starts',
|
|
255
|
-
frontier: 'hard steps: a failed try, a stuck agent',
|
|
256
|
-
};
|
|
257
|
-
/** `phantom lineup`: the model phantom-1 runs in each tier, whether it's the default or your pick, and its fallback. */
|
|
258
|
-
export function lineupScreen(l, style = {}) {
|
|
259
|
-
const p = paint(style.env ?? {}, Boolean(style.color));
|
|
260
|
-
const w = ruleWidth(style);
|
|
261
|
-
const lines = ['', ...caption(p, w, 'LINEUP', p.dim('the model phantom-1 runs in each tier'))];
|
|
262
|
-
for (const tier of ['standard', 'frontier']) {
|
|
263
|
-
const mine = Boolean(l.lineup?.[tier]);
|
|
264
|
-
const fallback = l.lineup?.fallbacks?.[tier];
|
|
265
|
-
lines.push(` ${p.bold(tier.toUpperCase().padEnd(10))}${l.tiers[tier].model.padEnd(36)}${mine ? p.lime('your pick') : p.dim('default')}`);
|
|
266
|
-
lines.push(` ${' '.repeat(10)}${p.dim(TIER_ABOUT[tier])}${fallback ? p.dim(` · falls back to ${fallback}`) : ''}`);
|
|
267
|
-
}
|
|
268
|
-
lines.push(...next(p, 'Pick a model for a tier:', 'phantom lineup set'));
|
|
269
|
-
return lines.join('\n');
|
|
270
|
-
}
|
|
271
|
-
/** A model's price per million tokens, in and out, for a picker's hint. */
|
|
272
|
-
export function priceHint(c) {
|
|
273
|
-
const price = c.input_per_m === null || c.output_per_m === null ? 'price not listed now' : `$${c.input_per_m.toFixed(2)} in · $${c.output_per_m.toFixed(2)} out per 1M`;
|
|
274
|
-
const context = c.context ? ` · ${Math.round(c.context / 1000)}k context` : '';
|
|
275
|
-
return `${price}${context}${c.default ? ' · default' : ''}`;
|
|
276
|
-
}
|
|
277
|
-
/** A link to open in the browser (Stripe Checkout, billing, a wallet), with what it's for and the next step. */
|
|
278
|
-
export function linkScreen(words, url, after, style = {}) {
|
|
279
|
-
const p = paint(style.env ?? {}, Boolean(style.color));
|
|
280
|
-
const w = ruleWidth(style);
|
|
281
|
-
return ['', ` ${p.lime('◆')} ${p.bold(words)}`, ` ${p.dim(style.opened ? 'Opened in your browser:' : 'Open:')} ${url}`, ...(after ? next(p, after[0], after[1]) : [])].join('\n');
|
|
282
|
-
}
|
|
283
|
-
/** `phantom fund`: the card checkout link, or the wallet payment link with its id to check on. */
|
|
284
|
-
export function fundScreen(f, style = {}) {
|
|
285
|
-
if (f.checkout_url) {
|
|
286
|
-
const total = f.amount_cents ? ` (${usd(f.amount_cents / 100)} with the card fee)` : '';
|
|
287
|
-
return linkScreen(`Pay by card on Stripe${total}`, f.checkout_url, ['Once it goes through:', 'phantom balance'], style);
|
|
288
|
-
}
|
|
289
|
-
const p = paint(style.env ?? {}, Boolean(style.color));
|
|
290
|
-
const w = ruleWidth(style);
|
|
291
|
-
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 ${dayAndTime(f.expires_at)}`) : ''}`, ...next(p, 'See whether it arrived:', `phantom workspace payment --id ${f.payment_id ?? '<id>'}`)].join('\n');
|
|
292
|
-
}
|
|
293
|
-
/** `phantom workspace payment`: whether a payment has come in. */
|
|
294
|
-
export function paymentScreen(pay, style = {}) {
|
|
295
|
-
const p = paint(style.env ?? {}, Boolean(style.color));
|
|
296
|
-
const w = ruleWidth(style);
|
|
297
|
-
const landed = pay.status === 'completed';
|
|
298
|
-
return ['', landed ? done(p, `Paid. ${usd(pay.credit_usd ?? 0)} of credit is in your workspace.`) : ` ${p.yellow('…')} Not in yet ${p.dim(`(${pay.status})`)}. Payments can take a minute.`, ...(landed ? next(p, 'See it:', 'phantom balance') : [])].join('\n');
|
|
299
|
-
}
|
|
300
|
-
/** What a key change did: created, rotated, revoked or updated, and what to do next. */
|
|
301
|
-
export function keyChangeScreen(change, name, style = {}) {
|
|
302
|
-
const p = paint(style.env ?? {}, Boolean(style.color));
|
|
303
|
-
const w = ruleWidth(style);
|
|
304
|
-
const named = name && name !== 'default' ? `"${name}"` : 'your default key';
|
|
305
|
-
const lines = [''];
|
|
306
|
-
if (change === 'created') {
|
|
307
|
-
lines.push(done(p, `Key ${named} created${style.limit != null ? ` with a ${usd(style.limit)} limit` : ''}.`, `saved in your ${style.storage ?? 'macOS Keychain'}`));
|
|
308
|
-
lines.push(...next(p, 'Run an agent on it:', `phantom codex --key ${name ?? 'default'}`));
|
|
309
|
-
}
|
|
310
|
-
else if (change === 'rotated') {
|
|
311
|
-
lines.push(done(p, `Key rotated. ${named} is the new one; the old one stops working.`));
|
|
312
|
-
}
|
|
313
|
-
else if (change === 'revoked') {
|
|
314
|
-
lines.push(done(p, 'Key revoked. Its credit stays in the workspace.'), ...next(p, 'See your keys:', 'phantom keys'));
|
|
315
|
-
}
|
|
316
|
-
else {
|
|
317
|
-
lines.push(done(p, 'Key updated.'), ...next(p, 'See it:', 'phantom keys'));
|
|
318
|
-
}
|
|
319
|
-
return lines.join('\n');
|
|
320
|
-
}
|
|
321
|
-
/** `phantom logout`: signed out on this computer, or nothing to sign out of. */
|
|
322
|
-
export function logoutScreen(removed, style = {}) {
|
|
323
|
-
const p = paint(style.env ?? {}, Boolean(style.color));
|
|
324
|
-
const w = ruleWidth(style);
|
|
325
|
-
const lines = ['', removed ? done(p, 'Signed out on this computer.', 'your workspace, keys and credit are unchanged') : ` ${p.dim('Not signed in on this computer, so nothing changed.')}`];
|
|
326
|
-
if (style.removedNamed?.length)
|
|
327
|
-
lines.push(` ${p.lime('✓')} Forgot the keys saved here: ${style.removedNamed.join(', ')}. ${p.dim('They still work wherever else they are.')}`);
|
|
328
|
-
if (style.kept?.length)
|
|
329
|
-
lines.push(` ${p.dim(`Still saved here: ${plural(style.kept.length, 'key')} by name (${style.kept.join(', ')}). To forget them too:`)} ${p.cyan('phantom logout --all')}`);
|
|
330
|
-
lines.push(...next(p, 'Sign in again:', 'phantom login'));
|
|
331
|
-
return lines.join('\n');
|
|
332
|
-
}
|
|
333
|
-
/** `phantom keys saved`: the keys saved on this computer, by name. */
|
|
334
|
-
export function savedKeysScreen(keys, style = {}) {
|
|
335
|
-
const p = paint(style.env ?? {}, Boolean(style.color));
|
|
336
|
-
const w = ruleWidth(style);
|
|
337
|
-
const lines = ['', ...caption(p, w, 'KEYS ON THIS COMPUTER', p.dim(String(keys.length)))];
|
|
338
|
-
if (!keys.length)
|
|
339
|
-
lines.push(` ${p.dim('None saved yet.')}`);
|
|
340
|
-
for (const k of keys) {
|
|
341
|
-
const credit = k.credit_balance_usd === undefined ? '' : usd(k.credit_balance_usd).padStart(10);
|
|
342
|
-
const off = k.active === false;
|
|
343
|
-
lines.push(` ${off ? p.dim('○') : p.lime('●')} ${clip(k.name, 20).padEnd(21)}${p.dim(k.id.slice(0, 12).padEnd(14))}${credit}${off ? ` ${p.dim('off')}` : ''}`);
|
|
344
|
-
}
|
|
345
|
-
lines.push(...next(p, 'Save another:', 'phantom keys save <name>'));
|
|
346
|
-
return lines.join('\n');
|
|
347
|
-
}
|
|
348
|
-
/** `phantom keys save <name>`: the key is saved under its name, and how to run an agent on it. */
|
|
349
|
-
export function keySavedScreen(name, style = {}) {
|
|
350
|
-
const p = paint(style.env ?? {}, Boolean(style.color));
|
|
351
|
-
const w = ruleWidth(style);
|
|
352
|
-
return ['', done(p, `Key "${name}" saved on this computer.`), ...next(p, 'Run an agent on it:', `phantom codex --key ${name}`)].join('\n');
|
|
353
|
-
}
|
|
354
|
-
/** What each of Phantom's own models is for, in a few words. */
|
|
355
|
-
const MODEL_ABOUT = {
|
|
356
|
-
'phantom-1': 'every job; chat starts each task on standard and moves hard steps to frontier',
|
|
357
|
-
'phantom-1:free': `chat on free models at $0, no card; ${FREE_REQUESTS_A_DAY} requests a day, ${FREE_AGENT_REQUESTS_A_DAY} from an agent`,
|
|
358
|
-
'phantom-1:zdr': 'chat on providers that keep none of your data, at their prices',
|
|
359
|
-
};
|
|
360
|
-
/** A model's few words: {@link MODEL_ABOUT}, or the first sentence the server gives for a model this CLI doesn't know yet. */
|
|
361
|
-
const modelAbout = (m) => MODEL_ABOUT[m.id] ?? m.description.split('. ')[0];
|
|
362
|
-
/**
|
|
363
|
-
* `phantom models`: a table of what each of Phantom's own models can do, a
|
|
364
|
-
* column per model, a ✓ per job. Under it, the model behind each job, so you
|
|
365
|
-
* can see what runs before you pick.
|
|
366
|
-
*/
|
|
367
|
-
export function modelsScreen(v, style = {}) {
|
|
368
|
-
const p = paint(style.env ?? {}, Boolean(style.color));
|
|
369
|
-
const LABEL = 18;
|
|
370
|
-
const COLUMN = 17;
|
|
371
|
-
// Padding goes outside the color, so the row's trailing spaces can be trimmed.
|
|
372
|
-
const cell = (text, color) => color(text) + ' '.repeat(Math.max(0, COLUMN - text.length));
|
|
373
|
-
const row = (label, cells) => ` ${label.padEnd(LABEL)}${cells.join('')}`.trimEnd();
|
|
374
|
-
const lines = ['', ...caption(p, ruleWidth(style), 'MODELS', p.dim('each is a model name your agents can send'))];
|
|
375
|
-
lines.push(row('', v.models.map((m) => cell(m.id, p.bold))));
|
|
376
|
-
lines.push(row('', v.models.map((m) => cell(m.id === v.using ? 'in use' : '', p.lime))));
|
|
377
|
-
for (const [job, label] of JOBS) {
|
|
378
|
-
lines.push(row(label, v.models.map((m) => (m.can.includes(job) ? cell('✓', p.lime) : cell('·', p.dim)))));
|
|
379
|
-
}
|
|
380
|
-
for (const m of v.models) {
|
|
381
|
-
lines.push('', ` ${p.bold(m.id)}${m.id === v.using ? ` ${p.lime('in use')}` : ''}`, ` ${p.dim(modelAbout(m))}`);
|
|
382
|
-
// Chat models in different tiers are named by tier; models in one tier are tried in order.
|
|
383
|
-
const oneTier = new Set(m.chat.map((c) => c.tier)).size === 1;
|
|
384
|
-
const idWidth = Math.max(0, ...m.chat.map((c) => c.id.length));
|
|
385
|
-
m.chat.forEach((c, i) => {
|
|
386
|
-
const label = oneTier ? (i === 0 ? 'chat' : 'then') : c.tier;
|
|
387
|
-
lines.push(` ${p.dim(label.padEnd(16))}${c.free ? `${c.id.padEnd(idWidth)} ${p.dim('$0')}` : c.id}`);
|
|
388
|
-
});
|
|
389
|
-
for (const [job, label] of JOBS) {
|
|
390
|
-
if (job === 'chat' || !m.can.includes(job))
|
|
391
|
-
continue;
|
|
392
|
-
lines.push(` ${p.dim(label.toLowerCase().padEnd(16))}${m.jobs[job] ?? p.dim('on the chat models above')}`);
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
const other = v.models.find((m) => m.id !== v.using)?.id ?? v.using;
|
|
396
|
-
lines.push(...next(p, 'Pick the one your agents use:', `phantom models use ${other}`));
|
|
397
|
-
return lines.join('\n');
|
|
398
|
-
}
|
package/dist/core/free.d.mts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
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";
|
package/dist/core/free.mjs
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
// What phantom-1 gives a key for free, said the same way on every screen that mentions it.
|
|
2
|
-
/**
|
|
3
|
-
* Free phantom-1 requests a workspace gets each UTC day, before it has had $10
|
|
4
|
-
* of credit. Phantom's own limit is `FREE_ROUTER_CAPS.perDay` in the Phantom
|
|
5
|
-
* repo's `lib/config.ts`; change both together.
|
|
6
|
-
*/
|
|
7
|
-
export const FREE_REQUESTS_A_DAY = 50;
|
|
8
|
-
/** The same, for requests a coding agent sends (`FREE_ROUTER_CAPS.perDayAgent` in the Phantom repo). */
|
|
9
|
-
export const FREE_AGENT_REQUESTS_A_DAY = 200;
|
|
10
|
-
/**
|
|
11
|
-
* The free offer in one line short enough for an 80-column terminal. It names
|
|
12
|
-
* the coding-agent limit, since the CLI sets up and starts agents.
|
|
13
|
-
*/
|
|
14
|
-
export const FREE_LINE = `phantom-1 runs free models, ${FREE_AGENT_REQUESTS_A_DAY} a day from agents, no card`;
|
package/dist/core/motion.d.mts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import type { Env } from './state.mts';
|
|
2
|
-
/** Whether to animate: color is on for that stream (a terminal, no NO_COLOR), it isn't CI, and PHANTOM_NO_MOTION isn't set. */
|
|
3
|
-
export declare function motionOn(env: Env, isTTY: boolean | undefined): boolean;
|
|
4
|
-
/** Fast at first, then easing to a stop: the curve for things that arrive. */
|
|
5
|
-
export declare const easeOut: (t: number) => number;
|
|
6
|
-
/** A flipbook: each frame is the whole block of lines, and each delay is how long to wait before drawing that frame. */
|
|
7
|
-
export type Flipbook = {
|
|
8
|
-
frames: string[][];
|
|
9
|
-
delays: number[];
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Lines appearing top to bottom: frame k shows the first k lines and keeps the
|
|
13
|
-
* rest blank, so the block's height never changes. `delay(line)` is how long
|
|
14
|
-
* the line waits before it appears; 0 lets it come with the one before.
|
|
15
|
-
*/
|
|
16
|
-
export declare function reveal(lines: string[], delay: (line: string, index: number) => number): Flipbook;
|
|
17
|
-
/**
|
|
18
|
-
* Every bar in `lines` (a run of ━ followed by its ─ track) drawn at
|
|
19
|
-
* `progress` of its length, 0 to 1. The track grows to fill what the bar gives
|
|
20
|
-
* up, so each line keeps its width.
|
|
21
|
-
*/
|
|
22
|
-
export declare function growBars(lines: string[], progress: number): string[];
|
|
23
|
-
/** Bars growing from nothing to their length over `ms`, easing out. */
|
|
24
|
-
export declare function barsGrowing(lines: string[], ms?: number, steps?: number): Flipbook;
|
|
25
|
-
/** The ghost's eye row with the eyes closed: the two gaps filled with a low half block, like lids. */
|
|
26
|
-
export declare const CLOSED_EYES: string;
|
|
27
|
-
/**
|
|
28
|
-
* The brand header drawing in, for a screen whose lines start with it
|
|
29
|
-
* (setup): PHANTOM appears letter by letter, the rest of the screen follows
|
|
30
|
-
* row by row, then the ghost blinks once.
|
|
31
|
-
*/
|
|
32
|
-
export declare function brandIntro(lines: string[], opts?: {
|
|
33
|
-
letterMs?: number;
|
|
34
|
-
rowMs?: number;
|
|
35
|
-
blinkMs?: number;
|
|
36
|
-
}): Flipbook;
|
|
37
|
-
/**
|
|
38
|
-
* Plays a flipbook on a stream: writes the first frame, then moves the cursor
|
|
39
|
-
* back up and redraws each next one in place. Ends on the last frame with a
|
|
40
|
-
* newline. A key press (on a terminal) or `rows` too few to fit the block
|
|
41
|
-
* skips straight to the last frame.
|
|
42
|
-
*/
|
|
43
|
-
export declare function play(write: (s: string) => void, book: Flipbook, opts?: {
|
|
44
|
-
sleep?: (ms: number) => Promise<void>;
|
|
45
|
-
rows?: number;
|
|
46
|
-
skipOnKey?: boolean;
|
|
47
|
-
}): Promise<void>;
|
package/dist/core/motion.mjs
DELETED
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import { colorOn } from "./style.mjs";
|
|
2
|
-
import { GHOST, WORDMARK } from "./brand.mjs";
|
|
3
|
-
/** Whether to animate: color is on for that stream (a terminal, no NO_COLOR), it isn't CI, and PHANTOM_NO_MOTION isn't set. */
|
|
4
|
-
export function motionOn(env, isTTY) {
|
|
5
|
-
if (env.PHANTOM_NO_MOTION && env.PHANTOM_NO_MOTION !== '0')
|
|
6
|
-
return false;
|
|
7
|
-
if (env.CI && env.CI !== 'false' && env.CI !== '0')
|
|
8
|
-
return false;
|
|
9
|
-
// FORCE_COLOR can color a pipe, but cursor moves only make sense on a real terminal.
|
|
10
|
-
return colorOn(env, isTTY) && Boolean(isTTY);
|
|
11
|
-
}
|
|
12
|
-
/** Fast at first, then easing to a stop: the curve for things that arrive. */
|
|
13
|
-
export const easeOut = (t) => 1 - (1 - Math.min(1, Math.max(0, t))) ** 3;
|
|
14
|
-
/**
|
|
15
|
-
* Lines appearing top to bottom: frame k shows the first k lines and keeps the
|
|
16
|
-
* rest blank, so the block's height never changes. `delay(line)` is how long
|
|
17
|
-
* the line waits before it appears; 0 lets it come with the one before.
|
|
18
|
-
*/
|
|
19
|
-
export function reveal(lines, delay) {
|
|
20
|
-
const book = { frames: [], delays: [] };
|
|
21
|
-
lines.forEach((line, k) => {
|
|
22
|
-
const wait = delay(line, k);
|
|
23
|
-
const frame = lines.map((l, j) => (j <= k ? l : ''));
|
|
24
|
-
// A line with no wait joins the frame before it instead of making its own.
|
|
25
|
-
if (book.frames.length && wait === 0)
|
|
26
|
-
book.frames[book.frames.length - 1] = frame;
|
|
27
|
-
else {
|
|
28
|
-
book.frames.push(frame);
|
|
29
|
-
book.delays.push(book.frames.length === 1 ? 0 : wait);
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
return book;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Every bar in `lines` (a run of ━ followed by its ─ track) drawn at
|
|
36
|
-
* `progress` of its length, 0 to 1. The track grows to fill what the bar gives
|
|
37
|
-
* up, so each line keeps its width.
|
|
38
|
-
*/
|
|
39
|
-
export function growBars(lines, progress) {
|
|
40
|
-
return lines.map((line) => line.replace(/(━+)((?:\x1b\[[0-9;]*m)*)(─*)/g, (_all, fill, codes, track) => {
|
|
41
|
-
const shown = Math.round(fill.length * progress);
|
|
42
|
-
return '━'.repeat(shown) + codes + '─'.repeat(fill.length - shown + track.length);
|
|
43
|
-
}));
|
|
44
|
-
}
|
|
45
|
-
/** Bars growing from nothing to their length over `ms`, easing out. */
|
|
46
|
-
export function barsGrowing(lines, ms = 250, steps = 10) {
|
|
47
|
-
const frames = Array.from({ length: steps + 1 }, (_, k) => growBars(lines, easeOut(k / steps)));
|
|
48
|
-
return { frames, delays: frames.map((_, k) => (k === 0 ? 0 : ms / steps)) };
|
|
49
|
-
}
|
|
50
|
-
/** The ghost's eye row with the eyes closed: the two gaps filled with a low half block, like lids. */
|
|
51
|
-
export const CLOSED_EYES = GHOST[1][0].replace(/ (?=█)/, '▄').replace(/ $/, '▄');
|
|
52
|
-
/**
|
|
53
|
-
* The brand header drawing in, for a screen whose lines start with it
|
|
54
|
-
* (setup): PHANTOM appears letter by letter, the rest of the screen follows
|
|
55
|
-
* row by row, then the ghost blinks once.
|
|
56
|
-
*/
|
|
57
|
-
export function brandIntro(lines, opts = {}) {
|
|
58
|
-
const { letterMs = 20, rowMs = 18, blinkMs = 90 } = opts;
|
|
59
|
-
const wordRows = lines.map((l, k) => [k, WORDMARK.findIndex((w) => l.includes(w))]).filter(([, r]) => r >= 0);
|
|
60
|
-
const eyeRow = lines.findIndex((l) => l.includes(GHOST[1][0]));
|
|
61
|
-
const headerEnd = Math.max(eyeRow, ...wordRows.map(([k]) => k)) + 2;
|
|
62
|
-
const book = { frames: [], delays: [] };
|
|
63
|
-
const push = (frame, wait) => (book.frames.push(frame), book.delays.push(book.frames.length === 1 ? 0 : wait));
|
|
64
|
-
// 1. The ghost, then PHANTOM letter by letter beside it.
|
|
65
|
-
const letterCount = 7;
|
|
66
|
-
for (let n = 0; n <= letterCount; n++) {
|
|
67
|
-
push(lines.map((l, k) => {
|
|
68
|
-
if (k >= headerEnd)
|
|
69
|
-
return '';
|
|
70
|
-
const hit = wordRows.find(([row]) => row === k);
|
|
71
|
-
if (!hit)
|
|
72
|
-
return l;
|
|
73
|
-
return l.replace(WORDMARK[hit[1]], lettersOf(hit[1], n));
|
|
74
|
-
}), letterMs);
|
|
75
|
-
}
|
|
76
|
-
// 2. The rest of the screen, a row at a time.
|
|
77
|
-
for (let k = headerEnd; k < lines.length; k++)
|
|
78
|
-
push(lines.map((l, j) => (j <= k ? l : '')), lines[k] ? rowMs : 0);
|
|
79
|
-
// 3. One blink.
|
|
80
|
-
if (eyeRow >= 0) {
|
|
81
|
-
push(lines.map((l, k) => (k === eyeRow ? l.replace(GHOST[1][0], CLOSED_EYES) : l)), blinkMs);
|
|
82
|
-
push(lines, blinkMs);
|
|
83
|
-
}
|
|
84
|
-
return book;
|
|
85
|
-
}
|
|
86
|
-
/** Row `row` of PHANTOM with its first `n` letters drawn and the rest left as spaces. */
|
|
87
|
-
function lettersOf(row, n) {
|
|
88
|
-
const full = WORDMARK[row];
|
|
89
|
-
const cut = LETTER_ENDS[n];
|
|
90
|
-
return full.slice(0, cut).padEnd(full.length);
|
|
91
|
-
}
|
|
92
|
-
/** Where each letter of PHANTOM ends in a wordmark row (the rows share widths): 0 letters, 1 letter and so on. */
|
|
93
|
-
const LETTER_ENDS = (() => {
|
|
94
|
-
const widths = [4, 4, 4, 4, 3, 4, 5];
|
|
95
|
-
const ends = [0];
|
|
96
|
-
widths.forEach((w, k) => ends.push(ends[k] + w + (k ? 1 : 0)));
|
|
97
|
-
return ends;
|
|
98
|
-
})();
|
|
99
|
-
/** Wait `ms` milliseconds. Tests pass their own so they don't wait. */
|
|
100
|
-
const realSleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
101
|
-
/**
|
|
102
|
-
* Plays a flipbook on a stream: writes the first frame, then moves the cursor
|
|
103
|
-
* back up and redraws each next one in place. Ends on the last frame with a
|
|
104
|
-
* newline. A key press (on a terminal) or `rows` too few to fit the block
|
|
105
|
-
* skips straight to the last frame.
|
|
106
|
-
*/
|
|
107
|
-
export async function play(write, book, opts = {}) {
|
|
108
|
-
const last = book.frames[book.frames.length - 1] ?? [];
|
|
109
|
-
// Taller than the window: moving the cursor up would run off the top, so print the result.
|
|
110
|
-
if (!book.frames.length || (opts.rows !== undefined && last.length >= opts.rows)) {
|
|
111
|
-
write(last.join('\n') + '\n');
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
const sleep = opts.sleep ?? realSleep;
|
|
115
|
-
const stopSkip = opts.skipOnKey ? listenForKey() : null;
|
|
116
|
-
try {
|
|
117
|
-
write(book.frames[0].join('\n'));
|
|
118
|
-
for (let k = 1; k < book.frames.length; k++) {
|
|
119
|
-
if (stopSkip?.pressed())
|
|
120
|
-
break;
|
|
121
|
-
await sleep(book.delays[k]);
|
|
122
|
-
write(redraw(book.frames[k]));
|
|
123
|
-
}
|
|
124
|
-
if (stopSkip?.pressed())
|
|
125
|
-
write(redraw(last));
|
|
126
|
-
write('\n');
|
|
127
|
-
}
|
|
128
|
-
finally {
|
|
129
|
-
stopSkip?.stop();
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
/** The codes that move back to the block's first line and write `frame` over it, clearing each line first. */
|
|
133
|
-
function redraw(frame) {
|
|
134
|
-
const up = frame.length > 1 ? `\x1b[${frame.length - 1}A` : '';
|
|
135
|
-
return `\r${up}` + frame.map((line) => `\x1b[2K${line}`).join('\n');
|
|
136
|
-
}
|
|
137
|
-
/** Watches the keyboard while an animation plays, so any key skips it. Leaves the terminal as it found it. */
|
|
138
|
-
function listenForKey() {
|
|
139
|
-
const input = process.stdin;
|
|
140
|
-
if (!input.isTTY || typeof input.setRawMode !== 'function')
|
|
141
|
-
return null;
|
|
142
|
-
let hit = false;
|
|
143
|
-
const onData = () => void (hit = true);
|
|
144
|
-
const wasRaw = input.isRaw;
|
|
145
|
-
input.setRawMode(true);
|
|
146
|
-
input.on('data', onData);
|
|
147
|
-
input.resume();
|
|
148
|
-
return {
|
|
149
|
-
pressed: () => hit,
|
|
150
|
-
stop: () => {
|
|
151
|
-
input.off('data', onData);
|
|
152
|
-
input.setRawMode(wasRaw);
|
|
153
|
-
input.pause();
|
|
154
|
-
},
|
|
155
|
-
};
|
|
156
|
-
}
|
package/dist/core/shapes.d.mts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/** The answer from GET /key/balance. */
|
|
2
|
-
export type BalanceResult = {
|
|
3
|
-
/** True while the key is switched on and not past its expiry. */
|
|
4
|
-
active: boolean;
|
|
5
|
-
/** The kind of key the server stores: `credit`, `pass` or `faucet`. */
|
|
6
|
-
kind: string;
|
|
7
|
-
/** Credit left on the key, in USD. */
|
|
8
|
-
credit_balance_usd: number;
|
|
9
|
-
/** Credit the key has spent, in USD. */
|
|
10
|
-
credit_spent_usd: number;
|
|
11
|
-
/** When the key stops working, as an ISO 8601 time. */
|
|
12
|
-
expires_at: string;
|
|
13
|
-
};
|
package/dist/core/shapes.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|