@keyboxed/cli 0.2.6 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/keybox.js CHANGED
@@ -50,6 +50,9 @@ function configDir() {
50
50
  }
51
51
  function loadConfig() {
52
52
  const env2 = process.env;
53
+ if (env2.KEYBOX_URL && env2.KEYBOX_DEVICE_ID && env2.KEYBOX_DEVICE_KEY) {
54
+ return { url: env2.KEYBOX_URL, deviceId: env2.KEYBOX_DEVICE_ID, deviceKey: env2.KEYBOX_DEVICE_KEY, name: env2.KEYBOX_NAME ?? "keybox", d1Id: "" };
55
+ }
53
56
  if (env2.KEYBOX_URL && env2.KEYBOX_ADMIN_TOKEN) {
54
57
  return {
55
58
  url: env2.KEYBOX_URL,
@@ -83,14 +86,48 @@ var init_config = __esm({
83
86
  }
84
87
  });
85
88
 
89
+ // src/device.ts
90
+ import { createHash, createPrivateKey, createPublicKey, generateKeyPairSync, randomBytes, sign } from "node:crypto";
91
+ import { hostname } from "node:os";
92
+ function newDeviceKey() {
93
+ const { privateKey, publicKey } = generateKeyPairSync("ed25519");
94
+ return {
95
+ privateKey: privateKey.export({ format: "der", type: "pkcs8" }).toString("base64url"),
96
+ publicKey: publicKey.export({ format: "jwk" }).x
97
+ };
98
+ }
99
+ function deviceName() {
100
+ return hostname().replace(/\.local$/, "").slice(0, 48) || "device";
101
+ }
102
+ function signRequest(device, method, fullUrl, body, now = Date.now()) {
103
+ const u = new URL(fullUrl);
104
+ const ts = String(now);
105
+ const nonce = randomBytes(16).toString("base64url");
106
+ const text = ["KEYBOX-SIG-1", method.toUpperCase(), u.host, u.pathname + u.search, ts, nonce, createHash("sha256").update(body).digest("hex")].join("\n");
107
+ const key = createPrivateKey({ key: Buffer.from(device.privateKey, "base64url"), format: "der", type: "pkcs8" });
108
+ const sig = sign(null, Buffer.from(text), key).toString("base64url");
109
+ return `Keybox-Sig id=${device.id}, ts=${ts}, nonce=${nonce}, sig=${sig}`;
110
+ }
111
+ var init_device = __esm({
112
+ "src/device.ts"() {
113
+ "use strict";
114
+ }
115
+ });
116
+
86
117
  // src/api.ts
87
118
  async function api(method, path, body, config = requireConfig()) {
88
119
  let res;
120
+ const url = `${config.url.replace(/\/$/, "")}/_keybox/admin${path}`;
121
+ const text = body === void 0 ? "" : JSON.stringify(body);
122
+ let authorization;
123
+ if (config.deviceId && config.deviceKey) authorization = signRequest({ id: config.deviceId, privateKey: config.deviceKey }, method, url, text);
124
+ else if (config.adminToken) authorization = `Bearer ${config.adminToken}`;
125
+ else throw new UserError("No credentials for this Keybox. Run `keybox login`.");
89
126
  try {
90
- res = await fetch(`${config.url.replace(/\/$/, "")}/_keybox/admin${path}`, {
127
+ res = await fetch(url, {
91
128
  method,
92
- headers: { authorization: `Bearer ${config.adminToken}`, "content-type": "application/json" },
93
- body: body === void 0 ? void 0 : JSON.stringify(body)
129
+ headers: { authorization, "content-type": "application/json" },
130
+ body: body === void 0 ? void 0 : text
94
131
  });
95
132
  } catch {
96
133
  throw new UserError(`Could not reach ${config.url}.`);
@@ -103,6 +140,7 @@ var init_api = __esm({
103
140
  "src/api.ts"() {
104
141
  "use strict";
105
142
  init_config();
143
+ init_device();
106
144
  }
107
145
  });
108
146
 
@@ -1894,7 +1932,7 @@ var VERSION;
1894
1932
  var init_version = __esm({
1895
1933
  "src/version.ts"() {
1896
1934
  "use strict";
1897
- VERSION = true ? "0.2.6" : "0.0.0-dev";
1935
+ VERSION = true ? "0.3.0" : "0.0.0-dev";
1898
1936
  }
1899
1937
  });
1900
1938
 
@@ -1909,7 +1947,7 @@ __export(verify_exports, {
1909
1947
  shippedWorkerVersion: () => shippedWorkerVersion,
1910
1948
  verify: () => verify
1911
1949
  });
1912
- import { createHash } from "node:crypto";
1950
+ import { createHash as createHash2 } from "node:crypto";
1913
1951
  import { readFileSync as readFileSync4 } from "node:fs";
1914
1952
  async function liveHealth(url, want, seconds = 30) {
1915
1953
  let last = null;
@@ -2055,7 +2093,7 @@ var init_verify = __esm({
2055
2093
  init_version();
2056
2094
  init_wrangler();
2057
2095
  EXPECTED_BINDINGS = /* @__PURE__ */ new Set(["DB", "KEYBOX_KEK", "KEYBOX_ADMIN_TOKEN_HASH", "KEYBOX_SCRIPT_NAME", "KEYBOX_D1_ID"]);
2058
- shaHex = (b) => createHash("sha256").update(b).digest("hex");
2096
+ shaHex = (b) => createHash2("sha256").update(b).digest("hex");
2059
2097
  shippedWorkerHash = () => shaHex(readFileSync4(new URL("../assets/worker.js", import.meta.url)));
2060
2098
  shippedWorkerVersion = () => /VERSION = "([^"]+)"/.exec(readFileSync4(new URL("../assets/worker.js", import.meta.url), "utf8"))?.[1] ?? VERSION;
2061
2099
  }
@@ -2069,7 +2107,7 @@ __export(deploy_exports, {
2069
2107
  status: () => status
2070
2108
  });
2071
2109
  import { spawn as spawn4 } from "node:child_process";
2072
- import { createHash as createHash2, randomBytes } from "node:crypto";
2110
+ import { createHash as createHash3, randomBytes as randomBytes2 } from "node:crypto";
2073
2111
  import { copyFileSync, existsSync as existsSync3, mkdirSync as mkdirSync2, readFileSync as readFileSync5, writeFileSync as writeFileSync2 } from "node:fs";
2074
2112
  import { join as join4 } from "node:path";
2075
2113
  async function deployWorker(cfg) {
@@ -2206,16 +2244,16 @@ async function init(opts) {
2206
2244
  async () => {
2207
2245
  const secrets = parseJson(await wrangler(["secret", "list", "--config", cfgPath, "--format", "json"], { capture: true, quiet: true }));
2208
2246
  if (secrets.some((s) => s.name === "KEYBOX_KEK")) return "kept the existing one";
2209
- await wrangler(["secret", "put", "KEYBOX_KEK", "--config", cfgPath], { input: randomBytes(32).toString("base64"), capture: true, quiet: true });
2247
+ await wrangler(["secret", "put", "KEYBOX_KEK", "--config", cfgPath], { input: randomBytes2(32).toString("base64"), capture: true, quiet: true });
2210
2248
  return "generated and sent to Cloudflare; never written to disk";
2211
2249
  },
2212
2250
  (r) => r
2213
2251
  );
2214
- const adminToken = "kb_adm_" + randomBytes(32).toString("base64url");
2252
+ const adminToken = "kb_adm_" + randomBytes2(32).toString("base64url");
2215
2253
  await task(
2216
2254
  "Admin token",
2217
2255
  async () => {
2218
- const hash = createHash2("sha256").update(adminToken).digest("hex");
2256
+ const hash = createHash3("sha256").update(adminToken).digest("hex");
2219
2257
  await wrangler(["secret", "put", "KEYBOX_ADMIN_TOKEN_HASH", "--config", cfgPath], { input: hash, capture: true, quiet: true });
2220
2258
  saveConfig({ url, adminToken, name, d1Id, accountId: account.id });
2221
2259
  },
@@ -2319,7 +2357,7 @@ var init_deploy = __esm({
2319
2357
  init_wrangler();
2320
2358
  COMPAT_DATE = "2026-07-01";
2321
2359
  asset = (f) => new URL(`../assets/${f}`, import.meta.url).pathname;
2322
- sha = (path) => createHash2("sha256").update(readFileSync5(path)).digest("hex");
2360
+ sha = (path) => createHash3("sha256").update(readFileSync5(path)).digest("hex");
2323
2361
  LATER = [
2324
2362
  ["keybox migrate", "bring keys in from .env, 1Password, Doppler, Vault\u2026"],
2325
2363
  ["keybox secrets add NAME", "add one key (hidden input)"],
@@ -4147,19 +4185,30 @@ __export(extra_exports, {
4147
4185
  accessCloudflare: () => accessCloudflare,
4148
4186
  accessSet: () => accessSet,
4149
4187
  accessShow: () => accessShow,
4188
+ claim: () => claim,
4189
+ devicesAdd: () => devicesAdd,
4190
+ devicesApprove: () => devicesApprove,
4191
+ devicesList: () => devicesList,
4192
+ devicesRevoke: () => devicesRevoke,
4150
4193
  login: () => login,
4194
+ membersAdd: () => membersAdd,
4195
+ membersList: () => membersList,
4196
+ membersLog: () => membersLog,
4197
+ membersRm: () => membersRm,
4151
4198
  pair: () => pair,
4152
4199
  qrBlocks: () => qrBlocks,
4153
4200
  skill: () => skill,
4201
+ tokenOff: () => tokenOff,
4154
4202
  ui: () => ui
4155
4203
  });
4156
4204
  import { spawn as spawn5 } from "node:child_process";
4157
4205
  import { existsSync as existsSync4, mkdirSync as mkdirSync3, readFileSync as readFileSync6, writeFileSync as writeFileSync3 } from "node:fs";
4158
4206
  import { homedir as homedir3 } from "node:os";
4159
4207
  import { dirname as dirname2, join as join5 } from "node:path";
4160
- async function login(urlArg) {
4161
- const url = (urlArg ?? await ask("Keybox address (https://\u2026)")).trim().replace(/\/+$/, "");
4162
- if (!/^https:\/\/[^/\s]+$/.test(url)) throw new UserError("Give the https:// address of your Keybox, for example https://yourteam.keybox.space.");
4208
+ async function login(urlArg, opts = {}) {
4209
+ const url = checkUrl(urlArg ?? await ask("Keybox address (https://\u2026)"));
4210
+ const code = (opts.code ?? process.env.KEYBOX_JOIN_CODE ?? "").trim();
4211
+ if (code) return joinWithCode(url, code);
4163
4212
  const token2 = (process.env.KEYBOX_ADMIN_TOKEN ?? await readSecret("Admin token")).trim();
4164
4213
  if (!token2.startsWith("kb_adm_")) throw new UserError("That does not look like an admin token (they start with kb_adm_).");
4165
4214
  let res;
@@ -4172,8 +4221,99 @@ async function login(urlArg) {
4172
4221
  if (!res.ok) throw new UserError(`${url} answered HTTP ${res.status}. Is that a Keybox?`);
4173
4222
  saveConfig({ url, adminToken: token2, name: "", d1Id: "" });
4174
4223
  ok(`Connected to ${url}. The token is saved in ~/.config/keybox (mode 600).`);
4224
+ note("Next: `keybox claim` gives this machine its own key, so the shared token can be turned off.");
4225
+ }
4226
+ async function joinWithCode(url, code) {
4227
+ const kind = /^kb_(pair|inv|clm)_[A-Za-z0-9_-]{20,}$/.exec(code)?.[1];
4228
+ if (!kind) throw new UserError("That does not look like a join code (they start with kb_pair_, kb_inv_ or kb_clm_).");
4229
+ const memberName = kind === "clm" && process.stdin.isTTY ? await ask("Your name", "owner") : void 0;
4230
+ const key = newDeviceKey();
4231
+ let res;
4232
+ try {
4233
+ res = await fetch(`${url}/_keybox/join`, {
4234
+ method: "POST",
4235
+ headers: { "content-type": "application/json" },
4236
+ body: JSON.stringify({ code, pubkey: key.publicKey, device_name: deviceName(), member_name: memberName })
4237
+ });
4238
+ } catch {
4239
+ throw new UserError(`Could not reach ${url}.`);
4240
+ }
4241
+ const data = await res.json().catch(() => null);
4242
+ if (!res.ok || !data?.device) throw new UserError(data?.error?.message ?? `${url} answered HTTP ${res.status}. Is that a Keybox?`);
4243
+ saveConfig({ url, deviceId: data.device, deviceKey: key.privateKey, name: "", d1Id: "" });
4244
+ if (data.pending) {
4245
+ ok(`Joined ${url} as ${c.bold(deviceName())}. This machine's key never left it.`);
4246
+ warn(`Waiting for approval. Ask an owner or admin to run: keybox devices approve ${data.device}`);
4247
+ note("Until then every command here will say the machine is waiting.");
4248
+ return;
4249
+ }
4250
+ ok(`Connected to ${url} as ${c.bold(deviceName())}. This machine's key never left it.`);
4175
4251
  note("Try `keybox ui` for the dashboard, or `keybox secrets add NAME`.");
4176
4252
  }
4253
+ async function claim() {
4254
+ const cfg = requireConfig();
4255
+ if (cfg.deviceId) throw new UserError("This machine already has a device key. See `keybox devices`.");
4256
+ if (!cfg.adminToken) throw new UserError("Claiming starts from the admin token. Run `keybox login` first.");
4257
+ const key = newDeviceKey();
4258
+ const name = deviceName();
4259
+ const r = await api("POST", "/claim", { pubkey: key.publicKey, device_name: name });
4260
+ const keepToken = process.env.KEYBOX_ADMIN_TOKEN ? void 0 : cfg.adminToken;
4261
+ saveConfig({ ...cfg, adminToken: keepToken, deviceId: r.device, deviceKey: key.privateKey });
4262
+ ok(`This machine (${c.bold(name)}) is now the owner of ${cfg.url}. Requests are signed with a key that never leaves it.`);
4263
+ note("The shared admin token still works. When you are ready, `keybox token off` turns it off for good.");
4264
+ note("Add a second machine with `keybox devices add`, so losing this one does not lock you out.");
4265
+ }
4266
+ async function devicesList() {
4267
+ const r = await api("GET", "/devices");
4268
+ if (!r.devices.length) {
4269
+ note("No devices yet. `keybox claim` enrols this machine as the owner.");
4270
+ } else {
4271
+ process.stdout.write(
4272
+ headed([
4273
+ ["ID", "MACHINE", "PERSON", "ROLE", "LAST SEEN", ""],
4274
+ ...r.devices.map((d) => [
4275
+ d.id,
4276
+ d.name,
4277
+ d.member,
4278
+ d.role,
4279
+ ago2(d.last_seen),
4280
+ d.revoked_at ? c.dim("revoked") : d.pending ? c.accent("waiting for approval") : d.current ? c.accent("this machine") : ""
4281
+ ])
4282
+ ])
4283
+ );
4284
+ if (r.devices.some((d) => d.pending && !d.revoked_at)) note("Check the machine name and person before approving: `keybox devices approve ID`.");
4285
+ }
4286
+ note(r.legacy_token ? "The shared admin token is still accepted. `keybox token off` turns it off." : "The shared admin token is off.");
4287
+ }
4288
+ async function devicesAdd() {
4289
+ if (!process.stderr.isTTY) throw new UserError("keybox devices add shows a one-time code that enrols a machine as you; run it yourself in a terminal.");
4290
+ const cfg = requireConfig();
4291
+ const { code } = await api("POST", "/devices/pair", {});
4292
+ step("On the other machine, run:");
4293
+ process.stderr.write(`
4294
+ keybox login ${cfg.url} --code ${code}
4295
+
4296
+ `);
4297
+ note("Works once, for 10 minutes. Anyone who has it in that time can enrol a machine as you, so type it yourself.");
4298
+ }
4299
+ async function devicesApprove(id) {
4300
+ await api("POST", `/devices/${encodeURIComponent(id)}/approve`, {});
4301
+ ok(`Approved ${id}. That machine can now use this Keybox with its person's role.`);
4302
+ }
4303
+ async function devicesRevoke(id) {
4304
+ await api("DELETE", `/devices/${encodeURIComponent(id)}`);
4305
+ ok(`Revoked ${id}. That machine can no longer reach this Keybox.`);
4306
+ }
4307
+ async function tokenOff(opts) {
4308
+ const cfg = requireConfig();
4309
+ if (!cfg.deviceId) throw new UserError("Run `keybox claim` first, so this machine has its own key.");
4310
+ note("After this, only device keys work. Anything still using the shared token stops, including the Rust terminal console (`keybox-tui`).");
4311
+ if (!opts.yes && !await confirm("Turn the shared admin token off?", false)) return;
4312
+ await api("POST", "/token/disable", {});
4313
+ if (!process.env.KEYBOX_ADMIN_TOKEN && cfg.adminToken) saveConfig({ ...cfg, adminToken: void 0 });
4314
+ ok("The shared admin token is off, and removed from this machine.");
4315
+ note("To bring it back (break-glass), set the Worker secret KEYBOX_ALLOW_ADMIN_TOKEN to 1.");
4316
+ }
4177
4317
  function openBrowser(url) {
4178
4318
  const cmd = process.platform === "darwin" ? "open" : process.platform === "win32" ? "cmd" : "xdg-open";
4179
4319
  const args = process.platform === "win32" ? ["/c", "start", '""', url] : [url];
@@ -4201,7 +4341,7 @@ async function ui(opts) {
4201
4341
  function qrBlocks(text) {
4202
4342
  const qr = (0, import_qrcode.create)(text, { errorCorrectionLevel: "M" });
4203
4343
  const n = qr.modules.size;
4204
- const q = 2;
4344
+ const q = 4;
4205
4345
  const dark = (x, y) => x >= 0 && y >= 0 && x < n && y < n && Boolean(qr.modules.get(y, x));
4206
4346
  const out2 = [];
4207
4347
  for (let y = -q; y < n + q; y += 2) {
@@ -4225,6 +4365,7 @@ async function pair() {
4225
4365
  step(`Scan this with the Keybox app ${c.dim("(Pair \u203A Scan QR code)")}`);
4226
4366
  process.stderr.write("\n" + qrBlocks(url) + "\n");
4227
4367
  note("Works once, for 2 minutes. The app gets a 12-hour session; your admin token stays on this machine.");
4368
+ note("Camera will not read it? Make the terminal window bigger or zoom out, or run `keybox ui --print` and paste that link into the app.");
4228
4369
  note("To end every dashboard and app session: Access \u203A Sign out every dashboard session.");
4229
4370
  }
4230
4371
  async function accessShow() {
@@ -4319,15 +4460,63 @@ async function skill(opts) {
4319
4460
  step("Agents that load skills now know how to set up Keybox, migrate keys and write narrow rules safely.");
4320
4461
  note('Ask yours: "set up keybox for this project".');
4321
4462
  }
4322
- var import_qrcode, describe, skillAsset;
4463
+ async function membersList() {
4464
+ const r = await api("GET", "/members");
4465
+ process.stdout.write(
4466
+ headed([
4467
+ ["ID", "NAME", "ROLE", "MACHINES", ""],
4468
+ ...r.map((m) => [m.id, m.name, m.role, String(m.devices), [m.pending ? c.accent(`${m.pending} waiting for approval`) : "", m.invited ? c.dim("invited, not joined") : ""].filter(Boolean).join(", ")])
4469
+ ])
4470
+ );
4471
+ note("Roles: owner runs everything. admin runs keys and policy. member runs their own agents and tokens, and cannot change keys.");
4472
+ }
4473
+ async function membersAdd(name, opts) {
4474
+ const cfg = requireConfig();
4475
+ const r = await api("POST", "/members", { name, role: opts.role ?? "member" });
4476
+ step(`Invited ${c.bold(name)} as ${r.role}. They run:`);
4477
+ process.stderr.write(`
4478
+ keybox login ${cfg.url} --code ${r.code}
4479
+
4480
+ `);
4481
+ note("Valid 24 hours, works once. Their machine then waits for you: `keybox devices` shows it, `keybox devices approve ID` lets it in.");
4482
+ }
4483
+ async function membersRm(who) {
4484
+ const list2 = await api("GET", "/members");
4485
+ const m = list2.find((x) => x.id === who || x.name.toLowerCase() === who.toLowerCase());
4486
+ if (!m) throw new UserError(`No member called ${who}. See \`keybox members\`.`);
4487
+ await api("DELETE", `/members/${encodeURIComponent(m.id)}`);
4488
+ ok(`Removed ${m.name}. Their machines and dashboard sessions are revoked.`);
4489
+ }
4490
+ async function membersLog(limit) {
4491
+ const r = await api("GET", `/events?limit=${limit}`);
4492
+ if (!r.length) return note("Nothing yet.");
4493
+ process.stdout.write(
4494
+ headed([
4495
+ ["WHEN", "WHO", "MACHINE", "WHAT"],
4496
+ ...r.map((e) => [ago2(e.ts), e.member ?? (e.via === "token" ? c.dim("shared token") : c.dim(e.via)), e.device ?? "", e.action])
4497
+ ])
4498
+ );
4499
+ }
4500
+ var import_qrcode, checkUrl, ago2, describe, skillAsset;
4323
4501
  var init_extra = __esm({
4324
4502
  "src/extra.ts"() {
4325
4503
  "use strict";
4326
4504
  import_qrcode = __toESM(require_qrcode(), 1);
4327
4505
  init_api();
4328
4506
  init_config();
4507
+ init_device();
4329
4508
  init_prompt();
4330
4509
  init_ui();
4510
+ checkUrl = (u) => {
4511
+ const url = u.trim().replace(/\/+$/, "");
4512
+ if (!/^https:\/\/[^/\s]+$/.test(url)) throw new UserError("Give the https:// address of your Keybox, for example https://yourteam.keybox.space.");
4513
+ return url;
4514
+ };
4515
+ ago2 = (ms) => {
4516
+ if (!ms) return "never";
4517
+ const s = Math.round((Date.now() - ms) / 1e3);
4518
+ return s < 60 ? "just now" : s < 3600 ? `${Math.round(s / 60)}m ago` : s < 86400 ? `${Math.round(s / 3600)}h ago` : `${Math.round(s / 86400)}d ago`;
4519
+ };
4331
4520
  describe = (r) => {
4332
4521
  if (!r || !Object.keys(r).length) return c.dim("any network");
4333
4522
  const parts2 = [];
@@ -4435,7 +4624,7 @@ import { existsSync as existsSync5 } from "node:fs";
4435
4624
  import { delimiter, join as join6 } from "node:path";
4436
4625
  var TABS = ["Activity", "Secrets", "Agents"];
4437
4626
  var out = process.stdout;
4438
- var ago2 = (ms) => {
4627
+ var ago3 = (ms) => {
4439
4628
  if (!ms) return "never";
4440
4629
  const s = Math.round((Date.now() - ms) / 1e3);
4441
4630
  return s < 60 ? `${s}s` : s < 3600 ? `${Math.round(s / 60)}m` : s < 86400 ? `${Math.round(s / 3600)}h` : `${Math.round(s / 86400)}d`;
@@ -4469,9 +4658,8 @@ function nativeTui() {
4469
4658
  }
4470
4659
  async function tui(opts = {}) {
4471
4660
  if (!process.stdin.isTTY || !out.isTTY) throw new UserError("keybox tui needs an interactive terminal. Try `keybox status` or `keybox audit -f`.");
4472
- const native = opts.basic ? null : nativeTui();
4661
+ const native = opts.basic || !requireConfig().adminToken ? null : nativeTui();
4473
4662
  if (native) {
4474
- requireConfig();
4475
4663
  const code = await new Promise((resolve) => {
4476
4664
  const child = spawn6(native, [], { stdio: "inherit" });
4477
4665
  child.on("error", () => resolve(-1));
@@ -4511,12 +4699,12 @@ async function tui(opts = {}) {
4511
4699
  const res = r.decision === "allow" ? String(r.status) : r.decision.toUpperCase();
4512
4700
  const col = r.decision === "allow" && r.status < 400 ? c.ok(res.padEnd(5)) : c.bad(res.padEnd(5));
4513
4701
  const req = `${r.method} ${r.host ?? ""}${r.path ?? ""}`;
4514
- return `${c.dim(ago2(r.ts).padStart(4))} ${(r.agent ?? "-").padEnd(12).slice(0, 12)} ${col} ${fit(req, Math.max(10, w - 52))} ${c.dim(r.secret ?? r.reason ?? "")}`;
4702
+ return `${c.dim(ago3(r.ts).padStart(4))} ${(r.agent ?? "-").padEnd(12).slice(0, 12)} ${col} ${fit(req, Math.max(10, w - 52))} ${c.dim(r.secret ?? r.reason ?? "")}`;
4515
4703
  });
4516
4704
  }
4517
4705
  if (st.tab === 1) {
4518
4706
  return st.secrets.map(
4519
- (s) => `${c.bold(s.name.padEnd(26))} ${s.hosts.join(",").padEnd(30).slice(0, 30)} ${c.dim((s.fingerprint ?? "-").padEnd(13))} ${c.dim("used " + ago2(s.last_used))}`
4707
+ (s) => `${c.bold(s.name.padEnd(26))} ${s.hosts.join(",").padEnd(30).slice(0, 30)} ${c.dim((s.fingerprint ?? "-").padEnd(13))} ${c.dim("used " + ago3(s.last_used))}`
4520
4708
  );
4521
4709
  }
4522
4710
  return st.agents.flatMap((a) => [
@@ -4767,7 +4955,13 @@ init_ui();
4767
4955
  init_version();
4768
4956
  var HELP_BODY = `Setup
4769
4957
  keybox init [--account ID] [--name keybox] Deploy Keybox to your Cloudflare account
4770
- keybox login [URL] Connect to a Keybox someone else runs (a hosted team)
4958
+ keybox login [URL] [--code kb_pair_\u2026] Connect to a Keybox someone else runs (a hosted team)
4959
+ keybox claim Give this machine its own key (becomes the owner)
4960
+ keybox members [add NAME [--role member|admin] | rm NAME | log]
4961
+ People on this Keybox: invite, remove, and who changed what
4962
+ keybox devices [list|add|approve ID|revoke ID]
4963
+ Machines that can manage this Keybox; add one with a one-time code
4964
+ keybox token off [--yes] Turn the shared admin token off; only device keys work after
4771
4965
  keybox update [--check] [--yes] Update the CLI, then the deployed Worker, then verify
4772
4966
  keybox verify [--json] Check Cloudflare is running exactly this CLI's code
4773
4967
  keybox deploy [--yes] Replace the deployed Worker with this CLI's version
@@ -4877,6 +5071,8 @@ async function main(argv) {
4877
5071
  version: { type: "boolean", short: "v", default: false },
4878
5072
  follow: { type: "boolean", short: "f", default: false },
4879
5073
  limit: { type: "string", default: "50" },
5074
+ code: { type: "string" },
5075
+ role: { type: "string" },
4880
5076
  help: { type: "boolean", short: "h", default: false }
4881
5077
  }
4882
5078
  });
@@ -4888,7 +5084,7 @@ async function main(argv) {
4888
5084
  if (o.version) return void process.stdout.write(VERSION + "\n");
4889
5085
  if (o.verbose) process.env.KEYBOX_VERBOSE = "1";
4890
5086
  if (o.help || !group) return void process.stdout.write(help());
4891
- switch (`${group} ${["secrets", "agents", "tokens", "access", "skill"].includes(group) ? sub ?? "" : ""}`.trim()) {
5087
+ switch (`${group} ${["secrets", "agents", "tokens", "access", "skill", "devices", "token", "members"].includes(group) ? sub ?? "" : ""}`.trim()) {
4892
5088
  case "init":
4893
5089
  return init({ name: o.name, url: o.url, account: o.account, yes: o.yes });
4894
5090
  case "verify":
@@ -4898,7 +5094,29 @@ async function main(argv) {
4898
5094
  case "deploy":
4899
5095
  return deploy({ yes: o.yes, force: o.force });
4900
5096
  case "login":
4901
- return login(sub);
5097
+ return login(sub, { code: o.code });
5098
+ case "claim":
5099
+ return claim();
5100
+ case "devices":
5101
+ case "devices list":
5102
+ return devicesList();
5103
+ case "devices add":
5104
+ return devicesAdd();
5105
+ case "devices approve":
5106
+ return devicesApprove(need(arg, "device id"));
5107
+ case "members":
5108
+ case "members list":
5109
+ return membersList();
5110
+ case "members add":
5111
+ return membersAdd(need(arg, "name"), { role: o.role });
5112
+ case "members rm":
5113
+ return membersRm(need(arg, "name or id"));
5114
+ case "members log":
5115
+ return membersLog(Number(o.limit));
5116
+ case "devices revoke":
5117
+ return devicesRevoke(need(arg, "device id"));
5118
+ case "token off":
5119
+ return tokenOff({ yes: o.yes });
4902
5120
  case "status":
4903
5121
  return status();
4904
5122
  case "ui":
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keyboxed/cli",
3
- "version": "0.2.6",
3
+ "version": "0.3.0",
4
4
  "description": "Give AI agents access to your APIs without giving them your keys.",
5
5
  "homepage": "https://keybox.space",
6
6
  "license": "FSL-1.1-ALv2",