@indigoai-us/hq-cli 5.345.220 → 5.345.222
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.
- package/CHANGELOG.md +164 -0
- package/dist/command-catalog.generated.d.ts +175 -2
- package/dist/command-catalog.generated.js +213 -2
- package/dist/commands/auth.js +6 -2
- package/dist/commands/bot-runtime.d.ts +18 -5
- package/dist/commands/bot-runtime.js +29 -12
- package/dist/commands/bot.d.ts +39 -2
- package/dist/commands/bot.js +140 -11
- package/dist/commands/core-delegate-w1b.js +9 -3
- package/dist/commands/core-stop-autosave.d.ts +21 -0
- package/dist/commands/core-stop-autosave.js +300 -0
- package/dist/commands/core.js +2 -0
- package/dist/commands/daemon.d.ts +6 -0
- package/dist/commands/daemon.js +46 -8
- package/dist/commands/doctor-usage.d.ts +5 -0
- package/dist/commands/doctor-usage.js +25 -0
- package/dist/commands/env.d.ts +49 -4
- package/dist/commands/env.js +355 -5
- package/dist/commands/lanes-shared.d.ts +3 -0
- package/dist/commands/lanes.d.ts +3 -0
- package/dist/commands/lanes.js +87 -3
- package/dist/commands/link.d.ts +2 -0
- package/dist/commands/link.js +14 -2
- package/dist/commands/mesh.js +23 -3
- package/dist/commands/sources.js +3 -3
- package/dist/commands/sync-core.d.ts +7 -0
- package/dist/commands/sync-core.js +132 -3
- package/dist/commands/whoami.js +96 -80
- package/dist/data/command-states.json +3 -0
- package/dist/lib/bot/config.d.ts +17 -0
- package/dist/lib/bot/config.js +13 -0
- package/dist/lib/bot/fleet-cron.js +24 -2
- package/dist/lib/bot/fleet-local.d.ts +30 -2
- package/dist/lib/bot/fleet-local.js +60 -1
- package/dist/lib/bot/grok-login-scope.d.ts +36 -0
- package/dist/lib/bot/grok-login-scope.js +93 -0
- package/dist/lib/bot/legacy-provider-login.d.ts +32 -9
- package/dist/lib/bot/legacy-provider-login.js +28 -22
- package/dist/lib/bot/runtime-sign-in-check.js +6 -1
- package/dist/lib/bot/runtime-sign-in.d.ts +2 -0
- package/dist/lib/core-utils/sentry-report.js +2 -0
- package/dist/lib/daemon/catalog.js +2 -0
- package/dist/lib/daemon/install.d.ts +2 -1
- package/dist/lib/daemon/install.js +9 -0
- package/dist/lib/daemon/legacy.d.ts +1 -0
- package/dist/lib/daemon/legacy.js +5 -2
- package/dist/lib/daemon/machine-check-owner.d.ts +2 -0
- package/dist/lib/daemon/machine-check-owner.js +6 -1
- package/dist/lib/daemon/machine-checks.d.ts +29 -2
- package/dist/lib/daemon/machine-checks.js +64 -13
- package/dist/lib/daemon/mesh-owner.d.ts +45 -0
- package/dist/lib/daemon/mesh-owner.js +166 -0
- package/dist/lib/daemon/native-notice-ledger.d.ts +27 -0
- package/dist/lib/daemon/native-notice-ledger.js +113 -0
- package/dist/lib/daemon/run.d.ts +15 -0
- package/dist/lib/daemon/run.js +137 -11
- package/dist/lib/daemon/selfcheck.d.ts +35 -2
- package/dist/lib/daemon/selfcheck.js +118 -9
- package/dist/lib/daemon/stop-autosave-lock.d.ts +19 -0
- package/dist/lib/daemon/stop-autosave-lock.js +166 -0
- package/dist/lib/daemon/stop-autosave.d.ts +28 -0
- package/dist/lib/daemon/stop-autosave.js +111 -0
- package/dist/lib/daemon/stop-diagnostics.d.ts +11 -0
- package/dist/lib/daemon/stop-diagnostics.js +136 -0
- package/dist/lib/daemon/stop-job-executor.d.ts +19 -0
- package/dist/lib/daemon/stop-job-executor.js +126 -0
- package/dist/lib/daemon/stop-jobs.d.ts +93 -0
- package/dist/lib/daemon/stop-jobs.js +599 -0
- package/dist/lib/doctor/checks/fleet-hook-core.js +1 -1
- package/dist/lib/doctor/checks/host-core.js +1 -1
- package/dist/lib/environment/access-probes.d.ts +234 -0
- package/dist/lib/environment/access-probes.js +918 -0
- package/dist/lib/environment/profile.d.ts +15 -2
- package/dist/lib/environment/profile.js +55 -20
- package/dist/lib/environment/rfc3339.d.ts +8 -0
- package/dist/lib/environment/rfc3339.js +26 -0
- package/dist/lib/environment/work-requirements.d.ts +169 -0
- package/dist/lib/environment/work-requirements.js +389 -0
- package/dist/lib/hook-engine/coverage.d.ts +146 -7
- package/dist/lib/hook-engine/coverage.js +1480 -4
- package/dist/lib/hook-engine/fleet-registration.js +2 -2
- package/dist/lib/hook-engine/git-stop-config.json +513 -0
- package/dist/lib/hook-engine/native-stop-compatibility.json +362 -0
- package/dist/lib/hook-engine/reconcile.js +2 -2
- package/dist/lib/hot-channels/alert.d.ts +2 -2
- package/dist/lib/hot-channels/alert.js +8 -5
- package/dist/lib/hot-channels/signals-pass.d.ts +126 -17
- package/dist/lib/hot-channels/signals-pass.js +296 -17
- package/dist/lib/hot-channels/signals-runtime.d.ts +30 -0
- package/dist/lib/hot-channels/signals-runtime.js +82 -0
- package/dist/lib/install/hook-target.js +1 -1
- package/dist/lib/lanes/host-capacity.d.ts +26 -2
- package/dist/lib/lanes/host-capacity.js +17 -2
- package/dist/lib/lanes/host-compute.d.ts +90 -0
- package/dist/lib/lanes/host-compute.js +185 -0
- package/dist/lib/lanes/index.d.ts +2 -0
- package/dist/lib/lanes/index.js +1 -0
- package/dist/lib/lanes/reconcile.js +22 -1
- package/dist/lib/lanes/resource-usage.d.ts +155 -0
- package/dist/lib/lanes/resource-usage.js +589 -0
- package/dist/lib/lanes/run-size.d.ts +46 -0
- package/dist/lib/lanes/run-size.js +197 -0
- package/dist/lib/lanes/store.js +27 -0
- package/dist/lib/lanes/throttle.d.ts +36 -1
- package/dist/lib/lanes/throttle.js +47 -10
- package/dist/lib/lanes/types.d.ts +40 -0
- package/dist/lib/lanes/types.js +2 -2
- package/dist/lib/lanes/watcher.js +13 -4
- package/dist/lib/lanes/worker-process.d.ts +25 -2
- package/dist/lib/lanes/worker-process.js +71 -19
- package/dist/lib/mesh/live/daemon/config.d.ts +8 -1
- package/dist/lib/mesh/live/daemon/config.js +16 -0
- package/dist/lib/mesh/live/daemon/install.d.ts +31 -2
- package/dist/lib/mesh/live/daemon/install.js +142 -1
- package/dist/lib/mesh/live/daemon/login-home.d.ts +5 -0
- package/dist/lib/mesh/live/daemon/login-home.js +27 -0
- package/dist/lib/mesh/live/daemon/unit-home.d.ts +49 -0
- package/dist/lib/mesh/live/daemon/unit-home.js +134 -0
- package/dist/lib/placement/match.d.ts +192 -0
- package/dist/lib/placement/match.js +667 -0
- package/dist/lib/registry/registry.d.ts +35 -7
- package/dist/lib/registry/registry.js +88 -13
- package/dist/lib/safe-store.d.ts +14 -0
- package/dist/lib/safe-store.js +77 -4
- package/dist/lib/scan-packages/index.js +24 -2
- package/dist/lib/search-index/index.d.ts +88 -4
- package/dist/lib/search-index/index.js +288 -24
- package/dist/lib/search-index/max-doc-bytes.d.ts +17 -6
- package/dist/lib/search-index/max-doc-bytes.js +49 -23
- package/dist/lib/service-manager/startup-migration.d.ts +1 -0
- package/dist/lib/service-manager/startup-migration.js +3 -0
- package/dist/lib/signals/codex-lockdown.d.ts +79 -0
- package/dist/lib/signals/codex-lockdown.js +271 -0
- package/dist/lib/signals/codex-login.d.ts +37 -0
- package/dist/lib/signals/codex-login.js +83 -0
- package/dist/lib/signals/engine.d.ts +27 -0
- package/dist/lib/signals/engine.js +70 -0
- package/dist/lib/signals/reply.js +22 -1
- package/dist/lib/signals/run-record.js +6 -1
- package/dist/lib/signals/settings.d.ts +5 -0
- package/dist/lib/signals/settings.js +2 -0
- package/dist/lib/signals/steps/extract.d.ts +85 -9
- package/dist/lib/signals/steps/extract.js +317 -68
- package/dist/lib/signals/steps/types.d.ts +2 -0
- package/dist/lib/sync-core/engine-holds.d.ts +14 -0
- package/dist/lib/sync-core/engine-holds.js +60 -0
- package/dist/lib/sync-core/engine-home.d.ts +37 -1
- package/dist/lib/sync-core/engine-home.js +119 -16
- package/dist/lib/sync-core/reconcile.js +8 -0
- package/dist/lib/sync-core/rollout-state.d.ts +2 -1
- package/dist/lib/sync-core/rollout-state.js +5 -2
- package/dist/lib/sync-core/vault-settings.d.ts +21 -0
- package/dist/lib/sync-core/vault-settings.js +131 -0
- package/dist/lib/sync-core/vault-uid.d.ts +2 -0
- package/dist/lib/sync-core/vault-uid.js +4 -0
- package/dist/lib/windows/install-followup.d.ts +2 -0
- package/dist/lib/windows/install-followup.js +4 -1
- package/dist/schemas/hq-work-requirements.v1.schema.json +145 -0
- package/dist/utils/auth-session-check.d.ts +16 -0
- package/dist/utils/auth-session-check.js +16 -0
- package/dist/utils/client-health-contract.d.ts +6 -0
- package/dist/utils/client-health-contract.js +13 -0
- package/dist/utils/client-health.d.ts +7 -0
- package/dist/utils/client-health.js +22 -1
- package/dist/utils/command-usage.d.ts +40 -0
- package/dist/utils/command-usage.js +61 -0
- package/dist/utils/duplicate-command-usage.d.ts +72 -0
- package/dist/utils/duplicate-command-usage.js +125 -0
- package/dist/utils/host-registration.js +5 -2
- package/dist/utils/pack-contributions.d.ts +3 -0
- package/dist/utils/pack-contributions.js +110 -23
- package/dist/utils/resident-package-preload.js +4 -0
- package/dist/utils/self-update.d.ts +3 -1
- package/dist/utils/self-update.js +56 -11
- package/dist/utils/sentry-fingerprint.js +9 -0
- package/dist/utils/update-lock.d.ts +151 -14
- package/dist/utils/update-lock.js +782 -46
- package/dist/utils/version-gate.js +12 -2
- package/dist/utils/windows-bash.d.ts +2 -0
- package/dist/utils/windows-bash.js +2 -1
- package/package.json +9 -8
- package/scripts/bench-core-compare.mjs +313 -0
- package/scripts/bench-core.mjs +399 -12
- package/scripts/check-function-manifest.mjs +116 -3
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type BotEngineMetadata, type BotRuntimeId } from "./config.js";
|
|
2
2
|
import type { BotMachineCreds } from "./creds.js";
|
|
3
|
+
import { type GrokSiblingLogin } from "./grok-login-scope.js";
|
|
3
4
|
import { type FleetPython } from "./fleet-python.js";
|
|
4
5
|
import { vaultApiFetch } from "../../utils/vault-api.js";
|
|
5
6
|
import type { LocalBotPromotionRuntime } from "./promote.js";
|
|
@@ -376,7 +377,7 @@ export declare const spawnFleetAuth: FleetAuthSpawn;
|
|
|
376
377
|
export declare const FLEET_GROK_CLI_IMPORT_MIN_VERSION = "0.4.31-local.13";
|
|
377
378
|
export declare function fleetReleaseImportsGrokCli(version: string | null | undefined): boolean;
|
|
378
379
|
export declare function fleetLocalProfileEngineVersion(agentUid: string, deps?: Pick<FleetLocalControlDeps, "fleetHome">): string | null;
|
|
379
|
-
export declare function authenticateFleetLocalBot(input: FleetLocalAuthInput, deps?:
|
|
380
|
+
export declare function authenticateFleetLocalBot(input: FleetLocalAuthInput, deps?: XaiOauthLoginGateDeps & {
|
|
380
381
|
control?: FleetLocalStartControl;
|
|
381
382
|
spawnAuth?: FleetAuthSpawn;
|
|
382
383
|
writeStderr?: (text: string) => void;
|
|
@@ -481,6 +482,33 @@ export type FleetLocalAsyncRun = (executable: string, args: string[], options: R
|
|
|
481
482
|
export declare function fleetLocalProviderAuthStatusAsync(agentUid: string, provider: string, deps?: FleetLocalControlDeps & {
|
|
482
483
|
runAsync?: FleetLocalAsyncRun;
|
|
483
484
|
}): Promise<FleetLocalProviderAuthStatus | null>;
|
|
485
|
+
/** The runtime provider id of the helper's Grok account (OAuth) sign-in. */
|
|
486
|
+
export declare const XAI_OAUTH_RUNTIME_PROVIDER = "xai-oauth";
|
|
487
|
+
/**
|
|
488
|
+
* Whether `hq bot auth --provider <provider>` runs the helper's Grok account
|
|
489
|
+
* sign-in: the name resolves to the xAI OAuth preset (grok, xai, xai-oauth,
|
|
490
|
+
* in any case) and no API key is given. Decided on the resolved runtime
|
|
491
|
+
* provider, never on the name typed.
|
|
492
|
+
*/
|
|
493
|
+
export declare function fleetAuthUsesXaiOauthLogin(provider: string, apiKey?: string): boolean;
|
|
494
|
+
export interface XaiOauthLoginGateDeps extends FleetLocalControlDeps {
|
|
495
|
+
/** Where the bot folders are (default: the bots root). */
|
|
496
|
+
botsRoot?: string;
|
|
497
|
+
/** The helper's word on a bot's Grok sign-in (default: the helper is asked). */
|
|
498
|
+
grokStatus?: (agentUid: string) => FleetLocalProviderAuthStatus | null;
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* Asked right before every Grok account sign-in the helper runs for a bot:
|
|
502
|
+
* may the helper copy from every bot it could copy from? The other Fleet
|
|
503
|
+
* profiles are scanned now, never from a cache, and the bot's company scope
|
|
504
|
+
* is read from its own bot.json. `blocked` means no.
|
|
505
|
+
*/
|
|
506
|
+
export declare function xaiOauthLoginHeldBack(agentUid: string, deps?: XaiOauthLoginGateDeps): GrokSiblingLogin;
|
|
507
|
+
/** What to tell the owner when a Grok account sign-in is held back, and how to clear it. */
|
|
508
|
+
export declare function xaiOauthLoginRefusal(held: GrokSiblingLogin, opts?: {
|
|
509
|
+
name?: string;
|
|
510
|
+
fleetHome?: string;
|
|
511
|
+
}): string;
|
|
484
512
|
/**
|
|
485
513
|
* Sign a bot in from a login already on this computer, without a browser:
|
|
486
514
|
* the helper imports the Codex CLI login (CODEX_HOME, else ~/.codex) or
|
|
@@ -488,7 +516,7 @@ export declare function fleetLocalProviderAuthStatusAsync(agentUid: string, prov
|
|
|
488
516
|
* environment (a bot's own Codex home). The profile's provider is already
|
|
489
517
|
* the runtime's preset from the bootstrap; this re-renders and checks it.
|
|
490
518
|
*/
|
|
491
|
-
export declare function importFleetLocalProviderLogin(agentUid: string, runtime: "codex" | "grok", deps?:
|
|
519
|
+
export declare function importFleetLocalProviderLogin(agentUid: string, runtime: "codex" | "grok", deps?: XaiOauthLoginGateDeps, opts?: {
|
|
492
520
|
env?: Record<string, string>;
|
|
493
521
|
}): {
|
|
494
522
|
runtimeProvider: string;
|
|
@@ -8,6 +8,7 @@ import { fileURLToPath, pathToFileURL } from "node:url";
|
|
|
8
8
|
import { HQ_FLEET_RUNTIME_ENGINE_ID, } from "./config.js";
|
|
9
9
|
import { withBotLock } from "./lock.js";
|
|
10
10
|
import { downloadFleetFileFromSources, fileSha256 } from "./fleet-download.js";
|
|
11
|
+
import { grokLoginFromScan, localBotLoginScopes } from "./grok-login-scope.js";
|
|
11
12
|
import { ensureFleetPython, fleetUvEnv } from "./fleet-python.js";
|
|
12
13
|
import semver from "semver";
|
|
13
14
|
import { CLI_VERSION } from "../../cli-version.js";
|
|
@@ -1599,6 +1600,9 @@ export async function authenticateFleetLocalBot(input, deps = {}) {
|
|
|
1599
1600
|
if (!provider.oauth && !input.apiKey) {
|
|
1600
1601
|
throw expectedError(`Pass --api-key and provide ${provider.runtimeProvider} credentials on stdin.`);
|
|
1601
1602
|
}
|
|
1603
|
+
// Every caller and every spelling of the provider passes here on its way to the helper's `auth login`.
|
|
1604
|
+
if (provider.oauth && !input.apiKey && provider.runtimeProvider === XAI_OAUTH_RUNTIME_PROVIDER)
|
|
1605
|
+
assertXaiOauthLoginAllowed(input.agentUid, deps);
|
|
1602
1606
|
const run = deps.run ?? execFileSync;
|
|
1603
1607
|
const files = fleetLocalExecutables(input.agentUid, deps);
|
|
1604
1608
|
const authArgs = provider.oauth && !input.apiKey
|
|
@@ -2208,6 +2212,58 @@ export async function fleetLocalProviderAuthStatusAsync(agentUid, provider, deps
|
|
|
2208
2212
|
return null;
|
|
2209
2213
|
}
|
|
2210
2214
|
}
|
|
2215
|
+
/** The runtime provider id of the helper's Grok account (OAuth) sign-in. */
|
|
2216
|
+
export const XAI_OAUTH_RUNTIME_PROVIDER = "xai-oauth";
|
|
2217
|
+
/**
|
|
2218
|
+
* Whether `hq bot auth --provider <provider>` runs the helper's Grok account
|
|
2219
|
+
* sign-in: the name resolves to the xAI OAuth preset (grok, xai, xai-oauth,
|
|
2220
|
+
* in any case) and no API key is given. Decided on the resolved runtime
|
|
2221
|
+
* provider, never on the name typed.
|
|
2222
|
+
*/
|
|
2223
|
+
export function fleetAuthUsesXaiOauthLogin(provider, apiKey) {
|
|
2224
|
+
if (apiKey)
|
|
2225
|
+
return false;
|
|
2226
|
+
const known = providerProfiles[provider.trim().toLowerCase()];
|
|
2227
|
+
return known !== undefined && known.oauth && known.runtimeProvider === XAI_OAUTH_RUNTIME_PROVIDER;
|
|
2228
|
+
}
|
|
2229
|
+
/**
|
|
2230
|
+
* Asked right before every Grok account sign-in the helper runs for a bot:
|
|
2231
|
+
* may the helper copy from every bot it could copy from? The other Fleet
|
|
2232
|
+
* profiles are scanned now, never from a cache, and the bot's company scope
|
|
2233
|
+
* is read from its own bot.json. `blocked` means no.
|
|
2234
|
+
*/
|
|
2235
|
+
export function xaiOauthLoginHeldBack(agentUid, deps = {}) {
|
|
2236
|
+
const others = listFleetLocalProfiles(deps).filter((profile) => profile.agentUid.toLowerCase() !== agentUid.toLowerCase());
|
|
2237
|
+
if (others.length === 0)
|
|
2238
|
+
return grokLoginFromScan({ holders: [], uids: [], unanswered: [] }, agentUid, null, () => null);
|
|
2239
|
+
const status = deps.grokStatus ?? ((uid) => fleetLocalProviderAuthStatus(uid, XAI_OAUTH_RUNTIME_PROVIDER, deps));
|
|
2240
|
+
const holders = [];
|
|
2241
|
+
const unanswered = [];
|
|
2242
|
+
for (const profile of others) {
|
|
2243
|
+
const found = status(profile.agentUid);
|
|
2244
|
+
if (found === null)
|
|
2245
|
+
unanswered.push(profile.agentUid);
|
|
2246
|
+
else if (found.authenticated && found.authType === "oauth")
|
|
2247
|
+
holders.push(profile.agentUid);
|
|
2248
|
+
}
|
|
2249
|
+
const scopeOf = localBotLoginScopes(deps.botsRoot);
|
|
2250
|
+
return grokLoginFromScan({ holders, uids: others.map((profile) => profile.agentUid), unanswered }, agentUid, scopeOf(agentUid), scopeOf);
|
|
2251
|
+
}
|
|
2252
|
+
/** What to tell the owner when a Grok account sign-in is held back, and how to clear it. */
|
|
2253
|
+
export function xaiOauthLoginRefusal(held, opts = {}) {
|
|
2254
|
+
const bot = opts.name ?? "<name>";
|
|
2255
|
+
const profiles = path.join(opts.fleetHome ?? fleetHome(), "profiles");
|
|
2256
|
+
return (`${opts.name ? `${opts.name} was not signed in to Grok` : "No Grok account sign-in was started"}: ${held.detail}. ` +
|
|
2257
|
+
"The HQ Fleet helper would copy that bot's Grok sign-in instead of asking for a new one. " +
|
|
2258
|
+
`A bot counts as a different or unknown company when it is a bot of another company, a personal bot (for a company bot), or a profile folder under ${profiles} left behind by a bot that is no longer in hq bot list. ` +
|
|
2259
|
+
"To clear it, remove the leftover profile folder, or remove the other bot with hq bot rm. " +
|
|
2260
|
+
`Or sign in with an xAI API key: hq bot auth ${bot} --provider grok --api-key reads the key from stdin (paste the key and press Ctrl-D, or pipe it in).`);
|
|
2261
|
+
}
|
|
2262
|
+
function assertXaiOauthLoginAllowed(agentUid, deps) {
|
|
2263
|
+
const held = xaiOauthLoginHeldBack(agentUid, deps);
|
|
2264
|
+
if (held.blocked)
|
|
2265
|
+
throw expectedError(xaiOauthLoginRefusal(held, deps.fleetHome ? { fleetHome: deps.fleetHome } : {}));
|
|
2266
|
+
}
|
|
2211
2267
|
/** The helper waits this long for a sign-in import before the move counts as failed. */
|
|
2212
2268
|
const FLEET_PROVIDER_IMPORT_TIMEOUT_MS = 60_000;
|
|
2213
2269
|
/**
|
|
@@ -2218,7 +2274,10 @@ const FLEET_PROVIDER_IMPORT_TIMEOUT_MS = 60_000;
|
|
|
2218
2274
|
* the runtime's preset from the bootstrap; this re-renders and checks it.
|
|
2219
2275
|
*/
|
|
2220
2276
|
export function importFleetLocalProviderLogin(agentUid, runtime, deps = {}, opts = {}) {
|
|
2221
|
-
const provider = runtime === "grok" ?
|
|
2277
|
+
const provider = runtime === "grok" ? XAI_OAUTH_RUNTIME_PROVIDER : "openai-codex";
|
|
2278
|
+
// Scanned again here, right before the helper copies: the earlier check may be minutes old.
|
|
2279
|
+
if (provider === XAI_OAUTH_RUNTIME_PROVIDER)
|
|
2280
|
+
assertXaiOauthLoginAllowed(agentUid, deps);
|
|
2222
2281
|
const run = deps.run ?? execFileSync;
|
|
2223
2282
|
const files = fleetLocalExecutables(agentUid, deps);
|
|
2224
2283
|
const env = opts.env ? { ...process.env, ...opts.env } : undefined;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type BotConfig, type BotKind } from "./config.js";
|
|
2
|
+
import type { LegacyProviderLogin } from "./legacy-convert.js";
|
|
3
|
+
/**
|
|
4
|
+
* Whose Grok sign-in a bot may share: "personal" for a personal bot (it acts
|
|
5
|
+
* as its owner), "company:<slugs>" for a company bot. Null when a company
|
|
6
|
+
* bot names no company, which matches nothing.
|
|
7
|
+
*/
|
|
8
|
+
export type BotLoginScope = string | null;
|
|
9
|
+
export declare function newBotLoginScope(kind: BotKind, companies: readonly string[]): BotLoginScope;
|
|
10
|
+
export declare function botLoginScope(config: Pick<BotConfig, "kind" | "companies" | "workerId">): BotLoginScope;
|
|
11
|
+
/**
|
|
12
|
+
* The scope of each bot on this computer, by agent id, read from the bot
|
|
13
|
+
* folders' bot.json. An id with no readable bot.json, or one that two folders
|
|
14
|
+
* give different scopes, has no known scope.
|
|
15
|
+
*/
|
|
16
|
+
export declare function localBotLoginScopes(root?: string): (agentUid: string) => BotLoginScope;
|
|
17
|
+
/**
|
|
18
|
+
* A sibling-login answer. `blocked`: another bot here holds, or may hold, a
|
|
19
|
+
* Grok sign-in this bot may not share. The helper copies the first sign-in it
|
|
20
|
+
* finds, so no Grok sign-in may be imported for this bot while that is so.
|
|
21
|
+
*/
|
|
22
|
+
export interface GrokSiblingLogin extends LegacyProviderLogin {
|
|
23
|
+
blocked?: true;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The answer for one bot from a scan of the others. `holders` hold a Grok
|
|
27
|
+
* OAuth login, `unanswered` are bots the helper could not answer for, `uids`
|
|
28
|
+
* is every bot with a Fleet profile. Reusable only when another bot holds a
|
|
29
|
+
* login and every other bot that holds one, or may hold one, has `scope`.
|
|
30
|
+
*/
|
|
31
|
+
export declare function grokLoginFromScan(scan: {
|
|
32
|
+
holders: string[];
|
|
33
|
+
uids: string[];
|
|
34
|
+
unanswered: string[];
|
|
35
|
+
}, exclude: string, scope: BotLoginScope, scopeOf: (agentUid: string) => BotLoginScope): GrokSiblingLogin;
|
|
36
|
+
//# sourceMappingURL=grok-login-scope.d.ts.map
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which bots may share a Grok sign-in on this computer.
|
|
3
|
+
*
|
|
4
|
+
* The HQ Fleet helper (0.4.31) copies the first other bot's Grok OAuth login
|
|
5
|
+
* it finds, in profile-folder order, before it reads the Grok CLI login or
|
|
6
|
+
* asks for a new sign-in, and it knows nothing of companies. hq-cli cannot
|
|
7
|
+
* choose the bot it copies from, so the rule here is about every bot it
|
|
8
|
+
* could copy from. This module reads only bot.json files; the callers hand
|
|
9
|
+
* it the helper's yes or no per bot.
|
|
10
|
+
*/
|
|
11
|
+
import * as fs from "node:fs";
|
|
12
|
+
import * as path from "node:path";
|
|
13
|
+
import { effectiveBotCompanies, effectiveBotKind, readBotConfig } from "./config.js";
|
|
14
|
+
import { botsRoot } from "./paths.js";
|
|
15
|
+
export function newBotLoginScope(kind, companies) {
|
|
16
|
+
if (kind === "personal")
|
|
17
|
+
return "personal";
|
|
18
|
+
const slugs = [...new Set(companies.map((slug) => slug.trim()).filter(Boolean))].sort();
|
|
19
|
+
return slugs.length ? `company:${slugs.join(",")}` : null;
|
|
20
|
+
}
|
|
21
|
+
export function botLoginScope(config) {
|
|
22
|
+
return newBotLoginScope(effectiveBotKind(config), effectiveBotCompanies(config));
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The scope of each bot on this computer, by agent id, read from the bot
|
|
26
|
+
* folders' bot.json. An id with no readable bot.json, or one that two folders
|
|
27
|
+
* give different scopes, has no known scope.
|
|
28
|
+
*/
|
|
29
|
+
export function localBotLoginScopes(root = botsRoot()) {
|
|
30
|
+
const scopes = new Map();
|
|
31
|
+
let entries = [];
|
|
32
|
+
try {
|
|
33
|
+
entries = fs.readdirSync(root, { withFileTypes: true });
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
/* no bots here */
|
|
37
|
+
}
|
|
38
|
+
for (const entry of entries) {
|
|
39
|
+
if (!entry.isDirectory())
|
|
40
|
+
continue;
|
|
41
|
+
// readBotConfig answers null for a folder with no readable bot.json.
|
|
42
|
+
const config = readBotConfig(path.join(root, entry.name));
|
|
43
|
+
if (!config)
|
|
44
|
+
continue;
|
|
45
|
+
const uid = config.agentUid.toLowerCase();
|
|
46
|
+
const scope = botLoginScope(config);
|
|
47
|
+
scopes.set(uid, scopes.has(uid) && scopes.get(uid) !== scope ? null : scope);
|
|
48
|
+
}
|
|
49
|
+
return (agentUid) => scopes.get(agentUid.toLowerCase()) ?? null;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The answer for one bot from a scan of the others. `holders` hold a Grok
|
|
53
|
+
* OAuth login, `unanswered` are bots the helper could not answer for, `uids`
|
|
54
|
+
* is every bot with a Fleet profile. Reusable only when another bot holds a
|
|
55
|
+
* login and every other bot that holds one, or may hold one, has `scope`.
|
|
56
|
+
*/
|
|
57
|
+
export function grokLoginFromScan(scan, exclude, scope, scopeOf) {
|
|
58
|
+
const other = (agentUid) => agentUid.toLowerCase() !== exclude.toLowerCase();
|
|
59
|
+
// Fail closed: a missing scope on either side never matches.
|
|
60
|
+
const outside = (agentUid) => scope === null || scopeOf(agentUid) !== scope;
|
|
61
|
+
const holders = scan.holders.filter(other);
|
|
62
|
+
const others = scan.uids.filter(other);
|
|
63
|
+
const unanswered = scan.unanswered.filter(other);
|
|
64
|
+
const outsideHolders = holders.filter(outside);
|
|
65
|
+
if (outsideHolders.length) {
|
|
66
|
+
return {
|
|
67
|
+
readable: false,
|
|
68
|
+
blocked: true,
|
|
69
|
+
detail: `${outsideHolders.length} other HQ Fleet bot(s) on this computer are signed in to Grok for a different or unknown company, and a bot shares a Grok sign-in only within its own company`,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
const allUnanswered = `the HQ Fleet helper could not say whether any of the ${others.length} other Fleet bot(s) on this computer is signed in to Grok`;
|
|
73
|
+
const outsideUnanswered = unanswered.filter(outside);
|
|
74
|
+
if (outsideUnanswered.length) {
|
|
75
|
+
return {
|
|
76
|
+
readable: false,
|
|
77
|
+
blocked: true,
|
|
78
|
+
detail: unanswered.length === others.length
|
|
79
|
+
? allUnanswered
|
|
80
|
+
: `the HQ Fleet helper could not say whether ${outsideUnanswered.length} other Fleet bot(s) of a different or unknown company on this computer are signed in to Grok`,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
if (holders.length)
|
|
84
|
+
return { readable: true, detail: `the Grok sign-in of HQ Fleet bot ${holders[0]} on this computer` };
|
|
85
|
+
if (others.length && unanswered.length === others.length) {
|
|
86
|
+
return { readable: false, detail: allUnanswered };
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
readable: false,
|
|
90
|
+
detail: others.length ? `none of the ${others.length} other HQ Fleet bot(s) on this computer is signed in to Grok` : "no other HQ Fleet bot on this computer is signed in to Grok",
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=grok-login-scope.js.map
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { BotConfig } from "./config.js";
|
|
2
2
|
import { type FleetLocalProviderAuthStatus } from "./fleet-local.js";
|
|
3
3
|
import type { LegacyProviderLogin, LegacyProviderLoginProbe } from "./legacy-convert.js";
|
|
4
|
+
import { type BotLoginScope, type GrokSiblingLogin } from "./grok-login-scope.js";
|
|
5
|
+
export { botLoginScope, localBotLoginScopes, newBotLoginScope, type BotLoginScope, type GrokSiblingLogin } from "./grok-login-scope.js";
|
|
4
6
|
export declare function codexCliAuthPath(home: string): string;
|
|
5
7
|
/** The `exp` claim of a JWT, in seconds, or null when the token has none that reads. */
|
|
6
8
|
export declare function jwtExpiry(token: string): number | null;
|
|
@@ -23,6 +25,10 @@ export interface GrokLoginProbeDeps {
|
|
|
23
25
|
profileDir: string;
|
|
24
26
|
}>;
|
|
25
27
|
status?: (agentUid: string) => FleetLocalProviderAuthStatus | null;
|
|
28
|
+
/** The company scope of the bot that would share a login. Without one, no other bot's login counts. */
|
|
29
|
+
scope?: BotLoginScope;
|
|
30
|
+
/** The company scope of a bot here; null when it is not known. */
|
|
31
|
+
scopeOf?: (agentUid: string) => BotLoginScope;
|
|
26
32
|
}
|
|
27
33
|
/** The helper asks the keychain per profile, so one list of bots shares a scan this long. */
|
|
28
34
|
export declare const GROK_HOLDER_SCAN_TTL_MS = 30000;
|
|
@@ -33,31 +39,48 @@ export interface GrokLoginProbeAsyncDeps {
|
|
|
33
39
|
profileDir: string;
|
|
34
40
|
}>;
|
|
35
41
|
status?: (agentUid: string) => Promise<FleetLocalProviderAuthStatus | null>;
|
|
42
|
+
scope?: BotLoginScope;
|
|
43
|
+
scopeOf?: (agentUid: string) => BotLoginScope;
|
|
36
44
|
}
|
|
37
|
-
export declare function grokLoginReadableHereAsync(exclude: string, deps?: GrokLoginProbeAsyncDeps): Promise<
|
|
38
|
-
/**
|
|
39
|
-
|
|
45
|
+
export declare function grokLoginReadableHereAsync(exclude: string, deps?: GrokLoginProbeAsyncDeps): Promise<GrokSiblingLogin>;
|
|
46
|
+
/**
|
|
47
|
+
* Whether the helper's `_existing_machine_oauth` would give this bot a Grok
|
|
48
|
+
* login it may share. The helper copies the first other bot's login it finds
|
|
49
|
+
* and knows nothing of companies, so the answer is yes only when another
|
|
50
|
+
* Fleet bot here holds a Grok OAuth login and every other bot that holds one,
|
|
51
|
+
* or that the helper could not answer for, has the company scope `deps.scope`.
|
|
52
|
+
*/
|
|
53
|
+
export declare function grokLoginReadableHere(exclude: string, deps?: GrokLoginProbeDeps, now?: number): GrokSiblingLogin;
|
|
40
54
|
export declare const GROK_CLI_AUTH_ISSUER = "https://auth.x.ai";
|
|
41
55
|
export declare const FLEET_XAI_OAUTH_CLIENT_ID = "b1a00492-073a-47ea-816f-4c329264a828";
|
|
42
56
|
export declare function grokCliAuthPath(homedir?: string, env?: NodeJS.ProcessEnv): string;
|
|
43
57
|
export declare function grokCliLoginReadable(homedir?: string, env?: NodeJS.ProcessEnv): LegacyProviderLogin;
|
|
44
58
|
export declare function fleetHelperSharesGrokCliLogin(): boolean;
|
|
45
59
|
export interface GrokSignInDeps {
|
|
46
|
-
sibling?: () =>
|
|
60
|
+
sibling?: () => GrokSiblingLogin;
|
|
47
61
|
cli?: () => LegacyProviderLogin;
|
|
48
62
|
cliImport?: boolean;
|
|
63
|
+
/** The company scope of the bot that would sign in. Without one, no other bot's login counts. */
|
|
64
|
+
scope?: BotLoginScope;
|
|
49
65
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
66
|
+
/**
|
|
67
|
+
* A Grok sign-in the helper would import for a bot of company scope `deps.scope`.
|
|
68
|
+
* The helper tries the other Fleet bots before the Grok CLI login, so a
|
|
69
|
+
* blocked sibling answer also rules out the Grok CLI login.
|
|
70
|
+
*/
|
|
71
|
+
export declare function grokSignInReusableHere(exclude: string, deps?: GrokSignInDeps): GrokSiblingLogin;
|
|
72
|
+
/** The live probe for a bot: Codex from its login home, Grok from the Grok CLI or the other Fleet bots of its company here. */
|
|
73
|
+
export declare function legacyProviderLoginProbe(dir: string, config: Pick<BotConfig, "name" | "agentUid" | "runtime" | "runtimeAuth" | "hqRoot" | "kind" | "companies" | "workerId">): LegacyProviderLoginProbe;
|
|
53
74
|
export type FleetSignInProvider = "chatgpt" | "grok";
|
|
54
75
|
export interface FleetSignInHereDeps {
|
|
55
76
|
env?: NodeJS.ProcessEnv;
|
|
56
77
|
homedir?: string;
|
|
57
|
-
grok?: () =>
|
|
78
|
+
grok?: () => GrokSiblingLogin;
|
|
58
79
|
grokCli?: () => LegacyProviderLogin;
|
|
59
80
|
grokCliImport?: boolean;
|
|
60
81
|
now?: number;
|
|
82
|
+
/** The company scope of the bot that would sign in. Without one, no other bot's Grok sign-in counts. */
|
|
83
|
+
scope?: BotLoginScope;
|
|
61
84
|
}
|
|
62
|
-
export declare function fleetSignInReusableHere(provider: FleetSignInProvider, deps?: FleetSignInHereDeps):
|
|
85
|
+
export declare function fleetSignInReusableHere(provider: FleetSignInProvider, deps?: FleetSignInHereDeps): GrokSiblingLogin;
|
|
63
86
|
//# sourceMappingURL=legacy-provider-login.d.ts.map
|
|
@@ -6,7 +6,10 @@
|
|
|
6
6
|
* ~/.codex/auth.json) with a refreshable, unexpired token. A bot with its
|
|
7
7
|
* own Codex login (hq bot login) or a capacity account imports from that
|
|
8
8
|
* home instead, so the account it answered with comes along.
|
|
9
|
-
* - Grok: the helper copies another Fleet bot's Grok login
|
|
9
|
+
* - Grok: the helper copies another Fleet bot's Grok login. It takes the
|
|
10
|
+
* first one it finds, whatever company that bot belongs to, so the check
|
|
11
|
+
* here says yes only when every bot it could copy from has this bot's
|
|
12
|
+
* company scope. From release
|
|
10
13
|
* 0.4.31 (local builds from 0.4.31-local.13) also shares the Grok CLI login
|
|
11
14
|
* in <GROK_HOME>/auth.json, else ~/.grok/auth.json (a record for the
|
|
12
15
|
* runtime's xAI client with a refresh token). Its own
|
|
@@ -20,6 +23,8 @@ import * as fs from "node:fs";
|
|
|
20
23
|
import * as os from "node:os";
|
|
21
24
|
import * as path from "node:path";
|
|
22
25
|
import { cachedFleetLocalTargetRelease, fleetLocalProviderAuthStatus, fleetLocalProviderAuthStatusAsync, fleetReleaseImportsGrokCli, listFleetLocalProfiles } from "./fleet-local.js";
|
|
26
|
+
import { botLoginScope, grokLoginFromScan, localBotLoginScopes } from "./grok-login-scope.js";
|
|
27
|
+
export { botLoginScope, localBotLoginScopes, newBotLoginScope } from "./grok-login-scope.js";
|
|
23
28
|
import { botOwnAuthHome, botRuntimeAuth, capacityAccountHome } from "./runtime-auth.js";
|
|
24
29
|
export function codexCliAuthPath(home) {
|
|
25
30
|
return path.join(home, "auth.json");
|
|
@@ -124,26 +129,17 @@ export async function grokLoginReadableHereAsync(exclude, deps = {}) {
|
|
|
124
129
|
else if (found.authenticated && found.authType === "oauth")
|
|
125
130
|
holders.push(agentUid);
|
|
126
131
|
});
|
|
127
|
-
return grokLoginFromScan({ holders, uids: profiles.map((profile) => profile.agentUid), unanswered }, exclude);
|
|
132
|
+
return grokLoginFromScan({ holders, uids: profiles.map((profile) => profile.agentUid), unanswered }, exclude, deps.scope ?? null, deps.scopeOf ?? localBotLoginScopes());
|
|
128
133
|
}
|
|
129
|
-
/**
|
|
134
|
+
/**
|
|
135
|
+
* Whether the helper's `_existing_machine_oauth` would give this bot a Grok
|
|
136
|
+
* login it may share. The helper copies the first other bot's login it finds
|
|
137
|
+
* and knows nothing of companies, so the answer is yes only when another
|
|
138
|
+
* Fleet bot here holds a Grok OAuth login and every other bot that holds one,
|
|
139
|
+
* or that the helper could not answer for, has the company scope `deps.scope`.
|
|
140
|
+
*/
|
|
130
141
|
export function grokLoginReadableHere(exclude, deps = {}, now = Date.now()) {
|
|
131
|
-
return grokLoginFromScan(grokHolders(deps, now), exclude);
|
|
132
|
-
}
|
|
133
|
-
function grokLoginFromScan(scan, exclude) {
|
|
134
|
-
const other = (agentUid) => agentUid.toLowerCase() !== exclude.toLowerCase();
|
|
135
|
-
const holder = scan.holders.find(other);
|
|
136
|
-
if (holder)
|
|
137
|
-
return { readable: true, detail: `the Grok sign-in of HQ Fleet bot ${holder} on this computer` };
|
|
138
|
-
const others = scan.uids.filter(other);
|
|
139
|
-
const unanswered = scan.unanswered.filter(other);
|
|
140
|
-
if (others.length && unanswered.length === others.length) {
|
|
141
|
-
return { readable: false, detail: `the HQ Fleet helper could not say whether any of the ${others.length} other Fleet bot(s) on this computer is signed in to Grok` };
|
|
142
|
-
}
|
|
143
|
-
return {
|
|
144
|
-
readable: false,
|
|
145
|
-
detail: others.length ? `none of the ${others.length} other HQ Fleet bot(s) on this computer is signed in to Grok` : "no other HQ Fleet bot on this computer is signed in to Grok",
|
|
146
|
-
};
|
|
142
|
+
return grokLoginFromScan(grokHolders(deps, now), exclude, deps.scope ?? null, deps.scopeOf ?? localBotLoginScopes());
|
|
147
143
|
}
|
|
148
144
|
export const GROK_CLI_AUTH_ISSUER = "https://auth.x.ai";
|
|
149
145
|
export const FLEET_XAI_OAUTH_CLIENT_ID = "b1a00492-073a-47ea-816f-4c329264a828";
|
|
@@ -181,21 +177,30 @@ export function fleetHelperSharesGrokCliLogin() {
|
|
|
181
177
|
return false;
|
|
182
178
|
}
|
|
183
179
|
}
|
|
180
|
+
/**
|
|
181
|
+
* A Grok sign-in the helper would import for a bot of company scope `deps.scope`.
|
|
182
|
+
* The helper tries the other Fleet bots before the Grok CLI login, so a
|
|
183
|
+
* blocked sibling answer also rules out the Grok CLI login.
|
|
184
|
+
*/
|
|
184
185
|
export function grokSignInReusableHere(exclude, deps = {}) {
|
|
186
|
+
const sibling = (deps.sibling ?? (() => grokLoginReadableHere(exclude, { scope: deps.scope ?? null })))();
|
|
187
|
+
if (sibling.blocked)
|
|
188
|
+
return sibling;
|
|
185
189
|
if (deps.cliImport ?? fleetHelperSharesGrokCliLogin()) {
|
|
186
190
|
const cli = (deps.cli ?? (() => grokCliLoginReadable()))();
|
|
187
191
|
if (cli.readable)
|
|
188
192
|
return cli;
|
|
189
193
|
}
|
|
190
|
-
return
|
|
194
|
+
return sibling;
|
|
191
195
|
}
|
|
192
|
-
/** The live probe for a bot: Codex from its login home, Grok from the Grok CLI or the other Fleet bots here. */
|
|
196
|
+
/** The live probe for a bot: Codex from its login home, Grok from the Grok CLI or the other Fleet bots of its company here. */
|
|
193
197
|
export function legacyProviderLoginProbe(dir, config) {
|
|
194
198
|
return (runtime) => {
|
|
195
199
|
if (runtime === "grok") {
|
|
196
200
|
if (config.runtimeAuth?.grok !== undefined)
|
|
197
201
|
return { readable: false, detail: "it uses its own Grok login, which HQ Fleet Local cannot import" };
|
|
198
|
-
|
|
202
|
+
const login = grokSignInReusableHere(config.agentUid, { scope: botLoginScope(config) });
|
|
203
|
+
return { readable: login.readable, detail: login.detail };
|
|
199
204
|
}
|
|
200
205
|
const home = legacyCodexHome(dir, config);
|
|
201
206
|
if ("error" in home)
|
|
@@ -207,6 +212,7 @@ export function legacyProviderLoginProbe(dir, config) {
|
|
|
207
212
|
export function fleetSignInReusableHere(provider, deps = {}) {
|
|
208
213
|
if (provider === "grok") {
|
|
209
214
|
return grokSignInReusableHere("", {
|
|
215
|
+
scope: deps.scope ?? null,
|
|
210
216
|
...(deps.grok ? { sibling: deps.grok } : {}),
|
|
211
217
|
cli: deps.grokCli ?? (() => grokCliLoginReadable(deps.homedir ?? os.homedir(), deps.env ?? process.env)),
|
|
212
218
|
...(deps.grokCliImport !== undefined ? { cliImport: deps.grokCliImport } : {}),
|
|
@@ -47,7 +47,12 @@ export async function checkRuntimeSignIn(opts) {
|
|
|
47
47
|
}
|
|
48
48
|
catch (err) {
|
|
49
49
|
const message = err instanceof Error ? err.message : String(err);
|
|
50
|
-
return {
|
|
50
|
+
return {
|
|
51
|
+
signedIn: null,
|
|
52
|
+
checkedAt,
|
|
53
|
+
detail: `${opts.runtime.id} ${status.args.join(" ")} could not run: ${message.slice(0, 200)}`,
|
|
54
|
+
couldNotStart: true,
|
|
55
|
+
};
|
|
51
56
|
}
|
|
52
57
|
}
|
|
53
58
|
//# sourceMappingURL=runtime-sign-in-check.js.map
|
|
@@ -37,6 +37,8 @@ export interface RuntimeSignInCheck {
|
|
|
37
37
|
checkedAt: string;
|
|
38
38
|
/** Why the check could not tell, for the log and the JSON output. */
|
|
39
39
|
detail?: string;
|
|
40
|
+
/** Set when the status command could not be started at all (for example, the tool is not installed). */
|
|
41
|
+
couldNotStart?: true;
|
|
40
42
|
}
|
|
41
43
|
/** How long a passed check stands in for another before a turn. */
|
|
42
44
|
export declare const SIGN_IN_CHECK_FRESH_MS = 30000;
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import * as path from "node:path";
|
|
13
13
|
import { syncCoreUnitId } from "../sync-core/engine-home.js";
|
|
14
|
+
import { engineSettingsEnv } from "../sync-core/vault-settings.js";
|
|
14
15
|
import { engineOwnedManifestScopes } from "../sync-core/manifest-scopes.js";
|
|
15
16
|
import { SYNC_RUNNER_OWNER, syncRunnerUnleasedBlockReason } from "./sync-runner.js";
|
|
16
17
|
import { vaultSkipEnv } from "../vault-sync-switches.js";
|
|
@@ -268,6 +269,7 @@ function planService(service, ctx) {
|
|
|
268
269
|
HQ_SYNC_MODE: full ? "full" : "readonly",
|
|
269
270
|
...(full ? { HQ_SYNC_FULL_VAULT: "1", HQ_SYNC_PROTOCOL: "1" } : {}),
|
|
270
271
|
HQ_SYNC_CORE_RELEASE: vault.release,
|
|
272
|
+
...engineSettingsEnv(vault.settings),
|
|
271
273
|
},
|
|
272
274
|
...(full ? { heartbeatTimeoutMs: 180_000 } : {}),
|
|
273
275
|
blocked: firstBlock([
|
|
@@ -68,6 +68,7 @@ export interface DaemonHost {
|
|
|
68
68
|
systemUnitDir: string;
|
|
69
69
|
/** Extra environment baked into the unit (PATH of the installing shell, HQ_DAEMON_DIR). */
|
|
70
70
|
env?: Record<string, string>;
|
|
71
|
+
loginHome?: string;
|
|
71
72
|
}
|
|
72
73
|
export interface InstallOptions {
|
|
73
74
|
scope: InstallScope;
|
|
@@ -198,7 +199,7 @@ export interface RefreshDaemonPlistResult {
|
|
|
198
199
|
* finds the old plist (see daemonPlistNeedsRefresh). It must not run inside
|
|
199
200
|
* the daemon's own job: the bootout would end the caller before the bootstrap.
|
|
200
201
|
*/
|
|
201
|
-
export declare function refreshDaemonPlist(host: Pick<DaemonHost, "home" | "uid">, deps: {
|
|
202
|
+
export declare function refreshDaemonPlist(host: Pick<DaemonHost, "home" | "uid" | "loginHome">, deps: {
|
|
202
203
|
run: RunCommand;
|
|
203
204
|
sleep?: SleepFn;
|
|
204
205
|
}): RefreshDaemonPlistResult;
|
|
@@ -26,6 +26,7 @@ import { readPidLock } from "../mesh/live/daemon/pid-lock.js";
|
|
|
26
26
|
import { userToolDirs } from "./tools.js";
|
|
27
27
|
import { liveDaemonLock, verifyDaemonForKill } from "./lock.js";
|
|
28
28
|
import { daemonPaths } from "./paths.js";
|
|
29
|
+
import { assertLoginHome, homeIsLoginSafe } from "../mesh/live/daemon/unit-home.js";
|
|
29
30
|
export const DAEMON_LAUNCHD_LABEL = "ai.getindigo.hq-daemon";
|
|
30
31
|
export const DAEMON_SYSTEMD_UNIT = "hq-daemon.service";
|
|
31
32
|
/**
|
|
@@ -427,6 +428,8 @@ function activate(plan, host, run, sleep, previous = null) {
|
|
|
427
428
|
}
|
|
428
429
|
}
|
|
429
430
|
export function installDaemonUnit(host, options, deps) {
|
|
431
|
+
if (host.platform === "darwin")
|
|
432
|
+
assertLoginHome("install", host.home, host.loginHome, DAEMON_LAUNCHD_LABEL);
|
|
430
433
|
const plan = planDaemonUnit(host, options);
|
|
431
434
|
if (plan.kind === "manual") {
|
|
432
435
|
return { kind: plan.kind, unitPath: "", installed: false, running: false, manualCommand: plan.manualCommand };
|
|
@@ -584,6 +587,8 @@ export function retryLaunchdBootstrap(plistPath, run, uid, sleep = blockingSleep
|
|
|
584
587
|
*/
|
|
585
588
|
export function refreshDaemonPlist(host, deps) {
|
|
586
589
|
const plistPath = launchdPlistPath(host.home, { label: DAEMON_LAUNCHD_LABEL });
|
|
590
|
+
if (!homeIsLoginSafe(host.home, host.loginHome))
|
|
591
|
+
return { action: "none", plistPath };
|
|
587
592
|
if (!fs.existsSync(plistPath))
|
|
588
593
|
return { action: "none", plistPath };
|
|
589
594
|
const source = fs.readFileSync(plistPath, "utf8");
|
|
@@ -751,6 +756,8 @@ export function daemonServiceStatus(host, run, daemonPid) {
|
|
|
751
756
|
*/
|
|
752
757
|
export function startDaemonUnit(host, deps) {
|
|
753
758
|
const sleep = deps.sleep ?? blockingSleep;
|
|
759
|
+
if (host.platform === "darwin")
|
|
760
|
+
assertLoginHome("start", host.home, host.loginHome, DAEMON_LAUNCHD_LABEL);
|
|
754
761
|
// An older install's plist runs through HQ.app and is skipped at login:
|
|
755
762
|
// rewrite it first, so the unit this loads or starts is the fixed one.
|
|
756
763
|
const previousPid = deps.daemonPid();
|
|
@@ -954,6 +961,8 @@ export function windowsInteractiveSession(run, user) {
|
|
|
954
961
|
});
|
|
955
962
|
}
|
|
956
963
|
export function uninstallDaemonUnit(host, options, deps) {
|
|
964
|
+
if (host.platform === "darwin")
|
|
965
|
+
assertLoginHome("remove", host.home, host.loginHome, DAEMON_LAUNCHD_LABEL);
|
|
957
966
|
// A system uninstall does not need the login user; only the unit path matters.
|
|
958
967
|
const plan = host.platform === "linux" && options.scope === "system"
|
|
959
968
|
? { kind: "systemd-system", unitPath: path.join(host.systemUnitDir, DAEMON_SYSTEMD_UNIT), rendered: "" }
|
|
@@ -30,6 +30,7 @@ export interface LegacyProbeDeps {
|
|
|
30
30
|
listDir: (dir: string) => string[];
|
|
31
31
|
/** True when launchctl can print the GUI-domain job despite a missing plist. */
|
|
32
32
|
launchdJobLoaded: (label: string) => boolean;
|
|
33
|
+
homeIsLogin?: boolean;
|
|
33
34
|
/** Whether the task exists and runs as the current user. Another user's task is never taken over. */
|
|
34
35
|
windowsTaskOwner: (taskName: string) => WindowsTaskOwner;
|
|
35
36
|
/**
|
|
@@ -55,8 +55,11 @@ function darwinUnits(deps) {
|
|
|
55
55
|
const at = (label) => path.join(dir, `${label}.plist`);
|
|
56
56
|
const add = (unitId, service, label, migratable = true) => units.push({ unitId, service, kind: "launchd", name: label, path: at(label), migratable });
|
|
57
57
|
const meshLabel = "ai.getindigo.hq-mesh-daemon";
|
|
58
|
-
if (deps.existsSync(at(meshLabel)) || deps.launchdJobLoaded(meshLabel))
|
|
59
|
-
add("mesh", "mesh", meshLabel);
|
|
58
|
+
if (deps.existsSync(at(meshLabel)) || deps.launchdJobLoaded(meshLabel)) {
|
|
59
|
+
add("mesh", "mesh", meshLabel, deps.homeIsLogin !== false);
|
|
60
|
+
if (deps.homeIsLogin === false)
|
|
61
|
+
units[units.length - 1].notMineReason = "HOME is not this account's home folder, and macOS has one Work Mesh service per login";
|
|
62
|
+
}
|
|
60
63
|
for (const file of safeList(deps, dir).sort()) {
|
|
61
64
|
const m = /^ai\.getindigo\.hq-bot\.(.+)\.plist$/.exec(file);
|
|
62
65
|
if (m)
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { NATIVE_NOTICE_LEDGER_FILE, NATIVE_NOTICE_LEDGER_REFUSED, nativeNoticeLedgerUsable } from "./native-notice-ledger.js";
|
|
1
2
|
/**
|
|
2
3
|
* How old the daemon's machine-check results file may be and still count as
|
|
3
4
|
* proof the schedule is running: two hourly intervals plus the first delay,
|
|
4
5
|
* so one late or skipped batch does not flip the owner.
|
|
5
6
|
*/
|
|
6
7
|
export declare const MACHINE_CHECK_RESULTS_FRESH_MS: number;
|
|
8
|
+
export { NATIVE_NOTICE_LEDGER_FILE, NATIVE_NOTICE_LEDGER_REFUSED, nativeNoticeLedgerUsable };
|
|
7
9
|
/** Internal, offline protocol shared with the legacy dispatcher. */
|
|
8
10
|
export declare function machineCheckOwner(env?: NodeJS.ProcessEnv, home?: string, options?: {
|
|
9
11
|
now?: Date;
|
|
@@ -7,6 +7,7 @@ import { readDaemonConfig } from "./config.js";
|
|
|
7
7
|
import { sameHqRoot } from "../hook-engine/registration-identity.js";
|
|
8
8
|
import { nativeSessionStartRegistered } from "./machine-check-registration.js";
|
|
9
9
|
import { codexEnvEvidence, grokEnvEvidence } from "../doctor/platform.js";
|
|
10
|
+
import { NATIVE_NOTICE_LEDGER_FILE, NATIVE_NOTICE_LEDGER_REFUSED, nativeNoticeLedgerUsable } from "./native-notice-ledger.js";
|
|
10
11
|
/**
|
|
11
12
|
* How old the daemon's machine-check results file may be and still count as
|
|
12
13
|
* proof the schedule is running: two hourly intervals plus the first delay,
|
|
@@ -16,6 +17,7 @@ export const MACHINE_CHECK_RESULTS_FRESH_MS = 2 * MACHINE_CHECKS_INTERVAL_MS + M
|
|
|
16
17
|
function errorName(error) {
|
|
17
18
|
return error instanceof Error ? error.code ?? error.name : "UnknownError";
|
|
18
19
|
}
|
|
20
|
+
export { NATIVE_NOTICE_LEDGER_FILE, NATIVE_NOTICE_LEDGER_REFUSED, nativeNoticeLedgerUsable };
|
|
19
21
|
/**
|
|
20
22
|
* The session's harness: `HQ_HARNESS` when set, else the Codex or Grok runtime
|
|
21
23
|
* variables (the same markers `lanes` uses for the orchestrator engine), else
|
|
@@ -36,7 +38,8 @@ function sessionHarness(env) {
|
|
|
36
38
|
* when every host-local signal shows the schedule is really running here:
|
|
37
39
|
* not Windows (checks start with /bin/bash), the rollout flag is on with no
|
|
38
40
|
* kill switch, the daemon heartbeat file is fresh, and the schedule wrote its
|
|
39
|
-
* results file (which needs a resolved HQ root) within the freshness window
|
|
41
|
+
* results file (which needs a resolved HQ root) within the freshness window,
|
|
42
|
+
* and the native notice can use its ledger (nativeNoticeLedgerUsable).
|
|
40
43
|
* Anything that cannot be observed answers "legacy" with the reason.
|
|
41
44
|
*/
|
|
42
45
|
function decideOwner(env, home, now, platform) {
|
|
@@ -80,6 +83,8 @@ function decideOwner(env, home, now, platform) {
|
|
|
80
83
|
if (!Number.isFinite(age) || age > MACHINE_CHECK_RESULTS_FRESH_MS) {
|
|
81
84
|
return { owner: "legacy", reason: "machine-check results stale" };
|
|
82
85
|
}
|
|
86
|
+
if (!nativeNoticeLedgerUsable(env, home))
|
|
87
|
+
return { owner: "legacy", reason: NATIVE_NOTICE_LEDGER_REFUSED };
|
|
83
88
|
return { owner: "daemon", reason: "daemon live and schedule results fresh" };
|
|
84
89
|
}
|
|
85
90
|
/** Internal, offline protocol shared with the legacy dispatcher. */
|