@astrale-os/cli 1.0.0-beta.1 → 1.0.0-beta.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 (180) hide show
  1. package/README.md +7 -11
  2. package/dist/astrale.js +3737 -3523
  3. package/dist/public/connect-core.js +396 -392
  4. package/dist/public/keys/index.js +371 -378
  5. package/dist/public/paths/index.js +371 -378
  6. package/dist/types/lib/idp.d.ts +6 -0
  7. package/dist/types/lib/meta.d.ts +2 -2
  8. package/package.json +6 -4
  9. package/src/admin/binding.ts +168 -0
  10. package/src/admin/catalog/__tests__/client.test.ts +2 -2
  11. package/src/admin/catalog/client.ts +4 -9
  12. package/src/admin/instance/__tests__/client.test.ts +2 -2
  13. package/src/admin/instance/client.ts +6 -11
  14. package/src/commands/__tests__/auth-login.test.ts +54 -1
  15. package/src/commands/__tests__/call.test.ts +5 -1
  16. package/src/commands/__tests__/domain-install-operation.test.ts +23 -7
  17. package/src/commands/__tests__/domain-install-owned.test.ts +5 -1
  18. package/src/commands/__tests__/domain-list.test.ts +83 -4
  19. package/src/commands/__tests__/install-identity-override.test.ts +30 -19
  20. package/src/commands/__tests__/studio-descriptor.test.ts +22 -0
  21. package/src/commands/__tests__/update.test.ts +23 -16
  22. package/src/commands/domain/install.ts +11 -15
  23. package/src/commands/domain/list.ts +17 -12
  24. package/src/commands/studio.ts +20 -0
  25. package/src/commands/update.ts +9 -5
  26. package/src/connection/__tests__/errors.test.ts +16 -12
  27. package/src/connection/__tests__/exchange.test.ts +6 -5
  28. package/src/connection/exchange.ts +5 -4
  29. package/src/lib/__tests__/domain-publication.test.ts +144 -0
  30. package/src/lib/__tests__/idp-session.test.ts +22 -0
  31. package/src/lib/__tests__/idp.test.ts +2 -0
  32. package/src/lib/__tests__/instance.test.ts +6 -0
  33. package/src/lib/__tests__/studio-server-deps.test.ts +53 -16
  34. package/src/lib/__tests__/update.test.ts +12 -0
  35. package/src/lib/domain-publication.ts +102 -0
  36. package/src/lib/idp.ts +5 -1
  37. package/src/lib/instance.ts +6 -1
  38. package/src/lib/login-flow.ts +13 -3
  39. package/src/lib/meta.ts +2 -2
  40. package/src/lib/update.ts +4 -4
  41. package/src/program/__tests__/program.test.ts +1 -1
  42. package/studio/client/dist/assets/{elk-api-D2xgMJvi.js → elk-api-lwhFo7vB.js} +1 -1
  43. package/studio/client/dist/assets/index-B-c-smo9.js +8 -0
  44. package/studio/client/dist/assets/index-BckHuAWk.js +81 -0
  45. package/studio/client/dist/assets/index-C4aNQ6dz.css +1 -0
  46. package/studio/client/dist/index.html +2 -2
  47. package/studio/package.json +3 -1
  48. package/studio/server/agent/bridge/stdio.ts +8 -1
  49. package/studio/server/agent/conversation.test.ts +10 -5
  50. package/studio/server/agent/conversation.ts +56 -8
  51. package/studio/server/agent/harness/codex/loadout.ts +18 -21
  52. package/studio/server/agent/harness/gateway/config.ts +20 -18
  53. package/studio/server/agent/harness/selection.ts +9 -1
  54. package/studio/server/agent/prompts/system.ts +3 -2
  55. package/studio/server/agent/prompts/turn.ts +13 -4
  56. package/studio/server/agent/run/completion.ts +2 -2
  57. package/studio/server/agent/run/preparation.ts +6 -5
  58. package/studio/server/agent/run/transcript.test.ts +35 -1
  59. package/studio/server/agent/run/transcript.ts +169 -3
  60. package/studio/server/agent/run/usage.test.ts +24 -0
  61. package/studio/server/agent/run/usage.ts +26 -1
  62. package/studio/server/api/canvas.ts +44 -0
  63. package/studio/server/api/comments.ts +85 -0
  64. package/studio/server/api/context.ts +61 -0
  65. package/studio/server/api/deployment.ts +39 -0
  66. package/studio/server/api/documents.ts +55 -0
  67. package/studio/server/api/domain.ts +59 -0
  68. package/studio/server/api/http.ts +45 -0
  69. package/studio/server/api/project.ts +57 -0
  70. package/studio/server/api/schema.ts +12 -0
  71. package/studio/server/api/views.ts +57 -0
  72. package/studio/server/api/workspace.ts +60 -0
  73. package/studio/server/api.test.ts +147 -0
  74. package/studio/server/api.ts +20 -422
  75. package/studio/server/cache.test.ts +111 -0
  76. package/studio/server/cache.ts +163 -9
  77. package/studio/server/cli-consumers.test.ts +494 -0
  78. package/studio/server/cli.test.ts +88 -0
  79. package/studio/server/cli.ts +240 -0
  80. package/studio/server/client-package.ts +25 -1
  81. package/studio/server/domain.test.ts +30 -2
  82. package/studio/server/domain.ts +14 -2
  83. package/studio/server/environment/dotenv-preview.test.ts +39 -0
  84. package/studio/server/environment/dotenv-preview.ts +27 -0
  85. package/studio/server/environment/files.test.ts +53 -0
  86. package/studio/server/{state/env.ts → environment/files.ts} +7 -48
  87. package/studio/server/{state → handoff}/copy.ts +21 -6
  88. package/studio/server/handoff/service.test.ts +22 -0
  89. package/studio/server/{state/handoff.ts → handoff/service.ts} +21 -14
  90. package/studio/server/instances/active.ts +72 -0
  91. package/studio/server/instances/deploy-record.test.ts +31 -0
  92. package/studio/server/instances/deploy-record.ts +37 -0
  93. package/studio/server/instances/deploy.ts +56 -0
  94. package/studio/server/{state/instance.test.ts → instances/probe.test.ts} +25 -21
  95. package/studio/server/instances/probe.ts +67 -0
  96. package/studio/server/instances/status.test.ts +12 -0
  97. package/studio/server/instances/status.ts +49 -0
  98. package/studio/server/introspect/anatomy/client-tree.ts +57 -0
  99. package/studio/server/introspect/anatomy/env-fields.ts +66 -0
  100. package/studio/server/introspect/anatomy/schema-definition.ts +53 -0
  101. package/studio/server/introspect/anatomy/source.ts +181 -0
  102. package/studio/server/introspect/anatomy/views/legacy.ts +232 -0
  103. package/studio/server/introspect/anatomy/views/routes.ts +105 -0
  104. package/studio/server/introspect/anatomy/views.ts +58 -0
  105. package/studio/server/introspect/anatomy-extras.test.ts +91 -4
  106. package/studio/server/introspect/anatomy-extras.ts +7 -726
  107. package/studio/server/introspect/anatomy.ts +46 -19
  108. package/studio/server/introspect/bundle.ts +15 -6
  109. package/studio/server/introspect/canonical-schema.test.ts +79 -0
  110. package/studio/server/introspect/canonical-schema.ts +80 -18
  111. package/studio/server/introspect/config-preview.test.ts +32 -0
  112. package/studio/server/introspect/config-preview.ts +119 -0
  113. package/studio/server/introspect/diff.test.ts +7 -11
  114. package/studio/server/introspect/diff.ts +28 -37
  115. package/studio/server/introspect/extractor.ts +8 -6
  116. package/studio/server/introspect/hash.ts +5 -2
  117. package/studio/server/introspect/overlay-tsmorph.ts +7 -1305
  118. package/studio/server/introspect/revision.test.ts +54 -0
  119. package/studio/server/introspect/revision.ts +49 -0
  120. package/studio/server/introspect/runtime.test.ts +63 -5
  121. package/studio/server/introspect/runtime.ts +49 -3
  122. package/studio/server/introspect/schema-ir-json.ts +181 -0
  123. package/studio/server/introspect/source-overlay/annotations.ts +14 -0
  124. package/studio/server/introspect/source-overlay/handlers.ts +681 -0
  125. package/studio/server/introspect/source-overlay/kernel-calls.ts +49 -0
  126. package/studio/server/introspect/source-overlay/project.ts +248 -0
  127. package/studio/server/introspect/source-overlay/spans.ts +360 -0
  128. package/studio/server/json.ts +46 -0
  129. package/studio/server/lifecycle.ts +5 -1
  130. package/studio/server/sse.test.ts +26 -0
  131. package/studio/server/sse.ts +4 -1
  132. package/studio/server/state/baseline.test.ts +212 -1
  133. package/studio/server/state/baseline.ts +145 -29
  134. package/studio/server/state/comments.test.ts +66 -1
  135. package/studio/server/state/comments.ts +173 -10
  136. package/studio/server/state/context.ts +34 -2
  137. package/studio/server/state/documents.ts +42 -1
  138. package/studio/server/state/integrations.ts +27 -1
  139. package/studio/server/state/layout.test.ts +34 -0
  140. package/studio/server/state/layout.ts +44 -17
  141. package/studio/server/state/settings.ts +29 -22
  142. package/studio/server/state/store.test.ts +122 -0
  143. package/studio/server/state/store.ts +66 -17
  144. package/studio/server/state/visibility.ts +22 -7
  145. package/studio/server/views/model.test.ts +57 -0
  146. package/studio/server/views/model.ts +66 -0
  147. package/studio/server/views/runtime.ts +40 -0
  148. package/studio/server/views/selection-repository.test.ts +31 -0
  149. package/studio/server/views/selection-repository.ts +60 -0
  150. package/studio/server/views/session.test.ts +73 -0
  151. package/studio/server/views/session.ts +166 -0
  152. package/studio/server/{state/views.test.ts → views/target.test.ts} +8 -159
  153. package/studio/server/views/target.ts +248 -0
  154. package/studio/server/watch.ts +1 -1
  155. package/studio/server/workspace/catalog.test.ts +17 -0
  156. package/studio/server/workspace/catalog.ts +43 -0
  157. package/studio/server/{state → workspace}/create.test.ts +1 -1
  158. package/studio/server/{state → workspace}/create.ts +1 -1
  159. package/studio/server/{state → workspace}/git.ts +1 -1
  160. package/studio/server/workspace/updates.ts +83 -0
  161. package/studio/server/workspace-state.ts +1 -1
  162. package/studio/shared/contracts/README.md +16 -0
  163. package/studio/shared/contracts/agent.ts +270 -0
  164. package/studio/shared/contracts/runtime.ts +50 -0
  165. package/studio/shared/contracts/schema.ts +462 -0
  166. package/studio/shared/contracts/surface.test.ts +319 -0
  167. package/studio/shared/contracts/workspace.ts +274 -0
  168. package/studio/shared/layout.test.ts +116 -0
  169. package/studio/shared/schema/identity.test.ts +58 -0
  170. package/studio/shared/schema/identity.ts +82 -0
  171. package/studio/shared/types.ts +11 -1099
  172. package/studio/tsconfig.json +1 -1
  173. package/viewer/dist/main.js +35 -35
  174. package/studio/client/dist/assets/index-BMdnsIJA.css +0 -1
  175. package/studio/client/dist/assets/index-D-vRV8w7.js +0 -8
  176. package/studio/client/dist/assets/index-LGSWRrk8.js +0 -81
  177. package/studio/server/state/catalog.ts +0 -117
  178. package/studio/server/state/instance.ts +0 -280
  179. package/studio/server/state/updates.ts +0 -63
  180. package/studio/server/state/views.ts +0 -535
@@ -1,16 +1,18 @@
1
1
  /**
2
- * copy.ts — the copy-payload builder. A PURE function (no IO): it turns studio
2
+ * Pure copy-payload projection for a Studio handoff (no IO). It turns studio
3
3
  * state into a single Markdown handoff payload that an author agent can paste
4
4
  * into its own session. The payload ends with a fenced ```json``` machine-state
5
5
  * block in the annotate shape so the author can reply by appending
6
6
  * {role:'author'} thread entries and merging back by id.
7
7
  */
8
- import type { Comment, ContextItem, DocMeta, ThreadEntry } from '../../shared/types'
8
+ import type { Comment, ContextItem, DocMeta, SchemaRevision, ThreadEntry } from '../../shared/types'
9
9
 
10
10
  interface CopyParts {
11
11
  origin: string
12
12
  root: string
13
- schemaHash: string
13
+ /** Studio render fingerprint retained by the legacy annotate machine-state. */
14
+ renderFingerprint: string
15
+ schemaRevision?: SchemaRevision
14
16
  openComments: Comment[]
15
17
  userContext: ContextItem[]
16
18
  autoContext: ContextItem[]
@@ -61,7 +63,16 @@ function toMachineState(comment: Comment): {
61
63
  }
62
64
 
63
65
  export function buildCopyMarkdown(parts: CopyParts): string {
64
- const { origin, root, schemaHash, openComments, userContext, autoContext, documents = [] } = parts
66
+ const {
67
+ origin,
68
+ root,
69
+ renderFingerprint,
70
+ schemaRevision,
71
+ openComments,
72
+ userContext,
73
+ autoContext,
74
+ documents = [],
75
+ } = parts
65
76
  const lines: string[] = []
66
77
 
67
78
  // ── Header ──
@@ -69,7 +80,8 @@ export function buildCopyMarkdown(parts: CopyParts): string {
69
80
  lines.push('')
70
81
  lines.push(`- **Origin:** \`${origin}\``)
71
82
  lines.push(`- **Repo root:** \`${root}\``)
72
- lines.push(`- **Schema hash:** \`${schemaHash}\``)
83
+ if (schemaRevision) lines.push(`- **Schema revision:** \`${schemaRevision}\``)
84
+ lines.push(`- **Render fingerprint:** \`${renderFingerprint}\``)
73
85
  lines.push('')
74
86
  lines.push(
75
87
  'Load the **astrale-domain** skill, use the context/threads below, ' +
@@ -143,8 +155,11 @@ export function buildCopyMarkdown(parts: CopyParts): string {
143
155
  }
144
156
 
145
157
  // ── Trailing machine-state block ──
158
+ // `schemaVersion` is the established annotate wire key. Its value remains the
159
+ // render fingerprint because it detects anchor/layout drift, not installation
160
+ // compatibility.
146
161
  const machineState = {
147
- schemaVersion: schemaHash,
162
+ schemaVersion: renderFingerprint,
148
163
  comments: openComments.map(toMachineState),
149
164
  }
150
165
  lines.push('```json')
@@ -0,0 +1,22 @@
1
+ import { expect, test } from 'bun:test'
2
+
3
+ import type { ChangeSet } from '../../shared/types'
4
+
5
+ import { changeText } from './service'
6
+
7
+ test('labels schema changes as indicative structure rather than Runtime compatibility', () => {
8
+ const changes: ChangeSet = {
9
+ source: 'baseline',
10
+ hasGit: false,
11
+ hasBaseline: true,
12
+ schemaChanges: [{ kind: 'class-removed', target: 'Legacy' }],
13
+ fileChanges: [],
14
+ structuralStatus: 'changed',
15
+ }
16
+
17
+ const text = changeText(changes)
18
+ expect(text).toContain('Indicative source/structure diff only')
19
+ expect(text).toContain('~ class-removed Legacy')
20
+ expect(text).not.toContain('BREAKING')
21
+ expect(text).not.toContain('additive')
22
+ })
@@ -1,5 +1,5 @@
1
1
  /**
2
- * handoff.ts shared helpers that turn live domain state into the "what changed
2
+ * Handoff service that turns live domain state into the "what changed
3
3
  * + what to read" material both the Copy payload (api.ts) and the live agent
4
4
  * runner depend on. Extracted so there is ONE definition of the change text and
5
5
  * the auto-context refresh.
@@ -8,29 +8,36 @@ import type { ChangeSet } from '../../shared/types'
8
8
  import type { DomainHandle } from '../domain'
9
9
 
10
10
  import { getBundle } from '../cache'
11
- import { computeChanges, hashAnatomyFiles } from './baseline'
12
- import { readComments } from './comments'
13
- import { materializeAuto } from './context'
11
+ import { computeChanges, hashAnatomyFiles } from '../state/baseline'
12
+ import { readComments } from '../state/comments'
13
+ import { materializeAuto } from '../state/context'
14
+ import { detectGit, gitDiff } from '../workspace/git'
14
15
 
15
16
  /** Current changes vs the review baseline (schema IR diff + anatomy file diff). */
16
17
  export async function changeSet(handle: DomainHandle): Promise<ChangeSet> {
17
18
  const bundle = await getBundle(handle.id)
18
19
  const files = hashAnatomyFiles(handle.root, handle.schemaDirName)
20
+ const { hasGit } = detectGit(handle.root)
21
+ const diffText = hasGit ? gitDiff(handle.root, handle.schemaDirName) : null
19
22
  return computeChanges(handle.root, bundle?.ir ?? null, files, {
20
- schemaDirName: handle.schemaDirName,
23
+ currentRevision: bundle?.schemaRevision ?? null,
24
+ git: {
25
+ hasGit,
26
+ ...(diffText === null ? {} : { diffText }),
27
+ },
21
28
  })
22
29
  }
23
30
 
24
31
  /** A human-readable "current changes" blob for the handoff payload. */
25
32
  export function changeText(cs: ChangeSet): string {
26
- if (cs.schemaDiffText && cs.schemaDiffText.trim()) return cs.schemaDiffText.trim()
33
+ const notice =
34
+ 'Indicative source/structure diff only; the Kernel Runtime has not assessed installation or data migration.'
35
+ if (cs.schemaDiffText && cs.schemaDiffText.trim()) return `${notice}\n${cs.schemaDiffText.trim()}`
27
36
  const lines: string[] = []
28
37
  for (const c of cs.schemaChanges)
29
- lines.push(
30
- `${c.breaking ? '! ' : '+ '}${c.kind} ${c.target}${c.detail ? ` (${c.detail})` : ''}`,
31
- )
38
+ lines.push(`~ ${c.kind} ${c.target}${c.detail ? ` (${c.detail})` : ''}`)
32
39
  for (const f of cs.fileChanges) lines.push(`~ ${f.status} ${f.file}`)
33
- return lines.join('\n')
40
+ return lines.length > 0 ? `${notice}\n${lines.join('\n')}` : ''
34
41
  }
35
42
 
36
43
  /** Refresh the on-disk context/auto digests so an external agent can read them. */
@@ -44,12 +51,12 @@ export async function refreshAuto(handle: DomainHandle): Promise<void> {
44
51
  `${i + 1}. [${c.kind} ${c.id}] ${c.anchorRefs[0]?.ref ?? ''} — ${c.thread.at(-1)?.text ?? ''}`,
45
52
  )
46
53
  .join('\n')
47
- const schemaSummary = cs.schemaChanges
48
- .map((c) => `${c.breaking ? 'BREAKING ' : ''}${c.kind} ${c.target}`)
49
- .join('\n')
54
+ const schemaSummary = cs.schemaChanges.map((c) => `STRUCTURAL ${c.kind} ${c.target}`).join('\n')
50
55
  materializeAuto(handle.root, {
51
56
  changes: changeText(cs) || 'no tracked changes',
52
- schemaChange: schemaSummary || 'no schema changes since baseline',
57
+ schemaChange: schemaSummary
58
+ ? `Indicative only; Runtime compatibility was not assessed.\n${schemaSummary}`
59
+ : 'no schema changes since baseline',
53
60
  comments: commentsDigest || 'no open comments',
54
61
  })
55
62
  }
@@ -0,0 +1,72 @@
1
+ import type { InstanceInfo, InstancesState } from '../../shared/types'
2
+
3
+ import { decodeJsonObject, runStudioCliJson, runStudioCliText } from '../cli'
4
+
5
+ async function astraleJson(args: string[]): Promise<Record<string, unknown> | null> {
6
+ const result = await runStudioCliJson(args, decodeJsonObject)
7
+ return result.ok ? result.data : null
8
+ }
9
+
10
+ function records(value: unknown): Record<string, unknown>[] {
11
+ return Array.isArray(value) ? value.map(decodeJsonObject).filter((item) => item !== null) : []
12
+ }
13
+
14
+ async function activeName(): Promise<string | null> {
15
+ const active = await astraleJson(['instance', 'active', '--json'])
16
+ return typeof active?.name === 'string' ? active.name : null
17
+ }
18
+
19
+ /** The CLI-owned global active instance. */
20
+ export const activeInstanceName = activeName
21
+
22
+ export async function listInstances(): Promise<InstancesState> {
23
+ const local = await astraleJson(['instance', 'list', '--bookmarked', '--json'])
24
+ const active = typeof local?.active === 'string' ? local.active : await activeName()
25
+ const instances: InstanceInfo[] = []
26
+ for (const bookmark of records(local?.bookmarks)) {
27
+ if (typeof bookmark.name !== 'string') continue
28
+ instances.push({
29
+ name: bookmark.name,
30
+ url: typeof bookmark.url === 'string' ? bookmark.url : '',
31
+ active: bookmark.active === true || bookmark.name === active,
32
+ kind: 'bookmark',
33
+ })
34
+ }
35
+ const managed = await astraleJson(['instance', 'list', '--admin-only', '--json'])
36
+ for (const item of records(managed?.instances)) {
37
+ if (
38
+ typeof item.slug !== 'string' ||
39
+ instances.some((instance) => instance.name === item.slug)
40
+ ) {
41
+ continue
42
+ }
43
+ instances.push({
44
+ name: item.slug,
45
+ url: typeof item.url === 'string' ? item.url : '',
46
+ active: item.slug === active,
47
+ kind: 'managed',
48
+ })
49
+ }
50
+ if (active && !instances.some((instance) => instance.name === active)) {
51
+ instances.unshift({ name: active, url: '', active: true, kind: 'bookmark' })
52
+ }
53
+ return { active, instances }
54
+ }
55
+
56
+ export async function setActiveInstance(
57
+ name: string,
58
+ ): Promise<{ ok: boolean; active: string | null; output: string }> {
59
+ const result = await runStudioCliText([
60
+ 'instance',
61
+ 'use',
62
+ name,
63
+ '--adopt-default',
64
+ '--skip-jwks-check',
65
+ ])
66
+ const combined = `${result.stdout}\n${result.stderr}`.trim()
67
+ return {
68
+ ok: result.ok,
69
+ active: await activeName(),
70
+ output: (combined || result.detail).slice(-1000),
71
+ }
72
+ }
@@ -0,0 +1,31 @@
1
+ import { afterEach, expect, test } from 'bun:test'
2
+ import { mkdtempSync, rmSync } from 'node:fs'
3
+ import { tmpdir } from 'node:os'
4
+ import { join } from 'node:path'
5
+
6
+ import { writeJson } from '../state/store'
7
+ import { lastDeploy } from './deploy-record'
8
+
9
+ const roots: string[] = []
10
+
11
+ afterEach(() => {
12
+ while (roots.length > 0) rmSync(roots.pop()!, { recursive: true, force: true })
13
+ })
14
+
15
+ test('reads the previous deploy fingerprint key but exposes only the current name', () => {
16
+ const root = mkdtempSync(join(tmpdir(), 'studio-deploy-record-'))
17
+ roots.push(root)
18
+ writeJson(root, 'deploy.json', {
19
+ at: '2026-08-20T00:00:00.000Z',
20
+ schemaHash: 'sha-legacy',
21
+ ok: true,
22
+ url: 'https://notes.svc.example.astrale.ai',
23
+ })
24
+
25
+ expect(lastDeploy(root)).toEqual({
26
+ at: '2026-08-20T00:00:00.000Z',
27
+ renderFingerprint: 'sha-legacy',
28
+ ok: true,
29
+ url: 'https://notes.svc.example.astrale.ai',
30
+ })
31
+ })
@@ -0,0 +1,37 @@
1
+ import type { DeployRecord } from '../../shared/types'
2
+
3
+ import { asJsonRecord, asString } from '../json'
4
+ import { readJson, writeJson } from '../state/store'
5
+
6
+ const DEPLOY_RECORD_FILE = 'deploy.json'
7
+
8
+ function decodeDeployRecord(value: unknown): DeployRecord | undefined {
9
+ const stored = asJsonRecord(value)
10
+ const at = asString(stored?.at)
11
+ if (!at || stored?.ok !== true) return undefined
12
+ const renderFingerprint = asString(stored.renderFingerprint) ?? asString(stored.schemaHash) ?? ''
13
+ const url = asString(stored.url)
14
+ return {
15
+ at,
16
+ renderFingerprint,
17
+ ok: true,
18
+ ...(url === undefined ? {} : { url }),
19
+ }
20
+ }
21
+
22
+ export function lastDeploy(root: string): DeployRecord | null {
23
+ return readJson(root, DEPLOY_RECORD_FILE, decodeDeployRecord, null)
24
+ }
25
+
26
+ export function recordSuccessfulDeploy(
27
+ root: string,
28
+ renderFingerprint: string | null,
29
+ url: string | null,
30
+ ): void {
31
+ writeJson(root, DEPLOY_RECORD_FILE, {
32
+ at: new Date().toISOString(),
33
+ renderFingerprint: renderFingerprint ?? '',
34
+ ok: true,
35
+ url: url ?? undefined,
36
+ } satisfies DeployRecord)
37
+ }
@@ -0,0 +1,56 @@
1
+ import { readFileSync } from 'node:fs'
2
+ import { join } from 'node:path'
3
+
4
+ import type { DeployResult } from '../../shared/types'
5
+ import type { DomainHandle } from '../domain'
6
+
7
+ import { recordSuccessfulDeploy } from './deploy-record'
8
+
9
+ export function hasProdScript(root: string): boolean {
10
+ try {
11
+ const pkg = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8'))
12
+ return typeof pkg?.scripts?.prod === 'string'
13
+ } catch {
14
+ return false
15
+ }
16
+ }
17
+
18
+ const SVC_URL = /https:\/\/[\w-]+\.svc\.[\w.-]+\.astrale\.ai\b/
19
+
20
+ /** Run `pnpm prod` only after an explicit outward-facing deploy request. */
21
+ export async function runDeploy(
22
+ handle: DomainHandle,
23
+ renderFingerprint: string | null,
24
+ ): Promise<DeployResult> {
25
+ if (!hasProdScript(handle.root)) {
26
+ return {
27
+ ok: false,
28
+ url: null,
29
+ output:
30
+ 'This domain has no "prod" script in package.json — it is not deployable via `pnpm prod`.',
31
+ }
32
+ }
33
+ let out = ''
34
+ let err = ''
35
+ let code = 1
36
+ try {
37
+ const proc = Bun.spawn(['pnpm', 'prod'], {
38
+ cwd: handle.root,
39
+ stdout: 'pipe',
40
+ stderr: 'pipe',
41
+ })
42
+ ;[out, err] = await Promise.all([
43
+ new Response(proc.stdout).text(),
44
+ new Response(proc.stderr).text(),
45
+ ])
46
+ code = await proc.exited
47
+ } catch (error) {
48
+ const message = error instanceof Error ? error.message : String(error)
49
+ return { ok: false, url: null, output: `failed to start pnpm: ${message}` }
50
+ }
51
+ const combined = `${out}\n${err}`.trim()
52
+ const url = combined.match(SVC_URL)?.[0] ?? null
53
+ const ok = code === 0
54
+ if (ok) recordSuccessfulDeploy(handle.root, renderFingerprint, url)
55
+ return { ok, url, output: combined.slice(-6000) }
56
+ }
@@ -1,16 +1,17 @@
1
1
  import { describe, expect, test } from 'bun:test'
2
2
 
3
- import { schemaHashOf } from '../introspect/hash'
4
- import {
5
- installedBundleRootHash,
6
- installedDomainCommand,
7
- installedDomainProbeResult,
8
- } from './instance'
3
+ import { installedDomainCommand, installedDomainProbeResult } from './probe'
9
4
 
10
5
  describe('installed Domain introspection', () => {
11
6
  test('uses the public bundle introspection command for the selected instance', () => {
12
- expect(installedDomainCommand('issues.astrale.ai', 'staging')).toEqual([
13
- 'astrale',
7
+ const descriptor = JSON.stringify({
8
+ version: 1,
9
+ executable: '/usr/local/bin/bun',
10
+ args: ['/workspace/cli/bin/astrale.ts'],
11
+ })
12
+ expect(installedDomainCommand('issues.astrale.ai', 'staging', descriptor)).toEqual([
13
+ '/usr/local/bin/bun',
14
+ '/workspace/cli/bin/astrale.ts',
14
15
  'introspect',
15
16
  'issues.astrale.ai',
16
17
  '--bundle',
@@ -20,22 +21,25 @@ describe('installed Domain introspection', () => {
20
21
  ])
21
22
  })
22
23
 
23
- test('hashes the installed Bundle root with the same deterministic hash as local schema', () => {
24
+ test('retains the complete installed Bundle for cohort SDK admission', () => {
24
25
  const root = {
25
26
  version: 'v1',
26
27
  domain: 'issues.astrale.ai',
27
28
  classes: { Issue: { properties: { title: { type: 'string' } } } },
28
29
  }
29
- const probe = installedDomainProbeResult(
30
- JSON.stringify({
31
- state: 'ready',
32
- bundle: { format: 'astrale.dsl.bundle', version: 'v1', root, closure: [] },
33
- }),
34
- '',
35
- 0,
36
- )
37
- expect(probe.state).toBe('installed')
38
- expect(installedBundleRootHash(probe)).toBe(schemaHashOf(root))
30
+ expect(
31
+ installedDomainProbeResult(
32
+ JSON.stringify({
33
+ state: 'ready',
34
+ bundle: { format: 'astrale.dsl.bundle', version: 'v1', root, closure: [] },
35
+ }),
36
+ '',
37
+ 0,
38
+ ),
39
+ ).toEqual({
40
+ state: 'installed',
41
+ bundle: { format: 'astrale.dsl.bundle', version: 'v1', root, closure: [] },
42
+ })
39
43
  })
40
44
 
41
45
  test('does not mistake the removed Domain Node shape for installation introspection', () => {
@@ -45,7 +49,7 @@ describe('installed Domain introspection', () => {
45
49
  '',
46
50
  0,
47
51
  ),
48
- ).toEqual({ state: 'unknown', root: null })
52
+ ).toEqual({ state: 'unknown', bundle: null })
49
53
  })
50
54
 
51
55
  test('recognizes the current CLI not-installed diagnostic', () => {
@@ -58,6 +62,6 @@ describe('installed Domain introspection', () => {
58
62
  }),
59
63
  1,
60
64
  ),
61
- ).toEqual({ state: 'not-installed', root: null })
65
+ ).toEqual({ state: 'not-installed', bundle: null })
62
66
  })
63
67
  })
@@ -0,0 +1,67 @@
1
+ import { decodeJsonObject, runStudioCliJson, studioCliCommand } from '../cli'
2
+
3
+ function installedDomainArgs(origin: string, instance: string): string[] {
4
+ return ['introspect', origin, '--bundle', '--json', '-i', instance]
5
+ }
6
+
7
+ export function installedDomainCommand(
8
+ origin: string,
9
+ instance: string,
10
+ encodedDescriptor?: string,
11
+ ): string[] {
12
+ return studioCliCommand(installedDomainArgs(origin, instance), encodedDescriptor)
13
+ }
14
+
15
+ export type InstalledDomainProbe =
16
+ | { state: 'installed'; bundle: unknown }
17
+ | { state: 'not-installed' | 'unknown'; bundle: null }
18
+
19
+ function jsonObject(text: string): Record<string, unknown> | null {
20
+ try {
21
+ const value = JSON.parse(text)
22
+ return value !== null && typeof value === 'object' && !Array.isArray(value) ? value : null
23
+ } catch {
24
+ return null
25
+ }
26
+ }
27
+
28
+ export function installedDomainProbeResult(
29
+ stdout: string,
30
+ stderr: string,
31
+ exitCode: number,
32
+ ): InstalledDomainProbe {
33
+ const output = jsonObject(stdout)
34
+ const diagnostic = jsonObject(stderr)
35
+ const error = output?.error ?? diagnostic?.error
36
+ if (
37
+ error === 'DOMAIN_NOT_INSTALLED' ||
38
+ error === 'NOT_FOUND' ||
39
+ /\b(?:DOMAIN_NOT_INSTALLED|NOT_FOUND)\b/.test(`${stdout}\n${stderr}`)
40
+ ) {
41
+ return { state: 'not-installed', bundle: null }
42
+ }
43
+
44
+ if (exitCode === 0) {
45
+ const bundle = output?.bundle
46
+ if (
47
+ bundle !== null &&
48
+ typeof bundle === 'object' &&
49
+ !Array.isArray(bundle) &&
50
+ Object.prototype.hasOwnProperty.call(bundle, 'root')
51
+ ) {
52
+ return { state: 'installed', bundle }
53
+ }
54
+ }
55
+ return { state: 'unknown', bundle: null }
56
+ }
57
+
58
+ export async function getInstalledDomain(
59
+ origin: string,
60
+ instance: string,
61
+ timeoutMs = 8000,
62
+ ): Promise<InstalledDomainProbe> {
63
+ const result = await runStudioCliJson(installedDomainArgs(origin, instance), decodeJsonObject, {
64
+ timeoutMs,
65
+ })
66
+ return installedDomainProbeResult(result.stdout, result.stderr, result.exitCode)
67
+ }
@@ -0,0 +1,12 @@
1
+ import { expect, test } from 'bun:test'
2
+
3
+ import { schemaRevisionDrift } from './status'
4
+
5
+ test('computes drift only from two admitted canonical revisions', () => {
6
+ const local = `sha256:${'a'.repeat(64)}` as const
7
+ const other = `sha256:${'b'.repeat(64)}` as const
8
+ expect(schemaRevisionDrift(local, local)).toBe('in-sync')
9
+ expect(schemaRevisionDrift(local, other)).toBe('drifted')
10
+ expect(schemaRevisionDrift(local, null)).toBe('unknown')
11
+ expect(schemaRevisionDrift(null, other)).toBe('unknown')
12
+ })
@@ -0,0 +1,49 @@
1
+ import type { InstanceStatus, SchemaRevision } from '../../shared/types'
2
+ import type { DomainHandle } from '../domain'
3
+
4
+ import { admittedBundleRevision } from '../introspect/revision'
5
+ import { hasProdScript } from './deploy'
6
+ import { lastDeploy } from './deploy-record'
7
+ import { getInstalledDomain } from './probe'
8
+
9
+ export function schemaRevisionDrift(
10
+ localRevision: SchemaRevision | null,
11
+ installedRevision: SchemaRevision | null,
12
+ ): InstanceStatus['drift'] {
13
+ if (!localRevision || !installedRevision) return 'unknown'
14
+ return localRevision === installedRevision ? 'in-sync' : 'drifted'
15
+ }
16
+
17
+ export async function instanceStatus(
18
+ handle: DomainHandle,
19
+ deployTarget: string | null,
20
+ origin: string | null,
21
+ localRevision: SchemaRevision | null,
22
+ ): Promise<InstanceStatus> {
23
+ const deployable = hasProdScript(handle.root)
24
+ const last = lastDeploy(handle.root)
25
+ let install: InstanceStatus['install'] = 'unknown'
26
+ let installedRevision: SchemaRevision | null = null
27
+ let drift: InstanceStatus['drift'] = 'unknown'
28
+
29
+ if (origin && deployTarget) {
30
+ const probe = await getInstalledDomain(origin, deployTarget)
31
+ if (probe.state === 'installed') {
32
+ install = 'installed'
33
+ installedRevision = await admittedBundleRevision(handle.root, probe.bundle)
34
+ drift = schemaRevisionDrift(localRevision, installedRevision)
35
+ } else if (probe.state === 'not-installed') {
36
+ install = 'not-installed'
37
+ }
38
+ }
39
+
40
+ return {
41
+ deployTarget,
42
+ deployable,
43
+ install,
44
+ drift,
45
+ localRevision,
46
+ installedRevision,
47
+ lastDeploy: last,
48
+ }
49
+ }
@@ -0,0 +1,57 @@
1
+ import { existsSync } from 'node:fs'
2
+ import { join } from 'node:path'
3
+
4
+ import type { ClientTree } from '../../../shared/types'
5
+
6
+ import { listDirs, listFiles, readTextSafe } from './source'
7
+
8
+ // Client tree and best-effort top-level route registry parsing.
9
+ const RESERVED_CLIENT_DIRS = new Set(['shell', 'ui', 'views'])
10
+
11
+ export function buildClientTree(
12
+ root: string,
13
+ clientDir: string | null = join(root, 'client'),
14
+ ): ClientTree {
15
+ // Current SDK projects own presentation modules directly under ui/. Legacy
16
+ // projects still point at a client package whose authored tree is client/src.
17
+ const srcDir = clientDir
18
+ ? join(clientDir, 'src')
19
+ : existsSync(join(root, 'ui'))
20
+ ? join(root, 'ui')
21
+ : ''
22
+ if (!existsSync(srcDir)) {
23
+ return { shell: [], features: [], routes: {}, present: false }
24
+ }
25
+
26
+ const shell = listFiles(join(srcDir, 'shell'))
27
+
28
+ const features = listDirs(srcDir)
29
+ .filter((d) => !RESERVED_CLIENT_DIRS.has(d))
30
+ .map((name) => ({ name, files: listFiles(join(srcDir, name)) }))
31
+
32
+ const routes = parseRoutes(
33
+ listFiles(srcDir)
34
+ .filter((file) => /\.[cm]?[jt]sx?$/.test(file))
35
+ .map((file) => join(srcDir, file)),
36
+ )
37
+
38
+ return { shell, features, routes, present: true }
39
+ }
40
+
41
+ /**
42
+ * Best-effort parse of top-level client route registries. Domains call these
43
+ * maps ROUTES, VIEW_REGISTRY, or another local name; the stable contract is a
44
+ * quoted `/ui/…` key pointing at a component identifier.
45
+ */
46
+ function parseRoutes(files: string[]): Record<string, string> {
47
+ const routes: Record<string, string> = {}
48
+ for (const file of files) {
49
+ const src = readTextSafe(file)
50
+ const entryRe = /['"`](\/ui\/[^'"`]+)['"`]\s*:\s*([A-Za-z_$][\w$.]*)/g
51
+ let match: RegExpExecArray | null
52
+ while ((match = entryRe.exec(src)) !== null) {
53
+ routes[match[1]] = match[2]
54
+ }
55
+ }
56
+ return routes
57
+ }