pi-subagents-router 1.0.2

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Asdrubal
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,119 @@
1
+ # Pi Subagents Router Extension
2
+
3
+ A TypeScript extension for Pi that intelligently routes tasks to appropriate agent types based on task descriptions using `useWhen` and `avoidWhen` criteria.
4
+
5
+ ## Features
6
+
7
+ - **Automatic Agent Routing**: Analyzes task descriptions and automatically selects the best agent type
8
+ - **Custom Tools**: Provides tools for manual routing (`route_agent`) and agent information (`list_agents`)
9
+ - **Custom Commands**: Includes `/assign-agent` command for manual routing
10
+ - **Input Interception**: Automatically routes tasks based on natural language input
11
+ - **Configurable Agents**: Easy to extend with additional agent types and criteria
12
+ - **Second-best Fallback**: When the top agent is penalized, tries the next best alternative instead of giving up
13
+
14
+ ## Routing Algorithm
15
+
16
+ ```
17
+ 1. Scans ALL trigger keywords across ALL agents, picks the earliest position in input text
18
+ 2. Scoring: counts useWhen matches per agent (most matches = highest score)
19
+ 3. Check avoidWhen penalties (keyword found → penalize that agent)
20
+ 4. If top-scoring agent is penalized, find the next-highest unpenalized agent (fallback)
21
+ 5. If all agents penalized, fall back to general-purpose
22
+ ```
23
+
24
+ > **Key improvement** (v1.1): Trigger matching is now **text-order aware** — the earliest keyword in the input determines routing priority. For example, \"implement documentation\" routes to the software-engineer (\"implement\" at pos 0) instead of the documenter (\"documentation\" at pos 9).
25
+
26
+ ## Usage
27
+
28
+ ### Automatic Routing
29
+
30
+ The extension automatically analyzes your input and routes to the appropriate agent:
31
+
32
+ ```
33
+ User: "Create documentation for the new API endpoint"
34
+ → Automatically routed to: documenter
35
+
36
+ User: "Research the latest React hooks best practices"
37
+ → Automatically routed to: researcher
38
+
39
+ User: "Implement the user authentication feature"
40
+ → Automatically routed to: software-engineer
41
+ ```
42
+
43
+ ### Manual Routing
44
+
45
+ Use the `/assign-agent` command:
46
+
47
+ ```
48
+ /assign-agent Create comprehensive documentation for the database schema
49
+ ```
50
+
51
+ ### List Available Agents
52
+
53
+ ```
54
+ Use the list_agents tool to see all available agents and their criteria.
55
+ ```
56
+
57
+ ### Force Specific Agent
58
+
59
+ ```
60
+ Use the route_agent tool with forceAgent parameter to override automatic routing.
61
+ ```
62
+
63
+ ## Agent Configuration
64
+
65
+ The extension comes with predefined agents:
66
+
67
+ ### Documenter
68
+ - **Description**: Documentation specialist responsible for creating and maintaining project documentation
69
+ - **Use When**: documentation creation, knowledge documentation, technical writing
70
+ - **Avoid When**: implementation, testing, deployment operations
71
+ - **Triggers**: documentation, docs, write docs, documentation update, README
72
+
73
+ ### Researcher
74
+ - **Description**: Research specialist responsible for information gathering, analysis, and evidence-based insights
75
+ - **Use When**: information gathering, market research, technical research, competitive analysis
76
+ - **Avoid When**: implementation, debugging, testing
77
+ - **Triggers**: research, investigate, find information, look up
78
+
79
+ ### Software Engineer
80
+ - **Description**: Senior software engineering implementation specialist
81
+ - **Use When**: software development, coding, implementation, feature development
82
+ - **Avoid When**: documentation, research, testing
83
+ - **Triggers**: code, implement, build, develop, program
84
+
85
+ ### Reviewer
86
+ - **Description**: Code quality reviewer responsible for validating implementation quality
87
+ - **Use When**: code review, quality assurance, architecture review, security review
88
+ - **Avoid When**: implementation, documentation, research
89
+ - **Triggers**: review, audit, check, validate
90
+
91
+ ## Customization
92
+
93
+ To add or modify agent configurations:
94
+
95
+ 1. Edit the `agents` array in `src/agent-router.ts`
96
+ 2. Add new agent configurations with appropriate `useWhen`, `avoidWhen`, and `triggers`
97
+ 3. Reload the extension with `/reload`
98
+
99
+ ## Development
100
+
101
+ ```bash
102
+ # Install dependencies
103
+ npm install
104
+
105
+ # Run tests
106
+ npx tsx test/test-routing.ts
107
+ ```
108
+
109
+ ## License
110
+
111
+ MIT License
112
+
113
+ ## Contributing
114
+
115
+ Pull requests are welcome! Please open an issue first to discuss major changes.
116
+
117
+ ## Support
118
+
119
+ For issues and questions, please open a GitHub issue.
@@ -0,0 +1,52 @@
1
+ /**
2
+ * AgentConfig — Shared type for all agents (builtin + filesystem).
3
+ *
4
+ * This file extracts the AgentConfig interface from the monolithic
5
+ * agent-router.ts so it can be imported by all modules.
6
+ */
7
+ export type AgentSource = "builtin" | "filesystem";
8
+ export interface AgentConfig {
9
+ name: string;
10
+ description: string;
11
+ thinking?: string;
12
+ tools?: string[];
13
+ systemPromptMode?: string;
14
+ inheritProjectContext?: boolean;
15
+ inheritSkills?: boolean;
16
+ triggers?: string[];
17
+ useWhen?: string[];
18
+ avoidWhen?: string[];
19
+ capabilities?: string[];
20
+ consumes?: string[];
21
+ produces?: string[];
22
+ dependsOn?: string[];
23
+ source?: AgentSource;
24
+ }
25
+ /**
26
+ * Simple routing decision
27
+ */
28
+ export interface RoutingDecision {
29
+ agentType: string;
30
+ reason: string;
31
+ }
32
+ /**
33
+ * Route result — single agent
34
+ */
35
+ export interface RouteResult {
36
+ success: boolean;
37
+ error?: string;
38
+ agentId?: string;
39
+ agentType?: string;
40
+ reason?: string;
41
+ details?: Record<string, any>;
42
+ }
43
+ /**
44
+ * Plan result — multi-agent workflow
45
+ */
46
+ export interface PlanResult {
47
+ success: boolean;
48
+ error?: string;
49
+ agents?: string[];
50
+ steps?: string[];
51
+ results?: Record<string, any>;
52
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * AgentConfig — Shared type for all agents (builtin + filesystem).
3
+ *
4
+ * This file extracts the AgentConfig interface from the monolithic
5
+ * agent-router.ts so it can be imported by all modules.
6
+ */
7
+ export {};
@@ -0,0 +1,10 @@
1
+ /**
2
+ * BuiltinAgents — The 4 hardcoded agents extracted from agent-router.ts
3
+ */
4
+ import type { AgentConfig } from "./AgentConfig.ts";
5
+ export declare const BUILTIN_AGENTS: AgentConfig[];
6
+ /**
7
+ * Simple keyword → capability mapping for built-in routing.
8
+ * Used when capabilities are not explicitly declared on agents.
9
+ */
10
+ export declare const KEYWORD_TO_CAPABILITY: Record<string, string[]>;
@@ -0,0 +1,156 @@
1
+ /**
2
+ * BuiltinAgents — The 4 hardcoded agents extracted from agent-router.ts
3
+ */
4
+ export const BUILTIN_AGENTS = [
5
+ {
6
+ name: "documenter",
7
+ description: "Documentation specialist responsible for creating and maintaining project documentation",
8
+ thinking: "high",
9
+ tools: [
10
+ "read",
11
+ "grep",
12
+ "find",
13
+ "ls",
14
+ "bash",
15
+ "edit",
16
+ "write",
17
+ "contact_supvisor",
18
+ ],
19
+ systemPromptMode: "replace",
20
+ inheritProjectContext: true,
21
+ inheritSkills: false,
22
+ triggers: [
23
+ "documentation",
24
+ "docs",
25
+ "write docs",
26
+ "documentation update",
27
+ "README",
28
+ ],
29
+ useWhen: [
30
+ "documentation creation",
31
+ "knowledge documentation",
32
+ "technical writing",
33
+ ],
34
+ avoidWhen: [
35
+ "implementation",
36
+ "testing",
37
+ "deployment operations",
38
+ ],
39
+ capabilities: ["documentation", "knowledge", "writing"],
40
+ produces: ["docs", "readme", "technical-writing"],
41
+ source: "builtin",
42
+ },
43
+ {
44
+ name: "researcher",
45
+ description: "Research specialist responsible for information gathering, analysis, and evidence-based insights",
46
+ thinking: "high",
47
+ tools: [
48
+ "read",
49
+ "grep",
50
+ "find",
51
+ "ls",
52
+ "bash",
53
+ "web_search",
54
+ "fetch_content",
55
+ ],
56
+ systemPromptMode: "replace",
57
+ inheritProjectContext: true,
58
+ inheritSkills: true,
59
+ triggers: [
60
+ "research",
61
+ "investigate",
62
+ "find information",
63
+ "look up",
64
+ ],
65
+ useWhen: [
66
+ "information gathering",
67
+ "market research",
68
+ "technical research",
69
+ "competitive analysis",
70
+ ],
71
+ avoidWhen: ["implementation", "debugging", "testing"],
72
+ capabilities: ["research", "analysis", "information-gathering"],
73
+ produces: ["research-report", "findings", "evidence"],
74
+ source: "builtin",
75
+ },
76
+ {
77
+ name: "software-engineer",
78
+ description: "Senior software engineering implementation specialist",
79
+ thinking: "medium",
80
+ tools: [
81
+ "read",
82
+ "grep",
83
+ "find",
84
+ "ls",
85
+ "bash",
86
+ "edit",
87
+ "write",
88
+ "contact_supvisor",
89
+ ],
90
+ systemPromptMode: "replace",
91
+ inheritProjectContext: true,
92
+ inheritSkills: true,
93
+ triggers: ["code", "implement", "build", "develop", "program"],
94
+ useWhen: [
95
+ "software development",
96
+ "coding",
97
+ "implementation",
98
+ "feature development",
99
+ ],
100
+ avoidWhen: [
101
+ "documentation",
102
+ "research",
103
+ "testing",
104
+ ],
105
+ capabilities: ["implementation", "coding", "software-development"],
106
+ produces: ["code", "source-files", "implementation"],
107
+ source: "builtin",
108
+ },
109
+ {
110
+ name: "reviewer",
111
+ description: "Code quality reviewer responsible for validating implementation quality",
112
+ thinking: "medium",
113
+ tools: ["read", "grep", "find", "ls", "bash"],
114
+ systemPromptMode: "replace",
115
+ inheritProjectContext: true,
116
+ inheritSkills: true,
117
+ triggers: ["review", "audit", "check", "validate"],
118
+ useWhen: [
119
+ "code review",
120
+ "quality assurance",
121
+ "architecture review",
122
+ "security review",
123
+ ],
124
+ avoidWhen: ["implementation", "documentation", "research"],
125
+ capabilities: ["review", "quality-assurance", "auditing"],
126
+ produces: ["review-report", "quality-feedback", "audit"],
127
+ source: "builtin",
128
+ },
129
+ ];
130
+ /**
131
+ * Simple keyword → capability mapping for built-in routing.
132
+ * Used when capabilities are not explicitly declared on agents.
133
+ */
134
+ export const KEYWORD_TO_CAPABILITY = {
135
+ // Documentation
136
+ documentation: ["documentation", "knowledge", "writing"],
137
+ docs: ["documentation", "knowledge", "writing"],
138
+ "write docs": ["documentation", "knowledge", "writing"],
139
+ readme: ["documentation", "knowledge", "writing"],
140
+ // Research
141
+ research: ["research", "analysis", "information-gathering"],
142
+ investigate: ["research", "analysis", "information-gathering"],
143
+ "find information": ["research", "analysis", "information-gathering"],
144
+ "look up": ["research", "analysis", "information-gathering"],
145
+ // Engineering
146
+ implement: ["implementation", "coding", "software-development"],
147
+ build: ["implementation", "coding", "software-development"],
148
+ develop: ["implementation", "coding", "software-development"],
149
+ program: ["implementation", "coding", "software-development"],
150
+ code: ["implementation", "coding", "software-development"],
151
+ // Review
152
+ review: ["review", "quality-assurance", "auditing"],
153
+ audit: ["review", "quality-assurance", "auditing"],
154
+ check: ["review", "quality-assurance", "auditing"],
155
+ validate: ["review", "quality-assurance", "auditing"],
156
+ };
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Supvisor — The agent routing supervisor.
3
+ *
4
+ * Extracts the agent management logic from agent-router.ts and provides
5
+ * two entry points:
6
+ * - routeAgent() — single-agent routing (same behavior as old)
7
+ * - planAndRoute() — multi-agent workflow (NEW)
8
+ */
9
+ import type { AgentConfig, RoutingDecision, RouteResult } from "./AgentConfig.ts";
10
+ export declare function analyzeTaskDescription(taskDescription: string, agents: AgentConfig[]): RoutingDecision;
11
+ export declare class Supervisor {
12
+ private agents;
13
+ private pi;
14
+ constructor(agents: AgentConfig[], pi: any);
15
+ routeAgent(taskDescription: string, forceAgent?: string, runInBackground?: boolean, thinking?: string, model?: string): Promise<RouteResult>;
16
+ /**
17
+ * Plan and route a workflow for multiple agents.
18
+ * Uses keyword matching to find relevant agents, then executes
19
+ * them in parallel (where dependencies allow).
20
+ */
21
+ planAndRoute(goal: string, options?: {
22
+ forceAgents?: string[];
23
+ background?: boolean;
24
+ }): Promise<{
25
+ success: boolean;
26
+ agents?: string[];
27
+ steps?: string[];
28
+ results?: Record<string, any>;
29
+ error?: string;
30
+ }>;
31
+ private _findRelevantAgents;
32
+ static getAllAgents(): Promise<AgentConfig[]>;
33
+ }