# 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's panel list behave the way a long list should: **drag to reorder**, and **one
arrow to fold every panel icon away** so the workspace / session list gets the height back.

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.

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

## 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 two extra entries

Besides reordering, the plugin can add two rows to the list that are otherwise only reachable
from the sidebar footer:

- **文献** — opens the literature plugin's panel (falls back to the plugin's own service if its
  footer button is not present).
- **插件市场 (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.

Both 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
