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
12 changes: 12 additions & 0 deletions docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ The shell decodes it strictly: one string value it does not know fails the whole
The string enums the core serializes into the snapshot are therefore pinned in `contracts/snapshot-wire-enums.json`; `model.rs` tests that each variant emits the listed value and `SnapshotWireEnumTests` that each listed value decodes, so a variant added on one side fails a suite before it can reach a running shell (a `PullRequestTitle` origin once shipped as `pull_request_title` against a shell that read `pr_title`).
The bridge publishes `bridgeError` only on change and names the coding path in it, because a repeated failure republished every notification rebuilt every view observing the bridge at the notification rate.

## Stored primary checkout

A local registered project stores `primary_checkout_id` on its `WorkspaceRegistration` in `core-state.json`.
An absent choice keeps the root default for existing registrations; a stored choice remains stored while its checkout is unavailable.
The single `set_primary_checkout` event carries `{workspace_id, checkout_id}` and accepts only an existing checkout of that registered local Git project.
Missing projects or checkouts, plain folders and remote registrations are refused with a diagnostic, without changing the selection or presenting an alert.
The catalog projects `CheckoutSnapshot.is_primary` after assigning registration identities and adding Git worktrees; sorting and inactive folding consume that flag, and the web reads it for the house glyph rather than comparing paths.
A change updates the accepted catalog immediately, so stale worker results cannot restore the old choice, then uses the existing coalesced off-lock UI save.
An unchanged choice publishes and saves nothing; there is no additional worker, subprocess, timer or queue.
Checkout fields remain in the hand-maintained `web/src/snapshot.ts` shape; the WebSocket frame generator does not generate this part of the core snapshot.
SSH catalogs currently read Herdr and the device helper, not another hided core's registrations, so they retain the remote root default and do not synchronize a primary choice stored by another daemon.

## Project sessions and Memory

`hide-project` is the single durable identity boundary for session discovery, Memory storage, core projection, and hook retrieval.
Expand Down
6 changes: 5 additions & 1 deletion docs/UI_BEHAVIOR.md
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,11 @@ Core owner: `herdr-core/src/sidebar.rs`, `herdr-core/src/project_context.rs`, `h

The sidebar hierarchy is Project > Workspace > Agents; a Workspace corresponds to one checkout path, including a plain folder.
Two checkouts of one repository share a project cycle.
Each checkout row shows a kind glyph, selected in priority order: the pull-request lifecycle icon when current GitHub data has a pull request, then branch, home for the primary checkout, commit for detached HEAD, or folder for a plain folder.
Each checkout row shows a kind glyph: home for the stored primary checkout, otherwise the pull-request lifecycle icon when current GitHub data has a pull request, then branch, commit for detached HEAD, or folder for a plain folder.
The primary choice belongs to the registered project and survives restart; a registration without a choice defaults to its root checkout.
Changing it moves the home glyph and first position together without moving focus; a vanished choice stays stored and is marked again when that checkout returns.
There is no setting menu for this choice yet; remote projects are read-only for this action.
Remote catalogs still derive home from Git-root facts and do not yet display the primary checkout stored by the remote core.
Open, draft, merged, and closed pull requests keep their own lifecycle shapes and colors, stale GitHub data mutes only the icon, an unavailable GitHub lookup falls back to the branch glyph, and a missing folder colors its branch glyph as danger and omits the age.
In the web shell every row reads on the left and ends the same way on the right: its time or its status badge, then a fold slot kept at rest, so nothing moves when a control shows and the times and badges of project, checkout and agent rows end on one column while their chevrons stand on another.
A folded chevron is always shown; an unfolded one shows under the pointer, while focus is inside the row, while its menu is open, and always on an input with no hover.
Expand Down
3 changes: 3 additions & 0 deletions herdr-core/src/device_catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ pub(crate) fn group(
path: checkout_root,
branch: facts.branch.clone(),
is_worktree: facts.linked_worktree,
is_primary: !facts.linked_worktree && facts.kind == ProjectKind::Git,
exists: true,
has_panes: !tabs.is_empty(),
purpose: if index == 0 {
Expand Down Expand Up @@ -393,6 +394,8 @@ pub(crate) fn apply_registrations(
path: registration.path.clone(),
branch,
exists: true,
is_primary: known
.is_some_and(|facts| facts.kind == ProjectKind::Git && !facts.linked_worktree),
..CheckoutSnapshot::default()
}],
inactive_checkouts: Default::default(),
Expand Down
5 changes: 5 additions & 0 deletions herdr-core/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,8 @@ pub struct CheckoutSnapshot {
/// description, representative agent title, pull-request title.
pub purpose: Option<CheckoutPurposeSnapshot>,
pub is_worktree: bool,
/// The core-owned home choice, independent of the Git main worktree.
pub is_primary: bool,
pub exists: bool,
pub temporary: bool,
/// Whether Herdr has a pane here. A worktree earns a row from git rather
Expand Down Expand Up @@ -2090,6 +2092,9 @@ impl Default for UiStateSnapshot {

#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
pub struct WorkspaceRegistration {
/// None preserves the root default for registrations written before this choice existed.
#[serde(default)]
pub primary_checkout_id: Option<String>,
pub id: String,
pub label: String,
pub path: String,
Expand Down
1 change: 1 addition & 0 deletions herdr-core/src/persistence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,7 @@ mod tests {
let path = root.join("state.json");
let state = UiStateSnapshot {
workspace_registrations: vec![WorkspaceRegistration {
primary_checkout_id: None,
id: "workspace:alpha".to_owned(),
label: "Alpha".to_owned(),
path: "/repo/alpha".to_owned(),
Expand Down
14 changes: 5 additions & 9 deletions herdr-core/src/project_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ pub(crate) fn sort_projects(
// The primary checkout leads its project whatever its activity: it is
// the one checkout that never folds, so the list starts at the same
// place every time. The rest follow by activity.
let project_path = project.path.clone();
project.checkouts.sort_by(|left, right| {
is_primary(right, &project_path)
.cmp(&is_primary(left, &project_path))
right
.is_primary
.cmp(&left.is_primary)
.then_with(|| keys[&right.id].cmp(&keys[&left.id]))
.then_with(|| left.id.cmp(&right.id))
});
Expand Down Expand Up @@ -111,11 +111,6 @@ pub(crate) fn sort_projects(
})
}

/// The checkout that is the project's own folder rather than a linked worktree.
fn is_primary(checkout: &CheckoutSnapshot, project_path: &str) -> bool {
!checkout.is_worktree && checkout.path == project_path
}

fn checkout_has_live_exception(
checkout: &CheckoutSnapshot,
focused_checkout_id: Option<&str>,
Expand Down Expand Up @@ -191,7 +186,7 @@ pub(crate) fn refresh_inactive_groups(
.checkouts
.iter()
.filter(|checkout| {
!is_primary(checkout, &workspace.path)
!checkout.is_primary
&& checkout_is_inactive(checkout, &by_pane, focused_checkout_id, now_unix_ms)
})
.map(|checkout| checkout.id.clone())
Expand Down Expand Up @@ -327,6 +322,7 @@ mod tests {
) -> CheckoutSnapshot {
CheckoutSnapshot {
id: id.to_owned(),
is_primary: true,
worktree: last_commit_unix_seconds.map(|seconds| WorktreeSnapshot {
last_commit_unix_seconds: Some(seconds),
..Default::default()
Expand Down
1 change: 1 addition & 0 deletions herdr-core/src/runtime/device_catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@ impl Runtime {
.ui_state
.workspace_registrations
.push(crate::model::WorkspaceRegistration {
primary_checkout_id: None,
id: id.clone(),
label,
path: registrable.root,
Expand Down
9 changes: 9 additions & 0 deletions herdr-core/src/runtime/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ pub(super) struct RemoveWorkspacePayload {
pub(super) workspace_id: String,
}

#[derive(Debug, Deserialize)]
pub(super) struct SetPrimaryCheckoutPayload {
pub workspace_id: String,
pub checkout_id: String,
}

#[derive(Debug, Deserialize)]
pub(super) struct WorkspacePinSetPayload {
pub(super) workspace_id: String,
Expand Down Expand Up @@ -891,6 +897,7 @@ pub(super) enum Event {
InactiveCheckoutsToggle(InactiveCheckoutsTogglePayload),
InactiveProjectsToggle(InactiveProjectsTogglePayload),
WorkspacePinSet(WorkspacePinSetPayload),
SetPrimaryCheckout(SetPrimaryCheckoutPayload),
RemoveWorkspace(RemoveWorkspacePayload),
RegisterDevice(RegisterDevicePayload),
DeviceHostConsent(DeviceHostConsentPayload),
Expand Down Expand Up @@ -1055,6 +1062,7 @@ pub(super) fn validate_event(event: EventEnvelope) -> Result<Event, EventValidat
"inactive_projects_toggle" => {
decode!(InactiveProjectsTogglePayload, InactiveProjectsToggle)
}
"set_primary_checkout" => decode!(SetPrimaryCheckoutPayload, SetPrimaryCheckout),
"workspace_pin_set" => decode!(WorkspacePinSetPayload, WorkspacePinSet),
"remove_workspace" => decode!(RemoveWorkspacePayload, RemoveWorkspace),
"register_device" => decode!(RegisterDevicePayload, RegisterDevice),
Expand Down Expand Up @@ -1726,6 +1734,7 @@ impl Runtime {
true
}
Event::WorkspacePinSet(payload) => self.set_workspace_pinned(payload),
Event::SetPrimaryCheckout(payload) => self.set_primary_checkout(payload),
Event::RemoveWorkspace(payload) => self.remove_workspace(payload),
Event::DeviceHostConsent(payload) => {
self.set_host_consent(payload.device_id.trim(), payload.allow)
Expand Down
77 changes: 77 additions & 0 deletions herdr-core/src/runtime/projects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,83 @@ impl Runtime {
true
}

/// One local registration choice; no filesystem or Herdr work under the lock.
pub(super) fn set_primary_checkout(&mut self, payload: SetPrimaryCheckoutPayload) -> bool {
let registration_index = self
.snapshot
.ui_state
.workspace_registrations
.iter()
.position(|row| row.id == payload.workspace_id);
let project = self
.snapshot
.navigator
.workspaces
.iter()
.find(|row| row.id == payload.workspace_id);
let refusal = match (registration_index, project) {
(Some(index), _)
if self.snapshot.ui_state.workspace_registrations[index].device_id
!= workspace::LOCAL_DEVICE_ID =>
{
Some("remote_read_only")
}
(None, _) => Some("unregistered"),
(_, None) => Some("missing_workspace"),
(_, Some(project)) if !project.is_git => Some("plain_folder"),
(_, Some(project))
if !project
.checkouts
.iter()
.any(|checkout| checkout.id == payload.checkout_id && checkout.exists) =>
{
Some("missing_checkout")
}
_ => None,
};
if let Some(reason) = refusal {
self.push_diagnostic(
format!("workspace.primary_{reason}"),
format!(
"Project {} checkout {}",
payload.workspace_id, payload.checkout_id
),
);
return true;
}
if project.is_some_and(|project| {
project
.checkouts
.iter()
.any(|checkout| checkout.id == payload.checkout_id && checkout.is_primary)
}) {
return false;
}
let registration = &mut self.snapshot.ui_state.workspace_registrations
[registration_index.expect("validated registration")];
if registration.primary_checkout_id.as_ref() == Some(&payload.checkout_id) {
return false;
}
registration.primary_checkout_id = Some(payload.checkout_id.clone());
for project in self
.snapshot
.navigator
.workspaces
.iter_mut()
.chain(self.last_accepted_catalog.iter_mut().flatten())
.filter(|project| project.id == payload.workspace_id)
{
workspace::apply_primary_checkout(project, Some(&payload.checkout_id));
}
crate::project_context::sort_projects(
&mut self.snapshot.navigator.workspaces,
&self.snapshot.navigator.agents,
);
self.refresh_inactive_groups();
self.persist_ui_state();
true
}

/// Pins or unpins a registered project (D-07, D-08). The row moves at
/// once and the registration is persisted on the existing off-lock save;
/// the same value again changes nothing and writes nothing.
Expand Down
3 changes: 3 additions & 0 deletions herdr-core/src/runtime/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,7 @@ fn split_checkout_payload(
fn tab_order_runtime(checkout_path: &str) -> (Runtime, String) {
let mut runtime = runtime();
runtime.snapshot.ui_state.workspace_registrations = vec![WorkspaceRegistration {
primary_checkout_id: None,
id: "workspace:order".to_owned(),
label: "order".to_owned(),
path: checkout_path.to_owned(),
Expand Down Expand Up @@ -1045,6 +1046,7 @@ fn reveal_runtime() -> (Runtime, PathBuf, String, PathBuf, String) {
.iter()
.enumerate()
.map(|(index, path)| WorkspaceRegistration {
primary_checkout_id: None,
id: format!("workspace:{index}"),
label: format!("workspace {index}"),
path: path.to_string_lossy().into_owned(),
Expand Down Expand Up @@ -1102,6 +1104,7 @@ fn explorer_runtime() -> (Runtime, PathBuf) {
/// way a click on it in the sidebar leaves the navigator.
fn focus_local_checkout(runtime: &mut Runtime, root: &Path) {
runtime.snapshot.ui_state.workspace_registrations = vec![WorkspaceRegistration {
primary_checkout_id: None,
id: "workspace:0".to_owned(),
label: "workspace 0".to_owned(),
path: root.to_string_lossy().into_owned(),
Expand Down
4 changes: 4 additions & 0 deletions herdr-core/src/runtime/tests/agents_settings_remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -983,13 +983,15 @@ fn read_record_is_released_and_not_raised_by_a_checkout_switch() {
}
runtime.snapshot.ui_state.workspace_registrations = vec![
WorkspaceRegistration {
primary_checkout_id: None,
id: "workspace:a".to_owned(),
label: "a".to_owned(),
path: root_a.clone(),
device_id: "local".to_owned(),
pinned: false,
},
WorkspaceRegistration {
primary_checkout_id: None,
id: "workspace:b".to_owned(),
label: "b".to_owned(),
path: root_b.clone(),
Expand Down Expand Up @@ -1123,6 +1125,7 @@ fn a_remote_pane_left_in_the_selection_does_not_block_local_projection() {
let workspace_id = workspace::workspace_id_for_path(Path::new(checkout_path));
let checkout_id = workspace::checkout_id_for_path(&workspace_id, Path::new(checkout_path));
let registration = WorkspaceRegistration {
primary_checkout_id: None,
id: workspace_id.clone(),
label: "Remote selection leak".to_owned(),
path: checkout_path.to_owned(),
Expand Down Expand Up @@ -1646,6 +1649,7 @@ fn read_record_reaches_the_pane_tree_and_not_only_the_agent_rows() {
};
let checkout_path = "/private/tmp/hide-read-record-pane-tree";
runtime.snapshot.ui_state.workspace_registrations = vec![WorkspaceRegistration {
primary_checkout_id: None,
id: "workspace:read-record".to_owned(),
label: "read-record".to_owned(),
path: checkout_path.to_owned(),
Expand Down
2 changes: 2 additions & 0 deletions herdr-core/src/runtime/tests/device_catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ fn a_device_registration_is_listed_without_panes_pinned_and_removed_on_that_devi
.ui_state
.workspace_registrations
.push(crate::model::WorkspaceRegistration {
primary_checkout_id: None,
id: "workspace:local-other".to_owned(),
label: "Local other".to_owned(),
path: t.other.clone(),
Expand Down Expand Up @@ -839,6 +840,7 @@ fn removing_a_device_forgets_its_projects_tabs_and_folders_and_keeps_this_machin
host_consent: None,
});
let registration = |id: &str, device: &str| crate::model::WorkspaceRegistration {
primary_checkout_id: None,
id: id.to_owned(),
label: id.to_owned(),
path: format!("/repo/{id}"),
Expand Down
1 change: 1 addition & 0 deletions herdr-core/src/runtime/tests/devices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ fn removing_the_selected_device_keeps_the_local_tabs_and_keyboard() {
fn a_device_project_at_this_machines_path_does_not_hold_up_its_add_or_removal() {
let mut runtime = runtime_with_home();
let registration = |id: &str, device: &str| crate::model::WorkspaceRegistration {
primary_checkout_id: None,
id: id.to_owned(),
label: "same".to_owned(),
path: "/work/same".to_owned(),
Expand Down
2 changes: 2 additions & 0 deletions herdr-core/src/runtime/tests/editor_reopen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ fn a_closed_projected_pane_retargets_to_the_remaining_pane_in_its_checkout() {
let workspace_id = workspace::workspace_id_for_path(Path::new(checkout_path));
let checkout_id = workspace::checkout_id_for_path(&workspace_id, Path::new(checkout_path));
let registration = WorkspaceRegistration {
primary_checkout_id: None,
id: workspace_id.clone(),
label: "Closed pane".to_owned(),
path: checkout_path.to_owned(),
Expand Down Expand Up @@ -1397,6 +1398,7 @@ fn explorer_file_create_opens_the_created_file_as_a_tab_and_others_do_not() {
);
let mut runtime = runtime();
runtime.snapshot.ui_state.workspace_registrations = vec![WorkspaceRegistration {
primary_checkout_id: None,
id: "workspace:0".to_owned(),
label: "workspace 0".to_owned(),
path: root.to_string_lossy().into_owned(),
Expand Down
1 change: 1 addition & 0 deletions herdr-core/src/runtime/tests/project_sessions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ fn fixture() -> Fixture {

fn project(path: &Path, checkouts: bool) -> WorkspaceSnapshot {
let mut project = workspace::inspect_registered(&crate::model::WorkspaceRegistration {
primary_checkout_id: None,
id: workspace::workspace_id_for_path(path),
label: "Project".to_owned(),
path: path.to_string_lossy().into_owned(),
Expand Down
Loading
Loading