mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-16 17:47:06 +08:00
6.0 KiB
6.0 KiB
CLAUDE Notes
- 2026-03-12: Legacy
handshakepayloads only containevent_type/handler_full_namemetadata and do not preserve v4 command/message trigger details such as command names, aliases, keywords, or regex. Any legacy-to-v4 handshake translation must approximate handlers as coarse event subscriptions and keep the raw handshake payload in metadata for lossless fallback. - 2026-03-12:
src/astrbot_sdk/tests/start_client.pyandbenchmark_8_plugins_resource_usage.pystill reference legacyastrbot_sdk.runtime.galaxy, butsrc-new/astrbot_sdk/runtime/galaxy.pyno longer exists. Treattests_v4/test_script_migrations.pyas the maintained replacement instead of reviving the old Galaxy path. - 2026-03-12: Legacy
src/astrbot_sdk/api/event/filter.pyexported a much larger decorator surface thansrc-new/astrbot_sdk/api/event/filter.py. Current compat coverage is enough forcommand/regex/permissionand the exercised migration tests, but it is not a full drop-in replacement for every historical filter helper. - 2026-03-13: Transport-pair startup tests for
SupervisorRuntimemust start a real peer on the opposite transport and provide aninitializeresponse. Wiring only the supervisor side drops or captures the outgoing initialize message without replying, andPeer.initialize()then waits forever. - 2026-03-13:
CapabilityRouter.register(..., stream_handler=...)uses the signature(request_id, payload, cancel_token), not the peer-level(message, token). Reusing the peer handler shape in router tests causes an immediate failed stream event before the test logic runs. - 2026-03-13:
Peerhad an early-cancel race for inbound invokes: ifCancelMessagearrived before the invoke task executed its first line, the task could be cancelled before sending any terminal event, leaving the caller's stream iterator waiting forever. Preserve a per-request start event and pre-check the cancel token at the top of_handle_invoke. - 2026-03-13:
src-new/astrbot_sdk/apiand several top-level module docstrings overstated v4 compatibility gaps by labeling migrated or compat-backed APIs as "missing". Treat_legacy_api.py,astrbot_sdk.api.*thin re-exports, and top-levelevents.py/decorators.pyas a split compatibility surface; do not mechanically recreate the old tree from stale TODO comments. - 2026-03-13: Legacy components are expected to share one
LegacyContextper plugin, matching the oldStarManagerbehavior. Creating one compat context per component breaks_register_component()/call_context_function()cross-component registration chains and diverges from legacy semantics. - 2026-03-13:
WorkerSessioncannot assume the caller-providedrepo_rootcontainssrc-new/astrbot_sdk. Tests and external bootstraps may pass a temporary repo root while still expecting the in-tree SDK package to launch worker subprocesses viapython -m astrbot_sdk. Resolve the SDK source directory from the real package location when the supplied root does not contain it. - 2026-03-13:
MemoryClient.get()is part of the supported v4 client surface and must stay in sync withCapabilityRouterbuilt-ins. The client method existed while the router forgot to registermemory.get, which caused a real runtime gap hidden by API shape alone. - 2026-03-13: When checking whether a peer has finished remote initialization, avoid
getattr(mock, "remote_peer")style probes in code that may receiveMagicMockpeers.MagicMockfabricates truthy child attributes, soCapabilityProxyshould read explicit state frompeer.__dict__or another concrete storage location instead of treating arbitrary attribute access as initialization. - 2026-03-13: The repository has no legacy
src/astrbot_sdk/protocolpackage to migrate file-for-file.src-new/astrbot_sdk/protocolis a v4-native protocol layer; compare it against legacy JSON-RPC behavior insrc/astrbot_sdk/runtime/*and the maintained migration tests, not against a nonexistent old package tree. - 2026-03-13:
load_plugin()must not blindlygetattr()every name fromdir(instance)during handler discovery. Real plugins may expose properties or descriptors with side effects or exceptions; inspect attributes statically first, and only bind names that actually carry handler metadata. - 2026-03-13: In
Peer, “remote initialized” and “transport still alive” are separate states. Waiting for initialization must fail when the connection closes first, and malformed inbound protocol messages should actively fail pending calls instead of leaving futures/streams hanging. - 2026-03-13: Several first-layer files under
src-new/astrbot_sdk/*.pycarried stale migration comparison blocks that claimed missing CLI help, missing compat APIs, or other gaps already covered by tests and current implementations. Treat those comments as historical noise; verify behavior against code and tests before "restoring" features from the comments. - 2026-03-13: The v4 design already defines built-in capability schema governance and reserved namespaces at the protocol layer. Keeping anonymous schema builders only inside
runtime/capability_router.pydrifts runtime behavior away from the protocol contract; centralize built-in schemas and namespace constants inprotocol/descriptors.py.
开发命令
格式化与检查
在提交代码前,请依次运行以下命令:
pyclean . # 清理 Python 缓存文件
ruff format . # 使用 ruff 格式化代码
ruff check . --fix # 使用 ruff 检查并自动修复问题
测试
如果修改了内容可能影响现有功能,请运行测试以确保没有引入错误: 如果修改了bug或者更改了功能需要添加新的测试
python run_tests.py # 运行所有测试
python run_tests.py -v # 详细输出
python run_tests.py -k "test_peer" # 运行匹配模式的测试
python run_tests.py --cov # 运行测试并生成覆盖率报告
重要
新实现要兼容旧实现但是还要保证架构良好,设计原则不变和最佳实践