@skrr-ai/cli 0.1.141 → 0.1.143
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/dist/base-command.d.ts +4 -2
- package/dist/base-command.js +46 -13
- package/dist/commands/agents/always-on/disable.js +9 -1
- package/dist/commands/agents/always-on/enable.js +9 -1
- package/dist/commands/agents/always-on/status.js +14 -1
- package/dist/commands/agents/create.js +10 -1
- package/dist/commands/agents/delete.d.ts +6 -0
- package/dist/commands/agents/delete.js +24 -0
- package/dist/commands/agents/intuitions/list.js +1 -1
- package/dist/commands/agents/spawn.d.ts +9 -0
- package/dist/commands/agents/spawn.js +127 -7
- package/dist/commands/agents/todos/cancel.js +3 -0
- package/dist/commands/agents/todos/edit.js +1 -1
- package/dist/commands/agents/triggers/policy.js +7 -0
- package/dist/commands/commitments/preflight.js +17 -2
- package/dist/commands/daemon/index.js +1 -0
- package/dist/commands/daemon/logs.d.ts +8 -1
- package/dist/commands/daemon/logs.js +32 -22
- package/dist/commands/daemon/profile.d.ts +15 -0
- package/dist/commands/daemon/profile.js +51 -0
- package/dist/commands/goals/briefing/status.js +1 -1
- package/dist/commands/machines/profiles/disconnect.d.ts +23 -0
- package/dist/commands/machines/profiles/disconnect.js +102 -0
- package/dist/commands/machines/profiles/index.d.ts +15 -0
- package/dist/commands/machines/profiles/index.js +33 -0
- package/dist/commands/machines/profiles/label.d.ts +24 -0
- package/dist/commands/machines/profiles/label.js +85 -0
- package/dist/commands/machines/profiles/list.d.ts +16 -0
- package/dist/commands/machines/profiles/list.js +87 -0
- package/dist/commands/profiles/list.js +17 -2
- package/dist/commands/spaces/heartbeats/create.js +1 -1
- package/dist/commands/spaces/heartbeats/update.js +1 -1
- package/dist/commands/triggers/authorization.js +1 -1
- package/dist/lib/agent-guides.js +1 -1
- package/dist/lib/agent-proactive-baseline.d.ts +6 -0
- package/dist/lib/agent-proactive-baseline.js +25 -2
- package/dist/lib/always-on-command-result.d.ts +18 -0
- package/dist/lib/always-on-command-result.js +52 -0
- package/dist/lib/always-on-runtime.d.ts +31 -0
- package/dist/lib/always-on-runtime.js +39 -0
- package/dist/lib/auth-diagnostics.d.ts +10 -1
- package/dist/lib/auth-diagnostics.js +16 -8
- package/dist/lib/compasses.js +5 -0
- package/dist/lib/daemon-binding.js +6 -3
- package/dist/lib/daemon-command-hint.d.ts +10 -5
- package/dist/lib/daemon-command-hint.js +11 -6
- package/dist/lib/daemonHandoff.js +6 -2
- package/dist/lib/drain-stdio.d.ts +22 -0
- package/dist/lib/drain-stdio.js +46 -0
- package/dist/lib/keychain.d.ts +22 -1
- package/dist/lib/keychain.js +40 -1
- package/dist/lib/local-daemon-readiness.js +4 -6
- package/dist/lib/local-skills.js +4 -1
- package/dist/lib/machines.d.ts +68 -0
- package/dist/lib/machines.js +67 -0
- package/dist/lib/proactiveApi.d.ts +15 -1
- package/dist/lib/runtime-start-verification.js +3 -6
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/configRoot.d.ts +12 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/configRoot.js +10 -2
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/deviceIdentityBridge.d.ts +8 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/deviceIdentityBridge.js +22 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/executorStopReceiptV2.d.ts +133 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/executorStopReceiptV2.js +180 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/index.d.ts +4 -2
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/index.js +48 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/profilePorts.d.ts +137 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/profilePorts.js +328 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/profileSelection.d.ts +63 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/profileSelection.js +174 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/esm/configRoot.d.ts +12 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/esm/configRoot.js +14 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/esm/deviceIdentityBridge.d.ts +8 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/esm/deviceIdentityBridge.js +27 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/esm/executorStopReceiptV2.d.ts +133 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/esm/executorStopReceiptV2.js +183 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/esm/index.d.ts +4 -2
- package/dist/node_modules/@skrr-ai/auth-core/dist/esm/index.js +10 -2
- package/dist/node_modules/@skrr-ai/auth-core/dist/esm/profilePorts.d.ts +137 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/esm/profilePorts.js +333 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/esm/profileSelection.d.ts +63 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/esm/profileSelection.js +212 -0
- package/dist/node_modules/@skrr-ai/auth-core/package.json +11 -1
- package/dist/node_modules/@skrr-ai/data-provider/index.js +7295 -7265
- package/oclif.manifest.json +332 -3
- package/package.json +1 -1
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* executorStopReceiptV2.ts — a stop receipt the PARENT daemon witnessed, with the coverage it claims.
|
|
3
|
+
*
|
|
4
|
+
* OSK-20777, docs/architecture/independent-stop-witness-2026-11-02.md. A v1 receipt (`executorStopReceipt.ts`)
|
|
5
|
+
* signs a body the session wrapper wrote, so it proves the claim came from the machine and nothing about how the
|
|
6
|
+
* claim was reached. The server holds those back until the evidence is independent and continuous. This body is
|
|
7
|
+
* that evidence's shape:
|
|
8
|
+
*
|
|
9
|
+
* - the observer is the parent daemon, which spawned the wrapper and is not part of the session;
|
|
10
|
+
* - the body states its own COVERAGE (when the witness started, when the wrapper was spawned, how many samples,
|
|
11
|
+
* the largest gap between two), so the server can refuse a receipt that looked too seldom, instead of trusting
|
|
12
|
+
* `survivors: 0`;
|
|
13
|
+
* - erasure is counted by the parent from a directory it created, not reported by the wrapper.
|
|
14
|
+
*
|
|
15
|
+
* The same discipline as v1: no new cryptography, a distinct proof `typ` and `htu` so a v1 receipt can never stand
|
|
16
|
+
* in for a v2 one (or the reverse), a closed body shape, an algorithm taken from the pin, and a reason, never a
|
|
17
|
+
* boolean. This module checks SHAPE and ARITHMETIC (counts add up). It does not decide whether the coverage is
|
|
18
|
+
* enough: the bounds are server policy and live with the server, so they can change without republishing this.
|
|
19
|
+
*/
|
|
20
|
+
import { type DeviceKeyAlg, type DeviceKeySigner, type DevicePublicJwk, type VerifyFailureReason } from './deviceKey.js';
|
|
21
|
+
import { type ExecutorStopReceiptStatus } from './executorStopReceipt.js';
|
|
22
|
+
/** Header `typ` of a v2 receipt. Distinct from the v1 `typ` and from `DEVICE_PROOF_TYP` on purpose. */
|
|
23
|
+
export declare const EXECUTOR_STOP_RECEIPT_V2_TYP = "skrr-executor-stop-receipt-v2+jwt";
|
|
24
|
+
/** How the witness kept orphaned descendants from leaving its tree. `sampling_only` closes no gap. */
|
|
25
|
+
export declare const EXECUTOR_STOP_RECEIPT_REAP_SUPPORT: readonly ["subreaper", "kqueue", "sampling_only"];
|
|
26
|
+
export type ExecutorStopReceiptReapSupport = (typeof EXECUTOR_STOP_RECEIPT_REAP_SUPPORT)[number];
|
|
27
|
+
/** Where the process table can be read the same way. */
|
|
28
|
+
export declare const EXECUTOR_STOP_RECEIPT_WITNESS_PLATFORMS: readonly ["darwin", "linux"];
|
|
29
|
+
export type ExecutorStopReceiptWitnessPlatform = (typeof EXECUTOR_STOP_RECEIPT_WITNESS_PLATFORMS)[number];
|
|
30
|
+
/** The one scope the owner allowed (2026-11-01). */
|
|
31
|
+
export declare const EXECUTOR_STOP_RECEIPT_V2_ERASURE_SCOPE: "session_temp";
|
|
32
|
+
export interface ExecutorStopReceiptWitness {
|
|
33
|
+
kind: 'parent_census';
|
|
34
|
+
platform: ExecutorStopReceiptWitnessPlatform;
|
|
35
|
+
/** The witness was armed before the wrapper was spawned. A receipt that says false is refused by the server. */
|
|
36
|
+
startedBeforeSpawn: boolean;
|
|
37
|
+
/** ISO-8601, when the witness started. */
|
|
38
|
+
startedAt: string;
|
|
39
|
+
/** ISO-8601, when the wrapper was spawned. */
|
|
40
|
+
spawnedAt: string;
|
|
41
|
+
/** ISO-8601, after the wrapper exited and the settle window elapsed. */
|
|
42
|
+
endedAt: string;
|
|
43
|
+
/** The sampling interval the witness asked for. */
|
|
44
|
+
intervalMs: number;
|
|
45
|
+
/** Process-table reads that completed between spawn and end. */
|
|
46
|
+
samples: number;
|
|
47
|
+
/** Largest gap between two consecutive observations, counting spawn to the first and the last to the end. */
|
|
48
|
+
maxGapMs: number;
|
|
49
|
+
reapSupport: ExecutorStopReceiptReapSupport;
|
|
50
|
+
}
|
|
51
|
+
export interface ExecutorStopReceiptBodyV2 {
|
|
52
|
+
version: 2;
|
|
53
|
+
daemonId: string;
|
|
54
|
+
/** The scheduled Run (or Source) the dispatch belongs to. */
|
|
55
|
+
sourceId: string;
|
|
56
|
+
sessionId: string;
|
|
57
|
+
requestId: string;
|
|
58
|
+
dispatchId: string;
|
|
59
|
+
status: ExecutorStopReceiptStatus;
|
|
60
|
+
/** ISO-8601, when the session's process tree was last observed stopped. */
|
|
61
|
+
stoppedAt: string;
|
|
62
|
+
witness: ExecutorStopReceiptWitness;
|
|
63
|
+
/**
|
|
64
|
+
* `observed` is every distinct (pid, start time) ever seen under the wrapper; `observed === stopped + survivors`.
|
|
65
|
+
* `reparented` is how many of them were seen with init as their parent, which is what a daemonized grandchild is.
|
|
66
|
+
*/
|
|
67
|
+
descendants: {
|
|
68
|
+
observed: number;
|
|
69
|
+
stopped: number;
|
|
70
|
+
survivors: number;
|
|
71
|
+
reparented: number;
|
|
72
|
+
};
|
|
73
|
+
/** Counted by the parent over the directory it created for the session. `inventory === removed + stillPresent`. */
|
|
74
|
+
erasure: {
|
|
75
|
+
scope: typeof EXECUTOR_STOP_RECEIPT_V2_ERASURE_SCOPE;
|
|
76
|
+
inventory: number;
|
|
77
|
+
removed: number;
|
|
78
|
+
stillPresent: number;
|
|
79
|
+
bytes: number;
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
export interface ExecutorStopReceiptV2 {
|
|
83
|
+
body: ExecutorStopReceiptBodyV2;
|
|
84
|
+
/** The device-key proof (JWS compact) that commits to `body`. */
|
|
85
|
+
proof: string;
|
|
86
|
+
}
|
|
87
|
+
export type ExecutorStopReceiptV2FailureReason = VerifyFailureReason | 'bad_receipt' | 'no_pin' | 'binding_mismatch' | 'not_quiescent';
|
|
88
|
+
export type VerifyExecutorStopReceiptV2Result = {
|
|
89
|
+
valid: true;
|
|
90
|
+
body: ExecutorStopReceiptBodyV2;
|
|
91
|
+
alg: DeviceKeyAlg;
|
|
92
|
+
thumbprint: string;
|
|
93
|
+
signedAtSeconds: number;
|
|
94
|
+
} | {
|
|
95
|
+
valid: false;
|
|
96
|
+
reason: ExecutorStopReceiptV2FailureReason;
|
|
97
|
+
};
|
|
98
|
+
/** Default ceiling on a receipt's age: one day. A replay from the response WAL can legitimately be late. */
|
|
99
|
+
export declare const EXECUTOR_STOP_RECEIPT_V2_DEFAULT_MAX_AGE_SECONDS: number;
|
|
100
|
+
declare const BINDING_KEYS: readonly ["daemonId", "sourceId", "sessionId", "requestId", "dispatchId"];
|
|
101
|
+
/** The URI a v2 receipt's proof names. Reserved `.invalid` host: it can never be a real request target. */
|
|
102
|
+
export declare function executorStopReceiptV2Htu(dispatchId: string): string;
|
|
103
|
+
/** Shape and arithmetic only. Returns the body as typed, or null when it is not exactly a v2 receipt body. */
|
|
104
|
+
export declare function parseExecutorStopReceiptBodyV2(value: unknown): ExecutorStopReceiptBodyV2 | null;
|
|
105
|
+
export interface SignExecutorStopReceiptV2Options {
|
|
106
|
+
/** Test hooks; production leaves both unset. */
|
|
107
|
+
iat?: number;
|
|
108
|
+
jti?: string;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Sign a v2 receipt with any `DeviceKeySigner`. Throws on a body that is not exactly a v2 receipt body, so a
|
|
112
|
+
* daemon bug cannot produce a signed receipt the server would only reject later.
|
|
113
|
+
*/
|
|
114
|
+
export declare function signExecutorStopReceiptV2(signer: DeviceKeySigner, body: ExecutorStopReceiptBodyV2, options?: SignExecutorStopReceiptV2Options): Promise<ExecutorStopReceiptV2>;
|
|
115
|
+
export interface VerifyExecutorStopReceiptV2Options {
|
|
116
|
+
/** The key pinned on the daemon's row. REQUIRED: without it nothing authorizes the signature. */
|
|
117
|
+
pinnedPublicJwk: DevicePublicJwk | undefined;
|
|
118
|
+
/** What the server issued for this dispatch. Every key given must equal the receipt's. */
|
|
119
|
+
expected?: Partial<Pick<ExecutorStopReceiptBodyV2, (typeof BINDING_KEYS)[number]>>;
|
|
120
|
+
/** Ceiling on the receipt's age in seconds. Defaults to one day. */
|
|
121
|
+
maxAgeSeconds?: number;
|
|
122
|
+
/** Tolerated clock skew in seconds. Defaults to the proof verifier's. */
|
|
123
|
+
clockSkewSeconds?: number;
|
|
124
|
+
/** Testing hook. */
|
|
125
|
+
now?: number;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Verify a v2 receipt against the pinned key. Order: shape, then signature and pin, then the binding to the
|
|
129
|
+
* dispatch, then what the body claims. A forged receipt is reported as the forgery it is, not as a quiescence
|
|
130
|
+
* failure. A survivor or an artifact still present is `not_quiescent`. Coverage is NOT judged here.
|
|
131
|
+
*/
|
|
132
|
+
export declare function verifyExecutorStopReceiptV2(receipt: unknown, options: VerifyExecutorStopReceiptV2Options): VerifyExecutorStopReceiptV2Result;
|
|
133
|
+
export {};
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* executorStopReceiptV2.ts — a stop receipt the PARENT daemon witnessed, with the coverage it claims.
|
|
3
|
+
*
|
|
4
|
+
* OSK-20777, docs/architecture/independent-stop-witness-2026-11-02.md. A v1 receipt (`executorStopReceipt.ts`)
|
|
5
|
+
* signs a body the session wrapper wrote, so it proves the claim came from the machine and nothing about how the
|
|
6
|
+
* claim was reached. The server holds those back until the evidence is independent and continuous. This body is
|
|
7
|
+
* that evidence's shape:
|
|
8
|
+
*
|
|
9
|
+
* - the observer is the parent daemon, which spawned the wrapper and is not part of the session;
|
|
10
|
+
* - the body states its own COVERAGE (when the witness started, when the wrapper was spawned, how many samples,
|
|
11
|
+
* the largest gap between two), so the server can refuse a receipt that looked too seldom, instead of trusting
|
|
12
|
+
* `survivors: 0`;
|
|
13
|
+
* - erasure is counted by the parent from a directory it created, not reported by the wrapper.
|
|
14
|
+
*
|
|
15
|
+
* The same discipline as v1: no new cryptography, a distinct proof `typ` and `htu` so a v1 receipt can never stand
|
|
16
|
+
* in for a v2 one (or the reverse), a closed body shape, an algorithm taken from the pin, and a reason, never a
|
|
17
|
+
* boolean. This module checks SHAPE and ARITHMETIC (counts add up). It does not decide whether the coverage is
|
|
18
|
+
* enough: the bounds are server policy and live with the server, so they can change without republishing this.
|
|
19
|
+
*/
|
|
20
|
+
import { algForJwk, isDevicePublicJwk, jwkThumbprint, signProofWith, tokenHash, verifyDevicePublicKeyProof, } from './deviceKey.js';
|
|
21
|
+
import { canonicalReceiptJson } from './executorStopReceipt.js';
|
|
22
|
+
/** Header `typ` of a v2 receipt. Distinct from the v1 `typ` and from `DEVICE_PROOF_TYP` on purpose. */
|
|
23
|
+
export const EXECUTOR_STOP_RECEIPT_V2_TYP = 'skrr-executor-stop-receipt-v2+jwt';
|
|
24
|
+
/** How the witness kept orphaned descendants from leaving its tree. `sampling_only` closes no gap. */
|
|
25
|
+
export const EXECUTOR_STOP_RECEIPT_REAP_SUPPORT = ['subreaper', 'kqueue', 'sampling_only'];
|
|
26
|
+
/** Where the process table can be read the same way. */
|
|
27
|
+
export const EXECUTOR_STOP_RECEIPT_WITNESS_PLATFORMS = ['darwin', 'linux'];
|
|
28
|
+
/** The one scope the owner allowed (2026-11-01). */
|
|
29
|
+
export const EXECUTOR_STOP_RECEIPT_V2_ERASURE_SCOPE = 'session_temp';
|
|
30
|
+
/** Default ceiling on a receipt's age: one day. A replay from the response WAL can legitimately be late. */
|
|
31
|
+
export const EXECUTOR_STOP_RECEIPT_V2_DEFAULT_MAX_AGE_SECONDS = 24 * 60 * 60;
|
|
32
|
+
const MAX_ID_LENGTH = 160;
|
|
33
|
+
const MAX_INTERVAL_MS = 60_000;
|
|
34
|
+
const BODY_KEYS = [
|
|
35
|
+
'version',
|
|
36
|
+
'daemonId',
|
|
37
|
+
'sourceId',
|
|
38
|
+
'sessionId',
|
|
39
|
+
'requestId',
|
|
40
|
+
'dispatchId',
|
|
41
|
+
'status',
|
|
42
|
+
'stoppedAt',
|
|
43
|
+
'witness',
|
|
44
|
+
'descendants',
|
|
45
|
+
'erasure',
|
|
46
|
+
];
|
|
47
|
+
const BINDING_KEYS = ['daemonId', 'sourceId', 'sessionId', 'requestId', 'dispatchId'];
|
|
48
|
+
const WITNESS_KEYS = [
|
|
49
|
+
'kind',
|
|
50
|
+
'platform',
|
|
51
|
+
'startedBeforeSpawn',
|
|
52
|
+
'startedAt',
|
|
53
|
+
'spawnedAt',
|
|
54
|
+
'endedAt',
|
|
55
|
+
'intervalMs',
|
|
56
|
+
'samples',
|
|
57
|
+
'maxGapMs',
|
|
58
|
+
'reapSupport',
|
|
59
|
+
];
|
|
60
|
+
const isPlainObject = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
61
|
+
const hasExactKeys = (value, keys) => Object.keys(value).length === keys.length && keys.every((key) => Object.hasOwn(value, key));
|
|
62
|
+
const isId = (value) => typeof value === 'string' && value.length > 0 && value.length <= MAX_ID_LENGTH;
|
|
63
|
+
const isCount = (value) => typeof value === 'number' && Number.isSafeInteger(value) && value >= 0;
|
|
64
|
+
const isInstant = (value) => typeof value === 'string' && !Number.isNaN(Date.parse(value));
|
|
65
|
+
/** The URI a v2 receipt's proof names. Reserved `.invalid` host: it can never be a real request target. */
|
|
66
|
+
export function executorStopReceiptV2Htu(dispatchId) {
|
|
67
|
+
return `https://executor-stop-receipt.skrr.invalid/v2/${encodeURIComponent(dispatchId)}`;
|
|
68
|
+
}
|
|
69
|
+
function parseWitness(value) {
|
|
70
|
+
if (!isPlainObject(value) || !hasExactKeys(value, WITNESS_KEYS) || value.kind !== 'parent_census')
|
|
71
|
+
return null;
|
|
72
|
+
if (!EXECUTOR_STOP_RECEIPT_WITNESS_PLATFORMS.includes(value.platform))
|
|
73
|
+
return null;
|
|
74
|
+
if (typeof value.startedBeforeSpawn !== 'boolean')
|
|
75
|
+
return null;
|
|
76
|
+
if (!isInstant(value.startedAt) || !isInstant(value.spawnedAt) || !isInstant(value.endedAt))
|
|
77
|
+
return null;
|
|
78
|
+
if (!isCount(value.intervalMs) ||
|
|
79
|
+
value.intervalMs < 1 ||
|
|
80
|
+
value.intervalMs > MAX_INTERVAL_MS ||
|
|
81
|
+
!isCount(value.samples) ||
|
|
82
|
+
!isCount(value.maxGapMs))
|
|
83
|
+
return null;
|
|
84
|
+
if (!EXECUTOR_STOP_RECEIPT_REAP_SUPPORT.includes(value.reapSupport))
|
|
85
|
+
return null;
|
|
86
|
+
return value;
|
|
87
|
+
}
|
|
88
|
+
/** Shape and arithmetic only. Returns the body as typed, or null when it is not exactly a v2 receipt body. */
|
|
89
|
+
export function parseExecutorStopReceiptBodyV2(value) {
|
|
90
|
+
if (!isPlainObject(value) || !hasExactKeys(value, BODY_KEYS) || value.version !== 2)
|
|
91
|
+
return null;
|
|
92
|
+
if (!BINDING_KEYS.every((key) => isId(value[key])))
|
|
93
|
+
return null;
|
|
94
|
+
if (value.status !== 'completed' && value.status !== 'failed' && value.status !== 'cancelled')
|
|
95
|
+
return null;
|
|
96
|
+
if (!isInstant(value.stoppedAt))
|
|
97
|
+
return null;
|
|
98
|
+
if (!parseWitness(value.witness))
|
|
99
|
+
return null;
|
|
100
|
+
const d = value.descendants;
|
|
101
|
+
if (!isPlainObject(d) || !hasExactKeys(d, ['observed', 'stopped', 'survivors', 'reparented']))
|
|
102
|
+
return null;
|
|
103
|
+
if (!isCount(d.observed) ||
|
|
104
|
+
!isCount(d.stopped) ||
|
|
105
|
+
!isCount(d.survivors) ||
|
|
106
|
+
!isCount(d.reparented))
|
|
107
|
+
return null;
|
|
108
|
+
if (d.observed !== d.stopped + d.survivors || d.reparented > d.observed)
|
|
109
|
+
return null;
|
|
110
|
+
const e = value.erasure;
|
|
111
|
+
if (!isPlainObject(e) ||
|
|
112
|
+
!hasExactKeys(e, ['scope', 'inventory', 'removed', 'stillPresent', 'bytes']) ||
|
|
113
|
+
e.scope !== EXECUTOR_STOP_RECEIPT_V2_ERASURE_SCOPE)
|
|
114
|
+
return null;
|
|
115
|
+
if (!isCount(e.inventory) || !isCount(e.removed) || !isCount(e.stillPresent) || !isCount(e.bytes))
|
|
116
|
+
return null;
|
|
117
|
+
if (e.inventory !== e.removed + e.stillPresent)
|
|
118
|
+
return null;
|
|
119
|
+
return value;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Sign a v2 receipt with any `DeviceKeySigner`. Throws on a body that is not exactly a v2 receipt body, so a
|
|
123
|
+
* daemon bug cannot produce a signed receipt the server would only reject later.
|
|
124
|
+
*/
|
|
125
|
+
export async function signExecutorStopReceiptV2(signer, body, options = {}) {
|
|
126
|
+
const parsed = parseExecutorStopReceiptBodyV2(body);
|
|
127
|
+
if (!parsed)
|
|
128
|
+
throw new Error('signExecutorStopReceiptV2: body is not a v2 executor stop receipt body');
|
|
129
|
+
const proof = await signProofWith(signer, {
|
|
130
|
+
method: 'POST',
|
|
131
|
+
url: executorStopReceiptV2Htu(parsed.dispatchId),
|
|
132
|
+
// `accessToken` is hashed inline into the `ath` claim: the commitment to the body.
|
|
133
|
+
accessToken: canonicalReceiptJson(parsed),
|
|
134
|
+
...(options.iat !== undefined ? { iat: options.iat } : {}),
|
|
135
|
+
...(options.jti !== undefined ? { jti: options.jti } : {}),
|
|
136
|
+
}, EXECUTOR_STOP_RECEIPT_V2_TYP);
|
|
137
|
+
return { body: parsed, proof };
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Verify a v2 receipt against the pinned key. Order: shape, then signature and pin, then the binding to the
|
|
141
|
+
* dispatch, then what the body claims. A forged receipt is reported as the forgery it is, not as a quiescence
|
|
142
|
+
* failure. A survivor or an artifact still present is `not_quiescent`. Coverage is NOT judged here.
|
|
143
|
+
*/
|
|
144
|
+
export function verifyExecutorStopReceiptV2(receipt, options) {
|
|
145
|
+
if (!isPlainObject(receipt) || !hasExactKeys(receipt, ['body', 'proof'])) {
|
|
146
|
+
return { valid: false, reason: 'bad_receipt' };
|
|
147
|
+
}
|
|
148
|
+
const body = parseExecutorStopReceiptBodyV2(receipt.body);
|
|
149
|
+
if (!body || typeof receipt.proof !== 'string')
|
|
150
|
+
return { valid: false, reason: 'bad_receipt' };
|
|
151
|
+
const pin = options.pinnedPublicJwk;
|
|
152
|
+
if (!pin || !isDevicePublicJwk(pin))
|
|
153
|
+
return { valid: false, reason: 'no_pin' };
|
|
154
|
+
const result = verifyDevicePublicKeyProof(receipt.proof, {
|
|
155
|
+
expectedHtm: 'POST',
|
|
156
|
+
expectedHtu: executorStopReceiptV2Htu(body.dispatchId),
|
|
157
|
+
expectedAth: tokenHash(canonicalReceiptJson(body)),
|
|
158
|
+
pinnedPublicJwk: pin,
|
|
159
|
+
// The algorithm of the PIN, never a list: a receipt cannot pick a weaker one.
|
|
160
|
+
allowedAlgs: [algForJwk(pin)],
|
|
161
|
+
maxAgeSeconds: options.maxAgeSeconds ?? EXECUTOR_STOP_RECEIPT_V2_DEFAULT_MAX_AGE_SECONDS,
|
|
162
|
+
...(options.clockSkewSeconds !== undefined
|
|
163
|
+
? { clockSkewSeconds: options.clockSkewSeconds }
|
|
164
|
+
: {}),
|
|
165
|
+
...(options.now !== undefined ? { now: options.now } : {}),
|
|
166
|
+
}, EXECUTOR_STOP_RECEIPT_V2_TYP);
|
|
167
|
+
if (!result.valid)
|
|
168
|
+
return { valid: false, reason: result.reason };
|
|
169
|
+
for (const key of BINDING_KEYS) {
|
|
170
|
+
const want = options.expected?.[key];
|
|
171
|
+
if (want !== undefined && body[key] !== want)
|
|
172
|
+
return { valid: false, reason: 'binding_mismatch' };
|
|
173
|
+
}
|
|
174
|
+
if (body.descendants.survivors > 0 || body.erasure.stillPresent > 0)
|
|
175
|
+
return { valid: false, reason: 'not_quiescent' };
|
|
176
|
+
return {
|
|
177
|
+
valid: true,
|
|
178
|
+
body,
|
|
179
|
+
alg: result.alg,
|
|
180
|
+
thumbprint: jwkThumbprint(result.publicJwk),
|
|
181
|
+
signedAtSeconds: result.claims.iat,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
@@ -29,12 +29,13 @@ export { __setKekStrategyForTest, getKekStrategy, InMemoryKek, UnavailableKek, K
|
|
|
29
29
|
export { ALLOW_LIVE_STATE_ENV, __setAccountHomeForTest, DAEMON_BYOK_KEYCHAIN_SERVICE_BASE, DAEMON_KEYCHAIN_SERVICE_BASE, HERMETIC_HOME_ENV, LEGACY_DAEMON_KEYCHAIN_SERVICE, LIVE_DEFAULT_PROFILE, LIVE_STATE_REFUSED_CODE, LiveStateRefusedError, accountHomeDir, assertMayMutateLiveKeychain, assertMayMutateLiveState, isLiveKeychainService, isLiveStateRefusal, isTestProcess, keychainSuffixForDir, liveKeychainServices, liveStateRoot, refusesLiveKeychainMutation, refusesLiveStateInTest, rethrowIfLiveStateRefusal, testProcessSignal, type LiveKeychainProbe, type LiveStateProbe, } from './liveState.js';
|
|
30
30
|
export { algForJwk, buildProof as buildDeviceProof, DEVICE_KEY_ALGS, generateDeviceKeyPair, isDevicePublicJwk, jwkThumbprint, normalizeHtu, p256PublicJwkFromRaw, proofSigningInput, publicJwkFromX, signProofWith, tokenHash, verifyProof as verifyDeviceProof, type DeviceKeyAlg, type DeviceKeyPair, type DeviceKeySigner, type DevicePublicJwk, type DeviceProofClaims, type DeviceProofHeader, type Ed25519PrivateJwk, type Ed25519PublicJwk, type P256PublicJwk, type VerifyFailureReason as DeviceProofVerifyFailureReason, type VerifyFailure as DeviceProofVerifyFailure, type VerifyOptions as DeviceProofVerifyOptions, type VerifySuccess as DeviceProofVerifySuccess, } from './deviceKey.js';
|
|
31
31
|
export { canonicalReceiptJson, EXECUTOR_STOP_RECEIPT_DEFAULT_MAX_AGE_SECONDS, EXECUTOR_STOP_RECEIPT_ERASURE_SCOPES, EXECUTOR_STOP_RECEIPT_TYP, executorStopReceiptHtu, parseExecutorStopReceiptBody, signExecutorStopReceipt, verifyExecutorStopReceipt, type ExecutorStopReceipt, type ExecutorStopReceiptBody, type ExecutorStopReceiptErasureScope, type ExecutorStopReceiptFailureReason, type ExecutorStopReceiptStatus, type SignExecutorStopReceiptOptions, type VerifyExecutorStopReceiptOptions, type VerifyExecutorStopReceiptResult, } from './executorStopReceipt.js';
|
|
32
|
+
export { EXECUTOR_STOP_RECEIPT_REAP_SUPPORT, EXECUTOR_STOP_RECEIPT_V2_DEFAULT_MAX_AGE_SECONDS, EXECUTOR_STOP_RECEIPT_V2_ERASURE_SCOPE, EXECUTOR_STOP_RECEIPT_V2_TYP, EXECUTOR_STOP_RECEIPT_WITNESS_PLATFORMS, executorStopReceiptV2Htu, parseExecutorStopReceiptBodyV2, signExecutorStopReceiptV2, verifyExecutorStopReceiptV2, type ExecutorStopReceiptBodyV2, type ExecutorStopReceiptReapSupport, type ExecutorStopReceiptV2, type ExecutorStopReceiptV2FailureReason, type ExecutorStopReceiptWitness, type ExecutorStopReceiptWitnessPlatform, type SignExecutorStopReceiptV2Options, type VerifyExecutorStopReceiptV2Options, type VerifyExecutorStopReceiptV2Result, } from './executorStopReceiptV2.js';
|
|
32
33
|
export { softwareEd25519Handle, type DeviceKeyCustody, type DeviceKeyHandle } from './deviceKeyHandle.js';
|
|
33
34
|
export { AUTH_SERVER_METADATA_PATH, readServerDeviceKeyAlgs, SERVER_DEVICE_KEY_ALGS_FIELD, } from './deviceKeyServerSupport.js';
|
|
34
35
|
export { configureHardwareDeviceKeyHelper, HARDWARE_KEY_HELPER_NAME, HardwareDeviceKeyError, probeHardwareDeviceKey, resolveHardwareDeviceKeyHelper, type HardwareDeviceKeyErrorCode, type HardwareKeyCapability, } from './deviceKeyHardware.js';
|
|
35
36
|
export { DPOP_HEADER, DPOP_MAX_AGE_SECONDS, DPOP_PROOF_INVALID, DPOP_PROOF_REQUIRED, DPOP_PROOF_TYP, DPOP_PROOF_VERIFY_UNAVAILABLE, accessTokenHash, createDpopKey, isAth, isJwkThumbprint, normalizeDpopHtu, verifyDpopProof, type DpopKey, type DpopProofClaims, type DpopProofRequest, type DpopVerifyFailureReason, type DpopVerifyOptions, type DpopVerifyResult, } from './dpop.js';
|
|
36
37
|
export { initCredEnvelope, initExistingCredEnvelope, initNewIndependentCredEnvelope, resetCredEnvelope, shutdownCredEnvelope, isCredEnvelopeActive, hasCredEnvelopePathConflict, describeCredEnvelopeState, splitKeyConvergencePolicy, maybeEncryptForWrite, maybeDecryptOnRead, DEFAULT_UNREADABLE_CREDENTIAL_HINT, type DecryptOnReadOptions, __wrappedDekFilePathForTest, __setStateForTest as __setCredEnvelopeStateForTest, __getStateForTest as __getCredEnvelopeStateForTest, __resetShutdownGuardForTest, type ReadTransformResult, } from './credentialEnvelopeBridge.js';
|
|
37
|
-
export { initDeviceIdentity, resetDeviceIdentity, signServerRequest, signExecutorStopReceiptWithDeviceKey, prepareHardwareKeyCandidate, commitDeviceKeyCandidate, signWithCandidate, persistPendingHardwareKey, commitPendingHardwareKey, discardPendingHardwareKey, PENDING_HARDWARE_KEY_MAX_AGE_MS, type DeviceKeyCandidate, type DeviceKeyCandidateResult, type PendingHardwareKeyOutcome, enrollWithServer, clearEnrollmentMarker, isDeviceIdentityActive, getDevicePublicKey, describeDeviceIdentityState, describeDeviceKeySplit, describeStoredDeviceKey, DEVICE_KEY_UNREADABLE_CREDENTIAL_HINT, type StoredDeviceKeyDescription, __publicKeyPathForTest, __privateKeyPathForTest, __enrollmentMarkerPathForTest, __enrollmentBackoffPathForTest, __setUnreadableReloadIntervalForTest, __setStateForTest as __setDeviceIdentityStateForTest, __getStateForTest as __getDeviceIdentityStateForTest, type EnrollmentResult, } from './deviceIdentityBridge.js';
|
|
38
|
+
export { initDeviceIdentity, resetDeviceIdentity, signServerRequest, signExecutorStopReceiptWithDeviceKey, signExecutorStopReceiptV2WithDeviceKey, prepareHardwareKeyCandidate, commitDeviceKeyCandidate, signWithCandidate, persistPendingHardwareKey, commitPendingHardwareKey, discardPendingHardwareKey, PENDING_HARDWARE_KEY_MAX_AGE_MS, type DeviceKeyCandidate, type DeviceKeyCandidateResult, type PendingHardwareKeyOutcome, enrollWithServer, clearEnrollmentMarker, isDeviceIdentityActive, getDevicePublicKey, describeDeviceIdentityState, describeDeviceKeySplit, describeStoredDeviceKey, DEVICE_KEY_UNREADABLE_CREDENTIAL_HINT, type StoredDeviceKeyDescription, __publicKeyPathForTest, __privateKeyPathForTest, __enrollmentMarkerPathForTest, __enrollmentBackoffPathForTest, __setUnreadableReloadIntervalForTest, __setStateForTest as __setDeviceIdentityStateForTest, __getStateForTest as __getDeviceIdentityStateForTest, type EnrollmentResult, } from './deviceIdentityBridge.js';
|
|
38
39
|
export { getMachineUuid, getMachineUuidForProfile, describeMachineIdentity, type MachineIdentityDescription, type MachineIdentityReason, getHardwareMachineUuid, setMachineUuidProfile, getMachineUuidProfile, qualifyMachineUuid, MACHINE_IDENTITY_FILENAME, hostedRuntimeIdOverride, HOSTED_RUNTIME_MACHINE_SOURCES, __resetMachineUuidCacheForTest, } from './machineUuid.js';
|
|
39
40
|
export { ensureMachineDaemonId, legacyDaemonUuids, __resetCachedDaemonIdForTest, } from './machineId.js';
|
|
40
41
|
export { PAIR_AAD_PREFIX, PAIR_AAD_MAX_LEN, PAIR_BUNDLE_MAX_BASE64_LEN, PAIR_NONCE_LEN, PAIR_PUBKEY_LEN, PAIR_SECRET_LEN, PairBundleError, assemblePairBundleBase64, base64ToUint8Array as pairBase64ToUint8Array, base64UrlToUint8Array as pairBase64UrlToUint8Array, buildPairAad, buildPairUrl, generatePairKeyPair, openPairBundleBase64, parsePairBundle, parsePairPlaintext, parsePairUrl, uint8ArrayToBase64 as pairUint8ArrayToBase64, uint8ArrayToBase64Url as pairUint8ArrayToBase64Url, type AssembleBundleOptions as PairAssembleBundleOptions, type OpenBundleOptions as PairOpenBundleOptions, type PairBundle, type PairBundleErrorCode, type PairKeyPair, type PairPlaintextV1, type PairUrlFields, } from './daemonPair.js';
|
|
@@ -49,7 +50,8 @@ export { FIRST_PARTY_HARNESS_PREVIOUS_SUFFIX, FIRST_PARTY_HARNESS_PROVENANCE_SUF
|
|
|
49
50
|
export { DEFAULT_FIRST_PARTY_HARNESS_CHANNEL, FIRST_PARTY_HARNESS_CHANNELS, firstPartyHarnessChannelPrefix, firstPartyHarnessFeedBase, firstPartyHarnessFeedCandidates, isFirstPartyHarnessChannel, resolveChannelManifestUrl, resolveFirstPartyHarnessChannel, type FirstPartyHarnessChannel, type FirstPartyHarnessFeedCandidate, } from './firstPartyHarnessChannels.js';
|
|
50
51
|
export { OVERSKY_RELEASE_PUBLIC_KEYS, type ReleaseKey } from './releaseKeys.js';
|
|
51
52
|
export { MAX_SIGS, TRUSTED_FEED_ORIGINS, buildArtifactMessage, buildManifestMessage, getDeltaFor, isTrustedArtifactOrigin, verifyArtifact, verifyManifest, type DaemonVersionManifest, type DeltaDescriptor, type ManifestSignature, type PlatformArtifact, type VerifyResult, } from './releaseManifest.js';
|
|
52
|
-
export { resolveConfigRoot, configRootPath, isConfigRootOverridden } from './configRoot.js';
|
|
53
|
+
export { resolveConfigRoot, configRootPath, isConfigRootOverridden, CONFIG_ROOT_ENV_VARS, withConfigRoot, } from './configRoot.js';
|
|
54
|
+
export { DEFAULT_PROFILE, PROFILE_LOCK_FILENAME, PROFILE_ENV_VAR, assertValidProfileName, isValidProfileName, profileLockPath, readProfileLock, resolveProfileSelection, explicitProfileArgs, profileIsImplicit, describeProfileSelection, type ProfileSelection, type ProfileSelectionSource, type ResolveProfileSelectionInput, } from './profileSelection.js';
|
|
53
55
|
export { PROFILES_SEGMENT, SUPERSEDED_MARKER_SUFFIX, SUPERSEDED_COPY_SUFFIX, profileStateDir, legacyProfileStateDir, resolveProfileStateDir, resolveProfileStateFile, profileStateFileLocations, profileStateFilePathsToClear, consolidateProfileState, type ResolvedProfileStateDir, type ConsolidationSpec, type ConsolidationStatus, type ConsolidationOutcome, } from './profileStateDir.js';
|
|
54
56
|
export * from './harnessPermissionControls.js';
|
|
55
57
|
export { compareReleaseVersions } from './releaseVersions.js';
|
|
@@ -111,6 +111,9 @@ export { ALLOW_LIVE_STATE_ENV, __setAccountHomeForTest, DAEMON_BYOK_KEYCHAIN_SER
|
|
|
111
111
|
export { algForJwk, buildProof as buildDeviceProof, DEVICE_KEY_ALGS, generateDeviceKeyPair, isDevicePublicJwk, jwkThumbprint, normalizeHtu, p256PublicJwkFromRaw, proofSigningInput, publicJwkFromX, signProofWith, tokenHash, verifyProof as verifyDeviceProof, } from './deviceKey.js';
|
|
112
112
|
// OSK-20777 Gate 1 — a daemon-signed proof that a scheduled session stopped, under its own proof `typ`.
|
|
113
113
|
export { canonicalReceiptJson, EXECUTOR_STOP_RECEIPT_DEFAULT_MAX_AGE_SECONDS, EXECUTOR_STOP_RECEIPT_ERASURE_SCOPES, EXECUTOR_STOP_RECEIPT_TYP, executorStopReceiptHtu, parseExecutorStopReceiptBody, signExecutorStopReceipt, verifyExecutorStopReceipt, } from './executorStopReceipt.js';
|
|
114
|
+
// OSK-20777 — the v2 receipt: what the PARENT daemon witnessed, with the coverage it claims
|
|
115
|
+
// (docs/architecture/independent-stop-witness-2026-11-02.md).
|
|
116
|
+
export { EXECUTOR_STOP_RECEIPT_REAP_SUPPORT, EXECUTOR_STOP_RECEIPT_V2_DEFAULT_MAX_AGE_SECONDS, EXECUTOR_STOP_RECEIPT_V2_ERASURE_SCOPE, EXECUTOR_STOP_RECEIPT_V2_TYP, EXECUTOR_STOP_RECEIPT_WITNESS_PLATFORMS, executorStopReceiptV2Htu, parseExecutorStopReceiptBodyV2, signExecutorStopReceiptV2, verifyExecutorStopReceiptV2, } from './executorStopReceiptV2.js';
|
|
114
117
|
// The handle every signing site holds instead of a private key, and the
|
|
115
118
|
// hardware-bound backend behind it (docs/architecture/device-key-custody-2026-10-29.md).
|
|
116
119
|
export { softwareEd25519Handle } from './deviceKeyHandle.js';
|
|
@@ -131,7 +134,7 @@ initCredEnvelope, initExistingCredEnvelope, initNewIndependentCredEnvelope, rese
|
|
|
131
134
|
__wrappedDekFilePathForTest, __setStateForTest as __setCredEnvelopeStateForTest, __getStateForTest as __getCredEnvelopeStateForTest, __resetShutdownGuardForTest, } from './credentialEnvelopeBridge.js';
|
|
132
135
|
export {
|
|
133
136
|
// deviceIdentity bridge
|
|
134
|
-
initDeviceIdentity, resetDeviceIdentity, signServerRequest, signExecutorStopReceiptWithDeviceKey, prepareHardwareKeyCandidate, commitDeviceKeyCandidate, signWithCandidate, persistPendingHardwareKey, commitPendingHardwareKey, discardPendingHardwareKey, PENDING_HARDWARE_KEY_MAX_AGE_MS, enrollWithServer, clearEnrollmentMarker, isDeviceIdentityActive, getDevicePublicKey, describeDeviceIdentityState, describeDeviceKeySplit, describeStoredDeviceKey, DEVICE_KEY_UNREADABLE_CREDENTIAL_HINT,
|
|
137
|
+
initDeviceIdentity, resetDeviceIdentity, signServerRequest, signExecutorStopReceiptWithDeviceKey, signExecutorStopReceiptV2WithDeviceKey, prepareHardwareKeyCandidate, commitDeviceKeyCandidate, signWithCandidate, persistPendingHardwareKey, commitPendingHardwareKey, discardPendingHardwareKey, PENDING_HARDWARE_KEY_MAX_AGE_MS, enrollWithServer, clearEnrollmentMarker, isDeviceIdentityActive, getDevicePublicKey, describeDeviceIdentityState, describeDeviceKeySplit, describeStoredDeviceKey, DEVICE_KEY_UNREADABLE_CREDENTIAL_HINT,
|
|
135
138
|
// Test seams — file path resolvers + state setters for spec files.
|
|
136
139
|
__publicKeyPathForTest, __privateKeyPathForTest, __enrollmentMarkerPathForTest, __enrollmentBackoffPathForTest, __setUnreadableReloadIntervalForTest, __setStateForTest as __setDeviceIdentityStateForTest, __getStateForTest as __getDeviceIdentityStateForTest, } from './deviceIdentityBridge.js';
|
|
137
140
|
// Hardware machine identity sent as `machineUuid` (IOPlatformUUID /
|
|
@@ -189,7 +192,12 @@ export { OVERSKY_RELEASE_PUBLIC_KEYS } from './releaseKeys.js';
|
|
|
189
192
|
export { MAX_SIGS, TRUSTED_FEED_ORIGINS, buildArtifactMessage, buildManifestMessage, getDeltaFor, isTrustedArtifactOrigin, verifyArtifact, verifyManifest, } from './releaseManifest.js';
|
|
190
193
|
// The one definition of the skrr root, shared by `skrr` and `skrrd`. See the
|
|
191
194
|
// module for why re-deriving it kept producing divergences.
|
|
192
|
-
export { resolveConfigRoot, configRootPath, isConfigRootOverridden } from './configRoot.js';
|
|
195
|
+
export { resolveConfigRoot, configRootPath, isConfigRootOverridden, CONFIG_ROOT_ENV_VARS, withConfigRoot, } from './configRoot.js';
|
|
196
|
+
// The one rule for which profile a `skrr` or `skrrd` command acts on, and the
|
|
197
|
+
// one profile-name grammar (OSK-22299). The two binaries resolved it by
|
|
198
|
+
// different rules, which is how a CLI login could hand its credential to the
|
|
199
|
+
// profile the daemon's lock named (OSK-22298).
|
|
200
|
+
export { DEFAULT_PROFILE, PROFILE_LOCK_FILENAME, PROFILE_ENV_VAR, assertValidProfileName, isValidProfileName, profileLockPath, readProfileLock, resolveProfileSelection, explicitProfileArgs, profileIsImplicit, describeProfileSelection, } from './profileSelection.js';
|
|
193
201
|
// The one definition of where a PROFILE's auth state lives under that root, and
|
|
194
202
|
// the migration for a machine that ended up with two. Same lesson, one level
|
|
195
203
|
// down: two modules spelled the rule themselves and the two consumers disagreed.
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
export declare const HEALTH_BASE_PORT = 19580;
|
|
2
|
+
export declare const BROWSER_RELAY_BASE_PORT = 18792;
|
|
3
|
+
/** Each kind owns `[base, base + PROFILE_PORT_RANGE)`. */
|
|
4
|
+
export declare const PROFILE_PORT_RANGE = 100;
|
|
5
|
+
export declare const PORT_ALLOCATIONS_FILENAME = "port-allocations.json";
|
|
6
|
+
export declare const PORT_ALLOCATIONS_VERSION = 1;
|
|
7
|
+
/** The kill switch: legacy fixed defaults, no allocation. */
|
|
8
|
+
export declare const STATIC_DEFAULT_PORTS_ENV = "OVERSKY_STATIC_DEFAULT_PORTS";
|
|
9
|
+
export declare const DEFAULT_PORT_PROFILE = "default";
|
|
10
|
+
export declare const PROFILE_PORT_KINDS: readonly ["health", "relay"];
|
|
11
|
+
export type ProfilePortKind = (typeof PROFILE_PORT_KINDS)[number];
|
|
12
|
+
/** Where a profile's port came from. */
|
|
13
|
+
export type ProfilePortSource = 'explicit' | 'allocated' | 'derived' | 'static';
|
|
14
|
+
/**
|
|
15
|
+
* Why an allocation is not the profile's derived port. Recorded when the
|
|
16
|
+
* allocation is made, because the condition (another process holding a port)
|
|
17
|
+
* may be gone by the time anyone reads it.
|
|
18
|
+
*/
|
|
19
|
+
export type ProfilePortMoveReason =
|
|
20
|
+
/** The derived port is the `default` profile's, which has priority on it. */
|
|
21
|
+
'default_priority'
|
|
22
|
+
/** Another profile's record or explicit port holds it. */
|
|
23
|
+
| 'held_by_profile'
|
|
24
|
+
/** A bind probe found something listening there. */
|
|
25
|
+
| 'in_use'
|
|
26
|
+
/** Every slot in the range was taken; the derived port was kept anyway. */
|
|
27
|
+
| 'range_exhausted';
|
|
28
|
+
export interface ProfilePortMove {
|
|
29
|
+
/** The derived port the allocation moved away from. */
|
|
30
|
+
from: number;
|
|
31
|
+
reason: ProfilePortMoveReason;
|
|
32
|
+
/** The profile holding `from`, when `reason` names one. */
|
|
33
|
+
profile?: string;
|
|
34
|
+
at?: string;
|
|
35
|
+
}
|
|
36
|
+
export interface ProfilePortAllocation {
|
|
37
|
+
health?: number;
|
|
38
|
+
relay?: number;
|
|
39
|
+
/** Present only for a kind whose port is not the derived one. */
|
|
40
|
+
moves?: Partial<Record<ProfilePortKind, ProfilePortMove>>;
|
|
41
|
+
updatedAt?: string;
|
|
42
|
+
}
|
|
43
|
+
export interface PortAllocationRecord {
|
|
44
|
+
version: typeof PORT_ALLOCATIONS_VERSION;
|
|
45
|
+
profiles: Record<string, ProfilePortAllocation>;
|
|
46
|
+
}
|
|
47
|
+
export interface ResolvedProfilePort {
|
|
48
|
+
kind: ProfilePortKind;
|
|
49
|
+
port: number;
|
|
50
|
+
source: ProfilePortSource;
|
|
51
|
+
/** What the hash alone would give; shown so a reader can see a move. */
|
|
52
|
+
derived: number;
|
|
53
|
+
/** Set when an allocation moved off `derived`. */
|
|
54
|
+
move?: ProfilePortMove;
|
|
55
|
+
}
|
|
56
|
+
export interface ResolvedProfilePorts {
|
|
57
|
+
profile: string;
|
|
58
|
+
health: ResolvedProfilePort;
|
|
59
|
+
relay: ResolvedProfilePort;
|
|
60
|
+
}
|
|
61
|
+
export declare function profilePortBase(kind: ProfilePortKind): number;
|
|
62
|
+
/** FNV-1a 32-bit over a string's UTF-16 code units. Pure. */
|
|
63
|
+
export declare function fnv1a32(str: string): number;
|
|
64
|
+
export declare function staticDefaultPortsEnabled(env?: NodeJS.ProcessEnv): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* `base + fnv1a32(profile) % 100`, or `base` under the kill switch. The legacy
|
|
67
|
+
* default and the starting point of every allocation; never, on its own, an
|
|
68
|
+
* answer to "which port does this profile listen on".
|
|
69
|
+
*/
|
|
70
|
+
export declare function profileDerivedPort(basePort: number, profile: string, env?: NodeJS.ProcessEnv): number;
|
|
71
|
+
export declare function derivedProfilePort(kind: ProfilePortKind, profile: string, env?: NodeJS.ProcessEnv): number;
|
|
72
|
+
export declare function isInProfilePortRange(kind: ProfilePortKind, port: unknown): port is number;
|
|
73
|
+
export declare function portAllocationsPath(root: string): string;
|
|
74
|
+
export declare function emptyPortAllocations(): PortAllocationRecord;
|
|
75
|
+
/**
|
|
76
|
+
* Tolerant parse: an entry that is not a port in its kind's range is dropped,
|
|
77
|
+
* so a hand-edited or truncated record degrades to "derived" for that profile
|
|
78
|
+
* rather than handing a reader a port the allocator would never have chosen.
|
|
79
|
+
*/
|
|
80
|
+
export declare function parsePortAllocations(raw: unknown): PortAllocationRecord;
|
|
81
|
+
/** The record under `root`, or an empty one when it is absent or unreadable. */
|
|
82
|
+
export declare function readPortAllocations(root: string): PortAllocationRecord;
|
|
83
|
+
/**
|
|
84
|
+
* A `daemon.json` port that is a real choice, or null. Absent, unparsable and
|
|
85
|
+
* equal-to-derived all read as "no choice" (see the header for why the last).
|
|
86
|
+
* `0` is a choice (an ephemeral bind) and is returned as 0.
|
|
87
|
+
*/
|
|
88
|
+
export declare function explicitProfilePort(kind: ProfilePortKind, configured: unknown, profile: string, env?: NodeJS.ProcessEnv): number | null;
|
|
89
|
+
export interface DaemonJsonPortValues {
|
|
90
|
+
health: unknown;
|
|
91
|
+
relay: unknown;
|
|
92
|
+
}
|
|
93
|
+
export declare function profileDaemonJsonPath(root: string, profile: string): string;
|
|
94
|
+
/** The raw port values in a profile's `daemon.json`; both undefined when unreadable. */
|
|
95
|
+
export declare function readDaemonJsonPortValues(root: string, profile: string): DaemonJsonPortValues;
|
|
96
|
+
/** One port, from inputs the caller already holds. */
|
|
97
|
+
export declare function resolveProfilePort(input: {
|
|
98
|
+
kind: ProfilePortKind;
|
|
99
|
+
profile: string;
|
|
100
|
+
configured: unknown;
|
|
101
|
+
allocations: PortAllocationRecord;
|
|
102
|
+
env?: NodeJS.ProcessEnv;
|
|
103
|
+
}): ResolvedProfilePort;
|
|
104
|
+
/**
|
|
105
|
+
* Both ports of `profile` under `root`. Pass `configured` when the caller has
|
|
106
|
+
* already parsed the profile's `daemon.json` (the daemon's `loadConfig` does),
|
|
107
|
+
* so the file is not read twice and the two cannot disagree.
|
|
108
|
+
*/
|
|
109
|
+
export declare function resolveProfilePorts(root: string, profile: string, options?: {
|
|
110
|
+
env?: NodeJS.ProcessEnv;
|
|
111
|
+
configured?: DaemonJsonPortValues;
|
|
112
|
+
allocations?: PortAllocationRecord;
|
|
113
|
+
}): ResolvedProfilePorts;
|
|
114
|
+
/** The profile directories under `root/profiles`. */
|
|
115
|
+
export declare function listProfileNames(root: string): string[];
|
|
116
|
+
/** Who else claims a port, and how. */
|
|
117
|
+
export interface ProfilePortClaim {
|
|
118
|
+
profile: string;
|
|
119
|
+
how: 'explicit' | 'allocated' | 'default_priority';
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Every OTHER profile's claim on each port of `kind`: its explicit port, else
|
|
123
|
+
* its recorded allocation, plus the `default` profile's derived port, which is
|
|
124
|
+
* reserved for it even before it has a record. This is the set an allocation
|
|
125
|
+
* must avoid, and what a reader shows when a derived port is shared.
|
|
126
|
+
*/
|
|
127
|
+
export declare function otherProfilePortClaims(root: string, kind: ProfilePortKind, profile: string, options?: {
|
|
128
|
+
env?: NodeJS.ProcessEnv;
|
|
129
|
+
allocations?: PortAllocationRecord;
|
|
130
|
+
}): Map<number, ProfilePortClaim>;
|
|
131
|
+
/**
|
|
132
|
+
* One sentence: which port, from where, and — when it is not the derived one or
|
|
133
|
+
* might be shared — why. `sharedWith` is a claim another profile holds on this
|
|
134
|
+
* port (from `otherProfilePortClaims`); pass it for a `derived` port, which is
|
|
135
|
+
* the one case where a reader can see a collision the daemon has not resolved.
|
|
136
|
+
*/
|
|
137
|
+
export declare function describeProfilePort(resolved: ResolvedProfilePort, sharedWith?: ProfilePortClaim | null): string;
|