mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-22 16:25:51 +00:00
* fix: bound agent communication memory growth UDS messaging now uses private local capabilities instead of exposing auth tokens through SDK metadata, environment variables, session registry, peer listing, or tool output. The receive path bounds NDJSON frames, response buffers, active clients, and pending inbox bytes, and strips auth metadata before messages enter the prompt queue. Teammate mailboxes now validate file and message sizes, fail closed on corrupt mutation inputs, compact by count and retained bytes, and use stable message identity for in-process acknowledgements. Agent summaries now fork only a bounded recent context using lazy size estimation and content fingerprints instead of retaining or serializing unbounded histories. Constraint: PR #361 was already merged; this branch is based on upstream/main@c2ac9a74. Rejected: Default-disabling COORDINATOR_MODE/TEAMMEM only | explicit feature enablement still hit unbounded paths. Rejected: Persisting UDS auth in SDK/env/session registry | bridge/remote metadata can leak local capability secrets. Rejected: Inline uds #token addresses | observable/tool/classifier paths can reflect raw addresses outside the UDS request frame. Rejected: Positional mailbox marking after compaction | compaction can shift indices across the lock boundary. Confidence: high Scope-risk: moderate Directive: Do not expose UDS capability tokens through SDK messages, environment variables, session registry, peer-list output, or SendMessage result/classifier surfaces. Directive: Do not reintroduce positional mailbox acknowledgements unless compaction is removed or read+mark is atomic under one lock. Tested: bun test src/utils/__tests__/ndjsonFramer.test.ts src/utils/__tests__/udsMessaging.test.ts packages/builtin-tools/src/tools/SendMessageTool/__tests__/udsRecipientSanitization.test.ts Tested: bunx tsc --noEmit --pretty false Tested: bun run lint Tested: bunx biome lint modified src/package files Tested: bun run test:all (3704 pass, 0 fail, 6734 expects) Tested: bun audit (No vulnerabilities found) Tested: bun run build Tested: bun run build:vite Tested: git diff --check Not-tested: End-to-end external UDS client driving a full production headless model turn. * fix: harden bounded agent communication review fixes CodeRabbit and Codecov surfaced real gaps in UDS framing, peer discovery, mailbox retention, and summary context coverage. This tightens those paths without suppressing review or coverage signals. Constraint: PR #369 must address CodeRabbit and Codecov findings without warning suppression or fake fallbacks Rejected: Suppress Codecov or CodeRabbit warnings | leaves real receive-path and test-isolation gaps Rejected: Add unreachable feature-gated tests | bun:bundle keeps those branches compile-time gated in local tests Confidence: high Scope-risk: moderate Directive: Keep UDS auth-token rejection outside feature flags; do not reintroduce inline token fallbacks Tested: bun test --coverage --coverage-reporter lcov --coverage-dir coverage; bun run test:all; bun run lint; bun run build; bun run build:vite; bun audit; git diff --cached --check Not-tested: Remote Codecov/CodeRabbit refreshed reports until pushed * fix: prevent agent communication bounds from hiding CI regressions Tighten the UDS auth, framing, and response-reader boundaries while keeping the AgentSummary lifecycle covered so Codecov and CI fail on real regressions instead of missing coverage. The poorMode settings mock mirrors unrelated real settings defaults to avoid Bun mock retention changing later permission tests. Constraint: PR #369 must fix Codecov/CI precisely without warning suppression, fallback masking, or mock pollution Rejected: Delete AgentSummary lifecycle coverage | would hide Codecov loss and stale-summary behavior Rejected: Store inline UDS rejection in a hidden input sentinel | cloned observable inputs can drop it and bypass rejection Rejected: Ignore malformed UDS frames until timeout | leaves client slots and SendMessage calls open to exhaustion Confidence: high Scope-risk: moderate Directive: Keep empty #token= markers rejected; do not require a non-empty token value in hasInlineUdsToken Tested: bun test packages/builtin-tools/src/tools/SendMessageTool/__tests__/udsRecipientSanitization.test.ts src/utils/__tests__/udsMessaging.test.ts src/utils/__tests__/udsResponseReader.test.ts src/utils/__tests__/ndjsonFramer.test.ts Tested: bunx tsc --noEmit --pretty false Tested: bun run lint Tested: bun test --coverage --coverage-reporter lcov --coverage-dir coverage Tested: bun run test:all Tested: bun audit Tested: bun run build Tested: bun run build:vite Not-tested: GitHub-hosted Codecov upload until pushed PR checks rerun --------- Co-authored-by: unraid <local@unraid.local>
134 lines
3.8 KiB
TypeScript
134 lines
3.8 KiB
TypeScript
import { z } from 'zod/v4'
|
|
import type { ToolResultBlockParam } from 'src/Tool.js'
|
|
import { buildTool } from 'src/Tool.js'
|
|
import { lazySchema } from 'src/utils/lazySchema.js'
|
|
|
|
const LIST_PEERS_TOOL_NAME = 'ListPeers'
|
|
|
|
const inputSchema = lazySchema(() =>
|
|
z.strictObject({
|
|
include_self: z
|
|
.boolean()
|
|
.optional()
|
|
.describe('Whether to include the current session in the list. Defaults to false.'),
|
|
}),
|
|
)
|
|
type InputSchema = ReturnType<typeof inputSchema>
|
|
type ListPeersInput = z.infer<InputSchema>
|
|
|
|
type PeerInfo = {
|
|
address: string
|
|
name?: string
|
|
cwd?: string
|
|
pid?: number
|
|
}
|
|
type ListPeersOutput = { peers: PeerInfo[] }
|
|
|
|
export const ListPeersTool = buildTool({
|
|
name: LIST_PEERS_TOOL_NAME,
|
|
searchHint: 'list peers sessions discover uds socket messaging',
|
|
maxResultSizeChars: 50_000,
|
|
strict: true,
|
|
|
|
get inputSchema(): InputSchema {
|
|
return inputSchema()
|
|
},
|
|
|
|
async description() {
|
|
return 'Discover other Claude Code sessions for cross-session messaging'
|
|
},
|
|
async prompt() {
|
|
return `List active Claude Code sessions that can receive messages via SendMessage.
|
|
|
|
Returns an array of peers with their addresses. Use these addresses as the \`to\` field in SendMessage:
|
|
- \`"uds:/path/to.sock"\` — local sessions on the same machine (Unix Domain Socket)
|
|
- \`"bridge:session_..."\` — remote sessions via Remote Control
|
|
|
|
Use this tool to discover messaging targets before sending cross-session messages. Only running sessions with active messaging sockets are returned.`
|
|
},
|
|
|
|
isConcurrencySafe() {
|
|
return true
|
|
},
|
|
isReadOnly() {
|
|
return true
|
|
},
|
|
|
|
userFacingName() {
|
|
return LIST_PEERS_TOOL_NAME
|
|
},
|
|
|
|
renderToolUseMessage() {
|
|
return 'ListPeers'
|
|
},
|
|
|
|
mapToolResultToToolResultBlockParam(
|
|
content: ListPeersOutput,
|
|
toolUseID: string,
|
|
): ToolResultBlockParam {
|
|
const lines = content.peers.map(
|
|
p => `${p.address}${p.name ? ` (${p.name})` : ''}${p.cwd ? ` @ ${p.cwd}` : ''}`,
|
|
)
|
|
return {
|
|
tool_use_id: toolUseID,
|
|
type: 'tool_result',
|
|
content:
|
|
lines.length > 0
|
|
? `Found ${lines.length} peer(s):\n${lines.join('\n')}`
|
|
: 'No peers found.',
|
|
}
|
|
},
|
|
|
|
async call(_input: ListPeersInput, context) {
|
|
// Peer discovery uses the concurrent sessions PID registry and
|
|
// UDS socket directory. The implementation scans for live sockets
|
|
// and optionally includes Remote Control bridge peers.
|
|
const peers: PeerInfo[] = []
|
|
const seen = new Set<string>()
|
|
const addPeer = (peer: PeerInfo): void => {
|
|
if (seen.has(peer.address)) return
|
|
seen.add(peer.address)
|
|
peers.push(peer)
|
|
}
|
|
|
|
/* eslint-disable @typescript-eslint/no-require-imports */
|
|
const udsMessaging =
|
|
require('src/utils/udsMessaging.js') as typeof import('src/utils/udsMessaging.js')
|
|
const udsClient =
|
|
require('src/utils/udsClient.js') as typeof import('src/utils/udsClient.js')
|
|
const bridgePeers =
|
|
require('src/bridge/peerSessions.js') as typeof import('src/bridge/peerSessions.js')
|
|
/* eslint-enable @typescript-eslint/no-require-imports */
|
|
|
|
const messagingSocketPath = udsMessaging.getUdsMessagingSocketPath()
|
|
if (messagingSocketPath) {
|
|
// Self entry for reference
|
|
if (_input.include_self) {
|
|
addPeer({
|
|
address: udsMessaging.formatUdsAddress(messagingSocketPath),
|
|
name: 'self',
|
|
pid: process.pid,
|
|
})
|
|
}
|
|
}
|
|
|
|
for (const peer of await udsClient.listPeers()) {
|
|
if (!peer.messagingSocketPath) continue
|
|
addPeer({
|
|
address: udsMessaging.formatUdsAddress(peer.messagingSocketPath),
|
|
name: peer.name ?? peer.kind,
|
|
cwd: peer.cwd,
|
|
pid: peer.pid,
|
|
})
|
|
}
|
|
|
|
for (const peer of await bridgePeers.listBridgePeers()) {
|
|
addPeer(peer)
|
|
}
|
|
|
|
return {
|
|
data: { peers },
|
|
}
|
|
},
|
|
})
|