Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions build/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/vale-runner.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions build/vale-runner.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/vale-runner.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 25 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ function getInstallationInstructions(): {
documentation: string;
} {
const platform = process.platform;
const instructions: any = {
const instructions: {
platform: string;
methods: Array<{ name: string; command: string; url?: string }>;
documentation: string;
} = {
platform,
documentation: "https://vale.sh/docs/vale-cli/installation/",
methods: [],
Expand Down Expand Up @@ -234,6 +238,10 @@ const TOOLS: Tool[] = [
type: "string",
description: "Absolute or relative path to the file to check",
},
config_path: {
type: "string",
description: "Optional path to .vale.ini file. If not provided, Vale will search for .vale.ini starting from the file's directory and moving upward through parent directories.",
},
},
required: ["path"],
},
Expand All @@ -249,6 +257,10 @@ const TOOLS: Tool[] = [
type: "string",
description: "The text content to check with Vale",
},
config_path: {
type: "string",
description: "Optional path to .vale.ini file. If not provided, uses the server's configured path or searches in the current directory.",
},
},
required: ["text"],
},
Expand Down Expand Up @@ -353,9 +365,9 @@ See Vale documentation: https://vale.sh/docs/topics/packages/`,
}

case "check_file": {
const { path: filePath } = args as { path: string };
const { path: filePath, config_path } = args as { path: string; config_path?: string };

debug(`check_file called - path: ${filePath}`);
debug(`check_file called - path: ${filePath}, config_path: ${config_path}`);

if (!filePath) {
return {
Expand All @@ -376,7 +388,9 @@ See Vale documentation: https://vale.sh/docs/topics/packages/`,
return createValeNotInstalledResponse();
}

const result = await checkFile(filePath, valeConfigPath);
// Only pass config_path if explicitly provided by the user
// This allows Vale to use its natural upward search from the file's directory
const result = await checkFile(filePath, config_path);

debug(`check_file result - file: ${result.file}, issues found: ${result.issues.length}, errors: ${result.summary.errors}, warnings: ${result.summary.warnings}, suggestions: ${result.summary.suggestions}`);

Expand All @@ -398,9 +412,9 @@ See Vale documentation: https://vale.sh/docs/topics/packages/`,
}

case "check_text": {
const { text } = args as { text: string };
const { text, config_path } = args as { text: string; config_path?: string };

debug(`check_text called - text length: ${text?.length}`);
debug(`check_text called - text length: ${text?.length}, config_path: ${config_path}`);

if (!text) {
return {
Expand All @@ -421,7 +435,11 @@ See Vale documentation: https://vale.sh/docs/topics/packages/`,
return createValeNotInstalledResponse();
}

const result = await checkText(text, valeConfigPath);
// For check_text, we should use the provided config_path if given,
// otherwise fall back to the server's configured path since there's no file directory to search from
const effectiveConfigPath = config_path !== undefined ? config_path : valeConfigPath;

const result = await checkText(text, effectiveConfigPath);

debug(`check_text result - issues found: ${result.issues.length}, errors: ${result.summary.errors}, warnings: ${result.summary.warnings}, suggestions: ${result.summary.suggestions}`);

Expand Down
16 changes: 9 additions & 7 deletions src/vale-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ export async function checkFile(
command += ` "${absolutePath}"`;

// Run Vale from the file's directory so it searches upward from there
const execOptions: any = {
const execOptions: ExecOptions = {
encoding: 'utf-8',
cwd: path.dirname(absolutePath)
};
Expand All @@ -308,13 +308,14 @@ export async function checkFile(
try {
const result = await execAsync(command, execOptions);
stdout = typeof result.stdout === 'string' ? result.stdout : result.stdout.toString('utf-8');
} catch (error: any) {
} catch (error: unknown) {
// Vale returns non-zero exit code when there are issues
// But it still outputs JSON to stdout
if (error.stdout) {
stdout = error.stdout;
const execError = error as { stdout?: string; stderr?: string; message?: string };
if (execError.stdout) {
stdout = execError.stdout;
} else {
const errorMessage = error.stderr || error.message || "Unknown error";
const errorMessage = execError.stderr || execError.message || "Unknown error";
throw new Error(
`Vale execution failed: ${errorMessage}`
);
Expand Down Expand Up @@ -379,8 +380,9 @@ export async function checkText(
});

stdout = result.stdout;
} catch (error: any) {
const errorMessage = error.stderr || error.message || "Unknown error";
} catch (error: unknown) {
const execError = error as { stderr?: string; message?: string };
const errorMessage = execError.stderr || execError.message || "Unknown error";
throw new Error(
`Vale execution failed: ${errorMessage}`
);
Expand Down