@skrr-ai/cli 0.1.48 → 0.1.50

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 (117) hide show
  1. package/README.md +5 -4
  2. package/dist/base-command.js +16 -4
  3. package/dist/commands/agent-worker.d.ts +12 -0
  4. package/dist/commands/agent-worker.js +140 -0
  5. package/dist/commands/agents/create.js +14 -7
  6. package/dist/commands/agents/update.js +11 -5
  7. package/dist/commands/code/index.d.ts +1 -0
  8. package/dist/commands/code/index.js +49 -5
  9. package/dist/commands/code/run.js +5 -1
  10. package/dist/commands/commitments/cycles.d.ts +19 -0
  11. package/dist/commands/commitments/cycles.js +46 -0
  12. package/dist/commands/commitments/effective-policy.js +26 -1
  13. package/dist/commands/commitments/explain.d.ts +17 -0
  14. package/dist/commands/commitments/explain.js +40 -0
  15. package/dist/commands/goals/create.d.ts +1 -0
  16. package/dist/commands/goals/create.js +22 -0
  17. package/dist/commands/logout.js +12 -1
  18. package/dist/commands/machines/dedicated/index.js +1 -1
  19. package/dist/commands/machines/dedicated/sign-in.js +4 -1
  20. package/dist/commands/machines/dedicated/terminal/kill.d.ts +21 -0
  21. package/dist/commands/machines/dedicated/terminal/kill.js +55 -0
  22. package/dist/commands/machines/dedicated/terminal/ls.d.ts +22 -0
  23. package/dist/commands/machines/dedicated/terminal/ls.js +70 -0
  24. package/dist/commands/machines/dedicated/terminal/rename.d.ts +23 -0
  25. package/dist/commands/machines/dedicated/terminal/rename.js +64 -0
  26. package/dist/commands/machines/dedicated/terminal.d.ts +9 -0
  27. package/dist/commands/machines/dedicated/terminal.js +27 -2
  28. package/dist/commands/machines/hosted/connect.js +2 -2
  29. package/dist/commands/machines/hosted/destroy.js +1 -1
  30. package/dist/commands/machines/hosted/exec.js +1 -1
  31. package/dist/commands/machines/hosted/list.js +1 -1
  32. package/dist/commands/machines/hosted/pause.js +1 -1
  33. package/dist/commands/machines/hosted/pull.js +1 -1
  34. package/dist/commands/machines/hosted/resume.js +1 -1
  35. package/dist/commands/machines/hosted/start.js +2 -2
  36. package/dist/commands/machines/hosted/status.js +2 -1
  37. package/dist/commands/tasks/create.js +1 -0
  38. package/dist/commands/tasks/list.js +1 -0
  39. package/dist/commands/tasks/update.js +1 -0
  40. package/dist/lib/agent-config.d.ts +2 -0
  41. package/dist/lib/agent-config.js +3 -1
  42. package/dist/lib/api-fetch.js +19 -0
  43. package/dist/lib/auth-storage.d.ts +14 -0
  44. package/dist/lib/auth-storage.js +14 -0
  45. package/dist/lib/commitments.d.ts +17 -2
  46. package/dist/lib/commitments.js +114 -0
  47. package/dist/lib/daemon-installer.d.ts +6 -5
  48. package/dist/lib/daemon-installer.js +4 -17
  49. package/dist/lib/daemonBroker.d.ts +120 -31
  50. package/dist/lib/daemonBroker.js +313 -20
  51. package/dist/lib/dedicated-lease-command.d.ts +14 -0
  52. package/dist/lib/dedicated-lease-command.js +30 -1
  53. package/dist/lib/dedicated-machines.js +8 -25
  54. package/dist/lib/dedicated-service-command.d.ts +11 -3
  55. package/dist/lib/dedicated-service-command.js +20 -3
  56. package/dist/lib/dedicated-service.d.ts +46 -0
  57. package/dist/lib/dedicated-service.js +85 -7
  58. package/dist/lib/dedicated-terminal.d.ts +21 -0
  59. package/dist/lib/dedicated-terminal.js +104 -9
  60. package/dist/lib/first-party-harness-broker.d.ts +10 -0
  61. package/dist/lib/first-party-harness-broker.js +9 -0
  62. package/dist/lib/first-party-harness-doctor.js +41 -1
  63. package/dist/lib/first-party-harness-managed.d.ts +4 -3
  64. package/dist/lib/first-party-harness-project-trust.d.ts +125 -0
  65. package/dist/lib/first-party-harness-project-trust.js +364 -0
  66. package/dist/lib/first-party-harness.d.ts +9 -2
  67. package/dist/lib/first-party-harness.js +6 -5
  68. package/dist/lib/hosted-machines.d.ts +10 -1
  69. package/dist/lib/hosted-machines.js +36 -2
  70. package/dist/lib/login.js +16 -0
  71. package/dist/lib/machine-spend-cap.d.ts +23 -0
  72. package/dist/lib/machine-spend-cap.js +68 -0
  73. package/dist/lib/node-adapter.js +15 -3
  74. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/cliHandoffWire.d.ts +90 -0
  75. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/cliHandoffWire.js +113 -0
  76. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/credentialSession.d.ts +47 -0
  77. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/credentialSession.js +69 -0
  78. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/daemonToolApproval.d.ts +109 -0
  79. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/daemonToolApproval.js +171 -0
  80. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/firstPartyHarness.d.ts +1 -1
  81. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/firstPartyHarness.js +1 -1
  82. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/index.d.ts +1 -1
  83. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/index.js +4 -2
  84. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/messages.d.ts +8 -3
  85. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/messages.js +9 -4
  86. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/refresh.js +8 -9
  87. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/refreshClassification.d.ts +6 -0
  88. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/refreshClassification.js +32 -9
  89. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/releaseManifest.d.ts +38 -0
  90. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/releaseManifest.js +66 -1
  91. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/sessionPermissionAuthority.d.ts +81 -0
  92. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/sessionPermissionAuthority.js +87 -0
  93. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/types.d.ts +6 -1
  94. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/cliHandoffWire.d.ts +90 -0
  95. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/cliHandoffWire.js +105 -0
  96. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/credentialSession.d.ts +47 -0
  97. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/credentialSession.js +66 -0
  98. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/daemonToolApproval.d.ts +109 -0
  99. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/daemonToolApproval.js +164 -0
  100. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/firstPartyHarness.d.ts +1 -1
  101. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/firstPartyHarness.js +1 -1
  102. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/index.d.ts +1 -1
  103. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/index.js +1 -1
  104. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/messages.d.ts +8 -3
  105. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/messages.js +9 -4
  106. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/refresh.js +8 -9
  107. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/refreshClassification.d.ts +6 -0
  108. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/refreshClassification.js +31 -9
  109. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/releaseManifest.d.ts +38 -0
  110. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/releaseManifest.js +64 -0
  111. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/sessionPermissionAuthority.d.ts +81 -0
  112. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/sessionPermissionAuthority.js +80 -0
  113. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/types.d.ts +6 -1
  114. package/dist/node_modules/@skrr-ai/auth-core/package.json +41 -1
  115. package/dist/node_modules/@skrr-ai/data-provider/index.js +3413 -3343
  116. package/oclif.manifest.json +8930 -8466
  117. package/package.json +4 -1
@@ -0,0 +1,164 @@
1
+ import { createHash } from 'node:crypto';
2
+ /**
3
+ * Server-attested tool approval (OSK-11975 follow-up to the `manual` mode
4
+ * refusal on `daemon:tool:request`).
5
+ *
6
+ * A daemon category in `manual` mode means "a PERSON approves each call". On
7
+ * the harness-session path the daemon asks through the permission bridge; on
8
+ * the daemon-tool path a cloud agent's call used to be refused outright,
9
+ * because the request carried no approval and there was no channel back to a
10
+ * person. The attested-approval protocol closes that gap without weakening
11
+ * the guarantee:
12
+ *
13
+ * 1. The daemon announces `daemon_tool_attested_approval_v1` and its
14
+ * resolved per-category posture (`toolPermissionModes`) at register time.
15
+ * 2. Before proxying a call, the server reads the announced posture for the
16
+ * tool's category. `manual` means it must ask first — through the same
17
+ * permission surface (`canUseTool` → `permission:request`) an in-process
18
+ * SDK turn would have used — and only then dispatch, carrying an
19
+ * `attestedApproval` object on the request.
20
+ * 3. The daemon verifies the attestation's SHAPE and BINDING — it is bound
21
+ * to this exact (toolUseId, toolName, toolInput digest) and expires
22
+ * quickly — and allows the call. A missing or malformed attestation gets
23
+ * the same named refusal as before.
24
+ *
25
+ * What the daemon verifies is the binding, not the server's honesty: the
26
+ * request already arrives over the daemon's authenticated server channel, so
27
+ * the field IS the attestation. What the binding buys is that the model —
28
+ * which authors `toolInput` — cannot mint an approval, and an approval for
29
+ * one call cannot be replayed onto another.
30
+ */
31
+ /** Announced by a daemon that honours `attestedApproval` on daemon:tool:request. */
32
+ export const DAEMON_TOOL_ATTESTED_APPROVAL_CAPABILITY = 'daemon_tool_attested_approval_v1';
33
+ /**
34
+ * Announced by a daemon that honours `toolPosture: 'read_only'` on
35
+ * daemon:tool:request — the daemon-tool-path expression of the wire `plan`
36
+ * session mode: reads run, every mutating category is refused with a named
37
+ * reason. Carries INTENT like `browserPolicy: 'read_only'` — the daemon owns
38
+ * what read-only means, so the server cannot widen the fence by shipping a
39
+ * wider value.
40
+ */
41
+ export const DAEMON_TOOL_READ_ONLY_CAPABILITY = 'daemon_tool_read_only_v1';
42
+ export const DAEMON_TOOL_CATEGORIES = [
43
+ 'read',
44
+ 'write',
45
+ 'bash',
46
+ 'browser',
47
+ 'claude_session',
48
+ 'native_ui',
49
+ ];
50
+ /** Map a tool name to its category. Unknown tools take the restrictive answer. */
51
+ export function categoryForDaemonTool(toolName) {
52
+ switch (String(toolName || '').toLowerCase()) {
53
+ case 'read':
54
+ case 'glob':
55
+ case 'grep':
56
+ case 'filetransferread':
57
+ return 'read';
58
+ case 'write':
59
+ case 'edit':
60
+ case 'multiedit':
61
+ case 'apply_patch':
62
+ case 'filetransferwrite':
63
+ return 'write';
64
+ // Reading or stopping a background command is part of running it.
65
+ case 'bash':
66
+ case 'taskoutput':
67
+ case 'taskstop':
68
+ return 'bash';
69
+ case 'browser':
70
+ return 'browser';
71
+ case 'native':
72
+ return 'native_ui';
73
+ case 'claude_session':
74
+ case 'claude-session':
75
+ return 'claude_session';
76
+ default:
77
+ return 'write';
78
+ }
79
+ }
80
+ // ---------------------------------------------------------------------------
81
+ // Attested approval
82
+ // ---------------------------------------------------------------------------
83
+ /**
84
+ * How long an attestation stays valid. Short: it answers ONE person, about
85
+ * THIS call, moments ago — it is not a standing grant. The server asks and
86
+ * dispatches back-to-back, so the window only has to outlive publish latency.
87
+ */
88
+ export const ATTESTED_TOOL_APPROVAL_TTL_MS = 60 * 1000;
89
+ /**
90
+ * Deterministic serialization for the input digest: objects sort keys
91
+ * recursively, arrays keep order, non-JSON values normalize the way
92
+ * `JSON.stringify` would emit them (undefined/functions in objects drop, in
93
+ * arrays become null). Both runtimes must digest the SAME bytes — the server
94
+ * mints and the daemon verifies — so this lives here, once.
95
+ */
96
+ function canonicalJson(value) {
97
+ if (value === null || typeof value !== 'object') {
98
+ if (value === undefined || typeof value === 'function' || typeof value === 'symbol') {
99
+ return 'null';
100
+ }
101
+ return JSON.stringify(value);
102
+ }
103
+ if (Array.isArray(value)) {
104
+ return `[${value.map((entry) => canonicalJson(entry)).join(',')}]`;
105
+ }
106
+ const record = value;
107
+ const keys = Object.keys(record).filter((key) => record[key] !== undefined &&
108
+ typeof record[key] !== 'function' &&
109
+ typeof record[key] !== 'symbol');
110
+ keys.sort();
111
+ return `{${keys.map((key) => `${JSON.stringify(key)}:${canonicalJson(record[key])}`).join(',')}}`;
112
+ }
113
+ /** The digest both sides compute over `toolInput`. */
114
+ export function canonicalToolInputDigest(toolInput) {
115
+ return createHash('sha256')
116
+ .update(canonicalJson(toolInput ?? {}))
117
+ .digest('hex');
118
+ }
119
+ /** Server side: mint the attestation after a person approved THIS call. */
120
+ export function mintAttestedToolApproval(args) {
121
+ const now = args.now ?? Date.now();
122
+ return {
123
+ v: 1,
124
+ toolUseId: args.toolUseId,
125
+ toolName: args.toolName,
126
+ inputSha256: canonicalToolInputDigest(args.toolInput),
127
+ decidedBy: 'user',
128
+ issuedAt: now,
129
+ expiresAt: now + (args.ttlMs ?? ATTESTED_TOOL_APPROVAL_TTL_MS),
130
+ };
131
+ }
132
+ /**
133
+ * Daemon side: verify an attestation against the call it claims to approve.
134
+ * Untrusted wire input — every field is checked, and any mismatch is a plain
135
+ * "no approval", never a partial credit. `reason` is for daemon logs; the
136
+ * refusal text stays generic so a probing caller learns nothing new.
137
+ */
138
+ export function verifyAttestedToolApproval(approval, call) {
139
+ if (approval === undefined || approval === null)
140
+ return { ok: false, reason: 'absent' };
141
+ if (typeof approval !== 'object' || Array.isArray(approval)) {
142
+ return { ok: false, reason: 'malformed' };
143
+ }
144
+ const a = approval;
145
+ if (a.v !== 1 ||
146
+ typeof a.toolUseId !== 'string' ||
147
+ typeof a.toolName !== 'string' ||
148
+ typeof a.inputSha256 !== 'string' ||
149
+ a.decidedBy !== 'user' ||
150
+ typeof a.issuedAt !== 'number' ||
151
+ typeof a.expiresAt !== 'number') {
152
+ return { ok: false, reason: 'malformed' };
153
+ }
154
+ const now = call.now ?? Date.now();
155
+ if (a.expiresAt <= now || a.issuedAt > now + 30_000) {
156
+ return { ok: false, reason: 'expired' };
157
+ }
158
+ if (a.toolUseId !== call.toolUseId ||
159
+ a.toolName.toLowerCase() !== String(call.toolName).toLowerCase() ||
160
+ a.inputSha256 !== canonicalToolInputDigest(call.toolInput)) {
161
+ return { ok: false, reason: 'binding' };
162
+ }
163
+ return { ok: true };
164
+ }
@@ -223,7 +223,7 @@ export declare function firstPartyHarnessManifestFile(provider?: string): string
223
223
  * The update feed ORIGIN. Not a product name, and not moved by this identity:
224
224
  * a feed host sits inside signed manifests (naming map §2 "Update feed").
225
225
  */
226
- export declare const FIRST_PARTY_HARNESS_FEED_ORIGIN = "https://updates.oversky.ai";
226
+ export declare const FIRST_PARTY_HARNESS_FEED_ORIGIN = "https://updates.skrr.ai";
227
227
  /** Object-key prefix for one spelling's feed, e.g. `skrr-code/`. */
228
228
  export declare function firstPartyHarnessFeedPrefix(provider?: string): string;
229
229
  /**
@@ -304,7 +304,7 @@ export function firstPartyHarnessManifestFile(provider = FIRST_PARTY_HARNESS.pro
304
304
  * The update feed ORIGIN. Not a product name, and not moved by this identity:
305
305
  * a feed host sits inside signed manifests (naming map §2 "Update feed").
306
306
  */
307
- export const FIRST_PARTY_HARNESS_FEED_ORIGIN = 'https://updates.oversky.ai';
307
+ export const FIRST_PARTY_HARNESS_FEED_ORIGIN = 'https://updates.skrr.ai';
308
308
  /** Object-key prefix for one spelling's feed, e.g. `skrr-code/`. */
309
309
  export function firstPartyHarnessFeedPrefix(provider = FIRST_PARTY_HARNESS.provider) {
310
310
  return `${provider}/`;
@@ -40,6 +40,6 @@ export * from './firstPartyHarness.js';
40
40
  export { FIRST_PARTY_HARNESS_PREVIOUS_SUFFIX, FIRST_PARTY_HARNESS_PROVENANCE_SUFFIX, firstPartyHarnessBinDir, firstPartyHarnessHomeDir, firstPartyHarnessInstalledBinaryPath, linkFirstPartyHarnessAliases, migrateFirstPartyHarnessHome, type FirstPartyHarnessHomeFs, type FirstPartyHarnessHomeMigration, } from './firstPartyHarnessHome.js';
41
41
  export { DEFAULT_FIRST_PARTY_HARNESS_CHANNEL, FIRST_PARTY_HARNESS_CHANNELS, firstPartyHarnessChannelPrefix, firstPartyHarnessFeedBase, firstPartyHarnessFeedCandidates, isFirstPartyHarnessChannel, resolveChannelManifestUrl, resolveFirstPartyHarnessChannel, type FirstPartyHarnessChannel, type FirstPartyHarnessFeedCandidate, } from './firstPartyHarnessChannels.js';
42
42
  export { OVERSKY_RELEASE_PUBLIC_KEYS, type ReleaseKey } from './releaseKeys.js';
43
- export { MAX_SIGS, buildArtifactMessage, buildManifestMessage, getDeltaFor, verifyArtifact, verifyManifest, type DaemonVersionManifest, type DeltaDescriptor, type ManifestSignature, type PlatformArtifact, type VerifyResult, } from './releaseManifest.js';
43
+ 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';
44
44
  export { resolveConfigRoot, configRootPath, isConfigRootOverridden } from './configRoot.js';
45
45
  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';
@@ -161,7 +161,7 @@ export { DEFAULT_FIRST_PARTY_HARNESS_CHANNEL, FIRST_PARTY_HARNESS_CHANNELS, firs
161
161
  // same manifest against the same root. See releaseManifest.ts for why a mirror
162
162
  // would be the wrong shape here.
163
163
  export { OVERSKY_RELEASE_PUBLIC_KEYS } from './releaseKeys.js';
164
- export { MAX_SIGS, buildArtifactMessage, buildManifestMessage, getDeltaFor, verifyArtifact, verifyManifest, } from './releaseManifest.js';
164
+ export { MAX_SIGS, TRUSTED_FEED_ORIGINS, buildArtifactMessage, buildManifestMessage, getDeltaFor, isTrustedArtifactOrigin, verifyArtifact, verifyManifest, } from './releaseManifest.js';
165
165
  // The one definition of the skrr root, shared by `skrr` and `skrrd`. See the
166
166
  // module for why re-deriving it kept producing divergences.
167
167
  export { resolveConfigRoot, configRootPath, isConfigRootOverridden } from './configRoot.js';
@@ -1,4 +1,4 @@
1
- export type AuthFailureReason = 'REFRESH_INVALID' | 'REFRESH_REUSED' | 'REFRESH_EXPIRED' | 'SESSION_REVOKED' | 'TOKEN_EXPIRED' | 'TOKEN_INVALID' | 'UNKNOWN_401' | 'UNKNOWN';
1
+ export type AuthFailureReason = 'REFRESH_INVALID' | 'REFRESH_REUSED' | 'REFRESH_EXPIRED' | 'SESSION_REVOKED' | 'DEVICE_KEY_MISMATCH' | 'TOKEN_EXPIRED' | 'TOKEN_INVALID' | 'UNKNOWN_401' | 'UNKNOWN';
2
2
  /**
3
3
  * The command that recovers this process from a re-auth latch.
4
4
  *
@@ -11,8 +11,13 @@ export type AuthFailureReason = 'REFRESH_INVALID' | 'REFRESH_REUSED' | 'REFRESH_
11
11
  * something the other did not describe (OSK-10224).
12
12
  *
13
13
  * The binary is whatever the consumer registered with
14
- * `configureAuthCore({ binaryName })` — the binary the user actually typed —
15
- * and `--device` is added only when there is no TTY to open a browser from.
14
+ * `configureAuthCore({ binaryName })` — the binary the user actually typed.
15
+ *
16
+ * No flag. This used to append `--device` whenever stdout was not a TTY, which
17
+ * is always true for a daemon under launchd/systemd — and neither `skrrd login`
18
+ * nor `skrr login` has a `--device` option, so the one command the latch line
19
+ * named failed with `unknown option '--device'` (OSK-12056). Both logins already
20
+ * fall back to a paste-a-code arm when no browser can be opened.
16
21
  */
17
22
  export declare function reauthCommand(): string;
18
23
  export declare function formatReauthMessage(reason: AuthFailureReason | string): string;
@@ -12,6 +12,7 @@ const REASON_HUMAN = {
12
12
  REFRESH_REUSED: 'Your session was ended for security reasons (token replay detected).',
13
13
  REFRESH_EXPIRED: 'Your session has expired.',
14
14
  SESSION_REVOKED: 'Your session was ended (you signed out elsewhere or your password changed).',
15
+ DEVICE_KEY_MISMATCH: "This computer's device key no longer matches the one skrr registered for it, so its session cannot be renewed.",
15
16
  TOKEN_EXPIRED: 'Your access token has expired.',
16
17
  TOKEN_INVALID: 'Your saved credentials are no longer valid.',
17
18
  UNKNOWN_401: 'skrr needs you to sign in again.',
@@ -29,12 +30,16 @@ const REASON_HUMAN = {
29
30
  * something the other did not describe (OSK-10224).
30
31
  *
31
32
  * The binary is whatever the consumer registered with
32
- * `configureAuthCore({ binaryName })` — the binary the user actually typed —
33
- * and `--device` is added only when there is no TTY to open a browser from.
33
+ * `configureAuthCore({ binaryName })` — the binary the user actually typed.
34
+ *
35
+ * No flag. This used to append `--device` whenever stdout was not a TTY, which
36
+ * is always true for a daemon under launchd/systemd — and neither `skrrd login`
37
+ * nor `skrr login` has a `--device` option, so the one command the latch line
38
+ * named failed with `unknown option '--device'` (OSK-12056). Both logins already
39
+ * fall back to a paste-a-code arm when no browser can be opened.
34
40
  */
35
41
  export function reauthCommand() {
36
- const bin = getAuthBinaryName();
37
- return process.stdout.isTTY ? `${bin} login` : `${bin} login --device`;
42
+ return `${getAuthBinaryName()} login`;
38
43
  }
39
44
  export function formatReauthMessage(reason) {
40
45
  const norm = REASON_HUMAN[reason] || REASON_HUMAN.UNKNOWN;
@@ -25,6 +25,7 @@ import fs from 'node:fs';
25
25
  import path from 'node:path';
26
26
  import lockfile from 'proper-lockfile';
27
27
  import { getAuthLogger, getAuthConfigDir, emitAuthTelemetry, notifyResponseObserver, } from './runtime.js';
28
+ import { permanentReasonForRefreshCode } from './refreshClassification.js';
28
29
  import { PermanentAuthFailure, TransientAuthFailure, } from './types.js';
29
30
  /**
30
31
  * P1-6: Reduced from 30 s to 5 s.
@@ -804,14 +805,12 @@ async function doRefresh(serverUrl, currentRefreshToken, daemonId, options = {})
804
805
  catch {
805
806
  /* ignore */
806
807
  }
807
- const code = parsedBody.code;
808
- const permanent = [
809
- 'REFRESH_INVALID',
810
- 'REFRESH_REUSED',
811
- 'REFRESH_EXPIRED',
812
- 'SESSION_REVOKED',
813
- ];
814
- if (code && permanent.includes(code)) {
808
+ // The server's code, mapped through the one table the stateless classifier
809
+ // reads too — so a permanent refusal that is not spelled as a reason name
810
+ // (DEVICE_PROOF_THUMBPRINT_MISMATCH) latches instead of riding the
811
+ // unknown-401 budget forever (OSK-12056).
812
+ const code = permanentReasonForRefreshCode(parsedBody.code);
813
+ if (code) {
815
814
  // A KNOWN credential-death code is genuinely permanent — latch
816
815
  // immediately, exactly as before. It is NOT routed through the
817
816
  // unknown-401 budget.
@@ -841,7 +840,7 @@ async function doRefresh(serverUrl, currentRefreshToken, daemonId, options = {})
841
840
  }
842
841
  // Unknown-shape 401 — unknown code, missing code, or unparseable body.
843
842
  // By construction this is NOT a daemon's actual refresh-family burn
844
- // (those arrive as one of the four KNOWN codes above); it most likely
843
+ // (those arrive as one of the KNOWN codes above); it most likely
845
844
  // came from infra OverSky does not fully control — a proxy/middleware
846
845
  // regression, a clock-skew replay rejection (DEVICE_PROOF_REPLAYED),
847
846
  // or a half-rolled-out server route.
@@ -36,6 +36,12 @@ export interface ClassifiedRefreshFailure {
36
36
  failure: PermanentAuthFailure | TransientAuthFailure;
37
37
  }
38
38
  export type ClassifiedRefreshResult = ClassifiedRefreshSuccess | ClassifiedRefreshFailure;
39
+ /**
40
+ * The permanent reason a 401 refresh refusal's `code` names, or `null` when the
41
+ * code is missing or unrecognised (an unknown-shape 401). The ONE mapping both
42
+ * this classifier and the daemon's `refresh.ts` read.
43
+ */
44
+ export declare function permanentReasonForRefreshCode(code: string | undefined | null): PermanentAuthReason | null;
39
45
  /**
40
46
  * Classify an HTTP response from /api/auth/refresh (or /api/daemons/token/refresh)
41
47
  * into a discriminated union of success or failure.
@@ -33,6 +33,33 @@ const PERMANENT_CODE_SET = new Set([
33
33
  'REFRESH_EXPIRED',
34
34
  'SESSION_REVOKED',
35
35
  ]);
36
+ /**
37
+ * Server refusal codes that are permanent but are not themselves reason names.
38
+ *
39
+ * `DEVICE_PROOF_THUMBPRINT_MISMATCH` (`daemonRefreshTokens.verifyDeviceProofPinForRow`)
40
+ * means the proof was signed by a key other than the one enrolled on the daemon's
41
+ * row. Every retry is signed by the same key, so it can never succeed — but
42
+ * because it was not in the set above it fell through to the unknown-401 path,
43
+ * where a daemon retrying on a five-minute cadence never exhausted its budget:
44
+ * one laptop logged 741 "transient, retrying" refusals over four days, and the
45
+ * reason it eventually surfaced was `UNKNOWN_401` (OSK-12056).
46
+ */
47
+ const PERMANENT_CODE_ALIASES = {
48
+ REFRESH_MISSING: 'REFRESH_INVALID',
49
+ DEVICE_PROOF_THUMBPRINT_MISMATCH: 'DEVICE_KEY_MISMATCH',
50
+ };
51
+ /**
52
+ * The permanent reason a 401 refresh refusal's `code` names, or `null` when the
53
+ * code is missing or unrecognised (an unknown-shape 401). The ONE mapping both
54
+ * this classifier and the daemon's `refresh.ts` read.
55
+ */
56
+ export function permanentReasonForRefreshCode(code) {
57
+ if (!code)
58
+ return null;
59
+ if (PERMANENT_CODE_SET.has(code))
60
+ return code;
61
+ return PERMANENT_CODE_ALIASES[code] ?? null;
62
+ }
36
63
  /**
37
64
  * Classify an HTTP response from /api/auth/refresh (or /api/daemons/token/refresh)
38
65
  * into a discriminated union of success or failure.
@@ -65,17 +92,12 @@ export function classifyRefreshResponse(status, body) {
65
92
  }
66
93
  // 401 — auth failure; check for known permanent code
67
94
  if (status === 401) {
68
- if (body?.code === 'REFRESH_MISSING') {
69
- return {
70
- kind: 'failure',
71
- failure: new PermanentAuthFailure('REFRESH_INVALID', body.message ?? 'Refresh token missing'),
72
- };
73
- }
74
- const code = body?.code;
75
- if (code && PERMANENT_CODE_SET.has(code)) {
95
+ const reason = permanentReasonForRefreshCode(body?.code);
96
+ if (reason) {
97
+ const fallback = body?.code === 'REFRESH_MISSING' ? 'Refresh token missing' : reason;
76
98
  return {
77
99
  kind: 'failure',
78
- failure: new PermanentAuthFailure(code, body?.message ?? code),
100
+ failure: new PermanentAuthFailure(reason, body?.message ?? fallback),
79
101
  };
80
102
  }
81
103
  // Unknown-shape 401 (no code, or a code we don't recognise). This is NOT a
@@ -159,3 +159,41 @@ export declare function verifyManifest(manifest: DaemonVersionManifest, keys?: r
159
159
  * against the signed `artifact.sha256`, not from this metadata).
160
160
  */
161
161
  export declare function getDeltaFor(artifact: PlatformArtifact, fromVersion: string): DeltaDescriptor | null;
162
+ /**
163
+ * Origins an artifact may be served from, beyond the feed base this run used.
164
+ *
165
+ * WHY A SET AND NOT THE ONE ORIGIN
166
+ * --------------------------------
167
+ * The pin used to require the artifact origin to EQUAL the feed base's
168
+ * origin. That is correct with one host and unsatisfiable with two, which the
169
+ * skrr rename creates:
170
+ *
171
+ * - a shipped daemon/CLI has `updates.oversky.ai` compiled in, so a manifest
172
+ * advertising skrr.ai artifacts is refused and it can never self-update
173
+ * again — including to the build that would have fixed it;
174
+ * - a new build shipping `updates.skrr.ai` refuses the SAME manifest for the
175
+ * mirror-image reason.
176
+ *
177
+ * One manifest of absolute URLs therefore cannot serve both, and the update
178
+ * path is the one thing that must not break: a client that cannot update
179
+ * cannot be repaired remotely.
180
+ *
181
+ * Widening to a small, closed set of origins we publish keeps the property the
182
+ * pin exists for: with keys pinned the ed25519 signature already binds the
183
+ * URL, and this is defence-in-depth for when verification is disabled —
184
+ * stopping a manifest-integrity failure from redirecting a download to an
185
+ * ARBITRARY origin serving a hash-matching payload. An attacker gains nothing
186
+ * from a second origin that is also ours.
187
+ *
188
+ * Both entries are removed down to one when no shipped client uses the old
189
+ * host, per the add -> verify -> remove ordering.
190
+ */
191
+ export declare const TRUSTED_FEED_ORIGINS: readonly string[];
192
+ /**
193
+ * True when `candidate` may serve an artifact for a feed rooted at `feedBase`.
194
+ *
195
+ * The feed base's own origin always passes, so an override
196
+ * (OVERSKY_DAEMON_UPDATE_FEED_BASE, a canary, a test server) keeps working
197
+ * without being listed here.
198
+ */
199
+ export declare function isTrustedArtifactOrigin(candidate: string, feedBase: string): boolean;
@@ -225,3 +225,67 @@ export function getDeltaFor(artifact, fromVersion) {
225
225
  }
226
226
  return d;
227
227
  }
228
+ // ---------------------------------------------------------------------------
229
+ // Trusted artifact origins
230
+ // ---------------------------------------------------------------------------
231
+ /**
232
+ * Origins an artifact may be served from, beyond the feed base this run used.
233
+ *
234
+ * WHY A SET AND NOT THE ONE ORIGIN
235
+ * --------------------------------
236
+ * The pin used to require the artifact origin to EQUAL the feed base's
237
+ * origin. That is correct with one host and unsatisfiable with two, which the
238
+ * skrr rename creates:
239
+ *
240
+ * - a shipped daemon/CLI has `updates.oversky.ai` compiled in, so a manifest
241
+ * advertising skrr.ai artifacts is refused and it can never self-update
242
+ * again — including to the build that would have fixed it;
243
+ * - a new build shipping `updates.skrr.ai` refuses the SAME manifest for the
244
+ * mirror-image reason.
245
+ *
246
+ * One manifest of absolute URLs therefore cannot serve both, and the update
247
+ * path is the one thing that must not break: a client that cannot update
248
+ * cannot be repaired remotely.
249
+ *
250
+ * Widening to a small, closed set of origins we publish keeps the property the
251
+ * pin exists for: with keys pinned the ed25519 signature already binds the
252
+ * URL, and this is defence-in-depth for when verification is disabled —
253
+ * stopping a manifest-integrity failure from redirecting a download to an
254
+ * ARBITRARY origin serving a hash-matching payload. An attacker gains nothing
255
+ * from a second origin that is also ours.
256
+ *
257
+ * Both entries are removed down to one when no shipped client uses the old
258
+ * host, per the add -> verify -> remove ordering.
259
+ */
260
+ export const TRUSTED_FEED_ORIGINS = [
261
+ 'https://updates.oversky.ai',
262
+ 'https://updates.skrr.ai',
263
+ ];
264
+ /**
265
+ * True when `candidate` may serve an artifact for a feed rooted at `feedBase`.
266
+ *
267
+ * The feed base's own origin always passes, so an override
268
+ * (OVERSKY_DAEMON_UPDATE_FEED_BASE, a canary, a test server) keeps working
269
+ * without being listed here.
270
+ */
271
+ export function isTrustedArtifactOrigin(candidate, feedBase) {
272
+ let feedOrigin;
273
+ try {
274
+ feedOrigin = new URL(feedBase).origin;
275
+ }
276
+ catch {
277
+ return false;
278
+ }
279
+ // Callers hand over either a bare origin (the daemon's self-updater) or a
280
+ // full artifact URL (the CLI installer) — both spell the same check.
281
+ let candidateOrigin = candidate;
282
+ try {
283
+ candidateOrigin = new URL(candidate).origin;
284
+ }
285
+ catch {
286
+ /* not a URL — compare raw; it will not match anything */
287
+ }
288
+ if (candidateOrigin === feedOrigin)
289
+ return true;
290
+ return TRUSTED_FEED_ORIGINS.includes(candidateOrigin);
291
+ }
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Session permission authority — the ONE rule that decides whether a session's
3
+ * execution contract governs the run's permissions, shared by the server and
4
+ * the daemon (OSK-11975 introduced it; it was implemented twice — the server
5
+ * read `kind !== 'commitment'`, the daemon read the `permissionSource` marker —
6
+ * which is exactly how a new contract kind or a new source value would drift
7
+ * them apart).
8
+ *
9
+ * The wire model:
10
+ *
11
+ * - The contract is closed (`hasOnlyKeys` on the daemon), so "whose
12
+ * permissions govern" can never ride INSIDE it. It is a top-level session
13
+ * field: `permissionSource`.
14
+ * - `'agent'` means the Agent's own configured permission mode, tool policy,
15
+ * Grants, session env, MCP servers and machine consent govern the run,
16
+ * exactly as for an unattended Task of the same Agent. Today only a
17
+ * `commitment` contract may carry it.
18
+ * - A `commitment` contract WITHOUT the marker (an older server mid-deploy)
19
+ * still governs permissions — the marker is the version signal, so its
20
+ * absence must keep the legacy fence, not silently lift it.
21
+ * - `task_delivery` contracts always govern, marker or not.
22
+ *
23
+ * Server vs daemon asymmetry, on purpose: the server STAMPS the marker
24
+ * (`permissionSourceForContract`), so on its own side the predicate reduces to
25
+ * "a commitment never governs" — `contractGovernsPermissions(c,
26
+ * permissionSourceForContract(c))` is exactly `kind !== 'commitment'`. The
27
+ * daemon reads the marker it received, because it cannot distinguish "new
28
+ * server, agent permissions" from "old server, contract fence" any other way.
29
+ * Both call the same function; only the input differs.
30
+ */
31
+ /** The wire vocabulary for `permissionSource`. Top-level session field. */
32
+ export declare const SESSION_PERMISSION_SOURCES: readonly ["agent"];
33
+ export type SessionPermissionSource = (typeof SESSION_PERMISSION_SOURCES)[number];
34
+ /**
35
+ * The daemon capability that proves a build honours `permissionSource`. The
36
+ * server announces it in preflight and refuses to dispatch a Commitment Run to
37
+ * a daemon without it (`COMMITMENT_AGENT_PERMISSIONS_RUNTIME_UNSUPPORTED`), so
38
+ * the marker never reaches a daemon that would ignore it.
39
+ */
40
+ export declare const COMMITMENT_AGENT_PERMISSIONS_CAPABILITY = "commitment_execution_contract_v2_agent_permissions";
41
+ /**
42
+ * The minimal contract shape this rule reads. The predicate only ever needs
43
+ * `kind` — keeping the input structural means this module never imports the
44
+ * full `CommitmentExecutionContract` type, which lives daemon-side
45
+ * (`daemon/src/commitment-execution-contract.ts`) and server-side in the
46
+ * commitment services.
47
+ */
48
+ export type PermissionContractKind = {
49
+ kind?: unknown;
50
+ } | null | undefined;
51
+ /**
52
+ * Untrusted wire input: anything but an exact vocabulary literal reads as
53
+ * absent. Never widen by coercion — an unrecognized future value must degrade
54
+ * to "contract governs", the conservative answer.
55
+ */
56
+ export declare function normalizeSessionPermissionSource(value: unknown): SessionPermissionSource | undefined;
57
+ /**
58
+ * What the server stamps on the wire for this contract. A `commitment`
59
+ * contract no longer carries permissions (OSK-11975); every other contract
60
+ * kind keeps its own authority and stamps nothing.
61
+ */
62
+ export declare function permissionSourceForContract(contract: PermissionContractKind): SessionPermissionSource | undefined;
63
+ /**
64
+ * Whether the contract is the run's PERMISSION authority — the single place
65
+ * this rule lives.
66
+ *
67
+ * True for a non-commitment contract regardless of marker, and for a
68
+ * commitment whose server did not declare agent permissions. False for no
69
+ * contract at all, and for a commitment carrying `permissionSource: 'agent'`,
70
+ * which then follows the Agent's own permissions exactly as a Task does while
71
+ * the contract keeps its non-permission roles (normalized shape, ephemeral
72
+ * worktree, result validation, `GIT_OPTIONAL_LOCKS`, provider restriction).
73
+ */
74
+ export declare function contractGovernsPermissions(contract: PermissionContractKind, permissionSource: unknown): boolean;
75
+ /**
76
+ * The contract when it governs permissions, else `undefined` — for the sites
77
+ * that used `executionContract` as "is this run permission-fenced".
78
+ */
79
+ export declare function permissionGoverningContract<T extends {
80
+ kind?: unknown;
81
+ }>(contract: T | null | undefined, permissionSource: unknown): T | undefined;
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Session permission authority — the ONE rule that decides whether a session's
3
+ * execution contract governs the run's permissions, shared by the server and
4
+ * the daemon (OSK-11975 introduced it; it was implemented twice — the server
5
+ * read `kind !== 'commitment'`, the daemon read the `permissionSource` marker —
6
+ * which is exactly how a new contract kind or a new source value would drift
7
+ * them apart).
8
+ *
9
+ * The wire model:
10
+ *
11
+ * - The contract is closed (`hasOnlyKeys` on the daemon), so "whose
12
+ * permissions govern" can never ride INSIDE it. It is a top-level session
13
+ * field: `permissionSource`.
14
+ * - `'agent'` means the Agent's own configured permission mode, tool policy,
15
+ * Grants, session env, MCP servers and machine consent govern the run,
16
+ * exactly as for an unattended Task of the same Agent. Today only a
17
+ * `commitment` contract may carry it.
18
+ * - A `commitment` contract WITHOUT the marker (an older server mid-deploy)
19
+ * still governs permissions — the marker is the version signal, so its
20
+ * absence must keep the legacy fence, not silently lift it.
21
+ * - `task_delivery` contracts always govern, marker or not.
22
+ *
23
+ * Server vs daemon asymmetry, on purpose: the server STAMPS the marker
24
+ * (`permissionSourceForContract`), so on its own side the predicate reduces to
25
+ * "a commitment never governs" — `contractGovernsPermissions(c,
26
+ * permissionSourceForContract(c))` is exactly `kind !== 'commitment'`. The
27
+ * daemon reads the marker it received, because it cannot distinguish "new
28
+ * server, agent permissions" from "old server, contract fence" any other way.
29
+ * Both call the same function; only the input differs.
30
+ */
31
+ /** The wire vocabulary for `permissionSource`. Top-level session field. */
32
+ export const SESSION_PERMISSION_SOURCES = ['agent'];
33
+ /**
34
+ * The daemon capability that proves a build honours `permissionSource`. The
35
+ * server announces it in preflight and refuses to dispatch a Commitment Run to
36
+ * a daemon without it (`COMMITMENT_AGENT_PERMISSIONS_RUNTIME_UNSUPPORTED`), so
37
+ * the marker never reaches a daemon that would ignore it.
38
+ */
39
+ export const COMMITMENT_AGENT_PERMISSIONS_CAPABILITY = 'commitment_execution_contract_v2_agent_permissions';
40
+ /**
41
+ * Untrusted wire input: anything but an exact vocabulary literal reads as
42
+ * absent. Never widen by coercion — an unrecognized future value must degrade
43
+ * to "contract governs", the conservative answer.
44
+ */
45
+ export function normalizeSessionPermissionSource(value) {
46
+ return SESSION_PERMISSION_SOURCES.includes(value)
47
+ ? value
48
+ : undefined;
49
+ }
50
+ /**
51
+ * What the server stamps on the wire for this contract. A `commitment`
52
+ * contract no longer carries permissions (OSK-11975); every other contract
53
+ * kind keeps its own authority and stamps nothing.
54
+ */
55
+ export function permissionSourceForContract(contract) {
56
+ return contract?.kind === 'commitment' ? 'agent' : undefined;
57
+ }
58
+ /**
59
+ * Whether the contract is the run's PERMISSION authority — the single place
60
+ * this rule lives.
61
+ *
62
+ * True for a non-commitment contract regardless of marker, and for a
63
+ * commitment whose server did not declare agent permissions. False for no
64
+ * contract at all, and for a commitment carrying `permissionSource: 'agent'`,
65
+ * which then follows the Agent's own permissions exactly as a Task does while
66
+ * the contract keeps its non-permission roles (normalized shape, ephemeral
67
+ * worktree, result validation, `GIT_OPTIONAL_LOCKS`, provider restriction).
68
+ */
69
+ export function contractGovernsPermissions(contract, permissionSource) {
70
+ if (!contract)
71
+ return false;
72
+ return !(contract.kind === 'commitment' && normalizeSessionPermissionSource(permissionSource) === 'agent');
73
+ }
74
+ /**
75
+ * The contract when it governs permissions, else `undefined` — for the sites
76
+ * that used `executionContract` as "is this run permission-fenced".
77
+ */
78
+ export function permissionGoverningContract(contract, permissionSource) {
79
+ return contract && contractGovernsPermissions(contract, permissionSource) ? contract : undefined;
80
+ }