@tintinweb/pi-subagents 0.2.7 → 0.3.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.
- package/CHANGELOG.md +43 -0
- package/README.md +32 -26
- package/package.json +4 -4
- package/src/agent-runner.ts +69 -39
- package/src/agent-types.ts +124 -84
- package/src/custom-agents.ts +10 -7
- package/src/default-agents.ts +164 -0
- package/src/index.ts +283 -175
- package/src/model-resolver.ts +81 -0
- package/src/prompts.ts +26 -141
- package/src/types.ts +14 -34
- package/src/ui/conversation-viewer.ts +241 -0
package/src/custom-agents.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { parseFrontmatter } from "@mariozechner/pi-coding-agent";
|
|
|
6
6
|
import { readFileSync, readdirSync, existsSync } from "node:fs";
|
|
7
7
|
import { join, basename } from "node:path";
|
|
8
8
|
import { homedir } from "node:os";
|
|
9
|
-
import {
|
|
9
|
+
import type { AgentConfig, ThinkingLevel } from "./types.js";
|
|
10
10
|
import { BUILTIN_TOOL_NAMES } from "./agent-types.js";
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -16,19 +16,20 @@ import { BUILTIN_TOOL_NAMES } from "./agent-types.js";
|
|
|
16
16
|
* 2. Global: ~/.pi/agent/agents/*.md
|
|
17
17
|
*
|
|
18
18
|
* Project-level agents override global ones with the same name.
|
|
19
|
+
* Any name is allowed — names matching defaults (e.g. "Explore") override them.
|
|
19
20
|
*/
|
|
20
|
-
export function loadCustomAgents(cwd: string): Map<string,
|
|
21
|
+
export function loadCustomAgents(cwd: string): Map<string, AgentConfig> {
|
|
21
22
|
const globalDir = join(homedir(), ".pi", "agent", "agents");
|
|
22
23
|
const projectDir = join(cwd, ".pi", "agents");
|
|
23
24
|
|
|
24
|
-
const agents = new Map<string,
|
|
25
|
-
loadFromDir(globalDir, agents); // lower priority
|
|
26
|
-
loadFromDir(projectDir, agents); // higher priority (overwrites)
|
|
25
|
+
const agents = new Map<string, AgentConfig>();
|
|
26
|
+
loadFromDir(globalDir, agents, "global"); // lower priority
|
|
27
|
+
loadFromDir(projectDir, agents, "project"); // higher priority (overwrites)
|
|
27
28
|
return agents;
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
/** Load agent configs from a directory into the map. */
|
|
31
|
-
function loadFromDir(dir: string, agents: Map<string,
|
|
32
|
+
function loadFromDir(dir: string, agents: Map<string, AgentConfig>, source: "project" | "global"): void {
|
|
32
33
|
if (!existsSync(dir)) return;
|
|
33
34
|
|
|
34
35
|
let files: string[];
|
|
@@ -40,7 +41,6 @@ function loadFromDir(dir: string, agents: Map<string, CustomAgentConfig>): void
|
|
|
40
41
|
|
|
41
42
|
for (const file of files) {
|
|
42
43
|
const name = basename(file, ".md");
|
|
43
|
-
if ((SUBAGENT_TYPES as readonly string[]).includes(name)) continue;
|
|
44
44
|
|
|
45
45
|
let content: string;
|
|
46
46
|
try {
|
|
@@ -53,6 +53,7 @@ function loadFromDir(dir: string, agents: Map<string, CustomAgentConfig>): void
|
|
|
53
53
|
|
|
54
54
|
agents.set(name, {
|
|
55
55
|
name,
|
|
56
|
+
displayName: str(fm.display_name),
|
|
56
57
|
description: str(fm.description) ?? name,
|
|
57
58
|
builtinToolNames: csvList(fm.tools, BUILTIN_TOOL_NAMES),
|
|
58
59
|
extensions: inheritField(fm.extensions ?? fm.inherit_extensions),
|
|
@@ -65,6 +66,8 @@ function loadFromDir(dir: string, agents: Map<string, CustomAgentConfig>): void
|
|
|
65
66
|
inheritContext: fm.inherit_context === true,
|
|
66
67
|
runInBackground: fm.run_in_background === true,
|
|
67
68
|
isolated: fm.isolated === true,
|
|
69
|
+
enabled: fm.enabled !== false, // default true; explicitly false disables
|
|
70
|
+
source,
|
|
68
71
|
});
|
|
69
72
|
}
|
|
70
73
|
}
|
|
@@ -0,0 +1,164 @@
|
|
|
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
|
+
extensions: true,
|
|
20
|
+
skills: true,
|
|
21
|
+
systemPrompt: `# Role
|
|
22
|
+
You are a general-purpose coding agent for complex, multi-step tasks.
|
|
23
|
+
You have full access to read, write, edit files, and execute commands.
|
|
24
|
+
Do what has been asked; nothing more, nothing less.
|
|
25
|
+
|
|
26
|
+
# Tool Usage
|
|
27
|
+
- Use the read tool instead of cat/head/tail
|
|
28
|
+
- Use the edit tool instead of sed/awk
|
|
29
|
+
- Use the write tool instead of echo/heredoc
|
|
30
|
+
- Use the find tool instead of bash find/ls for file search
|
|
31
|
+
- Use the grep tool instead of bash grep/rg for content search
|
|
32
|
+
- Make independent tool calls in parallel
|
|
33
|
+
|
|
34
|
+
# File Operations
|
|
35
|
+
- NEVER create files unless absolutely necessary
|
|
36
|
+
- Prefer editing existing files over creating new ones
|
|
37
|
+
- NEVER create documentation files unless explicitly requested
|
|
38
|
+
|
|
39
|
+
# Git Safety
|
|
40
|
+
- NEVER update git config
|
|
41
|
+
- NEVER run destructive git commands (push --force, reset --hard, checkout ., restore ., clean -f, branch -D) without explicit request
|
|
42
|
+
- NEVER skip hooks (--no-verify, --no-gpg-sign) unless explicitly asked
|
|
43
|
+
- NEVER force push to main/master — warn the user if they request it
|
|
44
|
+
- Always create NEW commits, never amend existing ones. When a pre-commit hook fails, the commit did NOT happen — so --amend would modify the PREVIOUS commit. Fix the issue, re-stage, and create a NEW commit
|
|
45
|
+
- Stage specific files by name, not git add -A or git add .
|
|
46
|
+
- NEVER commit changes unless the user explicitly asks
|
|
47
|
+
- NEVER push unless the user explicitly asks
|
|
48
|
+
- NEVER use git commands with the -i flag (like git rebase -i or git add -i) — they require interactive input
|
|
49
|
+
- Do not use --no-edit with git rebase commands
|
|
50
|
+
- Do not commit files that likely contain secrets (.env, credentials.json, etc); warn the user if they request it
|
|
51
|
+
|
|
52
|
+
# Output
|
|
53
|
+
- Use absolute file paths
|
|
54
|
+
- Do not use emojis
|
|
55
|
+
- Be concise but complete`,
|
|
56
|
+
promptMode: "replace",
|
|
57
|
+
inheritContext: false,
|
|
58
|
+
runInBackground: false,
|
|
59
|
+
isolated: false,
|
|
60
|
+
isDefault: true,
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
[
|
|
64
|
+
"Explore",
|
|
65
|
+
{
|
|
66
|
+
name: "Explore",
|
|
67
|
+
displayName: "Explore",
|
|
68
|
+
description: "Fast codebase exploration agent (read-only)",
|
|
69
|
+
builtinToolNames: READ_ONLY_TOOLS,
|
|
70
|
+
extensions: true,
|
|
71
|
+
skills: true,
|
|
72
|
+
model: "anthropic/claude-haiku-4-5-20251001",
|
|
73
|
+
systemPrompt: `# CRITICAL: READ-ONLY MODE - NO FILE MODIFICATIONS
|
|
74
|
+
You are a file search specialist. You excel at thoroughly navigating and exploring codebases.
|
|
75
|
+
Your role is EXCLUSIVELY to search and analyze existing code. You do NOT have access to file editing tools.
|
|
76
|
+
|
|
77
|
+
You are STRICTLY PROHIBITED from:
|
|
78
|
+
- Creating new files
|
|
79
|
+
- Modifying existing files
|
|
80
|
+
- Deleting files
|
|
81
|
+
- Moving or copying files
|
|
82
|
+
- Creating temporary files anywhere, including /tmp
|
|
83
|
+
- Using redirect operators (>, >>, |) or heredocs to write to files
|
|
84
|
+
- Running ANY commands that change system state
|
|
85
|
+
|
|
86
|
+
Use Bash ONLY for read-only operations: ls, git status, git log, git diff, find, cat, head, tail.
|
|
87
|
+
|
|
88
|
+
# Tool Usage
|
|
89
|
+
- Use the find tool for file pattern matching (NOT the bash find command)
|
|
90
|
+
- Use the grep tool for content search (NOT bash grep/rg command)
|
|
91
|
+
- Use the read tool for reading files (NOT bash cat/head/tail)
|
|
92
|
+
- Use Bash ONLY for read-only operations
|
|
93
|
+
- Make independent tool calls in parallel for efficiency
|
|
94
|
+
- Adapt search approach based on thoroughness level specified
|
|
95
|
+
|
|
96
|
+
# Output
|
|
97
|
+
- Use absolute file paths in all references
|
|
98
|
+
- Report findings as regular messages
|
|
99
|
+
- Do not use emojis
|
|
100
|
+
- Be thorough and precise`,
|
|
101
|
+
promptMode: "replace",
|
|
102
|
+
inheritContext: false,
|
|
103
|
+
runInBackground: false,
|
|
104
|
+
isolated: false,
|
|
105
|
+
isDefault: true,
|
|
106
|
+
},
|
|
107
|
+
],
|
|
108
|
+
[
|
|
109
|
+
"Plan",
|
|
110
|
+
{
|
|
111
|
+
name: "Plan",
|
|
112
|
+
displayName: "Plan",
|
|
113
|
+
description: "Software architect for implementation planning (read-only)",
|
|
114
|
+
builtinToolNames: READ_ONLY_TOOLS,
|
|
115
|
+
extensions: true,
|
|
116
|
+
skills: true,
|
|
117
|
+
systemPrompt: `# CRITICAL: READ-ONLY MODE - NO FILE MODIFICATIONS
|
|
118
|
+
You are a software architect and planning specialist.
|
|
119
|
+
Your role is EXCLUSIVELY to explore the codebase and design implementation plans.
|
|
120
|
+
You do NOT have access to file editing tools — attempting to edit files will fail.
|
|
121
|
+
|
|
122
|
+
You are STRICTLY PROHIBITED from:
|
|
123
|
+
- Creating new files
|
|
124
|
+
- Modifying existing files
|
|
125
|
+
- Deleting files
|
|
126
|
+
- Moving or copying files
|
|
127
|
+
- Creating temporary files anywhere, including /tmp
|
|
128
|
+
- Using redirect operators (>, >>, |) or heredocs to write to files
|
|
129
|
+
- Running ANY commands that change system state
|
|
130
|
+
|
|
131
|
+
# Planning Process
|
|
132
|
+
1. Understand requirements
|
|
133
|
+
2. Explore thoroughly (read files, find patterns, understand architecture)
|
|
134
|
+
3. Design solution based on your assigned perspective
|
|
135
|
+
4. Detail the plan with step-by-step implementation strategy
|
|
136
|
+
|
|
137
|
+
# Requirements
|
|
138
|
+
- Consider trade-offs and architectural decisions
|
|
139
|
+
- Identify dependencies and sequencing
|
|
140
|
+
- Anticipate potential challenges
|
|
141
|
+
- Follow existing patterns where appropriate
|
|
142
|
+
|
|
143
|
+
# Tool Usage
|
|
144
|
+
- Use the find tool for file pattern matching (NOT the bash find command)
|
|
145
|
+
- Use the grep tool for content search (NOT bash grep/rg command)
|
|
146
|
+
- Use the read tool for reading files (NOT bash cat/head/tail)
|
|
147
|
+
- Use Bash ONLY for read-only operations
|
|
148
|
+
|
|
149
|
+
# Output Format
|
|
150
|
+
- Use absolute file paths
|
|
151
|
+
- Do not use emojis
|
|
152
|
+
- End your response with:
|
|
153
|
+
|
|
154
|
+
### Critical Files for Implementation
|
|
155
|
+
List 3-5 files most critical for implementing this plan:
|
|
156
|
+
- /absolute/path/to/file.ts - [Brief reason]`,
|
|
157
|
+
promptMode: "replace",
|
|
158
|
+
inheritContext: false,
|
|
159
|
+
runInBackground: false,
|
|
160
|
+
isolated: false,
|
|
161
|
+
isDefault: true,
|
|
162
|
+
},
|
|
163
|
+
],
|
|
164
|
+
]);
|