Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-agents-md-symlink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@moonshot-ai/kimi-code": patch
---

Fix AGENTS.md files installed as symbolic links being ignored by the web backend.
2 changes: 1 addition & 1 deletion packages/agent-core-v2/src/agent/profile/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ async function pathExists(deps: ProfileContextDeps, path: string): Promise<boole

async function isFile(deps: ProfileContextDeps, path: string): Promise<boolean> {
try {
const stat = await deps.fs.stat(path);
const stat = await deps.fs.stat(path, { followSymlinks: true });
return stat.isFile;
} catch {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
mkdir,
realpath as nodeRealpath,
rm,
stat as nodeStat,
writeFile,
} from 'node:fs/promises';

Expand Down Expand Up @@ -187,9 +188,9 @@ export class HostFileSystem implements IHostFileSystem {
}
}

async stat(path: string): Promise<HostFileStat> {
async stat(path: string, options?: { followSymlinks?: boolean }): Promise<HostFileStat> {
try {
const s = await lstat(path);
const s = options?.followSymlinks === true ? await nodeStat(path) : await lstat(path);
return {
isFile: s.isFile(),
isDirectory: s.isDirectory(),
Expand Down
3 changes: 2 additions & 1 deletion packages/agent-core-v2/src/os/interface/hostFileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ export interface IHostFileSystem {
options?: { encoding?: BufferEncoding; errors?: TextDecodeErrors },
): AsyncGenerator<string>;
createExclusive(path: string, data: Uint8Array): Promise<boolean>;
stat(path: string): Promise<HostFileStat>;
/** Stats the entry itself (Node `lstat` semantics) unless `followSymlinks` resolves links to their target. */
stat(path: string, options?: { followSymlinks?: boolean }): Promise<HostFileStat>;
readdir(path: string): Promise<readonly HostDirEntry[]>;
mkdir(path: string, options?: { readonly recursive?: boolean }): Promise<void>;
remove(path: string): Promise<void>;
Expand Down
22 changes: 21 additions & 1 deletion packages/agent-core-v2/test/agent/profile/context.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises';
import { mkdir, mkdtemp, rm, symlink, writeFile } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join } from 'pathe';

Expand Down Expand Up @@ -75,6 +75,26 @@ describe('loadAgentsMd user-level discovery', () => {
});
});

describe('loadAgentsMd symlinked files', () => {
it('follows symlinks when loading user-level and project-level AGENTS.md', async () => {
const targetDir = await mkdtemp(join(tmpdir(), 'kimi-agents-target-'));
extraDirs.push(targetDir);
const brandTarget = join(targetDir, 'brand-AGENTS.md');
const projectTarget = join(targetDir, 'project-AGENTS.md');
await writeFile(brandTarget, 'brand via symlink', 'utf-8');
await writeFile(projectTarget, 'project via symlink', 'utf-8');

await mkdir(join(homeDir, '.kimi-code'), { recursive: true });
await symlink(brandTarget, join(homeDir, '.kimi-code', 'AGENTS.md'));
await symlink(projectTarget, join(workDir, 'AGENTS.md'));

const result = await loadAgentsMd({ fs, homeDir }, workDir);

expect(result).toContain('brand via symlink');
expect(result).toContain('project via symlink');
});
});

describe('loadAgentsMd brand home (KIMI_CODE_HOME)', () => {
let brandHome: string;

Expand Down
Loading