@johnnywu/pi-agent-profiles 0.2.0 → 0.4.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 +13 -9
- package/dist/agent-profile.d.ts +13 -0
- package/dist/agent-profile.js +49 -0
- package/dist/delegation.d.ts +28 -0
- package/dist/delegation.js +41 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ Review the changes. Report actionable findings with file and line references.
|
|
|
25
25
|
<pi-subagents-runtime-tools />
|
|
26
26
|
```
|
|
27
27
|
|
|
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.
|
|
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. A field name outside the reference below is an error, and the loader skips the definition with a warning, so a misspelled `maxDepth` or `allowedAgents` cannot silently lift a limit. The Markdown after the closing `---` is the agent prompt.
|
|
29
29
|
|
|
30
30
|
## Field reference
|
|
31
31
|
|
|
@@ -38,14 +38,14 @@ Start the file with a `---` block containing one `key: value` entry per line. Th
|
|
|
38
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
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
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
|
|
41
|
+
| `maxDepth` | `10` | Non-negative safe integer for the levels of delegated sessions allowed below the agent. See [Delegation](#delegation). |
|
|
42
42
|
| `systemPrompt` | `append` | One of `append`, `replace`, or `replace-all`. See [Prompt composition](#prompt-composition). |
|
|
43
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
44
|
|
|
45
45
|
### Model selection
|
|
46
46
|
|
|
47
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 `
|
|
48
|
+
- `subagent` and `hc_subagent` 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
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
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
51
|
|
|
@@ -58,9 +58,9 @@ Start the file with a `---` block containing one `key: value` entry per line. Th
|
|
|
58
58
|
| `tools:` or omitted | Keep the entry point's existing tool selection. |
|
|
59
59
|
| `tools: read, -write` or `tools: +hc_*` | Reject the profile. Use names and patterns together, or modifiers exclusively. Modifiers require exact tool names. |
|
|
60
60
|
|
|
61
|
-
`pi-subagents` passes the list to the child Pi's `--tools`. `pi-herdr-agents`
|
|
61
|
+
`pi-subagents` passes the list to the child Pi's `--tools`. `pi-herdr-agents` passes the result of `herdrAgentTools()`: each exact `subagent` entry becomes the Herdr delegation tools `hc_subagent`, `hc_renew`, `hc_read`, `hc_stop`, and `hc_rm`, keeping any `+` or `-` prefix. A non-empty list also gets `hc_send` and `hc_agents` for reporting, as `+` entries in modifier mode. Pi applies its own tool availability and MCP exposure rules.
|
|
62
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.
|
|
63
|
+
`pi --agent` resolves names and patterns against registered tools. When `hc_subagent` is registered, it first applies `herdrAgentTools()` and keeps `subagent`, so a Herdr lead gets both delegation 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
64
|
|
|
65
65
|
### Skills
|
|
66
66
|
|
|
@@ -72,11 +72,13 @@ Use `skills: review-*, tdd` to select matching skills or `skills: *` to select a
|
|
|
72
72
|
|
|
73
73
|
| Entry point | `allowedAgents` | `maxDepth` |
|
|
74
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. |
|
|
76
|
-
| `pi-herdr-agents` | Intersects the profile list with any inherited list. When restricted, `
|
|
77
|
-
| `pi --agent` |
|
|
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. | Applies the depth rule below. A child past its limit gets no `subagent` tool. |
|
|
76
|
+
| `pi-herdr-agents` | Intersects the profile list with any inherited list. When restricted, `hc_subagent` requires an allowed agent name. | Applies the depth rule below. A child past its limit gets none of the five delegation tools. |
|
|
77
|
+
| `pi --agent` | Emits `pi-subagents:configure`, which restricts `subagent` from `pi-subagents` and `hc_subagent` from `pi-herdr-agents` when they are loaded. | Emits the profile's `maxDepth` on the same event, so both extensions count it from the current session. With `maxDepth: 0`, `custom-agent` also removes the delegation tools from the session. |
|
|
78
78
|
|
|
79
|
-
|
|
79
|
+
`maxDepth` is the number of levels of delegated sessions allowed below the agent, counted from the agent's own level wherever it runs. With `maxDepth: 0` the agent cannot delegate. With `maxDepth: 1` it can launch children, and those children cannot delegate further.
|
|
80
|
+
|
|
81
|
+
The limit passes down the chain, and a descendant can tighten it but not widen it. If `a`, `b`, and `c` each declare `maxDepth: 3`, and `a` launches `b`, `b` launches `c`, and `c` launches `d`, then `d` cannot delegate: it is already three levels below `a`. `pi-subagents` and `pi-herdr-agents` apply the same rule, each to its own chain of children.
|
|
80
82
|
|
|
81
83
|
### Prompt composition
|
|
82
84
|
|
|
@@ -108,6 +110,8 @@ Use `loadAgentFromPath(path, cwd)` for an explicit Markdown path, or `parseAgent
|
|
|
108
110
|
|
|
109
111
|
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.
|
|
110
112
|
|
|
113
|
+
Delegation extensions share one scope contract. A session that runs as an agent emits `delegationScopeEvent` on `pi.events` with a `DelegationScope` payload (`{ allowedAgents?, maxDepth? }`), and listeners read it with `parseDelegationScope(payload)`. `delegationDepthLimit(depth, maxDepth, inherited)` returns the deepest level that may still delegate, and an agent delegates while its depth is at most that limit. `narrowAllowedAgents(names, inherited)` limits a profile's agents to the inherited list.
|
|
114
|
+
|
|
111
115
|
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.
|
|
112
116
|
|
|
113
117
|
## Development
|
package/dist/agent-profile.d.ts
CHANGED
|
@@ -47,6 +47,19 @@ export declare function selectAgentTools(entries: readonly string[], available:
|
|
|
47
47
|
selected: string[];
|
|
48
48
|
missing: string[];
|
|
49
49
|
};
|
|
50
|
+
/** Tools a Herdr agent uses to delegate to and manage its children. */
|
|
51
|
+
export declare const herdrDelegationTools: readonly ["hc_subagent", "hc_renew", "hc_read", "hc_stop", "hc_rm"];
|
|
52
|
+
/** Tools every Herdr agent keeps for reporting and coordination. */
|
|
53
|
+
export declare const herdrReportingTools: readonly ["hc_send", "hc_agents"];
|
|
54
|
+
/**
|
|
55
|
+
* Translate a profile's tool list for a session that runs in Herdr Core. Each exact `subagent`
|
|
56
|
+
* entry selects the Herdr delegation tools with the same `+` or `-` prefix, and keeps the
|
|
57
|
+
* `subagent` entry itself when `keepSubagent` is set. A non-empty list also selects the reporting
|
|
58
|
+
* tools, as `+` entries in modifier mode. An empty list stays empty.
|
|
59
|
+
*/
|
|
60
|
+
export declare function herdrAgentTools(entries: readonly string[], options?: {
|
|
61
|
+
keepSubagent?: boolean;
|
|
62
|
+
}): string[];
|
|
50
63
|
export declare function loadAgentFromPath(selector: string, cwd?: string): Promise<AgentProfile>;
|
|
51
64
|
export declare function loadAgentDefinitions(options?: LoadAgentDefinitionsOptions): Promise<AgentDefinitions>;
|
|
52
65
|
export {};
|
package/dist/agent-profile.js
CHANGED
|
@@ -3,6 +3,18 @@ import { homedir } from 'node:os';
|
|
|
3
3
|
import { join, resolve } from 'node:path';
|
|
4
4
|
const thinkingLevels = ['off', 'minimal', 'low', 'medium', 'high', 'xhigh'];
|
|
5
5
|
const promptModes = ['append', 'replace', 'replace-all'];
|
|
6
|
+
const fieldNames = [
|
|
7
|
+
'name',
|
|
8
|
+
'description',
|
|
9
|
+
'models',
|
|
10
|
+
'thinking',
|
|
11
|
+
'tools',
|
|
12
|
+
'skills',
|
|
13
|
+
'allowedAgents',
|
|
14
|
+
'maxDepth',
|
|
15
|
+
'systemPrompt',
|
|
16
|
+
'debug',
|
|
17
|
+
];
|
|
6
18
|
const defaultFs = {
|
|
7
19
|
async listFiles(dir) {
|
|
8
20
|
const entries = await readdir(dir, { withFileTypes: true });
|
|
@@ -55,6 +67,11 @@ export function parseAgentProfile(content, filePath, source = 'path') {
|
|
|
55
67
|
}
|
|
56
68
|
if (fields.has('model'))
|
|
57
69
|
throw new Error('The `model` field is no longer supported. Please use `models` instead.');
|
|
70
|
+
// A misspelled field would otherwise be ignored, which silently lifts a limit such as maxDepth.
|
|
71
|
+
const unknown = [...fields.keys()].filter((key) => !fieldNames.includes(key));
|
|
72
|
+
if (unknown.length) {
|
|
73
|
+
throw new Error(`unknown field${unknown.length > 1 ? 's' : ''}: ${unknown.join(', ')}. Supported fields: ${fieldNames.join(', ')}.`);
|
|
74
|
+
}
|
|
58
75
|
const name = fields.get('name');
|
|
59
76
|
if (!name)
|
|
60
77
|
throw new Error('missing required field: name');
|
|
@@ -172,6 +189,38 @@ export function selectAgentTools(entries, available, active) {
|
|
|
172
189
|
}
|
|
173
190
|
return { selected: [...selected], missing: [...missing] };
|
|
174
191
|
}
|
|
192
|
+
/** Tools a Herdr agent uses to delegate to and manage its children. */
|
|
193
|
+
export const herdrDelegationTools = [
|
|
194
|
+
'hc_subagent',
|
|
195
|
+
'hc_renew',
|
|
196
|
+
'hc_read',
|
|
197
|
+
'hc_stop',
|
|
198
|
+
'hc_rm',
|
|
199
|
+
];
|
|
200
|
+
/** Tools every Herdr agent keeps for reporting and coordination. */
|
|
201
|
+
export const herdrReportingTools = ['hc_send', 'hc_agents'];
|
|
202
|
+
/**
|
|
203
|
+
* Translate a profile's tool list for a session that runs in Herdr Core. Each exact `subagent`
|
|
204
|
+
* entry selects the Herdr delegation tools with the same `+` or `-` prefix, and keeps the
|
|
205
|
+
* `subagent` entry itself when `keepSubagent` is set. A non-empty list also selects the reporting
|
|
206
|
+
* tools, as `+` entries in modifier mode. An empty list stays empty.
|
|
207
|
+
*/
|
|
208
|
+
export function herdrAgentTools(entries, options = {}) {
|
|
209
|
+
validateToolList(entries);
|
|
210
|
+
if (!entries.length)
|
|
211
|
+
return [];
|
|
212
|
+
const tools = entries.flatMap((entry) => {
|
|
213
|
+
const prefix = /^([+-]?)subagent$/.exec(entry)?.[1];
|
|
214
|
+
if (prefix === undefined)
|
|
215
|
+
return [entry];
|
|
216
|
+
const delegation = herdrDelegationTools.map((tool) => `${prefix}${tool}`);
|
|
217
|
+
return options.keepSubagent ? [entry, ...delegation] : delegation;
|
|
218
|
+
});
|
|
219
|
+
const modifiers = isToolModifier(entries[0]);
|
|
220
|
+
for (const tool of herdrReportingTools)
|
|
221
|
+
tools.push(modifiers ? `+${tool}` : tool);
|
|
222
|
+
return tools;
|
|
223
|
+
}
|
|
175
224
|
export async function loadAgentFromPath(selector, cwd = process.cwd()) {
|
|
176
225
|
const input = selector.trim();
|
|
177
226
|
const filePath = resolve(cwd, /^~[/\\]/.test(input) ? join(homedir(), input.slice(2)) : input);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event a session that runs as an agent emits on `pi.events` to announce its own delegation
|
|
3
|
+
* scope. `pi --agent` emits it, and the delegation extensions listen for it.
|
|
4
|
+
*/
|
|
5
|
+
export declare const delegationScopeEvent = "pi-subagents:configure";
|
|
6
|
+
/** Payload of {@link delegationScopeEvent}. An omitted field adds no limit. */
|
|
7
|
+
export interface DelegationScope {
|
|
8
|
+
/** Profiles the session may delegate to. An empty list allows none. */
|
|
9
|
+
allowedAgents?: string[];
|
|
10
|
+
/** The `maxDepth` of the session's profile, counted from the session's own level. */
|
|
11
|
+
maxDepth?: number;
|
|
12
|
+
}
|
|
13
|
+
/** Read an event payload from another extension. A field with an unexpected type is dropped. */
|
|
14
|
+
export declare function parseDelegationScope(value: unknown): DelegationScope;
|
|
15
|
+
/**
|
|
16
|
+
* The deepest level that may still delegate, for an agent at `depth` whose profile declares
|
|
17
|
+
* `maxDepth`. The lead session is at depth 0 and its first child at depth 1. An agent delegates
|
|
18
|
+
* while its depth is at most this limit.
|
|
19
|
+
*
|
|
20
|
+
* A profile's `maxDepth` counts the levels below the agent itself, wherever it runs. A descendant
|
|
21
|
+
* can tighten the limit it inherits, not widen it.
|
|
22
|
+
*/
|
|
23
|
+
export declare function delegationDepthLimit(depth: number, maxDepth: number | undefined, inherited?: number): number | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* The agents a session may delegate to: `names` limited to the `inherited` list, in the order of
|
|
26
|
+
* `names`. An omitted list adds no restriction, so the other list is returned as it is.
|
|
27
|
+
*/
|
|
28
|
+
export declare function narrowAllowedAgents(names: readonly string[] | undefined, inherited: readonly string[] | undefined): string[] | undefined;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event a session that runs as an agent emits on `pi.events` to announce its own delegation
|
|
3
|
+
* scope. `pi --agent` emits it, and the delegation extensions listen for it.
|
|
4
|
+
*/
|
|
5
|
+
export const delegationScopeEvent = 'pi-subagents:configure';
|
|
6
|
+
/** Read an event payload from another extension. A field with an unexpected type is dropped. */
|
|
7
|
+
export function parseDelegationScope(value) {
|
|
8
|
+
const { allowedAgents, maxDepth } = (value && typeof value === 'object' ? value : {});
|
|
9
|
+
return {
|
|
10
|
+
allowedAgents: Array.isArray(allowedAgents)
|
|
11
|
+
? allowedAgents.filter((name) => typeof name === 'string')
|
|
12
|
+
: undefined,
|
|
13
|
+
maxDepth: typeof maxDepth === 'number' && Number.isSafeInteger(maxDepth) && maxDepth >= 0
|
|
14
|
+
? maxDepth
|
|
15
|
+
: undefined,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The deepest level that may still delegate, for an agent at `depth` whose profile declares
|
|
20
|
+
* `maxDepth`. The lead session is at depth 0 and its first child at depth 1. An agent delegates
|
|
21
|
+
* while its depth is at most this limit.
|
|
22
|
+
*
|
|
23
|
+
* A profile's `maxDepth` counts the levels below the agent itself, wherever it runs. A descendant
|
|
24
|
+
* can tighten the limit it inherits, not widen it.
|
|
25
|
+
*/
|
|
26
|
+
export function delegationDepthLimit(depth, maxDepth, inherited) {
|
|
27
|
+
if (maxDepth === undefined)
|
|
28
|
+
return inherited;
|
|
29
|
+
const own = depth + maxDepth - 1;
|
|
30
|
+
return inherited === undefined ? own : Math.min(own, inherited);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The agents a session may delegate to: `names` limited to the `inherited` list, in the order of
|
|
34
|
+
* `names`. An omitted list adds no restriction, so the other list is returned as it is.
|
|
35
|
+
*/
|
|
36
|
+
export function narrowAllowedAgents(names, inherited) {
|
|
37
|
+
if (!names)
|
|
38
|
+
return inherited ? [...new Set(inherited)] : undefined;
|
|
39
|
+
const allowed = inherited ? new Set(inherited) : undefined;
|
|
40
|
+
return [...new Set(names)].filter((name) => !allowed || allowed.has(name));
|
|
41
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
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';
|
|
1
|
+
export { herdrAgentTools, herdrDelegationTools, herdrReportingTools, loadAgentDefinitions, loadAgentFromPath, parseAgentProfile, selectAgentModel, selectAgentTools, type AgentDefinitions, type AgentDefinitionWarning, type AgentProfile, type AgentSource, type LoadAgentDefinitionsOptions, type SystemPromptMode, type ThinkingLevel, } from './agent-profile.js';
|
|
2
|
+
export { delegationDepthLimit, delegationScopeEvent, narrowAllowedAgents, parseDelegationScope, type DelegationScope, } from './delegation.js';
|
|
2
3
|
export { applyAgentProfile, formatRuntimeTools, selectAgentSkills, type AgentPromptResult, type SkillSelection, } from './agent-prompt.js';
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export { loadAgentDefinitions, loadAgentFromPath, parseAgentProfile, selectAgentModel, selectAgentTools, } from './agent-profile.js';
|
|
1
|
+
export { herdrAgentTools, herdrDelegationTools, herdrReportingTools, loadAgentDefinitions, loadAgentFromPath, parseAgentProfile, selectAgentModel, selectAgentTools, } from './agent-profile.js';
|
|
2
|
+
export { delegationDepthLimit, delegationScopeEvent, narrowAllowedAgents, parseDelegationScope, } from './delegation.js';
|
|
2
3
|
export { applyAgentProfile, formatRuntimeTools, selectAgentSkills, } from './agent-prompt.js';
|