@mariozechner/pi-coding-agent 0.23.4 → 0.24.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 (104) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/README.md +20 -13
  3. package/dist/core/custom-tools/loader.d.ts.map +1 -1
  4. package/dist/core/custom-tools/loader.js +56 -6
  5. package/dist/core/custom-tools/loader.js.map +1 -1
  6. package/dist/core/custom-tools/types.d.ts +9 -1
  7. package/dist/core/custom-tools/types.d.ts.map +1 -1
  8. package/dist/core/custom-tools/types.js.map +1 -1
  9. package/dist/core/hooks/index.d.ts +2 -1
  10. package/dist/core/hooks/index.d.ts.map +1 -1
  11. package/dist/core/hooks/index.js +1 -0
  12. package/dist/core/hooks/index.js.map +1 -1
  13. package/dist/core/hooks/runner.d.ts.map +1 -1
  14. package/dist/core/hooks/runner.js +44 -4
  15. package/dist/core/hooks/runner.js.map +1 -1
  16. package/dist/core/hooks/tool-wrapper.d.ts.map +1 -1
  17. package/dist/core/hooks/tool-wrapper.js +5 -9
  18. package/dist/core/hooks/tool-wrapper.js.map +1 -1
  19. package/dist/core/hooks/types.d.ts +73 -11
  20. package/dist/core/hooks/types.d.ts.map +1 -1
  21. package/dist/core/hooks/types.js +22 -1
  22. package/dist/core/hooks/types.js.map +1 -1
  23. package/dist/core/skills.d.ts +18 -5
  24. package/dist/core/skills.d.ts.map +1 -1
  25. package/dist/core/skills.js +183 -72
  26. package/dist/core/skills.js.map +1 -1
  27. package/dist/core/slash-commands.d.ts.map +1 -1
  28. package/dist/core/slash-commands.js +2 -2
  29. package/dist/core/slash-commands.js.map +1 -1
  30. package/dist/core/system-prompt.d.ts.map +1 -1
  31. package/dist/core/system-prompt.js +2 -2
  32. package/dist/core/system-prompt.js.map +1 -1
  33. package/dist/core/tools/bash.d.ts +5 -0
  34. package/dist/core/tools/bash.d.ts.map +1 -1
  35. package/dist/core/tools/bash.js.map +1 -1
  36. package/dist/core/tools/find.d.ts +5 -0
  37. package/dist/core/tools/find.d.ts.map +1 -1
  38. package/dist/core/tools/find.js.map +1 -1
  39. package/dist/core/tools/grep.d.ts +6 -0
  40. package/dist/core/tools/grep.d.ts.map +1 -1
  41. package/dist/core/tools/grep.js.map +1 -1
  42. package/dist/core/tools/index.d.ts +6 -5
  43. package/dist/core/tools/index.d.ts.map +1 -1
  44. package/dist/core/tools/index.js.map +1 -1
  45. package/dist/core/tools/ls.d.ts +5 -0
  46. package/dist/core/tools/ls.d.ts.map +1 -1
  47. package/dist/core/tools/ls.js.map +1 -1
  48. package/dist/core/tools/read.d.ts +4 -0
  49. package/dist/core/tools/read.d.ts.map +1 -1
  50. package/dist/core/tools/read.js.map +1 -1
  51. package/dist/index.d.ts +5 -3
  52. package/dist/index.d.ts.map +1 -1
  53. package/dist/index.js +5 -1
  54. package/dist/index.js.map +1 -1
  55. package/dist/main.d.ts.map +1 -1
  56. package/dist/main.js +4 -0
  57. package/dist/main.js.map +1 -1
  58. package/dist/modes/interactive/components/custom-editor.d.ts +1 -0
  59. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
  60. package/dist/modes/interactive/components/custom-editor.js +16 -7
  61. package/dist/modes/interactive/components/custom-editor.js.map +1 -1
  62. package/dist/modes/interactive/components/hook-input.d.ts.map +1 -1
  63. package/dist/modes/interactive/components/hook-input.js +2 -2
  64. package/dist/modes/interactive/components/hook-input.js.map +1 -1
  65. package/dist/modes/interactive/components/hook-selector.d.ts.map +1 -1
  66. package/dist/modes/interactive/components/hook-selector.js +2 -2
  67. package/dist/modes/interactive/components/hook-selector.js.map +1 -1
  68. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  69. package/dist/modes/interactive/components/model-selector.js +2 -2
  70. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  71. package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
  72. package/dist/modes/interactive/components/oauth-selector.js +2 -2
  73. package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
  74. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  75. package/dist/modes/interactive/components/session-selector.js +3 -3
  76. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  77. package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -1
  78. package/dist/modes/interactive/components/user-message-selector.js +3 -3
  79. package/dist/modes/interactive/components/user-message-selector.js.map +1 -1
  80. package/dist/modes/interactive/interactive-mode.d.ts +2 -0
  81. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  82. package/dist/modes/interactive/interactive-mode.js +63 -1
  83. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  84. package/dist/modes/print-mode.d.ts.map +1 -1
  85. package/dist/modes/print-mode.js +10 -0
  86. package/dist/modes/print-mode.js.map +1 -1
  87. package/docs/custom-tools.md +43 -4
  88. package/docs/hooks.md +104 -5
  89. package/docs/skills.md +65 -24
  90. package/examples/custom-tools/README.md +18 -7
  91. package/examples/custom-tools/subagent/README.md +172 -0
  92. package/examples/custom-tools/subagent/agents/planner.md +37 -0
  93. package/examples/custom-tools/subagent/agents/reviewer.md +35 -0
  94. package/examples/custom-tools/subagent/agents/scout.md +50 -0
  95. package/examples/custom-tools/subagent/agents/worker.md +24 -0
  96. package/examples/custom-tools/subagent/agents.ts +157 -0
  97. package/examples/custom-tools/subagent/commands/implement-and-review.md +10 -0
  98. package/examples/custom-tools/subagent/commands/implement.md +10 -0
  99. package/examples/custom-tools/subagent/commands/scout-and-plan.md +9 -0
  100. package/examples/custom-tools/subagent/index.ts +772 -0
  101. package/package.json +4 -4
  102. /package/examples/custom-tools/{hello.ts → hello/index.ts} +0 -0
  103. /package/examples/custom-tools/{question.ts → question/index.ts} +0 -0
  104. /package/examples/custom-tools/{todo.ts → todo/index.ts} +0 -0
@@ -0,0 +1,37 @@
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.
@@ -0,0 +1,35 @@
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.
@@ -0,0 +1,50 @@
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.
@@ -0,0 +1,24 @@
1
+ ---
2
+ name: worker
3
+ description: General-purpose subagent with full capabilities, isolated context
4
+ model: claude-sonnet-4-5
5
+ ---
6
+
7
+ You are a worker agent with full capabilities. You operate in an isolated context window to handle delegated tasks without polluting the main conversation.
8
+
9
+ Work autonomously to complete the assigned task. Use all available tools as needed.
10
+
11
+ Output format when finished:
12
+
13
+ ## Completed
14
+ What was done.
15
+
16
+ ## Files Changed
17
+ - `path/to/file.ts` - what changed
18
+
19
+ ## Notes (if any)
20
+ Anything the main agent should know.
21
+
22
+ If handing off to another agent (e.g. reviewer), include:
23
+ - Exact file paths changed
24
+ - Key functions/types touched (short list)
@@ -0,0 +1,157 @@
1
+ /**
2
+ * Agent discovery and configuration
3
+ */
4
+
5
+ import * as fs from "node:fs";
6
+ import * as os from "node:os";
7
+ import * as path from "node:path";
8
+
9
+ export type AgentScope = "user" | "project" | "both";
10
+
11
+ export interface AgentConfig {
12
+ name: string;
13
+ description: string;
14
+ tools?: string[];
15
+ model?: string;
16
+ systemPrompt: string;
17
+ source: "user" | "project";
18
+ filePath: string;
19
+ }
20
+
21
+ export interface AgentDiscoveryResult {
22
+ agents: AgentConfig[];
23
+ projectAgentsDir: string | null;
24
+ }
25
+
26
+ function parseFrontmatter(content: string): { frontmatter: Record<string, string>; body: string } {
27
+ const frontmatter: Record<string, string> = {};
28
+ const normalized = content.replace(/\r\n/g, "\n");
29
+
30
+ if (!normalized.startsWith("---")) {
31
+ return { frontmatter, body: normalized };
32
+ }
33
+
34
+ const endIndex = normalized.indexOf("\n---", 3);
35
+ if (endIndex === -1) {
36
+ return { frontmatter, body: normalized };
37
+ }
38
+
39
+ const frontmatterBlock = normalized.slice(4, endIndex);
40
+ const body = normalized.slice(endIndex + 4).trim();
41
+
42
+ for (const line of frontmatterBlock.split("\n")) {
43
+ const match = line.match(/^([\w-]+):\s*(.*)$/);
44
+ if (match) {
45
+ let value = match[2].trim();
46
+ if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
47
+ value = value.slice(1, -1);
48
+ }
49
+ frontmatter[match[1]] = value;
50
+ }
51
+ }
52
+
53
+ return { frontmatter, body };
54
+ }
55
+
56
+ function loadAgentsFromDir(dir: string, source: "user" | "project"): AgentConfig[] {
57
+ const agents: AgentConfig[] = [];
58
+
59
+ if (!fs.existsSync(dir)) {
60
+ return agents;
61
+ }
62
+
63
+ let entries: fs.Dirent[];
64
+ try {
65
+ entries = fs.readdirSync(dir, { withFileTypes: true });
66
+ } catch {
67
+ return agents;
68
+ }
69
+
70
+ for (const entry of entries) {
71
+ if (!entry.name.endsWith(".md")) continue;
72
+ if (!entry.isFile() && !entry.isSymbolicLink()) continue;
73
+
74
+ const filePath = path.join(dir, entry.name);
75
+ let content: string;
76
+ try {
77
+ content = fs.readFileSync(filePath, "utf-8");
78
+ } catch {
79
+ continue;
80
+ }
81
+
82
+ const { frontmatter, body } = parseFrontmatter(content);
83
+
84
+ if (!frontmatter.name || !frontmatter.description) {
85
+ continue;
86
+ }
87
+
88
+ const tools = frontmatter.tools
89
+ ?.split(",")
90
+ .map((t) => t.trim())
91
+ .filter(Boolean);
92
+
93
+ agents.push({
94
+ name: frontmatter.name,
95
+ description: frontmatter.description,
96
+ tools: tools && tools.length > 0 ? tools : undefined,
97
+ model: frontmatter.model,
98
+ systemPrompt: body,
99
+ source,
100
+ filePath,
101
+ });
102
+ }
103
+
104
+ return agents;
105
+ }
106
+
107
+ function isDirectory(p: string): boolean {
108
+ try {
109
+ return fs.statSync(p).isDirectory();
110
+ } catch {
111
+ return false;
112
+ }
113
+ }
114
+
115
+ function findNearestProjectAgentsDir(cwd: string): string | null {
116
+ let currentDir = cwd;
117
+ while (true) {
118
+ const candidate = path.join(currentDir, ".pi", "agents");
119
+ if (isDirectory(candidate)) return candidate;
120
+
121
+ const parentDir = path.dirname(currentDir);
122
+ if (parentDir === currentDir) return null;
123
+ currentDir = parentDir;
124
+ }
125
+ }
126
+
127
+ export function discoverAgents(cwd: string, scope: AgentScope): AgentDiscoveryResult {
128
+ const userDir = path.join(os.homedir(), ".pi", "agent", "agents");
129
+ const projectAgentsDir = findNearestProjectAgentsDir(cwd);
130
+
131
+ const userAgents = scope === "project" ? [] : loadAgentsFromDir(userDir, "user");
132
+ const projectAgents =
133
+ scope === "user" || !projectAgentsDir ? [] : loadAgentsFromDir(projectAgentsDir, "project");
134
+
135
+ const agentMap = new Map<string, AgentConfig>();
136
+
137
+ if (scope === "both") {
138
+ for (const agent of userAgents) agentMap.set(agent.name, agent);
139
+ for (const agent of projectAgents) agentMap.set(agent.name, agent);
140
+ } else if (scope === "user") {
141
+ for (const agent of userAgents) agentMap.set(agent.name, agent);
142
+ } else {
143
+ for (const agent of projectAgents) agentMap.set(agent.name, agent);
144
+ }
145
+
146
+ return { agents: Array.from(agentMap.values()), projectAgentsDir };
147
+ }
148
+
149
+ export function formatAgentList(agents: AgentConfig[], maxItems: number): { text: string; remaining: number } {
150
+ if (agents.length === 0) return { text: "none", remaining: 0 };
151
+ const listed = agents.slice(0, maxItems);
152
+ const remaining = agents.length - listed.length;
153
+ return {
154
+ text: listed.map((a) => `${a.name} (${a.source}): ${a.description}`).join("; "),
155
+ remaining,
156
+ };
157
+ }
@@ -0,0 +1,10 @@
1
+ ---
2
+ description: Worker implements, reviewer reviews, worker applies feedback
3
+ ---
4
+ Use the subagent tool with the chain parameter to execute this workflow:
5
+
6
+ 1. First, use the "worker" agent to implement: $@
7
+ 2. Then, use the "reviewer" agent to review the implementation from the previous step (use {previous} placeholder)
8
+ 3. Finally, use the "worker" agent to apply the feedback from the review (use {previous} placeholder)
9
+
10
+ Execute this as a chain, passing output between steps via {previous}.
@@ -0,0 +1,10 @@
1
+ ---
2
+ description: Full implementation workflow - scout gathers context, planner creates plan, worker implements
3
+ ---
4
+ Use the subagent tool with the chain parameter to execute this workflow:
5
+
6
+ 1. First, use the "scout" agent to find all code relevant to: $@
7
+ 2. Then, use the "planner" agent to create an implementation plan for "$@" using the context from the previous step (use {previous} placeholder)
8
+ 3. Finally, use the "worker" agent to implement the plan from the previous step (use {previous} placeholder)
9
+
10
+ Execute this as a chain, passing output between steps via {previous}.
@@ -0,0 +1,9 @@
1
+ ---
2
+ description: Scout gathers context, planner creates implementation plan (no implementation)
3
+ ---
4
+ Use the subagent tool with the chain parameter to execute this workflow:
5
+
6
+ 1. First, use the "scout" agent to find all code relevant to: $@
7
+ 2. Then, use the "planner" agent to create an implementation plan for "$@" using the context from the previous step (use {previous} placeholder)
8
+
9
+ Execute this as a chain, passing output between steps via {previous}. Do NOT implement - just return the plan.