mirror of
https://github.com/openai/codex.git
synced 2026-10-30 19:18:49 +00:00
generalize to all docs
This commit is contained in:
@@ -59,6 +59,7 @@ tree-sitter-bash = "0.25.0"
|
||||
uuid = { version = "1", features = ["serde", "v4"] }
|
||||
whoami = "1.6.1"
|
||||
wildmatch = "2.4.0"
|
||||
rust-embed = { version = "8.5.0", features = ["include-exclude"] }
|
||||
|
||||
|
||||
[target.'cfg(target_os = "linux")'.dependencies]
|
||||
|
||||
@@ -41,6 +41,9 @@ use crate::client::ModelClient;
|
||||
use crate::client_common::Prompt;
|
||||
use crate::client_common::ResponseEvent;
|
||||
use crate::config::Config;
|
||||
use crate::config_edit_tool::handle_get_config;
|
||||
use crate::config_edit_tool::handle_set_config;
|
||||
use crate::config_edit_tool::handle_show_codex_docs;
|
||||
use crate::config_types::ShellEnvironmentPolicy;
|
||||
use crate::conversation_history::ConversationHistory;
|
||||
use crate::environment_context::EnvironmentContext;
|
||||
@@ -70,9 +73,6 @@ use crate::openai_tools::ToolsConfigParams;
|
||||
use crate::openai_tools::get_openai_tools;
|
||||
use crate::parse_command::parse_command;
|
||||
use crate::plan_tool::handle_update_plan;
|
||||
use crate::config_edit_tool::handle_get_config;
|
||||
use crate::config_edit_tool::handle_set_config;
|
||||
use crate::config_edit_tool::handle_show_config_docs;
|
||||
use crate::project_doc::get_user_instructions;
|
||||
use crate::protocol::AgentMessageDeltaEvent;
|
||||
use crate::protocol::AgentMessageEvent;
|
||||
@@ -2193,7 +2193,7 @@ async fn handle_function_call(
|
||||
"update_plan" => handle_update_plan(sess, arguments, sub_id, call_id).await,
|
||||
"get_config" => handle_get_config(sess, arguments, sub_id, call_id).await,
|
||||
"set_config" => handle_set_config(sess, arguments, sub_id, call_id).await,
|
||||
"show_config_docs" => handle_show_config_docs(sess, arguments, sub_id, call_id).await,
|
||||
"show_codex_docs" => handle_show_codex_docs(sess, arguments, sub_id, call_id).await,
|
||||
EXEC_COMMAND_TOOL_NAME => {
|
||||
// TODO(mbolin): Sandbox check.
|
||||
let exec_params = match serde_json::from_str::<ExecCommandParams>(&arguments) {
|
||||
|
||||
@@ -171,7 +171,6 @@ pub struct Config {
|
||||
|
||||
pub tools_web_search_request: bool,
|
||||
|
||||
|
||||
/// The value for the `originator` header included with Responses API requests.
|
||||
pub responses_originator_header: String,
|
||||
|
||||
|
||||
@@ -3,21 +3,55 @@ use crate::config::find_codex_home;
|
||||
use crate::openai_tools::JsonSchema;
|
||||
use crate::openai_tools::OpenAiTool;
|
||||
use crate::openai_tools::ResponsesApiTool;
|
||||
use crate::protocol::ReviewDecision;
|
||||
use codex_apply_patch::ApplyPatchAction;
|
||||
use codex_apply_patch::MaybeApplyPatchVerified;
|
||||
use codex_apply_patch::maybe_parse_apply_patch_verified;
|
||||
use codex_protocol::models::FunctionCallOutputPayload;
|
||||
use codex_protocol::models::ResponseInputItem;
|
||||
use rust_embed::RustEmbed;
|
||||
use serde::Deserialize;
|
||||
use std::collections::BTreeMap;
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
use crate::protocol::ReviewDecision;
|
||||
use codex_apply_patch::maybe_parse_apply_patch_verified;
|
||||
use codex_apply_patch::MaybeApplyPatchVerified;
|
||||
use codex_apply_patch::ApplyPatchAction;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
|
||||
const CONFIG_TOML_FILE: &str = "config.toml";
|
||||
|
||||
// Embed docs at compile time.
|
||||
const CONFIG_DOCS_MD: &str = include_str!("../../../docs/config.md");
|
||||
// README from the repo root
|
||||
const README_MD: &str = include_str!("../../../README.md");
|
||||
// Entire docs directory from the repo root (only *.md files are embedded)
|
||||
#[derive(RustEmbed)]
|
||||
#[folder = "../../docs"]
|
||||
#[include = "**/*.md"]
|
||||
struct EmbeddedDocs;
|
||||
|
||||
fn push_separator(buf: &mut String) {
|
||||
buf.push_str("\n\n---\n\n");
|
||||
}
|
||||
|
||||
fn build_all_codex_docs() -> String {
|
||||
let mut out = String::new();
|
||||
out.push_str("# Codex Documentation\n\n");
|
||||
out.push_str("<!-- Source: README.md -->\n\n");
|
||||
out.push_str(README_MD);
|
||||
|
||||
// Add markdown files from ../docs recursively (embedded at compile time)
|
||||
let mut paths: Vec<String> = EmbeddedDocs::iter()
|
||||
.map(|p| p.as_ref().to_string())
|
||||
.collect();
|
||||
paths.sort();
|
||||
for path in paths.into_iter() {
|
||||
if let Some(file) = EmbeddedDocs::get(&path) {
|
||||
push_separator(&mut out);
|
||||
out.push_str(&format!("<!-- Source: {} -->\n\n", path));
|
||||
out.push_str(&String::from_utf8_lossy(&file.data));
|
||||
}
|
||||
}
|
||||
|
||||
out
|
||||
}
|
||||
|
||||
/// get_config() — fetches the current config.toml.
|
||||
pub(crate) fn create_get_config_tool() -> OpenAiTool {
|
||||
@@ -59,11 +93,11 @@ pub(crate) fn create_set_config_tool() -> OpenAiTool {
|
||||
})
|
||||
}
|
||||
|
||||
/// show_config_docs() — returns the configuration documentation.
|
||||
pub(crate) fn create_show_config_docs_tool() -> OpenAiTool {
|
||||
/// show_codex_docs() — returns Codex documentation.
|
||||
pub(crate) fn create_show_codex_docs_tool() -> OpenAiTool {
|
||||
OpenAiTool::Function(ResponsesApiTool {
|
||||
name: "show_config_docs".to_string(),
|
||||
description: "Returns the configuration documentation. If you need to know how to configure something in Codex or what configuration options are available, call this tool and use it to inform your answer.".to_string(),
|
||||
name: "show_codex_docs".to_string(),
|
||||
description: "Returns Codex documentation, including the repo README and all user docs under docs/. Use this when you need information about configuration, setup, features, or usage.".to_string(),
|
||||
strict: false,
|
||||
parameters: JsonSchema::Object {
|
||||
properties: BTreeMap::new(),
|
||||
@@ -122,7 +156,7 @@ pub(crate) async fn handle_set_config(
|
||||
content: format!("failed to parse function arguments: {e}"),
|
||||
success: None,
|
||||
},
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
// Validate TOML and ensure it can be materialized into a runtime Config.
|
||||
@@ -195,22 +229,24 @@ pub(crate) async fn handle_set_config(
|
||||
if v.last().is_some_and(|l| l.is_empty()) {
|
||||
v.pop();
|
||||
}
|
||||
v.into_iter().map(|l| l.to_string()).collect::<Vec<String>>()
|
||||
v.into_iter()
|
||||
.map(|l| l.to_string())
|
||||
.collect::<Vec<String>>()
|
||||
};
|
||||
|
||||
let patch_body = if let Some(curr) = ¤t {
|
||||
let mut body = format!("*** Update File: {}\n@@\n", path.display());
|
||||
for line in make_lines(curr) {
|
||||
body.push_str(&format!("-{}\n", line));
|
||||
body.push_str(&format!("-{line}\n"));
|
||||
}
|
||||
for line in make_lines(&args.new_config) {
|
||||
body.push_str(&format!("+{}\n", line));
|
||||
body.push_str(&format!("+{line}\n"));
|
||||
}
|
||||
body
|
||||
} else {
|
||||
let mut body = format!("*** Add File: {}\n", path.display());
|
||||
for line in make_lines(&args.new_config) {
|
||||
body.push_str(&format!("+{}\n", line));
|
||||
body.push_str(&format!("+{line}\n"));
|
||||
}
|
||||
body
|
||||
};
|
||||
@@ -265,16 +301,16 @@ pub(crate) async fn handle_set_config(
|
||||
};
|
||||
}
|
||||
}
|
||||
if let Some(parent) = path.parent() {
|
||||
if let Err(e) = fs::create_dir_all(parent) {
|
||||
return ResponseInputItem::FunctionCallOutput {
|
||||
call_id,
|
||||
output: FunctionCallOutputPayload {
|
||||
content: format!("failed to create config directory: {e}"),
|
||||
success: Some(false),
|
||||
},
|
||||
};
|
||||
}
|
||||
if let Some(parent) = path.parent()
|
||||
&& let Err(e) = fs::create_dir_all(parent)
|
||||
{
|
||||
return ResponseInputItem::FunctionCallOutput {
|
||||
call_id,
|
||||
output: FunctionCallOutputPayload {
|
||||
content: format!("failed to create config directory: {e}"),
|
||||
success: Some(false),
|
||||
},
|
||||
};
|
||||
}
|
||||
match fs::write(&path, args.new_config.as_bytes()) {
|
||||
Ok(_) => ResponseInputItem::FunctionCallOutput {
|
||||
@@ -294,16 +330,17 @@ pub(crate) async fn handle_set_config(
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) async fn handle_show_config_docs(
|
||||
pub(crate) async fn handle_show_codex_docs(
|
||||
_session: &Session,
|
||||
_arguments: String,
|
||||
_sub_id: String,
|
||||
call_id: String,
|
||||
) -> ResponseInputItem {
|
||||
let content = build_all_codex_docs();
|
||||
ResponseInputItem::FunctionCallOutput {
|
||||
call_id,
|
||||
output: FunctionCallOutputPayload {
|
||||
content: CONFIG_DOCS_MD.to_string(),
|
||||
content,
|
||||
success: Some(true),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -40,11 +40,11 @@ pub use model_provider_info::create_oss_provider_with_base_url;
|
||||
mod conversation_manager;
|
||||
pub use conversation_manager::ConversationManager;
|
||||
pub use conversation_manager::NewConversation;
|
||||
mod config_edit_tool;
|
||||
pub mod model_family;
|
||||
mod openai_model_info;
|
||||
mod openai_tools;
|
||||
pub mod plan_tool;
|
||||
mod config_edit_tool;
|
||||
pub mod project_doc;
|
||||
mod rollout;
|
||||
pub(crate) mod safety;
|
||||
|
||||
@@ -7,7 +7,7 @@ use std::collections::HashMap;
|
||||
|
||||
use crate::config_edit_tool::create_get_config_tool;
|
||||
use crate::config_edit_tool::create_set_config_tool;
|
||||
use crate::config_edit_tool::create_show_config_docs_tool;
|
||||
use crate::config_edit_tool::create_show_codex_docs_tool;
|
||||
use crate::model_family::ModelFamily;
|
||||
use crate::plan_tool::PLAN_TOOL;
|
||||
use crate::protocol::AskForApproval;
|
||||
@@ -576,7 +576,7 @@ pub(crate) fn get_openai_tools(
|
||||
// Always include internal config tools.
|
||||
tools.push(create_get_config_tool());
|
||||
tools.push(create_set_config_tool());
|
||||
tools.push(create_show_config_docs_tool());
|
||||
tools.push(create_show_codex_docs_tool());
|
||||
|
||||
// Include the view_image tool so the agent can attach images to context.
|
||||
if config.include_view_image_tool {
|
||||
@@ -658,7 +658,7 @@ mod tests {
|
||||
"web_search",
|
||||
"get_config",
|
||||
"set_config",
|
||||
"show_config_docs",
|
||||
"show_codex_docs",
|
||||
"view_image",
|
||||
],
|
||||
);
|
||||
@@ -687,7 +687,7 @@ mod tests {
|
||||
"web_search",
|
||||
"get_config",
|
||||
"set_config",
|
||||
"show_config_docs",
|
||||
"show_codex_docs",
|
||||
"view_image",
|
||||
],
|
||||
);
|
||||
@@ -751,7 +751,7 @@ mod tests {
|
||||
"web_search",
|
||||
"get_config",
|
||||
"set_config",
|
||||
"show_config_docs",
|
||||
"show_codex_docs",
|
||||
"view_image",
|
||||
"test_server/do_something_cool",
|
||||
],
|
||||
@@ -872,7 +872,7 @@ mod tests {
|
||||
"shell",
|
||||
"get_config",
|
||||
"set_config",
|
||||
"show_config_docs",
|
||||
"show_codex_docs",
|
||||
"view_image",
|
||||
"test_server/cool",
|
||||
"test_server/do",
|
||||
@@ -925,7 +925,7 @@ mod tests {
|
||||
"web_search",
|
||||
"get_config",
|
||||
"set_config",
|
||||
"show_config_docs",
|
||||
"show_codex_docs",
|
||||
"dash/search",
|
||||
],
|
||||
);
|
||||
@@ -993,7 +993,7 @@ mod tests {
|
||||
"get_config",
|
||||
"set_config",
|
||||
"view_image",
|
||||
"show_config_docs",
|
||||
"show_codex_docs",
|
||||
"dash/paginate",
|
||||
],
|
||||
);
|
||||
@@ -1057,7 +1057,7 @@ mod tests {
|
||||
"web_search",
|
||||
"get_config",
|
||||
"set_config",
|
||||
"show_config_docs",
|
||||
"show_codex_docs",
|
||||
"dash/tags",
|
||||
],
|
||||
);
|
||||
@@ -1125,7 +1125,7 @@ mod tests {
|
||||
"web_search",
|
||||
"get_config",
|
||||
"set_config",
|
||||
"show_config_docs",
|
||||
"show_codex_docs",
|
||||
"dash/value",
|
||||
],
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user