@johnnywu/pi-agent-profiles 0.1.0 → 0.2.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.
package/README.md CHANGED
@@ -4,22 +4,89 @@
4
4
 
5
5
  ## Agent definitions
6
6
 
7
- Name lookup uses the user's `~/.pi/agent/agents/` directory and the selected workspace's `.pi/agents/` directory. The project takes precedence by frontmatter `name`. Within one directory, the first file in filename order wins. Invalid files are reported with their paths.
7
+ `loadAgentDefinitions()` scans `~/.pi/agent/agents/*.md` and `<cwd>/.pi/agents/*.md`. A project definition overrides a global definition with the same `name`. Within one directory, the first valid definition in filename order wins. Invalid definitions are skipped and returned as warnings with their file paths. `PI_CODING_AGENT_DIR` changes the base directory for global definitions.
8
8
 
9
9
  ```markdown
10
10
  ---
11
11
  name: reviewer
12
- description: Reviews code changes.
13
- tools: read, grep, find, ls
12
+ description: "Reviews changes for correctness and test coverage."
13
+ models: anthropic/claude-sonnet-4-6, magpie/claude/*, deep-*
14
+ thinking: high
15
+ tools: read, grep, find, ls, subagent
14
16
  skills: review-*, tdd
17
+ allowedAgents: scout, test-writer
18
+ maxDepth: 2
15
19
  systemPrompt: replace
16
- thinking: high
20
+ debug: false
17
21
  ---
18
22
 
19
23
  Review the changes. Report actionable findings with file and line references.
24
+
25
+ <pi-subagents-runtime-tools />
20
26
  ```
21
27
 
22
- The scalar frontmatter format also accepts `model`, `allowedAgents`, `maxDepth`, and `debug`. Only `name` is required. `thinking` defaults to `off`, `maxDepth` to `10`, and `systemPrompt` to `append`.
28
+ Start the file with a `---` block containing one `key: value` entry per line. The parser trims surrounding whitespace and strips quotes from the edges of a value. Blank lines and full-line `#` comments are ignored inside the block. Write lists as comma-separated values on one line (for example, `tools: read, grep`). The parser trims each item and skips empty items. Inline comments, YAML sequences, and multiline values have no special syntax. Field names are case-sensitive. The Markdown after the closing `---` is the agent prompt.
29
+
30
+ ## Field reference
31
+
32
+ | Field | Default | Syntax and behavior |
33
+ | --- | --- | --- |
34
+ | `name` | Required | Non-empty string used to look up the profile. It can differ from the filename. |
35
+ | `description` | Omitted | Optional single-line summary for callers that display profile information. The Markdown body supplies the prompt. |
36
+ | `models` | Any model allowed | Comma-separated model IDs, provider-qualified IDs, or `*` patterns. See [Model selection](#model-selection). |
37
+ | `thinking` | `off` | One of `off`, `minimal`, `low`, `medium`, `high`, or `xhigh`. The launcher requests this reasoning level for the session. Pi may clamp it to the selected model's capabilities. |
38
+ | `tools` | Entry point's existing tool selection | Comma-separated tool names and `*` patterns, or a list of `+name` and `-name` entries. See [Tool selection](#tool-selection). |
39
+ | `skills` | No skills in the profile prompt | Comma-separated skill names or `*` patterns such as `review-*`. Matches the skill's declared `name` against the entry point's discovered skills. |
40
+ | `allowedAgents` | No additional name restriction | Comma-separated exact profile names for delegation, such as `scout, test-writer`. See [Delegation](#delegation). |
41
+ | `maxDepth` | `10` | Non-negative safe integer for the depth of delegated sessions. See [Delegation](#delegation). |
42
+ | `systemPrompt` | `append` | One of `append`, `replace`, or `replace-all`. See [Prompt composition](#prompt-composition). |
43
+ | `debug` | `false` | `true` or `false` in lowercase. With `true`, the launchers write `debug-system-prompt.md` in the session working directory when a turn starts, overwriting the previous copy. |
44
+
45
+ ### Model selection
46
+
47
+ - `models: anthropic/claude-sonnet-4-6, magpie/claude/*, deep-*` allows three kinds of entries. A provider-qualified entry matches the full selection. An unqualified entry such as `deep-*` also matches the model ID portion of a qualified selection.
48
+ - `subagent` and `hc_run` accept an optional `model` argument. A selection outside a configured list fails before launch. Leave it out to use the first `models` entry. If that entry is a pattern, the launcher takes the first matching model in Pi's available catalog. A pattern with no available match produces an error even if later entries could match.
49
+ - `pi --agent` applies the first entry to the current session. If model selection or activation fails, it warns and keeps the current model.
50
+ - An omitted or empty `models` list allows any caller selection. With no explicit selection, Pi keeps its normal model selection. Rename old `model:` fields to `models:`. A profile that still contains `model:` is rejected with a migration message.
51
+
52
+ ### Tool selection
53
+
54
+ | Example | Behavior |
55
+ | --- | --- |
56
+ | `tools: read, hc_*` | Select tools by exact name or by a `*` pattern. |
57
+ | `tools: +grep, -write` | Add and remove exact names in list order. Child Pi sessions start from their default selection. `pi --agent` starts from the current session's active tools. |
58
+ | `tools:` or omitted | Keep the entry point's existing tool selection. |
59
+ | `tools: read, -write` or `tools: +hc_*` | Reject the profile. Use names and patterns together, or modifiers exclusively. Modifiers require exact tool names. |
60
+
61
+ `pi-subagents` passes the list to the child Pi's `--tools`. `pi-herdr-agents` does the same and maps the exact `subagent` name to `hc_run`, preserving any `+` or `-` prefix. For a non-empty list, Herdr also adds `hc_send` and `hc_agents` for reporting, using `+` entries in modifier mode. Pi applies its own tool availability and MCP exposure rules.
62
+
63
+ `pi --agent` resolves names and patterns against registered tools, warns about entries with no match, and applies the result to the current session's active tool list. A non-empty allowlist with zero matches clears the active selection.
64
+
65
+ ### Skills
66
+
67
+ Use `skills: review-*, tdd` to select matching skills or `skills: *` to select all discovered skills. `*` matches zero or more characters. Names and patterns are case-sensitive. An empty or omitted list leaves the profile prompt's skill selection empty. The shared prompt helper returns unmatched entries so each extension can report them. Pi renders the selected skill metadata in the system prompt.
68
+
69
+ ### Delegation
70
+
71
+ `allowedAgents` restricts which named profiles a delegation tool can launch. Omit it or leave it empty to add no name restriction. The applicable delegation tool must also be available in the session.
72
+
73
+ | Entry point | `allowedAgents` | `maxDepth` |
74
+ | --- | --- | --- |
75
+ | `pi-subagents` | Filters the named agents offered by the child `subagent` tool when the launcher can pass a non-empty list of matching names. | The child `subagent` tool is disabled when the child depth exceeds the profile limit. |
76
+ | `pi-herdr-agents` | Intersects the profile list with any inherited list. When restricted, `hc_run` requires an allowed agent name. | Inherits the stricter of the profile limit and the parent limit. Exceeding it disables `hc_run` in the child. |
77
+ | `pi --agent` | Configures the `subagent` tool when the `pi-subagents` extension is loaded. | The field is parsed. `custom-agent` does not set a depth limit for the current session. |
78
+
79
+ The first delegated child starts at depth `1`. A child at depth `1` with `maxDepth: 0` cannot delegate further through its launcher. With `maxDepth: 1`, that child is still at the limit and may delegate if its tools and agent scope permit it. Each launch increments the depth. `pi-subagents` sets the new child's limit from the new profile, while Herdr also carries forward the inherited limit.
80
+
81
+ ### Prompt composition
82
+
83
+ | `systemPrompt` | Base prompt | Project context | Profile body and tools |
84
+ | --- | --- | --- | --- |
85
+ | `append` | Keep Pi's base prompt | Keep | Append the Markdown body after any existing addendum. Pi renders its normal tool information. |
86
+ | `replace` | Use the profile's custom preamble | Keep | Render the Markdown body with the visible runtime tool list and guidelines. |
87
+ | `replace-all` | Use the profile's custom preamble | Omit | Render the same replacement prompt with the project context cleared. The child launchers also pass `--no-context-files`. |
88
+
89
+ All modes apply the profile's `skills` selection. In replacement modes, put `<pi-subagents-runtime-tools />` in the body to place the tool list and guidelines at that point. By default, they follow the body. In `append` mode, the marker is removed.
23
90
 
24
91
  ## Extension integration
25
92
 
@@ -37,15 +104,11 @@ if (profile) {
37
104
  }
38
105
  ```
39
106
 
40
- Use `loadAgentFromPath(path, cwd)` for an explicit Markdown path, or `parseAgentProfile(content, path, source)` when the caller already has the contents. `loadAgentDefinitions` also accepts `agentDir`, `globalDir`, and `projectDir` overrides. By default it honors `PI_CODING_AGENT_DIR` for the user agent directory.
41
-
42
- - `append` adds the profile body after Pi's existing append prompt.
43
- - `replace` uses the profile body as Pi's custom preamble, injects visible tool descriptions and guidelines, and retains project context.
44
- - `replace-all` also clears project context when assembling the prompt. A child launcher can pass Pi's `--no-context-files` option to skip loading those files entirely.
107
+ Use `loadAgentFromPath(path, cwd)` for an explicit Markdown path, or `parseAgentProfile(content, path, source)` when the caller already has the contents. `loadAgentDefinitions` also accepts `agentDir`, `globalDir`, and `projectDir` overrides.
45
108
 
46
- The optional `<pi-subagents-runtime-tools />` marker controls where the tool block appears in a replacement prompt. Pi renders the selected skills from the session's discovered skills. Patterns support `*`. A profile without `skills` supplies an empty skill list to the prompt. Callers can use `selectAgentSkills` to match a separate catalog or `formatRuntimeTools` to render the tool block independently.
109
+ Call `selectAgentModel(profile, requestedModel, getAvailableModels)` to select or validate a model before activation. Child launchers can pass `profile.tools` to Pi's `--tools`. Current-session extensions can call `selectAgentTools(entries, available, active)` to resolve the declared selection and get unmatched entries. `selectAgentSkills` and `formatRuntimeTools` expose the skill matching and tool formatting independently.
47
110
 
48
- The caller activates the model and tool selection, enforces delegation rules, and decides how to run and debug the session. Apply the profile after configuring tools so the descriptions reflect the active set.
111
+ The integrating extension sets the model, thinking level, and tools, and handles delegation and debug output. Apply the profile after configuring the tools so the rendered tool descriptions reflect the active selection.
49
112
 
50
113
  ## Development
51
114
 
@@ -6,7 +6,7 @@ export type SystemPromptMode = (typeof promptModes)[number];
6
6
  export interface AgentProfile {
7
7
  name: string;
8
8
  description?: string;
9
- model?: string;
9
+ models?: string[];
10
10
  thinking: ThinkingLevel;
11
11
  tools: string[];
12
12
  skills?: string[];
@@ -38,6 +38,15 @@ export interface AgentDefinitionFs {
38
38
  readFile(filePath: string): Promise<string>;
39
39
  }
40
40
  export declare function parseAgentProfile(content: string, filePath: string, source?: AgentSource): AgentProfile;
41
+ export declare function wildcardMatcher(pattern: string): RegExp;
42
+ export declare function selectAgentModel(profile: Pick<AgentProfile, 'name' | 'models'> | undefined, requestedModel?: string, getAvailableModels?: () => readonly {
43
+ provider: string;
44
+ id: string;
45
+ }[]): string | undefined;
46
+ export declare function selectAgentTools(entries: readonly string[], available: readonly string[], active: readonly string[]): {
47
+ selected: string[];
48
+ missing: string[];
49
+ };
41
50
  export declare function loadAgentFromPath(selector: string, cwd?: string): Promise<AgentProfile>;
42
51
  export declare function loadAgentDefinitions(options?: LoadAgentDefinitionsOptions): Promise<AgentDefinitions>;
43
52
  export {};
@@ -53,6 +53,8 @@ export function parseAgentProfile(content, filePath, source = 'path') {
53
53
  .trim()
54
54
  .replace(/^['"]|['"]$/g, ''));
55
55
  }
56
+ if (fields.has('model'))
57
+ throw new Error('The `model` field is no longer supported. Please use `models` instead.');
56
58
  const name = fields.get('name');
57
59
  if (!name)
58
60
  throw new Error('missing required field: name');
@@ -66,14 +68,17 @@ export function parseAgentProfile(content, filePath, source = 'path') {
66
68
  if (debug !== undefined && debug !== 'true' && debug !== 'false') {
67
69
  throw new Error(`invalid debug: ${debug}`);
68
70
  }
71
+ const models = csv(fields.get('models'));
72
+ const tools = csv(fields.get('tools'));
73
+ validateToolList(tools);
69
74
  const skills = csv(fields.get('skills'));
70
75
  const allowedAgents = csv(fields.get('allowedAgents'));
71
76
  return {
72
77
  name,
73
78
  description: fields.get('description') || undefined,
74
- model: fields.get('model') || undefined,
79
+ models: models.length ? models : undefined,
75
80
  thinking,
76
- tools: csv(fields.get('tools')),
81
+ tools,
77
82
  skills: skills.length ? skills : undefined,
78
83
  allowedAgents: allowedAgents.length ? allowedAgents : undefined,
79
84
  maxDepth,
@@ -87,6 +92,86 @@ export function parseAgentProfile(content, filePath, source = 'path') {
87
92
  filePath,
88
93
  };
89
94
  }
95
+ export function wildcardMatcher(pattern) {
96
+ const expression = pattern
97
+ .split('*')
98
+ .map((part) => part.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'))
99
+ .join('.*');
100
+ return new RegExp(`^${expression}$`);
101
+ }
102
+ export function selectAgentModel(profile, requestedModel, getAvailableModels) {
103
+ const requested = requestedModel?.trim() || undefined;
104
+ const allowed = profile?.models;
105
+ if (!profile || !allowed?.length)
106
+ return requested;
107
+ if (requested) {
108
+ const modelId = requested.slice(requested.indexOf('/') + 1);
109
+ if (!requested.includes('*') &&
110
+ allowed.some((pattern) => {
111
+ const matches = wildcardMatcher(pattern);
112
+ return matches.test(requested) || (!pattern.includes('/') && matches.test(modelId));
113
+ })) {
114
+ return requested;
115
+ }
116
+ throw new Error(`Model "${requested}" is not allowed for agent "${profile.name}". Allowed models: ${allowed.join(', ')}.`);
117
+ }
118
+ const first = allowed[0];
119
+ if (!first.includes('*'))
120
+ return first;
121
+ const matches = wildcardMatcher(first);
122
+ for (const { provider, id } of getAvailableModels?.() ?? []) {
123
+ const qualified = `${provider}/${id}`;
124
+ if (matches.test(qualified) || (!first.includes('/') && matches.test(id)))
125
+ return qualified;
126
+ }
127
+ throw new Error(`No available models match default pattern "${first}" for agent "${profile.name}".`);
128
+ }
129
+ function isToolModifier(entry) {
130
+ return entry.startsWith('+') || entry.startsWith('-');
131
+ }
132
+ function validateToolList(entries) {
133
+ const modifiers = entries.filter(isToolModifier);
134
+ if (modifiers.length && modifiers.length !== entries.length) {
135
+ throw new Error('invalid tools: tool names cannot be mixed with +name or -name entries');
136
+ }
137
+ const pattern = modifiers.find((entry) => entry.includes('*'));
138
+ if (pattern) {
139
+ throw new Error(`invalid tools: +name and -name entries take exact tool names, not patterns: ${pattern}`);
140
+ }
141
+ }
142
+ export function selectAgentTools(entries, available, active) {
143
+ validateToolList(entries);
144
+ if (!entries.length)
145
+ return { selected: [...active], missing: [] };
146
+ const missing = new Set();
147
+ if (isToolModifier(entries[0])) {
148
+ const availableNames = new Set(available);
149
+ const selected = new Set(active);
150
+ for (const entry of entries) {
151
+ const name = entry.slice(1);
152
+ if (!availableNames.has(name)) {
153
+ missing.add(entry);
154
+ }
155
+ else if (entry.startsWith('+')) {
156
+ selected.add(name);
157
+ }
158
+ else {
159
+ selected.delete(name);
160
+ }
161
+ }
162
+ return { selected: [...selected], missing: [...missing] };
163
+ }
164
+ const selected = new Set();
165
+ for (const entry of entries) {
166
+ const pattern = wildcardMatcher(entry);
167
+ const matches = available.filter((name) => pattern.test(name));
168
+ if (!matches.length)
169
+ missing.add(entry);
170
+ for (const name of matches)
171
+ selected.add(name);
172
+ }
173
+ return { selected: [...selected], missing: [...missing] };
174
+ }
90
175
  export async function loadAgentFromPath(selector, cwd = process.cwd()) {
91
176
  const input = selector.trim();
92
177
  const filePath = resolve(cwd, /^~[/\\]/.test(input) ? join(homedir(), input.slice(2)) : input);
@@ -1,5 +1,5 @@
1
1
  import type { NormalizedBuildSystemPromptOptions } from '@earendil-works/pi-coding-agent';
2
- import type { AgentProfile } from './agent-profile.js';
2
+ import { type AgentProfile } from './agent-profile.js';
3
3
  export interface SkillSelection<T> {
4
4
  selected: T[];
5
5
  missing: string[];
@@ -1,3 +1,4 @@
1
+ import { wildcardMatcher } from './agent-profile.js';
1
2
  const runtimeToolsMarker = '<pi-subagents-runtime-tools />';
2
3
  export function selectAgentSkills(patterns, available) {
3
4
  const byName = new Map();
@@ -21,13 +22,6 @@ export function selectAgentSkills(patterns, available) {
21
22
  }
22
23
  return { selected: [...selected.values()], missing: [...missing] };
23
24
  }
24
- function wildcardMatcher(pattern) {
25
- const expression = pattern
26
- .split('*')
27
- .map((part) => part.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'))
28
- .join('.*');
29
- return new RegExp(`^${expression}$`);
30
- }
31
25
  export function formatRuntimeTools(options) {
32
26
  const visible = options.selectedTools.filter((name) => !options.hiddenTools.includes(name));
33
27
  const toolLines = visible.map((name) => {
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { loadAgentDefinitions, loadAgentFromPath, parseAgentProfile, type AgentDefinitions, type AgentDefinitionWarning, type AgentProfile, type AgentSource, type LoadAgentDefinitionsOptions, type SystemPromptMode, type ThinkingLevel, } from './agent-profile.js';
1
+ export { loadAgentDefinitions, loadAgentFromPath, parseAgentProfile, selectAgentModel, selectAgentTools, type AgentDefinitions, type AgentDefinitionWarning, type AgentProfile, type AgentSource, type LoadAgentDefinitionsOptions, type SystemPromptMode, type ThinkingLevel, } from './agent-profile.js';
2
2
  export { applyAgentProfile, formatRuntimeTools, selectAgentSkills, type AgentPromptResult, type SkillSelection, } from './agent-prompt.js';
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export { loadAgentDefinitions, loadAgentFromPath, parseAgentProfile, } from './agent-profile.js';
1
+ export { loadAgentDefinitions, loadAgentFromPath, parseAgentProfile, selectAgentModel, selectAgentTools, } from './agent-profile.js';
2
2
  export { applyAgentProfile, formatRuntimeTools, selectAgentSkills, } from './agent-prompt.js';
package/package.json CHANGED
@@ -1,7 +1,13 @@
1
1
  {
2
2
  "name": "@johnnywu/pi-agent-profiles",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Shared Markdown agent profiles and system prompt composition for Pi",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/jwu/pi-agent-profiles.git"
8
+ },
9
+ "homepage": "https://github.com/jwu/pi-agent-profiles#readme",
10
+ "bugs": "https://github.com/jwu/pi-agent-profiles/issues",
5
11
  "type": "module",
6
12
  "license": "MIT",
7
13
  "engines": { "node": ">=22.19.0" },