@usewhale/whale 0.1.43
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.
- package/bin/whale.js +176 -0
- package/package.json +45 -0
package/bin/whale.js
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Unified entry point for the Whale CLI.
|
|
3
|
+
// Detects platform, resolves the platform-specific optional dependency,
|
|
4
|
+
// and spawns the native binary with signal forwarding.
|
|
5
|
+
|
|
6
|
+
import { spawn } from "node:child_process";
|
|
7
|
+
import { existsSync, realpathSync } from "node:fs";
|
|
8
|
+
import { createRequire } from "node:module";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
import { fileURLToPath } from "node:url";
|
|
11
|
+
|
|
12
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
13
|
+
const __dirname = path.dirname(__filename);
|
|
14
|
+
|
|
15
|
+
const require = createRequire(import.meta.url);
|
|
16
|
+
|
|
17
|
+
const PLATFORM_PACKAGE_BY_TARGET = {
|
|
18
|
+
"aarch64-apple-darwin": "@usewhale/whale-darwin-arm64",
|
|
19
|
+
"x86_64-apple-darwin": "@usewhale/whale-darwin-x64",
|
|
20
|
+
"x86_64-unknown-linux-musl": "@usewhale/whale-linux-x64",
|
|
21
|
+
"aarch64-unknown-linux-musl": "@usewhale/whale-linux-arm64",
|
|
22
|
+
"x86_64-pc-windows-msvc": "@usewhale/whale-win32-x64",
|
|
23
|
+
"aarch64-pc-windows-msvc": "@usewhale/whale-win32-arm64",
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
function detectTargetTriple() {
|
|
27
|
+
const { platform, arch } = process;
|
|
28
|
+
|
|
29
|
+
switch (platform) {
|
|
30
|
+
case "darwin":
|
|
31
|
+
switch (arch) {
|
|
32
|
+
case "x64":
|
|
33
|
+
return "x86_64-apple-darwin";
|
|
34
|
+
case "arm64":
|
|
35
|
+
return "aarch64-apple-darwin";
|
|
36
|
+
}
|
|
37
|
+
break;
|
|
38
|
+
case "linux":
|
|
39
|
+
switch (arch) {
|
|
40
|
+
case "x64":
|
|
41
|
+
return "x86_64-unknown-linux-musl";
|
|
42
|
+
case "arm64":
|
|
43
|
+
return "aarch64-unknown-linux-musl";
|
|
44
|
+
}
|
|
45
|
+
break;
|
|
46
|
+
case "win32":
|
|
47
|
+
switch (arch) {
|
|
48
|
+
case "x64":
|
|
49
|
+
return "x86_64-pc-windows-msvc";
|
|
50
|
+
case "arm64":
|
|
51
|
+
return "aarch64-pc-windows-msvc";
|
|
52
|
+
}
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
throw new Error(`Unsupported platform: ${platform} (${arch})`);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function resolvePlatformPackage() {
|
|
60
|
+
const targetTriple = detectTargetTriple();
|
|
61
|
+
const packageName = PLATFORM_PACKAGE_BY_TARGET[targetTriple];
|
|
62
|
+
|
|
63
|
+
if (!packageName) {
|
|
64
|
+
throw new Error(`No platform package for target triple: ${targetTriple}`);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Resolve the platform-specific package root
|
|
68
|
+
const packageJsonPath = require.resolve(`${packageName}/package.json`);
|
|
69
|
+
const packageRoot = path.dirname(packageJsonPath);
|
|
70
|
+
const binaryName = process.platform === "win32" ? "whale.exe" : "whale";
|
|
71
|
+
const binaryPath = path.join(packageRoot, "vendor", binaryName);
|
|
72
|
+
|
|
73
|
+
if (!existsSync(binaryPath)) {
|
|
74
|
+
const updateCmd = `npm install -g @usewhale/whale@latest`;
|
|
75
|
+
throw new Error(
|
|
76
|
+
`Missing native binary at ${binaryPath}. ` +
|
|
77
|
+
`Try reinstalling: ${updateCmd}`
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return { binaryPath, packageRoot };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function detectPackageManager() {
|
|
85
|
+
const userAgent = process.env.npm_config_user_agent || "";
|
|
86
|
+
if (/\bbun\//.test(userAgent)) return "bun";
|
|
87
|
+
|
|
88
|
+
const execPath = process.env.npm_execpath || "";
|
|
89
|
+
if (execPath.includes("bun")) return "bun";
|
|
90
|
+
|
|
91
|
+
if (
|
|
92
|
+
__dirname.includes(".bun/install/global") ||
|
|
93
|
+
__dirname.includes(".bun\\install\\global")
|
|
94
|
+
) {
|
|
95
|
+
return "bun";
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return userAgent ? "npm" : null;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function getUpdatedPath(newDirs) {
|
|
102
|
+
const pathSep = process.platform === "win32" ? ";" : ":";
|
|
103
|
+
const existingPath = process.env.PATH || "";
|
|
104
|
+
return [...newDirs, ...existingPath.split(pathSep).filter(Boolean)].join(
|
|
105
|
+
pathSep
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async function main() {
|
|
110
|
+
const { binaryPath, packageRoot } = resolvePlatformPackage();
|
|
111
|
+
const additionalDirs = [];
|
|
112
|
+
|
|
113
|
+
// Add path directory if present (for companion tools, etc.)
|
|
114
|
+
const pathDir = path.join(packageRoot, "vendor", "path");
|
|
115
|
+
if (existsSync(pathDir)) {
|
|
116
|
+
additionalDirs.push(pathDir);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const updatedPath = getUpdatedPath(additionalDirs);
|
|
120
|
+
const env = { ...process.env, PATH: updatedPath };
|
|
121
|
+
|
|
122
|
+
// Mark as managed by npm/bun
|
|
123
|
+
const pkgMgr = detectPackageManager();
|
|
124
|
+
const mgrEnvVar =
|
|
125
|
+
pkgMgr === "bun" ? "WHALE_MANAGED_BY_BUN" : "WHALE_MANAGED_BY_NPM";
|
|
126
|
+
env[mgrEnvVar] = "1";
|
|
127
|
+
env.WHALE_MANAGED_PACKAGE_ROOT = realpathSync(path.join(__dirname, ".."));
|
|
128
|
+
|
|
129
|
+
// Use asynchronous spawn so Node can respond to signals (Ctrl-C, etc.)
|
|
130
|
+
// and forward them to the child process.
|
|
131
|
+
const child = spawn(binaryPath, process.argv.slice(2), {
|
|
132
|
+
stdio: "inherit",
|
|
133
|
+
env,
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
child.on("error", (err) => {
|
|
137
|
+
console.error(err);
|
|
138
|
+
process.exit(1);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
// Forward termination signals to the child so it shuts down gracefully.
|
|
142
|
+
const forwardSignal = (signal) => {
|
|
143
|
+
if (child.killed) return;
|
|
144
|
+
try {
|
|
145
|
+
child.kill(signal);
|
|
146
|
+
} catch {
|
|
147
|
+
/* ignore */
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
["SIGINT", "SIGTERM", "SIGHUP"].forEach((sig) => {
|
|
152
|
+
process.on(sig, () => forwardSignal(sig));
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
// Wait for child to exit and mirror its exit status.
|
|
156
|
+
const childResult = await new Promise((resolve) => {
|
|
157
|
+
child.on("exit", (code, signal) => {
|
|
158
|
+
if (signal) {
|
|
159
|
+
resolve({ type: "signal", signal });
|
|
160
|
+
} else {
|
|
161
|
+
resolve({ type: "code", exitCode: code ?? 1 });
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
if (childResult.type === "signal") {
|
|
167
|
+
process.kill(process.pid, childResult.signal);
|
|
168
|
+
} else {
|
|
169
|
+
process.exit(childResult.exitCode);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
main().catch((err) => {
|
|
174
|
+
console.error("Failed to start whale:", err.message);
|
|
175
|
+
process.exit(1);
|
|
176
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@usewhale/whale",
|
|
3
|
+
"version": "0.1.43",
|
|
4
|
+
"description": "DeepSeek-native coding agent for the terminal — 1M-token context, thinking-mode, full tool-use.",
|
|
5
|
+
"author": "usewhale",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://github.com/usewhale/DeepSeek-Code-Whale",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/usewhale/DeepSeek-Code-Whale.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/usewhale/DeepSeek-Code-Whale/issues"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"deepseek",
|
|
17
|
+
"cli",
|
|
18
|
+
"tui",
|
|
19
|
+
"coding-agent",
|
|
20
|
+
"terminal",
|
|
21
|
+
"whale"
|
|
22
|
+
],
|
|
23
|
+
"type": "module",
|
|
24
|
+
"bin": {
|
|
25
|
+
"whale": "bin/whale.js"
|
|
26
|
+
},
|
|
27
|
+
"optionalDependencies": {
|
|
28
|
+
"@usewhale/whale-darwin-arm64": "0.x.x",
|
|
29
|
+
"@usewhale/whale-darwin-x64": "0.x.x",
|
|
30
|
+
"@usewhale/whale-linux-arm64": "0.x.x",
|
|
31
|
+
"@usewhale/whale-linux-x64": "0.x.x",
|
|
32
|
+
"@usewhale/whale-win32-x64": "0.x.x",
|
|
33
|
+
"@usewhale/whale-win32-arm64": "0.x.x"
|
|
34
|
+
},
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">=18"
|
|
37
|
+
},
|
|
38
|
+
"files": [
|
|
39
|
+
"bin/whale.js"
|
|
40
|
+
],
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
},
|
|
44
|
+
"preferGlobal": true
|
|
45
|
+
}
|