From 5c2a2ddeefc545245f2bd891f61f33d8a2a4f01d Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Mon, 30 Sep 2024 18:22:53 +0000 Subject: [PATCH] revert file chunks --- packages/cli/src/cli.ts | 1 - packages/cli/src/run.ts | 67 ++++++++++++++++++----------------------- 2 files changed, 30 insertions(+), 38 deletions(-) diff --git a/packages/cli/src/cli.ts b/packages/cli/src/cli.ts index 6554766b0a..342904a5f9 100644 --- a/packages/cli/src/cli.ts +++ b/packages/cli/src/cli.ts @@ -99,7 +99,6 @@ export async function cli() { "-egi, --exclude-git-ignore", "exclude files that are ignored through the .gitignore file in the workspace root" ) - .option("-fcs, --file-chunk-size ", "file chunk size") .option( "-o, --out ", "output folder. Extra markdown fields for output and trace will also be generated" diff --git a/packages/cli/src/run.ts b/packages/cli/src/run.ts index 958134589b..077f11fe2e 100644 --- a/packages/cli/src/run.ts +++ b/packages/cli/src/run.ts @@ -70,7 +70,6 @@ import { resolveTokenEncoder } from "../../core/src/encoders" import { writeFile } from "fs/promises" import { writeFileSync } from "node:fs" import { prettifyMarkdown } from "../../core/src/markdown" -import { chunk } from "es-toolkit" async function setupTraceWriting(trace: MarkdownTrace, filename: string) { logVerbose(`trace: ${filename}`) @@ -125,37 +124,6 @@ export async function runScriptWithExitCode( process.exit(exitCode) } -async function resolveFiles( - files: string[], - options?: Partial -) { - const { excludedFiles, excludeGitIgnore } = options || {} - const resolvedFiles = new Set() - - for (const arg of files) { - if (HTTPS_REGEX.test(arg)) resolvedFiles.add(arg) - else { - const ffs = await host.findFiles(arg, { - applyGitIgnore: excludeGitIgnore, - }) - for (const file of ffs) { - resolvedFiles.add(filePathOrUrlToWorkspaceFile(file)) - } - } - } - - if (excludedFiles?.length) { - for (const arg of excludedFiles) { - const ffs = await host.findFiles(arg) - for (const f of ffs) - resolvedFiles.delete(filePathOrUrlToWorkspaceFile(f)) - } - } - - const res = Array.from(resolvedFiles) - return res -} - export async function runScript( scriptId: string, files: string[], @@ -168,7 +136,8 @@ export async function runScript( ): Promise<{ exitCode: number; result?: GenerationResult }> { const { trace = new MarkdownTrace(), infoCb, partialCb } = options || {} let result: GenerationResult - const filesChunkSize = normalizeInt(options.filesChunkSize) || -1 + const excludedFiles = options.excludedFiles + const excludeGitIgnore = !!options.excludeGitIgnore const out = options.out const stream = !options.json && !options.yaml && !out const skipLLM = !!options.prompt @@ -220,12 +189,36 @@ export async function runScript( } const toolFiles: string[] = [] - const resolvedFiles = await resolveFiles(files, options) - if (files.length && !resolvedFiles.length) - fail("no files found", FILES_NOT_FOUND_ERROR_CODE) + const resolvedFiles = new Set() if (GENAI_ANY_REGEX.test(scriptId)) toolFiles.push(scriptId) + for (const arg of files) { + if (HTTPS_REGEX.test(arg)) resolvedFiles.add(arg) + else { + const ffs = await host.findFiles(arg, { + applyGitIgnore: excludeGitIgnore, + }) + if (!ffs?.length) { + return fail( + `no files matching ${arg}`, + FILES_NOT_FOUND_ERROR_CODE + ) + } + for (const file of ffs) { + resolvedFiles.add(filePathOrUrlToWorkspaceFile(file)) + } + } + } + + if (excludedFiles?.length) { + for (const arg of excludedFiles) { + const ffs = await host.findFiles(arg) + for (const f of ffs) + resolvedFiles.delete(filePathOrUrlToWorkspaceFile(f)) + } + } + const prj = await buildProject({ toolFiles, }) @@ -243,7 +236,7 @@ export async function runScript( ) if (!script) throw new Error(`script ${scriptId} not found`) const fragment: Fragment = { - files: resolvedFiles, + files: Array.from(resolvedFiles), } const vars = options.vars?.reduce( (acc, v) => ({ ...acc, ...parseKeyValuePair(v) }),