setup-agent 0.1.2 → 0.2.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 +11 -3
- package/dist/cli.d.ts +0 -20
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +40 -88
- package/dist/cli.js.map +1 -1
- package/dist/guide.d.ts +45 -0
- package/dist/guide.d.ts.map +1 -0
- package/dist/guide.js +133 -0
- package/dist/guide.js.map +1 -0
- package/dist/host.js +1 -1
- package/dist/host.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/needs.d.ts +3 -1
- package/dist/needs.d.ts.map +1 -1
- package/dist/needs.js +20 -17
- package/dist/needs.js.map +1 -1
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +19 -24
- package/dist/sdk.js.map +1 -1
- package/dist/stream.d.ts +6 -2
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +23 -16
- package/dist/stream.js.map +1 -1
- package/package.json +1 -1
- package/src/cli.test.ts +23 -150
- package/src/cli.ts +51 -135
- package/src/guide.test.ts +246 -0
- package/src/guide.ts +177 -0
- package/src/host.ts +1 -1
- package/src/index.ts +2 -0
- package/src/needs.test.ts +4 -5
- package/src/needs.ts +38 -23
- package/src/sdk.test.ts +8 -14
- package/src/sdk.ts +21 -31
- package/src/stream.test.ts +8 -5
- package/src/stream.ts +32 -26
- package/src/tests/guide-fixture.ts +39 -0
- package/src/tests/setup.ts +15 -0
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ One setup, shared live between the browser that opened it and the coding agent i
|
|
|
5
5
|
```sh
|
|
6
6
|
npx setup-agent <url> # instructions plus the current setup
|
|
7
7
|
npx setup-agent <url> stream # one JSON array of events per line; run it under a Monitor
|
|
8
|
-
npx setup-agent <url> wait start # wait for the
|
|
8
|
+
npx setup-agent <url> wait start # wait for the setup page to start the plan
|
|
9
9
|
npx setup-agent <url> log "Sure, I will keep the existing chat route" # a reply, or something no question or step conveys
|
|
10
10
|
npx setup-agent <url> ask --preset llm-provider --only openai,anthropic --default openai
|
|
11
11
|
npx setup-agent <url> ask "Where should assistant-ui live?" --optional # keep working; the answer arrives on the stream
|
|
@@ -23,9 +23,9 @@ npx setup-agent <url> stream --setup-app-url https://setup.assistant-ui.com #
|
|
|
23
23
|
|
|
24
24
|
## Phases
|
|
25
25
|
|
|
26
|
-
A setup opens `waiting` with its products and nothing else: no steps, no questions. After connecting, the agent
|
|
26
|
+
A setup opens `waiting` with its products and nothing else: no steps, no questions. After connecting, the agent keeps the stream running and blocks on `wait start`, which prints `{"ok":true,"status":"planning"}` once planning begins, or `{"ok":false,"status":"cancelled"}` when the user ends the setup first. The setup page has no Begin plan button: it sends `checkout/begin-plan` by itself once it joins a waiting setup, moving the setup to `planning` and emitting `planning.started` on the stream. Questions and plan submissions are refused while waiting. Products are the starting list of names and setup guide references. The agent explores every starting guide and may discover other relevant products or dependencies without adding them to the cart. It includes those additions in the plan for approval. The legacy `ask --product` and `checkout/add-product` protocol remains supported for older agents. In `planning`, the agent investigates the project, asks what the code does not decide, and proposes a markdown plan with `plan` carrying its findings. `log` is for replying to the user and for what no question or step conveys. The user approves the plan or asks for changes with feedback; every revision is kept. Approval moves the setup to `installing`, where the agent declares its own steps with `add-step` and works through them with `step`. `add-step` and `step` are refused before approval. `done` marks the remaining steps done and proposes closing, with an optional `--summary` and an optional `--preview <url>` naming a dev server the agent left running; a preview must be an http(s) URL on localhost, and the browser offers to open it. `done` does not close. The browser shows the proposal with a close action that sends `checkout/finish`, and the stream prints `finished`. Until then the agent stays idle on the stream, because the user may send a follow-up message; after handling one it runs `done` again to renew the proposal.
|
|
27
27
|
|
|
28
|
-
The URL is the browser's link to its agent, not one setup. A finished or cancelled setup stays on the link
|
|
28
|
+
The URL is the browser's link to its agent, not one setup. A finished or cancelled setup stays on the link until the agent replaces it with a new `checkout/create` carrying a new `id` (only the agent creates setups; the browser never sends it): the plans, steps, inputs and log start over, the agent's presence carries across when it is still connected, and the stream prints `setup.created` with the new products. The agent keeps the stream running after `finished` or `cancelled` and blocks on `wait start`, which returns once the next setup begins planning; a setup already closed when the wait begins is skipped rather than reported.
|
|
29
29
|
|
|
30
30
|
The browser sends the setup `id` and the displayed plan `revision` with each `checkout/plan` decision. The host rejects a mismatched setup or revision with `stale-plan`, so a queued decision cannot approve or revise a newer plan. Older clients may omit these fields and retain their existing behavior. The guard requires a host running this version of `setup-agent`.
|
|
31
31
|
|
|
@@ -76,6 +76,14 @@ The browser opens only when the setup waits on the user (an open input, a propos
|
|
|
76
76
|
|
|
77
77
|
Each `input.needed` carries the question, its options and the `answer` command. On a worker without browser presence, setup opens once and then leaves the rest to the agent.
|
|
78
78
|
|
|
79
|
+
## Guide
|
|
80
|
+
|
|
81
|
+
Setup is online-only. Every text the CLI shows the agent lives on the setup server (`apps/checkout-worker/src/guide.ts`), so a wording or flow fix ships with a worker deploy and reaches every CLI from this version on. That covers the briefing, the stream's messages, the `waiting` and `done` hints, and the questions `input.needed` relays. Commands that print guidance (`<url>` itself, `stream`, `ask`, `plan`, `wait`, `done`, and `runAgentSetup`) fetch `GET <setup-url>/guide?protocol=1&started=<user|agent|agent-stream>&opened=<0|1>`. Without it they fail with `Setup needs internet access to <url>`.
|
|
82
|
+
|
|
83
|
+
The guide is data. The CLI strips control characters and bidirectional overrides from every text, and fills `{{cmd}}`, `{{url}}` and the other placeholders with values it computes itself. It runs the intro only from three local actions: `print` (a text by key), `print-status` and `announce-agent`. It refuses any other step, a guide over 256 KB, and redirects. Commands for the CLI to run, files it writes and URLs it opens never come from the guide. The server's text can still steer the agent, as its questions and user messages already can, so the guide is as trusted as the setup server.
|
|
84
|
+
|
|
85
|
+
`GUIDE_PROTOCOL` is the format version. The server answers another version with 426, and the CLI tells the user to update. Bump it only for a change an older CLI cannot read. A new command, flag or local action needs an npm release.
|
|
86
|
+
|
|
79
87
|
## Workspace
|
|
80
88
|
|
|
81
89
|
The package lives in `packages/setup-agent`; its Cloudflare worker lives in `apps/checkout-worker`. Build the worker dependencies with `pnpm turbo build --filter="checkout-worker^..."`, then run `pnpm --filter checkout-worker dev`. The worker consumes the published `@statewire/cloudflare` adapter.
|
package/dist/cli.d.ts
CHANGED
|
@@ -9,26 +9,6 @@ export declare const HELP: string;
|
|
|
9
9
|
* no credentials, query or fragment, and hold only address characters.
|
|
10
10
|
*/
|
|
11
11
|
export declare const parseSetupUrl: (value: string) => string;
|
|
12
|
-
export type AgentInstructionsOptions = {
|
|
13
|
-
/** How the agent invokes the setup commands, before the URL; `npx setup-agent` by default. */
|
|
14
|
-
command?: string;
|
|
15
|
-
/**
|
|
16
|
-
* The agent started this setup with `assistant-ui setup`, which already
|
|
17
|
-
* began planning; there is no Begin plan click to wait for.
|
|
18
|
-
*/
|
|
19
|
-
startedByAgent?: {
|
|
20
|
-
browserUrl: string;
|
|
21
|
-
/** False when the browser was not opened for the user; the agent then hands them the link. */
|
|
22
|
-
opened?: boolean;
|
|
23
|
-
/**
|
|
24
|
-
* The command that printed this briefing is the stream: it keeps running
|
|
25
|
-
* and opens the browser only when the setup waits on the user.
|
|
26
|
-
*/
|
|
27
|
-
streaming?: boolean;
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
export declare const agentInstructions: (setupUrl: string, options?: AgentInstructionsOptions) => string;
|
|
31
|
-
export declare const INSTRUCTIONS: typeof agentInstructions;
|
|
32
12
|
type Parsed = {
|
|
33
13
|
positional: string[];
|
|
34
14
|
flags: Map<string, string | true>;
|
package/dist/cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAU,CAAC;AA2B/C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAU,CAAC;AA2B/C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAY,CAAC;AAM3C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAU,CAAC;AAatC,eAAO,MAAM,IAAI,QAuChB,CAAC;AAMF;;;;;GAKG;AACH,eAAO,MAAM,aAAa,UAAW,MAAM,KAAG,MA6B7C,CAAC;AASF,KAAK,MAAM,GAAG;IAAE,UAAU,EAAE,MAAM,EAAE,CAAC;IAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAA;CAAE,CAAC;AAuB1E,OAAO,EACL,aAAa,EACb,eAAe,EACf,WAAW,EACX,kBAAkB,EAClB,cAAc,GACf,MAAM,aAAU,CAAC;AAClB,YAAY,EAAE,WAAW,EAAE,MAAM,aAAU,CAAC;AAuG5C,2LAA2L;AAC3L,eAAO,MAAM,YAAY,WACf,IAAI,CAAC,cAAc,EAAE,OAAO,GAAG,WAAW,CAAC,6BAiBjD,CAAC;AAiGL,eAAO,MAAM,OAAO,SACZ,SAAS,MAAM,EAAE,SAChB,MAAM,CAAC,OAAO,CAAC,KACrB,QAAQ,CAAC,SAAS,GAAG;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CA+HxC,CAAC;AAQF,+EAA+E;AAC/E,eAAO,MAAM,aAAa,YAAa,MAAM,OAAO,MAAM,SAAS,MAAM,WAqBxE,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,cAAc,SACnB,MAAM,OACP,MAAM,QACL,MAAM,OAAO,CAAC,MAAM,CAAC,wCAuD5B,CAAC;AAgHF,MAAM,MAAM,sBAAsB,GAAG;IACnC,0FAA0F;IAC1F,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,qGAAqG;IACrG,OAAO,CAAC,EAAE;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;CACtD,CAAC;AAoCF,eAAO,MAAM,IAAI,SAAU,SAAS,MAAM,EAAE,kBAA0B,CAAC;AAEvE;;;GAGG;AACH,eAAO,MAAM,eAAe,SACpB,SAAS,MAAM,EAAE,YACd,sBAAsB,kBAgVhC,CAAC"}
|
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CODING_AGENTS, detectAgentKind, findCommand, isDirectInvocation, runCodingAgent } from "./agents.js";
|
|
2
2
|
import { OPTION_ICONS, currentPlan, isAgentPresent, isClosed, isLoopbackHostname, isOptionIcon, isValidModelAnswer, parseEntryPointOptions, stepProgress } from "./protocol.js";
|
|
3
|
+
import { loadGuide, renderText } from "./guide.js";
|
|
3
4
|
import { answerNeed } from "./needs.js";
|
|
4
5
|
import { connectCheckout } from "./client.js";
|
|
5
6
|
import { INPUT_PRESETS, isPresetId, presetInput } from "./presets.js";
|
|
@@ -43,7 +44,7 @@ Commands (the url always comes first):
|
|
|
43
44
|
--icons is required and names an icon for every option, from: ${OPTION_ICONS.join(", ")}.
|
|
44
45
|
ask <prompt> --entry-points '<JSON array>' [--default <id>] [--optional] [--step <step-id>] [--wait]
|
|
45
46
|
Ask where users should access the assistant. Each of 1–3 options has id, label, description and entryPoint {formFactor: modal|sidebar|full-page, placement, trigger, recommended?}. Answers one option id.
|
|
46
|
-
wait start Block until the
|
|
47
|
+
wait start Block until the setup page starts the plan; prints {"ok":false,"status":"cancelled"} if the user cancels first. After a finished or cancelled setup, waits for the next one to begin.
|
|
47
48
|
wait <input-id> [--timeout <seconds>]
|
|
48
49
|
Block until the user answers or dismisses an input. A multi-select answer prints as an array.
|
|
49
50
|
plan (<markdown> | --file <path>) [--wait] [--timeout <seconds>]
|
|
@@ -82,71 +83,12 @@ const parseSetupUrl = (value) => {
|
|
|
82
83
|
if (!SETUP_URL_PATTERN.test(href)) throw new Error("the setup URL has characters a setup URL does not use");
|
|
83
84
|
return href;
|
|
84
85
|
};
|
|
85
|
-
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
- "browser.opened" ({id, message}): setup opened the setup page in the user's browser for a question. Tell the user once, in your own conversation, that it waits there, and keep working in the same turn.
|
|
92
|
-
- "input.needed" ({id, message, question, options?, answer}): the user may not see the browser right now. Do what its message says: run "wait <id>" for their answer in the browser, or ask the user in your own conversation with that question and options, then run its "answer" command with their reply. Answered either way, the setup goes on.
|
|
93
|
-
If this command stops, start it again in the background with
|
|
94
|
-
${cmd} ${url} stream${noOpen ? " --no-open" : ""}
|
|
95
|
-
The URL is the user's link to you from their browser, not one setup: it outlives this one, and their next setup arrives on the same stream.` : `First, start a persistent Monitor on
|
|
96
|
-
${cmd} ${url} stream
|
|
97
|
-
and keep it running: the browser shows you as connected only while it runs, and it is how answers reach you. The URL is the user's link to you from their browser, not one setup: it outlives this one, and their next setup arrives on the same stream. Each line is a JSON array of events: ${EVENT_LIST}.`;
|
|
98
|
-
/** Why the agent must not end its turn mid-setup, and how it waits instead. */
|
|
99
|
-
const keepGoing = (cmd, url) => `Run the setup to the end in one go. Do not count on the stream or the browser to wake you: if you end your turn before the install is done, the setup can stay paused until the user types to you, even after they answer in the browser. So never end your turn to wait for an answer, and do not stop after telling the user something. To get an answer, block on it:
|
|
100
|
-
${cmd} ${url} wait <input-id>
|
|
101
|
-
("plan --wait" and "ask --wait" block the same way). A wait that prints {"ok":false,"status":"waiting"} has not failed and the setup is not stuck: run its "next" command, right away. "next" only waits; never repeat an "ask" or "plan" to keep waiting, since that asks or submits again. End your turn only to ask the user in your own conversation (an "input.needed" you relay, or a value only they can give), and go on as soon as they reply; or once the install is done and proposed with "done".`;
|
|
102
|
-
const agentInstructions = (setupUrl, options = {}) => {
|
|
103
|
-
const url = shellWord(setupUrl);
|
|
104
|
-
const cmd = options.command ?? DEFAULT_COMMAND;
|
|
105
|
-
const started = options.startedByAgent;
|
|
106
|
-
const streaming = started?.streaming === true;
|
|
107
|
-
return `You are the coding agent for a setup ${started ? streaming ? started.opened === false ? "you started; setup opens no browser (--no-open), so the user follows it on the setup page if they open it, or answers you in your own conversation" : "you started; the user follows it in their browser, which setup opens when you ask the user something" : "you opened in the user's browser" : "the user opened in their browser"}. The browser shows this setup live; every command below updates it. The user watches the browser, not this terminal: once setup begins, send questions through "ask" so the user can answer in their browser.
|
|
108
|
-
|
|
109
|
-
${streamSection(cmd, url, streaming, started?.opened === false)}
|
|
110
|
-
|
|
111
|
-
${keepGoing(cmd, url)}
|
|
112
|
-
|
|
113
|
-
The user can message you at any time, including while a question is waiting. Read "message.created" events, acknowledge each with "${cmd} ${url} ack <message-id>", and reply using "log" with what you will do. Pending messages are replayed when the stream starts and listed in "status". A message is not an answer or plan approval; keep those decisions explicit.
|
|
114
|
-
|
|
115
|
-
"log" is a message to the user, and the user reads every one: send it only to reply to their message, to tell them something no question or step conveys (a blocker, a deviation from the plan, a decision you made for them), or once as a wrap-up when the install is finished. Findings go in the plan, progress in step notes, questions in "ask"; do not narrate.
|
|
116
|
-
|
|
117
|
-
${started ? agentStartedHandoff(started) : beginPlanHandoff(cmd, url)}
|
|
118
|
-
|
|
119
|
-
The remaining phases are plan, then install.
|
|
120
|
-
|
|
121
|
-
1. Plan. Investigate only; change nothing yet. If the current directory is not an app to install into (a monorepo root, an empty folder, a library), ask where to install first:
|
|
122
|
-
${cmd} ${url} ask "Which project should I install into?" --placeholder "An absolute path to the app" --wait
|
|
123
|
-
Read the project: its app framework and package manager, the agent framework and model provider it already uses, where components live, any existing chat route. Fetch each product's "guide" URL from the setup below; it is the install reference. Ask for what the project does not decide, using the standard questions so the browser can render them well:
|
|
124
|
-
${cmd} ${url} ask --preset framework
|
|
125
|
-
${cmd} ${url} ask --preset llm-provider
|
|
126
|
-
The setup's products are starting names and guide references. If the setup lists no products, first ask the user what to set up with a choice question whose options are slugs from https://www.assistant-ui.com/catalog.md, then fetch https://www.assistant-ui.com/install.md?items=<slugs> as the guide. Explore each product's setup instructions, then discover and plan any other relevant products or dependencies the app needs. Read /catalog.md on the guide URL’s origin to find related products and fetch their setup guides. The starting list does not restrict the implementation or require adding another product to the list. Include relevant additions in the plan for approval.
|
|
127
|
-
When the setup puts an assistant in the app, ask how users should access it after discovering the actual app and before proposing the plan. Skip this question when no product's guide installs an assistant (a standalone library or service setup, for example). Use an entry-point question with only 1–3 sensible alternatives. Describe the actual app's pages, workflow and component placement, not generic placeholder copy. Recommend one clear fit when there is one; two options may use the same form factor in different places. Each option needs a stable id, label, contextual description and entryPoint {"formFactor":"modal"|"sidebar"|"full-page","placement":"where it appears","trigger":"how users open it or navigate to it","recommended":true?}. Write the JSON array for this app and send it with:
|
|
128
|
-
${cmd} ${url} ask "Where should users access the assistant?" --entry-points '<JSON array>' --wait
|
|
129
|
-
Mark a clear fit with "recommended":true rather than --default, so the user makes the pick. When you ask it, do not submit the plan before the user picks an entry point. Respect the selected placement and trigger in the plan and implementation. Do not ask for a new-versus-existing app setting; discover the app from its files and ask only for an install path when needed.
|
|
130
|
-
Skip a preset the code already answers (a chat route on the AI SDK, a provider key in .env.local) and log why. Ask everything at once, keep investigating, and then run "wait <input-id>" for each open question before you write the plan; do not end your turn while they are open. A framework answer is "<framework>:<language>", for example "ai-sdk:typescript". A model answer is JSON {"provider","model","reasoningEffort"?}. An answer may carry a "note" from the user; follow it. A choice answer that matches none of the options is the user's own text.
|
|
131
|
-
Then write the plan as markdown and submit it:
|
|
132
|
-
${cmd} ${url} plan --file <path> --wait
|
|
133
|
-
Use these headings, each with bullets: "## What I found" (facts as \`- **Label:** value\`: app framework, package manager, agent framework, model provider and model, where components live), "## What I will install" (packages and files, one per bullet), "## Steps" (a numbered list, one line each), and "## Open questions" only if any remain. Keep it under 30 lines; no preamble. "plan --wait" prints {"decision":"approve"} or {"decision":"revise","feedback":"..."}; when it prints {"ok":false,"status":"waiting"}, the plan is submitted and still with the user, so keep waiting with "wait plan" and do not submit it again. On revise, address the feedback (ask again if you need to) and submit a new plan; repeat until approved. Do not change the project before approval: the setup refuses steps until then.
|
|
134
|
-
|
|
135
|
-
2. Install. Declare the steps from your plan up front, in order:
|
|
136
|
-
${cmd} ${url} add-step "<title>" --detail "<one line>"
|
|
137
|
-
which prints the step id. Then work through them: "step <id> active" before, "step <id> done --note '<one line on what you did>'" after; "skipped" when the step is already satisfied, "blocked" when you cannot continue, saying why in --note. Add steps as the work reveals them. Ask when you need another decision or value (--choices for a pick, plain for text; --optional when you can proceed without an answer; --wait only when the answer is the very next thing you need). A choice question is multi-select: the user checks any number of your options, and the answer is an array of the ids they checked, plus their own text as an entry when they typed one. Pass --single only when the options exclude each other (one framework, one model, yes or no); the answer is then one id. Every option must carry an icon, given as --icons "<id>=<icon>,..." with the closest name from this pack: ${OPTION_ICONS.join(", ")}. A question without an icon for each option is refused. Open inputs the user has not answered are listed under "inputs" in "status"; check them before asking again.
|
|
138
|
-
The API key behind a model answer is not in the answer and you never see it: pick the variable name the provider's SDK reads (OPENAI_API_KEY, ANTHROPIC_API_KEY, ...) and run
|
|
139
|
-
${cmd} ${url} env <input-id> <ENV_VAR> --file .env.local
|
|
140
|
-
which writes ENV_VAR=<key> into that file. Use the answer's model in the chat route and map reasoningEffort onto the provider's setting when it is set. If "env" says the key was never deposited (the model question was answered from your conversation), ask the user to add the key to that file themselves. Never invent a key or a model name.
|
|
141
|
-
|
|
142
|
-
When every product is installed and verified, run
|
|
143
|
-
${cmd} ${url} done --summary "<one or two lines on what you installed and how to try it>" --preview http://localhost:<port>
|
|
144
|
-
Before that, start the project's dev server in the background when the project has one, check that the page you changed loads, and pass the address as --preview (the page itself when it is not the root); leave the server running so the user can try the result. Omit --preview when there is nothing to open. This proposes closing the setup; only the user closes it. Do not stop the stream or exit: stay idle on it, because the user may follow up with a "message.created" event. Handle it, then run "done" again. The stream prints "finished" once the user closes the setup, and "cancelled" if they end it early. Keep the stream running after either: the user's next setup starts on this same URL and arrives as "setup.created" with its products. Run
|
|
145
|
-
${cmd} ${url} wait start
|
|
146
|
-
which returns once that setup begins, then run "status" for its products, guides and instructions and go through plan and install again. A "setup.created" event while you are still working means the user replaced this setup: drop what you were doing and start over the same way.
|
|
147
|
-
`;
|
|
148
|
-
};
|
|
149
|
-
const INSTRUCTIONS = agentInstructions;
|
|
86
|
+
/** The values the CLI fills into guide texts itself; never the server's to choose. */
|
|
87
|
+
const localValues = (setupUrl, command = DEFAULT_COMMAND) => ({
|
|
88
|
+
cmd: command,
|
|
89
|
+
url: shellWord(setupUrl),
|
|
90
|
+
icons: OPTION_ICONS.join(", ")
|
|
91
|
+
});
|
|
150
92
|
const parseArgs = (argv) => {
|
|
151
93
|
const positional = [];
|
|
152
94
|
const flags = /* @__PURE__ */ new Map();
|
|
@@ -302,12 +244,12 @@ const within = async (promise, seconds) => {
|
|
|
302
244
|
}
|
|
303
245
|
};
|
|
304
246
|
/** What a wait prints when the user has not decided yet: the command to run again, now. */
|
|
305
|
-
const stillWaiting = (target, next) => ({
|
|
247
|
+
const stillWaiting = (target, next, guide) => ({
|
|
306
248
|
ok: false,
|
|
307
249
|
status: "waiting",
|
|
308
250
|
waitingFor: target,
|
|
309
251
|
next,
|
|
310
|
-
message:
|
|
252
|
+
message: renderText(guide, "wait.waiting")
|
|
311
253
|
});
|
|
312
254
|
const decided = (plan, state) => {
|
|
313
255
|
if (state.status === "cancelled") return {
|
|
@@ -552,15 +494,18 @@ const answered = (input) => ({
|
|
|
552
494
|
status: input.status,
|
|
553
495
|
...input.answer !== void 0 && answerFields(input, input.answer)
|
|
554
496
|
});
|
|
555
|
-
const runStream = async (client, url, flags, options) => {
|
|
497
|
+
const runStream = async (client, url, flags, options, guide) => {
|
|
556
498
|
const setupAppUrl = options.browser?.setupAppUrl ?? flagText(flags, "setup-app-url");
|
|
557
499
|
const linkId = new URL(url).pathname.split("/").filter(Boolean).at(-1);
|
|
558
|
-
const stream = await followSetup(client, {
|
|
559
|
-
|
|
560
|
-
linkId
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
500
|
+
const stream = await followSetup(client, {
|
|
501
|
+
guide,
|
|
502
|
+
...setupAppUrl !== void 0 && linkId !== void 0 && { browser: {
|
|
503
|
+
setupAppUrl: parseSetupUrl(setupAppUrl),
|
|
504
|
+
linkId,
|
|
505
|
+
answerCommand: `${options.command ?? DEFAULT_COMMAND} ${shellWord(url)} answer`,
|
|
506
|
+
canOpen: (options.browser?.canOpen ?? true) && !flags.has("no-open")
|
|
507
|
+
} }
|
|
508
|
+
});
|
|
564
509
|
const stop = () => {
|
|
565
510
|
stream.stop().finally(() => {
|
|
566
511
|
client.dispose();
|
|
@@ -593,22 +538,28 @@ const runSetupCommand = async (argv, options = {}) => {
|
|
|
593
538
|
if (command === "intro" && isDirectInvocation()) return launchAgent(url);
|
|
594
539
|
const client = await connectCheckout(url).catch((error) => fail(error instanceof Error ? error.message : String(error)));
|
|
595
540
|
const commands = client.commands;
|
|
541
|
+
let guideLoad;
|
|
542
|
+
const guide = () => guideLoad ??= loadGuide(url, {
|
|
543
|
+
started: "user",
|
|
544
|
+
opened: command !== "stream" || (options.browser?.setupAppUrl ?? flagText(flags, "setup-app-url")) !== void 0 && (options.browser?.canOpen ?? true) && !flags.has("no-open")
|
|
545
|
+
});
|
|
596
546
|
const waitCommand = (target) => `${options.command ?? DEFAULT_COMMAND} ${shellWord(url)} wait ${target}`;
|
|
597
547
|
try {
|
|
598
548
|
switch (command) {
|
|
599
549
|
case "intro": {
|
|
600
|
-
const
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
print(
|
|
550
|
+
const intro = await guide();
|
|
551
|
+
for (const step of intro.intro) if (step.action === "announce-agent") {
|
|
552
|
+
const kind = detectAgentKind();
|
|
553
|
+
await commands["agent/intro"]({ ...kind !== void 0 && { kind } }).catch(() => {});
|
|
554
|
+
} else if (step.action === "print") process.stdout.write(renderText(intro, step.text, localValues(url, options.command)));
|
|
555
|
+
else print(summary(requireState(client)));
|
|
605
556
|
break;
|
|
606
557
|
}
|
|
607
558
|
case "status":
|
|
608
559
|
print(summary(requireState(client)));
|
|
609
560
|
break;
|
|
610
561
|
case "stream":
|
|
611
|
-
await runStream(client, url, flags, options);
|
|
562
|
+
await runStream(client, url, flags, options, await guide());
|
|
612
563
|
break;
|
|
613
564
|
case "answer": {
|
|
614
565
|
const id = rest[0] ?? fail("usage: answer <input-id|plan|finish> <answer> [--note <text>]");
|
|
@@ -667,7 +618,7 @@ const runSetupCommand = async (argv, options = {}) => {
|
|
|
667
618
|
break;
|
|
668
619
|
}
|
|
669
620
|
const plan = await within(waitForPlan(client, revision), waitSeconds(flags, DEFAULT_WAIT_SECONDS));
|
|
670
|
-
print(plan === TIMED_OUT ? stillWaiting("plan", waitCommand("plan")) : decided(plan, requireState(client)));
|
|
621
|
+
print(plan === TIMED_OUT ? stillWaiting("plan", waitCommand("plan"), await guide()) : decided(plan, requireState(client)));
|
|
671
622
|
break;
|
|
672
623
|
}
|
|
673
624
|
case "ask": {
|
|
@@ -693,7 +644,7 @@ const runSetupCommand = async (argv, options = {}) => {
|
|
|
693
644
|
break;
|
|
694
645
|
}
|
|
695
646
|
const input = await within(waitForInput(client, inputId), waitSeconds(flags, DEFAULT_WAIT_SECONDS));
|
|
696
|
-
print(input === TIMED_OUT ? stillWaiting(inputId, waitCommand(inputId)) : answered(input));
|
|
647
|
+
print(input === TIMED_OUT ? stillWaiting(inputId, waitCommand(inputId), await guide()) : answered(input));
|
|
697
648
|
break;
|
|
698
649
|
}
|
|
699
650
|
case "wait": {
|
|
@@ -702,7 +653,7 @@ const runSetupCommand = async (argv, options = {}) => {
|
|
|
702
653
|
if (target === "start") {
|
|
703
654
|
const status = await within(waitForStart(client), waitSeconds(flags, 0));
|
|
704
655
|
if (status === TIMED_OUT) {
|
|
705
|
-
print(stillWaiting("start", waitCommand("start")));
|
|
656
|
+
print(stillWaiting("start", waitCommand("start"), await guide()));
|
|
706
657
|
break;
|
|
707
658
|
}
|
|
708
659
|
print({
|
|
@@ -714,12 +665,12 @@ const runSetupCommand = async (argv, options = {}) => {
|
|
|
714
665
|
if (target === "plan") {
|
|
715
666
|
const plan = currentPlan(state) ?? fail("no plan has been proposed");
|
|
716
667
|
const decision = await within(waitForPlan(client, plan.revision), waitSeconds(flags, DEFAULT_WAIT_SECONDS));
|
|
717
|
-
print(decision === TIMED_OUT ? stillWaiting("plan", waitCommand("plan")) : decided(decision, requireState(client)));
|
|
668
|
+
print(decision === TIMED_OUT ? stillWaiting("plan", waitCommand("plan"), await guide()) : decided(decision, requireState(client)));
|
|
718
669
|
break;
|
|
719
670
|
}
|
|
720
671
|
if (!state.inputs.some((input) => input.id === target)) fail(`no input "${target}"`);
|
|
721
672
|
const input = await within(waitForInput(client, target), waitSeconds(flags, DEFAULT_WAIT_SECONDS));
|
|
722
|
-
print(input === TIMED_OUT ? stillWaiting(target, waitCommand(target)) : answered(input));
|
|
673
|
+
print(input === TIMED_OUT ? stillWaiting(target, waitCommand(target), await guide()) : answered(input));
|
|
723
674
|
break;
|
|
724
675
|
}
|
|
725
676
|
case "env": {
|
|
@@ -770,6 +721,7 @@ const runSetupCommand = async (argv, options = {}) => {
|
|
|
770
721
|
break;
|
|
771
722
|
}
|
|
772
723
|
case "done": {
|
|
724
|
+
const hint = renderText(await guide(), "done.next");
|
|
773
725
|
const summary = flagText(flags, "summary");
|
|
774
726
|
const preview = flagText(flags, "preview");
|
|
775
727
|
await commands["agent/done"]({
|
|
@@ -779,7 +731,7 @@ const runSetupCommand = async (argv, options = {}) => {
|
|
|
779
731
|
print({
|
|
780
732
|
ok: true,
|
|
781
733
|
status: "proposed",
|
|
782
|
-
next:
|
|
734
|
+
next: hint
|
|
783
735
|
});
|
|
784
736
|
break;
|
|
785
737
|
}
|
|
@@ -791,6 +743,6 @@ const runSetupCommand = async (argv, options = {}) => {
|
|
|
791
743
|
client.dispose();
|
|
792
744
|
}
|
|
793
745
|
};
|
|
794
|
-
export { CODING_AGENTS, HELP,
|
|
746
|
+
export { CODING_AGENTS, HELP, askSeed, detectAgentKind, diffEvents, findCommand, isDirectInvocation, main, parseSetupUrl, runCodingAgent, runSetupCommand, upsertEnvLine, waitForStart, writeEnvSecret };
|
|
795
747
|
|
|
796
748
|
//# sourceMappingURL=cli.js.map
|