feat(agents): inject environment context into OmO system prompt
Add user time and system context to OmO agent prompt to help the model understand the temporal context of the conversation. Injected context includes: - Working directory - Platform (darwin/linux/win32) - Current date and time - Timezone - Locale Closes #51 🤖 GENERATED WITH ASSISTANCE OF [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode)
This commit is contained in:
@@ -19,6 +19,39 @@ const allBuiltinAgents: Record<BuiltinAgentName, AgentConfig> = {
|
||||
"multimodal-looker": multimodalLookerAgent,
|
||||
}
|
||||
|
||||
export function createEnvContext(directory: string): string {
|
||||
const now = new Date()
|
||||
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone
|
||||
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", {
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
second: "2-digit",
|
||||
hour12: true,
|
||||
})
|
||||
|
||||
const platform = process.platform as "darwin" | "linux" | "win32" | string
|
||||
|
||||
return `
|
||||
Here is some useful information about the environment you are running in:
|
||||
<env>
|
||||
Working directory: ${directory}
|
||||
Platform: ${platform}
|
||||
Today's date: ${dateStr}
|
||||
Current time: ${timeStr}
|
||||
Timezone: ${timezone}
|
||||
Locale: ${locale}
|
||||
</env>`
|
||||
}
|
||||
|
||||
function mergeAgentConfig(
|
||||
base: AgentConfig,
|
||||
override: AgentOverrideConfig
|
||||
@@ -28,7 +61,8 @@ function mergeAgentConfig(
|
||||
|
||||
export function createBuiltinAgents(
|
||||
disabledAgents: BuiltinAgentName[] = [],
|
||||
agentOverrides: AgentOverrides = {}
|
||||
agentOverrides: AgentOverrides = {},
|
||||
directory?: string
|
||||
): Record<string, AgentConfig> {
|
||||
const result: Record<string, AgentConfig> = {}
|
||||
|
||||
@@ -39,11 +73,21 @@ export function createBuiltinAgents(
|
||||
continue
|
||||
}
|
||||
|
||||
let finalConfig = config
|
||||
|
||||
if (agentName === "OmO" && directory && config.prompt) {
|
||||
const envContext = createEnvContext(directory)
|
||||
finalConfig = {
|
||||
...config,
|
||||
prompt: config.prompt + envContext,
|
||||
}
|
||||
}
|
||||
|
||||
const override = agentOverrides[agentName]
|
||||
if (override) {
|
||||
result[name] = mergeAgentConfig(config, override)
|
||||
result[name] = mergeAgentConfig(finalConfig, override)
|
||||
} else {
|
||||
result[name] = config
|
||||
result[name] = finalConfig
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -278,6 +278,7 @@ const OhMyOpenCodePlugin: Plugin = async (ctx) => {
|
||||
const builtinAgents = createBuiltinAgents(
|
||||
pluginConfig.disabled_agents,
|
||||
pluginConfig.agents,
|
||||
ctx.directory,
|
||||
);
|
||||
|
||||
const userAgents = (pluginConfig.claude_code?.agents ?? true) ? loadUserAgents() : {};
|
||||
|
||||
Reference in New Issue
Block a user