@maiaos/cli 0.1.0-canary.76 → 0.1.0-canary.77

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.
@@ -15,18 +15,26 @@ export const setupFileSchema = Schema.Struct({
15
15
  });
16
16
  const stepSchema = Schema.Struct({
17
17
  command: Schema.optional(Schema.String),
18
- executor,
18
+ executor: Schema.optional(executor),
19
19
  state: Schema.Literals(["change", "done", "needs-person", "skipped"]),
20
- step: Schema.Literals(["account", "executable", "use"]),
20
+ step: Schema.Literals(["account", "executable", "grant", "project", "use"]),
21
21
  text: Schema.String,
22
22
  });
23
+ const projectSchema = Schema.Struct({
24
+ name: Schema.String,
25
+ path: Schema.String,
26
+ pathScope: Schema.Literal("node-local"),
27
+ projectId: Schema.optional(Schema.String),
28
+ });
23
29
  const planSchema = Schema.Struct({
24
30
  digest: Schema.String,
25
- file: setupFileSchema,
31
+ file: Schema.optional(setupFileSchema),
32
+ noProject: Schema.optional(Schema.String),
33
+ project: Schema.optional(projectSchema),
26
34
  resume: Schema.String,
27
35
  steps: Schema.Array(stepSchema),
28
36
  });
29
- const RESUME = "maia setup --non-interactive --config <path> --yes";
37
+ const resumeOf = (file) => `maia setup --non-interactive${file === undefined ? "" : " --config <path>"} --yes`;
30
38
  const invalidFile = (problem) => new CliArgumentError(`Option '--config' ${problem}.`);
31
39
  const decodeFile = Schema.decodeUnknownEffect(setupFileSchema, {
32
40
  onExcessProperty: "error",
@@ -55,17 +63,25 @@ const normalized = (file) => [
55
63
  file.executors.toSorted(),
56
64
  file.maxSessions ?? "",
57
65
  ];
58
- const digestOf = (file, steps, inputDigest) => `sha256:${createHash("sha256")
66
+ const digestOf = (plan, inputDigest) => `sha256:${createHash("sha256")
59
67
  .update(JSON.stringify([
60
- "maia.setup.plan/v1",
61
- normalized(file),
62
- steps.map((step) => [
63
- step.executor,
68
+ "maia.setup.plan/v2",
69
+ plan.file === undefined ? "" : normalized(plan.file),
70
+ plan.steps.map((step) => [
71
+ step.executor ?? "",
64
72
  step.step,
65
73
  step.state,
66
74
  step.text,
67
75
  step.command ?? "",
68
76
  ]),
77
+ plan.project === undefined
78
+ ? ""
79
+ : [
80
+ plan.project.name,
81
+ plan.project.path,
82
+ plan.project.projectId ?? "",
83
+ ],
84
+ plan.noProject ?? "",
69
85
  inputDigest,
70
86
  ]))
71
87
  .digest("hex")}`;
@@ -90,7 +106,9 @@ const leftAlone = (file, item, describe) => {
90
106
  return {
91
107
  ...(command === undefined ? {} : { command }),
92
108
  executor: item.executor,
93
- state: file.executors.includes(item.executor) ? "needs-person" : "skipped",
109
+ state: file?.executors.includes(item.executor) === true
110
+ ? "needs-person"
111
+ : "skipped",
94
112
  step: "use",
95
113
  text: describe(item),
96
114
  };
@@ -115,28 +133,76 @@ const stepsOf = (file, item, describe) => {
115
133
  },
116
134
  ];
117
135
  };
118
- export const planSetup = (file, preview, describe) => {
119
- const steps = preview.items.flatMap((item) => stepsOf(file, item, describe));
136
+ const grantSteps = (project, preview) => preview.items.flatMap(({ connection, executor: name }) => connection === undefined
137
+ ? []
138
+ : [
139
+ {
140
+ executor: name,
141
+ state: connection.action === "existing" &&
142
+ project.projectId !== undefined &&
143
+ project.granted.includes(connection.connectionId)
144
+ ? "done"
145
+ : "change",
146
+ step: "grant",
147
+ text: `grant account ${connection.name} to Project ${project.name}`,
148
+ },
149
+ ]);
150
+ const projectSteps = (project, preview) => [
151
+ project.projectId === undefined
152
+ ? {
153
+ state: "change",
154
+ step: "project",
155
+ text: `register ${project.path} as Project ${project.name}`,
156
+ }
157
+ : {
158
+ state: "done",
159
+ step: "project",
160
+ text: `use Project ${project.name} (${project.projectId})`,
161
+ },
162
+ ...grantSteps(project, preview),
163
+ ];
164
+ const projectOf = (project) => "skipped" in project
165
+ ? { noProject: project.skipped }
166
+ : {
167
+ project: {
168
+ name: project.name,
169
+ path: project.path,
170
+ pathScope: "node-local",
171
+ ...(project.projectId === undefined
172
+ ? {}
173
+ : { projectId: project.projectId }),
174
+ },
175
+ };
176
+ export const planSetup = ({ file, project, }, preview, describe) => {
177
+ const plan = {
178
+ ...(file === undefined ? {} : { file }),
179
+ ...projectOf(project),
180
+ steps: [
181
+ ...preview.items.flatMap((item) => stepsOf(file, item, describe)),
182
+ ...("skipped" in project ? [] : projectSteps(project, preview)),
183
+ ],
184
+ };
120
185
  return {
121
- digest: digestOf(file, steps, preview.inputDigest),
122
- file,
123
- resume: RESUME,
124
- steps,
186
+ ...plan,
187
+ digest: digestOf(plan, preview.inputDigest),
188
+ resume: resumeOf(file),
125
189
  };
126
190
  };
127
- const stalePlan = () => new CliArgumentError("The piped plan does not match its digest or the file; preview again with '--config <path> --dry-run'.");
128
- export const pipedPlan = (preview, file) => Effect.gen(function* () {
191
+ const stalePlan = () => new CliArgumentError("The piped plan does not match its digest or the file; preview again with '--dry-run'.");
192
+ const matches = (plan, preview, { file, noProject }) => plan.digest === digestOf(plan, Reflect.get(preview, "inputDigest")) &&
193
+ (plan.file === undefined ||
194
+ plan.file.maxSessions === Reflect.get(preview, "maxConcurrentSessions")) &&
195
+ !(noProject && plan.project !== undefined) &&
196
+ (file === undefined ||
197
+ (plan.file !== undefined &&
198
+ JSON.stringify(normalized(file)) ===
199
+ JSON.stringify(normalized(plan.file))));
200
+ export const pipedPlan = (preview, choices) => Effect.gen(function* () {
129
201
  const carried = Reflect.get(preview, "plan");
130
- if (carried === undefined && file === undefined)
202
+ if (carried === undefined && choices.file === undefined)
131
203
  return;
132
204
  const plan = yield* Effect.mapError(decodePlan(carried), stalePlan);
133
- const matches = plan.digest ===
134
- digestOf(plan.file, plan.steps, Reflect.get(preview, "inputDigest")) &&
135
- plan.file.maxSessions === Reflect.get(preview, "maxConcurrentSessions") &&
136
- (file === undefined ||
137
- JSON.stringify(normalized(file)) ===
138
- JSON.stringify(normalized(plan.file)));
139
- return matches ? plan : yield* stalePlan();
205
+ return matches(plan, preview, choices) ? plan : yield* stalePlan();
140
206
  });
141
207
  const STATES = {
142
208
  change: "to do",
@@ -144,8 +210,8 @@ const STATES = {
144
210
  ["needs-person"]: "needs a person",
145
211
  skipped: "skipped",
146
212
  };
147
- const stepText = ({ command, executor: name, state, text }) => ` ${name}: ${STATES[state]}, ${text}${command === undefined ? "" : `; run '${command}'`}\n`;
148
- export const planText = (plan) => `Plan ${plan.digest}:\n${plan.steps.map(stepText).join("")}`;
213
+ const stepText = ({ command, executor: name, state, text }) => ` ${name ?? "project"}: ${STATES[state]}, ${text}${command === undefined ? "" : `; run '${command}'`}\n`;
214
+ export const planText = (plan) => `Plan ${plan.digest}:\n${plan.steps.map(stepText).join("")}${plan.noProject === undefined ? "" : ` project: none, ${plan.noProject}\n`}`;
149
215
  export const personError = (plan) => {
150
216
  const waiting = plan.steps.filter((step) => step.state === "needs-person");
151
217
  return waiting.length === 0
@@ -153,7 +219,7 @@ export const personError = (plan) => {
153
219
  : {
154
220
  code: "resource_not_found",
155
221
  message: `Setup needs a person for ${waiting
156
- .map(({ command, executor: name, text }) => `${name} (${text}${command === undefined ? "" : `; run '${command}'`})`)
222
+ .map(({ command, executor: name, text }) => `${name ?? "project"} (${text}${command === undefined ? "" : `; run '${command}'`})`)
157
223
  .join(" and ")}; then run '${plan.resume}'.`,
158
224
  retryable: false,
159
225
  };
@@ -0,0 +1,138 @@
1
+ import { createHash } from "node:crypto";
2
+ import { basename, dirname, join } from "node:path";
3
+ import * as NodeFileSystem from "@effect/platform-node-shared/NodeFileSystem";
4
+ import { connectionGrantSetConfirmParametersSchema, } from "@maiaos/sdk";
5
+ import * as Data from "effect/Data";
6
+ import * as Effect from "effect/Effect";
7
+ import * as FileSystem from "effect/FileSystem";
8
+ import * as Option from "effect/Option";
9
+ import { CliArgumentError, LOCAL_NODE } from "../command-line/input/index.js";
10
+ import { confirmParameters } from "../command-line/two-phase/index.js";
11
+ export class SetupNodeError extends Data.TaggedError("SetupNodeError") {
12
+ }
13
+ export const required = (effect, hint) => effect === undefined
14
+ ? Effect.fail(new CliArgumentError("Connections are unavailable."))
15
+ : Effect.flatMap(effect, (result) => result.ok
16
+ ? Effect.succeed(result.value)
17
+ : Effect.fail(new SetupNodeError({
18
+ error: result.error,
19
+ ...(hint === undefined ? {} : { hint }),
20
+ })));
21
+ export const NO_PROJECT = {
22
+ noAccount: "setup uses no installed CLI, so no account would reach it",
23
+ optedOut: "'--no-project' asked for none",
24
+ outside: "the working directory is not inside a Git repository",
25
+ remote: "'--node' names a Node on another machine, which cannot see this working directory",
26
+ };
27
+ const rootFrom = (fs, folder) => Effect.flatMap(fs.exists(join(folder, ".git")), (found) => {
28
+ if (found)
29
+ return Effect.succeed(Option.some(folder));
30
+ const parent = dirname(folder);
31
+ return parent === folder
32
+ ? Effect.succeed(Option.none())
33
+ : rootFrom(fs, parent);
34
+ });
35
+ const repositoryRoot = (cwd) => Effect.gen(function* () {
36
+ const fs = yield* FileSystem.FileSystem;
37
+ const folder = yield* fs.realPath(cwd ?? process.cwd());
38
+ return yield* rootFrom(fs, folder);
39
+ }).pipe(Effect.catch(() => Effect.succeed(Option.none())), Effect.provide(NodeFileSystem.layer));
40
+ const READ_HINT = "Run it with '--no-project' to set up the accounts alone.";
41
+ const registeredAt = (context, path) => Effect.gen(function* () {
42
+ const { call } = context.dependencies;
43
+ if (call === undefined)
44
+ return yield* new CliArgumentError("Projects are unavailable.");
45
+ const answer = yield* call("reference.resolve", { kind: "project", path });
46
+ if (!answer.ok)
47
+ return answer.error.code === "resource_not_found"
48
+ ? Option.none()
49
+ : yield* new SetupNodeError({ error: answer.error, hint: READ_HINT });
50
+ const found = answer.value;
51
+ return found.outcome === "resolved" && found.match === "path"
52
+ ? Option.some(found)
53
+ : Option.none();
54
+ });
55
+ const grantedTo = (context, projectId) => Effect.map(required(context.dependencies.listConnectionGrants?.({
56
+ limit: 100,
57
+ scope: { id: projectId, kind: "project" },
58
+ state: "active",
59
+ }), READ_HINT), (grants) => grants.items.map((grant) => grant.connectionId));
60
+ export const readProject = (context, { noProject, usable, }) => Effect.gen(function* () {
61
+ if (noProject)
62
+ return { skipped: NO_PROJECT.optedOut };
63
+ if (context.node !== undefined && context.node !== LOCAL_NODE)
64
+ return { skipped: NO_PROJECT.remote };
65
+ if (!usable)
66
+ return { skipped: NO_PROJECT.noAccount };
67
+ const root = yield* repositoryRoot(context.io.cwd);
68
+ if (Option.isNone(root))
69
+ return { skipped: NO_PROJECT.outside };
70
+ const path = root.value;
71
+ const known = yield* registeredAt(context, path);
72
+ if (Option.isNone(known))
73
+ return { granted: [], name: basename(path), path };
74
+ const found = known.value;
75
+ return {
76
+ granted: yield* grantedTo(context, found.id),
77
+ name: found.label ?? basename(path),
78
+ path,
79
+ projectId: found.id,
80
+ };
81
+ });
82
+ const subCommand = (commandId, executor, step) => `setup_${createHash("sha256")
83
+ .update(`${commandId}\u0000${executor}\u0000${step}`)
84
+ .digest("hex")
85
+ .slice(0, 40)}`;
86
+ const stale = () => new CliArgumentError("The plan no longer matches the Node; preview again with '--dry-run'.");
87
+ export const recheckProject = (context, plan) => plan?.project === undefined
88
+ ? Effect.void
89
+ : Effect.flatMap(registeredAt(context, plan.project.path), (found) => Option.getOrUndefined(found)?.id === plan.project?.projectId
90
+ ? Effect.void
91
+ : Effect.fail(stale()));
92
+ const register = ({ confirmed, context, hint }, project) => required(context.dependencies.registerProject({
93
+ commandId: subCommand(confirmed.commandId, "", "project"),
94
+ name: project.name,
95
+ path: project.path,
96
+ }), `${hint} When the repository is a Project under another folder already, a linked worktree for example, add '--no-project'.`);
97
+ const grantTo = (run, projectId, executor) => Effect.gen(function* () {
98
+ const { confirmed, context, hint } = run;
99
+ const used = confirmed.items.find((item) => item.executor === executor);
100
+ if (used === undefined)
101
+ return yield* stale();
102
+ const preview = yield* required(context.dependencies.previewConnectionGrant?.({
103
+ commandId: subCommand(confirmed.commandId, executor, "grant"),
104
+ connectionId: used.connection.connectionId,
105
+ granted: true,
106
+ scope: { id: projectId, kind: "project" },
107
+ }), hint);
108
+ const parameters = yield* confirmParameters(connectionGrantSetConfirmParametersSchema, preview, ["current"]);
109
+ const { delivery, grant, receipt } = yield* required(context.dependencies.confirmConnectionGrant?.(parameters), hint);
110
+ const { connectionId, grantId } = grant;
111
+ return { connectionId, delivery, executor, grantId, receipt };
112
+ });
113
+ export const applyProject = (run, plan) => Effect.gen(function* () {
114
+ const { project, steps } = plan;
115
+ if (project === undefined)
116
+ return;
117
+ const changes = steps.filter((step) => step.state === "change");
118
+ const registered = changes.some((step) => step.step === "project")
119
+ ? yield* register(run, project)
120
+ : undefined;
121
+ const projectId = registered?.project.id ?? project.projectId;
122
+ if (projectId === undefined)
123
+ return yield* stale();
124
+ const grants = yield* Effect.forEach(changes.filter((step) => step.step === "grant"), (step) => grantTo(run, projectId, step.executor ?? ""));
125
+ if (registered === undefined)
126
+ return { grants, projectId };
127
+ const { delivery, receipt } = registered;
128
+ return { grants, projectId, registered: { delivery, receipt } };
129
+ });
130
+ export const projectAppliedText = (plan, applied) => {
131
+ const name = plan.project?.name ?? "";
132
+ return `${applied.registered === undefined
133
+ ? ""
134
+ : `project: Project ${name} (${applied.projectId}) registered, receipt ${applied.registered.receipt.receiptId}\n`}${applied.grants
135
+ .map(({ connectionId, executor, receipt }) => `${executor}: account ${connectionId} granted to Project ${name} (${applied.projectId}), receipt ${receipt.receiptId}\n`)
136
+ .join("")}`;
137
+ };
138
+ //# sourceMappingURL=setup-project.js.map
@@ -1,19 +1,9 @@
1
1
  import { connectionSystemConfirmParametersSchema, connectionUpkeepConfirmParametersSchema, EXECUTOR_IDS, } from "@maiaos/sdk";
2
- import * as Data from "effect/Data";
3
2
  import * as Effect from "effect/Effect";
4
3
  import { askToConfirm, CliArgumentError, confirmParameters, EXIT_CANCELLED, exitCodeOf, jsonLine, parseOptions, promptOrRefuse, readPipedPreview, reportError, requestedTwoPhaseMode, requirePositionals, TWO_PHASE_FLAGS, writeSuccess, } from "../command-line/index.js";
5
- import { commandIdentifier, } from "../local-node/index.js";
4
+ import { commandIdentifier } from "../local-node/index.js";
6
5
  import { personError, pipedPlan, planSetup, planText, readSetupFile, } from "./setup-file.js";
7
- class SetupNodeError extends Data.TaggedError("SetupNodeError") {
8
- }
9
- const required = (effect, hint) => effect === undefined
10
- ? Effect.fail(new CliArgumentError("Connections are unavailable."))
11
- : Effect.flatMap(effect, (result) => result.ok
12
- ? Effect.succeed(result.value)
13
- : Effect.fail(new SetupNodeError({
14
- error: result.error,
15
- ...(hint === undefined ? {} : { hint }),
16
- })));
6
+ import { applyProject, projectAppliedText, readProject, recheckProject, required, SetupNodeError, } from "./setup-project.js";
17
7
  const write = (context, output, text) => {
18
8
  context.io.stdout(context.json ? jsonLine({ ok: true, result: output }) : text);
19
9
  };
@@ -131,11 +121,8 @@ const itemText = (item) => {
131
121
  const through = endpoint === undefined ? "" : `, through ${endpoint.host}`;
132
122
  return ` ${executor} ${executable?.version ?? ""}: ${account}; ${approval}${through}\n`;
133
123
  };
134
- const hasWork = (item) => item.connection?.action === "create" || item.executable?.action === "approve";
135
- const previewText = (preview) => `Maia uses the installed CLIs as they are, with your own login and config:\n${preview.items.map(itemText).join("")}${(preview.notes ?? []).map((note) => ` note: ${note}\n`).join("")}${preview.plan === undefined ? "" : planText(preview.plan)}`;
136
- const withFilePlan = (preview, file) => file === undefined
137
- ? preview
138
- : { ...preview, plan: planSetup(file, preview, skipText) };
124
+ const hasWork = (preview) => preview.plan.steps.some((step) => step.state === "change");
125
+ const previewText = (preview) => `Maia uses the installed CLIs as they are, with your own login and config:\n${preview.items.map(itemText).join("")}${(preview.notes ?? []).map((note) => ` note: ${note}\n`).join("")}${planText(preview.plan)}`;
139
126
  const finish = (context, shown, plan) => {
140
127
  const error = plan === undefined ? undefined : personError(plan);
141
128
  if (error === undefined) {
@@ -158,11 +145,12 @@ const withCapacityNotes = (plan, requested) => {
158
145
  ]);
159
146
  return notes.length === 0 ? plan : { ...plan, notes };
160
147
  };
161
- const confirmedText = (result) => result.items
148
+ const confirmedText = ({ project, result }, plan) => `${result.items
162
149
  .map((item) => `${item.executor}: account ${item.connection.name} (${item.connection.connectionId})${item.connectionReceipt === undefined ? "" : ", created"}${item.approvalReceipt === undefined ? "" : ", executable approved"}\n`)
163
- .join("") || "Nothing changed.\n";
150
+ .join("")}${project === undefined || plan === undefined ? "" : projectAppliedText(plan, project)}` ||
151
+ "Nothing changed.\n";
164
152
  const readSetup = (tokens) => {
165
- const parsed = parseOptions(tokens, new Set(["--command-id", "--config", "--max-sessions"]), new Set(["--non-interactive", ...TWO_PHASE_FLAGS]));
153
+ const parsed = parseOptions(tokens, new Set(["--command-id", "--config", "--max-sessions"]), new Set(["--no-project", "--non-interactive", ...TWO_PHASE_FLAGS]));
166
154
  requirePositionals(parsed.positionals, 0);
167
155
  const sessions = parsed.options.get("--max-sessions");
168
156
  if (sessions !== undefined &&
@@ -175,27 +163,45 @@ const readSetup = (tokens) => {
175
163
  commandId: parsed.options.get("--command-id"),
176
164
  config,
177
165
  maxConcurrentSessions: sessions === undefined ? undefined : Number(sessions),
166
+ noProject: parsed.flags.has("--no-project"),
178
167
  requested: requestedTwoPhaseMode(parsed.flags),
179
168
  unattended: parsed.flags.has("--non-interactive"),
180
169
  };
181
170
  };
182
171
  const confirm = (context, preview, plan) => Effect.gen(function* () {
183
172
  const parameters = yield* confirmParameters(connectionSystemConfirmParametersSchema, preview, ["items", "notes", "plan"]);
184
- return yield* required(context.dependencies.confirmSystemConnections?.(parameters), plan === undefined
173
+ const hint = plan === undefined
185
174
  ? undefined
186
- : `Steps already done stay done; run '${plan.resume}' for the rest.`);
175
+ : `Steps already done stay done; run '${plan.resume}' for the rest.`;
176
+ yield* recheckProject(context, plan);
177
+ const result = yield* required(context.dependencies.confirmSystemConnections?.(parameters), hint);
178
+ const project = plan === undefined || hint === undefined
179
+ ? undefined
180
+ : yield* applyProject({ confirmed: result, context, hint }, plan);
181
+ return { ...(project === undefined ? {} : { project }), result };
187
182
  });
188
183
  const preview = (context, input, file) => {
189
184
  const sessions = file?.maxSessions ?? input.maxConcurrentSessions;
190
- return Effect.flatMap(commandIdentifier(input.commandId), (commandId) => required(context.dependencies.previewSystemConnections?.({
191
- commandId,
192
- ...(sessions === undefined ? {} : { maxConcurrentSessions: sessions }),
193
- })).pipe(Effect.map((plan) => withFilePlan(withCapacityNotes(plan, sessions), file))));
185
+ return Effect.gen(function* () {
186
+ const commandId = yield* commandIdentifier(input.commandId);
187
+ const plan = yield* required(context.dependencies.previewSystemConnections?.({
188
+ commandId,
189
+ ...(sessions === undefined ? {} : { maxConcurrentSessions: sessions }),
190
+ }));
191
+ const project = yield* readProject(context, {
192
+ noProject: input.noProject,
193
+ usable: plan.items.some((item) => item.connection !== undefined),
194
+ });
195
+ return {
196
+ ...withCapacityNotes(plan, sessions),
197
+ plan: planSetup({ ...(file === undefined ? {} : { file }), project }, plan, skipText),
198
+ };
199
+ });
194
200
  };
195
201
  const settled = (context, plan) => {
196
- if (plan.plan !== undefined ||
202
+ if (plan.plan.file !== undefined ||
197
203
  plan.items.some((item) => item.reason === undefined)) {
198
- const waits = plan.plan !== undefined && personError(plan.plan) !== undefined;
204
+ const waits = personError(plan.plan) !== undefined;
199
205
  return finish(context, {
200
206
  output: { command: "setup", result: { preview: markPreview(plan) } },
201
207
  text: `${previewText(plan)}${waits ? "" : "Already set up.\n"}`,
@@ -212,26 +218,29 @@ const settled = (context, plan) => {
212
218
  retryable: false,
213
219
  }, context);
214
220
  };
215
- const writeConfirmed = (context, result, { carried, preview: plan } = {}) => finish(context, {
216
- output: {
217
- command: "setup",
218
- result: {
219
- ...(plan === undefined ? {} : { preview: markPreview(plan) }),
220
- result,
221
+ const writeConfirmed = (context, applied, { carried, preview: plan } = {}) => {
222
+ const steps = plan?.plan ?? carried;
223
+ return finish(context, {
224
+ output: {
225
+ command: "setup",
226
+ result: {
227
+ ...(plan === undefined ? {} : { preview: markPreview(plan) }),
228
+ ...applied,
229
+ },
221
230
  },
222
- },
223
- text: confirmedText(result),
224
- }, plan?.plan ?? carried);
231
+ text: confirmedText(applied, steps),
232
+ }, steps);
233
+ };
225
234
  const writeDryRun = (context, plan) => {
226
- const config = plan.plan === undefined ? "" : " --config <path>";
235
+ const config = plan.plan.file === undefined ? "" : " --config <path>";
227
236
  write(context, { command: "connection.system.preview", result: markPreview(plan) }, `${previewText(plan)}Confirm with: maia --json setup${config} --dry-run | maia setup${config} --confirm-stdin\n`);
228
237
  return 0;
229
238
  };
230
- const confirmPiped = (context, file) => Effect.gen(function* () {
239
+ const confirmPiped = (context, choices) => Effect.gen(function* () {
231
240
  const piped = yield* readPipedPreview(context);
232
- const carried = yield* pipedPlan(piped, file);
233
- const result = yield* confirm(context, piped, carried);
234
- return writeConfirmed(context, result, { carried });
241
+ const carried = yield* pipedPlan(piped, choices);
242
+ const applied = yield* confirm(context, piped, carried);
243
+ return writeConfirmed(context, applied, { carried });
235
244
  });
236
245
  const confirmFresh = (context, plan, mode) => Effect.gen(function* () {
237
246
  if (!context.json)
@@ -240,19 +249,22 @@ const confirmFresh = (context, plan, mode) => Effect.gen(function* () {
240
249
  context.io.stderr("Cancelled; nothing changed.\n");
241
250
  return EXIT_CANCELLED;
242
251
  }
243
- const result = yield* confirm(context, plan, plan.plan);
244
- return writeConfirmed(context, result, { preview: plan });
252
+ const applied = yield* confirm(context, plan, plan.plan);
253
+ return writeConfirmed(context, applied, { preview: plan });
245
254
  });
246
255
  export const runSetup = (tokens, context) => Effect.gen(function* () {
247
256
  const input = readSetup(tokens);
248
- const { config, requested, unattended } = input;
257
+ const { config, noProject, requested, unattended } = input;
249
258
  const file = config === undefined ? undefined : yield* readSetupFile(config);
250
259
  if (requested === "confirm-stdin")
251
- return yield* confirmPiped(context, file);
260
+ return yield* confirmPiped(context, {
261
+ ...(file === undefined ? {} : { file }),
262
+ noProject,
263
+ });
252
264
  const plan = yield* preview(context, input, file);
253
265
  if (requested === "dry-run")
254
266
  return writeDryRun(context, plan);
255
- if (!plan.items.some(hasWork))
267
+ if (!hasWork(plan))
256
268
  return settled(context, plan);
257
269
  const asks = unattended
258
270
  ? { ...context, io: { ...context.io, interactive: false } }
@@ -29,10 +29,10 @@ export const CONNECTION_TREE = {
29
29
  ],
30
30
  leaves: [
31
31
  [
32
- "setup [--config <path> | --max-sessions <1..64>] [--non-interactive] [--command-id <id>] [--dry-run | --confirm-stdin | --yes]",
32
+ "setup [--config <path> | --max-sessions <1..64>] [--no-project] [--non-interactive] [--command-id <id>] [--dry-run | --confirm-stdin | --yes]",
33
33
  1,
34
34
  ["connection.system.preview", "connection.system.confirm"],
35
- "Use installed vendor CLIs as system-default accounts.",
35
+ "Use installed vendor CLIs as accounts; grant them this repository.",
36
36
  {
37
37
  example: "maia setup --max-sessions 4",
38
38
  kind: "two-phase",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maiaos/cli",
3
- "version": "0.1.0-canary.76",
3
+ "version": "0.1.0-canary.77",
4
4
  "description": "The maia CLI and MCP server: start, drive, observe and stop swarms of Claude Code and Codex agents from a terminal, a script or another agent.",
5
5
  "keywords": [
6
6
  "maia",
@@ -65,9 +65,9 @@
65
65
  "dependencies": {
66
66
  "@earendil-works/pi-tui": "1.0.0",
67
67
  "@effect/platform-node-shared": "4.0.0",
68
- "@maiaos/agent": "0.1.0-canary.76",
69
- "@maiaos/client-core": "0.1.0-canary.76",
70
- "@maiaos/sdk": "0.1.0-canary.76",
68
+ "@maiaos/agent": "0.1.0-canary.77",
69
+ "@maiaos/client-core": "0.1.0-canary.77",
70
+ "@maiaos/sdk": "0.1.0-canary.77",
71
71
  "effect": "4.0.0"
72
72
  },
73
73
  "scripts": {