fix: rpc-entry and bun support
This commit is contained in:
@@ -15,6 +15,9 @@
|
||||
".": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./dist/index.js"
|
||||
},
|
||||
"./rpc-entry": {
|
||||
"import": "./dist/rpc-entry.js"
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
@@ -27,7 +30,7 @@
|
||||
],
|
||||
"scripts": {
|
||||
"clean": "shx rm -rf dist",
|
||||
"build": "tsgo -p tsconfig.build.json && shx chmod +x dist/cli.js && npm run copy-assets",
|
||||
"build": "tsgo -p tsconfig.build.json && shx chmod +x dist/cli.js dist/rpc-entry.js && npm run copy-assets",
|
||||
"build:binary": "npm --prefix ../tui run build && npm --prefix ../ai run build && npm --prefix ../agent run build && npm run build && bun build --compile ./dist/bun/cli.js ./src/utils/image-resize-worker.ts --outfile dist/pi && npm run copy-binary-assets",
|
||||
"copy-assets": "shx mkdir -p dist/modes/interactive/theme && shx cp src/modes/interactive/theme/*.json dist/modes/interactive/theme/ && shx mkdir -p dist/modes/interactive/assets && shx cp src/modes/interactive/assets/*.png dist/modes/interactive/assets/ && shx mkdir -p dist/core/export-html/vendor && shx cp src/core/export-html/template.html src/core/export-html/template.css src/core/export-html/template.js dist/core/export-html/ && shx cp src/core/export-html/vendor/*.js dist/core/export-html/vendor/",
|
||||
"copy-binary-assets": "shx cp package.json dist/ && shx cp README.md dist/ && shx cp CHANGELOG.md dist/ && shx mkdir -p dist/theme && shx cp src/modes/interactive/theme/*.json dist/theme/ && shx mkdir -p dist/assets && shx cp src/modes/interactive/assets/*.png dist/assets/ && shx mkdir -p dist/export-html/vendor && shx cp src/core/export-html/template.html dist/export-html/ && shx cp src/core/export-html/vendor/*.js dist/export-html/vendor/ && shx cp -r docs dist/ && shx cp -r examples dist/ && shx cp ../../node_modules/@silvia-odwyer/photon-node/photon_rs_bg.wasm dist/",
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
#!/usr/bin/env node
|
||||
import { APP_NAME } from "./config.ts";
|
||||
import { configureHttpDispatcher } from "./core/http-dispatcher.ts";
|
||||
import { main } from "./main.ts";
|
||||
|
||||
process.title = `${APP_NAME}-rpc`;
|
||||
process.env.PI_CODING_AGENT = "true";
|
||||
process.emitWarning = (() => {}) as typeof process.emitWarning;
|
||||
|
||||
configureHttpDispatcher();
|
||||
|
||||
main(["--mode", "rpc", ...process.argv.slice(2)]);
|
||||
@@ -3,9 +3,6 @@
|
||||
"version": "0.80.2",
|
||||
"description": "experimental orchestrator package for pi",
|
||||
"type": "module",
|
||||
"bin": {
|
||||
"orchestrator": "dist/cli.js"
|
||||
},
|
||||
"main": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
"exports": {
|
||||
|
||||
@@ -4,6 +4,13 @@ import { join } from "node:path";
|
||||
const CONFIG_DIR_NAME = ".pi";
|
||||
const ENV_ORCHESTRATOR_DIR = "PI_ORCHESTRATOR_DIR";
|
||||
|
||||
/**
|
||||
* Detect if we're running as a Bun compiled binary.
|
||||
* Bun binaries have import.meta.url containing "$bunfs", "~BUN", or "%7EBUN" (Bun's virtual filesystem path)
|
||||
*/
|
||||
export const isBunBinary =
|
||||
import.meta.url.includes("$bunfs") || import.meta.url.includes("~BUN") || import.meta.url.includes("%7EBUN");
|
||||
|
||||
export function getOrchestratorDir(): string {
|
||||
const envDir = process.env[ENV_ORCHESTRATOR_DIR];
|
||||
if (envDir) {
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { type ChildProcess, spawn } from "node:child_process";
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { existsSync } from "node:fs";
|
||||
import { createRequire } from "node:module";
|
||||
import { dirname, join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import type {
|
||||
AgentSessionEvent,
|
||||
RpcCommand,
|
||||
@@ -10,6 +9,7 @@ import type {
|
||||
RpcExtensionUIResponse,
|
||||
RpcResponse,
|
||||
} from "@earendil-works/pi-coding-agent";
|
||||
import { isBunBinary } from "./config.ts";
|
||||
|
||||
interface PendingRequest {
|
||||
resolve(response: RpcResponse): void;
|
||||
@@ -26,13 +26,19 @@ export interface RpcProcessInstance {
|
||||
dispose(): Promise<void>;
|
||||
}
|
||||
|
||||
function resolveCodingAgentCli(): string {
|
||||
const packageDir = dirname(fileURLToPath(import.meta.url));
|
||||
const workspaceCli = join(packageDir, "../../coding-agent/dist/cli.js");
|
||||
if (existsSync(workspaceCli)) {
|
||||
return workspaceCli;
|
||||
const require = createRequire(import.meta.url);
|
||||
|
||||
function getRpcSpawnCommand(): { command: string; args: string[] } {
|
||||
if (isBunBinary) {
|
||||
return {
|
||||
command: join(dirname(process.execPath), process.platform === "win32" ? "pi.exe" : "pi"),
|
||||
args: ["--mode", "rpc"],
|
||||
};
|
||||
}
|
||||
throw new Error(`Unable to find coding-agent RPC CLI: ${workspaceCli}`);
|
||||
return {
|
||||
command: process.execPath,
|
||||
args: [require.resolve("@earendil-works/pi-coding-agent/rpc-entry")],
|
||||
};
|
||||
}
|
||||
|
||||
function toError(error: unknown): Error {
|
||||
@@ -40,8 +46,8 @@ function toError(error: unknown): Error {
|
||||
}
|
||||
|
||||
export function createRpcProcessInstance(options: { cwd: string }): RpcProcessInstance {
|
||||
const cliPath = resolveCodingAgentCli();
|
||||
const child = spawn(process.execPath, [cliPath, "--mode", "rpc"], {
|
||||
const rpcCommand = getRpcSpawnCommand();
|
||||
const child = spawn(rpcCommand.command, rpcCommand.args, {
|
||||
cwd: options.cwd,
|
||||
env: process.env,
|
||||
stdio: ["pipe", "pipe", "pipe"],
|
||||
|
||||
Reference in New Issue
Block a user