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/managed.js ADDED
@@ -0,0 +1,62 @@
1
+ // What `acryl` keeps for itself in ~/.acryl and starts on a surface (spec 050 D14):
2
+ // - Blend apps it owns: ACRYL ADE (`acryl ade`), made once from the Blends registry, installed, then started in the browser or a window;
3
+ // - the terminal coding agent (`acryl ade --tui`), the prepared CLI runtime, installed on first use instead of with every `npx acryl`.
4
+ // The functions here only decide what to run; cli.js runs it. Nothing here touches the network or the disk except `exists`.
5
+ import { existsSync } from 'node:fs'
6
+ import { join } from 'node:path'
7
+ import { CREATE_SPEC, npmCommand, npmExec } from './forward.js'
8
+
9
+ /** The apps acryl keeps in its own home: registry id, folder under ~/.acryl, name a person reads. */
10
+ export const MANAGED = Object.freeze({
11
+ ade: Object.freeze({ id: 'acryl.ade', folder: 'ade', title: 'ACRYL ADE' }),
12
+ })
13
+
14
+ /** The surfaces a managed Blend opens on, and the app script that opens it there. */
15
+ export const SURFACES = Object.freeze({ web: 'dev', gui: 'desktop' })
16
+
17
+ const SURFACE_FLAGS = Object.freeze({ '--web': 'web', '--gui': 'gui', '--desktop': 'gui', '--tui': 'tui', '--cli': 'tui' })
18
+
19
+ /**
20
+ * `acryl ade [--web | --gui | --tui] [words...]`: the surface the words ask for (`web` when none is named) and the other words, which only the
21
+ * terminal agent takes (`acryl ade --tui -p "..."`). `{ error }` for two surfaces, or for words the browser or the window cannot take.
22
+ */
23
+ export function surfaceFrom(args) {
24
+ const named = args.filter(arg => Object.hasOwn(SURFACE_FLAGS, arg))
25
+ if (new Set(named.map(flag => SURFACE_FLAGS[flag])).size > 1) return { error: 'acryl ade opens on one surface at a time: --web, --gui or --tui' }
26
+ const surface = SURFACE_FLAGS[named[0]] ?? 'web'
27
+ const rest = args.filter(arg => !Object.hasOwn(SURFACE_FLAGS, arg))
28
+ if (surface !== 'tui' && rest.length > 0) return { error: `acryl ade ${surface === 'web' ? '--web' : '--gui'} takes no other words (${rest.join(' ')}); the terminal agent does: acryl ade --tui ${rest.join(' ')}` }
29
+ return { surface, rest }
30
+ }
31
+
32
+ /**
33
+ * The steps that bring a managed Blend to running on `surface`: make it (once), install (when no finished install is there), start.
34
+ * npm writes `node_modules/.package-lock.json` last, so an install cut short is done again instead of starting a broken app.
35
+ * @returns {{ label: string, command: string, args: string[], cwd: string, shell?: boolean }[]}
36
+ */
37
+ export function managedSteps(app, surface, { home, context, exists = existsSync }) {
38
+ const folder = join(home, app.folder)
39
+ const steps = []
40
+ if (!exists(join(folder, 'blend.yaml'))) {
41
+ const create = context.env.ACRYL_CREATE?.trim() || CREATE_SPEC
42
+ steps.push({ label: `making ${app.title} in ${folder} (once)`, ...npmExec(context, create, [app.folder, '--from', app.id, '--no-start']), cwd: home })
43
+ }
44
+ if (!exists(join(folder, 'node_modules', '.package-lock.json'))) {
45
+ steps.push({ label: `installing ${app.title} (once, about a minute)`, ...npmCommand(context, ['install', '--no-audit', '--no-fund']), cwd: folder })
46
+ }
47
+ steps.push({ label: `starting ${app.title}`, ...npmCommand(context, ['run', SURFACES[surface]]), cwd: folder })
48
+ return steps
49
+ }
50
+
51
+ /** Where the terminal agent's runtime of this version is installed on first use. */
52
+ export const runtimePrefix = (home, version) => join(home, 'runtime', version)
53
+
54
+ /** The one step that installs the runtime package into its prefix. */
55
+ export function runtimeInstallStep({ home, version, packageName, context }) {
56
+ const prefix = runtimePrefix(home, version)
57
+ return {
58
+ label: `downloading the ACRYL terminal agent ${version} (once, about 450 MB)`,
59
+ ...npmCommand(context, ['install', '--prefix', prefix, '--no-save', '--no-audit', '--no-fund', `${packageName}@${version}`]),
60
+ cwd: home,
61
+ }
62
+ }
@@ -0,0 +1,21 @@
1
+ // Which Node versions acryl runs on, as package.json's engines says (>=22.19.0). Loaded by bin.js before anything else, so it keeps to
2
+ // syntax every Node since 12 parses: an older Node must reach the message below instead of failing on newer syntax elsewhere.
3
+
4
+ export var MINIMUM = '22.19.0'
5
+
6
+ /** Whether a `process.versions.node` string is new enough. */
7
+ export function supportedNode(version) {
8
+ var parts = String(version).split('.').map(Number)
9
+ var wanted = MINIMUM.split('.').map(Number)
10
+ for (var i = 0; i < 3; i++) {
11
+ var have = parts[i] || 0
12
+ if (have !== wanted[i]) return have > wanted[i]
13
+ }
14
+ return true
15
+ }
16
+
17
+ /** What a person on an older Node reads: what is wrong, and the one thing to do. */
18
+ export function unsupportedMessage(version) {
19
+ return 'acryl needs Node.js ' + MINIMUM + ' or later; this is Node.js ' + version + '.\n' +
20
+ 'Install the current LTS from https://nodejs.org (or with nvm: nvm install --lts), then run the command again.\n'
21
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "acryl",
3
- "version": "0.2.7",
3
+ "version": "0.2.8",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "bin": {
@@ -8,22 +8,22 @@
8
8
  },
9
9
  "files": [
10
10
  "bin.js",
11
+ "cli.js",
12
+ "desktop-open.js",
13
+ "secret-input.js",
14
+ "node-version.js",
11
15
  "forward.js",
12
16
  "launcher.js",
17
+ "managed.js",
13
18
  "runtime.js",
14
19
  "release-contract.js",
15
20
  "web-runtime.js",
16
21
  "desktop-runtime.js",
17
22
  "README.md"
18
23
  ],
19
- "optionalDependencies": {
20
- "acryl-cli-darwin-arm64": "0.2.7",
21
- "acryl-cli-linux-arm64": "0.2.7",
22
- "acryl-cli-linux-x64": "0.2.7",
23
- "acryl-cli-windows-x64": "0.2.7"
24
- },
24
+ "acrylRuntime": "0.2.7",
25
25
  "engines": {
26
- "node": ">=22.19.0 || >=24.0.0"
26
+ "node": ">=22.19.0"
27
27
  },
28
28
  "description": "A persistent, agent-agnostic coding environment. Keep your context, change your agent.",
29
29
  "keywords": [
@@ -0,0 +1,39 @@
1
+ // Read one secret line from the terminal without echoing it (a key pasted at a prompt). With no terminal (a pipe) the whole of stdin is the secret,
2
+ // so a script can run `printf %s "$KEY" | acryl model set deepseek`. The key is never an argument: arguments show in `ps` and shell history.
3
+ import { stderr, stdin } from 'node:process'
4
+
5
+ export function readSecret(prompt, { input = stdin, output = stderr } = {}) {
6
+ if (!input.isTTY) {
7
+ return new Promise((resolve, reject) => {
8
+ let text = ''
9
+ input.setEncoding('utf8')
10
+ input.on('data', chunk => { text += chunk })
11
+ input.once('end', () => resolve(text))
12
+ input.once('error', reject)
13
+ })
14
+ }
15
+ return new Promise((resolve, reject) => {
16
+ output.write(prompt)
17
+ let text = ''
18
+ const finish = (error) => {
19
+ input.off('data', onData)
20
+ input.setRawMode(false)
21
+ input.pause()
22
+ output.write('\n')
23
+ if (error) reject(error)
24
+ else resolve(text)
25
+ }
26
+ const onData = chunk => {
27
+ for (const char of String(chunk)) {
28
+ if (char === '\r' || char === '\n') return finish()
29
+ if (char === '\x03') return finish(new Error('cancelled'))
30
+ if (char === '\x7f' || char === '\b') text = text.slice(0, -1)
31
+ else if (char >= ' ') text += char // a paste arrives as one chunk: every printable character counts
32
+ }
33
+ }
34
+ input.setRawMode(true)
35
+ input.setEncoding('utf8')
36
+ input.resume()
37
+ input.on('data', onData)
38
+ })
39
+ }