@semacode/cli 2.3.1 → 3.5.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 (281) hide show
  1. package/README.md +265 -217
  2. package/dist/agentContextPack.js +14 -10
  3. package/dist/agentEntryPoints.d.ts +5 -0
  4. package/dist/agentEntryPoints.js +592 -568
  5. package/dist/angular-consumer-standalone.js +1 -1
  6. package/dist/bin.d.ts +6 -0
  7. package/dist/bin.js +130 -0
  8. package/dist/cliArgs.js +4 -4
  9. package/dist/cliControlError.d.ts +12 -0
  10. package/dist/cliControlError.js +47 -0
  11. package/dist/cliGrammar.d.ts +11 -0
  12. package/dist/cliGrammar.js +551 -0
  13. package/dist/cliHelp.d.ts +13 -0
  14. package/dist/cliHelp.js +19 -0
  15. package/dist/cliHelpTexto.d.ts +3 -0
  16. package/dist/cliHelpTexto.js +168 -0
  17. package/dist/cliRuntime.d.ts +2 -0
  18. package/dist/cliRuntime.js +31 -0
  19. package/dist/comandos.js +9 -22
  20. package/dist/contexto.js +5 -5
  21. package/dist/dev/index.d.ts +1 -0
  22. package/dist/dev/index.js +51 -9
  23. package/dist/discovery/catalog.js +3 -3
  24. package/dist/distribuicao/filesystemGlobal.d.ts +63 -0
  25. package/dist/distribuicao/filesystemGlobal.js +701 -0
  26. package/dist/distribuicao/index.d.ts +7 -0
  27. package/dist/distribuicao/index.js +227 -0
  28. package/dist/distribuicao/launcherGlobal.d.ts +53 -0
  29. package/dist/distribuicao/launcherGlobal.js +643 -0
  30. package/dist/distribuicao/launcherWindows.d.ts +28 -0
  31. package/dist/distribuicao/launcherWindows.js +326 -0
  32. package/dist/distribuicao/lockContextGlobal.d.ts +10 -0
  33. package/dist/distribuicao/lockContextGlobal.js +17 -0
  34. package/dist/distribuicao/lockGlobal.d.ts +6 -0
  35. package/dist/distribuicao/lockGlobal.js +520 -0
  36. package/dist/distribuicao/skillGlobal.d.ts +48 -0
  37. package/dist/distribuicao/skillGlobal.js +652 -0
  38. package/dist/distribuicao/skillIntentPolicy.d.ts +21 -0
  39. package/dist/distribuicao/skillIntentPolicy.js +115 -0
  40. package/dist/distribuicao/tipos.d.ts +50 -0
  41. package/dist/distribuicao/tipos.js +10 -0
  42. package/dist/distribuicao/versaoSemantica.d.ts +3 -0
  43. package/dist/distribuicao/versaoSemantica.js +62 -0
  44. package/dist/docs.part01.d.ts +4 -1
  45. package/dist/docs.part01.js +8 -0
  46. package/dist/docs.part02.js +9 -1
  47. package/dist/drift.part01.d.ts +33 -25
  48. package/dist/drift.part01.js +2 -1
  49. package/dist/drift.part04.d.ts +26 -5
  50. package/dist/drift.part04.js +123 -19
  51. package/dist/drift.part05.d.ts +2 -2
  52. package/dist/drift.part05.js +8 -6
  53. package/dist/drift.part06.d.ts +2 -2
  54. package/dist/drift.part06.js +113 -26
  55. package/dist/drift.part07.d.ts +11 -11
  56. package/dist/drift.part07.js +261 -265
  57. package/dist/drift.part08.d.ts +2 -2
  58. package/dist/drift.part08.js +35 -26
  59. package/dist/drift.part09.d.ts +2 -2
  60. package/dist/drift.part09.js +10 -3
  61. package/dist/drift.part11.js +261 -58
  62. package/dist/drift.part12.d.ts +1 -1
  63. package/dist/drift.part12.js +193 -21
  64. package/dist/drift.part13.d.ts +20 -39
  65. package/dist/drift.part13.js +601 -647
  66. package/dist/drift.part14.js +23 -7
  67. package/dist/driftCacheCas.d.ts +43 -0
  68. package/dist/driftCacheCas.js +351 -0
  69. package/dist/driftCacheFilesystem.d.ts +64 -0
  70. package/dist/driftCacheFilesystem.js +313 -0
  71. package/dist/driftCacheModes.d.ts +38 -0
  72. package/dist/driftCacheModes.js +147 -0
  73. package/dist/driftCacheStore.d.ts +80 -0
  74. package/dist/driftCacheStore.js +603 -0
  75. package/dist/driftCatalogo.d.ts +2 -28
  76. package/dist/driftCatalogo.js +143 -284
  77. package/dist/driftEscopo.d.ts +1 -3
  78. package/dist/driftEscopo.js +235 -151
  79. package/dist/driftEscopoReferencias.d.ts +5 -1
  80. package/dist/driftEscopoReferencias.js +375 -28
  81. package/dist/driftOrcamento.d.ts +0 -6
  82. package/dist/driftOrcamento.js +2 -1
  83. package/dist/execucoesExternas.js +19 -5
  84. package/dist/exemplosOficiais.d.ts +2 -1
  85. package/dist/exemplosOficiais.js +9 -3
  86. package/dist/geracaoCore.d.ts +1 -0
  87. package/dist/geracaoCore.js +6 -6
  88. package/dist/iaPrompts.d.ts +3 -3
  89. package/dist/iaPrompts.js +312 -313
  90. package/dist/importador.part01.d.ts +1 -1
  91. package/dist/importador.part06.d.ts +2 -0
  92. package/dist/importador.part06.js +87 -1
  93. package/dist/importador.part09.js +7 -1
  94. package/dist/index.d.ts +4 -1
  95. package/dist/index.js +6 -25
  96. package/dist/index.part01.d.ts +20 -28
  97. package/dist/index.part01.js +16 -237
  98. package/dist/index.part02.js +36 -22
  99. package/dist/index.part03.d.ts +24 -2
  100. package/dist/index.part03.js +83 -19
  101. package/dist/index.part04.d.ts +10 -2
  102. package/dist/index.part04.js +152 -123
  103. package/dist/index.part05.js +80 -78
  104. package/dist/index.part06.js +34 -17
  105. package/dist/index.part07.d.ts +8 -2
  106. package/dist/index.part07.js +153 -7
  107. package/dist/index.part08.d.ts +1 -1
  108. package/dist/index.part08.js +25 -30
  109. package/dist/initCommand.d.ts +1 -0
  110. package/dist/initCommand.js +20 -4
  111. package/dist/initTemplatesBase.js +6 -4
  112. package/dist/pipelineConteudo/command.d.ts +1 -0
  113. package/dist/pipelineConteudo/command.js +9 -2
  114. package/dist/pipelineConteudo/help.d.ts +2 -0
  115. package/dist/pipelineConteudo/help.js +33 -0
  116. package/dist/profileAuthorCommand.js +3 -7
  117. package/dist/profileCommand.js +3 -7
  118. package/dist/projetoCarregar.js +35 -17
  119. package/dist/projetoCatalogo.d.ts +1 -0
  120. package/dist/projetoCatalogo.js +64 -25
  121. package/dist/projetoConfig.js +2 -0
  122. package/dist/projetoLegado.js +18 -0
  123. package/dist/projetoOrigens.d.ts +2 -0
  124. package/dist/projetoOrigens.js +65 -9
  125. package/dist/projetoTipos.d.ts +1 -0
  126. package/dist/resultadoCli.d.ts +20 -0
  127. package/dist/resultadoCli.js +57 -0
  128. package/dist/saidaCli.d.ts +35 -0
  129. package/dist/saidaCli.js +118 -0
  130. package/dist/sistemasInterativos/acceptanceEvidence.d.ts +22 -0
  131. package/dist/sistemasInterativos/acceptanceEvidence.js +345 -0
  132. package/dist/sistemasInterativos/engineObservation.d.ts +12 -0
  133. package/dist/sistemasInterativos/engineObservation.js +438 -0
  134. package/dist/sistemasInterativos/jobOrchestration.d.ts +2 -0
  135. package/dist/sistemasInterativos/jobOrchestration.js +204 -0
  136. package/dist/sistemasInterativos/operationPrimitives.d.ts +21 -0
  137. package/dist/sistemasInterativos/operationPrimitives.js +194 -0
  138. package/dist/sistemasInterativos/operations.d.ts +4 -39
  139. package/dist/sistemasInterativos/operations.js +5 -1164
  140. package/dist/skillCommand.d.ts +5 -0
  141. package/dist/skillCommand.js +88 -0
  142. package/dist/tipos.d.ts +1 -1
  143. package/dist/typescript-http-modelos.d.ts +1 -1
  144. package/dist/typescript-http-rotas.d.ts +1 -0
  145. package/dist/typescript-http-rotas.js +93 -0
  146. package/dist/typescript-http.d.ts +1 -1
  147. package/dist/typescript-http.js +1 -1
  148. package/dist/verificacaoCache.d.ts +25 -0
  149. package/dist/verificacaoCache.js +80 -0
  150. package/docs/README.md +34 -30
  151. package/docs/ai-integration.md +25 -12
  152. package/docs/ai-onboarding.md +37 -18
  153. package/docs/ai-workflow.md +9 -7
  154. package/docs/cli.md +125 -7
  155. package/docs/commands.md +41 -20
  156. package/docs/deploy.md +21 -8
  157. package/docs/descoberta-capacidades.md +106 -106
  158. package/docs/documentation.md +49 -39
  159. package/docs/drift-cache.md +108 -0
  160. package/docs/getting-started.md +43 -18
  161. package/docs/pipeline-conteudo.md +246 -246
  162. package/docs/profiles.md +54 -54
  163. package/docs/repositories.md +19 -2
  164. package/docs/rollback.md +15 -8
  165. package/docs/security.md +25 -3
  166. package/docs/sistemas-interativos.md +379 -374
  167. package/docs/syntax.md +14 -0
  168. package/docs/testing.md +139 -40
  169. package/exemplos/express_crud.sema +139 -0
  170. package/exemplos/fastify_crud.sema +146 -0
  171. package/exemplos/pipeline-conteudo/README.md +44 -44
  172. package/exemplos/pipeline-conteudo/alvos.json +23 -23
  173. package/exemplos/pipeline-conteudo/definicao.json +136 -136
  174. package/exemplos/profile_simulation.sema +211 -211
  175. package/exemplos/sistemas-interativos/README.md +100 -100
  176. package/exemplos/sistemas-interativos/advanced/acceptance-context-evaluate-valid.json +5 -5
  177. package/exemplos/sistemas-interativos/advanced/acceptance-lock-valid.json +16 -16
  178. package/exemplos/sistemas-interativos/advanced/asset-provenance-valid.json +32 -32
  179. package/exemplos/sistemas-interativos/advanced/autonomy-repair-valid.json +93 -93
  180. package/exemplos/sistemas-interativos/advanced/control-run-definition-valid.json +78 -78
  181. package/exemplos/sistemas-interativos/advanced/control-run-valid.json +27 -27
  182. package/exemplos/sistemas-interativos/advanced/distributed-workers-valid.json +79 -79
  183. package/exemplos/sistemas-interativos/advanced/editor-state-valid.json +42 -42
  184. package/exemplos/sistemas-interativos/advanced/engine-snapshot-after-valid.json +32 -32
  185. package/exemplos/sistemas-interativos/advanced/engine-snapshot-before-valid.json +23 -23
  186. package/exemplos/sistemas-interativos/advanced/job-orchestration-valid.json +39 -39
  187. package/exemplos/sistemas-interativos/advanced/multimodal-evidence-valid.json +46 -46
  188. package/exemplos/sistemas-interativos/advanced/multiplayer-authority-valid.json +39 -39
  189. package/exemplos/sistemas-interativos/advanced/playtest-fuzz-valid.json +37 -37
  190. package/exemplos/sistemas-interativos/advanced/portability-valid.json +104 -104
  191. package/exemplos/sistemas-interativos/advanced/temporal-evidence-valid.json +27 -27
  192. package/exemplos/sistemas-interativos/advanced/temporal-valid.json +118 -118
  193. package/exemplos/sistemas-interativos/experience-ir-valid.json +459 -459
  194. package/exemplos/sistemas-interativos/game-2d.json +83 -83
  195. package/exemplos/sistemas-interativos/game-3d-human.json +81 -81
  196. package/exemplos/sistemas-interativos/game-pixel-16-bit.json +97 -97
  197. package/exemplos/sistemas-interativos/game-pixel-8-bit.json +94 -94
  198. package/exemplos/sistemas-interativos/game-xr-human.json +80 -80
  199. package/exemplos/sistemas-interativos/hybrid-2-5d.json +108 -108
  200. package/exemplos/sistemas-interativos/protocol-mutating-rollback-valid.json +75 -75
  201. package/exemplos/sistemas-interativos/protocol-read-only-valid.json +58 -58
  202. package/exemplos/sistemas-interativos/simulation-2d-controlled.json +97 -97
  203. package/exemplos/sistemas-interativos/simulation-3d-calibrated-autonomous.json +141 -141
  204. package/exemplos/sistemas-interativos/simulation-headless-autonomous-batch.json +112 -112
  205. package/exemplos/sistemas-interativos/simulation-pixel-16-bit.json +103 -103
  206. package/exemplos/sistemas-interativos/simulation-text-controlled.json +95 -95
  207. package/node_modules/@sema/gerador-cpp/package.json +1 -1
  208. package/node_modules/@sema/gerador-dotnet/package.json +1 -1
  209. package/node_modules/@sema/gerador-lua/dist/index.js +51 -51
  210. package/node_modules/@sema/gerador-php/dist/index.js +113 -113
  211. package/node_modules/@sema/nucleo/dist/ir/conversor.part01.js +37 -38
  212. package/node_modules/@sema/nucleo/dist/ir/modelos.d.ts +1 -0
  213. package/node_modules/@sema/nucleo/dist/semantico/analisador.d.ts +1 -0
  214. package/node_modules/@sema/nucleo/dist/semantico/analisador.js +1 -0
  215. package/node_modules/@sema/nucleo/dist/semantico/analisador.part01.d.ts +7 -0
  216. package/node_modules/@sema/nucleo/dist/semantico/analisador.part01.js +33 -10
  217. package/package.json +9 -4
  218. package/scripts/postinstall.mjs +148 -0
  219. package/skills/sema/SKILL.md +199 -0
  220. package/skills/sema/agents/openai.yaml +4 -0
  221. package/dist/driftCache.d.ts +0 -49
  222. package/dist/driftCache.js +0 -311
  223. package/dist/driftCacheIncremental.d.ts +0 -98
  224. package/dist/driftCacheIncremental.js +0 -596
  225. package/dist/driftCatalogoPersistente.d.ts +0 -8
  226. package/dist/driftCatalogoPersistente.js +0 -77
  227. package/node_modules/@sema/gerador-cpp/dist/index.js.map +0 -1
  228. package/node_modules/@sema/gerador-css/dist/index.js.map +0 -1
  229. package/node_modules/@sema/gerador-css/dist/index.part01.js.map +0 -1
  230. package/node_modules/@sema/gerador-css/dist/index.part02.js.map +0 -1
  231. package/node_modules/@sema/gerador-dart/dist/index.js.map +0 -1
  232. package/node_modules/@sema/gerador-dotnet/dist/index.js.map +0 -1
  233. package/node_modules/@sema/gerador-html/dist/index.js.map +0 -1
  234. package/node_modules/@sema/gerador-javascript/dist/index.js.map +0 -1
  235. package/node_modules/@sema/gerador-lua/dist/index.js.map +0 -1
  236. package/node_modules/@sema/gerador-php/dist/index.js.map +0 -1
  237. package/node_modules/@sema/gerador-python/dist/index.js.map +0 -1
  238. package/node_modules/@sema/gerador-python/dist/index.part01.js.map +0 -1
  239. package/node_modules/@sema/gerador-python/dist/index.part02.js.map +0 -1
  240. package/node_modules/@sema/gerador-typescript/dist/index.js.map +0 -1
  241. package/node_modules/@sema/gerador-typescript/dist/index.part01.js.map +0 -1
  242. package/node_modules/@sema/gerador-typescript/dist/index.part02.js.map +0 -1
  243. package/node_modules/@sema/gerador-typescript/dist/index.part03.js.map +0 -1
  244. package/node_modules/@sema/nucleo/dist/ast/tipos.js.map +0 -1
  245. package/node_modules/@sema/nucleo/dist/diagnosticos/index.js.map +0 -1
  246. package/node_modules/@sema/nucleo/dist/diagnosticos/melhorador.js.map +0 -1
  247. package/node_modules/@sema/nucleo/dist/diagnosticos/snippets.js.map +0 -1
  248. package/node_modules/@sema/nucleo/dist/formatador/index.js.map +0 -1
  249. package/node_modules/@sema/nucleo/dist/formatador/index.part01.js.map +0 -1
  250. package/node_modules/@sema/nucleo/dist/formatador/index.part02.js.map +0 -1
  251. package/node_modules/@sema/nucleo/dist/index.js.map +0 -1
  252. package/node_modules/@sema/nucleo/dist/ir/conversor.js.map +0 -1
  253. package/node_modules/@sema/nucleo/dist/ir/conversor.part01.js.map +0 -1
  254. package/node_modules/@sema/nucleo/dist/ir/conversor.part02.js.map +0 -1
  255. package/node_modules/@sema/nucleo/dist/ir/conversor.part03.js.map +0 -1
  256. package/node_modules/@sema/nucleo/dist/ir/modelos.js.map +0 -1
  257. package/node_modules/@sema/nucleo/dist/lexer/lexer.js.map +0 -1
  258. package/node_modules/@sema/nucleo/dist/lexer/tokens.js.map +0 -1
  259. package/node_modules/@sema/nucleo/dist/parser/parser.declaracoes.js.map +0 -1
  260. package/node_modules/@sema/nucleo/dist/parser/parser.js.map +0 -1
  261. package/node_modules/@sema/nucleo/dist/parser/parser.modulo.js.map +0 -1
  262. package/node_modules/@sema/nucleo/dist/parser/parser.part01.js.map +0 -1
  263. package/node_modules/@sema/nucleo/dist/parser/parser.part02.js.map +0 -1
  264. package/node_modules/@sema/nucleo/dist/parser/parser.part03.js.map +0 -1
  265. package/node_modules/@sema/nucleo/dist/persistencia/contratos.js.map +0 -1
  266. package/node_modules/@sema/nucleo/dist/semantico/analisador.js.map +0 -1
  267. package/node_modules/@sema/nucleo/dist/semantico/analisador.part01.js.map +0 -1
  268. package/node_modules/@sema/nucleo/dist/semantico/analisador.part02.js.map +0 -1
  269. package/node_modules/@sema/nucleo/dist/semantico/analisador.part03.js.map +0 -1
  270. package/node_modules/@sema/nucleo/dist/semantico/analisador.part04.js.map +0 -1
  271. package/node_modules/@sema/nucleo/dist/semantico/analisador.part05.js.map +0 -1
  272. package/node_modules/@sema/nucleo/dist/semantico/analisador.part06.js.map +0 -1
  273. package/node_modules/@sema/nucleo/dist/semantico/analisador.part07.js.map +0 -1
  274. package/node_modules/@sema/nucleo/dist/semantico/analisador.part08.js.map +0 -1
  275. package/node_modules/@sema/nucleo/dist/semantico/estruturas.js.map +0 -1
  276. package/node_modules/@sema/nucleo/dist/semantico/estruturas.part01.js.map +0 -1
  277. package/node_modules/@sema/nucleo/dist/semantico/estruturas.part02.js.map +0 -1
  278. package/node_modules/@sema/nucleo/dist/semantico/orcamentoSemantico.js.map +0 -1
  279. package/node_modules/@sema/nucleo/dist/semantico/seguranca.js.map +0 -1
  280. package/node_modules/@sema/nucleo/dist/util/arquivos.js.map +0 -1
  281. package/node_modules/@sema/padroes/dist/index.js.map +0 -1
@@ -0,0 +1,326 @@
1
+ // SEMA-GOVERNED: sema.produto.distribuicao_global
2
+ // Descrição: gera e valida .cmd, companion Unicode e wrapper PowerShell estável do launcher Windows.
3
+ import { createHash } from "node:crypto";
4
+ import path from "node:path";
5
+ import { versaoSemanticaValida } from "./versaoSemantica.js";
6
+ const MARCADOR = "SEMA-MANAGED-LAUNCHER v2";
7
+ const MARCADOR_COMPANION = "SEMA-MANAGED-LAUNCHER-COMPANION v1";
8
+ const PREFIXO_RECIBO = "SEMA-LAUNCHER-RECEIPT sha256:";
9
+ const PREFIXO_VERSAO = "SEMA-LAUNCHER-VERSION ";
10
+ const UTF8_BOM = Buffer.from([0xef, 0xbb, 0xbf]);
11
+ const NOME_WRAPPER = "sema-managed.ps1";
12
+ const NOME_LAUNCHER_POWERSHELL = "sema.ps1";
13
+ const NOME_ANCORA = "sema-launcher.receipt";
14
+ const MARCADOR_WRAPPER = "SEMA-MANAGED-LAUNCHER-WRAPPER v1";
15
+ const MARCADOR_ANCORA = "SEMA-MANAGED-LAUNCHER-ANCHOR v1";
16
+ const BOOTSTRAP_NODE = "(async()=>{const e=process.env,p=Buffer.from(e.SEMA_LAUNCHER_ENTRYPOINT_B64,'base64').toString('utf8'),a=JSON.parse(Buffer.from(e.SEMA_LAUNCHER_ARGS_B64,'base64').toString('utf8'));if(!Array.isArray(a)||a.some(v=>typeof(v)!=='string'))return Promise.reject();delete e.SEMA_LAUNCHER_ARGS_B64;delete e.SEMA_LAUNCHER_ENTRYPOINT_B64;process.argv=[process.execPath,p,...a];await import((await import('node:url')).pathToFileURL(p).href)})().catch(()=>{console.error('Sema launcher bootstrap failed.');process.exitCode=1})";
17
+ function sha256(valor) {
18
+ return createHash("sha256").update(valor).digest("hex");
19
+ }
20
+ function escaparPowerShell(valor) {
21
+ return valor.replaceAll("'", "''");
22
+ }
23
+ function desescaparPowerShell(valor) {
24
+ return valor.replaceAll("''", "'");
25
+ }
26
+ function gerarCompanionBase(executavelNode, entrypoint, versaoPacote) {
27
+ return [
28
+ `# ${MARCADOR_COMPANION}`,
29
+ `# ${PREFIXO_VERSAO}${versaoPacote}`,
30
+ "$ErrorActionPreference = 'Stop'",
31
+ `$node = '${escaparPowerShell(executavelNode)}'`,
32
+ `$entrypoint = '${escaparPowerShell(entrypoint)}'`,
33
+ "$semaUtf8 = [System.Text.UTF8Encoding]::new($false, $true)",
34
+ "$semaArgsJson = ConvertTo-Json -InputObject ([string[]]@($args)) -Compress",
35
+ "$semaArgsB64 = [System.Convert]::ToBase64String($semaUtf8.GetBytes($semaArgsJson))",
36
+ "$semaEntrypointB64 = [System.Convert]::ToBase64String($semaUtf8.GetBytes($entrypoint))",
37
+ "$semaArgsAnterior = [System.Environment]::GetEnvironmentVariable('SEMA_LAUNCHER_ARGS_B64', 'Process')",
38
+ "$semaEntrypointAnterior = [System.Environment]::GetEnvironmentVariable('SEMA_LAUNCHER_ENTRYPOINT_B64', 'Process')",
39
+ "$semaExit = $null",
40
+ "try {",
41
+ " [System.Environment]::SetEnvironmentVariable('SEMA_LAUNCHER_ARGS_B64', $semaArgsB64, 'Process')",
42
+ " [System.Environment]::SetEnvironmentVariable('SEMA_LAUNCHER_ENTRYPOINT_B64', $semaEntrypointB64, 'Process')",
43
+ ` $semaBootstrap = '${escaparPowerShell(BOOTSTRAP_NODE)}'`,
44
+ " & $node '-e' $semaBootstrap",
45
+ " $semaExit = $LASTEXITCODE",
46
+ "} finally {",
47
+ " [System.Environment]::SetEnvironmentVariable('SEMA_LAUNCHER_ARGS_B64', $semaArgsAnterior, 'Process')",
48
+ " [System.Environment]::SetEnvironmentVariable('SEMA_LAUNCHER_ENTRYPOINT_B64', $semaEntrypointAnterior, 'Process')",
49
+ "}",
50
+ "if ($null -eq $semaExit) { $semaExit = 1 }",
51
+ "$semaDedicated = $false",
52
+ "$semaProcessArgs = [System.Environment]::GetCommandLineArgs()",
53
+ "for ($semaIndice = 0; $semaIndice -lt ($semaProcessArgs.Length - 1); $semaIndice++) {",
54
+ " if ($semaProcessArgs[$semaIndice] -ieq '-File') {",
55
+ " try { $semaDedicated = [System.StringComparer]::OrdinalIgnoreCase.Equals([System.IO.Path]::GetFullPath($semaProcessArgs[$semaIndice + 1]), [System.IO.Path]::GetFullPath($PSCommandPath)) } catch { $semaDedicated = $false }",
56
+ " break",
57
+ " }",
58
+ "}",
59
+ "if (-not $semaDedicated) {",
60
+ " $global:LASTEXITCODE = $semaExit",
61
+ " return",
62
+ "}",
63
+ "exit $semaExit",
64
+ "",
65
+ ];
66
+ }
67
+ function gerarCompanion(executavelNode, entrypoint, versaoPacote) {
68
+ const base = gerarCompanionBase(executavelNode, entrypoint, versaoPacote);
69
+ const baseTexto = base.join("\r\n");
70
+ base.splice(2, 0, `# ${PREFIXO_RECIBO}${sha256(baseTexto)}`);
71
+ return Buffer.concat([UTF8_BOM, Buffer.from(base.join("\r\n"), "utf8")]);
72
+ }
73
+ function gerarComandoCompanion(_nomeCompanion) {
74
+ // `%*` segue a semântica normal do cmd.exe; transporte byte-exato pertence aos wrappers .ps1.
75
+ return `@"%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass -File "%~dp0${NOME_LAUNCHER_POWERSHELL}" %*`;
76
+ }
77
+ function gerarComandoEsperadoWrapper() {
78
+ return ` $expectedCommand = '${escaparPowerShell(gerarComandoCompanion(""))}'`;
79
+ }
80
+ function gerarAncora(launcher, companion, nomeCompanion, wrapper) {
81
+ const base = [
82
+ `# ${MARCADOR_ANCORA}`,
83
+ `launcher_sha256=${sha256(launcher)}`,
84
+ `wrapper_sha256=${sha256(wrapper)}`,
85
+ `companion_name=${nomeCompanion}`,
86
+ `companion_sha256=${sha256(companion)}`,
87
+ "",
88
+ ];
89
+ const baseTexto = base.join("\r\n");
90
+ base.splice(5, 0, `receipt_sha256=${sha256(baseTexto)}`);
91
+ return Buffer.from(base.join("\r\n"), "ascii");
92
+ }
93
+ function gerarCmdBase(nomeCompanion, versaoPacote) {
94
+ return [
95
+ "@echo off",
96
+ "@setlocal DisableDelayedExpansion",
97
+ `rem ${MARCADOR}`,
98
+ `rem ${PREFIXO_VERSAO}${versaoPacote}`,
99
+ `rem SEMA-LAUNCHER-COMPANION ${nomeCompanion}`,
100
+ gerarComandoCompanion(nomeCompanion),
101
+ "@set \"_SEMA_EXIT=%ERRORLEVEL%\"",
102
+ "@endlocal & exit /b %_SEMA_EXIT%",
103
+ "",
104
+ ];
105
+ }
106
+ function gerarWrapper() {
107
+ // A âncora detecta corrupção do conjunto antes do payload; não autentica uma
108
+ // substituição coordenada de wrapper e âncora pelo mesmo usuário do processo.
109
+ const linhas = [
110
+ `# ${MARCADOR_WRAPPER}`,
111
+ "$ErrorActionPreference = 'Stop'",
112
+ "$semaDedicated = $false",
113
+ "$semaProcessArgs = [System.Environment]::GetCommandLineArgs()",
114
+ "for ($semaIndice = 0; $semaIndice -lt ($semaProcessArgs.Length - 1); $semaIndice++) {",
115
+ " if ($semaProcessArgs[$semaIndice] -ieq '-File') {",
116
+ " try { $semaDedicated = [System.StringComparer]::OrdinalIgnoreCase.Equals([System.IO.Path]::GetFullPath($semaProcessArgs[$semaIndice + 1]), [System.IO.Path]::GetFullPath($PSCommandPath)) } catch { $semaDedicated = $false }",
117
+ " break",
118
+ " }",
119
+ "}",
120
+ "try {",
121
+ " $selfInfo = [System.IO.FileInfo]::new($PSCommandPath)",
122
+ " if (-not $selfInfo.Exists -or $selfInfo.Length -gt 65536 -or (($selfInfo.Attributes -band [System.IO.FileAttributes]::ReparsePoint) -ne 0)) { throw 'wrapper inválido' }",
123
+ " $selfBytes = [System.IO.File]::ReadAllBytes($PSCommandPath)",
124
+ " $selfInfo.Refresh()",
125
+ " if (-not $selfInfo.Exists -or $selfInfo.Length -ne $selfBytes.Length -or (($selfInfo.Attributes -band [System.IO.FileAttributes]::ReparsePoint) -ne 0)) { throw 'wrapper alterado' }",
126
+ ` $anchorPath = [System.IO.Path]::Combine($PSScriptRoot, '${NOME_ANCORA}')`,
127
+ " $anchorInfo = [System.IO.FileInfo]::new($anchorPath)",
128
+ " if (-not $anchorInfo.Exists -or $anchorInfo.Length -gt 8192 -or (($anchorInfo.Attributes -band [System.IO.FileAttributes]::ReparsePoint) -ne 0)) { throw 'âncora inválida' }",
129
+ " $anchorBytes = [System.IO.File]::ReadAllBytes($anchorPath)",
130
+ " $anchorInfo.Refresh()",
131
+ " if (-not $anchorInfo.Exists -or $anchorInfo.Length -ne $anchorBytes.Length -or (($anchorInfo.Attributes -band [System.IO.FileAttributes]::ReparsePoint) -ne 0)) { throw 'âncora alterada' }",
132
+ " $ascii = [System.Text.Encoding]::ASCII",
133
+ " $anchorLines = [System.Text.RegularExpressions.Regex]::Split($ascii.GetString($anchorBytes), '\\r\\n')",
134
+ ` if ($anchorLines.Count -ne 7 -or $anchorLines[0] -ne '# ${MARCADOR_ANCORA}' -or $anchorLines[6] -ne '') { throw 'âncora não gerenciada' }`,
135
+ " $launcherDigestMatch = [System.Text.RegularExpressions.Regex]::Match($anchorLines[1], '^launcher_sha256=([a-f0-9]{64})$')",
136
+ " $wrapperDigestMatch = [System.Text.RegularExpressions.Regex]::Match($anchorLines[2], '^wrapper_sha256=([a-f0-9]{64})$')",
137
+ " $anchorCompanionMatch = [System.Text.RegularExpressions.Regex]::Match($anchorLines[3], '^companion_name=(\\.sema-launcher-[a-f0-9]{64}\\.ps1)$')",
138
+ " $anchorCompanionDigestMatch = [System.Text.RegularExpressions.Regex]::Match($anchorLines[4], '^companion_sha256=([a-f0-9]{64})$')",
139
+ " $anchorReceiptMatch = [System.Text.RegularExpressions.Regex]::Match($anchorLines[5], '^receipt_sha256=([a-f0-9]{64})$')",
140
+ " if (-not $launcherDigestMatch.Success -or -not $wrapperDigestMatch.Success -or -not $anchorCompanionMatch.Success -or -not $anchorCompanionDigestMatch.Success -or -not $anchorReceiptMatch.Success) { throw 'âncora sem recibo' }",
141
+ " $sha = [System.Security.Cryptography.SHA256]::Create()",
142
+ " try {",
143
+ " $selfDigest = ([System.BitConverter]::ToString($sha.ComputeHash($selfBytes))).Replace('-', '').ToLowerInvariant()",
144
+ " $anchorBase = [string]::Join(\"`r`n\", @($anchorLines[0..4] + $anchorLines[6]))",
145
+ " $anchorDigest = ([System.BitConverter]::ToString($sha.ComputeHash($ascii.GetBytes($anchorBase)))).Replace('-', '').ToLowerInvariant()",
146
+ " } finally { $sha.Dispose() }",
147
+ " if ($selfDigest -ne $wrapperDigestMatch.Groups[1].Value -or $anchorDigest -ne $anchorReceiptMatch.Groups[1].Value) { throw 'integridade do wrapper divergente' }",
148
+ " $cmdPath = [System.IO.Path]::Combine($PSScriptRoot, 'sema.cmd')",
149
+ " $cmdInfo = [System.IO.FileInfo]::new($cmdPath)",
150
+ " if (-not $cmdInfo.Exists -or $cmdInfo.Length -gt 65536 -or (($cmdInfo.Attributes -band [System.IO.FileAttributes]::ReparsePoint) -ne 0)) { throw 'cmd inválido' }",
151
+ " $cmdBytes = [System.IO.File]::ReadAllBytes($cmdPath)",
152
+ " $cmdInfo.Refresh()",
153
+ " if (-not $cmdInfo.Exists -or $cmdInfo.Length -ne $cmdBytes.Length -or $cmdBytes.Length -gt 65536 -or (($cmdInfo.Attributes -band [System.IO.FileAttributes]::ReparsePoint) -ne 0)) { throw 'cmd alterado' }",
154
+ " $utf8 = [System.Text.UTF8Encoding]::new($false, $true)",
155
+ " $cmdLines = [System.Text.RegularExpressions.Regex]::Split($utf8.GetString($cmdBytes), '\\r\\n')",
156
+ " if ($cmdLines.Count -ne 10 -or $cmdLines[0] -ne '@echo off' -or $cmdLines[1] -ne '@setlocal DisableDelayedExpansion' -or $cmdLines[2] -ne 'rem SEMA-MANAGED-LAUNCHER v2' -or $cmdLines[7] -ne '@set \"_SEMA_EXIT=%ERRORLEVEL%\"' -or $cmdLines[8] -ne '@endlocal & exit /b %_SEMA_EXIT%' -or $cmdLines[9] -ne '') { throw 'cmd não gerenciado' }",
157
+ " if (-not [System.Text.RegularExpressions.Regex]::IsMatch($cmdLines[3], '^rem SEMA-LAUNCHER-VERSION (0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(?:-[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?(?:\\+[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?$')) { throw 'versão inválida' }",
158
+ " $companionMatch = [System.Text.RegularExpressions.Regex]::Match($cmdLines[4], '^rem SEMA-LAUNCHER-COMPANION (\\.sema-launcher-[a-f0-9]{64}\\.ps1)$')",
159
+ " $receiptMatch = [System.Text.RegularExpressions.Regex]::Match($cmdLines[5], '^rem SEMA-LAUNCHER-RECEIPT sha256:([a-f0-9]{64})$')",
160
+ " if (-not $companionMatch.Success -or -not $receiptMatch.Success) { throw 'recibo inválido' }",
161
+ " $companionName = $companionMatch.Groups[1].Value",
162
+ " $expectedDigest = $companionName.Substring(15, 64)",
163
+ gerarComandoEsperadoWrapper(),
164
+ " if ($cmdLines[6] -ne $expectedCommand) { throw 'comando inválido' }",
165
+ " $cmdBase = [string]::Join(\"`r`n\", @($cmdLines[0..4] + $cmdLines[6..9]))",
166
+ " $sha = [System.Security.Cryptography.SHA256]::Create()",
167
+ " try { $cmdDigest = ([System.BitConverter]::ToString($sha.ComputeHash($utf8.GetBytes($cmdBase)))).Replace('-', '').ToLowerInvariant() } finally { $sha.Dispose() }",
168
+ " if ($cmdDigest -ne $receiptMatch.Groups[1].Value) { throw 'recibo divergente' }",
169
+ " $sha = [System.Security.Cryptography.SHA256]::Create()",
170
+ " try { $cmdBytesDigest = ([System.BitConverter]::ToString($sha.ComputeHash($cmdBytes))).Replace('-', '').ToLowerInvariant() } finally { $sha.Dispose() }",
171
+ " if ($cmdBytesDigest -ne $launcherDigestMatch.Groups[1].Value) { throw 'launcher divergente da âncora' }",
172
+ " $companionPath = [System.IO.Path]::Combine($PSScriptRoot, $companionName)",
173
+ " $companionInfo = [System.IO.FileInfo]::new($companionPath)",
174
+ " if (-not $companionInfo.Exists -or $companionInfo.Length -gt 65536 -or (($companionInfo.Attributes -band [System.IO.FileAttributes]::ReparsePoint) -ne 0)) { throw 'companion inválido' }",
175
+ " $companionBytes = [System.IO.File]::ReadAllBytes($companionPath)",
176
+ " $companionInfo.Refresh()",
177
+ " if (-not $companionInfo.Exists -or $companionInfo.Length -ne $companionBytes.Length -or $companionBytes.Length -gt 65536 -or (($companionInfo.Attributes -band [System.IO.FileAttributes]::ReparsePoint) -ne 0)) { throw 'companion alterado' }",
178
+ " $sha = [System.Security.Cryptography.SHA256]::Create()",
179
+ " try { $companionDigest = ([System.BitConverter]::ToString($sha.ComputeHash($companionBytes))).Replace('-', '').ToLowerInvariant() } finally { $sha.Dispose() }",
180
+ " if ($companionName -ne $anchorCompanionMatch.Groups[1].Value -or $companionDigest -ne $anchorCompanionDigestMatch.Groups[1].Value -or $companionName -ne ('.sema-launcher-' + $companionDigest + '.ps1')) { throw 'digest divergente' }",
181
+ " if ($companionBytes.Length -lt 3 -or $companionBytes[0] -ne 239 -or $companionBytes[1] -ne 187 -or $companionBytes[2] -ne 191) { throw 'encoding divergente' }",
182
+ " $companionTexto = $utf8.GetString($companionBytes, 3, $companionBytes.Length - 3)",
183
+ " $companionScript = [ScriptBlock]::Create($companionTexto)",
184
+ " $semaExit = $null",
185
+ " & $companionScript @args",
186
+ " $semaExit = $LASTEXITCODE",
187
+ " if ($null -eq $semaExit) { $semaExit = 1 }",
188
+ " if ($semaDedicated) { exit $semaExit }",
189
+ " $global:LASTEXITCODE = $semaExit",
190
+ " return",
191
+ "} catch {",
192
+ " [Console]::Error.WriteLine('Sema managed launcher integrity check failed.')",
193
+ " if ($semaDedicated) { exit 1 }",
194
+ " $global:LASTEXITCODE = 1",
195
+ " return",
196
+ "}",
197
+ "",
198
+ ];
199
+ return Buffer.concat([UTF8_BOM, Buffer.from(linhas.join("\r\n"), "utf8")]);
200
+ }
201
+ export function gerarWrapperLauncherWindows() {
202
+ return gerarWrapper();
203
+ }
204
+ export function validarWrapperLauncherWindows(conteudo) {
205
+ return conteudo.equals(gerarWrapper());
206
+ }
207
+ export function nomeWrapperLauncherWindows() {
208
+ return NOME_WRAPPER;
209
+ }
210
+ export function nomeLauncherPowerShellWindows() {
211
+ return NOME_LAUNCHER_POWERSHELL;
212
+ }
213
+ export function nomeAncoraLauncherWindows() {
214
+ return NOME_ANCORA;
215
+ }
216
+ export function gerarArtefatosLauncherWindows(executavelNode, entrypoint, versaoPacote) {
217
+ if (!versaoSemanticaValida(versaoPacote)
218
+ || !path.win32.isAbsolute(executavelNode)
219
+ || !path.win32.isAbsolute(entrypoint)) {
220
+ throw new Error("ARTEFATO_LAUNCHER_WINDOWS_INVALIDO");
221
+ }
222
+ const companion = gerarCompanion(executavelNode, entrypoint, versaoPacote);
223
+ const nomeCompanion = `.sema-launcher-${sha256(companion)}.ps1`;
224
+ const base = gerarCmdBase(nomeCompanion, versaoPacote);
225
+ const baseTexto = base.join("\r\n");
226
+ base.splice(5, 0, `rem ${PREFIXO_RECIBO}${sha256(baseTexto)}`);
227
+ const launcher = base.join("\r\n");
228
+ const wrapper = gerarWrapper();
229
+ return {
230
+ launcher,
231
+ companion,
232
+ nomeCompanion,
233
+ wrapper,
234
+ anchor: gerarAncora(launcher, companion, nomeCompanion, wrapper),
235
+ };
236
+ }
237
+ export function validarAncoraLauncherWindows(conteudo, launcher, companion, nomeCompanion, wrapper) {
238
+ return conteudo.equals(gerarAncora(launcher, companion, nomeCompanion, wrapper));
239
+ }
240
+ export function validarReciboAncoraLauncherWindows(conteudo) {
241
+ if (conteudo.some((byte) => byte > 0x7f))
242
+ return false;
243
+ const linhas = conteudo.toString("ascii").split("\r\n");
244
+ if (linhas.length !== 7
245
+ || linhas[0] !== `# ${MARCADOR_ANCORA}`
246
+ || !/^launcher_sha256=[a-f0-9]{64}$/u.test(linhas[1] ?? "")
247
+ || !/^wrapper_sha256=[a-f0-9]{64}$/u.test(linhas[2] ?? "")
248
+ || !/^companion_name=\.sema-launcher-[a-f0-9]{64}\.ps1$/u.test(linhas[3] ?? "")
249
+ || !/^companion_sha256=[a-f0-9]{64}$/u.test(linhas[4] ?? "")
250
+ || !/^receipt_sha256=[a-f0-9]{64}$/u.test(linhas[5] ?? "")
251
+ || linhas[6] !== "")
252
+ return false;
253
+ const recibo = linhas[5]?.slice("receipt_sha256=".length);
254
+ const base = [...linhas];
255
+ base.splice(5, 1);
256
+ return sha256(Buffer.from(base.join("\r\n"), "ascii")) === recibo;
257
+ }
258
+ function validarCmd(conteudo) {
259
+ if (/[^\x00-\x7f]/u.test(conteudo))
260
+ return null;
261
+ const linhas = conteudo.split("\r\n");
262
+ if (linhas.length !== 10
263
+ || linhas[0] !== "@echo off"
264
+ || linhas[1] !== "@setlocal DisableDelayedExpansion"
265
+ || linhas[2] !== `rem ${MARCADOR}`
266
+ || linhas[7] !== "@set \"_SEMA_EXIT=%ERRORLEVEL%\""
267
+ || linhas[8] !== "@endlocal & exit /b %_SEMA_EXIT%"
268
+ || linhas[9] !== "")
269
+ return null;
270
+ const versao = linhas[3]?.slice(`rem ${PREFIXO_VERSAO}`.length) ?? "";
271
+ const companion = linhas[4]?.match(/^rem SEMA-LAUNCHER-COMPANION (\.sema-launcher-[a-f0-9]{64}\.ps1)$/u)?.[1];
272
+ const recibo = linhas[5]?.match(new RegExp(`^rem ${PREFIXO_RECIBO}([a-f0-9]{64})$`, "u"))?.[1];
273
+ if (!versaoSemanticaValida(versao) || !companion || !recibo)
274
+ return null;
275
+ if (linhas[6] !== gerarComandoCompanion(companion)) {
276
+ return null;
277
+ }
278
+ const base = [...linhas];
279
+ base.splice(5, 1);
280
+ if (sha256(base.join("\r\n")) !== recibo)
281
+ return null;
282
+ return { versaoPacote: versao, nomeCompanion: companion };
283
+ }
284
+ export function validarCompanionLauncherWindows(conteudo, nomeCompanion) {
285
+ if (conteudo.length < UTF8_BOM.length
286
+ || !conteudo.subarray(0, UTF8_BOM.length).equals(UTF8_BOM)
287
+ || nomeCompanion !== `.sema-launcher-${sha256(conteudo)}.ps1`)
288
+ return null;
289
+ const texto = conteudo.subarray(UTF8_BOM.length).toString("utf8");
290
+ const linhas = texto.split("\r\n");
291
+ const versaoPacote = linhas[1]?.slice(`# ${PREFIXO_VERSAO}`.length) ?? "";
292
+ if (linhas[0] !== `# ${MARCADOR_COMPANION}`
293
+ || linhas[1] !== `# ${PREFIXO_VERSAO}${versaoPacote}`
294
+ || !versaoSemanticaValida(versaoPacote)
295
+ || linhas[3] !== "$ErrorActionPreference = 'Stop'")
296
+ return null;
297
+ const node = linhas[4]?.match(/^\$node = '((?:[^']|'')*)'$/u)?.[1];
298
+ const entrypoint = linhas[5]?.match(/^\$entrypoint = '((?:[^']|'')*)'$/u)?.[1];
299
+ if (node === undefined || entrypoint === undefined)
300
+ return null;
301
+ const executavelNode = desescaparPowerShell(node);
302
+ const entrypointReal = desescaparPowerShell(entrypoint);
303
+ if (!path.win32.isAbsolute(executavelNode) || !path.win32.isAbsolute(entrypointReal))
304
+ return null;
305
+ if (!conteudo.equals(gerarCompanion(executavelNode, entrypointReal, versaoPacote)))
306
+ return null;
307
+ return { versaoPacote, executavelNode, entrypoint: entrypointReal };
308
+ }
309
+ export function validarArtefatosLauncherWindows(launcher, companion) {
310
+ const cmd = validarCmd(launcher);
311
+ if (!cmd)
312
+ return null;
313
+ const ps1 = validarCompanionLauncherWindows(companion, cmd.nomeCompanion);
314
+ if (!ps1 || ps1.versaoPacote !== cmd.versaoPacote)
315
+ return null;
316
+ return {
317
+ versaoPacote: cmd.versaoPacote,
318
+ executavelNode: ps1.executavelNode,
319
+ entrypoint: ps1.entrypoint,
320
+ nomeCompanion: cmd.nomeCompanion,
321
+ };
322
+ }
323
+ export function extrairNomeCompanionLauncherWindows(launcher) {
324
+ return validarCmd(launcher)?.nomeCompanion ?? null;
325
+ }
326
+ //# sourceMappingURL=launcherWindows.js.map
@@ -0,0 +1,10 @@
1
+ export interface TokenLockDistribuicaoGlobal {
2
+ homeReal: string;
3
+ nonce: string;
4
+ ativo: boolean;
5
+ encerrado: boolean;
6
+ confirmar: (homeReal: string) => Promise<void>;
7
+ }
8
+ export declare function tokenLockDistribuicaoGlobalAtual(): TokenLockDistribuicaoGlobal | undefined;
9
+ export declare function executarComTokenLockDistribuicaoGlobal<T>(token: TokenLockDistribuicaoGlobal, operacao: () => Promise<T>): Promise<T>;
10
+ export declare function confirmarFencingLockDistribuicaoGlobal(homeReal: string): Promise<void>;
@@ -0,0 +1,17 @@
1
+ // SEMA-GOVERNED: sema.produto.distribuicao_global, sema.produto.distribuicao_global.transacao
2
+ // Descrição: propaga o fencing token ativo da transação sem criar ciclo com primitivas de filesystem.
3
+ import { AsyncLocalStorage } from "node:async_hooks";
4
+ const contexto = new AsyncLocalStorage();
5
+ export function tokenLockDistribuicaoGlobalAtual() {
6
+ return contexto.getStore();
7
+ }
8
+ export function executarComTokenLockDistribuicaoGlobal(token, operacao) {
9
+ return contexto.run(token, operacao);
10
+ }
11
+ export async function confirmarFencingLockDistribuicaoGlobal(homeReal) {
12
+ const token = contexto.getStore();
13
+ if (!token)
14
+ return;
15
+ await token.confirmar(homeReal);
16
+ }
17
+ //# sourceMappingURL=lockContextGlobal.js.map
@@ -0,0 +1,6 @@
1
+ import type { OpcoesAmbienteDistribuicaoGlobal } from "./tipos.js";
2
+ export declare function comLockDistribuicaoGlobal<T>(opcoes: Pick<OpcoesAmbienteDistribuicaoGlobal, "diretorioUsuario">, operacao: (opcoesCanonicas: {
3
+ diretorioUsuario: string;
4
+ }) => Promise<T>): Promise<T>;
5
+ /** Nome fixo exportado apenas para testes de crash/stale sem revelar caminhos reais. */
6
+ export declare function nomeLockDistribuicaoGlobal(): string;