@indigoai-us/hq-cli 5.345.219 → 5.345.221
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 +170 -0
- package/dist/command-catalog.generated.d.ts +169 -3
- package/dist/command-catalog.generated.js +206 -3
- package/dist/commands/auth.js +4 -1
- package/dist/commands/bot-runtime.d.ts +18 -5
- package/dist/commands/bot-runtime.js +29 -12
- package/dist/commands/bot.d.ts +85 -0
- package/dist/commands/bot.js +245 -16
- package/dist/commands/cloud.d.ts +16 -0
- package/dist/commands/cloud.js +112 -102
- package/dist/commands/core-checkpoint-native.d.ts +13 -0
- package/dist/commands/core-checkpoint-native.js +167 -52
- package/dist/commands/core-hook-registration-plan.js +5 -4
- 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 +5 -0
- package/dist/commands/daemon.js +52 -9
- 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/integrations.js +84 -3
- 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/packs.js +23 -0
- package/dist/commands/pkg-update.d.ts +6 -0
- package/dist/commands/pkg-update.js +15 -7
- package/dist/commands/run.js +55 -45
- package/dist/commands/sources.js +4 -3
- package/dist/commands/sync-core.d.ts +1 -0
- package/dist/commands/sync-core.js +77 -3
- package/dist/commands/whoami.js +96 -80
- package/dist/lib/bot/config.d.ts +17 -0
- package/dist/lib/bot/config.js +13 -0
- package/dist/lib/bot/fleet-cron.js +29 -4
- 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/inflight.d.ts +9 -0
- package/dist/lib/bot/jobs/hot-signal-sync.d.ts +51 -0
- package/dist/lib/bot/jobs/hot-signal-sync.js +90 -9
- 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/run.d.ts +29 -5
- package/dist/lib/bot/run.js +203 -1
- 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/bot/signals-try-now.d.ts +76 -0
- package/dist/lib/bot/signals-try-now.js +111 -0
- package/dist/lib/capacity/collectors/claude-oauth.d.ts +22 -3
- package/dist/lib/capacity/collectors/claude-oauth.js +78 -22
- package/dist/lib/capacity/scheduler.d.ts +8 -0
- package/dist/lib/capacity/scheduler.js +5 -2
- package/dist/lib/core-utils/sentry-report.js +2 -0
- package/dist/lib/daemon/machine-checks.d.ts +22 -1
- package/dist/lib/daemon/machine-checks.js +54 -12
- package/dist/lib/daemon/run.js +71 -8
- package/dist/lib/daemon/runtime-notifications.d.ts +7 -0
- package/dist/lib/daemon/runtime-notifications.js +50 -0
- 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.d.ts +9 -1
- package/dist/lib/doctor/checks/fleet-hook-core.js +39 -15
- 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 +137 -7
- package/dist/lib/hook-engine/coverage.js +1424 -4
- package/dist/lib/hook-engine/fleet-registration.d.ts +17 -5
- package/dist/lib/hook-engine/fleet-registration.js +53 -17
- package/dist/lib/hook-engine/git-stop-config.json +513 -0
- package/dist/lib/hook-engine/native-stop-compatibility.json +311 -0
- package/dist/lib/hook-engine/reconcile.js +2 -2
- package/dist/lib/hot-channels/alert.d.ts +10 -1
- package/dist/lib/hot-channels/alert.js +38 -8
- package/dist/lib/hot-channels/signals-claude-login.d.ts +53 -0
- package/dist/lib/hot-channels/signals-claude-login.js +96 -0
- package/dist/lib/hot-channels/signals-pass.d.ts +143 -17
- package/dist/lib/hot-channels/signals-pass.js +324 -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/placement/match.d.ts +192 -0
- package/dist/lib/placement/match.js +667 -0
- package/dist/lib/safe-store.d.ts +14 -0
- package/dist/lib/safe-store.js +77 -4
- package/dist/lib/search-index/index.d.ts +88 -4
- package/dist/lib/search-index/index.js +299 -25
- package/dist/lib/search-index/max-doc-bytes.d.ts +17 -6
- package/dist/lib/search-index/max-doc-bytes.js +48 -23
- 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 +28 -0
- package/dist/lib/signals/engine.js +77 -0
- package/dist/lib/signals/reply.d.ts +48 -0
- package/dist/lib/signals/reply.js +94 -12
- 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/adapters.js +6 -0
- package/dist/lib/signals/steps/extract.d.ts +135 -12
- package/dist/lib/signals/steps/extract.js +416 -84
- package/dist/lib/signals/steps/types.d.ts +21 -0
- package/dist/lib/sync-core/engine-home.d.ts +41 -2
- package/dist/lib/sync-core/engine-home.js +132 -19
- package/dist/lib/sync-core/reconcile.js +1 -1
- package/dist/lib/sync-core/release-compare.d.ts +7 -0
- package/dist/lib/sync-core/release-compare.js +16 -0
- package/dist/lib/sync-core/release.d.ts +2 -1
- package/dist/lib/sync-core/release.js +2 -10
- 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-uid.d.ts +2 -0
- package/dist/lib/sync-core/vault-uid.js +4 -0
- package/dist/run/schema-env-overrides.d.ts +24 -0
- package/dist/run/schema-env-overrides.js +72 -0
- 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.d.ts +1 -1
- package/dist/utils/host-registration.js +6 -1
- package/dist/utils/resident-package-preload.js +4 -0
- package/dist/utils/sentry-fingerprint.js +9 -0
- package/dist/utils/windows-bash.d.ts +2 -0
- package/dist/utils/windows-bash.js +2 -1
- package/package.json +15 -10
- package/scripts/bench-core-compare.mjs +313 -0
- package/scripts/bench-core.mjs +399 -12
- package/scripts/check-function-manifest.mjs +121 -7
- package/dist/commands/__fixtures__/access-vault.d.ts +0 -95
- package/dist/commands/__fixtures__/access-vault.js +0 -166
- package/dist/commands/__fixtures__/make-tar.d.ts +0 -38
- package/dist/commands/__fixtures__/make-tar.js +0 -102
- package/dist/commands/secrets-public-types.test-d.d.ts +0 -2
- package/dist/commands/secrets-public-types.test-d.js +0 -18
- package/dist/lib/decisions/fixtures/us001.d.ts +0 -137
- package/dist/lib/decisions/fixtures/us001.js +0 -21
- package/dist/lib/doctor/__testing__/fake-hq-tree.d.ts +0 -226
- package/dist/lib/doctor/__testing__/fake-hq-tree.js +0 -408
- package/dist/lib/doctor/__testing__/run-doctor.d.ts +0 -8
- package/dist/lib/doctor/__testing__/run-doctor.js +0 -69
- package/dist/lib/fingerprint/fixtures.d.ts +0 -19
- package/dist/lib/fingerprint/fixtures.js +0 -61
- package/dist/lib/hot-channels/adapters/__fixtures__/dummy.d.ts +0 -33
- package/dist/lib/hot-channels/adapters/__fixtures__/dummy.js +0 -53
- package/dist/lib/hot-channels/adapters/__fixtures__/meeting-providers.d.ts +0 -38
- package/dist/lib/hot-channels/adapters/__fixtures__/meeting-providers.js +0 -64
- package/dist/lib/mesh/live/daemon/mqtt-events.test-d.d.ts +0 -2
- package/dist/lib/mesh/live/daemon/mqtt-events.test-d.js +0 -10
- package/dist/lib/test-utils/isolated-flag-company-context.d.ts +0 -3
- package/dist/lib/test-utils/isolated-flag-company-context.js +0 -18
- package/scripts/hook-engine-manifest.mjs +0 -22
- package/scripts/mesh-daemon-if-stale.mjs +0 -20
package/dist/commands/whoami.js
CHANGED
|
@@ -11,6 +11,7 @@ import { queuePlanLimitInviteTeammateExposure } from "../utils/cli-telemetry.js"
|
|
|
11
11
|
import { resolveCallerPersonUid } from "../utils/vault-api.js";
|
|
12
12
|
import { printDeletedCompanyNotices } from "../utils/deleted-company-notice.js";
|
|
13
13
|
import { authExpiryIso, formatAuthExpiry } from "../utils/auth-expiry.js";
|
|
14
|
+
import { authStatusExitCode } from "../utils/auth-session-check.js";
|
|
14
15
|
export const CLI_LIMIT_INVITE_TEAMMATE_FLAG = "cli.limit-invite-teammate-v1";
|
|
15
16
|
/**
|
|
16
17
|
* Resolves the person represented by an ID token without pairing a delegated
|
|
@@ -169,6 +170,7 @@ export function registerWhoamiCommand(program) {
|
|
|
169
170
|
.description('Show signed-in user and session expiry')
|
|
170
171
|
.option('--json', 'Output identity metadata as JSON (never tokens)')
|
|
171
172
|
.option('--company <slug>', 'Also report this company\'s billing and usage notice')
|
|
173
|
+
.option('--check', 'Exit 1 when there is no usable session, like `hq auth status`')
|
|
172
174
|
.action(async (opts) => {
|
|
173
175
|
try {
|
|
174
176
|
// Effective source (same as auth status / ensureCognitoToken): env
|
|
@@ -176,87 +178,18 @@ export function registerWhoamiCommand(program) {
|
|
|
176
178
|
// after a definitive person-refresh rejection marked the session rejected.
|
|
177
179
|
const machine = resolveCognitoTokenSource() === "machine";
|
|
178
180
|
const cached = loadCachedTokens();
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
const claims = identityCache ? decodeIdToken(identityCache.idToken) : {};
|
|
185
|
-
// Modern credentials carry the canonical UID. Legacy caches may only
|
|
186
|
-
// supply a UID when their subject is bound to the selected username.
|
|
187
|
-
const boundLegacyAgent = machineCreds && identity.entityType === 'agent'
|
|
188
|
-
&& (claims['cognito:username'] === machineCreds.username
|
|
189
|
-
|| claims.username === machineCreds.username || claims.sub === machineCreds.username)
|
|
190
|
-
? identity.entityUid ?? null : null;
|
|
191
|
-
const agentUid = machineCreds?.entityUid !== undefined
|
|
192
|
-
? (machineCreds.entityUid.startsWith('agt_') ? machineCreds.entityUid : null)
|
|
193
|
-
: boundLegacyAgent;
|
|
194
|
-
// planLimits is additive: absent-or-null means UNKNOWN.
|
|
195
|
-
const planLimits = await readPlanLimits(opts.company);
|
|
196
|
-
const authenticated = machine ? Boolean(machineCreds) : Boolean(cached && !isExpiring(cached, 0));
|
|
197
|
-
const personUid = !machine && authenticated ? await readPersonUid(identity) : null;
|
|
198
|
-
console.log(JSON.stringify({
|
|
199
|
-
schemaVersion: 1,
|
|
200
|
-
authenticated,
|
|
181
|
+
// `--check` keeps the `hq auth status` exit contract (US-041). Read
|
|
182
|
+
// from the same state auth status reads, before any lookup below
|
|
183
|
+
// could refresh the cache, and with the same shared predicate.
|
|
184
|
+
const checkExitCode = opts.check
|
|
185
|
+
? authStatusExitCode({
|
|
201
186
|
tokenSource: machine ? 'machine' : 'person',
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
delegatedEmail: identity.delegatedEmail !== undefined && identity.delegatedSub !== undefined
|
|
209
|
-
? identity.delegatedEmail : null,
|
|
210
|
-
delegatedSub: identity.delegatedEmail !== undefined && identity.delegatedSub !== undefined
|
|
211
|
-
? identity.delegatedSub : null,
|
|
212
|
-
personUid,
|
|
213
|
-
agentUid,
|
|
214
|
-
username: machineCreds?.username ?? null,
|
|
215
|
-
// Additive (what `hq auth status` reported): when the cached
|
|
216
|
-
// session expires, and whether it is inside the refresh window.
|
|
217
|
-
// Both are null when no session is cached.
|
|
218
|
-
sessionExpiresAt: identityCache ? authExpiryIso(identityCache.expiresAt) : null,
|
|
219
|
-
sessionExpiring: identityCache ? isExpiring(identityCache) : null,
|
|
220
|
-
planLimits,
|
|
221
|
-
}, null, 2));
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
if (machine) {
|
|
225
|
-
// Machine identities (company agents) mint sessions on demand from
|
|
226
|
-
// long-lived creds — report the machine identity honestly even when
|
|
227
|
-
// no session is cached yet.
|
|
228
|
-
const username = loadMachineCreds()?.username ?? 'unknown';
|
|
229
|
-
const entityUid = cached
|
|
230
|
-
? peekIdToken(cached.idToken).entityUid
|
|
231
|
-
: undefined;
|
|
232
|
-
console.log(`Machine identity ${username}${entityUid ? ` (agent ${entityUid})` : ''} — sessions mint automatically`);
|
|
233
|
-
// Machine tokens live in the daemon state dir, never ~/.hq.
|
|
234
|
-
const machineSession = loadMachineCachedTokens();
|
|
235
|
-
if (machineSession)
|
|
236
|
-
console.log(sessionStatusLine(machineSession));
|
|
237
|
-
console.log(`token source: machine`);
|
|
238
|
-
await printPlanBlock(opts.company);
|
|
239
|
-
return;
|
|
240
|
-
}
|
|
241
|
-
if (!cached) {
|
|
242
|
-
// No session, so no session status or token source to report.
|
|
243
|
-
console.log("Not logged in. Run 'hq login' to authenticate.");
|
|
244
|
-
return;
|
|
245
|
-
}
|
|
246
|
-
if (isExpiring(cached, 0)) {
|
|
247
|
-
const who = resolveWhoamiIdentity(peekIdToken(cached.idToken)).email ?? 'unknown';
|
|
248
|
-
console.log(chalk.yellow(`Session expired for ${who}. Run 'hq login' to re-authenticate.`));
|
|
249
|
-
console.log(chalk.dim('token source: person'));
|
|
250
|
-
return;
|
|
251
|
-
}
|
|
252
|
-
const { email, sub } = resolveWhoamiIdentity(peekIdToken(cached.idToken));
|
|
253
|
-
console.log(`Logged in as ${email ?? 'unknown'}${sub ? ` (${sub})` : ''}`);
|
|
254
|
-
console.log(sessionStatusLine(cached));
|
|
255
|
-
console.log(chalk.dim('token source: person'));
|
|
256
|
-
await printPlanBlock(opts.company);
|
|
257
|
-
// Person sessions only: a deleted company is otherwise invisible here.
|
|
258
|
-
// Bounded like the person-uid lookup, on stderr, and never a failure.
|
|
259
|
-
await printDeletedCompanyNotices({ timeoutMs: PERSON_UID_LOOKUP_TIMEOUT_MS });
|
|
187
|
+
cached: machine ? loadMachineCachedTokens() : cached,
|
|
188
|
+
})
|
|
189
|
+
: 0;
|
|
190
|
+
await printWhoami(opts, machine, cached);
|
|
191
|
+
if (checkExitCode !== 0)
|
|
192
|
+
process.exit(checkExitCode);
|
|
260
193
|
}
|
|
261
194
|
catch (error) {
|
|
262
195
|
console.error(chalk.red('Error:'), error instanceof Error ? error.message : 'Unknown error');
|
|
@@ -264,4 +197,87 @@ export function registerWhoamiCommand(program) {
|
|
|
264
197
|
}
|
|
265
198
|
});
|
|
266
199
|
}
|
|
200
|
+
async function printWhoami(opts, machine, cached) {
|
|
201
|
+
if (opts.json) {
|
|
202
|
+
const machineCreds = machine ? loadMachineCreds() : null;
|
|
203
|
+
const identityCache = machine ? loadMachineCachedTokens() : cached;
|
|
204
|
+
const identity = identityCache ? peekIdToken(identityCache.idToken) : {};
|
|
205
|
+
const displayedIdentity = resolveWhoamiIdentity(identity);
|
|
206
|
+
const claims = identityCache ? decodeIdToken(identityCache.idToken) : {};
|
|
207
|
+
// Modern credentials carry the canonical UID. Legacy caches may only
|
|
208
|
+
// supply a UID when their subject is bound to the selected username.
|
|
209
|
+
const boundLegacyAgent = machineCreds && identity.entityType === 'agent'
|
|
210
|
+
&& (claims['cognito:username'] === machineCreds.username
|
|
211
|
+
|| claims.username === machineCreds.username || claims.sub === machineCreds.username)
|
|
212
|
+
? identity.entityUid ?? null : null;
|
|
213
|
+
const agentUid = machineCreds?.entityUid !== undefined
|
|
214
|
+
? (machineCreds.entityUid.startsWith('agt_') ? machineCreds.entityUid : null)
|
|
215
|
+
: boundLegacyAgent;
|
|
216
|
+
// planLimits is additive: absent-or-null means UNKNOWN.
|
|
217
|
+
const planLimits = await readPlanLimits(opts.company);
|
|
218
|
+
const authenticated = machine ? Boolean(machineCreds) : Boolean(cached && !isExpiring(cached, 0));
|
|
219
|
+
const personUid = !machine && authenticated ? await readPersonUid(identity) : null;
|
|
220
|
+
console.log(JSON.stringify({
|
|
221
|
+
schemaVersion: 1,
|
|
222
|
+
authenticated,
|
|
223
|
+
tokenSource: machine ? 'machine' : 'person',
|
|
224
|
+
email: machine ? null : displayedIdentity.email ?? null,
|
|
225
|
+
// Cognito subject of the person shown in `email` (null for machine
|
|
226
|
+
// identities). Outpost jobs record owners by this id.
|
|
227
|
+
sub: machine ? null : displayedIdentity.sub ?? null,
|
|
228
|
+
// The human an Outpost session acts for, from the token's
|
|
229
|
+
// delegated claims, for machine and person sources alike.
|
|
230
|
+
delegatedEmail: identity.delegatedEmail !== undefined && identity.delegatedSub !== undefined
|
|
231
|
+
? identity.delegatedEmail : null,
|
|
232
|
+
delegatedSub: identity.delegatedEmail !== undefined && identity.delegatedSub !== undefined
|
|
233
|
+
? identity.delegatedSub : null,
|
|
234
|
+
personUid,
|
|
235
|
+
agentUid,
|
|
236
|
+
username: machineCreds?.username ?? null,
|
|
237
|
+
// Additive (what `hq auth status` reported): when the cached
|
|
238
|
+
// session expires, and whether it is inside the refresh window.
|
|
239
|
+
// Both are null when no session is cached.
|
|
240
|
+
sessionExpiresAt: identityCache ? authExpiryIso(identityCache.expiresAt) : null,
|
|
241
|
+
sessionExpiring: identityCache ? isExpiring(identityCache) : null,
|
|
242
|
+
planLimits,
|
|
243
|
+
}, null, 2));
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
if (machine) {
|
|
247
|
+
// Machine identities (company agents) mint sessions on demand from
|
|
248
|
+
// long-lived creds — report the machine identity honestly even when
|
|
249
|
+
// no session is cached yet.
|
|
250
|
+
const username = loadMachineCreds()?.username ?? 'unknown';
|
|
251
|
+
const entityUid = cached
|
|
252
|
+
? peekIdToken(cached.idToken).entityUid
|
|
253
|
+
: undefined;
|
|
254
|
+
console.log(`Machine identity ${username}${entityUid ? ` (agent ${entityUid})` : ''} — sessions mint automatically`);
|
|
255
|
+
// Machine tokens live in the daemon state dir, never ~/.hq.
|
|
256
|
+
const machineSession = loadMachineCachedTokens();
|
|
257
|
+
if (machineSession)
|
|
258
|
+
console.log(sessionStatusLine(machineSession));
|
|
259
|
+
console.log(`token source: machine`);
|
|
260
|
+
await printPlanBlock(opts.company);
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
if (!cached) {
|
|
264
|
+
// No session, so no session status or token source to report.
|
|
265
|
+
console.log("Not logged in. Run 'hq login' to authenticate.");
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
if (isExpiring(cached, 0)) {
|
|
269
|
+
const who = resolveWhoamiIdentity(peekIdToken(cached.idToken)).email ?? 'unknown';
|
|
270
|
+
console.log(chalk.yellow(`Session expired for ${who}. Run 'hq login' to re-authenticate.`));
|
|
271
|
+
console.log(chalk.dim('token source: person'));
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
const { email, sub } = resolveWhoamiIdentity(peekIdToken(cached.idToken));
|
|
275
|
+
console.log(`Logged in as ${email ?? 'unknown'}${sub ? ` (${sub})` : ''}`);
|
|
276
|
+
console.log(sessionStatusLine(cached));
|
|
277
|
+
console.log(chalk.dim('token source: person'));
|
|
278
|
+
await printPlanBlock(opts.company);
|
|
279
|
+
// Person sessions only: a deleted company is otherwise invisible here.
|
|
280
|
+
// Bounded like the person-uid lookup, on stderr, and never a failure.
|
|
281
|
+
await printDeletedCompanyNotices({ timeoutMs: PERSON_UID_LOOKUP_TIMEOUT_MS });
|
|
282
|
+
}
|
|
267
283
|
//# sourceMappingURL=whoami.js.map
|
package/dist/lib/bot/config.d.ts
CHANGED
|
@@ -178,7 +178,24 @@ export interface BotConfig {
|
|
|
178
178
|
* capacity account home. Names only, never a credential.
|
|
179
179
|
*/
|
|
180
180
|
runtimeAuth?: BotRuntimeAuthMap;
|
|
181
|
+
/**
|
|
182
|
+
* Which model the local hot-channel signals pass uses (signals-pass.ts).
|
|
183
|
+
* Unset or "claude": Claude Code, as before. "bot": the bot's own runtime,
|
|
184
|
+
* which today takes effect for a Codex bot only (a Claude bot already runs
|
|
185
|
+
* on Claude; Grok is not supported). Per bot and local; set with
|
|
186
|
+
* `hq bot set <name> --signals-runtime bot|claude`.
|
|
187
|
+
*/
|
|
188
|
+
signalsRuntime?: BotSignalsRuntimeSetting;
|
|
181
189
|
}
|
|
190
|
+
/** The `signalsRuntime` values bot.json accepts. */
|
|
191
|
+
export declare const BOT_SIGNALS_RUNTIME_SETTINGS: readonly ["claude", "bot"];
|
|
192
|
+
export type BotSignalsRuntimeSetting = (typeof BOT_SIGNALS_RUNTIME_SETTINGS)[number];
|
|
193
|
+
/**
|
|
194
|
+
* The tool the hot-channel signals pass runs on for this bot: Codex only for
|
|
195
|
+
* a Codex bot that opted in with `signalsRuntime: "bot"`, Claude Code for
|
|
196
|
+
* every other bot (and for no bot at all).
|
|
197
|
+
*/
|
|
198
|
+
export declare function signalsPassRuntime(config: Pick<BotConfig, "runtime" | "signalsRuntime"> | null | undefined): "claude" | "codex";
|
|
182
199
|
export declare function readBotConfig(dir: string): BotConfig | null;
|
|
183
200
|
export declare function writeBotConfig(dir: string, config: BotConfig): void;
|
|
184
201
|
/** "local" when the memory folder is an absolute path outside the HQ tree. */
|
package/dist/lib/bot/config.js
CHANGED
|
@@ -204,6 +204,19 @@ export function validateBotKickoff(text) {
|
|
|
204
204
|
}
|
|
205
205
|
return trimmed;
|
|
206
206
|
}
|
|
207
|
+
/** The `signalsRuntime` values bot.json accepts. */
|
|
208
|
+
export const BOT_SIGNALS_RUNTIME_SETTINGS = ["claude", "bot"];
|
|
209
|
+
/**
|
|
210
|
+
* The tool the hot-channel signals pass runs on for this bot: Codex only for
|
|
211
|
+
* a Codex bot that opted in with `signalsRuntime: "bot"`, Claude Code for
|
|
212
|
+
* every other bot (and for no bot at all).
|
|
213
|
+
*/
|
|
214
|
+
export function signalsPassRuntime(config) {
|
|
215
|
+
// Whether that bot's Codex login may be used (an HQ Fleet Runtime bot's may
|
|
216
|
+
// not) is decided in one place, signalsCodexLogin; `hq bot set` refuses the
|
|
217
|
+
// opt-in where it fails, and a pass that meets it reports codex-logged-out.
|
|
218
|
+
return config?.runtime === "codex" && config.signalsRuntime === "bot" ? "codex" : "claude";
|
|
219
|
+
}
|
|
207
220
|
export function readBotConfig(dir) {
|
|
208
221
|
const p = botConfigPath(dir);
|
|
209
222
|
if (!fs.existsSync(p))
|
|
@@ -341,9 +341,27 @@ def classify(out, err, code):
|
|
|
341
341
|
text = ANSI.sub('', (err or '') + '\n' + (out or ''))
|
|
342
342
|
if re.search(r"HQ session has expired|not signed in to HQ|Sign in to HQ first|run .hq login", text, re.I):
|
|
343
343
|
return 'you are signed out of HQ', FIXES['hq_signed_out']
|
|
344
|
-
# Before the plain claude checks: a Codex main bot
|
|
344
|
+
# Before the plain claude checks: a Codex main bot whose signals still run
|
|
345
|
+
# on Claude Code is pointed at running them on its own Codex.
|
|
345
346
|
if re.search(r'claude-logged-out-codex-bot', text, re.I):
|
|
346
|
-
return "your main bot runs on Codex, but signals from hot-channel sync
|
|
347
|
+
return "your main bot runs on Codex, but signals from hot-channel sync run on Claude Code, which is not installed or not signed in on this computer", FIXES['codex_bot_needs_claude']
|
|
348
|
+
# A Codex bot that runs signals on its own Codex (signalsRuntime "bot").
|
|
349
|
+
if re.search(r'codex could not start:.*\bENOENT\b|spawn codex ENOENT', text, re.I):
|
|
350
|
+
return 'Codex is not installed on this computer', FIXES['codex_signed_out']
|
|
351
|
+
if re.search(r'codex-logged-out|codex (reported it )?is not logged in|codex could not start|codex login is not usable', text, re.I):
|
|
352
|
+
return 'Codex is signed out on this computer', FIXES['codex_signed_out']
|
|
353
|
+
codex_timed_out = re.search(r'codex timed out after \d+ ?ms on (\S+)', text, re.I)
|
|
354
|
+
if codex_timed_out or re.search(r'codex-timeout', text, re.I):
|
|
355
|
+
key = codex_timed_out.group(1).rstrip('.,;:)\'"') if codex_timed_out else ''
|
|
356
|
+
if re.match(r'^sources/[A-Za-z0-9._/-]+\.md$', key) and '..' not in key:
|
|
357
|
+
return 'Codex ran out of time on one document', FIXES['claude_timeout_key'].replace('KEY', key)
|
|
358
|
+
return 'Codex ran out of time on one document', FIXES['claude_timeout']
|
|
359
|
+
if re.search(r'codex-usage-limit|codex is out of usage', text, re.I):
|
|
360
|
+
return 'Codex is out of usage on this account', FIXES['codex_usage_limit']
|
|
361
|
+
if re.search(r'codex-bad-output', text, re.I):
|
|
362
|
+
return 'Codex gave replies the signals step could not read', FIXES['claude_bad_output']
|
|
363
|
+
if re.search(r'codex-provider-error', text, re.I):
|
|
364
|
+
return 'Codex reported an error', FIXES['claude_provider_error']
|
|
347
365
|
if re.search(r'claude could not start:.*\bENOENT\b|spawn claude ENOENT', text, re.I):
|
|
348
366
|
return 'Claude Code is not installed on this computer', FIXES['claude_missing']
|
|
349
367
|
if re.search(r'claude-logged-out|claude (reported it )?is not logged in|claude could not start', text, re.I):
|
|
@@ -437,10 +455,17 @@ export function renderFleetHotSignalSyncScript(input) {
|
|
|
437
455
|
? ["sources", "sync", "--trigger", "scheduled", "--company", input.company, "--hq-root", input.hqRoot]
|
|
438
456
|
: ["signals", "run", "--trigger", "job", "--company", input.company, "--hq-root", input.hqRoot, "--report-found"];
|
|
439
457
|
const syncCommand = `hq sources sync --company ${input.company}`;
|
|
458
|
+
const claudeSignInFix = `open HQ, go to Settings → AI tools, and use the Claude Code button there (Connect Claude, or Install Claude if it is not installed yet). Or run \`${signInCommand("claude")}\` in a terminal on this computer.`;
|
|
440
459
|
const fixes = {
|
|
441
460
|
hq_signed_out: "run `hq login`.",
|
|
442
|
-
|
|
443
|
-
|
|
461
|
+
// The desktop app first (Settings → AI tools lists Claude Code with a
|
|
462
|
+
// "Connect Claude" or "Install Claude" button), the terminal as the fallback.
|
|
463
|
+
claude_signed_out: claudeSignInFix,
|
|
464
|
+
// A Fleet bot's signals run on Claude Code (an HQ Fleet Runtime bot cannot lend its Codex login), so the fix is the Claude sign-in.
|
|
465
|
+
codex_bot_needs_claude: claudeSignInFix,
|
|
466
|
+
// Settings → AI tools lists Codex with a "Connect Codex" or "Install Codex" button.
|
|
467
|
+
codex_signed_out: `open HQ, go to Settings → AI tools, and use the Codex button there (Connect Codex, or Install Codex if it is not installed yet). Or run \`${signInCommand("codex")}\` in a terminal on this computer.`,
|
|
468
|
+
codex_usage_limit: `wait for your Codex usage to reset, then run \`hq sources signals --company ${input.company} --since DATE\` to build the missing signals.`,
|
|
444
469
|
claude_missing: `install Claude Code (\`npm install -g @anthropic-ai/claude-code\`), then run \`${signInCommand("claude")}\`.`,
|
|
445
470
|
claude_timeout_key: `run \`hq sources signals --company ${input.company} --key KEY\` to retry that document.`,
|
|
446
471
|
claude_timeout: "the next run retries the document.",
|
|
@@ -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
|
|
@@ -73,6 +73,15 @@ export interface InflightTurn {
|
|
|
73
73
|
/** Older markers: the raw excerpt. Not reported anywhere since 5.345.76. */
|
|
74
74
|
excerpt?: string;
|
|
75
75
|
};
|
|
76
|
+
/**
|
|
77
|
+
* A signals "Try now" run (US-006 AC9): the company it ran for and the
|
|
78
|
+
* job's zone. A run cut off by a restart puts the Try now offer back, so
|
|
79
|
+
* the owner's next "Try now" runs.
|
|
80
|
+
*/
|
|
81
|
+
tryNow?: {
|
|
82
|
+
company: string;
|
|
83
|
+
timeZone?: string;
|
|
84
|
+
};
|
|
76
85
|
rootEventId?: string;
|
|
77
86
|
/** DM message carrying the thinking reaction, so a restart can clear it. */
|
|
78
87
|
reactionEventId?: string;
|