@indigoai-us/hq-cloud 6.18.86 → 6.18.88

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 (65) hide show
  1. package/dist/bin/sync-runner-company.d.ts.map +1 -1
  2. package/dist/bin/sync-runner-company.js +16 -0
  3. package/dist/bin/sync-runner-company.js.map +1 -1
  4. package/dist/bin/sync-runner.d.ts +5 -0
  5. package/dist/bin/sync-runner.d.ts.map +1 -1
  6. package/dist/bin/sync-runner.js.map +1 -1
  7. package/dist/cli/reconcile-skip-reason.d.ts +23 -0
  8. package/dist/cli/reconcile-skip-reason.d.ts.map +1 -0
  9. package/dist/cli/reconcile-skip-reason.js +60 -0
  10. package/dist/cli/reconcile-skip-reason.js.map +1 -0
  11. package/dist/cli/rescue-core.d.ts +16 -1
  12. package/dist/cli/rescue-core.d.ts.map +1 -1
  13. package/dist/cli/rescue-core.js +83 -27
  14. package/dist/cli/rescue-core.js.map +1 -1
  15. package/dist/cli/share.d.ts +31 -1
  16. package/dist/cli/share.d.ts.map +1 -1
  17. package/dist/cli/share.js +193 -28
  18. package/dist/cli/share.js.map +1 -1
  19. package/dist/cli/sync.d.ts +36 -2
  20. package/dist/cli/sync.d.ts.map +1 -1
  21. package/dist/cli/sync.js +135 -27
  22. package/dist/cli/sync.js.map +1 -1
  23. package/dist/local-link-warning.d.ts +48 -0
  24. package/dist/local-link-warning.d.ts.map +1 -0
  25. package/dist/local-link-warning.js +138 -0
  26. package/dist/local-link-warning.js.map +1 -0
  27. package/dist/object-io.d.ts +16 -1
  28. package/dist/object-io.d.ts.map +1 -1
  29. package/dist/object-io.js +31 -9
  30. package/dist/object-io.js.map +1 -1
  31. package/dist/outposts/cli-billing.d.ts +2 -0
  32. package/dist/outposts/cli-billing.d.ts.map +1 -1
  33. package/dist/outposts/cli-billing.js +13 -1
  34. package/dist/outposts/cli-billing.js.map +1 -1
  35. package/dist/outposts/client.d.ts +29 -6
  36. package/dist/outposts/client.d.ts.map +1 -1
  37. package/dist/outposts/client.js +83 -18
  38. package/dist/outposts/client.js.map +1 -1
  39. package/dist/outposts/command.d.ts +8 -4
  40. package/dist/outposts/command.d.ts.map +1 -1
  41. package/dist/outposts/command.js +713 -62
  42. package/dist/outposts/command.js.map +1 -1
  43. package/dist/outposts/company-outposts.d.ts +92 -0
  44. package/dist/outposts/company-outposts.d.ts.map +1 -0
  45. package/dist/outposts/company-outposts.js +194 -0
  46. package/dist/outposts/company-outposts.js.map +1 -0
  47. package/dist/outposts/company.d.ts +67 -9
  48. package/dist/outposts/company.d.ts.map +1 -1
  49. package/dist/outposts/company.js +175 -11
  50. package/dist/outposts/company.js.map +1 -1
  51. package/dist/outposts/errors.d.ts +7 -0
  52. package/dist/outposts/errors.d.ts.map +1 -1
  53. package/dist/outposts/errors.js +7 -0
  54. package/dist/outposts/errors.js.map +1 -1
  55. package/dist/s3.d.ts +7 -1
  56. package/dist/s3.d.ts.map +1 -1
  57. package/dist/s3.js +33 -12
  58. package/dist/s3.js.map +1 -1
  59. package/dist/sync-progress.d.ts.map +1 -1
  60. package/dist/sync-progress.js +3 -0
  61. package/dist/sync-progress.js.map +1 -1
  62. package/dist/vault-client.d.ts.map +1 -1
  63. package/dist/vault-client.js +5 -1
  64. package/dist/vault-client.js.map +1 -1
  65. package/package.json +1 -1
@@ -9,15 +9,19 @@
9
9
  *
10
10
  * Personal Outposts are caller-scoped: hq-pro keys those `/outpost/*` calls on
11
11
  * the caller's Cognito sub. `--company <slug>` switches the same provision and
12
- * status commands onto the company Outpost, and `outposts jobs register` sends
13
- * a company job for server acceptance. `--id <outpostId>` still selects a
14
- * personal box; when omitted, personal calls target the caller's primary slot.
12
+ * status commands onto the company Outpost. `outposts jobs` registers, edits,
13
+ * pauses, resumes, deletes, and runs a company job. `--id <outpostId>` still
14
+ * selects a personal box; when omitted, personal calls target the caller's primary slot.
15
15
  *
16
16
  * Subcommands:
17
17
  * outposts provision [--company] — provision a box (paid; requires --yes)
18
18
  * outposts list — every personal Outpost you own
19
+ * 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
+ * --outpost <name|id> - picks a company Outpost on status, login, login-code
22
+ * and jobs register; optional when there is only one
19
23
  * outposts status [--id|--company] — live detail for one box
20
- * outposts jobs register — register a company job, print its revision
24
+ * outposts jobs — register, edit, pause, resume, delete, run-now
21
25
  * outposts exec <command...> — run a command on the box (sync/async/detach)
22
26
  * outposts exec-stage — presign an input upload for an async command
23
27
  * outposts exec-submit <cmd...> — fire-and-forget async submit
@@ -38,7 +42,8 @@
38
42
  import chalk from "chalk";
39
43
  import * as fs from "node:fs";
40
44
  import { OUTPOST_PRICE_CENTS } from "./billing.js";
41
- import { buildCompanyJobDefinition, companyPayerLabel, companyProvisionProgress, CompanyTargetError, describeCompanySignIn, explainCompanyFailure, isCompanySlug, parseCompanySignIn, isProvisionOutcomeUnknown, mergeCompanyJobs, } from "./company.js";
45
+ import { buildCompanyJobDefinition, mergeCompanyJobEdit, companyPayerLabel, companyProvisionProgress, CompanyTargetError, JobDefinitionError, describeCompanySignIn, explainCompanyFailure, isCompanySlug, parseCompanySignIn, companyCreateContinues, isProvisionOutcomeUnknown, mergeCompanyJobs, provisionErrorSkipsStatusRead, } from "./company.js";
46
+ import { companyOutpostChargeLine, companyOutpostsUnreadableLine, CompanyOutpostSelectError, explainCompanyOutpostCreateFailure, explainCompanyOutpostSelect, isCompanyOutpostId, isOutpostName, LEGACY_OUTPOST_NAME, safeLifecycle, selectCompanyOutpost, } from "./company-outposts.js";
42
47
  import { confirmChargeOrExit, confirmCompanyOutpostChargeOrExit, surfaceBillingBlocked, } from "./cli-billing.js";
43
48
  import { EXEC_MAX_TIMEOUT_SECONDS, OutpostsClient, } from "./client.js";
44
49
  import { OutpostExecWaitError, OutpostHttpError } from "./errors.js";
@@ -77,8 +82,39 @@ function fail(err) {
77
82
  }
78
83
  process.exit(1);
79
84
  }
80
- function failCompany(slug, err, intent) {
81
- console.error(explainCompanyFailure(slug, err, intent));
85
+ function companyFailureCode(err) {
86
+ if (err instanceof CompanyOutpostSelectError)
87
+ return err.reason;
88
+ if (err instanceof OutpostHttpError) {
89
+ if (err.code)
90
+ return err.code;
91
+ if (err.status === 403)
92
+ return "admin_required";
93
+ if (err.status === 401)
94
+ return "unauthorized";
95
+ }
96
+ if (err instanceof JobDefinitionError)
97
+ return "invalid_definition";
98
+ if (err instanceof CompanyTargetError)
99
+ return err.reason;
100
+ return "request_failed";
101
+ }
102
+ function failCompany(slug, err, intent, json) {
103
+ const message = err instanceof CompanyOutpostSelectError
104
+ ? explainCompanyOutpostSelect(isCompanySlug(slug) ? slug : "that company", err)
105
+ : explainCompanyFailure(slug, err, intent, json?.jobId);
106
+ if (json) {
107
+ process.stdout.write(JSON.stringify({
108
+ ok: false,
109
+ action: json.action,
110
+ jobId: json.jobId,
111
+ code: companyFailureCode(err),
112
+ message,
113
+ }) + "\n");
114
+ }
115
+ else {
116
+ console.error(message);
117
+ }
82
118
  process.exit(1);
83
119
  }
84
120
  async function requireCompany(client, slug) {
@@ -96,6 +132,151 @@ async function requireCompany(client, slug) {
96
132
  throw err;
97
133
  }
98
134
  }
135
+ /**
136
+ * The Outpost a company command acts on. `--outpost` is optional when the
137
+ * company has one Outpost. The legacy Outpost has no outpostId, so callers
138
+ * send none and older servers see the request they always did.
139
+ */
140
+ async function requireCompanyOutpost(client, company, flag, command) {
141
+ return selectCompanyOutpost(await client.listCompanyOutposts(company.uid), flag, command);
142
+ }
143
+ /** Exit when --outpost is passed without --company. */
144
+ function rejectOutpostWithoutCompany(opts) {
145
+ if (opts.outpost !== undefined && opts.company === undefined) {
146
+ console.error(explainCompanyOutpostSelect("", new CompanyOutpostSelectError("needs_company")));
147
+ process.exit(1);
148
+ }
149
+ }
150
+ /** " --outpost <name>" for next-step hints, only when the company has a choice to make. */
151
+ function outpostHint(outpost, passed) {
152
+ return passed !== undefined ? ` --outpost ${outpost.name}` : "";
153
+ }
154
+ /**
155
+ * `hq outposts list` is the only command that reads status after a rejected
156
+ * list query, and only to print the legacy row's state. The id from that
157
+ * read is not kept, so later commands still omit `outpostId`.
158
+ */
159
+ async function legacyListWithLifecycle(client, companyUid, list) {
160
+ const row = list.outposts[0];
161
+ if (!list.legacy || list.outposts.length !== 1 || !row || row.lifecycle)
162
+ return list;
163
+ try {
164
+ const status = await client.companyStatus(companyUid);
165
+ const lifecycle = safeLifecycle(status.outpost?.lifecycle);
166
+ if (!lifecycle)
167
+ return list;
168
+ return { ...list, outposts: [{ ...row, lifecycle }] };
169
+ }
170
+ catch (err) {
171
+ // Only the server's coded "no Outpost" answer is an empty list. A codeless
172
+ // 404 is not proof, so it fails instead of suggesting a billed create.
173
+ if (err instanceof OutpostHttpError && err.status === 404 && err.code === "not_found") {
174
+ return { outposts: [], legacy: true };
175
+ }
176
+ throw err;
177
+ }
178
+ }
179
+ async function listCompanyOutpostsCommand(client, slug, asJson) {
180
+ const company = await requireCompany(client, slug);
181
+ const list = await legacyListWithLifecycle(client, company.uid, await client.listCompanyOutposts(company.uid));
182
+ const unreadable = list.unreadable ?? 0;
183
+ // Every row unreadable is not "no Outpost": fail instead of an empty list or the create hint.
184
+ if (list.outposts.length === 0 && unreadable > 0) {
185
+ console.error(companyOutpostsUnreadableLine(company.slug));
186
+ process.exit(1);
187
+ }
188
+ if (asJson) {
189
+ process.stdout.write(JSON.stringify({ company: company.slug, legacy: list.legacy, outposts: list.outposts, ...(unreadable > 0 ? { unreadable } : {}) }, null, 2) + "\n");
190
+ return;
191
+ }
192
+ if (list.outposts.length === 0) {
193
+ console.log(`${company.slug} does not have an Outpost yet.`);
194
+ console.log(`Next: hq outposts provision --company ${company.slug}`);
195
+ return;
196
+ }
197
+ const nameW = Math.max(4, ...list.outposts.map((o) => o.name.length));
198
+ const idW = Math.max(2, ...list.outposts.map((o) => (o.outpostId ?? "").length));
199
+ console.log(chalk.bold(["NAME".padEnd(nameW), "ID".padEnd(idW), "STATE"].join(" ")));
200
+ for (const o of list.outposts) {
201
+ console.log([
202
+ o.name.padEnd(nameW),
203
+ (o.outpostId ?? "").padEnd(idW),
204
+ o.lifecycle ?? "",
205
+ ].join(" "));
206
+ }
207
+ if (list.legacy) {
208
+ console.log(chalk.dim(`${company.slug} has one Outpost, shown as ${LEGACY_OUTPOST_NAME}.`));
209
+ }
210
+ if (unreadable > 0) {
211
+ console.log(chalk.yellow(`${unreadable} more Outpost row(s) could not be read and are not shown.`));
212
+ }
213
+ }
214
+ async function createCompanyOutpostCommand(client, host, opts, wait = {}) {
215
+ const json = opts.json === true;
216
+ const name = opts.name?.trim() ?? "";
217
+ if (!isOutpostName(name)) {
218
+ console.error("An Outpost needs a name of 1 to 32 lowercase letters, digits or dashes, such as research. " +
219
+ `Next: re-run with --company ${isCompanySlug(opts.company) ? opts.company : "<slug>"} --name <name>.`);
220
+ if (json) {
221
+ writeCompanyProvisionJson({ ok: false, company: opts.company, state: "not_created", reason: "invalid_name" });
222
+ }
223
+ process.exit(1);
224
+ }
225
+ let company;
226
+ try {
227
+ company = await requireCompany(client, opts.company);
228
+ }
229
+ catch (err) {
230
+ if (err && typeof err === "object")
231
+ failedBeforeCreate.add(err);
232
+ throw err;
233
+ }
234
+ const charge = companyOutpostChargeLine(companyPayerLabel(company));
235
+ const unnamed = `The name ${name} is not sent. This server creates the company's main Outpost.`;
236
+ if (!opts.yes) {
237
+ if (!host.isStdinTty()) {
238
+ console.error(`Creating ${company.slug}'s main Outpost costs ${charge}. ${unnamed} ` +
239
+ `Next: re-run with --yes to confirm this charge.`);
240
+ if (json) {
241
+ writeCompanyProvisionJson({
242
+ ok: false,
243
+ company: company.slug,
244
+ state: "not_created",
245
+ reason: "confirmation_required",
246
+ });
247
+ }
248
+ process.exit(1);
249
+ }
250
+ // In --json the prompt goes to stderr so stdout stays one object.
251
+ const prompt = `Create ${company.slug}'s main Outpost? ${charge}. ${unnamed} Type yes to confirm: `;
252
+ if (json)
253
+ process.stderr.write(prompt);
254
+ else
255
+ process.stdout.write(prompt);
256
+ if (!(await host.confirm())) {
257
+ if (json) {
258
+ console.error("Nothing was created or billed.");
259
+ writeCompanyProvisionJson({
260
+ ok: false,
261
+ company: company.slug,
262
+ state: "not_created",
263
+ reason: "confirmation_declined",
264
+ });
265
+ }
266
+ else {
267
+ console.log("Nothing was created or billed.");
268
+ }
269
+ return;
270
+ }
271
+ }
272
+ else {
273
+ provisionProgress(json, `Confirmed: ${charge}. ${unnamed}`);
274
+ }
275
+ await startCompanyOutpost(client, company, wait, {
276
+ json,
277
+ explainRefusal: (err) => explainCompanyOutpostCreateFailure(company.slug, err),
278
+ });
279
+ }
99
280
  function printCompanyJobs(companySlug, jobs, healthAvailable) {
100
281
  if (jobs.length === 0) {
101
282
  console.log("No company jobs yet.");
@@ -108,116 +289,309 @@ function printCompanyJobs(companySlug, jobs, healthAvailable) {
108
289
  console.log(["JOB", "LAST RUN", "NEXT RUN", "STATUS"].join(" "));
109
290
  for (const job of jobs) {
110
291
  console.log([job.jobId, job.lastRunAt ?? "none", job.nextRunAt ?? "none", job.status].join(" "));
292
+ if (job.message)
293
+ console.log(` ${job.message}`);
294
+ if (job.nextStep)
295
+ console.log(` Next: ${job.nextStep}`);
111
296
  }
112
297
  }
113
298
  const COMPANY_PROVISION_POLL_MS = 5_000;
114
299
  // The create Lambda's own timeout is 600s.
115
300
  const COMPANY_PROVISION_MAX_WAIT_MS = 600_000;
116
301
  const COMPANY_PROVISION_PROGRESS_EVERY_MS = 30_000;
117
- async function provisionCompanyOutpost(client, slug, yes, wait = {}) {
118
- const company = await requireCompany(client, slug);
302
+ function writeCompanyProvisionJson(body) {
303
+ const payload = {
304
+ ok: body.ok,
305
+ company: body.company,
306
+ state: body.state,
307
+ };
308
+ if (body.outpostId)
309
+ payload.outpostId = body.outpostId;
310
+ if (body.code)
311
+ payload.code = body.code;
312
+ if (body.reason)
313
+ payload.reason = body.reason;
314
+ process.stdout.write(JSON.stringify(payload) + "\n");
315
+ }
316
+ /** Errors thrown before the create request was sent, so nothing can exist. */
317
+ const failedBeforeCreate = new WeakSet();
318
+ function companyProvisionFailureJson(company, err) {
319
+ if (err instanceof CompanyTargetError) {
320
+ return JSON.stringify({
321
+ ok: false,
322
+ company,
323
+ state: "not_created",
324
+ reason: err.reason,
325
+ }) + "\n";
326
+ }
327
+ const code = err instanceof OutpostHttpError ? err.code : undefined;
328
+ const reason = code ?? "request_failed";
329
+ let state = "unconfirmed";
330
+ if (err && typeof err === "object" && failedBeforeCreate.has(err))
331
+ state = "not_created";
332
+ else if (code === "already_exists" || code === "billing_required")
333
+ state = "blocked";
334
+ else if (code === "feature_disabled" ||
335
+ code === "unavailable" ||
336
+ code === "dependencies_unavailable" ||
337
+ code === "unauthorized" ||
338
+ code === "forbidden" ||
339
+ code === "admin_required" ||
340
+ (typeof code === "string" && code.startsWith("invalid_"))) {
341
+ state = "not_created";
342
+ }
343
+ return JSON.stringify({
344
+ ok: false,
345
+ company,
346
+ state,
347
+ ...(code ? { code } : {}),
348
+ reason,
349
+ }) + "\n";
350
+ }
351
+ function provisionProgress(json, line) {
352
+ if (json)
353
+ console.error(chalk.dim(line));
354
+ else
355
+ console.log(chalk.dim(line));
356
+ }
357
+ function correlationFrom(outpost, err) {
358
+ const fromError = err instanceof OutpostHttpError ? err : undefined;
359
+ const attemptId = typeof outpost?.attemptId === "string" ? outpost.attemptId : fromError?.attemptId;
360
+ const operationId = typeof outpost?.operationId === "string" ? outpost.operationId : fromError?.operationId;
361
+ return {
362
+ ...(attemptId ? { attemptId } : {}),
363
+ ...(operationId ? { operationId } : {}),
364
+ };
365
+ }
366
+ async function provisionCompanyOutpost(client, slug, yes, wait = {}, json = false) {
367
+ let company;
368
+ try {
369
+ company = await requireCompany(client, slug);
370
+ }
371
+ catch (err) {
372
+ if (err && typeof err === "object")
373
+ failedBeforeCreate.add(err);
374
+ throw err;
375
+ }
119
376
  confirmCompanyOutpostChargeOrExit({
120
377
  slug: company.slug,
121
378
  payerLabel: companyPayerLabel(company),
122
379
  yes,
380
+ json,
123
381
  });
382
+ await startCompanyOutpost(client, company, wait, { json });
383
+ }
384
+ /**
385
+ * Send the create, then report what status shows. `provision --company` and
386
+ * `create --company --name` both use this, so neither prints "not created"
387
+ * for a create that may still be running.
388
+ *
389
+ * A refusal from {@link provisionErrorSkipsStatusRead} is a real answer:
390
+ * `explainRefusal` may give its plain line (not in `--json`), otherwise it
391
+ * is rethrown for the command's error handler. Any other error, such as a
392
+ * codeless 5xx (API Gateway's 30s cut-off on a create that keeps running),
393
+ * `503 outcome_unknown`, a coded 5xx, a dropped connection or an unreadable
394
+ * body, says nothing final about whether the box exists, so status is read.
395
+ * With `json`, progress goes to stderr and stdout gets one object.
396
+ */
397
+ async function startCompanyOutpost(client, company, wait, opts = {}) {
398
+ const json = opts.json === true;
124
399
  let outpost;
400
+ let provisionError;
125
401
  try {
126
402
  outpost = (await client.provisionCompany(company.uid)).outpost;
127
403
  }
128
404
  catch (err) {
129
- // A codeless 5xx (API Gateway's 30s cut-off on a create that keeps
130
- // running), a dropped connection or an unreadable body says nothing about
131
- // whether the box exists. Re-read status instead of reporting a failure.
132
- if (!isProvisionOutcomeUnknown(err))
405
+ // A refusal or a coded "nothing changed" answer is final.
406
+ // Anything else may have created the box. Poll status before any failure text.
407
+ // A failed read, a single 404, or a timeout stays unconfirmed and keeps this error.
408
+ if (provisionErrorSkipsStatusRead(err)) {
409
+ const plain = opts.json ? undefined : opts.explainRefusal?.(err);
410
+ if (plain) {
411
+ console.error(plain);
412
+ process.exit(1);
413
+ }
133
414
  throw err;
134
- console.log(chalk.dim("The create request did not return a result in time. Checking status..."));
415
+ }
416
+ provisionError = err;
417
+ const line = isProvisionOutcomeUnknown(err)
418
+ ? "The create request did not return a result in time. Checking status..."
419
+ : "The create request returned an error. Checking status...";
420
+ provisionProgress(json, line);
135
421
  }
136
- const id = typeof outpost?.outpostId === "string" ? outpost.outpostId : undefined;
137
- const finished = await waitForCompanyOutpost(client, company.uid, outpost, wait);
422
+ const code = provisionError instanceof OutpostHttpError ? provisionError.code : undefined;
423
+ const finished = await waitForCompanyOutpost(client, company.uid, outpost, wait, {
424
+ json,
425
+ correlation: correlationFrom(outpost, provisionError),
426
+ trustInitial: outpost !== undefined,
427
+ announceInProgress: provisionError !== undefined,
428
+ });
429
+ // The id goes into a terminal line and JSON, so only a printable one is shown.
430
+ const rawId = finished.outpostId ?? outpost?.outpostId;
431
+ const id = typeof rawId === "string" && isCompanyOutpostId(rawId) ? rawId : undefined;
138
432
  const label = `${company.slug}'s Outpost${id ? ` (${id})` : ""}`;
139
433
  if (finished.state === "ready") {
434
+ if (json) {
435
+ writeCompanyProvisionJson({
436
+ ok: true,
437
+ company: company.slug,
438
+ state: "ready",
439
+ ...(id ? { outpostId: id } : {}),
440
+ });
441
+ return;
442
+ }
140
443
  console.log(chalk.green(`${label} is ready.`));
141
444
  console.log(chalk.dim(`Next: hq outposts status --company ${company.slug}`));
142
445
  return;
143
446
  }
144
447
  if (finished.state === "blocked") {
145
- console.error(finished.reason === "not_started"
146
- ? `${label} was not created; nothing was built. Next: re-run hq outposts provision --company ${company.slug} to try again.`
147
- : finished.reason === "billing_required"
148
- ? `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}.`
149
- : `${label} stopped while provisioning and needs attention. Next: hq outposts status --company ${company.slug}, and contact support before retrying.`);
448
+ const notCreated = finished.reason === "not_started";
449
+ if (json) {
450
+ writeCompanyProvisionJson({
451
+ ok: false,
452
+ company: company.slug,
453
+ state: notCreated ? "not_created" : "blocked",
454
+ ...(id ? { outpostId: id } : {}),
455
+ ...(code ? { code } : {}),
456
+ ...(finished.reason ? { reason: finished.reason } : {}),
457
+ });
458
+ }
459
+ else if (notCreated) {
460
+ console.error(`${label} was not created; nothing was built. Next: re-run hq outposts provision --company ${company.slug} to try again.`);
461
+ }
462
+ else if (finished.reason === "billing_required") {
463
+ 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}.`);
464
+ }
465
+ else {
466
+ console.error(`${label} stopped while provisioning and needs attention. Next: hq outposts status --company ${company.slug}, and contact support before retrying.`);
467
+ }
150
468
  // exitCode, not exit(): the action's catch must not add a second message.
151
469
  process.exitCode = 1;
152
470
  return;
153
471
  }
154
472
  if (finished.state === "unconfirmed") {
155
- console.error(`The result of the create request could not be confirmed; no Outpost status was readable for ${company.slug}. Next: hq outposts status --company ${company.slug} before retrying.`);
473
+ console.error(finished.signInFailed
474
+ ? `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.`
475
+ : `The result of the create request could not be confirmed. Next: run hq outposts status --company ${company.slug} first, before retrying.`);
476
+ if (json) {
477
+ writeCompanyProvisionJson({
478
+ ok: false,
479
+ company: company.slug,
480
+ state: "unconfirmed",
481
+ ...(id ? { outpostId: id } : {}),
482
+ ...(code ? { code } : {}),
483
+ reason: code ?? "unconfirmed",
484
+ });
485
+ }
156
486
  process.exitCode = 1;
157
487
  return;
158
488
  }
489
+ if (json) {
490
+ writeCompanyProvisionJson({
491
+ ok: true,
492
+ company: company.slug,
493
+ state: "pending",
494
+ ...(id ? { outpostId: id } : {}),
495
+ });
496
+ return;
497
+ }
159
498
  console.log(chalk.yellow(`Provisioning started for ${label}; it is not ready yet. Check it with: hq outposts status --company ${company.slug}`));
160
499
  }
500
+ function rowBelongsToCreate(outpost, poll) {
501
+ if (!outpost)
502
+ return false;
503
+ if (poll.correlation.attemptId || poll.correlation.operationId) {
504
+ return companyCreateContinues(outpost, poll.correlation);
505
+ }
506
+ if (poll.trustInitial)
507
+ return true;
508
+ return companyCreateContinues(outpost, {});
509
+ }
161
510
  /**
162
511
  * Poll company status until the box is ready or blocked, or the wait runs out.
163
- * Status read errors are retried; they do not change the outcome.
512
+ * Any status-read error, or a row that is not this create, is "not yet".
513
+ * Only an adopted row can end the wait.
164
514
  */
165
- async function waitForCompanyOutpost(client, companyUid, initial, wait) {
515
+ async function waitForCompanyOutpost(client, companyUid, initial, wait, poll) {
166
516
  const pollMs = wait.pollMs ?? COMPANY_PROVISION_POLL_MS;
167
517
  const maxWaitMs = wait.maxWaitMs ?? COMPANY_PROVISION_MAX_WAIT_MS;
168
518
  const pause = wait.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
169
519
  const now = wait.now ?? Date.now;
520
+ let outpostId = typeof initial?.outpostId === "string" ? initial.outpostId : undefined;
170
521
  let progress = initial ? companyProvisionProgress(initial) : undefined;
171
- if (progress && progress.state !== "pending")
172
- return progress;
522
+ let announced = false;
523
+ const announce = (state) => {
524
+ if (announced || !poll.announceInProgress || state.state !== "pending")
525
+ return;
526
+ announced = true;
527
+ const line = "Status shows a create in progress.";
528
+ if (poll.json)
529
+ console.error(line);
530
+ else
531
+ console.log(line);
532
+ };
533
+ if (progress && progress.state !== "pending") {
534
+ return outpostId ? { ...progress, outpostId } : progress;
535
+ }
536
+ if (progress?.state === "pending")
537
+ announce(progress);
173
538
  const started = now();
174
539
  let lastLifecycle = progress?.state === "pending" ? progress.lifecycle : undefined;
175
540
  let lastProgressAt = started;
176
541
  let anyRead = initial !== undefined;
177
542
  for (;;) {
178
543
  if (now() - started >= maxWaitMs) {
179
- return anyRead ? { state: "pending" } : { state: "unconfirmed" };
544
+ if (anyRead && progress)
545
+ return outpostId ? { ...progress, outpostId } : progress;
546
+ return outpostId ? { state: "unconfirmed", outpostId } : { state: "unconfirmed" };
180
547
  }
181
548
  await pause(pollMs);
182
549
  try {
550
+ // No outpostId: the deployed server rejects it with 400 invalid_body
551
+ // until hq-pro-agents #1217 ships. Rows are matched by attempt id instead.
183
552
  const status = await client.companyStatus(companyUid);
553
+ if (!rowBelongsToCreate(status.outpost, poll))
554
+ continue;
184
555
  progress = companyProvisionProgress(status.outpost);
185
556
  anyRead = true;
557
+ if (typeof status.outpost?.outpostId === "string")
558
+ outpostId = status.outpost.outpostId;
186
559
  }
187
560
  catch (err) {
188
- // Not found yet, a codeless 5xx or a network failure: keep waiting.
189
- // Auth and other client errors will not fix themselves; surface them.
190
- if (err instanceof OutpostHttpError &&
191
- err.status >= 400 &&
192
- err.status < 500 &&
193
- err.status !== 404) {
194
- throw err;
561
+ // A create was already sent, so no status-read error proves what happened.
562
+ // A sign-in failure will not fix itself: stop now, still unconfirmed.
563
+ if (err instanceof OutpostHttpError && (err.status === 401 || err.status === 403)) {
564
+ return { state: "unconfirmed", signInFailed: true, ...(outpostId ? { outpostId } : {}) };
195
565
  }
566
+ // Anything else is "not yet"; the timeout ends unconfirmed with the create's own error.
196
567
  continue;
197
568
  }
198
- if (progress.state !== "pending")
199
- return progress;
569
+ if (!progress || progress.state !== "pending") {
570
+ return outpostId && progress ? { ...progress, outpostId } : progress ?? { state: "unconfirmed" };
571
+ }
572
+ announce(progress);
200
573
  const elapsed = Math.round((now() - started) / 1000);
201
574
  if (progress.lifecycle !== lastLifecycle) {
202
575
  lastLifecycle = progress.lifecycle;
203
576
  lastProgressAt = now();
204
- console.log(chalk.dim(`Outpost is ${progress.lifecycle ?? "being created"} (${elapsed}s).`));
577
+ provisionProgress(poll.json, `Outpost is ${progress.lifecycle ?? "being created"} (${elapsed}s).`);
205
578
  }
206
579
  else if (now() - lastProgressAt >= COMPANY_PROVISION_PROGRESS_EVERY_MS) {
207
580
  lastProgressAt = now();
208
- console.log(chalk.dim(`Still ${progress.lifecycle ?? "provisioning"} (${elapsed}s).`));
581
+ provisionProgress(poll.json, `Still ${progress.lifecycle ?? "provisioning"} (${elapsed}s).`);
209
582
  }
210
583
  }
211
584
  }
212
- async function showCompanyStatus(client, slug, asJson) {
585
+ async function showCompanyStatus(client, slug, asJson, outpostFlag) {
213
586
  const company = await requireCompany(client, slug);
214
- const status = await client.companyStatus(company.uid);
587
+ const target = await requireCompanyOutpost(client, company, outpostFlag, "hq outposts status");
588
+ const status = await client.companyStatus(company.uid, target.outpostId);
215
589
  const outpost = status.outpost ?? {};
216
- const registry = await client.listCompanyJobs(company.uid);
590
+ const registry = await client.listCompanyJobs(company.uid, target.outpostId);
217
591
  let health = null;
218
592
  let healthAvailable = false;
219
593
  try {
220
- health = await client.companyJobHealth(company.uid);
594
+ health = await client.companyJobHealth(company.uid, target.outpostId);
221
595
  healthAvailable = true;
222
596
  }
223
597
  catch (err) {
@@ -228,7 +602,7 @@ async function showCompanyStatus(client, slug, asJson) {
228
602
  const jobs = mergeCompanyJobs(registry, health);
229
603
  let signIn = { signedIn: false, state: "unknown" };
230
604
  try {
231
- signIn = parseCompanySignIn(await client.companySignIn(company.uid, "status"));
605
+ signIn = parseCompanySignIn(await client.companySignIn(company.uid, "status", undefined, target.outpostId));
232
606
  }
233
607
  catch (err) {
234
608
  // An older server has no sign-in route: unknown. A non-admin is told why.
@@ -239,6 +613,7 @@ async function showCompanyStatus(client, slug, asJson) {
239
613
  if (asJson) {
240
614
  process.stdout.write(JSON.stringify({
241
615
  company: { slug: company.slug, uid: company.uid, ...(company.name ? { name: company.name } : {}) },
616
+ outpostName: target.name,
242
617
  outpost,
243
618
  jobs,
244
619
  jobHealth: healthAvailable ? "available" : "unavailable",
@@ -254,7 +629,7 @@ async function showCompanyStatus(client, slug, asJson) {
254
629
  : "";
255
630
  console.log(`Company ${company.slug}${company.name ? ` (${company.name})` : ""}`);
256
631
  console.log(`Payer ${companyPayerLabel(company)}`);
257
- console.log(`Outpost ${outpostId}`);
632
+ console.log(`Outpost ${target.name}${outpostId ? ` (${outpostId})` : ""}`);
258
633
  console.log(`State ${lifecycle}`);
259
634
  if (instance)
260
635
  console.log(`Instance ${instance}`);
@@ -267,13 +642,14 @@ async function registerCompanyJobCommand(client, opts) {
267
642
  const slug = opts.company ?? "";
268
643
  const definition = buildCompanyJobDefinition(opts);
269
644
  const company = await requireCompany(client, slug);
645
+ const target = await requireCompanyOutpost(client, company, opts.outpost, "hq outposts jobs register");
270
646
  if (definition.schedule.kind === "recurring" &&
271
647
  opts.cron !== undefined &&
272
648
  definition.schedule.cron !== opts.cron.trim() &&
273
649
  !opts.json) {
274
650
  console.log(`Using schedule ${definition.schedule.cron} for --cron "${opts.cron.trim()}".`);
275
651
  }
276
- const created = await client.registerCompanyJob(company.uid, definition);
652
+ const created = await client.registerCompanyJob(company.uid, definition, target.outpostId);
277
653
  const jobId = created.job?.jobId;
278
654
  const revision = created.job?.acceptedRevision;
279
655
  if (!jobId || !revision) {
@@ -281,12 +657,184 @@ async function registerCompanyJobCommand(client, opts) {
281
657
  process.exit(1);
282
658
  }
283
659
  if (opts.json) {
284
- process.stdout.write(JSON.stringify({ jobId, acceptedRevision: revision, company: company.slug }, null, 2) + "\n");
660
+ process.stdout.write(JSON.stringify({ jobId, acceptedRevision: revision, company: company.slug, outpost: target.name }, null, 2) + "\n");
285
661
  return;
286
662
  }
287
- console.log(`Registered ${jobId} for ${company.slug}.`);
663
+ console.log(`Registered ${jobId} for ${company.slug} on Outpost ${target.name}.`);
288
664
  console.log(`Accepted revision: ${revision}`);
289
665
  }
666
+ const COMPANY_JOB_WIRE = {
667
+ edit: "update",
668
+ pause: "disable",
669
+ resume: "enable",
670
+ delete: "delete",
671
+ "run-now": "run-now",
672
+ };
673
+ const COMPANY_JOB_ID = /^job_[A-Za-z0-9]+$/;
674
+ const SAFE_TOKEN = /^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$/;
675
+ function safeToken(value) {
676
+ return typeof value === "string" && SAFE_TOKEN.test(value) ? value : undefined;
677
+ }
678
+ function stopCompanyJob(message, stop, code) {
679
+ if (stop.json) {
680
+ process.stdout.write(JSON.stringify({ ok: false, action: stop.action, jobId: stop.jobId, code, message }) + "\n");
681
+ }
682
+ else {
683
+ console.error(message);
684
+ }
685
+ process.exitCode = 1;
686
+ }
687
+ function deleteRerunLine(slug, outpostFlag, jobId, revision) {
688
+ const flag = outpostFlag && SAFE_TOKEN.test(outpostFlag) ? ` --outpost ${outpostFlag}` : "";
689
+ return `hq outposts jobs delete --company ${slug}${flag} ${jobId} --revision ${revision} --yes`;
690
+ }
691
+ function unconfirmedCompanyJob(slug) {
692
+ const status = isCompanySlug(slug)
693
+ ? `hq outposts status --company ${slug}`
694
+ : "hq outposts status --company <slug>";
695
+ return `The result could not be confirmed. The server may already have changed the job. Next: ${status}`;
696
+ }
697
+ async function runCompanyJobCommand(client, action, jobId, opts) {
698
+ const stop = { action, jobId, json: Boolean(opts.json) };
699
+ if (!COMPANY_JOB_ID.test(jobId)) {
700
+ stopCompanyJob("That job id is not valid. Next: copy it from hq outposts status --company <slug>.", stop, "invalid_job");
701
+ return;
702
+ }
703
+ const company = await requireCompany(client, opts.company ?? "");
704
+ // Same selector as register: a name or an id. Omitted means the company's default Outpost.
705
+ const target = opts.outpost === undefined
706
+ ? undefined
707
+ : await requireCompanyOutpost(client, company, opts.outpost, `hq outposts jobs ${action}`);
708
+ const outpostId = target?.outpostId;
709
+ const listed = await client.listCompanyJobs(company.uid, outpostId);
710
+ const job = listed.find((row) => row.jobId === jobId);
711
+ if (!job) {
712
+ stopCompanyJob(`No job ${jobId} on this Outpost. Next: pass --outpost <id> when the company has more than one, or run hq outposts status --company ${company.slug}.`, stop, "job_not_found");
713
+ return;
714
+ }
715
+ const revision = safeToken(job.acceptedRevision);
716
+ if (!revision) {
717
+ stopCompanyJob("Someone else changed this job. Reload it and try again.", stop, "job_changed");
718
+ return;
719
+ }
720
+ if (opts.revision !== undefined && safeToken(opts.revision) !== revision) {
721
+ stopCompanyJob("Someone else changed this job. Reload it and try again.", stop, "job_changed");
722
+ return;
723
+ }
724
+ if (action === "delete" && !opts.yes) {
725
+ stopCompanyJob(`This will delete job ${jobId} on ${company.slug}'s Outpost.\n` +
726
+ `Accepted revision: ${revision}\n` +
727
+ `Re-run with --yes to confirm: ${deleteRerunLine(company.slug, opts.outpost, jobId, revision)}`, stop, "confirmation_required");
728
+ return;
729
+ }
730
+ if ((action === "edit" || (action === "delete" && opts.yes)) && opts.revision === undefined) {
731
+ stopCompanyJob(action === "delete"
732
+ ? `Delete needs --revision ${revision} so a newer change is not removed.\n` +
733
+ `Next: ${deleteRerunLine(company.slug, opts.outpost, jobId, revision)}`
734
+ : `This edit needs the revision you last saw, so it does not overwrite a newer change. Next: re-run with --revision ${revision}.`, stop, "revision_required");
735
+ return;
736
+ }
737
+ if (action === "run-now" && job.status === "paused") {
738
+ stopCompanyJob(`This job is paused. Next: hq outposts jobs resume --company ${company.slug} ${jobId}`, stop, "paused");
739
+ return;
740
+ }
741
+ const definition = action === "edit"
742
+ ? mergeCompanyJobEdit(job, {
743
+ prompt: opts.prompt,
744
+ timezone: opts.timezone,
745
+ cron: opts.cron,
746
+ at: opts.at,
747
+ script: opts.script,
748
+ context: opts.context,
749
+ clearScript: opts.clearScript,
750
+ clearContext: opts.clearContext,
751
+ })
752
+ : undefined;
753
+ if (definition?.schedule.kind === "recurring" &&
754
+ opts.cron !== undefined &&
755
+ definition.schedule.cron !== opts.cron.trim() &&
756
+ !opts.json) {
757
+ console.log(`Using schedule ${definition.schedule.cron} for --cron "${opts.cron.trim()}".`);
758
+ }
759
+ const body = await client.companyJobCommand({
760
+ companyUid: company.uid,
761
+ action: COMPANY_JOB_WIRE[action],
762
+ jobId,
763
+ revision,
764
+ ...(outpostId ? { outpostId } : {}),
765
+ ...(definition ? { definition } : {}),
766
+ });
767
+ printCompanyJobResult(action, company.slug, jobId, body, Boolean(opts.json));
768
+ }
769
+ function printCompanyJobResult(action, slug, jobId, body, json) {
770
+ const stop = { action, jobId, json };
771
+ if (action === "run-now") {
772
+ const runId = safeToken(body.runId);
773
+ const returnedJob = safeToken(body.jobId);
774
+ if (!runId || (returnedJob !== undefined && returnedJob !== jobId)) {
775
+ stopCompanyJob(unconfirmedCompanyJob(slug), stop, "unconfirmed");
776
+ return;
777
+ }
778
+ if (json) {
779
+ process.stdout.write(JSON.stringify({ ok: true, company: slug, action, jobId, runId }) + "\n");
780
+ return;
781
+ }
782
+ console.log(`Started run ${runId} for ${jobId}.`);
783
+ console.log(`Next: hq outposts status --company ${slug}`);
784
+ return;
785
+ }
786
+ const job = body.job;
787
+ const row = job && typeof job === "object" ? job : undefined;
788
+ const returnedId = safeToken(row?.jobId);
789
+ const revision = safeToken(row?.acceptedRevision);
790
+ if (!row || returnedId !== jobId) {
791
+ stopCompanyJob(unconfirmedCompanyJob(slug), stop, "unconfirmed");
792
+ return;
793
+ }
794
+ if (action === "pause" && row.status !== "paused") {
795
+ stopCompanyJob(unconfirmedCompanyJob(slug), stop, "unconfirmed");
796
+ return;
797
+ }
798
+ if (action === "resume" && row.status !== "active") {
799
+ stopCompanyJob(unconfirmedCompanyJob(slug), stop, "unconfirmed");
800
+ return;
801
+ }
802
+ if (action === "delete" && row.deleted !== true) {
803
+ stopCompanyJob(unconfirmedCompanyJob(slug), stop, "unconfirmed");
804
+ return;
805
+ }
806
+ if (action === "edit" && !revision) {
807
+ stopCompanyJob(unconfirmedCompanyJob(slug), stop, "unconfirmed");
808
+ return;
809
+ }
810
+ const status = row.status === "paused" || row.status === "active" ? row.status : undefined;
811
+ if (json) {
812
+ process.stdout.write(JSON.stringify({
813
+ ok: true,
814
+ company: slug,
815
+ action,
816
+ jobId,
817
+ ...(revision ? { acceptedRevision: revision } : {}),
818
+ ...(status ? { status } : {}),
819
+ ...(action === "delete" ? { deleted: true } : {}),
820
+ }) + "\n");
821
+ return;
822
+ }
823
+ if (action === "edit") {
824
+ console.log(`Updated ${jobId} for ${slug}.`);
825
+ console.log(`Accepted revision: ${revision}`);
826
+ return;
827
+ }
828
+ if (action === "pause") {
829
+ console.log(`Paused ${jobId} for ${slug}.`);
830
+ return;
831
+ }
832
+ if (action === "resume") {
833
+ console.log(`Resumed ${jobId} for ${slug}.`);
834
+ return;
835
+ }
836
+ console.log(`Deleted ${jobId} for ${slug}.`);
837
+ }
290
838
  function quoteShellArgument(value) {
291
839
  return `'${value.replaceAll("'", "'\\''")}'`;
292
840
  }
@@ -415,22 +963,64 @@ export function registerOutpostsCommand(program, deps) {
415
963
  .option("--disk <gb>", "Root disk size in GB (EC2 only). Personal boxes only.")
416
964
  .option("--client-ip <ip>", "Your public IP for the box's SSH ingress (optional; server derives it otherwise). Personal boxes only.")
417
965
  .option("--company <slug>", "Provision the company's Outpost instead of your personal box")
418
- .option("--yes", "Confirm the $80/month charge (required to provision)")
966
+ .option("--name <name>", "With --company: not sent. This server creates the company's main Outpost and does not take a name yet")
967
+ .option("--yes", "Confirm the monthly charge (required to provision or create)")
968
+ .option("--json", "With --company, emit one JSON object. Progress goes to stderr.")
419
969
  .action(async function (opts) {
420
970
  try {
971
+ if (opts.name !== undefined && opts.company === undefined) {
972
+ console.error("--name names a company Outpost. Next: re-run with --company <slug> --name <name>.");
973
+ process.exit(1);
974
+ }
975
+ if (opts.company !== undefined && opts.name !== undefined) {
976
+ if (opts.runtime !== undefined || opts.disk !== undefined || opts.clientIp !== undefined) {
977
+ console.error("Those options are for a personal Outpost. Next: re-run with --company and --name, and leave out --runtime, --disk and --client-ip.");
978
+ process.exit(1);
979
+ }
980
+ try {
981
+ await createCompanyOutpostCommand(client, host, {
982
+ company: opts.company,
983
+ name: opts.name,
984
+ ...(opts.yes !== undefined ? { yes: opts.yes } : {}),
985
+ ...(opts.json ? { json: true } : {}),
986
+ }, deps.companyProvisionWait);
987
+ }
988
+ catch (err) {
989
+ // The create already reported this and called process.exit.
990
+ if (err instanceof Error && err.message.startsWith("process.exit("))
991
+ throw err;
992
+ if (opts.json) {
993
+ process.stdout.write(companyProvisionFailureJson(opts.company, err));
994
+ process.exit(1);
995
+ }
996
+ failCompany(opts.company, err, "provision");
997
+ }
998
+ return;
999
+ }
421
1000
  if (opts.company !== undefined) {
422
1001
  if (opts.runtime !== undefined || opts.disk !== undefined || opts.clientIp !== undefined) {
423
1002
  console.error("Those options are for a personal Outpost. Next: re-run with --company and --yes, and leave out --runtime, --disk and --client-ip.");
424
1003
  process.exit(1);
425
1004
  }
426
1005
  try {
427
- await provisionCompanyOutpost(client, opts.company, opts.yes, deps.companyProvisionWait);
1006
+ await provisionCompanyOutpost(client, opts.company, opts.yes, deps.companyProvisionWait, Boolean(opts.json));
428
1007
  }
429
1008
  catch (err) {
1009
+ // The charge gate already reported this and called process.exit.
1010
+ if (err instanceof Error && err.message.startsWith("process.exit("))
1011
+ throw err;
1012
+ if (opts.json) {
1013
+ process.stdout.write(companyProvisionFailureJson(opts.company, err));
1014
+ process.exit(1);
1015
+ }
430
1016
  failCompany(opts.company, err, "provision");
431
1017
  }
432
1018
  return;
433
1019
  }
1020
+ if (opts.json) {
1021
+ console.error("--json applies to a company Outpost. Next: re-run with --company <slug> --json, or drop --json.");
1022
+ process.exit(1);
1023
+ }
434
1024
  // Reject an unrecognized runtime rather than resolving it to claude:
435
1025
  // `--runtime codx` would otherwise hand back a silently Claude box.
436
1026
  if (opts.runtime !== undefined &&
@@ -500,9 +1090,19 @@ export function registerOutpostsCommand(program, deps) {
500
1090
  });
501
1091
  outposts
502
1092
  .command("list")
503
- .description("List every Outpost you own")
1093
+ .description("List every Outpost you own, or a company's Outposts with --company")
1094
+ .option("--company <slug>", "List the company's Outposts")
504
1095
  .option("--json", "Emit raw JSON")
505
1096
  .action(async function (opts) {
1097
+ if (opts.company !== undefined) {
1098
+ try {
1099
+ await listCompanyOutpostsCommand(client, opts.company, Boolean(opts.json));
1100
+ }
1101
+ catch (err) {
1102
+ failCompany(opts.company, err, "status");
1103
+ }
1104
+ return;
1105
+ }
506
1106
  try {
507
1107
  const rows = await client.list();
508
1108
  if (opts.json) {
@@ -546,8 +1146,10 @@ export function registerOutpostsCommand(program, deps) {
546
1146
  .description("Show live detail for one Outpost")
547
1147
  .option("--id <outpostId>", "Personal Outpost id (defaults to your primary box)")
548
1148
  .option("--company <slug>", "Show the company Outpost, its jobs, and each job's run status")
1149
+ .option("--outpost <name|id>", "Which company Outpost, when the company has more than one")
549
1150
  .option("--json", "Emit raw JSON")
550
1151
  .action(async function (opts) {
1152
+ rejectOutpostWithoutCompany(opts);
551
1153
  try {
552
1154
  if (opts.company !== undefined) {
553
1155
  if (opts.id !== undefined) {
@@ -555,7 +1157,7 @@ export function registerOutpostsCommand(program, deps) {
555
1157
  process.exit(1);
556
1158
  }
557
1159
  try {
558
- await showCompanyStatus(client, opts.company, Boolean(opts.json));
1160
+ await showCompanyStatus(client, opts.company, Boolean(opts.json), opts.outpost);
559
1161
  }
560
1162
  catch (err) {
561
1163
  failCompany(opts.company, err, "status");
@@ -575,7 +1177,7 @@ export function registerOutpostsCommand(program, deps) {
575
1177
  });
576
1178
  const jobs = outposts
577
1179
  .command("jobs")
578
- .description("Register a job on a company Outpost");
1180
+ .description("Register, edit, pause, resume, delete, or run a job on a company Outpost");
579
1181
  jobs
580
1182
  .command("register")
581
1183
  .description("Register a company job and print the accepted revision")
@@ -586,8 +1188,10 @@ export function registerOutpostsCommand(program, deps) {
586
1188
  .option("--at <iso>", "One-time ISO-8601 instant. Do not combine with --cron")
587
1189
  .option("--script <text>", "Optional precondition script stored with the job")
588
1190
  .option("--context <json>", "Optional JSON object stored with the job")
1191
+ .option("--outpost <name|id>", "Which company Outpost runs the job, when the company has more than one")
589
1192
  .option("--json", "Emit the job id and accepted revision as JSON")
590
1193
  .action(async function (opts) {
1194
+ rejectOutpostWithoutCompany(opts);
591
1195
  try {
592
1196
  await registerCompanyJobCommand(client, opts);
593
1197
  }
@@ -595,6 +1199,45 @@ export function registerOutpostsCommand(program, deps) {
595
1199
  failCompany(opts.company ?? "", err, "register");
596
1200
  }
597
1201
  });
1202
+ const companyJobActions = [
1203
+ { name: "edit", description: "Change a company job. Omitted fields stay as they are. Requires --revision", definition: true, confirm: false },
1204
+ { name: "pause", description: "Pause a company job", definition: false, confirm: false },
1205
+ { name: "resume", description: "Resume a paused company job", definition: false, confirm: false },
1206
+ { name: "delete", description: "Delete a company job (requires --yes)", definition: false, confirm: true },
1207
+ { name: "run-now", description: "Run a company job once now", definition: false, confirm: false },
1208
+ ];
1209
+ for (const spec of companyJobActions) {
1210
+ const command = jobs
1211
+ .command(spec.name)
1212
+ .description(spec.description)
1213
+ .argument("<jobId>", "Job id from hq outposts status --company <slug>")
1214
+ .option("--company <slug>", "Company that owns the Outpost")
1215
+ .option("--outpost <name|id>", "Which company Outpost, when the company has more than one")
1216
+ .option("--revision <rev>", "Accepted revision you last saw. Required for edit and delete --yes");
1217
+ if (spec.definition) {
1218
+ command
1219
+ .option("--prompt <text>", "What the job should do. Omit to keep the current prompt")
1220
+ .option("--timezone <name>", "IANA timezone, such as America/New_York. Omit to keep the current timezone")
1221
+ .option("--cron <expr>", 'Recurring schedule: rate(N minutes|hours|days), a five-field cron with * for day of month and month (such as "*/15 * * * *"; translated to the AWS form), or cron(MIN HOUR ? * DOW *). Omit to keep the current schedule')
1222
+ .option("--at <iso>", "One-time ISO-8601 instant. Do not combine with --cron")
1223
+ .option("--script <text>", "Precondition script stored with the job. Omit to keep the current script")
1224
+ .option("--context <json>", "JSON object stored with the job. Omit to keep the current context")
1225
+ .option("--clear-script", "Remove the job's precondition script")
1226
+ .option("--clear-context", "Remove the job's stored context");
1227
+ }
1228
+ if (spec.confirm) {
1229
+ command.option("--yes", "Confirm deletion of this job");
1230
+ }
1231
+ command.option("--json", "Emit the result as JSON").action(async function (jobId, opts) {
1232
+ rejectOutpostWithoutCompany(opts);
1233
+ try {
1234
+ await runCompanyJobCommand(client, spec.name, jobId, opts);
1235
+ }
1236
+ catch (err) {
1237
+ failCompany(opts.company ?? "", err, spec.name, opts.json ? { action: spec.name, jobId } : undefined);
1238
+ }
1239
+ });
1240
+ }
598
1241
  outposts
599
1242
  .command("exec <command...>")
600
1243
  .description("Run a shell command on an Outpost and print its output (use -- before flags meant for the remote command). " +
@@ -948,11 +1591,13 @@ export function registerOutpostsCommand(program, deps) {
948
1591
  .command("refresh-config")
949
1592
  .description("Re-apply the server's job runner configuration to the company Outpost (owner or admin)")
950
1593
  .requiredOption("--company <slug>", "Company slug")
1594
+ .option("--outpost <name|id>", "Which company Outpost, when the company has more than one")
951
1595
  .option("--json", "Emit raw JSON")
952
1596
  .action(async function (opts) {
953
1597
  try {
954
1598
  const company = await requireCompany(client, opts.company);
955
- await client.refreshCompanyConfig(company.uid);
1599
+ const target = await requireCompanyOutpost(client, company, opts.outpost, "hq outposts refresh-config");
1600
+ await client.refreshCompanyConfig(company.uid, target.outpostId);
956
1601
  // requireCompany validated opts.company; print the user's slug, never server text.
957
1602
  const slug = opts.company;
958
1603
  if (opts.json) {
@@ -960,7 +1605,7 @@ export function registerOutpostsCommand(program, deps) {
960
1605
  return;
961
1606
  }
962
1607
  console.log(chalk.green(`Configuration refresh started for ${slug}'s Outpost. It takes a few minutes.`));
963
- console.log(chalk.dim(`Next: hq outposts status --company ${slug}`));
1608
+ console.log(chalk.dim(`Next: hq outposts status --company ${slug}${outpostHint(target, opts.outpost)}`));
964
1609
  }
965
1610
  catch (err) {
966
1611
  failCompany(opts.company, err, "refresh");
@@ -989,8 +1634,10 @@ export function registerOutpostsCommand(program, deps) {
989
1634
  .description("Request a fresh login URL for an Outpost")
990
1635
  .option("--id <outpostId>", "Outpost id (defaults to your primary box)")
991
1636
  .option("--company <slug>", "Request a new sign-in link for the company's Outpost (owner or admin)")
1637
+ .option("--outpost <name|id>", "Which company Outpost, when the company has more than one")
992
1638
  .option("--json", "Emit raw JSON")
993
1639
  .action(async function (opts) {
1640
+ rejectOutpostWithoutCompany(opts);
994
1641
  if (opts.company !== undefined) {
995
1642
  if (opts.id) {
996
1643
  console.error(chalk.red("Use either --company or --id, not both."));
@@ -998,13 +1645,14 @@ export function registerOutpostsCommand(program, deps) {
998
1645
  }
999
1646
  try {
1000
1647
  const company = await requireCompany(client, opts.company);
1001
- await client.companySignIn(company.uid, "regenerate");
1648
+ const target = await requireCompanyOutpost(client, company, opts.outpost, "hq outposts login");
1649
+ await client.companySignIn(company.uid, "regenerate", undefined, target.outpostId);
1002
1650
  if (opts.json) {
1003
- process.stdout.write(JSON.stringify({ ok: true, company: company.slug, action: "regenerate" }, null, 2) + "\n");
1651
+ process.stdout.write(JSON.stringify({ ok: true, company: company.slug, outpost: target.name, action: "regenerate" }, null, 2) + "\n");
1004
1652
  return;
1005
1653
  }
1006
- console.log(chalk.green(`A new sign-in link was requested for ${company.slug}'s Outpost.`));
1007
- console.log(chalk.dim(`Next: hq outposts status --company ${company.slug} to read it.`));
1654
+ console.log(chalk.green(`A new sign-in link was requested for ${company.slug}'s Outpost ${target.name}.`));
1655
+ console.log(chalk.dim(`Next: hq outposts status --company ${company.slug}${outpostHint(target, opts.outpost)} to read it.`));
1008
1656
  }
1009
1657
  catch (err) {
1010
1658
  failCompany(opts.company, err, "signin");
@@ -1034,8 +1682,10 @@ export function registerOutpostsCommand(program, deps) {
1034
1682
  .description("Submit the Claude sign-in code for an Outpost that is awaiting login")
1035
1683
  .option("--id <outpostId>", "Outpost id (defaults to your primary box)")
1036
1684
  .option("--company <slug>", "Sign in the company's Outpost (owner or admin)")
1685
+ .option("--outpost <name|id>", "Which company Outpost, when the company has more than one")
1037
1686
  .option("--json", "Emit raw JSON")
1038
1687
  .action(async function (code, opts) {
1688
+ rejectOutpostWithoutCompany(opts);
1039
1689
  const trimmed = code.trim();
1040
1690
  if (!trimmed) {
1041
1691
  console.error(chalk.red("Provide the sign-in code: hq outposts login-code [--company <slug>] <code>"));
@@ -1048,13 +1698,14 @@ export function registerOutpostsCommand(program, deps) {
1048
1698
  }
1049
1699
  try {
1050
1700
  const company = await requireCompany(client, opts.company);
1051
- await client.companySignIn(company.uid, "code", trimmed);
1701
+ const target = await requireCompanyOutpost(client, company, opts.outpost, "hq outposts login-code <code>");
1702
+ await client.companySignIn(company.uid, "code", trimmed, target.outpostId);
1052
1703
  if (opts.json) {
1053
- process.stdout.write(JSON.stringify({ ok: true, company: company.slug, action: "code" }, null, 2) + "\n");
1704
+ process.stdout.write(JSON.stringify({ ok: true, company: company.slug, outpost: target.name, action: "code" }, null, 2) + "\n");
1054
1705
  return;
1055
1706
  }
1056
- console.log(chalk.green(`Code submitted. ${company.slug}'s Outpost will finish signing in shortly.`));
1057
- console.log(chalk.dim(`Next: hq outposts status --company ${company.slug}`));
1707
+ console.log(chalk.green(`Code submitted. ${company.slug}'s Outpost ${target.name} will finish signing in shortly.`));
1708
+ console.log(chalk.dim(`Next: hq outposts status --company ${company.slug}${outpostHint(target, opts.outpost)}`));
1058
1709
  }
1059
1710
  catch (err) {
1060
1711
  failCompany(opts.company, err, "signin");