@giladbarnea/pi-simple-team 2.0.11 → 2.0.13

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.
Files changed (2) hide show
  1. package/index.ts +33 -14
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -5,7 +5,7 @@ import * as fs from "node:fs";
5
5
  import http from "node:http";
6
6
  import * as path from "node:path";
7
7
  import { fileURLToPath } from "node:url";
8
- import { defineTool, type ContextUsage, type ExtensionAPI, getMarkdownTheme } from "@earendil-works/pi-coding-agent";
8
+ import { defineTool, type ContextUsage, type ExtensionAPI, getMarkdownTheme, getPackageDir } from "@earendil-works/pi-coding-agent";
9
9
  import { formatContextWindowReport, requireKnownContextUsage, type KnownContextUsage } from "./context-window.ts";
10
10
  import { formatScopedModelGuidance, validateTeammateModels, type ModelReference } from "./model-preflight.ts";
11
11
  import { composeTeamBriefing } from "./team-briefing.ts";
@@ -71,7 +71,7 @@ interface TeammateState {
71
71
  interface TeamState {
72
72
  owner: symbol;
73
73
  ownerPi: ExtensionAPI;
74
- parentPiExecutable: string;
74
+ parentPiCommand: string[];
75
75
  id?: string;
76
76
  name: string;
77
77
  projectDirectory?: string;
@@ -494,13 +494,21 @@ interface ChildStartOptions {
494
494
  signal?: AbortSignal;
495
495
  }
496
496
 
497
+ /**
498
+ * Resume lets Pi restore the session's model. It passes the saved thinking level because Pi records `--thinking` only in a new session, so a fork keeps main's level.
499
+ * @example launchSettingArguments({ model: "openai-codex/gpt-6-luna", thinking: "xhigh" }, { sessionFile: "/sessions/a.jsonl" }) // ["--thinking", "xhigh"]
500
+ */
501
+ function launchSettingArguments(teammate: Pick<TeammateState, "model" | "thinking">, options: ChildStartOptions): string[] {
502
+ const thinkingArguments = ["--thinking", teammate.thinking];
503
+ return options.sessionFile ? thinkingArguments : ["--model", teammate.model, ...thinkingArguments];
504
+ }
505
+
497
506
  function attachRpcTeammate(team: TeamState, teammate: TeammateState, participants: string[], options: ChildStartOptions): void {
498
507
  const sessionArgs = options.sessionFile
499
508
  ? ["--session", options.sessionFile]
500
509
  : teammate.forkContext && !options.restartEmpty
501
510
  ? ["--fork", team.mainSessionFile!]
502
511
  : [];
503
- const modelArgs = options.sessionFile ? [] : ["--model", teammate.model, "--thinking", teammate.thinking];
504
512
  const args = [
505
513
  "--mode",
506
514
  "rpc",
@@ -511,9 +519,10 @@ function attachRpcTeammate(team: TeamState, teammate: TeammateState, participant
511
519
  ...teammate.extensionPaths.flatMap(extensionPath => ["-e", extensionPath]),
512
520
  "--no-prompt-templates",
513
521
  "--no-themes",
514
- ...modelArgs,
522
+ ...launchSettingArguments(teammate, options),
515
523
  ];
516
- const proc = childProcess.spawn(team.parentPiExecutable, args, {
524
+ const [executable, ...piArguments] = team.parentPiCommand;
525
+ const proc = childProcess.spawn(executable, [...piArguments, ...args], {
517
526
  cwd: team.projectDirectory ?? process.cwd(),
518
527
  stdio: ["pipe", "ignore", "pipe"],
519
528
  env: { ...process.env, ...childEnvironmentOverrides(team, teammate, participants) },
@@ -559,7 +568,6 @@ async function attachHerdrTeammate(
559
568
  : teammate.forkContext && !options.restartEmpty
560
569
  ? ["--fork", team.mainSessionFile!]
561
570
  : [];
562
- const modelArgs = options.sessionFile ? [] : ["--model", teammate.model, "--thinking", teammate.thinking];
563
571
  const args = ["pane", "split", "--pane", herdrParentPaneId, "--direction", "right", "--no-focus", "--cwd", team.projectDirectory ?? process.cwd()];
564
572
  for (const [name, value] of Object.entries(environment)) {
565
573
  if (value !== undefined) args.push("--env", `${name}=${value}`);
@@ -568,13 +576,13 @@ async function attachHerdrTeammate(
568
576
  teammate.paneId = parseHerdrPaneId(result.stdout, teammate.name);
569
577
  await runCommand("herdr", ["pane", "rename", teammate.paneId, teammate.name]);
570
578
  const command = [
571
- team.parentPiExecutable,
579
+ ...team.parentPiCommand,
572
580
  ...sessionArgs,
573
581
  "--no-extensions",
574
582
  "-e",
575
583
  teamLiteExtensionPath,
576
584
  ...teammate.extensionPaths.flatMap(extensionPath => ["-e", extensionPath]),
577
- ...modelArgs,
585
+ ...launchSettingArguments(teammate, options),
578
586
  ].map(shellQuote).join(" ");
579
587
  await runCommand("herdr", ["pane", "run", teammate.paneId, command]);
580
588
  appendSpawnLog(team, teammate);
@@ -918,11 +926,11 @@ function teammateSchema(modelGuidance: string) {
918
926
  }, { additionalProperties: false });
919
927
  }
920
928
 
921
- function restoreTeamState(owner: symbol, ownerPi: ExtensionAPI, parentPiExecutable: string, manifest: TeamManifest, lease: TeamLease): TeamState {
929
+ function restoreTeamState(owner: symbol, ownerPi: ExtensionAPI, parentPiCommand: string[], manifest: TeamManifest, lease: TeamLease): TeamState {
922
930
  const team: TeamState = {
923
931
  owner,
924
932
  ownerPi,
925
- parentPiExecutable,
933
+ parentPiCommand,
926
934
  id: manifest.id,
927
935
  name: manifest.name,
928
936
  projectDirectory: manifest.projectDirectory,
@@ -967,6 +975,18 @@ function sessionFileForResume(teammate: TeammateState): string | undefined {
967
975
  return undefined;
968
976
  }
969
977
 
978
+ /**
979
+ * The command that starts another instance of the Pi running this extension, for RPC and Herdr teammates.
980
+ * A Bun standalone Pi is its own executable and reports an embedded entry. Otherwise, including in an SDK host, it is the Pi package's CLI script.
981
+ * The script's `env node` shebang finds the runtime at each start, so a removed runtime path, such as an upgraded Homebrew keg, cannot break later starts.
982
+ * @example piCommand("/$bunfs/root/pi", "/opt/pi/pi", "/opt/pi") // ["/opt/pi/pi"]
983
+ */
984
+ function piCommand(entry: string, runtime: string, packageDirectory: string): string[] {
985
+ if (/\$bunfs|~BUN/.test(entry)) return [runtime];
986
+ const manifest = JSON.parse(fs.readFileSync(path.join(packageDirectory, "package.json"), "utf8")) as { bin: { pi: string } };
987
+ return [path.join(packageDirectory, manifest.bin.pi)];
988
+ }
989
+
970
990
  export default function (pi: ExtensionAPI) {
971
991
  const childRuntimeConfig = readChildRuntimeConfig();
972
992
  if (childRuntimeConfig) {
@@ -974,8 +994,7 @@ export default function (pi: ExtensionAPI) {
974
994
  if (!childRuntimeConfig.canManageOwnTeams) return;
975
995
  }
976
996
 
977
- const parentPiExecutable = process.argv[1];
978
- if (!parentPiExecutable) throw new Error("pi-simple-team could not locate the parent Pi executable");
997
+ const parentPiCommand = piCommand(process.argv[1], process.execPath, getPackageDir());
979
998
  const owner = Symbol("pi-simple-team-owner");
980
999
  const reminderTimers = new Set<ReturnType<typeof setTimeout>>();
981
1000
  const sessionTeammateRoster = childRuntimeConfig?.participants ?? [];
@@ -1057,7 +1076,7 @@ export default function (pi: ExtensionAPI) {
1057
1076
  const team: TeamState = {
1058
1077
  owner,
1059
1078
  ownerPi: pi,
1060
- parentPiExecutable,
1079
+ parentPiCommand,
1061
1080
  id: teamId,
1062
1081
  name: teamName,
1063
1082
  projectDirectory,
@@ -1231,7 +1250,7 @@ export default function (pi: ExtensionAPI) {
1231
1250
  const lease = claimTeamLease(manifest.id, mainSessionId);
1232
1251
  try {
1233
1252
  await ensureCallbackServer();
1234
- team = restoreTeamState(owner, pi, parentPiExecutable, manifest, lease);
1253
+ team = restoreTeamState(owner, pi, parentPiCommand, manifest, lease);
1235
1254
  teams.set(team.id!, team);
1236
1255
  } catch (error) {
1237
1256
  releaseTeamLease(lease);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@giladbarnea/pi-simple-team",
3
- "version": "2.0.11",
3
+ "version": "2.0.13",
4
4
  "description": "A flat, live team of Pi agents.",
5
5
  "keywords": [
6
6
  "pi-package",