@polymorphism-tech/morph-spec 6.0.0 → 7.1.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 (114) hide show
  1. package/README.md +367 -366
  2. package/docs/CHEATSHEET.md +3 -3
  3. package/docs/QUICKSTART.md +4 -4
  4. package/framework/CLAUDE.md +13 -0
  5. package/framework/MORPH.md +57 -36
  6. package/framework/agents.json +132 -127
  7. package/framework/commands/morph-apply.md +4 -21
  8. package/framework/commands/morph-archive.md +1 -1
  9. package/framework/commands/morph-proposal.md +2 -0
  10. package/framework/hooks/claude-code/core/enforce-phase-writes.js +1 -1
  11. package/framework/hooks/claude-code/core/protect-spec-files.js +1 -1
  12. package/framework/hooks/claude-code/core/state-sync.js +212 -0
  13. package/framework/hooks/shared/phase-utils.js +5 -4
  14. package/framework/hooks/shared/state-reader.js +1 -1
  15. package/framework/phases.json +1 -1
  16. package/framework/rubrics/backend.json +41 -36
  17. package/framework/rules/ai-agents-standards.md +45 -15
  18. package/framework/rules/morph-workflow.md +15 -34
  19. package/framework/rules/neon-standards.md +25 -26
  20. package/framework/schemas/tasks.schema.json +35 -0
  21. package/framework/skills/core/morph-apply/SKILL.md +154 -0
  22. package/framework/skills/core/morph-brainstorming/SKILL.md +53 -30
  23. package/framework/skills/core/morph-implement/SKILL.md +25 -14
  24. package/framework/skills/core/morph-plan/SKILL.md +91 -23
  25. package/framework/skills/core/morph-proposal/SKILL.md +137 -0
  26. package/framework/skills/core/morph-review/SKILL.md +43 -7
  27. package/framework/skills/core/morph-stack-scan/SKILL.md +40 -1
  28. package/framework/standards/STANDARDS.json +1729 -1134
  29. package/framework/standards/ai-agents/agent-session.md +160 -0
  30. package/framework/standards/ai-agents/batching.md +193 -0
  31. package/framework/standards/ai-agents/context-providers.md +188 -0
  32. package/framework/standards/ai-agents/mcp-server.md +250 -0
  33. package/framework/standards/ai-agents/mcp-tools.md +197 -0
  34. package/framework/standards/ai-agents/middleware-patterns.md +207 -0
  35. package/framework/standards/ai-agents/modalities-image-gen.md +173 -0
  36. package/framework/standards/ai-agents/modalities-speech-to-text.md +171 -0
  37. package/framework/standards/ai-agents/modalities-text-to-speech.md +181 -0
  38. package/framework/standards/ai-agents/modalities-vision.md +201 -0
  39. package/framework/standards/ai-agents/multi-agent-patterns.md +155 -0
  40. package/framework/standards/ai-agents/production.md +114 -258
  41. package/framework/standards/ai-agents/prompts-in-db.md +214 -0
  42. package/framework/standards/ai-agents/providers/model-registry.md +158 -0
  43. package/framework/standards/ai-agents/rag-custom-pgvector.md +243 -0
  44. package/framework/standards/ai-agents/service-tier-flex.md +135 -0
  45. package/framework/standards/ai-agents/setup.md +142 -316
  46. package/framework/standards/ai-agents/structured-output.md +249 -0
  47. package/framework/standards/ai-agents/sweet-spot.md +109 -0
  48. package/framework/standards/ai-agents/workflows.md +114 -284
  49. package/framework/standards/architecture/vertical-slice/vertical-slice.md +433 -429
  50. package/framework/standards/backend/api/validation.md +92 -88
  51. package/framework/standards/backend/database/postgresql/database.md +336 -332
  52. package/framework/standards/backend/database/vector-search-rag.md +599 -541
  53. package/framework/standards/backend/dotnet/fluent-validation-vsa.md +4 -0
  54. package/framework/standards/backend/dotnet/result-pattern.md +4 -0
  55. package/framework/standards/backend/dotnet/scalar-ui.md +176 -172
  56. package/framework/standards/backend/dotnet/scrutor.md +4 -0
  57. package/framework/standards/backend/dotnet/vsa-handler-patterns.md +278 -274
  58. package/framework/standards/backend/integrations/asaas/asaas-api.md +260 -216
  59. package/framework/standards/backend/integrations/hangfire/hangfire-jobs.md +354 -350
  60. package/framework/standards/backend/integrations/neon-auth/neon-auth.md +30 -19
  61. package/framework/standards/backend/integrations/resend/resend-email.md +400 -385
  62. package/framework/standards/data/nosql/cache/redis.md +106 -97
  63. package/framework/standards/data/nosql/cosmos-db.md +127 -118
  64. package/framework/standards/data/vector-search/rag-chunking.md +113 -104
  65. package/framework/standards/frontend/design-system/ai-image-generation.md +4 -0
  66. package/framework/standards/frontend/design-system/animations.md +164 -160
  67. package/framework/standards/frontend/design-system/naming.md +68 -64
  68. package/framework/standards/frontend/gsap/gsap-core.md +14 -8
  69. package/framework/standards/frontend/gsap/gsap-plugins.md +26 -21
  70. package/framework/standards/frontend/gsap/gsap-scrolltrigger.md +9 -7
  71. package/framework/standards/frontend/nextjs/app-router.md +127 -123
  72. package/framework/standards/frontend/nextjs/components.md +136 -132
  73. package/framework/standards/frontend/nextjs/data-fetching.md +130 -126
  74. package/framework/standards/frontend/nextjs/forms.md +134 -128
  75. package/framework/standards/frontend/nextjs/motion-patterns.md +328 -322
  76. package/framework/standards/frontend/nextjs/naming-conventions.md +71 -67
  77. package/framework/standards/frontend/nextjs/nextjs-patterns.md +229 -225
  78. package/framework/standards/frontend/nextjs/project-structure.md +106 -102
  79. package/framework/standards/frontend/nextjs/state-management.md +76 -72
  80. package/framework/standards/frontend/nextjs/testing.md +115 -111
  81. package/framework/standards/infrastructure/docker/easypanel-deploy.md +196 -192
  82. package/framework/standards/infrastructure/neon/neon-pgrag.md +6 -2
  83. package/framework/standards/infrastructure/neon/neon-pgvector.md +4 -0
  84. package/framework/standards/infrastructure/neon/neon-setup.md +5 -1
  85. package/framework/standards/integration/mcp/mcp-tools.md +471 -462
  86. package/framework/templates/REGISTRY.json +1745 -1239
  87. package/framework/templates/code/dotnet/ai-agents/AgentBootstrap.cs.template +39 -0
  88. package/framework/templates/code/dotnet/ai-agents/EmbeddingService.cs.template +68 -0
  89. package/framework/templates/code/dotnet/ai-agents/ModelRegistry.cs.template +117 -0
  90. package/framework/templates/code/dotnet/ai-agents/PromptRepository.cs.template +95 -0
  91. package/framework/templates/code/dotnet/ai-agents/ResilientToolMiddleware.cs.template +61 -0
  92. package/framework/templates/code/dotnet/ai-agents/VectorSearchTool.cs.template +107 -0
  93. package/framework/templates/code/dotnet/ai-agents/model-registry.json.template +58 -0
  94. package/framework/templates/code/sql/ai-agents/agent-prompts-migration.sql.template +58 -0
  95. package/framework/templates/code/sql/ai-agents/pgvector-embeddings-migration.sql.template +91 -0
  96. package/framework/templates/docs/onboarding.md +4 -4
  97. package/framework/templates/tasks.template.json +17 -0
  98. package/package.json +89 -83
  99. package/src/commands/project/init.js +16 -0
  100. package/src/commands/validation/validate-feature.js +1 -1
  101. package/src/core/paths/output-schema.js +6 -6
  102. package/src/core/state/state-manager.js +1 -1
  103. package/src/core/templates/template-registry.js +289 -256
  104. package/src/lib/detectors/design-system-detector.js +1 -1
  105. package/src/lib/generators/context-generator.js +516 -518
  106. package/src/lib/generators/scaffold-generator.js +23 -26
  107. package/src/lib/installers/memory-installer.js +138 -0
  108. package/src/lib/phase-chain/phase-validator.js +4 -4
  109. package/src/lib/risk-detector.js +80 -0
  110. package/src/lib/tasks/tasks-json-parser.js +185 -0
  111. package/src/scripts/setup-infra.js +25 -0
  112. package/src/utils/hooks-installer.js +59 -10
  113. package/framework/standards/infrastructure/neon/neon-semantic-kernel.md +0 -310
  114. package/framework/templates/integrations/semantic-kernel-neon.cs +0 -125
@@ -1,128 +1,134 @@
1
- # Next.js Forms Standard
2
-
3
- > **Scope:** frontend/nextjs/forms
4
- > **Layer:** 2 (on keyword)
5
- > **Keywords:** form, react-hook-form, zod, validation, input, submit, zodResolver
6
- > **Load When:** implementing any form in Next.js
7
-
8
- react-hook-form + Zod + shadcn Form components. Schema defines both validation rules and TypeScript types.
9
-
10
- ## Core Rules
11
-
12
- - ALWAYS define the Zod schema first — derive the TypeScript type from it with `z.infer<>`
13
- - ALWAYS use `zodResolver` to connect schema to react-hook-form
14
- - ALWAYS use shadcn `<Form>`, `<FormField>`, `<FormItem>`, `<FormMessage>` for consistent UI
15
- - NEVER use `useState` for form field values — react-hook-form handles this
16
- - ALWAYS use `useMutation` from TanStack Query for form submission
17
-
18
- ## Complete Form Pattern
19
-
20
- ```tsx
21
- // features/users/types/user.schemas.ts
22
- import { z } from 'zod';
23
-
24
- export const createUserSchema = z.object({
25
- name: z.string().min(2, 'Name must be at least 2 characters'),
26
- email: z.string().email('Invalid email address'),
27
- role: z.enum(['admin', 'user'], { required_error: 'Role is required' }),
28
- });
29
-
30
- export type CreateUserInput = z.infer<typeof createUserSchema>;
31
- ```
32
-
33
- ```tsx
34
- // features/users/components/create-user-form.tsx
35
- 'use client';
36
-
37
- import { useForm } from 'react-hook-form';
38
- import { zodResolver } from '@hookform/resolvers/zod';
39
- import {
40
- Form, FormControl, FormField, FormItem, FormLabel, FormMessage
41
- } from '@/components/ui/form';
42
- import { Input } from '@/components/ui/input';
43
- import { Button } from '@/components/ui/button';
44
- import { useCreateUser } from '@/features/users/hooks/use-create-user';
45
- import { createUserSchema, type CreateUserInput } from '@/features/users/types/user.schemas';
46
-
47
- export function CreateUserForm({ onSuccess }: { onSuccess?: () => void }) {
48
- const form = useForm<CreateUserInput>({
49
- resolver: zodResolver(createUserSchema),
50
- defaultValues: { name: '', email: '', role: 'user' },
51
- });
52
-
53
- const { mutate: createUser, isPending } = useCreateUser();
54
-
55
- function onSubmit(values: CreateUserInput) {
56
- createUser(values, {
57
- onSuccess: () => { form.reset(); onSuccess?.(); },
58
- onError: (error) => form.setError('root', { message: error.message }),
59
- });
60
- }
61
-
62
- return (
63
- <Form {...form}>
64
- <form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
65
- <FormField
66
- control={form.control}
67
- name="name"
68
- render={({ field }) => (
69
- <FormItem>
70
- <FormLabel>Name</FormLabel>
71
- <FormControl><Input placeholder="John Doe" {...field} /></FormControl>
72
- <FormMessage />
73
- </FormItem>
74
- )}
75
- />
76
- <FormField
77
- control={form.control}
78
- name="email"
79
- render={({ field }) => (
80
- <FormItem>
81
- <FormLabel>Email</FormLabel>
82
- <FormControl><Input type="email" {...field} /></FormControl>
83
- <FormMessage />
84
- </FormItem>
85
- )}
86
- />
87
- {form.formState.errors.root && (
88
- <p className="text-sm text-destructive">{form.formState.errors.root.message}</p>
89
- )}
90
- <Button type="submit" disabled={isPending}>
91
- {isPending ? 'Creating...' : 'Create User'}
92
- </Button>
93
- </form>
94
- </Form>
95
- );
96
- }
97
- ```
98
-
99
- ## Edit Form Pattern
100
-
101
- ```tsx
102
- // Edit forms reuse the same schema with partial()
103
- const form = useForm<UpdateUserInput>({
104
- resolver: zodResolver(updateUserSchema),
105
- defaultValues: { name: user.name, email: user.email },
106
- });
107
- ```
108
-
109
- ## Schema Composition
110
-
111
- ```ts
112
- export const userSchema = z.object({ id: z.string(), name: z.string(), email: z.string() });
113
- export const createUserSchema = userSchema.omit({ id: true });
114
- export const updateUserSchema = createUserSchema.partial();
115
- ```
116
-
117
- ## Common Mistakes
118
-
119
- | Wrong | Right | Why |
120
- |-------|-------|-----|
121
- | `useState` for each field | `useForm` | Unnecessary re-renders on every keystroke |
122
- | Manual error display | `<FormMessage />` | Consistent UI, auto-connects to field errors |
123
- | `fetch` in submit handler | `useMutation` | Loading state, error handling, cache invalidation |
124
- | Type written manually | `z.infer<typeof schema>` | Single source of truth |
125
-
126
- ---
127
-
128
- *MORPH-SPEC by Polymorphism Tech*
1
+ # Next.js Forms Standard
2
+
3
+ > **Scope:** frontend/nextjs/forms
4
+ > **Layer:** 2 (on keyword)
5
+ > **Keywords:** form, react-hook-form, zod, validation, input, submit, zodResolver
6
+ > **Load When:** implementing any form in Next.js
7
+
8
+ **Verified against:** Next.js 15 + react-hook-form 7 + Zod 4 + @hookform/resolvers 3. Last-verified: 2026-05-20.
9
+
10
+ ---
11
+
12
+ react-hook-form + Zod + shadcn Form components. Schema defines both validation rules and TypeScript types.
13
+
14
+ ## Core Rules
15
+
16
+ - ALWAYS define the Zod schema first — derive the TypeScript type from it with `z.infer<>`
17
+ - ALWAYS use `zodResolver` to connect schema to react-hook-form
18
+ - ALWAYS use shadcn `<Form>`, `<FormField>`, `<FormItem>`, `<FormMessage>` for consistent UI
19
+ - NEVER use `useState` for form field values — react-hook-form handles this
20
+ - ALWAYS use `useMutation` from TanStack Query for form submission
21
+
22
+ ## Complete Form Pattern
23
+
24
+ ```tsx
25
+ // features/users/types/user.schemas.ts
26
+ import { z } from 'zod';
27
+
28
+ export const createUserSchema = z.object({
29
+ name: z.string().min(2, 'Name must be at least 2 characters'),
30
+ email: z.email('Invalid email address'),
31
+ role: z.enum(['admin', 'user'], { error: 'Role is required' }),
32
+ });
33
+
34
+ export type CreateUserInput = z.infer<typeof createUserSchema>;
35
+ ```
36
+
37
+ ```tsx
38
+ // features/users/components/create-user-form.tsx
39
+ 'use client';
40
+
41
+ import { useForm } from 'react-hook-form';
42
+ import { zodResolver } from '@hookform/resolvers/zod';
43
+ import {
44
+ Form, FormControl, FormField, FormItem, FormLabel, FormMessage
45
+ } from '@/components/ui/form';
46
+ import { Input } from '@/components/ui/input';
47
+ import { Button } from '@/components/ui/button';
48
+ import { useCreateUser } from '@/features/users/hooks/use-create-user';
49
+ import { createUserSchema, type CreateUserInput } from '@/features/users/types/user.schemas';
50
+
51
+ export function CreateUserForm({ onSuccess }: { onSuccess?: () => void }) {
52
+ const form = useForm<CreateUserInput>({
53
+ resolver: zodResolver(createUserSchema),
54
+ defaultValues: { name: '', email: '', role: 'user' },
55
+ });
56
+
57
+ const { mutate: createUser, isPending } = useCreateUser();
58
+
59
+ function onSubmit(values: CreateUserInput) {
60
+ createUser(values, {
61
+ onSuccess: () => { form.reset(); onSuccess?.(); },
62
+ onError: (error) => form.setError('root', { message: error.message }),
63
+ });
64
+ }
65
+
66
+ return (
67
+ <Form {...form}>
68
+ <form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
69
+ <FormField
70
+ control={form.control}
71
+ name="name"
72
+ render={({ field }) => (
73
+ <FormItem>
74
+ <FormLabel>Name</FormLabel>
75
+ <FormControl><Input placeholder="John Doe" {...field} /></FormControl>
76
+ <FormMessage />
77
+ </FormItem>
78
+ )}
79
+ />
80
+ <FormField
81
+ control={form.control}
82
+ name="email"
83
+ render={({ field }) => (
84
+ <FormItem>
85
+ <FormLabel>Email</FormLabel>
86
+ <FormControl><Input type="email" {...field} /></FormControl>
87
+ <FormMessage />
88
+ </FormItem>
89
+ )}
90
+ />
91
+ {form.formState.errors.root && (
92
+ <p className="text-sm text-destructive">{form.formState.errors.root.message}</p>
93
+ )}
94
+ <Button type="submit" disabled={isPending}>
95
+ {isPending ? 'Creating...' : 'Create User'}
96
+ </Button>
97
+ </form>
98
+ </Form>
99
+ );
100
+ }
101
+ ```
102
+
103
+ ## Edit Form Pattern
104
+
105
+ ```tsx
106
+ // Edit forms reuse the same schema with partial()
107
+ const form = useForm<UpdateUserInput>({
108
+ resolver: zodResolver(updateUserSchema),
109
+ defaultValues: { name: user.name, email: user.email },
110
+ });
111
+ ```
112
+
113
+ ## Schema Composition
114
+
115
+ ```ts
116
+ export const userSchema = z.object({ id: z.string(), name: z.string(), email: z.string() });
117
+ export const createUserSchema = userSchema.omit({ id: true });
118
+ export const updateUserSchema = createUserSchema.partial();
119
+ ```
120
+
121
+ ## Common Mistakes
122
+
123
+ | Wrong | Right | Why |
124
+ |-------|-------|-----|
125
+ | `useState` for each field | `useForm` | Unnecessary re-renders on every keystroke |
126
+ | Manual error display | `<FormMessage />` | Consistent UI, auto-connects to field errors |
127
+ | `fetch` in submit handler | `useMutation` | Loading state, error handling, cache invalidation |
128
+ | Type written manually | `z.infer<typeof schema>` | Single source of truth |
129
+ | `z.string().email()` | `z.email()` | Zod 4 moved format checks to top-level functions |
130
+ | `{ required_error: '...' }` | `{ error: '...' }` | Zod 4 unified error customization on one `error` param |
131
+
132
+ ---
133
+
134
+ *MORPH-SPEC by Polymorphism Tech*