@indigoai-us/hq-cli 5.345.218 → 5.345.220
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 +130 -0
- package/dist/command-catalog.generated.d.ts +94 -1
- package/dist/command-catalog.generated.js +114 -1
- package/dist/commands/agents.d.ts +22 -0
- package/dist/commands/agents.js +92 -1
- package/dist/commands/bot.d.ts +48 -0
- package/dist/commands/bot.js +108 -8
- 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.d.ts +8 -0
- package/dist/commands/core-hook-registration-plan.js +22 -0
- package/dist/commands/core.js +9 -0
- package/dist/commands/daemon.js +21 -2
- package/dist/commands/doctor.js +4 -0
- package/dist/commands/integrations.js +84 -3
- package/dist/commands/lanes-shared.d.ts +2 -0
- package/dist/commands/lanes-watch.js +28 -1
- package/dist/commands/lanes.d.ts +2 -0
- package/dist/commands/lanes.js +99 -9
- 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/reindex.js +6 -0
- package/dist/commands/run.js +55 -45
- package/dist/commands/sources.js +3 -2
- package/dist/index.js +8 -0
- package/dist/lib/anywhere-person-setting.d.ts +2 -2
- package/dist/lib/anywhere-person-setting.js +2 -2
- package/dist/lib/bot/fleet-cron.js +5 -2
- 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/run.d.ts +29 -5
- package/dist/lib/bot/run.js +203 -1
- 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/daemon/anywhere-listener.d.ts +33 -1
- package/dist/lib/daemon/anywhere-listener.js +86 -4
- package/dist/lib/daemon/machine-check-owner.d.ts +21 -0
- package/dist/lib/daemon/machine-check-owner.js +95 -0
- package/dist/lib/daemon/machine-check-registration.d.ts +4 -0
- package/dist/lib/daemon/machine-check-registration.js +64 -0
- package/dist/lib/daemon/machine-checks.d.ts +144 -0
- package/dist/lib/daemon/machine-checks.js +412 -0
- package/dist/lib/daemon/run.js +35 -4
- package/dist/lib/daemon/runtime-notifications.d.ts +7 -0
- package/dist/lib/daemon/runtime-notifications.js +50 -0
- package/dist/lib/daemon/server.d.ts +2 -0
- package/dist/lib/daemon/server.js +6 -0
- package/dist/lib/daemon/state-file.d.ts +12 -1
- package/dist/lib/daemon/state-file.js +23 -1
- package/dist/lib/doctor/checks/fleet-hook-core.d.ts +12 -0
- package/dist/lib/doctor/checks/fleet-hook-core.js +127 -0
- package/dist/lib/doctor/checks/host-core.js +3 -1
- package/dist/lib/doctor/checks/machine-checks.d.ts +16 -0
- package/dist/lib/doctor/checks/machine-checks.js +103 -0
- package/dist/lib/doctor/registry.js +4 -0
- package/dist/lib/doctor/types.d.ts +4 -0
- package/dist/lib/hook-engine/canary-gate.d.ts +64 -0
- package/dist/lib/hook-engine/canary-gate.js +147 -0
- package/dist/lib/hook-engine/coverage.d.ts +3 -1
- package/dist/lib/hook-engine/coverage.js +8 -2
- package/dist/lib/hook-engine/fleet-registration.d.ts +42 -0
- package/dist/lib/hook-engine/fleet-registration.js +168 -0
- package/dist/lib/hook-engine/reconcile.js +3 -2
- package/dist/lib/hook-engine/registration-identity.d.ts +33 -0
- package/dist/lib/hook-engine/registration-identity.js +97 -0
- package/dist/lib/hook-engine/registration.d.ts +1 -30
- package/dist/lib/hook-engine/registration.js +1 -88
- package/dist/lib/hook-engine/resolve.d.ts +2 -0
- package/dist/lib/hook-engine/resolve.js +7 -3
- package/dist/lib/hot-channels/alert.d.ts +10 -1
- package/dist/lib/hot-channels/alert.js +34 -7
- 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 +17 -0
- package/dist/lib/hot-channels/signals-pass.js +31 -3
- package/dist/lib/lanes/canonical-host.d.ts +8 -1
- package/dist/lib/lanes/canonical-host.js +9 -3
- package/dist/lib/lanes/machine-identity.d.ts +15 -0
- package/dist/lib/lanes/machine-identity.js +26 -0
- package/dist/lib/lanes/spawn.js +17 -3
- package/dist/lib/search-index/index.js +11 -1
- package/dist/lib/signals/engine.d.ts +1 -0
- package/dist/lib/signals/engine.js +7 -0
- package/dist/lib/signals/reply.d.ts +48 -0
- package/dist/lib/signals/reply.js +72 -11
- package/dist/lib/signals/steps/adapters.js +6 -0
- package/dist/lib/signals/steps/extract.d.ts +50 -3
- package/dist/lib/signals/steps/extract.js +100 -17
- package/dist/lib/signals/steps/types.d.ts +19 -0
- package/dist/lib/sync-core/engine-home.d.ts +6 -1
- package/dist/lib/sync-core/engine-home.js +13 -3
- 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/run/schema-env-overrides.d.ts +24 -0
- package/dist/run/schema-env-overrides.js +72 -0
- package/dist/utils/core-next-flag.d.ts +4 -0
- package/dist/utils/core-next-flag.js +22 -0
- package/dist/utils/core-next-kill.d.ts +16 -0
- package/dist/utils/core-next-kill.js +35 -0
- package/dist/utils/host-registration.d.ts +33 -23
- package/dist/utils/host-registration.js +90 -66
- package/package.json +14 -10
- package/scripts/check-function-manifest.mjs +5 -4
- 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
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/** Offline, default-off registration gate. No network work on the hook path. */
|
|
2
|
-
import { realpathSync } from 'node:fs';
|
|
3
2
|
import { readFlagSnapshotFile, readPersonFlagSnapshotFile } from '../flag-snapshot-file.js';
|
|
4
3
|
import { resolveProcessFlagCompanyContext } from '../process-flag-company-context.js';
|
|
5
4
|
import { installHookEngine } from './resolve.js';
|
|
@@ -15,91 +14,5 @@ export function registrationEngine(home, env = process.env) {
|
|
|
15
14
|
return null;
|
|
16
15
|
return installHookEngine({ home });
|
|
17
16
|
}
|
|
18
|
-
|
|
19
|
-
* Root spelling passed to the launcher. A trailing separator is dropped because
|
|
20
|
-
* Windows PowerShell 5.1 re-quotes a native argument containing a space as
|
|
21
|
-
* "...", and a final backslash would then escape the closing quote.
|
|
22
|
-
*/
|
|
23
|
-
export function launcherRoot(root) {
|
|
24
|
-
const trimmed = root.replace(/[\\/]+$/, '');
|
|
25
|
-
return trimmed === '' || /^[A-Za-z]:$/.test(trimmed) ? root : trimmed;
|
|
26
|
-
}
|
|
27
|
-
export function engineArgs(root, event, runtime, global = false) {
|
|
28
|
-
return [event, '--hq-root', launcherRoot(root), '--runtime', runtime, ...(global && runtime === 'claude' ? ['--global'] : [])];
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* The `--hq-root` value of an HQ entry: the argument after it in exec form,
|
|
32
|
-
* or the single-quoted word after it in a POSIX or PowerShell command string.
|
|
33
|
-
*/
|
|
34
|
-
function hqRootArgument(entry) {
|
|
35
|
-
if (Array.isArray(entry.args)) {
|
|
36
|
-
const i = entry.args.indexOf('--hq-root');
|
|
37
|
-
const value = i >= 0 ? entry.args[i + 1] : undefined;
|
|
38
|
-
return typeof value === 'string' ? value : undefined;
|
|
39
|
-
}
|
|
40
|
-
if (typeof entry.command !== 'string')
|
|
41
|
-
return undefined;
|
|
42
|
-
// `& '...'` is the PowerShell form (quote doubled); anything else is POSIX (`'\''`).
|
|
43
|
-
if (entry.command.startsWith('& ')) {
|
|
44
|
-
const windows = entry.command.match(/'--hq-root' '((?:[^']|'')*)'/);
|
|
45
|
-
return windows ? windows[1].replace(/''/g, "'") : undefined;
|
|
46
|
-
}
|
|
47
|
-
const posix = entry.command.match(/'--hq-root' '((?:[^']|'\\'')*)'/);
|
|
48
|
-
return posix ? posix[1].replace(/'\\''/g, "'") : undefined;
|
|
49
|
-
}
|
|
50
|
-
function realpathOrNull(p) {
|
|
51
|
-
try {
|
|
52
|
-
return realpathSync(p);
|
|
53
|
-
}
|
|
54
|
-
catch {
|
|
55
|
-
// A path that does not exist names no folder, so it matches no root.
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* True when an entry's `--hq-root` names this HQ root: the same spelling
|
|
61
|
-
* (trailing separators aside), or another spelling of the same folder
|
|
62
|
-
* (`/private/tmp/x` and `/tmp/x`, a symlinked root and its target), found
|
|
63
|
-
* by resolving both. An entry for any other folder is not this root's.
|
|
64
|
-
*/
|
|
65
|
-
export function sameHqRoot(value, root) {
|
|
66
|
-
if (value === undefined)
|
|
67
|
-
return false;
|
|
68
|
-
if (value === launcherRoot(root) || launcherRoot(value) === launcherRoot(root))
|
|
69
|
-
return true;
|
|
70
|
-
const a = realpathOrNull(value);
|
|
71
|
-
return a !== null && a === realpathOrNull(root);
|
|
72
|
-
}
|
|
73
|
-
/** Recognize only our pinned executable with this root's argument. */
|
|
74
|
-
export function isNativeEntry(entry, root) {
|
|
75
|
-
if (typeof entry.command !== 'string')
|
|
76
|
-
return false;
|
|
77
|
-
const pinned = /[\\/]\.hq[\\/]bin[\\/]hq-hook[\\/]\d+\.\d+\.\d+[^\\/]*[\\/]/;
|
|
78
|
-
if (!pinned.test(entry.command))
|
|
79
|
-
return false;
|
|
80
|
-
return sameHqRoot(hqRootArgument(entry), root);
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* A registration that calls the new core's entry point, `hq-hook run --host
|
|
84
|
-
* <host> <Event> --hq-root <root>`, through the release-stable link
|
|
85
|
-
* (hq-core-rust US-017). Recognized by the stable path, the `run --host`
|
|
86
|
-
* words and a root argument that names this root ([`sameHqRoot`]), in exec
|
|
87
|
-
* form (`args`) or as a command string (Codex, Grok).
|
|
88
|
-
*/
|
|
89
|
-
export const CORE_NEXT_LINK = /[\\/]\.hq[\\/]bin[\\/]hq-hook[\\/]stable[\\/]/;
|
|
90
|
-
export function isCoreNextEntry(entry, root) {
|
|
91
|
-
if (typeof entry.command !== 'string' || !CORE_NEXT_LINK.test(entry.command))
|
|
92
|
-
return false;
|
|
93
|
-
const runHost = Array.isArray(entry.args)
|
|
94
|
-
? entry.args[0] === 'run' && entry.args[1] === '--host'
|
|
95
|
-
: entry.command.includes(`${quotePosix('run')} ${quotePosix('--host')}`);
|
|
96
|
-
return runHost && sameHqRoot(hqRootArgument(entry), root);
|
|
97
|
-
}
|
|
98
|
-
export function quotePosix(value) { return "'" + value.replace(/'/g, "'\\''") + "'"; }
|
|
99
|
-
export function quoteWindows(value) {
|
|
100
|
-
// Codex 0.162.1 uses its Windows PowerShell runtime shell for hooks.
|
|
101
|
-
// Single-quoted literals prevent variable, subexpression and wildcard expansion.
|
|
102
|
-
// PowerShell also closes them on the typographic quotes U+2018-U+201B.
|
|
103
|
-
return "'" + value.replace(/['‘’‚‛]/g, '$&$&') + "'";
|
|
104
|
-
}
|
|
17
|
+
export { launcherRoot, engineArgs, isNativeEntry, isCoreNextEntry, sameHqRoot, CORE_NEXT_LINK, quotePosix, quoteWindows } from './registration-identity.js';
|
|
105
18
|
//# sourceMappingURL=registration.js.map
|
|
@@ -20,6 +20,8 @@ export interface EnginePackage {
|
|
|
20
20
|
export declare function hookEngineRequired(): boolean;
|
|
21
21
|
/** Check the whole signed bundle, including its resource seal and stapled ticket. */
|
|
22
22
|
export declare function pinnedHookEngineMatches(engine: EnginePackage): boolean;
|
|
23
|
+
/** The pinned bundle must be the package this CLI installed. */
|
|
24
|
+
export declare function assertPinnedHookEngineMatches(engine: EnginePackage): void;
|
|
23
25
|
/** Offline lookup. Never silently use an engine from a different CLI version. */
|
|
24
26
|
export declare function findHookEngine(options?: EngineOptions): EnginePackage | null;
|
|
25
27
|
/** Never truncate or replace a running Windows executable. */
|
|
@@ -38,6 +38,12 @@ export function pinnedHookEngineMatches(engine) {
|
|
|
38
38
|
}
|
|
39
39
|
return equal(engine.sourceDirectory, engine.pinnedDirectory);
|
|
40
40
|
}
|
|
41
|
+
/** The pinned bundle must be the package this CLI installed. */
|
|
42
|
+
export function assertPinnedHookEngineMatches(engine) {
|
|
43
|
+
if (!pinnedHookEngineMatches(engine)) {
|
|
44
|
+
throw new Error(`Hook engine ${engine.version} differs from its pinned copy; close HQ sessions and repair with: ${HOOK_ENGINE_REPAIR_PIN}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
41
47
|
/** Offline lookup. Never silently use an engine from a different CLI version. */
|
|
42
48
|
export function findHookEngine(options = {}) {
|
|
43
49
|
const platform = options.platform ?? process.platform;
|
|
@@ -105,9 +111,7 @@ export function installHookEngine(options = {}) {
|
|
|
105
111
|
rmSync(stage, { recursive: true, force: true });
|
|
106
112
|
}
|
|
107
113
|
}
|
|
108
|
-
|
|
109
|
-
throw new Error(`Hook engine ${engine.version} differs from its pinned copy; close HQ sessions and repair with: ${HOOK_ENGINE_REPAIR_PIN}`);
|
|
110
|
-
}
|
|
114
|
+
assertPinnedHookEngineMatches(engine);
|
|
111
115
|
writeHookEnginePointer(engine.pinned, options);
|
|
112
116
|
return engine.pinned;
|
|
113
117
|
}
|
|
@@ -15,6 +15,10 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import type { RunLedgerEntry } from "./ledger.js";
|
|
17
17
|
import type { OnDemandSyncDeps } from "./run.js";
|
|
18
|
+
/** Pass failures that mean Claude Code is signed out (or missing) on this computer. */
|
|
19
|
+
export declare const SIGNED_OUT_SIGNALS_CODES: ReadonlySet<string>;
|
|
20
|
+
/** A failed ledger line whose pass found Claude Code signed out. */
|
|
21
|
+
export declare function isSignedOutSignalsFailure(entry: Pick<RunLedgerEntry, "status" | "error">): boolean;
|
|
18
22
|
export declare const SIGNALS_HEALTH_RULE: string;
|
|
19
23
|
/** One alert per adapter and connection per hour. */
|
|
20
24
|
export declare const SIGNALS_ALERT_DEDUPE_MS: number;
|
|
@@ -25,11 +29,16 @@ export declare const SIGNALS_ALERT_CHANNEL_FIELD = "signals_alert_channel";
|
|
|
25
29
|
export declare const SLACK_POST_TOOL = "slack.messages.post";
|
|
26
30
|
/**
|
|
27
31
|
* Ledger lines that landed sources and either generated no signals, whatever
|
|
28
|
-
* their status, or failed partway after generating some.
|
|
32
|
+
* their status, or failed partway after generating some. A line whose pass
|
|
33
|
+
* failed because Claude Code is signed out counts too when it landed nothing:
|
|
34
|
+
* the pass only checks the login when queued documents are waiting, so that
|
|
35
|
+
* run had backlog it could not process, and the owner must hear about it.
|
|
29
36
|
*/
|
|
30
37
|
export declare function findSignalsFailures(entries: readonly RunLedgerEntry[]): RunLedgerEntry[];
|
|
31
38
|
/** The dedupe key: one adapter on one connection. */
|
|
32
39
|
export declare function signalsAlertKey(entry: Pick<RunLedgerEntry, "adapter" | "connectionId">): string;
|
|
40
|
+
/** The dedupe key shared by every connection of one adapter that failed signed out. */
|
|
41
|
+
export declare function signedOutAlertKey(entry: Pick<RunLedgerEntry, "adapter">): string;
|
|
33
42
|
/** The first words of every signals-failure alert; the Fleet job script finds the alert by them. */
|
|
34
43
|
export declare const SIGNALS_FAILURE_PREFIX = "Signals failure for ";
|
|
35
44
|
export declare function formatSignalsFailureAlert(entry: RunLedgerEntry, options?: {
|
|
@@ -17,8 +17,15 @@ import * as fs from "node:fs";
|
|
|
17
17
|
import * as path from "node:path";
|
|
18
18
|
import { assertNotIntegrationSecretsPath, personDirName } from "./cursors.js";
|
|
19
19
|
import { writeFileAtomic } from "./landing.js";
|
|
20
|
-
import { CODEX_BOT_NEEDS_CLAUDE_TEXT } from "./signals-pass.js";
|
|
20
|
+
import { CLAUDE_SIGNED_OUT_TEXT, CODEX_BOT_NEEDS_CLAUDE_TEXT } from "./signals-pass.js";
|
|
21
21
|
const CODEX_BOT_NEEDS_CLAUDE_CODE = "claude-logged-out-codex-bot";
|
|
22
|
+
const CLAUDE_SIGNED_OUT_CODE = "claude-logged-out";
|
|
23
|
+
/** Pass failures that mean Claude Code is signed out (or missing) on this computer. */
|
|
24
|
+
export const SIGNED_OUT_SIGNALS_CODES = new Set([CLAUDE_SIGNED_OUT_CODE, CODEX_BOT_NEEDS_CLAUDE_CODE]);
|
|
25
|
+
/** A failed ledger line whose pass found Claude Code signed out. */
|
|
26
|
+
export function isSignedOutSignalsFailure(entry) {
|
|
27
|
+
return entry.status === "failed" && entry.error !== null && SIGNED_OUT_SIGNALS_CODES.has(entry.error);
|
|
28
|
+
}
|
|
22
29
|
export const SIGNALS_HEALTH_RULE = 'Owner rule: "sync and build feels wrong. we should be logging sources and signals generated." ' +
|
|
23
30
|
"A run that lands sources and generates no signals is a failure.";
|
|
24
31
|
/** One alert per adapter and connection per hour. */
|
|
@@ -30,15 +37,22 @@ export const SIGNALS_ALERT_CHANNEL_FIELD = "signals_alert_channel";
|
|
|
30
37
|
export const SLACK_POST_TOOL = "slack.messages.post";
|
|
31
38
|
/**
|
|
32
39
|
* Ledger lines that landed sources and either generated no signals, whatever
|
|
33
|
-
* their status, or failed partway after generating some.
|
|
40
|
+
* their status, or failed partway after generating some. A line whose pass
|
|
41
|
+
* failed because Claude Code is signed out counts too when it landed nothing:
|
|
42
|
+
* the pass only checks the login when queued documents are waiting, so that
|
|
43
|
+
* run had backlog it could not process, and the owner must hear about it.
|
|
34
44
|
*/
|
|
35
45
|
export function findSignalsFailures(entries) {
|
|
36
|
-
return entries.filter((e) => e.sourcesLanded > 0 && (e.signalsGenerated === 0 || e.status === "failed"));
|
|
46
|
+
return entries.filter((e) => (e.sourcesLanded > 0 && (e.signalsGenerated === 0 || e.status === "failed")) || isSignedOutSignalsFailure(e));
|
|
37
47
|
}
|
|
38
48
|
/** The dedupe key: one adapter on one connection. */
|
|
39
49
|
export function signalsAlertKey(entry) {
|
|
40
50
|
return `${entry.adapter}:${entry.connectionId ?? "-"}`;
|
|
41
51
|
}
|
|
52
|
+
/** The dedupe key shared by every connection of one adapter that failed signed out. */
|
|
53
|
+
export function signedOutAlertKey(entry) {
|
|
54
|
+
return `${entry.adapter}:claude-signed-out`;
|
|
55
|
+
}
|
|
42
56
|
/** The first words of every signals-failure alert; the Fleet job script finds the alert by them. */
|
|
43
57
|
export const SIGNALS_FAILURE_PREFIX = "Signals failure for ";
|
|
44
58
|
export function formatSignalsFailureAlert(entry, options = {}) {
|
|
@@ -54,8 +68,11 @@ export function formatSignalsFailureAlert(entry, options = {}) {
|
|
|
54
68
|
// A Codex bot cannot fix this by signing in to its own tool; say what works.
|
|
55
69
|
if (entry.error === CODEX_BOT_NEEDS_CLAUDE_CODE)
|
|
56
70
|
lines.push(CODEX_BOT_NEEDS_CLAUDE_TEXT);
|
|
57
|
-
|
|
58
|
-
|
|
71
|
+
else if (entry.error === CLAUDE_SIGNED_OUT_CODE)
|
|
72
|
+
lines.push(CLAUDE_SIGNED_OUT_TEXT);
|
|
73
|
+
// The rule is about a run that landed sources and made no signals; a
|
|
74
|
+
// partial pass, or a backlog-only run, fails on its error alone.
|
|
75
|
+
if (entry.signalsGenerated === 0 && entry.sourcesLanded > 0)
|
|
59
76
|
lines.push(SIGNALS_HEALTH_RULE);
|
|
60
77
|
return lines.join("\n");
|
|
61
78
|
}
|
|
@@ -98,17 +115,25 @@ export async function raiseSignalsFailureAlerts(input) {
|
|
|
98
115
|
const state = await readAlertState(file);
|
|
99
116
|
const seen = new Set();
|
|
100
117
|
let changed = false;
|
|
118
|
+
const recent = (k, at) => {
|
|
119
|
+
const last = state.lastAlertAt[k] ? Date.parse(state.lastAlertAt[k]) : Number.NaN;
|
|
120
|
+
return !Number.isNaN(last) && at.getTime() - last < SIGNALS_ALERT_DEDUPE_MS;
|
|
121
|
+
};
|
|
101
122
|
for (const entry of failures) {
|
|
102
123
|
const key = signalsAlertKey(entry);
|
|
103
124
|
if (seen.has(key))
|
|
104
125
|
continue;
|
|
105
126
|
seen.add(key);
|
|
106
127
|
const at = input.now();
|
|
107
|
-
|
|
108
|
-
|
|
128
|
+
// One sign-out fails every connection of an adapter that has backlog the
|
|
129
|
+
// same way: the adapter gets one DM per hour, not one per connection.
|
|
130
|
+
const signedOutKey = isSignedOutSignalsFailure(entry) ? signedOutAlertKey(entry) : null;
|
|
131
|
+
if (recent(key, at) || (signedOutKey !== null && (seen.has(signedOutKey) || recent(signedOutKey, at)))) {
|
|
109
132
|
result.suppressed.push(key);
|
|
110
133
|
continue;
|
|
111
134
|
}
|
|
135
|
+
if (signedOutKey !== null)
|
|
136
|
+
seen.add(signedOutKey);
|
|
112
137
|
const text = formatSignalsFailureAlert(entry, input.personName ? { personName: input.personName } : {});
|
|
113
138
|
try {
|
|
114
139
|
await input.sendOwnerDm(text);
|
|
@@ -119,6 +144,8 @@ export async function raiseSignalsFailureAlerts(input) {
|
|
|
119
144
|
continue;
|
|
120
145
|
}
|
|
121
146
|
state.lastAlertAt[key] = at.toISOString();
|
|
147
|
+
if (signedOutKey !== null)
|
|
148
|
+
state.lastAlertAt[signedOutKey] = at.toISOString();
|
|
122
149
|
changed = true;
|
|
123
150
|
result.sent.push(key);
|
|
124
151
|
if (input.postCompanyChannel) {
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Claude Code sign-in that the signals pass needs, as last seen by a pass.
|
|
3
|
+
*
|
|
4
|
+
* The signals pass always runs Claude Code, whatever the bot's own runtime is
|
|
5
|
+
* (signals-pass.ts), so a Codex bot can be signed in to its own tool while
|
|
6
|
+
* signals cannot run. Each pass reports what it saw through `onClaudeLogin`,
|
|
7
|
+
* and this module keeps one machine-local record of it
|
|
8
|
+
* (`{botsRoot}/signals-claude-login.json`; the login belongs to this
|
|
9
|
+
* computer, so the record never goes in a company vault). `hq bot status`
|
|
10
|
+
* reads it to show that login next to the bot's own runtime login.
|
|
11
|
+
*/
|
|
12
|
+
export declare const SIGNALS_CLAUDE_LOGIN_FILE = "signals-claude-login.json";
|
|
13
|
+
/** Who saw the state. Only the signals pass records it today. */
|
|
14
|
+
export type SignalsClaudeLoginSource = "signals-pass";
|
|
15
|
+
export interface SignalsClaudeLogin {
|
|
16
|
+
v: 1;
|
|
17
|
+
signedIn: boolean;
|
|
18
|
+
checkedAt: string;
|
|
19
|
+
source: SignalsClaudeLoginSource;
|
|
20
|
+
/** When the login was first seen signed out, while it still is. */
|
|
21
|
+
signedOutSince?: string;
|
|
22
|
+
}
|
|
23
|
+
export declare function signalsClaudeLoginPath(root?: string): string;
|
|
24
|
+
/** The last recorded state, or null when nothing was recorded or the file is unreadable. */
|
|
25
|
+
export declare function readSignalsClaudeLogin(file?: string): SignalsClaudeLogin | null;
|
|
26
|
+
/**
|
|
27
|
+
* Record what a pass just saw. Never throws: the record is a report, and a
|
|
28
|
+
* failed write must not fail a signals run.
|
|
29
|
+
*/
|
|
30
|
+
export declare function recordSignalsClaudeLogin(signedIn: boolean, now?: () => Date, file?: string): void;
|
|
31
|
+
/** One live `claude auth status` answer for `hq bot status`. */
|
|
32
|
+
export interface ClaudeLoginNow {
|
|
33
|
+
/** null when the check could not tell (`error` says why). */
|
|
34
|
+
signedIn: boolean | null;
|
|
35
|
+
checkedAt: string;
|
|
36
|
+
error: string | null;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Ask `claude auth status` now, the way the signals pass reads it: a CLI that
|
|
40
|
+
* cannot start (not installed) or exits non-zero is signed out,
|
|
41
|
+
* `loggedIn: false` is signed out, any other exit 0 is signed in. It reads
|
|
42
|
+
* local credentials only: no network and no model call. A timeout or a
|
|
43
|
+
* thrown error is `signedIn: null` with the reason. Never throws.
|
|
44
|
+
*/
|
|
45
|
+
export declare function checkClaudeLoginNow(options?: {
|
|
46
|
+
claudeBin?: string;
|
|
47
|
+
env?: NodeJS.ProcessEnv;
|
|
48
|
+
timeoutMs?: number;
|
|
49
|
+
now?: () => Date;
|
|
50
|
+
}): Promise<ClaudeLoginNow>;
|
|
51
|
+
/** The `onClaudeLogin` reporter `hq sources sync` and `hq bot` give the signals pass. */
|
|
52
|
+
export declare function recordSignalsPassClaudeLogin(signedIn: boolean): void;
|
|
53
|
+
//# sourceMappingURL=signals-claude-login.d.ts.map
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Claude Code sign-in that the signals pass needs, as last seen by a pass.
|
|
3
|
+
*
|
|
4
|
+
* The signals pass always runs Claude Code, whatever the bot's own runtime is
|
|
5
|
+
* (signals-pass.ts), so a Codex bot can be signed in to its own tool while
|
|
6
|
+
* signals cannot run. Each pass reports what it saw through `onClaudeLogin`,
|
|
7
|
+
* and this module keeps one machine-local record of it
|
|
8
|
+
* (`{botsRoot}/signals-claude-login.json`; the login belongs to this
|
|
9
|
+
* computer, so the record never goes in a company vault). `hq bot status`
|
|
10
|
+
* reads it to show that login next to the bot's own runtime login.
|
|
11
|
+
*/
|
|
12
|
+
import * as fs from "node:fs";
|
|
13
|
+
import * as os from "node:os";
|
|
14
|
+
import * as path from "node:path";
|
|
15
|
+
import { botsRoot } from "../bot/paths.js";
|
|
16
|
+
import { AUTH_PREFLIGHT_TIMEOUT_MS, runBounded } from "./signals-pass.js";
|
|
17
|
+
export const SIGNALS_CLAUDE_LOGIN_FILE = "signals-claude-login.json";
|
|
18
|
+
export function signalsClaudeLoginPath(root = botsRoot()) {
|
|
19
|
+
return path.join(root, SIGNALS_CLAUDE_LOGIN_FILE);
|
|
20
|
+
}
|
|
21
|
+
/** The last recorded state, or null when nothing was recorded or the file is unreadable. */
|
|
22
|
+
export function readSignalsClaudeLogin(file = signalsClaudeLoginPath()) {
|
|
23
|
+
try {
|
|
24
|
+
const parsed = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
25
|
+
if (parsed?.v !== 1 || typeof parsed.signedIn !== "boolean" || typeof parsed.checkedAt !== "string")
|
|
26
|
+
return null;
|
|
27
|
+
if (!Number.isFinite(Date.parse(parsed.checkedAt)))
|
|
28
|
+
return null;
|
|
29
|
+
return {
|
|
30
|
+
v: 1,
|
|
31
|
+
signedIn: parsed.signedIn,
|
|
32
|
+
checkedAt: parsed.checkedAt,
|
|
33
|
+
source: "signals-pass",
|
|
34
|
+
...(!parsed.signedIn && typeof parsed.signedOutSince === "string" ? { signedOutSince: parsed.signedOutSince } : {}),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
// Missing or unreadable: nothing recorded yet.
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Record what a pass just saw. Never throws: the record is a report, and a
|
|
44
|
+
* failed write must not fail a signals run.
|
|
45
|
+
*/
|
|
46
|
+
export function recordSignalsClaudeLogin(signedIn, now = () => new Date(), file = signalsClaudeLoginPath()) {
|
|
47
|
+
try {
|
|
48
|
+
const at = now().toISOString();
|
|
49
|
+
const previous = readSignalsClaudeLogin(file);
|
|
50
|
+
const signedOutSince = signedIn ? undefined : previous && !previous.signedIn ? (previous.signedOutSince ?? previous.checkedAt) : at;
|
|
51
|
+
const record = { v: 1, signedIn, checkedAt: at, source: "signals-pass", ...(signedOutSince ? { signedOutSince } : {}) };
|
|
52
|
+
fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
53
|
+
const tmp = `${file}.${process.pid}.${Date.now()}.tmp`;
|
|
54
|
+
fs.writeFileSync(tmp, `${JSON.stringify(record, null, 2)}\n`, { mode: 0o600 });
|
|
55
|
+
fs.renameSync(tmp, file);
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
// A report only; the next pass writes it again.
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Ask `claude auth status` now, the way the signals pass reads it: a CLI that
|
|
63
|
+
* cannot start (not installed) or exits non-zero is signed out,
|
|
64
|
+
* `loggedIn: false` is signed out, any other exit 0 is signed in. It reads
|
|
65
|
+
* local credentials only: no network and no model call. A timeout or a
|
|
66
|
+
* thrown error is `signedIn: null` with the reason. Never throws.
|
|
67
|
+
*/
|
|
68
|
+
export async function checkClaudeLoginNow(options = {}) {
|
|
69
|
+
const checkedAt = (options.now ?? (() => new Date()))().toISOString();
|
|
70
|
+
try {
|
|
71
|
+
const run = await runBounded(options.claudeBin ?? "claude", ["auth", "status"], {
|
|
72
|
+
timeoutMs: options.timeoutMs ?? AUTH_PREFLIGHT_TIMEOUT_MS,
|
|
73
|
+
cwd: os.tmpdir(),
|
|
74
|
+
env: options.env ?? process.env,
|
|
75
|
+
});
|
|
76
|
+
if (run.timedOut)
|
|
77
|
+
return { signedIn: null, checkedAt, error: "claude auth status timed out" };
|
|
78
|
+
if (run.spawnError !== undefined || run.code !== 0)
|
|
79
|
+
return { signedIn: false, checkedAt, error: null };
|
|
80
|
+
try {
|
|
81
|
+
return { signedIn: JSON.parse(run.stdout).loggedIn !== false, checkedAt, error: null };
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
// A plain-text status with exit 0 means signed in, as in the pass.
|
|
85
|
+
return { signedIn: true, checkedAt, error: null };
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
catch (err) {
|
|
89
|
+
return { signedIn: null, checkedAt, error: err instanceof Error ? err.message : String(err) };
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/** The `onClaudeLogin` reporter `hq sources sync` and `hq bot` give the signals pass. */
|
|
93
|
+
export function recordSignalsPassClaudeLogin(signedIn) {
|
|
94
|
+
recordSignalsClaudeLogin(signedIn);
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=signals-claude-login.js.map
|
|
@@ -71,12 +71,22 @@ export declare class SignalsPassError extends Error {
|
|
|
71
71
|
noRetry: boolean;
|
|
72
72
|
constructor(code: SignalsPassErrorCode, message: string);
|
|
73
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* How to sign Claude Code in for signals. The desktop app comes first: its
|
|
76
|
+
* Settings → AI tools pane lists Claude Code with one button: "Connect
|
|
77
|
+
* Claude" when the CLI is installed, "Install Claude" when it is not
|
|
78
|
+
* (hq-desktop-app-src packages/ui/src/settings/AgentsSettingsPane.svelte).
|
|
79
|
+
* The terminal command is the fallback.
|
|
80
|
+
*/
|
|
81
|
+
export declare const CLAUDE_SIGN_IN_STEPS: string;
|
|
74
82
|
/**
|
|
75
83
|
* What the owner of a Codex main bot is told when this pass finds claude
|
|
76
84
|
* missing or signed out. The pass always runs Claude Code, whatever the main
|
|
77
85
|
* bot runs.
|
|
78
86
|
*/
|
|
79
87
|
export declare const CODEX_BOT_NEEDS_CLAUDE_TEXT: string;
|
|
88
|
+
/** What the owner is told when this pass finds claude signed out on any other bot. */
|
|
89
|
+
export declare const CLAUDE_SIGNED_OUT_TEXT: string;
|
|
80
90
|
/** Signal types the pass accepts; the same type folders existing signals use. */
|
|
81
91
|
export declare const SIGNAL_TYPES: readonly ["action_item", "commitment", "decision", "key_point", "participant_contribution", "question", "risk", "summary"];
|
|
82
92
|
export type SignalType = (typeof SIGNAL_TYPES)[number];
|
|
@@ -151,6 +161,13 @@ export interface ClaudeSignalsPassOptions {
|
|
|
151
161
|
* CODEX_BOT_NEEDS_CLAUDE_TEXT. Unset: the failure is reported as is.
|
|
152
162
|
*/
|
|
153
163
|
botRuntime?: () => BotRuntimeId | null;
|
|
164
|
+
/**
|
|
165
|
+
* Told what the pass saw of the Claude login: true after a preflight that
|
|
166
|
+
* passed, false when the pass failed signed out. Unset: nothing is recorded.
|
|
167
|
+
* `hq bot` and `hq sources sync` pass `recordSignalsPassClaudeLogin` here
|
|
168
|
+
* (signals-claude-login.ts), which `hq bot status` reads. Must not throw.
|
|
169
|
+
*/
|
|
170
|
+
onClaudeLogin?: (signedIn: boolean) => void;
|
|
154
171
|
}
|
|
155
172
|
/** Why the pass sent claude the pointer alone. */
|
|
156
173
|
export type PayloadFallbackReason = "payload-out-of-bounds" | "payload-missing" | "payload-unreadable";
|
|
@@ -28,13 +28,27 @@ export class SignalsPassError extends Error {
|
|
|
28
28
|
this.code = code;
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* How to sign Claude Code in for signals. The desktop app comes first: its
|
|
33
|
+
* Settings → AI tools pane lists Claude Code with one button: "Connect
|
|
34
|
+
* Claude" when the CLI is installed, "Install Claude" when it is not
|
|
35
|
+
* (hq-desktop-app-src packages/ui/src/settings/AgentsSettingsPane.svelte).
|
|
36
|
+
* The terminal command is the fallback.
|
|
37
|
+
*/
|
|
38
|
+
export const CLAUDE_SIGN_IN_STEPS = "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). " +
|
|
39
|
+
"Or run `claude auth login` in a terminal on this computer.";
|
|
40
|
+
/** Documents the pass could not run stay queued; said in every signed-out message. */
|
|
41
|
+
const QUEUED_DOCS_TEXT = "The documents waiting for signals stay queued and run once Claude Code is signed in.";
|
|
31
42
|
/**
|
|
32
43
|
* What the owner of a Codex main bot is told when this pass finds claude
|
|
33
44
|
* missing or signed out. The pass always runs Claude Code, whatever the main
|
|
34
45
|
* bot runs.
|
|
35
46
|
*/
|
|
36
47
|
export const CODEX_BOT_NEEDS_CLAUDE_TEXT = "Your main bot runs on Codex, but signals from hot-channel sync need Claude Code, which is not installed or not signed in on this computer. " +
|
|
37
|
-
|
|
48
|
+
`${CLAUDE_SIGN_IN_STEPS} ${QUEUED_DOCS_TEXT}`;
|
|
49
|
+
/** What the owner is told when this pass finds claude signed out on any other bot. */
|
|
50
|
+
export const CLAUDE_SIGNED_OUT_TEXT = "Signals from hot-channel sync need Claude Code, which is not signed in on this computer. " +
|
|
51
|
+
`${CLAUDE_SIGN_IN_STEPS} ${QUEUED_DOCS_TEXT}`;
|
|
38
52
|
/** Signal types the pass accepts; the same type folders existing signals use. */
|
|
39
53
|
export const SIGNAL_TYPES = [
|
|
40
54
|
"action_item",
|
|
@@ -574,7 +588,19 @@ export function createClaudeSignalsPass(options) {
|
|
|
574
588
|
return false;
|
|
575
589
|
}
|
|
576
590
|
};
|
|
591
|
+
const tellLogin = (signedIn) => {
|
|
592
|
+
try {
|
|
593
|
+
options.onClaudeLogin?.(signedIn);
|
|
594
|
+
}
|
|
595
|
+
catch {
|
|
596
|
+
// A report only; it never changes the pass's outcome.
|
|
597
|
+
}
|
|
598
|
+
};
|
|
577
599
|
const checkLogin = async () => {
|
|
600
|
+
await checkLoginOnce();
|
|
601
|
+
tellLogin(true);
|
|
602
|
+
};
|
|
603
|
+
const checkLoginOnce = async () => {
|
|
578
604
|
const run = await runBounded(claude, ["auth", "status"], { timeoutMs: authTimeoutMs, cwd: claudeCwd, env });
|
|
579
605
|
if (run.timedOut)
|
|
580
606
|
throw new SignalsPassError("claude-timeout", "claude auth status timed out");
|
|
@@ -866,8 +892,10 @@ export function createClaudeSignalsPass(options) {
|
|
|
866
892
|
}
|
|
867
893
|
catch (caught) {
|
|
868
894
|
let err = caught;
|
|
869
|
-
if (err instanceof SignalsPassError && err.code === "claude-logged-out"
|
|
870
|
-
|
|
895
|
+
if (err instanceof SignalsPassError && err.code === "claude-logged-out") {
|
|
896
|
+
tellLogin(false);
|
|
897
|
+
if (codexBot())
|
|
898
|
+
err = new SignalsPassError("claude-logged-out-codex-bot", CODEX_BOT_NEEDS_CLAUDE_TEXT);
|
|
871
899
|
}
|
|
872
900
|
if (err instanceof SignalsPassError) {
|
|
873
901
|
err.written = progress.written;
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
* uses: the Outpost marker (`/etc/outpost/outpost-id`) on an Outpost, and the
|
|
6
6
|
* stable id in `~/.hq/lane-host.json` elsewhere. This module only gathers the
|
|
7
7
|
* aliases, from values that are already on disk. It makes no network call, so
|
|
8
|
-
* the
|
|
8
|
+
* the registry instance name is not listed, and the EC2 instance id is listed
|
|
9
|
+
* only when the caller read it from a local file.
|
|
9
10
|
*
|
|
10
11
|
* The list is for printing and for joining records. It includes ids taken from
|
|
11
12
|
* lane records, so it must not be passed back into the local matcher to decide
|
|
@@ -29,6 +30,12 @@ export declare function resolveCanonicalHost(input: {
|
|
|
29
30
|
identityAliases?: readonly string[];
|
|
30
31
|
/** Stable local id from `~/.hq/lane-host.json` when `host` is an Outpost. */
|
|
31
32
|
localIdentityId?: string;
|
|
33
|
+
/**
|
|
34
|
+
* This machine's EC2 instance id, read from disk (`readInstanceIdFromDisk`).
|
|
35
|
+
* Used only when `host` is an Outpost: a lane record whose `imds` origin is
|
|
36
|
+
* this exact id was created on this machine.
|
|
37
|
+
*/
|
|
38
|
+
instanceId?: string;
|
|
32
39
|
lanes?: readonly CanonicalHostLane[];
|
|
33
40
|
now: Date;
|
|
34
41
|
}): CanonicalHost;
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
* uses: the Outpost marker (`/etc/outpost/outpost-id`) on an Outpost, and the
|
|
6
6
|
* stable id in `~/.hq/lane-host.json` elsewhere. This module only gathers the
|
|
7
7
|
* aliases, from values that are already on disk. It makes no network call, so
|
|
8
|
-
* the
|
|
8
|
+
* the registry instance name is not listed, and the EC2 instance id is listed
|
|
9
|
+
* only when the caller read it from a local file.
|
|
9
10
|
*
|
|
10
11
|
* The list is for printing and for joining records. It includes ids taken from
|
|
11
12
|
* lane records, so it must not be passed back into the local matcher to decide
|
|
@@ -40,8 +41,10 @@ export function resolveCanonicalHost(input) {
|
|
|
40
41
|
add(localId);
|
|
41
42
|
// A lane stamped `local` belongs to this machine when the existing local
|
|
42
43
|
// matcher says so. Outpost-stamped lanes carry the marker id or another
|
|
43
|
-
// Outpost's id,
|
|
44
|
-
//
|
|
44
|
+
// Outpost's id, so their host adds no alias. An `imds` origin is another
|
|
45
|
+
// machine's instance id unless it equals the one this machine read from its
|
|
46
|
+
// own disk; without that reading no `imds` origin is listed.
|
|
47
|
+
const instanceId = input.host.kind === "outpost" ? input.instanceId?.trim() : undefined;
|
|
45
48
|
const match = {
|
|
46
49
|
hostname,
|
|
47
50
|
...(localId ? { machineId: localId } : {}),
|
|
@@ -59,6 +62,9 @@ export function resolveCanonicalHost(input) {
|
|
|
59
62
|
localHostIdsReferToSameMachine(lane.origin_host, match)) {
|
|
60
63
|
add(lane.origin_host);
|
|
61
64
|
}
|
|
65
|
+
if (instanceId && lane.origin_host_source === "imds" && lane.origin_host === instanceId) {
|
|
66
|
+
add(instanceId);
|
|
67
|
+
}
|
|
62
68
|
}
|
|
63
69
|
return { kind: input.host.kind, id, aliases };
|
|
64
70
|
}
|
|
@@ -30,5 +30,20 @@ export interface MachineIdentityDeps {
|
|
|
30
30
|
}
|
|
31
31
|
/** IMDSv2 token then instance-id. Any failure is null, not a thrown guess. */
|
|
32
32
|
export declare function defaultReadImdsInstanceId(): string | null;
|
|
33
|
+
/** Where a Nitro EC2 instance exposes its instance id as a file. */
|
|
34
|
+
export declare const DMI_BOARD_ASSET_TAG_PATH = "/sys/devices/virtual/dmi/id/board_asset_tag";
|
|
35
|
+
/**
|
|
36
|
+
* This machine's EC2 instance id read from a local file, with no network
|
|
37
|
+
* call. Null when the platform is not Linux, the file is missing, or its
|
|
38
|
+
* content is not an instance id (other hardware puts vendor text there).
|
|
39
|
+
*
|
|
40
|
+
* This is for listing the id as a host alias. It is not a replacement for
|
|
41
|
+
* `resolveMachineIdentity`, which stays the one reading used to stamp and
|
|
42
|
+
* compare `origin_host`.
|
|
43
|
+
*/
|
|
44
|
+
export declare function readInstanceIdFromDisk(deps?: {
|
|
45
|
+
platform?: NodeJS.Platform;
|
|
46
|
+
readFileSync?: (file: string) => string;
|
|
47
|
+
}): string | null;
|
|
33
48
|
export declare function resolveMachineIdentity(deps?: MachineIdentityDeps): MachineIdentity;
|
|
34
49
|
//# sourceMappingURL=machine-identity.d.ts.map
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* lane must not touch IMDS / the network.
|
|
11
11
|
*/
|
|
12
12
|
import { spawnSync } from "node:child_process";
|
|
13
|
+
import * as fs from "node:fs";
|
|
13
14
|
import * as os from "node:os";
|
|
14
15
|
export const IMDS_HOST = "169.254.169.254";
|
|
15
16
|
export const IMDS_TOKEN_URL = `http://${IMDS_HOST}/latest/api/token`;
|
|
@@ -47,6 +48,31 @@ export function defaultReadImdsInstanceId() {
|
|
|
47
48
|
"X-aws-ec2-metadata-token": token,
|
|
48
49
|
});
|
|
49
50
|
}
|
|
51
|
+
/** Where a Nitro EC2 instance exposes its instance id as a file. */
|
|
52
|
+
export const DMI_BOARD_ASSET_TAG_PATH = "/sys/devices/virtual/dmi/id/board_asset_tag";
|
|
53
|
+
const EC2_INSTANCE_ID_PATTERN = /^i-[0-9a-f]{8,32}$/;
|
|
54
|
+
/**
|
|
55
|
+
* This machine's EC2 instance id read from a local file, with no network
|
|
56
|
+
* call. Null when the platform is not Linux, the file is missing, or its
|
|
57
|
+
* content is not an instance id (other hardware puts vendor text there).
|
|
58
|
+
*
|
|
59
|
+
* This is for listing the id as a host alias. It is not a replacement for
|
|
60
|
+
* `resolveMachineIdentity`, which stays the one reading used to stamp and
|
|
61
|
+
* compare `origin_host`.
|
|
62
|
+
*/
|
|
63
|
+
export function readInstanceIdFromDisk(deps = {}) {
|
|
64
|
+
if ((deps.platform ?? process.platform) !== "linux")
|
|
65
|
+
return null;
|
|
66
|
+
let text;
|
|
67
|
+
try {
|
|
68
|
+
text = (deps.readFileSync ?? ((file) => fs.readFileSync(file, "utf8")))(DMI_BOARD_ASSET_TAG_PATH);
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
const id = text.trim();
|
|
74
|
+
return EC2_INSTANCE_ID_PATTERN.test(id) ? id : null;
|
|
75
|
+
}
|
|
50
76
|
export function resolveMachineIdentity(deps = {}) {
|
|
51
77
|
const readImds = deps.readImdsInstanceId ?? defaultReadImdsInstanceId;
|
|
52
78
|
let imdsId = null;
|