Skip to content

Commit

Permalink
revert file chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Sep 30, 2024
1 parent c3cf3d1 commit 5c2a2dd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 38 deletions.
1 change: 0 additions & 1 deletion packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 <number>", "file chunk size")
.option(
"-o, --out <string>",
"output folder. Extra markdown fields for output and trace will also be generated"
Expand Down
67 changes: 30 additions & 37 deletions packages/cli/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
Expand Down Expand Up @@ -125,37 +124,6 @@ export async function runScriptWithExitCode(
process.exit(exitCode)
}

async function resolveFiles(
files: string[],
options?: Partial<PromptScriptRunOptions>
) {
const { excludedFiles, excludeGitIgnore } = options || {}
const resolvedFiles = new Set<string>()

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[],
Expand All @@ -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
Expand Down Expand Up @@ -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<string>()

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,
})
Expand All @@ -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) }),
Expand Down

0 comments on commit 5c2a2dd

Please sign in to comment.