swarm repositories / source
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormain <main@swarm.moe>2026-03-23 18:34:53 -0400
committermain <main@swarm.moe>2026-03-23 18:34:53 -0400
commitdd2b64ed08b8ac55d6aaeb54d635b33b51eea790 (patch)
treef9393e1eafde049f402ab3421eedd08fe53fa0ce
parent4e80028e44ede42b9e0f7bd4beaee8a5cf9aae7c (diff)
downloadphone_opus-dd2b64ed08b8ac55d6aaeb54d635b33b51eea790.zip
Surface consult session ids in saved outputs
-rw-r--r--assets/codex-skills/phone-opus/SKILL.md1
-rw-r--r--crates/phone-opus/src/mcp/service.rs10
-rw-r--r--crates/phone-opus/tests/mcp_hardening.rs2
3 files changed, 10 insertions, 3 deletions
diff --git a/assets/codex-skills/phone-opus/SKILL.md b/assets/codex-skills/phone-opus/SKILL.md
index 9a0781b..6b1ae3d 100644
--- a/assets/codex-skills/phone-opus/SKILL.md
+++ b/assets/codex-skills/phone-opus/SKILL.md
@@ -37,6 +37,7 @@ should be taken as authoritative or final. It is a pure consultant.
- Uses `--dangerously-skip-permissions`, but wraps Claude in an external `systemd-run --user` sandbox.
- The sandbox keeps the filesystem globally read-only, gives Claude a separate persistent home under phone-opus state, leaves `/tmp` and `/var/tmp` writable, and forces the consulted `cwd` read-only when that tree would otherwise be writable.
- Previous consult outputs can be found in `/tmp/phone_opus-consults`.
+- For related follow-ups, strongly prefer reusing `session_id`; cold-start Opus burns quota rereading files, while session reuse is much cheaper.
- This surface is consultative only. Edit tools are unavailable.
- The returned `session_id` is reusable: pass it back into a later `consult` call to continue that Claude conversation.
- Background consults return a `job_id`; use `consult_job` to poll one job or `consult_jobs` to rediscover recent ones.
diff --git a/crates/phone-opus/src/mcp/service.rs b/crates/phone-opus/src/mcp/service.rs
index 2baa744..ff25433 100644
--- a/crates/phone-opus/src/mcp/service.rs
+++ b/crates/phone-opus/src/mcp/service.rs
@@ -691,14 +691,18 @@ impl ClaudeSandbox {
struct PersistedConsultPath(PathBuf);
impl PersistedConsultPath {
- fn new(request: &ConsultRequest) -> io::Result<Self> {
+ fn new(request: &ConsultRequest, session_id: Option<&str>) -> io::Result<Self> {
fs::create_dir_all(CONSULT_OUTPUT_ROOT)?;
let timestamp = OffsetDateTime::now_utc()
.format(CONSULT_TIMESTAMP_FORMAT)
.map_err(|error| io::Error::other(error.to_string()))?;
let slug = consult_slug(request.prompt.as_str());
+ let session_slug = session_id.map_or_else(
+ || "session-none".to_owned(),
+ |session_id| format!("session-{}", consult_slug(session_id)),
+ );
Ok(Self(Path::new(CONSULT_OUTPUT_ROOT).join(format!(
- "{timestamp}-{slug}-{}.json",
+ "{timestamp}-{slug}-{session_slug}-{}.json",
Uuid::new_v4()
))))
}
@@ -1270,7 +1274,7 @@ fn persist_consult_output(
result: &str,
envelope: &ClaudeJsonEnvelope,
) -> io::Result<PersistedConsultPath> {
- let path = PersistedConsultPath::new(request)?;
+ let path = PersistedConsultPath::new(request, envelope.session_id.as_deref())?;
let saved_at = OffsetDateTime::now_utc()
.format(&Rfc3339)
.map_err(|error| io::Error::other(error.to_string()))?;
diff --git a/crates/phone-opus/tests/mcp_hardening.rs b/crates/phone-opus/tests/mcp_hardening.rs
index f7ce125..f4a8a89 100644
--- a/crates/phone-opus/tests/mcp_hardening.rs
+++ b/crates/phone-opus/tests/mcp_hardening.rs
@@ -417,6 +417,7 @@ fn consult_can_resume_a_prior_session_with_read_only_toolset_and_requested_worki
"persisted output path",
)?;
assert!(persisted_output_path.starts_with("/tmp/phone_opus-consults/"));
+ assert!(persisted_output_path.contains(resumed_session));
let persisted_output = must(
fs::read_to_string(&persisted_output_path),
"read persisted consult output",
@@ -644,6 +645,7 @@ fn consult_can_run_in_background_and_be_polled() -> TestResult {
"background persisted output path",
)?;
assert!(persisted_output_path.starts_with("/tmp/phone_opus-consults/"));
+ assert!(persisted_output_path.contains("3fc69f58-7752-4d9d-a95d-19a217814b6a"));
let persisted_output = must(
fs::read_to_string(&persisted_output_path),
"read background persisted consult output",