@giladbarnea/pi-simple-team 1.0.43 → 1.0.44

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 +22 -9
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -225,13 +225,22 @@ function enqueueDelivery(team: TeamState, from: string, recipient: TeammateState
225
225
  });
226
226
  }
227
227
 
228
+ /** @example resolveTeamIdentifier([{ id: "main-review", name: "review" }], "review")?.id // "main-review" */
229
+ function resolveTeamIdentifier<IdentifiedTeam extends { id?: string; name: string }>(
230
+ candidates: Iterable<IdentifiedTeam>,
231
+ teamIdentifier: string,
232
+ ): IdentifiedTeam | undefined {
233
+ const matches = [...candidates].filter((team) => team.id === teamIdentifier || team.name === teamIdentifier);
234
+ if (matches.length > 1) throw new Error(`Ambiguous team name: ${teamIdentifier}. Pass the persistent team ID.`);
235
+ return matches[0];
236
+ }
237
+
228
238
  function resolveTeam(owner: symbol, teamIdentifier?: string): TeamState {
229
239
  const ownedTeams = [...teams.values()].filter((team) => team.owner === owner);
230
240
  if (teamIdentifier) {
231
- const matches = ownedTeams.filter((team) => team.id === teamIdentifier || team.name === teamIdentifier);
232
- if (matches.length === 0) throw new Error(`Unknown team: ${teamIdentifier}`);
233
- if (matches.length > 1) throw new Error(`Ambiguous team name: ${teamIdentifier}. Pass the persistent team ID.`);
234
- return matches[0]!;
241
+ const team = resolveTeamIdentifier(ownedTeams, teamIdentifier);
242
+ if (!team) throw new Error(`Unknown team: ${teamIdentifier}`);
243
+ return team;
235
244
  }
236
245
 
237
246
  if (ownedTeams.length === 1) return ownedTeams[0];
@@ -1073,7 +1082,7 @@ export default function (pi: ExtensionAPI) {
1073
1082
  renderCall: (args, theme, context) => renderTeamToolCall("team_resume", args, theme, context, sessionTeammateRoster),
1074
1083
  renderResult: (result, options, theme, context) => renderTeamToolResult("team_resume", result, options, theme, context, undefined, sessionTeammateRoster),
1075
1084
  parameters: Type.Object({
1076
- team: Type.String({ description: "Persistent team ID" }),
1085
+ team: Type.String({ description: "Team name or persistent ID" }),
1077
1086
  teammates: Type.Optional(Type.Array(Type.String({ minLength: 1 }), { minItems: 1, description: "Stopped teammate names. Omit to resume all stopped teammates." })),
1078
1087
  showOnHerdrPanes: Type.Optional(Type.Boolean({ default: false, description: "Resume selected teammates in visible Herdr panes. Defaults to RPC." })),
1079
1088
  }),
@@ -1082,9 +1091,10 @@ export default function (pi: ExtensionAPI) {
1082
1091
  if (!rawProjectDirectory) throw new Error("team_resume requires a project directory");
1083
1092
  const managerSessionId = childRuntimeConfig ? context.sessionManager?.getSessionId?.() : undefined;
1084
1093
  if (childRuntimeConfig && !managerSessionId) throw new Error("team_resume requires a persistent overseeing teammate session");
1085
- const manifest = listTeamManifests(rawProjectDirectory).find(
1086
- (candidate) => candidate.id === params.team && (!managerSessionId || candidate.originMainSessionId === managerSessionId),
1094
+ const availableManifests = listTeamManifests(rawProjectDirectory).filter(
1095
+ (candidate) => !managerSessionId || candidate.originMainSessionId === managerSessionId,
1087
1096
  );
1097
+ const manifest = resolveTeamIdentifier(availableManifests, params.team);
1088
1098
  if (!manifest) throw new Error(`Unknown current-project team: ${params.team}`);
1089
1099
  const requestedNames = params.teammates?.map(compactName) ?? manifest.members.map((member) => member.name);
1090
1100
  const duplicateNames = requestedNames.filter((name, index) => requestedNames.indexOf(name) !== index);
@@ -1183,11 +1193,14 @@ export default function (pi: ExtensionAPI) {
1183
1193
  renderCall: (args, theme, context) => renderTeamToolCall("team_add", args, theme, context, sessionTeammateRoster),
1184
1194
  renderResult: (result, options, theme, context) => renderTeamToolResult("team_add", result, options, theme, context, undefined, sessionTeammateRoster),
1185
1195
  parameters: Type.Object({
1186
- team: Type.String({ description: "Persistent team ID" }),
1196
+ team: Type.String({ description: "Team name or persistent ID" }),
1187
1197
  teammates: Type.Array(teammateSchema(""), { minItems: 1, description: "New teammates to add" }),
1188
1198
  }),
1189
1199
  async execute(_toolCallId, params, _signal, _onUpdate, context) {
1190
- const team = [...teams.values()].find((candidate) => candidate.id === params.team && candidate.owner === owner);
1200
+ const team = resolveTeamIdentifier(
1201
+ [...teams.values()].filter((candidate) => candidate.owner === owner),
1202
+ params.team,
1203
+ );
1191
1204
  if (!team || !team.manifest || !team.lease || team.manifest.state !== "active") {
1192
1205
  throw new Error(`team_add requires a running team owned by this main session: ${params.team}`);
1193
1206
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@giladbarnea/pi-simple-team",
3
- "version": "1.0.43",
3
+ "version": "1.0.44",
4
4
  "description": "A flat, live team of Pi agents.",
5
5
  "keywords": [
6
6
  "pi-package",