@duheso/zerocli 0.7.7 → 0.7.9

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/bin/zero +103 -96
  2. package/dist/cli.mjs +2197 -974
  3. package/package.json +1 -1
package/bin/zero CHANGED
@@ -1,96 +1,103 @@
1
- #!/usr/bin/env bash
2
-
3
- # Zero CLI — Shell wrapper for env var mapping and V8 heap configuration
4
- #
5
- # Maps COPILOT_PROVIDER_* / COPILOT_MODEL vars to the native OpenAI-shim
6
- # vars, then boots the app.
7
- #
8
- # Internal (localhost):
9
- # export COPILOT_PROVIDER_BASE_URL=http://localhost:3052/v1
10
- # export COPILOT_PROVIDER_TYPE=openai
11
- # export COPILOT_PROVIDER_API_KEY=not-required
12
- # export COPILOT_MODEL=gemma4:code
13
- # zero
14
- #
15
- # External (remote server):
16
- # export COPILOT_PROVIDER_BASE_URL=http://10.11.36.131:3052/v1
17
- # export COPILOT_PROVIDER_TYPE=openai
18
- # export COPILOT_PROVIDER_API_KEY=not-required
19
- # export COPILOT_MODEL=gemma4:code
20
- # zero
21
-
22
- # ── COPILOT_* native env var mapping ──────────────────────────────────────
23
-
24
- providerType="${COPILOT_PROVIDER_TYPE,,}"
25
-
26
- if [[ "$providerType" == "openai" ]] && [[ -n "$COPILOT_PROVIDER_BASE_URL" ]]; then
27
- export CLAUDE_CODE_USE_OPENAI=1
28
- fi
29
-
30
- if [[ -n "$COPILOT_PROVIDER_BASE_URL" ]] && [[ -z "$OPENAI_BASE_URL" ]]; then
31
- export OPENAI_BASE_URL="$COPILOT_PROVIDER_BASE_URL"
32
- fi
33
-
34
- if [[ -n "$COPILOT_PROVIDER_API_KEY" ]] && [[ -z "$OPENAI_API_KEY" ]]; then
35
- export OPENAI_API_KEY="$COPILOT_PROVIDER_API_KEY"
36
- fi
37
-
38
- if [[ -n "$COPILOT_MODEL" ]] && [[ -z "$OPENAI_MODEL" ]]; then
39
- export OPENAI_MODEL="$COPILOT_MODEL"
40
- fi
41
-
42
- # COPILOT_TOOLLESS=1 → disable tool calling (text-only mode).
43
- if [[ -n "$COPILOT_TOOLLESS" ]] && [[ -z "$OPENAI_TOOLLESS" ]]; then
44
- export OPENAI_TOOLLESS="$COPILOT_TOOLLESS"
45
- fi
46
-
47
- # ── V8 heap configuration ────────────────────────────────────────────────────
48
- #
49
- # Prevent "JavaScript heap out of memory" crashes during long-running
50
- # sessions (large context windows, agent waves, file editing). The default
51
- # V8 heap limit (~4GB) is insufficient for the Zero CLI's context buildup.
52
- #
53
- # When running in CCR (remote containers), use 8GB. Otherwise, allocate
54
- # 8GB on machines with enough RAM, falling back to 6GB as minimum.
55
-
56
- if [[ "$CLAUDE_CODE_REMOTE" == "true" ]]; then
57
- HEAP_SIZE=8192
58
- else
59
- totalMemMB=$(free -m 2>/dev/null | awk '/^Mem:/{print $2}')
60
- if [[ -n "$totalMemMB" ]] && [[ "$totalMemMB" -gt 16384 ]]; then
61
- HEAP_SIZE=8192
62
- else
63
- HEAP_SIZE=6144
64
- fi
65
- fi
66
-
67
- # Preserve existing NODE_OPTIONS (user may set --inspect, etc.)
68
- if [[ -n "$NODE_OPTIONS" ]]; then
69
- export NODE_OPTIONS="${NODE_OPTIONS} --max-old-space-size=${HEAP_SIZE}"
70
- else
71
- export NODE_OPTIONS="--max-old-space-size=${HEAP_SIZE}"
72
- fi
73
-
74
- # ── Boot the compiled bundle ─────────────────────────────────────────────────
75
-
76
- # Resolve through symlinks (npm link creates symlink chains)
77
- RESOLVED="$(cd -P "$(dirname "$0")" && pwd)"
78
- SCRIPT_DIR="$(dirname "$(realpath "$0")" 2>/dev/null || echo "$RESOLVED")"
79
- DIST_PATH="${SCRIPT_DIR}/../dist/cli.mjs"
80
-
81
- if [[ -f "$DIST_PATH" ]]; then
82
- exec node "$DIST_PATH" "$@"
83
- else
84
- cat >&2 <<'USAGE'
85
- zero: dist/cli.mjs not found.
86
-
87
- Build first:
88
- bun run build
89
-
90
- Or run directly with Bun:
91
- bun run dev
92
-
93
- See README.md for setup instructions.
94
- USAGE
95
- exit 1
96
- fi
1
+ #!/usr/bin/env node
2
+
3
+ // Zero CLI — Cross-platform wrapper for env var mapping and V8 heap configuration
4
+ //
5
+ // Maps COPILOT_PROVIDER_* / COPILOT_MODEL vars to the native OpenAI-shim
6
+ // vars, then boots the app.
7
+ //
8
+ // Internal (localhost):
9
+ // export COPILOT_PROVIDER_BASE_URL=http://localhost:3052/v1
10
+ // export COPILOT_PROVIDER_TYPE=openai
11
+ // export COPILOT_PROVIDER_API_KEY=not-required
12
+ // export COPILOT_MODEL=gemma4:code
13
+ // zero
14
+ //
15
+ // External (remote server):
16
+ // export COPILOT_PROVIDER_BASE_URL=http://10.11.36.131:3052/v1
17
+ // export COPILOT_PROVIDER_TYPE=openai
18
+ // export COPILOT_PROVIDER_API_KEY=not-required
19
+ // export COPILOT_MODEL=gemma4:code
20
+ // zero
21
+
22
+ import { spawn } from 'child_process';
23
+ import { existsSync } from 'fs';
24
+ import { fileURLToPath } from 'url';
25
+ import { dirname, join } from 'path';
26
+ import os from 'os';
27
+
28
+ const __dirname = dirname(fileURLToPath(import.meta.url));
29
+ const env = { ...process.env };
30
+
31
+ // ── COPILOT_* → native env var mapping ──────────────────────────────────────
32
+
33
+ const providerType = (env.COPILOT_PROVIDER_TYPE ?? '').toLowerCase();
34
+
35
+ if (providerType === 'openai' && env.COPILOT_PROVIDER_BASE_URL) {
36
+ env.CLAUDE_CODE_USE_OPENAI = '1';
37
+ }
38
+
39
+ if (env.COPILOT_PROVIDER_BASE_URL && !env.OPENAI_BASE_URL) {
40
+ env.OPENAI_BASE_URL = env.COPILOT_PROVIDER_BASE_URL;
41
+ }
42
+
43
+ if (env.COPILOT_PROVIDER_API_KEY && !env.OPENAI_API_KEY) {
44
+ env.OPENAI_API_KEY = env.COPILOT_PROVIDER_API_KEY;
45
+ }
46
+
47
+ if (env.COPILOT_MODEL && !env.OPENAI_MODEL) {
48
+ env.OPENAI_MODEL = env.COPILOT_MODEL;
49
+ }
50
+
51
+ // COPILOT_TOOLLESS=1 disable tool calling (text-only mode).
52
+ if (env.COPILOT_TOOLLESS && !env.OPENAI_TOOLLESS) {
53
+ env.OPENAI_TOOLLESS = env.COPILOT_TOOLLESS;
54
+ }
55
+
56
+ // ── V8 heap configuration ────────────────────────────────────────────────────
57
+ //
58
+ // Prevent "JavaScript heap out of memory" crashes during long-running
59
+ // sessions (large context windows, agent waves, file editing). The default
60
+ // V8 heap limit (~4GB) is insufficient for the Zero CLI's context buildup.
61
+ //
62
+ // When running in CCR (remote containers), use 8GB. Otherwise, allocate
63
+ // 8GB on machines with enough RAM, falling back to 6GB as minimum.
64
+
65
+ let heapSize;
66
+ if (env.CLAUDE_CODE_REMOTE === 'true') {
67
+ heapSize = 8192;
68
+ } else {
69
+ const totalMemMB = os.totalmem() / (1024 * 1024);
70
+ heapSize = totalMemMB > 16384 ? 8192 : 6144;
71
+ }
72
+
73
+ // Preserve existing NODE_OPTIONS (user may set --inspect, etc.)
74
+ env.NODE_OPTIONS = env.NODE_OPTIONS
75
+ ? `${env.NODE_OPTIONS} --max-old-space-size=${heapSize}`
76
+ : `--max-old-space-size=${heapSize}`;
77
+
78
+ // ── Boot the compiled bundle ─────────────────────────────────────────────────
79
+
80
+ const distPath = join(__dirname, '..', 'dist', 'cli.mjs');
81
+
82
+ if (!existsSync(distPath)) {
83
+ process.stderr.write(
84
+ ' zero: dist/cli.mjs not found.\n\n' +
85
+ ' Build first:\n bun run build\n\n' +
86
+ ' Or run directly with Bun:\n bun run dev\n\n' +
87
+ ' See README.md for setup instructions.\n'
88
+ );
89
+ process.exit(1);
90
+ }
91
+
92
+ const child = spawn(process.execPath, [distPath, ...process.argv.slice(2)], {
93
+ stdio: 'inherit',
94
+ env,
95
+ });
96
+
97
+ child.on('exit', (code, signal) => {
98
+ if (signal) {
99
+ process.kill(process.pid, signal);
100
+ } else {
101
+ process.exit(code ?? 0);
102
+ }
103
+ });