@arizeai/phoenix-cli 1.9.0 → 1.10.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 +82 -7
- package/build/authFetch.d.ts +24 -0
- package/build/authFetch.d.ts.map +1 -0
- package/build/authFetch.js +44 -0
- package/build/authFetch.js.map +1 -0
- package/build/client.d.ts.map +1 -1
- package/build/client.js +5 -1
- package/build/client.js.map +1 -1
- package/build/commands/api.d.ts.map +1 -1
- package/build/commands/api.js +12 -1
- package/build/commands/api.js.map +1 -1
- package/build/commands/auth.d.ts +4 -1
- package/build/commands/auth.d.ts.map +1 -1
- package/build/commands/auth.js +326 -13
- package/build/commands/auth.js.map +1 -1
- package/build/commands/formatSetup.d.ts +12 -0
- package/build/commands/formatSetup.d.ts.map +1 -1
- package/build/commands/formatSetup.js +32 -1
- package/build/commands/formatSetup.js.map +1 -1
- package/build/commands/setup.d.ts.map +1 -1
- package/build/commands/setup.js +14 -38
- package/build/commands/setup.js.map +1 -1
- package/build/commands/setupErrors.d.ts +10 -0
- package/build/commands/setupErrors.d.ts.map +1 -0
- package/build/commands/setupErrors.js +54 -0
- package/build/commands/setupErrors.js.map +1 -0
- package/build/commands/setupMcp.d.ts +15 -0
- package/build/commands/setupMcp.d.ts.map +1 -0
- package/build/commands/setupMcp.js +141 -0
- package/build/commands/setupMcp.js.map +1 -0
- package/build/config.d.ts +15 -0
- package/build/config.d.ts.map +1 -1
- package/build/config.js +54 -7
- package/build/config.js.map +1 -1
- package/build/exitCodes.d.ts +6 -0
- package/build/exitCodes.d.ts.map +1 -1
- package/build/exitCodes.js +18 -0
- package/build/exitCodes.js.map +1 -1
- package/build/index.js +2 -1
- package/build/index.js.map +1 -1
- package/build/oauth.d.ts +138 -0
- package/build/oauth.d.ts.map +1 -0
- package/build/oauth.js +465 -0
- package/build/oauth.js.map +1 -0
- package/build/oauthCallbackPage.d.ts +9 -0
- package/build/oauthCallbackPage.d.ts.map +1 -0
- package/build/oauthCallbackPage.js +111 -0
- package/build/oauthCallbackPage.js.map +1 -0
- package/build/pxi/client.d.ts.map +1 -1
- package/build/pxi/client.js +11 -2
- package/build/pxi/client.js.map +1 -1
- package/build/settings.d.ts +19 -0
- package/build/settings.d.ts.map +1 -1
- package/build/settings.js +21 -0
- package/build/settings.js.map +1 -1
- package/build/setup/agents/registry.d.ts +61 -0
- package/build/setup/agents/registry.d.ts.map +1 -1
- package/build/setup/agents/registry.js +52 -3
- package/build/setup/agents/registry.js.map +1 -1
- package/build/setup/copy.d.ts +32 -0
- package/build/setup/copy.d.ts.map +1 -1
- package/build/setup/copy.js +44 -0
- package/build/setup/copy.js.map +1 -1
- package/build/setup/deps/buildDefaultDeps.d.ts.map +1 -1
- package/build/setup/deps/buildDefaultDeps.js +2 -0
- package/build/setup/deps/buildDefaultDeps.js.map +1 -1
- package/build/setup/deps/index.d.ts +4 -0
- package/build/setup/deps/index.d.ts.map +1 -1
- package/build/setup/deps/index.js.map +1 -1
- package/build/setup/deps/oauthLogin.d.ts +64 -0
- package/build/setup/deps/oauthLogin.d.ts.map +1 -0
- package/build/setup/deps/oauthLogin.js +82 -0
- package/build/setup/deps/oauthLogin.js.map +1 -0
- package/build/setup/deps/prompter.d.ts +7 -0
- package/build/setup/deps/prompter.d.ts.map +1 -1
- package/build/setup/mcp/agents.d.ts +91 -0
- package/build/setup/mcp/agents.d.ts.map +1 -0
- package/build/setup/mcp/agents.js +265 -0
- package/build/setup/mcp/agents.js.map +1 -0
- package/build/setup/mcp/install.d.ts +34 -0
- package/build/setup/mcp/install.d.ts.map +1 -0
- package/build/setup/mcp/install.js +76 -0
- package/build/setup/mcp/install.js.map +1 -0
- package/build/setup/mcp/runSetupMcp.d.ts +68 -0
- package/build/setup/mcp/runSetupMcp.d.ts.map +1 -0
- package/build/setup/mcp/runSetupMcp.js +235 -0
- package/build/setup/mcp/runSetupMcp.js.map +1 -0
- package/build/setup/options.d.ts +11 -0
- package/build/setup/options.d.ts.map +1 -1
- package/build/setup/options.js +1 -0
- package/build/setup/options.js.map +1 -1
- package/build/setup/prompts/instrumentationPrompt.d.ts +7 -1
- package/build/setup/prompts/instrumentationPrompt.d.ts.map +1 -1
- package/build/setup/prompts/instrumentationPrompt.js +6 -2
- package/build/setup/prompts/instrumentationPrompt.js.map +1 -1
- package/build/setup/runSetup.d.ts +3 -0
- package/build/setup/runSetup.d.ts.map +1 -1
- package/build/setup/runSetup.js +13 -12
- package/build/setup/runSetup.js.map +1 -1
- package/build/setup/steps/establishConnection.d.ts +6 -3
- package/build/setup/steps/establishConnection.d.ts.map +1 -1
- package/build/setup/steps/establishConnection.js +120 -11
- package/build/setup/steps/establishConnection.js.map +1 -1
- package/build/setup/steps/instrumentApp.d.ts +23 -4
- package/build/setup/steps/instrumentApp.d.ts.map +1 -1
- package/build/setup/steps/instrumentApp.js +89 -41
- package/build/setup/steps/instrumentApp.js.map +1 -1
- package/build/setup/steps/offerDocsMcp.d.ts +48 -0
- package/build/setup/steps/offerDocsMcp.d.ts.map +1 -0
- package/build/setup/steps/offerDocsMcp.js +134 -0
- package/build/setup/steps/offerDocsMcp.js.map +1 -0
- package/build/setup/ui/clackPrompter.d.ts.map +1 -1
- package/build/setup/ui/clackPrompter.js +15 -0
- package/build/setup/ui/clackPrompter.js.map +1 -1
- package/build/setup/util/mcpConfig.d.ts +38 -0
- package/build/setup/util/mcpConfig.d.ts.map +1 -0
- package/build/setup/util/mcpConfig.js +64 -0
- package/build/setup/util/mcpConfig.js.map +1 -0
- package/package.json +3 -3
|
@@ -5,8 +5,11 @@
|
|
|
5
5
|
* first ingestion, so setup only needs to settle on a *name* and hand it
|
|
6
6
|
* to the app via `PHOENIX_PROJECT_NAME`. What remains is credential
|
|
7
7
|
* acquisition: the auth-on lanes verify the key with a read-only probe so a
|
|
8
|
-
* bad paste is caught here rather than at first trace.
|
|
9
|
-
*
|
|
8
|
+
* bad paste is caught here rather than at first trace. When the instance runs
|
|
9
|
+
* the OAuth2 authorization server, the interactive lane offers a streamlined
|
|
10
|
+
* path first — log in with the browser, mint an API key over REST, revoke the
|
|
11
|
+
* grant that login created — and every failure along it falls back to the
|
|
12
|
+
* paste prompt rather than aborting setup.
|
|
10
13
|
*/
|
|
11
14
|
import * as path from "node:path";
|
|
12
15
|
import { HttpError } from "@arizeai/phoenix-client";
|
|
@@ -38,6 +41,18 @@ async function promptForProjectName(deps, inputs) {
|
|
|
38
41
|
}));
|
|
39
42
|
return name.trim();
|
|
40
43
|
}
|
|
44
|
+
/** A REST failure, as a short phrase to show the user. */
|
|
45
|
+
function describeRestError(error) {
|
|
46
|
+
if (error instanceof HttpError) {
|
|
47
|
+
return `HTTP ${error.status}`;
|
|
48
|
+
}
|
|
49
|
+
// A 2xx whose body will not parse: something answered, but not the Phoenix
|
|
50
|
+
// API. The raw parser message would only confuse.
|
|
51
|
+
if (error instanceof SyntaxError) {
|
|
52
|
+
return COPY.ENDPOINT.unexpectedBody;
|
|
53
|
+
}
|
|
54
|
+
return redactForDisplay(String(error));
|
|
55
|
+
}
|
|
41
56
|
/**
|
|
42
57
|
* Read-only probe: list one project. Only the credential matters here — an
|
|
43
58
|
* instance with no projects yet still answers 200.
|
|
@@ -52,13 +67,11 @@ async function checkApiKey(deps, endpoint, apiKey) {
|
|
|
52
67
|
return { kind: "ok" };
|
|
53
68
|
}
|
|
54
69
|
catch (error) {
|
|
55
|
-
if (error instanceof HttpError
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
return { kind: "error", detail: `HTTP ${error.status}` };
|
|
70
|
+
if (error instanceof HttpError &&
|
|
71
|
+
(error.status === 401 || error.status === 403)) {
|
|
72
|
+
return { kind: "rejected", status: error.status };
|
|
60
73
|
}
|
|
61
|
-
return { kind: "error", detail:
|
|
74
|
+
return { kind: "error", detail: describeRestError(error) };
|
|
62
75
|
}
|
|
63
76
|
}
|
|
64
77
|
// ---------------------------------------------------------------------------
|
|
@@ -78,13 +91,109 @@ async function promptForApiKey(deps) {
|
|
|
78
91
|
return apiKey.trim();
|
|
79
92
|
}
|
|
80
93
|
/**
|
|
81
|
-
*
|
|
82
|
-
* the
|
|
94
|
+
* Log in via the browser, then mint a personal API key over REST. Every
|
|
95
|
+
* failure returns `undefined` after narrating why, sending the lane to the
|
|
96
|
+
* paste prompt — the login is a shortcut, never a wall.
|
|
97
|
+
*/
|
|
98
|
+
async function acquireApiKeyViaLogin(deps, endpoint, projectName) {
|
|
99
|
+
// Ctrl-C here means "give up on the browser", not "abandon setup" — the
|
|
100
|
+
// paste prompt below is still a way forward, and the project name the user
|
|
101
|
+
// already gave is still good.
|
|
102
|
+
const outcome = await deps.prompter.runInterruptible((signal) => deps.oauthLogin.login({
|
|
103
|
+
endpoint,
|
|
104
|
+
onAuthorizationUrl: (url) => deps.prompter.note(COPY.CREDENTIALS.authorizationUrl(url)),
|
|
105
|
+
onBrowserOpenFailed: (detail) => deps.prompter.line(COPY.CREDENTIALS.browserOpenFailed(redactForDisplay(detail))),
|
|
106
|
+
signal,
|
|
107
|
+
}));
|
|
108
|
+
if (outcome.status === "cancelled") {
|
|
109
|
+
deps.prompter.line(COPY.CREDENTIALS.loginCancelled);
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
if (outcome.status === "error") {
|
|
113
|
+
deps.prompter.line(COPY.CREDENTIALS.loginFailed(redactForDisplay(outcome.detail)));
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
try {
|
|
117
|
+
const client = deps.createClient({
|
|
118
|
+
endpoint,
|
|
119
|
+
apiKey: outcome.accessToken,
|
|
120
|
+
});
|
|
121
|
+
const name = `px-setup ${projectName}`;
|
|
122
|
+
const response = await client.POST("/v1/user/api_keys", {
|
|
123
|
+
body: {
|
|
124
|
+
data: {
|
|
125
|
+
name,
|
|
126
|
+
description: `Created by px setup for project "${projectName}".`,
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
signal: AbortSignal.timeout(REST_TIMEOUT_MS),
|
|
130
|
+
});
|
|
131
|
+
const key = response.data?.data.key;
|
|
132
|
+
if (!key) {
|
|
133
|
+
deps.prompter.line(COPY.CREDENTIALS.keyCreateFailed("empty key in response"));
|
|
134
|
+
return undefined;
|
|
135
|
+
}
|
|
136
|
+
deps.prompter.line(COPY.CREDENTIALS.keyCreated(name));
|
|
137
|
+
return key;
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
deps.prompter.line(COPY.CREDENTIALS.keyCreateFailed(describeRestError(error)));
|
|
141
|
+
return undefined;
|
|
142
|
+
}
|
|
143
|
+
finally {
|
|
144
|
+
// The access token has served its one purpose. Ending the grant leaves the
|
|
145
|
+
// key in local files as the only credential this run created — without it,
|
|
146
|
+
// a refresh token setup no longer holds stays live for its full lifetime
|
|
147
|
+
// (a week by default). This does not touch an existing `px auth login`.
|
|
148
|
+
await outcome.revoke().catch(() => { });
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* The project name comes first so the browser-login path can stamp it into
|
|
153
|
+
* the minted key's name. A rejected key returns to the masked credential
|
|
154
|
+
* prompt without asking for the project name again.
|
|
83
155
|
*/
|
|
84
156
|
async function connectAuthOnInteractive(deps, endpoint, inputs) {
|
|
157
|
+
// Start the probe before the prompt so it can run while the user types (when
|
|
158
|
+
// --project is given there is no prompt, and this is simply awaited below).
|
|
159
|
+
// The `catch` is not redundant: the contract returns Promise<boolean>, and an
|
|
160
|
+
// implementation that rejected would otherwise go unhandled on the path where
|
|
161
|
+
// the prompt throws SetupCancelledError before the await below is reached.
|
|
162
|
+
const supportsLogin = deps.oauthLogin
|
|
163
|
+
.isSupported(endpoint)
|
|
164
|
+
.catch(() => false);
|
|
165
|
+
const projectName = await promptForProjectName(deps, inputs);
|
|
166
|
+
if (await supportsLogin) {
|
|
167
|
+
const method = await deps.prompter.select({
|
|
168
|
+
message: COPY.CREDENTIALS.methodMessage,
|
|
169
|
+
options: [
|
|
170
|
+
{
|
|
171
|
+
value: "login",
|
|
172
|
+
label: COPY.CREDENTIALS.loginLabel,
|
|
173
|
+
hint: COPY.CREDENTIALS.loginHint,
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
value: "paste",
|
|
177
|
+
label: COPY.CREDENTIALS.pasteLabel,
|
|
178
|
+
hint: COPY.CREDENTIALS.pasteHint,
|
|
179
|
+
},
|
|
180
|
+
],
|
|
181
|
+
});
|
|
182
|
+
if (method === "login") {
|
|
183
|
+
const apiKey = await acquireApiKeyViaLogin(deps, endpoint, projectName);
|
|
184
|
+
if (apiKey !== undefined) {
|
|
185
|
+
// The key was just minted by an authenticated call to this same
|
|
186
|
+
// endpoint, so a probe could only re-prove what the mint proved. It
|
|
187
|
+
// could, however, fail transiently — and the ephemeral session is
|
|
188
|
+
// already revoked, so a throw here would strand a live key the user
|
|
189
|
+
// never received and cannot name.
|
|
190
|
+
deps.prompter.line(COPY.CONNECT.usingProject(projectName));
|
|
191
|
+
return { endpoint, projectName, apiKey };
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
85
195
|
deps.prompter.note(COPY.API_KEY.instructions, COPY.API_KEY.instructionsTitle);
|
|
86
196
|
let apiKey = await promptForApiKey(deps);
|
|
87
|
-
const projectName = await promptForProjectName(deps, inputs);
|
|
88
197
|
for (;;) {
|
|
89
198
|
const result = await checkApiKey(deps, endpoint, apiKey);
|
|
90
199
|
if (result.kind === "ok") {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"establishConnection.js","sourceRoot":"","sources":["../../../src/setup/steps/establishConnection.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"establishConnection.js","sourceRoot":"","sources":["../../../src/setup/steps/establishConnection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,KAAK,IAAI,MAAM,SAAS,CAAC;AA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M,CAAC,OAAO,CAAC,CAAC;QACtD,IAAI,SAAS,EAAE,CAAC;YACd,MAAM,IAAI,kBAAkB,CAAC,SAAS,CAAC,CAAC;QAC1C,CAAC;IACH,CAAC;IACD,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;QACpB,OAAO,eAAe,CAAC,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;IAC9D,CAAC;IACD,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,cAAc,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;IAChD,CAAC;IACD,OAAO,wBAAwB,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;AAC1D,CAAC"}
|
|
@@ -7,13 +7,20 @@
|
|
|
7
7
|
* lanes converge on the trace-verification step — setup's definition of
|
|
8
8
|
* done is API-verified data flow, not agent self-report.
|
|
9
9
|
*
|
|
10
|
+
* The lane is resolved before anything docs-related happens: the docs MCP
|
|
11
|
+
* offer targets exactly the agent being launched, and taking it replaces the
|
|
12
|
+
* `.px/docs` download outright — the agent searches the docs server on demand
|
|
13
|
+
* instead of reading prefetched pages. The clipboard and manual lanes have no
|
|
14
|
+
* known agent to configure, so they keep the prefetch.
|
|
15
|
+
*
|
|
10
16
|
* `--agent` pre-answers the lane, which is what makes an unattended run
|
|
11
17
|
* possible: with no TTY there is no prompt to pick a lane from, and the agent
|
|
12
18
|
* runs in background mode (no TUI to hand the terminal to).
|
|
13
19
|
*/
|
|
14
20
|
import { type AgentRunMode, type CodingAgent, type CodingAgentId } from "../agents/registry.js";
|
|
15
|
-
import type { DocsPrefetchResult, SetupDeps } from "../deps/index.js";
|
|
21
|
+
import type { DocsPrefetchOptions, DocsPrefetchResult, SetupDeps } from "../deps/index.js";
|
|
16
22
|
import type { Connection } from "./establishConnection.js";
|
|
23
|
+
import { type DocsMcpResult } from "./offerDocsMcp.js";
|
|
17
24
|
export interface InstrumentAppArgs {
|
|
18
25
|
authEnabled: boolean;
|
|
19
26
|
/** Started at setup launch so the probes never block this prompt. */
|
|
@@ -24,8 +31,13 @@ export interface InstrumentAppArgs {
|
|
|
24
31
|
languages: string[];
|
|
25
32
|
/** How to run the agent — see {@link AgentRunMode}. */
|
|
26
33
|
mode: AgentRunMode;
|
|
27
|
-
/**
|
|
28
|
-
docs
|
|
34
|
+
/** Docs prefetch options; the download runs unless the MCP replaces it. */
|
|
35
|
+
docs: DocsPrefetchOptions;
|
|
36
|
+
/** `--docs-mcp` / `--no-docs-mcp`; undefined means ask (when we can). */
|
|
37
|
+
docsMcp?: boolean;
|
|
38
|
+
headless: boolean;
|
|
39
|
+
/** Gates the prefetch's .gitignore append, as in the docs step itself. */
|
|
40
|
+
isGitRepository: boolean;
|
|
29
41
|
}
|
|
30
42
|
/** Which lane instrumentation actually took — reported in the summary. */
|
|
31
43
|
export type InstrumentationLane = {
|
|
@@ -37,5 +49,12 @@ export type InstrumentationLane = {
|
|
|
37
49
|
} | {
|
|
38
50
|
kind: "manual";
|
|
39
51
|
};
|
|
40
|
-
export
|
|
52
|
+
export interface InstrumentAppResult {
|
|
53
|
+
lane: InstrumentationLane;
|
|
54
|
+
/** The docs download, when it ran (the MCP taking its place omits it). */
|
|
55
|
+
docs?: DocsPrefetchResult;
|
|
56
|
+
/** The docs MCP offer, when a launched agent was there to make it to. */
|
|
57
|
+
docsMcp?: DocsMcpResult;
|
|
58
|
+
}
|
|
59
|
+
export declare function instrumentApp(deps: Pick<SetupDeps, "context" | "processes" | "prompter" | "writeClipboard" | "fetchDocs">, connection: Connection, args: InstrumentAppArgs): Promise<InstrumentAppResult>;
|
|
41
60
|
//# sourceMappingURL=instrumentApp.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentApp.d.ts","sourceRoot":"","sources":["../../../src/setup/steps/instrumentApp.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"instrumentApp.d.ts","sourceRoot":"","sources":["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ED,wBAAsB,aAAa,CACjC,IAAI,EAAE,IAAI,CACR,SAAS,EACT,SAAS,GAAG,WAAW,GAAG,UAAU,GAAG,gBAAgB,GAAG,WAAW,CACtE,EACD,UAAU,EAAE,UAAU,EACtB,IAAI,EAAE,iBAAiB,GACtB,OAAO,CAAC,mBAAmB,CAAC,CAuI9B"}
|
|
@@ -7,6 +7,12 @@
|
|
|
7
7
|
* lanes converge on the trace-verification step — setup's definition of
|
|
8
8
|
* done is API-verified data flow, not agent self-report.
|
|
9
9
|
*
|
|
10
|
+
* The lane is resolved before anything docs-related happens: the docs MCP
|
|
11
|
+
* offer targets exactly the agent being launched, and taking it replaces the
|
|
12
|
+
* `.px/docs` download outright — the agent searches the docs server on demand
|
|
13
|
+
* instead of reading prefetched pages. The clipboard and manual lanes have no
|
|
14
|
+
* known agent to configure, so they keep the prefetch.
|
|
15
|
+
*
|
|
10
16
|
* `--agent` pre-answers the lane, which is what makes an unattended run
|
|
11
17
|
* possible: with no TTY there is no prompt to pick a lane from, and the agent
|
|
12
18
|
* runs in background mode (no TUI to hand the terminal to).
|
|
@@ -15,10 +21,78 @@ import { buildLaunchSpec, getCodingAgent, probeBinary, } from "../agents/registr
|
|
|
15
21
|
import * as COPY from "../copy.js";
|
|
16
22
|
import { SetupFatalError } from "../errors.js";
|
|
17
23
|
import { buildInstrumentationPrompt } from "../prompts/instrumentationPrompt.js";
|
|
24
|
+
import { offerDocsMcp } from "./offerDocsMcp.js";
|
|
25
|
+
import { prefetchDocs } from "./prefetchDocs.js";
|
|
18
26
|
import { tracesUrl } from "./verifyTraces.js";
|
|
19
27
|
const DEFAULT_LOCAL_ENDPOINT = "http://localhost:6006";
|
|
20
28
|
export async function instrumentApp(deps, connection, args) {
|
|
21
29
|
const { authEnabled, agentDetection, languages, mode } = args;
|
|
30
|
+
// Resolve the lane before the docs steps: the MCP offer needs to know which
|
|
31
|
+
// agent is doing the work, and only then can "skip the download" be decided.
|
|
32
|
+
let chosenAgent;
|
|
33
|
+
let fallbackLane = "manual";
|
|
34
|
+
if (args.agent) {
|
|
35
|
+
// `--agent` short-circuits the lane prompt. The binary is probed rather
|
|
36
|
+
// than taken from the detection sweep so a named-but-missing agent fails
|
|
37
|
+
// with "not on your PATH" instead of silently dropping to another lane.
|
|
38
|
+
const agent = getCodingAgent(args.agent);
|
|
39
|
+
if (!agent) {
|
|
40
|
+
throw new SetupFatalError(COPY.INSTRUMENTATION.unknownAgent(args.agent));
|
|
41
|
+
}
|
|
42
|
+
if (!(await probeBinary(deps, agent.binary))) {
|
|
43
|
+
throw new SetupFatalError(COPY.INSTRUMENTATION.agentNotFound(agent.label, agent.binary));
|
|
44
|
+
}
|
|
45
|
+
chosenAgent = agent;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
const detectedAgents = await agentDetection;
|
|
49
|
+
const options = [
|
|
50
|
+
...detectedAgents.map((agent) => ({
|
|
51
|
+
value: `agent:${agent.id}`,
|
|
52
|
+
label: COPY.INSTRUMENTATION.launchLabel(agent.label),
|
|
53
|
+
hint: COPY.INSTRUMENTATION.launchHint,
|
|
54
|
+
})),
|
|
55
|
+
{
|
|
56
|
+
value: "clipboard",
|
|
57
|
+
label: COPY.INSTRUMENTATION.clipboardLabel,
|
|
58
|
+
hint: COPY.INSTRUMENTATION.clipboardHint,
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
value: "manual",
|
|
62
|
+
label: COPY.INSTRUMENTATION.manualLabel,
|
|
63
|
+
hint: COPY.INSTRUMENTATION.manualHint,
|
|
64
|
+
},
|
|
65
|
+
];
|
|
66
|
+
const choice = await deps.prompter.select({
|
|
67
|
+
message: COPY.INSTRUMENTATION.modeMessage,
|
|
68
|
+
options,
|
|
69
|
+
});
|
|
70
|
+
chosenAgent = detectedAgents.find((agent) => choice === `agent:${agent.id}`);
|
|
71
|
+
fallbackLane = choice === "clipboard" ? "clipboard" : "manual";
|
|
72
|
+
}
|
|
73
|
+
// The offer is an optimization and never takes setup down with it — that
|
|
74
|
+
// contract lives inside offerDocsMcp, which reports any failure and returns
|
|
75
|
+
// "failed" instead of throwing. Only a user cancel unwinds.
|
|
76
|
+
let docsMcp;
|
|
77
|
+
if (chosenAgent) {
|
|
78
|
+
docsMcp = await offerDocsMcp(deps, {
|
|
79
|
+
docsMcp: args.docsMcp,
|
|
80
|
+
agent: chosenAgent,
|
|
81
|
+
headless: args.headless,
|
|
82
|
+
docsEnabled: args.docs.enabled,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
else if (args.docsMcp === true) {
|
|
86
|
+
// An explicit --docs-mcp deserves a word when the lane can't honor it,
|
|
87
|
+
// same as a pinned agent with no MCP install path.
|
|
88
|
+
deps.prompter.line(COPY.DOCS_MCP.noAgentLane);
|
|
89
|
+
}
|
|
90
|
+
const docs = docsMcp?.outcome === "configured"
|
|
91
|
+
? undefined
|
|
92
|
+
: await prefetchDocs(deps, {
|
|
93
|
+
docs: args.docs,
|
|
94
|
+
isGitRepository: args.isGitRepository,
|
|
95
|
+
});
|
|
22
96
|
const prompt = buildInstrumentationPrompt({
|
|
23
97
|
projectName: connection.projectName,
|
|
24
98
|
endpoint: connection.endpoint,
|
|
@@ -35,48 +109,22 @@ export async function instrumentApp(deps, connection, args) {
|
|
|
35
109
|
// Only advertise the local docs dir when it holds pages — an empty one
|
|
36
110
|
// (docs site down, over-narrow workflow filter) would send the agent to
|
|
37
111
|
// read a directory with nothing in it instead of the web.
|
|
38
|
-
...(
|
|
112
|
+
...(docs?.hasPagesOnDisk ? { localDocsDir: docs.outputDir } : {}),
|
|
113
|
+
...(docsMcp?.outcome === "configured" ? { docsMcpConfigured: true } : {}),
|
|
39
114
|
});
|
|
40
|
-
// `--agent` short-circuits the lane prompt. The binary is probed rather
|
|
41
|
-
// than taken from the detection sweep so a named-but-missing agent fails
|
|
42
|
-
// with "not on your PATH" instead of silently dropping to another lane.
|
|
43
|
-
if (args.agent) {
|
|
44
|
-
const agent = getCodingAgent(args.agent);
|
|
45
|
-
if (!agent) {
|
|
46
|
-
throw new SetupFatalError(COPY.INSTRUMENTATION.unknownAgent(args.agent));
|
|
47
|
-
}
|
|
48
|
-
if (!(await probeBinary(deps, agent.binary))) {
|
|
49
|
-
throw new SetupFatalError(COPY.INSTRUMENTATION.agentNotFound(agent.label, agent.binary));
|
|
50
|
-
}
|
|
51
|
-
return launchAgent(deps, connection, { agent, prompt, mode });
|
|
52
|
-
}
|
|
53
|
-
const detectedAgents = await agentDetection;
|
|
54
|
-
const options = [
|
|
55
|
-
...detectedAgents.map((agent) => ({
|
|
56
|
-
value: `agent:${agent.id}`,
|
|
57
|
-
label: COPY.INSTRUMENTATION.launchLabel(agent.label),
|
|
58
|
-
hint: COPY.INSTRUMENTATION.launchHint,
|
|
59
|
-
})),
|
|
60
|
-
{
|
|
61
|
-
value: "clipboard",
|
|
62
|
-
label: COPY.INSTRUMENTATION.clipboardLabel,
|
|
63
|
-
hint: COPY.INSTRUMENTATION.clipboardHint,
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
value: "manual",
|
|
67
|
-
label: COPY.INSTRUMENTATION.manualLabel,
|
|
68
|
-
hint: COPY.INSTRUMENTATION.manualHint,
|
|
69
|
-
},
|
|
70
|
-
];
|
|
71
|
-
const choice = await deps.prompter.select({
|
|
72
|
-
message: COPY.INSTRUMENTATION.modeMessage,
|
|
73
|
-
options,
|
|
74
|
-
});
|
|
75
|
-
const chosenAgent = detectedAgents.find((agent) => choice === `agent:${agent.id}`);
|
|
76
115
|
if (chosenAgent) {
|
|
77
|
-
|
|
116
|
+
const lane = await launchAgent(deps, connection, {
|
|
117
|
+
agent: chosenAgent,
|
|
118
|
+
prompt,
|
|
119
|
+
mode,
|
|
120
|
+
});
|
|
121
|
+
return {
|
|
122
|
+
lane,
|
|
123
|
+
...(docs ? { docs } : {}),
|
|
124
|
+
...(docsMcp ? { docsMcp } : {}),
|
|
125
|
+
};
|
|
78
126
|
}
|
|
79
|
-
if (
|
|
127
|
+
if (fallbackLane === "clipboard") {
|
|
80
128
|
const copied = await deps.writeClipboard(prompt);
|
|
81
129
|
if (copied) {
|
|
82
130
|
deps.prompter.line(COPY.INSTRUMENTATION.promptCopied);
|
|
@@ -91,14 +139,14 @@ export async function instrumentApp(deps, connection, args) {
|
|
|
91
139
|
{ value: true, label: COPY.INSTRUMENTATION.clipboardDoneLabel },
|
|
92
140
|
],
|
|
93
141
|
});
|
|
94
|
-
return { kind: "clipboard" };
|
|
142
|
+
return { lane: { kind: "clipboard" }, ...(docs ? { docs } : {}) };
|
|
95
143
|
}
|
|
96
144
|
deps.prompter.line(COPY.INSTRUMENTATION.manualDocs(COPY.DOCS.instrumentationIndex));
|
|
97
145
|
await deps.prompter.select({
|
|
98
146
|
message: COPY.INSTRUMENTATION.manualDoneMessage,
|
|
99
147
|
options: [{ value: true, label: COPY.INSTRUMENTATION.manualDoneLabel }],
|
|
100
148
|
});
|
|
101
|
-
return { kind: "manual" };
|
|
149
|
+
return { lane: { kind: "manual" }, ...(docs ? { docs } : {}) };
|
|
102
150
|
}
|
|
103
151
|
/**
|
|
104
152
|
* Run the agent with the prompt pre-loaded. A non-zero exit is a warning, not
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentApp.js","sourceRoot":"","sources":["../../../src/setup/steps/instrumentApp.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"instrumentApp.js","sourceRoot":"","sources":["../../../src/setup/steps/instrumentApp.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EACL,eAAe,EACf,cAAc,EACd,WAAW,GAIZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,IAAI,MAAM,SAAS,CAAC;AAOhC,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,0BAA0B,EAAE,MAAM,kCAAkC,CAAC;AAE9E,OAAO,EAAE,YAAY,EAAsB,MAAM,gBAAgB,CAAC;AAClE,OAAO,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gBAAgB,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;IACzE,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,EAAE,EAAE,QAAQ,EAAE,CAAC;AACtD,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Offer to connect the Phoenix docs MCP server to the coding agent taking the
|
|
3
|
+
* hand-off, instead of downloading the docs.
|
|
4
|
+
*
|
|
5
|
+
* Taking the offer is the fast path: one small config step replaces the
|
|
6
|
+
* ~100-page `.px/docs` download, and the agent then searches the docs server
|
|
7
|
+
* on demand — pulling only the sections it needs instead of reading whole
|
|
8
|
+
* pages. Declining (or any failure) degrades to the docs prefetch, which is
|
|
9
|
+
* what setup did before this step existed.
|
|
10
|
+
*
|
|
11
|
+
* The offer is an optimization and must never take setup down with it:
|
|
12
|
+
* whatever goes wrong (an agent CLI whose flags drifted, a config format we
|
|
13
|
+
* no longer understand), this step reports it, returns a "failed" result, and
|
|
14
|
+
* the caller carries on with the docs download. The only throw that leaves
|
|
15
|
+
* this function is a user cancel.
|
|
16
|
+
*
|
|
17
|
+
* The offer targets exactly one agent — the lane the user chose (or `--agent`
|
|
18
|
+
* pinned) — so setup never sprays MCP config for agents that aren't doing the
|
|
19
|
+
* work. How the entry lands is the agent's own affair ({@link DocsMcpInstall}):
|
|
20
|
+
* agents with an MCP subcommand register it through their own CLI, the rest
|
|
21
|
+
* get a merge into their documented config file. Headless runs never touch
|
|
22
|
+
* agent config unless `--docs-mcp` asked for it.
|
|
23
|
+
*/
|
|
24
|
+
import { type CodingAgent } from "../agents/registry.js";
|
|
25
|
+
import type { SetupDeps } from "../deps/index.js";
|
|
26
|
+
export type DocsMcpOutcome = "configured" | "declined" | "skipped" | "failed";
|
|
27
|
+
/** What the offer did — reported in the setup summary. */
|
|
28
|
+
export interface DocsMcpResult {
|
|
29
|
+
outcome: DocsMcpOutcome;
|
|
30
|
+
/** Agents whose config now names the server. */
|
|
31
|
+
agents: CodingAgent["id"][];
|
|
32
|
+
/** Repo-relative config files written (empty for a CLI-side install). */
|
|
33
|
+
files: string[];
|
|
34
|
+
}
|
|
35
|
+
export interface OfferDocsMcpArgs {
|
|
36
|
+
/** `--docs-mcp` / `--no-docs-mcp`; undefined means ask (when we can). */
|
|
37
|
+
docsMcp?: boolean;
|
|
38
|
+
/** The agent taking the hand-off — the only one the offer configures. */
|
|
39
|
+
agent: CodingAgent;
|
|
40
|
+
headless: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Whether the docs prefetch would actually run on decline/failure — with
|
|
43
|
+
* `--no-docs` it won't, and the offer must not promise a download.
|
|
44
|
+
*/
|
|
45
|
+
docsEnabled: boolean;
|
|
46
|
+
}
|
|
47
|
+
export declare function offerDocsMcp(deps: Pick<SetupDeps, "context" | "prompter" | "processes">, args: OfferDocsMcpArgs): Promise<DocsMcpResult>;
|
|
48
|
+
//# sourceMappingURL=offerDocsMcp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"offerDocsMcp.d.ts","sourceRoot":"","sources":["../../../src/setup/steps/offerDocsMcp.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAIH,OAAO,EAAuB,KAAK,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAE3E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAKzC,MAAM,MAAM,cAAc,GAAG,YAAY,GAAG,UAAU,GAAG,SAAS,GAAG,QAAQ,CAAC;AAE9E,0DAA0D;AAC1D,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,cAAc,CAAC;IACxB,gDAAgD;IAChD,MAAM,EAAE,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC;IAC5B,yEAAyE;IACzE,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAOD,MAAM,WAAW,gBAAgB;IAC/B,yEAAyE;IACzE,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,yEAAyE;IACzE,KAAK,EAAE,WAAW,CAAC;IACnB,QAAQ,EAAE,OAAO,CAAC;IAClB;;;OAGG;IACH,WAAW,EAAE,OAAO,CAAC;CACtB;AAED,wBAAsB,YAAY,CAChC,IAAI,EAAE,IAAI,CAAC,SAAS,EAAE,SAAS,GAAG,UAAU,GAAG,WAAW,CAAC,EAC3D,IAAI,EAAE,gBAAgB,GACrB,OAAO,CAAC,aAAa,CAAC,CAaxB"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Offer to connect the Phoenix docs MCP server to the coding agent taking the
|
|
3
|
+
* hand-off, instead of downloading the docs.
|
|
4
|
+
*
|
|
5
|
+
* Taking the offer is the fast path: one small config step replaces the
|
|
6
|
+
* ~100-page `.px/docs` download, and the agent then searches the docs server
|
|
7
|
+
* on demand — pulling only the sections it needs instead of reading whole
|
|
8
|
+
* pages. Declining (or any failure) degrades to the docs prefetch, which is
|
|
9
|
+
* what setup did before this step existed.
|
|
10
|
+
*
|
|
11
|
+
* The offer is an optimization and must never take setup down with it:
|
|
12
|
+
* whatever goes wrong (an agent CLI whose flags drifted, a config format we
|
|
13
|
+
* no longer understand), this step reports it, returns a "failed" result, and
|
|
14
|
+
* the caller carries on with the docs download. The only throw that leaves
|
|
15
|
+
* this function is a user cancel.
|
|
16
|
+
*
|
|
17
|
+
* The offer targets exactly one agent — the lane the user chose (or `--agent`
|
|
18
|
+
* pinned) — so setup never sprays MCP config for agents that aren't doing the
|
|
19
|
+
* work. How the entry lands is the agent's own affair ({@link DocsMcpInstall}):
|
|
20
|
+
* agents with an MCP subcommand register it through their own CLI, the rest
|
|
21
|
+
* get a merge into their documented config file. Headless runs never touch
|
|
22
|
+
* agent config unless `--docs-mcp` asked for it.
|
|
23
|
+
*/
|
|
24
|
+
import * as path from "node:path";
|
|
25
|
+
import { DOCS_MCP_SERVER_URL } from "../agents/registry.js";
|
|
26
|
+
import * as COPY from "../copy.js";
|
|
27
|
+
import { SetupCancelledError } from "../errors.js";
|
|
28
|
+
import { selectBoolean } from "../ui/selectBoolean.js";
|
|
29
|
+
import { writeMcpConfig } from "../util/mcpConfig.js";
|
|
30
|
+
const SKIPPED = { outcome: "skipped", agents: [], files: [] };
|
|
31
|
+
/** Registering a server is one config write; a slow CLI start is still fine. */
|
|
32
|
+
const CLI_INSTALL_TIMEOUT_MS = 30_000;
|
|
33
|
+
export async function offerDocsMcp(deps, args) {
|
|
34
|
+
try {
|
|
35
|
+
return await runOffer(deps, args);
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
if (error instanceof SetupCancelledError) {
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
return reportFailure(deps, args, error instanceof Error ? error.message : String(error));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/** The single failure path: say what broke, say what happens instead. */
|
|
45
|
+
function reportFailure(deps, { agent, docsEnabled }, reason) {
|
|
46
|
+
deps.prompter.line(COPY.DOCS_MCP.failedFor(agent.label, reason));
|
|
47
|
+
deps.prompter.line(docsEnabled ? COPY.DOCS_MCP.fallback : COPY.DOCS_MCP.fallbackWithoutDownload);
|
|
48
|
+
return { outcome: "failed", agents: [], files: [] };
|
|
49
|
+
}
|
|
50
|
+
async function runOffer(deps, args) {
|
|
51
|
+
const { docsMcp, agent, headless, docsEnabled } = args;
|
|
52
|
+
if (docsMcp === false) {
|
|
53
|
+
return SKIPPED;
|
|
54
|
+
}
|
|
55
|
+
const install = agent.docsMcpInstall;
|
|
56
|
+
if (!install) {
|
|
57
|
+
// Only worth a line when the caller asked by flag — a pinned agent with
|
|
58
|
+
// no MCP install path (Codex) would otherwise silently ignore it.
|
|
59
|
+
if (docsMcp === true) {
|
|
60
|
+
deps.prompter.line(COPY.DOCS_MCP.unsupported(agent.label));
|
|
61
|
+
}
|
|
62
|
+
return SKIPPED;
|
|
63
|
+
}
|
|
64
|
+
// An unattended run never edits agent config unless --docs-mcp said so.
|
|
65
|
+
if (docsMcp === undefined && headless) {
|
|
66
|
+
return SKIPPED;
|
|
67
|
+
}
|
|
68
|
+
const optedIn = docsMcp ??
|
|
69
|
+
(await selectBoolean({
|
|
70
|
+
prompter: deps.prompter,
|
|
71
|
+
message: COPY.DOCS_MCP.message(agent.label),
|
|
72
|
+
yesLabel: COPY.DOCS_MCP.yes,
|
|
73
|
+
yesHint: COPY.DOCS_MCP.yesHint,
|
|
74
|
+
noLabel: docsEnabled ? COPY.DOCS_MCP.no : COPY.DOCS_MCP.noWithoutDownload,
|
|
75
|
+
noHint: docsEnabled
|
|
76
|
+
? COPY.DOCS_MCP.noHint
|
|
77
|
+
: COPY.DOCS_MCP.noWithoutDownloadHint,
|
|
78
|
+
}));
|
|
79
|
+
if (!optedIn) {
|
|
80
|
+
return { outcome: "declined", agents: [], files: [] };
|
|
81
|
+
}
|
|
82
|
+
if (install.kind === "cli") {
|
|
83
|
+
const exec = (execArgs) => deps.processes.exec({
|
|
84
|
+
command: agent.binary,
|
|
85
|
+
args: execArgs,
|
|
86
|
+
cwd: deps.context.cwd,
|
|
87
|
+
timeoutMs: CLI_INSTALL_TIMEOUT_MS,
|
|
88
|
+
});
|
|
89
|
+
// `add` first: the clean path is one registration plus the read-back.
|
|
90
|
+
// Only when `add` is refused AND the agent's own listing shows an entry
|
|
91
|
+
// under our name is that entry removed and the add retried — removing
|
|
92
|
+
// before knowing the add works would destroy a working registration
|
|
93
|
+
// that a failed retry can't put back.
|
|
94
|
+
let added = await exec(install.addArgs(DOCS_MCP_SERVER_URL));
|
|
95
|
+
if (added.exitCode !== 0) {
|
|
96
|
+
const existing = await exec(install.verifyArgs);
|
|
97
|
+
if (existing.exitCode !== 0) {
|
|
98
|
+
return reportFailure(deps, args, added.stderr.trim() || `exit code ${added.exitCode}`);
|
|
99
|
+
}
|
|
100
|
+
await exec(install.removeArgs);
|
|
101
|
+
added = await exec(install.addArgs(DOCS_MCP_SERVER_URL));
|
|
102
|
+
if (added.exitCode !== 0) {
|
|
103
|
+
return reportFailure(deps, args, added.stderr.trim() || `exit code ${added.exitCode}`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// Don't trust the add's exit code alone: read the entry back through the
|
|
107
|
+
// agent's own listing, so a drifted command that "succeeds" without
|
|
108
|
+
// registering anything is caught here instead of silently costing the
|
|
109
|
+
// agent its docs.
|
|
110
|
+
const verified = await exec(install.verifyArgs);
|
|
111
|
+
if (verified.exitCode !== 0) {
|
|
112
|
+
return reportFailure(deps, args, COPY.DOCS_MCP.verifyFailed);
|
|
113
|
+
}
|
|
114
|
+
deps.prompter.line(COPY.DOCS_MCP.configuredCli(agent.label));
|
|
115
|
+
return { outcome: "configured", agents: [agent.id], files: [] };
|
|
116
|
+
}
|
|
117
|
+
// A write that throws (unparseable existing file, permissions) is handled
|
|
118
|
+
// by the catch-all in offerDocsMcp.
|
|
119
|
+
writeMcpConfig({
|
|
120
|
+
filePath: path.join(deps.context.cwd, install.relativePath),
|
|
121
|
+
displayPath: install.relativePath,
|
|
122
|
+
patch: install.patch(DOCS_MCP_SERVER_URL),
|
|
123
|
+
...(install.createDefaults
|
|
124
|
+
? { createDefaults: install.createDefaults }
|
|
125
|
+
: {}),
|
|
126
|
+
});
|
|
127
|
+
deps.prompter.line(COPY.DOCS_MCP.configured([install.relativePath]));
|
|
128
|
+
return {
|
|
129
|
+
outcome: "configured",
|
|
130
|
+
agents: [agent.id],
|
|
131
|
+
files: [install.relativePath],
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=offerDocsMcp.js.map
|