@semacode/cli 2.0.1 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +39 -39
- package/README.md +141 -121
- package/dist/agentEntryPoints.js +499 -499
- package/dist/comandos.js +2 -0
- package/dist/doctorCommand.js +28 -0
- package/dist/execucoesExternas.js +19 -5
- package/dist/geracaoCore.js +97 -1
- package/dist/iaPrompts.d.ts +1 -1
- package/dist/iaPrompts.js +307 -307
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.part01.d.ts +1 -1
- package/dist/index.part01.js +14 -4
- package/dist/index.part02.js +21 -21
- package/dist/index.part04.js +96 -96
- package/dist/index.part06.js +1 -1
- package/dist/index.part07.js +35 -24
- package/dist/init/templates.part01.js +393 -393
- package/dist/init/templates.part02.js +189 -189
- package/dist/initTemplatesBackend.js +73 -73
- package/dist/initTemplatesBase.js +81 -81
- package/dist/initTemplatesFlutter.js +137 -137
- package/dist/initTemplatesRuntime.js +350 -350
- package/dist/initTemplatesWeb.js +309 -309
- package/dist/nativeToolchains.d.ts +15 -0
- package/dist/nativeToolchains.js +132 -0
- package/dist/pipelineConteudo/adapters.d.ts +84 -0
- package/dist/pipelineConteudo/adapters.js +449 -0
- package/dist/pipelineConteudo/canonical.d.ts +18 -0
- package/dist/pipelineConteudo/canonical.js +107 -0
- package/dist/pipelineConteudo/command.d.ts +3 -0
- package/dist/pipelineConteudo/command.js +572 -0
- package/dist/pipelineConteudo/index.d.ts +9 -0
- package/dist/pipelineConteudo/index.js +12 -0
- package/dist/pipelineConteudo/ledger.d.ts +68 -0
- package/dist/pipelineConteudo/ledger.js +732 -0
- package/dist/pipelineConteudo/planner.d.ts +12 -0
- package/dist/pipelineConteudo/planner.js +366 -0
- package/dist/pipelineConteudo/projection.d.ts +16 -0
- package/dist/pipelineConteudo/projection.js +57 -0
- package/dist/pipelineConteudo/state.d.ts +23 -0
- package/dist/pipelineConteudo/state.js +615 -0
- package/dist/pipelineConteudo/trust.d.ts +17 -0
- package/dist/pipelineConteudo/trust.js +750 -0
- package/dist/pipelineConteudo/types.d.ts +331 -0
- package/dist/pipelineConteudo/types.js +4 -0
- package/dist/projetoConfig.js +7 -1
- package/dist/projetoResolucao.js +21 -6
- package/dist/sync/index.js +35 -35
- package/docs/README.md +28 -25
- package/docs/ai-onboarding.md +62 -62
- package/docs/ai-workflow.md +1 -1
- package/docs/auth.md +26 -26
- package/docs/cli.md +79 -72
- package/docs/commands.md +1 -1
- package/docs/database.md +15 -15
- package/docs/deploy.md +41 -36
- package/docs/documentation.md +39 -39
- package/docs/env.md +16 -16
- package/docs/frontend.md +41 -41
- package/docs/getting-started.md +57 -57
- package/docs/i18n.md +15 -15
- package/docs/pipeline-conteudo.md +246 -0
- package/docs/profiles.md +45 -43
- package/docs/repositories.md +43 -43
- package/docs/rollback.md +31 -31
- package/docs/security.md +32 -32
- package/docs/support.md +8 -8
- package/docs/syntax.md +1 -1
- package/docs/testing.md +35 -28
- package/docs/vocabulary.md +29 -29
- package/exemplos/agendamento.sema +1 -1
- package/exemplos/assinatura.sema +1 -1
- package/exemplos/auditoria.sema +1 -1
- package/exemplos/autenticacao.sema +1 -1
- package/exemplos/author_obra_comum.sema +1 -1
- package/exemplos/author_tema_sensivel.sema +1 -1
- package/exemplos/automacao.sema +1 -1
- package/exemplos/cadastro_usuario.sema +1 -1
- package/exemplos/calculadora.sema +1 -1
- package/exemplos/crud_simples.sema +1 -1
- package/exemplos/estoque.sema +1 -1
- package/exemplos/exportacao.sema +1 -1
- package/exemplos/fila.sema +1 -1
- package/exemplos/integracao_externa.sema +1 -1
- package/exemplos/multi_tenant.sema +1 -1
- package/exemplos/notificacao.sema +1 -1
- package/exemplos/operacao_estrategia.sema +132 -132
- package/exemplos/operacao_estrategia_discovery.sema +220 -220
- package/exemplos/operacao_estrategia_fluxo.sema +114 -114
- package/exemplos/operacao_estrategia_gates.sema +106 -106
- package/exemplos/operacao_estrategia_quarentena.sema +133 -133
- package/exemplos/operacao_estrategia_rollout.sema +124 -124
- package/exemplos/pagamento.sema +1 -1
- package/exemplos/pagamento_dominio.sema +1 -1
- package/exemplos/pedido.sema +1 -1
- package/exemplos/permissao.sema +1 -1
- package/exemplos/persistencia_vendor_first.sema +1 -1
- package/exemplos/pipeline-conteudo/README.md +44 -0
- package/exemplos/pipeline-conteudo/alvos.json +23 -0
- package/exemplos/pipeline-conteudo/definicao.json +136 -0
- package/exemplos/profile_conversas.sema +165 -165
- package/exemplos/profile_game.sema +1 -1
- package/exemplos/profile_legal.sema +1 -1
- package/exemplos/profile_ops.sema +1 -1
- package/exemplos/profile_research.sema +1 -1
- package/exemplos/profile_software.sema +1 -1
- package/exemplos/profile_workflow_n8n.sema +1 -1
- package/exemplos/relatorio.sema +1 -1
- package/exemplos/replica_analitica_erp.sema +1 -1
- package/exemplos/testes_embutidos.sema +1 -1
- package/exemplos/tratamento_erro.sema +1 -1
- package/exemplos/upload_arquivo.sema +1 -1
- package/exemplos/webhook.sema +1 -1
- package/node_modules/@sema/gerador-cpp/dist/index.d.ts +3 -0
- package/node_modules/@sema/gerador-cpp/dist/index.js +859 -0
- package/node_modules/@sema/gerador-cpp/dist/index.js.map +1 -0
- package/node_modules/@sema/gerador-cpp/package.json +7 -0
- package/node_modules/@sema/gerador-css/dist/index.part01.js +10 -10
- package/node_modules/@sema/gerador-css/dist/index.part02.js +460 -460
- package/node_modules/@sema/gerador-dotnet/dist/index.d.ts +3 -0
- package/node_modules/@sema/gerador-dotnet/dist/index.js +828 -0
- package/node_modules/@sema/gerador-dotnet/dist/index.js.map +1 -0
- package/node_modules/@sema/gerador-dotnet/package.json +7 -0
- package/node_modules/@sema/gerador-html/dist/index.js +17 -17
- package/node_modules/@sema/gerador-lua/dist/index.js +53 -8
- package/node_modules/@sema/gerador-lua/dist/index.js.map +1 -1
- package/node_modules/@sema/gerador-php/dist/index.js +121 -113
- package/node_modules/@sema/gerador-php/dist/index.js.map +1 -1
- package/node_modules/@sema/gerador-python/dist/index.part02.js +3 -3
- package/node_modules/@sema/gerador-typescript/dist/index.part02.js +11 -11
- package/node_modules/@sema/nucleo/dist/diagnosticos/melhorador.js +42 -42
- package/node_modules/@sema/padroes/dist/index.d.ts +1 -1
- package/package.json +12 -1
|
@@ -0,0 +1,572 @@
|
|
|
1
|
+
// SEMA-GOVERNED: sema.produto.pipeline_conteudo.cli
|
|
2
|
+
// Descrição: CLI declarativa do pipeline de conteúdo; não executa agentes, ferramentas ou publicação.
|
|
3
|
+
import { appendFile, mkdir, readFile, writeFile } from "node:fs/promises";
|
|
4
|
+
import { existsSync, realpathSync } from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { digestEnvelopeConteudo, hashCanonicoConteudo, } from "./canonical.js";
|
|
7
|
+
import { CAPABILITIES_CONTEUDO_PADRAO, } from "./adapters.js";
|
|
8
|
+
import { anexarEventoLedgerConteudo, HEAD_GENESIS_LEDGER_CONTEUDO, validarLedgerConteudo, validarPayloadEventoConteudo, } from "./ledger.js";
|
|
9
|
+
import { planejarPipelineConteudo, validarDefinicaoPipelineConteudo, } from "./planner.js";
|
|
10
|
+
import { projetarManifestoPipelineConteudo } from "./projection.js";
|
|
11
|
+
import { derivarEstadoPipelineConteudo } from "./state.js";
|
|
12
|
+
import { validarConfiguracaoConfiancaConteudo, verificarEnvelopeAssinadoConteudo, } from "./trust.js";
|
|
13
|
+
const OPCOES_COM_VALOR_CONTEUDO = new Set([
|
|
14
|
+
"--alvos-arquivo",
|
|
15
|
+
"--envelope-arquivo",
|
|
16
|
+
"--confianca-arquivo",
|
|
17
|
+
"--payload-type",
|
|
18
|
+
"--capability",
|
|
19
|
+
"--scope",
|
|
20
|
+
"--ledger-id",
|
|
21
|
+
"--expected-head",
|
|
22
|
+
"--politica-arquivo",
|
|
23
|
+
"--ledger-arquivo",
|
|
24
|
+
"--saida",
|
|
25
|
+
"--trust-root-digest",
|
|
26
|
+
"--revocation-digest",
|
|
27
|
+
]);
|
|
28
|
+
const SUBCOMANDOS_CONTEUDO = new Set([
|
|
29
|
+
"ajuda",
|
|
30
|
+
"capabilities",
|
|
31
|
+
"validar",
|
|
32
|
+
"planejar",
|
|
33
|
+
"validar-envelope",
|
|
34
|
+
"registrar",
|
|
35
|
+
"status",
|
|
36
|
+
"projetar",
|
|
37
|
+
]);
|
|
38
|
+
const USOS_PIPELINE_CONTEUDO = [
|
|
39
|
+
"sema conteudo capabilities --json",
|
|
40
|
+
"sema conteudo validar <definition.json> --json",
|
|
41
|
+
"sema conteudo planejar <definition.json> --alvos-arquivo <targets.json> --json",
|
|
42
|
+
"sema conteudo validar-envelope --envelope-arquivo <envelope.json> --confianca-arquivo <trust.json> --trust-root-digest <sha256:...> --revocation-digest <sha256:...> --payload-type <type> --json",
|
|
43
|
+
"sema conteudo registrar <ledger.ndjson> --envelope-arquivo <envelope.json> --politica-arquivo <policy-envelope.json> --confianca-arquivo <trust.json> --trust-root-digest <sha256:...> --revocation-digest <sha256:...> --ledger-id <id> --expected-head <sha256:...> --json",
|
|
44
|
+
"sema conteudo status <definition.json> --politica-arquivo <policy-envelope.json> --confianca-arquivo <trust.json> --trust-root-digest <sha256:...> --revocation-digest <sha256:...> --ledger-arquivo <ledger.ndjson> --expected-head <sha256:...> --json",
|
|
45
|
+
"sema conteudo projetar <definition.json> --politica-arquivo <policy-envelope.json> --confianca-arquivo <trust.json> --trust-root-digest <sha256:...> --revocation-digest <sha256:...> --ledger-arquivo <ledger.ndjson> --expected-head <sha256:...> --saida <manifest.json> --json",
|
|
46
|
+
];
|
|
47
|
+
function ajudaPipelineConteudo() {
|
|
48
|
+
const mensagem = [
|
|
49
|
+
"Sema Content Pipeline — controle AI-native multicanal e multiformato.",
|
|
50
|
+
"",
|
|
51
|
+
"Uso:",
|
|
52
|
+
...USOS_PIPELINE_CONTEUDO.map((uso) => ` ${uso}`),
|
|
53
|
+
"",
|
|
54
|
+
"O runner é externo e avança somente pelos nextActions derivados pelo Sema.",
|
|
55
|
+
"Evidências entram como envelopes assinados; vereditos e transições não são escritos manualmente.",
|
|
56
|
+
"Não existe revisão humana nativa. Chaves privadas permanecem nos processos signatários independentes.",
|
|
57
|
+
].join("\n");
|
|
58
|
+
return {
|
|
59
|
+
sucesso: true,
|
|
60
|
+
comando: "ajuda",
|
|
61
|
+
mensagem,
|
|
62
|
+
usos: USOS_PIPELINE_CONTEUDO,
|
|
63
|
+
nativeHumanReview: false,
|
|
64
|
+
runner: "external",
|
|
65
|
+
canonicalState: "signed_hash_chained_ledger",
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
const CAUSAS_PUBLICAS_CONTEUDO = [
|
|
69
|
+
"expected_head_divergente",
|
|
70
|
+
"trust_root_digest_divergente",
|
|
71
|
+
"revocation_digest_divergente",
|
|
72
|
+
"envelope_politica_ausente",
|
|
73
|
+
"politica_contexto_divergente",
|
|
74
|
+
"politica_expirada",
|
|
75
|
+
];
|
|
76
|
+
function obterOpcaoConteudo(args, nome) {
|
|
77
|
+
const indice = args.indexOf(nome);
|
|
78
|
+
if (indice < 0)
|
|
79
|
+
return undefined;
|
|
80
|
+
const valor = args[indice + 1];
|
|
81
|
+
if (valor === undefined || valor.startsWith("--")) {
|
|
82
|
+
throw new Error(`opcao_sem_valor:${nome}`);
|
|
83
|
+
}
|
|
84
|
+
return valor;
|
|
85
|
+
}
|
|
86
|
+
function posicionaisConteudo(args) {
|
|
87
|
+
const resultado = [];
|
|
88
|
+
for (let indice = 0; indice < args.length; indice += 1) {
|
|
89
|
+
const atual = args[indice];
|
|
90
|
+
if (atual.startsWith("-")) {
|
|
91
|
+
if (OPCOES_COM_VALOR_CONTEUDO.has(atual))
|
|
92
|
+
indice += 1;
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
resultado.push(atual);
|
|
96
|
+
}
|
|
97
|
+
return resultado;
|
|
98
|
+
}
|
|
99
|
+
async function lerJson(arquivo) {
|
|
100
|
+
try {
|
|
101
|
+
return JSON.parse(await readFile(path.resolve(arquivo), "utf8"));
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
throw new Error("json_invalido");
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
async function lerTextoOpcional(arquivo) {
|
|
108
|
+
try {
|
|
109
|
+
return await readFile(path.resolve(arquivo), "utf8");
|
|
110
|
+
}
|
|
111
|
+
catch (erro) {
|
|
112
|
+
if (erro.code === "ENOENT")
|
|
113
|
+
return "";
|
|
114
|
+
throw erro;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function parsearLedgerNdjson(texto) {
|
|
118
|
+
if (texto.trim().length === 0)
|
|
119
|
+
return [];
|
|
120
|
+
return texto
|
|
121
|
+
.split(/\r?\n/u)
|
|
122
|
+
.filter((linha) => linha.trim().length > 0)
|
|
123
|
+
.map((linha, indice) => {
|
|
124
|
+
try {
|
|
125
|
+
return JSON.parse(linha);
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
throw new Error(`ledger_ndjson_invalido:linha_${indice + 1}`);
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
function imprimirConteudo(payload, emJson) {
|
|
133
|
+
if (emJson) {
|
|
134
|
+
console.log(JSON.stringify(payload, null, 2));
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
if (typeof payload === "object" && payload !== null && "mensagem" in payload) {
|
|
138
|
+
console.log(String(payload.mensagem));
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
console.log(JSON.stringify(payload, null, 2));
|
|
142
|
+
}
|
|
143
|
+
function codigoErroPublicoConteudo(erro) {
|
|
144
|
+
const mensagem = erro instanceof Error ? erro.message : "";
|
|
145
|
+
for (const causa of CAUSAS_PUBLICAS_CONTEUDO) {
|
|
146
|
+
if (mensagem === causa || mensagem.includes(`:${causa}`) || mensagem.includes(`,${causa}`))
|
|
147
|
+
return causa;
|
|
148
|
+
}
|
|
149
|
+
return /^([a-z][a-z0-9_]{2,})/u.exec(mensagem)?.[1] ?? "falha_operacional";
|
|
150
|
+
}
|
|
151
|
+
function exigir(valor, nome) {
|
|
152
|
+
if (valor === undefined || valor.trim().length === 0)
|
|
153
|
+
throw new Error(`argumento_obrigatorio_ausente:${nome}`);
|
|
154
|
+
return valor;
|
|
155
|
+
}
|
|
156
|
+
function trustRootDigestEsperado(args) {
|
|
157
|
+
const porFlag = obterOpcaoConteudo(args, "--trust-root-digest");
|
|
158
|
+
const porAmbiente = process.env.SEMA_CONTENT_TRUST_ROOT_DIGEST;
|
|
159
|
+
if (porFlag !== undefined && porAmbiente !== undefined && porFlag !== porAmbiente) {
|
|
160
|
+
throw new Error("trust_root_digest_fontes_divergentes");
|
|
161
|
+
}
|
|
162
|
+
return exigir(porFlag ?? porAmbiente, "--trust-root-digest|SEMA_CONTENT_TRUST_ROOT_DIGEST");
|
|
163
|
+
}
|
|
164
|
+
function revocationDigestEsperado(args) {
|
|
165
|
+
const porFlag = obterOpcaoConteudo(args, "--revocation-digest");
|
|
166
|
+
const porAmbiente = process.env.SEMA_CONTENT_REVOCATION_DIGEST;
|
|
167
|
+
if (porFlag !== undefined && porAmbiente !== undefined && porFlag !== porAmbiente) {
|
|
168
|
+
throw new Error("revocation_digest_fontes_divergentes");
|
|
169
|
+
}
|
|
170
|
+
return exigir(porFlag ?? porAmbiente, "--revocation-digest|SEMA_CONTENT_REVOCATION_DIGEST");
|
|
171
|
+
}
|
|
172
|
+
function raizWorkspaceAtual() {
|
|
173
|
+
let atual = realpathSync(path.resolve(process.cwd()));
|
|
174
|
+
while (true) {
|
|
175
|
+
if (existsSync(path.join(atual, ".git")))
|
|
176
|
+
return atual;
|
|
177
|
+
const pai = path.dirname(atual);
|
|
178
|
+
if (pai === atual)
|
|
179
|
+
return realpathSync(path.resolve(process.cwd()));
|
|
180
|
+
atual = pai;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
function caminhoEstaNoWorkspace(arquivo) {
|
|
184
|
+
const raiz = raizWorkspaceAtual();
|
|
185
|
+
const caminhoReal = realpathSync(path.resolve(arquivo));
|
|
186
|
+
const relativo = path.relative(raiz, caminhoReal);
|
|
187
|
+
return relativo === "" || (!relativo.startsWith(`..${path.sep}`) && relativo !== ".." && !path.isAbsolute(relativo));
|
|
188
|
+
}
|
|
189
|
+
function validarRaizConfiancaDaCli(confianca, confiancaArquivo, args) {
|
|
190
|
+
if (caminhoEstaNoWorkspace(confiancaArquivo) && !args.includes("--development-local-trust")) {
|
|
191
|
+
throw new Error("trust_root_local_requer_development_local_trust");
|
|
192
|
+
}
|
|
193
|
+
const resultado = validarConfiguracaoConfiancaConteudo(confianca, trustRootDigestEsperado(args), revocationDigestEsperado(args));
|
|
194
|
+
if (!resultado.valida)
|
|
195
|
+
throw new Error(`raiz_confianca_invalida:${resultado.bloqueios.join(",")}`);
|
|
196
|
+
return { trustRootDigest: resultado.trustRootDigest, revocationDigest: resultado.revocationDigest };
|
|
197
|
+
}
|
|
198
|
+
function payloadTypeEsperado(payload) {
|
|
199
|
+
return payload.kind === "EVIDENCE_CLAIMED" ? "CLAIM_SUBMITTED" : payload.kind;
|
|
200
|
+
}
|
|
201
|
+
function papeisPermitidos(payload) {
|
|
202
|
+
switch (payload.kind) {
|
|
203
|
+
case "RUN_STARTED": return ["PIPELINE_CONTROLLER"];
|
|
204
|
+
case "ARTIFACT_REGISTERED": return ["PRODUCER"];
|
|
205
|
+
case "EVIDENCE_CLAIMED": return ["PRODUCER", "RUNNER", "ADAPTER"];
|
|
206
|
+
case "EVIDENCE_ATTESTED": return ["EVIDENCE_ATTESTER", "ADAPTER"];
|
|
207
|
+
case "AI_ASSESSMENT": return ["EVALUATOR"];
|
|
208
|
+
case "OPERATIONAL_CONDITION": return ["RUNNER", "ADAPTER"];
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
async function carregarContextoEstado(definicaoArquivo, args) {
|
|
212
|
+
const politicaArquivo = exigir(obterOpcaoConteudo(args, "--politica-arquivo"), "--politica-arquivo");
|
|
213
|
+
const confiancaArquivo = exigir(obterOpcaoConteudo(args, "--confianca-arquivo"), "--confianca-arquivo");
|
|
214
|
+
const ledgerArquivo = exigir(obterOpcaoConteudo(args, "--ledger-arquivo"), "--ledger-arquivo");
|
|
215
|
+
const [definicao, envelopePolitica, confianca, ledgerTexto] = await Promise.all([
|
|
216
|
+
lerJson(definicaoArquivo),
|
|
217
|
+
lerJson(politicaArquivo),
|
|
218
|
+
lerJson(confiancaArquivo),
|
|
219
|
+
lerTextoOpcional(ledgerArquivo),
|
|
220
|
+
]);
|
|
221
|
+
const validacaoDefinicao = validarDefinicaoPipelineConteudo(definicao);
|
|
222
|
+
if (!validacaoDefinicao.valida) {
|
|
223
|
+
throw new Error(`definicao_invalida:${validacaoDefinicao.bloqueios.join(",")}`);
|
|
224
|
+
}
|
|
225
|
+
const { trustRootDigest, revocationDigest } = validarRaizConfiancaDaCli(confianca, confiancaArquivo, args);
|
|
226
|
+
const verificacaoPolitica = verificarEnvelopeAssinadoConteudo(envelopePolitica, confianca, {
|
|
227
|
+
trustRootDigestEsperado: trustRootDigest,
|
|
228
|
+
revocationDigestEsperado: revocationDigest,
|
|
229
|
+
payloadTypeEsperado: "TRUST_POLICY",
|
|
230
|
+
papeisPermitidos: ["POLICY_AUTHORITY"],
|
|
231
|
+
agora: envelopePolitica.payload.issuedAt,
|
|
232
|
+
});
|
|
233
|
+
if (!verificacaoPolitica.valido) {
|
|
234
|
+
throw new Error(`politica_nao_confiavel:${verificacaoPolitica.bloqueios.join(",")}`);
|
|
235
|
+
}
|
|
236
|
+
const politica = envelopePolitica.payload;
|
|
237
|
+
if (politica.definitionDigest !== validacaoDefinicao.definitionDigest) {
|
|
238
|
+
throw new Error("politica_definition_digest_divergente");
|
|
239
|
+
}
|
|
240
|
+
if (politica.trustDomainId !== confianca.trustDomainId) {
|
|
241
|
+
throw new Error("politica_trust_domain_divergente");
|
|
242
|
+
}
|
|
243
|
+
if (typeof politica.runId !== "string" || politica.runId.trim().length === 0) {
|
|
244
|
+
throw new Error("politica_run_id_invalido");
|
|
245
|
+
}
|
|
246
|
+
if (!Number.isFinite(Date.parse(politica.issuedAt)) ||
|
|
247
|
+
!Number.isFinite(Date.parse(politica.expiresAt)) ||
|
|
248
|
+
Date.parse(politica.expiresAt) <= Date.parse(politica.issuedAt) ||
|
|
249
|
+
envelopePolitica.issuedAt !== politica.issuedAt) {
|
|
250
|
+
throw new Error("politica_janela_temporal_invalida");
|
|
251
|
+
}
|
|
252
|
+
if (politica.trustRootDigest !== trustRootDigest) {
|
|
253
|
+
throw new Error("politica_trust_root_digest_divergente");
|
|
254
|
+
}
|
|
255
|
+
if (politica.ledgerId.trim().length === 0)
|
|
256
|
+
throw new Error("politica_ledger_id_ausente");
|
|
257
|
+
if (!/^sha256:[a-f0-9]{64}$/u.test(politica.targetSetDigest)) {
|
|
258
|
+
throw new Error("politica_target_set_digest_invalido");
|
|
259
|
+
}
|
|
260
|
+
if (hashCanonicoConteudo(politica.gates) !== hashCanonicoConteudo(definicao.gates)) {
|
|
261
|
+
throw new Error("politica_gates_divergentes_da_definicao");
|
|
262
|
+
}
|
|
263
|
+
return {
|
|
264
|
+
definicao,
|
|
265
|
+
politica,
|
|
266
|
+
envelopePolitica,
|
|
267
|
+
confianca,
|
|
268
|
+
eventos: parsearLedgerNdjson(ledgerTexto),
|
|
269
|
+
expectedHead: exigir(obterOpcaoConteudo(args, "--expected-head"), "--expected-head"),
|
|
270
|
+
definitionDigest: validacaoDefinicao.definitionDigest,
|
|
271
|
+
policyEnvelopeDigest: digestEnvelopeConteudo(envelopePolitica),
|
|
272
|
+
trustRootDigest,
|
|
273
|
+
revocationDigest,
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
async function registrarEnvelopeLocal(args, ledgerArquivo) {
|
|
277
|
+
const envelopeArquivo = exigir(obterOpcaoConteudo(args, "--envelope-arquivo"), "--envelope-arquivo");
|
|
278
|
+
const confiancaArquivo = exigir(obterOpcaoConteudo(args, "--confianca-arquivo"), "--confianca-arquivo");
|
|
279
|
+
const politicaArquivo = exigir(obterOpcaoConteudo(args, "--politica-arquivo"), "--politica-arquivo");
|
|
280
|
+
const ledgerId = exigir(obterOpcaoConteudo(args, "--ledger-id"), "--ledger-id");
|
|
281
|
+
const expectedHead = exigir(obterOpcaoConteudo(args, "--expected-head"), "--expected-head");
|
|
282
|
+
const [envelope, envelopePolitica, confianca, ledgerAntes] = await Promise.all([
|
|
283
|
+
lerJson(envelopeArquivo),
|
|
284
|
+
lerJson(politicaArquivo),
|
|
285
|
+
lerJson(confiancaArquivo),
|
|
286
|
+
lerTextoOpcional(ledgerArquivo),
|
|
287
|
+
]);
|
|
288
|
+
const { trustRootDigest, revocationDigest } = validarRaizConfiancaDaCli(confianca, confiancaArquivo, args);
|
|
289
|
+
const politica = envelopePolitica.payload;
|
|
290
|
+
const verificacaoPolitica = verificarEnvelopeAssinadoConteudo(envelopePolitica, confianca, {
|
|
291
|
+
trustRootDigestEsperado: trustRootDigest,
|
|
292
|
+
revocationDigestEsperado: revocationDigest,
|
|
293
|
+
payloadTypeEsperado: "TRUST_POLICY",
|
|
294
|
+
papelRequerido: "POLICY_AUTHORITY",
|
|
295
|
+
agora: politica.issuedAt,
|
|
296
|
+
});
|
|
297
|
+
if (!verificacaoPolitica.valido) {
|
|
298
|
+
throw new Error(`politica_nao_confiavel:${verificacaoPolitica.bloqueios.join(",")}`);
|
|
299
|
+
}
|
|
300
|
+
const policyDigest = hashCanonicoConteudo(politica);
|
|
301
|
+
const contextoEsperado = {
|
|
302
|
+
runId: politica.runId,
|
|
303
|
+
trustDomainId: politica.trustDomainId,
|
|
304
|
+
trustRootDigest: politica.trustRootDigest,
|
|
305
|
+
ledgerId: politica.ledgerId,
|
|
306
|
+
policyDigest,
|
|
307
|
+
definitionDigest: politica.definitionDigest,
|
|
308
|
+
};
|
|
309
|
+
if (politica.trustDomainId !== confianca.trustDomainId ||
|
|
310
|
+
politica.trustRootDigest !== trustRootDigest ||
|
|
311
|
+
politica.ledgerId !== ledgerId ||
|
|
312
|
+
envelope.payload.runId !== politica.runId ||
|
|
313
|
+
envelope.payload.policyDigest !== policyDigest ||
|
|
314
|
+
envelope.payload.definitionDigest !== politica.definitionDigest) {
|
|
315
|
+
throw new Error("politica_contexto_divergente");
|
|
316
|
+
}
|
|
317
|
+
const validacaoPayload = validarPayloadEventoConteudo(envelope.payload, {
|
|
318
|
+
principalId: envelope.principalId,
|
|
319
|
+
});
|
|
320
|
+
if (!validacaoPayload.valido) {
|
|
321
|
+
throw new Error(`payload_evento_invalido:${validacaoPayload.bloqueios.join(",")}`);
|
|
322
|
+
}
|
|
323
|
+
if (envelope.payload.trustRootDigest !== trustRootDigest) {
|
|
324
|
+
throw new Error("payload_trust_root_digest_divergente");
|
|
325
|
+
}
|
|
326
|
+
const verificacao = verificarEnvelopeAssinadoConteudo(envelope, confianca, {
|
|
327
|
+
trustRootDigestEsperado: trustRootDigest,
|
|
328
|
+
revocationDigestEsperado: revocationDigest,
|
|
329
|
+
payloadTypeEsperado: payloadTypeEsperado(envelope.payload),
|
|
330
|
+
papeisPermitidos: papeisPermitidos(envelope.payload),
|
|
331
|
+
});
|
|
332
|
+
if (!verificacao.valido)
|
|
333
|
+
throw new Error(`envelope_nao_confiavel:${verificacao.bloqueios.join(",")}`);
|
|
334
|
+
const eventos = parsearLedgerNdjson(ledgerAntes);
|
|
335
|
+
const validacaoAtual = validarLedgerConteudo({
|
|
336
|
+
eventos,
|
|
337
|
+
envelopePolitica,
|
|
338
|
+
ledgerId,
|
|
339
|
+
expectedHead,
|
|
340
|
+
principals: confianca.principals,
|
|
341
|
+
trustRootDigestEsperado: trustRootDigest,
|
|
342
|
+
revocationDigestEsperado: revocationDigest,
|
|
343
|
+
configuracaoConfianca: confianca,
|
|
344
|
+
contextoEsperado,
|
|
345
|
+
});
|
|
346
|
+
if (!validacaoAtual.valido)
|
|
347
|
+
throw new Error(`ledger_invalido:${validacaoAtual.bloqueios.join(",")}`);
|
|
348
|
+
const agora = new Date().toISOString();
|
|
349
|
+
const envelopeDigest = digestEnvelopeConteudo(envelope);
|
|
350
|
+
const anexado = anexarEventoLedgerConteudo(eventos, {
|
|
351
|
+
ledgerId,
|
|
352
|
+
expectedHead,
|
|
353
|
+
schemaVersion: envelope.schemaVersion,
|
|
354
|
+
eventId: `event:${envelopeDigest.slice("sha256:".length)}`,
|
|
355
|
+
recordedAt: agora,
|
|
356
|
+
envelope,
|
|
357
|
+
envelopePolitica,
|
|
358
|
+
configuracaoConfianca: confianca,
|
|
359
|
+
trustRootDigestEsperado: trustRootDigest,
|
|
360
|
+
revocationDigestEsperado: revocationDigest,
|
|
361
|
+
});
|
|
362
|
+
const validacaoNova = validarLedgerConteudo({
|
|
363
|
+
eventos: anexado.eventos,
|
|
364
|
+
envelopePolitica,
|
|
365
|
+
ledgerId,
|
|
366
|
+
expectedHead: anexado.head,
|
|
367
|
+
principals: confianca.principals,
|
|
368
|
+
trustRootDigestEsperado: trustRootDigest,
|
|
369
|
+
revocationDigestEsperado: revocationDigest,
|
|
370
|
+
configuracaoConfianca: confianca,
|
|
371
|
+
contextoEsperado,
|
|
372
|
+
});
|
|
373
|
+
if (!validacaoNova.valido)
|
|
374
|
+
throw new Error(`evento_nao_registravel:${validacaoNova.bloqueios.join(",")}`);
|
|
375
|
+
// Segunda leitura reduz a janela de corrida. NDJSON local continua sem CAS/WORM;
|
|
376
|
+
// armazenamento forte deve ser fornecido por uma fronteira externa.
|
|
377
|
+
if (await lerTextoOpcional(ledgerArquivo) !== ledgerAntes)
|
|
378
|
+
throw new Error("ledger_alterado_durante_append");
|
|
379
|
+
const prefixo = ledgerAntes.length > 0 && !ledgerAntes.endsWith("\n") ? "\n" : "";
|
|
380
|
+
await mkdir(path.dirname(path.resolve(ledgerArquivo)), { recursive: true });
|
|
381
|
+
await appendFile(path.resolve(ledgerArquivo), `${prefixo}${JSON.stringify(anexado.evento)}\n`, "utf8");
|
|
382
|
+
return {
|
|
383
|
+
sucesso: true,
|
|
384
|
+
comando: "registrar",
|
|
385
|
+
backend: "ndjson_local_nao_worm",
|
|
386
|
+
ledgerId,
|
|
387
|
+
previousHead: expectedHead,
|
|
388
|
+
head: anexado.head,
|
|
389
|
+
sequence: anexado.evento.sequence,
|
|
390
|
+
eventId: anexado.evento.eventId,
|
|
391
|
+
trustRootDigest,
|
|
392
|
+
revocationDigest,
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
export async function comandoPipelineConteudo(_posicionaisGlobais, args, emJson) {
|
|
396
|
+
const posicionais = posicionaisConteudo(args);
|
|
397
|
+
const solicitouAjuda = args.includes("--help") || args.includes("-h") || posicionais[0] === "help" || posicionais[0] === "ajuda";
|
|
398
|
+
const subcomando = solicitouAjuda ? "ajuda" : posicionais[0] ?? "capabilities";
|
|
399
|
+
const comandoPublico = SUBCOMANDOS_CONTEUDO.has(subcomando) ? subcomando : "desconhecido";
|
|
400
|
+
try {
|
|
401
|
+
let payload;
|
|
402
|
+
switch (subcomando) {
|
|
403
|
+
case "ajuda":
|
|
404
|
+
payload = ajudaPipelineConteudo();
|
|
405
|
+
break;
|
|
406
|
+
case "capabilities":
|
|
407
|
+
payload = {
|
|
408
|
+
sucesso: true,
|
|
409
|
+
comando: subcomando,
|
|
410
|
+
capabilities: CAPABILITIES_CONTEUDO_PADRAO,
|
|
411
|
+
roles: ["POLICY_AUTHORITY", "PIPELINE_CONTROLLER", "PRODUCER", "RUNNER", "ADAPTER", "EVIDENCE_ATTESTER", "EVALUATOR"],
|
|
412
|
+
payloadTypes: ["TRUST_POLICY", "RUN_STARTED", "ARTIFACT_REGISTERED", "CLAIM_SUBMITTED", "EVIDENCE_ATTESTED", "AI_ASSESSMENT", "OPERATIONAL_CONDITION"],
|
|
413
|
+
nativeHumanReview: false,
|
|
414
|
+
runner: "external",
|
|
415
|
+
canonicalState: "signed_hash_chained_ledger",
|
|
416
|
+
trustRootPin: "required_external_digest",
|
|
417
|
+
revocationPin: "required_external_digest",
|
|
418
|
+
attestationCapability: "content.evidence.attest:<evidenceType>",
|
|
419
|
+
adapterAttestationCapability: "content.adapter.attest:<adapterId>@<version>:<evidenceType>",
|
|
420
|
+
};
|
|
421
|
+
break;
|
|
422
|
+
case "validar": {
|
|
423
|
+
const definicaoArquivo = exigir(posicionais[1], "definition.json");
|
|
424
|
+
const definicao = await lerJson(definicaoArquivo);
|
|
425
|
+
const resultado = validarDefinicaoPipelineConteudo(definicao);
|
|
426
|
+
payload = { sucesso: resultado.valida, comando: subcomando, ...resultado };
|
|
427
|
+
imprimirConteudo(payload, emJson);
|
|
428
|
+
return resultado.valida ? 0 : 1;
|
|
429
|
+
}
|
|
430
|
+
case "planejar": {
|
|
431
|
+
const definicaoArquivo = exigir(posicionais[1], "definition.json");
|
|
432
|
+
const alvosArquivo = exigir(obterOpcaoConteudo(args, "--alvos-arquivo"), "--alvos-arquivo");
|
|
433
|
+
const [definicao, alvos] = await Promise.all([
|
|
434
|
+
lerJson(definicaoArquivo),
|
|
435
|
+
lerJson(alvosArquivo),
|
|
436
|
+
]);
|
|
437
|
+
const resultado = planejarPipelineConteudo(definicao, alvos);
|
|
438
|
+
payload = { sucesso: resultado.bloqueios.length === 0, comando: subcomando, ...resultado };
|
|
439
|
+
imprimirConteudo(payload, emJson);
|
|
440
|
+
return resultado.bloqueios.length === 0 ? 0 : 1;
|
|
441
|
+
}
|
|
442
|
+
case "validar-envelope": {
|
|
443
|
+
const envelopeArquivo = exigir(obterOpcaoConteudo(args, "--envelope-arquivo"), "--envelope-arquivo");
|
|
444
|
+
const confiancaArquivo = exigir(obterOpcaoConteudo(args, "--confianca-arquivo"), "--confianca-arquivo");
|
|
445
|
+
const payloadType = exigir(obterOpcaoConteudo(args, "--payload-type"), "--payload-type");
|
|
446
|
+
const [envelope, confianca] = await Promise.all([
|
|
447
|
+
lerJson(envelopeArquivo),
|
|
448
|
+
lerJson(confiancaArquivo),
|
|
449
|
+
]);
|
|
450
|
+
const { trustRootDigest, revocationDigest } = validarRaizConfiancaDaCli(confianca, confiancaArquivo, args);
|
|
451
|
+
let papeis;
|
|
452
|
+
if (payloadType === "TRUST_POLICY") {
|
|
453
|
+
papeis = ["POLICY_AUTHORITY"];
|
|
454
|
+
}
|
|
455
|
+
else {
|
|
456
|
+
const validacaoPayload = validarPayloadEventoConteudo(envelope.payload, {
|
|
457
|
+
principalId: envelope.principalId,
|
|
458
|
+
});
|
|
459
|
+
if (!validacaoPayload.valido || validacaoPayload.kind === undefined) {
|
|
460
|
+
throw new Error(`payload_evento_invalido:${validacaoPayload.bloqueios.join(",")}`);
|
|
461
|
+
}
|
|
462
|
+
const payloadEvento = envelope.payload;
|
|
463
|
+
if (payloadEvento.trustRootDigest !== trustRootDigest) {
|
|
464
|
+
throw new Error("payload_trust_root_digest_divergente");
|
|
465
|
+
}
|
|
466
|
+
if (payloadTypeEsperado(payloadEvento) !== payloadType) {
|
|
467
|
+
throw new Error("payload_type_incompativel_com_kind");
|
|
468
|
+
}
|
|
469
|
+
papeis = papeisPermitidos(payloadEvento);
|
|
470
|
+
}
|
|
471
|
+
const resultado = verificarEnvelopeAssinadoConteudo(envelope, confianca, {
|
|
472
|
+
trustRootDigestEsperado: trustRootDigest,
|
|
473
|
+
revocationDigestEsperado: revocationDigest,
|
|
474
|
+
payloadTypeEsperado: payloadType,
|
|
475
|
+
capabilityRequerida: obterOpcaoConteudo(args, "--capability"),
|
|
476
|
+
scopeRequerido: obterOpcaoConteudo(args, "--scope"),
|
|
477
|
+
papeisPermitidos: papeis,
|
|
478
|
+
});
|
|
479
|
+
payload = {
|
|
480
|
+
sucesso: resultado.valido,
|
|
481
|
+
comando: subcomando,
|
|
482
|
+
trustRootDigest,
|
|
483
|
+
revocationDigest,
|
|
484
|
+
...resultado,
|
|
485
|
+
envelopeVerificado: undefined,
|
|
486
|
+
};
|
|
487
|
+
imprimirConteudo(payload, emJson);
|
|
488
|
+
return resultado.valido ? 0 : 1;
|
|
489
|
+
}
|
|
490
|
+
case "registrar":
|
|
491
|
+
payload = await registrarEnvelopeLocal(args, exigir(posicionais[1], "ledger.ndjson"));
|
|
492
|
+
break;
|
|
493
|
+
case "status": {
|
|
494
|
+
const definicaoArquivo = exigir(posicionais[1], "definition.json");
|
|
495
|
+
const contexto = await carregarContextoEstado(definicaoArquivo, args);
|
|
496
|
+
const estado = derivarEstadoPipelineConteudo({
|
|
497
|
+
eventos: contexto.eventos,
|
|
498
|
+
envelopePolitica: contexto.envelopePolitica,
|
|
499
|
+
definicao: contexto.definicao,
|
|
500
|
+
configuracaoConfianca: contexto.confianca,
|
|
501
|
+
trustRootDigestEsperado: contexto.trustRootDigest,
|
|
502
|
+
revocationDigestEsperado: contexto.revocationDigest,
|
|
503
|
+
expectedHead: contexto.expectedHead,
|
|
504
|
+
});
|
|
505
|
+
const ledger = validarLedgerConteudo({
|
|
506
|
+
eventos: contexto.eventos,
|
|
507
|
+
envelopePolitica: contexto.envelopePolitica,
|
|
508
|
+
ledgerId: contexto.politica.ledgerId,
|
|
509
|
+
expectedHead: contexto.expectedHead,
|
|
510
|
+
principals: contexto.confianca.principals,
|
|
511
|
+
trustRootDigestEsperado: contexto.trustRootDigest,
|
|
512
|
+
revocationDigestEsperado: contexto.revocationDigest,
|
|
513
|
+
configuracaoConfianca: contexto.confianca,
|
|
514
|
+
contextoEsperado: {
|
|
515
|
+
runId: contexto.politica.runId,
|
|
516
|
+
trustDomainId: contexto.politica.trustDomainId,
|
|
517
|
+
trustRootDigest: contexto.trustRootDigest,
|
|
518
|
+
ledgerId: contexto.politica.ledgerId,
|
|
519
|
+
policyDigest: hashCanonicoConteudo(contexto.politica),
|
|
520
|
+
definitionDigest: contexto.definitionDigest,
|
|
521
|
+
},
|
|
522
|
+
});
|
|
523
|
+
payload = {
|
|
524
|
+
sucesso: ledger.valido && estado.valido,
|
|
525
|
+
comando: subcomando,
|
|
526
|
+
definitionDigest: contexto.definitionDigest,
|
|
527
|
+
policyEnvelopeDigest: contexto.policyEnvelopeDigest,
|
|
528
|
+
trustRootDigest: contexto.trustRootDigest,
|
|
529
|
+
revocationDigest: contexto.revocationDigest,
|
|
530
|
+
ledger,
|
|
531
|
+
estado,
|
|
532
|
+
};
|
|
533
|
+
break;
|
|
534
|
+
}
|
|
535
|
+
case "projetar": {
|
|
536
|
+
const definicaoArquivo = exigir(posicionais[1], "definition.json");
|
|
537
|
+
const contexto = await carregarContextoEstado(definicaoArquivo, args);
|
|
538
|
+
const projecao = projetarManifestoPipelineConteudo({
|
|
539
|
+
eventos: contexto.eventos,
|
|
540
|
+
envelopePolitica: contexto.envelopePolitica,
|
|
541
|
+
definicao: contexto.definicao,
|
|
542
|
+
configuracaoConfianca: contexto.confianca,
|
|
543
|
+
trustRootDigestEsperado: contexto.trustRootDigest,
|
|
544
|
+
revocationDigestEsperado: contexto.revocationDigest,
|
|
545
|
+
expectedHead: contexto.expectedHead,
|
|
546
|
+
});
|
|
547
|
+
const saida = obterOpcaoConteudo(args, "--saida");
|
|
548
|
+
if (saida !== undefined) {
|
|
549
|
+
await mkdir(path.dirname(path.resolve(saida)), { recursive: true });
|
|
550
|
+
await writeFile(path.resolve(saida), `${JSON.stringify(projecao, null, 2)}\n`, "utf8");
|
|
551
|
+
}
|
|
552
|
+
payload = { sucesso: true, comando: subcomando, saida: saida ? path.resolve(saida) : null, projecao };
|
|
553
|
+
break;
|
|
554
|
+
}
|
|
555
|
+
default:
|
|
556
|
+
throw new Error("subcomando_conteudo_desconhecido");
|
|
557
|
+
}
|
|
558
|
+
imprimirConteudo(payload, emJson);
|
|
559
|
+
return 0;
|
|
560
|
+
}
|
|
561
|
+
catch (erro) {
|
|
562
|
+
const falha = {
|
|
563
|
+
sucesso: false,
|
|
564
|
+
comando: comandoPublico,
|
|
565
|
+
erro: codigoErroPublicoConteudo(erro),
|
|
566
|
+
};
|
|
567
|
+
imprimirConteudo(falha, emJson);
|
|
568
|
+
return 1;
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
export { HEAD_GENESIS_LEDGER_CONTEUDO };
|
|
572
|
+
//# sourceMappingURL=command.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./types.js";
|
|
2
|
+
export * from "./canonical.js";
|
|
3
|
+
export { digestConfiguracaoConfiancaConteudo, digestRevogacoesConfiancaConteudo, validarConfiguracaoConfiancaConteudo, verificarEnvelopeAssinadoConteudo, } from "./trust.js";
|
|
4
|
+
export * from "./adapters.js";
|
|
5
|
+
export * from "./planner.js";
|
|
6
|
+
export * from "./ledger.js";
|
|
7
|
+
export * from "./state.js";
|
|
8
|
+
export * from "./projection.js";
|
|
9
|
+
export * from "./command.js";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// SEMA-GOVERNED: sema.produto.pipeline_conteudo
|
|
2
|
+
// Descrição: superfície de biblioteca do pipeline AI-native de conteúdo.
|
|
3
|
+
export * from "./types.js";
|
|
4
|
+
export * from "./canonical.js";
|
|
5
|
+
export { digestConfiguracaoConfiancaConteudo, digestRevogacoesConfiancaConteudo, validarConfiguracaoConfiancaConteudo, verificarEnvelopeAssinadoConteudo, } from "./trust.js";
|
|
6
|
+
export * from "./adapters.js";
|
|
7
|
+
export * from "./planner.js";
|
|
8
|
+
export * from "./ledger.js";
|
|
9
|
+
export * from "./state.js";
|
|
10
|
+
export * from "./projection.js";
|
|
11
|
+
export * from "./command.js";
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { AlegacaoEvidenciaConteudo, ArtefatoConteudo, ConfiguracaoConfiancaConteudo, EnvelopeAssinadoConteudo, EventoLedgerConteudo, EventoPayloadConteudo, InicioExecucaoConteudo, PoliticaConfiancaConteudo, PrincipalConteudo } from "./types.js";
|
|
2
|
+
export declare const HEAD_GENESIS_LEDGER_CONTEUDO: string;
|
|
3
|
+
export interface ContextoEsperadoLedgerConteudo {
|
|
4
|
+
readonly trustDomainId: string;
|
|
5
|
+
readonly trustRootDigest: string;
|
|
6
|
+
readonly ledgerId: string;
|
|
7
|
+
readonly policyDigest: string;
|
|
8
|
+
readonly definitionDigest: string;
|
|
9
|
+
readonly runId: string;
|
|
10
|
+
}
|
|
11
|
+
export interface EntradaValidacaoLedgerConteudo {
|
|
12
|
+
readonly eventos: readonly EventoLedgerConteudo<EventoPayloadConteudo>[];
|
|
13
|
+
readonly envelopePolitica: EnvelopeAssinadoConteudo<PoliticaConfiancaConteudo>;
|
|
14
|
+
readonly ledgerId: string;
|
|
15
|
+
readonly expectedHead: string;
|
|
16
|
+
readonly principals: readonly PrincipalConteudo[];
|
|
17
|
+
readonly trustRootDigestEsperado: string;
|
|
18
|
+
readonly revocationDigestEsperado: string;
|
|
19
|
+
readonly configuracaoConfianca?: Omit<ConfiguracaoConfiancaConteudo, "principals">;
|
|
20
|
+
/** Quando presente, ancora o contexto do RUN_STARTED na policy/definition verificadas pelo chamador. */
|
|
21
|
+
readonly contextoEsperado: ContextoEsperadoLedgerConteudo;
|
|
22
|
+
}
|
|
23
|
+
export interface ResultadoValidacaoLedgerConteudo {
|
|
24
|
+
readonly valido: boolean;
|
|
25
|
+
readonly head: string;
|
|
26
|
+
readonly eventosValidos: number;
|
|
27
|
+
readonly bloqueios: readonly string[];
|
|
28
|
+
}
|
|
29
|
+
export interface EntradaAnexarEventoLedgerConteudo<TPayload extends EventoPayloadConteudo> {
|
|
30
|
+
readonly ledgerId: string;
|
|
31
|
+
/** Checkpoint conservado fora da mutacao que solicita o append. */
|
|
32
|
+
readonly expectedHead: string;
|
|
33
|
+
readonly schemaVersion: string;
|
|
34
|
+
readonly eventId: string;
|
|
35
|
+
readonly recordedAt: string;
|
|
36
|
+
readonly envelope: EnvelopeAssinadoConteudo<TPayload>;
|
|
37
|
+
/** Policy assinada usada para ancorar run, definition e target set. */
|
|
38
|
+
readonly envelopePolitica: EnvelopeAssinadoConteudo<PoliticaConfiancaConteudo>;
|
|
39
|
+
readonly configuracaoConfianca: ConfiguracaoConfiancaConteudo;
|
|
40
|
+
/** Pin fornecido pela fronteira chamadora; nunca derivado implicitamente do arquivo local. */
|
|
41
|
+
readonly trustRootDigestEsperado: string;
|
|
42
|
+
readonly revocationDigestEsperado: string;
|
|
43
|
+
}
|
|
44
|
+
export interface ResultadoAnexarEventoLedgerConteudo<TPayload extends EventoPayloadConteudo> {
|
|
45
|
+
readonly eventos: readonly EventoLedgerConteudo<EventoPayloadConteudo>[];
|
|
46
|
+
readonly evento: EventoLedgerConteudo<TPayload>;
|
|
47
|
+
readonly head: string;
|
|
48
|
+
}
|
|
49
|
+
export interface EntradaValidarPayloadEventoConteudo {
|
|
50
|
+
readonly principalId?: string;
|
|
51
|
+
readonly contextoEsperado?: ContextoEsperadoLedgerConteudo;
|
|
52
|
+
readonly inicio?: InicioExecucaoConteudo;
|
|
53
|
+
readonly artefatosAnteriores?: readonly ArtefatoConteudo[];
|
|
54
|
+
readonly alegacoesAnteriores?: readonly AlegacaoEvidenciaConteudo[];
|
|
55
|
+
}
|
|
56
|
+
export interface ResultadoValidarPayloadEventoConteudo {
|
|
57
|
+
readonly valido: boolean;
|
|
58
|
+
readonly kind?: EventoPayloadConteudo["kind"];
|
|
59
|
+
readonly bloqueios: readonly string[];
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Validador estrutural/contextual publico usado tambem pela CLI antes do append.
|
|
63
|
+
* Ele nao valida assinatura; essa responsabilidade continua na raiz de confianca.
|
|
64
|
+
*/
|
|
65
|
+
export declare function validarPayloadEventoConteudo(valor: unknown, entrada?: EntradaValidarPayloadEventoConteudo): ResultadoValidarPayloadEventoConteudo;
|
|
66
|
+
export declare function calcularHashEventoLedgerConteudo<TPayload>(evento: Omit<EventoLedgerConteudo<TPayload>, "hash">): string;
|
|
67
|
+
export declare function validarLedgerConteudo(entrada: EntradaValidacaoLedgerConteudo): ResultadoValidacaoLedgerConteudo;
|
|
68
|
+
export declare function anexarEventoLedgerConteudo<TPayload extends EventoPayloadConteudo>(eventosAtuais: readonly EventoLedgerConteudo<EventoPayloadConteudo>[], entrada: EntradaAnexarEventoLedgerConteudo<TPayload>): ResultadoAnexarEventoLedgerConteudo<TPayload>;
|