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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE IF EXISTS schedule_agent_sessions;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- Scheduling conversations are independent of workflow authoring sessions.
CREATE TABLE schedule_agent_sessions (
workspace_id TEXT NOT NULL,
id TEXT NOT NULL,
state_json TEXT NOT NULL,
updated_at TEXT NOT NULL,
PRIMARY KEY (workspace_id, id)
);
CREATE INDEX idx_schedule_agent_sessions_updated ON schedule_agent_sessions(workspace_id, updated_at DESC);
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ALTER TABLE schedules DROP COLUMN finish_reason;
ALTER TABLE schedules DROP COLUMN finished_at;
ALTER TABLE schedules DROP COLUMN run_at;
ALTER TABLE schedules DROP COLUMN schedule_kind;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ALTER TABLE schedules ADD COLUMN schedule_kind TEXT NOT NULL DEFAULT 'recurring' CHECK (schedule_kind IN ('recurring','once'));
ALTER TABLE schedules ADD COLUMN run_at TEXT;
ALTER TABLE schedules ADD COLUMN finished_at TEXT;
ALTER TABLE schedules ADD COLUMN finish_reason TEXT CHECK (finish_reason IN ('triggered','missed','skipped','failed'));
2 changes: 2 additions & 0 deletions apps/desktop/src-tauri/src/cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,5 @@ impl<T, E: std::fmt::Display> StringifyErr<T> for Result<T, E> {
})
}
}

pub mod schedule_agent;
7 changes: 7 additions & 0 deletions apps/desktop/src-tauri/src/cmd/model_usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ pub async fn model_usage_session(kind: String, id: String) -> CmdResult<Value> {
.fetch_one(&pool)
.await?
},
"schedule_agent" => {
sqlx::query_scalar("SELECT EXISTS(SELECT 1 FROM schedule_agent_sessions WHERE workspace_id=? AND id=?)")
.bind(&workspace)
.bind(&id)
.fetch_one(&pool)
.await?
},
_ => anyhow::bail!("Unknown session kind"),
};
anyhow::ensure!(exists, "Session not found in this workspace");
Expand Down
10 changes: 10 additions & 0 deletions apps/desktop/src-tauri/src/cmd/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ use crate::{
cmd::{CmdResult, StringifyErr},
module::schedule::{AppScheduleRequest, ScheduleStore, ScheduleSummary, WorkflowScheduleRequest},
};
use serde_json::Value;

#[tauri::command]
pub async fn schedule_update(change: Value, team_token: Option<String>) -> CmdResult<Value> {
crate::module::schedule_agent::ScheduleTaskManager::active()
.stringify_err()?
.update(change, team_token.as_deref())
.await
.stringify_err()
}

#[tauri::command]
pub async fn schedule_set_team_session(server_url: String, token: Option<String>) {
Expand Down
103 changes: 103 additions & 0 deletions apps/desktop/src-tauri/src/cmd/schedule_agent.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
//! Commands for the independent task center and scheduling conversations.
use super::{CmdResult, StringifyErr};
use crate::module::schedule_agent::{ScheduleAgent, ScheduleModelSelection, Turn};
use serde_json::Value;
use tauri::ipc::Channel;
#[tauri::command]
pub async fn schedule_list() -> CmdResult<Value> {
ScheduleAgent::active()
.stringify_err()?
.list_tasks()
.await
.stringify_err()
}
#[tauri::command]
pub async fn schedule_detail(id: String) -> CmdResult<Value> {
ScheduleAgent::active()
.stringify_err()?
.task_detail(&id)
.await
.stringify_err()
}
#[tauri::command]
pub async fn schedule_agent_create(
schedule_id: Option<String>,
selection: Option<ScheduleModelSelection>,
) -> CmdResult<Value> {
ScheduleAgent::active()
.stringify_err()?
.create(schedule_id, selection)
.await
.stringify_err()
}
#[tauri::command]
pub async fn schedule_agent_get(id: String) -> CmdResult<Value> {
ScheduleAgent::active().stringify_err()?.get(&id).await.stringify_err()
}
#[tauri::command]
pub async fn schedule_agent_list() -> CmdResult<Value> {
ScheduleAgent::active()
.stringify_err()?
.sessions()
.await
.stringify_err()
}
#[tauri::command]
pub async fn schedule_agent_turn(request: Turn, channel: Channel<Value>) -> CmdResult<Value> {
ScheduleAgent::active()
.stringify_err()?
.turn(request, channel)
.await
.stringify_err()
}
#[tauri::command]
pub fn schedule_agent_stop(id: String) -> CmdResult {
ScheduleAgent::active().map(|agent| agent.stop(&id)).stringify_err()
}
#[tauri::command]
pub async fn schedule_agent_propose(session_id: String, args: Value, team_token: Option<String>) -> CmdResult<Value> {
ScheduleAgent::active()
.stringify_err()?
.propose(&session_id, args, team_token.as_deref())
.await
.stringify_err()
}
#[tauri::command]
pub async fn schedule_agent_decide(
session_id: String,
proposal_id: String,
approve: bool,
team_token: Option<String>,
) -> CmdResult<Value> {
ScheduleAgent::active()
.stringify_err()?
.decide(&session_id, &proposal_id, approve, team_token.as_deref())
.await
.stringify_err()
}
#[tauri::command]
pub async fn schedule_agent_reply_receipt(session_id: String, channel: Channel<Value>) -> CmdResult<Value> {
ScheduleAgent::active()
.stringify_err()?
.reply_receipt(&session_id, channel)
.await
.stringify_err()
}

#[tauri::command]
pub async fn schedule_agent_delete(id: String) -> CmdResult {
ScheduleAgent::active()
.stringify_err()?
.delete_session(&id)
.await
.stringify_err()
}

#[tauri::command]
pub async fn schedule_agent_set_model(session_id: String, selection: ScheduleModelSelection) -> CmdResult<Value> {
ScheduleAgent::active()
.stringify_err()?
.set_model(&session_id, selection)
.await
.stringify_err()
}
40 changes: 39 additions & 1 deletion apps/desktop/src-tauri/src/core/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,27 @@ mod tests {
.unwrap();
assert_eq!(
versions,
vec![20260904083536, 20261005100000, 20261016100000, 20261027100000]
vec![
20260904083536,
20261005100000,
20261016100000,
20261027100000,
20261104100000,
20261104110000
]
);
assert!(
sqlx::query("SELECT state_json FROM schedule_agent_sessions")
.fetch_all(&pool)
.await
.unwrap()
.is_empty()
);
assert!(
sqlx::query("SELECT schedule_kind,run_at,finished_at,finish_reason FROM schedules")
.fetch_all(&pool)
.await
.is_ok()
);
assert!(
sqlx::query("SELECT state_json,title,model_id,status,created_at FROM assistant_sessions")
Expand All @@ -129,6 +149,18 @@ mod tests {
.is_empty()
);
migrator.undo(&pool, 20261005100000).await.unwrap();
assert!(
sqlx::query("SELECT * FROM schedule_agent_sessions")
.fetch_all(&pool)
.await
.is_err()
);
assert!(
sqlx::query("SELECT schedule_kind FROM schedules")
.fetch_all(&pool)
.await
.is_err()
);
assert!(
sqlx::query("SELECT * FROM assistant_sessions")
.fetch_all(&pool)
Expand All @@ -137,6 +169,12 @@ mod tests {
);
assert!(sqlx::query("SELECT * FROM run_records").fetch_all(&pool).await.is_ok());
migrator.run(&pool).await.unwrap();
assert!(
sqlx::query("SELECT schedule_kind,run_at,finished_at,finish_reason FROM schedules")
.fetch_all(&pool)
.await
.is_ok()
);
assert!(
sqlx::query("SELECT * FROM assistant_messages")
.fetch_all(&pool)
Expand Down
13 changes: 13 additions & 0 deletions apps/desktop/src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,19 @@ pub fn run() {
cmd::schedule::workflow_schedule_save,
cmd::schedule::schedule_set_enabled,
cmd::schedule::schedule_delete,
cmd::schedule::schedule_update,
cmd::schedule_agent::schedule_list,
cmd::schedule_agent::schedule_detail,
cmd::schedule_agent::schedule_agent_create,
cmd::schedule_agent::schedule_agent_set_model,
cmd::schedule_agent::schedule_agent_get,
cmd::schedule_agent::schedule_agent_list,
cmd::schedule_agent::schedule_agent_turn,
cmd::schedule_agent::schedule_agent_stop,
cmd::schedule_agent::schedule_agent_propose,
cmd::schedule_agent::schedule_agent_decide,
cmd::schedule_agent::schedule_agent_reply_receipt,
cmd::schedule_agent::schedule_agent_delete,
// workflow
cmd::workflow::workflow_compile,
cmd::workflow::workflow_run,
Expand Down
16 changes: 16 additions & 0 deletions apps/desktop/src-tauri/src/module/assistant/catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,22 @@ impl Catalog {
workspace_id: dirs::active_workspace_id(),
})
}
#[cfg(test)]
pub(crate) fn empty_scheduling_catalog() -> Self {
Self {
workflows: vec![],
team: None,
root: std::path::PathBuf::new(),
workspace_id: dirs::active_workspace_id(),
}
}

/// Read-only catalog access shared with the independent scheduling agent.
pub async fn schedule_targets(&self, args: &Value) -> Result<Value> {
use super::tools::WorkflowDiscovery;
self.list_capabilities(args).await
}

pub fn capabilities(&self) -> Vec<Capability> {
self.workflows.iter().filter_map(capability).collect()
}
Expand Down
3 changes: 3 additions & 0 deletions apps/desktop/src-tauri/src/module/assistant/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,6 @@ mod planning_tests;

#[cfg(test)]
mod lifecycle_tests;

// Provider transport only; scheduling owns its own instructions, tools and sessions.
pub(crate) use model::{content_text as agent_text, generate as generate_agent_stream, instructed as agent_contents};
8 changes: 4 additions & 4 deletions apps/desktop/src-tauri/src/module/assistant/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use adk_rust::prelude::{Content, Llm, LlmRequest, Part};
use anyhow::Result;
use futures::StreamExt;

pub(super) fn content_text(content: &Content) -> String {
pub(crate) fn content_text(content: &Content) -> String {
content
.parts
.iter()
Expand All @@ -17,7 +17,7 @@ pub(super) fn content_text(content: &Content) -> String {
}

/// Tool-round narration is progress, not a prefix of the eventual answer.
pub(super) async fn generate_answer(
pub(crate) async fn generate_answer(
model: &dyn Llm,
request: LlmRequest,
emit: &(dyn Fn(AssistantStreamEvent) -> Result<()> + Send + Sync),
Expand All @@ -44,7 +44,7 @@ pub(super) async fn generate_answer(
Ok(content)
}

pub(super) fn instructed(provider: &ModelProvider, instruction: &str, history: &[Content]) -> Vec<Content> {
pub(crate) fn instructed(provider: &ModelProvider, instruction: &str, history: &[Content]) -> Vec<Content> {
// ADK 2.3 Gemini ignores role=system entirely. Its own LlmAgent uses a user
// preamble. Keep that compatibility at this boundary, not in saved history.
let role = if *provider == ModelProvider::Gemini {
Expand All @@ -57,7 +57,7 @@ pub(super) fn instructed(provider: &ModelProvider, instruction: &str, history: &
contents
}

pub(super) async fn generate(
pub(crate) async fn generate(
model: &dyn Llm,
mut request: LlmRequest,
emit: &(dyn Fn(AssistantStreamEvent) -> Result<()> + Send + Sync),
Expand Down
2 changes: 2 additions & 0 deletions apps/desktop/src-tauri/src/module/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ pub mod skill;
pub mod state;
pub mod tool_registry;
pub mod workflow;

pub mod schedule_agent;
2 changes: 1 addition & 1 deletion apps/desktop/src-tauri/src/module/model_usage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ workflow dispatch persists its origin in native runtime metadata before queuing;
recovery retains that origin, while a new manual replay clears it. Memory summaries
belong to the conversation, not a workflow model node.

`model_usage_session(kind, id)` accepts `assistant` or `workflow_chat`, verifies the
`model_usage_session(kind, id)` accepts `assistant`, `workflow_chat`, or `schedule_agent`, verifies the
session belongs to the active workspace, and returns known subtotals, coverage,
purpose groups, and call details. Execution is a separate subtotal, identified by
runId. Native historical receipts can link imported runs without duplicating calls.
Expand Down
5 changes: 4 additions & 1 deletion apps/desktop/src-tauri/src/module/model_usage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,10 @@ async fn observe_with_writer(

/// All numbers are known subtotals. Completeness is separate from request success.
pub async fn session_usage(pool: &SqlitePool, workspace: &str, kind: &str, id: &str) -> anyhow::Result<Value> {
anyhow::ensure!(matches!(kind, "assistant" | "workflow_chat"), "Unknown session kind");
anyhow::ensure!(
matches!(kind, "assistant" | "workflow_chat" | "schedule_agent"),
"Unknown session kind"
);
// Native run receipts also link imported history. OR keeps a call unique
// when both the new origin metadata and an old receipt identify the run.
let rows = sqlx::query("SELECT record_json FROM model_calls WHERE workspace_id=? AND ((session_kind=? AND session_id=?) OR (?='assistant' AND run_id IN (SELECT run_id FROM assistant_messages WHERE workspace_id=? AND session_id=? UNION SELECT active_run_id FROM assistant_sessions WHERE workspace_id=? AND id=?))) ORDER BY started_at,id")
Expand Down
38 changes: 38 additions & 0 deletions apps/desktop/src-tauri/src/module/model_usage/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,3 +582,41 @@ async fn fingerprints_compare_origins_and_detect_request_changes_without_changin
"exactly one provider call per invocation"
);
}

#[tokio::test]
async fn scheduling_usage_is_isolated_by_workspace_session_and_kind() {
let pool = database().await;
let writer = Writer::new(pool.clone());
let model = Model(vec![chunk(10, 5, false)]);
let mut scheduling = context();
scheduling.session_kind = Some("schedule_agent".into());
scheduling.purpose = "schedule_agent".into();
let (_, mut stream) = observe_with_writer(
&model,
LlmRequest::new("test", vec![]),
true,
scheduling,
Some(writer.clone()),
)
.await
.unwrap();
while stream.next().await.is_some() {}
let result = snapshot(&pool, &writer, "personal", "schedule_agent", "session")
.await
.unwrap();
assert_eq!(result["conversation"]["totalTokens"], 15);
assert_eq!(result["execution"]["totalTokens"], 0);
assert_eq!(result["byPurpose"][0]["purpose"], "schedule_agent");
for (workspace, kind, id) in [
("other", "schedule_agent", "session"),
("personal", "schedule_agent", "other"),
("personal", "assistant", "session"),
] {
assert!(
snapshot(&pool, &writer, workspace, kind, id).await.unwrap()["calls"]
.as_array()
.unwrap()
.is_empty()
);
}
}
Loading
Loading