@maiaos/cli 0.1.0-canary.56 → 0.1.0-canary.57
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/dist/bin/maia.cdx.json +19 -19
- package/dist/bin/maia.mjs +1 -1
- package/dist/cli/cli.js +10 -0
- package/dist/command-line/context.d.ts +2 -1
- package/dist/command-line/index.d.ts +2 -2
- package/dist/command-line/index.js +1 -1
- package/dist/command-line/input/index.d.ts +1 -1
- package/dist/command-line/two-phase/index.d.ts +2 -0
- package/dist/command-line/two-phase/index.js +2 -0
- package/dist/command-line/{two-phase.d.ts → two-phase/two-phase.d.ts} +12 -12
- package/dist/command-line/{two-phase.js → two-phase/two-phase.js} +2 -2
- package/dist/command-tree/tree.d.ts +1 -1
- package/dist/command-tree/tree.js +3 -0
- package/dist/session/agent-permission.d.ts +2 -2
- package/dist/session/client.d.ts +2 -2
- package/dist/webhooks/client.d.ts +156 -0
- package/dist/webhooks/client.js +8 -0
- package/dist/webhooks/commands.d.ts +17 -0
- package/dist/webhooks/commands.js +76 -0
- package/dist/webhooks/index.d.ts +3 -0
- package/dist/webhooks/index.js +3 -0
- package/dist/webhooks/input.js +125 -0
- package/dist/webhooks/output/format.js +75 -0
- package/dist/webhooks/output/index.js +2 -0
- package/dist/webhooks/tree/index.js +2 -0
- package/dist/webhooks/tree/tree.js +49 -0
- package/package.json +4 -4
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { webhookSpecSchema, } from "@maiaos/sdk";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import { CliArgumentError, parseOptionsWith, readExpectedRevision, readPageSize, requirePositionals, } from "../command-line/input/index.js";
|
|
4
|
+
import { TWO_PHASE_FLAGS } from "../command-line/two-phase/index.js";
|
|
5
|
+
import { commandIdentifier } from "../local-node/index.js";
|
|
6
|
+
const targetOptions = ["--command-id", "--expected-revision"];
|
|
7
|
+
export const WEBHOOK_OPTIONS = {
|
|
8
|
+
add: {
|
|
9
|
+
allowed: new Set([
|
|
10
|
+
"--command-id",
|
|
11
|
+
"--event",
|
|
12
|
+
"--label",
|
|
13
|
+
"--node-id",
|
|
14
|
+
"--project",
|
|
15
|
+
"--secret-env",
|
|
16
|
+
"--url",
|
|
17
|
+
]),
|
|
18
|
+
allowedFlags: new Set([...TWO_PHASE_FLAGS, "--allow-private"]),
|
|
19
|
+
repeatable: new Set(["--event", "--label"]),
|
|
20
|
+
},
|
|
21
|
+
deliveries: {
|
|
22
|
+
allowed: new Set(["--after", "--limit", "--webhook"]),
|
|
23
|
+
allowedFlags: new Set(["--failed"]),
|
|
24
|
+
repeatable: new Set(),
|
|
25
|
+
},
|
|
26
|
+
list: {
|
|
27
|
+
allowed: new Set(["--after", "--limit"]),
|
|
28
|
+
allowedFlags: new Set(),
|
|
29
|
+
repeatable: new Set(),
|
|
30
|
+
},
|
|
31
|
+
redeliver: {
|
|
32
|
+
allowed: new Set(targetOptions),
|
|
33
|
+
allowedFlags: new Set(TWO_PHASE_FLAGS),
|
|
34
|
+
repeatable: new Set(),
|
|
35
|
+
},
|
|
36
|
+
remove: {
|
|
37
|
+
allowed: new Set(targetOptions),
|
|
38
|
+
allowedFlags: new Set(TWO_PHASE_FLAGS),
|
|
39
|
+
repeatable: new Set(),
|
|
40
|
+
},
|
|
41
|
+
test: {
|
|
42
|
+
allowed: new Set(targetOptions),
|
|
43
|
+
allowedFlags: new Set(TWO_PHASE_FLAGS),
|
|
44
|
+
repeatable: new Set(),
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
const required = (options, name) => {
|
|
48
|
+
const value = options.get(name);
|
|
49
|
+
if (value === undefined)
|
|
50
|
+
throw new CliArgumentError(`Option '${name}' is required.`);
|
|
51
|
+
return value;
|
|
52
|
+
};
|
|
53
|
+
const INVALID_SPEC = "The webhook is invalid: check '--url' (http or https, no credentials), '--secret-env' (an upper-case variable name), '--event' (a hook event) and '--label' (key=value, no comma).";
|
|
54
|
+
const labelFilter = (label) => {
|
|
55
|
+
const [key, ...rest] = label.split("=");
|
|
56
|
+
if (key === undefined || key === "" || rest.length === 0)
|
|
57
|
+
throw new CliArgumentError("Option '--label' takes key=value.");
|
|
58
|
+
return { key: `label.${key}`, value: rest.join("=") };
|
|
59
|
+
};
|
|
60
|
+
const filtersOf = (options) => {
|
|
61
|
+
const project = options.get("--project");
|
|
62
|
+
const node = options.get("--node-id");
|
|
63
|
+
return [
|
|
64
|
+
...(project === undefined ? [] : [{ key: "project", value: project }]),
|
|
65
|
+
...(node === undefined ? [] : [{ key: "node", value: node }]),
|
|
66
|
+
...(options.get("--label")?.split(",").map(labelFilter) ?? []),
|
|
67
|
+
];
|
|
68
|
+
};
|
|
69
|
+
const readSpec = (parsed) => {
|
|
70
|
+
const { flags, options } = parsed;
|
|
71
|
+
const spec = webhookSpecSchema.safeParse({
|
|
72
|
+
allowPrivate: flags.has("--allow-private"),
|
|
73
|
+
events: required(options, "--event").split(","),
|
|
74
|
+
filters: filtersOf(options),
|
|
75
|
+
secretEnv: required(options, "--secret-env"),
|
|
76
|
+
url: required(options, "--url"),
|
|
77
|
+
});
|
|
78
|
+
if (!spec.success)
|
|
79
|
+
throw new CliArgumentError(INVALID_SPEC);
|
|
80
|
+
return spec.data;
|
|
81
|
+
};
|
|
82
|
+
export const readWebhooksList = (tokens) => {
|
|
83
|
+
const { options, positionals } = parseOptionsWith(tokens, WEBHOOK_OPTIONS.list);
|
|
84
|
+
requirePositionals(positionals, 0);
|
|
85
|
+
const afterCursor = options.get("--after");
|
|
86
|
+
return {
|
|
87
|
+
...(afterCursor === undefined ? {} : { afterCursor }),
|
|
88
|
+
limit: readPageSize(options.get("--limit")),
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
export const readWebhooksDeliveries = (tokens) => {
|
|
92
|
+
const { flags, options, positionals } = parseOptionsWith(tokens, WEBHOOK_OPTIONS.deliveries);
|
|
93
|
+
requirePositionals(positionals, 0);
|
|
94
|
+
const afterCursor = options.get("--after");
|
|
95
|
+
const webhookId = options.get("--webhook");
|
|
96
|
+
return {
|
|
97
|
+
...(afterCursor === undefined ? {} : { afterCursor }),
|
|
98
|
+
...(flags.has("--failed") ? { failedOnly: true } : {}),
|
|
99
|
+
limit: readPageSize(options.get("--limit")),
|
|
100
|
+
...(webhookId === undefined ? {} : { webhookId }),
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
const withCommandId = (parsed, change) => Effect.map(commandIdentifier(parsed.options.get("--command-id")), (commandId) => ({ change, commandId }));
|
|
104
|
+
export const readAddChange = (parsed) => {
|
|
105
|
+
requirePositionals(parsed.positionals, 0);
|
|
106
|
+
return withCommandId(parsed, { kind: "add", spec: readSpec(parsed) });
|
|
107
|
+
};
|
|
108
|
+
const targetOf = (parsed, positionals) => {
|
|
109
|
+
requirePositionals(parsed.positionals, positionals);
|
|
110
|
+
return {
|
|
111
|
+
expectedRevision: readExpectedRevision(parsed.options.get("--expected-revision")),
|
|
112
|
+
webhookId: parsed.positionals[0] ?? "",
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
export const readRemoveChange = (parsed) => withCommandId(parsed, { ...targetOf(parsed, 1), kind: "remove" });
|
|
116
|
+
export const readTestChange = (parsed) => withCommandId(parsed, { ...targetOf(parsed, 1), kind: "test" });
|
|
117
|
+
export const readRedeliverChange = (parsed) => {
|
|
118
|
+
requirePositionals(parsed.positionals, 1);
|
|
119
|
+
return withCommandId(parsed, {
|
|
120
|
+
deliveryId: parsed.positionals[0] ?? "",
|
|
121
|
+
expectedRevision: readExpectedRevision(parsed.options.get("--expected-revision")),
|
|
122
|
+
kind: "redeliver",
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
//# sourceMappingURL=input.js.map
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { cell, formatRows, tab, withNextPage, } from "../../command-line/emit/index.js";
|
|
2
|
+
const hookLine = (hook) => tab([
|
|
3
|
+
hook.id,
|
|
4
|
+
hook.state,
|
|
5
|
+
hook.revision,
|
|
6
|
+
cell(hook.spec.url),
|
|
7
|
+
hook.spec.events.join(","),
|
|
8
|
+
]);
|
|
9
|
+
const deliveryLine = (delivery) => tab([
|
|
10
|
+
delivery.id,
|
|
11
|
+
delivery.webhookId,
|
|
12
|
+
delivery.state,
|
|
13
|
+
delivery.kind,
|
|
14
|
+
`attempts=${String(delivery.attempts)}`,
|
|
15
|
+
delivery.errorClass ?? "",
|
|
16
|
+
]);
|
|
17
|
+
const specOf = ({ change, current }) => change.kind === "add" ? change.spec : current?.spec;
|
|
18
|
+
const specLines = (spec) => [
|
|
19
|
+
spec.allowPrivate
|
|
20
|
+
? "allowPrivate=true (sends may reach private and loopback addresses)"
|
|
21
|
+
: "allowPrivate=false",
|
|
22
|
+
`url=${cell(spec.url)}`,
|
|
23
|
+
`events=${spec.events.join(",")}`,
|
|
24
|
+
`filters=${spec.filters.map(({ key, value }) => `${key}=${cell(value)}`).join(",") || "none"}`,
|
|
25
|
+
`secretEnv=${spec.secretEnv}`,
|
|
26
|
+
];
|
|
27
|
+
const targetLines = (result) => {
|
|
28
|
+
const { change, deletesDeliveries } = result;
|
|
29
|
+
return [
|
|
30
|
+
...(change.kind === "add" ? [] : [`revision=${change.expectedRevision}`]),
|
|
31
|
+
...(change.kind === "redeliver" ? [`delivery=${change.deliveryId}`] : []),
|
|
32
|
+
...(deletesDeliveries === undefined
|
|
33
|
+
? []
|
|
34
|
+
: [`deletes=${String(deletesDeliveries)} deliveries`]),
|
|
35
|
+
];
|
|
36
|
+
};
|
|
37
|
+
const previewLines = (result) => {
|
|
38
|
+
const { change, commandId, expiresAt, webhookId } = result;
|
|
39
|
+
const spec = specOf(result);
|
|
40
|
+
const header = tab([
|
|
41
|
+
change.kind,
|
|
42
|
+
webhookId,
|
|
43
|
+
`command=${commandId}`,
|
|
44
|
+
`expires=${expiresAt}`,
|
|
45
|
+
]);
|
|
46
|
+
return `${[header, ...(spec === undefined ? [] : specLines(spec)), ...targetLines(result)].join("\n")}\n`;
|
|
47
|
+
};
|
|
48
|
+
const confirmLine = ({ delivery, receipt, webhook, }) => `${tab([webhook.id, webhook.state, webhook.revision, receipt.receiptId, delivery])}\n`;
|
|
49
|
+
const DELIVERY_HEADERS = [
|
|
50
|
+
"DELIVERY",
|
|
51
|
+
"WEBHOOK",
|
|
52
|
+
"STATE",
|
|
53
|
+
"KIND",
|
|
54
|
+
"ATTEMPTS",
|
|
55
|
+
"ERROR",
|
|
56
|
+
];
|
|
57
|
+
export const formatWebhooksResult = ({ result }) => {
|
|
58
|
+
switch (result.method) {
|
|
59
|
+
case "webhooks.list":
|
|
60
|
+
return withNextPage(formatRows(result.items, hookLine, {
|
|
61
|
+
empty: "No webhooks.",
|
|
62
|
+
headers: ["WEBHOOK", "STATE", "REVISION", "URL", "EVENTS"],
|
|
63
|
+
}), result.nextCursor);
|
|
64
|
+
case "webhooks.deliveries":
|
|
65
|
+
return withNextPage(formatRows(result.items, deliveryLine, {
|
|
66
|
+
empty: "No deliveries.",
|
|
67
|
+
headers: DELIVERY_HEADERS,
|
|
68
|
+
}), result.nextCursor);
|
|
69
|
+
case "webhooks.change.preview":
|
|
70
|
+
return previewLines(result);
|
|
71
|
+
case "webhooks.change.confirm":
|
|
72
|
+
return confirmLine(result);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
//# sourceMappingURL=format.js.map
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const webhooks = () => import("../index.js");
|
|
2
|
+
export const WEBHOOKS_TREE = {
|
|
3
|
+
groups: [["webhooks", "Signed outbound webhooks for Node events."]],
|
|
4
|
+
leaves: [
|
|
5
|
+
[
|
|
6
|
+
"webhooks list [--limit <1..100>] [--after <cursor>]",
|
|
7
|
+
1,
|
|
8
|
+
"webhooks.list",
|
|
9
|
+
"List webhooks.",
|
|
10
|
+
{ run: [webhooks, "runWebhooksList"] },
|
|
11
|
+
],
|
|
12
|
+
[
|
|
13
|
+
"webhooks deliveries [--webhook <webhook-id>] [--failed] [--limit <1..100>] [--after <cursor>]",
|
|
14
|
+
1,
|
|
15
|
+
"webhooks.deliveries",
|
|
16
|
+
"List webhook deliveries; --failed lists parked and denied ones.",
|
|
17
|
+
{ run: [webhooks, "runWebhooksDeliveries"] },
|
|
18
|
+
],
|
|
19
|
+
[
|
|
20
|
+
"webhooks add (--url <http-url> --secret-env <VARIABLE> --event <kind>... [--label <key=value>...] [--project <project-id>] [--node-id <node-id>] [--allow-private] [--command-id <id>] [--dry-run] | --confirm-stdin)",
|
|
21
|
+
1,
|
|
22
|
+
["webhooks.change.preview", "webhooks.change.confirm"],
|
|
23
|
+
"Add a webhook after a preview.",
|
|
24
|
+
{ kind: "two-phase", run: [webhooks, "runWebhooksAdd"] },
|
|
25
|
+
],
|
|
26
|
+
[
|
|
27
|
+
"webhooks test (<webhook-id> --expected-revision <revision> [--command-id <id>] [--dry-run] | --confirm-stdin)",
|
|
28
|
+
1,
|
|
29
|
+
["webhooks.change.preview", "webhooks.change.confirm"],
|
|
30
|
+
"Send a test event to a webhook after a preview.",
|
|
31
|
+
{ kind: "two-phase", run: [webhooks, "runWebhooksTest"] },
|
|
32
|
+
],
|
|
33
|
+
[
|
|
34
|
+
"webhooks remove (<webhook-id> --expected-revision <revision> [--command-id <id>] [--dry-run] | --confirm-stdin)",
|
|
35
|
+
1,
|
|
36
|
+
["webhooks.change.preview", "webhooks.change.confirm"],
|
|
37
|
+
"Remove a webhook and its deliveries after a preview.",
|
|
38
|
+
{ kind: "two-phase", run: [webhooks, "runWebhooksRemove"] },
|
|
39
|
+
],
|
|
40
|
+
[
|
|
41
|
+
"webhooks redeliver (<delivery-id> --expected-revision <revision> [--command-id <id>] [--dry-run] | --confirm-stdin)",
|
|
42
|
+
1,
|
|
43
|
+
["webhooks.change.preview", "webhooks.change.confirm"],
|
|
44
|
+
"Send a delivery again after a preview.",
|
|
45
|
+
{ kind: "two-phase", run: [webhooks, "runWebhooksRedeliver"] },
|
|
46
|
+
],
|
|
47
|
+
],
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=tree.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maiaos/cli",
|
|
3
|
-
"version": "0.1.0-canary.
|
|
3
|
+
"version": "0.1.0-canary.57",
|
|
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",
|
|
@@ -64,9 +64,9 @@
|
|
|
64
64
|
"dependencies": {
|
|
65
65
|
"@earendil-works/pi-tui": "1.0.0",
|
|
66
66
|
"@effect/platform-node-shared": "4.0.0",
|
|
67
|
-
"@maiaos/agent": "0.1.0-canary.
|
|
68
|
-
"@maiaos/client-core": "0.1.0-canary.
|
|
69
|
-
"@maiaos/sdk": "0.1.0-canary.
|
|
67
|
+
"@maiaos/agent": "0.1.0-canary.57",
|
|
68
|
+
"@maiaos/client-core": "0.1.0-canary.57",
|
|
69
|
+
"@maiaos/sdk": "0.1.0-canary.57",
|
|
70
70
|
"effect": "4.0.0"
|
|
71
71
|
},
|
|
72
72
|
"scripts": {
|