@jaguilar87/gaia-ops 4.4.0 → 4.7.2

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 (371) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +12 -3
  3. package/ARCHITECTURE.md +9 -8
  4. package/CHANGELOG.md +34 -0
  5. package/README.md +43 -11
  6. package/agents/terraform-architect.md +1 -1
  7. package/bin/README.md +2 -2
  8. package/bin/gaia-doctor.js +18 -5
  9. package/bin/gaia-history.js +0 -1
  10. package/bin/gaia-metrics.js +2 -2
  11. package/bin/gaia-scan.py +23 -1
  12. package/bin/gaia-update.js +346 -54
  13. package/bin/pre-publish-validate.js +33 -10
  14. package/commands/gaia.md +37 -0
  15. package/config/README.md +3 -9
  16. package/config/context-contracts.json +47 -15
  17. package/config/surface-routing.json +9 -1
  18. package/dist/gaia-ops/.claude-plugin/plugin.json +22 -0
  19. package/dist/gaia-ops/agents/cloud-troubleshooter.md +73 -0
  20. package/dist/gaia-ops/agents/devops-developer.md +57 -0
  21. package/dist/gaia-ops/agents/gaia-system.md +58 -0
  22. package/dist/gaia-ops/agents/gitops-operator.md +60 -0
  23. package/dist/gaia-ops/agents/speckit-planner.md +71 -0
  24. package/dist/gaia-ops/agents/terraform-architect.md +60 -0
  25. package/dist/gaia-ops/commands/gaia.md +37 -0
  26. package/dist/gaia-ops/config/README.md +58 -0
  27. package/dist/gaia-ops/config/cloud/aws.json +140 -0
  28. package/dist/gaia-ops/config/cloud/gcp.json +145 -0
  29. package/dist/gaia-ops/config/context-contracts.json +131 -0
  30. package/dist/gaia-ops/config/git_standards.json +72 -0
  31. package/dist/gaia-ops/config/surface-routing.json +197 -0
  32. package/dist/gaia-ops/config/universal-rules.json +10 -0
  33. package/dist/gaia-ops/hooks/adapters/__init__.py +52 -0
  34. package/dist/gaia-ops/hooks/adapters/base.py +219 -0
  35. package/dist/gaia-ops/hooks/adapters/channel.py +17 -0
  36. package/dist/gaia-ops/hooks/adapters/claude_code.py +1477 -0
  37. package/dist/gaia-ops/hooks/adapters/types.py +194 -0
  38. package/dist/gaia-ops/hooks/adapters/utils.py +25 -0
  39. package/dist/gaia-ops/hooks/hooks.json +126 -0
  40. package/dist/gaia-ops/hooks/modules/__init__.py +15 -0
  41. package/dist/gaia-ops/hooks/modules/agents/__init__.py +29 -0
  42. package/dist/gaia-ops/hooks/modules/agents/contract_validator.py +647 -0
  43. package/dist/gaia-ops/hooks/modules/agents/response_contract.py +496 -0
  44. package/dist/gaia-ops/hooks/modules/agents/skill_injection_verifier.py +124 -0
  45. package/dist/gaia-ops/hooks/modules/agents/task_info_builder.py +74 -0
  46. package/dist/gaia-ops/hooks/modules/agents/transcript_analyzer.py +458 -0
  47. package/dist/gaia-ops/hooks/modules/agents/transcript_reader.py +152 -0
  48. package/dist/gaia-ops/hooks/modules/audit/__init__.py +28 -0
  49. package/dist/gaia-ops/hooks/modules/audit/event_detector.py +168 -0
  50. package/dist/gaia-ops/hooks/modules/audit/logger.py +131 -0
  51. package/dist/gaia-ops/hooks/modules/audit/metrics.py +134 -0
  52. package/dist/gaia-ops/hooks/modules/audit/workflow_auditor.py +576 -0
  53. package/dist/gaia-ops/hooks/modules/audit/workflow_recorder.py +296 -0
  54. package/dist/gaia-ops/hooks/modules/context/__init__.py +11 -0
  55. package/dist/gaia-ops/hooks/modules/context/anchor_tracker.py +317 -0
  56. package/dist/gaia-ops/hooks/modules/context/compact_context_builder.py +215 -0
  57. package/dist/gaia-ops/hooks/modules/context/context_cache.py +129 -0
  58. package/dist/gaia-ops/hooks/modules/context/context_freshness.py +145 -0
  59. package/dist/gaia-ops/hooks/modules/context/context_injector.py +427 -0
  60. package/dist/gaia-ops/hooks/modules/context/context_writer.py +518 -0
  61. package/dist/gaia-ops/hooks/modules/context/contracts_loader.py +161 -0
  62. package/dist/gaia-ops/hooks/modules/core/__init__.py +40 -0
  63. package/dist/gaia-ops/hooks/modules/core/hook_entry.py +78 -0
  64. package/dist/gaia-ops/hooks/modules/core/paths.py +160 -0
  65. package/dist/gaia-ops/hooks/modules/core/plugin_mode.py +149 -0
  66. package/dist/gaia-ops/hooks/modules/core/plugin_setup.py +558 -0
  67. package/dist/gaia-ops/hooks/modules/core/state.py +179 -0
  68. package/dist/gaia-ops/hooks/modules/core/stdin.py +24 -0
  69. package/dist/gaia-ops/hooks/modules/events/__init__.py +1 -0
  70. package/dist/gaia-ops/hooks/modules/events/event_writer.py +210 -0
  71. package/dist/gaia-ops/hooks/modules/identity/__init__.py +0 -0
  72. package/dist/gaia-ops/hooks/modules/identity/identity_provider.py +21 -0
  73. package/dist/gaia-ops/hooks/modules/identity/ops_identity.py +34 -0
  74. package/dist/gaia-ops/hooks/modules/identity/security_identity.py +10 -0
  75. package/dist/gaia-ops/hooks/modules/memory/__init__.py +8 -0
  76. package/dist/gaia-ops/hooks/modules/memory/episode_writer.py +227 -0
  77. package/dist/gaia-ops/hooks/modules/orchestrator/__init__.py +1 -0
  78. package/dist/gaia-ops/hooks/modules/orchestrator/delegate_mode.py +128 -0
  79. package/dist/gaia-ops/hooks/modules/scanning/__init__.py +8 -0
  80. package/dist/gaia-ops/hooks/modules/scanning/scan_trigger.py +84 -0
  81. package/dist/gaia-ops/hooks/modules/security/__init__.py +89 -0
  82. package/dist/gaia-ops/hooks/modules/security/approval_cleanup.py +87 -0
  83. package/dist/gaia-ops/hooks/modules/security/approval_constants.py +23 -0
  84. package/dist/gaia-ops/hooks/modules/security/approval_grants.py +912 -0
  85. package/dist/gaia-ops/hooks/modules/security/approval_messages.py +71 -0
  86. package/dist/gaia-ops/hooks/modules/security/approval_scopes.py +153 -0
  87. package/dist/gaia-ops/hooks/modules/security/blocked_commands.py +584 -0
  88. package/dist/gaia-ops/hooks/modules/security/blocked_message_formatter.py +86 -0
  89. package/dist/gaia-ops/hooks/modules/security/command_semantics.py +130 -0
  90. package/dist/gaia-ops/hooks/modules/security/gitops_validator.py +179 -0
  91. package/dist/gaia-ops/hooks/modules/security/mutative_verbs.py +850 -0
  92. package/dist/gaia-ops/hooks/modules/security/prompt_validator.py +40 -0
  93. package/dist/gaia-ops/hooks/modules/security/tiers.py +196 -0
  94. package/dist/gaia-ops/hooks/modules/session/__init__.py +10 -0
  95. package/dist/gaia-ops/hooks/modules/session/session_context_writer.py +100 -0
  96. package/dist/gaia-ops/hooks/modules/session/session_event_injector.py +158 -0
  97. package/dist/gaia-ops/hooks/modules/session/session_manager.py +31 -0
  98. package/dist/gaia-ops/hooks/modules/tools/__init__.py +25 -0
  99. package/dist/gaia-ops/hooks/modules/tools/bash_validator.py +708 -0
  100. package/dist/gaia-ops/hooks/modules/tools/cloud_pipe_validator.py +181 -0
  101. package/dist/gaia-ops/hooks/modules/tools/hook_response.py +55 -0
  102. package/dist/gaia-ops/hooks/modules/tools/shell_parser.py +227 -0
  103. package/dist/gaia-ops/hooks/modules/tools/task_validator.py +283 -0
  104. package/dist/gaia-ops/hooks/modules/validation/__init__.py +23 -0
  105. package/dist/gaia-ops/hooks/modules/validation/commit_validator.py +380 -0
  106. package/dist/gaia-ops/hooks/post_compact.py +43 -0
  107. package/dist/gaia-ops/hooks/post_tool_use.py +54 -0
  108. package/dist/gaia-ops/hooks/pre_tool_use.py +383 -0
  109. package/dist/gaia-ops/hooks/session_start.py +69 -0
  110. package/dist/gaia-ops/hooks/stop_hook.py +69 -0
  111. package/dist/gaia-ops/hooks/subagent_start.py +71 -0
  112. package/dist/gaia-ops/hooks/subagent_stop.py +288 -0
  113. package/dist/gaia-ops/hooks/task_completed.py +70 -0
  114. package/dist/gaia-ops/hooks/user_prompt_submit.py +177 -0
  115. package/dist/gaia-ops/settings.json +72 -0
  116. package/dist/gaia-ops/skills/README.md +109 -0
  117. package/dist/gaia-ops/skills/agent-protocol/SKILL.md +105 -0
  118. package/dist/gaia-ops/skills/agent-protocol/examples.md +170 -0
  119. package/dist/gaia-ops/skills/agent-response/SKILL.md +53 -0
  120. package/dist/gaia-ops/skills/approval/SKILL.md +85 -0
  121. package/dist/gaia-ops/skills/approval/examples.md +140 -0
  122. package/dist/gaia-ops/skills/approval/reference.md +57 -0
  123. package/dist/gaia-ops/skills/command-execution/SKILL.md +64 -0
  124. package/dist/gaia-ops/skills/command-execution/reference.md +83 -0
  125. package/dist/gaia-ops/skills/context-updater/SKILL.md +76 -0
  126. package/dist/gaia-ops/skills/context-updater/examples.md +71 -0
  127. package/dist/gaia-ops/skills/developer-patterns/SKILL.md +93 -0
  128. package/dist/gaia-ops/skills/developer-patterns/reference.md +112 -0
  129. package/dist/gaia-ops/skills/execution/SKILL.md +66 -0
  130. package/dist/gaia-ops/skills/fast-queries/SKILL.md +47 -0
  131. package/dist/gaia-ops/skills/gaia-patterns/SKILL.md +92 -0
  132. package/dist/gaia-ops/skills/gaia-patterns/reference.md +22 -0
  133. package/dist/gaia-ops/skills/git-conventions/SKILL.md +48 -0
  134. package/dist/gaia-ops/skills/gitops-patterns/SKILL.md +73 -0
  135. package/dist/gaia-ops/skills/gitops-patterns/reference.md +183 -0
  136. package/dist/gaia-ops/skills/investigation/SKILL.md +77 -0
  137. package/dist/gaia-ops/skills/orchestrator-approval/SKILL.md +64 -0
  138. package/dist/gaia-ops/skills/reference.md +134 -0
  139. package/dist/gaia-ops/skills/security-tiers/SKILL.md +61 -0
  140. package/dist/gaia-ops/skills/security-tiers/destructive-commands-reference.md +623 -0
  141. package/dist/gaia-ops/skills/security-tiers/reference.md +39 -0
  142. package/dist/gaia-ops/skills/skill-creation/SKILL.md +119 -0
  143. package/dist/gaia-ops/skills/specification/SKILL.md +186 -0
  144. package/dist/gaia-ops/skills/speckit-workflow/SKILL.md +165 -0
  145. package/dist/gaia-ops/skills/speckit-workflow/reference.md +117 -0
  146. package/dist/gaia-ops/skills/terraform-patterns/SKILL.md +63 -0
  147. package/dist/gaia-ops/skills/terraform-patterns/reference.md +93 -0
  148. package/dist/gaia-ops/speckit/README.md +516 -0
  149. package/dist/gaia-ops/speckit/scripts/.gitkeep +0 -0
  150. package/dist/gaia-ops/speckit/templates/adr-template.md +118 -0
  151. package/dist/gaia-ops/speckit/templates/agent-file-template.md +23 -0
  152. package/dist/gaia-ops/speckit/templates/plan-template.md +227 -0
  153. package/dist/gaia-ops/speckit/templates/spec-template.md +140 -0
  154. package/dist/gaia-ops/speckit/templates/tasks-template.md +257 -0
  155. package/dist/gaia-ops/tools/context/README.md +132 -0
  156. package/dist/gaia-ops/tools/context/__init__.py +42 -0
  157. package/dist/gaia-ops/tools/context/_paths.py +20 -0
  158. package/dist/gaia-ops/tools/context/context_provider.py +476 -0
  159. package/dist/gaia-ops/tools/context/context_section_reader.py +330 -0
  160. package/dist/gaia-ops/tools/context/deep_merge.py +159 -0
  161. package/dist/gaia-ops/tools/context/pending_updates.py +760 -0
  162. package/dist/gaia-ops/tools/context/surface_router.py +278 -0
  163. package/dist/gaia-ops/tools/fast-queries/README.md +65 -0
  164. package/dist/gaia-ops/tools/fast-queries/__init__.py +30 -0
  165. package/dist/gaia-ops/tools/fast-queries/appservices/quicktriage_devops_developer.sh +75 -0
  166. package/dist/gaia-ops/tools/fast-queries/cloud/aws/quicktriage_aws_troubleshooter.sh +32 -0
  167. package/dist/gaia-ops/tools/fast-queries/cloud/gcp/quicktriage_gcp_troubleshooter.sh +88 -0
  168. package/dist/gaia-ops/tools/fast-queries/gitops/quicktriage_gitops_operator.sh +48 -0
  169. package/dist/gaia-ops/tools/fast-queries/run_triage.sh +59 -0
  170. package/dist/gaia-ops/tools/fast-queries/terraform/quicktriage_terraform_architect.sh +80 -0
  171. package/dist/gaia-ops/tools/gaia_simulator/__init__.py +33 -0
  172. package/dist/gaia-ops/tools/gaia_simulator/cli.py +354 -0
  173. package/dist/gaia-ops/tools/gaia_simulator/extractor.py +457 -0
  174. package/dist/gaia-ops/tools/gaia_simulator/reporter.py +258 -0
  175. package/dist/gaia-ops/tools/gaia_simulator/routing_simulator.py +334 -0
  176. package/dist/gaia-ops/tools/gaia_simulator/runner.py +539 -0
  177. package/dist/gaia-ops/tools/gaia_simulator/skills_mapper.py +262 -0
  178. package/dist/gaia-ops/tools/memory/README.md +0 -0
  179. package/dist/gaia-ops/tools/memory/__init__.py +20 -0
  180. package/dist/gaia-ops/tools/memory/episodic.py +1196 -0
  181. package/dist/gaia-ops/tools/persist_transcript_analysis.py +85 -0
  182. package/dist/gaia-ops/tools/review/__init__.py +1 -0
  183. package/dist/gaia-ops/tools/review/review_engine.py +157 -0
  184. package/dist/gaia-ops/tools/scan/__init__.py +35 -0
  185. package/dist/gaia-ops/tools/scan/config.py +247 -0
  186. package/dist/gaia-ops/tools/scan/merge.py +212 -0
  187. package/dist/gaia-ops/tools/scan/orchestrator.py +549 -0
  188. package/dist/gaia-ops/tools/scan/registry.py +127 -0
  189. package/dist/gaia-ops/tools/scan/scanners/__init__.py +18 -0
  190. package/dist/gaia-ops/tools/scan/scanners/base.py +137 -0
  191. package/dist/gaia-ops/tools/scan/scanners/environment.py +324 -0
  192. package/dist/gaia-ops/tools/scan/scanners/git.py +570 -0
  193. package/dist/gaia-ops/tools/scan/scanners/infrastructure.py +875 -0
  194. package/dist/gaia-ops/tools/scan/scanners/orchestration.py +600 -0
  195. package/dist/gaia-ops/tools/scan/scanners/stack.py +1085 -0
  196. package/dist/gaia-ops/tools/scan/scanners/tools.py +260 -0
  197. package/dist/gaia-ops/tools/scan/setup.py +753 -0
  198. package/dist/gaia-ops/tools/scan/tests/__init__.py +1 -0
  199. package/dist/gaia-ops/tools/scan/tests/conftest.py +796 -0
  200. package/dist/gaia-ops/tools/scan/tests/test_environment.py +323 -0
  201. package/dist/gaia-ops/tools/scan/tests/test_git.py +419 -0
  202. package/dist/gaia-ops/tools/scan/tests/test_infrastructure.py +382 -0
  203. package/dist/gaia-ops/tools/scan/tests/test_integration.py +920 -0
  204. package/dist/gaia-ops/tools/scan/tests/test_merge.py +269 -0
  205. package/dist/gaia-ops/tools/scan/tests/test_orchestration.py +304 -0
  206. package/dist/gaia-ops/tools/scan/tests/test_stack.py +604 -0
  207. package/dist/gaia-ops/tools/scan/tests/test_tools.py +349 -0
  208. package/dist/gaia-ops/tools/scan/ui.py +624 -0
  209. package/dist/gaia-ops/tools/scan/verify.py +266 -0
  210. package/dist/gaia-ops/tools/scan/walk.py +118 -0
  211. package/dist/gaia-ops/tools/scan/workspace.py +85 -0
  212. package/dist/gaia-ops/tools/validation/README.md +244 -0
  213. package/dist/gaia-ops/tools/validation/__init__.py +17 -0
  214. package/dist/gaia-ops/tools/validation/approval_gate.py +321 -0
  215. package/dist/gaia-ops/tools/validation/validate_skills.py +189 -0
  216. package/dist/gaia-security/.claude-plugin/plugin.json +22 -0
  217. package/dist/gaia-security/config/universal-rules.json +10 -0
  218. package/dist/gaia-security/hooks/adapters/__init__.py +52 -0
  219. package/dist/gaia-security/hooks/adapters/base.py +219 -0
  220. package/dist/gaia-security/hooks/adapters/channel.py +17 -0
  221. package/dist/gaia-security/hooks/adapters/claude_code.py +1477 -0
  222. package/dist/gaia-security/hooks/adapters/types.py +194 -0
  223. package/dist/gaia-security/hooks/adapters/utils.py +25 -0
  224. package/dist/gaia-security/hooks/hooks.json +57 -0
  225. package/dist/gaia-security/hooks/modules/__init__.py +15 -0
  226. package/dist/gaia-security/hooks/modules/agents/__init__.py +29 -0
  227. package/dist/gaia-security/hooks/modules/agents/contract_validator.py +647 -0
  228. package/dist/gaia-security/hooks/modules/agents/response_contract.py +496 -0
  229. package/dist/gaia-security/hooks/modules/agents/skill_injection_verifier.py +124 -0
  230. package/dist/gaia-security/hooks/modules/agents/task_info_builder.py +74 -0
  231. package/dist/gaia-security/hooks/modules/agents/transcript_analyzer.py +458 -0
  232. package/dist/gaia-security/hooks/modules/agents/transcript_reader.py +152 -0
  233. package/dist/gaia-security/hooks/modules/audit/__init__.py +28 -0
  234. package/dist/gaia-security/hooks/modules/audit/event_detector.py +168 -0
  235. package/dist/gaia-security/hooks/modules/audit/logger.py +131 -0
  236. package/dist/gaia-security/hooks/modules/audit/metrics.py +134 -0
  237. package/dist/gaia-security/hooks/modules/audit/workflow_auditor.py +576 -0
  238. package/dist/gaia-security/hooks/modules/audit/workflow_recorder.py +296 -0
  239. package/dist/gaia-security/hooks/modules/context/__init__.py +11 -0
  240. package/dist/gaia-security/hooks/modules/context/anchor_tracker.py +317 -0
  241. package/dist/gaia-security/hooks/modules/context/compact_context_builder.py +215 -0
  242. package/dist/gaia-security/hooks/modules/context/context_cache.py +129 -0
  243. package/dist/gaia-security/hooks/modules/context/context_freshness.py +145 -0
  244. package/dist/gaia-security/hooks/modules/context/context_injector.py +427 -0
  245. package/dist/gaia-security/hooks/modules/context/context_writer.py +518 -0
  246. package/dist/gaia-security/hooks/modules/context/contracts_loader.py +161 -0
  247. package/dist/gaia-security/hooks/modules/core/__init__.py +40 -0
  248. package/dist/gaia-security/hooks/modules/core/hook_entry.py +78 -0
  249. package/dist/gaia-security/hooks/modules/core/paths.py +160 -0
  250. package/dist/gaia-security/hooks/modules/core/plugin_mode.py +149 -0
  251. package/dist/gaia-security/hooks/modules/core/plugin_setup.py +558 -0
  252. package/dist/gaia-security/hooks/modules/core/state.py +179 -0
  253. package/dist/gaia-security/hooks/modules/core/stdin.py +24 -0
  254. package/dist/gaia-security/hooks/modules/events/__init__.py +1 -0
  255. package/dist/gaia-security/hooks/modules/events/event_writer.py +210 -0
  256. package/dist/gaia-security/hooks/modules/identity/__init__.py +0 -0
  257. package/dist/gaia-security/hooks/modules/identity/identity_provider.py +21 -0
  258. package/dist/gaia-security/hooks/modules/identity/ops_identity.py +34 -0
  259. package/dist/gaia-security/hooks/modules/identity/security_identity.py +10 -0
  260. package/dist/gaia-security/hooks/modules/memory/__init__.py +8 -0
  261. package/dist/gaia-security/hooks/modules/memory/episode_writer.py +227 -0
  262. package/dist/gaia-security/hooks/modules/orchestrator/__init__.py +1 -0
  263. package/dist/gaia-security/hooks/modules/orchestrator/delegate_mode.py +128 -0
  264. package/dist/gaia-security/hooks/modules/scanning/__init__.py +8 -0
  265. package/dist/gaia-security/hooks/modules/scanning/scan_trigger.py +84 -0
  266. package/dist/gaia-security/hooks/modules/security/__init__.py +89 -0
  267. package/dist/gaia-security/hooks/modules/security/approval_cleanup.py +87 -0
  268. package/dist/gaia-security/hooks/modules/security/approval_constants.py +23 -0
  269. package/dist/gaia-security/hooks/modules/security/approval_grants.py +912 -0
  270. package/dist/gaia-security/hooks/modules/security/approval_messages.py +71 -0
  271. package/dist/gaia-security/hooks/modules/security/approval_scopes.py +153 -0
  272. package/dist/gaia-security/hooks/modules/security/blocked_commands.py +584 -0
  273. package/dist/gaia-security/hooks/modules/security/blocked_message_formatter.py +86 -0
  274. package/dist/gaia-security/hooks/modules/security/command_semantics.py +130 -0
  275. package/dist/gaia-security/hooks/modules/security/gitops_validator.py +179 -0
  276. package/dist/gaia-security/hooks/modules/security/mutative_verbs.py +850 -0
  277. package/dist/gaia-security/hooks/modules/security/prompt_validator.py +40 -0
  278. package/dist/gaia-security/hooks/modules/security/tiers.py +196 -0
  279. package/dist/gaia-security/hooks/modules/session/__init__.py +10 -0
  280. package/dist/gaia-security/hooks/modules/session/session_context_writer.py +100 -0
  281. package/dist/gaia-security/hooks/modules/session/session_event_injector.py +158 -0
  282. package/dist/gaia-security/hooks/modules/session/session_manager.py +31 -0
  283. package/dist/gaia-security/hooks/modules/tools/__init__.py +25 -0
  284. package/dist/gaia-security/hooks/modules/tools/bash_validator.py +708 -0
  285. package/dist/gaia-security/hooks/modules/tools/cloud_pipe_validator.py +181 -0
  286. package/dist/gaia-security/hooks/modules/tools/hook_response.py +55 -0
  287. package/dist/gaia-security/hooks/modules/tools/shell_parser.py +227 -0
  288. package/dist/gaia-security/hooks/modules/tools/task_validator.py +283 -0
  289. package/dist/gaia-security/hooks/modules/validation/__init__.py +23 -0
  290. package/dist/gaia-security/hooks/modules/validation/commit_validator.py +380 -0
  291. package/dist/gaia-security/hooks/post_tool_use.py +54 -0
  292. package/dist/gaia-security/hooks/pre_tool_use.py +383 -0
  293. package/dist/gaia-security/hooks/session_start.py +69 -0
  294. package/dist/gaia-security/hooks/stop_hook.py +69 -0
  295. package/dist/gaia-security/hooks/user_prompt_submit.py +177 -0
  296. package/dist/gaia-security/settings.json +58 -0
  297. package/git-hooks/commit-msg +41 -0
  298. package/hooks/README.md +8 -6
  299. package/hooks/adapters/channel.py +0 -25
  300. package/hooks/adapters/claude_code.py +364 -125
  301. package/hooks/elicitation_result.py +132 -0
  302. package/hooks/hooks.json +10 -1
  303. package/hooks/modules/README.md +3 -2
  304. package/hooks/modules/agents/contract_validator.py +3 -51
  305. package/hooks/modules/agents/response_contract.py +4 -8
  306. package/hooks/modules/agents/transcript_reader.py +4 -5
  307. package/hooks/modules/audit/__init__.py +4 -6
  308. package/hooks/modules/audit/event_detector.py +0 -2
  309. package/hooks/modules/audit/metrics.py +108 -187
  310. package/hooks/modules/audit/workflow_auditor.py +0 -4
  311. package/hooks/modules/audit/workflow_recorder.py +0 -5
  312. package/hooks/modules/context/compact_context_builder.py +1 -0
  313. package/hooks/modules/context/context_cache.py +129 -0
  314. package/hooks/modules/context/context_injector.py +18 -40
  315. package/hooks/modules/context/context_writer.py +1 -25
  316. package/hooks/modules/context/contracts_loader.py +7 -10
  317. package/hooks/modules/core/hook_entry.py +1 -0
  318. package/hooks/modules/core/paths.py +12 -13
  319. package/hooks/modules/core/plugin_mode.py +74 -4
  320. package/hooks/modules/core/plugin_setup.py +395 -23
  321. package/hooks/modules/events/__init__.py +1 -0
  322. package/hooks/modules/events/event_writer.py +210 -0
  323. package/hooks/modules/identity/ops_identity.py +18 -27
  324. package/hooks/modules/memory/episode_writer.py +1 -6
  325. package/hooks/modules/orchestrator/__init__.py +1 -0
  326. package/hooks/modules/orchestrator/delegate_mode.py +128 -0
  327. package/hooks/modules/security/__init__.py +2 -4
  328. package/hooks/modules/security/approval_constants.py +5 -1
  329. package/hooks/modules/security/approval_grants.py +189 -6
  330. package/hooks/modules/security/approval_messages.py +9 -21
  331. package/hooks/modules/security/blocked_commands.py +98 -34
  332. package/hooks/modules/security/command_semantics.py +0 -4
  333. package/hooks/modules/security/gitops_validator.py +1 -11
  334. package/hooks/modules/security/mutative_verbs.py +179 -38
  335. package/hooks/modules/security/tiers.py +1 -19
  336. package/hooks/modules/session/session_event_injector.py +1 -25
  337. package/hooks/modules/tools/bash_validator.py +310 -94
  338. package/hooks/modules/tools/shell_parser.py +0 -1
  339. package/hooks/modules/tools/task_validator.py +9 -29
  340. package/hooks/post_tool_use.py +0 -72
  341. package/hooks/pre_tool_use.py +42 -102
  342. package/hooks/session_start.py +4 -2
  343. package/hooks/subagent_start.py +6 -2
  344. package/hooks/subagent_stop.py +1 -13
  345. package/hooks/user_prompt_submit.py +119 -37
  346. package/index.js +1 -1
  347. package/package.json +5 -3
  348. package/skills/README.md +3 -5
  349. package/skills/agent-protocol/SKILL.md +17 -16
  350. package/skills/agent-protocol/examples.md +6 -6
  351. package/skills/agent-response/SKILL.md +11 -14
  352. package/skills/approval/SKILL.md +28 -13
  353. package/skills/approval/reference.md +2 -2
  354. package/skills/execution/SKILL.md +1 -1
  355. package/skills/gaia-patterns/SKILL.md +2 -3
  356. package/skills/orchestrator-approval/SKILL.md +22 -50
  357. package/skills/security-tiers/SKILL.md +1 -1
  358. package/templates/README.md +9 -9
  359. package/templates/managed-settings.template.json +43 -0
  360. package/tools/gaia_simulator/runner.py +34 -1
  361. package/tools/scan/orchestrator.py +13 -0
  362. package/tools/scan/scanners/base.py +8 -0
  363. package/tools/scan/scanners/git.py +78 -0
  364. package/tools/scan/scanners/infrastructure.py +65 -0
  365. package/tools/scan/scanners/stack.py +110 -0
  366. package/tools/scan/setup.py +120 -13
  367. package/tools/scan/workspace.py +85 -0
  368. package/config/context-contracts.aws.json +0 -42
  369. package/config/context-contracts.gcp.json +0 -39
  370. package/skills/project-dispatch/SKILL.md +0 -34
  371. package/templates/settings.template.json +0 -226
@@ -0,0 +1,109 @@
1
+ # Skills System
2
+
3
+ Skills are knowledge modules that extend agent capabilities. They use Claude Code's native skill system for automatic discovery and injection.
4
+
5
+ ## Architecture
6
+
7
+ ```
8
+ .claude/skills/
9
+ ├── agent-protocol/ # json:contract format, state machine, repair flow
10
+ ├── agent-response/ # Orchestrator: interpret agent json:contract responses
11
+ ├── security-tiers/ # T0-T3 classification
12
+ │ └── reference.md
13
+ ├── investigation/ # Diagnosis methodology and pattern analysis
14
+ ├── command-execution/ # Defensive execution, safe shell patterns
15
+ │ └── reference.md
16
+ ├── context-updater/ # CONTEXT_UPDATE format and contract-driven writable sections
17
+ │ └── examples.md
18
+ ├── git-conventions/ # Conventional commits (on-demand)
19
+ ├── skill-creation/ # How to create new skills
20
+ ├── gaia-patterns/ # Gaia meta-system patterns
21
+ │ └── reference.md
22
+ ├── terraform-patterns/ # Terraform/Terragrunt patterns
23
+ │ └── reference.md
24
+ ├── gitops-patterns/ # GitOps/Flux patterns
25
+ │ └── reference.md
26
+ ├── developer-patterns/ # Developer workflow patterns
27
+ ├── fast-queries/ # Quick diagnostic scripts
28
+ ├── speckit-workflow/ # Speckit phase management
29
+ ├── specification/ # Feature specification workflow
30
+ ├── orchestrator-approval/ # T3 approval presentation for orchestrator
31
+ ├── approval/ # T3 plan presentation and approval workflow
32
+ │ └── examples.md
33
+ ├── execution/ # Post-approval execution protocol
34
+ └── reference.md # Cross-skill reference
35
+ ```
36
+
37
+ ## How Skills Work
38
+
39
+ Skills are assigned to agents via the `skills:` field in agent frontmatter (`.claude/agents/<name>.md`). Claude Code injects the full skill content at subagent startup.
40
+
41
+ ```yaml
42
+ # Example: agents/cloud-troubleshooter.md
43
+ ---
44
+ name: cloud-troubleshooter
45
+ skills:
46
+ - security-tiers
47
+ - agent-protocol
48
+ - context-updater
49
+ - fast-queries
50
+ - command-execution
51
+ - investigation
52
+ ---
53
+ ```
54
+
55
+ ## Skill Assignment Matrix
56
+
57
+ | Agent | Core Skills | Domain Skills |
58
+ |-------|-------------|---------------|
59
+ | cloud-troubleshooter | agent-protocol, security-tiers | fast-queries |
60
+ | terraform-architect | agent-protocol, security-tiers, terraform-patterns | fast-queries |
61
+ | gitops-operator | agent-protocol, security-tiers, gitops-patterns | fast-queries |
62
+ | devops-developer | agent-protocol, security-tiers, developer-patterns | fast-queries |
63
+ | gaia | agent-protocol, security-tiers, gaia-patterns, skill-creation | - |
64
+ | speckit-planner | agent-protocol, security-tiers, speckit-workflow | - |
65
+
66
+ Orchestrator skills (loaded on-demand via Skill tool, not assigned to agents):
67
+ - **agent-response** -- contract status interpretation and presentation
68
+ - **orchestrator-approval** -- T3 approval presentation and grant activation
69
+
70
+ ## Skill Types
71
+
72
+ | Type | Injection | Examples |
73
+ |------|-----------|----------|
74
+ | **Core** | Always via `skills:` | agent-protocol, security-tiers |
75
+ | **Common** | Most agents via `skills:` | command-execution, context-updater |
76
+ | **Domain** | Per-agent via `skills:` | terraform-patterns, gitops-patterns, developer-patterns, gaia-patterns |
77
+ | **Workflow** | On-demand (agent reads file) | approval, execution, git-conventions |
78
+ | **Orchestrator** | On-demand via Skill tool | agent-response, orchestrator-approval |
79
+
80
+ Workflow skills are loaded on-demand -- agents read them from disk when needed rather than receiving them at startup. Supporting files (`examples.md`, `reference.md`) are also read on-demand.
81
+
82
+ ## SKILL.md Format
83
+
84
+ ```yaml
85
+ ---
86
+ name: skill-name
87
+ description: When Claude should use this skill
88
+ metadata:
89
+ user-invocable: false # Background knowledge, not a slash command
90
+ type: core # Optional: core, common, domain, workflow
91
+ ---
92
+
93
+ # Skill Content
94
+
95
+ Instructions and patterns the agent follows.
96
+ ```
97
+
98
+ ## Development Guidelines
99
+
100
+ - Keep skills focused and specific
101
+ - Use `metadata.user-invocable: false` for background knowledge
102
+ - Keep injected skills under 100 lines (move details to supporting files)
103
+ - Reference workflow skills as readable files, not injected content
104
+ - Avoid duplicating content across skills -- use references instead
105
+ - See `skill-creation/SKILL.md` for detailed creation guidelines
106
+
107
+ ---
108
+
109
+ **Updated:** 2026-03-19 | **Total skills:** 20
@@ -0,0 +1,105 @@
1
+ ---
2
+ name: agent-protocol
3
+ description: Defines json:contract response format, state machine, and evidence reporting
4
+ metadata:
5
+ user-invocable: false
6
+ type: protocol
7
+ ---
8
+
9
+ # Agent Protocol
10
+
11
+ ## Response Contract
12
+
13
+ Every response MUST end with a single fenced `json:contract` block.
14
+
15
+ ```json:contract
16
+ {
17
+ "agent_status": {
18
+ "plan_status": "<STATUS>",
19
+ "agent_id": "<a + 5+ hex chars>",
20
+ "pending_steps": [],
21
+ "next_action": "done"
22
+ },
23
+ "evidence_report": {
24
+ "patterns_checked": [],
25
+ "files_checked": [],
26
+ "commands_run": [],
27
+ "key_outputs": [],
28
+ "verbatim_outputs": [],
29
+ "cross_layer_impacts": [],
30
+ "open_gaps": []
31
+ },
32
+ "consolidation_report": null,
33
+ "approval_request": null
34
+ }
35
+ ```
36
+
37
+ ### agent_status (always required)
38
+
39
+ - `plan_status` -- one of the 5 valid states below
40
+ - `agent_id` -- generate once, reuse across responses
41
+ - `pending_steps` -- remaining work (`[]` when done)
42
+ - `next_action` -- `"done"` or what happens next
43
+
44
+ ### evidence_report (always required)
45
+
46
+ All 7 fields validated by runtime. Use `[]` when not applicable.
47
+ Keep each to 1-3 items unless the task genuinely needs more.
48
+
49
+ - `key_outputs` -- actionable findings, not descriptions of what you ran. Highlight what matters: what is wrong, what changed, what needs attention.
50
+ - `verbatim_outputs` -- literal command output; truncate at ~100 lines
51
+ - `cross_layer_impacts` -- adjacent surfaces affected
52
+ - `open_gaps` -- what remains unverified; never imply certainty
53
+
54
+ ### consolidation_report (when multi-surface)
55
+
56
+ Required when `investigation_brief.consolidation_required` or
57
+ `surface_routing.multi_surface` is true. Otherwise `null`.
58
+
59
+ Fields: `ownership_assessment`, `confirmed_findings`,
60
+ `suspected_findings`, `conflicts`, `open_gaps`, `next_best_agent`.
61
+
62
+ For examples, read `examples.md` in this skill directory.
63
+
64
+ ### approval_request (when REVIEW)
65
+
66
+ Required when `plan_status` is `REVIEW`. Otherwise `null`.
67
+
68
+ Fields: `operation`, `exact_content`, `scope`, `risk_level`, `rollback`, `verification`.
69
+ When a hook blocked a T3 command with `[T3_BLOCKED]` and an `approval_id`:
70
+ - Do NOT retry the command -- retrying generates new nonces in a loop
71
+ - Set `plan_status` to `REVIEW` and include `approval_id` in `approval_request`
72
+ - The orchestrator will resume you after user approval; only then retry
73
+
74
+ ## State Machine
75
+
76
+ | Status | Meaning |
77
+ |--------|---------|
78
+ | `IN_PROGRESS` | Active work: investigating, planning, executing, retrying (max 2 cycles) |
79
+ | `REVIEW` | Presenting plan or analysis for user feedback. May include `approval_id` when hook-blocked. |
80
+ | `COMPLETE` | Task finished |
81
+ | `BLOCKED` | Cannot proceed -- escalated |
82
+ | `NEEDS_INPUT` | Missing information from user |
83
+
84
+ ### Transitions
85
+
86
+ ```
87
+ IN_PROGRESS -> COMPLETE (T0/T1/T2)
88
+ IN_PROGRESS -> REVIEW -> IN_PROGRESS -> COMPLETE (plan-first or hook-blocked T3)
89
+ IN_PROGRESS -> BLOCKED | NEEDS_INPUT (any point)
90
+ IN_PROGRESS -> IN_PROGRESS (retry, max 2)
91
+ ```
92
+
93
+ ## Error Handling
94
+
95
+ | Type | Action | Status |
96
+ |------|--------|--------|
97
+ | Recoverable | Fix and retry (max 2 cycles) | `IN_PROGRESS` |
98
+ | Blocker | Log details, list solutions | `BLOCKED` |
99
+ | Ambiguous | List options | `NEEDS_INPUT` |
100
+
101
+ ## Contract Repair
102
+
103
+ If resumed with repair instructions, reissue a complete response
104
+ with `json:contract`. Do not rerun the full investigation.
105
+ Retries capped at 2.
@@ -0,0 +1,170 @@
1
+ # Agent Protocol -- Status-Specific Examples
2
+
3
+ Read on-demand when constructing a `json:contract` block.
4
+ See `SKILL.md` for the schema definition and field rules.
5
+
6
+ ## COMPLETE (task finished, evidence-backed)
7
+
8
+ ```json:contract
9
+ {
10
+ "agent_status": {
11
+ "plan_status": "COMPLETE",
12
+ "agent_id": "ab7e4d2",
13
+ "pending_steps": [],
14
+ "next_action": "done"
15
+ },
16
+ "evidence_report": {
17
+ "patterns_checked": ["existing HelmRelease naming convention in flux/apps/"],
18
+ "files_checked": ["flux/apps/qxo-api/helmrelease.yaml"],
19
+ "commands_run": ["kubectl get hr -n qxo -> all reconciled"],
20
+ "key_outputs": ["All 12 HelmReleases healthy, no drift detected"],
21
+ "verbatim_outputs": [],
22
+ "cross_layer_impacts": [],
23
+ "open_gaps": []
24
+ },
25
+ "consolidation_report": null,
26
+ "approval_request": null
27
+ }
28
+ ```
29
+
30
+ ## BLOCKED (cannot proceed)
31
+
32
+ ```json:contract
33
+ {
34
+ "agent_status": {
35
+ "plan_status": "BLOCKED",
36
+ "agent_id": "ac3a1f9",
37
+ "pending_steps": ["validate IAM binding", "apply terraform change"],
38
+ "next_action": "User must grant roles/container.admin to SA"
39
+ },
40
+ "evidence_report": {
41
+ "patterns_checked": ["SA binding pattern in terraform/iam/"],
42
+ "files_checked": ["terraform/iam/main.tf", "terraform/iam/variables.tf"],
43
+ "commands_run": ["gcloud iam service-accounts get-iam-policy sa@proj.iam -> missing binding"],
44
+ "key_outputs": ["SA lacks roles/container.admin required for node pool ops"],
45
+ "verbatim_outputs": ["gcloud iam service-accounts get-iam-policy sa@proj.iam:\n```\nbindings: []\n```"],
46
+ "cross_layer_impacts": ["GKE node pool scaling depends on this SA"],
47
+ "open_gaps": ["Whether SA should get role directly or via workload identity"]
48
+ },
49
+ "consolidation_report": null,
50
+ "approval_request": null
51
+ }
52
+ ```
53
+
54
+ ## NEEDS_INPUT (missing information)
55
+
56
+ ```json:contract
57
+ {
58
+ "agent_status": {
59
+ "plan_status": "NEEDS_INPUT",
60
+ "agent_id": "ad9f2b1",
61
+ "pending_steps": ["create namespace manifest", "configure HelmRelease"],
62
+ "next_action": "User must choose: Option A (shared namespace) or Option B (dedicated namespace)"
63
+ },
64
+ "evidence_report": {
65
+ "patterns_checked": ["namespace conventions in flux/clusters/"],
66
+ "files_checked": ["flux/clusters/dev/namespaces/"],
67
+ "commands_run": [],
68
+ "key_outputs": ["Both patterns exist in codebase -- no single convention"],
69
+ "verbatim_outputs": [],
70
+ "cross_layer_impacts": ["Network policies differ per pattern"],
71
+ "open_gaps": ["User preference for namespace isolation"]
72
+ },
73
+ "consolidation_report": null,
74
+ "approval_request": null
75
+ }
76
+ ```
77
+
78
+ ## REVIEW (plan ready for user feedback, no nonce)
79
+
80
+ ```json:contract
81
+ {
82
+ "agent_status": {
83
+ "plan_status": "REVIEW",
84
+ "agent_id": "ae5c8a3",
85
+ "pending_steps": ["execute terraform apply", "verify state"],
86
+ "next_action": "Awaiting user feedback on terraform apply plan"
87
+ },
88
+ "evidence_report": {
89
+ "patterns_checked": ["existing bucket naming in terraform/gcs/"],
90
+ "files_checked": ["terraform/gcs/main.tf", "terraform/gcs/variables.tf"],
91
+ "commands_run": ["terraform plan -out=tfplan -> 1 to add, 0 to change, 0 to destroy"],
92
+ "key_outputs": ["Plan adds 1 GCS bucket with standard config"],
93
+ "verbatim_outputs": ["terraform plan:\n```\n+ google_storage_bucket.events\n name: qxo-events-dev\n location: us-east4\n```"],
94
+ "cross_layer_impacts": ["Flux ExternalSecret must reference new bucket"],
95
+ "open_gaps": []
96
+ },
97
+ "consolidation_report": null,
98
+ "approval_request": {
99
+ "operation": "Create GCS bucket qxo-events-dev",
100
+ "exact_content": "terraform apply -auto-approve",
101
+ "scope": "terraform/gcs/main.tf, GCS bucket in us-east4",
102
+ "risk_level": "MEDIUM",
103
+ "rollback": "terraform destroy -target=google_storage_bucket.events",
104
+ "verification": "gcloud storage buckets describe gs://qxo-events-dev"
105
+ }
106
+ }
107
+ ```
108
+
109
+ ## REVIEW with approval_id (hook blocked T3 command)
110
+
111
+ ```json:contract
112
+ {
113
+ "agent_status": {
114
+ "plan_status": "REVIEW",
115
+ "agent_id": "af1d9b7",
116
+ "pending_steps": ["execute git push", "verify Flux reconciliation"],
117
+ "next_action": "Hook blocked git push -- awaiting user approval"
118
+ },
119
+ "evidence_report": {
120
+ "patterns_checked": ["git branch naming in flux/clusters/"],
121
+ "files_checked": ["flux/apps/qxo-api/helmrelease.yaml"],
122
+ "commands_run": ["git diff HEAD -> 1 file changed", "git push origin main -> BLOCKED by hook"],
123
+ "key_outputs": ["Push blocked by security hook, approval_id issued"],
124
+ "verbatim_outputs": ["[T3_BLOCKED] MUTATIVE operation requires user approval. approval_id: a1b2c3..."],
125
+ "cross_layer_impacts": ["Flux will reconcile HelmRelease on push"],
126
+ "open_gaps": []
127
+ },
128
+ "consolidation_report": null,
129
+ "approval_request": {
130
+ "operation": "Push HelmRelease changes to main",
131
+ "exact_content": "git push origin main",
132
+ "scope": "flux/apps/qxo-api/helmrelease.yaml",
133
+ "risk_level": "MEDIUM",
134
+ "rollback": "git revert HEAD && git push",
135
+ "verification": "flux get hr -n qxo -> reconciled",
136
+ "approval_id": "a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6"
137
+ }
138
+ }
139
+ ```
140
+
141
+ ## With Consolidation (multi-surface task)
142
+
143
+ ```json:contract
144
+ {
145
+ "agent_status": {
146
+ "plan_status": "COMPLETE",
147
+ "agent_id": "af4b2e8",
148
+ "pending_steps": [],
149
+ "next_action": "done"
150
+ },
151
+ "evidence_report": {
152
+ "patterns_checked": ["terraform module structure in terraform/modules/"],
153
+ "files_checked": ["terraform/modules/gke/main.tf", "flux/clusters/dev/kustomization.yaml"],
154
+ "commands_run": ["terragrunt plan -chdir=/abs/path -> no changes"],
155
+ "key_outputs": ["Terraform state matches code; Flux kustomization references correct cluster"],
156
+ "verbatim_outputs": [],
157
+ "cross_layer_impacts": ["Flux depends on GKE node pool count from terraform output"],
158
+ "open_gaps": ["HPA config in flux not verified"]
159
+ },
160
+ "consolidation_report": {
161
+ "ownership_assessment": "cross_surface_dependency",
162
+ "confirmed_findings": ["GKE cluster config matches terraform code", "Node pool count is 3 in both plan and live"],
163
+ "suspected_findings": ["HPA max replicas may exceed node capacity"],
164
+ "conflicts": [],
165
+ "open_gaps": ["HPA config in flux not verified -- gitops-operator should check"],
166
+ "next_best_agent": "gitops-operator"
167
+ },
168
+ "approval_request": null
169
+ }
170
+ ```
@@ -0,0 +1,53 @@
1
+ ---
2
+ name: agent-response
3
+ description: Use when an agent returns a json:contract response that needs to be interpreted and presented to the user
4
+ metadata:
5
+ user-invocable: false
6
+ type: protocol
7
+ ---
8
+
9
+ # Agent Response Protocol
10
+
11
+ ## State Machine
12
+
13
+ ```
14
+ Agent returns json:contract
15
+ |- COMPLETE -> Summarize key_outputs (3-5 bullets)
16
+ |- NEEDS_INPUT -> AskUserQuestion, then SendMessage answer back
17
+ |- REVIEW -> Load Skill("orchestrator-approval") if approval_id present,
18
+ | otherwise AskUserQuestion (execute/modify/cancel)
19
+ |- BLOCKED -> Present open_gaps via AskUserQuestion
20
+ +- IN_PROGRESS -> SendMessage to resume agent
21
+ ```
22
+
23
+ ## Mandatory Actions per Status
24
+
25
+ | Status | Action | Tool |
26
+ |---|---|---|
27
+ | `COMPLETE` | Summarize `key_outputs` in 3-5 bullets. Mention `cross_layer_impacts` and `open_gaps` if non-empty. Say "ask for details" if `verbatim_outputs` exists. | Direct response |
28
+ | `NEEDS_INPUT` | Present the agent's question with options | `AskUserQuestion` -> `SendMessage` |
29
+ | `REVIEW` | If `approval_request.approval_id` is present: load `Skill("orchestrator-approval")`. Otherwise: present plan with options execute / modify / cancel. | `AskUserQuestion` -> `SendMessage` |
30
+ | `BLOCKED` | Present alternatives from `open_gaps` | `AskUserQuestion` |
31
+ | `IN_PROGRESS` | Agent was interrupted, let it continue | `SendMessage` |
32
+
33
+ ## Output Fields
34
+
35
+ | Field | When to surface |
36
+ |---|---|
37
+ | `key_outputs` | Always -- base your summary on these |
38
+ | `verbatim_outputs` | Only when user asks for details -- relay in code blocks |
39
+ | `cross_layer_impacts` | Always mention if non-empty |
40
+ | `open_gaps` | Always mention -- never imply certainty |
41
+ | `consolidation_report` | Check for `conflicts` and `next_best_agent` |
42
+ | `next_best_agent` | Ask user if they want to dispatch |
43
+
44
+ ## Multiple Agents
45
+
46
+ Wait for ALL dispatched agents before responding. Consolidate findings.
47
+ If agents conflict, present both sides and ask user to decide.
48
+
49
+ ## Error Handling
50
+
51
+ | Situation | Action |
52
+ |---|---|
53
+ | Malformed contract | Resume agent with repair instructions (max 2 retries). |
@@ -0,0 +1,85 @@
1
+ ---
2
+ name: approval
3
+ description: Use when a T3 operation is ready and needs to be presented to the user for approval before execution
4
+ metadata:
5
+ user-invocable: false
6
+ type: technique
7
+ ---
8
+
9
+ # Approval
10
+
11
+ ## Overview
12
+
13
+ The plan is a contract. The user approves the exact contract --
14
+ not a vague intent. Structure your plan in the `approval_request`
15
+ field of your `json:contract` so the orchestrator can present it
16
+ directly to the user.
17
+
18
+ ## Approval Request
19
+
20
+ Include an `approval_request` object in your `json:contract` block
21
+ with these 6 fields:
22
+
23
+ ```json
24
+ "approval_request": {
25
+ "operation": "verb + target",
26
+ "exact_content": "literal command, config, or file change",
27
+ "scope": "files, resources, environments affected",
28
+ "risk_level": "LOW | MEDIUM | HIGH | CRITICAL",
29
+ "rollback": "how to undo if wrong",
30
+ "verification": "how to confirm success after execution"
31
+ }
32
+ ```
33
+
34
+ When a hook blocked your command with an `approval_id`, also include:
35
+ ```json
36
+ "approval_id": "hex from hook deny response"
37
+ ```
38
+
39
+ ### Risk Levels
40
+
41
+ | Level | Criteria |
42
+ |-------|----------|
43
+ | LOW | Single resource, non-prod, no dependencies |
44
+ | MEDIUM | Multiple resources, non-prod, some dependencies |
45
+ | HIGH | Production, dependencies, potential downtime |
46
+ | CRITICAL | Irreversible, data loss possible |
47
+
48
+ ## Which Status to Emit
49
+
50
+ - `REVIEW` -- presenting a plan before executing (no hook block)
51
+ - `REVIEW` with `approval_id` -- hook blocked your command with an approval_id
52
+
53
+ Both use `REVIEW` as the plan_status. The presence or absence of
54
+ `approval_id` in `approval_request` tells the orchestrator which
55
+ handling path to take.
56
+
57
+ ## Hook Block Flow
58
+
59
+ When a hook blocks your command with `[T3_BLOCKED]` and an `approval_id`:
60
+
61
+ 1. **STOP** -- do NOT retry the command. Retrying generates a new nonce
62
+ each time, creating an infinite loop.
63
+ 2. **Report REVIEW** -- set `plan_status` to `REVIEW` in your `json:contract`.
64
+ 3. **Include the approval_id** -- copy the hex identifier from the hook deny
65
+ response into `approval_request.approval_id`.
66
+ 4. **Wait** -- the orchestrator presents your plan to the user. When the user
67
+ approves, the orchestrator resumes you with the grant activated.
68
+ 5. **Then retry** -- only after the orchestrator resumes you, retry the command.
69
+
70
+ The hook deny message looks like:
71
+ ```
72
+ [T3_BLOCKED] This command requires user approval.
73
+ Do NOT retry this command. Report REVIEW with this approval_id in your json:contract.
74
+ approval_id: <hex>
75
+ ```
76
+
77
+ If you lose the approval_id, re-attempt the command once for a fresh one.
78
+
79
+ ## Anti-Patterns
80
+
81
+ - **Retrying after T3_BLOCKED** -- generates a new nonce, causes infinite loop
82
+ - Presenting approval without all 6 fields in `approval_request`
83
+ - Putting approval fields in text only without the JSON object
84
+ - Treating prior approvals as valid for new operations
85
+ - Fabricating or paraphrasing the approval_id token
@@ -0,0 +1,140 @@
1
+ # Approval Plan Examples
2
+
3
+ Reference examples for agents. Read on-demand when building your first plan or when unsure about format.
4
+
5
+ ## Example 1: Terraform Apply (GCP)
6
+
7
+ ```markdown
8
+ ## Terraform Apply Plan
9
+
10
+ ### Summary
11
+ - Creating GCP VPC network for production cluster
12
+ - Adds 3 subnetworks across us-east4-a, us-east4-b, us-east4-c
13
+ - No existing resources affected
14
+
15
+ ### Changes Proposed
16
+
17
+ **Resources to CREATE:**
18
+ - `google_compute_network.prod-network`: VPC in auto-subnet mode disabled
19
+ - `google_compute_subnetwork.prod-subnet-a`: 10.0.1.0/24 in us-east4-a
20
+ - `google_compute_subnetwork.prod-subnet-b`: 10.0.2.0/24 in us-east4-b
21
+ - `google_compute_subnetwork.prod-subnet-c`: 10.0.3.0/24 in us-east4-c
22
+
23
+ **Resources to MODIFY:** None
24
+ **Resources to DELETE:** None
25
+
26
+ ### Validation Results
27
+
28
+ **Dry-run status:**
29
+ - ✅ `terragrunt plan` - No errors, 4 to add, 0 to change, 0 to destroy
30
+ - ✅ `terragrunt hclfmt --check` - No formatting issues
31
+ - ✅ `terraform validate` - Success
32
+
33
+ **Dependencies verified:**
34
+ - GCP project [project-id]: accessible ✓
35
+ - No CIDR conflicts with existing networks ✓
36
+
37
+ ### Risk Assessment
38
+
39
+ **Risk Level:** MEDIUM
40
+
41
+ **Potential Risks:**
42
+ 1. CIDR overlap with existing VPC networks
43
+ - Mitigation: Verified no overlaps via `gcloud compute networks list`
44
+ 2. Subnet creation timeout
45
+ - Mitigation: Timeout set to 300s, idempotent — safe to retry
46
+
47
+ **Rollback Plan:**
48
+ - If creation fails: `terragrunt destroy --terragrunt-working-dir "/abs/path/to/terraform/vpc"`
49
+ - Recovery time: ~5 minutes
50
+
51
+ ### Execution Steps
52
+
53
+ When approved, will execute:
54
+ 1. `git add [terraform_vpc_path]/`
55
+ 2. `git commit -m "feat(infra): add production VPC network"`
56
+ 3. `git push origin main`
57
+ 4. `terragrunt apply -auto-approve --terragrunt-working-dir "/abs/path/to/terraform/vpc"`
58
+
59
+ ### Verification Criteria
60
+
61
+ - `gcloud compute networks describe prod-network --project=[project-id]` → `status: ACTIVE`
62
+ - `gcloud compute networks subnets list --filter="network:prod-network" --project=[project-id]` → 3 subnets listed
63
+
64
+ ### Files Affected
65
+
66
+ **Git changes:**
67
+ - Added: `[terraform_vpc_path]/terragrunt.hcl`
68
+ - Added: `[terraform_vpc_path]/main.tf`
69
+
70
+ ## Approval Required
71
+
72
+ **Approval Code:** `NONCE:<hex from hook block response>`
73
+ **Operation:** terragrunt apply
74
+ **Environment:** prod
75
+ **Risk Level:** MEDIUM
76
+ ```
77
+
78
+ ## Example 2: GitOps Deployment
79
+
80
+ ```markdown
81
+ ## GitOps Deployment Plan
82
+
83
+ ### Summary
84
+ - Updating graphql-server image to v1.0.180
85
+ - No configuration changes
86
+ - Flux will auto-reconcile in ~1 minute
87
+
88
+ ### Changes Proposed
89
+
90
+ **HelmRelease to MODIFY:**
91
+ - `graphql-server` in namespace `common`
92
+ - Image: ghcr.io/vtr/graphql-server:v1.0.176 → v1.0.180
93
+ - No other changes
94
+
95
+ ### Validation Results
96
+
97
+ **Dry-run status:**
98
+ - ✅ `kubectl apply --dry-run=client` - Valid manifest
99
+ - ✅ YAML syntax check - Passed
100
+ - ✅ Image exists in registry - Verified
101
+
102
+ ### Risk Assessment
103
+
104
+ **Risk Level:** LOW
105
+
106
+ **Potential Risks:**
107
+ 1. New image might have bugs
108
+ - Mitigation: Tested in dev cluster, all tests passed
109
+ 2. Pod restart might cause brief downtime
110
+ - Mitigation: RollingUpdate strategy, 2 replicas ensure availability
111
+
112
+ **Rollback Plan:**
113
+ - If deployment fails: `git revert` + `flux reconcile`
114
+ - Recovery time: ~2 minutes
115
+
116
+ ### Execution Steps
117
+
118
+ When approved, will execute:
119
+ 1. `git add gitops/clusters/prod-digital-eks/common/graphql-server.yaml`
120
+ 2. `git commit -m "chore(graphql): update to v1.0.180"`
121
+ 3. `git push origin main`
122
+ 4. Flux auto-reconciles in ~1 minute (or force: `flux reconcile helmrelease graphql-server -n common --timeout=90s`)
123
+
124
+ ### Verification Criteria
125
+
126
+ - `kubectl get helmrelease graphql-server -n common --request-timeout=30s` → `READY=True`, revision contains `v1.0.180`
127
+ - `kubectl get pods -n common -l app=graphql-server --request-timeout=30s` → all pods `Running`
128
+
129
+ ### Files Affected
130
+
131
+ **Git changes:**
132
+ - Modified: `gitops/clusters/prod-digital-eks/common/graphql-server.yaml`
133
+
134
+ ## Approval Required
135
+
136
+ **Approval Code:** `NONCE:<hex from hook block response>`
137
+ **Operation:** git push + flux reconcile
138
+ **Environment:** prod
139
+ **Risk Level:** LOW
140
+ ```