style: 完成所有文件的lint

This commit is contained in:
claude-code-best
2026-05-01 21:39:30 +08:00
parent d136872cc9
commit 6182015005
1333 changed files with 68255 additions and 77882 deletions

View File

@@ -1,28 +1,24 @@
import type { ContentBlockParam } from '@anthropic-ai/sdk/resources'
import { randomUUID } from 'crypto'
import * as React from 'react'
import { BashModeProgress } from 'src/components/BashModeProgress.js'
import type { SetToolJSXFn } from 'src/Tool.js'
import { BashTool } from '@claude-code-best/builtin-tools/tools/BashTool/BashTool.js'
import type {
AttachmentMessage,
SystemMessage,
UserMessage,
} from 'src/types/message.js'
import type { ShellProgress } from 'src/types/tools.js'
import { logEvent } from '../../services/analytics/index.js'
import { errorMessage, ShellError } from '../errors.js'
import type { ContentBlockParam } from '@anthropic-ai/sdk/resources';
import { randomUUID } from 'crypto';
import * as React from 'react';
import { BashModeProgress } from 'src/components/BashModeProgress.js';
import type { SetToolJSXFn } from 'src/Tool.js';
import { BashTool } from '@claude-code-best/builtin-tools/tools/BashTool/BashTool.js';
import type { AttachmentMessage, SystemMessage, UserMessage } from 'src/types/message.js';
import type { ShellProgress } from 'src/types/tools.js';
import { logEvent } from '../../services/analytics/index.js';
import { errorMessage, ShellError } from '../errors.js';
import {
createSyntheticUserCaveatMessage,
createUserInterruptionMessage,
createUserMessage,
prepareUserContent,
} from '../messages.js'
import { resolveDefaultShell } from '../shell/resolveDefaultShell.js'
import { isPowerShellToolEnabled } from '../shell/shellToolUtils.js'
import { processToolResultBlock } from '../toolResultStorage.js'
import { escapeXml } from '../xml.js'
import type { ProcessUserInputContext } from './processUserInput.js'
} from '../messages.js';
import { resolveDefaultShell } from '../shell/resolveDefaultShell.js';
import { isPowerShellToolEnabled } from '../shell/shellToolUtils.js';
import { processToolResultBlock } from '../toolResultStorage.js';
import { escapeXml } from '../xml.js';
import type { ProcessUserInputContext } from './processUserInput.js';
export async function processBashCommand(
inputString: string,
@@ -31,67 +27,56 @@ export async function processBashCommand(
context: ProcessUserInputContext,
setToolJSX: SetToolJSXFn,
): Promise<{
messages: (UserMessage | AttachmentMessage | SystemMessage)[]
shouldQuery: boolean
messages: (UserMessage | AttachmentMessage | SystemMessage)[];
shouldQuery: boolean;
}> {
// Shell routing (docs/design/ps-shell-selection.md §5.2): consult
// defaultShell, fall back to bash. isPowerShellToolEnabled() applies the
// same platform + env-var gate as tools.ts so input-box routing matches
// tool-list visibility. Computed up front so telemetry records the
// actual shell, not the raw setting.
const usePowerShell =
isPowerShellToolEnabled() && resolveDefaultShell() === 'powershell'
const usePowerShell = isPowerShellToolEnabled() && resolveDefaultShell() === 'powershell';
logEvent('tengu_input_bash', { powershell: usePowerShell })
logEvent('tengu_input_bash', { powershell: usePowerShell });
const userMessage = createUserMessage({
content: prepareUserContent({
inputString: `<bash-input>${inputString}</bash-input>`,
precedingInputBlocks,
}),
})
});
// ctrl+b to background indicator
let jsx: React.ReactNode
let jsx: React.ReactNode;
// Just show initial UI
setToolJSX({
jsx: (
<BashModeProgress
input={inputString}
progress={null}
verbose={context.options.verbose}
/>
),
jsx: <BashModeProgress input={inputString} progress={null} verbose={context.options.verbose} />,
shouldHidePromptInput: false,
})
});
try {
const bashModeContext: ProcessUserInputContext = {
...context,
// TODO: Clean up this hack
setToolJSX: _ => {
jsx = _?.jsx
jsx = _?.jsx;
},
}
};
// Progress UI — shared across both shell backends (both emit ShellProgress)
const onProgress = (progress: { data: ShellProgress }) => {
setToolJSX({
jsx: (
<>
<BashModeProgress
input={inputString!}
progress={progress.data}
verbose={context.options.verbose}
/>
<BashModeProgress input={inputString!} progress={progress.data} verbose={context.options.verbose} />
{jsx}
</>
),
shouldHidePromptInput: false,
showSpinner: false,
})
}
});
};
// User-initiated `!` commands run outside sandbox. Both shell tools honor
// dangerouslyDisableSandbox (checked against areUnsandboxedCommandsAllowed()
@@ -99,16 +84,15 @@ export async function processBashCommand(
// native, shouldUseSandbox() returns false regardless (unsupported platform).
// Lazy-require PowerShellTool so its ~300KB chunk only loads when the
// user has actually selected the powershell default shell.
type PSMod = typeof import('@claude-code-best/builtin-tools/tools/PowerShellTool/PowerShellTool.js')
let PowerShellTool: PSMod['PowerShellTool'] | null = null
type PSMod = typeof import('@claude-code-best/builtin-tools/tools/PowerShellTool/PowerShellTool.js');
let PowerShellTool: PSMod['PowerShellTool'] | null = null;
if (usePowerShell) {
/* eslint-disable @typescript-eslint/no-require-imports */
PowerShellTool = (
require('@claude-code-best/builtin-tools/tools/PowerShellTool/PowerShellTool.js') as PSMod
).PowerShellTool
PowerShellTool = (require('@claude-code-best/builtin-tools/tools/PowerShellTool/PowerShellTool.js') as PSMod)
.PowerShellTool;
/* eslint-enable @typescript-eslint/no-require-imports */
}
const shellTool = PowerShellTool ?? BashTool
const shellTool = PowerShellTool ?? BashTool;
const response = PowerShellTool
? await PowerShellTool.call(
@@ -127,31 +111,24 @@ export async function processBashCommand(
undefined,
undefined,
onProgress,
)
const data = response.data
);
const data = response.data;
if (!data) {
throw new Error('No result received from shell command')
throw new Error('No result received from shell command');
}
const stderr = data.stderr
const stderr = data.stderr;
// Reuse the same formatting pipeline as inline !`cmd` bash (promptShellExecution)
// and model-initiated Bash. When BashTool.call() persists large output to disk,
// data.persistedOutputPath is set and the formatter wraps in <persisted-output>.
// Pass stderr:'' to keep it separate for the <bash-stderr> UI tag.
const mapped = await processToolResultBlock(
shellTool,
{ ...data, stderr: '' },
randomUUID(),
)
const mapped = await processToolResultBlock(shellTool, { ...data, stderr: '' }, randomUUID());
// mapped.content may contain our own <persisted-output> wrapper (trusted
// XML from buildLargeToolResultMessage). Escaping it would turn structural
// tags into &lt;persisted-output&gt;, breaking the model's parse and
// UserBashOutputMessage's extractTag. Escape the raw fallback only.
const stdout =
typeof mapped.content === 'string'
? mapped.content
: escapeXml(data.stdout)
const stdout = typeof mapped.content === 'string' ? mapped.content : escapeXml(data.stdout);
return {
messages: [
createSyntheticUserCaveatMessage(),
@@ -162,7 +139,7 @@ export async function processBashCommand(
}),
],
shouldQuery: false,
}
};
} catch (e) {
if (e instanceof ShellError) {
if (e.interrupted) {
@@ -174,7 +151,7 @@ export async function processBashCommand(
...attachmentMessages,
],
shouldQuery: false,
}
};
}
return {
messages: [
@@ -186,7 +163,7 @@ export async function processBashCommand(
}),
],
shouldQuery: false,
}
};
}
return {
messages: [
@@ -198,8 +175,8 @@ export async function processBashCommand(
}),
],
shouldQuery: false,
}
};
} finally {
setToolJSX(null)
setToolJSX(null);
}
}

View File

@@ -258,7 +258,9 @@ export async function processUserInput({
...hookResult.message,
attachment: {
...hookResult.message.attachment!,
content: applyTruncation(hookResult.message.attachment!.content as string),
content: applyTruncation(
hookResult.message.attachment!.content as string,
),
},
} as AttachmentMessage)
break