dsh-data-window
simons-jiang/dsh-data-window
数据库窗口:从工作区自己的配置解析出各环境的主机与账号,树里能看到实例、库、表与字段,F4 直接查看建表语句,每个库都有自己的只读 SQL 工作台。
安装
dsh plugin --profile web add github:simons-jiang/dsh-data-windowREADME
dsh-data-window
A database window for DeepSeek Harness. For a normal project it asks for no connection at all: it reads the workspace's own Spring/Nacos configuration, resolves each environment's host and credentials from the local Nacos snapshot cache, and adds it to one browsable tree shared by every workspace, plus one read-only SQL workbench per database. When a project's configuration cannot be resolved, a model or the user can supply the connection — and either way it is proven with a real read-only connection before it enters the tree.
Features
- Workspace-driven discovery —
bootstrap.yml→ Nacos data-id → whichever data-id defines each${…}placeholder, resolved the way the JVM does it. No configuration file name is assumed. Only the data sources this project declares are shown; results are cached per workspace and refreshed when the files change. - One resource tree for the whole machine — a workspace's configuration only says how to find its databases. The tree is the union of every workspace opened so far plus the shared manual connections and database picks, so switching workspace adds that workspace's hosts instead of replacing the tree; the environments it contributes open automatically. Discovery caches and SQL consoles stay per workspace.
- AI fallback when the rules find nothing — a workspace whose configuration shape the scan does not recognise can be analysed by a model configured in DSH. The model only proposes hosts and file/key paths; password values are redacted before they enter the prompt, the Host reads the secret itself, and every proposed address is proven with a real read-only connection before it joins an “AI” group in the tree. The model is chosen the first time (and changeable in settings).
- Pick the databases to show — the configured database is what the tree shows first; a per-instance picker (searchable checkboxes, configured ones locked on) chooses the other schemas, and the choice is shared by every workspace.
- Manual connections — a toolbar button adds a host/port/account/database by hand for databases described nowhere in the workspace (a local container, a shared test instance). The form can import a connection another workspace already resolved — host, port, account and schema filled in, the password reused from the Host so it is never shown — because teams share one RDS endpoint across projects. The connection is tested before it is saved, entries are grouped by environment name (imported ones inherit the source's name; a manual environment can be renamed later), and the tree's context menu can remove one connection or delete the whole environment (re-importable from another workspace's data).
- Explorer — environments → instances → databases → tables → columns, with type, primary key, nullability and comment. One button reveals every schema on an instance, not only the configured ones. The column is draggable, and a double-click on the divider restores its default width.
- Editor with SQL colouring — keywords, data types, functions,
strings, numbers, constants, variables and comments each get their own colour, so
the language stands apart from the table and column names you wrote; typing
suggests tables, columns and keywords,
alias.narrows to that table's columns; one click reindents the statement. - AI SQL optimization from the editor — the editor's own context menu keeps undo/redo/cut/copy/paste/select-all and adds “AI optimize SQL”: the selection (or the whole statement) goes to the model configured in settings, and the suggestion opens in a dialog with a copy button. Both sides are formatted the way the console formats a statement, so the diff lines up. Nothing is executed or written back.
- Refresh structure — right-click a connection, database or table to re-read its structure (databases, tables or columns) without reloading the panel; an open DDL view for that table. Metadata only, never a write.
- Tab context menu — right-click a console tab to close it, close the tabs on
either side (or all of them), copy its reference (
schema.tableorschema), or put that reference into the chat composer when the chat input is open. - Saved SQL and a favorites tab — right-click a statement in the editor (or a
console tab) and choose “Save SQL” to keep it under a unique name together with
its schema and table. The resource manager has two tabs: the database tree and
★ Favorites, which groups the saved statements schema → table → name;
double-clicking one opens it in that schema's workbench.
Typing
@in the editor indexes them by name, and the chosen statement is inserted at the caret. Saving, renaming, copying and deleting never execute anything. - Paging for LIMIT queries — a statement ending in
LIMITgets previous/next controls whose page size is that limit; the next page is built as… LIMIT n OFFSET mand run without touching the editor. An empty next page ends the paging in place, leaving only “previous” available. - Create statement in one keystroke —
F4or⌘/Ctrl + Shift + Don a table opens it in a dialog with a copy button (no extra work tab) and the same SQL highlighting as the console; on a database the same key (or the context menu) reads the create statement of every table in it. - One workbench per database, kept as tabs, with a result grid, copy-as-TSV,
a row limit, a draggable editor/result split and a collapsible run log whose
height is dragged from its top edge (double-click resets it). Opening a
table's rows never overwrites SQL you already typed: a second console is added
instead. Values arrive as the server holds them — a
BIGINTid keeps all 19 digits, aDATEreads2026-10-26— each header names the type its table declares,varchar(32)anddecimal(13,2)included, and hovering it opens a card with the column's own comment. - Jump from SQL to the tree —
⌘/Ctrl+ click a table name in the editor: the explorer expands to that table, selects it, and its create statement opens right at the pointer. Qualified names (schema.table) resolve in the database they name; clicking a column, an alias or a keyword behaves as usual. - Dialogs that stay on top and close with Escape — every dialog (DDL, AI optimizer, cell detail, connection forms) is portalled to the page body, so a window another plugin docks below the editor cannot cover its buttons; Escape closes the top-most one, and never while a save is in flight.
- Export the page — the result bar exports the current page (with any local cell
edits) as an
.xlsxworkbook, a UTF-8 CSV, or an INSERT script. The save dialog lets you choose the path through the File System Access API, with a download fallback on hosts that do not expose it. - Editable cells, generated UPDATE — result rows are one fixed line high with
clipped cells; double-click edits a cell in place (Enter commits, Esc cancels),
and the context menu starts the same edit or copies the whole value (edited cells
turn blue); right-click copies a single-row
UPDATEbuilt from the edited columns and the original primary key. The statement is only copied, never executed, and it is refused for joins, subqueries or results without a primary key. - Read-only by construction — verb whitelist, one statement per request, a
write-keyword scan, and
SET SESSION TRANSACTION READ ONLYon every pooled connection so the server refuses a write even if the static check is ever wrong.
Install
cd dsh-data-window
npm install --omit=dev # mysql2, the only runtime dependency
node build.mjs # regenerate client.js from src/client/*.js
Then install the directory as a bundle (Plugins → Add plugin, or
plugin_manager install_bundle with this directory). The window opens from the
database button at the sidebar foot and renders as the main-column page keyed
dsh-data-window:database; conversation.header.leading is deliberately left
alone because another plugin already occupies that single seat.
- Workspace chip — the toolbar lists every workspace; picking one re-roots the window in place, without a trip through the sidebar.
- Full width on entry — entering the window folds the shell's navigation column; a toolbar button folds or unfolds it at any time.
Shortcuts
| Key | Action |
|---|---|
⌘/Ctrl + Enter | Run the statement in the active workbench (only the selection when there is one) |
⌘3 / Ctrl+3 | Open the data window from anywhere (editable in settings) |
F4 / ⌘/Ctrl + Shift + D | Show the selected table's create statement |
Tab in the editor | Insert two spaces (or accept the highlighted suggestion) |
⌘/Ctrl + Space | Open the suggestion list |
↑ / ↓, Esc | Move through or dismiss suggestions |
| Format button | Reindent the statement |
| Double-click a table | Open its rows in a workbench |
The window follows the workspace the shell is showing. Picking a directory by hand keeps that choice until Follow the workspace is pressed, and the choice survives a reload.
Configuration
Set these under the plugin row's config in cordis.patch.yml:
| Key | Default | Meaning |
|---|---|---|
nacosHome | ~/nacos | Root of the Nacos client's local cache |
groups | all | Only read these Nacos groups, e.g. [business] |
envOrder | dev1, dev, qa2, qa1, … | Environment order in the tree |
connectTimeoutMs | 8000 | Connect timeout |
statementTimeoutMs | 60000 | Per-statement timeout; 0 disables |
connectionLimit | 4 | Pool size per target |
defaultLimit | 200 | Default row limit |
cache | true | false re-reads the configuration on every open |
Limits
- MySQL / MariaDB only.
- Requires a local Nacos snapshot cache and the workspace's own
spring.datasourceconfiguration. A project without one, or one that has never started, shows an empty tree; the other data-ids in the snapshot are read only for the values the project's placeholders name. The optional AI fallback and manual connections can fill that gap; the AI path needs an LLM provider configured in DSH, and — like everything else — only keeps addresses that actually connect. - Each workspace keeps its own discovery cache under
$DSH_HOME/storages/dsh-data-window/workspaces/(mode0600). A file holds only that project's resolved hosts and credentials; deleting it forgets just that project. - One instance per query; use
schema.tablefor cross-schema reads.
License
MIT