diff --git a/package-lock.json b/package-lock.json index 7a6e1bfc..f37deb57 100644 --- a/package-lock.json +++ b/package-lock.json @@ -793,6 +793,10 @@ "resolved": "packages/coding-agent", "link": true }, + "node_modules/@earendil-works/pi-orchestrator": { + "resolved": "packages/orchestrator", + "link": true + }, "node_modules/@earendil-works/pi-tui": { "resolved": "packages/tui", "link": true @@ -6134,6 +6138,20 @@ } } }, + "packages/orchestrator": { + "name": "@earendil-works/pi-orchestrator", + "version": "0.80.2", + "license": "MIT", + "dependencies": { + "@earendil-works/pi-coding-agent": "0.80.2" + }, + "devDependencies": { + "shx": "0.4.0" + }, + "engines": { + "node": ">=22.19.0" + } + }, "packages/tui": { "name": "@earendil-works/pi-tui", "version": "0.80.2", diff --git a/package.json b/package.json index 0deabeca..c79b42fa 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ ], "scripts": { "clean": "npm run clean --workspaces", - "build": "cd packages/tui && npm run build && cd ../ai && npm run build && cd ../agent && npm run build && cd ../coding-agent && npm run build", + "build": "cd packages/tui && npm run build && cd ../ai && npm run build && cd ../agent && npm run build && cd ../coding-agent && npm run build && cd ../orchestrator && npm run build", "check": "biome check --write --error-on-warnings . && npm run check:pinned-deps && npm run check:ts-imports && npm run check:shrinkwrap && tsgo --noEmit && npm run check:browser-smoke", "check:browser-smoke": "node scripts/check-browser-smoke.mjs", "check:pinned-deps": "node scripts/check-pinned-deps.mjs", diff --git a/packages/coding-agent/package.json b/packages/coding-agent/package.json index 8175de4f..c75ccb3a 100644 --- a/packages/coding-agent/package.json +++ b/packages/coding-agent/package.json @@ -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/", diff --git a/packages/coding-agent/src/rpc-entry.ts b/packages/coding-agent/src/rpc-entry.ts new file mode 100644 index 00000000..a07f9b33 --- /dev/null +++ b/packages/coding-agent/src/rpc-entry.ts @@ -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)]); diff --git a/packages/orchestrator/CHANGELOG.md b/packages/orchestrator/CHANGELOG.md new file mode 100644 index 00000000..1a588142 --- /dev/null +++ b/packages/orchestrator/CHANGELOG.md @@ -0,0 +1,3 @@ +# Changelog + +## [Unreleased] diff --git a/packages/orchestrator/README.md b/packages/orchestrator/README.md new file mode 100644 index 00000000..aabd7243 --- /dev/null +++ b/packages/orchestrator/README.md @@ -0,0 +1,11 @@ +# @earendil-works/pi-orchestrator + +Experimental. This package is under active development and may change or be removed without notice. Its CLI, APIs, and behavior are not yet stable. + +Orchestrator package for pi. + +## CLI + +```bash +orchestrator --help +``` diff --git a/packages/orchestrator/package.json b/packages/orchestrator/package.json new file mode 100644 index 00000000..da71a472 --- /dev/null +++ b/packages/orchestrator/package.json @@ -0,0 +1,45 @@ +{ + "name": "@earendil-works/pi-orchestrator", + "version": "0.80.2", + "description": "experimental orchestrator package for pi", + "type": "module", + "main": "./dist/index.js", + "types": "./dist/index.d.ts", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/index.js" + } + }, + "files": [ + "dist", + "README.md", + "CHANGELOG.md" + ], + "scripts": { + "clean": "shx rm -rf dist", + "dev": "tsgo -p tsconfig.build.json --watch --preserveWatchOutput", + "build": "tsgo -p tsconfig.build.json && shx chmod +x dist/cli.js", + "prepublishOnly": "npm run clean && npm run build" + }, + "keywords": [ + "pi", + "orchestrator" + ], + "author": "Earendil Works", + "license": "MIT", + "repository": { + "type": "git", + "url": "git+https://github.com/earendil-works/pi.git", + "directory": "packages/orchestrator" + }, + "engines": { + "node": ">=22.19.0" + }, + "dependencies": { + "@earendil-works/pi-coding-agent": "0.80.2" + }, + "devDependencies": { + "shx": "0.4.0" + } +} diff --git a/packages/orchestrator/src/cli.ts b/packages/orchestrator/src/cli.ts new file mode 100644 index 00000000..856dd658 --- /dev/null +++ b/packages/orchestrator/src/cli.ts @@ -0,0 +1,161 @@ +#!/usr/bin/env node +import { readFileSync } from "node:fs"; +import { createConnection } from "node:net"; +import { dirname, join } from "node:path"; +import { cwd } from "node:process"; +import { fileURLToPath } from "node:url"; +import type { RpcCommand, RpcExtensionUIResponse } from "@earendil-works/pi-coding-agent"; +import { getSocketPath } from "./config.ts"; +import { sendIpcRequest } from "./ipc/client.ts"; +import { encodeMessage } from "./ipc/protocol.ts"; +import { serve } from "./serve.ts"; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); +const packageJson = JSON.parse(readFileSync(join(__dirname, "../package.json"), "utf-8")) as { + version: string; +}; + +function printHelp(): void { + console.log( + `orchestrator v${packageJson.version}\n\nUsage:\n orchestrator serve\n orchestrator list\n orchestrator spawn [--cwd ] [--label