@semacode/cli 4.2.5 → 4.2.7
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.
- package/dist/agentBootstrap.js +5 -4
- package/dist/agentContextPack.js +9 -9
- package/dist/agentEntryPoints.js +37 -12
- package/dist/agentFlowHelp.d.ts +4 -0
- package/dist/agentFlowHelp.js +38 -0
- package/dist/bin.js +6 -2
- package/dist/changeCommands.d.ts +1 -0
- package/dist/changeCommands.js +79 -0
- package/dist/changeScope.d.ts +18 -0
- package/dist/changeScope.js +89 -0
- package/dist/cliArgs.js +1 -0
- package/dist/cliGrammar.js +5 -5
- package/dist/cliHelpTexto.js +5 -5
- package/dist/comandoSessao.js +27 -0
- package/dist/contexto.js +2 -2
- package/dist/discovery/catalog.js +1 -1
- package/dist/docs.part02.js +2 -2
- package/dist/drift.part01.d.ts +5 -1
- package/dist/drift.part06.js +4 -0
- package/dist/drift.part11.js +18 -0
- package/dist/drift.part13.js +1 -1
- package/dist/driftPack.d.ts +4 -0
- package/dist/driftPack.js +8 -2
- package/dist/iaPrompts.d.ts +3 -3
- package/dist/iaPrompts.js +10 -9
- package/dist/index.part01.js +0 -3
- package/dist/index.part03.js +2 -20
- package/dist/index.part04.js +4 -73
- package/dist/index.part06.js +3 -55
- package/dist/javascriptBindings.d.ts +2 -0
- package/dist/javascriptBindings.js +75 -0
- package/dist/saidaCli.js +4 -1
- package/docs/ai-integration.md +9 -5
- package/docs/ai-workflow.md +4 -4
- package/docs/cli.md +1 -1
- package/docs/commands.md +3 -3
- package/docs/documentation.md +19 -4
- package/docs/syntax.md +21 -0
- package/node_modules/@sema/gerador-cpp/dist/index.js +177 -177
- package/node_modules/@sema/gerador-css/dist/index.part01.js +24 -24
- package/node_modules/@sema/gerador-dart/dist/index.js +1 -1
- package/node_modules/@sema/gerador-dotnet/dist/index.js +170 -170
- package/node_modules/@sema/gerador-html/dist/index.js +100 -100
- package/node_modules/@sema/gerador-javascript/dist/index.js +93 -93
- package/node_modules/@sema/gerador-lua/dist/index.js +85 -85
- package/node_modules/@sema/gerador-php/dist/index.js +114 -114
- package/node_modules/@sema/gerador-python/dist/index.part02.js +97 -97
- package/node_modules/@sema/gerador-typescript/dist/index.part02.js +145 -145
- package/node_modules/@sema/nucleo/dist/index.d.ts +3 -0
- package/node_modules/@sema/nucleo/dist/index.js +4 -1
- package/node_modules/@sema/nucleo/dist/lexer/lexer.js +13 -0
- package/node_modules/@sema/nucleo/dist/parser/parser.declaracoes.js +14 -5
- package/node_modules/@sema/nucleo/dist/parser/parser.modulo.js +7 -5
- package/node_modules/@sema/nucleo/dist/parser/parser.part02.d.ts +3 -1
- package/node_modules/@sema/nucleo/dist/parser/parser.part02.js +60 -18
- package/node_modules/@sema/nucleo/dist/parser/parser.part03.js +2 -2
- package/node_modules/@sema/nucleo/dist/semantico/analisador.part01.js +11 -2
- package/package.json +1 -1
- package/skills/sema/SKILL.md +15 -0
|
@@ -269,7 +269,7 @@ function gerarCabecalhoCSharp(modulo, descricao) {
|
|
|
269
269
|
`// Módulo de origem: ${modulo.nome}`,
|
|
270
270
|
"// Contrato: consulte o arquivo .sema aplicável antes de editar este artefato.",
|
|
271
271
|
"// Rastreabilidade: outros contratos .sema podem governar este mesmo arquivo via vinculos.",
|
|
272
|
-
"// Para IA
|
|
272
|
+
"// Para qualquer IA: chame Sema, rode docs-impacto e drift antes de alterar código.",
|
|
273
273
|
`// Descrição: ${descricao}`,
|
|
274
274
|
"",
|
|
275
275
|
].join("\n");
|
|
@@ -509,54 +509,54 @@ function gerarTask(task, contexto) {
|
|
|
509
509
|
const erros = Object.entries(task.errors)
|
|
510
510
|
.map(([codigo, mensagem]) => ` [${literalString(codigo)}] = ${literalString(mensagem)},`)
|
|
511
511
|
.join("\n");
|
|
512
|
-
return `// SEMA-TASK: ${escaparComentario(task.nome)}
|
|
513
|
-
public sealed record class ${nomeEntrada}
|
|
514
|
-
{
|
|
515
|
-
${gerarPropriedades(task.input, contexto)}
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
public sealed record class ${nomeSaida}
|
|
519
|
-
{
|
|
520
|
-
${gerarPropriedades(task.output, contexto)}
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
public static class ${nome}Contract
|
|
524
|
-
{
|
|
525
|
-
public static IReadOnlyList<string> Rules { get; } = ${regras};
|
|
526
|
-
public static IReadOnlyList<string> Guarantees { get; } = ${garantias};
|
|
527
|
-
public static IReadOnlyList<string> Effects { get; } = ${efeitos};
|
|
528
|
-
public static IReadOnlyDictionary<string, string> Errors { get; } = new Dictionary<string, string>
|
|
529
|
-
{
|
|
530
|
-
${erros}
|
|
531
|
-
};
|
|
532
|
-
|
|
533
|
-
public static void Validate(${nomeEntrada} input)
|
|
534
|
-
{
|
|
535
|
-
ArgumentNullException.ThrowIfNull(input);
|
|
536
|
-
${gerarValidacoes(task, contexto)}
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
public static ${nomeSaida} Execute(${nomeEntrada} input, string? expectedErrorCode = null)
|
|
540
|
-
{
|
|
541
|
-
Validate(input);
|
|
542
|
-
if (!string.IsNullOrWhiteSpace(expectedErrorCode))
|
|
543
|
-
{
|
|
544
|
-
var message = Errors.TryGetValue(expectedErrorCode, out var declaredMessage)
|
|
545
|
-
? declaredMessage
|
|
546
|
-
: "Erro esperado pelo caso Sema.";
|
|
547
|
-
throw new SemaContractException(expectedErrorCode, message);
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
var output = ${gerarInicializadorSaida(task, contexto)};
|
|
551
|
-
VerifyGuarantees(output);
|
|
552
|
-
return output;
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
public static void VerifyGuarantees(${nomeSaida} output)
|
|
556
|
-
{
|
|
557
|
-
ArgumentNullException.ThrowIfNull(output);
|
|
558
|
-
${gerarVerificacaoGarantias(task, contexto)}
|
|
559
|
-
}
|
|
512
|
+
return `// SEMA-TASK: ${escaparComentario(task.nome)}
|
|
513
|
+
public sealed record class ${nomeEntrada}
|
|
514
|
+
{
|
|
515
|
+
${gerarPropriedades(task.input, contexto)}
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
public sealed record class ${nomeSaida}
|
|
519
|
+
{
|
|
520
|
+
${gerarPropriedades(task.output, contexto)}
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
public static class ${nome}Contract
|
|
524
|
+
{
|
|
525
|
+
public static IReadOnlyList<string> Rules { get; } = ${regras};
|
|
526
|
+
public static IReadOnlyList<string> Guarantees { get; } = ${garantias};
|
|
527
|
+
public static IReadOnlyList<string> Effects { get; } = ${efeitos};
|
|
528
|
+
public static IReadOnlyDictionary<string, string> Errors { get; } = new Dictionary<string, string>
|
|
529
|
+
{
|
|
530
|
+
${erros}
|
|
531
|
+
};
|
|
532
|
+
|
|
533
|
+
public static void Validate(${nomeEntrada} input)
|
|
534
|
+
{
|
|
535
|
+
ArgumentNullException.ThrowIfNull(input);
|
|
536
|
+
${gerarValidacoes(task, contexto)}
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
public static ${nomeSaida} Execute(${nomeEntrada} input, string? expectedErrorCode = null)
|
|
540
|
+
{
|
|
541
|
+
Validate(input);
|
|
542
|
+
if (!string.IsNullOrWhiteSpace(expectedErrorCode))
|
|
543
|
+
{
|
|
544
|
+
var message = Errors.TryGetValue(expectedErrorCode, out var declaredMessage)
|
|
545
|
+
? declaredMessage
|
|
546
|
+
: "Erro esperado pelo caso Sema.";
|
|
547
|
+
throw new SemaContractException(expectedErrorCode, message);
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
var output = ${gerarInicializadorSaida(task, contexto)};
|
|
551
|
+
VerifyGuarantees(output);
|
|
552
|
+
return output;
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
public static void VerifyGuarantees(${nomeSaida} output)
|
|
556
|
+
{
|
|
557
|
+
ArgumentNullException.ThrowIfNull(output);
|
|
558
|
+
${gerarVerificacaoGarantias(task, contexto)}
|
|
559
|
+
}
|
|
560
560
|
}`;
|
|
561
561
|
}
|
|
562
562
|
function removerAspas(valor) {
|
|
@@ -636,27 +636,27 @@ function gerarMetodoTeste(task, caso, indice, contexto) {
|
|
|
636
636
|
.join(", ");
|
|
637
637
|
const assercoesEsperadas = gerarAssercoesEsperadas(task, caso, contexto);
|
|
638
638
|
const corpo = erro
|
|
639
|
-
? ` try
|
|
640
|
-
{
|
|
641
|
-
${nomeTask}.Execute(input, ${literalString(erro)});
|
|
642
|
-
throw new InvalidOperationException(${literalString(`O caso ${caso.nome} deveria falhar.`)});
|
|
643
|
-
}
|
|
644
|
-
catch (SemaContractException exception) when (exception.Code == ${literalString(erro)})
|
|
645
|
-
{
|
|
646
|
-
// Erro declarado e observado conforme o contrato.
|
|
639
|
+
? ` try
|
|
640
|
+
{
|
|
641
|
+
${nomeTask}.Execute(input, ${literalString(erro)});
|
|
642
|
+
throw new InvalidOperationException(${literalString(`O caso ${caso.nome} deveria falhar.`)});
|
|
643
|
+
}
|
|
644
|
+
catch (SemaContractException exception) when (exception.Code == ${literalString(erro)})
|
|
645
|
+
{
|
|
646
|
+
// Erro declarado e observado conforme o contrato.
|
|
647
647
|
}`
|
|
648
|
-
: ` var output = ${nomeTask}.Execute(input);
|
|
649
|
-
SemaAssert.NotNull(output, ${literalString(`O caso ${caso.nome} não retornou saída.`)});
|
|
650
|
-
${nomeTask}.VerifyGuarantees(output);
|
|
648
|
+
: ` var output = ${nomeTask}.Execute(input);
|
|
649
|
+
SemaAssert.NotNull(output, ${literalString(`O caso ${caso.nome} não retornou saída.`)});
|
|
650
|
+
${nomeTask}.VerifyGuarantees(output);
|
|
651
651
|
${assercoesEsperadas || " // O caso não declarou campos de saída verificáveis."}`;
|
|
652
652
|
return {
|
|
653
653
|
nome,
|
|
654
|
-
codigo: ` // SEMA-TEST: ${escaparComentario(task.nome)} :: ${escaparComentario(caso.nome)}
|
|
655
|
-
private static void ${nome}()
|
|
656
|
-
{
|
|
657
|
-
// SEMA-EXPECT: ${escaparComentario(detalhesEsperados || "sucesso")}
|
|
658
|
-
var input = ${entrada};
|
|
659
|
-
${corpo}
|
|
654
|
+
codigo: ` // SEMA-TEST: ${escaparComentario(task.nome)} :: ${escaparComentario(caso.nome)}
|
|
655
|
+
private static void ${nome}()
|
|
656
|
+
{
|
|
657
|
+
// SEMA-EXPECT: ${escaparComentario(detalhesEsperados || "sucesso")}
|
|
658
|
+
var input = ${entrada};
|
|
659
|
+
${corpo}
|
|
660
660
|
}`,
|
|
661
661
|
};
|
|
662
662
|
}
|
|
@@ -671,30 +671,30 @@ function gerarCodigoFonte(modulo, contexto) {
|
|
|
671
671
|
const flows = modulo.flows.map((item) => `// SEMA-FLOW: ${escaparComentario(item.nome)} tasks=${escaparComentario(item.tasksReferenciadas.join(", ") || "nenhuma")}`).join("\n");
|
|
672
672
|
const routes = modulo.routes.map((item) => `// SEMA-ROUTE: ${escaparComentario(item.nome)} metodo=${escaparComentario(item.metodo ?? "nao_definido")} caminho=${escaparComentario(item.caminho ?? "nao_definido")} task=${escaparComentario(item.task ?? "nao_definida")}`).join("\n");
|
|
673
673
|
const states = modulo.states.map((item) => `// SEMA-STATE: ${escaparComentario(item.nome ?? "anonimo")} campos=${item.campos.length} invariantes=${item.invariantes.length} transicoes=${item.transicoes.length}`).join("\n");
|
|
674
|
-
return `${gerarCabecalhoCSharp(modulo, "código C# gerado a partir do IR Sema, incluindo modelos, regras, garantias e metadados operacionais.")}using System;
|
|
675
|
-
using System.Collections.Generic;
|
|
676
|
-
using System.Globalization;
|
|
677
|
-
using System.Linq;
|
|
678
|
-
|
|
679
|
-
namespace ${namespace};
|
|
680
|
-
|
|
681
|
-
public class SemaContractException : Exception
|
|
682
|
-
{
|
|
683
|
-
public SemaContractException(string code, string message) : base(message) => Code = code;
|
|
684
|
-
public string Code { get; }
|
|
685
|
-
}
|
|
686
|
-
|
|
687
|
-
public sealed class SemaValidationException : SemaContractException
|
|
688
|
-
{
|
|
689
|
-
public SemaValidationException(string rule) : base("regra_invalida", $"Regra Sema violada: {rule}") { }
|
|
690
|
-
}
|
|
691
|
-
|
|
692
|
-
public sealed class SemaGuaranteeException : SemaContractException
|
|
693
|
-
{
|
|
694
|
-
public SemaGuaranteeException(string guarantee) : base("garantia_violada", $"Garantia Sema violada: {guarantee}") { }
|
|
695
|
-
}
|
|
696
|
-
|
|
697
|
-
${interops ? `${interops}\n\n` : ""}${externos ? `${externos}\n\n` : ""}${enums ? `${enums}\n\n` : ""}${tipos ? `${tipos}\n\n` : ""}${entidades ? `${entidades}\n\n` : ""}${tasks}${states ? `\n\n${states}` : ""}${flows ? `\n${flows}` : ""}${routes ? `\n${routes}` : ""}
|
|
674
|
+
return `${gerarCabecalhoCSharp(modulo, "código C# gerado a partir do IR Sema, incluindo modelos, regras, garantias e metadados operacionais.")}using System;
|
|
675
|
+
using System.Collections.Generic;
|
|
676
|
+
using System.Globalization;
|
|
677
|
+
using System.Linq;
|
|
678
|
+
|
|
679
|
+
namespace ${namespace};
|
|
680
|
+
|
|
681
|
+
public class SemaContractException : Exception
|
|
682
|
+
{
|
|
683
|
+
public SemaContractException(string code, string message) : base(message) => Code = code;
|
|
684
|
+
public string Code { get; }
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
public sealed class SemaValidationException : SemaContractException
|
|
688
|
+
{
|
|
689
|
+
public SemaValidationException(string rule) : base("regra_invalida", $"Regra Sema violada: {rule}") { }
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
public sealed class SemaGuaranteeException : SemaContractException
|
|
693
|
+
{
|
|
694
|
+
public SemaGuaranteeException(string guarantee) : base("garantia_violada", $"Garantia Sema violada: {guarantee}") { }
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
${interops ? `${interops}\n\n` : ""}${externos ? `${externos}\n\n` : ""}${enums ? `${enums}\n\n` : ""}${tipos ? `${tipos}\n\n` : ""}${entidades ? `${entidades}\n\n` : ""}${tasks}${states ? `\n\n${states}` : ""}${flows ? `\n${flows}` : ""}${routes ? `\n${routes}` : ""}
|
|
698
698
|
`;
|
|
699
699
|
}
|
|
700
700
|
function gerarCodigoTestes(modulo, contexto) {
|
|
@@ -703,96 +703,96 @@ function gerarCodigoTestes(modulo, contexto) {
|
|
|
703
703
|
if (metodos.length === 0) {
|
|
704
704
|
metodos.push({
|
|
705
705
|
nome: "TestEstruturaGerada",
|
|
706
|
-
codigo: ` // SEMA-TEST: estrutura gerada :: módulo sem casos declarados
|
|
707
|
-
private static void TestEstruturaGerada()
|
|
708
|
-
{
|
|
709
|
-
SemaAssert.True(true, "A estrutura .NET gerada deve ser executavel.");
|
|
706
|
+
codigo: ` // SEMA-TEST: estrutura gerada :: módulo sem casos declarados
|
|
707
|
+
private static void TestEstruturaGerada()
|
|
708
|
+
{
|
|
709
|
+
SemaAssert.True(true, "A estrutura .NET gerada deve ser executavel.");
|
|
710
710
|
}`,
|
|
711
711
|
});
|
|
712
712
|
}
|
|
713
713
|
const registros = metodos.map((metodo) => ` (${literalString(metodo.nome)}, ${metodo.nome}),`).join("\n");
|
|
714
|
-
return `${gerarCabecalhoCSharp(modulo, "runner de testes .NET gerado sem framework ou pacote NuGet externo.")}using System;
|
|
715
|
-
using System.Collections.Generic;
|
|
716
|
-
using System.Globalization;
|
|
717
|
-
using ${namespace};
|
|
718
|
-
|
|
719
|
-
internal static class SemaAssert
|
|
720
|
-
{
|
|
721
|
-
public static void True(bool condition, string message)
|
|
722
|
-
{
|
|
723
|
-
if (!condition) throw new InvalidOperationException(message);
|
|
724
|
-
}
|
|
725
|
-
|
|
726
|
-
public static void NotNull(object? value, string message) => True(value is not null, message);
|
|
727
|
-
|
|
728
|
-
public static void Equal<T>(T expected, T actual, string message)
|
|
729
|
-
{
|
|
730
|
-
if (!EqualityComparer<T>.Default.Equals(expected, actual))
|
|
731
|
-
{
|
|
732
|
-
throw new InvalidOperationException($"{message} Esperado={expected}; Atual={actual}.");
|
|
733
|
-
}
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
|
|
737
|
-
internal static class Program
|
|
738
|
-
{
|
|
739
|
-
private static int Main()
|
|
740
|
-
{
|
|
741
|
-
var tests = new (string Name, Action Run)[]
|
|
742
|
-
{
|
|
743
|
-
${registros}
|
|
744
|
-
};
|
|
745
|
-
|
|
746
|
-
foreach (var test in tests)
|
|
747
|
-
{
|
|
748
|
-
Console.WriteLine($"test {test.Name}");
|
|
749
|
-
test.Run();
|
|
750
|
-
}
|
|
751
|
-
|
|
752
|
-
Console.WriteLine($"ok {tests.Length} testes");
|
|
753
|
-
return 0;
|
|
754
|
-
}
|
|
755
|
-
|
|
756
|
-
${metodos.map((metodo) => metodo.codigo).join("\n\n")}
|
|
757
|
-
}
|
|
714
|
+
return `${gerarCabecalhoCSharp(modulo, "runner de testes .NET gerado sem framework ou pacote NuGet externo.")}using System;
|
|
715
|
+
using System.Collections.Generic;
|
|
716
|
+
using System.Globalization;
|
|
717
|
+
using ${namespace};
|
|
718
|
+
|
|
719
|
+
internal static class SemaAssert
|
|
720
|
+
{
|
|
721
|
+
public static void True(bool condition, string message)
|
|
722
|
+
{
|
|
723
|
+
if (!condition) throw new InvalidOperationException(message);
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
public static void NotNull(object? value, string message) => True(value is not null, message);
|
|
727
|
+
|
|
728
|
+
public static void Equal<T>(T expected, T actual, string message)
|
|
729
|
+
{
|
|
730
|
+
if (!EqualityComparer<T>.Default.Equals(expected, actual))
|
|
731
|
+
{
|
|
732
|
+
throw new InvalidOperationException($"{message} Esperado={expected}; Atual={actual}.");
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
internal static class Program
|
|
738
|
+
{
|
|
739
|
+
private static int Main()
|
|
740
|
+
{
|
|
741
|
+
var tests = new (string Name, Action Run)[]
|
|
742
|
+
{
|
|
743
|
+
${registros}
|
|
744
|
+
};
|
|
745
|
+
|
|
746
|
+
foreach (var test in tests)
|
|
747
|
+
{
|
|
748
|
+
Console.WriteLine($"test {test.Name}");
|
|
749
|
+
test.Run();
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
Console.WriteLine($"ok {tests.Length} testes");
|
|
753
|
+
return 0;
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
${metodos.map((metodo) => metodo.codigo).join("\n\n")}
|
|
757
|
+
}
|
|
758
758
|
`;
|
|
759
759
|
}
|
|
760
760
|
function gerarProjetoFonte(modulo, base, assemblyName) {
|
|
761
|
-
return `${gerarCabecalhoProjeto(modulo, "biblioteca .NET gerada sem dependências NuGet externas.")}
|
|
762
|
-
<Project Sdk="Microsoft.NET.Sdk">
|
|
763
|
-
<PropertyGroup>
|
|
764
|
-
<TargetFramework>net8.0</TargetFramework>
|
|
765
|
-
<ImplicitUsings>enable</ImplicitUsings>
|
|
766
|
-
<Nullable>enable</Nullable>
|
|
767
|
-
<LangVersion>latest</LangVersion>
|
|
768
|
-
<AssemblyName>${assemblyName}</AssemblyName>
|
|
769
|
-
<RootNamespace>${assemblyName}</RootNamespace>
|
|
770
|
-
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
|
|
771
|
-
</PropertyGroup>
|
|
772
|
-
<ItemGroup>
|
|
773
|
-
<Compile Include="${base}.cs" />
|
|
774
|
-
</ItemGroup>
|
|
775
|
-
</Project>
|
|
761
|
+
return `${gerarCabecalhoProjeto(modulo, "biblioteca .NET gerada sem dependências NuGet externas.")}
|
|
762
|
+
<Project Sdk="Microsoft.NET.Sdk">
|
|
763
|
+
<PropertyGroup>
|
|
764
|
+
<TargetFramework>net8.0</TargetFramework>
|
|
765
|
+
<ImplicitUsings>enable</ImplicitUsings>
|
|
766
|
+
<Nullable>enable</Nullable>
|
|
767
|
+
<LangVersion>latest</LangVersion>
|
|
768
|
+
<AssemblyName>${assemblyName}</AssemblyName>
|
|
769
|
+
<RootNamespace>${assemblyName}</RootNamespace>
|
|
770
|
+
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
|
|
771
|
+
</PropertyGroup>
|
|
772
|
+
<ItemGroup>
|
|
773
|
+
<Compile Include="${base}.cs" />
|
|
774
|
+
</ItemGroup>
|
|
775
|
+
</Project>
|
|
776
776
|
`;
|
|
777
777
|
}
|
|
778
778
|
function gerarProjetoTestes(modulo, base, assemblyName) {
|
|
779
|
-
return `${gerarCabecalhoProjeto(modulo, "executavel de testes .NET autocontido, sem xUnit, MSTest, NUnit ou outro pacote NuGet.")}
|
|
780
|
-
<Project Sdk="Microsoft.NET.Sdk">
|
|
781
|
-
<PropertyGroup>
|
|
782
|
-
<OutputType>Exe</OutputType>
|
|
783
|
-
<TargetFramework>net8.0</TargetFramework>
|
|
784
|
-
<ImplicitUsings>enable</ImplicitUsings>
|
|
785
|
-
<Nullable>enable</Nullable>
|
|
786
|
-
<LangVersion>latest</LangVersion>
|
|
787
|
-
<AssemblyName>${assemblyName}.Tests</AssemblyName>
|
|
788
|
-
<RootNamespace>${assemblyName}.Tests</RootNamespace>
|
|
789
|
-
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
|
|
790
|
-
</PropertyGroup>
|
|
791
|
-
<ItemGroup>
|
|
792
|
-
<Compile Include="${base}.Tests.cs" />
|
|
793
|
-
<ProjectReference Include="${base}.csproj" />
|
|
794
|
-
</ItemGroup>
|
|
795
|
-
</Project>
|
|
779
|
+
return `${gerarCabecalhoProjeto(modulo, "executavel de testes .NET autocontido, sem xUnit, MSTest, NUnit ou outro pacote NuGet.")}
|
|
780
|
+
<Project Sdk="Microsoft.NET.Sdk">
|
|
781
|
+
<PropertyGroup>
|
|
782
|
+
<OutputType>Exe</OutputType>
|
|
783
|
+
<TargetFramework>net8.0</TargetFramework>
|
|
784
|
+
<ImplicitUsings>enable</ImplicitUsings>
|
|
785
|
+
<Nullable>enable</Nullable>
|
|
786
|
+
<LangVersion>latest</LangVersion>
|
|
787
|
+
<AssemblyName>${assemblyName}.Tests</AssemblyName>
|
|
788
|
+
<RootNamespace>${assemblyName}.Tests</RootNamespace>
|
|
789
|
+
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
|
|
790
|
+
</PropertyGroup>
|
|
791
|
+
<ItemGroup>
|
|
792
|
+
<Compile Include="${base}.Tests.cs" />
|
|
793
|
+
<ProjectReference Include="${base}.csproj" />
|
|
794
|
+
</ItemGroup>
|
|
795
|
+
</Project>
|
|
796
796
|
`;
|
|
797
797
|
}
|
|
798
798
|
export function gerarDotNet(modulo) {
|
|
@@ -13,40 +13,40 @@ function gerarCampoInput(campo, nivel) {
|
|
|
13
13
|
const obrigatorio = campo.modificadores.includes("required");
|
|
14
14
|
const atributos = obrigatorio ? ' required' : '';
|
|
15
15
|
if (tipoInput === "textarea") {
|
|
16
|
-
return `${indent}<div class="sema-campo">
|
|
17
|
-
${indent} <label for="campo-${campo.nome}">${campo.nome}${obrigatorio ? ' <span class="sema-obrigatorio">*</span>' : ''}</label>
|
|
18
|
-
${indent} <textarea id="campo-${campo.nome}" name="${campo.nome}" data-tipo-sema="${tipo}"${atributos}></textarea>
|
|
16
|
+
return `${indent}<div class="sema-campo">
|
|
17
|
+
${indent} <label for="campo-${campo.nome}">${campo.nome}${obrigatorio ? ' <span class="sema-obrigatorio">*</span>' : ''}</label>
|
|
18
|
+
${indent} <textarea id="campo-${campo.nome}" name="${campo.nome}" data-tipo-sema="${tipo}"${atributos}></textarea>
|
|
19
19
|
${indent}</div>`;
|
|
20
20
|
}
|
|
21
21
|
if (tipoInput === "checkbox") {
|
|
22
|
-
return `${indent}<div class="sema-campo sema-campo-checkbox">
|
|
23
|
-
${indent} <label>
|
|
24
|
-
${indent} <input type="checkbox" id="campo-${campo.nome}" name="${campo.nome}" data-tipo-sema="${tipo}">
|
|
25
|
-
${indent} <span>${campo.nome}</span>
|
|
26
|
-
${indent} </label>
|
|
22
|
+
return `${indent}<div class="sema-campo sema-campo-checkbox">
|
|
23
|
+
${indent} <label>
|
|
24
|
+
${indent} <input type="checkbox" id="campo-${campo.nome}" name="${campo.nome}" data-tipo-sema="${tipo}">
|
|
25
|
+
${indent} <span>${campo.nome}</span>
|
|
26
|
+
${indent} </label>
|
|
27
27
|
${indent}</div>`;
|
|
28
28
|
}
|
|
29
|
-
return `${indent}<div class="sema-campo">
|
|
30
|
-
${indent} <label for="campo-${campo.nome}">${campo.nome}${obrigatorio ? ' <span class="sema-obrigatorio">*</span>' : ''}</label>
|
|
31
|
-
${indent} <input type="${tipoInput}" id="campo-${campo.nome}" name="${campo.nome}" data-tipo-sema="${tipo}"${atributos}>
|
|
29
|
+
return `${indent}<div class="sema-campo">
|
|
30
|
+
${indent} <label for="campo-${campo.nome}">${campo.nome}${obrigatorio ? ' <span class="sema-obrigatorio">*</span>' : ''}</label>
|
|
31
|
+
${indent} <input type="${tipoInput}" id="campo-${campo.nome}" name="${campo.nome}" data-tipo-sema="${tipo}"${atributos}>
|
|
32
32
|
${indent}</div>`;
|
|
33
33
|
}
|
|
34
34
|
function gerarTabelaEntity(entity) {
|
|
35
35
|
const cabecalho = entity.campos.map((campo) => ` <th>${campo.nome} <small>(${campo.tipo})</small></th>`).join("\n");
|
|
36
|
-
return ` <section class="sema-entity" data-entity="${entity.nome}">
|
|
37
|
-
<h3>${entity.nome}</h3>
|
|
38
|
-
<table class="sema-tabela">
|
|
39
|
-
<thead>
|
|
40
|
-
<tr>
|
|
41
|
-
${cabecalho}
|
|
42
|
-
</tr>
|
|
43
|
-
</thead>
|
|
44
|
-
<tbody>
|
|
45
|
-
<tr>
|
|
46
|
-
${entity.campos.map((campo) => ` <td data-campo="${campo.nome}">—</td>`).join("\n")}
|
|
47
|
-
</tr>
|
|
48
|
-
</tbody>
|
|
49
|
-
</table>
|
|
36
|
+
return ` <section class="sema-entity" data-entity="${entity.nome}">
|
|
37
|
+
<h3>${entity.nome}</h3>
|
|
38
|
+
<table class="sema-tabela">
|
|
39
|
+
<thead>
|
|
40
|
+
<tr>
|
|
41
|
+
${cabecalho}
|
|
42
|
+
</tr>
|
|
43
|
+
</thead>
|
|
44
|
+
<tbody>
|
|
45
|
+
<tr>
|
|
46
|
+
${entity.campos.map((campo) => ` <td data-campo="${campo.nome}">—</td>`).join("\n")}
|
|
47
|
+
</tr>
|
|
48
|
+
</tbody>
|
|
49
|
+
</table>
|
|
50
50
|
</section>`;
|
|
51
51
|
}
|
|
52
52
|
function gerarFormularioTask(task) {
|
|
@@ -55,40 +55,40 @@ function gerarFormularioTask(task) {
|
|
|
55
55
|
const erroHtml = erros.length > 0
|
|
56
56
|
? `\n <div class="sema-erros" data-task="${task.nome}">\n${erros.map(([codigo, mensagem]) => ` <div class="sema-erro" data-erro="${codigo}" hidden>${escaparHtml(mensagem)}</div>`).join("\n")}\n </div>`
|
|
57
57
|
: "";
|
|
58
|
-
return ` <section class="sema-task" data-task="${task.nome}">
|
|
59
|
-
<h3>Task: ${task.nome}</h3>
|
|
60
|
-
<form id="form-${normalizarNomeParaSimbolo(task.nome)}" class="sema-formulario" data-task="${task.nome}">
|
|
61
|
-
<fieldset>
|
|
62
|
-
<legend>Entrada</legend>
|
|
63
|
-
${campos}
|
|
64
|
-
</fieldset>
|
|
65
|
-
<button type="submit" class="sema-botao">Executar ${task.nome}</button>
|
|
66
|
-
</form>${erroHtml}
|
|
67
|
-
<div class="sema-saida" data-task-saida="${task.nome}" hidden>
|
|
68
|
-
<h4>Saida</h4>
|
|
69
|
-
${task.output.map((campo) => ` <div class="sema-campo-saida" data-campo="${campo.nome}"><strong>${campo.nome}</strong>: <span>—</span></div>`).join("\n")}
|
|
70
|
-
</div>
|
|
58
|
+
return ` <section class="sema-task" data-task="${task.nome}">
|
|
59
|
+
<h3>Task: ${task.nome}</h3>
|
|
60
|
+
<form id="form-${normalizarNomeParaSimbolo(task.nome)}" class="sema-formulario" data-task="${task.nome}">
|
|
61
|
+
<fieldset>
|
|
62
|
+
<legend>Entrada</legend>
|
|
63
|
+
${campos}
|
|
64
|
+
</fieldset>
|
|
65
|
+
<button type="submit" class="sema-botao">Executar ${task.nome}</button>
|
|
66
|
+
</form>${erroHtml}
|
|
67
|
+
<div class="sema-saida" data-task-saida="${task.nome}" hidden>
|
|
68
|
+
<h4>Saida</h4>
|
|
69
|
+
${task.output.map((campo) => ` <div class="sema-campo-saida" data-campo="${campo.nome}"><strong>${campo.nome}</strong>: <span>—</span></div>`).join("\n")}
|
|
70
|
+
</div>
|
|
71
71
|
</section>`;
|
|
72
72
|
}
|
|
73
73
|
function gerarEnumSelect(enumeracao) {
|
|
74
74
|
const opcoes = enumeracao.valores.map((valor) => ` <option value="${valor}">${valor}</option>`).join("\n");
|
|
75
|
-
return ` <section class="sema-enum" data-enum="${enumeracao.nome}">
|
|
76
|
-
<h3>Enum: ${enumeracao.nome}</h3>
|
|
77
|
-
<select id="enum-${normalizarNomeParaSimbolo(enumeracao.nome)}" class="sema-select" data-enum="${enumeracao.nome}">
|
|
78
|
-
<option value="">— Selecionar —</option>
|
|
79
|
-
${opcoes}
|
|
80
|
-
</select>
|
|
75
|
+
return ` <section class="sema-enum" data-enum="${enumeracao.nome}">
|
|
76
|
+
<h3>Enum: ${enumeracao.nome}</h3>
|
|
77
|
+
<select id="enum-${normalizarNomeParaSimbolo(enumeracao.nome)}" class="sema-select" data-enum="${enumeracao.nome}">
|
|
78
|
+
<option value="">— Selecionar —</option>
|
|
79
|
+
${opcoes}
|
|
80
|
+
</select>
|
|
81
81
|
</section>`;
|
|
82
82
|
}
|
|
83
83
|
function gerarState(state) {
|
|
84
84
|
const transicoes = state.transicoes.length > 0
|
|
85
85
|
? state.transicoes.map((transicao) => ` <li class="sema-transicao"><span class="sema-estado-origem">${transicao.origem}</span> → <span class="sema-estado-destino">${transicao.destino}</span></li>`).join("\n")
|
|
86
86
|
: ' <li>Nenhuma transicao declarada.</li>';
|
|
87
|
-
return ` <section class="sema-state" data-state="${state.nome ?? "anonimo"}">
|
|
88
|
-
<h3>State${state.nome ? `: ${state.nome}` : ""}</h3>
|
|
89
|
-
<ul class="sema-transicoes">
|
|
90
|
-
${transicoes}
|
|
91
|
-
</ul>
|
|
87
|
+
return ` <section class="sema-state" data-state="${state.nome ?? "anonimo"}">
|
|
88
|
+
<h3>State${state.nome ? `: ${state.nome}` : ""}</h3>
|
|
89
|
+
<ul class="sema-transicoes">
|
|
90
|
+
${transicoes}
|
|
91
|
+
</ul>
|
|
92
92
|
</section>`;
|
|
93
93
|
}
|
|
94
94
|
function gerarFlow(flow) {
|
|
@@ -100,37 +100,37 @@ function gerarFlow(flow) {
|
|
|
100
100
|
if (etapa.emErro) {
|
|
101
101
|
destinos.push(`erro → ${etapa.emErro}`);
|
|
102
102
|
}
|
|
103
|
-
return ` <li class="sema-etapa" data-etapa="${etapa.nome}" data-task="${etapa.task ?? ""}">
|
|
104
|
-
<strong>${etapa.nome}</strong>${etapa.task ? ` (usa ${etapa.task})` : ""}${destinos.length > 0 ? ` [${destinos.join(", ")}]` : ""}
|
|
103
|
+
return ` <li class="sema-etapa" data-etapa="${etapa.nome}" data-task="${etapa.task ?? ""}">
|
|
104
|
+
<strong>${etapa.nome}</strong>${etapa.task ? ` (usa ${etapa.task})` : ""}${destinos.length > 0 ? ` [${destinos.join(", ")}]` : ""}
|
|
105
105
|
</li>`;
|
|
106
106
|
}).join("\n");
|
|
107
|
-
return ` <section class="sema-flow" data-flow="${flow.nome}">
|
|
108
|
-
<h3>Flow: ${flow.nome}</h3>
|
|
109
|
-
<ol class="sema-etapas">
|
|
110
|
-
${etapas || ' <li>Nenhuma etapa estruturada.</li>'}
|
|
111
|
-
</ol>
|
|
107
|
+
return ` <section class="sema-flow" data-flow="${flow.nome}">
|
|
108
|
+
<h3>Flow: ${flow.nome}</h3>
|
|
109
|
+
<ol class="sema-etapas">
|
|
110
|
+
${etapas || ' <li>Nenhuma etapa estruturada.</li>'}
|
|
111
|
+
</ol>
|
|
112
112
|
</section>`;
|
|
113
113
|
}
|
|
114
114
|
function gerarRoute(route) {
|
|
115
|
-
return ` <section class="sema-route" data-route="${route.nome}">
|
|
116
|
-
<h3>Route: ${route.nome}</h3>
|
|
117
|
-
<div class="sema-route-detalhe">
|
|
118
|
-
<span class="sema-route-metodo">${route.metodo ?? "POST"}</span>
|
|
119
|
-
<code class="sema-route-caminho">${route.caminho ?? "/"}</code>
|
|
120
|
-
${route.task ? `<span class="sema-route-task">→ ${route.task}</span>` : ""}
|
|
121
|
-
</div>
|
|
122
|
-
${route.inputPublico.length > 0 ? `<details class="sema-route-io"><summary>Input publico</summary><ul>${route.inputPublico.map((campo) => `<li>${campo.nome}: ${campo.tipo}${campo.modificadores.includes("required") ? " (obrigatorio)" : ""}</li>`).join("")}</ul></details>` : ""}
|
|
123
|
-
${route.outputPublico.length > 0 ? `<details class="sema-route-io"><summary>Output publico</summary><ul>${route.outputPublico.map((campo) => `<li>${campo.nome}: ${campo.tipo}</li>`).join("")}</ul></details>` : ""}
|
|
115
|
+
return ` <section class="sema-route" data-route="${route.nome}">
|
|
116
|
+
<h3>Route: ${route.nome}</h3>
|
|
117
|
+
<div class="sema-route-detalhe">
|
|
118
|
+
<span class="sema-route-metodo">${route.metodo ?? "POST"}</span>
|
|
119
|
+
<code class="sema-route-caminho">${route.caminho ?? "/"}</code>
|
|
120
|
+
${route.task ? `<span class="sema-route-task">→ ${route.task}</span>` : ""}
|
|
121
|
+
</div>
|
|
122
|
+
${route.inputPublico.length > 0 ? `<details class="sema-route-io"><summary>Input publico</summary><ul>${route.inputPublico.map((campo) => `<li>${campo.nome}: ${campo.tipo}${campo.modificadores.includes("required") ? " (obrigatorio)" : ""}</li>`).join("")}</ul></details>` : ""}
|
|
123
|
+
${route.outputPublico.length > 0 ? `<details class="sema-route-io"><summary>Output publico</summary><ul>${route.outputPublico.map((campo) => `<li>${campo.nome}: ${campo.tipo}</li>`).join("")}</ul></details>` : ""}
|
|
124
124
|
</section>`;
|
|
125
125
|
}
|
|
126
126
|
function gerarCabecalhoSemaHtml(modulo) {
|
|
127
|
-
return `<!--
|
|
128
|
-
SEMA-GOVERNED
|
|
129
|
-
Módulo de origem: ${escaparHtml(modulo.nome)}
|
|
130
|
-
Consulte o contrato .sema aplicável antes de editar este arquivo.
|
|
131
|
-
Rastreabilidade: outros contratos .sema podem governar este mesmo arquivo via vinculos.
|
|
132
|
-
Para IA
|
|
133
|
-
Descrição: página HTML gerada para humanos e IAs entenderem rapidamente a intenção do contrato.
|
|
127
|
+
return `<!--
|
|
128
|
+
SEMA-GOVERNED
|
|
129
|
+
Módulo de origem: ${escaparHtml(modulo.nome)}
|
|
130
|
+
Consulte o contrato .sema aplicável antes de editar este arquivo.
|
|
131
|
+
Rastreabilidade: outros contratos .sema podem governar este mesmo arquivo via vinculos.
|
|
132
|
+
Para qualquer IA: chame Sema, rode docs-impacto e drift antes de alterar código.
|
|
133
|
+
Descrição: página HTML gerada para humanos e IAs entenderem rapidamente a intenção do contrato.
|
|
134
134
|
-->`;
|
|
135
135
|
}
|
|
136
136
|
export function gerarHtml(modulo) {
|
|
@@ -142,34 +142,34 @@ export function gerarHtml(modulo) {
|
|
|
142
142
|
const tasks = modulo.tasks.map(gerarFormularioTask).join("\n\n");
|
|
143
143
|
const flows = modulo.flows.map(gerarFlow).join("\n\n");
|
|
144
144
|
const routes = modulo.routes.map(gerarRoute).join("\n\n");
|
|
145
|
-
const html = `<!DOCTYPE html>
|
|
146
|
-
${gerarCabecalhoSemaHtml(modulo)}
|
|
147
|
-
<html lang="pt-BR">
|
|
148
|
-
<head>
|
|
149
|
-
<meta charset="UTF-8">
|
|
150
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
151
|
-
<meta name="description" content="Contrato Sema: ${escaparHtml(modulo.nome)}">
|
|
152
|
-
<meta name="sema-governed" content="true">
|
|
153
|
-
<meta name="sema-module" content="${escaparHtml(modulo.nome)}">
|
|
154
|
-
<title>${escaparHtml(titulo)} — Sema</title>
|
|
155
|
-
<link rel="stylesheet" href="${nomeBase}.css">
|
|
156
|
-
</head>
|
|
157
|
-
<body>
|
|
158
|
-
<header class="sema-header">
|
|
159
|
-
<h1>${escaparHtml(titulo)}</h1>
|
|
160
|
-
<p class="sema-subtitulo">Contrato gerado automaticamente pela Sema.</p>
|
|
161
|
-
</header>
|
|
162
|
-
|
|
163
|
-
<main class="sema-main">
|
|
164
|
-
${entidades ? ` <!-- Entities -->\n${entidades}\n\n` : ""}${enums ? ` <!-- Enums -->\n${enums}\n\n` : ""}${states ? ` <!-- States -->\n${states}\n\n` : ""}${tasks ? ` <!-- Tasks -->\n${tasks}\n\n` : ""}${flows ? ` <!-- Flows -->\n${flows}\n\n` : ""}${routes ? ` <!-- Routes -->\n${routes}\n\n` : ""} </main>
|
|
165
|
-
|
|
166
|
-
<footer class="sema-footer">
|
|
167
|
-
<p>Modulo: <code>${escaparHtml(modulo.nome)}</code> | Gerado pela Sema</p>
|
|
168
|
-
</footer>
|
|
169
|
-
|
|
170
|
-
<script src="${nomeBase}.js" type="module"></script>
|
|
171
|
-
</body>
|
|
172
|
-
</html>
|
|
145
|
+
const html = `<!DOCTYPE html>
|
|
146
|
+
${gerarCabecalhoSemaHtml(modulo)}
|
|
147
|
+
<html lang="pt-BR">
|
|
148
|
+
<head>
|
|
149
|
+
<meta charset="UTF-8">
|
|
150
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
151
|
+
<meta name="description" content="Contrato Sema: ${escaparHtml(modulo.nome)}">
|
|
152
|
+
<meta name="sema-governed" content="true">
|
|
153
|
+
<meta name="sema-module" content="${escaparHtml(modulo.nome)}">
|
|
154
|
+
<title>${escaparHtml(titulo)} — Sema</title>
|
|
155
|
+
<link rel="stylesheet" href="${nomeBase}.css">
|
|
156
|
+
</head>
|
|
157
|
+
<body>
|
|
158
|
+
<header class="sema-header">
|
|
159
|
+
<h1>${escaparHtml(titulo)}</h1>
|
|
160
|
+
<p class="sema-subtitulo">Contrato gerado automaticamente pela Sema.</p>
|
|
161
|
+
</header>
|
|
162
|
+
|
|
163
|
+
<main class="sema-main">
|
|
164
|
+
${entidades ? ` <!-- Entities -->\n${entidades}\n\n` : ""}${enums ? ` <!-- Enums -->\n${enums}\n\n` : ""}${states ? ` <!-- States -->\n${states}\n\n` : ""}${tasks ? ` <!-- Tasks -->\n${tasks}\n\n` : ""}${flows ? ` <!-- Flows -->\n${flows}\n\n` : ""}${routes ? ` <!-- Routes -->\n${routes}\n\n` : ""} </main>
|
|
165
|
+
|
|
166
|
+
<footer class="sema-footer">
|
|
167
|
+
<p>Modulo: <code>${escaparHtml(modulo.nome)}</code> | Gerado pela Sema</p>
|
|
168
|
+
</footer>
|
|
169
|
+
|
|
170
|
+
<script src="${nomeBase}.js" type="module"></script>
|
|
171
|
+
</body>
|
|
172
|
+
</html>
|
|
173
173
|
`;
|
|
174
174
|
return [{ caminhoRelativo: `${nomeBase}.html`, conteudo: html }];
|
|
175
175
|
}
|