@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.
Files changed (85) hide show
  1. package/dist/base-command.d.ts +4 -2
  2. package/dist/base-command.js +46 -13
  3. package/dist/commands/agents/always-on/disable.js +9 -1
  4. package/dist/commands/agents/always-on/enable.js +9 -1
  5. package/dist/commands/agents/always-on/status.js +14 -1
  6. package/dist/commands/agents/create.js +10 -1
  7. package/dist/commands/agents/delete.d.ts +6 -0
  8. package/dist/commands/agents/delete.js +24 -0
  9. package/dist/commands/agents/intuitions/list.js +1 -1
  10. package/dist/commands/agents/spawn.d.ts +9 -0
  11. package/dist/commands/agents/spawn.js +127 -7
  12. package/dist/commands/agents/todos/cancel.js +3 -0
  13. package/dist/commands/agents/todos/edit.js +1 -1
  14. package/dist/commands/agents/triggers/policy.js +7 -0
  15. package/dist/commands/commitments/preflight.js +17 -2
  16. package/dist/commands/daemon/index.js +1 -0
  17. package/dist/commands/daemon/logs.d.ts +8 -1
  18. package/dist/commands/daemon/logs.js +32 -22
  19. package/dist/commands/daemon/profile.d.ts +15 -0
  20. package/dist/commands/daemon/profile.js +51 -0
  21. package/dist/commands/goals/briefing/status.js +1 -1
  22. package/dist/commands/machines/profiles/disconnect.d.ts +23 -0
  23. package/dist/commands/machines/profiles/disconnect.js +102 -0
  24. package/dist/commands/machines/profiles/index.d.ts +15 -0
  25. package/dist/commands/machines/profiles/index.js +33 -0
  26. package/dist/commands/machines/profiles/label.d.ts +24 -0
  27. package/dist/commands/machines/profiles/label.js +85 -0
  28. package/dist/commands/machines/profiles/list.d.ts +16 -0
  29. package/dist/commands/machines/profiles/list.js +87 -0
  30. package/dist/commands/profiles/list.js +17 -2
  31. package/dist/commands/spaces/heartbeats/create.js +1 -1
  32. package/dist/commands/spaces/heartbeats/update.js +1 -1
  33. package/dist/commands/triggers/authorization.js +1 -1
  34. package/dist/lib/agent-guides.js +1 -1
  35. package/dist/lib/agent-proactive-baseline.d.ts +6 -0
  36. package/dist/lib/agent-proactive-baseline.js +25 -2
  37. package/dist/lib/always-on-command-result.d.ts +18 -0
  38. package/dist/lib/always-on-command-result.js +52 -0
  39. package/dist/lib/always-on-runtime.d.ts +31 -0
  40. package/dist/lib/always-on-runtime.js +39 -0
  41. package/dist/lib/auth-diagnostics.d.ts +10 -1
  42. package/dist/lib/auth-diagnostics.js +16 -8
  43. package/dist/lib/compasses.js +5 -0
  44. package/dist/lib/daemon-binding.js +6 -3
  45. package/dist/lib/daemon-command-hint.d.ts +10 -5
  46. package/dist/lib/daemon-command-hint.js +11 -6
  47. package/dist/lib/daemonHandoff.js +6 -2
  48. package/dist/lib/drain-stdio.d.ts +22 -0
  49. package/dist/lib/drain-stdio.js +46 -0
  50. package/dist/lib/keychain.d.ts +22 -1
  51. package/dist/lib/keychain.js +40 -1
  52. package/dist/lib/local-daemon-readiness.js +4 -6
  53. package/dist/lib/local-skills.js +4 -1
  54. package/dist/lib/machines.d.ts +68 -0
  55. package/dist/lib/machines.js +67 -0
  56. package/dist/lib/proactiveApi.d.ts +15 -1
  57. package/dist/lib/runtime-start-verification.js +3 -6
  58. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/configRoot.d.ts +12 -0
  59. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/configRoot.js +10 -2
  60. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/deviceIdentityBridge.d.ts +8 -0
  61. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/deviceIdentityBridge.js +22 -0
  62. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/executorStopReceiptV2.d.ts +133 -0
  63. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/executorStopReceiptV2.js +180 -0
  64. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/index.d.ts +4 -2
  65. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/index.js +48 -0
  66. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/profilePorts.d.ts +137 -0
  67. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/profilePorts.js +328 -0
  68. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/profileSelection.d.ts +63 -0
  69. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/profileSelection.js +174 -0
  70. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/configRoot.d.ts +12 -0
  71. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/configRoot.js +14 -0
  72. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/deviceIdentityBridge.d.ts +8 -0
  73. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/deviceIdentityBridge.js +27 -0
  74. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/executorStopReceiptV2.d.ts +133 -0
  75. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/executorStopReceiptV2.js +183 -0
  76. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/index.d.ts +4 -2
  77. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/index.js +10 -2
  78. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/profilePorts.d.ts +137 -0
  79. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/profilePorts.js +333 -0
  80. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/profileSelection.d.ts +63 -0
  81. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/profileSelection.js +212 -0
  82. package/dist/node_modules/@skrr-ai/auth-core/package.json +11 -1
  83. package/dist/node_modules/@skrr-ai/data-provider/index.js +7295 -7265
  84. package/oclif.manifest.json +332 -3
  85. package/package.json +1 -1
@@ -0,0 +1,328 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var profilePorts_exports = {};
30
+ __export(profilePorts_exports, {
31
+ BROWSER_RELAY_BASE_PORT: () => BROWSER_RELAY_BASE_PORT,
32
+ DEFAULT_PORT_PROFILE: () => DEFAULT_PORT_PROFILE,
33
+ HEALTH_BASE_PORT: () => HEALTH_BASE_PORT,
34
+ PORT_ALLOCATIONS_FILENAME: () => PORT_ALLOCATIONS_FILENAME,
35
+ PORT_ALLOCATIONS_VERSION: () => PORT_ALLOCATIONS_VERSION,
36
+ PROFILE_PORT_KINDS: () => PROFILE_PORT_KINDS,
37
+ PROFILE_PORT_RANGE: () => PROFILE_PORT_RANGE,
38
+ STATIC_DEFAULT_PORTS_ENV: () => STATIC_DEFAULT_PORTS_ENV,
39
+ derivedProfilePort: () => derivedProfilePort,
40
+ describeProfilePort: () => describeProfilePort,
41
+ emptyPortAllocations: () => emptyPortAllocations,
42
+ explicitProfilePort: () => explicitProfilePort,
43
+ fnv1a32: () => fnv1a32,
44
+ isInProfilePortRange: () => isInProfilePortRange,
45
+ listProfileNames: () => listProfileNames,
46
+ otherProfilePortClaims: () => otherProfilePortClaims,
47
+ parsePortAllocations: () => parsePortAllocations,
48
+ portAllocationsPath: () => portAllocationsPath,
49
+ profileDaemonJsonPath: () => profileDaemonJsonPath,
50
+ profileDerivedPort: () => profileDerivedPort,
51
+ profilePortBase: () => profilePortBase,
52
+ readDaemonJsonPortValues: () => readDaemonJsonPortValues,
53
+ readPortAllocations: () => readPortAllocations,
54
+ resolveProfilePort: () => resolveProfilePort,
55
+ resolveProfilePorts: () => resolveProfilePorts,
56
+ staticDefaultPortsEnabled: () => staticDefaultPortsEnabled
57
+ });
58
+ module.exports = __toCommonJS(profilePorts_exports);
59
+ var import_node_fs = __toESM(require("node:fs"), 1);
60
+ var import_node_path = __toESM(require("node:path"), 1);
61
+ const HEALTH_BASE_PORT = 19580;
62
+ const BROWSER_RELAY_BASE_PORT = 18792;
63
+ const PROFILE_PORT_RANGE = 100;
64
+ const PORT_ALLOCATIONS_FILENAME = "port-allocations.json";
65
+ const PORT_ALLOCATIONS_VERSION = 1;
66
+ const STATIC_DEFAULT_PORTS_ENV = "OVERSKY_STATIC_DEFAULT_PORTS";
67
+ const DEFAULT_PORT_PROFILE = "default";
68
+ const PROFILE_PORT_KINDS = ["health", "relay"];
69
+ function profilePortBase(kind) {
70
+ return kind === "health" ? HEALTH_BASE_PORT : BROWSER_RELAY_BASE_PORT;
71
+ }
72
+ function fnv1a32(str) {
73
+ let h = 2166136261;
74
+ for (let i = 0; i < str.length; i++) {
75
+ h ^= str.charCodeAt(i);
76
+ h = Math.imul(h, 16777619) >>> 0;
77
+ }
78
+ return h >>> 0;
79
+ }
80
+ function staticDefaultPortsEnabled(env = process.env) {
81
+ return env[STATIC_DEFAULT_PORTS_ENV] === "1";
82
+ }
83
+ function profileDerivedPort(basePort, profile, env = process.env) {
84
+ if (staticDefaultPortsEnabled(env))
85
+ return basePort;
86
+ return basePort + fnv1a32(profile) % PROFILE_PORT_RANGE;
87
+ }
88
+ function derivedProfilePort(kind, profile, env = process.env) {
89
+ return profileDerivedPort(profilePortBase(kind), profile, env);
90
+ }
91
+ function isInProfilePortRange(kind, port) {
92
+ const base = profilePortBase(kind);
93
+ return typeof port === "number" && Number.isInteger(port) && port >= base && port < base + PROFILE_PORT_RANGE;
94
+ }
95
+ function portAllocationsPath(root) {
96
+ return import_node_path.default.join(root, PORT_ALLOCATIONS_FILENAME);
97
+ }
98
+ function emptyPortAllocations() {
99
+ return { version: PORT_ALLOCATIONS_VERSION, profiles: {} };
100
+ }
101
+ const MOVE_REASONS = /* @__PURE__ */ new Set([
102
+ "default_priority",
103
+ "held_by_profile",
104
+ "in_use",
105
+ "range_exhausted"
106
+ ]);
107
+ function parseMove(raw, kind) {
108
+ if (!raw || typeof raw !== "object")
109
+ return void 0;
110
+ const m = raw;
111
+ if (!isInProfilePortRange(kind, m.from) || typeof m.reason !== "string")
112
+ return void 0;
113
+ if (!MOVE_REASONS.has(m.reason))
114
+ return void 0;
115
+ return {
116
+ from: m.from,
117
+ reason: m.reason,
118
+ ...typeof m.profile === "string" ? { profile: m.profile } : {},
119
+ ...typeof m.at === "string" ? { at: m.at } : {}
120
+ };
121
+ }
122
+ function parsePortAllocations(raw) {
123
+ const out = emptyPortAllocations();
124
+ if (!raw || typeof raw !== "object")
125
+ return out;
126
+ const profiles = raw.profiles;
127
+ if (!profiles || typeof profiles !== "object" || Array.isArray(profiles))
128
+ return out;
129
+ for (const [name, value] of Object.entries(profiles)) {
130
+ if (!value || typeof value !== "object")
131
+ continue;
132
+ const v = value;
133
+ const entry = {};
134
+ for (const kind of PROFILE_PORT_KINDS) {
135
+ if (isInProfilePortRange(kind, v[kind]))
136
+ entry[kind] = v[kind];
137
+ const move = parseMove(v.moves?.[kind], kind);
138
+ if (move && entry[kind] !== void 0)
139
+ entry.moves = { ...entry.moves, [kind]: move };
140
+ }
141
+ if (typeof v.updatedAt === "string")
142
+ entry.updatedAt = v.updatedAt;
143
+ if (entry.health !== void 0 || entry.relay !== void 0)
144
+ out.profiles[name] = entry;
145
+ }
146
+ return out;
147
+ }
148
+ function readPortAllocations(root) {
149
+ try {
150
+ return parsePortAllocations(JSON.parse(import_node_fs.default.readFileSync(portAllocationsPath(root), "utf8")));
151
+ } catch {
152
+ return emptyPortAllocations();
153
+ }
154
+ }
155
+ function configuredPortNumber(value) {
156
+ let n = null;
157
+ if (typeof value === "number")
158
+ n = value;
159
+ else if (typeof value === "string" && value.trim() !== "")
160
+ n = Number(value);
161
+ if (n === null || !Number.isInteger(n) || n < 0 || n > 65535)
162
+ return null;
163
+ return n;
164
+ }
165
+ function explicitProfilePort(kind, configured, profile, env = process.env) {
166
+ const n = configuredPortNumber(configured);
167
+ if (n === null)
168
+ return null;
169
+ return n === derivedProfilePort(kind, profile, env) ? null : n;
170
+ }
171
+ function profileDaemonJsonPath(root, profile) {
172
+ return import_node_path.default.join(root, "profiles", profile, "daemon.json");
173
+ }
174
+ function readDaemonJsonPortValues(root, profile) {
175
+ try {
176
+ const parsed = JSON.parse(import_node_fs.default.readFileSync(profileDaemonJsonPath(root, profile), "utf8"));
177
+ return { health: parsed?.health?.port, relay: parsed?.browser?.relayPort };
178
+ } catch {
179
+ return { health: void 0, relay: void 0 };
180
+ }
181
+ }
182
+ function resolveProfilePort(input) {
183
+ const env = input.env ?? process.env;
184
+ const derived = derivedProfilePort(input.kind, input.profile, env);
185
+ const explicit = explicitProfilePort(input.kind, input.configured, input.profile, env);
186
+ if (explicit !== null)
187
+ return { kind: input.kind, port: explicit, source: "explicit", derived };
188
+ if (staticDefaultPortsEnabled(env)) {
189
+ return { kind: input.kind, port: derived, source: "static", derived };
190
+ }
191
+ const entry = input.allocations.profiles[input.profile];
192
+ const allocated = entry?.[input.kind];
193
+ if (isInProfilePortRange(input.kind, allocated)) {
194
+ const move = entry?.moves?.[input.kind];
195
+ return {
196
+ kind: input.kind,
197
+ port: allocated,
198
+ source: "allocated",
199
+ derived,
200
+ ...move && allocated !== derived ? { move } : {}
201
+ };
202
+ }
203
+ return { kind: input.kind, port: derived, source: "derived", derived };
204
+ }
205
+ function resolveProfilePorts(root, profile, options = {}) {
206
+ const env = options.env ?? process.env;
207
+ const configured = options.configured ?? readDaemonJsonPortValues(root, profile);
208
+ const allocations = options.allocations ?? (staticDefaultPortsEnabled(env) ? emptyPortAllocations() : readPortAllocations(root));
209
+ return {
210
+ profile,
211
+ health: resolveProfilePort({
212
+ kind: "health",
213
+ profile,
214
+ configured: configured.health,
215
+ allocations,
216
+ env
217
+ }),
218
+ relay: resolveProfilePort({
219
+ kind: "relay",
220
+ profile,
221
+ configured: configured.relay,
222
+ allocations,
223
+ env
224
+ })
225
+ };
226
+ }
227
+ function listProfileNames(root) {
228
+ try {
229
+ return import_node_fs.default.readdirSync(import_node_path.default.join(root, "profiles"), { withFileTypes: true }).filter((d) => d.isDirectory() && !d.name.startsWith(".")).map((d) => d.name).sort();
230
+ } catch {
231
+ return [];
232
+ }
233
+ }
234
+ function otherProfilePortClaims(root, kind, profile, options = {}) {
235
+ const env = options.env ?? process.env;
236
+ const allocations = options.allocations ?? readPortAllocations(root);
237
+ const claims = /* @__PURE__ */ new Map();
238
+ const names = /* @__PURE__ */ new Set([...listProfileNames(root), ...Object.keys(allocations.profiles)]);
239
+ names.delete(profile);
240
+ for (const other of [...names].sort()) {
241
+ const explicit = explicitProfilePort(kind, readDaemonJsonPortValues(root, other)[kind], other, env);
242
+ if (explicit !== null) {
243
+ if (explicit > 0 && !claims.has(explicit))
244
+ claims.set(explicit, { profile: other, how: "explicit" });
245
+ continue;
246
+ }
247
+ const recorded = allocations.profiles[other]?.[kind];
248
+ if (isInProfilePortRange(kind, recorded) && !claims.has(recorded)) {
249
+ claims.set(recorded, { profile: other, how: "allocated" });
250
+ }
251
+ }
252
+ if (profile !== DEFAULT_PORT_PROFILE) {
253
+ const reserved = derivedProfilePort(kind, DEFAULT_PORT_PROFILE, env);
254
+ if (!claims.has(reserved)) {
255
+ claims.set(reserved, { profile: DEFAULT_PORT_PROFILE, how: "default_priority" });
256
+ }
257
+ }
258
+ return claims;
259
+ }
260
+ const KIND_LABEL = { health: "health", relay: "browser relay" };
261
+ const CLAIM_PHRASES = {
262
+ explicit: "sets it explicitly",
263
+ allocated: "is allocated it",
264
+ default_priority: "has priority on it"
265
+ };
266
+ function describeProfilePort(resolved, sharedWith) {
267
+ const label = `${KIND_LABEL[resolved.kind]} port ${resolved.port}`;
268
+ switch (resolved.source) {
269
+ case "explicit":
270
+ return `${label} (explicit: set in this profile's daemon.json)`;
271
+ case "static":
272
+ return `${label} (fixed default: ${STATIC_DEFAULT_PORTS_ENV}=1)`;
273
+ case "allocated": {
274
+ if (resolved.port === resolved.derived) {
275
+ return `${label} (allocated: this profile's derived port)`;
276
+ }
277
+ const move = resolved.move;
278
+ const from = `its derived port ${resolved.derived}`;
279
+ if (!move)
280
+ return `${label} (allocated: moved off ${from})`;
281
+ switch (move.reason) {
282
+ case "default_priority":
283
+ return `${label} (allocated: ${from} is reserved for the default profile)`;
284
+ case "held_by_profile":
285
+ return `${label} (allocated: ${from} is held by profile '${move.profile ?? "unknown"}')`;
286
+ case "in_use":
287
+ return `${label} (allocated: ${from} was in use by another process)`;
288
+ case "range_exhausted":
289
+ return `${label} (allocated: no free port in range; kept ${from})`;
290
+ }
291
+ return `${label} (allocated)`;
292
+ }
293
+ case "derived":
294
+ if (sharedWith) {
295
+ return `${label} (derived from the profile name, not yet allocated, and SHARED: profile '${sharedWith.profile}' ${CLAIM_PHRASES[sharedWith.how]}; restart this profile's daemon to be allocated its own)`;
296
+ }
297
+ return `${label} (derived from the profile name; allocated when this profile's daemon next starts)`;
298
+ }
299
+ }
300
+ // Annotate the CommonJS export names for ESM import in node:
301
+ 0 && (module.exports = {
302
+ BROWSER_RELAY_BASE_PORT,
303
+ DEFAULT_PORT_PROFILE,
304
+ HEALTH_BASE_PORT,
305
+ PORT_ALLOCATIONS_FILENAME,
306
+ PORT_ALLOCATIONS_VERSION,
307
+ PROFILE_PORT_KINDS,
308
+ PROFILE_PORT_RANGE,
309
+ STATIC_DEFAULT_PORTS_ENV,
310
+ derivedProfilePort,
311
+ describeProfilePort,
312
+ emptyPortAllocations,
313
+ explicitProfilePort,
314
+ fnv1a32,
315
+ isInProfilePortRange,
316
+ listProfileNames,
317
+ otherProfilePortClaims,
318
+ parsePortAllocations,
319
+ portAllocationsPath,
320
+ profileDaemonJsonPath,
321
+ profileDerivedPort,
322
+ profilePortBase,
323
+ readDaemonJsonPortValues,
324
+ readPortAllocations,
325
+ resolveProfilePort,
326
+ resolveProfilePorts,
327
+ staticDefaultPortsEnabled
328
+ });
@@ -0,0 +1,63 @@
1
+ /** Canonical default profile name. Used when no flag / env / lock is set. */
2
+ export declare const DEFAULT_PROFILE = "default";
3
+ /** Basename of the sticky selector at the skrr root (`skrrd profile use`). */
4
+ export declare const PROFILE_LOCK_FILENAME = "profile.lock";
5
+ /** Environment variable that selects a profile for one process tree. */
6
+ export declare const PROFILE_ENV_VAR = "OVERSKY_PROFILE";
7
+ export type ProfileSelectionSource = 'flag' | 'env' | 'lock' | 'default';
8
+ export interface ProfileSelection {
9
+ profile: string;
10
+ source: ProfileSelectionSource;
11
+ }
12
+ /**
13
+ * Validate a profile name. Throws `Error` with a human-readable message on
14
+ * invalid input. Never writes anywhere — pure predicate.
15
+ */
16
+ export declare function assertValidProfileName(name: string): void;
17
+ /** Non-throwing variant of `assertValidProfileName`. */
18
+ export declare function isValidProfileName(name: unknown): name is string;
19
+ /** Where the sticky selector lives for this environment's skrr root. */
20
+ export declare function profileLockPath(env?: NodeJS.ProcessEnv): string;
21
+ /**
22
+ * Read the sticky selector. Returns `null` when the file is absent, empty,
23
+ * unreadable, or names an invalid profile — a corrupted lock must never pin a
24
+ * command to a profile that cannot exist.
25
+ */
26
+ export declare function readProfileLock(env?: NodeJS.ProcessEnv): string | null;
27
+ export interface ResolveProfileSelectionInput {
28
+ /** The `--profile` value, or null/undefined/'' when the flag was not given. */
29
+ flag?: string | null;
30
+ /** Environment to read `OVERSKY_PROFILE` and the root from. Default: `process.env`. */
31
+ env?: NodeJS.ProcessEnv;
32
+ /**
33
+ * Whether to consult `OVERSKY_PROFILE` and the lock at all. Tests pass
34
+ * `false` to pin the output to `flag ?? DEFAULT_PROFILE`.
35
+ */
36
+ readEnv?: boolean;
37
+ }
38
+ /**
39
+ * Resolve the profile for one command invocation:
40
+ * `--profile` > `OVERSKY_PROFILE` > `<root>/profile.lock` > `default`.
41
+ *
42
+ * An invalid flag or environment value THROWS (with the grammar's message): a
43
+ * name the person typed is a request, and silently replacing it with another
44
+ * profile would act on the wrong credentials. An invalid lock is ignored, as a
45
+ * corrupt file should be.
46
+ *
47
+ * Pure apart from reading the lock; mutates no global state.
48
+ */
49
+ export declare function resolveProfileSelection(input?: ResolveProfileSelectionInput): ProfileSelection;
50
+ /**
51
+ * The argv a process passes to the OTHER binary so the child acts on exactly
52
+ * `profile`. Always explicit, `default` included — see rule 2 above.
53
+ */
54
+ export declare function explicitProfileArgs(profile: string): string[];
55
+ /**
56
+ * Does a command typed WITHOUT `--profile` in this environment act on
57
+ * `profile`? A person-facing hint can then omit the flag when it would be
58
+ * noise, and must include it when the environment or the lock would send the
59
+ * typed command somewhere else.
60
+ */
61
+ export declare function profileIsImplicit(profile: string, env?: NodeJS.ProcessEnv): boolean;
62
+ /** One sentence naming the profile and why it was chosen, for diagnostics. */
63
+ export declare function describeProfileSelection(selection: ProfileSelection, env?: NodeJS.ProcessEnv): string;
@@ -0,0 +1,174 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var profileSelection_exports = {};
30
+ __export(profileSelection_exports, {
31
+ DEFAULT_PROFILE: () => DEFAULT_PROFILE,
32
+ PROFILE_ENV_VAR: () => PROFILE_ENV_VAR,
33
+ PROFILE_LOCK_FILENAME: () => PROFILE_LOCK_FILENAME,
34
+ assertValidProfileName: () => assertValidProfileName,
35
+ describeProfileSelection: () => describeProfileSelection,
36
+ explicitProfileArgs: () => explicitProfileArgs,
37
+ isValidProfileName: () => isValidProfileName,
38
+ profileIsImplicit: () => profileIsImplicit,
39
+ profileLockPath: () => profileLockPath,
40
+ readProfileLock: () => readProfileLock,
41
+ resolveProfileSelection: () => resolveProfileSelection
42
+ });
43
+ module.exports = __toCommonJS(profileSelection_exports);
44
+ var import_node_fs = __toESM(require("node:fs"), 1);
45
+ var import_node_path = __toESM(require("node:path"), 1);
46
+ var import_configRoot = require("./configRoot.js");
47
+ const DEFAULT_PROFILE = "default";
48
+ const PROFILE_LOCK_FILENAME = "profile.lock";
49
+ const PROFILE_ENV_VAR = "OVERSKY_PROFILE";
50
+ const VALID_PROFILE_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
51
+ const RESERVED_PROFILE_NAMES = /* @__PURE__ */ new Set([
52
+ "profiles",
53
+ "profile",
54
+ ".migrated",
55
+ ".migrated-2026-Q3-phase-k"
56
+ ]);
57
+ const WINDOWS_RESERVED_NAMES = /* @__PURE__ */ new Set([
58
+ "con",
59
+ "prn",
60
+ "aux",
61
+ "nul",
62
+ "com1",
63
+ "com2",
64
+ "com3",
65
+ "com4",
66
+ "com5",
67
+ "com6",
68
+ "com7",
69
+ "com8",
70
+ "com9",
71
+ "lpt1",
72
+ "lpt2",
73
+ "lpt3",
74
+ "lpt4",
75
+ "lpt5",
76
+ "lpt6",
77
+ "lpt7",
78
+ "lpt8",
79
+ "lpt9"
80
+ ]);
81
+ function assertValidProfileName(name) {
82
+ if (typeof name !== "string" || name.length === 0) {
83
+ throw new Error("Profile name must be a non-empty string.");
84
+ }
85
+ if (!VALID_PROFILE_RE.test(name)) {
86
+ throw new Error(`Invalid profile name "${name}". Profile names must be 1\u201364 characters and contain only letters, digits, dot, dash, or underscore. The first character must be a letter or digit.`);
87
+ }
88
+ if (RESERVED_PROFILE_NAMES.has(name)) {
89
+ throw new Error(`Profile name "${name}" is reserved. Pick a different name.`);
90
+ }
91
+ if (WINDOWS_RESERVED_NAMES.has(name.toLowerCase())) {
92
+ throw new Error(`Profile name "${name}" is a Windows reserved device name and cannot be used as a directory name on Windows filesystems. Pick a different name (e.g., "${name}-ws").`);
93
+ }
94
+ }
95
+ function isValidProfileName(name) {
96
+ if (typeof name !== "string")
97
+ return false;
98
+ if (!VALID_PROFILE_RE.test(name))
99
+ return false;
100
+ if (RESERVED_PROFILE_NAMES.has(name))
101
+ return false;
102
+ if (WINDOWS_RESERVED_NAMES.has(name.toLowerCase()))
103
+ return false;
104
+ return true;
105
+ }
106
+ function profileLockPath(env = process.env) {
107
+ return import_node_path.default.join((0, import_configRoot.resolveConfigRoot)(env), PROFILE_LOCK_FILENAME);
108
+ }
109
+ function readProfileLock(env = process.env) {
110
+ try {
111
+ const raw = import_node_fs.default.readFileSync(profileLockPath(env), "utf-8").trim();
112
+ if (!raw)
113
+ return null;
114
+ return isValidProfileName(raw) ? raw : null;
115
+ } catch {
116
+ return null;
117
+ }
118
+ }
119
+ function resolveProfileSelection(input = {}) {
120
+ const flag = typeof input.flag === "string" ? input.flag.trim() : "";
121
+ if (flag) {
122
+ assertValidProfileName(flag);
123
+ return { profile: flag, source: "flag" };
124
+ }
125
+ if (input.readEnv === false)
126
+ return { profile: DEFAULT_PROFILE, source: "default" };
127
+ const env = input.env ?? process.env;
128
+ const fromEnv = (env[PROFILE_ENV_VAR] ?? "").trim();
129
+ if (fromEnv) {
130
+ assertValidProfileName(fromEnv);
131
+ return { profile: fromEnv, source: "env" };
132
+ }
133
+ const pinned = readProfileLock(env);
134
+ if (pinned)
135
+ return { profile: pinned, source: "lock" };
136
+ return { profile: DEFAULT_PROFILE, source: "default" };
137
+ }
138
+ function explicitProfileArgs(profile) {
139
+ assertValidProfileName(profile);
140
+ return ["--profile", profile];
141
+ }
142
+ function profileIsImplicit(profile, env = process.env) {
143
+ try {
144
+ return resolveProfileSelection({ env }).profile === profile;
145
+ } catch {
146
+ return false;
147
+ }
148
+ }
149
+ function describeProfileSelection(selection, env = process.env) {
150
+ switch (selection.source) {
151
+ case "flag":
152
+ return `profile '${selection.profile}' (from --profile)`;
153
+ case "env":
154
+ return `profile '${selection.profile}' (from ${PROFILE_ENV_VAR})`;
155
+ case "lock":
156
+ return `profile '${selection.profile}' (pinned by ${profileLockPath(env)})`;
157
+ default:
158
+ return `profile '${selection.profile}'`;
159
+ }
160
+ }
161
+ // Annotate the CommonJS export names for ESM import in node:
162
+ 0 && (module.exports = {
163
+ DEFAULT_PROFILE,
164
+ PROFILE_ENV_VAR,
165
+ PROFILE_LOCK_FILENAME,
166
+ assertValidProfileName,
167
+ describeProfileSelection,
168
+ explicitProfileArgs,
169
+ isValidProfileName,
170
+ profileIsImplicit,
171
+ profileLockPath,
172
+ readProfileLock,
173
+ resolveProfileSelection
174
+ });
@@ -32,6 +32,18 @@
32
32
  * child process it is about to spawn, and so tests need no process-wide mutation.
33
33
  */
34
34
  export declare function resolveConfigRoot(env?: NodeJS.ProcessEnv): string;
35
+ /**
36
+ * The variables that relocate the root, newest spelling first. For a message
37
+ * that must tell a person which override to drop; nothing reads the
38
+ * environment through this list.
39
+ */
40
+ export declare const CONFIG_ROOT_ENV_VARS: readonly ["SKRR_CONFIG_DIR", "OVERSKY_CONFIG_DIR"];
41
+ /**
42
+ * `env` with the root pointed at `root`, for a caller that resolves as though the
43
+ * root were elsewhere (a test's temporary home, a child process). Writing the
44
+ * override here keeps the variable's name in its one definition.
45
+ */
46
+ export declare function withConfigRoot(env: NodeJS.ProcessEnv, root: string): NodeJS.ProcessEnv;
35
47
  /** A path under the skrr root, e.g. `configRootPath(env, 'daemon', 'logs')`. */
36
48
  export declare function configRootPath(env: NodeJS.ProcessEnv, ...segments: string[]): string;
37
49
  /**
@@ -37,6 +37,20 @@ export function resolveConfigRoot(env = process.env) {
37
37
  const override = (env.SKRR_CONFIG_DIR || env.OVERSKY_CONFIG_DIR)?.trim();
38
38
  return override || path.join(homedir(), '.skrr');
39
39
  }
40
+ /**
41
+ * The variables that relocate the root, newest spelling first. For a message
42
+ * that must tell a person which override to drop; nothing reads the
43
+ * environment through this list.
44
+ */
45
+ export const CONFIG_ROOT_ENV_VARS = ['SKRR_CONFIG_DIR', 'OVERSKY_CONFIG_DIR'];
46
+ /**
47
+ * `env` with the root pointed at `root`, for a caller that resolves as though the
48
+ * root were elsewhere (a test's temporary home, a child process). Writing the
49
+ * override here keeps the variable's name in its one definition.
50
+ */
51
+ export function withConfigRoot(env, root) {
52
+ return { ...env, SKRR_CONFIG_DIR: root };
53
+ }
40
54
  /** A path under the skrr root, e.g. `configRootPath(env, 'daemon', 'logs')`. */
41
55
  export function configRootPath(env, ...segments) {
42
56
  return path.join(resolveConfigRoot(env), ...segments);
@@ -1,6 +1,7 @@
1
1
  import { type DeviceKeyAlg, type DevicePublicJwk } from './deviceKey.js';
2
2
  import { type DeviceKeyCustody, type DeviceKeyHandle } from './deviceKeyHandle.js';
3
3
  import { type ExecutorStopReceipt, type ExecutorStopReceiptBody } from './executorStopReceipt.js';
4
+ import { type ExecutorStopReceiptBodyV2, type ExecutorStopReceiptV2 } from './executorStopReceiptV2.js';
4
5
  import { type HardwareKeyCapability, type HardwareKeyRecord } from './deviceKeyHardware.js';
5
6
  /**
6
7
  * The `cred_envelope.read.decrypt_failed` hint for the device PRIVATE key
@@ -244,6 +245,13 @@ export declare function signServerRequest(opts: {
244
245
  * server treats as an unproven stop rather than as a failure of the session.
245
246
  */
246
247
  export declare function signExecutorStopReceiptWithDeviceKey(body: ExecutorStopReceiptBody): Promise<ExecutorStopReceipt | null>;
248
+ /**
249
+ * Sign a parent-witnessed stop receipt (OSK-20777, docs/architecture/independent-stop-witness-2026-11-02.md)
250
+ * with the device key. Same contract as `signExecutorStopReceiptWithDeviceKey`: null when device identity is not
251
+ * active or the key cannot sign right now, never throws, and a failed sign emits a telemetry event so the caller
252
+ * sends the response without a receipt, which the server treats as an unproven stop.
253
+ */
254
+ export declare function signExecutorStopReceiptV2WithDeviceKey(body: ExecutorStopReceiptBodyV2): Promise<ExecutorStopReceiptV2 | null>;
247
255
  /** @internal Test seams — file path resolvers. */
248
256
  export declare function __publicKeyPathForTest(profile: string): string;
249
257
  export declare function __privateKeyPathForTest(profile: string): string;
@@ -35,6 +35,7 @@ import lockfile from 'proper-lockfile';
35
35
  import { generateDeviceKeyPair, isDevicePublicJwk, jwkThumbprint, signProofWith, } from './deviceKey.js';
36
36
  import { softwareEd25519Handle } from './deviceKeyHandle.js';
37
37
  import { signExecutorStopReceipt, } from './executorStopReceipt.js';
38
+ import { signExecutorStopReceiptV2, } from './executorStopReceiptV2.js';
38
39
  import { createHardwareDeviceKey, hardwareDeviceKeyHandle, parseHardwareKeyRecord, probeHardwareDeviceKey, resolveHardwareDeviceKeyHelper, serializeHardwareKeyRecord, HardwareDeviceKeyError, } from './deviceKeyHardware.js';
39
40
  import { hasCredEnvelopePathConflict, isCredEnvelopeActive, maybeDecryptOnRead, splitKeyConvergencePolicy, wrapIfActiveOrPassthrough, } from './credentialEnvelopeBridge.js';
40
41
  import { consolidateProfileState, profileStateFilePathsToClear, profileStateDir, resolveProfileStateDir, RETIRED_COPY_SUFFIX, } from './profileStateDir.js';
@@ -1161,6 +1162,32 @@ export async function signExecutorStopReceiptWithDeviceKey(body) {
1161
1162
  return null;
1162
1163
  }
1163
1164
  }
1165
+ /**
1166
+ * Sign a parent-witnessed stop receipt (OSK-20777, docs/architecture/independent-stop-witness-2026-11-02.md)
1167
+ * with the device key. Same contract as `signExecutorStopReceiptWithDeviceKey`: null when device identity is not
1168
+ * active or the key cannot sign right now, never throws, and a failed sign emits a telemetry event so the caller
1169
+ * sends the response without a receipt, which the server treats as an unproven stop.
1170
+ */
1171
+ export async function signExecutorStopReceiptV2WithDeviceKey(body) {
1172
+ reloadIfRecovered();
1173
+ const state = _state;
1174
+ if (state.kind !== 'active')
1175
+ return null;
1176
+ try {
1177
+ return await signExecutorStopReceiptV2(state.key, body);
1178
+ }
1179
+ catch (err) {
1180
+ emit('sign_failed', false, {
1181
+ profile: state.profile,
1182
+ thumbprint: state.key.thumbprint,
1183
+ custody: state.key.custody,
1184
+ method: 'executor_stop_receipt_v2',
1185
+ ...(err instanceof HardwareDeviceKeyError ? { hardwareFailure: err.code } : {}),
1186
+ message: err?.message ?? 'unknown',
1187
+ });
1188
+ return null;
1189
+ }
1190
+ }
1164
1191
  /** @internal Test seams — file path resolvers. */
1165
1192
  export function __publicKeyPathForTest(profile) {
1166
1193
  return publicKeyPath(profile);