@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.
- package/README.md +7 -11
- package/dist/astrale.js +3737 -3523
- package/dist/public/connect-core.js +396 -392
- package/dist/public/keys/index.js +371 -378
- package/dist/public/paths/index.js +371 -378
- package/dist/types/lib/idp.d.ts +6 -0
- package/dist/types/lib/meta.d.ts +2 -2
- package/package.json +6 -4
- package/src/admin/binding.ts +168 -0
- package/src/admin/catalog/__tests__/client.test.ts +2 -2
- package/src/admin/catalog/client.ts +4 -9
- package/src/admin/instance/__tests__/client.test.ts +2 -2
- package/src/admin/instance/client.ts +6 -11
- package/src/commands/__tests__/auth-login.test.ts +54 -1
- package/src/commands/__tests__/call.test.ts +5 -1
- package/src/commands/__tests__/domain-install-operation.test.ts +23 -7
- package/src/commands/__tests__/domain-install-owned.test.ts +5 -1
- package/src/commands/__tests__/domain-list.test.ts +83 -4
- package/src/commands/__tests__/install-identity-override.test.ts +30 -19
- package/src/commands/__tests__/studio-descriptor.test.ts +22 -0
- package/src/commands/__tests__/update.test.ts +23 -16
- package/src/commands/domain/install.ts +11 -15
- package/src/commands/domain/list.ts +17 -12
- package/src/commands/studio.ts +20 -0
- package/src/commands/update.ts +9 -5
- package/src/connection/__tests__/errors.test.ts +16 -12
- package/src/connection/__tests__/exchange.test.ts +6 -5
- package/src/connection/exchange.ts +5 -4
- package/src/lib/__tests__/domain-publication.test.ts +144 -0
- package/src/lib/__tests__/idp-session.test.ts +22 -0
- package/src/lib/__tests__/idp.test.ts +2 -0
- package/src/lib/__tests__/instance.test.ts +6 -0
- package/src/lib/__tests__/studio-server-deps.test.ts +53 -16
- package/src/lib/__tests__/update.test.ts +12 -0
- package/src/lib/domain-publication.ts +102 -0
- package/src/lib/idp.ts +5 -1
- package/src/lib/instance.ts +6 -1
- package/src/lib/login-flow.ts +13 -3
- package/src/lib/meta.ts +2 -2
- package/src/lib/update.ts +4 -4
- package/src/program/__tests__/program.test.ts +1 -1
- package/studio/client/dist/assets/{elk-api-D2xgMJvi.js → elk-api-lwhFo7vB.js} +1 -1
- package/studio/client/dist/assets/index-B-c-smo9.js +8 -0
- package/studio/client/dist/assets/index-BckHuAWk.js +81 -0
- package/studio/client/dist/assets/index-C4aNQ6dz.css +1 -0
- package/studio/client/dist/index.html +2 -2
- package/studio/package.json +3 -1
- package/studio/server/agent/bridge/stdio.ts +8 -1
- package/studio/server/agent/conversation.test.ts +10 -5
- package/studio/server/agent/conversation.ts +56 -8
- package/studio/server/agent/harness/codex/loadout.ts +18 -21
- package/studio/server/agent/harness/gateway/config.ts +20 -18
- package/studio/server/agent/harness/selection.ts +9 -1
- package/studio/server/agent/prompts/system.ts +3 -2
- package/studio/server/agent/prompts/turn.ts +13 -4
- package/studio/server/agent/run/completion.ts +2 -2
- package/studio/server/agent/run/preparation.ts +6 -5
- package/studio/server/agent/run/transcript.test.ts +35 -1
- package/studio/server/agent/run/transcript.ts +169 -3
- package/studio/server/agent/run/usage.test.ts +24 -0
- package/studio/server/agent/run/usage.ts +26 -1
- package/studio/server/api/canvas.ts +44 -0
- package/studio/server/api/comments.ts +85 -0
- package/studio/server/api/context.ts +61 -0
- package/studio/server/api/deployment.ts +39 -0
- package/studio/server/api/documents.ts +55 -0
- package/studio/server/api/domain.ts +59 -0
- package/studio/server/api/http.ts +45 -0
- package/studio/server/api/project.ts +57 -0
- package/studio/server/api/schema.ts +12 -0
- package/studio/server/api/views.ts +57 -0
- package/studio/server/api/workspace.ts +60 -0
- package/studio/server/api.test.ts +147 -0
- package/studio/server/api.ts +20 -422
- package/studio/server/cache.test.ts +111 -0
- package/studio/server/cache.ts +163 -9
- package/studio/server/cli-consumers.test.ts +494 -0
- package/studio/server/cli.test.ts +88 -0
- package/studio/server/cli.ts +240 -0
- package/studio/server/client-package.ts +25 -1
- package/studio/server/domain.test.ts +30 -2
- package/studio/server/domain.ts +14 -2
- package/studio/server/environment/dotenv-preview.test.ts +39 -0
- package/studio/server/environment/dotenv-preview.ts +27 -0
- package/studio/server/environment/files.test.ts +53 -0
- package/studio/server/{state/env.ts → environment/files.ts} +7 -48
- package/studio/server/{state → handoff}/copy.ts +21 -6
- package/studio/server/handoff/service.test.ts +22 -0
- package/studio/server/{state/handoff.ts → handoff/service.ts} +21 -14
- package/studio/server/instances/active.ts +72 -0
- package/studio/server/instances/deploy-record.test.ts +31 -0
- package/studio/server/instances/deploy-record.ts +37 -0
- package/studio/server/instances/deploy.ts +56 -0
- package/studio/server/{state/instance.test.ts → instances/probe.test.ts} +25 -21
- package/studio/server/instances/probe.ts +67 -0
- package/studio/server/instances/status.test.ts +12 -0
- package/studio/server/instances/status.ts +49 -0
- package/studio/server/introspect/anatomy/client-tree.ts +57 -0
- package/studio/server/introspect/anatomy/env-fields.ts +66 -0
- package/studio/server/introspect/anatomy/schema-definition.ts +53 -0
- package/studio/server/introspect/anatomy/source.ts +181 -0
- package/studio/server/introspect/anatomy/views/legacy.ts +232 -0
- package/studio/server/introspect/anatomy/views/routes.ts +105 -0
- package/studio/server/introspect/anatomy/views.ts +58 -0
- package/studio/server/introspect/anatomy-extras.test.ts +91 -4
- package/studio/server/introspect/anatomy-extras.ts +7 -726
- package/studio/server/introspect/anatomy.ts +46 -19
- package/studio/server/introspect/bundle.ts +15 -6
- package/studio/server/introspect/canonical-schema.test.ts +79 -0
- package/studio/server/introspect/canonical-schema.ts +80 -18
- package/studio/server/introspect/config-preview.test.ts +32 -0
- package/studio/server/introspect/config-preview.ts +119 -0
- package/studio/server/introspect/diff.test.ts +7 -11
- package/studio/server/introspect/diff.ts +28 -37
- package/studio/server/introspect/extractor.ts +8 -6
- package/studio/server/introspect/hash.ts +5 -2
- package/studio/server/introspect/overlay-tsmorph.ts +7 -1305
- package/studio/server/introspect/revision.test.ts +54 -0
- package/studio/server/introspect/revision.ts +49 -0
- package/studio/server/introspect/runtime.test.ts +63 -5
- package/studio/server/introspect/runtime.ts +49 -3
- package/studio/server/introspect/schema-ir-json.ts +181 -0
- package/studio/server/introspect/source-overlay/annotations.ts +14 -0
- package/studio/server/introspect/source-overlay/handlers.ts +681 -0
- package/studio/server/introspect/source-overlay/kernel-calls.ts +49 -0
- package/studio/server/introspect/source-overlay/project.ts +248 -0
- package/studio/server/introspect/source-overlay/spans.ts +360 -0
- package/studio/server/json.ts +46 -0
- package/studio/server/lifecycle.ts +5 -1
- package/studio/server/sse.test.ts +26 -0
- package/studio/server/sse.ts +4 -1
- package/studio/server/state/baseline.test.ts +212 -1
- package/studio/server/state/baseline.ts +145 -29
- package/studio/server/state/comments.test.ts +66 -1
- package/studio/server/state/comments.ts +173 -10
- package/studio/server/state/context.ts +34 -2
- package/studio/server/state/documents.ts +42 -1
- package/studio/server/state/integrations.ts +27 -1
- package/studio/server/state/layout.test.ts +34 -0
- package/studio/server/state/layout.ts +44 -17
- package/studio/server/state/settings.ts +29 -22
- package/studio/server/state/store.test.ts +122 -0
- package/studio/server/state/store.ts +66 -17
- package/studio/server/state/visibility.ts +22 -7
- package/studio/server/views/model.test.ts +57 -0
- package/studio/server/views/model.ts +66 -0
- package/studio/server/views/runtime.ts +40 -0
- package/studio/server/views/selection-repository.test.ts +31 -0
- package/studio/server/views/selection-repository.ts +60 -0
- package/studio/server/views/session.test.ts +73 -0
- package/studio/server/views/session.ts +166 -0
- package/studio/server/{state/views.test.ts → views/target.test.ts} +8 -159
- package/studio/server/views/target.ts +248 -0
- package/studio/server/watch.ts +1 -1
- package/studio/server/workspace/catalog.test.ts +17 -0
- package/studio/server/workspace/catalog.ts +43 -0
- package/studio/server/{state → workspace}/create.test.ts +1 -1
- package/studio/server/{state → workspace}/create.ts +1 -1
- package/studio/server/{state → workspace}/git.ts +1 -1
- package/studio/server/workspace/updates.ts +83 -0
- package/studio/server/workspace-state.ts +1 -1
- package/studio/shared/contracts/README.md +16 -0
- package/studio/shared/contracts/agent.ts +270 -0
- package/studio/shared/contracts/runtime.ts +50 -0
- package/studio/shared/contracts/schema.ts +462 -0
- package/studio/shared/contracts/surface.test.ts +319 -0
- package/studio/shared/contracts/workspace.ts +274 -0
- package/studio/shared/layout.test.ts +116 -0
- package/studio/shared/schema/identity.test.ts +58 -0
- package/studio/shared/schema/identity.ts +82 -0
- package/studio/shared/types.ts +11 -1099
- package/studio/tsconfig.json +1 -1
- package/viewer/dist/main.js +35 -35
- package/studio/client/dist/assets/index-BMdnsIJA.css +0 -1
- package/studio/client/dist/assets/index-D-vRV8w7.js +0 -8
- package/studio/client/dist/assets/index-LGSWRrk8.js +0 -81
- package/studio/server/state/catalog.ts +0 -117
- package/studio/server/state/instance.ts +0 -280
- package/studio/server/state/updates.ts +0 -63
- package/studio/server/state/views.ts +0 -535
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
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
|
-
|
|
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 {
|
|
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
|
|
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:
|
|
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
|
-
*
|
|
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 '
|
|
12
|
-
import { readComments } from '
|
|
13
|
-
import { materializeAuto } from '
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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 {
|
|
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
|
-
|
|
13
|
-
|
|
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('
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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',
|
|
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',
|
|
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
|
+
}
|