@johnnywu/pi-agent-profiles 0.3.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 +10 -6
- package/dist/agent-profile.js +17 -0
- package/dist/delegation.d.ts +28 -0
- package/dist/delegation.js +41 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- 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,7 +38,7 @@ 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
|
|
|
@@ -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, `hc_subagent` requires an allowed agent name. |
|
|
77
|
-
| `pi --agent` | Emits `pi-subagents:configure`, which restricts `subagent` from `pi-subagents` and `hc_subagent` from `pi-herdr-agents` when they are loaded. |
|
|
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.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');
|
|
@@ -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
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
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';
|