Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 0 additions & 71 deletions profiles/claude-code/runbook.md

This file was deleted.

4 changes: 2 additions & 2 deletions src/adapters/claude_cli.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Claude Code `claude -p` command rendering for `DispatchMechanism::Cli`
//! guidance (hybrid / headless run modes).
//! Claude Code `claude -p` command rendering for dispatch guidance
//! (hybrid / headless run modes).
//!
//! Differences from the Codex recipe, all forced by the `claude` CLI:
//! `--output-format stream-json` requires `--verbose` in `-p` mode; there is no
Expand Down
136 changes: 0 additions & 136 deletions src/adapters/claude_code_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
//! `<system-reminder>` block. Both live in an adapter rather than the harness-
//! agnostic orchestrator so a new harness adds its own renderer alongside.

use std::path::{Path, PathBuf};

use crate::core::AvailableSkill;

/// Render the list of discoverable skills the way a real Claude Code session
Expand Down Expand Up @@ -40,54 +38,10 @@ pub fn render_plan_mode_context(profile_text: &str) -> String {
format!("<system-reminder>\n{trimmed}\n</system-reminder>")
}

/// Slugify an absolute path the way Claude Code names its project directories:
/// every non-alphanumeric character becomes `-`. For example
/// `/Users/x/.config/oc` → `-Users-x--config-oc` (the `/` before `.config` and
/// the `.` each map to a `-`, producing the double hyphen).
pub fn slugify_project_path(path: &Path) -> String {
path.to_string_lossy()
.chars()
.map(|c| if c.is_ascii_alphanumeric() { c } else { '-' })
.collect()
}

/// Locate the subagents transcript dir for a Claude Code session.
///
/// Returns `<config_dir>/projects/<slug>/<session_id>/subagents/` when it
/// exists, where `<slug>` is [`slugify_project_path`] of `cwd`. If the
/// cwd-derived slug doesn't match (e.g. the command ran from a subdirectory of
/// the session's project), scans `<config_dir>/projects/*` for a child named
/// `<session_id>` — the session id is a globally-unique UUID, so at most one
/// project dir contains it. Returns `None` if no `subagents/` dir is found.
pub fn resolve_subagents_dir_for_session(
config_dir: &Path,
cwd: &Path,
session_id: &str,
) -> Option<PathBuf> {
let projects = config_dir.join("projects");
let primary = projects
.join(slugify_project_path(cwd))
.join(session_id)
.join("subagents");
if primary.is_dir() {
return Some(primary);
}
let entries = std::fs::read_dir(&projects).ok()?;
for entry in entries.flatten() {
let candidate = entry.path().join(session_id).join("subagents");
if candidate.is_dir() {
return Some(candidate);
}
}
None
}

#[cfg(test)]
mod tests {
use super::*;
use crate::core::AvailableSkill;
use std::fs;
use tempfile::TempDir;

fn skill(name: &str, description: &str) -> AvailableSkill {
AvailableSkill {
Expand Down Expand Up @@ -137,94 +91,4 @@ mod tests {
assert_eq!(render_plan_mode_context(""), "");
assert_eq!(render_plan_mode_context(" \n "), "");
}

#[test]
fn slugify_matches_claude_code_double_hyphen() {
// Verified against a real Claude Code project dir: the `/` before `.config`
// and the `.` both become `-`, producing a double hyphen.
assert_eq!(
slugify_project_path(Path::new("/Users/maxhaarhaus/.config/opencode")),
"-Users-maxhaarhaus--config-opencode"
);
}

#[test]
fn slugify_replaces_all_non_alphanumerics_keeping_alnum() {
assert_eq!(
slugify_project_path(Path::new("/a-b/c.d_e f")),
"-a-b-c-d-e-f"
);
assert_eq!(slugify_project_path(Path::new("/Proj9/v2")), "-Proj9-v2");
}

/// Create `<config>/projects/<dir>/<sid>/subagents/` and return the subagents path.
fn make_subagents(config: &Path, project_dir: &str, sid: &str) -> std::path::PathBuf {
let dir = config
.join("projects")
.join(project_dir)
.join(sid)
.join("subagents");
fs::create_dir_all(&dir).unwrap();
dir
}

#[test]
fn resolve_finds_primary_cwd_slug_path() {
let tmp = TempDir::new().unwrap();
let cwd = Path::new("/tmp/proj");
let sid = "5ade3f59-dda3-4f40-8776-79f82ba0fab2";
let expected = make_subagents(tmp.path(), "-tmp-proj", sid);
assert_eq!(
resolve_subagents_dir_for_session(tmp.path(), cwd, sid),
Some(expected)
);
}

#[test]
fn resolve_falls_back_to_scan_when_cwd_slug_differs() {
let tmp = TempDir::new().unwrap();
let cwd = Path::new("/tmp/proj"); // slug `-tmp-proj` is NOT created
let sid = "11111111-2222-3333-4444-555555555555";
let expected = make_subagents(tmp.path(), "some-other-project-slug", sid);
assert_eq!(
resolve_subagents_dir_for_session(tmp.path(), cwd, sid),
Some(expected)
);
}

#[test]
fn resolve_prefers_primary_over_scan_match() {
let tmp = TempDir::new().unwrap();
let cwd = Path::new("/tmp/proj");
let sid = "99999999-aaaa-bbbb-cccc-dddddddddddd";
// A scan candidate that sorts first, plus the cwd-slug primary.
make_subagents(tmp.path(), "aaa-other", sid);
let primary = make_subagents(tmp.path(), "-tmp-proj", sid);
assert_eq!(
resolve_subagents_dir_for_session(tmp.path(), cwd, sid),
Some(primary)
);
}

#[test]
fn resolve_none_when_session_dir_absent() {
let tmp = TempDir::new().unwrap();
fs::create_dir_all(tmp.path().join("projects")).unwrap();
assert_eq!(
resolve_subagents_dir_for_session(tmp.path(), Path::new("/tmp/proj"), "no-such-sid"),
None
);
}

#[test]
fn resolve_none_when_subagents_subdir_missing() {
let tmp = TempDir::new().unwrap();
let sid = "abcdabcd-0000-1111-2222-333333333333";
// Session dir exists (under the cwd slug) but without a `subagents/` child.
fs::create_dir_all(tmp.path().join("projects").join("-tmp-proj").join(sid)).unwrap();
assert_eq!(
resolve_subagents_dir_for_session(tmp.path(), Path::new("/tmp/proj"), sid),
None
);
}
}
Loading
Loading