@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
|
@@ -3,38 +3,85 @@ import * as fs from "node:fs";
|
|
|
3
3
|
import * as os from "node:os";
|
|
4
4
|
import * as path from "node:path";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { RESOURCE_STOP_WAIT_MS, WorkerResourceSampler, resourceSampleIntervalMs, } from "./resource-usage.js";
|
|
6
7
|
export const LANE_WORKER_EXIT_PATH_ENV = "HQ_LANE_WORKER_EXIT_PATH";
|
|
8
|
+
/**
|
|
9
|
+
* The longest the wrapper waits for resource figures after the worker exits.
|
|
10
|
+
* The sampler gives up on a running sample at RESOURCE_STOP_WAIT_MS; this is
|
|
11
|
+
* the backstop for a sampler that does not return at all.
|
|
12
|
+
*/
|
|
13
|
+
export const WORKER_USAGE_WAIT_MS = RESOURCE_STOP_WAIT_MS + 250;
|
|
7
14
|
function exitCodeFor(code, signal) {
|
|
8
15
|
if (code !== null)
|
|
9
16
|
return code;
|
|
10
17
|
return signal ? 128 + (os.constants.signals[signal] ?? 0) : 1;
|
|
11
18
|
}
|
|
12
|
-
function recordExit(pathname, code, signal) {
|
|
19
|
+
function recordExit(pathname, code, signal, endedAt, usage) {
|
|
13
20
|
const tempPath = `${pathname}.${process.pid}.tmp`;
|
|
14
21
|
fs.writeFileSync(tempPath, `${JSON.stringify({
|
|
15
22
|
exit_code: exitCodeFor(code, signal),
|
|
16
23
|
...(signal ? { signal } : {}),
|
|
17
|
-
ended_at:
|
|
24
|
+
ended_at: endedAt.toISOString(),
|
|
25
|
+
// PS-011: what this run used. resource-usage.ts documents each field's accuracy.
|
|
26
|
+
...(usage ? { resource_usage: usage } : {}),
|
|
18
27
|
})}\n`, { mode: 0o600 });
|
|
19
28
|
fs.renameSync(tempPath, pathname);
|
|
20
29
|
}
|
|
21
|
-
/**
|
|
22
|
-
|
|
30
|
+
/** The sampler's usage, or null when it fails or does not answer within waitMs. */
|
|
31
|
+
async function boundedUsage(sampler, endedAt, waitMs) {
|
|
32
|
+
let timer;
|
|
33
|
+
try {
|
|
34
|
+
return await Promise.race([
|
|
35
|
+
sampler.stop(endedAt),
|
|
36
|
+
new Promise((resolve) => {
|
|
37
|
+
timer = setTimeout(() => {
|
|
38
|
+
process.stderr.write("hq lanes: worker resource use was not ready in time; the exit record has none\n");
|
|
39
|
+
resolve(null);
|
|
40
|
+
}, waitMs);
|
|
41
|
+
// Not unref'd: this timer is what keeps the wrapper alive until the
|
|
42
|
+
// exit record is written when a sampler never answers.
|
|
43
|
+
}),
|
|
44
|
+
]);
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
process.stderr.write(`hq lanes: could not measure worker resource use: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
finally {
|
|
51
|
+
if (timer)
|
|
52
|
+
clearTimeout(timer);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/** Runs one lane worker process and persists its terminal process status and resource use. */
|
|
56
|
+
export function runLaneWorkerProcess(command, args, env = process.env, cwd = process.cwd(), options = {}) {
|
|
57
|
+
const now = options.now ?? (() => new Date());
|
|
23
58
|
const exitPath = env[LANE_WORKER_EXIT_PATH_ENV];
|
|
24
59
|
const childEnv = { ...env };
|
|
25
60
|
delete childEnv[LANE_WORKER_EXIT_PATH_ENV];
|
|
61
|
+
const intervalMs = options.sampleIntervalMs ?? resourceSampleIntervalMs(env);
|
|
62
|
+
const sampler = exitPath
|
|
63
|
+
? (options.createSampler ?? ((pid, at, ms) => new WorkerResourceSampler(pid, at, ms, options.samplerDeps)))(process.pid, now(), intervalMs)
|
|
64
|
+
: null;
|
|
26
65
|
const child = childProcess.spawn(command, args, { cwd, env: childEnv, stdio: "inherit" });
|
|
66
|
+
sampler?.setWorkerPid(child.pid);
|
|
67
|
+
sampler?.start();
|
|
27
68
|
let settled = false;
|
|
28
|
-
|
|
29
|
-
|
|
69
|
+
// The worker's exit code is recorded before anything else can end the
|
|
70
|
+
// wrapper. The signal forwarders stay installed until the exit record is in
|
|
71
|
+
// place, so a SIGTERM that arrives after the worker exited (the reaper
|
|
72
|
+
// signals the wrapper pid) cannot kill the wrapper before it writes it.
|
|
73
|
+
const finish = async (code, signal) => {
|
|
74
|
+
settled = true;
|
|
75
|
+
const endedAt = now();
|
|
76
|
+
const usage = sampler ? await boundedUsage(sampler, endedAt, options.usageWaitMs ?? WORKER_USAGE_WAIT_MS) : null;
|
|
77
|
+
if (exitPath) {
|
|
30
78
|
try {
|
|
31
|
-
recordExit(exitPath, code, signal);
|
|
79
|
+
recordExit(exitPath, code, signal, endedAt, usage);
|
|
32
80
|
}
|
|
33
81
|
catch (error) {
|
|
34
82
|
process.stderr.write(`hq lanes: could not persist worker exit status: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
35
83
|
}
|
|
36
84
|
}
|
|
37
|
-
settled = true;
|
|
38
85
|
return exitCodeFor(code, signal);
|
|
39
86
|
};
|
|
40
87
|
return new Promise((resolve) => {
|
|
@@ -45,23 +92,28 @@ export function runLaneWorkerProcess(command, args, env = process.env, cwd = pro
|
|
|
45
92
|
process.removeListener(signal, handler);
|
|
46
93
|
};
|
|
47
94
|
for (const signal of signals) {
|
|
48
|
-
|
|
95
|
+
// Once the worker has exited there is nothing to forward to; the
|
|
96
|
+
// handler then only keeps the wrapper alive until the record is written.
|
|
97
|
+
const handler = () => {
|
|
98
|
+
if (!settled)
|
|
99
|
+
child.kill(signal);
|
|
100
|
+
};
|
|
49
101
|
handlers.set(signal, handler);
|
|
50
102
|
process.on(signal, handler);
|
|
51
103
|
}
|
|
104
|
+
const end = (code, signal) => {
|
|
105
|
+
if (settled)
|
|
106
|
+
return;
|
|
107
|
+
void finish(code, signal).then((exitCode) => {
|
|
108
|
+
cleanup();
|
|
109
|
+
resolve(exitCode);
|
|
110
|
+
});
|
|
111
|
+
};
|
|
52
112
|
child.once("error", (error) => {
|
|
53
113
|
process.stderr.write(`hq lanes: worker process could not start: ${error.message}\n`);
|
|
54
|
-
|
|
55
|
-
cleanup();
|
|
56
|
-
resolve(finish(127, null));
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
child.once("exit", (code, signal) => {
|
|
60
|
-
if (!settled) {
|
|
61
|
-
cleanup();
|
|
62
|
-
resolve(finish(code, signal));
|
|
63
|
-
}
|
|
114
|
+
end(127, null);
|
|
64
115
|
});
|
|
116
|
+
child.once("exit", (code, signal) => end(code, signal));
|
|
65
117
|
});
|
|
66
118
|
}
|
|
67
119
|
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The matcher: which environments can do one piece of work, and a first
|
|
3
|
+
* ranking of the (environment, login) pairs that can.
|
|
4
|
+
*
|
|
5
|
+
* match(requirements, profiles, { now }) -> { feasible, rejected, ranked }
|
|
6
|
+
*
|
|
7
|
+
* Pass 1 applies rules R1 to R9 from the HQ Everywhere match walkthrough
|
|
8
|
+
* (research/environment-profile-v1/match-walkthrough.md). An environment is
|
|
9
|
+
* rejected at the first rule it fails, and a pair at the first account check
|
|
10
|
+
* it fails; each rejection carries exactly one reason naming the rule and the
|
|
11
|
+
* field. Pass 2 scores every feasible pair with the weights in MATCH_WEIGHTS.
|
|
12
|
+
*
|
|
13
|
+
* This is a tool for the conductor engine (owner decision 1): it filters and
|
|
14
|
+
* gives a first ranking. It does not choose; the conductor makes and records
|
|
15
|
+
* the choice.
|
|
16
|
+
*
|
|
17
|
+
* Login policy (owner decision 5): a login held by the owner pairs with work
|
|
18
|
+
* for any of his businesses. owning_company is shown on the ranked pair and
|
|
19
|
+
* breaks ties; it never filters the owner's logins. A login held by another
|
|
20
|
+
* person (readings.foreign_accounts) never pairs.
|
|
21
|
+
*
|
|
22
|
+
* Freshness: every reading is aged against the one `now` passed in. A reading
|
|
23
|
+
* is fresh when it was observed at most ttl_seconds before now (exactly at the
|
|
24
|
+
* ttl is still fresh). A reading with no observed_at, or one observed more than
|
|
25
|
+
* clock_skew_seconds after now, is unknown; one older than its ttl is stale.
|
|
26
|
+
* Stale or unknown room counts as a quarter of the room points, never as fresh
|
|
27
|
+
* room. Stale or unknown compute counts as unknown compute and is not used for
|
|
28
|
+
* the live size check. An access probe that is not fresh fails R5.
|
|
29
|
+
*
|
|
30
|
+
* Company isolation: a profile is a company-scoped view, so it ranks only for
|
|
31
|
+
* the company whose view it is (R1 on view.company).
|
|
32
|
+
*
|
|
33
|
+
* Input: the documents must already be valid (parseEnvironmentProfile and
|
|
34
|
+
* parseWorkRequirements). A missing required array throws an Error that names
|
|
35
|
+
* it. Duplicate environment ids are settled under R0 (input), field
|
|
36
|
+
* declared.id, after the company filter and whatever the input order:
|
|
37
|
+
* identical copies collapse to one, an undated or future-dated copy is
|
|
38
|
+
* rejected without hiding the others, the copy with the latest
|
|
39
|
+
* view.generated_at is kept, and when no single copy is latest every copy is
|
|
40
|
+
* rejected.
|
|
41
|
+
*
|
|
42
|
+
* The module has no I/O. It imports types only, reads no file, environment
|
|
43
|
+
* variable, clock or network, and runs without an HQ root.
|
|
44
|
+
*/
|
|
45
|
+
import type { EnvironmentProfile } from "../environment/profile.js";
|
|
46
|
+
import type { WorkRequirements } from "../environment/work-requirements.js";
|
|
47
|
+
export declare const MATCH_RESULT_SCHEMA_VERSION = "hq-env-match.v1";
|
|
48
|
+
/** Printed with every result: this is not a placement. */
|
|
49
|
+
export declare const MATCH_FIRST_RANKING_NOTICE = "First ranking from the matcher, not a placement. The conductor engine makes and records the choice.";
|
|
50
|
+
/**
|
|
51
|
+
* Pass-2 weights: the scoring table from the match walkthrough, as one config
|
|
52
|
+
* table. A total is out of about 100.
|
|
53
|
+
*/
|
|
54
|
+
export interface MatchWeights {
|
|
55
|
+
/** Room: room_max x left_percent / 100 for a fresh reading. */
|
|
56
|
+
room_max: number;
|
|
57
|
+
/** Share of room_max given to unknown or stale room (0.25 -> 8.75 points). */
|
|
58
|
+
room_unknown_share: number;
|
|
59
|
+
/** Compute: compute_max x clamp(1 - load_per_vcpu, 0, 1) for a fresh reading. */
|
|
60
|
+
compute_max: number;
|
|
61
|
+
/** Compute with no reading, a stale reading or a template. */
|
|
62
|
+
compute_unknown_points: number;
|
|
63
|
+
/** Every repo and data need already has a passing probe here. Template: 0. */
|
|
64
|
+
locality_points: number;
|
|
65
|
+
/** Locality for work with no repo or data needs: the same for every environment, template or not. */
|
|
66
|
+
locality_no_needs_points: number;
|
|
67
|
+
/** soft_labels_max x share of prefers.labels present. */
|
|
68
|
+
soft_labels_max: number;
|
|
69
|
+
/** engine_order_max x (n - i) / n for the engine's place i in engines.any_of. */
|
|
70
|
+
engine_order_max: number;
|
|
71
|
+
/** Minus cost_per_usd x estimated run cost in USD (metered environments only). */
|
|
72
|
+
cost_per_usd: number;
|
|
73
|
+
/** Cost penalty cap; also the penalty when a metered price is unknown. */
|
|
74
|
+
cost_cap: number;
|
|
75
|
+
/** Minus start_per_minute x start_seconds_estimate / 60 for an environment that is not running. */
|
|
76
|
+
start_per_minute: number;
|
|
77
|
+
/** Start penalty cap. */
|
|
78
|
+
start_cap: number;
|
|
79
|
+
/** Start penalty when the estimate is unknown. */
|
|
80
|
+
start_unknown_penalty: number;
|
|
81
|
+
/** Minus this for each untolerated prefer-not taint. */
|
|
82
|
+
taint_prefer_not_penalty: number;
|
|
83
|
+
/**
|
|
84
|
+
* Clock-skew allowance: a reading observed up to this many seconds after
|
|
85
|
+
* now is aged as if observed at now; one observed later is unknown, not fresh.
|
|
86
|
+
*/
|
|
87
|
+
clock_skew_seconds: number;
|
|
88
|
+
}
|
|
89
|
+
/** The config table: pass-2 weights and the clock-skew allowance. */
|
|
90
|
+
export declare const MATCH_WEIGHTS: Readonly<MatchWeights>;
|
|
91
|
+
/** R1..R9 are the walkthrough rules. R0 is input integrity: a duplicate environment id. */
|
|
92
|
+
export type MatchRule = "R0" | "R1" | "R2" | "R3" | "R4" | "R5" | "R6" | "R7" | "R8" | "R9";
|
|
93
|
+
export interface MatchReason {
|
|
94
|
+
rule: MatchRule;
|
|
95
|
+
/** The field that failed: a work field (needs.labels) or a profile field (readings.accounts[2].enabled). */
|
|
96
|
+
field: string;
|
|
97
|
+
detail: string;
|
|
98
|
+
}
|
|
99
|
+
export interface MatchRejection {
|
|
100
|
+
subject: "environment" | "pair";
|
|
101
|
+
environment_id: string;
|
|
102
|
+
/** Pairs only. */
|
|
103
|
+
engine?: string;
|
|
104
|
+
/** Pairs only; null for a login held by another person, which has no account id. */
|
|
105
|
+
account_id?: string | null;
|
|
106
|
+
holder?: string | null;
|
|
107
|
+
owning_company?: string | null;
|
|
108
|
+
/** Exactly one reason. */
|
|
109
|
+
reason: MatchReason;
|
|
110
|
+
}
|
|
111
|
+
export interface MatchFeasibleEnvironment {
|
|
112
|
+
environment_id: string;
|
|
113
|
+
kind: string;
|
|
114
|
+
state: string;
|
|
115
|
+
/** Conditions the dispatcher must still meet, e.g. a post-start preflight. */
|
|
116
|
+
flags: string[];
|
|
117
|
+
pairs: number;
|
|
118
|
+
}
|
|
119
|
+
export type RoomBasis = "fresh" | "stale" | "unknown";
|
|
120
|
+
export type ComputeBasis = "fresh" | "stale" | "unknown" | "template";
|
|
121
|
+
export interface MatchScoreTerms {
|
|
122
|
+
room: number;
|
|
123
|
+
compute: number;
|
|
124
|
+
locality: number;
|
|
125
|
+
soft_labels: number;
|
|
126
|
+
engine_order: number;
|
|
127
|
+
cost: number;
|
|
128
|
+
start_time: number;
|
|
129
|
+
taints: number;
|
|
130
|
+
}
|
|
131
|
+
export interface MatchRankedPair {
|
|
132
|
+
rank: number;
|
|
133
|
+
environment_id: string;
|
|
134
|
+
kind: string;
|
|
135
|
+
engine: string;
|
|
136
|
+
/** null for a template, which pairs through its engine label. */
|
|
137
|
+
account_id: string | null;
|
|
138
|
+
pairing: "account" | "template-label";
|
|
139
|
+
holder: string | null;
|
|
140
|
+
/** The login's business. A ranking (tie-break) and reporting input, never a filter for the owner's logins. */
|
|
141
|
+
owning_company: string | null;
|
|
142
|
+
score: number;
|
|
143
|
+
terms: MatchScoreTerms;
|
|
144
|
+
room: {
|
|
145
|
+
basis: RoomBasis;
|
|
146
|
+
left_percent: number | null;
|
|
147
|
+
observed_at: string | null;
|
|
148
|
+
};
|
|
149
|
+
compute: {
|
|
150
|
+
basis: ComputeBasis;
|
|
151
|
+
load_per_vcpu: number | null;
|
|
152
|
+
};
|
|
153
|
+
flags: string[];
|
|
154
|
+
}
|
|
155
|
+
export interface MatchResult {
|
|
156
|
+
schema_version: typeof MATCH_RESULT_SCHEMA_VERSION;
|
|
157
|
+
/** Always "first-ranking": the conductor makes the choice. */
|
|
158
|
+
output: "first-ranking";
|
|
159
|
+
notice: string;
|
|
160
|
+
work_id: string;
|
|
161
|
+
company: string;
|
|
162
|
+
now: string;
|
|
163
|
+
weights: MatchWeights;
|
|
164
|
+
feasible: MatchFeasibleEnvironment[];
|
|
165
|
+
rejected: MatchRejection[];
|
|
166
|
+
ranked: MatchRankedPair[];
|
|
167
|
+
}
|
|
168
|
+
export interface MatchOptions {
|
|
169
|
+
/** The match time. Every reading is aged against it. Required: the library reads no clock. */
|
|
170
|
+
now: Date | string;
|
|
171
|
+
weights?: Partial<MatchWeights>;
|
|
172
|
+
}
|
|
173
|
+
export type Freshness = "fresh" | "stale" | "future" | "missing";
|
|
174
|
+
/** The clock the readings are aged against: now and the skew allowance, in ms. */
|
|
175
|
+
interface Clock {
|
|
176
|
+
nowMs: number;
|
|
177
|
+
skewMs: number;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* fresh: observed at most ttl_seconds before now (a reading up to the skew
|
|
181
|
+
* allowance after now counts as observed at now). stale: older than its ttl.
|
|
182
|
+
* future: observed more than the skew allowance after now. missing: no
|
|
183
|
+
* observed_at, or one that is not a date-time.
|
|
184
|
+
*/
|
|
185
|
+
export declare function readingFreshness(observedAt: string | null | undefined, ttlSeconds: number, clock: Clock): Freshness;
|
|
186
|
+
/**
|
|
187
|
+
* Filter environments for one piece of work and rank the pairs that remain.
|
|
188
|
+
* Pure: the same inputs and `now` always give the same result.
|
|
189
|
+
*/
|
|
190
|
+
export declare function match(requirements: WorkRequirements, profiles: readonly EnvironmentProfile[], options: MatchOptions): MatchResult;
|
|
191
|
+
export {};
|
|
192
|
+
//# sourceMappingURL=match.d.ts.map
|