Skip to content
Closed
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions crates/cccc-daemon/src/ops/actor_delivery_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ pub(super) fn process_batch_tracked(
}
let events = jobs.iter().map(|job| job.event.clone()).collect::<Vec<_>>();
if crate::ops::local_headless::held_batch(&events, chrono::Utc::now())
&& !crate::ops::working_state::antigravity_hook_idle_for_status(
&& !crate::ops::agent_status::turn_ended_for_session(
&job.home,
&current_group.group_id,
&current_actor.id,
Expand Down Expand Up @@ -374,7 +374,7 @@ pub(super) fn process_batch_tracked(
// Recheck immediately before writing: startup input-mode / settle waits can
// span seconds during which PreInvocation may transition the Actor to working.
if crate::ops::local_headless::held_batch(&events, chrono::Utc::now())
&& !crate::ops::working_state::antigravity_hook_idle_for_status(
&& !crate::ops::agent_status::turn_ended_for_session(
&job.home,
&current_group.group_id,
&current_actor.id,
Expand Down Expand Up @@ -435,7 +435,7 @@ fn process_owned_pty_batch(
) -> BatchOutcome {
let events = jobs.iter().map(|job| job.event.clone()).collect::<Vec<_>>();
if crate::ops::local_headless::held_batch(&events, chrono::Utc::now())
&& !crate::ops::working_state::antigravity_hook_idle_for_status(
&& !crate::ops::agent_status::turn_ended_for_session(
home,
&group.group_id,
&actor.id,
Expand Down
84 changes: 84 additions & 0 deletions crates/cccc-daemon/src/ops/agent_status/antigravity_hook.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
//! Antigravity native lifecycle hooks bound to one PTY launch.

use super::{AgentState, AgentStatus, StatusSource};
use crate::session_owner::runtime as cccc_runtime;
use cccc_contracts::ActorRuntime;
use cccc_core::HomeLayout;
use cccc_core::antigravity_hook::HookState;

fn launched_runtime(
group_id: &str,
actor_id: &str,
session: &cccc_runtime::SessionStatus,
) -> Option<ActorRuntime> {
#[cfg(unix)]
let launch = crate::session_owner::snapshot(group_id, actor_id)
.ok()
.flatten()
.and_then(|snapshot| snapshot.terminal_launch)
.or(session.launch);
#[cfg(not(unix))]
let launch = {
let _ = (group_id, actor_id);
session.launch
};
launch.map(|launch| launch.runtime)
}

fn live_state(
home: &HomeLayout,
group_id: &str,
actor_id: &str,
session: &cccc_runtime::SessionStatus,
) -> Option<HookState> {
cccc_core::antigravity_hook::read_live_state(
home,
group_id,
actor_id,
session.pid,
&session.started_at,
)
}

/// The hook state of a running Antigravity PTY. With a configured runtime,
/// either that configuration or the actual launch must be Antigravity.
pub(super) fn status(
home: &HomeLayout,
group_id: &str,
actor_id: &str,
configured_runtime: Option<ActorRuntime>,
) -> Option<AgentStatus> {
let session = cccc_runtime::status(group_id, actor_id).ok()?;
if !session.running {
return None;
}
let launched = launched_runtime(group_id, actor_id, &session);
if launched.is_some_and(|runtime| runtime != ActorRuntime::Antigravity) {
return None;
}
if let Some(configured) = configured_runtime
&& configured != ActorRuntime::Antigravity
&& launched != Some(ActorRuntime::Antigravity)
{
return None;
}
let hook = live_state(home, group_id, actor_id, &session)?;
let mut status = AgentStatus::new(
AgentState::parse(&hook.status),
"antigravity_hook",
StatusSource::AntigravityHook,
);
status.turn_ended = hook.status == "idle";
status.updated_at = Some(hook.updated_at);
Some(status)
}

/// Whether that launch's hooks report idle; `None` without a hook binding.
pub(super) fn turn_ended_for_session(
home: &HomeLayout,
group_id: &str,
actor_id: &str,
session: &cccc_runtime::SessionStatus,
) -> Option<bool> {
live_state(home, group_id, actor_id, session).map(|hook| hook.status == "idle")
}
34 changes: 34 additions & 0 deletions crates/cccc-daemon/src/ops/agent_status/dots.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//! ChatGPT Dots event turns.

use super::{AgentState, AgentStatus, StatusSource};
use cccc_contracts::{Actor, ActorRuntime};
use cccc_core::HomeLayout;

pub(super) fn status(home: &HomeLayout, group_id: &str, actor: &Actor) -> Option<AgentStatus> {
if actor.runtime != ActorRuntime::ChatgptDots {
return None;
}
let Ok(runtime) = crate::ops::runtime_state::actor_state(home, group_id, &actor.id) else {
return Some(AgentStatus::new(
AgentState::Waiting,
"dots_state_unavailable",
StatusSource::Dots,
));
};
let active_turn = runtime["active_turn_id"]
.as_str()
.filter(|id| !id.is_empty())
.map(str::to_owned);
let mut status = AgentStatus::new(
if active_turn.is_some() {
AgentState::Working
} else {
AgentState::Waiting
},
"dots_event_turn",
StatusSource::Dots,
);
status.updated_at = runtime["updated_at"].as_str().map(str::to_owned);
status.active_task_id = active_turn;
Some(status)
}
40 changes: 40 additions & 0 deletions crates/cccc-daemon/src/ops/agent_status/managed.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//! Managed agent sessions (CCCC-hosted app-server, ACP or RPC sessions).

use super::{AgentState, AgentStatus, StatusSource};
use cccc_contracts::Actor;

/// The live managed session's own state, or its pending registration.
pub(super) fn live(group_id: &str, actor_id: &str, pty: bool) -> Option<AgentStatus> {
if let Some(local) = crate::ops::local_headless::status(group_id, actor_id) {
let reason = local.reason.unwrap_or_else(|| {
if pty {
"managed_agent_session".to_owned()
} else {
"provider_headless_session".to_owned()
}
});
let mut status = AgentStatus::new(
AgentState::parse(&local.status),
&reason,
StatusSource::ManagedSession,
);
status.updated_at = Some(local.updated_at);
status.active_task_id = local.task_id;
return Some(status);
}
crate::ops::local_headless::running(group_id, actor_id).then(pending)
}

/// An Actor configured for a managed session whose session has not
/// registered yet.
pub(super) fn configured_pending(actor: &Actor) -> Option<AgentStatus> {
crate::ops::local_headless::uses_managed_session(actor).then(pending)
}

fn pending() -> AgentStatus {
AgentStatus::new(
AgentState::Waiting,
"managed_agent_session_pending",
StatusSource::ManagedSession,
)
}
Loading
Loading