@jaguilar87/gaia 5.0.0-rc.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.
- package/.claude-plugin/marketplace.json +33 -0
- package/.claude-plugin/plugin.json +26 -0
- package/ARCHITECTURE.md +335 -0
- package/CHANGELOG.md +1298 -0
- package/CODE_OF_CONDUCT.md +11 -0
- package/CONTRIBUTING.md +146 -0
- package/INSTALL.md +436 -0
- package/LICENSE +21 -0
- package/README.md +222 -0
- package/SECURITY.md +47 -0
- package/agents/README.md +78 -0
- package/agents/cloud-troubleshooter.md +73 -0
- package/agents/developer.md +65 -0
- package/agents/gaia-operator.md +64 -0
- package/agents/gaia-orchestrator.md +111 -0
- package/agents/gaia-planner.md +53 -0
- package/agents/gaia-system.md +71 -0
- package/agents/gitops-operator.md +61 -0
- package/agents/terraform-architect.md +63 -0
- package/bin/README.md +106 -0
- package/bin/cli/__init__.py +1 -0
- package/bin/cli/approvals.py +740 -0
- package/bin/cli/cleanup.py +562 -0
- package/bin/cli/context.py +283 -0
- package/bin/cli/doctor.py +651 -0
- package/bin/cli/history.py +305 -0
- package/bin/cli/memory.py +483 -0
- package/bin/cli/metrics.py +1068 -0
- package/bin/cli/plans.py +515 -0
- package/bin/cli/status.py +302 -0
- package/bin/cli/update.py +382 -0
- package/bin/gaia +112 -0
- package/bin/gaia-cleanup.js +531 -0
- package/bin/gaia-doctor.js +635 -0
- package/bin/gaia-evidence +126 -0
- package/bin/gaia-history.js +251 -0
- package/bin/gaia-metrics.js +1278 -0
- package/bin/gaia-review.js +269 -0
- package/bin/gaia-scan +44 -0
- package/bin/gaia-scan.py +589 -0
- package/bin/gaia-skills-diagnose.js +929 -0
- package/bin/gaia-status.js +278 -0
- package/bin/gaia-uninstall.js +111 -0
- package/bin/gaia-update.js +919 -0
- package/bin/pre-publish-validate.js +610 -0
- package/bin/python-detect.js +60 -0
- package/bin/validate-sandbox.sh +601 -0
- package/commands/README.md +64 -0
- package/commands/gaia.md +37 -0
- package/commands/scan-project.md +67 -0
- package/config/README.md +71 -0
- package/config/cloud/aws.json +134 -0
- package/config/cloud/gcp.json +139 -0
- package/config/context-contracts.json +158 -0
- package/config/crons-schema.md +81 -0
- package/config/git_standards.json +72 -0
- package/config/surface-routing.json +417 -0
- package/config/universal-rules.json +102 -0
- package/dist/gaia-ops/.claude-plugin/plugin.json +24 -0
- package/dist/gaia-ops/README.md +80 -0
- package/dist/gaia-ops/agents/cloud-troubleshooter.md +73 -0
- package/dist/gaia-ops/agents/developer.md +65 -0
- package/dist/gaia-ops/agents/gaia-operator.md +64 -0
- package/dist/gaia-ops/agents/gaia-orchestrator.md +111 -0
- package/dist/gaia-ops/agents/gaia-planner.md +53 -0
- package/dist/gaia-ops/agents/gaia-system.md +71 -0
- package/dist/gaia-ops/agents/gitops-operator.md +61 -0
- package/dist/gaia-ops/agents/terraform-architect.md +63 -0
- package/dist/gaia-ops/commands/gaia.md +37 -0
- package/dist/gaia-ops/config/README.md +71 -0
- package/dist/gaia-ops/config/cloud/aws.json +134 -0
- package/dist/gaia-ops/config/cloud/gcp.json +139 -0
- package/dist/gaia-ops/config/context-contracts.json +158 -0
- package/dist/gaia-ops/config/crons-schema.md +81 -0
- package/dist/gaia-ops/config/git_standards.json +72 -0
- package/dist/gaia-ops/config/surface-routing.json +417 -0
- package/dist/gaia-ops/config/universal-rules.json +102 -0
- package/dist/gaia-ops/hooks/adapters/__init__.py +52 -0
- package/dist/gaia-ops/hooks/adapters/base.py +219 -0
- package/dist/gaia-ops/hooks/adapters/channel.py +17 -0
- package/dist/gaia-ops/hooks/adapters/claude_code.py +1890 -0
- package/dist/gaia-ops/hooks/adapters/types.py +194 -0
- package/dist/gaia-ops/hooks/adapters/utils.py +25 -0
- package/dist/gaia-ops/hooks/hooks.json +192 -0
- package/dist/gaia-ops/hooks/modules/__init__.py +15 -0
- package/dist/gaia-ops/hooks/modules/agents/__init__.py +29 -0
- package/dist/gaia-ops/hooks/modules/agents/contract_validator.py +647 -0
- package/dist/gaia-ops/hooks/modules/agents/response_contract.py +496 -0
- package/dist/gaia-ops/hooks/modules/agents/skill_injection_verifier.py +120 -0
- package/dist/gaia-ops/hooks/modules/agents/state_tracker.py +267 -0
- package/dist/gaia-ops/hooks/modules/agents/task_info_builder.py +74 -0
- package/dist/gaia-ops/hooks/modules/agents/transcript_analyzer.py +458 -0
- package/dist/gaia-ops/hooks/modules/agents/transcript_reader.py +152 -0
- package/dist/gaia-ops/hooks/modules/audit/__init__.py +28 -0
- package/dist/gaia-ops/hooks/modules/audit/event_detector.py +168 -0
- package/dist/gaia-ops/hooks/modules/audit/logger.py +131 -0
- package/dist/gaia-ops/hooks/modules/audit/metrics.py +134 -0
- package/dist/gaia-ops/hooks/modules/audit/workflow_auditor.py +611 -0
- package/dist/gaia-ops/hooks/modules/audit/workflow_recorder.py +296 -0
- package/dist/gaia-ops/hooks/modules/context/__init__.py +11 -0
- package/dist/gaia-ops/hooks/modules/context/agentic_loop_detector.py +165 -0
- package/dist/gaia-ops/hooks/modules/context/anchor_tracker.py +317 -0
- package/dist/gaia-ops/hooks/modules/context/compact_context_builder.py +218 -0
- package/dist/gaia-ops/hooks/modules/context/context_freshness.py +145 -0
- package/dist/gaia-ops/hooks/modules/context/context_injector.py +558 -0
- package/dist/gaia-ops/hooks/modules/context/context_writer.py +530 -0
- package/dist/gaia-ops/hooks/modules/context/contracts_loader.py +161 -0
- package/dist/gaia-ops/hooks/modules/core/__init__.py +40 -0
- package/dist/gaia-ops/hooks/modules/core/hook_entry.py +78 -0
- package/dist/gaia-ops/hooks/modules/core/paths.py +160 -0
- package/dist/gaia-ops/hooks/modules/core/plugin_mode.py +149 -0
- package/dist/gaia-ops/hooks/modules/core/plugin_setup.py +577 -0
- package/dist/gaia-ops/hooks/modules/core/state.py +179 -0
- package/dist/gaia-ops/hooks/modules/core/stdin.py +24 -0
- package/dist/gaia-ops/hooks/modules/events/__init__.py +1 -0
- package/dist/gaia-ops/hooks/modules/events/event_writer.py +210 -0
- package/dist/gaia-ops/hooks/modules/memory/__init__.py +8 -0
- package/dist/gaia-ops/hooks/modules/memory/episode_writer.py +216 -0
- package/dist/gaia-ops/hooks/modules/orchestrator/__init__.py +1 -0
- package/dist/gaia-ops/hooks/modules/orchestrator/delegate_mode.py +122 -0
- package/dist/gaia-ops/hooks/modules/scanning/__init__.py +8 -0
- package/dist/gaia-ops/hooks/modules/scanning/scan_trigger.py +84 -0
- package/dist/gaia-ops/hooks/modules/security/__init__.py +120 -0
- package/dist/gaia-ops/hooks/modules/security/approval_cleanup.py +87 -0
- package/dist/gaia-ops/hooks/modules/security/approval_constants.py +23 -0
- package/dist/gaia-ops/hooks/modules/security/approval_grants.py +1638 -0
- package/dist/gaia-ops/hooks/modules/security/approval_messages.py +71 -0
- package/dist/gaia-ops/hooks/modules/security/approval_scopes.py +222 -0
- package/dist/gaia-ops/hooks/modules/security/blocked_commands.py +595 -0
- package/dist/gaia-ops/hooks/modules/security/blocked_message_formatter.py +87 -0
- package/dist/gaia-ops/hooks/modules/security/command_semantics.py +181 -0
- package/dist/gaia-ops/hooks/modules/security/composition_rules.py +547 -0
- package/dist/gaia-ops/hooks/modules/security/flag_classifiers.py +873 -0
- package/dist/gaia-ops/hooks/modules/security/gitops_validator.py +179 -0
- package/dist/gaia-ops/hooks/modules/security/mutative_verbs.py +1131 -0
- package/dist/gaia-ops/hooks/modules/security/network_hosts.py +481 -0
- package/dist/gaia-ops/hooks/modules/security/prompt_validator.py +40 -0
- package/dist/gaia-ops/hooks/modules/security/shell_unwrapper.py +165 -0
- package/dist/gaia-ops/hooks/modules/security/tiers.py +196 -0
- package/dist/gaia-ops/hooks/modules/session/__init__.py +10 -0
- package/dist/gaia-ops/hooks/modules/session/pending_scanner.py +174 -0
- package/dist/gaia-ops/hooks/modules/session/session_context_writer.py +100 -0
- package/dist/gaia-ops/hooks/modules/session/session_event_injector.py +160 -0
- package/dist/gaia-ops/hooks/modules/session/session_manager.py +31 -0
- package/dist/gaia-ops/hooks/modules/session/session_registry.py +333 -0
- package/dist/gaia-ops/hooks/modules/tools/__init__.py +29 -0
- package/dist/gaia-ops/hooks/modules/tools/bash_validator.py +1008 -0
- package/dist/gaia-ops/hooks/modules/tools/cloud_pipe_validator.py +231 -0
- package/dist/gaia-ops/hooks/modules/tools/hook_response.py +55 -0
- package/dist/gaia-ops/hooks/modules/tools/shell_parser.py +227 -0
- package/dist/gaia-ops/hooks/modules/tools/stage_decomposer.py +315 -0
- package/dist/gaia-ops/hooks/modules/tools/task_validator.py +294 -0
- package/dist/gaia-ops/hooks/modules/validation/__init__.py +23 -0
- package/dist/gaia-ops/hooks/modules/validation/commit_validator.py +380 -0
- package/dist/gaia-ops/hooks/post_compact.py +43 -0
- package/dist/gaia-ops/hooks/post_tool_use.py +54 -0
- package/dist/gaia-ops/hooks/pre_compact.py +60 -0
- package/dist/gaia-ops/hooks/pre_tool_use.py +413 -0
- package/dist/gaia-ops/hooks/session_end_hook.py +77 -0
- package/dist/gaia-ops/hooks/session_start.py +81 -0
- package/dist/gaia-ops/hooks/stop_hook.py +70 -0
- package/dist/gaia-ops/hooks/subagent_start.py +71 -0
- package/dist/gaia-ops/hooks/subagent_stop.py +295 -0
- package/dist/gaia-ops/hooks/task_completed.py +70 -0
- package/dist/gaia-ops/hooks/user_prompt_submit.py +246 -0
- package/dist/gaia-ops/settings.json +72 -0
- package/dist/gaia-ops/skills/README.md +158 -0
- package/dist/gaia-ops/skills/agent-creation/SKILL.md +87 -0
- package/dist/gaia-ops/skills/agent-creation/examples.md +170 -0
- package/dist/gaia-ops/skills/agent-creation/reference.md +191 -0
- package/dist/gaia-ops/skills/agent-protocol/SKILL.md +93 -0
- package/dist/gaia-ops/skills/agent-protocol/examples.md +223 -0
- package/dist/gaia-ops/skills/agent-response/SKILL.md +69 -0
- package/dist/gaia-ops/skills/agentic-loop/SKILL.md +80 -0
- package/dist/gaia-ops/skills/agentic-loop/reference.md +378 -0
- package/dist/gaia-ops/skills/blog-writing/SKILL.md +98 -0
- package/dist/gaia-ops/skills/blog-writing/reference.md +130 -0
- package/dist/gaia-ops/skills/brief-spec/SKILL.md +185 -0
- package/dist/gaia-ops/skills/command-execution/SKILL.md +64 -0
- package/dist/gaia-ops/skills/command-execution/reference.md +83 -0
- package/dist/gaia-ops/skills/context-updater/SKILL.md +87 -0
- package/dist/gaia-ops/skills/context-updater/examples.md +71 -0
- package/dist/gaia-ops/skills/developer-patterns/SKILL.md +50 -0
- package/dist/gaia-ops/skills/developer-patterns/reference.md +112 -0
- package/dist/gaia-ops/skills/execution/SKILL.md +99 -0
- package/dist/gaia-ops/skills/fast-queries/SKILL.md +43 -0
- package/dist/gaia-ops/skills/gaia-compact/SKILL.md +74 -0
- package/dist/gaia-ops/skills/gaia-patterns/SKILL.md +108 -0
- package/dist/gaia-ops/skills/gaia-patterns/reference.md +395 -0
- package/dist/gaia-ops/skills/gaia-planner/SKILL.md +37 -0
- package/dist/gaia-ops/skills/gaia-planner/reference.md +107 -0
- package/dist/gaia-ops/skills/gaia-release/SKILL.md +85 -0
- package/dist/gaia-ops/skills/gaia-release/reference.md +92 -0
- package/dist/gaia-ops/skills/gaia-self-check/SKILL.md +114 -0
- package/dist/gaia-ops/skills/gaia-self-check/reference.md +453 -0
- package/dist/gaia-ops/skills/gaia-verify/SKILL.md +77 -0
- package/dist/gaia-ops/skills/gaia-verify/reference.md +80 -0
- package/dist/gaia-ops/skills/git-conventions/SKILL.md +47 -0
- package/dist/gaia-ops/skills/gitops-patterns/SKILL.md +60 -0
- package/dist/gaia-ops/skills/gitops-patterns/reference.md +183 -0
- package/dist/gaia-ops/skills/gmail-policy/SKILL.md +200 -0
- package/dist/gaia-ops/skills/gmail-policy/reference.md +150 -0
- package/dist/gaia-ops/skills/gmail-triage/SKILL.md +100 -0
- package/dist/gaia-ops/skills/gws-setup/SKILL.md +99 -0
- package/dist/gaia-ops/skills/gws-setup/reference.md +73 -0
- package/dist/gaia-ops/skills/investigation/SKILL.md +100 -0
- package/dist/gaia-ops/skills/memory-curation/SKILL.md +83 -0
- package/dist/gaia-ops/skills/memory-search/SKILL.md +88 -0
- package/dist/gaia-ops/skills/orchestrator-approval/SKILL.md +160 -0
- package/dist/gaia-ops/skills/orchestrator-approval/reference.md +174 -0
- package/dist/gaia-ops/skills/pending-approvals/SKILL.md +72 -0
- package/dist/gaia-ops/skills/pending-approvals/reference.md +214 -0
- package/dist/gaia-ops/skills/readme-writing/SKILL.md +71 -0
- package/dist/gaia-ops/skills/readme-writing/reference.md +188 -0
- package/dist/gaia-ops/skills/reference.md +135 -0
- package/dist/gaia-ops/skills/request-approval/SKILL.md +140 -0
- package/dist/gaia-ops/skills/request-approval/examples.md +140 -0
- package/dist/gaia-ops/skills/request-approval/reference.md +57 -0
- package/dist/gaia-ops/skills/schedule-task/SKILL.md +64 -0
- package/dist/gaia-ops/skills/schedule-task/reference.md +233 -0
- package/dist/gaia-ops/skills/security-tiers/SKILL.md +141 -0
- package/dist/gaia-ops/skills/security-tiers/destructive-commands-reference.md +623 -0
- package/dist/gaia-ops/skills/security-tiers/reference.md +39 -0
- package/dist/gaia-ops/skills/session-reflection/SKILL.md +69 -0
- package/dist/gaia-ops/skills/skill-creation/SKILL.md +92 -0
- package/dist/gaia-ops/skills/skill-creation/reference.md +29 -0
- package/dist/gaia-ops/skills/terraform-patterns/SKILL.md +89 -0
- package/dist/gaia-ops/skills/terraform-patterns/reference.md +93 -0
- package/dist/gaia-ops/tools/__init__.py +9 -0
- package/dist/gaia-ops/tools/agentic-loop/decide-status.py +210 -0
- package/dist/gaia-ops/tools/agentic-loop/parse-metric.py +106 -0
- package/dist/gaia-ops/tools/agentic-loop/record-iteration.py +221 -0
- package/dist/gaia-ops/tools/context/README.md +132 -0
- package/dist/gaia-ops/tools/context/__init__.py +42 -0
- package/dist/gaia-ops/tools/context/_paths.py +20 -0
- package/dist/gaia-ops/tools/context/context_provider.py +721 -0
- package/dist/gaia-ops/tools/context/context_section_reader.py +342 -0
- package/dist/gaia-ops/tools/context/deep_merge.py +159 -0
- package/dist/gaia-ops/tools/context/pending_updates.py +760 -0
- package/dist/gaia-ops/tools/context/surface_router.py +278 -0
- package/dist/gaia-ops/tools/fast-queries/README.md +65 -0
- package/dist/gaia-ops/tools/fast-queries/__init__.py +30 -0
- package/dist/gaia-ops/tools/fast-queries/appservices/quicktriage_devops_developer.sh +75 -0
- package/dist/gaia-ops/tools/fast-queries/cloud/aws/quicktriage_aws_troubleshooter.sh +32 -0
- package/dist/gaia-ops/tools/fast-queries/cloud/gcp/quicktriage_gcp_troubleshooter.sh +88 -0
- package/dist/gaia-ops/tools/fast-queries/gitops/quicktriage_gitops_operator.sh +48 -0
- package/dist/gaia-ops/tools/fast-queries/run_triage.sh +59 -0
- package/dist/gaia-ops/tools/fast-queries/terraform/quicktriage_terraform_architect.sh +80 -0
- package/dist/gaia-ops/tools/gaia_simulator/__init__.py +33 -0
- package/dist/gaia-ops/tools/gaia_simulator/cli.py +354 -0
- package/dist/gaia-ops/tools/gaia_simulator/extractor.py +457 -0
- package/dist/gaia-ops/tools/gaia_simulator/reporter.py +258 -0
- package/dist/gaia-ops/tools/gaia_simulator/routing_simulator.py +334 -0
- package/dist/gaia-ops/tools/gaia_simulator/runner.py +539 -0
- package/dist/gaia-ops/tools/gaia_simulator/skills_mapper.py +264 -0
- package/dist/gaia-ops/tools/memory/README.md +0 -0
- package/dist/gaia-ops/tools/memory/__init__.py +20 -0
- package/dist/gaia-ops/tools/memory/backfill_fts5.py +107 -0
- package/dist/gaia-ops/tools/memory/conflict_detector.py +295 -0
- package/dist/gaia-ops/tools/memory/episodic.py +1210 -0
- package/dist/gaia-ops/tools/memory/git_invalidator.py +262 -0
- package/dist/gaia-ops/tools/memory/paths.py +102 -0
- package/dist/gaia-ops/tools/memory/scoring.py +193 -0
- package/dist/gaia-ops/tools/memory/search_store.py +375 -0
- package/dist/gaia-ops/tools/persist_transcript_analysis.py +85 -0
- package/dist/gaia-ops/tools/review/__init__.py +1 -0
- package/dist/gaia-ops/tools/review/review_engine.py +157 -0
- package/dist/gaia-ops/tools/scan/__init__.py +35 -0
- package/dist/gaia-ops/tools/scan/config.py +247 -0
- package/dist/gaia-ops/tools/scan/merge.py +212 -0
- package/dist/gaia-ops/tools/scan/orchestrator.py +549 -0
- package/dist/gaia-ops/tools/scan/registry.py +127 -0
- package/dist/gaia-ops/tools/scan/scanners/__init__.py +18 -0
- package/dist/gaia-ops/tools/scan/scanners/base.py +137 -0
- package/dist/gaia-ops/tools/scan/scanners/environment.py +349 -0
- package/dist/gaia-ops/tools/scan/scanners/git.py +570 -0
- package/dist/gaia-ops/tools/scan/scanners/infrastructure.py +875 -0
- package/dist/gaia-ops/tools/scan/scanners/orchestration.py +600 -0
- package/dist/gaia-ops/tools/scan/scanners/stack.py +1085 -0
- package/dist/gaia-ops/tools/scan/scanners/tools.py +260 -0
- package/dist/gaia-ops/tools/scan/setup.py +686 -0
- package/dist/gaia-ops/tools/scan/tests/__init__.py +1 -0
- package/dist/gaia-ops/tools/scan/tests/conftest.py +796 -0
- package/dist/gaia-ops/tools/scan/tests/test_environment.py +323 -0
- package/dist/gaia-ops/tools/scan/tests/test_git.py +419 -0
- package/dist/gaia-ops/tools/scan/tests/test_infrastructure.py +382 -0
- package/dist/gaia-ops/tools/scan/tests/test_integration.py +920 -0
- package/dist/gaia-ops/tools/scan/tests/test_merge.py +269 -0
- package/dist/gaia-ops/tools/scan/tests/test_orchestration.py +304 -0
- package/dist/gaia-ops/tools/scan/tests/test_stack.py +604 -0
- package/dist/gaia-ops/tools/scan/tests/test_tools.py +349 -0
- package/dist/gaia-ops/tools/scan/ui.py +624 -0
- package/dist/gaia-ops/tools/scan/verify.py +270 -0
- package/dist/gaia-ops/tools/scan/walk.py +118 -0
- package/dist/gaia-ops/tools/scan/workspace.py +85 -0
- package/dist/gaia-ops/tools/validation/README.md +244 -0
- package/dist/gaia-ops/tools/validation/__init__.py +17 -0
- package/dist/gaia-ops/tools/validation/approval_gate.py +321 -0
- package/dist/gaia-ops/tools/validation/validate_skills.py +189 -0
- package/dist/gaia-security/.claude-plugin/plugin.json +24 -0
- package/dist/gaia-security/README.md +90 -0
- package/dist/gaia-security/config/universal-rules.json +102 -0
- package/dist/gaia-security/hooks/adapters/__init__.py +52 -0
- package/dist/gaia-security/hooks/adapters/base.py +219 -0
- package/dist/gaia-security/hooks/adapters/channel.py +17 -0
- package/dist/gaia-security/hooks/adapters/claude_code.py +1890 -0
- package/dist/gaia-security/hooks/adapters/types.py +194 -0
- package/dist/gaia-security/hooks/adapters/utils.py +25 -0
- package/dist/gaia-security/hooks/hooks.json +113 -0
- package/dist/gaia-security/hooks/modules/__init__.py +15 -0
- package/dist/gaia-security/hooks/modules/agents/__init__.py +29 -0
- package/dist/gaia-security/hooks/modules/agents/contract_validator.py +647 -0
- package/dist/gaia-security/hooks/modules/agents/response_contract.py +496 -0
- package/dist/gaia-security/hooks/modules/agents/skill_injection_verifier.py +120 -0
- package/dist/gaia-security/hooks/modules/agents/state_tracker.py +267 -0
- package/dist/gaia-security/hooks/modules/agents/task_info_builder.py +74 -0
- package/dist/gaia-security/hooks/modules/agents/transcript_analyzer.py +458 -0
- package/dist/gaia-security/hooks/modules/agents/transcript_reader.py +152 -0
- package/dist/gaia-security/hooks/modules/audit/__init__.py +28 -0
- package/dist/gaia-security/hooks/modules/audit/event_detector.py +168 -0
- package/dist/gaia-security/hooks/modules/audit/logger.py +131 -0
- package/dist/gaia-security/hooks/modules/audit/metrics.py +134 -0
- package/dist/gaia-security/hooks/modules/audit/workflow_auditor.py +611 -0
- package/dist/gaia-security/hooks/modules/audit/workflow_recorder.py +296 -0
- package/dist/gaia-security/hooks/modules/context/__init__.py +11 -0
- package/dist/gaia-security/hooks/modules/context/agentic_loop_detector.py +165 -0
- package/dist/gaia-security/hooks/modules/context/anchor_tracker.py +317 -0
- package/dist/gaia-security/hooks/modules/context/compact_context_builder.py +218 -0
- package/dist/gaia-security/hooks/modules/context/context_freshness.py +145 -0
- package/dist/gaia-security/hooks/modules/context/context_injector.py +558 -0
- package/dist/gaia-security/hooks/modules/context/context_writer.py +530 -0
- package/dist/gaia-security/hooks/modules/context/contracts_loader.py +161 -0
- package/dist/gaia-security/hooks/modules/core/__init__.py +40 -0
- package/dist/gaia-security/hooks/modules/core/hook_entry.py +78 -0
- package/dist/gaia-security/hooks/modules/core/paths.py +160 -0
- package/dist/gaia-security/hooks/modules/core/plugin_mode.py +149 -0
- package/dist/gaia-security/hooks/modules/core/plugin_setup.py +577 -0
- package/dist/gaia-security/hooks/modules/core/state.py +179 -0
- package/dist/gaia-security/hooks/modules/core/stdin.py +24 -0
- package/dist/gaia-security/hooks/modules/events/__init__.py +1 -0
- package/dist/gaia-security/hooks/modules/events/event_writer.py +210 -0
- package/dist/gaia-security/hooks/modules/memory/__init__.py +8 -0
- package/dist/gaia-security/hooks/modules/memory/episode_writer.py +216 -0
- package/dist/gaia-security/hooks/modules/orchestrator/__init__.py +1 -0
- package/dist/gaia-security/hooks/modules/orchestrator/delegate_mode.py +122 -0
- package/dist/gaia-security/hooks/modules/scanning/__init__.py +8 -0
- package/dist/gaia-security/hooks/modules/scanning/scan_trigger.py +84 -0
- package/dist/gaia-security/hooks/modules/security/__init__.py +120 -0
- package/dist/gaia-security/hooks/modules/security/approval_cleanup.py +87 -0
- package/dist/gaia-security/hooks/modules/security/approval_constants.py +23 -0
- package/dist/gaia-security/hooks/modules/security/approval_grants.py +1638 -0
- package/dist/gaia-security/hooks/modules/security/approval_messages.py +71 -0
- package/dist/gaia-security/hooks/modules/security/approval_scopes.py +222 -0
- package/dist/gaia-security/hooks/modules/security/blocked_commands.py +595 -0
- package/dist/gaia-security/hooks/modules/security/blocked_message_formatter.py +87 -0
- package/dist/gaia-security/hooks/modules/security/command_semantics.py +181 -0
- package/dist/gaia-security/hooks/modules/security/composition_rules.py +547 -0
- package/dist/gaia-security/hooks/modules/security/flag_classifiers.py +873 -0
- package/dist/gaia-security/hooks/modules/security/gitops_validator.py +179 -0
- package/dist/gaia-security/hooks/modules/security/mutative_verbs.py +1131 -0
- package/dist/gaia-security/hooks/modules/security/network_hosts.py +481 -0
- package/dist/gaia-security/hooks/modules/security/prompt_validator.py +40 -0
- package/dist/gaia-security/hooks/modules/security/shell_unwrapper.py +165 -0
- package/dist/gaia-security/hooks/modules/security/tiers.py +196 -0
- package/dist/gaia-security/hooks/modules/session/__init__.py +10 -0
- package/dist/gaia-security/hooks/modules/session/pending_scanner.py +174 -0
- package/dist/gaia-security/hooks/modules/session/session_context_writer.py +100 -0
- package/dist/gaia-security/hooks/modules/session/session_event_injector.py +160 -0
- package/dist/gaia-security/hooks/modules/session/session_manager.py +31 -0
- package/dist/gaia-security/hooks/modules/session/session_registry.py +333 -0
- package/dist/gaia-security/hooks/modules/tools/__init__.py +29 -0
- package/dist/gaia-security/hooks/modules/tools/bash_validator.py +1008 -0
- package/dist/gaia-security/hooks/modules/tools/cloud_pipe_validator.py +231 -0
- package/dist/gaia-security/hooks/modules/tools/hook_response.py +55 -0
- package/dist/gaia-security/hooks/modules/tools/shell_parser.py +227 -0
- package/dist/gaia-security/hooks/modules/tools/stage_decomposer.py +315 -0
- package/dist/gaia-security/hooks/modules/tools/task_validator.py +294 -0
- package/dist/gaia-security/hooks/modules/validation/__init__.py +23 -0
- package/dist/gaia-security/hooks/modules/validation/commit_validator.py +380 -0
- package/dist/gaia-security/hooks/post_tool_use.py +54 -0
- package/dist/gaia-security/hooks/pre_tool_use.py +413 -0
- package/dist/gaia-security/hooks/session_end_hook.py +77 -0
- package/dist/gaia-security/hooks/session_start.py +81 -0
- package/dist/gaia-security/hooks/stop_hook.py +70 -0
- package/dist/gaia-security/hooks/user_prompt_submit.py +246 -0
- package/dist/gaia-security/settings.json +58 -0
- package/git-hooks/commit-msg +41 -0
- package/hooks/README.md +100 -0
- package/hooks/adapters/__init__.py +52 -0
- package/hooks/adapters/base.py +219 -0
- package/hooks/adapters/channel.py +17 -0
- package/hooks/adapters/claude_code.py +1890 -0
- package/hooks/adapters/types.py +194 -0
- package/hooks/adapters/utils.py +25 -0
- package/hooks/elicitation_result.py +179 -0
- package/hooks/hooks.json +84 -0
- package/hooks/modules/README.md +189 -0
- package/hooks/modules/__init__.py +15 -0
- package/hooks/modules/agents/__init__.py +29 -0
- package/hooks/modules/agents/contract_validator.py +647 -0
- package/hooks/modules/agents/response_contract.py +496 -0
- package/hooks/modules/agents/skill_injection_verifier.py +120 -0
- package/hooks/modules/agents/state_tracker.py +267 -0
- package/hooks/modules/agents/task_info_builder.py +74 -0
- package/hooks/modules/agents/transcript_analyzer.py +458 -0
- package/hooks/modules/agents/transcript_reader.py +152 -0
- package/hooks/modules/audit/__init__.py +28 -0
- package/hooks/modules/audit/event_detector.py +168 -0
- package/hooks/modules/audit/logger.py +131 -0
- package/hooks/modules/audit/metrics.py +134 -0
- package/hooks/modules/audit/workflow_auditor.py +611 -0
- package/hooks/modules/audit/workflow_recorder.py +296 -0
- package/hooks/modules/context/__init__.py +11 -0
- package/hooks/modules/context/agentic_loop_detector.py +165 -0
- package/hooks/modules/context/anchor_tracker.py +317 -0
- package/hooks/modules/context/compact_context_builder.py +218 -0
- package/hooks/modules/context/context_freshness.py +145 -0
- package/hooks/modules/context/context_injector.py +558 -0
- package/hooks/modules/context/context_writer.py +530 -0
- package/hooks/modules/context/contracts_loader.py +161 -0
- package/hooks/modules/core/__init__.py +40 -0
- package/hooks/modules/core/hook_entry.py +78 -0
- package/hooks/modules/core/paths.py +160 -0
- package/hooks/modules/core/plugin_mode.py +149 -0
- package/hooks/modules/core/plugin_setup.py +577 -0
- package/hooks/modules/core/state.py +179 -0
- package/hooks/modules/core/stdin.py +24 -0
- package/hooks/modules/events/__init__.py +1 -0
- package/hooks/modules/events/event_writer.py +210 -0
- package/hooks/modules/evidence/__init__.py +34 -0
- package/hooks/modules/evidence/assertions.py +137 -0
- package/hooks/modules/evidence/index_writer.py +57 -0
- package/hooks/modules/evidence/loader.py +126 -0
- package/hooks/modules/evidence/runner.py +241 -0
- package/hooks/modules/memory/__init__.py +8 -0
- package/hooks/modules/memory/episode_writer.py +216 -0
- package/hooks/modules/orchestrator/__init__.py +1 -0
- package/hooks/modules/orchestrator/delegate_mode.py +122 -0
- package/hooks/modules/scanning/__init__.py +8 -0
- package/hooks/modules/scanning/scan_trigger.py +84 -0
- package/hooks/modules/security/__init__.py +120 -0
- package/hooks/modules/security/approval_cleanup.py +87 -0
- package/hooks/modules/security/approval_constants.py +23 -0
- package/hooks/modules/security/approval_grants.py +1638 -0
- package/hooks/modules/security/approval_messages.py +71 -0
- package/hooks/modules/security/approval_scopes.py +222 -0
- package/hooks/modules/security/blocked_commands.py +595 -0
- package/hooks/modules/security/blocked_message_formatter.py +87 -0
- package/hooks/modules/security/command_semantics.py +181 -0
- package/hooks/modules/security/composition_rules.py +547 -0
- package/hooks/modules/security/flag_classifiers.py +873 -0
- package/hooks/modules/security/gitops_validator.py +179 -0
- package/hooks/modules/security/mutative_verbs.py +1131 -0
- package/hooks/modules/security/network_hosts.py +481 -0
- package/hooks/modules/security/prompt_validator.py +40 -0
- package/hooks/modules/security/shell_unwrapper.py +165 -0
- package/hooks/modules/security/tiers.py +196 -0
- package/hooks/modules/session/__init__.py +10 -0
- package/hooks/modules/session/pending_scanner.py +174 -0
- package/hooks/modules/session/session_context_writer.py +100 -0
- package/hooks/modules/session/session_event_injector.py +160 -0
- package/hooks/modules/session/session_manager.py +31 -0
- package/hooks/modules/session/session_registry.py +333 -0
- package/hooks/modules/tools/__init__.py +29 -0
- package/hooks/modules/tools/bash_validator.py +1008 -0
- package/hooks/modules/tools/cloud_pipe_validator.py +231 -0
- package/hooks/modules/tools/hook_response.py +55 -0
- package/hooks/modules/tools/shell_parser.py +227 -0
- package/hooks/modules/tools/stage_decomposer.py +315 -0
- package/hooks/modules/tools/task_validator.py +294 -0
- package/hooks/modules/validation/__init__.py +23 -0
- package/hooks/modules/validation/commit_validator.py +380 -0
- package/hooks/post_compact.py +43 -0
- package/hooks/post_tool_use.py +54 -0
- package/hooks/pre_compact.py +60 -0
- package/hooks/pre_tool_use.py +413 -0
- package/hooks/session_end_hook.py +77 -0
- package/hooks/session_start.py +81 -0
- package/hooks/stop_hook.py +70 -0
- package/hooks/subagent_start.py +71 -0
- package/hooks/subagent_stop.py +295 -0
- package/hooks/task_completed.py +70 -0
- package/hooks/user_prompt_submit.py +246 -0
- package/index.js +83 -0
- package/package.json +103 -0
- package/pyproject.toml +32 -0
- package/skills/README.md +158 -0
- package/skills/agent-creation/SKILL.md +87 -0
- package/skills/agent-creation/examples.md +170 -0
- package/skills/agent-creation/reference.md +191 -0
- package/skills/agent-protocol/SKILL.md +93 -0
- package/skills/agent-protocol/examples.md +223 -0
- package/skills/agent-response/SKILL.md +69 -0
- package/skills/agentic-loop/SKILL.md +80 -0
- package/skills/agentic-loop/reference.md +378 -0
- package/skills/blog-writing/SKILL.md +98 -0
- package/skills/blog-writing/reference.md +130 -0
- package/skills/brief-spec/SKILL.md +185 -0
- package/skills/command-execution/SKILL.md +64 -0
- package/skills/command-execution/reference.md +83 -0
- package/skills/context-updater/SKILL.md +87 -0
- package/skills/context-updater/examples.md +71 -0
- package/skills/developer-patterns/SKILL.md +50 -0
- package/skills/developer-patterns/reference.md +112 -0
- package/skills/execution/SKILL.md +99 -0
- package/skills/fast-queries/SKILL.md +43 -0
- package/skills/gaia-compact/SKILL.md +74 -0
- package/skills/gaia-patterns/SKILL.md +108 -0
- package/skills/gaia-patterns/reference.md +395 -0
- package/skills/gaia-planner/SKILL.md +37 -0
- package/skills/gaia-planner/reference.md +107 -0
- package/skills/gaia-release/SKILL.md +85 -0
- package/skills/gaia-release/reference.md +92 -0
- package/skills/gaia-self-check/SKILL.md +114 -0
- package/skills/gaia-self-check/reference.md +453 -0
- package/skills/gaia-verify/SKILL.md +77 -0
- package/skills/gaia-verify/reference.md +80 -0
- package/skills/git-conventions/SKILL.md +47 -0
- package/skills/gitops-patterns/SKILL.md +60 -0
- package/skills/gitops-patterns/reference.md +183 -0
- package/skills/gmail-policy/SKILL.md +200 -0
- package/skills/gmail-policy/reference.md +150 -0
- package/skills/gmail-triage/SKILL.md +100 -0
- package/skills/gws-setup/SKILL.md +99 -0
- package/skills/gws-setup/reference.md +73 -0
- package/skills/investigation/SKILL.md +100 -0
- package/skills/memory-curation/SKILL.md +83 -0
- package/skills/memory-search/SKILL.md +88 -0
- package/skills/orchestrator-approval/SKILL.md +160 -0
- package/skills/orchestrator-approval/reference.md +174 -0
- package/skills/pending-approvals/SKILL.md +72 -0
- package/skills/pending-approvals/reference.md +214 -0
- package/skills/readme-writing/SKILL.md +71 -0
- package/skills/readme-writing/reference.md +188 -0
- package/skills/reference.md +135 -0
- package/skills/request-approval/SKILL.md +140 -0
- package/skills/request-approval/examples.md +140 -0
- package/skills/request-approval/reference.md +57 -0
- package/skills/schedule-task/SKILL.md +64 -0
- package/skills/schedule-task/reference.md +233 -0
- package/skills/security-tiers/SKILL.md +141 -0
- package/skills/security-tiers/destructive-commands-reference.md +623 -0
- package/skills/security-tiers/reference.md +39 -0
- package/skills/session-reflection/SKILL.md +69 -0
- package/skills/skill-creation/SKILL.md +92 -0
- package/skills/skill-creation/reference.md +29 -0
- package/skills/terraform-patterns/SKILL.md +89 -0
- package/skills/terraform-patterns/reference.md +93 -0
- package/templates/README.md +69 -0
- package/templates/managed-settings.template.json +43 -0
- package/tools/__init__.py +9 -0
- package/tools/agentic-loop/decide-status.py +210 -0
- package/tools/agentic-loop/parse-metric.py +106 -0
- package/tools/agentic-loop/record-iteration.py +221 -0
- package/tools/context/README.md +132 -0
- package/tools/context/__init__.py +42 -0
- package/tools/context/_paths.py +20 -0
- package/tools/context/context_provider.py +721 -0
- package/tools/context/context_section_reader.py +342 -0
- package/tools/context/deep_merge.py +159 -0
- package/tools/context/pending_updates.py +760 -0
- package/tools/context/surface_router.py +278 -0
- package/tools/fast-queries/README.md +65 -0
- package/tools/fast-queries/__init__.py +30 -0
- package/tools/fast-queries/appservices/quicktriage_devops_developer.sh +75 -0
- package/tools/fast-queries/cloud/aws/quicktriage_aws_troubleshooter.sh +32 -0
- package/tools/fast-queries/cloud/gcp/quicktriage_gcp_troubleshooter.sh +88 -0
- package/tools/fast-queries/gitops/quicktriage_gitops_operator.sh +48 -0
- package/tools/fast-queries/run_triage.sh +59 -0
- package/tools/fast-queries/terraform/quicktriage_terraform_architect.sh +80 -0
- package/tools/gaia_simulator/__init__.py +33 -0
- package/tools/gaia_simulator/cli.py +354 -0
- package/tools/gaia_simulator/extractor.py +457 -0
- package/tools/gaia_simulator/reporter.py +258 -0
- package/tools/gaia_simulator/routing_simulator.py +334 -0
- package/tools/gaia_simulator/runner.py +539 -0
- package/tools/gaia_simulator/skills_mapper.py +264 -0
- package/tools/memory/README.md +0 -0
- package/tools/memory/__init__.py +20 -0
- package/tools/memory/backfill_fts5.py +107 -0
- package/tools/memory/conflict_detector.py +295 -0
- package/tools/memory/episodic.py +1210 -0
- package/tools/memory/git_invalidator.py +262 -0
- package/tools/memory/paths.py +102 -0
- package/tools/memory/scoring.py +193 -0
- package/tools/memory/search_store.py +375 -0
- package/tools/persist_transcript_analysis.py +85 -0
- package/tools/review/__init__.py +1 -0
- package/tools/review/review_engine.py +157 -0
- package/tools/scan/__init__.py +35 -0
- package/tools/scan/config.py +247 -0
- package/tools/scan/merge.py +212 -0
- package/tools/scan/orchestrator.py +549 -0
- package/tools/scan/registry.py +127 -0
- package/tools/scan/scanners/__init__.py +18 -0
- package/tools/scan/scanners/base.py +137 -0
- package/tools/scan/scanners/environment.py +349 -0
- package/tools/scan/scanners/git.py +570 -0
- package/tools/scan/scanners/infrastructure.py +875 -0
- package/tools/scan/scanners/orchestration.py +600 -0
- package/tools/scan/scanners/stack.py +1085 -0
- package/tools/scan/scanners/tools.py +260 -0
- package/tools/scan/setup.py +686 -0
- package/tools/scan/tests/__init__.py +1 -0
- package/tools/scan/tests/conftest.py +796 -0
- package/tools/scan/tests/test_environment.py +323 -0
- package/tools/scan/tests/test_git.py +419 -0
- package/tools/scan/tests/test_infrastructure.py +382 -0
- package/tools/scan/tests/test_integration.py +920 -0
- package/tools/scan/tests/test_merge.py +269 -0
- package/tools/scan/tests/test_orchestration.py +304 -0
- package/tools/scan/tests/test_stack.py +604 -0
- package/tools/scan/tests/test_tools.py +349 -0
- package/tools/scan/ui.py +624 -0
- package/tools/scan/verify.py +270 -0
- package/tools/scan/walk.py +118 -0
- package/tools/scan/workspace.py +85 -0
- package/tools/validation/README.md +244 -0
- package/tools/validation/__init__.py +17 -0
- package/tools/validation/approval_gate.py +321 -0
- package/tools/validation/validate_skills.py +189 -0
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Context Section Reader for Claude Agent System
|
|
4
|
+
|
|
5
|
+
Reads specific sections from project-context.json for selective loading by agents.
|
|
6
|
+
Called by Claude orchestrator BEFORE invoking agents to reduce token usage.
|
|
7
|
+
|
|
8
|
+
Architecture:
|
|
9
|
+
- Claude orchestrator executes this script (NOT agents)
|
|
10
|
+
- Agents receive pre-filtered context in their prompts
|
|
11
|
+
- Reduces token usage by ~70% per agent invocation
|
|
12
|
+
|
|
13
|
+
Usage:
|
|
14
|
+
from .claude.tools.context_section_reader import ContextSectionReader
|
|
15
|
+
|
|
16
|
+
reader = ContextSectionReader()
|
|
17
|
+
context = reader.get_for_agent('gitops-operator')
|
|
18
|
+
|
|
19
|
+
# Pass context to agent in Task tool prompt
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
from pathlib import Path
|
|
23
|
+
from typing import List, Dict, Optional, Any
|
|
24
|
+
import json
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def find_claude_dir() -> Path:
|
|
28
|
+
"""Find the .claude directory by searching upward from current location"""
|
|
29
|
+
current = Path.cwd()
|
|
30
|
+
|
|
31
|
+
# If we're already in a .claude directory, return it
|
|
32
|
+
if current.name == ".claude":
|
|
33
|
+
return current
|
|
34
|
+
|
|
35
|
+
# Look for .claude in current directory
|
|
36
|
+
claude_dir = current / ".claude"
|
|
37
|
+
if claude_dir.exists():
|
|
38
|
+
return claude_dir
|
|
39
|
+
|
|
40
|
+
# Search upward through parent directories
|
|
41
|
+
for parent in current.parents:
|
|
42
|
+
claude_dir = parent / ".claude"
|
|
43
|
+
if claude_dir.exists():
|
|
44
|
+
return claude_dir
|
|
45
|
+
|
|
46
|
+
# Fallback - raise error if not found
|
|
47
|
+
raise FileNotFoundError(
|
|
48
|
+
"No .claude directory found. Please run from a project directory "
|
|
49
|
+
"or specify context_file explicitly."
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class ContextSectionReader:
|
|
54
|
+
"""
|
|
55
|
+
Read and filter sections from project-context.json for agent-specific loading.
|
|
56
|
+
|
|
57
|
+
Token Optimization:
|
|
58
|
+
- Without filtering: ~328 lines (1,312 tokens)
|
|
59
|
+
- With filtering: ~80-100 lines (320-400 tokens)
|
|
60
|
+
- Savings: ~70% per agent invocation
|
|
61
|
+
"""
|
|
62
|
+
|
|
63
|
+
# Define which sections each agent needs (JSON keys in snake_case)
|
|
64
|
+
# Aligned with v2 scanner sections from context-contracts.json v3
|
|
65
|
+
AGENT_SECTIONS = {
|
|
66
|
+
'gitops-operator': [
|
|
67
|
+
'project_identity',
|
|
68
|
+
'stack',
|
|
69
|
+
'git',
|
|
70
|
+
'environment',
|
|
71
|
+
'infrastructure',
|
|
72
|
+
'orchestration',
|
|
73
|
+
'gitops_configuration',
|
|
74
|
+
'cluster_details',
|
|
75
|
+
'operational_guidelines',
|
|
76
|
+
'application_services',
|
|
77
|
+
],
|
|
78
|
+
'cloud-troubleshooter': [
|
|
79
|
+
'project_identity',
|
|
80
|
+
'stack',
|
|
81
|
+
'git',
|
|
82
|
+
'environment',
|
|
83
|
+
'infrastructure',
|
|
84
|
+
'orchestration',
|
|
85
|
+
'cluster_details',
|
|
86
|
+
'infrastructure_topology',
|
|
87
|
+
'terraform_infrastructure',
|
|
88
|
+
'gitops_configuration',
|
|
89
|
+
'application_services',
|
|
90
|
+
'monitoring_observability',
|
|
91
|
+
],
|
|
92
|
+
'terraform-architect': [
|
|
93
|
+
'project_identity',
|
|
94
|
+
'stack',
|
|
95
|
+
'git',
|
|
96
|
+
'environment',
|
|
97
|
+
'infrastructure',
|
|
98
|
+
'orchestration',
|
|
99
|
+
'terraform_infrastructure',
|
|
100
|
+
'infrastructure_topology',
|
|
101
|
+
'operational_guidelines',
|
|
102
|
+
'cluster_details',
|
|
103
|
+
'application_services',
|
|
104
|
+
],
|
|
105
|
+
'developer': [
|
|
106
|
+
'project_identity',
|
|
107
|
+
'stack',
|
|
108
|
+
'git',
|
|
109
|
+
'environment',
|
|
110
|
+
'infrastructure',
|
|
111
|
+
'application_services',
|
|
112
|
+
'operational_guidelines',
|
|
113
|
+
],
|
|
114
|
+
'gaia-operator': [
|
|
115
|
+
'project_identity',
|
|
116
|
+
'stack',
|
|
117
|
+
'git',
|
|
118
|
+
'environment',
|
|
119
|
+
'infrastructure',
|
|
120
|
+
'infrastructure_topology',
|
|
121
|
+
'application_services',
|
|
122
|
+
'architecture_overview',
|
|
123
|
+
'operational_guidelines',
|
|
124
|
+
'workspace_repos',
|
|
125
|
+
],
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
def __init__(self, context_file: Optional[str] = None):
|
|
129
|
+
"""
|
|
130
|
+
Initialize reader with project context file.
|
|
131
|
+
|
|
132
|
+
Args:
|
|
133
|
+
context_file: Path to project-context.json (default: searches for .claude/project-context/project-context.json)
|
|
134
|
+
"""
|
|
135
|
+
if context_file is None:
|
|
136
|
+
# Find the .claude directory by searching upward
|
|
137
|
+
claude_dir = find_claude_dir()
|
|
138
|
+
# Try project-context/ subdirectory first (new location)
|
|
139
|
+
context_file = claude_dir / "project-context" / "project-context.json"
|
|
140
|
+
if not Path(context_file).exists():
|
|
141
|
+
# Fallback to root .claude/ (old location)
|
|
142
|
+
context_file = claude_dir / "project-context.json"
|
|
143
|
+
|
|
144
|
+
self.path = Path(context_file)
|
|
145
|
+
|
|
146
|
+
if not self.path.exists():
|
|
147
|
+
raise FileNotFoundError(f"Context file not found: {self.path}")
|
|
148
|
+
|
|
149
|
+
with open(self.path, 'r', encoding='utf-8') as f:
|
|
150
|
+
self.data = json.load(f)
|
|
151
|
+
|
|
152
|
+
self._parse_sections()
|
|
153
|
+
|
|
154
|
+
def _parse_sections(self) -> None:
|
|
155
|
+
"""Extract sections from JSON data."""
|
|
156
|
+
self.sections: Dict[str, Any] = {}
|
|
157
|
+
|
|
158
|
+
# Extract sections from JSON
|
|
159
|
+
if 'sections' in self.data:
|
|
160
|
+
self.sections = self.data['sections']
|
|
161
|
+
else:
|
|
162
|
+
raise ValueError("Invalid JSON structure: 'sections' key not found")
|
|
163
|
+
|
|
164
|
+
def get_sections(self, section_names: List[str]) -> str:
|
|
165
|
+
"""
|
|
166
|
+
Get specific sections as formatted JSON string.
|
|
167
|
+
|
|
168
|
+
Args:
|
|
169
|
+
section_names: List of section names to retrieve
|
|
170
|
+
|
|
171
|
+
Returns:
|
|
172
|
+
Formatted JSON string with requested sections
|
|
173
|
+
"""
|
|
174
|
+
result = {}
|
|
175
|
+
missing = []
|
|
176
|
+
|
|
177
|
+
for name in section_names:
|
|
178
|
+
if name in self.sections:
|
|
179
|
+
result[name] = self.sections[name]
|
|
180
|
+
else:
|
|
181
|
+
missing.append(name)
|
|
182
|
+
|
|
183
|
+
if missing:
|
|
184
|
+
print(f"Warning: Sections not found: {missing}")
|
|
185
|
+
|
|
186
|
+
if not result:
|
|
187
|
+
return json.dumps({
|
|
188
|
+
"error": "No sections found",
|
|
189
|
+
"message": "Requested sections were not available."
|
|
190
|
+
}, indent=2)
|
|
191
|
+
|
|
192
|
+
# Format as JSON for agent consumption
|
|
193
|
+
return json.dumps(result, indent=2, ensure_ascii=False)
|
|
194
|
+
|
|
195
|
+
def get_for_agent(self, agent_name: str) -> str:
|
|
196
|
+
"""
|
|
197
|
+
Get sections needed by specific agent.
|
|
198
|
+
|
|
199
|
+
Args:
|
|
200
|
+
agent_name: Name of the agent (e.g., 'gitops-operator')
|
|
201
|
+
|
|
202
|
+
Returns:
|
|
203
|
+
Markdown string with agent-specific context
|
|
204
|
+
|
|
205
|
+
Raises:
|
|
206
|
+
ValueError: If agent_name is not recognized
|
|
207
|
+
"""
|
|
208
|
+
if agent_name not in self.AGENT_SECTIONS:
|
|
209
|
+
available = ', '.join(self.AGENT_SECTIONS.keys())
|
|
210
|
+
raise ValueError(
|
|
211
|
+
f"Unknown agent: {agent_name}. "
|
|
212
|
+
f"Available agents: {available}"
|
|
213
|
+
)
|
|
214
|
+
|
|
215
|
+
sections = self.AGENT_SECTIONS[agent_name]
|
|
216
|
+
return self.get_sections(sections)
|
|
217
|
+
|
|
218
|
+
def list_sections(self) -> List[str]:
|
|
219
|
+
"""Get list of all available sections."""
|
|
220
|
+
return list(self.sections.keys())
|
|
221
|
+
|
|
222
|
+
def get_stats(self) -> Dict[str, Any]:
|
|
223
|
+
"""
|
|
224
|
+
Get statistics about the context file.
|
|
225
|
+
|
|
226
|
+
Returns:
|
|
227
|
+
Dictionary with size and token estimates
|
|
228
|
+
"""
|
|
229
|
+
# Calculate total JSON size
|
|
230
|
+
total_json = json.dumps(self.data, ensure_ascii=False)
|
|
231
|
+
total_chars = len(total_json)
|
|
232
|
+
total_tokens = total_chars // 4 # Rough estimate: 4 chars per token
|
|
233
|
+
|
|
234
|
+
return {
|
|
235
|
+
'total_chars': total_chars,
|
|
236
|
+
'total_tokens_estimated': total_tokens,
|
|
237
|
+
'total_sections': len(self.sections),
|
|
238
|
+
'sections': {
|
|
239
|
+
name: {
|
|
240
|
+
'chars': len(json.dumps(content, ensure_ascii=False)),
|
|
241
|
+
'tokens_estimated': len(json.dumps(content, ensure_ascii=False)) // 4
|
|
242
|
+
}
|
|
243
|
+
for name, content in self.sections.items()
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
def get_agent_stats(self, agent_name: str) -> Dict[str, Any]:
|
|
248
|
+
"""
|
|
249
|
+
Get statistics for a specific agent's context.
|
|
250
|
+
|
|
251
|
+
Args:
|
|
252
|
+
agent_name: Name of the agent
|
|
253
|
+
|
|
254
|
+
Returns:
|
|
255
|
+
Dictionary with character and token counts for agent
|
|
256
|
+
"""
|
|
257
|
+
context = self.get_for_agent(agent_name)
|
|
258
|
+
chars = len(context)
|
|
259
|
+
tokens = chars // 4
|
|
260
|
+
|
|
261
|
+
full_stats = self.get_stats()
|
|
262
|
+
savings = {
|
|
263
|
+
'chars': full_stats['total_chars'] - chars,
|
|
264
|
+
'tokens': full_stats['total_tokens_estimated'] - tokens,
|
|
265
|
+
'percentage': round((1 - chars / full_stats['total_chars']) * 100, 1)
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
return {
|
|
269
|
+
'agent': agent_name,
|
|
270
|
+
'chars_loaded': chars,
|
|
271
|
+
'tokens_estimated': tokens,
|
|
272
|
+
'savings': savings
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
def main():
|
|
277
|
+
"""CLI interface for testing and debugging."""
|
|
278
|
+
import sys
|
|
279
|
+
import json
|
|
280
|
+
|
|
281
|
+
reader = ContextSectionReader()
|
|
282
|
+
|
|
283
|
+
if len(sys.argv) < 2:
|
|
284
|
+
print("Context Section Reader")
|
|
285
|
+
print("\nUsage:")
|
|
286
|
+
print(" python context_section_reader.py <command> [args]")
|
|
287
|
+
print("\nCommands:")
|
|
288
|
+
print(" list - List all available sections")
|
|
289
|
+
print(" stats - Show statistics for context file")
|
|
290
|
+
print(" agent <name> - Get context for specific agent")
|
|
291
|
+
print(" agent-stats <name> - Show stats for agent's context")
|
|
292
|
+
print(" sections <name1> <name2> - Get specific sections")
|
|
293
|
+
print("\nAvailable agents:")
|
|
294
|
+
for agent in reader.AGENT_SECTIONS.keys():
|
|
295
|
+
print(f" - {agent}")
|
|
296
|
+
sys.exit(0)
|
|
297
|
+
|
|
298
|
+
command = sys.argv[1]
|
|
299
|
+
|
|
300
|
+
if command == 'list':
|
|
301
|
+
print("Available sections:")
|
|
302
|
+
for section in reader.list_sections():
|
|
303
|
+
print(f" - {section}")
|
|
304
|
+
|
|
305
|
+
elif command == 'stats':
|
|
306
|
+
stats = reader.get_stats()
|
|
307
|
+
print(json.dumps(stats, indent=2))
|
|
308
|
+
|
|
309
|
+
elif command == 'agent':
|
|
310
|
+
if len(sys.argv) < 3:
|
|
311
|
+
print("Error: Agent name required")
|
|
312
|
+
sys.exit(1)
|
|
313
|
+
|
|
314
|
+
agent_name = sys.argv[2]
|
|
315
|
+
context = reader.get_for_agent(agent_name)
|
|
316
|
+
print(context)
|
|
317
|
+
|
|
318
|
+
elif command == 'agent-stats':
|
|
319
|
+
if len(sys.argv) < 3:
|
|
320
|
+
print("Error: Agent name required")
|
|
321
|
+
sys.exit(1)
|
|
322
|
+
|
|
323
|
+
agent_name = sys.argv[2]
|
|
324
|
+
stats = reader.get_agent_stats(agent_name)
|
|
325
|
+
print(json.dumps(stats, indent=2))
|
|
326
|
+
|
|
327
|
+
elif command == 'sections':
|
|
328
|
+
if len(sys.argv) < 3:
|
|
329
|
+
print("Error: Section names required")
|
|
330
|
+
sys.exit(1)
|
|
331
|
+
|
|
332
|
+
section_names = sys.argv[2:]
|
|
333
|
+
context = reader.get_sections(section_names)
|
|
334
|
+
print(context)
|
|
335
|
+
|
|
336
|
+
else:
|
|
337
|
+
print(f"Unknown command: {command}")
|
|
338
|
+
sys.exit(1)
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
if __name__ == '__main__':
|
|
342
|
+
main()
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Deep merge utility for project-context.json updates.
|
|
3
|
+
|
|
4
|
+
Merges two dicts recursively following the gaia-ops merge decision tree:
|
|
5
|
+
1. Key missing in current -> ADD
|
|
6
|
+
2. Both values are dicts -> RECURSE (deep merge)
|
|
7
|
+
3. Both values are lists -> UNION (primitives: sorted set union;
|
|
8
|
+
dicts with "name": merge by name;
|
|
9
|
+
other dicts: concatenate + deduplicate)
|
|
10
|
+
4. Both values are scalars -> OVERWRITE (new replaces old)
|
|
11
|
+
5. Type mismatch -> OVERWRITE with warning
|
|
12
|
+
|
|
13
|
+
No-Delete Policy: keys in current but NOT in update are always preserved.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
import copy
|
|
17
|
+
import json
|
|
18
|
+
import logging
|
|
19
|
+
|
|
20
|
+
logger = logging.getLogger(__name__)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def deep_merge(current: dict, update: dict) -> tuple[dict, dict]:
|
|
24
|
+
"""Merge *update* into *current* returning ``(merged, diff)``.
|
|
25
|
+
|
|
26
|
+
Parameters
|
|
27
|
+
----------
|
|
28
|
+
current:
|
|
29
|
+
The existing data (will NOT be mutated).
|
|
30
|
+
update:
|
|
31
|
+
New data to merge on top of *current*.
|
|
32
|
+
|
|
33
|
+
Returns
|
|
34
|
+
-------
|
|
35
|
+
tuple[dict, dict]
|
|
36
|
+
``merged`` – the result of the merge.
|
|
37
|
+
``diff`` – audit trail recording changes (``{key: {old, new}}``).
|
|
38
|
+
"""
|
|
39
|
+
merged = copy.deepcopy(current)
|
|
40
|
+
diff: dict = {}
|
|
41
|
+
|
|
42
|
+
for key, new_value in update.items():
|
|
43
|
+
if key not in merged:
|
|
44
|
+
# Rule 1: ADD missing key
|
|
45
|
+
merged[key] = copy.deepcopy(new_value)
|
|
46
|
+
continue
|
|
47
|
+
|
|
48
|
+
old_value = merged[key]
|
|
49
|
+
|
|
50
|
+
# Rule 2: Both dicts -> recurse
|
|
51
|
+
if isinstance(old_value, dict) and isinstance(new_value, dict):
|
|
52
|
+
sub_merged, sub_diff = deep_merge(old_value, new_value)
|
|
53
|
+
merged[key] = sub_merged
|
|
54
|
+
if sub_diff:
|
|
55
|
+
diff[key] = sub_diff
|
|
56
|
+
continue
|
|
57
|
+
|
|
58
|
+
# Rule 3: Both lists -> union strategy
|
|
59
|
+
if isinstance(old_value, list) and isinstance(new_value, list):
|
|
60
|
+
merged_list = _merge_lists(old_value, new_value)
|
|
61
|
+
if merged_list != old_value:
|
|
62
|
+
diff[key] = {"old": old_value, "new": merged_list}
|
|
63
|
+
merged[key] = merged_list
|
|
64
|
+
continue
|
|
65
|
+
|
|
66
|
+
# Rule 5: Type mismatch -> overwrite with warning
|
|
67
|
+
if type(old_value) is not type(new_value):
|
|
68
|
+
logger.warning(
|
|
69
|
+
"Type mismatch for key '%s': %s -> %s. New value wins.",
|
|
70
|
+
key,
|
|
71
|
+
type(old_value).__name__,
|
|
72
|
+
type(new_value).__name__,
|
|
73
|
+
)
|
|
74
|
+
diff[key] = {"old": old_value, "new": new_value}
|
|
75
|
+
merged[key] = copy.deepcopy(new_value)
|
|
76
|
+
continue
|
|
77
|
+
|
|
78
|
+
# Rule 4: Both scalars -> overwrite
|
|
79
|
+
if old_value != new_value:
|
|
80
|
+
diff[key] = {"old": old_value, "new": new_value}
|
|
81
|
+
merged[key] = copy.deepcopy(new_value)
|
|
82
|
+
|
|
83
|
+
return merged, diff
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
# ---------------------------------------------------------------------------
|
|
87
|
+
# List merge helpers
|
|
88
|
+
# ---------------------------------------------------------------------------
|
|
89
|
+
|
|
90
|
+
def _merge_lists(current: list, update: list) -> list:
|
|
91
|
+
"""Merge two lists following the union strategy.
|
|
92
|
+
|
|
93
|
+
a) All items are primitives (str, int, float, bool) -> sorted set union.
|
|
94
|
+
b) Items are dicts with a ``"name"`` key -> merge by name, preserve missing.
|
|
95
|
+
c) Otherwise -> concatenate, deduplicate by JSON equality.
|
|
96
|
+
"""
|
|
97
|
+
if _all_primitives(current) and _all_primitives(update):
|
|
98
|
+
return sorted(set(current) | set(update))
|
|
99
|
+
|
|
100
|
+
if _all_dicts_with_name(current) and _all_dicts_with_name(update):
|
|
101
|
+
return _merge_named_dicts(current, update)
|
|
102
|
+
|
|
103
|
+
# Fallback: concatenate + deduplicate by JSON equality
|
|
104
|
+
return _concat_deduplicate(current, update)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def _all_primitives(items: list) -> bool:
|
|
108
|
+
"""Return True if every item is a primitive (str, int, float, bool)."""
|
|
109
|
+
return all(isinstance(i, (str, int, float, bool)) for i in items)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def _all_dicts_with_name(items: list) -> bool:
|
|
113
|
+
"""Return True if every item is a dict containing a ``"name"`` key."""
|
|
114
|
+
return bool(items) and all(
|
|
115
|
+
isinstance(i, dict) and "name" in i for i in items
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def _merge_named_dicts(current: list[dict], update: list[dict]) -> list[dict]:
|
|
120
|
+
"""Merge lists of dicts by their ``"name"`` field.
|
|
121
|
+
|
|
122
|
+
- Matching names: deep-merge the dict fields.
|
|
123
|
+
- Names only in current: preserved (no-delete).
|
|
124
|
+
- Names only in update: appended.
|
|
125
|
+
"""
|
|
126
|
+
result_by_name: dict[str, dict] = {}
|
|
127
|
+
order: list[str] = []
|
|
128
|
+
|
|
129
|
+
# Seed with current entries (preserves order + no-delete)
|
|
130
|
+
for item in current:
|
|
131
|
+
name = item["name"]
|
|
132
|
+
result_by_name[name] = copy.deepcopy(item)
|
|
133
|
+
order.append(name)
|
|
134
|
+
|
|
135
|
+
# Merge / add from update
|
|
136
|
+
for item in update:
|
|
137
|
+
name = item["name"]
|
|
138
|
+
if name in result_by_name:
|
|
139
|
+
merged_item, _ = deep_merge(result_by_name[name], item)
|
|
140
|
+
result_by_name[name] = merged_item
|
|
141
|
+
else:
|
|
142
|
+
result_by_name[name] = copy.deepcopy(item)
|
|
143
|
+
order.append(name)
|
|
144
|
+
|
|
145
|
+
return [result_by_name[n] for n in order]
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def _concat_deduplicate(current: list, update: list) -> list:
|
|
149
|
+
"""Concatenate two lists, deduplicating by JSON equality."""
|
|
150
|
+
seen: list[str] = []
|
|
151
|
+
result: list = []
|
|
152
|
+
|
|
153
|
+
for item in current + update:
|
|
154
|
+
serialized = json.dumps(item, sort_keys=True)
|
|
155
|
+
if serialized not in seen:
|
|
156
|
+
seen.append(serialized)
|
|
157
|
+
result.append(copy.deepcopy(item))
|
|
158
|
+
|
|
159
|
+
return result
|