@semacode/cli 2.3.0 → 3.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 (267) hide show
  1. package/LICENSE +39 -39
  2. package/README.md +112 -41
  3. package/dist/agentContextPack.js +14 -10
  4. package/dist/agentEntryPoints.d.ts +5 -0
  5. package/dist/agentEntryPoints.js +102 -91
  6. package/dist/angular-consumer-standalone.d.ts +3 -1
  7. package/dist/angular-consumer-standalone.js +12 -8
  8. package/dist/bin.d.ts +6 -0
  9. package/dist/bin.js +130 -0
  10. package/dist/cliArgs.js +4 -4
  11. package/dist/cliControlError.d.ts +12 -0
  12. package/dist/cliControlError.js +47 -0
  13. package/dist/cliGrammar.d.ts +11 -0
  14. package/dist/cliGrammar.js +551 -0
  15. package/dist/cliHelp.d.ts +13 -0
  16. package/dist/cliHelp.js +19 -0
  17. package/dist/cliHelpTexto.d.ts +3 -0
  18. package/dist/cliHelpTexto.js +168 -0
  19. package/dist/cliRuntime.d.ts +2 -0
  20. package/dist/cliRuntime.js +31 -0
  21. package/dist/comandos.js +9 -22
  22. package/dist/contexto.js +5 -5
  23. package/dist/dev/index.d.ts +1 -0
  24. package/dist/dev/index.js +51 -9
  25. package/dist/discovery/catalog.js +3 -3
  26. package/dist/distribuicao/filesystemGlobal.d.ts +63 -0
  27. package/dist/distribuicao/filesystemGlobal.js +701 -0
  28. package/dist/distribuicao/index.d.ts +7 -0
  29. package/dist/distribuicao/index.js +227 -0
  30. package/dist/distribuicao/launcherGlobal.d.ts +53 -0
  31. package/dist/distribuicao/launcherGlobal.js +643 -0
  32. package/dist/distribuicao/launcherWindows.d.ts +28 -0
  33. package/dist/distribuicao/launcherWindows.js +326 -0
  34. package/dist/distribuicao/lockContextGlobal.d.ts +10 -0
  35. package/dist/distribuicao/lockContextGlobal.js +17 -0
  36. package/dist/distribuicao/lockGlobal.d.ts +6 -0
  37. package/dist/distribuicao/lockGlobal.js +520 -0
  38. package/dist/distribuicao/skillGlobal.d.ts +48 -0
  39. package/dist/distribuicao/skillGlobal.js +652 -0
  40. package/dist/distribuicao/skillIntentPolicy.d.ts +21 -0
  41. package/dist/distribuicao/skillIntentPolicy.js +115 -0
  42. package/dist/distribuicao/tipos.d.ts +50 -0
  43. package/dist/distribuicao/tipos.js +10 -0
  44. package/dist/distribuicao/versaoSemantica.d.ts +3 -0
  45. package/dist/distribuicao/versaoSemantica.js +62 -0
  46. package/dist/drift.part01.d.ts +34 -2
  47. package/dist/drift.part01.js +3 -0
  48. package/dist/drift.part04.d.ts +12 -2
  49. package/dist/drift.part04.js +89 -15
  50. package/dist/drift.part05.d.ts +2 -1
  51. package/dist/drift.part05.js +9 -6
  52. package/dist/drift.part06.d.ts +2 -1
  53. package/dist/drift.part06.js +115 -24
  54. package/dist/drift.part07.d.ts +11 -10
  55. package/dist/drift.part07.js +261 -255
  56. package/dist/drift.part08.d.ts +2 -1
  57. package/dist/drift.part08.js +35 -25
  58. package/dist/drift.part11.js +279 -32
  59. package/dist/drift.part12.d.ts +1 -1
  60. package/dist/drift.part12.js +196 -11
  61. package/dist/drift.part13.d.ts +18 -2
  62. package/dist/drift.part13.js +654 -76
  63. package/dist/drift.part14.js +21 -7
  64. package/dist/driftCacheCas.d.ts +43 -0
  65. package/dist/driftCacheCas.js +351 -0
  66. package/dist/driftCacheFilesystem.d.ts +64 -0
  67. package/dist/driftCacheFilesystem.js +313 -0
  68. package/dist/driftCacheModes.d.ts +38 -0
  69. package/dist/driftCacheModes.js +147 -0
  70. package/dist/driftCacheStore.d.ts +80 -0
  71. package/dist/driftCacheStore.js +603 -0
  72. package/dist/driftCatalogo.d.ts +65 -0
  73. package/dist/driftCatalogo.js +516 -0
  74. package/dist/driftEscopo.d.ts +21 -0
  75. package/dist/driftEscopo.js +647 -0
  76. package/dist/driftEscopoReferencias.d.ts +8 -0
  77. package/dist/driftEscopoReferencias.js +612 -0
  78. package/dist/driftOrcamento.d.ts +6 -0
  79. package/dist/driftOrcamento.js +20 -3
  80. package/dist/geracaoCore.js +4 -6
  81. package/dist/iaPrompts.d.ts +3 -3
  82. package/dist/iaPrompts.js +13 -14
  83. package/dist/index.d.ts +4 -1
  84. package/dist/index.js +6 -25
  85. package/dist/index.part01.d.ts +21 -14
  86. package/dist/index.part01.js +20 -165
  87. package/dist/index.part02.js +57 -43
  88. package/dist/index.part03.d.ts +23 -1
  89. package/dist/index.part03.js +83 -8
  90. package/dist/index.part04.d.ts +10 -2
  91. package/dist/index.part04.js +48 -14
  92. package/dist/index.part05.d.ts +1 -1
  93. package/dist/index.part05.js +109 -30
  94. package/dist/index.part06.js +34 -16
  95. package/dist/index.part07.js +31 -27
  96. package/dist/index.part08.d.ts +1 -1
  97. package/dist/index.part08.js +23 -28
  98. package/dist/init/templates.part01.js +393 -393
  99. package/dist/init/templates.part02.js +189 -189
  100. package/dist/initCommand.js +5 -1
  101. package/dist/initTemplatesBackend.js +73 -73
  102. package/dist/initTemplatesBase.js +7 -5
  103. package/dist/initTemplatesFlutter.js +137 -137
  104. package/dist/initTemplatesRuntime.js +350 -350
  105. package/dist/initTemplatesWeb.js +309 -309
  106. package/dist/pipelineConteudo/command.d.ts +1 -0
  107. package/dist/pipelineConteudo/command.js +4 -32
  108. package/dist/pipelineConteudo/help.d.ts +2 -0
  109. package/dist/pipelineConteudo/help.js +33 -0
  110. package/dist/profileAuthorCommand.js +3 -7
  111. package/dist/profileCommand.js +3 -7
  112. package/dist/projeto.d.ts +1 -1
  113. package/dist/projetoCarregar.d.ts +2 -2
  114. package/dist/projetoCarregar.js +69 -28
  115. package/dist/projetoCatalogo.d.ts +8 -0
  116. package/dist/projetoCatalogo.js +164 -0
  117. package/dist/projetoOrigens.d.ts +2 -0
  118. package/dist/projetoOrigens.js +65 -9
  119. package/dist/projetoTipos.d.ts +15 -5
  120. package/dist/resultadoCli.d.ts +20 -0
  121. package/dist/resultadoCli.js +57 -0
  122. package/dist/saidaCli.d.ts +35 -0
  123. package/dist/saidaCli.js +118 -0
  124. package/dist/sistemasInterativos/acceptanceEvidence.d.ts +22 -0
  125. package/dist/sistemasInterativos/acceptanceEvidence.js +345 -0
  126. package/dist/sistemasInterativos/engineObservation.d.ts +12 -0
  127. package/dist/sistemasInterativos/engineObservation.js +438 -0
  128. package/dist/sistemasInterativos/jobOrchestration.d.ts +2 -0
  129. package/dist/sistemasInterativos/jobOrchestration.js +204 -0
  130. package/dist/sistemasInterativos/operationPrimitives.d.ts +21 -0
  131. package/dist/sistemasInterativos/operationPrimitives.js +194 -0
  132. package/dist/sistemasInterativos/operations.d.ts +4 -39
  133. package/dist/sistemasInterativos/operations.js +5 -1164
  134. package/dist/skillCommand.d.ts +5 -0
  135. package/dist/skillCommand.js +88 -0
  136. package/dist/sync/index.js +35 -35
  137. package/docs/README.md +11 -7
  138. package/docs/ai-integration.md +18 -11
  139. package/docs/ai-onboarding.md +81 -62
  140. package/docs/ai-workflow.md +10 -4
  141. package/docs/auth.md +26 -26
  142. package/docs/cli.md +197 -79
  143. package/docs/commands.md +30 -6
  144. package/docs/database.md +15 -15
  145. package/docs/deploy.md +54 -41
  146. package/docs/documentation.md +11 -10
  147. package/docs/drift-cache.md +108 -0
  148. package/docs/env.md +16 -16
  149. package/docs/frontend.md +41 -41
  150. package/docs/getting-started.md +82 -57
  151. package/docs/i18n.md +15 -15
  152. package/docs/repositories.md +60 -43
  153. package/docs/rollback.md +38 -31
  154. package/docs/security.md +54 -32
  155. package/docs/sistemas-interativos.md +27 -27
  156. package/docs/support.md +8 -8
  157. package/docs/testing.md +123 -17
  158. package/docs/vocabulary.md +29 -29
  159. package/exemplos/agendamento.sema +1 -1
  160. package/exemplos/assinatura.sema +1 -1
  161. package/exemplos/auditoria.sema +1 -1
  162. package/exemplos/autenticacao.sema +1 -1
  163. package/exemplos/author_obra_comum.sema +1 -1
  164. package/exemplos/author_tema_sensivel.sema +1 -1
  165. package/exemplos/automacao.sema +1 -1
  166. package/exemplos/cadastro_usuario.sema +1 -1
  167. package/exemplos/calculadora.sema +1 -1
  168. package/exemplos/crud_simples.sema +1 -1
  169. package/exemplos/estoque.sema +1 -1
  170. package/exemplos/exportacao.sema +1 -1
  171. package/exemplos/fila.sema +1 -1
  172. package/exemplos/integracao_externa.sema +1 -1
  173. package/exemplos/multi_tenant.sema +1 -1
  174. package/exemplos/notificacao.sema +1 -1
  175. package/exemplos/operacao_estrategia.sema +132 -132
  176. package/exemplos/operacao_estrategia_discovery.sema +220 -220
  177. package/exemplos/operacao_estrategia_fluxo.sema +114 -114
  178. package/exemplos/operacao_estrategia_gates.sema +106 -106
  179. package/exemplos/operacao_estrategia_quarentena.sema +133 -133
  180. package/exemplos/operacao_estrategia_rollout.sema +124 -124
  181. package/exemplos/pagamento.sema +1 -1
  182. package/exemplos/pagamento_dominio.sema +1 -1
  183. package/exemplos/pedido.sema +1 -1
  184. package/exemplos/permissao.sema +1 -1
  185. package/exemplos/persistencia_vendor_first.sema +1 -1
  186. package/exemplos/profile_conversas.sema +165 -165
  187. package/exemplos/profile_game.sema +1 -1
  188. package/exemplos/profile_legal.sema +1 -1
  189. package/exemplos/profile_ops.sema +1 -1
  190. package/exemplos/profile_research.sema +1 -1
  191. package/exemplos/profile_software.sema +1 -1
  192. package/exemplos/profile_workflow_n8n.sema +1 -1
  193. package/exemplos/relatorio.sema +1 -1
  194. package/exemplos/replica_analitica_erp.sema +1 -1
  195. package/exemplos/testes_embutidos.sema +1 -1
  196. package/exemplos/tratamento_erro.sema +1 -1
  197. package/exemplos/upload_arquivo.sema +1 -1
  198. package/exemplos/webhook.sema +1 -1
  199. package/node_modules/@sema/gerador-cpp/dist/index.js +176 -176
  200. package/node_modules/@sema/gerador-css/dist/index.part01.js +10 -10
  201. package/node_modules/@sema/gerador-css/dist/index.part02.js +460 -460
  202. package/node_modules/@sema/gerador-dotnet/dist/index.js +169 -169
  203. package/node_modules/@sema/gerador-html/dist/index.js +17 -17
  204. package/node_modules/@sema/gerador-python/dist/index.part02.js +3 -3
  205. package/node_modules/@sema/gerador-typescript/dist/index.part02.js +11 -11
  206. package/node_modules/@sema/nucleo/dist/diagnosticos/melhorador.js +42 -42
  207. package/node_modules/@sema/nucleo/dist/semantico/analisador.d.ts +1 -0
  208. package/node_modules/@sema/nucleo/dist/semantico/analisador.js +1 -0
  209. package/package.json +7 -2
  210. package/scripts/postinstall.mjs +148 -0
  211. package/skills/sema/SKILL.md +199 -0
  212. package/skills/sema/agents/openai.yaml +4 -0
  213. package/node_modules/@sema/gerador-cpp/dist/index.js.map +0 -1
  214. package/node_modules/@sema/gerador-css/dist/index.js.map +0 -1
  215. package/node_modules/@sema/gerador-css/dist/index.part01.js.map +0 -1
  216. package/node_modules/@sema/gerador-css/dist/index.part02.js.map +0 -1
  217. package/node_modules/@sema/gerador-dart/dist/index.js.map +0 -1
  218. package/node_modules/@sema/gerador-dotnet/dist/index.js.map +0 -1
  219. package/node_modules/@sema/gerador-html/dist/index.js.map +0 -1
  220. package/node_modules/@sema/gerador-javascript/dist/index.js.map +0 -1
  221. package/node_modules/@sema/gerador-lua/dist/index.js.map +0 -1
  222. package/node_modules/@sema/gerador-php/dist/index.js.map +0 -1
  223. package/node_modules/@sema/gerador-python/dist/index.js.map +0 -1
  224. package/node_modules/@sema/gerador-python/dist/index.part01.js.map +0 -1
  225. package/node_modules/@sema/gerador-python/dist/index.part02.js.map +0 -1
  226. package/node_modules/@sema/gerador-typescript/dist/index.js.map +0 -1
  227. package/node_modules/@sema/gerador-typescript/dist/index.part01.js.map +0 -1
  228. package/node_modules/@sema/gerador-typescript/dist/index.part02.js.map +0 -1
  229. package/node_modules/@sema/gerador-typescript/dist/index.part03.js.map +0 -1
  230. package/node_modules/@sema/nucleo/dist/ast/tipos.js.map +0 -1
  231. package/node_modules/@sema/nucleo/dist/diagnosticos/index.js.map +0 -1
  232. package/node_modules/@sema/nucleo/dist/diagnosticos/melhorador.js.map +0 -1
  233. package/node_modules/@sema/nucleo/dist/diagnosticos/snippets.js.map +0 -1
  234. package/node_modules/@sema/nucleo/dist/formatador/index.js.map +0 -1
  235. package/node_modules/@sema/nucleo/dist/formatador/index.part01.js.map +0 -1
  236. package/node_modules/@sema/nucleo/dist/formatador/index.part02.js.map +0 -1
  237. package/node_modules/@sema/nucleo/dist/index.js.map +0 -1
  238. package/node_modules/@sema/nucleo/dist/ir/conversor.js.map +0 -1
  239. package/node_modules/@sema/nucleo/dist/ir/conversor.part01.js.map +0 -1
  240. package/node_modules/@sema/nucleo/dist/ir/conversor.part02.js.map +0 -1
  241. package/node_modules/@sema/nucleo/dist/ir/conversor.part03.js.map +0 -1
  242. package/node_modules/@sema/nucleo/dist/ir/modelos.js.map +0 -1
  243. package/node_modules/@sema/nucleo/dist/lexer/lexer.js.map +0 -1
  244. package/node_modules/@sema/nucleo/dist/lexer/tokens.js.map +0 -1
  245. package/node_modules/@sema/nucleo/dist/parser/parser.declaracoes.js.map +0 -1
  246. package/node_modules/@sema/nucleo/dist/parser/parser.js.map +0 -1
  247. package/node_modules/@sema/nucleo/dist/parser/parser.modulo.js.map +0 -1
  248. package/node_modules/@sema/nucleo/dist/parser/parser.part01.js.map +0 -1
  249. package/node_modules/@sema/nucleo/dist/parser/parser.part02.js.map +0 -1
  250. package/node_modules/@sema/nucleo/dist/parser/parser.part03.js.map +0 -1
  251. package/node_modules/@sema/nucleo/dist/persistencia/contratos.js.map +0 -1
  252. package/node_modules/@sema/nucleo/dist/semantico/analisador.js.map +0 -1
  253. package/node_modules/@sema/nucleo/dist/semantico/analisador.part01.js.map +0 -1
  254. package/node_modules/@sema/nucleo/dist/semantico/analisador.part02.js.map +0 -1
  255. package/node_modules/@sema/nucleo/dist/semantico/analisador.part03.js.map +0 -1
  256. package/node_modules/@sema/nucleo/dist/semantico/analisador.part04.js.map +0 -1
  257. package/node_modules/@sema/nucleo/dist/semantico/analisador.part05.js.map +0 -1
  258. package/node_modules/@sema/nucleo/dist/semantico/analisador.part06.js.map +0 -1
  259. package/node_modules/@sema/nucleo/dist/semantico/analisador.part07.js.map +0 -1
  260. package/node_modules/@sema/nucleo/dist/semantico/analisador.part08.js.map +0 -1
  261. package/node_modules/@sema/nucleo/dist/semantico/estruturas.js.map +0 -1
  262. package/node_modules/@sema/nucleo/dist/semantico/estruturas.part01.js.map +0 -1
  263. package/node_modules/@sema/nucleo/dist/semantico/estruturas.part02.js.map +0 -1
  264. package/node_modules/@sema/nucleo/dist/semantico/orcamentoSemantico.js.map +0 -1
  265. package/node_modules/@sema/nucleo/dist/semantico/seguranca.js.map +0 -1
  266. package/node_modules/@sema/nucleo/dist/util/arquivos.js.map +0 -1
  267. package/node_modules/@sema/padroes/dist/index.js.map +0 -1
@@ -0,0 +1,612 @@
1
+ // SEMA-GOVERNED: sema.produto.governanca_ia.drift
2
+ // Descricao: extrai e resolve candidatos exatos de dependencias locais sem caminhada de filesystem.
3
+ import path from "node:path";
4
+ import ts from "typescript";
5
+ const EXTENSOES_DEPENDENCIA_CODIGO = [
6
+ ".ts", ".tsx", ".mts", ".cts", ".js", ".jsx", ".mjs", ".cjs", ".py", ".dart", ".lua", ".cs", ".java",
7
+ ".go", ".rs", ".php", ".cpp", ".cc", ".cxx", ".hpp", ".h",
8
+ ".sql", ".psql", ".ddl", ".prisma", ".html", ".htm", ".css",
9
+ ];
10
+ const EXTENSOES_TYPESCRIPT_DEPENDENCIA = [
11
+ ".ts", ".tsx", ".mts", ".cts", ".js", ".jsx", ".mjs", ".cjs", ".html", ".htm", ".css",
12
+ ];
13
+ const PREFIXO_REFERENCIA_PYTHON = "python:";
14
+ const PREFIXO_REFERENCIA_RUST_MODULO = "rust-mod:";
15
+ const PREFIXO_REFERENCIA_RUST_CAMINHO = "rust-path:";
16
+ const REFERENCIA_ALIAS_CONFIG_INCOMPLETA = "alias-config:nao_resolvida";
17
+ function chaveCaminho(caminho) {
18
+ const absoluto = path.normalize(path.resolve(caminho));
19
+ return process.platform === "win32" ? absoluto.toLowerCase() : absoluto;
20
+ }
21
+ function caminhoEstaDentro(raiz, alvo) {
22
+ const relativo = path.relative(path.resolve(raiz), path.resolve(alvo));
23
+ return relativo === "" || (relativo !== ".."
24
+ && !relativo.startsWith(`..${path.sep}`)
25
+ && !path.isAbsolute(relativo));
26
+ }
27
+ function encontrarConfiguracaoTypeScript(contexto, arquivoOrigem) {
28
+ const baseProjeto = path.resolve(contexto.baseProjeto);
29
+ let diretorio = path.dirname(path.resolve(arquivoOrigem));
30
+ if (!caminhoEstaDentro(baseProjeto, diretorio)) {
31
+ return undefined;
32
+ }
33
+ for (;;) {
34
+ for (const nome of ["tsconfig.json", "jsconfig.json"]) {
35
+ const candidato = path.join(diretorio, nome);
36
+ if (ts.sys.fileExists(candidato)) {
37
+ return candidato;
38
+ }
39
+ }
40
+ if (chaveCaminho(diretorio) === chaveCaminho(baseProjeto)) {
41
+ return undefined;
42
+ }
43
+ const pai = path.dirname(diretorio);
44
+ if (pai === diretorio || !caminhoEstaDentro(baseProjeto, pai)) {
45
+ return undefined;
46
+ }
47
+ diretorio = pai;
48
+ }
49
+ }
50
+ function resolverExtendsTypeScript(configuracao, valor) {
51
+ if (!valor.startsWith(".") && !path.isAbsolute(valor)) {
52
+ return undefined;
53
+ }
54
+ const base = path.resolve(path.dirname(configuracao), valor);
55
+ for (const candidato of [base, `${base}.json`, path.join(base, "tsconfig.json")]) {
56
+ if (ts.sys.fileExists(candidato)) {
57
+ return candidato;
58
+ }
59
+ }
60
+ return undefined;
61
+ }
62
+ function carregarConfiguracaoAliasesTypeScript(contexto, arquivoOrigem) {
63
+ const configuracaoInicial = encontrarConfiguracaoTypeScript(contexto, arquivoOrigem);
64
+ if (!configuracaoInicial) {
65
+ return { regras: [], incompleta: false };
66
+ }
67
+ const visitadas = new Set();
68
+ const carregar = (configuracao) => {
69
+ const chave = chaveCaminho(configuracao);
70
+ if (visitadas.has(chave) || visitadas.size >= 8) {
71
+ return { regras: [], incompleta: true };
72
+ }
73
+ visitadas.add(chave);
74
+ const leitura = ts.readConfigFile(configuracao, ts.sys.readFile);
75
+ if (leitura.error || !leitura.config || typeof leitura.config !== "object") {
76
+ return { regras: [], incompleta: true };
77
+ }
78
+ const config = leitura.config;
79
+ const opcoes = config.compilerOptions ?? {};
80
+ const base = path.resolve(path.dirname(configuracao), opcoes.baseUrl ?? ".");
81
+ const regrasAtuais = Object.entries(opcoes.paths ?? {})
82
+ .map(([padrao, alvos]) => {
83
+ if (!Array.isArray(alvos)) {
84
+ return undefined;
85
+ }
86
+ const alvosValidos = alvos.filter((alvo) => typeof alvo === "string" && alvo.length > 0);
87
+ return alvosValidos.length > 0 ? { padrao, alvos: alvosValidos, base } : undefined;
88
+ })
89
+ .filter((regra) => Boolean(regra));
90
+ let incompleta = false;
91
+ const herdadas = [];
92
+ const extensoes = Array.isArray(config.extends)
93
+ ? config.extends
94
+ : config.extends ? [config.extends] : [];
95
+ for (const extensao of extensoes) {
96
+ const caminhoBase = resolverExtendsTypeScript(configuracao, extensao);
97
+ if (!caminhoBase || !caminhoEstaDentro(contexto.baseProjeto, caminhoBase)) {
98
+ incompleta = true;
99
+ continue;
100
+ }
101
+ const resultadoBase = carregar(caminhoBase);
102
+ herdadas.push(...resultadoBase.regras);
103
+ incompleta = incompleta || resultadoBase.incompleta;
104
+ }
105
+ const padroesAtuais = new Set(regrasAtuais.map((regra) => regra.padrao));
106
+ return {
107
+ regras: [...regrasAtuais, ...herdadas.filter((regra) => !padroesAtuais.has(regra.padrao))],
108
+ incompleta,
109
+ };
110
+ };
111
+ return carregar(configuracaoInicial);
112
+ }
113
+ function capturarAliasTypeScript(padrao, referencia) {
114
+ const indiceCoringa = padrao.indexOf("*");
115
+ if (indiceCoringa < 0) {
116
+ return padrao === referencia ? "" : undefined;
117
+ }
118
+ const prefixo = padrao.slice(0, indiceCoringa);
119
+ const sufixo = padrao.slice(indiceCoringa + 1);
120
+ if (!referencia.startsWith(prefixo) || !referencia.endsWith(sufixo)) {
121
+ return undefined;
122
+ }
123
+ return referencia.slice(prefixo.length, referencia.length - sufixo.length);
124
+ }
125
+ function referenciaCorrespondeAliasTypeScript(referencia, configuracao) {
126
+ return configuracao?.regras.some((regra) => capturarAliasTypeScript(regra.padrao, referencia) !== undefined) ?? false;
127
+ }
128
+ function mascararIntervalo(codigo, saida, inicio, fim) {
129
+ for (let indice = inicio; indice < fim; indice += 1) {
130
+ if (codigo[indice] !== "\n" && codigo[indice] !== "\r") {
131
+ saida[indice] = " ";
132
+ }
133
+ }
134
+ }
135
+ function avancarStringEmExpressao(codigo, inicio) {
136
+ const delimitador = codigo[inicio];
137
+ let indice = inicio + 1;
138
+ while (indice < codigo.length) {
139
+ if (codigo[indice] === "\\") {
140
+ indice += 2;
141
+ continue;
142
+ }
143
+ if (codigo[indice] === delimitador) {
144
+ return indice + 1;
145
+ }
146
+ indice += 1;
147
+ }
148
+ return codigo.length;
149
+ }
150
+ function avancarRegexEmExpressao(codigo, inicio) {
151
+ let indice = inicio + 1;
152
+ let classe = false;
153
+ while (indice < codigo.length) {
154
+ if (codigo[indice] === "\\") {
155
+ indice += 2;
156
+ continue;
157
+ }
158
+ if (codigo[indice] === "[") {
159
+ classe = true;
160
+ }
161
+ else if (codigo[indice] === "]") {
162
+ classe = false;
163
+ }
164
+ else if (codigo[indice] === "/" && !classe) {
165
+ indice += 1;
166
+ while (/[A-Za-z]/u.test(codigo[indice] ?? "")) {
167
+ indice += 1;
168
+ }
169
+ return indice;
170
+ }
171
+ indice += 1;
172
+ }
173
+ return codigo.length;
174
+ }
175
+ function barraIniciaRegex(codigo, indice) {
176
+ let anterior = indice - 1;
177
+ while (anterior >= 0 && /\s/u.test(codigo[anterior] ?? "")) {
178
+ anterior -= 1;
179
+ }
180
+ return anterior < 0 || /[([{=,:;!?&|+\-*%^~<>]/u.test(codigo[anterior] ?? "");
181
+ }
182
+ function avancarExpressaoTemplate(codigo, inicio, profundidade) {
183
+ let indice = inicio;
184
+ let nivelChaves = 1;
185
+ while (indice < codigo.length) {
186
+ const atual = codigo[indice];
187
+ const proximo = codigo[indice + 1];
188
+ if (atual === "'" || atual === '"') {
189
+ indice = avancarStringEmExpressao(codigo, indice);
190
+ continue;
191
+ }
192
+ if (atual === "`") {
193
+ indice = avancarTemplateLiteral(codigo, indice, profundidade + 1).fim;
194
+ continue;
195
+ }
196
+ if (atual === "/" && proximo === "/") {
197
+ const fimLinha = codigo.indexOf("\n", indice + 2);
198
+ indice = fimLinha < 0 ? codigo.length : fimLinha;
199
+ continue;
200
+ }
201
+ if (atual === "/" && proximo === "*") {
202
+ const fimComentario = codigo.indexOf("*/", indice + 2);
203
+ indice = fimComentario < 0 ? codigo.length : fimComentario + 2;
204
+ continue;
205
+ }
206
+ if (atual === "/" && barraIniciaRegex(codigo, indice)) {
207
+ indice = avancarRegexEmExpressao(codigo, indice);
208
+ continue;
209
+ }
210
+ if (atual === "{") {
211
+ nivelChaves += 1;
212
+ }
213
+ else if (atual === "}") {
214
+ nivelChaves -= 1;
215
+ if (nivelChaves === 0) {
216
+ return indice + 1;
217
+ }
218
+ }
219
+ indice += 1;
220
+ }
221
+ return codigo.length;
222
+ }
223
+ function avancarTemplateLiteral(codigo, inicio, profundidade = 0) {
224
+ if (profundidade > 64) {
225
+ return { fim: codigo.length, fechado: false, interpolado: true };
226
+ }
227
+ let indice = inicio + 1;
228
+ let interpolado = false;
229
+ while (indice < codigo.length) {
230
+ if (codigo[indice] === "\\") {
231
+ indice += 2;
232
+ continue;
233
+ }
234
+ if (codigo[indice] === "`") {
235
+ return { fim: indice + 1, fechado: true, interpolado };
236
+ }
237
+ if (codigo[indice] === "$" && codigo[indice + 1] === "{") {
238
+ interpolado = true;
239
+ indice = avancarExpressaoTemplate(codigo, indice + 2, profundidade);
240
+ continue;
241
+ }
242
+ indice += 1;
243
+ }
244
+ return { fim: codigo.length, fechado: false, interpolado };
245
+ }
246
+ function literalEhReferenciaEstatica(codigo, inicio, fim, templateLiteral) {
247
+ const conteudo = codigo.slice(inicio + 1, Math.max(inicio + 1, fim - 1));
248
+ if (templateLiteral && conteudo.includes("${")) {
249
+ return false;
250
+ }
251
+ const prefixo = codigo.slice(Math.max(0, inicio - 4_096), inicio);
252
+ const inicioLinha = prefixo.lastIndexOf("\n") + 1;
253
+ const prefixoLinha = prefixo.slice(inicioLinha);
254
+ return /\bstyleUrls\s*:\s*\[[^\]]*$/u.test(prefixo)
255
+ || /\b(?:import|require)\s*\(\s*$/u.test(prefixoLinha)
256
+ || /^\s*import\s*$/u.test(prefixoLinha)
257
+ || /\b(?:import|export)\b[^;]*\bfrom\s*$/u.test(prefixo)
258
+ || /\b(?:templateUrl|styleUrl)\s*:\s*$/u.test(prefixoLinha)
259
+ || /^\s*@import\s+(?:url\(\s*)?$/u.test(prefixoLinha)
260
+ || /^\s*#include\s*$/u.test(prefixoLinha)
261
+ || /\b(?:require|include)(?:_once)?\s*\(?\s*$/u.test(prefixoLinha)
262
+ || /\b(?:include|include_str|include_bytes)!\s*\(\s*$/u.test(prefixoLinha)
263
+ || /^\s*#\[\s*path\s*=\s*$/u.test(prefixoLinha);
264
+ }
265
+ /** Remove comentarios/docstrings sem alterar offsets ou caminhos em imports reais. */
266
+ function removerComentariosDependencias(codigo) {
267
+ const saida = [...codigo];
268
+ let indice = 0;
269
+ while (indice < codigo.length) {
270
+ const atual = codigo[indice];
271
+ const proximo = codigo[indice + 1];
272
+ if ((atual === "'" || atual === '"') && codigo.slice(indice, indice + 3) === atual.repeat(3)) {
273
+ const delimitador = atual.repeat(3);
274
+ const fimEncontrado = codigo.indexOf(delimitador, indice + 3);
275
+ const fim = fimEncontrado < 0 ? codigo.length : fimEncontrado + 3;
276
+ mascararIntervalo(codigo, saida, indice, fim);
277
+ indice = fim;
278
+ continue;
279
+ }
280
+ if (atual === "`") {
281
+ const inicio = indice;
282
+ const resultado = avancarTemplateLiteral(codigo, inicio);
283
+ indice = resultado.fim;
284
+ if (!resultado.fechado
285
+ || resultado.interpolado
286
+ || !literalEhReferenciaEstatica(codigo, inicio, indice, true)) {
287
+ mascararIntervalo(codigo, saida, inicio, indice);
288
+ }
289
+ continue;
290
+ }
291
+ if (atual === "'" || atual === '"') {
292
+ const inicio = indice;
293
+ const delimitador = atual;
294
+ let fechado = false;
295
+ indice += 1;
296
+ while (indice < codigo.length) {
297
+ if (codigo[indice] === "\\") {
298
+ indice += 2;
299
+ continue;
300
+ }
301
+ if (codigo[indice] === delimitador) {
302
+ indice += 1;
303
+ fechado = true;
304
+ break;
305
+ }
306
+ indice += 1;
307
+ }
308
+ if (!fechado || !literalEhReferenciaEstatica(codigo, inicio, indice, false)) {
309
+ mascararIntervalo(codigo, saida, inicio, indice);
310
+ }
311
+ continue;
312
+ }
313
+ if (atual === "/" && proximo === "/") {
314
+ const fimLinha = codigo.indexOf("\n", indice + 2);
315
+ const fim = fimLinha < 0 ? codigo.length : fimLinha;
316
+ mascararIntervalo(codigo, saida, indice, fim);
317
+ indice = fim;
318
+ continue;
319
+ }
320
+ if (atual === "/" && proximo === "*") {
321
+ const fimEncontrado = codigo.indexOf("*/", indice + 2);
322
+ const fim = fimEncontrado < 0 ? codigo.length : fimEncontrado + 2;
323
+ mascararIntervalo(codigo, saida, indice, fim);
324
+ indice = fim;
325
+ continue;
326
+ }
327
+ if (atual === "#") {
328
+ const inicioLinha = codigo.lastIndexOf("\n", indice - 1) + 1;
329
+ const prefixoLinha = codigo.slice(inicioLinha, indice);
330
+ if (/^\s*$/u.test(prefixoLinha)
331
+ && (codigo.slice(indice).startsWith("#include") || codigo.slice(indice).startsWith("#[path"))) {
332
+ indice += 1;
333
+ continue;
334
+ }
335
+ const fimLinha = codigo.indexOf("\n", indice + 1);
336
+ const fim = fimLinha < 0 ? codigo.length : fimLinha;
337
+ mascararIntervalo(codigo, saida, indice, fim);
338
+ indice = fim;
339
+ continue;
340
+ }
341
+ indice += 1;
342
+ }
343
+ return saida.join("");
344
+ }
345
+ function referenciaTypescriptLocal(referencia, aliases) {
346
+ return referencia.startsWith(".")
347
+ || referencia.startsWith("@/")
348
+ || referenciaCorrespondeAliasTypeScript(referencia, aliases);
349
+ }
350
+ function adicionarImportacoesPython(codigo, referencias) {
351
+ const adicionarModulo = (modulo) => {
352
+ const normalizado = modulo.trim();
353
+ if (/^\.*[A-Za-z_][A-Za-z0-9_.]*$/u.test(normalizado)) {
354
+ referencias.add(`${PREFIXO_REFERENCIA_PYTHON}${normalizado}`);
355
+ }
356
+ };
357
+ for (const ocorrencia of codigo.matchAll(/^\s*import\s+([^\r\n;]+)$/gmu)) {
358
+ for (const item of (ocorrencia[1] ?? "").split(",")) {
359
+ adicionarModulo(item.trim().split(/\s+as\s+/iu)[0] ?? "");
360
+ }
361
+ }
362
+ for (const ocorrencia of codigo.matchAll(/^\s*from\s+(\.*[A-Za-z_][A-Za-z0-9_.]*|\.+)\s+import\s+([^\r\n;]+)$/gmu)) {
363
+ const modulo = ocorrencia[1] ?? "";
364
+ adicionarModulo(modulo);
365
+ const importados = (ocorrencia[2] ?? "").replace(/[()\\]/gu, "");
366
+ for (const item of importados.split(",")) {
367
+ const nome = item.trim().split(/\s+as\s+/iu)[0] ?? "";
368
+ if (nome && nome !== "*" && /^[A-Za-z_][A-Za-z0-9_]*$/u.test(nome)) {
369
+ adicionarModulo(`${modulo}${modulo.endsWith(".") ? "" : "."}${nome}`);
370
+ }
371
+ }
372
+ }
373
+ }
374
+ function adicionarReferenciasRust(codigo, referencias) {
375
+ const padraoModulo = /(?:^\s*#\[\s*path\s*=\s*["'`]([^"'`\r\n]+)["'`]\s*\]\s*(?:\r?\n\s*)?)?^\s*(?:(?:pub(?:\([^)]*\))?)\s+)?mod\s+([A-Za-z_][A-Za-z0-9_]*)\s*;/gmu;
376
+ for (const ocorrencia of codigo.matchAll(padraoModulo)) {
377
+ const caminhoExplicito = ocorrencia[1]?.trim();
378
+ const modulo = ocorrencia[2]?.trim();
379
+ if (caminhoExplicito) {
380
+ const seguro = !path.posix.isAbsolute(caminhoExplicito)
381
+ && !path.win32.isAbsolute(caminhoExplicito)
382
+ && !caminhoExplicito.includes(":");
383
+ referencias.add(`${PREFIXO_REFERENCIA_RUST_CAMINHO}${seguro ? caminhoExplicito : "nao_resolvida"}`);
384
+ }
385
+ else if (modulo) {
386
+ referencias.add(`${PREFIXO_REFERENCIA_RUST_MODULO}${modulo}`);
387
+ }
388
+ }
389
+ for (const ocorrencia of codigo.matchAll(/\b(?:include|include_str|include_bytes)!\s*\(\s*["'`]([^"'`\r\n]+)["'`]\s*\)/gu)) {
390
+ const referencia = ocorrencia[1]?.trim();
391
+ if (referencia && !referencia.includes(":")) {
392
+ referencias.add(referencia);
393
+ }
394
+ }
395
+ }
396
+ export function extrairReferenciasLocaisDrift(codigo, opcoes = {}) {
397
+ const referencias = new Set();
398
+ const codigoExecutavel = removerComentariosDependencias(codigo);
399
+ const aliases = opcoes.contexto && opcoes.arquivoOrigem
400
+ ? carregarConfiguracaoAliasesTypeScript(opcoes.contexto, opcoes.arquivoOrigem)
401
+ : undefined;
402
+ let encontrouReferenciaNaoRelativa = false;
403
+ const adicionarReferenciaTypescript = (referenciaBruta) => {
404
+ const referencia = referenciaBruta?.trim();
405
+ if (!referencia) {
406
+ return;
407
+ }
408
+ if (referenciaTypescriptLocal(referencia, aliases)) {
409
+ referencias.add(referencia);
410
+ }
411
+ else if (!referencia.startsWith(".") && aliases?.incompleta) {
412
+ encontrouReferenciaNaoRelativa = true;
413
+ }
414
+ };
415
+ const padroesTypescript = [
416
+ /^\s*(?:import|export)\s+(?:type\s+)?(?:[A-Za-z_$][\w$]*\s*,\s*)?\{[^}]*\}\s+from\s+["'`]([^"'`\r\n]+)["'`]/gmu,
417
+ /^\s*(?:import|export)\s+(?:type\s+)?(?:[^;"'`\r\n]*?\s+from\s+)?["'`]([^"'`\r\n]+)["'`]/gmu,
418
+ /\b(?:import|require)\s*\(\s*["'`]([^"'`\r\n]+)["'`]\s*\)/gu,
419
+ /\b(?:templateUrl|styleUrl)\s*:\s*["'`]([^"'`\r\n]+)["'`]/gu,
420
+ /^\s*@import\s+(?:url\(\s*)?["'`]([^"'`\r\n]+)["'`]/gmu,
421
+ ];
422
+ for (const padrao of padroesTypescript) {
423
+ for (const ocorrencia of codigoExecutavel.matchAll(padrao)) {
424
+ adicionarReferenciaTypescript(ocorrencia[1]);
425
+ }
426
+ }
427
+ for (const ocorrencia of codigoExecutavel.matchAll(/\bstyleUrls\s*:\s*\[([^\]]*)\]/gu)) {
428
+ for (const estilo of (ocorrencia[1] ?? "").matchAll(/["'`]([^"'`\r\n]+)["'`]/gu)) {
429
+ adicionarReferenciaTypescript(estilo[1]);
430
+ }
431
+ }
432
+ if (encontrouReferenciaNaoRelativa) {
433
+ referencias.add(REFERENCIA_ALIAS_CONFIG_INCOMPLETA);
434
+ }
435
+ for (const ocorrencia of codigoExecutavel.matchAll(/^\s*#include\s+["']([^"'\r\n]+)["']/gmu)) {
436
+ const referencia = ocorrencia[1]?.trim();
437
+ if (referencia && !referencia.includes(":")) {
438
+ referencias.add(referencia);
439
+ }
440
+ }
441
+ for (const ocorrencia of codigoExecutavel.matchAll(/\b(?:require|include)(?:_once)?\s*\(?\s*["']([^"'\r\n]+)["']/gu)) {
442
+ const referencia = ocorrencia[1]?.trim();
443
+ const extensao = path.posix.extname(referencia ?? "").toLowerCase();
444
+ if (referencia
445
+ && !referencia.includes(":")
446
+ && (referencia.startsWith(".") || EXTENSOES_DEPENDENCIA_CODIGO.includes(extensao))) {
447
+ referencias.add(referencia);
448
+ }
449
+ }
450
+ adicionarImportacoesPython(codigoExecutavel, referencias);
451
+ adicionarReferenciasRust(codigoExecutavel, referencias);
452
+ return [...referencias];
453
+ }
454
+ export function raizesCodigoLogicasDrift(contexto) {
455
+ const candidatas = contexto.diretoriosCodigo.length > 0
456
+ ? contexto.diretoriosCodigo
457
+ : [contexto.baseProjeto];
458
+ return [...new Map(candidatas
459
+ .map((raiz) => path.resolve(raiz))
460
+ .filter((raiz) => caminhoEstaDentro(contexto.baseProjeto, raiz))
461
+ .map((raiz) => [chaveCaminho(raiz), raiz])).values()];
462
+ }
463
+ function adicionarVariantesArquivo(candidatos, base, extensoesPermitidas) {
464
+ const extensao = path.extname(base).toLowerCase();
465
+ const extensaoConhecida = extensoesPermitidas.includes(extensao);
466
+ const adicionar = (caminho) => {
467
+ const absoluto = path.resolve(caminho);
468
+ const chave = chaveCaminho(absoluto);
469
+ if (!candidatos.has(chave)) {
470
+ candidatos.set(chave, absoluto);
471
+ }
472
+ };
473
+ const substituicoesNodeNext = {
474
+ ".js": [".ts", ".tsx", ".d.ts", ".js", ".jsx"],
475
+ ".jsx": [".tsx", ".jsx"],
476
+ ".mjs": [".mts", ".d.mts", ".mjs"],
477
+ ".cjs": [".cts", ".d.cts", ".cjs"],
478
+ };
479
+ const substituicoes = substituicoesNodeNext[extensao];
480
+ if (substituicoes) {
481
+ const semExtensao = base.slice(0, -extensao.length);
482
+ for (const alternativa of substituicoes) {
483
+ adicionar(`${semExtensao}${alternativa}`);
484
+ }
485
+ return;
486
+ }
487
+ adicionar(base);
488
+ if (!extensaoConhecida) {
489
+ for (const alternativa of extensoesPermitidas) {
490
+ adicionar(`${base}${alternativa}`);
491
+ adicionar(path.join(base, `index${alternativa}`));
492
+ }
493
+ }
494
+ }
495
+ function adicionarCandidatosAliasTypeScript(candidatos, contexto, arquivoOrigem, referencia) {
496
+ const configuracao = carregarConfiguracaoAliasesTypeScript(contexto, arquivoOrigem);
497
+ const regrasCorrespondentes = configuracao.regras
498
+ .map((regra) => ({ regra, captura: capturarAliasTypeScript(regra.padrao, referencia) }))
499
+ .filter((item) => item.captura !== undefined)
500
+ .sort((a, b) => {
501
+ const especificidadeA = a.regra.padrao.replace("*", "").length;
502
+ const especificidadeB = b.regra.padrao.replace("*", "").length;
503
+ return especificidadeB - especificidadeA;
504
+ });
505
+ const melhorPadrao = regrasCorrespondentes[0]?.regra.padrao;
506
+ if (!melhorPadrao) {
507
+ return false;
508
+ }
509
+ for (const { regra, captura } of regrasCorrespondentes.filter((item) => item.regra.padrao === melhorPadrao)) {
510
+ for (const alvo of regra.alvos) {
511
+ adicionarVariantesArquivo(candidatos, path.resolve(regra.base, alvo.replace("*", captura)), EXTENSOES_TYPESCRIPT_DEPENDENCIA);
512
+ }
513
+ }
514
+ return true;
515
+ }
516
+ function adicionarCandidatosModuloRust(candidatos, arquivoOrigem, modulo) {
517
+ const nomeArquivo = path.basename(arquivoOrigem, path.extname(arquivoOrigem));
518
+ const baseModulo = ["lib", "main", "mod"].includes(nomeArquivo)
519
+ ? path.dirname(arquivoOrigem)
520
+ : path.join(path.dirname(arquivoOrigem), nomeArquivo);
521
+ for (const candidato of [
522
+ path.join(baseModulo, `${modulo}.rs`),
523
+ path.join(baseModulo, modulo, "mod.rs"),
524
+ ]) {
525
+ candidatos.set(chaveCaminho(candidato), path.resolve(candidato));
526
+ }
527
+ }
528
+ function candidatosModuloPython(contexto, arquivoOrigem, moduloDeclarado) {
529
+ const candidatos = new Map();
530
+ const correspondencia = /^(\.*)(.*)$/u.exec(moduloDeclarado);
531
+ const prefixoRelativo = correspondencia?.[1] ?? "";
532
+ const modulo = correspondencia?.[2] ?? "";
533
+ const segmentos = modulo.split(".").filter(Boolean);
534
+ const bases = new Map();
535
+ const adicionarBase = (base, segmentosBase) => {
536
+ const caminhoModulo = path.resolve(base, ...segmentosBase);
537
+ bases.set(chaveCaminho(caminhoModulo), caminhoModulo);
538
+ };
539
+ if (prefixoRelativo.length > 0) {
540
+ let baseRelativa = path.dirname(arquivoOrigem);
541
+ for (let nivel = 1; nivel < prefixoRelativo.length; nivel += 1) {
542
+ baseRelativa = path.dirname(baseRelativa);
543
+ }
544
+ adicionarBase(baseRelativa, segmentos);
545
+ }
546
+ else {
547
+ const raizes = raizesCodigoLogicasDrift(contexto);
548
+ for (const base of [path.dirname(arquivoOrigem), contexto.baseProjeto, ...raizes]) {
549
+ adicionarBase(base, segmentos);
550
+ const nomeBase = path.basename(base).toLowerCase();
551
+ if (segmentos[0]?.toLowerCase() === nomeBase) {
552
+ adicionarBase(base, segmentos.slice(1));
553
+ }
554
+ }
555
+ }
556
+ for (const base of bases.values()) {
557
+ const arquivoModulo = `${base}.py`;
558
+ candidatos.set(chaveCaminho(arquivoModulo), arquivoModulo);
559
+ const inicializador = path.join(base, "__init__.py");
560
+ candidatos.set(chaveCaminho(inicializador), inicializador);
561
+ }
562
+ return [...candidatos.values()];
563
+ }
564
+ export function candidatosReferenciaLocalDrift(contexto, arquivoOrigem, referencia) {
565
+ if (referencia === REFERENCIA_ALIAS_CONFIG_INCOMPLETA) {
566
+ return [];
567
+ }
568
+ if (referencia.startsWith(PREFIXO_REFERENCIA_PYTHON)) {
569
+ if (path.extname(arquivoOrigem).toLowerCase() !== ".py") {
570
+ return [];
571
+ }
572
+ return candidatosModuloPython(contexto, arquivoOrigem, referencia.slice(PREFIXO_REFERENCIA_PYTHON.length));
573
+ }
574
+ if (referencia.startsWith(PREFIXO_REFERENCIA_RUST_MODULO)) {
575
+ if (path.extname(arquivoOrigem).toLowerCase() !== ".rs") {
576
+ return [];
577
+ }
578
+ const candidatos = new Map();
579
+ adicionarCandidatosModuloRust(candidatos, arquivoOrigem, referencia.slice(PREFIXO_REFERENCIA_RUST_MODULO.length));
580
+ return [...candidatos.values()];
581
+ }
582
+ if (referencia.startsWith(PREFIXO_REFERENCIA_RUST_CAMINHO)) {
583
+ if (path.extname(arquivoOrigem).toLowerCase() !== ".rs") {
584
+ return [];
585
+ }
586
+ const declarado = referencia.slice(PREFIXO_REFERENCIA_RUST_CAMINHO.length);
587
+ if (path.isAbsolute(declarado) || path.win32.isAbsolute(declarado) || declarado.includes(":")) {
588
+ return [];
589
+ }
590
+ return [path.resolve(path.dirname(arquivoOrigem), declarado)];
591
+ }
592
+ const candidatos = new Map();
593
+ if (adicionarCandidatosAliasTypeScript(candidatos, contexto, arquivoOrigem, referencia)) {
594
+ return [...candidatos.values()];
595
+ }
596
+ if (referencia.startsWith("@/")) {
597
+ const relativoAlias = referencia.slice(2);
598
+ const raizes = raizesCodigoLogicasDrift(contexto).sort((a, b) => {
599
+ const aContemOrigem = caminhoEstaDentro(a, arquivoOrigem) ? 1 : 0;
600
+ const bContemOrigem = caminhoEstaDentro(b, arquivoOrigem) ? 1 : 0;
601
+ return bContemOrigem - aContemOrigem || b.length - a.length || a.localeCompare(b, "pt-BR");
602
+ });
603
+ for (const raiz of raizes) {
604
+ adicionarVariantesArquivo(candidatos, path.resolve(raiz, relativoAlias), EXTENSOES_TYPESCRIPT_DEPENDENCIA);
605
+ }
606
+ }
607
+ else {
608
+ adicionarVariantesArquivo(candidatos, path.resolve(path.dirname(arquivoOrigem), referencia), EXTENSOES_DEPENDENCIA_CODIGO);
609
+ }
610
+ return [...candidatos.values()];
611
+ }
612
+ //# sourceMappingURL=driftEscopoReferencias.js.map
@@ -4,6 +4,7 @@ export declare const LIMITE_AVISO_LINHAS_CONTRATO_SEMA = 300;
4
4
  export declare const LIMITE_BLOQUEIO_LINHAS_CONTRATO_SEMA = 500;
5
5
  export declare const LIMITE_AVISO_LINHAS_ORCAMENTO_SEMANTICO = 1000;
6
6
  export declare const LIMITE_BLOQUEIO_LINHAS_ORCAMENTO_SEMANTICO = 2000;
7
+ export declare function workspaceExigeCabecalhoCodigoGovernado(baseProjeto: string, modoEstrito: boolean): Promise<boolean>;
7
8
  export type TipoArquivoOrcamento = "contrato" | "codigo" | "documentacao" | "gerado" | "migracao_historica";
8
9
  export type SeveridadeOrcamentoSemantico = "ok" | "aviso" | "erro";
9
10
  export type TipoDiagnosticoOrcamento = "contrato_monolitico" | "codigo_monolitico" | "codigo_governado_sem_cabecalho";
@@ -35,6 +36,10 @@ export interface DiagnosticoOrcamentoArquivo {
35
36
  limite_aviso_linhas: number;
36
37
  limite_bloqueio_linhas: number;
37
38
  }
39
+ export interface LeitorArquivosOrcamento {
40
+ contem(caminho: string): boolean;
41
+ lerTexto(caminho: string): Promise<string>;
42
+ }
38
43
  export interface LimitesOrcamentoSemantico {
39
44
  aviso: number;
40
45
  bloqueio: number;
@@ -76,4 +81,5 @@ export declare function emitirDiagnosticosArquivosOrcamento(opcoes: {
76
81
  arquivos: string[];
77
82
  baseProjeto?: string;
78
83
  exigirCabecalhoCodigoGovernado?: boolean;
84
+ leitorArquivos?: LeitorArquivosOrcamento;
79
85
  }): Promise<DiagnosticoOrcamentoArquivo[]>;
@@ -2,7 +2,7 @@
2
2
  // Módulo: sema.produto.orcamento_semantico
3
3
  // Contrato: contratos/sema/orcamento_semantico.sema
4
4
  // Descrição: centraliza os gates de linhas e cabeçalho Sema para drift, finalização e snapshots.
5
- import { readFile } from "node:fs/promises";
5
+ import { lstat, readFile } from "node:fs/promises";
6
6
  import path from "node:path";
7
7
  export const LIMITE_AVISO_LINHAS_CODIGO_GOVERNADO = 1000;
8
8
  export const LIMITE_BLOQUEIO_LINHAS_CODIGO_GOVERNADO = 2000;
@@ -10,6 +10,17 @@ export const LIMITE_AVISO_LINHAS_CONTRATO_SEMA = 300;
10
10
  export const LIMITE_BLOQUEIO_LINHAS_CONTRATO_SEMA = 500;
11
11
  export const LIMITE_AVISO_LINHAS_ORCAMENTO_SEMANTICO = LIMITE_AVISO_LINHAS_CODIGO_GOVERNADO;
12
12
  export const LIMITE_BLOQUEIO_LINHAS_ORCAMENTO_SEMANTICO = LIMITE_BLOQUEIO_LINHAS_CODIGO_GOVERNADO;
13
+ export async function workspaceExigeCabecalhoCodigoGovernado(baseProjeto, modoEstrito) {
14
+ if (!modoEstrito) {
15
+ return false;
16
+ }
17
+ try {
18
+ return (await lstat(path.resolve(baseProjeto, "AGENTS.md"))).isFile();
19
+ }
20
+ catch {
21
+ return false;
22
+ }
23
+ }
13
24
  const EXTENSOES_CODIGO_GOVERNAVEL = new Set([
14
25
  ".ts",
15
26
  ".tsx",
@@ -289,13 +300,19 @@ export async function emitirDiagnosticosArquivosOrcamento(opcoes) {
289
300
  const absoluto = path.isAbsolute(arquivoInformado)
290
301
  ? arquivoInformado
291
302
  : path.resolve(baseProjeto, arquivoInformado);
292
- const chave = path.resolve(absoluto);
303
+ const resolvido = path.resolve(absoluto);
304
+ const chave = process.platform === "win32" ? resolvido.toLowerCase() : resolvido;
293
305
  if (vistos.has(chave)) {
294
306
  continue;
295
307
  }
296
308
  vistos.add(chave);
309
+ if (opcoes.leitorArquivos && !opcoes.leitorArquivos.contem(absoluto)) {
310
+ continue;
311
+ }
297
312
  try {
298
- const conteudo = await readFile(absoluto, "utf8");
313
+ const conteudo = opcoes.leitorArquivos
314
+ ? await opcoes.leitorArquivos.lerTexto(absoluto)
315
+ : await readFile(absoluto, "utf8");
299
316
  const relativo = path.relative(baseProjeto, absoluto).replace(/\\/g, "/") || arquivoInformado.replace(/\\/g, "/");
300
317
  diagnosticos.push(...avaliarOrcamentoArquivo({
301
318
  arquivo: relativo,