@@ -735,9 +735,15 @@ pub struct App {
735735 pub minibuffer: Option<Minibuffer>,
736736 pub harnesses: Vec<HarnessInfo>,
737737 /// Program templates offered as clickable buttons in the empty-program
738- /// placeholder. Fetched at startup and on reload (same cadence as
739- /// `harnesses`); rarely changes within a session.
738+ /// placeholder. Fetched at startup and on reconnect, and refreshed in the
739+ /// background every time the program pane opens so edits to template files
740+ /// (or newly dropped files) appear on the next open without a daemon restart.
740741 pub program_templates: Vec<agentd_protocol::ProgramTemplate>,
742+ /// Background channel for live-reloaded program templates. `open_program_popup`
743+ /// spawns a non-blocking fetch that delivers the latest list here; the event
744+ /// loop applies it on the next iteration (no flicker — the placeholder keeps
745+ /// the cached list until the fresh one lands).
746+ pub program_templates_tx: mpsc::UnboundedSender<Vec<agentd_protocol::ProgramTemplate>>,
741747 pub theme: crate::theme::Theme,
742748 pub help_visible: bool,
743749 pub profile: Profile,
@@ -1459,7 +1465,7 @@ pub struct ProgramRun {
14591465 /// When Run was pressed. The shimmer wave is a function of elapsed time.
14601466 pub started_at: Instant,
14611467 /// Stable content-derived ids of blocks still pending (shimmering), per
1462- /// spec 0051 . A block shimmers while its id is in this set; the daemon
1468+ /// spec 0053 . A block shimmers while its id is in this set; the daemon
14631469 /// owns the set and publishes it, and clients map it back onto source lines
14641470 /// via the shared block parser.
14651471 pub pending: HashSet<String>,
@@ -1496,12 +1502,12 @@ impl ProgramRun {
14961502
14971503/// A program "block": a maximal run of consecutive non-blank Markdown lines,
14981504/// identified by its stable content-derived id. The unit of Run shimmer — a
1499- /// block shimmers as a whole and settles as a whole (specs 0042, 0051 ).
1505+ /// block shimmers as a whole and settles as a whole (specs 0042, 0053 ).
15001506pub(crate) struct ProgramBlock {
15011507 /// Source-line index range `[start_line, end_line)` into `markdown.lines()`.
15021508 pub start_line: usize,
15031509 pub end_line: usize,
1504- /// Stable content-derived block id (spec 0051 ) — what the shimmer set keys on.
1510+ /// Stable content-derived block id (spec 0053 ) — what the shimmer set keys on.
15051511 pub id: String,
15061512}
15071513
@@ -2122,6 +2128,8 @@ async fn run_with_socket_initial_selection(
21222128 let now = Instant::now();
21232129 let socket = client.socket_path().to_path_buf();
21242130 let (pty_input_tx, pty_input_errors) = spawn_pty_input_pump(client.clone());
2131+ // Placeholder sender; `run_loop` installs the live channel it actually drains.
2132+ let program_templates_tx = mpsc::unbounded_channel().0;
21252133 let mut app = App {
21262134 client: client.clone(),
21272135 last_reported_view: None,
@@ -2142,6 +2150,7 @@ async fn run_with_socket_initial_selection(
21422150 minibuffer: None,
21432151 harnesses,
21442152 program_templates,
2153+ program_templates_tx,
21452154 theme,
21462155 help_visible: false,
21472156 profile,
@@ -2361,6 +2370,12 @@ async fn run_loop(
23612370 .take_notifications()
23622371 .await
23632372 .context("notifications channel already taken")?;
2373+ // Live-reload channel for program templates. The sender lives on `app` so
2374+ // `open_program_popup` can kick off a background refresh; this loop drains the
2375+ // receiver and applies the freshest list.
2376+ let (program_templates_tx, mut program_templates_rx) =
2377+ mpsc::unbounded_channel::<Vec<agentd_protocol::ProgramTemplate>>();
2378+ app.program_templates_tx = program_templates_tx;
23642379 let mut reconnect: Option<ReconnectState> = None;
23652380 // Tick at the spinner frame boundary so each frame gets one redraw.
23662381 let mut tick = tokio::time::interval(Duration::from_millis(SPINNER_FRAME_MS as u64));
@@ -2778,6 +2793,20 @@ async fn run_loop(
27782793 }
27792794 }
27802795 }
2796+ templates = program_templates_rx.recv() => {
2797+ // Live-reloaded program templates from a background fetch
2798+ // (`refresh_program_templates`, kicked off when the program pane
2799+ // opens). Apply only the freshest value: drain any queued
2800+ // refreshes so a burst of opens collapses to the latest list.
2801+ if let Some(mut latest) = templates {
2802+ while let Ok(next) = program_templates_rx.try_recv() {
2803+ latest = next;
2804+ }
2805+ if !latest.is_empty() {
2806+ app.program_templates = latest;
2807+ }
2808+ }
2809+ }
27812810 _ = tick.tick() => {
27822811 if let Some((_, at)) = &app.status {
27832812 if at.elapsed() > Duration::from_secs(5) {
@@ -7306,13 +7335,32 @@ impl App {
73067335 self.program_popups.remove(&result.program.session_id);
73077336 self.program_popup = Some(program_popup_from_document(result.program, now));
73087337 self.set_status(format!("program opened at version {version}"));
7338+ // Live reload: the daemon re-reads the templates dir on every
7339+ // call, but the client caches the list. Kick off a non-blocking
7340+ // refresh on open so edits / new template files surface in the
7341+ // empty-state placeholder without a daemon restart.
7342+ self.refresh_program_templates();
73097343 }
73107344 Err(e) => {
73117345 self.set_status(format!("program get failed: {e}"));
73127346 }
73137347 }
73147348 }
73157349
7350+ /// Fetch program templates from the daemon in the background and deliver them
7351+ /// to the event loop via `program_templates_tx`. Non-blocking: the program
7352+ /// opens immediately against the cached list and swaps to the fresh one when
7353+ /// it lands, so there's no flicker and a slow daemon never stalls the open.
7354+ fn refresh_program_templates(&self) {
7355+ let client = self.client.clone();
7356+ let tx = self.program_templates_tx.clone();
7357+ tokio::spawn(async move {
7358+ if let Ok(result) = client.program_templates().await {
7359+ let _ = tx.send(result.templates);
7360+ }
7361+ });
7362+ }
7363+
73167364 async fn toggle_program_popup(&mut self) {
73177365 if self.program_popup.is_some() {
73187366 self.close_program_popup().await;
@@ -7449,7 +7497,7 @@ impl App {
74497497 template_id: popup.program.template_id.clone(),
74507498 note: None,
74517499 // Human co-edit save: no shimmer declaration — the daemon
7452- // narrows the active run by content change only (spec 0051 ).
7500+ // narrows the active run by content change only (spec 0053 ).
74537501 shimmer: None,
74547502 };
74557503 match self.client.program_update(params).await {
@@ -11765,6 +11813,7 @@ mod tests {
1176511813 minibuffer: None,
1176611814 harnesses: Vec::new(),
1176711815 program_templates: Vec::new(),
11816+ program_templates_tx: mpsc::unbounded_channel().0,
1176811817 theme: crate::theme::Theme::default(),
1176911818 help_visible: false,
1177011819 profile: Profile::Emacs,
0 commit comments