@haffa/decision-browser 0.1.2 → 0.2.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.
- package/README.md +20 -83
- package/bin/decision-browser.cjs +43 -205
- package/native/darwin-arm64/decision-browser +0 -0
- package/native/darwin-arm64/manifest.json +1 -0
- package/native/linux-x64/decision-browser +0 -0
- package/native/linux-x64/manifest.json +1 -0
- package/package.json +20 -7
- package/bin/uv-bootstrap.cjs +0 -146
- package/bin/uv-download.cjs +0 -344
- package/bin/uv-manifest.json +0 -12
- package/installer/decision-browser.pyz +0 -0
- package/installer/manifest.json +0 -5
package/README.md
CHANGED
|
@@ -1,96 +1,33 @@
|
|
|
1
|
-
# Decision Browser launcher
|
|
1
|
+
# Decision Browser native npm launcher
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
The public `@haffa/decision-browser` package contains the Rust executables for
|
|
4
|
+
macOS arm64 and Linux x64. The launcher selects the matching executable and
|
|
5
|
+
checks its SHA-256 before running it. Node.js 20 or newer is required.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
selected client CLI(s) on PATH. The launcher prepares uv automatically when a
|
|
9
|
-
suitable version is absent; Python 3.12 is managed by uv. It does not install
|
|
10
|
-
the coding clients. Downloads require
|
|
11
|
-
network access; Linux also needs Playwright's host libraries and a working
|
|
12
|
-
Chromium sandbox. No sudo or security-setting changes are performed.
|
|
13
|
-
|
|
14
|
-
Start guided setup from your project:
|
|
7
|
+
Install Chrome or Chromium separately, then run from your project.
|
|
15
8
|
|
|
16
9
|
```sh
|
|
17
|
-
|
|
10
|
+
npm exec --yes --package=@haffa/decision-browser@0.2.1 -- decision-browser setup codex
|
|
11
|
+
npm exec --yes --package=@haffa/decision-browser@0.2.1 -- decision-browser configure openai
|
|
18
12
|
```
|
|
19
13
|
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
Choose `claude` or `both` for the other client registrations. `setup` copies the
|
|
15
|
+
native executable into the project's persistent runtime and writes managed MCP
|
|
16
|
+
settings. Restart the coding client, review its trust and MCP prompts, and
|
|
17
|
+
supply credentials through the [provider guide](https://github.com/HaffASE/decision-browser/blob/v0.2.1/docs/providers.md).
|
|
22
18
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
The package has no lifecycle hooks or npm dependencies. Installation and launch
|
|
20
|
+
use the bundled executable and local files. Set `DECISION_BROWSER_CHROME` to the
|
|
21
|
+
browser executable when automatic discovery is insufficient.
|
|
26
22
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
plaintext outside projects with private permissions. On Windows use environment
|
|
30
|
-
settings for credentials. Provider selection does not call the API. Cancelled
|
|
31
|
-
key entry retains the installation and prints an exact resume command.
|
|
23
|
+
For direct native installation, use the [v0.2.1 release archives](https://github.com/HaffASE/decision-browser/releases/tag/v0.2.1).
|
|
24
|
+
Source builds and release packaging use the [release procedure](https://github.com/HaffASE/decision-browser/blob/v0.2.1/docs/releasing.md).
|
|
32
25
|
|
|
33
|
-
|
|
26
|
+
Maintainers can test a reviewed local tarball in a fresh directory.
|
|
34
27
|
|
|
35
28
|
```sh
|
|
36
|
-
|
|
37
|
-
npx --yes @haffa/decision-browser@0.1.2 install claude
|
|
38
|
-
npx --yes @haffa/decision-browser@0.1.2 install both
|
|
29
|
+
npm exec --offline --yes --package=/absolute/path/haffa-decision-browser-0.2.1.tgz -- decision-browser --version
|
|
39
30
|
```
|
|
40
31
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
still need their official services. To select another project, append
|
|
44
|
-
`--project "/path/with spaces"`. Repeat the command to check an installation;
|
|
45
|
-
append `--upgrade` for a reviewed new candidate, including all installed clients.
|
|
46
|
-
Append `--uninstall` to remove unchanged managed registrations and skills.
|
|
47
|
-
Runtime/cache files are retained for manual cleanup.
|
|
48
|
-
The npm removal command also prepares uv and managed Python when needed. The
|
|
49
|
-
direct Python `.pyz --uninstall` route can remove
|
|
50
|
-
registrations without uv when a suitable Python is already available.
|
|
51
|
-
|
|
52
|
-
Change your provider or inspect the current project using the same package:
|
|
53
|
-
|
|
54
|
-
```sh
|
|
55
|
-
npx --yes @haffa/decision-browser@0.1.2 configure
|
|
56
|
-
npx --yes @haffa/decision-browser@0.1.2 doctor --json
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
`configure [provider]` needs an interactive terminal. `doctor --project /path`
|
|
60
|
-
checks another project. Both use a private cached Python package runtime without
|
|
61
|
-
installing Chromium or changing client registrations. The first call can download
|
|
62
|
-
Python and locked dependencies; later calls verify and reuse that runtime.
|
|
63
|
-
Preparation messages go to stderr, so `doctor --json` keeps stdout as JSON.
|
|
64
|
-
Doctor checks local configuration; it does not test provider access or client trust.
|
|
65
|
-
|
|
66
|
-
Use `configure gemini` for Gemini Decision 1 through OpenCode Console. This
|
|
67
|
-
preset uses an OpenCode Console API key and selects `gemini-decision-1`.
|
|
68
|
-
|
|
69
|
-
The uv bootstrap downloads version 0.13.7 from Astral's official releases and
|
|
70
|
-
checks its pinned SHA-256 before extracting or executing it. A uv 0.13.7+ already
|
|
71
|
-
on PATH is reused. Downloads support `HTTPS_PROXY` / `ALL_PROXY`, `NO_PROXY`,
|
|
72
|
-
`SSL_CERT_FILE` and `NODE_EXTRA_CA_CERTS`; TLS verification remains enabled.
|
|
73
|
-
No shell profile or global PATH changes are made. Tool and command-runtime caches
|
|
74
|
-
default to `~/Library/Caches/decision-browser` on macOS,
|
|
75
|
-
`${XDG_CACHE_HOME:-~/.cache}/decision-browser` on Linux, and
|
|
76
|
-
`%LOCALAPPDATA%/decision-browser` on Windows. An absolute
|
|
77
|
-
`DECISION_BROWSER_CACHE_DIR` overrides this location. uv manages its Python cache
|
|
78
|
-
separately. A modified tool/runtime cache is rejected rather than executed.
|
|
79
|
-
|
|
80
|
-
The package contains a checked `.pyz` installer and SHA-256 manifest. It never
|
|
81
|
-
looks up a Python package by name on PyPI, and has no npm runtime dependencies or
|
|
82
|
-
lifecycle hooks. Runtime Python dependencies come from the embedded lockfile.
|
|
83
|
-
MCP settings point to a persistent project runtime, never to the npm/uv cache.
|
|
84
|
-
The hash detects a broken package; it is not publisher authentication.
|
|
85
|
-
|
|
86
|
-
Unattended installation does not require a model key. Inherited model credentials
|
|
87
|
-
and Python/uv environment overrides are not passed to bootstrap children. Only
|
|
88
|
-
the prepared configure/doctor process receives supported provider overrides. Guided
|
|
89
|
-
setup asks for credentials only after installation; the MCP server then reads
|
|
90
|
-
the saved profile automatically. Advanced environment configuration remains
|
|
91
|
-
available. Restart your client in the project and review its trust/MCP/admission
|
|
92
|
-
prompts. Those approvals are unchanged.
|
|
93
|
-
|
|
94
|
-
The launcher uses portable Node/uv APIs for macOS, Linux and Windows, but each
|
|
95
|
-
platform still needs native installation verification before a release claims
|
|
96
|
-
support. See the repository's [installation guide](https://github.com/HaffASE/decision-browser/blob/main/docs/installation.md).
|
|
32
|
+
The checked-in package template stays private. The release builder creates the
|
|
33
|
+
public package after verifying both platform candidates.
|
package/bin/decision-browser.cjs
CHANGED
|
@@ -1,220 +1,58 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
// No npm dependencies, install scripts, shell interpolation, or unpinned PyPI lookup.
|
|
5
|
-
const { spawnSync } = require('node:child_process');
|
|
6
4
|
const { createHash } = require('node:crypto');
|
|
7
|
-
const
|
|
5
|
+
const fs = require('node:fs');
|
|
8
6
|
const path = require('node:path');
|
|
9
|
-
const
|
|
10
|
-
const { BootstrapError, ensureUv, supportedUv, cacheDirectory, privateDirectory } = require('./uv-bootstrap.cjs');
|
|
11
|
-
|
|
12
|
-
class SetupError extends Error {}
|
|
13
|
-
|
|
14
|
-
const PROVIDER_ENV_NAMES = ['OPENAI_API_KEY', 'TYPESAFE_API_KEY', 'OPENROUTER_API_KEY', 'OPENCODE_API_KEY',
|
|
15
|
-
'DECISION_BROWSER_PROVIDER', 'DECISION_BROWSER_API_KEY', 'DECISION_BROWSER_ENDPOINT',
|
|
16
|
-
'DECISION_BROWSER_MODEL', 'DECISION_BROWSER_MAX_CHOICES', 'DECISION_BROWSER_TEXT_ENDPOINT',
|
|
17
|
-
'DECISION_BROWSER_TEXT_MODEL', 'DECISION_BROWSER_TEXT_API_KEY'];
|
|
18
|
-
|
|
19
|
-
const HELP = `Decision Browser ${pkg.version}
|
|
20
|
-
Usage: decision-browser setup [codex|claude|both] [options]
|
|
21
|
-
decision-browser install <codex|claude|both> [options]
|
|
22
|
-
decision-browser configure [provider] [--project <directory>]
|
|
23
|
-
decision-browser doctor [--json] [--project <directory>]
|
|
24
|
-
|
|
25
|
-
setup chooses your client and provider interactively; install is unattended.
|
|
26
|
-
|
|
27
|
-
--project <directory> Existing project (default: current directory)
|
|
28
|
-
--upgrade Replace a reviewed installation; include all its clients
|
|
29
|
-
--uninstall Remove unchanged managed registrations and skills (install only)
|
|
30
|
-
--help Show this help without downloads or changes
|
|
31
|
-
--version Print the launcher version
|
|
32
|
-
|
|
33
|
-
Requires Node.js 20+ and the selected client CLI(s) for setup/install.
|
|
34
|
-
uv and Python 3.12 are prepared automatically when needed, without shell changes.
|
|
35
|
-
configure and doctor use a cached package runtime; they do not reinstall Chromium.
|
|
36
|
-
Setup downloads Python if needed, locked dependencies, and Chromium. It does not
|
|
37
|
-
install client CLIs, invoke sudo, change project trust, or call a model API.
|
|
38
|
-
`;
|
|
39
|
-
|
|
40
|
-
function cleanEnvironment(env, platform = process.platform) {
|
|
41
|
-
const allowed = new Set(['PATH', 'HOME', 'USERPROFILE', 'SYSTEMROOT', 'WINDIR',
|
|
42
|
-
'TMPDIR', 'TMP', 'TEMP', 'LANG', 'LC_ALL', 'SSL_CERT_FILE', 'SSL_CERT_DIR', 'HTTPS_PROXY', 'HTTP_PROXY', 'ALL_PROXY', 'NO_PROXY',
|
|
43
|
-
'DECISION_BROWSER_INSTALL_INDEX_URL', 'DECISION_BROWSER_CONFIG_FILE', 'NODE_EXTRA_CA_CERTS',
|
|
44
|
-
'DECISION_BROWSER_CACHE_DIR', 'XDG_CACHE_HOME', 'LOCALAPPDATA']);
|
|
45
|
-
const result = {};
|
|
46
|
-
for (const [key, value] of Object.entries(env)) {
|
|
47
|
-
if (!allowed.has(key.toUpperCase())) continue;
|
|
48
|
-
const name = platform === 'win32' ? key.toUpperCase() : key;
|
|
49
|
-
if (Object.hasOwn(result, name) && result[name] !== value) {
|
|
50
|
-
throw new SetupError('Conflicting Windows environment spellings; keep one value for each setting.');
|
|
51
|
-
}
|
|
52
|
-
result[name] = value;
|
|
53
|
-
}
|
|
54
|
-
return result;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function runtimeEnvironment(env) {
|
|
58
|
-
const result = cleanEnvironment(env);
|
|
59
|
-
for (const name of PROVIDER_ENV_NAMES) {
|
|
60
|
-
if (Object.hasOwn(env, name)) result[name] = env[name];
|
|
61
|
-
}
|
|
62
|
-
return result;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function parseArgs(argv, cwd) {
|
|
66
|
-
if (argv.length === 0 || (argv.length === 1 && ['--help', '-h'].includes(argv[0]))) return { help: true };
|
|
67
|
-
if (argv.length === 1 && argv[0] === '--version') return { version: true };
|
|
68
|
-
if (['configure', 'doctor'].includes(argv[0])) {
|
|
69
|
-
const command = argv[0];
|
|
70
|
-
let project = cwd, provider, json = false;
|
|
71
|
-
let start = 1;
|
|
72
|
-
if (command === 'configure' && argv[1] && !argv[1].startsWith('-')) {
|
|
73
|
-
provider = argv[1]; start = 2;
|
|
74
|
-
if (!['openai', 'typesafe', 'openrouter', 'opencode', 'gemini', 'local', 'jev', 'nimble'].includes(provider)) {
|
|
75
|
-
throw new SetupError('Unknown provider. Run configure without a provider to choose from the menu.');
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
const flags = new Set();
|
|
79
|
-
for (let i = start; i < argv.length; i++) {
|
|
80
|
-
const option = argv[i];
|
|
81
|
-
if (['--help', '-h'].includes(option)) return { help: true };
|
|
82
|
-
if (flags.has(option)) throw new SetupError('Duplicate option. See --help.');
|
|
83
|
-
flags.add(option);
|
|
84
|
-
if (option === '--project') {
|
|
85
|
-
const value = argv[++i];
|
|
86
|
-
if (!value || value.startsWith('--')) throw new SetupError('--project needs a directory.');
|
|
87
|
-
project = path.resolve(cwd, value);
|
|
88
|
-
} else if (option === '--json' && command === 'doctor') json = true;
|
|
89
|
-
else throw new SetupError('Unknown option. See --help.');
|
|
90
|
-
}
|
|
91
|
-
return { command, project, provider, json };
|
|
92
|
-
}
|
|
93
|
-
const setup = argv[0] === 'setup';
|
|
94
|
-
if (!setup && argv[0] !== 'install') {
|
|
95
|
-
throw new SetupError('Use setup, install, configure, or doctor. See --help.');
|
|
96
|
-
}
|
|
97
|
-
const client = ['codex', 'claude', 'both'].includes(argv[1]) ? argv[1] : undefined;
|
|
98
|
-
if (!setup && !client) throw new SetupError('Choose install codex, install claude, or install both. See --help.');
|
|
99
|
-
let project = cwd;
|
|
100
|
-
const flags = new Set();
|
|
101
|
-
for (let i = client ? 2 : 1; i < argv.length; i++) {
|
|
102
|
-
const option = argv[i];
|
|
103
|
-
if (option === '--help' || option === '-h') return { help: true };
|
|
104
|
-
if (flags.has(option)) throw new SetupError('Duplicate option. See --help.');
|
|
105
|
-
flags.add(option);
|
|
106
|
-
if (option === '--project') {
|
|
107
|
-
const value = argv[++i];
|
|
108
|
-
if (!value || value.startsWith('--')) throw new SetupError('--project needs a directory.');
|
|
109
|
-
project = path.resolve(cwd, value);
|
|
110
|
-
} else if (!['--upgrade', '--uninstall'].includes(option)) {
|
|
111
|
-
throw new SetupError('Unknown option. See --help.');
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
if (flags.has('--upgrade') && flags.has('--uninstall')) throw new SetupError('Choose --upgrade or --uninstall, not both.');
|
|
115
|
-
if (setup && flags.has('--uninstall')) throw new SetupError('setup cannot be combined with --uninstall.');
|
|
116
|
-
return { client, project, setup, upgrade: flags.has('--upgrade'), uninstall: flags.has('--uninstall') };
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
function archivePath(root) {
|
|
120
|
-
const file = path.join(root, 'installer', 'decision-browser.pyz');
|
|
121
|
-
const manifestFile = path.join(root, 'installer', 'manifest.json');
|
|
122
|
-
for (const name of [file, manifestFile]) {
|
|
123
|
-
const stat = lstatSync(name);
|
|
124
|
-
if (!stat.isFile() || stat.isSymbolicLink()) throw new SetupError('Installer files must be regular files.');
|
|
125
|
-
}
|
|
126
|
-
const manifest = JSON.parse(readFileSync(manifestFile, 'utf8'));
|
|
127
|
-
const digest = createHash('sha256').update(readFileSync(file)).digest('hex');
|
|
128
|
-
if (!manifest || manifest.version !== pkg.version ||
|
|
129
|
-
manifest.sha256 !== digest || manifest.file !== 'decision-browser.pyz') {
|
|
130
|
-
throw new SetupError('Installer integrity check failed; obtain the reviewed package again.');
|
|
131
|
-
}
|
|
132
|
-
return file;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
function uvArgs(archive, options) {
|
|
136
|
-
const args = ['--no-config', 'run', '--no-project', '--managed-python', '--python', '3.12',
|
|
137
|
-
'--', 'python', '-I', archive];
|
|
138
|
-
if (options.client) args.push('--client', options.client);
|
|
139
|
-
args.push('--project', options.project);
|
|
140
|
-
if (options.setup) args.push('--setup');
|
|
141
|
-
if (options.upgrade) args.push('--upgrade');
|
|
142
|
-
if (options.uninstall) args.push('--uninstall');
|
|
143
|
-
return args;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
function prepareRuntime(uv, archive, cache, run, cwd) {
|
|
147
|
-
privateDirectory(cache);
|
|
148
|
-
const args = ['--no-config', 'run', '--no-project', '--managed-python', '--python', '3.12',
|
|
149
|
-
'--', 'python', '-I', archive, '--prepare-runtime', '--cache', cache];
|
|
150
|
-
const result = run(uv.command, args, { env: uv.env, cwd, encoding: 'utf8',
|
|
151
|
-
stdio: ['ignore', 'pipe', 'inherit'], shell: false, timeout: 900000, maxBuffer: 65536 });
|
|
152
|
-
if (result.error || result.signal || result.status !== 0) {
|
|
153
|
-
throw new SetupError('Command runtime preparation failed. Check the diagnostic above and retry; project settings were not changed.');
|
|
154
|
-
}
|
|
155
|
-
let response;
|
|
156
|
-
try { response = JSON.parse(result.stdout); } catch { /* fixed diagnostic below */ }
|
|
157
|
-
const python = response?.python;
|
|
158
|
-
const relative = typeof python === 'string' && path.isAbsolute(python)
|
|
159
|
-
? path.relative(path.join(cache, 'runtimes'), python) : '..';
|
|
160
|
-
const suffix = process.platform === 'win32' ? path.join('venv', 'Scripts', 'python.exe') : path.join('venv', 'bin', 'python');
|
|
161
|
-
if (!relative || relative.startsWith('..') || path.isAbsolute(relative)
|
|
162
|
-
|| !relative.endsWith(path.sep + suffix) || !require('node:fs').statSync(python).isFile()) {
|
|
163
|
-
throw new SetupError('Invalid prepared runtime; no project-supplied executable was started.');
|
|
164
|
-
}
|
|
165
|
-
return python;
|
|
166
|
-
}
|
|
7
|
+
const { spawnSync } = require('node:child_process');
|
|
167
8
|
|
|
168
|
-
|
|
169
|
-
const run = deps.run || spawnSync;
|
|
170
|
-
const out = deps.out || process.stdout;
|
|
171
|
-
const err = deps.err || process.stderr;
|
|
172
|
-
const root = deps.root || path.resolve(__dirname, '..');
|
|
173
|
-
const cwd = deps.cwd || process.cwd();
|
|
9
|
+
function run(args, root = path.resolve(__dirname, '..')) {
|
|
174
10
|
try {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
const uv = await (deps.ensureUv || ensureUv)({ run, env: cleanEnvironment(sourceEnv), cwd, err });
|
|
187
|
-
let command = uv.command, args = uvArgs(archive, options), env = uv.env;
|
|
188
|
-
if (options.command) {
|
|
189
|
-
command = (deps.prepareRuntime || prepareRuntime)(uv, archive, cacheDirectory(uv.env), run, cwd);
|
|
190
|
-
args = ['-I', '-B', '-m', 'decision_browser.cli', options.command];
|
|
191
|
-
if (options.command === 'doctor') args.push('--json', '--project', options.project);
|
|
192
|
-
else if (options.provider) args.push(options.provider);
|
|
193
|
-
env = runtimeEnvironment({ ...sourceEnv, ...uv.env });
|
|
194
|
-
} else {
|
|
195
|
-
out.write('Preparing Decision Browser with uv-managed Python 3.12. Downloads may be needed.\n');
|
|
11
|
+
let nativeRoot = path.join(root, 'native');
|
|
12
|
+
if (!fs.lstatSync(path.join(nativeRoot, 'manifest.json'), { throwIfNoEntry: false })) {
|
|
13
|
+
const target = `${process.platform}-${process.arch}`;
|
|
14
|
+
if (target !== 'darwin-arm64' && target !== 'linux-x64') {
|
|
15
|
+
throw new Error(`unsupported platform: ${target}`);
|
|
16
|
+
}
|
|
17
|
+
nativeRoot = path.join(nativeRoot, target);
|
|
18
|
+
const nativeStat = fs.lstatSync(nativeRoot, { throwIfNoEntry: false });
|
|
19
|
+
if (!nativeStat || !nativeStat.isDirectory() || nativeStat.isSymbolicLink()) {
|
|
20
|
+
throw new Error(`bundled executable is missing or invalid for ${target}`);
|
|
21
|
+
}
|
|
196
22
|
}
|
|
197
|
-
const
|
|
198
|
-
|
|
199
|
-
|
|
23
|
+
const manifestPath = path.join(nativeRoot, 'manifest.json');
|
|
24
|
+
const manifestStat = fs.lstatSync(manifestPath);
|
|
25
|
+
if (!manifestStat.isFile() || manifestStat.isSymbolicLink() || manifestStat.size > 4096) {
|
|
26
|
+
throw new Error('invalid bundled manifest');
|
|
27
|
+
}
|
|
28
|
+
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
|
|
29
|
+
const expectedFile = process.platform === 'win32' ? 'decision-browser.exe' : 'decision-browser';
|
|
30
|
+
if (manifest.format !== 1 || manifest.platform !== process.platform ||
|
|
31
|
+
manifest.arch !== process.arch || manifest.file !== expectedFile ||
|
|
32
|
+
typeof manifest.sha256 !== 'string' || !/^[a-f0-9]{64}$/.test(manifest.sha256)) {
|
|
33
|
+
throw new Error('bundle does not match this platform or manifest format');
|
|
34
|
+
}
|
|
35
|
+
const executable = path.join(nativeRoot, manifest.file);
|
|
36
|
+
const executableStat = fs.lstatSync(executable);
|
|
37
|
+
if (!executableStat.isFile() || executableStat.isSymbolicLink()) {
|
|
38
|
+
throw new Error('bundled executable is missing or invalid');
|
|
39
|
+
}
|
|
40
|
+
const digest = createHash('sha256').update(fs.readFileSync(executable)).digest('hex');
|
|
41
|
+
if (digest !== manifest.sha256) {
|
|
42
|
+
throw new Error('bundled executable integrity check failed');
|
|
43
|
+
}
|
|
44
|
+
const result = spawnSync(executable, args, { stdio: 'inherit', env: process.env, shell: false });
|
|
45
|
+
if (result.error) throw new Error('could not start bundled executable');
|
|
46
|
+
if (result.signal) {
|
|
47
|
+
process.kill(process.pid, result.signal);
|
|
200
48
|
return 1;
|
|
201
49
|
}
|
|
202
|
-
|
|
203
|
-
const overrides = PROVIDER_ENV_NAMES.filter(name => Object.hasOwn(sourceEnv, name));
|
|
204
|
-
if (overrides.length) {
|
|
205
|
-
err.write('Provider environment settings may still take precedence over the saved profile: '
|
|
206
|
-
+ overrides.join(', ') + '. Remove relevant overrides from the coding client environment '
|
|
207
|
-
+ 'to use the saved selection, then restart the client.\n');
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
return result.status;
|
|
50
|
+
return Number.isInteger(result.status) ? result.status : 1;
|
|
211
51
|
} catch (error) {
|
|
212
|
-
|
|
213
|
-
const message = error instanceof SetupError || error instanceof BootstrapError ? error.message : 'Missing, invalid or unreadable project/package/cache files.';
|
|
214
|
-
err.write(`Setup stopped: ${message || 'Invalid package or arguments.'}\n`);
|
|
52
|
+
process.stderr.write(`Decision Browser native launcher: ${error.message}\n`);
|
|
215
53
|
return 1;
|
|
216
54
|
}
|
|
217
55
|
}
|
|
218
56
|
|
|
219
|
-
module.exports = {
|
|
220
|
-
if (require.main === module)
|
|
57
|
+
module.exports = { run };
|
|
58
|
+
if (require.main === module) process.exitCode = run(process.argv.slice(2));
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"format":1,"version":"0.2.1","target":"aarch64-apple-darwin","platform":"darwin","arch":"arm64","file":"decision-browser","sha256":"0cf15a18dbe6585a2f430b290475e389a09a399510adae8ef345e264ee7bbf00"}
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"format":1,"version":"0.2.1","target":"x86_64-unknown-linux-gnu","platform":"linux","arch":"x64","file":"decision-browser","sha256":"50a4bc0c00eacddd16a367ee3c61b6ba2f8334aab2c38ce5f013d91def1c81e6"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@haffa/decision-browser",
|
|
3
|
-
"version": "0.1
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "Native Rust MCP server for browser tasks with Codex and Claude Code",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/HaffASE/decision-browser.git",
|
|
9
|
+
"directory": "npm"
|
|
10
|
+
},
|
|
11
|
+
"engines": {
|
|
12
|
+
"node": ">=20"
|
|
13
|
+
},
|
|
14
|
+
"bin": {
|
|
15
|
+
"decision-browser": "bin/decision-browser.cjs"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"bin/",
|
|
19
|
+
"native/",
|
|
20
|
+
"README.md",
|
|
21
|
+
"LICENSE",
|
|
22
|
+
"THIRD_PARTY_NOTICES.md"
|
|
23
|
+
]
|
|
11
24
|
}
|
package/bin/uv-bootstrap.cjs
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const fs = require('node:fs');
|
|
4
|
-
const os = require('node:os');
|
|
5
|
-
const path = require('node:path');
|
|
6
|
-
const { createHash } = require('node:crypto');
|
|
7
|
-
const manifest = require('./uv-manifest.json');
|
|
8
|
-
|
|
9
|
-
class BootstrapError extends Error {}
|
|
10
|
-
|
|
11
|
-
function versionOf(result) {
|
|
12
|
-
if (result.error || result.status !== 0) return null;
|
|
13
|
-
const match = /^uv (\d+)\.(\d+)\.(\d+)(?:[^\r\n]*)\r?\n?$/.exec(result.stdout || '');
|
|
14
|
-
return match ? match.slice(1).map(Number) : null;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function supportedUv(result) {
|
|
18
|
-
const version = versionOf(result);
|
|
19
|
-
if (!version) return false;
|
|
20
|
-
const [major, minor, patch] = version;
|
|
21
|
-
return major > 0 || minor > 13 || (minor === 13 && patch >= 7);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function envValue(env, name) {
|
|
25
|
-
const key = Object.keys(env).find(key => key.toUpperCase() === name);
|
|
26
|
-
return key === undefined ? undefined : env[key];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function cacheDirectory(env, platform = process.platform) {
|
|
30
|
-
const override = envValue(env, 'DECISION_BROWSER_CACHE_DIR');
|
|
31
|
-
const home = envValue(env, platform === 'win32' ? 'USERPROFILE' : 'HOME') || os.homedir();
|
|
32
|
-
const base = platform === 'win32' ? (envValue(env, 'LOCALAPPDATA') || path.join(home, 'AppData', 'Local'))
|
|
33
|
-
: platform === 'darwin' ? path.join(home, 'Library', 'Caches')
|
|
34
|
-
: (envValue(env, 'XDG_CACHE_HOME') || path.join(home, '.cache'));
|
|
35
|
-
const directory = override === undefined ? path.join(base, 'decision-browser') : override;
|
|
36
|
-
if (!directory || !path.isAbsolute(directory) || /[\x00-\x1f\x7f]/.test(directory)
|
|
37
|
-
|| directory.split(/[\\/]/).includes('..')) {
|
|
38
|
-
throw new BootstrapError('Invalid cache location; use an absolute DECISION_BROWSER_CACHE_DIR.');
|
|
39
|
-
}
|
|
40
|
-
return path.resolve(directory);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function privatePath(file, directory = false) {
|
|
44
|
-
const info = fs.lstatSync(file);
|
|
45
|
-
if (info.isSymbolicLink() || (directory ? !info.isDirectory() : !info.isFile())
|
|
46
|
-
|| (!directory && info.nlink !== 1)
|
|
47
|
-
|| (process.platform !== 'win32' && ((info.mode & 0o077) || info.uid !== process.getuid()))) {
|
|
48
|
-
throw new BootstrapError('Tool cache must contain private, user-owned regular files and directories.');
|
|
49
|
-
}
|
|
50
|
-
return info;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function privateDirectory(directory) {
|
|
54
|
-
for (let current = directory; ; current = path.dirname(current)) {
|
|
55
|
-
try {
|
|
56
|
-
if (fs.lstatSync(current).isSymbolicLink()) throw new BootstrapError('Symlinked tool cache paths are not supported.');
|
|
57
|
-
} catch (error) { if (error.code !== 'ENOENT') throw error; }
|
|
58
|
-
if (current === path.dirname(current)) break;
|
|
59
|
-
}
|
|
60
|
-
fs.mkdirSync(directory, { recursive: true, mode: 0o700 });
|
|
61
|
-
privatePath(directory, true);
|
|
62
|
-
return directory;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function digest(data) { return createHash('sha256').update(data).digest('hex'); }
|
|
66
|
-
|
|
67
|
-
function readCached(directory, target, version) {
|
|
68
|
-
if (!fs.existsSync(directory)) return null;
|
|
69
|
-
privatePath(directory, true);
|
|
70
|
-
const receiptFile = path.join(directory, 'receipt.json');
|
|
71
|
-
const executable = path.join(directory, target.format === 'zip' ? 'uv.exe' : 'uv');
|
|
72
|
-
try {
|
|
73
|
-
if (privatePath(receiptFile).size > 4096 || privatePath(executable).size > 128 * 1024 * 1024) {
|
|
74
|
-
throw new Error('size');
|
|
75
|
-
}
|
|
76
|
-
const receipt = JSON.parse(fs.readFileSync(receiptFile, 'utf8'));
|
|
77
|
-
if (receipt.version !== version || receipt.archive !== target.sha256
|
|
78
|
-
|| receipt.binary !== digest(fs.readFileSync(executable))) throw new Error('integrity');
|
|
79
|
-
} catch (error) {
|
|
80
|
-
if (error instanceof BootstrapError) throw error;
|
|
81
|
-
throw new BootstrapError('Cached uv failed its integrity check. Remove this version from the Decision Browser tool cache and retry.');
|
|
82
|
-
}
|
|
83
|
-
return executable;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function withUvPath(env, executable) {
|
|
87
|
-
const result = { ...env };
|
|
88
|
-
const key = Object.keys(result).find(name => name.toUpperCase() === 'PATH') || 'PATH';
|
|
89
|
-
result[key] = path.dirname(executable) + path.delimiter + (result[key] || '');
|
|
90
|
-
return result;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
async function ensureUv({ run, env, cwd, err, platform = process.platform, arch = process.arch,
|
|
94
|
-
release = manifest, fetchArchive, extract } = {}) {
|
|
95
|
-
const options = { env, cwd, encoding: 'utf8', timeout: 15000, shell: false };
|
|
96
|
-
if (supportedUv(run('uv', ['--version'], options))) return { command: 'uv', env };
|
|
97
|
-
const target = release.targets[`${platform}-${arch}`];
|
|
98
|
-
if (!target) throw new BootstrapError('Automatic uv installation is unavailable for this platform/architecture.');
|
|
99
|
-
const cache = privateDirectory(cacheDirectory(env, platform));
|
|
100
|
-
const parent = privateDirectory(path.join(cache, 'tools', 'uv'));
|
|
101
|
-
const directory = path.join(parent, `${release.version}-${platform}-${arch}`);
|
|
102
|
-
const cached = readCached(directory, target, release.version);
|
|
103
|
-
if (cached) {
|
|
104
|
-
const result = run(cached, ['--version'], options);
|
|
105
|
-
if (versionOf(result)?.join('.') !== release.version) throw new BootstrapError('Cached uv cannot run on this system.');
|
|
106
|
-
return { command: cached, env: withUvPath(env, cached) };
|
|
107
|
-
}
|
|
108
|
-
err.write(`Preparing uv ${release.version} for ${platform}/${arch}. Downloading from Astral.\n`);
|
|
109
|
-
const stage = fs.mkdtempSync(path.join(parent, '.prepare-'));
|
|
110
|
-
try {
|
|
111
|
-
const downloader = require('./uv-download.cjs');
|
|
112
|
-
const data = await (fetchArchive || downloader.download)(release.baseUrl + target.file, { env });
|
|
113
|
-
if (digest(data) !== target.sha256) throw new BootstrapError('uv download checksum mismatch; no downloaded program was executed. Retry or check your network.');
|
|
114
|
-
const binary = (extract || downloader.extractUv)(data, target);
|
|
115
|
-
const executable = path.join(stage, target.format === 'zip' ? 'uv.exe' : 'uv');
|
|
116
|
-
fs.writeFileSync(executable, binary, { flag: 'wx', mode: 0o700 });
|
|
117
|
-
// Check the exact pinned version only after archive integrity verification.
|
|
118
|
-
if (versionOf(run(executable, ['--version'], options))?.join('.') !== release.version) {
|
|
119
|
-
throw new BootstrapError('Downloaded uv cannot run on this system; check platform compatibility.');
|
|
120
|
-
}
|
|
121
|
-
fs.writeFileSync(path.join(stage, 'receipt.json'), JSON.stringify({
|
|
122
|
-
version: release.version, archive: target.sha256, binary: digest(binary),
|
|
123
|
-
}) + '\n', { flag: 'wx', mode: 0o600 });
|
|
124
|
-
try { fs.renameSync(stage, directory); }
|
|
125
|
-
catch (error) {
|
|
126
|
-
if (!['EEXIST', 'ENOTEMPTY'].includes(error.code)) throw error;
|
|
127
|
-
// A concurrent successful installer may have committed the same version.
|
|
128
|
-
if (!readCached(directory, target, release.version)) throw error;
|
|
129
|
-
}
|
|
130
|
-
const ready = readCached(directory, target, release.version);
|
|
131
|
-
return { command: ready, env: withUvPath(env, ready) };
|
|
132
|
-
} catch (error) {
|
|
133
|
-
if (error instanceof BootstrapError) throw error;
|
|
134
|
-
const code = error.code;
|
|
135
|
-
const hints = {
|
|
136
|
-
download_timeout: 'uv download timed out. Retry or check your proxy.',
|
|
137
|
-
download_tls_failed: 'uv TLS verification failed. Configure NODE_EXTRA_CA_CERTS or SSL_CERT_FILE for your network.',
|
|
138
|
-
download_dns_failed: 'uv download hostname could not be resolved. Check your network or HTTPS_PROXY.',
|
|
139
|
-
};
|
|
140
|
-
throw new BootstrapError(hints[code] || 'Could not prepare uv. Check network/proxy/CA settings and cache permissions, then retry.');
|
|
141
|
-
} finally {
|
|
142
|
-
fs.rmSync(stage, { recursive: true, force: true });
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
module.exports = { BootstrapError, ensureUv, supportedUv, cacheDirectory, privateDirectory, withUvPath };
|
package/bin/uv-download.cjs
DELETED
|
@@ -1,344 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// Download only explicitly selected HTTPS assets. Never execute archive contents.
|
|
4
|
-
const http = require('node:http');
|
|
5
|
-
const https = require('node:https');
|
|
6
|
-
const tls = require('node:tls');
|
|
7
|
-
const net = require('node:net');
|
|
8
|
-
const fs = require('node:fs');
|
|
9
|
-
const zlib = require('node:zlib');
|
|
10
|
-
|
|
11
|
-
class DownloadError extends Error {
|
|
12
|
-
constructor(code) { super(code); this.name = 'DownloadError'; this.code = code; }
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function failure(error) {
|
|
16
|
-
if (error instanceof DownloadError) return error;
|
|
17
|
-
const code = error && error.code || '';
|
|
18
|
-
if (['ENOTFOUND', 'EAI_AGAIN'].includes(code)) return new DownloadError('download_dns_failed');
|
|
19
|
-
if (/CERT|TLS|SSL|SELF_SIGNED|UNABLE_TO_VERIFY/.test(code)) return new DownloadError('download_tls_failed');
|
|
20
|
-
return new DownloadError('download_failed');
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function destination(raw, base) {
|
|
24
|
-
try {
|
|
25
|
-
if (typeof raw !== 'string' || /[\s\x00-\x1f\x7f]/.test(raw)) throw new Error();
|
|
26
|
-
const url = new URL(raw, base);
|
|
27
|
-
if (url.protocol !== 'https:' || url.username || url.password) throw new Error();
|
|
28
|
-
return url;
|
|
29
|
-
} catch { throw new DownloadError('download_invalid_url'); }
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function bypassProxy(url, value) {
|
|
33
|
-
const host = url.hostname.replace(/^\[|\]$/g, '').toLowerCase();
|
|
34
|
-
return value.split(',').some((part) => {
|
|
35
|
-
let entry = part.trim().toLowerCase();
|
|
36
|
-
if (!entry) return false;
|
|
37
|
-
if (entry === '*') return true;
|
|
38
|
-
let port;
|
|
39
|
-
if (entry.startsWith('[')) {
|
|
40
|
-
const match = /^\[([^\]]+)\](?::(\d+))?$/.exec(entry);
|
|
41
|
-
if (!match) return false;
|
|
42
|
-
[, entry, port] = match;
|
|
43
|
-
} else if ((entry.match(/:/g) || []).length === 1) {
|
|
44
|
-
[entry, port] = entry.split(':');
|
|
45
|
-
}
|
|
46
|
-
if (port && port !== (url.port || '443')) return false;
|
|
47
|
-
entry = entry.replace(/^\*?\./, '');
|
|
48
|
-
return host === entry || host.endsWith('.' + entry);
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function proxyFor(url, env) {
|
|
53
|
-
if (bypassProxy(url, env.no_proxy || env.NO_PROXY || '')) return null;
|
|
54
|
-
const raw = env.https_proxy || env.HTTPS_PROXY || env.all_proxy || env.ALL_PROXY;
|
|
55
|
-
// HTTP_PROXY is intentionally not used for HTTPS; this matches uv/curl routing.
|
|
56
|
-
if (!raw) return null;
|
|
57
|
-
try {
|
|
58
|
-
const proxy = new URL(raw);
|
|
59
|
-
if (!['http:', 'https:'].includes(proxy.protocol) || proxy.search || proxy.hash ||
|
|
60
|
-
(proxy.pathname && proxy.pathname !== '/')) throw new Error();
|
|
61
|
-
return proxy;
|
|
62
|
-
} catch { throw new DownloadError('download_invalid_proxy'); }
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function windowsEnvironment(env, platform) {
|
|
66
|
-
if (platform !== 'win32') return env;
|
|
67
|
-
const result = {};
|
|
68
|
-
for (const [name, value] of Object.entries(env)) {
|
|
69
|
-
const key = name.toUpperCase();
|
|
70
|
-
if (Object.hasOwn(result, key) && result[key] !== value) throw new DownloadError('download_ambiguous_environment');
|
|
71
|
-
result[key] = value;
|
|
72
|
-
}
|
|
73
|
-
return result;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function certificates(env) {
|
|
77
|
-
const paths = [...new Set([env.SSL_CERT_FILE, env.NODE_EXTRA_CA_CERTS].filter(Boolean))];
|
|
78
|
-
if (!paths.length) return undefined;
|
|
79
|
-
const ca = typeof tls.getCACertificates === 'function'
|
|
80
|
-
? [...tls.getCACertificates('default')] : [...tls.rootCertificates];
|
|
81
|
-
try {
|
|
82
|
-
for (const file of paths) {
|
|
83
|
-
const info = fs.statSync(file);
|
|
84
|
-
if (!info.isFile() || info.size > 4 * 1024 * 1024) throw new Error();
|
|
85
|
-
const pem = fs.readFileSync(file, 'utf8');
|
|
86
|
-
if (!pem.includes('-----BEGIN CERTIFICATE-----')) throw new Error();
|
|
87
|
-
ca.push(pem);
|
|
88
|
-
}
|
|
89
|
-
} catch { throw new DownloadError('download_invalid_ca'); }
|
|
90
|
-
return ca;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function requestAsset(url, env, ca, state) {
|
|
94
|
-
return new Promise((resolve, reject) => {
|
|
95
|
-
const proxy = proxyFor(url, env);
|
|
96
|
-
const agent = new https.Agent({ keepAlive: false, ...(ca ? { ca } : {}) });
|
|
97
|
-
state.resources.add(agent);
|
|
98
|
-
if (proxy) {
|
|
99
|
-
agent.createConnection = (_options, callback) => {
|
|
100
|
-
let completed = false;
|
|
101
|
-
const complete = (error, socket) => {
|
|
102
|
-
if (completed) return;
|
|
103
|
-
completed = true;
|
|
104
|
-
callback(error, socket);
|
|
105
|
-
};
|
|
106
|
-
const authority = url.host + (url.port ? '' : ':443');
|
|
107
|
-
const headers = { Host: authority };
|
|
108
|
-
if (proxy.username || proxy.password) {
|
|
109
|
-
headers['Proxy-Authorization'] = 'Basic ' + Buffer.from(
|
|
110
|
-
decodeURIComponent(proxy.username) + ':' + decodeURIComponent(proxy.password),
|
|
111
|
-
).toString('base64');
|
|
112
|
-
}
|
|
113
|
-
const transport = proxy.protocol === 'https:' ? https : http;
|
|
114
|
-
const connect = transport.request({
|
|
115
|
-
protocol: proxy.protocol, hostname: proxy.hostname.replace(/^\[|\]$/g, ''),
|
|
116
|
-
port: proxy.port || (proxy.protocol === 'https:' ? 443 : 80),
|
|
117
|
-
method: 'CONNECT', path: authority, headers, agent: false,
|
|
118
|
-
maxHeaderSize: 16384, signal: state.controller.signal,
|
|
119
|
-
rejectUnauthorized: true, ...(ca ? { ca } : {}),
|
|
120
|
-
});
|
|
121
|
-
state.resources.add(connect);
|
|
122
|
-
connect.once('error', (error) => complete(error));
|
|
123
|
-
connect.once('connect', (response, socket, head) => {
|
|
124
|
-
state.resources.add(socket);
|
|
125
|
-
if (response.statusCode !== 200) {
|
|
126
|
-
socket.destroy();
|
|
127
|
-
complete(new DownloadError('download_proxy_rejected'));
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
if (head.length) socket.unshift(head);
|
|
131
|
-
const hostname = url.hostname.replace(/^\[|\]$/g, '');
|
|
132
|
-
const secure = tls.connect({
|
|
133
|
-
socket, servername: net.isIP(hostname) ? undefined : hostname,
|
|
134
|
-
host: hostname, rejectUnauthorized: true, ...(ca ? { ca } : {}),
|
|
135
|
-
});
|
|
136
|
-
state.resources.add(secure);
|
|
137
|
-
secure.once('error', (error) => complete(error));
|
|
138
|
-
secure.once('secureConnect', () => complete(null, secure));
|
|
139
|
-
});
|
|
140
|
-
connect.end();
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
const request = https.request(url, {
|
|
144
|
-
method: 'GET', agent, signal: state.controller.signal, maxHeaderSize: 16384,
|
|
145
|
-
rejectUnauthorized: true, headers: { 'User-Agent': 'decision-browser-bootstrap', 'Accept-Encoding': 'identity' },
|
|
146
|
-
...(ca ? { ca } : {}),
|
|
147
|
-
}, (response) => {
|
|
148
|
-
state.resources.add(response);
|
|
149
|
-
if ([301, 302, 303, 307, 308].includes(response.statusCode)) {
|
|
150
|
-
const location = response.headers.location;
|
|
151
|
-
response.destroy();
|
|
152
|
-
resolve({ location });
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
if (response.statusCode !== 200) {
|
|
156
|
-
response.destroy();
|
|
157
|
-
reject(new DownloadError('download_http_failed'));
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
const length = response.headers['content-length'];
|
|
161
|
-
if (length !== undefined && (!/^\d+$/.test(length) || Number(length) > state.maxBytes)) {
|
|
162
|
-
response.destroy();
|
|
163
|
-
reject(new DownloadError('download_too_large'));
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
const chunks = [];
|
|
167
|
-
let size = 0;
|
|
168
|
-
response.on('data', (chunk) => {
|
|
169
|
-
size += chunk.length;
|
|
170
|
-
if (size > state.maxBytes) {
|
|
171
|
-
reject(new DownloadError('download_too_large'));
|
|
172
|
-
response.destroy();
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
chunks.push(chunk);
|
|
176
|
-
});
|
|
177
|
-
response.once('error', reject);
|
|
178
|
-
response.once('aborted', () => reject(new DownloadError('download_truncated')));
|
|
179
|
-
response.once('end', () => {
|
|
180
|
-
if (length !== undefined && size !== Number(length)) reject(new DownloadError('download_truncated'));
|
|
181
|
-
else resolve({ bytes: Buffer.concat(chunks, size) });
|
|
182
|
-
});
|
|
183
|
-
});
|
|
184
|
-
state.resources.add(request);
|
|
185
|
-
request.once('error', reject);
|
|
186
|
-
request.end();
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
async function download(url, { env = {}, maxBytes = 64 * 1024 * 1024, timeoutMs = 120000, platform = process.platform } = {}) {
|
|
191
|
-
if (!Number.isSafeInteger(maxBytes) || maxBytes < 1 || !Number.isFinite(timeoutMs) || timeoutMs <= 0) {
|
|
192
|
-
throw new DownloadError('download_invalid_limits');
|
|
193
|
-
}
|
|
194
|
-
const state = { controller: new AbortController(), resources: new Set(), maxBytes };
|
|
195
|
-
let timer;
|
|
196
|
-
try {
|
|
197
|
-
env = windowsEnvironment(env, platform);
|
|
198
|
-
const ca = certificates(env);
|
|
199
|
-
const task = async () => {
|
|
200
|
-
let target = destination(url);
|
|
201
|
-
for (let redirects = 0; redirects <= 5; redirects++) {
|
|
202
|
-
const result = await requestAsset(target, env, ca, state);
|
|
203
|
-
if (result.bytes) return result.bytes;
|
|
204
|
-
if (!result.location) throw new DownloadError('download_invalid_redirect');
|
|
205
|
-
target = destination(result.location, target);
|
|
206
|
-
}
|
|
207
|
-
throw new DownloadError('download_redirect_limit');
|
|
208
|
-
};
|
|
209
|
-
return await Promise.race([task(), new Promise((_, reject) => {
|
|
210
|
-
timer = setTimeout(() => reject(new DownloadError('download_timeout')), timeoutMs);
|
|
211
|
-
})]);
|
|
212
|
-
} catch (error) { throw failure(error); }
|
|
213
|
-
finally {
|
|
214
|
-
clearTimeout(timer);
|
|
215
|
-
state.controller.abort();
|
|
216
|
-
for (const resource of state.resources) resource.destroy();
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
function tarNumber(field) {
|
|
221
|
-
const value = field.toString('ascii').replace(/\0.*$/, '').trim();
|
|
222
|
-
if (!/^[0-7]+$/.test(value)) throw new DownloadError('archive_invalid');
|
|
223
|
-
const number = parseInt(value, 8);
|
|
224
|
-
if (!Number.isSafeInteger(number)) throw new DownloadError('archive_invalid');
|
|
225
|
-
return number;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
function tarMember(buffer, member, maxBytes) {
|
|
229
|
-
const tar = zlib.gunzipSync(buffer, { maxOutputLength: Math.min(512 * 1024 * 1024, maxBytes * 3 + 1024 * 1024) });
|
|
230
|
-
let found;
|
|
231
|
-
let position = 0;
|
|
232
|
-
let ended = false;
|
|
233
|
-
while (position + 512 <= tar.length) {
|
|
234
|
-
const header = tar.subarray(position, position + 512);
|
|
235
|
-
if (header.every((value) => value === 0)) {
|
|
236
|
-
if (position + 1024 > tar.length || !tar.subarray(position).every((value) => value === 0)) {
|
|
237
|
-
throw new DownloadError('archive_truncated');
|
|
238
|
-
}
|
|
239
|
-
ended = true;
|
|
240
|
-
break;
|
|
241
|
-
}
|
|
242
|
-
let checksum = 0;
|
|
243
|
-
for (let index = 0; index < 512; index++) checksum += index >= 148 && index < 156 ? 32 : header[index];
|
|
244
|
-
if (checksum !== tarNumber(header.subarray(148, 156))) throw new DownloadError('archive_invalid');
|
|
245
|
-
const name = header.subarray(0, 100).toString('utf8').replace(/\0.*$/, '');
|
|
246
|
-
const prefix = header.subarray(345, 500).toString('utf8').replace(/\0.*$/, '');
|
|
247
|
-
const fullName = prefix ? prefix + '/' + name : name;
|
|
248
|
-
const size = tarNumber(header.subarray(124, 136));
|
|
249
|
-
const start = position + 512;
|
|
250
|
-
const end = start + size;
|
|
251
|
-
if (end > tar.length) throw new DownloadError('archive_truncated');
|
|
252
|
-
if (fullName === member) {
|
|
253
|
-
if (found !== undefined || ![0, 48].includes(header[156])) throw new DownloadError('archive_invalid_member');
|
|
254
|
-
if (size === 0 || size > maxBytes) throw new DownloadError('archive_member_too_large');
|
|
255
|
-
found = Buffer.from(tar.subarray(start, end));
|
|
256
|
-
}
|
|
257
|
-
position = start + Math.ceil(size / 512) * 512;
|
|
258
|
-
}
|
|
259
|
-
if (!ended) throw new DownloadError('archive_truncated');
|
|
260
|
-
if (found === undefined) throw new DownloadError('archive_missing_member');
|
|
261
|
-
return found;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
function crc32(bytes) {
|
|
265
|
-
let crc = 0xffffffff;
|
|
266
|
-
for (const byte of bytes) {
|
|
267
|
-
crc ^= byte;
|
|
268
|
-
for (let bit = 0; bit < 8; bit++) crc = (crc >>> 1) ^ ((crc & 1) ? 0xedb88320 : 0);
|
|
269
|
-
}
|
|
270
|
-
return (crc ^ 0xffffffff) >>> 0;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
function zipMember(zip, member, maxBytes) {
|
|
274
|
-
let footer = -1;
|
|
275
|
-
for (let index = zip.length - 22; index >= Math.max(0, zip.length - 65557); index--) {
|
|
276
|
-
if (zip.readUInt32LE(index) === 0x06054b50 && index + 22 + zip.readUInt16LE(index + 20) === zip.length) {
|
|
277
|
-
footer = index; break;
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
if (footer < 0 || zip.readUInt16LE(footer + 4) !== 0 || zip.readUInt16LE(footer + 6) !== 0) {
|
|
281
|
-
throw new DownloadError('archive_invalid');
|
|
282
|
-
}
|
|
283
|
-
const count = zip.readUInt16LE(footer + 10);
|
|
284
|
-
const directorySize = zip.readUInt32LE(footer + 12);
|
|
285
|
-
let cursor = zip.readUInt32LE(footer + 16);
|
|
286
|
-
const directoryEnd = cursor + directorySize;
|
|
287
|
-
if (count !== zip.readUInt16LE(footer + 8) || count === 65535 || directoryEnd !== footer) throw new DownloadError('archive_invalid');
|
|
288
|
-
let found;
|
|
289
|
-
for (let index = 0; index < count; index++) {
|
|
290
|
-
if (cursor + 46 > directoryEnd || zip.readUInt32LE(cursor) !== 0x02014b50) throw new DownloadError('archive_invalid');
|
|
291
|
-
const flags = zip.readUInt16LE(cursor + 8);
|
|
292
|
-
const method = zip.readUInt16LE(cursor + 10);
|
|
293
|
-
const packed = zip.readUInt32LE(cursor + 20);
|
|
294
|
-
const size = zip.readUInt32LE(cursor + 24);
|
|
295
|
-
const nameSize = zip.readUInt16LE(cursor + 28);
|
|
296
|
-
const extraSize = zip.readUInt16LE(cursor + 30);
|
|
297
|
-
const commentSize = zip.readUInt16LE(cursor + 32);
|
|
298
|
-
const end = cursor + 46 + nameSize + extraSize + commentSize;
|
|
299
|
-
if (end > directoryEnd) throw new DownloadError('archive_invalid');
|
|
300
|
-
const name = zip.subarray(cursor + 46, cursor + 46 + nameSize).toString('utf8');
|
|
301
|
-
if (name === member) {
|
|
302
|
-
const mode = zip.readUInt32LE(cursor + 38) >>> 16;
|
|
303
|
-
if (found !== undefined || (flags & 1) || (mode & 0xf000) && (mode & 0xf000) !== 0x8000 || ![0, 8].includes(method)) {
|
|
304
|
-
throw new DownloadError('archive_invalid_member');
|
|
305
|
-
}
|
|
306
|
-
if (!size || size > maxBytes) throw new DownloadError('archive_member_too_large');
|
|
307
|
-
const local = zip.readUInt32LE(cursor + 42);
|
|
308
|
-
if (local + 30 > directoryEnd || zip.readUInt32LE(local) !== 0x04034b50) throw new DownloadError('archive_invalid');
|
|
309
|
-
const localNameSize = zip.readUInt16LE(local + 26);
|
|
310
|
-
const start = local + 30 + localNameSize + zip.readUInt16LE(local + 28);
|
|
311
|
-
if (start + packed > zip.readUInt32LE(footer + 16) || zip.readUInt16LE(local + 6) !== flags ||
|
|
312
|
-
zip.readUInt16LE(local + 8) !== method || zip.subarray(local + 30, local + 30 + localNameSize).toString('utf8') !== member) {
|
|
313
|
-
throw new DownloadError('archive_invalid');
|
|
314
|
-
}
|
|
315
|
-
const data = zip.subarray(start, start + packed);
|
|
316
|
-
found = method === 0 ? Buffer.from(data) : zlib.inflateRawSync(data, { maxOutputLength: maxBytes });
|
|
317
|
-
if (found.length !== size) throw new DownloadError('archive_truncated');
|
|
318
|
-
const checksum = zip.readUInt32LE(cursor + 16);
|
|
319
|
-
if (crc32(found) !== checksum || (!(flags & 8) && zip.readUInt32LE(local + 14) !== checksum)) {
|
|
320
|
-
throw new DownloadError('archive_crc_mismatch');
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
cursor = end;
|
|
324
|
-
}
|
|
325
|
-
if (cursor !== directoryEnd) throw new DownloadError('archive_invalid');
|
|
326
|
-
if (found === undefined) throw new DownloadError('archive_missing_member');
|
|
327
|
-
return found;
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
function extractUv(buffer, { format, member, maxBytes = 128 * 1024 * 1024 }) {
|
|
331
|
-
try {
|
|
332
|
-
if (!Buffer.isBuffer(buffer) || typeof member !== 'string' || !member || /[\x00-\x1f\x7f]/.test(member) ||
|
|
333
|
-
member.startsWith('/') || member.includes('\\') || member.split('/').some((part) => !part || ['.', '..'].includes(part)) ||
|
|
334
|
-
!Number.isSafeInteger(maxBytes) || maxBytes < 1) throw new DownloadError('archive_invalid');
|
|
335
|
-
if (format === 'tar.gz') return tarMember(buffer, member, maxBytes);
|
|
336
|
-
if (format === 'zip') return zipMember(buffer, member, maxBytes);
|
|
337
|
-
throw new DownloadError('archive_unsupported');
|
|
338
|
-
} catch (error) {
|
|
339
|
-
if (error instanceof DownloadError) throw error;
|
|
340
|
-
throw new DownloadError('archive_invalid');
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
module.exports = { DownloadError, download, extractUv };
|
package/bin/uv-manifest.json
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": "0.13.7",
|
|
3
|
-
"baseUrl": "https://releases.astral.sh/github/uv/releases/download/0.13.7/",
|
|
4
|
-
"targets": {
|
|
5
|
-
"darwin-arm64": {"file": "uv-aarch64-apple-darwin.tar.gz", "sha256": "81b811b57e4624df7ed3aac148e0359100d9962f3d9dce00aec533dc2e086731", "format": "tar.gz", "member": "uv-aarch64-apple-darwin/uv"},
|
|
6
|
-
"darwin-x64": {"file": "uv-x86_64-apple-darwin.tar.gz", "sha256": "20c47e4c1f630b8abaff8c291fa9b9aa300fef92c4fbff95adf198b55287cda7", "format": "tar.gz", "member": "uv-x86_64-apple-darwin/uv"},
|
|
7
|
-
"linux-arm64": {"file": "uv-aarch64-unknown-linux-musl.tar.gz", "sha256": "2d3ec076a0c4c0e8250bb6418c44080828b544f1a3be0b6e46adf9fb6923de45", "format": "tar.gz", "member": "uv-aarch64-unknown-linux-musl/uv"},
|
|
8
|
-
"linux-x64": {"file": "uv-x86_64-unknown-linux-musl.tar.gz", "sha256": "287491da03f2a785c70fa75b13e1f849918c2f2b5415fe84876b8214eeb792f9", "format": "tar.gz", "member": "uv-x86_64-unknown-linux-musl/uv"},
|
|
9
|
-
"win32-arm64": {"file": "uv-aarch64-pc-windows-msvc.zip", "sha256": "505d9e65e7692bac3ddf98c66754aa26c5050c409c184af30a881a0a72cc85e3", "format": "zip", "member": "uv.exe"},
|
|
10
|
-
"win32-x64": {"file": "uv-x86_64-pc-windows-msvc.zip", "sha256": "0cdc5b38fe5a8168ed6a25814f5ba43c21d313dd3187314fccb37b7cec46e021", "format": "zip", "member": "uv.exe"}
|
|
11
|
-
}
|
|
12
|
-
}
|
|
Binary file
|