mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-21 15:55:50 +00:00
style(B1-3): 格式化 components/messages,permissions,mcp,sandbox,shell (104 files)
纯格式化:移除分号、React Compiler import、import 多行展开。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,149 +1,158 @@
|
||||
import { c as _c } from "react/compiler-runtime";
|
||||
import * as React from 'react';
|
||||
import { Markdown } from '../../components/Markdown.js';
|
||||
import { Box, Text } from '../../ink.js';
|
||||
import { jsonParse } from '../../utils/slowOperations.js';
|
||||
import { type IdleNotificationMessage, isIdleNotification, isPlanApprovalRequest, isPlanApprovalResponse, type PlanApprovalRequestMessage, type PlanApprovalResponseMessage } from '../../utils/teammateMailbox.js';
|
||||
import { getShutdownMessageSummary } from './ShutdownMessage.js';
|
||||
import { getTaskAssignmentSummary } from './TaskAssignmentMessage.js';
|
||||
import * as React from 'react'
|
||||
import { Markdown } from '../../components/Markdown.js'
|
||||
import { Box, Text } from '../../ink.js'
|
||||
import { jsonParse } from '../../utils/slowOperations.js'
|
||||
import {
|
||||
type IdleNotificationMessage,
|
||||
isIdleNotification,
|
||||
isPlanApprovalRequest,
|
||||
isPlanApprovalResponse,
|
||||
type PlanApprovalRequestMessage,
|
||||
type PlanApprovalResponseMessage,
|
||||
} from '../../utils/teammateMailbox.js'
|
||||
import { getShutdownMessageSummary } from './ShutdownMessage.js'
|
||||
import { getTaskAssignmentSummary } from './TaskAssignmentMessage.js'
|
||||
|
||||
type PlanApprovalRequestProps = {
|
||||
request: PlanApprovalRequestMessage;
|
||||
};
|
||||
request: PlanApprovalRequestMessage
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a plan approval request with a planMode-colored border,
|
||||
* showing the plan content and instructions for approving/rejecting.
|
||||
*/
|
||||
export function PlanApprovalRequestDisplay(t0) {
|
||||
const $ = _c(10);
|
||||
const {
|
||||
request
|
||||
} = t0;
|
||||
let t1;
|
||||
if ($[0] !== request.from) {
|
||||
t1 = <Box marginBottom={1}><Text color="planMode" bold={true}>Plan Approval Request from {request.from}</Text></Box>;
|
||||
$[0] = request.from;
|
||||
$[1] = t1;
|
||||
} else {
|
||||
t1 = $[1];
|
||||
}
|
||||
let t2;
|
||||
if ($[2] !== request.planContent) {
|
||||
t2 = <Box borderStyle="dashed" borderColor="subtle" borderLeft={false} borderRight={false} flexDirection="column" paddingX={1} marginBottom={1}><Markdown>{request.planContent}</Markdown></Box>;
|
||||
$[2] = request.planContent;
|
||||
$[3] = t2;
|
||||
} else {
|
||||
t2 = $[3];
|
||||
}
|
||||
let t3;
|
||||
if ($[4] !== request.planFilePath) {
|
||||
t3 = <Text dimColor={true}>Plan file: {request.planFilePath}</Text>;
|
||||
$[4] = request.planFilePath;
|
||||
$[5] = t3;
|
||||
} else {
|
||||
t3 = $[5];
|
||||
}
|
||||
let t4;
|
||||
if ($[6] !== t1 || $[7] !== t2 || $[8] !== t3) {
|
||||
t4 = <Box flexDirection="column" marginY={1}><Box borderStyle="round" borderColor="planMode" flexDirection="column" paddingX={1}>{t1}{t2}{t3}</Box></Box>;
|
||||
$[6] = t1;
|
||||
$[7] = t2;
|
||||
$[8] = t3;
|
||||
$[9] = t4;
|
||||
} else {
|
||||
t4 = $[9];
|
||||
}
|
||||
return t4;
|
||||
export function PlanApprovalRequestDisplay({
|
||||
request,
|
||||
}: PlanApprovalRequestProps): React.ReactNode {
|
||||
return (
|
||||
<Box flexDirection="column" marginY={1}>
|
||||
<Box
|
||||
borderStyle="round"
|
||||
borderColor="planMode"
|
||||
flexDirection="column"
|
||||
paddingX={1}
|
||||
>
|
||||
<Box marginBottom={1}>
|
||||
<Text color="planMode" bold>
|
||||
Plan Approval Request from {request.from}
|
||||
</Text>
|
||||
</Box>
|
||||
<Box
|
||||
borderStyle="dashed"
|
||||
borderColor="subtle"
|
||||
borderLeft={false}
|
||||
borderRight={false}
|
||||
flexDirection="column"
|
||||
paddingX={1}
|
||||
marginBottom={1}
|
||||
>
|
||||
<Markdown>{request.planContent}</Markdown>
|
||||
</Box>
|
||||
<Text dimColor>Plan file: {request.planFilePath}</Text>
|
||||
</Box>
|
||||
</Box>
|
||||
)
|
||||
}
|
||||
|
||||
type PlanApprovalResponseProps = {
|
||||
response: PlanApprovalResponseMessage;
|
||||
senderName: string;
|
||||
};
|
||||
response: PlanApprovalResponseMessage
|
||||
senderName: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a plan approval response with a success (green) or error (red) border.
|
||||
*/
|
||||
export function PlanApprovalResponseDisplay(t0) {
|
||||
const $ = _c(13);
|
||||
const {
|
||||
response,
|
||||
senderName
|
||||
} = t0;
|
||||
export function PlanApprovalResponseDisplay({
|
||||
response,
|
||||
senderName,
|
||||
}: PlanApprovalResponseProps): React.ReactNode {
|
||||
if (response.approved) {
|
||||
let t1;
|
||||
if ($[0] !== senderName) {
|
||||
t1 = <Box><Text color="success" bold={true}>✓ Plan Approved by {senderName}</Text></Box>;
|
||||
$[0] = senderName;
|
||||
$[1] = t1;
|
||||
} else {
|
||||
t1 = $[1];
|
||||
}
|
||||
let t2;
|
||||
if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
|
||||
t2 = <Box marginTop={1}><Text>You can now proceed with implementation. Your plan mode restrictions have been lifted.</Text></Box>;
|
||||
$[2] = t2;
|
||||
} else {
|
||||
t2 = $[2];
|
||||
}
|
||||
let t3;
|
||||
if ($[3] !== t1) {
|
||||
t3 = <Box flexDirection="column" marginY={1}><Box borderStyle="round" borderColor="success" flexDirection="column" paddingX={1} paddingY={1}>{t1}{t2}</Box></Box>;
|
||||
$[3] = t1;
|
||||
$[4] = t3;
|
||||
} else {
|
||||
t3 = $[4];
|
||||
}
|
||||
return t3;
|
||||
return (
|
||||
<Box flexDirection="column" marginY={1}>
|
||||
<Box
|
||||
borderStyle="round"
|
||||
borderColor="success"
|
||||
flexDirection="column"
|
||||
paddingX={1}
|
||||
paddingY={1}
|
||||
>
|
||||
<Box>
|
||||
<Text color="success" bold>
|
||||
✓ Plan Approved by {senderName}
|
||||
</Text>
|
||||
</Box>
|
||||
<Box marginTop={1}>
|
||||
<Text>
|
||||
You can now proceed with implementation. Your plan mode
|
||||
restrictions have been lifted.
|
||||
</Text>
|
||||
</Box>
|
||||
</Box>
|
||||
</Box>
|
||||
)
|
||||
}
|
||||
let t1;
|
||||
if ($[5] !== senderName) {
|
||||
t1 = <Box><Text color="error" bold={true}>✗ Plan Rejected by {senderName}</Text></Box>;
|
||||
$[5] = senderName;
|
||||
$[6] = t1;
|
||||
} else {
|
||||
t1 = $[6];
|
||||
}
|
||||
let t2;
|
||||
if ($[7] !== response.feedback) {
|
||||
t2 = response.feedback && <Box marginTop={1} borderStyle="dashed" borderColor="subtle" borderLeft={false} borderRight={false} paddingX={1}><Text>Feedback: {response.feedback}</Text></Box>;
|
||||
$[7] = response.feedback;
|
||||
$[8] = t2;
|
||||
} else {
|
||||
t2 = $[8];
|
||||
}
|
||||
let t3;
|
||||
if ($[9] === Symbol.for("react.memo_cache_sentinel")) {
|
||||
t3 = <Box marginTop={1}><Text dimColor={true}>Please revise your plan based on the feedback and call ExitPlanMode again.</Text></Box>;
|
||||
$[9] = t3;
|
||||
} else {
|
||||
t3 = $[9];
|
||||
}
|
||||
let t4;
|
||||
if ($[10] !== t1 || $[11] !== t2) {
|
||||
t4 = <Box flexDirection="column" marginY={1}><Box borderStyle="round" borderColor="error" flexDirection="column" paddingX={1} paddingY={1}>{t1}{t2}{t3}</Box></Box>;
|
||||
$[10] = t1;
|
||||
$[11] = t2;
|
||||
$[12] = t4;
|
||||
} else {
|
||||
t4 = $[12];
|
||||
}
|
||||
return t4;
|
||||
|
||||
return (
|
||||
<Box flexDirection="column" marginY={1}>
|
||||
<Box
|
||||
borderStyle="round"
|
||||
borderColor="error"
|
||||
flexDirection="column"
|
||||
paddingX={1}
|
||||
paddingY={1}
|
||||
>
|
||||
<Box>
|
||||
<Text color="error" bold>
|
||||
✗ Plan Rejected by {senderName}
|
||||
</Text>
|
||||
</Box>
|
||||
{response.feedback && (
|
||||
<Box
|
||||
marginTop={1}
|
||||
borderStyle="dashed"
|
||||
borderColor="subtle"
|
||||
borderLeft={false}
|
||||
borderRight={false}
|
||||
paddingX={1}
|
||||
>
|
||||
<Text>Feedback: {response.feedback}</Text>
|
||||
</Box>
|
||||
)}
|
||||
<Box marginTop={1}>
|
||||
<Text dimColor>
|
||||
Please revise your plan based on the feedback and call ExitPlanMode
|
||||
again.
|
||||
</Text>
|
||||
</Box>
|
||||
</Box>
|
||||
</Box>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to parse and render a plan approval message from raw content.
|
||||
* Returns the rendered component if it's a plan approval message, null otherwise.
|
||||
*/
|
||||
export function tryRenderPlanApprovalMessage(content: string, senderName: string): React.ReactNode | null {
|
||||
const request = isPlanApprovalRequest(content);
|
||||
export function tryRenderPlanApprovalMessage(
|
||||
content: string,
|
||||
senderName: string,
|
||||
): React.ReactNode | null {
|
||||
const request = isPlanApprovalRequest(content)
|
||||
if (request) {
|
||||
return <PlanApprovalRequestDisplay request={request} />;
|
||||
return <PlanApprovalRequestDisplay request={request} />
|
||||
}
|
||||
const response = isPlanApprovalResponse(content);
|
||||
|
||||
const response = isPlanApprovalResponse(content)
|
||||
if (response) {
|
||||
return <PlanApprovalResponseDisplay response={response} senderName={senderName} />;
|
||||
return (
|
||||
<PlanApprovalResponseDisplay
|
||||
response={response}
|
||||
senderName={senderName}
|
||||
/>
|
||||
)
|
||||
}
|
||||
return null;
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -152,34 +161,36 @@ export function tryRenderPlanApprovalMessage(content: string, senderName: string
|
||||
* Returns null if the content is not a plan approval message.
|
||||
*/
|
||||
function getPlanApprovalSummary(content: string): string | null {
|
||||
const request = isPlanApprovalRequest(content);
|
||||
const request = isPlanApprovalRequest(content)
|
||||
if (request) {
|
||||
return `[Plan Approval Request from ${request.from}]`;
|
||||
return `[Plan Approval Request from ${request.from}]`
|
||||
}
|
||||
const response = isPlanApprovalResponse(content);
|
||||
|
||||
const response = isPlanApprovalResponse(content)
|
||||
if (response) {
|
||||
if (response.approved) {
|
||||
return '[Plan Approved] You can now proceed with implementation';
|
||||
return '[Plan Approved] You can now proceed with implementation'
|
||||
} else {
|
||||
return `[Plan Rejected] ${response.feedback || 'Please revise your plan'}`;
|
||||
return `[Plan Rejected] ${response.feedback || 'Please revise your plan'}`
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a brief summary text for an idle notification.
|
||||
*/
|
||||
function getIdleNotificationSummary(msg: IdleNotificationMessage): string {
|
||||
const parts: string[] = ['Agent idle'];
|
||||
const parts: string[] = ['Agent idle']
|
||||
if (msg.completedTaskId) {
|
||||
const status = msg.completedStatus || 'completed';
|
||||
parts.push(`Task ${msg.completedTaskId} ${status}`);
|
||||
const status = msg.completedStatus || 'completed'
|
||||
parts.push(`Task ${msg.completedTaskId} ${status}`)
|
||||
}
|
||||
if (msg.summary) {
|
||||
parts.push(`Last DM: ${msg.summary}`);
|
||||
parts.push(`Last DM: ${msg.summary}`)
|
||||
}
|
||||
return parts.join(' · ');
|
||||
return parts.join(' · ')
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -188,34 +199,35 @@ function getIdleNotificationSummary(msg: IdleNotificationMessage): string {
|
||||
* Otherwise returns the original content.
|
||||
*/
|
||||
export function formatTeammateMessageContent(content: string): string {
|
||||
const planSummary = getPlanApprovalSummary(content);
|
||||
const planSummary = getPlanApprovalSummary(content)
|
||||
if (planSummary) {
|
||||
return planSummary;
|
||||
return planSummary
|
||||
}
|
||||
const shutdownSummary = getShutdownMessageSummary(content);
|
||||
|
||||
const shutdownSummary = getShutdownMessageSummary(content)
|
||||
if (shutdownSummary) {
|
||||
return shutdownSummary;
|
||||
return shutdownSummary
|
||||
}
|
||||
const idleMsg = isIdleNotification(content);
|
||||
|
||||
const idleMsg = isIdleNotification(content)
|
||||
if (idleMsg) {
|
||||
return getIdleNotificationSummary(idleMsg);
|
||||
return getIdleNotificationSummary(idleMsg)
|
||||
}
|
||||
const taskAssignmentSummary = getTaskAssignmentSummary(content);
|
||||
|
||||
const taskAssignmentSummary = getTaskAssignmentSummary(content)
|
||||
if (taskAssignmentSummary) {
|
||||
return taskAssignmentSummary;
|
||||
return taskAssignmentSummary
|
||||
}
|
||||
|
||||
// Check for teammate_terminated message
|
||||
try {
|
||||
const parsed = jsonParse(content) as {
|
||||
type?: string;
|
||||
message?: string;
|
||||
};
|
||||
const parsed = jsonParse(content) as { type?: string; message?: string }
|
||||
if (parsed?.type === 'teammate_terminated' && parsed.message) {
|
||||
return parsed.message;
|
||||
return parsed.message
|
||||
}
|
||||
} catch {
|
||||
// Not JSON
|
||||
}
|
||||
return content;
|
||||
|
||||
return content
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user