@indigoai-us/hq-cli 5.345.242 → 5.345.244

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 (33) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/command-catalog.generated.d.ts +3 -3
  3. package/dist/command-catalog.generated.js +3 -3
  4. package/dist/commands/bot.d.ts +12 -0
  5. package/dist/commands/bot.js +126 -44
  6. package/dist/hq-cloud-sync-runner/bin/sync-runner.js +285 -225
  7. package/dist/hq-cloud-sync-runner/package.json +1 -1
  8. package/dist/lib/bot/config.d.ts +10 -0
  9. package/dist/lib/bot/config.js +15 -0
  10. package/dist/lib/bot/continuity.js +2 -2
  11. package/dist/lib/bot/promote-sign-in.d.ts +78 -0
  12. package/dist/lib/bot/promote-sign-in.js +152 -0
  13. package/dist/lib/bot/promote.d.ts +19 -1
  14. package/dist/lib/bot/promote.js +25 -5
  15. package/dist/lib/bot/scaffold.d.ts +20 -3
  16. package/dist/lib/bot/scaffold.js +18 -8
  17. package/dist/lib/claude-md-imports.d.ts +52 -0
  18. package/dist/lib/claude-md-imports.js +226 -0
  19. package/dist/lib/daemon/hook-requests-fleet-session-start.d.ts +10 -0
  20. package/dist/lib/daemon/hook-requests-fleet-session-start.js +86 -42
  21. package/dist/lib/daemon/hook-requests.d.ts +2 -2
  22. package/dist/lib/daemon/hook-requests.js +13 -3
  23. package/dist/lib/doctor/checks/claude-imports.d.ts +29 -0
  24. package/dist/lib/doctor/checks/claude-imports.js +131 -0
  25. package/dist/lib/doctor/fix/apply.d.ts +7 -0
  26. package/dist/lib/doctor/fix/apply.js +77 -0
  27. package/dist/lib/doctor/fix/remediation.d.ts +11 -1
  28. package/dist/lib/doctor/fix/remediation.js +42 -0
  29. package/dist/lib/doctor/registry.js +4 -0
  30. package/dist/lib/flag-registry-worker-source.generated.d.ts +1 -1
  31. package/dist/lib/flag-registry-worker-source.generated.js +1 -1
  32. package/dist/lib/lanes/liveness.js +46 -16
  33. package/package.json +8 -8
@@ -1 +1 @@
1
- {"name":"hq-cli-daemon-sync-runner","type":"module","version":"6.18.118","bundleSha256":"7f7e31221249ffacdaee78e883c2d2e761d189b251d6cb8b57824e97ee185d2f","formatVersion":1}
1
+ {"name":"hq-cli-daemon-sync-runner","type":"module","version":"6.18.119","bundleSha256":"9c6586f7fbaea150883640c5326469e9999be45a94159a990aabdf098a3893a6","formatVersion":1}
@@ -40,6 +40,16 @@ export declare function normalizeBotCompanies(values: readonly string[] | undefi
40
40
  export declare function effectiveBotKind(config: Pick<BotConfig, "kind" | "workerId">): BotKind;
41
41
  /** The companies a bot belongs to (empty for a personal bot: its owner's memberships apply). */
42
42
  export declare function effectiveBotCompanies(config: Pick<BotConfig, "kind" | "companies" | "workerId">): string[];
43
+ /**
44
+ * The one company a bot works in: its explicit `companySlug` (the company of
45
+ * the company worker it runs), else a company bot's single membership. A
46
+ * company bot scaffolded with `--kind company --company <slug>` has no
47
+ * `companySlug` in bot.json; its company is read from its current membership
48
+ * list, so it follows `hq bot companies` instead of keeping a stale copy. The
49
+ * same rule binds its turns (resolveBotCompanyBinding). Undefined for a
50
+ * personal bot and for a company bot in more than one company.
51
+ */
52
+ export declare function botCompanySlug(config: Pick<BotConfig, "kind" | "companies" | "workerId" | "companySlug">): string | undefined;
43
53
  /** Longest display name (Slack's own limit for a bot's display name). */
44
54
  export declare const BOT_DISPLAY_NAME_MAX_CHARS = 35;
45
55
  /** Longest `intro` (first-start hello DM) a bot may store. */
@@ -91,6 +91,21 @@ export function effectiveBotCompanies(config) {
91
91
  }
92
92
  return listed;
93
93
  }
94
+ /**
95
+ * The one company a bot works in: its explicit `companySlug` (the company of
96
+ * the company worker it runs), else a company bot's single membership. A
97
+ * company bot scaffolded with `--kind company --company <slug>` has no
98
+ * `companySlug` in bot.json; its company is read from its current membership
99
+ * list, so it follows `hq bot companies` instead of keeping a stale copy. The
100
+ * same rule binds its turns (resolveBotCompanyBinding). Undefined for a
101
+ * personal bot and for a company bot in more than one company.
102
+ */
103
+ export function botCompanySlug(config) {
104
+ if (config.companySlug)
105
+ return config.companySlug;
106
+ const companies = effectiveBotCompanies(config);
107
+ return companies.length === 1 ? companies[0] : undefined;
108
+ }
94
109
  /** Longest display name (Slack's own limit for a bot's display name). */
95
110
  export const BOT_DISPLAY_NAME_MAX_CHARS = 35;
96
111
  /** Longest `intro` (first-start hello DM) a bot may store. */
@@ -6,7 +6,7 @@ import * as path from "node:path";
6
6
  import { createHash } from "node:crypto";
7
7
  import { isUtf8 } from "node:buffer";
8
8
  import * as yaml from "js-yaml";
9
- import { resolveBotMemoryDir } from "./config.js";
9
+ import { botCompanySlug, resolveBotMemoryDir } from "./config.js";
10
10
  import { packageRoot } from "../../utils/hq-roots.js";
11
11
  const MAX_FILES = 2000;
12
12
  const MAX_BYTES = 32 * 1024 * 1024;
@@ -144,7 +144,7 @@ export function snapshotBotContinuity(config, stateDir, fleetState = []) {
144
144
  reject("worker.yaml is missing");
145
145
  const payload = {
146
146
  version: 1, agentUid: config.agentUid, ownerUid: config.ownerUid, name: config.name,
147
- ...(config.companySlug ? { companySlug: config.companySlug } : {}),
147
+ ...(botCompanySlug(config) ? { companySlug: botCompanySlug(config) } : {}),
148
148
  source: { hqRoot, workerDir: sourceWorkerDir, memoryDir: memoryRoot }, files,
149
149
  };
150
150
  return { ...payload, digest: digestOf(payload) };
@@ -0,0 +1,78 @@
1
+ /**
2
+ * The Codex device sign-in a move to the cloud waits for (`hq bot promote`).
3
+ *
4
+ * A promoted bot runs Codex on the owner's ChatGPT subscription. Once HQ has
5
+ * the cloud machine up, the machine runs `codex login --device-auth` and HQ
6
+ * hands the device URL and code back on the promotion details read. The code
7
+ * lives 15 minutes; the machine then starts a new one, and HQ stops returning
8
+ * the old one. This module turns those details into what the owner is told,
9
+ * and waits (in a terminal) until the move finishes.
10
+ */
11
+ import type { BotPromotionState } from "./api.js";
12
+ /** How long a Codex device code is valid. HQ drops a pairing older than this. */
13
+ export declare const CODEX_DEVICE_CODE_LIFETIME_MS: number;
14
+ /** How often an attached `hq bot promote` checks on the move. */
15
+ export declare const PROMOTION_WAIT_INTERVAL_MS = 30000;
16
+ /** Failed checks in a row (HQ unreachable, a 5xx) an attached wait rides out before it gives up. */
17
+ export declare const PROMOTION_WAIT_MAX_FAILURES = 4;
18
+ /** How long an attached `hq bot promote` waits before it hands back the prompt. */
19
+ export declare const PROMOTION_WAIT_MAX_MS: number;
20
+ export interface PromotionPairing {
21
+ url: string;
22
+ code: string;
23
+ capturedAt?: string;
24
+ }
25
+ /** The sign-in a pending move waits for, as `hq bot promote --json` reports it. */
26
+ export interface PromotionSignIn {
27
+ /** Same type as `hq agents status` gives this action. */
28
+ type: "codex-device-sign-in";
29
+ /** "code-ready": open `url` and enter `code`. "waiting-for-code": HQ has not shown a code yet. */
30
+ status: "code-ready" | "waiting-for-code";
31
+ url: string | null;
32
+ code: string | null;
33
+ capturedAt: string | null;
34
+ /** When the code stops working; null when HQ did not say when it was made. */
35
+ expiresAt: string | null;
36
+ instruction: string;
37
+ }
38
+ /**
39
+ * The sign-in a pending move waits for, or null when it waits for none. Only
40
+ * a move HQ holds at local-stopped (the cloud copy is being set up) waits for
41
+ * one; an expired code counts as no code.
42
+ */
43
+ export declare function promotionSignIn(result: {
44
+ promotion: Pick<BotPromotionState, "phase">;
45
+ pending: boolean;
46
+ }, pairing: PromotionPairing | null | undefined, nowMs: number): PromotionSignIn | null;
47
+ /** The lines `hq bot promote` prints for a sign-in. `attached`: this command keeps waiting. */
48
+ export declare function describePromotionSignIn(name: string, signIn: PromotionSignIn, nowMs: number, attached: boolean): string[];
49
+ /** One check on the move: resume it, then read its details. */
50
+ export interface PromotionCheck {
51
+ result: {
52
+ promotion: BotPromotionState;
53
+ pending: boolean;
54
+ };
55
+ pairing: PromotionPairing | null;
56
+ /** HQ's failure, already in plain words: the move stops here. */
57
+ failure: string | null;
58
+ /** The details could not be read this time. */
59
+ detailsError: string | null;
60
+ }
61
+ export interface PromotionWaitDeps {
62
+ check(): Promise<PromotionCheck>;
63
+ sleep(ms: number): Promise<void>;
64
+ now(): number;
65
+ print(line: string): void;
66
+ intervalMs?: number;
67
+ maxWaitMs?: number;
68
+ maxFailures?: number;
69
+ }
70
+ /**
71
+ * Keep checking on a pending move until it finishes, fails, is closed in HQ
72
+ * (`check` throws an error named PromotionClosedError), or the wait runs out.
73
+ * Prints a new code whenever HQ shows one (the caller printed the first
74
+ * check's), says when a shown code expires or stops being shown, and rides out
75
+ * a few failed checks in a row. A sign-in error is never retried.
76
+ */
77
+ export declare function waitForPromotion(name: string, first: PromotionCheck, deps: PromotionWaitDeps): Promise<PromotionCheck>;
78
+ //# sourceMappingURL=promote-sign-in.d.ts.map
@@ -0,0 +1,152 @@
1
+ /**
2
+ * The Codex device sign-in a move to the cloud waits for (`hq bot promote`).
3
+ *
4
+ * A promoted bot runs Codex on the owner's ChatGPT subscription. Once HQ has
5
+ * the cloud machine up, the machine runs `codex login --device-auth` and HQ
6
+ * hands the device URL and code back on the promotion details read. The code
7
+ * lives 15 minutes; the machine then starts a new one, and HQ stops returning
8
+ * the old one. This module turns those details into what the owner is told,
9
+ * and waits (in a terminal) until the move finishes.
10
+ */
11
+ /** How long a Codex device code is valid. HQ drops a pairing older than this. */
12
+ export const CODEX_DEVICE_CODE_LIFETIME_MS = 15 * 60_000;
13
+ /** How often an attached `hq bot promote` checks on the move. */
14
+ export const PROMOTION_WAIT_INTERVAL_MS = 30_000;
15
+ /** Failed checks in a row (HQ unreachable, a 5xx) an attached wait rides out before it gives up. */
16
+ export const PROMOTION_WAIT_MAX_FAILURES = 4;
17
+ /** How long an attached `hq bot promote` waits before it hands back the prompt. */
18
+ export const PROMOTION_WAIT_MAX_MS = 60 * 60_000;
19
+ function codeExpiry(pairing) {
20
+ const captured = pairing.capturedAt ? Date.parse(pairing.capturedAt) : NaN;
21
+ return Number.isFinite(captured) ? captured + CODEX_DEVICE_CODE_LIFETIME_MS : null;
22
+ }
23
+ /**
24
+ * The sign-in a pending move waits for, or null when it waits for none. Only
25
+ * a move HQ holds at local-stopped (the cloud copy is being set up) waits for
26
+ * one; an expired code counts as no code.
27
+ */
28
+ export function promotionSignIn(result, pairing, nowMs) {
29
+ if (!result.pending || result.promotion.phase !== "local-stopped")
30
+ return null;
31
+ const expiry = pairing ? codeExpiry(pairing) : null;
32
+ if (pairing && (expiry === null || expiry > nowMs)) {
33
+ return {
34
+ type: "codex-device-sign-in",
35
+ status: "code-ready",
36
+ url: pairing.url,
37
+ code: pairing.code,
38
+ capturedAt: pairing.capturedAt ?? null,
39
+ expiresAt: expiry === null ? null : new Date(expiry).toISOString(),
40
+ instruction: "Open this page and enter the code to sign the cloud bot in to Codex with your ChatGPT subscription.",
41
+ };
42
+ }
43
+ return {
44
+ type: "codex-device-sign-in",
45
+ status: "waiting-for-code",
46
+ url: null,
47
+ code: null,
48
+ capturedAt: null,
49
+ expiresAt: null,
50
+ instruction: "HQ is setting up the cloud copy. When its machine is ready, HQ shows a Codex sign-in page and code here (unless it is already signed in). Run the same command to see it.",
51
+ };
52
+ }
53
+ function clock(iso) {
54
+ return `${iso.slice(11, 16)} UTC`;
55
+ }
56
+ /** The lines `hq bot promote` prints for a sign-in. `attached`: this command keeps waiting. */
57
+ export function describePromotionSignIn(name, signIn, nowMs, attached) {
58
+ if (signIn.status === "waiting-for-code") {
59
+ return [
60
+ `${name}: the move is waiting for HQ to set up the cloud copy. Next, HQ asks you to sign it in to Codex with your ChatGPT subscription (a device code); if it is already signed in, the move goes on without one.` +
61
+ (attached
62
+ ? " The code shows here when it is ready. Ctrl-C stops waiting; the move goes on, and the same command picks it up."
63
+ : " Run the same command to see the code when it is ready."),
64
+ ];
65
+ }
66
+ const left = signIn.expiresAt ? Date.parse(signIn.expiresAt) - nowMs : null;
67
+ const minutes = left === null ? 0 : Math.ceil(left / 60_000);
68
+ const within = left !== null && left < 60_000 ? "under a minute" : `${minutes} minute${minutes === 1 ? "" : "s"}`;
69
+ const expires = signIn.expiresAt
70
+ ? ` The code expires at ${clock(signIn.expiresAt)} (in ${within})${attached ? "; a new one shows here if it does" : ""}.`
71
+ : "";
72
+ return [
73
+ `${name}: the move is waiting for you to sign the cloud bot in to Codex with your ChatGPT subscription.`,
74
+ ` Open ${signIn.url} and enter the code ${signIn.code}.${expires}`,
75
+ attached
76
+ ? " Waiting for the sign-in. Ctrl-C stops waiting; the move goes on, and the same command picks it up."
77
+ : " Then run the same command to continue.",
78
+ ];
79
+ }
80
+ /**
81
+ * Keep checking on a pending move until it finishes, fails, is closed in HQ
82
+ * (`check` throws an error named PromotionClosedError), or the wait runs out.
83
+ * Prints a new code whenever HQ shows one (the caller printed the first
84
+ * check's), says when a shown code expires or stops being shown, and rides out
85
+ * a few failed checks in a row. A sign-in error is never retried.
86
+ */
87
+ export async function waitForPromotion(name, first, deps) {
88
+ const interval = deps.intervalMs ?? PROMOTION_WAIT_INTERVAL_MS;
89
+ const deadline = deps.now() + (deps.maxWaitMs ?? PROMOTION_WAIT_MAX_MS);
90
+ const firstSignIn = promotionSignIn(first.result, first.pairing, deps.now());
91
+ let shown = firstSignIn?.status === "code-ready" ? firstSignIn : null;
92
+ let last = first;
93
+ let lastPhase = first.result.promotion.phase;
94
+ let failures = 0;
95
+ for (;;) {
96
+ if (deps.now() >= deadline) {
97
+ const minutes = Math.round((deps.maxWaitMs ?? PROMOTION_WAIT_MAX_MS) / 60_000);
98
+ deps.print(`${name}: still ${last.result.promotion.phase} after ${minutes} minute${minutes === 1 ? "" : "s"}. The move goes on; run the same command to keep waiting.`);
99
+ return last;
100
+ }
101
+ await deps.sleep(interval);
102
+ try {
103
+ last = await deps.check();
104
+ failures = 0;
105
+ }
106
+ catch (error) {
107
+ const err = error instanceof Error ? error : new Error(String(error));
108
+ if (err.name === "PromotionClosedError") {
109
+ deps.print(`${name}: ${err.message}`);
110
+ return last;
111
+ }
112
+ failures += 1;
113
+ if (err.name === "AuthError" || failures >= (deps.maxFailures ?? PROMOTION_WAIT_MAX_FAILURES))
114
+ throw err;
115
+ if (failures === 1)
116
+ deps.print(`${name}: could not check on the move (${err.message}). Trying again.`);
117
+ continue;
118
+ }
119
+ if (!last.result.pending) {
120
+ deps.print(`${name}: ${last.result.promotion.phase}.`);
121
+ return last;
122
+ }
123
+ if (last.failure) {
124
+ deps.print(`${name}: ${last.failure}`);
125
+ return last;
126
+ }
127
+ if (last.detailsError)
128
+ continue;
129
+ const now = deps.now();
130
+ const signIn = promotionSignIn(last.result, last.pairing, now);
131
+ if (signIn?.status === "code-ready") {
132
+ if (signIn.code !== shown?.code) {
133
+ for (const line of describePromotionSignIn(name, signIn, now, true))
134
+ deps.print(line);
135
+ }
136
+ shown = signIn;
137
+ }
138
+ else if (shown) {
139
+ const expired = shown.expiresAt !== null && Date.parse(shown.expiresAt) <= now;
140
+ deps.print(expired
141
+ ? `${name}: the code ${shown.code} expired. Waiting for HQ to show a new one.`
142
+ : `${name}: HQ no longer shows the code ${shown.code}. If you signed in, HQ is finishing the move; if not, a new code shows here.`);
143
+ shown = null;
144
+ }
145
+ if (last.result.promotion.phase !== lastPhase) {
146
+ lastPhase = last.result.promotion.phase;
147
+ if (!signIn)
148
+ deps.print(`${name}: ${lastPhase}.`);
149
+ }
150
+ }
151
+ }
152
+ //# sourceMappingURL=promote-sign-in.js.map
@@ -46,10 +46,21 @@ export interface LocalBotPromotionRuntime {
46
46
  model?: string;
47
47
  } | null;
48
48
  }
49
- /** The bot's brain as sent at prepare: a known runtime profile provider, and its model, win over bot.json. */
49
+ /**
50
+ * The bot's brain as sent at prepare: a known runtime profile provider, and its
51
+ * model, win over bot.json. The thinking level is always sent: the bot's own
52
+ * level as `hq bot status` shows it, the default (medium) included, because HQ
53
+ * fills a missing level with the cloud's own default (high). A level the brain's
54
+ * runtime does not have falls back to the default, as a restore does.
55
+ */
50
56
  export declare function promotionBrain(config: BotConfig, runtime?: LocalBotPromotionRuntime): BotPromotionBrain;
51
57
  /** Cloud bots run on Codex only for now. A bot already held names the cancel. */
52
58
  export declare function promotionBrainRefusal(config: BotConfig, brain: BotPromotionBrain, dir: string): Error | null;
59
+ /** The move a caller asked to continue is no longer open in HQ. Nothing was changed. */
60
+ export declare class PromotionClosedError extends Error {
61
+ readonly expected: true;
62
+ constructor(name: string, companyUid: string);
63
+ }
53
64
  /** One recoverable local-to-cloud step, used by CLI and desktop. Never kills the
54
65
  * local runtime, recopies provider login files, or changes another bot.
55
66
  * When this call creates the hold and fails before the server records the
@@ -66,6 +77,13 @@ export declare function promoteLocalBot(input: {
66
77
  restart?: () => Promise<unknown>;
67
78
  fleetHome?: string;
68
79
  onSnapshot?: (fleetState: FleetStateManifest | null) => void;
80
+ /**
81
+ * Only continue this operation: when HQ no longer shows it open (cancelled or being cancelled,
82
+ * gone, or replaced by another), throw PromotionClosedError before anything
83
+ * changes, instead of starting a new move. An attached `hq bot promote`
84
+ * passes the operation its first check returned.
85
+ */
86
+ continueOperation?: string;
69
87
  }): Promise<{
70
88
  promotion: BotPromotionState;
71
89
  pending: boolean;
@@ -3,7 +3,7 @@ import * as fs from "node:fs";
3
3
  import * as path from "node:path";
4
4
  import { randomUUID } from "node:crypto";
5
5
  import { BotApiError } from "./api.js";
6
- import { HQ_FLEET_RUNTIME_ENGINE_ID } from "./config.js";
6
+ import { BOT_EFFORT_LEVELS, botCompanySlug, DEFAULT_BOT_EFFORT, effectiveBotEffort, HQ_FLEET_RUNTIME_ENGINE_ID } from "./config.js";
7
7
  import { botCredsPath } from "./paths.js";
8
8
  import { FLEET_STATE_DIR, planFleetContinuity, snapshotBotContinuity, validateBotContinuity } from "./continuity.js";
9
9
  import { collectFleetState, FleetStateLimitError, fleetStateManifestOf } from "./fleet-state.js";
@@ -237,12 +237,20 @@ function withCancelHint(error, config, companyUid, dir) {
237
237
  return new Error(`${reason(error, dir)}. ${config.name} stays stopped on this computer while it is held for the move. ` +
238
238
  `Run the same command to continue, or cancel the move with: hq bot promote ${config.name} --company ${companyUid} --cancel`, { cause: error });
239
239
  }
240
- /** The bot's brain as sent at prepare: a known runtime profile provider, and its model, win over bot.json. */
240
+ /**
241
+ * The bot's brain as sent at prepare: a known runtime profile provider, and its
242
+ * model, win over bot.json. The thinking level is always sent: the bot's own
243
+ * level as `hq bot status` shows it, the default (medium) included, because HQ
244
+ * fills a missing level with the cloud's own default (high). A level the brain's
245
+ * runtime does not have falls back to the default, as a restore does.
246
+ */
241
247
  export function promotionBrain(config, runtime) {
242
248
  const profile = runtime?.brain?.() ?? null;
243
249
  const model = profile?.runtime ? profile.model?.trim() || config.model?.trim() : config.model?.trim() || profile?.model?.trim();
244
- const effort = config.effort?.trim();
245
- return { runtime: profile?.runtime ?? config.runtime, ...(model ? { model } : {}), ...(effort ? { effort } : {}) };
250
+ const brainRuntime = profile?.runtime ?? config.runtime;
251
+ const level = effectiveBotEffort(config).toLowerCase();
252
+ const effort = BOT_EFFORT_LEVELS[brainRuntime]?.includes(level) ? level : DEFAULT_BOT_EFFORT;
253
+ return { runtime: brainRuntime, ...(model ? { model } : {}), effort };
246
254
  }
247
255
  /** Cloud bots run on Codex only for now. A bot already held names the cancel. */
248
256
  export function promotionBrainRefusal(config, brain, dir) {
@@ -268,7 +276,7 @@ const CLOUD_HQ_ROOT = "/home/ec2-user/hq-agent";
268
276
  function assertCloudImportable(bundle, config) {
269
277
  try {
270
278
  validateBotContinuity(bundle, { agentUid: config.agentUid, ownerUid: config.ownerUid });
271
- planFleetContinuity(bundle, { agentUid: config.agentUid, ownerUid: config.ownerUid, hqRoot: CLOUD_HQ_ROOT, ...(config.companySlug ? { companySlug: config.companySlug } : {}) });
279
+ planFleetContinuity(bundle, { agentUid: config.agentUid, ownerUid: config.ownerUid, hqRoot: CLOUD_HQ_ROOT, ...(botCompanySlug(config) ? { companySlug: botCompanySlug(config) } : {}) });
272
280
  }
273
281
  catch (error) {
274
282
  const reason = error instanceof Error ? error.message : String(error);
@@ -296,6 +304,14 @@ function skillsToRemove(reason, state) {
296
304
  }
297
305
  return [...weight].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).map(([skill]) => skill);
298
306
  }
307
+ /** The move a caller asked to continue is no longer open in HQ. Nothing was changed. */
308
+ export class PromotionClosedError extends Error {
309
+ expected = true;
310
+ constructor(name, companyUid) {
311
+ super(`HQ no longer shows this move of ${name} as open: it was cancelled, or another move replaced it. Nothing more was done. See where it stands with: hq bot promote ${name} --company ${companyUid}`);
312
+ this.name = "PromotionClosedError";
313
+ }
314
+ }
299
315
  /** One recoverable local-to-cloud step, used by CLI and desktop. Never kills the
300
316
  * local runtime, recopies provider login files, or changes another bot.
301
317
  * When this call creates the hold and fails before the server records the
@@ -338,6 +354,10 @@ export async function promoteLocalBot(input) {
338
354
  if (localHold && localHold.companyUid !== companyUid)
339
355
  throw otherCompanyError(config, localHold.companyUid, companyUid, false);
340
356
  let existing = await readPromotionStatus(api, config, companyUid, dir);
357
+ if (input.continueOperation !== undefined &&
358
+ (!existing || existing.operationId !== input.continueOperation || existing.phase === "cancelled" || existing.cancelRequested === true)) {
359
+ throw new PromotionClosedError(config.name, companyUid);
360
+ }
341
361
  let priorOrigin = null;
342
362
  let canceledHere = false;
343
363
  if (existing?.phase === "cancelled") {
@@ -1,8 +1,10 @@
1
1
  /**
2
2
  * personal/workers/<name>/ scaffold for a local bot (local-bots US-005/US-006).
3
- * Never overwrites an existing file (the bot edits its own memory).
3
+ * Never overwrites an existing file (the bot edits its own memory). A company
4
+ * bot gets the same folder, labelled as a company bot of its company.
4
5
  */
5
6
  import * as fs from "node:fs";
7
+ import type { BotKind } from "./config.js";
6
8
  export interface ScaffoldResult {
7
9
  /** personal/workers/<name> (absolute). */
8
10
  dir: string;
@@ -20,10 +22,25 @@ export interface ScaffoldOptions {
20
22
  * Default: personal/workers/<name>/memory.
21
23
  */
22
24
  memoryDir?: string;
25
+ /**
26
+ * "company" for a company bot: worker.yaml and persona.md then describe a
27
+ * company bot (acts as itself, with its own permissions) instead of the
28
+ * owner's personal bot. Default: personal.
29
+ */
30
+ kind?: BotKind;
31
+ /**
32
+ * A company bot's company when it has exactly one, recorded as the
33
+ * `company:` label in worker.yaml. The persona never names it: the bot's
34
+ * instructions bind its turns to its current company, and a company named
35
+ * in persona.md would go stale when `hq bot companies` changes the list.
36
+ */
37
+ company?: string;
23
38
  }
24
39
  export declare function botSpokenName(name: string, displayName?: string): string;
25
- export declare function renderWorkerYaml(name: string, agentUid: string, runtime: string, memoryDir?: string, displayName?: string): string;
26
- export declare function renderPersonaMd(name: string, displayName?: string): string;
40
+ export declare function renderWorkerYaml(name: string, agentUid: string, runtime: string, memoryDir?: string, displayName?: string, companyBot?: {
41
+ company?: string;
42
+ }): string;
43
+ export declare function renderPersonaMd(name: string, displayName?: string, kind?: BotKind): string;
27
44
  export declare function renderMemoryReadme(name: string, displayName?: string): string;
28
45
  type ScaffoldFs = Pick<typeof fs, "existsSync" | "mkdirSync" | "writeFileSync">;
29
46
  /** Absolute memory folder for a scaffold: the override (relative to hqRoot unless absolute) or the default. */
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * personal/workers/<name>/ scaffold for a local bot (local-bots US-005/US-006).
3
- * Never overwrites an existing file (the bot edits its own memory).
3
+ * Never overwrites an existing file (the bot edits its own memory). A company
4
+ * bot gets the same folder, labelled as a company bot of its company.
4
5
  */
5
6
  import * as fs from "node:fs";
6
7
  import * as path from "node:path";
@@ -8,13 +9,19 @@ import { botWorkerRelDir } from "./paths.js";
8
9
  export function botSpokenName(name, displayName) {
9
10
  return displayName?.trim() || name;
10
11
  }
11
- export function renderWorkerYaml(name, agentUid, runtime, memoryDir, displayName) {
12
+ export function renderWorkerYaml(name, agentUid, runtime, memoryDir, displayName, companyBot) {
12
13
  const memory = (memoryDir?.trim() || `personal/workers/${name}/memory`).replace(/\/+$/, "");
14
+ const companySlug = companyBot?.company?.trim();
15
+ const identity = companyBot
16
+ ? ` description: "Company HQ bot (${runtime}) — runs on this computer and acts as itself, with its own permissions, in its company"\n` +
17
+ ` type: CompanyBot` +
18
+ (companySlug ? `\n company: ${companySlug}` : "")
19
+ : ` description: "Personal local HQ bot (${runtime}) — runs on this computer with the owner's permissions"\n` +
20
+ ` type: PersonalBot`;
13
21
  return `worker:
14
22
  id: ${name}
15
23
  name: ${JSON.stringify(botSpokenName(name, displayName))}
16
- description: "Personal local HQ bot (${runtime}) — runs on this computer with the owner's permissions"
17
- type: PersonalBot
24
+ ${identity}
18
25
  version: "1.0"
19
26
  kind: local-bot
20
27
  agent_uid: ${agentUid}
@@ -30,12 +37,15 @@ context:
30
37
  - ${memory}/
31
38
  `;
32
39
  }
33
- export function renderPersonaMd(name, displayName) {
40
+ export function renderPersonaMd(name, displayName, kind = "personal") {
34
41
  const spoken = botSpokenName(name, displayName);
35
42
  const handle = spoken === name ? "" : ` Your hq bot handle is \`${name}\`; use it only in \`hq bot\` commands.`;
43
+ const who = kind === "company"
44
+ ? "a company bot that lives in this HQ. You act as yourself, with your own permissions, only in your company's context."
45
+ : "a personal assistant bot that lives in this HQ.";
36
46
  return `# ${spoken}
37
47
 
38
- You are ${spoken}, a personal assistant bot that lives in this HQ.${handle}
48
+ You are ${spoken}, ${who}${handle}
39
49
 
40
50
  ## Voice
41
51
 
@@ -93,8 +103,8 @@ export function scaffoldBotWorker(hqRoot, name, agentUid, runtime, io = fs, opts
93
103
  const result = scaffoldBotMemory(hqRoot, name, io, opts);
94
104
  const { dir } = result;
95
105
  io.mkdirSync(dir, { recursive: true });
96
- writeIfMissing(io, path.join(dir, "worker.yaml"), renderWorkerYaml(name, agentUid, runtime, opts.memoryDir, opts.displayName), result);
97
- writeIfMissing(io, path.join(dir, "persona.md"), renderPersonaMd(name, opts.displayName), result);
106
+ writeIfMissing(io, path.join(dir, "worker.yaml"), renderWorkerYaml(name, agentUid, runtime, opts.memoryDir, opts.displayName, opts.kind === "company" ? { company: opts.company } : undefined), result);
107
+ writeIfMissing(io, path.join(dir, "persona.md"), renderPersonaMd(name, opts.displayName, opts.kind), result);
98
108
  return result;
99
109
  }
100
110
  //# sourceMappingURL=scaffold.js.map
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Claude Code `@import` paths that never load.
3
+ *
4
+ * Claude Code finds imports with `(?:^|\s)@((?:[^\s\\]|\\ )+)` and turns each
5
+ * `\ ` into a space, so `\ ` is an escaped space and any other backslash ends
6
+ * the path. `@C:\Users\me\hq\.claude\CLAUDE.md` therefore imports `C:` and
7
+ * nothing loads, while `@C:/Users/me/hq/.claude/CLAUDE.md` loads on Windows
8
+ * too. Nothing reports the failure (feedback_362cdca7).
9
+ *
10
+ * Pure text functions only. Claude Code does not import from code spans,
11
+ * fenced or indented code blocks, or HTML comments, so neither do these.
12
+ */
13
+ /** One `@import` whose path holds a backslash that is not an escaped space. */
14
+ export interface BackslashImport {
15
+ /** One-based line number. */
16
+ line: number;
17
+ /** The import path as written, without the leading `@`. */
18
+ path: string;
19
+ }
20
+ /** Every `@import` in `text` whose path holds a backslash that is not an escaped space. */
21
+ export declare function findBackslashImports(text: string): BackslashImport[];
22
+ /**
23
+ * An import path written as Claude Code reads it: each path backslash becomes
24
+ * `/`, an escaped space (`\ `) stays, and an unescaped space is escaped.
25
+ */
26
+ export declare function toForwardSlashes(importPath: string): string;
27
+ /**
28
+ * `text` with each such `@import` path rewritten by {@link toForwardSlashes}.
29
+ * Nothing else changes: other text, code, comments and line endings keep their
30
+ * bytes. Returns `text` itself when there is nothing to change.
31
+ */
32
+ export declare function normalizeBackslashImports(text: string): string;
33
+ /** The import line inside the hq-anywhere managed block of a CLAUDE.md file. */
34
+ export interface HqBlockImport {
35
+ /** One-based line number. */
36
+ line: number;
37
+ /** Everything after the `@`, trailing whitespace trimmed. */
38
+ raw: string;
39
+ /** The path Claude Code imports from that line (its tokenizer, `\ ` as a space). */
40
+ claudePath: string;
41
+ /** The path the line means: `\ ` as a space, every other backslash as `/`. */
42
+ intendedPath: string;
43
+ }
44
+ /** The managed block's import line, or null when the file has no such block. */
45
+ export declare function findHqBlockImport(text: string): HqBlockImport | null;
46
+ /**
47
+ * `text` with the managed block's import line rewritten as the path it means,
48
+ * forward slashes and every space escaped (`\ `), so Claude Code reads the
49
+ * whole path. Only that one line changes; `text` itself when nothing would.
50
+ */
51
+ export declare function escapeHqBlockImport(text: string): string;
52
+ //# sourceMappingURL=claude-md-imports.d.ts.map