Skip to content

Commit f3db564

Browse files
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 <[email protected]>
1 parent 15b0ee8 commit f3db564

File tree

2 files changed

+19
-21
lines changed

2 files changed

+19
-21
lines changed

src/agents/utils.ts

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,37 +29,30 @@ function buildAgent(source: AgentSource, model?: string): AgentConfig {
2929
return isFactory(source) ? source(model) : source
3030
}
3131

32-
export function createEnvContext(directory: string): string {
32+
/**
33+
* Creates OmO-specific environment context (time, timezone, locale).
34+
* Note: Working directory, platform, and date are already provided by OpenCode's system.ts,
35+
* so we only include fields that OpenCode doesn't provide to avoid duplication.
36+
* See: https://github.com/code-yeongyu/oh-my-opencode/issues/379
37+
*/
38+
export function createEnvContext(): string {
3339
const now = new Date()
3440
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone
3541
const locale = Intl.DateTimeFormat().resolvedOptions().locale
3642

37-
const dateStr = now.toLocaleDateString("en-US", {
38-
weekday: "short",
39-
year: "numeric",
40-
month: "short",
41-
day: "numeric",
42-
})
43-
4443
const timeStr = now.toLocaleTimeString("en-US", {
4544
hour: "2-digit",
4645
minute: "2-digit",
4746
second: "2-digit",
4847
hour12: true,
4948
})
5049

51-
const platform = process.platform as "darwin" | "linux" | "win32" | string
52-
5350
return `
54-
Here is some useful information about the environment you are running in:
55-
<env>
56-
Working directory: ${directory}
57-
Platform: ${platform}
58-
Today's date: ${dateStr} (NOT 2024, NEVEREVER 2024)
51+
<omo-env>
5952
Current time: ${timeStr}
6053
Timezone: ${timezone}
6154
Locale: ${locale}
62-
</env>`
55+
</omo-env>`
6356
}
6457

6558
function mergeAgentConfig(
@@ -97,7 +90,7 @@ export function createBuiltinAgents(
9790
let config = buildAgent(source, model)
9891

9992
if ((agentName === "Sisyphus" || agentName === "librarian") && directory && config.prompt) {
100-
const envContext = createEnvContext(directory)
93+
const envContext = createEnvContext()
10194
config = { ...config, prompt: config.prompt + envContext }
10295
}
10396

src/hooks/directory-agents-injector/index.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,17 @@ export function createDirectoryAgentsInjectorHook(ctx: PluginInput) {
6060
let current = startDir;
6161

6262
while (true) {
63-
const agentsPath = join(current, AGENTS_FILENAME);
64-
if (existsSync(agentsPath)) {
65-
found.push(agentsPath);
63+
// Skip root AGENTS.md - OpenCode's system.ts already loads it via custom()
64+
// See: https://github.com/code-yeongyu/oh-my-opencode/issues/379
65+
const isRootDir = current === ctx.directory;
66+
if (!isRootDir) {
67+
const agentsPath = join(current, AGENTS_FILENAME);
68+
if (existsSync(agentsPath)) {
69+
found.push(agentsPath);
70+
}
6671
}
6772

68-
if (current === ctx.directory) break;
73+
if (isRootDir) break;
6974
const parent = dirname(current);
7075
if (parent === current) break;
7176
if (!parent.startsWith(ctx.directory)) break;

0 commit comments

Comments
 (0)