@indigoai-us/hq-cli 5.345.223 → 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 (130) hide show
  1. package/CHANGELOG.md +98 -0
  2. package/assets/bot-workers/setup/context/quick-reference.md +2 -2
  3. package/assets/mesh-daemon/README.md +11 -12
  4. package/dist/command-catalog.generated.d.ts +156 -4
  5. package/dist/command-catalog.generated.js +191 -4
  6. package/dist/commands/cloud-provision.d.ts +4 -1
  7. package/dist/commands/cloud-provision.js +7 -3
  8. package/dist/commands/cloud-retire.js +1 -1
  9. package/dist/commands/core-delegate-w1b.js +3 -1
  10. package/dist/commands/core-delegate.d.ts +5 -0
  11. package/dist/commands/core-dm-bind-native.d.ts +5 -1
  12. package/dist/commands/core-dm-bind-native.js +4 -0
  13. package/dist/commands/core-job-notify-native.d.ts +5 -1
  14. package/dist/commands/core-job-notify-native.js +8 -2
  15. package/dist/commands/core-jobs-native.d.ts +27 -1
  16. package/dist/commands/core-jobs-native.js +49 -28
  17. package/dist/commands/core-pipeline-conductor-native.js +7 -7
  18. package/dist/commands/core-pipeline-driver-native.js +5 -5
  19. package/dist/commands/core-refresh-vault-access-native.d.ts +5 -0
  20. package/dist/commands/core-refresh-vault-access-native.js +3 -1
  21. package/dist/commands/core-work-mesh-bind-trusted-native.js +1 -1
  22. package/dist/commands/daemon.d.ts +2 -0
  23. package/dist/commands/daemon.js +68 -2
  24. package/dist/commands/deploy-domains.js +38 -2
  25. package/dist/commands/lanes-accounts.d.ts +14 -0
  26. package/dist/commands/lanes-accounts.js +119 -0
  27. package/dist/commands/lanes-hold.d.ts +2 -27
  28. package/dist/commands/lanes-hold.js +3 -75
  29. package/dist/commands/lanes-loop.js +1 -1
  30. package/dist/commands/lanes-move.js +10 -0
  31. package/dist/commands/lanes-session-start.js +2 -2
  32. package/dist/commands/lanes-shared.js +9 -0
  33. package/dist/commands/lanes.js +137 -12
  34. package/dist/commands/mesh.d.ts +12 -0
  35. package/dist/commands/mesh.js +13 -4
  36. package/dist/commands/monitor.js +1 -1
  37. package/dist/commands/packs.js +1 -1
  38. package/dist/commands/sync-held.d.ts +22 -0
  39. package/dist/commands/sync-held.js +167 -18
  40. package/dist/commands/whoami.d.ts +10 -17
  41. package/dist/commands/whoami.js +7 -79
  42. package/dist/data/command-states.json +13 -0
  43. package/dist/hq-cloud-sync-runner/bin/sync-runner.js +4845 -2524
  44. package/dist/hq-cloud-sync-runner/package.json +1 -1
  45. package/dist/index.js +1 -1
  46. package/dist/lib/capacity/accounts.d.ts +4 -0
  47. package/dist/lib/capacity/accounts.js +4 -0
  48. package/dist/lib/capacity/route.js +14 -0
  49. package/dist/lib/capacity/sign-in.d.ts +18 -0
  50. package/dist/lib/capacity/sign-in.js +34 -1
  51. package/dist/lib/daemon/catalog.d.ts +9 -5
  52. package/dist/lib/daemon/catalog.js +14 -8
  53. package/dist/lib/daemon/config.d.ts +5 -0
  54. package/dist/lib/daemon/config.js +6 -0
  55. package/dist/lib/daemon/hook-requests.d.ts +76 -0
  56. package/dist/lib/daemon/hook-requests.js +481 -0
  57. package/dist/lib/daemon/lanes-monitor-state.d.ts +55 -0
  58. package/dist/lib/daemon/lanes-monitor-state.js +129 -0
  59. package/dist/lib/daemon/lanes-reconcile-loader.d.ts +7 -0
  60. package/dist/lib/daemon/lanes-reconcile-loader.js +13 -0
  61. package/dist/lib/daemon/lanes-reconcile-status.d.ts +35 -0
  62. package/dist/lib/daemon/lanes-reconcile-status.js +86 -0
  63. package/dist/lib/daemon/merge-sections.d.ts +165 -0
  64. package/dist/lib/daemon/merge-sections.js +556 -0
  65. package/dist/lib/daemon/ops/policy.d.ts +2 -2
  66. package/dist/lib/daemon/ops/policy.js +44 -5
  67. package/dist/lib/daemon/protocol.d.ts +1 -1
  68. package/dist/lib/daemon/protocol.js +0 -6
  69. package/dist/lib/daemon/run.js +110 -5
  70. package/dist/lib/daemon/selfcheck.js +2 -2
  71. package/dist/lib/daemon/server.d.ts +2 -4
  72. package/dist/lib/daemon/server.js +11 -49
  73. package/dist/lib/daemon/state-file.d.ts +74 -4
  74. package/dist/lib/daemon/state-file.js +159 -19
  75. package/dist/lib/daemon/supervisor.d.ts +3 -1
  76. package/dist/lib/daemon/updater.d.ts +2 -6
  77. package/dist/lib/daemon/updater.js +4 -11
  78. package/dist/lib/daemon/whoami-cache.d.ts +96 -0
  79. package/dist/lib/daemon/whoami-cache.js +244 -0
  80. package/dist/lib/flag-registry-worker-source.generated.d.ts +1 -1
  81. package/dist/lib/flag-registry-worker-source.generated.js +1 -1
  82. package/dist/lib/hook-engine/coverage.d.ts +2 -0
  83. package/dist/lib/hook-engine/coverage.js +71 -0
  84. package/dist/lib/hook-engine/native-precompact-compatibility.json +449 -0
  85. package/dist/lib/hook-engine/reconcile.js +14 -8
  86. package/dist/lib/install/hook-target.d.ts +13 -3
  87. package/dist/lib/install/hook-target.js +14 -11
  88. package/dist/lib/lanes/account-company.d.ts +7 -1
  89. package/dist/lib/lanes/account-company.js +22 -4
  90. package/dist/lib/lanes/account-ownership.d.ts +65 -0
  91. package/dist/lib/lanes/account-ownership.js +134 -0
  92. package/dist/lib/lanes/accounts.js +9 -2
  93. package/dist/lib/lanes/claude-balance.js +9 -3
  94. package/dist/lib/lanes/config.js +17 -0
  95. package/dist/lib/lanes/envelope-repair-dispatch.js +1 -1
  96. package/dist/lib/lanes/host-capacity.d.ts +19 -0
  97. package/dist/lib/lanes/host-capacity.js +37 -0
  98. package/dist/lib/lanes/monitor.d.ts +2 -0
  99. package/dist/lib/lanes/monitor.js +2 -1
  100. package/dist/lib/lanes/reconcile.js +44 -3
  101. package/dist/lib/lanes/registry-flag.d.ts +6 -0
  102. package/dist/lib/lanes/registry-flag.js +3 -2
  103. package/dist/lib/lanes/repo-merge-hold.d.ts +39 -0
  104. package/dist/lib/lanes/repo-merge-hold.js +90 -0
  105. package/dist/lib/lanes/spawn.d.ts +0 -10
  106. package/dist/lib/lanes/spawn.js +51 -1
  107. package/dist/lib/lanes/types.d.ts +12 -0
  108. package/dist/lib/lanes/watcher-main.js +3 -3
  109. package/dist/lib/mesh/live/daemon/doctor.js +1 -1
  110. package/dist/lib/mesh/live/daemon/install.js +2 -2
  111. package/dist/lib/windows/install-followup.js +1 -1
  112. package/dist/utils/client-health-contract.d.ts +1 -0
  113. package/dist/utils/client-health-contract.js +5 -0
  114. package/dist/utils/client-health.d.ts +2 -0
  115. package/dist/utils/client-health.js +40 -0
  116. package/dist/utils/cognito-session.d.ts +2 -14
  117. package/dist/utils/cognito-session.js +2 -40
  118. package/dist/utils/daemon-cli-version.d.ts +13 -0
  119. package/dist/utils/daemon-cli-version.js +47 -0
  120. package/dist/utils/duplicate-command-usage.js +1 -1
  121. package/dist/utils/machine-token-cache.d.ts +21 -0
  122. package/dist/utils/machine-token-cache.js +49 -0
  123. package/dist/utils/resident-package-preload.js +4 -0
  124. package/dist/utils/whoami-identity.d.ts +54 -0
  125. package/dist/utils/whoami-identity.js +108 -0
  126. package/package.json +8 -8
  127. package/dist/lib/daemon/ops/memory.d.ts +0 -18
  128. package/dist/lib/daemon/ops/memory.js +0 -65
  129. package/dist/lib/daemon/ops/mesh.d.ts +0 -38
  130. package/dist/lib/daemon/ops/mesh.js +0 -70
@@ -6,15 +6,11 @@
6
6
  import * as fs from 'node:fs';
7
7
  import * as path from 'node:path';
8
8
  import { spawnSync } from 'node:child_process';
9
- import { realpathOrSelf } from '../../commands/mcp-registration.js';
10
9
  import { DAEMON_LAUNCHD_LABEL, DAEMON_SYSTEMD_UNIT, SYSTEM_UNIT_DIR, currentWindowsIdentity, legacyWindowsTask, windowsTaskName } from '../daemon/install.js';
11
10
  import { defaultRunCommand } from '../service-manager/launchd.js';
12
- import { readDaemonConfig } from '../daemon/config.js';
13
- import { daemonPaths } from '../daemon/paths.js';
14
11
  import { registrationEngine } from '../hook-engine/registration.js';
15
12
  import { coreNextTargetOrWarn } from '../../utils/host-registration.js';
16
13
  import { forHost } from '../hook-engine/coverage.js';
17
- import { shimPath } from './claude-targets.js';
18
14
  /**
19
15
  * True when this user's hq daemon unit (launchd plist, systemd unit, or the
20
16
  * per-user Windows Scheduled Task) exists. On Windows the shared task an older
@@ -41,17 +37,24 @@ export function hookTargetFor(hqRoot, home, daemonInstalled, env = process.env,
41
37
  // is one warning, and install goes on with the flag-off target for every
42
38
  // event.
43
39
  const coreNext = forHost(coreNextTargetOrWarn(home, env), hqRoot, host, env);
44
- const fallback = legacyHookTarget(hqRoot, home, daemonInstalled, env);
40
+ const fallback = legacyHookTarget(hqRoot, home, daemonInstalled, env, host);
45
41
  return coreNext ? { ...coreNext, fallback } : fallback;
46
42
  }
47
- /** The target with `core.next` off: the pinned launcher, the hqd shim, or master-hook.sh. */
48
- export function legacyHookTarget(hqRoot, home, daemonInstalled, env = process.env) {
43
+ /**
44
+ * The target with `core.next` off: the pinned launcher, or master-hook.sh
45
+ * (the Codex adapter on Codex).
46
+ *
47
+ * No user-scope entry gets the bare hqd shim. The shim only forwards to hqd's
48
+ * policy.check, which runs the scope authorizer but none of master-hook's
49
+ * other PreToolUse guards (the credential guards among them), and with no
50
+ * socket it allows the call. master-hook still asks hqd through the shim when
51
+ * the daemon is up. The root, daemon and host arguments stay for callers; they
52
+ * no longer change the answer.
53
+ */
54
+ export function legacyHookTarget(_hqRoot, home, _daemonInstalled, env = process.env, _host = 'claude') {
49
55
  const engine = registrationEngine(home, env);
50
56
  if (engine)
51
57
  return { engine };
52
- const installed = daemonInstalled ?? isDaemonInstalled(home);
53
- const configuredRoot = readDaemonConfig(daemonPaths(home, env).configPath).hqRoot;
54
- const daemonMatchesRoot = configuredRoot !== undefined && realpathOrSelf(configuredRoot) === realpathOrSelf(hqRoot);
55
- return installed && daemonMatchesRoot && fs.existsSync(shimPath(hqRoot)) ? 'shim' : 'master';
58
+ return 'master';
56
59
  }
57
60
  //# sourceMappingURL=hook-target.js.map
@@ -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)) {
@@ -43,7 +43,7 @@ export function spawnEnvelopeRepairViaCurrentCli(hqRoot, lane, input, deps = {})
43
43
  isLaneRunnerEntry(cliEntry)) {
44
44
  throw new LanesError("repair_cli_entry_invalid", "Lane watcher has no valid absolute hq CLI entrypoint for envelope repair", { lane_id: lane.lane_id });
45
45
  }
46
- const result = run(liveNodeBinary(), [cliEntry, "lanes", "_spawn-envelope-repair"], {
46
+ const result = run(liveNodeBinary(), [cliEntry, "runners", "_spawn-envelope-repair"], {
47
47
  encoding: "utf8",
48
48
  timeout: 120_000,
49
49
  input: JSON.stringify(request),
@@ -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) {
@@ -59,6 +59,8 @@ export declare function isMonitorTaskLive(task: MonitorTaskEvidence, now: Date):
59
59
  */
60
60
  export declare function expiredLaneIds(evidence: MonitorEvidence, now: Date): Set<string>;
61
61
  export declare function coveredLaneIds(evidence: MonitorEvidence, now: Date): Set<string>;
62
+ /** Every process command line on this host (`ps -eww -o args=`); empty when ps fails. */
63
+ export declare function defaultProcessCommands(): readonly string[];
62
64
  export declare function readLiveMonitorEvidence(sessionId: string, options?: LiveMonitorEvidenceOptions): MonitorEvidence;
63
65
  export type MonitorEvidenceReader = (sessionId: string) => MonitorEvidence | Promise<MonitorEvidence>;
64
66
  export declare function monitorReminderText(): string;
@@ -406,7 +406,8 @@ function taskOutputCandidates(transcriptPath, sessionId, task) {
406
406
  }
407
407
  return [...new Set(candidates)];
408
408
  }
409
- function defaultProcessCommands() {
409
+ /** Every process command line on this host (`ps -eww -o args=`); empty when ps fails. */
410
+ export function defaultProcessCommands() {
410
411
  try {
411
412
  const output = execFileSync("ps", ["-eww", "-o", "args="], {
412
413
  encoding: "utf8",