@parcha/agentrun 0.4.21 → 0.4.22
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 -1
- package/lib/cli.mjs +3 -2
- package/lib/commands.generated.mjs +192 -0
- package/lib/device.mjs +50 -20
- package/lib/login.mjs +24 -10
- package/lib/target.mjs +2 -0
- package/package.json +2 -2
- package/skills/agentrun-cli/SKILL.md +1 -1
- package/skills/agentrun-cli/references/commands.md +56 -1
package/README.md
CHANGED
|
@@ -167,7 +167,8 @@ Every other command is the server's API, from a second terminal: `npx @parcha/ag
|
|
|
167
167
|
another server, set `AGENTRUN_BASE_URL` and `AGENTRUN_API_KEY`, or sign in once with `agentrun login --to URL`
|
|
168
168
|
(`--to cloud` for AgentRun cloud): when the server offers a device sign-in, it prints an address and a code to approve
|
|
169
169
|
there, then keeps the token in `$XDG_CONFIG_HOME/agentrun/config.json` (0600); else it reads the token from stdin, as
|
|
170
|
-
`agentrun login --base-url URL < FILE` does.
|
|
170
|
+
`agentrun login --base-url URL < FILE` does. `agentrun login --base-url URL` typed on a terminal takes the device
|
|
171
|
+
sign-in too, when the server offers one. The response's JSON goes to stdout and an error's to
|
|
171
172
|
stderr; the exit code is 0 when it worked, 1 when the server refused, 2 for bad usage, 3 when the server cannot be
|
|
172
173
|
reached, 4 for a missing or refused token and 5 when the server does not offer the command here (a 501,
|
|
173
174
|
`unsupported_here`, its error saying why). The token is never a flag and never printed. A list command (`agents list`,
|
package/lib/cli.mjs
CHANGED
|
@@ -74,8 +74,9 @@ const HELP = () => {
|
|
|
74
74
|
"The server: --base-url, else AGENTRUN_BASE_URL, else base_url in $XDG_CONFIG_HOME/agentrun/config.json, else the",
|
|
75
75
|
"server started on this machine with the data directory (--data, default ~/.agentrun). The token: AGENTRUN_API_KEY,",
|
|
76
76
|
"else api_key in the config file, else that server's own; it is never a flag and never printed. agentrun login",
|
|
77
|
-
"--base-url URL checks a token read from stdin and writes the config file (0600)
|
|
78
|
-
"
|
|
77
|
+
"--base-url URL checks a token read from stdin and writes the config file (0600), or on a terminal signs in with a",
|
|
78
|
+
"device code when the server offers one; agentrun login --to URL (or cloud) signs in with a device code when the",
|
|
79
|
+
"server offers one, else reads the token from stdin; agentrun logout removes it.",
|
|
79
80
|
"Keys and other secrets are set in the console, signed in: the token can't write one, so no command does.",
|
|
80
81
|
"Output: the response's JSON on stdout, a file's bytes as they are; an error's on stderr. Exit codes: 0 ok, 1 the",
|
|
81
82
|
"server refused, 2 bad usage (a bad base URL among it), 3 the server cannot be reached, 4 no token, the token was",
|
|
@@ -2041,6 +2041,37 @@ export const COMMANDS = [
|
|
|
2041
2041
|
"raw": false,
|
|
2042
2042
|
"summary": "A code that pairs a person's own computer with this server"
|
|
2043
2043
|
},
|
|
2044
|
+
{
|
|
2045
|
+
"command": [
|
|
2046
|
+
"local",
|
|
2047
|
+
"create-suggested-agent"
|
|
2048
|
+
],
|
|
2049
|
+
"operationId": "createSuggestedAgent",
|
|
2050
|
+
"method": "POST",
|
|
2051
|
+
"path": "/suggestions/{suggestion_id}/create",
|
|
2052
|
+
"pathParams": [
|
|
2053
|
+
"suggestion_id"
|
|
2054
|
+
],
|
|
2055
|
+
"multiSegment": [],
|
|
2056
|
+
"query": [],
|
|
2057
|
+
"headers": [],
|
|
2058
|
+
"bodyFlags": [
|
|
2059
|
+
{
|
|
2060
|
+
"name": "name",
|
|
2061
|
+
"type": "string",
|
|
2062
|
+
"required": false,
|
|
2063
|
+
"description": "The agent's name, in place of the suggestion's."
|
|
2064
|
+
}
|
|
2065
|
+
],
|
|
2066
|
+
"hasBody": true,
|
|
2067
|
+
"bodyRequired": false,
|
|
2068
|
+
"bodyTypes": [
|
|
2069
|
+
"application/json"
|
|
2070
|
+
],
|
|
2071
|
+
"secretBody": false,
|
|
2072
|
+
"raw": false,
|
|
2073
|
+
"summary": "Create a suggested agent: a branch with its package and client, the agent made here, and a pull request"
|
|
2074
|
+
},
|
|
2044
2075
|
{
|
|
2045
2076
|
"command": [
|
|
2046
2077
|
"local",
|
|
@@ -2105,6 +2136,28 @@ export const COMMANDS = [
|
|
|
2105
2136
|
"raw": false,
|
|
2106
2137
|
"summary": "Turn Mode 2 off: run folders on this server's own disk"
|
|
2107
2138
|
},
|
|
2139
|
+
{
|
|
2140
|
+
"command": [
|
|
2141
|
+
"local",
|
|
2142
|
+
"discard-suggestion"
|
|
2143
|
+
],
|
|
2144
|
+
"operationId": "discardSuggestion",
|
|
2145
|
+
"method": "POST",
|
|
2146
|
+
"path": "/suggestions/{suggestion_id}/discard",
|
|
2147
|
+
"pathParams": [
|
|
2148
|
+
"suggestion_id"
|
|
2149
|
+
],
|
|
2150
|
+
"multiSegment": [],
|
|
2151
|
+
"query": [],
|
|
2152
|
+
"headers": [],
|
|
2153
|
+
"bodyFlags": [],
|
|
2154
|
+
"hasBody": false,
|
|
2155
|
+
"bodyRequired": false,
|
|
2156
|
+
"bodyTypes": [],
|
|
2157
|
+
"secretBody": false,
|
|
2158
|
+
"raw": false,
|
|
2159
|
+
"summary": "Discard a suggested agent: it goes away, and later scans leave it out"
|
|
2160
|
+
},
|
|
2108
2161
|
{
|
|
2109
2162
|
"command": [
|
|
2110
2163
|
"local",
|
|
@@ -2165,6 +2218,35 @@ export const COMMANDS = [
|
|
|
2165
2218
|
"raw": false,
|
|
2166
2219
|
"summary": "The model gateway in force: the environment's, the one saved here, or none"
|
|
2167
2220
|
},
|
|
2221
|
+
{
|
|
2222
|
+
"command": [
|
|
2223
|
+
"local",
|
|
2224
|
+
"get-suggestion"
|
|
2225
|
+
],
|
|
2226
|
+
"operationId": "getSuggestion",
|
|
2227
|
+
"method": "GET",
|
|
2228
|
+
"path": "/suggestions/{suggestion_id}",
|
|
2229
|
+
"pathParams": [
|
|
2230
|
+
"suggestion_id"
|
|
2231
|
+
],
|
|
2232
|
+
"multiSegment": [],
|
|
2233
|
+
"query": [
|
|
2234
|
+
{
|
|
2235
|
+
"name": "name",
|
|
2236
|
+
"type": "string",
|
|
2237
|
+
"required": false,
|
|
2238
|
+
"description": "The agent's name a create would be sent (`POST .../create` `name`): `files` are rendered with it, as the create pushes them. 422 when it is not 3 to 60 characters."
|
|
2239
|
+
}
|
|
2240
|
+
],
|
|
2241
|
+
"headers": [],
|
|
2242
|
+
"bodyFlags": [],
|
|
2243
|
+
"hasBody": false,
|
|
2244
|
+
"bodyRequired": false,
|
|
2245
|
+
"bodyTypes": [],
|
|
2246
|
+
"secretBody": false,
|
|
2247
|
+
"raw": false,
|
|
2248
|
+
"summary": "One suggested agent whole: its instructions, the files a create adds, and whether GitHub lets it"
|
|
2249
|
+
},
|
|
2168
2250
|
{
|
|
2169
2251
|
"command": [
|
|
2170
2252
|
"local",
|
|
@@ -2271,6 +2353,26 @@ export const COMMANDS = [
|
|
|
2271
2353
|
"raw": false,
|
|
2272
2354
|
"summary": "Settings → Computers: the kinds of computer this server offers, each provider and whether its keys are saved"
|
|
2273
2355
|
},
|
|
2356
|
+
{
|
|
2357
|
+
"command": [
|
|
2358
|
+
"local",
|
|
2359
|
+
"list-git-hub-repositories"
|
|
2360
|
+
],
|
|
2361
|
+
"operationId": "listGitHubRepositories",
|
|
2362
|
+
"method": "GET",
|
|
2363
|
+
"path": "/integrations/github/repositories",
|
|
2364
|
+
"pathParams": [],
|
|
2365
|
+
"multiSegment": [],
|
|
2366
|
+
"query": [],
|
|
2367
|
+
"headers": [],
|
|
2368
|
+
"bodyFlags": [],
|
|
2369
|
+
"hasBody": false,
|
|
2370
|
+
"bodyRequired": false,
|
|
2371
|
+
"bodyTypes": [],
|
|
2372
|
+
"secretBody": false,
|
|
2373
|
+
"raw": false,
|
|
2374
|
+
"summary": "The repositories this server's GitHub App is installed on"
|
|
2375
|
+
},
|
|
2274
2376
|
{
|
|
2275
2377
|
"command": [
|
|
2276
2378
|
"local",
|
|
@@ -2291,6 +2393,45 @@ export const COMMANDS = [
|
|
|
2291
2393
|
"raw": false,
|
|
2292
2394
|
"summary": "The names of the MCP servers saved here, and nothing else of them"
|
|
2293
2395
|
},
|
|
2396
|
+
{
|
|
2397
|
+
"command": [
|
|
2398
|
+
"local",
|
|
2399
|
+
"list-suggestions"
|
|
2400
|
+
],
|
|
2401
|
+
"operationId": "listSuggestions",
|
|
2402
|
+
"method": "GET",
|
|
2403
|
+
"path": "/suggestions",
|
|
2404
|
+
"pathParams": [],
|
|
2405
|
+
"multiSegment": [],
|
|
2406
|
+
"query": [
|
|
2407
|
+
{
|
|
2408
|
+
"name": "repo",
|
|
2409
|
+
"type": "string",
|
|
2410
|
+
"required": false,
|
|
2411
|
+
"description": "owner/name: one repository's alone."
|
|
2412
|
+
},
|
|
2413
|
+
{
|
|
2414
|
+
"name": "status",
|
|
2415
|
+
"type": "string",
|
|
2416
|
+
"enum": [
|
|
2417
|
+
"open",
|
|
2418
|
+
"created",
|
|
2419
|
+
"discarded",
|
|
2420
|
+
"all"
|
|
2421
|
+
],
|
|
2422
|
+
"required": false,
|
|
2423
|
+
"description": ""
|
|
2424
|
+
}
|
|
2425
|
+
],
|
|
2426
|
+
"headers": [],
|
|
2427
|
+
"bodyFlags": [],
|
|
2428
|
+
"hasBody": false,
|
|
2429
|
+
"bodyRequired": false,
|
|
2430
|
+
"bodyTypes": [],
|
|
2431
|
+
"secretBody": false,
|
|
2432
|
+
"raw": false,
|
|
2433
|
+
"summary": "Suggested agents: each repository's scan and the agents it suggests"
|
|
2434
|
+
},
|
|
2294
2435
|
{
|
|
2295
2436
|
"command": [
|
|
2296
2437
|
"local",
|
|
@@ -2315,6 +2456,28 @@ export const COMMANDS = [
|
|
|
2315
2456
|
"raw": false,
|
|
2316
2457
|
"summary": "Fire a Composio trigger: a request it checks, no token"
|
|
2317
2458
|
},
|
|
2459
|
+
{
|
|
2460
|
+
"command": [
|
|
2461
|
+
"local",
|
|
2462
|
+
"restore-suggestion"
|
|
2463
|
+
],
|
|
2464
|
+
"operationId": "restoreSuggestion",
|
|
2465
|
+
"method": "POST",
|
|
2466
|
+
"path": "/suggestions/{suggestion_id}/restore",
|
|
2467
|
+
"pathParams": [
|
|
2468
|
+
"suggestion_id"
|
|
2469
|
+
],
|
|
2470
|
+
"multiSegment": [],
|
|
2471
|
+
"query": [],
|
|
2472
|
+
"headers": [],
|
|
2473
|
+
"bodyFlags": [],
|
|
2474
|
+
"hasBody": false,
|
|
2475
|
+
"bodyRequired": false,
|
|
2476
|
+
"bodyTypes": [],
|
|
2477
|
+
"secretBody": false,
|
|
2478
|
+
"raw": false,
|
|
2479
|
+
"summary": "Bring a discarded suggestion back (an undo)"
|
|
2480
|
+
},
|
|
2318
2481
|
{
|
|
2319
2482
|
"command": [
|
|
2320
2483
|
"local",
|
|
@@ -2337,6 +2500,35 @@ export const COMMANDS = [
|
|
|
2337
2500
|
"raw": false,
|
|
2338
2501
|
"summary": "Rotate the Composio project's webhook subscription's secret, and keep the new one"
|
|
2339
2502
|
},
|
|
2503
|
+
{
|
|
2504
|
+
"command": [
|
|
2505
|
+
"local",
|
|
2506
|
+
"scan-for-suggestions"
|
|
2507
|
+
],
|
|
2508
|
+
"operationId": "scanForSuggestions",
|
|
2509
|
+
"method": "POST",
|
|
2510
|
+
"path": "/suggestions/scans",
|
|
2511
|
+
"pathParams": [],
|
|
2512
|
+
"multiSegment": [],
|
|
2513
|
+
"query": [],
|
|
2514
|
+
"headers": [],
|
|
2515
|
+
"bodyFlags": [
|
|
2516
|
+
{
|
|
2517
|
+
"name": "repo",
|
|
2518
|
+
"type": "string",
|
|
2519
|
+
"required": true,
|
|
2520
|
+
"description": "owner/name, or its https://github.com URL."
|
|
2521
|
+
}
|
|
2522
|
+
],
|
|
2523
|
+
"hasBody": true,
|
|
2524
|
+
"bodyRequired": true,
|
|
2525
|
+
"bodyTypes": [
|
|
2526
|
+
"application/json"
|
|
2527
|
+
],
|
|
2528
|
+
"secretBody": false,
|
|
2529
|
+
"raw": false,
|
|
2530
|
+
"summary": "Scan a repository for places its app needs an agent"
|
|
2531
|
+
},
|
|
2340
2532
|
{
|
|
2341
2533
|
"command": [
|
|
2342
2534
|
"local",
|
package/lib/device.mjs
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
|
-
// Device sign-in (RFC 8628) for `agentrun login
|
|
1
|
+
// Device sign-in (RFC 8628) for `agentrun login`, used when the target's GET /v2/capabilities offers it:
|
|
2
2
|
// `sign_in.device`, the metadata's URL and the scope to ask for. The person opens the address printed, enters the code
|
|
3
3
|
// and approves there; the token endpoint then answers a token, which login keeps where it keeps a pasted one. Every URL
|
|
4
4
|
// fetched is on the target's own origin, over https unless the target is on this machine; no redirect is followed; each
|
|
5
|
-
// answer's size and shape are checked before any of it is used.
|
|
6
|
-
//
|
|
5
|
+
// answer's size and shape are checked before any of it is used. Every request names this CLI and its version
|
|
6
|
+
// (User-Agent), so the page that approves a code can say what asked for it. The flow's first line names the server
|
|
7
|
+
// signed in to, and a line says so when the address to open is on another origin. The device code and the token are
|
|
8
|
+
// never printed, never in an error and never in argv.
|
|
9
|
+
import { readFileSync } from "node:fs";
|
|
10
|
+
import { CLOUD_CONSOLE, CLOUD_URL } from "./target.mjs";
|
|
11
|
+
|
|
12
|
+
/** What each request of the flow names itself: this package and its version. */
|
|
13
|
+
const USER_AGENT = `agentrun-cli/${JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version}`;
|
|
7
14
|
|
|
8
15
|
/** A sign-in that stopped: its exit code (cli.mjs's), and words of this CLI's own, never a server's answer. */
|
|
9
16
|
export class SignInError extends Error {
|
|
@@ -66,13 +73,14 @@ async function capped(response, max) {
|
|
|
66
73
|
}
|
|
67
74
|
|
|
68
75
|
/** One request, never redirected: `{ status, redirect }` for a 3xx, else `{ status, body, retryAfter }`, body the answer's
|
|
69
|
-
* JSON object (undefined when it holds none or is past `max`)
|
|
70
|
-
|
|
76
|
+
* JSON object (undefined when it holds none or is past `max`), retryAfter its Retry-After from `now`. A request that
|
|
77
|
+
* fails throws as fetch does. */
|
|
78
|
+
async function ask(url, { form, max = ANSWER_BYTES, ms = REQUEST_MS, now = Date.now } = {}) {
|
|
71
79
|
const response = await fetch(url, {
|
|
72
80
|
method: form ? "POST" : "GET",
|
|
73
81
|
redirect: "manual",
|
|
74
82
|
signal: AbortSignal.timeout(ms),
|
|
75
|
-
headers: { accept: "application/json", ...(form ? { "content-type": "application/x-www-form-urlencoded" } : {}) },
|
|
83
|
+
headers: { accept: "application/json", "user-agent": USER_AGENT, ...(form ? { "content-type": "application/x-www-form-urlencoded" } : {}) },
|
|
76
84
|
...(form ? { body: new URLSearchParams(form).toString() } : {}),
|
|
77
85
|
});
|
|
78
86
|
if (response.status >= 300 && response.status < 400) return await response.body?.cancel(), { status: response.status, redirect: true };
|
|
@@ -83,7 +91,7 @@ async function ask(url, { form, max = ANSWER_BYTES, ms = REQUEST_MS } = {}) {
|
|
|
83
91
|
} catch {
|
|
84
92
|
body = undefined;
|
|
85
93
|
}
|
|
86
|
-
return { status: response.status, body: OBJECT(body) ? body : undefined, retryAfter: retryAfterMs(response.headers.get("retry-after")) };
|
|
94
|
+
return { status: response.status, body: OBJECT(body) ? body : undefined, retryAfter: retryAfterMs(response.headers.get("retry-after"), now()) };
|
|
87
95
|
}
|
|
88
96
|
|
|
89
97
|
/** A Retry-After header's wait in ms from `now` (RFC 9110 10.2.3: delay seconds, or an HTTP date), 0 for anything else
|
|
@@ -132,36 +140,56 @@ export function deviceOffer(capabilities, base) {
|
|
|
132
140
|
return { metadata, scope };
|
|
133
141
|
}
|
|
134
142
|
|
|
143
|
+
/** AgentRun cloud's API and the origin of its device page, its console: the one pair the cross-origin line is not said
|
|
144
|
+
* for. It is exempt from that line alone, never from a check. */
|
|
145
|
+
const CLOUD_PAIR = { api: new URL(CLOUD_URL).origin, page: new URL(CLOUD_CONSOLE).origin };
|
|
146
|
+
|
|
147
|
+
/** The origins the person is told the code is approved at: those of `addresses` (the ones printed to open, any of them
|
|
148
|
+
* null when absent) other than the target's, each once. An address on another origin is taken, not refused: a
|
|
149
|
+
* self-hosted install may serve its console on another origin, and this CLI cannot know which. So the line names both
|
|
150
|
+
* origins, and a server that hands out another service's code, to keep the token approved there, is seen before the
|
|
151
|
+
* code is approved. Cloud's API with its device page on its console is the known pair, named by neither: a warning
|
|
152
|
+
* on every cloud sign-in would teach people to skip it. */
|
|
153
|
+
export function elsewhereOf(target, addresses) {
|
|
154
|
+
const own = new URL(target).origin;
|
|
155
|
+
const known = (origin) => own === CLOUD_PAIR.api && origin === CLOUD_PAIR.page;
|
|
156
|
+
return [...new Set(addresses.filter((at) => at != null).map((at) => new URL(at).origin))].filter((origin) => origin !== own && !known(origin));
|
|
157
|
+
}
|
|
158
|
+
|
|
135
159
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
136
160
|
|
|
137
161
|
/** The device flow for `offer` on the target `base`, its lines to the person on `io.stderr`: the token, once the person
|
|
138
|
-
* approved. Every
|
|
139
|
-
|
|
162
|
+
* approved. Every wait is `wait(ms)`'s and every reading of the time `now()`'s (a test's fake clock). Every refusal is a
|
|
163
|
+
* SignInError that says nothing was written. */
|
|
164
|
+
export async function deviceSignIn(base, offer, io, { wait = sleep, now = Date.now } = {}) {
|
|
140
165
|
const target = new URL(base);
|
|
166
|
+
// The server first, before anything else of the flow: a server named by a stale or wrong AGENTRUN_BASE_URL is seen
|
|
167
|
+
// before any code is approved.
|
|
168
|
+
io.stderr.write(`Signing in to ${target.origin}.\n`);
|
|
141
169
|
const unreached = (url, error) => refuse(3, `Cannot reach ${url.origin} for the device sign-in (${why(error)}); ${NOTHING}.`);
|
|
142
170
|
|
|
143
171
|
let meta;
|
|
144
172
|
try {
|
|
145
|
-
meta = await ask(offer.metadata);
|
|
173
|
+
meta = await ask(offer.metadata, { now });
|
|
146
174
|
} catch (error) {
|
|
147
175
|
throw unreached(offer.metadata, error);
|
|
148
176
|
}
|
|
149
177
|
if (meta.redirect) throw bad(`metadata answered with a redirect (${meta.status}), which this CLI never follows`);
|
|
150
178
|
if (meta.status !== 200 || !meta.body) throw bad(`metadata answered ${meta.status}${meta.body ? "" : ", not a JSON object (or one too large)"}`);
|
|
179
|
+
// Only the fields the flow uses: the scope it asks for is the capabilities' (offer.scope), and no issuer is read.
|
|
151
180
|
const m = meta.body;
|
|
152
|
-
if (["
|
|
181
|
+
if (["client_id", "device_authorization_endpoint", "token_endpoint", "resource"].some((field) => typeof m[field] !== "string" || !VISIBLE.test(m[field]))) {
|
|
153
182
|
throw bad("metadata lacks a field it needs, or holds one this CLI does not take");
|
|
154
183
|
}
|
|
155
|
-
const issuer = urlOf(m.issuer, target);
|
|
156
184
|
const authorization = urlOf(m.device_authorization_endpoint, target);
|
|
157
185
|
const tokenAt = urlOf(m.token_endpoint, target);
|
|
158
|
-
if (!
|
|
186
|
+
if (!authorization || !tokenAt) throw bad("metadata names an endpoint that is off the server's own origin or not over https");
|
|
159
187
|
if (m.verification_uri != null && !urlOf(m.verification_uri, target, { query: true, elsewhere: true })) throw bad("metadata's verification_uri is not an https URL");
|
|
160
188
|
|
|
161
|
-
const started =
|
|
189
|
+
const started = now();
|
|
162
190
|
let granted;
|
|
163
191
|
try {
|
|
164
|
-
granted = await ask(authorization, { form: { client_id: m.client_id, scope: offer.scope, audience: m.resource } });
|
|
192
|
+
granted = await ask(authorization, { form: { client_id: m.client_id, scope: offer.scope, audience: m.resource }, now });
|
|
165
193
|
} catch (error) {
|
|
166
194
|
throw unreached(authorization, error);
|
|
167
195
|
}
|
|
@@ -182,20 +210,22 @@ export async function deviceSignIn(base, offer, io) {
|
|
|
182
210
|
|
|
183
211
|
// The metadata's verification_uri first, when it names one, as the open-source connector's client does.
|
|
184
212
|
const open = m.verification_uri ?? g.verification_uri;
|
|
213
|
+
const elsewhere = elsewhereOf(target, [open, g.verification_uri_complete]);
|
|
214
|
+
if (elsewhere.length) io.stderr.write(`The code is approved at ${elsewhere.join(" and ")}, not at ${target.origin}. Approve it only if ${target.origin} is the server you meant to sign in to.\n`);
|
|
185
215
|
io.stderr.write(`Open ${open} and enter the code ${g.user_code}${g.verification_uri_complete ? ` (or open ${g.verification_uri_complete})` : ""}.\n`);
|
|
186
216
|
io.stderr.write(`Waiting for the sign-in to be approved there; the code expires in ${Math.ceil(g.expires_in / 60)} min.\n`);
|
|
187
217
|
|
|
188
218
|
const deadline = started + g.expires_in * 1000;
|
|
189
|
-
const expired = () => refuse(4, `The code expired before the sign-in was approved; ${NOTHING}. Run agentrun login
|
|
219
|
+
const expired = () => refuse(4, `The code expired before the sign-in was approved; ${NOTHING}. Run agentrun login again.`);
|
|
190
220
|
let every = interval * 1000;
|
|
191
221
|
let delay = every;
|
|
192
222
|
for (;;) {
|
|
193
|
-
if (
|
|
194
|
-
await
|
|
195
|
-
if (
|
|
223
|
+
if (now() >= deadline) throw expired();
|
|
224
|
+
await wait(Math.min(delay, deadline - now()));
|
|
225
|
+
if (now() >= deadline) throw expired();
|
|
196
226
|
let answer;
|
|
197
227
|
try {
|
|
198
|
-
answer = await ask(tokenAt, { form: { grant_type: GRANT_TYPE, device_code: g.device_code, client_id: m.client_id, audience: m.resource }, ms: Math.max(1, Math.min(REQUEST_MS, deadline -
|
|
228
|
+
answer = await ask(tokenAt, { form: { grant_type: GRANT_TYPE, device_code: g.device_code, client_id: m.client_id, audience: m.resource }, ms: Math.max(1, Math.min(REQUEST_MS, deadline - now())), now });
|
|
199
229
|
} catch {
|
|
200
230
|
// Not reached this time (a dropped connection, a timeout): wait longer, until the code expires.
|
|
201
231
|
delay = Math.max(every, Math.min(BACKOFF_MS, delay * 2));
|
package/lib/login.mjs
CHANGED
|
@@ -170,25 +170,39 @@ export const LOGIN = {
|
|
|
170
170
|
route: "GET /capabilities, then its device sign-in; else GET /agents?limit=1, to check a token from stdin",
|
|
171
171
|
help: [
|
|
172
172
|
["--to URL|cloud", `the server, /v2 added when its address lacks it; cloud is AgentRun cloud (AGENTRUN_CLOUD_URL, else ${CLOUD_URL}). When its capabilities offer a device sign-in, prints an address and a code to approve there, else reads the token from stdin`],
|
|
173
|
-
["--base-url URL", "the server's API, ending /v2 (default AGENTRUN_BASE_URL); the token from stdin"],
|
|
173
|
+
["--base-url URL", "the server's API, ending /v2 (default AGENTRUN_BASE_URL); the token from stdin, or on a terminal a device sign-in when the server offers one"],
|
|
174
174
|
["(stdin)", "the token: agentrun login --base-url URL < FILE"],
|
|
175
175
|
],
|
|
176
176
|
options: { to: { type: "string" } },
|
|
177
177
|
async run({ values, env, io, cli }) {
|
|
178
178
|
if (values.to !== undefined && values["base-url"] !== undefined) throw cli.fail(2, "agentrun login takes the server once: --to or --base-url, not both.");
|
|
179
|
+
const named = values.to !== undefined;
|
|
179
180
|
const flagged = values["base-url"] !== undefined;
|
|
180
|
-
const given =
|
|
181
|
+
const given = named ? toUrl(values.to, env) : flagged ? values["base-url"] : env.AGENTRUN_BASE_URL;
|
|
181
182
|
if (given === undefined) throw cli.fail(2, "agentrun login needs the server: --to URL, --base-url URL (its API, ending /v2) or AGENTRUN_BASE_URL.");
|
|
182
|
-
const base = cli.baseOf(given,
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
183
|
+
const base = cli.baseOf(given, named ? "--to" : flagged ? "--base-url" : "AGENTRUN_BASE_URL");
|
|
184
|
+
// The device sign-in, when the server offers one: for --to, and for a server named otherwise when stdin is a
|
|
185
|
+
// terminal, which can hold no token (off one, stdin holds the token, as a script gives it). A SignInError's words
|
|
186
|
+
// are this CLI's own and say nothing was written. The token it ends with is the server's own answer from its own
|
|
187
|
+
// origin, so it is kept as it is.
|
|
188
|
+
if (named || io.stdin.isTTY) {
|
|
189
|
+
let offer;
|
|
186
190
|
try {
|
|
187
|
-
|
|
188
|
-
if (offer) return keep(base, await deviceSignIn(base, offer, io), env, io, cli);
|
|
191
|
+
offer = deviceOffer(await capabilitiesOf(base), base);
|
|
189
192
|
} catch (error) {
|
|
190
|
-
if (error instanceof SignInError) throw
|
|
191
|
-
throw error;
|
|
193
|
+
if (!(error instanceof SignInError)) throw error;
|
|
194
|
+
if (named) throw cli.fail(error.code, error.message);
|
|
195
|
+
// A server named otherwise that offers a sign-in this CLI does not take, or is not reached: why, then the
|
|
196
|
+
// refusal below of a token typed on a terminal, exit 2 as for a server that offers none.
|
|
197
|
+
io.stderr.write(`${error.message}\n`);
|
|
198
|
+
}
|
|
199
|
+
if (offer) {
|
|
200
|
+
try {
|
|
201
|
+
return keep(base, await deviceSignIn(base, offer, io), env, io, cli);
|
|
202
|
+
} catch (error) {
|
|
203
|
+
if (error instanceof SignInError) throw cli.fail(error.code, error.message);
|
|
204
|
+
throw error;
|
|
205
|
+
}
|
|
192
206
|
}
|
|
193
207
|
}
|
|
194
208
|
const token = (await readSecret(io, cli.fail, "The token", "agentrun login --base-url URL < FILE")).trim();
|
package/lib/target.mjs
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
|
|
4
4
|
/** AgentRun cloud's address, which `--to cloud` names unless AGENTRUN_CLOUD_URL names another. */
|
|
5
5
|
export const CLOUD_URL = "https://api.agentrun.ai";
|
|
6
|
+
/** AgentRun cloud's console, where cloud's device sign-in page is. */
|
|
7
|
+
export const CLOUD_CONSOLE = "https://console.agentrun.ai";
|
|
6
8
|
|
|
7
9
|
/** The API base a `--to` names, ending /v2: `cloud` is AGENTRUN_CLOUD_URL, else CLOUD_URL; an address whose path does
|
|
8
10
|
* not end /v2 gets it appended. The caller checks the result as every base URL is checked (cli.mjs baseOf), so a query,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcha/agentrun",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.22",
|
|
4
4
|
"description": "AgentRun, the open-source platform that supercharges your agents (self-improvement, durable execution and a control plane on top of your favorite agent harness), on this machine with one command: npx @parcha/agentrun",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"NOTICE"
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@parcha/agentrun-serve": "0.1.0-beta.
|
|
20
|
+
"@parcha/agentrun-serve": "0.1.0-beta.54"
|
|
21
21
|
},
|
|
22
22
|
"scripts": {
|
|
23
23
|
"test": "node --test 'test/*.test.mjs'"
|
|
@@ -143,7 +143,7 @@ Two clients call the same API from code, with the same server and token. `@parch
|
|
|
143
143
|
- `agentrun harness-check`: Run a recipe's installed agent for real and check it (tools off, env allowlist, pins, limits, no side requests, resume, a denied call, an MCP tool): a JSON report and three facts. Real models cost money
|
|
144
144
|
- `agentrun home`: delete, list, read, write
|
|
145
145
|
- `agentrun learning`: corrections, cost, get, log, read, replay, reset, retire, workflow-revisions, write-corrections
|
|
146
|
-
- `agentrun local`: create-pairing, delete-composio-subscription, delete-computer, delete-workspace-archil, disconnect-git-hub, get-git-hub-connection, get-model-gateway, get-workspace-archil, list-composio-events, list-composio-triggers, list-computer-choices, list-computers, list-mcp-server-names, receive-hook-composio, rotate-composio-secret, test-computer, test-workspace-archil
|
|
146
|
+
- `agentrun local`: create-pairing, create-suggested-agent, delete-composio-subscription, delete-computer, delete-workspace-archil, discard-suggestion, disconnect-git-hub, get-git-hub-connection, get-model-gateway, get-suggestion, get-workspace-archil, list-composio-events, list-composio-triggers, list-computer-choices, list-computers, list-git-hub-repositories, list-mcp-server-names, list-suggestions, receive-hook-composio, restore-suggestion, rotate-composio-secret, scan-for-suggestions, test-computer, test-workspace-archil
|
|
147
147
|
- `agentrun login`: Sign in to a server, with a device code when it offers one, else a token read from stdin, and keep the token with the server's address in the config file
|
|
148
148
|
- `agentrun logout`: Remove the config file login wrote, its address and token
|
|
149
149
|
- `agentrun mcp-servers`: delete, get, list, oauth-client, private-hosts, refresh
|
|
@@ -671,6 +671,16 @@ A code that pairs a person's own computer with this server.
|
|
|
671
671
|
|
|
672
672
|
Route: `POST /computers/pairings`.
|
|
673
673
|
|
|
674
|
+
### `agentrun local create-suggested-agent SUGGESTION_ID`
|
|
675
|
+
|
|
676
|
+
Create a suggested agent: a branch with its package and client, the agent made here, and a pull request.
|
|
677
|
+
|
|
678
|
+
Route: `POST /suggestions/{suggestion_id}/create`.
|
|
679
|
+
|
|
680
|
+
- `--name STRING` (string): The agent's name, in place of the suggestion's.
|
|
681
|
+
- `--body JSON|@FILE|-` (application/json): The whole body: inline, from a file or from stdin. The flags above win over a JSON body's fields.
|
|
682
|
+
- `--body-type TYPE` (string): The body's type, one of application/json; any other than JSON is sent as given.
|
|
683
|
+
|
|
674
684
|
### `agentrun local delete-composio-subscription NAME`
|
|
675
685
|
|
|
676
686
|
Delete the Composio project's webhook subscription, once no trigger uses it.
|
|
@@ -689,6 +699,12 @@ Turn Mode 2 off: run folders on this server's own disk.
|
|
|
689
699
|
|
|
690
700
|
Route: `DELETE /workspace/archil`.
|
|
691
701
|
|
|
702
|
+
### `agentrun local discard-suggestion SUGGESTION_ID`
|
|
703
|
+
|
|
704
|
+
Discard a suggested agent: it goes away, and later scans leave it out.
|
|
705
|
+
|
|
706
|
+
Route: `POST /suggestions/{suggestion_id}/discard`.
|
|
707
|
+
|
|
692
708
|
### `agentrun local disconnect-git-hub`
|
|
693
709
|
|
|
694
710
|
Disconnect GitHub: the App's credentials gone from this server, and every github trigger off.
|
|
@@ -707,6 +723,14 @@ The model gateway in force: the environment's, the one saved here, or none.
|
|
|
707
723
|
|
|
708
724
|
Route: `GET /settings/model-gateway`.
|
|
709
725
|
|
|
726
|
+
### `agentrun local get-suggestion SUGGESTION_ID`
|
|
727
|
+
|
|
728
|
+
One suggested agent whole: its instructions, the files a create adds, and whether GitHub lets it.
|
|
729
|
+
|
|
730
|
+
Route: `GET /suggestions/{suggestion_id}`.
|
|
731
|
+
|
|
732
|
+
- `--name STRING` (string): The agent's name a create would be sent (`POST .../create` `name`): `files` are rendered with it, as the create pushes them. 422 when it is not 3 to 60 characters.
|
|
733
|
+
|
|
710
734
|
### `agentrun local get-workspace-archil`
|
|
711
735
|
|
|
712
736
|
Whether run folders are on Archil disks (Mode 2), the settings, and whether its keys are saved.
|
|
@@ -737,12 +761,27 @@ Settings → Computers: the kinds of computer this server offers, each provider
|
|
|
737
761
|
|
|
738
762
|
Route: `GET /computers`.
|
|
739
763
|
|
|
764
|
+
### `agentrun local list-git-hub-repositories`
|
|
765
|
+
|
|
766
|
+
The repositories this server's GitHub App is installed on.
|
|
767
|
+
|
|
768
|
+
Route: `GET /integrations/github/repositories`.
|
|
769
|
+
|
|
740
770
|
### `agentrun local list-mcp-server-names`
|
|
741
771
|
|
|
742
772
|
The names of the MCP servers saved here, and nothing else of them.
|
|
743
773
|
|
|
744
774
|
Route: `GET /settings/mcp-server-names`.
|
|
745
775
|
|
|
776
|
+
### `agentrun local list-suggestions`
|
|
777
|
+
|
|
778
|
+
Suggested agents: each repository's scan and the agents it suggests.
|
|
779
|
+
|
|
780
|
+
Route: `GET /suggestions`.
|
|
781
|
+
|
|
782
|
+
- `--repo STRING` (string): owner/name: one repository's alone.
|
|
783
|
+
- `--status open|created|discarded|all` (string, one of these)
|
|
784
|
+
|
|
746
785
|
### `agentrun local receive-hook-composio HOOK`
|
|
747
786
|
|
|
748
787
|
Fire a Composio trigger: a request it checks, no token.
|
|
@@ -752,12 +791,28 @@ Route: `POST /hooks/composio/{hook}`.
|
|
|
752
791
|
- `--body JSON|@FILE|-` (`*/*`, required): The whole body: inline, from a file or from stdin. The flags above win over a JSON body's fields.
|
|
753
792
|
- `--body-type TYPE` (string): The body's type, one of `*/*`; any other than JSON is sent as given.
|
|
754
793
|
|
|
794
|
+
### `agentrun local restore-suggestion SUGGESTION_ID`
|
|
795
|
+
|
|
796
|
+
Bring a discarded suggestion back (an undo).
|
|
797
|
+
|
|
798
|
+
Route: `POST /suggestions/{suggestion_id}/restore`.
|
|
799
|
+
|
|
755
800
|
### `agentrun local rotate-composio-secret NAME`
|
|
756
801
|
|
|
757
802
|
Rotate the Composio project's webhook subscription's secret, and keep the new one.
|
|
758
803
|
|
|
759
804
|
Route: `POST /settings/mcp-servers/{name}/composio/rotate-secret`.
|
|
760
805
|
|
|
806
|
+
### `agentrun local scan-for-suggestions`
|
|
807
|
+
|
|
808
|
+
Scan a repository for places its app needs an agent.
|
|
809
|
+
|
|
810
|
+
Route: `POST /suggestions/scans`.
|
|
811
|
+
|
|
812
|
+
- `--repo STRING` (string, required): owner/name, or its https://github.com URL.
|
|
813
|
+
- `--body JSON|@FILE|-` (application/json, required): The whole body: inline, from a file or from stdin. The flags above win over a JSON body's fields.
|
|
814
|
+
- `--body-type TYPE` (string): The body's type, one of application/json; any other than JSON is sent as given.
|
|
815
|
+
|
|
761
816
|
### `agentrun local test-computer PROVIDER`
|
|
762
817
|
|
|
763
818
|
Test a computer provider's account with its saved keys.
|
|
@@ -779,7 +834,7 @@ Sign in to a server, with a device code when it offers one, else a token read fr
|
|
|
779
834
|
Route: `GET /capabilities, then its device sign-in; else GET /agents?limit=1, to check a token from stdin`.
|
|
780
835
|
|
|
781
836
|
- `--to URL|cloud` (string, this CLI's own): the server, /v2 added when its address lacks it; cloud is AgentRun cloud (AGENTRUN_CLOUD_URL, else https://api.agentrun.ai). When its capabilities offer a device sign-in, prints an address and a code to approve there, else reads the token from stdin
|
|
782
|
-
- `--base-url URL` (string, this CLI's own): the server's API, ending /v2 (default AGENTRUN_BASE_URL); the token from stdin
|
|
837
|
+
- `--base-url URL` (string, this CLI's own): the server's API, ending /v2 (default AGENTRUN_BASE_URL); the token from stdin, or on a terminal a device sign-in when the server offers one
|
|
783
838
|
|
|
784
839
|
## logout
|
|
785
840
|
|