@semacode/cli 4.2.1 → 4.2.2
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IdentificadorDestinoSkillGlobal, OpcoesAmbienteDistribuicaoGlobal, ResultadoDestinoSkillGlobal, ResultadoSkillGlobal } from "./tipos.js";
|
|
2
|
-
export declare const ARQUIVOS_SKILL_SEMA_GERENCIADOS: readonly ["SKILL.md", "agents/openai.yaml"];
|
|
2
|
+
export declare const ARQUIVOS_SKILL_SEMA_GERENCIADOS: readonly ["SKILL.md", "agents/openai.yaml", "references/distribution.md"];
|
|
3
3
|
export declare const NOME_RECIBO_SKILL_SEMA = ".sema-managed.json";
|
|
4
4
|
declare const ESQUEMA_RECIBO = "sema.skill-install-receipt/v1";
|
|
5
5
|
declare const GERENCIADOR_RECIBO = "@semacode/cli";
|
|
@@ -11,6 +11,7 @@ import { versaoSemanticaValida } from "./versaoSemantica.js";
|
|
|
11
11
|
export const ARQUIVOS_SKILL_SEMA_GERENCIADOS = [
|
|
12
12
|
"SKILL.md",
|
|
13
13
|
"agents/openai.yaml",
|
|
14
|
+
"references/distribution.md",
|
|
14
15
|
];
|
|
15
16
|
export const NOME_RECIBO_SKILL_SEMA = ".sema-managed.json";
|
|
16
17
|
const ESQUEMA_RECIBO = "sema.skill-install-receipt/v1";
|
|
@@ -148,6 +149,7 @@ async function carregarSnapshot(opcoes) {
|
|
|
148
149
|
await statDiretorioSeguro(path.join(raizPacote, "skills"));
|
|
149
150
|
await statDiretorioSeguro(origem);
|
|
150
151
|
await statDiretorioSeguro(path.join(origem, "agents"));
|
|
152
|
+
await statDiretorioSeguro(path.join(origem, "references"));
|
|
151
153
|
const pacoteJson = JSON.parse((await lerArquivoSeguro(path.join(raizPacote, "package.json"), LIMITE_RECIBO, raizPacote)).toString("utf8"));
|
|
152
154
|
if (pacoteJson.name !== GERENCIADOR_RECIBO) {
|
|
153
155
|
throw new FalhaDistribuicaoGlobal("BROKEN_TARGET", "PACOTE_INVALIDO");
|
|
@@ -216,16 +218,17 @@ function reciboValido(valor) {
|
|
|
216
218
|
return false;
|
|
217
219
|
}
|
|
218
220
|
if (!candidato.files || typeof candidato.files !== "object" || Array.isArray(candidato.files)
|
|
219
|
-
|| !chavesExatas(candidato.files, [...ARQUIVOS_SKILL_SEMA_GERENCIADOS])
|
|
221
|
+
|| !(chavesExatas(candidato.files, [...ARQUIVOS_SKILL_SEMA_GERENCIADOS])
|
|
222
|
+
|| chavesExatas(candidato.files, ["SKILL.md", "agents/openai.yaml"])))
|
|
220
223
|
return false;
|
|
221
|
-
return
|
|
222
|
-
&& /^[a-f0-9]{64}$/u.test(candidato.files[arquivo])));
|
|
224
|
+
return Object.values(candidato.files).every((hash) => (typeof hash === "string" && /^[a-f0-9]{64}$/u.test(hash)));
|
|
223
225
|
}
|
|
224
226
|
async function estruturaDestinoPermitida(destino) {
|
|
225
227
|
const topo = await readdir(destino, { withFileTypes: true });
|
|
226
228
|
if (topo.length === 0)
|
|
227
229
|
return true;
|
|
228
|
-
if (!chavesExatas(Object.fromEntries(topo.map((entrada) => [entrada.name, true])), ["SKILL.md", "agents", NOME_RECIBO_SKILL_SEMA
|
|
230
|
+
if (!chavesExatas(Object.fromEntries(topo.map((entrada) => [entrada.name, true])), ["SKILL.md", "agents", NOME_RECIBO_SKILL_SEMA,
|
|
231
|
+
...(topo.some((entrada) => entrada.name === "references") ? ["references"] : [])]))
|
|
229
232
|
return false;
|
|
230
233
|
const agents = path.join(destino, "agents");
|
|
231
234
|
await statDiretorioSeguro(agents);
|
|
@@ -235,6 +238,14 @@ async function estruturaDestinoPermitida(destino) {
|
|
|
235
238
|
await validarArquivoRegular(path.join(destino, "SKILL.md"), destino);
|
|
236
239
|
await validarArquivoRegular(path.join(agents, "openai.yaml"), destino);
|
|
237
240
|
await validarArquivoRegular(path.join(destino, NOME_RECIBO_SKILL_SEMA), destino);
|
|
241
|
+
if (topo.some((entrada) => entrada.name === "references")) {
|
|
242
|
+
const referencias = path.join(destino, "references");
|
|
243
|
+
await statDiretorioSeguro(referencias);
|
|
244
|
+
const entradas = await readdir(referencias);
|
|
245
|
+
if (entradas.length !== 1 || entradas[0] !== "distribution.md")
|
|
246
|
+
return false;
|
|
247
|
+
await validarArquivoRegular(path.join(referencias, "distribution.md"), destino);
|
|
248
|
+
}
|
|
238
249
|
return true;
|
|
239
250
|
}
|
|
240
251
|
async function diagnosticarDestino(ambiente, destino) {
|
|
@@ -284,7 +295,12 @@ async function diagnosticarDestino(ambiente, destino) {
|
|
|
284
295
|
identidade,
|
|
285
296
|
};
|
|
286
297
|
}
|
|
287
|
-
|
|
298
|
+
const temReferencia = await lstatOuNull(path.join(destino.caminho, "references")) !== null;
|
|
299
|
+
if (temReferencia !== Object.hasOwn(reciboDesconhecido.files, "references/distribution.md")) {
|
|
300
|
+
return { resultado: resultadoDestino(destino, "BROKEN_TARGET", "CONTEUDO_NAO_GERENCIADO"), identidade };
|
|
301
|
+
}
|
|
302
|
+
// Recibos anteriores a 4.2.2 possuem dois arquivos; validar ownership antes do upgrade.
|
|
303
|
+
for (const relativo of Object.keys(reciboDesconhecido.files)) {
|
|
288
304
|
const absoluto = path.resolve(destino.caminho, ...relativo.split("/"));
|
|
289
305
|
const bytes = await lerArquivoSeguro(absoluto, LIMITE_ARQUIVO_SKILL, ambiente.homeReal);
|
|
290
306
|
if (sha256(bytes) !== reciboDesconhecido.files[relativo]) {
|
|
@@ -322,8 +338,10 @@ async function criarStage(ambiente, destino, arquivos = ambiente.snapshot.arquiv
|
|
|
322
338
|
throw new FalhaDistribuicaoGlobal("BROKEN_TARGET", "DESTINO_ALTERADO");
|
|
323
339
|
}
|
|
324
340
|
await garantirDiretoriosSeguros(ambiente.homeReal, path.join(caminho, "agents"));
|
|
325
|
-
|
|
326
|
-
|
|
341
|
+
if (arquivos.has("references/distribution.md")) {
|
|
342
|
+
await garantirDiretoriosSeguros(ambiente.homeReal, path.join(caminho, "references"));
|
|
343
|
+
}
|
|
344
|
+
for (const [relativo, bytes] of arquivos) {
|
|
327
345
|
if (!bytes)
|
|
328
346
|
throw new FalhaDistribuicaoGlobal("BROKEN_TARGET", "PACOTE_INVALIDO");
|
|
329
347
|
await escreverArquivoAtomico(ambiente.homeReal, path.resolve(caminho, ...relativo.split("/")), bytes, 0o600);
|
|
@@ -537,8 +555,12 @@ export async function capturarSnapshotSkillGlobalTransacao(opcoes = {}) {
|
|
|
537
555
|
destinos.push({ destino, existente: true, vazio: true });
|
|
538
556
|
continue;
|
|
539
557
|
}
|
|
558
|
+
const recibo = await lerArquivoSeguro(path.join(destino.caminho, NOME_RECIBO_SKILL_SEMA), LIMITE_RECIBO, ambiente.homeReal);
|
|
559
|
+
const receipt = JSON.parse(recibo.toString("utf8"));
|
|
560
|
+
if (!reciboValido(receipt))
|
|
561
|
+
throw new FalhaDistribuicaoGlobal("BROKEN_TARGET", "RECIBO_INVALIDO");
|
|
540
562
|
const arquivos = new Map();
|
|
541
|
-
for (const relativo of
|
|
563
|
+
for (const relativo of Object.keys(receipt.files)) {
|
|
542
564
|
arquivos.set(relativo, await lerArquivoSeguro(path.resolve(destino.caminho, ...relativo.split("/")), LIMITE_ARQUIVO_SKILL, ambiente.homeReal));
|
|
543
565
|
}
|
|
544
566
|
destinos.push({
|
|
@@ -546,7 +568,7 @@ export async function capturarSnapshotSkillGlobalTransacao(opcoes = {}) {
|
|
|
546
568
|
existente: true,
|
|
547
569
|
vazio: false,
|
|
548
570
|
arquivos,
|
|
549
|
-
recibo
|
|
571
|
+
recibo,
|
|
550
572
|
});
|
|
551
573
|
}
|
|
552
574
|
return { ambiente, destinos };
|
|
@@ -563,7 +585,7 @@ async function destinoIgualSnapshot(ambiente, snapshot) {
|
|
|
563
585
|
if (!snapshot.arquivos || !snapshot.recibo
|
|
564
586
|
|| !await estruturaDestinoPermitida(snapshot.destino.caminho))
|
|
565
587
|
return false;
|
|
566
|
-
for (const relativo of
|
|
588
|
+
for (const relativo of snapshot.arquivos.keys()) {
|
|
567
589
|
const atual = await lerArquivoSeguro(path.resolve(snapshot.destino.caminho, ...relativo.split("/")), LIMITE_ARQUIVO_SKILL, ambiente.homeReal);
|
|
568
590
|
if (!atual.equals(snapshot.arquivos.get(relativo) ?? Buffer.alloc(0)))
|
|
569
591
|
return false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@semacode/cli",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.2",
|
|
4
4
|
"description": "Local-first semantic governance CLI for AI agents, proven with Claude, Codex, zCode (GLM) and Kimi: contracts, drift, impact, docs gates, and code generation.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"icon": "logo.png",
|