@indigoai-us/hq-cli 5.345.233 → 5.345.235

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 (104) hide show
  1. package/CHANGELOG.md +67 -0
  2. package/dist/command-catalog.generated.d.ts +240 -7
  3. package/dist/command-catalog.generated.js +296 -7
  4. package/dist/command-registration-plan.d.ts +24 -0
  5. package/dist/command-registration-plan.js +4 -0
  6. package/dist/commands/bot-companies.d.ts +4 -1
  7. package/dist/commands/bot-companies.js +5 -1
  8. package/dist/commands/bot.d.ts +10 -0
  9. package/dist/commands/bot.js +165 -36
  10. package/dist/commands/capacity.js +1 -1
  11. package/dist/commands/core-handoff.js +2 -2
  12. package/dist/commands/core-ontology-native.js +5 -4
  13. package/dist/commands/core-pipeline-workflow-runner-native.js +4 -9
  14. package/dist/commands/deploy-app-db.d.ts +3 -0
  15. package/dist/commands/deploy-app-db.js +79 -0
  16. package/dist/commands/deploy-app-upload.d.ts +3 -0
  17. package/dist/commands/deploy-app-upload.js +120 -0
  18. package/dist/commands/deploy-comments.js +46 -1
  19. package/dist/commands/deploy-mutations.js +71 -5
  20. package/dist/commands/deploy-ssr.d.ts +3 -0
  21. package/dist/commands/deploy-ssr.js +74 -0
  22. package/dist/commands/dm.d.ts +7 -1
  23. package/dist/commands/dm.js +39 -9
  24. package/dist/commands/doctor.d.ts +1 -0
  25. package/dist/commands/doctor.js +26 -10
  26. package/dist/commands/fingerprint.js +4 -9
  27. package/dist/commands/install-global.js +10 -0
  28. package/dist/commands/lanes-accounts.js +5 -5
  29. package/dist/commands/lanes-hold.js +1 -1
  30. package/dist/commands/lanes-message.js +3 -3
  31. package/dist/commands/lanes-move.js +1 -1
  32. package/dist/commands/lanes-resume.js +6 -6
  33. package/dist/commands/lanes-watch.js +2 -2
  34. package/dist/commands/lanes.js +21 -21
  35. package/dist/commands/work-env.d.ts +90 -0
  36. package/dist/commands/work-env.js +304 -0
  37. package/dist/lazy-commands.js +2 -10
  38. package/dist/lib/bot/api.d.ts +27 -0
  39. package/dist/lib/bot/api.js +28 -2
  40. package/dist/lib/bot/cloud-create.d.ts +46 -0
  41. package/dist/lib/bot/cloud-create.js +128 -0
  42. package/dist/lib/bot/fleet-daemon.js +4 -1
  43. package/dist/lib/bot/fleet-local.d.ts +7 -0
  44. package/dist/lib/bot/fleet-local.js +39 -3
  45. package/dist/lib/bot/fleet-owner-companies.js +2 -2
  46. package/dist/lib/bot/promote.d.ts +81 -2
  47. package/dist/lib/bot/promote.js +425 -51
  48. package/dist/lib/bot/promotion-hold.d.ts +9 -0
  49. package/dist/lib/bot/promotion-hold.js +29 -0
  50. package/dist/lib/bot/promotion-receipt.d.ts +10 -0
  51. package/dist/lib/bot/promotion-receipt.js +41 -1
  52. package/dist/lib/bot/promotion-upload.d.ts +6 -1
  53. package/dist/lib/bot/promotion-upload.js +3 -1
  54. package/dist/lib/bot/readiness.d.ts +9 -0
  55. package/dist/lib/bot/readiness.js +16 -0
  56. package/dist/lib/capacity/route.js +4 -4
  57. package/dist/lib/capacity/sign-in.js +1 -1
  58. package/dist/lib/checkpoint-ontology/entity-file.js +15 -17
  59. package/dist/lib/daemon/catalog.d.ts +2 -0
  60. package/dist/lib/daemon/catalog.js +2 -0
  61. package/dist/lib/daemon/hook-requests.js +23 -3
  62. package/dist/lib/daemon/run.d.ts +14 -0
  63. package/dist/lib/daemon/run.js +24 -14
  64. package/dist/lib/deploy-api.d.ts +2 -0
  65. package/dist/lib/deploy-api.js +9 -0
  66. package/dist/lib/environment/work-requirements.js +1 -1
  67. package/dist/lib/hook-engine/coverage.js +50 -0
  68. package/dist/lib/hot-channels/signals-pass.d.ts +0 -76
  69. package/dist/lib/hot-channels/signals-pass.js +81 -4
  70. package/dist/lib/lanes/account-company.js +1 -1
  71. package/dist/lib/lanes/account-ownership.js +1 -1
  72. package/dist/lib/lanes/accounts.js +1 -1
  73. package/dist/lib/lanes/delivery.js +7 -7
  74. package/dist/lib/lanes/dropbox.js +1 -1
  75. package/dist/lib/lanes/grants.js +3 -3
  76. package/dist/lib/lanes/hq-root.js +1 -1
  77. package/dist/lib/lanes/keep-alive-audit.js +2 -2
  78. package/dist/lib/lanes/links.js +4 -4
  79. package/dist/lib/lanes/monitor.js +3 -3
  80. package/dist/lib/lanes/quota-notice.js +1 -1
  81. package/dist/lib/lanes/reconcile.js +22 -12
  82. package/dist/lib/lanes/signal-brief-template.js +1 -1
  83. package/dist/lib/lanes/worker-continuity.js +1 -1
  84. package/dist/lib/mesh/live/direct-drain.d.ts +1 -0
  85. package/dist/lib/mesh/live/direct-drain.js +12 -1
  86. package/dist/lib/mesh/live/emit.d.ts +1 -1
  87. package/dist/lib/mesh/live/emit.js +10 -5
  88. package/dist/lib/mesh/live/flush.js +19 -4
  89. package/dist/lib/mesh/live/reporting-privacy.d.ts +9 -3
  90. package/dist/lib/mesh/live/reporting-privacy.js +27 -7
  91. package/dist/lib/mesh/live/spool.d.ts +2 -0
  92. package/dist/lib/mesh/live/spool.js +41 -0
  93. package/dist/lib/signals/sanitize.js +5 -4
  94. package/dist/lib/signals/steps/garden.js +5 -4
  95. package/dist/lib/windows/jq.d.ts +17 -0
  96. package/dist/lib/windows/jq.js +72 -0
  97. package/dist/utils/frontmatter.d.ts +8 -0
  98. package/dist/utils/frontmatter.js +11 -2
  99. package/dist/utils/hq-roots-core.d.ts +5 -0
  100. package/dist/utils/hq-roots-core.js +18 -9
  101. package/dist/utils/owner-session.d.ts +13 -0
  102. package/dist/utils/owner-session.js +28 -0
  103. package/package.json +7 -7
  104. package/scripts/install-hook-engine.mjs +8 -15
@@ -105,7 +105,7 @@ export function createLaneResumeHandlers(deps) {
105
105
  }
106
106
  const failedResumeReason = opts.reason?.trim();
107
107
  if (opts.reason !== undefined && opts.fromFailed !== true) {
108
- throw new LanesError("failed_resume_reason_requires_flag", "--reason on hq lanes resume requires --from-failed", { lane_id: laneId });
108
+ throw new LanesError("failed_resume_reason_requires_flag", "--reason on hq runners resume requires --from-failed", { lane_id: laneId });
109
109
  }
110
110
  if (opts.fromFailed === true && !failedResumeReason) {
111
111
  throw new LanesError("failed_resume_reason_required", "--from-failed requires a non-empty --reason", { lane_id: laneId });
@@ -173,7 +173,7 @@ export function createLaneResumeHandlers(deps) {
173
173
  lane = casUpdateLane(hqRoot, laneId, (current) => ({ ...current, provider_session_id: opts.loopSessionId }));
174
174
  }
175
175
  if (opts.model !== undefined && opts.account === undefined) {
176
- throw new LanesError("model_requires_account", "--model on hq lanes resume is only accepted together with --account", {});
176
+ throw new LanesError("model_requires_account", "--model on hq runners resume is only accepted together with --account", {});
177
177
  }
178
178
  if (opts.account !== undefined && lane.state === "running") {
179
179
  throw new LanesError("lane_running", `Lane ${laneId} is running; stop it or wait for it to exit before moving its session`, {
@@ -186,7 +186,7 @@ export function createLaneResumeHandlers(deps) {
186
186
  }
187
187
  if (lane.state === "queued" &&
188
188
  (lane.queued_reason !== "worker_profile_changed" || opts.worker === undefined)) {
189
- throw new LanesError("lane_not_resumable", `Lane ${laneId} is queued; use hq lanes admit ${laneId} to request admission`, { lane_id: laneId, state: lane.state, admission_command: `hq lanes admit ${laneId}` });
189
+ throw new LanesError("lane_not_resumable", `Lane ${laneId} is queued; use hq runners admit ${laneId} to request admission`, { lane_id: laneId, state: lane.state, admission_command: `hq runners admit ${laneId}` });
190
190
  }
191
191
  const queuedProfileRecovery = lane.state === "queued" &&
192
192
  lane.queued_reason === "worker_profile_changed" &&
@@ -200,20 +200,20 @@ export function createLaneResumeHandlers(deps) {
200
200
  opts.keepAlive !== undefined ||
201
201
  opts.meshCompany !== undefined ||
202
202
  opts.compact === false)) {
203
- throw new LanesError("worker_profile_recovery_options_invalid", "Queued worker-profile recovery accepts only --worker; rerun hq lanes resume after reconcile admits the lane", { lane_id: laneId });
203
+ throw new LanesError("worker_profile_recovery_options_invalid", "Queued worker-profile recovery accepts only --worker; rerun hq runners resume after reconcile admits the lane", { lane_id: laneId });
204
204
  }
205
205
  const pendingQuestions = lane.state === "awaiting_input"
206
206
  ? await deps.pendingQuestionsForLane(ctx, lane)
207
207
  : [];
208
208
  if (pendingQuestions.length > 0 && !loopHandoffRepair) {
209
209
  const companySlug = lane.company?.slug ?? lane.mesh_company ?? "<company-slug>";
210
- const instructions = pendingQuestions.map(({ question_id, audience }) => `question ${question_id} awaits ${audience.kind}:${audience.id}; answer it with hq lanes questions answer ${question_id} --company ${companySlug} --freeform <answer>`);
210
+ const instructions = pendingQuestions.map(({ question_id, audience }) => `question ${question_id} awaits ${audience.kind}:${audience.id}; answer it with hq runners questions answer ${question_id} --company ${companySlug} --freeform <answer>`);
211
211
  const message = `Lane ${laneId} is awaiting input. ${instructions.join("; ")}`;
212
212
  throw new LanesError("lane_pending_questions", message, {
213
213
  lane_id: laneId,
214
214
  state: lane.state,
215
215
  pending_questions: pendingQuestions,
216
- answer_commands: pendingQuestions.map(({ question_id }) => `hq lanes questions answer ${question_id} --company ${companySlug} --freeform <answer>`),
216
+ answer_commands: pendingQuestions.map(({ question_id }) => `hq runners questions answer ${question_id} --company ${companySlug} --freeform <answer>`),
217
217
  });
218
218
  }
219
219
  const projectId = opts.project?.trim() || lane.project_id;
@@ -27,7 +27,7 @@ function monitorCallsForLaneIds(laneIds) {
27
27
  for (let offset = 0; offset < laneIds.length; offset += MAX_WATCHED_LANES) {
28
28
  const chunk = laneIds.slice(offset, offset + MAX_WATCHED_LANES);
29
29
  calls.push({
30
- command: `hq lanes watch ${chunk.join(" ")}`,
30
+ command: `hq runners watch ${chunk.join(" ")}`,
31
31
  timeout_ms: MONITOR_MAX_TIMEOUT_MS,
32
32
  persistent: false,
33
33
  });
@@ -151,7 +151,7 @@ export function createLaneWatchHandlers(deps) {
151
151
  }
152
152
  const sessionId = opts.session?.trim();
153
153
  if (!sessionId) {
154
- throw new LanesError("monitor_session_required", "hq lanes monitor-check requires --session <id> unless --reminder is used");
154
+ throw new LanesError("monitor_session_required", "hq runners monitor-check requires --session <id> unless --reminder is used");
155
155
  }
156
156
  const engine = resolveMonitorEngine(opts.engine, ctx.env);
157
157
  const activeLanes = loadAllLanes(ctx.hqRoot()).filter((lane) => lane.senior.kind === "session" &&
@@ -1527,7 +1527,7 @@ function outpostPickupTimeoutMessage(outpostId, waitMs, operation) {
1527
1527
  }
1528
1528
  function outpostIdentityUnknownError(message, expectedId, details = {}) {
1529
1529
  const expected = expectedId ?? "<expected-outpost-id>";
1530
- const command = `hq lanes outpost-identity backfill --id ${expected}`;
1530
+ const command = `hq runners outpost-identity backfill --id ${expected}`;
1531
1531
  return new LanesError("outpost_identity_unknown", message, {
1532
1532
  ...details,
1533
1533
  ...(expectedId !== undefined ? { expected_id: expectedId } : {}),
@@ -3234,7 +3234,7 @@ export function composeWorkerBrief(worker, taskBrief, hqRoot) {
3234
3234
  ? [
3235
3235
  "",
3236
3236
  "## Lane hiring grants",
3237
- "A child lane may hire only within its assigned grant. If you need more direct child lanes than your current grant allows, stop before creating them and write a decision=ask envelope. Include the total grant you want and why in the question and context. Use your lane id from HQ_LANE_ID so your senior can run `hq lanes grant <lane-id> --hire <n>`.",
3237
+ "A child lane may hire only within its assigned grant. If you need more direct child lanes than your current grant allows, stop before creating them and write a decision=ask envelope. Include the total grant you want and why in the question and context. Use your lane id from HQ_LANE_ID so your senior can run `hq runners grant <lane-id> --hire <n>`.",
3238
3238
  ]
3239
3239
  : [];
3240
3240
  return [
@@ -4865,7 +4865,7 @@ async function runCreate(ctx, opts) {
4865
4865
  assigned_child_grants: assignedChildHireGrants(children),
4866
4866
  requested_hire_grant: hireGrant,
4867
4867
  available_hire_grant: availableChildGrant,
4868
- ask_guidance: `Write an ask envelope with the desired total grant and reason; the senior runs hq lanes grant ${parent.lane_id} --hire <n>.`,
4868
+ ask_guidance: `Write an ask envelope with the desired total grant and reason; the senior runs hq runners grant ${parent.lane_id} --hire <n>.`,
4869
4869
  });
4870
4870
  }
4871
4871
  return createLane(hqRoot, laneInit);
@@ -5824,7 +5824,7 @@ async function dispatchOutpostLaneCommand(ctx, lane, action, options, behavior =
5824
5824
  });
5825
5825
  }
5826
5826
  if (action === "set" && outpostRejectedSetTargetCommand(dispatched)) {
5827
- throw new LanesError("outpost_cli_upgrade_required", `Outpost ${outpostId} needs an hq-cli release containing remote lane settings before hq lanes set can change lane ${lane.lane_id}`, {
5827
+ throw new LanesError("outpost_cli_upgrade_required", `Outpost ${outpostId} needs an hq-cli release containing remote lane settings before hq runners set can change lane ${lane.lane_id}`, {
5828
5828
  lane_id: lane.lane_id,
5829
5829
  outpost_id: outpostId,
5830
5830
  command_id: dispatched.commandId,
@@ -6383,7 +6383,7 @@ async function laneStatusFieldsForCommand(ctx, hqRoot, lane, now) {
6383
6383
  }
6384
6384
  async function runList(ctx, opts) {
6385
6385
  if (opts.json && opts.human) {
6386
- throw new LanesError("conflicting_output_format", "Use either --json or --human for hq lanes list", { json: true, human: true });
6386
+ throw new LanesError("conflicting_output_format", "Use either --json or --human for hq runners list", { json: true, human: true });
6387
6387
  }
6388
6388
  const requestedLaneIds = opts.lane ?? [];
6389
6389
  if (!Array.isArray(requestedLaneIds) ||
@@ -6700,17 +6700,17 @@ async function runLaneStatus(ctx, laneId, opts) {
6700
6700
  async function runStatus(ctx, opts, laneId) {
6701
6701
  if (laneId !== undefined) {
6702
6702
  if (opts.project !== undefined || opts.company !== undefined) {
6703
- throw new LanesError("invalid_args", "hq lanes status <lane-id> reports one lane; drop --project and --company", { lane_id: laneId });
6703
+ throw new LanesError("invalid_args", "hq runners status <lane-id> reports one lane; drop --project and --company", { lane_id: laneId });
6704
6704
  }
6705
6705
  await runLaneStatus(ctx, laneId, opts);
6706
6706
  return;
6707
6707
  }
6708
6708
  if (opts.project === undefined) {
6709
- throw new LanesError("invalid_args", "hq lanes status requires --project <slug>, or a lane id for one lane", {});
6709
+ throw new LanesError("invalid_args", "hq runners status requires --project <slug>, or a lane id for one lane", {});
6710
6710
  }
6711
6711
  const projectId = opts.project;
6712
6712
  if (!ctx.storyLedgerEnabled()) {
6713
- throw new LanesError("story_ledger_disabled", "hq lanes status requires the lanes.story-ledger flag", {
6713
+ throw new LanesError("story_ledger_disabled", "hq runners status requires the lanes.story-ledger flag", {
6714
6714
  flag: "lanes.story-ledger",
6715
6715
  });
6716
6716
  }
@@ -7409,7 +7409,7 @@ async function runSetOwnerTarget(ctx, laneId, opts) {
7409
7409
  }
7410
7410
  function parseLaneSetRequest(laneId, opts) {
7411
7411
  if (opts.model === undefined && opts.effort === undefined) {
7412
- throw new LanesError("lane_set_empty", "hq lanes set needs --company, --model, or --effort", { lane_id: laneId });
7412
+ throw new LanesError("lane_set_empty", "hq runners set needs --company, --model, or --effort", { lane_id: laneId });
7413
7413
  }
7414
7414
  const reason = opts.reason?.trim();
7415
7415
  if (opts.reason !== undefined && !reason) {
@@ -7442,7 +7442,7 @@ function applyLaneSettings(ctx, laneId, request, options) {
7442
7442
  const hqRoot = ctx.hqRoot();
7443
7443
  const lane = readLane(hqRoot, laneId);
7444
7444
  if (lane.host.kind === "outpost" && !laneRunsHereForOperatorMutation(ctx, lane)) {
7445
- throw new LanesError("set_remote_unsupported", `Lane ${laneId} runs on Outpost ${lane.host.id}; run hq lanes set on that Outpost`, { lane_id: laneId, outpost_id: lane.host.id });
7445
+ throw new LanesError("set_remote_unsupported", `Lane ${laneId} runs on Outpost ${lane.host.id}; run hq runners set on that Outpost`, { lane_id: laneId, outpost_id: lane.host.id });
7446
7446
  }
7447
7447
  assertLaneRunsHereForOperatorMutation(ctx, lane, "set");
7448
7448
  assertLaneSetSenior(lane, options.expectedSenior);
@@ -7471,7 +7471,7 @@ function applyLaneSettings(ctx, laneId, request, options) {
7471
7471
  const at = ctx.now().toISOString();
7472
7472
  return casUpdateLane(hqRoot, laneId, (current) => {
7473
7473
  if (current.version !== lane.version) {
7474
- throw new LanesError("lane_set_conflict", `Lane ${laneId} changed while the settings were checked; run hq lanes set again`, { lane_id: laneId, prepared_version: lane.version, version: current.version });
7474
+ throw new LanesError("lane_set_conflict", `Lane ${laneId} changed while the settings were checked; run hq runners set again`, { lane_id: laneId, prepared_version: lane.version, version: current.version });
7475
7475
  }
7476
7476
  const entry = { at, actor: options.actor, ...(reason !== undefined ? { reason } : {}) };
7477
7477
  const next = { ...current };
@@ -7577,7 +7577,7 @@ async function runLaneDoctor(ctx, pendingQuestionsForLane) {
7577
7577
  senior: lane.senior,
7578
7578
  terminal_reason: lane.terminal_reason,
7579
7579
  ...(isFailedQuotaKeepAliveLane(lane)
7580
- ? { suggested_command: `hq lanes resume ${lane.lane_id}` }
7580
+ ? { suggested_command: `hq runners resume ${lane.lane_id}` }
7581
7581
  : { suggested_action: "Inspect the quota reset details before authorizing a failed-lane resume." }),
7582
7582
  });
7583
7583
  }
@@ -7628,7 +7628,7 @@ async function runLaneDoctor(ctx, pendingQuestionsForLane) {
7628
7628
  question_id: question.question_id,
7629
7629
  asked_at: question.asked_at,
7630
7630
  audience: question.audience,
7631
- suggested_command: `hq lanes questions answer ${question.question_id} --company ${companySlug} --freeform <answer>`,
7631
+ suggested_command: `hq runners questions answer ${question.question_id} --company ${companySlug} --freeform <answer>`,
7632
7632
  });
7633
7633
  }
7634
7634
  }
@@ -7646,7 +7646,7 @@ function assertKeepAliveChangeAllowed(ctx, lane, laneId) {
7646
7646
  throw new LanesError("keep_alive_unauthorized", appendCallerSeniorReason("Only senior " + seniorKey(lane.senior) + " may change lane " + laneId + "'s keep-alive setting", callerAuthorization), { lane_id: laneId, senior: lane.senior, reason: callerAuthorization.reason });
7647
7647
  }
7648
7648
  if (!laneRunsHere(lane, reconcileHostFromCtx(ctx))) {
7649
- throw new LanesError("keep_alive_owner_host_required", "Run hq lanes keep-alive " + laneId + " on its owner host " + lane.host.kind + ":" + lane.host.id, { lane_id: laneId, host: lane.host });
7649
+ throw new LanesError("keep_alive_owner_host_required", "Run hq runners keep-alive " + laneId + " on its owner host " + lane.host.kind + ":" + lane.host.id, { lane_id: laneId, host: lane.host });
7650
7650
  }
7651
7651
  if (lane.state === "killed" || lane.state === "cancelled" || lane.state === "failed") {
7652
7652
  throw new LanesError("keep_alive_terminal_lane", "Cannot change keep-alive for lane " + laneId + " in terminal state " + lane.state, { lane_id: laneId, state: lane.state });
@@ -8358,7 +8358,7 @@ async function prepareAccountMove(ctx, lane, input) {
8358
8358
  });
8359
8359
  const block = quotaBlockFor(loadQuotaState(hqRoot), lane.provider, target, model, now);
8360
8360
  if (block.blocked) {
8361
- throw new LanesError("account_quota_held", `Account ${target} for ${lane.provider} cannot run model ${model ?? "(default)"}: the account's model needs credits${block.marker ? ` (${block.marker})` : ""}. Once credits are added, clear the marker with: hq lanes accounts clear-quota ${lane.provider} ${target}`, { provider: lane.provider, account: target, quota_reset_at: block.quota_reset_at ?? null, marker: block.marker ?? null, model: model ?? null, clear_command: `hq lanes accounts clear-quota ${lane.provider} ${target}` });
8361
+ throw new LanesError("account_quota_held", `Account ${target} for ${lane.provider} cannot run model ${model ?? "(default)"}: the account's model needs credits${block.marker ? ` (${block.marker})` : ""}. Once credits are added, clear the marker with: hq runners accounts clear-quota ${lane.provider} ${target}`, { provider: lane.provider, account: target, quota_reset_at: block.quota_reset_at ?? null, marker: block.marker ?? null, model: model ?? null, clear_command: `hq runners accounts clear-quota ${lane.provider} ${target}` });
8362
8362
  }
8363
8363
  if (model !== undefined) {
8364
8364
  validateLaneModel(lane.provider, model, targetHome, {
@@ -10076,7 +10076,7 @@ async function runStop(ctx, laneId, reason, quiet = false) {
10076
10076
  /** Stderr notice that `stop` ends a lane for good, naming the resumable path. */
10077
10077
  function stopTerminalWarning(laneId) {
10078
10078
  return `hq lanes: warning: stop kills lane ${laneId} and it cannot be resumed. ` +
10079
- `To pause it and keep it resumable, use hq lanes interrupt ${laneId}.\n`;
10079
+ `To pause it and keep it resumable, use hq runners interrupt ${laneId}.\n`;
10080
10080
  }
10081
10081
  /**
10082
10082
  * Stop a running lane's worker and leave it `interrupted`, keeping the provider
@@ -10105,7 +10105,7 @@ async function runInterrupt(ctx, laneId, reason, options = {}) {
10105
10105
  const hqRoot = ctx.hqRoot();
10106
10106
  const lane = readLane(hqRoot, laneId);
10107
10107
  if (lane.host.kind === "outpost" && !laneRunsHereForOperatorMutation(ctx, lane)) {
10108
- throw new LanesError("interrupt_remote_unsupported", `Lane ${laneId} runs on Outpost ${lane.host.id}; run hq lanes interrupt on that Outpost`, { lane_id: laneId, outpost_id: lane.host.id });
10108
+ throw new LanesError("interrupt_remote_unsupported", `Lane ${laneId} runs on Outpost ${lane.host.id}; run hq runners interrupt on that Outpost`, { lane_id: laneId, outpost_id: lane.host.id });
10109
10109
  }
10110
10110
  assertLaneRunsHereForOperatorMutation(ctx, lane, "interrupt");
10111
10111
  if (options.story !== undefined && lane.loop_mode !== true) {
@@ -10142,7 +10142,7 @@ async function runInterrupt(ctx, laneId, reason, options = {}) {
10142
10142
  const assertInterruptible = (current) => {
10143
10143
  if (current.state !== "running") {
10144
10144
  throw new LanesError("lane_not_running", current.state === "queued"
10145
- ? `Lane ${laneId} is queued and has no running turn; use hq lanes stop to cancel it`
10145
+ ? `Lane ${laneId} is queued and has no running turn; use hq runners stop to cancel it`
10146
10146
  : `Lane ${laneId} is ${current.state}; only a running lane can be interrupted`, { lane_id: laneId, state: current.state });
10147
10147
  }
10148
10148
  };
@@ -10212,7 +10212,7 @@ function persistInterruptedSession(hqRoot, lane) {
10212
10212
  /** Stderr notice when an interrupted lane has no session to resume from. */
10213
10213
  function interruptNotResumableWarning(laneId) {
10214
10214
  return `hq lanes: warning: lane ${laneId} was interrupted before its provider reported a session id, ` +
10215
- `so hq lanes resume cannot continue it. Start a new lane for the remaining work.\n`;
10215
+ `so hq runners resume cannot continue it. Start a new lane for the remaining work.\n`;
10216
10216
  }
10217
10217
  function parseQuestionPriority(value) {
10218
10218
  if (value === undefined) {
@@ -10234,7 +10234,7 @@ async function runAsk(ctx, opts) {
10234
10234
  const hqRoot = ctx.hqRoot();
10235
10235
  const laneId = ctx.env.HQ_LANE_ID?.trim();
10236
10236
  if (!laneId) {
10237
- throw new LanesError("missing_lane_id", "hq lanes ask requires HQ_LANE_ID in the environment", {});
10237
+ throw new LanesError("missing_lane_id", "hq runners ask requires HQ_LANE_ID in the environment", {});
10238
10238
  }
10239
10239
  const questionText = opts.question?.trim();
10240
10240
  if (!questionText) {
@@ -11669,7 +11669,7 @@ export function registerRunnersCommand(parent, deps = {}) {
11669
11669
  }));
11670
11670
  lanes
11671
11671
  .command("interrupt")
11672
- .description("Stop a running lane's turn and keep it resumable with hq lanes resume")
11672
+ .description("Stop a running lane's turn and keep it resumable with hq runners resume")
11673
11673
  .argument("<lane-id>", "Lane id")
11674
11674
  .option("--reason <text>", "Record the reason in the lane's stop history")
11675
11675
  .option("--story <id>", "Withdraw only this story's queued phases (loop lanes only)")
@@ -0,0 +1,90 @@
1
+ /**
2
+ * hq work-env: a thin launcher for the company-scoped work-env skill script
3
+ * at companies/<company>/skills/work-env/scripts/work-env.sh.
4
+ *
5
+ * The script owns every security rule (company lock, per-run key, teardown,
6
+ * leak scan). This command finds the script and runs it with `bash` from PATH
7
+ * (the script needs bash 4+), passing argv exactly as given, with no shell.
8
+ *
9
+ * Before choosing a script it checks the company against the session's locked
10
+ * company set, the same set the script checks, so no company's script runs
11
+ * from a session that is not locked to that company.
12
+ *
13
+ * Signals: the child shares the terminal's foreground process group, so a
14
+ * terminal Ctrl-C (SIGINT) or Ctrl-\ (SIGQUIT) already reaches it. The wrapper
15
+ * ignores those and does not forward them; forwarding would deliver a second
16
+ * signal that can cut the script's teardown short. SIGTERM and SIGHUP, which
17
+ * the terminal does not send to the child, are forwarded once each. The
18
+ * wrapper always waits for the child to exit and returns its exit code.
19
+ *
20
+ * Environment: nothing is added. WORK_ENV_* test seams are removed, and so
21
+ * are BASH_ENV, ENV and exported bash functions (BASH_FUNC_*), which bash
22
+ * would otherwise run before the script's first line.
23
+ */
24
+ import { type ChildProcess, type SpawnOptions } from "node:child_process";
25
+ import type { Command } from "commander";
26
+ export declare const WORK_ENV_COMMAND = "work-env";
27
+ export declare const WORK_ENV_SCRIPT_RELATIVE: string;
28
+ type SignalSource = {
29
+ on(event: string, listener: (...args: unknown[]) => void): unknown;
30
+ removeListener(event: string, listener: (...args: unknown[]) => void): unknown;
31
+ };
32
+ export interface WorkEnvDeps {
33
+ env?: NodeJS.ProcessEnv;
34
+ cwd?: string;
35
+ /** Where signals arrive from. Defaults to `process`. */
36
+ signals?: SignalSource;
37
+ spawn?: (file: string, args: readonly string[], options: SpawnOptions) => ChildProcess;
38
+ writeError?: (text: string) => void;
39
+ /** Called once the child has started. Defaults to releasing this process's package-use lease. */
40
+ onSpawn?: () => void;
41
+ /** Keep WORK_ENV_* in the child environment. Only this CLI's own tests set it. */
42
+ allowTestSeams?: boolean;
43
+ }
44
+ export type WorkEnvScriptResolution = {
45
+ ok: true;
46
+ path: string;
47
+ } | {
48
+ ok: false;
49
+ path: string;
50
+ message: string;
51
+ };
52
+ /**
53
+ * The script path for `company` under `hqRoot`, and whether it is installed.
54
+ * The script must be a regular file reached without symlinks below the HQ
55
+ * root, because the script derives its HQ root from its own resolved path.
56
+ */
57
+ export declare function resolveWorkEnvScript(hqRoot: string, company: string): WorkEnvScriptResolution;
58
+ /**
59
+ * The company named on the command line. Only tokens before the first `--`
60
+ * count (after it is the user's own command), and the last `--company` wins,
61
+ * as in the script's own option loop. `--company=<slug>` is reported so the
62
+ * caller can refuse it: the script does not accept that spelling.
63
+ */
64
+ export declare function workEnvCompanyFromArgs(args: readonly string[]): {
65
+ company?: string;
66
+ equalsForm: boolean;
67
+ };
68
+ /**
69
+ * The parent environment minus WORK_ENV_* test seams, BASH_ENV, ENV and
70
+ * exported bash functions. Nothing is added.
71
+ */
72
+ export declare function workEnvChildEnv(env: NodeJS.ProcessEnv, { allowTestSeams }?: {
73
+ allowTestSeams?: boolean;
74
+ }): NodeJS.ProcessEnv;
75
+ /** Find the script, check the lock, run it, and resolve with the exit code to use. */
76
+ export declare function runWorkEnv(args: readonly string[], deps?: WorkEnvDeps): Promise<number>;
77
+ /**
78
+ * The tokens after `work-env` exactly as typed. Commander can take a root
79
+ * option (`--verbose`) out of a child's arguments and drops a `--` that
80
+ * follows a plain argument, so the action reads the root's raw argv instead.
81
+ * Returns undefined when the raw argv does not line up; the caller refuses
82
+ * rather than fall back to Commander's parsed (lossy) arguments.
83
+ */
84
+ export declare function rawWorkEnvArgs(rawArgs: readonly string[] | undefined): string[] | undefined;
85
+ export interface WorkEnvCommandDeps extends WorkEnvDeps {
86
+ exit?: (code: number) => void;
87
+ }
88
+ export declare function registerWorkEnvCommand(program: Command, deps?: WorkEnvCommandDeps): Command;
89
+ export {};
90
+ //# sourceMappingURL=work-env.d.ts.map
@@ -0,0 +1,304 @@
1
+ /**
2
+ * hq work-env: a thin launcher for the company-scoped work-env skill script
3
+ * at companies/<company>/skills/work-env/scripts/work-env.sh.
4
+ *
5
+ * The script owns every security rule (company lock, per-run key, teardown,
6
+ * leak scan). This command finds the script and runs it with `bash` from PATH
7
+ * (the script needs bash 4+), passing argv exactly as given, with no shell.
8
+ *
9
+ * Before choosing a script it checks the company against the session's locked
10
+ * company set, the same set the script checks, so no company's script runs
11
+ * from a session that is not locked to that company.
12
+ *
13
+ * Signals: the child shares the terminal's foreground process group, so a
14
+ * terminal Ctrl-C (SIGINT) or Ctrl-\ (SIGQUIT) already reaches it. The wrapper
15
+ * ignores those and does not forward them; forwarding would deliver a second
16
+ * signal that can cut the script's teardown short. SIGTERM and SIGHUP, which
17
+ * the terminal does not send to the child, are forwarded once each. The
18
+ * wrapper always waits for the child to exit and returns its exit code.
19
+ *
20
+ * Environment: nothing is added. WORK_ENV_* test seams are removed, and so
21
+ * are BASH_ENV, ENV and exported bash functions (BASH_FUNC_*), which bash
22
+ * would otherwise run before the script's first line.
23
+ */
24
+ import { spawn as nodeSpawn } from "node:child_process";
25
+ import * as fs from "node:fs";
26
+ import os from "node:os";
27
+ import path from "node:path";
28
+ import { readSessionCompanyLock } from "../lib/session-company-lock.js";
29
+ import { resolveDefaultHqRoot } from "../utils/hq-root-resolver.js";
30
+ import { STILL_USE_FLAG } from "../utils/command-usage.js";
31
+ export const WORK_ENV_COMMAND = "work-env";
32
+ export const WORK_ENV_SCRIPT_RELATIVE = path.join("skills", "work-env", "scripts", "work-env.sh");
33
+ /** The script's own slug rule (check_company in work-env.sh). */
34
+ const COMPANY_SLUG = /^[a-z0-9][a-z0-9-]*$/;
35
+ /** Signals the terminal already delivers to the child's process group. */
36
+ const TERMINAL_SIGNALS = ["SIGINT", "SIGQUIT"];
37
+ /** Signals only the wrapper receives; forwarded to the child once each. */
38
+ const FORWARDED_SIGNALS = ["SIGTERM", "SIGHUP"];
39
+ function realpathOrUndefined(target) {
40
+ try {
41
+ return fs.realpathSync(target);
42
+ }
43
+ catch {
44
+ return undefined;
45
+ }
46
+ }
47
+ /**
48
+ * The script path for `company` under `hqRoot`, and whether it is installed.
49
+ * The script must be a regular file reached without symlinks below the HQ
50
+ * root, because the script derives its HQ root from its own resolved path.
51
+ */
52
+ export function resolveWorkEnvScript(hqRoot, company) {
53
+ const scriptPath = path.join(hqRoot, "companies", company, WORK_ENV_SCRIPT_RELATIVE);
54
+ let isFile;
55
+ try {
56
+ isFile = fs.statSync(scriptPath).isFile();
57
+ }
58
+ catch {
59
+ isFile = false;
60
+ }
61
+ if (!isFile) {
62
+ return {
63
+ ok: false,
64
+ path: scriptPath,
65
+ message: `The work-env skill is not installed for company '${company}'. Expected ${scriptPath}.`,
66
+ };
67
+ }
68
+ const realRoot = realpathOrUndefined(hqRoot);
69
+ const realScript = realpathOrUndefined(scriptPath);
70
+ if (!realRoot || realScript !== path.join(realRoot, "companies", company, WORK_ENV_SCRIPT_RELATIVE)) {
71
+ return {
72
+ ok: false,
73
+ path: scriptPath,
74
+ message: `The work-env script for company '${company}' resolves outside companies/${company}/ (a symlink). Refusing to run it.`,
75
+ };
76
+ }
77
+ return { ok: true, path: scriptPath };
78
+ }
79
+ /**
80
+ * The company named on the command line. Only tokens before the first `--`
81
+ * count (after it is the user's own command), and the last `--company` wins,
82
+ * as in the script's own option loop. `--company=<slug>` is reported so the
83
+ * caller can refuse it: the script does not accept that spelling.
84
+ */
85
+ export function workEnvCompanyFromArgs(args) {
86
+ let company;
87
+ let equalsForm = false;
88
+ for (let index = 0; index < args.length; index += 1) {
89
+ const token = args[index];
90
+ if (token === "--")
91
+ break;
92
+ if (token === "--company") {
93
+ company = args[index + 1] ?? "";
94
+ index += 1;
95
+ }
96
+ else if (token.startsWith("--company=")) {
97
+ equalsForm = true;
98
+ }
99
+ }
100
+ return { company, equalsForm };
101
+ }
102
+ /**
103
+ * The parent environment minus WORK_ENV_* test seams, BASH_ENV, ENV and
104
+ * exported bash functions. Nothing is added.
105
+ */
106
+ export function workEnvChildEnv(env, { allowTestSeams = false } = {}) {
107
+ const child = {};
108
+ for (const [key, value] of Object.entries(env)) {
109
+ if (!allowTestSeams && key.startsWith("WORK_ENV_"))
110
+ continue;
111
+ if (key === "BASH_ENV" || key === "ENV" || key.startsWith("BASH_FUNC_"))
112
+ continue;
113
+ child[key] = value;
114
+ }
115
+ return child;
116
+ }
117
+ function exitCodeFor(code, signal) {
118
+ if (typeof code === "number")
119
+ return code;
120
+ if (signal) {
121
+ const number = os.constants.signals[signal];
122
+ if (typeof number === "number")
123
+ return 128 + number;
124
+ }
125
+ return 1;
126
+ }
127
+ /** Find the script, check the lock, run it, and resolve with the exit code to use. */
128
+ export async function runWorkEnv(args, deps = {}) {
129
+ const env = deps.env ?? process.env;
130
+ const writeError = deps.writeError ?? ((text) => process.stderr.write(text));
131
+ const refuse = (message, code = 2) => {
132
+ writeError(`hq work-env: ${message}\n`);
133
+ return code;
134
+ };
135
+ let hqRoot;
136
+ try {
137
+ hqRoot = resolveDefaultHqRoot({ env, cwd: deps.cwd, onMissing: "throw" });
138
+ }
139
+ catch (error) {
140
+ return refuse(error instanceof Error ? error.message : String(error));
141
+ }
142
+ const named = workEnvCompanyFromArgs(args);
143
+ if (named.equalsForm) {
144
+ return refuse("pass the company as two arguments, --company <slug>; the work-env script does not accept --company=<slug>.");
145
+ }
146
+ let locked;
147
+ try {
148
+ locked = readSessionCompanyLock({ ...env, HQ_ROOT: hqRoot })?.companies ?? [];
149
+ }
150
+ catch (error) {
151
+ return refuse(error instanceof Error ? error.message : String(error));
152
+ }
153
+ const company = named.company ?? locked[0];
154
+ if (!company) {
155
+ return refuse("no active company. Run it from an HQ session locked to the company (core/scripts/hq-session.sh add company <slug>), and pass --company <slug> to start.");
156
+ }
157
+ if (!COMPANY_SLUG.test(company))
158
+ return refuse(`'${company}' is not a valid company slug.`);
159
+ if (company === "personal")
160
+ return refuse("personal is not a company.");
161
+ if (!locked.includes(company)) {
162
+ return refuse(`company '${company}' is not in this session's locked company set (${locked.join(",") || "none"}). ` +
163
+ `Add it with core/scripts/hq-session.sh add company ${company} if this is intended.`);
164
+ }
165
+ const script = resolveWorkEnvScript(hqRoot, company);
166
+ if (!script.ok)
167
+ return refuse(script.message, 1);
168
+ const spawn = deps.spawn ?? ((file, spawnArgs, options) => nodeSpawn(file, [...spawnArgs], options));
169
+ const signals = deps.signals ?? process;
170
+ const onSpawn = deps.onSpawn ?? releaseLeaseAfterStart;
171
+ return new Promise((resolve) => {
172
+ let child;
173
+ const listeners = new Map();
174
+ const cleanup = () => {
175
+ for (const [signal, listener] of listeners)
176
+ signals.removeListener(signal, listener);
177
+ listeners.clear();
178
+ };
179
+ try {
180
+ child = spawn("bash", [script.path, ...args], {
181
+ stdio: "inherit",
182
+ env: workEnvChildEnv(env, { allowTestSeams: deps.allowTestSeams === true }),
183
+ shell: false,
184
+ });
185
+ }
186
+ catch (error) {
187
+ resolve(refuse(`could not start bash: ${error instanceof Error ? error.message : String(error)}`, 1));
188
+ return;
189
+ }
190
+ for (const signal of TERMINAL_SIGNALS) {
191
+ // Listening keeps Node from exiting on the signal. The child got its
192
+ // own copy from the terminal; keep waiting for it to finish teardown.
193
+ const listener = () => { };
194
+ listeners.set(signal, listener);
195
+ signals.on(signal, listener);
196
+ }
197
+ const forwarded = new Set();
198
+ for (const signal of FORWARDED_SIGNALS) {
199
+ const listener = () => {
200
+ if (forwarded.has(signal))
201
+ return;
202
+ forwarded.add(signal);
203
+ try {
204
+ child.kill(signal);
205
+ }
206
+ catch {
207
+ // The child already exited; its close event settles the run.
208
+ }
209
+ };
210
+ listeners.set(signal, listener);
211
+ signals.on(signal, listener);
212
+ }
213
+ child.once("spawn", () => onSpawn());
214
+ child.once("error", (error) => {
215
+ cleanup();
216
+ resolve(refuse(`could not start bash: ${error.message}`, 1));
217
+ });
218
+ child.once("close", (code, signal) => {
219
+ cleanup();
220
+ resolve(exitCodeFor(code, signal));
221
+ });
222
+ });
223
+ }
224
+ function releaseLeaseAfterStart() {
225
+ // The script calls hq itself; each nested hq takes its own lease, so this
226
+ // wrapper does not hold one for the whole run (a run can outlast the lease's
227
+ // maximum hold and would block CLI updates for hours).
228
+ void import("../utils/child-wrapper-lease.js").then(({ releaseChildWrapperPackageUseLeaseAfterStart }) => releaseChildWrapperPackageUseLeaseAfterStart("childWrapper"));
229
+ }
230
+ /**
231
+ * The tokens after `work-env` exactly as typed. Commander can take a root
232
+ * option (`--verbose`) out of a child's arguments and drops a `--` that
233
+ * follows a plain argument, so the action reads the root's raw argv instead.
234
+ * Returns undefined when the raw argv does not line up; the caller refuses
235
+ * rather than fall back to Commander's parsed (lossy) arguments.
236
+ */
237
+ export function rawWorkEnvArgs(rawArgs) {
238
+ if (!rawArgs)
239
+ return undefined;
240
+ let index = 2;
241
+ while (rawArgs[index] === "--verbose" || rawArgs[index] === STILL_USE_FLAG)
242
+ index += 1;
243
+ if (rawArgs[index] !== WORK_ENV_COMMAND)
244
+ return undefined;
245
+ return rawArgs.slice(index + 1);
246
+ }
247
+ const HELP_AFTER = `
248
+ Subcommands (handled by the company's work-env.sh):
249
+ start --company <slug> --secrets NAME1,NAME2 --workdir <abs path> --hours <n>
250
+ [--cpus 2] [--memory 4] [--backend local|microvm] -- <command...>
251
+ status <id>
252
+ logs <id>
253
+ stop <id>
254
+ build [--context <agent-image dir>]
255
+
256
+ Runs only in an HQ session locked to the company. The company is --company
257
+ (start) or, for the other subcommands, the session's primary company. It must
258
+ be in the session's locked company set; it selects
259
+ companies/<company>/skills/work-env/scripts/work-env.sh under the HQ root.
260
+ Every argument reaches the script unchanged, and the script enforces the lock
261
+ again, mints and revokes the per-run key, and runs teardown and the leak scan.
262
+
263
+ Runs the script with bash from PATH and no shell. A terminal Ctrl-C reaches
264
+ the script directly; SIGTERM and SIGHUP sent to hq are forwarded once. hq
265
+ waits for teardown and exits with the script's exit code (2 refused, 3
266
+ teardown failed, 4 key mint failed, 5 docker run failed, 124 timeout, 130/143
267
+ interrupted).
268
+
269
+ Examples:
270
+ hq work-env start --company indigo --secrets NPM_TOKEN --workdir "$PWD" --hours 1 -- pnpm test
271
+ hq work-env status we-20261118t210000z-a1b2c3
272
+ hq work-env stop we-20261118t210000z-a1b2c3
273
+ `;
274
+ export function registerWorkEnvCommand(program, deps = {}) {
275
+ return program
276
+ .command(WORK_ENV_COMMAND)
277
+ .description("Start, inspect and stop a company-scoped work environment (runs the work-env skill script)")
278
+ .usage("<start|status|logs|stop|build> [args...]")
279
+ .helpOption(false)
280
+ .allowUnknownOption()
281
+ .allowExcessArguments()
282
+ .argument("[args...]", "Arguments passed unchanged to work-env.sh")
283
+ .addHelpText("after", HELP_AFTER)
284
+ .action(async (_parsedArgs, _options, command) => {
285
+ const exit = deps.exit ?? ((code) => process.exit(code));
286
+ let root = command;
287
+ while (root.parent)
288
+ root = root.parent;
289
+ const args = rawWorkEnvArgs(root.rawArgs);
290
+ if (!args) {
291
+ (deps.writeError ?? ((text) => process.stderr.write(text)))("hq work-env: could not read the command line exactly as typed; nothing was run.\n");
292
+ exit(2);
293
+ return;
294
+ }
295
+ const first = args[0];
296
+ if (first === undefined || first === "--help" || first === "-h" || first === "help") {
297
+ command.outputHelp();
298
+ exit(0);
299
+ return;
300
+ }
301
+ exit(await runWorkEnv(args, deps));
302
+ });
303
+ }
304
+ //# sourceMappingURL=work-env.js.map