@gjczone/pi-swarm 0.3.4 → 0.4.1
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 +11 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -6
- package/dist/index.js.map +1 -1
- package/dist/shared/controller.d.ts +1 -0
- package/dist/shared/controller.d.ts.map +1 -1
- package/dist/shared/controller.js +60 -2
- package/dist/shared/controller.js.map +1 -1
- package/dist/shared/spawner.d.ts.map +1 -1
- package/dist/shared/spawner.js +320 -78
- package/dist/shared/spawner.js.map +1 -1
- package/dist/shared/types.d.ts +28 -0
- package/dist/shared/types.d.ts.map +1 -1
- package/dist/shared/types.js +4 -1
- package/dist/shared/types.js.map +1 -1
- package/dist/shared/worktree.d.ts +81 -0
- package/dist/shared/worktree.d.ts.map +1 -0
- package/dist/shared/worktree.js +417 -0
- package/dist/shared/worktree.js.map +1 -0
- package/dist/state/persistence.d.ts +5 -0
- package/dist/state/persistence.d.ts.map +1 -1
- package/dist/state/persistence.js +1 -1
- package/dist/state/persistence.js.map +1 -1
- package/dist/state/recovery.d.ts.map +1 -1
- package/dist/state/recovery.js +13 -6
- package/dist/state/recovery.js.map +1 -1
- package/dist/swarm/command.d.ts +0 -4
- package/dist/swarm/command.d.ts.map +1 -1
- package/dist/swarm/command.js +1 -19
- package/dist/swarm/command.js.map +1 -1
- package/dist/swarm/tool.d.ts.map +1 -1
- package/dist/swarm/tool.js +59 -14
- package/dist/swarm/tool.js.map +1 -1
- package/dist/team/command.d.ts.map +1 -1
- package/dist/team/command.js +0 -8
- package/dist/team/command.js.map +1 -1
- package/dist/team/mailbox.d.ts +5 -0
- package/dist/team/mailbox.d.ts.map +1 -1
- package/dist/team/mailbox.js +46 -5
- package/dist/team/mailbox.js.map +1 -1
- package/dist/team/supervisor.d.ts +27 -2
- package/dist/team/supervisor.d.ts.map +1 -1
- package/dist/team/supervisor.js +84 -23
- package/dist/team/supervisor.js.map +1 -1
- package/dist/team/task-graph.d.ts +5 -2
- package/dist/team/task-graph.d.ts.map +1 -1
- package/dist/team/task-graph.js +27 -1
- package/dist/team/task-graph.js.map +1 -1
- package/dist/team/tool.d.ts.map +1 -1
- package/dist/team/tool.js +56 -8
- package/dist/team/tool.js.map +1 -1
- package/dist/tui/progress.d.ts +6 -43
- package/dist/tui/progress.d.ts.map +1 -1
- package/dist/tui/progress.js +101 -165
- package/dist/tui/progress.js.map +1 -1
- package/dist/tui/team-dashboard.d.ts +5 -22
- package/dist/tui/team-dashboard.d.ts.map +1 -1
- package/dist/tui/team-dashboard.js +87 -132
- package/dist/tui/team-dashboard.js.map +1 -1
- package/package.json +1 -1
package/dist/shared/types.d.ts
CHANGED
|
@@ -26,6 +26,10 @@ export interface SubagentResult<T = unknown> {
|
|
|
26
26
|
readonly result?: string;
|
|
27
27
|
/** Error message (for failed/aborted tasks). */
|
|
28
28
|
readonly error?: string;
|
|
29
|
+
/** Token usage for this subagent. */
|
|
30
|
+
readonly usage?: SubagentUsage;
|
|
31
|
+
/** Git worktree branch name (if worktree was used and changes committed). */
|
|
32
|
+
readonly worktreeBranch?: string;
|
|
29
33
|
}
|
|
30
34
|
/** A new subagent spawned from a template item. */
|
|
31
35
|
export interface SwarmSpawnSpec {
|
|
@@ -96,6 +100,9 @@ export interface RunSubagentOptions {
|
|
|
96
100
|
readonly runInBackground: boolean;
|
|
97
101
|
readonly signal: AbortSignal;
|
|
98
102
|
readonly onReady?: () => void;
|
|
103
|
+
readonly onUsage?: (usage: SubagentUsage) => void;
|
|
104
|
+
/** Callback for real-time messages sent by the agent via mailbox file writes. */
|
|
105
|
+
readonly onMessage?: (message: MailboxMessage) => void;
|
|
99
106
|
readonly suppressRateLimitFailureEvent?: boolean;
|
|
100
107
|
readonly timeout?: number;
|
|
101
108
|
readonly swarmRoot?: string;
|
|
@@ -104,6 +111,11 @@ export interface RunSubagentOptions {
|
|
|
104
111
|
readonly model?: string;
|
|
105
112
|
readonly tools?: string[];
|
|
106
113
|
readonly cwd?: string;
|
|
114
|
+
readonly useWorktree?: boolean;
|
|
115
|
+
/** Path to the shared mailbox root for real-time inter-agent communication. */
|
|
116
|
+
readonly mailboxPath?: string;
|
|
117
|
+
/** Role name for team agents (used to resolve mailbox paths). */
|
|
118
|
+
readonly roleName?: string;
|
|
107
119
|
}
|
|
108
120
|
/** Model tier for cost-optimized routing. */
|
|
109
121
|
export type ModelTier = "default" | "small";
|
|
@@ -121,6 +133,7 @@ export interface SpawnSubagentOptions extends RunSubagentOptions {
|
|
|
121
133
|
export interface SubagentCompletion {
|
|
122
134
|
readonly result: string;
|
|
123
135
|
readonly usage?: SubagentUsage;
|
|
136
|
+
readonly worktreeBranch?: string;
|
|
124
137
|
}
|
|
125
138
|
/** Handle to a running subagent. */
|
|
126
139
|
export interface SubagentHandle {
|
|
@@ -173,6 +186,16 @@ export interface BaseQueuedSubagentTask<T = unknown> {
|
|
|
173
186
|
readonly runId?: string;
|
|
174
187
|
/** Path to write per-agent output log (optional). */
|
|
175
188
|
readonly outputLogPath?: string;
|
|
189
|
+
/** Whether to use git worktree isolation (default: true for git repos). */
|
|
190
|
+
readonly useWorktree?: boolean;
|
|
191
|
+
/** Callback for real-time token usage updates (optional). */
|
|
192
|
+
readonly onUsage?: (usage: SubagentUsage) => void;
|
|
193
|
+
/** Callback for real-time messages via mailbox file writes (optional). */
|
|
194
|
+
readonly onMessage?: (message: MailboxMessage) => void;
|
|
195
|
+
/** Path to the shared mailbox root for real-time inter-agent communication (optional). */
|
|
196
|
+
readonly mailboxPath?: string;
|
|
197
|
+
/** Role name for team agents (optional, used for mailbox routing). */
|
|
198
|
+
readonly roleName?: string;
|
|
176
199
|
}
|
|
177
200
|
/** A task that spawns a NEW subagent. */
|
|
178
201
|
export interface SpawnQueuedSubagentTask<T = unknown> extends BaseQueuedSubagentTask<T> {
|
|
@@ -211,6 +234,7 @@ export interface TeamProgressSnapshot {
|
|
|
211
234
|
readonly phases: ReadonlyArray<TeamPhaseStatus>;
|
|
212
235
|
readonly mailboxCount: number;
|
|
213
236
|
readonly startedAt: number;
|
|
237
|
+
readonly totalUsage: SubagentUsage;
|
|
214
238
|
}
|
|
215
239
|
/** Per-phase status in a team progress snapshot. */
|
|
216
240
|
export interface TeamPhaseStatus {
|
|
@@ -218,6 +242,7 @@ export interface TeamPhaseStatus {
|
|
|
218
242
|
readonly role: AgentRole;
|
|
219
243
|
readonly status: "queued" | "running" | "completed" | "failed" | "skipped";
|
|
220
244
|
readonly error?: string;
|
|
245
|
+
readonly usage?: SubagentUsage;
|
|
221
246
|
}
|
|
222
247
|
/** Callback for team progress updates. */
|
|
223
248
|
export type TeamProgressCallback = (snapshot: TeamProgressSnapshot) => void;
|
|
@@ -229,6 +254,8 @@ export interface BatchProgressSnapshot {
|
|
|
229
254
|
readonly active: number;
|
|
230
255
|
readonly queued: number;
|
|
231
256
|
readonly members: ReadonlyArray<BatchMemberStatus>;
|
|
257
|
+
readonly totalUsage: SubagentUsage;
|
|
258
|
+
readonly startedAt: number;
|
|
232
259
|
}
|
|
233
260
|
/** Per-member status in a progress snapshot. */
|
|
234
261
|
export interface BatchMemberStatus {
|
|
@@ -236,6 +263,7 @@ export interface BatchMemberStatus {
|
|
|
236
263
|
readonly phase: "queued" | "working" | "completed" | "failed" | "suspended";
|
|
237
264
|
readonly item?: string;
|
|
238
265
|
readonly error?: string;
|
|
266
|
+
readonly usage?: SubagentUsage;
|
|
239
267
|
}
|
|
240
268
|
/** Emitted when a subagent is suspended due to rate limiting. */
|
|
241
269
|
export interface SubagentSuspendedEvent {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/shared/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,mDAAmD;AACnD,MAAM,MAAM,aAAa,GACrB,SAAS,GACT,WAAW,GACX,SAAS,GACT,WAAW,GACX,QAAQ,GACR,WAAW,GACX,WAAW,CAAC;AAEhB,0CAA0C;AAC1C,M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AAsB;IACrC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAMD;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,KAAK,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IAC9D,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IAC9E,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;CAC9E"}
|
package/dist/shared/types.js
CHANGED
|
@@ -5,5 +5,8 @@
|
|
|
5
5
|
* No pi or tui imports — pure data types.
|
|
6
6
|
*/
|
|
7
7
|
/** Roles that automatically use the small/fast model when configured. */
|
|
8
|
-
export const SMALL_MODEL_ROLES = new Set([
|
|
8
|
+
export const SMALL_MODEL_ROLES = new Set([
|
|
9
|
+
"explorer",
|
|
10
|
+
"tester",
|
|
11
|
+
]);
|
|
9
12
|
//# sourceMappingURL=types.js.map
|
package/dist/shared/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/shared/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/shared/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA+JH,yEAAyE;AACzE,MAAM,CAAC,MAAM,iBAAiB,GAAwB,IAAI,GAAG,CAAC;IAC5D,UAAU;IACV,QAAQ;CACT,CAAC,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* worktree - Git worktree isolation for subagents.
|
|
3
|
+
*
|
|
4
|
+
* Creates a temporary git worktree so an agent works on an isolated copy of the repo.
|
|
5
|
+
* On completion:
|
|
6
|
+
* - If no changes: worktree is removed.
|
|
7
|
+
* - If changes exist: committed to a new branch, worktree is removed.
|
|
8
|
+
* - The caller is responsible for merging the branch back (see mergeBranch).
|
|
9
|
+
*
|
|
10
|
+
* Safety:
|
|
11
|
+
* - Non-git repos silently fall back to cwd (no worktree created).
|
|
12
|
+
* - Symbolic links to node_modules are created to avoid reinstalling dependencies.
|
|
13
|
+
* - Each worktree is created from HEAD in detached mode; changes are committed to a
|
|
14
|
+
* uniquely-named branch to avoid collisions.
|
|
15
|
+
*
|
|
16
|
+
* Reference implementation: gotgenes/pi-subagents-worktrees, pi-crew worktree-manager.
|
|
17
|
+
*/
|
|
18
|
+
export interface WorktreeInfo {
|
|
19
|
+
path: string;
|
|
20
|
+
branch: string;
|
|
21
|
+
originalBranch: string;
|
|
22
|
+
originalHead: string;
|
|
23
|
+
repoCwd: string;
|
|
24
|
+
mailboxLinkCreated?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export interface WorktreeCleanupResult {
|
|
27
|
+
hasChanges: boolean;
|
|
28
|
+
branch?: string;
|
|
29
|
+
}
|
|
30
|
+
export interface MergeResult {
|
|
31
|
+
success: boolean;
|
|
32
|
+
branch: string;
|
|
33
|
+
error?: string;
|
|
34
|
+
mergedCommit?: string;
|
|
35
|
+
}
|
|
36
|
+
export interface SubagentWorktreeResult {
|
|
37
|
+
worktreeUsed: boolean;
|
|
38
|
+
branch?: string;
|
|
39
|
+
hasChanges: boolean;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Detect whether cwd is inside a git repository.
|
|
43
|
+
*/
|
|
44
|
+
export declare function isGitRepository(cwd: string): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Create a temporary worktree for a subagent.
|
|
47
|
+
* Returns undefined if not in a git repo or worktree creation fails.
|
|
48
|
+
*
|
|
49
|
+
* 业务说明:为子 agent 创建临时 git worktree 实现目录隔离。
|
|
50
|
+
* worktree 基于 HEAD 的 detached 状态创建,确保不污染主分支。
|
|
51
|
+
* 同时符号链接项目上下文文件(AGENTS.md、.pi 等)和 mailbox 目录,
|
|
52
|
+
* 这样子 agent 可以访问项目规则并实时读写 mailbox 消息。
|
|
53
|
+
* 记录原始分支名和 HEAD SHA 用于后续合并。
|
|
54
|
+
*/
|
|
55
|
+
export declare function createWorktree(cwd: string, agentId: string, mailboxPath?: string): WorktreeInfo | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Clean up the worktree after agent completion.
|
|
58
|
+
*
|
|
59
|
+
* Steps:
|
|
60
|
+
* 1. Check for changes in worktree.
|
|
61
|
+
* 2. If no changes: remove worktree, return { hasChanges: false }.
|
|
62
|
+
* 3. If changes: add + commit to a new branch based on the commit, remove worktree.
|
|
63
|
+
*
|
|
64
|
+
* Note: This function does NOT merge back to the original branch.
|
|
65
|
+
* Call mergeBranch() after all agents in a batch complete for safe merging.
|
|
66
|
+
*
|
|
67
|
+
* 业务说明:子 agent 完成后清理 worktree。有变更则提交到新分支,
|
|
68
|
+
* 不自动合并——合并应在批处理完成后顺序执行以避免竞争条件。
|
|
69
|
+
*/
|
|
70
|
+
export declare function cleanupWorktree(cwd: string, worktree: WorktreeInfo, agentDescription: string): WorktreeCleanupResult;
|
|
71
|
+
/**
|
|
72
|
+
* Merge a branch into the current branch.
|
|
73
|
+
* Must be called when the working directory is clean (no parallel agents running).
|
|
74
|
+
* Uses --no-ff --no-edit to create a merge commit preserving history.
|
|
75
|
+
*
|
|
76
|
+
* 业务说明:将子 agent 的分支合并到当前分支。必须在工作目录干净时调用
|
|
77
|
+
* (所有并行 agent 完成后顺序执行)。冲突时返回错误信息并保留分支供手动解决。
|
|
78
|
+
*/
|
|
79
|
+
export declare function mergeBranch(cwd: string, branchName: string): MergeResult;
|
|
80
|
+
export declare function pruneWorktrees(cwd: string): void;
|
|
81
|
+
//# sourceMappingURL=worktree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worktree.d.ts","sourceRoot":"","sources":["../../src/shared/worktree.ts"],"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|
2
|
+
* worktree - Git worktree isolation for subagents.
|
|
3
|
+
*
|
|
4
|
+
* Creates a temporary git worktree so an agent works on an isolated copy of the repo.
|
|
5
|
+
* On completion:
|
|
6
|
+
* - If no changes: worktree is removed.
|
|
7
|
+
* - If changes exist: committed to a new branch, worktree is removed.
|
|
8
|
+
* - The caller is responsible for merging the branch back (see mergeBranch).
|
|
9
|
+
*
|
|
10
|
+
* Safety:
|
|
11
|
+
* - Non-git repos silently fall back to cwd (no worktree created).
|
|
12
|
+
* - Symbolic links to node_modules are created to avoid reinstalling dependencies.
|
|
13
|
+
* - Each worktree is created from HEAD in detached mode; changes are committed to a
|
|
14
|
+
* uniquely-named branch to avoid collisions.
|
|
15
|
+
*
|
|
16
|
+
* Reference implementation: gotgenes/pi-subagents-worktrees, pi-crew worktree-manager.
|
|
17
|
+
*/
|
|
18
|
+
import { execFileSync } from "node:child_process";
|
|
19
|
+
import { randomUUID } from "node:crypto";
|
|
20
|
+
import { existsSync, mkdirSync, symlinkSync, statSync, } from "node:fs";
|
|
21
|
+
import { tmpdir } from "node:os";
|
|
22
|
+
import { join, dirname } from "node:path";
|
|
23
|
+
/**
|
|
24
|
+
* Detect whether cwd is inside a git repository.
|
|
25
|
+
*/
|
|
26
|
+
export function isGitRepository(cwd) {
|
|
27
|
+
try {
|
|
28
|
+
execFileSync("git", ["rev-parse", "--is-inside-work-tree"], {
|
|
29
|
+
cwd,
|
|
30
|
+
stdio: "pipe",
|
|
31
|
+
timeout: 5000,
|
|
32
|
+
});
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Get the current branch name or "HEAD" if detached.
|
|
41
|
+
*/
|
|
42
|
+
function getCurrentBranch(cwd) {
|
|
43
|
+
try {
|
|
44
|
+
const name = execFileSync("git", ["rev-parse", "--abbrev-ref", "HEAD"], {
|
|
45
|
+
cwd,
|
|
46
|
+
stdio: "pipe",
|
|
47
|
+
timeout: 5000,
|
|
48
|
+
})
|
|
49
|
+
.toString()
|
|
50
|
+
.trim();
|
|
51
|
+
return name || "HEAD";
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return "HEAD";
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Get the current HEAD commit SHA.
|
|
59
|
+
*/
|
|
60
|
+
function getCurrentHead(cwd) {
|
|
61
|
+
try {
|
|
62
|
+
return execFileSync("git", ["rev-parse", "HEAD"], {
|
|
63
|
+
cwd,
|
|
64
|
+
stdio: "pipe",
|
|
65
|
+
timeout: 5000,
|
|
66
|
+
})
|
|
67
|
+
.toString()
|
|
68
|
+
.trim();
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
return "";
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Check if the working directory is clean (no uncommitted changes).
|
|
76
|
+
*/
|
|
77
|
+
function isWorkingTreeClean(cwd) {
|
|
78
|
+
try {
|
|
79
|
+
const status = execFileSync("git", ["status", "--porcelain"], {
|
|
80
|
+
cwd,
|
|
81
|
+
stdio: "pipe",
|
|
82
|
+
timeout: 5000,
|
|
83
|
+
})
|
|
84
|
+
.toString()
|
|
85
|
+
.trim();
|
|
86
|
+
return status.length === 0;
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Files/directories to symlink from repo root into worktree for project context.
|
|
94
|
+
* These contain project rules, config, and state that subagents need access to.
|
|
95
|
+
*/
|
|
96
|
+
const PROJECT_CONTEXT_ENTRIES = [
|
|
97
|
+
"AGENTS.md",
|
|
98
|
+
"CLAUDE.md",
|
|
99
|
+
".pi",
|
|
100
|
+
".cursorrules",
|
|
101
|
+
".cursor",
|
|
102
|
+
".github",
|
|
103
|
+
"docs",
|
|
104
|
+
"rules",
|
|
105
|
+
];
|
|
106
|
+
/**
|
|
107
|
+
* Create a temporary worktree for a subagent.
|
|
108
|
+
* Returns undefined if not in a git repo or worktree creation fails.
|
|
109
|
+
*
|
|
110
|
+
* 业务说明:为子 agent 创建临时 git worktree 实现目录隔离。
|
|
111
|
+
* worktree 基于 HEAD 的 detached 状态创建,确保不污染主分支。
|
|
112
|
+
* 同时符号链接项目上下文文件(AGENTS.md、.pi 等)和 mailbox 目录,
|
|
113
|
+
* 这样子 agent 可以访问项目规则并实时读写 mailbox 消息。
|
|
114
|
+
* 记录原始分支名和 HEAD SHA 用于后续合并。
|
|
115
|
+
*/
|
|
116
|
+
export function createWorktree(cwd, agentId, mailboxPath) {
|
|
117
|
+
if (!isGitRepository(cwd))
|
|
118
|
+
return undefined;
|
|
119
|
+
try {
|
|
120
|
+
execFileSync("git", ["rev-parse", "HEAD"], {
|
|
121
|
+
cwd,
|
|
122
|
+
stdio: "pipe",
|
|
123
|
+
timeout: 5000,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
return undefined;
|
|
128
|
+
}
|
|
129
|
+
const originalBranch = getCurrentBranch(cwd);
|
|
130
|
+
const originalHead = getCurrentHead(cwd);
|
|
131
|
+
const branch = `pi-agent-${agentId}`;
|
|
132
|
+
const suffix = randomUUID().slice(0, 8);
|
|
133
|
+
const worktreePath = join(tmpdir(), `pi-agent-${agentId}-${suffix}`);
|
|
134
|
+
try {
|
|
135
|
+
execFileSync("git", ["worktree", "add", "--detach", worktreePath, "HEAD"], {
|
|
136
|
+
cwd,
|
|
137
|
+
stdio: "pipe",
|
|
138
|
+
timeout: 30000,
|
|
139
|
+
});
|
|
140
|
+
// Symlink node_modules to avoid reinstalling dependencies in every worktree
|
|
141
|
+
try {
|
|
142
|
+
const nodeModulesSource = join(cwd, "node_modules");
|
|
143
|
+
const nodeModulesTarget = join(worktreePath, "node_modules");
|
|
144
|
+
if (existsSync(nodeModulesSource) && !existsSync(nodeModulesTarget)) {
|
|
145
|
+
symlinkSync(nodeModulesSource, nodeModulesTarget, "dir");
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
// node_modules symlink failure is non-fatal; agent can still work
|
|
150
|
+
}
|
|
151
|
+
// Symlink project context files that are not tracked by git
|
|
152
|
+
// (AGENTS.md, .pi config, etc.) so subagents inherit project rules
|
|
153
|
+
let mailboxLinkCreated = false;
|
|
154
|
+
for (const entry of PROJECT_CONTEXT_ENTRIES) {
|
|
155
|
+
const sourcePath = join(cwd, entry);
|
|
156
|
+
const targetPath = join(worktreePath, entry);
|
|
157
|
+
if (!existsSync(sourcePath) || existsSync(targetPath))
|
|
158
|
+
continue;
|
|
159
|
+
try {
|
|
160
|
+
const stat = statSync(sourcePath);
|
|
161
|
+
symlinkSync(sourcePath, targetPath, stat.isDirectory() ? "dir" : "file");
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
// Best effort per-entry symlink
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
// Symlink mailbox directory into worktree so subagents can read/write messages in real time
|
|
168
|
+
if (mailboxPath && existsSync(mailboxPath)) {
|
|
169
|
+
const mailboxTarget = join(worktreePath, ".pi", "swarm", "mailbox-link");
|
|
170
|
+
try {
|
|
171
|
+
mkdirSync(dirname(mailboxTarget), { recursive: true });
|
|
172
|
+
if (!existsSync(mailboxTarget)) {
|
|
173
|
+
symlinkSync(mailboxPath, mailboxTarget, "dir");
|
|
174
|
+
mailboxLinkCreated = true;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
catch {
|
|
178
|
+
// Best effort mailbox link
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return {
|
|
182
|
+
path: worktreePath,
|
|
183
|
+
branch,
|
|
184
|
+
originalBranch,
|
|
185
|
+
originalHead,
|
|
186
|
+
repoCwd: cwd,
|
|
187
|
+
mailboxLinkCreated,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
catch {
|
|
191
|
+
return undefined;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Clean up the worktree after agent completion.
|
|
196
|
+
*
|
|
197
|
+
* Steps:
|
|
198
|
+
* 1. Check for changes in worktree.
|
|
199
|
+
* 2. If no changes: remove worktree, return { hasChanges: false }.
|
|
200
|
+
* 3. If changes: add + commit to a new branch based on the commit, remove worktree.
|
|
201
|
+
*
|
|
202
|
+
* Note: This function does NOT merge back to the original branch.
|
|
203
|
+
* Call mergeBranch() after all agents in a batch complete for safe merging.
|
|
204
|
+
*
|
|
205
|
+
* 业务说明:子 agent 完成后清理 worktree。有变更则提交到新分支,
|
|
206
|
+
* 不自动合并——合并应在批处理完成后顺序执行以避免竞争条件。
|
|
207
|
+
*/
|
|
208
|
+
export function cleanupWorktree(cwd, worktree, agentDescription) {
|
|
209
|
+
if (!existsSync(worktree.path)) {
|
|
210
|
+
return { hasChanges: false };
|
|
211
|
+
}
|
|
212
|
+
try {
|
|
213
|
+
const status = execFileSync("git", ["status", "--porcelain"], {
|
|
214
|
+
cwd: worktree.path,
|
|
215
|
+
stdio: "pipe",
|
|
216
|
+
timeout: 10000,
|
|
217
|
+
})
|
|
218
|
+
.toString()
|
|
219
|
+
.trim();
|
|
220
|
+
if (!status) {
|
|
221
|
+
removeWorktree(cwd, worktree.path);
|
|
222
|
+
return { hasChanges: false };
|
|
223
|
+
}
|
|
224
|
+
// Stage all changes
|
|
225
|
+
execFileSync("git", ["add", "-A"], {
|
|
226
|
+
cwd: worktree.path,
|
|
227
|
+
stdio: "pipe",
|
|
228
|
+
timeout: 10000,
|
|
229
|
+
});
|
|
230
|
+
// Commit in worktree
|
|
231
|
+
const safeDesc = agentDescription.slice(0, 200);
|
|
232
|
+
const commitMsg = `pi-agent: ${safeDesc}`;
|
|
233
|
+
execFileSync("git", ["commit", "-m", commitMsg], {
|
|
234
|
+
cwd: worktree.path,
|
|
235
|
+
stdio: "pipe",
|
|
236
|
+
timeout: 10000,
|
|
237
|
+
});
|
|
238
|
+
// Get the commit SHA from worktree
|
|
239
|
+
const commitSha = execFileSync("git", ["rev-parse", "HEAD"], {
|
|
240
|
+
cwd: worktree.path,
|
|
241
|
+
stdio: "pipe",
|
|
242
|
+
timeout: 5000,
|
|
243
|
+
})
|
|
244
|
+
.toString()
|
|
245
|
+
.trim();
|
|
246
|
+
// Remove worktree first so we can create the branch in the main repo
|
|
247
|
+
removeWorktree(cwd, worktree.path);
|
|
248
|
+
// Create branch pointing to the commit in the main repo
|
|
249
|
+
let branchName = worktree.branch;
|
|
250
|
+
try {
|
|
251
|
+
execFileSync("git", ["branch", branchName, commitSha], {
|
|
252
|
+
cwd,
|
|
253
|
+
stdio: "pipe",
|
|
254
|
+
timeout: 5000,
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
catch {
|
|
258
|
+
branchName = `${worktree.branch}-${Date.now()}`;
|
|
259
|
+
try {
|
|
260
|
+
execFileSync("git", ["branch", branchName, commitSha], {
|
|
261
|
+
cwd,
|
|
262
|
+
stdio: "pipe",
|
|
263
|
+
timeout: 5000,
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
catch {
|
|
267
|
+
return { hasChanges: true }; // Commit exists but branch creation failed; user can find by SHA
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
return { hasChanges: true, branch: branchName };
|
|
271
|
+
}
|
|
272
|
+
catch (err) {
|
|
273
|
+
try {
|
|
274
|
+
removeWorktree(cwd, worktree.path);
|
|
275
|
+
}
|
|
276
|
+
catch {
|
|
277
|
+
// best effort cleanup
|
|
278
|
+
}
|
|
279
|
+
return { hasChanges: false };
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Merge a branch into the current branch.
|
|
284
|
+
* Must be called when the working directory is clean (no parallel agents running).
|
|
285
|
+
* Uses --no-ff --no-edit to create a merge commit preserving history.
|
|
286
|
+
*
|
|
287
|
+
* 业务说明:将子 agent 的分支合并到当前分支。必须在工作目录干净时调用
|
|
288
|
+
* (所有并行 agent 完成后顺序执行)。冲突时返回错误信息并保留分支供手动解决。
|
|
289
|
+
*/
|
|
290
|
+
export function mergeBranch(cwd, branchName) {
|
|
291
|
+
try {
|
|
292
|
+
if (!isWorkingTreeClean(cwd)) {
|
|
293
|
+
return {
|
|
294
|
+
success: false,
|
|
295
|
+
branch: branchName,
|
|
296
|
+
error: `Working directory is dirty. Merge branch '${branchName}' manually after committing/stashing changes.`,
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
// Verify the branch exists
|
|
300
|
+
try {
|
|
301
|
+
execFileSync("git", ["rev-parse", "--verify", branchName], {
|
|
302
|
+
cwd,
|
|
303
|
+
stdio: "pipe",
|
|
304
|
+
timeout: 5000,
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
catch {
|
|
308
|
+
return {
|
|
309
|
+
success: false,
|
|
310
|
+
branch: branchName,
|
|
311
|
+
error: `Branch '${branchName}' not found.`,
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
// Check if already merged by seeing if the branch commit is an ancestor of HEAD
|
|
315
|
+
try {
|
|
316
|
+
execFileSync("git", ["merge-base", "--is-ancestor", branchName, "HEAD"], {
|
|
317
|
+
cwd,
|
|
318
|
+
stdio: "pipe",
|
|
319
|
+
timeout: 5000,
|
|
320
|
+
});
|
|
321
|
+
// Already merged; clean up branch
|
|
322
|
+
try {
|
|
323
|
+
execFileSync("git", ["branch", "-d", branchName], {
|
|
324
|
+
cwd,
|
|
325
|
+
stdio: "pipe",
|
|
326
|
+
timeout: 5000,
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
catch {
|
|
330
|
+
// Best effort cleanup
|
|
331
|
+
}
|
|
332
|
+
return { success: true, branch: branchName };
|
|
333
|
+
}
|
|
334
|
+
catch {
|
|
335
|
+
// Not yet merged, proceed
|
|
336
|
+
}
|
|
337
|
+
// Attempt merge with --no-ff --no-edit
|
|
338
|
+
execFileSync("git", ["merge", "--no-ff", "--no-edit", branchName], {
|
|
339
|
+
cwd,
|
|
340
|
+
stdio: "pipe",
|
|
341
|
+
timeout: 30000,
|
|
342
|
+
});
|
|
343
|
+
// Clean up feature branch after successful merge
|
|
344
|
+
try {
|
|
345
|
+
execFileSync("git", ["branch", "-d", branchName], {
|
|
346
|
+
cwd,
|
|
347
|
+
stdio: "pipe",
|
|
348
|
+
timeout: 5000,
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
catch {
|
|
352
|
+
// Branch deletion failure is non-fatal
|
|
353
|
+
}
|
|
354
|
+
return { success: true, branch: branchName };
|
|
355
|
+
}
|
|
356
|
+
catch (err) {
|
|
357
|
+
const stderr = err instanceof Error ? err.message : String(err);
|
|
358
|
+
// Attempt to abort if a merge is in progress
|
|
359
|
+
try {
|
|
360
|
+
execFileSync("git", ["merge", "--abort"], {
|
|
361
|
+
cwd,
|
|
362
|
+
stdio: "pipe",
|
|
363
|
+
timeout: 5000,
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
catch {
|
|
367
|
+
// Merge abort may fail if no merge was in progress
|
|
368
|
+
}
|
|
369
|
+
if (stderr.includes("CONFLICT") ||
|
|
370
|
+
stderr.includes("Automatic merge failed")) {
|
|
371
|
+
return {
|
|
372
|
+
success: false,
|
|
373
|
+
branch: branchName,
|
|
374
|
+
error: `Merge conflicts detected. Resolve manually: git merge ${branchName}`,
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
return {
|
|
378
|
+
success: false,
|
|
379
|
+
branch: branchName,
|
|
380
|
+
error: `Auto-merge failed: ${stderr}`,
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
function removeWorktree(cwd, worktreePath) {
|
|
385
|
+
try {
|
|
386
|
+
execFileSync("git", ["worktree", "remove", "--force", worktreePath], {
|
|
387
|
+
cwd,
|
|
388
|
+
stdio: "pipe",
|
|
389
|
+
timeout: 10000,
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
catch {
|
|
393
|
+
try {
|
|
394
|
+
execFileSync("git", ["worktree", "prune"], {
|
|
395
|
+
cwd,
|
|
396
|
+
stdio: "pipe",
|
|
397
|
+
timeout: 5000,
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
catch {
|
|
401
|
+
// best effort prune
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
export function pruneWorktrees(cwd) {
|
|
406
|
+
try {
|
|
407
|
+
execFileSync("git", ["worktree", "prune"], {
|
|
408
|
+
cwd,
|
|
409
|
+
stdio: "pipe",
|
|
410
|
+
timeout: 5000,
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
catch {
|
|
414
|
+
// best effort
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
//# sourceMappingURL=worktree.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worktree.js","sourceRoot":"","sources":["../../src/shared/worktree.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,YAAY,EAAY,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EACL,UAAU,EACV,SAAS,EACT,WAAW,EAGX,QAAQ,GACT,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAY,MAAM,WAAW,CAAC;AA6BpD;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,GAAW;IACzC,IAAI,CAAC;QACH,YAAY,CAAC,KAAK,EAAE,CAAC,WAAW,EAAE,uBAAuB,CAAC,EAAE;YAC1D,GAAG;YACH,KAAK,EAAE,MAAM;YACb,OAAO,EAAE,IAAI;SACd,CAAC,CAAC;QACH,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,C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,CAAC;AACH,CAAC;AAED,SAAS,cAAc,CAAC,GAAW,EAAE,YAAoB;IACvD,IAAI,CAAC;QACH,YAAY,CAAC,KAAK,EAAE,CAAC,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,YAAY,CAAC,EAAE;YACnE,GAAG;YACH,KAAK,EAAE,MAAM;YACb,OAAO,EAAE,KAAK;SACf,CAAC,CAAC;IACL,CAAC;IAAC,MAAM,CAAC;QACP,IAAI,CAAC;YACH,YAAY,CAAC,KAAK,EAAE,CAAC,UAAU,EAAE,OAAO,CAAC,EAAE;gBACzC,GAAG;gBACH,KAAK,EAAE,MAAM;gBACb,OAAO,EAAE,IAAI;aACd,CAAC,CAAC;QACL,CAAC;QAAC,MAAM,CAAC;YACP,oBAAoB;QACtB,CAAC;IACH,CAAC;AACH,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,GAAW;IACxC,IAAI,CAAC;QACH,YAAY,CAAC,KAAK,EAAE,CAAC,UAAU,EAAE,OAAO,CAAC,EAAE;YACzC,GAAG;YACH,KAAK,EAAE,MAAM;YACb,OAAO,EAAE,IAAI;SACd,CAAC,CAAC;IACL,CAAC;IAAC,MAAM,CAAC;QACP,cAAc;IAChB,CAAC;AACH,CAAC"}
|
|
@@ -99,4 +99,9 @@ export declare function listActiveRuns(swarmRoot: string): string[];
|
|
|
99
99
|
* Delete the entire run state directory.
|
|
100
100
|
*/
|
|
101
101
|
export declare function deleteRunState(swarmRoot: string, runId: string): void;
|
|
102
|
+
/**
|
|
103
|
+
* Write a file atomically using a temp file + rename.
|
|
104
|
+
* On POSIX rename is atomic; on Windows it replaces the target.
|
|
105
|
+
*/
|
|
106
|
+
export declare function writeAtomic(filePath: string, content: string): void;
|
|
102
107
|
//# sourceMappingURL=persistence.d.ts.map
|