fix: RPC parity, UX polish, logging
This commit is contained in:
@@ -18,7 +18,7 @@ const packageJson = JSON.parse(readFileSync(join(__dirname, "../package.json"),
|
||||
|
||||
function printHelp(): void {
|
||||
console.log(
|
||||
`orchestrator v${packageJson.version}\n\nUsage:\n orchestrator serve\n orchestrator list\n orchestrator spawn [--cwd <path>] [--label <label>]\n orchestrator status <instance-id>\n orchestrator stop <instance-id>\n orchestrator rpc <instance-id> <json-command>\n orchestrator attach <instance-id>\n orchestrator --help\n orchestrator --version`,
|
||||
`orchestrator v${packageJson.version}\n\nUsage:\n orchestrator serve\n orchestrator list\n orchestrator spawn [--cwd <path>] [--label <label>]\n orchestrator status <instance-id>\n orchestrator stop <instance-id>\n orchestrator rpc <instance-id> <json-command>\n orchestrator attach <instance-id>\n orchestrator --help\n orchestrator --version\n\nAttach stdin expects JSONL RpcCommand or extension_ui_response messages.`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ function getFlagValue(args: string[], flag: string): string | undefined {
|
||||
|
||||
async function attach(instanceId: string): Promise<void> {
|
||||
const socket = createConnection(getSocketPath());
|
||||
let stdinBuffer = "";
|
||||
process.stdin.setEncoding("utf8");
|
||||
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
@@ -49,6 +50,7 @@ async function attach(instanceId: string): Promise<void> {
|
||||
socket.on("data", (chunk: Buffer | string) => {
|
||||
process.stdout.write(chunk.toString());
|
||||
});
|
||||
console.error(`attached to ${instanceId}; send JSONL RpcCommand or extension_ui_response on stdin`);
|
||||
socket.on("error", (error) => {
|
||||
console.error(error instanceof Error ? error.message : String(error));
|
||||
process.exit(1);
|
||||
@@ -57,11 +59,17 @@ async function attach(instanceId: string): Promise<void> {
|
||||
process.exit(0);
|
||||
});
|
||||
process.stdin.on("data", (chunk: string) => {
|
||||
const lines = chunk
|
||||
.split("\n")
|
||||
.map((line) => line.trim())
|
||||
.filter((line) => line.length > 0);
|
||||
for (const line of lines) {
|
||||
stdinBuffer += chunk;
|
||||
while (true) {
|
||||
const newlineIndex = stdinBuffer.indexOf("\n");
|
||||
if (newlineIndex === -1) {
|
||||
return;
|
||||
}
|
||||
const line = stdinBuffer.slice(0, newlineIndex).trim();
|
||||
stdinBuffer = stdinBuffer.slice(newlineIndex + 1);
|
||||
if (!line) {
|
||||
continue;
|
||||
}
|
||||
const parsed = JSON.parse(line) as RpcCommand | RpcExtensionUIResponse;
|
||||
if (parsed.type === "extension_ui_response") {
|
||||
socket.write(encodeMessage(parsed));
|
||||
|
||||
Reference in New Issue
Block a user