claude: static role/tools moved to --system-prompt-file
This commit is contained in:
parent
37c6504462
commit
68fe66c0ef
5 changed files with 98 additions and 80 deletions
|
|
@ -50,6 +50,29 @@ pub async fn write_mcp_config(socket: &Path) -> Result<PathBuf> {
|
|||
Ok(path)
|
||||
}
|
||||
|
||||
/// Write the agent's / manager's static system prompt to a file next to
|
||||
/// the MCP config and return the path. Passed to claude via
|
||||
/// `--system-prompt-file`, replacing claude's default system prompt with
|
||||
/// the role + tools instructions. Per-turn prompts become much smaller
|
||||
/// (just the wake message body).
|
||||
pub async fn write_system_prompt(
|
||||
socket: &Path,
|
||||
label: &str,
|
||||
flavor: mcp::Flavor,
|
||||
) -> Result<PathBuf> {
|
||||
let parent = socket.parent().unwrap_or_else(|| Path::new("/run/hive"));
|
||||
tokio::fs::create_dir_all(parent).await.ok();
|
||||
let template = match flavor {
|
||||
mcp::Flavor::Agent => include_str!("../prompts/agent.md"),
|
||||
mcp::Flavor::Manager => include_str!("../prompts/manager.md"),
|
||||
};
|
||||
let body = template.replace("{label}", label);
|
||||
let path = parent.join("claude-system-prompt.md");
|
||||
tokio::fs::write(&path, body).await?;
|
||||
tracing::info!(path = %path.display(), "wrote claude system prompt");
|
||||
Ok(path)
|
||||
}
|
||||
|
||||
/// One claude turn's outcome. The harness uses this to decide whether to
|
||||
/// transparently kick off a compaction and retry.
|
||||
#[derive(Debug)]
|
||||
|
|
@ -66,16 +89,17 @@ pub enum TurnOutcome {
|
|||
pub async fn drive_turn(
|
||||
prompt: &str,
|
||||
mcp_config: &Path,
|
||||
system_prompt: &Path,
|
||||
bus: &Bus,
|
||||
flavor: mcp::Flavor,
|
||||
) -> TurnOutcome {
|
||||
match run_turn(prompt, mcp_config, bus, flavor).await {
|
||||
match run_turn(prompt, mcp_config, system_prompt, bus, flavor).await {
|
||||
TurnOutcome::PromptTooLong => {
|
||||
if let Err(e) = compact_session(bus).await {
|
||||
tracing::warn!(error = %format!("{e:#}"), "compact failed");
|
||||
return TurnOutcome::Failed(e);
|
||||
}
|
||||
run_turn(prompt, mcp_config, bus, flavor).await
|
||||
run_turn(prompt, mcp_config, system_prompt, bus, flavor).await
|
||||
}
|
||||
other => other,
|
||||
}
|
||||
|
|
@ -131,10 +155,20 @@ pub async fn wait_for_login(claude_dir: &Path, state: Arc<Mutex<LoginState>>, po
|
|||
pub async fn run_turn(
|
||||
prompt: &str,
|
||||
mcp_config: &Path,
|
||||
system_prompt: &Path,
|
||||
bus: &Bus,
|
||||
flavor: mcp::Flavor,
|
||||
) -> TurnOutcome {
|
||||
match run_claude(prompt, mcp_config, bus, flavor, ClaudeMode::Turn).await {
|
||||
match run_claude(
|
||||
prompt,
|
||||
mcp_config,
|
||||
Some(system_prompt),
|
||||
bus,
|
||||
flavor,
|
||||
ClaudeMode::Turn,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(too_long) if too_long => TurnOutcome::PromptTooLong,
|
||||
Ok(_) => TurnOutcome::Ok,
|
||||
Err(e) => TurnOutcome::Failed(e),
|
||||
|
|
@ -151,6 +185,7 @@ pub async fn compact_session(bus: &Bus) -> Result<()> {
|
|||
let _ = run_claude(
|
||||
"/compact",
|
||||
Path::new("/dev/null"),
|
||||
None,
|
||||
bus,
|
||||
mcp::Flavor::Agent, // tool surface unused for /compact
|
||||
ClaudeMode::Compact,
|
||||
|
|
@ -169,6 +204,7 @@ enum ClaudeMode {
|
|||
async fn run_claude(
|
||||
prompt: &str,
|
||||
mcp_config: &Path,
|
||||
system_prompt: Option<&Path>,
|
||||
bus: &Bus,
|
||||
flavor: mcp::Flavor,
|
||||
mode: ClaudeMode,
|
||||
|
|
@ -183,6 +219,9 @@ async fn run_claude(
|
|||
.arg("--continue")
|
||||
.arg("--settings")
|
||||
.arg(CLAUDE_SETTINGS);
|
||||
if let Some(p) = system_prompt {
|
||||
cmd.arg("--system-prompt-file").arg(p);
|
||||
}
|
||||
if let ClaudeMode::Turn = mode {
|
||||
cmd.arg("--mcp-config")
|
||||
.arg(mcp_config)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue