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
17
cli/mcp.ts
17
cli/mcp.ts
|
|
@ -20,8 +20,8 @@
|
|||
// Every tool runs the CLI as a child process in the project directory (STOREBOUND_PROJECT or the server's cwd) and
|
||||
// returns its output. stdout of this process carries protocol messages only; logs go to stderr.
|
||||
// Tool list and safety rules: mcp-tools.ts (write tools default to dry_run, nothing public or irreversible exposed).
|
||||
import { join } from 'node:path';
|
||||
import pkg from '../package.json' with { type: 'json' };
|
||||
import { runCommand, type Running } from './lib/runner';
|
||||
import { listTools, TOOLS, toArgv, validateInput } from './mcp-tools';
|
||||
|
||||
/** Current (modern, stateless) revision. */
|
||||
|
|
@ -54,7 +54,6 @@ type Id = string | number;
|
|||
interface Msg { jsonrpc: '2.0'; id?: Id; method?: string; params?: Record<string, unknown> }
|
||||
|
||||
const MAX_OUTPUT = 60_000;
|
||||
const CLI = join(import.meta.dir, 'index.ts');
|
||||
const serverInfo = () => ({ name: 'storebound', title: 'storebound', version: pkg.version });
|
||||
|
||||
/** Era of one request: modern when its _meta names a modern (or unknown) protocol version, else legacy. */
|
||||
|
|
@ -117,17 +116,13 @@ export async function handle(m: Msg, run: (argv: string[], id: Id) => Promise<{
|
|||
}
|
||||
}
|
||||
|
||||
const running = new Map<Id, ReturnType<typeof Bun.spawn>>();
|
||||
function cancel(id: Id | undefined): void { if (id !== undefined) running.get(id)?.kill(); }
|
||||
const running = new Map<Id, Running>();
|
||||
function cancel(id: Id | undefined): void { if (id !== undefined) running.get(id)?.cancel(); }
|
||||
|
||||
async function runCli(argv: string[], id: Id): Promise<{ code: number; out: string }> {
|
||||
const cwd = process.env.STOREBOUND_PROJECT || process.cwd();
|
||||
const p = Bun.spawn([process.execPath, CLI, ...argv], { cwd, stdin: 'ignore', stdout: 'pipe', stderr: 'pipe', env: { ...process.env, NO_COLOR: '1' } });
|
||||
running.set(id, p);
|
||||
try {
|
||||
const [out, errText, code] = await Promise.all([new Response(p.stdout).text(), new Response(p.stderr).text(), p.exited]);
|
||||
return { code, out: (out + (errText ? `\n${errText}` : '')).trim() };
|
||||
} finally { running.delete(id); }
|
||||
const r = runCommand(argv, { cwd: process.env.STOREBOUND_PROJECT || process.cwd() });
|
||||
running.set(id, r);
|
||||
try { const { code, out } = await r.result; return { code, out }; } finally { running.delete(id); }
|
||||
}
|
||||
|
||||
export async function serve(): Promise<void> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue