# 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, and a
**pinned-session section** at the top of the workspace list.

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 two 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.

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. That is what keeps "取消置顶"
  working 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.

## The three extra entries

Besides reordering, the plugin adds rows to the list for actions that are otherwise only
reachable from the sidebar footer. The footer button is hidden by a CSS rule so the rail stays
one column — these rows *are* those actions, just moved up:

- **文献** — 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; this row tries the footer button, then the dock tab it migrated into,
  then the service itself.
- **插件市场 (dsh-m)** — opens the `dsh-m` marketplace panel. The label carries the plugin name
  because `dshmarket` and `dsh-m` are two different plugins that both call themselves
  `插件市场`; without the suffix the two rows are indistinguishable.
- **远程访问** — clicks the remote-access (tunnel / pairing) trigger that lives in the footer.

All three degrade quietly: if the corresponding plugin is not installed, the row does nothing.

## 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
