@oversk7/pi-web-dsh-style 1.0.1 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/pi-rpc.ts CHANGED
@@ -4,6 +4,7 @@ import { existsSync, readFileSync } from "node:fs";
4
4
  import { join, resolve } from "node:path";
5
5
  import { fileURLToPath } from "node:url";
6
6
  import { getPackageDir } from "@earendil-works/pi-coding-agent";
7
+ import { terminalProxyEnv, type TerminalProxySettings } from "./terminal-proxy.ts";
7
8
 
8
9
  export type Json = Record<string, any>;
9
10
 
@@ -72,6 +73,7 @@ export interface PiRpcSpawnOptions {
72
73
  sessionFile?: string;
73
74
  name?: string;
74
75
  noSession?: boolean;
76
+ proxy?: TerminalProxySettings;
75
77
  }
76
78
 
77
79
  export function spawnPiRpc(options: PiRpcSpawnOptions): PiRpc {
@@ -95,7 +97,7 @@ export function spawnPiRpc(options: PiRpcSpawnOptions): PiRpc {
95
97
  const child = spawn(executable, childArgs, {
96
98
  cwd: options.cwd,
97
99
  env: {
98
- ...process.env, NO_COLOR: "1", PI_TELEMETRY: "0",
100
+ ...(options.proxy ? terminalProxyEnv(options.proxy) : process.env), NO_COLOR: "1", PI_TELEMETRY: "0",
99
101
  ...(windows ? { PI_WEB_RPC_JOB: JSON.stringify({ ownerPid: process.pid, executable: process.execPath, args: [launch.entry, ...args], cwd: options.cwd }) } : {}),
100
102
  },
101
103
  stdio: ["pipe", "pipe", "pipe"],
@@ -160,8 +162,8 @@ export function spawnPiRpc(options: PiRpcSpawnOptions): PiRpc {
160
162
  console.error(`[pi-web rpc stderr] ${text}`);
161
163
  };
162
164
 
163
- child.stderr?.on("data", (chunk: Buffer) => {
164
- stderrBuffer += chunk.toString("utf8");
165
+ child.stderr?.setEncoding("utf8").on("data", (chunk: string) => {
166
+ stderrBuffer += chunk;
165
167
  let idx: number;
166
168
  while ((idx = stderrBuffer.indexOf("\n")) >= 0) {
167
169
  logStderrLine(stderrBuffer.slice(0, idx));
@@ -173,8 +175,8 @@ export function spawnPiRpc(options: PiRpcSpawnOptions): PiRpc {
173
175
  stderrBuffer = "";
174
176
  });
175
177
 
176
- child.stdout?.on("data", (chunk: Buffer) => {
177
- buffer += chunk.toString("utf8");
178
+ child.stdout?.setEncoding("utf8").on("data", (chunk: string) => {
179
+ buffer += chunk;
178
180
  let idx: number;
179
181
  while ((idx = buffer.indexOf("\n")) >= 0) {
180
182
  let line = buffer.slice(0, idx);