MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / work_start_session

Function work_start_session

atomic-cli/src/commands/intent/update.rs:156–188  ·  view source on GitHub ↗

Resolve only context supplied by this invocation. Never choose a session by recency, process-global hook state, or a scan of active sessions.

(
    explicit: Option<&str>,
    environment: impl Fn(&str) -> CliResult<Option<String>>,
)

Source from the content-addressed store, hash-verified

154/// Resolve only context supplied by this invocation. Never choose a session by
155/// recency, process-global hook state, or a scan of active sessions.
156fn work_start_session(
157 explicit: Option<&str>,
158 environment: impl Fn(&str) -> CliResult<Option<String>>,
159) -> CliResult<Option<String>> {
160 let checked = |source: &str, value: &str| {
161 if value.trim().is_empty() || value.trim() != value {
162 Err(CliError::InvalidArgument {
163 message: format!(
164 "{source} must name a nonempty session ID without surrounding whitespace"
165 ),
166 })
167 } else {
168 Ok(value.to_string())
169 }
170 };
171 // A deliberate selection overrides ambient context, including stale host
172 // variables inherited by nested tools. The store still validates the turn.
173 if let Some(session) = explicit {
174 return checked("--session-id", session).map(Some);
175 }
176 let atomic = environment("ATOMIC_SESSION_ID")?
177 .map(|value| checked("ATOMIC_SESSION_ID", &value))
178 .transpose()?;
179 if let Some(session) = atomic {
180 return Ok(Some(session));
181 }
182 if environment("ATOMIC_AGENT")?.is_some_and(|agent| !agent.trim().is_empty()) {
183 return Err(CliError::InvalidArgument {
184 message: "agent work start has no session context; pass --session-id or provide ATOMIC_SESSION_ID. The agent integration must forward the current session_id. No intent status or governing link was changed".into(),
185 });
186 }
187 Ok(None)
188}
189
190#[cfg(test)]
191mod tests {

Callers 2

bind_work_startMethod · 0.85
resolveFunction · 0.85

Calls 2

checkedFunction · 0.85
is_emptyMethod · 0.45

Tested by

no test coverage detected