Skip to content
Closed
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: 3 additions & 2 deletions packages/opencode/src/session/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -655,9 +655,10 @@ export namespace SessionPrompt {
// Build system prompt, adding structured output instruction if needed
const skills = await SystemPrompt.skills(agent)
const system = [
...(await SystemPrompt.environment(model)),
...(skills ? [skills] : []),
...(await InstructionPrompt.system()),
// Put the most stable instructions first to maximize prompt-cache reuse.
...(await SystemPrompt.environment(model, session.time.created)),
...(skills ? [skills] : []),
]
const format = lastUser.format ?? { type: "text" }
if (format.type === "json_schema") {
Expand Down
5 changes: 3 additions & 2 deletions packages/opencode/src/session/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export namespace SystemPrompt {
return [PROMPT_DEFAULT]
}

export async function environment(model: Provider.Model) {
export async function environment(model: Provider.Model, sessionCreatedAt: number) {
const project = Instance.project
return [
[
Expand All @@ -36,7 +36,8 @@ export namespace SystemPrompt {
` Workspace root folder: ${Instance.worktree}`,
` Is directory a git repo: ${project.vcs === "git" ? "yes" : "no"}`,
` Platform: ${process.platform}`,
` Today's date: ${new Date().toDateString()}`,
// Keep the session day stable so long-lived sessions do not churn the prompt at midnight.
` Today's date: ${new Date(sessionCreatedAt).toDateString()}`,
`</env>`,
`<directories>`,
` ${
Expand Down
24 changes: 24 additions & 0 deletions packages/opencode/test/session/system.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,30 @@ import { SystemPrompt } from "../../src/session/system"
import { tmpdir } from "../fixture/fixture"

describe("session.system", () => {
test("environment uses the session creation day", async () => {
await using tmp = await tmpdir({
git: true,
})

await Instance.provide({
directory: tmp.path,
fn: async () => {
const environment = await SystemPrompt.environment(
{
providerID: "openai",
api: {
id: "gpt-5.2",
},
} as any,
Date.UTC(2026, 2, 22, 23, 59, 59),
)

expect(environment).toHaveLength(1)
expect(environment[0]).toContain("Today's date: Sun Mar 22 2026")
},
})
})

test("skills output is sorted by name and stable across calls", async () => {
await using tmp = await tmpdir({
git: true,
Expand Down
Loading