@polymorphism-tech/morph-spec 4.17.0 → 4.19.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 (70) hide show
  1. package/CLAUDE.md +36 -0
  2. package/README.md +2 -2
  3. package/bin/task-manager.js +12 -0
  4. package/claude-plugin.json +1 -1
  5. package/docs/CHEATSHEET.md +1 -1
  6. package/docs/QUICKSTART.md +1 -1
  7. package/framework/agents/architecture/architecture-expert.md +86 -0
  8. package/framework/agents/architecture/morph-spec-architect.md +66 -0
  9. package/framework/agents/architecture/packages-validator.md +77 -0
  10. package/framework/agents/architecture/security-expert.md +67 -0
  11. package/framework/agents/backend/ms-agent-expert.md +1 -1
  12. package/framework/agents/backend/neon-expert.md +9 -27
  13. package/framework/agents/frontend/design-system-validator.md +88 -0
  14. package/framework/agents/frontend/nextjs-component-validator.md +85 -0
  15. package/framework/agents/frontend/{ui-ux-designer.md → ui-designer.md} +31 -0
  16. package/framework/agents/integrations/neon-auth.md +151 -0
  17. package/framework/agents.json +22 -14
  18. package/framework/hooks/claude-code/post-tool-use/dispatch.js +39 -0
  19. package/framework/hooks/claude-code/post-tool-use/handle-tool-failure.js +78 -44
  20. package/framework/hooks/claude-code/post-tool-use/loop-detect.js +103 -0
  21. package/framework/hooks/claude-code/session-start/inject-morph-context.js +21 -2
  22. package/framework/hooks/claude-code/stop/validate-completion.js +48 -1
  23. package/framework/hooks/shared/activity-logger.js +56 -1
  24. package/framework/hooks/shared/build-check.js +79 -0
  25. package/framework/hooks/shared/payload-utils.js +39 -0
  26. package/framework/hooks/shared/session-snapshot.js +105 -0
  27. package/framework/phases.json +1 -1
  28. package/framework/rules/neon-auth-standards.md +13 -0
  29. package/framework/rules/neon-standards.md +1 -0
  30. package/framework/skills/level-0-meta/mcp-registry.json +34 -1
  31. package/framework/skills/level-0-meta/morph-agent-teams/SKILL.md +3 -3
  32. package/framework/skills/level-0-meta/morph-frontend-review/SKILL.md +1 -1
  33. package/framework/skills/level-0-meta/morph-init/SKILL.md +4 -4
  34. package/framework/skills/level-1-workflows/morph-phase-codebase-analysis/SKILL.md +1 -1
  35. package/framework/skills/level-1-workflows/morph-phase-design/SKILL.md +11 -1
  36. package/framework/skills/level-1-workflows/morph-phase-implement/SKILL.md +12 -1
  37. package/framework/skills/level-1-workflows/morph-phase-plan/SKILL.md +1 -1
  38. package/framework/skills/level-1-workflows/morph-phase-tasks/SKILL.md +1 -1
  39. package/framework/skills/level-1-workflows/morph-phase-uiux/SKILL.md +119 -11
  40. package/framework/skills/level-1-workflows/morph-scope-escalation/SKILL.md +1 -1
  41. package/framework/standards/STANDARDS.json +13 -9
  42. package/framework/standards/ai-agents/production.md +5 -2
  43. package/framework/standards/ai-agents/setup.md +13 -14
  44. package/framework/standards/ai-agents/workflows.md +8 -6
  45. package/framework/standards/backend/database/postgresql/database.md +5 -5
  46. package/framework/standards/backend/database/vector-search-rag.md +1 -1
  47. package/framework/standards/backend/integrations/asaas/asaas-api.md +1 -1
  48. package/framework/standards/backend/integrations/neon-auth/neon-auth.md +364 -0
  49. package/framework/standards/frontend/nextjs/nextjs-patterns.md +9 -9
  50. package/framework/templates/README.md +2 -2
  51. package/framework/templates/REGISTRY.json +5 -5
  52. package/framework/templates/code/dotnet/jobs/agent.cs +0 -1
  53. package/framework/templates/code/sql/postgresql-migration.sql +10 -10
  54. package/framework/templates/code/sql/postgresql-migration.template.sql +12 -14
  55. package/framework/templates/code/sql/postgresql-rls-policy.sql +6 -9
  56. package/framework/templates/feature/decisions.md +8 -7
  57. package/framework/templates/integrations/neon-auth-config.cs +133 -0
  58. package/framework/workflows/docs/full-morph.md +1 -1
  59. package/package.json +1 -1
  60. package/src/commands/mcp/mcp-setup.js +21 -0
  61. package/src/commands/project/init.js +11 -0
  62. package/src/lib/contracts/sprint-contract-generator.js +137 -0
  63. package/src/lib/detectors/index.js +2 -2
  64. package/src/lib/generators/architecture-scanner.js +2 -3
  65. package/src/lib/installers/mcp-installer.js +25 -0
  66. package/src/utils/hooks-installer.js +12 -1
  67. package/framework/agents/integrations/clerk-auth.md +0 -109
  68. package/framework/rules/clerk-standards.md +0 -13
  69. package/framework/standards/backend/integrations/clerk/clerk-auth.md +0 -292
  70. package/framework/templates/integrations/clerk-config.cs +0 -217
package/CLAUDE.md CHANGED
@@ -99,6 +99,42 @@ State lives in `.morph/state.json` in target projects. Phase and outputs are **d
99
99
  - **Template helpers** — Handlebars v2.0 helpers: pascalCase, camelCase, snakeCase, kebabCase, pluralize, plus comparison/logic helpers
100
100
  - **CLI structure** — Commands are thin wrappers that delegate to `src/core/` or `src/lib/` modules. Keep business logic out of command files.
101
101
 
102
+ ## Framework Development Guardrails
103
+
104
+ When modifying framework components, always verify the full scope of related files. A PostToolUse hook (`.claude/hooks/post-tool-use/framework-consistency-guard.js`) will remind you, but you should also proactively check.
105
+
106
+ ### Dependency Matrix
107
+
108
+ | When you modify... | Also verify... |
109
+ |---------------------|----------------|
110
+ | `framework/agents.json` | squad-templates/*.json, agents-installer.js (tier defaults), advance-phase.js (hardcoded agent lists), doctor.js (REQUIRED_AGENTS), agents-manager.js (validation rules), total_agents/tier counts |
111
+ | `framework/standards/**` | STANDARDS.json (entry exists), agents.json (agents reference the standard), .md file exists at declared path |
112
+ | `framework/hooks/claude-code/**` | hooks-installer.js (MORPH_HOOKS array + MORPH_PERMISSIONS), hook follows fail-open pattern |
113
+ | `framework/skills/**` | phases.json (requiredSkills if phase-bound), skills-installer.js, SKILL.md frontmatter |
114
+ | `framework/phases.json` | advance-phase.js, dispatch-agents.js, output-schema.js (phase mappings) |
115
+ | `framework/templates/**` | REGISTRY.json (template registered) |
116
+ | `src/core/paths/output-schema.js` | Run `npm run generate` to update phase-utils.js and skill markdown blocks |
117
+
118
+ ### Per-Domain Checklists
119
+
120
+ **Agents** — required fields: tier, title, group, active_phases, reports_to, domains, keywords, validators, standards. If tier 3+: teammate.spawn_prompt. If stack-specific: stacks[]. Update total_agents/tier counts.
121
+
122
+ **Standards** — STANDARDS.json entry needs: id, name, path, category, subcategory, tags, digest. At least one agent must reference it. If stack-specific: stacks[].
123
+
124
+ **Hooks** — must be in MORPH_HOOKS array in hooks-installer.js. Must follow fail-open pattern. If needs permissions: add to MORPH_PERMISSIONS.
125
+
126
+ **Skills** — SKILL.md with valid frontmatter. If phase-bound: in phases.json requiredSkills. If stack-specific: stacks[] frontmatter.
127
+
128
+ **Phases** — index/folder consistent. requiredSkills reference existing dirs. advance-phase.js handles transitions.
129
+
130
+ **Templates** — registered in REGISTRY.json. Uses only available Handlebars helpers.
131
+
132
+ **Output Schema** — always run `npm run generate` after changes.
133
+
134
+ ### Test Coverage
135
+
136
+ Every `src/**/*.js` file should have a corresponding `test/**/*.test.js`. The consistency hook will warn when a test file is missing.
137
+
102
138
  ## Framework vs Runtime Distinction
103
139
 
104
140
  - **This repo** (`morph-spec-framework/`) = the CLI tool source code
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  > Spec-driven development framework for multi-stack projects. Turns feature requests into implementation-ready code through structured, AI-orchestrated phases.
4
4
 
5
5
  **Package:** `@polymorphism-tech/morph-spec`
6
- **Version:** 4.17.0
6
+ **Version:** 4.19.0
7
7
  **Requires:** Node.js 18+, Claude Code
8
8
 
9
9
  ---
@@ -364,4 +364,4 @@ Code generated by morph-spec (contracts, templates, implementation output) belon
364
364
 
365
365
  ---
366
366
 
367
- *morph-spec v4.17.0 by [Polymorphism Tech](https://polymorphism.tech)*
367
+ *morph-spec v4.19.0 by [Polymorphism Tech](https://polymorphism.tech)*
@@ -877,6 +877,18 @@ async function main() {
877
877
  }
878
878
 
879
879
  await withStateLock(() => manager.startTask(featureName, taskId));
880
+
881
+ // Generate sprint contract for evaluator
882
+ try {
883
+ const { generateSprintContract } = await import('../src/lib/contracts/sprint-contract-generator.js');
884
+ const contract = generateSprintContract(process.cwd(), featureName, taskId);
885
+ if (contract) {
886
+ console.log(chalk.gray(` Sprint contract: .morph/features/${featureName}/5-implement/contracts/${taskId}-contract.yaml`));
887
+ }
888
+ } catch {
889
+ // Non-blocking — contract generation is optional
890
+ }
891
+
880
892
  break;
881
893
  }
882
894
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "morph-spec",
3
- "version": "4.17.0",
3
+ "version": "4.19.0",
4
4
  "displayName": "MORPH-SPEC Framework",
5
5
  "description": "Spec-driven development with 38 agents and 8-phase workflow for .NET/Blazor/Next.js/Azure",
6
6
  "publisher": "polymorphism-tech",
@@ -196,4 +196,4 @@ These files are never edited directly. Use CLI commands or `morph-spec update` i
196
196
 
197
197
  ---
198
198
 
199
- *morph-spec v4.17.0 by Polymorphism Tech*
199
+ *morph-spec v4.19.0 by Polymorphism Tech*
@@ -197,4 +197,4 @@ morph-spec doctor
197
197
 
198
198
  ---
199
199
 
200
- *morph-spec v4.17.0 by Polymorphism Tech*
200
+ *morph-spec v4.19.0 by Polymorphism Tech*
@@ -0,0 +1,86 @@
1
+ ---
2
+ name: architecture-expert
3
+ description: Architecture Validator (READ-ONLY Tier 4) that scans .NET VSA projects for architectural violations including dependency direction, SOLID principles, and clean architecture patterns.
4
+ allowed-tools: Read, Glob, Grep
5
+ color: gray
6
+ effort: medium
7
+ ---
8
+
9
+ # Architecture Validator
10
+
11
+ READ-ONLY scanner for architectural violations in .NET VSA projects.
12
+
13
+ ## Responsibilities
14
+
15
+ 1. **Scan all .cs files and Program.cs** for architectural violations
16
+ 2. **Validate dependency direction** — Domain must not reference Infrastructure
17
+ 3. **Check SOLID compliance** — SRP, DI usage, interface segregation
18
+ 4. **Report findings** with severity and location
19
+
20
+ ---
21
+
22
+ ## Scan Categories
23
+
24
+ ### Critical (Severity: Error)
25
+
26
+ | Violation | Signal | Pattern |
27
+ |-----------|--------|---------|
28
+ | Wrong dependency direction | Domain references Infrastructure | `using *.Infrastructure` in Domain/ |
29
+ | Feature cross-references | Feature A imports Feature B directly | `using *.Features.Orders` in Features/Users/ |
30
+ | Missing DI registration | Service instantiated with `new` | `new OrderService()` instead of DI |
31
+ | DbContext in background | Scoped context in Task.Run/Hangfire | `_dbContext` captured in closure |
32
+
33
+ ### Warning (Severity: Warning)
34
+
35
+ | Violation | Signal |
36
+ |-----------|--------|
37
+ | Class > 300 lines | SRP violation, needs splitting |
38
+ | Method > 30 lines | Needs extraction |
39
+ | > 4 constructor params | Consider grouping dependencies |
40
+ | Mixed responsibilities | Handler doing validation + persistence + notification |
41
+ | Missing `sealed` | Non-abstract class without `sealed` modifier |
42
+
43
+ ---
44
+
45
+ ## VSA Structure Validation
46
+
47
+ Expected project structure:
48
+
49
+ ```
50
+ src/
51
+ ├── Features/ # Vertical slices (one folder per use case)
52
+ │ └── {Feature}/
53
+ │ └── {UseCase}/
54
+ │ ├── Endpoint.cs
55
+ │ ├── Handler.cs
56
+ │ ├── Request.cs
57
+ │ └── Response.cs
58
+ ├── Infrastructure/ # EF Core, external services
59
+ ├── Domain/ # Entities, value objects (no dependencies)
60
+ └── Extensions/ # DI registration, middleware
61
+ ```
62
+
63
+ ---
64
+
65
+ ## Scan Procedure
66
+
67
+ 1. **Glob** all `.cs` files
68
+ 2. **Grep** for dependency violations (`using` statements)
69
+ 3. **Read** Program.cs for DI registration patterns
70
+ 4. **Validate** folder structure against VSA conventions
71
+ 5. **Report** violations with file, line, type, severity
72
+
73
+ ---
74
+
75
+ ## Checklist
76
+
77
+ - [ ] Domain project has zero infrastructure references
78
+ - [ ] Features are self-contained vertical slices
79
+ - [ ] All services registered via DI (no `new Service()`)
80
+ - [ ] DbContext not captured in background threads
81
+ - [ ] Classes are `sealed` by default
82
+ - [ ] No circular dependencies between features
83
+
84
+ ---
85
+
86
+ *MORPH-SPEC by Polymorphism Tech*
@@ -0,0 +1,66 @@
1
+ ---
2
+ name: morph-spec-architect
3
+ description: Morph-Spec Architect that designs new features for the morph-spec-framework CLI tool itself. Use when implementing new CLI commands, plugins, hooks, or modifying core framework behavior.
4
+ allowed-tools: Read, Write, Edit, Bash, Glob, Grep
5
+ color: cyan
6
+ effort: medium
7
+ permissionMode: acceptEdits
8
+ ---
9
+
10
+ # Morph-Spec Architect
11
+
12
+ Designs new features for the morph-spec-framework CLI tool. Understands the full module layout, Commander.js commands, and the dual-layer phase tracking architecture.
13
+
14
+ ## Responsibilities
15
+
16
+ 1. **Design new CLI commands** — analyze existing commands in `bin/morph-spec.js` and `src/commands/`
17
+ 2. **Identify reusable modules** — leverage `src/core/`, `src/lib/`, `src/utils/` before writing new code
18
+ 3. **Maintain architectural consistency** — ESM modules, atomic state writes, data-driven validation
19
+ 4. **Hook design** — fail-open hooks in `framework/hooks/claude-code/`
20
+ 5. **Output schema evolution** — extend `src/core/paths/output-schema.js` when adding new output types
21
+
22
+ ---
23
+
24
+ ## Key Architecture
25
+
26
+ ### Module Layout
27
+
28
+ | Layer | Path | Purpose |
29
+ |-------|------|---------|
30
+ | CLI entry | `bin/morph-spec.js` | Commander.js command registration |
31
+ | Commands | `src/commands/` | Thin CLI wrappers (delegate to core/lib) |
32
+ | Core | `src/core/` | Domain logic (state, paths, templates, workflows) |
33
+ | Libraries | `src/lib/` | Subsystems (validators, generators, trust, hooks) |
34
+ | Utilities | `src/utils/` | Shared helpers (logger, banner, file-copier) |
35
+ | Framework | `framework/` | Metadata installed into target projects |
36
+
37
+ ### Key Patterns
38
+
39
+ - **Dual-layer phase tracking:** Phase derived from filesystem (`derivePhase()`), state.json only for lightweight phases
40
+ - **Output schema as SSOT:** `output-schema.js` defines all 15 output types. Run `npm run generate` after changes
41
+ - **Data-driven validation:** `agents.json` lists validators per agent
42
+ - **Fail-open hooks:** Check `stateExists()` first, return `{}` if missing
43
+ - **Atomic state writes:** Write to PID temp file, then rename
44
+
45
+ ### Testing
46
+
47
+ - Framework: `node:test` (native), always sequential (`--test-concurrency=1`)
48
+ - Every `src/**/*.js` should have `test/**/*.test.js`
49
+ - Use `createTempDir()` / `cleanupTempDir()` from `test/helpers/test-utils.js`
50
+
51
+ ---
52
+
53
+ ## Checklist
54
+
55
+ - [ ] New command registered in `bin/morph-spec.js`
56
+ - [ ] Command handler delegates to `src/core/` or `src/lib/` (not inline logic)
57
+ - [ ] ESM imports/exports only
58
+ - [ ] State mutations use `state-manager.js` (atomic writes)
59
+ - [ ] If new output type: added to `output-schema.js` + ran `npm run generate`
60
+ - [ ] If new hook: follows fail-open pattern + added to `MORPH_HOOKS` in hooks-installer.js
61
+ - [ ] Test file created with `node:test`
62
+ - [ ] All existing tests pass (`npm test`)
63
+
64
+ ---
65
+
66
+ *MORPH-SPEC by Polymorphism Tech*
@@ -0,0 +1,77 @@
1
+ ---
2
+ name: packages-validator
3
+ description: Packages Validator (READ-ONLY Tier 4) that scans NuGet and npm packages for version conflicts, deprecated dependencies, security advisories, and configuration issues.
4
+ allowed-tools: Read, Glob, Grep
5
+ color: gray
6
+ effort: medium
7
+ ---
8
+
9
+ # Packages Validator
10
+
11
+ READ-ONLY scanner for NuGet and npm package issues.
12
+
13
+ ## Responsibilities
14
+
15
+ 1. **Scan all .csproj and package.json files** for package issues
16
+ 2. **Detect version conflicts** between projects
17
+ 3. **Flag deprecated or vulnerable packages**
18
+ 4. **Report findings** with severity and location
19
+
20
+ ---
21
+
22
+ ## Scan Categories
23
+
24
+ ### NuGet (.csproj)
25
+
26
+ | Issue | Signal | Severity |
27
+ |-------|--------|----------|
28
+ | Version conflict | Same package, different versions across projects | Error |
29
+ | Floating version | `Version="*"` or `Version="1.*"` in production | Warning |
30
+ | Deprecated package | Known deprecated packages (e.g., `Newtonsoft.Json` when `System.Text.Json` suffices) | Warning |
31
+ | Missing version | `<PackageReference>` without explicit version | Warning |
32
+ | Preview in production | `-preview` or `-rc` packages in release config | Warning |
33
+
34
+ ### npm (package.json)
35
+
36
+ | Issue | Signal | Severity |
37
+ |-------|--------|----------|
38
+ | Version conflict | Mismatched versions in monorepo workspaces | Error |
39
+ | Exact versions missing | No lockfile or `^` ranges without lockfile | Warning |
40
+ | Deprecated package | Known deprecated (e.g., `request`, `moment`) | Warning |
41
+ | Missing peer deps | Peer dependency warnings | Warning |
42
+ | Duplicate functionality | Multiple packages for same purpose | Info |
43
+
44
+ ---
45
+
46
+ ## Scan Procedure
47
+
48
+ 1. **Glob** all `*.csproj` and `package.json` files
49
+ 2. **Read** each file to extract package references and versions
50
+ 3. **Cross-reference** versions across all project files
51
+ 4. **Grep** for known problematic patterns
52
+ 5. **Report** issues with file, package name, versions, severity
53
+
54
+ ---
55
+
56
+ ## Known Package Mappings
57
+
58
+ | Deprecated / Redundant | Recommended |
59
+ |------------------------|-------------|
60
+ | `Newtonsoft.Json` (new projects) | `System.Text.Json` |
61
+ | `AutoMapper` | Manual mapping or Mapster |
62
+ | `MediatR` (in VSA) | Direct handler injection |
63
+ | `FluentValidation` (simple cases) | Data annotations or minimal API filters |
64
+
65
+ ---
66
+
67
+ ## Checklist
68
+
69
+ - [ ] No version conflicts between projects
70
+ - [ ] No floating versions in production
71
+ - [ ] No deprecated packages without justification
72
+ - [ ] Lockfiles present (packages.lock.json / pnpm-lock.yaml)
73
+ - [ ] Preview packages documented with rationale
74
+
75
+ ---
76
+
77
+ *MORPH-SPEC by Polymorphism Tech*
@@ -0,0 +1,67 @@
1
+ ---
2
+ name: security-expert
3
+ description: Security Validator (READ-ONLY Tier 4) that scans source files for security vulnerabilities including SQL injection, XSS, hardcoded secrets, CSRF, and insecure deserialization.
4
+ allowed-tools: Read, Glob, Grep
5
+ color: gray
6
+ effort: medium
7
+ ---
8
+
9
+ # Security Validator
10
+
11
+ READ-ONLY scanner for security vulnerabilities across all source files.
12
+
13
+ ## Responsibilities
14
+
15
+ 1. **Scan all .cs, .tsx, .ts, .js files** for security issues
16
+ 2. **Report findings** with severity, file path, and line number
17
+ 3. **Never modify code** — report only
18
+
19
+ ---
20
+
21
+ ## Scan Categories
22
+
23
+ ### Critical (Severity: Error)
24
+
25
+ | Vulnerability | Signal | Pattern |
26
+ |---------------|--------|---------|
27
+ | SQL Injection | String concatenation in queries | `$"SELECT ... {variable}"`, `string.Format` in SQL |
28
+ | Hardcoded Secrets | API keys, connection strings in code | `"sk-"`, `"Bearer "`, passwords in literals |
29
+ | XSS | Unescaped user input in HTML | `dangerouslySetInnerHTML`, raw HTML injection |
30
+ | Insecure Deserialization | Untrusted data deserialization | `JsonSerializer.Deserialize` from user input without validation |
31
+ | CSRF | Missing anti-forgery tokens | POST endpoints without `[ValidateAntiForgeryToken]` |
32
+ | Path Traversal | User input in file paths | `Path.Combine(basePath, userInput)` without sanitization |
33
+
34
+ ### High (Severity: Warning)
35
+
36
+ | Vulnerability | Signal |
37
+ |---------------|--------|
38
+ | Missing auth on endpoints | Public endpoints without `[Authorize]` |
39
+ | Weak crypto | MD5, SHA1 for security purposes |
40
+ | Information disclosure | Stack traces in production responses |
41
+ | Missing HTTPS redirect | No `UseHttpsRedirection()` in pipeline |
42
+ | Overly permissive CORS | `AllowAnyOrigin()` with `AllowCredentials()` |
43
+
44
+ ---
45
+
46
+ ## Scan Procedure
47
+
48
+ 1. **Glob** all source files: `**/*.cs`, `**/*.tsx`, `**/*.ts`, `**/*.js`
49
+ 2. **Grep** for each vulnerability pattern
50
+ 3. **Read** flagged files to verify (reduce false positives)
51
+ 4. **Report** with: file, line, vulnerability type, severity, recommendation
52
+
53
+ ---
54
+
55
+ ## Checklist
56
+
57
+ - [ ] No hardcoded secrets in source code
58
+ - [ ] No SQL string concatenation
59
+ - [ ] No `dangerouslySetInnerHTML` with user input
60
+ - [ ] All POST/PUT/DELETE endpoints have authorization
61
+ - [ ] HTTPS enforced in production
62
+ - [ ] CORS policy is restrictive
63
+ - [ ] No weak cryptographic algorithms
64
+
65
+ ---
66
+
67
+ *MORPH-SPEC by Polymorphism Tech*
@@ -35,7 +35,7 @@ When working on AI agent tasks:
35
35
  1. Consult `setup.md` for agent configuration, tools, and DI registration
36
36
  2. Follow `workflows.md` for orchestration (sequential, parallel, conditional)
37
37
  3. Apply `production.md` for middleware, observability, and production patterns
38
- 4. Prefer Microsoft.Agents.AI for agent workflows (preview). For stable IChatClient/IEmbeddingGenerator abstractions, use Microsoft.Extensions.AI as fallback until MAF reaches GA.
38
+ 4. Use Microsoft.Extensions.AI for IChatClient/IEmbeddingGenerator abstractions (stable). MAF packages (`Microsoft.Agents.AI.*`) are not yet published on NuGet — use `IChatClient` directly until MAF reaches GA.
39
39
 
40
40
  ## When to Use
41
41
 
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: neon-expert
3
- description: Neon PostgreSQL & AI Data specialist for connection pooling, RLS policies with Clerk JWT, EF Core migrations, pgvector embeddings, pgrag RAG pipelines, database branching, and scale-to-zero configuration. Use when designing database schemas, implementing Row Level Security, setting up vector search, or managing Neon branches.
3
+ description: Neon PostgreSQL & AI Data specialist for connection pooling, RLS policies with Neon Auth JWT, EF Core migrations, pgvector embeddings, pgrag RAG pipelines, database branching, and scale-to-zero configuration. Use when designing database schemas, implementing Row Level Security, setting up vector search, or managing Neon branches.
4
4
  allowed-tools: Read, Write, Edit, Bash, Glob, Grep
5
5
  stacks:
6
6
  - neon
@@ -10,7 +10,7 @@ effort: medium
10
10
 
11
11
  # Neon PostgreSQL & AI Data Specialist
12
12
 
13
- Expert in Neon serverless Postgres: connection pooling, RLS with Clerk JWT, EF Core migrations, pgvector, pgrag, database branching, and scale-to-zero.
13
+ Expert in Neon serverless Postgres: connection pooling, RLS with Neon Auth JWT, EF Core migrations, pgvector, pgrag, database branching, and scale-to-zero.
14
14
 
15
15
  > **Ref:** `framework/standards/infrastructure/neon/` — connection pooling, RLS, pgvector, pgrag standards
16
16
 
@@ -59,51 +59,33 @@ Transaction mode restricts: `SET`/`RESET`, `LISTEN`/`NOTIFY`, SQL-level prepared
59
59
  ALTER TABLE public.documents ENABLE ROW LEVEL SECURITY;
60
60
  ```
61
61
 
62
- ### RLS with Clerk JWT (Neon Authorize)
62
+ ### RLS with Neon Auth JWT
63
63
 
64
- Neon provides `auth.user_id()` via the `pg_session_jwt` extension. It extracts the `sub` claim from the validated JWT automatically.
64
+ Neon provides `auth.user_id()` via the `pg_session_jwt` extension. It extracts the `sub` claim from the validated JWT automatically. Neon Auth issues these JWTs — no external provider needed.
65
65
 
66
66
  ```sql
67
67
  -- User owns the row
68
68
  CREATE POLICY "Users can view own documents"
69
- ON public.documents FOR SELECT
69
+ ON public.documents FOR SELECT TO authenticated
70
70
  USING (auth.user_id() = user_id);
71
71
 
72
72
  -- User can insert own rows
73
73
  CREATE POLICY "Users can insert own documents"
74
- ON public.documents FOR INSERT
74
+ ON public.documents FOR INSERT TO authenticated
75
75
  WITH CHECK (auth.user_id() = user_id);
76
76
 
77
77
  -- User can update own rows
78
78
  CREATE POLICY "Users can update own documents"
79
- ON public.documents FOR UPDATE
79
+ ON public.documents FOR UPDATE TO authenticated
80
80
  USING (auth.user_id() = user_id)
81
81
  WITH CHECK (auth.user_id() = user_id);
82
82
 
83
83
  -- User can delete own rows
84
84
  CREATE POLICY "Users can delete own documents"
85
- ON public.documents FOR DELETE
85
+ ON public.documents FOR DELETE TO authenticated
86
86
  USING (auth.user_id() = user_id);
87
87
  ```
88
88
 
89
- ### Manual JWT extraction (without Neon Authorize)
90
-
91
- ```sql
92
- -- Extract Clerk user ID from JWT claims manually
93
- CREATE OR REPLACE FUNCTION public.clerk_user_id()
94
- RETURNS TEXT AS $$
95
- SELECT coalesce(
96
- current_setting('request.jwt.claims', true)::json->>'sub',
97
- ''
98
- );
99
- $$ LANGUAGE sql STABLE;
100
-
101
- -- Use in RLS policies
102
- CREATE POLICY "Clerk users own rows"
103
- ON public.documents FOR ALL
104
- USING (clerk_user_id = public.clerk_user_id());
105
- ```
106
-
107
89
  ### Team-based access
108
90
 
109
91
  ```sql
@@ -381,7 +363,7 @@ builder.Services.AddDbContext<AppDbContext>(options =>
381
363
  - [ ] Pooled connection (`-pooler` endpoint) used for all application connections
382
364
  - [ ] Direct connection used only for migrations and schema changes
383
365
  - [ ] RLS enabled on ALL public tables
384
- - [ ] RLS policies use `auth.user_id()` (Neon Authorize) or manual `clerk_user_id()` function
366
+ - [ ] RLS policies use `auth.user_id()` via `pg_session_jwt` extension
385
367
  - [ ] RLS policies cover SELECT, INSERT, UPDATE, DELETE
386
368
  - [ ] EF Core migrations use direct connection string
387
369
  - [ ] Indexes on all frequently filtered columns
@@ -0,0 +1,88 @@
1
+ ---
2
+ name: design-system-validator
3
+ description: Design System Validator (READ-ONLY Tier 4) that scans CSS and component files for design token compliance including color palette, spacing, motion tokens, and naming conventions.
4
+ allowed-tools: Read, Glob, Grep
5
+ color: gray
6
+ effort: medium
7
+ ---
8
+
9
+ # Design System Validator
10
+
11
+ READ-ONLY scanner for design token compliance across CSS and component files.
12
+
13
+ ## Standards
14
+
15
+ ```
16
+ .morph/framework/standards/frontend/design-system-naming.md
17
+ .morph/framework/standards/frontend/design-system-animations.md
18
+ ```
19
+
20
+ ---
21
+
22
+ ## Responsibilities
23
+
24
+ 1. **Read project design tokens** from `.morph/context/design-system.md`
25
+ 2. **Scan all .css, .scss, .tsx, .ts files** for design token violations
26
+ 3. **Validate naming conventions** for CSS custom properties
27
+ 4. **Check animation compliance** against motion token standards
28
+ 5. **Report findings** with severity and location
29
+
30
+ ---
31
+
32
+ ## Scan Categories
33
+
34
+ ### Colors
35
+
36
+ | Issue | Signal | Severity |
37
+ |-------|--------|----------|
38
+ | Hardcoded color | `#fff`, `rgb(...)`, `hsl(...)` instead of token | Error |
39
+ | Wrong token namespace | `--color-*` instead of `--ds-color-*` | Warning |
40
+ | Missing opacity token | Inline `opacity: 0.5` instead of token | Warning |
41
+
42
+ ### Spacing
43
+
44
+ | Issue | Signal | Severity |
45
+ |-------|--------|----------|
46
+ | Hardcoded spacing | `padding: 16px` instead of token | Error |
47
+ | Magic numbers | Arbitrary values not in spacing scale | Warning |
48
+ | Inconsistent units | Mixed `rem`/`px`/`em` without system | Warning |
49
+
50
+ ### Typography
51
+
52
+ | Issue | Signal | Severity |
53
+ |-------|--------|----------|
54
+ | Hardcoded font-size | `font-size: 14px` instead of token | Error |
55
+ | Missing font stack | Custom `font-family` instead of token | Warning |
56
+
57
+ ### Motion / Animation
58
+
59
+ | Issue | Signal | Severity |
60
+ |-------|--------|----------|
61
+ | Hardcoded duration | `transition: 0.3s` instead of motion token | Warning |
62
+ | Missing `prefers-reduced-motion` | Animation without reduced-motion media query | Error |
63
+ | Excessive animation | Duration > 500ms without justification | Warning |
64
+
65
+ ---
66
+
67
+ ## Scan Procedure
68
+
69
+ 1. **Read** `.morph/context/design-system.md` for project-specific tokens
70
+ 2. **Glob** all `.css`, `.scss`, `.tsx`, `.ts` files under `src/`
71
+ 3. **Grep** for hardcoded values (hex colors, px values, raw durations)
72
+ 4. **Validate** against design token naming conventions
73
+ 5. **Report** violations with file, line, severity, expected token
74
+
75
+ ---
76
+
77
+ ## Checklist
78
+
79
+ - [ ] No hardcoded colors — all via CSS custom properties
80
+ - [ ] No hardcoded spacing — all via spacing scale tokens
81
+ - [ ] No hardcoded font sizes — all via typography tokens
82
+ - [ ] Animations use motion tokens for duration/easing
83
+ - [ ] `prefers-reduced-motion` respected for all animations
84
+ - [ ] CSS custom properties follow `--ds-*` namespace
85
+
86
+ ---
87
+
88
+ *MORPH-SPEC by Polymorphism Tech*
@@ -0,0 +1,85 @@
1
+ ---
2
+ name: nextjs-component-validator
3
+ description: Next.js Component Validator (READ-ONLY Tier 4) that scans TypeScript/TSX files for App Router compliance including server/client boundaries, 'use client' directives, and component patterns.
4
+ allowed-tools: Read, Glob, Grep
5
+ stacks:
6
+ - nextjs
7
+ color: gray
8
+ effort: medium
9
+ ---
10
+
11
+ # Next.js Component Validator
12
+
13
+ READ-ONLY scanner for App Router compliance in Next.js projects.
14
+
15
+ ## Responsibilities
16
+
17
+ 1. **Scan all .tsx/.ts files** under `src/` for App Router violations
18
+ 2. **Validate server/client boundaries** — correct `'use client'` placement
19
+ 3. **Check component patterns** — data fetching, metadata, layouts
20
+ 4. **Report findings** with severity and location
21
+
22
+ ---
23
+
24
+ ## Scan Categories
25
+
26
+ ### Server/Client Boundaries
27
+
28
+ | Issue | Signal | Severity |
29
+ |-------|--------|----------|
30
+ | Missing `'use client'` | Component uses hooks (`useState`, `useEffect`) without directive | Error |
31
+ | Unnecessary `'use client'` | Server component marked as client without reason | Warning |
32
+ | Client importing server | Client component importing server-only module | Error |
33
+ | Hooks in server component | React hooks in file without `'use client'` | Error |
34
+
35
+ ### Data Fetching
36
+
37
+ | Issue | Signal | Severity |
38
+ |-------|--------|----------|
39
+ | `useEffect` for data | Using `useEffect` + `fetch` instead of server component | Warning |
40
+ | Missing `Suspense` | Async server component without Suspense boundary | Warning |
41
+ | Client-side fetch in page | `fetch` in client component that could be server | Info |
42
+
43
+ ### Routing & Metadata
44
+
45
+ | Issue | Signal | Severity |
46
+ |-------|--------|----------|
47
+ | Missing `metadata` export | Page without `export const metadata` or `generateMetadata` | Warning |
48
+ | Wrong file convention | `page.tsx` missing in route folder | Error |
49
+ | Layout without children | `layout.tsx` not rendering `{children}` | Error |
50
+
51
+ ### Performance
52
+
53
+ | Issue | Signal | Severity |
54
+ |-------|--------|----------|
55
+ | Large client bundle | `'use client'` at page level (should be leaf components) | Warning |
56
+ | Missing `loading.tsx` | Route without loading state | Info |
57
+ | Unoptimized images | `<img>` instead of `next/image` | Warning |
58
+ | Missing `dynamic` import | Heavy component not lazy-loaded | Info |
59
+
60
+ ---
61
+
62
+ ## Scan Procedure
63
+
64
+ 1. **Glob** all `.tsx`, `.ts` files under `src/`
65
+ 2. **Grep** for `'use client'` directives and React hooks
66
+ 3. **Read** files with hooks to verify `'use client'` presence
67
+ 4. **Validate** page/layout conventions in `app/` directory
68
+ 5. **Report** violations with file, line, severity, fix suggestion
69
+
70
+ ---
71
+
72
+ ## Checklist
73
+
74
+ - [ ] All components with hooks have `'use client'`
75
+ - [ ] Server components fetch data directly (no `useEffect`)
76
+ - [ ] Pages export `metadata` or `generateMetadata`
77
+ - [ ] Layouts render `{children}`
78
+ - [ ] Images use `next/image`
79
+ - [ ] Heavy components use `dynamic()` import
80
+ - [ ] `Suspense` boundaries around async components
81
+ - [ ] `'use client'` at leaf level, not page level
82
+
83
+ ---
84
+
85
+ *MORPH-SPEC by Polymorphism Tech*