Files
oh-my-pi/packages/coding-agent/src/tools/file-recorder.ts
T
can1357 c6a11079f5 feat: added compact atom-mode parser and execution support
- Added compact Lark grammar processing and applied it to OpenAI custom-format tools before conversion.
- Reworked atom mode into `---PATH` compact commands with new grammar, parser, and rm/mv file operations.
- Updated `hline`/`href`/`hrefr` helper behavior and hashline mismatch guidance using shared anchor state.
- Standardized path formatting with `formatPathRelativeToCwd` across LSP, prompts, and edit/search/write tools.
- Added benchmark run-path handling, including `.gitignore` runs mapping, absolute reports, and safer snapshot output.
- Added tests for compact grammar payloads, atom parsing/execution, renderer streaming, and path-list outputs.
2026-04-29 01:16:33 +02:00

36 lines
1.0 KiB
TypeScript

import * as path from "node:path";
import { formatPathRelativeToCwd } from "./path-utils";
/**
* Creates a deduplicating recorder for relative file paths.
* Preserves insertion order in `list`; subsequent duplicates are ignored.
*/
export function createFileRecorder(): {
record: (relativePath: string) => void;
list: string[];
} {
const seen = new Set<string>();
const list: string[] = [];
return {
record(relativePath: string) {
if (!seen.has(relativePath)) {
seen.add(relativePath);
list.push(relativePath);
}
},
list,
};
}
/**
* Strip native virtual-root prefixes and format file paths relative to cwd when
* they are inside cwd. Paths outside cwd remain absolute.
*/
export function formatResultPath(filePath: string, isDirectory: boolean, basePath: string, cwd: string): string {
const cleanPath = filePath.startsWith("/") ? filePath.slice(1) : filePath;
if (isDirectory) {
return formatPathRelativeToCwd(path.resolve(basePath, cleanPath), cwd);
}
return formatPathRelativeToCwd(basePath, cwd);
}