@factadev/cli 0.2.2

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 (5) hide show
  1. package/LICENSE +17 -0
  2. package/NOTICE +52 -0
  3. package/README.md +146 -0
  4. package/bin/nest.cjs +182 -0
  5. package/package.json +86 -0
package/LICENSE ADDED
@@ -0,0 +1,17 @@
1
+ NEST Software License
2
+ Copyright © 2026 Carlos Matias Baglieri
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to use the Software for personal or internal business purposes, subject to the following conditions:
5
+
6
+ 1. Restrictions
7
+ No Modifications: The Software must be used exactly as provided. You may not alter, transform, or build upon this work.
8
+
9
+ No Redistribution: You may not redistribute, sub-license, or sell the Software to third parties without express written authorization from the owner.
10
+
11
+ Authorization: Any use case not explicitly covered by this license requires prior written consent. Please contact matias@facta.dev for authorization inquiries.
12
+
13
+ 2. Disclaimer of Warranty
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT.
15
+
16
+ 3. Limitation of Liability
17
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS (CARLOS MATIAS BAGLIERI) BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OF THE SOFTWARE. THE USERS USE THIS SOFTWARE AT THEIR OWN RISK AND RESPONSIBILITY.
package/NOTICE ADDED
@@ -0,0 +1,52 @@
1
+ nest CLI
2
+ Copyright (c) 2024-2026 Carlos Matias Baglieri
3
+
4
+ This software contains code derived from happy-cli
5
+ (https://github.com/slopus/happy-cli), which is licensed
6
+ under the MIT License:
7
+
8
+ ---
9
+
10
+ MIT License
11
+
12
+ Copyright (c) 2024 Kirill Dubovitskiy
13
+
14
+ Permission is hereby granted, free of charge, to any person obtaining a copy
15
+ of this software and associated documentation files (the "Software"), to deal
16
+ in the Software without restriction, including without limitation the rights
17
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18
+ copies of the Software, and to permit persons to whom the Software is
19
+ furnished to do so, subject to the following conditions:
20
+
21
+ The above copyright notice and this permission notice shall be included in all
22
+ copies or substantial portions of the Software.
23
+
24
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30
+ SOFTWARE.
31
+
32
+ ---
33
+
34
+ The following files/directories are derived from happy-cli:
35
+ - src/api/
36
+ - src/claude/
37
+ - src/codex/
38
+ - src/runner/
39
+ - src/commands/
40
+ - src/ui/
41
+ - src/utils/
42
+ - src/modules/ripgrep/
43
+ - src/modules/difftastic/
44
+ - src/modules/watcher/
45
+ - src/modules/common/registerCommonHandlers.ts
46
+ - src/modules/common/pathSecurity.ts
47
+ - src/parsers/
48
+ - src/configuration.ts
49
+ - src/persistence.ts
50
+ - src/projectPath.ts
51
+ - src/lib.ts
52
+ - src/index.ts
package/README.md ADDED
@@ -0,0 +1,146 @@
1
+ # nest CLI
2
+
3
+ Run Claude Code, Codex, Cursor Agent, Gemini, or OpenCode sessions from your terminal and control them remotely through the NEST hub.
4
+
5
+ ## What it does
6
+
7
+ - Starts Claude Code sessions and registers them with nest-hub.
8
+ - Starts Codex mode for OpenAI-based sessions.
9
+ - Starts Cursor Agent mode for Cursor CLI sessions.
10
+ - Starts Gemini mode via ACP (Anthropic Code Plugins).
11
+ - Starts OpenCode mode via ACP and its plugin hook system.
12
+ - Provides an MCP stdio bridge for external tools.
13
+ - Manages a background runner for long-running sessions.
14
+ - Includes diagnostics and auth helpers.
15
+
16
+ ## Typical flow
17
+
18
+ 1. Start the hub and set env vars (see ../hub/README.md).
19
+ 2. Set the same CLI_API_TOKEN on this machine or run `nest auth login`.
20
+ 3. Run `nest` to start a session.
21
+ 4. Use the web app or Telegram Mini App to monitor and control.
22
+
23
+ ## Commands
24
+
25
+ ### Session commands
26
+
27
+ - `nest` - Start a Claude Code session (passes through Claude CLI flags). See `src/index.ts`.
28
+ - `nest codex` - Start Codex mode. See `src/codex/runCodex.ts`.
29
+ - `nest codex resume <sessionId>` - Resume existing Codex session.
30
+ - `nest cursor` - Start Cursor Agent mode. See `src/cursor/runCursor.ts`.
31
+ Supports `nest cursor resume <chatId>`, `nest cursor --continue`, `--mode plan|ask`, `--yolo`, `--model`.
32
+ Local and remote modes supported; remote uses `agent -p` with stream-json.
33
+ - `nest gemini` - Start Gemini mode via ACP. See `src/agent/runners/runAgentSession.ts`.
34
+ Note: Gemini runs in remote mode only; it waits for messages from the hub UI/Telegram.
35
+ - `nest opencode` - Start OpenCode mode via ACP. See `src/opencode/runOpencode.ts`.
36
+ Note: OpenCode supports local and remote modes; local mode streams via OpenCode plugins.
37
+
38
+ ### Authentication
39
+
40
+ - `nest auth status` - Show authentication configuration and token source.
41
+ - `nest auth login` - Interactively enter and save CLI_API_TOKEN.
42
+ - `nest auth logout` - Clear saved credentials.
43
+
44
+ See `src/commands/auth.ts`.
45
+
46
+ ### Runner management
47
+
48
+ - `nest runner start` - Start runner as detached process.
49
+ - `nest runner stop` - Stop runner gracefully.
50
+ - `nest runner status` - Show runner diagnostics.
51
+ - `nest runner list` - List active sessions managed by runner.
52
+ - `nest runner stop-session <sessionId>` - Terminate specific session.
53
+ - `nest runner logs` - Print path to latest runner log file.
54
+
55
+ See `src/runner/run.ts`.
56
+
57
+ ### Diagnostics
58
+
59
+ - `nest doctor` - Show full diagnostics (version, runner status, logs, processes).
60
+ - `nest doctor clean` - Kill runaway NEST processes.
61
+
62
+ See `src/ui/doctor.ts`.
63
+
64
+ ### Other
65
+
66
+ - `nest mcp` - Start MCP stdio bridge. See `src/codex/happyMcpStdioBridge.ts`.
67
+ - `nest hub` - Start the bundled hub (single binary workflow).
68
+ - `nest server` - Alias for `nest hub`.
69
+
70
+ ## Configuration
71
+
72
+ See `src/configuration.ts` for all options.
73
+
74
+ ### Required
75
+
76
+ - `CLI_API_TOKEN` - Shared secret; must match the hub. Can be set via env or `~/.nest/settings.json` (env wins).
77
+ - `NEST_API_URL` - Hub base URL (default: http://localhost:3006).
78
+
79
+ ### Optional
80
+
81
+ - `NEST_HOME` - Config/data directory (default: ~/.nest).
82
+ - `NEST_EXPERIMENTAL` - Enable experimental features (true/1/yes).
83
+ - `NEST_CLAUDE_PATH` - Path to a specific `claude` executable.
84
+ - `NEST_HTTP_MCP_URL` - Default MCP target for `nest mcp`.
85
+
86
+ ### Runner
87
+
88
+ - `NEST_RUNNER_HEARTBEAT_INTERVAL` - Heartbeat interval in ms (default: 60000).
89
+ - `NEST_RUNNER_HTTP_TIMEOUT` - HTTP timeout for runner control in ms (default: 10000).
90
+
91
+ ### Worktree (set by runner)
92
+
93
+ - `NEST_WORKTREE_BASE_PATH` - Base repository path.
94
+ - `NEST_WORKTREE_BRANCH` - Current branch name.
95
+ - `NEST_WORKTREE_NAME` - Worktree name.
96
+ - `NEST_WORKTREE_PATH` - Full worktree path.
97
+ - `NEST_WORKTREE_CREATED_AT` - Creation timestamp (ms).
98
+
99
+ ## Storage
100
+
101
+ Data is stored in `~/.nest/` (or `$NEST_HOME`):
102
+
103
+ - `settings.json` - User settings (machineId, token, onboarding flag). See `src/persistence.ts`.
104
+ - `runner.state.json` - Runner state (pid, port, version, heartbeat).
105
+ - `logs/` - Log files.
106
+
107
+ ## Requirements
108
+
109
+ - Claude CLI installed and logged in (`claude` on PATH).
110
+ - Cursor Agent CLI installed (`agent` on PATH) for `nest cursor`. Install: `curl https://cursor.com/install -fsS | bash` (macOS/Linux), `irm 'https://cursor.com/install?win32=true' | iex` (Windows).
111
+ - OpenCode CLI installed (`opencode` on PATH).
112
+ - Bun for building from source.
113
+
114
+ ## Build from source
115
+
116
+ From the repo root:
117
+
118
+ ```bash
119
+ bun install
120
+ bun run build:cli
121
+ bun run build:cli:exe
122
+ ```
123
+
124
+ For an all-in-one binary that also embeds the web app:
125
+
126
+ ```bash
127
+ bun run build:single-exe
128
+ ```
129
+
130
+ ## Source structure
131
+
132
+ - `src/api/` - Bot communication (Socket.IO + REST).
133
+ - `src/claude/` - Claude Code integration.
134
+ - `src/codex/` - Codex mode integration.
135
+ - `src/cursor/` - Cursor Agent integration.
136
+ - `src/agent/` - Multi-agent support (Gemini via ACP).
137
+ - `src/opencode/` - OpenCode ACP + hook integration.
138
+ - `src/runner/` - Background service.
139
+ - `src/commands/` - CLI command handlers.
140
+ - `src/ui/` - User interface and diagnostics.
141
+ - `src/modules/` - Tool implementations (ripgrep, difftastic, git).
142
+
143
+ ## Related docs
144
+
145
+ - `../hub/README.md`
146
+ - `../web/README.md`
package/bin/nest.cjs ADDED
@@ -0,0 +1,182 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { execFileSync } = require('child_process');
4
+ const path = require('path');
5
+
6
+ const platform = process.platform;
7
+ const arch = process.arch;
8
+ const RELEASE_URL = 'https://github.com/ctx0/nest/releases';
9
+ const OFFICIAL_NPM_REGISTRY = 'https://registry.npmjs.org';
10
+ const SUPPORTED_PLATFORMS = [
11
+ {
12
+ key: 'darwin-arm64',
13
+ label: 'darwin-arm64 (macOS Apple Silicon)',
14
+ },
15
+ {
16
+ key: 'darwin-x64',
17
+ label: 'darwin-x64 (macOS Intel)',
18
+ },
19
+ {
20
+ key: 'linux-arm64',
21
+ label: 'linux-arm64',
22
+ },
23
+ {
24
+ key: 'linux-x64',
25
+ label: 'linux-x64',
26
+ },
27
+ {
28
+ key: 'win32-x64',
29
+ label: 'win32-x64',
30
+ },
31
+ ];
32
+
33
+ function getPlatformKey(platformName = platform, archName = arch) {
34
+ return `${platformName}-${archName}`;
35
+ }
36
+
37
+ function isSupportedPlatform(platformName = platform, archName = arch) {
38
+ return SUPPORTED_PLATFORMS.some((item) => item.key === getPlatformKey(platformName, archName));
39
+ }
40
+
41
+ function getBinaryPath(platformName = platform, archName = arch) {
42
+ const pkgName = `@factadev/cli-${platformName}-${archName}`;
43
+
44
+ try {
45
+ const pkgPath = require.resolve(`${pkgName}/package.json`);
46
+ const binName = platformName === 'win32' ? 'nest.exe' : 'nest';
47
+ return path.join(path.dirname(pkgPath), 'bin', binName);
48
+ } catch (e) {
49
+ return null;
50
+ }
51
+ }
52
+
53
+ function getBunPath() {
54
+ const bunPaths = [
55
+ path.join(__dirname, '..', 'node_modules', '.bin', 'bun'),
56
+ path.join(process.env.HOME || '', '.bun', 'bin', 'bun'),
57
+ path.join(process.env.APPDATA || '', 'bun', 'bin', 'bun.exe'),
58
+ '/usr/local/bin/bun',
59
+ '/opt/homebrew/bin/bun',
60
+ ];
61
+
62
+ for (const p of bunPaths) {
63
+ try {
64
+ require('fs').accessSync(p, require('fs').constants.X_OK);
65
+ return p;
66
+ } catch {}
67
+ }
68
+
69
+ return 'bun';
70
+ }
71
+
72
+ function formatCommand(binPath, args) {
73
+ return [binPath, ...args].map((arg) => JSON.stringify(String(arg))).join(' ');
74
+ }
75
+
76
+ function normalizeExecError(error) {
77
+ return {
78
+ status: typeof error?.status === 'number' ? error.status : null,
79
+ signal: typeof error?.signal === 'string' ? error.signal : null,
80
+ message: error?.message ? String(error.message) : null,
81
+ };
82
+ }
83
+
84
+ function reportExecutionFailure(error, binPath, args, log = console.error) {
85
+ const { status, signal, message } = normalizeExecError(error);
86
+
87
+ log(`Failed to execute: ${formatCommand(binPath, args)}`);
88
+
89
+ if (signal) {
90
+ log(`Binary terminated by signal ${signal}.`);
91
+ }
92
+
93
+ if (status !== null) {
94
+ log(`Binary exited with status ${status}.`);
95
+ }
96
+
97
+ if (message) {
98
+ log(message);
99
+ }
100
+
101
+ return { status, signal };
102
+ }
103
+
104
+ function reportUnsupportedPlatform(platformName = platform, archName = arch, log = console.error) {
105
+ log(`Unsupported platform: ${platformName}-${archName}`);
106
+ log('');
107
+ log('Supported platforms:');
108
+ for (const item of SUPPORTED_PLATFORMS) {
109
+ log(` - ${item.label}`);
110
+ }
111
+ log('');
112
+ log('You can download the binary manually from:');
113
+ log(` ${RELEASE_URL}`);
114
+ }
115
+
116
+ function reportMissingPlatformPackage(platformName = platform, archName = arch, log = console.error) {
117
+ const platformPackage = `@factadev/cli-${platformName}-${archName}`;
118
+ log(`Missing platform package: ${platformPackage}`);
119
+ log('');
120
+ log(`Detected platform ${platformName}-${archName} is supported, but the platform binary package was not installed.`);
121
+ log('The CLI will attempt to fall back to using bun to run directly.');
122
+ log('');
123
+ log('To ensure fastest startup, try reinstalling with the official npm registry:');
124
+ log(` npm install -g @factadev/cli --registry=${OFFICIAL_NPM_REGISTRY}`);
125
+ log('');
126
+ log('Or install bun and the CLI will use it as fallback:');
127
+ log(' curl -fsSL https://bun.sh/install | bash');
128
+ log('');
129
+ log('You can also download binaries manually from:');
130
+ log(` ${RELEASE_URL}`);
131
+ }
132
+
133
+ function main() {
134
+ if (!isSupportedPlatform()) {
135
+ reportUnsupportedPlatform();
136
+ process.exit(1);
137
+ }
138
+
139
+ let binPath = getBinaryPath();
140
+ let useBun = !binPath;
141
+
142
+ if (useBun) {
143
+ const bunPath = getBunPath();
144
+ const cliPath = path.join(__dirname, '..', 'src', 'index.ts');
145
+ console.log('No pre-built binary for this platform. Using bun to run CLI...\n');
146
+
147
+ try {
148
+ execFileSync(bunPath, [cliPath, ...process.argv.slice(2)], {
149
+ stdio: 'inherit',
150
+ env: {
151
+ ...process.env,
152
+ npm_lifecycle_event: 'nest',
153
+ npm_package_name: '@factadev/cli',
154
+ },
155
+ });
156
+ return;
157
+ } catch (error) {
158
+ console.error(`Failed to run with bun: ${error.message}`);
159
+ console.error('\nPlease install bun:');
160
+ console.error(' curl -fsSL https://bun.sh/install | bash');
161
+ process.exit(1);
162
+ }
163
+ }
164
+
165
+ const args = process.argv.slice(2);
166
+
167
+ try {
168
+ execFileSync(binPath, args, {
169
+ stdio: 'inherit',
170
+ env: {
171
+ ...process.env,
172
+ npm_lifecycle_event: 'nest',
173
+ npm_package_name: '@factadev/cli',
174
+ },
175
+ });
176
+ } catch (error) {
177
+ const { status, signal } = reportExecutionFailure(error, binPath, args);
178
+ process.exit(status ?? (signal ? 1 : 1));
179
+ }
180
+ }
181
+
182
+ main();
package/package.json ADDED
@@ -0,0 +1,86 @@
1
+ {
2
+ "name": "@factadev/cli",
3
+ "version": "0.2.2",
4
+ "description": "NEST CLI - Run AI coding agents and control them remotely",
5
+ "author": "Carlos Matias Baglieri",
6
+ "license": "UNLICENSED",
7
+ "type": "module",
8
+ "homepage": "https://github.com/ctx0/nest",
9
+ "bugs": "https://github.com/ctx0/nest/issues",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/ctx0/nest.git",
13
+ "directory": "cli"
14
+ },
15
+ "bin": {
16
+ "nest": "bin/nest.cjs"
17
+ },
18
+ "files": [
19
+ "bin/nest.cjs",
20
+ "NOTICE"
21
+ ],
22
+ "imports": {
23
+ "#embedded-assets": {
24
+ "bun": "./src/runtime/embeddedAssets.bun.ts",
25
+ "default": "./src/runtime/embeddedAssets.stub.ts"
26
+ }
27
+ },
28
+ "dependencies": {
29
+ "@factadev/protocol": "workspace:*",
30
+ "@modelcontextprotocol/sdk": "^1.25.1",
31
+ "@types/cross-spawn": "^6.0.6",
32
+ "@types/ps-list": "^6.2.1",
33
+ "@types/react": "^19.2.7",
34
+ "axios": "^1.13.2",
35
+ "chalk": "^5.6.2",
36
+ "cross-spawn": "^7.0.6",
37
+ "fastify": "^5.6.2",
38
+ "fastify-type-provider-zod": "6.1.0",
39
+ "ink": "^6.6.0",
40
+ "ps-list": "^9.0.0",
41
+ "react": "^19.2.3",
42
+ "socket.io-client": "^4.8.3",
43
+ "tar": "^7.5.2",
44
+ "yaml": "^2.8.2",
45
+ "zod": "^4.2.1"
46
+ },
47
+ "scripts": {
48
+ "postinstall": "node -e \"try{require('fs').chmodSync(require('path').join(__dirname,'bin','nest.cjs'),0o755)}catch(e){}\"",
49
+ "typecheck": "tsc --noEmit",
50
+ "build:exe": "bun run scripts/build-executable.ts",
51
+ "build:exe:all": "bun run scripts/build-executable.ts --all",
52
+ "build:exe:allinone": "bun run scripts/build-executable.ts --with-web-assets",
53
+ "build:exe:allinone:all": "bun run scripts/build-executable.ts --with-web-assets --all",
54
+ "prepare-npm-packages": "bun run scripts/prepare-npm-packages.ts",
55
+ "prepack": "bun run prepare-npm-packages",
56
+ "tools:unpack": "bun run scripts/unpack-tools.ts",
57
+ "update-homebrew-formula": "bun run scripts/update-homebrew-formula.ts",
58
+ "test": "bun run tools:unpack && vitest run",
59
+ "test:win": "vitest run",
60
+ "publish": "bash scripts/publish.sh",
61
+ "dev": "bun src/index.ts",
62
+ "dev:local-server": "bun --env-file .env.dev-local-server src/index.ts",
63
+ "dev:integration-test-env": "bun --env-file .env.integration-test src/index.ts",
64
+ "release-all": "bun run scripts/release-all.ts"
65
+ },
66
+ "devDependencies": {
67
+ "@types/node": ">=25",
68
+ "bun-types": "^1.3.5",
69
+ "dotenv": "^17.2.3",
70
+ "typescript": "^5",
71
+ "vitest": "^4.0.16"
72
+ },
73
+ "resolutions": {
74
+ "whatwg-url": "14.2.0",
75
+ "parse-path": "7.0.3",
76
+ "@types/parse-path": "7.0.3"
77
+ },
78
+ "packageManager": "bun@1.3.5",
79
+ "optionalDependencies": {
80
+ "@factadev/cli-darwin-arm64": "0.2.2",
81
+ "@factadev/cli-darwin-x64": "0.2.2",
82
+ "@factadev/cli-linux-arm64": "0.2.2",
83
+ "@factadev/cli-linux-x64": "0.2.2",
84
+ "@factadev/cli-win32-x64": "0.2.2"
85
+ }
86
+ }