serve --stdio: desktop JSON-RPC profile on the MCP core, confirm tokens, --json results, sidecar builds
- cli/serve.ts: session.hello with a per-session secret, typed methods per tool, project.inspect, portfolio.status over many project folders, progress notifications, cancellation - cli/lib/confirm-token.ts: single-use HMAC tokens bound to method + canonical params + expiry; writes are dry runs without one; no submit / release / publish method exists - cli/lib/runner.ts: shared child runner for mcp and serve, works from a compiled binary - --json on check, testflight / ppo status, next-build, next-version-code, analytics compare, prices import; inspect command; confirm() always answers no under serve - tools/build-sidecars.ts: bun build --compile for five targets, ad-hoc re-sign on macOS, path leak check - tests/serve.test.ts: methods, token binding / expiry / replay, shared vector, stdio and compiled smoke
This commit is contained in:
parent
c6360812b8
commit
3454a9aadb
28 changed files with 1048 additions and 42 deletions
71
tools/build-sidecars.ts
Normal file
71
tools/build-sidecars.ts
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
#!/usr/bin/env bun
|
||||
// Compiles the storebound CLI into single-file executables for the desktop app's sidecar (Tauri `externalBin`).
|
||||
// bun tools/build-sidecars.ts every target
|
||||
// bun tools/build-sidecars.ts --host only this machine's target (what `tauri dev` needs)
|
||||
// bun tools/build-sidecars.ts --target bun-linux-x64[,bun-windows-x64]
|
||||
// Output: apps/desktop/src-tauri/binaries/storebound-<rust target triple>[.exe] (Tauri's sidecar naming; gitignored).
|
||||
// macOS outputs are re-signed ad hoc: the signature `bun build --compile` leaves is invalid once the payload is
|
||||
// appended, and the kernel kills such a binary on start (exit 137). Release builds re-sign with Developer ID (D5).
|
||||
// Every output is scanned for the build machine's home and checkout paths: nothing private may ship.
|
||||
import { mkdirSync, readFileSync, rmSync, statSync } from 'node:fs';
|
||||
import { homedir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
|
||||
export const TARGETS: Record<string, string> = {
|
||||
'bun-darwin-arm64': 'aarch64-apple-darwin',
|
||||
'bun-darwin-x64': 'x86_64-apple-darwin',
|
||||
'bun-linux-x64': 'x86_64-unknown-linux-gnu',
|
||||
'bun-linux-arm64': 'aarch64-unknown-linux-gnu',
|
||||
'bun-windows-x64': 'x86_64-pc-windows-msvc',
|
||||
};
|
||||
|
||||
export const ROOT = join(import.meta.dir, '..');
|
||||
export const OUT_DIR = join(ROOT, 'apps/desktop/src-tauri/binaries');
|
||||
|
||||
export function hostTarget(): string {
|
||||
const os = process.platform === 'darwin' ? 'darwin' : process.platform === 'win32' ? 'windows' : 'linux';
|
||||
const arch = process.arch === 'arm64' ? 'arm64' : 'x64';
|
||||
return `bun-${os}-${arch}`;
|
||||
}
|
||||
|
||||
export const outName = (target: string): string => `storebound-${TARGETS[target]}${target.includes('windows') ? '.exe' : ''}`;
|
||||
|
||||
/** Paths of this machine that must not appear in a shipped binary. */
|
||||
export function privateStrings(): string[] {
|
||||
return [...new Set([homedir(), ROOT].filter(s => s.length > 4))];
|
||||
}
|
||||
|
||||
export function leaks(file: string, needles = privateStrings()): string[] {
|
||||
const buf = readFileSync(file);
|
||||
return needles.filter(n => buf.includes(Buffer.from(n)));
|
||||
}
|
||||
|
||||
export async function buildOne(target: string, outDir = OUT_DIR): Promise<string> {
|
||||
if (!TARGETS[target]) throw new Error(`unknown target ${target} (${Object.keys(TARGETS).join(', ')})`);
|
||||
mkdirSync(outDir, { recursive: true });
|
||||
const out = join(outDir, outName(target));
|
||||
rmSync(out, { force: true });
|
||||
const t = Date.now();
|
||||
const p = Bun.spawnSync(['bun', 'build', '--compile', `--target=${target}`, '--minify-syntax', '--minify-whitespace', 'cli/index.ts', '--outfile', out],
|
||||
{ cwd: ROOT, stdout: 'pipe', stderr: 'pipe' });
|
||||
if (p.exitCode !== 0) throw new Error(`${target}: bun build failed\n${p.stderr.toString()}${p.stdout.toString()}`);
|
||||
if (target.startsWith('bun-darwin') && process.platform === 'darwin') {
|
||||
const s = Bun.spawnSync(['codesign', '--force', '--sign', '-', out], { stdout: 'pipe', stderr: 'pipe' });
|
||||
if (s.exitCode !== 0) throw new Error(`${target}: ad-hoc codesign failed: ${s.stderr.toString()}`);
|
||||
}
|
||||
const hits = leaks(out);
|
||||
if (hits.length) throw new Error(`${target}: ${out} contains private paths (${hits.length}); refusing to keep it`);
|
||||
console.log(`sidecar ${target} -> ${out} (${(statSync(out).size / 1e6).toFixed(1)} MB, ${((Date.now() - t) / 1000).toFixed(1)}s)`);
|
||||
return out;
|
||||
}
|
||||
|
||||
if (import.meta.main) {
|
||||
const argv = process.argv.slice(2);
|
||||
const i = argv.indexOf('--target');
|
||||
const targets = argv.includes('--host') ? [hostTarget()] : i >= 0 ? (argv[i + 1] ?? '').split(',').filter(Boolean) : Object.keys(TARGETS);
|
||||
let failed = 0;
|
||||
for (const t of targets) {
|
||||
try { await buildOne(t); } catch (e) { failed++; console.error(`sidecar ${t}: ${(e as Error).message}`); }
|
||||
}
|
||||
if (failed) process.exit(1);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue