@semacode/cli 1.5.55 → 2.0.1
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/README.md +50 -7
- package/dist/agentContext.d.ts +1 -1
- package/dist/agentContext.js +3 -3
- package/dist/agentContextPack.js +33 -92
- package/dist/agentContextTipos.d.ts +6 -9
- package/dist/agentContextTipos.js +5 -4
- package/dist/agentEntryPoints.d.ts +22 -2
- package/dist/agentEntryPoints.js +229 -126
- package/dist/docs.part01.js +1 -1
- package/dist/docs.part02.js +21 -10
- package/dist/doctorCommand.d.ts +4 -4
- package/dist/doctorCommand.js +21 -10
- package/dist/exemplosOficiais.d.ts +10 -0
- package/dist/exemplosOficiais.js +32 -22
- package/dist/fsGovernado.js +8 -6
- package/dist/iaPrompts.d.ts +2 -2
- package/dist/iaPrompts.js +3 -3
- package/dist/index.part01.d.ts +1 -1
- package/dist/index.part01.js +6 -6
- package/dist/index.part02.js +1 -1
- package/dist/index.part03.d.ts +1 -0
- package/dist/index.part03.js +26 -12
- package/dist/index.part04.d.ts +1 -0
- package/dist/index.part04.js +49 -21
- package/dist/index.part05.js +1 -1
- package/dist/index.part06.d.ts +1 -1
- package/dist/index.part06.js +27 -18
- package/dist/index.part07.js +20 -20
- package/dist/index.part08.js +4 -8
- package/dist/initCommand.d.ts +3 -1
- package/dist/initCommand.js +41 -12
- package/dist/initTemplatesBase.js +8 -10
- package/dist/workspaceWrite.d.ts +22 -0
- package/dist/workspaceWrite.js +332 -0
- package/docs/README.md +10 -4
- package/docs/ai-integration.md +31 -12
- package/docs/ai-onboarding.md +43 -14
- package/docs/ai-workflow.md +22 -39
- package/docs/auth.md +13 -3
- package/docs/cli.md +21 -8
- package/docs/commands.md +9 -10
- package/docs/deploy.md +27 -4
- package/docs/documentation.md +2 -2
- package/docs/env.md +3 -1
- package/docs/getting-started.md +27 -3
- package/docs/repositories.md +18 -2
- package/docs/rollback.md +23 -5
- package/docs/security.md +8 -0
- package/docs/syntax.md +8 -9
- package/docs/testing.md +15 -4
- package/docs/vocabulary.md +2 -1
- package/package.json +20 -12
- package/dist/billing/index.d.ts +0 -17
- package/dist/billing/index.js +0 -74
package/dist/agentEntryPoints.js
CHANGED
|
@@ -1,12 +1,32 @@
|
|
|
1
|
-
// SEMA-GOVERNED: sema.produto.governanca_ia.contexto.entrypoints
|
|
2
|
-
// Descrição:
|
|
3
|
-
import {
|
|
1
|
+
// SEMA-GOVERNED: sema.produto.governanca_ia.contexto.entrypoints, sema.produto.escrita_segura_workspace
|
|
2
|
+
// Descrição: sincroniza o entrypoint Codex com marcadores estritos e escrita contida no workspace.
|
|
3
|
+
import { readFile, rm, rmdir, stat } from 'node:fs/promises';
|
|
4
4
|
import path from 'node:path';
|
|
5
|
+
import { escreverArquivoWorkspaceSeguro, validarDestinosEscritaWorkspace, } from './workspaceWrite.js';
|
|
5
6
|
import { LIMITE_AVISO_LINHAS_CODIGO_GOVERNADO, LIMITE_AVISO_LINHAS_CONTRATO_SEMA, LIMITE_BLOQUEIO_LINHAS_CODIGO_GOVERNADO, LIMITE_BLOQUEIO_LINHAS_CONTRATO_SEMA, } from './driftOrcamento.js';
|
|
6
7
|
import { ARQUIVO_AGENT_CONTEXT_PACK, ARQUIVO_SEMA_BOOT, ARQUIVO_SEMA_SMALL_MODEL, } from './agentContextTipos.js';
|
|
7
8
|
import { LIMITE_CARACTERES_PAYLOAD_INLINE } from './agentContextPack.js';
|
|
8
9
|
const MARCADOR_SEMA_AGENT_ENTRYPOINT_INICIO = '<!-- sema:agent-entrypoint:start -->';
|
|
9
10
|
const MARCADOR_SEMA_AGENT_ENTRYPOINT_FIM = '<!-- sema:agent-entrypoint:end -->';
|
|
11
|
+
const ENTRYPOINTS_LEGADOS_NAO_CODEX = [
|
|
12
|
+
".clinerules/00-sema.md",
|
|
13
|
+
".clinerules",
|
|
14
|
+
".github/copilot-instructions.md",
|
|
15
|
+
".roo/rules/00-sema.md",
|
|
16
|
+
".opencode/instructions.md",
|
|
17
|
+
".cursor/rules/sema.mdc",
|
|
18
|
+
".claude/CLAUDE.md",
|
|
19
|
+
".windsurf/rules.md",
|
|
20
|
+
];
|
|
21
|
+
export function listarDestinosEntrypointCodex(entrypointCodex) {
|
|
22
|
+
return [
|
|
23
|
+
entrypointCodex,
|
|
24
|
+
"docs/syntax.md",
|
|
25
|
+
"docs/ai-workflow.md",
|
|
26
|
+
"docs/commands.md",
|
|
27
|
+
...ENTRYPOINTS_LEGADOS_NAO_CODEX,
|
|
28
|
+
];
|
|
29
|
+
}
|
|
10
30
|
async function statSeguro(caminho) {
|
|
11
31
|
try {
|
|
12
32
|
return await stat(caminho);
|
|
@@ -20,38 +40,99 @@ function pareceEntradaSemaLegada(conteudo) {
|
|
|
20
40
|
/Sema.*Regras obrigatorias para IA/is.test(conteudo) ||
|
|
21
41
|
/Sema.*Regras obrigatórias para IA/is.test(conteudo);
|
|
22
42
|
}
|
|
43
|
+
function contemVestigioSemaLegado(conteudo) {
|
|
44
|
+
const marcadorIncompleto = conteudo.includes(MARCADOR_SEMA_AGENT_ENTRYPOINT_INICIO) !==
|
|
45
|
+
conteudo.includes(MARCADOR_SEMA_AGENT_ENTRYPOINT_FIM);
|
|
46
|
+
return marcadorIncompleto ||
|
|
47
|
+
pareceEntradaSemaLegada(conteudo) ||
|
|
48
|
+
/\bsema\s+(?:preflight|sync-ai-entrypoints)\b|\buse_cli_local\b/i.test(conteudo);
|
|
49
|
+
}
|
|
23
50
|
function montarBlocoGerenciadoSema(conteudo) {
|
|
24
51
|
return `${MARCADOR_SEMA_AGENT_ENTRYPOINT_INICIO}\n${conteudo.trim()}\n${MARCADOR_SEMA_AGENT_ENTRYPOINT_FIM}\n`;
|
|
25
52
|
}
|
|
26
|
-
|
|
53
|
+
function contarOcorrencias(conteudo, marcador) {
|
|
54
|
+
return conteudo.split(marcador).length - 1;
|
|
55
|
+
}
|
|
56
|
+
function removerBlocosGerenciadosCompletos(conteudo) {
|
|
57
|
+
const partesManuais = [];
|
|
58
|
+
let blocosEncontrados = 0;
|
|
59
|
+
let cursor = 0;
|
|
60
|
+
while (true) {
|
|
61
|
+
const inicio = conteudo.indexOf(MARCADOR_SEMA_AGENT_ENTRYPOINT_INICIO, cursor);
|
|
62
|
+
const fimOrfao = conteudo.indexOf(MARCADOR_SEMA_AGENT_ENTRYPOINT_FIM, cursor);
|
|
63
|
+
if (inicio < 0 && fimOrfao < 0) {
|
|
64
|
+
partesManuais.push(conteudo.slice(cursor));
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
if (inicio < 0 || (fimOrfao >= 0 && fimOrfao < inicio)) {
|
|
68
|
+
return { conteudoManual: conteudo, blocosEncontrados: 0, marcadorIncompleto: true };
|
|
69
|
+
}
|
|
70
|
+
const proximoInicio = conteudo.indexOf(MARCADOR_SEMA_AGENT_ENTRYPOINT_INICIO, inicio + MARCADOR_SEMA_AGENT_ENTRYPOINT_INICIO.length);
|
|
71
|
+
const fimMarcador = conteudo.indexOf(MARCADOR_SEMA_AGENT_ENTRYPOINT_FIM, inicio + MARCADOR_SEMA_AGENT_ENTRYPOINT_INICIO.length);
|
|
72
|
+
if (fimMarcador < 0 || (proximoInicio >= 0 && proximoInicio < fimMarcador)) {
|
|
73
|
+
return { conteudoManual: conteudo, blocosEncontrados: 0, marcadorIncompleto: true };
|
|
74
|
+
}
|
|
75
|
+
partesManuais.push(conteudo.slice(cursor, inicio));
|
|
76
|
+
cursor = fimMarcador + MARCADOR_SEMA_AGENT_ENTRYPOINT_FIM.length;
|
|
77
|
+
blocosEncontrados += 1;
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
conteudoManual: partesManuais.join(""),
|
|
81
|
+
blocosEncontrados,
|
|
82
|
+
marcadorIncompleto: false,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
async function escreverArquivoGerenciadoSema(baseProjeto, caminhoRelativo, conteudo, substituirLegadoSema = false) {
|
|
86
|
+
const caminho = path.join(baseProjeto, caminhoRelativo);
|
|
27
87
|
const bloco = montarBlocoGerenciadoSema(conteudo);
|
|
28
88
|
const atual = await statSeguro(caminho);
|
|
29
89
|
if (!atual) {
|
|
30
|
-
await
|
|
31
|
-
await writeFile(caminho, bloco, "utf8");
|
|
90
|
+
await escreverArquivoWorkspaceSeguro(baseProjeto, caminhoRelativo, bloco);
|
|
32
91
|
return "criado";
|
|
33
92
|
}
|
|
34
93
|
if (!atual.isFile()) {
|
|
35
94
|
return "preservado";
|
|
36
95
|
}
|
|
37
96
|
const textoAtual = await readFile(caminho, "utf8");
|
|
38
|
-
|
|
39
|
-
if (
|
|
40
|
-
|
|
41
|
-
const fim = textoAtual.indexOf(MARCADOR_SEMA_AGENT_ENTRYPOINT_FIM, inicio) + MARCADOR_SEMA_AGENT_ENTRYPOINT_FIM.length;
|
|
42
|
-
proximo = `${textoAtual.slice(0, inicio)}${bloco.trimEnd()}${textoAtual.slice(fim)}`;
|
|
97
|
+
const extraido = removerBlocosGerenciadosCompletos(textoAtual);
|
|
98
|
+
if (extraido.marcadorIncompleto) {
|
|
99
|
+
return "pendente";
|
|
43
100
|
}
|
|
44
|
-
|
|
45
|
-
|
|
101
|
+
const conteudoManual = extraido.conteudoManual.trim();
|
|
102
|
+
const proximo = conteudoManual ? `${bloco}\n${conteudoManual}\n` : bloco;
|
|
103
|
+
const legadoManualPendente = (substituirLegadoSema && extraido.blocosEncontrados === 0 && pareceEntradaSemaLegada(textoAtual)) ||
|
|
104
|
+
contemVestigioSemaLegado(conteudoManual);
|
|
105
|
+
if (proximo === textoAtual) {
|
|
106
|
+
return legadoManualPendente ? "pendente" : "preservado";
|
|
46
107
|
}
|
|
47
|
-
|
|
48
|
-
|
|
108
|
+
await escreverArquivoWorkspaceSeguro(baseProjeto, caminhoRelativo, proximo, {
|
|
109
|
+
sobrescrever: true,
|
|
110
|
+
});
|
|
111
|
+
return legadoManualPendente ? "pendente" : "atualizado";
|
|
112
|
+
}
|
|
113
|
+
async function limparEntrypointLegadoNaoCodex(baseProjeto, caminhoRelativo) {
|
|
114
|
+
const caminho = path.join(baseProjeto, caminhoRelativo);
|
|
115
|
+
const atual = await statSeguro(caminho);
|
|
116
|
+
if (!atual || !atual.isFile()) {
|
|
117
|
+
return null;
|
|
49
118
|
}
|
|
50
|
-
|
|
51
|
-
|
|
119
|
+
const textoAtual = await readFile(caminho, "utf8");
|
|
120
|
+
const extraido = removerBlocosGerenciadosCompletos(textoAtual);
|
|
121
|
+
if (extraido.marcadorIncompleto) {
|
|
122
|
+
return "pendente";
|
|
123
|
+
}
|
|
124
|
+
if (extraido.blocosEncontrados === 0) {
|
|
125
|
+
return contemVestigioSemaLegado(textoAtual) ? "pendente" : "preservado";
|
|
52
126
|
}
|
|
53
|
-
|
|
54
|
-
|
|
127
|
+
const conteudoManual = extraido.conteudoManual.trim();
|
|
128
|
+
if (!conteudoManual) {
|
|
129
|
+
await rm(caminho, { force: true });
|
|
130
|
+
return "removido";
|
|
131
|
+
}
|
|
132
|
+
await escreverArquivoWorkspaceSeguro(baseProjeto, caminhoRelativo, `${conteudoManual}\n`, {
|
|
133
|
+
sobrescrever: true,
|
|
134
|
+
});
|
|
135
|
+
return contemVestigioSemaLegado(conteudoManual) ? "pendente" : "atualizado";
|
|
55
136
|
}
|
|
56
137
|
export function renderizarSemaBoot(agentContextPack) {
|
|
57
138
|
const politica = agentContextPack.politicaIdioma;
|
|
@@ -65,15 +146,14 @@ Você está em um projeto governado por Sema. O contrato semântico vem antes de
|
|
|
65
146
|
|
|
66
147
|
## Primeira ação
|
|
67
148
|
|
|
68
|
-
1.
|
|
69
|
-
2.
|
|
70
|
-
3.
|
|
71
|
-
4.
|
|
72
|
-
5.
|
|
73
|
-
6. Antes de
|
|
74
|
-
7. Antes de
|
|
75
|
-
8.
|
|
76
|
-
9. Se qualquer etapa falhar, pare e diga que está bloqueado.
|
|
149
|
+
1. Confirme \`AGENTS.md\` na raiz e rode \`sema --version\`; se o comando não existir, pare e peça a instalação da CLI.
|
|
150
|
+
2. Use a CLI local diretamente para ler o workspace: \`sema resumo\`, \`sema docs-impacto\`, \`sema inspecionar\`, \`sema drift\` e \`sema impacto\`.
|
|
151
|
+
3. Não use fonte externa de workspace para substituir a CLI local quando ela estiver operacional.
|
|
152
|
+
4. Este boot é para workspace local em disco; se não houver workspace local, pare bloqueado em vez de inventar caminho.
|
|
153
|
+
5. Antes de criar módulo, rota, task ou contrato, inspecione o contrato \`.sema\` aplicável.
|
|
154
|
+
6. Antes de editar código existente, rode drift e impacto pela CLI local.
|
|
155
|
+
7. Antes de criar ou corrigir \`.sema\`, use os exemplos oficiais na CLI local.
|
|
156
|
+
8. Se qualquer etapa falhar, pare e diga que está bloqueado.
|
|
77
157
|
|
|
78
158
|
Não substitua esse fluxo por leitura manual de \`AGENTS.md\`, \`README.md\`, busca local, inferência pelo nome do projeto, bom senso ou ferramenta não citada aqui.
|
|
79
159
|
|
|
@@ -164,11 +244,11 @@ export function renderizarSemaSmallModel(agentContextPack) {
|
|
|
164
244
|
Leia isto primeiro se você tem pouco contexto, pouca memória, pouco tool use ou tendência a ignorar instruções longas.
|
|
165
245
|
|
|
166
246
|
1. Não edite nada antes de chamar Sema.
|
|
167
|
-
2. Em
|
|
247
|
+
2. Em workspace local, rode \`sema --version\`; se falhar, pare e peça a instalação da CLI. Com a CLI disponível, opere diretamente sobre a pasta local e não use espelho externo.
|
|
168
248
|
3. Sema não contorna políticas da plataforma: ele governa contrato, escopo, drift, evidência e qualidade.
|
|
169
249
|
4. Se aparecer alerta de política: pare, explique de forma neutra e não tente burlar filtro.
|
|
170
250
|
5. Se não houver workspace local em disco: pare bloqueado e peça o fluxo apropriado; não invente leitura por caminho.
|
|
171
|
-
6. Se for escrever \`.sema\`:
|
|
251
|
+
6. Se for escrever \`.sema\`: leia \`exemplos/\`; se a pasta estiver ausente, rode \`sema instalar-exemplos --json\` antes.
|
|
172
252
|
7. Se não houver contrato ou vínculo semântico do arquivo: inspecione o arquivo, crie ou edite o contrato aplicável e vincule antes do código.
|
|
173
253
|
8. Se não conseguir chamar Sema: pare e declare bloqueio.
|
|
174
254
|
9. Responda no idioma do usuário. Em PT-BR, use vocabulário Sema: pontuação, desvio semântico, pré-checagem, ambiente de execução e perfil; preserve comandos, endpoints e identificadores.
|
|
@@ -221,12 +301,31 @@ ${agentContextPack.failClosed.map((regra) => `- ${regra}`).join("\n")}
|
|
|
221
301
|
export function renderizarDocumentoAgentesPorCapacidade(agentContextPack) {
|
|
222
302
|
const supportedCapacities = Object.keys(agentContextPack.guiaPorCapacidade).join(", ");
|
|
223
303
|
return [
|
|
224
|
-
"#
|
|
304
|
+
"# Codex Integration",
|
|
305
|
+
"",
|
|
306
|
+
"The official Sema agent integration is Codex through the repository-level",
|
|
307
|
+
"`AGENTS.md`. Codex loads that file automatically and runs the local Sema CLI",
|
|
308
|
+
"inside the project to read contracts, check drift, map impact, and close changes",
|
|
309
|
+
"with evidence.",
|
|
225
310
|
"",
|
|
226
|
-
"Sema is
|
|
227
|
-
"
|
|
228
|
-
"
|
|
229
|
-
"
|
|
311
|
+
"Sema is an independent project and is not affiliated with or endorsed by OpenAI.",
|
|
312
|
+
"Codex surfaces and `AGENTS.md` behavior are documented at",
|
|
313
|
+
"https://learn.chatgpt.com/docs/agent-configuration/agents-md.",
|
|
314
|
+
"",
|
|
315
|
+
"## Before AGENTS.md Exists",
|
|
316
|
+
"",
|
|
317
|
+
"The official Sema skill is the required first-contact bootstrap for Codex in a",
|
|
318
|
+
"project that does not have Sema yet. Install it explicitly:",
|
|
319
|
+
"",
|
|
320
|
+
"```bash",
|
|
321
|
+
"codex plugin marketplace add gerlanss/Sema",
|
|
322
|
+
"codex plugin add sema@sema",
|
|
323
|
+
"```",
|
|
324
|
+
"",
|
|
325
|
+
"The skill locates the local CLI, runs `sema iniciar`, generates `AGENTS.md`, and",
|
|
326
|
+
"then delegates all ongoing workspace governance to that file. It contains no",
|
|
327
|
+
"MCP server, remote workspace bridge, login, license, billing, token, credit,",
|
|
328
|
+
"panel, or authorization gate.",
|
|
230
329
|
"",
|
|
231
330
|
`Supported capacity labels: ${supportedCapacities}.`,
|
|
232
331
|
"",
|
|
@@ -236,12 +335,12 @@ export function renderizarDocumentoAgentesPorCapacidade(agentContextPack) {
|
|
|
236
335
|
"",
|
|
237
336
|
"```bash",
|
|
238
337
|
"sema --version",
|
|
239
|
-
"sema preflight resumo --json",
|
|
240
338
|
"sema resumo",
|
|
241
339
|
"```",
|
|
242
340
|
"",
|
|
243
|
-
"
|
|
244
|
-
"
|
|
341
|
+
"A successful `sema --version` is enough to use the local CLI directly. Local",
|
|
342
|
+
"commands require no login, activation key, license check, token, credits, billing",
|
|
343
|
+
"service, control panel, or external authorization request.",
|
|
245
344
|
"",
|
|
246
345
|
"## Before Editing",
|
|
247
346
|
"",
|
|
@@ -255,19 +354,19 @@ export function renderizarDocumentoAgentesPorCapacidade(agentContextPack) {
|
|
|
255
354
|
"Read every document listed by `docs-impacto` before changing code, contracts,",
|
|
256
355
|
"operational docs, generated artifacts, workflows, profiles, or release material.",
|
|
257
356
|
"",
|
|
258
|
-
"##
|
|
357
|
+
"## Codex Context Tiers",
|
|
259
358
|
"",
|
|
260
|
-
"
|
|
359
|
+
"Codex with a small context budget should start with `" + ARQUIVO_SEMA_BOOT + "`,",
|
|
261
360
|
"`" + ARQUIVO_SEMA_SMALL_MODEL + "`, `SEMA_BRIEF.micro.txt`,",
|
|
262
361
|
"`" + ARQUIVO_AGENT_CONTEXT_PACK + "`, and `SEMA_INDEX.json`. They should stop early",
|
|
263
362
|
"when a gate is unclear.",
|
|
264
363
|
"",
|
|
265
|
-
"
|
|
364
|
+
"Codex with a medium context budget should start with `" + ARQUIVO_SEMA_BOOT + "`,",
|
|
266
365
|
"`" + ARQUIVO_AGENT_CONTEXT_PACK + "`, `SEMA_BRIEF.curto.txt`,",
|
|
267
366
|
"`SEMA_INDEX.json`, and `AGENTS.md`. They must run docs-impact, drift, and",
|
|
268
367
|
"impact before edits.",
|
|
269
368
|
"",
|
|
270
|
-
"
|
|
369
|
+
"Codex with a large context budget may consume `" + ARQUIVO_AGENT_CONTEXT_PACK + "`, `SEMA_BRIEF.md`,",
|
|
271
370
|
"`SEMA_INDEX.json`, AST, IR, drift, and impact outputs, but larger context does",
|
|
272
371
|
"not remove the contract-first rule.",
|
|
273
372
|
"",
|
|
@@ -313,20 +412,20 @@ export function renderizarDocumentoAgentesPorCapacidade(agentContextPack) {
|
|
|
313
412
|
"platform policies, terms of use, permissions, security controls, or laws.",
|
|
314
413
|
].join("\n");
|
|
315
414
|
}
|
|
316
|
-
function
|
|
415
|
+
function renderizarInstrucaoCodexSema(agentContextPack) {
|
|
416
|
+
const capacidade = "media";
|
|
317
417
|
const guia = agentContextPack.guiaPorCapacidade[capacidade];
|
|
318
418
|
const politicaTimeout = agentContextPack.politicaTimeoutResumo;
|
|
319
419
|
const politicaDesign = agentContextPack.politicaDesignVisual;
|
|
320
420
|
const politicaPlataforma = agentContextPack.politicaPlataforma;
|
|
321
|
-
|
|
322
|
-
return `# Sema para ${tituloCliente}
|
|
421
|
+
return `# Sema para Codex
|
|
323
422
|
|
|
324
423
|
Este workspace é governado por Sema. Antes de qualquer ação em código, contrato, documentação operacional, workflow, profile ou deploy:
|
|
325
424
|
|
|
326
425
|
1. Leia \`${ARQUIVO_SEMA_BOOT}\`.
|
|
327
|
-
2.
|
|
328
|
-
3. Use CLI local: \`sema resumo\`, \`sema docs-impacto\`, \`sema inspecionar\`, \`sema drift\` e \`sema impacto\`.
|
|
329
|
-
4. Não use fonte externa de workspace para substituir a CLI local quando
|
|
426
|
+
2. Rode \`sema --version\`; se falhar, pare e peça a instalação da CLI.
|
|
427
|
+
3. Use diretamente a CLI local: \`sema resumo\`, \`sema docs-impacto\`, \`sema inspecionar\`, \`sema drift\` e \`sema impacto\`.
|
|
428
|
+
4. Não use fonte externa de workspace para substituir a CLI local quando ela estiver operacional.
|
|
330
429
|
5. Chame docs-impacto com a intenção declarada antes de agir.
|
|
331
430
|
6. Chame inspecionar no contrato \`.sema\` aplicável.
|
|
332
431
|
7. Antes de editar código existente, rode drift e impacto.
|
|
@@ -336,7 +435,8 @@ Este workspace é governado por Sema. Antes de qualquer ação em código, contr
|
|
|
336
435
|
|
|
337
436
|
É proibido substituir esse fluxo por leitura manual de \`AGENTS.md\`, \`README.md\`, busca local por arquivos, inferência pelo nome do projeto, bom senso ou ferramenta não citada nesta lista.
|
|
338
437
|
|
|
339
|
-
|
|
438
|
+
Entrypoint oficial do Codex: \`${agentContextPack.entrypointCodex}\`.
|
|
439
|
+
Capacidade padrão do Codex: ${capacidade}.
|
|
340
440
|
Ordem de leitura: ${guia.join(" -> ")}.
|
|
341
441
|
|
|
342
442
|
Políticas da plataforma:
|
|
@@ -381,8 +481,8 @@ Idioma:
|
|
|
381
481
|
- Não traduza comandos, rotas, arquivos, endpoints, variáveis, pacotes, marcas, símbolos de código nem palavras-chave da DSL.
|
|
382
482
|
`;
|
|
383
483
|
}
|
|
384
|
-
function renderizarDocSintaxeSemaLocal(
|
|
385
|
-
return `# Sema Syntax for
|
|
484
|
+
function renderizarDocSintaxeSemaLocal(_agentContextPack) {
|
|
485
|
+
return `# Sema Syntax for Codex
|
|
386
486
|
|
|
387
487
|
Use this file as a compact reference before creating or fixing \`.sema\` contracts.
|
|
388
488
|
|
|
@@ -497,35 +597,34 @@ The project can also generate TypeScript, Python, PHP, Dart, Lua, HTML, and CSS
|
|
|
497
597
|
|
|
498
598
|
## Support Files
|
|
499
599
|
|
|
500
|
-
- \`AGENTS.md\`:
|
|
501
|
-
- \`${ARQUIVO_SEMA_BOOT}\`: first read for
|
|
502
|
-
- \`${ARQUIVO_SEMA_SMALL_MODEL}\`:
|
|
503
|
-
- \`${ARQUIVO_AGENT_CONTEXT_PACK}\`: structured
|
|
600
|
+
- \`AGENTS.md\`: official Codex repository rules, loaded automatically.
|
|
601
|
+
- \`${ARQUIVO_SEMA_BOOT}\`: first Sema read for Codex.
|
|
602
|
+
- \`${ARQUIVO_SEMA_SMALL_MODEL}\`: compact guidance for a small context budget.
|
|
603
|
+
- \`${ARQUIVO_AGENT_CONTEXT_PACK}\`: structured Codex context pack.
|
|
504
604
|
- \`SEMA_INDEX.json\`: project index.
|
|
505
605
|
- \`docs/commands.md\`: command catalog, gates, and \`--saida\` rule.
|
|
506
606
|
- \`exemplos/\`: official DSL examples.
|
|
507
607
|
|
|
508
|
-
If
|
|
608
|
+
If Codex does not know which shape to use, it must open \`exemplos/calculadora.sema\`, \`exemplos/crud_simples.sema\`, \`exemplos/pagamento.sema\`, or \`exemplos/tratamento_erro.sema\` before inventing syntax.
|
|
509
609
|
|
|
510
|
-
Platform policy:
|
|
610
|
+
Platform policy: Sema governs project contracts, scope, drift, evidence, and quality. It never bypasses platform policies, permissions, security controls, terms, or laws.
|
|
511
611
|
`;
|
|
512
612
|
}
|
|
513
|
-
function renderizarDocFluxoPraticoSemaLocal(
|
|
514
|
-
return `# Practical
|
|
515
|
-
|
|
516
|
-
This is the minimum workflow for
|
|
517
|
-
|
|
518
|
-
1.
|
|
519
|
-
2.
|
|
520
|
-
3.
|
|
521
|
-
4.
|
|
522
|
-
5.
|
|
523
|
-
6.
|
|
524
|
-
7.
|
|
525
|
-
8.
|
|
526
|
-
9.
|
|
527
|
-
10.
|
|
528
|
-
11. Antes de concluir, rode \`sema finalizar-mudanca\` com as docs lidas.
|
|
613
|
+
function renderizarDocFluxoPraticoSemaLocal(_agentContextPack) {
|
|
614
|
+
return `# Practical Codex + Sema Workflow
|
|
615
|
+
|
|
616
|
+
This is the minimum workflow for Codex in a local workspace.
|
|
617
|
+
|
|
618
|
+
1. Read \`${ARQUIVO_SEMA_BOOT}\`.
|
|
619
|
+
2. Run \`sema --version\`. Success enables direct local execution; there is no login, license, token, billing, panel, or authorization gate.
|
|
620
|
+
3. Run \`sema resumo\`.
|
|
621
|
+
4. Run \`sema docs-impacto --intencao "<change>" --json\`.
|
|
622
|
+
5. Read every required document returned by the command.
|
|
623
|
+
6. Read \`docs/commands.md\` before selecting a command or interpreting \`--saida\`.
|
|
624
|
+
7. Use \`exemplos/\` and \`docs/syntax.md\` before creating or editing a contract.
|
|
625
|
+
8. Run \`sema drift\` and \`sema impacto\` before editing existing code.
|
|
626
|
+
9. Run \`sema formatar\` and \`sema validar\` after changing a \`.sema\` contract.
|
|
627
|
+
10. Run \`sema finalizar-mudanca\` with the documents read before closure.
|
|
529
628
|
|
|
530
629
|
Contract edit rule: \`.sema\` has its own size budget. Above ${LIMITE_AVISO_LINHAS_CONTRATO_SEMA} lines, plan a split by domain/capability; above ${LIMITE_BLOQUEIO_LINHAS_CONTRATO_SEMA}, do not create or edit before splitting. Do not use parte_1/parte_2 and do not force a 1:1 contract-to-file relationship; several contracts can govern the same file through \`vinculos\`.
|
|
531
630
|
|
|
@@ -533,11 +632,11 @@ Closing rule: \`sema drift --json\` must return \`sucesso:true\`. If it reports
|
|
|
533
632
|
|
|
534
633
|
UI rule: if the task involves an interface, minimum evidence includes desktop and mobile. On a narrow viewport such as 390px, \`document.documentElement.scrollWidth <= document.documentElement.clientWidth\` must pass; horizontal scroll blocks closure.
|
|
535
634
|
|
|
536
|
-
##
|
|
635
|
+
## Codex Context Capacity
|
|
537
636
|
|
|
538
|
-
-
|
|
539
|
-
- Medium
|
|
540
|
-
-
|
|
637
|
+
- Small context: \`${ARQUIVO_SEMA_SMALL_MODEL}\`, \`SEMA_BRIEF.micro.txt\`, \`${ARQUIVO_AGENT_CONTEXT_PACK}\`, \`SEMA_INDEX.json\`.
|
|
638
|
+
- Medium context: \`${ARQUIVO_SEMA_BOOT}\`, \`${ARQUIVO_AGENT_CONTEXT_PACK}\`, \`SEMA_BRIEF.curto.txt\`, \`SEMA_INDEX.json\`, \`AGENTS.md\`.
|
|
639
|
+
- Large context: \`${ARQUIVO_SEMA_BOOT}\`, \`${ARQUIVO_AGENT_CONTEXT_PACK}\`, \`SEMA_BRIEF.md\`, \`SEMA_INDEX.json\`, AST, IR, drift, and impact.
|
|
541
640
|
|
|
542
641
|
## When to Generate Code
|
|
543
642
|
|
|
@@ -551,19 +650,21 @@ Replace \`javascript\` with \`typescript\`, \`python\`, \`php\`, \`dart\`, \`lua
|
|
|
551
650
|
|
|
552
651
|
## Fail Closed
|
|
553
652
|
|
|
554
|
-
|
|
653
|
+
- If the local CLI is unavailable, stop before editing governed code or contracts and ask for \`@semacode/cli\` installation.
|
|
654
|
+
- If the applicable contract or semantic link is missing, create or repair it before code.
|
|
655
|
+
- If validation or drift reports failure, broken links, divergent routes, or broken implementations, fix the evidence and run the gate again.
|
|
656
|
+
- A local timeout is not authorization to skip Sema; retry with a larger timeout or a narrower scope.
|
|
555
657
|
`;
|
|
556
658
|
}
|
|
557
659
|
function renderizarDocComandosSemaLocal(agentContextPack) {
|
|
558
660
|
return `# Sema Command Catalog
|
|
559
661
|
|
|
560
|
-
Use this file when
|
|
662
|
+
Use this file when Codex does not know which command to run. A Sema command is an operational gate; do not replace it with a Markdown report.
|
|
561
663
|
|
|
562
664
|
## Minimum Local Flow
|
|
563
665
|
|
|
564
666
|
\`\`\`bash
|
|
565
667
|
sema --version
|
|
566
|
-
sema preflight resumo --json
|
|
567
668
|
sema resumo
|
|
568
669
|
sema docs-impacto --intencao "<acao>" --json
|
|
569
670
|
\`\`\`
|
|
@@ -572,7 +673,7 @@ Then read every required doc returned by \`docs-impacto\`.
|
|
|
572
673
|
|
|
573
674
|
## Contract and Discovery
|
|
574
675
|
|
|
575
|
-
- \`sema iniciar --template <template
|
|
676
|
+
- \`sema iniciar --template <template> [--force]\`: creates a new Sema project and preserves existing files by default; \`--force\` is the only explicit overwrite path.
|
|
576
677
|
- \`sema validar <arquivo-ou-pasta> --json\`: validates \`.sema\` contracts.
|
|
577
678
|
- \`sema diagnosticos <arquivo.sema> --json\`: details errors and warnings.
|
|
578
679
|
- \`sema formatar <arquivo-ou-pasta>\`: formats contracts.
|
|
@@ -611,17 +712,17 @@ Ready UI rule: if the task generates an app, site, dashboard, form, or static HT
|
|
|
611
712
|
|
|
612
713
|
\`sema compilar --alvo javascript\` is a generation target. \`impl { js: ... }\` is the live-code origin. Do not swap one for the other.
|
|
613
714
|
|
|
614
|
-
##
|
|
715
|
+
## Codex and Context
|
|
615
716
|
|
|
616
|
-
- \`sema ajuda-ia\`: short guidance for
|
|
717
|
+
- \`sema ajuda-ia\`: short guidance for Codex.
|
|
617
718
|
- \`sema starter-ia\`: operational starter.
|
|
618
719
|
- \`sema contexto-ia <arquivo.sema> --saida <dir> --json\`: AI context package.
|
|
619
720
|
- \`sema prompt-curto <arquivo-ou-pasta> --json\`: compact prompt.
|
|
620
|
-
- \`sema sync-
|
|
721
|
+
- \`sema sync-codex --json\`: synchronizes the official Codex entrypoint and local support docs.
|
|
621
722
|
- \`sema instalar-exemplos --json\`: installs official examples in the workspace.
|
|
622
723
|
- \`sema exemplos-prompt-ia\`: shows prompt examples, not \`.sema\` examples.
|
|
623
724
|
|
|
624
|
-
## Profiles
|
|
725
|
+
## Profiles and Author
|
|
625
726
|
|
|
626
727
|
- \`sema author iniciar|validar|briefing|revisar-cliches|validar-narrativa|validar-proibicoes\`: governs authorial writing.
|
|
627
728
|
- \`sema profile validar <software|workflow|ops|game|legal|research|redacao|propostas|conversas> <arquivo> --json\`: validates an artifact by profile.
|
|
@@ -637,18 +738,18 @@ Ready UI rule: if the task generates an app, site, dashboard, form, or static HT
|
|
|
637
738
|
- Do not use an external workspace source to inspect a local workspace when \`sema --version\` works.
|
|
638
739
|
- Do not search the entire disk for \`.sema\` syntax; use \`exemplos/\`, \`docs/syntax.md\`, and this catalog.
|
|
639
740
|
- Do not stop after \`sema compilar\` if the contract target files still do not exist.
|
|
640
|
-
- Do not replace \`sema compilar\` with \`sema testar\` when
|
|
741
|
+
- Do not replace \`sema compilar\` with \`sema testar\` when the contract requires generated code.
|
|
641
742
|
- Do not create a Markdown report to pretend a gate ran.
|
|
642
743
|
- Do not say drift passed when \`sema drift --json\` returned \`sucesso:false\`, broken link, divergent route, or broken impl.
|
|
643
744
|
- Do not declare a UI responsive without mobile/desktop proof; horizontal scroll at 390px blocks closure.
|
|
644
745
|
|
|
645
|
-
Governed code policy:
|
|
746
|
+
Governed code policy: keep the \`SEMA-GOVERNED\` marker, split large code by real responsibility, preserve contract links, and never treat a generated output directory as the final delivery.
|
|
646
747
|
`;
|
|
647
748
|
}
|
|
648
|
-
function renderizarAgentStarterLocal(
|
|
649
|
-
return `#
|
|
749
|
+
function renderizarAgentStarterLocal(_agentContextPack) {
|
|
750
|
+
return `# Codex Starter
|
|
650
751
|
|
|
651
|
-
|
|
752
|
+
Codex is operating in a Sema-governed project.
|
|
652
753
|
|
|
653
754
|
Read in this order:
|
|
654
755
|
|
|
@@ -664,7 +765,6 @@ Basic commands:
|
|
|
664
765
|
|
|
665
766
|
\`\`\`bash
|
|
666
767
|
sema --version
|
|
667
|
-
sema preflight resumo --json
|
|
668
768
|
sema resumo
|
|
669
769
|
sema docs-impacto --intencao "<acao>" --json
|
|
670
770
|
sema validar contratos/orders.sema --json
|
|
@@ -678,53 +778,56 @@ Closure is not an opinion: \`sema drift --json\` must be green. \`sucesso:false\
|
|
|
678
778
|
|
|
679
779
|
Ready UI requires proof: desktop/mobile and a narrow viewport without horizontal overflow (\`scrollWidth <= clientWidth\`).
|
|
680
780
|
|
|
681
|
-
|
|
781
|
+
Keep \`SEMA-GOVERNED\` markers and follow the applicable contract before editing governed code.
|
|
682
782
|
`;
|
|
683
783
|
}
|
|
684
|
-
export async function
|
|
784
|
+
export async function sincronizarEntrypointCodex(baseProjeto, agentContextPack) {
|
|
685
785
|
const resultados = [];
|
|
786
|
+
await validarDestinosEscritaWorkspace(baseProjeto, listarDestinosEntrypointCodex(agentContextPack.entrypointCodex));
|
|
686
787
|
const registrar = async (relativo, conteudo, substituirLegadoSema = false) => {
|
|
687
|
-
const
|
|
688
|
-
const status = await escreverArquivoGerenciadoSema(destino, conteudo, substituirLegadoSema);
|
|
788
|
+
const status = await escreverArquivoGerenciadoSema(baseProjeto, relativo, conteudo, substituirLegadoSema);
|
|
689
789
|
resultados.push({ caminho: relativo, status });
|
|
690
790
|
};
|
|
691
|
-
await registrar(
|
|
791
|
+
await registrar(agentContextPack.entrypointCodex, renderizarInstrucaoCodexSema(agentContextPack), true);
|
|
692
792
|
await registrar("docs/syntax.md", renderizarDocSintaxeSemaLocal(agentContextPack), true);
|
|
693
793
|
await registrar("docs/ai-workflow.md", renderizarDocFluxoPraticoSemaLocal(agentContextPack), true);
|
|
694
794
|
await registrar("docs/commands.md", renderizarDocComandosSemaLocal(agentContextPack), true);
|
|
695
|
-
|
|
696
|
-
const
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
else {
|
|
702
|
-
await registrar(".clinerules/00-sema.md", renderizarInstrucaoClienteSema("cline", "fraca", agentContextPack), true);
|
|
703
|
-
}
|
|
704
|
-
await registrar(".roo/rules/00-sema.md", renderizarInstrucaoClienteSema("roo", "fraca", agentContextPack), true);
|
|
705
|
-
const opencodeDir = path.join(baseProjeto, ".opencode");
|
|
706
|
-
const opencodeStat = await statSeguro(opencodeDir);
|
|
707
|
-
if (opencodeStat?.isDirectory()) {
|
|
708
|
-
await registrar(".opencode/instructions.md", renderizarInstrucaoClienteSema("opencode", "media", agentContextPack), true);
|
|
709
|
-
}
|
|
710
|
-
const cursorDir = path.join(baseProjeto, ".cursor");
|
|
711
|
-
const cursorStat = await statSeguro(cursorDir);
|
|
712
|
-
if (cursorStat?.isDirectory()) {
|
|
713
|
-
await registrar(".cursor/rules/sema.mdc", renderizarInstrucaoClienteSema("cursor", "media", agentContextPack), true);
|
|
714
|
-
}
|
|
715
|
-
const claudeDir = path.join(baseProjeto, ".claude");
|
|
716
|
-
const claudeStat = await statSeguro(claudeDir);
|
|
717
|
-
if (claudeStat?.isDirectory()) {
|
|
718
|
-
await registrar(".claude/CLAUDE.md", renderizarInstrucaoClienteSema("claude", "forte", agentContextPack), true);
|
|
719
|
-
}
|
|
720
|
-
const windsurfDir = path.join(baseProjeto, ".windsurf");
|
|
721
|
-
const windsurfStat = await statSeguro(windsurfDir);
|
|
722
|
-
if (windsurfStat?.isDirectory()) {
|
|
723
|
-
await registrar(".windsurf/rules.md", renderizarInstrucaoClienteSema("windsurf", "media", agentContextPack), true);
|
|
795
|
+
const entrypointsLegados = [];
|
|
796
|
+
for (const relativo of ENTRYPOINTS_LEGADOS_NAO_CODEX) {
|
|
797
|
+
const status = await limparEntrypointLegadoNaoCodex(baseProjeto, relativo);
|
|
798
|
+
if (status) {
|
|
799
|
+
entrypointsLegados.push({ caminho: relativo, status });
|
|
800
|
+
}
|
|
724
801
|
}
|
|
802
|
+
await rmdir(path.join(baseProjeto, ".clinerules")).catch(() => undefined);
|
|
725
803
|
const criados = resultados.filter((item) => item.status === "criado").map((item) => item.caminho);
|
|
726
804
|
const atualizados = resultados.filter((item) => item.status === "atualizado").map((item) => item.caminho);
|
|
727
805
|
const preservados = resultados.filter((item) => item.status === "preservado").map((item) => item.caminho);
|
|
728
|
-
|
|
806
|
+
const entrypointsLegadosPendentes = [
|
|
807
|
+
...resultados.filter((item) => item.status === "pendente").map((item) => item.caminho),
|
|
808
|
+
...entrypointsLegados
|
|
809
|
+
.filter((item) => item.status === "pendente")
|
|
810
|
+
.map((item) => item.caminho),
|
|
811
|
+
];
|
|
812
|
+
return {
|
|
813
|
+
arquivos: resultados,
|
|
814
|
+
criados,
|
|
815
|
+
atualizados,
|
|
816
|
+
preservados,
|
|
817
|
+
entrypointCodex: agentContextPack.entrypointCodex,
|
|
818
|
+
codexNativo: true,
|
|
819
|
+
cliLocalSemAutorizacao: true,
|
|
820
|
+
skillBootstrapCodexDocumentada: true,
|
|
821
|
+
idiomaHumanoPreservado: true,
|
|
822
|
+
retryTimeoutProgressivo: true,
|
|
823
|
+
politicaPlataformaExplicita: true,
|
|
824
|
+
politicaSinalVsRitualExplicita: true,
|
|
825
|
+
divisaoPorResponsabilidadeExplicita: true,
|
|
826
|
+
contextoLocalSemEspelho: true,
|
|
827
|
+
destinosEntrypointPrevalidados: true,
|
|
828
|
+
entrypointsLegados,
|
|
829
|
+
entrypointsLegadosPendentes,
|
|
830
|
+
entrypointsLegadosLimpos: entrypointsLegadosPendentes.length === 0,
|
|
831
|
+
};
|
|
729
832
|
}
|
|
730
833
|
//# sourceMappingURL=agentEntryPoints.js.map
|
package/dist/docs.part01.js
CHANGED
|
@@ -173,7 +173,7 @@ export const REGRAS_DOCUMENTACAO = [
|
|
|
173
173
|
},
|
|
174
174
|
{
|
|
175
175
|
categoria: "integracao_ia",
|
|
176
|
-
padroes: [/
|
|
176
|
+
padroes: [/codex/, /agent/, /agente/, /tool/, /ferramenta/],
|
|
177
177
|
docs: [
|
|
178
178
|
{ relativo: "docs/ai-integration.md", tipo: "documentacao", motivo: "integracao do Sema com agentes IA", permitirCriacao: false },
|
|
179
179
|
],
|
package/dist/docs.part02.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
// SEMA-GOVERNED: sema.
|
|
2
|
-
// Descricao:
|
|
3
|
-
import {
|
|
1
|
+
// SEMA-GOVERNED: sema.produto.governanca_ia.documentacao, sema.produto.escrita_segura_workspace
|
|
2
|
+
// Descricao: resolve e cria documentacao obrigatoria sem escapar do workspace nem gravar lotes parcialmente.
|
|
3
|
+
import { readFile } from "node:fs/promises";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { emitirDiagnosticosArquivosOrcamento } from "./driftOrcamento.js";
|
|
6
|
+
import { escreverArquivoWorkspaceSeguro, validarDestinosEscritaWorkspace, } from "./workspaceWrite.js";
|
|
6
7
|
import { REGRAS_DOCUMENTACAO, adicionarDocsRaizExistentes, adicionarReadmesDeArquivos, caminhoEstaDentro, caminhoExiste, criarTemplateDoc, documentoPareceTemplateCriadoPelaSema, inferirCategorias, listarArquivosRecursivo, normalizarRelativo, normalizarTexto, resumoConteudo, termosRelacionamentoContratos } from "./docs.part01.js";
|
|
7
8
|
export async function adicionarContratosRelacionados(baseProjeto, intencao, arquivosAlvo, registrar) {
|
|
8
9
|
const pastaContratos = path.join(baseProjeto, "contratos");
|
|
@@ -55,17 +56,27 @@ export async function resolverDocumentacaoObrigatoria(opcoes) {
|
|
|
55
56
|
}
|
|
56
57
|
await adicionarReadmesDeArquivos(baseProjeto, arquivosAlvo, registrar);
|
|
57
58
|
await adicionarContratosRelacionados(baseProjeto, intencao, arquivosAlvo, registrar);
|
|
58
|
-
const
|
|
59
|
-
for (const doc of docs) {
|
|
59
|
+
const documentosPreparados = await Promise.all(docs.map(async (doc) => {
|
|
60
60
|
const caminho = path.resolve(baseProjeto, doc.relativo);
|
|
61
|
-
|
|
61
|
+
return {
|
|
62
|
+
doc,
|
|
63
|
+
caminho,
|
|
64
|
+
existe: await caminhoExiste(caminho),
|
|
65
|
+
template: criarTemplateDoc(doc, intencao, categorias, arquivosAlvo),
|
|
66
|
+
};
|
|
67
|
+
}));
|
|
68
|
+
if (documentosPreparados.length > 0) {
|
|
69
|
+
await validarDestinosEscritaWorkspace(baseProjeto, documentosPreparados.map(({ doc }) => doc.relativo));
|
|
70
|
+
}
|
|
71
|
+
const leituraObrigatoria = [];
|
|
72
|
+
for (const preparado of documentosPreparados) {
|
|
73
|
+
const { doc, caminho, template } = preparado;
|
|
74
|
+
let existe = preparado.existe;
|
|
62
75
|
let criado = false;
|
|
63
|
-
const template = criarTemplateDoc(doc, intencao, categorias, arquivosAlvo);
|
|
64
76
|
if (!existe && opcoes.criarAusentes && doc.permitirCriacao) {
|
|
65
|
-
await
|
|
66
|
-
await writeFile(caminho, template, "utf8");
|
|
77
|
+
const resultado = await escreverArquivoWorkspaceSeguro(baseProjeto, doc.relativo, template);
|
|
67
78
|
existe = true;
|
|
68
|
-
criado =
|
|
79
|
+
criado = resultado.status === "criado";
|
|
69
80
|
}
|
|
70
81
|
const item = {
|
|
71
82
|
caminho,
|