mirror of
https://gitverse.ru/anarchic/claude-code
synced 2026-05-03 15:00:37 +00:00
new initial commit (history rewritten)
This commit is contained in:
commit
c1996f2e3b
1907 changed files with 514172 additions and 0 deletions
45
utils/settings/validateEditTool.ts
Normal file
45
utils/settings/validateEditTool.ts
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import type { ValidationResult } from 'src/Tool.js'
|
||||
import { isClaudeSettingsPath } from '../permissions/filesystem.js'
|
||||
import { validateSettingsFileContent } from './validation.js'
|
||||
|
||||
/**
|
||||
* Validates settings file edits to ensure the result conforms to SettingsSchema.
|
||||
* This is used by FileEditTool to avoid code duplication.
|
||||
*
|
||||
* @param filePath - The file path being edited
|
||||
* @param originalContent - The original file content before edits
|
||||
* @param getUpdatedContent - A closure that returns the content after applying edits
|
||||
* @returns Validation result with error details if validation fails
|
||||
*/
|
||||
export function validateInputForSettingsFileEdit(
|
||||
filePath: string,
|
||||
originalContent: string,
|
||||
getUpdatedContent: () => string,
|
||||
): Extract<ValidationResult, { result: false }> | null {
|
||||
// Only validate Claude settings files
|
||||
if (!isClaudeSettingsPath(filePath)) {
|
||||
return null
|
||||
}
|
||||
|
||||
// Check if the current file (before edit) conforms to the schema
|
||||
const beforeValidation = validateSettingsFileContent(originalContent)
|
||||
|
||||
if (!beforeValidation.isValid) {
|
||||
// If the before version is invalid, allow the edit (don't block it)
|
||||
return null
|
||||
}
|
||||
|
||||
// If the before version is valid, ensure the after version is also valid
|
||||
const updatedContent = getUpdatedContent()
|
||||
const afterValidation = validateSettingsFileContent(updatedContent)
|
||||
|
||||
if (!afterValidation.isValid) {
|
||||
return {
|
||||
result: false,
|
||||
message: `Claude Code settings.json validation failed after edit:\n${afterValidation.error}\n\nFull schema:\n${afterValidation.fullSchema}\nIMPORTANT: Do not update the env unless explicitly instructed to do so.`,
|
||||
errorCode: 10,
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue