claude-smart 0.2.45 → 0.2.47
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 +3 -3
- package/README.md +47 -10
- package/bin/claude-smart.js +535 -23
- package/package.json +22 -3
- package/plugin/.claude-plugin/plugin.json +4 -2
- package/plugin/.codex-plugin/plugin.json +1 -1
- package/plugin/README.md +27 -6
- package/plugin/commands/clear-all.md +1 -0
- package/plugin/commands/dashboard.md +1 -0
- package/plugin/commands/learn.md +1 -0
- package/plugin/commands/restart.md +1 -0
- package/plugin/commands/show.md +1 -0
- package/plugin/dashboard/app/configure/env/page.tsx +40 -14
- package/plugin/dashboard/app/configure/server/page.tsx +51 -1
- package/plugin/dashboard/app/layout.tsx +20 -0
- package/plugin/dashboard/app/preferences/[id]/page.tsx +8 -8
- package/plugin/dashboard/app/skills/project/[id]/page.tsx +7 -3
- package/plugin/dashboard/app/skills/shared/[id]/page.tsx +10 -3
- package/plugin/dashboard/lib/claude-settings-file.ts +20 -10
- package/plugin/dashboard/lib/reflexio-client.ts +16 -0
- package/plugin/dashboard/lib/status.ts +10 -3
- package/plugin/dashboard/lib/types.ts +18 -6
- package/plugin/hooks/codex-hooks.json +0 -1
- package/plugin/opencode/assistant-buffer.ts +108 -0
- package/plugin/opencode/dist/assistant-buffer.js +96 -0
- package/plugin/opencode/dist/internal.js +12 -0
- package/plugin/opencode/dist/payload.js +85 -0
- package/plugin/opencode/dist/server.mjs +232 -0
- package/plugin/opencode/internal.ts +18 -0
- package/plugin/opencode/package.json +3 -0
- package/plugin/opencode/payload.ts +90 -0
- package/plugin/opencode/server.mts +251 -0
- package/plugin/opencode/tsconfig.json +13 -0
- package/plugin/pyproject.toml +25 -4
- package/plugin/scripts/_lib.sh +5 -1
- package/plugin/scripts/backend-service.sh +22 -2
- package/plugin/scripts/ensure-plugin-root.sh +4 -4
- package/plugin/scripts/hook_entry.sh +1 -1
- package/plugin/scripts/opencode-claude-compat +4 -0
- package/plugin/scripts/opencode-claude-compat.cmd +3 -0
- package/plugin/scripts/opencode-claude-compat.js +225 -0
- package/plugin/scripts/smart-install.sh +17 -9
- package/plugin/src/README.md +1 -1
- package/plugin/src/claude_smart/cli.py +498 -12
- package/plugin/src/claude_smart/context_format.py +9 -9
- package/plugin/src/claude_smart/cs_cite.py +66 -19
- package/plugin/src/claude_smart/env_config.py +12 -4
- package/plugin/src/claude_smart/events/session_start.py +26 -7
- package/plugin/src/claude_smart/events/stop.py +1 -1
- package/plugin/src/claude_smart/ids.py +1 -1
- package/plugin/src/claude_smart/reflexio_adapter.py +5 -5
- package/plugin/src/claude_smart/runtime.py +7 -1
- package/plugin/uv.lock +5 -5
- package/plugin/vendor/reflexio/.env.example +54 -30
- package/plugin/vendor/reflexio/README.md +17 -11
- package/plugin/vendor/reflexio/pyproject.toml +13 -1
- package/plugin/vendor/reflexio/reflexio/README.md +4 -1
- package/plugin/vendor/reflexio/reflexio/cli/README.md +9 -7
- package/plugin/vendor/reflexio/reflexio/cli/__main__.py +10 -1
- package/plugin/vendor/reflexio/reflexio/cli/bootstrap_config.py +22 -5
- package/plugin/vendor/reflexio/reflexio/cli/commands/interactions.py +34 -4
- package/plugin/vendor/reflexio/reflexio/cli/commands/profiles.py +12 -7
- package/plugin/vendor/reflexio/reflexio/cli/commands/services.py +13 -6
- package/plugin/vendor/reflexio/reflexio/cli/commands/setup_cmd.py +212 -52
- package/plugin/vendor/reflexio/reflexio/cli/commands/shortcuts.py +15 -2
- package/plugin/vendor/reflexio/reflexio/cli/env_loader.py +292 -22
- package/plugin/vendor/reflexio/reflexio/cli/log_format.py +29 -4
- package/plugin/vendor/reflexio/reflexio/cli/run_services.py +17 -8
- package/plugin/vendor/reflexio/reflexio/cli/stop_services.py +13 -10
- package/plugin/vendor/reflexio/reflexio/cli/utils.py +44 -1
- package/plugin/vendor/reflexio/reflexio/client/client.py +154 -13
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/README.md +135 -257
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/npm/openclaw-smart/bin/openclaw-smart.js +13 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/npm/openclaw-smart/package.json +15 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/README.md +38 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/index.ts +151 -110
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/openclaw.plugin.json +20 -10
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/package.json +28 -6
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/pyproject.toml +42 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/scripts/_lib.sh +371 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/scripts/backend-log-runner.sh +33 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/scripts/backend-service.sh +271 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/scripts/cli.sh +68 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/scripts/dashboard-open.sh +15 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/scripts/ensure-plugin-root.sh +84 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/scripts/hook_entry.sh +106 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/scripts/npm-cli.js +219 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/scripts/smart-install.sh +269 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/skills/clear-all/SKILL.md +8 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/skills/dashboard/SKILL.md +8 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/skills/learn/SKILL.md +10 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/skills/reflexio/SKILL.md +15 -44
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/skills/restart/SKILL.md +6 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/skills/show/SKILL.md +8 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/src/openclaw_smart/cli.py +634 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/src/openclaw_smart/context_format.py +224 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/src/openclaw_smart/context_inject.py +79 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/src/openclaw_smart/events/__init__.py +0 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/src/openclaw_smart/events/after_tool_call.py +160 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/src/openclaw_smart/events/agent_end.py +187 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/src/openclaw_smart/events/before_prompt_build.py +69 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/src/openclaw_smart/events/before_tool_call.py +30 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/src/openclaw_smart/events/session_end.py +36 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/src/openclaw_smart/events/session_start.py +130 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/src/openclaw_smart/hook.py +131 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/src/openclaw_smart/ids.py +94 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/src/openclaw_smart/internal_call.py +75 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/src/openclaw_smart/oc_cite.py +196 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/src/openclaw_smart/optimizer_assistant.py +272 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/src/openclaw_smart/publish.py +96 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/src/openclaw_smart/query_compose.py +66 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/src/openclaw_smart/reflexio_adapter.py +336 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/src/openclaw_smart/runtime.py +47 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/src/openclaw_smart/stall_banner.py +61 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/src/openclaw_smart/state.py +323 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/tests/__init__.py +0 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/tests/integration/__init__.py +0 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/tests/integration/test_e2e_session_loop.py +190 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/tests/integration/test_publish_to_local_reflexio_integration.py +112 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/tests/integration/test_recursion_guard_integration.py +86 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/tests/integration/test_search_inject_integration.py +144 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/tests/test_cli.py +184 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/tests/test_events_after_tool_call.py +142 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/tests/test_events_agent_end.py +233 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/tests/test_events_before_prompt_build.py +116 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/tests/test_events_before_tool_call.py +35 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/tests/test_events_session_end.py +47 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/tests/test_events_session_start.py +109 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/tests/test_hook_dispatch.py +117 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/tests/test_ids.py +41 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/tests/test_internal_call.py +50 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/tests/test_oc_cite.py +88 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/tests/test_publish.py +48 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/tests/test_query_compose.py +48 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/tests/test_reflexio_adapter.py +188 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/tests/test_runtime.py +41 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/tests/test_state.py +235 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/tests-ts/__mocks__/plugin-entry-stub.ts +6 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/tests-ts/test_npm_cli.test.ts +56 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/tests-ts/test_shim_dispatch.test.ts +171 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/tsconfig.build.json +18 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/{tsconfig.json → plugin/tsconfig.json} +2 -2
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/uv.lock +3835 -0
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/vitest.config.ts +18 -0
- package/plugin/vendor/reflexio/reflexio/lib/_agent_playbook.py +246 -10
- package/plugin/vendor/reflexio/reflexio/lib/_base.py +15 -0
- package/plugin/vendor/reflexio/reflexio/lib/_config.py +11 -4
- package/plugin/vendor/reflexio/reflexio/lib/_generation.py +17 -5
- package/plugin/vendor/reflexio/reflexio/lib/_lineage_parity_readers.py +187 -0
- package/plugin/vendor/reflexio/reflexio/lib/_profiles.py +224 -21
- package/plugin/vendor/reflexio/reflexio/lib/_reflection.py +1 -1
- package/plugin/vendor/reflexio/reflexio/lib/_search.py +52 -25
- package/plugin/vendor/reflexio/reflexio/lib/_user_playbook.py +11 -1
- package/plugin/vendor/reflexio/reflexio/models/api_schema/domain/__init__.py +1 -0
- package/plugin/vendor/reflexio/reflexio/models/api_schema/domain/entities.py +127 -38
- package/plugin/vendor/reflexio/reflexio/models/api_schema/domain/enums.py +4 -0
- package/plugin/vendor/reflexio/reflexio/models/api_schema/domain/governance.py +117 -0
- package/plugin/vendor/reflexio/reflexio/models/api_schema/eval_overview_schema.py +64 -41
- package/plugin/vendor/reflexio/reflexio/models/api_schema/internal_schema.py +19 -0
- package/plugin/vendor/reflexio/reflexio/models/api_schema/pending_tool_call_schema.py +12 -5
- package/plugin/vendor/reflexio/reflexio/models/api_schema/retriever_schema.py +97 -3
- package/plugin/vendor/reflexio/reflexio/models/api_schema/ui/converters.py +5 -1
- package/plugin/vendor/reflexio/reflexio/models/api_schema/ui/entities.py +5 -1
- package/plugin/vendor/reflexio/reflexio/models/config_schema.py +104 -7
- package/plugin/vendor/reflexio/reflexio/models/structured_output.py +148 -0
- package/plugin/vendor/reflexio/reflexio/server/OVERVIEW.md +3 -3
- package/plugin/vendor/reflexio/reflexio/server/README.md +58 -33
- package/plugin/vendor/reflexio/reflexio/server/__init__.py +29 -5
- package/plugin/vendor/reflexio/reflexio/server/__main__.py +2 -2
- package/plugin/vendor/reflexio/reflexio/server/api.py +899 -103
- package/plugin/vendor/reflexio/reflexio/server/api_endpoints/precondition_checks.py +7 -0
- package/plugin/vendor/reflexio/reflexio/server/api_endpoints/request_context.py +4 -2
- package/plugin/vendor/reflexio/reflexio/server/auth.py +90 -0
- package/plugin/vendor/reflexio/reflexio/server/billing_meter.py +173 -0
- package/plugin/vendor/reflexio/reflexio/server/billing_signals.py +64 -0
- package/plugin/vendor/reflexio/reflexio/server/cache/reflexio_cache.py +46 -16
- package/plugin/vendor/reflexio/reflexio/server/env_utils.py +65 -0
- package/plugin/vendor/reflexio/reflexio/server/extensions.py +213 -0
- package/plugin/vendor/reflexio/reflexio/server/llm/embedding_service.py +19 -4
- package/plugin/vendor/reflexio/reflexio/server/llm/litellm_client.py +264 -77
- package/plugin/vendor/reflexio/reflexio/server/llm/llm_utils.py +69 -7
- package/plugin/vendor/reflexio/reflexio/server/llm/model_defaults.py +4 -4
- package/plugin/vendor/reflexio/reflexio/server/llm/providers/claude_code_provider.py +1 -1
- package/plugin/vendor/reflexio/reflexio/server/llm/providers/embedding_service_provider.py +75 -16
- package/plugin/vendor/reflexio/reflexio/server/llm/providers/openclaw_provider.py +280 -0
- package/plugin/vendor/reflexio/reflexio/server/llm/rerank/cross_encoder_reranker.py +12 -1
- package/plugin/vendor/reflexio/reflexio/server/llm/token_accounting.py +48 -0
- package/plugin/vendor/reflexio/reflexio/server/llm/tools.py +107 -17
- package/plugin/vendor/reflexio/reflexio/server/operation_limiter.py +360 -4
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/memory_reflection/v1.6.0.prompt.md +1 -1
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/memory_reflection/v1.7.0.prompt.md +85 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_aggregation/v2.2.0.prompt.md +1 -1
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_aggregation/v2.3.0.prompt.md +253 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_consolidation/v2.3.2.prompt.md +1 -1
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_consolidation/v2.3.3.prompt.md +74 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_extraction_context/v4.2.3.prompt.md +1 -1
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_extraction_context/v4.3.0.prompt.md +266 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_extraction_context/v4.4.0.prompt.md +278 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_extraction_context_expert/v3.3.0.prompt.md +1 -1
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_extraction_context_expert/v3.4.0.prompt.md +137 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_extraction_main/v1.2.0.prompt.md +1 -1
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/playbook_extraction_main/v1.3.0.prompt.md +34 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/profile_update_instruction_start/v1.0.0.prompt.md +5 -12
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/profile_update_instruction_start/v1.1.0.prompt.md +5 -12
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/profile_update_instruction_start/v1.2.0.prompt.md +155 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_bank/tagging/v1.0.0.prompt.md +23 -0
- package/plugin/vendor/reflexio/reflexio/server/prompt/prompt_manager.py +89 -32
- package/plugin/vendor/reflexio/reflexio/server/services/README.md +28 -11
- package/plugin/vendor/reflexio/reflexio/server/services/agent_success_evaluation/README.md +22 -0
- package/plugin/vendor/reflexio/reflexio/server/services/agent_success_evaluation/__init__.py +1 -0
- package/plugin/vendor/reflexio/reflexio/server/services/agent_success_evaluation/agent_success_evaluation_constants.py +4 -2
- package/plugin/vendor/reflexio/reflexio/server/services/agent_success_evaluation/agent_success_evaluation_utils.py +1 -0
- package/plugin/vendor/reflexio/reflexio/server/services/agent_success_evaluation/components/__init__.py +7 -0
- package/plugin/vendor/reflexio/reflexio/server/services/agent_success_evaluation/{agent_success_evaluator.py → components/evaluator.py} +3 -16
- package/plugin/vendor/reflexio/reflexio/server/services/agent_success_evaluation/regen_jobs.py +28 -72
- package/plugin/vendor/reflexio/reflexio/server/services/agent_success_evaluation/{group_evaluation_runner.py → runner.py} +12 -10
- package/plugin/vendor/reflexio/reflexio/server/services/agent_success_evaluation/{delayed_group_evaluator.py → scheduler.py} +10 -2
- package/plugin/vendor/reflexio/reflexio/server/services/agent_success_evaluation/{agent_success_evaluation_service.py → service.py} +36 -1
- package/plugin/vendor/reflexio/reflexio/server/services/base_generation_service.py +160 -0
- package/plugin/vendor/reflexio/reflexio/server/services/configurator/base_configurator.py +5 -0
- package/plugin/vendor/reflexio/reflexio/server/services/deduplication_utils.py +1 -1
- package/plugin/vendor/reflexio/reflexio/server/services/evaluation_overview/README.md +9 -0
- package/plugin/vendor/reflexio/reflexio/server/services/evaluation_overview/components/__init__.py +0 -0
- package/plugin/vendor/reflexio/reflexio/server/services/evaluation_overview/{rule_attribution.py → components/rule_attribution.py} +10 -9
- package/plugin/vendor/reflexio/reflexio/server/services/evaluation_overview/eval_sampler.py +15 -24
- package/plugin/vendor/reflexio/reflexio/server/services/evaluation_overview/service.py +238 -164
- package/plugin/vendor/reflexio/reflexio/server/services/extraction/README.md +31 -0
- package/plugin/vendor/reflexio/reflexio/server/services/extraction/outcome.py +13 -3
- package/plugin/vendor/reflexio/reflexio/server/services/extraction/pending_tool_call_dispatch.py +3 -2
- package/plugin/vendor/reflexio/reflexio/server/services/extraction/resumable_agent.py +32 -118
- package/plugin/vendor/reflexio/reflexio/server/services/extraction/resume_worker.py +47 -16
- package/plugin/vendor/reflexio/reflexio/server/services/generation_service.py +105 -23
- package/plugin/vendor/reflexio/reflexio/server/services/governance/config.py +52 -0
- package/plugin/vendor/reflexio/reflexio/server/services/governance/service.py +378 -0
- package/plugin/vendor/reflexio/reflexio/server/services/governance/subject_refs.py +34 -0
- package/plugin/vendor/reflexio/reflexio/server/services/lineage/__init__.py +0 -0
- package/plugin/vendor/reflexio/reflexio/server/services/lineage/gc_scheduler.py +219 -0
- package/plugin/vendor/reflexio/reflexio/server/services/lineage/resolve.py +98 -0
- package/plugin/vendor/reflexio/reflexio/server/services/operation_state_utils.py +26 -0
- package/plugin/vendor/reflexio/reflexio/server/services/playbook/README.md +18 -11
- package/plugin/vendor/reflexio/reflexio/server/services/playbook/aggregation_prompt_processing.py +100 -0
- package/plugin/vendor/reflexio/reflexio/server/services/playbook/components/__init__.py +5 -0
- package/plugin/vendor/reflexio/reflexio/server/services/playbook/{playbook_aggregator.py → components/aggregator.py} +334 -178
- package/plugin/vendor/reflexio/reflexio/server/services/playbook/{playbook_consolidator.py → components/consolidator.py} +168 -62
- package/plugin/vendor/reflexio/reflexio/server/services/playbook/{playbook_extractor.py → components/extractor.py} +5 -1
- package/plugin/vendor/reflexio/reflexio/server/services/playbook/playbook_edit_apply.py +74 -0
- package/plugin/vendor/reflexio/reflexio/server/services/playbook/playbook_service_utils.py +33 -3
- package/plugin/vendor/reflexio/reflexio/server/services/playbook/{playbook_generation_service.py → service.py} +121 -19
- package/plugin/vendor/reflexio/reflexio/server/services/playbook_optimizer/README.md +10 -0
- package/plugin/vendor/reflexio/reflexio/server/services/playbook_optimizer/models.py +2 -1
- package/plugin/vendor/reflexio/reflexio/server/services/playbook_optimizer/optimizer.py +178 -30
- package/plugin/vendor/reflexio/reflexio/server/services/pre_retrieval/README.md +9 -0
- package/plugin/vendor/reflexio/reflexio/server/services/profile/components/__init__.py +17 -0
- package/plugin/vendor/reflexio/reflexio/server/services/profile/{profile_deduplicator.py → components/consolidator.py} +7 -6
- package/plugin/vendor/reflexio/reflexio/server/services/profile/{profile_extractor.py → components/extractor.py} +31 -22
- package/plugin/vendor/reflexio/reflexio/server/services/profile/profile_generation_service_utils.py +6 -13
- package/plugin/vendor/reflexio/reflexio/server/services/profile/{profile_generation_service.py → service.py} +32 -50
- package/plugin/vendor/reflexio/reflexio/server/services/reflection/__init__.py +4 -8
- package/plugin/vendor/reflexio/reflexio/server/services/reflection/components/__init__.py +7 -0
- package/plugin/vendor/reflexio/reflexio/server/services/reflection/reflection_service_utils.py +12 -1
- package/plugin/vendor/reflexio/reflexio/server/services/reflection/{reflection_service.py → service.py} +36 -16
- package/plugin/vendor/reflexio/reflexio/server/services/retrieval/recency.py +211 -0
- package/plugin/vendor/reflexio/reflexio/server/services/retrieval/relevance_floor.py +99 -6
- package/plugin/vendor/reflexio/reflexio/server/services/service_utils.py +36 -1
- package/plugin/vendor/reflexio/reflexio/server/services/shadow_comparison/README.md +8 -0
- package/plugin/vendor/reflexio/reflexio/server/services/shadow_comparison/outcome.py +1 -2
- package/plugin/vendor/reflexio/reflexio/server/services/storage/error.py +31 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/governance_validation.py +681 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/retention.py +9 -9
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/__init__.py +16 -2
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/_agent_run.py +4 -1
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/_base.py +644 -197
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/_extras.py +106 -119
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/_governance.py +1965 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/_lineage.py +630 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/_operations.py +38 -6
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/_playbook.py +31 -1369
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/_profiles.py +756 -210
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/_requests.py +148 -34
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/_shadow_verdicts.py +23 -9
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/_stall_state.py +5 -2
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/playbook/__init__.py +13 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/playbook/_agent.py +952 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/playbook/_eval_results.py +189 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/playbook/_optimization.py +247 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/playbook/_source_linkage.py +145 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/sqlite_storage/playbook/_user.py +838 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/__init__.py +150 -23
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/_agent_run.py +2 -8
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/_base.py +5 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/_extras.py +40 -57
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/_governance.py +148 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/_lineage.py +215 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/_operations.py +20 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/_playbook.py +4 -677
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/_profiles.py +134 -1
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/_requests.py +62 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/_retrieval_log.py +51 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/_shadow_verdicts.py +17 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/playbook/__init__.py +13 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/playbook/_agent.py +365 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/playbook/_eval_results.py +124 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/playbook/_optimization.py +85 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/playbook/_source_linkage.py +47 -0
- package/plugin/vendor/reflexio/reflexio/server/services/storage/storage_base/playbook/_user.py +333 -0
- package/plugin/vendor/reflexio/reflexio/server/services/tagging/README.md +8 -0
- package/plugin/vendor/reflexio/reflexio/server/services/tagging/__init__.py +1 -0
- package/plugin/vendor/reflexio/reflexio/server/services/tagging/service.py +200 -0
- package/plugin/vendor/reflexio/reflexio/server/services/tagging/tagging_scheduler.py +149 -0
- package/plugin/vendor/reflexio/reflexio/server/services/unified_search_service.py +372 -34
- package/plugin/vendor/reflexio/reflexio/server/site_var/README.md +2 -1
- package/plugin/vendor/reflexio/reflexio/server/site_var/feature_flags.py +120 -1
- package/plugin/vendor/reflexio/reflexio/server/site_var/site_var_sources/feature_flags.json +4 -0
- package/plugin/vendor/reflexio/reflexio/server/site_var/site_var_sources/search_settings.json +5 -0
- package/plugin/vendor/reflexio/reflexio/server/tracing.py +30 -0
- package/plugin/vendor/reflexio/reflexio/server/usage_metrics.py +18 -0
- package/plugin/vendor/reflexio/reflexio/test_support/llm_mock.py +61 -26
- package/plugin/vendor/reflexio/reflexio/test_support/llm_model_registry.py +41 -4
- package/scripts/setup-claude-smart.sh +8 -3
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/TESTING.md +0 -517
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/hook/handler.js +0 -473
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/package-lock.json +0 -2156
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/package.json +0 -18
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/hook/handler.ts +0 -241
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/hook/setup.ts +0 -140
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/lib/publish.ts +0 -113
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/lib/search.ts +0 -52
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/lib/server.ts +0 -103
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/lib/sqlite-buffer.ts +0 -156
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/lib/user-id.ts +0 -134
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/plugin/rules/reflexio.md +0 -24
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/publish_clawhub.sh +0 -278
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/references/HOOK.md +0 -164
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/scripts/install.sh +0 -36
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/scripts/uninstall.sh +0 -35
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/tests/publish.test.ts +0 -27
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/tests/search.test.ts +0 -31
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/tests/server.test.ts +0 -42
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/tests/setup.test.ts +0 -49
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/tests/sqlite-buffer.test.ts +0 -91
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/tests/user-id.test.ts +0 -50
- package/plugin/vendor/reflexio/reflexio/integrations/openclaw/vitest.config.ts +0 -13
- package/plugin/vendor/reflexio/reflexio/server/_auth.py +0 -25
- package/plugin/vendor/reflexio/reflexio/server/services/evaluation_overview/group_aggregation.py +0 -192
- package/plugin/vendor/reflexio/reflexio/server/services/extraction/invariants.py +0 -303
- package/plugin/vendor/reflexio/reflexio/server/services/extraction/plan.py +0 -138
- package/plugin/vendor/reflexio/reflexio/server/services/extraction/tools.py +0 -1125
- /package/plugin/vendor/reflexio/reflexio/integrations/{__init__.py → openclaw/plugin/src/openclaw_smart/__init__.py} +0 -0
- /package/plugin/vendor/reflexio/reflexio/integrations/openclaw/{types → plugin/types}/openclaw.d.ts +0 -0
- /package/plugin/vendor/reflexio/reflexio/server/services/evaluation_overview/{distribution.py → components/distribution.py} +0 -0
- /package/plugin/vendor/reflexio/reflexio/server/services/evaluation_overview/{hero_state.py → components/hero_state.py} +0 -0
- /package/plugin/vendor/reflexio/reflexio/server/services/evaluation_overview/{shadow_aggregation.py → components/shadow_aggregation.py} +0 -0
- /package/plugin/vendor/reflexio/reflexio/server/services/reflection/{reflection_extractor.py → components/extractor.py} +0 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { eventProperties, type EventLike, sessionIDFrom } from "./internal.js"
|
|
2
|
+
|
|
3
|
+
type PartLike = {
|
|
4
|
+
id?: string
|
|
5
|
+
type?: string
|
|
6
|
+
text?: string
|
|
7
|
+
messageID?: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
type SessionText = {
|
|
11
|
+
messageID?: string
|
|
12
|
+
parts: Map<string, string>
|
|
13
|
+
textPartIDs: Set<string>
|
|
14
|
+
ignoredPartIDs: Set<string>
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function textFromPart(part: unknown): { id: string; text: string; messageID?: string } | undefined {
|
|
18
|
+
if (!part || typeof part !== "object") return undefined
|
|
19
|
+
const item = part as PartLike
|
|
20
|
+
if (item.type !== "text") return undefined
|
|
21
|
+
if (typeof item.text !== "string") return undefined
|
|
22
|
+
return {
|
|
23
|
+
id: item.id || `${item.messageID || "message"}:${item.type}`,
|
|
24
|
+
text: item.text,
|
|
25
|
+
messageID: item.messageID,
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function partIDFrom(part: unknown): string | undefined {
|
|
30
|
+
if (!part || typeof part !== "object") return undefined
|
|
31
|
+
const item = part as PartLike
|
|
32
|
+
return item.id || (item.messageID && item.type ? `${item.messageID}:${item.type}` : undefined)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function emptySession(messageID?: string): SessionText {
|
|
36
|
+
return { messageID, parts: new Map(), textPartIDs: new Set(), ignoredPartIDs: new Set() }
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export class AssistantBuffer {
|
|
40
|
+
private readonly sessions = new Map<string, SessionText>()
|
|
41
|
+
|
|
42
|
+
update(event: EventLike): void {
|
|
43
|
+
const type = event.type
|
|
44
|
+
const properties = eventProperties(event)
|
|
45
|
+
const sessionID = sessionIDFrom(properties)
|
|
46
|
+
if (!sessionID || !type) return
|
|
47
|
+
|
|
48
|
+
if (type === "message.updated") {
|
|
49
|
+
const info = properties.info
|
|
50
|
+
if (!info || typeof info !== "object") return
|
|
51
|
+
const message = info as { id?: string; role?: string }
|
|
52
|
+
if (message.role !== "assistant") return
|
|
53
|
+
const current = this.sessions.get(sessionID)
|
|
54
|
+
if (!current || current.messageID !== message.id) {
|
|
55
|
+
this.sessions.set(sessionID, emptySession(message.id))
|
|
56
|
+
}
|
|
57
|
+
return
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (type === "message.part.updated") {
|
|
61
|
+
const hit = textFromPart(properties.part)
|
|
62
|
+
if (!hit) {
|
|
63
|
+
const ignoredID = partIDFrom(properties.part)
|
|
64
|
+
if (!ignoredID) return
|
|
65
|
+
const current: SessionText = this.sessions.get(sessionID) ?? emptySession()
|
|
66
|
+
current.ignoredPartIDs.add(ignoredID)
|
|
67
|
+
current.textPartIDs.delete(ignoredID)
|
|
68
|
+
current.parts.delete(ignoredID)
|
|
69
|
+
this.sessions.set(sessionID, current)
|
|
70
|
+
return
|
|
71
|
+
}
|
|
72
|
+
const current: SessionText = this.sessions.get(sessionID) ?? emptySession()
|
|
73
|
+
if (hit.messageID && current.messageID && hit.messageID !== current.messageID) {
|
|
74
|
+
current.messageID = hit.messageID
|
|
75
|
+
current.parts.clear()
|
|
76
|
+
current.textPartIDs.clear()
|
|
77
|
+
current.ignoredPartIDs.clear()
|
|
78
|
+
} else if (hit.messageID) {
|
|
79
|
+
current.messageID = hit.messageID
|
|
80
|
+
}
|
|
81
|
+
current.ignoredPartIDs.delete(hit.id)
|
|
82
|
+
current.textPartIDs.add(hit.id)
|
|
83
|
+
current.parts.set(hit.id, hit.text)
|
|
84
|
+
this.sessions.set(sessionID, current)
|
|
85
|
+
return
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (type === "message.part.delta") {
|
|
89
|
+
const partID = typeof properties.partID === "string" ? properties.partID : undefined
|
|
90
|
+
const delta = typeof properties.delta === "string" ? properties.delta : undefined
|
|
91
|
+
if (!partID || !delta) return
|
|
92
|
+
const current: SessionText = this.sessions.get(sessionID) ?? emptySession()
|
|
93
|
+
if (current.ignoredPartIDs.has(partID) || !current.textPartIDs.has(partID)) return
|
|
94
|
+
current.parts.set(partID, `${current.parts.get(partID) || ""}${delta}`)
|
|
95
|
+
this.sessions.set(sessionID, current)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
text(sessionID: string): string {
|
|
100
|
+
const current = this.sessions.get(sessionID)
|
|
101
|
+
if (!current) return ""
|
|
102
|
+
return Array.from(current.parts.values()).filter(Boolean).join("\n\n")
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
clear(sessionID: string): void {
|
|
106
|
+
this.sessions.delete(sessionID)
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { eventProperties, sessionIDFrom } from "./internal.js";
|
|
2
|
+
function textFromPart(part) {
|
|
3
|
+
if (!part || typeof part !== "object")
|
|
4
|
+
return undefined;
|
|
5
|
+
const item = part;
|
|
6
|
+
if (item.type !== "text")
|
|
7
|
+
return undefined;
|
|
8
|
+
if (typeof item.text !== "string")
|
|
9
|
+
return undefined;
|
|
10
|
+
return {
|
|
11
|
+
id: item.id || `${item.messageID || "message"}:${item.type}`,
|
|
12
|
+
text: item.text,
|
|
13
|
+
messageID: item.messageID,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function partIDFrom(part) {
|
|
17
|
+
if (!part || typeof part !== "object")
|
|
18
|
+
return undefined;
|
|
19
|
+
const item = part;
|
|
20
|
+
return item.id || (item.messageID && item.type ? `${item.messageID}:${item.type}` : undefined);
|
|
21
|
+
}
|
|
22
|
+
function emptySession(messageID) {
|
|
23
|
+
return { messageID, parts: new Map(), textPartIDs: new Set(), ignoredPartIDs: new Set() };
|
|
24
|
+
}
|
|
25
|
+
export class AssistantBuffer {
|
|
26
|
+
sessions = new Map();
|
|
27
|
+
update(event) {
|
|
28
|
+
const type = event.type;
|
|
29
|
+
const properties = eventProperties(event);
|
|
30
|
+
const sessionID = sessionIDFrom(properties);
|
|
31
|
+
if (!sessionID || !type)
|
|
32
|
+
return;
|
|
33
|
+
if (type === "message.updated") {
|
|
34
|
+
const info = properties.info;
|
|
35
|
+
if (!info || typeof info !== "object")
|
|
36
|
+
return;
|
|
37
|
+
const message = info;
|
|
38
|
+
if (message.role !== "assistant")
|
|
39
|
+
return;
|
|
40
|
+
const current = this.sessions.get(sessionID);
|
|
41
|
+
if (!current || current.messageID !== message.id) {
|
|
42
|
+
this.sessions.set(sessionID, emptySession(message.id));
|
|
43
|
+
}
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (type === "message.part.updated") {
|
|
47
|
+
const hit = textFromPart(properties.part);
|
|
48
|
+
if (!hit) {
|
|
49
|
+
const ignoredID = partIDFrom(properties.part);
|
|
50
|
+
if (!ignoredID)
|
|
51
|
+
return;
|
|
52
|
+
const current = this.sessions.get(sessionID) ?? emptySession();
|
|
53
|
+
current.ignoredPartIDs.add(ignoredID);
|
|
54
|
+
current.textPartIDs.delete(ignoredID);
|
|
55
|
+
current.parts.delete(ignoredID);
|
|
56
|
+
this.sessions.set(sessionID, current);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const current = this.sessions.get(sessionID) ?? emptySession();
|
|
60
|
+
if (hit.messageID && current.messageID && hit.messageID !== current.messageID) {
|
|
61
|
+
current.messageID = hit.messageID;
|
|
62
|
+
current.parts.clear();
|
|
63
|
+
current.textPartIDs.clear();
|
|
64
|
+
current.ignoredPartIDs.clear();
|
|
65
|
+
}
|
|
66
|
+
else if (hit.messageID) {
|
|
67
|
+
current.messageID = hit.messageID;
|
|
68
|
+
}
|
|
69
|
+
current.ignoredPartIDs.delete(hit.id);
|
|
70
|
+
current.textPartIDs.add(hit.id);
|
|
71
|
+
current.parts.set(hit.id, hit.text);
|
|
72
|
+
this.sessions.set(sessionID, current);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (type === "message.part.delta") {
|
|
76
|
+
const partID = typeof properties.partID === "string" ? properties.partID : undefined;
|
|
77
|
+
const delta = typeof properties.delta === "string" ? properties.delta : undefined;
|
|
78
|
+
if (!partID || !delta)
|
|
79
|
+
return;
|
|
80
|
+
const current = this.sessions.get(sessionID) ?? emptySession();
|
|
81
|
+
if (current.ignoredPartIDs.has(partID) || !current.textPartIDs.has(partID))
|
|
82
|
+
return;
|
|
83
|
+
current.parts.set(partID, `${current.parts.get(partID) || ""}${delta}`);
|
|
84
|
+
this.sessions.set(sessionID, current);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
text(sessionID) {
|
|
88
|
+
const current = this.sessions.get(sessionID);
|
|
89
|
+
if (!current)
|
|
90
|
+
return "";
|
|
91
|
+
return Array.from(current.parts.values()).filter(Boolean).join("\n\n");
|
|
92
|
+
}
|
|
93
|
+
clear(sessionID) {
|
|
94
|
+
this.sessions.delete(sessionID);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export function isRecord(value) {
|
|
2
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
3
|
+
}
|
|
4
|
+
export function eventProperties(event) {
|
|
5
|
+
return isRecord(event.properties) ? event.properties : event;
|
|
6
|
+
}
|
|
7
|
+
export function sessionIDFrom(value) {
|
|
8
|
+
if (!isRecord(value))
|
|
9
|
+
return "";
|
|
10
|
+
const raw = value.sessionID ?? value.session_id;
|
|
11
|
+
return typeof raw === "string" ? raw : "";
|
|
12
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { eventProperties, isRecord, sessionIDFrom } from "./internal.js";
|
|
2
|
+
function textFromParts(parts) {
|
|
3
|
+
if (!Array.isArray(parts))
|
|
4
|
+
return "";
|
|
5
|
+
return parts
|
|
6
|
+
.map((part) => (part && part.type === "text" && typeof part.text === "string" ? part.text : ""))
|
|
7
|
+
.filter(Boolean)
|
|
8
|
+
.join("\n\n");
|
|
9
|
+
}
|
|
10
|
+
export function eventPayload(event, cwd) {
|
|
11
|
+
const properties = eventProperties(event);
|
|
12
|
+
const info = isRecord(properties.info) ? properties.info : {};
|
|
13
|
+
return {
|
|
14
|
+
session_id: sessionIDFrom(properties) || sessionIDFrom(info),
|
|
15
|
+
cwd: typeof info.directory === "string" ? info.directory : cwd,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export function chatMessagePayload(input, output, cwd) {
|
|
19
|
+
const message = isRecord(output.message) ? output.message : {};
|
|
20
|
+
const prompt = textFromParts(output.parts) ||
|
|
21
|
+
(typeof message.content === "string" ? message.content : "") ||
|
|
22
|
+
textFromParts(message.parts);
|
|
23
|
+
return {
|
|
24
|
+
session_id: sessionIDFrom(input),
|
|
25
|
+
cwd,
|
|
26
|
+
prompt,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export function normalizeToolName(tool) {
|
|
30
|
+
const lowered = tool.toLowerCase();
|
|
31
|
+
if (lowered === "edit")
|
|
32
|
+
return "Edit";
|
|
33
|
+
if (lowered === "write")
|
|
34
|
+
return "Write";
|
|
35
|
+
if (lowered === "apply_patch")
|
|
36
|
+
return "apply_patch";
|
|
37
|
+
if (["bash", "shell", "terminal", "exec", "command"].includes(lowered))
|
|
38
|
+
return "Bash";
|
|
39
|
+
return tool;
|
|
40
|
+
}
|
|
41
|
+
export function normalizeToolInput(tool, args) {
|
|
42
|
+
if (!isRecord(args))
|
|
43
|
+
return {};
|
|
44
|
+
const out = { ...args };
|
|
45
|
+
const copy = (from, to) => {
|
|
46
|
+
if (from in args && !(to in out))
|
|
47
|
+
out[to] = args[from];
|
|
48
|
+
};
|
|
49
|
+
copy("filePath", "file_path");
|
|
50
|
+
copy("oldString", "old_string");
|
|
51
|
+
copy("newString", "new_string");
|
|
52
|
+
copy("patchText", "command");
|
|
53
|
+
if (normalizeToolName(tool) === "Bash") {
|
|
54
|
+
copy("cmd", "command");
|
|
55
|
+
copy("script", "command");
|
|
56
|
+
}
|
|
57
|
+
return out;
|
|
58
|
+
}
|
|
59
|
+
export function toolAfterPayload(input, output, cwd) {
|
|
60
|
+
const tool = typeof input.tool === "string" ? input.tool : "";
|
|
61
|
+
const text = typeof output.output === "string" ? output.output : "";
|
|
62
|
+
const response = {
|
|
63
|
+
output: text,
|
|
64
|
+
stdout: text,
|
|
65
|
+
};
|
|
66
|
+
if (typeof output.title === "string")
|
|
67
|
+
response.title = output.title;
|
|
68
|
+
if (isRecord(output.metadata))
|
|
69
|
+
response.metadata = output.metadata;
|
|
70
|
+
if (isRecord(output.metadata) && output.metadata.error)
|
|
71
|
+
response.error = output.metadata.error;
|
|
72
|
+
return {
|
|
73
|
+
session_id: sessionIDFrom(input),
|
|
74
|
+
cwd,
|
|
75
|
+
tool_name: normalizeToolName(tool),
|
|
76
|
+
tool_input: normalizeToolInput(tool, input.args),
|
|
77
|
+
tool_response: response,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
export function stopPayload(event, cwd, lastAssistantMessage) {
|
|
81
|
+
return {
|
|
82
|
+
...eventPayload(event, cwd),
|
|
83
|
+
last_assistant_message: lastAssistantMessage,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { dirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { AssistantBuffer } from "./assistant-buffer.js";
|
|
7
|
+
import { sessionIDFrom } from "./internal.js";
|
|
8
|
+
import { chatMessagePayload, eventPayload, stopPayload, toolAfterPayload } from "./payload.js";
|
|
9
|
+
const MODULE_DIR = dirname(fileURLToPath(import.meta.url));
|
|
10
|
+
function homeDir() {
|
|
11
|
+
return process.env.HOME || homedir();
|
|
12
|
+
}
|
|
13
|
+
function textFilePluginRoot() {
|
|
14
|
+
try {
|
|
15
|
+
return readFileSync(join(homeDir(), ".reflexio", "plugin-root.txt"), "utf8").trim() || undefined;
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function isPluginRoot(candidate) {
|
|
22
|
+
return !!candidate
|
|
23
|
+
&& existsSync(join(candidate, "pyproject.toml"))
|
|
24
|
+
&& existsSync(join(candidate, "uv.lock"))
|
|
25
|
+
&& existsSync(join(candidate, "scripts", "hook_entry.sh"));
|
|
26
|
+
}
|
|
27
|
+
function canonicalPluginRoot(candidate) {
|
|
28
|
+
if (!isPluginRoot(candidate))
|
|
29
|
+
return undefined;
|
|
30
|
+
try {
|
|
31
|
+
return realpathSync(candidate);
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function pathParts(candidate) {
|
|
38
|
+
return candidate.split(/[\\/]+/).filter(Boolean);
|
|
39
|
+
}
|
|
40
|
+
function isDescendantOrSame(child, parent) {
|
|
41
|
+
const path = relative(parent, child);
|
|
42
|
+
return path === "" || (!path.startsWith("..") && !isAbsolute(path));
|
|
43
|
+
}
|
|
44
|
+
function isReflexioSessionCopy(candidate) {
|
|
45
|
+
try {
|
|
46
|
+
const reflexioRoot = realpathSync(join(homeDir(), ".reflexio"));
|
|
47
|
+
return isDescendantOrSame(candidate, reflexioRoot);
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function isTransientPackageRoot(candidate) {
|
|
54
|
+
return pathParts(candidate).includes("_npx") || isReflexioSessionCopy(candidate);
|
|
55
|
+
}
|
|
56
|
+
function resolvePluginRoot() {
|
|
57
|
+
const current = resolve(MODULE_DIR, "../..");
|
|
58
|
+
const explicit = canonicalPluginRoot(process.env.CLAUDE_SMART_PLUGIN_ROOT);
|
|
59
|
+
if (explicit)
|
|
60
|
+
return explicit;
|
|
61
|
+
const currentRoot = canonicalPluginRoot(current);
|
|
62
|
+
if (currentRoot && !isTransientPackageRoot(currentRoot))
|
|
63
|
+
return currentRoot;
|
|
64
|
+
const candidates = [
|
|
65
|
+
join(homeDir(), ".reflexio", "plugin-root"),
|
|
66
|
+
textFilePluginRoot(),
|
|
67
|
+
];
|
|
68
|
+
for (const candidate of candidates) {
|
|
69
|
+
const root = canonicalPluginRoot(candidate);
|
|
70
|
+
if (root)
|
|
71
|
+
return root;
|
|
72
|
+
}
|
|
73
|
+
if (currentRoot)
|
|
74
|
+
return currentRoot;
|
|
75
|
+
try {
|
|
76
|
+
return realpathSync(current);
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
return current;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const PLUGIN_ROOT = resolvePluginRoot();
|
|
83
|
+
const SCRIPTS_DIR = resolve(PLUGIN_ROOT, "scripts");
|
|
84
|
+
const HOOK_ENTRY = resolve(SCRIPTS_DIR, "hook_entry.sh");
|
|
85
|
+
const BACKEND_SERVICE = resolve(SCRIPTS_DIR, "backend-service.sh");
|
|
86
|
+
const DASHBOARD_SERVICE = resolve(SCRIPTS_DIR, "dashboard-service.sh");
|
|
87
|
+
function contextFrom(result) {
|
|
88
|
+
const hookOutput = result.hookSpecificOutput;
|
|
89
|
+
if (!hookOutput || typeof hookOutput !== "object")
|
|
90
|
+
return "";
|
|
91
|
+
const additional = hookOutput.additionalContext;
|
|
92
|
+
return typeof additional === "string" ? additional : "";
|
|
93
|
+
}
|
|
94
|
+
function parseFirstJsonObject(text) {
|
|
95
|
+
for (const line of text.split(/\r?\n/)) {
|
|
96
|
+
const trimmed = line.trim();
|
|
97
|
+
if (!trimmed.startsWith("{"))
|
|
98
|
+
continue;
|
|
99
|
+
try {
|
|
100
|
+
const parsed = JSON.parse(trimmed);
|
|
101
|
+
if (parsed && typeof parsed === "object")
|
|
102
|
+
return parsed;
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return {};
|
|
109
|
+
}
|
|
110
|
+
function runScript(script, args, payload) {
|
|
111
|
+
return new Promise((resolvePromise) => {
|
|
112
|
+
const child = spawn("bash", [script, ...args], {
|
|
113
|
+
cwd: PLUGIN_ROOT,
|
|
114
|
+
env: {
|
|
115
|
+
...process.env,
|
|
116
|
+
CLAUDE_PLUGIN_ROOT: PLUGIN_ROOT,
|
|
117
|
+
CLAUDE_SMART_HOST: "opencode",
|
|
118
|
+
},
|
|
119
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
120
|
+
});
|
|
121
|
+
let stdout = "";
|
|
122
|
+
child.stdout.on("data", (chunk) => {
|
|
123
|
+
stdout += chunk.toString();
|
|
124
|
+
});
|
|
125
|
+
child.stderr.on("data", (chunk) => {
|
|
126
|
+
process.stderr.write(chunk);
|
|
127
|
+
});
|
|
128
|
+
child.stdin.on("error", () => {
|
|
129
|
+
// Hooks can exit before reading stdin on marker-gated setup failures.
|
|
130
|
+
});
|
|
131
|
+
child.on("error", () => resolvePromise({}));
|
|
132
|
+
child.on("close", () => resolvePromise(parseFirstJsonObject(stdout)));
|
|
133
|
+
try {
|
|
134
|
+
if (payload)
|
|
135
|
+
child.stdin.write(JSON.stringify(payload));
|
|
136
|
+
child.stdin.end();
|
|
137
|
+
}
|
|
138
|
+
catch {
|
|
139
|
+
resolvePromise({});
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
function runService(script, subcommand) {
|
|
144
|
+
return runScript(script, [subcommand]).then(() => undefined);
|
|
145
|
+
}
|
|
146
|
+
function cacheContext(cache, sessionID, result) {
|
|
147
|
+
const context = contextFrom(result);
|
|
148
|
+
if (!sessionID || !context)
|
|
149
|
+
return;
|
|
150
|
+
const pending = cache.get(sessionID) ?? [];
|
|
151
|
+
pending.push(context);
|
|
152
|
+
cache.set(sessionID, pending);
|
|
153
|
+
}
|
|
154
|
+
async function server(input) {
|
|
155
|
+
const pendingContext = new Map();
|
|
156
|
+
const activeSessions = new Set();
|
|
157
|
+
const completedAssistantText = new Map();
|
|
158
|
+
const assistant = new AssistantBuffer();
|
|
159
|
+
const cwd = input.directory;
|
|
160
|
+
async function flushStop(sessionID) {
|
|
161
|
+
if (!sessionID || !activeSessions.has(sessionID))
|
|
162
|
+
return;
|
|
163
|
+
activeSessions.delete(sessionID);
|
|
164
|
+
const text = assistant.text(sessionID) || completedAssistantText.get(sessionID) || "";
|
|
165
|
+
completedAssistantText.delete(sessionID);
|
|
166
|
+
await runScript(HOOK_ENTRY, ["opencode", "stop"], stopPayload({ properties: { sessionID, info: { directory: cwd } } }, cwd, text));
|
|
167
|
+
assistant.clear(sessionID);
|
|
168
|
+
}
|
|
169
|
+
return {
|
|
170
|
+
event: async ({ event }) => {
|
|
171
|
+
const type = event.type;
|
|
172
|
+
assistant.update(event);
|
|
173
|
+
if (type === "session.created") {
|
|
174
|
+
const payload = eventPayload(event, cwd);
|
|
175
|
+
const sessionID = String(payload.session_id || "");
|
|
176
|
+
if (!sessionID)
|
|
177
|
+
return;
|
|
178
|
+
activeSessions.add(sessionID);
|
|
179
|
+
await runService(BACKEND_SERVICE, "start");
|
|
180
|
+
await runService(DASHBOARD_SERVICE, "start");
|
|
181
|
+
const result = await runScript(HOOK_ENTRY, ["opencode", "session-start"], payload);
|
|
182
|
+
cacheContext(pendingContext, sessionID, result);
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
if (type === "session.idle") {
|
|
186
|
+
const payload = eventPayload(event, cwd);
|
|
187
|
+
const sessionID = String(payload.session_id || "");
|
|
188
|
+
if (!sessionID)
|
|
189
|
+
return;
|
|
190
|
+
await flushStop(sessionID);
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
"chat.message": async (hookInput, output) => {
|
|
194
|
+
const payload = chatMessagePayload(hookInput, output, cwd);
|
|
195
|
+
if (!payload.session_id || !payload.prompt)
|
|
196
|
+
return;
|
|
197
|
+
activeSessions.add(String(payload.session_id || ""));
|
|
198
|
+
const result = await runScript(HOOK_ENTRY, ["opencode", "user-prompt"], payload);
|
|
199
|
+
cacheContext(pendingContext, String(payload.session_id || ""), result);
|
|
200
|
+
},
|
|
201
|
+
"experimental.chat.system.transform": async (hookInput, output) => {
|
|
202
|
+
const sessionID = sessionIDFrom(hookInput);
|
|
203
|
+
const pending = pendingContext.get(sessionID);
|
|
204
|
+
if (!pending?.length)
|
|
205
|
+
return;
|
|
206
|
+
output.system.push(...pending);
|
|
207
|
+
pendingContext.delete(sessionID);
|
|
208
|
+
},
|
|
209
|
+
"tool.execute.after": async (hookInput, output) => {
|
|
210
|
+
const payload = toolAfterPayload(hookInput, output, cwd);
|
|
211
|
+
if (!payload.session_id || !payload.tool_name)
|
|
212
|
+
return;
|
|
213
|
+
await runScript(HOOK_ENTRY, ["opencode", "post-tool"], payload);
|
|
214
|
+
},
|
|
215
|
+
"experimental.text.complete": async (hookInput, output) => {
|
|
216
|
+
const sessionID = typeof hookInput.sessionID === "string" ? hookInput.sessionID : "";
|
|
217
|
+
if (!sessionID)
|
|
218
|
+
return;
|
|
219
|
+
if (typeof output.text === "string")
|
|
220
|
+
completedAssistantText.set(sessionID, output.text);
|
|
221
|
+
},
|
|
222
|
+
dispose: async () => {
|
|
223
|
+
await Promise.all([...activeSessions].map((sessionID) => flushStop(sessionID)));
|
|
224
|
+
await runService(DASHBOARD_SERVICE, "session-end");
|
|
225
|
+
await runService(BACKEND_SERVICE, "session-end");
|
|
226
|
+
},
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
export default {
|
|
230
|
+
id: "claude-smart",
|
|
231
|
+
server,
|
|
232
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type EventLike = {
|
|
2
|
+
type?: string
|
|
3
|
+
properties?: Record<string, unknown>
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export function isRecord(value: unknown): value is Record<string, unknown> {
|
|
7
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function eventProperties(event: EventLike): Record<string, unknown> {
|
|
11
|
+
return isRecord(event.properties) ? event.properties : (event as Record<string, unknown>)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function sessionIDFrom(value: unknown): string {
|
|
15
|
+
if (!isRecord(value)) return ""
|
|
16
|
+
const raw = value.sessionID ?? value.session_id
|
|
17
|
+
return typeof raw === "string" ? raw : ""
|
|
18
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { eventProperties, type EventLike, isRecord, sessionIDFrom } from "./internal.js"
|
|
2
|
+
|
|
3
|
+
type PartLike = {
|
|
4
|
+
type?: string
|
|
5
|
+
text?: string
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export type PythonPayload = Record<string, unknown>
|
|
9
|
+
|
|
10
|
+
function textFromParts(parts: unknown): string {
|
|
11
|
+
if (!Array.isArray(parts)) return ""
|
|
12
|
+
return parts
|
|
13
|
+
.map((part: PartLike) => (part && part.type === "text" && typeof part.text === "string" ? part.text : ""))
|
|
14
|
+
.filter(Boolean)
|
|
15
|
+
.join("\n\n")
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function eventPayload(event: EventLike, cwd: string): PythonPayload {
|
|
19
|
+
const properties = eventProperties(event)
|
|
20
|
+
const info = isRecord(properties.info) ? properties.info : {}
|
|
21
|
+
return {
|
|
22
|
+
session_id: sessionIDFrom(properties) || sessionIDFrom(info),
|
|
23
|
+
cwd: typeof info.directory === "string" ? info.directory : cwd,
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function chatMessagePayload(input: Record<string, unknown>, output: Record<string, unknown>, cwd: string): PythonPayload {
|
|
28
|
+
const message = isRecord(output.message) ? output.message : {}
|
|
29
|
+
const prompt =
|
|
30
|
+
textFromParts(output.parts) ||
|
|
31
|
+
(typeof message.content === "string" ? message.content : "") ||
|
|
32
|
+
textFromParts(message.parts)
|
|
33
|
+
return {
|
|
34
|
+
session_id: sessionIDFrom(input),
|
|
35
|
+
cwd,
|
|
36
|
+
prompt,
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function normalizeToolName(tool: string): string {
|
|
41
|
+
const lowered = tool.toLowerCase()
|
|
42
|
+
if (lowered === "edit") return "Edit"
|
|
43
|
+
if (lowered === "write") return "Write"
|
|
44
|
+
if (lowered === "apply_patch") return "apply_patch"
|
|
45
|
+
if (["bash", "shell", "terminal", "exec", "command"].includes(lowered)) return "Bash"
|
|
46
|
+
return tool
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function normalizeToolInput(tool: string, args: unknown): Record<string, unknown> {
|
|
50
|
+
if (!isRecord(args)) return {}
|
|
51
|
+
const out: Record<string, unknown> = { ...args }
|
|
52
|
+
const copy = (from: string, to: string) => {
|
|
53
|
+
if (from in args && !(to in out)) out[to] = args[from]
|
|
54
|
+
}
|
|
55
|
+
copy("filePath", "file_path")
|
|
56
|
+
copy("oldString", "old_string")
|
|
57
|
+
copy("newString", "new_string")
|
|
58
|
+
copy("patchText", "command")
|
|
59
|
+
if (normalizeToolName(tool) === "Bash") {
|
|
60
|
+
copy("cmd", "command")
|
|
61
|
+
copy("script", "command")
|
|
62
|
+
}
|
|
63
|
+
return out
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function toolAfterPayload(input: Record<string, unknown>, output: Record<string, unknown>, cwd: string): PythonPayload {
|
|
67
|
+
const tool = typeof input.tool === "string" ? input.tool : ""
|
|
68
|
+
const text = typeof output.output === "string" ? output.output : ""
|
|
69
|
+
const response: Record<string, unknown> = {
|
|
70
|
+
output: text,
|
|
71
|
+
stdout: text,
|
|
72
|
+
}
|
|
73
|
+
if (typeof output.title === "string") response.title = output.title
|
|
74
|
+
if (isRecord(output.metadata)) response.metadata = output.metadata
|
|
75
|
+
if (isRecord(output.metadata) && output.metadata.error) response.error = output.metadata.error
|
|
76
|
+
return {
|
|
77
|
+
session_id: sessionIDFrom(input),
|
|
78
|
+
cwd,
|
|
79
|
+
tool_name: normalizeToolName(tool),
|
|
80
|
+
tool_input: normalizeToolInput(tool, input.args),
|
|
81
|
+
tool_response: response,
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function stopPayload(event: EventLike, cwd: string, lastAssistantMessage: string): PythonPayload {
|
|
86
|
+
return {
|
|
87
|
+
...eventPayload(event, cwd),
|
|
88
|
+
last_assistant_message: lastAssistantMessage,
|
|
89
|
+
}
|
|
90
|
+
}
|