MCPcopy Create free account
hub / github.com/ChrisFeldmeier/OpenCodeRust / environment

Method environment

crates/opencode-session/src/system.rs:88–112  ·  view source on GitHub ↗

Build the environment context block. TS: `SystemPrompt.environment(model)` in session/system.ts Produces a string like: ```text You are powered by the model named claude-sonnet-4-20250514. The exact model ID is anthropic/claude-sonnet-4-20250514 Here is some useful information about the environment you are running in: Working directory: /home/user/project Is directory a git repo: yes Platfo

(env: &EnvironmentContext)

Source from the content-addressed store, hash-verified

86 /// </env>
87 /// ```
88 pub fn environment(env: &EnvironmentContext) -> String {
89 let mut lines = Vec::with_capacity(10);
90
91 lines.push(format!(
92 "You are powered by the model named {}. The exact model ID is {}/{}",
93 env.model_api_id, env.provider_id, env.model_api_id
94 ));
95 lines.push(
96 "Here is some useful information about the environment you are running in:".to_string(),
97 );
98 lines.push("<env>".to_string());
99 lines.push(format!(" Working directory: {}", env.working_directory));
100 lines.push(format!(
101 " Is directory a git repo: {}",
102 if env.is_git_repo { "yes" } else { "no" }
103 ));
104 lines.push(format!(" Platform: {}", env.platform));
105 lines.push(format!(
106 " Today's date: {}",
107 Local::now().format("%a %b %d %Y")
108 ));
109 lines.push("</env>".to_string());
110
111 lines.join("\n")
112 }
113}
114
115/// Context needed to build the environment block in the system prompt.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected