@giladbarnea/pi-simple-team 2.0.13 → 2.0.15

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 +25 -11
  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, getPackageDir } from "@earendil-works/pi-coding-agent";
8
+ import { defineTool, type ContextUsage, type ExtensionAPI, type ExtensionContext, 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";
@@ -635,12 +635,17 @@ function manifestMemberFromTeammate(teammate: TeammateState): TeamManifestMember
635
635
  };
636
636
  }
637
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
+
638
643
  function persistActiveTeamManifest(team: TeamState): void {
639
644
  if (!team.manifest || !teams.has(team.id ?? team.name)) return;
640
645
  const updatedAt = new Date().toISOString();
641
646
  team.manifest = {
642
647
  ...team.manifest,
643
- members: [...team.members.values()].map(manifestMemberFromTeammate),
648
+ members: registeredManifestMembers(team),
644
649
  state: "active",
645
650
  updatedAt,
646
651
  shutdownAt: undefined,
@@ -702,7 +707,7 @@ async function shutdownTeam(team: TeamState): Promise<string[]> {
702
707
  const shutdownAt = new Date().toISOString();
703
708
  team.manifest = {
704
709
  ...team.manifest,
705
- members: [...team.members.values()].map(manifestMemberFromTeammate),
710
+ members: registeredManifestMembers(team),
706
711
  state: "dormant",
707
712
  updatedAt: shutdownAt,
708
713
  shutdownAt,
@@ -998,6 +1003,18 @@ export default function (pi: ExtensionAPI) {
998
1003
  const owner = Symbol("pi-simple-team-owner");
999
1004
  const reminderTimers = new Set<ReturnType<typeof setTimeout>>();
1000
1005
  const sessionTeammateRoster = childRuntimeConfig?.participants ?? [];
1006
+
1007
+ /** Current-project manifests that team_resume can select: all for main, only its own for a managing teammate. */
1008
+ function resumableTeamManifests(context: ExtensionContext, toolName: string): TeamManifest[] {
1009
+ const projectDirectory = context.sessionManager?.getCwd?.() ?? context.cwd;
1010
+ if (!projectDirectory) throw new Error(`${toolName} requires a project directory`);
1011
+ const managerSessionId = childRuntimeConfig ? context.sessionManager?.getSessionId?.() : undefined;
1012
+ if (childRuntimeConfig && !managerSessionId) throw new Error(`${toolName} requires a persistent managing teammate Pi session`);
1013
+ return listTeamManifests(projectDirectory).manifests.filter(
1014
+ (candidate) => !managerSessionId || candidate.originMainSessionId === managerSessionId,
1015
+ );
1016
+ }
1017
+
1001
1018
  pi.registerMessageRenderer(teamMessageType, (message, options, theme) => renderTeamMessage(message, options, theme, getMarkdownTheme(), sessionTeammateRoster));
1002
1019
 
1003
1020
  pi.registerCommand("team", {
@@ -1224,14 +1241,7 @@ export default function (pi: ExtensionAPI) {
1224
1241
  }, { additionalProperties: false }),
1225
1242
  async execute(_toolCallId, params, signal, _onUpdate, context) {
1226
1243
  signal?.throwIfAborted();
1227
- const rawProjectDirectory = context.sessionManager?.getCwd?.() ?? context.cwd;
1228
- if (!rawProjectDirectory) throw new Error("team_resume requires a project directory");
1229
- const managerSessionId = childRuntimeConfig ? context.sessionManager?.getSessionId?.() : undefined;
1230
- if (childRuntimeConfig && !managerSessionId) throw new Error("team_resume requires a persistent managing teammate Pi session");
1231
- const availableManifests = listTeamManifests(rawProjectDirectory).manifests.filter(
1232
- (candidate) => !managerSessionId || candidate.originMainSessionId === managerSessionId,
1233
- );
1234
- const manifest = resolveTeamIdentifier(availableManifests, params.team);
1244
+ const manifest = resolveTeamIdentifier(resumableTeamManifests(context, "team_resume"), params.team);
1235
1245
  if (!manifest) throw new Error(`Unknown current-project team: ${JSON.stringify(params.team)}. Call team_list and pass a listed teamId or unique teamName in the team parameter.`);
1236
1246
  const members = manifest.members;
1237
1247
  const requestedNames = resolveTeammates(members, params.teammates ?? members.map((member) => member.teammateId)).map((member) => member.name);
@@ -1334,6 +1344,9 @@ export default function (pi: ExtensionAPI) {
1334
1344
  }, { additionalProperties: false }),
1335
1345
  async execute(_toolCallId, params, signal, _onUpdate, context) {
1336
1346
  signal?.throwIfAborted();
1347
+ const ownsSelectedTeam = !params.team || resolveTeamIdentifier([...teams.values()].filter((team) => team.owner === owner), params.team);
1348
+ const stoppedTeam = ownsSelectedTeam ? undefined : resolveTeamIdentifier(resumableTeamManifests(context, "team_add_teammates").filter((manifest) => manifest.state === "dormant"), params.team!);
1349
+ if (stoppedTeam) throw new Error(`Team "${stoppedTeam.name}" (team ID: ${stoppedTeam.id}) is stopped. Resume it with team_resume before adding teammates.`);
1337
1350
  const team = resolveTeam(owner, params.team);
1338
1351
  if (!team || !team.manifest || !team.lease || team.manifest.state !== "active") {
1339
1352
  throw new Error(`team_add_teammates requires a running team owned by this main session: ${params.team}`);
@@ -1377,6 +1390,7 @@ export default function (pi: ExtensionAPI) {
1377
1390
  team.members.delete(teammate.name);
1378
1391
  team.statuses.delete(teammate.name);
1379
1392
  }
1393
+ persistActiveTeamManifest(team);
1380
1394
  throw error;
1381
1395
  }
1382
1396
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@giladbarnea/pi-simple-team",
3
- "version": "2.0.13",
3
+ "version": "2.0.15",
4
4
  "description": "A flat, live team of Pi agents.",
5
5
  "keywords": [
6
6
  "pi-package",