mirror of
https://github.com/MoonshotAI/kimi-code.git
synced 2026-12-05 13:50:50 +00:00
fix(agent-core-v2): anchor fs:list absolute keys at the containing workspace dir
Request-anchored keying broke deep browsing: listing a subdirectory of
an additional root re-anchored entry keys at that subdirectory, so the
client tree's key space shifted per request. Keys are now anchored at
the workspace dir (workdir or merged additional dir, longest match)
that contains the requested path, so a source folder has one stable
key space ('docs', 'docs/note.md') no matter which subpath is listed.
The longest-match comparison also no longer ties out additional roots
whose path length equals the workdir's.
This commit is contained in:
parent
bc10567e66
commit
2cc2ce5192
2 changed files with 53 additions and 2 deletions
|
|
@ -141,8 +141,8 @@ export class WorkspaceFsService implements IWorkspaceFsService {
|
|||
async list(req: FsListRequest): Promise<FsListResponse> {
|
||||
const abs = await this.resolveWithin(req.path);
|
||||
const anchored = this.path.isAbsolute(req.path);
|
||||
const rel = anchored ? '.' : this.toRel(abs);
|
||||
const base = anchored ? abs : this.workDir;
|
||||
const base = anchored ? this.anchorRoot(abs) : this.workDir;
|
||||
const rel = anchored ? this.toRelFrom(base, abs) : this.toRel(abs);
|
||||
const absOf = (relPath: string): string =>
|
||||
relPath === '' || relPath === '.' ? base : this.path.join(base, relPath);
|
||||
|
||||
|
|
@ -1218,6 +1218,23 @@ export class WorkspaceFsService implements IWorkspaceFsService {
|
|||
if (rel === '') return '.';
|
||||
return rel.split(this.path.separator).join('/');
|
||||
}
|
||||
|
||||
private anchorRoot(abs: string): string {
|
||||
const dirs = [this.workDir, ...this.workspaceDirs.additionalDirs.map((d) => this.path.resolve(d))];
|
||||
let best: string | undefined;
|
||||
for (const dir of dirs) {
|
||||
if (!isInsideOrEqual(this.path, abs, dir)) continue;
|
||||
if (best === undefined || dir.length > best.length) best = dir;
|
||||
}
|
||||
return best ?? this.workDir;
|
||||
}
|
||||
|
||||
private toRelFrom(base: string, abs: string): string {
|
||||
if (abs === base) return '.';
|
||||
const rel = this.path.relative(base, abs);
|
||||
if (rel === '') return '.';
|
||||
return rel.split(this.path.separator).join('/');
|
||||
}
|
||||
}
|
||||
|
||||
class RgJsonAccumulator {
|
||||
|
|
|
|||
|
|
@ -1397,6 +1397,40 @@ describe('WorkspaceFsService.list', () => {
|
|||
});
|
||||
expect(result.items.map((i) => i.path).toSorted()).toEqual(['notes.md', 'sub']);
|
||||
expect(result.children_by_path?.['sub']?.map((i) => i.path)).toEqual(['sub/more.ts']);
|
||||
|
||||
const sub = await fs.list({
|
||||
path: '/extra/sub',
|
||||
depth: 1,
|
||||
limit: 200,
|
||||
show_hidden: false,
|
||||
follow_gitignore: false,
|
||||
sort: 'name_asc',
|
||||
include_git_status: false,
|
||||
});
|
||||
expect(sub.items.map((i) => i.path)).toEqual(['sub/more.ts']);
|
||||
});
|
||||
|
||||
it('anchors at an additional root whose path length ties with the workdir', async () => {
|
||||
const fs = makeSession(
|
||||
{ '/repa/notes.md': '', 'src/a.ts': '' },
|
||||
emptyHandler,
|
||||
[],
|
||||
defaultGitStub(),
|
||||
[],
|
||||
undefined,
|
||||
{},
|
||||
['/repa'],
|
||||
);
|
||||
const result = await fs.list({
|
||||
path: '/repa',
|
||||
depth: 1,
|
||||
limit: 200,
|
||||
show_hidden: false,
|
||||
follow_gitignore: false,
|
||||
sort: 'name_asc',
|
||||
include_git_status: false,
|
||||
});
|
||||
expect(result.items.map((i) => i.path)).toEqual(['notes.md']);
|
||||
});
|
||||
|
||||
it('rejects absolute paths outside the workspace dir set', async () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue