cli, tui: syn jobs cancel, and c on the TUI's Jobs screen
Three daemon comments and a protocol doc told the reader to run syn jobs
cancel, which did not exist; the TUI's Jobs screen said it had no cancel
because the protocol had no command for one. The daemon's JobRunner
could always cancel. JobsCmd::Cancel { id } now asks it to (Write, the
reach that starts an import), syn jobs cancel <ID> sends it and says
what happened in copy::job_cancel's words, and c cancels the selected
job on the TUI's Active tab.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1409666a5e
commit
bc207e6bc4
8 files changed
+114
-20
No files matched your search
@@ -155,6 +155,6 @@ rediscovered as a bug:
|
||||
- The `(kind, subject)` dedup key is what made phase 3's scheduler (ADR
|
||||
0012) safe to add later without a redesign: a scheduler tick that lands on
|
||||
work already in flight defers to it instead of double-firing, for free.
|
||||
- TUI/CLI have a Jobs surface (`syn jobs list`/`syn jobs history`, and the
|
||||
TUI's Jobs screen). Dedup and cancel arrived there with the 2026-08-23 note
|
||||
- TUI/CLI have a Jobs surface (`syn jobs list`/`syn jobs history`/`syn jobs
|
||||
cancel`, and the TUI's Jobs screen, whose `c` cancels). Dedup and cancel arrived there with the 2026-08-23 note
|
||||
above; no-live-refresh is still true of the TUI, which polls on demand.
|
||||
@@ -4,6 +4,7 @@ use std::path::PathBuf;
|
||||
use syn_daemon::protocol::DocumentSort;
|
||||
use synchronicity::agents::{AgentId, AgentRegistry};
|
||||
use synchronicity::documents::DocumentID;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Bpaf, Debug)]
|
||||
#[bpaf(options, version, descr("Synchronicity - decentralized personal server"))]
|
||||
@@ -860,4 +861,12 @@ pub(crate) enum JobsCmd {
|
||||
#[bpaf(short('n'), long("number"), argument("N"), fallback(50u32))]
|
||||
limit: u32,
|
||||
},
|
||||
|
||||
/// Stop a running job; it stops at its next step and keeps what landed
|
||||
#[bpaf(command("cancel"))]
|
||||
Cancel {
|
||||
/// The job's id, as `syn jobs list` shows it
|
||||
#[bpaf(positional("ID"))]
|
||||
id: Uuid,
|
||||
},
|
||||
}
|
||||
@@ -1146,7 +1146,8 @@ fn handle_humans(store_path: &Path, sub: cli::HumansCmd) -> Result<()> {
|
||||
/// needed), so `client::query_store` runs it daemon-first, falling back to a
|
||||
/// direct store open when no daemon is running — same as `syn humans`.
|
||||
fn handle_jobs(store_path: &Path, sub: cli::JobsCmd) -> Result<()> {
|
||||
use syn_daemon::protocol::JobsSnapshot;
|
||||
use syn_daemon::protocol::{JobCancelSnapshot, JobsSnapshot};
|
||||
use synchronicity::copy::job_cancel;
|
||||
|
||||
match sub {
|
||||
cli::JobsCmd::List => {
|
||||
@@ -1163,6 +1164,23 @@ fn handle_jobs(store_path: &Path, sub: cli::JobsCmd) -> Result<()> {
|
||||
)?;
|
||||
println!("{}", commands::cmd_jobs_list(&snapshot.jobs, "No finished jobs yet."));
|
||||
}
|
||||
// Daemon-only: a job is stopped by the process running it, so with no
|
||||
// daemon there is nothing running to ask.
|
||||
cli::JobsCmd::Cancel { id } => {
|
||||
let snapshot: JobCancelSnapshot = syn_daemon::client::query_daemon_as(
|
||||
store_path,
|
||||
&DaemonCommand::Jobs(protocol::JobsCmd::Cancel { id }),
|
||||
)?;
|
||||
let id = id.to_string();
|
||||
println!(
|
||||
"{}",
|
||||
if snapshot.canceled {
|
||||
job_cancel::requested(&id)
|
||||
} else {
|
||||
job_cancel::not_running(&id)
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -900,6 +900,25 @@ pub mod job_state {
|
||||
}
|
||||
}
|
||||
|
||||
/// What `syn jobs cancel` says about the job it was asked to stop.
|
||||
pub mod job_cancel {
|
||||
use super::short_id;
|
||||
|
||||
/// The job was running and has been asked to stop. Work checks between
|
||||
/// steps, so it ends shortly rather than at once, and keeps what landed.
|
||||
pub fn requested(id: &str) -> String {
|
||||
format!(
|
||||
"Asked job {} to stop. It stops at its next step; whatever already landed stays.",
|
||||
short_id(id)
|
||||
)
|
||||
}
|
||||
|
||||
/// No job by that id is running in this daemon — finished, or never here.
|
||||
pub fn not_running(id: &str) -> String {
|
||||
format!("No job {} is running here. It may already have finished.", short_id(id))
|
||||
}
|
||||
}
|
||||
|
||||
/// An absolute timestamp for display: "Aug 22, 2026 15:24 PDT", or the same in
|
||||
/// UTC when no zone is given. The counterpart to [`format_last_seen`] for a
|
||||
/// moment read as a date rather than a relative presence, e.g. a job's start
|
||||
|
||||
@@ -42,13 +42,13 @@ use crate::protocol::{
|
||||
DaemonCommand, DeletedSnapshot, DocumentDetailSnapshot, DocumentItemRow, DocumentItemsSnapshot,
|
||||
DocumentListRow, DocumentListSnapshot, DocumentSort, EnsembleAddrSnapshot, EnsembleMemberPeer,
|
||||
EnsembleMembersSnapshot, EnsembleStatusSnapshot, EnsembleSyncSnapshot, EpochSnapshot,
|
||||
HumanAddArgs, HumanShowResult, HumansCmd, IdSnapshot, ImportEvent, ImportOutcome, JobSnapshot,
|
||||
JobsCmd, JobsSnapshot, LinkageCmd, LinkagesSnapshot, MaterializeSkippedRow,
|
||||
MaterializeSnapshot, MusicBuildSnapshot, MusicCmd, NeighborCountSnapshot, NodeInfoSnapshot,
|
||||
NodeNameSnapshot, NodePresenceRow, NoteCmd, NoteSnapshot, NotebookCmd, NotebooksSnapshot,
|
||||
PingSnapshot, PropertyRow, PurgeSnapshot, RenamedSnapshot, RetirementAttempt,
|
||||
RetirementOutcome, RetirementSnapshot, RevocationSnapshot, RevokedSnapshot, SearchSnapshot,
|
||||
StatusSnapshot, TimezoneSnapshot, UrlImportOutcome,
|
||||
HumanAddArgs, HumanShowResult, HumansCmd, IdSnapshot, ImportEvent, ImportOutcome,
|
||||
JobCancelSnapshot, JobSnapshot, JobsCmd, JobsSnapshot, LinkageCmd, LinkagesSnapshot,
|
||||
MaterializeSkippedRow, MaterializeSnapshot, MusicBuildSnapshot, MusicCmd,
|
||||
NeighborCountSnapshot, NodeInfoSnapshot, NodeNameSnapshot, NodePresenceRow, NoteCmd,
|
||||
NoteSnapshot, NotebookCmd, NotebooksSnapshot, PingSnapshot, PropertyRow, PurgeSnapshot,
|
||||
RenamedSnapshot, RetirementAttempt, RetirementOutcome, RetirementSnapshot, RevocationSnapshot,
|
||||
RevokedSnapshot, SearchSnapshot, StatusSnapshot, TimezoneSnapshot, UrlImportOutcome,
|
||||
};
|
||||
|
||||
/// Serialize a typed response body into the `Value` that
|
||||
@@ -1325,11 +1325,17 @@ pub async fn run(cmd: &DaemonCommand, cx: &Ctx<'_>) -> Result<Box<RawValue>> {
|
||||
.await?,
|
||||
)
|
||||
}
|
||||
DaemonCommand::Jobs(sub) => {
|
||||
let jobs = store.job_store.batch(|tx| match sub {
|
||||
JobsCmd::Active => store.job_store.list_active(tx),
|
||||
JobsCmd::History { limit } => store.job_store.list_history(tx, limit.unwrap_or(50)),
|
||||
})?;
|
||||
DaemonCommand::Jobs(JobsCmd::Cancel { id }) => {
|
||||
body(JobCancelSnapshot { canceled: job_runner.cancel(*id) })
|
||||
}
|
||||
DaemonCommand::Jobs(JobsCmd::Active) => {
|
||||
let jobs = store.job_store.batch(|tx| store.job_store.list_active(tx))?;
|
||||
body(jobs_snapshot(store, jobs))
|
||||
}
|
||||
DaemonCommand::Jobs(JobsCmd::History { limit }) => {
|
||||
let jobs = store
|
||||
.job_store
|
||||
.batch(|tx| store.job_store.list_history(tx, limit.unwrap_or(50)))?;
|
||||
body(jobs_snapshot(store, jobs))
|
||||
}
|
||||
DaemonCommand::Clipping(ClippingCmd::Capture { text, source_url, page_title }) => {
|
||||
|
||||
@@ -398,6 +398,9 @@ impl JobsCmd {
|
||||
fn required_capability(&self) -> Capability {
|
||||
match self {
|
||||
Self::Active | Self::History { .. } => Capability::Read,
|
||||
// Stopping work is changing what the store is about to hold —
|
||||
// the same reach as starting it, which an import needs `Write` for.
|
||||
Self::Cancel { .. } => Capability::Write,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -876,6 +879,19 @@ pub enum JobsCmd {
|
||||
/// Terminal jobs (done/failed/canceled), most recently finished first.
|
||||
/// `limit` defaults to 50 when omitted.
|
||||
History { limit: Option<u32> },
|
||||
/// Ask the job `id` to stop, as a [`JobCancelSnapshot`]. Only a job the
|
||||
/// daemon itself is running can be: a job is stopped by the process
|
||||
/// doing the work, which checks between steps — whatever already landed
|
||||
/// stays.
|
||||
Cancel { id: Uuid },
|
||||
}
|
||||
|
||||
/// Answer to [`JobsCmd::Cancel`].
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct JobCancelSnapshot {
|
||||
/// Whether the job was running here and has been asked to stop; `false`
|
||||
/// for one that has already finished or that this daemon never ran.
|
||||
pub canceled: bool,
|
||||
}
|
||||
|
||||
/// One row of `syn jobs list`/`syn jobs history` and the TUI's Jobs screen —
|
||||
|
||||
@@ -54,6 +54,7 @@ Documents agent
|
||||
|
||||
Jobs agent
|
||||
j/k, ↓/↑ move selection
|
||||
c cancel the selected active job (it stops at its next step)
|
||||
Shift+Tab switch between the Active and History tabs
|
||||
r refresh
|
||||
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
//! claimed at the app level for sidebar/content focus. Both tabs re-read when
|
||||
//! the app's [`ChangeWatcher`](crate::changes::ChangeWatcher) reports the
|
||||
//! `Jobs` channel moved, so live progress arrives without the user asking; `r`
|
||||
//! stays as the manual refresh. No cancel action yet: the daemon's protocol
|
||||
//! has no command for one, though the daemon now runs a `JobRunner` that
|
||||
//! could honor it.
|
||||
//! stays as the manual refresh. `c` cancels the selected active job: the
|
||||
//! daemon flags it, the work stops at its next step, and the row moving to
|
||||
//! History is the change watcher's to report, like any other.
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
@@ -23,7 +23,9 @@ use ratatui::{
|
||||
};
|
||||
|
||||
use syn_daemon::client;
|
||||
use syn_daemon::protocol::{DaemonCommand, JobSnapshot, JobsCmd as DaemonJobsCmd, JobsSnapshot};
|
||||
use syn_daemon::protocol::{
|
||||
DaemonCommand, JobCancelSnapshot, JobSnapshot, JobsCmd as DaemonJobsCmd, JobsSnapshot,
|
||||
};
|
||||
use synchronicity::copy::empty;
|
||||
|
||||
use crate::ui::{self, Screen};
|
||||
@@ -120,6 +122,24 @@ impl JobsScreen {
|
||||
}
|
||||
}
|
||||
|
||||
/// Ask the daemon to stop the selected job, on the Active tab. A job that
|
||||
/// finished in the meantime is not an error: the next reload shows where
|
||||
/// it ended up.
|
||||
fn cancel_selected(&mut self) -> Result<()> {
|
||||
if self.tab != JobsTab::Active {
|
||||
return Ok(());
|
||||
}
|
||||
let Some(job) = self.list_state.selected().and_then(|i| self.active.get(i)) else {
|
||||
return Ok(());
|
||||
};
|
||||
let id = job.id.parse()?;
|
||||
let _: JobCancelSnapshot = client::query_daemon_as(
|
||||
&self.store_path,
|
||||
&DaemonCommand::Jobs(DaemonJobsCmd::Cancel { id }),
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn step(&mut self, forward: bool) {
|
||||
let len = self.current_jobs().len();
|
||||
ui::step(&mut self.list_state, len, forward);
|
||||
@@ -137,6 +157,11 @@ impl Screen for JobsScreen {
|
||||
self.error = Some(format!("{e}"));
|
||||
}
|
||||
}
|
||||
KeyCode::Char('c') => {
|
||||
if let Err(e) = self.cancel_selected() {
|
||||
self.error = Some(format!("{e}"));
|
||||
}
|
||||
}
|
||||
KeyCode::BackTab => {
|
||||
self.tab = self.tab.toggled();
|
||||
self.list_state.select(Some(0));
|
||||
@@ -196,7 +221,7 @@ impl Screen for JobsScreen {
|
||||
|
||||
fn status_line(&self) -> (String, Style) {
|
||||
(
|
||||
"j/k: navigate Shift+Tab: switch tab r: refresh".to_string(),
|
||||
"j/k: navigate c: cancel Shift+Tab: switch tab r: refresh".to_string(),
|
||||
Style::default().fg(Color::DarkGray),
|
||||
)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user