gsd-pi 2.29.0-dev.49d972f → 2.29.0-dev.77f06e2

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.
Files changed (48) hide show
  1. package/README.md +24 -17
  2. package/dist/resources/extensions/bg-shell/process-manager.ts +13 -0
  3. package/dist/resources/extensions/gsd/auto-dashboard.ts +186 -65
  4. package/dist/resources/extensions/gsd/auto-post-unit.ts +5 -2
  5. package/dist/resources/extensions/gsd/commands-prefs-wizard.ts +44 -14
  6. package/dist/resources/extensions/gsd/commands-workflow-templates.ts +544 -0
  7. package/dist/resources/extensions/gsd/commands.ts +53 -1
  8. package/dist/resources/extensions/gsd/prompts/workflow-start.md +28 -0
  9. package/dist/resources/extensions/gsd/tests/extension-selector-separator.test.ts +60 -38
  10. package/dist/resources/extensions/gsd/tests/workflow-templates.test.ts +173 -0
  11. package/dist/resources/extensions/gsd/workflow-templates/bugfix.md +87 -0
  12. package/dist/resources/extensions/gsd/workflow-templates/dep-upgrade.md +74 -0
  13. package/dist/resources/extensions/gsd/workflow-templates/full-project.md +41 -0
  14. package/dist/resources/extensions/gsd/workflow-templates/hotfix.md +45 -0
  15. package/dist/resources/extensions/gsd/workflow-templates/refactor.md +83 -0
  16. package/dist/resources/extensions/gsd/workflow-templates/registry.json +85 -0
  17. package/dist/resources/extensions/gsd/workflow-templates/security-audit.md +73 -0
  18. package/dist/resources/extensions/gsd/workflow-templates/small-feature.md +81 -0
  19. package/dist/resources/extensions/gsd/workflow-templates/spike.md +69 -0
  20. package/dist/resources/extensions/gsd/workflow-templates.ts +241 -0
  21. package/dist/resources/extensions/mcp-client/index.ts +459 -0
  22. package/package.json +1 -1
  23. package/packages/pi-coding-agent/dist/core/extensions/loader.d.ts.map +1 -1
  24. package/packages/pi-coding-agent/dist/core/extensions/loader.js +13 -0
  25. package/packages/pi-coding-agent/dist/core/extensions/loader.js.map +1 -1
  26. package/packages/pi-coding-agent/src/core/extensions/loader.ts +13 -0
  27. package/src/resources/extensions/bg-shell/process-manager.ts +13 -0
  28. package/src/resources/extensions/gsd/auto-dashboard.ts +186 -65
  29. package/src/resources/extensions/gsd/auto-post-unit.ts +5 -2
  30. package/src/resources/extensions/gsd/commands-prefs-wizard.ts +44 -14
  31. package/src/resources/extensions/gsd/commands-workflow-templates.ts +544 -0
  32. package/src/resources/extensions/gsd/commands.ts +53 -1
  33. package/src/resources/extensions/gsd/prompts/workflow-start.md +28 -0
  34. package/src/resources/extensions/gsd/tests/extension-selector-separator.test.ts +60 -38
  35. package/src/resources/extensions/gsd/tests/workflow-templates.test.ts +173 -0
  36. package/src/resources/extensions/gsd/workflow-templates/bugfix.md +87 -0
  37. package/src/resources/extensions/gsd/workflow-templates/dep-upgrade.md +74 -0
  38. package/src/resources/extensions/gsd/workflow-templates/full-project.md +41 -0
  39. package/src/resources/extensions/gsd/workflow-templates/hotfix.md +45 -0
  40. package/src/resources/extensions/gsd/workflow-templates/refactor.md +83 -0
  41. package/src/resources/extensions/gsd/workflow-templates/registry.json +85 -0
  42. package/src/resources/extensions/gsd/workflow-templates/security-audit.md +73 -0
  43. package/src/resources/extensions/gsd/workflow-templates/small-feature.md +81 -0
  44. package/src/resources/extensions/gsd/workflow-templates/spike.md +69 -0
  45. package/src/resources/extensions/gsd/workflow-templates.ts +241 -0
  46. package/src/resources/extensions/mcp-client/index.ts +459 -0
  47. package/dist/resources/extensions/mcporter/index.ts +0 -525
  48. package/src/resources/extensions/mcporter/index.ts +0 -525
@@ -0,0 +1,83 @@
1
+ # Refactor / Migration Workflow
2
+
3
+ <template_meta>
4
+ name: refactor
5
+ version: 1
6
+ requires_project: false
7
+ artifact_dir: .gsd/workflows/refactors/
8
+ </template_meta>
9
+
10
+ <purpose>
11
+ Systematic code transformation with inventory-driven planning. Designed for
12
+ renames, restructures, pattern migrations, and API modernization. Executes in
13
+ waves to minimize risk and enable incremental verification.
14
+ </purpose>
15
+
16
+ <phases>
17
+ 1. inventory — Catalog everything that needs to change
18
+ 2. plan — Group changes into safe waves
19
+ 3. migrate — Execute waves with verification between each
20
+ 4. verify — Full regression testing and cleanup
21
+ </phases>
22
+
23
+ <process>
24
+
25
+ ## Phase 1: Inventory
26
+
27
+ **Goal:** Know the full scope before changing anything.
28
+
29
+ 1. **Scan the codebase:** Find all instances of what needs to change
30
+ - Files, functions, types, imports, tests, docs, config
31
+ - Use grep/glob to be exhaustive — don't rely on memory
32
+ 2. **Categorize:** Group by type (source, test, config, docs)
33
+ 3. **Identify dependencies:** What order must changes happen in?
34
+ 4. **Produce:** Write `INVENTORY.md` with:
35
+ - Complete list of files/locations that need changes
36
+ - Dependency relationships
37
+ - Estimated scope (number of files, lines affected)
38
+
39
+ 5. **Gate:** Review inventory with user. Confirm nothing is missing.
40
+
41
+ ## Phase 2: Plan
42
+
43
+ **Goal:** Break the migration into safe, independently-verifiable waves.
44
+
45
+ 1. **Define waves:** Group related changes so each wave:
46
+ - Leaves the codebase in a working state
47
+ - Can be committed and tested independently
48
+ - Handles dependencies (change the definition before the consumers)
49
+ 2. **Typical wave structure:**
50
+ - Wave 1: Types/interfaces
51
+ - Wave 2: Core implementation
52
+ - Wave 3: Consumers/callers
53
+ - Wave 4: Tests
54
+ - Wave 5: Documentation and config
55
+ 3. **Produce:** Write `PLAN.md` with waves and per-wave file lists
56
+
57
+ 4. **Gate:** Confirm plan with user.
58
+
59
+ ## Phase 3: Migrate
60
+
61
+ **Goal:** Execute waves one at a time with verification between each.
62
+
63
+ 1. For each wave:
64
+ - Make the changes
65
+ - Run tests (at minimum, the build must pass)
66
+ - Commit: `refactor(<scope>): wave N — <description>`
67
+ 2. If a wave introduces failures, fix them before moving to the next wave
68
+ 3. If unexpected scope is discovered, update the inventory and plan
69
+
70
+ ## Phase 4: Verify
71
+
72
+ **Goal:** Ensure the full refactor is complete and clean.
73
+
74
+ 1. Run the complete test suite
75
+ 2. Run the build
76
+ 3. Run the linter — fix any new warnings
77
+ 4. Search for any remnants of the old pattern (grep for old names/patterns)
78
+ 5. **Produce:** Write `SUMMARY.md` with:
79
+ - What was changed and why
80
+ - Files modified (count and list)
81
+ - Any remaining follow-up items
82
+
83
+ </process>
@@ -0,0 +1,85 @@
1
+ {
2
+ "version": 1,
3
+ "templates": {
4
+ "full-project": {
5
+ "name": "Full Project",
6
+ "description": "Complete GSD workflow with roadmap, milestones, slices, and full ceremony",
7
+ "file": "full-project.md",
8
+ "phases": ["init", "discuss", "plan", "execute", "verify"],
9
+ "triggers": ["new project", "greenfield", "from scratch", "build an app", "create a new"],
10
+ "artifact_dir": ".gsd/",
11
+ "estimated_complexity": "high",
12
+ "requires_project": true
13
+ },
14
+ "bugfix": {
15
+ "name": "Bug Fix",
16
+ "description": "Triage, reproduce, fix, test, and ship a bug fix",
17
+ "file": "bugfix.md",
18
+ "phases": ["triage", "fix", "verify", "ship"],
19
+ "triggers": ["bug", "issue", "fix", "broken", "regression", "error", "crash", "failing", "github.com/*/issues/*"],
20
+ "artifact_dir": ".gsd/workflows/bugfixes/",
21
+ "estimated_complexity": "low",
22
+ "requires_project": false
23
+ },
24
+ "small-feature": {
25
+ "name": "Small Feature",
26
+ "description": "Lightweight feature development with optional discussion and research",
27
+ "file": "small-feature.md",
28
+ "phases": ["scope", "plan", "implement", "verify"],
29
+ "triggers": ["add", "feature", "implement", "build", "create", "new command", "new endpoint"],
30
+ "artifact_dir": ".gsd/workflows/features/",
31
+ "estimated_complexity": "medium",
32
+ "requires_project": false
33
+ },
34
+ "refactor": {
35
+ "name": "Refactor / Migration",
36
+ "description": "Systematic code transformation with inventory and wave-based execution",
37
+ "file": "refactor.md",
38
+ "phases": ["inventory", "plan", "migrate", "verify"],
39
+ "triggers": ["refactor", "migrate", "rename", "restructure", "move", "reorganize", "clean up"],
40
+ "artifact_dir": ".gsd/workflows/refactors/",
41
+ "estimated_complexity": "medium",
42
+ "requires_project": false
43
+ },
44
+ "spike": {
45
+ "name": "Research Spike",
46
+ "description": "Investigate a question, prototype, and document findings",
47
+ "file": "spike.md",
48
+ "phases": ["scope", "research", "synthesize"],
49
+ "triggers": ["research", "investigate", "explore", "spike", "compare", "evaluate", "should we", "what if", "how does"],
50
+ "artifact_dir": ".gsd/workflows/spikes/",
51
+ "estimated_complexity": "low",
52
+ "requires_project": false
53
+ },
54
+ "hotfix": {
55
+ "name": "Hotfix",
56
+ "description": "Minimal ceremony: fix the thing, test it, ship it",
57
+ "file": "hotfix.md",
58
+ "phases": ["fix", "ship"],
59
+ "triggers": ["hotfix", "urgent", "critical", "asap", "production down", "p0"],
60
+ "artifact_dir": null,
61
+ "estimated_complexity": "minimal",
62
+ "requires_project": false
63
+ },
64
+ "security-audit": {
65
+ "name": "Security Audit",
66
+ "description": "Scan for vulnerabilities, triage findings, remediate, and verify",
67
+ "file": "security-audit.md",
68
+ "phases": ["scan", "triage", "remediate", "re-scan"],
69
+ "triggers": ["security", "audit", "vulnerability", "owasp", "cve", "penetration", "hardening"],
70
+ "artifact_dir": ".gsd/workflows/audits/",
71
+ "estimated_complexity": "medium",
72
+ "requires_project": false
73
+ },
74
+ "dep-upgrade": {
75
+ "name": "Dependency Upgrade",
76
+ "description": "Assess impact, upgrade dependencies, fix breaking changes",
77
+ "file": "dep-upgrade.md",
78
+ "phases": ["assess", "upgrade", "fix", "verify"],
79
+ "triggers": ["upgrade", "update", "dependency", "deps", "bump", "outdated", "npm update", "renovate"],
80
+ "artifact_dir": ".gsd/workflows/upgrades/",
81
+ "estimated_complexity": "medium",
82
+ "requires_project": false
83
+ }
84
+ }
85
+ }
@@ -0,0 +1,73 @@
1
+ # Security Audit Workflow
2
+
3
+ <template_meta>
4
+ name: security-audit
5
+ version: 1
6
+ requires_project: false
7
+ artifact_dir: .gsd/workflows/audits/
8
+ </template_meta>
9
+
10
+ <purpose>
11
+ Systematic security review of the codebase. Scan for vulnerabilities, triage
12
+ findings by severity, remediate issues, and verify fixes. Covers OWASP Top 10,
13
+ dependency vulnerabilities, and project-specific security concerns.
14
+ </purpose>
15
+
16
+ <phases>
17
+ 1. scan — Identify potential vulnerabilities
18
+ 2. triage — Prioritize findings by severity and exploitability
19
+ 3. remediate — Fix critical and high-severity issues
20
+ 4. re-scan — Verify fixes and document remaining items
21
+ </phases>
22
+
23
+ <process>
24
+
25
+ ## Phase 1: Scan
26
+
27
+ **Goal:** Identify potential security issues across the codebase.
28
+
29
+ 1. **Dependency audit:** Run `npm audit` / `pip audit` / equivalent
30
+ 2. **Code review for common vulnerabilities:**
31
+ - Injection (SQL, command, XSS)
32
+ - Authentication/authorization flaws
33
+ - Sensitive data exposure (hardcoded secrets, logs)
34
+ - Insecure configuration
35
+ - Missing input validation at boundaries
36
+ 3. **Check security headers and CORS** (if web application)
37
+ 4. **Review secrets management:** .env files, config, environment variables
38
+ 5. **Produce:** Write `SCAN-RESULTS.md` with all findings
39
+
40
+ ## Phase 2: Triage
41
+
42
+ **Goal:** Prioritize what to fix now vs later.
43
+
44
+ 1. **Rate each finding:**
45
+ - Critical: exploitable, high impact, fix immediately
46
+ - High: likely exploitable, fix in this workflow
47
+ - Medium: lower risk, fix if time allows
48
+ - Low: informational, document for later
49
+ 2. **Assess exploitability:** Is this theoretical or practically exploitable?
50
+ 3. **Produce:** Update `SCAN-RESULTS.md` with severity ratings and triage decisions
51
+
52
+ 4. **Gate:** Review triage with user. Agree on what to remediate now.
53
+
54
+ ## Phase 3: Remediate
55
+
56
+ **Goal:** Fix critical and high-severity issues.
57
+
58
+ 1. Fix each issue with proper testing
59
+ 2. Commit each fix individually: `fix(security): <description>`
60
+ 3. Don't introduce new functionality — security fixes only
61
+
62
+ ## Phase 4: Re-scan
63
+
64
+ **Goal:** Verify fixes and document the final state.
65
+
66
+ 1. Re-run the scans from Phase 1
67
+ 2. Verify all targeted issues are resolved
68
+ 3. **Produce:** Write `AUDIT-REPORT.md` with:
69
+ - Summary of findings and fixes
70
+ - Remaining medium/low items for future attention
71
+ - Recommendations for ongoing security practices
72
+
73
+ </process>
@@ -0,0 +1,81 @@
1
+ # Small Feature Workflow
2
+
3
+ <template_meta>
4
+ name: small-feature
5
+ version: 1
6
+ requires_project: false
7
+ artifact_dir: .gsd/workflows/features/
8
+ </template_meta>
9
+
10
+ <purpose>
11
+ Build a small-to-medium feature with lightweight planning. Designed for work that
12
+ needs more structure than /gsd quick but doesn't warrant full milestone ceremony.
13
+ Typical scope: a new command, endpoint, component, or module.
14
+ </purpose>
15
+
16
+ <phases>
17
+ 1. scope — Define what we're building and confirm boundaries
18
+ 2. plan — Break into 2-5 implementable tasks
19
+ 3. implement — Execute the plan with atomic commits
20
+ 4. verify — Run tests, build, and validate
21
+ </phases>
22
+
23
+ <process>
24
+
25
+ ## Phase 1: Scope
26
+
27
+ **Goal:** Align on what to build and what's out of scope.
28
+
29
+ 1. **Understand the request:** Clarify the feature's purpose and user-facing behavior
30
+ 2. **Identify gray areas:** Surface 3-4 design decisions that need answers:
31
+ - API shape / interface design
32
+ - Where in the codebase this fits
33
+ - What existing patterns to follow
34
+ - Edge cases to handle (or explicitly skip)
35
+ 3. **Define boundaries:** What's in scope vs out of scope for this workflow
36
+ 4. **Produce:** Write a brief `CONTEXT.md` in the artifact directory with:
37
+ - Feature description
38
+ - Key decisions made
39
+ - Scope boundaries
40
+
41
+ 5. **Gate:** Confirm scope with user before planning.
42
+
43
+ ## Phase 2: Plan
44
+
45
+ **Goal:** Create a clear, executable plan.
46
+
47
+ 1. **Research (if needed):** Read relevant existing code to understand patterns
48
+ 2. **Break into tasks:** 2-5 tasks, each independently committable:
49
+ - Each task should take ~10-30 minutes of AI work
50
+ - Include file paths and specific changes
51
+ - Include verification steps per task
52
+ 3. **Produce:** Write `PLAN.md` in the artifact directory
53
+
54
+ 4. **Gate:** Present plan to user for approval. Adjust if needed.
55
+
56
+ ## Phase 3: Implement
57
+
58
+ **Goal:** Build the feature following the plan.
59
+
60
+ 1. Execute tasks in order
61
+ 2. After each task:
62
+ - Verify the specific task's acceptance criteria
63
+ - Commit with message: `feat(<scope>): <description>`
64
+ 3. If a task reveals the plan needs adjustment, note the deviation and adapt
65
+ 4. Run incremental tests as you go (don't wait until the end)
66
+
67
+ ## Phase 4: Verify
68
+
69
+ **Goal:** Ensure everything works together.
70
+
71
+ 1. Run the full test suite
72
+ 2. Run the build
73
+ 3. Run the linter
74
+ 4. Manual smoke check if applicable
75
+ 5. **Produce:** Write a brief `SUMMARY.md` with:
76
+ - What was built
77
+ - Files changed
78
+ - How to test/use the feature
79
+ 6. Present summary to user
80
+
81
+ </process>
@@ -0,0 +1,69 @@
1
+ # Research Spike Workflow
2
+
3
+ <template_meta>
4
+ name: spike
5
+ version: 1
6
+ requires_project: false
7
+ artifact_dir: .gsd/workflows/spikes/
8
+ </template_meta>
9
+
10
+ <purpose>
11
+ Investigate a question, evaluate options, prototype if needed, and produce a
12
+ clear recommendation. No production code is shipped — the output is knowledge.
13
+ Use for: technology evaluation, architecture decisions, "should we X?" questions.
14
+ </purpose>
15
+
16
+ <phases>
17
+ 1. scope — Define the question and success criteria
18
+ 2. research — Investigate from multiple angles
19
+ 3. synthesize — Combine findings into a recommendation
20
+ </phases>
21
+
22
+ <process>
23
+
24
+ ## Phase 1: Scope
25
+
26
+ **Goal:** Define exactly what we're investigating and what a good answer looks like.
27
+
28
+ 1. **Frame the question:** What specific question(s) need answering?
29
+ 2. **Define success criteria:** What would a useful answer include?
30
+ - Comparison criteria (performance, DX, maintenance, ecosystem, etc.)
31
+ - Constraints (must integrate with X, must support Y)
32
+ - Decision format (go/no-go, pick from options, tradeoff matrix)
33
+ 3. **Identify research angles:** 2-3 distinct approaches to investigate:
34
+ - e.g., "evaluate library A", "evaluate library B", "evaluate building our own"
35
+ - e.g., "performance implications", "DX implications", "migration path"
36
+ 4. **Produce:** Write `SCOPE.md` in the artifact directory
37
+
38
+ 5. **Gate:** Confirm scope and research angles with user.
39
+
40
+ ## Phase 2: Research
41
+
42
+ **Goal:** Investigate each angle thoroughly.
43
+
44
+ 1. For each research angle:
45
+ - Search for relevant documentation, benchmarks, comparisons
46
+ - Read relevant source code in the project
47
+ - Build small prototypes or proof-of-concepts if needed
48
+ - Note pros, cons, risks, and unknowns
49
+ 2. **Produce:** Write a research doc per angle in `research/` subdirectory:
50
+ - `research/ANGLE-1.md`, `research/ANGLE-2.md`, etc.
51
+ - Each doc: findings, evidence, pros/cons, confidence level
52
+
53
+ ## Phase 3: Synthesize
54
+
55
+ **Goal:** Combine findings into a clear recommendation.
56
+
57
+ 1. **Compare across angles:** Build a comparison matrix or summary table
58
+ 2. **Make a recommendation:** Based on the evidence, what should we do?
59
+ - Primary recommendation with rationale
60
+ - Alternative if the primary doesn't work out
61
+ - What would change the recommendation (risk factors)
62
+ 3. **Produce:** Write `RECOMMENDATION.md` with:
63
+ - Executive summary (1-2 paragraphs)
64
+ - Comparison matrix
65
+ - Recommendation with rationale
66
+ - Next steps if the recommendation is accepted
67
+ 4. **Present** the recommendation to the user for discussion
68
+
69
+ </process>
@@ -0,0 +1,241 @@
1
+ /**
2
+ * GSD Workflow Templates — Registry & Resolution
3
+ *
4
+ * Loads the workflow template registry and resolves templates by name,
5
+ * alias, or trigger-keyword matching against user input.
6
+ */
7
+
8
+ import { readFileSync, existsSync } from "node:fs";
9
+ import { join, dirname } from "node:path";
10
+ import { fileURLToPath } from "node:url";
11
+
12
+ const __extensionDir = dirname(fileURLToPath(import.meta.url));
13
+ const registryPath = join(__extensionDir, "workflow-templates", "registry.json");
14
+
15
+ // ─── Types ───────────────────────────────────────────────────────────────────
16
+
17
+ export interface TemplateEntry {
18
+ name: string;
19
+ description: string;
20
+ file: string;
21
+ phases: string[];
22
+ triggers: string[];
23
+ artifact_dir: string | null;
24
+ estimated_complexity: string;
25
+ requires_project: boolean;
26
+ }
27
+
28
+ export interface TemplateRegistry {
29
+ version: number;
30
+ templates: Record<string, TemplateEntry>;
31
+ }
32
+
33
+ export interface TemplateMatch {
34
+ id: string;
35
+ template: TemplateEntry;
36
+ confidence: "exact" | "high" | "medium" | "low";
37
+ matchedTrigger?: string;
38
+ }
39
+
40
+ // ─── Registry Cache ──────────────────────────────────────────────────────────
41
+
42
+ let cachedRegistry: TemplateRegistry | null = null;
43
+
44
+ /**
45
+ * Load and cache the workflow template registry.
46
+ */
47
+ export function loadRegistry(): TemplateRegistry {
48
+ if (cachedRegistry) return cachedRegistry;
49
+
50
+ const content = readFileSync(registryPath, "utf-8");
51
+ cachedRegistry = JSON.parse(content) as TemplateRegistry;
52
+ return cachedRegistry;
53
+ }
54
+
55
+ /**
56
+ * Resolve a template by exact name or alias.
57
+ * Returns null if no match found.
58
+ */
59
+ export function resolveByName(nameOrAlias: string): TemplateMatch | null {
60
+ const registry = loadRegistry();
61
+ const normalized = nameOrAlias.toLowerCase().trim();
62
+
63
+ // Exact key match
64
+ if (registry.templates[normalized]) {
65
+ return {
66
+ id: normalized,
67
+ template: registry.templates[normalized],
68
+ confidence: "exact",
69
+ };
70
+ }
71
+
72
+ // Match by template name (case-insensitive)
73
+ for (const [id, entry] of Object.entries(registry.templates)) {
74
+ if (entry.name.toLowerCase() === normalized) {
75
+ return { id, template: entry, confidence: "exact" };
76
+ }
77
+ }
78
+
79
+ // Fuzzy: prefix match on id
80
+ for (const [id, entry] of Object.entries(registry.templates)) {
81
+ if (id.startsWith(normalized) || normalized.startsWith(id)) {
82
+ return { id, template: entry, confidence: "high" };
83
+ }
84
+ }
85
+
86
+ // Common aliases
87
+ const aliases: Record<string, string> = {
88
+ "bug": "bugfix",
89
+ "fix": "bugfix",
90
+ "feature": "small-feature",
91
+ "feat": "small-feature",
92
+ "research": "spike",
93
+ "investigate": "spike",
94
+ "hot": "hotfix",
95
+ "urgent": "hotfix",
96
+ "security": "security-audit",
97
+ "audit": "security-audit",
98
+ "upgrade": "dep-upgrade",
99
+ "deps": "dep-upgrade",
100
+ "update-deps": "dep-upgrade",
101
+ "migration": "refactor",
102
+ "project": "full-project",
103
+ "full": "full-project",
104
+ };
105
+
106
+ const aliasMatch = aliases[normalized];
107
+ if (aliasMatch && registry.templates[aliasMatch]) {
108
+ return {
109
+ id: aliasMatch,
110
+ template: registry.templates[aliasMatch],
111
+ confidence: "high",
112
+ };
113
+ }
114
+
115
+ return null;
116
+ }
117
+
118
+ /**
119
+ * Auto-detect the best template based on user description text.
120
+ * Returns ranked matches sorted by confidence.
121
+ */
122
+ export function autoDetect(description: string): TemplateMatch[] {
123
+ const registry = loadRegistry();
124
+ const lower = description.toLowerCase();
125
+ const words = lower.split(/\s+/);
126
+ const matches: TemplateMatch[] = [];
127
+
128
+ for (const [id, entry] of Object.entries(registry.templates)) {
129
+ let bestScore = 0;
130
+ let bestTrigger = "";
131
+
132
+ for (const trigger of entry.triggers) {
133
+ const triggerLower = trigger.toLowerCase();
134
+
135
+ // Exact phrase match in description
136
+ if (lower.includes(triggerLower)) {
137
+ const score = triggerLower.split(/\s+/).length * 2; // multi-word triggers score higher
138
+ if (score > bestScore) {
139
+ bestScore = score;
140
+ bestTrigger = trigger;
141
+ }
142
+ continue;
143
+ }
144
+
145
+ // Single-word trigger match against description words
146
+ if (!triggerLower.includes(" ") && words.includes(triggerLower)) {
147
+ if (1 > bestScore) {
148
+ bestScore = 1;
149
+ bestTrigger = trigger;
150
+ }
151
+ }
152
+ }
153
+
154
+ if (bestScore > 0) {
155
+ const confidence = bestScore >= 4 ? "high" : bestScore >= 2 ? "medium" : "low";
156
+ matches.push({
157
+ id,
158
+ template: entry,
159
+ confidence,
160
+ matchedTrigger: bestTrigger,
161
+ });
162
+ }
163
+ }
164
+
165
+ // Sort by confidence (high > medium > low), then alphabetically
166
+ const order = { exact: 0, high: 1, medium: 2, low: 3 };
167
+ matches.sort((a, b) => order[a.confidence] - order[b.confidence] || a.id.localeCompare(b.id));
168
+
169
+ return matches;
170
+ }
171
+
172
+ /**
173
+ * List all templates as formatted text for display.
174
+ */
175
+ export function listTemplates(): string {
176
+ const registry = loadRegistry();
177
+ const lines: string[] = ["Workflow Templates\n"];
178
+
179
+ for (const [id, entry] of Object.entries(registry.templates)) {
180
+ const phases = entry.phases.join(" → ");
181
+ const complexity = entry.estimated_complexity;
182
+ lines.push(` ${id.padEnd(16)} ${entry.name}`);
183
+ lines.push(` ${"".padEnd(16)} ${entry.description}`);
184
+ lines.push(` ${"".padEnd(16)} Phases: ${phases} | Complexity: ${complexity}`);
185
+ lines.push("");
186
+ }
187
+
188
+ lines.push("Usage: /gsd start <template> [description]");
189
+ lines.push(" /gsd templates info <name>");
190
+
191
+ return lines.join("\n");
192
+ }
193
+
194
+ /**
195
+ * Get detailed info about a specific template.
196
+ */
197
+ export function getTemplateInfo(name: string): string | null {
198
+ const match = resolveByName(name);
199
+ if (!match) return null;
200
+
201
+ const { id, template: t } = match;
202
+ const lines = [
203
+ `Template: ${t.name} (${id})`,
204
+ "",
205
+ `Description: ${t.description}`,
206
+ `Complexity: ${t.estimated_complexity}`,
207
+ `Requires .gsd/: ${t.requires_project ? "yes" : "no"}`,
208
+ "",
209
+ "Phases:",
210
+ ...t.phases.map((p, i) => ` ${i + 1}. ${p}`),
211
+ "",
212
+ "Triggers:",
213
+ ` ${t.triggers.join(", ")}`,
214
+ ];
215
+
216
+ if (t.artifact_dir) {
217
+ lines.push("", `Artifacts: ${t.artifact_dir}`);
218
+ }
219
+
220
+ const templateFilePath = join(__extensionDir, "workflow-templates", t.file);
221
+ if (existsSync(templateFilePath)) {
222
+ lines.push("", "Template file: loaded");
223
+ } else {
224
+ lines.push("", "Template file: not yet created");
225
+ }
226
+
227
+ return lines.join("\n");
228
+ }
229
+
230
+ /**
231
+ * Load the raw content of a workflow template .md file.
232
+ */
233
+ export function loadWorkflowTemplate(templateId: string): string | null {
234
+ const match = resolveByName(templateId);
235
+ if (!match) return null;
236
+
237
+ const filePath = join(__extensionDir, "workflow-templates", match.template.file);
238
+ if (!existsSync(filePath)) return null;
239
+
240
+ return readFileSync(filePath, "utf-8");
241
+ }