@makine/cli 0.6.3 → 0.7.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/dist/agents/command.d.ts +49 -0
- package/dist/agents/command.d.ts.map +1 -0
- package/dist/agents/command.js +368 -0
- package/dist/agents/command.js.map +1 -0
- package/dist/contracts/command.js +36 -21
- package/dist/contracts/command.js.map +1 -1
- package/dist/gov-id/command.d.ts +34 -0
- package/dist/gov-id/command.d.ts.map +1 -0
- package/dist/gov-id/command.js +170 -0
- package/dist/gov-id/command.js.map +1 -0
- package/dist/index.d.ts +24 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +276 -7
- package/dist/index.js.map +1 -1
- package/dist/migrate/runtime-rules.d.ts.map +1 -1
- package/dist/migrate/runtime-rules.js +5 -1
- package/dist/migrate/runtime-rules.js.map +1 -1
- package/dist/quality/command.d.ts +1 -1
- package/dist/quality/command.d.ts.map +1 -1
- package/dist/quality/command.js +1 -1
- package/dist/quality/command.js.map +1 -1
- package/dist/receipts/command.d.ts +26 -2
- package/dist/receipts/command.d.ts.map +1 -1
- package/dist/receipts/command.js +74 -6
- package/dist/receipts/command.js.map +1 -1
- package/dist/runs/command.d.ts +45 -0
- package/dist/runs/command.d.ts.map +1 -0
- package/dist/runs/command.js +224 -0
- package/dist/runs/command.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `makine agents`: register an outside A2A agent, read it, rotate its credential, re-pin its card
|
|
3
|
+
* and retire it (ADR 0016 § D16.5).
|
|
4
|
+
*
|
|
5
|
+
* The agent's credential is read from stdin or a hidden prompt only, never from an argument or an
|
|
6
|
+
* environment variable, where `ps` and shell history would see it, and it is never printed back.
|
|
7
|
+
* Every write needs `makine login`: a workspace key is refused, because this workspace's task input
|
|
8
|
+
* leaves Makine for whatever host a registration names.
|
|
9
|
+
*/
|
|
10
|
+
export declare const AGENTS_SUBCOMMANDS: readonly ["register", "list", "show", "credential", "repin", "retire"];
|
|
11
|
+
export type AgentsSubcommand = (typeof AGENTS_SUBCOMMANDS)[number];
|
|
12
|
+
export interface AgentsInvocation {
|
|
13
|
+
subcommand: AgentsSubcommand;
|
|
14
|
+
/** The host for `register`; the agent id for `show`, `credential`, `repin` and `retire`. */
|
|
15
|
+
target?: string;
|
|
16
|
+
/** `register` only: what screens call the agent. */
|
|
17
|
+
name?: string;
|
|
18
|
+
/** `register` only: one `<role>:<artifact_type>[:<artifact_name>]` per `--artifact`. */
|
|
19
|
+
artifacts?: readonly string[];
|
|
20
|
+
/** `register` only: read the agent's credential from standard input. */
|
|
21
|
+
credentialStdin?: boolean;
|
|
22
|
+
/** `register` only: the explicit acknowledgement the route requires. */
|
|
23
|
+
acknowledgeEgress?: boolean;
|
|
24
|
+
/** `repin` only: pin the live card without asking. */
|
|
25
|
+
yes: boolean;
|
|
26
|
+
json: boolean;
|
|
27
|
+
}
|
|
28
|
+
export interface AgentsConnection {
|
|
29
|
+
baseUrl: string;
|
|
30
|
+
apiKey: string;
|
|
31
|
+
/** True when the credential came from `MAKINE_API_KEY` or `--api-key` rather than a session. */
|
|
32
|
+
explicitKey: boolean;
|
|
33
|
+
fetchImpl?: typeof fetch;
|
|
34
|
+
}
|
|
35
|
+
export interface AgentsIo {
|
|
36
|
+
out: (line: string) => void;
|
|
37
|
+
err: (line: string) => void;
|
|
38
|
+
/**
|
|
39
|
+
* Reads the agent's credential. The default reads stdin to end of input; a terminal session
|
|
40
|
+
* supplies a hidden prompt. It returns the value and this module keeps no other copy of it.
|
|
41
|
+
*/
|
|
42
|
+
readCredential: (prompt: string) => Promise<string>;
|
|
43
|
+
/** Reads the answer `repin` asks for without `--yes`. */
|
|
44
|
+
confirm: (prompt: string) => Promise<string>;
|
|
45
|
+
}
|
|
46
|
+
export type AgentsOutcome = "ok" | "usage" | "refused" | "auth" | "unavailable";
|
|
47
|
+
export declare function runAgents(invocation: AgentsInvocation, connection: AgentsConnection, io: AgentsIo): Promise<AgentsOutcome>;
|
|
48
|
+
export declare function isAgentsSubcommand(value: string): value is AgentsSubcommand;
|
|
49
|
+
//# sourceMappingURL=command.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../src/agents/command.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AAEH,eAAO,MAAM,kBAAkB,wEAOrB,CAAC;AAEX,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC;AAanE,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,gBAAgB,CAAC;IAC7B,4FAA4F;IAC5F,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oDAAoD;IACpD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wFAAwF;IACxF,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC9B,wEAAwE;IACxE,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,wEAAwE;IACxE,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,sDAAsD;IACtD,GAAG,EAAE,OAAO,CAAC;IACb,IAAI,EAAE,OAAO,CAAC;CACf;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,gGAAgG;IAChG,WAAW,EAAE,OAAO,CAAC;IACrB,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;CAC1B;AAED,MAAM,WAAW,QAAQ;IACvB,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5B,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5B;;;OAGG;IACH,cAAc,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACpD,yDAAyD;IACzD,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;CAC9C;AAED,MAAM,MAAM,aAAa,GAAG,IAAI,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,GAAG,aAAa,CAAC;AA8ChF,wBAAsB,SAAS,CAC7B,UAAU,EAAE,gBAAgB,EAC5B,UAAU,EAAE,gBAAgB,EAC5B,EAAE,EAAE,QAAQ,GACX,OAAO,CAAC,aAAa,CAAC,CAgBxB;AA+XD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,gBAAgB,CAE3E"}
|
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/**
|
|
3
|
+
* `makine agents`: register an outside A2A agent, read it, rotate its credential, re-pin its card
|
|
4
|
+
* and retire it (ADR 0016 § D16.5).
|
|
5
|
+
*
|
|
6
|
+
* The agent's credential is read from stdin or a hidden prompt only, never from an argument or an
|
|
7
|
+
* environment variable, where `ps` and shell history would see it, and it is never printed back.
|
|
8
|
+
* Every write needs `makine login`: a workspace key is refused, because this workspace's task input
|
|
9
|
+
* leaves Makine for whatever host a registration names.
|
|
10
|
+
*/
|
|
11
|
+
export const AGENTS_SUBCOMMANDS = [
|
|
12
|
+
"register",
|
|
13
|
+
"list",
|
|
14
|
+
"show",
|
|
15
|
+
"credential",
|
|
16
|
+
"repin",
|
|
17
|
+
"retire",
|
|
18
|
+
];
|
|
19
|
+
const SIGN_IN_NOTE = "This needs a signed-in account. Run `makine login`.";
|
|
20
|
+
/**
|
|
21
|
+
* Why `makine login` alone does not fix it when the environment carries a key: `resolveCredential`
|
|
22
|
+
* sends an explicit key in preference to a stored session, so a set `MAKINE_API_KEY` keeps the
|
|
23
|
+
* refusal in place however many times you sign in.
|
|
24
|
+
*/
|
|
25
|
+
const API_KEY_OVERRIDES_LOGIN_NOTE = "MAKINE_API_KEY is set, and an explicit key is used in preference to a stored session. Unset it " +
|
|
26
|
+
"(or drop --api-key) and run `makine login`.";
|
|
27
|
+
const CREDENTIAL_PROMPT = "Agent credential (read from stdin; it is never echoed, stored on this machine, or passed as an argument): ";
|
|
28
|
+
export async function runAgents(invocation, connection, io) {
|
|
29
|
+
const call = makeCall(connection);
|
|
30
|
+
switch (invocation.subcommand) {
|
|
31
|
+
case "register":
|
|
32
|
+
return await registerAgent(invocation, call, io, connection);
|
|
33
|
+
case "list":
|
|
34
|
+
return await listAgents(invocation, call, io, connection);
|
|
35
|
+
case "show":
|
|
36
|
+
return await showAgent(invocation, call, io, connection);
|
|
37
|
+
case "credential":
|
|
38
|
+
return await setCredential(invocation, call, io, connection);
|
|
39
|
+
case "repin":
|
|
40
|
+
return await repinCard(invocation, call, io, connection);
|
|
41
|
+
case "retire":
|
|
42
|
+
return await retireAgent(invocation, call, io, connection);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Each declaration is `<role>:<artifact_type>[:<artifact_name>]`. The A2A artifact name is the name
|
|
47
|
+
* the agent gives its own artifact and the role is what the contract asks for; the two differ often
|
|
48
|
+
* enough to be separable, and the name defaults to the role when they agree.
|
|
49
|
+
*/
|
|
50
|
+
function parseDeclarations(values) {
|
|
51
|
+
const declarations = [];
|
|
52
|
+
for (const value of values) {
|
|
53
|
+
const parts = value.split(":");
|
|
54
|
+
const [role, artifactType, artifactName] = parts;
|
|
55
|
+
if ((parts.length !== 2 && parts.length !== 3) ||
|
|
56
|
+
role === undefined ||
|
|
57
|
+
role.trim().length === 0 ||
|
|
58
|
+
artifactType === undefined ||
|
|
59
|
+
artifactType.trim().length === 0 ||
|
|
60
|
+
(parts.length === 3 && (artifactName === undefined || artifactName.trim().length === 0))) {
|
|
61
|
+
return {
|
|
62
|
+
ok: false,
|
|
63
|
+
message: `\`--artifact ${value}\` is not \`<role>:<artifact_type>[:<artifact_name>]\`. The artifact name defaults to the role.`,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
declarations.push({
|
|
67
|
+
role: role.trim(),
|
|
68
|
+
artifact_type: artifactType.trim(),
|
|
69
|
+
required: true,
|
|
70
|
+
collection: {
|
|
71
|
+
kind: "a2a_artifact",
|
|
72
|
+
artifact_name: (artifactName ?? role).trim(),
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return { ok: true, declarations };
|
|
77
|
+
}
|
|
78
|
+
async function registerAgent(invocation, call, io, connection) {
|
|
79
|
+
const host = invocation.target;
|
|
80
|
+
if (host === undefined || host.trim().length === 0) {
|
|
81
|
+
io.err('`makine agents register` needs the agent\'s host, e.g. `makine agents register agent.example.com --name "Acme" --artifact message:text`.');
|
|
82
|
+
return "usage";
|
|
83
|
+
}
|
|
84
|
+
const displayName = invocation.name;
|
|
85
|
+
if (displayName === undefined || displayName.trim().length === 0) {
|
|
86
|
+
io.err("`makine agents register` needs --name <display name>.");
|
|
87
|
+
return "usage";
|
|
88
|
+
}
|
|
89
|
+
const values = invocation.artifacts ?? [];
|
|
90
|
+
if (values.length === 0) {
|
|
91
|
+
io.err("`makine agents register` needs at least one --artifact <role>:<artifact_type>[:<artifact_name>], naming what the agent must deliver.");
|
|
92
|
+
return "usage";
|
|
93
|
+
}
|
|
94
|
+
const parsed = parseDeclarations(values);
|
|
95
|
+
if (!parsed.ok) {
|
|
96
|
+
io.err(parsed.message);
|
|
97
|
+
return "usage";
|
|
98
|
+
}
|
|
99
|
+
// The notice comes before the write, on both sides: the route refuses without the
|
|
100
|
+
// acknowledgement, and this prints the same sentences the route carries.
|
|
101
|
+
if (invocation.acknowledgeEgress !== true) {
|
|
102
|
+
const preview = await call("GET", "/agents");
|
|
103
|
+
if (preview.ok) {
|
|
104
|
+
for (const line of readNotice(preview.body))
|
|
105
|
+
io.err(`! ${line}`);
|
|
106
|
+
}
|
|
107
|
+
io.err("Re-run with --acknowledge-egress to confirm you have read what registering this agent opens. Nothing was registered.");
|
|
108
|
+
return "usage";
|
|
109
|
+
}
|
|
110
|
+
let credential;
|
|
111
|
+
if (invocation.credentialStdin === true) {
|
|
112
|
+
credential = await io.readCredential(CREDENTIAL_PROMPT);
|
|
113
|
+
if (credential.trim().length === 0) {
|
|
114
|
+
io.err("No credential was supplied on stdin.");
|
|
115
|
+
return "usage";
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const result = await call("POST", "/agents", {
|
|
119
|
+
agent_host: host.trim(),
|
|
120
|
+
display_name: displayName,
|
|
121
|
+
acknowledged_agent_egress: true,
|
|
122
|
+
artifact_declarations: parsed.declarations,
|
|
123
|
+
...(credential === undefined ? {} : { credential }),
|
|
124
|
+
});
|
|
125
|
+
if (!result.ok)
|
|
126
|
+
return report(io, result, connection, host.trim());
|
|
127
|
+
const body = result.body;
|
|
128
|
+
if (invocation.json) {
|
|
129
|
+
io.out(JSON.stringify(body, null, 2));
|
|
130
|
+
return "ok";
|
|
131
|
+
}
|
|
132
|
+
const agent = body.agent;
|
|
133
|
+
if (agent === null) {
|
|
134
|
+
io.err("Registered, but the agent could not be read back.");
|
|
135
|
+
return "ok";
|
|
136
|
+
}
|
|
137
|
+
io.err(`Registered ${agent.display_name} as ${agent.remote_agent_id}.`);
|
|
138
|
+
io.err(` card ${body.card.name} (${body.card.signature_state})`);
|
|
139
|
+
if (body.card.provider !== null)
|
|
140
|
+
io.err(` provider ${body.card.provider}`);
|
|
141
|
+
io.err(` skills ${body.card.skills.join(", ")}`);
|
|
142
|
+
io.err(` pinned ${agent.pinned_card_hash}`);
|
|
143
|
+
io.err(` credential ${agent.has_credential ? "stored, sent only to this agent's host" : "none"}`);
|
|
144
|
+
io.err(`Send it a task with \`makine runs submit --executor ${agent.executor_ref} --contract <id>@<version> --input <file.json>\`.`);
|
|
145
|
+
io.out(agent.executor_ref);
|
|
146
|
+
return "ok";
|
|
147
|
+
}
|
|
148
|
+
async function listAgents(invocation, call, io, connection) {
|
|
149
|
+
const result = await call("GET", "/agents");
|
|
150
|
+
if (!result.ok)
|
|
151
|
+
return report(io, result, connection);
|
|
152
|
+
const body = result.body;
|
|
153
|
+
if (invocation.json) {
|
|
154
|
+
io.out(JSON.stringify(body, null, 2));
|
|
155
|
+
return "ok";
|
|
156
|
+
}
|
|
157
|
+
if (body.agents.length === 0) {
|
|
158
|
+
io.out("No outside agents. Register one with `makine agents register <host> --name <name> --artifact <role>:<type>`.");
|
|
159
|
+
return "ok";
|
|
160
|
+
}
|
|
161
|
+
for (const agent of body.agents) {
|
|
162
|
+
const retired = agent.retired_at === null ? "" : `\tretired ${agent.retired_at}`;
|
|
163
|
+
io.out(`${agent.remote_agent_id}\t${agent.executor_ref}\t${agent.display_name}\t→ ${agent.agent_host}\t${agent.status}${retired}`);
|
|
164
|
+
}
|
|
165
|
+
for (const line of body.egress_notice ?? [])
|
|
166
|
+
io.out(`! ${line}`);
|
|
167
|
+
return "ok";
|
|
168
|
+
}
|
|
169
|
+
async function showAgent(invocation, call, io, connection) {
|
|
170
|
+
const target = invocation.target;
|
|
171
|
+
if (target === undefined) {
|
|
172
|
+
io.err("`makine agents show` needs an agent id. `makine agents list` prints them.");
|
|
173
|
+
return "usage";
|
|
174
|
+
}
|
|
175
|
+
const result = await call("GET", `/agents/${encodeURIComponent(target)}`);
|
|
176
|
+
if (!result.ok)
|
|
177
|
+
return report(io, result, connection);
|
|
178
|
+
const body = result.body;
|
|
179
|
+
if (invocation.json) {
|
|
180
|
+
io.out(JSON.stringify(body, null, 2));
|
|
181
|
+
return "ok";
|
|
182
|
+
}
|
|
183
|
+
const agent = body.agent;
|
|
184
|
+
io.out(`${agent.remote_agent_id}\t${agent.display_name}`);
|
|
185
|
+
io.out(` executor ${agent.executor_ref}`);
|
|
186
|
+
io.out(` address ${agent.agent_url}`);
|
|
187
|
+
io.out(` status ${agent.status}${agent.retired_at === null ? "" : ` (retired ${agent.retired_at})`}`);
|
|
188
|
+
io.out(` card now ${agent.card_hash} (${agent.card_state}, ${agent.card_signature_state})`);
|
|
189
|
+
io.out(` pinned ${agent.pinned_card_hash}`);
|
|
190
|
+
io.out(` skills ${agent.declared_skills.join(", ")}`);
|
|
191
|
+
io.out(` credential ${agent.has_credential ? "stored" : "none"}`);
|
|
192
|
+
if (agent.last_error_code !== null)
|
|
193
|
+
io.out(` last error ${agent.last_error_code}`);
|
|
194
|
+
for (const pin of body.card_pins) {
|
|
195
|
+
io.out(` pin ${pin.pinned_card_hash}\t${pin.card_signature_state}\t${pin.approved_at}`);
|
|
196
|
+
}
|
|
197
|
+
if (agent.card_hash !== agent.pinned_card_hash) {
|
|
198
|
+
io.out("The live card differs from the pinned one. `makine agents repin` pins what is live now.");
|
|
199
|
+
}
|
|
200
|
+
return "ok";
|
|
201
|
+
}
|
|
202
|
+
async function setCredential(invocation, call, io, connection) {
|
|
203
|
+
const target = invocation.target;
|
|
204
|
+
if (target === undefined) {
|
|
205
|
+
io.err("`makine agents credential` needs an agent id.");
|
|
206
|
+
return "usage";
|
|
207
|
+
}
|
|
208
|
+
const credential = await io.readCredential(CREDENTIAL_PROMPT);
|
|
209
|
+
if (credential.trim().length === 0) {
|
|
210
|
+
io.err("No credential was supplied on stdin.");
|
|
211
|
+
return "usage";
|
|
212
|
+
}
|
|
213
|
+
const result = await call("PUT", `/agents/${encodeURIComponent(target)}/credential`, {
|
|
214
|
+
credential,
|
|
215
|
+
});
|
|
216
|
+
if (!result.ok)
|
|
217
|
+
return report(io, result, connection);
|
|
218
|
+
const body = result.body;
|
|
219
|
+
if (invocation.json) {
|
|
220
|
+
io.out(JSON.stringify(body, null, 2));
|
|
221
|
+
return "ok";
|
|
222
|
+
}
|
|
223
|
+
io.err(`Stored a credential for ${body.remote_agent_id}; it is sent only to that agent's host.`);
|
|
224
|
+
io.out(body.remote_agent_id);
|
|
225
|
+
return "ok";
|
|
226
|
+
}
|
|
227
|
+
async function repinCard(invocation, call, io, connection) {
|
|
228
|
+
const target = invocation.target;
|
|
229
|
+
if (target === undefined) {
|
|
230
|
+
io.err("`makine agents repin` needs an agent id.");
|
|
231
|
+
return "usage";
|
|
232
|
+
}
|
|
233
|
+
const read = await call("GET", `/agents/${encodeURIComponent(target)}`);
|
|
234
|
+
if (!read.ok)
|
|
235
|
+
return report(io, read, connection);
|
|
236
|
+
const before = read.body.agent;
|
|
237
|
+
// What is being approved is the difference between the two hashes, so both are shown before the
|
|
238
|
+
// question rather than after the write.
|
|
239
|
+
io.err(`Agent ${before.remote_agent_id} (${before.display_name})`);
|
|
240
|
+
io.err(`Card now ${before.card_hash} (${before.card_signature_state})`);
|
|
241
|
+
io.err(`Pinned ${before.pinned_card_hash}`);
|
|
242
|
+
if (before.card_hash === before.pinned_card_hash) {
|
|
243
|
+
io.err("The live card is the one already pinned; re-pinning records a fresh approval.");
|
|
244
|
+
}
|
|
245
|
+
if (!invocation.yes) {
|
|
246
|
+
const answer = (await io.confirm("Type yes to pin the card above: ")).trim().toLowerCase();
|
|
247
|
+
if (answer !== "yes") {
|
|
248
|
+
io.err("Nothing was pinned.");
|
|
249
|
+
return "usage";
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
const result = await call("POST", `/agents/${encodeURIComponent(target)}/repin`);
|
|
253
|
+
if (!result.ok)
|
|
254
|
+
return report(io, result, connection);
|
|
255
|
+
const body = result.body;
|
|
256
|
+
if (invocation.json) {
|
|
257
|
+
io.out(JSON.stringify(body, null, 2));
|
|
258
|
+
return "ok";
|
|
259
|
+
}
|
|
260
|
+
const after = body.agent;
|
|
261
|
+
if (after === null) {
|
|
262
|
+
io.err("Re-pinned, but the agent could not be read back.");
|
|
263
|
+
return "ok";
|
|
264
|
+
}
|
|
265
|
+
io.err(`Pinned ${after.pinned_card_hash} (${after.card_signature_state}).`);
|
|
266
|
+
io.out(after.pinned_card_hash);
|
|
267
|
+
return "ok";
|
|
268
|
+
}
|
|
269
|
+
async function retireAgent(invocation, call, io, connection) {
|
|
270
|
+
const target = invocation.target;
|
|
271
|
+
if (target === undefined) {
|
|
272
|
+
io.err("`makine agents retire` needs an agent id.");
|
|
273
|
+
return "usage";
|
|
274
|
+
}
|
|
275
|
+
const result = await call("POST", `/agents/${encodeURIComponent(target)}/retire`);
|
|
276
|
+
if (!result.ok)
|
|
277
|
+
return report(io, result, connection);
|
|
278
|
+
const body = result.body;
|
|
279
|
+
if (invocation.json) {
|
|
280
|
+
io.out(JSON.stringify(body, null, 2));
|
|
281
|
+
return "ok";
|
|
282
|
+
}
|
|
283
|
+
io.err(`Retired ${body.remote_agent_id} at ${body.retired_at}.`);
|
|
284
|
+
if (body.note !== undefined)
|
|
285
|
+
io.err(body.note);
|
|
286
|
+
io.out(body.remote_agent_id);
|
|
287
|
+
return "ok";
|
|
288
|
+
}
|
|
289
|
+
function readNotice(body) {
|
|
290
|
+
const notice = body?.egress_notice;
|
|
291
|
+
return Array.isArray(notice)
|
|
292
|
+
? notice.filter((line) => typeof line === "string")
|
|
293
|
+
: [];
|
|
294
|
+
}
|
|
295
|
+
function makeCall(connection) {
|
|
296
|
+
const send = connection.fetchImpl ?? fetch;
|
|
297
|
+
return async (method, path, payload) => {
|
|
298
|
+
let response;
|
|
299
|
+
try {
|
|
300
|
+
response = await send(`${connection.baseUrl.replace(/\/+$/, "")}${path}`, {
|
|
301
|
+
method,
|
|
302
|
+
redirect: "manual",
|
|
303
|
+
headers: {
|
|
304
|
+
authorization: `Bearer ${connection.apiKey}`,
|
|
305
|
+
...(payload === undefined ? {} : { "content-type": "application/json" }),
|
|
306
|
+
},
|
|
307
|
+
...(payload === undefined ? {} : { body: JSON.stringify(payload) }),
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
catch (error) {
|
|
311
|
+
return {
|
|
312
|
+
ok: false,
|
|
313
|
+
status: 0,
|
|
314
|
+
code: "unreachable",
|
|
315
|
+
message: `Could not reach Makine: ${error instanceof Error ? error.message : String(error)}`,
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
let parsed;
|
|
319
|
+
try {
|
|
320
|
+
parsed = await response.json();
|
|
321
|
+
}
|
|
322
|
+
catch {
|
|
323
|
+
parsed = undefined;
|
|
324
|
+
}
|
|
325
|
+
if (!response.ok) {
|
|
326
|
+
const error = parsed?.error ?? {};
|
|
327
|
+
return {
|
|
328
|
+
ok: false,
|
|
329
|
+
status: response.status,
|
|
330
|
+
code: error.code ?? "unexpected_error",
|
|
331
|
+
message: error.message ?? `Makine answered ${String(response.status)}.`,
|
|
332
|
+
...(error.acknowledgement === undefined ? {} : { acknowledgement: error.acknowledgement }),
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
return { ok: true, body: parsed };
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
/** The route's own words first, then the one step that clears this refusal. */
|
|
339
|
+
function report(io, result, connection, host) {
|
|
340
|
+
io.err(result.message);
|
|
341
|
+
for (const line of result.acknowledgement ?? [])
|
|
342
|
+
io.err(`! ${line}`);
|
|
343
|
+
if (result.code === "sign_in_required") {
|
|
344
|
+
io.err(connection.explicitKey ? API_KEY_OVERRIDES_LOGIN_NOTE : SIGN_IN_NOTE);
|
|
345
|
+
}
|
|
346
|
+
if (result.code === "agent_host_not_allowed") {
|
|
347
|
+
io.err(`Approve it first: \`makine workflows approve-host ${host ?? "<host>"} --acknowledge-egress\`.`);
|
|
348
|
+
}
|
|
349
|
+
if (result.code === "agent_egress_acknowledgement_required") {
|
|
350
|
+
io.err("Re-run with --acknowledge-egress once you have read the lines above.");
|
|
351
|
+
}
|
|
352
|
+
// The route words this one as a plain `invalid_request`, so the flag that supplies the credential
|
|
353
|
+
// is named here rather than left to be guessed.
|
|
354
|
+
if (result.code === "invalid_request" && result.message.toLowerCase().includes("credential")) {
|
|
355
|
+
io.err("Pipe the credential in: `pbpaste | makine agents register ... --credential-stdin`.");
|
|
356
|
+
}
|
|
357
|
+
if (result.status === 0)
|
|
358
|
+
return "unavailable";
|
|
359
|
+
if (result.status === 401 || result.status === 403)
|
|
360
|
+
return "auth";
|
|
361
|
+
if (result.status >= 500)
|
|
362
|
+
return "unavailable";
|
|
363
|
+
return "refused";
|
|
364
|
+
}
|
|
365
|
+
export function isAgentsSubcommand(value) {
|
|
366
|
+
return AGENTS_SUBCOMMANDS.includes(value);
|
|
367
|
+
}
|
|
368
|
+
//# sourceMappingURL=command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.js","sourceRoot":"","sources":["../../src/agents/command.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAE9B;;;;;;;;GAQG;AAEH,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,UAAU;IACV,MAAM;IACN,MAAM;IACN,YAAY;IACZ,OAAO;IACP,QAAQ;CACA,CAAC;AAIX,MAAM,YAAY,GAAG,qDAAqD,CAAC;AAE3E;;;;GAIG;AACH,MAAM,4BAA4B,GAChC,iGAAiG;IACjG,6CAA6C,CAAC;AAyChD,MAAM,iBAAiB,GACrB,4GAA4G,CAAC;AA2C/G,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,UAA4B,EAC5B,UAA4B,EAC5B,EAAY;IAEZ,MAAM,IAAI,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC;IAClC,QAAQ,UAAU,CAAC,UAAU,EAAE,CAAC;QAC9B,KAAK,UAAU;YACb,OAAO,MAAM,aAAa,CAAC,UAAU,EAAE,IAAI,EAAE,EAAE,EAAE,UAAU,CAAC,CAAC;QAC/D,KAAK,MAAM;YACT,OAAO,MAAM,UAAU,CAAC,UAAU,EAAE,IAAI,EAAE,EAAE,EAAE,UAAU,CAAC,CAAC;QAC5D,KAAK,MAAM;YACT,OAAO,MAAM,SAAS,CAAC,UAAU,EAAE,IAAI,EAAE,EAAE,EAAE,UAAU,CAAC,CAAC;QAC3D,KAAK,YAAY;YACf,OAAO,MAAM,aAAa,CAAC,UAAU,EAAE,IAAI,EAAE,EAAE,EAAE,UAAU,CAAC,CAAC;QAC/D,KAAK,OAAO;YACV,OAAO,MAAM,SAAS,CAAC,UAAU,EAAE,IAAI,EAAE,EAAE,EAAE,UAAU,CAAC,CAAC;QAC3D,KAAK,QAAQ;YACX,OAAO,MAAM,WA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C;IACD,kGAAkG;IAClG,gDAAgD;IAChD,IAAI,MAAM,CAAC,IAAI,KAAK,iBAAiB,IAAI,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC;QAC7F,EAAE,CAAC,GAAG,CAAC,oFAAoF,CAAC,CAAC;IAC/F,CAAC;IACD,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,aAAa,CAAC;IAC9C,IAAI,MAAM,CAAC,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,MAAM,KAAK,GAAG;QAAE,OAAO,MAAM,CAAC;IAClE,IAAI,MAAM,CAAC,MAAM,IAAI,GAAG;QAAE,OAAO,aAAa,CAAC;IAC/C,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,KAAa;IAC9C,OAAQ,kBAAwC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACnE,CAAC"}
|
|
@@ -131,8 +131,11 @@ async function createContract(invocation, client, io) {
|
|
|
131
131
|
const { repair_plan_definition: planDefinition, repair_plan: filePlan, ...body } = parsed;
|
|
132
132
|
const named = await contractName(body.acceptance_contract_id, useCase, client, identity);
|
|
133
133
|
if (named === undefined) {
|
|
134
|
-
io.err(
|
|
135
|
-
"
|
|
134
|
+
io.err(useCase === undefined
|
|
135
|
+
? "`makine contracts create` needs acceptance_contract_id in the file, or --use-case " +
|
|
136
|
+
"<address> to name the contract after a use case."
|
|
137
|
+
: `${useCase.display_name} has no address, so there is no name to take. ` +
|
|
138
|
+
"Put acceptance_contract_id in the file.");
|
|
136
139
|
return "usage";
|
|
137
140
|
}
|
|
138
141
|
const version = await contractVersion(body.version, named, client, identity);
|
|
@@ -242,24 +245,26 @@ async function contractName(fromFile, useCase, client, identity) {
|
|
|
242
245
|
return splitCoordinate(fromFile).id;
|
|
243
246
|
if (useCase === undefined || useCase.address === null)
|
|
244
247
|
return undefined;
|
|
245
|
-
// Only an id this workspace
|
|
246
|
-
//
|
|
247
|
-
//
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
248
|
+
// Only an id under this workspace's `<namespace><separator>` prefix carries a local name to
|
|
249
|
+
// continue. The gateway's passthrough id never does, so the address names the contract, as it
|
|
250
|
+
// does for a first one.
|
|
251
|
+
const continuing = useCase.live_acceptance_contract_id === null
|
|
252
|
+
? undefined
|
|
253
|
+
: localName(useCase.live_acceptance_contract_id, identity);
|
|
254
|
+
if (continuing !== undefined)
|
|
255
|
+
return continuing;
|
|
251
256
|
// The view carries no use case id, so a row is "somewhere else" by the name it is live on.
|
|
252
257
|
const here = useCase.address.trim().toLowerCase();
|
|
253
258
|
const { live_contracts: rows } = await client.listLiveContracts();
|
|
254
|
-
const liveElsewhere = rows.flatMap((row) => row.acceptance_contract_id === null || row.model.trim().toLowerCase() === here
|
|
259
|
+
const liveElsewhere = localNames(rows.flatMap((row) => row.acceptance_contract_id === null || row.model.trim().toLowerCase() === here
|
|
255
260
|
? []
|
|
256
|
-
: [
|
|
261
|
+
: [row.acceptance_contract_id]), identity);
|
|
257
262
|
const derived = contractNameFor(useCase.address);
|
|
258
263
|
if (!liveElsewhere.includes(derived))
|
|
259
264
|
return derived;
|
|
260
265
|
const { contracts } = await client.listContracts();
|
|
261
266
|
const taken = new Set([
|
|
262
|
-
...contracts.map((row) =>
|
|
267
|
+
...localNames(contracts.map((row) => row.acceptance_contract_id), identity),
|
|
263
268
|
...liveElsewhere,
|
|
264
269
|
]);
|
|
265
270
|
let suffix = 2;
|
|
@@ -274,9 +279,11 @@ async function contractName(fromFile, useCase, client, identity) {
|
|
|
274
279
|
async function contractVersion(fromFile, name, client, identity) {
|
|
275
280
|
if (fromFile !== undefined)
|
|
276
281
|
return fromFile;
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
282
|
+
// Only a name under this workspace's own prefix is already canonical. Merely holding the
|
|
283
|
+
// separator does not make one: that is the dashboard's rule, and the two must agree on which
|
|
284
|
+
// contract a save continues.
|
|
285
|
+
const prefix = `${identity.id_namespace}${identity.id_separator}`;
|
|
286
|
+
const namespaced = name.startsWith(prefix) ? name : `${prefix}${name}`;
|
|
280
287
|
let existing = [];
|
|
281
288
|
try {
|
|
282
289
|
existing = (await client.getContract(namespaced)).versions.map((row) => row.version);
|
|
@@ -289,15 +296,23 @@ async function contractVersion(fromFile, name, client, identity) {
|
|
|
289
296
|
return nextContractVersion(existing) ?? undefined;
|
|
290
297
|
}
|
|
291
298
|
/**
|
|
292
|
-
* The half of an acceptance id a person chose
|
|
293
|
-
*
|
|
294
|
-
*
|
|
299
|
+
* The half of an acceptance id a person chose, or `undefined` where this workspace did not mint
|
|
300
|
+
* the id. The gateway's passthrough contract is `makine.gateway.passthrough.<workspace id>`, which
|
|
301
|
+
* carries a separator of its own whenever the workspace id does, and none of it names a contract
|
|
302
|
+
* here.
|
|
295
303
|
*/
|
|
296
304
|
function localName(acceptanceContractId, identity) {
|
|
297
|
-
const
|
|
298
|
-
return
|
|
299
|
-
? acceptanceContractId
|
|
300
|
-
:
|
|
305
|
+
const prefix = `${identity.id_namespace}${identity.id_separator}`;
|
|
306
|
+
return acceptanceContractId.startsWith(prefix)
|
|
307
|
+
? acceptanceContractId.slice(prefix.length)
|
|
308
|
+
: undefined;
|
|
309
|
+
}
|
|
310
|
+
/** The local names among `ids`, leaving out every id this workspace did not mint. */
|
|
311
|
+
function localNames(ids, identity) {
|
|
312
|
+
return ids.flatMap((id) => {
|
|
313
|
+
const name = localName(id, identity);
|
|
314
|
+
return name === undefined ? [] : [name];
|
|
315
|
+
});
|
|
301
316
|
}
|
|
302
317
|
/**
|
|
303
318
|
* Why a judge check in a freshly created contract would fail every run: the judge is off for this
|