@tintinweb/pi-subagents 0.4.0 → 0.4.3

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.
@@ -0,0 +1,126 @@
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
+ const READ_ONLY_TOOLS = ["read", "bash", "grep", "find", "ls"];
7
+ export const DEFAULT_AGENTS = new Map([
8
+ [
9
+ "general-purpose",
10
+ {
11
+ name: "general-purpose",
12
+ displayName: "Agent",
13
+ description: "General-purpose agent for complex, multi-step tasks",
14
+ // builtinToolNames omitted — means "all available tools" (resolved at lookup time)
15
+ extensions: true,
16
+ skills: true,
17
+ systemPrompt: "",
18
+ promptMode: "append",
19
+ inheritContext: false,
20
+ runInBackground: false,
21
+ isolated: false,
22
+ isDefault: true,
23
+ },
24
+ ],
25
+ [
26
+ "Explore",
27
+ {
28
+ name: "Explore",
29
+ displayName: "Explore",
30
+ description: "Fast codebase exploration agent (read-only)",
31
+ builtinToolNames: READ_ONLY_TOOLS,
32
+ extensions: true,
33
+ skills: true,
34
+ model: "anthropic/claude-haiku-4-5-20251001",
35
+ systemPrompt: `# CRITICAL: READ-ONLY MODE - NO FILE MODIFICATIONS
36
+ You are a file search specialist. You excel at thoroughly navigating and exploring codebases.
37
+ Your role is EXCLUSIVELY to search and analyze existing code. You do NOT have access to file editing tools.
38
+
39
+ You are STRICTLY PROHIBITED from:
40
+ - Creating new files
41
+ - Modifying existing files
42
+ - Deleting files
43
+ - Moving or copying files
44
+ - Creating temporary files anywhere, including /tmp
45
+ - Using redirect operators (>, >>, |) or heredocs to write to files
46
+ - Running ANY commands that change system state
47
+
48
+ Use Bash ONLY for read-only operations: ls, git status, git log, git diff, find, cat, head, tail.
49
+
50
+ # Tool Usage
51
+ - Use the find tool for file pattern matching (NOT the bash find command)
52
+ - Use the grep tool for content search (NOT bash grep/rg command)
53
+ - Use the read tool for reading files (NOT bash cat/head/tail)
54
+ - Use Bash ONLY for read-only operations
55
+ - Make independent tool calls in parallel for efficiency
56
+ - Adapt search approach based on thoroughness level specified
57
+
58
+ # Output
59
+ - Use absolute file paths in all references
60
+ - Report findings as regular messages
61
+ - Do not use emojis
62
+ - Be thorough and precise`,
63
+ promptMode: "replace",
64
+ inheritContext: false,
65
+ runInBackground: false,
66
+ isolated: false,
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
+ inheritContext: false,
121
+ runInBackground: false,
122
+ isolated: false,
123
+ isDefault: true,
124
+ },
125
+ ],
126
+ ]);
package/dist/env.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ /**
2
+ * env.ts — Detect environment info (git, platform) for subagent system prompts.
3
+ */
4
+ import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
5
+ import type { EnvInfo } from "./types.js";
6
+ export declare function detectEnv(pi: ExtensionAPI, cwd: string): Promise<EnvInfo>;
package/dist/env.js ADDED
@@ -0,0 +1,28 @@
1
+ /**
2
+ * env.ts — Detect environment info (git, platform) for subagent system prompts.
3
+ */
4
+ export async function detectEnv(pi, cwd) {
5
+ let isGitRepo = false;
6
+ let branch = "";
7
+ try {
8
+ const result = await pi.exec("git", ["rev-parse", "--is-inside-work-tree"], { cwd, timeout: 5000 });
9
+ isGitRepo = result.code === 0 && result.stdout.trim() === "true";
10
+ }
11
+ catch {
12
+ // Not a git repo or git not installed
13
+ }
14
+ if (isGitRepo) {
15
+ try {
16
+ const result = await pi.exec("git", ["branch", "--show-current"], { cwd, timeout: 5000 });
17
+ branch = result.code === 0 ? result.stdout.trim() : "unknown";
18
+ }
19
+ catch {
20
+ branch = "unknown";
21
+ }
22
+ }
23
+ return {
24
+ isGitRepo,
25
+ branch,
26
+ platform: process.platform,
27
+ };
28
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * group-join.ts — Manages grouped background agent completion notifications.
3
+ *
4
+ * Instead of each agent individually nudging the main agent on completion,
5
+ * agents in a group are held until all complete (or a timeout fires),
6
+ * then a single consolidated notification is sent.
7
+ */
8
+ import type { AgentRecord } from "./types.js";
9
+ export type DeliveryCallback = (records: AgentRecord[], partial: boolean) => void;
10
+ export declare class GroupJoinManager {
11
+ private deliverCb;
12
+ private groupTimeout;
13
+ private groups;
14
+ private agentToGroup;
15
+ constructor(deliverCb: DeliveryCallback, groupTimeout?: number);
16
+ /** Register a group of agent IDs that should be joined. */
17
+ registerGroup(groupId: string, agentIds: string[]): void;
18
+ /**
19
+ * Called when an agent completes.
20
+ * Returns:
21
+ * - 'pass' — agent is not grouped, caller should send individual nudge
22
+ * - 'held' — result held, waiting for group completion
23
+ * - 'delivered' — this completion triggered the group notification
24
+ */
25
+ onAgentComplete(record: AgentRecord): 'delivered' | 'held' | 'pass';
26
+ private onTimeout;
27
+ private deliver;
28
+ private cleanupGroup;
29
+ /** Check if an agent is in a group. */
30
+ isGrouped(agentId: string): boolean;
31
+ dispose(): void;
32
+ }
@@ -0,0 +1,116 @@
1
+ /**
2
+ * group-join.ts — Manages grouped background agent completion notifications.
3
+ *
4
+ * Instead of each agent individually nudging the main agent on completion,
5
+ * agents in a group are held until all complete (or a timeout fires),
6
+ * then a single consolidated notification is sent.
7
+ */
8
+ /** Default timeout: 30s after first completion in a group. */
9
+ const DEFAULT_TIMEOUT = 30_000;
10
+ /** Straggler re-batch timeout: 15s. */
11
+ const STRAGGLER_TIMEOUT = 15_000;
12
+ export class GroupJoinManager {
13
+ deliverCb;
14
+ groupTimeout;
15
+ groups = new Map();
16
+ agentToGroup = new Map();
17
+ constructor(deliverCb, groupTimeout = DEFAULT_TIMEOUT) {
18
+ this.deliverCb = deliverCb;
19
+ this.groupTimeout = groupTimeout;
20
+ }
21
+ /** Register a group of agent IDs that should be joined. */
22
+ registerGroup(groupId, agentIds) {
23
+ const group = {
24
+ groupId,
25
+ agentIds: new Set(agentIds),
26
+ completedRecords: new Map(),
27
+ delivered: false,
28
+ isStraggler: false,
29
+ };
30
+ this.groups.set(groupId, group);
31
+ for (const id of agentIds) {
32
+ this.agentToGroup.set(id, groupId);
33
+ }
34
+ }
35
+ /**
36
+ * Called when an agent completes.
37
+ * Returns:
38
+ * - 'pass' — agent is not grouped, caller should send individual nudge
39
+ * - 'held' — result held, waiting for group completion
40
+ * - 'delivered' — this completion triggered the group notification
41
+ */
42
+ onAgentComplete(record) {
43
+ const groupId = this.agentToGroup.get(record.id);
44
+ if (!groupId)
45
+ return 'pass';
46
+ const group = this.groups.get(groupId);
47
+ if (!group || group.delivered)
48
+ return 'pass';
49
+ group.completedRecords.set(record.id, record);
50
+ // All done — deliver immediately
51
+ if (group.completedRecords.size >= group.agentIds.size) {
52
+ this.deliver(group, false);
53
+ return 'delivered';
54
+ }
55
+ // First completion in this batch — start timeout
56
+ if (!group.timeoutHandle) {
57
+ const timeout = group.isStraggler ? STRAGGLER_TIMEOUT : this.groupTimeout;
58
+ group.timeoutHandle = setTimeout(() => {
59
+ this.onTimeout(group);
60
+ }, timeout);
61
+ }
62
+ return 'held';
63
+ }
64
+ onTimeout(group) {
65
+ if (group.delivered)
66
+ return;
67
+ group.timeoutHandle = undefined;
68
+ // Partial delivery — some agents still running
69
+ const remaining = new Set();
70
+ for (const id of group.agentIds) {
71
+ if (!group.completedRecords.has(id))
72
+ remaining.add(id);
73
+ }
74
+ // Clean up agentToGroup for delivered agents (they won't complete again)
75
+ for (const id of group.completedRecords.keys()) {
76
+ this.agentToGroup.delete(id);
77
+ }
78
+ // Deliver what we have
79
+ this.deliverCb([...group.completedRecords.values()], true);
80
+ // Set up straggler group for remaining agents
81
+ group.completedRecords.clear();
82
+ group.agentIds = remaining;
83
+ group.isStraggler = true;
84
+ // Timeout will be started when the next straggler completes
85
+ }
86
+ deliver(group, partial) {
87
+ if (group.timeoutHandle) {
88
+ clearTimeout(group.timeoutHandle);
89
+ group.timeoutHandle = undefined;
90
+ }
91
+ group.delivered = true;
92
+ this.deliverCb([...group.completedRecords.values()], partial);
93
+ this.cleanupGroup(group.groupId);
94
+ }
95
+ cleanupGroup(groupId) {
96
+ const group = this.groups.get(groupId);
97
+ if (!group)
98
+ return;
99
+ for (const id of group.agentIds) {
100
+ this.agentToGroup.delete(id);
101
+ }
102
+ this.groups.delete(groupId);
103
+ }
104
+ /** Check if an agent is in a group. */
105
+ isGrouped(agentId) {
106
+ return this.agentToGroup.has(agentId);
107
+ }
108
+ dispose() {
109
+ for (const group of this.groups.values()) {
110
+ if (group.timeoutHandle)
111
+ clearTimeout(group.timeoutHandle);
112
+ }
113
+ this.groups.clear();
114
+ this.agentToGroup.clear();
115
+ }
116
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * pi-agents — A pi extension providing Claude Code-style autonomous sub-agents.
3
+ *
4
+ * Tools:
5
+ * Agent — LLM-callable: spawn a sub-agent
6
+ * get_subagent_result — LLM-callable: check background agent status/result
7
+ * steer_subagent — LLM-callable: send a steering message to a running agent
8
+ *
9
+ * Commands:
10
+ * /agents — Interactive agent management menu
11
+ */
12
+ import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
13
+ export default function (pi: ExtensionAPI): void;