feat: capability-based peer discovery (Wave 2)#53
feat: capability-based peer discovery (Wave 2)#53Jing-yilin wants to merge 2 commits intofeat/wave-1-batchfrom
Conversation
Jing-yilin
left a comment
There was a problem hiding this comment.
Codex Review
[Medium] The advertised --capability flag was added to the slash command, not the actual CLI
The PR description and examples call out openclaw p2p peers --capability ..., but the Commander CLI surface is still the separate p2p.command("peers") action. That code path was not updated with an .option("--capability <cap>"), so the real CLI will still reject the flag and its output still omits capabilities. The new filtering logic only exists on the api.registerCommand({ name: "p2p-peers" }) slash command.
Refs: src/index.ts:333, src/index.ts:347, src/index.ts:478
[Medium] Capability search can return peers that no longer advertise that capability
findPeersByCapability() assumes the stored capability list is current, but upsertDiscoveredPeer() only overwrites existing.capabilities when the incoming array is non-empty. If a peer first announces ["code:review"] and later announces [], the old capability is retained, so capability searches keep returning that peer indefinitely. I reproduced this locally against dist/peer-db.js after npm run build.
Refs: src/peer-db.ts:108, src/peer-db.ts:257
Reviewed by Codex
- peer-db: update capabilities on upsert even when array is empty (allows peers to withdraw capabilities) - index.ts: add --capability flag to Commander CLI p2p peers command (was only on registerCommand slash command) - test: add regression test for capability withdrawal via empty array
Wave 2 — Capability Search
Builds on top of #52 (Wave 1 batch).
Changes
src/peer-db.ts— newfindPeersByCapability(cap)findPeersByCapability('code:review')findPeersByCapability('code:')returns allcode:*capabilitieslastSeendescendingsrc/index.ts— capability filter on existing surfacesp2p_list_peersagent tool: new optionalcapabilityparameterp2p-peersCLI command: new--capability <cap>flagtest/agentid-peer-db.test.mjs— 4 new tests forfindPeersByCapabilityTest results
120/120 tests pass (116 from Wave 1 + 4 new)
Usage examples