-
Notifications
You must be signed in to change notification settings - Fork 14k
feat: enable Remote Control (BRIDGE_MODE) with stub completions #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
claude-code-best
merged 5 commits into
claude-code-best:main
from
amDosion:feat/rc-clean
Apr 3, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
74e51e7
feat: enable Remote Control (BRIDGE_MODE) with stub completions
1d38eae
fix: address CodeRabbit review findings
8645d37
fix: add Authorization header to peer message requests
e784f23
fix: validate and encode target sessionId in peer messages
67caa5d
docs: add Remote Control (BRIDGE_MODE) entry to DEV-LOG
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,84 @@ | ||
| // Auto-generated stub — replace with real implementation | ||
| export {}; | ||
| export const postInterClaudeMessage: (target: string, message: string) => Promise<{ ok: boolean; error?: string }> = () => Promise.resolve({ ok: false }); | ||
| import axios from 'axios' | ||
| import { logForDebugging } from '../utils/debug.js' | ||
| import { errorMessage } from '../utils/errors.js' | ||
| import { validateBridgeId } from './bridgeApi.js' | ||
| import { getBridgeAccessToken } from './bridgeConfig.js' | ||
| import { getReplBridgeHandle } from './replBridgeHandle.js' | ||
| import { toCompatSessionId } from './sessionIdCompat.js' | ||
|
|
||
| /** | ||
| * Send a plain-text message to another Claude session via the bridge API. | ||
| * | ||
| * Called by SendMessageTool when the target address scheme is "bridge:". | ||
| * Uses the current ReplBridgeHandle to derive the sender identity and | ||
| * the session ingress URL for the POST request. | ||
| * | ||
| * @param target - Target session ID (from the "bridge:<sessionId>" address) | ||
| * @param message - Plain text message content (structured messages are rejected upstream) | ||
| * @returns { ok: true } on success, { ok: false, error } on failure. Never throws. | ||
| */ | ||
| export async function postInterClaudeMessage( | ||
| target: string, | ||
| message: string, | ||
| ): Promise<{ ok: true } | { ok: false; error: string }> { | ||
| try { | ||
| const handle = getReplBridgeHandle() | ||
| if (!handle) { | ||
| return { ok: false, error: 'Bridge not connected' } | ||
| } | ||
|
|
||
| const normalizedTarget = target.trim() | ||
| if (!normalizedTarget) { | ||
| return { ok: false, error: 'No target session specified' } | ||
| } | ||
|
|
||
| const accessToken = getBridgeAccessToken() | ||
| if (!accessToken) { | ||
| return { ok: false, error: 'No access token available' } | ||
| } | ||
|
|
||
| const compatTarget = toCompatSessionId(normalizedTarget) | ||
| // Validate against path traversal — same allowlist as bridgeApi.ts | ||
| validateBridgeId(compatTarget, 'target sessionId') | ||
| const from = toCompatSessionId(handle.bridgeSessionId) | ||
| const baseUrl = handle.sessionIngressUrl | ||
|
|
||
| const url = `${baseUrl}/v1/sessions/${encodeURIComponent(compatTarget)}/messages` | ||
|
|
||
| const response = await axios.post( | ||
| url, | ||
| { | ||
| type: 'peer_message', | ||
| from, | ||
| content: message, | ||
| }, | ||
| { | ||
| headers: { | ||
| Authorization: `Bearer ${accessToken}`, | ||
| 'Content-Type': 'application/json', | ||
| 'anthropic-version': '2023-06-01', | ||
| }, | ||
| timeout: 10_000, | ||
| validateStatus: (s: number) => s < 500, | ||
| }, | ||
| ) | ||
|
|
||
| if (response.status === 200 || response.status === 204) { | ||
| logForDebugging( | ||
| `[bridge:peer] Message sent to ${compatTarget} (${response.status})`, | ||
| ) | ||
| return { ok: true } | ||
| } | ||
|
|
||
| const detail = | ||
| typeof response.data === 'object' && response.data?.error?.message | ||
| ? response.data.error.message | ||
| : `HTTP ${response.status}` | ||
| logForDebugging(`[bridge:peer] Send failed: ${detail}`) | ||
| return { ok: false, error: detail } | ||
| } catch (err: unknown) { | ||
| const msg = errorMessage(err) | ||
| logForDebugging(`[bridge:peer] postInterClaudeMessage error: ${msg}`) | ||
| return { ok: false, error: msg } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,57 @@ | ||
| // Auto-generated stub — replace with real implementation | ||
| export {}; | ||
| export const sanitizeInboundWebhookContent: (content: string) => string = (content) => content; | ||
| /** | ||
| * Sanitize inbound GitHub webhook payload content before it enters the session. | ||
| * | ||
| * Called from useReplBridge.tsx when feature('KAIROS_GITHUB_WEBHOOKS') is enabled. | ||
| * Strips known secret patterns (tokens, API keys, credentials) while preserving | ||
| * the meaningful content (PR titles, descriptions, commit messages, etc.). | ||
| * | ||
| * Must be synchronous and never throw — on error, returns a safe placeholder. | ||
| */ | ||
|
|
||
| /** Patterns that match known secret/token formats. */ | ||
| const SECRET_PATTERNS: Array<{ pattern: RegExp; replacement: string }> = [ | ||
| // GitHub tokens (PAT, OAuth, App, Server-to-server) | ||
| { pattern: /\b(ghp|gho|ghs|ghu|github_pat)_[A-Za-z0-9_]{10,}\b/g, replacement: '[REDACTED_GITHUB_TOKEN]' }, | ||
| // Anthropic API keys | ||
| { pattern: /\bsk-ant-[A-Za-z0-9_-]{10,}\b/g, replacement: '[REDACTED_ANTHROPIC_KEY]' }, | ||
| // Generic Bearer tokens in headers | ||
| { pattern: /(Bearer\s+)[A-Za-z0-9._\-/+=]{20,}/gi, replacement: '$1[REDACTED_TOKEN]' }, | ||
| // AWS access keys | ||
| { pattern: /\b(AKIA|ASIA)[A-Z0-9]{16}\b/g, replacement: '[REDACTED_AWS_KEY]' }, | ||
| // AWS secret keys (40-char base64-like strings after common labels) | ||
| { pattern: /(aws_secret_access_key|secret_key|SecretAccessKey)['":\s=]+[A-Za-z0-9/+=]{30,}/gi, replacement: '$1=[REDACTED_AWS_SECRET]' }, | ||
| // Generic API key patterns (key=value or "key": "value") | ||
| { pattern: /(api[_-]?key|apikey|secret|password|token|credential)['":\s=]+["']?[A-Za-z0-9._\-/+=]{16,}["']?/gi, replacement: '$1=[REDACTED]' }, | ||
| // npm tokens | ||
| { pattern: /\bnpm_[A-Za-z0-9]{36}\b/g, replacement: '[REDACTED_NPM_TOKEN]' }, | ||
| // Slack tokens | ||
| { pattern: /\bxox[bporas]-[A-Za-z0-9-]{10,}\b/g, replacement: '[REDACTED_SLACK_TOKEN]' }, | ||
| ] | ||
|
|
||
| /** Maximum content length before truncation (100KB). */ | ||
| const MAX_CONTENT_LENGTH = 100_000 | ||
|
|
||
| export function sanitizeInboundWebhookContent(content: string): string { | ||
| try { | ||
| if (!content) return content | ||
|
|
||
| let sanitized = content | ||
|
|
||
| // Redact known secret patterns first (before truncation to avoid | ||
| // splitting a secret across the truncation boundary) | ||
| for (const { pattern, replacement } of SECRET_PATTERNS) { | ||
| pattern.lastIndex = 0 | ||
| sanitized = sanitized.replace(pattern, replacement) | ||
| } | ||
|
|
||
| // Truncate excessively large payloads after redaction | ||
| if (sanitized.length > MAX_CONTENT_LENGTH) { | ||
| sanitized = sanitized.slice(0, MAX_CONTENT_LENGTH) + '\n... [truncated]' | ||
| } | ||
|
|
||
| return sanitized | ||
| } catch { | ||
| // Never throw, never return raw content — return a safe placeholder | ||
| return '[webhook content redacted due to sanitization error]' | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,34 @@ | ||
| /** | ||
| * Stub: SDK Control Types (not yet published in open-source). | ||
| * Used by bridge/transport layer for the control protocol. | ||
| * SDK Control Types — inferred from Zod schemas in controlSchemas.ts / coreSchemas.ts. | ||
| * | ||
| * These types define the control protocol between the CLI bridge and the server. | ||
| * Used by bridge/transport layer, remote session manager, and CLI print/IO paths. | ||
| */ | ||
| export type SDKControlRequest = { type: string; [key: string]: unknown } | ||
| export type SDKControlResponse = { type: string; [key: string]: unknown } | ||
| export type StdoutMessage = any; | ||
| export type SDKControlInitializeRequest = any; | ||
| export type SDKControlInitializeResponse = any; | ||
| export type SDKControlMcpSetServersResponse = any; | ||
| export type SDKControlReloadPluginsResponse = any; | ||
| export type StdinMessage = any; | ||
| export type SDKPartialAssistantMessage = any; | ||
| export type SDKControlPermissionRequest = any; | ||
| export type SDKControlCancelRequest = any; | ||
| export type SDKControlRequestInner = any; | ||
| import type { z } from 'zod' | ||
| import type { | ||
| SDKControlRequestSchema, | ||
| SDKControlResponseSchema, | ||
| SDKControlInitializeRequestSchema, | ||
| SDKControlInitializeResponseSchema, | ||
| SDKControlMcpSetServersResponseSchema, | ||
| SDKControlReloadPluginsResponseSchema, | ||
| SDKControlPermissionRequestSchema, | ||
| SDKControlCancelRequestSchema, | ||
| SDKControlRequestInnerSchema, | ||
| StdoutMessageSchema, | ||
| StdinMessageSchema, | ||
| } from './controlSchemas.js' | ||
| import type { SDKPartialAssistantMessageSchema } from './coreSchemas.js' | ||
|
|
||
| export type SDKControlRequest = z.infer<ReturnType<typeof SDKControlRequestSchema>> | ||
| export type SDKControlResponse = z.infer<ReturnType<typeof SDKControlResponseSchema>> | ||
| export type StdoutMessage = z.infer<ReturnType<typeof StdoutMessageSchema>> | ||
| export type SDKControlInitializeRequest = z.infer<ReturnType<typeof SDKControlInitializeRequestSchema>> | ||
| export type SDKControlInitializeResponse = z.infer<ReturnType<typeof SDKControlInitializeResponseSchema>> | ||
| export type SDKControlMcpSetServersResponse = z.infer<ReturnType<typeof SDKControlMcpSetServersResponseSchema>> | ||
| export type SDKControlReloadPluginsResponse = z.infer<ReturnType<typeof SDKControlReloadPluginsResponseSchema>> | ||
| export type StdinMessage = z.infer<ReturnType<typeof StdinMessageSchema>> | ||
| export type SDKPartialAssistantMessage = z.infer<ReturnType<typeof SDKPartialAssistantMessageSchema>> | ||
| export type SDKControlPermissionRequest = z.infer<ReturnType<typeof SDKControlPermissionRequestSchema>> | ||
| export type SDKControlCancelRequest = z.infer<ReturnType<typeof SDKControlCancelRequestSchema>> | ||
| export type SDKControlRequestInner = z.infer<ReturnType<typeof SDKControlRequestInnerSchema>> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: claude-code-best/claude-code
Length of output: 839
Add the missing screenshot or remove the broken image reference.
The documentation at line 33 references
docs/images/remote-control-mobile.png, but this file does not exist in the repository. Either add the screenshot todocs/images/as requested in the original review ("测试的截图"), or remove the broken image reference from the documentation.🤖 Prompt for AI Agents