dsh-data-window 0.0.0-stage → 0.1.1

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.
Files changed (45) hide show
  1. package/AGENTS.md +111 -0
  2. package/CHANGELOG.md +239 -0
  3. package/LICENSE +21 -0
  4. package/README.md +146 -2
  5. package/client.js +7779 -0
  6. package/cordis.patch.yml +4 -0
  7. package/docs/BRIDGE.md +100 -0
  8. package/docs/DESIGN.md +417 -0
  9. package/docs/DETAIL.md +220 -0
  10. package/docs/screenshots/ddl.png +0 -0
  11. package/docs/screenshots/workbench.png +0 -0
  12. package/icon.svg +30 -0
  13. package/index.js +180 -0
  14. package/locale/en.json +286 -0
  15. package/locale/zh.json +286 -0
  16. package/package.json +68 -4
  17. package/src/client/00-css.js +993 -0
  18. package/src/client/05-icons.js +137 -0
  19. package/src/client/05-theme.js +107 -0
  20. package/src/client/06-shortcuts.js +89 -0
  21. package/src/client/07-bridge.js +193 -0
  22. package/src/client/10-core.js +1352 -0
  23. package/src/client/20-tree.js +281 -0
  24. package/src/client/25-sql.js +631 -0
  25. package/src/client/30-editor.js +537 -0
  26. package/src/client/40-results.js +556 -0
  27. package/src/client/45-export.js +219 -0
  28. package/src/client/50-panel.js +761 -0
  29. package/src/client/60-settings.js +180 -0
  30. package/src/client/63-schema.js +186 -0
  31. package/src/client/64-manual.js +350 -0
  32. package/src/client/65-ai.js +320 -0
  33. package/src/client/66-optimize.js +98 -0
  34. package/src/client/90-apply.js +183 -0
  35. package/src/host/ai.js +721 -0
  36. package/src/host/cache.js +157 -0
  37. package/src/host/catalog.js +161 -0
  38. package/src/host/consoles.js +116 -0
  39. package/src/host/discovery.js +603 -0
  40. package/src/host/manual.js +276 -0
  41. package/src/host/mysql.js +650 -0
  42. package/src/host/remembered.js +225 -0
  43. package/src/host/rpc.js +487 -0
  44. package/src/host/shared.js +172 -0
  45. 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` |
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,239 @@
1
+ # Changelog
2
+
3
+ ## [0.1.1] — 2026-11-25
4
+
5
+ ### Fixed
6
+
7
+ - Paging a `LIMIT` statement no longer fails with `ER_PARSE_ERROR`: the Host's row
8
+ cap only recognised `LIMIT n` / `LIMIT m, n`, so a paged `… LIMIT n OFFSET m` got
9
+ a second `LIMIT n+1` appended. All trailing limit forms are now left alone.
10
+ - Switching workspace now expands the shared tree down to that workspace's
11
+ instances, so its databases are visible without two manual clicks; the Host's
12
+ `focus` already carried instance ids, but the panel only used the environment ids.
13
+ - The `数据窗口` control in the sidebar foot no longer reads as permanently selected.
14
+ DSH paints the selected panel on its own navigation rows and expects a footer
15
+ occupant to bring hover chrome only; the filled toolbar button this control reused
16
+ (white pill with a border in the light palette) therefore looked like a chosen row
17
+ at all times. It now sits transparent beside the code workspace's control, and the
18
+ highlight appears only while the data window is the open panel.
19
+ - The total-row `COUNT(*)` drops the statement's outermost `LIMIT` (limits inside
20
+ subqueries are kept), so it counts the whole result set instead of echoing the
21
+ preview size back.
22
+ - The suggestion list follows the keyboard: moving the highlight with ↑/↓ scrolls the
23
+ popup so the selected column never slides out of view.
24
+ - Completion resolves quoted table names in `db`.`table` form, so columns of a
25
+ backtick-quoted table are suggested (they used to be dropped because the table
26
+ name kept its leading backtick).
27
+ - The SQL completion list appears as soon as the schema map arrives. Typing right
28
+ after opening a workbench used to beat the map request, so the list stayed closed
29
+ until the next keystroke.
30
+ - Placeholder resolution now understands nested defaults (`${new.name:${old.name}}`),
31
+ which projects use when a service or data-id was renamed. The first `}` used to end
32
+ the placeholder, so the resolved user kept a trailing `}` and the password one more
33
+ character, and every query failed with `Access denied` even though the configuration
34
+ was correct.
35
+
36
+
37
+ - INSERT export stays limited to single-table SELECT; a join is not made to guess a
38
+ target table. Refusing now opens a dialog explaining why (it used to only append a
39
+ log line, so clicking the menu item looked like nothing happened).
40
+ - Result cells are one fixed-height line with an ellipsis instead of growing to fit
41
+ a long value; double-clicking a cell opens a detail dialog with the full text,
42
+ copy and an edit action (editing moved from double-click to the context menu).
43
+
44
+ ### Added
45
+
46
+ - The SQL editor now owns its context menu (undo, redo, cut, copy, paste, select all)
47
+ and adds “AI optimize SQL”: the selection or whole statement is sent to the model
48
+ chosen in settings, and the suggestion opens in a dialog that can copy it. The
49
+ statement is never executed or written back to the editor. The explanation comes
50
+ back in the window's language (the document language, falling back to the system
51
+ locale).
52
+ - Right-click “刷新结构” on a connection, database or table/view re-reads that
53
+ node's structure: the connection re-runs discovery, a database re-fetches its
54
+ tables (and invalidates the editor's completion map), a table re-fetches its
55
+ columns and refreshes its open DDL tab.
56
+ - The result bar's clipboard copy was replaced by “Export”: the current page (local
57
+ cell edits included) can be saved as an XLSX workbook (built in the client, no
58
+ dependency), a UTF-8 CSV, or an INSERT script. The save location is chosen through
59
+ the File System Access API when available, otherwise the file is downloaded; the
60
+ INSERT option requires a single-table SELECT.
61
+ - Result cells can be edited locally (double-click; Enter commits, Esc cancels) and
62
+ edited cells are highlighted. Right-clicking a cell copies a single-row `UPDATE`
63
+ built from the edited columns and the original primary key — the statement is never
64
+ executed, and it is refused for non-single-table statements or results without a
65
+ primary-key column. The “N edited” badge also has a copy button that copies one
66
+ UPDATE per edited row in result order. Drafts reset when the result or page changes.
67
+ - Results paging for statements with a trailing `LIMIT`: the result bar shows
68
+ previous/next controls, the page size is the statement's own limit (`LIMIT n`,
69
+ `LIMIT n OFFSET m` and `LIMIT m, n` all parse; a subquery limit does not count),
70
+ and a next page is run as a derived `… LIMIT n OFFSET m` statement without
71
+ rewriting the editor. A next page that returns no rows ends the paging in place and
72
+ disables “next”, leaving “previous” available; the total-row count still comes from
73
+ the original statement.
74
+ - The resource tree is now shared by every workspace: opening a workspace adds its
75
+ environments to the one tree (and expands them) instead of replacing it. Manual
76
+ connections and picked databases moved to machine-wide files
77
+ (`manual/connections.json`, `remembered/databases.json`); the old per-workspace
78
+ documents are merged once and renamed `*.migrated`. Console snapshots and the
79
+ discovery cache stay per workspace, and target ids are unchanged, so saved tabs
80
+ keep working.
81
+ - The instance row opens a **database picker** instead of dumping every schema into
82
+ the tree: a searchable checkbox list where the configured databases are locked on,
83
+ and only checked schemas appear. The selection is remembered per workspace
84
+ (instance id + schema name, 0600) and reappears on the next open; the schema reuses
85
+ the instance's credentials, so no second copy of a password exists.
86
+ - Manually added connections: a toolbar button opens a small form (environment name,
87
+ host, port, user, password, optional database) for databases described nowhere in
88
+ the workspace. The Host proves the connection with a read-only `SELECT VERSION()`
89
+ before saving it, keeps the entries in a 0600 file per workspace, groups them by
90
+ environment name, and offers “Remove this connection” in the tree's context menu.
91
+ The form can also import a connection that any workspace on this machine already
92
+ resolved or added: host, port, account and schema are filled in, and the password
93
+ is reused from the Host store (looked up by source id at save time) instead of
94
+ being shown or retyped. Importing also fills the environment name from the saved
95
+ connection, and a manual environment can be renamed from the tree — the databases
96
+ already picked for it move with the new name instead of being stranded. A manual
97
+ environment can also be deleted as a whole (with a confirmation): its connections,
98
+ picked databases and pools go away, and it stays out of the tree until the
99
+ connection is imported again from another workspace.
100
+ - An optional AI fallback for workspaces whose configuration shape the rule-based
101
+ scan does not recognise. The model (chosen the first time it is needed, from the
102
+ providers configured in DSH, and changeable in settings) only points at files and
103
+ key paths; password values are redacted before the prompt, the Host reads the
104
+ secret itself inside the workspace, and each proposed address is proven with a
105
+ read-only connection before it joins an “AI” group in the tree. Failures are
106
+ reported in the run log instead of leaving broken entries behind.
107
+ - The data window answers the code workspace's bridge: `openTable` opens/focuses a
108
+ table's console, resolves the owning database through `findTable`, and runs the
109
+ base query; `openSql` pastes a mapper statement without running it. The contract
110
+ is versioned and documented in `docs/BRIDGE.md`.
111
+ - The settings page has a dedicated **Shortcuts** group. The open shortcut is
112
+ editable (record a new combination, reset to ⌘3 / Ctrl+3) and stored per browser.
113
+ - The data window follows the palette chosen in `dsh-ide-window` through the same
114
+ `dsh-theme` contract `dsh-git-window` uses; with no theme chosen it keeps DSH's
115
+ colours.
116
+ - The run log records every executed statement, including the `COUNT(*)` the total-row
117
+ refresh runs.
118
+ - The result bar shows a total-row counter: the refresh button next to it runs one
119
+ `COUNT(*)` for the statement that produced the result.
120
+ - The plugin has its own page in DSH's settings (`数据窗口`): auto-fold the sidebar,
121
+ the default row limit, the shortcut and the console snapshot path.
122
+ - `⌘3` / `Ctrl+3` opens the data window from anywhere.
123
+ - Workbench SQL is kept per workspace in a Host file
124
+ (`<workspace>/workspaces/<hash>-<name>.consoles.json`, mode 0600): switching to
125
+ another workspace, reloading the window or restarting DSH restores the console
126
+ with its text. Closing a tab deletes its snapshot; results are never restored.
127
+ - Running with a selection executes **only the selected statement** (⌘/Ctrl+Enter or
128
+ the Run button); running the whole buffer while a fragment was selected used to
129
+ send several statements and end in a confusing `ER_PARSE_ERROR`.
130
+ - The window is titled **Data window / 数据窗口** (it used to read “database data
131
+ window”).
132
+ - A workspace chip in the toolbar lists every known workspace and re-roots the window
133
+ in place, without a trip through the sidebar.
134
+ - The explorer column is draggable; a double-click on the divider restores the
135
+ default width.
136
+ - Entering the window folds the shell's navigation column, and a toolbar button folds
137
+ or unfolds it at any time.
138
+
139
+ - The SQL editor highlights keywords, functions, strings, numbers and comments, and
140
+ suggests tables, columns and keywords from a schema map the Host reads once per
141
+ database (`alias.` narrows to that table's columns).
142
+ - A **Format** button reindents the statement: clause keywords on their own line, one
143
+ select item per line, joins and boolean operators indented; keyword case is kept.
144
+
145
+ ### Changed
146
+
147
+ - The “跟随工作区” and “选择工作区” toolbar buttons are gone: the workspace is
148
+ chosen in the shell's own top-left control, and the project chip menu keeps a
149
+ “跟随工作区” row so a manually picked directory can still return to following the
150
+ shell.
151
+ - “AI 分析” and “添加连接” moved from the top toolbar into the resource explorer
152
+ header: both act on the tree, not on the workspace, and the toolbar keeps only
153
+ workspace-level actions.
154
+ - Each table has its own console tab (`sql:<dbId>:tbl:<table>`). Double-clicking a
155
+ table opens or focuses that tab and appends one base statement at the bottom;
156
+ numbered copies no longer pile up and existing text is never replaced. Only the
157
+ appended statement runs, so repeating the double-click cannot send several
158
+ statements in one request.
159
+
160
+ - Discovery no longer hard-codes the data-id that carries hosts and passwords.
161
+ Every YAML data-id in the snapshot is a candidate, and only the files that define
162
+ a `${…}` key referenced by the project's own datasource are read; the project's
163
+ own values win over shared ones. Data-ids are accepted with or without the `.yml`
164
+ suffix (Nacos stores both), and an instance alias now comes from the project's own
165
+ URL template (`${acme.dbs.mysql-main}` → `mysql-main`) instead of the
166
+ fixed `<namespace>.dbs.<alias>` shape.
167
+ - Discovery now returns only the instances and databases the workspace's own
168
+ `spring.datasource` entries name. `yunwei-db.yml` is still read to resolve the
169
+ placeholders and to label a host with its alias, but the hosts it declares on its
170
+ own no longer reach the tree: they belong to other projects and the viewer has no
171
+ account for them, so browsing them only produced `Access denied` and
172
+ `ENOTFOUND` for a short host name that only resolves inside the cluster.
173
+ - The empty state explains that only this project's data sources are read; the
174
+ "list every database on the first instance" fallback button is gone with it.
175
+ - The discovery cache is now one file per workspace under
176
+ `storages/dsh-data-window/workspaces/` instead of a single `discovery.json` that
177
+ held every project's resolved hosts and credentials. Deleting a project's file
178
+ forgets only that project, a corrupt file cannot affect the others, and the old
179
+ shared file is removed on startup.
180
+ - An empty discovery result is no longer cached, so a service that starts (or a
181
+ datasource that is added) shows up on the next open instead of needing a reload.
182
+ - `docs/screenshots/` retaken against a neutral `demo-shop` workspace (system schema
183
+ through a local forwarder): no real host, business database, table or person is
184
+ visible in the images.
185
+
186
+ ## 0.1.0
187
+
188
+ First version.
189
+
190
+ ### Host
191
+
192
+ - Workspace configuration discovery: `bootstrap.yml` → `spring.application.name` →
193
+ the matching Nacos data-id → `yunwei-db.yml` for hosts and credentials, resolved
194
+ the way the JVM resolves the placeholders.
195
+ - Several Nacos caches may hold a tenant with the same name; the cache the project's
196
+ own `server-addr` points at wins, so another cluster's hosts never leak in.
197
+ - Per-workspace discovery cache (`$DSH_HOME/storages/dsh-data-window`, mode `0600`)
198
+ keyed by a fingerprint of every file it read and by the plugin version.
199
+ - Read-only MySQL gateway: verb whitelist, one statement per request, a
200
+ write-keyword scan, and `SET SESSION TRANSACTION READ ONLY` on every pooled
201
+ connection, so the server refuses a write even if the static check is wrong.
202
+ - `SHOW DATABASES`, `information_schema` table/column metadata, `SHOW CREATE TABLE`,
203
+ and every schema on a listed instance, not only the configured ones.
204
+ - Connection ids carry the environment, because one RDS host serves several tenants.
205
+
206
+ ### Client
207
+
208
+ - DataGrip-style main-column window: explorer tree, one workbench tab per database,
209
+ result grid, draggable editor/result split and a collapsible run log.
210
+ - `F4` / `⌘/Ctrl + Shift + D` opens the selected table's create statement; the DDL
211
+ document can be refreshed without closing it.
212
+ - Table rows open in the workbench without overwriting SQL the user already typed:
213
+ a second console is added instead.
214
+ - The window follows the workspace the shell shows; a manual directory pick is kept
215
+ until "Follow the workspace" is pressed and survives a reload.
216
+ - Zero-environment, zero-configuration, failed-discovery and failed-node states each
217
+ say what happened and offer the next step; a failed node is retryable.
218
+ - Host error codes are rendered as sentences, with the original detail in brackets.
219
+
220
+ ### Verified in the running application
221
+
222
+ The panel was driven end to end in a real browser (CDP, real mouse and keyboard
223
+ events): open from the sidebar, expand an environment and an instance, open the
224
+ `demo_order` workbench (65 tables), run `SELECT * FROM demo_api_log
225
+ LIMIT 5` (5 rows, 63 ms), press F4 on a table for its create statement. No console
226
+ errors. Two screenshots in `docs/screenshots/`.
227
+
228
+ Fixes found by that pass:
229
+
230
+ - The instance row showed the configuration path (`spring.datasource`) instead of
231
+ the host alias from `yunwei-db.yml` (`mysql-main`).
232
+ - Column names were truncated to two characters because the `NOT NULL` badge and
233
+ the type text competed for the row width; the badge moved into the tooltip.
234
+ - `TEXT` columns were labelled `BLOB` (the protocol reports both under one code; the
235
+ character set now decides).
236
+ - A workspace picked by hand did not survive a reload when the shell detected a
237
+ workspace: the stored choice was only applied when detection was empty.
238
+ - The environment row read `4 · 0`; it now reads `2 实例 · 2 库`.
239
+ - 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,147 @@
1
- # Temporary Holding Version
1
+ # dsh-data-window
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
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 tab for that table refreshes with it. Metadata only, never a write.
55
+ - **Paging for LIMIT queries** — a statement ending in `LIMIT` gets previous/next
56
+ controls whose page size is that limit; the next page is built as
57
+ `… LIMIT n OFFSET m` and run without touching the editor. An empty next page ends
58
+ the paging in place, leaving only “previous” available.
59
+ - **Create statement in one keystroke** — `F4` or `⌘/Ctrl + Shift + D` on a table.
60
+ - **One workbench per database**, kept as tabs, with a result grid, copy-as-TSV,
61
+ a row limit, a draggable editor/result split and a collapsible run log. Opening a
62
+ table's rows never overwrites SQL you already typed: a second console is added
63
+ instead.
64
+ - **Export the page** — the result bar exports the current page (with any local cell
65
+ edits) as an `.xlsx` workbook, a UTF-8 CSV, or an INSERT script. The save dialog
66
+ lets you choose the path through the File System Access API, with a download
67
+ fallback on hosts that do not expose it.
68
+ - **Editable cells, generated UPDATE** — result rows are one fixed line high with
69
+ clipped cells; double-click opens the full value, and “Edit cell” in its context
70
+ menu (or the detail dialog) turns a cell into a local draft (edited cells turn
71
+ blue); right-click copies a single-row `UPDATE` built
72
+ from the edited columns and the original primary key. The statement is only copied,
73
+ never executed, and it is refused for joins, subqueries or results without a
74
+ primary key.
75
+ - **Read-only by construction** — verb whitelist, one statement per request, a
76
+ write-keyword scan, and `SET SESSION TRANSACTION READ ONLY` on every pooled
77
+ connection so the server refuses a write even if the static check is ever wrong.
78
+
79
+ ## Install
80
+
81
+ ```sh
82
+ cd dsh-data-window
83
+ npm install --omit=dev # mysql2, the only runtime dependency
84
+ node build.mjs # regenerate client.js from src/client/*.js
85
+ ```
86
+
87
+ Then install the directory as a bundle (**Plugins → Add plugin**, or
88
+ `plugin_manager` `install_bundle` with this directory). The window opens from the
89
+ database button at the sidebar foot and renders as the main-column page keyed
90
+ `dsh-data-window:database`; `conversation.header.leading` is deliberately left
91
+ alone because another plugin already occupies that single seat.
92
+
93
+ - **Workspace chip** — the toolbar lists every workspace; picking one re-roots the
94
+ window in place, without a trip through the sidebar.
95
+ - **Full width on entry** — entering the window folds the shell's navigation column;
96
+ a toolbar button folds or unfolds it at any time.
97
+
98
+ ## Shortcuts
99
+
100
+ | Key | Action |
101
+ |---|---|
102
+ | `⌘/Ctrl + Enter` | Run the statement in the active workbench (only the selection when there is one) |
103
+ | `⌘3` / `Ctrl+3` | Open the data window from anywhere (editable in settings) |
104
+ | `F4` / `⌘/Ctrl + Shift + D` | Show the selected table's create statement |
105
+ | `Tab` in the editor | Insert two spaces (or accept the highlighted suggestion) |
106
+ | `⌘/Ctrl + Space` | Open the suggestion list |
107
+ | `↑` / `↓`, `Esc` | Move through or dismiss suggestions |
108
+ | Format button | Reindent the statement |
109
+ | Double-click a table | Open its rows in a workbench |
110
+
111
+ The window follows the workspace the shell is showing. Picking a directory by hand
112
+ keeps that choice until **Follow the workspace** is pressed, and the choice survives
113
+ a reload.
114
+
115
+ ## Configuration
116
+
117
+ Set these under the plugin row's `config` in `cordis.patch.yml`:
118
+
119
+ | Key | Default | Meaning |
120
+ |---|---|---|
121
+ | `nacosHome` | `~/nacos` | Root of the Nacos client's local cache |
122
+ | `groups` | all | Only read these Nacos groups, e.g. `[business]` |
123
+ | `envOrder` | `dev1, dev, qa2, qa1, …` | Environment order in the tree |
124
+ | `connectTimeoutMs` | `8000` | Connect timeout |
125
+ | `statementTimeoutMs` | `60000` | Per-statement timeout; `0` disables |
126
+ | `connectionLimit` | `4` | Pool size per target |
127
+ | `defaultLimit` | `200` | Default row limit |
128
+ | `cache` | `true` | `false` re-reads the configuration on every open |
129
+
130
+ ## Limits
131
+
132
+ - MySQL / MariaDB only.
133
+ - Requires a local Nacos snapshot cache and the workspace's own `spring.datasource`
134
+ configuration. A project without one, or one that has never started, shows an empty
135
+ tree; the other data-ids in the snapshot are read only for the values the
136
+ project's placeholders name. The optional AI fallback and manual connections can
137
+ fill that gap; the AI path needs an LLM provider configured in DSH, and — like
138
+ everything else — only keeps addresses that actually connect.
139
+ - Each workspace keeps its own discovery cache under
140
+ `$DSH_HOME/storages/dsh-data-window/workspaces/` (mode `0600`). A file holds only
141
+ that project's resolved hosts and credentials; deleting it forgets just that
142
+ project.
143
+ - One instance per query; use `schema.table` for cross-schema reads.
144
+
145
+ ## License
146
+
147
+ MIT