@gotgenes/pi-subagents 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/.markdownlint-cli2.yaml +19 -0
  2. package/.prettierignore +5 -0
  3. package/.release-please-manifest.json +3 -0
  4. package/AGENTS.md +85 -0
  5. package/CHANGELOG.md +495 -0
  6. package/LICENSE +21 -0
  7. package/README.md +528 -0
  8. package/dist/agent-manager.d.ts +108 -0
  9. package/dist/agent-manager.js +390 -0
  10. package/dist/agent-runner.d.ts +93 -0
  11. package/dist/agent-runner.js +428 -0
  12. package/dist/agent-types.d.ts +48 -0
  13. package/dist/agent-types.js +136 -0
  14. package/dist/context.d.ts +12 -0
  15. package/dist/context.js +56 -0
  16. package/dist/cross-extension-rpc.d.ts +46 -0
  17. package/dist/cross-extension-rpc.js +54 -0
  18. package/dist/custom-agents.d.ts +14 -0
  19. package/dist/custom-agents.js +127 -0
  20. package/dist/default-agents.d.ts +7 -0
  21. package/dist/default-agents.js +119 -0
  22. package/dist/env.d.ts +6 -0
  23. package/dist/env.js +28 -0
  24. package/dist/group-join.d.ts +32 -0
  25. package/dist/group-join.js +116 -0
  26. package/dist/index.d.ts +13 -0
  27. package/dist/index.js +1731 -0
  28. package/dist/invocation-config.d.ts +22 -0
  29. package/dist/invocation-config.js +15 -0
  30. package/dist/memory.d.ts +49 -0
  31. package/dist/memory.js +151 -0
  32. package/dist/model-resolver.d.ts +19 -0
  33. package/dist/model-resolver.js +62 -0
  34. package/dist/output-file.d.ts +24 -0
  35. package/dist/output-file.js +86 -0
  36. package/dist/prompts.d.ts +29 -0
  37. package/dist/prompts.js +72 -0
  38. package/dist/schedule-store.d.ts +36 -0
  39. package/dist/schedule-store.js +144 -0
  40. package/dist/schedule.d.ts +109 -0
  41. package/dist/schedule.js +338 -0
  42. package/dist/settings.d.ts +66 -0
  43. package/dist/settings.js +130 -0
  44. package/dist/skill-loader.d.ts +24 -0
  45. package/dist/skill-loader.js +93 -0
  46. package/dist/types.d.ts +164 -0
  47. package/dist/types.js +5 -0
  48. package/dist/ui/agent-widget.d.ts +134 -0
  49. package/dist/ui/agent-widget.js +451 -0
  50. package/dist/ui/conversation-viewer.d.ts +35 -0
  51. package/dist/ui/conversation-viewer.js +252 -0
  52. package/dist/ui/schedule-menu.d.ts +16 -0
  53. package/dist/ui/schedule-menu.js +95 -0
  54. package/dist/usage.d.ts +50 -0
  55. package/dist/usage.js +49 -0
  56. package/dist/worktree.d.ts +36 -0
  57. package/dist/worktree.js +139 -0
  58. package/docs/decisions/0001-deferred-patches.md +75 -0
  59. package/package.json +68 -0
  60. package/prek.toml +24 -0
  61. package/release-please-config.json +22 -0
  62. package/src/agent-manager.ts +482 -0
  63. package/src/agent-runner.ts +625 -0
  64. package/src/agent-types.ts +164 -0
  65. package/src/context.ts +58 -0
  66. package/src/cross-extension-rpc.ts +95 -0
  67. package/src/custom-agents.ts +136 -0
  68. package/src/default-agents.ts +123 -0
  69. package/src/env.ts +33 -0
  70. package/src/group-join.ts +141 -0
  71. package/src/index.ts +1894 -0
  72. package/src/invocation-config.ts +40 -0
  73. package/src/memory.ts +165 -0
  74. package/src/model-resolver.ts +81 -0
  75. package/src/output-file.ts +96 -0
  76. package/src/prompts.ts +105 -0
  77. package/src/schedule-store.ts +143 -0
  78. package/src/schedule.ts +365 -0
  79. package/src/settings.ts +186 -0
  80. package/src/skill-loader.ts +102 -0
  81. package/src/types.ts +176 -0
  82. package/src/ui/agent-widget.ts +533 -0
  83. package/src/ui/conversation-viewer.ts +261 -0
  84. package/src/ui/schedule-menu.ts +104 -0
  85. package/src/usage.ts +60 -0
  86. package/src/worktree.ts +162 -0
@@ -0,0 +1,164 @@
1
+ /**
2
+ * agent-types.ts — Unified agent type registry.
3
+ *
4
+ * Merges embedded default agents with user-defined agents from .pi/agents/*.md.
5
+ * User agents override defaults with the same name. Disabled agents are kept but excluded from spawning.
6
+ */
7
+
8
+ import { DEFAULT_AGENTS } from "./default-agents.js";
9
+ import type { AgentConfig } from "./types.js";
10
+
11
+ /** All known built-in tool names. */
12
+ export const BUILTIN_TOOL_NAMES: string[] = ["read", "bash", "edit", "write", "grep", "find", "ls"];
13
+
14
+ /** Unified runtime registry of all agents (defaults + user-defined). */
15
+ const agents = new Map<string, AgentConfig>();
16
+
17
+ /**
18
+ * Register agents into the unified registry.
19
+ * Starts with DEFAULT_AGENTS, then overlays user agents (overrides defaults with same name).
20
+ * Disabled agents (enabled === false) are kept in the registry but excluded from spawning.
21
+ */
22
+ export function registerAgents(userAgents: Map<string, AgentConfig>): void {
23
+ agents.clear();
24
+
25
+ // Start with defaults
26
+ for (const [name, config] of DEFAULT_AGENTS) {
27
+ agents.set(name, config);
28
+ }
29
+
30
+ // Overlay user agents (overrides defaults with same name)
31
+ for (const [name, config] of userAgents) {
32
+ agents.set(name, config);
33
+ }
34
+ }
35
+
36
+ /** Case-insensitive key resolution. */
37
+ function resolveKey(name: string): string | undefined {
38
+ if (agents.has(name)) return name;
39
+ const lower = name.toLowerCase();
40
+ for (const key of agents.keys()) {
41
+ if (key.toLowerCase() === lower) return key;
42
+ }
43
+ return undefined;
44
+ }
45
+
46
+ /** Resolve a type name case-insensitively. Returns the canonical key or undefined. */
47
+ export function resolveType(name: string): string | undefined {
48
+ return resolveKey(name);
49
+ }
50
+
51
+ /** Get the agent config for a type (case-insensitive). */
52
+ export function getAgentConfig(name: string): AgentConfig | undefined {
53
+ const key = resolveKey(name);
54
+ return key ? agents.get(key) : undefined;
55
+ }
56
+
57
+ /** Get all enabled type names (for spawning and tool descriptions). */
58
+ export function getAvailableTypes(): string[] {
59
+ return [...agents.entries()]
60
+ .filter(([_, config]) => config.enabled !== false)
61
+ .map(([name]) => name);
62
+ }
63
+
64
+ /** Get all type names including disabled (for UI listing). */
65
+ export function getAllTypes(): string[] {
66
+ return [...agents.keys()];
67
+ }
68
+
69
+ /** Get names of default agents currently in the registry. */
70
+ export function getDefaultAgentNames(): string[] {
71
+ return [...agents.entries()]
72
+ .filter(([_, config]) => config.isDefault === true)
73
+ .map(([name]) => name);
74
+ }
75
+
76
+ /** Get names of user-defined agents (non-defaults) currently in the registry. */
77
+ export function getUserAgentNames(): string[] {
78
+ return [...agents.entries()]
79
+ .filter(([_, config]) => config.isDefault !== true)
80
+ .map(([name]) => name);
81
+ }
82
+
83
+ /** Check if a type is valid and enabled (case-insensitive). */
84
+ export function isValidType(type: string): boolean {
85
+ const key = resolveKey(type);
86
+ if (!key) return false;
87
+ return agents.get(key)?.enabled !== false;
88
+ }
89
+
90
+ /** Tool names required for memory management. */
91
+ const MEMORY_TOOL_NAMES = ["read", "write", "edit"];
92
+
93
+ /**
94
+ * Get memory tool names (read/write/edit) not already in the provided set.
95
+ */
96
+ export function getMemoryToolNames(existingToolNames: Set<string>): string[] {
97
+ return MEMORY_TOOL_NAMES.filter(n => !existingToolNames.has(n));
98
+ }
99
+
100
+ /** Tool names needed for read-only memory access. */
101
+ const READONLY_MEMORY_TOOL_NAMES = ["read"];
102
+
103
+ /**
104
+ * Get read-only memory tool names not already in the provided set.
105
+ */
106
+ export function getReadOnlyMemoryToolNames(existingToolNames: Set<string>): string[] {
107
+ return READONLY_MEMORY_TOOL_NAMES.filter(n => !existingToolNames.has(n));
108
+ }
109
+
110
+ /** Get built-in tool names for a type (case-insensitive). */
111
+ export function getToolNamesForType(type: string): string[] {
112
+ const key = resolveKey(type);
113
+ const raw = key ? agents.get(key) : undefined;
114
+ const config = raw?.enabled !== false ? raw : undefined;
115
+ const names = config?.builtinToolNames?.length ? config.builtinToolNames : [...BUILTIN_TOOL_NAMES];
116
+ return names;
117
+ }
118
+
119
+ /** Get config for a type (case-insensitive, returns a SubagentTypeConfig-compatible object). Falls back to general-purpose. */
120
+ export function getConfig(type: string): {
121
+ displayName: string;
122
+ description: string;
123
+ builtinToolNames: string[];
124
+ extensions: true | string[] | false;
125
+ skills: true | string[] | false;
126
+ promptMode: "replace" | "append";
127
+ } {
128
+ const key = resolveKey(type);
129
+ const config = key ? agents.get(key) : undefined;
130
+ if (config && config.enabled !== false) {
131
+ return {
132
+ displayName: config.displayName ?? config.name,
133
+ description: config.description,
134
+ builtinToolNames: config.builtinToolNames ?? BUILTIN_TOOL_NAMES,
135
+ extensions: config.extensions,
136
+ skills: config.skills,
137
+ promptMode: config.promptMode,
138
+ };
139
+ }
140
+
141
+ // Fallback for unknown/disabled types — general-purpose config
142
+ const gp = agents.get("general-purpose");
143
+ if (gp && gp.enabled !== false) {
144
+ return {
145
+ displayName: gp.displayName ?? gp.name,
146
+ description: gp.description,
147
+ builtinToolNames: gp.builtinToolNames ?? BUILTIN_TOOL_NAMES,
148
+ extensions: gp.extensions,
149
+ skills: gp.skills,
150
+ promptMode: gp.promptMode,
151
+ };
152
+ }
153
+
154
+ // Absolute fallback (should never happen)
155
+ return {
156
+ displayName: "Agent",
157
+ description: "General-purpose agent for complex, multi-step tasks",
158
+ builtinToolNames: BUILTIN_TOOL_NAMES,
159
+ extensions: true,
160
+ skills: true,
161
+ promptMode: "append",
162
+ };
163
+ }
164
+
package/src/context.ts ADDED
@@ -0,0 +1,58 @@
1
+ /**
2
+ * context.ts — Extract parent conversation context for subagent inheritance.
3
+ */
4
+
5
+ import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
6
+
7
+ /** Extract text from a message content block array. */
8
+ export function extractText(content: unknown[]): string {
9
+ return content
10
+ .filter((c: any) => c.type === "text")
11
+ .map((c: any) => c.text ?? "")
12
+ .join("\n");
13
+ }
14
+
15
+ /**
16
+ * Build a text representation of the parent conversation context.
17
+ * Used when inherit_context is true to give the subagent visibility
18
+ * into what has been discussed/done so far.
19
+ */
20
+ export function buildParentContext(ctx: ExtensionContext): string {
21
+ const entries = ctx.sessionManager.getBranch();
22
+ if (!entries || entries.length === 0) return "";
23
+
24
+ const parts: string[] = [];
25
+
26
+ for (const entry of entries) {
27
+ if (entry.type === "message") {
28
+ const msg = entry.message;
29
+ if (msg.role === "user") {
30
+ const text = typeof msg.content === "string"
31
+ ? msg.content
32
+ : extractText(msg.content);
33
+ if (text.trim()) parts.push(`[User]: ${text.trim()}`);
34
+ } else if (msg.role === "assistant") {
35
+ const text = extractText(msg.content);
36
+ if (text.trim()) parts.push(`[Assistant]: ${text.trim()}`);
37
+ }
38
+ // Skip toolResult messages — too verbose for context
39
+ } else if (entry.type === "compaction") {
40
+ // Include compaction summaries — they're already condensed
41
+ if (entry.summary) {
42
+ parts.push(`[Summary]: ${entry.summary}`);
43
+ }
44
+ }
45
+ }
46
+
47
+ if (parts.length === 0) return "";
48
+
49
+ return `# Parent Conversation Context
50
+ The following is the conversation history from the parent session that spawned you.
51
+ Use this context to understand what has been discussed and decided so far.
52
+
53
+ ${parts.join("\n\n")}
54
+
55
+ ---
56
+ # Your Task (below)
57
+ `;
58
+ }
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Cross-extension RPC handlers for the subagents extension.
3
+ *
4
+ * Exposes ping, spawn, and stop RPCs over the pi.events event bus,
5
+ * using per-request scoped reply channels.
6
+ *
7
+ * Reply envelope follows pi-mono convention:
8
+ * success → { success: true, data?: T }
9
+ * error → { success: false, error: string }
10
+ */
11
+
12
+ /** Minimal event bus interface needed by the RPC handlers. */
13
+ export interface EventBus {
14
+ on(event: string, handler: (data: unknown) => void): () => void;
15
+ emit(event: string, data: unknown): void;
16
+ }
17
+
18
+ /** RPC reply envelope — matches pi-mono's RpcResponse shape. */
19
+ export type RpcReply<T = void> =
20
+ | { success: true; data?: T }
21
+ | { success: false; error: string };
22
+
23
+ /** RPC protocol version — bumped when the envelope or method contracts change. */
24
+ export const PROTOCOL_VERSION = 2;
25
+
26
+ /** Minimal AgentManager interface needed by the spawn/stop RPCs. */
27
+ export interface SpawnCapable {
28
+ spawn(pi: unknown, ctx: unknown, type: string, prompt: string, options: any): string;
29
+ abort(id: string): boolean;
30
+ }
31
+
32
+ export interface RpcDeps {
33
+ events: EventBus;
34
+ pi: unknown; // passed through to manager.spawn
35
+ getCtx: () => unknown | undefined; // returns current ExtensionContext
36
+ manager: SpawnCapable;
37
+ }
38
+
39
+ export interface RpcHandle {
40
+ unsubPing: () => void;
41
+ unsubSpawn: () => void;
42
+ unsubStop: () => void;
43
+ }
44
+
45
+ /**
46
+ * Wire a single RPC handler: listen on `channel`, run `fn(params)`,
47
+ * emit the reply envelope on `channel:reply:${requestId}`.
48
+ */
49
+ function handleRpc<P extends { requestId: string }>(
50
+ events: EventBus,
51
+ channel: string,
52
+ fn: (params: P) => unknown | Promise<unknown>,
53
+ ): () => void {
54
+ return events.on(channel, async (raw: unknown) => {
55
+ const params = raw as P;
56
+ try {
57
+ const data = await fn(params);
58
+ const reply: { success: true; data?: unknown } = { success: true };
59
+ if (data !== undefined) reply.data = data;
60
+ events.emit(`${channel}:reply:${params.requestId}`, reply);
61
+ } catch (err: any) {
62
+ events.emit(`${channel}:reply:${params.requestId}`, {
63
+ success: false, error: err?.message ?? String(err),
64
+ });
65
+ }
66
+ });
67
+ }
68
+
69
+ /**
70
+ * Register ping, spawn, and stop RPC handlers on the event bus.
71
+ * Returns unsub functions for cleanup.
72
+ */
73
+ export function registerRpcHandlers(deps: RpcDeps): RpcHandle {
74
+ const { events, pi, getCtx, manager } = deps;
75
+
76
+ const unsubPing = handleRpc(events, "subagents:rpc:ping", () => {
77
+ return { version: PROTOCOL_VERSION };
78
+ });
79
+
80
+ const unsubSpawn = handleRpc<{ requestId: string; type: string; prompt: string; options?: any }>(
81
+ events, "subagents:rpc:spawn", ({ type, prompt, options }) => {
82
+ const ctx = getCtx();
83
+ if (!ctx) throw new Error("No active session");
84
+ return { id: manager.spawn(pi, ctx, type, prompt, options ?? {}) };
85
+ },
86
+ );
87
+
88
+ const unsubStop = handleRpc<{ requestId: string; agentId: string }>(
89
+ events, "subagents:rpc:stop", ({ agentId }) => {
90
+ if (!manager.abort(agentId)) throw new Error("Agent not found");
91
+ },
92
+ );
93
+
94
+ return { unsubPing, unsubSpawn, unsubStop };
95
+ }
@@ -0,0 +1,136 @@
1
+ /**
2
+ * custom-agents.ts — Load user-defined agents from project (.pi/agents/) and global ($PI_CODING_AGENT_DIR/agents/, default ~/.pi/agent/agents/) locations.
3
+ */
4
+
5
+ import { existsSync, readdirSync, readFileSync } from "node:fs";
6
+ import { basename, join } from "node:path";
7
+ import { getAgentDir, parseFrontmatter } from "@earendil-works/pi-coding-agent";
8
+ import { BUILTIN_TOOL_NAMES } from "./agent-types.js";
9
+ import type { AgentConfig, MemoryScope, ThinkingLevel } from "./types.js";
10
+
11
+ /**
12
+ * Scan for custom agent .md files from multiple locations.
13
+ * Discovery hierarchy (higher priority wins):
14
+ * 1. Project: <cwd>/.pi/agents/*.md
15
+ * 2. Global: $PI_CODING_AGENT_DIR/agents/*.md (default: ~/.pi/agent/agents/*.md)
16
+ *
17
+ * Project-level agents override global ones with the same name.
18
+ * Any name is allowed — names matching defaults (e.g. "Explore") override them.
19
+ */
20
+ export function loadCustomAgents(cwd: string): Map<string, AgentConfig> {
21
+ const globalDir = join(getAgentDir(), "agents");
22
+ const projectDir = join(cwd, ".pi", "agents");
23
+
24
+ const agents = new Map<string, AgentConfig>();
25
+ loadFromDir(globalDir, agents, "global"); // lower priority
26
+ loadFromDir(projectDir, agents, "project"); // higher priority (overwrites)
27
+ return agents;
28
+ }
29
+
30
+ /** Load agent configs from a directory into the map. */
31
+ function loadFromDir(dir: string, agents: Map<string, AgentConfig>, source: "project" | "global"): void {
32
+ if (!existsSync(dir)) return;
33
+
34
+ let files: string[];
35
+ try {
36
+ files = readdirSync(dir).filter(f => f.endsWith(".md"));
37
+ } catch {
38
+ return;
39
+ }
40
+
41
+ for (const file of files) {
42
+ const name = basename(file, ".md");
43
+
44
+ let content: string;
45
+ try {
46
+ content = readFileSync(join(dir, file), "utf-8");
47
+ } catch {
48
+ continue;
49
+ }
50
+
51
+ const { frontmatter: fm, body } = parseFrontmatter<Record<string, unknown>>(content);
52
+
53
+ agents.set(name, {
54
+ name,
55
+ displayName: str(fm.display_name),
56
+ description: str(fm.description) ?? name,
57
+ builtinToolNames: csvList(fm.tools, BUILTIN_TOOL_NAMES),
58
+ disallowedTools: csvListOptional(fm.disallowed_tools),
59
+ extensions: inheritField(fm.extensions ?? fm.inherit_extensions),
60
+ skills: inheritField(fm.skills ?? fm.inherit_skills),
61
+ model: str(fm.model),
62
+ thinking: str(fm.thinking) as ThinkingLevel | undefined,
63
+ maxTurns: nonNegativeInt(fm.max_turns),
64
+ systemPrompt: body.trim(),
65
+ promptMode: fm.prompt_mode === "append" ? "append" : "replace",
66
+ inheritContext: fm.inherit_context != null ? fm.inherit_context === true : undefined,
67
+ runInBackground: fm.run_in_background != null ? fm.run_in_background === true : undefined,
68
+ isolated: fm.isolated != null ? fm.isolated === true : undefined,
69
+ memory: parseMemory(fm.memory),
70
+ isolation: fm.isolation === "worktree" ? "worktree" : undefined,
71
+ enabled: fm.enabled !== false, // default true; explicitly false disables
72
+ source,
73
+ });
74
+ }
75
+ }
76
+
77
+ // ---- Field parsers ----
78
+ // All follow the same convention: omitted → default, "none"/empty → nothing, value → exact.
79
+
80
+ /** Extract a string or undefined. */
81
+ function str(val: unknown): string | undefined {
82
+ return typeof val === "string" ? val : undefined;
83
+ }
84
+
85
+ /** Extract a non-negative integer or undefined. 0 means unlimited for max_turns. */
86
+ function nonNegativeInt(val: unknown): number | undefined {
87
+ return typeof val === "number" && val >= 0 ? val : undefined;
88
+ }
89
+
90
+ /**
91
+ * Parse a raw CSV field value into items, or undefined if absent/empty/"none".
92
+ */
93
+ function parseCsvField(val: unknown): string[] | undefined {
94
+ if (val === undefined || val === null) return undefined;
95
+ const s = String(val).trim();
96
+ if (!s || s === "none") return undefined;
97
+ const items = s.split(",").map(t => t.trim()).filter(Boolean);
98
+ return items.length > 0 ? items : undefined;
99
+ }
100
+
101
+ /**
102
+ * Parse a comma-separated list field with defaults.
103
+ * omitted → defaults; "none"/empty → []; csv → listed items.
104
+ */
105
+ function csvList(val: unknown, defaults: string[]): string[] {
106
+ if (val === undefined || val === null) return defaults;
107
+ return parseCsvField(val) ?? [];
108
+ }
109
+
110
+ /**
111
+ * Parse an optional comma-separated list field.
112
+ * omitted → undefined; "none"/empty → undefined; csv → listed items.
113
+ */
114
+ function csvListOptional(val: unknown): string[] | undefined {
115
+ return parseCsvField(val);
116
+ }
117
+
118
+ /**
119
+ * Parse a memory scope field.
120
+ * omitted → undefined; "user"/"project"/"local" → MemoryScope.
121
+ */
122
+ function parseMemory(val: unknown): MemoryScope | undefined {
123
+ if (val === "user" || val === "project" || val === "local") return val;
124
+ return undefined;
125
+ }
126
+
127
+ /**
128
+ * Parse an inherit field (extensions, skills).
129
+ * omitted/true → true (inherit all); false/"none"/empty → false; csv → listed names.
130
+ */
131
+ function inheritField(val: unknown): true | string[] | false {
132
+ if (val === undefined || val === null || val === true) return true;
133
+ if (val === false || val === "none") return false;
134
+ const items = csvList(val, []);
135
+ return items.length > 0 ? items : false;
136
+ }
@@ -0,0 +1,123 @@
1
+ /**
2
+ * default-agents.ts — Embedded default agent configurations.
3
+ *
4
+ * These are always available but can be overridden by user .md files with the same name.
5
+ */
6
+
7
+ import type { AgentConfig } from "./types.js";
8
+
9
+ const READ_ONLY_TOOLS = ["read", "bash", "grep", "find", "ls"];
10
+
11
+ export const DEFAULT_AGENTS: Map<string, AgentConfig> = new Map([
12
+ [
13
+ "general-purpose",
14
+ {
15
+ name: "general-purpose",
16
+ displayName: "Agent",
17
+ description: "General-purpose agent for complex, multi-step tasks",
18
+ // builtinToolNames omitted — means "all available tools" (resolved at lookup time)
19
+ // inheritContext / runInBackground / isolated omitted — strategy fields, callers decide per-call.
20
+ // Setting them to false would lock callsite intent (see resolveAgentInvocationConfig in invocation-config.ts).
21
+ extensions: true,
22
+ skills: true,
23
+ systemPrompt: "",
24
+ promptMode: "append",
25
+ isDefault: true,
26
+ },
27
+ ],
28
+ [
29
+ "Explore",
30
+ {
31
+ name: "Explore",
32
+ displayName: "Explore",
33
+ description: "Fast codebase exploration agent (read-only)",
34
+ builtinToolNames: READ_ONLY_TOOLS,
35
+ extensions: true,
36
+ skills: true,
37
+ model: "anthropic/claude-haiku-4-5-20251001",
38
+ systemPrompt: `# CRITICAL: READ-ONLY MODE - NO FILE MODIFICATIONS
39
+ You are a file search specialist. You excel at thoroughly navigating and exploring codebases.
40
+ Your role is EXCLUSIVELY to search and analyze existing code. You do NOT have access to file editing tools.
41
+
42
+ You are STRICTLY PROHIBITED from:
43
+ - Creating new files
44
+ - Modifying existing files
45
+ - Deleting files
46
+ - Moving or copying files
47
+ - Creating temporary files anywhere, including /tmp
48
+ - Using redirect operators (>, >>, |) or heredocs to write to files
49
+ - Running ANY commands that change system state
50
+
51
+ Use Bash ONLY for read-only operations: ls, git status, git log, git diff, find, cat, head, tail.
52
+
53
+ # Tool Usage
54
+ - Use the find tool for file pattern matching (NOT the bash find command)
55
+ - Use the grep tool for content search (NOT bash grep/rg command)
56
+ - Use the read tool for reading files (NOT bash cat/head/tail)
57
+ - Use Bash ONLY for read-only operations
58
+ - Make independent tool calls in parallel for efficiency
59
+ - Adapt search approach based on thoroughness level specified
60
+
61
+ # Output
62
+ - Use absolute file paths in all references
63
+ - Report findings as regular messages
64
+ - Do not use emojis
65
+ - Be thorough and precise`,
66
+ promptMode: "replace",
67
+ isDefault: true,
68
+ },
69
+ ],
70
+ [
71
+ "Plan",
72
+ {
73
+ name: "Plan",
74
+ displayName: "Plan",
75
+ description: "Software architect for implementation planning (read-only)",
76
+ builtinToolNames: READ_ONLY_TOOLS,
77
+ extensions: true,
78
+ skills: true,
79
+ systemPrompt: `# CRITICAL: READ-ONLY MODE - NO FILE MODIFICATIONS
80
+ You are a software architect and planning specialist.
81
+ Your role is EXCLUSIVELY to explore the codebase and design implementation plans.
82
+ You do NOT have access to file editing tools — attempting to edit files will fail.
83
+
84
+ You are STRICTLY PROHIBITED from:
85
+ - Creating new files
86
+ - Modifying existing files
87
+ - Deleting files
88
+ - Moving or copying files
89
+ - Creating temporary files anywhere, including /tmp
90
+ - Using redirect operators (>, >>, |) or heredocs to write to files
91
+ - Running ANY commands that change system state
92
+
93
+ # Planning Process
94
+ 1. Understand requirements
95
+ 2. Explore thoroughly (read files, find patterns, understand architecture)
96
+ 3. Design solution based on your assigned perspective
97
+ 4. Detail the plan with step-by-step implementation strategy
98
+
99
+ # Requirements
100
+ - Consider trade-offs and architectural decisions
101
+ - Identify dependencies and sequencing
102
+ - Anticipate potential challenges
103
+ - Follow existing patterns where appropriate
104
+
105
+ # Tool Usage
106
+ - Use the find tool for file pattern matching (NOT the bash find command)
107
+ - Use the grep tool for content search (NOT bash grep/rg command)
108
+ - Use the read tool for reading files (NOT bash cat/head/tail)
109
+ - Use Bash ONLY for read-only operations
110
+
111
+ # Output Format
112
+ - Use absolute file paths
113
+ - Do not use emojis
114
+ - End your response with:
115
+
116
+ ### Critical Files for Implementation
117
+ List 3-5 files most critical for implementing this plan:
118
+ - /absolute/path/to/file.ts - [Brief reason]`,
119
+ promptMode: "replace",
120
+ isDefault: true,
121
+ },
122
+ ],
123
+ ]);
package/src/env.ts ADDED
@@ -0,0 +1,33 @@
1
+ /**
2
+ * env.ts — Detect environment info (git, platform) for subagent system prompts.
3
+ */
4
+
5
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
6
+ import type { EnvInfo } from "./types.js";
7
+
8
+ export async function detectEnv(pi: ExtensionAPI, cwd: string): Promise<EnvInfo> {
9
+ let isGitRepo = false;
10
+ let branch = "";
11
+
12
+ try {
13
+ const result = await pi.exec("git", ["rev-parse", "--is-inside-work-tree"], { cwd, timeout: 5000 });
14
+ isGitRepo = result.code === 0 && result.stdout.trim() === "true";
15
+ } catch {
16
+ // Not a git repo or git not installed
17
+ }
18
+
19
+ if (isGitRepo) {
20
+ try {
21
+ const result = await pi.exec("git", ["branch", "--show-current"], { cwd, timeout: 5000 });
22
+ branch = result.code === 0 ? result.stdout.trim() : "unknown";
23
+ } catch {
24
+ branch = "unknown";
25
+ }
26
+ }
27
+
28
+ return {
29
+ isGitRepo,
30
+ branch,
31
+ platform: process.platform,
32
+ };
33
+ }