diff --git a/agents/prd/sidebar-row-click-overview-row/prd.md b/agents/prd/sidebar-row-click-overview-row/prd.md index 1a0a88afbd..1181eec299 100644 --- a/agents/prd/sidebar-row-click-overview-row/prd.md +++ b/agents/prd/sidebar-row-click-overview-row/prd.md @@ -34,7 +34,7 @@ hide 사용자가 Projects 사이드바에서 체크아웃 행을 클릭하면 | D-02 | 체크아웃 행 클릭 = 열기 + 에이전트 펼치기. 이미 열려 있고 펼쳐진 체크아웃의 행을 다시 클릭하면 접는다(열림 유지). chevron은 그대로 접기/펼치기만. 에이전트가 없는 체크아웃은 열기만. PR #167의 "행은 열기만" 결정을 번복한다. | 사용자: "저 체크아웃 row 클릭하면 나오게 해줘!" (qa-log D-02) | | D-03 | 펼친 프로젝트의 체크아웃 목록 첫 행에 Overview 행(layout-dashboard 글리프, 체크아웃 행의 열)을 둔다. 클릭하면 Project Overview. Overview가 앞이면 선택 fill은 이 행이 받고 프로젝트 이름 행은 받지 않는다. 플레인 폴더에는 없다. | 사용자: "Overview가 하나는 있게 보여지면 좋을 것 같아!!!" (qa-log D-03) | | D-04 | Overview 행은 체크아웃 행과 같은 높이·포커스 링·키보드 동작(Enter/Space로 열기)을 가지며 배지·시간·chevron 슬롯은 비어 있다. 행 클릭 펼침은 마우스와 Enter/Space가 같고 다른 행을 움직이지 않는다. | 가정 (qa-log D-04) | -| D-05 | 펼침 상태는 그대로 core가 소유한다. 행 클릭은 열기 이벤트 하나에 펼침 의도를 함께 실어 보낸다(한 동작 = 한 이벤트); 웹이 두 이벤트를 연달아 보내지 않는다. core 변경은 그 이벤트의 페이로드 확장뿐. | 가정; AGENTS.md "A user action is one event, not a sequence" (qa-log D-05) | +| D-05 | 펼침 상태는 그대로 core가 소유한다. 행 클릭은 열기 이벤트 하나에 펼침 의도를 함께 실어 보낸다(한 동작 = 한 이벤트); 웹이 두 이벤트를 연달아 보내지 않는다. core 변경은 그 이벤트의 페이로드 확장과 admission 검증뿐. 유효하지 않은 workspace/checkout은 focus와 펼침 모두 바꾸지 않고 진단만 남긴다. 수락 후 Herdr pane.layout 실패·타임아웃은 기존 정책대로 core 값을 유지하고 진단하며 펼침을 되돌리지 않는다. | 가정; AGENTS.md "A user action is one event, not a sequence" (qa-log D-05) | | D-06 | Pen: Screen / Projects Sidebar 시트에 Overview 행을 넣고(gen-screens), 라이브러리는 바꾸지 않는다. UI_BEHAVIOR.md 401·407·410행과 시트 설명을 새 동작으로 고친다. | 가정 (qa-log D-06) | | D-07 | 검증: vitest(행 클릭 규칙, 선택 규칙), 웹 e2e 1개(클릭 → 열림+펼침, 재클릭 → 접힘, Overview 행 → Overview, 선택 fill), gen-screens diff. | 가정 (qa-log D-07) | | D-08 | 실행: please, Claude Implementor --effort high, PR 배포, Observer 자동 머지. T0 머지 후 main에서 시작. | 사용자 (qa-log D-08) | @@ -53,7 +53,7 @@ hide 사용자가 Projects 사이드바에서 체크아웃 행을 클릭하면 | B6 | Overview가 앞에 있을 때 Overview 행이 선택 fill을 갖고 프로젝트 이름 행은 갖지 않는다; 체크아웃 Workspace가 앞이면 지금처럼 그 체크아웃 행만 선택 fill을 갖는다. | D-03 | | B7 | Overview 행은 체크아웃 행과 같은 높이·글꼴·포커스 링이며 배지·시간·chevron이 없다; 프로젝트를 접으면 함께 사라진다. | D-03, D-04 | | B8 | 행 클릭 펼침과 Overview 행 추가로 다른 행의 높이나 위치가 바뀌지 않는다(펼친 에이전트 행이 아래 행을 미는 것 외). | D-04 | -| B9 | 웹 셸이 보내는 이벤트는 행 클릭당 하나이고, Herdr가 열기를 거부하면 펼침도 일어나지 않는다(반쯤 움직인 화면 없음). | D-05 | +| B9 | 웹 셸이 보내는 이벤트는 행 클릭당 하나이다. core admission이 유효하지 않은 workspace/checkout을 거부하면 focus와 펼침 모두 바뀌지 않고 진단만 남는다. 수락되면 focus와 expanded가 같은 snapshot에 함께 반영된다. 이후 Herdr pane.layout 실패·타임아웃은 기존 정책대로 core 값을 유지하고 진단하며 펼침을 되돌리지 않는다. | D-05 | | B10 | UI_BEHAVIOR.md와 Screen / Projects Sidebar 시트가 새 동작을 서술하고, gen-screens 산출물에 Overview 행이 있다. | D-06 | ## Technical structure diff --git a/contracts/hided-ws.schema.json b/contracts/hided-ws.schema.json index 92c015c029..26109cbb1f 100644 --- a/contracts/hided-ws.schema.json +++ b/contracts/hided-ws.schema.json @@ -157,6 +157,19 @@ "usage_popover_open": { "type": "boolean" } } }, + "focusCheckoutPayload": { + "description": "focus_checkout: one admitted focus and optional sidebar disclosure transition. Unknown workspace/checkout refuses the disclosure intent before either value changes.", + "type": "object", + "additionalProperties": false, + "required": ["workspace_id", "checkout_id"], + "properties": { + "workspace_id": { "type": "string" }, + "checkout_id": { "type": "string" }, + "focus_device": { "type": "boolean" }, + "display_id": { "type": "string" }, + "expanded": { "type": "boolean" } + } + }, "clientEvent": { "type": "object", "required": ["schema_version", "kind", "payload"], diff --git a/design/hide-screens.pen b/design/hide-screens.pen index 6de7f0ab72..eaac6a3049 100644 --- a/design/hide-screens.pen +++ b/design/hide-screens.pen @@ -28395,7 +28395,7 @@ "type": "text", "id": "screen-projects-sidebar-spec", "name": "sidebar.tsx, projects.ts: th", - "content": "sidebar.tsx, projects.ts: the Projects tab, the scope picker. All projects heads the list and opens All projects; the row of the scope the center shows carries the selected fill, here herdr-ide on its Overview, and a checkout only while its Workspace is in front. A project’s primary checkout comes first, then the rest by activity. Every line ends in its time or status badge and then a fold slot, so names never move and the times, badges and chevrons stand in one column each; a folded chevron is drawn and an unfolded one waits for the pointer. A row’s menu opens on a right-click, with nothing drawn for it. A status badge counts agents under the mark each agent’s own row draws, worst first (× ! ? ● ✓ ○). A project row opens the Overview and wears its checkouts’ badges added up, open or folded, and no time. A checkout row opens the checkout; while its agent rows are folded its badge ends line one, and its chevron, there only while agents run, opens them on one group fill in place of the badge. Line two is the purpose with the last-commit age on the time column, kept wherever agents run; a checkout with neither is one line with its age there. A parent agent folds its children with the same chevron and speaks for them with its badge. The kind glyph is the pull request’s lifecycle when GitHub knows one, else folder, primary, detached or branch; a missing folder is danger with no age.", + "content": "sidebar.tsx, projects.ts: the Projects tab, the scope picker. All projects heads the list and opens All projects; the row of the scope the center shows carries the selected fill, here the Overview child under herdr-ide, and a checkout only while its Workspace is in front. A project’s primary checkout comes first, then the rest by activity. Every line ends in its time or status badge and then a fold slot, so names never move and the times, badges and chevrons stand in one column each; a folded chevron is drawn and an unfolded one waits for the pointer. A row’s menu opens on a right-click, with nothing drawn for it. A status badge counts agents under the mark each agent’s own row draws, worst first (× ! ? ● ✓ ○). A project row opens the Overview and wears its checkouts’ badges added up, open or folded, and no time. The first row under an expanded Git project is Overview, an instance of the checkout row with a layout-dashboard glyph and empty trailing slots. A checkout row opens the checkout and unfolds its agents; clicking its already selected, unfolded Workspace folds them without leaving it. The chevron changes disclosure alone. While its agent rows are folded its badge ends line one, and its chevron, there only while agents run, opens them on one group fill in place of the badge. Line two is the purpose with the last-commit age on the time column, kept wherever agents run; a checkout with neither is one line with its age there. A parent agent folds its children with the same chevron and speaks for them with its badge. The kind glyph is the pull request’s lifecycle when GitHub knows one, else folder, primary, detached or branch; a missing folder is danger with no age.", "fill": "$--muted-foreground", "fontFamily": "$--font-ui", "fontSize": "$--text-caption", @@ -28725,7 +28725,6 @@ "name": "herdr-ide", "width": 284, "height": 36, - "fill": "$--secondary", "descendants": { "hideui:mIzlX": { "fill": "$--subtle-foreground", @@ -28809,6 +28808,104 @@ } } }, + { + "id": "psb-overview-l", + "type": "ref", + "ref": "hideui:DLP27", + "name": "Overview", + "width": 284, + "height": 36, + "padding": [ + 0, + 4, + 0, + 6 + ], + "fill": "$--secondary", + "descendants": { + "hideui:VtSRn": { + "fill": "$--subtle-foreground", + "icon": "layout-dashboard" + }, + "hideui:q91d7": { + "fill": "$--foreground", + "content": "Overview", + "fontWeight": "600" + }, + "hideui:checkout-status": { + "fill": "$--secondary", + "enabled": false + }, + "hideui:checkout-error-glyph": { + "fill": "$--destructive" + }, + "hideui:checkout-error-count": { + "fill": "$--subtle-foreground" + }, + "hideui:checkout-approval-glyph": { + "fill": "$--warning" + }, + "hideui:checkout-approval-count": { + "fill": "$--subtle-foreground" + }, + "hideui:checkout-question-glyph": { + "fill": "$--warning" + }, + "hideui:checkout-question-count": { + "fill": "$--subtle-foreground" + }, + "hideui:checkout-working-dot": { + "fill": "$--agent-working" + }, + "hideui:checkout-working-count": { + "fill": "$--subtle-foreground" + }, + "hideui:checkout-done-glyph": { + "fill": "$--success" + }, + "hideui:checkout-done-count": { + "fill": "$--subtle-foreground" + }, + "hideui:checkout-idle-ring": { + "stroke": "$--subtle-foreground" + }, + "hideui:checkout-idle-count": { + "fill": "$--subtle-foreground" + }, + "hideui:TuosT": { + "fill": "$--muted-foreground", + "enabled": false + }, + "hideui:CgZj3": { + "fill": "$--muted-foreground", + "icon": "chevron-right" + }, + "hideui:D37Vr": { + "fill": "$--muted-foreground", + "enabled": false + }, + "hideui:line2-age": { + "fill": "$--muted-foreground", + "enabled": false + }, + "hideui:QetL0": { + "width": 274 + }, + "hideui:TS5x9": { + "enabled": false + }, + "hideui:IXwZI": { + "opacity": 0 + }, + "hideui:o6XLUj": { + "enabled": false, + "width": 274 + }, + "hideui:yfur4": { + "width": 20 + } + } + }, { "type": "frame", "id": "psb-g-main-l", @@ -30568,7 +30665,6 @@ "name": "herdr-ide", "width": 284, "height": 36, - "fill": "$--secondary", "descendants": { "hideui:mIzlX": { "fill": "$--subtle-foreground", @@ -30652,6 +30748,104 @@ } } }, + { + "id": "psb-overview-d", + "type": "ref", + "ref": "hideui:DLP27", + "name": "Overview", + "width": 284, + "height": 36, + "padding": [ + 0, + 4, + 0, + 6 + ], + "fill": "$--secondary", + "descendants": { + "hideui:VtSRn": { + "fill": "$--subtle-foreground", + "icon": "layout-dashboard" + }, + "hideui:q91d7": { + "fill": "$--foreground", + "content": "Overview", + "fontWeight": "600" + }, + "hideui:checkout-status": { + "fill": "$--secondary", + "enabled": false + }, + "hideui:checkout-error-glyph": { + "fill": "$--destructive" + }, + "hideui:checkout-error-count": { + "fill": "$--subtle-foreground" + }, + "hideui:checkout-approval-glyph": { + "fill": "$--warning" + }, + "hideui:checkout-approval-count": { + "fill": "$--subtle-foreground" + }, + "hideui:checkout-question-glyph": { + "fill": "$--warning" + }, + "hideui:checkout-question-count": { + "fill": "$--subtle-foreground" + }, + "hideui:checkout-working-dot": { + "fill": "$--agent-working" + }, + "hideui:checkout-working-count": { + "fill": "$--subtle-foreground" + }, + "hideui:checkout-done-glyph": { + "fill": "$--success" + }, + "hideui:checkout-done-count": { + "fill": "$--subtle-foreground" + }, + "hideui:checkout-idle-ring": { + "stroke": "$--subtle-foreground" + }, + "hideui:checkout-idle-count": { + "fill": "$--subtle-foreground" + }, + "hideui:TuosT": { + "fill": "$--muted-foreground", + "enabled": false + }, + "hideui:CgZj3": { + "fill": "$--muted-foreground", + "icon": "chevron-right" + }, + "hideui:D37Vr": { + "fill": "$--muted-foreground", + "enabled": false + }, + "hideui:line2-age": { + "fill": "$--muted-foreground", + "enabled": false + }, + "hideui:QetL0": { + "width": 274 + }, + "hideui:TS5x9": { + "enabled": false + }, + "hideui:IXwZI": { + "opacity": 0 + }, + "hideui:o6XLUj": { + "enabled": false, + "width": 274 + }, + "hideui:yfur4": { + "width": 20 + } + } + }, { "type": "frame", "id": "psb-g-main-d", diff --git a/docs/DESIGN_WORKFLOW.md b/docs/DESIGN_WORKFLOW.md index e4926e7662..408361c7d6 100644 --- a/docs/DESIGN_WORKFLOW.md +++ b/docs/DESIGN_WORKFLOW.md @@ -168,7 +168,8 @@ It draws the sidebar row menu, the Explorer context menu, the device picker, and Its web files are `web/src/entry-menu.tsx` and `web/src/DevicePicker.tsx`. Projects Sidebar is `Screen / Projects Sidebar`. -It draws the sidebar's Projects tab as the scope picker: the All projects row on top, pinned and activity-ordered projects with the row of the scope on screen selected, checkout rows with their kind glyph, age and agent line, an opened checkout's agent rows, and both inactive folds. +It draws the sidebar's Projects tab as the scope picker: the All projects row on top, pinned and activity-ordered projects with the row of the scope on screen selected, a Git project’s first Overview child as a checkout-row master instance with a layout-dashboard glyph and empty trailing slots, checkout rows with their kind glyph, age and agent line, an opened checkout’s agent rows, and both inactive folds. +The Overview child owns selection on Overview; a checkout row opens and unfolds, then folds on activation while already selected and unfolded. Its web files are `web/src/sidebar.tsx` and `web/src/projects.ts`. ## How to add a token diff --git a/docs/UI_BEHAVIOR.md b/docs/UI_BEHAVIOR.md index 0f7714c056..ea5e16e5ba 100644 --- a/docs/UI_BEHAVIOR.md +++ b/docs/UI_BEHAVIOR.md @@ -303,7 +303,7 @@ A pull request shows here only in the task chip's tooltip (title, branch, pull r On the web, the sidebar picks the scope and the tabs under the title pick the view. All projects is every project on every device, a project is its Overview, and a checkout is its Workspace, which has no views of its own. -The board is the Project Overview: the sidebar's project name (a plain folder's one row opens its checkout instead), All projects' project row, the palette and the Workspace toolbar menu open it, and ⌘⇧H opens it for the checkout in front. +The board is the Project Overview: the sidebar's project name or its Overview child (a plain folder's one row opens its checkout instead), All projects' project row, the palette and the Workspace toolbar menu open it, and ⌘⇧H opens it for the checkout in front. Escape, once no dialog or menu is open and no text field holds text, returns to the Workspace in front, or to All projects when there is none. The title row carries the path back (`All projects / Project`) and New agent; directly under it is one line of facts, then the `Tasks · Agents · Sessions` tabs, which show even while the project has no agent. The facts line holds only numbers the system has: the worktree count, the open pull-request count once GitHub has answered, the disk every worktree and the shared Git directory occupy, main's distance behind origin only above zero, and the merged worktrees only above zero. @@ -426,17 +426,24 @@ Open, draft, merged, and closed pull requests keep their own lifecycle shapes an 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. Nothing on a row stands for its menu: a right-click, or the menu key or ⇧F10 on the focused row, opens it. -A web checkout row always opens its checkout: its chevron, drawn only while agents run there, opens and closes their rows, and its last-commit age stays in place whatever the pointer does and while the menu is open. +A web checkout row opens its checkout and unfolds its agent rows in one event; activating its already selected, unfolded Workspace folds the agents while keeping that Workspace in front. +Click, Enter and Space have the same behavior, and a checkout without agents only opens. +Its chevron changes disclosure alone, and other checkouts keep their own expansion. +The core admits the workspace/checkout pair before changing focus or expansion and publishes both in the same snapshot; a stale pair changes neither and leaves a diagnostic. +A later Herdr projection failure retains these accepted values under the existing focus policy. +The last-commit age stays in place whatever the pointer does and while the menu is open. An opened checkout and its agent rows share one small group fill; no card border nests inside another. A web checkout's agent rows start closed, so its status badge counts them, and the checkouts the operator opens are kept in the core's ui state across launches. A status badge counts agents under the mark each agent's own row draws, one mark and count per state, worst first (`× ! ? ● ✓ ○`), with idle agents included and zero states left out (docs/status-model.md, Workspace aggregation). A web project row folds its checkouts from its chevron on the right, and the rest of the row opens the project's Overview; both folds are this machine's, so a selected SSH device's tree is drawn with nothing folded. A web project row carries no time: it ends in its checkouts' badges added up, which stay while its checkouts are open because they are the project's own summary, and a project with no agent draws none. An opened checkout's parent agent folds its children with the lineage chevron and badge the Agents list uses, from the same core state; a child working in another checkout is also drawn as a root in that checkout, so folding a parent never hides where an agent runs, and a selected SSH device's lineage is drawn unfolded with no chevron. -Folding a project, a checkout or a parent changes the list only: the center, the focused pane and tab, read state, groups and running processes stay as they were. +Folding a project or parent, or using a checkout chevron, changes the list only: the center, the focused pane and tab, read state, groups and running processes stay as they were. Before the first snapshot arrives the Agents and Projects lists say they are connecting rather than drawing an empty list, and a local Projects list with no registered project offers Add project. The web Projects list is the scope picker: an All projects row heads it, with the layout-grid glyph and `N projects`, and opens All projects. -One row carries the selected fill at a time, the row of the scope the center shows: All projects, a project row on its Overview, or the focused checkout and its open agent row only while a Workspace is in front. +One row carries the selected fill at a time, the row of the scope the center shows: All projects, a Git project’s Overview child on its Overview, or the focused checkout and its open agent row only while a Workspace is in front. +An expanded Git project starts with an Overview row using the checkout row’s columns, single-line height, font and focus ring, with a layout-dashboard glyph and no badge, time or chevron. +Click, Enter or Space opens the same Overview as the project name; only the Overview child carries its selection fill, and folding the project hides the child too. A plain folder, a project that is not a Git repository and holds one checkout, is one web row instead of a project row over an identical checkout row. Its first line is the project's folder glyph, name and status badge, set in the checkout row's columns, and the badge stays while its agent rows are open, as a project's does; its second line and trailing chevron are the checkout's, and a plain folder has no commit age. It has no project fold of its own and keeps the checkout row's right slots; the row opens the checkout and is marked while that checkout's Workspace or the project's Overview is in front, its menu lists the project's items and then the checkout's, and its Overview is reached from All projects, the palette or the Workspace toolbar. diff --git a/herdr-core/src/runtime.rs b/herdr-core/src/runtime.rs index b9c96808c1..d670f39a5e 100644 --- a/herdr-core/src/runtime.rs +++ b/herdr-core/src/runtime.rs @@ -1651,6 +1651,27 @@ impl Runtime { } }; + // A stale sidebar row has no action left to offer. Reject the whole + // open/disclosure intent before focus, persistence or visit effects. + if let Event::FocusCheckout(payload) = &event + && !self.snapshot.navigator.workspaces.iter().any(|workspace| { + workspace.id == payload.workspace_id + && workspace + .checkouts + .iter() + .any(|checkout| checkout.id == payload.checkout_id) + }) + { + self.push_diagnostic( + "checkout.row_stale", + format!( + "Checkout {} is not available in {}", + payload.checkout_id, payload.workspace_id + ), + ); + return true; + } + let cleared_error = self.snapshot.status.last_error.take().is_some(); let intent = self .separate_view_areas() diff --git a/herdr-core/src/runtime/events.rs b/herdr-core/src/runtime/events.rs index 73d0369f76..053e066e4d 100644 --- a/herdr-core/src/runtime/events.rs +++ b/herdr-core/src/runtime/events.rs @@ -129,6 +129,9 @@ pub(super) struct CreateTabPayload { #[derive(Debug, Deserialize)] pub(super) struct FocusCheckoutPayload { + /// Sidebar row disclosure, committed with checkout focus. Omitted by other open entrypoints. + #[serde(default)] + pub(super) expanded: Option, pub(super) workspace_id: String, pub(super) checkout_id: String, /// Also makes this machine the device in front when the checkout is @@ -1515,6 +1518,14 @@ impl Runtime { self.set_error(error.kind(), error.message(), false); return true; } + if let Some(expanded) = payload.expanded { + let ids = &mut self.snapshot.ui_state.expanded_checkout_ids; + ids.retain(|id| id != &payload.checkout_id); + if expanded { + ids.push(payload.checkout_id.clone()); + ids.sort(); + } + } let mut changed = self.focus_checkout(&payload.workspace_id, &payload.checkout_id); // The display follows whenever the checkout came forward: a // later failure inside the checkout focus (a pane projection diff --git a/herdr-core/src/runtime/projects.rs b/herdr-core/src/runtime/projects.rs index 91512ed650..3406949ee2 100644 --- a/herdr-core/src/runtime/projects.rs +++ b/herdr-core/src/runtime/projects.rs @@ -519,6 +519,12 @@ impl Runtime { continue; } workspace::apply_worktrees(workspace, &self.worktree_catalog); + // Git refreshes the persistent purpose sources. Restore the + // agent/PR fallback in this same projection before publishing it. + crate::sidebar::sync_checkout_purposes( + std::slice::from_mut(workspace), + &self.snapshot.navigator.agents, + ); let named = self.disk_project.as_deref() == Some(workspace.path.as_str()); workspace.disk = project_disk(self.worktree_catalog.project(&workspace.path), named); } diff --git a/herdr-core/src/runtime/tests/projects.rs b/herdr-core/src/runtime/tests/projects.rs index d72658387d..e592f446d3 100644 --- a/herdr-core/src/runtime/tests/projects.rs +++ b/herdr-core/src/runtime/tests/projects.rs @@ -1,5 +1,61 @@ use super::*; +#[test] +fn worktree_refresh_keeps_derived_checkout_purpose_with_its_agent() { + let mut runtime = runtime(); + let path = "/fixture/purpose-refresh"; + let mut row = checkout("project", "checkout", path, None); + row.is_primary = true; + row.agent_summary.representative_pane_id = Some("pane".into()); + runtime.snapshot.navigator.workspaces = vec![workspace("project", "Project", path, vec![row])]; + runtime.snapshot.navigator.agents = crate::sidebar::project_agents( + serde_json::from_value(serde_json::json!({"agents": [{ + "pane_id": "pane", "workspace_label": "Project", "agent": "claude", + "agent_status": "idle", "state_change_seq": 1, "tokens": {"task": "메인 체크아웃 정리"} + }]})) + .unwrap(), + ) + .agents; + crate::sidebar::sync_checkout_purposes( + &mut runtime.snapshot.navigator.workspaces, + &runtime.snapshot.navigator.agents, + ); + assert_eq!( + runtime.snapshot.navigator.workspaces[0].checkouts[0] + .purpose + .as_ref() + .map(|purpose| purpose.text.as_str()), + Some("메인 체크아웃 정리") + ); + runtime.worktree_catalog.projects = vec![crate::model::ProjectWorktreesSnapshot { + root_path: path.into(), + worktrees: vec![crate::model::WorktreeSnapshot { + path: path.into(), + branch: Some("main".into()), + is_main: true, + ..Default::default() + }], + ..Default::default() + }]; + for _ in 0..2 { + runtime.refresh_worktree_projection(); + let row = &runtime.snapshot.navigator.workspaces[0].checkouts[0]; + assert!(row.is_primary); + assert_eq!(row.id, "checkout"); + assert_eq!( + row.purpose.as_ref().map(|purpose| purpose.text.as_str()), + Some("메인 체크아웃 정리") + ); + } + runtime.snapshot.navigator.agents.clear(); + runtime.refresh_worktree_projection(); + assert!( + runtime.snapshot.navigator.workspaces[0].checkouts[0] + .purpose + .is_none() + ); +} + /// A registered folder below a Git root keeps the live History request and /// the web's root identity on that folder. The reader's direct scope test is /// insufficient if the catalog hands the runtime the repository root. diff --git a/herdr-core/src/runtime/tests/session_navigation.rs b/herdr-core/src/runtime/tests/session_navigation.rs index 9e51437736..3d70f911a9 100644 --- a/herdr-core/src/runtime/tests/session_navigation.rs +++ b/herdr-core/src/runtime/tests/session_navigation.rs @@ -2834,7 +2834,15 @@ fn a_checkout_chosen_with_its_device_moves_both_or_neither() { runtime.snapshot.navigator.focused_device_id = Some("mini".to_owned()); runtime.dispatch_json(&choose("checkout:missing")); - assert!(runtime.snapshot.status.last_error.is_some()); + assert!(runtime.snapshot.status.last_error.is_none()); + assert!( + runtime + .snapshot + .status + .diagnostics + .iter() + .any(|entry| entry.kind == "checkout.row_stale") + ); assert_eq!( runtime.snapshot.navigator.focused_device_id.as_deref(), Some("mini") @@ -2848,6 +2856,80 @@ fn a_checkout_chosen_with_its_device_moves_both_or_neither() { ); } +#[test] +fn checkout_row_admits_focus_and_disclosure_together_and_rejects_stale_targets() { + let mut runtime = runtime(); + runtime.snapshot.navigator.workspaces = vec![workspace( + "project", + "Project", + "/tmp/project", + vec![ + checkout("project", "first", "/tmp/project", None), + checkout("project", "second", "/tmp/second", None), + ], + )]; + let activate = |runtime: &mut Runtime, project: &str, checkout: &str, expanded: bool| { + runtime.dispatch_json(&serde_json::to_vec(&serde_json::json!({ + "schema_version": SCHEMA_VERSION, + "kind": "focus_checkout", + "payload": { "workspace_id": project, "checkout_id": checkout, "expanded": expanded } + })).unwrap()); + }; + activate(&mut runtime, "project", "first", true); + let snapshot = runtime.snapshot(); + assert_eq!( + snapshot.navigator.focused_checkout_id.as_deref(), + Some("first") + ); + assert_eq!(snapshot.ui_state.expanded_checkout_ids, ["first"]); + activate(&mut runtime, "project", "second", true); + let snapshot = runtime.snapshot(); + assert_eq!( + snapshot.navigator.focused_checkout_id.as_deref(), + Some("second") + ); + assert_eq!(snapshot.ui_state.expanded_checkout_ids, ["first", "second"]); + // Repeating an explicit target converges; closing only removes this row. + activate(&mut runtime, "project", "second", true); + activate(&mut runtime, "project", "second", false); + let snapshot = runtime.snapshot(); + assert_eq!( + snapshot.navigator.focused_checkout_id.as_deref(), + Some("second") + ); + assert_eq!(snapshot.ui_state.expanded_checkout_ids, ["first"]); + for (project, checkout, expanded) in [ + ("missing", "first", Some(true)), + ("project", "missing", Some(true)), + ("missing", "first", None), + ("project", "missing", None), + ] { + let mut payload = serde_json::json!({"workspace_id": project, "checkout_id": checkout}); + if let Some(expanded) = expanded { + payload["expanded"] = serde_json::json!(expanded); + } + runtime.dispatch_json(&serde_json::to_vec(&serde_json::json!({"schema_version": SCHEMA_VERSION, "kind": "focus_checkout", "payload": payload})).unwrap()); + let snapshot = runtime.snapshot(); + assert_eq!( + snapshot.navigator.focused_workspace_id.as_deref(), + Some("project") + ); + assert_eq!( + snapshot.navigator.focused_checkout_id.as_deref(), + Some("second") + ); + assert_eq!(snapshot.ui_state.expanded_checkout_ids, ["first"]); + assert!(snapshot.status.last_error.is_none()); + assert!( + snapshot + .status + .diagnostics + .iter() + .any(|entry| entry.kind == "checkout.row_stale") + ); + } +} + #[test] fn tab_rename_keeps_the_committed_name_on_failure_and_ignores_old_receipts() { let mut runtime = runtime(); diff --git a/scripts/pen-screens.mjs b/scripts/pen-screens.mjs index 48a0b7a2dc..6f575be42a 100644 --- a/scripts/pen-screens.mjs +++ b/scripts/pen-screens.mjs @@ -1259,6 +1259,7 @@ function buildProjectsSidebar(tokens) { const STATUS = {working: '$--agent-working', asking: '$--warning', done: '$--success', seen: '$--muted-foreground'}; const SYMBOL = {working: '●', asking: '?', done: '✓', seen: '○'}; const KIND = { + overview: {icon: 'layout-dashboard', fill: '$--subtle-foreground'}, primary: {icon: 'house', fill: '$--subtle-foreground'}, branch: {icon: 'git-branch', fill: '$--subtle-foreground'}, folder: {icon: 'folder', fill: '$--subtle-foreground'}, @@ -1380,7 +1381,8 @@ function buildProjectsSidebar(tokens) { section(`psb-sec-pin-${s}`, 'PINNED · 1'), folderRow(`psb-p-notes-${s}`, {name: 'team-notes', marks: {idle: 1}, purpose: '회의록 요약 정리'}), section(`psb-sec-recent-${s}`, 'PROJECTS · RECENT ACTIVITY · 5'), - projectRow(`psb-p-herdr-${s}`, {name: 'herdr-ide', marks: {question: 3, working: 5, done: 1, idle: 1}, expanded: true, selected: true}), + projectRow(`psb-p-herdr-${s}`, {name: 'herdr-ide', marks: {question: 3, working: 5, done: 1, idle: 1}, expanded: true}), + checkoutRow(`psb-overview-${s}`, {name: 'Overview', kind: 'overview', selected: true}), group(`psb-g-main-${s}`, [ checkoutRow(`psb-c2-${s}`, {name: 'main', kind: 'primary', age: 'now', marks: {question: 2, working: 4, idle: 1}, purpose: '사이드바 가독성 개선', expanded: true}), // An unfolded parent: its chevron waits in the slot, its children follow. @@ -1416,7 +1418,7 @@ function buildProjectsSidebar(tokens) { ]); return [frame(`psb-sidebar-${s}`, 'Sidebar', {width, layout: 'vertical', fill: '$--sidebar', clip: true}, [header, list, footer])]; } - return screenSheet('screen-projects-sidebar', 'Screen / Projects Sidebar', 'sidebar.tsx, projects.ts: the Projects tab, the scope picker. All projects heads the list and opens All projects; the row of the scope the center shows carries the selected fill, here herdr-ide on its Overview, and a checkout only while its Workspace is in front. A project’s primary checkout comes first, then the rest by activity. Every line ends in its time or status badge and then a fold slot, so names never move and the times, badges and chevrons stand in one column each; a folded chevron is drawn and an unfolded one waits for the pointer. A row’s menu opens on a right-click, with nothing drawn for it. A status badge counts agents under the mark each agent’s own row draws, worst first (× ! ? ● ✓ ○). A project row opens the Overview and wears its checkouts’ badges added up, open or folded, and no time. A checkout row opens the checkout; while its agent rows are folded its badge ends line one, and its chevron, there only while agents run, opens them on one group fill in place of the badge. Line two is the purpose with the last-commit age on the time column, kept wherever agents run; a checkout with neither is one line with its age there. A parent agent folds its children with the same chevron and speaks for them with its badge. The kind glyph is the pull request’s lifecycle when GitHub knows one, else folder, primary, detached or branch; a missing folder is danger with no age.', build, build); + return screenSheet('screen-projects-sidebar', 'Screen / Projects Sidebar', 'sidebar.tsx, projects.ts: the Projects tab, the scope picker. All projects heads the list and opens All projects; the row of the scope the center shows carries the selected fill, here the Overview child under herdr-ide, and a checkout only while its Workspace is in front. A project’s primary checkout comes first, then the rest by activity. Every line ends in its time or status badge and then a fold slot, so names never move and the times, badges and chevrons stand in one column each; a folded chevron is drawn and an unfolded one waits for the pointer. A row’s menu opens on a right-click, with nothing drawn for it. A status badge counts agents under the mark each agent’s own row draws, worst first (× ! ? ● ✓ ○). A project row opens the Overview and wears its checkouts’ badges added up, open or folded, and no time. The first row under an expanded Git project is Overview, an instance of the checkout row with a layout-dashboard glyph and empty trailing slots. A checkout row opens the checkout and unfolds its agents; clicking its already selected, unfolded Workspace folds them without leaving it. The chevron changes disclosure alone. While its agent rows are folded its badge ends line one, and its chevron, there only while agents run, opens them on one group fill in place of the badge. Line two is the purpose with the last-commit age on the time column, kept wherever agents run; a checkout with neither is one line with its age there. A parent agent folds its children with the same chevron and speaks for them with its badge. The kind glyph is the pull request’s lifecycle when GitHub knows one, else folder, primary, detached or branch; a missing folder is danger with no age.', build, build); } // -- assembly --------------------------------------------------------------------- diff --git a/web/e2e/delegated-checkout.spec.ts b/web/e2e/delegated-checkout.spec.ts index 28158f124c..630d628374 100644 --- a/web/e2e/delegated-checkout.spec.ts +++ b/web/e2e/delegated-checkout.spec.ts @@ -55,7 +55,8 @@ test("a checkout whose only tab is delegated opens on the child's pane", async ( await page.locator("[data-project]", { hasText: "fixture" }).locator("[data-checkout]").first().click(); await expect(page.locator(`[data-pane-view="${parent}"]`)).toBeVisible({ timeout: 20_000 }); const betaProject = page.locator("[data-project]", { hasText: "beta" }); - await betaProject.locator("[data-checkout-toggle]").click(); + // Opening beta unfolded it; switching checkout keeps that expansion. + await expect(betaProject.locator("[data-checkout-toggle]")).toHaveAttribute("aria-expanded", "true"); await betaProject.locator(`[data-agent-open="${child}"]`).click(); await expect.poll(() => last.get("focus_pane")?.pane_id).toBe(child); await expect(page.locator(`[data-pane-view="${child}"]`)).toHaveAttribute("data-focused", "true", { timeout: 20_000 }); diff --git a/web/e2e/overview.spec.ts b/web/e2e/overview.spec.ts index 334af9791f..1d1c4d7294 100644 --- a/web/e2e/overview.spec.ts +++ b/web/e2e/overview.spec.ts @@ -164,9 +164,10 @@ test("a project's Overview board: entry, columns, cards, Agents view and its sta await expect(overview).toBeVisible(); await expect(overview).toHaveAttribute("data-overview-state", "board"); await expect(overview).toHaveAttribute("data-overview-view", "tasks"); - // The sidebar marks the scope on screen: this project's row, not All - // projects and not a checkout. - await expect(repoRow).toHaveAttribute("aria-current", "page"); + // The Overview child marks this scope; the project header only navigates. + const overviewRow = repoRow.locator("xpath=ancestor::li[@data-project]").locator("[data-project-overview]"); + await expect(overviewRow).toHaveAttribute("aria-current", "page"); + await expect(repoRow).not.toHaveAttribute("aria-current", "page"); await expect(page.locator("[data-all-projects]")).not.toHaveAttribute("aria-current", "page"); await expect(page.locator('[data-project-list] [data-checkout][aria-current="true"]')).toHaveCount(0); diff --git a/web/e2e/projects-sidebar.spec.ts b/web/e2e/projects-sidebar.spec.ts index 82b61af041..90981f04cc 100644 --- a/web/e2e/projects-sidebar.spec.ts +++ b/web/e2e/projects-sidebar.spec.ts @@ -88,6 +88,9 @@ test("the Projects tab: kind, age, status badges, opened checkouts and folded pr git(worktree, ["commit", "--allow-empty", "-m", "rows"]); // The branch description is a purpose the core reads from Git itself. git(repo, ["config", "branch.feature/sidebar-rows.description", "Projects 탭 행 다시 그리기"]); + const emptyTree = path.join(herdr.root, "repo-empty"); + git(repo, ["worktree", "add", "-b", "empty", emptyTree]); + await workspaceAt(herdr, emptyTree, null); const notes = path.join(herdr.root, "notes"); fs.mkdirSync(notes); @@ -98,6 +101,17 @@ test("the Projects tab: kind, age, status badges, opened checkouts and folded pr daemon = await startHided(herdr, "projects-sidebar"); const last = new Map>(); const sent = countSent(page, last); + let holdOpen = false; + const heldOpen: { release: (() => void) | null } = { release: null }; + await page.routeWebSocket(/\/ws$/, (socket) => { + const server = socket.connectToServer(); + socket.onMessage((message) => { + const event = typeof message === "string" ? JSON.parse(message) as { kind?: string } : null; + if (holdOpen && event?.kind === "focus_checkout") { + heldOpen.release = () => server.send(message); + } else server.send(message); + }); + }); await open(page, daemon); const project = page.locator("[data-project]").filter({ has: page.locator("[data-project-row]", { hasText: /^repo/ }) }); @@ -182,12 +196,63 @@ test("the Projects tab: kind, age, status badges, opened checkouts and folded pr // Looking at a row sends nothing: hover, focus and an open menu are the list's own. await page.waitForTimeout(300); expect([...sent].filter(([kind, count]) => count !== (beforeLooking.get(kind) ?? 0)).map(([kind]) => kind)).toEqual([]); + const overview = project.locator("[data-project-overview]"); + await expect(project.locator("ul").first().locator(":scope > li").first()).toContainText("Overview"); + await overview.click(); + await expect(overview).toHaveAttribute("aria-current", "page"); + await expect(project.locator("[data-project-row]")).not.toHaveAttribute("aria-current"); + await expect(project.locator("[data-project-row]").locator("xpath=..")).not.toHaveClass(/bg-secondary/); + const beforeOpen = new Map(sent); await primary.locator("[data-checkout]").click(); await expect(primary.locator("[data-checkout]")).toHaveAttribute("aria-current", "true"); + await expect(primaryToggle).toHaveAttribute("aria-expanded", "true"); + expect((sent.get("focus_checkout") ?? 0) - (beforeOpen.get("focus_checkout") ?? 0)).toBe(1); + expect(sent.get("ui_state_update") ?? 0).toBe(beforeOpen.get("ui_state_update") ?? 0); + expect(last.get("focus_checkout")?.expanded).toBe(true); + await expect(overview).not.toHaveAttribute("aria-current"); + await screenshot(page, "row-click-expanded"); + await primary.locator("[data-checkout]").click(); + await expect(primaryToggle).toHaveAttribute("aria-expanded", "false"); + await expect(primary.locator("[data-checkout]")).toHaveAttribute("aria-current", "true"); + await keyboardFocus(page, primary.locator("[data-checkout]")); + await page.keyboard.press("Enter"); + await expect(primaryToggle).toHaveAttribute("aria-expanded", "true"); + await page.keyboard.press("Space"); + await expect(primaryToggle).toHaveAttribute("aria-expanded", "false"); + await keyboardFocus(page, overview); + await page.keyboard.press("Enter"); + await expect(overview).toHaveAttribute("aria-current", "page"); + await expect(primary.locator("[data-checkout]")).not.toHaveAttribute("aria-current"); + await screenshot(page, "overview-row-selected"); + await page.keyboard.press("Space"); + await expect(overview).toHaveAttribute("aria-current", "page"); + // The existing focused checkout cannot land from the old folded snapshot. + holdOpen = true; + await primary.locator("[data-checkout]").click(); + await expect.poll(() => heldOpen.release !== null).toBe(true); + await expect(overview).toHaveAttribute("aria-current", "page"); + await expect(page.locator("[data-overview-screen]")).toBeVisible(); + await expect(primaryToggle).toHaveAttribute("aria-expanded", "false"); + holdOpen = false; + heldOpen.release!(); + await expect(primaryToggle).toHaveAttribute("aria-expanded", "true"); + await expect(primary.locator("[data-checkout]")).toHaveAttribute("aria-current", "true"); + await primary.locator("[data-checkout]").click(); + await expect(primaryToggle).toHaveAttribute("aria-expanded", "false"); await expect(primary.locator("[data-purpose]")).toHaveText("메인 체크아웃 정리"); await rest(page); expect(await rowGeometry(primaryRow, feature, primaryParts)).toEqual(atRest); + // An agentless checkout uses the same single-line height as Overview; + // opening it sends no disclosure intent and leaves the fold slot empty. + const emptyRow = project.locator("[data-checkout-row]").filter({ has: page.locator('[data-checkout][aria-label^="empty"]') }); + const emptyButton = emptyRow.locator("[data-checkout]"); + await expect(emptyRow.locator("[data-checkout-toggle]")).toHaveCount(0); + expect((await emptyButton.boundingBox())!.height).toBe((await overview.boundingBox())!.height); + await emptyButton.click(); + await expect(emptyButton).toHaveAttribute("aria-current", "true"); + expect(last.get("focus_checkout")?.expanded).toBeUndefined(); + // The chevron opens the agent rows below the row: their own marks stand // for the checkout's badge, which goes, and the row keeps its purpose, // its age and its height. The project's badge stays. @@ -223,7 +288,9 @@ test("the Projects tab: kind, age, status badges, opened checkouts and folded pr await expect(folderRow).toHaveAttribute("aria-current", "true"); await expect(page.locator("[data-workspace-screen]")).toBeVisible(); await expect(feature.locator("[data-checkout]")).not.toHaveAttribute("aria-current", "true"); - await folderToggle.click(); + await expect(folder.locator("[data-project-overview]")).toHaveCount(0); + await expect(folderToggle).toHaveAttribute("aria-expanded", "true"); + await expect(featureToggle).toHaveAttribute("aria-expanded", "true"); await expect(folder.locator(`[data-checkout-agents-open] [data-pane="${notesPane}"]`)).toBeVisible(); await expect(folder.locator("[data-project-status]")).toBeVisible(); // B7: an agent that reported no elapsed time draws none rather than a made-up 0s. @@ -290,6 +357,7 @@ test("the Projects tab: kind, age, status badges, opened checkouts and folded pr await projectToggle.click(); await expect(projectToggle).toHaveAttribute("aria-expanded", "false"); await expect(project.locator("[data-checkout]")).toHaveCount(0); + await expect(overview).toHaveCount(0); await open(page, daemon); await expect(projectToggle).toHaveAttribute("aria-expanded", "false"); await expect(project.locator("[data-checkout]")).toHaveCount(0); diff --git a/web/scripts/gen-types.mjs b/web/scripts/gen-types.mjs index 288b02a282..f04403a999 100644 --- a/web/scripts/gen-types.mjs +++ b/web/scripts/gen-types.mjs @@ -7,7 +7,7 @@ import { compile } from 'json-schema-to-typescript'; // frames that cross the socket. A snapshot section the contract declares is a // $def no frame references, so each one the web reads is named here and // emitted beside the root, with the $defs it refers to. -const SNAPSHOT_DEFS = ['providerUsage', 'uiStateUsageHints']; +const SNAPSHOT_DEFS = ['providerUsage', 'uiStateUsageHints', 'focusCheckoutPayload']; const root = path.resolve(process.cwd(), '..'); const schema = JSON.parse(fs.readFileSync(path.join(root, 'contracts/hided-ws.schema.json'), 'utf8')); diff --git a/web/src/App.tsx b/web/src/App.tsx index 86008fcc93..0ba4770e9a 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -266,6 +266,10 @@ function CenterScreen({ actions }: { actions: Actions }) { useEffect(() => { if (!opening || opening.failure || progress === null) return; const store = useUiStore.getState(); + if (progress === "cancelled") { + store.setOpening(null); + return; + } if (progress === "landed") { store.setOpening(null); store.setScreen({ kind: "workspace" }); diff --git a/web/src/actions.ts b/web/src/actions.ts index b8abd22ce2..31027aea99 100644 --- a/web/src/actions.ts +++ b/web/src/actions.ts @@ -2,7 +2,7 @@ // the same code against the same snapshot. Each action is one core event // (dispatch is fire-and-forget; a sequence would arrive as several frames). -import type { UiStateUsageHints } from "./generated/hided-ws"; +import type { FocusCheckoutPayload, UiStateUsageHints } from "./generated/hided-ws"; import type { ThemeChoice } from "./theme"; import type { HostKind } from "./host"; import { @@ -210,7 +210,7 @@ export function createActions(dispatch: DispatchFn) { * A project or checkout row. On a selected SSH device a project can hold * several Herdr workspaces, and the checkout names the one to focus. */ - const focusCheckout = (workspaceId: string, checkoutId: string) => { + const focusCheckout = (workspaceId: string, checkoutId: string, expanded?: FocusCheckoutPayload["expanded"]) => { const context = remoteContext(rest()); if (context) { const host = remoteHost("Switching workspace"); @@ -229,7 +229,7 @@ export function createActions(dispatch: DispatchFn) { sendRemote(host.targetId, { action: "focus_workspace", workspace_id: workspaceId, checkout_id: checkoutId }); return; } - dispatch({ schema_version: 2, kind: "focus_checkout", payload: { workspace_id: workspaceId, checkout_id: checkoutId } }); + dispatch({ schema_version: 2, kind: "focus_checkout", payload: { workspace_id: workspaceId, checkout_id: checkoutId, ...(expanded === undefined ? {} : { expanded }) } }); }; /** @@ -846,16 +846,16 @@ export function createActions(dispatch: DispatchFn) { * also brings its device forward, so a refusal moves neither. The screen * follows once the core has moved there (`opening`). */ - openWorkspace(deviceId: string, workspaceId: string, checkoutId: string) { + openWorkspace(deviceId: string, workspaceId: string, checkoutId: string, expanded?: FocusCheckoutPayload["expanded"]) { const path = (deviceId === "local" ? rest()?.navigator?.workspaces : rest()?.status?.remote?.find((row) => row.target_id === deviceId)?.session?.workspaces) ?.flatMap((row) => row.checkouts) .find((row) => row.id === checkoutId)?.path ?? null; - beginOpening({ checkoutId, deviceId, path }); + beginOpening({ checkoutId, deviceId, path, workspaceId, expanded }); const front = rest()?.navigator?.focused_device_id ?? "local"; - if (front === deviceId) return focusCheckout(workspaceId, checkoutId); + if (front === deviceId) return focusCheckout(workspaceId, checkoutId, expanded); if (deviceId === "local") { - dispatch({ schema_version: 2, kind: "focus_checkout", payload: { workspace_id: workspaceId, checkout_id: checkoutId, focus_device: true } }); + dispatch({ schema_version: 2, kind: "focus_checkout", payload: { workspace_id: workspaceId, checkout_id: checkoutId, focus_device: true, ...(expanded === undefined ? {} : { expanded }) } }); return; } // A registered device project Herdr has no workspace in yet is opened @@ -1014,7 +1014,7 @@ export function createActions(dispatch: DispatchFn) { const focusDevice = (rest()?.navigator?.focused_device_id ?? "local") !== "local" ? { focus_device: true } : {}; const ids = { workspace_id: surface.workspaceId, checkout_id: surface.checkoutId }; expectSurface(surface.key); - beginOpening({ checkoutId: checkout.id, deviceId: "local", path: checkout.path }); + beginOpening({ checkoutId: checkout.id, deviceId: "local", path: checkout.path, workspaceId: surface.workspaceId }); if (surface.kind === "herdr") { dispatch({ schema_version: 2, kind: "focus_tab", payload: { ...ids, tab_id: surface.id, ...focusDevice } }); return; diff --git a/web/src/generated/hided-ws.ts b/web/src/generated/hided-ws.ts index 105991234a..488ef9ebcd 100644 --- a/web/src/generated/hided-ws.ts +++ b/web/src/generated/hided-ws.ts @@ -147,3 +147,13 @@ export interface UiStateUsageHints { usage_popover_open?: boolean; [k: string]: unknown; } +/** + * focus_checkout: one admitted focus and optional sidebar disclosure transition. Unknown workspace/checkout refuses the disclosure intent before either value changes. + */ +export interface FocusCheckoutPayload { + workspace_id: string; + checkout_id: string; + focus_device?: boolean; + display_id?: string; + expanded?: boolean; +} diff --git a/web/src/navigation.test.ts b/web/src/navigation.test.ts index c1dff992c6..543d37b4d3 100644 --- a/web/src/navigation.test.ts +++ b/web/src/navigation.test.ts @@ -182,6 +182,25 @@ describe("an open from Main or an Overview", () => { expect(openingProgress(rest("c2"), toPane)).toBe("landed"); }); + it("waits for focus and disclosure together when returning from Overview", () => { + const opening = { target: { workspaceId: "w", checkoutId: "c2", deviceId: "local", path: "/w2", expanded: true }, errorBefore: null, failure: null }; + // Focus can already match while Overview is visible; the old folded snapshot cannot land. + expect(openingProgress(rest("c2"), opening)).toBeNull(); + const accepted = { ...rest("c2"), ui_state: { expanded_checkout_ids: ["c2"] } } as unknown as SnapshotRest; + expect(openingProgress(accepted, opening)).toBe("landed"); + expect(openingProgress({ ...accepted, navigator: rest("c1").navigator }, opening)).toBeNull(); + }); + + it("silently cancels a vanished local row, with or without agents", () => { + for (const expanded of [true, undefined]) { + const opening = { target: { workspaceId: "w", checkoutId: "gone", deviceId: "local", path: "/gone", expanded }, errorBefore: null, failure: null }; + expect(openingProgress(rest("c1"), opening)).toBe("cancelled"); + expect(openingProgress(null, opening)).toBeNull(); + } + const wrongProject = { target: { workspaceId: "gone", checkoutId: "c1", deviceId: "local", path: "/w" }, errorBefore: null, failure: null }; + expect(openingProgress(rest("c1"), wrongProject)).toBe("cancelled"); + }); + it("reads a newer core error as the refusal and ignores the one from before", () => { const opening = { target: { checkoutId: "c2", deviceId: "local", path: "/w2" }, errorBefore: 5, failure: null }; expect(openingProgress(rest("c1", 5), opening)).toBeNull(); diff --git a/web/src/navigation.ts b/web/src/navigation.ts index 2ed4267e5f..73398724e9 100644 --- a/web/src/navigation.ts +++ b/web/src/navigation.ts @@ -373,7 +373,7 @@ export function startupScreen(rest: SnapshotRest | null, hasFront: boolean): "wo } /** What All projects, an Overview or the Agents list asked to bring forward (B2, B12, B21). */ -export type OpenTarget = { checkoutId: string; deviceId: string; path: string | null } | { paneId: string }; +export type OpenTarget = { checkoutId: string; deviceId: string; path: string | null; workspaceId?: string; expanded?: boolean } | { paneId: string }; /** * A Workspace or agent asked for and not yet in front. The screen changes @@ -391,14 +391,18 @@ export function openingLanded(rest: SnapshotRest | null, target: OpenTarget): bo const front = frontCheckout(rest); if (!front) return false; if ("paneId" in target) return front.tabs.some((tab) => tab.panes.some((pane) => pane.id === target.paneId)); + if (target.expanded !== undefined && (rest?.ui_state?.expanded_checkout_ids ?? []).includes(target.checkoutId) !== target.expanded) return false; if (front.id === target.checkoutId) return true; // A device project with no Herdr workspace yet gets one at its folder, under a new id. return target.path !== null && front.path === target.path && (rest?.navigator?.focused_device_id ?? "local") === target.deviceId; } -/** Where an open stands: "landed", the core's refusal, or null while it is on its way. */ +/** A vanished local target is cancelled silently; other refusals keep their existing message. */ export function openingProgress(rest: SnapshotRest | null, opening: Opening): "landed" | string | null { - if (openingLanded(rest, opening.target)) return "landed"; + const target = opening.target; + if (rest?.navigator?.workspaces && "checkoutId" in target && target.deviceId === "local" && target.workspaceId !== undefined + && !rest.navigator.workspaces.some((workspace) => workspace.id === target.workspaceId && workspace.checkouts.some((checkout) => checkout.id === target.checkoutId))) return "cancelled"; + if (openingLanded(rest, target)) return "landed"; const error = rest?.status?.last_error; if (error && error.occurred_at !== opening.errorBefore) return error.message; return null; diff --git a/web/src/projects.test.ts b/web/src/projects.test.ts index 6147de87b8..80e1855803 100644 --- a/web/src/projects.test.ts +++ b/web/src/projects.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from "vitest"; -import { checkoutPresentation, projectMarks, projectRows, pullRequestBadge, relativeActivity } from "./projects"; +import { checkoutRowExpansion, overviewRowSelected, checkoutPresentation, projectMarks, projectRows, pullRequestBadge, relativeActivity } from "./projects"; import type { Checkout, GithubStatus, PullRequest, Workspace } from "./snapshot"; function workspace(id: string, extra: Partial = {}): Workspace { @@ -147,3 +147,21 @@ describe("projectMarks", () => { expect(projectMarks(project)).toEqual({ ...NO_MARKS, question: 2, working: 3, idle: 2 }); }); }); + +describe("sidebar row activation", () => { + it("opens folded rows and preserves an expanded row when returning from another scope", () => { + expect(checkoutRowExpansion(true, false, false)).toBe(true); + expect(checkoutRowExpansion(true, true, false)).toBe(true); + expect(checkoutRowExpansion(true, false, true)).toBe(true); + expect(checkoutRowExpansion(true, true, true)).toBe(false); + expect(checkoutRowExpansion(false, true, true)).toBeUndefined(); + }); + + it("selects the Git project's Overview child only for its own Overview", () => { + const project = workspace("repo", { is_git: true }); + expect(overviewRowSelected(project, "repo")).toBe(true); + expect(overviewRowSelected(project, "other")).toBe(false); + expect(overviewRowSelected(project, null)).toBe(false); + expect(overviewRowSelected(workspace("notes", { is_git: false }), "notes")).toBe(false); + }); +}); diff --git a/web/src/projects.ts b/web/src/projects.ts index 26eb5272ef..09e7f11d0a 100644 --- a/web/src/projects.ts +++ b/web/src/projects.ts @@ -203,3 +203,13 @@ export function checkoutPresentation(workspace: Workspace, checkout: Checkout, n detail: lines.join("\n"), }; } + +/** A sidebar activation opens agents unless this Workspace is already open and unfolded. */ +export function checkoutRowExpansion(foldable: boolean, workspaceSelected: boolean, expanded: boolean): boolean | undefined { + return foldable ? !(workspaceSelected && expanded) : undefined; +} + +/** Git project headings navigate too, but only their Overview child owns selection. */ +export function overviewRowSelected(workspace: Workspace, overviewProjectId: string | null): boolean { + return workspace.is_git === true && workspace.id === overviewProjectId; +} diff --git a/web/src/sidebar.tsx b/web/src/sidebar.tsx index bd9f6a81de..866258b688 100644 --- a/web/src/sidebar.tsx +++ b/web/src/sidebar.tsx @@ -11,6 +11,7 @@ import { GitPullRequestIcon, HouseIcon, LayoutGridIcon, + LayoutDashboardIcon, SettingsIcon, } from "lucide-react"; import { memo, useMemo, type ReactNode } from "react"; @@ -32,6 +33,8 @@ import { agentPlaces, agentSections, allAgents, allProjectsCount, liveDescendant import { activeCheckouts, checkoutPresentation, + checkoutRowExpansion, + overviewRowSelected, folderCheckout, inactiveCheckouts, projectMarks, @@ -473,7 +476,7 @@ function WorkspaceRows({ workspace, level, context }: { workspace: Workspace; le ); } const ProjectIcon = workspace.is_git ? FolderGit2Icon : FolderIcon; - const selected = context.overviewProjectId === workspace.id; + const selected = overviewRowSelected(workspace, context.overviewProjectId); const marks = projectMarks(workspace); const checkoutRow = (checkout: Checkout) => (
+ + ); +} + const NO_BOARD_ROWS: BoardRow[] = []; const KIND_ICON: Record = { @@ -629,6 +654,7 @@ const CheckoutRowView = memo(function CheckoutRowView({ focused={focused} label={[name, open ? null : badgeWords(marks), view.age, purpose].filter(Boolean).join(", ")} actions={actions} + expanded={checkoutRowExpansion(foldable, context.workspaceScreen && focused, open)} /> {/* The row button covers the whole row; a control drawn over it is positioned, so it stacks above. */} @@ -714,6 +740,7 @@ const FolderRowView = memo(function FolderRowView({ focused={focused} label={[workspace.label, badgeWords(marks), purpose].filter(Boolean).join(", ")} actions={actions} + expanded={checkoutRowExpansion(foldable, context.workspaceScreen && focused, open)} />