@twsxtd/hapi 0.1.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 +131 -0
  2. package/bin/hapi.js +48 -0
  3. package/package.json +90 -0
package/README.md ADDED
@@ -0,0 +1,131 @@
1
+ # hapi CLI
2
+
3
+ Run Claude Code, Codex, or Gemini sessions from your terminal and control them remotely through the hapi server.
4
+
5
+ ## What it does
6
+
7
+ - Starts Claude Code sessions and registers them with hapi-server.
8
+ - Starts Codex mode for OpenAI-based sessions.
9
+ - Starts Gemini mode via ACP (Anthropic Code Plugins).
10
+ - Provides an MCP stdio bridge for external tools.
11
+ - Manages a background daemon for long-running sessions.
12
+ - Includes diagnostics and auth helpers.
13
+
14
+ ## Typical flow
15
+
16
+ 1. Start the server and set env vars (see ../server/README.md).
17
+ 2. Set the same CLI_API_TOKEN on this machine or run `hapi auth login`.
18
+ 3. Run `hapi` to start a session.
19
+ 4. Use the web app or Telegram Mini App to monitor and control.
20
+
21
+ ## Commands
22
+
23
+ ### Session commands
24
+
25
+ - `hapi` - Start a Claude Code session (passes through Claude CLI flags). See `src/index.ts`.
26
+ - `hapi codex` - Start Codex mode. See `src/codex/runCodex.ts`.
27
+ - `hapi gemini` - Start Gemini mode via ACP. See `src/agent/runners/runAgentSession.ts`.
28
+
29
+ ### Authentication
30
+
31
+ - `hapi auth status` - Show authentication configuration and token source.
32
+ - `hapi auth login` - Interactively enter and save CLI_API_TOKEN.
33
+ - `hapi auth logout` - Clear saved credentials.
34
+
35
+ See `src/commands/auth.ts`.
36
+
37
+ ### Daemon management
38
+
39
+ - `hapi daemon start` - Start daemon as detached process.
40
+ - `hapi daemon stop` - Stop daemon gracefully.
41
+ - `hapi daemon status` - Show daemon diagnostics.
42
+ - `hapi daemon list` - List active sessions managed by daemon.
43
+ - `hapi daemon stop-session <sessionId>` - Terminate specific session.
44
+ - `hapi daemon logs` - Print path to latest daemon log file.
45
+ - `hapi daemon install` - Install daemon as system service.
46
+ - `hapi daemon uninstall` - Remove daemon system service.
47
+
48
+ See `src/daemon/run.ts`.
49
+
50
+ ### Diagnostics
51
+
52
+ - `hapi doctor` - Show full diagnostics (version, daemon status, logs, processes).
53
+ - `hapi doctor clean` - Kill runaway HAPI processes.
54
+
55
+ See `src/ui/doctor.ts`.
56
+
57
+ ### Other
58
+
59
+ - `hapi mcp` - Start MCP stdio bridge. See `src/codex/happyMcpStdioBridge.ts`.
60
+ - `hapi server` - Start the bundled server (single binary workflow).
61
+
62
+ ## Configuration
63
+
64
+ See `src/configuration.ts` for all options.
65
+
66
+ ### Required
67
+
68
+ - `CLI_API_TOKEN` - Shared secret; must match the server. Can be set via env or `~/.hapi/settings.json` (env wins).
69
+ - `HAPI_BOT_URL` - Server base URL (default: http://localhost:3006).
70
+
71
+ ### Optional
72
+
73
+ - `HAPI_HOME` - Config/data directory (default: ~/.hapi).
74
+ - `HAPI_EXPERIMENTAL` - Enable experimental features (true/1/yes).
75
+ - `HAPI_CLAUDE_PATH` - Path to a specific `claude` executable.
76
+ - `HAPI_HTTP_MCP_URL` - Default MCP target for `hapi mcp`.
77
+
78
+ ### Daemon
79
+
80
+ - `HAPI_DAEMON_HEARTBEAT_INTERVAL` - Heartbeat interval in ms (default: 60000).
81
+ - `HAPI_DAEMON_HTTP_TIMEOUT` - HTTP timeout for daemon control in ms (default: 10000).
82
+
83
+ ### Gemini/Agent
84
+
85
+ - `HAPPY_GEMINI_COMMAND` - Gemini executable command (default: gemini).
86
+ - `HAPPY_GEMINI_ARGS` - Gemini arguments (default: --acp).
87
+
88
+ ## Storage
89
+
90
+ Data is stored in `~/.hapi/` (or `$HAPI_HOME`):
91
+
92
+ - `settings.json` - User settings (machineId, token, onboarding flag). See `src/persistence.ts`.
93
+ - `daemon.state.json` - Daemon state (pid, port, version, heartbeat).
94
+ - `logs/` - Log files.
95
+
96
+ ## Requirements
97
+
98
+ - Claude CLI installed and logged in (`claude` on PATH).
99
+ - Bun for building from source.
100
+
101
+ ## Build from source
102
+
103
+ From the repo root:
104
+
105
+ ```bash
106
+ bun install
107
+ bun run build:cli
108
+ bun run build:cli:exe
109
+ ```
110
+
111
+ For an all-in-one binary that also embeds the web app:
112
+
113
+ ```bash
114
+ bun run build:single-exe
115
+ ```
116
+
117
+ ## Source structure
118
+
119
+ - `src/api/` - Bot communication (Socket.IO + REST).
120
+ - `src/claude/` - Claude Code integration.
121
+ - `src/codex/` - Codex mode integration.
122
+ - `src/agent/` - Multi-agent support (Gemini via ACP).
123
+ - `src/daemon/` - Background service.
124
+ - `src/commands/` - CLI command handlers.
125
+ - `src/ui/` - User interface and diagnostics.
126
+ - `src/modules/` - Tool implementations (ripgrep, difftastic, git).
127
+
128
+ ## Related docs
129
+
130
+ - `../server/README.md`
131
+ - `../web/README.md`
package/bin/hapi.js ADDED
@@ -0,0 +1,48 @@
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 pkgName = `@twsxtd/hapi-${platform}-${arch}`;
9
+
10
+ function getBinaryPath() {
11
+ try {
12
+ // Try to find the platform-specific package
13
+ const pkgPath = require.resolve(`${pkgName}/package.json`);
14
+ const binName = platform === 'win32' ? 'hapi.exe' : 'hapi';
15
+ return path.join(path.dirname(pkgPath), 'bin', binName);
16
+ } catch (e) {
17
+ return null;
18
+ }
19
+ }
20
+
21
+ const binPath = getBinaryPath();
22
+
23
+ if (!binPath) {
24
+ console.error(`Unsupported platform: ${platform}-${arch}`);
25
+ console.error('');
26
+ console.error('Supported platforms:');
27
+ console.error(' - darwin-arm64 (macOS Apple Silicon)');
28
+ console.error(' - darwin-x64 (macOS Intel)');
29
+ console.error(' - linux-arm64');
30
+ console.error(' - linux-x64');
31
+ console.error(' - win32-x64');
32
+ console.error('');
33
+ console.error('You can download the binary manually from:');
34
+ console.error(' https://github.com/anthropics/hapi/releases');
35
+ process.exit(1);
36
+ }
37
+
38
+ try {
39
+ execFileSync(binPath, process.argv.slice(2), { stdio: 'inherit' });
40
+ } catch (e) {
41
+ // If the binary execution fails, exit with the same code
42
+ if (e.status !== undefined) {
43
+ process.exit(e.status);
44
+ }
45
+ // For other errors (e.g., binary not found), print and exit
46
+ console.error(`Failed to execute ${binPath}:`, e.message);
47
+ process.exit(1);
48
+ }
package/package.json ADDED
@@ -0,0 +1,90 @@
1
+ {
2
+ "name": "@twsxtd/hapi",
3
+ "version": "0.1.0",
4
+ "description": "App for agentic coding - access coding agent anywhere",
5
+ "author": "Kirill Dubovitskiy & weishu",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "homepage": "https://github.com/tiann/hapi",
9
+ "bugs": "https://github.com/tiann/hapi/issues",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/tiann/hapi",
13
+ "directory": "cli"
14
+ },
15
+ "bin": {
16
+ "hapi": "bin/hapi.js"
17
+ },
18
+ "files": [
19
+ "bin/hapi.js"
20
+ ],
21
+ "imports": {
22
+ "#embedded-assets": {
23
+ "bun": "./src/runtime/embeddedAssets.bun.ts",
24
+ "default": "./src/runtime/embeddedAssets.stub.ts"
25
+ }
26
+ },
27
+ "optionalDependencies": {
28
+ "@twsxtd/hapi-darwin-arm64": "0.1.0",
29
+ "@twsxtd/hapi-darwin-x64": "0.1.0",
30
+ "@twsxtd/hapi-linux-arm64": "0.1.0",
31
+ "@twsxtd/hapi-linux-x64": "0.1.0",
32
+ "@twsxtd/hapi-win32-x64": "0.1.0"
33
+ },
34
+ "scripts": {
35
+ "typecheck": "tsc --noEmit",
36
+ "build:exe": "bun run scripts/build-executable.ts",
37
+ "build:exe:all": "bun run scripts/build-executable.ts --all",
38
+ "build:exe:allinone": "bun run scripts/build-executable.ts --with-web-assets",
39
+ "build:exe:allinone:all": "bun run scripts/build-executable.ts --with-web-assets --all",
40
+ "prepare-npm-packages": "bun run scripts/prepare-npm-packages.ts",
41
+ "prepack": "bun run prepare-npm-packages",
42
+ "publish-npm": "bun run scripts/publish-npm.ts",
43
+ "publish-npm:dry-run": "bun run scripts/publish-npm.ts --dry-run",
44
+ "tools:unpack": "bun run scripts/unpack-tools.ts",
45
+ "test": "tsx --env-file .env.integration-test node_modules/.bin/vitest run",
46
+ "test:win": "vitest run",
47
+ "dev": "tsx src/index.ts",
48
+ "dev:local-server": "tsx --env-file .env.dev-local-server src/index.ts",
49
+ "dev:integration-test-env": "tsx --env-file .env.integration-test src/index.ts"
50
+ },
51
+ "dependencies": {
52
+ "@modelcontextprotocol/sdk": "^1.22.0",
53
+ "@types/cross-spawn": "^6.0.6",
54
+ "@types/ps-list": "^6.2.1",
55
+ "@types/react": "^19.2.7",
56
+ "@types/tmp": "^0.2.6",
57
+ "axios": "^1.13.2",
58
+ "chalk": "^5.6.2",
59
+ "cross-spawn": "^7.0.6",
60
+ "fastify": "^5.6.2",
61
+ "fastify-type-provider-zod": "4.0.2",
62
+ "ink": "^6.5.1",
63
+ "ps-list": "^8.1.1",
64
+ "react": "^19.2.0",
65
+ "react-devtools-core": "^7.0.1",
66
+ "socket.io-client": "^4.8.1",
67
+ "tar": "^7.5.2",
68
+ "zod": "^3.23.8"
69
+ },
70
+ "devDependencies": {
71
+ "@eslint/compat": "^1",
72
+ "@types/node": ">=20",
73
+ "bun-types": "^1.3.5",
74
+ "cross-env": "^10.1.0",
75
+ "dotenv": "^16.6.1",
76
+ "eslint": "^9",
77
+ "eslint-config-prettier": "^10",
78
+ "shx": "^0.3.3",
79
+ "ts-node": "^10",
80
+ "tsx": "^4.20.6",
81
+ "typescript": "^5",
82
+ "vitest": "^3.2.4"
83
+ },
84
+ "resolutions": {
85
+ "whatwg-url": "14.2.0",
86
+ "parse-path": "7.0.3",
87
+ "@types/parse-path": "7.0.3"
88
+ },
89
+ "packageManager": "bun@1.3.4"
90
+ }