acryl 0.2.7 → 0.2.8

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 CHANGED
@@ -19,8 +19,11 @@ npm install -g acryl
19
19
  ## Run
20
20
 
21
21
  ```bash
22
- acryl # terminal client (default)
23
- acryl web # serve the local ACRYL web runtime
22
+ acryl # the ACRYL app screen in this terminal (same as --tui)
23
+ acryl --tui # the ACRYL app screen in this terminal
24
+ acryl --gui # the ACRYL desktop app (Electron); fetched once if it is not installed
25
+ acryl --web # the ACRYL app screen in your browser (same as: acryl web)
26
+ acryl ade # ACRYL ADE, the agentic development environment
24
27
  ```
25
28
 
26
29
  A standalone Desktop application is distributed separately.
package/bin.js CHANGED
@@ -1,129 +1,15 @@
1
1
  #!/usr/bin/env node
2
- import { spawn } from 'node:child_process'
3
- import { createRequire } from 'node:module'
4
- import { join } from 'node:path'
5
- import { createInterface } from 'node:readline/promises'
6
- import { stdin, stderr } from 'node:process'
7
- import { existsSync } from 'node:fs'
8
- import { fileURLToPath, pathToFileURL } from 'node:url'
9
- import { forwardCommand, launcherCommand } from './forward.js'
10
- import { forwardStopSignals, runtimeCommand, runtimeLauncher, targetFor } from './runtime.js'
11
- import { acquireDesktopInstaller } from './desktop-runtime.js'
12
- import { acquireWebRuntime, fetchReleaseManifest, hasVerifiedWebRuntime, manifestUrl, managedWebRoot, selectWebArtifact, webRuntimeCommand } from './web-runtime.js'
13
-
14
- const require = createRequire(import.meta.url)
15
- const selectorVersion = require('./package.json').version
16
- const args = process.argv.slice(2)
17
-
18
- function run({ command, args: commandArgs }) {
19
- const child = spawn(command, commandArgs, { stdio: 'inherit' })
20
- const stopForwarding = forwardStopSignals(child)
21
- child.once('error', cause => {
22
- stopForwarding()
23
- console.error(`acryl: ${cause.message}`)
24
- process.exitCode = 1
25
- })
26
- child.once('exit', code => {
27
- stopForwarding()
28
- process.exitCode = code ?? 1
29
- })
30
- }
31
-
32
- async function confirmDownload() {
33
- if (!stdin.isTTY || !stderr.isTTY) return false
34
- const prompt = createInterface({ input: stdin, output: stderr })
35
- try {
36
- return (await prompt.question('ACRYL Web will download a verified matching runtime. Continue? [y/N] ')).trim().toLowerCase() === 'y'
37
- } finally { prompt.close() }
38
- }
39
-
40
- function openInstaller(path) {
41
- const opener = process.platform === 'darwin' ? ['open', [path]]
42
- : process.platform === 'win32' ? ['cmd', ['/c', 'start', '', path]]
43
- : ['xdg-open', [path]]
44
- const child = spawn(...opener, { stdio: 'ignore' })
45
- child.once('error', () => {})
46
- }
47
-
48
- async function runDesktop(desktopArgs) {
49
- const noOpen = desktopArgs.includes('--no-open')
50
- const result = await acquireDesktopInstaller({
51
- version: selectorVersion,
52
- ...(noOpen ? {} : { open: openInstaller }),
53
- })
54
- console.log(`ACRYL desktop installer ${result.version}: ${result.path}`)
55
- if (noOpen) console.log('use --no-open to download without launching')
56
- }
57
-
58
- async function runWeb(webArgs) {
59
- const yes = webArgs.includes('--yes') || webArgs.includes('-y')
60
- const forwarded = webArgs.filter(arg => arg !== '--yes' && arg !== '-y')
61
- const target = targetFor({ platform: process.platform, arch: process.arch })
62
- const root = join(managedWebRoot(), selectorVersion, target)
63
- let launcher
64
- try { launcher = runtimeLauncher({ require, platform: process.platform, arch: process.arch }) } catch (cause) {
65
- throw new Error(`matching CLI runtime is unavailable: ${cause instanceof Error ? cause.message : String(cause)}`)
66
- }
67
- // The CLI runtime is resolved first so a partial/broken selector never downloads Web.
68
- void launcher
69
- const manifest = await fetchReleaseManifest(manifestUrl(selectorVersion))
70
- const artifact = selectWebArtifact(manifest, { version: selectorVersion, target })
71
- const cached = hasVerifiedWebRuntime(root, { version: selectorVersion, target, sha256: artifact.sha256 })
72
- if (!cached && !yes && !(await confirmDownload())) {
73
- throw new Error('Web runtime acquisition requires confirmation. Re-run with: acryl web --yes')
74
- }
75
- const result = await acquireWebRuntime({ root: managedWebRoot(), version: selectorVersion, target, manifest })
76
- run(webRuntimeCommand(result.root, forwarded))
77
- }
78
-
79
- /** The launcher (spec 050), bundled into this package as one file at pack time (apps/acryl-launcher-tui/scripts/bundle.mjs). */
80
- const LAUNCHER = fileURLToPath(new URL('./launcher.js', import.meta.url))
81
-
82
- /** A bare `acryl` in a terminal: every step offered; what the person chose then runs exactly as if they had typed it. */
83
- async function openLauncher() {
84
- const { runLauncher } = await import(pathToFileURL(LAUNCHER).href)
85
- const chosen = await runLauncher()
86
- if (!chosen) return
87
- const target = launcherCommand(chosen.command, {
88
- env: process.env, platform: process.platform, cwd: process.cwd(), execPath: process.execPath, bin: fileURLToPath(import.meta.url), exists: existsSync,
89
- })
90
- if (target.error) throw new Error(target.error)
91
- console.log(`\n$ ${chosen.line}\n`)
92
- const child = spawn(target.command, target.args, { stdio: 'inherit', cwd: target.cwd, shell: target.shell === true })
93
- const stopForwarding = forwardStopSignals(child)
94
- child.once('error', cause => { stopForwarding(); console.error(`acryl: ${cause.message}`); process.exitCode = 1 })
95
- child.once('exit', code => { stopForwarding(); process.exitCode = code ?? 1 })
96
- }
97
-
98
- // The short commands (acryl new, plugin, blends, update) run the part that owns them (forward.js).
99
- const forwarded = forwardCommand(args, { env: process.env, platform: process.platform, cwd: process.cwd(), execPath: process.execPath, exists: existsSync })
100
- if (forwarded?.error) {
101
- console.error(`acryl: ${forwarded.error}`)
102
- process.exitCode = 2
103
- } else if (forwarded) {
104
- const child = spawn(forwarded.command, forwarded.args, { stdio: 'inherit', cwd: forwarded.cwd, shell: forwarded.shell === true })
105
- child.once('error', cause => { console.error(`acryl: ${cause.message}`); process.exitCode = 1 })
106
- child.once('exit', code => { process.exitCode = code ?? 1 })
107
- } else if (args[0] === 'web') {
108
- runWeb(args.slice(1)).catch(cause => {
109
- console.error(`acryl: ${cause instanceof Error ? cause.message : String(cause)}`)
110
- process.exitCode = 1
111
- })
112
- } else if (args[0] === 'desktop') {
113
- runDesktop(args.slice(1)).catch(cause => {
114
- console.error(`acryl: ${cause instanceof Error ? cause.message : String(cause)}`)
115
- process.exitCode = 1
116
- })
117
- } else if (args.length === 0 && stdin.isTTY && process.stdout.isTTY && existsSync(LAUNCHER)) {
118
- openLauncher().catch(cause => {
119
- console.error(`acryl: ${cause instanceof Error ? cause.message : String(cause)}`)
120
- process.exitCode = 1
121
- })
2
+ // The entry every Node runs. It checks the Node version before the selector (cli.js) loads, because the selector and the launcher use syntax
3
+ // an older Node cannot parse and would fail with a message nobody can act on (Node 18: "Invalid regular expression flags"). Keep this file
4
+ // to syntax every Node since 12 parses.
5
+ import { supportedNode, unsupportedMessage } from './node-version.js'
6
+
7
+ if (!supportedNode(process.versions.node)) {
8
+ process.stderr.write(unsupportedMessage(process.versions.node))
9
+ process.exitCode = 1
122
10
  } else {
123
- // `acryl code` is ACRYL Code, the IDE (spec 050 Q1); with no terminal, or no launcher, a bare `acryl` keeps opening it as before.
124
- const ideArgs = args[0] === 'code' ? args.slice(1) : args
125
- try { run(runtimeCommand(runtimeLauncher(), ideArgs)) } catch (cause) {
126
- console.error(`acryl: ${cause instanceof Error ? cause.message : String(cause)}`)
11
+ import('./cli.js').catch(function (cause) {
12
+ process.stderr.write('acryl: ' + (cause && cause.message ? cause.message : String(cause)) + '\n')
127
13
  process.exitCode = 1
128
- }
14
+ })
129
15
  }
package/cli.js ADDED
@@ -0,0 +1,279 @@
1
+ // The selector itself, loaded by bin.js once the Node version is known to be new enough.
2
+ import { spawn } from 'node:child_process'
3
+ import { createRequire } from 'node:module'
4
+ import { join, resolve } from 'node:path'
5
+ import { createInterface } from 'node:readline/promises'
6
+ import { stdin, stderr } from 'node:process'
7
+ import { existsSync, mkdirSync } from 'node:fs'
8
+ import { homedir } from 'node:os'
9
+ import { fileURLToPath, pathToFileURL } from 'node:url'
10
+ import { createdAppName, forwardCommand, launcherCommand } from './forward.js'
11
+ import { installedDesktop } from './desktop-open.js'
12
+ import { readSecret } from './secret-input.js'
13
+ import { forwardStopSignals, runtimeCommand, runtimeLauncher, targetFor, targetPackageName } from './runtime.js'
14
+ import { MANAGED, managedSteps, runtimeInstallStep, runtimePrefix, surfaceFrom } from './managed.js'
15
+ import { acquireDesktopInstaller } from './desktop-runtime.js'
16
+ import { acquireWebRuntime, fetchReleaseManifest, hasVerifiedWebRuntime, manifestUrl, managedWebRoot, selectWebArtifact, webRuntimeCommand } from './web-runtime.js'
17
+
18
+ const require = createRequire(import.meta.url)
19
+ const selectorVersion = require('./package.json').version
20
+ /** The release the prepared runtimes (terminal agent, old Web, desktop installer) come from; it moves only when they are rebuilt (spec 050 D14). */
21
+ const runtimeVersion = require('./package.json').acrylRuntime ?? selectorVersion
22
+ const args = process.argv.slice(2)
23
+
24
+ function run({ command, args: commandArgs }) {
25
+ const child = spawn(command, commandArgs, { stdio: 'inherit' })
26
+ const stopForwarding = forwardStopSignals(child)
27
+ child.once('error', cause => {
28
+ stopForwarding()
29
+ console.error(`acryl: ${cause.message}`)
30
+ process.exitCode = 1
31
+ })
32
+ child.once('exit', code => {
33
+ stopForwarding()
34
+ process.exitCode = code ?? 1
35
+ })
36
+ }
37
+
38
+ async function confirmDownload() {
39
+ if (!stdin.isTTY || !stderr.isTTY) return false
40
+ const prompt = createInterface({ input: stdin, output: stderr })
41
+ try {
42
+ return (await prompt.question('ACRYL Web will download a verified matching runtime. Continue? [y/N] ')).trim().toLowerCase() === 'y'
43
+ } finally { prompt.close() }
44
+ }
45
+
46
+ function openInstaller(path) {
47
+ const opener = process.platform === 'darwin' ? ['open', [path]]
48
+ : process.platform === 'win32' ? ['cmd', ['/c', 'start', '', path]]
49
+ : ['xdg-open', [path]]
50
+ const child = spawn(...opener, { stdio: 'ignore' })
51
+ child.once('error', () => {})
52
+ }
53
+
54
+ async function runDesktop(desktopArgs) {
55
+ const noOpen = desktopArgs.includes('--no-open')
56
+ const result = await acquireDesktopInstaller({
57
+ version: runtimeVersion,
58
+ ...(noOpen ? {} : { open: openInstaller }),
59
+ })
60
+ console.log(`ACRYL desktop installer ${result.version}: ${result.path}`)
61
+ if (noOpen) console.log('use --no-open to download without launching')
62
+ }
63
+
64
+ async function runWeb(webArgs) {
65
+ const yes = webArgs.includes('--yes') || webArgs.includes('-y')
66
+ const forwarded = webArgs.filter(arg => arg !== '--yes' && arg !== '-y')
67
+ const target = targetFor({ platform: process.platform, arch: process.arch })
68
+ const root = join(managedWebRoot(), runtimeVersion, target)
69
+ const manifest = await fetchReleaseManifest(manifestUrl(runtimeVersion))
70
+ const artifact = selectWebArtifact(manifest, { version: runtimeVersion, target })
71
+ const cached = hasVerifiedWebRuntime(root, { version: runtimeVersion, target, sha256: artifact.sha256 })
72
+ if (!cached && !yes && !(await confirmDownload())) {
73
+ throw new Error('Web runtime acquisition requires confirmation. Re-run with: acryl web --yes')
74
+ }
75
+ const result = await acquireWebRuntime({ root: managedWebRoot(), version: runtimeVersion, target, manifest })
76
+ run(webRuntimeCommand(result.root, forwarded))
77
+ }
78
+
79
+ /** The launcher (spec 050), bundled into this package as one file at pack time (apps/acryl-launcher-tui/scripts/bundle.mjs). */
80
+ const LAUNCHER = fileURLToPath(new URL('./launcher.js', import.meta.url))
81
+
82
+ /** ACRYL's own folder (the list of apps lives here) and the visible folder new apps are suggested in (spec 050 D8). HOME moves both, which is how tests isolate. */
83
+ const ACRYL_HOME = join(homedir(), '.acryl')
84
+ const APPS_FOLDER = join(homedir(), 'ACRYL')
85
+
86
+ const loadLauncher = () => import(pathToFileURL(LAUNCHER).href)
87
+
88
+ /** After `acryl new`, put the new app in the list (spec 050 D6). The list is a convenience: a failure says so and never fails the command. */
89
+ async function listCreatedApp(commandArgs, cwd) {
90
+ const name = createdAppName(commandArgs)
91
+ // The app is made before it starts, and a person stops a running app with Ctrl-C, so the exit code says nothing: the folder does.
92
+ if (name === undefined || !existsSync(LAUNCHER) || !existsSync(join(resolve(cwd, name), 'blend.yaml'))) return
93
+ try {
94
+ const { addApp } = await loadLauncher()
95
+ addApp(ACRYL_HOME, { path: resolve(cwd, name) })
96
+ } catch (cause) {
97
+ console.error(`acryl: ${name} was made but could not be added to the list of apps: ${cause instanceof Error ? cause.message : String(cause)}`)
98
+ }
99
+ }
100
+
101
+ /** `acryl` or `acryl --tui` in a terminal: the ACRYL app screen; what the person chose then runs exactly as if they had typed it. */
102
+ async function openLauncher() {
103
+ const { runLauncher } = await loadLauncher()
104
+ const chosen = await runLauncher({ home: ACRYL_HOME, appsFolder: APPS_FOLDER })
105
+ if (!chosen) return
106
+ const target = launcherCommand(await desktopWhenListed(chosen.command), {
107
+ env: process.env, platform: process.platform, cwd: process.cwd(), execPath: process.execPath, bin: fileURLToPath(new URL('./bin.js', import.meta.url)), exists: existsSync,
108
+ })
109
+ if (target.error) throw new Error(target.error)
110
+ // A new app's folder may not exist yet (the suggested ~/ACRYL on a first run): make it, so the command has somewhere to run.
111
+ if (chosen.command.ensureCwd === true) mkdirSync(target.cwd, { recursive: true })
112
+ console.log(`\n$ ${chosen.line}\n`)
113
+ const child = spawn(target.command, target.args, { stdio: 'inherit', cwd: target.cwd, shell: target.shell === true, env: await appEnvironment() })
114
+ const stopForwarding = forwardStopSignals(child)
115
+ child.once('error', cause => { stopForwarding(); console.error(`acryl: ${cause.message}`); process.exitCode = 1 })
116
+ child.once('exit', code => {
117
+ stopForwarding()
118
+ process.exitCode = code ?? 1
119
+ void listCreatedApp(chosen.command.args, target.cwd)
120
+ })
121
+ }
122
+
123
+ /**
124
+ * "Open an app" runs `npm run dev`, which serves the app to a browser. An app the list records as a Desktop app (made from the desktop or web screen with that
125
+ * surface) is opened the way that screen opens it: `npm run desktop`, which starts the same app in its own window.
126
+ */
127
+ async function desktopWhenListed(command) {
128
+ if (command.program !== 'npm' || command.args.join(' ') !== 'run dev') return command
129
+ try {
130
+ const { readApps } = await loadLauncher()
131
+ const folder = resolve(process.cwd(), command.cwd)
132
+ const app = readApps(ACRYL_HOME).find(entry => resolve(entry.path) === folder)
133
+ return app?.surface === 'desktop' ? { ...command, args: ['run', 'desktop'] } : command
134
+ } catch { return command } // the list is a convenience: without it the app starts in the browser as before
135
+ }
136
+
137
+ /** `acryl --gui`: open the installed ACRYL desktop app; when none is installed, fetch the installer for this version and open that. */
138
+ async function openDesktop() {
139
+ const installed = installedDesktop({ platform: process.platform, env: process.env, home: homedir(), exists: existsSync })
140
+ if (installed === undefined) {
141
+ console.log('ACRYL desktop is not installed on this machine yet: fetching the installer.')
142
+ return runDesktop([])
143
+ }
144
+ const child = spawn(installed.command, installed.args, { stdio: 'ignore', detached: true })
145
+ child.once('error', cause => { console.error(`acryl: could not open ${installed.command}: ${cause.message}`); process.exitCode = 1 })
146
+ child.unref()
147
+ }
148
+
149
+ /** The environment an app the `acryl` command starts gets: this one, plus the stored model key when the environment names none (acryl model). */
150
+ async function appEnvironment() {
151
+ if (!existsSync(LAUNCHER)) return process.env
152
+ try {
153
+ const { modelEnv } = await loadLauncher()
154
+ return { ...process.env, ...modelEnv(ACRYL_HOME, process.env) }
155
+ } catch { return process.env }
156
+ }
157
+
158
+ /** `acryl model [set deepseek | set orcarouter | clear [provider]]`: the machine's model key, asked for without echo and never in an argument. */
159
+ async function runModel(modelArgs) {
160
+ if (!existsSync(LAUNCHER)) throw new Error('the launcher is not part of this install; install acryl from npm')
161
+ const { runModelCommand } = await loadLauncher()
162
+ process.exitCode = await runModelCommand(modelArgs, {
163
+ home: ACRYL_HOME, env: process.env, out: line => console.log(line), err: line => console.error(line), readSecret,
164
+ })
165
+ }
166
+
167
+ /** `acryl apps ...`: the list the launcher shows, as commands. */
168
+ async function runApps(appsArgs) {
169
+ if (!existsSync(LAUNCHER)) throw new Error('the launcher is not part of this install; install acryl from npm')
170
+ const { runAppsCommand } = await loadLauncher()
171
+ process.exitCode = runAppsCommand(appsArgs, { home: ACRYL_HOME, cwd: process.cwd(), out: line => console.log(line), err: line => console.error(line) })
172
+ }
173
+
174
+ const context = () => ({ env: process.env, platform: process.platform, cwd: process.cwd(), execPath: process.execPath, exists: existsSync })
175
+
176
+ /** Run each step in turn, its label first; the exit code of the first that fails, else 0. */
177
+ async function runSteps(steps, env) {
178
+ for (const step of steps) {
179
+ console.log(`acryl: ${step.label}`)
180
+ const code = await new Promise(done => {
181
+ const child = spawn(step.command, step.args, { stdio: 'inherit', cwd: step.cwd, shell: step.shell === true, env })
182
+ const stopForwarding = forwardStopSignals(child)
183
+ child.once('error', cause => { stopForwarding(); console.error(`acryl: ${cause.message}`); done(1) })
184
+ child.once('exit', exitCode => { stopForwarding(); done(exitCode ?? 1) })
185
+ })
186
+ if (code !== 0) return code
187
+ }
188
+ return 0
189
+ }
190
+
191
+ /** `acryl ade [--web | --gui | --tui]`: ACRYL ADE, kept in ~/.acryl/ade, made and installed on first use. */
192
+ async function openAde(adeArgs) {
193
+ const chosen = surfaceFrom(adeArgs)
194
+ if (chosen.error) throw new Error(chosen.error)
195
+ if (chosen.surface === 'tui') return openTerminalAgent(chosen.rest)
196
+ mkdirSync(ACRYL_HOME, { recursive: true })
197
+ process.exitCode = await runSteps(managedSteps(MANAGED.ade, chosen.surface, { home: ACRYL_HOME, context: context() }), await appEnvironment())
198
+ }
199
+
200
+ /** The terminal runtime: beside the selector (an install that still carries it), else the one acryl installed in ~/.acryl/runtime. */
201
+ function terminalRuntime() {
202
+ try { return runtimeLauncher({ require, version: runtimeVersion }) } catch { /* not beside the selector: look in ~/.acryl */ }
203
+ return runtimeLauncher({ require: createRequire(join(runtimePrefix(ACRYL_HOME, runtimeVersion), 'package.json')), version: runtimeVersion })
204
+ }
205
+
206
+ async function confirmRuntimeDownload() {
207
+ if (!stdin.isTTY || !stderr.isTTY) return false
208
+ const prompt = createInterface({ input: stdin, output: stderr })
209
+ try {
210
+ return (await prompt.question(`The ACRYL terminal agent ${runtimeVersion} is a one-time download of about 450 MB into ${join(ACRYL_HOME, 'runtime')}. Continue? [y/N] `)).trim().toLowerCase() === 'y'
211
+ } finally { prompt.close() }
212
+ }
213
+
214
+ /** The ACRYL terminal coding agent with these words; downloaded on first use, after the person says yes. */
215
+ async function openTerminalAgent(agentArgs) {
216
+ let launcher
217
+ try { launcher = terminalRuntime() } catch {
218
+ if (!(await confirmRuntimeDownload())) throw new Error('the terminal agent is not downloaded yet; run acryl ade --tui in a terminal and answer y')
219
+ mkdirSync(ACRYL_HOME, { recursive: true })
220
+ const packageName = targetPackageName(targetFor({ platform: process.platform, arch: process.arch }))
221
+ const code = await runSteps([runtimeInstallStep({ home: ACRYL_HOME, version: runtimeVersion, packageName, context: context() })], process.env)
222
+ if (code !== 0) throw new Error(`the download of ${packageName}@${runtimeVersion} failed (exit ${code})`)
223
+ launcher = terminalRuntime()
224
+ }
225
+ run(runtimeCommand(launcher, agentArgs))
226
+ }
227
+
228
+ const fail = cause => {
229
+ console.error(`acryl: ${cause instanceof Error ? cause.message : String(cause)}`)
230
+ process.exitCode = 1
231
+ }
232
+
233
+ // The short commands (acryl new, plugin, blends, update) run the part that owns them (forward.js).
234
+ const forwarded = forwardCommand(args, { env: process.env, platform: process.platform, cwd: process.cwd(), execPath: process.execPath, exists: existsSync })
235
+ if (forwarded?.error) {
236
+ console.error(`acryl: ${forwarded.error}`)
237
+ process.exitCode = 2
238
+ } else if (forwarded) {
239
+ appEnvironment().then(env => {
240
+ const child = spawn(forwarded.command, forwarded.args, { stdio: 'inherit', cwd: forwarded.cwd, shell: forwarded.shell === true, env })
241
+ child.once('error', cause => { console.error(`acryl: ${cause.message}`); process.exitCode = 1 })
242
+ child.once('exit', code => {
243
+ process.exitCode = code ?? 1
244
+ void listCreatedApp(args, forwarded.cwd ?? process.cwd())
245
+ })
246
+ }, fail)
247
+ } else if (args[0] === 'model') {
248
+ runModel(args.slice(1)).catch(fail)
249
+ } else if (args[0] === 'apps') {
250
+ runApps(args.slice(1)).catch(fail)
251
+ } else if (args[0] === '--gui') {
252
+ openDesktop().catch(fail)
253
+ } else if (args[0] === '--tui') {
254
+ if (!stdin.isTTY || !process.stdout.isTTY) fail(new Error('acryl --tui needs a terminal; to open the app window instead run: acryl --gui'))
255
+ else if (!existsSync(LAUNCHER)) fail(new Error('the terminal screen is not part of this install; install acryl from npm'))
256
+ else openLauncher().catch(fail)
257
+ } else if (args[0] === 'web' || args[0] === '--web') {
258
+ // `acryl --web` is the third launcher flag beside `--tui` and `--gui`: the same ACRYL screen, served to a browser.
259
+ runWeb(args.slice(1)).catch(cause => {
260
+ console.error(`acryl: ${cause instanceof Error ? cause.message : String(cause)}`)
261
+ process.exitCode = 1
262
+ })
263
+ } else if (args[0] === 'desktop') {
264
+ runDesktop(args.slice(1)).catch(cause => {
265
+ console.error(`acryl: ${cause instanceof Error ? cause.message : String(cause)}`)
266
+ process.exitCode = 1
267
+ })
268
+ } else if (args.length === 0 && stdin.isTTY && process.stdout.isTTY && existsSync(LAUNCHER)) {
269
+ openLauncher().catch(cause => {
270
+ console.error(`acryl: ${cause instanceof Error ? cause.message : String(cause)}`)
271
+ process.exitCode = 1
272
+ })
273
+ } else if (args[0] === 'ade' || args[0] === 'code') {
274
+ // `acryl ade` is ACRYL ADE (spec 050 D14): the Blend in the browser, `--gui` in a window, `--tui` the terminal agent. `acryl code` is its earlier name.
275
+ openAde(args.slice(1)).catch(fail)
276
+ } else {
277
+ // Any other words (`acryl -p "..."`), or a bare `acryl` with no terminal: the terminal agent, as before.
278
+ openTerminalAgent(args).catch(fail)
279
+ }
@@ -0,0 +1,18 @@
1
+ // `acryl --gui`: open the ACRYL desktop app that is already installed. Where the installer puts it is fixed by the desktop package's electron-builder
2
+ // config (productName ACRYL, per-user NSIS install, Debian package): macOS /Applications/ACRYL.app, Windows %LOCALAPPDATA%\Programs\ACRYL\ACRYL.exe,
3
+ // Linux /opt/ACRYL/acryl-desktop. Returns the command that opens it, or undefined when it is not installed (the selector then fetches the installer).
4
+ import { join } from 'node:path'
5
+
6
+ /** Where each OS keeps the installed app, most likely first. */
7
+ export function desktopLocations({ platform, env, home }) {
8
+ if (platform === 'darwin') return [join('/Applications', 'ACRYL.app'), join(home, 'Applications', 'ACRYL.app')]
9
+ if (platform === 'win32') return [join(env.LOCALAPPDATA ?? join(home, 'AppData', 'Local'), 'Programs', 'ACRYL', 'ACRYL.exe')]
10
+ return ['/opt/ACRYL/acryl-desktop']
11
+ }
12
+
13
+ /** `{ command, args }` that opens the installed desktop app, or undefined. */
14
+ export function installedDesktop({ platform, env, home, exists }) {
15
+ const found = desktopLocations({ platform, env, home }).find(exists)
16
+ if (found === undefined) return undefined
17
+ return platform === 'darwin' ? { command: 'open', args: ['-a', found] } : { command: found, args: [] }
18
+ }
package/forward.js CHANGED
@@ -84,3 +84,17 @@ export function forwardCommand(argv, context) {
84
84
  return { error: `acryl ${command} needs what to do, for example: acryl plugin publish my-plugin` }
85
85
  return { command: context.execPath, args: [join(root, DOOR), 'plugin', ...rest], cwd: root }
86
86
  }
87
+
88
+ /**
89
+ * The folder name `acryl new <name> [starter] [--from <blend>]` makes, or undefined when there is none. The selector lists the app after the
90
+ * command succeeds (acryl apps), so it must name the same folder the create command does: the first argument that is not a flag or a flag's value.
91
+ */
92
+ export function createdAppName(argv) {
93
+ const [command, ...rest] = argv
94
+ if (command !== 'new' && command !== 'create') return undefined
95
+ for (let i = 0; i < rest.length; i += 1) {
96
+ if (rest[i] === '--from') { i += 1; continue }
97
+ if (!rest[i].startsWith('-')) return rest[i]
98
+ }
99
+ return undefined
100
+ }