@maiaos/cli 0.1.0-canary.76 → 0.1.0-canary.78
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 +2 -3
- package/dist/bin/maia.cdx.json +24 -24
- package/dist/bin/maia.mjs +1 -1
- package/dist/connection/client.d.ts +36 -0
- package/dist/connection/output/format.js +4 -1
- package/dist/connection/resolve.d.ts +4 -0
- package/dist/connection/setup-file.js +95 -29
- package/dist/connection/setup-project.js +138 -0
- package/dist/connection/system.js +67 -48
- package/dist/connection/tree/tree.js +2 -2
- package/package.json +4 -4
|
@@ -28,6 +28,10 @@ export declare const makeConnectionClient: (node: CliNodeOperations) => {
|
|
|
28
28
|
};
|
|
29
29
|
readonly connectionId: string;
|
|
30
30
|
readonly createdAt: string;
|
|
31
|
+
readonly endpoint?: {
|
|
32
|
+
readonly credential: "cli-config";
|
|
33
|
+
readonly host: string;
|
|
34
|
+
} | undefined;
|
|
31
35
|
readonly executor: "claude-code" | "codex-cli" | "gateway";
|
|
32
36
|
readonly gateway?: {
|
|
33
37
|
readonly baseUrl: string;
|
|
@@ -77,6 +81,10 @@ export declare const makeConnectionClient: (node: CliNodeOperations) => {
|
|
|
77
81
|
};
|
|
78
82
|
readonly connectionId: string;
|
|
79
83
|
readonly createdAt: string;
|
|
84
|
+
readonly endpoint?: {
|
|
85
|
+
readonly credential: "cli-config";
|
|
86
|
+
readonly host: string;
|
|
87
|
+
} | undefined;
|
|
80
88
|
readonly executor: "claude-code" | "codex-cli" | "gateway";
|
|
81
89
|
readonly gateway?: {
|
|
82
90
|
readonly baseUrl: string;
|
|
@@ -125,6 +133,10 @@ export declare const makeConnectionClient: (node: CliNodeOperations) => {
|
|
|
125
133
|
};
|
|
126
134
|
readonly connectionId: string;
|
|
127
135
|
readonly createdAt: string;
|
|
136
|
+
readonly endpoint?: {
|
|
137
|
+
readonly credential: "cli-config";
|
|
138
|
+
readonly host: string;
|
|
139
|
+
} | undefined;
|
|
128
140
|
readonly executor: "claude-code" | "codex-cli" | "gateway";
|
|
129
141
|
readonly gateway?: {
|
|
130
142
|
readonly baseUrl: string;
|
|
@@ -174,6 +186,10 @@ export declare const makeConnectionClient: (node: CliNodeOperations) => {
|
|
|
174
186
|
};
|
|
175
187
|
readonly connectionId: string;
|
|
176
188
|
readonly createdAt: string;
|
|
189
|
+
readonly endpoint?: {
|
|
190
|
+
readonly credential: "cli-config";
|
|
191
|
+
readonly host: string;
|
|
192
|
+
} | undefined;
|
|
177
193
|
readonly executor: "claude-code" | "codex-cli" | "gateway";
|
|
178
194
|
readonly gateway?: {
|
|
179
195
|
readonly baseUrl: string;
|
|
@@ -241,6 +257,10 @@ export declare const makeConnectionClient: (node: CliNodeOperations) => {
|
|
|
241
257
|
};
|
|
242
258
|
readonly connectionId: string;
|
|
243
259
|
readonly createdAt: string;
|
|
260
|
+
readonly endpoint?: {
|
|
261
|
+
readonly credential: "cli-config";
|
|
262
|
+
readonly host: string;
|
|
263
|
+
} | undefined;
|
|
244
264
|
readonly executor: "claude-code" | "codex-cli" | "gateway";
|
|
245
265
|
readonly gateway?: {
|
|
246
266
|
readonly baseUrl: string;
|
|
@@ -309,6 +329,10 @@ export declare const makeConnectionClient: (node: CliNodeOperations) => {
|
|
|
309
329
|
};
|
|
310
330
|
readonly connectionId: string;
|
|
311
331
|
readonly createdAt: string;
|
|
332
|
+
readonly endpoint?: {
|
|
333
|
+
readonly credential: "cli-config";
|
|
334
|
+
readonly host: string;
|
|
335
|
+
} | undefined;
|
|
312
336
|
readonly executor: "claude-code" | "codex-cli" | "gateway";
|
|
313
337
|
readonly gateway?: {
|
|
314
338
|
readonly baseUrl: string;
|
|
@@ -377,6 +401,10 @@ export declare const makeConnectionClient: (node: CliNodeOperations) => {
|
|
|
377
401
|
};
|
|
378
402
|
readonly connectionId: string;
|
|
379
403
|
readonly createdAt: string;
|
|
404
|
+
readonly endpoint?: {
|
|
405
|
+
readonly credential: "cli-config";
|
|
406
|
+
readonly host: string;
|
|
407
|
+
} | undefined;
|
|
380
408
|
readonly executor: "claude-code" | "codex-cli" | "gateway";
|
|
381
409
|
readonly gateway?: {
|
|
382
410
|
readonly baseUrl: string;
|
|
@@ -445,6 +473,10 @@ export declare const makeConnectionClient: (node: CliNodeOperations) => {
|
|
|
445
473
|
};
|
|
446
474
|
readonly connectionId: string;
|
|
447
475
|
readonly createdAt: string;
|
|
476
|
+
readonly endpoint?: {
|
|
477
|
+
readonly credential: "cli-config";
|
|
478
|
+
readonly host: string;
|
|
479
|
+
} | undefined;
|
|
448
480
|
readonly executor: "claude-code" | "codex-cli" | "gateway";
|
|
449
481
|
readonly gateway?: {
|
|
450
482
|
readonly baseUrl: string;
|
|
@@ -541,6 +573,10 @@ export declare const makeConnectionClient: (node: CliNodeOperations) => {
|
|
|
541
573
|
};
|
|
542
574
|
readonly connectionId: string;
|
|
543
575
|
readonly createdAt: string;
|
|
576
|
+
readonly endpoint?: {
|
|
577
|
+
readonly credential: "cli-config";
|
|
578
|
+
readonly host: string;
|
|
579
|
+
} | undefined;
|
|
544
580
|
readonly executor: "claude-code" | "codex-cli" | "gateway";
|
|
545
581
|
readonly gateway?: {
|
|
546
582
|
readonly baseUrl: string;
|
|
@@ -46,7 +46,10 @@ export const describeConnection = (connection) => {
|
|
|
46
46
|
const gateway = connection.gateway === undefined
|
|
47
47
|
? ""
|
|
48
48
|
: ` gateway=${connection.gateway.baseUrl}${connection.gateway.keyEnv === undefined ? "" : ` key=env:${connection.gateway.keyEnv}`}`;
|
|
49
|
-
|
|
49
|
+
const endpoint = connection.endpoint === undefined
|
|
50
|
+
? ""
|
|
51
|
+
: ` endpoint=${connection.endpoint.host} key=${connection.endpoint.credential}`;
|
|
52
|
+
return `${connection.connectionId} ${connection.name} ${connection.executor} ${connection.state} sessions<=${String(connection.maxConcurrentSessions)} revision=${connection.revision} root=${connection.configRoot.kind}${endpoint}${gateway}${limited}${usage}`;
|
|
50
53
|
};
|
|
51
54
|
const describeLogin = (login) => login.authUrl === undefined
|
|
52
55
|
? `Open ${login.verificationUrl ?? ""} and enter ${login.userCode ?? ""} before ${login.expiresAt}.`
|
|
@@ -21,6 +21,10 @@ export declare const findConnectionByName: (context: CommandContext, name: strin
|
|
|
21
21
|
};
|
|
22
22
|
readonly connectionId: string;
|
|
23
23
|
readonly createdAt: string;
|
|
24
|
+
readonly endpoint?: {
|
|
25
|
+
readonly credential: "cli-config";
|
|
26
|
+
readonly host: string;
|
|
27
|
+
} | undefined;
|
|
24
28
|
readonly executor: "claude-code" | "codex-cli" | "gateway";
|
|
25
29
|
readonly gateway?: {
|
|
26
30
|
readonly baseUrl: string;
|
|
@@ -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
|
|
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 = (
|
|
66
|
+
const digestOf = (plan, inputDigest) => `sha256:${createHash("sha256")
|
|
59
67
|
.update(JSON.stringify([
|
|
60
|
-
"maia.setup.plan/
|
|
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
|
|
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
|
-
|
|
119
|
-
|
|
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
|
-
|
|
122
|
-
|
|
123
|
-
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 '--
|
|
128
|
-
|
|
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
|
-
|
|
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
|
|
4
|
+
import { commandIdentifier } from "../local-node/index.js";
|
|
6
5
|
import { personError, pipedPlan, planSetup, planText, readSetupFile, } from "./setup-file.js";
|
|
7
|
-
|
|
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
|
};
|
|
@@ -76,7 +66,14 @@ const detectedText = (item) => {
|
|
|
76
66
|
return [
|
|
77
67
|
`${item.executor} ${version ?? "(version unknown)"} ${path}${onNodePath ? "" : " (not on the Node's PATH)"}`,
|
|
78
68
|
` ${signIn(item)}; ${account}; executable ${item.executableApproved ? "approved" : "not approved"}`,
|
|
79
|
-
...(item.endpoint?.
|
|
69
|
+
...(item.endpoint?.credential === "helper" && item.connection === undefined
|
|
70
|
+
? [
|
|
71
|
+
" next: 'maia setup' uses it with the CLI's own config; Maia keeps no key",
|
|
72
|
+
]
|
|
73
|
+
: []),
|
|
74
|
+
...(item.endpoint?.hint === undefined
|
|
75
|
+
? []
|
|
76
|
+
: [` for worker Sessions: ${item.endpoint.hint}`]),
|
|
80
77
|
...upkeepText(item),
|
|
81
78
|
"",
|
|
82
79
|
].join("\n");
|
|
@@ -131,11 +128,8 @@ const itemText = (item) => {
|
|
|
131
128
|
const through = endpoint === undefined ? "" : `, through ${endpoint.host}`;
|
|
132
129
|
return ` ${executor} ${executable?.version ?? ""}: ${account}; ${approval}${through}\n`;
|
|
133
130
|
};
|
|
134
|
-
const hasWork = (
|
|
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("")}${
|
|
136
|
-
const withFilePlan = (preview, file) => file === undefined
|
|
137
|
-
? preview
|
|
138
|
-
: { ...preview, plan: planSetup(file, preview, skipText) };
|
|
131
|
+
const hasWork = (preview) => preview.plan.steps.some((step) => step.state === "change");
|
|
132
|
+
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
133
|
const finish = (context, shown, plan) => {
|
|
140
134
|
const error = plan === undefined ? undefined : personError(plan);
|
|
141
135
|
if (error === undefined) {
|
|
@@ -158,11 +152,12 @@ const withCapacityNotes = (plan, requested) => {
|
|
|
158
152
|
]);
|
|
159
153
|
return notes.length === 0 ? plan : { ...plan, notes };
|
|
160
154
|
};
|
|
161
|
-
const confirmedText = (result) => result.items
|
|
155
|
+
const confirmedText = ({ project, result }, plan) => `${result.items
|
|
162
156
|
.map((item) => `${item.executor}: account ${item.connection.name} (${item.connection.connectionId})${item.connectionReceipt === undefined ? "" : ", created"}${item.approvalReceipt === undefined ? "" : ", executable approved"}\n`)
|
|
163
|
-
.join("") || "
|
|
157
|
+
.join("")}${project === undefined || plan === undefined ? "" : projectAppliedText(plan, project)}` ||
|
|
158
|
+
"Nothing changed.\n";
|
|
164
159
|
const readSetup = (tokens) => {
|
|
165
|
-
const parsed = parseOptions(tokens, new Set(["--command-id", "--config", "--max-sessions"]), new Set(["--non-interactive", ...TWO_PHASE_FLAGS]));
|
|
160
|
+
const parsed = parseOptions(tokens, new Set(["--command-id", "--config", "--max-sessions"]), new Set(["--no-project", "--non-interactive", ...TWO_PHASE_FLAGS]));
|
|
166
161
|
requirePositionals(parsed.positionals, 0);
|
|
167
162
|
const sessions = parsed.options.get("--max-sessions");
|
|
168
163
|
if (sessions !== undefined &&
|
|
@@ -175,27 +170,45 @@ const readSetup = (tokens) => {
|
|
|
175
170
|
commandId: parsed.options.get("--command-id"),
|
|
176
171
|
config,
|
|
177
172
|
maxConcurrentSessions: sessions === undefined ? undefined : Number(sessions),
|
|
173
|
+
noProject: parsed.flags.has("--no-project"),
|
|
178
174
|
requested: requestedTwoPhaseMode(parsed.flags),
|
|
179
175
|
unattended: parsed.flags.has("--non-interactive"),
|
|
180
176
|
};
|
|
181
177
|
};
|
|
182
178
|
const confirm = (context, preview, plan) => Effect.gen(function* () {
|
|
183
179
|
const parameters = yield* confirmParameters(connectionSystemConfirmParametersSchema, preview, ["items", "notes", "plan"]);
|
|
184
|
-
|
|
180
|
+
const hint = plan === undefined
|
|
181
|
+
? undefined
|
|
182
|
+
: `Steps already done stay done; run '${plan.resume}' for the rest.`;
|
|
183
|
+
yield* recheckProject(context, plan);
|
|
184
|
+
const result = yield* required(context.dependencies.confirmSystemConnections?.(parameters), hint);
|
|
185
|
+
const project = plan === undefined || hint === undefined
|
|
185
186
|
? undefined
|
|
186
|
-
:
|
|
187
|
+
: yield* applyProject({ confirmed: result, context, hint }, plan);
|
|
188
|
+
return { ...(project === undefined ? {} : { project }), result };
|
|
187
189
|
});
|
|
188
190
|
const preview = (context, input, file) => {
|
|
189
191
|
const sessions = file?.maxSessions ?? input.maxConcurrentSessions;
|
|
190
|
-
return Effect.
|
|
191
|
-
commandId
|
|
192
|
-
|
|
193
|
-
|
|
192
|
+
return Effect.gen(function* () {
|
|
193
|
+
const commandId = yield* commandIdentifier(input.commandId);
|
|
194
|
+
const plan = yield* required(context.dependencies.previewSystemConnections?.({
|
|
195
|
+
commandId,
|
|
196
|
+
...(sessions === undefined ? {} : { maxConcurrentSessions: sessions }),
|
|
197
|
+
}));
|
|
198
|
+
const project = yield* readProject(context, {
|
|
199
|
+
noProject: input.noProject,
|
|
200
|
+
usable: plan.items.some((item) => item.connection !== undefined),
|
|
201
|
+
});
|
|
202
|
+
return {
|
|
203
|
+
...withCapacityNotes(plan, sessions),
|
|
204
|
+
plan: planSetup({ ...(file === undefined ? {} : { file }), project }, plan, skipText),
|
|
205
|
+
};
|
|
206
|
+
});
|
|
194
207
|
};
|
|
195
208
|
const settled = (context, plan) => {
|
|
196
|
-
if (plan.plan !== undefined ||
|
|
209
|
+
if (plan.plan.file !== undefined ||
|
|
197
210
|
plan.items.some((item) => item.reason === undefined)) {
|
|
198
|
-
const waits =
|
|
211
|
+
const waits = personError(plan.plan) !== undefined;
|
|
199
212
|
return finish(context, {
|
|
200
213
|
output: { command: "setup", result: { preview: markPreview(plan) } },
|
|
201
214
|
text: `${previewText(plan)}${waits ? "" : "Already set up.\n"}`,
|
|
@@ -212,26 +225,29 @@ const settled = (context, plan) => {
|
|
|
212
225
|
retryable: false,
|
|
213
226
|
}, context);
|
|
214
227
|
};
|
|
215
|
-
const writeConfirmed = (context,
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
result
|
|
228
|
+
const writeConfirmed = (context, applied, { carried, preview: plan } = {}) => {
|
|
229
|
+
const steps = plan?.plan ?? carried;
|
|
230
|
+
return finish(context, {
|
|
231
|
+
output: {
|
|
232
|
+
command: "setup",
|
|
233
|
+
result: {
|
|
234
|
+
...(plan === undefined ? {} : { preview: markPreview(plan) }),
|
|
235
|
+
...applied,
|
|
236
|
+
},
|
|
221
237
|
},
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
}
|
|
238
|
+
text: confirmedText(applied, steps),
|
|
239
|
+
}, steps);
|
|
240
|
+
};
|
|
225
241
|
const writeDryRun = (context, plan) => {
|
|
226
|
-
const config = plan.plan === undefined ? "" : " --config <path>";
|
|
242
|
+
const config = plan.plan.file === undefined ? "" : " --config <path>";
|
|
227
243
|
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
244
|
return 0;
|
|
229
245
|
};
|
|
230
|
-
const confirmPiped = (context,
|
|
246
|
+
const confirmPiped = (context, choices) => Effect.gen(function* () {
|
|
231
247
|
const piped = yield* readPipedPreview(context);
|
|
232
|
-
const carried = yield* pipedPlan(piped,
|
|
233
|
-
const
|
|
234
|
-
return writeConfirmed(context,
|
|
248
|
+
const carried = yield* pipedPlan(piped, choices);
|
|
249
|
+
const applied = yield* confirm(context, piped, carried);
|
|
250
|
+
return writeConfirmed(context, applied, { carried });
|
|
235
251
|
});
|
|
236
252
|
const confirmFresh = (context, plan, mode) => Effect.gen(function* () {
|
|
237
253
|
if (!context.json)
|
|
@@ -240,19 +256,22 @@ const confirmFresh = (context, plan, mode) => Effect.gen(function* () {
|
|
|
240
256
|
context.io.stderr("Cancelled; nothing changed.\n");
|
|
241
257
|
return EXIT_CANCELLED;
|
|
242
258
|
}
|
|
243
|
-
const
|
|
244
|
-
return writeConfirmed(context,
|
|
259
|
+
const applied = yield* confirm(context, plan, plan.plan);
|
|
260
|
+
return writeConfirmed(context, applied, { preview: plan });
|
|
245
261
|
});
|
|
246
262
|
export const runSetup = (tokens, context) => Effect.gen(function* () {
|
|
247
263
|
const input = readSetup(tokens);
|
|
248
|
-
const { config, requested, unattended } = input;
|
|
264
|
+
const { config, noProject, requested, unattended } = input;
|
|
249
265
|
const file = config === undefined ? undefined : yield* readSetupFile(config);
|
|
250
266
|
if (requested === "confirm-stdin")
|
|
251
|
-
return yield* confirmPiped(context,
|
|
267
|
+
return yield* confirmPiped(context, {
|
|
268
|
+
...(file === undefined ? {} : { file }),
|
|
269
|
+
noProject,
|
|
270
|
+
});
|
|
252
271
|
const plan = yield* preview(context, input, file);
|
|
253
272
|
if (requested === "dry-run")
|
|
254
273
|
return writeDryRun(context, plan);
|
|
255
|
-
if (!plan
|
|
274
|
+
if (!hasWork(plan))
|
|
256
275
|
return settled(context, plan);
|
|
257
276
|
const asks = unattended
|
|
258
277
|
? { ...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
|
|
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",
|