# dsh-sidebar-entries

[![npm version](https://img.shields.io/npm/v/dsh-sidebar-entries)](https://www.npmjs.com/package/dsh-sidebar-entries)

A [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) plugin that makes the
left sidebar behave the way a long list should: **drag to reorder** the panel icons, **one
arrow to fold them all away** so the workspace / session list gets its height back, a
**pinned-session section** at the top of the workspace list, and a **generic lift** that pulls
every plugin's sidebar-footer entry up into the same rail so nothing is split between the top
and the bottom of the column.

The sidebar panel list is a stack of icon rows (`插件`, `插件市场`, `自动化任务`, …). Once a
handful of plugins are installed the stack eats the column and pushes the session list into a
narrow strip. This plugin adds three things to that stack:

- **Long-press drag to reorder.** Press an icon for ~0.3 s, then drag. The row lifts and follows
  the cursor; the neighbours slide out of the way with a short FLIP animation; the order is
  written to `localStorage` on release. A short click still selects the panel — only a deliberate
  long press starts a drag, so nothing navigates by accident.
- **A fold arrow at the top of the list.** A plain chevron (`v` when everything is shown, `^`
  when folded) that hides every panel icon in one click. The state survives a reload. The arrow
  itself never moves and can never be dragged, so there is always a way back.
- **Footer entries lifted into the rail.** Any plugin that registers an action in the sidebar
  footer gets a row up here automatically — see below.

And one thing to the list below it:

- **A 置顶 section.** Pinned Sessions are gathered into one group at the very top of the
  workspace list and their originals are hidden, so a pinned Session appears exactly once no
  matter which workspace it belongs to. Unpinning from the copy works; the copy is rebuilt
  whenever the store changes.

## Layout

```
lib/index.js     host half  — diagnostics routes (see below), no runtime dependencies
lib/client.js    browser half — wraps in window.__ModuleLoader__.load; requires('react') from the host
cordis.patch.yml bundle patch — inserts the host row under the id `sidebar-entries`
```

The two halves are independent: the browser half is the actual feature, the host half only
provides the `/sidebar-entries/*` routes used for self-diagnostics and for hot-reloading the
client bundle while developing.

## How the reordering works (and why it is done in the DOM)

DeepSeek Harness ships a pin/unpin model for sidebar panels (`createPanelPins`), but it is
memory-only — it resets on every reload — and it permanently pins the `plugins` row. This plugin
therefore keeps its own order in `localStorage` (`dse.sidebar.order.v2`) and replays it onto the
list on every render:

- rows are identified by `aria-label`, grouped so that two rows sharing a label move together and
  keep their relative order;
- the "More" row is never draggable and never moves — it is the insertion anchor;
- a `MutationObserver` on the list re-applies the saved order after React re-renders, with an
  "already in order → do nothing" short-circuit so the plugin cannot ping-pong with itself.

Nothing in the shipped app is patched; the plugin only manipulates the rendered list.

## How the pinned section works

The shipped list already sorts pinned Sessions to the front of *their own* group, but they stay
scattered across workspaces. This plugin lifts them into one group:

- a `MutationObserver` on `[class*=listArea]` re-derives everything after each render;
- whether a row is pinned is read from the pin indicator the row component itself renders, so no
  cached list can drift out of date;
- the original rows are `display:none` (not removed — React owns them), and a copy of each is
  appended to a `置顶` section inserted as the first child of the list area;
- a copy carries the markup but none of React's handlers, so a click on one is replayed on the
  same element of the original by walking the child index path;
- the exception is the pin toggle: clicking it in a copy calls `uiWorkspace.unpinSession(id)`
  directly, the same service the shipped button calls. Replaying a click into a row that is
  currently `display:none` is exactly what made "取消置顶" dead from inside the section;
- the copy's `⋯` menu button is hidden rather than removed: that menu anchors on its own button,
  which now sits inside a hidden row, and hiding keeps the child indexes aligned for the replay.

## Storage keys

| key | meaning |
| --- | --- |
| `dse.sidebar.order.v2` | JSON array of panel ids, in the user's order |
| `dse.sidebar.collapsed.v1` | `'1'` when the panel icons are folded away |

Both live in the web app's `localStorage`. Clearing site data resets the plugin to defaults.

## Footer entries are lifted into the rail

Any button rendered in the sidebar footer (`sidebar.footer.action`, or a plugin that injects its
own button into the footer container) is pulled up into the rail automatically. The plugin builds a
stand-in row from the footer button itself — same label, a copy of its own icon — and only then
hides the original with `[data-dse-lifted]{display:none}`. If the lift ever fails, the button stays
where it was, so a plugin installed tomorrow needs no change in this one.

- The row forwards its click to the original control, so whatever panel the plugin opens still
  opens; the plugin does not need to be known by name.
- The pass is driven by a `MutationObserver` on `document.body` and re-checks which footer
  controls exist, so a plugin that mounts its footer entry late is still picked up.
- An uninstall or a client rebuild removes the stand-in rows **and** clears `data-dse-lifted`, so
  a footer control can never be left permanently hidden by a stale attribute.

## The one built-in row

**文献** — opens the literature plugin's panel. The literature plugin moves its own entry into the
right sidebar when it detects a `betterSidebar` service, and does not move it back when the service
later disappears, so its footer button is sometimes gone entirely; this row tries the footer
button, then the dock tab it migrated into, then the service itself. It degrades quietly when the
literature plugin is not installed.

## Install

```bash
dsh plugin --profile web add dsh-sidebar-entries
```

Restart the web app once so the bundle patch layer is picked up, then reload the page.

## Diagnostics

While developing, the host half exposes four routes. They are intentionally unauthenticated —
they only read in-memory state and only mutate the client bundle revision.

| route | purpose |
| --- | --- |
| `GET /sidebar-entries/ping` | liveness + version |
| `GET /sidebar-entries/graph` | client modules visible to the host, and this package's resolved client path |
| `GET/POST /sidebar-entries/log` | last 20 client reports (drag start/end, panel state) |
| `POST /sidebar-entries/reload` | rebuild this package's client bundle (hot reload, no restart) |

Client reports are only sent when `window.__dseDebug` is set, except for the handful of events
that are always sent (drag start/end) — those are what make the drag verifiable without a
browser automation harness.

## License

MIT
