@leing2021/super-pi 0.22.1 → 0.23.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.
Files changed (117) hide show
  1. package/README.md +66 -293
  2. package/extensions/ce-core/index.ts +276 -48
  3. package/extensions/ce-core/tools/parallel-subagent.ts +3 -3
  4. package/extensions/ce-core/tools/subagent.ts +2 -2
  5. package/package.json +4 -20
  6. package/rules/common/naming.md +154 -0
  7. package/skills/01-brainstorm/SKILL.md +42 -79
  8. package/skills/01-brainstorm/references/ce-brainstorm-mode.md +47 -0
  9. package/skills/02-plan/SKILL.md +43 -61
  10. package/skills/02-plan/references/solution-search.md +46 -0
  11. package/skills/03-work/SKILL.md +34 -52
  12. package/skills/03-work/references/completion-report.md +51 -0
  13. package/skills/04-review/SKILL.md +44 -51
  14. package/skills/04-review/references/solution-search.md +46 -0
  15. package/skills/06-next/SKILL.md +35 -20
  16. package/skills/06-next/references/recommendation-logic.md +47 -2
  17. package/skills/07-worktree/SKILL.md +21 -20
  18. package/skills/08-help/SKILL.md +46 -0
  19. package/skills/08-help/references/workflow-sequence.md +135 -0
  20. package/skills/references/language-detection.md +44 -0
  21. package/LICENSE +0 -21
  22. package/THIRD-PARTY-NOTICES.md +0 -35
  23. package/extensions/subagent/__tests__/async-job-tracker.test.ts +0 -21
  24. package/extensions/subagent/__tests__/execution-activity.test.ts +0 -15
  25. package/extensions/subagent/__tests__/parallel-render-stress.test.ts +0 -82
  26. package/extensions/subagent/__tests__/render-dedup.test.ts +0 -98
  27. package/extensions/subagent/__tests__/render-widget.test.ts +0 -28
  28. package/extensions/subagent/__tests__/throttle.test.ts +0 -90
  29. package/extensions/subagent/agent-management.ts +0 -596
  30. package/extensions/subagent/agent-manager-chain-detail.ts +0 -163
  31. package/extensions/subagent/agent-manager-detail.ts +0 -232
  32. package/extensions/subagent/agent-manager-edit.ts +0 -391
  33. package/extensions/subagent/agent-manager-list.ts +0 -279
  34. package/extensions/subagent/agent-manager-parallel.ts +0 -305
  35. package/extensions/subagent/agent-manager.ts +0 -706
  36. package/extensions/subagent/agent-scope.ts +0 -9
  37. package/extensions/subagent/agent-selection.ts +0 -26
  38. package/extensions/subagent/agent-serializer.ts +0 -124
  39. package/extensions/subagent/agent-templates.ts +0 -63
  40. package/extensions/subagent/agents/context-builder.md +0 -37
  41. package/extensions/subagent/agents/delegate.md +0 -9
  42. package/extensions/subagent/agents/oracle.md +0 -73
  43. package/extensions/subagent/agents/planner.md +0 -52
  44. package/extensions/subagent/agents/researcher.md +0 -50
  45. package/extensions/subagent/agents/reviewer.md +0 -38
  46. package/extensions/subagent/agents/scout.md +0 -48
  47. package/extensions/subagent/agents/worker.md +0 -52
  48. package/extensions/subagent/agents.ts +0 -762
  49. package/extensions/subagent/artifacts.ts +0 -101
  50. package/extensions/subagent/async-execution.ts +0 -521
  51. package/extensions/subagent/async-job-tracker.ts +0 -240
  52. package/extensions/subagent/async-status.ts +0 -242
  53. package/extensions/subagent/chain-clarify.ts +0 -1365
  54. package/extensions/subagent/chain-execution.ts +0 -854
  55. package/extensions/subagent/chain-serializer.ts +0 -127
  56. package/extensions/subagent/completion-dedupe.ts +0 -66
  57. package/extensions/subagent/doctor.ts +0 -201
  58. package/extensions/subagent/execution.ts +0 -748
  59. package/extensions/subagent/file-coalescer.ts +0 -43
  60. package/extensions/subagent/fork-context.ts +0 -64
  61. package/extensions/subagent/formatters.ts +0 -123
  62. package/extensions/subagent/frontmatter.ts +0 -32
  63. package/extensions/subagent/index.ts +0 -586
  64. package/extensions/subagent/intercom-bridge.ts +0 -241
  65. package/extensions/subagent/jsonl-writer.ts +0 -84
  66. package/extensions/subagent/model-fallback.ts +0 -109
  67. package/extensions/subagent/notify.ts +0 -111
  68. package/extensions/subagent/parallel-utils.ts +0 -109
  69. package/extensions/subagent/pi-args.ts +0 -139
  70. package/extensions/subagent/pi-spawn.ts +0 -101
  71. package/extensions/subagent/post-exit-stdio-guard.ts +0 -88
  72. package/extensions/subagent/prompt-template-bridge.ts +0 -400
  73. package/extensions/subagent/prompts/gather-context-and-clarify.md +0 -13
  74. package/extensions/subagent/prompts/parallel-cleanup.md +0 -42
  75. package/extensions/subagent/prompts/parallel-research.md +0 -50
  76. package/extensions/subagent/prompts/parallel-review.md +0 -40
  77. package/extensions/subagent/render-helpers.ts +0 -83
  78. package/extensions/subagent/render.ts +0 -908
  79. package/extensions/subagent/result-intercom.ts +0 -238
  80. package/extensions/subagent/result-watcher.ts +0 -172
  81. package/extensions/subagent/run-history.ts +0 -58
  82. package/extensions/subagent/run-status.ts +0 -137
  83. package/extensions/subagent/schemas.ts +0 -165
  84. package/extensions/subagent/session-tokens.ts +0 -51
  85. package/extensions/subagent/settings.ts +0 -368
  86. package/extensions/subagent/single-output.ts +0 -98
  87. package/extensions/subagent/skills.ts +0 -627
  88. package/extensions/subagent/slash-bridge.ts +0 -177
  89. package/extensions/subagent/slash-commands.ts +0 -304
  90. package/extensions/subagent/slash-live-state.ts +0 -295
  91. package/extensions/subagent/subagent-control.ts +0 -151
  92. package/extensions/subagent/subagent-executor.ts +0 -1915
  93. package/extensions/subagent/subagent-prompt-runtime.ts +0 -76
  94. package/extensions/subagent/subagent-runner.ts +0 -1471
  95. package/extensions/subagent/subagents-status.ts +0 -473
  96. package/extensions/subagent/text-editor.ts +0 -273
  97. package/extensions/subagent/throttle.ts +0 -77
  98. package/extensions/subagent/top-level-async.ts +0 -16
  99. package/extensions/subagent/types.ts +0 -624
  100. package/extensions/subagent/utils.ts +0 -457
  101. package/extensions/subagent/worktree.ts +0 -580
  102. package/extensions/super-pi-extension/agents/ce-oracle.md +0 -109
  103. package/extensions/super-pi-extension/agents/ce-planner.md +0 -116
  104. package/extensions/super-pi-extension/agents/ce-reviewer.md +0 -99
  105. package/extensions/super-pi-extension/agents/ce-scout.md +0 -80
  106. package/extensions/super-pi-extension/agents/ce-worker.md +0 -78
  107. package/extensions/super-pi-extension/chains/ce-parallel-review.chain.md +0 -34
  108. package/extensions/super-pi-extension/chains/ce-review-only.chain.md +0 -12
  109. package/extensions/super-pi-extension/chains/ce-standard.chain.md +0 -28
  110. package/extensions/super-pi-extension/index.ts +0 -129
  111. package/extensions/super-pi-extension/model-sync.ts +0 -204
  112. package/skills/08-status/SKILL.md +0 -41
  113. package/skills/08-status/references/artifact-locations.md +0 -10
  114. package/skills/09-help/SKILL.md +0 -37
  115. package/skills/09-help/references/workflow-sequence.md +0 -9
  116. package/skills/10-rules/SKILL.md +0 -76
  117. package/skills/pi-subagents/SKILL.md +0 -566
@@ -1,580 +0,0 @@
1
- // SPDX-FileCopyrightText: 2025 Nico Bailon
2
- // SPDX-License-Identifier: MIT
3
- // Source: https://github.com/nicobailon/pi-subagents
4
- import { spawnSync } from "node:child_process";
5
- import * as fs from "node:fs";
6
- import * as os from "node:os";
7
- import * as path from "node:path";
8
-
9
- export interface WorktreeSetup {
10
- cwd: string;
11
- worktrees: WorktreeInfo[];
12
- baseCommit: string;
13
- }
14
-
15
- export interface WorktreeInfo {
16
- path: string;
17
- agentCwd: string;
18
- branch: string;
19
- index: number;
20
- nodeModulesLinked: boolean;
21
- syntheticPaths: string[];
22
- }
23
-
24
- export interface WorktreeDiff {
25
- index: number;
26
- agent: string;
27
- branch: string;
28
- diffStat: string;
29
- filesChanged: number;
30
- insertions: number;
31
- deletions: number;
32
- patchPath: string;
33
- }
34
-
35
- export interface WorktreeTaskCwdConflict {
36
- index: number;
37
- agent: string;
38
- cwd: string;
39
- }
40
-
41
- export interface WorktreeSetupHookConfig {
42
- hookPath: string;
43
- timeoutMs?: number;
44
- }
45
-
46
- export interface CreateWorktreesOptions {
47
- agents?: string[];
48
- setupHook?: WorktreeSetupHookConfig;
49
- }
50
-
51
- interface ResolvedWorktreeSetupHook {
52
- hookPath: string;
53
- timeoutMs: number;
54
- }
55
-
56
- interface WorktreeSetupHookInput {
57
- version: 1;
58
- repoRoot: string;
59
- worktreePath: string;
60
- agentCwd: string;
61
- branch: string;
62
- index: number;
63
- runId: string;
64
- baseCommit: string;
65
- agent?: string;
66
- }
67
-
68
- interface WorktreeSetupHookOutput {
69
- syntheticPaths?: string[];
70
- }
71
-
72
- interface GitResult {
73
- stdout: string;
74
- stderr: string;
75
- status: number | null;
76
- }
77
-
78
- interface RepoState {
79
- toplevel: string;
80
- cwdRelative: string;
81
- baseCommit: string;
82
- }
83
-
84
- const DEFAULT_WORKTREE_SETUP_HOOK_TIMEOUT_MS = 30000;
85
-
86
- function runGit(cwd: string, args: string[]): GitResult {
87
- const result = spawnSync("git", ["-C", cwd, ...args], { encoding: "utf-8" });
88
- return {
89
- stdout: result.stdout ?? "",
90
- stderr: result.stderr ?? "",
91
- status: result.status,
92
- };
93
- }
94
-
95
- function runGitChecked(cwd: string, args: string[]): string {
96
- const result = runGit(cwd, args);
97
- if (result.status !== 0) {
98
- const command = `git -C ${cwd} ${args.join(" ")}`;
99
- const message = result.stderr.trim() || result.stdout.trim() || `${command} failed`;
100
- throw new Error(message);
101
- }
102
- return result.stdout;
103
- }
104
-
105
- function resolveRepoState(cwd: string): RepoState {
106
- const cwdRelative = resolveRepoCwdRelative(cwd);
107
- const toplevel = runGitChecked(cwd, ["rev-parse", "--show-toplevel"]).trim();
108
-
109
- const status = runGitChecked(toplevel, ["status", "--porcelain"]);
110
- if (status.trim().length > 0) {
111
- throw new Error("worktree isolation requires a clean git working tree. Commit or stash changes first.");
112
- }
113
-
114
- const baseCommit = runGitChecked(toplevel, ["rev-parse", "HEAD"]).trim();
115
- return { toplevel, cwdRelative, baseCommit };
116
- }
117
-
118
- function normalizeComparableCwd(cwd: string): string {
119
- const resolved = path.resolve(cwd);
120
- try {
121
- return fs.realpathSync(resolved);
122
- } catch {
123
- // Use the unresolved absolute path when realpath resolution is unavailable.
124
- return resolved;
125
- }
126
- }
127
-
128
- export function findWorktreeTaskCwdConflict(
129
- tasks: ReadonlyArray<{ agent: string; cwd?: string }>,
130
- sharedCwd: string,
131
- ): WorktreeTaskCwdConflict | undefined {
132
- const normalizedSharedCwd = normalizeComparableCwd(sharedCwd);
133
- for (let index = 0; index < tasks.length; index++) {
134
- const task = tasks[index]!;
135
- if (!task.cwd) continue;
136
- const taskCwd = path.isAbsolute(task.cwd) ? task.cwd : path.resolve(sharedCwd, task.cwd);
137
- if (normalizeComparableCwd(taskCwd) === normalizedSharedCwd) continue;
138
- return { index, agent: task.agent, cwd: task.cwd };
139
- }
140
- return undefined;
141
- }
142
-
143
- export function formatWorktreeTaskCwdConflict(
144
- conflict: WorktreeTaskCwdConflict,
145
- sharedCwd: string,
146
- ): string {
147
- return `worktree isolation uses the shared cwd (${sharedCwd}); task ${conflict.index + 1} (${conflict.agent}) sets cwd to ${conflict.cwd}. Remove task-level cwd overrides or disable worktree.`;
148
- }
149
-
150
- function safePatchAgentName(agent: string): string {
151
- return agent.replace(/[^\w.-]/g, "_");
152
- }
153
-
154
- function buildWorktreeBranch(runId: string, index: number): string {
155
- return `pi-parallel-${runId}-${index}`;
156
- }
157
-
158
- function buildWorktreePath(runId: string, index: number): string {
159
- return path.join(os.tmpdir(), `pi-worktree-${runId}-${index}`);
160
- }
161
-
162
- function resolveRepoCwdRelative(cwd: string): string {
163
- const repoCheck = runGit(cwd, ["rev-parse", "--is-inside-work-tree"]);
164
- if (repoCheck.status !== 0 || repoCheck.stdout.trim() !== "true") {
165
- throw new Error("worktree isolation requires a git repository");
166
- }
167
- const rawPrefix = runGitChecked(cwd, ["rev-parse", "--show-prefix"]).trim();
168
- const normalizedPrefix = rawPrefix
169
- ? path.normalize(rawPrefix.replace(/[\\/]+$/, ""))
170
- : "";
171
- return normalizedPrefix === "." ? "" : normalizedPrefix;
172
- }
173
-
174
- export function resolveExpectedWorktreeAgentCwd(cwd: string, runId: string, index: number): string {
175
- const cwdRelative = resolveRepoCwdRelative(cwd);
176
- const worktreePath = buildWorktreePath(runId, index);
177
- return cwdRelative ? path.join(worktreePath, cwdRelative) : worktreePath;
178
- }
179
-
180
- function linkNodeModulesIfPresent(toplevel: string, worktreePath: string): boolean {
181
- const nodeModulesPath = path.join(toplevel, "node_modules");
182
- const nodeModulesLinkPath = path.join(worktreePath, "node_modules");
183
- if (!fs.existsSync(nodeModulesPath) || fs.existsSync(nodeModulesLinkPath)) return false;
184
- try {
185
- fs.symlinkSync(nodeModulesPath, nodeModulesLinkPath);
186
- return true;
187
- } catch {
188
- // Symlink creation is optional (e.g., unsupported filesystems on CI runners).
189
- return false;
190
- }
191
- }
192
-
193
- function parseHookTimeout(timeoutMs: number | undefined): number {
194
- if (timeoutMs === undefined) return DEFAULT_WORKTREE_SETUP_HOOK_TIMEOUT_MS;
195
- if (!Number.isInteger(timeoutMs) || timeoutMs <= 0) {
196
- throw new Error("worktree setup hook timeout must be an integer greater than 0");
197
- }
198
- return timeoutMs;
199
- }
200
-
201
- function resolveWorktreeSetupHook(
202
- repoRoot: string,
203
- config: WorktreeSetupHookConfig | undefined,
204
- ): ResolvedWorktreeSetupHook | undefined {
205
- if (!config) return undefined;
206
- const hookPath = config.hookPath.trim();
207
- if (!hookPath) {
208
- throw new Error("worktree setup hook path cannot be empty");
209
- }
210
-
211
- const expandedHookPath = hookPath.startsWith("~/") ? path.join(os.homedir(), hookPath.slice(2)) : hookPath;
212
- let resolvedPath: string;
213
- if (path.isAbsolute(expandedHookPath)) {
214
- resolvedPath = expandedHookPath;
215
- } else if (expandedHookPath.includes("/") || expandedHookPath.includes("\\")) {
216
- resolvedPath = path.resolve(repoRoot, expandedHookPath);
217
- } else {
218
- throw new Error("worktree setup hook must be an absolute path or a repo-relative path");
219
- }
220
-
221
- if (!fs.existsSync(resolvedPath)) {
222
- throw new Error(`worktree setup hook not found: ${resolvedPath}`);
223
- }
224
- if (fs.statSync(resolvedPath).isDirectory()) {
225
- throw new Error(`worktree setup hook must be a file, got directory: ${resolvedPath}`);
226
- }
227
-
228
- return {
229
- hookPath: resolvedPath,
230
- timeoutMs: parseHookTimeout(config.timeoutMs),
231
- };
232
- }
233
-
234
- function normalizeSyntheticPath(worktreePath: string, rawPath: string): string {
235
- const trimmed = rawPath.trim();
236
- if (!trimmed) throw new Error("synthetic path cannot be empty");
237
- if (path.isAbsolute(trimmed)) throw new Error(`synthetic path must be relative: ${rawPath}`);
238
-
239
- const resolved = path.resolve(worktreePath, trimmed);
240
- const relative = path.relative(worktreePath, resolved);
241
- if (!relative || relative === ".") {
242
- throw new Error(`synthetic path cannot target the worktree root: ${rawPath}`);
243
- }
244
- if (relative === ".." || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) {
245
- throw new Error(`synthetic path escapes the worktree root: ${rawPath}`);
246
- }
247
- return path.normalize(relative);
248
- }
249
-
250
- function hasTrackedEntries(worktreePath: string, relativePath: string): boolean {
251
- const result = runGit(worktreePath, ["ls-files", "--", relativePath]);
252
- return result.status === 0 && result.stdout.trim().length > 0;
253
- }
254
-
255
- function parseWorktreeSetupHookOutput(rawStdout: string): WorktreeSetupHookOutput {
256
- const trimmed = rawStdout.trim();
257
- if (!trimmed) {
258
- throw new Error("worktree setup hook returned empty stdout; expected JSON object");
259
- }
260
- let parsed: unknown;
261
- try {
262
- parsed = JSON.parse(trimmed);
263
- } catch (error) {
264
- const message = error instanceof Error ? error.message : String(error);
265
- throw new Error(`worktree setup hook returned invalid JSON: ${message}`);
266
- }
267
- if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
268
- throw new Error("worktree setup hook stdout must be a JSON object");
269
- }
270
- return parsed as WorktreeSetupHookOutput;
271
- }
272
-
273
- function runWorktreeSetupHook(
274
- hook: ResolvedWorktreeSetupHook,
275
- input: WorktreeSetupHookInput,
276
- ): string[] {
277
- const result = spawnSync(hook.hookPath, [], {
278
- cwd: input.worktreePath,
279
- encoding: "utf-8",
280
- input: JSON.stringify(input),
281
- timeout: hook.timeoutMs,
282
- shell: false,
283
- });
284
-
285
- if (result.error) {
286
- const code = "code" in result.error ? result.error.code : undefined;
287
- if (code === "ETIMEDOUT") {
288
- throw new Error(`worktree setup hook timed out after ${hook.timeoutMs}ms`);
289
- }
290
- throw new Error(`worktree setup hook failed: ${result.error.message}`);
291
- }
292
-
293
- if (result.status !== 0) {
294
- const details = result.stderr.trim() || result.stdout.trim() || "no output";
295
- throw new Error(`worktree setup hook failed with exit code ${result.status}: ${details}`);
296
- }
297
-
298
- const output = parseWorktreeSetupHookOutput(result.stdout);
299
- if (output.syntheticPaths === undefined) return [];
300
- if (!Array.isArray(output.syntheticPaths)) {
301
- throw new Error("worktree setup hook output field 'syntheticPaths' must be an array of relative paths");
302
- }
303
-
304
- const uniquePaths = new Set<string>();
305
- for (const candidate of output.syntheticPaths) {
306
- if (typeof candidate !== "string") {
307
- throw new Error("worktree setup hook output field 'syntheticPaths' must contain only strings");
308
- }
309
- const normalizedPath = normalizeSyntheticPath(input.worktreePath, candidate);
310
- if (hasTrackedEntries(input.worktreePath, normalizedPath)) {
311
- throw new Error(`worktree setup hook cannot mark tracked paths as synthetic: ${normalizedPath}`);
312
- }
313
- uniquePaths.add(normalizedPath);
314
- }
315
- return [...uniquePaths];
316
- }
317
-
318
- function createSingleWorktree(
319
- toplevel: string,
320
- cwdRelative: string,
321
- runId: string,
322
- index: number,
323
- baseCommit: string,
324
- setupHook: ResolvedWorktreeSetupHook | undefined,
325
- agent: string | undefined,
326
- ): WorktreeInfo {
327
- const branch = buildWorktreeBranch(runId, index);
328
- const worktreePath = buildWorktreePath(runId, index);
329
- const add = runGit(toplevel, ["worktree", "add", worktreePath, "-b", branch, "HEAD"]);
330
- if (add.status !== 0) {
331
- const message = add.stderr.trim() || add.stdout.trim() || `failed to create worktree ${worktreePath}`;
332
- throw new Error(message);
333
- }
334
-
335
- const agentCwd = cwdRelative ? path.join(worktreePath, cwdRelative) : worktreePath;
336
- try {
337
- const nodeModulesLinked = linkNodeModulesIfPresent(toplevel, worktreePath);
338
- const syntheticPaths = nodeModulesLinked ? ["node_modules"] : [];
339
-
340
- if (setupHook) {
341
- const hookSyntheticPaths = runWorktreeSetupHook(setupHook, {
342
- version: 1,
343
- repoRoot: toplevel,
344
- worktreePath,
345
- agentCwd,
346
- branch,
347
- index,
348
- runId,
349
- baseCommit,
350
- agent,
351
- });
352
- syntheticPaths.push(...hookSyntheticPaths);
353
- }
354
-
355
- return {
356
- path: worktreePath,
357
- agentCwd,
358
- branch,
359
- index,
360
- nodeModulesLinked,
361
- syntheticPaths,
362
- };
363
- } catch (error) {
364
- try { runGitChecked(toplevel, ["worktree", "remove", "--force", worktreePath]); } catch {
365
- // Best-effort rollback; preserve the original setup failure.
366
- }
367
- try { runGitChecked(toplevel, ["branch", "-D", branch]); } catch {
368
- // Best-effort rollback; preserve the original setup failure.
369
- }
370
- throw error;
371
- }
372
- }
373
-
374
- function removeSyntheticPath(worktree: WorktreeInfo, syntheticPath: string): void {
375
- const resolved = path.resolve(worktree.path, syntheticPath);
376
- const relative = path.relative(worktree.path, resolved);
377
- if (!relative || relative === "." || relative === ".." || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) {
378
- return;
379
- }
380
-
381
- let stat: fs.Stats;
382
- try {
383
- stat = fs.lstatSync(resolved);
384
- } catch (error) {
385
- const code = error && typeof error === "object" && "code" in error ? (error as { code?: unknown }).code : undefined;
386
- if (code === "ENOENT") return;
387
- throw error;
388
- }
389
-
390
- if (stat.isSymbolicLink()) {
391
- fs.unlinkSync(resolved);
392
- return;
393
- }
394
- if (stat.isDirectory()) {
395
- fs.rmSync(resolved, { recursive: true, force: true });
396
- return;
397
- }
398
- fs.rmSync(resolved, { force: true });
399
- }
400
-
401
- function removeSyntheticPathsBeforeDiff(worktree: WorktreeInfo): void {
402
- if (worktree.syntheticPaths.length === 0) return;
403
- const seen = new Set<string>();
404
- for (const syntheticPath of worktree.syntheticPaths) {
405
- if (seen.has(syntheticPath)) continue;
406
- seen.add(syntheticPath);
407
- removeSyntheticPath(worktree, syntheticPath);
408
- }
409
- }
410
-
411
- function emptyDiff(index: number, agent: string, branch: string, patchPath: string): WorktreeDiff {
412
- return {
413
- index,
414
- agent,
415
- branch,
416
- diffStat: "",
417
- filesChanged: 0,
418
- insertions: 0,
419
- deletions: 0,
420
- patchPath,
421
- };
422
- }
423
-
424
- function parseNumstat(numstat: string): { filesChanged: number; insertions: number; deletions: number } {
425
- const lines = numstat
426
- .split("\n")
427
- .map((line) => line.trim())
428
- .filter(Boolean);
429
- let filesChanged = 0;
430
- let insertions = 0;
431
- let deletions = 0;
432
-
433
- for (const line of lines) {
434
- const [rawInsertions, rawDeletions] = line.split("\t");
435
- if (rawInsertions === undefined || rawDeletions === undefined) continue;
436
- filesChanged++;
437
- if (/^\d+$/.test(rawInsertions)) insertions += parseInt(rawInsertions, 10);
438
- if (/^\d+$/.test(rawDeletions)) deletions += parseInt(rawDeletions, 10);
439
- }
440
-
441
- return { filesChanged, insertions, deletions };
442
- }
443
-
444
- function captureWorktreeDiff(
445
- setup: WorktreeSetup,
446
- worktree: WorktreeInfo,
447
- agent: string,
448
- patchPath: string,
449
- ): WorktreeDiff {
450
- removeSyntheticPathsBeforeDiff(worktree);
451
- runGitChecked(worktree.path, ["add", "-A"]);
452
- const diffStat = runGitChecked(worktree.path, ["diff", "--cached", "--stat", setup.baseCommit]).trim();
453
- const patch = runGitChecked(worktree.path, ["diff", "--cached", setup.baseCommit]);
454
- const numstat = runGitChecked(worktree.path, ["diff", "--cached", "--numstat", setup.baseCommit]);
455
- fs.writeFileSync(patchPath, patch, "utf-8");
456
-
457
- if (!patch.trim()) {
458
- return emptyDiff(worktree.index, agent, worktree.branch, patchPath);
459
- }
460
-
461
- const parsed = parseNumstat(numstat);
462
- return {
463
- index: worktree.index,
464
- agent,
465
- branch: worktree.branch,
466
- diffStat,
467
- filesChanged: parsed.filesChanged,
468
- insertions: parsed.insertions,
469
- deletions: parsed.deletions,
470
- patchPath,
471
- };
472
- }
473
-
474
- function writeEmptyPatch(patchPath: string): void {
475
- try {
476
- fs.writeFileSync(patchPath, "", "utf-8");
477
- } catch {
478
- // Diff artifact writing is best-effort in error paths.
479
- }
480
- }
481
-
482
- function cleanupSingleWorktree(repoCwd: string, worktree: WorktreeInfo): void {
483
- try { runGitChecked(repoCwd, ["worktree", "remove", "--force", worktree.path]); } catch {
484
- // Cleanup is best-effort to avoid masking caller errors.
485
- }
486
- try { runGitChecked(repoCwd, ["branch", "-D", worktree.branch]); } catch {
487
- // Cleanup is best-effort to avoid masking caller errors.
488
- }
489
- }
490
-
491
- function hasWorktreeChanges(diff: WorktreeDiff): boolean {
492
- return diff.filesChanged > 0 || diff.insertions > 0 || diff.deletions > 0 || diff.diffStat.trim().length > 0;
493
- }
494
-
495
- export function createWorktrees(cwd: string, runId: string, count: number, options?: CreateWorktreesOptions): WorktreeSetup {
496
- const repo = resolveRepoState(cwd);
497
- const setupHook = resolveWorktreeSetupHook(repo.toplevel, options?.setupHook);
498
- const worktrees: WorktreeInfo[] = [];
499
-
500
- try {
501
- for (let index = 0; index < count; index++) {
502
- worktrees.push(createSingleWorktree(
503
- repo.toplevel,
504
- repo.cwdRelative,
505
- runId,
506
- index,
507
- repo.baseCommit,
508
- setupHook,
509
- options?.agents?.[index],
510
- ));
511
- }
512
- } catch (error) {
513
- cleanupWorktrees({
514
- cwd: repo.toplevel,
515
- worktrees,
516
- baseCommit: repo.baseCommit,
517
- });
518
- throw error;
519
- }
520
-
521
- return {
522
- cwd: repo.toplevel,
523
- worktrees,
524
- baseCommit: repo.baseCommit,
525
- };
526
- }
527
-
528
- export function diffWorktrees(setup: WorktreeSetup, agents: string[], diffsDir: string): WorktreeDiff[] {
529
- try {
530
- fs.mkdirSync(diffsDir, { recursive: true });
531
- } catch {
532
- // Returning no diffs is safer than failing the whole command on artifact-dir issues.
533
- return [];
534
- }
535
-
536
- const diffs: WorktreeDiff[] = [];
537
- for (let index = 0; index < setup.worktrees.length; index++) {
538
- const worktree = setup.worktrees[index]!;
539
- const agent = agents[index] ?? `task-${index + 1}`;
540
- const patchPath = path.join(diffsDir, `task-${index}-${safePatchAgentName(agent)}.patch`);
541
- try {
542
- diffs.push(captureWorktreeDiff(setup, worktree, agent, patchPath));
543
- } catch {
544
- // Preserve execution flow; failed diff capture maps to an empty per-task patch.
545
- writeEmptyPatch(patchPath);
546
- diffs.push(emptyDiff(index, agent, worktree.branch, patchPath));
547
- }
548
- }
549
-
550
- return diffs;
551
- }
552
-
553
- export function cleanupWorktrees(setup: WorktreeSetup): void {
554
- for (let index = setup.worktrees.length - 1; index >= 0; index--) {
555
- cleanupSingleWorktree(setup.cwd, setup.worktrees[index]!);
556
- }
557
- try { runGitChecked(setup.cwd, ["worktree", "prune"]); } catch {
558
- // Pruning is best-effort cleanup.
559
- }
560
- }
561
-
562
- export function formatWorktreeDiffSummary(diffs: WorktreeDiff[]): string {
563
- const changed = diffs.filter(hasWorktreeChanges);
564
- if (changed.length === 0) return "";
565
-
566
- const lines: string[] = ["=== Worktree Changes ===", ""];
567
- for (const diff of changed) {
568
- lines.push(
569
- `--- Task ${diff.index + 1} (${diff.agent}): ${diff.filesChanged} files changed, +${diff.insertions} -${diff.deletions} ---`,
570
- );
571
- if (diff.diffStat.trim().length > 0) {
572
- lines.push(diff.diffStat);
573
- }
574
- lines.push("");
575
- }
576
-
577
- const patchesDir = path.dirname(changed[0]!.patchPath);
578
- lines.push(`Full patches: ${patchesDir}`);
579
- return lines.join("\n").trimEnd();
580
- }
@@ -1,109 +0,0 @@
1
- ---
2
- name: ce-oracle
3
- description: Compound Engineering 决策顾问,在行动前提供第二意见
4
- tools: read, bash, grep, find, glob, ls, mcp
5
- systemPromptMode: replace
6
- inheritProjectContext: true
7
- inheritSkills: true
8
- ---
9
-
10
- # CE-Oracle: Compound Engineering 决策顾问
11
-
12
- 你是 Compound Engineering 工作流中的决策顾问代理。
13
-
14
- ## 核心职责
15
-
16
- 在用户行动之前提供第二意见:
17
- - 质疑假设
18
- - 捕捉偏离
19
- - 推荐最安全的下一步
20
-
21
- ## 使用场景
22
-
23
- 使用 oracle 当:
24
- - 计划可能遗漏关键风险
25
- - 存在多条可行路径需要抉择
26
- - 技术决策影响深远
27
- - 需要挑战现有方向
28
-
29
- ## 执行规则
30
-
31
- ### 不编辑原则
32
- - 不修改任何文件
33
- - 不写代码或测试
34
- - 只分析和建议
35
-
36
- ### 质疑框架
37
-
38
- 对每个方案追问:
39
- 1. **假设是什么?** 这些假设是否可靠?
40
- 2. **最坏情况?** 如果失败,会发生什么?
41
- 3. **回退成本?** 恢复到当前状态需要多少工作?
42
- 4. **是否可逆?** 这个决策是否是单向的?
43
- 5. **机会成本?** 做这个 vs 不做的代价?
44
-
45
- ### 决策矩阵
46
-
47
- 对于多方案评估,提供:
48
-
49
- \`\`\`markdown
50
- ## 方案 A vs 方案 B
51
-
52
- | 维度 | 方案 A | 方案 B |
53
- |------|--------|--------|
54
- | 开发时间 | | |
55
- | 维护成本 | | |
56
- | 可扩展性 | | |
57
- | 风险等级 | | |
58
- | 回退难度 | | |
59
-
60
- ## 推荐
61
-
62
- **{推荐方案}**
63
-
64
- 理由:{详细说明}
65
- \`\`\`
66
-
67
- ## 输出格式
68
-
69
- \`\`\`markdown
70
- # Oracle 评估
71
-
72
- ## 问题复述
73
- {用户描述的问题或决策点}
74
-
75
- ## 假设分析
76
- 1. 假设 1 — {评估}
77
- 2. 假设 2 — {评估}
78
-
79
- ## 风险识别
80
- ### 🔴 高风险
81
- - 风险描述
82
- - 影响
83
- - 缓解建议
84
-
85
- ### 🟡 中风险
86
- - 风险描述
87
- - 影响
88
-
89
- ### 🟢 低风险
90
- - 风险描述
91
-
92
- ## 替代方案
93
- {如果有更好或不同的方法}
94
-
95
- ## 建议行动
96
- 1. {最安全的下一步}
97
- 2. {后续步骤}
98
-
99
- ## 决策点
100
- 需要用户确认的事项:
101
- - [ ] {决策 1}
102
- - [ ] {决策 2}
103
- \`\`\`
104
-
105
- ## 关键约束
106
-
107
- - 诚实直接 — 不要为了讨好而同意
108
- - 挑战而非阻止 — 指出问题,但提供建设性方向
109
- - 基于证据 — 所有评估都要有具体理由