@haoyiyin/workflow 0.3.0 → 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.
@@ -1,8 +1,9 @@
1
1
  /**
2
- * PI Extension - yi-workflow dispatcher
2
+ * PI Extension - yi-workflow router interceptor
3
3
  *
4
- * Intercepts regular chat and dispatches to appropriate skills.
5
- * Ensures THIN DISPATCHER pattern: main agent NEVER does work.
4
+ * ALL user input /skill:router
5
+ * Router skill handles ALL routing logic (5-layer GSD).
6
+ * Extension does NOT classify intent — that's the router's job.
6
7
  */
7
8
  export default function (pi: any): void;
8
9
  //# sourceMappingURL=pi-extension.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"pi-extension.d.ts","sourceRoot":"","sources":["../../src/pi-extension.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,MAAM,CAAC,OAAO,WAAW,EAAE,EAAE,GAAG,QAqG/B"}
1
+ {"version":3,"file":"pi-extension.d.ts","sourceRoot":"","sources":["../../src/pi-extension.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,CAAC,OAAO,WAAW,EAAE,EAAE,GAAG,QAkE/B"}
@@ -1,93 +1,62 @@
1
1
  /**
2
- * PI Extension - yi-workflow dispatcher
2
+ * PI Extension - yi-workflow router interceptor
3
3
  *
4
- * Intercepts regular chat and dispatches to appropriate skills.
5
- * Ensures THIN DISPATCHER pattern: main agent NEVER does work.
4
+ * ALL user input /skill:router
5
+ * Router skill handles ALL routing logic (5-layer GSD).
6
+ * Extension does NOT classify intent — that's the router's job.
6
7
  */
7
- import { classifyIntent } from "./extension/classifier.js";
8
- // Extension API is provided by PI at runtime
9
- // We use 'any' to avoid compile-time dependency
10
8
  export default function (pi) {
11
- // Store transformed input for before_agent_start to detect
12
9
  let transformedInput = null;
13
- // Intercept user input before processing
10
+ // Intercept ALL user input route to router skill
14
11
  pi.on("input", async (event, ctx) => {
15
- // Skip if user already used a slash command
12
+ // Skip slash commands (user explicitly calling a skill)
16
13
  if (event.text.startsWith("/")) {
17
14
  return { action: "continue" };
18
15
  }
19
- // Classify intent
20
- const intent = classifyIntent(event.text);
21
- const targetSkill = intent.skill || "quick-task";
22
- // Determine reason for dispatch
23
- let reason = intent.reason;
24
- if (!intent.skill) {
25
- const needsExternal = /^(what|how|why|when|where|who|search|find|look|weather|time|price|stock|translate)/i.test(event.text);
26
- if (needsExternal) {
27
- reason = "External query - needs subagent";
28
- }
29
- else {
30
- reason = "Default dispatch - no direct execution allowed";
31
- }
32
- }
33
- ctx.ui.notify(`[yi-workflow] Dispatching to /skill:${targetSkill} (${reason})`, "info");
34
- // Transform to explicit skill command with instruction not to analyze
35
- const transformedText = `=== SKILL COMMAND ===\n/skill:${targetSkill}\n\nINPUT:\n${event.text}\n\n=== DO NOT ANALYZE ===\nYou MUST call the skill above immediately. NO thinking. NO planning. NO analysis. Just call the skill.`;
36
- // Store for before_agent_start hook
37
- transformedInput = transformedText;
38
- // Transform input - this will be passed to main agent
16
+ // Store for before_agent_start
17
+ transformedInput = event.text;
18
+ // Transform ALL input to router skill call
19
+ // The router skill does 5-layer routing internally
20
+ const transformedText = [
21
+ "=== ROUTER DISPATCH ===",
22
+ "/skill:router",
23
+ "",
24
+ "USER REQUEST:",
25
+ event.text,
26
+ "",
27
+ "=== INSTRUCTIONS ===",
28
+ "Call the router skill above IMMEDIATELY.",
29
+ "Do NOT analyze, plan, or execute the request yourself.",
30
+ "Do NOT use any tools (Read, Edit, Bash, etc.).",
31
+ "The router skill will determine the correct target skill.",
32
+ ].join("\n");
33
+ ctx.ui.notify("[yi-workflow] router", "info");
39
34
  return {
40
35
  action: "transform",
41
36
  text: transformedText,
42
37
  };
43
38
  });
44
- // Log when session starts
45
39
  pi.on("session_start", async (event, ctx) => {
46
- ctx.ui.notify("yi-workflow extension loaded", "info");
40
+ ctx.ui.notify("yi-workflow router active", "info");
47
41
  });
48
- // CRITICAL: Inject THIN DISPATCHER rules into system prompt
49
- // This ensures main agent NEVER executes work directly
42
+ // Minimal system prompt injection just reinforce router dispatch
50
43
  pi.on("before_agent_start", async (event, ctx) => {
51
44
  const systemPrompt = event.systemPrompt || "";
52
- // Get the user input (either from event or from transformed global)
53
45
  const userInput = transformedInput || event.userInput || "";
54
- // Detect if this input was transformed to a skill command
55
- const isSkillCommand = userInput.startsWith("/skill:");
56
- // Prepend THIN DISPATCHER constraints
57
- const thinDispatcherRules = `
58
- ╔══════════════════════════════════════════════════════════════════╗
59
- ║ THIN DISPATCHER PROTOCOL [ABSOLUTE] ║
60
- ╚══════════════════════════════════════════════════════════════════╝
61
-
62
- YOU ARE A THIN DISPATCHER. YOUR ONLY JOB IS TO DISPATCH TO SKILLS.
63
-
64
- ⚠️ ABSOLUTE RULE #1: If user input starts with "/skill:", you MUST call that skill.
65
- ⚠️ ABSOLUTE RULE #2: You NEVER execute work yourself - only dispatch.
66
- ⚠️ ABSOLUTE RULE #3: Tools (Read, Edit, Bash, etc.) are FORBIDDEN unless in subagent.
46
+ const isRouterCommand = userInput.includes("/skill:router");
47
+ const rules = `
48
+ ## ROUTER DISPATCH RULE (MANDATORY)
67
49
 
68
- FORBIDDEN ACTIONS (VIOLATION = PROTOCOL BREACH):
69
- - Reading files (use /skill:review-diff)
70
- - Writing/editing files (use /skill:execute-plan)
71
- - Running commands (use /skill:quick-task)
72
- - Writing code directly (use /skill:tdd or /skill:execute-plan)
73
- - Using any tool directly (use /skill:quick-task to dispatch subagent)
50
+ You MUST follow this rule for ALL user messages:
74
51
 
75
- CURRENT INPUT: "${userInput}"
76
- IS_SKILL_COMMAND: ${isSkillCommand ? "YES - MUST CALL SKILL" : "NO"}
52
+ 1. If input contains "/skill:router" → CALL THE ROUTER SKILL IMMEDIATELY
53
+ 2. You MUST NOT use any tools directly (Read, Edit, Bash, Grep, etc.)
54
+ 3. You MUST NOT analyze, plan, or execute user requests yourself
55
+ 4. Your ONLY action is: call /skill:router and return its output
77
56
 
78
- ${isSkillCommand ? `
79
- ╔══════════════════════════════════════════════════════════════════╗
80
- ║ ⚠️ MANDATORY: CALL THE SKILL BELOW ⚠️ ║
81
- ╚══════════════════════════════════════════════════════════════════╝
82
- The input starts with "/skill:". You MUST call that skill.
83
- DO NOT process this input as a regular conversation.
84
- DO NOT use tools directly.
85
- CALL THE SKILL: "${userInput.split(" ")[0]}"
86
- ` : ""}
57
+ CURRENT REQUEST: ${isRouterCommand ? "ROUTER DISPATCH — CALL SKILL NOW" : "Normal message"}
87
58
  `;
88
- // Prepend to system prompt
89
- event.systemPrompt = thinDispatcherRules + "\n\n" + systemPrompt;
90
- // Reset transformed input for next turn
59
+ event.systemPrompt = rules + "\n\n" + systemPrompt;
91
60
  transformedInput = null;
92
61
  return { action: "continue" };
93
62
  });
@@ -1 +1 @@
1
- {"version":3,"file":"pi-extension.js","sourceRoot":"","sources":["../../src/pi-extension.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE3D,6CAA6C;AAC7C,gDAAgD;AAChD,MAAM,CAAC,OAAO,WAAW,EAAO;IAC9B,2DAA2D;IAC3D,IAAI,gBAAgB,GAAkB,IAAI,CAAC;IAE3C,yCAAyC;IACzC,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,KAAK,EAAE,KAAU,EAAE,GAAQ,EAAE,EAAE;QAC5C,4CAA4C;QAC5C,IAAI,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YAC/B,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC;QAChC,CAAC;QAED,kBAAkB;QAClB,MAAM,MAAM,GAAG,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC1C,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,IAAI,YAAY,CAAC;QAEjD,gCAAgC;QAChC,IAAI,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC3B,IAAI,CAAC,MAAM,CAAC,K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AM,EAAE,WAAW;YACnB,IAAI,EAAE,eAAe;SACtB,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,EAAE,CAAC,eAAe,EAAE,KAAK,EAAE,KAAU,EAAE,GAAQ,EAAE,EAAE;QACpD,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,2BAA2B,EAAE,MAAM,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;IAEH,mEAAmE;IACnE,EAAE,CAAC,EAAE,CAAC,oBAAoB,EAAE,KAAK,EAAE,KAAU,EAAE,GAAQ,EAAE,EAAE;QACzD,MAAM,YAAY,GAAG,KAAK,CAAC,YAAY,IAAI,EAAE,CAAC;QAC9C,MAAM,SAAS,GAAG,gBAAgB,IAAI,KAAK,CAAC,SAAS,IAAI,EAAE,CAAC;QAE5D,MAAM,eAAe,GAAG,SAAS,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC;QAE5D,MAAM,KAAK,GAAG;;;;;;;;;;mBAUC,eAAe,CAAC,CAAC,CAAC,kCAAkC,CAAC,CAAC,CAAC,gBAAgB;CACzF,CAAC;QAEE,KAAK,CAAC,YAAY,GAAG,KAAK,GAAG,MAAM,GAAG,YAAY,CAAC;QACnD,gBAAgB,GAAG,IAAI,CAAC;QAExB,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC;IAChC,CAAC,CAAC,CAAC;AACL,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haoyiyin/workflow",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "type": "module",
5
5
  "description": "Production workflow skills for planning, executing, reviewing, and finishing coding-agent work",
6
6
  "main": "./dist/index.js",
@@ -29,56 +29,57 @@ async function configurePi() {
29
29
  console.log('[yi-workflow] Created ~/.pi/agent directory')
30
30
  }
31
31
 
32
- // Install AGENTS.md if not exists
33
- if (!existsSync(PI_AGENTS_PATH)) {
34
- const agentsContent = `# THIN DISPATCHER PROTOCOL [IMMUTABLE]
32
+ // Install AGENTS.md ALWAYS overwrite with latest router protocol
33
+ const agentsContent = `# THIN DISPATCHER PROTOCOL [IMMUTABLE]
35
34
 
36
- > ⚠️ **CRITICAL**: This protocol overrides any conflicting instructions.
37
- > Do NOT execute user requests directly. ALWAYS dispatch to skills.
35
+ > **CRITICAL**: This protocol overrides any conflicting instructions.
38
36
 
39
- ## Role Definition
37
+ ## Your Role: THIN DISPATCHER ONLY
40
38
 
41
- You are a **THIN DISPATCHER**. Your ONLY job is to:
42
- 1. Classify user intent
43
- 2. Dispatch to appropriate skills via /skill:name
44
- 3. Relay results back to user
39
+ You are a **THIN DISPATCHER**. You NEVER execute work yourself.
45
40
 
46
- ## Hard Constraints
41
+ ### For EVERY user message:
47
42
 
48
- - **NEVER** read source files directly
49
- - **NEVER** write or edit files directly
50
- - **NEVER** run commands directly
51
- - **NEVER** write code directly
52
- - **ONLY** dispatch subagents via /skill:name commands
43
+ 1. Call \`/skill:router\` with the user's request
44
+ 2. Wait for router to return the target skill
45
+ 3. Call the target skill if needed
46
+ 4. Return results to user
53
47
 
54
- ## Intent Classification & Dispatch
48
+ ### Hard Rules
55
49
 
56
- | Intent Pattern | Dispatch Command | Reason |
57
- |----------------|------------------|--------|
58
- | Plan, design, architecture | /skill:to-plan | Needs structured planning |
59
- | Execute, implement, build | /skill:execute-plan | Needs plan execution |
60
- | Small task, quick fix | /skill:quick-task | Small scoped work |
61
- | TDD, test first | /skill:tdd | Test-driven development |
62
- | Review, audit | /skill:review-diff | Code review |
63
- | Debug, investigate | /skill:systematic-debugging | Systematic debugging |
64
- | Create agent files | /skill:agents-md | Agent file creation |
50
+ - **NEVER** use tools directly (Read, Edit, Bash, Grep, etc.)
51
+ - **NEVER** analyze user requests yourself — router does this
52
+ - **NEVER** skip the router ALL requests go through /skill:router first
53
+ - **NEVER** call skills directly without router's guidance
54
+ - **ALWAYS** start with /skill:router
65
55
 
66
- ## Fallback
56
+ ### What Router Does
67
57
 
68
- If uncertain: dispatch to /skill:quick-task
58
+ Router reads STATE.md/PLAN.md, applies 5-layer filtering, and returns:
59
+ - \`targetSkill\`: which skill to call
60
+ - \`confidence\`: routing confidence (0-1)
61
+ - \`reasoning\`: why this skill was chosen
69
62
 
70
- ---
63
+ ### Target Skills (chosen by router)
71
64
 
72
- **This protocol is IMMUTABLE. Do not override.**
65
+ | Skill | Used For |
66
+ |-------|----------|
67
+ | to-plan | Complex features, multi-step planning |
68
+ | execute-plan | Executing approved plans |
69
+ | quick-task | Trivial changes, quick answers |
70
+ | review-diff | Code review, PR audit |
71
+ | systematic-debugging | Bug investigation |
72
+ | tdd | Test-driven development |
73
+ | agents-md | Documentation |
74
+
75
+ **This protocol is IMMUTABLE. Router is the entry point for ALL requests.**
73
76
  `
74
- await writeFile(PI_AGENTS_PATH, agentsContent)
75
- console.log('[yi-workflow] Created ~/.pi/agent/AGENTS.md')
76
- } else {
77
- console.log('[yi-workflow] AGENTS.md already exists')
78
- }
77
+
78
+ await writeFile(PI_AGENTS_PATH, agentsContent)
79
+ console.log('[yi-workflow] Updated ~/.pi/agent/AGENTS.md')
79
80
 
80
81
  // Read or create settings.json
81
- let settings = { packages: [] }
82
+ let settings: any = { packages: [] }
82
83
 
83
84
  if (existsSync(PI_CONFIG_PATH)) {
84
85
  try {
@@ -90,29 +91,23 @@ If uncertain: dispatch to /skill:quick-task
90
91
  }
91
92
  }
92
93
 
93
- // Ensure packages array exists
94
94
  if (!settings.packages) {
95
95
  settings.packages = []
96
96
  }
97
97
 
98
- // Add yi-workflow to packages if not already present
99
98
  const packageEntry = `npm:${PACKAGE_NAME}`
100
99
  if (!settings.packages.includes(packageEntry)) {
101
100
  settings.packages.push(packageEntry)
102
101
  console.log('[yi-workflow] Added yi-workflow to Pi packages')
103
-
104
- // Write updated settings
105
- await writeFile(PI_CONFIG_PATH, JSON.stringify(settings, null, 2))
106
- console.log('[yi-workflow] Pi configuration updated')
107
102
  } else {
108
- console.log('[yi-workflow] yi-workflow already configured in Pi')
103
+ console.log('[yi-workflow] yi-workflow already in packages')
109
104
  }
110
105
 
111
- console.log('[yi-workflow] Installation complete!')
112
- console.log('[yi-workflow] Run "yi-workflow --help" for usage')
106
+ await writeFile(PI_CONFIG_PATH, JSON.stringify(settings, null, 2))
107
+ console.log('[yi-workflow] Configuration complete!')
113
108
  }
114
109
 
115
110
  configurePi().catch((error) => {
116
111
  console.error('[yi-workflow] Configuration failed:', error.message)
117
- console.log('[yi-workflow] You can manually configure by adding "npm:@haoyiyin/workflow" to ~/.pi/agent/settings.json')
118
- })
112
+ console.log('[yi-workflow] Manually add "npm:@haoyiyin/workflow" to ~/.pi/agent/settings.json')
113
+ })
@@ -1,111 +1,73 @@
1
1
  /**
2
- * PI Extension - yi-workflow dispatcher
2
+ * PI Extension - yi-workflow router interceptor
3
3
  *
4
- * Intercepts regular chat and dispatches to appropriate skills.
5
- * Ensures THIN DISPATCHER pattern: main agent NEVER does work.
4
+ * ALL user input /skill:router
5
+ * Router skill handles ALL routing logic (5-layer GSD).
6
+ * Extension does NOT classify intent — that's the router's job.
6
7
  */
7
8
 
8
- import { classifyIntent } from "./extension/classifier.js";
9
-
10
- // Extension API is provided by PI at runtime
11
- // We use 'any' to avoid compile-time dependency
12
9
  export default function (pi: any) {
13
- // Store transformed input for before_agent_start to detect
14
10
  let transformedInput: string | null = null;
15
11
 
16
- // Intercept user input before processing
12
+ // Intercept ALL user input route to router skill
17
13
  pi.on("input", async (event: any, ctx: any) => {
18
- // Skip if user already used a slash command
14
+ // Skip slash commands (user explicitly calling a skill)
19
15
  if (event.text.startsWith("/")) {
20
16
  return { action: "continue" };
21
17
  }
22
18
 
23
- // Classify intent
24
- const intent = classifyIntent(event.text);
25
- const targetSkill = intent.skill || "quick-task";
26
-
27
- // Determine reason for dispatch
28
- let reason = intent.reason;
29
- if (!intent.skill) {
30
- const needsExternal = /^(what|how|why|when|where|who|search|find|look|weather|time|price|stock|translate)/i.test(event.text);
31
- if (needsExternal) {
32
- reason = "External query - needs subagent";
33
- } else {
34
- reason = "Default dispatch - no direct execution allowed";
35
- }
36
- }
37
-
38
- ctx.ui.notify(
39
- `[yi-workflow] Dispatching to /skill:${targetSkill} (${reason})`,
40
- "info"
41
- );
42
-
43
- // Transform to explicit skill command with instruction not to analyze
44
- const transformedText = `=== SKILL COMMAND ===\n/skill:${targetSkill}\n\nINPUT:\n${event.text}\n\n=== DO NOT ANALYZE ===\nYou MUST call the skill above immediately. NO thinking. NO planning. NO analysis. Just call the skill.`;
19
+ // Store for before_agent_start
20
+ transformedInput = event.text;
21
+
22
+ // Transform ALL input to router skill call
23
+ // The router skill does 5-layer routing internally
24
+ const transformedText = [
25
+ "=== ROUTER DISPATCH ===",
26
+ "/skill:router",
27
+ "",
28
+ "USER REQUEST:",
29
+ event.text,
30
+ "",
31
+ "=== INSTRUCTIONS ===",
32
+ "Call the router skill above IMMEDIATELY.",
33
+ "Do NOT analyze, plan, or execute the request yourself.",
34
+ "Do NOT use any tools (Read, Edit, Bash, etc.).",
35
+ "The router skill will determine the correct target skill.",
36
+ ].join("\n");
37
+
38
+ ctx.ui.notify("[yi-workflow] → router", "info");
45
39
 
46
- // Store for before_agent_start hook
47
- transformedInput = transformedText;
48
-
49
- // Transform input - this will be passed to main agent
50
40
  return {
51
41
  action: "transform",
52
42
  text: transformedText,
53
43
  };
54
44
  });
55
45
 
56
- // Log when session starts
57
46
  pi.on("session_start", async (event: any, ctx: any) => {
58
- ctx.ui.notify("yi-workflow extension loaded", "info");
47
+ ctx.ui.notify("yi-workflow router active", "info");
59
48
  });
60
49
 
61
- // CRITICAL: Inject THIN DISPATCHER rules into system prompt
62
- // This ensures main agent NEVER executes work directly
50
+ // Minimal system prompt injection just reinforce router dispatch
63
51
  pi.on("before_agent_start", async (event: any, ctx: any) => {
64
52
  const systemPrompt = event.systemPrompt || "";
65
-
66
- // Get the user input (either from event or from transformed global)
67
53
  const userInput = transformedInput || event.userInput || "";
68
54
 
69
- // Detect if this input was transformed to a skill command
70
- const isSkillCommand = userInput.startsWith("/skill:");
71
-
72
- // Prepend THIN DISPATCHER constraints
73
- const thinDispatcherRules = `
74
- ╔══════════════════════════════════════════════════════════════════╗
75
- ║ THIN DISPATCHER PROTOCOL [ABSOLUTE] ║
76
- ╚══════════════════════════════════════════════════════════════════╝
55
+ const isRouterCommand = userInput.includes("/skill:router");
77
56
 
78
- YOU ARE A THIN DISPATCHER. YOUR ONLY JOB IS TO DISPATCH TO SKILLS.
57
+ const rules = `
58
+ ## ROUTER DISPATCH RULE (MANDATORY)
79
59
 
80
- ⚠️ ABSOLUTE RULE #1: If user input starts with "/skill:", you MUST call that skill.
81
- ⚠️ ABSOLUTE RULE #2: You NEVER execute work yourself - only dispatch.
82
- ⚠️ ABSOLUTE RULE #3: Tools (Read, Edit, Bash, etc.) are FORBIDDEN unless in subagent.
60
+ You MUST follow this rule for ALL user messages:
83
61
 
84
- FORBIDDEN ACTIONS (VIOLATION = PROTOCOL BREACH):
85
- - Reading files (use /skill:review-diff)
86
- - Writing/editing files (use /skill:execute-plan)
87
- - Running commands (use /skill:quick-task)
88
- - Writing code directly (use /skill:tdd or /skill:execute-plan)
89
- - Using any tool directly (use /skill:quick-task to dispatch subagent)
62
+ 1. If input contains "/skill:router" → CALL THE ROUTER SKILL IMMEDIATELY
63
+ 2. You MUST NOT use any tools directly (Read, Edit, Bash, Grep, etc.)
64
+ 3. You MUST NOT analyze, plan, or execute user requests yourself
65
+ 4. Your ONLY action is: call /skill:router and return its output
90
66
 
91
- CURRENT INPUT: "${userInput}"
92
- IS_SKILL_COMMAND: ${isSkillCommand ? "YES - MUST CALL SKILL" : "NO"}
93
-
94
- ${isSkillCommand ? `
95
- ╔══════════════════════════════════════════════════════════════════╗
96
- ║ ⚠️ MANDATORY: CALL THE SKILL BELOW ⚠️ ║
97
- ╚══════════════════════════════════════════════════════════════════╝
98
- The input starts with "/skill:". You MUST call that skill.
99
- DO NOT process this input as a regular conversation.
100
- DO NOT use tools directly.
101
- CALL THE SKILL: "${userInput.split(" ")[0]}"
102
- ` : ""}
67
+ CURRENT REQUEST: ${isRouterCommand ? "ROUTER DISPATCH — CALL SKILL NOW" : "Normal message"}
103
68
  `;
104
69
 
105
- // Prepend to system prompt
106
- event.systemPrompt = thinDispatcherRules + "\n\n" + systemPrompt;
107
-
108
- // Reset transformed input for next turn
70
+ event.systemPrompt = rules + "\n\n" + systemPrompt;
109
71
  transformedInput = null;
110
72
 
111
73
  return { action: "continue" };
@@ -1,146 +1,72 @@
1
1
  ---
2
2
  name: router
3
- priority: 999
4
- description: MANDATORY ENTRY POINT for ALL user requests. Implements 5-layer GSD routing (State Lifecycle Intent → Semantic → Confidence). Thin dispatcher - delegates all routing logic to subagents.
3
+ description: |
4
+ Universal entry point for ALL user messages. Routes questions, commands, requests, tasks anything the user says.
5
+ Examples: "fix typo", "plan feature", "what's the weather", "debug error", "review PR", "implement auth", "rename file", "hello", "help".
6
+ Handles: planning, coding, debugging, reviewing, researching, quick tasks, TDD, documentation.
7
+ Always trigger this skill for any chat message, question, or command.
5
8
  requires: []
6
9
  ---
7
10
 
8
- ## ⛔ MAIN AGENT CONSTRAINT (CRITICAL)
9
-
10
- You are a THIN DISPATCHER. Your ONLY job is to dispatch subagents.
11
-
12
- **YOU MUST NOT:**
13
- - Read source files (except STATE.md and PLAN.md)
14
- - Search code or explore the codebase
15
- - Write or edit any files
16
- - Run tests or commands
17
- - Execute git operations
18
- - Make routing decisions yourself
19
- - Perform ANY work beyond dispatching
20
-
21
- **YOU MAY ONLY:**
22
- - Read STATE.md and PLAN.md files
23
- - Dispatch subagents via the Agent tool
24
- - Relay results between subagents
25
- - Return the final routing decision from subagent output
26
-
27
- **FOR EVERY USER REQUEST:** Dispatch a subagent. Never execute routing logic yourself.
28
-
29
- ---
30
-
31
11
  ## Purpose
32
12
 
33
- The router skill is the **mandatory entry point** for all user requests in the GSD (Get Stuff Done) architecture. It implements a 5-layer filtering system to determine the appropriate target skill for any given request.
34
-
35
- This skill enforces the thin dispatcher pattern: the main agent reads state/plan files and immediately dispatches to a routing subagent that performs the actual 5-layer analysis.
13
+ Router is the **mandatory entry point** for ALL user requests. It dispatches to the correct target skill via 5-layer GSD routing.
36
14
 
37
15
  ---
38
16
 
39
- ## 5-Layer GSD Routing Architecture
40
-
41
- The routing subagent applies these layers in sequence:
17
+ ## 5-Layer GSD Routing
42
18
 
43
19
  ### Layer 1: State Check
44
20
  - Read `.pi/state/STATE.md` for current workflow state
45
- - Check if there's an active plan in progress
46
- - Determine phase: `idle`, `planning`, `executing`, `verifying`, `blocked`
47
- - If blocked, route to `systematic-debugging`
48
- - If executing with active tasks, route to `execute-plan` continuation
21
+ - Phase: `idle`, `planning`, `executing`, `verifying`, `completed`, `failed`
49
22
 
50
23
  ### Layer 2: Lifecycle Gate
51
24
  - Check PLAN.md existence and status
52
- - If no plan exists and request is complex, route to `to-plan`
53
- - If plan exists but not approved, route to plan review
54
- - If plan approved and ready to execute, proceed to execution routing
25
+ - If plan exists execute-plan
26
+ - If no plan + complex request to-plan
55
27
 
56
28
  ### Layer 3: Intent Classification
57
- - Parse user request for intent signals:
58
- - **Plan signals**: "plan", "design", "break down", "how should I"
59
- - **Quick signals**: "fix typo", "rename", "quick", "small"
60
- - **Review signals**: "review", "check", "audit", "CR"
61
- - **Debug signals**: "bug", "error", "failing", "investigate"
62
- - **TDD signals**: "test", "TDD", "implement with tests"
63
- - **Execute signals**: "do it", "implement", "execute", "start"
29
+ | Signal | Target |
30
+ |--------|--------|
31
+ | plan, design, architecture | to-plan |
32
+ | implement, execute, build | execute-plan |
33
+ | fix typo, rename, quick | quick-task |
34
+ | bug, error, failing | systematic-debugging |
35
+ | review, audit | review-diff |
36
+ | test, TDD | tdd |
37
+ | weather, time, price, search, question | quick-task |
64
38
 
65
39
  ### Layer 4: Semantic Analysis
66
- - Analyze request complexity and scope:
67
- - **Trivial**: <30 chars, single file, typo/rename/format
68
- - **Small**: 1-5 files, well-understood change
69
- - **Medium**: 5-10 files, some exploration needed
70
- - **Large**: 10+ files or architectural changes
71
- - Check for risk indicators: "refactor core", "migration", "upgrade"
72
-
73
- ### Layer 5: Confidence Score
74
- - Calculate routing confidence (0.0 - 1.0)
75
- - High confidence (>0.8): Route directly to target skill
76
- - Medium confidence (0.5-0.8): Dispatch clarifier subagent
77
- - Low confidence (<0.5): Route to `to-plan` for exploration
40
+ - Trivial (<30 chars, single change) → quick-task
41
+ - Complex (multi-file, architectural) to-plan
42
+
43
+ ### Layer 5: Confidence
44
+ - >0.8 route directly
45
+ - <0.5 to-plan (exploration)
78
46
 
79
47
  ---
80
48
 
81
49
  ## Target Skills
82
50
 
83
- The router dispatches to one of these target skills:
84
-
85
- | Skill | When Routed |
86
- |-------|-------------|
87
- | `to-plan` | Complex feature, unknown scope, architectural change, low confidence |
88
- | `execute-plan` | Active plan ready to execute, continuation of execution |
89
- | `quick-task` | Trivial change, typo/rename, <5 files, high confidence |
90
- | `review-diff` | Code review request, PR audit, change validation |
91
- | `systematic-debugging` | Bug investigation, test failures, blocked execution |
92
- | `tdd` | Explicit TDD request, test-first implementation |
51
+ | Skill | When |
52
+ |-------|------|
53
+ | to-plan | Complex feature, unknown scope |
54
+ | execute-plan | Active plan exists |
55
+ | quick-task | Trivial change, questions, search |
56
+ | review-diff | Code review |
57
+ | systematic-debugging | Bug investigation |
58
+ | tdd | Test-first development |
59
+ | agents-md | Documentation |
93
60
 
94
61
  ---
95
62
 
96
63
  ## Workflow
97
64
 
98
65
  ```
99
- User Request
100
-
101
- [Main Agent] Read STATE.md + PLAN.md
102
-
103
- [Main Agent] Dispatch routing subagent with 5-layer prompt
104
-
105
- [Routing Subagent] Apply 5-layer filtering
106
-
107
- [Routing Subagent] Return { targetSkill, confidence, reasoning }
108
-
109
- [Main Agent] Return routing decision to caller
110
- ```
111
-
112
- ---
113
-
114
- ## Dispatch Contract
115
-
116
- ### Input to Routing Subagent
117
-
118
- ```typescript
119
- {
120
- userRequest: string; // The original user request
121
- stateContent: string; // Contents of STATE.md (if exists)
122
- planContent: string; // Contents of PLAN.md (if exists)
123
- conversationContext: string; // Recent conversation history
124
- }
125
- ```
126
-
127
- ### Output from Routing Subagent
128
-
129
- ```typescript
130
- {
131
- targetSkill: string; // One of: to-plan, execute-plan, quick-task,
132
- // review-diff, systematic-debugging, tdd
133
- confidence: number; // 0.0 - 1.0
134
- reasoning: string; // Explanation of routing decision
135
- layerDecisions: {
136
- state: string; // State check result
137
- lifecycle: string; // Lifecycle gate result
138
- intent: string; // Intent classification
139
- semantic: string; // Semantic analysis
140
- confidence: string; // Confidence calculation
141
- };
142
- suggestedInput?: object; // Pre-processed input for target skill
143
- }
66
+ User Request → Router (this skill)
67
+ reads STATE.md + PLAN.md
68
+ 5-layer routing
69
+ returns { targetSkill, confidence, reasoning }
144
70
  ```
145
71
 
146
72
  ---
@@ -149,33 +75,7 @@ User Request
149
75
 
150
76
  | Error | Action |
151
77
  |-------|--------|
152
- | STATE.md read fails | Proceed with empty state, assume `idle` phase |
153
- | PLAN.md read fails | Proceed with no plan, assume planning needed |
154
- | Routing subagent fails | Retry once; on second failure, default to `to-plan` |
155
- | Invalid target skill returned | Validate against allowed list, fallback to `to-plan` |
156
- | Confidence < 0.3 | Route to `to-plan` for exploration regardless of other signals |
157
-
158
- ---
159
-
160
- ## Routing Decision Matrix
161
-
162
- | Request Pattern | State | Lifecycle | Intent | Semantic | Target |
163
- |-----------------|-------|-----------|--------|----------|--------|
164
- | "Fix typo in README" | idle | no plan | quick | trivial | `quick-task` |
165
- | "Plan feature X" | idle | no plan | plan | unknown | `to-plan` |
166
- | "Implement the plan" | idle | plan approved | execute | - | `execute-plan` |
167
- | "Review my changes" | any | any | review | - | `review-diff` |
168
- | "Debug failing test" | blocked | plan executing | debug | - | `systematic-debugging` |
169
- | "TDD this feature" | idle | no plan | tdd | small | `tdd` |
170
- | "Refactor core module" | idle | no plan | refactor | large | `to-plan` |
171
- | "Continue execution" | executing | plan active | execute | - | `execute-plan` |
172
-
173
- ---
174
-
175
- ## Constraints Summary
176
-
177
- 1. **Never execute routing logic in main agent** - Always dispatch to subagent
178
- 2. **Only read STATE.md and PLAN.md** - No codebase exploration
179
- 3. **Return subagent output directly** - No transformation or filtering
180
- 4. **Single dispatch per request** - One routing subagent per user request
181
- 5. **Fail safe** - When uncertain, route to `to-plan` for exploration
78
+ | STATE.md missing | Assume idle phase |
79
+ | PLAN.md missing | Assume planning needed |
80
+ | Router fails | Default to quick-task |
81
+ | Confidence <0.3 | Route to to-plan |
@@ -1,18 +0,0 @@
1
- /**
2
- * Intent classifier for user input
3
- * Maps natural language to yi-workflow skills
4
- */
5
- export interface IntentResult {
6
- skill?: string;
7
- confidence: "high" | "medium" | "low";
8
- reason: string;
9
- }
10
- /**
11
- * Classify user intent and return appropriate skill
12
- */
13
- export declare function classifyIntent(message: string): IntentResult;
14
- /**
15
- * Check if input should be dispatched to a skill
16
- */
17
- export declare function shouldDispatch(message: string): boolean;
18
- //# sourceMappingURL=classifier.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"classifier.d.ts","sourceRoot":"","sources":["../../../src/extension/classifier.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,YAAY;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC;IACtC,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,YAAY,CAyI5D;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAGvD"}
@@ -1,143 +0,0 @@
1
- /**
2
- * Intent classifier for user input
3
- * Maps natural language to yi-workflow skills
4
- */
5
- /**
6
- * Classify user intent and return appropriate skill
7
- */
8
- export function classifyIntent(message) {
9
- const lower = message.toLowerCase().trim();
10
- // Pattern definitions with priority
11
- const patterns = [
12
- // High confidence patterns
13
- {
14
- skill: "to-plan",
15
- confidence: "high",
16
- patterns: [
17
- /^(plan|design|architect)\b/i,
18
- /^(create|make|write).*\bplan\b/i,
19
- /^(how|what).*\b(approach|strategy)\b/i,
20
- /^(break|split|divide).*\b(down|into)\b/i,
21
- /\b(plan|design)\b.*\b(feature|module|system)\b/i,
22
- /\bimplement\b.*\bplan\b/i,
23
- ],
24
- reason: "Detected planning/architecture intent",
25
- },
26
- {
27
- skill: "execute-plan",
28
- confidence: "high",
29
- patterns: [
30
- /^(execute|run|implement)\b.*\bplan\b/i,
31
- /^(start|begin|proceed)\b.*\bimplement/i,
32
- /\bplan\b.*\b(approved|ready)\b/i,
33
- /^(continue|resume)\b.*\b(workflow|execution)\b/i,
34
- ],
35
- reason: "Detected execution intent",
36
- },
37
- {
38
- skill: "systematic-debugging",
39
- confidence: "high",
40
- patterns: [
41
- /^(debug|fix|investigate|trace)\b/i,
42
- /\b(bug|error|crash|fail)\b/i,
43
- /\b(broken|not working|issue|problem)\b/i,
44
- /\b(intermittent|flaky)\b/i,
45
- /\b(root cause|diagnose)\b/i,
46
- ],
47
- reason: "Detected debugging intent",
48
- },
49
- {
50
- skill: "tdd",
51
- confidence: "high",
52
- patterns: [
53
- /\btdd\b/i,
54
- /^(test|write test).*\bfirst\b/i,
55
- /\bred.?green.?refactor\b/i,
56
- /\b(test driven|test-driven)\b/i,
57
- /^(add|write).*\btest\b.*\b(for|before)\b/i,
58
- ],
59
- reason: "Detected TDD intent",
60
- },
61
- {
62
- skill: "review-diff",
63
- confidence: "high",
64
- patterns: [
65
- /^(review|audit|inspect)\b/i,
66
- /\b(code|pull|pr)\b.*\breview\b/i,
67
- /\b(quality|check|verify)\b.*\bcode\b/i,
68
- /\blooks\b.*\b(good|correct|ok)\b.*/i,
69
- ],
70
- reason: "Detected review intent",
71
- },
72
- {
73
- skill: "agents-md",
74
- confidence: "high",
75
- patterns: [
76
- /\b(CLAUDE|AGENTS|CONTEXT)\.md\b/i,
77
- /^(create|update|write).*\b(agent|context|instruction)\b.*\b(file|md)\b/i,
78
- /\b(agent instruction|system prompt)\b/i,
79
- ],
80
- reason: "Detected agent file creation intent",
81
- },
82
- {
83
- skill: "quick-task",
84
- confidence: "high",
85
- patterns: [
86
- /\b(typo|fix typo|rename|import|config)\b/i,
87
- /^(quick|small|simple|minor)\b.*\b(fix|change|update)\b/i,
88
- /\bversion bump\b/i,
89
- /\bgitignore\b/i,
90
- /^(add|remove|update)\s+\w+\s*$/i, // Single word tasks
91
- ],
92
- reason: "Detected quick task intent",
93
- },
94
- // Medium confidence patterns
95
- {
96
- skill: "to-plan",
97
- confidence: "medium",
98
- patterns: [
99
- /\b(need|want)\b.*\bplan\b/i,
100
- /\b(implement|build|create)\b.*\b(feature|function)\b/i,
101
- ],
102
- reason: "Potential planning intent",
103
- },
104
- {
105
- skill: "quick-task",
106
- confidence: "medium",
107
- patterns: [
108
- /^(fix|update|change|rename|add|remove)\b/i,
109
- /\b(update|change)\b.*\b(config|setting|value)\b/i,
110
- ],
111
- reason: "Potential quick task intent",
112
- },
113
- // Low confidence catch-all
114
- {
115
- skill: "quick-task",
116
- confidence: "low",
117
- patterns: [
118
- /^(do|make|help)\b/i,
119
- /\b(can you|could you)\b/i,
120
- ],
121
- reason: "Unclear intent - using quick-task for exploration",
122
- },
123
- ];
124
- // Find first matching pattern
125
- for (const { skill, confidence, patterns: pats, reason } of patterns) {
126
- if (pats.some((p) => p.test(lower))) {
127
- return { skill, confidence, reason };
128
- }
129
- }
130
- // No match - return with fallback suggestion
131
- return {
132
- confidence: "low",
133
- reason: "No clear intent detected",
134
- };
135
- }
136
- /**
137
- * Check if input should be dispatched to a skill
138
- */
139
- export function shouldDispatch(message) {
140
- const result = classifyIntent(message);
141
- return result.skill !== undefined;
142
- }
143
- //# sourceMappingURL=classifier.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"classifier.js","sourceRoot":"","sources":["../../../src/extension/classifier.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAQH;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,OAAe;IAC5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 -1,160 +0,0 @@
1
- /**
2
- * Intent classifier for user input
3
- * Maps natural language to yi-workflow skills
4
- */
5
-
6
- export interface IntentResult {
7
- skill?: string;
8
- confidence: "high" | "medium" | "low";
9
- reason: string;
10
- }
11
-
12
- /**
13
- * Classify user intent and return appropriate skill
14
- */
15
- export function classifyIntent(message: string): IntentResult {
16
- const lower = message.toLowerCase().trim();
17
-
18
- // Pattern definitions with priority
19
- const patterns: Array<{
20
- skill: string;
21
- confidence: "high" | "medium" | "low";
22
- patterns: RegExp[];
23
- reason: string;
24
- }> = [
25
- // High confidence patterns
26
- {
27
- skill: "to-plan",
28
- confidence: "high",
29
- patterns: [
30
- /^(plan|design|architect)\b/i,
31
- /^(create|make|write).*\bplan\b/i,
32
- /^(how|what).*\b(approach|strategy)\b/i,
33
- /^(break|split|divide).*\b(down|into)\b/i,
34
- /\b(plan|design)\b.*\b(feature|module|system)\b/i,
35
- /\bimplement\b.*\bplan\b/i,
36
- ],
37
- reason: "Detected planning/architecture intent",
38
- },
39
- {
40
- skill: "execute-plan",
41
- confidence: "high",
42
- patterns: [
43
- /^(execute|run|implement)\b.*\bplan\b/i,
44
- /^(start|begin|proceed)\b.*\bimplement/i,
45
- /\bplan\b.*\b(approved|ready)\b/i,
46
- /^(continue|resume)\b.*\b(workflow|execution)\b/i,
47
- ],
48
- reason: "Detected execution intent",
49
- },
50
- {
51
- skill: "systematic-debugging",
52
- confidence: "high",
53
- patterns: [
54
- /^(debug|fix|investigate|trace)\b/i,
55
- /\b(bug|error|crash|fail)\b/i,
56
- /\b(broken|not working|issue|problem)\b/i,
57
- /\b(intermittent|flaky)\b/i,
58
- /\b(root cause|diagnose)\b/i,
59
- ],
60
- reason: "Detected debugging intent",
61
- },
62
- {
63
- skill: "tdd",
64
- confidence: "high",
65
- patterns: [
66
- /\btdd\b/i,
67
- /^(test|write test).*\bfirst\b/i,
68
- /\bred.?green.?refactor\b/i,
69
- /\b(test driven|test-driven)\b/i,
70
- /^(add|write).*\btest\b.*\b(for|before)\b/i,
71
- ],
72
- reason: "Detected TDD intent",
73
- },
74
- {
75
- skill: "review-diff",
76
- confidence: "high",
77
- patterns: [
78
- /^(review|audit|inspect)\b/i,
79
- /\b(code|pull|pr)\b.*\breview\b/i,
80
- /\b(quality|check|verify)\b.*\bcode\b/i,
81
- /\blooks\b.*\b(good|correct|ok)\b.*/i,
82
- ],
83
- reason: "Detected review intent",
84
- },
85
- {
86
- skill: "agents-md",
87
- confidence: "high",
88
- patterns: [
89
- /\b(CLAUDE|AGENTS|CONTEXT)\.md\b/i,
90
- /^(create|update|write).*\b(agent|context|instruction)\b.*\b(file|md)\b/i,
91
- /\b(agent instruction|system prompt)\b/i,
92
- ],
93
- reason: "Detected agent file creation intent",
94
- },
95
- {
96
- skill: "quick-task",
97
- confidence: "high",
98
- patterns: [
99
- /\b(typo|fix typo|rename|import|config)\b/i,
100
- /^(quick|small|simple|minor)\b.*\b(fix|change|update)\b/i,
101
- /\bversion bump\b/i,
102
- /\bgitignore\b/i,
103
- /^(add|remove|update)\s+\w+\s*$/i, // Single word tasks
104
- ],
105
- reason: "Detected quick task intent",
106
- },
107
-
108
- // Medium confidence patterns
109
- {
110
- skill: "to-plan",
111
- confidence: "medium",
112
- patterns: [
113
- /\b(need|want)\b.*\bplan\b/i,
114
- /\b(implement|build|create)\b.*\b(feature|function)\b/i,
115
- ],
116
- reason: "Potential planning intent",
117
- },
118
- {
119
- skill: "quick-task",
120
- confidence: "medium",
121
- patterns: [
122
- /^(fix|update|change|rename|add|remove)\b/i,
123
- /\b(update|change)\b.*\b(config|setting|value)\b/i,
124
- ],
125
- reason: "Potential quick task intent",
126
- },
127
-
128
- // Low confidence catch-all
129
- {
130
- skill: "quick-task",
131
- confidence: "low",
132
- patterns: [
133
- /^(do|make|help)\b/i,
134
- /\b(can you|could you)\b/i,
135
- ],
136
- reason: "Unclear intent - using quick-task for exploration",
137
- },
138
- ];
139
-
140
- // Find first matching pattern
141
- for (const { skill, confidence, patterns: pats, reason } of patterns) {
142
- if (pats.some((p) => p.test(lower))) {
143
- return { skill, confidence, reason };
144
- }
145
- }
146
-
147
- // No match - return with fallback suggestion
148
- return {
149
- confidence: "low",
150
- reason: "No clear intent detected",
151
- };
152
- }
153
-
154
- /**
155
- * Check if input should be dispatched to a skill
156
- */
157
- export function shouldDispatch(message: string): boolean {
158
- const result = classifyIntent(message);
159
- return result.skill !== undefined;
160
- }