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

Function current_plan

libatomic/src/review/incremental.rs:239–299  ·  view source on GitHub ↗
(
    repo: &Repository,
    store: Option<&SessionStore>,
    session_id: &str,
)

Source from the content-addressed store, hash-verified

237}
238
239fn current_plan(
240 repo: &Repository,
241 store: Option<&SessionStore>,
242 session_id: &str,
243) -> CliResult<Option<String>> {
244 let runtime = runtime_session(store, session_id)?;
245 let ledger = repo
246 .get_session_ledger(session_id)
247 .map_err(CliError::Repository)?;
248 if runtime.is_none() && ledger.is_none() {
249 return Err(invalid(format!(
250 "Unknown explicit session context: {session_id}"
251 )));
252 }
253 let mut keys = BTreeSet::new();
254 let runtime_active = runtime.as_ref().is_some_and(AgentSession::is_turn_active);
255 if let Some(runtime) = runtime {
256 if runtime.view_name != repo.current_view() {
257 return Err(invalid(
258 "Explicit session context belongs to a different view",
259 ));
260 }
261 if runtime.is_turn_active() {
262 let turn = runtime
263 .turn_count
264 .checked_add(1)
265 .ok_or_else(|| invalid("Turn overflow"))?;
266 if let Some(binding) = store
267 .map(|s| s.turn_intent_binding(session_id, turn))
268 .transpose()
269 .map_err(|e| CliError::Internal(e.into()))?
270 .flatten()
271 {
272 keys.insert(intent_key(repo, &binding.intent_uid)?);
273 }
274 if let Some(work_item) = runtime.managed_run.and_then(|run| run.work_item_id) {
275 keys.insert(intent_key(repo, &work_item)?);
276 }
277 }
278 }
279 if let Some((record, turns)) = ledger.filter(|_| !runtime_active) {
280 if record
281 .view_name
282 .as_deref()
283 .is_some_and(|view| view != repo.current_view())
284 {
285 return Err(invalid(
286 "Explicit session ledger belongs to a different view",
287 ));
288 }
289 for plan in turns.iter().filter_map(|turn| turn.plan_id.as_deref()) {
290 keys.insert(intent_key(repo, plan)?);
291 }
292 }
293 if keys.len() > 1 {
294 return Err(invalid(
295 "Ambiguous governing intent in explicit session context",
296 ));

Callers 1

resolve_with_sessionFunction · 0.85

Calls 14

runtime_sessionFunction · 0.85
intent_keyFunction · 0.85
get_session_ledgerMethod · 0.80
is_noneMethod · 0.80
as_refMethod · 0.80
is_turn_activeMethod · 0.80
turn_intent_bindingMethod · 0.80
invalidFunction · 0.70
current_viewMethod · 0.45
insertMethod · 0.45
iterMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected