@indigoai-us/hq-cloud 6.18.111 → 6.18.113

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 (56) hide show
  1. package/dist/cognito-auth.d.ts.map +1 -1
  2. package/dist/cognito-auth.js +10 -2
  3. package/dist/cognito-auth.js.map +1 -1
  4. package/dist/outposts/cli-billing.d.ts +26 -13
  5. package/dist/outposts/cli-billing.d.ts.map +1 -1
  6. package/dist/outposts/cli-billing.js +41 -18
  7. package/dist/outposts/cli-billing.js.map +1 -1
  8. package/dist/outposts/client.d.ts +20 -3
  9. package/dist/outposts/client.d.ts.map +1 -1
  10. package/dist/outposts/client.js +58 -5
  11. package/dist/outposts/client.js.map +1 -1
  12. package/dist/outposts/command-company-access.d.ts +14 -0
  13. package/dist/outposts/command-company-access.d.ts.map +1 -0
  14. package/dist/outposts/command-company-access.js +328 -0
  15. package/dist/outposts/command-company-access.js.map +1 -0
  16. package/dist/outposts/command.d.ts +9 -6
  17. package/dist/outposts/command.d.ts.map +1 -1
  18. package/dist/outposts/command.js +435 -172
  19. package/dist/outposts/command.js.map +1 -1
  20. package/dist/outposts/company-access.d.ts +92 -0
  21. package/dist/outposts/company-access.d.ts.map +1 -0
  22. package/dist/outposts/company-access.js +331 -0
  23. package/dist/outposts/company-access.js.map +1 -0
  24. package/dist/outposts/company-outposts.d.ts +34 -2
  25. package/dist/outposts/company-outposts.d.ts.map +1 -1
  26. package/dist/outposts/company-outposts.js +75 -5
  27. package/dist/outposts/company-outposts.js.map +1 -1
  28. package/dist/outposts/company.d.ts +15 -3
  29. package/dist/outposts/company.d.ts.map +1 -1
  30. package/dist/outposts/company.js +41 -8
  31. package/dist/outposts/company.js.map +1 -1
  32. package/dist/outposts/errors.d.ts +9 -0
  33. package/dist/outposts/errors.d.ts.map +1 -1
  34. package/dist/outposts/errors.js +6 -0
  35. package/dist/outposts/errors.js.map +1 -1
  36. package/dist/outposts/host-deps.d.ts +11 -3
  37. package/dist/outposts/host-deps.d.ts.map +1 -1
  38. package/dist/outposts/host-deps.js +4 -4
  39. package/dist/outposts/host-deps.js.map +1 -1
  40. package/dist/outposts/index.d.ts +1 -1
  41. package/dist/outposts/index.d.ts.map +1 -1
  42. package/dist/outposts/index.js +1 -1
  43. package/dist/outposts/index.js.map +1 -1
  44. package/dist/outposts/sizes.d.ts +13 -9
  45. package/dist/outposts/sizes.d.ts.map +1 -1
  46. package/dist/outposts/sizes.js +19 -11
  47. package/dist/outposts/sizes.js.map +1 -1
  48. package/dist/s3.d.ts +79 -0
  49. package/dist/s3.d.ts.map +1 -1
  50. package/dist/s3.js +542 -61
  51. package/dist/s3.js.map +1 -1
  52. package/dist/sync/idle-full-reconcile.d.ts +13 -3
  53. package/dist/sync/idle-full-reconcile.d.ts.map +1 -1
  54. package/dist/sync/idle-full-reconcile.js +15 -3
  55. package/dist/sync/idle-full-reconcile.js.map +1 -1
  56. package/package.json +1 -1
@@ -14,13 +14,16 @@
14
14
  * selects a personal box; when omitted, personal calls target the caller's primary slot.
15
15
  *
16
16
  * Subcommands:
17
- * outposts provision [--company] — provision a box (paid; requires --yes)
17
+ * outposts provision [--company|--personal] — provision a box (paid; --yes, or
18
+ * confirm at a terminal). Without a kind flag a
19
+ * terminal asks company or personal; a script must pass one.
20
+ * A company that already has an Outpost gets another one.
18
21
  * outposts list — every personal Outpost you own
19
22
  * outposts list --company - a company's Outposts (name, id, state, jobs)
20
- * outposts create --company --name - another named company Outpost (billed to the company)
21
23
  * --outpost <name|id> - picks a company Outpost on status, login, login-code
22
24
  * and jobs register; optional when there is only one
23
- * outposts status [--id|--company] — live detail for one box
25
+ * outposts status [--id|--company] — live detail for one box; a company with several
26
+ * Outposts and no --outpost gets a table of them
24
27
  * outposts jobs — register, edit, pause, resume, delete, run-now, runs
25
28
  * outposts exec <command...> — run a command on the box (sync/async/detach);
26
29
  * exec, exec-*, and terminal take --company for a company box
@@ -43,13 +46,16 @@
43
46
  */
44
47
  import chalk from "chalk";
45
48
  import * as fs from "node:fs";
46
- import { invalidSizeMessage, isOutpostSize, loadOutpostPricing, outpostMonthlyCents, outpostSizeMenu, outpostSizePrompt, readSizeChoice, } from "./sizes.js";
49
+ import { invalidSizeMessage, isOutpostSize, loadOutpostPricing, MENU_PRESELECTED_SIZE, outpostMonthlyCents, outpostSizeMenu, outpostSizePrompt, readSizeChoice, } from "./sizes.js";
47
50
  import { OutpostPullError, pullOutpostFile } from "./pull.js";
48
51
  import { buildCompanyJobDefinition, mergeCompanyJobEdit, companyPayerLabel, companyProvisionProgress, CompanyTargetError, JobDefinitionError, describeCompanySignIn, safeLoginUrl, explainCompanyFailure, FAILED_CLEANED_UP, failedCleanedUpLine, isCompanySlug, isFailedCleanedUpRecord, provisionRetryCommand, parseCompanySignIn, companyCreateContinues, isProvisionOutcomeUnknown, mergeCompanyJobs, provisionErrorSkipsStatusRead, } from "./company.js";
49
- import { companyOutpostChargeLine, companyOutpostsUnreadableLine, CompanyOutpostSelectError, explainCompanyOutpostCreateFailure, explainCompanyOutpostSelect, isCompanyOutpostId, isOutpostName, LEGACY_OUTPOST_NAME, safeLifecycle, selectCompanyOutpost, } from "./company-outposts.js";
50
- import { confirmChargeOrExit, confirmCompanyOutpostChargeOrExit, surfaceBillingBlocked, } from "./cli-billing.js";
52
+ import { companyHasOutpost, companyOutpostChargeLine, companyOutpostFailure, companyOutpostFailureLine, companyOutpostsUnreadableLine, CompanyOutpostSelectError, explainCompanyOutpostCreateFailure, explainCompanyOutpostSelect, isCompanyOutpostId, LEGACY_OUTPOST_NAME, readViewerRole, safeLifecycle, selectCompanyOutpost, } from "./company-outposts.js";
53
+ import { chargeConfirmedText, chargeRefusalText, companyChargeConfirmedText, companyChargeRefusalText, surfaceBillingBlocked, } from "./cli-billing.js";
51
54
  import { EXEC_MAX_TIMEOUT_SECONDS, OutpostsClient, } from "./client.js";
52
55
  import { OutpostExecWaitError, OutpostHttpError } from "./errors.js";
56
+ import { formatUsd } from "./billing.js";
57
+ import { explainCompanyShellRefusal, explainDiskRefusal, isQuoteUnsupported, quoteLines, quoteTotalCents, readQuote, } from "./company-access.js";
58
+ import { registerCompanyAccessCommands } from "./command-company-access.js";
53
59
  import { registerHeartbeatCommand } from "./heartbeat-command.js";
54
60
  import { registerSessionHostCommand } from "./session-host-command.js";
55
61
  import { HQ_CLOUD_VERSION } from "../version.js";
@@ -194,19 +200,10 @@ async function listCompanyOutpostsCommand(client, slug, asJson) {
194
200
  }
195
201
  if (list.outposts.length === 0) {
196
202
  console.log(`${company.slug} does not have an Outpost yet.`);
197
- console.log(`Next: hq outposts provision --company ${company.slug}`);
203
+ console.log(noOutpostNext(company.slug, list.viewerRole));
198
204
  return;
199
205
  }
200
- const nameW = Math.max(4, ...list.outposts.map((o) => o.name.length));
201
- const idW = Math.max(2, ...list.outposts.map((o) => (o.outpostId ?? "").length));
202
- console.log(chalk.bold(["NAME".padEnd(nameW), "ID".padEnd(idW), "STATE"].join(" ")));
203
- for (const o of list.outposts) {
204
- console.log([
205
- o.name.padEnd(nameW),
206
- (o.outpostId ?? "").padEnd(idW),
207
- o.lifecycle ?? "",
208
- ].join(" "));
209
- }
206
+ printCompanyOutpostTable(list.outposts);
210
207
  if (list.legacy) {
211
208
  console.log(chalk.dim(`${company.slug} has one Outpost, shown as ${LEGACY_OUTPOST_NAME}.`));
212
209
  }
@@ -214,14 +211,97 @@ async function listCompanyOutpostsCommand(client, slug, asJson) {
214
211
  console.log(chalk.yellow(`${unreadable} more Outpost row(s) could not be read and are not shown.`));
215
212
  }
216
213
  }
214
+ /** The next step when a company has no Outpost. A member cannot create one. */
215
+ function noOutpostNext(slug, role) {
216
+ return role === "member"
217
+ ? `Only an owner or admin of ${slug} can create one. Next: ask an owner or admin of ${slug}.`
218
+ : `Next: hq outposts provision --company ${slug}`;
219
+ }
220
+ /** NAME, ID, STATE and, when any row has one, SIZE; then CAN_USE (yes, no or -) when the server sent canUse. */
221
+ function printCompanyOutpostTable(rows) {
222
+ const nameW = Math.max(4, ...rows.map((o) => o.name.length));
223
+ const idW = Math.max(2, ...rows.map((o) => (o.outpostId ?? "").length));
224
+ const stateW = Math.max(5, ...rows.map((o) => (o.lifecycle ?? "").length));
225
+ const sized = rows.some((o) => o.size);
226
+ const usable = rows.some((o) => o.canUse !== undefined);
227
+ const header = ["NAME".padEnd(nameW), "ID".padEnd(idW), sized ? "STATE".padEnd(stateW) : "STATE"];
228
+ if (sized)
229
+ header.push("SIZE");
230
+ if (usable)
231
+ header.push("CAN_USE");
232
+ console.log(chalk.bold(header.join(" ")));
233
+ for (const o of rows) {
234
+ const cells = [
235
+ o.name.padEnd(nameW),
236
+ (o.outpostId ?? "").padEnd(idW),
237
+ sized ? (o.lifecycle ?? "").padEnd(stateW) : o.lifecycle ?? "",
238
+ ];
239
+ if (sized)
240
+ cells.push(o.size ?? "");
241
+ if (usable)
242
+ cells.push(o.canUse === undefined ? "-" : o.canUse ? "yes" : "no");
243
+ console.log(cells.join(" "));
244
+ }
245
+ }
246
+ const KIND_PROMPT_ATTEMPTS = 3;
247
+ function readKindChoice(answer) {
248
+ const value = answer.trim().toLowerCase();
249
+ if (value === "1" || value === "company")
250
+ return "company";
251
+ if (value === "2" || value === "personal")
252
+ return "personal";
253
+ return undefined;
254
+ }
255
+ /**
256
+ * Ask which kind of Outpost to create when neither --company nor --personal
257
+ * was passed. Company is listed first. Nothing is taken from the active
258
+ * company, and there is no default: the person types a choice. Without a
259
+ * terminal, or with --json, the command stops and names both flags.
260
+ */
261
+ async function chooseOutpostKind(host, json) {
262
+ const missing = "Choose which kind of Outpost to create. Nothing was created or billed. " +
263
+ "Next: re-run with --company <slug> for a company Outpost, or --personal for your own.";
264
+ if (json || !host.isStdinTty() || !host.readAnswer) {
265
+ console.error(missing);
266
+ process.exit(1);
267
+ }
268
+ console.error("Which kind of Outpost?");
269
+ console.error(" 1) Company Outpost (billed to a company)");
270
+ console.error(" 2) Personal Outpost (your own, billed to you)");
271
+ let kind;
272
+ for (let attempt = 0; attempt < KIND_PROMPT_ATTEMPTS && !kind; attempt++) {
273
+ kind = readKindChoice(await host.readAnswer("Kind [1-2]: "));
274
+ if (!kind)
275
+ console.error(chalk.yellow("Pick 1 for a company Outpost or 2 for a personal Outpost."));
276
+ }
277
+ if (!kind) {
278
+ console.error(missing);
279
+ process.exit(1);
280
+ }
281
+ if (kind === "personal")
282
+ return { kind };
283
+ let slug;
284
+ for (let attempt = 0; attempt < KIND_PROMPT_ATTEMPTS && !slug; attempt++) {
285
+ const answer = (await host.readAnswer("Company slug: ")).trim();
286
+ if (isCompanySlug(answer))
287
+ slug = answer;
288
+ else
289
+ console.error(chalk.yellow("Type the company's lowercase slug, such as indigo."));
290
+ }
291
+ if (!slug) {
292
+ console.error("No company was chosen. Nothing was created or billed. Next: re-run with --company <slug>.");
293
+ process.exit(1);
294
+ }
295
+ return { kind, slug };
296
+ }
217
297
  const SIZE_PROMPT_ATTEMPTS = 3;
218
298
  /**
219
299
  * Settle the Outpost size before anything is created or billed.
220
300
  *
221
301
  * `--size` wins. Without it, an interactive terminal gets a menu of the four
222
- * sizes with their prices; Enter takes the default. A script with no
223
- * terminal, or any `--json` run, takes the default. The default sends no
224
- * `size`: the server keeps today's box and bills the small tier's price.
302
+ * sizes with their prices; medium is preselected and Enter takes it. A
303
+ * script with no terminal, or any `--json` run, takes the default, which
304
+ * sends no `size`: the server keeps today's box and bills the small tier's price.
225
305
  * Prices come from `/v1/pricing`, or the bundled copy when that call fails.
226
306
  * The menu goes to stderr so `--json` stdout stays one object.
227
307
  */
@@ -238,15 +318,14 @@ export async function chooseOutpostSize(source, host, flag, json = false) {
238
318
  }
239
319
  else if (!json && host.isStdinTty() && host.readAnswer) {
240
320
  console.error("Choose an Outpost size:");
241
- for (const line of outpostSizeMenu(pricing))
321
+ for (const line of outpostSizeMenu(pricing, MENU_PRESELECTED_SIZE))
242
322
  console.error(line);
243
323
  if (pricing.source === "bundled") {
244
324
  console.error(chalk.dim("Prices could not be fetched, so these are the prices this CLI shipped with."));
245
325
  }
246
326
  let answer;
247
327
  for (let attempt = 0; attempt < SIZE_PROMPT_ATTEMPTS && !answer; attempt++) {
248
- process.stderr.write(outpostSizePrompt(pricing));
249
- answer = readSizeChoice(await host.readAnswer());
328
+ answer = readSizeChoice(await host.readAnswer(outpostSizePrompt(pricing, MENU_PRESELECTED_SIZE)), MENU_PRESELECTED_SIZE);
250
329
  if (!answer)
251
330
  console.error(chalk.yellow("Pick 1 to 4, or one of small, medium, large, xlarge."));
252
331
  }
@@ -258,79 +337,32 @@ export async function chooseOutpostSize(source, host, flag, json = false) {
258
337
  }
259
338
  return { ...(size ? { size } : {}), pricing, priceCents: outpostMonthlyCents(pricing, size) };
260
339
  }
261
- async function createCompanyOutpostCommand(client, host, loadPricing, opts, wait = {}) {
262
- const json = opts.json === true;
263
- const name = opts.name?.trim() ?? "";
264
- if (!isOutpostName(name)) {
265
- console.error("An Outpost needs a name of 1 to 32 lowercase letters, digits or dashes, such as research. " +
266
- `Next: re-run with --company ${isCompanySlug(opts.company) ? opts.company : "<slug>"} --name <name>.`);
267
- if (json) {
268
- writeCompanyProvisionJson({ ok: false, company: opts.company, state: "not_created", reason: "invalid_name" });
269
- }
340
+ /**
341
+ * Settle the charge before anything is sent. `--yes` confirms it. Without
342
+ * it, a terminal (not `--json`) asks for "yes"; a script gets the refusal
343
+ * and exits 1. Returns false when the person said no: nothing was sent.
344
+ */
345
+ async function confirmOutpostCharge(host, gate) {
346
+ if (gate.yes)
347
+ return true;
348
+ if (gate.json || !host.isStdinTty()) {
349
+ console.error(chalk.yellow(gate.refusal));
350
+ gate.onNotCreated?.("confirmation_required");
270
351
  process.exit(1);
271
352
  }
272
- let company;
273
- try {
274
- company = await requireCompany(client, opts.company);
275
- }
276
- catch (err) {
277
- if (err && typeof err === "object")
278
- failedBeforeCreate.add(err);
279
- throw err;
280
- }
281
- const choice = await chooseOutpostSize(loadPricing, host, opts.size, json);
282
- const charge = companyOutpostChargeLine(companyPayerLabel(company), choice.priceCents, choice.size);
283
- const unnamed = `The name ${name} is not sent. This server creates the company's main Outpost.`;
284
- if (!opts.yes) {
285
- if (!host.isStdinTty()) {
286
- console.error(`Creating ${company.slug}'s main Outpost costs ${charge}. ${unnamed} ` +
287
- `Next: re-run with --yes to confirm this charge.`);
288
- if (json) {
289
- writeCompanyProvisionJson({
290
- ok: false,
291
- company: company.slug,
292
- state: "not_created",
293
- reason: "confirmation_required",
294
- });
295
- }
296
- process.exit(1);
297
- }
298
- // In --json the prompt goes to stderr so stdout stays one object.
299
- const prompt = `Create ${company.slug}'s main Outpost? ${charge}. ${unnamed} Type yes to confirm: `;
300
- if (json)
301
- process.stderr.write(prompt);
302
- else
303
- process.stdout.write(prompt);
304
- if (!(await host.confirm())) {
305
- if (json) {
306
- console.error("Nothing was created or billed.");
307
- writeCompanyProvisionJson({
308
- ok: false,
309
- company: company.slug,
310
- state: "not_created",
311
- reason: "confirmation_declined",
312
- });
313
- }
314
- else {
315
- console.log("Nothing was created or billed.");
316
- }
317
- return;
318
- }
319
- }
320
- else {
321
- provisionProgress(json, `Confirmed: ${charge}. ${unnamed}`);
322
- }
323
- await startCompanyOutpost(client, company, wait, {
324
- json,
325
- size: choice.size,
326
- explainRefusal: (err) => explainCompanyOutpostCreateFailure(company.slug, err),
327
- retryCommand: `hq outposts create --company ${company.slug} --name ${name}${choice.size ? ` --size ${choice.size}` : ""} --yes`,
328
- });
353
+ // The prompt goes through the reader: readline clears the line before it
354
+ // draws, so a separate write here would be erased.
355
+ if (await host.confirm(`${gate.prompt} Type yes to confirm: `))
356
+ return true;
357
+ console.log("Nothing was created or billed.");
358
+ return false;
329
359
  }
330
- function printCompanyJobs(companySlug, jobs, healthAvailable) {
360
+ function printCompanyJobs(companySlug, jobs, healthAvailable, role) {
331
361
  if (jobs.length === 0) {
332
362
  console.log("No company jobs yet.");
333
- console.log(`Next: hq outposts jobs register --company ${companySlug} --prompt "<what to run>" --cron "rate(1 day)" --timezone UTC`);
363
+ if (role !== "member") {
364
+ console.log(`Next: hq outposts jobs register --company ${companySlug} --prompt "<what to run>" --cron "rate(1 day)" --timezone UTC`);
365
+ }
334
366
  return;
335
367
  }
336
368
  if (!healthAvailable) {
@@ -361,6 +393,10 @@ function writeCompanyProvisionJson(body) {
361
393
  payload.code = body.code;
362
394
  if (body.reason)
363
395
  payload.reason = body.reason;
396
+ if (body.failure)
397
+ payload.failure = body.failure;
398
+ if (body.reused)
399
+ payload.reused = true;
364
400
  if (body.retrySafe)
365
401
  payload.retrySafe = true;
366
402
  process.stdout.write(JSON.stringify(payload) + "\n");
@@ -384,8 +420,10 @@ function companyProvisionFailureJson(company, err) {
384
420
  else if (code === FAILED_CLEANED_UP) {
385
421
  return JSON.stringify({ ok: false, company, state: "blocked", code, reason, retrySafe: true }) + "\n";
386
422
  }
387
- else if (code === "already_exists" || code === "billing_required")
423
+ else if (code === "already_exists" || code === "outpost_limit" || code === "billing_required")
388
424
  state = "blocked";
425
+ else if (code === "name_taken" || code === "operation_in_progress")
426
+ state = "not_created";
389
427
  else if (code === "feature_disabled" ||
390
428
  code === "unavailable" ||
391
429
  code === "dependencies_unavailable" ||
@@ -418,42 +456,131 @@ function correlationFrom(outpost, err) {
418
456
  ...(operationId ? { operationId } : {}),
419
457
  };
420
458
  }
459
+ /**
460
+ * The server's price for this create (machine, disk tier and total), read
461
+ * before the price is confirmed. A server without quotes gives undefined,
462
+ * and the size price is used as before. A disk-sizing refusal stops here,
463
+ * before anything is created or billed.
464
+ */
465
+ async function quoteCompanyOutpostForCreate(client, company, size, additional, json) {
466
+ let body;
467
+ try {
468
+ body = await client.quoteCompanyOutpost(company.uid, size, additional);
469
+ }
470
+ catch (err) {
471
+ if (isQuoteUnsupported(err))
472
+ return undefined;
473
+ const disk = explainDiskRefusal(company.slug, err);
474
+ if (disk) {
475
+ console.error(disk);
476
+ if (json) {
477
+ writeCompanyProvisionJson({
478
+ ok: false,
479
+ company: company.slug,
480
+ state: "not_created",
481
+ code: err.code ?? "request_failed",
482
+ reason: err.code ?? "request_failed",
483
+ });
484
+ }
485
+ process.exit(1);
486
+ }
487
+ if (err && typeof err === "object")
488
+ failedBeforeCreate.add(err);
489
+ throw err;
490
+ }
491
+ const quote = readQuote(body);
492
+ if (!quote) {
493
+ console.error(`The server's price for ${company.slug}'s Outpost could not be read. Nothing was created or billed. Next: try again later.`);
494
+ if (json) {
495
+ writeCompanyProvisionJson({ ok: false, company: company.slug, state: "not_created", code: "quote_unreadable", reason: "quote_unreadable" });
496
+ }
497
+ process.exit(1);
498
+ }
499
+ return quote;
500
+ }
421
501
  async function provisionCompanyOutpost(client, host, loadPricing, slug, yes, wait = {}, json = false, sizeFlag) {
422
502
  let company;
503
+ let list;
423
504
  try {
424
505
  company = await requireCompany(client, slug);
506
+ list = await client.listCompanyOutposts(company.uid);
425
507
  }
426
508
  catch (err) {
427
509
  if (err && typeof err === "object")
428
510
  failedBeforeCreate.add(err);
429
511
  throw err;
430
512
  }
513
+ if (list.viewerRole === "member") {
514
+ console.error(`Only an owner or admin of ${company.slug} can create an Outpost. Nothing was created or billed. ` +
515
+ `Next: ask an owner or admin of ${company.slug}.`);
516
+ if (json) {
517
+ writeCompanyProvisionJson({ ok: false, company: company.slug, state: "not_created", code: "admin_required", reason: "admin_required" });
518
+ }
519
+ process.exit(1);
520
+ }
521
+ const additional = companyHasOutpost(list, company.uid);
431
522
  const choice = await chooseOutpostSize(loadPricing, host, sizeFlag, json);
432
- confirmCompanyOutpostChargeOrExit({
523
+ const payerLabel = companyPayerLabel(company);
524
+ const quote = await quoteCompanyOutpostForCreate(client, company, choice.size, additional, json);
525
+ if (quote) {
526
+ for (const line of quoteLines(quote, payerLabel))
527
+ provisionProgress(json, line);
528
+ }
529
+ const priceCents = quote ? quoteTotalCents(quote) : choice.priceCents;
530
+ const charge = {
433
531
  slug: company.slug,
434
- payerLabel: companyPayerLabel(company),
435
- priceCents: choice.priceCents,
532
+ payerLabel,
533
+ priceCents,
436
534
  ...(choice.size ? { size: choice.size } : {}),
437
- yes,
535
+ };
536
+ const what = additional ? `another Outpost for ${company.slug}` : `${company.slug}'s Outpost`;
537
+ const confirmed = await confirmOutpostCharge(host, {
538
+ ...(yes !== undefined ? { yes } : {}),
438
539
  json,
540
+ refusal: companyChargeRefusalText(charge),
541
+ prompt: `Create ${what}? ${quote
542
+ ? `${formatUsd(priceCents)} per month in total, billed to ${payerLabel}`
543
+ : companyOutpostChargeLine(payerLabel, choice.priceCents, choice.size)}.`,
544
+ onNotCreated: (reason) => {
545
+ if (json)
546
+ writeCompanyProvisionJson({ ok: false, company: company.slug, state: "not_created", reason });
547
+ },
439
548
  });
549
+ if (!confirmed)
550
+ return;
440
551
  await startCompanyOutpost(client, company, wait, {
441
552
  json,
442
553
  size: choice.size,
554
+ additional,
555
+ acceptedLine: companyChargeConfirmedText(charge),
556
+ explainRefusal: (err) => explainCompanyOutpostCreateFailure(company.slug, err),
443
557
  retryCommand: `${provisionRetryCommand(company.slug)}${choice.size ? ` --size ${choice.size}` : ""}`,
444
558
  });
445
559
  }
446
560
  /**
447
- * Send the create, then report what status shows. `provision --company` and
448
- * `create --company --name` both use this, so neither prints "not created"
449
- * for a create that may still be running.
561
+ * Send the create, then report what status shows, so a create that may
562
+ * still be running is never reported as "not created".
563
+ *
564
+ * `acceptedLine` (the confirmed charge) prints once the server accepts the
565
+ * create, or once status shows it running after an unclear answer; never
566
+ * before. With `additional`, the create asks for another Outpost and status
567
+ * is read for the new Outpost's id.
568
+ *
569
+ * An accepted create that answers with an Outpost another create already
570
+ * started is not a new Outpost: the server marks it `reused: true`, and an
571
+ * additional create whose returned row was created before this request was
572
+ * sent (beyond {@link REUSED_CLOCK_SKEW_MS}) is treated the same. That case
573
+ * prints one plain line, no confirmed charge, and exits 0.
450
574
  *
451
575
  * A refusal from {@link provisionErrorSkipsStatusRead} is a real answer:
452
576
  * `explainRefusal` may give its plain line (not in `--json`), otherwise it
453
577
  * is rethrown for the command's error handler. Any other error, such as a
454
578
  * codeless 5xx (API Gateway's 30s cut-off on a create that keeps running),
455
579
  * `503 outcome_unknown`, a coded 5xx, a dropped connection or an unreadable
456
- * body, says nothing final about whether the box exists, so status is read.
580
+ * body, says nothing final about whether the box exists. For a first create,
581
+ * status is read. For an additional create there is no new id to read, and
582
+ * status without one would show a different Outpost, so status is not read:
583
+ * the result is unconfirmed and the next step is `hq outposts list`.
457
584
  * `failed_cleaned_up`, from the create or from status, is also final: the
458
585
  * server verified the cleanup, so it stops the wait and names `retryCommand`.
459
586
  * With `json`, progress goes to stderr and stdout gets one object.
@@ -463,12 +590,26 @@ async function startCompanyOutpost(client, company, wait, opts = {}) {
463
590
  const retryCommand = opts.retryCommand ?? provisionRetryCommand(company.slug);
464
591
  let outpost;
465
592
  let provisionError;
593
+ let accepted = false;
594
+ const announceAccepted = () => {
595
+ if (accepted || !opts.acceptedLine)
596
+ return;
597
+ accepted = true;
598
+ provisionProgress(json, opts.acceptedLine);
599
+ };
600
+ const sentAt = (wait.now ?? Date.now)();
466
601
  try {
467
- outpost = (await client.provisionCompany(company.uid, opts.size)).outpost;
602
+ const answer = await client.provisionCompany(company.uid, opts.size, opts.additional === true);
603
+ outpost = answer.outpost;
604
+ if (createWasReused(answer, opts.additional === true, sentAt)) {
605
+ reportReusedCreate(company.slug, outpost, json);
606
+ return;
607
+ }
608
+ announceAccepted();
468
609
  }
469
610
  catch (err) {
470
611
  if (err instanceof OutpostHttpError && err.code === FAILED_CLEANED_UP) {
471
- reportFailedCleanedUp(company.slug, retryCommand, json);
612
+ reportFailedCleanedUp(company.slug, retryCommand, json, undefined, err.failure);
472
613
  return;
473
614
  }
474
615
  // A refusal or a coded "nothing changed" answer is final.
@@ -489,16 +630,25 @@ async function startCompanyOutpost(client, company, wait, opts = {}) {
489
630
  provisionProgress(json, line);
490
631
  }
491
632
  const code = provisionError instanceof OutpostHttpError ? provisionError.code : undefined;
492
- const finished = await waitForCompanyOutpost(client, company.uid, outpost, wait, {
493
- json,
494
- correlation: correlationFrom(outpost, provisionError),
495
- trustInitial: outpost !== undefined,
496
- announceInProgress: provisionError !== undefined,
497
- });
633
+ const createdId = typeof outpost?.outpostId === "string" && isCompanyOutpostId(outpost.outpostId)
634
+ ? outpost.outpostId
635
+ : undefined;
636
+ const finished = opts.additional && !createdId
637
+ ? { state: "unconfirmed" }
638
+ : await waitForCompanyOutpost(client, company.uid, outpost, wait, {
639
+ json,
640
+ correlation: correlationFrom(outpost, provisionError),
641
+ trustInitial: outpost !== undefined,
642
+ announceInProgress: provisionError !== undefined,
643
+ ...(opts.additional && createdId ? { outpostId: createdId } : {}),
644
+ });
645
+ if (finished.state === "ready" || finished.state === "pending")
646
+ announceAccepted();
498
647
  // The id goes into a terminal line and JSON, so only a printable one is shown.
499
648
  const rawId = finished.outpostId ?? outpost?.outpostId;
500
649
  const id = typeof rawId === "string" && isCompanyOutpostId(rawId) ? rawId : undefined;
501
650
  const label = `${company.slug}'s Outpost${id ? ` (${id})` : ""}`;
651
+ const statusNext = `hq outposts status --company ${company.slug}${opts.additional && id ? ` --outpost ${id}` : ""}`;
502
652
  if (finished.state === "ready") {
503
653
  if (json) {
504
654
  writeCompanyProvisionJson({
@@ -510,15 +660,16 @@ async function startCompanyOutpost(client, company, wait, opts = {}) {
510
660
  return;
511
661
  }
512
662
  console.log(chalk.green(`${label} is ready.`));
513
- console.log(chalk.dim(`Next: hq outposts status --company ${company.slug}`));
663
+ console.log(chalk.dim(`Next: ${statusNext}`));
514
664
  return;
515
665
  }
516
666
  if (finished.state === "blocked" && finished.reason === FAILED_CLEANED_UP) {
517
- reportFailedCleanedUp(company.slug, retryCommand, json, id);
667
+ reportFailedCleanedUp(company.slug, retryCommand, json, id, finished.failure);
518
668
  return;
519
669
  }
520
670
  if (finished.state === "blocked") {
521
671
  const notCreated = finished.reason === "not_started";
672
+ const failure = finished.failure;
522
673
  if (json) {
523
674
  writeCompanyProvisionJson({
524
675
  ok: false,
@@ -527,25 +678,31 @@ async function startCompanyOutpost(client, company, wait, opts = {}) {
527
678
  ...(id ? { outpostId: id } : {}),
528
679
  ...(code ? { code } : {}),
529
680
  ...(finished.reason ? { reason: finished.reason } : {}),
681
+ ...(failure ? { failure } : {}),
530
682
  });
683
+ if (failure)
684
+ console.error(companyOutpostFailureLine(failure));
531
685
  }
532
686
  else if (notCreated) {
533
687
  console.error(`${label} was not created; nothing was built. Next: re-run hq outposts provision --company ${company.slug} to try again.`);
534
688
  }
535
689
  else if (finished.reason === "billing_required") {
536
- console.error(`Billing for ${company.slug} is blocked, so the Outpost could not finish provisioning. Next: check the company's billing in the console, then run hq outposts status --company ${company.slug}.`);
690
+ console.error(`Billing for ${company.slug} is blocked, so the Outpost could not finish provisioning. Next: check the company's billing in the console, then run ${statusNext}.`);
537
691
  }
538
692
  else {
539
- console.error(`${label} stopped while provisioning and needs attention. Next: hq outposts status --company ${company.slug}, and contact support before retrying.`);
693
+ if (failure)
694
+ console.error(companyOutpostFailureLine(failure));
695
+ console.error(`${label} stopped while provisioning and needs attention. Next: ${statusNext}, and contact support before retrying.`);
540
696
  }
541
697
  // exitCode, not exit(): the action's catch must not add a second message.
542
698
  process.exitCode = 1;
543
699
  return;
544
700
  }
545
701
  if (finished.state === "unconfirmed") {
702
+ const check = opts.additional && !id ? `hq outposts list --company ${company.slug}` : statusNext;
546
703
  console.error(finished.signInFailed
547
- ? `The result of the create request could not be confirmed because the status check needs you to sign in to HQ again. Next: run hq login, then run hq outposts status --company ${company.slug} first, before retrying.`
548
- : `The result of the create request could not be confirmed. Next: run hq outposts status --company ${company.slug} first, before retrying.`);
704
+ ? `The result of the create request could not be confirmed because the status check needs you to sign in to HQ again. Next: run hq login, then run ${check} first, before retrying.`
705
+ : `The result of the create request could not be confirmed. Next: run ${check} first, before retrying.`);
549
706
  if (json) {
550
707
  writeCompanyProvisionJson({
551
708
  ok: false,
@@ -568,12 +725,47 @@ async function startCompanyOutpost(client, company, wait, opts = {}) {
568
725
  });
569
726
  return;
570
727
  }
571
- console.log(chalk.yellow(`Provisioning started for ${label}; it is not ready yet. Check it with: hq outposts status --company ${company.slug}`));
728
+ console.log(chalk.yellow(`Provisioning started for ${label}; it is not ready yet. Check it with: ${statusNext}`));
572
729
  }
573
- /** A create that failed and was cleaned up: say it is safe to run again, and exit 1. */
574
- function reportFailedCleanedUp(slug, retryCommand, json, outpostId) {
575
- const line = failedCleanedUpLine(retryCommand);
576
- console.error(line);
730
+ /** How far the server clock may run behind this one before a returned row counts as older than the request. */
731
+ const REUSED_CLOCK_SKEW_MS = 60_000;
732
+ /**
733
+ * True when the server answered with an Outpost that an earlier create
734
+ * started, rather than a new one: it says `reused: true` (on the body or the
735
+ * row), or, for an additional create, the row's `createdAt` is earlier than
736
+ * the moment the request was sent minus {@link REUSED_CLOCK_SKEW_MS}.
737
+ */
738
+ function createWasReused(answer, additional, sentAt) {
739
+ if (answer.reused === true || answer.outpost?.reused === true)
740
+ return true;
741
+ if (!additional)
742
+ return false;
743
+ const createdAt = answer.outpost?.createdAt;
744
+ if (typeof createdAt !== "string")
745
+ return false;
746
+ const created = Date.parse(createdAt);
747
+ return Number.isFinite(created) && created < sentAt - REUSED_CLOCK_SKEW_MS;
748
+ }
749
+ /** Another create was already running: name it, say nothing was created or billed, exit 0. */
750
+ function reportReusedCreate(slug, outpost, json) {
751
+ const rawId = outpost?.outpostId;
752
+ const id = typeof rawId === "string" && isCompanyOutpostId(rawId) ? rawId : undefined;
753
+ const line = `Another Outpost is already being created for ${slug}${id ? `: ${id}` : ""}. Nothing new was created or billed.`;
754
+ if (json) {
755
+ console.error(line);
756
+ writeCompanyProvisionJson({ ok: true, company: slug, state: "pending", ...(id ? { outpostId: id } : {}), reused: true });
757
+ return;
758
+ }
759
+ console.log(line);
760
+ console.log(chalk.dim(`Next: hq outposts status --company ${slug}${id ? ` --outpost ${id}` : ""}`));
761
+ }
762
+ /**
763
+ * A create that failed and was cleaned up: say why in the server's words,
764
+ * that nothing was left running or billed, that it is safe to run again, and
765
+ * exit 1.
766
+ */
767
+ function reportFailedCleanedUp(slug, retryCommand, json, outpostId, failure) {
768
+ console.error(failedCleanedUpLine(retryCommand, failure));
577
769
  if (json) {
578
770
  writeCompanyProvisionJson({
579
771
  ok: false,
@@ -583,6 +775,7 @@ function reportFailedCleanedUp(slug, retryCommand, json, outpostId) {
583
775
  code: FAILED_CLEANED_UP,
584
776
  reason: FAILED_CLEANED_UP,
585
777
  retrySafe: true,
778
+ ...(failure ? { failure } : {}),
586
779
  });
587
780
  }
588
781
  // exitCode, not exit(): the action's catch must not add a second message.
@@ -638,9 +831,9 @@ async function waitForCompanyOutpost(client, companyUid, initial, wait, poll) {
638
831
  }
639
832
  await pause(pollMs);
640
833
  try {
641
- // No outpostId: the deployed server rejects it with 400 invalid_body
642
- // until hq-pro-agents #1217 ships. Rows are matched by attempt id instead.
643
- const status = await client.companyStatus(companyUid);
834
+ // Only an additional Outpost is read by id. The first Outpost is read
835
+ // without one, as older servers expect, and matched by attempt id.
836
+ const status = await client.companyStatus(companyUid, poll.outpostId);
644
837
  if (!rowBelongsToCreate(status.outpost, poll))
645
838
  continue;
646
839
  progress = companyProvisionProgress(status.outpost);
@@ -816,11 +1009,11 @@ async function destroyCompanyOutpostCommand(client, host, opts, wait = {}) {
816
1009
  process.stdout.write("This permanently destroys an Outpost and everything on it.\n" +
817
1010
  ` Company: ${company.slug}\n` +
818
1011
  ` Outpost: ${target.name}\n` +
819
- ` Id: ${id ?? "none (the company's only Outpost)"}\n` +
820
- `Type the Outpost name (${target.name}) or yes to confirm: `);
1012
+ ` Id: ${id ?? "none (the company's only Outpost)"}\n`);
1013
+ const question = `Type the Outpost name (${target.name}) or yes to confirm: `;
821
1014
  const answer = host.readAnswer
822
- ? (await host.readAnswer()).trim()
823
- : (await host.confirm()) ? "yes" : "";
1015
+ ? (await host.readAnswer(question)).trim()
1016
+ : (await host.confirm(question)) ? "yes" : "";
824
1017
  if (answer !== target.name && !/^yes$/i.test(answer)) {
825
1018
  console.log("Nothing was destroyed.");
826
1019
  return;
@@ -890,9 +1083,20 @@ async function destroyCompanyOutpostCommand(client, host, opts, wait = {}) {
890
1083
  }
891
1084
  async function showCompanyStatus(client, slug, asJson, outpostFlag) {
892
1085
  const company = await requireCompany(client, slug);
893
- const target = await requireCompanyOutpost(client, company, outpostFlag, "hq outposts status");
1086
+ const list = await client.listCompanyOutposts(company.uid);
1087
+ if (outpostFlag === undefined && !list.legacy && list.outposts.length > 0 &&
1088
+ list.outposts.length + (list.unreadable ?? 0) > 1) {
1089
+ showCompanyOutpostTable(company, list, asJson);
1090
+ return;
1091
+ }
1092
+ if (outpostFlag === undefined && list.outposts.length === 0 && (list.unreadable ?? 0) === 0 && list.viewerRole === "member") {
1093
+ console.error(`${company.slug} does not have an Outpost yet. ${noOutpostNext(company.slug, "member")}`);
1094
+ process.exit(1);
1095
+ }
1096
+ const target = selectCompanyOutpost(list, outpostFlag, "hq outposts status");
894
1097
  const status = await client.companyStatus(company.uid, target.outpostId);
895
1098
  const outpost = status.outpost ?? {};
1099
+ const role = readViewerRole(status) ?? list.viewerRole;
896
1100
  const registry = await client.listCompanyJobs(company.uid, target.outpostId);
897
1101
  let health = null;
898
1102
  let healthAvailable = false;
@@ -941,12 +1145,67 @@ async function showCompanyStatus(client, slug, asJson, outpostFlag) {
941
1145
  console.log(`State ${lifecycle}`);
942
1146
  if (instance)
943
1147
  console.log(`Instance ${instance}`);
944
- if (cleanedUp)
945
- console.log(failedCleanedUpLine(provisionRetryCommand(company.slug)));
1148
+ for (const line of blockedStatusLines(company.slug, outpost, role))
1149
+ console.log(line);
946
1150
  for (const line of describeCompanySignIn(company.slug, signIn))
947
1151
  console.log(line);
948
1152
  console.log("");
949
- printCompanyJobs(company.slug, jobs, healthAvailable);
1153
+ printCompanyJobs(company.slug, jobs, healthAvailable, role);
1154
+ }
1155
+ /** `status --company` with several Outposts and no --outpost: one row each. */
1156
+ function showCompanyOutpostTable(company, list, asJson) {
1157
+ const unreadable = list.unreadable ?? 0;
1158
+ if (asJson) {
1159
+ process.stdout.write(JSON.stringify({
1160
+ company: { slug: company.slug, uid: company.uid, ...(company.name ? { name: company.name } : {}) },
1161
+ outposts: list.outposts,
1162
+ ...(unreadable > 0 ? { unreadable } : {}),
1163
+ }, null, 2) + "\n");
1164
+ return;
1165
+ }
1166
+ console.log(`Company ${company.slug}${company.name ? ` (${company.name})` : ""}`);
1167
+ console.log(`Payer ${companyPayerLabel(company)}`);
1168
+ console.log("");
1169
+ printCompanyOutpostTable(list.outposts);
1170
+ if (unreadable > 0) {
1171
+ console.log(chalk.yellow(`${unreadable} more Outpost row(s) could not be read and are not shown.`));
1172
+ }
1173
+ console.log(chalk.dim(`Next: hq outposts status --company ${company.slug} --outpost <name> for one Outpost's detail and jobs.`));
1174
+ }
1175
+ /**
1176
+ * Lines for a blocked Outpost: what stopped it, the server's failure reason
1177
+ * when it sent one, and a next step this caller is allowed to take. A member
1178
+ * is never told to run provision.
1179
+ */
1180
+ function blockedStatusLines(slug, outpost, role) {
1181
+ if (outpost.lifecycle !== "blocked")
1182
+ return [];
1183
+ const lines = [];
1184
+ const failure = companyOutpostFailure(outpost);
1185
+ if (failure)
1186
+ lines.push(companyOutpostFailureLine(failure));
1187
+ const member = role === "member";
1188
+ const askAdmin = `Next: ask an owner or admin of ${slug}.`;
1189
+ switch (outpost.blockedReason) {
1190
+ case FAILED_CLEANED_UP:
1191
+ lines.push(member
1192
+ ? `The Outpost could not start and was cleaned up. Nothing was left running. Only an owner or admin can create it again. ${askAdmin}`
1193
+ : failedCleanedUpLine(provisionRetryCommand(slug)));
1194
+ break;
1195
+ case "not_started":
1196
+ lines.push(member
1197
+ ? `The create never started, so nothing was built. Only an owner or admin can create it again. ${askAdmin}`
1198
+ : `The create never started, so nothing was built. Next: ${provisionRetryCommand(slug)}`);
1199
+ break;
1200
+ case "billing_required":
1201
+ lines.push(member
1202
+ ? `Billing for ${slug} is blocked. ${askAdmin}`
1203
+ : `Billing for ${slug} is blocked. Next: check the company's billing in the console.`);
1204
+ break;
1205
+ default:
1206
+ lines.push(`The last change to this Outpost stopped partway and needs attention. Next: contact HQ support${failure ? ` with the reason above` : ""}.`);
1207
+ }
1208
+ return lines;
950
1209
  }
951
1210
  async function registerCompanyJobCommand(client, opts) {
952
1211
  const slug = opts.company ?? "";
@@ -1235,6 +1494,17 @@ async function resolveShellTarget(client, opts, command) {
1235
1494
  failCompany(opts.company, err, "status");
1236
1495
  }
1237
1496
  }
1497
+ /** A failed shell call. A refused company Outpost says how to get access instead of the raw server text. */
1498
+ function failShell(err, opts) {
1499
+ if (opts.company !== undefined && isCompanySlug(opts.company)) {
1500
+ const plain = explainCompanyShellRefusal(opts.company, opts.outpost, err);
1501
+ if (plain) {
1502
+ console.error(chalk.red(plain));
1503
+ process.exit(1);
1504
+ }
1505
+ }
1506
+ return fail(err);
1507
+ }
1238
1508
  /** The target flags for a follow-up command hint, such as ` --company acme`. */
1239
1509
  function shellTargetFlags(opts) {
1240
1510
  if (opts.company !== undefined) {
@@ -1243,7 +1513,7 @@ function shellTargetFlags(opts) {
1243
1513
  }
1244
1514
  return opts.id ? ` --id ${quoteShellArgument(opts.id)}` : "";
1245
1515
  }
1246
- const COMPANY_SHELL_OPTION = "Run on this company's Outpost (company owners and admins)";
1516
+ const COMPANY_SHELL_OPTION = "Run on this company's Outpost (owners, admins, and members approved for it; others: hq outposts request-access)";
1247
1517
  const COMPANY_SHELL_OUTPOST_OPTION = "Which company Outpost, when the company has more than one";
1248
1518
  const DEFAULT_EXEC_WAIT_TIMEOUT_SECONDS = 1800;
1249
1519
  // exec-stage has no accepted-file-size ceiling; budget 60s for setup plus 15s per MiB.
@@ -1360,14 +1630,14 @@ export function registerOutpostsCommand(program, deps) {
1360
1630
  outposts
1361
1631
  .command("provision")
1362
1632
  .alias("create")
1363
- .description("Provision a new Outpost (priced by size: small, medium, large or xlarge; requires --yes)")
1364
- .option("--size <size>", "Outpost size: small | medium | large | xlarge. Without it, a terminal shows a menu with prices; the default is $100/month")
1633
+ .description("Provision a new company or personal Outpost (priced by size: small, medium, large or xlarge)")
1634
+ .option("--size <size>", "Outpost size: small | medium | large | xlarge. Without it, a terminal shows a menu with prices and medium preselected; a script gets the default, $100/month")
1365
1635
  .option("--runtime <runtime>", "Agent runtime: claude | codex (default claude). Personal boxes only.")
1366
1636
  .option("--disk <gb>", "Root disk size in GB (EC2 only). Personal boxes only.")
1367
1637
  .option("--client-ip <ip>", "Your public IP for the box's SSH ingress (optional; server derives it otherwise). Personal boxes only.")
1368
- .option("--company <slug>", "Provision the company's Outpost instead of your personal box")
1369
- .option("--name <name>", "With --company: not sent. This server creates the company's main Outpost and does not take a name yet")
1370
- .option("--yes", "Confirm the monthly charge for the chosen size (required to provision or create)")
1638
+ .option("--company <slug>", "Provision an Outpost for this company. A company that already has one gets another")
1639
+ .option("--personal", "Provision your own personal Outpost")
1640
+ .option("--yes", "Confirm the monthly charge for the chosen size (required without a terminal)")
1371
1641
  .option("--json", "With --company, emit one JSON object. Progress goes to stderr.")
1372
1642
  .action(async function (opts) {
1373
1643
  try {
@@ -1375,35 +1645,14 @@ export function registerOutpostsCommand(program, deps) {
1375
1645
  console.error(chalk.red(invalidSizeMessage(opts.size)));
1376
1646
  process.exit(1);
1377
1647
  }
1378
- if (opts.name !== undefined && opts.company === undefined) {
1379
- console.error("--name names a company Outpost. Next: re-run with --company <slug> --name <name>.");
1648
+ if (opts.company !== undefined && opts.personal) {
1649
+ console.error("Use either --company or --personal, not both. Nothing was created. Next: re-run with just one of them.");
1380
1650
  process.exit(1);
1381
1651
  }
1382
- if (opts.company !== undefined && opts.name !== undefined) {
1383
- if (opts.runtime !== undefined || opts.disk !== undefined || opts.clientIp !== undefined) {
1384
- console.error("Those options are for a personal Outpost. Next: re-run with --company and --name, and leave out --runtime, --disk and --client-ip.");
1385
- process.exit(1);
1386
- }
1387
- try {
1388
- await createCompanyOutpostCommand(client, host, loadPricing, {
1389
- company: opts.company,
1390
- name: opts.name,
1391
- ...(opts.yes !== undefined ? { yes: opts.yes } : {}),
1392
- ...(opts.json ? { json: true } : {}),
1393
- ...(opts.size !== undefined ? { size: opts.size } : {}),
1394
- }, deps.companyProvisionWait);
1395
- }
1396
- catch (err) {
1397
- // The create already reported this and called process.exit.
1398
- if (err instanceof Error && err.message.startsWith("process.exit("))
1399
- throw err;
1400
- if (opts.json) {
1401
- process.stdout.write(companyProvisionFailureJson(opts.company, err));
1402
- process.exit(1);
1403
- }
1404
- failCompany(opts.company, err, "provision");
1405
- }
1406
- return;
1652
+ if (opts.company === undefined && !opts.personal) {
1653
+ const kind = await chooseOutpostKind(host, Boolean(opts.json));
1654
+ if (kind.kind === "company")
1655
+ opts.company = kind.slug;
1407
1656
  }
1408
1657
  if (opts.company !== undefined) {
1409
1658
  if (opts.runtime !== undefined || opts.disk !== undefined || opts.clientIp !== undefined) {
@@ -1450,15 +1699,22 @@ export function registerOutpostsCommand(program, deps) {
1450
1699
  process.exit(1);
1451
1700
  }
1452
1701
  }
1453
- // Paid gate: settle the size, print its monthly cost, and require
1454
- // --yes before the create call.
1702
+ // Paid gate: settle the size and its monthly cost, and confirm it
1703
+ // (--yes, or "yes" at a terminal) before the create call.
1455
1704
  const choice = await chooseOutpostSize(loadPricing, host, opts.size);
1456
- confirmChargeOrExit({
1705
+ const charge = {
1457
1706
  resource: "Outpost",
1458
1707
  unitCents: choice.priceCents,
1459
1708
  ...(choice.size ? { detail: `${choice.size} Outpost` } : {}),
1460
- yes: opts.yes,
1709
+ };
1710
+ const confirmed = await confirmOutpostCharge(host, {
1711
+ ...(opts.yes !== undefined ? { yes: opts.yes } : {}),
1712
+ json: false,
1713
+ refusal: chargeRefusalText(charge),
1714
+ prompt: `Create your personal Outpost? ${chargeConfirmedText(charge).replace(/^Confirmed: /, "")}`,
1461
1715
  });
1716
+ if (!confirmed)
1717
+ return;
1462
1718
  // The box authenticates AS the caller using the cached refresh token —
1463
1719
  // the same body the console sends. Never printed.
1464
1720
  const refreshToken = deps.loadCachedTokens()?.refreshToken;
@@ -1474,6 +1730,7 @@ export function registerOutpostsCommand(program, deps) {
1474
1730
  ...(agentRuntime ? { agentRuntime } : {}),
1475
1731
  ...(choice.size ? { size: choice.size } : {}),
1476
1732
  });
1733
+ console.log(chalk.dim(chargeConfirmedText(charge)));
1477
1734
  console.log(chalk.green("Provisioning started for your Outpost."));
1478
1735
  console.log(chalk.dim("Track it: hq outposts status"));
1479
1736
  }
@@ -1500,6 +1757,12 @@ export function registerOutpostsCommand(program, deps) {
1500
1757
  fail(err);
1501
1758
  }
1502
1759
  });
1760
+ registerCompanyAccessCommands(outposts, {
1761
+ client,
1762
+ host,
1763
+ requireCompany: (slug) => requireCompany(client, slug),
1764
+ failCompany: (slug, err) => failCompany(slug, err, "status"),
1765
+ });
1503
1766
  outposts
1504
1767
  .command("list")
1505
1768
  .description("List every Outpost you own, or a company's Outposts with --company")
@@ -1833,7 +2096,7 @@ export function registerOutpostsCommand(program, deps) {
1833
2096
  return;
1834
2097
  }
1835
2098
  catch (err) {
1836
- fail(err);
2099
+ failShell(err, opts);
1837
2100
  }
1838
2101
  });
1839
2102
  outposts
@@ -1878,7 +2141,7 @@ export function registerOutpostsCommand(program, deps) {
1878
2141
  }
1879
2142
  }
1880
2143
  catch (err) {
1881
- fail(err);
2144
+ failShell(err, opts);
1882
2145
  }
1883
2146
  });
1884
2147
  outposts
@@ -1922,7 +2185,7 @@ export function registerOutpostsCommand(program, deps) {
1922
2185
  }
1923
2186
  }
1924
2187
  catch (err) {
1925
- fail(err);
2188
+ failShell(err, opts);
1926
2189
  }
1927
2190
  });
1928
2191
  outposts
@@ -1955,7 +2218,7 @@ export function registerOutpostsCommand(program, deps) {
1955
2218
  }
1956
2219
  }
1957
2220
  catch (err) {
1958
- fail(err);
2221
+ failShell(err, opts);
1959
2222
  }
1960
2223
  });
1961
2224
  outposts
@@ -2067,7 +2330,7 @@ export function registerOutpostsCommand(program, deps) {
2067
2330
  console.error(chalk.red(err.message));
2068
2331
  process.exit(1);
2069
2332
  }
2070
- fail(err);
2333
+ failShell(err, opts);
2071
2334
  }
2072
2335
  });
2073
2336
  outposts