@indigoai-us/hq-cli 5.345.225 → 5.345.226

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 (46) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/dist/command-catalog.generated.d.ts +78 -0
  3. package/dist/command-catalog.generated.js +97 -0
  4. package/dist/commands/daemon.js +1 -1
  5. package/dist/commands/deploy-domains.js +38 -2
  6. package/dist/commands/lanes-accounts.d.ts +14 -0
  7. package/dist/commands/lanes-accounts.js +119 -0
  8. package/dist/commands/lanes-move.js +10 -0
  9. package/dist/commands/lanes-shared.js +9 -0
  10. package/dist/commands/lanes.js +137 -12
  11. package/dist/commands/sync-held.d.ts +22 -0
  12. package/dist/commands/sync-held.js +167 -18
  13. package/dist/hq-cloud-sync-runner/bin/sync-runner.js +4845 -2524
  14. package/dist/hq-cloud-sync-runner/package.json +1 -1
  15. package/dist/lib/capacity/accounts.d.ts +4 -0
  16. package/dist/lib/capacity/accounts.js +4 -0
  17. package/dist/lib/capacity/route.js +14 -0
  18. package/dist/lib/capacity/sign-in.d.ts +18 -0
  19. package/dist/lib/capacity/sign-in.js +34 -1
  20. package/dist/lib/daemon/catalog.d.ts +1 -0
  21. package/dist/lib/daemon/catalog.js +1 -1
  22. package/dist/lib/daemon/hook-requests.d.ts +76 -0
  23. package/dist/lib/daemon/hook-requests.js +481 -0
  24. package/dist/lib/daemon/lanes-reconcile-status.d.ts +35 -0
  25. package/dist/lib/daemon/lanes-reconcile-status.js +86 -0
  26. package/dist/lib/daemon/ops/policy.d.ts +1 -1
  27. package/dist/lib/daemon/ops/policy.js +43 -4
  28. package/dist/lib/daemon/run.js +37 -4
  29. package/dist/lib/daemon/server.js +6 -1
  30. package/dist/lib/daemon/supervisor.d.ts +2 -0
  31. package/dist/lib/flag-registry-worker-source.generated.d.ts +1 -1
  32. package/dist/lib/flag-registry-worker-source.generated.js +1 -1
  33. package/dist/lib/lanes/account-company.d.ts +7 -1
  34. package/dist/lib/lanes/account-company.js +22 -4
  35. package/dist/lib/lanes/account-ownership.d.ts +65 -0
  36. package/dist/lib/lanes/account-ownership.js +134 -0
  37. package/dist/lib/lanes/accounts.js +9 -2
  38. package/dist/lib/lanes/claude-balance.js +9 -3
  39. package/dist/lib/lanes/config.js +17 -0
  40. package/dist/lib/lanes/host-capacity.d.ts +19 -0
  41. package/dist/lib/lanes/host-capacity.js +37 -0
  42. package/dist/lib/lanes/reconcile.js +44 -3
  43. package/dist/lib/lanes/spawn.d.ts +0 -10
  44. package/dist/lib/lanes/spawn.js +51 -1
  45. package/dist/lib/lanes/types.d.ts +12 -0
  46. package/package.json +8 -8
@@ -10,9 +10,15 @@ export declare function companyEnforcementActive(providerAccounts: ProviderAccou
10
10
  /**
11
11
  * Account ownership is explicit; names and homes never imply a tenant.
12
12
  * Pass the provider's account map to apply the opt-in rule above.
13
+ * A login whose `holder` names another person never matches (PS-006): the
14
+ * owner's own logins serve any of the owner's businesses, other people's do not.
13
15
  */
14
16
  export declare function accountMatchesCompany(account: AccountConfig | undefined, company: LaneCompanyRef | null, providerAccounts?: ProviderAccounts): boolean;
15
- /** Legacy untagged accounts may retain an existing lane, never acquire one. */
17
+ /**
18
+ * Legacy untagged accounts may retain an existing lane, never acquire one.
19
+ * A login held by another person retains nothing (PS-006): the lane moves off
20
+ * it, or is refused, on its next spawn, resume or recovery.
21
+ */
16
22
  export declare function accountMayRetainLane(account: AccountConfig | undefined, company: LaneCompanyRef | null, providerAccounts?: ProviderAccounts): boolean;
17
23
  /**
18
24
  * When enforcement is active and every enabled candidate was excluded only by
@@ -1,3 +1,4 @@
1
+ import { accountHeldByOther } from "./account-ownership.js";
1
2
  import { LanesError } from "./errors.js";
2
3
  /**
3
4
  * Company enforcement is opt-in per provider: it begins once any account for
@@ -12,30 +13,47 @@ export function companyEnforcementActive(providerAccounts) {
12
13
  /**
13
14
  * Account ownership is explicit; names and homes never imply a tenant.
14
15
  * Pass the provider's account map to apply the opt-in rule above.
16
+ * A login whose `holder` names another person never matches (PS-006): the
17
+ * owner's own logins serve any of the owner's businesses, other people's do not.
15
18
  */
16
19
  export function accountMatchesCompany(account, company, providerAccounts) {
17
20
  if (account === undefined)
18
21
  return false;
22
+ if (accountHeldByOther(account))
23
+ return false;
19
24
  if (providerAccounts !== undefined && !companyEnforcementActive(providerAccounts))
20
25
  return true;
21
26
  if (company === null)
22
27
  return account.company === undefined;
23
28
  return account.company === company.uid || account.company === company.slug;
24
29
  }
25
- /** Legacy untagged accounts may retain an existing lane, never acquire one. */
30
+ /**
31
+ * Legacy untagged accounts may retain an existing lane, never acquire one.
32
+ * A login held by another person retains nothing (PS-006): the lane moves off
33
+ * it, or is refused, on its next spawn, resume or recovery.
34
+ */
26
35
  export function accountMayRetainLane(account, company, providerAccounts) {
27
- return account !== undefined && (account.company === undefined || accountMatchesCompany(account, company, providerAccounts));
36
+ if (account === undefined || accountHeldByOther(account))
37
+ return false;
38
+ return account.company === undefined || accountMatchesCompany(account, company, providerAccounts);
28
39
  }
29
40
  /**
30
41
  * When enforcement is active and every enabled candidate was excluded only by
31
42
  * company ownership, name the problem instead of reporting no enabled account.
32
43
  */
33
44
  export function companyMismatchError(input) {
34
- if (!companyEnforcementActive(input.providerAccounts))
35
- return undefined;
36
45
  const enabled = input.candidates.filter((id) => input.providerAccounts[id]?.enabled === true);
37
46
  if (enabled.length === 0)
38
47
  return undefined;
48
+ if (enabled.every((id) => accountHeldByOther(input.providerAccounts[id]))) {
49
+ const held = enabled.map((id) => ({ account: id, holder: input.providerAccounts[id]?.holder ?? null }));
50
+ return new LanesError("account_held_by_other", `Every enabled ${input.provider} account is held by another person and is not used for lanes: ` +
51
+ `${held.map((row) => `${row.account} (${row.holder})`).join(", ")}. ` +
52
+ "Sign in with one of your own logins. Change a holder to owner only if that login is really yours: " +
53
+ `hq lanes accounts set-owner ${input.provider} <id> --holder owner`, { provider: input.provider, held_accounts: held, config_key: `providers.${input.provider}.accounts.<id>.holder`, config_file: "personal/lanes/config.json" });
54
+ }
55
+ if (!companyEnforcementActive(input.providerAccounts))
56
+ return undefined;
39
57
  if (enabled.some((id) => accountMatchesCompany(input.providerAccounts[id], input.company, input.providerAccounts)))
40
58
  return undefined;
41
59
  const companyLabel = input.company === null ? "(no company)" : input.company.slug;
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Owning business and holder on every lane account (PS-006).
3
+ *
4
+ * `owning_company` records which business owns a login: a company slug,
5
+ * `personal`, or `unknown`. It is for reporting and ranking. The owner's own
6
+ * logins may be used for any of the owner's businesses (decision D5), so it
7
+ * is never a lane filter; `company` stays the only company filter.
8
+ *
9
+ * `holder` records who holds the login: `owner` for the person this HQ
10
+ * belongs to, or another named person. A login held by another person is
11
+ * never picked for lane work and is listed without its account id when the
12
+ * host's capacity is printed.
13
+ *
14
+ * Accounts written before this change have neither field. They read as
15
+ * `unknown`, keep working as before, and carry a warning naming the command
16
+ * that records both values.
17
+ */
18
+ import type { AccountConfig, LaneProvider } from "./types.js";
19
+ export declare const OWNER_HOLDER = "owner";
20
+ export declare const PERSONAL_OWNING_COMPANY = "personal";
21
+ export declare const UNKNOWN_OWNING_COMPANY = "unknown";
22
+ export declare const UNKNOWN_HOLDER = "unknown";
23
+ export type OwnershipField = "owning_company" | "holder";
24
+ export interface AccountOwnership {
25
+ /** The configured slug, `personal`, or `unknown`. Falls back to `company` when only that is set. */
26
+ owning_company: string;
27
+ /** Where `owning_company` came from. */
28
+ owning_company_source: "config" | "company" | "unset";
29
+ /** `owner`, another person's name, or `unknown` when unset. */
30
+ holder: string;
31
+ holder_source: "config" | "unset";
32
+ /** Fields with no recorded value. Empty when both are recorded. */
33
+ ownership_missing: OwnershipField[];
34
+ }
35
+ /**
36
+ * Reserved words are matched case-insensitively and stored in lowercase:
37
+ * "Personal" and "UNKNOWN" become `personal` and `unknown`. Any other value is
38
+ * returned unchanged (and then validated as a slug, which must be lowercase).
39
+ */
40
+ export declare function normalizeOwningCompany<T>(value: T): T | string;
41
+ /** "Owner", "OWNER" and "Unknown" become `owner` and `unknown`; names are kept as given. */
42
+ export declare function normalizeHolder<T>(value: T): T | string;
43
+ /** null when valid, else the reason. Pass the normalized value. */
44
+ export declare function owningCompanyProblem(value: unknown): string | null;
45
+ /** null when valid, else the reason. Pass the normalized value. */
46
+ export declare function holderProblem(value: unknown): string | null;
47
+ export declare function accountOwnership(account: AccountConfig | undefined): AccountOwnership;
48
+ /**
49
+ * True only when the holder is recorded as another person. An unset holder is
50
+ * not "another person": accounts from before PS-006 keep their lane use.
51
+ */
52
+ export declare function accountHeldByOther(account: AccountConfig | undefined): boolean;
53
+ /**
54
+ * true when the recorded holder is the owner, false when it names another
55
+ * person, null when no holder is recorded or it is recorded as unknown.
56
+ */
57
+ export declare function heldByOwner(account: AccountConfig | undefined): boolean | null;
58
+ export declare function setOwnerCommand(provider: LaneProvider | string, id: string): string;
59
+ /** Warning for an enabled account missing either field; undefined when nothing is missing. */
60
+ export declare function ownershipWarning(provider: LaneProvider | string, id: string, account: AccountConfig | undefined): {
61
+ message: string;
62
+ missing: OwnershipField[];
63
+ fix_command: string;
64
+ } | undefined;
65
+ //# sourceMappingURL=account-ownership.d.ts.map
@@ -0,0 +1,134 @@
1
+ /**
2
+ * Owning business and holder on every lane account (PS-006).
3
+ *
4
+ * `owning_company` records which business owns a login: a company slug,
5
+ * `personal`, or `unknown`. It is for reporting and ranking. The owner's own
6
+ * logins may be used for any of the owner's businesses (decision D5), so it
7
+ * is never a lane filter; `company` stays the only company filter.
8
+ *
9
+ * `holder` records who holds the login: `owner` for the person this HQ
10
+ * belongs to, or another named person. A login held by another person is
11
+ * never picked for lane work and is listed without its account id when the
12
+ * host's capacity is printed.
13
+ *
14
+ * Accounts written before this change have neither field. They read as
15
+ * `unknown`, keep working as before, and carry a warning naming the command
16
+ * that records both values.
17
+ */
18
+ export const OWNER_HOLDER = "owner";
19
+ export const PERSONAL_OWNING_COMPANY = "personal";
20
+ export const UNKNOWN_OWNING_COMPANY = "unknown";
21
+ export const UNKNOWN_HOLDER = "unknown";
22
+ const SLUG = /^[a-z0-9][a-z0-9-]{0,62}$/;
23
+ const HOLDER_MAX = 64;
24
+ const RESERVED_OWNING = new Set([PERSONAL_OWNING_COMPANY, UNKNOWN_OWNING_COMPANY]);
25
+ const RESERVED_HOLDER = new Set([OWNER_HOLDER, UNKNOWN_HOLDER]);
26
+ /**
27
+ * Reserved words are matched case-insensitively and stored in lowercase:
28
+ * "Personal" and "UNKNOWN" become `personal` and `unknown`. Any other value is
29
+ * returned unchanged (and then validated as a slug, which must be lowercase).
30
+ */
31
+ export function normalizeOwningCompany(value) {
32
+ return typeof value === "string" && RESERVED_OWNING.has(value.toLowerCase()) ? value.toLowerCase() : value;
33
+ }
34
+ /** "Owner", "OWNER" and "Unknown" become `owner` and `unknown`; names are kept as given. */
35
+ export function normalizeHolder(value) {
36
+ return typeof value === "string" && RESERVED_HOLDER.has(value.toLowerCase()) ? value.toLowerCase() : value;
37
+ }
38
+ /** null when valid, else the reason. Pass the normalized value. */
39
+ export function owningCompanyProblem(value) {
40
+ if (typeof value !== "string")
41
+ return "must be a string";
42
+ if (!SLUG.test(value))
43
+ return "must be a company slug (lowercase letters, digits, hyphens), personal or unknown";
44
+ return null;
45
+ }
46
+ /**
47
+ * Characters a holder name may not contain: C0 and C1 controls, DEL, bidi
48
+ * embeddings, overrides, isolates and marks, and zero-width characters. They
49
+ * can make one name print as another.
50
+ */
51
+ function forbiddenHolderChar(code) {
52
+ return code < 0x20 ||
53
+ (code >= 0x7f && code <= 0x9f) ||
54
+ code === 0x061c ||
55
+ (code >= 0x200b && code <= 0x200f) ||
56
+ (code >= 0x202a && code <= 0x202e) ||
57
+ (code >= 0x2060 && code <= 0x2069) ||
58
+ code === 0xfeff;
59
+ }
60
+ /** null when valid, else the reason. Pass the normalized value. */
61
+ export function holderProblem(value) {
62
+ if (typeof value !== "string")
63
+ return "must be a string";
64
+ if (value.trim() === "" || value.trim() !== value)
65
+ return "must be non-empty with no surrounding whitespace";
66
+ if (value.length > HOLDER_MAX)
67
+ return `must be at most ${HOLDER_MAX} characters`;
68
+ if ([...value].some((ch) => forbiddenHolderChar(ch.codePointAt(0) ?? 0))) {
69
+ return "must not contain control, bidi or zero-width characters";
70
+ }
71
+ return null;
72
+ }
73
+ export function accountOwnership(account) {
74
+ const missing = [];
75
+ let owning;
76
+ let owningSource;
77
+ if (account?.owning_company !== undefined) {
78
+ owning = account.owning_company;
79
+ owningSource = "config";
80
+ }
81
+ else if (account?.company !== undefined && SLUG.test(account.company)) {
82
+ owning = account.company;
83
+ owningSource = "company";
84
+ }
85
+ else {
86
+ owning = UNKNOWN_OWNING_COMPANY;
87
+ owningSource = "unset";
88
+ missing.push("owning_company");
89
+ }
90
+ const holderSet = account?.holder !== undefined;
91
+ if (!holderSet)
92
+ missing.push("holder");
93
+ return {
94
+ owning_company: owning,
95
+ owning_company_source: owningSource,
96
+ holder: holderSet ? account.holder : UNKNOWN_HOLDER,
97
+ holder_source: holderSet ? "config" : "unset",
98
+ ownership_missing: missing,
99
+ };
100
+ }
101
+ /**
102
+ * True only when the holder is recorded as another person. An unset holder is
103
+ * not "another person": accounts from before PS-006 keep their lane use.
104
+ */
105
+ export function accountHeldByOther(account) {
106
+ return account?.holder !== undefined && !RESERVED_HOLDER.has(account.holder.toLowerCase());
107
+ }
108
+ /**
109
+ * true when the recorded holder is the owner, false when it names another
110
+ * person, null when no holder is recorded or it is recorded as unknown.
111
+ */
112
+ export function heldByOwner(account) {
113
+ if (account?.holder === undefined || account.holder.toLowerCase() === UNKNOWN_HOLDER)
114
+ return null;
115
+ return !accountHeldByOther(account);
116
+ }
117
+ export function setOwnerCommand(provider, id) {
118
+ return `hq lanes accounts set-owner ${provider} ${id} --owning-company <slug|personal|unknown> --holder <owner|name>`;
119
+ }
120
+ /** Warning for an enabled account missing either field; undefined when nothing is missing. */
121
+ export function ownershipWarning(provider, id, account) {
122
+ if (account?.enabled !== true)
123
+ return undefined;
124
+ const { ownership_missing: missing } = accountOwnership(account);
125
+ if (missing.length === 0)
126
+ return undefined;
127
+ const fix = setOwnerCommand(provider, id);
128
+ return {
129
+ message: `${provider} account ${id} has no ${missing.join(" and no ")}. Set it with: ${fix}`,
130
+ missing,
131
+ fix_command: fix,
132
+ };
133
+ }
134
+ //# sourceMappingURL=account-ownership.js.map
@@ -12,6 +12,7 @@
12
12
  */
13
13
  import * as fs from "node:fs";
14
14
  import { effectiveAccountHome } from "./account-home.js";
15
+ import { accountHeldByOther } from "./account-ownership.js";
15
16
  import * as path from "node:path";
16
17
  import { AccountResolutionError } from "./errors.js";
17
18
  import { isTerminalLaneState } from "./types.js";
@@ -285,9 +286,15 @@ export function selectBalancedAccount(provider, config, ctx = {}) {
285
286
  const providerCfg = config.providers[provider];
286
287
  const existsSync = ctx.existsSync ?? ((p) => fs.existsSync(p));
287
288
  const allowed = ctx.allowedAccounts;
288
- const enabled = enabledIds(providerCfg).filter((id) => allowed === undefined || allowed.includes(id));
289
+ const allowedEnabled = enabledIds(providerCfg).filter((id) => allowed === undefined || allowed.includes(id));
290
+ // PS-006: a login whose holder is another person is never a balanced pick,
291
+ // whichever caller asks (Outpost pickup and model pre-checks pass no list).
292
+ const enabled = allowedEnabled.filter((id) => !accountHeldByOther(providerCfg.accounts[id]));
289
293
  if (enabled.length === 0) {
290
- throw new AccountResolutionError("no_enabled_account", `No enabled account for provider ${provider}`, { provider, ineligible: "none_enabled" });
294
+ const held = allowedEnabled.length > 0;
295
+ throw new AccountResolutionError("no_enabled_account", held
296
+ ? `Every enabled account for provider ${provider} is held by another person and is not used for lanes`
297
+ : `No enabled account for provider ${provider}`, { provider, ineligible: held ? "held_by_other" : "none_enabled" });
291
298
  }
292
299
  const proven = [];
293
300
  const identities = new Map();
@@ -1,5 +1,6 @@
1
1
  import { LanesError } from "./errors.js";
2
2
  import { accountMatchesCompany, accountMayRetainLane } from "./account-company.js";
3
+ import { accountHeldByOther } from "./account-ownership.js";
3
4
  import { quotaBlockFor } from "./quota.js";
4
5
  export const BALANCE_LIVE_STATES = ["running", "queued", "awaiting_input"];
5
6
  export const BALANCE_MOVABLE_STATES = ["interrupted", "done", "awaiting_input"];
@@ -138,7 +139,8 @@ function buildLoads(input) {
138
139
  const companyMismatch = input.company !== undefined && !(account === input.retainedAccount
139
140
  ? accountMayRetainLane(configAccounts[account], input.company, configAccounts)
140
141
  : accountMatchesCompany(configAccounts[account], input.company, configAccounts));
141
- const ineligible = companyMismatch ? "company_mismatch" : targetIneligibilityReason(account, configAccounts[account]?.enabled === true, input.allowedAccounts, targetLoad) ?? (quotaBlock?.blocked === true ? "quota_held" : undefined);
142
+ // PS-006: another person's login is never eligible, with or without a lane company.
143
+ const ineligible = accountHeldByOther(configAccounts[account]) ? "held_by_other" : companyMismatch ? "company_mismatch" : targetIneligibilityReason(account, configAccounts[account]?.enabled === true, input.allowedAccounts, targetLoad) ?? (quotaBlock?.blocked === true ? "quota_held" : undefined);
142
144
  if (ineligible !== undefined)
143
145
  skipped.push({ account, host: targetHost, reason: ineligible });
144
146
  const knownCounts = hosts.flatMap((host) => host.live_lanes === null ? [] : [host.live_lanes]);
@@ -286,7 +288,11 @@ export function planClaudeBalanceMoves(input) {
286
288
  if (!hostSnapshot)
287
289
  continue;
288
290
  const sourceStatus = hostSnapshot.capacity.providers.claude.accounts[source];
289
- if (sourceStatus === undefined)
291
+ // PS-006: buildHostCapacitySnapshot leaves another person's login out of
292
+ // `accounts`, so a missing row must not hide it; such a source is always
293
+ // unavailable and its lanes are moved off.
294
+ const sourceHeldByOther = accountHeldByOther(input.config.providers.claude.accounts[source]);
295
+ if (sourceStatus === undefined && !sourceHeldByOther)
290
296
  continue;
291
297
  const candidates = Object.keys(input.config.providers.claude.accounts)
292
298
  .filter((account) => accountMatchesCompany(input.config.providers.claude.accounts[account], input.laneCompany ? input.laneCompany(lane) : lane.company, input.config.providers.claude.accounts))
@@ -298,7 +304,7 @@ export function planClaudeBalanceMoves(input) {
298
304
  }))
299
305
  .filter((candidate) => candidate.targetStatus?.enabled === true && candidate.targetStatus.logged_in === true)
300
306
  .sort((a, b) => a.load - b.load || a.account.localeCompare(b.account));
301
- const sourceUnavailable = sourceStatus.enabled !== true || sourceStatus.logged_in !== true;
307
+ const sourceUnavailable = sourceHeldByOther || sourceStatus?.enabled !== true || sourceStatus.logged_in !== true;
302
308
  const target = candidates[0];
303
309
  const laneIsLive = isBalanceLive(lane);
304
310
  if (!target || (!sourceUnavailable && (!laneIsLive || target.load >= sourceLoad)))
@@ -9,6 +9,7 @@
9
9
  import * as fs from "node:fs";
10
10
  import * as os from "node:os";
11
11
  import * as path from "node:path";
12
+ import { holderProblem, normalizeHolder, normalizeOwningCompany, owningCompanyProblem } from "./account-ownership.js";
12
13
  import { parseConfigEffort } from "./effort.js";
13
14
  import { LanesConfigError } from "./errors.js";
14
15
  import { CONFIG_SCHEMA_VERSION, LANE_PROVIDERS, isLaneProvider, parseMajorSchema, } from "./types.js";
@@ -200,6 +201,22 @@ function parseAccount(provider, id, raw, deps) {
200
201
  }
201
202
  account.company = raw.company;
202
203
  }
204
+ if (raw.owning_company !== undefined) {
205
+ raw.owning_company = normalizeOwningCompany(raw.owning_company);
206
+ const problem = owningCompanyProblem(raw.owning_company);
207
+ if (problem !== null) {
208
+ throw new LanesConfigError("invalid_config", `providers.${provider}.accounts.${id}.owning_company ${problem}`, { provider, account: id, field: `providers.${provider}.accounts.${id}.owning_company` });
209
+ }
210
+ account.owning_company = raw.owning_company;
211
+ }
212
+ if (raw.holder !== undefined) {
213
+ raw.holder = normalizeHolder(raw.holder);
214
+ const problem = holderProblem(raw.holder);
215
+ if (problem !== null) {
216
+ throw new LanesConfigError("invalid_config", `providers.${provider}.accounts.${id}.holder ${problem}`, { provider, account: id, field: `providers.${provider}.accounts.${id}.holder` });
217
+ }
218
+ account.holder = raw.holder;
219
+ }
203
220
  if (raw.hosts !== undefined) {
204
221
  const field = `providers.${provider}.accounts.${id}.hosts`;
205
222
  if (!isPlainObject(raw.hosts)) {
@@ -26,6 +26,14 @@ export interface HostCapacityAccount {
26
26
  awaiting_input: number;
27
27
  live: number;
28
28
  };
29
+ /**
30
+ * The business that owns this login (slug, `personal` or `unknown`) and who
31
+ * holds it (`owner`, or `unknown` when not recorded). PS-006. Absent on
32
+ * snapshots from older CLIs. Logins held by another person are not in
33
+ * `accounts`; see `HostCapacitySnapshot.other_holder_logins`.
34
+ */
35
+ owning_company?: string;
36
+ holder?: string;
29
37
  /** Provider-reported usage, when a host can read a recent sample. */
30
38
  usage?: {
31
39
  five_hour_percent?: number;
@@ -66,6 +74,17 @@ export interface HostCapacitySnapshot {
66
74
  * snapshot from another host is parsed.
67
75
  */
68
76
  compute_stale?: boolean;
77
+ /**
78
+ * Logins on this host held by another person (PS-006). Engine and holder
79
+ * only: the account id, home and owning business are left out, and these
80
+ * logins are never offered for placement. Absent when there are none and on
81
+ * snapshots from older CLIs.
82
+ */
83
+ other_holder_logins?: OtherHolderLogin[];
84
+ }
85
+ export interface OtherHolderLogin {
86
+ engine: LaneProvider;
87
+ holder: string;
69
88
  }
70
89
  /** The printed form: `hq runners capacity --json` and the remote capacity probe. */
71
90
  export type HostCapacitySnapshotWire = Omit<HostCapacitySnapshot, "host" | "host_aliases"> & {
@@ -1,4 +1,5 @@
1
1
  import { accountStatus } from "./accounts.js";
2
+ import { accountHeldByOther, accountOwnership, holderProblem, owningCompanyProblem } from "./account-ownership.js";
2
3
  import { accountMaxRunning } from "./config.js";
3
4
  import { laneOccupiesRunningSlot, laneRunsOnHost, } from "./admission.js";
4
5
  import { HOST_ALIAS_LIMIT } from "./canonical-host.js";
@@ -34,6 +35,7 @@ export function buildHostCapacitySnapshot(input) {
34
35
  lane.host.kind === "local" &&
35
36
  lane.host.id === localHostname));
36
37
  const providers = {};
38
+ const otherHolderLogins = [];
37
39
  for (const provider of ["claude", "codex", "grok"]) {
38
40
  const providerConfig = input.config.providers[provider];
39
41
  const providerLanes = onHost.filter((lane) => lane.provider === provider);
@@ -41,6 +43,11 @@ export function buildHostCapacitySnapshot(input) {
41
43
  const queued = providerLanes.filter((lane) => lane.state === "queued");
42
44
  const accounts = {};
43
45
  for (const [id, account] of Object.entries(providerConfig.accounts)) {
46
+ if (accountHeldByOther(account)) {
47
+ otherHolderLogins.push({ engine: provider, holder: account.holder });
48
+ continue;
49
+ }
50
+ const ownership = accountOwnership(account);
44
51
  const status = accountStatus(provider, id, input.config, {
45
52
  existsSync: input.existsSync,
46
53
  ...(input.probe !== undefined ? { probe: input.probe } : {}),
@@ -62,6 +69,8 @@ export function buildHostCapacitySnapshot(input) {
62
69
  max_running: accountMaxRunning(providerConfig, id),
63
70
  running: running.filter((lane) => lane.account === id).length,
64
71
  queued: queued.filter((lane) => lane.account === id).length,
72
+ owning_company: ownership.owning_company,
73
+ holder: ownership.holder,
65
74
  ...(quotaBlock !== undefined
66
75
  ? {
67
76
  quota_held: quotaBlock.blocked,
@@ -95,6 +104,7 @@ export function buildHostCapacitySnapshot(input) {
95
104
  ...(input.compute
96
105
  ? { compute: input.compute, compute_stale: computeReadingIsStale(input.compute, input.now) }
97
106
  : {}),
107
+ ...(otherHolderLogins.length > 0 ? { other_holder_logins: otherHolderLogins } : {}),
98
108
  };
99
109
  }
100
110
  function objectValue(value) {
@@ -178,6 +188,11 @@ export function parseHostCapacitySnapshot(raw, now = new Date()) {
178
188
  max_running: requireCount(account.max_running, `${provider}.${id}.max_running`, true),
179
189
  running: requireCount(account.running, `${provider}.${id}.running`),
180
190
  queued: requireCount(account.queued, `${provider}.${id}.queued`),
191
+ // Informational labels: a malformed value is dropped, never fatal.
192
+ ...(owningCompanyProblem(account.owning_company) === null
193
+ ? { owning_company: account.owning_company }
194
+ : {}),
195
+ ...(holderProblem(account.holder) === null ? { holder: account.holder } : {}),
181
196
  ...(account.quota_held !== undefined ? { quota_held: account.quota_held } : {}),
182
197
  ...(account.quota_reset_at !== undefined
183
198
  ? { quota_reset_at: account.quota_reset_at }
@@ -205,6 +220,7 @@ export function parseHostCapacitySnapshot(raw, now = new Date()) {
205
220
  };
206
221
  }
207
222
  const compute = root.compute === undefined ? null : parseHostComputeReading(root.compute);
223
+ const otherHolderLogins = parseOtherHolderLogins(root.other_holder_logins);
208
224
  return {
209
225
  schema_version: "hq-lanes-host-capacity.v1",
210
226
  host: { kind: hostRaw.kind, id: hostRaw.id },
@@ -214,8 +230,29 @@ export function parseHostCapacitySnapshot(raw, now = new Date()) {
214
230
  ...(compute !== null
215
231
  ? { compute, compute_stale: root.compute_stale === true || computeReadingIsStale(compute, now) }
216
232
  : {}),
233
+ ...(otherHolderLogins.length > 0 ? { other_holder_logins: otherHolderLogins } : {}),
217
234
  };
218
235
  }
236
+ /**
237
+ * Keep only engine and holder from each entry, whatever else a producer sent,
238
+ * so an account id never travels further than the host that holds it.
239
+ */
240
+ function parseOtherHolderLogins(value) {
241
+ if (!Array.isArray(value))
242
+ return [];
243
+ const out = [];
244
+ for (const entry of value) {
245
+ const row = objectValue(entry);
246
+ if (row === undefined)
247
+ continue;
248
+ if (row.engine !== "claude" && row.engine !== "codex" && row.engine !== "grok")
249
+ continue;
250
+ if (holderProblem(row.holder) !== null)
251
+ continue;
252
+ out.push({ engine: row.engine, holder: row.holder });
253
+ }
254
+ return out;
255
+ }
219
256
  function parseLaneCounts(value, field) {
220
257
  const counts = objectValue(value);
221
258
  if (counts === undefined) {
@@ -6,6 +6,7 @@
6
6
  * live process — this pass owns the transitions no single lane can own.
7
7
  */
8
8
  import { accountMatchesCompany } from "./account-company.js";
9
+ import { accountHeldByOther } from "./account-ownership.js";
9
10
  import * as fs from "node:fs";
10
11
  import * as path from "node:path";
11
12
  import { parseUserYaml } from "../../utils/user-yaml-error.js";
@@ -756,6 +757,29 @@ function availableBalancedAccount(hqRoot, lane, occupying, config, host, profile
756
757
  }
757
758
  return undefined;
758
759
  }
760
+ /**
761
+ * Move a queued recovering lane off a login that another person holds
762
+ * (PS-006). The write is guarded on the lane still recording that login and
763
+ * the target being one this lane may use, and it records the change in
764
+ * account_history like any other automatic account move.
765
+ */
766
+ function writeRecoveryAccountOffHeldLogin(hqRoot, lane, account, now, dryRun) {
767
+ return casLaneIf(hqRoot, lane.lane_id, (current) => {
768
+ const accounts = loadLanesConfig(hqRoot).providers[current.provider].accounts;
769
+ return current.state === "queued" &&
770
+ current.account === lane.account &&
771
+ current.account !== undefined &&
772
+ accountHeldByOther(accounts[current.account]) &&
773
+ accountMatchesCompany(accounts[account], resolveLaneCompany(hqRoot, current).company, accounts);
774
+ }, (current) => ({
775
+ ...current,
776
+ account,
777
+ account_history: [
778
+ ...(current.account_history ?? []),
779
+ { from: current.account ?? null, to: account, at: now.toISOString(), reason: "account_unavailable" },
780
+ ],
781
+ }), dryRun).record;
782
+ }
759
783
  function writeAdmissionAccount(hqRoot, lane, account, dryRun) {
760
784
  return casLaneIf(hqRoot, lane.lane_id, (current) => current.state === "queued" &&
761
785
  current.account === lane.account &&
@@ -2245,8 +2269,12 @@ async function admitQueued(hqRoot, lanes, summary, deps, now, onlyLaneIds, exclu
2245
2269
  const accounts = config.providers[admittedLane.provider].accounts;
2246
2270
  const company = resolveLaneCompany(hqRoot, admittedLane).company;
2247
2271
  let account;
2272
+ // A recorded login now held by another person is not kept (PS-006):
2273
+ // pick again among the allowed accounts instead.
2274
+ const leavingHeldLogin = admittedLane.account !== undefined && accountHeldByOther(accounts[admittedLane.account]);
2275
+ const recorded = leavingHeldLogin ? undefined : admittedLane.account;
2248
2276
  try {
2249
- account = resolveAccount(admittedLane.provider, admittedLane.account, config, {
2277
+ account = resolveAccount(admittedLane.provider, recorded, config, {
2250
2278
  hqRoot, hostname: deps.host.hostname,
2251
2279
  allowedAccounts: Object.keys(accounts).filter((id) => accountMatchesCompany(accounts[id], company, accounts)),
2252
2280
  }).id;
@@ -2257,12 +2285,25 @@ async function admitQueued(hqRoot, lanes, summary, deps, now, onlyLaneIds, exclu
2257
2285
  writeQueueReason(hqRoot, admittedLane, "account_retry", deps.dryRun);
2258
2286
  continue;
2259
2287
  }
2260
- if (!accountMatchesCompany(accounts[account], company, accounts) && accounts[account]?.company !== undefined) {
2288
+ if (accountHeldByOther(accounts[account]) ||
2289
+ (!accountMatchesCompany(accounts[account], company, accounts) && accounts[account]?.company !== undefined)) {
2261
2290
  writeQueueReason(hqRoot, admittedLane, "account_retry", deps.dryRun);
2262
2291
  continue;
2263
2292
  }
2264
- if (admittedLane.account !== account)
2293
+ if (leavingHeldLogin) {
2294
+ // writeAdmissionAccount only moves within admission_accounts, which a
2295
+ // recovering lane usually lacks. Leaving another person's login is not
2296
+ // an admission choice: write the move directly, and never spawn the
2297
+ // lane while it still records that login (PS-006).
2298
+ admittedLane = writeRecoveryAccountOffHeldLogin(hqRoot, admittedLane, account, now, deps.dryRun);
2299
+ if (admittedLane.account !== account) {
2300
+ writeQueueReason(hqRoot, admittedLane, "account_retry", deps.dryRun);
2301
+ continue;
2302
+ }
2303
+ }
2304
+ else if (admittedLane.account !== account) {
2265
2305
  admittedLane = writeAdmissionAccount(hqRoot, admittedLane, account, deps.dryRun);
2306
+ }
2266
2307
  const status = accountStatus(admittedLane.provider, account, config, {
2267
2308
  hostname: deps.host.hostname,
2268
2309
  existsSync: (file) => fs.existsSync(file),
@@ -410,16 +410,6 @@ export type EnvelopeRepairMode = "resume" | "fresh_turn";
410
410
  * path was built and proven that way, and a repair by resume has not been.
411
411
  */
412
412
  export declare function envelopeRepairMode(provider: LaneProvider): EnvelopeRepairMode;
413
- /**
414
- * Spec §4 repair turn. The lane is still `running` (the watcher has not
415
- * written a terminal state), so this does not claim or transition the
416
- * record. It resumes the recorded provider session with the repair prompt
417
- * (`resume` mode), or for a provider with no session resume runs the repair
418
- * prompt as a fresh single turn on the same account (`fresh_turn` mode). It
419
- * replaces `worker.pid` and rewrites `spawn.json` so the watcher's next tick
420
- * follows the new process. The account is the one already bound on the record.
421
- * Fast-mode evidence is updated after the replacement is proven detached.
422
- */
423
413
  export declare function spawnEnvelopeRepair(hqRoot: string, lane: LaneRecord, input: EnvelopeRepairSpawnInput, deps?: SpawnLaneDeps): number;
424
414
  export { PROVIDER_HOME_ENV, PROVIDER_COMMAND };
425
415
  //# sourceMappingURL=spawn.d.ts.map