forge-workflow 0.0.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.
Files changed (105) hide show
  1. package/.claude/commands/dev.md +314 -0
  2. package/.claude/commands/plan.md +389 -0
  3. package/.claude/commands/premerge.md +179 -0
  4. package/.claude/commands/research.md +42 -0
  5. package/.claude/commands/review.md +442 -0
  6. package/.claude/commands/rollback.md +721 -0
  7. package/.claude/commands/ship.md +134 -0
  8. package/.claude/commands/sonarcloud.md +152 -0
  9. package/.claude/commands/status.md +77 -0
  10. package/.claude/commands/validate.md +237 -0
  11. package/.claude/commands/verify.md +221 -0
  12. package/.claude/rules/greptile-review-process.md +285 -0
  13. package/.claude/rules/workflow.md +105 -0
  14. package/.claude/scripts/greptile-resolve.sh +526 -0
  15. package/.claude/scripts/load-env.sh +32 -0
  16. package/.forge/hooks/check-tdd.js +240 -0
  17. package/.github/PLUGIN_TEMPLATE.json +32 -0
  18. package/.mcp.json.example +12 -0
  19. package/AGENTS.md +169 -0
  20. package/CLAUDE.md +99 -0
  21. package/LICENSE +21 -0
  22. package/README.md +414 -0
  23. package/bin/forge-cmd.js +313 -0
  24. package/bin/forge-validate.js +303 -0
  25. package/bin/forge.js +4228 -0
  26. package/docs/AGENT_INSTALL_PROMPT.md +342 -0
  27. package/docs/ENHANCED_ONBOARDING.md +602 -0
  28. package/docs/EXAMPLES.md +482 -0
  29. package/docs/GREPTILE_SETUP.md +400 -0
  30. package/docs/MANUAL_REVIEW_GUIDE.md +106 -0
  31. package/docs/ROADMAP.md +359 -0
  32. package/docs/SETUP.md +632 -0
  33. package/docs/TOOLCHAIN.md +849 -0
  34. package/docs/VALIDATION.md +363 -0
  35. package/docs/WORKFLOW.md +400 -0
  36. package/docs/planning/PROGRESS.md +396 -0
  37. package/docs/plans/.gitkeep +0 -0
  38. package/docs/plans/2026-02-27-forge-test-suite-v2-decisions.md +21 -0
  39. package/docs/plans/2026-02-27-forge-test-suite-v2-design.md +362 -0
  40. package/docs/plans/2026-02-27-forge-test-suite-v2-tasks.md +343 -0
  41. package/docs/plans/2026-03-02-superpowers-gaps-decisions.md +26 -0
  42. package/docs/plans/2026-03-02-superpowers-gaps-design.md +239 -0
  43. package/docs/plans/2026-03-02-superpowers-gaps-tasks.md +260 -0
  44. package/docs/plans/2026-03-04-agent-command-parity-design.md +163 -0
  45. package/docs/plans/2026-03-04-verify-worktree-cleanup-decisions.md +7 -0
  46. package/docs/plans/2026-03-04-verify-worktree-cleanup-design.md +165 -0
  47. package/docs/plans/2026-03-05-forge-uto-decisions.md +6 -0
  48. package/docs/plans/2026-03-05-forge-uto-design.md +116 -0
  49. package/docs/plans/2026-03-05-forge-uto-tasks.md +244 -0
  50. package/docs/plans/2026-03-10-command-creator-and-eval-decisions.md +52 -0
  51. package/docs/plans/2026-03-10-command-creator-and-eval-design.md +350 -0
  52. package/docs/plans/2026-03-10-command-creator-and-eval-tasks.md +426 -0
  53. package/docs/plans/2026-03-10-stale-workflow-refs-decisions.md +8 -0
  54. package/docs/plans/2026-03-10-stale-workflow-refs-design.md +80 -0
  55. package/docs/plans/2026-03-10-stale-workflow-refs-tasks.md +90 -0
  56. package/docs/plans/2026-03-14-beads-plan-context-decisions.md +9 -0
  57. package/docs/plans/2026-03-14-beads-plan-context-design.md +171 -0
  58. package/docs/plans/2026-03-14-beads-plan-context-tasks.md +160 -0
  59. package/docs/plans/2026-03-14-skill-eval-loop-decisions.md +33 -0
  60. package/docs/plans/2026-03-14-skill-eval-loop-design.md +118 -0
  61. package/docs/plans/2026-03-14-skill-eval-loop-results.md +78 -0
  62. package/docs/plans/2026-03-14-skill-eval-loop-tasks.md +160 -0
  63. package/docs/plans/2026-03-15-agent-command-parity-v2-decisions.md +11 -0
  64. package/docs/plans/2026-03-15-agent-command-parity-v2-design.md +145 -0
  65. package/docs/plans/2026-03-15-agent-command-parity-v2-tasks.md +211 -0
  66. package/docs/research/TEMPLATE.md +292 -0
  67. package/docs/research/advanced-testing.md +297 -0
  68. package/docs/research/agent-permissions.md +167 -0
  69. package/docs/research/dependency-chain.md +328 -0
  70. package/docs/research/forge-workflow-v2.md +550 -0
  71. package/docs/research/plugin-architecture.md +772 -0
  72. package/docs/research/pr4-cli-automation.md +326 -0
  73. package/docs/research/premerge-verify-restructure.md +205 -0
  74. package/docs/research/skills-restructure.md +508 -0
  75. package/docs/research/sonarcloud-perfection-plan.md +166 -0
  76. package/docs/research/sonarcloud-quality-gate.md +184 -0
  77. package/docs/research/superpowers-integration.md +403 -0
  78. package/docs/research/superpowers.md +319 -0
  79. package/docs/research/test-environment.md +519 -0
  80. package/install.sh +1062 -0
  81. package/lefthook.yml +39 -0
  82. package/lib/agents/README.md +198 -0
  83. package/lib/agents/claude.plugin.json +28 -0
  84. package/lib/agents/cline.plugin.json +22 -0
  85. package/lib/agents/codex.plugin.json +19 -0
  86. package/lib/agents/copilot.plugin.json +24 -0
  87. package/lib/agents/cursor.plugin.json +25 -0
  88. package/lib/agents/kilocode.plugin.json +22 -0
  89. package/lib/agents/opencode.plugin.json +20 -0
  90. package/lib/agents/roo.plugin.json +23 -0
  91. package/lib/agents-config.js +2112 -0
  92. package/lib/commands/dev.js +513 -0
  93. package/lib/commands/plan.js +696 -0
  94. package/lib/commands/recommend.js +119 -0
  95. package/lib/commands/ship.js +377 -0
  96. package/lib/commands/status.js +378 -0
  97. package/lib/commands/validate.js +602 -0
  98. package/lib/context-merge.js +359 -0
  99. package/lib/plugin-catalog.js +360 -0
  100. package/lib/plugin-manager.js +166 -0
  101. package/lib/plugin-recommender.js +141 -0
  102. package/lib/project-discovery.js +491 -0
  103. package/lib/setup.js +118 -0
  104. package/lib/workflow-profiles.js +203 -0
  105. package/package.json +115 -0
@@ -0,0 +1,360 @@
1
+ /**
2
+ * Plugin Catalog
3
+ *
4
+ * Static, frozen catalog of tools for the Forge workflow.
5
+ * Read-only data — no installations, no side effects.
6
+ */
7
+
8
+ const TIERS = Object.freeze({
9
+ FREE: 'free',
10
+ FREE_PUBLIC: 'free-public',
11
+ FREE_LIMITED: 'free-limited',
12
+ PAID: 'paid',
13
+ });
14
+
15
+ const TOOL_TYPES = Object.freeze({
16
+ CLI: 'cli',
17
+ SKILL: 'skill',
18
+ MCP: 'mcp',
19
+ CONFIG: 'config',
20
+ LSP: 'lsp',
21
+ });
22
+
23
+ const STAGES = Object.freeze({
24
+ RESEARCH: 'research',
25
+ PLAN: 'plan',
26
+ DEV: 'dev',
27
+ CHECK: 'check',
28
+ SHIP: 'ship',
29
+ REVIEW: 'review',
30
+ MERGE: 'merge',
31
+ });
32
+
33
+ const BUDGET_MODES = Object.freeze({
34
+ free: { label: 'Free only', includes: ['free'] },
35
+ 'open-source': { label: 'Open source', includes: ['free', 'free-public'] },
36
+ startup: { label: 'Startup', includes: ['free', 'free-public', 'free-limited'] },
37
+ professional: { label: 'Professional', includes: ['free', 'free-public', 'free-limited', 'paid'] },
38
+ custom: { label: 'Custom', includes: [] },
39
+ });
40
+
41
+ const PREREQUISITES = Object.freeze({
42
+ node: { check: 'node --version', installUrl: 'https://nodejs.org' },
43
+ git: { check: 'git --version', installUrl: 'https://git-scm.com' },
44
+ gh: { check: 'gh --version', installUrl: 'https://cli.github.com' },
45
+ bun: { check: 'bun --version', installUrl: 'https://bun.sh' },
46
+ jq: { check: 'jq --version', installUrl: 'https://jqlang.github.io/jq/download/' },
47
+ go: { check: 'go version', installUrl: 'https://go.dev/dl/' },
48
+ curl: { check: 'curl --version', installUrl: null },
49
+ 'parallel-cli': {
50
+ check: 'parallel-cli --version',
51
+ installUrl: 'https://parallel.ai/install.sh',
52
+ },
53
+ });
54
+
55
+ const CATALOG = Object.freeze({
56
+ // ── Research ──
57
+ 'context7-mcp': {
58
+ name: 'Context7',
59
+ type: 'mcp',
60
+ tier: 'free',
61
+ stage: 'research',
62
+ description: 'Up-to-date library documentation via MCP',
63
+ detectWhen: [],
64
+ install: { method: 'add-mcp', cmd: 'bunx add-mcp context7' },
65
+ mcpJustified: true,
66
+ },
67
+ 'grep-app-mcp': {
68
+ name: 'grep.app',
69
+ type: 'mcp',
70
+ tier: 'free',
71
+ stage: 'research',
72
+ description: 'Search 1M+ GitHub repos for real-world code examples',
73
+ detectWhen: [],
74
+ install: { method: 'add-mcp', cmd: 'bunx add-mcp grep-app' },
75
+ mcpJustified: true,
76
+ },
77
+
78
+ 'parallel-deep-research': {
79
+ name: 'Parallel Deep Research',
80
+ type: 'skill',
81
+ tier: 'paid',
82
+ stage: 'research',
83
+ description: 'Comprehensive research reports via Parallel AI pro/ultra processors (3-25 min)',
84
+ detectWhen: [],
85
+ install: {
86
+ method: 'skills',
87
+ cmd: 'bunx skills add parallel-web/parallel-agent-skills --skill parallel-deep-research',
88
+ cmdCurl: 'bunx skills add harshanandak/forge --skill parallel-deep-research',
89
+ },
90
+ prerequisites: ['parallel-cli'],
91
+ alternatives: [{ tool: 'WebSearch', tier: 'free', tradeoff: 'Shallow — only a few queries vs deep multi-source synthesis' }],
92
+ },
93
+
94
+ // ── Plan ──
95
+ beads: {
96
+ name: 'Beads',
97
+ type: 'cli',
98
+ tier: 'free',
99
+ stage: 'plan',
100
+ description: 'Git-backed issue tracking',
101
+ detectWhen: [],
102
+ install: { method: 'npm', cmd: 'bun add -g @beads/bd' },
103
+ },
104
+ openspec: {
105
+ name: 'OpenSpec',
106
+ type: 'cli',
107
+ tier: 'free',
108
+ stage: 'plan',
109
+ description: 'Spec-driven development proposals',
110
+ detectWhen: [],
111
+ install: { method: 'npm', cmd: 'bun add -g @fission-ai/openspec' },
112
+ },
113
+
114
+ // ── Dev ──
115
+ 'typescript-lsp': {
116
+ name: 'TypeScript LSP',
117
+ type: 'lsp',
118
+ tier: 'free',
119
+ stage: 'dev',
120
+ description: 'TypeScript language server for IDE integration',
121
+ detectWhen: ['dep:typescript', 'file:tsconfig.json'],
122
+ install: { method: 'lsp', cmd: '.lsp.json config' },
123
+ },
124
+ 'supabase-cli': {
125
+ name: 'Supabase CLI',
126
+ type: 'cli',
127
+ tier: 'free-limited',
128
+ stage: 'dev',
129
+ description: 'Local Supabase development and migrations',
130
+ detectWhen: ['dep:@supabase/supabase-js'],
131
+ install: { method: 'npm', cmd: 'bun add -D supabase', dev: true },
132
+ alternatives: [{ tool: 'postgresql-client', tier: 'free', tradeoff: 'No Supabase-specific features' }],
133
+ },
134
+ 'stripe-cli': {
135
+ name: 'Stripe CLI',
136
+ type: 'cli',
137
+ tier: 'free',
138
+ stage: 'dev',
139
+ description: 'Stripe webhook testing and API interaction',
140
+ detectWhen: ['dep:stripe'],
141
+ install: { method: 'binary', cmd: 'https://stripe.com/docs/stripe-cli' },
142
+ },
143
+ 'vercel-agent-skills': {
144
+ name: 'Vercel Agent Skills',
145
+ type: 'skill',
146
+ tier: 'free',
147
+ stage: 'dev',
148
+ description: 'Vercel deployment and preview management',
149
+ detectWhen: ['dep:next'],
150
+ install: { method: 'skills', cmd: 'bunx skills add vercel-labs/agent-skills' },
151
+ },
152
+
153
+ // ── Check ──
154
+ eslint: {
155
+ name: 'ESLint',
156
+ type: 'cli',
157
+ tier: 'free',
158
+ stage: 'check',
159
+ description: 'JavaScript/TypeScript linting',
160
+ detectWhen: ['file:eslint.config.js', 'dep:eslint'],
161
+ install: { method: 'npm', cmd: 'bun add -D eslint', dev: true },
162
+ },
163
+ biome: {
164
+ name: 'Biome',
165
+ type: 'cli',
166
+ tier: 'free',
167
+ stage: 'check',
168
+ description: 'Fast formatter and linter',
169
+ detectWhen: ['file:biome.json'],
170
+ install: { method: 'npm', cmd: 'bun add -D @biomejs/biome', dev: true },
171
+ },
172
+ prettier: {
173
+ name: 'Prettier',
174
+ type: 'cli',
175
+ tier: 'free',
176
+ stage: 'check',
177
+ description: 'Opinionated code formatter',
178
+ detectWhen: ['file:.prettierrc'],
179
+ install: { method: 'npm', cmd: 'bun add -D prettier', dev: true },
180
+ },
181
+ 'eslint-plugin-security': {
182
+ name: 'ESLint Security Plugin',
183
+ type: 'config',
184
+ tier: 'free',
185
+ stage: 'check',
186
+ description: 'Security-focused ESLint rules',
187
+ detectWhen: ['dep:express', 'dep:fastify'],
188
+ install: { method: 'npm', cmd: 'bun add -D eslint-plugin-security', dev: true },
189
+ },
190
+ 'sonarcloud-analysis': {
191
+ name: 'SonarCloud Analysis',
192
+ type: 'skill',
193
+ tier: 'free-public',
194
+ stage: 'check',
195
+ description: 'Code quality and security analysis via SonarCloud REST API',
196
+ detectWhen: [],
197
+ install: {
198
+ method: 'skills',
199
+ cmd: 'bunx skills add harshanandak/forge --skill sonarcloud-analysis',
200
+ },
201
+ alternatives: [{ tool: 'eslint', tier: 'free', tradeoff: 'Less comprehensive analysis' }],
202
+ },
203
+ 'sonar-scanner': {
204
+ name: 'Sonar Scanner',
205
+ type: 'cli',
206
+ tier: 'free-public',
207
+ stage: 'check',
208
+ description: 'SonarCloud/SonarQube CLI scanner',
209
+ detectWhen: ['file:sonar-project.properties'],
210
+ install: { method: 'npm', cmd: 'bun add -D sonarqube-scanner', dev: true },
211
+ alternatives: [{ tool: 'eslint', tier: 'free', tradeoff: 'No centralized dashboard' }],
212
+ },
213
+ codeql: {
214
+ name: 'CodeQL',
215
+ type: 'cli',
216
+ tier: 'free-public',
217
+ stage: 'check',
218
+ description: 'Semantic code analysis by GitHub',
219
+ detectWhen: [],
220
+ install: { method: 'binary', cmd: 'GitHub-provided (github.com/github/codeql-action)' },
221
+ alternatives: [{ tool: 'eslint-plugin-security', tier: 'free', tradeoff: 'Less deep analysis' }],
222
+ },
223
+ 'npm-audit': {
224
+ name: 'npm audit',
225
+ type: 'cli',
226
+ tier: 'free',
227
+ stage: 'check',
228
+ description: 'Dependency vulnerability scanning',
229
+ detectWhen: [],
230
+ install: { method: 'npm', cmd: 'built-in (bun pm audit)' },
231
+ },
232
+ vitest: {
233
+ name: 'Vitest',
234
+ type: 'cli',
235
+ tier: 'free',
236
+ stage: 'check',
237
+ description: 'Vite-native test runner',
238
+ detectWhen: ['dep:vitest', 'file:vitest.config.ts'],
239
+ install: { method: 'npm', cmd: 'bun add -D vitest', dev: true },
240
+ },
241
+ jest: {
242
+ name: 'Jest',
243
+ type: 'cli',
244
+ tier: 'free',
245
+ stage: 'check',
246
+ description: 'Delightful JavaScript testing',
247
+ detectWhen: ['dep:jest', 'file:jest.config.js'],
248
+ install: { method: 'npm', cmd: 'bun add -D jest', dev: true },
249
+ },
250
+ playwright: {
251
+ name: 'Playwright',
252
+ type: 'cli',
253
+ tier: 'free',
254
+ stage: 'check',
255
+ description: 'End-to-end browser testing',
256
+ detectWhen: ['dep:@playwright/test'],
257
+ install: { method: 'npm', cmd: 'bun add -D @playwright/test', dev: true },
258
+ },
259
+ c8: {
260
+ name: 'c8',
261
+ type: 'cli',
262
+ tier: 'free',
263
+ stage: 'check',
264
+ description: 'Native V8 code coverage',
265
+ detectWhen: [],
266
+ install: { method: 'npm', cmd: 'bun add -D c8', dev: true },
267
+ },
268
+ stryker: {
269
+ name: 'Stryker',
270
+ type: 'cli',
271
+ tier: 'free',
272
+ stage: 'check',
273
+ description: 'Mutation testing for JavaScript',
274
+ detectWhen: [],
275
+ install: { method: 'npm', cmd: 'bun add -D @stryker-mutator/core', dev: true },
276
+ },
277
+ oxlint: {
278
+ name: 'Oxlint',
279
+ type: 'cli',
280
+ tier: 'free',
281
+ stage: 'check',
282
+ description: 'Blazing-fast Rust-based linter',
283
+ detectWhen: [],
284
+ install: { method: 'npm', cmd: 'bun add -D oxlint', dev: true },
285
+ },
286
+
287
+ // ── Ship ──
288
+ 'gh-cli': {
289
+ name: 'GitHub CLI',
290
+ type: 'cli',
291
+ tier: 'free',
292
+ stage: 'ship',
293
+ description: 'GitHub PR and issue management',
294
+ detectWhen: [],
295
+ install: { method: 'binary', cmd: 'https://cli.github.com' },
296
+ prerequisites: ['gh'],
297
+ },
298
+ lefthook: {
299
+ name: 'Lefthook',
300
+ type: 'cli',
301
+ tier: 'free',
302
+ stage: 'ship',
303
+ description: 'Fast git hooks manager',
304
+ detectWhen: [],
305
+ install: { method: 'npm', cmd: 'bun add -D lefthook', dev: true },
306
+ },
307
+
308
+ // ── Review ──
309
+ coderabbit: {
310
+ name: 'CodeRabbit',
311
+ type: 'config',
312
+ tier: 'free-public',
313
+ stage: 'review',
314
+ description: 'AI-powered code review',
315
+ detectWhen: [],
316
+ install: { method: 'config', cmd: 'GitHub App (coderabbit.ai)' },
317
+ alternatives: [{ tool: 'qodo-merge', tier: 'free', tradeoff: 'Self-hosted, more setup' }],
318
+ },
319
+ greptile: {
320
+ name: 'Greptile',
321
+ type: 'config',
322
+ tier: 'paid',
323
+ stage: 'review',
324
+ description: 'AI code review with codebase context',
325
+ detectWhen: [],
326
+ install: { method: 'config', cmd: 'GitHub App (greptile.com)' },
327
+ alternatives: [{ tool: 'coderabbit', tier: 'free-public', tradeoff: 'Less codebase awareness' }],
328
+ },
329
+ 'qodo-merge': {
330
+ name: 'Qodo Merge',
331
+ type: 'cli',
332
+ tier: 'free',
333
+ stage: 'review',
334
+ description: 'AI-assisted code review (self-hosted)',
335
+ detectWhen: [],
336
+ install: { method: 'config', cmd: 'Self-hosted (qodo.ai)' },
337
+ },
338
+
339
+ // ── Merge ──
340
+ changesets: {
341
+ name: 'Changesets',
342
+ type: 'cli',
343
+ tier: 'free',
344
+ stage: 'merge',
345
+ description: 'Versioning and changelog management',
346
+ detectWhen: ['file:package.json'],
347
+ install: { method: 'npm', cmd: 'bun add -D @changesets/cli', dev: true },
348
+ },
349
+ 'release-please': {
350
+ name: 'Release Please',
351
+ type: 'config',
352
+ tier: 'free',
353
+ stage: 'merge',
354
+ description: 'Automated release PRs by Google',
355
+ detectWhen: [],
356
+ install: { method: 'config', cmd: 'GitHub Action (google-github-actions/release-please-action)' },
357
+ },
358
+ });
359
+
360
+ module.exports = { CATALOG, TIERS, TOOL_TYPES, STAGES, BUDGET_MODES, PREREQUISITES };
@@ -0,0 +1,166 @@
1
+ /**
2
+ * Plugin Manager
3
+ *
4
+ * Handles loading, validating, and managing agent plugin JSON files.
5
+ * Provides discoverable plugin architecture for AI coding agents.
6
+ */
7
+
8
+ const fs = require('node:fs');
9
+ const path = require('node:path');
10
+
11
+ class PluginManager {
12
+ constructor() {
13
+ this.plugins = new Map();
14
+ this.loadPlugins();
15
+ }
16
+
17
+ /**
18
+ * Load all plugin files from lib/agents/ directory
19
+ */
20
+ loadPlugins() {
21
+ const pluginDir = path.join(__dirname, 'agents');
22
+
23
+ // Create directory if it doesn't exist (for first-time setup)
24
+ if (!fs.existsSync(pluginDir)) {
25
+ fs.mkdirSync(pluginDir, { recursive: true });
26
+ return;
27
+ }
28
+
29
+ const files = fs.readdirSync(pluginDir)
30
+ .filter(f => f.endsWith('.plugin.json'));
31
+
32
+ files.forEach(file => {
33
+ try {
34
+ const content = fs.readFileSync(path.join(pluginDir, file), 'utf-8');
35
+ const plugin = JSON.parse(content);
36
+ this.validatePlugin(plugin);
37
+
38
+ // Check for duplicate IDs
39
+ if (this.plugins.has(plugin.id)) {
40
+ throw new Error(`Plugin with ID "${plugin.id}" already exists`);
41
+ }
42
+
43
+ this.plugins.set(plugin.id, plugin);
44
+ } catch (error) {
45
+ // Re-throw with file context
46
+ throw new Error(`Failed to load plugin ${file}: ${error.message}`);
47
+ }
48
+ });
49
+ }
50
+
51
+ /**
52
+ * Validate plugin schema
53
+ * @param {Object} plugin - Plugin object to validate
54
+ * @throws {Error} If validation fails
55
+ */
56
+ validatePlugin(plugin) {
57
+ const required = ['id', 'name', 'version', 'directories'];
58
+
59
+ // Check required fields exist
60
+ required.forEach(field => {
61
+ if (!plugin[field]) {
62
+ throw new Error(`Plugin validation failed: missing required field "${field}"`);
63
+ }
64
+ });
65
+
66
+ // Validate field types
67
+ if (typeof plugin.id !== 'string') {
68
+ throw new TypeError('Plugin validation failed: "id" must be a string');
69
+ }
70
+ if (typeof plugin.name !== 'string') {
71
+ throw new TypeError('Plugin validation failed: "name" must be a string');
72
+ }
73
+ if (typeof plugin.version !== 'string') {
74
+ throw new TypeError('Plugin validation failed: "version" must be a string');
75
+ }
76
+ if (typeof plugin.directories !== 'object' || Array.isArray(plugin.directories)) {
77
+ throw new TypeError('Plugin validation failed: "directories" must be an object');
78
+ }
79
+
80
+ // Validate optional fields if present
81
+ if (plugin.description && typeof plugin.description !== 'string') {
82
+ throw new TypeError('Plugin validation failed: "description" must be a string');
83
+ }
84
+ if (plugin.homepage && typeof plugin.homepage !== 'string') {
85
+ throw new TypeError('Plugin validation failed: "homepage" must be a string');
86
+ }
87
+ }
88
+
89
+ /**
90
+ * Get plugin by ID
91
+ * @param {string} id - Plugin ID
92
+ * @returns {Object|undefined} Plugin object or undefined if not found
93
+ */
94
+ getPlugin(id) {
95
+ return this.plugins.get(id);
96
+ }
97
+
98
+ /**
99
+ * Get all plugins as a Map
100
+ * @returns {Map} Map of plugin ID to plugin object
101
+ */
102
+ getAllPlugins() {
103
+ return this.plugins;
104
+ }
105
+
106
+ /**
107
+ * Get list of all agent IDs
108
+ * @returns {Array<string>} Array of plugin IDs
109
+ */
110
+ listAgents() {
111
+ return Array.from(this.plugins.keys());
112
+ }
113
+ }
114
+
115
+ /**
116
+ * Standalone plugin schema validator (for testing and external use)
117
+ * @param {Object} plugin - Plugin object to validate
118
+ * @returns {{valid: boolean, errors: Array<string>}}
119
+ */
120
+ function validatePluginSchema(plugin) {
121
+ const errors = [];
122
+
123
+ // Check if plugin is an object
124
+ if (!plugin || typeof plugin !== 'object' || Array.isArray(plugin)) {
125
+ return { valid: false, errors: ['Plugin must be a non-null object'] };
126
+ }
127
+
128
+ // Check required fields
129
+ const required = ['id', 'name', 'version', 'directories'];
130
+ required.forEach(field => {
131
+ if (!plugin[field]) {
132
+ errors.push(`Missing required field "${field}"`);
133
+ }
134
+ });
135
+
136
+ // Validate field types
137
+ if (plugin.id !== undefined && typeof plugin.id !== 'string') {
138
+ errors.push('"id" must be a string');
139
+ }
140
+ if (plugin.name !== undefined && typeof plugin.name !== 'string') {
141
+ errors.push('"name" must be a string');
142
+ }
143
+ if (plugin.version !== undefined && typeof plugin.version !== 'string') {
144
+ errors.push('"version" must be a string');
145
+ }
146
+ if (plugin.directories !== undefined) {
147
+ if (typeof plugin.directories !== 'object' || Array.isArray(plugin.directories)) {
148
+ errors.push('"directories" must be an object');
149
+ } else if (Object.keys(plugin.directories).length === 0) {
150
+ errors.push('"directories" must not be empty');
151
+ }
152
+ }
153
+
154
+ // Validate optional fields if present
155
+ if (plugin.description !== undefined && typeof plugin.description !== 'string') {
156
+ errors.push('"description" must be a string');
157
+ }
158
+ if (plugin.homepage !== undefined && typeof plugin.homepage !== 'string') {
159
+ errors.push('"homepage" must be a string');
160
+ }
161
+
162
+ return { valid: errors.length === 0, errors };
163
+ }
164
+
165
+ module.exports = PluginManager;
166
+ module.exports.validatePluginSchema = validatePluginSchema;
@@ -0,0 +1,141 @@
1
+ /**
2
+ * Plugin Recommender
3
+ *
4
+ * Filters and sorts tools from the catalog based on tech stack detection
5
+ * and budget mode. Pure logic — no I/O, no side effects.
6
+ */
7
+
8
+ const { CATALOG, BUDGET_MODES, STAGES } = require('./plugin-catalog');
9
+
10
+ const STAGE_ORDER = Object.values(STAGES);
11
+
12
+ // Dependency-to-detection-field mapping for matchesDetection
13
+ const DEP_FIELD_MAP = {
14
+ // Frameworks
15
+ next: 'frameworks:nextjs', react: 'frameworks:react', vue: 'frameworks:vue',
16
+ '@angular/core': 'frameworks:angular', express: 'frameworks:express',
17
+ fastify: 'frameworks:fastify', '@nestjs/core': 'frameworks:nestjs',
18
+ // Databases
19
+ '@supabase/supabase-js': 'databases:supabase', '@prisma/client': 'databases:prisma',
20
+ // Payments
21
+ stripe: 'payments:stripe',
22
+ // Testing
23
+ vitest: 'testing:vitest', jest: 'testing:jest', '@playwright/test': 'testing:playwright',
24
+ // Auth
25
+ '@clerk/nextjs': 'auth:clerk',
26
+ // Misc
27
+ typescript: 'languages:typescript', eslint: 'linting:eslint',
28
+ };
29
+
30
+ // File-to-detection-field mapping
31
+ const FILE_FIELD_MAP = {
32
+ 'tsconfig.json': 'lsps:typescript',
33
+ 'biome.json': 'linting:biome',
34
+ '.prettierrc': 'linting:prettier',
35
+ 'eslint.config.js': 'linting:eslint',
36
+ 'vitest.config.ts': 'testing:vitest',
37
+ 'jest.config.js': 'testing:jest',
38
+ 'sonar-project.properties': 'linting:sonar',
39
+ 'package.json': null, // universal, always matches
40
+ };
41
+
42
+ /**
43
+ * Check if detection conditions match the tech stack.
44
+ * Empty conditions = universal (always matches).
45
+ * Multiple conditions use OR logic.
46
+ */
47
+ function matchesDetection(conditions, techStack) {
48
+ if (!conditions || conditions.length === 0) return true;
49
+
50
+ return conditions.some((condition) => {
51
+ const [type, value] = condition.split(':');
52
+ if (type === 'dep') {
53
+ // Check if the dependency maps to a detected field
54
+ const mapping = DEP_FIELD_MAP[value];
55
+ if (mapping) {
56
+ const [field, name] = mapping.split(':');
57
+ return techStack[field]?.includes(name);
58
+ }
59
+ // Fallback: check all array fields for the value
60
+ return Object.values(techStack).some(
61
+ (arr) => Array.isArray(arr) && arr.includes(value)
62
+ );
63
+ }
64
+ if (type === 'file') {
65
+ const mapping = FILE_FIELD_MAP[value];
66
+ if (mapping === null) return true; // package.json always matches
67
+ if (mapping) {
68
+ const [field, name] = mapping.split(':');
69
+ return techStack[field]?.includes(name);
70
+ }
71
+ return false;
72
+ }
73
+ if (type === 'framework') {
74
+ return techStack.frameworks?.includes(value);
75
+ }
76
+ return false;
77
+ });
78
+ }
79
+
80
+ /**
81
+ * Recommend tools based on tech stack and budget.
82
+ * @param {Object} techStack - Output from detectTechStack()
83
+ * @param {string} budgetMode - Budget mode key
84
+ * @param {Object} [options] - Additional options
85
+ * @param {string[]} [options.customTiers] - Tiers to include for 'custom' mode
86
+ * @returns {{ recommended: Object[], skipped: Object[] }}
87
+ */
88
+ function recommend(techStack, budgetMode, options = {}) {
89
+ const mode = BUDGET_MODES[budgetMode];
90
+ if (!mode) {
91
+ throw new Error(`Invalid budget mode: '${budgetMode}'. Valid modes: ${Object.keys(BUDGET_MODES).join(', ')}`);
92
+ }
93
+
94
+ const allowedTiers = budgetMode === 'custom'
95
+ ? (options.customTiers || [])
96
+ : mode.includes;
97
+
98
+ const recommended = [];
99
+ const skipped = [];
100
+
101
+ for (const [id, tool] of Object.entries(CATALOG)) {
102
+ // Check detection match
103
+ if (!matchesDetection(tool.detectWhen, techStack)) {
104
+ continue; // Not relevant to this project
105
+ }
106
+
107
+ // Check tier
108
+ if (!allowedTiers.includes(tool.tier)) {
109
+ skipped.push({
110
+ id,
111
+ ...tool,
112
+ reason: `Tier '${tool.tier}' not included in '${budgetMode}' budget`,
113
+ });
114
+ continue;
115
+ }
116
+
117
+ // CLI-first: skip unjustified MCPs
118
+ if (tool.type === 'mcp' && !tool.mcpJustified) {
119
+ skipped.push({
120
+ id,
121
+ ...tool,
122
+ reason: 'MCP not justified — prefer CLI alternative',
123
+ });
124
+ continue;
125
+ }
126
+
127
+ recommended.push({ id, ...tool });
128
+ }
129
+
130
+ // Sort: free first, then by stage order
131
+ recommended.sort((a, b) => {
132
+ const aFree = a.tier === 'free' ? 0 : 1;
133
+ const bFree = b.tier === 'free' ? 0 : 1;
134
+ if (aFree !== bFree) return aFree - bFree;
135
+ return STAGE_ORDER.indexOf(a.stage) - STAGE_ORDER.indexOf(b.stage);
136
+ });
137
+
138
+ return { recommended, skipped };
139
+ }
140
+
141
+ module.exports = { recommend, matchesDetection };