@semacode/cli 1.5.54 → 2.0.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.
Files changed (63) hide show
  1. package/README.md +51 -7
  2. package/dist/agentContext.d.ts +1 -1
  3. package/dist/agentContext.js +3 -3
  4. package/dist/agentContextPack.js +33 -92
  5. package/dist/agentContextTipos.d.ts +6 -9
  6. package/dist/agentContextTipos.js +5 -4
  7. package/dist/agentEntryPoints.d.ts +22 -2
  8. package/dist/agentEntryPoints.js +232 -129
  9. package/dist/docs.part01.js +1 -1
  10. package/dist/docs.part02.js +21 -10
  11. package/dist/doctorCommand.d.ts +4 -4
  12. package/dist/doctorCommand.js +21 -10
  13. package/dist/exemplosOficiais.d.ts +10 -0
  14. package/dist/exemplosOficiais.js +32 -22
  15. package/dist/fsGovernado.js +8 -6
  16. package/dist/geracaoCore.js +49 -2
  17. package/dist/iaPrompts.d.ts +2 -2
  18. package/dist/iaPrompts.js +5 -5
  19. package/dist/index.part01.d.ts +1 -1
  20. package/dist/index.part01.js +9 -9
  21. package/dist/index.part02.js +1 -1
  22. package/dist/index.part03.d.ts +1 -0
  23. package/dist/index.part03.js +26 -12
  24. package/dist/index.part04.d.ts +1 -0
  25. package/dist/index.part04.js +49 -21
  26. package/dist/index.part05.js +1 -1
  27. package/dist/index.part06.d.ts +1 -1
  28. package/dist/index.part06.js +28 -19
  29. package/dist/index.part07.js +20 -20
  30. package/dist/index.part08.js +4 -8
  31. package/dist/initCommand.d.ts +3 -1
  32. package/dist/initCommand.js +41 -12
  33. package/dist/initTemplatesBase.js +9 -11
  34. package/dist/projetoConfig.js +1 -1
  35. package/dist/workspaceWrite.d.ts +22 -0
  36. package/dist/workspaceWrite.js +332 -0
  37. package/docs/README.md +10 -4
  38. package/docs/ai-integration.md +31 -12
  39. package/docs/ai-onboarding.md +43 -14
  40. package/docs/ai-workflow.md +23 -40
  41. package/docs/auth.md +13 -3
  42. package/docs/cli.md +21 -8
  43. package/docs/commands.md +10 -11
  44. package/docs/deploy.md +27 -4
  45. package/docs/documentation.md +2 -2
  46. package/docs/env.md +3 -1
  47. package/docs/getting-started.md +27 -3
  48. package/docs/repositories.md +18 -2
  49. package/docs/rollback.md +23 -5
  50. package/docs/security.md +8 -0
  51. package/docs/syntax.md +8 -9
  52. package/docs/testing.md +15 -4
  53. package/docs/vocabulary.md +2 -1
  54. package/node_modules/@sema/gerador-php/dist/index.d.ts +3 -0
  55. package/node_modules/@sema/gerador-php/dist/index.js +538 -0
  56. package/node_modules/@sema/gerador-php/dist/index.js.map +1 -0
  57. package/node_modules/@sema/gerador-php/package.json +7 -0
  58. package/node_modules/@sema/padroes/dist/index.d.ts +2 -1
  59. package/node_modules/@sema/padroes/dist/index.js +31 -0
  60. package/node_modules/@sema/padroes/dist/index.js.map +1 -1
  61. package/package.json +22 -12
  62. package/dist/billing/index.d.ts +0 -17
  63. package/dist/billing/index.js +0 -74
@@ -1,12 +1,32 @@
1
- // SEMA-GOVERNED: sema.produto.governanca_ia.contexto.entrypoints
2
- // Descrição: renderiza e sincroniza instruções curtas para agentes de IDE e clientes com disciplina variável.
3
- import { mkdir, readFile, stat, writeFile } from 'node:fs/promises';
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
- async function escreverArquivoGerenciadoSema(caminho, conteudo, substituirLegadoSema = false) {
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 mkdir(path.dirname(caminho), { recursive: true });
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
- let proximo;
39
- if (textoAtual.includes(MARCADOR_SEMA_AGENT_ENTRYPOINT_INICIO) && textoAtual.includes(MARCADOR_SEMA_AGENT_ENTRYPOINT_FIM)) {
40
- const inicio = textoAtual.indexOf(MARCADOR_SEMA_AGENT_ENTRYPOINT_INICIO);
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
- else if (substituirLegadoSema && pareceEntradaSemaLegada(textoAtual)) {
45
- proximo = bloco;
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
- else {
48
- proximo = `${bloco}\n${textoAtual.trimStart()}`;
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
- if (proximo === textoAtual) {
51
- return "preservado";
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
- await writeFile(caminho, proximo.endsWith("\n") ? proximo : `${proximo}\n`, "utf8");
54
- return "atualizado";
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. Em IDE local, confirme \`AGENTS.md\` na raiz e rode \`sema --version\`; se o comando não existir, pare. A IA não acessa o painel Sema: peça ao humano para instalar a CLI pelo painel.
69
- 2. Chame \`sema preflight resumo --json\`; se \`decisao\` não for \`use_cli_local\`, pare bloqueado.
70
- 3. Use a CLI local para ler o workspace: \`sema resumo\`, \`sema docs-impacto\`, \`sema inspecionar\`, \`sema drift\` e \`sema impacto\`.
71
- 4. Não use fonte externa de workspace para substituir a CLI local quando a CLI estiver operacional.
72
- 5. Este boot é para workspace local em disco; se não houver workspace local, pare bloqueado em vez de inventar caminho.
73
- 6. Antes de criar módulo, rota, task ou contrato, inspecione o contrato \`.sema\` aplicável.
74
- 7. Antes de editar código existente, rode drift e impacto pelo caminho autorizado da superfície atual.
75
- 8. Antes de criar ou corrigir \`.sema\`, use \`sema exemplos\` na CLI local.
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 IDE local, rode \`sema --version\`; se falhar, pare. A IA não acessa o painel Sema: peça ao humano para instalar a CLI pelo painel. Depois rode \`sema preflight resumo --json\`; só continue com \`use_cli_local\`; não use fonte externa de workspace para substituir a CLI local.
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\`: use \`sema_exemplos\` antes.
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
- "# AI Integration",
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 designed for AI agents with different context sizes and discipline",
227
- "levels. The public repository documents the local CLI flow only: agents run the",
228
- "CLI inside the project, read contracts, check drift, map impact, and close the",
229
- "change with evidence.",
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
- "Continue only when preflight returns `use_cli_local`. Do not replace the local",
244
- "CLI with an external workspace source, external sync, or project-name guessing.",
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
- "## Capacity Tiers",
357
+ "## Codex Context Tiers",
259
358
  "",
260
- "Weak agents should start with `" + ARQUIVO_SEMA_BOOT + "`,",
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
- "Medium agents should start with `" + ARQUIVO_SEMA_BOOT + "`,",
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
- "Strong agents may consume `" + ARQUIVO_AGENT_CONTEXT_PACK + "`, `SEMA_BRIEF.md`,",
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 renderizarInstrucaoClienteSema(cliente, capacidade, agentContextPack) {
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
- const tituloCliente = cliente === "generico" ? "agente" : cliente;
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. Em IDE local, rode \`sema --version\`; se falhar, pare. A IA não acessa o painel Sema: peça ao humano para instalar a CLI pelo painel. Depois rode \`sema preflight resumo --json\`; se \`decisao\` não for \`use_cli_local\`, pare.
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 a CLI estiver operacional.
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
- Capacidade padrão deste cliente: ${capacidade}.
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(agentContextPack) {
385
- return `# Sema Syntax for AI Agents
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
 
@@ -493,39 +593,38 @@ The CLI supports JavaScript generation:
493
593
  sema compilar contratos/orders.sema --alvo javascript --saida ./generated/javascript
494
594
  \`\`\`
495
595
 
496
- The project can also generate TypeScript, Python, Dart, Lua, HTML, and CSS when those targets are enabled in \`sema.config.json\`.
596
+ The project can also generate TypeScript, Python, PHP, Dart, Lua, HTML, and CSS when those targets are enabled in \`sema.config.json\`.
497
597
 
498
598
  ## Support Files
499
599
 
500
- - \`AGENTS.md\`: required agent rules.
501
- - \`${ARQUIVO_SEMA_BOOT}\`: first read for every AI agent.
502
- - \`${ARQUIVO_SEMA_SMALL_MODEL}\`: short version for weaker agents.
503
- - \`${ARQUIVO_AGENT_CONTEXT_PACK}\`: structured agent context pack.
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 an AI agent 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.
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: ${agentContextPack.politicaPlataforma.regra}
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(agentContextPack) {
514
- return `# Practical AI + Sema Workflow
515
-
516
- This is the minimum workflow for agents in a local workspace.
517
-
518
- 1. Leia \`${ARQUIVO_SEMA_BOOT}\`.
519
- 2. Rode \`sema --version\`.
520
- 3. Rode \`sema preflight resumo --json\` e continue apenas se retornar \`use_cli_local\`.
521
- 4. Rode \`sema resumo\`.
522
- 5. Rode \`sema docs-impacto --intencao "<acao>" --json\`.
523
- 6. Leia a documentacao obrigatoria retornada.
524
- 7. Antes de escolher comando ou interpretar \`--saida\`, leia \`docs/commands.md\`.
525
- 8. Antes de criar ou editar contrato, use \`exemplos/\` e \`docs/syntax.md\`.
526
- 9. Antes de editar codigo existente, rode \`sema drift\` e \`sema impacto\`.
527
- 10. Depois de alterar \`.sema\`, rode \`sema formatar\` e \`sema validar\`.
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
- ## Agent Capacity
635
+ ## Codex Context Capacity
537
636
 
538
- - Weak agent: \`${ARQUIVO_SEMA_SMALL_MODEL}\`, \`SEMA_BRIEF.micro.txt\`, \`${ARQUIVO_AGENT_CONTEXT_PACK}\`, \`SEMA_INDEX.json\`.
539
- - Medium agent: \`${ARQUIVO_SEMA_BOOT}\`, \`${ARQUIVO_AGENT_CONTEXT_PACK}\`, \`SEMA_BRIEF.curto.txt\`, \`SEMA_INDEX.json\`, \`AGENTS.md\`.
540
- - Strong agent: \`${ARQUIVO_SEMA_BOOT}\`, \`${ARQUIVO_AGENT_CONTEXT_PACK}\`, \`SEMA_BRIEF.md\`, \`SEMA_INDEX.json\`, AST, IR, drift, and impact.
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
 
@@ -547,23 +646,25 @@ If the delivery includes code derived from a contract, run \`sema compilar\`.
547
646
  sema compilar contratos/orders.sema --alvo javascript --saida ./generated/javascript
548
647
  \`\`\`
549
648
 
550
- Replace \`javascript\` with \`typescript\`, \`python\`, \`dart\`, \`lua\`, \`html\`, or \`css\` when appropriate.
649
+ Replace \`javascript\` with \`typescript\`, \`python\`, \`php\`, \`dart\`, \`lua\`, \`html\`, or \`css\` when appropriate.
551
650
 
552
651
  ## Fail Closed
553
652
 
554
- ${agentContextPack.failClosed.map((regra) => `- ${regra}`).join("\n")}
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 an AI agent does not know which command to run. A Sema command is an operational gate; do not replace it with a Markdown report.
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>\`: creates a new Sema project with a contract, docs, examples, and AI kit.
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.
@@ -592,7 +693,7 @@ Honest closure: treat drift JSON as the source of truth. \`sucesso:false\`, \`vi
592
693
 
593
694
  ## Sema Code
594
695
 
595
- - \`sema compilar <arquivo-ou-pasta> --alvo <typescript|python|dart|lua|javascript|html|css> --saida <diretorio>\`: generates starter/support artifacts from the contract.
696
+ - \`sema compilar <arquivo-ou-pasta> --alvo <typescript|python|php|dart|lua|javascript|html|css> --saida <diretorio>\`: generates starter/support artifacts from the contract.
596
697
  - \`sema testar <arquivo.sema> --alvo <alvo> --saida <diretorio-temporario>\`: generates and runs local tests when the target supports it.
597
698
  - \`sema importar <fonte> <diretorio> --saida <diretorio> --json\`: imports a legacy project into initial contracts.
598
699
  - \`sema renomear-semantico <arquivo-ou-pasta> --de <nome> --para <nome> --json\`: helps rename symbols semantically.
@@ -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
- ## AI and Context
715
+ ## Codex and Context
615
716
 
616
- - \`sema ajuda-ia\`: short guidance for agents.
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-ai-entrypoints --json\`: synchronizes AGENTS, boot, pack, and local docs.
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 e Author
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 Guard asks for Sema Code.
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: ${agentContextPack.politicaCodigoGovernado.regra}
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(agentContextPack) {
649
- return `# Agent Starter
749
+ function renderizarAgentStarterLocal(_agentContextPack) {
750
+ return `# Codex Starter
650
751
 
651
- You are in a Sema-governed project.
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
- ${agentContextPack.politicaCodigoGovernado.regra}
781
+ Keep \`SEMA-GOVERNED\` markers and follow the applicable contract before editing governed code.
682
782
  `;
683
783
  }
684
- export async function sincronizarEntryPointsAgentes(baseProjeto, agentContextPack) {
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 destino = path.join(baseProjeto, relativo);
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("AGENTS.md", renderizarInstrucaoClienteSema("generico", "media", agentContextPack), true);
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
- await registrar(".github/copilot-instructions.md", renderizarInstrucaoClienteSema("copilot", "media", agentContextPack), true);
696
- const clinePath = path.join(baseProjeto, ".clinerules");
697
- const clineStat = await statSeguro(clinePath);
698
- if (clineStat?.isFile()) {
699
- await registrar(".clinerules", renderizarInstrucaoClienteSema("cline", "fraca", agentContextPack), true);
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
- return { arquivos: resultados, criados, atualizados, preservados };
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
@@ -173,7 +173,7 @@ export const REGRAS_DOCUMENTACAO = [
173
173
  },
174
174
  {
175
175
  categoria: "integracao_ia",
176
- padroes: [/tool/, /ferramenta/, /agent/, /agente/, /copilot/, /cursor/, /cline/, /roo/, /opencode/],
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
  ],