@morsa/guidance-bank 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +135 -0
  3. package/bin/gbank.js +3 -0
  4. package/dist/cli/commands/init.js +27 -0
  5. package/dist/cli/commands/mcpServe.js +8 -0
  6. package/dist/cli/commands/stats.js +92 -0
  7. package/dist/cli/index.js +67 -0
  8. package/dist/cli/postinstall.js +24 -0
  9. package/dist/cli/prompts/initPrompts.js +89 -0
  10. package/dist/cli/prompts/providerAvailability.js +31 -0
  11. package/dist/core/audit/summarizeEntryContent.js +43 -0
  12. package/dist/core/audit/types.js +1 -0
  13. package/dist/core/bank/canonicalEntry.js +106 -0
  14. package/dist/core/bank/integration.js +16 -0
  15. package/dist/core/bank/layout.js +159 -0
  16. package/dist/core/bank/lifecycle.js +24 -0
  17. package/dist/core/bank/manifest.js +37 -0
  18. package/dist/core/bank/project.js +105 -0
  19. package/dist/core/bank/types.js +6 -0
  20. package/dist/core/context/contextEntryResolver.js +140 -0
  21. package/dist/core/context/contextTextRenderer.js +116 -0
  22. package/dist/core/context/detectProjectContext.js +118 -0
  23. package/dist/core/context/resolveContextService.js +138 -0
  24. package/dist/core/context/types.js +1 -0
  25. package/dist/core/init/initService.js +112 -0
  26. package/dist/core/init/initTypes.js +1 -0
  27. package/dist/core/projects/createBankDeriveGuidance/index.js +47 -0
  28. package/dist/core/projects/createBankDeriveGuidance/shared/general.js +49 -0
  29. package/dist/core/projects/createBankDeriveGuidance/shared/typescript.js +18 -0
  30. package/dist/core/projects/createBankDeriveGuidance/stacks/angular.js +252 -0
  31. package/dist/core/projects/createBankDeriveGuidance/stacks/ios.js +254 -0
  32. package/dist/core/projects/createBankDeriveGuidance/stacks/nextjs.js +220 -0
  33. package/dist/core/projects/createBankDeriveGuidance/stacks/nodejs.js +221 -0
  34. package/dist/core/projects/createBankDeriveGuidance/stacks/other.js +34 -0
  35. package/dist/core/projects/createBankDeriveGuidance/stacks/react.js +214 -0
  36. package/dist/core/projects/createBankFlow.js +252 -0
  37. package/dist/core/projects/createBankIterationPrompt.js +294 -0
  38. package/dist/core/projects/createBankPrompt.js +95 -0
  39. package/dist/core/projects/createFlowPhases.js +28 -0
  40. package/dist/core/projects/discoverCurrentProjectBank.js +43 -0
  41. package/dist/core/projects/discoverExistingGuidance.js +99 -0
  42. package/dist/core/projects/discoverProjectEvidence.js +87 -0
  43. package/dist/core/projects/discoverRecentCommits.js +28 -0
  44. package/dist/core/projects/findReferenceProjects.js +42 -0
  45. package/dist/core/projects/guidanceStrategies.js +29 -0
  46. package/dist/core/projects/identity.js +16 -0
  47. package/dist/core/projects/providerProjectGuidance.js +82 -0
  48. package/dist/core/providers/providerRegistry.js +51 -0
  49. package/dist/core/providers/types.js +1 -0
  50. package/dist/core/stats/statsService.js +117 -0
  51. package/dist/core/sync/syncService.js +145 -0
  52. package/dist/core/sync/syncTypes.js +1 -0
  53. package/dist/core/upgrade/upgradeService.js +134 -0
  54. package/dist/integrations/claudeCode/install.js +78 -0
  55. package/dist/integrations/codex/install.js +80 -0
  56. package/dist/integrations/commandRunner.js +32 -0
  57. package/dist/integrations/cursor/install.js +118 -0
  58. package/dist/integrations/shared.js +20 -0
  59. package/dist/mcp/config.js +19 -0
  60. package/dist/mcp/createMcpServer.js +31 -0
  61. package/dist/mcp/launcher.js +49 -0
  62. package/dist/mcp/registerTools.js +33 -0
  63. package/dist/mcp/serverMetadata.js +7 -0
  64. package/dist/mcp/tools/auditUtils.js +49 -0
  65. package/dist/mcp/tools/createBankApply.js +106 -0
  66. package/dist/mcp/tools/createBankToolRuntime.js +115 -0
  67. package/dist/mcp/tools/createBankToolSchemas.js +234 -0
  68. package/dist/mcp/tools/entryMutationHelpers.js +44 -0
  69. package/dist/mcp/tools/registerBankManifestTool.js +47 -0
  70. package/dist/mcp/tools/registerClearProjectBankTool.js +73 -0
  71. package/dist/mcp/tools/registerCreateBankTool.js +240 -0
  72. package/dist/mcp/tools/registerDeleteEntryTool.js +98 -0
  73. package/dist/mcp/tools/registerDeleteGuidanceSourceTool.js +120 -0
  74. package/dist/mcp/tools/registerListEntriesTool.js +94 -0
  75. package/dist/mcp/tools/registerReadEntryTool.js +99 -0
  76. package/dist/mcp/tools/registerResolveContextTool.js +128 -0
  77. package/dist/mcp/tools/registerSetProjectStateTool.js +121 -0
  78. package/dist/mcp/tools/registerSyncBankTool.js +113 -0
  79. package/dist/mcp/tools/registerUpgradeBankTool.js +89 -0
  80. package/dist/mcp/tools/registerUpsertRuleTool.js +100 -0
  81. package/dist/mcp/tools/registerUpsertSkillTool.js +102 -0
  82. package/dist/mcp/tools/sharedSchemas.js +13 -0
  83. package/dist/shared/errors.js +18 -0
  84. package/dist/shared/paths.js +11 -0
  85. package/dist/storage/atomicWrite.js +15 -0
  86. package/dist/storage/auditLogger.js +20 -0
  87. package/dist/storage/auditStore.js +22 -0
  88. package/dist/storage/bankRepository.js +168 -0
  89. package/dist/storage/entryStore.js +142 -0
  90. package/dist/storage/manifestStore.js +30 -0
  91. package/dist/storage/projectBankStore.js +55 -0
  92. package/dist/storage/providerIntegrationStore.js +22 -0
  93. package/dist/storage/safeFs.js +202 -0
  94. package/package.json +64 -0
  95. package/scripts/postinstall.js +20 -0
@@ -0,0 +1,220 @@
1
+ export const NEXTJS_DERIVE_GUIDANCE = `## Next.js Guidance
2
+
3
+ Focus on Next.js-specific patterns: router mode, server/client boundaries, data fetching and caching strategy, route handlers, middleware, metadata, and runtime constraints.
4
+ Apply React component/hook conventions from observed project patterns where relevant.
5
+
6
+ ## Codebase Exploration Before Generating
7
+
8
+ ### Structure Discovery
9
+
10
+ 1. List root folders.
11
+ 2. Identify Next.js source roots (\`app/\`, \`pages/\`, \`src/app/\`, \`src/pages/\`, \`components/\`, \`lib/\`).
12
+ 3. Detect route/layout structure 2-3 levels deep.
13
+ 4. Record the exact folder names and paths you found.
14
+
15
+ ### Router Mode Detection (Critical)
16
+
17
+ Determine which routing model is actually used:
18
+ - App Router (\`app/\`, route segments, \`layout.tsx\`, \`page.tsx\`, \`route.ts\`)
19
+ - Pages Router (\`pages/\`, \`_app.tsx\`, \`_document.tsx\`, \`pages/api\`)
20
+ - Mixed migration state
21
+
22
+ Do not generate rules until router mode is explicit with file-path evidence.
23
+
24
+ ### Pattern Extraction (Read Real Files)
25
+
26
+ For each category, read 2-3 representative files and extract reusable decisions:
27
+
28
+ | Category | What to Find | What to Extract |
29
+ |----------|--------------|-----------------|
30
+ | Routing/Layout | Route segments and layouts | Route organization, segment conventions, nesting boundaries |
31
+ | Server/Client split | \`use client\`, server components, client hooks | Boundary rules for where logic can run |
32
+ | Data fetching/cache | \`fetch\`, cache/revalidate usage | Caching model, revalidation strategy, dynamic/static behavior |
33
+ | API layer | \`route.ts\` or \`pages/api\` handlers | Request/response structure, auth/error handling, service usage |
34
+ | Actions/mutations | Server actions/forms/mutations | Mutation flow and boundaries |
35
+ | Middleware/Auth | \`middleware.ts\`, auth wrappers | Access control flow, redirect patterns, edge/runtime constraints |
36
+ | Metadata/SEO | metadata exports and head patterns | Canonical metadata structure and ownership |
37
+ | Styling/UI | CSS Modules/Tailwind/SCSS/design tokens | Styling conventions and composition patterns |
38
+ | Testing | test setup and specs | Test location, mocking strategy, critical coverage expectations |
39
+
40
+ ### Config and Tooling Analysis (Next.js-Specific)
41
+
42
+ Read these files if present:
43
+ - package.json and lockfile
44
+ - \`next.config.js\` / \`next.config.mjs\` / \`next.config.ts\`
45
+ - \`middleware.ts\`
46
+ - \`app/layout.tsx\`, \`app/page.tsx\`, nested segment files
47
+ - \`pages/_app.tsx\`, \`pages/_document.tsx\`, \`pages/api/**\` (if Pages Router)
48
+ - eslint config and formatting config
49
+ - deployment/runtime config (edge/node settings if present)
50
+ - monorepo config (\`nx.json\`, \`turbo.json\`, workspace manifests)
51
+
52
+ ### Version and Feature Gate (Next.js)
53
+
54
+ Before turning patterns into rules, verify what is actually used in this codebase:
55
+ - Next.js version from dependencies.
56
+ - Router mode: App Router, Pages Router, or mixed.
57
+ - Runtime target per area: Node.js runtime, Edge runtime, or mixed.
58
+ - Use Server Actions only when App Router usage and code evidence support them.
59
+ - Use \`route.ts\` handler conventions only when App Router API routes are present.
60
+ - Use \`pages/api\` conventions only when Pages Router API routes are present.
61
+ - Preserve observed caching model (\`revalidate\`, dynamic/static behavior, cache tags) instead of introducing new defaults.
62
+
63
+ ### Red Flag Detection (Next.js-Specific)
64
+
65
+ Search for recurring issues that should become explicit rules:
66
+ - mixed App Router and Pages Router patterns without clear boundaries
67
+ - server/client boundary violations (client hooks in server components, server-only logic in client components)
68
+ - inconsistent caching/revalidation strategy across similar routes
69
+ - duplicated request/response logic across route handlers and services
70
+ - heavy business logic in middleware
71
+ - direct secret/runtime-dependent usage in client-side code
72
+ - inconsistent error/not-found/redirect handling across route modules
73
+
74
+ ### Analysis Checklist (Next.js Project)
75
+
76
+ Document these with file path evidence:
77
+
78
+ - Router mode and route organization model.
79
+ - Server/client component boundaries.
80
+ - Data fetching and caching/revalidation strategy.
81
+ - API route pattern and service integration.
82
+ - Middleware/auth flow and runtime boundaries.
83
+ - Metadata/SEO pattern and ownership.
84
+ - Testing strategy and helper usage.
85
+ - Styling mode and constraints.
86
+ - Main recurring anti-patterns and where they appear.
87
+
88
+ Before final output, gather concrete evidence for each applicable item.
89
+ If evidence remains partial, continue conservatively and mark uncertainty with \`[VERIFY: ...]\` instead of blocking output.
90
+
91
+ ### Generation Locks (Prevent Architecture Drift)
92
+
93
+ Apply these constraints when generating rules and skills:
94
+ - Preserve detected router mode (App Router / Pages Router / mixed); do not migrate architecture implicitly.
95
+ - Preserve server/client split boundaries; do not move logic across boundaries without evidence.
96
+ - Preserve detected runtime targets and deployment assumptions (Node/Edge).
97
+ - Preserve detected data fetching and caching model; avoid introducing incompatible defaults.
98
+ - Preserve detected styling mode and monorepo boundaries when present.
99
+
100
+ ## Skill Candidates (Next.js)
101
+
102
+ Generate these skills with actual project paths and Next.js-specific workflow steps:
103
+ Generate only skills that have clear project evidence and practical value.
104
+ For small/low-confidence projects, 2-4 core skills are usually enough.
105
+
106
+ ### adding-route
107
+ - Include actual route segment or pages structure from this project.
108
+ - Show how to add page/layout/route wiring using existing conventions.
109
+ - Include data-loading and error/not-found handling integration where applicable.
110
+
111
+ ### adding-api-route
112
+ - Include existing API route style (\`app/**/route.ts\` or \`pages/api/**\`).
113
+ - Show request parsing, validation, service usage, and error response flow.
114
+ - Include test or verification strategy used in this project.
115
+
116
+ ### code-review
117
+ - Include Next.js-specific review checklist based on project patterns.
118
+ - Cover router mode consistency, server/client boundaries, caching strategy, and runtime correctness.
119
+
120
+ ### common-anti-patterns
121
+ - Include recurring Next.js anti-patterns from this project.
122
+ - Pair each anti-pattern with preferred local alternative.
123
+
124
+ ### troubleshooting
125
+ - Include common build/runtime/hydration/cache issues for this codebase.
126
+ - Include where to inspect first when these issues happen.
127
+
128
+ ### [framework-specific]
129
+ Generate 1-3 extra skills based on actual stack usage:
130
+ - app-router-patterns (if App Router is primary)
131
+ - pages-router-patterns (if Pages Router is primary)
132
+ - server-actions-patterns (if Server Actions are primary)
133
+ - middleware-auth-workflows (if middleware/auth is central)
134
+ - monorepo-workflows (if apps/libs pattern exists)
135
+
136
+ ### enrichment-tasks (optional)
137
+ - Generate this only when the user explicitly asks for enrichment, or when analysis shows a clear gap in the existing rule/skill bank.
138
+
139
+ ## Rule Generation Requirements
140
+
141
+ ### What NOT to Include
142
+
143
+ - Do not invent generic philosophy ("clean code", "think about user").
144
+ - Do not duplicate what linters/formatters fully enforce.
145
+ - Do not add rules without evidence from codebase patterns.
146
+ - Do not repeat the same rule across multiple rule topics.
147
+ - Do not mix App Router and Pages Router conventions unless mixed mode is confirmed in this project.
148
+
149
+ ### Rule Content Requirements
150
+
151
+ Keep this section Next.js-specific:
152
+ - Capture decisions tied to router mode, server/client boundaries, caching strategy, API layer, and runtime model.
153
+ - Use Next.js-native terminology aligned with observed project structure.
154
+ - Highlight recurring Next.js anti-patterns and safer local alternatives.
155
+
156
+ ## Algorithm: Analysis -> Rules (Next.js)
157
+
158
+ Follow this systematic approach for Next.js projects:
159
+
160
+ **Router Structure -> Architecture Rules:**
161
+ 1. Determine router mode and segment organization.
162
+ 2. Define placement rules for pages/layouts/route handlers.
163
+ 3. Document allowed dependency directions between route modules and shared layers.
164
+
165
+ **Server/Client Boundaries -> Runtime Rules:**
166
+ 1. Identify where server and client logic currently lives.
167
+ 2. Extract repeated boundary decisions for hooks, secrets, and side effects.
168
+ 3. Generate concise rules preserving those boundaries.
169
+
170
+ **Data/API -> Flow Rules:**
171
+ 1. Identify fetching, caching, mutation, and API response patterns.
172
+ 2. Extract repeated error handling and validation conventions.
173
+ 3. Generate rules that keep data flow predictable across routes.
174
+
175
+ **Configs -> Constraints Rules:**
176
+ 1. Inspect Next config, middleware, runtime/deployment settings.
177
+ 2. Promote only meaningful architectural constraints.
178
+ 3. Avoid restating trivial formatter/linter-only behavior.
179
+
180
+ **Tests -> Testing Rules:**
181
+ 1. Identify where tests live and which module types are covered.
182
+ 2. Extract common test patterns and helper usage.
183
+ 3. Require tests for module types that are consistently tested in this project.
184
+
185
+ ## Recommended Rule Topics (Next.js Project)
186
+
187
+ Split by topic:
188
+ Generate only topics that are supported by concrete project evidence.
189
+
190
+ | Topic | Covers (Next.js-Specific) |
191
+ |------|----------------------------|
192
+ | \`architecture\` | route/module boundaries, placement, dependency direction |
193
+ | \`routing\` | App Router/Pages Router conventions, segments/pages/layouts |
194
+ | \`server-client-boundaries\` | server vs client component boundaries and constraints |
195
+ | \`data-fetching-cache\` | fetching model, cache/revalidate strategy, dynamic/static behavior |
196
+ | \`api-routes\` | route handlers or pages/api conventions, request/response patterns |
197
+ | \`middleware-auth\` | middleware flow, access control, redirects/runtime constraints |
198
+ | \`components\` | UI composition patterns and file organization |
199
+ | \`styling\` | CSS strategy, token usage, naming conventions |
200
+ | \`testing\` | test placement, helpers, minimum critical checks |
201
+ | \`error-handling\` | error mapping, not-found/redirect behavior, retry/logging boundaries |
202
+ | \`i18n\` | localization key usage and routing integration (if applicable) |
203
+
204
+ ## Context-to-Rule/Skill Mapping (Next.js)
205
+
206
+ Use this mapping to decide what files to generate:
207
+ Generate only skills that are supported by concrete project evidence.
208
+
209
+ | Found in Next.js Codebase | Generate Rule Topic | Generate Skill |
210
+ |---------------------------|---------------------|----------------|
211
+ | App Router segments/layouts | \`routing\`, \`architecture\` | \`adding-route\`, \`app-router-patterns\` |
212
+ | Pages Router structure | \`routing\`, \`architecture\` | \`adding-route\`, \`pages-router-patterns\` |
213
+ | Server/client boundary conventions | \`server-client-boundaries\` | \`code-review\` |
214
+ | Structured fetch/cache/revalidate usage | \`data-fetching-cache\` | \`troubleshooting\` |
215
+ | API route layer with shared services | \`api-routes\`, \`services-data\` | \`adding-api-route\` |
216
+ | Middleware-driven auth/routing | \`middleware-auth\` | \`middleware-auth-workflows\` |
217
+ | Monorepo boundary rules | \`architecture\` | \`monorepo-workflows\` |
218
+ | Repeated runtime/hydration/cache issues | \`error-handling\` | \`troubleshooting\` |
219
+ | Repeated unsafe patterns | \`error-handling\` | \`common-anti-patterns\` |
220
+ `;
@@ -0,0 +1,221 @@
1
+ export const NODEJS_DERIVE_GUIDANCE = `## Node.js Backend Guidance
2
+
3
+ Focus on Node.js backend patterns: HTTP/API architecture, service and data layers, validation, auth, error handling, background processing, and runtime/ops boundaries.
4
+ Apply TypeScript guidance from the shared section only when the project uses TypeScript.
5
+
6
+ ## Codebase Exploration Before Generating
7
+
8
+ ### Structure Discovery
9
+
10
+ 1. List root folders.
11
+ 2. Identify backend source roots (for example: \`src/\`, \`apps/\`, \`services/\`, \`modules/\`, \`server/\`).
12
+ 3. Map API/module hierarchy 2-3 levels deep.
13
+ 4. Record exact folder names and paths.
14
+
15
+ ### Runtime and Framework Detection (Critical)
16
+
17
+ Determine what backend style is actually used:
18
+ - Express / Fastify / NestJS / Koa / custom HTTP server
19
+ - Monolith service vs modular services
20
+ - REST / RPC / GraphQL / mixed
21
+ - ESM / CJS runtime mode (if relevant)
22
+
23
+ Do not generate framework-specific rules until runtime/framework mode is explicit with file-path evidence.
24
+
25
+ ### Pattern Extraction (Read Real Files)
26
+
27
+ For each category, read 2-3 representative files and extract reusable decisions:
28
+
29
+ | Category | What to Find | What to Extract |
30
+ |----------|--------------|-----------------|
31
+ | Entry/bootstrap | server startup and app wiring | initialization order, middleware setup, module loading |
32
+ | Routing/controllers | endpoint modules and handlers | handler structure, request/response flow, route organization |
33
+ | Services/use-cases | business logic orchestration | service boundaries, dependency flow, transaction patterns |
34
+ | Data layer | ORM/query/repository usage | data access boundaries, mapping, consistency rules |
35
+ | Validation | request/input validation | schema location, validation timing, error shape |
36
+ | Auth/security | auth guards/middleware | token/session flow, permission checks, sensitive-path handling |
37
+ | Error handling/logging | global handlers and logger usage | error normalization, log structure, observability patterns |
38
+ | Async/jobs/events | queues, workers, schedulers | job boundaries, retry/error handling, idempotency patterns |
39
+ | Testing | test setup and suite structure | test location, integration/unit split, mocking style |
40
+
41
+ ### Config and Tooling Analysis (Node.js-Specific)
42
+
43
+ Read these files if present:
44
+ - package.json and lockfile
45
+ - runtime config and env files (\`.env.example\`, config modules, secrets loading)
46
+ - framework config (Nest config, Fastify plugins, Express wiring, GraphQL config, etc.)
47
+ - DB/migration config (Prisma/TypeORM/Knex/Sequelize or equivalent)
48
+ - queue/worker config (BullMQ, agenda, cron jobs, message consumers)
49
+ - eslint and formatting config
50
+ - deployment/runtime files (Dockerfile, compose, process manager config, CI scripts)
51
+ - monorepo config (\`nx.json\`, \`turbo.json\`, workspace manifests)
52
+
53
+ ### Version and Feature Gate (Node.js)
54
+
55
+ Before turning patterns into rules, verify what is actually used in this codebase:
56
+ - Node.js version and module/runtime mode.
57
+ - Backend framework mode and routing style.
58
+ - Data layer style (ORM/query builder/raw SQL/repository wrappers).
59
+ - Validation strategy and where it is enforced.
60
+ - Auth strategy and boundary points.
61
+ - Background processing model (queues/workers/schedulers), if present.
62
+ - Do not introduce framework conventions not present in the project.
63
+
64
+ ### Red Flag Detection (Node.js-Specific)
65
+
66
+ Search for recurring issues that should become explicit rules:
67
+ - missing or inconsistent request validation on public endpoints
68
+ - duplicated business logic between handlers/controllers
69
+ - direct DB access from handlers when service/repository layer exists
70
+ - inconsistent error responses across similar endpoints
71
+ - logging sensitive fields or credentials
72
+ - missing auth/permission checks on protected routes
73
+ - long synchronous/blocking operations in request path
74
+ - inconsistent transaction boundaries or partial failure handling
75
+ - duplicated job/retry logic across workers
76
+
77
+ ### Analysis Checklist (Node.js Project)
78
+
79
+ Document these with file path evidence:
80
+
81
+ - Framework/runtime model and module organization.
82
+ - Routing/controller conventions.
83
+ - Service/data-layer boundaries and mapping style.
84
+ - Validation and auth flow.
85
+ - Error/logging standards.
86
+ - Async/jobs/events architecture (if present).
87
+ - Testing strategy and helper usage.
88
+ - Deployment/runtime constraints.
89
+ - Main recurring anti-patterns and where they appear.
90
+
91
+ Before final output, gather concrete evidence for each applicable item.
92
+ If evidence remains partial, continue conservatively and mark uncertainty with \`[VERIFY: ...]\` instead of blocking output.
93
+
94
+ ### Generation Locks (Prevent Architecture Drift)
95
+
96
+ Apply these constraints when generating rules and skills:
97
+ - Preserve detected framework/runtime mode; do not migrate architecture implicitly.
98
+ - Preserve routing style and handler layering.
99
+ - Preserve service/data boundaries and transaction model.
100
+ - Preserve validation/auth/error contracts already used across endpoints.
101
+ - Preserve async/job processing model when present.
102
+ - Preserve deployment/runtime assumptions and monorepo boundaries when present.
103
+
104
+ ## Skill Candidates (Node.js)
105
+
106
+ Generate these skills with actual project paths and Node.js-specific workflow steps:
107
+ Generate only skills that have clear project evidence and practical value.
108
+ For small/low-confidence projects, 2-4 core skills are usually enough.
109
+
110
+ ### adding-endpoint
111
+ - Include actual route/controller/handler structure from this project.
112
+ - Show validation, auth checks, service call, and response pattern based on local conventions.
113
+ - Include verification or tests according to existing practices.
114
+
115
+ ### adding-service
116
+ - Include actual service and data access structure used in this project.
117
+ - Show dependency wiring, transaction/error handling, and integration points.
118
+ - Include test/mocking strategy used for services in this codebase.
119
+
120
+ ### code-review
121
+ - Include Node.js backend review checklist based on project patterns.
122
+ - Cover validation, auth boundaries, error contracts, data layer boundaries, and logging hygiene.
123
+
124
+ ### common-anti-patterns
125
+ - Include recurring backend anti-patterns from this project.
126
+ - Pair each anti-pattern with preferred local alternative.
127
+
128
+ ### troubleshooting
129
+ - Include common runtime/data/integration issues for this codebase.
130
+ - Include where to inspect first when these issues happen.
131
+
132
+ ### [framework-specific]
133
+ Generate 1-3 extra skills based on actual stack usage:
134
+ - nestjs-patterns (if NestJS is primary)
135
+ - express-fastify-patterns (if Express/Fastify style is primary)
136
+ - data-access-patterns (if ORM/repository complexity is central)
137
+ - jobs-workers-patterns (if queues/workers are central)
138
+ - monorepo-workflows (if apps/libs pattern exists)
139
+
140
+ ### enrichment-tasks (optional)
141
+ - Generate this only when the user explicitly asks for enrichment, or when analysis shows a clear gap in the existing rule/skill bank.
142
+
143
+ ## Rule Generation Requirements
144
+
145
+ ### What NOT to Include
146
+
147
+ - Do not invent generic philosophy ("clean code", "think about user").
148
+ - Do not duplicate what linters/formatters fully enforce.
149
+ - Do not add rules without evidence from codebase patterns.
150
+ - Do not repeat the same rule across multiple rule topics.
151
+ - Do not introduce framework APIs or architectural layers not used in this backend.
152
+
153
+ ### Rule Content Requirements
154
+
155
+ Keep this section Node.js-backend-specific:
156
+ - Capture decisions tied to request flow, service/data boundaries, validation/auth, and error/logging contracts.
157
+ - Use runtime/framework terminology aligned with observed project structure.
158
+ - Highlight recurring backend anti-patterns and safer local alternatives.
159
+
160
+ ## Algorithm: Analysis -> Rules (Node.js)
161
+
162
+ Follow this systematic approach for Node.js backends:
163
+
164
+ **Structure -> Architecture Rules:**
165
+ 1. Identify repeated module and request-flow structures.
166
+ 2. Define placement rules for handlers/controllers, services, and data modules.
167
+ 3. Document allowed dependency directions.
168
+
169
+ **Request Flow -> API Rules:**
170
+ 1. Scan representative route/controller/handler files.
171
+ 2. Extract repeated patterns for validation, auth, response shape, and error mapping.
172
+ 3. Convert repeated high-quality patterns into concise rules.
173
+
174
+ **Service/Data -> Boundary Rules:**
175
+ 1. Identify service orchestration and data access boundaries.
176
+ 2. Extract transaction and error-handling conventions.
177
+ 3. Generate rules preserving those boundaries.
178
+
179
+ **Async/Jobs -> Reliability Rules:**
180
+ 1. Inspect workers/queues/schedulers where present.
181
+ 2. Extract retry/idempotency and failure-handling patterns.
182
+ 3. Generate rules for reliable async processing.
183
+
184
+ **Configs -> Runtime Constraints:**
185
+ 1. Inspect runtime/framework/deployment config files.
186
+ 2. Promote only meaningful architectural constraints.
187
+ 3. Avoid restating trivial formatter/linter-only behavior.
188
+
189
+ ## Recommended Rule Topics (Node.js Project)
190
+
191
+ Split by topic:
192
+ Generate only topics supported by concrete project evidence.
193
+
194
+ | Topic | Covers (Node.js-Specific) |
195
+ |------|----------------------------|
196
+ | \`architecture\` | module boundaries, placement, dependency direction |
197
+ | \`api-handlers\` | route/controller/handler organization and request flow |
198
+ | \`services\` | business logic boundaries and orchestration patterns |
199
+ | \`data-access\` | repositories/ORM/query layer patterns and transaction boundaries |
200
+ | \`validation-auth\` | input validation and permission/auth boundaries |
201
+ | \`error-logging\` | error normalization, logging patterns, observability boundaries |
202
+ | \`jobs-workers\` | queue/worker/scheduler behavior and retry/idempotency |
203
+ | \`testing\` | test placement, helper usage, minimum critical checks |
204
+ | \`runtime-deploy\` | runtime assumptions, env/config boundaries, deployment constraints |
205
+
206
+ ## Context-to-Rule/Skill Mapping (Node.js)
207
+
208
+ Use this mapping to decide what files to generate:
209
+ Generate only skills that are supported by concrete project evidence.
210
+
211
+ | Found in Node.js Codebase | Generate Rule Topic | Generate Skill |
212
+ |---------------------------|---------------------|----------------|
213
+ | Clear handler -> service -> repository flow | \`api-handlers\`, \`services\`, \`data-access\` | \`adding-endpoint\`, \`adding-service\` |
214
+ | Strong validation/auth middleware usage | \`validation-auth\` | \`code-review\` |
215
+ | Centralized error mapper/logger | \`error-logging\` | \`troubleshooting\` |
216
+ | Worker/queue architecture | \`jobs-workers\` | \`jobs-workers-patterns\` |
217
+ | NestJS module/controller/provider patterns | \`architecture\`, \`api-handlers\` | \`nestjs-patterns\` |
218
+ | Express/Fastify route plugins and handlers | \`api-handlers\`, \`architecture\` | \`express-fastify-patterns\` |
219
+ | Monorepo boundary rules | \`architecture\`, \`runtime-deploy\` | \`monorepo-workflows\` |
220
+ | Repeated unsafe patterns | \`error-logging\` | \`common-anti-patterns\` |
221
+ `;
@@ -0,0 +1,34 @@
1
+ export const OTHER_DERIVE_GUIDANCE = `## Unknown or Mixed Stack Guidance
2
+
3
+ The stack is not confidently identified or does not match known stack routes.
4
+ Build stack-aware guidance without forcing unsupported framework assumptions.
5
+
6
+ ## Stack Identification Pass
7
+
8
+ Infer the most likely stack from project fingerprints:
9
+ - runtime/platform markers (for example: \`package.json\`, \`pyproject.toml\`, \`go.mod\`, \`pom.xml\`, \`*.csproj\`, \`Gemfile\`)
10
+ - framework markers (dependencies, CLI configs, routing/bootstrap entry files)
11
+ - build/test/tooling markers (linters, test runners, bundlers, CI scripts)
12
+
13
+ Classify confidence explicitly:
14
+ - high confidence: one dominant stack is clearly supported by code/config evidence
15
+ - medium confidence: multiple plausible stacks or mixed architecture
16
+ - low confidence: minimal or conflicting evidence
17
+
18
+ ## Stack-Specific Fallback Strategy
19
+
20
+ - If confidence is high and trusted docs are helpful, use them only as a secondary source for best-practice alignment.
21
+ - Keep project evidence as the primary source; external guidance should refine, not override, observed project patterns.
22
+ - If confidence is medium/low, prefer conservative, technology-neutral rules and avoid stack-specific APIs not proven in the repository.
23
+
24
+ ## Output Size by Evidence Strength
25
+
26
+ - High confidence + sufficient codebase: generate a normal stack-oriented set.
27
+ - Medium confidence: generate a smaller set focused on stable cross-cutting decisions visible in code.
28
+ - Low confidence or near-empty project: generate only a minimal scaffold that can evolve (baseline structure rules + a small core skill set).
29
+
30
+ ## Ambiguity Markers
31
+
32
+ - Mark uncertain stack decisions with \`[VERIFY: what to confirm]\`.
33
+ - Keep each uncertain point scoped and actionable for future refinement.
34
+ `;