ci: add typechecking, fail fast in CI, and patch typechecking errors (#63)

This commit is contained in:
Charles Packer
2025-11-04 11:50:07 -08:00
committed by GitHub
parent 42eb671bf4
commit cf73f3a11f
27 changed files with 183 additions and 69 deletions

View File

@@ -113,7 +113,9 @@ export async function grep(args: GrepArgs): Promise<GrepResult> {
for (const line of lines) {
const parts = line.split(":");
if (parts.length >= 2) {
const count = parseInt(parts[parts.length - 1], 10);
const lastPart = parts[parts.length - 1];
if (!lastPart) continue;
const count = parseInt(lastPart, 10);
if (!Number.isNaN(count) && count > 0) {
totalMatches += count;
filesWithMatches++;

View File

@@ -19,7 +19,11 @@ export async function ls(
args: LSArgs,
): Promise<{ content: Array<{ type: string; text: string }> }> {
validateRequiredParams(args, ["path"], "LS");
validateParamTypes(args, LSSchema, "LS");
validateParamTypes(
args as unknown as Record<string, unknown>,
LSSchema,
"LS",
);
const { path: inputPath, ignore = [] } = args;
const dirPath = resolve(inputPath);
try {

View File

@@ -25,12 +25,16 @@ export async function multi_edit(
throw new Error(`File path must be absolute, got: ${file_path}`);
if (!edits || edits.length === 0) throw new Error("No edits provided");
for (let i = 0; i < edits.length; i++) {
const edit = edits[i];
if (!edit) {
throw new Error(`Edit ${i + 1} is undefined`);
}
validateRequiredParams(
edits[i] as Record<string, unknown>,
edit as unknown as Record<string, unknown>,
["old_string", "new_string"],
`MultiEdit (edit ${i + 1})`,
);
if (edits[i].old_string === edits[i].new_string)
if (edit.old_string === edit.new_string)
throw new Error(
`Edit ${i + 1}: No changes to make: old_string and new_string are exactly the same.`,
);
@@ -39,7 +43,9 @@ export async function multi_edit(
let content = await fs.readFile(file_path, "utf-8");
const appliedEdits: string[] = [];
for (let i = 0; i < edits.length; i++) {
const { old_string, new_string, replace_all = false } = edits[i];
const edit = edits[i];
if (!edit) continue;
const { old_string, new_string, replace_all = false } = edit;
const occurrences = content.split(old_string).length - 1;
if (occurrences === 0) {
throw new Error(

View File

@@ -35,7 +35,7 @@ import ReadSchema from "./schemas/Read.json";
import TodoWriteSchema from "./schemas/TodoWrite.json";
import WriteSchema from "./schemas/Write.json";
type ToolImplementation = (args: Record<string, any>) => Promise<any>;
type ToolImplementation = (args: Record<string, unknown>) => Promise<unknown>;
interface ToolAssets {
schema: Record<string, unknown>;
@@ -47,62 +47,62 @@ const toolDefinitions = {
Bash: {
schema: BashSchema,
description: BashDescription.trim(),
impl: bash as ToolImplementation,
impl: bash as unknown as ToolImplementation,
},
BashOutput: {
schema: BashOutputSchema,
description: BashOutputDescription.trim(),
impl: bash_output as ToolImplementation,
impl: bash_output as unknown as ToolImplementation,
},
Edit: {
schema: EditSchema,
description: EditDescription.trim(),
impl: edit as ToolImplementation,
impl: edit as unknown as ToolImplementation,
},
ExitPlanMode: {
schema: ExitPlanModeSchema,
description: ExitPlanModeDescription.trim(),
impl: exit_plan_mode as ToolImplementation,
impl: exit_plan_mode as unknown as ToolImplementation,
},
Glob: {
schema: GlobSchema,
description: GlobDescription.trim(),
impl: glob as ToolImplementation,
impl: glob as unknown as ToolImplementation,
},
Grep: {
schema: GrepSchema,
description: GrepDescription.trim(),
impl: grep as ToolImplementation,
impl: grep as unknown as ToolImplementation,
},
KillBash: {
schema: KillBashSchema,
description: KillBashDescription.trim(),
impl: kill_bash as ToolImplementation,
impl: kill_bash as unknown as ToolImplementation,
},
LS: {
schema: LSSchema,
description: LSDescription.trim(),
impl: ls as ToolImplementation,
impl: ls as unknown as ToolImplementation,
},
MultiEdit: {
schema: MultiEditSchema,
description: MultiEditDescription.trim(),
impl: multi_edit as ToolImplementation,
impl: multi_edit as unknown as ToolImplementation,
},
Read: {
schema: ReadSchema,
description: ReadDescription.trim(),
impl: read as ToolImplementation,
impl: read as unknown as ToolImplementation,
},
TodoWrite: {
schema: TodoWriteSchema,
description: TodoWriteDescription.trim(),
impl: todo_write as ToolImplementation,
impl: todo_write as unknown as ToolImplementation,
},
Write: {
schema: WriteSchema,
description: WriteDescription.trim(),
impl: write as ToolImplementation,
impl: write as unknown as ToolImplementation,
},
} as const satisfies Record<string, ToolAssets>;