@astrale-os/cli 0.4.0-alpha.13
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/.check-workspace.cjs +40 -0
- package/README.md +151 -0
- package/dist/astrale.js +59749 -0
- package/package.json +90 -0
- package/src/command.ts +40 -0
- package/src/commands/__tests__/admin-instance.test.ts +73 -0
- package/src/commands/__tests__/auth-login.test.ts +178 -0
- package/src/commands/__tests__/auth-token.test.ts +223 -0
- package/src/commands/__tests__/call.test.ts +72 -0
- package/src/commands/__tests__/domain-list.test.ts +74 -0
- package/src/commands/__tests__/help-contract.test.ts +136 -0
- package/src/commands/__tests__/install-identity-override.test.ts +65 -0
- package/src/commands/__tests__/instance-bookmark.test.ts +101 -0
- package/src/commands/__tests__/instance-create-hosts.test.ts +29 -0
- package/src/commands/__tests__/instance-list-rows.test.ts +63 -0
- package/src/commands/__tests__/logs.test.ts +117 -0
- package/src/commands/__tests__/ls.test.ts +25 -0
- package/src/commands/__tests__/setup-plan.test.ts +61 -0
- package/src/commands/admin/status.ts +61 -0
- package/src/commands/admin/use.ts +77 -0
- package/src/commands/auth/login.ts +82 -0
- package/src/commands/auth/logout.ts +50 -0
- package/src/commands/auth/status.ts +86 -0
- package/src/commands/auth/token.ts +162 -0
- package/src/commands/browser.ts +207 -0
- package/src/commands/call.ts +300 -0
- package/src/commands/describe.ts +182 -0
- package/src/commands/domain/install.ts +420 -0
- package/src/commands/domain/list.ts +154 -0
- package/src/commands/domain/publish.ts +155 -0
- package/src/commands/get.ts +60 -0
- package/src/commands/identity/create.ts +26 -0
- package/src/commands/identity/delete.ts +18 -0
- package/src/commands/identity/export.ts +66 -0
- package/src/commands/identity/import.ts +101 -0
- package/src/commands/identity/list.ts +56 -0
- package/src/commands/identity/register.ts +170 -0
- package/src/commands/identity/sync.ts +32 -0
- package/src/commands/identity/unsync.ts +24 -0
- package/src/commands/identity/use.ts +18 -0
- package/src/commands/identity/whoami.ts +34 -0
- package/src/commands/idp/add.ts +150 -0
- package/src/commands/idp/list.ts +57 -0
- package/src/commands/idp/refresh.ts +38 -0
- package/src/commands/idp/remove.ts +36 -0
- package/src/commands/idp/show.ts +29 -0
- package/src/commands/instance/active.ts +64 -0
- package/src/commands/instance/bookmark.ts +72 -0
- package/src/commands/instance/create.ts +69 -0
- package/src/commands/instance/delete.ts +72 -0
- package/src/commands/instance/forget.ts +26 -0
- package/src/commands/instance/list.ts +149 -0
- package/src/commands/instance/status.ts +42 -0
- package/src/commands/instance/use.ts +210 -0
- package/src/commands/logs.ts +347 -0
- package/src/commands/ls.ts +229 -0
- package/src/commands/query.ts +32 -0
- package/src/commands/setup.ts +54 -0
- package/src/commands/status.ts +60 -0
- package/src/commands/studio.ts +401 -0
- package/src/commands/token.ts +77 -0
- package/src/commands/update.ts +267 -0
- package/src/commands/use.ts +87 -0
- package/src/errors.ts +65 -0
- package/src/kernel/__tests__/auth.test.ts +77 -0
- package/src/kernel/__tests__/errors.test.ts +43 -0
- package/src/kernel/__tests__/remote-routing.test.ts +70 -0
- package/src/kernel/auth.ts +234 -0
- package/src/kernel/ca-fetch.ts +119 -0
- package/src/kernel/client.ts +191 -0
- package/src/kernel/errors.ts +280 -0
- package/src/kernel/expand.ts +217 -0
- package/src/kernel/index.ts +14 -0
- package/src/kernel/options.ts +22 -0
- package/src/kernel/remote-routing.ts +88 -0
- package/src/kernel/run.ts +63 -0
- package/src/kernel/types.ts +14 -0
- package/src/lib/__tests__/admin-target.test.ts +112 -0
- package/src/lib/__tests__/binary.test.ts +56 -0
- package/src/lib/__tests__/command-dx.test.ts +58 -0
- package/src/lib/__tests__/concurrency.test.ts +62 -0
- package/src/lib/__tests__/config.test.ts +53 -0
- package/src/lib/__tests__/design.test.ts +99 -0
- package/src/lib/__tests__/domain-identity.test.ts +60 -0
- package/src/lib/__tests__/format.test.ts +22 -0
- package/src/lib/__tests__/fs-atomic.test.ts +104 -0
- package/src/lib/__tests__/identity.test.ts +79 -0
- package/src/lib/__tests__/idp-session.driver.ts +53 -0
- package/src/lib/__tests__/idp-session.test.ts +357 -0
- package/src/lib/__tests__/idp.test.ts +385 -0
- package/src/lib/__tests__/instance-candidates.test.ts +73 -0
- package/src/lib/__tests__/instance-target.test.ts +183 -0
- package/src/lib/__tests__/instance.test.ts +136 -0
- package/src/lib/__tests__/keys.test.ts +129 -0
- package/src/lib/__tests__/local-status.test.ts +202 -0
- package/src/lib/__tests__/output.test.ts +150 -0
- package/src/lib/__tests__/panel.test.ts +40 -0
- package/src/lib/__tests__/port.test.ts +44 -0
- package/src/lib/__tests__/prompt.test.ts +25 -0
- package/src/lib/__tests__/sdk-deps.test.ts +68 -0
- package/src/lib/__tests__/self.test.ts +272 -0
- package/src/lib/__tests__/studio-server-deps.test.ts +74 -0
- package/src/lib/__tests__/table.test.ts +53 -0
- package/src/lib/__tests__/update.test.ts +246 -0
- package/src/lib/__tests__/use-target.test.ts +56 -0
- package/src/lib/__tests__/validation.test.ts +34 -0
- package/src/lib/admin-domain.ts +25 -0
- package/src/lib/admin-instance.ts +26 -0
- package/src/lib/admin-target.ts +217 -0
- package/src/lib/binary.ts +131 -0
- package/src/lib/browser.ts +150 -0
- package/src/lib/command-dx.ts +161 -0
- package/src/lib/concurrency.ts +31 -0
- package/src/lib/config.ts +45 -0
- package/src/lib/domain-identity.ts +49 -0
- package/src/lib/env.ts +49 -0
- package/src/lib/format.ts +4 -0
- package/src/lib/fs-atomic.ts +126 -0
- package/src/lib/identity.ts +256 -0
- package/src/lib/idp-session.ts +134 -0
- package/src/lib/idp.ts +876 -0
- package/src/lib/instance-candidates.ts +49 -0
- package/src/lib/instance-target.ts +182 -0
- package/src/lib/instance.ts +395 -0
- package/src/lib/keys.ts +294 -0
- package/src/lib/local-status.ts +152 -0
- package/src/lib/log.ts +116 -0
- package/src/lib/login-flow.ts +164 -0
- package/src/lib/meta.ts +86 -0
- package/src/lib/output.ts +222 -0
- package/src/lib/panel.ts +61 -0
- package/src/lib/paths.ts +11 -0
- package/src/lib/port.ts +41 -0
- package/src/lib/proc.ts +82 -0
- package/src/lib/prompt.ts +136 -0
- package/src/lib/provision-instance.ts +170 -0
- package/src/lib/sdk-deps.ts +104 -0
- package/src/lib/self.ts +166 -0
- package/src/lib/skills.ts +171 -0
- package/src/lib/table.ts +62 -0
- package/src/lib/update.ts +315 -0
- package/src/lib/use-target.ts +24 -0
- package/src/lib/validation.ts +59 -0
- package/src/program.ts +200 -0
- package/src/registry.ts +59 -0
- package/src/setup/__tests__/util.test.ts +29 -0
- package/src/setup/engine.ts +83 -0
- package/src/setup/render.ts +109 -0
- package/src/setup/steps/admin.ts +78 -0
- package/src/setup/steps/agent-browser.ts +81 -0
- package/src/setup/steps/auth.ts +54 -0
- package/src/setup/steps/domain.ts +68 -0
- package/src/setup/steps/index.ts +18 -0
- package/src/setup/steps/instance.ts +119 -0
- package/src/setup/steps/skills-bridge.ts +70 -0
- package/src/setup/steps/skills.ts +59 -0
- package/src/setup/types.ts +61 -0
- package/src/setup/util.ts +34 -0
- package/src/test-utils.ts +18 -0
- package/studio/client/dist/assets/index-DOwzZAEK.css +1 -0
- package/studio/client/dist/assets/index-wtU0Zxhy.js +183 -0
- package/studio/client/dist/index.html +13 -0
- package/studio/package.json +62 -0
- package/studio/server/agent/ask.ts +68 -0
- package/studio/server/agent/bridge-mcp.ts +182 -0
- package/studio/server/agent/bridge.ts +188 -0
- package/studio/server/agent/claude.ts +666 -0
- package/studio/server/agent/mock.ts +186 -0
- package/studio/server/agent/prompt.ts +202 -0
- package/studio/server/agent/registry.ts +29 -0
- package/studio/server/agent/runner.ts +484 -0
- package/studio/server/agent/schema-map.ts +112 -0
- package/studio/server/agent/types.ts +120 -0
- package/studio/server/api.ts +574 -0
- package/studio/server/cache.ts +138 -0
- package/studio/server/detect.ts +81 -0
- package/studio/server/domain.ts +70 -0
- package/studio/server/index.ts +136 -0
- package/studio/server/introspect/anatomy-extras.ts +398 -0
- package/studio/server/introspect/anatomy.ts +108 -0
- package/studio/server/introspect/bundle.ts +57 -0
- package/studio/server/introspect/core-extractor.ts +119 -0
- package/studio/server/introspect/core.ts +44 -0
- package/studio/server/introspect/diff.ts +133 -0
- package/studio/server/introspect/extractor.ts +102 -0
- package/studio/server/introspect/hash.ts +21 -0
- package/studio/server/introspect/overlay-tsmorph.ts +874 -0
- package/studio/server/introspect/overlay.ts +57 -0
- package/studio/server/introspect/runtime.ts +99 -0
- package/studio/server/introspect/schema-refs.ts +46 -0
- package/studio/server/lifecycle.ts +38 -0
- package/studio/server/sse.ts +57 -0
- package/studio/server/state/baseline.ts +211 -0
- package/studio/server/state/catalog.ts +117 -0
- package/studio/server/state/comments.ts +321 -0
- package/studio/server/state/context.ts +167 -0
- package/studio/server/state/copy.ts +156 -0
- package/studio/server/state/create.ts +156 -0
- package/studio/server/state/documents.ts +70 -0
- package/studio/server/state/env.ts +161 -0
- package/studio/server/state/git.ts +75 -0
- package/studio/server/state/handoff.ts +55 -0
- package/studio/server/state/harness-gateway.ts +181 -0
- package/studio/server/state/harness-token.ts +0 -0
- package/studio/server/state/instance.ts +244 -0
- package/studio/server/state/integrations.ts +55 -0
- package/studio/server/state/layout.ts +55 -0
- package/studio/server/state/settings.ts +39 -0
- package/studio/server/state/store.ts +97 -0
- package/studio/server/state/updates.ts +63 -0
- package/studio/server/state/usage.ts +37 -0
- package/studio/server/state/views.ts +138 -0
- package/studio/server/state/visibility.ts +33 -0
- package/studio/server/watch.ts +81 -0
- package/studio/server/workspace-state.ts +26 -0
- package/studio/server/workspace-watch.ts +101 -0
- package/studio/shared/types.ts +873 -0
- package/studio/tsconfig.json +23 -0
- package/tsconfig.json +14 -0
package/src/program.ts
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { Command, Option } from 'commander'
|
|
2
|
+
|
|
3
|
+
import type { CommandDefinition } from './command'
|
|
4
|
+
|
|
5
|
+
import pkg from '../package.json' with { type: 'json' }
|
|
6
|
+
import { KERNEL_PASSTHROUGH_OPTIONS } from './kernel/options'
|
|
7
|
+
import { RAW_OUTPUT_OPTIONS } from './lib/output'
|
|
8
|
+
import { registerCommand, registerGroup } from './registry'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Build the fully-wired Commander program (every command + group registered)
|
|
12
|
+
* WITHOUT parsing argv. `bin/astrale.ts` is a thin shim that calls this and
|
|
13
|
+
* `.parse()`; tests import it to walk the command tree (the `--help` surface
|
|
14
|
+
* is asserted to be the source of truth it claims to be — see
|
|
15
|
+
* `commands/__tests__/help-contract.test.ts`).
|
|
16
|
+
*/
|
|
17
|
+
export async function buildProgram(): Promise<Command> {
|
|
18
|
+
const program = new Command()
|
|
19
|
+
|
|
20
|
+
program
|
|
21
|
+
.name('astrale')
|
|
22
|
+
.description('Astrale CLI — connect to existing Astrale kernels')
|
|
23
|
+
// Single source of truth = package.json (bumped by release-please together
|
|
24
|
+
// with .release-please-manifest.json). Never hand-write a version literal.
|
|
25
|
+
.version(pkg.version)
|
|
26
|
+
.showSuggestionAfterError(true)
|
|
27
|
+
.addOption(new Option('--ci', 'Machine mode: no prompts, structured errors on stderr'))
|
|
28
|
+
.addOption(new Option('--no-prompt', 'Disable interactive prompts'))
|
|
29
|
+
.addOption(
|
|
30
|
+
new Option('--offline-ok', 'Tolerate offline state for commands that can operate locally'),
|
|
31
|
+
)
|
|
32
|
+
.addOption(
|
|
33
|
+
new Option('--log-level <level>', 'Log level').choices(['debug', 'info', 'warn', 'error']),
|
|
34
|
+
)
|
|
35
|
+
.addOption(new Option('--log-format <format>', 'Log output format').choices(['text', 'json']))
|
|
36
|
+
.action(async () => {
|
|
37
|
+
// Bare `astrale` in an interactive terminal with nothing connected yet →
|
|
38
|
+
// launch the guided setup. Otherwise (configured, piped, or CI) show help.
|
|
39
|
+
if (process.stdin.isTTY && process.stdout.isTTY) {
|
|
40
|
+
const { shouldAutostartSetup } = await import('./setup/engine')
|
|
41
|
+
if (await shouldAutostartSetup()) {
|
|
42
|
+
await (await import('./commands/setup')).default.action(undefined, {})
|
|
43
|
+
return
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
program.help()
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
// Options shared by every kernel-touching command (call / token / get / ls /
|
|
50
|
+
// describe / query + `domain install`). Merged onto the command's own
|
|
51
|
+
// options at the registration site so the list stays single-sourced — the
|
|
52
|
+
// command-definition files only carry their command-specific options.
|
|
53
|
+
const kernelOptions = [
|
|
54
|
+
{
|
|
55
|
+
flags: '--format <type>',
|
|
56
|
+
description: 'Output format (default: yaml in TTY, json when piped)',
|
|
57
|
+
choices: ['yaml', 'json'],
|
|
58
|
+
},
|
|
59
|
+
...RAW_OUTPUT_OPTIONS,
|
|
60
|
+
...KERNEL_PASSTHROUGH_OPTIONS,
|
|
61
|
+
]
|
|
62
|
+
|
|
63
|
+
const withKernelOptions = (def: CommandDefinition): CommandDefinition => ({
|
|
64
|
+
...def,
|
|
65
|
+
options: [...(def.options ?? []), ...kernelOptions],
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
// Verbatim alias of `identity whoami` — defer to the command-definition
|
|
69
|
+
// module so options stay in sync.
|
|
70
|
+
const whoamiMod = await import('./commands/identity/whoami')
|
|
71
|
+
registerCommand(program, {
|
|
72
|
+
name: 'whoami',
|
|
73
|
+
description: 'Show the current default identity (alias for identity whoami)',
|
|
74
|
+
options: whoamiMod.default.options,
|
|
75
|
+
action: whoamiMod.default.action,
|
|
76
|
+
})
|
|
77
|
+
registerCommand(program, (await import('./commands/setup')).default)
|
|
78
|
+
registerCommand(program, (await import('./commands/use')).default)
|
|
79
|
+
registerCommand(program, (await import('./commands/update')).default)
|
|
80
|
+
|
|
81
|
+
// ── Graph / kernel ─────────────────────────────────────────────
|
|
82
|
+
registerCommand(program, withKernelOptions((await import('./commands/call')).default))
|
|
83
|
+
registerCommand(program, withKernelOptions((await import('./commands/token')).default))
|
|
84
|
+
registerCommand(program, withKernelOptions((await import('./commands/get')).default))
|
|
85
|
+
registerCommand(program, withKernelOptions((await import('./commands/ls')).default))
|
|
86
|
+
registerCommand(program, withKernelOptions((await import('./commands/describe')).default))
|
|
87
|
+
registerCommand(program, withKernelOptions((await import('./commands/query')).default))
|
|
88
|
+
registerCommand(program, withKernelOptions((await import('./commands/logs')).default))
|
|
89
|
+
registerCommand(program, (await import('./commands/status')).default)
|
|
90
|
+
registerCommand(program, (await import('./commands/browser')).default)
|
|
91
|
+
registerCommand(program, (await import('./commands/studio')).default)
|
|
92
|
+
|
|
93
|
+
registerGroup(program, {
|
|
94
|
+
name: 'instance',
|
|
95
|
+
description: 'Manage admin-provisioned instances and local bookmarks',
|
|
96
|
+
commands: [
|
|
97
|
+
withKernelOptions((await import('./commands/instance/list')).default),
|
|
98
|
+
(await import('./commands/instance/bookmark')).default,
|
|
99
|
+
(await import('./commands/instance/forget')).default,
|
|
100
|
+
withKernelOptions((await import('./commands/instance/create')).default),
|
|
101
|
+
withKernelOptions((await import('./commands/instance/delete')).default),
|
|
102
|
+
withKernelOptions((await import('./commands/instance/status')).default),
|
|
103
|
+
(await import('./commands/instance/active')).default,
|
|
104
|
+
(await import('./commands/instance/use')).default,
|
|
105
|
+
],
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
registerGroup(program, {
|
|
109
|
+
name: 'domain',
|
|
110
|
+
description: 'List, publish, and install domains (admin catalog + per-instance install)',
|
|
111
|
+
commands: [
|
|
112
|
+
withKernelOptions((await import('./commands/domain/list')).default),
|
|
113
|
+
withKernelOptions((await import('./commands/domain/publish')).default),
|
|
114
|
+
withKernelOptions((await import('./commands/domain/install')).default),
|
|
115
|
+
],
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
registerGroup(program, {
|
|
119
|
+
name: 'admin',
|
|
120
|
+
description: 'Configure the admin kernel',
|
|
121
|
+
commands: [
|
|
122
|
+
(await import('./commands/admin/status')).default,
|
|
123
|
+
(await import('./commands/admin/use')).default,
|
|
124
|
+
],
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
registerGroup(program, {
|
|
128
|
+
name: 'identity',
|
|
129
|
+
description: 'Manage CLI identities & delegation keypairs',
|
|
130
|
+
commands: [
|
|
131
|
+
(await import('./commands/identity/create')).default,
|
|
132
|
+
(await import('./commands/identity/register')).default,
|
|
133
|
+
(await import('./commands/identity/list')).default,
|
|
134
|
+
(await import('./commands/identity/use')).default,
|
|
135
|
+
(await import('./commands/identity/whoami')).default,
|
|
136
|
+
(await import('./commands/identity/delete')).default,
|
|
137
|
+
(await import('./commands/identity/sync')).default,
|
|
138
|
+
(await import('./commands/identity/unsync')).default,
|
|
139
|
+
(await import('./commands/identity/export')).default,
|
|
140
|
+
(await import('./commands/identity/import')).default,
|
|
141
|
+
],
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
registerGroup(program, {
|
|
145
|
+
name: 'auth',
|
|
146
|
+
description: 'Authenticate with configured identity providers',
|
|
147
|
+
commands: [
|
|
148
|
+
(await import('./commands/auth/login')).default,
|
|
149
|
+
(await import('./commands/auth/token')).default,
|
|
150
|
+
(await import('./commands/auth/logout')).default,
|
|
151
|
+
(await import('./commands/auth/status')).default,
|
|
152
|
+
],
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
registerGroup(program, {
|
|
156
|
+
name: 'idp',
|
|
157
|
+
description: 'Manage OpenID Connect identity providers',
|
|
158
|
+
commands: [
|
|
159
|
+
(await import('./commands/idp/add')).default,
|
|
160
|
+
(await import('./commands/idp/list')).default,
|
|
161
|
+
(await import('./commands/idp/show')).default,
|
|
162
|
+
(await import('./commands/idp/refresh')).default,
|
|
163
|
+
(await import('./commands/idp/remove')).default,
|
|
164
|
+
],
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
program.addHelpText(
|
|
168
|
+
'after',
|
|
169
|
+
`
|
|
170
|
+
Command groups:
|
|
171
|
+
Getting started setup (sign in, pick an instance, equip your workspace)
|
|
172
|
+
Kernel ls, get, call, query, describe, token
|
|
173
|
+
Management admin, instance, domain, identity, auth, idp, update
|
|
174
|
+
Agent browser (drive the GUI via agent-browser)
|
|
175
|
+
Studio studio (launch the local Domain Studio GUI for a workspace)
|
|
176
|
+
|
|
177
|
+
Path syntax:
|
|
178
|
+
/domain Domain node
|
|
179
|
+
/domain/class.Name Class node (or /domain/interface.Name)
|
|
180
|
+
/domain/class.Name/method Static method — single slash
|
|
181
|
+
(interface-hosted static: /domain/interface.Name/method)
|
|
182
|
+
<nodePath>::method Instance method dispatch — double colon ::
|
|
183
|
+
@nodeId Reference a node by its UID
|
|
184
|
+
@nodeId::method Instance method on a node by UID
|
|
185
|
+
|
|
186
|
+
Examples:
|
|
187
|
+
$ astrale ls /
|
|
188
|
+
$ astrale studio
|
|
189
|
+
$ astrale admin status
|
|
190
|
+
$ astrale update --check
|
|
191
|
+
$ astrale instance bookmark staging --url https://kernel.example.com
|
|
192
|
+
$ astrale instance create my-app
|
|
193
|
+
$ astrale instance status staging
|
|
194
|
+
$ astrale token --audience dist.astrale.ai --ttl 3600
|
|
195
|
+
$ astrale query 'MATCH (n) RETURN n LIMIT 5'
|
|
196
|
+
`,
|
|
197
|
+
)
|
|
198
|
+
|
|
199
|
+
return program
|
|
200
|
+
}
|
package/src/registry.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type Command, Option } from 'commander'
|
|
2
|
+
|
|
3
|
+
import type { CommandDefinition, CommandGroup } from './command'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Register a single command on a Commander program or subcommand.
|
|
7
|
+
*/
|
|
8
|
+
export function registerCommand(parent: Command, def: CommandDefinition): void {
|
|
9
|
+
const cmd = parent.command(def.name).description(def.description)
|
|
10
|
+
|
|
11
|
+
if (def.summary) cmd.summary(def.summary)
|
|
12
|
+
|
|
13
|
+
if (def.aliases) {
|
|
14
|
+
for (const alias of def.aliases) cmd.alias(alias)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (def.arguments) {
|
|
18
|
+
for (const arg of def.arguments) {
|
|
19
|
+
const bracket = arg.required !== false ? `<${arg.name}>` : `[${arg.name}]`
|
|
20
|
+
cmd.argument(bracket, arg.description)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (def.options) {
|
|
25
|
+
for (const opt of def.options) {
|
|
26
|
+
if (opt.choices) {
|
|
27
|
+
const o = new Option(opt.flags, opt.description)
|
|
28
|
+
o.choices(opt.choices)
|
|
29
|
+
if (opt.default !== undefined) o.default(opt.default)
|
|
30
|
+
cmd.addOption(o)
|
|
31
|
+
} else if (opt.default !== undefined) {
|
|
32
|
+
cmd.option(opt.flags, opt.description, opt.default)
|
|
33
|
+
} else {
|
|
34
|
+
cmd.option(opt.flags, opt.description)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
cmd.action(def.action)
|
|
40
|
+
|
|
41
|
+
if (def.afterHelpText) cmd.addHelpText('after', def.afterHelpText)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Register a command group (subcommand with nested commands). Supports
|
|
46
|
+
* one level of nested subgroups via `group.subgroups`.
|
|
47
|
+
*/
|
|
48
|
+
export function registerGroup(parent: Command, group: CommandGroup): void {
|
|
49
|
+
const sub = parent.command(group.name).description(group.description)
|
|
50
|
+
if (group.summary) sub.summary(group.summary)
|
|
51
|
+
for (const def of group.commands) {
|
|
52
|
+
registerCommand(sub, def)
|
|
53
|
+
}
|
|
54
|
+
if (group.subgroups) {
|
|
55
|
+
for (const nested of group.subgroups) {
|
|
56
|
+
registerGroup(sub, nested)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test'
|
|
2
|
+
|
|
3
|
+
import { guiOrigin, slugError, urlError } from '../util'
|
|
4
|
+
|
|
5
|
+
describe('guiOrigin — the clickable instance URL', () => {
|
|
6
|
+
test('strips the /api path bookmarks carry', () => {
|
|
7
|
+
expect(guiOrigin('https://my-app.eu.astrale.ai/api')).toBe('https://my-app.eu.astrale.ai')
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
test('leaves a bare origin untouched', () => {
|
|
11
|
+
expect(guiOrigin('https://my-app.eu.astrale.ai')).toBe('https://my-app.eu.astrale.ai')
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
test('returns the input verbatim when it is not a URL', () => {
|
|
15
|
+
expect(guiOrigin('not a url')).toBe('not a url')
|
|
16
|
+
})
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
describe('inquirer validators', () => {
|
|
20
|
+
test('slugError accepts a DNS-label slug and rejects junk', () => {
|
|
21
|
+
expect(slugError('my-app')).toBe(true)
|
|
22
|
+
expect(typeof slugError('Not A Slug')).toBe('string')
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
test('urlError accepts http(s) and rejects junk', () => {
|
|
26
|
+
expect(urlError('https://admin.eu.astrale.ai/api')).toBe(true)
|
|
27
|
+
expect(typeof urlError('ftp://nope')).toBe('string')
|
|
28
|
+
})
|
|
29
|
+
})
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import chalk from 'chalk'
|
|
2
|
+
|
|
3
|
+
import type { SetupContext, SetupOpts } from './types'
|
|
4
|
+
|
|
5
|
+
import { readLocalStatus } from '../lib/local-status'
|
|
6
|
+
import { isMachine } from '../lib/output'
|
|
7
|
+
import { promptMultiSelect } from '../lib/prompt'
|
|
8
|
+
import { type Detected, phaseHeader, renderFinale, renderIntro, renderPlan } from './render'
|
|
9
|
+
import { ALL_STEPS, CONNECT_STEPS, EQUIP_STEPS } from './steps'
|
|
10
|
+
|
|
11
|
+
export type { SetupOpts } from './types'
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Run the setup reconciler. Two modes, one set of steps:
|
|
15
|
+
* - interactive (TTY): hand-hold each Connect step, then offer the unsatisfied
|
|
16
|
+
* Equip steps as a pre-checked multi-select.
|
|
17
|
+
* - --plan / non-interactive: detect everything and report (machine JSON or a
|
|
18
|
+
* human checklist), mutating nothing. This is the agent-facing contract.
|
|
19
|
+
*/
|
|
20
|
+
export async function runSetup(opts: SetupOpts, slug?: string): Promise<void> {
|
|
21
|
+
const machine = isMachine(opts)
|
|
22
|
+
const interactive = !!process.stdin.isTTY && !(opts.ci || opts.noPrompt || process.env.CI)
|
|
23
|
+
const ctx: SetupContext = { interactive, machine, opts, slug }
|
|
24
|
+
|
|
25
|
+
if (opts.plan || !interactive) {
|
|
26
|
+
renderPlan(await detectAll(ctx), ctx)
|
|
27
|
+
return
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
renderIntro()
|
|
31
|
+
|
|
32
|
+
// Connect: required prerequisites, walked in order. Each ensure() re-detects
|
|
33
|
+
// and is a no-op (a ✔ line) when already satisfied, so this resumes cleanly.
|
|
34
|
+
phaseHeader(1, 'Connect to Astrale')
|
|
35
|
+
for (const step of CONNECT_STEPS) {
|
|
36
|
+
await step.ensure(ctx)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Equip: optional. Offer only the unsatisfied ones, pre-checked.
|
|
40
|
+
const equipGaps: Detected[] = []
|
|
41
|
+
for (const step of EQUIP_STEPS) {
|
|
42
|
+
const detection = await step.detect(ctx)
|
|
43
|
+
if (detection.state !== 'satisfied') equipGaps.push({ step, detection })
|
|
44
|
+
}
|
|
45
|
+
if (equipGaps.length > 0) {
|
|
46
|
+
phaseHeader(2, 'Equip your workspace & agents')
|
|
47
|
+
const chosen =
|
|
48
|
+
(await promptMultiSelect(
|
|
49
|
+
'Select what to set up — space toggles, enter confirms:',
|
|
50
|
+
equipGaps.map(({ step, detection }) => ({
|
|
51
|
+
name: `${step.title} ${chalk.dim(`— ${detection.summary}`)}`,
|
|
52
|
+
value: step.id,
|
|
53
|
+
checked: true,
|
|
54
|
+
})),
|
|
55
|
+
)) ?? []
|
|
56
|
+
for (const { step } of equipGaps) {
|
|
57
|
+
if (chosen.includes(step.id)) await step.ensure(ctx)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
await renderFinale()
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function detectAll(ctx: SetupContext): Promise<Detected[]> {
|
|
65
|
+
const detected: Detected[] = []
|
|
66
|
+
for (const step of ALL_STEPS) {
|
|
67
|
+
detected.push({ step, detection: await step.detect(ctx) })
|
|
68
|
+
}
|
|
69
|
+
return detected
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Should a bare `astrale` (no args, interactive terminal) launch setup instead
|
|
74
|
+
* of printing help? Yes only when the user has no active instance — i.e. not
|
|
75
|
+
* yet set up. A configured user gets help.
|
|
76
|
+
*/
|
|
77
|
+
export async function shouldAutostartSetup(): Promise<boolean> {
|
|
78
|
+
try {
|
|
79
|
+
return (await readLocalStatus()).instance === null
|
|
80
|
+
} catch {
|
|
81
|
+
return false
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import chalk from 'chalk'
|
|
2
|
+
|
|
3
|
+
import type { SetupContext, SetupStep, StepDetection, StepState } from './types'
|
|
4
|
+
|
|
5
|
+
import { readLocalStatus } from '../lib/local-status'
|
|
6
|
+
import { output } from '../lib/output'
|
|
7
|
+
import { panel } from '../lib/panel'
|
|
8
|
+
import { guiOrigin } from './util'
|
|
9
|
+
|
|
10
|
+
export type Detected = { step: SetupStep; detection: StepDetection }
|
|
11
|
+
|
|
12
|
+
const MARK: Record<StepState, () => string> = {
|
|
13
|
+
satisfied: () => chalk.green('✔'),
|
|
14
|
+
gap: () => chalk.yellow('○'),
|
|
15
|
+
broken: () => chalk.red('✖'),
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function renderIntro(): void {
|
|
19
|
+
console.log('')
|
|
20
|
+
console.log(`${chalk.bold.cyan('astrale setup')} ${chalk.dim('· get connected and equipped')}`)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function phaseHeader(n: number, title: string): void {
|
|
24
|
+
console.log('')
|
|
25
|
+
console.log(chalk.bold(`${n} · ${title}`))
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The read-only report for `--plan` and non-interactive runs: machine-readable
|
|
30
|
+
* JSON (the agent's contract — each gap carries the command to fix it) or a
|
|
31
|
+
* human checklist mirroring `astrale status`.
|
|
32
|
+
*/
|
|
33
|
+
export function renderPlan(detected: Detected[], ctx: SetupContext): void {
|
|
34
|
+
const connected = detected
|
|
35
|
+
.filter((d) => d.step.group === 'connect')
|
|
36
|
+
.every((d) => d.detection.state === 'satisfied')
|
|
37
|
+
|
|
38
|
+
if (ctx.machine) {
|
|
39
|
+
output(
|
|
40
|
+
{
|
|
41
|
+
connected,
|
|
42
|
+
steps: detected.map(({ step, detection }) => ({
|
|
43
|
+
id: step.id,
|
|
44
|
+
title: step.title,
|
|
45
|
+
group: step.group,
|
|
46
|
+
state: detection.state,
|
|
47
|
+
summary: detection.summary,
|
|
48
|
+
...(detection.fixHint ? { fix: detection.fixHint } : {}),
|
|
49
|
+
})),
|
|
50
|
+
},
|
|
51
|
+
ctx.opts,
|
|
52
|
+
)
|
|
53
|
+
return
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
console.log('')
|
|
57
|
+
console.log(chalk.bold('Astrale setup — status'))
|
|
58
|
+
for (const group of ['connect', 'equip'] as const) {
|
|
59
|
+
const rows = detected.filter((d) => d.step.group === group)
|
|
60
|
+
if (rows.length === 0) continue
|
|
61
|
+
console.log('')
|
|
62
|
+
console.log(chalk.bold(group === 'connect' ? 'Connect' : 'Equip'))
|
|
63
|
+
for (const { detection } of rows) {
|
|
64
|
+
const hint =
|
|
65
|
+
detection.state === 'satisfied' || !detection.fixHint
|
|
66
|
+
? ''
|
|
67
|
+
: ` ${chalk.dim(`→ ${detection.fixHint}`)}`
|
|
68
|
+
console.log(` ${MARK[detection.state]()} ${detection.summary}${hint}`)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
console.log('')
|
|
72
|
+
console.log(
|
|
73
|
+
chalk.dim(
|
|
74
|
+
connected
|
|
75
|
+
? 'Connected. Run `astrale setup` to equip your workspace.'
|
|
76
|
+
: 'Run `astrale setup` in a terminal to fix these interactively.',
|
|
77
|
+
),
|
|
78
|
+
)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Closing recap: the active-instance hero (again) plus the obvious next moves. */
|
|
82
|
+
export async function renderFinale(): Promise<void> {
|
|
83
|
+
const { instance } = await readLocalStatus()
|
|
84
|
+
console.log('')
|
|
85
|
+
if (instance) {
|
|
86
|
+
console.log(
|
|
87
|
+
panel(
|
|
88
|
+
[
|
|
89
|
+
`${chalk.green('✔')} ${chalk.bold("You're all set")}`,
|
|
90
|
+
'',
|
|
91
|
+
` ${chalk.cyan('Instance')} ${chalk.bold(guiOrigin(instance.url))}`,
|
|
92
|
+
],
|
|
93
|
+
{ borderColor: chalk.green },
|
|
94
|
+
),
|
|
95
|
+
)
|
|
96
|
+
} else {
|
|
97
|
+
console.log(
|
|
98
|
+
chalk.yellow('⚠'),
|
|
99
|
+
'Setup finished without an active instance — run `astrale setup` again when ready.',
|
|
100
|
+
)
|
|
101
|
+
}
|
|
102
|
+
console.log('')
|
|
103
|
+
console.log(chalk.bold('Next'))
|
|
104
|
+
console.log(
|
|
105
|
+
` ${chalk.cyan('astrale call /:dist.astrale.ai:class.Echo:echo message=hello')} ${chalk.dim('— smoke test')}`,
|
|
106
|
+
)
|
|
107
|
+
console.log(` ${chalk.cyan('astrale browser')} ${chalk.dim('— drive the GUI as your agent')}`)
|
|
108
|
+
console.log(` ${chalk.cyan('astrale --help')} ${chalk.dim('— everything else')}`)
|
|
109
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { SetupContext, SetupStep } from '../types'
|
|
2
|
+
|
|
3
|
+
import { AdminTargetConfigSchema, DEFAULT_ADMIN_TARGET_NAME } from '../../lib/admin-target'
|
|
4
|
+
import { readConfig, writeConfig } from '../../lib/config'
|
|
5
|
+
import { readLocalStatus } from '../../lib/local-status'
|
|
6
|
+
import { log } from '../../lib/log'
|
|
7
|
+
import { promptText } from '../../lib/prompt'
|
|
8
|
+
import { urlError } from '../util'
|
|
9
|
+
|
|
10
|
+
const FIX = 'astrale admin use --url <admin-url>'
|
|
11
|
+
|
|
12
|
+
async function setAdminUrl(url: string): Promise<void> {
|
|
13
|
+
const config = await readConfig()
|
|
14
|
+
await writeConfig({
|
|
15
|
+
...config,
|
|
16
|
+
admin: AdminTargetConfigSchema.parse({ name: DEFAULT_ADMIN_TARGET_NAME, url, issuer: url }),
|
|
17
|
+
})
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async function setAdminBookmark(bookmark: string): Promise<void> {
|
|
21
|
+
const config = await readConfig()
|
|
22
|
+
await writeConfig({ ...config, admin: AdminTargetConfigSchema.parse({ instance: bookmark }) })
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Step 2 — the admin control plane. There's always a default (admin.eu), so the
|
|
27
|
+
* checklist shows it as satisfied and setup just confirms it with a ✔ line — no
|
|
28
|
+
* prompt, since the default is right for nearly everyone and asking only confused
|
|
29
|
+
* first-run users. Explicit --admin-url / --admin flags still persist immediately,
|
|
30
|
+
* and power users repoint later with `astrale admin use <bookmark>|--url <url>`.
|
|
31
|
+
* The only prompt left is the recovery path when the configured target is broken.
|
|
32
|
+
*/
|
|
33
|
+
export const adminStep: SetupStep = {
|
|
34
|
+
id: 'admin',
|
|
35
|
+
title: 'Admin control plane',
|
|
36
|
+
group: 'connect',
|
|
37
|
+
|
|
38
|
+
async detect() {
|
|
39
|
+
const { admin } = await readLocalStatus()
|
|
40
|
+
if ('error' in admin) {
|
|
41
|
+
return { state: 'broken', summary: `Admin target invalid: ${admin.error}`, fixHint: FIX }
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
state: 'satisfied',
|
|
45
|
+
summary: `${admin.name} (${admin.url})`,
|
|
46
|
+
detail: `source: ${admin.source}`,
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
async ensure(ctx: SetupContext) {
|
|
51
|
+
// Explicit overrides win and persist, no prompt.
|
|
52
|
+
if (ctx.opts.adminUrl) {
|
|
53
|
+
await setAdminUrl(ctx.opts.adminUrl)
|
|
54
|
+
log.success(`Admin control plane set: ${ctx.opts.adminUrl}`)
|
|
55
|
+
return 'fixed'
|
|
56
|
+
}
|
|
57
|
+
if (ctx.opts.admin) {
|
|
58
|
+
await setAdminBookmark(ctx.opts.admin)
|
|
59
|
+
log.success(`Admin control plane set: bookmark "${ctx.opts.admin}"`)
|
|
60
|
+
return 'fixed'
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const { admin } = await readLocalStatus()
|
|
64
|
+
if ('error' in admin) {
|
|
65
|
+
log.warn(`Admin target invalid: ${admin.error}`)
|
|
66
|
+
const url = await promptText('Admin kernel URL', { validate: urlError })
|
|
67
|
+
if (!url) return 'skipped'
|
|
68
|
+
await setAdminUrl(url)
|
|
69
|
+
log.success(`Admin control plane set: ${url}`)
|
|
70
|
+
return 'fixed'
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Configured or baked default: accept it silently — no prompt. Power users
|
|
74
|
+
// repoint with `astrale admin use` (or the --admin-url / --admin flags above).
|
|
75
|
+
log.success(`Admin control plane: ${admin.name} (${admin.url})`)
|
|
76
|
+
return 'unchanged'
|
|
77
|
+
},
|
|
78
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { SetupStep } from '../types'
|
|
2
|
+
|
|
3
|
+
import { AGENT_BROWSER_REPO } from '../../lib/browser'
|
|
4
|
+
import { log } from '../../lib/log'
|
|
5
|
+
import { runInherit } from '../../lib/proc'
|
|
6
|
+
import { confirmDefaultYes } from '../../lib/prompt'
|
|
7
|
+
import { AGENT_BROWSER_SKILL, detectAgentBrowser, detectSkill } from '../../lib/skills'
|
|
8
|
+
|
|
9
|
+
const FIX = 'npm install -g agent-browser && agent-browser install'
|
|
10
|
+
const SKILL_FIX = `npx skills add ${AGENT_BROWSER_REPO} -g`
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Equip — agent-browser, the tool `astrale browser` drives. Two halves: the
|
|
14
|
+
* third-party binary (a global npm install + one-time engine download, so opt-in
|
|
15
|
+
* and confirmed) and its agent skill (so the harness knows the commands). We
|
|
16
|
+
* track BOTH: a skill that the harness can't load is as broken as a missing
|
|
17
|
+
* binary, so detection requires both, and `ensure` wires a missing skill even
|
|
18
|
+
* when the binary is already present (the "installed but not loaded" gap).
|
|
19
|
+
*/
|
|
20
|
+
export const agentBrowserStep: SetupStep = {
|
|
21
|
+
id: 'agent-browser',
|
|
22
|
+
title: 'agent-browser',
|
|
23
|
+
group: 'equip',
|
|
24
|
+
|
|
25
|
+
async detect() {
|
|
26
|
+
const haveBin = await detectAgentBrowser()
|
|
27
|
+
const haveSkill = detectSkill(AGENT_BROWSER_SKILL).installed
|
|
28
|
+
if (haveBin && haveSkill)
|
|
29
|
+
return { state: 'satisfied', summary: 'agent-browser + skill installed' }
|
|
30
|
+
if (haveBin && !haveSkill) {
|
|
31
|
+
return {
|
|
32
|
+
state: 'gap',
|
|
33
|
+
summary: 'agent-browser installed, but its skill is not loaded by the harness',
|
|
34
|
+
fixHint: SKILL_FIX,
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return { state: 'gap', summary: 'agent-browser not installed', fixHint: FIX }
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
async ensure() {
|
|
41
|
+
const haveSkill = () => detectSkill(AGENT_BROWSER_SKILL).installed
|
|
42
|
+
if ((await detectAgentBrowser()) && haveSkill()) {
|
|
43
|
+
log.success('agent-browser already installed')
|
|
44
|
+
return 'unchanged'
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// 1) The binary — third-party global npm + engine download, so confirm it.
|
|
48
|
+
if (!(await detectAgentBrowser())) {
|
|
49
|
+
log.warn(`agent-browser is a third-party global npm package (${AGENT_BROWSER_REPO}).`)
|
|
50
|
+
if (!(await confirmDefaultYes('Install agent-browser globally now?'))) {
|
|
51
|
+
log.dim(` Skipped — install later: ${FIX} && ${SKILL_FIX}`)
|
|
52
|
+
return 'skipped'
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
log.step('npm install -g agent-browser')
|
|
56
|
+
if ((await runInherit('npm', ['install', '-g', 'agent-browser'])) !== 0) {
|
|
57
|
+
log.warn('npm install failed — see the output above.')
|
|
58
|
+
return 'failed'
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
log.step('agent-browser install (downloading the browser engine)')
|
|
62
|
+
if ((await runInherit('agent-browser', ['install'])) !== 0) {
|
|
63
|
+
log.warn('`agent-browser install` failed — re-run it manually.')
|
|
64
|
+
return 'failed'
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// 2) The skill — wire it into the harness so the agent can load it. Runs even
|
|
69
|
+
// when the binary was already present (the installed-but-not-loaded gap).
|
|
70
|
+
if (!haveSkill()) {
|
|
71
|
+
log.step(`${SKILL_FIX} (teaches your agent its commands)`)
|
|
72
|
+
if ((await runInherit('npx', ['skills', 'add', AGENT_BROWSER_REPO, '-g', '-y'])) !== 0) {
|
|
73
|
+
log.warn(`Skill install did not complete — run it later: ${SKILL_FIX}`)
|
|
74
|
+
return 'failed'
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
log.success('agent-browser ready — drive the GUI with `astrale browser`')
|
|
79
|
+
return 'fixed'
|
|
80
|
+
},
|
|
81
|
+
}
|