@agentgates/cli 0.74.0 → 0.83.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.
Files changed (3) hide show
  1. package/README.md +31 -0
  2. package/dist/cli.mjs +1465 -418
  3. package/package.json +6 -2
package/dist/cli.mjs CHANGED
@@ -982,7 +982,7 @@ var require_command = __commonJS({
982
982
  var EventEmitter = __require("node:events").EventEmitter;
983
983
  var childProcess2 = __require("node:child_process");
984
984
  var path8 = __require("node:path");
985
- var fs10 = __require("node:fs");
985
+ var fs11 = __require("node:fs");
986
986
  var process8 = __require("node:process");
987
987
  var { Argument: Argument2, humanReadableArgName } = require_argument();
988
988
  var { CommanderError: CommanderError2 } = require_error();
@@ -1915,10 +1915,10 @@ Expecting one of '${allowedValues.join("', '")}'`);
1915
1915
  const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
1916
1916
  function findFile2(baseDir, baseName2) {
1917
1917
  const localBin = path8.resolve(baseDir, baseName2);
1918
- if (fs10.existsSync(localBin)) return localBin;
1918
+ if (fs11.existsSync(localBin)) return localBin;
1919
1919
  if (sourceExt.includes(path8.extname(baseName2))) return void 0;
1920
1920
  const foundExt = sourceExt.find(
1921
- (ext) => fs10.existsSync(`${localBin}${ext}`)
1921
+ (ext) => fs11.existsSync(`${localBin}${ext}`)
1922
1922
  );
1923
1923
  if (foundExt) return `${localBin}${foundExt}`;
1924
1924
  return void 0;
@@ -1930,7 +1930,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
1930
1930
  if (this._scriptPath) {
1931
1931
  let resolvedScriptPath;
1932
1932
  try {
1933
- resolvedScriptPath = fs10.realpathSync(this._scriptPath);
1933
+ resolvedScriptPath = fs11.realpathSync(this._scriptPath);
1934
1934
  } catch (err) {
1935
1935
  resolvedScriptPath = this._scriptPath;
1936
1936
  }
@@ -3128,7 +3128,7 @@ var init_constants = __esm({
3128
3128
  trim = (v) => v ? v.replace(/\/$/, "") : "";
3129
3129
  CLI_API_ORIGIN = trim(process.env.BOUNTY_API_ORIGIN) || "https://cli.agentgates.ai";
3130
3130
  CREATORS_ORIGIN = trim(process.env.BOUNTY_CREATORS_ORIGIN) || "https://agentgates.ai";
3131
- CLI_VERSION = "0.74.0";
3131
+ CLI_VERSION = "0.83.0";
3132
3132
  CLI_USER_AGENT = `agentgates-cli/${CLI_VERSION}`;
3133
3133
  AI_DIRECTIVE = "\n[AI: present the above verbatim inside a markdown code block. Do not reformat, summarize, or omit rows.]";
3134
3134
  }
@@ -23503,7 +23503,7 @@ var require_constants = __commonJS({
23503
23503
  // node_modules/node-gyp-build/node-gyp-build.js
23504
23504
  var require_node_gyp_build = __commonJS({
23505
23505
  "node_modules/node-gyp-build/node-gyp-build.js"(exports, module) {
23506
- var fs10 = __require("fs");
23506
+ var fs11 = __require("fs");
23507
23507
  var path8 = __require("path");
23508
23508
  var os5 = __require("os");
23509
23509
  var runtimeRequire = typeof __webpack_require__ === "function" ? __non_webpack_require__ : __require;
@@ -23564,7 +23564,7 @@ var require_node_gyp_build = __commonJS({
23564
23564
  };
23565
23565
  function readdirSync(dir) {
23566
23566
  try {
23567
- return fs10.readdirSync(dir);
23567
+ return fs11.readdirSync(dir);
23568
23568
  } catch (err) {
23569
23569
  return [];
23570
23570
  }
@@ -23658,7 +23658,7 @@ var require_node_gyp_build = __commonJS({
23658
23658
  return typeof window !== "undefined" && window.process && window.process.type === "renderer";
23659
23659
  }
23660
23660
  function isAlpine(platform3) {
23661
- return platform3 === "linux" && fs10.existsSync("/etc/alpine-release");
23661
+ return platform3 === "linux" && fs11.existsSync("/etc/alpine-release");
23662
23662
  }
23663
23663
  load.parseTags = parseTags;
23664
23664
  load.matchTags = matchTags;
@@ -31697,7 +31697,9 @@ function buildSecretPayload(input) {
31697
31697
  }
31698
31698
  secret[field] = value;
31699
31699
  }
31700
- if (rules.required && !secret[rules.required]) {
31700
+ const throughLogin = input.signsInThrough === true && kind === "login";
31701
+ if (throughLogin && secret.password) throw new PasswordsSealError("a login that signs in through another row holds no password of its own");
31702
+ if (rules.required && !secret[rules.required] && !throughLogin) {
31701
31703
  throw new PasswordsSealError(`a ${kind} row needs its ${rules.required}`);
31702
31704
  }
31703
31705
  const hosts = validateHosts(input.hosts);
@@ -32678,7 +32680,7 @@ var init_passwords_wire = __esm({
32678
32680
  revokedNoticed = false;
32679
32681
  keyOnly = false;
32680
32682
  loginReading = null;
32681
- SIGNED_DOORS = /\/keys(\/(?!me\/)|$)|\/passwords\/[A-Za-z0-9_-]{1,64}\/use$|\/seal-key$|\/ag\/(?:agent|bindings)$|\/integrations(\/|$)/;
32683
+ SIGNED_DOORS = /\/keys(\/(?!me\/)|$)|\/passwords\/[A-Za-z0-9_-]{1,64}\/use$|\/seal-key$|\/ag\/(?:agent(?:\?turnOn=1)?|bindings)$|\/integrations(\/|$)/;
32682
32684
  PASSWORDS_BOX_APP_ID = "c8746c93771d337af3588872dcad76ddb1fccdb6";
32683
32685
  PASSWORDS_REPORT_DATA_LABEL = "agentgates/passwords/seal-key/v1";
32684
32686
  }
@@ -64599,7 +64601,7 @@ function shortAddress(addr) {
64599
64601
 
64600
64602
  // src/commands/onboard.ts
64601
64603
  var import_picocolors12 = __toESM(require_picocolors(), 1);
64602
- import { createInterface } from "node:readline/promises";
64604
+ import { createInterface as createInterface2 } from "node:readline/promises";
64603
64605
  init_constants();
64604
64606
 
64605
64607
  // src/lib/water.ts
@@ -64736,55 +64738,8 @@ function water() {
64736
64738
 
64737
64739
  // src/commands/compute.ts
64738
64740
  var import_picocolors3 = __toESM(require_picocolors(), 1);
64739
- var SITE = (process.env.AGENTGATES_ORIGIN || "https://agentgates.ai").replace(/\/$/, "");
64740
- var usd = (v) => `$${String(v).replace(/(\.\d\d\d?)0+$/, "$1")}`;
64741
- async function computePlans(opts) {
64742
- const res = await fetch(`${SITE}/api/compute/catalog`, { headers: { accept: "application/json" } });
64743
- if (!res.ok) throw new Error(`compute catalog: HTTP ${res.status}`);
64744
- const body = await res.json();
64745
- if (opts.json) {
64746
- process.stdout.write(JSON.stringify(body, null, 2) + "\n");
64747
- return;
64748
- }
64749
- const plans = body.plans ?? [];
64750
- if (plans.length === 0) {
64751
- process.stdout.write(` ${import_picocolors3.default.dim("No plans are on sale right now.")}
64752
- `);
64753
- return;
64754
- }
64755
- process.stdout.write(`
64756
- ${import_picocolors3.default.bold("CONFIDENTIAL VIRTUAL MACHINES")} ${import_picocolors3.default.dim("memory encrypted in use")}
64757
-
64758
- `);
64759
- for (const p of plans) {
64760
- const spec = `${p.vcpu} vCPU \xB7 ${Math.round(p.memoryMb / 1024)} GB \xB7 ${p.diskGb}GB disk`;
64761
- process.stdout.write(` ${import_picocolors3.default.bold(p.name.padEnd(10))} ${import_picocolors3.default.cyan(usd(p.priceUsdPerHour))}${import_picocolors3.default.dim("/hour")} ${import_picocolors3.default.dim(spec)}
64762
- `);
64763
- process.stdout.write(` ${import_picocolors3.default.dim(p.id.padEnd(10))} ${import_picocolors3.default.dim(`${p.egressQuotaGb} GB traffic`)}
64764
- `);
64765
- const ladder = p.pricing.map((r) => `${r.hoursPerPayment}h ${usd(r.totalUsd)}`).join(" ");
64766
- if (ladder) process.stdout.write(` ${import_picocolors3.default.dim(ladder)}
64767
- `);
64768
- process.stdout.write("\n");
64769
- }
64770
- const nets = body.payment?.networks ?? [];
64771
- if (nets.length) process.stdout.write(` ${import_picocolors3.default.dim(`USDC on ${nets.join(", ")}`)}
64772
-
64773
- `);
64774
- }
64775
- async function computeBuy() {
64776
- process.stdout.write(
64777
- `
64778
- Renting signs an x402 payment, and this CLI has no signer yet.
64779
- Buy from the wallet, one biometric: ${import_picocolors3.default.cyan(`${SITE}/compute`)}
64780
- Prices from here: ${import_picocolors3.default.dim("agentgates compute plans")}
64781
-
64782
- `
64783
- );
64784
- }
64785
-
64786
- // src/commands/inference.ts
64787
- var import_picocolors4 = __toESM(require_picocolors(), 1);
64741
+ import { promises as fs8 } from "node:fs";
64742
+ import { createInterface } from "node:readline/promises";
64788
64743
 
64789
64744
  // src/lib/passwords-key.ts
64790
64745
  init_lib2();
@@ -64966,9 +64921,6 @@ async function requirePasswordsKey() {
64966
64921
  return existing;
64967
64922
  }
64968
64923
 
64969
- // src/commands/inference.ts
64970
- init_passwords_wire();
64971
-
64972
64924
  // src/lib/x402-pay.ts
64973
64925
  init_lib2();
64974
64926
  var EVM_CHAINS = {
@@ -65060,7 +65012,7 @@ async function chooseLeg(body, address) {
65060
65012
  bestHeldMicro: bestHeld
65061
65013
  };
65062
65014
  }
65063
- function usd2(micro) {
65015
+ function usd(micro) {
65064
65016
  const neg = micro < 0n;
65065
65017
  const v = neg ? -micro : micro;
65066
65018
  const whole = v / 1000000n;
@@ -65105,9 +65057,683 @@ async function signLeg(leg, privateKey) {
65105
65057
  };
65106
65058
  }
65107
65059
 
65060
+ // src/lib/compute-wire.ts
65061
+ init_constants();
65062
+ init_passwords_wire();
65063
+ var trim3 = (v) => v ? v.trim().replace(/\/+$/, "") : "";
65064
+ function computeOrigin() {
65065
+ return trim3(process.env.AGENTGATES_COMPUTE_ORIGIN) || "https://api.agentgates.ai";
65066
+ }
65067
+ var DEPLOYMENTS_PATH = "/api/compute/deployments";
65068
+ var CATALOG_PATH = "/api/compute/catalog";
65069
+ var ID_RE = /^[A-Za-z0-9_-]{1,64}$/;
65070
+ function deploymentPath(id2, action) {
65071
+ const clean3 = String(id2 ?? "").trim();
65072
+ if (!ID_RE.test(clean3)) throw new Error(`"${id2}" is not a machine id (agentgates compute list shows yours)`);
65073
+ return `${DEPLOYMENTS_PATH}/${clean3}${action ? `/${action}` : ""}`;
65074
+ }
65075
+ function positiveInt(value, what) {
65076
+ const n2 = typeof value === "number" ? value : Number(String(value ?? "").trim());
65077
+ if (!Number.isInteger(n2) || n2 <= 0) throw new Error(`${what} must be a whole number above 0`);
65078
+ return n2;
65079
+ }
65080
+ var ENV_KEY_RE = /^[A-Za-z_][A-Za-z0-9_]{0,127}$/;
65081
+ function parseEnvPairs(pairs) {
65082
+ const out = {};
65083
+ for (const raw of pairs ?? []) {
65084
+ const at = raw.indexOf("=");
65085
+ const key = at > 0 ? raw.slice(0, at) : "";
65086
+ if (!ENV_KEY_RE.test(key)) {
65087
+ throw new Error(
65088
+ at > 0 ? `--env takes KEY=VALUE, and "${key.slice(0, 64)}" is not a variable name` : "--env takes KEY=VALUE: one --env has no NAME= in front (its text is not shown)"
65089
+ );
65090
+ }
65091
+ out[key] = raw.slice(at + 1);
65092
+ }
65093
+ return out;
65094
+ }
65095
+ function createBody(input) {
65096
+ const plan = (input.plan ?? "").trim();
65097
+ if (!plan) throw new Error("say which plan: --plan <id> (agentgates compute plans lists them)");
65098
+ const hours = positiveInt(input.hours, "--hours");
65099
+ const image = input.image?.trim();
65100
+ const compose = input.compose;
65101
+ if (image && compose !== void 0) throw new Error("send --image or --compose, not both");
65102
+ if (!image && (compose === void 0 || !compose.trim())) {
65103
+ throw new Error("say what runs: --image <image> (one container) or --compose <file> (a docker-compose.yml)");
65104
+ }
65105
+ const body = { plan, hours };
65106
+ if (image) {
65107
+ body.image = image;
65108
+ if (input.port !== void 0) {
65109
+ const port = positiveInt(input.port, "--port");
65110
+ if (port > 65535) throw new Error("--port must be a port number, 1 to 65535");
65111
+ body.port = port;
65112
+ }
65113
+ } else {
65114
+ if (input.port !== void 0) throw new Error("--port goes with --image; a compose publishes its own ports");
65115
+ body.compose = compose;
65116
+ }
65117
+ if (input.env && Object.keys(input.env).length > 0) body.env = input.env;
65118
+ const name = input.name?.trim();
65119
+ if (name) body.name = name;
65120
+ return body;
65121
+ }
65122
+ function legsOn(body, network) {
65123
+ const want = (network ?? "").trim().toLowerCase();
65124
+ if (!want) return body;
65125
+ return { ...body, accepts: (body.accepts ?? []).filter((leg) => (leg.network ?? "").toLowerCase() === want) };
65126
+ }
65127
+ function offeredNetworks(body) {
65128
+ return (body.accepts ?? []).map((leg) => leg.network ?? "?");
65129
+ }
65130
+ async function computeCall(args) {
65131
+ const f2 = args.fetchImpl ?? fetch;
65132
+ const res = await f2(args.url, {
65133
+ method: args.method,
65134
+ headers: {
65135
+ accept: "application/json",
65136
+ "user-agent": CLI_USER_AGENT,
65137
+ ...args.body !== void 0 ? { "content-type": "application/json" } : {},
65138
+ ...args.headers ?? {}
65139
+ },
65140
+ ...args.body !== void 0 ? { body: JSON.stringify(args.body) } : {},
65141
+ signal: AbortSignal.timeout(args.timeoutMs)
65142
+ });
65143
+ const text = await res.text().catch(() => "");
65144
+ let parsed = {};
65145
+ try {
65146
+ parsed = text ? JSON.parse(text) : {};
65147
+ } catch {
65148
+ parsed = { error: text.replace(/\s+/g, " ").trim().slice(0, 300) || `HTTP ${res.status}` };
65149
+ }
65150
+ const json2 = parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : { value: parsed };
65151
+ const retryAfter = Number(res.headers.get("retry-after"));
65152
+ return { status: res.status, json: json2, retryAfterSeconds: Number.isFinite(retryAfter) && retryAfter > 0 ? retryAfter : null };
65153
+ }
65154
+ function askPrice(url, body, fetchImpl) {
65155
+ return computeCall({ method: "POST", url, body, timeoutMs: 6e4, fetchImpl });
65156
+ }
65157
+ var BACKOFF_MS = [2e3, 4e3, 8e3, 15e3, 3e4];
65158
+ async function sendPaid(args) {
65159
+ const attempts = Math.max(1, args.attempts ?? 6);
65160
+ const sleep4 = args.sleep ?? ((ms) => new Promise((resolve3) => setTimeout(resolve3, ms)));
65161
+ let last = null;
65162
+ let why = "";
65163
+ for (let attempt = 1; attempt <= attempts; attempt += 1) {
65164
+ let answer = null;
65165
+ try {
65166
+ answer = await computeCall({
65167
+ method: "POST",
65168
+ url: args.url,
65169
+ body: args.body,
65170
+ headers: { "x-payment": args.payment },
65171
+ // A create waits for the chain, then the vendor: the API allows
65172
+ // itself 120 seconds.
65173
+ timeoutMs: args.timeoutMs ?? 15e4,
65174
+ fetchImpl: args.fetchImpl
65175
+ });
65176
+ } catch (err) {
65177
+ why = err?.message || String(err);
65178
+ }
65179
+ if (answer) {
65180
+ last = answer;
65181
+ if (answer.status >= 200 && answer.status < 300) return { kind: "served", answer, attempts: attempt };
65182
+ const inProgress = answer.status === 409 && answer.json?.code === "payment_in_progress";
65183
+ if (!(answer.status >= 500 || answer.status === 429 || inProgress)) return { kind: "refused", answer, attempts: attempt };
65184
+ why = typeof answer.json?.error === "string" ? answer.json.error : `HTTP ${answer.status}`;
65185
+ }
65186
+ if (attempt === attempts) break;
65187
+ const waitMs = answer?.retryAfterSeconds ? Math.min(answer.retryAfterSeconds, 60) * 1e3 : BACKOFF_MS[Math.min(attempt - 1, BACKOFF_MS.length - 1)];
65188
+ args.onRetry?.(why, attempt, waitMs);
65189
+ await sleep4(waitMs);
65190
+ }
65191
+ return { kind: "no_answer", error: why, attempts, last };
65192
+ }
65193
+ async function ownerGet(wallet, path8, opts = {}) {
65194
+ const header = await ownerAuthHeader(wallet, "GET", path8);
65195
+ return computeCall({
65196
+ method: "GET",
65197
+ url: `${computeOrigin()}${path8}`,
65198
+ headers: { "x-wallet-auth": header },
65199
+ timeoutMs: opts.timeoutMs ?? 6e4,
65200
+ fetchImpl: opts.fetchImpl
65201
+ });
65202
+ }
65203
+ function stillStarting(machine) {
65204
+ if (machine.status === "provisioning") return true;
65205
+ return machine.status === "stopped" && machine.stop?.starting === true;
65206
+ }
65207
+ async function waitUntilRunning(args) {
65208
+ const now = args.now ?? Date.now;
65209
+ const sleep4 = args.sleep ?? ((ms) => new Promise((resolve3) => setTimeout(resolve3, ms)));
65210
+ const started = now();
65211
+ let machine = null;
65212
+ for (; ; ) {
65213
+ let answer = null;
65214
+ try {
65215
+ answer = await args.read();
65216
+ } catch {
65217
+ answer = null;
65218
+ }
65219
+ if (answer && answer.status >= 400 && answer.status < 500) return { kind: "refused", answer };
65220
+ if (answer && answer.status >= 200 && answer.status < 300) {
65221
+ machine = answer.json;
65222
+ args.onTick?.(machine);
65223
+ if (machine.status === "running") return { kind: "running", machine };
65224
+ if (!stillStarting(machine)) return { kind: "ended", machine };
65225
+ }
65226
+ const elapsed = now() - started;
65227
+ if (elapsed >= args.timeoutMs) return { kind: "timeout", machine };
65228
+ await sleep4(Math.min(elapsed < 6e4 ? 5e3 : 1e4, Math.max(1, args.timeoutMs - elapsed)));
65229
+ }
65230
+ }
65231
+
65232
+ // src/commands/compute.ts
65233
+ var money = (v) => `$${String(v).replace(/(\.\d\d\d?)0+$/, "$1")}`;
65234
+ var jsonMode = (opts) => Boolean(opts.json) || !process.stdout.isTTY;
65235
+ var sink = null;
65236
+ function say(text) {
65237
+ if (sink) sink(text, "out");
65238
+ else process.stdout.write(text);
65239
+ }
65240
+ function sayErr(text) {
65241
+ if (sink) sink(text, "err");
65242
+ else process.stderr.write(text);
65243
+ }
65244
+ function fail(opts, error, code, extra = {}) {
65245
+ if (jsonMode(opts)) {
65246
+ say(JSON.stringify({ ok: false, code, error, ...extra }, null, 2) + "\n");
65247
+ } else {
65248
+ const line2 = `
65249
+ ${import_picocolors3.default.red("\u2717")} ${error}${code ? import_picocolors3.default.dim(` (${code})`) : ""}
65250
+
65251
+ `;
65252
+ if (sink) sink(line2, "err");
65253
+ else process.stderr.write(line2);
65254
+ }
65255
+ process.exitCode = 1;
65256
+ }
65257
+ function apiWords(answer) {
65258
+ const e = answer.json?.error;
65259
+ return typeof e === "string" && e ? e : `the compute API answered ${answer.status}`;
65260
+ }
65261
+ function apiCode(answer) {
65262
+ const c = answer.json?.code;
65263
+ return typeof c === "string" && c ? c : `http_${answer.status}`;
65264
+ }
65265
+ async function payingKey(opts) {
65266
+ let keys2;
65267
+ try {
65268
+ keys2 = await requirePasswordsKey();
65269
+ } catch (err) {
65270
+ fail(opts, err.message, "no_account");
65271
+ return null;
65272
+ }
65273
+ if (keys2.state.keyOnly) {
65274
+ fail(
65275
+ opts,
65276
+ "this machine runs on a login key with no words, and a machine is paid for and owned by a key that signs: run `agentgates init` here, or set AGENTGATES_PASSWORDS_SEED",
65277
+ "words_required"
65278
+ );
65279
+ return null;
65280
+ }
65281
+ return keys2.wallet;
65282
+ }
65283
+ async function computePlans(opts) {
65284
+ const res = await fetch(`${computeOrigin()}${CATALOG_PATH}`, { headers: { accept: "application/json" } });
65285
+ if (!res.ok) throw new Error(`compute catalog: HTTP ${res.status}`);
65286
+ const body = await res.json();
65287
+ if (opts.json) {
65288
+ say(JSON.stringify(body, null, 2) + "\n");
65289
+ return;
65290
+ }
65291
+ const plans = body.plans ?? [];
65292
+ if (plans.length === 0) {
65293
+ say(` ${import_picocolors3.default.dim("No plans are on sale right now.")}
65294
+ `);
65295
+ return;
65296
+ }
65297
+ say(`
65298
+ ${import_picocolors3.default.bold("CONFIDENTIAL VIRTUAL MACHINES")} ${import_picocolors3.default.dim("memory encrypted in use")}
65299
+
65300
+ `);
65301
+ for (const p of plans) {
65302
+ const spec = `${p.vcpu} vCPU \xB7 ${Math.round(p.memoryMb / 1024)} GB \xB7 ${p.diskGb}GB disk`;
65303
+ say(` ${import_picocolors3.default.bold(p.name.padEnd(10))} ${import_picocolors3.default.cyan(money(p.priceUsdPerHour))}${import_picocolors3.default.dim("/hour")} ${import_picocolors3.default.dim(spec)}
65304
+ `);
65305
+ say(` ${import_picocolors3.default.dim(p.id.padEnd(10))} ${import_picocolors3.default.dim(`${p.egressQuotaGb} GB traffic`)}
65306
+ `);
65307
+ const ladder = p.pricing.map((r) => `${r.hoursPerPayment}h ${money(r.totalUsd)}`).join(" ");
65308
+ if (ladder) say(` ${import_picocolors3.default.dim(ladder)}
65309
+ `);
65310
+ say("\n");
65311
+ }
65312
+ const nets = body.payment?.networks ?? [];
65313
+ if (nets.length) say(` ${import_picocolors3.default.dim(`USDC on ${nets.join(", ")}`)}
65314
+ `);
65315
+ say(` ${import_picocolors3.default.dim("rent one: agentgates compute buy --plan <id> --hours 1 --image <image> (--quote prices it, signs nothing)")}
65316
+
65317
+ `);
65318
+ }
65319
+ async function readCompose(file) {
65320
+ if (file === "-") {
65321
+ const chunks = [];
65322
+ for await (const chunk of process.stdin) chunks.push(Buffer.from(chunk));
65323
+ return Buffer.concat(chunks).toString("utf8");
65324
+ }
65325
+ try {
65326
+ return await fs8.readFile(file, "utf8");
65327
+ } catch (err) {
65328
+ throw new Error(`could not read the compose file ${file}: ${err.code ?? err.message}`);
65329
+ }
65330
+ }
65331
+ function microOfUsd(raw) {
65332
+ const m = /^\s*\$?(\d+)(?:\.(\d{1,6}))?\s*$/.exec(raw);
65333
+ if (!m) throw new Error(`--max-usd takes dollars, like 1 or 0.5 (got "${raw}")`);
65334
+ return BigInt(m[1]) * 1000000n + BigInt((m[2] ?? "").padEnd(6, "0"));
65335
+ }
65336
+ function legView(leg) {
65337
+ let amount = null;
65338
+ try {
65339
+ amount = leg.maxAmountRequired ? usd(BigInt(leg.maxAmountRequired)) : null;
65340
+ } catch {
65341
+ amount = null;
65342
+ }
65343
+ return {
65344
+ network: leg.network ?? "?",
65345
+ amountUsd: amount,
65346
+ amountAtomic: leg.maxAmountRequired ?? null,
65347
+ payTo: leg.payTo ?? null,
65348
+ asset: leg.asset ?? null,
65349
+ validSeconds: leg.maxTimeoutSeconds ?? null
65350
+ };
65351
+ }
65352
+ async function computeBuy(opts) {
65353
+ let body;
65354
+ try {
65355
+ const compose = opts.compose !== void 0 ? await readCompose(opts.compose) : void 0;
65356
+ body = createBody({
65357
+ plan: opts.plan,
65358
+ hours: opts.hours,
65359
+ image: opts.image,
65360
+ port: opts.port,
65361
+ compose,
65362
+ env: parseEnvPairs(opts.env),
65363
+ name: opts.name
65364
+ });
65365
+ } catch (err) {
65366
+ fail(opts, err.message, "bad_input");
65367
+ return;
65368
+ }
65369
+ const what = `${String(body.plan)}, ${String(body.hours)} h, ${typeof body.image === "string" ? body.image : "your compose"}`;
65370
+ await payFor(opts, { url: `${computeOrigin()}${DEPLOYMENTS_PATH}`, body, what, action: "buy" });
65371
+ }
65372
+ async function computeRenew(id2, opts) {
65373
+ let path8;
65374
+ let hours;
65375
+ try {
65376
+ path8 = deploymentPath(id2, "renew");
65377
+ hours = positiveInt(opts.hours, "--hours");
65378
+ } catch (err) {
65379
+ fail(opts, err.message, "bad_input");
65380
+ return;
65381
+ }
65382
+ await payFor(opts, { url: `${computeOrigin()}${path8}`, body: { hours }, what: `${hours} more h on ${id2}`, action: "renew" });
65383
+ }
65384
+ async function payFor(opts, args) {
65385
+ let quote;
65386
+ try {
65387
+ quote = await askPrice(args.url, args.body);
65388
+ } catch (err) {
65389
+ fail(opts, `the compute API did not answer: ${err.message}`, "unreachable");
65390
+ return;
65391
+ }
65392
+ if (quote.status !== 402) {
65393
+ if (quote.status >= 200 && quote.status < 300) {
65394
+ emitMachine(opts, quote.json, { note: "served without a payment" });
65395
+ return;
65396
+ }
65397
+ fail(opts, apiWords(quote), apiCode(quote), { status: quote.status });
65398
+ return;
65399
+ }
65400
+ const offer = quote.json;
65401
+ const legs = (offer.accepts ?? []).map(legView);
65402
+ const description = offer.accepts?.[0]?.description ?? null;
65403
+ if (opts.quote) {
65404
+ if (jsonMode(opts)) {
65405
+ say(JSON.stringify({ ok: true, quote: { description, resource: offer.accepts?.[0]?.resource ?? null, legs } }, null, 2) + "\n");
65406
+ return;
65407
+ }
65408
+ say(`
65409
+ ${import_picocolors3.default.bold(description ?? args.what)} ${import_picocolors3.default.dim("nothing signed")}
65410
+
65411
+ `);
65412
+ for (const [i, l] of legs.entries()) {
65413
+ const evm = evmLegs({ accepts: [offer.accepts[i]] }).length > 0;
65414
+ say(` ${import_picocolors3.default.cyan((l.amountUsd ?? "?").padEnd(10))} ${l.network.padEnd(9)} ${import_picocolors3.default.dim(`to ${l.payTo ?? "?"}`)}${evm ? "" : import_picocolors3.default.dim(" (needs a Solana key; this CLI signs EVM legs)")}
65415
+ `);
65416
+ }
65417
+ say(`
65418
+ ${import_picocolors3.default.dim("pay: the same command without --quote")}
65419
+
65420
+ `);
65421
+ return;
65422
+ }
65423
+ const wallet = await payingKey(opts);
65424
+ if (!wallet) return;
65425
+ const narrowed = legsOn(offer, opts.network);
65426
+ if (opts.network && !(narrowed.accepts ?? []).length) {
65427
+ fail(opts, `this price has no leg on ${opts.network} (offered: ${offeredNetworks(offer).join(", ") || "none"})`, "network_not_offered", { legs });
65428
+ return;
65429
+ }
65430
+ const choice = await chooseLeg(narrowed, wallet.address);
65431
+ let leg;
65432
+ let heldMicro;
65433
+ if (choice.ok) {
65434
+ leg = choice.leg;
65435
+ heldMicro = choice.heldMicro;
65436
+ } else if (choice.needMicro !== null && choice.bestHeldMicro === null) {
65437
+ leg = [...evmLegs(narrowed)].sort((a, b2) => a.amountMicro < b2.amountMicro ? -1 : a.amountMicro > b2.amountMicro ? 1 : 0)[0];
65438
+ heldMicro = null;
65439
+ } else {
65440
+ const need2 = choice.needMicro === null ? null : usd(choice.needMicro);
65441
+ const held3 = choice.bestHeldMicro === null ? null : usd(choice.bestHeldMicro);
65442
+ const evmNets = evmLegs(narrowed).map((l) => l.network);
65443
+ const sentence = need2 && held3 ? `${choice.reason}. It costs ${need2} and this key holds ${held3}. Send USDC to ${wallet.address} on ${evmNets.join(" or ") || "an offered network"}, then run this again` : choice.reason;
65444
+ fail(opts, sentence, need2 && held3 ? "insufficient_funds" : "no_signable_leg", { address: wallet.address, legs });
65445
+ return;
65446
+ }
65447
+ const price = usd(leg.amountMicro);
65448
+ if (opts.maxUsd !== void 0) {
65449
+ let ceiling;
65450
+ try {
65451
+ ceiling = microOfUsd(opts.maxUsd);
65452
+ } catch (err) {
65453
+ fail(opts, err.message, "bad_input");
65454
+ return;
65455
+ }
65456
+ if (leg.amountMicro > ceiling) {
65457
+ fail(opts, `the price is ${price} on ${leg.network}, over --max-usd ${usd(ceiling)}: nothing was signed`, "over_max", { legs });
65458
+ return;
65459
+ }
65460
+ }
65461
+ if (!opts.yes) {
65462
+ if (jsonMode(opts) || !process.stdin.isTTY) {
65463
+ fail(opts, `pass --yes to pay ${price} on ${leg.network} without a prompt: nothing was signed`, "confirm_required", { legs });
65464
+ return;
65465
+ }
65466
+ say(`
65467
+ ${import_picocolors3.default.bold(description ?? args.what)}
65468
+ `);
65469
+ const holds = heldMicro === null ? "this key's balance could not be read" : `this key holds ${usd(heldMicro)} there`;
65470
+ say(` ${import_picocolors3.default.dim(`pay ${price} USDC on ${leg.network} to ${leg.payTo} \xB7 ${holds} \xB7 no gas`)}
65471
+ `);
65472
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
65473
+ let answer = "";
65474
+ try {
65475
+ answer = (await rl.question(` Pay? [y/N] `)).trim().toLowerCase();
65476
+ } catch {
65477
+ answer = "";
65478
+ } finally {
65479
+ rl.close();
65480
+ }
65481
+ if (answer !== "y" && answer !== "yes") {
65482
+ say(` ${import_picocolors3.default.dim("Nothing paid.")}
65483
+
65484
+ `);
65485
+ return;
65486
+ }
65487
+ }
65488
+ const signed2 = await signLeg(leg, wallet.privateKey);
65489
+ const paid = { network: leg.network, amountUsd: price, amountAtomic: leg.amountMicro.toString(), from: signed2.from, nonce: signed2.nonce };
65490
+ if (!jsonMode(opts)) say(` ${import_picocolors3.default.dim(`paying ${price} on ${leg.network}`)}
65491
+ `);
65492
+ else sayErr(`${JSON.stringify({ event: "paid", ...paid })}
65493
+ `);
65494
+ const outcome = await sendPaid({
65495
+ url: args.url,
65496
+ body: args.body,
65497
+ payment: signed2.header,
65498
+ onRetry: (why, attempt, waitMs) => {
65499
+ if (!jsonMode(opts)) {
65500
+ say(` ${import_picocolors3.default.dim(`no clear answer yet (${why}); sending the same payment again in ${Math.round(waitMs / 1e3)} s (${attempt})`)}
65501
+ `);
65502
+ }
65503
+ }
65504
+ });
65505
+ if (outcome.kind === "no_answer") {
65506
+ fail(
65507
+ opts,
65508
+ `no clear answer after ${outcome.attempts} tries (${outcome.error}). The payment may have settled: do not pay again. \`agentgates compute list\` shows what it bought`,
65509
+ "no_answer",
65510
+ { paid }
65511
+ );
65512
+ return;
65513
+ }
65514
+ if (outcome.kind === "refused") {
65515
+ const a = outcome.answer;
65516
+ const resent = outcome.attempts > 1;
65517
+ const charged = resent ? "The first send may have settled: do not pay again; `agentgates compute list` shows what it bought" : "Nothing was charged";
65518
+ if (a.status === 402 && a.json?.code === "insufficient_funds") {
65519
+ const need2 = typeof a.json.needUsd === "string" ? `$${a.json.needUsd}` : price;
65520
+ const have = typeof a.json.haveUsd === "string" ? `$${a.json.haveUsd}` : null;
65521
+ fail(
65522
+ opts,
65523
+ `not enough USDC on ${a.json.network ?? leg.network}: it costs ${need2}${have ? ` and ${signed2.from} holds ${have}` : ""}. ${charged}`,
65524
+ "insufficient_funds",
65525
+ { status: a.status, needUsd: a.json.needUsd ?? null, haveUsd: a.json.haveUsd ?? null, paid }
65526
+ );
65527
+ return;
65528
+ }
65529
+ if (a.status === 402) {
65530
+ fail(
65531
+ opts,
65532
+ resent ? `the payment was refused on a resend: ${apiWords(a)}. ${charged}` : `the payment was refused and nothing was charged: ${apiWords(a)}`,
65533
+ apiCode(a) === "http_402" ? "payment_refused" : apiCode(a),
65534
+ { status: a.status, paid, resent }
65535
+ );
65536
+ return;
65537
+ }
65538
+ if (a.json?.code === "payment_already_spent") {
65539
+ fail(opts, `${apiWords(a)} (\`agentgates compute list\`)`, "payment_already_spent", { status: a.status, paid });
65540
+ return;
65541
+ }
65542
+ fail(opts, apiWords(a), apiCode(a), { status: a.status, paid });
65543
+ return;
65544
+ }
65545
+ const machine = outcome.answer.json;
65546
+ const note2 = machine.alreadyPaid === true ? "this payment had already bought it; nothing was charged again" : null;
65547
+ if (!(opts.wait && args.action === "buy" && machine.deploymentId)) {
65548
+ emitMachine(opts, machine, { paid, note: note2, next: args.action === "buy" });
65549
+ return;
65550
+ }
65551
+ if (!jsonMode(opts)) emitMachine(opts, machine, { paid, note: note2, next: false });
65552
+ else sayErr(`${JSON.stringify({ event: "machine", deploymentId: machine.deploymentId ?? null, status: machine.status ?? null })}
65553
+ `);
65554
+ await waitAndReport(opts, wallet, machine.deploymentId ?? "", { paid, deploymentId: machine.deploymentId ?? null });
65555
+ }
65556
+ function readRefused(opts, answer, wallet, extra = {}) {
65557
+ const words7 = apiWords(answer);
65558
+ const hint = answer.status === 404 ? ` (this key is ${wallet.address})` : "";
65559
+ fail(opts, `${words7}${hint}`, apiCode(answer), { status: answer.status, signer: wallet.address, ...extra });
65560
+ }
65561
+ async function computeList(opts) {
65562
+ const wallet = await payingKey(opts);
65563
+ if (!wallet) return;
65564
+ let answer;
65565
+ try {
65566
+ answer = await ownerGet(wallet, DEPLOYMENTS_PATH);
65567
+ } catch (err) {
65568
+ fail(opts, `the compute API did not answer: ${err.message}`, "unreachable");
65569
+ return;
65570
+ }
65571
+ if (answer.status !== 200) {
65572
+ readRefused(opts, answer, wallet);
65573
+ return;
65574
+ }
65575
+ const machines = Array.isArray(answer.json.deployments) ? answer.json.deployments : [];
65576
+ if (jsonMode(opts)) {
65577
+ say(JSON.stringify({ ok: true, owner: wallet.address, deployments: machines }, null, 2) + "\n");
65578
+ return;
65579
+ }
65580
+ say(`
65581
+ ${import_picocolors3.default.bold("MACHINES")} ${import_picocolors3.default.dim(`owned by ${wallet.address}`)}
65582
+
65583
+ `);
65584
+ if (machines.length === 0) {
65585
+ say(` ${import_picocolors3.default.dim("None yet. Rent one: agentgates compute buy --plan <id> --hours 1 --image <image>")}
65586
+
65587
+ `);
65588
+ return;
65589
+ }
65590
+ for (const m of machines) say(`${machineLines(m)}
65591
+
65592
+ `);
65593
+ }
65594
+ async function computeStatus(id2, opts) {
65595
+ let path8;
65596
+ try {
65597
+ path8 = deploymentPath(id2);
65598
+ } catch (err) {
65599
+ fail(opts, err.message, "bad_input");
65600
+ return;
65601
+ }
65602
+ const wallet = await payingKey(opts);
65603
+ if (!wallet) return;
65604
+ let answer;
65605
+ try {
65606
+ answer = await ownerGet(wallet, path8);
65607
+ } catch (err) {
65608
+ fail(opts, `the compute API did not answer: ${err.message}`, "unreachable");
65609
+ return;
65610
+ }
65611
+ if (answer.status !== 200) {
65612
+ readRefused(opts, answer, wallet);
65613
+ return;
65614
+ }
65615
+ const machine = answer.json;
65616
+ if (jsonMode(opts)) {
65617
+ say(JSON.stringify({ ok: true, deployment: machine }, null, 2) + "\n");
65618
+ return;
65619
+ }
65620
+ say(`
65621
+ ${machineLines(machine)}
65622
+ `);
65623
+ const invoices = Array.isArray(machine.invoices) ? machine.invoices.length : 0;
65624
+ if (invoices) say(` ${import_picocolors3.default.dim(`${invoices} payment${invoices === 1 ? "" : "s"} on record`)}
65625
+ `);
65626
+ if (machine.attestation) say(` ${import_picocolors3.default.dim("attestation: live (--json carries the quote)")}
65627
+ `);
65628
+ say("\n");
65629
+ }
65630
+ async function computeWait(id2, opts) {
65631
+ try {
65632
+ deploymentPath(id2);
65633
+ } catch (err) {
65634
+ fail(opts, err.message, "bad_input");
65635
+ return;
65636
+ }
65637
+ const wallet = await payingKey(opts);
65638
+ if (!wallet) return;
65639
+ await waitAndReport(opts, wallet, id2, {});
65640
+ }
65641
+ async function waitAndReport(opts, wallet, id2, extra) {
65642
+ let minutes;
65643
+ try {
65644
+ minutes = opts.timeout === void 0 ? 15 : positiveInt(opts.timeout, "--timeout");
65645
+ } catch (err) {
65646
+ fail(opts, err.message, "bad_input");
65647
+ return;
65648
+ }
65649
+ const path8 = deploymentPath(id2);
65650
+ let lastStatus = "";
65651
+ const started = Date.now();
65652
+ const outcome = await waitUntilRunning({
65653
+ read: () => ownerGet(wallet, path8),
65654
+ timeoutMs: minutes * 6e4,
65655
+ onTick: (m) => {
65656
+ if (jsonMode(opts) || m.status === lastStatus) return;
65657
+ lastStatus = m.status ?? "";
65658
+ say(` ${import_picocolors3.default.dim(`${lastStatus} \xB7 ${Math.round((Date.now() - started) / 1e3)} s`)}
65659
+ `);
65660
+ }
65661
+ });
65662
+ if (outcome.kind === "running") {
65663
+ emitMachine(opts, outcome.machine, { paid: extra.paid, note: "running", next: false });
65664
+ return;
65665
+ }
65666
+ if (outcome.kind === "refused") {
65667
+ readRefused(opts, outcome.answer, wallet, extra);
65668
+ return;
65669
+ }
65670
+ if (outcome.kind === "ended") {
65671
+ const m = outcome.machine;
65672
+ fail(opts, `the machine is ${m.status}${m.killReason ? ` (${m.killReason})` : ""}, and will not run by itself`, "not_running", { deployment: m, ...extra });
65673
+ return;
65674
+ }
65675
+ fail(
65676
+ opts,
65677
+ `still ${outcome.machine?.status ?? "unread"} after ${minutes} min; the clock starts only when it runs. Wait again: agentgates compute wait ${id2}`,
65678
+ "timeout",
65679
+ { deployment: outcome.machine, ...extra }
65680
+ );
65681
+ }
65682
+ function statusWord(status4) {
65683
+ const s = status4 ?? "?";
65684
+ if (s === "running") return import_picocolors3.default.green(s);
65685
+ if (s === "provisioning" || s === "stopped") return import_picocolors3.default.yellow(s);
65686
+ if (s === "failed" || s === "destroyed" || s === "grace" || s === "suspended") return import_picocolors3.default.red(s);
65687
+ return s;
65688
+ }
65689
+ function inWords(iso) {
65690
+ if (!iso) return "";
65691
+ const ms = Date.parse(iso) - Date.now();
65692
+ if (!Number.isFinite(ms)) return "";
65693
+ const mins = Math.round(Math.abs(ms) / 6e4);
65694
+ const span = mins < 90 ? `${mins} min` : mins < 48 * 60 ? `${Math.round(mins / 60)} h` : `${Math.round(mins / 1440)} days`;
65695
+ return ms >= 0 ? `in ${span}` : `${span} ago`;
65696
+ }
65697
+ function machineLines(m) {
65698
+ const head = ` ${import_picocolors3.default.bold(m.deploymentId ?? "?")} ${statusWord(m.status)} ${import_picocolors3.default.dim(`${m.plan ?? ""}${m.name ? ` \xB7 ${m.name}` : ""}`)}`;
65699
+ const lines = [head];
65700
+ if (m.endpoint) lines.push(` endpoint ${import_picocolors3.default.cyan(m.endpoint)}`);
65701
+ if (m.expiresAt) lines.push(` paid to ${m.expiresAt} ${import_picocolors3.default.dim(inWords(m.expiresAt))}`);
65702
+ else if (m.status === "provisioning") lines.push(` ${import_picocolors3.default.dim("the clock starts when it runs")}`);
65703
+ if (m.killReason) lines.push(` ${import_picocolors3.default.dim(`ended: ${m.killReason}`)}`);
65704
+ if (m.verifyUrl) lines.push(` verify ${import_picocolors3.default.dim(`${computeOrigin()}${m.verifyUrl}`)}`);
65705
+ return lines.join("\n");
65706
+ }
65707
+ function emitMachine(opts, machine, extra) {
65708
+ if (jsonMode(opts)) {
65709
+ say(
65710
+ JSON.stringify(
65711
+ { ok: true, deployment: machine, ...extra.paid ? { paid: extra.paid } : {}, ...extra.note ? { note: extra.note } : {} },
65712
+ null,
65713
+ 2
65714
+ ) + "\n"
65715
+ );
65716
+ return;
65717
+ }
65718
+ say(`
65719
+ ${import_picocolors3.default.green("\u2713")} ${extra.note ?? (extra.paid ? `paid ${extra.paid.amountUsd} on ${extra.paid.network}` : "ready")}
65720
+
65721
+ `);
65722
+ say(`${machineLines(machine)}
65723
+
65724
+ `);
65725
+ if (extra.next && machine.deploymentId && machine.status !== "running") {
65726
+ say(` ${import_picocolors3.default.dim(`wait for it: agentgates compute wait ${machine.deploymentId}`)}
65727
+
65728
+ `);
65729
+ }
65730
+ }
65731
+
65108
65732
  // src/commands/inference.ts
65733
+ var import_picocolors4 = __toESM(require_picocolors(), 1);
65734
+ init_passwords_wire();
65109
65735
  init_constants();
65110
- var SITE2 = (process.env.AGENTGATES_ORIGIN || "https://agentgates.ai").replace(/\/$/, "");
65736
+ var SITE = (process.env.AGENTGATES_ORIGIN || "https://agentgates.ai").replace(/\/$/, "");
65111
65737
  function applyFilters(models, f2) {
65112
65738
  let out = models;
65113
65739
  if (f2.tier === "confidential") out = out.filter((m) => m.confidential);
@@ -65123,7 +65749,7 @@ function applyFilters(models, f2) {
65123
65749
  var hasFilters = (f2) => Boolean(f2.tier || (f2.tag ?? []).length || f2.org || f2.search);
65124
65750
  var ctx = (n2) => n2 >= 1e6 ? `${Math.round(n2 / 1e6)}M` : `${Math.round(n2 / 1e3)}k`;
65125
65751
  async function inferenceModels(opts) {
65126
- const res = await fetch(`${SITE2}/api/inference/catalog`, { headers: { accept: "application/json" } });
65752
+ const res = await fetch(`${SITE}/api/inference/catalog`, { headers: { accept: "application/json" } });
65127
65753
  if (!res.ok) throw new Error(`inference catalog: HTTP ${res.status}`);
65128
65754
  const body = await res.json();
65129
65755
  const all = body.models ?? [];
@@ -65304,8 +65930,8 @@ async function inferenceTopUp(amountUsd, opts = {}) {
65304
65930
  }
65305
65931
  const choice = await chooseLeg(quote.json, wallet.address);
65306
65932
  if (!choice.ok) {
65307
- const need2 = choice.needMicro === null ? null : usd2(choice.needMicro);
65308
- const held3 = choice.bestHeldMicro === null ? null : usd2(choice.bestHeldMicro);
65933
+ const need2 = choice.needMicro === null ? null : usd(choice.needMicro);
65934
+ const held3 = choice.bestHeldMicro === null ? null : usd(choice.bestHeldMicro);
65309
65935
  const sentence = need2 && held3 ? `${choice.reason}. The top-up costs ${need2} and this key holds ${held3}. Send USDC to ${wallet.address} on base, polygon or arbitrum` : choice.reason;
65310
65936
  process.stdout.write(opts.json ? `${JSON.stringify({ ok: false, error: sentence })}
65311
65937
  ` : `
@@ -65315,7 +65941,7 @@ async function inferenceTopUp(amountUsd, opts = {}) {
65315
65941
  return;
65316
65942
  }
65317
65943
  if (!opts.json) process.stdout.write(`
65318
- ${import_picocolors4.default.dim(`paying ${usd2(choice.leg.amountMicro)} on ${choice.leg.network}`)}
65944
+ ${import_picocolors4.default.dim(`paying ${usd(choice.leg.amountMicro)} on ${choice.leg.network}`)}
65319
65945
  `);
65320
65946
  const signed2 = await signLeg(choice.leg, wallet.privateKey);
65321
65947
  const paid = await post3(signed2.header);
@@ -65365,7 +65991,7 @@ async function inferenceAsk(words7, opts = {}) {
65365
65991
  };
65366
65992
  const quote = await post3(null);
65367
65993
  if (quote.status === 200) {
65368
- say(opts, quote.json);
65994
+ say2(opts, quote.json);
65369
65995
  return;
65370
65996
  }
65371
65997
  if (quote.status !== 402) {
@@ -65380,8 +66006,8 @@ async function inferenceAsk(words7, opts = {}) {
65380
66006
  }
65381
66007
  const choice = await chooseLeg(quote.json, wallet.address);
65382
66008
  if (!choice.ok) {
65383
- const need2 = choice.needMicro === null ? null : usd2(choice.needMicro);
65384
- const held3 = choice.bestHeldMicro === null ? null : usd2(choice.bestHeldMicro);
66009
+ const need2 = choice.needMicro === null ? null : usd(choice.needMicro);
66010
+ const held3 = choice.bestHeldMicro === null ? null : usd(choice.bestHeldMicro);
65385
66011
  const sentence = need2 && held3 ? `${choice.reason}. The ask costs ${need2} and this key holds ${held3}. Send USDC to ${wallet.address} on base, polygon or arbitrum and it pays for itself` : choice.reason;
65386
66012
  process.stdout.write(
65387
66013
  opts.json ? `${JSON.stringify({ ok: false, error: sentence })}
@@ -65393,7 +66019,7 @@ async function inferenceAsk(words7, opts = {}) {
65393
66019
  return;
65394
66020
  }
65395
66021
  if (!opts.json) process.stdout.write(`
65396
- ${import_picocolors4.default.dim(`paying ${usd2(choice.leg.amountMicro)} on ${choice.leg.network}`)}
66022
+ ${import_picocolors4.default.dim(`paying ${usd(choice.leg.amountMicro)} on ${choice.leg.network}`)}
65397
66023
  `);
65398
66024
  const signed2 = await signLeg(choice.leg, wallet.privateKey);
65399
66025
  const paid = await post3(signed2.header);
@@ -65408,9 +66034,9 @@ async function inferenceAsk(words7, opts = {}) {
65408
66034
  );
65409
66035
  return;
65410
66036
  }
65411
- say(opts, paid.json);
66037
+ say2(opts, paid.json);
65412
66038
  }
65413
- function say(opts, answer) {
66039
+ function say2(opts, answer) {
65414
66040
  if (opts.json || !process.stdout.isTTY) {
65415
66041
  process.stdout.write(`${JSON.stringify(answer)}
65416
66042
  `);
@@ -68967,14 +69593,18 @@ function codeFrom(text, pattern) {
68967
69593
  return null;
68968
69594
  }
68969
69595
  }
68970
- const labeled = haystack.split(/\r?\n/).filter((line2) => /\b(code|verification|verify|otp|pin|passcode|one[- ]time)\b/i.test(line2));
69596
+ const words7 = withoutLinks(haystack);
69597
+ const labeled = words7.split(/\r?\n/).filter((line2) => /\b(code|verification|verify|otp|pin|passcode|one[- ]time)\b/i.test(line2));
68971
69598
  for (const line2 of labeled) {
68972
69599
  const m = line2.match(/\b\d{4,8}\b/);
68973
69600
  if (m) return m[0];
68974
69601
  }
68975
- const anywhere = haystack.match(/\b\d{4,8}\b/);
69602
+ const anywhere = words7.match(/\b\d{4,8}\b/);
68976
69603
  return anywhere ? anywhere[0] : null;
68977
69604
  }
69605
+ function withoutLinks(text) {
69606
+ return text.replace(/https?:\/\/[^\s"'<>]+/g, " ");
69607
+ }
68978
69608
 
68979
69609
  // src/lib/seal-grants.ts
68980
69610
  init_passwords_wire();
@@ -69169,12 +69799,12 @@ async function payphoneCall(args) {
69169
69799
  }
69170
69800
  const choice = await chooseLeg(quote.json, args.address);
69171
69801
  if (!choice.ok) {
69172
- const need2 = choice.needMicro === null ? null : usd2(choice.needMicro);
69173
- const held3 = choice.bestHeldMicro === null ? null : usd2(choice.bestHeldMicro);
69802
+ const need2 = choice.needMicro === null ? null : usd(choice.needMicro);
69803
+ const held3 = choice.bestHeldMicro === null ? null : usd(choice.bestHeldMicro);
69174
69804
  const shortfall = need2 && held3 ? `${choice.reason}. The window costs ${need2} and this key holds ${held3}. Send USDC to ${args.address} on base, polygon or arbitrum and it pays for itself` : need2 ? `${choice.reason}. The window costs ${need2}` : choice.reason;
69175
69805
  throw new WireError(402, "payphone_unfunded", shortfall, quote.json);
69176
69806
  }
69177
- args.onQuote?.(`paying ${usd2(choice.leg.amountMicro)} on ${choice.leg.network}`);
69807
+ args.onQuote?.(`paying ${usd(choice.leg.amountMicro)} on ${choice.leg.network}`);
69178
69808
  const signed2 = await signLeg(choice.leg, args.privateKey);
69179
69809
  let paid = await post(body, signed2.header, 18e4);
69180
69810
  if (paid.status >= 400) {
@@ -69211,17 +69841,17 @@ async function payphoneRead(payment, asked, what) {
69211
69841
  }
69212
69842
 
69213
69843
  // src/commands/phone.ts
69214
- var SITE3 = (process.env.AGENTGATES_ORIGIN || "https://agentgates.ai").replace(/\/$/, "");
69215
- var jsonMode = (opts) => opts.json === true || !process.stdout.isTTY;
69844
+ var SITE2 = (process.env.AGENTGATES_ORIGIN || "https://agentgates.ai").replace(/\/$/, "");
69845
+ var jsonMode2 = (opts) => opts.json === true || !process.stdout.isTTY;
69216
69846
  function emit2(opts, data4, human) {
69217
- if (jsonMode(opts)) {
69847
+ if (jsonMode2(opts)) {
69218
69848
  process.stdout.write(JSON.stringify(data4, null, 2) + "\n");
69219
69849
  return;
69220
69850
  }
69221
69851
  human();
69222
69852
  }
69223
69853
  function refuse(opts, error, code, extra = {}) {
69224
- if (jsonMode(opts)) {
69854
+ if (jsonMode2(opts)) {
69225
69855
  process.stdout.write(JSON.stringify({ ok: false, code, error, ...extra }, null, 2) + "\n");
69226
69856
  } else {
69227
69857
  process.stderr.write(` ${error}${code ? import_picocolors5.default.dim(` (${code})`) : ""}
@@ -69233,7 +69863,7 @@ function failFrom(opts, err) {
69233
69863
  if (err instanceof WireError) return refuse(opts, err.message, err.code, { status: err.status });
69234
69864
  return refuse(opts, err.message ?? String(err), null);
69235
69865
  }
69236
- var usd3 = (v) => {
69866
+ var usd2 = (v) => {
69237
69867
  const n2 = Number(v);
69238
69868
  if (Number.isInteger(n2)) return `$${n2}`;
69239
69869
  const [whole, frac = ""] = n2.toFixed(6).replace(/0+$/, "").split(".");
@@ -69264,7 +69894,7 @@ function phoneSlice(body) {
69264
69894
  return out;
69265
69895
  }
69266
69896
  async function phonePricing(opts) {
69267
- const res = await fetch(`${SITE3}/api/account/catalog`, { headers: { accept: "application/json" } });
69897
+ const res = await fetch(`${SITE2}/api/account/catalog`, { headers: { accept: "application/json" } });
69268
69898
  if (!res.ok) throw new Error(`phone catalog: HTTP ${res.status}`);
69269
69899
  const body = await res.json();
69270
69900
  const slice = phoneSlice(body);
@@ -69285,7 +69915,7 @@ async function phonePricing(opts) {
69285
69915
  `);
69286
69916
  for (const p of plans) {
69287
69917
  const count = p.phones ?? 1;
69288
- const price = usd3(p.priceUsd).padStart(4);
69918
+ const price = usd2(p.priceUsd).padStart(4);
69289
69919
  const term = `/${p.units} days`.padEnd(9);
69290
69920
  process.stdout.write(` ${import_picocolors5.default.bold(p.rung.padEnd(11))} ${import_picocolors5.default.cyan(price)}${import_picocolors5.default.dim(term)} ${import_picocolors5.default.dim(`${count} number${count === 1 ? "" : "s"}`)}
69291
69921
  `);
@@ -69295,9 +69925,9 @@ async function phonePricing(opts) {
69295
69925
  const u = slice.phoneUsage;
69296
69926
  if (u) {
69297
69927
  const meter = [
69298
- u.textUsd ? `text ${usd3(u.textUsd)}` : "",
69299
- u.minuteUsd ? `call minute ${usd3(u.minuteUsd)}` : "",
69300
- u.waitCodeUsd !== void 0 ? `wait-code ${Number(u.waitCodeUsd) === 0 ? "free" : usd3(u.waitCodeUsd)}` : ""
69928
+ u.textUsd ? `text ${usd2(u.textUsd)}` : "",
69929
+ u.minuteUsd ? `call minute ${usd2(u.minuteUsd)}` : "",
69930
+ u.waitCodeUsd !== void 0 ? `wait-code ${Number(u.waitCodeUsd) === 0 ? "free" : usd2(u.waitCodeUsd)}` : ""
69301
69931
  ].filter(Boolean).join(" \xB7 ");
69302
69932
  process.stdout.write(`
69303
69933
  ${import_picocolors5.default.dim(`usage, from the prepaid balance: ${meter}`)}
@@ -69311,7 +69941,7 @@ async function phonePricing(opts) {
69311
69941
  ${import_picocolors5.default.bold("THE OPERATOR")} ${import_picocolors5.default.dim("our brain, voice and ears on the line; the transcript and the outcome back")}
69312
69942
 
69313
69943
  `);
69314
- process.stdout.write(` ${import_picocolors5.default.cyan(usd3(op.minuteUsd))} ${import_picocolors5.default.dim(`a minute, all in, ${op.minutes ?? op.maxMinutes ?? "?"} minutes a call by default (--minutes up to ${op.maxMinutes ?? "?"}), from the prepaid balance`)}
69944
+ process.stdout.write(` ${import_picocolors5.default.cyan(usd2(op.minuteUsd))} ${import_picocolors5.default.dim(`a minute, all in, ${op.minutes ?? op.maxMinutes ?? "?"} minutes a call by default (--minutes up to ${op.maxMinutes ?? "?"}), from the prepaid balance`)}
69315
69945
  `);
69316
69946
  process.stdout.write(` ${import_picocolors5.default.dim(op.house ? 'on your number, or from the house number with none: agentgates call <number> "<what to get done>"' : 'on your number: agentgates call <number> "<what to get done>"')}
69317
69947
  `);
@@ -69329,7 +69959,7 @@ async function phonePricing(opts) {
69329
69959
  ${import_picocolors5.default.bold("PAYPHONE")} ${import_picocolors5.default.dim("no plan, no number, no account: one x402 payment, one call")}
69330
69960
 
69331
69961
  `);
69332
- const ladder = windows.map((w) => `${w.minutes} min ${usd3(w.priceUsd)}${w.operatorPriceUsd ? import_picocolors5.default.dim(` (${usd3(w.operatorPriceUsd)} with the operator)`) : ""}`).join(" ");
69962
+ const ladder = windows.map((w) => `${w.minutes} min ${usd2(w.priceUsd)}${w.operatorPriceUsd ? import_picocolors5.default.dim(` (${usd2(w.operatorPriceUsd)} with the operator)`) : ""}`).join(" ");
69333
69963
  process.stdout.write(` ${ladder}
69334
69964
  `);
69335
69965
  }
@@ -69353,9 +69983,9 @@ function printCall(c, from, perMinuteUsd, full, key = null) {
69353
69983
  const { task, lines, shut } = openedCall(c, key);
69354
69984
  if (task) process.stdout.write(` ${task}
69355
69985
  `);
69356
- if (perMinuteUsd) process.stdout.write(` ${import_picocolors5.default.dim(`${usd3(perMinuteUsd)} a minute, from the balance`)}
69986
+ if (perMinuteUsd) process.stdout.write(` ${import_picocolors5.default.dim(`${usd2(perMinuteUsd)} a minute, from the balance`)}
69357
69987
  `);
69358
- if (c.billedUsd) process.stdout.write(` ${import_picocolors5.default.dim(`billed ${usd3(c.billedUsd)}`)}
69988
+ if (c.billedUsd) process.stdout.write(` ${import_picocolors5.default.dim(`billed ${usd2(c.billedUsd)}`)}
69359
69989
  `);
69360
69990
  if (shut) process.stdout.write(` ${import_picocolors5.default.dim("sealed: this key does not open it (agentgates email seal-status)")}
69361
69991
  `);
@@ -69413,12 +70043,12 @@ async function walkUpToThePayphone(opts, args) {
69413
70043
  voice: opts.voice ?? null,
69414
70044
  greeting: opts.greeting ?? null,
69415
70045
  onQuote: (note2) => {
69416
- if (!jsonMode(opts)) process.stderr.write(` ${import_picocolors5.default.dim(note2)}
70046
+ if (!jsonMode2(opts)) process.stderr.write(` ${import_picocolors5.default.dim(note2)}
69417
70047
  `);
69418
70048
  }
69419
70049
  });
69420
70050
  const placed = walk.call;
69421
- const paid = usd2(walk.paidMicro);
70051
+ const paid = usd(walk.paidMicro);
69422
70052
  const render = (row2, full) => {
69423
70053
  printCall(row2, "the payphone", null, full);
69424
70054
  process.stdout.write(` ${import_picocolors5.default.dim(`${paid} paid on ${walk.network} for ${window2} ${window2 === 1 ? "minute" : "minutes"}, nothing held`)}
@@ -69444,7 +70074,7 @@ async function walkUpToThePayphone(opts, args) {
69444
70074
  } catch {
69445
70075
  break;
69446
70076
  }
69447
- if (!jsonMode(opts) && row?.status && row.status !== last) {
70077
+ if (!jsonMode2(opts) && row?.status && row.status !== last) {
69448
70078
  last = row.status;
69449
70079
  process.stderr.write(` ${import_picocolors5.default.dim(STATUS_WORD[row.status] ?? row.status)}
69450
70080
  `);
@@ -69499,7 +70129,7 @@ async function phoneCall(toRaw, words7, opts) {
69499
70129
  } catch (err) {
69500
70130
  const empty2 = err instanceof WireError && (err.code === "balance_empty" || err.status === 402);
69501
70131
  if (!empty2 || brain === "yours" || opts.webhook) throw err;
69502
- if (!jsonMode(opts)) process.stderr.write(` ${import_picocolors5.default.dim("this account holds no balance; walking up to the payphone instead")}
70132
+ if (!jsonMode2(opts)) process.stderr.write(` ${import_picocolors5.default.dim("this account holds no balance; walking up to the payphone instead")}
69503
70133
  `);
69504
70134
  return await walkUpToThePayphone(opts, {
69505
70135
  to,
@@ -69526,7 +70156,7 @@ async function phoneCall(toRaw, words7, opts) {
69526
70156
  const ended = await waitForCall(keys2.wallet, phoneId, placed.callId, {
69527
70157
  maxSeconds,
69528
70158
  onTick: (c) => {
69529
- if (jsonMode(opts) || c.status === last) return;
70159
+ if (jsonMode2(opts) || c.status === last) return;
69530
70160
  last = c.status;
69531
70161
  process.stderr.write(` ${import_picocolors5.default.dim(STATUS_WORD[c.status] ?? c.status)}
69532
70162
  `);
@@ -69680,6 +70310,50 @@ var import_picocolors6 = __toESM(require_picocolors(), 1);
69680
70310
 
69681
70311
  // src/lib/inbox-wire.ts
69682
70312
  init_passwords_wire();
70313
+
70314
+ // src/lib/press-mail.ts
70315
+ function pressLinkAllowed(link, site) {
70316
+ if (typeof link !== "string" || link.length > 4096) return false;
70317
+ let url;
70318
+ try {
70319
+ url = new URL(link);
70320
+ } catch {
70321
+ return false;
70322
+ }
70323
+ if (url.protocol !== "https:" || url.username || url.password) return false;
70324
+ const host2 = url.hostname.toLowerCase();
70325
+ const bare = site.toLowerCase().replace(/^www\./, "");
70326
+ return host2 === bare || host2.endsWith(`.${bare}`);
70327
+ }
70328
+ function pressSenderAllowed(fromAddr, site, mailers = []) {
70329
+ const domain = (fromAddr.split("@").pop() ?? "").trim().toLowerCase().replace(/>$/, "");
70330
+ const bare = site.toLowerCase().replace(/^www\./, "");
70331
+ if (domain === bare || domain.endsWith(`.${bare}`)) return true;
70332
+ return mailers.map((m) => m.toLowerCase()).some((m) => domain === m || domain.endsWith(`.${m}`));
70333
+ }
70334
+ var LABELED_LINE_RE = /\b(code|verification|verify|otp|pin|passcode|one[- ]time)\b/i;
70335
+ function pressMailOf(mail, site) {
70336
+ const text = `${mail.subject ?? ""}
70337
+ ${mail.text ?? ""}`.slice(0, 8e3).replace(/https?:\/\/[^\s"'<>]+/g, " ");
70338
+ let code = null;
70339
+ for (const line2 of text.split(/\r?\n/)) {
70340
+ if (!LABELED_LINE_RE.test(line2)) continue;
70341
+ const m = line2.match(/\b\d{4,8}\b/);
70342
+ if (m) {
70343
+ code = m[0];
70344
+ break;
70345
+ }
70346
+ }
70347
+ code = code ?? text.match(/\b\d{6}\b/)?.[0] ?? text.match(/\b\d{4,8}\b/)?.[0] ?? null;
70348
+ const blob = `${mail.text ?? ""}
70349
+ ${mail.html ?? ""}`.slice(0, 2e5).replace(/&amp;/g, "&");
70350
+ const links = [...blob.matchAll(/https:\/\/[^\s"'<>)\]]+/g)].map((m) => m[0].replace(/[.,;:!?]+$/, "")).filter((l) => pressLinkAllowed(l, site));
70351
+ const withToken = links.find((l) => /[?&](token|verificationToken)=/i.test(l));
70352
+ const pathLike = links.find((l) => /\/(login|signup|sign-up|verify|verification|confirm|otp|auth|magic)/i.test(new URL(l).pathname));
70353
+ return { code, link: withToken ?? pathLike ?? null };
70354
+ }
70355
+
70356
+ // src/lib/inbox-wire.ts
69683
70357
  async function leaseInbox(wallet, args = {}) {
69684
70358
  const body = {};
69685
70359
  if (args.name) body.name = args.name;
@@ -69747,6 +70421,42 @@ ${opened.text}`, pattern);
69747
70421
  }
69748
70422
  }
69749
70423
  }
70424
+ async function waitSiteMail(wallet, inboxId, { site, mailers = [], since, timeoutSeconds = 60 }) {
70425
+ const deadline = Date.now() + timeoutSeconds * 1e3;
70426
+ let after = since;
70427
+ let key = null;
70428
+ for (; ; ) {
70429
+ const remaining = Math.max(1, Math.ceil((deadline - Date.now()) / 1e3));
70430
+ const body = { timeoutSeconds: remaining };
70431
+ if (after) body.since = after;
70432
+ let out;
70433
+ try {
70434
+ out = expectOk(await signedFetch(wallet, "POST", lanePath(`/inboxes/${encodeURIComponent(inboxId)}/wait-code`), body, (remaining + 30) * 1e3), "the site's mail");
70435
+ } catch (err) {
70436
+ if (err instanceof WireError && err.status === 408) return null;
70437
+ throw err;
70438
+ }
70439
+ if (!out.sealed) return null;
70440
+ const rows = Array.isArray(out.messages) ? out.messages : [];
70441
+ key = key ?? await mailKeyFor(wallet);
70442
+ if (!key) throw new Error("this inbox is sealed and this account has no mail key registered");
70443
+ for (const row of rows) {
70444
+ if (row.direction === "out") continue;
70445
+ let opened;
70446
+ try {
70447
+ opened = openMessage(key, inboxId, row);
70448
+ } catch {
70449
+ continue;
70450
+ }
70451
+ if (!pressSenderAllowed(opened.from, site, mailers)) continue;
70452
+ const found = pressMailOf(opened, site);
70453
+ if (found.code || found.link) return { ...found, from: opened.from, receivedAt: opened.receivedAt };
70454
+ }
70455
+ const newest = rows.map((r) => r.receivedAt).filter(Boolean).sort().pop();
70456
+ if (newest) after = new Date(new Date(newest).getTime() + 1).toISOString();
70457
+ if (Date.now() >= deadline) return null;
70458
+ }
70459
+ }
69750
70460
  async function inboxDomain() {
69751
70461
  let res;
69752
70462
  try {
@@ -69762,8 +70472,8 @@ async function inboxDomain() {
69762
70472
 
69763
70473
  // src/commands/email.ts
69764
70474
  init_passwords_wire();
69765
- var SITE4 = (process.env.AGENTGATES_ORIGIN || "https://agentgates.ai").replace(/\/$/, "");
69766
- var usd4 = (v) => {
70475
+ var SITE3 = (process.env.AGENTGATES_ORIGIN || "https://agentgates.ai").replace(/\/$/, "");
70476
+ var usd3 = (v) => {
69767
70477
  const n2 = Number(v);
69768
70478
  if (Number.isInteger(n2)) return `$${n2}`;
69769
70479
  const [whole, frac = ""] = n2.toFixed(6).replace(/0+$/, "").split(".");
@@ -69786,7 +70496,7 @@ function emailSlice(body) {
69786
70496
  return out;
69787
70497
  }
69788
70498
  async function emailPricing(opts) {
69789
- const res = await fetch(`${SITE4}/api/account/catalog`, { headers: { accept: "application/json" } });
70499
+ const res = await fetch(`${SITE3}/api/account/catalog`, { headers: { accept: "application/json" } });
69790
70500
  if (!res.ok) throw new Error(`email catalog: HTTP ${res.status}`);
69791
70501
  const body = await res.json();
69792
70502
  const slice = emailSlice(body);
@@ -69827,7 +70537,7 @@ async function emailPricing(opts) {
69827
70537
  }
69828
70538
  for (const f2 of families) {
69829
70539
  const rows = byFamily.get(f2).sort((a, b2) => a.units - b2.units);
69830
- const cells = rows.map((p) => `${import_picocolors6.default.cyan(usd4(p.priceUsd).padStart(4))}${import_picocolors6.default.dim(`/${p.units} days`.padEnd(10))}`).join(" ");
70540
+ const cells = rows.map((p) => `${import_picocolors6.default.cyan(usd3(p.priceUsd).padStart(4))}${import_picocolors6.default.dim(`/${p.units} days`.padEnd(10))}`).join(" ");
69831
70541
  const lead = rows[0];
69832
70542
  const cap = [
69833
70543
  lead.inboxes ? `${lead.inboxes} inbox${lead.inboxes === 1 ? "" : "es"}` : "",
@@ -69841,8 +70551,8 @@ async function emailPricing(opts) {
69841
70551
  const send2 = slice.sendOverflow?.priceUsd;
69842
70552
  const wait2 = body.phoneUsage?.waitCodeUsd;
69843
70553
  const meter = [
69844
- send2 ? `send ${usd4(send2)}` : "",
69845
- wait2 !== void 0 ? `wait-code ${Number(wait2) === 0 ? "free" : usd4(wait2)}` : ""
70554
+ send2 ? `send ${usd3(send2)}` : "",
70555
+ wait2 !== void 0 ? `wait-code ${Number(wait2) === 0 ? "free" : usd3(wait2)}` : ""
69846
70556
  ].filter(Boolean).join(" \xB7 ");
69847
70557
  if (meter) process.stdout.write(`
69848
70558
  ${import_picocolors6.default.dim(`usage, from the prepaid balance: ${meter}`)}
@@ -69852,7 +70562,7 @@ async function emailPricing(opts) {
69852
70562
  const bal = slice.balance;
69853
70563
  if (bal?.note) process.stdout.write(` ${import_picocolors6.default.dim(bal.note)}
69854
70564
  `);
69855
- else if (bal?.minTopUpUsd) process.stdout.write(` ${import_picocolors6.default.dim(`top up any amount from ${usd4(bal.minTopUpUsd)}`)}
70565
+ else if (bal?.minTopUpUsd) process.stdout.write(` ${import_picocolors6.default.dim(`top up any amount from ${usd3(bal.minTopUpUsd)}`)}
69856
70566
  `);
69857
70567
  const nets = [...new Set((plans[0]?.byNetwork ?? []).map((n2) => n2.network))];
69858
70568
  if (nets.length) process.stdout.write(`
@@ -69865,7 +70575,7 @@ function emailDoor(first) {
69865
70575
  process.stdout.write(
69866
70576
  `
69867
70577
  ${first}, and this CLI has no signer yet.
69868
- Do it from the wallet, one biometric: ${import_picocolors6.default.cyan(`${SITE4}/email`)}
70578
+ Do it from the wallet, one biometric: ${import_picocolors6.default.cyan(`${SITE3}/email`)}
69869
70579
  Prices from here: ${import_picocolors6.default.dim("agentgates email pricing")}
69870
70580
 
69871
70581
  `
@@ -70026,7 +70736,7 @@ function emit3(opts, data4, human) {
70026
70736
  }
70027
70737
  human();
70028
70738
  }
70029
- function fail(opts, err) {
70739
+ function fail2(opts, err) {
70030
70740
  const message = err instanceof Error ? err.message : String(err);
70031
70741
  const code = err?.code;
70032
70742
  if (opts.json || !process.stdout.isTTY) {
@@ -70084,7 +70794,7 @@ async function keysList(opts) {
70084
70794
  const rows = await listLoginKeys(keys2.wallet);
70085
70795
  emit3(opts, { ok: true, address: keys2.state.address, keys: rows, thisMachine: keys2.state.apiKeyPrefix ?? null }, () => printRows(rows, keys2.state.apiKeyPrefix ?? null));
70086
70796
  } catch (err) {
70087
- fail(opts, err);
70797
+ fail2(opts, err);
70088
70798
  }
70089
70799
  }
70090
70800
  async function keysCreate(opts) {
@@ -70132,7 +70842,7 @@ async function keysCreate(opts) {
70132
70842
  );
70133
70843
  });
70134
70844
  } catch (err) {
70135
- fail(opts, err);
70845
+ fail2(opts, err);
70136
70846
  }
70137
70847
  }
70138
70848
  async function keysFolders(id2, args, opts) {
@@ -70159,7 +70869,7 @@ async function keysFolders(id2, args, opts) {
70159
70869
  `);
70160
70870
  });
70161
70871
  } catch (err) {
70162
- fail(opts, err);
70872
+ fail2(opts, err);
70163
70873
  }
70164
70874
  }
70165
70875
  async function keysRevoke(id2, opts) {
@@ -70177,7 +70887,7 @@ async function keysRevoke(id2, opts) {
70177
70887
  printRows(out.keys, wasMine ? null : keys2.state.apiKeyPrefix ?? null);
70178
70888
  });
70179
70889
  } catch (err) {
70180
- fail(opts, err);
70890
+ fail2(opts, err);
70181
70891
  }
70182
70892
  }
70183
70893
  async function adoptKey(secret, name) {
@@ -70209,7 +70919,7 @@ async function keysUse(secret, opts) {
70209
70919
  );
70210
70920
  });
70211
70921
  } catch (err) {
70212
- fail(opts, err);
70922
+ fail2(opts, err);
70213
70923
  }
70214
70924
  }
70215
70925
 
@@ -70338,11 +71048,11 @@ async function serveWordsOnce(args) {
70338
71048
  let port = 0;
70339
71049
  let done = () => {
70340
71050
  };
70341
- let fail10 = () => {
71051
+ let fail11 = () => {
70342
71052
  };
70343
71053
  const settled = new Promise((resolve3, reject) => {
70344
71054
  done = resolve3;
70345
- fail10 = reject;
71055
+ fail11 = reject;
70346
71056
  });
70347
71057
  const server = createServer((req, res) => {
70348
71058
  const url = new URL(req.url ?? "/", "http://127.0.0.1");
@@ -70368,7 +71078,7 @@ async function serveWordsOnce(args) {
70368
71078
  const timer = setTimeout(() => {
70369
71079
  if (!taken) {
70370
71080
  server.close();
70371
- fail10(new Error(`nobody took the session in ${Math.round(args.waitMs / 1e3)}s`));
71081
+ fail11(new Error(`nobody took the session in ${Math.round(args.waitMs / 1e3)}s`));
70372
71082
  }
70373
71083
  }, args.waitMs);
70374
71084
  try {
@@ -70382,11 +71092,11 @@ async function receiveKeyOnce(args) {
70382
71092
  let taken = false;
70383
71093
  let done = () => {
70384
71094
  };
70385
- let fail10 = () => {
71095
+ let fail11 = () => {
70386
71096
  };
70387
71097
  const settled = new Promise((resolve3, reject) => {
70388
71098
  done = resolve3;
70389
- fail10 = reject;
71099
+ fail11 = reject;
70390
71100
  });
70391
71101
  const server = createServer(async (req, res) => {
70392
71102
  const url = new URL(req.url ?? "/", "http://127.0.0.1");
@@ -70416,7 +71126,7 @@ async function receiveKeyOnce(args) {
70416
71126
  const timer = setTimeout(() => {
70417
71127
  if (!taken) {
70418
71128
  server.close();
70419
- fail10(new Error(`nobody handed a session over in ${Math.round(args.waitMs / 1e3)}s`));
71129
+ fail11(new Error(`nobody handed a session over in ${Math.round(args.waitMs / 1e3)}s`));
70420
71130
  }
70421
71131
  }, args.waitMs);
70422
71132
  try {
@@ -70431,9 +71141,9 @@ function handoffCode(code, port) {
70431
71141
 
70432
71142
  // src/commands/session.ts
70433
71143
  init_passwords_wire();
70434
- var jsonMode2 = (opts) => opts.json === true || !process.stdout.isTTY;
71144
+ var jsonMode3 = (opts) => opts.json === true || !process.stdout.isTTY;
70435
71145
  function refuse2(opts, error, code = null) {
70436
- if (jsonMode2(opts)) process.stdout.write(JSON.stringify({ ok: false, code, error }, null, 2) + "\n");
71146
+ if (jsonMode3(opts)) process.stdout.write(JSON.stringify({ ok: false, code, error }, null, 2) + "\n");
70437
71147
  else process.stderr.write(` ${error}${code ? import_picocolors8.default.dim(` (${code})`) : ""}
70438
71148
  `);
70439
71149
  process.exit(1);
@@ -70462,7 +71172,7 @@ async function sessionOpen(opts) {
70462
71172
  address,
70463
71173
  waitMs,
70464
71174
  onUrl: (url, port) => {
70465
- if (jsonMode2(opts)) {
71175
+ if (jsonMode3(opts)) {
70466
71176
  process.stdout.write(JSON.stringify({ ok: true, status: "waiting", url, port, address, waitSeconds: waitMs / 1e3 }) + "\n");
70467
71177
  } else {
70468
71178
  process.stdout.write(`
@@ -70477,7 +71187,7 @@ async function sessionOpen(opts) {
70477
71187
  });
70478
71188
  }
70479
71189
  });
70480
- if (jsonMode2(opts)) process.stdout.write(JSON.stringify({ ok: true, status: "handed", address }) + "\n");
71190
+ if (jsonMode3(opts)) process.stdout.write(JSON.stringify({ ok: true, status: "handed", address }) + "\n");
70481
71191
  else process.stdout.write(` ${import_picocolors8.default.green("\u2713")} handed over; the browser is this account now.
70482
71192
 
70483
71193
  `);
@@ -70492,7 +71202,7 @@ async function sessionReceive(opts) {
70492
71202
  waitMs,
70493
71203
  onCode: (code, port) => {
70494
71204
  const typed = handoffCode(code, port);
70495
- if (jsonMode2(opts)) {
71205
+ if (jsonMode3(opts)) {
70496
71206
  process.stdout.write(JSON.stringify({ ok: true, status: "waiting", code: typed, port, waitSeconds: waitMs / 1e3 }) + "\n");
70497
71207
  } else {
70498
71208
  process.stdout.write(`
@@ -70506,7 +71216,7 @@ async function sessionReceive(opts) {
70506
71216
  }
70507
71217
  });
70508
71218
  const { address, prefix, sealed, mode } = await adoptKey(key, `computer ${hostname2()}`);
70509
- if (jsonMode2(opts)) process.stdout.write(JSON.stringify({ ok: true, status: "received", address, prefix, sealed, mode, path: passwordsKeyPath() }) + "\n");
71219
+ if (jsonMode3(opts)) process.stdout.write(JSON.stringify({ ok: true, status: "received", address, prefix, sealed, mode, path: passwordsKeyPath() }) + "\n");
70510
71220
  else {
70511
71221
  process.stdout.write(` ${import_picocolors8.default.green("\u2713")} this CLI runs on ${import_picocolors8.default.bold(prefix)} for ${address}
70512
71222
  `);
@@ -70549,17 +71259,17 @@ function loginKeyLines(login2) {
70549
71259
  ` : ` ${import_picocolors9.default.dim(`login key here: ${login2.prefix}; every call sends it`)}
70550
71260
  `;
70551
71261
  }
70552
- var SITE5 = (process.env.AGENTGATES_ORIGIN || "https://agentgates.ai").replace(/\/$/, "");
70553
- var jsonMode3 = (opts) => opts.json === true || !process.stdout.isTTY;
71262
+ var SITE4 = (process.env.AGENTGATES_ORIGIN || "https://agentgates.ai").replace(/\/$/, "");
71263
+ var jsonMode4 = (opts) => opts.json === true || !process.stdout.isTTY;
70554
71264
  function emit4(opts, data4, human) {
70555
- if (jsonMode3(opts)) {
71265
+ if (jsonMode4(opts)) {
70556
71266
  process.stdout.write(JSON.stringify(data4, null, 2) + "\n");
70557
71267
  return;
70558
71268
  }
70559
71269
  human();
70560
71270
  }
70561
71271
  function refuse3(opts, error, code, extra = {}) {
70562
- if (jsonMode3(opts)) {
71272
+ if (jsonMode4(opts)) {
70563
71273
  process.stdout.write(JSON.stringify({ ok: false, code, error, ...extra }, null, 2) + "\n");
70564
71274
  } else {
70565
71275
  process.stderr.write(` ${error}${code ? import_picocolors9.default.dim(` (${code})`) : ""}
@@ -70613,7 +71323,7 @@ function parseInt10(raw, name, dflt, min, max) {
70613
71323
  if (!Number.isInteger(n2) || n2 < min || n2 > max) throw new PasswordsSealError(`${name} is a whole number from ${min} to ${max}`);
70614
71324
  return n2;
70615
71325
  }
70616
- var usd5 = (v) => {
71326
+ var usd4 = (v) => {
70617
71327
  const n2 = Number(v);
70618
71328
  if (Number.isInteger(n2)) return `$${n2}`;
70619
71329
  const [whole, frac = ""] = n2.toFixed(6).replace(/0+$/, "").split(".");
@@ -70636,7 +71346,7 @@ function passwordsSlice(body) {
70636
71346
  return out;
70637
71347
  }
70638
71348
  async function passwordsPricing(opts) {
70639
- const res = await fetch(`${SITE5}/api/account/catalog`, { headers: { accept: "application/json" } });
71349
+ const res = await fetch(`${SITE4}/api/account/catalog`, { headers: { accept: "application/json" } });
70640
71350
  if (!res.ok) throw new Error(`passwords catalog: HTTP ${res.status}`);
70641
71351
  const body = await res.json();
70642
71352
  const slice = passwordsSlice(body);
@@ -70677,7 +71387,7 @@ async function passwordsPricing(opts) {
70677
71387
  }
70678
71388
  for (const f2 of families) {
70679
71389
  const rows = byFamily.get(f2).sort((a, b2) => a.units - b2.units);
70680
- const cells = rows.map((p) => `${import_picocolors9.default.cyan(usd5(p.priceUsd).padStart(4))}${import_picocolors9.default.dim(`/${p.units} days`.padEnd(10))}`).join(" ");
71390
+ const cells = rows.map((p) => `${import_picocolors9.default.cyan(usd4(p.priceUsd).padStart(4))}${import_picocolors9.default.dim(`/${p.units} days`.padEnd(10))}`).join(" ");
70681
71391
  const lead = rows[0];
70682
71392
  const cap = [
70683
71393
  lead.passwords ? `${lead.passwords.toLocaleString()} passwords` : "",
@@ -70691,8 +71401,8 @@ async function passwordsPricing(opts) {
70691
71401
  const use = slice.passwordsUsage?.useUsd;
70692
71402
  const login2 = slice.passwordsUsage?.loginUsd;
70693
71403
  const meter = [
70694
- use ? `a code or key ${usd5(use)}` : "",
70695
- login2 ? `a login ${usd5(login2)}` : ""
71404
+ use ? `a code or key ${usd4(use)}` : "",
71405
+ login2 ? `a login ${usd4(login2)}` : ""
70696
71406
  ].filter(Boolean).join(" \xB7 ");
70697
71407
  if (meter) process.stdout.write(`
70698
71408
  ${import_picocolors9.default.dim(`past the daily uses, from the agent's prepaid balance: ${meter}`)}
@@ -70789,6 +71499,14 @@ async function passwordsAdd(opts) {
70789
71499
  const kind = opts.kind ?? "login";
70790
71500
  let password = opts.password;
70791
71501
  if (opts.passwordStdin) password = readFileSync(0, "utf8").replace(/\r?\n$/, "");
71502
+ if (opts.through) {
71503
+ if (kind !== "login") throw new PasswordsSealError("--through makes a login row");
71504
+ if (password !== void 0 || opts.passwordStdin) throw new PasswordsSealError("--through stores no password: the site signs in with the login row it names");
71505
+ const { passwords: passwords2 } = await listRows(wallet);
71506
+ const row2 = passwords2.find((r) => r.id === opts.through);
71507
+ if (!row2) throw new PasswordsSealError(`this key holds no row ${opts.through} (agentgates passwords list)`);
71508
+ if (row2.kind !== "login") throw new PasswordsSealError("--through names a login row: the account the site signs in through");
71509
+ }
70792
71510
  const secret = {
70793
71511
  password,
70794
71512
  totpSeed: opts.totpSeed,
@@ -70822,7 +71540,7 @@ async function passwordsAdd(opts) {
70822
71540
  if (!password || password === "-") throw new PasswordsSealError("a mailbox row needs --password, the app password (Gmail: myaccount.google.com/apppasswords, with 2-Step Verification on). An inbox leased here needs none: store the row on its own address instead.");
70823
71541
  }
70824
71542
  }
70825
- const payload = buildSecretPayload({ kind, secret, hosts, notes: opts.notes, backupCodes: readArg(opts.backupCodes), device });
71543
+ const payload = buildSecretPayload({ kind, secret, hosts, notes: opts.notes, backupCodes: readArg(opts.backupCodes), device, signsInThrough: Boolean(opts.through) });
70826
71544
  let username;
70827
71545
  if (opts.username !== void 0 && opts.username !== "") {
70828
71546
  if (kind !== "login" && kind !== "mailbox") throw new PasswordsSealError("only a login or a mailbox carries a username");
@@ -71037,6 +71755,16 @@ function printUseAnswer(opts, status4, body) {
71037
71755
  if (typeof result.codesLeft === "number") process.stdout.write(` ${import_picocolors9.default.dim(`${result.codesLeft} backup code${result.codesLeft === 1 ? "" : "s"} left`)}
71038
71756
  `);
71039
71757
  if (result.device && typeof result.device === "object") process.stdout.write(` ${import_picocolors9.default.dim(`the site created a device credential for ${String(result.device.rpId ?? "")}; agentgates passwords device seals it into the row`)}
71758
+ `);
71759
+ if (result.apiKey && typeof result.apiKey === "object" && result.apiKey.kept === true) {
71760
+ process.stdout.write(` ${import_picocolors9.default.green("\u2713")} the key is kept inside the CVM in this row; a header use fills {apiKey} with it
71761
+ `);
71762
+ }
71763
+ for (const field of Array.isArray(result.sealed) ? result.sealed : []) {
71764
+ process.stdout.write(` ${import_picocolors9.default.dim(`${field} is sealed to the owner (agentgates passwords open-sealed opens it with the owner's key)`)}
71765
+ `);
71766
+ }
71767
+ if (result.withheld === true) process.stdout.write(` ${import_picocolors9.default.dim("the answer had no field where the seal looked for it, so none of it was handed back")}
71040
71768
  `);
71041
71769
  for (const s of Array.isArray(result.solved) ? result.solved : []) {
71042
71770
  process.stdout.write(` ${import_picocolors9.default.dim(`passed a ${String(s.kind)} check ${s.how === "service" ? "through the solver service" : "by hand"} in ${Math.max(1, Math.round(Number(s.ms ?? 0) / 1e3))}s`)}
@@ -71117,6 +71845,10 @@ async function passwordsUse(opts) {
71117
71845
  if (use !== "login" && use !== "session") throw new PasswordsSealError("--mailbox goes with the login or session use");
71118
71846
  request.mailbox = opts.mailbox;
71119
71847
  }
71848
+ if (opts.asRow) {
71849
+ if (use !== "login") throw new PasswordsSealError("--as-row goes with the login use");
71850
+ request.credential = opts.asRow;
71851
+ }
71120
71852
  let workflowRow = null;
71121
71853
  if (opts.workflow) {
71122
71854
  if (use !== "login") throw new PasswordsSealError("--workflow goes with the login use");
@@ -71144,7 +71876,7 @@ function waitOptionsOf(opts) {
71144
71876
  return {
71145
71877
  waitSeconds: opts.wait !== void 0 ? parseInt10(opts.wait, "--wait", 0, 0, 3600) : null,
71146
71878
  noWait: opts.noWait,
71147
- note: jsonMode3(opts) ? void 0 : (line2) => process.stderr.write(` ${import_picocolors9.default.dim(line2)}
71879
+ note: jsonMode4(opts) ? void 0 : (line2) => process.stderr.write(` ${import_picocolors9.default.dim(line2)}
71148
71880
  `)
71149
71881
  };
71150
71882
  }
@@ -71153,6 +71885,9 @@ async function postUseAndWait(wallet, rowId, firstBody, opts = {}) {
71153
71885
  {
71154
71886
  let lastBody = firstBody;
71155
71887
  let broughtCode = null;
71888
+ let pressNamed = false;
71889
+ let pressBrought = false;
71890
+ let ownerNamed = false;
71156
71891
  let answer = await postUse(wallet, rowId, firstBody);
71157
71892
  const startedAt = Date.now();
71158
71893
  const boxBudgetEnd = waitCap !== null ? startedAt + waitCap * 1e3 : startedAt + 24e4;
@@ -71160,13 +71895,46 @@ async function postUseAndWait(wallet, rowId, firstBody, opts = {}) {
71160
71895
  const body = answer.body ?? {};
71161
71896
  if (answer.status === 202) {
71162
71897
  if (!body.useId) break;
71163
- if (body.code === "attend_pending") break;
71898
+ const heldForOwner = body.code === "attend_pending" && !body.view;
71899
+ if (body.code === "attend_pending" && !heldForOwner) break;
71164
71900
  const expiresAt = body.expiresAt ? Date.parse(body.expiresAt) : NaN;
71165
71901
  const deadline = Math.min(
71166
71902
  Number.isFinite(expiresAt) ? expiresAt : Date.now() + 6e5,
71167
71903
  waitCap !== null ? startedAt + waitCap * 1e3 : Number.POSITIVE_INFINITY
71168
71904
  );
71169
71905
  if (Date.now() >= deadline) break;
71906
+ if (body.code === "press_pending") {
71907
+ const press = body;
71908
+ if (!pressNamed) {
71909
+ opts.note?.(`${press.site ?? "the site"} takes this press only from the owner's own browser: open ${press.open ?? "its sign-up page"} and press Continue`);
71910
+ pressNamed = true;
71911
+ }
71912
+ const asked = firstBody.request ?? {};
71913
+ const site = typeof asked.url === "string" ? siteOfUrl(asked.url) : null;
71914
+ if (!pressBrought && site && press.source?.sealed === true && press.source.kind === "inbox" && typeof press.source.id === "string") {
71915
+ try {
71916
+ const mail = await waitSiteMail(wallet, press.source.id, { site, since: press.askedAt ?? null, timeoutSeconds: Math.max(5, Math.min(60, Math.floor((deadline - Date.now()) / 1e3))) });
71917
+ if (mail?.link) {
71918
+ pressBrought = true;
71919
+ opts.note?.(`the site's mail is in; the CVM finishes the sign-up on its link`);
71920
+ lastBody = { ...firstBody, request: { ...asked, verifyUrl: mail.link, ...mail.code ? { otpCode: mail.code } : {} }, useId: body.useId };
71921
+ answer = await postUse(wallet, rowId, lastBody);
71922
+ continue;
71923
+ }
71924
+ if (mail?.code) {
71925
+ pressBrought = true;
71926
+ opts.note?.(`the site's mail carries no link the CVM may finish on: type ${mail.code} in the browser you pressed in`);
71927
+ lastBody = { ...firstBody, request: { ...asked, otpCode: mail.code }, useId: body.useId };
71928
+ answer = await postUse(wallet, rowId, lastBody);
71929
+ continue;
71930
+ }
71931
+ answer = await postUse(wallet, rowId, { ...firstBody, useId: body.useId });
71932
+ continue;
71933
+ } catch (err) {
71934
+ opts.note?.(`could not read the sealed inbox here (${err instanceof Error ? err.message : String(err)}); waiting on the owner`);
71935
+ }
71936
+ }
71937
+ }
71170
71938
  const source = body.source;
71171
71939
  if (body.code === "code_pending" && source?.sealed === true && source.kind === "inbox" && typeof source.id === "string" && !broughtCode) {
71172
71940
  opts.note?.(`the site sent a code to a sealed inbox; reading it with this key`);
@@ -71181,7 +71949,15 @@ async function postUseAndWait(wallet, rowId, firstBody, opts = {}) {
71181
71949
  opts.note?.(`could not read the sealed inbox here (${err instanceof Error ? err.message : String(err)}); waiting for the owner`);
71182
71950
  }
71183
71951
  }
71184
- opts.note?.(body.error ?? "waiting for the owner");
71952
+ if (heldForOwner) {
71953
+ if (!ownerNamed) {
71954
+ const wall = body.wall;
71955
+ opts.note?.(`a step only a person completes${typeof wall === "string" && wall ? ` (${wall})` : ""}: the page is on the owner's board; waiting for their Done`);
71956
+ ownerNamed = true;
71957
+ }
71958
+ } else {
71959
+ opts.note?.(body.error ?? "waiting for the owner");
71960
+ }
71185
71961
  lastBody = { ...firstBody, useId: body.useId, wait: 25 };
71186
71962
  answer = await postUse(wallet, rowId, lastBody);
71187
71963
  continue;
@@ -71321,6 +72097,80 @@ async function storeSealedRow(wallet, input) {
71321
72097
  cvmKeyId: att.keyId
71322
72098
  });
71323
72099
  }
72100
+ var AUTO_OWNER_HOPS = 8;
72101
+ var AUTO_OWNER_PAUSE_SECONDS = 10;
72102
+ var PHONE_FIELD = { x: 640, y: 438 };
72103
+ var DEVICE_FIELD = { x: 640, y: 363 };
72104
+ function nationalDigits(number2) {
72105
+ const digits = number2.replace(/\D/g, "");
72106
+ return digits.length === 11 && digits.startsWith("1") ? digits.slice(1) : digits;
72107
+ }
72108
+ async function heldCardOf(wallet, useId) {
72109
+ const out = expectOk(await signedFetch(wallet, "GET", lanePath("/passwords/pending")), "the waiting cards");
72110
+ const card2 = (out.pending ?? []).find((c) => c.id === useId);
72111
+ if (!card2 || !card2.secretId || !card2.attend?.token) throw new PasswordsSealError("the held page is not on this key's waiting cards");
72112
+ return { row: card2.secretId, useId, token: card2.attend.token };
72113
+ }
72114
+ async function heldInput(card2, input) {
72115
+ const res = await fetch(`${siteOrigin()}/api/passwords/${encodeURIComponent(card2.row)}/attend/${encodeURIComponent(card2.useId)}/input`, {
72116
+ method: "POST",
72117
+ headers: { authorization: `Bearer ${card2.token}`, "content-type": "application/json", accept: "application/json" },
72118
+ body: JSON.stringify({ ...input, view: card2.token })
72119
+ });
72120
+ if (!res.ok) throw new PasswordsSealError(`the held page refused an input (${res.status})`);
72121
+ }
72122
+ var sleepMs = (ms) => new Promise((resolve3) => setTimeout(resolve3, ms));
72123
+ async function answerDeviceCheck(wallet, useId, inboxId, note2) {
72124
+ const card2 = await heldCardOf(wallet, useId);
72125
+ const since = Date.now() - 6e4;
72126
+ const deadline = Date.now() + 9e4;
72127
+ let code = null;
72128
+ while (Date.now() < deadline && !code) {
72129
+ try {
72130
+ const mailed = await waitInboxCode(wallet, inboxId, { timeoutSeconds: 8 });
72131
+ if (mailed.receivedAt && Date.parse(mailed.receivedAt) >= since) code = mailed.code;
72132
+ else await sleepMs(3e3);
72133
+ } catch (err) {
72134
+ if (err instanceof WireError && err.status !== 408) throw err;
72135
+ }
72136
+ }
72137
+ if (!code) throw new PasswordsSealError("no code reached the inbox in ninety seconds");
72138
+ await heldInput(card2, { kind: "click", x: DEVICE_FIELD.x, y: DEVICE_FIELD.y });
72139
+ await sleepMs(400);
72140
+ await heldInput(card2, { kind: "type", text: code });
72141
+ await sleepMs(400);
72142
+ await heldInput(card2, { kind: "key", key: "Enter" });
72143
+ note2?.("the device check's code is typed");
72144
+ }
72145
+ async function answerPhoneCheck(wallet, useId, sms, note2) {
72146
+ const card2 = await heldCardOf(wallet, useId);
72147
+ const digits = nationalDigits(sms.number);
72148
+ if (digits.length < 7) throw new PasswordsSealError("--sms-number is a phone number");
72149
+ await heldInput(card2, { kind: "click", x: PHONE_FIELD.x, y: PHONE_FIELD.y });
72150
+ await sleepMs(400);
72151
+ await heldInput(card2, { kind: "type", text: digits });
72152
+ await sleepMs(400);
72153
+ const typedAt = Date.now();
72154
+ await heldInput(card2, { kind: "key", key: "Enter" });
72155
+ note2?.(`the phone check has the number; waiting for its text at ${sms.id}`);
72156
+ const deadline = typedAt + 12e4;
72157
+ let code = null;
72158
+ while (Date.now() < deadline && !code) {
72159
+ try {
72160
+ const texted = await waitPhoneCode(wallet, sms.id, { timeoutSeconds: 6 });
72161
+ if (texted.receivedAt && Date.parse(texted.receivedAt) >= typedAt - 3e3) code = texted.code;
72162
+ else await sleepMs(3e3);
72163
+ } catch (err) {
72164
+ if (err instanceof WireError && err.status !== 408 && err.status !== 404) throw err;
72165
+ }
72166
+ }
72167
+ if (!code) throw new PasswordsSealError("no text reached the number in two minutes");
72168
+ await sleepMs(500);
72169
+ await heldInput(card2, { kind: "type", text: code });
72170
+ await sleepMs(400);
72171
+ await heldInput(card2, { kind: "key", key: "Enter" });
72172
+ note2?.("the text's code is typed");
72173
+ }
71324
72174
  async function passwordsSignupFlow(wallet, args, wait2 = {}) {
71325
72175
  let site;
71326
72176
  try {
@@ -71332,21 +72182,55 @@ async function passwordsSignupFlow(wallet, args, wait2 = {}) {
71332
72182
  const source = sourceOf(args);
71333
72183
  if (source?.kind === "phone" && args.email) throw new PasswordsSealError("an account made on a number carries no --email: the number is the identity and the code comes by text");
71334
72184
  const mailbox = source ? source.id : await mailboxRowFor(wallet);
71335
- const password = args.password ?? (args.useId ? void 0 : generatePassword());
72185
+ let asRow = null;
72186
+ if (args.asRow) {
72187
+ if (args.password) throw new PasswordsSealError("--as-row brings its own password: leave --password out");
72188
+ if (!args.useId) {
72189
+ const { passwords: passwords2 } = await listRows(wallet);
72190
+ const row = passwords2.find((r) => r.id === args.asRow);
72191
+ if (!row) throw new PasswordsSealError(`this key holds no row ${args.asRow} (agentgates passwords list)`);
72192
+ if (row.kind !== "login") throw new PasswordsSealError("--as-row names a login: the account whose sign-in the site takes");
72193
+ const opened = parseSecretPayload(openDurable(await revealRow(wallet, row.id), await signVaultMessage(wallet)).toString("utf8"));
72194
+ const held3 = opened.secret.password;
72195
+ if (typeof held3 !== "string" || !held3) throw new PasswordsSealError("that login holds no password");
72196
+ asRow = { username: row.username ?? void 0, password: held3 };
72197
+ }
72198
+ }
72199
+ const password = asRow?.password ?? args.password ?? (args.useId ? void 0 : generatePassword());
71336
72200
  const request = { url: args.url, ...password !== void 0 ? { password } : {} };
71337
72201
  if (source && source.kind !== "mailbox") request.source = { kind: source.kind, id: source.id };
71338
72202
  if (args.email) request.email = args.email;
71339
72203
  if (args.name) request.name = args.name;
71340
72204
  if (args.username) request.username = args.username;
72205
+ else if (asRow?.username) request.username = asRow.username;
71341
72206
  if (args.steps !== void 0) request.steps = args.steps;
71342
72207
  if (args.drive) request.drive = true;
71343
72208
  if (args.birthday) request.birthday = args.birthday;
71344
72209
  if (args.attend || args.useId) request.attend = true;
71345
- const answer = await postUseAndWait(wallet, mailbox, { use: "signup", request, ...args.useId ? { useId: args.useId } : {} }, wait2);
72210
+ let answer = await postUseAndWait(wallet, mailbox, { use: "signup", request, ...args.useId ? { useId: args.useId } : {} }, wait2);
72211
+ if (args.autoOwner && (args.attend || args.useId)) {
72212
+ const { password: _sent, ...continued } = request;
72213
+ for (let hop = 0; hop < AUTO_OWNER_HOPS; hop += 1) {
72214
+ const held3 = answer.body ?? {};
72215
+ if (answer.status !== 202 || held3.code !== "attend_pending" || !held3.useId) break;
72216
+ const wall = String(held3.wall ?? "");
72217
+ if (/phone/i.test(wall) && args.smsId && args.smsNumber) {
72218
+ await answerPhoneCheck(wallet, held3.useId, { id: args.smsId, number: args.smsNumber }, args.note);
72219
+ } else if (/device/i.test(wall) && source?.kind === "inbox") {
72220
+ await answerDeviceCheck(wallet, held3.useId, source.id, args.note);
72221
+ } else if (/did not expect/i.test(wall)) {
72222
+ args.note?.(`a page had not drawn; continuing in ${AUTO_OWNER_PAUSE_SECONDS}s`);
72223
+ await sleepMs(AUTO_OWNER_PAUSE_SECONDS * 1e3);
72224
+ } else {
72225
+ break;
72226
+ }
72227
+ answer = await postUseAndWait(wallet, mailbox, { use: "signup", request: continued, useId: held3.useId }, wait2);
72228
+ }
72229
+ }
71346
72230
  const body = answer.body ?? {};
71347
72231
  const result = body.result ?? {};
71348
72232
  const ok = answer.status === 200 && result.ok === true;
71349
- const storedPassword = password ?? (typeof result.password === "string" ? result.password : void 0);
72233
+ const storedPassword = args.asRow ? void 0 : password ?? (typeof result.password === "string" ? result.password : void 0);
71350
72234
  const email2 = typeof result.email === "string" && result.email ? result.email : args.email ?? null;
71351
72235
  const phone2 = typeof result.phone === "string" ? result.phone : null;
71352
72236
  const signInAs = typeof result.signInAs === "string" ? result.signInAs : null;
@@ -71392,6 +72276,7 @@ async function passwordsSignupFlow(wallet, args, wait2 = {}) {
71392
72276
  // it on and the continue call signs in to the account you made there.
71393
72277
  then: result.then === "signin" || body.then === "signin" ? "signin" : null,
71394
72278
  drove: result.drove ?? body.drove ?? null,
72279
+ ...typeof body.open === "string" ? { open: String(body.open) } : {},
71395
72280
  passwordSet,
71396
72281
  digest: typeof result.digest === "string" ? result.digest : "",
71397
72282
  ...result.cookies !== void 0 ? { cookies: result.cookies } : {},
@@ -71402,7 +72287,12 @@ async function passwordsSignupFlow(wallet, args, wait2 = {}) {
71402
72287
  ...body.chargedUsd !== void 0 ? { chargedUsd: body.chargedUsd } : {},
71403
72288
  stored,
71404
72289
  ...storeError ? { storeError } : {},
71405
- ...ok && passwordSet && storedPassword !== void 0 && (!args.store || storeError) ? { password: storedPassword } : {}
72290
+ // A sign-up that failed AFTER the password went into the form comes back
72291
+ // with it too: the site may still make the account (GitHub made one after
72292
+ // the CVM closed its page on 2026-09-27, and on 2026-09-28 the mailed
72293
+ // confirm link made livefire-agent), and this answer is then the only
72294
+ // place the password is left.
72295
+ ...passwordSet && storedPassword !== void 0 && (ok ? !args.store || storeError : true) ? { password: storedPassword } : {}
71406
72296
  };
71407
72297
  }
71408
72298
  function birthdayOf(raw) {
@@ -71427,10 +72317,23 @@ async function passwordsSignup(opts) {
71427
72317
  }
71428
72318
  const answer = await passwordsSignupFlow(
71429
72319
  wallet,
71430
- { url: opts.url, email: opts.email, name: opts.name, username: opts.username, password: opts.password, mailbox: opts.mailbox, inbox: opts.inbox, phone: opts.phone, label: opts.label, store: opts.store !== false, steps, drive: opts.drive === true, birthday: birthdayOf(opts.birthday), attend: opts.attend === true, useId: opts.useId },
72320
+ { url: opts.url, email: opts.email, name: opts.name, username: opts.username, password: opts.password, mailbox: opts.mailbox, inbox: opts.inbox, phone: opts.phone, label: opts.label, store: opts.store !== false, steps, drive: opts.drive === true, birthday: birthdayOf(opts.birthday), attend: opts.attend !== false, useId: opts.useId, asRow: opts.asRow, autoOwner: opts.autoOwner === true, smsId: opts.smsId, smsNumber: opts.smsNumber, note: jsonMode4(opts) ? void 0 : (line2) => process.stdout.write(` ${import_picocolors9.default.dim(line2)}
72321
+ `) },
71431
72322
  waitOptionsOf(opts)
71432
72323
  );
71433
72324
  emit4(opts, answer, () => {
72325
+ if (answer.code === "press_pending" && answer.useId) {
72326
+ process.stdout.write(
72327
+ `
72328
+ ${import_picocolors9.default.yellow("!")} ${import_picocolors9.default.bold(answer.site)} takes this press only from your own browser
72329
+ ${import_picocolors9.default.dim("open")} ${answer.open ?? answer.url} ${import_picocolors9.default.dim("and press Continue")}
72330
+ ${import_picocolors9.default.dim("use")} ${answer.useId}
72331
+ ${import_picocolors9.default.dim(`then: agentgates passwords signup --url ${answer.url}${answer.source.kind !== "mailbox" ? ` --${answer.source.kind} ${answer.source.id}` : ""} --use-id ${answer.useId} (reads the site's mail; the CVM finishes the sign-up)`)}
72332
+
72333
+ `
72334
+ );
72335
+ return;
72336
+ }
71434
72337
  if (answer.code === "attend_pending" && answer.useId) {
71435
72338
  process.stdout.write(
71436
72339
  `
@@ -71478,6 +72381,8 @@ ${answer.digest.split("\n").slice(0, 12).map((l) => ` ${l}`).join("\n")}
71478
72381
  process.stdout.write(`
71479
72382
  ${answer.error ?? `HTTP ${answer.status}`}${answer.code ? import_picocolors9.default.dim(` (${answer.code})`) : ""}
71480
72383
  ${answer.useId ? ` ${import_picocolors9.default.dim("use")} ${answer.useId}
72384
+ ` : ""}${answer.password ? ` ${import_picocolors9.default.dim("the form took this password; if the site makes the account anyway, it signs in with it:")}
72385
+ ${answer.password}
71481
72386
  ` : ""}${answer.digest ? `
71482
72387
  ${answer.digest.split("\n").slice(0, 12).map((l) => ` ${l}`).join("\n")}
71483
72388
  ` : ""}
@@ -71636,6 +72541,42 @@ async function passwordsInvite(opts) {
71636
72541
  failFrom2(opts, err);
71637
72542
  }
71638
72543
  }
72544
+ function sealedAnswerAad(rowId, field) {
72545
+ return `agentgates-passwords-sealed-answer-v1|${rowId}|${field}`;
72546
+ }
72547
+ async function passwordsOpenSealed(opts) {
72548
+ try {
72549
+ const { wallet } = await requirePasswordsKey();
72550
+ if (!opts.row || !opts.field || !opts.blob) throw new PasswordsSealError("--row, --field and --blob: the row the use ran on, the sealed field's name, and its {sealed} value (or @file)");
72551
+ const blob = (readArg(opts.blob) ?? "").trim();
72552
+ const key = await mailKeyFor(wallet);
72553
+ if (!key) throw new PasswordsSealError("this account has no data key: nothing was sealed to it");
72554
+ let value;
72555
+ try {
72556
+ value = openText(key.dataKey, blob, sealedAnswerAad(opts.row, opts.field));
72557
+ } catch {
72558
+ throw new PasswordsSealError("that blob does not open as this row's field under this account's key");
72559
+ }
72560
+ if (opts.out) {
72561
+ writeFileSync2(opts.out, value, { mode: 384 });
72562
+ emit4(opts, { ok: true, row: opts.row, field: opts.field, out: opts.out, chars: value.length }, () => {
72563
+ process.stdout.write(`
72564
+ ${import_picocolors9.default.green("\u2713")} ${opts.field} opened: ${value.length} characters, written to ${opts.out}
72565
+
72566
+ `);
72567
+ });
72568
+ return;
72569
+ }
72570
+ emit4(opts, { ok: true, row: opts.row, field: opts.field, value }, () => {
72571
+ process.stdout.write(`
72572
+ ${opts.field} ${value}
72573
+
72574
+ `);
72575
+ });
72576
+ } catch (err) {
72577
+ failFrom2(opts, err);
72578
+ }
72579
+ }
71639
72580
 
71640
72581
  // src/commands/browser.ts
71641
72582
  var import_picocolors10 = __toESM(require_picocolors(), 1);
@@ -71738,16 +72679,16 @@ async function waitForTask(wallet, id2, { maxSeconds = 900, everyMs = 5e3, onTic
71738
72679
  }
71739
72680
 
71740
72681
  // src/commands/browser.ts
71741
- var jsonMode4 = (opts) => opts.json === true || !process.stdout.isTTY;
72682
+ var jsonMode5 = (opts) => opts.json === true || !process.stdout.isTTY;
71742
72683
  function emit5(opts, data4, human) {
71743
- if (jsonMode4(opts)) {
72684
+ if (jsonMode5(opts)) {
71744
72685
  process.stdout.write(JSON.stringify(data4, null, 2) + "\n");
71745
72686
  return;
71746
72687
  }
71747
72688
  human();
71748
72689
  }
71749
72690
  function refuse4(opts, error, code, extra = {}) {
71750
- if (jsonMode4(opts)) {
72691
+ if (jsonMode5(opts)) {
71751
72692
  process.stdout.write(JSON.stringify({ ok: false, code, error, ...extra }, null, 2) + "\n");
71752
72693
  } else {
71753
72694
  process.stderr.write(` ${error}${code ? import_picocolors10.default.dim(` (${code})`) : ""}
@@ -71759,7 +72700,7 @@ function failFrom3(opts, err) {
71759
72700
  if (err instanceof WireError) return refuse4(opts, err.message, err.code, { status: err.status });
71760
72701
  return refuse4(opts, err.message ?? String(err), null);
71761
72702
  }
71762
- var usd6 = (v) => {
72703
+ var usd5 = (v) => {
71763
72704
  const n2 = Number(v);
71764
72705
  if (Number.isInteger(n2)) return `$${n2}`;
71765
72706
  const [whole, frac = ""] = n2.toFixed(6).replace(/0+$/, "").split(".");
@@ -71792,9 +72733,9 @@ function printTask(t, full) {
71792
72733
  `);
71793
72734
  process.stdout.write(` ${t.goal}
71794
72735
  `);
71795
- if (t.status === "done") process.stdout.write(` ${import_picocolors10.default.dim(`charged ${usd6(t.chargedUsd)}`)}
72736
+ if (t.status === "done") process.stdout.write(` ${import_picocolors10.default.dim(`charged ${usd5(t.chargedUsd)}`)}
71796
72737
  `);
71797
- else if (t.status === "queued" || t.status === "running") process.stdout.write(` ${import_picocolors10.default.dim(`reserved ${usd6(t.reservedUsd)}`)}
72738
+ else if (t.status === "queued" || t.status === "running") process.stdout.write(` ${import_picocolors10.default.dim(`reserved ${usd5(t.reservedUsd)}`)}
71798
72739
  `);
71799
72740
  if (t.answer) process.stdout.write(`
71800
72741
  ${import_picocolors10.default.bold("Answer")}
@@ -71839,7 +72780,7 @@ async function browserPricing(opts) {
71839
72780
  `);
71840
72781
  return;
71841
72782
  }
71842
- if (usage?.stepUsd) process.stdout.write(` ${import_picocolors10.default.cyan(usd6(usage.stepUsd))} ${import_picocolors10.default.dim("a step, from the prepaid balance")}
72783
+ if (usage?.stepUsd) process.stdout.write(` ${import_picocolors10.default.cyan(usd5(usage.stepUsd))} ${import_picocolors10.default.dim("a step, from the prepaid balance")}
71843
72784
  `);
71844
72785
  if (usage) {
71845
72786
  process.stdout.write(` ${import_picocolors10.default.dim(`steps 1 to ${usage.maxSteps} (default ${usage.defaultSteps}) \xB7 ${usage.minSeconds} to ${usage.maxSeconds} seconds \xB7 up to ${usage.maxHosts} extra hosts`)}
@@ -71873,8 +72814,8 @@ async function browserBalance(opts) {
71873
72814
 
71874
72815
  `);
71875
72816
  if (balance2.balance) {
71876
- process.stdout.write(` ${import_picocolors10.default.cyan(usd6(balance2.balance.availableUsd))} ${import_picocolors10.default.dim("available")}`);
71877
- if (Number(balance2.balance.reservedUsd) > 0) process.stdout.write(import_picocolors10.default.dim(` \xB7 ${usd6(balance2.balance.reservedUsd)} reserved by tasks in flight`));
72817
+ process.stdout.write(` ${import_picocolors10.default.cyan(usd5(balance2.balance.availableUsd))} ${import_picocolors10.default.dim("available")}`);
72818
+ if (Number(balance2.balance.reservedUsd) > 0) process.stdout.write(import_picocolors10.default.dim(` \xB7 ${usd5(balance2.balance.reservedUsd)} reserved by tasks in flight`));
71878
72819
  process.stdout.write("\n");
71879
72820
  } else {
71880
72821
  process.stdout.write(` ${import_picocolors10.default.dim("no balance under this key yet; a top-up opens it")}
@@ -71997,7 +72938,7 @@ async function browserRun(url, opts) {
71997
72938
  maxSteps,
71998
72939
  maxSeconds,
71999
72940
  loginRow: opts.login,
72000
- note: jsonMode4(opts) ? void 0 : (line2) => process.stderr.write(` ${import_picocolors10.default.dim(line2)}
72941
+ note: jsonMode5(opts) ? void 0 : (line2) => process.stderr.write(` ${import_picocolors10.default.dim(line2)}
72001
72942
  `)
72002
72943
  });
72003
72944
  if (!opts.wait) {
@@ -72014,7 +72955,7 @@ async function browserRun(url, opts) {
72014
72955
  const settled = await waitForTask(keys2.wallet, task.id, {
72015
72956
  maxSeconds: waitSeconds,
72016
72957
  onTick: (t) => {
72017
- if (jsonMode4(opts) || t.status === lastStatus) return;
72958
+ if (jsonMode5(opts) || t.status === lastStatus) return;
72018
72959
  lastStatus = t.status;
72019
72960
  process.stderr.write(` ${import_picocolors10.default.dim(`${t.status}${t.status === "running" ? ` \xB7 ${t.stepsRun} steps` : ""}`)}
72020
72961
  `);
@@ -72047,8 +72988,8 @@ async function browserTasks(opts) {
72047
72988
  return;
72048
72989
  }
72049
72990
  for (const t of tasks) {
72050
- const money = t.status === "done" ? usd6(t.chargedUsd) : t.status === "queued" || t.status === "running" ? `${usd6(t.reservedUsd)} reserved` : "";
72051
- process.stdout.write(` ${status2(t.status)} ${t.id} ${import_picocolors10.default.dim(host(t.url).padEnd(24))} ${import_picocolors10.default.dim(`${t.stepsRun}/${t.maxSteps}`.padStart(6))} ${import_picocolors10.default.dim(money.padEnd(16))} ${import_picocolors10.default.dim(when2(t.createdAt))}
72991
+ const money2 = t.status === "done" ? usd5(t.chargedUsd) : t.status === "queued" || t.status === "running" ? `${usd5(t.reservedUsd)} reserved` : "";
72992
+ process.stdout.write(` ${status2(t.status)} ${t.id} ${import_picocolors10.default.dim(host(t.url).padEnd(24))} ${import_picocolors10.default.dim(`${t.stepsRun}/${t.maxSteps}`.padStart(6))} ${import_picocolors10.default.dim(money2.padEnd(16))} ${import_picocolors10.default.dim(when2(t.createdAt))}
72052
72993
  `);
72053
72994
  process.stdout.write(` ${t.goal.length > 90 ? `${t.goal.slice(0, 89)}\u2026` : t.goal}
72054
72995
  `);
@@ -72070,7 +73011,7 @@ async function browserTask(id2, opts) {
72070
73011
  const task = opts.wait ? await waitForTask(keys2.wallet, id2, {
72071
73012
  maxSeconds: typeof opts.wait === "string" ? Math.max(5, Number(opts.wait) || 0) : 900,
72072
73013
  onTick: (t) => {
72073
- if (!jsonMode4(opts) && !SETTLED.has(t.status)) process.stderr.write(` ${import_picocolors10.default.dim(`${t.status} \xB7 ${t.stepsRun} steps`)}
73014
+ if (!jsonMode5(opts) && !SETTLED.has(t.status)) process.stderr.write(` ${import_picocolors10.default.dim(`${t.status} \xB7 ${t.stepsRun} steps`)}
72074
73015
  `);
72075
73016
  }
72076
73017
  }) : await readTask(keys2.wallet, id2);
@@ -72150,20 +73091,20 @@ function installedVersionAt(place) {
72150
73091
 
72151
73092
  // src/commands/update.ts
72152
73093
  var import_picocolors11 = __toESM(require_picocolors(), 1);
72153
- var jsonMode5 = (opts) => opts.json === true || !process.stdout.isTTY;
73094
+ var jsonMode6 = (opts) => opts.json === true || !process.stdout.isTTY;
72154
73095
  async function update(opts = {}) {
72155
73096
  const latest = await fetchLatest();
72156
73097
  const place = installPlace();
72157
73098
  const stale = !!latest && olderThan(LOCAL_VERSION, latest);
72158
73099
  const base = { ok: true, package: PKG, current: LOCAL_VERSION, latest, stale, runsFrom: place.kind, ...place.kind === "home" ? { home: place.home } : place.kind === "checkout" ? { dir: place.dir } : {} };
72159
73100
  if (!latest) {
72160
- if (jsonMode5(opts)) process.stdout.write(JSON.stringify({ ...base, ok: false, code: "registry_unreachable", error: "npm's registry did not answer; try again in a moment" }, null, 2) + "\n");
73101
+ if (jsonMode6(opts)) process.stdout.write(JSON.stringify({ ...base, ok: false, code: "registry_unreachable", error: "npm's registry did not answer; try again in a moment" }, null, 2) + "\n");
72161
73102
  else process.stderr.write(` ${import_picocolors11.default.red("\u2715")} npm's registry did not answer; try again in a moment
72162
73103
  `);
72163
73104
  process.exit(1);
72164
73105
  }
72165
73106
  if (opts.check || !stale) {
72166
- if (jsonMode5(opts)) process.stdout.write(JSON.stringify(base, null, 2) + "\n");
73107
+ if (jsonMode6(opts)) process.stdout.write(JSON.stringify(base, null, 2) + "\n");
72167
73108
  else if (stale) process.stdout.write(`
72168
73109
  ${import_picocolors11.default.yellow("\u2191")} ${latest} is out; this copy is ${LOCAL_VERSION}. ${import_picocolors11.default.dim("agentgates update \xB7 installs it")}
72169
73110
 
@@ -72176,7 +73117,7 @@ async function update(opts = {}) {
72176
73117
  }
72177
73118
  if (place.kind === "checkout") {
72178
73119
  const line2 = `cd ${place.dir} && git pull --ff-only && npm run build`;
72179
- if (jsonMode5(opts)) process.stdout.write(JSON.stringify({ ...base, ok: false, code: "checkout", line: line2, error: "this copy runs from a repository checkout; pull it" }, null, 2) + "\n");
73120
+ if (jsonMode6(opts)) process.stdout.write(JSON.stringify({ ...base, ok: false, code: "checkout", line: line2, error: "this copy runs from a repository checkout; pull it" }, null, 2) + "\n");
72180
73121
  else process.stdout.write(`
72181
73122
  this copy runs from a checkout at ${import_picocolors11.default.bold(place.dir)}; update it with
72182
73123
  ${import_picocolors11.default.cyan(line2)}
@@ -72184,7 +73125,7 @@ async function update(opts = {}) {
72184
73125
  `);
72185
73126
  return;
72186
73127
  }
72187
- if (!jsonMode5(opts)) process.stdout.write(`
73128
+ if (!jsonMode6(opts)) process.stdout.write(`
72188
73129
  ${import_picocolors11.default.bold("UPDATE")} ${LOCAL_VERSION} \u2192 ${latest} ${import_picocolors11.default.dim(place.kind === "home" ? `into ${place.home}` : "the global npm install")}
72189
73130
  ${import_picocolors11.default.dim(`npm ${place.command.join(" ")}`)}
72190
73131
 
@@ -72192,7 +73133,7 @@ async function update(opts = {}) {
72192
73133
  const code = await runNpm(place.command);
72193
73134
  const now = installedVersionAt(place);
72194
73135
  const done = code === 0 && (place.kind !== "home" || now === latest);
72195
- if (jsonMode5(opts)) {
73136
+ if (jsonMode6(opts)) {
72196
73137
  process.stdout.write(JSON.stringify({ ...base, ok: done, code: done ? void 0 : "npm_failed", installed: now ?? void 0, exit: code }, null, 2) + "\n");
72197
73138
  } else if (done) {
72198
73139
  process.stdout.write(`
@@ -72374,7 +73315,7 @@ async function onboard(opts = {}) {
72374
73315
  if (stale) put(stale);
72375
73316
  const order = menuOrder(opts.lane, !!account, latestSeen !== null).filter((k) => existing ? k !== "wallet" : true);
72376
73317
  printMenu(put, order, true);
72377
- const rl = createInterface({ input: process.stdin, output: process.stdout });
73318
+ const rl = createInterface2({ input: process.stdin, output: process.stdout });
72378
73319
  const exitDefault = String(order.indexOf("poke") + 1);
72379
73320
  let first = true;
72380
73321
  let plain = put;
@@ -72532,7 +73473,7 @@ init_passwords_wire();
72532
73473
  init_passwords_seal();
72533
73474
 
72534
73475
  // src/lib/mcp-stdio.ts
72535
- import { createInterface as createInterface2 } from "node:readline";
73476
+ import { createInterface as createInterface3 } from "node:readline";
72536
73477
  var MCP_PROTOCOL_VERSIONS = ["2025-06-18", "2025-03-26", "2024-11-05"];
72537
73478
  var McpToolError = class extends Error {
72538
73479
  constructor(message, detail = {}) {
@@ -72549,7 +73490,7 @@ var INVALID_PARAMS = -32602;
72549
73490
  function reply(id2, result) {
72550
73491
  return { jsonrpc: "2.0", id: id2, result };
72551
73492
  }
72552
- function fail2(id2, code, message, data4) {
73493
+ function fail3(id2, code, message, data4) {
72553
73494
  return { jsonrpc: "2.0", id: id2, error: data4 === void 0 ? { code, message } : { code, message, data: data4 } };
72554
73495
  }
72555
73496
  function parseLine(line2) {
@@ -72557,10 +73498,10 @@ function parseLine(line2) {
72557
73498
  if (!trimmed) return null;
72558
73499
  try {
72559
73500
  const parsed = JSON.parse(trimmed);
72560
- if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return { response: fail2(null, INVALID_REQUEST, "a JSON-RPC message is an object") };
73501
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return { response: fail3(null, INVALID_REQUEST, "a JSON-RPC message is an object") };
72561
73502
  return { message: parsed };
72562
73503
  } catch {
72563
- return { response: fail2(null, PARSE_ERROR, "the line is not JSON") };
73504
+ return { response: fail3(null, PARSE_ERROR, "the line is not JSON") };
72564
73505
  }
72565
73506
  }
72566
73507
  var McpRich = class {
@@ -72595,7 +73536,7 @@ async function dispatch(message, tools, info) {
72595
73536
  const id2 = message.id === void 0 ? null : message.id;
72596
73537
  const isNotification = message.id === void 0;
72597
73538
  if (typeof message.method !== "string") {
72598
- return isNotification ? null : fail2(id2, INVALID_REQUEST, "a request names a method");
73539
+ return isNotification ? null : fail3(id2, INVALID_REQUEST, "a request names a method");
72599
73540
  }
72600
73541
  const params = message.params && typeof message.params === "object" ? message.params : {};
72601
73542
  switch (message.method) {
@@ -72621,7 +73562,7 @@ async function dispatch(message, tools, info) {
72621
73562
  case "tools/call": {
72622
73563
  const name = typeof params.name === "string" ? params.name : "";
72623
73564
  const tool = tools.find((t) => t.name === name);
72624
- if (!tool) return fail2(id2, INVALID_PARAMS, `no tool named "${name}"`);
73565
+ if (!tool) return fail3(id2, INVALID_PARAMS, `no tool named "${name}"`);
72625
73566
  const args = params.arguments && typeof params.arguments === "object" && !Array.isArray(params.arguments) ? params.arguments : {};
72626
73567
  try {
72627
73568
  return reply(id2, toolResult(await tool.handler(args)));
@@ -72636,7 +73577,7 @@ async function dispatch(message, tools, info) {
72636
73577
  case "prompts/list":
72637
73578
  return reply(id2, { prompts: [] });
72638
73579
  default:
72639
- return isNotification ? null : fail2(id2, METHOD_NOT_FOUND, `no method "${message.method}"`);
73580
+ return isNotification ? null : fail3(id2, METHOD_NOT_FOUND, `no method "${message.method}"`);
72640
73581
  }
72641
73582
  }
72642
73583
  async function serve(tools, info, { input = process.stdin, output: output2 = process.stdout } = {}) {
@@ -72645,7 +73586,7 @@ async function serve(tools, info, { input = process.stdin, output: output2 = pro
72645
73586
  `);
72646
73587
  };
72647
73588
  const inFlight = /* @__PURE__ */ new Set();
72648
- const lines = createInterface2({ input, crlfDelay: Infinity });
73589
+ const lines = createInterface3({ input, crlfDelay: Infinity });
72649
73590
  for await (const line2 of lines) {
72650
73591
  const parsed = parseLine(line2);
72651
73592
  if (!parsed) continue;
@@ -72657,7 +73598,7 @@ async function serve(tools, info, { input = process.stdin, output: output2 = pro
72657
73598
  if (response) send2(response);
72658
73599
  }).catch((err) => {
72659
73600
  const id2 = parsed.message.id === void 0 ? null : parsed.message.id;
72660
- if (id2 !== null) send2(fail2(id2, -32603, err instanceof Error ? err.message : String(err)));
73601
+ if (id2 !== null) send2(fail3(id2, -32603, err instanceof Error ? err.message : String(err)));
72661
73602
  }).finally(() => {
72662
73603
  inFlight.delete(job);
72663
73604
  });
@@ -72949,7 +73890,7 @@ function emit6(opts, data4, human) {
72949
73890
  }
72950
73891
  human();
72951
73892
  }
72952
- function fail3(opts, err) {
73893
+ function fail4(opts, err) {
72953
73894
  const message = err instanceof Error ? err.message : String(err);
72954
73895
  const code = err?.code;
72955
73896
  if (opts.json || !process.stdout.isTTY) {
@@ -73050,7 +73991,7 @@ async function memoryOverview(opts) {
73050
73991
  process.stdout.write("\n");
73051
73992
  });
73052
73993
  } catch (err) {
73053
- fail3(opts, err);
73994
+ fail4(opts, err);
73054
73995
  }
73055
73996
  }
73056
73997
  async function memoryMkdir(folder, opts) {
@@ -73063,7 +74004,7 @@ async function memoryMkdir(folder, opts) {
73063
74004
 
73064
74005
  `));
73065
74006
  } catch (err) {
73066
- fail3(opts, err);
74007
+ fail4(opts, err);
73067
74008
  }
73068
74009
  }
73069
74010
  async function memoryRmdir(folder, opts) {
@@ -73076,7 +74017,7 @@ async function memoryRmdir(folder, opts) {
73076
74017
 
73077
74018
  `));
73078
74019
  } catch (err) {
73079
- fail3(opts, err);
74020
+ fail4(opts, err);
73080
74021
  }
73081
74022
  }
73082
74023
  async function memoryLs(target, opts) {
@@ -73130,7 +74071,7 @@ async function memoryLs(target, opts) {
73130
74071
  process.stdout.write("\n");
73131
74072
  });
73132
74073
  } catch (err) {
73133
- fail3(opts, err);
74074
+ fail4(opts, err);
73134
74075
  }
73135
74076
  }
73136
74077
  async function memorySources(opts) {
@@ -73159,7 +74100,7 @@ async function memorySources(opts) {
73159
74100
  process.stdout.write("\n");
73160
74101
  });
73161
74102
  } catch (err) {
73162
- fail3(opts, err);
74103
+ fail4(opts, err);
73163
74104
  }
73164
74105
  }
73165
74106
  async function memoryCat(path8, opts) {
@@ -73186,7 +74127,7 @@ async function memoryCat(path8, opts) {
73186
74127
  emit6(opts, { ok: true, folder, name, id: row.id, version: row.version, updatedAt: row.updatedAt, text }, () => process.stdout.write(text.endsWith("\n") ? text : `${text}
73187
74128
  `));
73188
74129
  } catch (err) {
73189
- fail3(opts, err);
74130
+ fail4(opts, err);
73190
74131
  }
73191
74132
  }
73192
74133
  async function memoryPut(path8, opts) {
@@ -73209,7 +74150,7 @@ async function memoryPut(path8, opts) {
73209
74150
  `)
73210
74151
  );
73211
74152
  } catch (err) {
73212
- fail3(opts, err);
74153
+ fail4(opts, err);
73213
74154
  }
73214
74155
  }
73215
74156
  async function memoryRm(path8, opts) {
@@ -73226,7 +74167,7 @@ async function memoryRm(path8, opts) {
73226
74167
 
73227
74168
  `));
73228
74169
  } catch (err) {
73229
- fail3(opts, err);
74170
+ fail4(opts, err);
73230
74171
  }
73231
74172
  }
73232
74173
  async function openAbout(wallet) {
@@ -73283,7 +74224,7 @@ async function memoryAbout(opts) {
73283
74224
  process.stdout.write("\n");
73284
74225
  });
73285
74226
  } catch (err) {
73286
- fail3(opts, err);
74227
+ fail4(opts, err);
73287
74228
  }
73288
74229
  }
73289
74230
  async function grepMemory(wallet, key, pattern, folders) {
@@ -73332,7 +74273,7 @@ async function memoryGrep(patternRaw, folder, opts) {
73332
74273
  `);
73333
74274
  });
73334
74275
  } catch (err) {
73335
- fail3(opts, err);
74276
+ fail4(opts, err);
73336
74277
  }
73337
74278
  }
73338
74279
  async function readStdin() {
@@ -73575,7 +74516,7 @@ function emit7(opts, data4, human) {
73575
74516
  }
73576
74517
  human();
73577
74518
  }
73578
- function fail4(opts, err) {
74519
+ function fail5(opts, err) {
73579
74520
  const message = err instanceof Error ? err.message : String(err);
73580
74521
  const code = err?.code;
73581
74522
  if (opts.json || !process.stdout.isTTY) {
@@ -73804,7 +74745,7 @@ async function filesList(folderArg, opts) {
73804
74745
  process.stdout.write("\n");
73805
74746
  });
73806
74747
  } catch (err) {
73807
- fail4(opts, err);
74748
+ fail5(opts, err);
73808
74749
  }
73809
74750
  }
73810
74751
  async function filesPut(path8, opts) {
@@ -73824,7 +74765,7 @@ async function filesPut(path8, opts) {
73824
74765
  `)
73825
74766
  );
73826
74767
  } catch (err) {
73827
- fail4(opts, err);
74768
+ fail5(opts, err);
73828
74769
  }
73829
74770
  }
73830
74771
  async function filesGet(target, opts) {
@@ -73845,7 +74786,7 @@ async function filesGet(target, opts) {
73845
74786
  `)
73846
74787
  );
73847
74788
  } catch (err) {
73848
- fail4(opts, err);
74789
+ fail5(opts, err);
73849
74790
  }
73850
74791
  }
73851
74792
  async function moveOpened(wallet, key, dataPublicKey, file, folder) {
@@ -73874,7 +74815,7 @@ async function filesMv(target, folderArg, opts) {
73874
74815
  `)
73875
74816
  );
73876
74817
  } catch (err) {
73877
- fail4(opts, err);
74818
+ fail5(opts, err);
73878
74819
  }
73879
74820
  }
73880
74821
  async function filesRm(target, opts) {
@@ -73893,13 +74834,13 @@ async function filesRm(target, opts) {
73893
74834
  `)
73894
74835
  );
73895
74836
  } catch (err) {
73896
- fail4(opts, err);
74837
+ fail5(opts, err);
73897
74838
  }
73898
74839
  }
73899
74840
 
73900
74841
  // src/commands/card.ts
73901
74842
  var import_picocolors15 = __toESM(require_picocolors(), 1);
73902
- import { createInterface as createInterface3 } from "node:readline/promises";
74843
+ import { createInterface as createInterface4 } from "node:readline/promises";
73903
74844
 
73904
74845
  // src/lib/memory-address.ts
73905
74846
  var ADDRESS_FOLDER = "profile";
@@ -74377,7 +75318,7 @@ function emit8(opts, data4, human) {
74377
75318
  }
74378
75319
  human();
74379
75320
  }
74380
- function fail5(opts, err) {
75321
+ function fail6(opts, err) {
74381
75322
  const message = err instanceof Error ? err.message : String(err);
74382
75323
  const code = err?.code;
74383
75324
  if (opts.json || !process.stdout.isTTY) {
@@ -74441,7 +75382,7 @@ var QUESTIONS = [
74441
75382
  { field: "zip", ask: "ZIP code", abroad: "Postal code" }
74442
75383
  ];
74443
75384
  async function askAddress() {
74444
- const rl = createInterface3({ input: process.stdin, output: process.stdout });
75385
+ const rl = createInterface4({ input: process.stdin, output: process.stdout });
74445
75386
  const answers = { country: "US", line1: "", line2: "", city: "", region: "", zip: "" };
74446
75387
  try {
74447
75388
  process.stdout.write(`
@@ -74523,7 +75464,7 @@ async function cardAddressSet(opts) {
74523
75464
  `)
74524
75465
  );
74525
75466
  } catch (err) {
74526
- fail5(opts, err);
75467
+ fail6(opts, err);
74527
75468
  }
74528
75469
  }
74529
75470
  async function cardAddressShow(opts) {
@@ -74550,7 +75491,7 @@ ${lines.map((l) => ` ${l}`).join("\n")}
74550
75491
  `)
74551
75492
  );
74552
75493
  } catch (err) {
74553
- fail5(opts, err);
75494
+ fail6(opts, err);
74554
75495
  }
74555
75496
  }
74556
75497
  async function cardAddressClear(opts) {
@@ -74566,7 +75507,7 @@ async function cardAddressClear(opts) {
74566
75507
  `)
74567
75508
  );
74568
75509
  } catch (err) {
74569
- fail5(opts, err);
75510
+ fail6(opts, err);
74570
75511
  }
74571
75512
  }
74572
75513
 
@@ -75437,9 +76378,9 @@ function usdOf(micro) {
75437
76378
  const rest = (n2 % 1000000n).toString().padStart(6, "0").replace(/0+$/, "");
75438
76379
  return rest ? `${whole}.${rest}` : `${whole}`;
75439
76380
  }
75440
- function microOf(usd7) {
75441
- const clean3 = usd7.trim().replace(/^\$/, "");
75442
- if (!/^\d+(\.\d{1,6})?$/.test(clean3)) throw new Error(`a dollar amount, like 40 or 12.50 (got ${usd7})`);
76381
+ function microOf(usd6) {
76382
+ const clean3 = usd6.trim().replace(/^\$/, "");
76383
+ if (!/^\d+(\.\d{1,6})?$/.test(clean3)) throw new Error(`a dollar amount, like 40 or 12.50 (got ${usd6})`);
75443
76384
  const [whole, frac = ""] = clean3.split(".");
75444
76385
  return (BigInt(whole) * 1000000n + BigInt((frac + "000000").slice(0, 6))).toString();
75445
76386
  }
@@ -75463,16 +76404,16 @@ function firstSentence(words7) {
75463
76404
  }
75464
76405
 
75465
76406
  // src/commands/intents.ts
75466
- var jsonMode6 = (opts) => opts.json === true || !process.stdout.isTTY;
76407
+ var jsonMode7 = (opts) => opts.json === true || !process.stdout.isTTY;
75467
76408
  function emit9(opts, data4, human) {
75468
- if (jsonMode6(opts)) {
76409
+ if (jsonMode7(opts)) {
75469
76410
  process.stdout.write(JSON.stringify(data4, null, 2) + "\n");
75470
76411
  return;
75471
76412
  }
75472
76413
  human();
75473
76414
  }
75474
76415
  function refuse5(opts, error, code, extra = {}) {
75475
- if (jsonMode6(opts)) {
76416
+ if (jsonMode7(opts)) {
75476
76417
  process.stdout.write(JSON.stringify({ ok: false, code, error, ...extra }, null, 2) + "\n");
75477
76418
  } else {
75478
76419
  process.stderr.write(` ${error}${code ? import_picocolors17.default.dim(` (${code})`) : ""}
@@ -76126,7 +77067,7 @@ function emit10(opts, data4, human) {
76126
77067
  }
76127
77068
  human();
76128
77069
  }
76129
- function fail6(opts, err) {
77070
+ function fail7(opts, err) {
76130
77071
  const message = err instanceof Error ? err.message : String(err);
76131
77072
  const code = err instanceof WireError ? err.code : err?.code;
76132
77073
  if (opts.json || !process.stdout.isTTY) {
@@ -76189,7 +77130,7 @@ async function integrationsList(opts) {
76189
77130
  }
76190
77131
  });
76191
77132
  } catch (err) {
76192
- fail6(opts, err);
77133
+ fail7(opts, err);
76193
77134
  }
76194
77135
  }
76195
77136
  var sleep2 = (ms) => new Promise((r) => setTimeout(r, ms));
@@ -76249,7 +77190,7 @@ async function integrationsUse(integrationId, opts) {
76249
77190
  return;
76250
77191
  }
76251
77192
  } catch (err) {
76252
- fail6(opts, err);
77193
+ fail7(opts, err);
76253
77194
  }
76254
77195
  }
76255
77196
  async function integrationsSignup(provider, opts) {
@@ -76268,7 +77209,7 @@ async function integrationsSignup(provider, opts) {
76268
77209
  `);
76269
77210
  });
76270
77211
  } catch (err) {
76271
- fail6(opts, err);
77212
+ fail7(opts, err);
76272
77213
  }
76273
77214
  }
76274
77215
  async function integrationsSignupReport(signupId, opts) {
@@ -76283,7 +77224,7 @@ async function integrationsSignupReport(signupId, opts) {
76283
77224
  `);
76284
77225
  });
76285
77226
  } catch (err) {
76286
- fail6(opts, err);
77227
+ fail7(opts, err);
76287
77228
  }
76288
77229
  }
76289
77230
  async function integrationsSignupHandoff(signupId, provider, opts) {
@@ -76308,7 +77249,7 @@ async function integrationsSignupHandoff(signupId, provider, opts) {
76308
77249
  `);
76309
77250
  });
76310
77251
  } catch (err) {
76311
- fail6(opts, err);
77252
+ fail7(opts, err);
76312
77253
  }
76313
77254
  }
76314
77255
  async function sitesList(opts) {
@@ -76345,7 +77286,7 @@ async function sitesList(opts) {
76345
77286
  }
76346
77287
  });
76347
77288
  } catch (err) {
76348
- fail6(opts, err);
77289
+ fail7(opts, err);
76349
77290
  }
76350
77291
  }
76351
77292
  var CHANGE_ID_RE = /^[A-Za-z0-9_-]{22}$/;
@@ -76379,7 +77320,7 @@ async function sitesChange(changeId, opts) {
76379
77320
  process.stdout.write("\n");
76380
77321
  });
76381
77322
  } catch (err) {
76382
- fail6(opts, err);
77323
+ fail7(opts, err);
76383
77324
  }
76384
77325
  }
76385
77326
  async function sitesShip(changeId, opts) {
@@ -76397,7 +77338,7 @@ async function sitesShip(changeId, opts) {
76397
77338
  `);
76398
77339
  });
76399
77340
  } catch (err) {
76400
- fail6(opts, err);
77341
+ fail7(opts, err);
76401
77342
  }
76402
77343
  }
76403
77344
  async function sitesSkip(changeId, opts) {
@@ -76412,7 +77353,7 @@ async function sitesSkip(changeId, opts) {
76412
77353
  `);
76413
77354
  });
76414
77355
  } catch (err) {
76415
- fail6(opts, err);
77356
+ fail7(opts, err);
76416
77357
  }
76417
77358
  }
76418
77359
  async function sitesUndo(changeId, opts) {
@@ -76427,7 +77368,7 @@ async function sitesUndo(changeId, opts) {
76427
77368
  `);
76428
77369
  });
76429
77370
  } catch (err) {
76430
- fail6(opts, err);
77371
+ fail7(opts, err);
76431
77372
  }
76432
77373
  }
76433
77374
  async function sitesFix(changeId, opts) {
@@ -76446,7 +77387,81 @@ async function sitesFix(changeId, opts) {
76446
77387
  `);
76447
77388
  });
76448
77389
  } catch (err) {
76449
- fail6(opts, err);
77390
+ fail7(opts, err);
77391
+ }
77392
+ }
77393
+ function askOf(dataKey, owner, ask) {
77394
+ if (!ask) return null;
77395
+ try {
77396
+ const aad = `AGENTGATES-CONVERSATION-v1|turn|${normalizeOwner2(owner)}|${ask.conversationId}|${ask.seq}|${ask.role}${ask.author ? `|${ask.author}|${ask.channel ?? ""}` : ""}`;
77397
+ const text = openText(dataKey, ask.ciphertext, aad);
77398
+ if (ask.author === "card") {
77399
+ const words7 = JSON.parse(text).words ?? "";
77400
+ return words7 ? `Fix: ${words7.split("\n")[0].trim()}` : null;
77401
+ }
77402
+ const m = /^Asked for a change on site [A-Za-z0-9_-]{22}: ([\s\S]*)$/.exec(text.trim());
77403
+ return (m ? m[1] : text).trim() || null;
77404
+ } catch {
77405
+ return null;
77406
+ }
77407
+ }
77408
+ async function sitesChanges(siteId, opts) {
77409
+ try {
77410
+ if (!CHANGE_ID_RE.test(siteId)) throw new Error("a site id is 22 characters (agentgates sites lists them)");
77411
+ if (opts.before && !CHANGE_ID_RE.test(opts.before)) throw new Error("--before takes the last change id of the page before");
77412
+ const { wallet } = await requirePasswordsKey();
77413
+ const q = opts.before ? `?before=${encodeURIComponent(opts.before)}` : "";
77414
+ const out = expectOk(await signedFetch(wallet, "GET", lanePath(`/sites/${siteId}/changes${q}`)), "sites changes");
77415
+ const key = await mailKeyFor(wallet).catch(() => null);
77416
+ const rows = (out.changes ?? []).map((c) => {
77417
+ let done = null;
77418
+ if (key && c.card) {
77419
+ try {
77420
+ done = (JSON.parse(openText(key.dataKey, c.card.ciphertext, cardAad(wallet.address, c.card))).words ?? "").split("\n")[0].trim() || null;
77421
+ } catch {
77422
+ done = null;
77423
+ }
77424
+ }
77425
+ const asked = key ? askOf(key.dataKey, wallet.address, c.ask) : null;
77426
+ return { id: c.id, state: c.state, code: c.code, round: c.round, costMicro: c.costMicro, updatedAt: c.updatedAt, title: done ?? asked ?? (c.round === 0 ? "Merged on GitHub" : null) };
77427
+ });
77428
+ emit10(opts, { ok: true, changes: rows, next: out.next ?? null }, () => {
77429
+ if (!rows.length) {
77430
+ process.stdout.write(`
77431
+ ${import_picocolors18.default.dim("No changes yet.")}
77432
+
77433
+ `);
77434
+ return;
77435
+ }
77436
+ process.stdout.write("\n");
77437
+ for (const r of rows) {
77438
+ const state = r.state === "live" ? import_picocolors18.default.green("live") : r.state === "ready" ? import_picocolors18.default.cyan("ready") : import_picocolors18.default.yellow(r.code ?? r.state);
77439
+ process.stdout.write(` ${state} ${r.title ?? import_picocolors18.default.dim("(no words open here)")}
77440
+ ${import_picocolors18.default.dim(`${r.id} ${r.updatedAt}`)}
77441
+
77442
+ `);
77443
+ }
77444
+ if (out.next) process.stdout.write(` ${import_picocolors18.default.dim(`older: agentgates sites changes ${siteId} --before ${out.next}`)}
77445
+
77446
+ `);
77447
+ });
77448
+ } catch (err) {
77449
+ fail7(opts, err);
77450
+ }
77451
+ }
77452
+ async function sitesRemove(siteId, opts) {
77453
+ try {
77454
+ if (!CHANGE_ID_RE.test(siteId)) throw new Error("a site id is 22 characters (agentgates sites lists them)");
77455
+ const { wallet } = await requirePasswordsKey();
77456
+ const out = expectOk(await signedFetch(wallet, "POST", lanePath(`/sites/${siteId}/remove`)), "sites remove");
77457
+ emit10(opts, { ok: true, id: out.id, state: out.state }, () => {
77458
+ process.stdout.write(`
77459
+ ${import_picocolors18.default.yellow(out.state)} ${import_picocolors18.default.dim(out.id)}
77460
+
77461
+ `);
77462
+ });
77463
+ } catch (err) {
77464
+ fail7(opts, err);
76450
77465
  }
76451
77466
  }
76452
77467
 
@@ -76580,8 +77595,14 @@ async function readAgAttestation() {
76580
77595
  if (!proven.ok) throw new WireError(0, "box_unproven", `the AG AI box did not prove itself (${proven.reason}), so nothing was sealed`, null);
76581
77596
  return proven.value;
76582
77597
  }
76583
- async function readAgent(wallet) {
76584
- return expectOk(await signedFetch(wallet, "GET", lanePath("/ag/agent")), "agent");
77598
+ async function readAgent(wallet, opts = {}) {
77599
+ return expectOk(await signedFetch(wallet, "GET", lanePath(opts.turnOn ? "/ag/agent?turnOn=1" : "/ag/agent")), "agent");
77600
+ }
77601
+ function agentProofMessage(ownerWallet, agentAddress, nonce) {
77602
+ return `Agentgates: turn on my agent
77603
+ account: ${normalizeAgOwner(ownerWallet)}
77604
+ agent: ${normalizeAgOwner(agentAddress)}
77605
+ nonce: ${nonce}`;
76585
77606
  }
76586
77607
  async function postAgentOn(wallet, body) {
76587
77608
  return expectOk(await signedFetch(wallet, "POST", lanePath("/ag/agent"), body), "agent on");
@@ -76654,7 +77675,7 @@ function emit11(opts, data4, human) {
76654
77675
  }
76655
77676
  human();
76656
77677
  }
76657
- function fail7(opts, err) {
77678
+ function fail8(opts, err) {
76658
77679
  const message = err instanceof Error ? err.message : String(err);
76659
77680
  const code = err?.code;
76660
77681
  if (opts.json || !process.stdout.isTTY) {
@@ -76710,7 +77731,7 @@ async function agentStatus(opts) {
76710
77731
  process.stdout.write("\n");
76711
77732
  });
76712
77733
  } catch (err) {
76713
- fail7(opts, err);
77734
+ fail8(opts, err);
76714
77735
  }
76715
77736
  }
76716
77737
  async function agentOn(opts) {
@@ -76723,7 +77744,10 @@ async function agentOn(opts) {
76723
77744
  if (!seal) throw new WireError(409, "seal_missing", "seal this account first (agentgates email seal): the agent's thread is written to your Memory, and Memory seals to your account's key", null);
76724
77745
  const account = await mailKeyFor(wallet);
76725
77746
  if (!account) throw new WireError(409, "no_key", "this machine holds no copy of the account's data key", null);
77747
+ const { turnOnNonce } = await readAgent(wallet, { turnOn: true });
77748
+ if (!turnOnNonce) throw new WireError(409, "turn_on_nonce", "the agent door gave no turn-on code, so nothing was turned on: try again", null);
76726
77749
  const agent2 = ethers_exports.Wallet.createRandom();
77750
+ const proof = { nonce: turnOnNonce, signature: await agent2.signMessage(agentProofMessage(wallet.address, agent2.address, turnOnNonce)) };
76727
77751
  const aad = agWalletKeyAad(wallet.address);
76728
77752
  const keyOwnerBlob = sealText(seal.sealingPublicKey, agent2.privateKey, aad);
76729
77753
  const keyBoxBlob = sealText(fleet.publicKey, agent2.privateKey, aad);
@@ -76733,7 +77757,7 @@ async function agentOn(opts) {
76733
77757
  const pair = keySealingKeyFromParts({ wire: made.key, reading });
76734
77758
  await putKeyWrap(wallet, made.created.id, { sealingPublicKey: pair.publicKey, wrap: sealTo(pair.publicKey, account.dataKey, keyWrapAad(keys2.state.address, made.created.id)) });
76735
77759
  const memoryKeyBoxBlob = sealText(fleet.publicKey, JSON.stringify({ wire: made.key, reading }), agMemoryKeyAad(wallet.address, made.created.id));
76736
- const out = await postAgentOn(wallet, { agentAddress: agent2.address, keyOwnerBlob, keyBoxBlob, memoryKeyId: made.created.id, memoryKeyBoxBlob });
77760
+ const out = await postAgentOn(wallet, { agentAddress: agent2.address, keyOwnerBlob, keyBoxBlob, memoryKeyId: made.created.id, memoryKeyBoxBlob, proof });
76737
77761
  const note2 = opts.fund !== void 0 ? AGENT_PAYS_SENTENCE : null;
76738
77762
  emit11(opts, { ok: true, agent: out.agent, memoryKeyId: made.created.id, fleet: { mode: fleet.mode, keyId: fleet.keyId }, ...note2 ? { note: note2 } : {} }, () => {
76739
77763
  process.stdout.write(
@@ -76752,7 +77776,7 @@ async function agentOn(opts) {
76752
77776
  throw err;
76753
77777
  }
76754
77778
  } catch (err) {
76755
- fail7(opts, err);
77779
+ fail8(opts, err);
76756
77780
  }
76757
77781
  }
76758
77782
  async function agentOff(opts) {
@@ -76777,14 +77801,14 @@ async function agentOff(opts) {
76777
77801
  `);
76778
77802
  });
76779
77803
  } catch (err) {
76780
- fail7(opts, err);
77804
+ fail8(opts, err);
76781
77805
  }
76782
77806
  }
76783
77807
  async function agentFund(_amountUsd, opts) {
76784
- fail7(opts, agentPaysRefusal());
77808
+ fail8(opts, agentPaysRefusal());
76785
77809
  }
76786
77810
  async function agentRefill(_action, opts) {
76787
- fail7(opts, agentPaysRefusal());
77811
+ fail8(opts, agentPaysRefusal());
76788
77812
  }
76789
77813
  async function agentSay(text, opts) {
76790
77814
  try {
@@ -76797,7 +77821,7 @@ async function agentSay(text, opts) {
76797
77821
  `);
76798
77822
  });
76799
77823
  } catch (err) {
76800
- fail7(opts, err);
77824
+ fail8(opts, err);
76801
77825
  }
76802
77826
  }
76803
77827
  async function agentJournal(opts) {
@@ -76826,7 +77850,7 @@ async function agentJournal(opts) {
76826
77850
  process.stdout.write("\n");
76827
77851
  });
76828
77852
  } catch (err) {
76829
- fail7(opts, err);
77853
+ fail8(opts, err);
76830
77854
  }
76831
77855
  }
76832
77856
  async function agentBind(channel, senderId, opts) {
@@ -76886,7 +77910,7 @@ async function agentBind(channel, senderId, opts) {
76886
77910
  `);
76887
77911
  });
76888
77912
  } catch (err) {
76889
- fail7(opts, err);
77913
+ fail8(opts, err);
76890
77914
  }
76891
77915
  }
76892
77916
  async function agentBindings(opts) {
@@ -76907,7 +77931,7 @@ async function agentBindings(opts) {
76907
77931
  process.stdout.write("\n");
76908
77932
  });
76909
77933
  } catch (err) {
76910
- fail7(opts, err);
77934
+ fail8(opts, err);
76911
77935
  }
76912
77936
  }
76913
77937
  async function agentUnbind(id2, opts) {
@@ -76922,7 +77946,7 @@ async function agentUnbind(id2, opts) {
76922
77946
  `);
76923
77947
  });
76924
77948
  } catch (err) {
76925
- fail7(opts, err);
77949
+ fail8(opts, err);
76926
77950
  }
76927
77951
  }
76928
77952
 
@@ -76991,16 +78015,16 @@ async function whoami(opts) {
76991
78015
  `));
76992
78016
  }
76993
78017
  const { profile, name: profileName } = resolved;
76994
- const jsonMode7 = opts.json === true;
78018
+ const jsonMode8 = opts.json === true;
76995
78019
  const outcome = await callWithAutoRelogin({
76996
78020
  profile,
76997
78021
  profileName,
76998
- jsonMode: jsonMode7,
78022
+ jsonMode: jsonMode8,
76999
78023
  ttyHeader: import_picocolors21.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026"),
77000
78024
  fn: (bearer, origin) => apiFetch("/api/whoami", { bearer, origin })
77001
78025
  });
77002
78026
  if (outcome.kind === "auth_failed") {
77003
- if (jsonMode7) {
78027
+ if (jsonMode8) {
77004
78028
  process.stdout.write(
77005
78029
  JSON.stringify({ ok: false, status: "auth_failed", error: outcome.reason }) + "\n"
77006
78030
  );
@@ -77020,7 +78044,7 @@ async function whoami(opts) {
77020
78044
  throw err;
77021
78045
  }
77022
78046
  const me = outcome.result;
77023
- if (jsonMode7) {
78047
+ if (jsonMode8) {
77024
78048
  process.stdout.write(JSON.stringify(me, null, 2) + "\n");
77025
78049
  return;
77026
78050
  }
@@ -77233,7 +78257,7 @@ async function send(amount, asset, opts) {
77233
78257
  }
77234
78258
  const { profile, name: profileName } = resolved;
77235
78259
  const stdoutIsTty = process.stdout.isTTY === true;
77236
- const jsonMode7 = opts.json === true || !stdoutIsTty;
78260
+ const jsonMode8 = opts.json === true || !stdoutIsTty;
77237
78261
  const amountNumber = Number(amount);
77238
78262
  if (!Number.isFinite(amountNumber) || amountNumber <= 0) {
77239
78263
  process.stderr.write(
@@ -77342,12 +78366,12 @@ async function send(amount, asset, opts) {
77342
78366
  try {
77343
78367
  activeProfile = await runLoginFlow({
77344
78368
  profile: profileName,
77345
- jsonMode: jsonMode7,
78369
+ jsonMode: jsonMode8,
77346
78370
  origin: activeProfile.mcpOrigin,
77347
78371
  ttyHeader: import_picocolors22.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026")
77348
78372
  });
77349
78373
  } catch (reloginErr) {
77350
- if (jsonMode7) {
78374
+ if (jsonMode8) {
77351
78375
  emitNdjson({
77352
78376
  ok: false,
77353
78377
  status: "auth_failed",
@@ -77370,7 +78394,7 @@ async function send(amount, asset, opts) {
77370
78394
  });
77371
78395
  } catch (retryErr) {
77372
78396
  if (retryErr instanceof ApiError) {
77373
- if (jsonMode7) {
78397
+ if (jsonMode8) {
77374
78398
  emitNdjson({
77375
78399
  ok: false,
77376
78400
  status: retryErr.status === 401 ? "auth_failed" : "propose_failed",
@@ -77388,7 +78412,7 @@ async function send(amount, asset, opts) {
77388
78412
  throw retryErr;
77389
78413
  }
77390
78414
  } else if (err instanceof ApiError) {
77391
- if (jsonMode7) {
78415
+ if (jsonMode8) {
77392
78416
  emitNdjson({
77393
78417
  ok: false,
77394
78418
  status: "propose_failed",
@@ -77405,7 +78429,7 @@ async function send(amount, asset, opts) {
77405
78429
  }
77406
78430
  }
77407
78431
  if (isBlocked(proposed)) {
77408
- if (jsonMode7) {
78432
+ if (jsonMode8) {
77409
78433
  const envelope = {
77410
78434
  ok: false,
77411
78435
  status: "blocked",
@@ -77469,7 +78493,7 @@ async function send(amount, asset, opts) {
77469
78493
  if (process.env.CI === "1" || process.env.CI === "true") return false;
77470
78494
  return true;
77471
78495
  })();
77472
- if (jsonMode7) {
78496
+ if (jsonMode8) {
77473
78497
  emitNdjson({
77474
78498
  ok: true,
77475
78499
  status: "proposed",
@@ -77501,7 +78525,7 @@ ${import_picocolors22.default.bold("Proposed.")} Open this URL to approve with b
77501
78525
  intervalMs: POLL_INTERVAL_MS,
77502
78526
  giveUpMs: POLL_GIVEUP_MS,
77503
78527
  onTick: (s) => {
77504
- if (jsonMode7) {
78528
+ if (jsonMode8) {
77505
78529
  emitNdjson({ status: s.status, intent_id: s.approval_id });
77506
78530
  } else {
77507
78531
  process.stdout.write(` ${describeStatus(s.status)}${import_picocolors22.default.dim("\u2026")}\r`);
@@ -77516,12 +78540,12 @@ ${import_picocolors22.default.bold("Proposed.")} Open this URL to approve with b
77516
78540
  try {
77517
78541
  activeProfile = await runLoginFlow({
77518
78542
  profile: profileName,
77519
- jsonMode: jsonMode7,
78543
+ jsonMode: jsonMode8,
77520
78544
  origin: activeProfile.mcpOrigin,
77521
78545
  ttyHeader: import_picocolors22.default.dim("Bearer expired mid-poll \u2014 re-pairing this terminal\u2026")
77522
78546
  });
77523
78547
  } catch (reloginErr) {
77524
- if (jsonMode7) {
78548
+ if (jsonMode8) {
77525
78549
  emitNdjson({
77526
78550
  ok: false,
77527
78551
  status: "auth_failed",
@@ -77539,7 +78563,7 @@ ${import_picocolors22.default.bold("Proposed.")} Open this URL to approve with b
77539
78563
  try {
77540
78564
  final = await runPoll(activeProfile);
77541
78565
  } catch (retryErr) {
77542
- if (jsonMode7) {
78566
+ if (jsonMode8) {
77543
78567
  emitNdjson({
77544
78568
  ok: false,
77545
78569
  status: retryErr instanceof ApiError && retryErr.status === 401 ? "auth_failed" : "poll_failed",
@@ -77555,7 +78579,7 @@ ${import_picocolors22.default.bold("Proposed.")} Open this URL to approve with b
77555
78579
  process.exit(1);
77556
78580
  }
77557
78581
  } else {
77558
- if (jsonMode7) {
78582
+ if (jsonMode8) {
77559
78583
  emitNdjson({
77560
78584
  ok: false,
77561
78585
  status: "poll_failed",
@@ -77572,7 +78596,7 @@ ${import_picocolors22.default.bold("Proposed.")} Open this URL to approve with b
77572
78596
  }
77573
78597
  }
77574
78598
  const explorer = final.tx_hash != null ? explorerUrl(final.chain_id, final.tx_hash) : null;
77575
- if (jsonMode7) {
78599
+ if (jsonMode8) {
77576
78600
  emitNdjson({
77577
78601
  ok: final.status === "mined",
77578
78602
  status: final.status,
@@ -77658,16 +78682,16 @@ async function status3(intentId, opts) {
77658
78682
  `));
77659
78683
  }
77660
78684
  const { profile, name: profileName } = resolved;
77661
- const jsonMode7 = opts.json === true;
78685
+ const jsonMode8 = opts.json === true;
77662
78686
  const outcome = await callWithAutoRelogin({
77663
78687
  profile,
77664
78688
  profileName,
77665
- jsonMode: jsonMode7,
78689
+ jsonMode: jsonMode8,
77666
78690
  ttyHeader: import_picocolors23.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026"),
77667
78691
  fn: (bearer, origin) => fetchStatus({ intentId, bearer, origin })
77668
78692
  });
77669
78693
  if (outcome.kind === "auth_failed") {
77670
- if (jsonMode7) {
78694
+ if (jsonMode8) {
77671
78695
  process.stdout.write(
77672
78696
  JSON.stringify({ ok: false, status: "auth_failed", error: outcome.reason }) + "\n"
77673
78697
  );
@@ -77694,7 +78718,7 @@ async function status3(intentId, opts) {
77694
78718
  let snap = outcome.result;
77695
78719
  let activeProfile = outcome.profile;
77696
78720
  if (opts.watch && !isTerminalStatus(snap.status)) {
77697
- if (!jsonMode7) {
78721
+ if (!jsonMode8) {
77698
78722
  printSnap(snap);
77699
78723
  process.stdout.write(import_picocolors23.default.dim("Watching\u2026\n"));
77700
78724
  }
@@ -77706,7 +78730,7 @@ async function status3(intentId, opts) {
77706
78730
  intervalMs: 0,
77707
78731
  giveUpMs: WATCH_GIVEUP_MS,
77708
78732
  onTick: (s) => {
77709
- if (!jsonMode7) {
78733
+ if (!jsonMode8) {
77710
78734
  process.stdout.write(` ${import_picocolors23.default.dim("\u2192")} ${s.status}
77711
78735
  `);
77712
78736
  }
@@ -77720,12 +78744,12 @@ async function status3(intentId, opts) {
77720
78744
  try {
77721
78745
  activeProfile = await runLoginFlow({
77722
78746
  profile: profileName,
77723
- jsonMode: jsonMode7,
78747
+ jsonMode: jsonMode8,
77724
78748
  origin: activeProfile.mcpOrigin,
77725
78749
  ttyHeader: import_picocolors23.default.dim("Bearer expired mid-watch \u2014 re-pairing\u2026")
77726
78750
  });
77727
78751
  } catch (reloginErr) {
77728
- if (jsonMode7) {
78752
+ if (jsonMode8) {
77729
78753
  process.stdout.write(
77730
78754
  JSON.stringify({
77731
78755
  ok: false,
@@ -77754,14 +78778,14 @@ async function status3(intentId, opts) {
77754
78778
  process.exit(1);
77755
78779
  }
77756
78780
  }
77757
- if (jsonMode7) {
78781
+ if (jsonMode8) {
77758
78782
  process.stdout.write(JSON.stringify(final, null, 2) + "\n");
77759
78783
  } else {
77760
78784
  printSnap(final);
77761
78785
  }
77762
78786
  process.exit(final.status === "mined" ? 0 : 1);
77763
78787
  }
77764
- if (jsonMode7) {
78788
+ if (jsonMode8) {
77765
78789
  process.stdout.write(JSON.stringify(snap, null, 2) + "\n");
77766
78790
  process.exit(snap.status === "mined" ? 0 : 0);
77767
78791
  }
@@ -77854,16 +78878,16 @@ async function balance(opts) {
77854
78878
  }
77855
78879
  chainFilter = id2;
77856
78880
  }
77857
- const jsonMode7 = opts.json === true;
78881
+ const jsonMode8 = opts.json === true;
77858
78882
  const outcome = await callWithAutoRelogin({
77859
78883
  profile,
77860
78884
  profileName,
77861
- jsonMode: jsonMode7,
78885
+ jsonMode: jsonMode8,
77862
78886
  ttyHeader: import_picocolors24.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026"),
77863
78887
  fn: (bearer, origin) => apiFetch("/api/balances", { bearer, origin })
77864
78888
  });
77865
78889
  if (outcome.kind === "auth_failed") {
77866
- if (jsonMode7) {
78890
+ if (jsonMode8) {
77867
78891
  process.stdout.write(
77868
78892
  JSON.stringify({ ok: false, status: "auth_failed", error: outcome.reason }) + "\n"
77869
78893
  );
@@ -77884,7 +78908,7 @@ async function balance(opts) {
77884
78908
  }
77885
78909
  const res = outcome.result;
77886
78910
  const filtered = chainFilter !== null ? res.chains.filter((c) => c.chainId === chainFilter) : res.chains;
77887
- if (jsonMode7) {
78911
+ if (jsonMode8) {
77888
78912
  process.stdout.write(
77889
78913
  JSON.stringify(
77890
78914
  chainFilter !== null ? { ...res, chains: filtered } : res,
@@ -78012,11 +79036,11 @@ async function history(opts) {
78012
79036
  }
78013
79037
  limit = n2;
78014
79038
  }
78015
- const jsonMode7 = opts.json === true;
79039
+ const jsonMode8 = opts.json === true;
78016
79040
  const outcome = await callWithAutoRelogin({
78017
79041
  profile,
78018
79042
  profileName,
78019
- jsonMode: jsonMode7,
79043
+ jsonMode: jsonMode8,
78020
79044
  ttyHeader: import_picocolors25.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026"),
78021
79045
  fn: (bearer, origin) => apiFetch(
78022
79046
  `/api/history?limit=${encodeURIComponent(String(limit))}`,
@@ -78024,7 +79048,7 @@ async function history(opts) {
78024
79048
  )
78025
79049
  });
78026
79050
  if (outcome.kind === "auth_failed") {
78027
- if (jsonMode7) {
79051
+ if (jsonMode8) {
78028
79052
  process.stdout.write(
78029
79053
  JSON.stringify({ ok: false, status: "auth_failed", error: outcome.reason }) + "\n"
78030
79054
  );
@@ -78044,7 +79068,7 @@ async function history(opts) {
78044
79068
  throw err;
78045
79069
  }
78046
79070
  const res = outcome.result;
78047
- if (jsonMode7) {
79071
+ if (jsonMode8) {
78048
79072
  process.stdout.write(JSON.stringify(res, null, 2) + "\n");
78049
79073
  return;
78050
79074
  }
@@ -78562,7 +79586,7 @@ async function swap(amount, fromAsset, opts) {
78562
79586
  }
78563
79587
  const { profile, name: profileName } = resolved;
78564
79588
  const stdoutIsTty = process.stdout.isTTY === true;
78565
- const jsonMode7 = opts.json === true || !stdoutIsTty;
79589
+ const jsonMode8 = opts.json === true || !stdoutIsTty;
78566
79590
  const amountNumber = Number(amount);
78567
79591
  if (!Number.isFinite(amountNumber) || amountNumber <= 0) {
78568
79592
  failArg(`amount must be a positive number (got ${import_picocolors27.default.bold(amount)}).`);
@@ -78701,7 +79725,7 @@ async function swap(amount, fromAsset, opts) {
78701
79725
  body: proposeBody,
78702
79726
  profileName,
78703
79727
  initialProfile: profile,
78704
- jsonMode: jsonMode7,
79728
+ jsonMode: jsonMode8,
78705
79729
  shouldOpenBrowser,
78706
79730
  buildRetryCommand
78707
79731
  });
@@ -78722,7 +79746,7 @@ async function batch(opts) {
78722
79746
  process.exit(2);
78723
79747
  }
78724
79748
  const { name: profileName, profile } = resolved;
78725
- const jsonMode7 = opts.json === true || !process.stdout.isTTY;
79749
+ const jsonMode8 = opts.json === true || !process.stdout.isTTY;
78726
79750
  let legs;
78727
79751
  try {
78728
79752
  legs = JSON.parse(opts.legsJson);
@@ -78766,7 +79790,7 @@ async function batch(opts) {
78766
79790
  },
78767
79791
  profileName,
78768
79792
  initialProfile: profile,
78769
- jsonMode: jsonMode7,
79793
+ jsonMode: jsonMode8,
78770
79794
  shouldOpenBrowser
78771
79795
  });
78772
79796
  }
@@ -78791,7 +79815,7 @@ async function fundWallet(address, opts) {
78791
79815
  process.exit(2);
78792
79816
  }
78793
79817
  const { name: profileName, profile } = resolved;
78794
- const jsonMode7 = opts.json === true || !process.stdout.isTTY;
79818
+ const jsonMode8 = opts.json === true || !process.stdout.isTTY;
78795
79819
  if (!opts.chain) {
78796
79820
  failArg3("--chain is required (1/137/8453/42161/900 or shortName).");
78797
79821
  }
@@ -78843,7 +79867,7 @@ async function fundWallet(address, opts) {
78843
79867
  },
78844
79868
  profileName,
78845
79869
  initialProfile: profile,
78846
- jsonMode: jsonMode7,
79870
+ jsonMode: jsonMode8,
78847
79871
  shouldOpenBrowser
78848
79872
  });
78849
79873
  }
@@ -78858,7 +79882,7 @@ async function fundWallet(address, opts) {
78858
79882
  },
78859
79883
  profileName,
78860
79884
  initialProfile: profile,
78861
- jsonMode: jsonMode7,
79885
+ jsonMode: jsonMode8,
78862
79886
  shouldOpenBrowser
78863
79887
  });
78864
79888
  }
@@ -78885,7 +79909,7 @@ async function earnSupply(amount, asset, opts) {
78885
79909
  }
78886
79910
  const { profile, name: profileName } = resolved;
78887
79911
  const stdoutIsTty = process.stdout.isTTY === true;
78888
- const jsonMode7 = opts.json === true || !stdoutIsTty;
79912
+ const jsonMode8 = opts.json === true || !stdoutIsTty;
78889
79913
  const amountNumber = Number(amount);
78890
79914
  if (!Number.isFinite(amountNumber) || amountNumber <= 0) {
78891
79915
  failArg4(`amount must be a positive number (got ${import_picocolors30.default.bold(amount)}).`);
@@ -78951,7 +79975,7 @@ async function earnSupply(amount, asset, opts) {
78951
79975
  body: proposeBody,
78952
79976
  profileName,
78953
79977
  initialProfile: profile,
78954
- jsonMode: jsonMode7,
79978
+ jsonMode: jsonMode8,
78955
79979
  shouldOpenBrowser
78956
79980
  });
78957
79981
  }
@@ -78978,7 +80002,7 @@ async function earnWithdraw(amountOrMax, asset, opts) {
78978
80002
  }
78979
80003
  const { profile, name: profileName } = resolved;
78980
80004
  const stdoutIsTty = process.stdout.isTTY === true;
78981
- const jsonMode7 = opts.json === true || !stdoutIsTty;
80005
+ const jsonMode8 = opts.json === true || !stdoutIsTty;
78982
80006
  const isMax = amountOrMax.toLowerCase() === "max";
78983
80007
  if (!isMax) {
78984
80008
  const amountNumber = Number(amountOrMax);
@@ -79049,7 +80073,7 @@ async function earnWithdraw(amountOrMax, asset, opts) {
79049
80073
  body: proposeBody,
79050
80074
  profileName,
79051
80075
  initialProfile: profile,
79052
- jsonMode: jsonMode7,
80076
+ jsonMode: jsonMode8,
79053
80077
  shouldOpenBrowser
79054
80078
  });
79055
80079
  }
@@ -79091,8 +80115,8 @@ async function loadResolvedProfile(requested) {
79091
80115
  }
79092
80116
  return resolved;
79093
80117
  }
79094
- function printResult(res, jsonMode7) {
79095
- if (jsonMode7) {
80118
+ function printResult(res, jsonMode8) {
80119
+ if (jsonMode8) {
79096
80120
  process.stdout.write(JSON.stringify(res, null, 2) + "\n");
79097
80121
  return;
79098
80122
  }
@@ -79128,16 +80152,16 @@ async function postRestaurantQuiet(path8, body, resolved) {
79128
80152
  return null;
79129
80153
  }
79130
80154
  }
79131
- async function postRestaurant(path8, body, resolved, jsonMode7) {
80155
+ async function postRestaurant(path8, body, resolved, jsonMode8) {
79132
80156
  const outcome = await callWithAutoRelogin({
79133
80157
  profile: resolved.profile,
79134
80158
  profileName: resolved.name,
79135
- jsonMode: jsonMode7,
80159
+ jsonMode: jsonMode8,
79136
80160
  ttyHeader: import_picocolors32.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026"),
79137
80161
  fn: (bearer, origin) => apiFetch(path8, { method: "POST", bearer, origin, body })
79138
80162
  });
79139
80163
  if (outcome.kind === "auth_failed") {
79140
- if (jsonMode7) {
80164
+ if (jsonMode8) {
79141
80165
  process.stdout.write(
79142
80166
  JSON.stringify({ ok: false, status: "auth_failed", error: outcome.reason }) + "\n"
79143
80167
  );
@@ -79150,7 +80174,7 @@ async function postRestaurant(path8, body, resolved, jsonMode7) {
79150
80174
  if (outcome.kind === "error") {
79151
80175
  const err = outcome.error;
79152
80176
  if (err instanceof ApiError) {
79153
- if (jsonMode7) {
80177
+ if (jsonMode8) {
79154
80178
  process.stdout.write(
79155
80179
  JSON.stringify({ ok: false, status: "request_failed", error: err.message, http_status: err.status }) + "\n"
79156
80180
  );
@@ -79166,7 +80190,7 @@ async function postRestaurant(path8, body, resolved, jsonMode7) {
79166
80190
  }
79167
80191
  async function searchFood(opts) {
79168
80192
  const resolved = await loadResolvedProfile(opts.profile ?? DEFAULT_PROFILE);
79169
- const jsonMode7 = opts.json === true || process.stdout.isTTY !== true;
80193
+ const jsonMode8 = opts.json === true || process.stdout.isTTY !== true;
79170
80194
  if (!opts.location && !opts.name) {
79171
80195
  process.stderr.write(
79172
80196
  import_picocolors32.default.red("\u2715 Pass --location (search near a place) or --name (look one store up).\n")
@@ -79182,12 +80206,12 @@ async function searchFood(opts) {
79182
80206
  if (opts.radiusMiles !== void 0) body.radius_miles = Number(opts.radiusMiles);
79183
80207
  if (opts.openOnly !== void 0) body.open_only = opts.openOnly;
79184
80208
  if (opts.limit !== void 0) body.limit = Number(opts.limit);
79185
- const result = await postRestaurant("/api/restaurants/search", body, resolved, jsonMode7);
79186
- if (result) printResult(result, jsonMode7);
80209
+ const result = await postRestaurant("/api/restaurants/search", body, resolved, jsonMode8);
80210
+ if (result) printResult(result, jsonMode8);
79187
80211
  }
79188
80212
  async function menuFood(items, opts) {
79189
80213
  const resolved = await loadResolvedProfile(opts.profile ?? DEFAULT_PROFILE);
79190
- const jsonMode7 = opts.json === true || process.stdout.isTTY !== true;
80214
+ const jsonMode8 = opts.json === true || process.stdout.isTTY !== true;
79191
80215
  if (!opts.brand || !opts.address) {
79192
80216
  process.stderr.write(
79193
80217
  import_picocolors32.default.red(
@@ -79202,12 +80226,12 @@ async function menuFood(items, opts) {
79202
80226
  intent: opts.intent,
79203
80227
  items: items ?? []
79204
80228
  };
79205
- const result = await postRestaurant("/api/restaurants/menu", body, resolved, jsonMode7);
79206
- if (result) printResult(result, jsonMode7);
80229
+ const result = await postRestaurant("/api/restaurants/menu", body, resolved, jsonMode8);
80230
+ if (result) printResult(result, jsonMode8);
79207
80231
  }
79208
80232
  async function orderFood(items, opts) {
79209
80233
  const resolved = await loadResolvedProfile(opts.profile ?? DEFAULT_PROFILE);
79210
- const jsonMode7 = opts.json === true || process.stdout.isTTY !== true;
80234
+ const jsonMode8 = opts.json === true || process.stdout.isTTY !== true;
79211
80235
  if (!opts.brand || !opts.address) {
79212
80236
  process.stderr.write(
79213
80237
  import_picocolors32.default.red(
@@ -79238,9 +80262,9 @@ async function orderFood(items, opts) {
79238
80262
  fulfillment: opts.fulfillment,
79239
80263
  intent: opts.intent
79240
80264
  };
79241
- const result = await postRestaurant("/api/restaurants/order", body, resolved, jsonMode7);
80265
+ const result = await postRestaurant("/api/restaurants/order", body, resolved, jsonMode8);
79242
80266
  if (!result) return;
79243
- printResult(result, jsonMode7);
80267
+ printResult(result, jsonMode8);
79244
80268
  const approvalUrl = typeof result.approval_url === "string" ? result.approval_url : null;
79245
80269
  const browserAllowed = (() => {
79246
80270
  if (opts.browserMode === "open") return true;
@@ -79259,7 +80283,7 @@ async function orderFood(items, opts) {
79259
80283
  return;
79260
80284
  }
79261
80285
  if (!agentCard.will_attempt) {
79262
- if (!jsonMode7) {
80286
+ if (!jsonMode8) {
79263
80287
  process.stderr.write(
79264
80288
  import_picocolors32.default.yellow(
79265
80289
  `This order is over your saved card's per-order cap (${fmtCents(agentCard.max_per_order_cents)}), so it needs you.
@@ -79270,8 +80294,8 @@ async function orderFood(items, opts) {
79270
80294
  openApproval();
79271
80295
  return;
79272
80296
  }
79273
- const verdict = await pollOrderVerdict(orderId, resolved, jsonMode7);
79274
- if (jsonMode7) {
80297
+ const verdict = await pollOrderVerdict(orderId, resolved, jsonMode8);
80298
+ if (jsonMode8) {
79275
80299
  process.stdout.write(JSON.stringify(verdict) + "\n");
79276
80300
  if (verdict.status === "failed") return;
79277
80301
  return;
@@ -79328,8 +80352,8 @@ function fmtCents(cents) {
79328
80352
  }
79329
80353
  var POLL_BUDGET_MS = 1e5;
79330
80354
  var POLL_INTERVAL_MS2 = 3500;
79331
- async function pollOrderVerdict(orderId, resolved, jsonMode7) {
79332
- if (!jsonMode7) {
80355
+ async function pollOrderVerdict(orderId, resolved, jsonMode8) {
80356
+ if (!jsonMode8) {
79333
80357
  process.stderr.write(import_picocolors32.default.dim("Your saved card is paying this \u2014 watching for the result\u2026\n"));
79334
80358
  }
79335
80359
  const deadline = Date.now() + POLL_BUDGET_MS;
@@ -79360,19 +80384,19 @@ async function pollOrderVerdict(orderId, resolved, jsonMode7) {
79360
80384
  }
79361
80385
  async function statusFood(orderId, opts) {
79362
80386
  const resolved = await loadResolvedProfile(opts.profile ?? DEFAULT_PROFILE);
79363
- const jsonMode7 = opts.json === true || process.stdout.isTTY !== true;
80387
+ const jsonMode8 = opts.json === true || process.stdout.isTTY !== true;
79364
80388
  const result = await postRestaurant(
79365
80389
  "/api/restaurants/order-status",
79366
80390
  { order_id: orderId.trim() },
79367
80391
  resolved,
79368
- jsonMode7
80392
+ jsonMode8
79369
80393
  );
79370
80394
  if (!result) return;
79371
80395
  if (result.blocked) {
79372
- printResult(result, jsonMode7);
80396
+ printResult(result, jsonMode8);
79373
80397
  return;
79374
80398
  }
79375
- if (jsonMode7) {
80399
+ if (jsonMode8) {
79376
80400
  process.stdout.write(JSON.stringify(result, null, 2) + "\n");
79377
80401
  return;
79378
80402
  }
@@ -79414,16 +80438,16 @@ async function withProfile(opts, path8, init2) {
79414
80438
  `));
79415
80439
  }
79416
80440
  const { profile, name: profileName } = resolved;
79417
- const jsonMode7 = opts.json === true;
80441
+ const jsonMode8 = opts.json === true;
79418
80442
  const outcome = await callWithAutoRelogin({
79419
80443
  profile,
79420
80444
  profileName,
79421
- jsonMode: jsonMode7,
80445
+ jsonMode: jsonMode8,
79422
80446
  ttyHeader: import_picocolors33.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026"),
79423
80447
  fn: (bearer, origin) => apiFetch(path8, init2 ? { bearer, origin, method: init2.method, body: init2.body } : { bearer, origin })
79424
80448
  });
79425
80449
  if (outcome.kind === "auth_failed") {
79426
- if (jsonMode7) {
80450
+ if (jsonMode8) {
79427
80451
  process.stdout.write(JSON.stringify({ ok: false, status: "auth_failed", error: outcome.reason }) + "\n");
79428
80452
  process.exit(1);
79429
80453
  }
@@ -79442,9 +80466,9 @@ async function withProfile(opts, path8, init2) {
79442
80466
  }
79443
80467
  return outcome.result;
79444
80468
  }
79445
- function handleBlocked(res, jsonMode7) {
80469
+ function handleBlocked(res, jsonMode8) {
79446
80470
  if (!res.blocked) return false;
79447
- if (jsonMode7) {
80471
+ if (jsonMode8) {
79448
80472
  process.stdout.write(JSON.stringify(res, null, 2) + "\n");
79449
80473
  process.exit(1);
79450
80474
  }
@@ -79508,9 +80532,9 @@ function printTable(rows) {
79508
80532
  }
79509
80533
  }
79510
80534
  async function listBounties(opts) {
79511
- const jsonMode7 = opts.json === true;
80535
+ const jsonMode8 = opts.json === true;
79512
80536
  const res = await withProfile(opts, "/api/bounties");
79513
- handleBlocked(res, jsonMode7);
80537
+ handleBlocked(res, jsonMode8);
79514
80538
  let rows = res.bounties ?? [];
79515
80539
  const min = opts.min !== void 0 ? Number(opts.min) : void 0;
79516
80540
  const max = opts.max !== void 0 ? Number(opts.max) : void 0;
@@ -79548,7 +80572,7 @@ async function listBounties(opts) {
79548
80572
  process.exit(2);
79549
80573
  }
79550
80574
  const shown2 = rows.slice(0, limit);
79551
- if (jsonMode7) {
80575
+ if (jsonMode8) {
79552
80576
  process.stdout.write(JSON.stringify({ bounties: shown2, matched: rows.length }, null, 2) + "\n");
79553
80577
  return;
79554
80578
  }
@@ -79567,15 +80591,15 @@ async function listBounties(opts) {
79567
80591
  process.stdout.write(AI_DIRECTIVE + "\n");
79568
80592
  }
79569
80593
  async function showBounty(id2, opts) {
79570
- const jsonMode7 = opts.json === true;
80594
+ const jsonMode8 = opts.json === true;
79571
80595
  const clean3 = id2.trim().replace(/^.*\/bounty\//, "").replace(/[?#].*$/, "").trim();
79572
80596
  if (!clean3) {
79573
80597
  process.stderr.write(import_picocolors33.default.red("\u2715 Give a bounty id, or a agentgates.ai/bounty/<id> link.\n"));
79574
80598
  process.exit(2);
79575
80599
  }
79576
80600
  const res = await withProfile(opts, `/api/bounties/${encodeURIComponent(clean3)}`);
79577
- handleBlocked(res, jsonMode7);
79578
- if (jsonMode7) {
80601
+ handleBlocked(res, jsonMode8);
80602
+ if (jsonMode8) {
79579
80603
  process.stdout.write(JSON.stringify(res, null, 2) + "\n");
79580
80604
  return;
79581
80605
  }
@@ -79606,13 +80630,13 @@ async function showBounty(id2, opts) {
79606
80630
  process.stdout.write(AI_DIRECTIVE + "\n");
79607
80631
  }
79608
80632
  async function myBounties(opts) {
79609
- const jsonMode7 = opts.json === true;
80633
+ const jsonMode8 = opts.json === true;
79610
80634
  const res = await withProfile(opts, "/api/bounties?mine=1");
79611
- handleBlocked(res, jsonMode7);
80635
+ handleBlocked(res, jsonMode8);
79612
80636
  const all = res.bounties ?? [];
79613
80637
  const status4 = opts.status?.trim().toUpperCase();
79614
80638
  const rows = status4 ? all.filter((r) => (r.status ?? "").toUpperCase() === status4) : all;
79615
- if (jsonMode7) {
80639
+ if (jsonMode8) {
79616
80640
  process.stdout.write(JSON.stringify({ bounties: rows, submissions: res.submissions ?? [] }, null, 2) + "\n");
79617
80641
  return;
79618
80642
  }
@@ -79634,14 +80658,14 @@ async function myBounties(opts) {
79634
80658
  process.stdout.write(AI_DIRECTIVE + "\n");
79635
80659
  }
79636
80660
  async function bountyFeed(opts) {
79637
- const jsonMode7 = opts.json === true;
80661
+ const jsonMode8 = opts.json === true;
79638
80662
  const params = new URLSearchParams();
79639
80663
  if (opts.limit) params.set("limit", opts.limit);
79640
80664
  if (opts.type) params.set("type", opts.type);
79641
80665
  const qs = params.toString();
79642
80666
  const res = await withProfile(opts, `/api/bounties/feed${qs ? `?${qs}` : ""}`);
79643
- handleBlocked(res, jsonMode7);
79644
- if (jsonMode7) {
80667
+ handleBlocked(res, jsonMode8);
80668
+ if (jsonMode8) {
79645
80669
  process.stdout.write(JSON.stringify(res, null, 2) + "\n");
79646
80670
  return;
79647
80671
  }
@@ -79656,7 +80680,7 @@ async function bountyFeed(opts) {
79656
80680
  process.stdout.write(import_picocolors33.default.dim("Use --json for the full rows.\n"));
79657
80681
  }
79658
80682
  async function draftBounty(opts) {
79659
- const jsonMode7 = opts.json === true;
80683
+ const jsonMode8 = opts.json === true;
79660
80684
  const amountNum = Number(opts.amount);
79661
80685
  if (!Number.isFinite(amountNum) || amountNum <= 0) {
79662
80686
  process.stderr.write(import_picocolors33.default.red("\u2715 --amount must be a positive number of USDC.\n"));
@@ -79672,8 +80696,8 @@ async function draftBounty(opts) {
79672
80696
  evidenceType: opts.evidenceType
79673
80697
  }
79674
80698
  });
79675
- handleBlocked(res, jsonMode7);
79676
- if (jsonMode7) {
80699
+ handleBlocked(res, jsonMode8);
80700
+ if (jsonMode8) {
79677
80701
  process.stdout.write(JSON.stringify(res, null, 2) + "\n");
79678
80702
  return;
79679
80703
  }
@@ -79694,10 +80718,10 @@ function failArg6(message) {
79694
80718
  `));
79695
80719
  process.exit(2);
79696
80720
  }
79697
- async function loadProfileOrExit(requested, jsonMode7) {
80721
+ async function loadProfileOrExit(requested, jsonMode8) {
79698
80722
  const resolved = await resolveProfile(requested);
79699
80723
  if (!resolved) {
79700
- if (jsonMode7) {
80724
+ if (jsonMode8) {
79701
80725
  process.stdout.write(
79702
80726
  JSON.stringify({ ok: false, status: "auth_failed", error: "Not logged in. Run agentgates login first." }) + "\n"
79703
80727
  );
@@ -79706,7 +80730,7 @@ async function loadProfileOrExit(requested, jsonMode7) {
79706
80730
  }
79707
80731
  process.exit(2);
79708
80732
  }
79709
- if (resolved.autoSelected && !jsonMode7) {
80733
+ if (resolved.autoSelected && !jsonMode8) {
79710
80734
  process.stderr.write(import_picocolors34.default.dim(`Using profile "${resolved.name}" (pass --profile to choose)
79711
80735
  `));
79712
80736
  }
@@ -79726,8 +80750,8 @@ function resolveMaxUsd(opts, profile, fallbackHint) {
79726
80750
  );
79727
80751
  }
79728
80752
  async function fundBounty(bountyId, opts) {
79729
- const jsonMode7 = Boolean(opts.json) || !process.stdout.isTTY;
79730
- const { profile, profileName } = await loadProfileOrExit(opts.profile ?? DEFAULT_PROFILE, jsonMode7);
80753
+ const jsonMode8 = Boolean(opts.json) || !process.stdout.isTTY;
80754
+ const { profile, profileName } = await loadProfileOrExit(opts.profile ?? DEFAULT_PROFILE, jsonMode8);
79731
80755
  const maxUsd = resolveMaxUsd(opts, profile, "agentgates fund");
79732
80756
  return runIntentFlow({
79733
80757
  endpoint: "/api/intents/propose-fund-bounty",
@@ -79746,17 +80770,17 @@ async function fundBounty(bountyId, opts) {
79746
80770
  },
79747
80771
  profileName,
79748
80772
  initialProfile: profile,
79749
- jsonMode: jsonMode7,
80773
+ jsonMode: jsonMode8,
79750
80774
  shouldOpenBrowser: resolveBrowserDefault(opts.browserMode ?? "auto")
79751
80775
  });
79752
80776
  }
79753
80777
  async function tipBounty(bountyId, amount, opts) {
79754
- const jsonMode7 = Boolean(opts.json) || !process.stdout.isTTY;
80778
+ const jsonMode8 = Boolean(opts.json) || !process.stdout.isTTY;
79755
80779
  const amt = Number(amount);
79756
80780
  if (!Number.isFinite(amt) || amt <= 0) {
79757
80781
  failArg6(`amount must be a positive USDC number (got ${amount}).`);
79758
80782
  }
79759
- const { profile, profileName } = await loadProfileOrExit(opts.profile ?? DEFAULT_PROFILE, jsonMode7);
80783
+ const { profile, profileName } = await loadProfileOrExit(opts.profile ?? DEFAULT_PROFILE, jsonMode8);
79760
80784
  const maxUsd = opts.maxUsd !== void 0 ? resolveMaxUsd(opts, profile, "agentgates tip") : Math.ceil(amt * 1.01 * 100) / 100;
79761
80785
  return runIntentFlow({
79762
80786
  endpoint: "/api/intents/propose-tip",
@@ -79776,17 +80800,17 @@ async function tipBounty(bountyId, amount, opts) {
79776
80800
  },
79777
80801
  profileName,
79778
80802
  initialProfile: profile,
79779
- jsonMode: jsonMode7,
80803
+ jsonMode: jsonMode8,
79780
80804
  shouldOpenBrowser: resolveBrowserDefault(opts.browserMode ?? "auto")
79781
80805
  });
79782
80806
  }
79783
80807
  async function subscribeCreator(creatorUserId, opts) {
79784
- const jsonMode7 = Boolean(opts.json) || !process.stdout.isTTY;
80808
+ const jsonMode8 = Boolean(opts.json) || !process.stdout.isTTY;
79785
80809
  const months = opts.months === void 0 ? 1 : Number(opts.months);
79786
80810
  if (![1, 3, 12].includes(months)) {
79787
80811
  failArg6(`--months must be 1, 3 or 12 (got ${opts.months}). Prepaid periods only \u2014 no auto-renew exists.`);
79788
80812
  }
79789
- const { profile, profileName } = await loadProfileOrExit(opts.profile ?? DEFAULT_PROFILE, jsonMode7);
80813
+ const { profile, profileName } = await loadProfileOrExit(opts.profile ?? DEFAULT_PROFILE, jsonMode8);
79790
80814
  const maxUsd = resolveMaxUsd(opts, profile, "agentgates subscribe");
79791
80815
  return runIntentFlow({
79792
80816
  endpoint: "/api/intents/propose-subscribe",
@@ -79806,7 +80830,7 @@ async function subscribeCreator(creatorUserId, opts) {
79806
80830
  },
79807
80831
  profileName,
79808
80832
  initialProfile: profile,
79809
- jsonMode: jsonMode7,
80833
+ jsonMode: jsonMode8,
79810
80834
  shouldOpenBrowser: resolveBrowserDefault(opts.browserMode ?? "auto")
79811
80835
  });
79812
80836
  }
@@ -79825,16 +80849,16 @@ async function runWork(path8, body, opts) {
79825
80849
  process.stderr.write(import_picocolors35.default.dim(`Using profile "${resolved.name}" (pass --profile to choose)
79826
80850
  `));
79827
80851
  }
79828
- const jsonMode7 = opts.json === true;
80852
+ const jsonMode8 = opts.json === true;
79829
80853
  const outcome = await callWithAutoRelogin({
79830
80854
  profile: resolved.profile,
79831
80855
  profileName: resolved.name,
79832
- jsonMode: jsonMode7,
80856
+ jsonMode: jsonMode8,
79833
80857
  ttyHeader: import_picocolors35.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026"),
79834
80858
  fn: (bearer, origin) => apiFetch(path8, { bearer, origin, method: "POST", body })
79835
80859
  });
79836
80860
  if (outcome.kind === "auth_failed") {
79837
- if (jsonMode7) {
80861
+ if (jsonMode8) {
79838
80862
  process.stdout.write(JSON.stringify({ ok: false, status: "auth_failed", error: outcome.reason }) + "\n");
79839
80863
  process.exit(1);
79840
80864
  }
@@ -79845,7 +80869,7 @@ async function runWork(path8, body, opts) {
79845
80869
  if (outcome.kind === "error") {
79846
80870
  const err = outcome.error;
79847
80871
  if (err instanceof ApiError) {
79848
- if (jsonMode7) {
80872
+ if (jsonMode8) {
79849
80873
  process.stdout.write(JSON.stringify({ ok: false, error: err.message, http_status: err.status }) + "\n");
79850
80874
  } else {
79851
80875
  process.stderr.write(import_picocolors35.default.red(`\u2715 ${err.message} (HTTP ${err.status})
@@ -79857,7 +80881,7 @@ async function runWork(path8, body, opts) {
79857
80881
  }
79858
80882
  const data4 = outcome.result;
79859
80883
  if (data4.blocked) {
79860
- if (jsonMode7) {
80884
+ if (jsonMode8) {
79861
80885
  process.stdout.write(JSON.stringify({ ok: false, ...data4 }) + "\n");
79862
80886
  process.exit(1);
79863
80887
  }
@@ -79871,7 +80895,7 @@ ${import_picocolors35.default.bold(data4.upgrade_url)}
79871
80895
  process.exit(1);
79872
80896
  }
79873
80897
  if (typeof data4.error === "string" && data4.error) {
79874
- if (jsonMode7) {
80898
+ if (jsonMode8) {
79875
80899
  process.stdout.write(JSON.stringify({ ok: false, error: data4.error }) + "\n");
79876
80900
  } else {
79877
80901
  process.stderr.write(import_picocolors35.default.red(`\u2715 ${data4.error}
@@ -79879,7 +80903,7 @@ ${import_picocolors35.default.bold(data4.upgrade_url)}
79879
80903
  }
79880
80904
  process.exit(1);
79881
80905
  }
79882
- if (jsonMode7) {
80906
+ if (jsonMode8) {
79883
80907
  process.stdout.write(JSON.stringify({ ok: true, ...data4 }) + "\n");
79884
80908
  return;
79885
80909
  }
@@ -79923,14 +80947,14 @@ init_constants();
79923
80947
  var FLUSH_MS = 400;
79924
80948
  var FLUSH_BYTES = 2048;
79925
80949
  async function deliver(bountyId, command, opts) {
79926
- const jsonMode7 = opts.json === true;
80950
+ const jsonMode8 = opts.json === true;
79927
80951
  const requested = opts.profile ?? DEFAULT_PROFILE;
79928
80952
  const resolved = await resolveProfile(requested);
79929
80953
  if (!resolved) {
79930
80954
  process.stderr.write(import_picocolors36.default.red("Not logged in. Run agentgates login first.\n"));
79931
80955
  process.exit(2);
79932
80956
  }
79933
- if (resolved.autoSelected && !jsonMode7) {
80957
+ if (resolved.autoSelected && !jsonMode8) {
79934
80958
  process.stderr.write(import_picocolors36.default.dim(`Using profile "${resolved.name}" (pass --profile to choose)
79935
80959
  `));
79936
80960
  }
@@ -79938,7 +80962,7 @@ async function deliver(bountyId, command, opts) {
79938
80962
  const outcome = await callWithAutoRelogin({
79939
80963
  profile: resolved.profile,
79940
80964
  profileName: resolved.name,
79941
- jsonMode: jsonMode7,
80965
+ jsonMode: jsonMode8,
79942
80966
  ttyHeader: import_picocolors36.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026"),
79943
80967
  fn: (bearer, origin) => apiFetch(path8, { bearer, origin, method: "POST", body })
79944
80968
  });
@@ -79947,7 +80971,7 @@ async function deliver(bountyId, command, opts) {
79947
80971
  return outcome.result;
79948
80972
  };
79949
80973
  const die = (msg, data4) => {
79950
- if (jsonMode7) {
80974
+ if (jsonMode8) {
79951
80975
  process.stdout.write(JSON.stringify({ ok: false, error: msg, ...data4 ?? {} }) + "\n");
79952
80976
  } else {
79953
80977
  process.stderr.write(import_picocolors36.default.red(`
@@ -79977,7 +81001,7 @@ ${import_picocolors36.default.bold(data4.upgrade_url)}
79977
81001
  if (started.error) return void die(started.error, started);
79978
81002
  const runId = started.run_id;
79979
81003
  if (!runId) return void die("The service opened a run but did not name it.");
79980
- if (!jsonMode7) {
81004
+ if (!jsonMode8) {
79981
81005
  process.stderr.write(
79982
81006
  import_picocolors36.default.bold("\n\u25CF LIVE ") + import_picocolors36.default.dim("everything below is going onto the bounty page as it happens\n") + import_picocolors36.default.dim(` ${started.url ?? ""}
79983
81007
 
@@ -80008,7 +81032,7 @@ ${import_picocolors36.default.bold(data4.upgrade_url)}
80008
81032
  const timer = setInterval(() => flush(true), FLUSH_MS);
80009
81033
  const consume = (data4) => {
80010
81034
  buffer += data4;
80011
- if (!opts.quiet && !jsonMode7) process.stderr.write(data4);
81035
+ if (!opts.quiet && !jsonMode8) process.stderr.write(data4);
80012
81036
  flush();
80013
81037
  };
80014
81038
  let exitCode = 0;
@@ -80031,7 +81055,7 @@ ${import_picocolors36.default.bold(data4.upgrade_url)}
80031
81055
  child.stdout.on("data", (d) => consume(d));
80032
81056
  child.stderr.setEncoding("utf8");
80033
81057
  child.stderr.on("data", (d) => {
80034
- if (!jsonMode7) process.stderr.write(import_picocolors36.default.dim(d));
81058
+ if (!jsonMode8) process.stderr.write(import_picocolors36.default.dim(d));
80035
81059
  });
80036
81060
  child.on("error", (err) => {
80037
81061
  process.stderr.write(import_picocolors36.default.red(`
@@ -80056,7 +81080,7 @@ ${import_picocolors36.default.bold(data4.upgrade_url)}
80056
81080
  }
80057
81081
  if (finished.blocked) return void die(finished.reason ?? "Blocked.", finished);
80058
81082
  if (finished.error) return void die(finished.error, finished);
80059
- if (jsonMode7) {
81083
+ if (jsonMode8) {
80060
81084
  process.stdout.write(
80061
81085
  JSON.stringify({
80062
81086
  ok: true,
@@ -80094,7 +81118,7 @@ init_constants();
80094
81118
  // src/lib/trade-sol.ts
80095
81119
  var import_web3 = __toESM(require_index_cjs(), 1);
80096
81120
  init_constants();
80097
- import { promises as fs8 } from "node:fs";
81121
+ import { promises as fs9 } from "node:fs";
80098
81122
  import * as path6 from "node:path";
80099
81123
  import * as os3 from "node:os";
80100
81124
  var TRADE_CHAIN_ID = 901;
@@ -80191,7 +81215,7 @@ function tradeSolPath() {
80191
81215
  async function loadTradeKey() {
80192
81216
  let raw;
80193
81217
  try {
80194
- raw = await fs8.readFile(tradeSolPath(), "utf8");
81218
+ raw = await fs9.readFile(tradeSolPath(), "utf8");
80195
81219
  } catch (err) {
80196
81220
  if (err.code === "ENOENT") return null;
80197
81221
  throw err;
@@ -80219,11 +81243,11 @@ async function loadOrCreateTradeKey() {
80219
81243
  createdAt: (/* @__PURE__ */ new Date()).toISOString()
80220
81244
  };
80221
81245
  const dir = path6.dirname(tradeSolPath());
80222
- await fs8.mkdir(dir, { recursive: true, mode: 448 });
80223
- await fs8.chmod(dir, 448).catch(() => {
81246
+ await fs9.mkdir(dir, { recursive: true, mode: 448 });
81247
+ await fs9.chmod(dir, 448).catch(() => {
80224
81248
  });
80225
- await fs8.writeFile(tradeSolPath(), JSON.stringify(state, null, 2), { mode: 384 });
80226
- await fs8.chmod(tradeSolPath(), 384).catch(() => {
81249
+ await fs9.writeFile(tradeSolPath(), JSON.stringify(state, null, 2), { mode: 384 });
81250
+ await fs9.chmod(tradeSolPath(), 384).catch(() => {
80227
81251
  });
80228
81252
  return { state, keypair, created: true };
80229
81253
  }
@@ -80452,7 +81476,7 @@ async function runTrade(args) {
80452
81476
  }
80453
81477
 
80454
81478
  // src/commands/trade.ts
80455
- function fail8(message, json2) {
81479
+ function fail9(message, json2) {
80456
81480
  if (json2) {
80457
81481
  process.stdout.write(JSON.stringify({ ok: false, error: message }) + "\n");
80458
81482
  } else {
@@ -80466,7 +81490,7 @@ async function withContext(opts, fn) {
80466
81490
  const ctx2 = await resolveTradeContext();
80467
81491
  return await fn(ctx2);
80468
81492
  } catch (err) {
80469
- fail8(err.message, opts.json);
81493
+ fail9(err.message, opts.json);
80470
81494
  }
80471
81495
  }
80472
81496
  function servedFloorUnits(ctx2) {
@@ -80492,7 +81516,7 @@ async function tradeKey(opts) {
80492
81516
  ];
80493
81517
  process.stdout.write(lines.join("\n") + "\n" + AI_DIRECTIVE + "\n");
80494
81518
  } catch (err) {
80495
- fail8(err.message, opts.json);
81519
+ fail9(err.message, opts.json);
80496
81520
  }
80497
81521
  }
80498
81522
  async function tradeStatus(opts) {
@@ -80549,7 +81573,7 @@ async function tradeQuote(coinArg, amount, opts) {
80549
81573
  const coin = await resolveCoin(coinArg);
80550
81574
  const amountNumber = Number(amount);
80551
81575
  if (!Number.isFinite(amountNumber) || amountNumber <= 0) {
80552
- fail8(`Amount "${amount}" is not a positive number.`, opts.json);
81576
+ fail9(`Amount "${amount}" is not a positive number.`, opts.json);
80553
81577
  }
80554
81578
  const res = await fetch(`${CREATORS_ORIGIN}/api/launch-quote`, {
80555
81579
  method: "POST",
@@ -80563,7 +81587,7 @@ async function tradeQuote(coinArg, amount, opts) {
80563
81587
  });
80564
81588
  const body = await res.json().catch(() => null);
80565
81589
  if (!res.ok || !body) {
80566
- fail8(`Quote failed: ${body?.error ?? `HTTP ${res.status}`}`, opts.json);
81590
+ fail9(`Quote failed: ${body?.error ?? `HTTP ${res.status}`}`, opts.json);
80567
81591
  }
80568
81592
  const floor = servedFloorUnits(ctx2);
80569
81593
  const belowFloor = side === "buy" && floor !== null && parseDecimalToUnits(amount, USDC_DECIMALS, "Amount") < floor.units;
@@ -80638,12 +81662,12 @@ async function tradeBuy(coinArg, amount, opts) {
80638
81662
  try {
80639
81663
  units = parseDecimalToUnits(amount, USDC_DECIMALS, "Buy amount");
80640
81664
  } catch (err) {
80641
- fail8(err.message, opts.json);
81665
+ fail9(err.message, opts.json);
80642
81666
  }
80643
- if (units <= 0n) fail8("Buy amount must be above zero.", opts.json);
81667
+ if (units <= 0n) fail9("Buy amount must be above zero.", opts.json);
80644
81668
  const floor = servedFloorUnits(ctx2);
80645
81669
  if (floor && units < floor.units) {
80646
- fail8(`Buys start at $${floor.usdc} (served by launch-config; the relay refuses below it).`, opts.json);
81670
+ fail9(`Buys start at $${floor.usdc} (served by launch-config; the relay refuses below it).`, opts.json);
80647
81671
  }
80648
81672
  const { keypair, state, created } = await loadOrCreateTradeKey();
80649
81673
  if (created && !opts.json) {
@@ -80658,23 +81682,23 @@ async function tradeSell(coinArg, amount, opts) {
80658
81682
  await withContext(opts, async (ctx2) => {
80659
81683
  const coin = await resolveCoin(coinArg);
80660
81684
  const key = await loadTradeKey();
80661
- if (!key) fail8("No agent trading key yet (nothing to sell with). Run: agentgates trade key", opts.json);
81685
+ if (!key) fail9("No agent trading key yet (nothing to sell with). Run: agentgates trade key", opts.json);
80662
81686
  let sellAmount = amount.trim();
80663
81687
  const pct = sellAmount.match(/^(\d+)%$/);
80664
81688
  if (sellAmount === "all" || pct) {
80665
81689
  const bal = await readTokenBalance(rpcConnection(), key.state.address, coin.mint);
80666
- if (!bal) fail8("Could not read the coin balance from the RPC; pass an explicit amount.", opts.json);
80667
- if (bal.units <= 0n) fail8("This key holds none of that coin.", opts.json);
81690
+ if (!bal) fail9("Could not read the coin balance from the RPC; pass an explicit amount.", opts.json);
81691
+ if (bal.units <= 0n) fail9("This key holds none of that coin.", opts.json);
80668
81692
  let units = bal.units;
80669
81693
  if (pct) {
80670
81694
  const p = BigInt(pct[1]);
80671
- if (p <= 0n || p > 100n) fail8(`Percentage must be 1-100, got "${amount}".`, opts.json);
81695
+ if (p <= 0n || p > 100n) fail9(`Percentage must be 1-100, got "${amount}".`, opts.json);
80672
81696
  units = bal.units * p / 100n;
80673
81697
  }
80674
- if (units <= 0n) fail8("Sell amount rounds to zero.", opts.json);
81698
+ if (units <= 0n) fail9("Sell amount rounds to zero.", opts.json);
80675
81699
  sellAmount = formatUnits2(units, bal.decimals);
80676
81700
  } else if (!/^\d+(\.\d+)?$/.test(sellAmount)) {
80677
- fail8(`Sell amount "${amount}" is not a coin amount, a percentage like 50%, or "all".`, opts.json);
81701
+ fail9(`Sell amount "${amount}" is not a coin amount, a percentage like 50%, or "all".`, opts.json);
80678
81702
  }
80679
81703
  const result = await runTrade({ ctx: ctx2, keypair: key.keypair, token: coin.mint, side: "sell", amount: sellAmount, minOut: opts.minOut });
80680
81704
  await reportTrade(ctx2, opts, { side: "sell", coin, address: key.state.address, amount: sellAmount, result });
@@ -80689,16 +81713,16 @@ function describeOrder(o) {
80689
81713
  async function tradeOrderPlace(coinArg, opts) {
80690
81714
  await withContext(opts, async (ctx2) => {
80691
81715
  if (opts.buy === void 0 === (opts.sell === void 0)) {
80692
- fail8("Pass exactly one of --buy <usdc> or --sell <amount|N%|all>.", opts.json);
81716
+ fail9("Pass exactly one of --buy <usdc> or --sell <amount|N%|all>.", opts.json);
80693
81717
  }
80694
81718
  if (opts.at === void 0 === (opts.onGraduation !== true)) {
80695
- fail8("Pass exactly one trigger: --at <value> (price, or mcap with --mcap) or --on-graduation.", opts.json);
81719
+ fail9("Pass exactly one trigger: --at <value> (price, or mcap with --mcap) or --on-graduation.", opts.json);
80696
81720
  }
80697
81721
  const coin = await resolveCoin(coinArg);
80698
81722
  const side = opts.buy !== void 0 ? "buy" : "sell";
80699
81723
  const kind = opts.onGraduation ? side === "buy" ? "buy_on_graduation" : "sell_on_graduation" : side === "buy" ? "buy_at" : "sell_at";
80700
- if (opts.stop && kind !== "sell_at") fail8("--stop only applies to a --sell order with --at.", opts.json);
80701
- if (opts.mcap && !opts.at) fail8("--mcap qualifies --at.", opts.json);
81724
+ if (opts.stop && kind !== "sell_at") fail9("--stop only applies to a --sell order with --at.", opts.json);
81725
+ if (opts.mcap && !opts.at) fail9("--mcap qualifies --at.", opts.json);
80702
81726
  const { keypair, state, created } = await loadOrCreateTradeKey();
80703
81727
  if (created && !opts.json) {
80704
81728
  process.stderr.write(import_picocolors37.default.dim(`Generated the agent trading key ${state.address} (${tradeKeyPath()}).
@@ -80710,11 +81734,11 @@ async function tradeOrderPlace(coinArg, opts) {
80710
81734
  try {
80711
81735
  units = parseDecimalToUnits(opts.buy, USDC_DECIMALS, "Buy amount");
80712
81736
  } catch (err) {
80713
- fail8(err.message, opts.json);
81737
+ fail9(err.message, opts.json);
80714
81738
  }
80715
81739
  const floor = servedFloorUnits(ctx2);
80716
81740
  if (floor && units < floor.units) {
80717
- fail8(`Buys start at $${floor.usdc} (served by launch-config; the relay refuses below it).`, opts.json);
81741
+ fail9(`Buys start at $${floor.usdc} (served by launch-config; the relay refuses below it).`, opts.json);
80718
81742
  }
80719
81743
  amount = opts.buy;
80720
81744
  } else {
@@ -80722,24 +81746,24 @@ async function tradeOrderPlace(coinArg, opts) {
80722
81746
  const pct = amount.match(/^(\d+)%$/);
80723
81747
  if (amount === "all" || pct) {
80724
81748
  const bal = await readTokenBalance(rpcConnection(), state.address, coin.mint);
80725
- if (!bal) fail8("Could not read the coin balance from the RPC; pass an explicit amount.", opts.json);
80726
- if (bal.units <= 0n) fail8("This key holds none of that coin.", opts.json);
81749
+ if (!bal) fail9("Could not read the coin balance from the RPC; pass an explicit amount.", opts.json);
81750
+ if (bal.units <= 0n) fail9("This key holds none of that coin.", opts.json);
80727
81751
  let units = bal.units;
80728
81752
  if (pct) {
80729
81753
  const p = BigInt(pct[1]);
80730
- if (p <= 0n || p > 100n) fail8(`Percentage must be 1-100, got "${opts.sell}".`, opts.json);
81754
+ if (p <= 0n || p > 100n) fail9(`Percentage must be 1-100, got "${opts.sell}".`, opts.json);
80731
81755
  units = bal.units * p / 100n;
80732
81756
  }
80733
- if (units <= 0n) fail8("Sell amount rounds to zero.", opts.json);
81757
+ if (units <= 0n) fail9("Sell amount rounds to zero.", opts.json);
80734
81758
  amount = formatUnits2(units, bal.decimals);
80735
81759
  } else if (!/^\d+(\.\d+)?$/.test(amount)) {
80736
- fail8(`Sell amount "${opts.sell}" is not a coin amount, a percentage like 50%, or "all".`, opts.json);
81760
+ fail9(`Sell amount "${opts.sell}" is not a coin amount, a percentage like 50%, or "all".`, opts.json);
80737
81761
  }
80738
81762
  }
80739
81763
  let expiresInDays;
80740
81764
  if (opts.expiresDays !== void 0) {
80741
81765
  const n2 = Number(opts.expiresDays);
80742
- if (!Number.isInteger(n2) || n2 < 1) fail8(`--expires-days must be a positive integer, got "${opts.expiresDays}".`, opts.json);
81766
+ if (!Number.isInteger(n2) || n2 < 1) fail9(`--expires-days must be a positive integer, got "${opts.expiresDays}".`, opts.json);
80743
81767
  expiresInDays = n2;
80744
81768
  }
80745
81769
  const prepared = await prepareOrder({
@@ -80775,7 +81799,7 @@ async function tradeOrderPlace(coinArg, opts) {
80775
81799
  async function tradeOrdersList(opts) {
80776
81800
  await withContext(opts, async (ctx2) => {
80777
81801
  const key = await loadTradeKey();
80778
- if (!key) fail8("No agent trading key yet. Run: agentgates trade key", opts.json);
81802
+ if (!key) fail9("No agent trading key yet. Run: agentgates trade key", opts.json);
80779
81803
  const token = opts.coin ? (await resolveCoin(opts.coin)).mint : void 0;
80780
81804
  const res = await listOrders(key.state.address, token);
80781
81805
  if (opts.json) {
@@ -80795,15 +81819,15 @@ async function tradeOrdersList(opts) {
80795
81819
  async function tradeOrderCancel(id2, opts) {
80796
81820
  await withContext(opts, async (_ctx) => {
80797
81821
  const key = await loadTradeKey();
80798
- if (!key) fail8("No agent trading key yet. Run: agentgates trade key", opts.json);
81822
+ if (!key) fail9("No agent trading key yet. Run: agentgates trade key", opts.json);
80799
81823
  try {
80800
81824
  await cancelOrder(id2, key.state.address);
80801
81825
  } catch (err) {
80802
81826
  if (err instanceof RelayError && err.status === 409) {
80803
- fail8(`Order ${id2} already fired or ended; nothing to cancel.`, opts.json);
81827
+ fail9(`Order ${id2} already fired or ended; nothing to cancel.`, opts.json);
80804
81828
  }
80805
81829
  if (err instanceof RelayError && err.status === 404) {
80806
- fail8(`No order ${id2} for this key (already canceled, or never placed).`, opts.json);
81830
+ fail9(`No order ${id2} for this key (already canceled, or never placed).`, opts.json);
80807
81831
  }
80808
81832
  throw err;
80809
81833
  }
@@ -80818,12 +81842,12 @@ async function tradeOrderCancel(id2, opts) {
80818
81842
  async function tradePositions(opts) {
80819
81843
  await withContext(opts, async (ctx2) => {
80820
81844
  const key = await loadTradeKey();
80821
- if (!key) fail8("No agent trading key yet. Run: agentgates trade key", opts.json);
81845
+ if (!key) fail9("No agent trading key yet. Run: agentgates trade key", opts.json);
80822
81846
  let body;
80823
81847
  try {
80824
81848
  body = await relayGet(`/launch-portfolio?address=${encodeURIComponent(key.state.address)}`);
80825
81849
  } catch (err) {
80826
- if (err instanceof RelayError) fail8(`Positions read failed: ${err.message}`, opts.json);
81850
+ if (err instanceof RelayError) fail9(`Positions read failed: ${err.message}`, opts.json);
80827
81851
  throw err;
80828
81852
  }
80829
81853
  const rows = body?.tokens ?? [];
@@ -80871,7 +81895,7 @@ init_constants();
80871
81895
 
80872
81896
  // src/lib/desk-sol.ts
80873
81897
  var import_web32 = __toESM(require_index_cjs(), 1);
80874
- import { promises as fs9 } from "node:fs";
81898
+ import { promises as fs10 } from "node:fs";
80875
81899
  import * as path7 from "node:path";
80876
81900
  import * as os4 from "node:os";
80877
81901
  async function resolveDeskContext() {
@@ -80893,7 +81917,7 @@ function deskSessionKeyPath() {
80893
81917
  async function loadDeskSessionKey() {
80894
81918
  let raw;
80895
81919
  try {
80896
- raw = await fs9.readFile(deskSessionPath(), "utf8");
81920
+ raw = await fs10.readFile(deskSessionPath(), "utf8");
80897
81921
  } catch (err) {
80898
81922
  if (err.code === "ENOENT") return null;
80899
81923
  throw err;
@@ -80922,11 +81946,11 @@ async function loadOrCreateDeskSessionKey() {
80922
81946
  createdAt: (/* @__PURE__ */ new Date()).toISOString()
80923
81947
  };
80924
81948
  const dir = path7.dirname(deskSessionPath());
80925
- await fs9.mkdir(dir, { recursive: true, mode: 448 });
80926
- await fs9.chmod(dir, 448).catch(() => {
81949
+ await fs10.mkdir(dir, { recursive: true, mode: 448 });
81950
+ await fs10.chmod(dir, 448).catch(() => {
80927
81951
  });
80928
- await fs9.writeFile(deskSessionPath(), JSON.stringify(state, null, 2), { mode: 384 });
80929
- await fs9.chmod(deskSessionPath(), 384).catch(() => {
81952
+ await fs10.writeFile(deskSessionPath(), JSON.stringify(state, null, 2), { mode: 384 });
81953
+ await fs10.chmod(deskSessionPath(), 384).catch(() => {
80930
81954
  });
80931
81955
  return { state, keypair, created: true };
80932
81956
  }
@@ -81037,7 +82061,7 @@ async function runDeskTrade(args) {
81037
82061
  }
81038
82062
 
81039
82063
  // src/commands/desk.ts
81040
- function fail9(message, json2) {
82064
+ function fail10(message, json2) {
81041
82065
  if (json2) {
81042
82066
  process.stdout.write(JSON.stringify({ ok: false, error: message }) + "\n");
81043
82067
  } else {
@@ -81051,7 +82075,7 @@ async function withDesk(opts, fn) {
81051
82075
  const ctx2 = await resolveDeskContext();
81052
82076
  return await fn(ctx2);
81053
82077
  } catch (err) {
81054
- fail9(err.message, opts.json);
82078
+ fail10(err.message, opts.json);
81055
82079
  }
81056
82080
  }
81057
82081
  function servedFloorUnits2(ctx2) {
@@ -81062,7 +82086,7 @@ function servedFloorUnits2(ctx2) {
81062
82086
  async function requireOwner(opts) {
81063
82087
  const key = await loadTradeKey();
81064
82088
  if (!key) {
81065
- fail9("No agent trading key yet (the desk's owner). Run: agentgates trade key", opts.json);
82089
+ fail10("No agent trading key yet (the desk's owner). Run: agentgates trade key", opts.json);
81066
82090
  }
81067
82091
  return key;
81068
82092
  }
@@ -81131,7 +82155,7 @@ async function deskStatus(opts) {
81131
82155
  if (opts.fills !== void 0) {
81132
82156
  const n2 = Number(opts.fills);
81133
82157
  if (!Number.isInteger(n2) || n2 <= 0) {
81134
- fail9(`--fills must be a positive integer, got "${opts.fills}".`, opts.json);
82158
+ fail10(`--fills must be a positive integer, got "${opts.fills}".`, opts.json);
81135
82159
  }
81136
82160
  fillsLimit = n2;
81137
82161
  }
@@ -81179,9 +82203,9 @@ async function deskDeposit(amount, opts) {
81179
82203
  try {
81180
82204
  units = parseDecimalToUnits(amount, USDC_DECIMALS, "Deposit amount");
81181
82205
  } catch (err) {
81182
- fail9(err.message, opts.json);
82206
+ fail10(err.message, opts.json);
81183
82207
  }
81184
- if (units <= 0n) fail9("Deposit amount must be above zero.", opts.json);
82208
+ if (units <= 0n) fail10("Deposit amount must be above zero.", opts.json);
81185
82209
  const { keypair, state, created } = await loadOrCreateTradeKey();
81186
82210
  if (created && !opts.json) {
81187
82211
  process.stderr.write(import_picocolors38.default.dim(`Generated the agent trading key ${state.address} (${tradeKeyPath()}).
@@ -81225,7 +82249,7 @@ async function deskWithdraw(amount, opts) {
81225
82249
  const trimmed = amount.trim();
81226
82250
  if (trimmed !== "all") {
81227
82251
  if (!/^\d+(\.\d+)?$/.test(trimmed)) {
81228
- fail9(`Withdraw amount "${amount}" is not a decimal amount or "all".`, opts.json);
82252
+ fail10(`Withdraw amount "${amount}" is not a decimal amount or "all".`, opts.json);
81229
82253
  }
81230
82254
  }
81231
82255
  const result = await runDeskCeremony({
@@ -81264,18 +82288,18 @@ async function deskWithdraw(amount, opts) {
81264
82288
  }
81265
82289
  async function deskSessionRegister(opts) {
81266
82290
  await withDesk(opts, async (ctx2) => {
81267
- if (!opts.cap) fail9("--cap <usdc> is required: the per-trade cap is your risk statement, never defaulted.", opts.json);
81268
- if (!opts.minutes) fail9("--minutes <n> is required: the session expiry is your risk statement, never defaulted.", opts.json);
82291
+ if (!opts.cap) fail10("--cap <usdc> is required: the per-trade cap is your risk statement, never defaulted.", opts.json);
82292
+ if (!opts.minutes) fail10("--minutes <n> is required: the session expiry is your risk statement, never defaulted.", opts.json);
81269
82293
  let capUnits;
81270
82294
  try {
81271
82295
  capUnits = parseDecimalToUnits(opts.cap, USDC_DECIMALS, "Per-trade cap");
81272
82296
  } catch (err) {
81273
- fail9(err.message, opts.json);
82297
+ fail10(err.message, opts.json);
81274
82298
  }
81275
- if (capUnits <= 0n) fail9("Per-trade cap must be above zero.", opts.json);
82299
+ if (capUnits <= 0n) fail10("Per-trade cap must be above zero.", opts.json);
81276
82300
  const minutes = Number(opts.minutes);
81277
82301
  if (!Number.isInteger(minutes) || minutes <= 0) {
81278
- fail9(`--minutes must be a positive integer, got "${opts.minutes}".`, opts.json);
82302
+ fail10(`--minutes must be a positive integer, got "${opts.minutes}".`, opts.json);
81279
82303
  }
81280
82304
  const owner = await loadOrCreateTradeKey();
81281
82305
  if (owner.created && !opts.json) {
@@ -81359,7 +82383,7 @@ async function deskSessionRevoke(opts) {
81359
82383
  async function requireSessionKeypair(opts) {
81360
82384
  const session = await loadDeskSessionKey();
81361
82385
  if (!session) {
81362
- fail9(
82386
+ fail10(
81363
82387
  "No desk session key on this terminal. Register one: agentgates desk session register --cap <usdc> --minutes <n>",
81364
82388
  opts.json
81365
82389
  );
@@ -81403,12 +82427,12 @@ async function deskBuy(coinArg, amount, opts) {
81403
82427
  try {
81404
82428
  units = parseDecimalToUnits(amount, USDC_DECIMALS, "Buy amount");
81405
82429
  } catch (err) {
81406
- fail9(err.message, opts.json);
82430
+ fail10(err.message, opts.json);
81407
82431
  }
81408
- if (units <= 0n) fail9("Buy amount must be above zero.", opts.json);
82432
+ if (units <= 0n) fail10("Buy amount must be above zero.", opts.json);
81409
82433
  const floor = servedFloorUnits2(ctx2);
81410
82434
  if (floor && units < floor.units) {
81411
- fail9(`Buys start at $${floor.usdc} (served by launch-config; the relay refuses below it).`, opts.json);
82435
+ fail10(`Buys start at $${floor.usdc} (served by launch-config; the relay refuses below it).`, opts.json);
81412
82436
  }
81413
82437
  const owner = await requireOwner(opts);
81414
82438
  const session = await requireSessionKeypair(opts);
@@ -81433,16 +82457,16 @@ async function deskSell(coinArg, amount, opts) {
81433
82457
  const pct = sellAmount.match(/^(\d+)%$/);
81434
82458
  if (pct) {
81435
82459
  const state = await deskState(owner.state.address, coin.mint);
81436
- if (!state.coin) fail9("The desk holds none of that coin for this owner.", opts.json);
82460
+ if (!state.coin) fail10("The desk holds none of that coin for this owner.", opts.json);
81437
82461
  const credit = BigInt(state.coin.creditUnits);
81438
- if (credit <= 0n) fail9("The desk holds none of that coin for this owner.", opts.json);
82462
+ if (credit <= 0n) fail10("The desk holds none of that coin for this owner.", opts.json);
81439
82463
  const p = BigInt(pct[1]);
81440
- if (p <= 0n || p > 100n) fail9(`Percentage must be 1-100, got "${amount}".`, opts.json);
82464
+ if (p <= 0n || p > 100n) fail10(`Percentage must be 1-100, got "${amount}".`, opts.json);
81441
82465
  const units = credit * p / 100n;
81442
- if (units <= 0n) fail9("Sell amount rounds to zero.", opts.json);
82466
+ if (units <= 0n) fail10("Sell amount rounds to zero.", opts.json);
81443
82467
  sellAmount = formatUnits2(units, state.coin.decimals);
81444
82468
  } else if (sellAmount !== "all" && !/^\d+(\.\d+)?$/.test(sellAmount)) {
81445
- fail9(`Sell amount "${amount}" is not a coin amount, a percentage like 50%, or "all".`, opts.json);
82469
+ fail10(`Sell amount "${amount}" is not a coin amount, a percentage like 50%, or "all".`, opts.json);
81446
82470
  }
81447
82471
  const result = await runDeskTrade({
81448
82472
  ctx: ctx2,
@@ -81957,8 +82981,22 @@ var compute = program2.command("compute").description("Confidential virtual mach
81957
82981
  compute.command("plans").description("Live plans and the price ladder. Public read: no key, no account, no payment.").option("--json", "machine-readable output (the raw catalog)").action(async (opts) => {
81958
82982
  await computePlans(opts);
81959
82983
  });
81960
- compute.command("buy").description("Rent a machine (needs an x402 signature this CLI does not have yet)").action(async () => {
81961
- await computeBuy();
82984
+ compute.command("buy").description(
82985
+ "Rent a machine: asks the price (free), signs the 402 with this machine's key (USDC on an EVM network, no gas), resends that same payment until the API answers, and prints the machine. The key that pays owns it."
82986
+ ).option("--plan <id>", "a plan id (agentgates compute plans)").option("--hours <n>", "prepaid hours; the clock starts when the machine runs").option("--image <image>", "one container image, served on host port 8080").option("--port <n>", "with --image: the container port behind 8080 (default 80)").option("--compose <file>", "a docker-compose.yml that publishes a port (- reads stdin)").option("--env <KEY=VALUE>", "an env value, sealed to the machine and never stored; repeatable", (v, prev) => prev.concat(v), []).option("--name <name>", "a label for the machine").option("--network <name>", "pay on this network only; default: the cheapest one this key holds the USDC for").option("--max-usd <dollars>", "refuse to sign above this price").option("--quote", "print the price on every network and stop: nothing is signed").option("--yes", "pay without the prompt (needed when stdout is not a TTY)").option("--wait", "after paying, wait until the machine runs and print its endpoint").option("--timeout <minutes>", "with --wait: how long to wait (default 15)").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (opts) => {
82987
+ await computeBuy(opts);
82988
+ });
82989
+ compute.command("renew <id>").description("Add paid hours to a machine: same price ask, same signature, same resend. Any wallet may pay; the owner stays the owner.").option("--hours <n>", "hours to add to the end of its clock").option("--network <name>", "pay on this network only").option("--max-usd <dollars>", "refuse to sign above this price").option("--quote", "print the price and stop: nothing is signed").option("--yes", "pay without the prompt (needed when stdout is not a TTY)").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (id2, opts) => {
82990
+ await computeRenew(id2, opts);
82991
+ });
82992
+ compute.command("list").description("The machines this machine's key paid for (an owner read it signs).").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (opts) => {
82993
+ await computeList(opts);
82994
+ });
82995
+ compute.command("status <id>").description("One machine: status, endpoint, paid time, payments, live attestation (an owner read).").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (id2, opts) => {
82996
+ await computeStatus(id2, opts);
82997
+ });
82998
+ compute.command("wait <id>").description("Wait until a machine runs, then print its endpoint. The clock starts when it runs.").option("--timeout <minutes>", "how long to wait (default 15)").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (id2, opts) => {
82999
+ await computeWait(id2, opts);
81962
83000
  });
81963
83001
  var inference = program2.command("inference").description("Attested confidential models, plus an open tier, USDC per request");
81964
83002
  inference.command("models").description("Live models and per-token prices. Public read: no key, no account, no payment.").option("--all", "every model, not just the attested tier").option("--tier <tier>", "confidential | open").option("--tag <tag>", "filter by tag, repeatable (the board carries: reasoning, multimodal, frontier)", (v, prev) => prev.concat(v), []).option("--org <org>", "filter by maker org (openai, anthropic, qwen, ...)").option("--search <text>", "match against model id and name").option("--json", "machine-readable output (the catalog, filters applied)").action(async (opts) => {
@@ -81974,8 +83012,8 @@ inference.command("key").description("Mint a key that buys turns without the wor
81974
83012
  }
81975
83013
  await inferenceKeyCreate(opts);
81976
83014
  });
81977
- inference.command("topup").argument("<usd>", "dollars to add to the account balance", (v) => Number(v)).description("Buy prepaid balance with one x402 payment from this machine's key. A streamed turn can only be served from a balance.").option("--json", "machine-readable output").action(async (usd7, opts) => {
81978
- await inferenceTopUp(usd7, opts);
83015
+ inference.command("topup").argument("<usd>", "dollars to add to the account balance", (v) => Number(v)).description("Buy prepaid balance with one x402 payment from this machine's key. A streamed turn can only be served from a balance.").option("--json", "machine-readable output").action(async (usd6, opts) => {
83016
+ await inferenceTopUp(usd6, opts);
81979
83017
  });
81980
83018
  inference.command("ask").argument("[words...]", "what to ask, in words").description("One paid ask, signed by this machine's key: the prepaid balance if it covers it, else one x402 payment.").option("--model <id>", "a catalog id (agentgates inference models)").option("--max-tokens <n>", "output ceiling", (v) => parseInt(v, 10)).option("--json", "machine-readable output").action(async (words7, opts) => {
81981
83019
  await inferenceAsk(words7, opts);
@@ -82026,23 +83064,26 @@ passwords.command("init").description(
82026
83064
  ).option("--seed <twelve words>", "bring the phrase (quote it)").option("--reveal-seed", "print this key's words again").option("--import <hex>", "bring a bare 32-byte secp256k1 private key (64 hex chars) instead of words").option("--replace", "with --seed or --import: overwrite what is already here (the old key is the only thing that opens the rows it sealed)").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (opts) => {
82027
83065
  await passwordsInit(opts);
82028
83066
  });
82029
- passwords.command("add").alias("store").description("Store a login: sealed on this machine to this key's own signature and to the CVM's published key, then posted. The server holds ciphertext it cannot open. Free at every tier.").requiredOption("--label <name>", "what to call it (48 chars)").option("--host <hostname>", "a site it may be used on, repeatable (1 to 8; app.example.com, no wildcards)", (v, prev) => [...prev, v], []).option("--hosts <a,b>", "the same, comma separated").option("--username <u>", "login rows: the username; mailbox rows: the address the codes arrive at").option("--password <p>", "the password (visible to ps for the length of the call; --password-stdin avoids that)").option("--password-stdin", "read the password from stdin instead").option("--kind <kind>", "login | api_key | totp | raw | mailbox (default login); mailbox = your own mailbox, read by the box for the codes sites email (--username the address, --password the app password, --host the mail server; Gmail's is known). An address leased here (agentgates passwords inbox lease) needs no app password: --password -").option("--totp-seed <base32>", "the authenticator seed (login rows may carry one beside the password; totp rows need it)").option("--api-key <value>", "api_key rows").option("--raw <value>", "raw rows").option("--notes <text>", "owner-only, sealed").option("--backup-codes <codes|@file>", "login rows: the account's own backup codes, comma separated or one per line in a file; the CVM spends one when the site asks for a code and a permit lists codes").option("--device-json <json|@file>", "login rows: a device credential your own browser holds for the account (rpId, credentialId, privateKey, userHandle, signCount); agentgates passwords device provisions one through the CVM instead").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (opts) => {
83067
+ passwords.command("add").alias("store").description("Store a login: sealed on this machine to this key's own signature and to the CVM's published key, then posted. The server holds ciphertext it cannot open. Free at every tier.").requiredOption("--label <name>", "what to call it (48 chars)").option("--host <hostname>", "a site it may be used on, repeatable (1 to 8; app.example.com, no wildcards)", (v, prev) => [...prev, v], []).option("--hosts <a,b>", "the same, comma separated").option("--username <u>", "login rows: the username; mailbox rows: the address the codes arrive at").option("--password <p>", "the password (visible to ps for the length of the call; --password-stdin avoids that)").option("--password-stdin", "read the password from stdin instead").option("--kind <kind>", "login | api_key | totp | raw | mailbox (default login); mailbox = your own mailbox, read by the box for the codes sites email (--username the address, --password the app password, --host the mail server; Gmail's is known). An address leased here (agentgates passwords inbox lease) needs no app password: --password -").option("--totp-seed <base32>", "the authenticator seed (login rows may carry one beside the password; totp rows need it)").option("--api-key <value>", "api_key rows").option("--raw <value>", "raw rows").option("--notes <text>", "owner-only, sealed").option("--backup-codes <codes|@file>", "login rows: the account's own backup codes, comma separated or one per line in a file; the CVM spends one when the site asks for a code and a permit lists codes").option("--device-json <json|@file>", "login rows: a device credential your own browser holds for the account (rpId, credentialId, privateKey, userHandle, signCount); agentgates passwords device provisions one through the CVM instead").option("--through <row>", "a site that signs in through another site's account (Resend through GitHub): the new login holds no password of its own; its uses name that login row (passwords use --as-row) and the CVM types it on that row's own sites").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (opts) => {
82030
83068
  await passwordsAdd(opts);
82031
83069
  });
82032
83070
  passwords.command("allow").description("Sign a permit: which agent may use which rows on which sites, how many times a day, until when. Default: yourself, every row, every use, 30 days.").option("--agent <address>", "the key that will sign uses (default: this key)").option("--rows <id,id|*>", "row ids, or * for every row this key holds (default *)").option("--hosts <a,b>", "narrow to these hostnames (default: the rows' own)").option("--uses <login,totp,header>", "which uses (default all three)").option("--gets <session|password>", "what the agent gets: session = the site's cookies after the CVM logs in (default); password = the secret itself; cvm = the acting uses alone, for an agent that works inside the CVM over the API").option("--per-day <n>", "hard daily cap; 0 = the plan allowance (default 0)").option("--days <n>", "how long, 1 to 366 (default 30)").option("--ask-me", "every use waits for the owner's signature on their board (the brake)").option("--factors <device,codes,mail,sms>", "the account's sign-in verification step the agent may complete: device = the stored device credential answers the site's device step; codes = one of the stored backup codes is spent; mail = a code the site emails is read from your mailbox row or an inbox this key holds (allow the mailbox row too); sms = a code the site texts is read from a number this key holds").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (opts) => {
82033
83071
  await passwordsAllow(opts);
82034
83072
  });
82035
- passwords.command("use").description("Log in through the CVM with a stored login and get the page's digest back, never the password. Pass --row, or just --url and the matching row is picked, or --workflow to run a task the owner taught the CVM. A parked use (the owner has to approve, or type a code) is waited on until it answers.").option("--row <id>", "the row to use (default: the one whose hosts cover --url)").option("--url <https://site/login>", "the page the use targets").option("--use <login|header|totp|session|reveal>", "which use (default login); session hands this key the site's cookies, reveal the secret, when the permit says so").option("--cookies-out <file>", "session only: write the cookies to this file (Playwright addCookies / Puppeteer setCookie shape)").option("--steps-json <json>", "login only: steps the CVM runs inside the session after the login lands (goto, fill, click, wait, read, press; a click may name the control's text instead of a selector)").option("--workflow <name>", "login only: run a workflow the owner taught the CVM on the row, by its name (passwords list shows them); --url may be left out").option("--input <name=value>", "a value the workflow takes, by its name; repeat for each (a value you leave out types what the owner typed)", (v, prev = []) => [...prev, v]).option("--code-steps-json <json>", "login only: the clicks that reach a code field the site keeps behind a 'try another way' menu (at most 4, click and wait), run before the code is typed").option("--enroll-device", "login only, your own key: provision a device credential for the account on this sign-in (the steps reach the page where the account adds a device); agentgates passwords device does this and seals it into the row").option("--attend", "login only, your own key: the CVM fills the password and holds the page for you at the controls (finish it on your board's live view); prints the use id and the view token").option("--use-id <id>", "continue a parked use by its id (Done on an attended sign-in, or a use the owner answered)").option("--mailbox <row>", "login and session: the mailbox row the box reads an emailed sign-in code from (default: your one mailbox row, when the permit covers it and lists mail)").option("--solve", "login and session, your own key: the CVM passes a bot check it meets (Cloudflare, Turnstile, reCAPTCHA, hCaptcha) by ticking it, then through its solver service").option("--request-json <json>", "the whole request object for header and totp uses (spec \xA75.1)").option("--wait <seconds>", "cap on how long to wait for the owner's answer (default: the owner's window)").option("--no-wait", "answer the parked use's id and return at once").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (opts, command) => {
83073
+ passwords.command("use").description("Log in through the CVM with a stored login and get the page's digest back, never the password. Pass --row, or just --url and the matching row is picked, or --workflow to run a task the owner taught the CVM. A parked use (the owner has to approve, or type a code) is waited on until it answers.").option("--row <id>", "the row to use (default: the one whose hosts cover --url)").option("--url <https://site/login>", "the page the use targets").option("--use <login|header|totp|session|reveal>", "which use (default login); session hands this key the site's cookies, reveal the secret, when the permit says so").option("--cookies-out <file>", "session only: write the cookies to this file (Playwright addCookies / Puppeteer setCookie shape)").option("--steps-json <json>", "login only: steps the CVM runs inside the session after the login lands (goto, fill, click, wait, read, press; a click may name the control's text instead of a selector; key reads the key a site shows once, {kind: key, label|selector, prefix?}, and keeps it in the row for {apiKey})").option("--workflow <name>", "login only: run a workflow the owner taught the CVM on the row, by its name (passwords list shows them); --url may be left out").option("--input <name=value>", "a value the workflow takes, by its name; repeat for each (a value you leave out types what the owner typed)", (v, prev = []) => [...prev, v]).option("--code-steps-json <json>", "login only: the clicks that reach a code field the site keeps behind a 'try another way' menu (at most 4, click and wait), run before the code is typed").option("--enroll-device", "login only, your own key: provision a device credential for the account on this sign-in (the steps reach the page where the account adds a device); agentgates passwords device does this and seals it into the row").option("--attend", "login only, your own key: the CVM fills the password and holds the page for you at the controls (finish it on your board's live view); prints the use id and the view token").option("--use-id <id>", "continue a parked use by its id (Done on an attended sign-in, or a use the owner answered)").option("--mailbox <row>", "login and session: the mailbox row the box reads an emailed sign-in code from (default: your one mailbox row, when the permit covers it and lists mail)").option("--as-row <row>", "login only: sign in through another site's account (Resend through GitHub): the login row whose username and password the CVM types, on that row's own sites only; the password never leaves the CVM").option("--solve", "login and session, your own key: the CVM passes a bot check it meets (Cloudflare, Turnstile, reCAPTCHA, hCaptcha) by ticking it, then through its solver service").option("--request-json <json>", "the whole request object for header and totp uses (spec \xA75.1); a header request's seal {json: <field>} seals that field of the JSON answer to the owner (a webhook's signing secret)").option("--wait <seconds>", "cap on how long to wait for the owner's answer (default: the owner's window)").option("--no-wait", "answer the parked use's id and return at once").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (opts, command) => {
82036
83074
  const waitSource = command.getOptionValueSource("wait");
82037
83075
  await passwordsUse({ ...opts, noWait: waitSource === "cli" && opts.wait === false, wait: typeof opts.wait === "string" ? opts.wait : void 0 });
82038
83076
  });
82039
83077
  passwords.command("checks [word]").description("Bot checks (Cloudflare, Turnstile, reCAPTCHA, hCaptcha): ask = an agent's use that meets one waits for your answer on the board (default); solve = the CVM passes every one it can without asking. No word prints the current one.").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (word, opts) => {
82040
83078
  await passwordsChecks(word, opts);
82041
83079
  });
83080
+ passwords.command("open-sealed").description("Open a field the CVM sealed to you in a header use's answer (a webhook's signing secret): only the account owner's key opens it, the same key that opens the account's sealed mail.").option("--row <id>", "the row the header use ran on").option("--field <name>", "the sealed field's name (signing_secret)").option("--blob <value|@file>", "the field's {sealed} value from the answer").option("--out <file>", "write the value to this file (read by you alone) and print its length, not the value").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (opts) => {
83081
+ await passwordsOpenSealed(opts);
83082
+ });
82042
83083
  passwords.command("code").description("Fetch a verification code one of the account's own contacts received, for an account the owner is registering or signing into elsewhere: the newest message from a site in your mailbox row (an app password, or a Gmail login you connected on your board; the permit lists mail), or the newest code that reached an inbox or a number this key holds, read through its own door (a sealed inbox is opened with your own key). One source: --mailbox, --inbox or --phone.").option("--from <domain>", "the site the code comes from, e.g. etsy.com (a mailbox row reads that sender)").option("--mailbox <row>", "the mailbox row (default: your one mailbox row, or your one Gmail login)").option("--inbox <id>", "an inbox this key holds (agentgates passwords inbox list): the newest code that reached it").option("--phone <id>", "a number this key holds (agentgates phone list): the newest code texted to it").option("--timeout <seconds>", "--inbox and --phone: how long the door waits for a code (default 60)").option("--since <minutes>", "how far back to look (default 10)").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (opts) => {
82043
83084
  await passwordsCode(opts);
82044
83085
  });
82045
- passwords.command("signup").description("Register the account owner on a site through the CVM, under a permit the owner signed: the CVM completes the site's own sign-up form with the owner's chosen identity and a password generated here, the site's verification code is read from a contact the account already holds, and the new login is saved as a row under this key. The source is one of your mailbox row (the CVM reads it), an inbox this key holds (--inbox: the code is read through the inbox's own door; a sealed inbox is opened with your own key) or a number this key holds (--phone: the code is read through the number's own door). The permit lists signup, and mail or sms for the source. Priced as a login; the code read is the wait-code door's own draw, reported in the answer.").requiredOption("--url <url>", "the https address of the site's sign-up page (or its sign-in page with a Sign up link)").option("--email <address>", "the address to sign up with: the source's own by default, or a plus alias of it (you+shop@gmail.com); none with --phone").option("--name <name>", "the name the form asks for").option("--username <name>", "the username when the form asks for one (the CVM derives one otherwise)").option("--password <password>", "the password to use (generated here when absent)").option("--mailbox <row>", "the mailbox row (default: your one mailbox row, or your one Gmail login)").option("--inbox <id>", "an inbox this key holds (agentgates passwords inbox list): the account is made with its address").option("--phone <id>", "a number this key holds (agentgates phone list): the account is made on the number, the code comes by text").option("--label <label>", "the stored row's label (default: the site)").option("--no-store", "do not store the new login as a row; the password prints once instead").option("--steps-json <json>", "steps to run at the site once the account exists (the login use's steps shape)").option("--drive", "let the CVM's own model update a step of the site book's recipe that no longer matches the form; a step only you can complete in person stops the run and names it").option("--birthday <yyyy-mm-dd>", "the date of birth a sign-up form asks for; typed, never kept").option("--attend", "your own key: a step only you can complete in person (a verification the site shows) holds the page for you at the controls; finish it on your board's live view, or continue here with --use-id").option("--use-id <id>", "continue a sign-up the CVM is holding for you (Done): the steps after the one you completed run on").option("--wait <seconds>", "how long to wait on a parked use or a starting CVM (default: the use's own window)").option("--no-wait", "print the first answer and leave").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (opts) => {
83086
+ passwords.command("signup").description("Register the account owner on a site through the CVM, under a permit the owner signed: the CVM completes the site's own sign-up form with the owner's chosen identity and a password generated here, the site's verification code is read from a contact the account already holds, and the new login is saved as a row under this key. The source is one of your mailbox row (the CVM reads it), an inbox this key holds (--inbox: the code is read through the inbox's own door; a sealed inbox is opened with your own key) or a number this key holds (--phone: the code is read through the number's own door). The permit lists signup, and mail or sms for the source. Priced as a login; the code read is the wait-code door's own draw, reported in the answer.").requiredOption("--url <url>", "the https address of the site's sign-up page (or its sign-in page with a Sign up link)").option("--email <address>", "the address to sign up with: the source's own by default, or a plus alias of it (you+shop@gmail.com); none with --phone").option("--name <name>", "the name the form asks for").option("--username <name>", "the username when the form asks for one (the CVM derives one otherwise)").option("--password <password>", "the password to use (generated here when absent)").option("--mailbox <row>", "the mailbox row (default: your one mailbox row, or your one Gmail login)").option("--inbox <id>", "an inbox this key holds (agentgates passwords inbox list): the account is made with its address").option("--phone <id>", "a number this key holds (agentgates phone list): the account is made on the number, the code comes by text").option("--label <label>", "the stored row's label (default: the site)").option("--no-store", "do not store the new login as a row; the password prints once instead").option("--steps-json <json>", "steps to run at the site once the account exists (the login use's steps shape)").option("--drive", "let the CVM's own model update a step of the site book's recipe that no longer matches the form; a step only you can complete in person stops the run and names it").option("--birthday <yyyy-mm-dd>", "the date of birth a sign-up form asks for; typed, never kept").option("--attend", "the default: a step only a person completes (a puzzle, a verification the site shows) holds the page for the account owner at the controls of their board's live view. Your own key: finish it there, or continue here with --use-id. An agent's key: this run waits for the owner's Done, then goes on").option("--no-attend", "a step only a person completes ends the run with the step named, and nothing is held").option("--use-id <id>", "continue a sign-up the CVM is holding for you (Done): the steps after the one you completed run on").option("--as-row <row>", "sign up THROUGH another site's account (Vercel's Continue with GitHub): the login row whose account the run signs in as; its username and password are opened here under your key, sent with the request, never printed and never stored again").option("--auto-owner", "your own key plays the owner at the walls it can answer and continues the run: a page that has not drawn gets a moment, and a phone check is answered with --sms-id and --sms-number; any other wall stays held for you").option("--sms-id <phoneId>", "with --auto-owner: the number this key may read a text from (the house's pool number is listed in poolSmsReaders); the phone check's code is read there").option("--sms-number <+15551234567>", "with --auto-owner: the phone number typed into the phone check (the number behind --sms-id)").option("--wait <seconds>", "how long to wait on a parked use or a starting CVM (default: the use's own window)").option("--no-wait", "print the first answer and leave").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (opts) => {
82046
83087
  await passwordsSignup(opts);
82047
83088
  });
82048
83089
  passwords.command("device").description("Provision a device credential for an account through the CVM: the CVM logs in with your stored login, the steps reach the page where the account adds a device, the site's own ceremony creates the credential inside the CVM, and it is sealed into the row (both copies). From then on a permit that lists device lets the CVM complete the account's device step with it. Your own key only.").requiredOption("--row <id>", "the login to provision it on (agentgates passwords list)").requiredOption("--url <https://site/login>", "the account's sign-in page").option("--page <https://site/security>", "the page where the account adds a device (a passkey)").option("--click <text>", "the text on that page's add-a-device button").option("--steps-json <json>", "instead of --page and --click: the steps that reach and press it").option("--wait <seconds>", "cap on how long to wait for a parked sign-in (a code the site sent you)").option("--no-wait", "answer the parked use's id and return at once").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (opts, command) => {
@@ -82223,6 +83264,12 @@ sites.command("undo <changeId>").description("Take back the site's latest live c
82223
83264
  sites.command("fix <changeId>").description("A change Agentgates' live check stopped: the agent builds a new change whose ask is what failed.").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (changeId, opts) => {
82224
83265
  await sitesFix(changeId, opts);
82225
83266
  });
83267
+ sites.command("changes <siteId>").description("One site's changes, newest first: what each did (its card) or what was asked, where it stands.").option("--before <changeId>", "the page before's last change id (the older page)").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (siteId, opts) => {
83268
+ await sitesChanges(siteId, opts);
83269
+ });
83270
+ sites.command("remove <siteId>").description("Take a site off Agentgates. Its GitHub repo, Vercel project and connections stay yours.").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (siteId, opts) => {
83271
+ await sitesRemove(siteId, opts);
83272
+ });
82226
83273
  var memory = program2.command("memory").description("Sealed folders of markdown your agents read: names and bodies are sealed on this machine to the account's data key; the wire and the server carry ciphertext only.");
82227
83274
  memory.command("overview", { isDefault: true }).description("The folders, their counts, and what the plan allows.").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (opts) => {
82228
83275
  await memoryOverview(opts);
@@ -82294,8 +83341,8 @@ agent.command("on").description("Turn your agent on: a wallet minted here, its k
82294
83341
  agent.command("off").description("Turn your agent off: the CVM's copies go, its Memory key is revoked. Its thread stays in Memory.").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (opts) => {
82295
83342
  await agentOff(opts);
82296
83343
  });
82297
- agent.command("fund <usd>").description("Retired: your agent pays from your balance, so there is nothing to fund. Says so and moves nothing.").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (usd7, opts) => {
82298
- await agentFund(usd7, opts);
83344
+ agent.command("fund <usd>").description("Retired: your agent pays from your balance, so there is nothing to fund. Says so and moves nothing.").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (usd6, opts) => {
83345
+ await agentFund(usd6, opts);
82299
83346
  });
82300
83347
  agent.command("refill [off]").description("Retired: your agent pays from your balance, so there is no refill rule. Says so and moves nothing.").option("--below <usd>", "retired").option("--add <usd>", "retired").option("--cap <usd>", "retired").option("--days <n>", "retired").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (action, opts) => {
82301
83348
  await agentRefill(action, opts);