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-missing-workdir-resume.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@moonshot-ai/kimi-code": patch
---

Fix resuming sessions whose original working directory no longer exists.
2 changes: 1 addition & 1 deletion packages/agent-core/src/agent/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class ConfigState {
});
if (changed.cwd) {
this._cwd = changed.cwd;
void this.agent.kaos.chdir(changed.cwd);
this.agent.setKaos(this.agent.kaos.withCwd(changed.cwd));
}
if (changed.modelAlias) {
this._modelAlias = changed.modelAlias;
Expand Down
19 changes: 19 additions & 0 deletions packages/agent-core/test/agent/config-state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,27 @@ import { emptyUsage } from '@moonshot-ai/kosong';
import { ProviderManager } from '../../src/session/provider-manager';
import type { KimiConfig } from '../../src/config';
import { testAgent } from './harness';
import { createFakeKaos } from '../tools/fixtures/fake-kaos';

describe('ConfigState model capabilities', () => {
it('updates the agent cwd without requiring the directory to exist', () => {
const chdir = vi.fn(async () => {
throw Object.assign(new Error('missing workspace'), { code: 'ENOENT' });
});
const ctx = testAgent({
kaos: createFakeKaos({
getcwd: () => '/workspace',
chdir,
}),
});

ctx.agent.config.update({ cwd: '/tmp/missing-workdir' });

expect(ctx.agent.config.cwd).toBe('/tmp/missing-workdir');
expect(ctx.agent.kaos.getcwd()).toBe('/tmp/missing-workdir');
expect(chdir).not.toHaveBeenCalled();
});

it('computes provider and model capabilities from ProviderManager metadata', () => {
const ctx = testAgent({
providerManager: new ProviderManager({
Expand Down
6 changes: 3 additions & 3 deletions packages/agent-core/test/tools/fixtures/fake-kaos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ export function createFakeKaos(
overrides?: Partial<Kaos>,
envLayers: readonly Record<string, string>[] = [],
): Kaos {
// Hold cwd in a closure so `chdir` (which `config.update({cwd})` now
// routes through) can mutate it and later `getcwd()` calls see the
// update — mirroring real-kaos semantics without needing a backing fs.
// Hold cwd in a closure so tests that call `chdir` directly can mutate it
// and later `getcwd()` calls see the update — mirroring real-kaos semantics
// without needing a backing fs.
let cwd = overrides?.getcwd?.() ?? '/workspace';
const base: Kaos = {
name: 'fake',
Expand Down
Loading