@astrale-os/cli 0.8.0-alpha.0 → 0.8.1-alpha.2

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 (317) hide show
  1. package/README.md +4 -1
  2. package/dist/astrale.js +62968 -41240
  3. package/dist/public/connect-core.js +55030 -0
  4. package/dist/public/keys/index.js +45631 -0
  5. package/dist/public/paths/index.js +43990 -0
  6. package/dist/types/admin/instance/model.d.ts +40 -0
  7. package/dist/types/connect-core.d.ts +22 -0
  8. package/dist/types/connection/auth.d.ts +33 -0
  9. package/dist/types/errors.d.ts +23 -0
  10. package/dist/types/identity/registry.d.ts +25 -0
  11. package/dist/types/keys/algorithm.d.ts +6 -0
  12. package/dist/types/keys/credential.d.ts +21 -0
  13. package/dist/types/keys/index.d.ts +4 -0
  14. package/dist/types/keys/pair.d.ts +34 -0
  15. package/dist/types/lib/admin-target.d.ts +74 -0
  16. package/dist/types/lib/ca-fetch.d.ts +2 -0
  17. package/dist/types/lib/config.d.ts +71 -0
  18. package/dist/types/lib/format.d.ts +1 -0
  19. package/dist/types/lib/idp-session.d.ts +33 -0
  20. package/dist/types/lib/idp.d.ts +397 -0
  21. package/dist/types/lib/instance-target.d.ts +36 -0
  22. package/dist/types/lib/instance.d.ts +186 -0
  23. package/dist/types/lib/log.d.ts +30 -0
  24. package/dist/types/lib/login-flow.d.ts +49 -0
  25. package/dist/types/lib/meta.d.ts +36 -0
  26. package/dist/types/lib/output.d.ts +83 -0
  27. package/dist/types/lib/table.d.ts +18 -0
  28. package/dist/types/lib/validation.d.ts +11 -0
  29. package/dist/types/paths/index.d.ts +2 -0
  30. package/dist/types/state/exchange-credentials.d.ts +25 -0
  31. package/dist/types/state/files.d.ts +9 -0
  32. package/dist/types/state/identities.d.ts +42 -0
  33. package/dist/types/state/index.d.ts +8 -0
  34. package/dist/types/state/paths.d.ts +32 -0
  35. package/package.json +30 -8
  36. package/src/admin/.spec/api.d.ts +3 -0
  37. package/src/admin/.spec/architecture.md +15 -0
  38. package/src/admin/.spec/icon.svg +3 -0
  39. package/src/admin/.spec/layout.ts +6 -0
  40. package/src/admin/catalog/.spec/api.d.ts +65 -0
  41. package/src/admin/catalog/.spec/architecture.md +6 -0
  42. package/src/admin/catalog/.spec/icon.svg +3 -0
  43. package/src/admin/catalog/.spec/layout.ts +6 -0
  44. package/src/admin/catalog/__tests__/client.test.ts +171 -0
  45. package/src/admin/catalog/client.ts +214 -0
  46. package/src/admin/catalog/index.ts +13 -0
  47. package/src/admin/catalog/model.ts +42 -0
  48. package/src/admin/catalog/tsconfig.json +8 -0
  49. package/src/admin/graph/.spec/api.d.ts +28 -0
  50. package/src/admin/graph/.spec/architecture.md +5 -0
  51. package/src/admin/graph/.spec/icon.svg +3 -0
  52. package/src/admin/graph/.spec/layout.ts +3 -0
  53. package/src/admin/graph/index.ts +6 -0
  54. package/src/admin/graph/nodes.ts +56 -0
  55. package/src/admin/index.ts +2 -0
  56. package/src/admin/instance/.spec/api.d.ts +66 -0
  57. package/src/admin/instance/.spec/architecture.md +10 -0
  58. package/src/admin/instance/.spec/icon.svg +3 -0
  59. package/src/admin/instance/.spec/layout.ts +6 -0
  60. package/src/admin/instance/__tests__/client.test.ts +289 -0
  61. package/src/admin/instance/client.ts +298 -0
  62. package/src/admin/instance/index.ts +16 -0
  63. package/src/admin/instance/model.ts +65 -0
  64. package/src/admin/instance/tsconfig.json +8 -0
  65. package/src/commands/__tests__/admin-instance.test.ts +3 -36
  66. package/src/commands/__tests__/call.test.ts +21 -68
  67. package/src/commands/__tests__/domain-install-owned.test.ts +26 -27
  68. package/src/commands/__tests__/domain-list.test.ts +2 -6
  69. package/src/commands/__tests__/logs.test.ts +50 -98
  70. package/src/commands/__tests__/ls.test.ts +21 -17
  71. package/src/commands/__tests__/read-commands.test.ts +171 -101
  72. package/src/commands/__tests__/view.test.ts +100 -51
  73. package/src/commands/admin/status.ts +3 -3
  74. package/src/commands/admin/use.ts +29 -6
  75. package/src/commands/auth/login.ts +1 -1
  76. package/src/commands/auth/logout.ts +4 -2
  77. package/src/commands/auth/status.ts +2 -2
  78. package/src/commands/auth/token.ts +2 -2
  79. package/src/commands/browser.ts +1 -1
  80. package/src/commands/call.ts +55 -91
  81. package/src/commands/describe.ts +52 -147
  82. package/src/commands/domain/install.ts +81 -50
  83. package/src/commands/domain/list.ts +4 -8
  84. package/src/commands/domain/publish.ts +9 -31
  85. package/src/commands/get.ts +32 -65
  86. package/src/commands/identity/__tests__/register.test.ts +93 -0
  87. package/src/commands/identity/create.ts +2 -2
  88. package/src/commands/identity/delete.ts +2 -2
  89. package/src/commands/identity/export.ts +7 -33
  90. package/src/commands/identity/import.ts +21 -70
  91. package/src/commands/identity/list.ts +2 -2
  92. package/src/commands/identity/register.ts +148 -117
  93. package/src/commands/identity/sync.ts +2 -2
  94. package/src/commands/identity/unsync.ts +2 -2
  95. package/src/commands/identity/use.ts +2 -2
  96. package/src/commands/identity/whoami.ts +2 -2
  97. package/src/commands/idp/add.ts +1 -1
  98. package/src/commands/idp/list.ts +1 -1
  99. package/src/commands/idp/refresh.ts +1 -1
  100. package/src/commands/idp/remove.ts +2 -2
  101. package/src/commands/idp/show.ts +1 -1
  102. package/src/commands/instance/active.ts +2 -2
  103. package/src/commands/instance/bookmark.ts +8 -2
  104. package/src/commands/instance/create.ts +1 -1
  105. package/src/commands/instance/delete.ts +4 -10
  106. package/src/commands/instance/forget.ts +1 -1
  107. package/src/commands/instance/list.ts +3 -3
  108. package/src/commands/instance/status.ts +5 -7
  109. package/src/commands/instance/use.ts +3 -3
  110. package/src/commands/logs.ts +152 -279
  111. package/src/commands/ls.ts +78 -204
  112. package/src/commands/mutate.ts +70 -139
  113. package/src/commands/query.ts +100 -278
  114. package/src/commands/session/analyze.ts +1 -1
  115. package/src/commands/session/list.ts +1 -1
  116. package/src/commands/setup.ts +1 -1
  117. package/src/commands/status.ts +1 -1
  118. package/src/commands/studio.ts +1 -1
  119. package/src/commands/token.ts +26 -21
  120. package/src/commands/update.ts +1 -1
  121. package/src/commands/use.ts +2 -3
  122. package/src/commands/view-serve.ts +1 -1
  123. package/src/commands/view.ts +67 -109
  124. package/src/connect-core.test.ts +38 -0
  125. package/src/connect-core.ts +42 -0
  126. package/src/connection/.spec/api.d.ts +111 -0
  127. package/src/connection/.spec/architecture.md +41 -0
  128. package/src/connection/.spec/capabilities/connection.ts +13 -0
  129. package/src/connection/.spec/examples/call.ts +7 -0
  130. package/src/connection/.spec/flows/command.ts +20 -0
  131. package/src/connection/.spec/flows/session.ts +61 -0
  132. package/src/connection/.spec/laws/connection.ts +181 -0
  133. package/src/connection/.spec/layout.ts +19 -0
  134. package/src/{kernel → connection}/__tests__/auth.test.ts +26 -2
  135. package/src/connection/__tests__/ca-fetch.test.ts +53 -0
  136. package/src/connection/__tests__/call.test.ts +17 -0
  137. package/src/connection/__tests__/credential.test.ts +109 -0
  138. package/src/connection/__tests__/errors.test.ts +96 -0
  139. package/src/connection/__tests__/exchange.test.ts +224 -0
  140. package/src/connection/__tests__/fixtures/localhost-cert.pem +19 -0
  141. package/src/connection/__tests__/fixtures/localhost-key.base64 +1 -0
  142. package/src/connection/__tests__/managed.test.ts +39 -0
  143. package/src/connection/__tests__/self.test.ts +51 -0
  144. package/src/connection/__tests__/session.test.ts +140 -0
  145. package/src/connection/__tests__/target.test.ts +93 -0
  146. package/src/{kernel → connection}/auth.ts +8 -8
  147. package/src/connection/call.ts +7 -0
  148. package/src/{kernel/run.ts → connection/command.ts} +22 -13
  149. package/src/connection/credential.ts +114 -0
  150. package/src/{kernel → connection}/errors.ts +32 -9
  151. package/src/connection/exchange.ts +274 -0
  152. package/src/connection/index.ts +8 -0
  153. package/src/connection/self.ts +120 -0
  154. package/src/connection/session.ts +176 -0
  155. package/src/connection/target.ts +111 -0
  156. package/src/connection/tsconfig.json +6 -0
  157. package/src/graph/.spec/api.d.ts +34 -0
  158. package/src/graph/.spec/laws/documents.ts +24 -0
  159. package/src/graph/.spec/laws/projection.ts +13 -0
  160. package/src/graph/.spec/layout.ts +6 -0
  161. package/src/graph/__tests__/mutation.test.ts +43 -0
  162. package/src/graph/__tests__/projection.test.ts +22 -0
  163. package/src/graph/__tests__/query.test.ts +154 -0
  164. package/src/graph/index.ts +3 -0
  165. package/src/graph/mutation.ts +18 -0
  166. package/src/graph/projection.ts +21 -0
  167. package/src/graph/query.ts +108 -0
  168. package/src/graph/tsconfig.json +6 -0
  169. package/src/identity/.history/ard/bootstrap-root-transfer.md +57 -0
  170. package/src/identity/.history/ard/domain-mediated-registration.md +36 -0
  171. package/src/identity/.spec/api.d.ts +124 -0
  172. package/src/identity/.spec/architecture.md +33 -0
  173. package/src/identity/.spec/capabilities/identity.ts +7 -0
  174. package/src/identity/.spec/flows/bootstrap-root.ts +79 -0
  175. package/src/identity/.spec/flows/domain-mediated-registration.ts +51 -0
  176. package/src/identity/.spec/flows/import.ts +29 -0
  177. package/src/identity/.spec/laws/identity.ts +56 -0
  178. package/src/identity/.spec/layout.ts +13 -0
  179. package/src/identity/.spec/schemas/identity-export-v1.schema.json +25 -0
  180. package/src/identity/__tests__/fixtures/registry-journey.ts +53 -0
  181. package/src/identity/__tests__/registration.test.ts +64 -0
  182. package/src/identity/__tests__/registry.test.ts +70 -0
  183. package/src/identity/__tests__/transfer.test.ts +198 -0
  184. package/src/identity/index.ts +23 -0
  185. package/src/identity/registration.ts +72 -0
  186. package/src/identity/registry.ts +172 -0
  187. package/src/identity/transfer.ts +187 -0
  188. package/src/identity/tsconfig.json +6 -0
  189. package/src/index.ts +1 -0
  190. package/src/keys/.spec/api.d.ts +74 -0
  191. package/src/keys/.spec/architecture.md +13 -0
  192. package/src/keys/.spec/laws/keys.ts +43 -0
  193. package/src/keys/.spec/layout.ts +6 -0
  194. package/src/keys/__tests__/algorithm.test.ts +39 -0
  195. package/src/keys/__tests__/keys.test.ts +168 -0
  196. package/src/keys/algorithm.ts +33 -0
  197. package/src/keys/credential.ts +112 -0
  198. package/src/keys/index.ts +14 -0
  199. package/src/keys/pair.ts +219 -0
  200. package/src/keys/tsconfig.json +6 -0
  201. package/src/lib/__tests__/admin-target.test.ts +67 -7
  202. package/src/lib/__tests__/binary.test.ts +2 -3
  203. package/src/lib/__tests__/command-dx.test.ts +2 -2
  204. package/src/lib/__tests__/config.test.ts +3 -2
  205. package/src/lib/__tests__/idp.test.ts +4 -6
  206. package/src/lib/__tests__/instance-target.test.ts +7 -4
  207. package/src/lib/__tests__/local-status.test.ts +1 -1
  208. package/src/lib/__tests__/log.test.ts +31 -0
  209. package/src/lib/__tests__/meta.test.ts +55 -0
  210. package/src/lib/__tests__/sdk-deps.test.ts +1 -1
  211. package/src/lib/__tests__/self.test.ts +8 -230
  212. package/src/lib/__tests__/use-target.test.ts +1 -1
  213. package/src/lib/__tests__/view-open-intent.test.ts +78 -104
  214. package/src/lib/__tests__/view-session.test.ts +99 -0
  215. package/src/lib/admin-domain.ts +39 -25
  216. package/src/lib/admin-instance.ts +38 -43
  217. package/src/lib/admin-target.ts +67 -13
  218. package/src/lib/binary.ts +13 -34
  219. package/src/lib/browser.ts +1 -1
  220. package/src/{kernel → lib}/ca-fetch.ts +35 -27
  221. package/src/lib/config.ts +1 -1
  222. package/src/lib/idp-session.ts +1 -1
  223. package/src/lib/idp.ts +3 -8
  224. package/src/lib/instance-target.ts +12 -8
  225. package/src/lib/instance.ts +34 -2
  226. package/src/lib/local-status.ts +2 -2
  227. package/src/lib/log.ts +3 -1
  228. package/src/lib/login-flow.ts +32 -5
  229. package/src/lib/meta.ts +15 -11
  230. package/src/lib/provision-instance.ts +4 -12
  231. package/src/lib/self.ts +5 -147
  232. package/src/lib/update.ts +1 -1
  233. package/src/lib/use-target.ts +1 -1
  234. package/src/lib/validation.ts +2 -2
  235. package/src/lib/view/open-intent.ts +7 -37
  236. package/src/lib/view/port-allocation.ts +1 -1
  237. package/src/lib/view/resolve.ts +52 -45
  238. package/src/lib/view/server.ts +16 -33
  239. package/src/lib/view/session.ts +51 -22
  240. package/src/paths/.spec/api.d.ts +13 -0
  241. package/src/paths/.spec/architecture.md +5 -0
  242. package/src/paths/.spec/layout.ts +3 -0
  243. package/src/paths/index.ts +13 -0
  244. package/src/program/.spec/api.d.ts +42 -0
  245. package/src/program/.spec/architecture.md +18 -0
  246. package/src/program/.spec/laws/program.ts +29 -0
  247. package/src/program/.spec/layout.ts +14 -0
  248. package/src/program/__tests__/program.test.ts +359 -0
  249. package/src/program/build.ts +190 -0
  250. package/src/program/command.ts +42 -0
  251. package/src/program/index.ts +2 -0
  252. package/src/program/options.ts +40 -0
  253. package/src/{registry.ts → program/registry.ts} +5 -1
  254. package/src/program/tsconfig.json +6 -0
  255. package/src/setup/steps/admin.ts +18 -3
  256. package/src/setup/steps/instance.ts +1 -1
  257. package/src/state/.spec/api.d.ts +133 -0
  258. package/src/state/.spec/architecture.md +31 -0
  259. package/src/state/.spec/capabilities/state.ts +7 -0
  260. package/src/state/.spec/flows/identity-update.ts +22 -0
  261. package/src/state/.spec/laws/state.ts +73 -0
  262. package/src/state/.spec/layout.ts +14 -0
  263. package/src/state/__tests__/exchange-credentials.test.ts +188 -0
  264. package/src/state/__tests__/files.test.ts +113 -0
  265. package/src/state/__tests__/fixtures/identity-transition.ts +37 -0
  266. package/src/state/__tests__/identities.test.ts +142 -0
  267. package/src/state/__tests__/paths.test.ts +27 -0
  268. package/src/state/exchange-credentials.ts +219 -0
  269. package/src/state/files.ts +129 -0
  270. package/src/state/identities.ts +236 -0
  271. package/src/state/index.ts +29 -0
  272. package/src/state/paths.ts +61 -0
  273. package/src/state/tsconfig.json +6 -0
  274. package/src/telemetry/__tests__/redact.test.ts +3 -3
  275. package/src/telemetry/__tests__/trigger.test.ts +1 -1
  276. package/src/telemetry/settings.ts +1 -1
  277. package/src/telemetry/store.ts +1 -1
  278. package/src/test-utils.ts +1 -1
  279. package/studio/client/dist/assets/elk-api-D0cBetPW.js +1 -0
  280. package/studio/client/dist/assets/elk-worker.min-C9JGDOE-.js +6312 -0
  281. package/studio/client/dist/assets/index-BQnJ5sgd.css +1 -0
  282. package/studio/client/dist/assets/index-ChOr3yP0.css +1 -0
  283. package/studio/client/dist/assets/index-Dspir4w7.js +81 -0
  284. package/studio/client/dist/assets/index-bVD2KJgz.js +8 -0
  285. package/studio/client/dist/index.html +2 -2
  286. package/studio/package.json +10 -1
  287. package/studio/server/introspect/extractor.ts +1 -1
  288. package/studio/server/state/views.test.ts +3 -7
  289. package/studio/server/state/views.ts +23 -30
  290. package/studio/tsconfig.json +23 -0
  291. package/tsconfig.json +1 -1
  292. package/viewer/dist/main.js +65 -39
  293. package/viewer/tsconfig.json +13 -0
  294. package/src/command.ts +0 -42
  295. package/src/commands/__tests__/help-contract.test.ts +0 -164
  296. package/src/kernel/__tests__/client-owned-lookup.test.ts +0 -51
  297. package/src/kernel/__tests__/errors.test.ts +0 -43
  298. package/src/kernel/__tests__/expand.test.ts +0 -123
  299. package/src/kernel/client.ts +0 -214
  300. package/src/kernel/expand.ts +0 -192
  301. package/src/kernel/graph.ts +0 -96
  302. package/src/kernel/index.ts +0 -29
  303. package/src/kernel/options.ts +0 -22
  304. package/src/kernel/types.ts +0 -14
  305. package/src/lib/__tests__/domain-identity.test.ts +0 -60
  306. package/src/lib/__tests__/fs-atomic.test.ts +0 -104
  307. package/src/lib/__tests__/identity.test.ts +0 -79
  308. package/src/lib/__tests__/keys.test.ts +0 -129
  309. package/src/lib/domain-identity.ts +0 -49
  310. package/src/lib/env.ts +0 -49
  311. package/src/lib/fs-atomic.ts +0 -126
  312. package/src/lib/identity.ts +0 -256
  313. package/src/lib/keys.ts +0 -294
  314. package/src/lib/paths.ts +0 -11
  315. package/src/program.ts +0 -213
  316. package/studio/client/dist/assets/index-BaqEuIQJ.js +0 -109
  317. package/studio/client/dist/assets/index-jRdExahh.css +0 -1
@@ -0,0 +1,14 @@
1
+ export {
2
+ acceptKeypair,
3
+ fileExists,
4
+ generateEd25519Jwk,
5
+ importKeypair,
6
+ keypairPaths,
7
+ listIdentityKeys,
8
+ persistKeypair,
9
+ readKeypair,
10
+ removeKeypair,
11
+ } from './pair'
12
+ export { loadAuth, persistAuth, resolveAuth, signAs } from './credential'
13
+ export type { Keypair, KeypairInput, KeypairPaths } from './pair'
14
+ export type { AuthBinding } from './credential'
@@ -0,0 +1,219 @@
1
+ import { compactVerify, CompactSign, exportJWK, generateKeyPair, importJWK, type JWK } from 'jose'
2
+ import { randomUUID } from 'node:crypto'
3
+ import { access, mkdir, readFile, unlink } from 'node:fs/promises'
4
+ import { dirname, join, resolve } from 'node:path'
5
+
6
+ import { AstraleError } from '../errors'
7
+ import { atomicWrite, KEYS_DIR } from '../state/index'
8
+ import { inferAlg } from './algorithm'
9
+
10
+ const LEGACY_MANAGER_PRIVATE = 'manager.private.jwk'
11
+ const LEGACY_MANAGER_PUBLIC = 'manager.public.jwk'
12
+
13
+ export type KeypairPaths = {
14
+ readonly privatePath: string
15
+ readonly publicPath: string
16
+ }
17
+
18
+ export interface Keypair {
19
+ readonly privateJwk: JWK
20
+ readonly publicJwk: JWK
21
+ readonly kid?: string
22
+ }
23
+
24
+ export interface KeypairInput {
25
+ readonly privateJwk: unknown
26
+ readonly publicJwk: unknown
27
+ }
28
+
29
+ /** Preserve manager filenames and confine every subject file to the selected key directory. */
30
+ export function keypairPaths(subject: string, keysDir: string = KEYS_DIR): KeypairPaths {
31
+ if (
32
+ subject.length === 0 ||
33
+ subject.includes('\0') ||
34
+ subject.includes('/') ||
35
+ subject.includes('\\')
36
+ ) {
37
+ throw invalidKeySubject(subject)
38
+ }
39
+ const filenames =
40
+ subject === 'manager'
41
+ ? { private: LEGACY_MANAGER_PRIVATE, public: LEGACY_MANAGER_PUBLIC }
42
+ : { private: `${subject}.private.jwk`, public: `${subject}.public.jwk` }
43
+
44
+ return {
45
+ privatePath: confinedKeyPath(keysDir, filenames.private, subject),
46
+ publicPath: confinedKeyPath(keysDir, filenames.public, subject),
47
+ }
48
+ }
49
+
50
+ function confinedKeyPath(keysDir: string, filename: string, subject: string): string {
51
+ const path = join(keysDir, filename)
52
+ if (dirname(resolve(path)) !== resolve(keysDir)) throw invalidKeySubject(subject)
53
+ return path
54
+ }
55
+
56
+ function invalidKeySubject(subject: string): AstraleError {
57
+ return new AstraleError(
58
+ 'INVALID_KEY_SUBJECT',
59
+ `Identity subject ${JSON.stringify(subject)} cannot name a key file.`,
60
+ 'Use a non-empty subject without path separators.',
61
+ )
62
+ }
63
+
64
+ function invalidKeypair(message: string): AstraleError {
65
+ return new AstraleError('INVALID_KEYPAIR', message, 'Import a supported matching keypair.')
66
+ }
67
+
68
+ function acceptJwk(input: unknown, role: 'private' | 'public'): JWK {
69
+ if (typeof input !== 'object' || input === null || Array.isArray(input)) {
70
+ throw invalidKeypair(`The ${role} JWK must be an object.`)
71
+ }
72
+ const jwk = { ...input } as JWK
73
+ if (jwk.kid !== undefined && (typeof jwk.kid !== 'string' || jwk.kid.length === 0)) {
74
+ throw invalidKeypair(`The ${role} JWK kid must be a non-empty string when present.`)
75
+ }
76
+ return jwk
77
+ }
78
+
79
+ export async function acceptKeypair(input: KeypairInput): Promise<Keypair> {
80
+ const privateJwk = acceptJwk(input.privateJwk, 'private')
81
+ const publicJwk = acceptJwk(input.publicJwk, 'public')
82
+ if (!Object.hasOwn(privateJwk, 'd')) {
83
+ throw invalidKeypair('The private JWK does not contain private key material.')
84
+ }
85
+ if (Object.hasOwn(publicJwk, 'd')) {
86
+ throw invalidKeypair('The public JWK must not contain private key material.')
87
+ }
88
+
89
+ const privateAlg = inferAlg(privateJwk as Record<string, unknown>)
90
+ const publicAlg = inferAlg(publicJwk as Record<string, unknown>)
91
+ if (privateAlg !== publicAlg) {
92
+ throw invalidKeypair(
93
+ `The private and public JWK algorithms differ (${privateAlg} versus ${publicAlg}).`,
94
+ )
95
+ }
96
+ if (privateJwk.kid && publicJwk.kid && privateJwk.kid !== publicJwk.kid) {
97
+ throw invalidKeypair('The private and public JWK key IDs differ.')
98
+ }
99
+
100
+ try {
101
+ const [privateKey, publicKey] = await Promise.all([
102
+ importJWK(privateJwk, privateAlg),
103
+ importJWK(publicJwk, publicAlg),
104
+ ])
105
+ const proof = await new CompactSign(new TextEncoder().encode('astrale-keypair-proof'))
106
+ .setProtectedHeader({ alg: privateAlg })
107
+ .sign(privateKey)
108
+ await compactVerify(proof, publicKey, { algorithms: [publicAlg] })
109
+ } catch {
110
+ throw invalidKeypair('The private and public JWKs do not form a valid matching pair.')
111
+ }
112
+
113
+ return { privateJwk, publicJwk, kid: privateJwk.kid ?? publicJwk.kid }
114
+ }
115
+
116
+ export async function fileExists(path: string): Promise<boolean> {
117
+ try {
118
+ await access(path)
119
+ return true
120
+ } catch (error) {
121
+ if ((error as { code?: string }).code === 'ENOENT') return false
122
+ throw error
123
+ }
124
+ }
125
+
126
+ export async function listIdentityKeys(keysDir: string = KEYS_DIR): Promise<string[]> {
127
+ try {
128
+ const { readdir } = await import('node:fs/promises')
129
+ const entries = await readdir(keysDir)
130
+ const names = new Set<string>()
131
+ for (const entry of entries) {
132
+ if (entry === LEGACY_MANAGER_PRIVATE) names.add('manager')
133
+ else if (entry.endsWith('.private.jwk')) names.add(entry.replace(/\.private\.jwk$/, ''))
134
+ }
135
+ return Array.from(names).sort()
136
+ } catch (error) {
137
+ if ((error as { code?: string }).code === 'ENOENT') return []
138
+ throw error
139
+ }
140
+ }
141
+
142
+ export async function generateEd25519Jwk(
143
+ kid: string,
144
+ ): Promise<{ readonly privateJwk: JWK; readonly publicJwk: JWK }> {
145
+ const { publicKey, privateKey } = await generateKeyPair('EdDSA', {
146
+ crv: 'Ed25519',
147
+ extractable: true,
148
+ })
149
+ const privateJwk = await exportJWK(privateKey)
150
+ const publicJwk = await exportJWK(publicKey)
151
+ privateJwk.alg = 'EdDSA'
152
+ publicJwk.alg = 'EdDSA'
153
+ privateJwk.kid = kid
154
+ publicJwk.kid = kid
155
+ return { privateJwk, publicJwk }
156
+ }
157
+
158
+ export async function persistKeypair(
159
+ subject: string,
160
+ opts?: { readonly keysDir?: string; readonly kid?: string },
161
+ ): Promise<{ readonly publicJwk: JWK; readonly privateJwk: JWK; readonly kid: string }> {
162
+ const keysDir = opts?.keysDir ?? KEYS_DIR
163
+ const { publicKey, privateKey } = await generateKeyPair('ES256', { extractable: true })
164
+ const publicJwk = await exportJWK(publicKey)
165
+ const privateJwk = await exportJWK(privateKey)
166
+ const kid = opts?.kid ?? `${subject}-key-${randomUUID().slice(0, 8)}`
167
+ publicJwk.kid = kid
168
+ privateJwk.kid = kid
169
+ publicJwk.alg = 'ES256'
170
+ privateJwk.alg = 'ES256'
171
+
172
+ await writeKeypair(subject, { privateJwk, publicJwk, kid }, keysDir)
173
+ return { publicJwk, privateJwk, kid }
174
+ }
175
+
176
+ export async function readKeypair(subject: string, keysDir: string = KEYS_DIR): Promise<Keypair> {
177
+ const { privatePath, publicPath } = keypairPaths(subject, keysDir)
178
+ try {
179
+ const [privateRaw, publicRaw] = await Promise.all([
180
+ readFile(privatePath, 'utf-8'),
181
+ readFile(publicPath, 'utf-8'),
182
+ ])
183
+ return await acceptKeypair({
184
+ privateJwk: JSON.parse(privateRaw) as unknown,
185
+ publicJwk: JSON.parse(publicRaw) as unknown,
186
+ })
187
+ } catch (error) {
188
+ if (error instanceof AstraleError) throw error
189
+ throw invalidKeypair(`Could not read the keypair for identity ${JSON.stringify(subject)}.`)
190
+ }
191
+ }
192
+
193
+ export async function importKeypair(
194
+ subject: string,
195
+ input: KeypairInput,
196
+ keysDir: string = KEYS_DIR,
197
+ ): Promise<Keypair> {
198
+ const pair = await acceptKeypair(input)
199
+ await writeKeypair(subject, pair, keysDir)
200
+ return pair
201
+ }
202
+
203
+ async function writeKeypair(subject: string, pair: Keypair, keysDir: string): Promise<void> {
204
+ const { privatePath, publicPath } = keypairPaths(subject, keysDir)
205
+ await mkdir(keysDir, { recursive: true })
206
+ await atomicWrite(privatePath, JSON.stringify(pair.privateJwk, null, 2))
207
+ await atomicWrite(publicPath, JSON.stringify(pair.publicJwk, null, 2))
208
+ }
209
+
210
+ export async function removeKeypair(subject: string, keysDir: string = KEYS_DIR): Promise<void> {
211
+ const { privatePath, publicPath } = keypairPaths(subject, keysDir)
212
+ for (const path of [privatePath, publicPath]) {
213
+ try {
214
+ await unlink(path)
215
+ } catch (error) {
216
+ if ((error as { code?: string }).code !== 'ENOENT') throw error
217
+ }
218
+ }
219
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": { "types": ["@types/node"] },
4
+ "include": ["*.ts"],
5
+ "exclude": ["__tests__"]
6
+ }
@@ -4,6 +4,7 @@ import type { InstanceStore } from '../instance'
4
4
 
5
5
  import {
6
6
  DEFAULT_ADMIN_TARGET_NAME,
7
+ DEFAULT_ADMIN_DOMAIN_ISSUER,
7
8
  DEFAULT_ADMIN_TARGET_URL,
8
9
  resolveAdminTargetFromStore,
9
10
  } from '../admin-target'
@@ -19,9 +20,14 @@ const instances: InstanceStore = {
19
20
  admin: {
20
21
  url: 'https://bookmarked-admin.example.com',
21
22
  issuer: 'https://bookmarked-issuer.example.com',
23
+ domainIssuer: 'https://bookmarked-domain.example.com',
22
24
  defaultIdentity: 'admin-workos',
23
25
  },
24
- alias: { url: 'https://alias-admin.example.com', name: 'named-admin' },
26
+ alias: {
27
+ url: 'https://alias-admin.example.com',
28
+ domainIssuer: 'https://alias-domain.example.com',
29
+ name: 'named-admin',
30
+ },
25
31
  },
26
32
  }
27
33
 
@@ -31,7 +37,8 @@ describe('resolveAdminTargetFromStore', () => {
31
37
  name: DEFAULT_ADMIN_TARGET_NAME,
32
38
  registrationSlug: DEFAULT_ADMIN_TARGET_NAME,
33
39
  url: DEFAULT_ADMIN_TARGET_URL,
34
- issuer: DEFAULT_ADMIN_TARGET_URL,
40
+ kernelIssuer: DEFAULT_ADMIN_TARGET_URL,
41
+ domainIssuer: DEFAULT_ADMIN_DOMAIN_ISSUER,
35
42
  source: 'default',
36
43
  configured: false,
37
44
  })
@@ -47,33 +54,69 @@ describe('resolveAdminTargetFromStore', () => {
47
54
  name: 'admin',
48
55
  registrationSlug: 'admin',
49
56
  url: 'https://bookmarked-admin.example.com',
50
- issuer: 'https://bookmarked-issuer.example.com',
57
+ kernelIssuer: 'https://bookmarked-issuer.example.com',
58
+ domainIssuer: 'https://bookmarked-domain.example.com',
51
59
  defaultIdentity: 'admin-workos',
52
60
  source: 'config-instance',
53
61
  configured: true,
54
62
  })
55
63
  })
56
64
 
65
+ test('keeps an exact beta Domain issuer separate from the Admin Kernel target', () => {
66
+ const config: AstraleConfig = {
67
+ ...DEFAULT_CONFIG,
68
+ admin: {
69
+ url: 'https://admin.eu.beta.astrale.ai/api',
70
+ kernelIssuer: 'https://admin.eu.beta.astrale.ai/api',
71
+ domainIssuer: 'https://admin.beta.astrale.ai',
72
+ },
73
+ }
74
+
75
+ expect(resolveAdminTargetFromStore({}, config, instances)).toMatchObject({
76
+ url: 'https://admin.eu.beta.astrale.ai/api',
77
+ kernelIssuer: 'https://admin.eu.beta.astrale.ai/api',
78
+ domainIssuer: 'https://admin.beta.astrale.ai',
79
+ source: 'config-url',
80
+ configured: true,
81
+ })
82
+
83
+ expect(
84
+ resolveAdminTargetFromStore(
85
+ { adminUrl: 'https://override.eu.beta.astrale.ai/api' },
86
+ config,
87
+ instances,
88
+ ),
89
+ ).toMatchObject({
90
+ url: 'https://override.eu.beta.astrale.ai/api',
91
+ domainIssuer: 'https://admin.beta.astrale.ai',
92
+ })
93
+ })
94
+
57
95
  test('allows explicit admin bookmark and admin url overrides', () => {
58
96
  expect(
59
97
  resolveAdminTargetFromStore({ admin: 'alias' }, DEFAULT_CONFIG, instances),
60
98
  ).toMatchObject({
61
99
  name: 'alias',
62
100
  url: 'https://alias-admin.example.com',
63
- issuer: 'https://alias-admin.example.com',
101
+ kernelIssuer: 'https://alias-admin.example.com',
102
+ domainIssuer: 'https://alias-domain.example.com',
64
103
  source: 'admin',
65
104
  })
66
105
 
67
106
  expect(
68
107
  resolveAdminTargetFromStore(
69
- { adminUrl: 'https://override-admin.example.com' },
108
+ {
109
+ adminUrl: 'https://override-admin.example.com',
110
+ domainIssuer: 'https://override-domain.example.com',
111
+ },
70
112
  DEFAULT_CONFIG,
71
113
  instances,
72
114
  ),
73
115
  ).toMatchObject({
74
116
  name: 'admin',
75
117
  url: 'https://override-admin.example.com',
76
- issuer: 'https://override-admin.example.com',
118
+ kernelIssuer: 'https://override-admin.example.com',
119
+ domainIssuer: 'https://override-domain.example.com',
77
120
  source: 'admin-url',
78
121
  })
79
122
  })
@@ -89,13 +132,17 @@ describe('resolveAdminTargetFromStore', () => {
89
132
 
90
133
  expect(
91
134
  resolveAdminTargetFromStore(
92
- { url: 'https://override.example.com' },
135
+ {
136
+ url: 'https://override.example.com',
137
+ domainIssuer: 'https://override-domain.example.com',
138
+ },
93
139
  DEFAULT_CONFIG,
94
140
  instances,
95
141
  ),
96
142
  ).toMatchObject({
97
143
  name: 'admin',
98
144
  url: 'https://override.example.com',
145
+ domainIssuer: 'https://override-domain.example.com',
99
146
  source: 'admin-url',
100
147
  })
101
148
  })
@@ -109,4 +156,17 @@ describe('resolveAdminTargetFromStore', () => {
109
156
  ),
110
157
  ).toThrow('Choose one admin target override')
111
158
  })
159
+
160
+ test('retains configured Domain evidence instead of inferring it from the Kernel issuer', () => {
161
+ expect(
162
+ resolveAdminTargetFromStore(
163
+ { adminUrl: 'https://override-admin.example.com' },
164
+ DEFAULT_CONFIG,
165
+ instances,
166
+ ),
167
+ ).toMatchObject({
168
+ kernelIssuer: 'https://override-admin.example.com',
169
+ domainIssuer: DEFAULT_ADMIN_DOMAIN_ISSUER,
170
+ })
171
+ })
112
172
  })
@@ -4,8 +4,7 @@ import { readFile, unlink } from 'node:fs/promises'
4
4
  import { presentBinary, type BinaryLike } from '../binary'
5
5
 
6
6
  const png = (): BinaryLike => ({
7
- status: 200,
8
- contentType: 'image/png',
7
+ mediaType: 'image/png',
9
8
  body: new Uint8Array([1, 2, 3, 4]),
10
9
  })
11
10
 
@@ -40,7 +39,7 @@ describe('presentBinary', () => {
40
39
 
41
40
  test('--json inlines text for text-like content types', async () => {
42
41
  await presentBinary(
43
- { status: 200, contentType: 'text/plain', body: new TextEncoder().encode('hi') },
42
+ { mediaType: 'text/plain', body: new TextEncoder().encode('hi') },
44
43
  { json: true },
45
44
  )
46
45
  const obj = JSON.parse(Buffer.concat(chunks).toString())
@@ -1,7 +1,7 @@
1
1
  import { describe, expect, test } from 'bun:test'
2
2
  import { CommanderError } from 'commander'
3
3
 
4
- import { buildProgram } from '../../program'
4
+ import { buildProgram } from '../../program/index'
5
5
  import { collectCommandCatalog, renderCommanderError } from '../command-dx'
6
6
 
7
7
  // `renderCommanderError` styles commands with `chalk.bold`, which emits ANSI
@@ -22,7 +22,7 @@ describe('command DX suggestions', () => {
22
22
  expect(usages).toContain('admin use [bookmark]')
23
23
  expect(usages).toContain('use <name>')
24
24
  expect(usages).toContain('update')
25
- expect(usages).toContain('ls [path]')
25
+ expect(usages).toContain('ls <source>')
26
26
  expect(usages).toContain('status')
27
27
  })
28
28
 
@@ -1,6 +1,6 @@
1
1
  import { describe, expect, test } from 'bun:test'
2
2
 
3
- import { DEFAULT_ADMIN_TARGET_URL } from '../admin-target'
3
+ import { DEFAULT_ADMIN_DOMAIN_ISSUER, DEFAULT_ADMIN_TARGET_URL } from '../admin-target'
4
4
  import { AstraleConfigSchema } from '../config'
5
5
 
6
6
  describe('AstraleConfigSchema', () => {
@@ -18,7 +18,8 @@ describe('AstraleConfigSchema', () => {
18
18
  expect(result.admin).toEqual({
19
19
  name: 'admin',
20
20
  url: DEFAULT_ADMIN_TARGET_URL,
21
- issuer: DEFAULT_ADMIN_TARGET_URL,
21
+ kernelIssuer: DEFAULT_ADMIN_TARGET_URL,
22
+ domainIssuer: DEFAULT_ADMIN_DOMAIN_ISSUER,
22
23
  })
23
24
  })
24
25
 
@@ -63,11 +63,8 @@ describe('IdP schemas and token helpers', () => {
63
63
  expect(config?.client.token_request_format).toBe('json')
64
64
  })
65
65
 
66
- test('builds built-in WorkOS IdP config with the public alpha client id by default', () => {
67
- const config = builtinIdpConfig('workos', undefined, {})
68
-
69
- expect(config?.entry.builtIn).toBe(true)
70
- expect(config?.client.client_id).toBe('client_01KC29HEGD7B40TV2C4QZ436BG')
66
+ test('does not invent a WorkOS environment when no client id is configured', () => {
67
+ expect(builtinIdpConfig('workos', undefined, {})).toBeNull()
71
68
  })
72
69
 
73
70
  test('reads WorkOS client id from WORKOS_CLIENT_ID before VITE_WORKOS_CLIENT_ID', () => {
@@ -78,7 +75,8 @@ describe('IdP schemas and token helpers', () => {
78
75
  }),
79
76
  ).toBe('client_primary')
80
77
  expect(workosClientIdFromEnv({ VITE_WORKOS_CLIENT_ID: 'client_vite' })).toBe('client_vite')
81
- expect(workosClientIdFromEnv({})).toBe('client_01KC29HEGD7B40TV2C4QZ436BG')
78
+ expect(workosClientIdFromEnv({})).toBeUndefined()
79
+ expect(workosClientIdFromEnv({ WORKOS_CLIENT_ID: ' ' })).toBeUndefined()
82
80
  })
83
81
 
84
82
  test('stores client secret env names, not secret material', () => {
@@ -22,6 +22,7 @@ const store: InstanceStore = {
22
22
  admin: {
23
23
  url: 'https://bookmarked-admin.example.com/api',
24
24
  issuer: 'https://bookmarked-admin-issuer.example.com',
25
+ domainIssuer: 'https://bookmarked-admin-domain.example.com',
25
26
  },
26
27
  },
27
28
  }
@@ -36,7 +37,8 @@ const directAdminConfig: AstraleConfig = {
36
37
  admin: {
37
38
  name: 'admin',
38
39
  url: 'https://admin.eu.astrale.ai/api',
39
- issuer: 'https://admin.eu.astrale.ai/api',
40
+ kernelIssuer: 'https://admin.eu.astrale.ai/api',
41
+ domainIssuer: 'https://admin.beta.astrale.ai',
40
42
  },
41
43
  }
42
44
 
@@ -83,7 +85,8 @@ describe('resolveInstanceTarget', () => {
83
85
  name: 'admin',
84
86
  source: 'admin',
85
87
  url: 'https://admin.eu.astrale.ai/api',
86
- issuer: 'https://admin.eu.astrale.ai/api',
88
+ kernelIssuer: 'https://admin.eu.astrale.ai/api',
89
+ domainIssuer: 'https://admin.beta.astrale.ai',
87
90
  })
88
91
  expect(managedCalls).toEqual([])
89
92
  })
@@ -116,7 +119,7 @@ describe('resolveInstanceTarget', () => {
116
119
  name: 'bryan',
117
120
  source: 'managed',
118
121
  url: 'https://bryan.eu.astrale.ai/api',
119
- issuer: 'https://bryan.eu.astrale.ai/api',
122
+ kernelIssuer: 'https://bryan.eu.astrale.ai/api',
120
123
  })
121
124
  })
122
125
 
@@ -147,7 +150,7 @@ describe('resolveInstanceTarget', () => {
147
150
  ).resolves.toEqual({
148
151
  source: 'url',
149
152
  url: 'https://kernel.example.com/api',
150
- issuer: 'https://kernel.example.com/api',
153
+ kernelIssuer: 'https://kernel.example.com/api',
151
154
  name: undefined,
152
155
  })
153
156
  })
@@ -1,6 +1,6 @@
1
1
  import { describe, expect, test } from 'bun:test'
2
2
 
3
- import type { IdentityStore } from '../identity'
3
+ import type { IdentityStore } from '../../identity/index'
4
4
  import type { IdpSession } from '../idp'
5
5
  import type { InstanceStore } from '../instance'
6
6
 
@@ -0,0 +1,31 @@
1
+ import { afterEach, beforeEach, describe, expect, mock, test } from 'bun:test'
2
+
3
+ import { log } from '../log'
4
+
5
+ describe('log diagnostics', () => {
6
+ let stdout: string[]
7
+ let stderr: string[]
8
+ let originalLog: typeof console.log
9
+ let originalError: typeof console.error
10
+
11
+ beforeEach(() => {
12
+ stdout = []
13
+ stderr = []
14
+ originalLog = console.log
15
+ originalError = console.error
16
+ console.log = mock((...values: unknown[]) => stdout.push(values.map(String).join(' ')))
17
+ console.error = mock((...values: unknown[]) => stderr.push(values.map(String).join(' ')))
18
+ })
19
+
20
+ afterEach(() => {
21
+ console.log = originalLog
22
+ console.error = originalError
23
+ })
24
+
25
+ test('warnings use stderr so machine-readable stdout remains one value', () => {
26
+ log.warn('identity override consented')
27
+
28
+ expect(stdout).toEqual([])
29
+ expect(stderr.join('\n')).toContain('identity override consented')
30
+ })
31
+ })
@@ -0,0 +1,55 @@
1
+ import { describe, expect, test } from 'bun:test'
2
+
3
+ import { checkIssuerReachability } from '../meta'
4
+
5
+ const ISSUER = 'https://host.example/kernel/child'
6
+ const INVOCATION = `${ISSUER}/invoke`
7
+
8
+ describe('issuer reachability', () => {
9
+ /** @evidence TEST-CLI-CONNECTION-PROBES-PINNED-ISSUER */
10
+ test('probes OIDC discovery at the separately pinned issuer, not the invocation endpoint', async () => {
11
+ const requests: string[] = []
12
+ const fetch = async (input: RequestInfo | URL): Promise<Response> => {
13
+ const url = String(input)
14
+ requests.push(url)
15
+ if (url === `${ISSUER}/.well-known/openid-configuration`) {
16
+ return Response.json({
17
+ issuer: ISSUER,
18
+ jwks_uri: `${ISSUER}/.well-known/jwks.json`,
19
+ })
20
+ }
21
+ if (url === `${ISSUER}/.well-known/jwks.json`) {
22
+ return Response.json({ keys: [{ kid: 'bootstrap' }] })
23
+ }
24
+ return new Response(null, { status: 404 })
25
+ }
26
+
27
+ await expect(checkIssuerReachability(INVOCATION, ISSUER, fetch)).resolves.toEqual({
28
+ issuer: ISSUER,
29
+ keys: [{ kid: 'bootstrap' }],
30
+ })
31
+ expect(requests).toEqual([
32
+ `${ISSUER}/.well-known/openid-configuration`,
33
+ `${ISSUER}/.well-known/jwks.json`,
34
+ ])
35
+ })
36
+
37
+ /** @evidence TEST-CLI-CONNECTION-REJECTS-DISCOVERY-ISSUER-MISMATCH */
38
+ test('rejects discovery that contradicts the separately pinned issuer', async () => {
39
+ const conflictingIssuer = 'https://attacker.example/kernel/child'
40
+ const fetch = async (input: RequestInfo | URL): Promise<Response> => {
41
+ const url = String(input)
42
+ if (url.endsWith('/.well-known/openid-configuration')) {
43
+ return Response.json({
44
+ issuer: conflictingIssuer,
45
+ jwks_uri: `${conflictingIssuer}/.well-known/jwks.json`,
46
+ })
47
+ }
48
+ return Response.json({ keys: [{ kid: 'attacker' }] })
49
+ }
50
+
51
+ await expect(checkIssuerReachability(INVOCATION, ISSUER, fetch)).rejects.toMatchObject({
52
+ code: 'ISSUER_UNREACHABLE',
53
+ })
54
+ })
55
+ })
@@ -9,7 +9,7 @@ describe('parseSdkOutdated', () => {
9
9
  test('keeps only deps with a strictly newer latest; uses wanted when current is absent', () => {
10
10
  const json = JSON.stringify({
11
11
  '@astrale-os/sdk': { current: '0.1.5', wanted: '0.1.5', latest: '0.1.9' }, // behind
12
- '@astrale-os/kernel-dsl': { current: '0.1.2', wanted: '0.1.2', latest: '0.1.2' }, // current
12
+ '@astrale-os/sdk/schema': { current: '0.1.2', wanted: '0.1.2', latest: '0.1.2' }, // current
13
13
  '@astrale-os/shell': { wanted: '0.1.0', latest: '0.1.1' }, // no `current` (not installed)
14
14
  })
15
15
  expect(parseSdkOutdated(json)).toEqual([