@giladbarnea/pi-simple-team 1.0.15 → 1.0.17
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/README.md +113 -39
- package/index.ts +78 -73
- package/model-preflight.ts +18 -58
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,30 +22,87 @@
|
|
|
22
22
|
---
|
|
23
23
|
|
|
24
24
|
|
|
25
|
-
|
|
26
25
|
## Why
|
|
27
26
|
|
|
28
|
-
|
|
27
|
+
I've always done my best work in a small room with a few capable people, building something together.
|
|
28
|
+
|
|
29
|
+
> <span style="color:grey">_[shouts]_</span> Has anyone figured out how to set up auth yet?
|
|
29
30
|
|
|
30
|
-
|
|
31
|
+
Not filing a "request for assistance".
|
|
31
32
|
|
|
32
|
-
|
|
33
|
+
> <span style="color:grey">_[taps shoulder]_</span> Dude can you grill me on this plan?
|
|
34
|
+
|
|
35
|
+
Not scheduling a meeting.
|
|
33
36
|
|
|
34
37
|
**That's the whole design. Not a swarm, not a company. *A room.***
|
|
35
38
|
|
|
36
39
|
## Using `pi-simple-team`
|
|
37
40
|
|
|
38
|
-
|
|
41
|
+
Tell your main agent:
|
|
42
|
+
> Spawn a team.
|
|
43
|
+
|
|
44
|
+
### Throw a team at something hard.
|
|
39
45
|
|
|
40
|
-
|
|
46
|
+
The team takes the shape of the mission.
|
|
41
47
|
|
|
42
|
-
**
|
|
43
|
-
|
|
48
|
+
**Basic example: adversarial pair**
|
|
49
|
+
|
|
50
|
+
You:
|
|
51
|
+
> Create an implementer-reviewer team to complete `PLAN.md`.
|
|
52
|
+
|
|
53
|
+
Main agent:
|
|
54
|
+
> Pair created. They'll loop through it together. They'll let me know when they're done.
|
|
55
|
+
|
|
56
|
+
<br>
|
|
44
57
|
|
|
45
|
-
**
|
|
58
|
+
**Better example: build an agentic graph**
|
|
46
59
|
|
|
47
|
-
|
|
48
|
-
**
|
|
60
|
+
You:
|
|
61
|
+
> **Team goal:**
|
|
62
|
+
> 1. map out all customer–product money streams in the database.
|
|
63
|
+
> 2. Feed this knowledge into the harness.
|
|
64
|
+
> 3. Then prove the data analysis agent passes the new evals.
|
|
65
|
+
>
|
|
66
|
+
> **Note:**
|
|
67
|
+
> - #1 and #3 are _loops._ Call them `1-map` and `3-eval`.
|
|
68
|
+
> - `1-map` and `3-eval` each gets a teamate.
|
|
69
|
+
> - Each teammate spawns _its own team_ to loop on its task.
|
|
70
|
+
|
|
71
|
+
<br>
|
|
72
|
+
|
|
73
|
+
<center>
|
|
74
|
+
<b>Because</b> it does nothing specially, <code>pi-simple-team</code> can construct any topography you wish it to.
|
|
75
|
+
</center>
|
|
76
|
+
<br>
|
|
77
|
+
That prompt gives you this graph:
|
|
78
|
+
|
|
79
|
+
```mermaid
|
|
80
|
+
flowchart LR
|
|
81
|
+
subgraph map["1-map: map the money streams"]
|
|
82
|
+
scout["`**Scout**
|
|
83
|
+
Runs repeatedly to clear
|
|
84
|
+
out the fog of war.`"] <--> advocate["`**Devil’s advocate**
|
|
85
|
+
Points out what we
|
|
86
|
+
still don’t know.`"]
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
harness["`**2: subagent dispatch**
|
|
90
|
+
Feeds new understanding
|
|
91
|
+
into the harness.`"]
|
|
92
|
+
|
|
93
|
+
subgraph eval["3-eval: hill-climb the evals"]
|
|
94
|
+
engineer["`**Engineer**
|
|
95
|
+
Improves the harness.`"] <--> watcher["`**Performance watcher**
|
|
96
|
+
Suggests a fresh approach
|
|
97
|
+
when stuck. `"]
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
map --> harness --> eval
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
<br>
|
|
104
|
+
|
|
105
|
+
---
|
|
49
106
|
|
|
50
107
|
<br>
|
|
51
108
|
|
|
@@ -55,48 +112,50 @@ Ask your main agent for a team.
|
|
|
55
112
|
|
|
56
113
|
## The mechanics
|
|
57
114
|
|
|
115
|
+
### 🏋️ Woken up when needed. Works freely otherwise.
|
|
58
116
|
|
|
117
|
+
Tokens, intelligence and time are never wasted on busy-polling for messages.
|
|
59
118
|
|
|
60
|
-
|
|
119
|
+
Instead, `pi-simple-team` pushes messages to the receipients.
|
|
120
|
+
|
|
121
|
+
This is both efficient and effective:
|
|
61
122
|
|
|
62
123
|
- ✔ No inbox to forget.
|
|
63
|
-
- ✔
|
|
124
|
+
- ✔ Context window stays lean.
|
|
125
|
+
- ✔ Unlocks teams doing arbitrary workflows.
|
|
64
126
|
|
|
65
127
|
*{screenshot of Codex filling up the entire visible chat with countless* `Waiting agents to finish...`*}*
|
|
66
128
|
|
|
67
|
-
### Messages arrive
|
|
68
|
-
|
|
69
|
-
- ⚡ Sub-second, when the recipient is idle.
|
|
70
|
-
- 🏎️ The moment the current bout of work ends, when busy.
|
|
129
|
+
### ⚡ Messages arrive _fast_.
|
|
71
130
|
|
|
72
|
-
|
|
131
|
+
- Sub-second, when the recipient is idle.
|
|
132
|
+
- The moment the current bout of work ends, when busy.
|
|
73
133
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
You get a live view of the room. Main and teammates keep using the same tools.
|
|
77
|
-
|
|
78
|
-
### Statuses everyone can see.
|
|
134
|
+
### 🟢 Statuses everyone can see.
|
|
79
135
|
|
|
80
136
|
Teammates publish a one-liner:
|
|
81
137
|
|
|
82
|
-
|
|
83
|
-
|
|
138
|
+
> <span style="color:grey">implementer </span> Done, 89 tests green, awaiting review.
|
|
139
|
+
|
|
140
|
+
> <span style="color:grey">reviewer </span> Reading implementation, will finalize review in a few minutes"
|
|
84
141
|
|
|
85
|
-
Your main agent calls `teamstatus` and understands exactly what's going on
|
|
142
|
+
Your main agent calls `teamstatus` and understands exactly what's going on. Main doesn't ask and clutter the teammates' context.
|
|
86
143
|
|
|
87
|
-
|
|
144
|
+
### 🌡️ Context window self-awareness
|
|
88
145
|
|
|
89
|
-
|
|
146
|
+
Teammates know how much free context they have left.
|
|
90
147
|
|
|
91
|
-
|
|
148
|
+
Main agent knows its own and everyone else's too.
|
|
92
149
|
|
|
93
|
-
|
|
94
|
-
- At the same time, Release teammate sets status: "Ran `git add .`, preparing commit and push."
|
|
95
|
-
- Scout immediately interrupts them. Key never leaves the machine. Developer keeps their job.
|
|
150
|
+
### 📣 Interrupts, when justified.
|
|
96
151
|
|
|
152
|
+
> _Situation: Late afternoon. Team has finished a production hotfix and started to wrap up._
|
|
97
153
|
|
|
154
|
+
- 17:32:00: Security scout spots a private SSH key not covered by `.gitignore`.
|
|
155
|
+
- 17:32:01: Release teammate sets status: "Ran `git add .`, preparing commit and push."
|
|
156
|
+
- 17:32:02: Scout immediately interrupts. Key never leaves the machine. Developer keeps their job.
|
|
98
157
|
|
|
99
|
-
### Complete observability by design.
|
|
158
|
+
### 📡 Complete observability by design.
|
|
100
159
|
|
|
101
160
|
The main agent can access one exhaustive, **timestamped history** of tool calls, messages, and lifecycle events, **recorded by the harness itself.**
|
|
102
161
|
|
|
@@ -109,6 +168,14 @@ Useful for tracing a failure *across* teammates—without asking anyone to recon
|
|
|
109
168
|

|
|
110
169
|
<div align="center"><em>Visual representation of the team log.</em></div>
|
|
111
170
|
|
|
171
|
+
### 🪟 Herdr Mode
|
|
172
|
+
|
|
173
|
+
`pi-simple-team` can give each teammate a Pi session in its own [Herdr](https://herdr.dev) pane. Just ask your main agent to do that.
|
|
174
|
+
|
|
175
|
+
- Live view of the room.
|
|
176
|
+
- Talk directly with teammates.
|
|
177
|
+
|
|
178
|
+
|
|
112
179
|
## Install
|
|
113
180
|
|
|
114
181
|
```sh
|
|
@@ -128,9 +195,11 @@ Kept minimal:
|
|
|
128
195
|
| **Main agent** | Team lifecycle | `team_spawn`, `team_shutdown` |
|
|
129
196
|
| | With team | `teamsend` |
|
|
130
197
|
| | On team | `teamstatus`, `teamlog` |
|
|
131
|
-
|
|
|
198
|
+
| | On everyone | `report_context_window` |
|
|
199
|
+
| **Teammates** | With team | `teamsend` |
|
|
132
200
|
| | With main | `teammain` |
|
|
133
|
-
| |
|
|
201
|
+
| | On self | `report_context_window` |
|
|
202
|
+
| **Everyone** | For everyone | `teamstatus` |
|
|
134
203
|
|
|
135
204
|
|
|
136
205
|
---
|
|
@@ -139,12 +208,17 @@ Kept minimal:
|
|
|
139
208
|
|
|
140
209
|
## Roadmap
|
|
141
210
|
|
|
211
|
+
**User involvement track:**
|
|
142
212
|
|
|
143
|
-
|
|
144
|
-
### User involvement track
|
|
213
|
+
- [x] Herdr panes for teammates.
|
|
145
214
|
|
|
146
215
|
Slash commands for:
|
|
147
216
|
|
|
148
|
-
- [ ] 💠 Live control panel.
|
|
217
|
+
- [ ] 💠 Live control panel.
|
|
149
218
|
- [ ] 👋 Joining and steering teams.
|
|
150
|
-
- [ ] 🪄 Spawning teams directly.
|
|
219
|
+
- [ ] 🪄 Spawning teams directly.
|
|
220
|
+
|
|
221
|
+
**Functional:**
|
|
222
|
+
|
|
223
|
+
- [ ] Add new teammates after team has spawned.
|
|
224
|
+
- [ ] Main forces `/compact` on select teammate.
|
package/index.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { StringDecoder } from "node:string_decoder";
|
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
7
|
import { defineTool, type ContextUsage, type ExtensionAPI, getMarkdownTheme } from "@earendil-works/pi-coding-agent";
|
|
8
8
|
import { formatContextWindowReport, requireKnownContextUsage, type KnownContextUsage } from "./context-window.ts";
|
|
9
|
-
import { validateTeammateModels } from "./model-preflight.ts";
|
|
9
|
+
import { formatScopedModelGuidance, validateTeammateModels, type ModelReference } from "./model-preflight.ts";
|
|
10
10
|
import { composeSystemPrompt } from "./system-prompt.ts";
|
|
11
11
|
import { readChildRuntimeConfig, registerChildTools } from "./child-tools.ts";
|
|
12
12
|
import { appendTeamLog, filterTeamLog, normalizeChildEvent, nowText, pageTeamLog, preview, renderTeamLogPage, type TeamLogEntry } from "./teamlog.ts";
|
|
@@ -797,12 +797,14 @@ async function handleCallbackRequest(request: http.IncomingMessage, response: ht
|
|
|
797
797
|
}
|
|
798
798
|
}
|
|
799
799
|
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
})
|
|
800
|
+
function teammateSchema(modelGuidance: string) {
|
|
801
|
+
return Type.Object({
|
|
802
|
+
name: Type.String({ description: "Teammate name" }),
|
|
803
|
+
prompt: Type.String({ description: "Individual teammate system prompt" }),
|
|
804
|
+
model: Type.String({ description: `Canonical provider/model id for this teammate. ${modelGuidance}` }),
|
|
805
|
+
thinking: Type.Optional(StringEnum(thinkingLevels, { description: "Thinking level for this teammate. Defaults to xhigh.", default: defaultThinkingLevel })),
|
|
806
|
+
});
|
|
807
|
+
}
|
|
806
808
|
|
|
807
809
|
export default function (pi: ExtensionAPI) {
|
|
808
810
|
const childRuntimeConfig = readChildRuntimeConfig();
|
|
@@ -822,73 +824,76 @@ export default function (pi: ExtensionAPI) {
|
|
|
822
824
|
closeCallbackServerIfUnused();
|
|
823
825
|
});
|
|
824
826
|
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
827
|
+
pi.on("session_start", (_event, context) => {
|
|
828
|
+
const scopedModels = (context as typeof context & { scopedModels?: ReadonlyArray<{ model: ModelReference }> }).scopedModels ?? [];
|
|
829
|
+
const modelGuidance = formatScopedModelGuidance(scopedModels.map(({ model }) => model));
|
|
830
|
+
pi.registerTool(
|
|
831
|
+
defineTool({
|
|
832
|
+
name: "team_spawn",
|
|
833
|
+
label: "Team Spawn",
|
|
834
|
+
description: `Spawn a persistent team of Pi teammates with fresh context windows. If the user is interested, set \`showOnHerdrPanes\` to run each teammate in a visible Herdr pane. The main agent (you) is included automatically; do not specify it as a teammate. ${modelGuidance}`,
|
|
835
|
+
promptSnippet: `Spawn persistent Pi teammates. ${modelGuidance} Unless required, don’t fill up your time by repeatedly busy-polling team information. Don’t bash sleep to wait for progress; instead, set your status to advertise that you are counting on teammates to send you important milestones or requests for help, and that otherwise you are staying idle. Send this actively to the team. Then end your turn by sending a simple message to the user, and finally stay put.`,
|
|
836
|
+
renderShell: "self",
|
|
837
|
+
renderCall: (args, theme, context) => renderTeamToolCall("team_spawn", args, theme, context, sessionTeammateRoster),
|
|
838
|
+
renderResult: (result, options, theme, context) => renderTeamToolResult("team_spawn", result, options, theme, context, undefined, sessionTeammateRoster),
|
|
839
|
+
parameters: Type.Object({
|
|
840
|
+
team: Type.String({ description: "Team name" }),
|
|
841
|
+
teamPrompt: Type.String({ description: "Common team system prompt" }),
|
|
842
|
+
teammates: Type.Array(teammateSchema(modelGuidance), { description: "Teammates to spawn" }),
|
|
843
|
+
showOnHerdrPanes: Type.Optional(Type.Boolean({ default: false })),
|
|
844
|
+
}),
|
|
845
|
+
async execute(_toolCallId, params, _signal, _onUpdate, context) {
|
|
846
|
+
const teamName = compactName(params.team);
|
|
847
|
+
if (teams.has(teamName)) throw new Error(`Team already exists: ${teamName}`);
|
|
848
|
+
const showOnHerdrPanes = Boolean(params.showOnHerdrPanes);
|
|
849
|
+
const herdrTabId = showOnHerdrPanes ? await validateHerdrAvailability() : undefined;
|
|
850
|
+
|
|
851
|
+
const teammateSpecs = params.teammates as TeammateSpec[];
|
|
852
|
+
const teammateNames = teammateSpecs.map((teammate) => compactName(teammate.name));
|
|
853
|
+
const duplicateNames = teammateNames.filter((name, index) => teammateNames.indexOf(name) !== index);
|
|
854
|
+
if (duplicateNames.length > 0) throw new Error(`Duplicate teammate name(s): ${[...new Set(duplicateNames)].join(", ")}`);
|
|
855
|
+
if (teammateNames.includes("main")) throw new Error('"main" is reserved');
|
|
856
|
+
|
|
857
|
+
validateTeammateModels(teammateSpecs, context.modelRegistry.getAvailable());
|
|
858
|
+
sessionTeammateRoster.push(...teammateNames.filter((teammateName) => !sessionTeammateRoster.includes(teammateName)));
|
|
859
|
+
await ensureCallbackServer();
|
|
860
|
+
|
|
861
|
+
const team: TeamState = {
|
|
862
|
+
owner,
|
|
863
|
+
ownerPi: pi,
|
|
864
|
+
name: teamName,
|
|
865
|
+
showOnHerdrPanes,
|
|
866
|
+
teamPrompt: params.teamPrompt,
|
|
867
|
+
members: new Map(),
|
|
868
|
+
statuses: new Map([["main", status("available", "Main agent")]]),
|
|
869
|
+
created: nowText(),
|
|
870
|
+
log: [],
|
|
871
|
+
nextLogSequence: 1,
|
|
872
|
+
};
|
|
873
|
+
|
|
874
|
+
teams.set(teamName, team);
|
|
875
|
+
try {
|
|
876
|
+
for (const teammateSpec of teammateSpecs) {
|
|
877
|
+
const teammate = createTeammateState(team, teammateSpec);
|
|
878
|
+
team.members.set(teammate.name, teammate);
|
|
879
|
+
team.statuses.set(teammate.name, status("idle", "Spawned"));
|
|
880
|
+
await startTeammate(team, teammate, teammateNames, herdrTabId);
|
|
881
|
+
}
|
|
882
|
+
} catch (error) {
|
|
883
|
+
await shutdownTeam(team);
|
|
884
|
+
closeCallbackServerIfUnused();
|
|
885
|
+
throw error;
|
|
877
886
|
}
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
});
|
|
889
|
-
},
|
|
890
|
-
}),
|
|
891
|
-
);
|
|
887
|
+
return toolResult({
|
|
888
|
+
accepted: true,
|
|
889
|
+
team: team.name,
|
|
890
|
+
teammates: [...team.members.keys()],
|
|
891
|
+
status: formatStatus(team),
|
|
892
|
+
});
|
|
893
|
+
},
|
|
894
|
+
}),
|
|
895
|
+
);
|
|
896
|
+
});
|
|
892
897
|
|
|
893
898
|
pi.registerTool(
|
|
894
899
|
defineTool({
|
package/model-preflight.ts
CHANGED
|
@@ -1,72 +1,32 @@
|
|
|
1
|
-
|
|
1
|
+
export interface ModelReference {
|
|
2
|
+
provider: string;
|
|
3
|
+
id: string;
|
|
4
|
+
}
|
|
2
5
|
|
|
3
6
|
export interface TeammateModelSpec {
|
|
4
7
|
name: string;
|
|
5
8
|
model: string;
|
|
6
9
|
}
|
|
7
10
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const listModelsTimeoutMilliseconds = 15_000;
|
|
12
|
-
|
|
13
|
-
export function stripThinkingSuffix(model: string): string {
|
|
14
|
-
const suffixSeparatorIndex = model.lastIndexOf(":");
|
|
15
|
-
if (suffixSeparatorIndex === -1) return model;
|
|
16
|
-
|
|
17
|
-
const suffix = model.slice(suffixSeparatorIndex + 1);
|
|
18
|
-
if (!thinkingSuffixes.includes(suffix as (typeof thinkingSuffixes)[number])) return model;
|
|
19
|
-
|
|
20
|
-
return model.slice(0, suffixSeparatorIndex);
|
|
11
|
+
/** @example formatModelReference({ provider: "anthropic", id: "claude-sonnet-4-6" }) // "anthropic/claude-sonnet-4-6" */
|
|
12
|
+
export function formatModelReference(model: ModelReference): string {
|
|
13
|
+
return `${model.provider}/${model.id}`;
|
|
21
14
|
}
|
|
22
15
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
.
|
|
28
|
-
.
|
|
29
|
-
.filter(Boolean);
|
|
30
|
-
const headerIndex = lines.findIndex((line) => line.startsWith("provider ") && line.includes(" model"));
|
|
31
|
-
if (headerIndex === -1) return false;
|
|
32
|
-
|
|
33
|
-
return lines.slice(headerIndex + 1).some((line) => {
|
|
34
|
-
if (line.startsWith("No models matching ")) return false;
|
|
35
|
-
const columns = line.split(/\s+/);
|
|
36
|
-
return columns.length >= 2 && columns[0] !== "provider" && columns[1] !== "model";
|
|
37
|
-
});
|
|
16
|
+
/** @example formatScopedModelGuidance([{ provider: "anthropic", id: "claude-sonnet-4-6" }]) */
|
|
17
|
+
export function formatScopedModelGuidance(scopedModels: readonly ModelReference[]): string {
|
|
18
|
+
const modelReferences = scopedModels.map(formatModelReference);
|
|
19
|
+
return modelReferences.length > 0
|
|
20
|
+
? `You should probably use one of these user-scoped models: ${modelReferences.join(", ")}.`
|
|
21
|
+
: "The user has not defined a list of preferred models explicitly. Figure out which model _you_ are by reading the value of the PI_PROVIDER, PI_MODEL, and PI_REASONING_LEVEL environment variables. That should give you something to start with. Confirm with the user before picking any model id.";
|
|
38
22
|
}
|
|
39
23
|
|
|
40
|
-
export
|
|
24
|
+
export function validateTeammateModels(teammates: readonly TeammateModelSpec[], availableModels: readonly ModelReference[]): void {
|
|
25
|
+
const availableModelReferences = new Set(availableModels.map(formatModelReference));
|
|
26
|
+
const errors = teammates
|
|
27
|
+
.filter((teammate) => !availableModelReferences.has(teammate.model))
|
|
28
|
+
.map((teammate) => `Model ${JSON.stringify(teammate.model)} for teammate ${JSON.stringify(teammate.name)} is not available.`);
|
|
41
29
|
|
|
42
|
-
const runPiListModels: RunListModels = (modelPattern) => {
|
|
43
|
-
return new Promise((resolve, reject) => {
|
|
44
|
-
childProcess.execFile("pi", ["--list-models", modelPattern], { timeout: listModelsTimeoutMilliseconds, maxBuffer: 1024 * 1024 }, (error, stdout, stderr) => {
|
|
45
|
-
const output = `${stdout}${stderr}`;
|
|
46
|
-
if (!error) {
|
|
47
|
-
resolve(output);
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const details = output.trim() ? `\n${output.trim()}` : "";
|
|
52
|
-
reject(new Error(`pi --list-models ${JSON.stringify(modelPattern)} failed: ${error.message}${details}`));
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
async function validateTeammateModel(teammate: TeammateModelSpec, runListModels: RunListModels): Promise<void> {
|
|
58
|
-
const modelPattern = stripThinkingSuffix(teammate.model);
|
|
59
|
-
const output = await runListModels(modelPattern);
|
|
60
|
-
if (parseListModelsOutput(output)) return;
|
|
61
|
-
|
|
62
|
-
const details = output.trim() || "(no output)";
|
|
63
|
-
throw new Error(`No configured model matched ${JSON.stringify(teammate.model)} for teammate ${JSON.stringify(teammate.name)}. Checked ${JSON.stringify(modelPattern)} with pi --list-models:\n${details}`);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export async function validateTeammateModels(teammates: TeammateModelSpec[], runListModels: RunListModels = runPiListModels): Promise<void> {
|
|
67
|
-
const results = await Promise.allSettled(teammates.map((teammate) => validateTeammateModel(teammate, runListModels)));
|
|
68
|
-
const errors = results.flatMap((result) => (result.status === "rejected" ? [result.reason instanceof Error ? result.reason.message : String(result.reason)] : []));
|
|
69
30
|
if (errors.length === 0) return;
|
|
70
|
-
|
|
71
31
|
throw new Error(`Model preflight failed:\n${errors.map((error) => `- ${error}`).join("\n")}`);
|
|
72
32
|
}
|