@scemoon/cdh 1.0.0
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/ai-dlc-skill/SKILL.md +75 -0
- package/ai-dlc-skill/agents/deliver-agent.md +24 -0
- package/ai-dlc-skill/agents/master.md +44 -0
- package/ai-dlc-skill/agents/plan-agent.md +23 -0
- package/ai-dlc-skill/agents/understand-agent.md +23 -0
- package/ai-dlc-skill/agents/verify-agent.md +27 -0
- package/ai-dlc-skill/architecture/project-structure.md +78 -0
- package/ai-dlc-skill/brownfield/README.md +30 -0
- package/ai-dlc-skill/brownfield/generate-context.sh +64 -0
- package/ai-dlc-skill/brownfield/scripts/deps.sh +27 -0
- package/ai-dlc-skill/brownfield/scripts/discover.sh +34 -0
- package/ai-dlc-skill/brownfield/scripts/extract-api.sh +45 -0
- package/ai-dlc-skill/components/backend.md +34 -0
- package/ai-dlc-skill/components/desktop.md +30 -0
- package/ai-dlc-skill/components/mya.md +29 -0
- package/ai-dlc-skill/components/native.md +30 -0
- package/ai-dlc-skill/components/tta.md +29 -0
- package/ai-dlc-skill/components/web.md +31 -0
- package/ai-dlc-skill/components/wxa.md +29 -0
- package/ai-dlc-skill/contracts/README.md +25 -0
- package/ai-dlc-skill/core/adaptive-flow.md +36 -0
- package/ai-dlc-skill/core/security.md +29 -0
- package/ai-dlc-skill/cross-tool/cline/export.sh +31 -0
- package/ai-dlc-skill/cross-tool/copilot/export.sh +47 -0
- package/ai-dlc-skill/cross-tool/cursor/export.sh +32 -0
- package/ai-dlc-skill/cross-tool/export.sh +22 -0
- package/ai-dlc-skill/cross-tool/onecode/config.yaml.tpl +17 -0
- package/ai-dlc-skill/cross-tool/onecode/export-skills.sh +31 -0
- package/ai-dlc-skill/cross-tool/onecode/export.sh +48 -0
- package/ai-dlc-skill/phases/deliver/entry.md +26 -0
- package/ai-dlc-skill/phases/deliver/lifecycle.md +185 -0
- package/ai-dlc-skill/phases/deliver/prompt.md +40 -0
- package/ai-dlc-skill/phases/deliver/rules.md +61 -0
- package/ai-dlc-skill/phases/plan/entry.md +25 -0
- package/ai-dlc-skill/phases/plan/lifecycle.md +204 -0
- package/ai-dlc-skill/phases/plan/prompt.md +38 -0
- package/ai-dlc-skill/phases/plan/rules.md +25 -0
- package/ai-dlc-skill/phases/understand/entry.md +26 -0
- package/ai-dlc-skill/phases/understand/lifecycle.md +184 -0
- package/ai-dlc-skill/phases/understand/prompt.md +41 -0
- package/ai-dlc-skill/phases/understand/rules.md +37 -0
- package/ai-dlc-skill/phases/verify/entry.md +26 -0
- package/ai-dlc-skill/phases/verify/lifecycle.md +192 -0
- package/ai-dlc-skill/phases/verify/prompt.md +43 -0
- package/ai-dlc-skill/phases/verify/rules.md +73 -0
- package/ai-dlc-skill/practices/bdd.md +91 -0
- package/ai-dlc-skill/practices/sdd.md +84 -0
- package/ai-dlc-skill/practices/tdd.md +95 -0
- package/ai-dlc-skill/providers/README.md +114 -0
- package/ai-dlc-skill/providers/aliyun/deployment.yaml +66 -0
- package/ai-dlc-skill/providers/aliyun/preview.yaml +84 -0
- package/ai-dlc-skill/providers/aliyun/provider.yaml +160 -0
- package/ai-dlc-skill/providers/tcb/deployment.yaml +69 -0
- package/ai-dlc-skill/providers/tcb/preview.yaml +83 -0
- package/ai-dlc-skill/providers/tcb/provider.yaml +172 -0
- package/ai-dlc-skill/requirements.md +140 -0
- package/ai-dlc-skill/skill.yaml +147 -0
- package/ai-dlc-skill/templates/integration/CHANGELOG.md +41 -0
- package/ai-dlc-skill/templates/integration/asyncapi.yaml +43 -0
- package/ai-dlc-skill/templates/integration/contract-diff.md +63 -0
- package/ai-dlc-skill/templates/integration/contract-spec.md +49 -0
- package/ai-dlc-skill/templates/integration/openapi.yaml +18 -0
- package/ai-dlc-skill/templates/integration/runtime-contract.yaml +36 -0
- package/ai-dlc-skill/templates/plan/design.md +49 -0
- package/ai-dlc-skill/templates/plan/task-list.md +32 -0
- package/ai-dlc-skill/templates/project/README.md +127 -0
- package/ai-dlc-skill/templates/project/template.md +119 -0
- package/ai-dlc-skill/templates/understand/feature.feature +23 -0
- package/ai-dlc-skill/templates/understand/intent.md +29 -0
- package/ai-dlc-skill/templates/understand/spec-delta.md +47 -0
- package/ai-dlc-skill/templates/verify/test-unit.py +27 -0
- package/ai-dlc-skill/walkthrough/collect.sh +50 -0
- package/ai-dlc-skill/walkthrough/template.md +54 -0
- package/ai-dlc-skill/workflows/ai-dlc.yaml +110 -0
- package/ai-dlc-skill/workflows/deployment.yaml +199 -0
- package/cdh/__init__.py +0 -0
- package/cdh/__main__.py +4 -0
- package/cdh/__pycache__/__init__.cpython-313.pyc +0 -0
- package/cdh/__pycache__/__init__.cpython-314.pyc +0 -0
- package/cdh/__pycache__/cli.cpython-314.pyc +0 -0
- package/cdh/__pycache__/scaffold.cpython-313.pyc +0 -0
- package/cdh/__pycache__/scaffold.cpython-314.pyc +0 -0
- package/cdh/cli.py +361 -0
- package/cdh/scaffold.py +312 -0
- package/cli.js +2 -0
- package/onecode/__init__.py +1 -0
- package/onecode/__main__.py +4 -0
- package/onecode/__pycache__/__init__.cpython-314.pyc +0 -0
- package/onecode/__pycache__/cli.cpython-314.pyc +0 -0
- package/onecode/__pycache__/commands.cpython-314.pyc +0 -0
- package/onecode/__pycache__/config.cpython-314.pyc +0 -0
- package/onecode/__pycache__/config_screen.cpython-314.pyc +0 -0
- package/onecode/__pycache__/mock_data.cpython-314.pyc +0 -0
- package/onecode/agent/__init__.py +0 -0
- package/onecode/agent/__pycache__/__init__.cpython-314.pyc +0 -0
- package/onecode/agent/__pycache__/cdh_agent_acp.cpython-313.pyc +0 -0
- package/onecode/agent/__pycache__/cdh_agent_acp.cpython-314.pyc +0 -0
- package/onecode/agent/__pycache__/cdh_loader.cpython-314.pyc +0 -0
- package/onecode/agent/__pycache__/context.cpython-314.pyc +0 -0
- package/onecode/agent/__pycache__/engine.cpython-314.pyc +0 -0
- package/onecode/agent/__pycache__/harness_skill.cpython-314.pyc +0 -0
- package/onecode/agent/__pycache__/hooks.cpython-314.pyc +0 -0
- package/onecode/agent/__pycache__/onecode_agent_acp.cpython-314.pyc +0 -0
- package/onecode/agent/__pycache__/permissions.cpython-314.pyc +0 -0
- package/onecode/agent/__pycache__/permissions_store.cpython-314.pyc +0 -0
- package/onecode/agent/__pycache__/session.cpython-314.pyc +0 -0
- package/onecode/agent/agents/__init__.py +29 -0
- package/onecode/agent/agents/__pycache__/__init__.cpython-314.pyc +0 -0
- package/onecode/agent/agents/__pycache__/types.cpython-314.pyc +0 -0
- package/onecode/agent/agents/types.py +662 -0
- package/onecode/agent/attachments.py +113 -0
- package/onecode/agent/cdh_loader.py +262 -0
- package/onecode/agent/context.py +338 -0
- package/onecode/agent/engine.py +1894 -0
- package/onecode/agent/hooks.py +86 -0
- package/onecode/agent/onecode_agent_acp.py +2203 -0
- package/onecode/agent/permissions.py +151 -0
- package/onecode/agent/permissions_store.py +62 -0
- package/onecode/agent/session.py +186 -0
- package/onecode/agent/snapshot.py +145 -0
- package/onecode/agent/tools/__init__.py +17 -0
- package/onecode/agent/tools/__pycache__/__init__.cpython-314.pyc +0 -0
- package/onecode/agent/tools/__pycache__/agent_tools.cpython-314.pyc +0 -0
- package/onecode/agent/tools/__pycache__/apply_patch_tool.cpython-314.pyc +0 -0
- package/onecode/agent/tools/__pycache__/bash_tool.cpython-314.pyc +0 -0
- package/onecode/agent/tools/__pycache__/communication_tools.cpython-314.pyc +0 -0
- package/onecode/agent/tools/__pycache__/config_tool.cpython-314.pyc +0 -0
- package/onecode/agent/tools/__pycache__/cron_tools.cpython-314.pyc +0 -0
- package/onecode/agent/tools/__pycache__/errors.cpython-314.pyc +0 -0
- package/onecode/agent/tools/__pycache__/file_ops.cpython-314.pyc +0 -0
- package/onecode/agent/tools/__pycache__/file_tools.cpython-314.pyc +0 -0
- package/onecode/agent/tools/__pycache__/git_tools.cpython-314.pyc +0 -0
- package/onecode/agent/tools/__pycache__/lsp_tools.cpython-314.pyc +0 -0
- package/onecode/agent/tools/__pycache__/mcp_tools.cpython-314.pyc +0 -0
- package/onecode/agent/tools/__pycache__/permission_handler.cpython-314.pyc +0 -0
- package/onecode/agent/tools/__pycache__/permissions.cpython-314.pyc +0 -0
- package/onecode/agent/tools/__pycache__/protocol.cpython-314.pyc +0 -0
- package/onecode/agent/tools/__pycache__/registry.cpython-314.pyc +0 -0
- package/onecode/agent/tools/__pycache__/sandbox.cpython-314.pyc +0 -0
- package/onecode/agent/tools/__pycache__/schema_validation.cpython-314.pyc +0 -0
- package/onecode/agent/tools/__pycache__/skill_tools.cpython-314.pyc +0 -0
- package/onecode/agent/tools/__pycache__/task_tools.cpython-314.pyc +0 -0
- package/onecode/agent/tools/__pycache__/web_tools.cpython-314.pyc +0 -0
- package/onecode/agent/tools/agent_tools.py +134 -0
- package/onecode/agent/tools/apply_patch_tool.py +144 -0
- package/onecode/agent/tools/bash_tool.py +91 -0
- package/onecode/agent/tools/communication_tools.py +149 -0
- package/onecode/agent/tools/config_tool.py +130 -0
- package/onecode/agent/tools/cron_tools.py +179 -0
- package/onecode/agent/tools/errors.py +17 -0
- package/onecode/agent/tools/file_ops.py +187 -0
- package/onecode/agent/tools/file_tools.py +226 -0
- package/onecode/agent/tools/git_tools.py +88 -0
- package/onecode/agent/tools/lsp_tools.py +404 -0
- package/onecode/agent/tools/mcp_tools.py +129 -0
- package/onecode/agent/tools/permission_handler.py +46 -0
- package/onecode/agent/tools/permissions.py +77 -0
- package/onecode/agent/tools/protocol.py +20 -0
- package/onecode/agent/tools/registry.py +134 -0
- package/onecode/agent/tools/sandbox.py +264 -0
- package/onecode/agent/tools/schema_validation.py +100 -0
- package/onecode/agent/tools/skill_tools.py +52 -0
- package/onecode/agent/tools/task_tools.py +249 -0
- package/onecode/agent/tools/web_tools.py +170 -0
- package/onecode/builtin_skills/git/SKILL.md +64 -0
- package/onecode/builtin_skills/git/skill.yaml +7 -0
- package/onecode/builtin_skills/shell/SKILL.md +58 -0
- package/onecode/builtin_skills/shell/skill.yaml +8 -0
- package/onecode/cli.py +755 -0
- package/onecode/cloud/__init__.py +0 -0
- package/onecode/cloud/base.py +20 -0
- package/onecode/codebase/__init__.py +69 -0
- package/onecode/codebase/__pycache__/__init__.cpython-314.pyc +0 -0
- package/onecode/codebase/__pycache__/chunker.cpython-314.pyc +0 -0
- package/onecode/codebase/__pycache__/config.cpython-314.pyc +0 -0
- package/onecode/codebase/__pycache__/indexer.cpython-314.pyc +0 -0
- package/onecode/codebase/__pycache__/retriever.cpython-314.pyc +0 -0
- package/onecode/codebase/__pycache__/storage.cpython-314.pyc +0 -0
- package/onecode/codebase/__pycache__/tools.cpython-314.pyc +0 -0
- package/onecode/codebase/chunker.py +130 -0
- package/onecode/codebase/indexer.py +136 -0
- package/onecode/codebase/retriever.py +192 -0
- package/onecode/codebase/storage.py +130 -0
- package/onecode/codebase/tools.py +59 -0
- package/onecode/commands.py +276 -0
- package/onecode/config.py +285 -0
- package/onecode/config_screen.py +594 -0
- package/onecode/cron/__init__.py +3 -0
- package/onecode/lsp/__init__.py +3 -0
- package/onecode/mcp/__init__.py +4 -0
- package/onecode/mcp/__pycache__/__init__.cpython-314.pyc +0 -0
- package/onecode/mcp/__pycache__/client.cpython-314.pyc +0 -0
- package/onecode/mcp/__pycache__/manager.cpython-314.pyc +0 -0
- package/onecode/mcp/client.py +193 -0
- package/onecode/mcp/manager.py +191 -0
- package/onecode/memory/__init__.py +95 -0
- package/onecode/memory/__pycache__/__init__.cpython-314.pyc +0 -0
- package/onecode/memory/__pycache__/backend.cpython-314.pyc +0 -0
- package/onecode/memory/__pycache__/offload.cpython-314.pyc +0 -0
- package/onecode/memory/__pycache__/pyramid.cpython-314.pyc +0 -0
- package/onecode/memory/__pycache__/recall.cpython-314.pyc +0 -0
- package/onecode/memory/__pycache__/symbolic.cpython-314.pyc +0 -0
- package/onecode/memory/backend.py +185 -0
- package/onecode/memory/offload.py +114 -0
- package/onecode/memory/pyramid.py +202 -0
- package/onecode/memory/recall.py +168 -0
- package/onecode/memory/symbolic.py +164 -0
- package/onecode/models/__init__.py +4 -0
- package/onecode/models/__pycache__/__init__.cpython-314.pyc +0 -0
- package/onecode/models/__pycache__/errors.cpython-314.pyc +0 -0
- package/onecode/models/__pycache__/messages.cpython-314.pyc +0 -0
- package/onecode/models/__pycache__/provider.cpython-314.pyc +0 -0
- package/onecode/models/__pycache__/registry.cpython-314.pyc +0 -0
- package/onecode/models/errors.py +94 -0
- package/onecode/models/messages.py +662 -0
- package/onecode/models/provider.py +450 -0
- package/onecode/models/providers/__init__.py +17 -0
- package/onecode/models/providers/__pycache__/__init__.cpython-314.pyc +0 -0
- package/onecode/models/providers/__pycache__/anthropic_provider.cpython-314.pyc +0 -0
- package/onecode/models/providers/__pycache__/deepseek_provider.cpython-314.pyc +0 -0
- package/onecode/models/providers/__pycache__/glm_provider.cpython-314.pyc +0 -0
- package/onecode/models/providers/__pycache__/minimax_provider.cpython-314.pyc +0 -0
- package/onecode/models/providers/__pycache__/minimaxi_provider.cpython-314.pyc +0 -0
- package/onecode/models/providers/__pycache__/mock_provider.cpython-314.pyc +0 -0
- package/onecode/models/providers/__pycache__/ollama_provider.cpython-314.pyc +0 -0
- package/onecode/models/providers/__pycache__/openai_provider.cpython-314.pyc +0 -0
- package/onecode/models/providers/anthropic_provider.py +224 -0
- package/onecode/models/providers/deepseek_provider.py +210 -0
- package/onecode/models/providers/glm_provider.py +154 -0
- package/onecode/models/providers/minimax_provider.py +154 -0
- package/onecode/models/providers/minimaxi_provider.py +363 -0
- package/onecode/models/providers/ollama_provider.py +96 -0
- package/onecode/models/providers/openai_provider.py +233 -0
- package/onecode/models/registry.py +212 -0
- package/onecode/server/__init__.py +3 -0
- package/onecode/server/app.py +224 -0
- package/onecode/skills/__init__.py +11 -0
- package/onecode/skills/__pycache__/__init__.cpython-314.pyc +0 -0
- package/onecode/skills/__pycache__/argument_substitution.cpython-314.pyc +0 -0
- package/onecode/skills/__pycache__/create.cpython-314.pyc +0 -0
- package/onecode/skills/__pycache__/frontmatter.cpython-314.pyc +0 -0
- package/onecode/skills/__pycache__/loader.cpython-314.pyc +0 -0
- package/onecode/skills/__pycache__/manager.cpython-314.pyc +0 -0
- package/onecode/skills/__pycache__/model.cpython-314.pyc +0 -0
- package/onecode/skills/argument_substitution.py +39 -0
- package/onecode/skills/create.py +56 -0
- package/onecode/skills/frontmatter.py +33 -0
- package/onecode/skills/loader.py +157 -0
- package/onecode/skills/manager.py +75 -0
- package/onecode/skills/model.py +43 -0
- package/onecode/storage/__init__.py +0 -0
- package/onecode/storage/activity.py +64 -0
- package/onecode/storage/project.py +54 -0
- package/onecode/storage/session.py +113 -0
- package/onecode/tasks/__init__.py +26 -0
- package/onecode/tasks/manager.py +219 -0
- package/onecode/tasks/models.py +240 -0
- package/onecode/trace/__init__.py +0 -0
- package/onecode/trace/tracer.py +174 -0
- package/onecode/utils/__init__.py +0 -0
- package/onecode/utils/helpers.py +20 -0
- package/onecode-cli.js +2 -0
- package/package.json +32 -0
- package/pyproject.toml +60 -0
- package/run.js +86 -0
- package/tui/__init__.py +46 -0
- package/tui/__main__.py +4 -0
- package/tui/__pycache__/__init__.cpython-314.pyc +0 -0
- package/tui/__pycache__/_loop.cpython-314.pyc +0 -0
- package/tui/__pycache__/_path_fuzzy_search.cpython-314.pyc +0 -0
- package/tui/__pycache__/_path_match.cpython-314.pyc +0 -0
- package/tui/__pycache__/agent.cpython-314.pyc +0 -0
- package/tui/__pycache__/agent_schema.cpython-314.pyc +0 -0
- package/tui/__pycache__/agents.cpython-314.pyc +0 -0
- package/tui/__pycache__/answer.cpython-314.pyc +0 -0
- package/tui/__pycache__/app.cpython-314.pyc +0 -0
- package/tui/__pycache__/atomic.cpython-314.pyc +0 -0
- package/tui/__pycache__/complete.cpython-314.pyc +0 -0
- package/tui/__pycache__/constants.cpython-314.pyc +0 -0
- package/tui/__pycache__/conversation_markdown.cpython-314.pyc +0 -0
- package/tui/__pycache__/danger.cpython-314.pyc +0 -0
- package/tui/__pycache__/db.cpython-314.pyc +0 -0
- package/tui/__pycache__/dec.cpython-314.pyc +0 -0
- package/tui/__pycache__/directory.cpython-314.pyc +0 -0
- package/tui/__pycache__/directory_suggester.cpython-314.pyc +0 -0
- package/tui/__pycache__/directory_watcher.cpython-314.pyc +0 -0
- package/tui/__pycache__/format_path.cpython-314.pyc +0 -0
- package/tui/__pycache__/fuzzy.cpython-314.pyc +0 -0
- package/tui/__pycache__/fuzzy_index.cpython-314.pyc +0 -0
- package/tui/__pycache__/history.cpython-314.pyc +0 -0
- package/tui/__pycache__/jsonrpc.cpython-314.pyc +0 -0
- package/tui/__pycache__/menus.cpython-314.pyc +0 -0
- package/tui/__pycache__/message_log.cpython-314.pyc +0 -0
- package/tui/__pycache__/messages.cpython-314.pyc +0 -0
- package/tui/__pycache__/path_complete.cpython-314.pyc +0 -0
- package/tui/__pycache__/path_filter.cpython-314.pyc +0 -0
- package/tui/__pycache__/paths.cpython-314.pyc +0 -0
- package/tui/__pycache__/pill.cpython-314.pyc +0 -0
- package/tui/__pycache__/platform_commands.cpython-314.pyc +0 -0
- package/tui/__pycache__/protocol.cpython-314.pyc +0 -0
- package/tui/__pycache__/session_tracker.cpython-314.pyc +0 -0
- package/tui/__pycache__/settings.cpython-314.pyc +0 -0
- package/tui/__pycache__/settings_schema.cpython-314.pyc +0 -0
- package/tui/__pycache__/shell.cpython-314.pyc +0 -0
- package/tui/__pycache__/shell_read.cpython-314.pyc +0 -0
- package/tui/__pycache__/slash_command.cpython-314.pyc +0 -0
- package/tui/__pycache__/version.cpython-314.pyc +0 -0
- package/tui/_loop.py +86 -0
- package/tui/_path_fuzzy_search.py +48 -0
- package/tui/_path_match.py +141 -0
- package/tui/about.py +95 -0
- package/tui/acp/__pycache__/agent.cpython-314.pyc +0 -0
- package/tui/acp/__pycache__/api.cpython-314.pyc +0 -0
- package/tui/acp/__pycache__/encode_tool_call_id.cpython-314.pyc +0 -0
- package/tui/acp/__pycache__/messages.cpython-314.pyc +0 -0
- package/tui/acp/__pycache__/prompt.cpython-314.pyc +0 -0
- package/tui/acp/__pycache__/protocol.cpython-314.pyc +0 -0
- package/tui/acp/agent.py +886 -0
- package/tui/acp/api.py +55 -0
- package/tui/acp/encode_tool_call_id.py +12 -0
- package/tui/acp/messages.py +190 -0
- package/tui/acp/prompt.py +110 -0
- package/tui/acp/protocol.py +462 -0
- package/tui/agent.py +70 -0
- package/tui/agent_schema.py +76 -0
- package/tui/agents.py +45 -0
- package/tui/ansi/__init__.py +1 -0
- package/tui/ansi/__pycache__/__init__.cpython-314.pyc +0 -0
- package/tui/ansi/__pycache__/_ansi.cpython-314.pyc +0 -0
- package/tui/ansi/__pycache__/_ansi_colors.cpython-314.pyc +0 -0
- package/tui/ansi/__pycache__/_control_codes.cpython-314.pyc +0 -0
- package/tui/ansi/__pycache__/_keys.cpython-314.pyc +0 -0
- package/tui/ansi/__pycache__/_sgr_styles.cpython-314.pyc +0 -0
- package/tui/ansi/__pycache__/_stream_parser.cpython-314.pyc +0 -0
- package/tui/ansi/_ansi.py +1689 -0
- package/tui/ansi/_ansi_colors.py +264 -0
- package/tui/ansi/_control_codes.py +37 -0
- package/tui/ansi/_keys.py +251 -0
- package/tui/ansi/_sgr_styles.py +64 -0
- package/tui/ansi/_stream_parser.py +418 -0
- package/tui/answer.py +12 -0
- package/tui/app.py +1236 -0
- package/tui/atomic.py +37 -0
- package/tui/cli.py +313 -0
- package/tui/code_analyze.py +27 -0
- package/tui/complete.py +38 -0
- package/tui/constants.py +61 -0
- package/tui/conversation_markdown.py +30 -0
- package/tui/danger.py +372 -0
- package/tui/data/agents/ampcode.com.toml +51 -0
- package/tui/data/agents/augmentcode.com.toml +40 -0
- package/tui/data/agents/cdh.cloud-dev-harness.toml +22 -0
- package/tui/data/agents/claude.com.toml +41 -0
- package/tui/data/agents/copilot.github.com.toml +29 -0
- package/tui/data/agents/crowai.dev.toml +35 -0
- package/tui/data/agents/cursor.com.toml +38 -0
- package/tui/data/agents/deepagents.langchain.com +33 -0
- package/tui/data/agents/docker.com.toml +59 -0
- package/tui/data/agents/geminicli.com.toml +28 -0
- package/tui/data/agents/goose.ai.toml +51 -0
- package/tui/data/agents/inference.huggingface.co.toml +41 -0
- package/tui/data/agents/kimi.com.toml +35 -0
- package/tui/data/agents/kiro.dev.toml +42 -0
- package/tui/data/agents/openai.com.toml +53 -0
- package/tui/data/agents/openclaw.ai.toml +37 -0
- package/tui/data/agents/opencode.ai.toml +39 -0
- package/tui/data/agents/openhands.dev.toml +45 -0
- package/tui/data/agents/stakpak.dev.toml +61 -0
- package/tui/data/agents/vibe.mistral.ai.toml +30 -0
- package/tui/data/agents/vtcode.dev.toml +62 -0
- package/tui/data/images/frog.png +0 -0
- package/tui/data/sounds/question.wav +0 -0
- package/tui/data/sounds/turn-over.wav +0 -0
- package/tui/db.py +190 -0
- package/tui/dec.py +332 -0
- package/tui/directory.py +234 -0
- package/tui/directory_suggester.py +93 -0
- package/tui/directory_watcher.py +197 -0
- package/tui/format_path.py +25 -0
- package/tui/fuzzy.py +140 -0
- package/tui/fuzzy_index.py +275 -0
- package/tui/gist.py +33 -0
- package/tui/history.py +138 -0
- package/tui/jsonrpc.py +578 -0
- package/tui/menus.py +14 -0
- package/tui/message_log.py +69 -0
- package/tui/messages.py +139 -0
- package/tui/option_content.py +51 -0
- package/tui/os.py +0 -0
- package/tui/path_complete.py +217 -0
- package/tui/path_filter.py +124 -0
- package/tui/paths.py +71 -0
- package/tui/pill.py +23 -0
- package/tui/platform_commands.py +52 -0
- package/tui/prompt/__pycache__/extract.cpython-314.pyc +0 -0
- package/tui/prompt/__pycache__/resource.cpython-314.pyc +0 -0
- package/tui/prompt/extract.py +19 -0
- package/tui/prompt/resource.py +68 -0
- package/tui/protocol.py +28 -0
- package/tui/screens/__init__.py +0 -0
- package/tui/screens/__pycache__/__init__.cpython-314.pyc +0 -0
- package/tui/screens/__pycache__/log.cpython-314.pyc +0 -0
- package/tui/screens/__pycache__/main.cpython-314.pyc +0 -0
- package/tui/screens/__pycache__/projects_screen.cpython-314.pyc +0 -0
- package/tui/screens/__pycache__/sessions.cpython-314.pyc +0 -0
- package/tui/screens/__pycache__/settings.cpython-314.pyc +0 -0
- package/tui/screens/__pycache__/store.cpython-314.pyc +0 -0
- package/tui/screens/action_modal.py +94 -0
- package/tui/screens/agent_modal.py +175 -0
- package/tui/screens/command_edit_modal.py +74 -0
- package/tui/screens/log.py +553 -0
- package/tui/screens/main.py +411 -0
- package/tui/screens/main.tcss +655 -0
- package/tui/screens/permissions.py +404 -0
- package/tui/screens/permissions.tcss +72 -0
- package/tui/screens/projects.tcss +66 -0
- package/tui/screens/projects_app.py +319 -0
- package/tui/screens/projects_screen.py +142 -0
- package/tui/screens/session_resume_modal.py +172 -0
- package/tui/screens/session_resume_modal.tcss +35 -0
- package/tui/screens/sessions.py +166 -0
- package/tui/screens/sessions.tcss +119 -0
- package/tui/screens/settings.py +254 -0
- package/tui/screens/settings.tcss +101 -0
- package/tui/screens/store.py +500 -0
- package/tui/screens/store.tcss +274 -0
- package/tui/screens/tool_content_screen.py +59 -0
- package/tui/session_tracker.py +120 -0
- package/tui/settings.py +353 -0
- package/tui/settings_schema.py +431 -0
- package/tui/shell.py +304 -0
- package/tui/shell_read.py +42 -0
- package/tui/slash_command.py +34 -0
- package/tui/tui.tcss +246 -0
- package/tui/twitter.py +38 -0
- package/tui/version.py +80 -0
- package/tui/visuals/__init__.py +0 -0
- package/tui/visuals/__pycache__/__init__.cpython-314.pyc +0 -0
- package/tui/visuals/__pycache__/columns.cpython-314.pyc +0 -0
- package/tui/visuals/columns.py +273 -0
- package/tui/widgets/__init__.py +0 -0
- package/tui/widgets/__pycache__/__init__.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/acp_content.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/agent_response.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/agent_thought.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/ask_user.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/condensed_path.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/context_stats.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/conversation.cpython-313.pyc +0 -0
- package/tui/widgets/__pycache__/conversation.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/diff_view.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/directory_input.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/flash.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/future_text.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/grid_select.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/highlighted_textarea.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/mandelbrot.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/markdown_note.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/menu.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/modified_files.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/non_selectable_label.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/note.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/path_search.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/plan.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/project_directory_tree.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/project_grid_select.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/project_summary.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/prompt.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/question.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/session_grid_select.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/session_summary.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/session_tabs.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/shell_result.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/shell_terminal.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/side_bar.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/slash_complete.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/strike_text.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/subagent.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/terminal.cpython-313.pyc +0 -0
- package/tui/widgets/__pycache__/terminal.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/throbber.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/tool_call.cpython-313.pyc +0 -0
- package/tui/widgets/__pycache__/tool_call.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/user_input.cpython-314.pyc +0 -0
- package/tui/widgets/acp_content.py +70 -0
- package/tui/widgets/agent_response.py +77 -0
- package/tui/widgets/agent_thought.py +168 -0
- package/tui/widgets/ask_user.py +264 -0
- package/tui/widgets/command_pane.py +223 -0
- package/tui/widgets/condensed_path.py +115 -0
- package/tui/widgets/context_stats.py +66 -0
- package/tui/widgets/conversation.py +2441 -0
- package/tui/widgets/danger_warning.py +65 -0
- package/tui/widgets/diff_view.py +59 -0
- package/tui/widgets/directory_input.py +8 -0
- package/tui/widgets/flash.py +81 -0
- package/tui/widgets/future_text.py +126 -0
- package/tui/widgets/grid_select.py +234 -0
- package/tui/widgets/highlighted_textarea.py +180 -0
- package/tui/widgets/mandelbrot.py +294 -0
- package/tui/widgets/markdown_note.py +13 -0
- package/tui/widgets/menu.py +147 -0
- package/tui/widgets/modified_files.py +106 -0
- package/tui/widgets/non_selectable_label.py +5 -0
- package/tui/widgets/note.py +18 -0
- package/tui/widgets/path_search.py +492 -0
- package/tui/widgets/plan.py +263 -0
- package/tui/widgets/project_directory_tree.py +90 -0
- package/tui/widgets/project_grid_select.py +35 -0
- package/tui/widgets/project_summary.py +33 -0
- package/tui/widgets/prompt.py +795 -0
- package/tui/widgets/question.py +360 -0
- package/tui/widgets/session_grid_select.py +224 -0
- package/tui/widgets/session_summary.py +115 -0
- package/tui/widgets/session_tabs.py +188 -0
- package/tui/widgets/shell_result.py +35 -0
- package/tui/widgets/shell_terminal.py +40 -0
- package/tui/widgets/side_bar.py +114 -0
- package/tui/widgets/slash_complete.py +235 -0
- package/tui/widgets/strike_text.py +70 -0
- package/tui/widgets/subagent.py +87 -0
- package/tui/widgets/terminal.py +577 -0
- package/tui/widgets/terminal_tool.py +351 -0
- package/tui/widgets/throbber.py +100 -0
- package/tui/widgets/tool_call.py +368 -0
- package/tui/widgets/user_input.py +23 -0
- package/tui/widgets/version.py +5 -0
- package/tui/widgets/welcome.py +31 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
import fnmatch
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Optional
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass
|
|
11
|
+
class OffloadConfig:
|
|
12
|
+
enabled: bool = True
|
|
13
|
+
mild_ratio: float = 0.5
|
|
14
|
+
aggressive_ratio: float = 0.85
|
|
15
|
+
mmd_max_token_ratio: float = 0.2
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class ContextOffloader:
|
|
19
|
+
def __init__(
|
|
20
|
+
self,
|
|
21
|
+
refs_dir: Optional[Path] = None,
|
|
22
|
+
config: Optional[OffloadConfig] = None,
|
|
23
|
+
):
|
|
24
|
+
from onecode.config import CLOUD_DEV_HARNESS_DIR
|
|
25
|
+
self.refs_dir = refs_dir or (CLOUD_DEV_HARNESS_DIR / "memory" / "refs")
|
|
26
|
+
self.refs_dir.mkdir(parents=True, exist_ok=True)
|
|
27
|
+
self.config = config or OffloadConfig()
|
|
28
|
+
self._offloaded_refs: dict[str, Path] = {}
|
|
29
|
+
|
|
30
|
+
def should_offload(self, context_length: int, max_tokens: int) -> tuple[bool, str]:
|
|
31
|
+
if not self.config.enabled:
|
|
32
|
+
return False, "disabled"
|
|
33
|
+
|
|
34
|
+
ratio = context_length / max_tokens if max_tokens > 0 else 0
|
|
35
|
+
|
|
36
|
+
if ratio >= self.config.aggressive_ratio:
|
|
37
|
+
return True, "aggressive"
|
|
38
|
+
elif ratio >= self.config.mild_ratio:
|
|
39
|
+
return True, "mild"
|
|
40
|
+
return False, "none"
|
|
41
|
+
|
|
42
|
+
def offload_content(
|
|
43
|
+
self,
|
|
44
|
+
content: str,
|
|
45
|
+
node_id: str,
|
|
46
|
+
file_pattern: str = "*.md",
|
|
47
|
+
) -> str:
|
|
48
|
+
ext = file_pattern.replace("*", "md")
|
|
49
|
+
ref_file = self.refs_dir / f"{node_id}.{ext}"
|
|
50
|
+
ref_file.write_text(content, encoding="utf-8")
|
|
51
|
+
self._offloaded_refs[node_id] = ref_file
|
|
52
|
+
return f"See refs/{node_id}.{ext}"
|
|
53
|
+
|
|
54
|
+
def recall_ref(self, node_id: str) -> Optional[str]:
|
|
55
|
+
ref_file = self._offloaded_refs.get(node_id)
|
|
56
|
+
if ref_file and ref_file.exists():
|
|
57
|
+
return ref_file.read_text(encoding="utf-8")
|
|
58
|
+
for ext in ["md", "txt", "log"]:
|
|
59
|
+
alt_path = self.refs_dir / f"{node_id}.{ext}"
|
|
60
|
+
if alt_path.exists():
|
|
61
|
+
return alt_path.read_text(encoding="utf-8")
|
|
62
|
+
return None
|
|
63
|
+
|
|
64
|
+
def list_offloaded(self) -> list[str]:
|
|
65
|
+
return list(self._offloaded_refs.keys())
|
|
66
|
+
|
|
67
|
+
def cleanup_old_refs(self, max_age_hours: int = 24) -> int:
|
|
68
|
+
import time
|
|
69
|
+
from datetime import datetime, timezone
|
|
70
|
+
removed = 0
|
|
71
|
+
for ref_file in self.refs_dir.iterdir():
|
|
72
|
+
if ref_file.is_file():
|
|
73
|
+
age_hours = (time.time() - ref_file.stat().st_mtime) / 3600
|
|
74
|
+
if age_hours > max_age_hours:
|
|
75
|
+
ref_file.unlink()
|
|
76
|
+
node_id = ref_file.stem
|
|
77
|
+
if node_id in self._offloaded_refs:
|
|
78
|
+
del self._offloaded_refs[node_id]
|
|
79
|
+
removed += 1
|
|
80
|
+
return removed
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
class ToolCallExtractor:
|
|
84
|
+
PATTERNS = [
|
|
85
|
+
re.compile(r'\[TOOL_CALL\]\s*(\w+)\s*:\s*(.+)', re.DOTALL),
|
|
86
|
+
re.compile(r'"tool":\s*"(\w+)"[^}]*"args":\s*({.+?})', re.DOTALL),
|
|
87
|
+
re.compile(r'(\w+)\((.*?)\)\s*=>\s*(.+)', re.DOTALL),
|
|
88
|
+
]
|
|
89
|
+
|
|
90
|
+
@classmethod
|
|
91
|
+
def extract_calls(cls, text: str) -> list[dict]:
|
|
92
|
+
calls = []
|
|
93
|
+
for pattern in cls.PATTERNS:
|
|
94
|
+
matches = pattern.finditer(text)
|
|
95
|
+
for match in matches:
|
|
96
|
+
if pattern == cls.PATTERNS[0]:
|
|
97
|
+
calls.append({"tool": match.group(1), "args": match.group(2)})
|
|
98
|
+
elif pattern == cls.PATTERNS[1]:
|
|
99
|
+
calls.append({"tool": match.group(1), "args": match.group(2)})
|
|
100
|
+
else:
|
|
101
|
+
calls.append({"tool": match.group(1), "args": match.group(2), "result": match.group(3)})
|
|
102
|
+
return calls
|
|
103
|
+
|
|
104
|
+
@classmethod
|
|
105
|
+
def format_as_mermaid(cls, calls: list[dict]) -> str:
|
|
106
|
+
lines = ["graph LR"]
|
|
107
|
+
for i, call in enumerate(calls):
|
|
108
|
+
node_id = f"C{i:03d}"
|
|
109
|
+
tool_name = call.get("tool", "unknown")
|
|
110
|
+
lines.append(f" {node_id}[{tool_name}]")
|
|
111
|
+
if i > 0:
|
|
112
|
+
prev_id = f"C{i-1:03d}"
|
|
113
|
+
lines.append(f" {prev_id} --> {node_id}")
|
|
114
|
+
return "\n".join(lines)
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import uuid
|
|
5
|
+
from dataclasses import dataclass, field
|
|
6
|
+
from datetime import datetime, timezone
|
|
7
|
+
from enum import Enum
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import Optional
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class MemoryLayer(Enum):
|
|
13
|
+
L0_CONVERSATION = "l0_conversation"
|
|
14
|
+
L1_ATOM = "l1_atom"
|
|
15
|
+
L2_SCENARIO = "l2_scenario"
|
|
16
|
+
L3_PERSONA = "l3_persona"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@dataclass
|
|
20
|
+
class MemoryEntry:
|
|
21
|
+
id: str
|
|
22
|
+
layer: MemoryLayer
|
|
23
|
+
content: str
|
|
24
|
+
timestamp: str
|
|
25
|
+
metadata: dict = field(default_factory=dict)
|
|
26
|
+
parent_id: Optional[str] = None
|
|
27
|
+
result_ref: Optional[str] = None
|
|
28
|
+
|
|
29
|
+
@classmethod
|
|
30
|
+
def create(
|
|
31
|
+
cls,
|
|
32
|
+
layer: MemoryLayer,
|
|
33
|
+
content: str,
|
|
34
|
+
metadata: Optional[dict] = None,
|
|
35
|
+
parent_id: Optional[str] = None,
|
|
36
|
+
) -> "MemoryEntry":
|
|
37
|
+
return cls(
|
|
38
|
+
id=str(uuid.uuid4())[:16],
|
|
39
|
+
layer=layer,
|
|
40
|
+
content=content,
|
|
41
|
+
timestamp=datetime.now(timezone.utc).isoformat(),
|
|
42
|
+
metadata=metadata or {},
|
|
43
|
+
parent_id=parent_id,
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
def to_dict(self) -> dict:
|
|
47
|
+
return {
|
|
48
|
+
"id": self.id,
|
|
49
|
+
"layer": self.layer.value,
|
|
50
|
+
"content": self.content,
|
|
51
|
+
"timestamp": self.timestamp,
|
|
52
|
+
"metadata": self.metadata,
|
|
53
|
+
"parent_id": self.parent_id,
|
|
54
|
+
"result_ref": self.result_ref,
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@classmethod
|
|
58
|
+
def from_dict(cls, data: dict) -> "MemoryEntry":
|
|
59
|
+
return cls(
|
|
60
|
+
id=data["id"],
|
|
61
|
+
layer=MemoryLayer(data["layer"]),
|
|
62
|
+
content=data["content"],
|
|
63
|
+
timestamp=data["timestamp"],
|
|
64
|
+
metadata=data.get("metadata", {}),
|
|
65
|
+
parent_id=data.get("parent_id"),
|
|
66
|
+
result_ref=data.get("result_ref"),
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class MemoryPyramid:
|
|
71
|
+
def __init__(self, storage_path: Optional[Path] = None):
|
|
72
|
+
from onecode.config import CLOUD_DEV_HARNESS_DIR
|
|
73
|
+
self.storage_path = storage_path or (CLOUD_DEV_HARNESS_DIR / "memory")
|
|
74
|
+
self.storage_path.mkdir(parents=True, exist_ok=True)
|
|
75
|
+
self._layers = {layer: [] for layer in MemoryLayer}
|
|
76
|
+
self._load_index()
|
|
77
|
+
|
|
78
|
+
def _layer_dir(self, layer: MemoryLayer) -> Path:
|
|
79
|
+
return self.storage_path / layer.value
|
|
80
|
+
|
|
81
|
+
def _load_index(self) -> None:
|
|
82
|
+
index_file = self.storage_path / "index.json"
|
|
83
|
+
if index_file.exists():
|
|
84
|
+
try:
|
|
85
|
+
data = json.loads(index_file.read_text(encoding="utf-8"))
|
|
86
|
+
for layer_str, entries in data.items():
|
|
87
|
+
layer = MemoryLayer(layer_str)
|
|
88
|
+
self._layers[layer] = [MemoryEntry.from_dict(e) for e in entries]
|
|
89
|
+
except Exception:
|
|
90
|
+
pass
|
|
91
|
+
|
|
92
|
+
def _save_index(self) -> None:
|
|
93
|
+
index_file = self.storage_path / "index.json"
|
|
94
|
+
data = {layer.value: [e.to_dict() for e in entries] for layer, entries in self._layers.items()}
|
|
95
|
+
index_file.write_text(json.dumps(data, indent=2, ensure_ascii=False), encoding="utf-8")
|
|
96
|
+
|
|
97
|
+
def add(
|
|
98
|
+
self,
|
|
99
|
+
layer: MemoryLayer,
|
|
100
|
+
content: str,
|
|
101
|
+
metadata: Optional[dict] = None,
|
|
102
|
+
parent_id: Optional[str] = None,
|
|
103
|
+
result_ref: Optional[str] = None,
|
|
104
|
+
) -> MemoryEntry:
|
|
105
|
+
entry = MemoryEntry.create(layer, content, metadata, parent_id)
|
|
106
|
+
entry.result_ref = result_ref
|
|
107
|
+
self._layers[layer].append(entry)
|
|
108
|
+
self._save_index()
|
|
109
|
+
self._write_content(layer, entry)
|
|
110
|
+
return entry
|
|
111
|
+
|
|
112
|
+
def _write_content(self, layer: MemoryLayer, entry: MemoryEntry) -> None:
|
|
113
|
+
layer_dir = self._layer_dir(layer)
|
|
114
|
+
layer_dir.mkdir(parents=True, exist_ok=True)
|
|
115
|
+
content_file = layer_dir / f"{entry.id}.md"
|
|
116
|
+
content_file.write_text(entry.content, encoding="utf-8")
|
|
117
|
+
|
|
118
|
+
def get(self, layer: MemoryLayer, entry_id: str) -> Optional[MemoryEntry]:
|
|
119
|
+
for entry in self._layers[layer]:
|
|
120
|
+
if entry.id == entry_id:
|
|
121
|
+
return entry
|
|
122
|
+
return None
|
|
123
|
+
|
|
124
|
+
def get_content(self, entry: MemoryEntry) -> str:
|
|
125
|
+
layer_dir = self._layer_dir(entry.layer)
|
|
126
|
+
content_file = layer_dir / f"{entry.id}.md"
|
|
127
|
+
if content_file.exists():
|
|
128
|
+
return content_file.read_text(encoding="utf-8")
|
|
129
|
+
return entry.content
|
|
130
|
+
|
|
131
|
+
def list_by_layer(self, layer: MemoryLayer) -> list[MemoryEntry]:
|
|
132
|
+
return list(self._layers.get(layer, []))
|
|
133
|
+
|
|
134
|
+
def list_recent(self, layer: MemoryLayer, limit: int = 10) -> list[MemoryEntry]:
|
|
135
|
+
entries = self._layers.get(layer, [])
|
|
136
|
+
return sorted(entries, key=lambda e: e.timestamp, reverse=True)[:limit]
|
|
137
|
+
|
|
138
|
+
def drill_down(self, entry_id: str) -> list[MemoryEntry]:
|
|
139
|
+
chain = []
|
|
140
|
+
current = self._find_entry_anywhere(entry_id)
|
|
141
|
+
while current:
|
|
142
|
+
chain.append(current)
|
|
143
|
+
if current.parent_id:
|
|
144
|
+
current = self._find_entry_anywhere(current.parent_id)
|
|
145
|
+
else:
|
|
146
|
+
current = None
|
|
147
|
+
return list(reversed(chain))
|
|
148
|
+
|
|
149
|
+
def _find_entry_anywhere(self, entry_id: str) -> Optional[MemoryEntry]:
|
|
150
|
+
for entries in self._layers.values():
|
|
151
|
+
for entry in entries:
|
|
152
|
+
if entry.id == entry_id:
|
|
153
|
+
return entry
|
|
154
|
+
return None
|
|
155
|
+
|
|
156
|
+
def extract_atoms_from_conversation(
|
|
157
|
+
self, conversation_id: str, max_atoms: int = 20
|
|
158
|
+
) -> list[MemoryEntry]:
|
|
159
|
+
l0_entries = [e for e in self._layers[MemoryLayer.L0_CONVERSATION] if e.parent_id == conversation_id]
|
|
160
|
+
atoms = []
|
|
161
|
+
for l0 in l0_entries:
|
|
162
|
+
content = self.get_content(l0)
|
|
163
|
+
if len(content) > 100:
|
|
164
|
+
atom_content = content[:200] + "..."
|
|
165
|
+
else:
|
|
166
|
+
atom_content = content
|
|
167
|
+
atom = self.add(
|
|
168
|
+
MemoryLayer.L1_ATOM,
|
|
169
|
+
atom_content,
|
|
170
|
+
metadata={"source": "auto_extract", "source_id": l0.id},
|
|
171
|
+
parent_id=l0.id,
|
|
172
|
+
)
|
|
173
|
+
atoms.append(atom)
|
|
174
|
+
if len(atoms) >= max_atoms:
|
|
175
|
+
break
|
|
176
|
+
return atoms
|
|
177
|
+
|
|
178
|
+
def build_scenario_from_atoms(self, atom_ids: list[str], name: str) -> MemoryEntry:
|
|
179
|
+
atom_contents = []
|
|
180
|
+
for atom_id in atom_ids:
|
|
181
|
+
atom = self._find_entry_anywhere(atom_id)
|
|
182
|
+
if atom:
|
|
183
|
+
atom_contents.append(f"- {atom.content}")
|
|
184
|
+
content = f"## {name}\n\n" + "\n".join(atom_contents)
|
|
185
|
+
return self.add(
|
|
186
|
+
MemoryLayer.L2_SCENARIO,
|
|
187
|
+
content,
|
|
188
|
+
metadata={"atom_count": len(atom_ids)},
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
def build_persona_from_scenarios(self, scenario_ids: list[str], name: str) -> MemoryEntry:
|
|
192
|
+
scenario_contents = []
|
|
193
|
+
for sc_id in scenario_ids:
|
|
194
|
+
sc = self._find_entry_anywhere(sc_id)
|
|
195
|
+
if sc:
|
|
196
|
+
scenario_contents.append(f"### {sc.content[:100]}...\n{sc.content}")
|
|
197
|
+
content = f"# {name}\n\n" + "\n".join(scenario_contents)
|
|
198
|
+
return self.add(
|
|
199
|
+
MemoryLayer.L3_PERSONA,
|
|
200
|
+
content,
|
|
201
|
+
metadata={"scenario_count": len(scenario_ids)},
|
|
202
|
+
)
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import math
|
|
4
|
+
import re
|
|
5
|
+
from collections import Counter
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from typing import Optional
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass
|
|
11
|
+
class RecallResult:
|
|
12
|
+
entry_id: str
|
|
13
|
+
content: str
|
|
14
|
+
score: float
|
|
15
|
+
source: str
|
|
16
|
+
metadata: dict
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class BM25:
|
|
20
|
+
def __init__(self, k1: float = 1.5, b: float = 0.75):
|
|
21
|
+
self.k1 = k1
|
|
22
|
+
self.b = b
|
|
23
|
+
self.doc_lengths: list[int] = []
|
|
24
|
+
self.avgdl: float = 0
|
|
25
|
+
self.doc_freqs: dict[str, int] = {}
|
|
26
|
+
self.num_docs: int = 0
|
|
27
|
+
self.doc_tokens: list[list[str]] = []
|
|
28
|
+
|
|
29
|
+
def index(self, documents: list[str]) -> None:
|
|
30
|
+
self.doc_tokens = [self._tokenize(doc) for doc in documents]
|
|
31
|
+
self.doc_lengths = [len(tokens) for tokens in self.doc_tokens]
|
|
32
|
+
self.avgdl = sum(self.doc_lengths) / len(self.doc_lengths) if self.doc_lengths else 0
|
|
33
|
+
self.num_docs = len(documents)
|
|
34
|
+
|
|
35
|
+
all_tokens = set()
|
|
36
|
+
for tokens in self.doc_tokens:
|
|
37
|
+
all_tokens.update(tokens)
|
|
38
|
+
self.doc_freqs = {token: sum(1 for doc in self.doc_tokens if token in doc) for token in all_tokens}
|
|
39
|
+
|
|
40
|
+
def _tokenize(self, text: str) -> list[str]:
|
|
41
|
+
text = text.lower()
|
|
42
|
+
tokens = re.findall(r"\b\w+\b", text)
|
|
43
|
+
return tokens
|
|
44
|
+
|
|
45
|
+
def score(self, query: str, doc_index: int) -> float:
|
|
46
|
+
query_tokens = self._tokenize(query)
|
|
47
|
+
doc_tokens = self.doc_tokens[doc_index]
|
|
48
|
+
doc_len = self.doc_lengths[doc_index]
|
|
49
|
+
score = 0.0
|
|
50
|
+
|
|
51
|
+
for qt in query_tokens:
|
|
52
|
+
if qt not in self.doc_freqs:
|
|
53
|
+
continue
|
|
54
|
+
df = self.doc_freqs[qt]
|
|
55
|
+
idf = math.log((self.num_docs - df + 0.5) / (df + 0.5) + 1)
|
|
56
|
+
tf = doc_tokens.count(qt)
|
|
57
|
+
tf_score = (tf * (self.k1 + 1)) / (tf + self.k1 * (1 - self.b + self.b * doc_len / self.avgdl))
|
|
58
|
+
score += idf * tf_score
|
|
59
|
+
return score
|
|
60
|
+
|
|
61
|
+
def search(self, query: str, top_k: int = 5) -> list[tuple[int, float]]:
|
|
62
|
+
scores = [(i, self.score(query, i)) for i in range(self.num_docs)]
|
|
63
|
+
scores.sort(key=lambda x: x[1], reverse=True)
|
|
64
|
+
return scores[:top_k]
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class HybridRecall:
|
|
68
|
+
def __init__(
|
|
69
|
+
self,
|
|
70
|
+
bm25: Optional[BM25] = None,
|
|
71
|
+
embedding_fn: Optional[callable] = None,
|
|
72
|
+
):
|
|
73
|
+
self.bm25 = bm25 or BM25()
|
|
74
|
+
self.embedding_fn = embedding_fn
|
|
75
|
+
self._documents: list[str] = []
|
|
76
|
+
self._embeddings: list[list[float]] = []
|
|
77
|
+
self._entry_ids: list[str] = []
|
|
78
|
+
self._metadata: dict[str, dict] = {}
|
|
79
|
+
|
|
80
|
+
def add_documents(self, documents: list[str], entry_ids: Optional[list[str]] = None, metadata: Optional[dict] = None) -> None:
|
|
81
|
+
start_idx = len(self._documents)
|
|
82
|
+
self._documents.extend(documents)
|
|
83
|
+
for i, doc in enumerate(documents):
|
|
84
|
+
eid = entry_ids[i] if entry_ids and i < len(entry_ids) else f"doc_{start_idx + i}"
|
|
85
|
+
self._entry_ids.append(eid)
|
|
86
|
+
if metadata and eid in metadata:
|
|
87
|
+
self._metadata[eid] = metadata[eid]
|
|
88
|
+
|
|
89
|
+
self.bm25.index(self._documents)
|
|
90
|
+
|
|
91
|
+
if self.embedding_fn:
|
|
92
|
+
for doc in documents:
|
|
93
|
+
emb = self.embedding_fn(doc)
|
|
94
|
+
self._embeddings.append(emb)
|
|
95
|
+
|
|
96
|
+
def keyword_recall(self, query: str, top_k: int = 5) -> list[RecallResult]:
|
|
97
|
+
bm25_results = self.bm25.search(query, top_k * 2)
|
|
98
|
+
results = []
|
|
99
|
+
for doc_idx, bm25_score in bm25_results:
|
|
100
|
+
if doc_idx < len(self._entry_ids):
|
|
101
|
+
eid = self._entry_ids[doc_idx]
|
|
102
|
+
results.append(RecallResult(
|
|
103
|
+
entry_id=eid,
|
|
104
|
+
content=self._documents[doc_idx],
|
|
105
|
+
score=bm25_score,
|
|
106
|
+
source="bm25",
|
|
107
|
+
metadata=self._metadata.get(eid, {}),
|
|
108
|
+
))
|
|
109
|
+
return results[:top_k]
|
|
110
|
+
|
|
111
|
+
def semantic_recall(self, query: str, top_k: int = 5) -> list[RecallResult]:
|
|
112
|
+
if not self.embedding_fn:
|
|
113
|
+
return []
|
|
114
|
+
|
|
115
|
+
query_emb = self.embedding_fn(query)
|
|
116
|
+
similarities = []
|
|
117
|
+
|
|
118
|
+
for i, emb in enumerate(self._embeddings):
|
|
119
|
+
sim = self._cosine_similarity(query_emb, emb)
|
|
120
|
+
similarities.append((i, sim))
|
|
121
|
+
|
|
122
|
+
similarities.sort(key=lambda x: x[1], reverse=True)
|
|
123
|
+
results = []
|
|
124
|
+
for doc_idx, sim_score in similarities[:top_k]:
|
|
125
|
+
eid = self._entry_ids[doc_idx]
|
|
126
|
+
results.append(RecallResult(
|
|
127
|
+
entry_id=eid,
|
|
128
|
+
content=self._documents[doc_idx],
|
|
129
|
+
score=sim_score,
|
|
130
|
+
source="embedding",
|
|
131
|
+
metadata=self._metadata.get(eid, {}),
|
|
132
|
+
))
|
|
133
|
+
return results
|
|
134
|
+
|
|
135
|
+
def _cosine_similarity(self, a: list[float], b: list[float]) -> float:
|
|
136
|
+
dot = sum(x * y for x, y in zip(a, b))
|
|
137
|
+
norm_a = math.sqrt(sum(x * x for x in a))
|
|
138
|
+
norm_b = math.sqrt(sum(x * x for x in b))
|
|
139
|
+
if norm_a == 0 or norm_b == 0:
|
|
140
|
+
return 0
|
|
141
|
+
return dot / (norm_a * norm_b)
|
|
142
|
+
|
|
143
|
+
def hybrid_recall(self, query: str, top_k: int = 5, rrf_k: int = 60) -> list[RecallResult]:
|
|
144
|
+
bm25_results = self.keyword_recall(query, top_k * 2)
|
|
145
|
+
semantic_results = self.semantic_recall(query, top_k * 2)
|
|
146
|
+
|
|
147
|
+
rrf_scores: dict[str, float] = {}
|
|
148
|
+
rrf_results: dict[str, RecallResult] = {}
|
|
149
|
+
|
|
150
|
+
for rank, result in enumerate(bm25_results):
|
|
151
|
+
score = 1.0 / (rrf_k + rank + 1)
|
|
152
|
+
rrf_scores[result.entry_id] = rrf_scores.get(result.entry_id, 0) + score
|
|
153
|
+
rrf_results[result.entry_id] = result
|
|
154
|
+
|
|
155
|
+
for rank, result in enumerate(semantic_results):
|
|
156
|
+
score = 1.0 / (rrf_k + rank + 1)
|
|
157
|
+
rrf_scores[result.entry_id] = rrf_scores.get(result.entry_id, 0) + score
|
|
158
|
+
rrf_results[result.entry_id] = result
|
|
159
|
+
|
|
160
|
+
sorted_ids = sorted(rrf_scores.items(), key=lambda x: x[1], reverse=True)
|
|
161
|
+
return [rrf_results[eid] for eid, _ in sorted_ids[:top_k]]
|
|
162
|
+
|
|
163
|
+
def clear(self) -> None:
|
|
164
|
+
self._documents = []
|
|
165
|
+
self._embeddings = []
|
|
166
|
+
self._entry_ids = []
|
|
167
|
+
self._metadata = {}
|
|
168
|
+
self.bm25 = BM25()
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
import uuid
|
|
5
|
+
from dataclasses import dataclass, field
|
|
6
|
+
from datetime import datetime, timezone
|
|
7
|
+
from enum import Enum
|
|
8
|
+
from typing import Optional
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class NodeType(Enum):
|
|
12
|
+
TASK = "task"
|
|
13
|
+
ACTION = "action"
|
|
14
|
+
RESULT = "result"
|
|
15
|
+
ERROR = "error"
|
|
16
|
+
CHECKPOINT = "checkpoint"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@dataclass
|
|
20
|
+
class MermaidNode:
|
|
21
|
+
node_id: str
|
|
22
|
+
node_type: NodeType
|
|
23
|
+
label: str
|
|
24
|
+
metadata: dict = field(default_factory=dict)
|
|
25
|
+
|
|
26
|
+
def to_mermaid(self) -> str:
|
|
27
|
+
type_styles = {
|
|
28
|
+
NodeType.TASK: "([,shape=ellipse",
|
|
29
|
+
NodeType.ACTION: "[,shape=box",
|
|
30
|
+
NodeType.RESULT: "[(,shape=cylinder",
|
|
31
|
+
NodeType.ERROR: "([,shape=ellipse,color=red",
|
|
32
|
+
NodeType.CHECKPOINT: "[,shape=diamond",
|
|
33
|
+
}
|
|
34
|
+
style = type_styles.get(self.node_type, "[")
|
|
35
|
+
return f" {self.node_id}{style} {self.label}])"
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@dataclass
|
|
39
|
+
class MermaidEdge:
|
|
40
|
+
from_node: str
|
|
41
|
+
to_node: str
|
|
42
|
+
label: Optional[str] = None
|
|
43
|
+
style: str = ""
|
|
44
|
+
|
|
45
|
+
def to_mermaid(self) -> str:
|
|
46
|
+
edge_str = f" {self.from_node} --> {self.to_node}"
|
|
47
|
+
if self.label:
|
|
48
|
+
edge_str = f" {self.from_node} -->|{self.label}| {self.to_node}"
|
|
49
|
+
if self.style:
|
|
50
|
+
edge_str += f" -. {self.style} .-> {self.to_node}"
|
|
51
|
+
return edge_str
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class MermaidCanvas:
|
|
55
|
+
def __init__(self, task_id: Optional[str] = None):
|
|
56
|
+
self.task_id = task_id or str(uuid.uuid4())[:8]
|
|
57
|
+
self.nodes: list[MermaidNode] = []
|
|
58
|
+
self.edges: list[MermaidEdge] = []
|
|
59
|
+
self.refs: dict[str, str] = {}
|
|
60
|
+
|
|
61
|
+
def add_node(
|
|
62
|
+
self,
|
|
63
|
+
node_type: NodeType,
|
|
64
|
+
label: str,
|
|
65
|
+
metadata: Optional[dict] = None,
|
|
66
|
+
) -> str:
|
|
67
|
+
node_id = f"N{len(self.nodes):03d}"
|
|
68
|
+
node = MermaidNode(node_id, node_type, label, metadata or {})
|
|
69
|
+
self.nodes.append(node)
|
|
70
|
+
return node_id
|
|
71
|
+
|
|
72
|
+
def add_edge(
|
|
73
|
+
self,
|
|
74
|
+
from_node: str,
|
|
75
|
+
to_node: str,
|
|
76
|
+
label: Optional[str] = None,
|
|
77
|
+
style: str = "",
|
|
78
|
+
) -> None:
|
|
79
|
+
edge = MermaidEdge(from_node, to_node, label, style)
|
|
80
|
+
self.edges.append(edge)
|
|
81
|
+
|
|
82
|
+
def add_ref(self, node_id: str, content: str) -> None:
|
|
83
|
+
self.refs[node_id] = content
|
|
84
|
+
|
|
85
|
+
def get_ref(self, node_id: str) -> Optional[str]:
|
|
86
|
+
return self.refs.get(node_id)
|
|
87
|
+
|
|
88
|
+
def to_mermaid(self) -> str:
|
|
89
|
+
if not self.nodes:
|
|
90
|
+
return "graph LR\n empty((empty))"
|
|
91
|
+
|
|
92
|
+
lines = ["graph LR"]
|
|
93
|
+
for node in self.nodes:
|
|
94
|
+
lines.append(node.to_mermaid())
|
|
95
|
+
for edge in self.edges:
|
|
96
|
+
lines.append(edge.to_mermaid())
|
|
97
|
+
return "\n".join(lines)
|
|
98
|
+
|
|
99
|
+
def to_markdown(self) -> str:
|
|
100
|
+
lines = [f"## Task Canvas: {self.task_id}\n"]
|
|
101
|
+
lines.append(f"Generated: {datetime.now(timezone.utc).isoformat()}\n")
|
|
102
|
+
lines.append("### Mermaid Diagram\n```mermaid")
|
|
103
|
+
lines.append(self.to_mermaid())
|
|
104
|
+
lines.append("```\n")
|
|
105
|
+
if self.refs:
|
|
106
|
+
lines.append("### References\n")
|
|
107
|
+
for node_id, content in self.refs.items():
|
|
108
|
+
lines.append(f"**{node_id}**: {content[:200]}...\n")
|
|
109
|
+
return "\n".join(lines)
|
|
110
|
+
|
|
111
|
+
@classmethod
|
|
112
|
+
def from_mermaid(cls, mermaid_text: str) -> Optional["MermaidCanvas"]:
|
|
113
|
+
try:
|
|
114
|
+
canvas = cls()
|
|
115
|
+
node_pattern = re.compile(r"(\w+)\[(.*?)\]")
|
|
116
|
+
for match in node_pattern.finditer(mermaid_text):
|
|
117
|
+
node_id, label = match.groups()
|
|
118
|
+
if node_id.startswith("N"):
|
|
119
|
+
canvas.add_node(NodeType.ACTION, label)
|
|
120
|
+
return canvas
|
|
121
|
+
except Exception:
|
|
122
|
+
return None
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
class SymbolicMemory:
|
|
126
|
+
def __init__(self, canvas: Optional[MermaidCanvas] = None):
|
|
127
|
+
self.canvas = canvas or MermaidCanvas()
|
|
128
|
+
self._verbose_cache: dict[str, str] = {}
|
|
129
|
+
|
|
130
|
+
def offload_log(self, node_id: str, verbose_content: str) -> str:
|
|
131
|
+
self._verbose_cache[node_id] = verbose_content
|
|
132
|
+
self.canvas.add_ref(node_id, f"See ref: {node_id}")
|
|
133
|
+
return f"[{node_id}]"
|
|
134
|
+
|
|
135
|
+
def recall_log(self, node_id: str) -> Optional[str]:
|
|
136
|
+
return self._verbose_cache.get(node_id)
|
|
137
|
+
|
|
138
|
+
def create_task_node(self, label: str, metadata: Optional[dict] = None) -> str:
|
|
139
|
+
return self.canvas.add_node(NodeType.TASK, label, metadata)
|
|
140
|
+
|
|
141
|
+
def create_action_node(self, label: str, metadata: Optional[dict] = None) -> str:
|
|
142
|
+
return self.canvas.add_node(NodeType.ACTION, label, metadata)
|
|
143
|
+
|
|
144
|
+
def create_result_node(self, label: str, result_content: str, metadata: Optional[dict] = None) -> str:
|
|
145
|
+
node_id = self.canvas.add_node(NodeType.RESULT, label, metadata)
|
|
146
|
+
self.offload_log(node_id, result_content)
|
|
147
|
+
return node_id
|
|
148
|
+
|
|
149
|
+
def create_error_node(self, label: str, error_content: str, metadata: Optional[dict] = None) -> str:
|
|
150
|
+
node_id = self.canvas.add_node(NodeType.ERROR, label, metadata)
|
|
151
|
+
self.offload_log(node_id, error_content)
|
|
152
|
+
return node_id
|
|
153
|
+
|
|
154
|
+
def link(self, from_id: str, to_id: str, label: Optional[str] = None) -> None:
|
|
155
|
+
self.canvas.add_edge(from_id, to_id, label)
|
|
156
|
+
|
|
157
|
+
def get_canvas_markdown(self) -> str:
|
|
158
|
+
return self.canvas.to_markdown()
|
|
159
|
+
|
|
160
|
+
def get_canvas_mermaid(self) -> str:
|
|
161
|
+
return self.canvas.to_mermaid()
|
|
162
|
+
|
|
163
|
+
def get_ref_content(self, node_id: str) -> Optional[str]:
|
|
164
|
+
return self._verbose_cache.get(node_id)
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|