higpertext-cli 0.8.0__py3-none-any.whl

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 (335) hide show
  1. config/adapters_config.json +450 -0
  2. config/antigravity_agent_template.json +31 -0
  3. config/app_config.json +174 -0
  4. config/context_engine.json +33 -0
  5. config/environments/model_defaults.json +5 -0
  6. config/governance/branching_strategy.json +36 -0
  7. config/governance/deployment_gates.json +30 -0
  8. config/governance/guidelines_contract.json +54 -0
  9. config/governance/quality_gates.json +39 -0
  10. config/governance/section_rules.json +22 -0
  11. config/governance/security_guardrails.json +52 -0
  12. config/hooks/README.md +35 -0
  13. config/hooks/custom/test_output_limiter.json +9 -0
  14. config/hooks/global/session_prompt.json +9 -0
  15. config/htx_config.json +24 -0
  16. config/profile_learner.json +18 -0
  17. config/profiles/base_agent.json +40 -0
  18. config/profiles/base_auditor.json +19 -0
  19. config/profiles/base_developer.json +19 -0
  20. config/profiles/base_operator.json +16 -0
  21. config/profiles/global.json +33 -0
  22. config/profiles/software_developer.json +23 -0
  23. config/router_content.json +137 -0
  24. config/semantic_graph.json +66 -0
  25. config/workflows/ado_release_flow.json +38 -0
  26. config/workflows/docs-update.json +33 -0
  27. config/workflows/governance-check.yaml +26 -0
  28. config/workflows/guidelines-sync.json +40 -0
  29. config/workflows/higpertext-build.json +73 -0
  30. config/workflows/higpertext-plan.json +38 -0
  31. config/workflows/higpertext-review.json +41 -0
  32. config/workflows/pr-quality-check.json +56 -0
  33. config/workflows/quality-remediation.json +57 -0
  34. higpertext/__init__.py +18 -0
  35. higpertext/adapters/__init__.py +27 -0
  36. higpertext/adapters/adapter_utils.py +604 -0
  37. higpertext/adapters/claude_adapter/__init__.py +0 -0
  38. higpertext/adapters/claude_adapter/claude_adapter.py +154 -0
  39. higpertext/adapters/copilot_adapter/__init__.py +0 -0
  40. higpertext/adapters/copilot_adapter/copilot_adapter.py +231 -0
  41. higpertext/adapters/gemini_adapter/__init__.py +0 -0
  42. higpertext/adapters/gemini_adapter/gemini_adapter.py +211 -0
  43. higpertext/adapters/llm_formatter.py +46 -0
  44. higpertext/adapters/open_code_adapter/__init__.py +0 -0
  45. higpertext/adapters/open_code_adapter/open_code_adapter.py +480 -0
  46. higpertext/capabilities/capabilities_runner.py +216 -0
  47. higpertext/capabilities/common/agent-builder.json +54 -0
  48. higpertext/capabilities/common/agent-sync.json +34 -0
  49. higpertext/capabilities/common/code-skeletonizer.json +35 -0
  50. higpertext/capabilities/common/commit-report.json +42 -0
  51. higpertext/capabilities/common/context-assembler.json +37 -0
  52. higpertext/capabilities/common/context-budget-report.json +15 -0
  53. higpertext/capabilities/common/dep-manager.json +43 -0
  54. higpertext/capabilities/common/docs-sync.json +14 -0
  55. higpertext/capabilities/common/doctor.json +18 -0
  56. higpertext/capabilities/common/efficiency-meter.json +31 -0
  57. higpertext/capabilities/common/env-catalog.json +13 -0
  58. higpertext/capabilities/common/env-clean.json +14 -0
  59. higpertext/capabilities/common/env-logs.json +16 -0
  60. higpertext/capabilities/common/env-runner.json +23 -0
  61. higpertext/capabilities/common/env-status.json +13 -0
  62. higpertext/capabilities/common/env-stop.json +14 -0
  63. higpertext/capabilities/common/env-template.json +14 -0
  64. higpertext/capabilities/common/error-context-locator.json +23 -0
  65. higpertext/capabilities/common/eval-agent.json +33 -0
  66. higpertext/capabilities/common/file-map.json +17 -0
  67. higpertext/capabilities/common/governance-exception.json +54 -0
  68. higpertext/capabilities/common/graph-query.json +59 -0
  69. higpertext/capabilities/common/graph-rebuild.json +31 -0
  70. higpertext/capabilities/common/graph-visualize.json +37 -0
  71. higpertext/capabilities/common/grep-search.json +176 -0
  72. higpertext/capabilities/common/higpertext-tester.json +25 -0
  73. higpertext/capabilities/common/hook-health.json +19 -0
  74. higpertext/capabilities/common/hook-sync-check.json +19 -0
  75. higpertext/capabilities/common/hooks-manager.json +55 -0
  76. higpertext/capabilities/common/knowledge-asker.json +27 -0
  77. higpertext/capabilities/common/list-rules.json +27 -0
  78. higpertext/capabilities/common/llm-invoke.json +59 -0
  79. higpertext/capabilities/common/load-rules.json +37 -0
  80. higpertext/capabilities/common/memory-manager.json +65 -0
  81. higpertext/capabilities/common/quality-scan.json +21 -0
  82. higpertext/capabilities/common/quality-updater.json +35 -0
  83. higpertext/capabilities/common/rag-index.json +17 -0
  84. higpertext/capabilities/common/report-viewer.json +24 -0
  85. higpertext/capabilities/common/roadmap-report.json +37 -0
  86. higpertext/capabilities/common/scripts/_env_cli.py +65 -0
  87. higpertext/capabilities/common/scripts/agent_builder.py +60 -0
  88. higpertext/capabilities/common/scripts/agent_sync.py +56 -0
  89. higpertext/capabilities/common/scripts/ask_higpertext.py +38 -0
  90. higpertext/capabilities/common/scripts/code_skeletonizer.py +225 -0
  91. higpertext/capabilities/common/scripts/commit_report.py +134 -0
  92. higpertext/capabilities/common/scripts/context_assembler.py +70 -0
  93. higpertext/capabilities/common/scripts/context_budget_report.py +53 -0
  94. higpertext/capabilities/common/scripts/dep_manager.py +81 -0
  95. higpertext/capabilities/common/scripts/docs_sync.py +981 -0
  96. higpertext/capabilities/common/scripts/doctor.py +144 -0
  97. higpertext/capabilities/common/scripts/efficiency_meter.py +83 -0
  98. higpertext/capabilities/common/scripts/env_catalog.py +47 -0
  99. higpertext/capabilities/common/scripts/env_clean.py +30 -0
  100. higpertext/capabilities/common/scripts/env_logs.py +32 -0
  101. higpertext/capabilities/common/scripts/env_runner.py +53 -0
  102. higpertext/capabilities/common/scripts/env_status.py +38 -0
  103. higpertext/capabilities/common/scripts/env_stop.py +30 -0
  104. higpertext/capabilities/common/scripts/env_template.py +73 -0
  105. higpertext/capabilities/common/scripts/error_context_locator.py +138 -0
  106. higpertext/capabilities/common/scripts/eval_agent.py +80 -0
  107. higpertext/capabilities/common/scripts/file_map.py +95 -0
  108. higpertext/capabilities/common/scripts/governance_exception.py +116 -0
  109. higpertext/capabilities/common/scripts/graph_query.py +104 -0
  110. higpertext/capabilities/common/scripts/graph_rebuild.py +107 -0
  111. higpertext/capabilities/common/scripts/graph_visualize.py +76 -0
  112. higpertext/capabilities/common/scripts/grep_search.py +648 -0
  113. higpertext/capabilities/common/scripts/higpertext_tester.py +102 -0
  114. higpertext/capabilities/common/scripts/hook_health.py +149 -0
  115. higpertext/capabilities/common/scripts/hook_sync_check.py +134 -0
  116. higpertext/capabilities/common/scripts/hooks_manager.py +171 -0
  117. higpertext/capabilities/common/scripts/list_rules.py +175 -0
  118. higpertext/capabilities/common/scripts/llm_invoke.py +135 -0
  119. higpertext/capabilities/common/scripts/load_rules.py +379 -0
  120. higpertext/capabilities/common/scripts/memory_manager.py +210 -0
  121. higpertext/capabilities/common/scripts/presentation_engine.py +63 -0
  122. higpertext/capabilities/common/scripts/quality_scan.py +132 -0
  123. higpertext/capabilities/common/scripts/rag_index.py +39 -0
  124. higpertext/capabilities/common/scripts/report_viewer.py +106 -0
  125. higpertext/capabilities/common/scripts/roadmap_report.py +73 -0
  126. higpertext/capabilities/common/scripts/search_router.py +111 -0
  127. higpertext/capabilities/common/scripts/semantic_diff.py +166 -0
  128. higpertext/capabilities/common/scripts/semantic_search.py +43 -0
  129. higpertext/capabilities/common/scripts/session_control.py +136 -0
  130. higpertext/capabilities/common/scripts/smart_read.py +232 -0
  131. higpertext/capabilities/common/scripts/subagent_executor.py +143 -0
  132. higpertext/capabilities/common/scripts/sync_agents.py +353 -0
  133. higpertext/capabilities/common/scripts/task_decomposer.py +78 -0
  134. higpertext/capabilities/common/scripts/telemetry_report.py +36 -0
  135. higpertext/capabilities/common/search-router.json +24 -0
  136. higpertext/capabilities/common/semantic-diff.json +40 -0
  137. higpertext/capabilities/common/semantic-search.json +19 -0
  138. higpertext/capabilities/common/session-clean.json +20 -0
  139. higpertext/capabilities/common/session-start.json +44 -0
  140. higpertext/capabilities/common/smart-read.json +28 -0
  141. higpertext/capabilities/common/subagent-executor.json +25 -0
  142. higpertext/capabilities/common/sync-agents.json +32 -0
  143. higpertext/capabilities/common/task-decomposer.json +37 -0
  144. higpertext/capabilities/common/telemetry-report.json +23 -0
  145. higpertext/capabilities/git/__init__.py +0 -0
  146. higpertext/capabilities/git/committer.json +61 -0
  147. higpertext/capabilities/git/diff.json +33 -0
  148. higpertext/capabilities/git/ls-files.json +44 -0
  149. higpertext/capabilities/git/rm.json +27 -0
  150. higpertext/capabilities/git/scripts/__init__.py +0 -0
  151. higpertext/capabilities/git/scripts/commit_changes.py +1077 -0
  152. higpertext/capabilities/git/scripts/git_diff.py +171 -0
  153. higpertext/capabilities/git/scripts/git_ls_files.py +376 -0
  154. higpertext/capabilities/git/scripts/git_rm.py +62 -0
  155. higpertext/capabilities/security/k8s-auditor.json +33 -0
  156. higpertext/capabilities/security/scripts/k8s_auditor.py +307 -0
  157. higpertext/capabilities/security/scripts/secret_scanner.py +235 -0
  158. higpertext/capabilities/security/secret-scanner.json +32 -0
  159. higpertext/hooks/__init__.py +28 -0
  160. higpertext/hooks/_compat.py +27 -0
  161. higpertext/hooks/hook_tasks/__init__.py +1 -0
  162. higpertext/hooks/hook_tasks/_rules/__init__.py +0 -0
  163. higpertext/hooks/hook_tasks/_rules/bash_rules.py +635 -0
  164. higpertext/hooks/hook_tasks/_rules/context_engine_rule.py +79 -0
  165. higpertext/hooks/hook_tasks/_rules/context_rules.py +199 -0
  166. higpertext/hooks/hook_tasks/_rules/governance_adapter.py +72 -0
  167. higpertext/hooks/hook_tasks/_rules/profile_rules.json +25 -0
  168. higpertext/hooks/hook_tasks/_rules/quality_rules.py +86 -0
  169. higpertext/hooks/hook_tasks/_rules/security_rules.py +214 -0
  170. higpertext/hooks/hook_tasks/_rules/session_rules.py +316 -0
  171. higpertext/hooks/hook_tasks/_rules/telemetry_rules.py +121 -0
  172. higpertext/hooks/hook_tasks/audit_logger_hook.py +28 -0
  173. higpertext/hooks/hook_tasks/hook_bash_guard.py +101 -0
  174. higpertext/hooks/hook_tasks/hook_code_quality.py +48 -0
  175. higpertext/hooks/hook_tasks/hook_context_hint.py +46 -0
  176. higpertext/hooks/hook_tasks/hook_context_manager.py +44 -0
  177. higpertext/hooks/hook_tasks/hook_io.py +122 -0
  178. higpertext/hooks/hook_tasks/hook_loop_guard.py +182 -0
  179. higpertext/hooks/hook_tasks/hook_post_observer.py +54 -0
  180. higpertext/hooks/hook_tasks/hook_read_guard.py +85 -0
  181. higpertext/hooks/hook_tasks/hook_security_guard.py +81 -0
  182. higpertext/hooks/hook_tasks/hook_session_prompt.py +83 -0
  183. higpertext/hooks/hook_tasks/hook_session_stop.py +115 -0
  184. higpertext/hooks/hook_tasks/hook_utils.py +144 -0
  185. higpertext/hooks/hook_tasks/session_guard_hook.py +23 -0
  186. higpertext/hooks/hook_tasks/telemetry_utils.py +176 -0
  187. higpertext/hooks/hook_tasks/test_echo_hook.py +33 -0
  188. higpertext/hooks/hook_tasks/webhook_hook.py +54 -0
  189. higpertext/hooks/hook_tasks/workflow_runner_hook.py +49 -0
  190. higpertext/hooks/hooks_catalog.json +116 -0
  191. higpertext/kernel/__init__.py +63 -0
  192. higpertext/kernel/_compat.py +138 -0
  193. higpertext/kernel/app_config.py +117 -0
  194. higpertext/kernel/application/__init__.py +13 -0
  195. higpertext/kernel/application/agent_registry.py +102 -0
  196. higpertext/kernel/application/capability_manager.py +61 -0
  197. higpertext/kernel/application/commit_reporter.py +247 -0
  198. higpertext/kernel/application/context_builder.py +166 -0
  199. higpertext/kernel/application/context_engine.py +409 -0
  200. higpertext/kernel/application/engine.py +41 -0
  201. higpertext/kernel/application/env_runtime.py +174 -0
  202. higpertext/kernel/application/environment_manager.py +154 -0
  203. higpertext/kernel/application/governance.py +192 -0
  204. higpertext/kernel/application/hook_registry.py +102 -0
  205. higpertext/kernel/application/hook_renderer.py +720 -0
  206. higpertext/kernel/application/ports.py +49 -0
  207. higpertext/kernel/application/profile_learner.py +358 -0
  208. higpertext/kernel/application/profile_service.py +205 -0
  209. higpertext/kernel/application/profile_services.py +6 -0
  210. higpertext/kernel/application/profile_use_cases.py +93 -0
  211. higpertext/kernel/application/rag_service.py +75 -0
  212. higpertext/kernel/application/roadmap_reporter.py +178 -0
  213. higpertext/kernel/application/semantic_engine.py +258 -0
  214. higpertext/kernel/application/session_services.py +33 -0
  215. higpertext/kernel/application/skill_hook_compiler.py +85 -0
  216. higpertext/kernel/application/telemetry.py +326 -0
  217. higpertext/kernel/application/workflow_manager.py +176 -0
  218. higpertext/kernel/config_paths.py +66 -0
  219. higpertext/kernel/domain/__init__.py +12 -0
  220. higpertext/kernel/domain/agent_registry.py +23 -0
  221. higpertext/kernel/domain/commit_reporter.py +155 -0
  222. higpertext/kernel/domain/compilers.py +7 -0
  223. higpertext/kernel/domain/context_engine.py +319 -0
  224. higpertext/kernel/domain/entities.py +51 -0
  225. higpertext/kernel/domain/env_runtime.py +62 -0
  226. higpertext/kernel/domain/governance.py +198 -0
  227. higpertext/kernel/domain/hook_models.py +29 -0
  228. higpertext/kernel/domain/profile_learner.py +186 -0
  229. higpertext/kernel/domain/rag.py +70 -0
  230. higpertext/kernel/domain/repositories.py +8 -0
  231. higpertext/kernel/domain/roadmap_reporter.py +80 -0
  232. higpertext/kernel/domain/semantic_engine.py +107 -0
  233. higpertext/kernel/engine.py +42 -0
  234. higpertext/kernel/htx_resolver.py +69 -0
  235. higpertext/kernel/infrastructure/__init__.py +13 -0
  236. higpertext/kernel/infrastructure/agent_registry.py +40 -0
  237. higpertext/kernel/infrastructure/cache/capability_cache.py +319 -0
  238. higpertext/kernel/infrastructure/capability_helper.py +40 -0
  239. higpertext/kernel/infrastructure/cli/__init__.py +1 -0
  240. higpertext/kernel/infrastructure/cli/agent_commands.py +62 -0
  241. higpertext/kernel/infrastructure/cli/arguments.py +39 -0
  242. higpertext/kernel/infrastructure/cli/capability_command_builder.py +86 -0
  243. higpertext/kernel/infrastructure/cli/capability_task_service.py +234 -0
  244. higpertext/kernel/infrastructure/cli/cli_search.py +234 -0
  245. higpertext/kernel/infrastructure/cli/parameter_contracts.py +83 -0
  246. higpertext/kernel/infrastructure/cli/parser_builder.py +122 -0
  247. higpertext/kernel/infrastructure/cli/profile_commands.py +89 -0
  248. higpertext/kernel/infrastructure/cli/roadmap_commands.py +117 -0
  249. higpertext/kernel/infrastructure/cli/router.py +1110 -0
  250. higpertext/kernel/infrastructure/cli/session_commands.py +36 -0
  251. higpertext/kernel/infrastructure/cli/task_commands.py +23 -0
  252. higpertext/kernel/infrastructure/cli/task_result_reporter.py +56 -0
  253. higpertext/kernel/infrastructure/cli/workflow_commands.py +25 -0
  254. higpertext/kernel/infrastructure/compilers/__init__.py +3 -0
  255. higpertext/kernel/infrastructure/compilers/factory.py +27 -0
  256. higpertext/kernel/infrastructure/compilers/graph_compiler.py +20 -0
  257. higpertext/kernel/infrastructure/compilers/guide_compiler.py +50 -0
  258. higpertext/kernel/infrastructure/compilers/hook_compiler.py +69 -0
  259. higpertext/kernel/infrastructure/compilers/playbook_compiler.py +154 -0
  260. higpertext/kernel/infrastructure/context_engine.py +303 -0
  261. higpertext/kernel/infrastructure/database/local_vector_store.py +99 -0
  262. higpertext/kernel/infrastructure/deployment/__init__.py +1 -0
  263. higpertext/kernel/infrastructure/deployment/resource_deployer.py +283 -0
  264. higpertext/kernel/infrastructure/diagnostics/__init__.py +1 -0
  265. higpertext/kernel/infrastructure/diagnostics/health.py +191 -0
  266. higpertext/kernel/infrastructure/env_runtime.py +227 -0
  267. higpertext/kernel/infrastructure/execution/__init__.py +1 -0
  268. higpertext/kernel/infrastructure/execution/parallel.py +188 -0
  269. higpertext/kernel/infrastructure/execution/resilience.py +155 -0
  270. higpertext/kernel/infrastructure/file_repositories.py +213 -0
  271. higpertext/kernel/infrastructure/governance.py +198 -0
  272. higpertext/kernel/infrastructure/hook_config_loader.py +53 -0
  273. higpertext/kernel/infrastructure/hook_webhook_dispatcher.py +61 -0
  274. higpertext/kernel/infrastructure/hook_workflow_bridge.py +60 -0
  275. higpertext/kernel/infrastructure/llm/__init__.py +6 -0
  276. higpertext/kernel/infrastructure/llm/provider.py +46 -0
  277. higpertext/kernel/infrastructure/llm/providers/__init__.py +0 -0
  278. higpertext/kernel/infrastructure/llm/providers/anthropic_provider.py +94 -0
  279. higpertext/kernel/infrastructure/llm/providers/gemini_embeddings.py +74 -0
  280. higpertext/kernel/infrastructure/llm/providers/gemini_provider.py +101 -0
  281. higpertext/kernel/infrastructure/llm/providers/ollama_provider.py +110 -0
  282. higpertext/kernel/infrastructure/llm/providers/openai_provider.py +98 -0
  283. higpertext/kernel/infrastructure/llm/registry.py +81 -0
  284. higpertext/kernel/infrastructure/logger.py +303 -0
  285. higpertext/kernel/infrastructure/output_store.py +70 -0
  286. higpertext/kernel/infrastructure/parser/__init__.py +1 -0
  287. higpertext/kernel/infrastructure/parser/code_chunker.py +144 -0
  288. higpertext/kernel/infrastructure/parser/language/__init__.py +14 -0
  289. higpertext/kernel/infrastructure/parser/language/base.py +41 -0
  290. higpertext/kernel/infrastructure/parser/language/powershell_parser.py +35 -0
  291. higpertext/kernel/infrastructure/parser/language/python_parser.py +98 -0
  292. higpertext/kernel/infrastructure/parser/language/typescript_parser.py +91 -0
  293. higpertext/kernel/infrastructure/parser/semantic_graph.py +409 -0
  294. higpertext/kernel/infrastructure/presentation/__init__.py +1 -0
  295. higpertext/kernel/infrastructure/presentation/html_renderer.py +137 -0
  296. higpertext/kernel/infrastructure/presentation/markdown_renderer.py +84 -0
  297. higpertext/kernel/infrastructure/presentation/markdown_report_renderer.py +97 -0
  298. higpertext/kernel/infrastructure/profile_store.py +28 -0
  299. higpertext/kernel/infrastructure/semantic_engine.py +289 -0
  300. higpertext/kernel/infrastructure/telemetry_reporter.py +132 -0
  301. higpertext/kernel/infrastructure/validation/__init__.py +1 -0
  302. higpertext/kernel/infrastructure/validation/contract_validator.py +163 -0
  303. higpertext/kernel/pkg_resources.py +38 -0
  304. higpertext/kernel/session_manager.py +319 -0
  305. higpertext/templates/env/generic-shell.yaml +21 -0
  306. higpertext/templates/env/node-vitest.yaml +27 -0
  307. higpertext/templates/env/python-pytest.yaml +29 -0
  308. higpertext/templates/html/commit_body.html +20 -0
  309. higpertext/templates/html/commit_diff.html +4 -0
  310. higpertext/templates/html/commit_index.html +29 -0
  311. higpertext/templates/html/commit_layer.html +11 -0
  312. higpertext/templates/html/commit_shell.html +28 -0
  313. higpertext/templates/html/graph_visualize.html +86 -0
  314. higpertext/templates/html/roadmap_body.html +12 -0
  315. higpertext/templates/html/roadmap_phase.html +5 -0
  316. higpertext/templates/html/roadmap_shell.html +29 -0
  317. higpertext/templates/markdown/commit_report.md +18 -0
  318. higpertext/templates/markdown/efficiency_report.md +12 -0
  319. higpertext/templates/markdown/roadmap_report.md +25 -0
  320. higpertext/templates/skills/best-practices.md +7 -0
  321. higpertext/templates/skills/clean-code.md +8 -0
  322. higpertext/templates/skills/ddd-standards.md +7 -0
  323. higpertext/templates/skills/tdd-practices.md +7 -0
  324. higpertext/templates/subagents/architect.md +7 -0
  325. higpertext/templates/subagents/test-engineer.md +7 -0
  326. higpertext/templates/workflows/build.json +23 -0
  327. higpertext/templates/workflows/compact.json +21 -0
  328. higpertext/templates/workflows/plan.json +59 -0
  329. higpertext/templates/workflows/review.json +26 -0
  330. higpertext/templates/workflows/spec.json +27 -0
  331. higpertext_cli-0.8.0.dist-info/METADATA +35 -0
  332. higpertext_cli-0.8.0.dist-info/RECORD +335 -0
  333. higpertext_cli-0.8.0.dist-info/WHEEL +5 -0
  334. higpertext_cli-0.8.0.dist-info/entry_points.txt +2 -0
  335. higpertext_cli-0.8.0.dist-info/top_level.txt +2 -0
@@ -0,0 +1,480 @@
1
+ """higpertext OpenCode Adapter — genera AGENTS.md y definición de agente para opencode.ai."""
2
+
3
+ import json
4
+ from pathlib import Path
5
+ from higpertext.kernel.config_paths import WORKSPACE_DIR_NAME
6
+ from higpertext.adapters.adapter_utils import (
7
+ HTX_CMD,
8
+ HTX_WORKFLOW_CMD,
9
+ load_session,
10
+ guidelines_lines,
11
+ session_lines,
12
+ capabilities_section,
13
+ workflows_section,
14
+ delegation_rule_lines,
15
+ workflow_trigger_lines,
16
+ hooks_section,
17
+ loop_guard_lines,
18
+ reasoning_style_lines,
19
+ project_refs_lines,
20
+ )
21
+ from higpertext.kernel.app_config import ADAPTERS_CONFIG
22
+ _CFG = ADAPTERS_CONFIG["opencode"]
23
+
24
+
25
+ class OpenCodeAdapter:
26
+ """Genera archivos de configuración para OpenCode (opencode.ai).
27
+
28
+ OpenCode lee varias fuentes de instrucciones y configuración:
29
+ - opencode.json — configuración global del proyecto.
30
+ - AGENTS.md en la raíz del proyecto — instrucciones del workspace (auto-inyectadas).
31
+ - .opencode/agents/{workflow}.md — definición del agente por workflow (con frontmatter YAML).
32
+ - .opencode/rules/{name}.md — reglas derivadas del perfil.
33
+ """
34
+
35
+ @staticmethod
36
+ def generate_rules(context: dict, target_dir: Path) -> Path:
37
+ profile = context["profile"]
38
+ agent_name = profile["name"]
39
+ capabilities = context["active_capabilities"]
40
+ workflows = context.get("active_workflows", [])
41
+
42
+ # ── 1. AGENTS.md en la raíz del proyecto (índice liviano) ────────────
43
+ agents_file = target_dir / "AGENTS.md"
44
+ agents_file.write_text(OpenCodeAdapter._agents_md_index(profile), encoding="utf-8")
45
+
46
+ # ── 2. .opencode/rules/{name}.md (perfil como regla) ─────────────────
47
+ opencode_rules_dir = target_dir / ".opencode" / "rules"
48
+ opencode_rules_dir.mkdir(parents=True, exist_ok=True)
49
+ rule_md = OpenCodeAdapter._build_rule_md(profile, capabilities, workflows, target_dir)
50
+ rule_file = opencode_rules_dir / f"{agent_name}.md"
51
+ rule_file.write_text(rule_md, encoding="utf-8")
52
+
53
+ # ── 3. .opencode/agents/{workflow}.md (workflows como agentes) ────────
54
+ opencode_agents_dir = target_dir / ".opencode" / "agents"
55
+ if opencode_agents_dir.exists():
56
+ for f in opencode_agents_dir.glob("*.md"):
57
+ try:
58
+ f.unlink()
59
+ except OSError: # nosec B110
60
+ pass
61
+ opencode_agents_dir.mkdir(parents=True, exist_ok=True)
62
+ playbooks = ("spec", "plan", "build", "review", "testworkflow")
63
+ # Alias: workflows whose id suffix maps to a different output filename
64
+ _alias = {
65
+ "higpertext-plan": "plan",
66
+ "higpertext-build": "build",
67
+ "higpertext-review": "review",
68
+ }
69
+ for wf in workflows:
70
+ wf_name = wf["id"].split(".")[-1]
71
+ out_name = _alias.get(wf_name, wf_name)
72
+ if out_name not in playbooks:
73
+ continue
74
+ wf_agent_md = OpenCodeAdapter._build_workflow_agent_md(wf, profile)
75
+ (opencode_agents_dir / f"{out_name}.md").write_text(wf_agent_md, encoding="utf-8")
76
+
77
+ # ── 4. opencode.json ──────────────────────────────────────────────────
78
+ opencode_json = OpenCodeAdapter._build_opencode_json(profile)
79
+ (target_dir / "opencode.json").write_text(opencode_json, encoding="utf-8")
80
+
81
+ # ── 5. Reglas adicionales de contexto controlado ──────────────────────
82
+ (opencode_rules_dir / "htx-workflow.md").write_text(
83
+ OpenCodeAdapter._build_htx_workflow_rules_md(), encoding="utf-8"
84
+ )
85
+ (opencode_rules_dir / "repository-boundaries.md").write_text(
86
+ OpenCodeAdapter._build_boundary_rules_md(), encoding="utf-8"
87
+ )
88
+
89
+ # ── 6. Eliminar guía obsoleta ─────────────────────────────────────────
90
+ guide_file = target_dir / ".opencode" / "OPENCODE.md"
91
+ if guide_file.exists():
92
+ guide_file.unlink()
93
+
94
+ return rule_file
95
+
96
+ # ── Builders ──────────────────────────────────────────────────────────────
97
+
98
+ @staticmethod
99
+ def _agents_md_index(profile: dict) -> str:
100
+ """Genera AGENTS.md liviano — índice que apunta a .opencode/rules/ como fuente de verdad.
101
+
102
+ OpenCode carga AGENTS.md + .opencode/rules/*.md en el mismo contexto; duplicar el
103
+ contenido completo en ambos infla el contexto ~38KB por sesión sin aportar información
104
+ nueva.
105
+ """
106
+ agent_name = profile["name"]
107
+ return "\n".join(
108
+ [
109
+ line.format(
110
+ agent_name=agent_name,
111
+ agent_name_upper=agent_name.upper(),
112
+ description=profile["description"],
113
+ htx_cmd=HTX_CMD,
114
+ htx_workflow_cmd=HTX_WORKFLOW_CMD,
115
+ )
116
+ for line in _CFG["agents_md_index"]
117
+ ]
118
+ )
119
+
120
+ @staticmethod
121
+ def _build_agents_md(
122
+ profile: dict, capabilities: list, workflows: list, target_dir: Path
123
+ ) -> str:
124
+ """Genera AGENTS.md — instrucciones del workspace que OpenCode inyecta automáticamente."""
125
+ governance = [_CFG["agents_md_governance_header"]]
126
+ for rule in _CFG["agents_md_governance_lines"]:
127
+ governance.append(rule)
128
+ if profile.get("governance_access"):
129
+ governance.append(_CFG["agents_md_governance_enabled"])
130
+
131
+ lines = [
132
+ line.format(
133
+ agent_name=profile["name"],
134
+ agent_name_upper=profile["name"].upper(),
135
+ description=profile["description"],
136
+ system_prompt=profile["system_prompt"],
137
+ )
138
+ for line in _CFG["agents_md_header"]
139
+ ]
140
+ lines += governance + ["", "---", ""]
141
+
142
+ guide_lines = guidelines_lines(Path(__file__))
143
+ if guide_lines:
144
+ lines += ["## Lineamientos activos de gobernanza", ""]
145
+ lines += [
146
+ "Estas reglas son de cumplimiento obligatorio en todo el desarrollo:",
147
+ "",
148
+ ]
149
+ lines += guide_lines
150
+ lines += ["---", ""]
151
+
152
+ lines += loop_guard_lines()
153
+ lines += reasoning_style_lines()
154
+
155
+ exec_lines = [
156
+ line.format(htx_cmd=HTX_CMD)
157
+ for line in _CFG["execution_protocol_lines"]
158
+ ]
159
+ lines += exec_lines
160
+ lines += delegation_rule_lines()
161
+ lines += workflow_trigger_lines(workflows)
162
+
163
+ token_rules = [
164
+ line.format(
165
+ htx_cmd=HTX_CMD,
166
+ htx_workflow_cmd=HTX_WORKFLOW_CMD,
167
+ )
168
+ for line in _CFG["token_rules_lines"]
169
+ ]
170
+ lines += token_rules
171
+
172
+ session = load_session(target_dir)
173
+ lines += session_lines(session, target_dir, ".opencode/skills")
174
+ lines += capabilities_section(capabilities)
175
+ lines += workflows_section(workflows)
176
+ lines.append(
177
+ "*higpertext Engine v5.0 — auto-generated workspace instructions."
178
+ " Do not edit manually.*"
179
+ )
180
+ return "\n".join(lines)
181
+
182
+ @staticmethod
183
+ def _build_rule_md(profile: dict, capabilities: list, workflows: list, target_dir: Path) -> str:
184
+ """Genera .opencode/rules/{name}.md — reglas derivadas del perfil."""
185
+ agent_name = profile["name"]
186
+ higpertext_cmd = "htx"
187
+
188
+ lines = [
189
+ line.format(
190
+ agent_name_upper=agent_name.upper(),
191
+ description=profile["description"],
192
+ system_prompt=profile["system_prompt"],
193
+ )
194
+ for line in _CFG["profile_rules_header"]
195
+ ]
196
+ if profile.get("governance_access"):
197
+ lines.append(_CFG["profile_rules_governance_access"])
198
+
199
+ lines += ["", "---", ""]
200
+ lines += loop_guard_lines()
201
+ lines += reasoning_style_lines()
202
+ lines += project_refs_lines(
203
+ target_dir,
204
+ _CFG["project_refs_header"],
205
+ )
206
+ lines += delegation_rule_lines()
207
+ lines += workflow_trigger_lines(workflows)
208
+
209
+ lines += list(_CFG["token_rules_summary"])
210
+
211
+ session = load_session(target_dir)
212
+ lines += session_lines(session, target_dir, ".opencode/skills")
213
+ lines += hooks_section(target_dir, "opencode", agent_name)
214
+
215
+ lines += ["## Capacidades asignadas", ""]
216
+ for cap in capabilities:
217
+ short_id = cap["id"].split(".")[-1]
218
+ lines.append(f"- **`{cap['id']}`**: {cap['description']}")
219
+ lines.append(f" - Comando: `{higpertext_cmd} task {short_id} [--params]`")
220
+
221
+ if workflows:
222
+ lines += ["", "## Workflows asignados (Playbooks)", ""]
223
+ for wf in workflows:
224
+ short_id = wf["id"].split(".")[-1]
225
+ lines.append(f"- **`{wf['id']}` ({wf['name']})**: {wf['description']}")
226
+ lines.append(f" - Comando: `{higpertext_cmd} workflow run {short_id} [--params]`")
227
+
228
+ lines += [
229
+ "",
230
+ "",
231
+ "> Los contratos técnicos completos y parámetros de cada capacidad y workflow"
232
+ " están en `AGENTS.md`.",
233
+ "",
234
+ "*higpertext Engine v5.0 — auto-generated rule. Do not edit manually.*",
235
+ ]
236
+ return "\n".join(lines)
237
+
238
+ @staticmethod
239
+ def _build_workflow_agent_md(wf: dict, profile: dict) -> str:
240
+ """Genera .opencode/agents/{workflow}.md — definición del agente para un workflow."""
241
+ wf_id = wf["id"]
242
+ wf_name = wf_id.split(".")[-1]
243
+
244
+ lines = [
245
+ line.format(
246
+ wf_name=wf_name,
247
+ wf_name_upper=wf_name.upper(),
248
+ description=wf["description"],
249
+ name=wf["name"],
250
+ wf_id=wf_id,
251
+ htx_workflow_cmd=HTX_WORKFLOW_CMD,
252
+ )
253
+ for line in _CFG["workflow_agent_header"]
254
+ ]
255
+
256
+ if profile.get("model"):
257
+ lines.insert(4, f"model: {profile['model']}")
258
+
259
+ if wf.get("execution_chain"):
260
+ lines += ["## Cadena de Ejecución", ""]
261
+ for step in wf["execution_chain"]:
262
+ lines.append(f"- `Paso {step['step']}`: Ejecuta capacidad `{step['task']}`")
263
+ lines.append("")
264
+
265
+ if wf_name in {"plan", "higpertext-plan"}:
266
+ lines += [
267
+ "## Semantic Graph Check",
268
+ "",
269
+ "- Antes de proponer arquitectura, roadmap o cambios cross-file,"
270
+ " consulta el grafo semántico.",
271
+ "- Usa `htx task common.graph-query --symbol <keyword> --depth 2`"
272
+ " para símbolos relevantes.",
273
+ "- Si `.higpertext/state/semantic_graph.json` no existe, solicita o"
274
+ " ejecuta `htx task common.graph-rebuild` primero.",
275
+ "- Declara en el plan qué símbolos/módulos del grafo delimitan el impacto.",
276
+ "",
277
+ ]
278
+
279
+ if wf.get("parameters"):
280
+ lines += ["## Parámetros", ""]
281
+ for p in wf["parameters"]:
282
+ req = "REQUERIDO" if p.get("required") else "opcional"
283
+ default_str = f" — default: `{p['default']}`" if "default" in p else ""
284
+ lines.append(f"- `--{p['name']}` ({req}): {p['description']}{default_str}")
285
+ lines.append("")
286
+
287
+ lines += [
288
+ "---",
289
+ "",
290
+ "*higpertext Engine v5.0 — auto-generated workflow agent. Do not edit manually.*",
291
+ ]
292
+ return "\n".join(lines)
293
+
294
+ @staticmethod
295
+ def _build_opencode_json(profile: dict) -> str:
296
+ """Genera el archivo opencode.json con la configuración del proyecto."""
297
+ config = {
298
+ "$schema": "https://opencode.ai/config.json",
299
+ "instructions": ["AGENTS.md", ".opencode/rules/*.md"],
300
+ "command": {
301
+ "spec": {
302
+ "description": "Define technical specifications using HTX.",
303
+ "template": "Usa el flujo HTX de especificación. Llama a higpertext_workflow"
304
+ " con name='spec'. No hagas exploración manual masiva; identifica primero"
305
+ " los archivos mínimos necesarios.",
306
+ },
307
+ "plan": {
308
+ "description": "Design architecture and execution plans using HTX.",
309
+ "template": "Usa el flujo HTX de planeación. Llama a higpertext_workflow"
310
+ " con name='plan'. No modifiques código; entrega plan, riesgos y archivos"
311
+ " probables.",
312
+ },
313
+ "build": {
314
+ "description": "Implement code using HTX.",
315
+ "template": "Usa el flujo HTX de implementación."
316
+ " Llama a higpertext_workflow con name='build'."
317
+ " Haz cambios mínimos y muestra diff/resumen al final.",
318
+ },
319
+ "review": {
320
+ "description": "Review quality and compliance using HTX.",
321
+ "template": "Usa el flujo HTX de revisión."
322
+ " Llama a higpertext_workflow con name='review'."
323
+ " No modifiques código salvo autorización explícita.",
324
+ },
325
+ },
326
+ "skills": {"paths": [".opencode/skills"]},
327
+ "plugin": ["./.opencode/plugin/higpertext-hooks.js"],
328
+ "permission": {
329
+ "bash": {"./.venv/bin/htx *": "allow", "*": "ask"},
330
+ "read": {
331
+ "./.opencode/**": "allow",
332
+ "./{WORKSPACE_DIR_NAME}/**": "allow",
333
+ "./AGENTS.md": "allow",
334
+ "./opencode.json": "allow",
335
+ "./src/**": "ask",
336
+ "*": "deny",
337
+ },
338
+ "edit": "ask",
339
+ "glob": "deny",
340
+ "grep": "deny",
341
+ "task": "deny",
342
+ "external_directory": "ask",
343
+ "webfetch": "deny",
344
+ "websearch": "deny",
345
+ "question": "allow",
346
+ "todowrite": "allow",
347
+ "higpertext_task": "allow",
348
+ "higpertext_workflow": "allow",
349
+ },
350
+ "logLevel": "ERROR",
351
+ "tool_output": {"max_lines": 120, "max_bytes": 8000},
352
+ "compaction": {"auto": True, "tail_turns": 8},
353
+ }
354
+ if profile.get("model"):
355
+ config["model"] = profile["model"]
356
+ return json.dumps(config, indent=2)
357
+
358
+ @staticmethod
359
+ def _build_htx_workflow_rules_md() -> str:
360
+ return "\n".join(
361
+ [
362
+ "# HTX Workflow Rules",
363
+ "",
364
+ "Para tareas de especificación, planeación, implementación y revisión,"
365
+ " usa el flujo HTX como fuente principal de decisión.",
366
+ "",
367
+ "## Comandos principales",
368
+ "",
369
+ "- Spec: `higpertext_workflow` con `name='spec'`",
370
+ "- Plan: `higpertext_workflow` con `name='plan'`",
371
+ "- Build: `higpertext_workflow` con `name='build'`",
372
+ "- Review: `higpertext_workflow` con `name='review'`",
373
+ "",
374
+ "## Reglas",
375
+ "",
376
+ "1. No reemplaces el flujo HTX con exploración manual del repositorio.",
377
+ "2. Antes de leer muchos archivos, explica qué necesitas revisar.",
378
+ "3. En este workspace, invoca HTX con `./.venv/bin/htx`; no uses `htx` sin ruta.",
379
+ "4. Para búsqueda, diff, tests, calidad, memoria o tareas con capacidad asignada,"
380
+ " usa `./.venv/bin/htx task <capability>`.",
381
+ "5. No uses `ls`, `grep`, `glob`, `find`, `rg`, `git diff/status`"
382
+ " ni búsquedas nativas si existe capacidad HTX equivalente.",
383
+ "6. Si una capacidad HTX falla por PATH o entorno, no hagas fallback"
384
+ " a herramientas generales; corrige el launcher o pregunta.",
385
+ "7. Usa `read` solo para archivos explícitos y directamente relacionados;"
386
+ " no lo uses como mecanismo de búsqueda.",
387
+ "8. No uses subagentes salvo autorización explícita.",
388
+ "9. No ejecutes comandos bash largos sin aprobación.",
389
+ "10. No uses búsquedas web salvo que el usuario lo pida.",
390
+ "11. Antes de modificar código, presenta un plan breve.",
391
+ "12. Después de modificar código, muestra resumen de cambios.",
392
+ "",
393
+ "*higpertext Engine v5.0 — auto-generated. Do not edit manually.*",
394
+ ]
395
+ )
396
+
397
+ @staticmethod
398
+ def _build_boundary_rules_md() -> str:
399
+ excluded = [
400
+ "node_modules/",
401
+ "dist/",
402
+ "build/",
403
+ "coverage/",
404
+ ".next/",
405
+ ".nuxt/",
406
+ ".turbo/",
407
+ ".cache/",
408
+ "logs/",
409
+ "tmp/",
410
+ ".git/",
411
+ "vendor/",
412
+ "target/",
413
+ "__pycache__/",
414
+ ".venv/",
415
+ "venv/",
416
+ ]
417
+ preferred = [
418
+ "package.json",
419
+ "pyproject.toml",
420
+ "README.md",
421
+ "AGENTS.md",
422
+ "opencode.json",
423
+ ".opencode/rules/*.md",
424
+ ".opencode/plugin/*.js",
425
+ "archivos de configuración relacionados con la tarea",
426
+ ]
427
+ excl_lines = "\n".join(f"- `{d}`" for d in excluded)
428
+ pref_lines = "\n".join(f"- `{f}`" for f in preferred)
429
+ return "\n".join(
430
+ [
431
+ "# Repository Boundaries",
432
+ "",
433
+ "No leer ni indexar de forma masiva los siguientes directorios:",
434
+ "",
435
+ excl_lines,
436
+ "",
437
+ "## Archivos preferidos para contexto inicial",
438
+ "",
439
+ pref_lines,
440
+ "",
441
+ "Si necesitas explorar más, pide autorización y explica por qué.",
442
+ "",
443
+ "*higpertext Engine v5.0 — auto-generated. Do not edit manually.*",
444
+ ]
445
+ )
446
+
447
+ @staticmethod
448
+ def on_init(context: dict, target_dir: Path) -> None:
449
+ """Gancho de inicialización de proyecto para OpenCode."""
450
+ profile = context["profile"]
451
+ opencode_json = OpenCodeAdapter._build_opencode_json(profile)
452
+ (target_dir / "opencode.json").write_text(opencode_json, encoding="utf-8")
453
+
454
+ @staticmethod
455
+ def on_session_start(context: dict, target_dir: Path) -> None:
456
+ """Gancho de inicio de sesión para OpenCode."""
457
+ OpenCodeAdapter.generate_rules(context, target_dir)
458
+
459
+ @staticmethod
460
+ def on_session_clean(target_dir: Path) -> None:
461
+ """Gancho de limpieza de sesión para OpenCode."""
462
+ rules_dir = target_dir / ".opencode" / "rules"
463
+ if rules_dir.exists():
464
+ try:
465
+ import shutil
466
+
467
+ shutil.rmtree(rules_dir)
468
+ except OSError: # nosec B110
469
+ pass
470
+
471
+ agents_dir = target_dir / ".opencode" / "agents"
472
+ if agents_dir.exists():
473
+ # Standard playbooks to preserve
474
+ playbooks = ("spec", "plan", "build", "review")
475
+ for f in agents_dir.glob("*.md"):
476
+ if f.stem not in playbooks:
477
+ try:
478
+ f.unlink()
479
+ except OSError: # nosec B110
480
+ pass