PerFilePromptGenerator: relative filePattern resolves against process.cwd() instead of the config file directory
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 72/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Ít trao đổi
- Công nghệ
- typescript
Hướng nghiên cứu
Start in src/prompt-generators/per-file.ts, especially PerFilePromptGenerator.generate() and resolveFiles(), then review src/prompt-generators/test/per-file.test.ts. Add coverage for a relative pattern with an explicit basePath and run the per-file tests. Done means config-relative files are found regardless of the invocation directory, with resumed IDs remaining consistent across runs.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Observed behavior
PerFilePromptGenerator accepts a basePath constructor argument used to resolve {{include:...}} macros, and the CLI loader threads the config-file directory through as that basePath. However, filePattern (and excludePatterns) are passed directly to glob() without a cwd option, so a relative filePattern is resolved against process.cwd() rather than the config file directory.
Source: src/prompt-generators/per-file.ts:62-79
constructor(task: PerFileTask, basePath?: string) {
this.#task = task;
this.#basePath = basePath ?? process.cwd();
}
async *generate(loopState: LoopState): AsyncIterable<Prompt> {
const { filePattern, excludePatterns } = this.#task;
const allFiles = await resolveFiles(filePattern, excludePatterns);
// ...
}
And src/prompt-generators/per-file.ts:85-97:
export async function resolveFiles(
filePattern: string,
excludePatterns?: Array<string>,
): Promise<Array<string>> {
const files = await glob(filePattern, {
...(excludePatterns ? { ignore: excludePatterns } : {}),
nodir: true,
});
files.sort();
return files;
}
Note that #basePath is captured but never used inside generate() for the glob call. The glob library defaults its cwd option to process.cwd().
This is inconsistent with the rest of the CLI config loader:
outputDir: resolved against the config file directory (src/util/load-cli-config.ts:226-229, since issue #34).{{include:...}}macros (in prompt templates andclaude-sdksystemPrompt): resolved against the config file directory (src/util/expand-prompt.ts).JsonPromptGenerator.dataFile: explicitlyresolve(basePath, task.dataFile)(src/prompt-generators/json.ts:122-126).
per-file.filePattern is the odd one out.
Expected behavior
A relative filePattern in a CLI JSON config should resolve against the directory containing the config file, the same as outputDir, {{include:...}} macros, and JsonTask.dataFile. A user writing:
{ "promptGenerator": ["per-file", { "filePattern": "src/**/*.ts", "promptTemplate": "Review {{file}}" }] }
in /some/where/config.json naturally expects the loop to enumerate /some/where/src/**/*.ts, not ${cwd}/src/**/*.ts.
Minimal reproduction
mkdir -p /tmp/llt-pf-repro/proj/src
cat > /tmp/llt-pf-repro/proj/src/hello.ts <<'TS'
export const hello = 'world';
TS
cat > /tmp/llt-pf-repro/proj/config.json <<'JSON'
{
"name": "demo",
"agent": "claude-sdk",
"promptGenerator": [
"per-file",
{ "filePattern": "src/**/*.ts", "promptTemplate": "Review {{file}}" }
]
}
JSON
mkdir -p /tmp/llt-pf-repro/elsewhere
cd /tmp/llt-pf-repro/elsewhere
pnpx loop-the-loop --dry-run /tmp/llt-pf-repro/proj/config.json
# Yields zero prompts: glob looks for /tmp/llt-pf-repro/elsewhere/src/**/*.ts.
# Expected: one prompt for src/hello.ts, since the config lives next to src/.
For comparison, running the same command from /tmp/llt-pf-repro/proj does match the file, because process.cwd() happens to coincide with the config directory in that case.
Suggested fix
Thread #basePath through to glob's cwd option:
export async function resolveFiles(
filePattern: string,
excludePatterns?: Array<string>,
cwd?: string,
): Promise<Array<string>> {
const files = await glob(filePattern, {
...(cwd ? { cwd } : {}),
...(excludePatterns ? { ignore: excludePatterns } : {}),
nodir: true,
});
files.sort();
return files;
}
and in generate():
const allFiles = await resolveFiles(filePattern, excludePatterns, this.#basePath);
glob's cwd option is a no-op when the pattern is already absolute, so callers that pass absolute paths (including the existing tests in src/prompt-generators/__test__/per-file.test.ts) keep working. A new test should cover the relative case with an explicit basePath.
One subtlety: with cwd set, glob returns paths relative to cwd. The current id (used by LoopState) is whatever glob returns. If we want IDs to remain stable across runs regardless of the invocation cwd, the fix should also normalize the returned paths (e.g. by resolving to absolute, or by joining with basePath) so that the resumed IDs match a fresh run from a different directory.
- Ngôn ngữ chính
- TypeScript
- Star
- 2
- Fork
- 1
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của joewalker/loop-the-loop
-
bug S4
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
joewalker/loop-the-loop#88 ·
-
Git exec(): child killed by a signal rejects with new Error('') and loses the signal informationĐang mởbug S3
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
joewalker/loop-the-loop#84 ·
-
bug S3
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
joewalker/loop-the-loop#83 ·
-
bug S3
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
joewalker/loop-the-loop#82 ·
-
bug S4
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
joewalker/loop-the-loop#79 ·
Tất cả issue của joewalker/loop-the-loop
Issue tương tự
-
comp/desktop desktop/shell os/windows P3 tool/file type/bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
NousResearch/hermes-agent#145928 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
compiler-dom: stringifyStatic renders :disabled="0" as a present attributeCó thể đã có người làm @DaZuiZui đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
vuejs/core#16051 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 74/100
-
integration:coding-agents
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 83/100
vectorize-io/hindsight#6151 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
DogFooding
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
OpenAEV-Platform/openaev#8768 ·
Maintainer thường phản hồi trong vòng 1 ngày