@polymorphism-tech/morph-spec 4.8.7 → 4.8.9

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 (35) hide show
  1. package/README.md +2 -2
  2. package/bin/morph-spec.js +22 -1
  3. package/bin/task-manager.cjs +120 -16
  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.json +1855 -1815
  8. package/framework/hooks/claude-code/pre-compact/save-morph-context.js +141 -23
  9. package/framework/hooks/claude-code/statusline.py +0 -12
  10. package/framework/hooks/claude-code/statusline.sh +6 -2
  11. package/framework/hooks/claude-code/stop/validate-completion.js +70 -23
  12. package/framework/hooks/dev/guard-version-numbers.js +1 -1
  13. package/framework/skills/level-0-meta/morph-init/SKILL.md +44 -6
  14. package/framework/skills/level-0-meta/tool-usage-guide/SKILL.md +67 -16
  15. package/framework/skills/level-1-workflows/phase-clarify/SKILL.md +1 -1
  16. package/framework/skills/level-1-workflows/phase-codebase-analysis/SKILL.md +77 -7
  17. package/framework/skills/level-1-workflows/phase-design/SKILL.md +115 -51
  18. package/framework/skills/level-1-workflows/phase-implement/SKILL.md +139 -1
  19. package/framework/skills/level-1-workflows/phase-setup/SKILL.md +29 -6
  20. package/framework/skills/level-1-workflows/phase-tasks/SKILL.md +115 -5
  21. package/framework/skills/level-1-workflows/phase-tasks/references/tasks-example.md +173 -0
  22. package/framework/skills/level-1-workflows/phase-uiux/SKILL.md +1 -1
  23. package/framework/standards/STANDARDS.json +944 -933
  24. package/framework/standards/architecture/vertical-slice/vertical-slice.md +429 -0
  25. package/framework/templates/REGISTRY.json +1909 -1888
  26. package/framework/templates/code/dotnet/contracts/contracts-vsa.cs +282 -0
  27. package/framework/templates/docs/spec.md +33 -1
  28. package/package.json +1 -1
  29. package/src/commands/agents/dispatch-agents.js +430 -0
  30. package/src/commands/agents/index.js +2 -1
  31. package/src/commands/project/doctor.js +138 -2
  32. package/src/commands/state/state.js +20 -4
  33. package/src/commands/templates/generate-contracts.js +445 -0
  34. package/src/commands/templates/index.js +1 -0
  35. package/src/lib/validators/validation-runner.js +19 -7
@@ -0,0 +1,282 @@
1
+ // ============================================================
2
+ // CONTRACTS: {{pascalCase FEATURE_NAME}} — Vertical Slice Architecture
3
+ // Generated by MORPH Framework | Date: {{DATE}}
4
+ // Pattern: KanaiyaKatarmal/VerticalSliceArchitectureTemplate
5
+ // Ref: framework/standards/architecture/vertical-slice/vertical-slice.md
6
+ // ============================================================
7
+ //
8
+ // INSTRUÇÕES DE USO:
9
+ // 1. Copie cada seção para o arquivo correspondente no projeto
10
+ // 2. Substitua {{pascalCase FEATURE_NAME}} pelo nome da entidade (ex: Product)
11
+ // 3. Substitua {{NAMESPACE}} pelo namespace raiz do projeto (ex: MyApp)
12
+ // 4. Substitua {{ROUTE}} pela rota base (ex: /api/products)
13
+ // 5. Adicione os campos reais da entidade (marcados com TODO)
14
+ // ============================================================
15
+
16
+ // ============================================================
17
+ // ABSTRACTIONS (apenas se ainda não existir no projeto)
18
+ // Caminho: Abstractions/IHandler.cs
19
+ // ============================================================
20
+
21
+ namespace {{NAMESPACE}}.Abstractions
22
+ {
23
+ public interface IHandler<in TRequest, TResponse>
24
+ {
25
+ Task<TResponse> HandleAsync(TRequest command, CancellationToken cancellationToken);
26
+ }
27
+ }
28
+
29
+ // ============================================================
30
+ // Caminho: Abstractions/IApiEndpoint.cs
31
+ // ============================================================
32
+
33
+ namespace {{NAMESPACE}}.Abstractions
34
+ {
35
+ public interface IApiEndpoint
36
+ {
37
+ void MapEndpoint(WebApplication app);
38
+ }
39
+ }
40
+
41
+ // ============================================================
42
+ // Caminho: Abstractions/Errors/Error.cs
43
+ // ============================================================
44
+
45
+ namespace {{NAMESPACE}}.Abstractions.Errors;
46
+
47
+ public record Error(string Code, string? Description = default, ErrorType Type = ErrorType.Failure)
48
+ {
49
+ public static readonly Error None = new(string.Empty);
50
+ public static readonly Error Null = new("Error.NullValue", "The specified result value is null.");
51
+
52
+ public static implicit operator Result(Error error) => Result.Failure(error);
53
+
54
+ public static Error Failure(string code, string description) =>
55
+ new(code, description, ErrorType.Failure);
56
+ public static Error Unexpected(string code, string description) =>
57
+ new(code, description, ErrorType.Unexpected);
58
+ public static Error Validation(string code, string description) =>
59
+ new(code, description, ErrorType.Validation);
60
+ public static Error Conflict(string code, string description) =>
61
+ new(code, description, ErrorType.Conflict);
62
+ public static Error NotFound(string code, string description) =>
63
+ new(code, description, ErrorType.NotFound);
64
+ public static Error Unauthorized(string code, string description) =>
65
+ new(code, description, ErrorType.Unauthorized);
66
+ public static Error Forbidden(string code, string description) =>
67
+ new(code, description, ErrorType.Forbidden);
68
+ }
69
+
70
+ public enum ErrorType
71
+ {
72
+ Failure, Unexpected, Validation, Conflict, NotFound, Unauthorized, Forbidden, Custom
73
+ }
74
+
75
+ // ============================================================
76
+ // Caminho: Abstractions/Errors/ValidationError.cs
77
+ // ============================================================
78
+
79
+ namespace {{NAMESPACE}}.Abstractions.Errors;
80
+
81
+ public sealed record ValidationError : Error
82
+ {
83
+ public ValidationError(Error[] errors)
84
+ : base("Validation.General", "One or more validation errors occurred", ErrorType.Validation)
85
+ {
86
+ Errors = errors;
87
+ }
88
+ public Error[] Errors { get; }
89
+ public static ValidationError FromResults(IEnumerable<Result> results) =>
90
+ new(results.Where(r => r.IsFailure).Select(r => r.Error).ToArray());
91
+ }
92
+
93
+ // ============================================================
94
+ // Caminho: Abstractions/Result.cs
95
+ // ============================================================
96
+
97
+ using {{NAMESPACE}}.Abstractions.Errors;
98
+ namespace {{NAMESPACE}}.Abstractions;
99
+
100
+ public class Result
101
+ {
102
+ protected internal Result(bool isSuccess, Error error)
103
+ {
104
+ if (isSuccess && error != Error.None || !isSuccess && error == Error.None)
105
+ throw new ArgumentException("Invalid error", nameof(error));
106
+ IsSuccess = isSuccess;
107
+ Error = error;
108
+ }
109
+ public bool IsSuccess { get; }
110
+ public bool IsFailure => !IsSuccess;
111
+ public Error Error { get; }
112
+
113
+ public static Result Success() => new(true, Error.None);
114
+ public static Result<TValue> Success<TValue>(TValue value) => new(value, true, Error.None);
115
+ public static Result Failure(Error error) => new(false, error);
116
+ public static Result<TValue> Failure<TValue>(Error error) => new(default, false, error);
117
+ public static Result<TValue> Create<TValue>(TValue? value) =>
118
+ value is not null ? Success(value) : Failure<TValue>(Error.Null);
119
+ }
120
+
121
+ public class Result<TValue> : Result
122
+ {
123
+ private readonly TValue? _value;
124
+ protected internal Result(TValue? value, bool isSuccess, Error error) : base(isSuccess, error)
125
+ => _value = value;
126
+ public TValue Value => IsSuccess
127
+ ? _value!
128
+ : throw new InvalidOperationException("The value of a failure result can not be accessed.");
129
+ public static implicit operator Result<TValue>(TValue? value) => Create(value);
130
+ public static implicit operator Result<TValue>(Error error) => Failure<TValue>(error);
131
+ }
132
+
133
+ // ============================================================
134
+ // ENTITY
135
+ // Caminho: Entities/{{pascalCase FEATURE_NAME}}.cs
136
+ // ============================================================
137
+
138
+ namespace {{NAMESPACE}}.Entities;
139
+
140
+ public sealed class {{pascalCase FEATURE_NAME}}
141
+ {
142
+ public Guid Id { get; set; }
143
+
144
+ // TODO: adicionar campos da entidade com tipos C# corretos
145
+ // Exemplo:
146
+ // public required string Name { get; set; }
147
+ // public decimal Price { get; set; }
148
+ // public int Quantity { get; set; }
149
+ // public DateTime CreatedAt { get; set; }
150
+ }
151
+
152
+ // ============================================================
153
+ // FEATURE ERRORS (compartilhado por todos os slices da feature)
154
+ // Caminho: Features/{{pascalCase FEATURE_NAME}}Feature/{{pascalCase FEATURE_NAME}}Errors.cs
155
+ // ============================================================
156
+
157
+ using {{NAMESPACE}}.Abstractions.Errors;
158
+ namespace {{NAMESPACE}}.Features.{{pascalCase FEATURE_NAME}}Feature;
159
+
160
+ public static class {{pascalCase FEATURE_NAME}}Errors
161
+ {
162
+ public static Error NotFound(Guid id) =>
163
+ Error.NotFound("{{pascalCase FEATURE_NAME}}s.NotFound",
164
+ $"The {{pascalCase FEATURE_NAME}} with Id '{id}' was not found");
165
+
166
+ // TODO: adicionar outros tipos de erro específicos da feature
167
+ // public static Error AlreadyExists(string name) =>
168
+ // Error.Conflict("{{pascalCase FEATURE_NAME}}s.AlreadyExists",
169
+ // $"A {{pascalCase FEATURE_NAME}} with name '{name}' already exists");
170
+ }
171
+
172
+ // ============================================================
173
+ // SLICE: Create{{pascalCase FEATURE_NAME}}
174
+ // Caminho: Features/{{pascalCase FEATURE_NAME}}Feature/Create{{pascalCase FEATURE_NAME}}/
175
+ // ============================================================
176
+
177
+ // --- Create{{pascalCase FEATURE_NAME}}Handler.cs ---
178
+ namespace {{NAMESPACE}}.Features.{{pascalCase FEATURE_NAME}}Feature.Create{{pascalCase FEATURE_NAME}};
179
+
180
+ using {{NAMESPACE}}.Abstractions;
181
+ using {{NAMESPACE}}.Entities;
182
+ using {{NAMESPACE}}.Repository;
183
+
184
+ // TODO: adicionar todos os campos do request (campos obrigatórios para criação)
185
+ public sealed record Create{{pascalCase FEATURE_NAME}}Request(/* string Name, decimal Price, ... */);
186
+
187
+ // TODO: adicionar todos os campos do response (campos retornados após criação)
188
+ public sealed record Create{{pascalCase FEATURE_NAME}}Response(Guid Id /* , string Name, ... */);
189
+
190
+ public sealed class Create{{pascalCase FEATURE_NAME}}Handler(
191
+ IRepository<{{pascalCase FEATURE_NAME}}> _repo,
192
+ IUnitOfWork _unitOfWork) : IHandler<Create{{pascalCase FEATURE_NAME}}Request, Result<Create{{pascalCase FEATURE_NAME}}Response>>
193
+ {
194
+ public async Task<Result<Create{{pascalCase FEATURE_NAME}}Response>> HandleAsync(
195
+ Create{{pascalCase FEATURE_NAME}}Request command, CancellationToken cancellationToken)
196
+ {
197
+ var entity = new {{pascalCase FEATURE_NAME}}
198
+ {
199
+ Id = Guid.CreateVersion7(),
200
+ // TODO: mapear campos do command para a entidade
201
+ // Name = command.Name,
202
+ // Price = command.Price,
203
+ };
204
+
205
+ await _repo.AddAsync(entity, cancellationToken);
206
+ await _unitOfWork.CommitAsync(cancellationToken);
207
+
208
+ return Result.Success(new Create{{pascalCase FEATURE_NAME}}Response(entity.Id /* , entity.Name, ... */));
209
+ }
210
+ }
211
+
212
+ // --- Create{{pascalCase FEATURE_NAME}}Validator.cs ---
213
+ namespace {{NAMESPACE}}.Features.{{pascalCase FEATURE_NAME}}Feature.Create{{pascalCase FEATURE_NAME}};
214
+
215
+ using FluentValidation;
216
+
217
+ public class Create{{pascalCase FEATURE_NAME}}Validator : AbstractValidator<Create{{pascalCase FEATURE_NAME}}Request>
218
+ {
219
+ public Create{{pascalCase FEATURE_NAME}}Validator()
220
+ {
221
+ // TODO: adicionar regras de validação para cada campo
222
+ // RuleFor(c => c.Name)
223
+ // .NotEmpty().WithMessage("Name is required")
224
+ // .MaximumLength(200).WithMessage("Name must not exceed 200 characters");
225
+ // RuleFor(c => c.Price)
226
+ // .GreaterThan(0).WithMessage("Price must be greater than 0");
227
+ }
228
+ }
229
+
230
+ // --- Create{{pascalCase FEATURE_NAME}}Endpoint.cs ---
231
+ namespace {{NAMESPACE}}.Features.{{pascalCase FEATURE_NAME}}Feature.Create{{pascalCase FEATURE_NAME}};
232
+
233
+ using {{NAMESPACE}}.Abstractions;
234
+ using {{NAMESPACE}}.Extensions;
235
+
236
+ internal sealed class Create{{pascalCase FEATURE_NAME}}Endpoint : IApiEndpoint
237
+ {
238
+ public void MapEndpoint(WebApplication app)
239
+ {
240
+ app.MapPost("{{ROUTE}}", async (
241
+ IHandler<Create{{pascalCase FEATURE_NAME}}Request, Result<Create{{pascalCase FEATURE_NAME}}Response>> handler,
242
+ Create{{pascalCase FEATURE_NAME}}Request command,
243
+ CancellationToken cancellationToken) =>
244
+ {
245
+ var result = await handler.HandleAsync(command, cancellationToken);
246
+ return result.Match(
247
+ onSuccess: () => Results.Ok(result.Value),
248
+ onFailure: error => Results.BadRequest(error));
249
+ })
250
+ // TODO: substituir "{{pascalCase FEATURE_NAME}}s" pelo tag correto em ApiTags
251
+ .WithTags("{{pascalCase FEATURE_NAME}}s")
252
+ .Produces<Create{{pascalCase FEATURE_NAME}}Response>(StatusCodes.Status200OK)
253
+ .Produces(StatusCodes.Status400BadRequest);
254
+ }
255
+ }
256
+
257
+ // ============================================================
258
+ // TODO: adicionar slices restantes (copiar padrão do Create acima)
259
+ // ============================================================
260
+ // GetAll{{pascalCase FEATURE_NAME}}s — sem validator (sem parâmetros)
261
+ // Request: sealed record GetAll{{pascalCase FEATURE_NAME}}sRequest;
262
+ // Response: sealed record GetAll{{pascalCase FEATURE_NAME}}sResponse(IEnumerable<{{pascalCase FEATURE_NAME}}Dto> Items);
263
+ // DTO: sealed record {{pascalCase FEATURE_NAME}}Dto(Guid Id, /* campos */);
264
+ // Endpoint: app.MapGet("{{ROUTE}}", ...)
265
+ //
266
+ // Get{{pascalCase FEATURE_NAME}}ById — com validator (Id obrigatório)
267
+ // Request: sealed record Get{{pascalCase FEATURE_NAME}}ByIdRequest(Guid Id);
268
+ // Response: sealed record Get{{pascalCase FEATURE_NAME}}ByIdResponse(Guid Id, /* campos */);
269
+ // Endpoint: app.MapGet("{{ROUTE}}/{id:guid}", ...)
270
+ // OnFailure: Results.NotFound(error)
271
+ //
272
+ // Update{{pascalCase FEATURE_NAME}} — com validator
273
+ // Request: sealed record Update{{pascalCase FEATURE_NAME}}Request(Guid Id, /* campos nullable */);
274
+ // Response: sealed record Update{{pascalCase FEATURE_NAME}}Response(Guid Id, /* campos */);
275
+ // Endpoint: app.MapPut("{{ROUTE}}/{id:guid}", ...)
276
+ // Checar NotFound antes de atualizar
277
+ //
278
+ // Delete{{pascalCase FEATURE_NAME}} — com validator
279
+ // Request: sealed record Delete{{pascalCase FEATURE_NAME}}Request(Guid Id);
280
+ // Response: sealed record Delete{{pascalCase FEATURE_NAME}}Response(Guid Id);
281
+ // Endpoint: app.MapDelete("{{ROUTE}}/{id:guid}", ...)
282
+ // Checar NotFound antes de deletar
@@ -99,9 +99,41 @@ public interface I{{pascalCase FEATURE_NAME}}Service
99
99
 
100
100
  ---
101
101
 
102
+ ## Architecture Style: Vertical Slice
103
+
104
+ > Preencher SOMENTE se `config.architecture.style === "vertical-slice"`. Omitir em projetos DDD.
105
+
106
+ **Architecture Style:** Vertical Slice Architecture (VSA)
107
+
108
+ **Entity Fields:**
109
+ | Field | Type | Constraints |
110
+ |-------|------|-------------|
111
+ | Id | Guid | PK, `Guid.CreateVersion7()` |
112
+ | {Field} | {C# Type} | {Required / Optional / Unique} |
113
+ | CreatedAt | DateTimeOffset | Auto |
114
+
115
+ **Operations:**
116
+ | Slice | HTTP | Route | Has Validator |
117
+ |-------|------|-------|---------------|
118
+ | Create{Entity} | POST | {ROUTE} | Yes |
119
+ | GetAll{Entity}s | GET | {ROUTE} | No |
120
+ | Get{Entity}ById | GET | {ROUTE}/{id} | Yes |
121
+ | Update{Entity} | PUT | {ROUTE}/{id} | Yes |
122
+ | Delete{Entity} | DELETE | {ROUTE}/{id} | Yes |
123
+
124
+ **Error Types ({Entity}Errors):**
125
+ - `{Entity}Errors.{ErrorName}()` — {description}
126
+
127
+ **Validation Rules:**
128
+ | Field | Rules |
129
+ |-------|-------|
130
+ | {Field} | NotEmpty(), MaxLength({N}), {etc.} |
131
+
132
+ ---
133
+
102
134
  ## Aggregate Blueprint (Nível 2+ apenas)
103
135
 
104
- > Omitir esta seção se Nível 1 (CRUD).
136
+ > Omitir esta seção se Nível 1 (CRUD) ou se Architecture Style = Vertical Slice.
105
137
 
106
138
  ### Aggregate Root: {EntityName}
107
139
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polymorphism-tech/morph-spec",
3
- "version": "4.8.7",
3
+ "version": "4.8.9",
4
4
  "description": "MORPH-SPEC: AI-First development framework with validation pipeline and multi-stack support",
5
5
  "keywords": [
6
6
  "claude-code",