mirror of
https://github.com/Twigpine/zero.git
synced 2026-11-11 18:00:54 -10:00
* Add local control browser and terminal tools Add configurable local browser, desktop, and terminal control helpers with packaged helper discovery for install and release flows. Improve sandbox scope classification for local control commands and shared temporary paths. Add structured browser actions, terminal session line input/key normalization/read support, and artifact capture for local-control outputs. Tested: GOCACHE=/tmp/zero-go-cache go test ./internal/localcontrol ./internal/tools ./internal/cli ./internal/config -run 'Test.*LocalControl|TestTerminal|TestBrowser|TestDesktop|TestCapture' Tested: GOCACHE=/tmp/zero-go-cache go test ./internal/localcontrol ./internal/tools ./internal/cli ./internal/config ./internal/agent Tested: tuistory smoke launched bash, sent interactive input, waited for expected output, and captured a no-cursor snapshot Tested: git diff --cached --check * Fix npm wrapper helper manifest test on macOS Canonicalize expected helper paths in the npm wrapper manifest test so macOS /var and /private/var temp path aliases compare correctly. Tested: GOCACHE=/tmp/zero-go-cache go test ./internal/npmwrapper Tested: git diff --check * Harden local control review fixes Respect resolved local-control config before tool listing and filter validation while preserving stream-json usage error ordering. Harden browser, desktop, and artifact tool validation; guard Linux-only app launch behavior; clear stale helper manifests from the npm wrapper. Make helper packaging lockfile-based with npm ci and add installer/package tests for helper staging. Tested: focused local-control/tool/CLI/release/install/sandbox suite Tested: isolated full go test ./... Tested: macOS and Windows compile-only checks for touched packages
85 lines
2.3 KiB
JavaScript
Executable File
85 lines
2.3 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
|
|
import { spawnSync } from 'node:child_process';
|
|
import { existsSync } from 'node:fs';
|
|
import { dirname, join } from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
function zeroBinaryName(platform = process.platform) {
|
|
return platform === 'win32' ? 'zero.exe' : 'zero';
|
|
}
|
|
|
|
function helperShimNames(name, platform = process.platform) {
|
|
if (platform === 'win32') {
|
|
return [`${name}.cmd`, `${name}.exe`, name];
|
|
}
|
|
return [name];
|
|
}
|
|
|
|
function commandForShim(path, platform = process.platform) {
|
|
if (platform === 'win32' && path.toLowerCase().endsWith('.cmd')) {
|
|
return {
|
|
command: process.env.ComSpec || 'cmd.exe',
|
|
prefixArgs: ['/d', '/s', '/c', `"${path.replace(/"/g, '""')}"`],
|
|
};
|
|
}
|
|
return { command: path, prefixArgs: [] };
|
|
}
|
|
|
|
function resolveHelper(packageRoot, name) {
|
|
const binDir = join(packageRoot, 'node_modules', '.bin');
|
|
for (const shimName of helperShimNames(name)) {
|
|
const candidate = join(binDir, shimName);
|
|
if (!existsSync(candidate)) continue;
|
|
return {
|
|
...commandForShim(candidate),
|
|
pathPrepend: [binDir],
|
|
};
|
|
}
|
|
return null;
|
|
}
|
|
|
|
function localControlHelperManifest(packageRoot) {
|
|
const helpers = {};
|
|
for (const name of ['agent-browser', 'tuistory']) {
|
|
const helper = resolveHelper(packageRoot, name);
|
|
if (helper) helpers[name] = helper;
|
|
}
|
|
if (Object.keys(helpers).length === 0) return '';
|
|
return JSON.stringify({ version: 1, helpers });
|
|
}
|
|
|
|
const packageRoot = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
const nativePath = join(packageRoot, zeroBinaryName());
|
|
const localControlHelpers = localControlHelperManifest(packageRoot);
|
|
|
|
if (!existsSync(nativePath)) {
|
|
console.error(
|
|
'[zero] No native binary found next to the npm wrapper. Reinstall the zero package or run `go run ./cmd/zero-release build` from the repository.'
|
|
);
|
|
process.exit(1);
|
|
}
|
|
|
|
const env = { ...process.env };
|
|
if (localControlHelpers) {
|
|
env.ZERO_LOCAL_CONTROL_HELPERS = localControlHelpers;
|
|
} else {
|
|
delete env.ZERO_LOCAL_CONTROL_HELPERS;
|
|
}
|
|
|
|
const child = spawnSync(nativePath, process.argv.slice(2), {
|
|
stdio: 'inherit',
|
|
env,
|
|
});
|
|
|
|
if (child.error) {
|
|
console.error(`[zero] Failed to launch wrapper target: ${child.error.message}`);
|
|
process.exit(1);
|
|
}
|
|
|
|
if (child.signal) {
|
|
process.kill(process.pid, child.signal);
|
|
}
|
|
|
|
process.exit(child.status ?? 1);
|