@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.
- 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/utils/discover.ts
CHANGED
|
@@ -1,219 +1,221 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Crew - Agent & Skill Discovery
|
|
3
|
-
*
|
|
4
|
-
* Discovers agent definitions and skill files from extension,
|
|
5
|
-
* project, and user directories.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import * as fs from "node:fs";
|
|
9
|
-
import * as
|
|
10
|
-
import
|
|
11
|
-
import {
|
|
12
|
-
import
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
export
|
|
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
|
-
): CrewSkillInfo[] {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Crew - Agent & Skill Discovery
|
|
3
|
+
*
|
|
4
|
+
* Discovers agent definitions and skill files from extension,
|
|
5
|
+
* project, and user directories.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as fs from "node:fs";
|
|
9
|
+
import * as path from "node:path";
|
|
10
|
+
import { fileURLToPath } from "node:url";
|
|
11
|
+
import type { MaxOutputConfig } from "./truncate.ts";
|
|
12
|
+
import { getAgentDir } from "@linxiraos/pi-utils/dirs";
|
|
13
|
+
import { getProjectCrewDir } from "../../paths.ts";
|
|
14
|
+
import { isProjectAgentsTrusted } from "../../config.ts";
|
|
15
|
+
|
|
16
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
17
|
+
const __dirname = path.dirname(__filename);
|
|
18
|
+
const DEFAULT_EXTENSION_AGENTS_DIR = path.resolve(__dirname, "..", "agents");
|
|
19
|
+
const DEFAULT_EXTENSION_SKILLS_DIR = path.resolve(__dirname, "..", "skills");
|
|
20
|
+
|
|
21
|
+
export type CrewRole = "planner" | "worker" | "reviewer" | "analyst";
|
|
22
|
+
|
|
23
|
+
export interface CrewAgentConfig {
|
|
24
|
+
name: string;
|
|
25
|
+
description: string;
|
|
26
|
+
tools?: string[];
|
|
27
|
+
model?: string;
|
|
28
|
+
thinking?: string;
|
|
29
|
+
systemPrompt: string;
|
|
30
|
+
source: "extension" | "project";
|
|
31
|
+
filePath: string;
|
|
32
|
+
crewRole?: CrewRole;
|
|
33
|
+
maxOutput?: MaxOutputConfig;
|
|
34
|
+
parallel?: boolean;
|
|
35
|
+
retryable?: boolean;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function parseFrontmatter(content: string): { frontmatter: Record<string, unknown>; body: string } {
|
|
39
|
+
const normalized = content.replace(/\r\n/g, "\n");
|
|
40
|
+
if (!normalized.startsWith("---")) {
|
|
41
|
+
return { frontmatter: {}, body: normalized };
|
|
42
|
+
}
|
|
43
|
+
const endIndex = normalized.indexOf("\n---", 3);
|
|
44
|
+
if (endIndex === -1) {
|
|
45
|
+
return { frontmatter: {}, body: normalized };
|
|
46
|
+
}
|
|
47
|
+
const frontmatterBlock = normalized.slice(4, endIndex);
|
|
48
|
+
const body = normalized.slice(endIndex + 4).trim();
|
|
49
|
+
|
|
50
|
+
const frontmatter: Record<string, unknown> = {};
|
|
51
|
+
for (const line of frontmatterBlock.split("\n")) {
|
|
52
|
+
const match = line.match(/^([\w-]+):\s*(.*)$/);
|
|
53
|
+
if (match) {
|
|
54
|
+
let value: unknown = match[2].trim();
|
|
55
|
+
if ((value as string).startsWith('"') || (value as string).startsWith("'")) {
|
|
56
|
+
value = (value as string).slice(1, -1);
|
|
57
|
+
}
|
|
58
|
+
if ((value as string).startsWith("{") && (value as string).endsWith("}")) {
|
|
59
|
+
try {
|
|
60
|
+
const jsonStr = (value as string).replace(/(\w+):/g, '"$1":');
|
|
61
|
+
value = JSON.parse(jsonStr);
|
|
62
|
+
} catch {
|
|
63
|
+
// Keep as string if parse fails
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (value === "true") value = true;
|
|
67
|
+
if (value === "false") value = false;
|
|
68
|
+
frontmatter[match[1]] = value;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return { frontmatter, body };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function loadAgentsFromDir(dir: string, source: "extension" | "project"): CrewAgentConfig[] {
|
|
76
|
+
if (!fs.existsSync(dir)) return [];
|
|
77
|
+
const agents: CrewAgentConfig[] = [];
|
|
78
|
+
|
|
79
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
80
|
+
if (!entry.name.endsWith(".md")) continue;
|
|
81
|
+
if (!entry.isFile() && !entry.isSymbolicLink()) continue;
|
|
82
|
+
|
|
83
|
+
const filePath = path.join(dir, entry.name);
|
|
84
|
+
let content: string;
|
|
85
|
+
try {
|
|
86
|
+
content = fs.readFileSync(filePath, "utf-8");
|
|
87
|
+
} catch {
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const { frontmatter, body } = parseFrontmatter(content);
|
|
92
|
+
if (!frontmatter.name || !frontmatter.description) continue;
|
|
93
|
+
|
|
94
|
+
const tools = (frontmatter.tools as string)
|
|
95
|
+
?.split(",")
|
|
96
|
+
.map(t => t.trim())
|
|
97
|
+
.filter(Boolean);
|
|
98
|
+
|
|
99
|
+
agents.push({
|
|
100
|
+
name: frontmatter.name as string,
|
|
101
|
+
description: frontmatter.description as string,
|
|
102
|
+
tools: tools && tools.length > 0 ? tools : undefined,
|
|
103
|
+
model: frontmatter.model as string | undefined,
|
|
104
|
+
thinking: frontmatter.thinking as string | undefined,
|
|
105
|
+
systemPrompt: body,
|
|
106
|
+
source,
|
|
107
|
+
filePath,
|
|
108
|
+
crewRole: frontmatter.crewRole as CrewRole | undefined,
|
|
109
|
+
maxOutput: frontmatter.maxOutput as MaxOutputConfig | undefined,
|
|
110
|
+
parallel: (frontmatter.parallel as boolean | undefined) ?? true,
|
|
111
|
+
retryable: (frontmatter.retryable as boolean | undefined) ?? true,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return agents;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function discoverCrewAgents(cwd: string, extensionAgentsDir?: string): CrewAgentConfig[] {
|
|
119
|
+
const extDir = extensionAgentsDir ?? DEFAULT_EXTENSION_AGENTS_DIR;
|
|
120
|
+
// Project-supplied agent overrides load only when the project explicitly
|
|
121
|
+
// opted in (trustProjectAgents) — see isProjectAgentsTrusted.
|
|
122
|
+
const projectAgentsDir = path.join(getProjectCrewDir(cwd), "agents");
|
|
123
|
+
|
|
124
|
+
const extensionAgents = loadAgentsFromDir(extDir, "extension");
|
|
125
|
+
const projectAgents = isProjectAgentsTrusted(cwd) ? loadAgentsFromDir(projectAgentsDir, "project") : [];
|
|
126
|
+
|
|
127
|
+
const agentMap = new Map<string, CrewAgentConfig>();
|
|
128
|
+
for (const agent of extensionAgents) agentMap.set(agent.name, agent);
|
|
129
|
+
for (const agent of projectAgents) agentMap.set(agent.name, agent);
|
|
130
|
+
|
|
131
|
+
return Array.from(agentMap.values());
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// =============================================================================
|
|
135
|
+
// Skill Discovery
|
|
136
|
+
// =============================================================================
|
|
137
|
+
|
|
138
|
+
export interface CrewSkillInfo {
|
|
139
|
+
name: string;
|
|
140
|
+
description: string;
|
|
141
|
+
path: string;
|
|
142
|
+
source: "user" | "extension" | "project";
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function loadSkillsFromFlatDir(dir: string, source: "extension" | "project"): CrewSkillInfo[] {
|
|
146
|
+
if (!fs.existsSync(dir)) return [];
|
|
147
|
+
const skills: CrewSkillInfo[] = [];
|
|
148
|
+
|
|
149
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
150
|
+
if (!entry.name.endsWith(".md")) continue;
|
|
151
|
+
if (!entry.isFile() && !entry.isSymbolicLink()) continue;
|
|
152
|
+
|
|
153
|
+
const filePath = path.join(dir, entry.name);
|
|
154
|
+
let content: string;
|
|
155
|
+
try {
|
|
156
|
+
content = fs.readFileSync(filePath, "utf-8");
|
|
157
|
+
} catch {
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const { frontmatter } = parseFrontmatter(content);
|
|
162
|
+
if (!frontmatter.name || !frontmatter.description) continue;
|
|
163
|
+
|
|
164
|
+
skills.push({
|
|
165
|
+
name: frontmatter.name as string,
|
|
166
|
+
description: (frontmatter.description as string).split("\n")[0].trim(),
|
|
167
|
+
path: filePath,
|
|
168
|
+
source,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return skills;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function loadSkillsFromUserDir(dir: string): CrewSkillInfo[] {
|
|
176
|
+
if (!fs.existsSync(dir)) return [];
|
|
177
|
+
const skills: CrewSkillInfo[] = [];
|
|
178
|
+
|
|
179
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
180
|
+
if (!entry.isDirectory() && !entry.isSymbolicLink()) continue;
|
|
181
|
+
|
|
182
|
+
const skillFile = path.join(dir, entry.name, "SKILL.md");
|
|
183
|
+
let content: string;
|
|
184
|
+
try {
|
|
185
|
+
content = fs.readFileSync(skillFile, "utf-8");
|
|
186
|
+
} catch {
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const { frontmatter } = parseFrontmatter(content);
|
|
191
|
+
if (!frontmatter.name || !frontmatter.description) continue;
|
|
192
|
+
|
|
193
|
+
skills.push({
|
|
194
|
+
name: frontmatter.name as string,
|
|
195
|
+
description: (frontmatter.description as string).split("\n")[0].trim(),
|
|
196
|
+
path: skillFile,
|
|
197
|
+
source: "user",
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return skills;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export function discoverCrewSkills(cwd: string, extensionSkillsDir?: string, userSkillsDir?: string): CrewSkillInfo[] {
|
|
205
|
+
const extDir = extensionSkillsDir ?? DEFAULT_EXTENSION_SKILLS_DIR;
|
|
206
|
+
// Project-supplied skills load only when the project explicitly opted in
|
|
207
|
+
// (trustProjectAgents) — see isProjectAgentsTrusted.
|
|
208
|
+
const projectSkillsDir = path.join(getProjectCrewDir(cwd), "skills");
|
|
209
|
+
const userDir = userSkillsDir ?? path.join(getAgentDir(), "skills");
|
|
210
|
+
|
|
211
|
+
const userSkills = loadSkillsFromUserDir(userDir);
|
|
212
|
+
const extensionSkills = loadSkillsFromFlatDir(extDir, "extension");
|
|
213
|
+
const projectSkills = isProjectAgentsTrusted(cwd) ? loadSkillsFromFlatDir(projectSkillsDir, "project") : [];
|
|
214
|
+
|
|
215
|
+
const skillMap = new Map<string, CrewSkillInfo>();
|
|
216
|
+
for (const skill of userSkills) skillMap.set(skill.name, skill);
|
|
217
|
+
for (const skill of extensionSkills) skillMap.set(skill.name, skill);
|
|
218
|
+
for (const skill of projectSkills) skillMap.set(skill.name, skill);
|
|
219
|
+
|
|
220
|
+
return Array.from(skillMap.values());
|
|
221
|
+
}
|
package/crew/utils/install.ts
CHANGED
|
@@ -1,85 +1,94 @@
|
|
|
1
|
-
import * as fs from "node:fs";
|
|
2
|
-
import * as path from "node:path";
|
|
3
|
-
import { homedir } from "node:os";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { getAgentDir } from "@linxiraos/pi-utils/dirs";
|
|
5
|
+
|
|
6
|
+
const CREW_AGENTS = ["crew-planner.md", "crew-plan-sync.md", "crew-worker.md", "crew-reviewer.md"];
|
|
7
|
+
|
|
8
|
+
const DEPRECATED_AGENTS = [
|
|
9
|
+
"crew-repo-scout.md",
|
|
10
|
+
"crew-practice-scout.md",
|
|
11
|
+
"crew-docs-scout.md",
|
|
12
|
+
"crew-web-scout.md",
|
|
13
|
+
"crew-github-scout.md",
|
|
14
|
+
"crew-gap-analyst.md",
|
|
15
|
+
"crew-interview-generator.md",
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
const DEFAULT_MIGRATION_MARKER = "legacy-crew-agent-cleanup-v1.json";
|
|
19
|
+
|
|
20
|
+
export interface InstallOptions {
|
|
21
|
+
homeDir?: string;
|
|
22
|
+
migrationMarker?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function getTargetAgentsDir(homeDir: string): string {
|
|
26
|
+
// The legacy ~/.pi/agent/agents directory is exactly what this migration
|
|
27
|
+
// cleans up, so it intentionally stays in the pi tree.
|
|
28
|
+
return path.join(homeDir, ".pi", "agent", "agents");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function getMigrationMarkerPath(homeDir: string, marker: string): string {
|
|
32
|
+
// Markers live in the current messenger tree; pre-existing markers migrate
|
|
33
|
+
// together with the rest of ~/.pi/agent/messenger (crew/utils/migrations.ts).
|
|
34
|
+
const messengerDir =
|
|
35
|
+
homeDir === homedir() ? path.join(getAgentDir(), "messenger") : path.join(homeDir, ".zeta", "agent", "messenger");
|
|
36
|
+
return path.join(messengerDir, "migrations", marker);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function uninstallAgents(options: InstallOptions = {}): { removed: string[]; errors: string[] } {
|
|
40
|
+
const homeDir = options.homeDir ?? homedir();
|
|
41
|
+
const targetAgentsDir = getTargetAgentsDir(homeDir);
|
|
42
|
+
const removed: string[] = [];
|
|
43
|
+
const errors: string[] = [];
|
|
44
|
+
|
|
45
|
+
for (const agent of [...CREW_AGENTS, ...DEPRECATED_AGENTS]) {
|
|
46
|
+
const target = path.join(targetAgentsDir, agent);
|
|
47
|
+
try {
|
|
48
|
+
if (fs.existsSync(target)) {
|
|
49
|
+
fs.unlinkSync(target);
|
|
50
|
+
removed.push(agent);
|
|
51
|
+
}
|
|
52
|
+
} catch (err) {
|
|
53
|
+
errors.push(`Failed to remove ${agent}: ${err}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return { removed, errors };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function runLegacyAgentCleanupMigration(options: InstallOptions = {}): {
|
|
61
|
+
ran: boolean;
|
|
62
|
+
removed: string[];
|
|
63
|
+
errors: string[];
|
|
64
|
+
} {
|
|
65
|
+
const homeDir = options.homeDir ?? homedir();
|
|
66
|
+
const migrationMarker = options.migrationMarker ?? DEFAULT_MIGRATION_MARKER;
|
|
67
|
+
const markerPath = getMigrationMarkerPath(homeDir, migrationMarker);
|
|
68
|
+
|
|
69
|
+
if (fs.existsSync(markerPath)) {
|
|
70
|
+
return { ran: false, removed: [], errors: [] };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const uninstallResult = uninstallAgents({ homeDir });
|
|
74
|
+
|
|
75
|
+
try {
|
|
76
|
+
fs.mkdirSync(path.dirname(markerPath), { recursive: true });
|
|
77
|
+
fs.writeFileSync(
|
|
78
|
+
markerPath,
|
|
79
|
+
JSON.stringify(
|
|
80
|
+
{
|
|
81
|
+
migratedAt: new Date().toISOString(),
|
|
82
|
+
removed: uninstallResult.removed,
|
|
83
|
+
errors: uninstallResult.errors,
|
|
84
|
+
},
|
|
85
|
+
null,
|
|
86
|
+
2,
|
|
87
|
+
),
|
|
88
|
+
);
|
|
89
|
+
} catch (err) {
|
|
90
|
+
uninstallResult.errors.push(`Failed to persist migration marker: ${err}`);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return { ran: true, removed: uninstallResult.removed, errors: uninstallResult.errors };
|
|
94
|
+
}
|