@linxiraos/pi-messenger 1.1.0 → 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.
Files changed (66) hide show
  1. package/CHANGELOG.md +741 -676
  2. package/LICENSE +45 -0
  3. package/README.md +424 -424
  4. package/THIRD-PARTY-NOTICES.txt +22951 -0
  5. package/config-overlay.ts +175 -171
  6. package/config.ts +221 -209
  7. package/crew/agents/crew-plan-sync.md +66 -64
  8. package/crew/agents/crew-planner.md +173 -172
  9. package/crew/agents/crew-reviewer.md +58 -58
  10. package/crew/agents/crew-worker.md +130 -129
  11. package/crew/agents.ts +507 -434
  12. package/crew/handlers/coordination.ts +350 -332
  13. package/crew/handlers/plan.ts +988 -906
  14. package/crew/handlers/review.ts +354 -333
  15. package/crew/handlers/revise.ts +400 -376
  16. package/crew/handlers/status.ts +303 -295
  17. package/crew/handlers/sync.ts +237 -233
  18. package/crew/handlers/task.ts +820 -792
  19. package/crew/handlers/team.ts +294 -235
  20. package/crew/handlers/work.ts +467 -425
  21. package/crew/id-allocator.ts +30 -30
  22. package/crew/index.ts +297 -257
  23. package/crew/live-progress.ts +58 -58
  24. package/crew/lobby.ts +504 -473
  25. package/crew/prompt.ts +262 -252
  26. package/crew/registry.ts +114 -114
  27. package/crew/spawn.ts +135 -111
  28. package/crew/state-autonomous.ts +163 -164
  29. package/crew/state-planning.ts +264 -263
  30. package/crew/state.ts +20 -20
  31. package/crew/store.ts +646 -642
  32. package/crew/task-actions.ts +162 -131
  33. package/crew/team/store.ts +572 -479
  34. package/crew/team/subagent-roles.ts +105 -87
  35. package/crew/team/types.ts +50 -50
  36. package/crew/types.ts +194 -194
  37. package/crew/utils/artifacts.ts +57 -62
  38. package/crew/utils/config.ts +158 -156
  39. package/crew/utils/discover.ts +221 -219
  40. package/crew/utils/install.ts +94 -85
  41. package/crew/utils/migrations.ts +126 -0
  42. package/crew/utils/progress.ts +191 -187
  43. package/crew/utils/result.ts +16 -16
  44. package/crew/utils/risk-labels.ts +5 -7
  45. package/crew/utils/task-format.ts +14 -14
  46. package/crew/utils/team-roles.ts +44 -28
  47. package/crew/utils/truncate.ts +76 -79
  48. package/crew/utils/verdict.ts +55 -55
  49. package/editor-binary.ts +150 -0
  50. package/editor-command.ts +107 -0
  51. package/editor-target.ts +40 -0
  52. package/feed.ts +321 -268
  53. package/handlers.ts +1041 -1107
  54. package/index.ts +1314 -1206
  55. package/install.mjs +187 -189
  56. package/lib.ts +587 -467
  57. package/overlay-actions.ts +519 -511
  58. package/overlay-coordinator.ts +150 -150
  59. package/overlay-render.ts +770 -676
  60. package/overlay.ts +872 -830
  61. package/package.json +64 -60
  62. package/paths.ts +60 -0
  63. package/skills/pi-messenger-crew/SKILL.md +375 -347
  64. package/store.ts +1147 -1139
  65. package/teamagent-command.ts +321 -0
  66. package/vitest.config.ts +10 -10
@@ -1,235 +1,294 @@
1
- import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
2
- import type { MessengerState } from "../../lib.ts";
3
- import type { CrewParams } from "../types.ts";
4
- import { result } from "../utils/result.ts";
5
- import * as crewStore from "../store.ts";
6
- import * as teamStore from "../team/store.ts";
7
- import { TEAM_MEMORY_TYPES, type TeamMemoryType, type TeamProfile } from "../team/types.ts";
8
-
9
- export async function execute(op: string, params: CrewParams, state: MessengerState, ctx: ExtensionContext) {
10
- const cwd = ctx.cwd;
11
-
12
- switch (op) {
13
- case "setup":
14
- return setup(cwd, params);
15
- case "profile.list":
16
- return profileList();
17
- case "profile.use":
18
- return profileUse(cwd, params);
19
- case "profile.save":
20
- return profileSave(cwd, params);
21
- case "charter.show":
22
- return charterShow(cwd);
23
- case "charter.create":
24
- return charterCreate(cwd, params);
25
- case "charter.update":
26
- return charterUpdate(cwd, params);
27
- case "memory.note":
28
- return memoryNote(cwd, params, state);
29
- case "memory.list":
30
- return memoryList(cwd, params);
31
- case "roles":
32
- return roles(cwd);
33
- case "status":
34
- return status(cwd);
35
- default:
36
- return result(`Unknown team operation: ${op}`, { mode: "team", error: "unknown_operation", operation: op });
37
- }
38
- }
39
-
40
- function memoryType(value: unknown): TeamMemoryType | null {
41
- return typeof value === "string" && TEAM_MEMORY_TYPES.includes(value as TeamMemoryType) ? value as TeamMemoryType : null;
42
- }
43
-
44
- function starterCharter(profile: TeamProfile): string {
45
- const roles = Object.keys(profile.roles ?? {}).sort();
46
- const approval = profile.approval?.mode === "off"
47
- ? "No approval gates are configured for this profile."
48
- : `High-risk editing tasks need lead approval for: ${(profile.approval?.labels ?? ["security", "database", "api-contract", "destructive", "migration", "auth", "payment"]).join(", ")}.`;
49
- return [
50
- `Use the ${profile.name} Team profile for this project.`,
51
- profile.description ? `Profile intent: ${profile.description}.` : null,
52
- roles.length > 0 ? `Planner may assign these roles: ${roles.join(", ")}.` : null,
53
- approval,
54
- "Keep Team memory current with decisions, interface notes, risks, and handoffs.",
55
- ].filter(Boolean).join("\n\n");
56
- }
57
-
58
- function setup(cwd: string, params: CrewParams) {
59
- const name = params.name ?? "migration-squad";
60
- if (!teamStore.isValidProfileName(name)) {
61
- return result("Error: invalid team profile name. Use letters, numbers, underscore, or hyphen.", { mode: "team.setup", error: "invalid_name" });
62
- }
63
-
64
- const { team, profile, created } = teamStore.useProfile(cwd, name);
65
- const existingCharter = teamStore.readCharter(cwd);
66
- const customCharter = typeof params.message === "string" && params.message.trim().length > 0 ? params.message : undefined;
67
- const charter = customCharter || !existingCharter
68
- ? teamStore.writeCharter(cwd, profile.name, customCharter ?? starterCharter(profile))
69
- : existingCharter;
70
- const charterStatus = customCharter ? "updated" : existingCharter ? "kept" : "created";
71
-
72
- const text = `Set up Team profile **${profile.name}**.
73
-
74
- Profile: ${created ? "created editable JSON" : "activated"}
75
- Charter: ${charterStatus}
76
-
77
- Next:
78
- - Plan with this Team context: \`pi_messenger({ action: "plan", prompt: "..." })\`
79
- - Check Team status: \`pi_messenger({ action: "team.status" })\`
80
- - Approve gated work with \`task.approve\`; reject with \`task.reject\` and feedback.`;
81
-
82
- return result(text, {
83
- mode: "team.setup",
84
- team,
85
- profile,
86
- created,
87
- charter,
88
- charterStatus,
89
- });
90
- }
91
-
92
- function profileList() {
93
- const profiles = teamStore.listProfiles();
94
- const text = `# Team Profiles\n\n${profiles.map(p => `- ${p.name}${p.description ? ` — ${p.description}` : ""}`).join("\n")}`;
95
- return result(text, { mode: "team.profile.list", profiles });
96
- }
97
-
98
- function profileUse(cwd: string, params: CrewParams) {
99
- if (!params.name) return result("Error: name required for team.profile.use", { mode: "team.profile.use", error: "missing_name" });
100
- if (!teamStore.isValidProfileName(params.name)) {
101
- return result("Error: invalid team profile name. Use letters, numbers, underscore, or hyphen.", { mode: "team.profile.use", error: "invalid_name" });
102
- }
103
- const { team, profile, created } = teamStore.useProfile(cwd, params.name);
104
- const action = created ? "Created and activated" : "Activated";
105
- return result(`${action} team profile **${profile.name}**.`, {
106
- mode: "team.profile.use",
107
- team,
108
- profile,
109
- created,
110
- });
111
- }
112
-
113
- function profileSave(cwd: string, params: CrewParams) {
114
- if (!params.name) return result("Error: name required for team.profile.save", { mode: "team.profile.save", error: "missing_name" });
115
- if (!teamStore.isValidProfileName(params.name)) {
116
- return result("Error: invalid team profile name. Use letters, numbers, underscore, or hyphen.", { mode: "team.profile.save", error: "invalid_name" });
117
- }
118
- const active = teamStore.getActiveTeam(cwd);
119
- const activeProfile = teamStore.loadActiveProfile(cwd);
120
- const profile: TeamProfile = {
121
- ...(activeProfile ?? teamStore.defaultTeamProfile(params.name)),
122
- name: params.name,
123
- };
124
- teamStore.saveProfile(profile);
125
- const team = teamStore.setActiveTeam(cwd, active?.name ?? params.name, profile.name);
126
- return result(`Saved team profile **${profile.name}**.`, { mode: "team.profile.save", team, profile });
127
- }
128
-
129
- function charterShow(cwd: string) {
130
- const charter = teamStore.readCharter(cwd);
131
- if (!charter) {
132
- return result("No team charter found. Create one with `team.charter.create`.", {
133
- mode: "team.charter.show",
134
- charter: null,
135
- exists: false,
136
- });
137
- }
138
- return result(charter, {
139
- mode: "team.charter.show",
140
- charter,
141
- exists: true,
142
- });
143
- }
144
-
145
- function charterCreate(cwd: string, params: CrewParams) {
146
- if (!params.name) return result("Error: name required for team.charter.create", { mode: "team.charter.create", error: "missing_name" });
147
- if (!params.message) return result("Error: message required for team.charter.create", { mode: "team.charter.create", error: "missing_message" });
148
- const charter = teamStore.writeCharter(cwd, params.name, params.message);
149
- return result(`Created charter for **${params.name}**.`, { mode: "team.charter.create", charter, team: teamStore.getActiveTeam(cwd) });
150
- }
151
-
152
- function charterUpdate(cwd: string, params: CrewParams) {
153
- if (!params.message) return result("Error: message required for team.charter.update", { mode: "team.charter.update", error: "missing_message" });
154
- const charter = teamStore.updateCharter(cwd, params.message);
155
- return result("Updated team charter.", { mode: "team.charter.update", charter, team: teamStore.getActiveTeam(cwd) });
156
- }
157
-
158
- function memoryNote(cwd: string, params: CrewParams, state: MessengerState) {
159
- const type = memoryType(params.type);
160
- if (!type) return result("Error: type must be one of decision, interface, risk, or handoff", { mode: "team.memory.note", error: "invalid_type" });
161
- if (!params.message) return result("Error: message required for team.memory.note", { mode: "team.memory.note", error: "missing_message" });
162
- const entry = teamStore.noteMemory(cwd, type, params.message, state.agentName || "unknown", params.id);
163
- return result(`Saved team ${type} note.`, { mode: "team.memory.note", entry });
164
- }
165
-
166
- function memoryList(cwd: string, params: CrewParams) {
167
- const type = params.type ? memoryType(params.type) : null;
168
- if (params.type && !type) return result("Error: type must be one of decision, interface, risk, or handoff", { mode: "team.memory.list", error: "invalid_type" });
169
- const entries = teamStore.listMemory(cwd, type ?? undefined, params.limit);
170
- const text = entries.length > 0
171
- ? entries.map(entry => `- ${entry.ts} [${entry.type}] ${entry.message}${entry.taskId ? ` (${entry.taskId})` : ""}`).join("\n")
172
- : "No team memory entries found.";
173
- return result(text, { mode: "team.memory.list", type, entries });
174
- }
175
-
176
- function roles(cwd: string) {
177
- const roles = teamStore.resolveRoles(cwd);
178
- const profile = teamStore.loadActiveProfile(cwd);
179
- const activeNames = Object.keys(profile?.roles ?? {}).sort();
180
- const builtInNames = Object.keys(roles).filter(name => !activeNames.includes(name)).sort();
181
- const formatRole = (name: string) => {
182
- const role = roles[name];
183
- return `- ${name}${role?.description ? ` — ${role.description}` : ""}`;
184
- };
185
- const activeText = activeNames.length > 0
186
- ? `## Active profile roles\n${activeNames.map(formatRole).join("\n")}`
187
- : "## Active profile roles\nNo Team profile is active.";
188
- const availableText = builtInNames.length > 0
189
- ? `\n\n## Other available roles\n${builtInNames.map(formatRole).join("\n")}`
190
- : "";
191
- const note = "Team roles are labels and prompt context. Crew still runs tasks through Crew agents and does not launch pi-subagents.";
192
- return result(`# Team Roles\n\n${note}\n\n${activeText}${availableText}`, {
193
- mode: "team.roles",
194
- activeRoles: activeNames,
195
- availableRoles: builtInNames,
196
- roles,
197
- });
198
- }
199
-
200
- function status(cwd: string) {
201
- const team = teamStore.getActiveTeam(cwd);
202
- const profile = teamStore.loadActiveProfile(cwd);
203
- const charter = teamStore.readCharter(cwd);
204
- const roles = teamStore.resolveRoles(cwd);
205
- const roleNames = Object.keys(roles).sort();
206
- const activeRoleNames = Object.keys(profile?.roles ?? {}).sort();
207
- const counts = teamStore.memoryCounts(cwd);
208
- const needsLead = teamStore.needsLeadTasks(cwd);
209
- const rejected = teamStore.rejectedTasks(cwd);
210
- const approvalText = needsLead.length > 0
211
- ? `\nNeeds approval:\n${needsLead.map(t => `- ${t.id}: ${t.title} [${t.approval?.status ?? "pending"}]`).join("\n")}`
212
- : "\nNeeds approval: none";
213
- const rejectedText = rejected.length > 0
214
- ? `\nRejected tasks:\n${rejected.map(t => `- ${t.id}: ${t.title}${t.approval?.feedback ? ` — ${t.approval.feedback}` : ""}`).join("\n")}`
215
- : "\nRejected tasks: none";
216
- const nextAction = rejected.length > 0
217
- ? `Revise rejected work with: pi_messenger({ action: "task.revise", id: "${rejected[0].id}", prompt: "Address approval feedback" })`
218
- : needsLead.length > 0
219
- ? `Approve with: pi_messenger({ action: "task.approve", id: "${needsLead[0].id}" })`
220
- : team ? "Next: plan or run Crew work with this Team context." : "Next: activate a sample profile, e.g. migration-squad, review-squad, or research-squad.";
221
- const text = `Team: ${team?.name ?? "(none)"}\nProfile: ${profile?.name ?? team?.profile ?? "(none)"}\nCharter: ${charter ? "present" : "missing"}\nActive roles: ${activeRoleNames.length > 0 ? activeRoleNames.join(", ") : "none"}\nMemory: decisions ${counts.decision}, interfaces ${counts.interface}, risks ${counts.risk}, handoffs ${counts.handoff}${approvalText}${rejectedText}\n${nextAction}`;
222
- return result(text, {
223
- mode: "team.status",
224
- team,
225
- profile,
226
- charterPresent: !!charter,
227
- roles: roleNames,
228
- activeRoles: activeRoleNames,
229
- nextAction,
230
- memoryCounts: counts,
231
- needsLead: needsLead.map(t => ({ id: t.id, title: t.title, approval: t.approval })),
232
- rejected: rejected.map(t => ({ id: t.id, title: t.title, approval: t.approval })),
233
- taskCount: crewStore.getTasks(cwd).length,
234
- });
235
- }
1
+ import type { ExtensionContext } from "@linxiraos/zeta";
2
+ import type { MessengerState } from "../../lib.ts";
3
+ import type { CrewParams } from "../types.ts";
4
+ import { result } from "../utils/result.ts";
5
+ import * as crewStore from "../store.ts";
6
+ import * as teamStore from "../team/store.ts";
7
+ import { TEAM_MEMORY_TYPES, type TeamMemoryType, type TeamProfile } from "../team/types.ts";
8
+
9
+ export async function execute(op: string, params: CrewParams, state: MessengerState, ctx: ExtensionContext) {
10
+ const cwd = ctx.cwd;
11
+
12
+ switch (op) {
13
+ case "setup":
14
+ return setup(cwd, params);
15
+ case "profile.list":
16
+ return profileList();
17
+ case "profile.use":
18
+ return profileUse(cwd, params);
19
+ case "profile.save":
20
+ return profileSave(cwd, params);
21
+ case "charter.show":
22
+ return charterShow(cwd);
23
+ case "charter.create":
24
+ return charterCreate(cwd, params);
25
+ case "charter.update":
26
+ return charterUpdate(cwd, params);
27
+ case "memory.note":
28
+ return memoryNote(cwd, params, state);
29
+ case "memory.list":
30
+ return memoryList(cwd, params);
31
+ case "roles":
32
+ return roles(cwd);
33
+ case "status":
34
+ return status(cwd);
35
+ default:
36
+ return result(`Unknown team operation: ${op}`, { mode: "team", error: "unknown_operation", operation: op });
37
+ }
38
+ }
39
+
40
+ function memoryType(value: unknown): TeamMemoryType | null {
41
+ return typeof value === "string" && TEAM_MEMORY_TYPES.includes(value as TeamMemoryType)
42
+ ? (value as TeamMemoryType)
43
+ : null;
44
+ }
45
+
46
+ function starterCharter(profile: TeamProfile): string {
47
+ const roles = Object.keys(profile.roles ?? {}).sort();
48
+ const approval =
49
+ profile.approval?.mode === "off"
50
+ ? "No approval gates are configured for this profile."
51
+ : `High-risk editing tasks need lead approval for: ${(profile.approval?.labels ?? ["security", "database", "api-contract", "destructive", "migration", "auth", "payment"]).join(", ")}.`;
52
+ return [
53
+ `Use the ${profile.name} Team profile for this project.`,
54
+ profile.description ? `Profile intent: ${profile.description}.` : null,
55
+ roles.length > 0 ? `Planner may assign these roles: ${roles.join(", ")}.` : null,
56
+ approval,
57
+ "Keep Team memory current with decisions, interface notes, risks, and handoffs.",
58
+ ]
59
+ .filter(Boolean)
60
+ .join("\n\n");
61
+ }
62
+
63
+ function setup(cwd: string, params: CrewParams) {
64
+ const name = params.name ?? "migration-squad";
65
+ if (!teamStore.isValidProfileName(name)) {
66
+ return result("Error: invalid team profile name. Use letters, numbers, underscore, or hyphen.", {
67
+ mode: "team.setup",
68
+ error: "invalid_name",
69
+ });
70
+ }
71
+
72
+ const { team, profile, created } = teamStore.useProfile(cwd, name);
73
+ const existingCharter = teamStore.readCharter(cwd);
74
+ const customCharter =
75
+ typeof params.message === "string" && params.message.trim().length > 0 ? params.message : undefined;
76
+ const charter =
77
+ customCharter || !existingCharter
78
+ ? teamStore.writeCharter(cwd, profile.name, customCharter ?? starterCharter(profile))
79
+ : existingCharter;
80
+ const charterStatus = customCharter ? "updated" : existingCharter ? "kept" : "created";
81
+
82
+ const text = `Set up Team profile **${profile.name}**.
83
+
84
+ Profile: ${created ? "created editable JSON" : "activated"}
85
+ Charter: ${charterStatus}
86
+
87
+ Next:
88
+ - Plan with this Team context: \`pi_messenger({ action: "plan", prompt: "..." })\`
89
+ - Check Team status: \`pi_messenger({ action: "team.status" })\`
90
+ - Approve gated work with \`task.approve\`; reject with \`task.reject\` and feedback.`;
91
+
92
+ return result(text, {
93
+ mode: "team.setup",
94
+ team,
95
+ profile,
96
+ created,
97
+ charter,
98
+ charterStatus,
99
+ });
100
+ }
101
+
102
+ function profileList() {
103
+ const profiles = teamStore.listProfiles();
104
+ const text = `# Team Profiles\n\n${profiles.map(p => `- ${p.name}${p.description ? ` — ${p.description}` : ""}`).join("\n")}`;
105
+ return result(text, { mode: "team.profile.list", profiles });
106
+ }
107
+
108
+ function profileUse(cwd: string, params: CrewParams) {
109
+ if (!params.name)
110
+ return result("Error: name required for team.profile.use", { mode: "team.profile.use", error: "missing_name" });
111
+ if (!teamStore.isValidProfileName(params.name)) {
112
+ return result("Error: invalid team profile name. Use letters, numbers, underscore, or hyphen.", {
113
+ mode: "team.profile.use",
114
+ error: "invalid_name",
115
+ });
116
+ }
117
+ const { team, profile, created } = teamStore.useProfile(cwd, params.name);
118
+ const action = created ? "Created and activated" : "Activated";
119
+ return result(`${action} team profile **${profile.name}**.`, {
120
+ mode: "team.profile.use",
121
+ team,
122
+ profile,
123
+ created,
124
+ });
125
+ }
126
+
127
+ function profileSave(cwd: string, params: CrewParams) {
128
+ if (!params.name)
129
+ return result("Error: name required for team.profile.save", { mode: "team.profile.save", error: "missing_name" });
130
+ if (!teamStore.isValidProfileName(params.name)) {
131
+ return result("Error: invalid team profile name. Use letters, numbers, underscore, or hyphen.", {
132
+ mode: "team.profile.save",
133
+ error: "invalid_name",
134
+ });
135
+ }
136
+ const active = teamStore.getActiveTeam(cwd);
137
+ const activeProfile = teamStore.loadActiveProfile(cwd);
138
+ const profile: TeamProfile = {
139
+ ...(activeProfile ?? teamStore.defaultTeamProfile(params.name)),
140
+ name: params.name,
141
+ };
142
+ teamStore.saveProfile(profile);
143
+ const team = teamStore.setActiveTeam(cwd, active?.name ?? params.name, profile.name);
144
+ return result(`Saved team profile **${profile.name}**.`, { mode: "team.profile.save", team, profile });
145
+ }
146
+
147
+ function charterShow(cwd: string) {
148
+ const charter = teamStore.readCharter(cwd);
149
+ if (!charter) {
150
+ return result("No team charter found. Create one with `team.charter.create`.", {
151
+ mode: "team.charter.show",
152
+ charter: null,
153
+ exists: false,
154
+ });
155
+ }
156
+ return result(charter, {
157
+ mode: "team.charter.show",
158
+ charter,
159
+ exists: true,
160
+ });
161
+ }
162
+
163
+ function charterCreate(cwd: string, params: CrewParams) {
164
+ if (!params.name)
165
+ return result("Error: name required for team.charter.create", {
166
+ mode: "team.charter.create",
167
+ error: "missing_name",
168
+ });
169
+ if (!params.message)
170
+ return result("Error: message required for team.charter.create", {
171
+ mode: "team.charter.create",
172
+ error: "missing_message",
173
+ });
174
+ const charter = teamStore.writeCharter(cwd, params.name, params.message);
175
+ return result(`Created charter for **${params.name}**.`, {
176
+ mode: "team.charter.create",
177
+ charter,
178
+ team: teamStore.getActiveTeam(cwd),
179
+ });
180
+ }
181
+
182
+ function charterUpdate(cwd: string, params: CrewParams) {
183
+ if (!params.message)
184
+ return result("Error: message required for team.charter.update", {
185
+ mode: "team.charter.update",
186
+ error: "missing_message",
187
+ });
188
+ const charter = teamStore.updateCharter(cwd, params.message);
189
+ return result("Updated team charter.", { mode: "team.charter.update", charter, team: teamStore.getActiveTeam(cwd) });
190
+ }
191
+
192
+ function memoryNote(cwd: string, params: CrewParams, state: MessengerState) {
193
+ const type = memoryType(params.type);
194
+ if (!type)
195
+ return result("Error: type must be one of decision, interface, risk, or handoff", {
196
+ mode: "team.memory.note",
197
+ error: "invalid_type",
198
+ });
199
+ if (!params.message)
200
+ return result("Error: message required for team.memory.note", {
201
+ mode: "team.memory.note",
202
+ error: "missing_message",
203
+ });
204
+ const entry = teamStore.noteMemory(cwd, type, params.message, state.agentName || "unknown", params.id);
205
+ return result(`Saved team ${type} note.`, { mode: "team.memory.note", entry });
206
+ }
207
+
208
+ function memoryList(cwd: string, params: CrewParams) {
209
+ const type = params.type ? memoryType(params.type) : null;
210
+ if (params.type && !type)
211
+ return result("Error: type must be one of decision, interface, risk, or handoff", {
212
+ mode: "team.memory.list",
213
+ error: "invalid_type",
214
+ });
215
+ const entries = teamStore.listMemory(cwd, type ?? undefined, params.limit);
216
+ const text =
217
+ entries.length > 0
218
+ ? entries
219
+ .map(
220
+ entry => `- ${entry.ts} [${entry.type}] ${entry.message}${entry.taskId ? ` (${entry.taskId})` : ""}`,
221
+ )
222
+ .join("\n")
223
+ : "No team memory entries found.";
224
+ return result(text, { mode: "team.memory.list", type, entries });
225
+ }
226
+
227
+ function roles(cwd: string) {
228
+ const roles = teamStore.resolveRoles(cwd);
229
+ const profile = teamStore.loadActiveProfile(cwd);
230
+ const activeNames = Object.keys(profile?.roles ?? {}).sort();
231
+ const builtInNames = Object.keys(roles)
232
+ .filter(name => !activeNames.includes(name))
233
+ .sort();
234
+ const formatRole = (name: string) => {
235
+ const role = roles[name];
236
+ return `- ${name}${role?.description ? ` — ${role.description}` : ""}`;
237
+ };
238
+ const activeText =
239
+ activeNames.length > 0
240
+ ? `## Active profile roles\n${activeNames.map(formatRole).join("\n")}`
241
+ : "## Active profile roles\nNo Team profile is active.";
242
+ const availableText =
243
+ builtInNames.length > 0 ? `\n\n## Other available roles\n${builtInNames.map(formatRole).join("\n")}` : "";
244
+ const note =
245
+ "Team roles are labels and prompt context. Crew still runs tasks through Crew agents and does not launch pi-subagents.";
246
+ return result(`# Team Roles\n\n${note}\n\n${activeText}${availableText}`, {
247
+ mode: "team.roles",
248
+ activeRoles: activeNames,
249
+ availableRoles: builtInNames,
250
+ roles,
251
+ });
252
+ }
253
+
254
+ function status(cwd: string) {
255
+ const team = teamStore.getActiveTeam(cwd);
256
+ const profile = teamStore.loadActiveProfile(cwd);
257
+ const charter = teamStore.readCharter(cwd);
258
+ const roles = teamStore.resolveRoles(cwd);
259
+ const roleNames = Object.keys(roles).sort();
260
+ const activeRoleNames = Object.keys(profile?.roles ?? {}).sort();
261
+ const counts = teamStore.memoryCounts(cwd);
262
+ const needsLead = teamStore.needsLeadTasks(cwd);
263
+ const rejected = teamStore.rejectedTasks(cwd);
264
+ const approvalText =
265
+ needsLead.length > 0
266
+ ? `\nNeeds approval:\n${needsLead.map(t => `- ${t.id}: ${t.title} [${t.approval?.status ?? "pending"}]`).join("\n")}`
267
+ : "\nNeeds approval: none";
268
+ const rejectedText =
269
+ rejected.length > 0
270
+ ? `\nRejected tasks:\n${rejected.map(t => `- ${t.id}: ${t.title}${t.approval?.feedback ? ` — ${t.approval.feedback}` : ""}`).join("\n")}`
271
+ : "\nRejected tasks: none";
272
+ const nextAction =
273
+ rejected.length > 0
274
+ ? `Revise rejected work with: pi_messenger({ action: "task.revise", id: "${rejected[0].id}", prompt: "Address approval feedback" })`
275
+ : needsLead.length > 0
276
+ ? `Approve with: pi_messenger({ action: "task.approve", id: "${needsLead[0].id}" })`
277
+ : team
278
+ ? "Next: plan or run Crew work with this Team context."
279
+ : "Next: activate a sample profile, e.g. migration-squad, review-squad, or research-squad.";
280
+ const text = `Team: ${team?.name ?? "(none)"}\nProfile: ${profile?.name ?? team?.profile ?? "(none)"}\nCharter: ${charter ? "present" : "missing"}\nActive roles: ${activeRoleNames.length > 0 ? activeRoleNames.join(", ") : "none"}\nMemory: decisions ${counts.decision}, interfaces ${counts.interface}, risks ${counts.risk}, handoffs ${counts.handoff}${approvalText}${rejectedText}\n${nextAction}`;
281
+ return result(text, {
282
+ mode: "team.status",
283
+ team,
284
+ profile,
285
+ charterPresent: !!charter,
286
+ roles: roleNames,
287
+ activeRoles: activeRoleNames,
288
+ nextAction,
289
+ memoryCounts: counts,
290
+ needsLead: needsLead.map(t => ({ id: t.id, title: t.title, approval: t.approval })),
291
+ rejected: rejected.map(t => ({ id: t.id, title: t.title, approval: t.approval })),
292
+ taskCount: crewStore.getTasks(cwd).length,
293
+ });
294
+ }