@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,483 @@
|
|
|
1
|
+
"""
|
|
2
|
+
gaia memory -- Inspect and query Gaia episodic memory (read-only).
|
|
3
|
+
|
|
4
|
+
Subcommands:
|
|
5
|
+
search <query> [--limit N] [--json] FTS5 search with hybrid scoring
|
|
6
|
+
stats [--json] Episode count, index count, scores, conflicts
|
|
7
|
+
show <episode_id> [--json] Full episode with metadata and score
|
|
8
|
+
conflicts [--threshold F] [--json] Contradiction scan across memory files
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import json
|
|
12
|
+
import sys
|
|
13
|
+
from datetime import datetime, timezone
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# ---------------------------------------------------------------------------
|
|
18
|
+
# Root detection
|
|
19
|
+
# ---------------------------------------------------------------------------
|
|
20
|
+
|
|
21
|
+
def _find_project_root() -> Path:
|
|
22
|
+
"""Return the Gaia instance root: the highest ancestor with a .claude/ dir.
|
|
23
|
+
|
|
24
|
+
Walks upward from cwd to Path.home(), collects every directory that
|
|
25
|
+
contains a .claude/ subdirectory, and returns the one closest to HOME
|
|
26
|
+
(the top-most one). This prevents a nested .claude/ in a sub-repository
|
|
27
|
+
or dev checkout from shadowing the real Gaia instance.
|
|
28
|
+
|
|
29
|
+
Falls back to INIT_CWD if set and no .claude/ ancestor is found.
|
|
30
|
+
"""
|
|
31
|
+
import sys as _sys
|
|
32
|
+
import os
|
|
33
|
+
|
|
34
|
+
# Resolve via the shared helper (tools/memory/paths.py).
|
|
35
|
+
# Build the import path so this works regardless of sys.path state.
|
|
36
|
+
_tools_dir = Path(__file__).resolve().parent.parent.parent / "tools"
|
|
37
|
+
if str(_tools_dir) not in _sys.path:
|
|
38
|
+
_sys.path.insert(0, str(_tools_dir))
|
|
39
|
+
|
|
40
|
+
try:
|
|
41
|
+
from memory.paths import find_highest_claude_root
|
|
42
|
+
root = find_highest_claude_root()
|
|
43
|
+
if root is not None:
|
|
44
|
+
return root
|
|
45
|
+
except ImportError:
|
|
46
|
+
pass
|
|
47
|
+
|
|
48
|
+
# Fallback: honour INIT_CWD if the helper was unavailable or found nothing.
|
|
49
|
+
init_cwd = os.environ.get("INIT_CWD")
|
|
50
|
+
if init_cwd and (Path(init_cwd) / ".claude").is_dir():
|
|
51
|
+
return Path(init_cwd)
|
|
52
|
+
|
|
53
|
+
return Path.cwd()
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _memory_base(project_root: Path) -> Path:
|
|
57
|
+
return project_root / ".claude" / "project-context" / "episodic-memory"
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
# ---------------------------------------------------------------------------
|
|
61
|
+
# Lazy imports
|
|
62
|
+
# ---------------------------------------------------------------------------
|
|
63
|
+
|
|
64
|
+
def _import_search_store():
|
|
65
|
+
try:
|
|
66
|
+
from tools.memory import search_store
|
|
67
|
+
return search_store
|
|
68
|
+
except ImportError:
|
|
69
|
+
return None
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _import_episodic():
|
|
73
|
+
try:
|
|
74
|
+
from tools.memory.episodic import EpisodicMemory
|
|
75
|
+
return EpisodicMemory
|
|
76
|
+
except ImportError:
|
|
77
|
+
return None
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def _import_scoring():
|
|
81
|
+
try:
|
|
82
|
+
from tools.memory.scoring import score_memory
|
|
83
|
+
return score_memory
|
|
84
|
+
except ImportError:
|
|
85
|
+
return None
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def _import_conflict_detector():
|
|
89
|
+
try:
|
|
90
|
+
from tools.memory.conflict_detector import detect_conflicts
|
|
91
|
+
return detect_conflicts
|
|
92
|
+
except ImportError:
|
|
93
|
+
return None
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
# ---------------------------------------------------------------------------
|
|
97
|
+
# Helpers
|
|
98
|
+
# ---------------------------------------------------------------------------
|
|
99
|
+
|
|
100
|
+
def _days_old(timestamp_str: str) -> float:
|
|
101
|
+
"""Compute age in days from an ISO-8601 timestamp string."""
|
|
102
|
+
if not timestamp_str:
|
|
103
|
+
return 0.0
|
|
104
|
+
try:
|
|
105
|
+
ts = timestamp_str
|
|
106
|
+
if ts.endswith("Z"):
|
|
107
|
+
ts = ts[:-1] + "+00:00"
|
|
108
|
+
recorded = datetime.fromisoformat(ts)
|
|
109
|
+
if recorded.tzinfo is None:
|
|
110
|
+
recorded = recorded.replace(tzinfo=timezone.utc)
|
|
111
|
+
delta = datetime.now(tz=timezone.utc) - recorded
|
|
112
|
+
return max(0.0, delta.total_seconds() / 86400.0)
|
|
113
|
+
except (ValueError, AttributeError):
|
|
114
|
+
return 0.0
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def _load_index(project_root: Path) -> dict:
|
|
118
|
+
"""Load index.json from episodic memory dir. Returns empty index on failure."""
|
|
119
|
+
index_path = _memory_base(project_root) / "index.json"
|
|
120
|
+
if not index_path.is_file():
|
|
121
|
+
return {"episodes": []}
|
|
122
|
+
try:
|
|
123
|
+
return json.loads(index_path.read_text())
|
|
124
|
+
except Exception:
|
|
125
|
+
return {"episodes": []}
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def _err(msg: str, as_json: bool) -> int:
|
|
129
|
+
"""Print an error and return exit code 1."""
|
|
130
|
+
if as_json:
|
|
131
|
+
print(json.dumps({"error": msg}))
|
|
132
|
+
else:
|
|
133
|
+
print(f"Error: {msg}", file=sys.stderr)
|
|
134
|
+
return 1
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
# ---------------------------------------------------------------------------
|
|
138
|
+
# Subcommand handlers
|
|
139
|
+
# ---------------------------------------------------------------------------
|
|
140
|
+
|
|
141
|
+
def _cmd_search(args) -> int:
|
|
142
|
+
"""Handle `gaia memory search <query> [--limit N]`."""
|
|
143
|
+
as_json = getattr(args, "json", False)
|
|
144
|
+
query = args.query
|
|
145
|
+
limit = getattr(args, "limit", 10)
|
|
146
|
+
|
|
147
|
+
search_store = _import_search_store()
|
|
148
|
+
EpisodicMemory = _import_episodic()
|
|
149
|
+
score_memory = _import_scoring()
|
|
150
|
+
|
|
151
|
+
if search_store is None:
|
|
152
|
+
return _err("search_store module not available", as_json)
|
|
153
|
+
|
|
154
|
+
raw_results = search_store.search(query, max_results=limit)
|
|
155
|
+
|
|
156
|
+
results = []
|
|
157
|
+
for hit in raw_results:
|
|
158
|
+
episode_id = hit.get("episode_id", "")
|
|
159
|
+
rank = hit.get("rank", 0.0)
|
|
160
|
+
|
|
161
|
+
# Enrich via episodic module
|
|
162
|
+
episode = None
|
|
163
|
+
if EpisodicMemory is not None:
|
|
164
|
+
try:
|
|
165
|
+
mem = EpisodicMemory()
|
|
166
|
+
episode = mem.get_episode(episode_id)
|
|
167
|
+
except Exception:
|
|
168
|
+
episode = None
|
|
169
|
+
|
|
170
|
+
if episode is None:
|
|
171
|
+
# Minimal record from rank alone
|
|
172
|
+
results.append({
|
|
173
|
+
"id": episode_id,
|
|
174
|
+
"title": "",
|
|
175
|
+
"score": 0.0,
|
|
176
|
+
"date": "",
|
|
177
|
+
"snippet": "",
|
|
178
|
+
})
|
|
179
|
+
continue
|
|
180
|
+
|
|
181
|
+
# Compute hybrid score
|
|
182
|
+
days = _days_old(episode.get("timestamp", ""))
|
|
183
|
+
retrieval_count = int(episode.get("retrieval_count", 0))
|
|
184
|
+
if score_memory is not None:
|
|
185
|
+
try:
|
|
186
|
+
hybrid_score = score_memory(days_old=days, retrieval_count=retrieval_count)
|
|
187
|
+
except Exception:
|
|
188
|
+
hybrid_score = 0.0
|
|
189
|
+
else:
|
|
190
|
+
hybrid_score = 0.0
|
|
191
|
+
|
|
192
|
+
# Snippet: first 120 chars of enriched_prompt or prompt
|
|
193
|
+
text = episode.get("enriched_prompt") or episode.get("prompt") or ""
|
|
194
|
+
snippet = text[:120] + ("..." if len(text) > 120 else "")
|
|
195
|
+
|
|
196
|
+
results.append({
|
|
197
|
+
"id": episode_id,
|
|
198
|
+
"title": episode.get("title") or "",
|
|
199
|
+
"score": round(hybrid_score, 4),
|
|
200
|
+
"date": episode.get("timestamp", "")[:10], # YYYY-MM-DD
|
|
201
|
+
"snippet": snippet,
|
|
202
|
+
})
|
|
203
|
+
|
|
204
|
+
output = {"results": results}
|
|
205
|
+
if as_json:
|
|
206
|
+
print(json.dumps(output, indent=2))
|
|
207
|
+
else:
|
|
208
|
+
if not results:
|
|
209
|
+
print("No results found.")
|
|
210
|
+
else:
|
|
211
|
+
for i, r in enumerate(results, 1):
|
|
212
|
+
print(f"\n{i}. [{r['score']:.4f}] {r['title'] or r['id']}")
|
|
213
|
+
print(f" Date: {r['date']}")
|
|
214
|
+
print(f" {r['snippet']}")
|
|
215
|
+
return 0
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def _cmd_stats(args) -> int:
|
|
219
|
+
"""Handle `gaia memory stats`."""
|
|
220
|
+
as_json = getattr(args, "json", False)
|
|
221
|
+
project_root = _find_project_root()
|
|
222
|
+
|
|
223
|
+
index = _load_index(project_root)
|
|
224
|
+
episodes = index.get("episodes", [])
|
|
225
|
+
total_episodes = len(episodes)
|
|
226
|
+
|
|
227
|
+
search_store = _import_search_store()
|
|
228
|
+
score_memory = _import_scoring()
|
|
229
|
+
detect_conflicts = _import_conflict_detector()
|
|
230
|
+
|
|
231
|
+
warnings: list[str] = []
|
|
232
|
+
|
|
233
|
+
# Indexed count. The FTS5 backend returns -1 as a sentinel when path
|
|
234
|
+
# resolution / connection fails (e.g. broken `.claude/*` symlinks).
|
|
235
|
+
# Previously we silently coerced that to 0, which hid drift: `doctor`
|
|
236
|
+
# would report 102/102 while `memory stats` reported 0/0 with no
|
|
237
|
+
# indication anything was wrong. Now we surface it explicitly.
|
|
238
|
+
indexed: int = 0
|
|
239
|
+
if search_store is not None:
|
|
240
|
+
try:
|
|
241
|
+
raw = search_store.count()
|
|
242
|
+
except Exception:
|
|
243
|
+
raw = -1
|
|
244
|
+
if isinstance(raw, int) and raw < 0:
|
|
245
|
+
warnings.append(
|
|
246
|
+
"FTS5 index path not resolved — symlinks may be broken. "
|
|
247
|
+
"Run: gaia doctor"
|
|
248
|
+
)
|
|
249
|
+
indexed = raw # keep the sentinel visible in JSON output
|
|
250
|
+
else:
|
|
251
|
+
indexed = int(raw) if isinstance(raw, int) else 0
|
|
252
|
+
|
|
253
|
+
# avg_score from a sample of episodes
|
|
254
|
+
avg_score = 0.0
|
|
255
|
+
if score_memory is not None and episodes:
|
|
256
|
+
sample = episodes[:100] # cap to avoid slow computation on huge indexes
|
|
257
|
+
scores = []
|
|
258
|
+
for ep in sample:
|
|
259
|
+
try:
|
|
260
|
+
days = _days_old(ep.get("timestamp", ""))
|
|
261
|
+
rc = int(ep.get("retrieval_count", 0))
|
|
262
|
+
scores.append(score_memory(days_old=days, retrieval_count=rc))
|
|
263
|
+
except Exception:
|
|
264
|
+
pass
|
|
265
|
+
if scores:
|
|
266
|
+
avg_score = round(sum(scores) / len(scores), 4)
|
|
267
|
+
|
|
268
|
+
# Conflict count
|
|
269
|
+
conflicts_count = 0
|
|
270
|
+
if detect_conflicts is not None:
|
|
271
|
+
try:
|
|
272
|
+
mem_dir = project_root / ".claude" / "projects" / "-home-jorge-ws-me" / "memory"
|
|
273
|
+
if not mem_dir.is_dir():
|
|
274
|
+
# Try the user memory default
|
|
275
|
+
mem_dir = Path.home() / ".claude" / "projects" / "-home-jorge-ws-me" / "memory"
|
|
276
|
+
raw_conflicts = detect_conflicts(memory_dir=mem_dir)
|
|
277
|
+
conflicts_count = len(raw_conflicts)
|
|
278
|
+
except Exception:
|
|
279
|
+
conflicts_count = 0
|
|
280
|
+
|
|
281
|
+
output = {
|
|
282
|
+
"total_episodes": total_episodes,
|
|
283
|
+
"indexed": indexed,
|
|
284
|
+
"avg_score": avg_score,
|
|
285
|
+
"conflicts": conflicts_count,
|
|
286
|
+
"warnings": warnings,
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
if as_json:
|
|
290
|
+
print(json.dumps(output, indent=2))
|
|
291
|
+
else:
|
|
292
|
+
indexed_display = "unknown" if indexed < 0 else str(indexed)
|
|
293
|
+
print(f"\n Memory Stats")
|
|
294
|
+
print(f" Total episodes : {total_episodes}")
|
|
295
|
+
print(f" FTS5 indexed : {indexed_display}")
|
|
296
|
+
print(f" Avg score : {avg_score:.4f}")
|
|
297
|
+
print(f" Conflicts : {conflicts_count}")
|
|
298
|
+
for w in warnings:
|
|
299
|
+
print(f" WARN: {w}", file=sys.stderr)
|
|
300
|
+
print()
|
|
301
|
+
|
|
302
|
+
return 0
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
def _cmd_show(args) -> int:
|
|
306
|
+
"""Handle `gaia memory show <episode_id>`."""
|
|
307
|
+
as_json = getattr(args, "json", False)
|
|
308
|
+
episode_id = args.episode_id
|
|
309
|
+
|
|
310
|
+
EpisodicMemory = _import_episodic()
|
|
311
|
+
score_memory = _import_scoring()
|
|
312
|
+
|
|
313
|
+
if EpisodicMemory is None:
|
|
314
|
+
return _err("episodic module not available", as_json)
|
|
315
|
+
|
|
316
|
+
try:
|
|
317
|
+
mem = EpisodicMemory()
|
|
318
|
+
episode = mem.get_episode(episode_id)
|
|
319
|
+
except Exception as exc:
|
|
320
|
+
return _err(f"Could not load episode: {exc}", as_json)
|
|
321
|
+
|
|
322
|
+
if episode is None:
|
|
323
|
+
return _err(f"Episode not found: {episode_id}", as_json)
|
|
324
|
+
|
|
325
|
+
# Compute score
|
|
326
|
+
days = _days_old(episode.get("timestamp", ""))
|
|
327
|
+
retrieval_count = int(episode.get("retrieval_count", 0))
|
|
328
|
+
if score_memory is not None:
|
|
329
|
+
try:
|
|
330
|
+
score = round(score_memory(days_old=days, retrieval_count=retrieval_count), 4)
|
|
331
|
+
except Exception:
|
|
332
|
+
score = 0.0
|
|
333
|
+
else:
|
|
334
|
+
score = 0.0
|
|
335
|
+
|
|
336
|
+
output = {
|
|
337
|
+
"id": episode.get("episode_id") or episode.get("id") or episode_id,
|
|
338
|
+
"title": episode.get("title") or "",
|
|
339
|
+
"content": episode.get("enriched_prompt") or episode.get("prompt") or "",
|
|
340
|
+
"score": score,
|
|
341
|
+
"tags": episode.get("tags") or [],
|
|
342
|
+
"retrieval_count": retrieval_count,
|
|
343
|
+
"age_days": round(days, 2),
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
if as_json:
|
|
347
|
+
print(json.dumps(output, indent=2))
|
|
348
|
+
else:
|
|
349
|
+
print(f"\n Episode: {output['id']}")
|
|
350
|
+
print(f" Title : {output['title']}")
|
|
351
|
+
print(f" Score : {output['score']}")
|
|
352
|
+
print(f" Age : {output['age_days']} days")
|
|
353
|
+
print(f" Tags : {', '.join(output['tags']) if output['tags'] else 'none'}")
|
|
354
|
+
print(f" Retrievals: {output['retrieval_count']}")
|
|
355
|
+
print(f"\n Content:\n {output['content'][:500]}\n")
|
|
356
|
+
|
|
357
|
+
return 0
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
def _cmd_conflicts(args) -> int:
|
|
361
|
+
"""Handle `gaia memory conflicts [--threshold F]`."""
|
|
362
|
+
as_json = getattr(args, "json", False)
|
|
363
|
+
threshold = getattr(args, "threshold", 0.3)
|
|
364
|
+
|
|
365
|
+
detect_conflicts = _import_conflict_detector()
|
|
366
|
+
|
|
367
|
+
if detect_conflicts is None:
|
|
368
|
+
return _err("conflict_detector module not available", as_json)
|
|
369
|
+
|
|
370
|
+
project_root = _find_project_root()
|
|
371
|
+
|
|
372
|
+
try:
|
|
373
|
+
# Use the default memory dir (same as detect_conflicts default)
|
|
374
|
+
raw = detect_conflicts(threshold=threshold)
|
|
375
|
+
except Exception as exc:
|
|
376
|
+
return _err(f"Conflict detection failed: {exc}", as_json)
|
|
377
|
+
|
|
378
|
+
# Normalize: similarity -> score, flatten conflicts list into reason string
|
|
379
|
+
conflicts_out = []
|
|
380
|
+
for item in raw:
|
|
381
|
+
inner = item.get("conflicts", [])
|
|
382
|
+
reason = "; ".join(c.get("reason", "") for c in inner) if inner else "high similarity"
|
|
383
|
+
conflicts_out.append({
|
|
384
|
+
"file_a": item.get("file_a", ""),
|
|
385
|
+
"file_b": item.get("file_b", ""),
|
|
386
|
+
"score": item.get("similarity", 0.0), # similarity -> score
|
|
387
|
+
"reason": reason,
|
|
388
|
+
})
|
|
389
|
+
|
|
390
|
+
output = {"conflicts": conflicts_out}
|
|
391
|
+
|
|
392
|
+
if as_json:
|
|
393
|
+
print(json.dumps(output, indent=2))
|
|
394
|
+
else:
|
|
395
|
+
if not conflicts_out:
|
|
396
|
+
print("No conflicts detected.")
|
|
397
|
+
else:
|
|
398
|
+
print(f"\n {len(conflicts_out)} conflict(s) found:\n")
|
|
399
|
+
for c in conflicts_out:
|
|
400
|
+
print(f" [{c['score']:.4f}] {Path(c['file_a']).name} <-> {Path(c['file_b']).name}")
|
|
401
|
+
print(f" Reason: {c['reason']}\n")
|
|
402
|
+
|
|
403
|
+
return 0
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
# ---------------------------------------------------------------------------
|
|
407
|
+
# Dispatcher + registration
|
|
408
|
+
# ---------------------------------------------------------------------------
|
|
409
|
+
|
|
410
|
+
def cmd_memory(args) -> int:
|
|
411
|
+
"""Top-level dispatcher for `gaia memory <action>`."""
|
|
412
|
+
func = getattr(args, "func", None)
|
|
413
|
+
if func is None:
|
|
414
|
+
# No subcommand given — print help via argparse
|
|
415
|
+
if hasattr(args, "_memory_parser"):
|
|
416
|
+
args._memory_parser.print_help()
|
|
417
|
+
else:
|
|
418
|
+
print("Usage: gaia memory <search|stats|show|conflicts>", file=sys.stderr)
|
|
419
|
+
return 0
|
|
420
|
+
return func(args) or 0
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
def register(subparsers):
|
|
424
|
+
"""Register the memory subcommand with nested sub-actions."""
|
|
425
|
+
mem_parser = subparsers.add_parser(
|
|
426
|
+
"memory",
|
|
427
|
+
help="Inspect and query Gaia episodic memory (read-only)",
|
|
428
|
+
)
|
|
429
|
+
mem_parser.add_argument(
|
|
430
|
+
"--json",
|
|
431
|
+
action="store_true",
|
|
432
|
+
default=False,
|
|
433
|
+
help="Output as JSON (machine-readable)",
|
|
434
|
+
)
|
|
435
|
+
|
|
436
|
+
# Stash parser reference so dispatcher can print help when no subcommand given
|
|
437
|
+
mem_parser.set_defaults(_memory_parser=mem_parser)
|
|
438
|
+
|
|
439
|
+
actions = mem_parser.add_subparsers(dest="memory_action", metavar="<action>")
|
|
440
|
+
|
|
441
|
+
# -- search ---------------------------------------------------------------
|
|
442
|
+
search_p = actions.add_parser("search", help="FTS5 search with hybrid scoring")
|
|
443
|
+
search_p.add_argument("query", help="Search query")
|
|
444
|
+
search_p.add_argument(
|
|
445
|
+
"--limit", type=int, default=10, metavar="N",
|
|
446
|
+
help="Maximum number of results (default: 10)",
|
|
447
|
+
)
|
|
448
|
+
search_p.add_argument(
|
|
449
|
+
"--json", action="store_true", default=False,
|
|
450
|
+
help="Output as JSON",
|
|
451
|
+
)
|
|
452
|
+
search_p.set_defaults(func=_cmd_search)
|
|
453
|
+
|
|
454
|
+
# -- stats ----------------------------------------------------------------
|
|
455
|
+
stats_p = actions.add_parser("stats", help="Episode count, index stats, conflict count")
|
|
456
|
+
stats_p.add_argument(
|
|
457
|
+
"--json", action="store_true", default=False,
|
|
458
|
+
help="Output as JSON",
|
|
459
|
+
)
|
|
460
|
+
stats_p.set_defaults(func=_cmd_stats)
|
|
461
|
+
|
|
462
|
+
# -- show -----------------------------------------------------------------
|
|
463
|
+
show_p = actions.add_parser("show", help="Full episode with metadata and score")
|
|
464
|
+
show_p.add_argument("episode_id", help="Episode ID to display")
|
|
465
|
+
show_p.add_argument(
|
|
466
|
+
"--json", action="store_true", default=False,
|
|
467
|
+
help="Output as JSON",
|
|
468
|
+
)
|
|
469
|
+
show_p.set_defaults(func=_cmd_show)
|
|
470
|
+
|
|
471
|
+
# -- conflicts ------------------------------------------------------------
|
|
472
|
+
conflicts_p = actions.add_parser(
|
|
473
|
+
"conflicts", help="Contradiction scan across memory files"
|
|
474
|
+
)
|
|
475
|
+
conflicts_p.add_argument(
|
|
476
|
+
"--threshold", type=float, default=0.3, metavar="F",
|
|
477
|
+
help="Jaccard similarity threshold (default: 0.3)",
|
|
478
|
+
)
|
|
479
|
+
conflicts_p.add_argument(
|
|
480
|
+
"--json", action="store_true", default=False,
|
|
481
|
+
help="Output as JSON",
|
|
482
|
+
)
|
|
483
|
+
conflicts_p.set_defaults(func=_cmd_conflicts)
|