@linxiraos/pi-messenger 1.1.1 → 1.3.0
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/CHANGELOG.md +741 -676
- package/LICENSE +45 -0
- package/README.md +424 -424
- package/THIRD-PARTY-NOTICES.txt +22951 -0
- package/config-overlay.ts +175 -171
- package/config.ts +221 -209
- package/crew/agents/crew-plan-sync.md +66 -64
- package/crew/agents/crew-planner.md +173 -172
- package/crew/agents/crew-reviewer.md +58 -58
- package/crew/agents/crew-worker.md +130 -129
- package/crew/agents.ts +507 -434
- package/crew/handlers/coordination.ts +350 -332
- package/crew/handlers/plan.ts +988 -906
- package/crew/handlers/review.ts +354 -333
- package/crew/handlers/revise.ts +400 -376
- package/crew/handlers/status.ts +303 -295
- package/crew/handlers/sync.ts +237 -233
- package/crew/handlers/task.ts +820 -792
- package/crew/handlers/team.ts +294 -235
- package/crew/handlers/work.ts +467 -425
- package/crew/id-allocator.ts +30 -30
- package/crew/index.ts +297 -257
- package/crew/live-progress.ts +58 -58
- package/crew/lobby.ts +504 -473
- package/crew/prompt.ts +262 -252
- package/crew/registry.ts +114 -114
- package/crew/spawn.ts +135 -111
- package/crew/state-autonomous.ts +163 -164
- package/crew/state-planning.ts +264 -263
- package/crew/state.ts +20 -20
- package/crew/store.ts +646 -642
- package/crew/task-actions.ts +162 -131
- package/crew/team/store.ts +572 -479
- package/crew/team/subagent-roles.ts +105 -87
- package/crew/team/types.ts +50 -50
- package/crew/types.ts +194 -194
- package/crew/utils/artifacts.ts +57 -62
- package/crew/utils/config.ts +158 -156
- package/crew/utils/discover.ts +221 -219
- package/crew/utils/install.ts +94 -85
- package/crew/utils/migrations.ts +126 -0
- package/crew/utils/progress.ts +191 -187
- package/crew/utils/result.ts +16 -16
- package/crew/utils/risk-labels.ts +5 -7
- package/crew/utils/task-format.ts +14 -14
- package/crew/utils/team-roles.ts +44 -28
- package/crew/utils/truncate.ts +76 -79
- package/crew/utils/verdict.ts +55 -55
- package/editor-binary.ts +150 -0
- package/editor-command.ts +107 -0
- package/editor-target.ts +40 -0
- package/feed.ts +321 -268
- package/handlers.ts +1041 -1107
- package/index.ts +1314 -1206
- package/install.mjs +187 -189
- package/lib.ts +587 -467
- package/overlay-actions.ts +519 -511
- package/overlay-coordinator.ts +150 -150
- package/overlay-render.ts +770 -676
- package/overlay.ts +872 -830
- package/package.json +64 -60
- package/paths.ts +60 -0
- package/skills/pi-messenger-crew/SKILL.md +375 -347
- package/store.ts +1147 -1139
- package/teamagent-command.ts +321 -0
- package/vitest.config.ts +10 -10
package/crew/prompt.ts
CHANGED
|
@@ -1,252 +1,262 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Crew - Worker Prompt Builder
|
|
3
|
-
*
|
|
4
|
-
* Assembles the full prompt sent to a worker when it's assigned a task.
|
|
5
|
-
* Pure function: reads from store, returns a string.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import type { Task } from "./types.ts";
|
|
9
|
-
import type { CrewConfig } from "./utils/config.ts";
|
|
10
|
-
import type { CrewSkillInfo } from "./utils/discover.ts";
|
|
11
|
-
import { TEAM_MEMORY_TYPES, type TeamMemoryType, type TeamPromptContext } from "./team/types.ts";
|
|
12
|
-
import { isNonEditingTeamRole } from "./utils/team-roles.ts";
|
|
13
|
-
import * as store from "./store.ts";
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
${
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Crew - Worker Prompt Builder
|
|
3
|
+
*
|
|
4
|
+
* Assembles the full prompt sent to a worker when it's assigned a task.
|
|
5
|
+
* Pure function: reads from store, returns a string.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { Task } from "./types.ts";
|
|
9
|
+
import type { CrewConfig } from "./utils/config.ts";
|
|
10
|
+
import type { CrewSkillInfo } from "./utils/discover.ts";
|
|
11
|
+
import { TEAM_MEMORY_TYPES, type TeamMemoryType, type TeamPromptContext } from "./team/types.ts";
|
|
12
|
+
import { isNonEditingTeamRole } from "./utils/team-roles.ts";
|
|
13
|
+
import * as store from "./store.ts";
|
|
14
|
+
import {
|
|
15
|
+
buildDependencySection,
|
|
16
|
+
buildCoordinationContext,
|
|
17
|
+
buildCoordinationInstructions,
|
|
18
|
+
} from "./handlers/coordination.ts";
|
|
19
|
+
|
|
20
|
+
export function buildWorkerPrompt(
|
|
21
|
+
task: Task,
|
|
22
|
+
prdPath: string,
|
|
23
|
+
cwd: string,
|
|
24
|
+
config: CrewConfig,
|
|
25
|
+
concurrentTasks: Task[],
|
|
26
|
+
skills?: CrewSkillInfo[],
|
|
27
|
+
teamContext?: TeamPromptContext,
|
|
28
|
+
): string {
|
|
29
|
+
const taskSpec = store.getTaskSpec(cwd, task.id);
|
|
30
|
+
const planSpec = store.getPlanSpec(cwd);
|
|
31
|
+
const isNonEditingRole = isNonEditingTeamRole(teamContext?.role?.name ?? task.role);
|
|
32
|
+
const mission = isNonEditingRole
|
|
33
|
+
? `Inspect this task as a read-only Team role. This overrides generic implementation protocol for this assignment:
|
|
34
|
+
1. Join the mesh
|
|
35
|
+
2. Read task spec to understand requirements
|
|
36
|
+
3. Start the task so Crew can track ownership
|
|
37
|
+
4. Inspect code, docs, and context without editing files
|
|
38
|
+
5. Record findings, plans, decisions, risks, or handoff notes in progress or Team memory
|
|
39
|
+
6. Mark complete with a concise summary of what you found or recommend`
|
|
40
|
+
: `Implement this task following the crew-worker protocol:
|
|
41
|
+
1. Join the mesh
|
|
42
|
+
2. Read task spec to understand requirements
|
|
43
|
+
3. Start task and reserve files
|
|
44
|
+
4. Implement the feature
|
|
45
|
+
5. Commit your changes
|
|
46
|
+
6. Release reservations and mark complete`;
|
|
47
|
+
|
|
48
|
+
let prompt = `# Task Assignment
|
|
49
|
+
|
|
50
|
+
**Task ID:** ${task.id}
|
|
51
|
+
**Task Title:** ${task.title}
|
|
52
|
+
**PRD:** ${prdPath}
|
|
53
|
+
${task.attempt_count >= 1 ? `**Attempt:** ${task.attempt_count + 1} (retry after previous attempt)` : ""}
|
|
54
|
+
|
|
55
|
+
## Your Mission
|
|
56
|
+
|
|
57
|
+
${mission}
|
|
58
|
+
|
|
59
|
+
`;
|
|
60
|
+
|
|
61
|
+
const teamSection = buildTeamSection(task, teamContext);
|
|
62
|
+
if (teamSection) {
|
|
63
|
+
prompt += teamSection;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (task.last_review) {
|
|
67
|
+
prompt += `## ⚠️ Previous Review Feedback
|
|
68
|
+
|
|
69
|
+
**Verdict:** ${task.last_review.verdict}
|
|
70
|
+
|
|
71
|
+
${task.last_review.summary}
|
|
72
|
+
|
|
73
|
+
${task.last_review.issues.length > 0 ? `**Issues to fix:**\n${task.last_review.issues.map(i => `- ${i}`).join("\n")}\n` : ""}
|
|
74
|
+
${task.last_review.suggestions.length > 0 ? `**Suggestions:**\n${task.last_review.suggestions.map(s => `- ${s}`).join("\n")}\n` : ""}
|
|
75
|
+
|
|
76
|
+
**You MUST address the issues above in this attempt.**
|
|
77
|
+
|
|
78
|
+
`;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const progress = store.getTaskProgress(cwd, task.id);
|
|
82
|
+
if (progress) {
|
|
83
|
+
const lines = progress.trimEnd().split("\n");
|
|
84
|
+
const capped = lines.length > 30 ? lines.slice(-30) : lines;
|
|
85
|
+
const truncated = capped.join("\n");
|
|
86
|
+
const omitted = lines.length > 30 ? `(${lines.length - 30} earlier entries omitted)\n` : "";
|
|
87
|
+
prompt += `## Progress from Prior Attempts
|
|
88
|
+
|
|
89
|
+
${omitted}${truncated}
|
|
90
|
+
|
|
91
|
+
`;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (task.depends_on.length > 0) {
|
|
95
|
+
if (config.dependencies === "advisory" || config.coordination !== "none") {
|
|
96
|
+
prompt += buildDependencySection(cwd, task, config, { readOnly: isNonEditingRole });
|
|
97
|
+
} else {
|
|
98
|
+
prompt += `## Dependencies
|
|
99
|
+
|
|
100
|
+
This task depends on: ${task.depends_on.join(", ")}
|
|
101
|
+
These tasks are already complete - you can reference their implementations.
|
|
102
|
+
|
|
103
|
+
`;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const coordContext = buildCoordinationContext(cwd, task, config, concurrentTasks, { readOnly: isNonEditingRole });
|
|
108
|
+
if (coordContext) {
|
|
109
|
+
prompt += coordContext;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (taskSpec && !taskSpec.includes("*Spec pending*")) {
|
|
113
|
+
prompt += `## Task Specification
|
|
114
|
+
|
|
115
|
+
${taskSpec}
|
|
116
|
+
|
|
117
|
+
`;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (planSpec && !planSpec.includes("*Spec pending*")) {
|
|
121
|
+
const truncatedSpec =
|
|
122
|
+
planSpec.length > 2000
|
|
123
|
+
? planSpec.slice(0, 2000) + `\n\n[Spec truncated - read full spec from .zeta/messenger/crew/plan.md]`
|
|
124
|
+
: planSpec;
|
|
125
|
+
prompt += `## Plan Context
|
|
126
|
+
|
|
127
|
+
${truncatedSpec}
|
|
128
|
+
`;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const coordInstructions = buildCoordinationInstructions(config, { readOnly: isNonEditingRole });
|
|
132
|
+
if (coordInstructions) {
|
|
133
|
+
prompt += coordInstructions;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const skillsSection = buildSkillsSection(skills, task.skills, isNonEditingRole);
|
|
137
|
+
if (skillsSection) {
|
|
138
|
+
prompt += skillsSection;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return prompt;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const WORKER_HIDDEN_SKILLS = new Set(["pi-messenger-crew"]);
|
|
145
|
+
|
|
146
|
+
function buildTeamSection(task: Task, teamContext: TeamPromptContext | undefined): string | null {
|
|
147
|
+
if (!teamContext) return null;
|
|
148
|
+
|
|
149
|
+
let section = `## Team Context\n\n`;
|
|
150
|
+
if (teamContext.team) {
|
|
151
|
+
const profileText =
|
|
152
|
+
teamContext.profile?.name && teamContext.profile.name !== teamContext.team.name
|
|
153
|
+
? ` (profile: ${teamContext.profile.name})`
|
|
154
|
+
: "";
|
|
155
|
+
section += `Active team: ${teamContext.team.name}${profileText}\n\n`;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (task.role || teamContext.role) {
|
|
159
|
+
section += `### Team Role\nYou are acting as the \`${task.role ?? teamContext.role?.name}\` role for this task.\n`;
|
|
160
|
+
if (teamContext.role?.description) section += `Role description: ${teamContext.role.description}\n`;
|
|
161
|
+
if (teamContext.role?.thinking) section += `Thinking default: ${teamContext.role.thinking}\n`;
|
|
162
|
+
if (teamContext.role?.skills && teamContext.role.skills.length > 0)
|
|
163
|
+
section += `Role skills: ${teamContext.role.skills.join(", ")}\n`;
|
|
164
|
+
if (teamContext.role && isNonEditingTeamRole(teamContext.role.name)) {
|
|
165
|
+
section +=
|
|
166
|
+
"This is a non-editing Team role. Do not edit files; report findings, plans, decisions, or handoff notes instead.\n";
|
|
167
|
+
}
|
|
168
|
+
if (teamContext.role?.prompt) {
|
|
169
|
+
const prompt =
|
|
170
|
+
teamContext.role.prompt.length > 2000
|
|
171
|
+
? teamContext.role.prompt.slice(0, 2000) + "\n[Role prompt truncated]"
|
|
172
|
+
: teamContext.role.prompt;
|
|
173
|
+
section += `\nRole working rules:\n${prompt}\n`;
|
|
174
|
+
}
|
|
175
|
+
section += "\n";
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (teamContext.charter) {
|
|
179
|
+
const charter =
|
|
180
|
+
teamContext.charter.length > 2500
|
|
181
|
+
? teamContext.charter.slice(0, 2500) + "\n[Team charter truncated]"
|
|
182
|
+
: teamContext.charter;
|
|
183
|
+
section += `### Team Charter\n${charter}\n\n`;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const memoryText = formatMemory(teamContext.memory);
|
|
187
|
+
if (memoryText) section += memoryText;
|
|
188
|
+
|
|
189
|
+
if (task.risk_labels && task.risk_labels.length > 0) {
|
|
190
|
+
section += `### Risk Labels\n${task.risk_labels.join(", ")}\n\n`;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (task.approval?.required) {
|
|
194
|
+
section += `### Approval Policy\nLead approval required. Current status: ${task.approval.status}.\n`;
|
|
195
|
+
if (task.approval.plan) section += `Approval plan: ${task.approval.plan}\n`;
|
|
196
|
+
if (task.approval.feedback) section += `Approval feedback: ${task.approval.feedback}\n`;
|
|
197
|
+
section += "\n";
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return section;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function formatMemory(memory: TeamPromptContext["memory"]): string {
|
|
204
|
+
const labels: Record<TeamMemoryType, string> = {
|
|
205
|
+
decision: "Recent decisions",
|
|
206
|
+
interface: "Interfaces",
|
|
207
|
+
risk: "Risks",
|
|
208
|
+
handoff: "Handoffs",
|
|
209
|
+
};
|
|
210
|
+
let text = "";
|
|
211
|
+
for (const type of TEAM_MEMORY_TYPES) {
|
|
212
|
+
const entries = memory[type];
|
|
213
|
+
if (!entries || entries.length === 0) continue;
|
|
214
|
+
text += `### ${labels[type]}\n`;
|
|
215
|
+
for (const entry of entries.slice(-8)) {
|
|
216
|
+
text += `- ${entry.message}${entry.taskId ? ` (${entry.taskId})` : ""}\n`;
|
|
217
|
+
}
|
|
218
|
+
text += "\n";
|
|
219
|
+
}
|
|
220
|
+
return text ? `### Team Memory\n${text}` : "";
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function buildSkillsSection(
|
|
224
|
+
skills: CrewSkillInfo[] | undefined,
|
|
225
|
+
taskSkills: string[] | undefined,
|
|
226
|
+
readOnly: boolean,
|
|
227
|
+
): string | null {
|
|
228
|
+
if (!skills || skills.length === 0) return null;
|
|
229
|
+
|
|
230
|
+
const visibleSkills = skills.filter(skill => !WORKER_HIDDEN_SKILLS.has(skill.name));
|
|
231
|
+
if (visibleSkills.length === 0) return null;
|
|
232
|
+
|
|
233
|
+
const recommended = new Set(taskSkills ?? []);
|
|
234
|
+
const recSkills = visibleSkills.filter(s => recommended.has(s.name));
|
|
235
|
+
const otherSkills = visibleSkills.filter(s => !recommended.has(s.name));
|
|
236
|
+
|
|
237
|
+
let section = `## Available Skills
|
|
238
|
+
|
|
239
|
+
${readOnly ? "Read any skill that matches what you're investigating." : "Read any skill that matches what you're implementing."}
|
|
240
|
+
|
|
241
|
+
`;
|
|
242
|
+
|
|
243
|
+
if (recSkills.length > 0) {
|
|
244
|
+
section += "**Recommended for this task:**\n";
|
|
245
|
+
for (const s of recSkills) {
|
|
246
|
+
section += ` ${s.name} — ${s.description}\n ${s.path}\n`;
|
|
247
|
+
}
|
|
248
|
+
section += "\n";
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (otherSkills.length > 0) {
|
|
252
|
+
if (recSkills.length > 0) section += "**Also available:**\n";
|
|
253
|
+
for (const s of otherSkills) {
|
|
254
|
+
section += ` ${s.name} — ${s.description}\n ${s.path}\n`;
|
|
255
|
+
}
|
|
256
|
+
section += "\n";
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
section += `To load a skill: read({ path: "<skill-path>" })\n`;
|
|
260
|
+
|
|
261
|
+
return section;
|
|
262
|
+
}
|