@giladbarnea/pi-simple-team 2.0.12 → 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.
- package/index.ts +22 -10
- 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
|
-
|
|
74
|
+
parentPiCommand: string[];
|
|
75
75
|
id?: string;
|
|
76
76
|
name: string;
|
|
77
77
|
projectDirectory?: string;
|
|
@@ -521,7 +521,8 @@ function attachRpcTeammate(team: TeamState, teammate: TeammateState, participant
|
|
|
521
521
|
"--no-themes",
|
|
522
522
|
...launchSettingArguments(teammate, options),
|
|
523
523
|
];
|
|
524
|
-
const
|
|
524
|
+
const [executable, ...piArguments] = team.parentPiCommand;
|
|
525
|
+
const proc = childProcess.spawn(executable, [...piArguments, ...args], {
|
|
525
526
|
cwd: team.projectDirectory ?? process.cwd(),
|
|
526
527
|
stdio: ["pipe", "ignore", "pipe"],
|
|
527
528
|
env: { ...process.env, ...childEnvironmentOverrides(team, teammate, participants) },
|
|
@@ -575,7 +576,7 @@ async function attachHerdrTeammate(
|
|
|
575
576
|
teammate.paneId = parseHerdrPaneId(result.stdout, teammate.name);
|
|
576
577
|
await runCommand("herdr", ["pane", "rename", teammate.paneId, teammate.name]);
|
|
577
578
|
const command = [
|
|
578
|
-
team.
|
|
579
|
+
...team.parentPiCommand,
|
|
579
580
|
...sessionArgs,
|
|
580
581
|
"--no-extensions",
|
|
581
582
|
"-e",
|
|
@@ -925,11 +926,11 @@ function teammateSchema(modelGuidance: string) {
|
|
|
925
926
|
}, { additionalProperties: false });
|
|
926
927
|
}
|
|
927
928
|
|
|
928
|
-
function restoreTeamState(owner: symbol, ownerPi: ExtensionAPI,
|
|
929
|
+
function restoreTeamState(owner: symbol, ownerPi: ExtensionAPI, parentPiCommand: string[], manifest: TeamManifest, lease: TeamLease): TeamState {
|
|
929
930
|
const team: TeamState = {
|
|
930
931
|
owner,
|
|
931
932
|
ownerPi,
|
|
932
|
-
|
|
933
|
+
parentPiCommand,
|
|
933
934
|
id: manifest.id,
|
|
934
935
|
name: manifest.name,
|
|
935
936
|
projectDirectory: manifest.projectDirectory,
|
|
@@ -974,6 +975,18 @@ function sessionFileForResume(teammate: TeammateState): string | undefined {
|
|
|
974
975
|
return undefined;
|
|
975
976
|
}
|
|
976
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
|
+
|
|
977
990
|
export default function (pi: ExtensionAPI) {
|
|
978
991
|
const childRuntimeConfig = readChildRuntimeConfig();
|
|
979
992
|
if (childRuntimeConfig) {
|
|
@@ -981,8 +994,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
981
994
|
if (!childRuntimeConfig.canManageOwnTeams) return;
|
|
982
995
|
}
|
|
983
996
|
|
|
984
|
-
const
|
|
985
|
-
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());
|
|
986
998
|
const owner = Symbol("pi-simple-team-owner");
|
|
987
999
|
const reminderTimers = new Set<ReturnType<typeof setTimeout>>();
|
|
988
1000
|
const sessionTeammateRoster = childRuntimeConfig?.participants ?? [];
|
|
@@ -1064,7 +1076,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
1064
1076
|
const team: TeamState = {
|
|
1065
1077
|
owner,
|
|
1066
1078
|
ownerPi: pi,
|
|
1067
|
-
|
|
1079
|
+
parentPiCommand,
|
|
1068
1080
|
id: teamId,
|
|
1069
1081
|
name: teamName,
|
|
1070
1082
|
projectDirectory,
|
|
@@ -1238,7 +1250,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
1238
1250
|
const lease = claimTeamLease(manifest.id, mainSessionId);
|
|
1239
1251
|
try {
|
|
1240
1252
|
await ensureCallbackServer();
|
|
1241
|
-
team = restoreTeamState(owner, pi,
|
|
1253
|
+
team = restoreTeamState(owner, pi, parentPiCommand, manifest, lease);
|
|
1242
1254
|
teams.set(team.id!, team);
|
|
1243
1255
|
} catch (error) {
|
|
1244
1256
|
releaseTeamLease(lease);
|