@zenera/cli 1.1.59 → 1.2.1
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 +33 -15
- package/assets/chat.html +4539 -0
- package/dist/chat.d.ts +7 -0
- package/dist/chat.js +29 -0
- package/dist/commands/index.js +2 -0
- package/dist/commands/server.d.ts +12 -0
- package/dist/commands/server.js +479 -0
- package/dist/container.d.ts +47 -0
- package/dist/container.js +398 -0
- package/dist/containerCredentials.d.ts +2 -0
- package/dist/containerCredentials.js +33 -0
- package/dist/podman.d.ts +1 -0
- package/dist/podman.js +7 -1
- package/dist/seed.d.ts +6 -0
- package/dist/seed.js +64 -0
- package/dist/serverDisplay.d.ts +24 -0
- package/dist/serverDisplay.js +161 -0
- package/dist/serverKeys.d.ts +5 -0
- package/dist/serverKeys.js +53 -0
- package/package.json +8 -5
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Terminal presentation shared by direct and container-based server startup.
|
|
3
|
+
* printServerStarted renders the runtime summary and browser link; streamAgentBuild
|
|
4
|
+
* uses animated compact build progress by default and full grouped logs with --verbose.
|
|
5
|
+
* HOST_MANAGED_ENV lets the image report readiness without repeating the host summary.
|
|
6
|
+
*/
|
|
7
|
+
import { spawn } from 'node:child_process';
|
|
8
|
+
import { createInterface } from 'node:readline';
|
|
9
|
+
import { bold, CliError, cut, cyan, dim, EXIT, green, note, plain, progress, red, table, warn, write, yellow, } from "./term.js";
|
|
10
|
+
export const HOST_MANAGED_ENV = 'ZEN_SERVER_HOST_MANAGED';
|
|
11
|
+
export function printServerStarted(info) {
|
|
12
|
+
note();
|
|
13
|
+
note(` ${green(bold(info.image ? '✓ Container started' : '✓ Server ready'))}`);
|
|
14
|
+
note();
|
|
15
|
+
const rows = [
|
|
16
|
+
['Project', bold(info.project)],
|
|
17
|
+
['HTTP', cyan(info.url)],
|
|
18
|
+
[
|
|
19
|
+
'Auth',
|
|
20
|
+
info.auth === 'insecure'
|
|
21
|
+
? yellow('insecure · JWT signatures not checked')
|
|
22
|
+
: green('JWT · EdDSA verified'),
|
|
23
|
+
],
|
|
24
|
+
['Sandbox', info.sandbox],
|
|
25
|
+
['State', dim(info.root)],
|
|
26
|
+
['Memory', 'private per user · shared across sessions'],
|
|
27
|
+
];
|
|
28
|
+
if (info.runtimeUser)
|
|
29
|
+
rows.push(['Process', info.runtimeUser]);
|
|
30
|
+
if (info.image) {
|
|
31
|
+
rows.push([
|
|
32
|
+
'Image',
|
|
33
|
+
`${cyan(info.image.tag)} ${dim(info.image.built ? '(just built)' : '(cached)')}`,
|
|
34
|
+
], ['Base', dim(info.image.base)]);
|
|
35
|
+
}
|
|
36
|
+
if (info.page)
|
|
37
|
+
rows.push(['Chat user', bold(info.chatUser ?? 'local')]);
|
|
38
|
+
for (const line of table(rows.map(([label, value]) => [dim(label), value]))) {
|
|
39
|
+
note(` ${line}`);
|
|
40
|
+
}
|
|
41
|
+
if (info.auth === 'insecure') {
|
|
42
|
+
note();
|
|
43
|
+
warn('Anyone with access can impersonate any user. Local testing only.');
|
|
44
|
+
}
|
|
45
|
+
if (info.page) {
|
|
46
|
+
write();
|
|
47
|
+
write(` ${bold('Test chat')}`);
|
|
48
|
+
write(` ${cyan(info.page)}`);
|
|
49
|
+
write();
|
|
50
|
+
}
|
|
51
|
+
note();
|
|
52
|
+
note(dim(' Press Ctrl+C to stop gracefully and save active runs.'));
|
|
53
|
+
note();
|
|
54
|
+
}
|
|
55
|
+
/** Keep the host's published address and paths out of the image's own ready message. */
|
|
56
|
+
export function hostManagedOutput(inAgentImage, env = process.env) {
|
|
57
|
+
return inAgentImage && env[HOST_MANAGED_ENV] === '1';
|
|
58
|
+
}
|
|
59
|
+
const BUILD_ERROR = /^(?:error\b|npm (?:err!|error)\b)|\b(?:fatal error|failed to)\b/i;
|
|
60
|
+
const BUILD_WARNING = /\b(?:warn|warning|deprecated)\b/i;
|
|
61
|
+
function buildLinePrinter() {
|
|
62
|
+
let stage;
|
|
63
|
+
return (line) => {
|
|
64
|
+
const step = /^(\s*(?:\[(\d+)\/(\d+)\] )?STEP \d+\/\d+:)(.*)/.exec(line);
|
|
65
|
+
if (step?.[2] && stage !== step[2]) {
|
|
66
|
+
stage = step[2];
|
|
67
|
+
const name = /\bAS\s+(\S+)/i.exec(step[4])?.[1] ?? 'agent image';
|
|
68
|
+
note();
|
|
69
|
+
note(` ${bold(cyan(`Build stage ${step[2]}/${step[3]} · ${name}`))}`);
|
|
70
|
+
}
|
|
71
|
+
const text = step
|
|
72
|
+
? `${bold(cyan(step[1]))}${dim(step[4])}`
|
|
73
|
+
: BUILD_ERROR.test(line.trimStart())
|
|
74
|
+
? red(line)
|
|
75
|
+
: BUILD_WARNING.test(line)
|
|
76
|
+
? yellow(line)
|
|
77
|
+
: /^(?:Successfully tagged|Successfully built)/i.test(line)
|
|
78
|
+
? green(line)
|
|
79
|
+
: dim(line);
|
|
80
|
+
note(line ? ` ${text}` : '');
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/** A spinning row with elapsed time in a terminal, or one final row in a piped log. */
|
|
84
|
+
export function buildProgress(verbose = false) {
|
|
85
|
+
const print = buildLinePrinter();
|
|
86
|
+
const bar = progress();
|
|
87
|
+
const tty = Boolean(process.stderr.isTTY);
|
|
88
|
+
const started = Date.now();
|
|
89
|
+
const frames = ['|', '/', '-', '\\'];
|
|
90
|
+
let frame = 0;
|
|
91
|
+
let last = '';
|
|
92
|
+
let finished = false;
|
|
93
|
+
const render = () => {
|
|
94
|
+
const seconds = Math.floor((Date.now() - started) / 1000);
|
|
95
|
+
const text = `${frames[frame++ % frames.length]} ${seconds}s ${last || 'Building…'}`;
|
|
96
|
+
bar.update(` ${dim(plain(cut(text, Math.max(1, (process.stderr.columns || 100) - 2))))}`);
|
|
97
|
+
};
|
|
98
|
+
const timer = !verbose && tty ? setInterval(render, 150) : undefined;
|
|
99
|
+
timer?.unref();
|
|
100
|
+
if (timer)
|
|
101
|
+
render();
|
|
102
|
+
return {
|
|
103
|
+
line(line) {
|
|
104
|
+
if (finished)
|
|
105
|
+
return;
|
|
106
|
+
if (verbose) {
|
|
107
|
+
print(line);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (!line.trim())
|
|
111
|
+
return;
|
|
112
|
+
if (BUILD_ERROR.test(line.trimStart()) || BUILD_WARNING.test(line)) {
|
|
113
|
+
bar.done();
|
|
114
|
+
print(line);
|
|
115
|
+
last = '';
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
last = line;
|
|
119
|
+
if (tty)
|
|
120
|
+
render();
|
|
121
|
+
},
|
|
122
|
+
done() {
|
|
123
|
+
if (finished)
|
|
124
|
+
return;
|
|
125
|
+
finished = true;
|
|
126
|
+
if (timer)
|
|
127
|
+
clearInterval(timer);
|
|
128
|
+
bar.done();
|
|
129
|
+
if (!verbose && !tty && last)
|
|
130
|
+
note(` ${dim(plain(cut(last, 120)))}`);
|
|
131
|
+
last = '';
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
/** stdout and stderr are decoded independently so split chunks never corrupt build lines. */
|
|
136
|
+
export function streamAgentBuild(bin, args, verbose = false) {
|
|
137
|
+
const output = buildProgress(verbose);
|
|
138
|
+
return new Promise((done, fail) => {
|
|
139
|
+
const child = spawn(bin, [...args], { stdio: ['ignore', 'pipe', 'pipe'] });
|
|
140
|
+
const tail = [];
|
|
141
|
+
const show = (line) => {
|
|
142
|
+
if (line.trim()) {
|
|
143
|
+
tail.push(line);
|
|
144
|
+
if (tail.length > 20)
|
|
145
|
+
tail.shift();
|
|
146
|
+
}
|
|
147
|
+
output.line(line);
|
|
148
|
+
};
|
|
149
|
+
createInterface({ input: child.stdout, crlfDelay: Infinity })
|
|
150
|
+
.on('line', show)
|
|
151
|
+
.on('error', fail);
|
|
152
|
+
createInterface({ input: child.stderr, crlfDelay: Infinity })
|
|
153
|
+
.on('line', show)
|
|
154
|
+
.on('error', fail);
|
|
155
|
+
child.once('error', fail);
|
|
156
|
+
child.once('close', (code) => code === 0
|
|
157
|
+
? done()
|
|
158
|
+
: fail(new CliError(`the agent image did not build (exit ${code})`, EXIT.sandbox, tail.slice(-3).join('\n'))));
|
|
159
|
+
}).finally(() => output.done());
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=serverDisplay.js.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ed25519 key-pair generation for standalone secure runtime callers.
|
|
3
|
+
* generateServerKeys writes exclusive PKCS#8 private and SPKI public PEM files,
|
|
4
|
+
* removing files it created if generation cannot finish. Used by zen server keygen;
|
|
5
|
+
* only the public key belongs on the runtime, never the signing private key.
|
|
6
|
+
*/
|
|
7
|
+
import { generateKeyPairSync } from 'node:crypto';
|
|
8
|
+
import { closeSync, fchmodSync, openSync, rmSync, writeFileSync } from 'node:fs';
|
|
9
|
+
import { CliError, EXIT } from "./term.js";
|
|
10
|
+
export function generateServerKeys(prefix) {
|
|
11
|
+
const paths = {
|
|
12
|
+
privateKey: `${prefix}.private.pem`,
|
|
13
|
+
publicKey: `${prefix}.public.pem`,
|
|
14
|
+
};
|
|
15
|
+
const created = [];
|
|
16
|
+
try {
|
|
17
|
+
const pair = generateKeyPairSync('ed25519', {
|
|
18
|
+
privateKeyEncoding: { type: 'pkcs8', format: 'pem' },
|
|
19
|
+
publicKeyEncoding: { type: 'spki', format: 'pem' },
|
|
20
|
+
});
|
|
21
|
+
for (const [path, pem, mode] of [
|
|
22
|
+
[paths.privateKey, pair.privateKey, 0o600],
|
|
23
|
+
[paths.publicKey, pair.publicKey, 0o644],
|
|
24
|
+
]) {
|
|
25
|
+
const fd = openSync(path, 'wx', mode);
|
|
26
|
+
created.push(path);
|
|
27
|
+
try {
|
|
28
|
+
fchmodSync(fd, mode);
|
|
29
|
+
writeFileSync(fd, pem);
|
|
30
|
+
}
|
|
31
|
+
finally {
|
|
32
|
+
closeSync(fd);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return paths;
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
const failures = [];
|
|
39
|
+
for (const path of created) {
|
|
40
|
+
try {
|
|
41
|
+
rmSync(path);
|
|
42
|
+
}
|
|
43
|
+
catch (cleanup) {
|
|
44
|
+
failures.push(`${path}: ${cleanup instanceof Error ? cleanup.message : cleanup}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const exists = err instanceof Error && 'code' in err && err.code === 'EEXIST';
|
|
48
|
+
throw new CliError(`cannot generate server keys: ${err instanceof Error ? err.message : err}${failures.length ? `; cleanup failed: ${failures.join('; ')}` : ''}`, EXIT.credentials, exists
|
|
49
|
+
? 'existing files are never overwritten; choose a new --out prefix'
|
|
50
|
+
: 'use an --out prefix in an existing writable directory');
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=serverKeys.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zenera/cli",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Command-line front end for @zenera/neo: agentic projects you can run, share and commit.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agents",
|
|
@@ -38,7 +38,8 @@
|
|
|
38
38
|
"dist",
|
|
39
39
|
"!dist/**/*.map",
|
|
40
40
|
"postinstall.mjs",
|
|
41
|
-
"templates"
|
|
41
|
+
"templates",
|
|
42
|
+
"assets"
|
|
42
43
|
],
|
|
43
44
|
"engines": {
|
|
44
45
|
"node": ">=24"
|
|
@@ -54,9 +55,11 @@
|
|
|
54
55
|
"@google/genai": "^2.30.0",
|
|
55
56
|
"@inkjs/ui": "^2.0.0",
|
|
56
57
|
"@openrouter/sdk": "^1.4.25",
|
|
57
|
-
"@zenera/engine": "^1.1
|
|
58
|
-
"@zenera/neo": "^1.1
|
|
59
|
-
"@zenera/
|
|
58
|
+
"@zenera/engine": "^1.2.1",
|
|
59
|
+
"@zenera/neo": "^1.2.1",
|
|
60
|
+
"@zenera/sandbox": "^1.2.1",
|
|
61
|
+
"@zenera/server": "^1.2.1",
|
|
62
|
+
"@zenera/view": "^1.2.1",
|
|
60
63
|
"google-auth-library": "^10.0.0",
|
|
61
64
|
"ink": "^7.1.1",
|
|
62
65
|
"openai": "^6.0.0",
|