@cargo-ai/cli 1.0.72 → 1.0.73

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.
@@ -0,0 +1,222 @@
1
+ // The pure half of `start`: what it knows, turned into prose.
2
+ //
3
+ // Kept apart from the flow so the interesting decisions — what a coding agent
4
+ // is told, where the palette opens, what `--continue` accepts — are testable
5
+ // without a terminal, the way `planRevocation` and `collectSetupIssues` are.
6
+ import { CANONICAL_SKILLS_DIRECTORY, CDK_SKILL, SKILLS_INSTALL_COMMAND, } from "@cargo-ai/cdk/cli";
7
+ /**
8
+ * The command group "Explore in the CLI" opens the palette on. The action
9
+ * catalog is the shortest path from a menu to something real: search one, run
10
+ * one, see a result.
11
+ */
12
+ export const EXPLORE_PATH = ["orchestration", "action"];
13
+ export const ROUTER_SKILL = "cargo";
14
+ export const DEMO_SKILL = "cargo-quickstart";
15
+ export { CDK_SKILL };
16
+ /**
17
+ * `--continue <where>` as a destination. Agents are named the way a person
18
+ * refers to them ("cursor"), not the way they are installed ("cursor-agent"),
19
+ * and one that is not on this machine is a usage error rather than a silent
20
+ * fallback to something else.
21
+ */
22
+ export function parseDestination(value, agents) {
23
+ const wanted = value.trim().toLowerCase();
24
+ if (wanted === "code") {
25
+ return { kind: "code" };
26
+ }
27
+ if (wanted === "cli") {
28
+ return { kind: "cli" };
29
+ }
30
+ if (wanted === "demo") {
31
+ return { kind: "demo" };
32
+ }
33
+ if (wanted === "none") {
34
+ return { kind: "none" };
35
+ }
36
+ const agent = agents.find((candidate) => candidate.bin === wanted ||
37
+ candidate.bin.replace(/-agent$/, "") === wanted);
38
+ if (agent === undefined) {
39
+ return undefined;
40
+ }
41
+ return { kind: "agent", agent };
42
+ }
43
+ /**
44
+ * The brief a coding agent is opened with. An agent launched in a bare
45
+ * directory has to rediscover the workspace, the skills and the cost rules;
46
+ * this is the whole reason the handoff beats telling someone to open Claude
47
+ * Code themselves.
48
+ *
49
+ * What it says depends on `project` — see `ProjectContext` for why all three
50
+ * cases need different words rather than one brief and a different skill name.
51
+ */
52
+ export function buildBrief(facts, skill, project = { kind: "none" }) {
53
+ return [
54
+ ...opening(project),
55
+ "",
56
+ `Workspace: ${facts.workspace.name} (${facts.workspace.uuid})`,
57
+ "",
58
+ "## Start here",
59
+ "",
60
+ ...startSteps(facts, skill),
61
+ ...firstMove(project),
62
+ "",
63
+ ...RULES,
64
+ ].join("\n");
65
+ }
66
+ /** What the agent has been opened on, in the first two sentences. */
67
+ function opening(project) {
68
+ if (project.kind === "none") {
69
+ return [
70
+ "Work with the user on their Cargo workspace.",
71
+ "",
72
+ "Cargo is GTM infrastructure: connectors to the systems they sell with,",
73
+ "models holding the data, plays and agents that act on it. The `cargo-ai`",
74
+ "CLI is installed and signed in.",
75
+ ];
76
+ }
77
+ return [
78
+ "Work with the user on the Cargo workspace declared in this repo.",
79
+ "",
80
+ "This is a Cargo CDK project: the workspace — connectors, models, plays,",
81
+ "tools and agents — is defined in files under `infra/` and applied with",
82
+ "`npm run deploy`. Read what is declared before changing anything; the",
83
+ "repo, not the workspace, is the source of truth.",
84
+ ];
85
+ }
86
+ /**
87
+ * Step 3: the one thing to do first, which is the whole point of branching.
88
+ *
89
+ * Outside a project that is a conversation. Inside one it is reading — and
90
+ * inside one with a cookbook it is that cookbook's own procedure, which is
91
+ * more specific than anything this brief could restate.
92
+ */
93
+ function firstMove(project) {
94
+ if (project.kind === "none") {
95
+ return [
96
+ "3. Ask what they are trying to do before building anything. If they are",
97
+ " not sure, `npx @cargo-ai/cdk cookbook list` is the menu of worked",
98
+ " pipelines, and `cargo-ai orchestration action list <query>` is the",
99
+ " catalog of individual actions.",
100
+ ];
101
+ }
102
+ const company = project.companyContextPath === undefined
103
+ ? []
104
+ : [
105
+ `4. Read \`${project.companyContextPath}\` — the user has already`,
106
+ " answered who they are and who they sell to. Expand it with them",
107
+ " rather than asking again.",
108
+ ];
109
+ if (project.kind === "cookbook") {
110
+ return [
111
+ `3. This project has ${project.cookbooks.length === 1 ? "a cookbook" : "cookbooks"} installed:`,
112
+ ...project.cookbooks.map((name) => ` - \`${name}\` — its procedure is \`${CANONICAL_SKILLS_DIRECTORY}/${name}/SKILL.md\``),
113
+ " Read that first and follow it. It is the authority on this pipeline,",
114
+ " including what it needs from the user. Do not re-derive the intent or",
115
+ " go looking for a different cookbook.",
116
+ ...company,
117
+ ];
118
+ }
119
+ return [
120
+ "3. Run `npm run info` to see every resource this project declares, which",
121
+ " file declares it, and whether it is deployed. That is the fastest way",
122
+ " to understand the workspace, and it is offline. Then ask what they want",
123
+ " to change.",
124
+ ...company,
125
+ ];
126
+ }
127
+ /**
128
+ * The brief behind the guided demo.
129
+ *
130
+ * It names `cargo-quickstart` rather than describing the demo, because that
131
+ * skill *is* this demo — a persona, ~25 leads, a cost receipt, then saving the
132
+ * pull as a play. Describing the outcome instead is what cost the first version
133
+ * half its runtime (see `HandoffSkill`), so this brief spends its length on
134
+ * pointing at the procedure and forbidding the detour.
135
+ */
136
+ export function buildDemoBrief(facts, icp) {
137
+ return [
138
+ "Run the Cargo quickstart demo for the user, now.",
139
+ "",
140
+ `Workspace: ${facts.workspace.name} (${facts.workspace.uuid})`,
141
+ icp === undefined
142
+ ? "They have not said who they sell to yet — ask, in one question."
143
+ : `Who they sell to, in their words: ${icp}`,
144
+ "",
145
+ "## How",
146
+ "",
147
+ ...startSteps(facts, DEMO_SKILL),
148
+ `3. Follow \`${DEMO_SKILL}\` exactly. It is the procedure for this — a`,
149
+ " persona, around 25 matching leads, a cost receipt, and saving the pull",
150
+ " as a recurring play. Do not re-derive it, and do not route to a",
151
+ " different skill because the market sounds specific.",
152
+ "",
153
+ "## Do not go exploring",
154
+ "",
155
+ "This is a two-minute demo and discovery is what kills it. The skill names",
156
+ "the actions and their inputs; take them from there rather than:",
157
+ "",
158
+ "- guessing action names with repeated `orchestration action list` calls,",
159
+ "- dumping `connection integration get <slug>` to find a config schema,",
160
+ "- reading `--help` for commands the skill already spells out.",
161
+ "",
162
+ "If something genuinely is not in the skill, say so and ask the user rather",
163
+ "than spelunking. Their first impression of Cargo is how long this takes.",
164
+ "",
165
+ ...RULES,
166
+ ].join("\n");
167
+ }
168
+ /** The block printed when nobody wanted a handoff. */
169
+ export function formatStartNextSteps(facts) {
170
+ const lines = [
171
+ "Next steps:",
172
+ " cargo-ai whoami # confirm the workspace",
173
+ " cargo-ai orchestration action list enrich # find something to run",
174
+ " cargo-ai cdk init # set the workspace up as code",
175
+ " cargo-ai # the command palette",
176
+ ];
177
+ if (facts.skillsInstalled === false) {
178
+ lines.push(` ${SKILLS_INSTALL_COMMAND} # teach your coding agent this CLI`);
179
+ }
180
+ return lines.join("\n");
181
+ }
182
+ /**
183
+ * The two steps every brief opens with: get the skills, confirm the ground.
184
+ *
185
+ * `skill` is the one the handoff picked, which is not always the router: a
186
+ * CDK repo gets `cargo-cdk` and the demo gets `cargo-quickstart`. It has to be
187
+ * threaded here rather than assumed — see `HandoffSkill`.
188
+ */
189
+ function startSteps(facts, skill) {
190
+ // The router earns a sentence about routing; a skill that owns the task
191
+ // outright does not, and saying so invites the hop this is avoiding.
192
+ const loadLine = skill === ROUTER_SKILL
193
+ ? `Load the \`${ROUTER_SKILL}\` skill and let it route you to the right one.`
194
+ : `Load the \`${skill}\` skill — it owns this, so do not route elsewhere.`;
195
+ const install = facts.skillsInstalled === false
196
+ ? [
197
+ "1. Install the Cargo skills, which are the authority on every command:",
198
+ ` \`${SKILLS_INSTALL_COMMAND}\`. ${loadLine}`,
199
+ ]
200
+ : [`1. ${loadLine} It is already installed.`];
201
+ return [
202
+ ...install,
203
+ "2. Run `cargo-ai whoami` to confirm the workspace, and",
204
+ " `cargo-ai billing subscription get` so you know what there is to spend.",
205
+ "",
206
+ ];
207
+ }
208
+ /**
209
+ * The part of every brief that never varies. An agent that deploys or emails
210
+ * unasked spends the user's money or their reputation.
211
+ */
212
+ const RULES = [
213
+ "## Rules",
214
+ "",
215
+ "- Connector actions cost credits. Price a run with",
216
+ " `cargo-ai orchestration action list` before fanning it out, sample before",
217
+ " volume, and tell the user what it cost.",
218
+ "- Never deploy, never run a batch, and never send anything to a person",
219
+ " without the user asking for it in that turn.",
220
+ "- Anything touching a named person needs a lawful basis and a suppression",
221
+ " check. Sourcing people in order to message them without one is refused.",
222
+ ];
@@ -0,0 +1,44 @@
1
+ import type { Command } from "commander";
2
+ import type { Api } from "../../api.js";
3
+ import { type ProjectContext } from "./brief.js";
4
+ export type StartOptions = {
5
+ email?: string;
6
+ oauth?: boolean;
7
+ workspaceName?: string;
8
+ workspaceUuid?: string;
9
+ code?: string;
10
+ continue?: string;
11
+ directory?: string;
12
+ icp?: string;
13
+ baseUrl?: string;
14
+ };
15
+ /** What the flow needs from the program it was registered on. */
16
+ export type StartDeps = {
17
+ /** The script `cdk init` is re-run through — normally `process.argv[1]`. */
18
+ binPath: string;
19
+ /** Opens the command palette, part-way down the tree. */
20
+ openPalette: (startPath: readonly string[]) => Promise<void>;
21
+ };
22
+ /**
23
+ * Where the agent is about to be opened. Three cases, all decided locally —
24
+ * this runs before every handoff, including from the palette, so it must not
25
+ * touch the network.
26
+ *
27
+ * Exported for tests; `go` is the only production caller.
28
+ */
29
+ export declare function resolveProjectContext(cwd: string): ProjectContext;
30
+ export declare function registerStartCommand(program: Command, getApi: () => Api, deps: StartDeps): void;
31
+ export declare function runStart(getApi: () => Api, deps: StartDeps, opts: StartOptions): Promise<void>;
32
+ /**
33
+ * The command that finishes what this run started, for a machine with no
34
+ * terminal to type the emailed code into.
35
+ *
36
+ * It has to be `start` rather than `login`: `login --code` signs the user in
37
+ * and stops, so the destination this run was headed for is lost and re-running
38
+ * `start --email` issues a second code instead of spending the first. Every
39
+ * flag that decided where this was going is carried over.
40
+ *
41
+ * Exported for tests; `signIn` is the only production caller.
42
+ */
43
+ export declare function resumeCommand(email: string, opts: StartOptions): string;
44
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../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