@dyyz1993/pi-coding-agent 0.69.18 → 0.69.25

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 (129) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/cli/args.d.ts +1 -0
  3. package/dist/cli/args.d.ts.map +1 -1
  4. package/dist/cli/args.js +12 -2
  5. package/dist/cli/args.js.map +1 -1
  6. package/dist/core/agent-session.d.ts +15 -1
  7. package/dist/core/agent-session.d.ts.map +1 -1
  8. package/dist/core/agent-session.js +216 -0
  9. package/dist/core/agent-session.js.map +1 -1
  10. package/dist/core/extensions/client-channel.d.ts +61 -0
  11. package/dist/core/extensions/client-channel.d.ts.map +1 -0
  12. package/dist/core/extensions/client-channel.js +67 -0
  13. package/dist/core/extensions/client-channel.js.map +1 -0
  14. package/dist/core/extensions/index.d.ts +3 -2
  15. package/dist/core/extensions/index.d.ts.map +1 -1
  16. package/dist/core/extensions/index.js +1 -0
  17. package/dist/core/extensions/index.js.map +1 -1
  18. package/dist/core/extensions/loader.d.ts.map +1 -1
  19. package/dist/core/extensions/loader.js +21 -0
  20. package/dist/core/extensions/loader.js.map +1 -1
  21. package/dist/core/extensions/runner.d.ts +1 -0
  22. package/dist/core/extensions/runner.d.ts.map +1 -1
  23. package/dist/core/extensions/runner.js +31 -0
  24. package/dist/core/extensions/runner.js.map +1 -1
  25. package/dist/core/extensions/types.d.ts +86 -34
  26. package/dist/core/extensions/types.d.ts.map +1 -1
  27. package/dist/core/extensions/types.js.map +1 -1
  28. package/dist/core/include-resolver.d.ts +18 -0
  29. package/dist/core/include-resolver.d.ts.map +1 -0
  30. package/dist/core/include-resolver.js +304 -0
  31. package/dist/core/include-resolver.js.map +1 -0
  32. package/dist/core/resource-loader.d.ts.map +1 -1
  33. package/dist/core/resource-loader.js +17 -4
  34. package/dist/core/resource-loader.js.map +1 -1
  35. package/dist/core/session-manager.d.ts +8 -4
  36. package/dist/core/session-manager.d.ts.map +1 -1
  37. package/dist/core/session-manager.js +29 -6
  38. package/dist/core/session-manager.js.map +1 -1
  39. package/dist/core/storage.d.ts +24 -0
  40. package/dist/core/storage.d.ts.map +1 -0
  41. package/dist/core/storage.js +55 -0
  42. package/dist/core/storage.js.map +1 -0
  43. package/dist/core/tools/path-security.d.ts +15 -0
  44. package/dist/core/tools/path-security.d.ts.map +1 -0
  45. package/dist/core/tools/path-security.js +76 -0
  46. package/dist/core/tools/path-security.js.map +1 -0
  47. package/dist/core/tools/strip-markdown.d.ts +2 -0
  48. package/dist/core/tools/strip-markdown.d.ts.map +1 -0
  49. package/dist/core/tools/strip-markdown.js +8 -0
  50. package/dist/core/tools/strip-markdown.js.map +1 -0
  51. package/dist/index.d.ts +5 -4
  52. package/dist/index.d.ts.map +1 -1
  53. package/dist/index.js +3 -2
  54. package/dist/index.js.map +1 -1
  55. package/dist/main.d.ts.map +1 -1
  56. package/dist/main.js +1 -0
  57. package/dist/main.js.map +1 -1
  58. package/dist/modes/interactive/components/extension-selector.d.ts +4 -1
  59. package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
  60. package/dist/modes/interactive/components/extension-selector.js +54 -12
  61. package/dist/modes/interactive/components/extension-selector.js.map +1 -1
  62. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  63. package/dist/modes/interactive/interactive-mode.js +2 -1
  64. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  65. package/dist/modes/print-mode.d.ts +2 -0
  66. package/dist/modes/print-mode.d.ts.map +1 -1
  67. package/dist/modes/print-mode.js +8 -1
  68. package/dist/modes/print-mode.js.map +1 -1
  69. package/dist/modes/rpc/rpc-client-types.d.ts +11 -0
  70. package/dist/modes/rpc/rpc-client-types.d.ts.map +1 -1
  71. package/dist/modes/rpc/rpc-client-types.js.map +1 -1
  72. package/dist/modes/rpc/rpc-client.d.ts +11 -0
  73. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  74. package/dist/modes/rpc/rpc-client.js +14 -0
  75. package/dist/modes/rpc/rpc-client.js.map +1 -1
  76. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  77. package/dist/modes/rpc/rpc-mode.js +36 -1
  78. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  79. package/dist/modes/rpc/rpc-types.d.ts +26 -0
  80. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  81. package/dist/modes/rpc/rpc-types.js.map +1 -1
  82. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  83. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  84. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  85. package/examples/extensions/custom-provider-qwen-cli/package.json +1 -1
  86. package/examples/extensions/with-deps/package-lock.json +2 -2
  87. package/examples/extensions/with-deps/package.json +1 -1
  88. package/package.json +9 -5
  89. package/dist/rules-engine/cache.d.ts +0 -4
  90. package/dist/rules-engine/cache.d.ts.map +0 -1
  91. package/dist/rules-engine/cache.js +0 -32
  92. package/dist/rules-engine/cache.js.map +0 -1
  93. package/dist/rules-engine/config.d.ts +0 -8
  94. package/dist/rules-engine/config.d.ts.map +0 -1
  95. package/dist/rules-engine/config.js +0 -56
  96. package/dist/rules-engine/config.js.map +0 -1
  97. package/dist/rules-engine/index.d.ts +0 -10
  98. package/dist/rules-engine/index.d.ts.map +0 -1
  99. package/dist/rules-engine/index.js +0 -393
  100. package/dist/rules-engine/index.js.map +0 -1
  101. package/dist/rules-engine/injector.d.ts +0 -5
  102. package/dist/rules-engine/injector.d.ts.map +0 -1
  103. package/dist/rules-engine/injector.js +0 -57
  104. package/dist/rules-engine/injector.js.map +0 -1
  105. package/dist/rules-engine/loader.d.ts +0 -8
  106. package/dist/rules-engine/loader.d.ts.map +0 -1
  107. package/dist/rules-engine/loader.js +0 -190
  108. package/dist/rules-engine/loader.js.map +0 -1
  109. package/dist/rules-engine/matcher.d.ts +0 -3
  110. package/dist/rules-engine/matcher.d.ts.map +0 -1
  111. package/dist/rules-engine/matcher.js +0 -48
  112. package/dist/rules-engine/matcher.js.map +0 -1
  113. package/dist/rules-engine/types.d.ts +0 -150
  114. package/dist/rules-engine/types.d.ts.map +0 -1
  115. package/dist/rules-engine/types.js +0 -2
  116. package/dist/rules-engine/types.js.map +0 -1
  117. package/examples/extensions/auto-session-title.ts +0 -82
  118. package/examples/extensions/file-snapshot.ts +0 -417
  119. package/examples/extensions/subagent/README.md +0 -172
  120. package/examples/extensions/subagent/agents/planner.md +0 -37
  121. package/examples/extensions/subagent/agents/reviewer.md +0 -35
  122. package/examples/extensions/subagent/agents/scout.md +0 -50
  123. package/examples/extensions/subagent/agents/worker.md +0 -24
  124. package/examples/extensions/subagent/agents.ts +0 -126
  125. package/examples/extensions/subagent/index.ts +0 -987
  126. package/examples/extensions/subagent/prompts/implement-and-review.md +0 -10
  127. package/examples/extensions/subagent/prompts/implement.md +0 -10
  128. package/examples/extensions/subagent/prompts/scout-and-plan.md +0 -9
  129. package/examples/extensions/subagent-v2/index.ts +0 -849
@@ -1,417 +0,0 @@
1
- import {
2
- existsSync,
3
- lstatSync,
4
- mkdirSync,
5
- readdirSync,
6
- readFileSync,
7
- realpathSync,
8
- rmSync,
9
- writeFileSync,
10
- } from "node:fs";
11
- import { homedir } from "node:os";
12
- import { dirname, join, relative } from "node:path";
13
- import type { ExtensionAPI, ExtensionContext, SessionTreeEvent, TurnEndEvent } from "@dyyz1993/pi-coding-agent";
14
-
15
- function fnv1a(data: string): string {
16
- let hash = 0x811c9dc5;
17
- for (let i = 0; i < data.length; i++) {
18
- hash ^= data.charCodeAt(i);
19
- hash = Math.imul(hash, 0x01000193);
20
- }
21
- return hash.toString(16).padStart(8, "0");
22
- }
23
-
24
- const DEFAULT_IGNORE_PATTERNS = [
25
- "node_modules",
26
- ".git",
27
- ".pi",
28
- "dist",
29
- "build",
30
- ".DS_Store",
31
- "__pycache__",
32
- ".next",
33
- ".nuxt",
34
- "target",
35
- ".gradle",
36
- ".idea",
37
- ".vscode",
38
- "*.swp",
39
- "*.swo",
40
- "*.pyc",
41
- ];
42
-
43
- function matchGlob(name: string, pattern: string): boolean {
44
- if (pattern.startsWith("*.")) {
45
- return name.endsWith(pattern.slice(1));
46
- }
47
- if (pattern.endsWith("/")) {
48
- return name === pattern.slice(0, -1);
49
- }
50
- return name === pattern;
51
- }
52
-
53
- function shouldIgnore(relPath: string, extraPatterns: string[]): boolean {
54
- const parts = relPath.split("/");
55
- for (const part of parts) {
56
- for (const pattern of DEFAULT_IGNORE_PATTERNS) {
57
- if (matchGlob(part, pattern)) return true;
58
- }
59
- for (const pattern of extraPatterns) {
60
- const trimmed = pattern.trim();
61
- if (!trimmed || trimmed.startsWith("#")) continue;
62
- if (trimmed.startsWith("!")) continue;
63
- if (matchGlob(part, trimmed.replace(/^\/+/, ""))) return true;
64
- }
65
- }
66
- return false;
67
- }
68
-
69
- function findCanonicalGitRoot(cwd: string): string | null {
70
- let dir = realpathSync(cwd);
71
- for (;;) {
72
- const gitPath = join(dir, ".git");
73
- if (!existsSync(gitPath)) {
74
- const parent = dirname(dir);
75
- if (parent === dir) return null;
76
- dir = parent;
77
- continue;
78
- }
79
- const stat = lstatSync(gitPath);
80
- if (stat.isDirectory()) return dir;
81
- if (stat.isFile()) {
82
- const content = readFileSync(gitPath, "utf-8").trim();
83
- const match = content.match(/^gitdir:\s*(.+)/);
84
- if (!match) return null;
85
- const gitdir = match[1]!.trim();
86
- if (gitdir.includes("/worktrees/")) {
87
- const commonPrefix = gitdir.replace(/\/worktrees\/[^/]+\/?$/, "");
88
- let rootDir = commonPrefix;
89
- if (rootDir.endsWith("/.git")) rootDir = rootDir.slice(0, -4);
90
- if (!existsSync(join(rootDir, ".git"))) return null;
91
- return realpathSync(rootDir);
92
- }
93
- const parent = dirname(gitdir);
94
- if (!existsSync(parent)) return null;
95
- return parent;
96
- }
97
- return null;
98
- }
99
- }
100
-
101
- class ObjectStore {
102
- private readonly objectsDir: string;
103
-
104
- constructor(storeDir: string) {
105
- this.objectsDir = join(storeDir, "objects");
106
- mkdirSync(this.objectsDir, { recursive: true });
107
- }
108
-
109
- writeObject(content: string): string {
110
- const hash = fnv1a(content);
111
- const prefix = hash.slice(0, 2);
112
- const suffix = hash.slice(2);
113
- const dir = join(this.objectsDir, prefix);
114
- const file = join(dir, suffix);
115
- if (!existsSync(file)) {
116
- mkdirSync(dir, { recursive: true });
117
- writeFileSync(file, content, "utf-8");
118
- }
119
- return hash;
120
- }
121
-
122
- readObject(hash: string): string {
123
- return readFileSync(join(this.objectsDir, hash.slice(0, 2), hash.slice(2)), "utf-8");
124
- }
125
-
126
- hasObject(hash: string): boolean {
127
- return existsSync(join(this.objectsDir, hash.slice(0, 2), hash.slice(2)));
128
- }
129
-
130
- scanWorkingDir(cwd: string): Map<string, string> {
131
- const gitignorePatterns: string[] = [];
132
- const gitignorePath = join(cwd, ".gitignore");
133
- if (existsSync(gitignorePath)) {
134
- try {
135
- gitignorePatterns.push(...readFileSync(gitignorePath, "utf-8").split(/\r?\n/));
136
- } catch {}
137
- }
138
- const result = new Map<string, string>();
139
- this.scanDir(cwd, cwd, gitignorePatterns, result);
140
- return result;
141
- }
142
-
143
- private scanDir(dir: string, root: string, extraPatterns: string[], result: Map<string, string>): void {
144
- let entries: ReturnType<typeof readdirSync>;
145
- try {
146
- entries = readdirSync(dir, { withFileTypes: true });
147
- } catch {
148
- return;
149
- }
150
- for (const entry of entries) {
151
- const fullPath = join(dir, entry.name);
152
- const relPath = relative(root, fullPath);
153
- if (entry.isDirectory()) {
154
- if (shouldIgnore(`${relPath}/`, extraPatterns)) continue;
155
- this.scanDir(fullPath, root, extraPatterns, result);
156
- } else if (entry.isFile()) {
157
- if (shouldIgnore(relPath, extraPatterns)) continue;
158
- try {
159
- const stat = lstatSync(fullPath);
160
- if (stat.size > 1024 * 1024) continue;
161
- const content = readFileSync(fullPath, "utf-8");
162
- result.set(relPath, content);
163
- } catch {}
164
- }
165
- }
166
- }
167
-
168
- writeTree(files: Map<string, string>): string {
169
- const entries: Array<{ path: string; hash: string }> = [];
170
- for (const [path, content] of files) {
171
- const hash = this.writeObject(content);
172
- entries.push({ path, hash });
173
- }
174
- entries.sort((a, b) => a.path.localeCompare(b.path));
175
- const treeData = entries.map((e) => `${e.path}\0${e.hash}`).join("\n");
176
- return this.writeObject(treeData);
177
- }
178
-
179
- readTree(treeHash: string): Map<string, string> {
180
- const treeData = this.readObject(treeHash);
181
- const files = new Map<string, string>();
182
- for (const line of treeData.split("\n")) {
183
- if (!line) continue;
184
- const sep = line.indexOf("\0");
185
- if (sep === -1) continue;
186
- const path = line.slice(0, sep);
187
- const hash = line.slice(sep + 1);
188
- if (this.hasObject(hash)) {
189
- files.set(path, this.readObject(hash));
190
- }
191
- }
192
- return files;
193
- }
194
-
195
- parseTreeEntries(treeHash: string): Map<string, string> {
196
- const treeData = this.readObject(treeHash);
197
- const entries = new Map<string, string>();
198
- for (const line of treeData.split("\n")) {
199
- if (!line) continue;
200
- const sep = line.indexOf("\0");
201
- if (sep === -1) continue;
202
- entries.set(line.slice(0, sep), line.slice(sep + 1));
203
- }
204
- return entries;
205
- }
206
-
207
- computeTreeDiff(
208
- oldTreeHash: string | null,
209
- newTreeHash: string,
210
- ): { added: string[]; modified: string[]; deleted: string[] } {
211
- const oldEntries = oldTreeHash ? this.parseTreeEntries(oldTreeHash) : new Map<string, string>();
212
- const newEntries = this.parseTreeEntries(newTreeHash);
213
-
214
- const added: string[] = [];
215
- const modified: string[] = [];
216
- const deleted: string[] = [];
217
-
218
- for (const [path, hash] of newEntries) {
219
- const old = oldEntries.get(path);
220
- if (!old) added.push(path);
221
- else if (old !== hash) modified.push(path);
222
- }
223
- for (const path of oldEntries.keys()) {
224
- if (!newEntries.has(path)) deleted.push(path);
225
- }
226
-
227
- return { added: added.sort(), modified: modified.sort(), deleted: deleted.sort() };
228
- }
229
- }
230
-
231
- interface StepSnapshot {
232
- baselineTreeHash: string | null;
233
- snapshotTreeHash: string;
234
- diff: { added: string[]; modified: string[]; deleted: string[] } | null;
235
- turnIndex: number;
236
- }
237
-
238
- interface UnrevertPoint {
239
- preRollbackTreeHash: string;
240
- rolledBackToLeaf: string;
241
- restoredFiles: string[];
242
- }
243
-
244
- function getStoreRoot(): string {
245
- return join(homedir(), ".pi", "agent", "file-store");
246
- }
247
-
248
- export default function fileSnapshot(pi: ExtensionAPI) {
249
- let store: ObjectStore | null = null;
250
- let sessionStartTreeHash: string | null = null;
251
- let lastCommittedTreeHash: string | null = null;
252
- let turnIndex = 0;
253
- let _sessionBaselinePaths: Set<string> = new Set();
254
-
255
- function getStore(ctx: ExtensionContext): ObjectStore {
256
- if (!store) {
257
- const projectRoot = findCanonicalGitRoot(ctx.cwd) ?? ctx.cwd;
258
- const projectHash = fnv1a(projectRoot);
259
- store = new ObjectStore(join(getStoreRoot(), projectHash));
260
- }
261
- return store;
262
- }
263
-
264
- pi.on("session_start", async (_event: unknown, ctx: ExtensionContext) => {
265
- store = null;
266
- sessionStartTreeHash = null;
267
- lastCommittedTreeHash = null;
268
- turnIndex = 0;
269
- const s = getStore(ctx);
270
- const files = s.scanWorkingDir(ctx.cwd);
271
- _sessionBaselinePaths = new Set(files.keys());
272
- if (files.size > 0) {
273
- sessionStartTreeHash = s.writeTree(files);
274
- }
275
- });
276
-
277
- pi.on("turn_end", async (_event: TurnEndEvent, ctx: ExtensionContext) => {
278
- const s = getStore(ctx);
279
- const files = s.scanWorkingDir(ctx.cwd);
280
- const snapshotTreeHash = s.writeTree(files);
281
-
282
- const compareTo = lastCommittedTreeHash ?? sessionStartTreeHash;
283
- const isFirstSnapshot = !lastCommittedTreeHash && files.size > 0;
284
- const diff = compareTo ? s.computeTreeDiff(compareTo, snapshotTreeHash || "") : null;
285
- const hasChanges = diff && (diff.added.length > 0 || diff.modified.length > 0 || diff.deleted.length > 0);
286
-
287
- if (hasChanges || isFirstSnapshot) {
288
- pi.appendEntry(
289
- "step-snapshot",
290
- {
291
- baselineTreeHash: compareTo,
292
- snapshotTreeHash,
293
- diff: hasChanges ? diff : null,
294
- turnIndex,
295
- } satisfies StepSnapshot,
296
- { display: false },
297
- );
298
- lastCommittedTreeHash = snapshotTreeHash || null;
299
- }
300
-
301
- turnIndex++;
302
- });
303
-
304
- pi.on("session_tree", async (event: SessionTreeEvent, ctx: ExtensionContext) => {
305
- if (event.skipFiles) return;
306
-
307
- const targetId = event.newLeafId;
308
- const s = getStore(ctx);
309
- const entries = ctx.sessionManager.getEntries();
310
-
311
- let targetTreeHash: string | null;
312
- let currentTreeHash2: string | null;
313
-
314
- if (!targetId) {
315
- targetTreeHash = sessionStartTreeHash ?? null;
316
- const currentSnapshot = findLatestSnapshotOnPath(entries, event.oldLeafId);
317
- currentTreeHash2 = currentSnapshot?.snapshotTreeHash ?? null;
318
- } else {
319
- const targetEntry = entries.find((e) => e.id === targetId);
320
- const isRootTarget = targetEntry && !targetEntry.parentId;
321
-
322
- const targetSnapshot = isRootTarget ? null : findLatestSnapshotOnPath(entries, targetId);
323
- const currentSnapshot = findLatestSnapshotOnPath(entries, event.oldLeafId);
324
-
325
- targetTreeHash = targetSnapshot?.snapshotTreeHash ?? sessionStartTreeHash ?? null;
326
- currentTreeHash2 = currentSnapshot?.snapshotTreeHash ?? null;
327
- }
328
-
329
- if (targetTreeHash === currentTreeHash2) return;
330
-
331
- const targetFiles = targetTreeHash ? s.readTree(targetTreeHash) : new Map<string, string>();
332
- const currentFiles = currentTreeHash2 ? s.readTree(currentTreeHash2) : new Map<string, string>();
333
-
334
- const toRestore: string[] = [];
335
- for (const [path, content] of targetFiles) {
336
- const current = currentFiles.get(path);
337
- if (current !== content) {
338
- toRestore.push(path);
339
- }
340
- }
341
-
342
- const toDelete: string[] = [];
343
- for (const path of currentFiles.keys()) {
344
- if (!targetFiles.has(path)) {
345
- toDelete.push(path);
346
- }
347
- }
348
-
349
- if (toRestore.length === 0 && toDelete.length === 0) return;
350
-
351
- if (event.preview) {
352
- return { restored: toRestore.sort(), deleted: toDelete.sort() };
353
- }
354
-
355
- const preRollbackFiles = s.scanWorkingDir(ctx.cwd);
356
- const preRollbackTreeHash = preRollbackFiles.size > 0 ? s.writeTree(preRollbackFiles) : "";
357
-
358
- pi.appendEntry("unrevert-point", {
359
- preRollbackTreeHash,
360
- rolledBackToLeaf: targetId ?? "",
361
- restoredFiles: toRestore,
362
- } satisfies UnrevertPoint);
363
-
364
- restoreFiles(ctx.cwd, new Map(toRestore.map((p) => [p, targetFiles.get(p)!])));
365
- deleteFiles(ctx.cwd, toDelete);
366
- });
367
- }
368
-
369
- function restoreFiles(cwd: string, toRestore: Map<string, string>): void {
370
- for (const [path, content] of toRestore) {
371
- const absPath = join(cwd, path);
372
- mkdirSync(join(absPath, ".."), { recursive: true });
373
- writeFileSync(absPath, content, "utf-8");
374
- }
375
- }
376
-
377
- function deleteFiles(cwd: string, paths: string[]): void {
378
- for (const path of paths) {
379
- const absPath = join(cwd, path);
380
- if (existsSync(absPath)) {
381
- rmSync(absPath, { force: true });
382
- }
383
- }
384
- }
385
-
386
- function findLatestSnapshotOnPath(
387
- entries: Array<{ id: string; parentId: string | null; type: string; customType?: string; data?: unknown }>,
388
- leafId: string | null,
389
- ): StepSnapshot | null {
390
- if (!leafId) return null;
391
-
392
- const byId = new Map(entries.map((e) => [e.id, e]));
393
- const snapshots: StepSnapshot[] = [];
394
-
395
- for (const entry of entries) {
396
- if (entry.type !== "custom" || entry.customType !== "step-snapshot") continue;
397
- if (!isOnPathTo(byId, leafId, entry.id)) continue;
398
- snapshots.push(entry.data as StepSnapshot);
399
- }
400
-
401
- return snapshots.length > 0 ? snapshots[snapshots.length - 1] : null;
402
- }
403
-
404
- function isOnPathTo(
405
- byId: Map<string, { id: string; parentId: string | null }>,
406
- startId: string,
407
- targetId: string,
408
- ): boolean {
409
- let current: string | null = startId;
410
- while (current !== null) {
411
- if (current === targetId) return true;
412
- const entry = byId.get(current);
413
- if (!entry) break;
414
- current = entry.parentId;
415
- }
416
- return false;
417
- }
@@ -1,172 +0,0 @@
1
- # Subagent Example
2
-
3
- Delegate tasks to specialized subagents with isolated context windows.
4
-
5
- ## Features
6
-
7
- - **Isolated context**: Each subagent runs in a separate `pi` process
8
- - **Streaming output**: See tool calls and progress as they happen
9
- - **Parallel streaming**: All parallel tasks stream updates simultaneously
10
- - **Markdown rendering**: Final output rendered with proper formatting (expanded view)
11
- - **Usage tracking**: Shows turns, tokens, cost, and context usage per agent
12
- - **Abort support**: Ctrl+C propagates to kill subagent processes
13
-
14
- ## Structure
15
-
16
- ```
17
- subagent/
18
- ├── README.md # This file
19
- ├── index.ts # The extension (entry point)
20
- ├── agents.ts # Agent discovery logic
21
- ├── agents/ # Sample agent definitions
22
- │ ├── scout.md # Fast recon, returns compressed context
23
- │ ├── planner.md # Creates implementation plans
24
- │ ├── reviewer.md # Code review
25
- │ └── worker.md # General-purpose (full capabilities)
26
- └── prompts/ # Workflow presets (prompt templates)
27
- ├── implement.md # scout -> planner -> worker
28
- ├── scout-and-plan.md # scout -> planner (no implementation)
29
- └── implement-and-review.md # worker -> reviewer -> worker
30
- ```
31
-
32
- ## Installation
33
-
34
- From the repository root, symlink the files:
35
-
36
- ```bash
37
- # Symlink the extension (must be in a subdirectory with index.ts)
38
- mkdir -p ~/.pi/agent/extensions/subagent
39
- ln -sf "$(pwd)/packages/coding-agent/examples/extensions/subagent/index.ts" ~/.pi/agent/extensions/subagent/index.ts
40
- ln -sf "$(pwd)/packages/coding-agent/examples/extensions/subagent/agents.ts" ~/.pi/agent/extensions/subagent/agents.ts
41
-
42
- # Symlink agents
43
- mkdir -p ~/.pi/agent/agents
44
- for f in packages/coding-agent/examples/extensions/subagent/agents/*.md; do
45
- ln -sf "$(pwd)/$f" ~/.pi/agent/agents/$(basename "$f")
46
- done
47
-
48
- # Symlink workflow prompts
49
- mkdir -p ~/.pi/agent/prompts
50
- for f in packages/coding-agent/examples/extensions/subagent/prompts/*.md; do
51
- ln -sf "$(pwd)/$f" ~/.pi/agent/prompts/$(basename "$f")
52
- done
53
- ```
54
-
55
- ## Security Model
56
-
57
- This tool executes a separate `pi` subprocess with a delegated system prompt and tool/model configuration.
58
-
59
- **Project-local agents** (`.pi/agents/*.md`) are repo-controlled prompts that can instruct the model to read files, run bash commands, etc.
60
-
61
- **Default behavior:** Only loads **user-level agents** from `~/.pi/agent/agents`.
62
-
63
- To enable project-local agents, pass `agentScope: "both"` (or `"project"`). Only do this for repositories you trust.
64
-
65
- When running interactively, the tool prompts for confirmation before running project-local agents. Set `confirmProjectAgents: false` to disable.
66
-
67
- ## Usage
68
-
69
- ### Single agent
70
- ```
71
- Use scout to find all authentication code
72
- ```
73
-
74
- ### Parallel execution
75
- ```
76
- Run 2 scouts in parallel: one to find models, one to find providers
77
- ```
78
-
79
- ### Chained workflow
80
- ```
81
- Use a chain: first have scout find the read tool, then have planner suggest improvements
82
- ```
83
-
84
- ### Workflow prompts
85
- ```
86
- /implement add Redis caching to the session store
87
- /scout-and-plan refactor auth to support OAuth
88
- /implement-and-review add input validation to API endpoints
89
- ```
90
-
91
- ## Tool Modes
92
-
93
- | Mode | Parameter | Description |
94
- |------|-----------|-------------|
95
- | Single | `{ agent, task }` | One agent, one task |
96
- | Parallel | `{ tasks: [...] }` | Multiple agents run concurrently (max 8, 4 concurrent) |
97
- | Chain | `{ chain: [...] }` | Sequential with `{previous}` placeholder |
98
-
99
- ## Output Display
100
-
101
- **Collapsed view** (default):
102
- - Status icon (✓/✗/⏳) and agent name
103
- - Last 5-10 items (tool calls and text)
104
- - Usage stats: `3 turns ↑input ↓output RcacheRead WcacheWrite $cost ctx:contextTokens model`
105
-
106
- **Expanded view** (Ctrl+O):
107
- - Full task text
108
- - All tool calls with formatted arguments
109
- - Final output rendered as Markdown
110
- - Per-task usage (for chain/parallel)
111
-
112
- **Parallel mode streaming**:
113
- - Shows all tasks with live status (⏳ running, ✓ done, ✗ failed)
114
- - Updates as each task makes progress
115
- - Shows "2/3 done, 1 running" status
116
-
117
- **Tool call formatting** (mimics built-in tools):
118
- - `$ command` for bash
119
- - `read ~/path:1-10` for read
120
- - `grep /pattern/ in ~/path` for grep
121
- - etc.
122
-
123
- ## Agent Definitions
124
-
125
- Agents are markdown files with YAML frontmatter:
126
-
127
- ```markdown
128
- ---
129
- name: my-agent
130
- description: What this agent does
131
- tools: read, grep, find, ls
132
- model: claude-haiku-4-5
133
- ---
134
-
135
- System prompt for the agent goes here.
136
- ```
137
-
138
- **Locations:**
139
- - `~/.pi/agent/agents/*.md` - User-level (always loaded)
140
- - `.pi/agents/*.md` - Project-level (only with `agentScope: "project"` or `"both"`)
141
-
142
- Project agents override user agents with the same name when `agentScope: "both"`.
143
-
144
- ## Sample Agents
145
-
146
- | Agent | Purpose | Model | Tools |
147
- |-------|---------|-------|-------|
148
- | `scout` | Fast codebase recon | Haiku | read, grep, find, ls, bash |
149
- | `planner` | Implementation plans | Sonnet | read, grep, find, ls |
150
- | `reviewer` | Code review | Sonnet | read, grep, find, ls, bash |
151
- | `worker` | General-purpose | Sonnet | (all default) |
152
-
153
- ## Workflow Prompts
154
-
155
- | Prompt | Flow |
156
- |--------|------|
157
- | `/implement <query>` | scout → planner → worker |
158
- | `/scout-and-plan <query>` | scout → planner |
159
- | `/implement-and-review <query>` | worker → reviewer → worker |
160
-
161
- ## Error Handling
162
-
163
- - **Exit code != 0**: Tool returns error with stderr/output
164
- - **stopReason "error"**: LLM error propagated with error message
165
- - **stopReason "aborted"**: User abort (Ctrl+C) kills subprocess, throws error
166
- - **Chain mode**: Stops at first failing step, reports which step failed
167
-
168
- ## Limitations
169
-
170
- - Output truncated to last 10 items in collapsed view (expand to see all)
171
- - Agents discovered fresh on each invocation (allows editing mid-session)
172
- - Parallel mode limited to 8 tasks, 4 concurrent
@@ -1,37 +0,0 @@
1
- ---
2
- name: planner
3
- description: Creates implementation plans from context and requirements
4
- tools: read, grep, find, ls
5
- model: claude-sonnet-4-5
6
- ---
7
-
8
- You are a planning specialist. You receive context (from a scout) and requirements, then produce a clear implementation plan.
9
-
10
- You must NOT make any changes. Only read, analyze, and plan.
11
-
12
- Input format you'll receive:
13
- - Context/findings from a scout agent
14
- - Original query or requirements
15
-
16
- Output format:
17
-
18
- ## Goal
19
- One sentence summary of what needs to be done.
20
-
21
- ## Plan
22
- Numbered steps, each small and actionable:
23
- 1. Step one - specific file/function to modify
24
- 2. Step two - what to add/change
25
- 3. ...
26
-
27
- ## Files to Modify
28
- - `path/to/file.ts` - what changes
29
- - `path/to/other.ts` - what changes
30
-
31
- ## New Files (if any)
32
- - `path/to/new.ts` - purpose
33
-
34
- ## Risks
35
- Anything to watch out for.
36
-
37
- Keep the plan concrete. The worker agent will execute it verbatim.
@@ -1,35 +0,0 @@
1
- ---
2
- name: reviewer
3
- description: Code review specialist for quality and security analysis
4
- tools: read, grep, find, ls, bash
5
- model: claude-sonnet-4-5
6
- ---
7
-
8
- You are a senior code reviewer. Analyze code for quality, security, and maintainability.
9
-
10
- Bash is for read-only commands only: `git diff`, `git log`, `git show`. Do NOT modify files or run builds.
11
- Assume tool permissions are not perfectly enforceable; keep all bash usage strictly read-only.
12
-
13
- Strategy:
14
- 1. Run `git diff` to see recent changes (if applicable)
15
- 2. Read the modified files
16
- 3. Check for bugs, security issues, code smells
17
-
18
- Output format:
19
-
20
- ## Files Reviewed
21
- - `path/to/file.ts` (lines X-Y)
22
-
23
- ## Critical (must fix)
24
- - `file.ts:42` - Issue description
25
-
26
- ## Warnings (should fix)
27
- - `file.ts:100` - Issue description
28
-
29
- ## Suggestions (consider)
30
- - `file.ts:150` - Improvement idea
31
-
32
- ## Summary
33
- Overall assessment in 2-3 sentences.
34
-
35
- Be specific with file paths and line numbers.
@@ -1,50 +0,0 @@
1
- ---
2
- name: scout
3
- description: Fast codebase recon that returns compressed context for handoff to other agents
4
- tools: read, grep, find, ls, bash
5
- model: claude-haiku-4-5
6
- ---
7
-
8
- You are a scout. Quickly investigate a codebase and return structured findings that another agent can use without re-reading everything.
9
-
10
- Your output will be passed to an agent who has NOT seen the files you explored.
11
-
12
- Thoroughness (infer from task, default medium):
13
- - Quick: Targeted lookups, key files only
14
- - Medium: Follow imports, read critical sections
15
- - Thorough: Trace all dependencies, check tests/types
16
-
17
- Strategy:
18
- 1. grep/find to locate relevant code
19
- 2. Read key sections (not entire files)
20
- 3. Identify types, interfaces, key functions
21
- 4. Note dependencies between files
22
-
23
- Output format:
24
-
25
- ## Files Retrieved
26
- List with exact line ranges:
27
- 1. `path/to/file.ts` (lines 10-50) - Description of what's here
28
- 2. `path/to/other.ts` (lines 100-150) - Description
29
- 3. ...
30
-
31
- ## Key Code
32
- Critical types, interfaces, or functions:
33
-
34
- ```typescript
35
- interface Example {
36
- // actual code from the files
37
- }
38
- ```
39
-
40
- ```typescript
41
- function keyFunction() {
42
- // actual implementation
43
- }
44
- ```
45
-
46
- ## Architecture
47
- Brief explanation of how the pieces connect.
48
-
49
- ## Start Here
50
- Which file to look at first and why.