@zhigang1992/happy-cli 0.12.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.
Files changed (47) hide show
  1. package/README.md +60 -0
  2. package/bin/happy-mcp.mjs +32 -0
  3. package/bin/happy.mjs +35 -0
  4. package/dist/codex/happyMcpStdioBridge.cjs +80 -0
  5. package/dist/codex/happyMcpStdioBridge.d.cts +2 -0
  6. package/dist/codex/happyMcpStdioBridge.d.mts +2 -0
  7. package/dist/codex/happyMcpStdioBridge.mjs +78 -0
  8. package/dist/index-BOBrKhX5.cjs +6655 -0
  9. package/dist/index-DsHtmQqP.mjs +6624 -0
  10. package/dist/index.cjs +42 -0
  11. package/dist/index.d.cts +1 -0
  12. package/dist/index.d.mts +1 -0
  13. package/dist/index.mjs +39 -0
  14. package/dist/lib.cjs +31 -0
  15. package/dist/lib.d.cts +817 -0
  16. package/dist/lib.d.mts +817 -0
  17. package/dist/lib.mjs +21 -0
  18. package/dist/list-BW6QBLa1.cjs +328 -0
  19. package/dist/list-hET5tyMc.mjs +326 -0
  20. package/dist/prompt-DXkgjktW.cjs +203 -0
  21. package/dist/prompt-Dz7G8yGx.mjs +201 -0
  22. package/dist/runCodex-CLGYMNs2.mjs +1335 -0
  23. package/dist/runCodex-CylcX5Ug.cjs +1338 -0
  24. package/dist/types-BsjUgWOx.cjs +2264 -0
  25. package/dist/types-CGco5Y-r.mjs +2213 -0
  26. package/package.json +126 -0
  27. package/scripts/claude_local_launcher.cjs +98 -0
  28. package/scripts/claude_remote_launcher.cjs +13 -0
  29. package/scripts/ripgrep_launcher.cjs +33 -0
  30. package/scripts/unpack-tools.cjs +163 -0
  31. package/tools/archives/difftastic-LICENSE +21 -0
  32. package/tools/archives/difftastic-arm64-darwin.tar.gz +0 -0
  33. package/tools/archives/difftastic-arm64-linux.tar.gz +0 -0
  34. package/tools/archives/difftastic-x64-darwin.tar.gz +0 -0
  35. package/tools/archives/difftastic-x64-linux.tar.gz +0 -0
  36. package/tools/archives/difftastic-x64-win32.tar.gz +0 -0
  37. package/tools/archives/ripgrep-LICENSE +3 -0
  38. package/tools/archives/ripgrep-arm64-darwin.tar.gz +0 -0
  39. package/tools/archives/ripgrep-arm64-linux.tar.gz +0 -0
  40. package/tools/archives/ripgrep-x64-darwin.tar.gz +0 -0
  41. package/tools/archives/ripgrep-x64-linux.tar.gz +0 -0
  42. package/tools/archives/ripgrep-x64-win32.tar.gz +0 -0
  43. package/tools/licenses/difftastic-LICENSE +21 -0
  44. package/tools/licenses/ripgrep-LICENSE +3 -0
  45. package/tools/unpacked/difft +0 -0
  46. package/tools/unpacked/rg +0 -0
  47. package/tools/unpacked/ripgrep.node +0 -0
package/package.json ADDED
@@ -0,0 +1,126 @@
1
+ {
2
+ "name": "@zhigang1992/happy-cli",
3
+ "version": "0.12.1",
4
+ "description": "Mobile and Web client for Claude Code and Codex",
5
+ "author": "Kirill Dubovitskiy",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "homepage": "https://github.com/slopus/happy-cli",
9
+ "bugs": "https://github.com/slopus/happy-cli/issues",
10
+ "repository": "slopus/happy-cli",
11
+ "bin": {
12
+ "happy": "./bin/happy.mjs",
13
+ "happy-mcp": "./bin/happy-mcp.mjs"
14
+ },
15
+ "main": "./dist/index.cjs",
16
+ "module": "./dist/index.mjs",
17
+ "types": "./dist/index.d.cts",
18
+ "exports": {
19
+ ".": {
20
+ "require": {
21
+ "types": "./dist/index.d.cts",
22
+ "default": "./dist/index.cjs"
23
+ },
24
+ "import": {
25
+ "types": "./dist/index.d.mts",
26
+ "default": "./dist/index.mjs"
27
+ }
28
+ },
29
+ "./lib": {
30
+ "require": {
31
+ "types": "./dist/lib.d.cts",
32
+ "default": "./dist/lib.cjs"
33
+ },
34
+ "import": {
35
+ "types": "./dist/lib.d.mts",
36
+ "default": "./dist/lib.mjs"
37
+ }
38
+ },
39
+ "./codex/happyMcpStdioBridge": {
40
+ "require": {
41
+ "types": "./dist/codex/happyMcpStdioBridge.d.cts",
42
+ "default": "./dist/codex/happyMcpStdioBridge.cjs"
43
+ },
44
+ "import": {
45
+ "types": "./dist/codex/happyMcpStdioBridge.d.mts",
46
+ "default": "./dist/codex/happyMcpStdioBridge.mjs"
47
+ }
48
+ }
49
+ },
50
+ "files": [
51
+ "dist",
52
+ "bin",
53
+ "scripts",
54
+ "tools",
55
+ "package.json"
56
+ ],
57
+ "scripts": {
58
+ "why do we need to build before running tests / dev?": "We need the binary to be built so we run daemon commands which directly run the binary - we don't want them to go out of sync or have custom spawn logic depending how we started happy",
59
+ "typecheck": "tsc --noEmit",
60
+ "build": "shx rm -rf dist && npx tsc --noEmit && pkgroll",
61
+ "test": "yarn build && tsx --env-file .env.integration-test node_modules/.bin/vitest run",
62
+ "start": "yarn build && ./bin/happy.mjs",
63
+ "dev": "tsx src/index.ts",
64
+ "dev:local-server": "yarn build && tsx --env-file .env.dev-local-server src/index.ts",
65
+ "dev:integration-test-env": "yarn build && tsx --env-file .env.integration-test src/index.ts",
66
+ "prepublishOnly": "yarn build && yarn test",
67
+ "release": "release-it",
68
+ "postinstall": "node scripts/unpack-tools.cjs"
69
+ },
70
+ "dependencies": {
71
+ "@anthropic-ai/claude-code": "2.0.55",
72
+ "@anthropic-ai/sdk": "0.65.0",
73
+ "@elevenlabs/elevenlabs-js": "^2.25.1",
74
+ "@modelcontextprotocol/sdk": "^1.15.1",
75
+ "@stablelib/base64": "^2.0.1",
76
+ "@stablelib/hex": "^2.0.1",
77
+ "@types/cross-spawn": "^6.0.6",
78
+ "@types/http-proxy": "^1.17.16",
79
+ "@types/ps-list": "^6.2.1",
80
+ "@types/qrcode-terminal": "^0.12.2",
81
+ "@types/react": "^19.1.9",
82
+ "@types/tmp": "^0.2.6",
83
+ "axios": "^1.10.0",
84
+ "chalk": "^5.4.1",
85
+ "cross-spawn": "^7.0.6",
86
+ "expo-server-sdk": "^3.15.0",
87
+ "fastify": "^5.5.0",
88
+ "fastify-type-provider-zod": "4.0.2",
89
+ "http-proxy": "^1.18.1",
90
+ "http-proxy-middleware": "^3.0.5",
91
+ "ink": "^6.1.0",
92
+ "open": "^10.2.0",
93
+ "ps-list": "^8.1.1",
94
+ "qrcode-terminal": "^0.12.0",
95
+ "react": "^19.1.1",
96
+ "socket.io-client": "^4.8.1",
97
+ "tar": "^7.4.3",
98
+ "tmp": "^0.2.5",
99
+ "tweetnacl": "^1.0.3",
100
+ "zod": "^3.23.8"
101
+ },
102
+ "devDependencies": {
103
+ "@eslint/compat": "^1",
104
+ "@types/node": ">=20",
105
+ "cross-env": "^10.0.0",
106
+ "dotenv": "^16.6.1",
107
+ "eslint": "^9",
108
+ "eslint-config-prettier": "^10",
109
+ "pkgroll": "^2.14.2",
110
+ "release-it": "^19.0.4",
111
+ "shx": "^0.3.3",
112
+ "ts-node": "^10",
113
+ "tsx": "^4.20.3",
114
+ "typescript": "^5",
115
+ "vitest": "^3.2.4"
116
+ },
117
+ "resolutions": {
118
+ "whatwg-url": "14.2.0",
119
+ "parse-path": "7.0.3",
120
+ "@types/parse-path": "7.0.3"
121
+ },
122
+ "publishConfig": {
123
+ "registry": "https://registry.npmjs.org"
124
+ },
125
+ "packageManager": "yarn@1.22.22"
126
+ }
@@ -0,0 +1,98 @@
1
+ const crypto = require('crypto');
2
+ const fs = require('fs');
3
+
4
+ // Disable autoupdater (never works really)
5
+ process.env.DISABLE_AUTOUPDATER = '1';
6
+
7
+ // Helper to write JSON messages to fd 3
8
+ function writeMessage(message) {
9
+ try {
10
+ fs.writeSync(3, JSON.stringify(message) + '\n');
11
+ } catch (err) {
12
+ // fd 3 not available, ignore
13
+ }
14
+ }
15
+
16
+ // Intercept crypto.randomUUID
17
+ const originalRandomUUID = crypto.randomUUID;
18
+ Object.defineProperty(global, 'crypto', {
19
+ configurable: true,
20
+ enumerable: true,
21
+ get() {
22
+ return {
23
+ randomUUID: () => {
24
+ const uuid = originalRandomUUID();
25
+ writeMessage({ type: 'uuid', value: uuid });
26
+ return uuid;
27
+ }
28
+ };
29
+ }
30
+ });
31
+ Object.defineProperty(crypto, 'randomUUID', {
32
+ configurable: true,
33
+ enumerable: true,
34
+ get() {
35
+ return () => {
36
+ const uuid = originalRandomUUID();
37
+ writeMessage({ type: 'uuid', value: uuid });
38
+ return uuid;
39
+ }
40
+ }
41
+ });
42
+
43
+ // Intercept fetch to track activity
44
+ const originalFetch = global.fetch;
45
+ let fetchCounter = 0;
46
+
47
+ global.fetch = function(...args) {
48
+ const id = ++fetchCounter;
49
+ const url = typeof args[0] === 'string' ? args[0] : args[0]?.url || '';
50
+ const method = args[1]?.method || 'GET';
51
+
52
+ // Parse URL for privacy
53
+ let hostname = '';
54
+ let path = '';
55
+ try {
56
+ const urlObj = new URL(url, 'http://localhost');
57
+ hostname = urlObj.hostname;
58
+ path = urlObj.pathname;
59
+ } catch (e) {
60
+ // If URL parsing fails, use defaults
61
+ hostname = 'unknown';
62
+ path = url;
63
+ }
64
+
65
+ // Send fetch start event
66
+ writeMessage({
67
+ type: 'fetch-start',
68
+ id,
69
+ hostname,
70
+ path,
71
+ method,
72
+ timestamp: Date.now()
73
+ });
74
+
75
+ // Execute the original fetch immediately
76
+ const fetchPromise = originalFetch(...args);
77
+
78
+ // Attach handlers to send fetch end event
79
+ const sendEnd = () => {
80
+ writeMessage({
81
+ type: 'fetch-end',
82
+ id,
83
+ timestamp: Date.now()
84
+ });
85
+ };
86
+
87
+ // Send end event on both success and failure
88
+ fetchPromise.then(sendEnd, sendEnd);
89
+
90
+ // Return the original promise unchanged
91
+ return fetchPromise;
92
+ };
93
+
94
+ // Preserve fetch properties
95
+ Object.defineProperty(global.fetch, 'name', { value: 'fetch' });
96
+ Object.defineProperty(global.fetch, 'length', { value: originalFetch.length });
97
+
98
+ import('@anthropic-ai/claude-code/cli.js')
@@ -0,0 +1,13 @@
1
+ // Intercept setTimeout for the Claude Code SDK
2
+ const originalSetTimeout = global.setTimeout;
3
+
4
+ global.setTimeout = function(callback, delay, ...args) {
5
+ // Just wrap and call the original setTimeout
6
+ return originalSetTimeout(callback, delay, ...args);
7
+ };
8
+
9
+ // Preserve setTimeout properties
10
+ Object.defineProperty(global.setTimeout, 'name', { value: 'setTimeout' });
11
+ Object.defineProperty(global.setTimeout, 'length', { value: originalSetTimeout.length });
12
+
13
+ import('@anthropic-ai/claude-code/cli.js')
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Ripgrep runner - executed as a subprocess to run the native module
5
+ * This file is intentionally written in CommonJS to avoid ESM complexities
6
+ */
7
+
8
+ const path = require('path');
9
+
10
+ // Load the native module from unpacked directory
11
+ const modulePath = path.join(__dirname, '..', 'tools', 'unpacked', 'ripgrep.node');
12
+ const ripgrepNative = require(modulePath);
13
+
14
+ // Get arguments from command line (skip node and script name)
15
+ const args = process.argv.slice(2);
16
+
17
+ // Parse the JSON-encoded arguments
18
+ let parsedArgs;
19
+ try {
20
+ parsedArgs = JSON.parse(args[0]);
21
+ } catch (error) {
22
+ console.error('Failed to parse arguments:', error.message);
23
+ process.exit(1);
24
+ }
25
+
26
+ // Run ripgrep
27
+ try {
28
+ const exitCode = ripgrepNative.ripgrepMain(parsedArgs);
29
+ process.exit(exitCode);
30
+ } catch (error) {
31
+ console.error('Ripgrep error:', error.message);
32
+ process.exit(1);
33
+ }
@@ -0,0 +1,163 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Unpacks platform-specific binaries from compressed archives
5
+ * This script extracts the necessary tools for the current platform
6
+ */
7
+
8
+ const fs = require('fs');
9
+ const path = require('path');
10
+ const zlib = require('zlib');
11
+ const tar = require('tar');
12
+ const os = require('os');
13
+
14
+ /**
15
+ * Get the platform-specific directory name
16
+ */
17
+ function getPlatformDir() {
18
+ const platform = os.platform();
19
+ const arch = os.arch();
20
+
21
+ if (platform === 'darwin') {
22
+ if (arch === 'arm64') return 'arm64-darwin';
23
+ if (arch === 'x64') return 'x64-darwin';
24
+ } else if (platform === 'linux') {
25
+ if (arch === 'arm64') return 'arm64-linux';
26
+ if (arch === 'x64') return 'x64-linux';
27
+ } else if (platform === 'win32') {
28
+ if (arch === 'x64') return 'x64-win32';
29
+ }
30
+
31
+ throw new Error(`Unsupported platform: ${arch}-${platform}`);
32
+ }
33
+
34
+ /**
35
+ * Get the root tools directory
36
+ */
37
+ function getToolsDir() {
38
+ // Handle both direct execution and require() calls
39
+ const scriptDir = __dirname;
40
+ return path.resolve(scriptDir, '..', 'tools');
41
+ }
42
+
43
+ /**
44
+ * Check if tools are already unpacked for current platform
45
+ */
46
+ function areToolsUnpacked(toolsDir) {
47
+ const unpackedPath = path.join(toolsDir, 'unpacked');
48
+
49
+ if (!fs.existsSync(unpackedPath)) {
50
+ return false;
51
+ }
52
+
53
+ // Check for expected binaries
54
+ const isWin = os.platform() === 'win32';
55
+ const difftBinary = isWin ? 'difft.exe' : 'difft';
56
+ const rgBinary = isWin ? 'rg.exe' : 'rg';
57
+
58
+ const expectedFiles = [
59
+ path.join(unpackedPath, difftBinary),
60
+ path.join(unpackedPath, rgBinary),
61
+ path.join(unpackedPath, 'ripgrep.node')
62
+ ];
63
+
64
+ return expectedFiles.every(file => fs.existsSync(file));
65
+ }
66
+
67
+ /**
68
+ * Unpack a tar.gz archive to a destination directory
69
+ */
70
+ async function unpackArchive(archivePath, destDir) {
71
+ return new Promise((resolve, reject) => {
72
+ // Ensure destination directory exists
73
+ if (!fs.existsSync(destDir)) {
74
+ fs.mkdirSync(destDir, { recursive: true });
75
+ }
76
+
77
+ // Create read stream and extract
78
+ fs.createReadStream(archivePath)
79
+ .pipe(zlib.createGunzip())
80
+ .pipe(tar.extract({
81
+ cwd: destDir,
82
+ preserveMode: true,
83
+ preserveOwner: false
84
+ }))
85
+ .on('finish', () => {
86
+ // Set executable permissions for Unix systems
87
+ if (os.platform() !== 'win32') {
88
+ const files = fs.readdirSync(destDir);
89
+ files.forEach(file => {
90
+ const filePath = path.join(destDir, file);
91
+ const stats = fs.statSync(filePath);
92
+ if (stats.isFile() && !file.endsWith('.node')) {
93
+ // Make binary files executable
94
+ fs.chmodSync(filePath, 0o755);
95
+ }
96
+ });
97
+ }
98
+ resolve();
99
+ })
100
+ .on('error', reject);
101
+ });
102
+ }
103
+
104
+ /**
105
+ * Main unpacking function
106
+ */
107
+ async function unpackTools() {
108
+ try {
109
+ const platformDir = getPlatformDir();
110
+ const toolsDir = getToolsDir();
111
+ const archivesDir = path.join(toolsDir, 'archives');
112
+ const unpackedPath = path.join(toolsDir, 'unpacked');
113
+
114
+ // Check if already unpacked
115
+ if (areToolsUnpacked(toolsDir)) {
116
+ console.log(`Tools already unpacked for ${platformDir}`);
117
+ return { success: true, alreadyUnpacked: true };
118
+ }
119
+
120
+ console.log(`Unpacking tools for ${platformDir}...`);
121
+
122
+ // Create unpacked directory
123
+ if (!fs.existsSync(unpackedPath)) {
124
+ fs.mkdirSync(unpackedPath, { recursive: true });
125
+ }
126
+
127
+ // Unpack difftastic
128
+ const difftasticArchive = path.join(archivesDir, `difftastic-${platformDir}.tar.gz`);
129
+ if (!fs.existsSync(difftasticArchive)) {
130
+ throw new Error(`Archive not found: ${difftasticArchive}`);
131
+ }
132
+ await unpackArchive(difftasticArchive, unpackedPath);
133
+
134
+ // Unpack ripgrep
135
+ const ripgrepArchive = path.join(archivesDir, `ripgrep-${platformDir}.tar.gz`);
136
+ if (!fs.existsSync(ripgrepArchive)) {
137
+ throw new Error(`Archive not found: ${ripgrepArchive}`);
138
+ }
139
+ await unpackArchive(ripgrepArchive, unpackedPath);
140
+
141
+ console.log(`Tools unpacked successfully to ${unpackedPath}`);
142
+ return { success: true, alreadyUnpacked: false };
143
+
144
+ } catch (error) {
145
+ console.error('Failed to unpack tools:', error.message);
146
+ throw error;
147
+ }
148
+ }
149
+
150
+ // Export for use as module
151
+ module.exports = { unpackTools, getPlatformDir, getToolsDir };
152
+
153
+ // Run if executed directly
154
+ if (require.main === module) {
155
+ unpackTools()
156
+ .then(result => {
157
+ process.exit(0);
158
+ })
159
+ .catch(error => {
160
+ console.error('Error:', error);
161
+ process.exit(1);
162
+ });
163
+ }
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021-2025 Wilfred Hughes
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,3 @@
1
+ This project is dual-licensed under the Unlicense and MIT licenses.
2
+
3
+ You may use this code under the terms of either license.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021-2025 Wilfred Hughes
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,3 @@
1
+ This project is dual-licensed under the Unlicense and MIT licenses.
2
+
3
+ You may use this code under the terms of either license.
Binary file
Binary file
Binary file