fix: remove Current date from env context since OpenCode already provides it

date is already injected by OpenCode's system.ts. omo-env now contains only
Timezone and Locale, which are stable across requests and never break cache.
This commit is contained in:
YeonGyu-Kim 2026-02-26 20:22:17 +09:00
parent 0b69a6c507
commit 088984a8d4
2 changed files with 6 additions and 14 deletions

View File

@ -4,7 +4,7 @@ import { describe, test, expect } from "bun:test"
import { createEnvContext } from "./env-context"
describe("createEnvContext", () => {
test("returns omo-env block with date, timezone, and locale", () => {
test("returns omo-env block with timezone and locale", () => {
// #given - no setup needed
// #when
@ -13,9 +13,9 @@ describe("createEnvContext", () => {
// #then
expect(result).toContain("<omo-env>")
expect(result).toContain("</omo-env>")
expect(result).toContain("Current date:")
expect(result).toContain("Timezone:")
expect(result).toContain("Locale:")
expect(result).not.toContain("Current date:")
})
test("does not include time with seconds precision to preserve token cache", () => {
@ -28,13 +28,14 @@ describe("createEnvContext", () => {
expect(result).not.toMatch(/\d{1,2}:\d{2}:\d{2}/)
})
test("does not include Current time field", () => {
// #given - time field (even without seconds) changes every minute, degrading cache
test("does not include date or time fields since OpenCode already provides them", () => {
// #given - OpenCode's system.ts already injects date, platform, working directory
// #when
const result = createEnvContext()
// #then - time field entirely removed; date-level precision is sufficient
// #then - only timezone and locale remain; both are stable across requests
expect(result).not.toContain("Current date:")
expect(result).not.toContain("Current time:")
})
})

View File

@ -5,20 +5,11 @@
* See: https://github.com/code-yeongyu/oh-my-opencode/issues/379
*/
export function createEnvContext(): string {
const now = new Date()
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone
const locale = Intl.DateTimeFormat().resolvedOptions().locale
const dateStr = now.toLocaleDateString(locale, {
weekday: "short",
year: "numeric",
month: "short",
day: "numeric",
})
return `
<omo-env>
Current date: ${dateStr}
Timezone: ${timezone}
Locale: ${locale}
</omo-env>`