zainocli 0.0.0-stage → 1.0.0

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.
Files changed (3) hide show
  1. package/README.md +65 -2
  2. package/bin/zaino.js +302 -0
  3. package/package.json +28 -4
package/README.md CHANGED
@@ -1,3 +1,66 @@
1
- # Temporary Holding Version
1
+ <p align="center"><strong>Zaino CLI</strong> is a coding agent that runs locally on your computer.
2
+ </p>
2
3
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
4
+ ---
5
+
6
+ ## Quickstart
7
+
8
+ ### Installing and running Zaino CLI
9
+
10
+ Build from source (the npm package is not published yet):
11
+
12
+ ```shell
13
+ git clone https://github.com/Louay0007/zaino-cli.git
14
+ cd zaino-cli/codex-rs
15
+ cargo build --release -p codex-cli
16
+ ./target/release/zaino --version
17
+ ```
18
+
19
+ Then run `zaino` to get started.
20
+
21
+ ### Using Zaino with an API key
22
+
23
+ Create a key at <https://zaino.soon.it>, then:
24
+
25
+ ```shell
26
+ zaino login --with-api-key
27
+ ```
28
+
29
+ Paste your `zn-` key and press Enter. The key is stored in `$ZAINO_HOME/.env` (mode `600`), and `zaino logout` removes it.
30
+
31
+ You can also export it yourself:
32
+
33
+ ```shell
34
+ export ZAINO_API_KEY=zn-...
35
+ ```
36
+
37
+ No config file is needed: the CLI defaults to the `zaino` provider, which speaks the Responses API at `https://api.zaino.soon.it/v1`. `~/.zaino/config.toml` is optional and only overrides defaults (for example `model = "frontier"`).
38
+
39
+ ### Models
40
+
41
+ Four aliases, chosen with/model picker or `--model`:
42
+
43
+ | Alias | Use |
44
+ | --- | --- |
45
+ | `fast` | Cheap, quick edits |
46
+ | `smart` | Default; everyday coding |
47
+ | `frontier` | Hardest problems |
48
+ | `fable` | Long-form and explanatory work |
49
+
50
+ ### From source
51
+
52
+ ```shell
53
+ cd codex-rs
54
+ cargo build --release -p codex-cli
55
+ ./target/release/zaino --version
56
+ ```
57
+
58
+ ## Docs
59
+
60
+ - [**Getting started**](./docs/getting-started.md)
61
+ - [**Authentication**](./docs/authentication.md)
62
+ - [**Configuration**](./docs/config.md)
63
+ - [**Contributing**](./docs/contributing.md)
64
+ - [**Installing & building**](./docs/install.md)
65
+
66
+ This repository is licensed under the [Apache-2.0 License](LICENSE).
package/bin/zaino.js ADDED
@@ -0,0 +1,302 @@
1
+ #!/usr/bin/env node
2
+ // Unified entry point for the Zaino CLI.
3
+
4
+ import { spawn } from "node:child_process";
5
+ import { existsSync, readFileSync, realpathSync } from "fs";
6
+ import { createRequire } from "node:module";
7
+ import { constants } from "node:os";
8
+ import path from "path";
9
+ import { fileURLToPath } from "url";
10
+
11
+ // __dirname equivalent in ESM
12
+ const __filename = fileURLToPath(import.meta.url);
13
+ const __dirname = path.dirname(__filename);
14
+ const require = createRequire(import.meta.url);
15
+ const zainoPackageRoot = realpathSync(path.join(__dirname, ".."));
16
+
17
+ const PLATFORM_PACKAGE_BY_TARGET = {
18
+ "x86_64-unknown-linux-musl": "zainocli-linux-x64",
19
+ "aarch64-unknown-linux-musl": "zainocli-linux-arm64",
20
+ "x86_64-apple-darwin": "zainocli-darwin-x64",
21
+ "aarch64-apple-darwin": "zainocli-darwin-arm64",
22
+ "x86_64-pc-windows-msvc": "zainocli-win32-x64",
23
+ "aarch64-pc-windows-msvc": "zainocli-win32-arm64",
24
+ };
25
+
26
+ const { platform, arch } = process;
27
+
28
+ let targetTriple = null;
29
+ switch (platform) {
30
+ case "linux":
31
+ case "android":
32
+ switch (arch) {
33
+ case "x64":
34
+ targetTriple = "x86_64-unknown-linux-musl";
35
+ break;
36
+ case "arm64":
37
+ targetTriple = "aarch64-unknown-linux-musl";
38
+ break;
39
+ default:
40
+ break;
41
+ }
42
+ break;
43
+ case "darwin":
44
+ switch (arch) {
45
+ case "x64":
46
+ targetTriple = "x86_64-apple-darwin";
47
+ break;
48
+ case "arm64":
49
+ targetTriple = "aarch64-apple-darwin";
50
+ break;
51
+ default:
52
+ break;
53
+ }
54
+ break;
55
+ case "win32":
56
+ switch (arch) {
57
+ case "x64":
58
+ targetTriple = "x86_64-pc-windows-msvc";
59
+ break;
60
+ case "arm64":
61
+ targetTriple = "aarch64-pc-windows-msvc";
62
+ break;
63
+ default:
64
+ break;
65
+ }
66
+ break;
67
+ default:
68
+ break;
69
+ }
70
+
71
+ if (!targetTriple) {
72
+ throw new Error(`Unsupported platform: ${platform} (${arch})`);
73
+ }
74
+
75
+ const platformPackage = PLATFORM_PACKAGE_BY_TARGET[targetTriple];
76
+ if (!platformPackage) {
77
+ throw new Error(`Unsupported target triple: ${targetTriple}`);
78
+ }
79
+
80
+ function findZainoExecutable() {
81
+ let vendorRoot;
82
+ try {
83
+ const packageJsonPath = require.resolve(`${platformPackage}/package.json`);
84
+ vendorRoot = path.join(path.dirname(packageJsonPath), "vendor");
85
+ } catch {
86
+ vendorRoot = path.join(__dirname, "..", "vendor");
87
+ }
88
+
89
+ const zainoExecutable = path.join(
90
+ vendorRoot,
91
+ targetTriple,
92
+ "bin",
93
+ process.platform === "win32" ? "zaino.exe" : "zaino",
94
+ );
95
+ if (existsSync(zainoExecutable)) {
96
+ return zainoExecutable;
97
+ }
98
+
99
+ const packageManager = detectPackageManager();
100
+ const updateCommand =
101
+ packageManager === "bun"
102
+ ? "bun install -g zainocli@latest"
103
+ : packageManager === "pnpm"
104
+ ? "pnpm add -g zainocli@latest"
105
+ : packageManager === "vite-plus"
106
+ ? "vp install -g zainocli@latest"
107
+ : "npm install -g zainocli@latest";
108
+ throw new Error(
109
+ `Missing optional dependency ${platformPackage}. Reinstall Zaino: ${updateCommand}`,
110
+ );
111
+ }
112
+
113
+ const binaryPath = findZainoExecutable();
114
+
115
+ function isPnpmOwnedZainoInstall(nodeModulesDir) {
116
+ if (!existsSync(path.join(nodeModulesDir, ".modules.yaml"))) {
117
+ return false;
118
+ }
119
+
120
+ try {
121
+ return (
122
+ realpathSync(path.join(nodeModulesDir, "@zaino", "cli")) ===
123
+ zainoPackageRoot
124
+ );
125
+ } catch {
126
+ return false;
127
+ }
128
+ }
129
+
130
+ function isVitePlusOwnedZainoInstall(packagesDir) {
131
+ if (path.basename(packagesDir) !== "packages") {
132
+ return false;
133
+ }
134
+
135
+ try {
136
+ const metadata = JSON.parse(
137
+ readFileSync(path.join(packagesDir, "@zaino", "cli.json"), "utf8"),
138
+ );
139
+ if (metadata.name !== "@zaino/cli") {
140
+ return false;
141
+ }
142
+
143
+ // Vite+ records the active global installation in packages/@zaino/cli.json.
144
+ // Older installs have no ID or append a #-prefixed ID to the package name;
145
+ // newer installs put the ID in a subdirectory of the package prefix.
146
+ const installId = metadata.installId || "";
147
+ const installDir = installId.startsWith("#")
148
+ ? path.join(packagesDir, `@zaino/cli${installId}`)
149
+ : path.join(packagesDir, "@zaino/cli", installId);
150
+ for (const nodeModulesDir of [
151
+ path.join(installDir, "lib", "node_modules"),
152
+ path.join(installDir, "node_modules"),
153
+ ]) {
154
+ const packageRoot = path.join(nodeModulesDir, "@zaino", "cli");
155
+ if (
156
+ existsSync(packageRoot) &&
157
+ realpathSync(packageRoot) === zainoPackageRoot
158
+ ) {
159
+ return true;
160
+ }
161
+ }
162
+ } catch {
163
+ // Missing or unreadable ownership metadata must not prevent Zaino starting.
164
+ }
165
+ return false;
166
+ }
167
+
168
+ /**
169
+ * Use heuristics to detect the package manager that was used to install Zaino
170
+ * in order to give the user a hint about how to update it.
171
+ */
172
+ function detectPackageManager() {
173
+ // Package-manager ownership metadata can be several parents above the package.
174
+ // Search ancestors of both the canonical package root and lexical entrypoint
175
+ // because the package manager may link either path.
176
+ const entrypointDir = path.dirname(path.resolve(process.argv[1]));
177
+ for (const startDir of new Set([zainoPackageRoot, entrypointDir])) {
178
+ const filesystemRoot = path.parse(startDir).root;
179
+ for (
180
+ let currentDir = startDir;
181
+ currentDir !== filesystemRoot;
182
+ currentDir = path.dirname(currentDir)
183
+ ) {
184
+ if (isVitePlusOwnedZainoInstall(currentDir)) {
185
+ return "vite-plus";
186
+ }
187
+ if (isPnpmOwnedZainoInstall(path.join(currentDir, "node_modules"))) {
188
+ return "pnpm";
189
+ }
190
+ }
191
+
192
+ if (isPnpmOwnedZainoInstall(path.join(filesystemRoot, "node_modules"))) {
193
+ return "pnpm";
194
+ }
195
+ }
196
+
197
+ const userAgent = process.env.npm_config_user_agent || "";
198
+ if (/\bbun\//.test(userAgent)) {
199
+ return "bun";
200
+ }
201
+
202
+ const execPath = process.env.npm_execpath || "";
203
+ if (execPath.includes("bun")) {
204
+ return "bun";
205
+ }
206
+
207
+ if (
208
+ __dirname.includes(".bun/install/global") ||
209
+ __dirname.includes(".bun\\install\\global")
210
+ ) {
211
+ return "bun";
212
+ }
213
+
214
+ return userAgent ? "npm" : null;
215
+ }
216
+
217
+ const packageManager = detectPackageManager();
218
+ const packageManagerEnvVar =
219
+ packageManager === "bun"
220
+ ? "CODEX_MANAGED_BY_BUN"
221
+ : packageManager === "pnpm"
222
+ ? "CODEX_MANAGED_BY_PNPM"
223
+ : packageManager === "vite-plus"
224
+ ? "CODEX_MANAGED_BY_VITE_PLUS"
225
+ : "CODEX_MANAGED_BY_NPM";
226
+ const env = {
227
+ ...process.env,
228
+ CODEX_MANAGED_PACKAGE_ROOT: zainoPackageRoot,
229
+ };
230
+ delete env.CODEX_MANAGED_BY_NPM;
231
+ delete env.CODEX_MANAGED_BY_BUN;
232
+ delete env.CODEX_MANAGED_BY_PNPM;
233
+ delete env.CODEX_MANAGED_BY_VITE_PLUS;
234
+ env[packageManagerEnvVar] = "1";
235
+
236
+ // Replace Node so the native binary receives signals and exits directly.
237
+ // Node exposes execve on Windows too, but calling it there is unsupported.
238
+ if (process.platform !== "win32" && typeof process.execve === "function") {
239
+ // Node ignores SIGXFSZ, and ignored signals survive execve. Installing a
240
+ // handler lets execve restore the default disposition in the native binary.
241
+ process.on("SIGXFSZ", () => {});
242
+ process.execve(binaryPath, [binaryPath, ...process.argv.slice(2)], env);
243
+ }
244
+
245
+ // Older Node versions and Windows need a child process. Spawn asynchronously
246
+ // so Node can forward signals while the native binary is executing.
247
+ const child = spawn(binaryPath, process.argv.slice(2), {
248
+ stdio: "inherit",
249
+ env,
250
+ });
251
+
252
+ child.on("error", (err) => {
253
+ // Typically triggered when the binary is missing or not executable.
254
+ // Re-throwing here will terminate the parent with a non-zero exit code
255
+ // while still printing a helpful stack trace.
256
+ // eslint-disable-next-line no-console
257
+ console.error(err);
258
+ process.exit(1);
259
+ });
260
+
261
+ // Forward common termination signals to the child so that it shuts down
262
+ // gracefully. In the handler we temporarily disable the default behavior of
263
+ // exiting immediately; once the child has been signaled we simply wait for
264
+ // its exit event which will in turn terminate the parent (see below).
265
+ const forwardSignal = (signal) => {
266
+ if (child.killed) {
267
+ return;
268
+ }
269
+ try {
270
+ child.kill(signal);
271
+ } catch {
272
+ /* ignore */
273
+ }
274
+ };
275
+
276
+ ["SIGINT", "SIGTERM", "SIGHUP"].forEach((sig) => {
277
+ process.on(sig, () => forwardSignal(sig));
278
+ });
279
+
280
+ // When the child exits, mirror its termination reason in the parent so that
281
+ // shell scripts and other tooling observe the correct exit status.
282
+ // Wrap the lifetime of the child process in a Promise so that we can await
283
+ // its termination in a structured way. The Promise resolves with an object
284
+ // describing how the child exited: either via exit code or due to a signal.
285
+ const childResult = await new Promise((resolve) => {
286
+ child.on("exit", (code, signal) => {
287
+ if (signal) {
288
+ resolve({ type: "signal", signal });
289
+ } else {
290
+ resolve({ type: "code", exitCode: code ?? 1 });
291
+ }
292
+ });
293
+ });
294
+
295
+ if (childResult.type === "signal") {
296
+ // Preserve a failure exit code even if Node ignores the re-emitted signal.
297
+ process.exitCode = 128 + constants.signals[childResult.signal];
298
+ process.removeAllListeners(childResult.signal);
299
+ process.kill(process.pid, childResult.signal);
300
+ } else {
301
+ process.exit(childResult.exitCode);
302
+ }
package/package.json CHANGED
@@ -1,6 +1,30 @@
1
1
  {
2
2
  "name": "zainocli",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "Zaino CLI is a coding agent that runs locally on your computer.",
5
+ "license": "Apache-2.0",
6
+ "bin": {
7
+ "zaino": "bin/zaino.js"
8
+ },
9
+ "type": "module",
10
+ "engines": {
11
+ "node": ">=16"
12
+ },
13
+ "files": [
14
+ "bin/zaino.js"
15
+ ],
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/Louay0007/zaino-cli.git",
19
+ "directory": "codex-cli"
20
+ },
21
+ "packageManager": "pnpm@10.34.5+sha512.a4ee05f2f73658255bd6a89859c065a45c28a57daefae2c893a168ee2b73168c37b91e83e57ea67654ad03f03031746430e8bce38e362e042605fb8abc80192e",
22
+ "optionalDependencies": {
23
+ "zainocli-linux-x64": "npm:zainocli@1.0.0-linux-x64",
24
+ "zainocli-linux-arm64": "npm:zainocli@1.0.0-linux-arm64",
25
+ "zainocli-darwin-x64": "npm:zainocli@1.0.0-darwin-x64",
26
+ "zainocli-darwin-arm64": "npm:zainocli@1.0.0-darwin-arm64",
27
+ "zainocli-win32-x64": "npm:zainocli@1.0.0-win32-x64",
28
+ "zainocli-win32-arm64": "npm:zainocli@1.0.0-win32-arm64"
29
+ }
30
+ }