@giladbarnea/pi-simple-team 2.0.12 → 2.0.14
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 +30 -12
- 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",
|
|
@@ -634,12 +635,17 @@ function manifestMemberFromTeammate(teammate: TeammateState): TeamManifestMember
|
|
|
634
635
|
};
|
|
635
636
|
}
|
|
636
637
|
|
|
638
|
+
/** A teammate that is still starting has no session identity yet. It joins the manifest after it registers, so it cannot fail bookkeeping for its siblings. */
|
|
639
|
+
function registeredManifestMembers(team: TeamState): TeamManifestMember[] {
|
|
640
|
+
return [...team.members.values()].filter((teammate) => teammate.sessionId).map(manifestMemberFromTeammate);
|
|
641
|
+
}
|
|
642
|
+
|
|
637
643
|
function persistActiveTeamManifest(team: TeamState): void {
|
|
638
644
|
if (!team.manifest || !teams.has(team.id ?? team.name)) return;
|
|
639
645
|
const updatedAt = new Date().toISOString();
|
|
640
646
|
team.manifest = {
|
|
641
647
|
...team.manifest,
|
|
642
|
-
members:
|
|
648
|
+
members: registeredManifestMembers(team),
|
|
643
649
|
state: "active",
|
|
644
650
|
updatedAt,
|
|
645
651
|
shutdownAt: undefined,
|
|
@@ -701,7 +707,7 @@ async function shutdownTeam(team: TeamState): Promise<string[]> {
|
|
|
701
707
|
const shutdownAt = new Date().toISOString();
|
|
702
708
|
team.manifest = {
|
|
703
709
|
...team.manifest,
|
|
704
|
-
members:
|
|
710
|
+
members: registeredManifestMembers(team),
|
|
705
711
|
state: "dormant",
|
|
706
712
|
updatedAt: shutdownAt,
|
|
707
713
|
shutdownAt,
|
|
@@ -925,11 +931,11 @@ function teammateSchema(modelGuidance: string) {
|
|
|
925
931
|
}, { additionalProperties: false });
|
|
926
932
|
}
|
|
927
933
|
|
|
928
|
-
function restoreTeamState(owner: symbol, ownerPi: ExtensionAPI,
|
|
934
|
+
function restoreTeamState(owner: symbol, ownerPi: ExtensionAPI, parentPiCommand: string[], manifest: TeamManifest, lease: TeamLease): TeamState {
|
|
929
935
|
const team: TeamState = {
|
|
930
936
|
owner,
|
|
931
937
|
ownerPi,
|
|
932
|
-
|
|
938
|
+
parentPiCommand,
|
|
933
939
|
id: manifest.id,
|
|
934
940
|
name: manifest.name,
|
|
935
941
|
projectDirectory: manifest.projectDirectory,
|
|
@@ -974,6 +980,18 @@ function sessionFileForResume(teammate: TeammateState): string | undefined {
|
|
|
974
980
|
return undefined;
|
|
975
981
|
}
|
|
976
982
|
|
|
983
|
+
/**
|
|
984
|
+
* The command that starts another instance of the Pi running this extension, for RPC and Herdr teammates.
|
|
985
|
+
* 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.
|
|
986
|
+
* 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.
|
|
987
|
+
* @example piCommand("/$bunfs/root/pi", "/opt/pi/pi", "/opt/pi") // ["/opt/pi/pi"]
|
|
988
|
+
*/
|
|
989
|
+
function piCommand(entry: string, runtime: string, packageDirectory: string): string[] {
|
|
990
|
+
if (/\$bunfs|~BUN/.test(entry)) return [runtime];
|
|
991
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(packageDirectory, "package.json"), "utf8")) as { bin: { pi: string } };
|
|
992
|
+
return [path.join(packageDirectory, manifest.bin.pi)];
|
|
993
|
+
}
|
|
994
|
+
|
|
977
995
|
export default function (pi: ExtensionAPI) {
|
|
978
996
|
const childRuntimeConfig = readChildRuntimeConfig();
|
|
979
997
|
if (childRuntimeConfig) {
|
|
@@ -981,8 +999,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
981
999
|
if (!childRuntimeConfig.canManageOwnTeams) return;
|
|
982
1000
|
}
|
|
983
1001
|
|
|
984
|
-
const
|
|
985
|
-
if (!parentPiExecutable) throw new Error("pi-simple-team could not locate the parent Pi executable");
|
|
1002
|
+
const parentPiCommand = piCommand(process.argv[1], process.execPath, getPackageDir());
|
|
986
1003
|
const owner = Symbol("pi-simple-team-owner");
|
|
987
1004
|
const reminderTimers = new Set<ReturnType<typeof setTimeout>>();
|
|
988
1005
|
const sessionTeammateRoster = childRuntimeConfig?.participants ?? [];
|
|
@@ -1064,7 +1081,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
1064
1081
|
const team: TeamState = {
|
|
1065
1082
|
owner,
|
|
1066
1083
|
ownerPi: pi,
|
|
1067
|
-
|
|
1084
|
+
parentPiCommand,
|
|
1068
1085
|
id: teamId,
|
|
1069
1086
|
name: teamName,
|
|
1070
1087
|
projectDirectory,
|
|
@@ -1238,7 +1255,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
1238
1255
|
const lease = claimTeamLease(manifest.id, mainSessionId);
|
|
1239
1256
|
try {
|
|
1240
1257
|
await ensureCallbackServer();
|
|
1241
|
-
team = restoreTeamState(owner, pi,
|
|
1258
|
+
team = restoreTeamState(owner, pi, parentPiCommand, manifest, lease);
|
|
1242
1259
|
teams.set(team.id!, team);
|
|
1243
1260
|
} catch (error) {
|
|
1244
1261
|
releaseTeamLease(lease);
|
|
@@ -1365,6 +1382,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
1365
1382
|
team.members.delete(teammate.name);
|
|
1366
1383
|
team.statuses.delete(teammate.name);
|
|
1367
1384
|
}
|
|
1385
|
+
persistActiveTeamManifest(team);
|
|
1368
1386
|
throw error;
|
|
1369
1387
|
}
|
|
1370
1388
|
|