@h-rig/cli 0.0.6-alpha.21 → 0.0.6-alpha.23

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.
@@ -189,79 +189,6 @@ async function requestServerJson(context, pathname, init = {}) {
189
189
  return payload;
190
190
  }
191
191
 
192
- // packages/cli/src/commands/_pi-install.ts
193
- import { existsSync as existsSync3, readFileSync as readFileSync3, rmSync } from "fs";
194
- import { homedir as homedir2 } from "os";
195
- import { resolve as resolve3 } from "path";
196
- var PI_RIG_PACKAGE_NAME = "@h-rig/pi-rig";
197
- var LEGACY_PI_RIG_PACKAGE_NAME = "@rig/pi-rig";
198
- async function defaultCommandRunner(command, options = {}) {
199
- const proc = Bun.spawn(command, { cwd: options.cwd, stdout: "pipe", stderr: "pipe" });
200
- const [stdout, stderr, exitCode] = await Promise.all([
201
- new Response(proc.stdout).text(),
202
- new Response(proc.stderr).text(),
203
- proc.exited
204
- ]);
205
- return { exitCode, stdout, stderr };
206
- }
207
- function resolvePiRigExtensionPath(homeDir) {
208
- return resolve3(homeDir, ".pi", "agent", "extensions", "pi-rig");
209
- }
210
- function resolvePiHomeDir(inputHomeDir) {
211
- return inputHomeDir ?? process.env.RIG_PI_HOME_DIR?.trim() ?? homedir2();
212
- }
213
- function piListContainsPiRig(output) {
214
- return output.split(/\r?\n/).some((line) => {
215
- const normalized = line.trim();
216
- return normalized.includes(PI_RIG_PACKAGE_NAME) || normalized.includes(LEGACY_PI_RIG_PACKAGE_NAME) || /(?:^|[\\/])packages[\\/]pi-rig(?:$|\s)/.test(normalized);
217
- });
218
- }
219
- async function safeRun(runner, command, options) {
220
- try {
221
- return await runner(command, options);
222
- } catch (error) {
223
- return { exitCode: 1, stdout: "", stderr: error instanceof Error ? error.message : String(error) };
224
- }
225
- }
226
- async function checkPiRigInstall(input = {}) {
227
- const home = resolvePiHomeDir(input.homeDir);
228
- const extensionPath = resolvePiRigExtensionPath(home);
229
- if (process.env.RIG_TEST_FAKE_PI_INSTALL === "1") {
230
- return {
231
- extensionPath,
232
- pi: { ok: true, label: "pi", detail: "fake-pi" },
233
- piRig: { ok: true, label: "pi-rig global extension", detail: extensionPath }
234
- };
235
- }
236
- const exists = input.exists ?? existsSync3;
237
- const runner = input.commandRunner ?? defaultCommandRunner;
238
- const piResult = await safeRun(runner, ["pi", "--version"]);
239
- const piListResult = piResult.exitCode === 0 ? await safeRun(runner, ["pi", "list"]) : { exitCode: 1, stdout: "", stderr: "" };
240
- const listedPiRig = piListResult.exitCode === 0 && piListContainsPiRig(`${piListResult.stdout}
241
- ${piListResult.stderr}`);
242
- const legacyBridge = exists(resolve3(extensionPath, "index.ts"));
243
- const hasPiRig = listedPiRig;
244
- return {
245
- extensionPath,
246
- pi: {
247
- ok: piResult.exitCode === 0,
248
- label: "pi",
249
- detail: (piResult.stdout || piResult.stderr).trim() || undefined,
250
- hint: piResult.exitCode === 0 ? undefined : "Install Pi or run `rig init --yes` to install/update the Pi runtime."
251
- },
252
- piRig: {
253
- ok: hasPiRig,
254
- label: "pi-rig global extension",
255
- detail: hasPiRig ? piListResult.stdout.trim() || PI_RIG_PACKAGE_NAME : legacyBridge ? `${extensionPath} (legacy bridge; reinstall required)` : undefined,
256
- hint: hasPiRig ? undefined : "Run `rig init --yes` to install/enable the global pi-rig package with `pi install`."
257
- }
258
- };
259
- }
260
- async function buildPiSetupChecks(input = {}) {
261
- const status = await checkPiRigInstall(input);
262
- return [status.pi, status.piRig];
263
- }
264
-
265
192
  // packages/cli/src/commands/_preflight.ts
266
193
  function preflightCheck(id, label, status, detail, remediation) {
267
194
  return {
@@ -419,14 +346,7 @@ async function runFastTaskRunPreflight(context, options = {}) {
419
346
  }
420
347
  }
421
348
  if ((options.runtimeAdapter ?? "pi") === "pi") {
422
- const piChecks = await (options.piChecks ?? (() => buildPiSetupChecks()))().catch((error) => [{
423
- ok: false,
424
- label: "pi/pi-rig checks",
425
- hint: message(error)
426
- }]);
427
- for (const pi of piChecks) {
428
- checks.push(preflightCheck(pi.label === "pi" ? "pi" : "pi-rig", pi.label, pi.ok ? "pass" : "fail", pi.detail, pi.hint ?? (pi.ok ? undefined : "Run `rig init --yes` to install/update Pi and enable pi-rig.")));
429
- }
349
+ checks.push(preflightCheck("runtime", "worker Pi SDK session daemon", "pass", selectedServer?.connectionKind === "remote" ? "remote worker-owned runtime" : "bundled server-owned runtime"));
430
350
  } else {
431
351
  checks.push(preflightCheck("runtime", "runtime adapter", "pass", options.runtimeAdapter));
432
352
  }
@@ -378,6 +378,74 @@ async function steerRunViaServer(context, runId, message) {
378
378
  });
379
379
  return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { ok: true };
380
380
  }
381
+ async function getRunPiSessionViaServer(context, runId) {
382
+ const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/pi`);
383
+ return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : {};
384
+ }
385
+ async function getRunPiMessagesViaServer(context, runId) {
386
+ const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/pi/messages`);
387
+ return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { messages: [] };
388
+ }
389
+ async function getRunPiStatusViaServer(context, runId) {
390
+ const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/pi/status`);
391
+ return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : {};
392
+ }
393
+ async function getRunPiCommandsViaServer(context, runId) {
394
+ const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/pi/commands`);
395
+ return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { commands: [] };
396
+ }
397
+ async function sendRunPiPromptViaServer(context, runId, text, streamingBehavior) {
398
+ const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/pi/prompt`, {
399
+ method: "POST",
400
+ headers: { "content-type": "application/json" },
401
+ body: JSON.stringify({ text, streamingBehavior })
402
+ });
403
+ return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { accepted: true };
404
+ }
405
+ async function sendRunPiShellViaServer(context, runId, text) {
406
+ const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/pi/shell`, {
407
+ method: "POST",
408
+ headers: { "content-type": "application/json" },
409
+ body: JSON.stringify({ text })
410
+ });
411
+ return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { accepted: true };
412
+ }
413
+ async function runRunPiCommandViaServer(context, runId, text) {
414
+ const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/pi/commands/run`, {
415
+ method: "POST",
416
+ headers: { "content-type": "application/json" },
417
+ body: JSON.stringify({ text })
418
+ });
419
+ return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { type: "done" };
420
+ }
421
+ async function respondRunPiCommandViaServer(context, runId, requestId, value) {
422
+ const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/pi/commands/respond`, {
423
+ method: "POST",
424
+ headers: { "content-type": "application/json" },
425
+ body: JSON.stringify({ requestId, value })
426
+ });
427
+ return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { type: "done" };
428
+ }
429
+ async function respondRunPiExtensionUiViaServer(context, runId, requestId, valueOrCancel) {
430
+ const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/pi/extension-ui/respond`, {
431
+ method: "POST",
432
+ headers: { "content-type": "application/json" },
433
+ body: JSON.stringify({ requestId, ...valueOrCancel })
434
+ });
435
+ return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { accepted: true };
436
+ }
437
+ async function abortRunPiViaServer(context, runId) {
438
+ const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/pi/abort`, { method: "POST" });
439
+ return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { aborted: true };
440
+ }
441
+ async function buildRunPiEventsWebSocketUrl(context, runId) {
442
+ const server = await ensureServerForCli(context.projectRoot);
443
+ const url = new URL(`${server.baseUrl.replace(/\/+$/, "")}/api/runs/${encodeURIComponent(runId)}/pi/events`);
444
+ url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
445
+ if (server.authToken)
446
+ url.searchParams.set("token", server.authToken);
447
+ return url.toString();
448
+ }
381
449
  async function submitTaskRunViaServer(context, input) {
382
450
  const isTaskRun = Boolean(input.taskId);
383
451
  const endpoint = isTaskRun ? "/api/runs/task" : "/api/runs/adhoc";
@@ -416,7 +484,12 @@ export {
416
484
  stopRunViaServer,
417
485
  steerRunViaServer,
418
486
  setGitHubBearerTokenForCurrentProcess,
487
+ sendRunPiShellViaServer,
488
+ sendRunPiPromptViaServer,
419
489
  selectNextWorkspaceTaskViaServer,
490
+ runRunPiCommandViaServer,
491
+ respondRunPiExtensionUiViaServer,
492
+ respondRunPiCommandViaServer,
420
493
  requestServerJson,
421
494
  registerProjectViaServer,
422
495
  prepareRemoteCheckoutViaServer,
@@ -426,10 +499,16 @@ export {
426
499
  listGitHubProjectsViaServer,
427
500
  getWorkspaceTaskViaServer,
428
501
  getRunTimelineViaServer,
502
+ getRunPiStatusViaServer,
503
+ getRunPiSessionViaServer,
504
+ getRunPiMessagesViaServer,
505
+ getRunPiCommandsViaServer,
429
506
  getRunLogsViaServer,
430
507
  getRunDetailsViaServer,
431
508
  getGitHubProjectStatusFieldViaServer,
432
509
  getGitHubAuthStatusViaServer,
433
510
  ensureTaskLabelsViaServer,
434
- ensureServerForCli
511
+ ensureServerForCli,
512
+ buildRunPiEventsWebSocketUrl,
513
+ abortRunPiViaServer
435
514
  };