Skip to content

feat: SQL 库与终端 reintegrate 恢复(#313) - #383

Merged
feigeCode merged 4 commits into
mainfrom
feat/sql-library
Oct 12, 2026
Merged

feigeCode merged 4 commits into
mainfrom
feat/sql-library

Conversation

@feigeCode

@feigeCode feigeCode commented Oct 12, 2026 •

Copy link
Copy Markdown
Owner

Closes #313

Description

本 PR 包含两个特性:

1. SQL 库(standalone SQL library)

Adds a standalone SQL library: a global, connection-agnostic home for .sql
documents, so scripts no longer have to live inside a per-(connection+database)
query folder.

  • core: new storage::sql_library module — default library root
    (<data_dir>/sql-library, deliberately outside ~/Documents to avoid the
    macOS TCC prompt), mounted user directories persisted to
    config/sql-library-directories.json, directory listing, create / rename /
    delete for .sql files and subfolders, and shared SQL file-name validation.
  • db_view: new SqlLibraryPanel, reachable from a rail button on the database
    tab's right sidebar. Lazy-loading tree (one level per expand), create / rename /
    delete / remove-from-library dialogs, notifications, empty and load-error
    placeholders.
  • Clicking a .sql file opens it in the existing SQL editor, reusing syntax
    highlighting, execution and autosave. Tabs are keyed by file path, so clicking
    the same file again focuses the tab that is already open.
  • Library files are not bound to a connection: the current tree selection (or the
    first connection) is used as the default, and the connection can be switched
    inside the editor. If no connection exists, the panel just notifies instead of
    opening an empty editor.
  • File-name validation moved to core::storage::sql_library
    (sql_file_path_for_name); db_view::sql_editor_view::query_file_path_for_name
    now delegates to it, removing the duplicated implementation.
  • Removing a mounted directory only detaches it from the library, the files stay
    on disk.

2. 终端 reintegrate 恢复(terminal.control action=reintegrate)

嵌套 shell(sudo -i / su)不继承运行时注入的 shell integration,OSC 133
事件流断开后 supervisor readiness 卡死在瞬态,terminal.exec 持续
terminal_busy 且 interrupt 的 ETX 无法恢复(空提示符上只回显 ^C,
不产生 OSC 事件)。

  • ExecSupervisor::reintegrate_shell 门控:exec 在途 / 断连拒绝,卡在
    SubmissionPending / CommandRunning 瞬态时放行,不改状态
  • SSH actor 写 runtime_shell_integration_command() 重注入;新提示符的
    OSC InputStart 无条件翻回 Ready,状态机自愈,等 1-2 秒重试 exec 即可
  • local actor 返回 terminal_control_unsupported(本地集成形态不同,fail
    closed)
  • readiness_before 改 Option,reintegrate 恒 None
  • Busy 出口富化为 BusyContext{readiness},指引 Agent 走
    read → reintegrate → retry 自救链路
  • Agent 自救链:exec busy(带 readiness 快照)→ terminal.read 确认空闲
    提示符 → control action=reintegrate → 重试

Screenshot

Before After
No SQL library entry point in the database tab SQL library rail button + panel listing library roots, folders and .sql files

No screenshots attached — the UI has not been captured yet.

How to Test

Automated, run on top of origin/main (this branch's base):

SQL 库:

  • cargo test -p one-core sql_library → 13 passed, 798 filtered out
  • cargo test -p db_view sql_library → 11 passed, 914 filtered out
  • cargo check -p main → 0 errors

The db_view suite covers the tree state machine (expansion, lazy loading, stale
state on root reset) and source-level contracts for the wiring and the i18n keys;
the core suite covers the storage layer against a temp directory, never the real
config dir.

reintegrate:

  • cargo test -p terminal --lib reintegrate → 10 passed(门控 fail-closed、
    瞬态放行、端到端自愈、SSH actor 注入 contract、local Unsupported contract)
  • cargo test -p public_mcp --test terminal_control → schema enum、parse、
    reintegrate 结果 readiness_before=null、未知 action 拒绝
  • cargo test -p terminal -p public_mcp -p terminal_view → 1307 passed, 0 failed
  • cargo clippy -p terminal -p public_mcp -p terminal_view --all-targets →
    新增代码零告警
  • cargo check -p main → 0 errors

Manual: SSH 连接后进入 sudo -i,确认 terminal.exec 报带指引的 busy,
terminal.read 看到空闲 root 提示符后 terminal.control action=reintegrate,
1-2 秒后重试 exec 正常执行。

- core: 新增 sql-library 存储层——默认库根目录、挂载/卸载用户目录(持久化到配置目录)、
  目录列表、新建/重命名/删除 SQL 文件与子目录、SQL 文件名校验
- db_view: 数据库页右侧新增「SQL 库」面板,库树懒加载、文件操作弹窗与通知
- 点击库内 .sql 文件用 SQL 编辑器打开,页签按文件路径复用,连接可在编辑器内切换
- 文件名校验统一收敛到 core,db_view 的 query_file_path_for_name 改为委托,删除重复实现
- 新增单测:core 13 项(临时目录)、面板 11 项(树状态 + 接线/i18n 契约)
查询结果里 `SELECT * FROM ads.tbl` 解析出的表名是 `ads.tbl`(库名与表名用 . 拼接),
复制 INSERT/UPDATE/DELETE 时被整体当成一个标识符加引号,产出 `ads.tbl` 这种库表名
粘在一起的非法名字。

- table_identifier 改走新增的 qualified_identifier:按 . 拆分逐段引用,兼容
  db.schema.table,仅一段时行为不变
- 新增 3 个契约测试(MySQL 逐段引用并覆盖 INSERT/UPDATE/DELETE、无插件的回退引号
  与三段名、非限定名不受影响)

验证:cargo test -p db_view --lib(927 passed / 0 failed)。
sudo -i / su 等嵌套 shell 不继承运行时注入的 shell integration,
OSC 133 事件流断开后 supervisor readiness 卡死在瞬态,
terminal.exec 持续 terminal_busy 且 interrupt 的 ETX 无法恢复。

- ExecSupervisor::reintegrate_shell 门控:exec 在途/断连拒绝,
  卡在瞬态 readiness 时放行,不改状态
- SSH actor 写 runtime_shell_integration_command() 重注入;
  新提示符的 OSC InputStart 无条件翻回 Ready,状态机自愈
- local actor 返回 terminal_control_unsupported(集成形态不同,fail closed)
- readiness_before 改 Option,reintegrate 恒 None
- Busy 出口富化为 BusyContext{readiness},指引 Agent 走
  read → reintegrate → retry 自救链路
@feigeCode feigeCode changed the title feat(db): 新增 SQL 库,独立于连接管理 SQL 文件(#313) feat: SQL 库与终端 reintegrate 恢复(#313) Oct 12, 2026
…tream sync)

kit upstream sync brings caret-pinned gpui-pre 0.3.9 + gpui-fast 0.1.7
workspace requirements (satisfied by the existing release/v0.1.8 shim
snapshot at 0.3.126/0.1.8), caret-anchored completion popups, auto-grow
row fitting, TextView selection-under-glyphs painting.

Fix the terminal.control test stub missed by a6b91ff: readiness_before
is Option<TerminalControlReadiness> now.
@feigeCode
feigeCode merged commit f49eeee into main Oct 12, 2026
8 checks passed
@feigeCode
feigeCode deleted the feat/sql-library branch October 13, 2026 08:10
feigeCode added a commit that referenced this pull request Oct 16, 2026
恢复 a9ed96b6b 被遗落在 feat/issue-313-sql-library 分支的完整实现:
SQL 库整理成 feat/sql-library 走 PR #383 时只挑了 b801a46,
磁盘下拉 UI 接线被丢下,dev 只剩 checkpoint 半截(WIP 标记 + allow(dead_code))。

cherry-pick 仅一处冲突(local_volume.rs 测试 import 块),取完整版;
另删掉 lib.rs / local_volume.rs 里已失效的 WIP 注释与 allow(dead_code)。

验证:cargo test -p sftp_view --lib 118 passed;cargo check -p main --tests、
cargo clippy -p sftp_view --all-targets 均通过
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: 希望增加SQL文件管理功能

1 participant