@phantomcodes/cli 1.6.3 → 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 -118
- 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/setup/plan.mjs
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import { fileURLToPath } from 'node:url';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import os from 'node:os';
|
|
4
|
-
import { existsSync, readFileSync } from 'node:fs';
|
|
5
|
-
import { CliError, die } from "../core/errors.mjs";
|
|
6
|
-
import { resolveApiKey } from "../keys/saved.mjs";
|
|
7
|
-
import { readText } from "./shared.mjs";
|
|
8
|
-
import { shellRcFile, withShellBlock } from "./editors.mjs";
|
|
9
|
-
import { SETUP_AGENTS, SETUP_NAMES, orList } from "./agents.mjs";
|
|
10
|
-
function skillSource() {
|
|
11
|
-
// The skill is in the package's skills/ folder, two up from this file in
|
|
12
|
-
// both src/setup/ and dist/setup/.
|
|
13
|
-
const p = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', '..', 'skills', 'phantom-ai', 'SKILL.md');
|
|
14
|
-
if (existsSync(p))
|
|
15
|
-
return p;
|
|
16
|
-
die('The phantom-ai skill is missing from this install');
|
|
17
|
-
}
|
|
18
|
-
const isSkip = (err) => err instanceof CliError && err.code === 'setup_unreadable';
|
|
19
|
-
/**
|
|
20
|
-
* Works out what setup would change, and writes nothing: the skill for each
|
|
21
|
-
* agent ({@link SETUP_AGENTS}), each agent's model
|
|
22
|
-
* settings with `provider` ({@link SetupAgentSpec.provider}), and the shell
|
|
23
|
-
* block ({@link shellBlock}) for agents that read the key from the
|
|
24
|
-
* environment. A config file setup can't edit safely is left out and listed
|
|
25
|
-
* in `skipped`.
|
|
26
|
-
* @throws {@link CliError} when no agent is found, the agent is unknown, the model is not a plain id, `provider` is set without an agent that supports it, or there is no key for `provider`.
|
|
27
|
-
*/
|
|
28
|
-
export function planSetup(env, opts = {}) {
|
|
29
|
-
const home = env.HOME || os.homedir();
|
|
30
|
-
const names = SETUP_NAMES;
|
|
31
|
-
let picked;
|
|
32
|
-
if (!opts.agent || opts.agent === 'all') {
|
|
33
|
-
picked = names.filter((a) => SETUP_AGENTS[a].detect?.(env, home) ?? existsSync(path.join(home, SETUP_AGENTS[a].home)));
|
|
34
|
-
if (picked.length === 0) {
|
|
35
|
-
const looked = names.map((a) => `${SETUP_AGENTS[a].label} (~/${SETUP_AGENTS[a].home})`).join(', ');
|
|
36
|
-
die(`No supported coding agents were found on this computer. phantom looks for these folders: ${looked}. Install one, or set up a specific one with --agent <name> (${names.join(', ')}).`, 'no_agents_found');
|
|
37
|
-
}
|
|
38
|
-
if (opts.only)
|
|
39
|
-
picked = picked.filter((a) => opts.only.includes(a));
|
|
40
|
-
}
|
|
41
|
-
else if (names.includes(opts.agent)) {
|
|
42
|
-
picked = [opts.agent];
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
die(`Unknown agent: ${opts.agent}. Use ${names.join(', ')} or all`);
|
|
46
|
-
}
|
|
47
|
-
// The model goes into shell and config files, so it must be a plain id.
|
|
48
|
-
if (opts.model !== undefined && !/^[A-Za-z0-9][A-Za-z0-9._:/@[\]-]*$/.test(opts.model))
|
|
49
|
-
die(`Not a model id: ${opts.model}`, 'model_invalid');
|
|
50
|
-
const notes = [];
|
|
51
|
-
let provider = opts.provider ?? false;
|
|
52
|
-
if (provider && !picked.some((a) => SETUP_AGENTS[a].provider)) {
|
|
53
|
-
if (opts.guided)
|
|
54
|
-
provider = false;
|
|
55
|
-
else {
|
|
56
|
-
const able = names.filter((a) => SETUP_AGENTS[a].provider);
|
|
57
|
-
die(`--provider sets up ${orList(able.map((a) => SETUP_AGENTS[a].label))}; add --agent ${orList(able)}`, 'provider_agent');
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
if (provider === true && !resolveApiKey(env)) {
|
|
61
|
-
if (!opts.guided)
|
|
62
|
-
die('No Phantom key yet to give the agents. Run phantom login to sign in, then run this again.', 'no_key');
|
|
63
|
-
notes.push('No Phantom key yet, so only the skills are installed. Run phantom setup in a terminal to sign in and set up the rest.');
|
|
64
|
-
provider = false;
|
|
65
|
-
}
|
|
66
|
-
const ctx = { env, home, onPath: opts.onPath, model: opts.model, shellRc: shellRcFile(env, home) };
|
|
67
|
-
const files = [];
|
|
68
|
-
const skipped = [];
|
|
69
|
-
const agents = [];
|
|
70
|
-
const add = (agent, file, after, skill = false, mode, was) => {
|
|
71
|
-
const known = files.find((f) => f.file === file);
|
|
72
|
-
if (known) {
|
|
73
|
-
known.after = after;
|
|
74
|
-
if (mode)
|
|
75
|
-
known.mode = mode;
|
|
76
|
-
if (was !== undefined)
|
|
77
|
-
known.was = was;
|
|
78
|
-
known.action = known.before === null ? 'create' : after === null ? 'remove' : 'update';
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
const before = readText(file);
|
|
82
|
-
if (before === after)
|
|
83
|
-
return;
|
|
84
|
-
files.push({ agent, file, action: before === null ? 'create' : after === null ? 'remove' : 'update', before, after, ...(skill ? { skill } : {}), ...(mode ? { mode } : {}), ...(was !== undefined ? { was } : {}) });
|
|
85
|
-
};
|
|
86
|
-
const skillText = readFileSync(skillSource(), 'utf-8');
|
|
87
|
-
const shellOn = new Map();
|
|
88
|
-
const shellOff = [];
|
|
89
|
-
for (const agent of picked) {
|
|
90
|
-
const spec = SETUP_AGENTS[agent];
|
|
91
|
-
const skill = spec.skills ? path.join(home, spec.skills, 'phantom-ai', 'SKILL.md') : null;
|
|
92
|
-
if (skill)
|
|
93
|
-
add(agent, skill, skillText, true);
|
|
94
|
-
let result;
|
|
95
|
-
if (provider && spec.provider) {
|
|
96
|
-
try {
|
|
97
|
-
const p = spec.provider(ctx, provider === 'off');
|
|
98
|
-
for (const e of p.edits)
|
|
99
|
-
add(agent, e.file, e.after, false, e.mode, e.was);
|
|
100
|
-
result = p.result;
|
|
101
|
-
if (spec.shellEnv) {
|
|
102
|
-
if (provider === 'off')
|
|
103
|
-
shellOff.push(agent);
|
|
104
|
-
else
|
|
105
|
-
shellOn.set(agent, spec.shellEnv(ctx));
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
catch (err) {
|
|
109
|
-
if (!isSkip(err))
|
|
110
|
-
throw err;
|
|
111
|
-
skipped.push({ agent, reason: err.message });
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
agents.push({ agent, skill, ...(result ? { provider: result } : {}) });
|
|
115
|
-
}
|
|
116
|
-
if (shellOn.size && opts.shell === false) {
|
|
117
|
-
const block = withShellBlock(env, ctx.shellRc, '', shellOn, [], opts.onPath) ?? '';
|
|
118
|
-
const short = ctx.shellRc.startsWith(home + path.sep) ? '~' + ctx.shellRc.slice(home.length) : ctx.shellRc;
|
|
119
|
-
notes.push(`Your shell file was left alone. So ${orList([...shellOn.keys()].map((a) => SETUP_AGENTS[a].label))} can find your key, add these lines to ${short}:`, '', ...block.trimEnd().split('\n').map((l) => ` ${l}`));
|
|
120
|
-
}
|
|
121
|
-
else if (shellOn.size || shellOff.length) {
|
|
122
|
-
try {
|
|
123
|
-
add('shell', ctx.shellRc, withShellBlock(env, ctx.shellRc, readText(ctx.shellRc), shellOn, shellOff, opts.onPath));
|
|
124
|
-
}
|
|
125
|
-
catch (err) {
|
|
126
|
-
if (!isSkip(err))
|
|
127
|
-
throw err;
|
|
128
|
-
skipped.push({ agent: 'shell', reason: err.message });
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
return { agents, files, skipped, notes };
|
|
132
|
-
}
|
package/dist/setup/screen.d.mts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { Env } from '../core/state.mts';
|
|
2
|
-
import type { SetupResult } from './plan.mts';
|
|
3
|
-
/** Which moment the screen shows. */
|
|
4
|
-
export type ScreenMode =
|
|
5
|
-
/** Before "Make these changes?": what setup is about to do. */
|
|
6
|
-
'ask'
|
|
7
|
-
/** `--dry-run`: what setup would do; nothing was written. */
|
|
8
|
-
| 'dry'
|
|
9
|
-
/** The user said no at the prompt. */
|
|
10
|
-
| 'declined'
|
|
11
|
-
/** The changes are made. */
|
|
12
|
-
| 'done';
|
|
13
|
-
export type ScreenOptions = {
|
|
14
|
-
/** The environment, for the home folder (shown as ~) and the terminal's colors. */
|
|
15
|
-
env?: Env;
|
|
16
|
-
/** Print color, and the ghost. Off unless asked for, so tests and pipes get plain text. */
|
|
17
|
-
color?: boolean;
|
|
18
|
-
/** Show every line each file gains or loses (`--diff`). */
|
|
19
|
-
diff?: boolean;
|
|
20
|
-
/** Which moment to show. Worked out from the result when left out. */
|
|
21
|
-
mode?: ScreenMode;
|
|
22
|
-
/** The terminal's width, so long lines wrap at a word with an indent. 100 when unknown. */
|
|
23
|
-
columns?: number;
|
|
24
|
-
/** Say how to see every line. Off when a picker offers that as a choice instead. */
|
|
25
|
-
hint?: boolean;
|
|
26
|
-
};
|
|
27
|
-
/** `text` broken at spaces into lines of at most `width` characters; a single longer word stays whole. */
|
|
28
|
-
export declare function wrapWords(text: string, width: number): string[];
|
|
29
|
-
/** `phantom setup`'s screen for one result. See {@link ScreenMode} for the moments it shows. */
|
|
30
|
-
export declare function setupScreen(r: SetupResult, opts?: ScreenOptions): string;
|
package/dist/setup/screen.mjs
DELETED
|
@@ -1,260 +0,0 @@
|
|
|
1
|
-
// How `phantom setup` looks in a terminal, drawn in the site's style: the
|
|
2
|
-
// ghost and a title, an uppercase caption over a thin rule, one row per agent
|
|
3
|
-
// with its files lined up in columns, and after the changes a ✓ per agent and
|
|
4
|
-
// the next step in corner brackets, like the site's hero.
|
|
5
|
-
// The JSON result (setupCommand without a terminal) never goes through here.
|
|
6
|
-
import os from 'node:os';
|
|
7
|
-
import path from 'node:path';
|
|
8
|
-
import { fitText, paint, unstyled } from "../core/style.mjs";
|
|
9
|
-
import { brandHeader } from "../core/brand.mjs";
|
|
10
|
-
import { inApp } from "../cli/screens.mjs";
|
|
11
|
-
import { SETUP_AGENTS } from "./agents.mjs";
|
|
12
|
-
import { FREE_LINE } from "../core/free.mjs";
|
|
13
|
-
/** `text` broken at spaces into lines of at most `width` characters; a single longer word stays whole. */
|
|
14
|
-
export function wrapWords(text, width) {
|
|
15
|
-
const lines = [];
|
|
16
|
-
let line = '';
|
|
17
|
-
for (const word of text.split(' ')) {
|
|
18
|
-
if (line && (line + ' ' + word).length > width) {
|
|
19
|
-
lines.push(line);
|
|
20
|
-
line = word;
|
|
21
|
-
}
|
|
22
|
-
else
|
|
23
|
-
line = line ? line + ' ' + word : word;
|
|
24
|
-
}
|
|
25
|
-
return [...lines, line];
|
|
26
|
-
}
|
|
27
|
-
/** The name a person knows an agent by: "Claude Code", or "Your shell" for the startup file. */
|
|
28
|
-
const label = (agent) => (agent === 'shell' ? 'Your shell' : (SETUP_AGENTS[agent]?.label ?? agent));
|
|
29
|
-
/** How many lines a diff from `lineDiff` adds and removes. */
|
|
30
|
-
function counts(diff) {
|
|
31
|
-
const rows = (diff ?? '').split('\n');
|
|
32
|
-
return { added: rows.filter((r) => r.startsWith('+')).length, removed: rows.filter((r) => r.startsWith('-')).length };
|
|
33
|
-
}
|
|
34
|
-
/** An uppercase caption over a thin rule, like the site's section labels (SPEND, CALLS). */
|
|
35
|
-
function caption(p, text, extra, width) {
|
|
36
|
-
return [` ${p.bold(text)} ${extra}`.trimEnd(), ` ${p.dim('─'.repeat(width))}`];
|
|
37
|
-
}
|
|
38
|
-
/** Text framed by corner brackets, the site's hero frame, for the one thing to do next. */
|
|
39
|
-
function framed(p, text, columns) {
|
|
40
|
-
const inner = unstyled(text).length + 4;
|
|
41
|
-
// Too wide for the window: the corners would wrap away from the text, so it's a plain line instead.
|
|
42
|
-
if (columns && inner + 4 > columns)
|
|
43
|
-
return [` ${text}`];
|
|
44
|
-
return [` ${p.lime('┌')}${' '.repeat(inner)}${p.lime('┐')}`, ` ${text}`, ` ${p.lime('└')}${' '.repeat(inner)}${p.lime('┘')}`];
|
|
45
|
-
}
|
|
46
|
-
/** `phantom setup`'s screen for one result. See {@link ScreenMode} for the moments it shows. */
|
|
47
|
-
export function setupScreen(r, opts = {}) {
|
|
48
|
-
const env = opts.env ?? {};
|
|
49
|
-
const color = Boolean(opts.color);
|
|
50
|
-
const p = paint(env, color);
|
|
51
|
-
const mode = opts.mode ?? (r.dry_run ? 'dry' : r.applied === false ? 'declined' : 'done');
|
|
52
|
-
// The list is already on screen above the question, so a no only needs saying.
|
|
53
|
-
if (mode === 'declined')
|
|
54
|
-
return '\n Nothing was changed.';
|
|
55
|
-
const home = env.HOME || os.homedir();
|
|
56
|
-
const short = (file) => (file === home || file.startsWith(home + path.sep) ? '~' + file.slice(home.length) : file);
|
|
57
|
-
// Rows run in the order setup found the agents, then the shell file last.
|
|
58
|
-
const agents = [...r.agents.map((a) => a.agent), ...(r.files.some((f) => f.agent === 'shell') ? ['shell'] : [])];
|
|
59
|
-
const skipped = (r.skipped ?? []).filter((s) => !agents.includes(s.agent));
|
|
60
|
-
const names = [...agents, ...skipped.map((s) => s.agent)];
|
|
61
|
-
const width = Math.max(12, ...names.map((a) => label(a).length + 2));
|
|
62
|
-
const pad = ' '.repeat(width + 4);
|
|
63
|
-
const name = (agent) => p.bold(label(agent).padEnd(width));
|
|
64
|
-
// Every path is padded to the longest, so the line counts form one column,
|
|
65
|
-
// unless that's wider than the window: then rows stay short and unaligned.
|
|
66
|
-
const longest = Math.max(0, ...r.files.map((f) => short(f.file).length));
|
|
67
|
-
const columns = opts.columns ?? process.stdout.columns ?? 100;
|
|
68
|
-
// The widest "what happens" phrase (`new file, 12 lines`), plus room for "copy kept".
|
|
69
|
-
const said = Math.max(8, ...r.files.map((f) => change(f).length + (f.backup ? 11 : 0)));
|
|
70
|
-
const fits = width + 4 + 10 + longest + 2 + said <= columns;
|
|
71
|
-
const pathWidth = fits ? longest : 0;
|
|
72
|
-
// As wide as a file row (name, kind, path, action and a line count), and never wider than the window.
|
|
73
|
-
const rule = Math.max(20, Math.min(width + 2 + 10 + longest + 2 + said, columns - 4));
|
|
74
|
-
// After the prompt, a blank line sets the result apart from the answer typed above it.
|
|
75
|
-
const lines = [''];
|
|
76
|
-
const found = r.agents.length;
|
|
77
|
-
if (mode !== 'done') {
|
|
78
|
-
lines.push(...brandHeader(p, color, 'setup'), ...caption(p, 'AGENTS FOUND', p.lime(p.bold(String(found))), rule));
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
lines.push(...caption(p, 'DONE', '', rule));
|
|
82
|
-
}
|
|
83
|
-
for (const agent of agents) {
|
|
84
|
-
const a = r.agents.find((x) => x.agent === agent);
|
|
85
|
-
// The agent's settings before its skill: the settings are what change how it runs.
|
|
86
|
-
const files = r.files.filter((f) => f.agent === agent).sort((x, y) => Number(!x.diff) - Number(!y.diff));
|
|
87
|
-
const skip = (r.skipped ?? []).filter((s) => s.agent === agent);
|
|
88
|
-
const manual = a?.provider?.manual ?? [];
|
|
89
|
-
const warnings = a?.provider?.warnings ?? [];
|
|
90
|
-
const detail = [];
|
|
91
|
-
if (mode === 'done') {
|
|
92
|
-
// Turning Phantom off for an agent that was never on changed nothing, so it gets no check mark.
|
|
93
|
-
const unchanged = !files.length && a?.provider && !a.provider.on;
|
|
94
|
-
const mark = skip.length ? p.red('✗') : manual.length ? p.yellow('!') : unchanged ? p.dim('·') : p.lime('✓');
|
|
95
|
-
lines.push(` ${mark} ${name(agent)}${doneSummary(agent, a, files.length, skip.length > 0, p)}`);
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
// The files first, so the eye reads down one column of paths.
|
|
99
|
-
const [first, ...rest] = files.map((f) => fileRow(f, p, short, pathWidth));
|
|
100
|
-
lines.push(` ${name(agent)}${first ?? p.dim(manual.length ? 'nothing to write' : 'already set up')}`);
|
|
101
|
-
for (const row of rest)
|
|
102
|
-
detail.push(pad + row);
|
|
103
|
-
if (opts.diff) {
|
|
104
|
-
for (const f of files.filter((x) => x.diff)) {
|
|
105
|
-
detail.push('', ...f.diff.split('\n').map((row) => pad + ' ' + diffRow(row, p)), '');
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
for (const s of skip)
|
|
110
|
-
detail.push(pad + p.red(`skipped: ${s.reason}`));
|
|
111
|
-
for (const w of warnings)
|
|
112
|
-
detail.push(pad + p.yellow(w));
|
|
113
|
-
// Steps to do by hand show once, after the changes, when they can be done.
|
|
114
|
-
if (manual.length && mode !== 'done')
|
|
115
|
-
detail.push(pad + p.yellow(`then a few steps by hand in ${a?.provider?.settings}, shown after`));
|
|
116
|
-
else if (manual.length) {
|
|
117
|
-
detail.push(pad + p.yellow(`In ${a?.provider?.settings}:`));
|
|
118
|
-
// Each step wraps under its own first word, not under the number.
|
|
119
|
-
const room = Math.max(30, (opts.columns ?? 100) - pad.length - 5);
|
|
120
|
-
manual.forEach((step, k) => {
|
|
121
|
-
const [first, ...rest] = wrapWords(step, room);
|
|
122
|
-
detail.push(`${pad} ${p.dim(`${k + 1}.`)} ${first}`, ...rest.map((l) => `${pad} ${l}`));
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
lines.push(...detail);
|
|
126
|
-
}
|
|
127
|
-
for (const s of skipped)
|
|
128
|
-
lines.push(` ${mode === 'done' ? p.red('✗') + ' ' : ' '}${name(s.agent)}${p.red(`skipped: ${s.reason}`)}`);
|
|
129
|
-
const notes = r.notes ?? [];
|
|
130
|
-
if (notes.length)
|
|
131
|
-
lines.push('', ...notes.map((n) => ` ${n}`));
|
|
132
|
-
if (mode === 'ask' || mode === 'dry') {
|
|
133
|
-
// The file list says where; these lines say what it means, in plain words, before anyone reads a diff.
|
|
134
|
-
const routes = r.files.some((f) => f.diff && f.agent !== 'shell');
|
|
135
|
-
const skills = r.files.some((f) => !f.diff);
|
|
136
|
-
if (routes || skills)
|
|
137
|
-
lines.push('');
|
|
138
|
-
if (routes) {
|
|
139
|
-
lines.push(` ${p.dim('What this does:')} these agents send their model requests to Phantom AI, and phantom-1 picks the model.`);
|
|
140
|
-
lines.push(` ${p.dim('Free to start:')} ${FREE_LINE}.`);
|
|
141
|
-
// Claude Code's settings file applies in every folder, so its own login stops being used.
|
|
142
|
-
if (r.agents.some((a) => a.agent === 'claude' && a.provider?.on)) {
|
|
143
|
-
lines.push(` ${p.dim('Claude Code:')} uses Phantom AI in place of your Anthropic login, in every folder. To keep your login, leave Claude Code out and start it with ${p.cyan('phantom claude')} when you want Phantom.`);
|
|
144
|
-
}
|
|
145
|
-
const readers = r.agents.filter((a) => a.provider?.on && SETUP_AGENTS[a.agent]?.shellEnv);
|
|
146
|
-
if (readers.length && r.files.some((f) => f.agent === 'shell')) {
|
|
147
|
-
lines.push(` ${p.dim('Your shell:')} new terminals get your key as PHANTOM_API_KEY, for ${readers.map((a) => label(a.agent)).join(', ')}. The file runs ${p.cyan('phantom key show')}; the key itself isn't written in it.`);
|
|
148
|
-
}
|
|
149
|
-
lines.push(` ${p.dim('Undo:')} phantom keeps a copy of each file it changes, and ${p.cyan('phantom setup --restore')} puts them back.`);
|
|
150
|
-
}
|
|
151
|
-
if (skills)
|
|
152
|
-
lines.push(` ${p.dim('Skill:')} a file that teaches the agent the phantom commands.`);
|
|
153
|
-
// Most people only see the 'ask' screen, so its hint is the plain command they just ran, plus --diff.
|
|
154
|
-
if (!opts.diff && opts.hint !== false && r.files.some((f) => f.diff)) {
|
|
155
|
-
lines.push('', mode === 'ask' ? ` To see every line first, answer n and run: ${p.cyan('phantom setup --diff')}` : ` To see every line, add ${p.cyan('--diff')}.`);
|
|
156
|
-
}
|
|
157
|
-
if (mode === 'dry')
|
|
158
|
-
lines.push(p.dim(' This was a preview. Nothing was changed.'));
|
|
159
|
-
}
|
|
160
|
-
else if (!r.files.length && !(r.skipped ?? []).length && !r.agents.some((a) => a.provider?.manual?.length)) {
|
|
161
|
-
const off = r.agents.length > 0 && r.agents.every((a) => a.provider && !a.provider.on);
|
|
162
|
-
lines.push(off ? ` ${p.dim('·')} Phantom AI was already off for these agents. Nothing to change.` : ` ${p.lime('✓')} Everything is already set up. Nothing to change.`);
|
|
163
|
-
}
|
|
164
|
-
else if (r.files.length) {
|
|
165
|
-
lines.push('', ...nextStep(r, p, opts.columns));
|
|
166
|
-
lines.push('', inApp() ? ` ${p.dim('Undo any time: More, then Undo setup.')}` : ` Undo any time: ${p.cyan('phantom setup --restore')}`);
|
|
167
|
-
}
|
|
168
|
-
// Long sentences break at a word under their own indent, at the terminal's width.
|
|
169
|
-
return fitText(lines.join('\n'), columns);
|
|
170
|
-
}
|
|
171
|
-
/** What a file is, in the words the screen uses: its settings (an agent's, or the shell's ~/.zshrc), or its skill. */
|
|
172
|
-
function kind(f) {
|
|
173
|
-
if (!f.diff)
|
|
174
|
-
return 'skill';
|
|
175
|
-
// ~/.zshrc is the shell's own settings file, and the row already says "Your shell".
|
|
176
|
-
return 'settings';
|
|
177
|
-
}
|
|
178
|
-
/** `n lines`, or `1 line`. */
|
|
179
|
-
const lineCount = (n) => `${n} line${n === 1 ? '' : 's'}`;
|
|
180
|
-
/**
|
|
181
|
-
* What happens to a file, in words: `new file, 12 lines`, `adds 3 lines`,
|
|
182
|
-
* `adds 3, removes 1`, `updated` (a skill) or `deleted`.
|
|
183
|
-
*/
|
|
184
|
-
function change(f) {
|
|
185
|
-
const { added, removed } = counts(f.diff);
|
|
186
|
-
if (f.action === 'remove')
|
|
187
|
-
return 'deleted';
|
|
188
|
-
if (f.action === 'create')
|
|
189
|
-
return added ? `new file, ${lineCount(added)}` : 'new file';
|
|
190
|
-
if (!f.diff)
|
|
191
|
-
return 'updated';
|
|
192
|
-
return removed ? `adds ${added}, removes ${removed}` : `adds ${lineCount(added)}`;
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* One file under an agent, in columns: what the file is, where it is, and
|
|
196
|
-
* what happens to it. For example `settings ~/.codex/config.toml new file, 12 lines`.
|
|
197
|
-
*/
|
|
198
|
-
function fileRow(f, p, short, pathWidth) {
|
|
199
|
-
const what = change(f);
|
|
200
|
-
return [
|
|
201
|
-
p.dim(kind(f).padEnd(8)),
|
|
202
|
-
short(f.file).padEnd(pathWidth),
|
|
203
|
-
(f.action === 'remove' ? p.red(what) : p.cyan(what)) + (f.backup ? p.dim(' copy kept') : ''),
|
|
204
|
-
]
|
|
205
|
-
.join(' ')
|
|
206
|
-
.trimEnd();
|
|
207
|
-
}
|
|
208
|
-
/** One line of a diff, colored by whether it adds, removes or only shows context. */
|
|
209
|
-
function diffRow(row, p) {
|
|
210
|
-
if (row.startsWith('+'))
|
|
211
|
-
return p.green(row);
|
|
212
|
-
if (row.startsWith('-'))
|
|
213
|
-
return p.red(row);
|
|
214
|
-
return p.dim(row);
|
|
215
|
-
}
|
|
216
|
-
/** After the changes: one plain sentence per agent on what it does now. */
|
|
217
|
-
function doneSummary(agent, a, files, skipped, p) {
|
|
218
|
-
if (skipped)
|
|
219
|
-
return p.red('left as it was.');
|
|
220
|
-
if (agent === 'shell')
|
|
221
|
-
return 'loads your Phantom AI key in new terminals.';
|
|
222
|
-
const prov = a?.provider;
|
|
223
|
-
if (prov?.manual?.length)
|
|
224
|
-
return p.yellow('not finished: do these steps by hand.');
|
|
225
|
-
if (prov && !prov.on)
|
|
226
|
-
return !files ? p.dim('already off: nothing to remove.') : agent === 'claude' ? 'back on Anthropic.' : 'Phantom AI settings removed.';
|
|
227
|
-
if (prov?.on) {
|
|
228
|
-
const model = prov.model ? ` ${p.pill(` ${prov.model} `)}` : '';
|
|
229
|
-
return `runs on Phantom AI${model} ${p.dim(`restart ${label(agent)} to pick it up`)}`;
|
|
230
|
-
}
|
|
231
|
-
return files ? 'skill installed.' : p.dim('already set up.');
|
|
232
|
-
}
|
|
233
|
-
/** The command that starts each agent that runs in a terminal. Editors (Cursor, Continue, Cline) are opened, not run. */
|
|
234
|
-
const START = { claude: 'claude', codex: 'codex', pi: 'pi', opencode: 'opencode', goose: 'goose', aider: 'aider', copilot: 'copilot', gemini: 'gemini', crush: 'crush', qwen: 'qwen', kilo: 'kilo', kimi: 'kimi', droid: 'droid', vibe: 'vibe' };
|
|
235
|
-
/**
|
|
236
|
-
* The one thing to do after setup, in corner brackets: run the agent. When an
|
|
237
|
-
* agent reads its key from the shell (Codex, Goose and others), the step says
|
|
238
|
-
* to open a new terminal first, and names that agent; otherwise it doesn't.
|
|
239
|
-
*/
|
|
240
|
-
function nextStep(r, p, columns) {
|
|
241
|
-
const on = r.agents.filter((a) => a.provider?.on || (!a.provider && r.files.some((f) => f.agent === a.agent)));
|
|
242
|
-
const shell = r.files.some((f) => f.agent === 'shell');
|
|
243
|
-
const readsShell = on.filter((a) => SETUP_AGENTS[a.agent]?.shellEnv);
|
|
244
|
-
const first = (readsShell.length && shell ? readsShell : on).find((a) => START[a.agent]) ?? on[0];
|
|
245
|
-
if (!first)
|
|
246
|
-
return [];
|
|
247
|
-
const cmd = START[first.agent];
|
|
248
|
-
const name = label(first.agent);
|
|
249
|
-
const step = cmd
|
|
250
|
-
? shell && readsShell.some((a) => a.agent === first.agent)
|
|
251
|
-
? `${p.lime('→')} ${p.bold('Open a new terminal')}, then run ${p.cyan(cmd)}`
|
|
252
|
-
: `${p.lime('→')} ${p.bold('Next:')} run ${p.cyan(cmd)}`
|
|
253
|
-
: `${p.lime('→')} ${p.bold('Next:')} open ${name}`;
|
|
254
|
-
const lines = framed(p, step, columns);
|
|
255
|
-
if (cmd && ['claude', 'codex', 'pi'].includes(first.agent))
|
|
256
|
-
lines.push(p.dim(` or start it through phantom: phantom ${first.agent}`));
|
|
257
|
-
if (shell && readsShell.length)
|
|
258
|
-
lines.push(p.dim(` ${readsShell.map((a) => label(a.agent)).join(', ')} ${readsShell.length === 1 ? 'reads' : 'read'} your Phantom AI key from the shell, so a new terminal is needed.`));
|
|
259
|
-
return lines;
|
|
260
|
-
}
|
package/dist/setup/shared.d.mts
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import type { Env } from '../core/state.mts';
|
|
2
|
-
import type { JsonWas } from './was.mts';
|
|
3
|
-
/** True when `bin` is a program on PATH. */
|
|
4
|
-
export declare function onPath(bin: string): boolean;
|
|
5
|
-
/**
|
|
6
|
-
* `phantom setup` installs the phantom-ai skill where each agent looks for skills,
|
|
7
|
-
* and points each agent's own model calls at Phantom AI. Every agent here
|
|
8
|
-
* reads the same SKILL.md format, so one file serves all of them.
|
|
9
|
-
*
|
|
10
|
-
* Nothing is written straight away. {@link planSetup} works out each file's
|
|
11
|
-
* text before and after, so `phantom setup` can show the change as a diff and ask
|
|
12
|
-
* first, and {@link applySetup} writes it, keeping a copy of each file it
|
|
13
|
-
* edits beside it as `<file>.phantom.bak`. Lines phantom adds to a TOML, YAML or shell
|
|
14
|
-
* file end with `# phantom setup`, so `--provider off` removes exactly those.
|
|
15
|
-
*
|
|
16
|
-
* The key never goes into an agent's config. Claude Code runs `phantom key show`
|
|
17
|
-
* through `apiKeyHelper`. Agents that read an environment variable get
|
|
18
|
-
* PHANTOM_API_KEY from a block phantom adds to the shell's startup file, which
|
|
19
|
-
* reads the key from the macOS Keychain (or `phantom key show`) each time a shell
|
|
20
|
-
* starts ({@link shellBlock}). Cursor and Cline keep their model settings on
|
|
21
|
-
* their own settings screens, so setup prints the steps.
|
|
22
|
-
*/
|
|
23
|
-
/**
|
|
24
|
-
* What {@link planSetup} hands each agent's functions in {@link SETUP_AGENTS}.
|
|
25
|
-
* @deprecated Compatibility export. Use {@link planSetup}, {@link applySetup}, and {@link restoreSetup} for agent setup.
|
|
26
|
-
*/
|
|
27
|
-
export type SetupContext = {
|
|
28
|
-
/** The environment phantom runs in. */
|
|
29
|
-
env: Env;
|
|
30
|
-
/** The home folder agents are found in. */
|
|
31
|
-
home: string;
|
|
32
|
-
/** Whether a program is on PATH. Defaults to checking for real. */
|
|
33
|
-
onPath?: (bin: string) => boolean;
|
|
34
|
-
/** The model `--model` asked for, if any. */
|
|
35
|
-
model?: string;
|
|
36
|
-
/** The shell startup file the key block goes in ({@link shellRcFile}). */
|
|
37
|
-
shellRc: string;
|
|
38
|
-
};
|
|
39
|
-
/**
|
|
40
|
-
* One file a setup step changes.
|
|
41
|
-
* @deprecated Compatibility export. Use {@link planSetup}, {@link applySetup}, and {@link restoreSetup} for agent setup.
|
|
42
|
-
*/
|
|
43
|
-
export type SetupEdit = {
|
|
44
|
-
/** The file. */
|
|
45
|
-
file: string;
|
|
46
|
-
/** Its text after the change. null removes the file. */
|
|
47
|
-
after: string | null;
|
|
48
|
-
/** The file's mode, for a file that holds a key. */
|
|
49
|
-
mode?: number;
|
|
50
|
-
/** What setup recorded about the JSON keys it wrote, for `--provider off` to put back ({@link JsonWas}). null forgets the record. */
|
|
51
|
-
was?: JsonWas | null;
|
|
52
|
-
};
|
|
53
|
-
/**
|
|
54
|
-
* What {@link SetupAgentSpec.provider} returns.
|
|
55
|
-
* @deprecated Compatibility export. Use {@link planSetup}, {@link applySetup}, and {@link restoreSetup} for agent setup.
|
|
56
|
-
*/
|
|
57
|
-
export type ProviderPlan = {
|
|
58
|
-
/** The files to write. Empty for an agent set up on its settings screen or by the shell block alone. */
|
|
59
|
-
edits: SetupEdit[];
|
|
60
|
-
/** What to report. */
|
|
61
|
-
result: ProviderResult;
|
|
62
|
-
};
|
|
63
|
-
/** An agent name `phantom setup --agent` takes, other than `all`. */
|
|
64
|
-
export type SetupAgent = 'pi' | 'codex' | 'claude' | 'cursor' | 'opencode' | 'continue' | 'goose' | 'aider' | 'copilot' | 'cline' | 'gemini' | 'crush' | 'qwen' | 'kilo' | 'kimi' | 'droid' | 'vibe' | 'zed' | 'vscode' | 'jetbrains' | 'warp' | 'trae';
|
|
65
|
-
/**
|
|
66
|
-
* One agent `phantom setup` knows: where to find it, where its skill goes, and what else setup can do for it.
|
|
67
|
-
* @deprecated Compatibility export. Use {@link planSetup}, {@link applySetup}, and {@link restoreSetup} for agent setup.
|
|
68
|
-
*/
|
|
69
|
-
export type SetupAgentSpec = {
|
|
70
|
-
/** The agent's name in messages, such as `Claude Code`. */
|
|
71
|
-
label: string;
|
|
72
|
-
/** The folder (or file) in the home directory whose presence means the agent is installed. */
|
|
73
|
-
home: string;
|
|
74
|
-
/** Whether the agent is installed, for one found somewhere other than {@link SetupAgentSpec.home}, such as `$CODEX_HOME`. */
|
|
75
|
-
detect?: (env: Env, home: string) => boolean;
|
|
76
|
-
/** The folder in the home directory the skill goes in. Left out for agents without skills. */
|
|
77
|
-
skills?: string;
|
|
78
|
-
/**
|
|
79
|
-
* Points the agent's own model calls at Phantom AI, or with `off` removes
|
|
80
|
-
* what phantom wrote. Throws a {@link CliError} with code `setup_unreadable` for
|
|
81
|
-
* a config file it can't edit safely, and setup skips that agent.
|
|
82
|
-
*/
|
|
83
|
-
provider?: (ctx: SetupContext, off: boolean) => ProviderPlan;
|
|
84
|
-
/**
|
|
85
|
-
* Variables the agent reads, set in the shell block next to
|
|
86
|
-
* PHANTOM_API_KEY. A value may use `$PHANTOM_API_KEY`. Present (even empty)
|
|
87
|
-
* for every agent that reads the key from the environment.
|
|
88
|
-
*/
|
|
89
|
-
shellEnv?: (ctx: SetupContext) => Record<string, string>;
|
|
90
|
-
};
|
|
91
|
-
/** The model setup starts each agent on when `--model` is not given. */
|
|
92
|
-
export declare const SETUP_MODEL = "phantom-1";
|
|
93
|
-
/** The coding agents Phantom AI serves at their own base path. */
|
|
94
|
-
export type AgentPath = 'codex' | 'claude-code' | 'cursor' | 'coding-agent' | 'gemini-cli';
|
|
95
|
-
/**
|
|
96
|
-
* The address Phantom AI serves a coding agent at, from PHANTOM_BASE_URL
|
|
97
|
-
* without its `/v1`: `/claude-code` (Claude Code adds `/v1` itself),
|
|
98
|
-
* `/gemini-cli` (Gemini CLI adds Google's `/v1beta`), or `/codex/v1`,
|
|
99
|
-
* `/cursor/v1` and `/coding-agent/v1` for the others.
|
|
100
|
-
* @throws {@link CliError} when PHANTOM_BASE_URL is not https ({@link httpsOnly}).
|
|
101
|
-
*/
|
|
102
|
-
export declare function agentBaseUrl(env: Env, agent: AgentPath): string;
|
|
103
|
-
/** The end of every line phantom adds to a TOML, YAML or shell file. */
|
|
104
|
-
export declare const SETUP_MARK = "# phantom setup";
|
|
105
|
-
/** The start of a line phantom turned into a comment because it replaced it. `--provider off` puts it back. */
|
|
106
|
-
export declare const SETUP_WAS = "# phantom setup was: ";
|
|
107
|
-
/** True for a line setup added: it ends with {@link SETUP_MARK}, or the mark pai wrote. */
|
|
108
|
-
export declare function setupMarked(line: string): boolean;
|
|
109
|
-
/** The line without the setup mark on its end. */
|
|
110
|
-
export declare function stripMark(line: string): string;
|
|
111
|
-
/** A line setup turned into a comment, put back as it was. Other lines come back unchanged. */
|
|
112
|
-
export declare function unwas(line: string): string;
|
|
113
|
-
/** A file's text, or null when it does not exist. Other read errors pass through. */
|
|
114
|
-
export declare function readText(file: string): string | null;
|
|
115
|
-
/** Refuses a file setup can't edit safely. Setup skips the agent and says why. */
|
|
116
|
-
export declare function unreadable(file: string, why: string): never;
|
|
117
|
-
/** How to run this phantom from outside this shell: `phantom` if it's installed, else this node and script by absolute path. */
|
|
118
|
-
export declare function phantomCommand(onPathFn: (bin: string) => boolean): string;
|
|
119
|
-
/** `$XDG_CONFIG_HOME` when it is an absolute path, else `~/.config`. */
|
|
120
|
-
export declare function configHome(env: Env, home: string): string;
|
|
121
|
-
/** A writer's `off` result for a file it edits by removing its own lines or entries. */
|
|
122
|
-
export declare function offResult(label: string, file: string, text: string | null, after: string | null, forgetJsonWas?: boolean): ProviderPlan;
|
|
123
|
-
/** What {@link claudeProvider} changed, and what each agent's provider step reports. */
|
|
124
|
-
export type ProviderResult = {
|
|
125
|
-
/** The agent's settings file, or the shell startup file for an agent set up by environment variables alone. */
|
|
126
|
-
settings: string;
|
|
127
|
-
/** True when the agent now runs on Phantom AI; false after `--provider off`, and for an agent set up on its settings screen. */
|
|
128
|
-
on: boolean;
|
|
129
|
-
/** The base URL the agent now calls. */
|
|
130
|
-
base_url?: string;
|
|
131
|
-
/** The model the agent now starts with, if phantom set one. */
|
|
132
|
-
model?: string;
|
|
133
|
-
/** Things the user should know, such as an ANTHROPIC_AUTH_TOKEN in the shell that would win over the Phantom key. */
|
|
134
|
-
warnings: string[];
|
|
135
|
-
/** Steps to follow by hand, for an agent whose model settings live on its settings screen. */
|
|
136
|
-
manual?: string[];
|
|
137
|
-
};
|
|
138
|
-
/** A model as Claude Code names it: `phantom-1:private` is `claude-code/phantom-1:private`, and one that has the prefix keeps one. */
|
|
139
|
-
export declare function claudeModelName(model: string): string;
|
|
140
|
-
/** The context window Phantom AI's catalog gives phantom-1. Goose and Aider size requests by it. */
|
|
141
|
-
export declare const SETUP_CONTEXT_WINDOW = 1000000;
|
package/dist/setup/shared.mjs
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { readFileSync } from 'node:fs';
|
|
3
|
-
import { spawnSync } from 'node:child_process';
|
|
4
|
-
import { die } from "../core/errors.mjs";
|
|
5
|
-
import { DEFAULT_BASE_URL, httpsOnly } from "../core/request.mjs";
|
|
6
|
-
/** True when `bin` is a program on PATH. */
|
|
7
|
-
export function onPath(bin) {
|
|
8
|
-
return spawnSync(process.platform === 'win32' ? 'where' : 'which', [bin], { stdio: 'ignore' }).status === 0;
|
|
9
|
-
}
|
|
10
|
-
/** The model setup starts each agent on when `--model` is not given. */
|
|
11
|
-
export const SETUP_MODEL = 'phantom-1';
|
|
12
|
-
/**
|
|
13
|
-
* The address Phantom AI serves a coding agent at, from PHANTOM_BASE_URL
|
|
14
|
-
* without its `/v1`: `/claude-code` (Claude Code adds `/v1` itself),
|
|
15
|
-
* `/gemini-cli` (Gemini CLI adds Google's `/v1beta`), or `/codex/v1`,
|
|
16
|
-
* `/cursor/v1` and `/coding-agent/v1` for the others.
|
|
17
|
-
* @throws {@link CliError} when PHANTOM_BASE_URL is not https ({@link httpsOnly}).
|
|
18
|
-
*/
|
|
19
|
-
export function agentBaseUrl(env, agent) {
|
|
20
|
-
const origin = httpsOnly(env.PHANTOM_BASE_URL || DEFAULT_BASE_URL).replace(/\/+$/, '').replace(/\/v1$/, '');
|
|
21
|
-
return agent === 'claude-code' || agent === 'gemini-cli' ? `${origin}/${agent}` : `${origin}/${agent}/v1`;
|
|
22
|
-
}
|
|
23
|
-
/** The end of every line phantom adds to a TOML, YAML or shell file. */
|
|
24
|
-
export const SETUP_MARK = '# phantom setup';
|
|
25
|
-
/** The start of a line phantom turned into a comment because it replaced it. `--provider off` puts it back. */
|
|
26
|
-
export const SETUP_WAS = '# phantom setup was: ';
|
|
27
|
-
/** The marks this CLI wrote under its old name, pai. Setup still finds and removes them. */
|
|
28
|
-
const LEGACY_MARK = '# pai setup';
|
|
29
|
-
const LEGACY_WAS = '# pai setup was: ';
|
|
30
|
-
/** True for a line setup added: it ends with {@link SETUP_MARK}, or the mark pai wrote. */
|
|
31
|
-
export function setupMarked(line) {
|
|
32
|
-
const t = line.trimEnd();
|
|
33
|
-
return t.endsWith(SETUP_MARK) || t.endsWith(LEGACY_MARK);
|
|
34
|
-
}
|
|
35
|
-
/** The line without the setup mark on its end. */
|
|
36
|
-
export function stripMark(line) {
|
|
37
|
-
const t = line.trimEnd();
|
|
38
|
-
const mark = t.endsWith(SETUP_MARK) ? SETUP_MARK : t.endsWith(LEGACY_MARK) ? LEGACY_MARK : '';
|
|
39
|
-
return t.slice(0, t.length - mark.length).trimEnd();
|
|
40
|
-
}
|
|
41
|
-
/** A line setup turned into a comment, put back as it was. Other lines come back unchanged. */
|
|
42
|
-
export function unwas(line) {
|
|
43
|
-
for (const was of [SETUP_WAS, LEGACY_WAS])
|
|
44
|
-
if (line.startsWith(was))
|
|
45
|
-
return line.slice(was.length);
|
|
46
|
-
return line;
|
|
47
|
-
}
|
|
48
|
-
/** A file's text, or null when it does not exist. Other read errors pass through. */
|
|
49
|
-
export function readText(file) {
|
|
50
|
-
try {
|
|
51
|
-
return readFileSync(file, 'utf-8');
|
|
52
|
-
}
|
|
53
|
-
catch (err) {
|
|
54
|
-
if (err.code === 'ENOENT')
|
|
55
|
-
return null;
|
|
56
|
-
throw err;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
/** Refuses a file setup can't edit safely. Setup skips the agent and says why. */
|
|
60
|
-
export function unreadable(file, why) {
|
|
61
|
-
die(`${file} ${why}; fix it first so setup doesn't overwrite it`, 'setup_unreadable');
|
|
62
|
-
}
|
|
63
|
-
/** How to run this phantom from outside this shell: `phantom` if it's installed, else this node and script by absolute path. */
|
|
64
|
-
export function phantomCommand(onPathFn) {
|
|
65
|
-
return onPathFn('phantom')
|
|
66
|
-
? 'phantom'
|
|
67
|
-
: `${onPathFn('node') ? 'node' : JSON.stringify(process.execPath)} ${JSON.stringify(path.resolve(process.argv[1] ?? 'phantom'))}`;
|
|
68
|
-
}
|
|
69
|
-
/** `$XDG_CONFIG_HOME` when it is an absolute path, else `~/.config`. */
|
|
70
|
-
export function configHome(env, home) {
|
|
71
|
-
return env.XDG_CONFIG_HOME && path.isAbsolute(env.XDG_CONFIG_HOME) ? env.XDG_CONFIG_HOME : path.join(home, '.config');
|
|
72
|
-
}
|
|
73
|
-
/** A writer's `off` result for a file it edits by removing its own lines or entries. */
|
|
74
|
-
export function offResult(label, file, text, after, forgetJsonWas = false) {
|
|
75
|
-
const changed = text !== null && after !== text;
|
|
76
|
-
return {
|
|
77
|
-
edits: changed ? [{ file, after: after || null, ...(forgetJsonWas ? { was: null } : {}) }] : [],
|
|
78
|
-
result: { settings: file, on: false, warnings: changed ? [] : [`${label} was not set to Phantom AI by phantom; nothing changed`] },
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
/** The prefix Claude Code's `/model` picker needs to keep a model: it drops ids without "claude" in them. The server strips it again. */
|
|
82
|
-
const CLAUDE_CODE_PREFIX = 'claude-code/';
|
|
83
|
-
/** A model as Claude Code names it: `phantom-1:private` is `claude-code/phantom-1:private`, and one that has the prefix keeps one. */
|
|
84
|
-
export function claudeModelName(model) {
|
|
85
|
-
return CLAUDE_CODE_PREFIX + (model.startsWith(CLAUDE_CODE_PREFIX) ? model.slice(CLAUDE_CODE_PREFIX.length) : model);
|
|
86
|
-
}
|
|
87
|
-
/** The context window Phantom AI's catalog gives phantom-1. Goose and Aider size requests by it. */
|
|
88
|
-
export const SETUP_CONTEXT_WINDOW = 1_000_000;
|