Skip to content
Open
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
6 changes: 6 additions & 0 deletions .changeset/fresh-kimi-now-resume.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@moonshot-ai/agent-core": patch
"@moonshot-ai/kimi-code": patch
---

Refresh the system prompt timestamp after resuming sessions.
13 changes: 13 additions & 0 deletions packages/agent-core/src/agent/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import type { ResolvedRuntimeProvider } from '../../session/provider-manager';
export * from './types';
export { resolveThinkingEffort, type ThinkingEffort } from './thinking';

const KIMI_NOW_LINE_RE = /The current date and time in ISO format is `[^`]*`\./;

export class ConfigState {
private _cwd: string;
private _modelAlias: string | undefined;
Expand Down Expand Up @@ -131,6 +133,10 @@ export class ConfigState {
return this._systemPrompt;
}

refreshRuntimeValues(): void {
this._systemPrompt = refreshKimiNow(this._systemPrompt);
}

get modelCapabilities(): ModelCapability {
return this.tryResolvedProviderConfig()?.modelCapabilities ?? UNKNOWN_CAPABILITY;
}
Expand All @@ -152,3 +158,10 @@ export class ConfigState {
}
}
}

function refreshKimiNow(systemPrompt: string): string {
return systemPrompt.replace(
KIMI_NOW_LINE_RE,
`The current date and time in ISO format is \`${new Date().toISOString()}\`.`,
Comment on lines +163 to +165

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Handle custom KIMI_NOW prompt templates

When a resumed session was created with a custom or extended profile that uses {{ KIMI_NOW }} anywhere other than the built-in English sentence, this replacement is a no-op and the next model request still receives the session-creation timestamp. Profiles render KIMI_NOW from arbitrary systemPromptTemplate values before persisting config.update, so the refresh needs to account for those prompts too rather than matching only the default prose line.

Useful? React with 👍 / 👎.

);
}
1 change: 1 addition & 0 deletions packages/agent-core/src/agent/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ export class Agent {

async resume(): Promise<{ warning?: string }> {
const result = await this.records.replay();
this.config.refreshRuntimeValues();
await this.background.loadFromDisk();
await this.background.reconcile();
await this.cron?.loadFromDisk();
Expand Down
41 changes: 41 additions & 0 deletions packages/agent-core/test/session/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,47 @@ afterEach(async () => {
});

describe('Session.init', () => {
it('refreshes KIMI_NOW in the system prompt when resuming a session', async () => {
vi.useFakeTimers();
try {
const workDir = await makeTempDir();
const sessionDir = await makeTempDir();
const oldNow = '2026-05-08T00:00:18.000Z';
const resumedNow = '2026-06-05T02:42:13.000Z';

vi.setSystemTime(new Date(oldNow));
const session = new Session({
id: 'test-kimi-now',
kaos: testKaos.withCwd(workDir),
homedir: sessionDir,
rpc: createSessionRpc([]),
skills: { explicitDirs: [join(workDir, 'missing-skills')] },
providerManager: testProviderManager(),
});
await session.createMain();
expect(session.getReadyAgent('main')?.config.systemPrompt).toContain(oldNow);
await session.closeForReload();

vi.setSystemTime(new Date(resumedNow));
const resumed = new Session({
id: 'test-kimi-now',
kaos: testKaos.withCwd(workDir),
homedir: sessionDir,
rpc: createSessionRpc([]),
skills: { explicitDirs: [join(workDir, 'missing-skills')] },
providerManager: testProviderManager(),
});
await resumed.resume();

const prompt = resumed.getReadyAgent('main')?.config.systemPrompt;
expect(prompt).toContain(resumedNow);
expect(prompt).not.toContain(oldNow);
await resumed.closeForReload();
} finally {
vi.useRealTimers();
}
});

it('runs an isolated system-trigger turn and records the latest AGENTS as a system reminder', async () => {
const workDir = await makeTempDir();
const sessionDir = await makeTempDir();
Expand Down