Phase 2 references for the host-agent Dune adapter, moved out of volatile /tmp
into docs/reference-repos/ (per Commander). Three upstream projects, .git +
node_modules + compiled binaries stripped (16MB source). Nested AI-instruction
files (.claude/, CLAUDE.md) removed so they don't pollute Corrosion sessions.
- icehunter/ dune-admin (Go+React) — 4 control planes; SETUP_DOCKER.md is the
closest analog to our agent's Dune docker control plane (compose
lifecycle, docker logs, RabbitMQ-via-exec, dune Postgres schema)
- adainrivers/ Rust/Tauri desktop — SSH+k8s BattleGroup control, maintenance
daemon, in-game admin console (Rust idiom reference)
- the4rchangel/ Node web UI replacing battlegroup.bat — matches the Commander's
Hyper-V self-host path + game-config schema
See docs/reference-repos/README.md for the full index + how we use each.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
99 lines
2.7 KiB
JavaScript
99 lines
2.7 KiB
JavaScript
const { spawn } = require('child_process');
|
|
const paths = require('./paths');
|
|
|
|
/**
|
|
* @param {string} ip
|
|
* @param {string} command
|
|
* @param {function} [onData] — streaming callback
|
|
* @param {object} [opts]
|
|
* @param {number} [opts.timeout] — kill after N ms (default 300000 = 5 min)
|
|
* @param {boolean} [opts.tty] — force pseudo-terminal (-tt)
|
|
* @param {string} [opts.stdin] — data to write to stdin then close
|
|
*/
|
|
function run(ip, command, onData, opts = {}) {
|
|
return new Promise((resolve, reject) => {
|
|
let keyPath;
|
|
try {
|
|
keyPath = paths.getSshIdentityPath();
|
|
} catch (err) {
|
|
reject(err);
|
|
return;
|
|
}
|
|
const timeout = opts.timeout || 300000;
|
|
|
|
const args = [
|
|
'-o', 'StrictHostKeyChecking=no',
|
|
'-o', 'LogLevel=QUIET',
|
|
'-o', 'ConnectTimeout=10',
|
|
'-o', 'ServerAliveInterval=15',
|
|
'-o', 'ServerAliveCountMax=4',
|
|
];
|
|
|
|
if (opts.tty) args.push('-tt');
|
|
|
|
args.push('-i', keyPath, `dune@${ip}`, command);
|
|
|
|
const needsStdinPipe = opts.tty || opts.stdin != null;
|
|
|
|
const proc = spawn('ssh', args, {
|
|
windowsHide: true,
|
|
stdio: [needsStdinPipe ? 'pipe' : 'ignore', 'pipe', 'pipe'],
|
|
});
|
|
|
|
if (needsStdinPipe) {
|
|
if (opts.stdin != null) proc.stdin.write(opts.stdin);
|
|
proc.stdin.end();
|
|
}
|
|
|
|
let stdout = '';
|
|
let stderr = '';
|
|
let killed = false;
|
|
|
|
const timer = setTimeout(() => {
|
|
killed = true;
|
|
proc.kill('SIGKILL');
|
|
}, timeout);
|
|
|
|
proc.stdout.on('data', (chunk) => {
|
|
const text = chunk.toString();
|
|
stdout += text;
|
|
if (onData) onData(text);
|
|
});
|
|
|
|
proc.stderr.on('data', (chunk) => {
|
|
const text = chunk.toString();
|
|
stderr += text;
|
|
if (onData) onData(text);
|
|
});
|
|
|
|
proc.on('error', (err) => { clearTimeout(timer); reject(err); });
|
|
proc.on('close', (code) => {
|
|
clearTimeout(timer);
|
|
if (killed) {
|
|
const err = new Error(`SSH command timed out after ${timeout / 1000}s`);
|
|
err.stdout = stdout;
|
|
err.stderr = stderr;
|
|
return reject(err);
|
|
}
|
|
if (code === 0) {
|
|
resolve(stdout.trim());
|
|
} else {
|
|
const stderrTrim = stderr.trim();
|
|
const stdoutTrim = stdout.trim();
|
|
const ptyClosed = /Connection to .+ closed\.?$/m.test(stderrTrim);
|
|
if (stdoutTrim && (!stderrTrim || ptyClosed)) {
|
|
resolve(stdoutTrim);
|
|
return;
|
|
}
|
|
const err = new Error(stderrTrim || stdoutTrim || `SSH exited with code ${code}`);
|
|
err.code = code;
|
|
err.stdout = stdout;
|
|
err.stderr = stderr;
|
|
reject(err);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
module.exports = { run, getKeyPath: paths.getKeyPath, sshKeyExists: paths.sshKeyExists };
|