dsh-data-window 0.0.0-stage → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +111 -0
- package/CHANGELOG.md +267 -0
- package/LICENSE +21 -0
- package/README.md +151 -2
- package/client.js +8271 -0
- package/cordis.patch.yml +4 -0
- package/docs/BRIDGE.md +106 -0
- package/docs/DESIGN.md +417 -0
- package/docs/DETAIL.md +242 -0
- package/docs/screenshots/ddl.png +0 -0
- package/docs/screenshots/workbench.png +0 -0
- package/icon.svg +30 -0
- package/index.js +180 -0
- package/locale/en.json +304 -0
- package/locale/zh.json +304 -0
- package/package.json +68 -4
- package/src/client/00-css.js +1110 -0
- package/src/client/05-icons.js +156 -0
- package/src/client/05-theme.js +107 -0
- package/src/client/06-shortcuts.js +89 -0
- package/src/client/07-bridge.js +202 -0
- package/src/client/10-core.js +1320 -0
- package/src/client/20-tree.js +293 -0
- package/src/client/25-sql.js +631 -0
- package/src/client/30-editor.js +742 -0
- package/src/client/40-results.js +556 -0
- package/src/client/45-export.js +219 -0
- package/src/client/50-panel.js +768 -0
- package/src/client/60-settings.js +180 -0
- package/src/client/63-schema.js +186 -0
- package/src/client/64-manual.js +350 -0
- package/src/client/65-ai.js +320 -0
- package/src/client/66-optimize.js +217 -0
- package/src/client/90-apply.js +183 -0
- package/src/host/ai.js +721 -0
- package/src/host/cache.js +157 -0
- package/src/host/catalog.js +161 -0
- package/src/host/consoles.js +116 -0
- package/src/host/discovery.js +603 -0
- package/src/host/manual.js +276 -0
- package/src/host/mysql.js +650 -0
- package/src/host/remembered.js +225 -0
- package/src/host/rpc.js +487 -0
- package/src/host/shared.js +180 -0
- package/src/host/yaml.js +335 -0
package/AGENTS.md
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# dsh-data-window — 项目开发须知
|
|
2
|
+
|
|
3
|
+
DataGrip 风格的 DSH 数据库窗口插件。本文件是这个工作区的**项目级约定**,新会话请先读它和 `docs/DESIGN.md`。
|
|
4
|
+
|
|
5
|
+
## 一句话职责
|
|
6
|
+
|
|
7
|
+
默认不新建连接配置:读工作区自己的 Spring/Nacos 配置拿到各环境的主机与账号,渲染成"环境 → 实例 → 库 → 表 → 字段"的树,每个库一个只读 SQL 工作台。**资源树是全机共享的**:切工作区只是把新工作区的地址并进来,不换树。规则读不到时有三条兜底:AI 分析、手动添加连接,或者继续用规则;三者产出的连接都必须通过只读连接验证才进树。
|
|
8
|
+
|
|
9
|
+
## 不可让步的三条
|
|
10
|
+
|
|
11
|
+
1. **只读**。任何改动都不能放松 `src/host/mysql.js` 的四层拦截(白名单 / 单语句 / 写关键字 / `SET SESSION TRANSACTION READ ONLY`)。这是用户的硬约束,不是可选项。
|
|
12
|
+
2. **密码不出 Host**。客户端只拿不透明连接 id(`i:…` / `d:…`),凭据只在 Host 进程内存与 0600 缓存文件里。
|
|
13
|
+
3. **不覆盖用户 SQL,只追加**。树上的动作只往控制台末尾追加语句,绝不改写已有内容。每张表在工作区里只有一个标签:双击表打开/聚焦 `sql:<dbId>:tbl:<table>`,并在最下方追加一条该表的基础查询;不再创建编号副本。
|
|
14
|
+
|
|
15
|
+
## 目录职责
|
|
16
|
+
|
|
17
|
+
| 路径 | 职责 |
|
|
18
|
+
|---|---|
|
|
19
|
+
| `index.js` | Host 入口:注册 `POST /dsh-data/rpc`、构造控制器、读 package 版本用于缓存失效 |
|
|
20
|
+
| `src/host/yaml.js` | YAML 子集解析(缩进映射/列表/多文档/注释/引号),`${a.b:default}` 占位符解析 |
|
|
21
|
+
| `src/host/discovery.js` | 配置发现:`bootstrap.yml` → 应用名 → Nacos 快照 → 按占位符找定义变量的 data-id(不假定文件名),产出环境/实例/库与连接目标表 |
|
|
22
|
+
| `src/host/mysql.js` | 只读网关:连接池、语句校验、元数据与 DDL 查询、行数上限 |
|
|
23
|
+
| `src/host/rpc.js` | action 分发(discover/ping/databases/tables/columns/schema/ddl/query/consoles/saveConsoles/config/forget)、错误→HTTP 映射 |
|
|
24
|
+
| `src/host/cache.js` | 每个工作区一份发现缓存(文件指纹 + 插件版本),0600,写临时文件再 rename |
|
|
25
|
+
| `src/host/consoles.js` | 每个工作区一份 SQL 控制台快照(只存语句,0600,原子写) |
|
|
26
|
+
| `src/host/ai.js` | AI 兜底:证据收集与脱敏、提示词、候选解析、凭据回读、连接校验、内存缓存 |
|
|
27
|
+
| `src/host/manual.js` | 手动连接:全机共享一份 0600 条目文件(首次启动合并旧的按工作区文件)+ 环境/实例/库与连接目标表 |
|
|
28
|
+
| `src/host/catalog.js` | 本机已解析/已手动添加的连接目录(跨工作区去重,列表不含密码,保存时按 id 取密码) |
|
|
29
|
+
| `src/host/remembered.js` | 记住用户勾选的库(全机共享一份 0600 文件),下次发现时并进实例 |
|
|
30
|
+
| `src/host/shared.js` | 把各工作区发现结果 + 共享手动连接 + 共享勾选库拼成**同一棵树**,并返回本工作区的 `focus`;本项目发现出来的库带 `inWorkspace: true`(树是全机共享的,别的项目的库也会挂进来,`openSql` 靠这个标记选库) |
|
|
31
|
+
| `src/client/*.js` | 面板源码,`node build.mjs` 拼成单文件 `client.js` |
|
|
32
|
+
| `build.mjs` | 拼接 + 注入语言字典 + 未定义 helper 检查 + 去掉模块语法 |
|
|
33
|
+
| `locale/{en,zh}.json` | 显示名(`meta`)+ 全部界面文案,客户端把它内联进 bundle |
|
|
34
|
+
| `test/ui-verify.mjs` | CDP 驱动的界面验证脚本(真实鼠标/键盘) |
|
|
35
|
+
| `docs/screenshots/` | 验证留档(工作台、建表语句) |
|
|
36
|
+
| `docs/BRIDGE.md` | 与代码工作区(`dsh-ide-window`)的事件桥契约:能力标记、请求/回执、动作与失败码 |
|
|
37
|
+
|
|
38
|
+
## 开发循环
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
node build.mjs # 改完 src/client/*.js 必须重新生成 client.js
|
|
42
|
+
node --check client.js # 语法
|
|
43
|
+
npm install --omit=dev # 只在首次或依赖变化时(link 安装从本目录解析 node_modules)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
装到 profile(已装过的新版本需要先移除):
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
plugin_manager remove_bundle dsh-data-window
|
|
50
|
+
plugin_manager install_bundle /path/to/dsh-data-window
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
**生效条件**:Host 改动要一次模块重新加载(移除+安装通常就够,否则重启应用)。客户端 bundle 由宿主按插件**版本号**拼成 `/plugins/??…&rev=<hash>` 并带 `immutable` 缓存:**同版本下改 `client.js`,普通刷新可能仍用旧 bundle**(重启应用也不一定有用,实测踩过)。
|
|
54
|
+
|
|
55
|
+
约定:**本地开发不升版本**(不发 npm 包),改完客户端 `node build.mjs` + 重新安装后,用 `⌘ + Shift + R` 强刷一次换掉旧 bundle;版本号只在正式发布时调整。
|
|
56
|
+
|
|
57
|
+
## 验证方式(重要)
|
|
58
|
+
|
|
59
|
+
### Host 侧:脱离 GUI 直接跑
|
|
60
|
+
|
|
61
|
+
`DataController` 不依赖 cordis,用 Node 脚本 `discover → databases → tables → columns → ddl → query` 即可,或带上鉴权 cookie 打真实路由:
|
|
62
|
+
|
|
63
|
+
```sh
|
|
64
|
+
curl -c /tmp/cj -o /dev/null "http://127.0.0.1:<port>/?token=<启动令牌>" # 换 30 天 cookie
|
|
65
|
+
curl -b /tmp/cj -X POST "http://127.0.0.1:<port>/dsh-data/rpc" \
|
|
66
|
+
-H 'content-type: application/json' -d '{"action":"discover","root":"…","refresh":true}'
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### 界面:自己开浏览器验证,不要推给用户
|
|
70
|
+
|
|
71
|
+
宿主页面要启动令牌,直接开 `http://127.0.0.1:<port>/` 会 401。拿令牌的正规方式是**让 Host 自己生成**:
|
|
72
|
+
|
|
73
|
+
```js
|
|
74
|
+
// 临时加在 index.js 的 apply 里,验证完删掉
|
|
75
|
+
writeFileSync(join(cacheDirectory, 'launch-url.txt'),
|
|
76
|
+
ctx.get('connection').authenticatedUrl(ctx.webServer.getOrigin()), { mode: 0o600 })
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
移除+安装让 Host 重新加载后,读 `~/.dsh/storages/dsh-data-window/launch-url.txt`,用它换 cookie(30 天有效,换一次能反复用)。
|
|
80
|
+
|
|
81
|
+
然后用 `test/ui-verify.mjs` 驱动(CDP + 真实鼠标键盘,不是 `dispatchEvent`):
|
|
82
|
+
|
|
83
|
+
```sh
|
|
84
|
+
node test/ui-verify.mjs "http://127.0.0.1:<port>/?token=<令牌>" \
|
|
85
|
+
/path/to/your-service /tmp/shots
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
它会输出 6 张截图(面板 / 展开环境 / 展开实例 / 工作台 / 结果 / DDL)和每步的 DOM 文本,并报告 console error。
|
|
89
|
+
|
|
90
|
+
两个必知的坑:
|
|
91
|
+
|
|
92
|
+
- **默认环境是自动展开的**,第一次点环境行是"收起",不是展开;脚本要先数 `.dw-node-instance`。
|
|
93
|
+
- **发现结果有磁盘缓存**,改了 `discovery.js` 的输出语义(不只是文件格式)必须 bump `cache.js` 的 `CACHE_VERSION`,否则旧 payload 会继续命中,界面看不到新字段。
|
|
94
|
+
|
|
95
|
+
## 已知边界
|
|
96
|
+
|
|
97
|
+
- 只支持 MySQL/MariaDB。
|
|
98
|
+
- 规则解析依赖本机 Nacos 快照与工作区自己的 `spring.datasource`;缺失时规则结果是空的(不再用快照里其它 data-id 兜底列实例),可以改用 AI 分析或手动添加连接。
|
|
99
|
+
- 查询不能取消,最长 60 秒(`statementTimeoutMs`)。
|
|
100
|
+
- 一次只连一个实例的库;跨库请写 `库名.表名`。
|
|
101
|
+
- 远端是 `github.com/simons-jiang/dsh-data-window`(公开仓库,截图与文档已脱敏);提交与推送仍需用户明确发话(全局规范)。
|
|
102
|
+
|
|
103
|
+
## 待办(按价值排序)
|
|
104
|
+
|
|
105
|
+
1. 查询取消(Host 记录 queryId + `connection.destroy()`)。
|
|
106
|
+
2. 结果导出 CSV、单元格复制。
|
|
107
|
+
3. 执行计划(`EXPLAIN` 已有白名单,缺 UI)。
|
|
108
|
+
4. 编辑器大结果下的渲染优化(网格已 memo,输入仍是整 store patch)。
|
|
109
|
+
5. `EXPLAIN`/`SHOW` 结果的可读化。
|
|
110
|
+
|
|
111
|
+
细节与取舍理由见 `docs/DESIGN.md`。
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.1.2] — 2026-11-26
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- SQL console tabs have a right-click menu: close, close others, close all, close
|
|
8
|
+
tabs to the left/right, copy the tab's reference (`schema.table` or `schema`), and
|
|
9
|
+
copy that reference into the chat composer when it is open (clipboard fallback
|
|
10
|
+
otherwise). Bulk closes pick the neighbouring tab and save the console snapshot
|
|
11
|
+
immediately. The menu reuses the code workspace's IDEA-style layout: icons,
|
|
12
|
+
separators, 27px rows, disabled side items, placement clamped to the panel.
|
|
13
|
+
- The create statement opens in a dialog with a copy button instead of a work tab;
|
|
14
|
+
the F4 / ⌘⇧D shortcut and the context-menu entry stay.
|
|
15
|
+
- Right-clicking a database (or F4 on it) reads every table's create statement with
|
|
16
|
+
`x/y` progress, one `-- table` block per statement, and marks the tables that
|
|
17
|
+
could not be read at the end of the script.
|
|
18
|
+
- The SQL optimization dialog is now a side-by-side diff: the original statement on
|
|
19
|
+
the left, the optimized one on the right, with changed tokens highlighted (red
|
|
20
|
+
left, green right) and synchronized scrolling. The comparison is token-based so a
|
|
21
|
+
model that collapses the statement into one line still diffs cleanly.
|
|
22
|
+
|
|
23
|
+
### Changed
|
|
24
|
+
|
|
25
|
+
- Clicking a tree row only selects it now; expanding/collapsing belongs to the
|
|
26
|
+
twisty, while double-click opens the node (database console, table data, or the
|
|
27
|
+
list for an environment/instance).
|
|
28
|
+
- The DDL dialog keeps the server's formatting: long lines scroll horizontally
|
|
29
|
+
instead of wrapping, and the code box is the dialog's only scroll container.
|
|
30
|
+
|
|
31
|
+
## [0.1.1] — 2026-11-25
|
|
32
|
+
|
|
33
|
+
### Fixed
|
|
34
|
+
|
|
35
|
+
- Paging a `LIMIT` statement no longer fails with `ER_PARSE_ERROR`: the Host's row
|
|
36
|
+
cap only recognised `LIMIT n` / `LIMIT m, n`, so a paged `… LIMIT n OFFSET m` got
|
|
37
|
+
a second `LIMIT n+1` appended. All trailing limit forms are now left alone.
|
|
38
|
+
- Switching workspace now expands the shared tree down to that workspace's
|
|
39
|
+
instances, so its databases are visible without two manual clicks; the Host's
|
|
40
|
+
`focus` already carried instance ids, but the panel only used the environment ids.
|
|
41
|
+
- The `数据窗口` control in the sidebar foot no longer reads as permanently selected.
|
|
42
|
+
DSH paints the selected panel on its own navigation rows and expects a footer
|
|
43
|
+
occupant to bring hover chrome only; the filled toolbar button this control reused
|
|
44
|
+
(white pill with a border in the light palette) therefore looked like a chosen row
|
|
45
|
+
at all times. It now sits transparent beside the code workspace's control, and the
|
|
46
|
+
highlight appears only while the data window is the open panel.
|
|
47
|
+
- The total-row `COUNT(*)` drops the statement's outermost `LIMIT` (limits inside
|
|
48
|
+
subqueries are kept), so it counts the whole result set instead of echoing the
|
|
49
|
+
preview size back.
|
|
50
|
+
- The suggestion list follows the keyboard: moving the highlight with ↑/↓ scrolls the
|
|
51
|
+
popup so the selected column never slides out of view.
|
|
52
|
+
- Completion resolves quoted table names in `db`.`table` form, so columns of a
|
|
53
|
+
backtick-quoted table are suggested (they used to be dropped because the table
|
|
54
|
+
name kept its leading backtick).
|
|
55
|
+
- The SQL completion list appears as soon as the schema map arrives. Typing right
|
|
56
|
+
after opening a workbench used to beat the map request, so the list stayed closed
|
|
57
|
+
until the next keystroke.
|
|
58
|
+
- Placeholder resolution now understands nested defaults (`${new.name:${old.name}}`),
|
|
59
|
+
which projects use when a service or data-id was renamed. The first `}` used to end
|
|
60
|
+
the placeholder, so the resolved user kept a trailing `}` and the password one more
|
|
61
|
+
character, and every query failed with `Access denied` even though the configuration
|
|
62
|
+
was correct.
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
- INSERT export stays limited to single-table SELECT; a join is not made to guess a
|
|
66
|
+
target table. Refusing now opens a dialog explaining why (it used to only append a
|
|
67
|
+
log line, so clicking the menu item looked like nothing happened).
|
|
68
|
+
- Result cells are one fixed-height line with an ellipsis instead of growing to fit
|
|
69
|
+
a long value; double-clicking a cell opens a detail dialog with the full text,
|
|
70
|
+
copy and an edit action (editing moved from double-click to the context menu).
|
|
71
|
+
|
|
72
|
+
### Added
|
|
73
|
+
|
|
74
|
+
- The SQL editor now owns its context menu (undo, redo, cut, copy, paste, select all)
|
|
75
|
+
and adds “AI optimize SQL”: the selection or whole statement is sent to the model
|
|
76
|
+
chosen in settings, and the suggestion opens in a dialog that can copy it. The
|
|
77
|
+
statement is never executed or written back to the editor. The explanation comes
|
|
78
|
+
back in the window's language (the document language, falling back to the system
|
|
79
|
+
locale).
|
|
80
|
+
- Right-click “刷新结构” on a connection, database or table/view re-reads that
|
|
81
|
+
node's structure: the connection re-runs discovery, a database re-fetches its
|
|
82
|
+
tables (and invalidates the editor's completion map), a table re-fetches its
|
|
83
|
+
columns and refreshes its open DDL tab.
|
|
84
|
+
- The result bar's clipboard copy was replaced by “Export”: the current page (local
|
|
85
|
+
cell edits included) can be saved as an XLSX workbook (built in the client, no
|
|
86
|
+
dependency), a UTF-8 CSV, or an INSERT script. The save location is chosen through
|
|
87
|
+
the File System Access API when available, otherwise the file is downloaded; the
|
|
88
|
+
INSERT option requires a single-table SELECT.
|
|
89
|
+
- Result cells can be edited locally (double-click; Enter commits, Esc cancels) and
|
|
90
|
+
edited cells are highlighted. Right-clicking a cell copies a single-row `UPDATE`
|
|
91
|
+
built from the edited columns and the original primary key — the statement is never
|
|
92
|
+
executed, and it is refused for non-single-table statements or results without a
|
|
93
|
+
primary-key column. The “N edited” badge also has a copy button that copies one
|
|
94
|
+
UPDATE per edited row in result order. Drafts reset when the result or page changes.
|
|
95
|
+
- Results paging for statements with a trailing `LIMIT`: the result bar shows
|
|
96
|
+
previous/next controls, the page size is the statement's own limit (`LIMIT n`,
|
|
97
|
+
`LIMIT n OFFSET m` and `LIMIT m, n` all parse; a subquery limit does not count),
|
|
98
|
+
and a next page is run as a derived `… LIMIT n OFFSET m` statement without
|
|
99
|
+
rewriting the editor. A next page that returns no rows ends the paging in place and
|
|
100
|
+
disables “next”, leaving “previous” available; the total-row count still comes from
|
|
101
|
+
the original statement.
|
|
102
|
+
- The resource tree is now shared by every workspace: opening a workspace adds its
|
|
103
|
+
environments to the one tree (and expands them) instead of replacing it. Manual
|
|
104
|
+
connections and picked databases moved to machine-wide files
|
|
105
|
+
(`manual/connections.json`, `remembered/databases.json`); the old per-workspace
|
|
106
|
+
documents are merged once and renamed `*.migrated`. Console snapshots and the
|
|
107
|
+
discovery cache stay per workspace, and target ids are unchanged, so saved tabs
|
|
108
|
+
keep working.
|
|
109
|
+
- The instance row opens a **database picker** instead of dumping every schema into
|
|
110
|
+
the tree: a searchable checkbox list where the configured databases are locked on,
|
|
111
|
+
and only checked schemas appear. The selection is remembered per workspace
|
|
112
|
+
(instance id + schema name, 0600) and reappears on the next open; the schema reuses
|
|
113
|
+
the instance's credentials, so no second copy of a password exists.
|
|
114
|
+
- Manually added connections: a toolbar button opens a small form (environment name,
|
|
115
|
+
host, port, user, password, optional database) for databases described nowhere in
|
|
116
|
+
the workspace. The Host proves the connection with a read-only `SELECT VERSION()`
|
|
117
|
+
before saving it, keeps the entries in a 0600 file per workspace, groups them by
|
|
118
|
+
environment name, and offers “Remove this connection” in the tree's context menu.
|
|
119
|
+
The form can also import a connection that any workspace on this machine already
|
|
120
|
+
resolved or added: host, port, account and schema are filled in, and the password
|
|
121
|
+
is reused from the Host store (looked up by source id at save time) instead of
|
|
122
|
+
being shown or retyped. Importing also fills the environment name from the saved
|
|
123
|
+
connection, and a manual environment can be renamed from the tree — the databases
|
|
124
|
+
already picked for it move with the new name instead of being stranded. A manual
|
|
125
|
+
environment can also be deleted as a whole (with a confirmation): its connections,
|
|
126
|
+
picked databases and pools go away, and it stays out of the tree until the
|
|
127
|
+
connection is imported again from another workspace.
|
|
128
|
+
- An optional AI fallback for workspaces whose configuration shape the rule-based
|
|
129
|
+
scan does not recognise. The model (chosen the first time it is needed, from the
|
|
130
|
+
providers configured in DSH, and changeable in settings) only points at files and
|
|
131
|
+
key paths; password values are redacted before the prompt, the Host reads the
|
|
132
|
+
secret itself inside the workspace, and each proposed address is proven with a
|
|
133
|
+
read-only connection before it joins an “AI” group in the tree. Failures are
|
|
134
|
+
reported in the run log instead of leaving broken entries behind.
|
|
135
|
+
- The data window answers the code workspace's bridge: `openTable` opens/focuses a
|
|
136
|
+
table's console, resolves the owning database through `findTable`, and runs the
|
|
137
|
+
base query; `openSql` pastes a mapper statement without running it. The contract
|
|
138
|
+
is versioned and documented in `docs/BRIDGE.md`.
|
|
139
|
+
- The settings page has a dedicated **Shortcuts** group. The open shortcut is
|
|
140
|
+
editable (record a new combination, reset to ⌘3 / Ctrl+3) and stored per browser.
|
|
141
|
+
- The data window follows the palette chosen in `dsh-ide-window` through the same
|
|
142
|
+
`dsh-theme` contract `dsh-git-window` uses; with no theme chosen it keeps DSH's
|
|
143
|
+
colours.
|
|
144
|
+
- The run log records every executed statement, including the `COUNT(*)` the total-row
|
|
145
|
+
refresh runs.
|
|
146
|
+
- The result bar shows a total-row counter: the refresh button next to it runs one
|
|
147
|
+
`COUNT(*)` for the statement that produced the result.
|
|
148
|
+
- The plugin has its own page in DSH's settings (`数据窗口`): auto-fold the sidebar,
|
|
149
|
+
the default row limit, the shortcut and the console snapshot path.
|
|
150
|
+
- `⌘3` / `Ctrl+3` opens the data window from anywhere.
|
|
151
|
+
- Workbench SQL is kept per workspace in a Host file
|
|
152
|
+
(`<workspace>/workspaces/<hash>-<name>.consoles.json`, mode 0600): switching to
|
|
153
|
+
another workspace, reloading the window or restarting DSH restores the console
|
|
154
|
+
with its text. Closing a tab deletes its snapshot; results are never restored.
|
|
155
|
+
- Running with a selection executes **only the selected statement** (⌘/Ctrl+Enter or
|
|
156
|
+
the Run button); running the whole buffer while a fragment was selected used to
|
|
157
|
+
send several statements and end in a confusing `ER_PARSE_ERROR`.
|
|
158
|
+
- The window is titled **Data window / 数据窗口** (it used to read “database data
|
|
159
|
+
window”).
|
|
160
|
+
- A workspace chip in the toolbar lists every known workspace and re-roots the window
|
|
161
|
+
in place, without a trip through the sidebar.
|
|
162
|
+
- The explorer column is draggable; a double-click on the divider restores the
|
|
163
|
+
default width.
|
|
164
|
+
- Entering the window folds the shell's navigation column, and a toolbar button folds
|
|
165
|
+
or unfolds it at any time.
|
|
166
|
+
|
|
167
|
+
- The SQL editor highlights keywords, functions, strings, numbers and comments, and
|
|
168
|
+
suggests tables, columns and keywords from a schema map the Host reads once per
|
|
169
|
+
database (`alias.` narrows to that table's columns).
|
|
170
|
+
- A **Format** button reindents the statement: clause keywords on their own line, one
|
|
171
|
+
select item per line, joins and boolean operators indented; keyword case is kept.
|
|
172
|
+
|
|
173
|
+
### Changed
|
|
174
|
+
|
|
175
|
+
- The “跟随工作区” and “选择工作区” toolbar buttons are gone: the workspace is
|
|
176
|
+
chosen in the shell's own top-left control, and the project chip menu keeps a
|
|
177
|
+
“跟随工作区” row so a manually picked directory can still return to following the
|
|
178
|
+
shell.
|
|
179
|
+
- “AI 分析” and “添加连接” moved from the top toolbar into the resource explorer
|
|
180
|
+
header: both act on the tree, not on the workspace, and the toolbar keeps only
|
|
181
|
+
workspace-level actions.
|
|
182
|
+
- Each table has its own console tab (`sql:<dbId>:tbl:<table>`). Double-clicking a
|
|
183
|
+
table opens or focuses that tab and appends one base statement at the bottom;
|
|
184
|
+
numbered copies no longer pile up and existing text is never replaced. Only the
|
|
185
|
+
appended statement runs, so repeating the double-click cannot send several
|
|
186
|
+
statements in one request.
|
|
187
|
+
|
|
188
|
+
- Discovery no longer hard-codes the data-id that carries hosts and passwords.
|
|
189
|
+
Every YAML data-id in the snapshot is a candidate, and only the files that define
|
|
190
|
+
a `${…}` key referenced by the project's own datasource are read; the project's
|
|
191
|
+
own values win over shared ones. Data-ids are accepted with or without the `.yml`
|
|
192
|
+
suffix (Nacos stores both), and an instance alias now comes from the project's own
|
|
193
|
+
URL template (`${acme.dbs.mysql-main}` → `mysql-main`) instead of the
|
|
194
|
+
fixed `<namespace>.dbs.<alias>` shape.
|
|
195
|
+
- Discovery now returns only the instances and databases the workspace's own
|
|
196
|
+
`spring.datasource` entries name. `yunwei-db.yml` is still read to resolve the
|
|
197
|
+
placeholders and to label a host with its alias, but the hosts it declares on its
|
|
198
|
+
own no longer reach the tree: they belong to other projects and the viewer has no
|
|
199
|
+
account for them, so browsing them only produced `Access denied` and
|
|
200
|
+
`ENOTFOUND` for a short host name that only resolves inside the cluster.
|
|
201
|
+
- The empty state explains that only this project's data sources are read; the
|
|
202
|
+
"list every database on the first instance" fallback button is gone with it.
|
|
203
|
+
- The discovery cache is now one file per workspace under
|
|
204
|
+
`storages/dsh-data-window/workspaces/` instead of a single `discovery.json` that
|
|
205
|
+
held every project's resolved hosts and credentials. Deleting a project's file
|
|
206
|
+
forgets only that project, a corrupt file cannot affect the others, and the old
|
|
207
|
+
shared file is removed on startup.
|
|
208
|
+
- An empty discovery result is no longer cached, so a service that starts (or a
|
|
209
|
+
datasource that is added) shows up on the next open instead of needing a reload.
|
|
210
|
+
- `docs/screenshots/` retaken against a neutral `demo-shop` workspace (system schema
|
|
211
|
+
through a local forwarder): no real host, business database, table or person is
|
|
212
|
+
visible in the images.
|
|
213
|
+
|
|
214
|
+
## 0.1.0
|
|
215
|
+
|
|
216
|
+
First version.
|
|
217
|
+
|
|
218
|
+
### Host
|
|
219
|
+
|
|
220
|
+
- Workspace configuration discovery: `bootstrap.yml` → `spring.application.name` →
|
|
221
|
+
the matching Nacos data-id → `yunwei-db.yml` for hosts and credentials, resolved
|
|
222
|
+
the way the JVM resolves the placeholders.
|
|
223
|
+
- Several Nacos caches may hold a tenant with the same name; the cache the project's
|
|
224
|
+
own `server-addr` points at wins, so another cluster's hosts never leak in.
|
|
225
|
+
- Per-workspace discovery cache (`$DSH_HOME/storages/dsh-data-window`, mode `0600`)
|
|
226
|
+
keyed by a fingerprint of every file it read and by the plugin version.
|
|
227
|
+
- Read-only MySQL gateway: verb whitelist, one statement per request, a
|
|
228
|
+
write-keyword scan, and `SET SESSION TRANSACTION READ ONLY` on every pooled
|
|
229
|
+
connection, so the server refuses a write even if the static check is wrong.
|
|
230
|
+
- `SHOW DATABASES`, `information_schema` table/column metadata, `SHOW CREATE TABLE`,
|
|
231
|
+
and every schema on a listed instance, not only the configured ones.
|
|
232
|
+
- Connection ids carry the environment, because one RDS host serves several tenants.
|
|
233
|
+
|
|
234
|
+
### Client
|
|
235
|
+
|
|
236
|
+
- DataGrip-style main-column window: explorer tree, one workbench tab per database,
|
|
237
|
+
result grid, draggable editor/result split and a collapsible run log.
|
|
238
|
+
- `F4` / `⌘/Ctrl + Shift + D` opens the selected table's create statement; the DDL
|
|
239
|
+
document can be refreshed without closing it.
|
|
240
|
+
- Table rows open in the workbench without overwriting SQL the user already typed:
|
|
241
|
+
a second console is added instead.
|
|
242
|
+
- The window follows the workspace the shell shows; a manual directory pick is kept
|
|
243
|
+
until "Follow the workspace" is pressed and survives a reload.
|
|
244
|
+
- Zero-environment, zero-configuration, failed-discovery and failed-node states each
|
|
245
|
+
say what happened and offer the next step; a failed node is retryable.
|
|
246
|
+
- Host error codes are rendered as sentences, with the original detail in brackets.
|
|
247
|
+
|
|
248
|
+
### Verified in the running application
|
|
249
|
+
|
|
250
|
+
The panel was driven end to end in a real browser (CDP, real mouse and keyboard
|
|
251
|
+
events): open from the sidebar, expand an environment and an instance, open the
|
|
252
|
+
`demo_order` workbench (65 tables), run `SELECT * FROM demo_api_log
|
|
253
|
+
LIMIT 5` (5 rows, 63 ms), press F4 on a table for its create statement. No console
|
|
254
|
+
errors. Two screenshots in `docs/screenshots/`.
|
|
255
|
+
|
|
256
|
+
Fixes found by that pass:
|
|
257
|
+
|
|
258
|
+
- The instance row showed the configuration path (`spring.datasource`) instead of
|
|
259
|
+
the host alias from `yunwei-db.yml` (`mysql-main`).
|
|
260
|
+
- Column names were truncated to two characters because the `NOT NULL` badge and
|
|
261
|
+
the type text competed for the row width; the badge moved into the tooltip.
|
|
262
|
+
- `TEXT` columns were labelled `BLOB` (the protocol reports both under one code; the
|
|
263
|
+
character set now decides).
|
|
264
|
+
- A workspace picked by hand did not survive a reload when the shell detected a
|
|
265
|
+
workspace: the stored choice was only applied when detection was empty.
|
|
266
|
+
- The environment row read `4 · 0`; it now reads `2 实例 · 2 库`.
|
|
267
|
+
- Discovery cache now invalidates on the payload generation (`CACHE_VERSION` 3).
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 simons-jiang
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,152 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dsh-data-window
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A DataGrip-style database window for DeepSeek Harness. For a normal project it asks
|
|
4
|
+
for no connection at all: it reads the workspace's own Spring/Nacos configuration,
|
|
5
|
+
resolves each environment's host and credentials from the local Nacos snapshot
|
|
6
|
+
cache, and adds it to one browsable tree shared by every workspace, plus one
|
|
7
|
+
read-only SQL workbench per database. When a project's configuration cannot be resolved, a model or the user
|
|
8
|
+
can supply the connection — and either way it is proven with a real read-only
|
|
9
|
+
connection before it enters the tree.
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- **Workspace-driven discovery** — `bootstrap.yml` → Nacos data-id → whichever
|
|
14
|
+
data-id defines each `${…}` placeholder, resolved the way the JVM does it. No
|
|
15
|
+
configuration file name is assumed. Only the data sources this project declares
|
|
16
|
+
are shown; results are cached per workspace and refreshed when the files change.
|
|
17
|
+
- **One resource tree for the whole machine** — a workspace's configuration only
|
|
18
|
+
says how to *find* its databases. The tree is the union of every workspace opened
|
|
19
|
+
so far plus the shared manual connections and database picks, so switching
|
|
20
|
+
workspace adds that workspace's hosts instead of replacing the tree; the
|
|
21
|
+
environments it contributes open automatically. Discovery caches and SQL consoles
|
|
22
|
+
stay per workspace.
|
|
23
|
+
- **AI fallback when the rules find nothing** — a workspace whose configuration
|
|
24
|
+
shape the scan does not recognise can be analysed by a model configured in DSH.
|
|
25
|
+
The model only proposes hosts and file/key paths; password values are redacted
|
|
26
|
+
before they enter the prompt, the Host reads the secret itself, and every proposed
|
|
27
|
+
address is proven with a real read-only connection before it joins an “AI” group
|
|
28
|
+
in the tree. The model is chosen the first time (and changeable in settings).
|
|
29
|
+
- **Pick the databases to show** — the configured database is what the tree shows
|
|
30
|
+
first; a per-instance picker (searchable checkboxes, configured ones locked on)
|
|
31
|
+
chooses the other schemas, and the choice is shared by every workspace.
|
|
32
|
+
- **Manual connections** — a toolbar button adds a host/port/account/database by
|
|
33
|
+
hand for databases described nowhere in the workspace (a local container, a shared
|
|
34
|
+
test instance). The form can import a connection another workspace already
|
|
35
|
+
resolved — host, port, account and schema filled in, the password reused from the
|
|
36
|
+
Host so it is never shown — because teams share one RDS endpoint across projects.
|
|
37
|
+
The connection is tested before it is saved, entries are grouped by environment
|
|
38
|
+
name (imported ones inherit the source's name; a manual environment can be renamed
|
|
39
|
+
later), and the tree's context menu can remove one connection or delete the whole
|
|
40
|
+
environment (re-importable from another workspace's data).
|
|
41
|
+
- **Explorer** — environments → instances → databases → tables → columns, with type,
|
|
42
|
+
primary key, nullability and comment. One button reveals every schema on an
|
|
43
|
+
instance, not only the configured ones. The column is draggable, and a
|
|
44
|
+
double-click on the divider restores its default width.
|
|
45
|
+
- **Editor with JetBrains-style colouring** — keywords, functions, strings, numbers and
|
|
46
|
+
comments are highlighted; typing suggests tables, columns and keywords, `alias.`
|
|
47
|
+
narrows to that table's columns; one click reindents the statement.
|
|
48
|
+
- **AI SQL optimization from the editor** — the editor's own context menu keeps
|
|
49
|
+
undo/redo/cut/copy/paste/select-all and adds “AI optimize SQL”: the selection (or
|
|
50
|
+
the whole statement) goes to the model configured in settings, and the suggestion
|
|
51
|
+
opens in a dialog with a copy button. Nothing is executed or written back.
|
|
52
|
+
- **Refresh structure** — right-click a connection, database or table to re-read
|
|
53
|
+
its structure (databases, tables or columns) without reloading the panel; an open
|
|
54
|
+
DDL view for that table. Metadata only, never a write.
|
|
55
|
+
- **Tab context menu** — right-click a console tab to close it, close the tabs on
|
|
56
|
+
either side (or all of them), copy its reference (`schema.table` or `schema`), or
|
|
57
|
+
put that reference into the chat composer when the chat input is open.
|
|
58
|
+
- **Paging for LIMIT queries** — a statement ending in `LIMIT` gets previous/next
|
|
59
|
+
controls whose page size is that limit; the next page is built as
|
|
60
|
+
`… LIMIT n OFFSET m` and run without touching the editor. An empty next page ends
|
|
61
|
+
the paging in place, leaving only “previous” available.
|
|
62
|
+
- **Create statement in one keystroke** — `F4` or `⌘/Ctrl + Shift + D` on a table
|
|
63
|
+
opens it in a dialog with a copy button (no extra work tab); on a database the same
|
|
64
|
+
key (or the context menu) reads the create statement of every table in it.
|
|
65
|
+
- **One workbench per database**, kept as tabs, with a result grid, copy-as-TSV,
|
|
66
|
+
a row limit, a draggable editor/result split and a collapsible run log. Opening a
|
|
67
|
+
table's rows never overwrites SQL you already typed: a second console is added
|
|
68
|
+
instead.
|
|
69
|
+
- **Export the page** — the result bar exports the current page (with any local cell
|
|
70
|
+
edits) as an `.xlsx` workbook, a UTF-8 CSV, or an INSERT script. The save dialog
|
|
71
|
+
lets you choose the path through the File System Access API, with a download
|
|
72
|
+
fallback on hosts that do not expose it.
|
|
73
|
+
- **Editable cells, generated UPDATE** — result rows are one fixed line high with
|
|
74
|
+
clipped cells; double-click opens the full value, and “Edit cell” in its context
|
|
75
|
+
menu (or the detail dialog) turns a cell into a local draft (edited cells turn
|
|
76
|
+
blue); right-click copies a single-row `UPDATE` built
|
|
77
|
+
from the edited columns and the original primary key. The statement is only copied,
|
|
78
|
+
never executed, and it is refused for joins, subqueries or results without a
|
|
79
|
+
primary key.
|
|
80
|
+
- **Read-only by construction** — verb whitelist, one statement per request, a
|
|
81
|
+
write-keyword scan, and `SET SESSION TRANSACTION READ ONLY` on every pooled
|
|
82
|
+
connection so the server refuses a write even if the static check is ever wrong.
|
|
83
|
+
|
|
84
|
+
## Install
|
|
85
|
+
|
|
86
|
+
```sh
|
|
87
|
+
cd dsh-data-window
|
|
88
|
+
npm install --omit=dev # mysql2, the only runtime dependency
|
|
89
|
+
node build.mjs # regenerate client.js from src/client/*.js
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Then install the directory as a bundle (**Plugins → Add plugin**, or
|
|
93
|
+
`plugin_manager` `install_bundle` with this directory). The window opens from the
|
|
94
|
+
database button at the sidebar foot and renders as the main-column page keyed
|
|
95
|
+
`dsh-data-window:database`; `conversation.header.leading` is deliberately left
|
|
96
|
+
alone because another plugin already occupies that single seat.
|
|
97
|
+
|
|
98
|
+
- **Workspace chip** — the toolbar lists every workspace; picking one re-roots the
|
|
99
|
+
window in place, without a trip through the sidebar.
|
|
100
|
+
- **Full width on entry** — entering the window folds the shell's navigation column;
|
|
101
|
+
a toolbar button folds or unfolds it at any time.
|
|
102
|
+
|
|
103
|
+
## Shortcuts
|
|
104
|
+
|
|
105
|
+
| Key | Action |
|
|
106
|
+
|---|---|
|
|
107
|
+
| `⌘/Ctrl + Enter` | Run the statement in the active workbench (only the selection when there is one) |
|
|
108
|
+
| `⌘3` / `Ctrl+3` | Open the data window from anywhere (editable in settings) |
|
|
109
|
+
| `F4` / `⌘/Ctrl + Shift + D` | Show the selected table's create statement |
|
|
110
|
+
| `Tab` in the editor | Insert two spaces (or accept the highlighted suggestion) |
|
|
111
|
+
| `⌘/Ctrl + Space` | Open the suggestion list |
|
|
112
|
+
| `↑` / `↓`, `Esc` | Move through or dismiss suggestions |
|
|
113
|
+
| Format button | Reindent the statement |
|
|
114
|
+
| Double-click a table | Open its rows in a workbench |
|
|
115
|
+
|
|
116
|
+
The window follows the workspace the shell is showing. Picking a directory by hand
|
|
117
|
+
keeps that choice until **Follow the workspace** is pressed, and the choice survives
|
|
118
|
+
a reload.
|
|
119
|
+
|
|
120
|
+
## Configuration
|
|
121
|
+
|
|
122
|
+
Set these under the plugin row's `config` in `cordis.patch.yml`:
|
|
123
|
+
|
|
124
|
+
| Key | Default | Meaning |
|
|
125
|
+
|---|---|---|
|
|
126
|
+
| `nacosHome` | `~/nacos` | Root of the Nacos client's local cache |
|
|
127
|
+
| `groups` | all | Only read these Nacos groups, e.g. `[business]` |
|
|
128
|
+
| `envOrder` | `dev1, dev, qa2, qa1, …` | Environment order in the tree |
|
|
129
|
+
| `connectTimeoutMs` | `8000` | Connect timeout |
|
|
130
|
+
| `statementTimeoutMs` | `60000` | Per-statement timeout; `0` disables |
|
|
131
|
+
| `connectionLimit` | `4` | Pool size per target |
|
|
132
|
+
| `defaultLimit` | `200` | Default row limit |
|
|
133
|
+
| `cache` | `true` | `false` re-reads the configuration on every open |
|
|
134
|
+
|
|
135
|
+
## Limits
|
|
136
|
+
|
|
137
|
+
- MySQL / MariaDB only.
|
|
138
|
+
- Requires a local Nacos snapshot cache and the workspace's own `spring.datasource`
|
|
139
|
+
configuration. A project without one, or one that has never started, shows an empty
|
|
140
|
+
tree; the other data-ids in the snapshot are read only for the values the
|
|
141
|
+
project's placeholders name. The optional AI fallback and manual connections can
|
|
142
|
+
fill that gap; the AI path needs an LLM provider configured in DSH, and — like
|
|
143
|
+
everything else — only keeps addresses that actually connect.
|
|
144
|
+
- Each workspace keeps its own discovery cache under
|
|
145
|
+
`$DSH_HOME/storages/dsh-data-window/workspaces/` (mode `0600`). A file holds only
|
|
146
|
+
that project's resolved hosts and credentials; deleting it forgets just that
|
|
147
|
+
project.
|
|
148
|
+
- One instance per query; use `schema.table` for cross-schema reads.
|
|
149
|
+
|
|
150
|
+
## License
|
|
151
|
+
|
|
152
|
+
MIT
|