fix: reduce context duplication from ~22k to ~11k tokens (#383)

* fix: reduce context duplication from ~22k to ~11k tokens

Remove redundant env info and root AGENTS.md injection that OpenCode
already provides, addressing significant token waste on startup.

Changes:
- src/agents/utils.ts: Remove duplicated env fields (working dir,
  platform, date) from createEnvContext(), keep only OmO-specific
  fields (time, timezone, locale)
- src/hooks/directory-agents-injector/index.ts: Skip root AGENTS.md
  injection since OpenCode's system.ts already loads it via custom()

Fixes #379

* refactor: remove unused _directory parameter from createEnvContext()

---------

Co-authored-by: sisyphus-dev-ai <sisyphus-dev-ai@users.noreply.github.com>
This commit is contained in:
Sisyphus
2026-01-01 20:23:23 +09:00
committed by GitHub
parent 15b0ee80e1
commit f3db564b2e
2 changed files with 19 additions and 21 deletions

View File

@@ -29,18 +29,17 @@ function buildAgent(source: AgentSource, model?: string): AgentConfig {
return isFactory(source) ? source(model) : source return isFactory(source) ? source(model) : source
} }
export function createEnvContext(directory: string): string { /**
* Creates OmO-specific environment context (time, timezone, locale).
* Note: Working directory, platform, and date are already provided by OpenCode's system.ts,
* so we only include fields that OpenCode doesn't provide to avoid duplication.
* See: https://github.com/code-yeongyu/oh-my-opencode/issues/379
*/
export function createEnvContext(): string {
const now = new Date() const now = new Date()
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone
const locale = Intl.DateTimeFormat().resolvedOptions().locale const locale = Intl.DateTimeFormat().resolvedOptions().locale
const dateStr = now.toLocaleDateString("en-US", {
weekday: "short",
year: "numeric",
month: "short",
day: "numeric",
})
const timeStr = now.toLocaleTimeString("en-US", { const timeStr = now.toLocaleTimeString("en-US", {
hour: "2-digit", hour: "2-digit",
minute: "2-digit", minute: "2-digit",
@@ -48,18 +47,12 @@ export function createEnvContext(directory: string): string {
hour12: true, hour12: true,
}) })
const platform = process.platform as "darwin" | "linux" | "win32" | string
return ` return `
Here is some useful information about the environment you are running in: <omo-env>
<env>
Working directory: ${directory}
Platform: ${platform}
Today's date: ${dateStr} (NOT 2024, NEVEREVER 2024)
Current time: ${timeStr} Current time: ${timeStr}
Timezone: ${timezone} Timezone: ${timezone}
Locale: ${locale} Locale: ${locale}
</env>` </omo-env>`
} }
function mergeAgentConfig( function mergeAgentConfig(
@@ -97,7 +90,7 @@ export function createBuiltinAgents(
let config = buildAgent(source, model) let config = buildAgent(source, model)
if ((agentName === "Sisyphus" || agentName === "librarian") && directory && config.prompt) { if ((agentName === "Sisyphus" || agentName === "librarian") && directory && config.prompt) {
const envContext = createEnvContext(directory) const envContext = createEnvContext()
config = { ...config, prompt: config.prompt + envContext } config = { ...config, prompt: config.prompt + envContext }
} }

View File

@@ -60,12 +60,17 @@ export function createDirectoryAgentsInjectorHook(ctx: PluginInput) {
let current = startDir; let current = startDir;
while (true) { while (true) {
// Skip root AGENTS.md - OpenCode's system.ts already loads it via custom()
// See: https://github.com/code-yeongyu/oh-my-opencode/issues/379
const isRootDir = current === ctx.directory;
if (!isRootDir) {
const agentsPath = join(current, AGENTS_FILENAME); const agentsPath = join(current, AGENTS_FILENAME);
if (existsSync(agentsPath)) { if (existsSync(agentsPath)) {
found.push(agentsPath); found.push(agentsPath);
} }
}
if (current === ctx.directory) break; if (isRootDir) break;
const parent = dirname(current); const parent = dirname(current);
if (parent === current) break; if (parent === current) break;
if (!parent.startsWith(ctx.directory)) break; if (!parent.startsWith(ctx.directory)) break;