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
14 changes: 10 additions & 4 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -514,10 +514,16 @@ during the wait.
- `GET /api/projects` re-authorizes registered roots with `allowFileRoot()` —
the in-memory browse allowlist does not survive restarts, and empty managed
projects derive no root from sessions.
- The client sorts the merged list by most-recently-added (registration
order), then by path for session-discovered projects
(`lib/project-ordering.ts`); the order deliberately does NOT depend on
session activity, so project rows never jump around while sessions refresh.
- By default (sort "None") the client orders the merged list manually
(`sortOrder`, set by drag/Move up/down), then most-recently-added, then by
path (`lib/project-ordering.ts`), so rows never jump while sessions refresh.
The header sort button (`omp-web:project-sort` in `localStorage`, per
browser) switches to Alphabetical (label A→Z) or Last updated (newest last
message first: `lastMessageAt` from the session tail scan, else the file
mtime) — the latter deliberately reorders on activity. While a
sort is active, rows get a pin toggle: pinned projects (`pinOrder` in the
registry, pinned to the end of the group) lead in their own manual order and
alone keep Move up/down and drag; pins are ignored under "None".
Expanded project paths live
in `localStorage` (`omp-web:expanded-projects`), defaulting to only the
active/restored project expanded, and stale keys are pruned against the
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ All notable changes to **omp-web** (`@kahme247/ompweb`) are documented in this f
- **On desktop, notifications open from a bell in the top bar**, left of the right-panel toggle. The bell shows the unread count and opens a floating panel with the notification history, **Mark all as read** and **Clear**; the list scrolls inside a panel of limited width and height. Opening a notification closes the panel, and closing it marks the shown notifications as read. The right panel's Notifications tab and the right-panel toggle's unread count remain on phones only.
- On phones and narrow windows, the top bar's tools menu is only as wide as its buttons instead of spanning the screen, and its **System** button opens the system prompt again. The prompt panel used to open inside the menu's sideways-scrolling strip, which clipped it out of view.

### Sidebar

- **Sort and pin workspaces.** A sort button next to the workspace search switches between None (your manual order), Alphabetical and Last updated (the workspace whose session got the newest message first). While a sort is active, each workspace has a pin button: pinned workspaces stay at the top in the order you give them with Move up, Move down or dragging, and newly pinned ones join the end of that group. Unpinned workspaces follow the sort and cannot be moved by hand. The sort is remembered per browser; pins are stored with the workspace list. (#271)

---

## [v0.5.2] - 2026-10-15
Expand Down
28 changes: 16 additions & 12 deletions app/api/projects/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ function parseLaunchConfig(value: unknown): ProjectLaunchConfig | undefined {

// GET /api/projects → { projects: ManagedProject[] }
// Registered (non-hidden) projects plus session-discovered projects, excluding
// hidden entries. Session-discovered paths get no addedAt; the client orders
// the merged list by most-recently-added (registration order), then by path —
// deliberately not by session activity, which would reorder rows on refresh.
// hidden entries. Session-discovered paths get no addedAt; the client applies
// the ordering (manual / most-recently-added by default, or the user's chosen
// sort with pins first — see lib/project-ordering.ts).
export async function GET() {
try {
const registry = loadProjectRegistry();
Expand Down Expand Up @@ -91,7 +91,7 @@ export async function POST(req: Request) {
}

// PATCH /api/projects
// Single shape: { cwd, alias?, sortOrder? } Batch shape: { updates: [{ cwd, alias?, sortOrder? }, ...] }
// Single shape: { cwd, alias?, sortOrder?, pinOrder? } Batch shape: { updates: [{ cwd, alias?, sortOrder?, pinOrder? }, ...] }
// Applied atomically in one registry load/save so a drag reorder (one request,
// many entries) can never interleave with another writer and lose updates.
// Renaming or ordering a project is an explicit act of managing it: paths that
Expand All @@ -105,13 +105,14 @@ export async function PATCH(req: Request) {
cwd?: unknown;
alias?: unknown;
sortOrder?: unknown;
pinOrder?: unknown;
launchConfig?: unknown;
updates?: unknown;
};
const rawUpdates: unknown[] = Array.isArray(body.updates)
? body.updates
: body.cwd !== undefined || body.alias !== undefined || body.sortOrder !== undefined || body.launchConfig !== undefined
? [{ cwd: body.cwd, alias: body.alias, sortOrder: body.sortOrder, launchConfig: body.launchConfig }]
: body.cwd !== undefined || body.alias !== undefined || body.sortOrder !== undefined || body.pinOrder !== undefined || body.launchConfig !== undefined
? [{ cwd: body.cwd, alias: body.alias, sortOrder: body.sortOrder, pinOrder: body.pinOrder, launchConfig: body.launchConfig }]
: [];
if (rawUpdates.length === 0) {
return NextResponse.json({ error: "Path is required", code: "path_required" }, { status: 400 });
Expand All @@ -138,16 +139,18 @@ export async function PATCH(req: Request) {
return match ? match.path : null;
};

const parsed: Array<{ path: string; alias?: string | null; sortOrder?: number | null; launchConfig?: ProjectLaunchConfig | null }> = [];
const parsed: Array<{ path: string; alias?: string | null; sortOrder?: number | null; pinOrder?: number | null; launchConfig?: ProjectLaunchConfig | null }> = [];
const skipped: Array<{ cwd: string; code: string; error: string }> = [];
for (const item of rawUpdates) {
const entry = item as { cwd?: unknown; alias?: unknown; sortOrder?: unknown; launchConfig?: unknown };
const entry = item as { cwd?: unknown; alias?: unknown; sortOrder?: unknown; pinOrder?: unknown; launchConfig?: unknown };
const cwd = typeof entry.cwd === "string" ? entry.cwd.trim() : "";
if (!cwd) return NextResponse.json({ error: "Path is required", code: "path_required" }, { status: 400 });
const alias = entry.alias === null ? null : typeof entry.alias === "string" ? entry.alias : undefined;
const sortOrder = entry.sortOrder === null ? null : typeof entry.sortOrder === "number" && Number.isFinite(entry.sortOrder) ? entry.sortOrder : undefined;
const pinOrder = entry.pinOrder === null ? null : typeof entry.pinOrder === "number" && Number.isFinite(entry.pinOrder) ? entry.pinOrder : undefined;
if (entry.alias !== undefined && alias === undefined) return NextResponse.json({ error: "Alias must be a string", code: "invalid_alias" }, { status: 400 });
if (entry.sortOrder !== undefined && sortOrder === undefined) return NextResponse.json({ error: "Sort order must be a number", code: "invalid_sort_order" }, { status: 400 });
if (entry.pinOrder !== undefined && pinOrder === undefined) return NextResponse.json({ error: "Pin order must be a number", code: "invalid_pin_order" }, { status: 400 });
const launchConfig = entry.launchConfig === null ? null : parseLaunchConfig(entry.launchConfig);
// Same existence/directory checks as POST: an auto-registering endpoint
// must never persist ghost entries for deleted paths, plain files, or
Expand All @@ -158,7 +161,7 @@ export async function PATCH(req: Request) {
// workspace stays reorderable/renamable even after its directory is removed.
const managedPath = isAlreadyManaged(cwd);
if (managedPath) {
parsed.push({ path: managedPath, alias, sortOrder, launchConfig });
parsed.push({ path: managedPath, alias, sortOrder, pinOrder, launchConfig });
continue;
}
let normalized: string;
Expand All @@ -185,7 +188,7 @@ export async function PATCH(req: Request) {
}
throw error;
}
parsed.push({ path: projectRoot, alias, sortOrder, launchConfig });
parsed.push({ path: projectRoot, alias, sortOrder, pinOrder, launchConfig });
}
// Bulk path: every entry was a ghost — propagate the first failure so the
// client gets a meaningful 400 instead of a misleading 200 with no changes.
Expand All @@ -196,14 +199,15 @@ export async function PATCH(req: Request) {

// Duplicate targets within one batch merge per-field (later defined
// fields win) instead of the whole later update replacing the earlier.
const merged = new Map<string, { path: string; alias?: string | null; sortOrder?: number | null; launchConfig?: ProjectLaunchConfig | null }>();
const merged = new Map<string, { path: string; alias?: string | null; sortOrder?: number | null; pinOrder?: number | null; launchConfig?: ProjectLaunchConfig | null }>();
for (const update of parsed) {
const key = comparableProjectPath(update.path);
const previous = merged.get(key);
merged.set(key, previous ? {
path: previous.path,
alias: update.alias !== undefined ? update.alias : previous.alias,
sortOrder: update.sortOrder !== undefined ? update.sortOrder : previous.sortOrder,
pinOrder: update.pinOrder !== undefined ? update.pinOrder : previous.pinOrder,
launchConfig: update.launchConfig !== undefined ? update.launchConfig : previous.launchConfig,
} : update);
}
Expand Down Expand Up @@ -232,7 +236,7 @@ export async function PATCH(req: Request) {
const updatedKeys = new Set(updates.map((update) => comparableProjectPath(update.path)));
const projects = next.projects
.filter((entry) => updatedKeys.has(comparableProjectPath(entry.path)))
.map((entry) => ({ path: entry.path, addedAt: entry.addedAt, hidden: entry.hidden, alias: entry.alias, sortOrder: entry.sortOrder, launchConfig: entry.launchConfig }));
.map((entry) => ({ path: entry.path, addedAt: entry.addedAt, hidden: entry.hidden, alias: entry.alias, sortOrder: entry.sortOrder, pinOrder: entry.pinOrder, launchConfig: entry.launchConfig }));
return NextResponse.json({ projects });
} catch (error) {
if (error instanceof ProjectPathError) {
Expand Down
8 changes: 5 additions & 3 deletions app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -1614,16 +1614,18 @@ html[data-touch-targets="accessible"] :is(.image-lightbox-stepper button, .image
height: 24px;
}
.sidebar-project-actions {
/* Match the session status column after reserving timestamp + menu space. */
width: 46px;
/* Match the session status column after reserving timestamp + menu space;
grows when the pin toggle sits beside the menu. */
min-width: 46px;
display: flex;
justify-content: flex-end;
gap: 2px;
}

/* Touch rows keep the compact timestamp immediately beside a full-size menu target. */
@media (hover: none), (pointer: coarse) {
.sidebar-project-actions {
width: 56px;
min-width: 56px;
}
.sidebar-icon-button,
.sidebar-project-action,
Expand Down
22 changes: 16 additions & 6 deletions components/SessionSidebar-chrome.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import { useCallback, useEffect, useLayoutEffect, useRef, useState, type CSSProperties, type ReactNode, type RefObject } from "react";
import { useCallback, useEffect, useLayoutEffect, useRef, useState, type CSSProperties, type ReactNode, type Ref, type RefObject } from "react";
import { createPortal } from "react-dom";
import { useI18n } from "@/lib/i18n";
import { usePrefersReducedMotion } from "@/hooks/usePrefersReducedMotion";
Expand Down Expand Up @@ -36,32 +36,40 @@ const SIDEBAR_BUTTON_TRANSITION = "background var(--dur-fast) var(--ease-out-war

/** Quiet square icon button used across the sidebar chrome (header, section
* headers, footer). Stays visually subdued; the accent appears on hover and
* when active (e.g. an applied filter). */
* when active (e.g. an applied filter). `menuExpanded` makes it a menu
* trigger (aria-haspopup/aria-expanded instead of aria-pressed). */
function SidebarIconButton({
ref,
label,
title,
onClick,
active = false,
menuExpanded,
disabled = false,
children,
}: {
ref?: Ref<HTMLButtonElement>;
label: string;
title?: string;
onClick: () => void;
active?: boolean;
menuExpanded?: boolean;
disabled?: boolean;
children: ReactNode;
}) {
const [hovered, setHovered] = useState(false);
return (
<button
ref={ref}
type="button"
className="sidebar-icon-button"
aria-label={label}
title={title ?? label}
onClick={onClick}
disabled={disabled}
aria-pressed={active}
{...(menuExpanded === undefined
? { "aria-pressed": active }
: { "aria-haspopup": "menu" as const, "aria-expanded": menuExpanded })}
style={{
display: "flex", alignItems: "center", justifyContent: "center",
width: 26, height: 26, padding: 0, flexShrink: 0, lineHeight: 0,
Expand Down Expand Up @@ -184,8 +192,10 @@ function SidebarPortalMenu({
useEffect(() => {
if (!open) return;
const timer = setTimeout(() => {
const firstBtn = menuRef.current?.querySelector<HTMLButtonElement>("button:not([disabled])");
firstBtn?.focus();
// A radio menu opens on its checked item.
const menu = menuRef.current;
(menu?.querySelector<HTMLButtonElement>('button[aria-checked="true"]:not([disabled])')
?? menu?.querySelector<HTMLButtonElement>("button:not([disabled])"))?.focus();
}, 0);
const onPointerDown = (e: MouseEvent | TouchEvent) => {
const target = e.target as Node;
Expand Down Expand Up @@ -231,7 +241,7 @@ function SidebarPortalMenu({
// before the item's own onClick runs, and React then drops that click.
onClick={(event) => {
const target = event.target;
if (target instanceof Element && target.closest('[role="menuitem"]')) closeAndRestore();
if (target instanceof Element && target.closest('[role^="menuitem"]')) closeAndRestore();
}}
role="menu"
style={{
Expand Down
24 changes: 24 additions & 0 deletions components/SessionSidebar-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { SessionInfo } from "@/lib/types";
import type { ProjectSortMode } from "@/lib/project-ordering";
import { comparableProjectPath } from "@/lib/comparable-path";
interface WorktreeEntry {
path: string;
Expand Down Expand Up @@ -102,6 +103,27 @@ function saveExpandedProjects(paths: Set<string>): void {
// ignore storage quota / privacy-mode errors
}
}
const PROJECT_SORT_STORAGE_KEY = "omp-web:project-sort";

function loadProjectSortMode(): ProjectSortMode {
if (typeof window === "undefined") return "none";
try {
const raw = window.localStorage.getItem(PROJECT_SORT_STORAGE_KEY);
return raw === "alphabetical" || raw === "updated" ? raw : "none";
} catch {
return "none";
}
}

function saveProjectSortMode(mode: ProjectSortMode): void {
if (typeof window === "undefined") return;
try {
if (mode === "none") window.localStorage.removeItem(PROJECT_SORT_STORAGE_KEY);
else window.localStorage.setItem(PROJECT_SORT_STORAGE_KEY, mode);
} catch {
// ignore storage quota / privacy-mode errors
}
}
/** Substitute the home dir prefix with ~ (no path truncation — see PathLabel) */
function displayCwd(cwd: string, homeDir?: string): string {
return (homeDir && cwd.startsWith(homeDir)) ? "~" + cwd.slice(homeDir.length) : cwd;
Expand Down Expand Up @@ -191,10 +213,12 @@ export {
displayCwd,
formatRelativeTime,
loadExpandedProjects,
loadProjectSortMode,
loadUnreadSessionIds,
normalizeProjectKey,
projectLabel,
saveExpandedProjects,
saveProjectSortMode,
saveUnreadSessionIds,
type SessionTreeNode,
type WorktreeContext,
Expand Down
Loading
Loading