Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
92edd8e
feat(terminal): restore bounded recent command output per pane
galact-byte Sep 21, 2026
d3f3962
merge: integrate upstream main for recent output restore
galact-byte Sep 21, 2026
aa93047
docs(recent-output): fix decision note validation and refresh evidence
galact-byte Sep 21, 2026
ec9fba4
fix(terminal): confirm recent output submissions on all platforms
galact-byte Sep 21, 2026
19e72aa
Merge branch 'main' into feat/recent-output-restore
galact-byte Sep 21, 2026
997e05f
fix(cli): sync Windows completions on output restore branch
galact-byte Sep 21, 2026
ae3a43d
Merge upstream main into PR #235 and resolve conflicts
galact-byte Sep 21, 2026
ad812bb
test: fix Unix fixture collision and macOS path selection
galact-byte Sep 21, 2026
2cd35c2
Merge upstream main into PR #235, retain recent output restore
galact-byte Sep 23, 2026
49a6942
test: initialize output refs in workspace recovery fixture
galact-byte Sep 23, 2026
761dfac
Merge branch 'main' into feat/recent-output-restore
galact-byte Sep 23, 2026
e6c2260
Merge branch 'main' into feat/recent-output-restore
galact-byte Sep 23, 2026
1e23fe0
Merge branch 'main' into feat/recent-output-restore
galact-byte Sep 24, 2026
5cfdfec
Merge branch 'main' into feat/recent-output-restore
galact-byte Sep 24, 2026
0d07b1f
feat: narrow recent output restore to snapshot and storage foundation
galact-byte Sep 26, 2026
f71db5b
feat: collect per-pane command output and map local snapshots
galact-byte Sep 26, 2026
35fe055
feat: persist and restore recent output across window lifecycle
galact-byte Sep 26, 2026
5917c5f
ci: rerun checks for recent output foundation
galact-byte Sep 26, 2026
c454ae9
Merge branch 'main' into feat/recent-output-restore
galact-byte Sep 27, 2026
086ac80
Merge branch 'main' into feat/recent-output-restore
galact-byte Sep 28, 2026
2f9ae61
fix: bound snapshot decoding and sanitize orphan wide-char flags
galact-byte Sep 28, 2026
1e6c0e3
Merge feat/recent-output-restore: take snapshot audit fixes and local…
galact-byte Sep 28, 2026
bc26d48
Merge feat/recent-output-pane-capture: sync audit fixes
galact-byte Sep 28, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# 静态输出快照与本机引用的持久化边界

## Status

供审核的持久化基础;尚未接入命令采集、设置控件或窗口输出恢复。
关联 #160,本阶段不代表完整功能已交付。

## Context

终端显示、输出文件和布局会话的生命周期不同。多个 pane 可以处于同一目录,
因此目录不能作为旧输出归属。直接回放原始 VT 会再次执行控制动作;
把输出及引用放进共享工作区格式,又会让导出携带本机历史。

## Evidence

- [显示快照与校验](../../../../nebula_terminal/src/grid/snapshot.rs)覆盖 Unicode 重排、容量和控制数据拒绝;备用屏活动时读取主屏由第二项随采集接入。
- [有界输出存储](../../../../nebula_app/src/recent_output/storage.rs)复用原子文件写入。
- [发布生命周期](../../../../nebula_app/src/recent_output/storage/lifecycle.rs)的回归测试覆盖两代交接、失败重试和发布回调内失效。
- 本机会话引用(`session/local_output.rs`)随第二项的逐 pane 采集交付;本项存储测试以普通文件代替会话,只验证发布回调的提交语义。

## Decision

terminal 层仅捕获和恢复主屏的静态显示字段,恢复到历史区,不重放 VT,
不改活终端屏幕或光标。反序列化与恢复先校验结构、容量和控制数据。

app 层以独立 sidecar 保存有界记录,每 pane 最多五条,每条最多 256 KiB。
正常归档最多 16 MiB,两代原子交接最多 32 MiB;超量先裁剪旧记录再生成引用。
精确引用只属于本机自动恢复文档,共享工作区的导入和导出不携带这些引用。

先持久化输出,再发布会话引用,发布成功前保留旧引用可读取的那一代。
发布失败恢复旧归档;成功后才能回收旧代。回调成功意味着会话已经落盘,
即使回调内代次失效,也必须报告真实的持久化结果并保留交接数据。
后续接入者负责通过同一串行边界提交新的 checkpoint;无引用 checkpoint
不能等同清除全部旧历史,显式清除使用独立操作。

## Rejected alternatives

- 回放原始 VT:会重放控制动作,无法保证只恢复显示。
- 按 cwd 匹配:同目录多 pane 无法确定归属。
- 在共享会话中嵌入输出或本机引用:扩大导出范围和载入成本。
- 发布引用前覆盖旧代:中断后旧会话可能引用已丢失的数据。
- 发布成功后仅凭代次变化返回未提交:内存结果会与实际磁盘状态矛盾。

## Consequences

存储和终端边界可各自验证,后续采集及窗口接入复用同一规则。
本阶段不会自动记录命令或恢复终端输出,也不新增用户设置。
调用方须在后台执行磁盘操作,并承担持久化完成后的生命周期收尾。

## Validation

Windows 上实际运行:存储 24 项、会话相关 105 项、启动恢复 1 项通过;
`cargo test --locked -p nebula_terminal --features serde` 的 352 项通过,
包含使用现有打包资产执行的 ConPTY 生命周期测试。
应用测试启用 `gpui-test-support`;仅关闭应用测试目标的调试符号,断言不变。
这些结果验证本阶段边界,不作为尚未接入的窗口输出恢复验收。

## Supersedes

None。

## Revisit when

需要改变容量、引用身份、原子交接协议,或允许跨设备导出输出时重新审核。
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# 显示快照的有界解码与宽字符边界

## Status

#235 的候选审计修正,待审核。沿用现有 JSON 字段,不改变后台发布协议。

## Context

编码文件的字节限额不能代替解码对象限额。先反序列化嵌套 Vec 再 validate,
会在拒绝输入前分配大量空行、单元格或组合字符。宽字符占位参与文本提取和
重排;行首孤立占位会使文本提取回退到负列。另一方面,终端删除半个宽字符
后的重排可能留下孤立标志,严格拒绝会让正常编辑后的输出无法恢复。

## Evidence

- [解码器](../../../../nebula_terminal/src/grid/snapshot/serialization.rs)原先先生成完整 WireSnapshot。
- [快照回归测试](../../../../nebula_terminal/src/grid/snapshot.rs)用超限有效元素后接畸形尾部,证明解码必须先因预算失败;包括跨单元格累计组合字符。
- 同处真实解析器测试覆盖中文、组合字符以及删除、插入、擦除后三种列宽的重排。

## Decision

通过 serde DeserializeSeed 按行读取,每读入一个单元格即扣减预算。不信任
size_hint,不按输入提示预分配。行、单元格与单格组合字符在读取中计数,累计组合
字符在每个单元格读完后扣减;各项均不超过 262_144。后续 validate 仍检查尺寸和
控制数据。保留 JSON 对象字段顺序无关的合同。

捕获与导入共用同一规范化:清除互斥宽字符标志、未配对的宽字符/占位以及错误位置
的跨行前导占位,保留字符、颜色、组合字符和其他标志;末行跨行占位可以没有下一行。
倒序处理确保前导占位看到已规范化的下一行。行首孤立占位因此不会进入文本提取;
活终端不变。

## Rejected alternatives

- 只在整个 Vec 建成后校验:拒绝太晚,不能限制解码期间分配。
- 每个单元格单独限制组合字符:无法限制所有单元格的累计量。
- 导入严格拒绝畸形宽字符标志:需与捕获分设两套规则,且一个无效标志即丢弃整段输出。
- 依赖 columns 已先读取:会破坏已有 JSON 字段顺序无关的格式。
- 所有跨行占位必须有下一行:误拒绝合法的有界裁剪。
- 直接修活网格:改变正常终端编辑行为。

## Consequences

资源与结构校验属于 terminal 快照边界,不增加应用依赖、数据迁移或新配置。
旧格式的正常快照继续可读;超预算或尺寸/控制数据畸形的快照拒绝,应用降级为无旧
输出。无效宽字符标志仅从快照副本移除,不承诺修复终端核心的编辑行为。

## Validation

`cargo test --offline --locked -p nebula_terminal --features serde` 全套通过。
新测试在原解码器上失败(超限尾部被读取、孤立占位保留),并用真实解析器覆盖中文
半字符删除/插入/擦除后在三种列宽下重排的正常快照不被改动。

## Supersedes

None。

## Revisit when

改变 wire 格式、快照资源上限、宽字符布局或主屏捕获边界时重新核验。
9 changes: 9 additions & 0 deletions nebula_app/i18n/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
"en_us": "English"
},
"settings": {
"command_output": {
"save": "Remember recent command output",
"help": "With session restore enabled, keep up to five commands and their output per terminal on this device. Output may contain sensitive information; full-screen applications are not captured.",
"clear": "Clear saved command output",
"clear_help": "Remove saved output for all terminals on this device without clearing their screens. New commands are still saved while the option above is enabled.",
"clearing": "Clearing…",
"cleared": "Saved output cleared",
"clear_failed": "Clear failed — retry"
},
"scrolling": {
"history": "Scrollback lines",
"history_description": "History lines retained per terminal. Applies to new terminals only.",
Expand Down
9 changes: 9 additions & 0 deletions nebula_app/i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
"en_us": "English"
},
"settings": {
"command_output": {
"save": "保存最近命令与输出",
"help": "开启会话恢复时,在本机为每个终端保留最近五条命令及输出。输出可能包含敏感信息;不采集全屏程序画面。",
"clear": "清除已保存的命令输出",
"clear_help": "移除本机所有终端已保存的输出,不清空当前屏幕。上方开关开启时,后续新命令仍会保存。",
"clearing": "正在清除…",
"cleared": "已清除保存的输出",
"clear_failed": "清除失败,点击重试"
},
"scrolling": {
"history": "回滚行数",
"history_description": "每个窗格保留的历史行数。仅适用于新窗格。",
Expand Down
2 changes: 2 additions & 0 deletions nebula_app/src/gpui_shell/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ pub struct Settings {
pub cursor_blink: Option<bool>,
/// 选区完成即复制(旧壳 `copy_on_select` 设置)。
pub copy_on_select: bool,
pub(crate) command_output_enabled: bool,
pub scrollback_lines: usize,
pub scroll_speed: f32,
/// Pointer handlers and split rendering only read these cached preferences.
Expand Down Expand Up @@ -280,6 +281,7 @@ impl Settings {
}),
cursor_blink: runtime.cursor_blink,
copy_on_select: runtime.copy_on_select,
command_output_enabled: runtime.command_output_enabled(),
scrollback_lines: runtime.scrollback_lines,
scroll_speed: runtime.scroll_speed,
focus_follows_mouse: runtime
Expand Down
2 changes: 1 addition & 1 deletion nebula_app/src/gpui_shell/file_editor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ mod structure_inline_view;
mod structure_tests;
mod structure_view;
#[cfg(all(test, feature = "gpui-test-support"))]
mod tests;
pub(in crate::gpui_shell) mod tests;

use std::cell::RefCell;
use std::path::PathBuf;
Expand Down
11 changes: 11 additions & 0 deletions nebula_app/src/gpui_shell/file_editor/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@ use super::*;
use gpui::{TestAppContext, VisualTestContext};
use gpui_component::Root;

pub(in crate::gpui_shell) fn replace_draft(
file: &Entity<TextFileView>,
text: &str,
window: &mut gpui::Window,
cx: &mut gpui::App,
) {
file.update(cx, |view, cx| {
view.input.update(cx, |input, cx| input.replace_all(text, window, cx));
});
}

pub(super) fn open(
path: PathBuf,
cx: &mut TestAppContext,
Expand Down
9 changes: 8 additions & 1 deletion nebula_app/src/gpui_shell/settings_pane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ mod appearance_picker;
#[path = "background_color.rs"]
mod background_color;
mod backup;
mod command_output;
mod design;
mod font_picker;
mod providers;
Expand Down Expand Up @@ -215,6 +216,7 @@ pub struct SettingsPane {
/// 备份密码(masked;只在导出/恢复动作瞬时读取,不落任何配置)。
backup_pass_input: Entity<InputState>,
backup_status: Option<BackupStatus>,
command_output_clear: command_output::ClearState,
/// 导出/恢复/推送进行中(按钮禁用 + 忽略过期完成回调)。
backup_busy: bool,
backup_seq: u64,
Expand Down Expand Up @@ -380,7 +382,10 @@ impl SettingsPane {
cx.notify();
return;
}
if matches!(key, "ai_toasts" | "focus_follows_mouse" | "dim_inactive_panes") {
if matches!(
key,
"ai_toasts" | "focus_follows_mouse" | "dim_inactive_panes" | "save_command_output"
) {
if let Err(error) = self.try_persist(&[(key, (value as u8).to_string())], cx) {
let language = crate::gpui_shell::config::ui_language(cx);
super::toast::toast(
Expand Down Expand Up @@ -750,6 +755,7 @@ impl SettingsPane {
"fetch" => flag!(fetch),
"keep_session" => flag!(keep_session),
"restore_session" => flag!(restore_session),
"save_command_output" => flag!(save_command_output),
"resume_ai" => flag!(resume_ai),
"tray" => flag!(tray),
"panel_resize" => flag!(panel_resize),
Expand Down Expand Up @@ -1265,6 +1271,7 @@ impl SettingsPane {
self.runtime.restore_session,
cx,
))
.child(self.command_output_controls(cx))
.child(self.switch_row(
"resume_ai",
language.pick("恢复时接续 AI 对话", "Resume AI conversations"),
Expand Down
69 changes: 69 additions & 0 deletions nebula_app/src/gpui_shell/settings_pane/command_output.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//! 本机命令输出沿用会话恢复设置区域;清除成功必须等磁盘操作完成。
use super::*;
use crate::i18n::Message;

#[derive(Default)]
pub(super) enum ClearState {
#[default]
Idle,
Busy,
Done,
Failed,
}

impl SettingsPane {
pub(super) fn command_output_controls(&self, cx: &mut Context<Self>) -> impl IntoElement {
let language = crate::gpui_shell::config::ui_language(cx);
let label = match self.command_output_clear {
ClearState::Idle => Message::SettingsCommandOutputClear,
ClearState::Busy => Message::SettingsCommandOutputClearing,
ClearState::Done => Message::SettingsCommandOutputCleared,
ClearState::Failed => Message::SettingsCommandOutputClearFailed,
};
let control = crate::gpui_shell::widgets::NebulaButton::new("clear-command-output")
.label(language.text(label))
.disabled(matches!(self.command_output_clear, ClearState::Busy))
.on_click(cx.listener(|this, _, _, cx| this.clear_command_output(cx)));
#[cfg(any(test, feature = "gpui-test-support"))]
let control = div().debug_selector(|| "clear-command-output".to_owned()).child(control);
div()
.child(self.switch_row(
"save_command_output",
language.text(Message::SettingsCommandOutputSave),
language.text(Message::SettingsCommandOutputHelp),
self.runtime.save_command_output,
cx,
))
.child(self.row(
language.text(Message::SettingsCommandOutputClear),
language.text(Message::SettingsCommandOutputClearHelp),
control,
cx,
))
}

fn clear_command_output(&mut self, cx: &mut Context<Self>) {
if matches!(self.command_output_clear, ClearState::Busy) {
return;
}
self.command_output_clear = ClearState::Busy;
let clear = crate::gpui_shell::workspace::windowing::clear_command_output(cx);
cx.notify();
cx.spawn(async move |this, cx| {
let result = clear.await;
let state = match result {
Ok(true) => ClearState::Done,
Ok(false) => ClearState::Failed,
Err(error) => {
log::warn!("Could not clear command output: {error}");
ClearState::Failed
},
};
let _ = this.update(cx, |this, cx| {
this.command_output_clear = state;
cx.notify();
});
})
.detach();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,7 @@ impl SettingsPane {
.placeholder(localized_input_placeholder("backup_password", language))
}),
backup_status: None,
command_output_clear: super::command_output::ClearState::Idle,
backup_busy: false,
backup_seq: 0,
backup_remote: {
Expand Down
2 changes: 1 addition & 1 deletion nebula_app/src/gpui_shell/settings_pane/navigation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub(super) const SECTION_SEARCH_TERMS: [&str; 11] = [
"network 网络 proxy 代理 connectivity 连接",
"interaction 交互 copy 复制 paste 粘贴 tab 标签 panel 面板 focus follows mouse 焦点跟随鼠标 自动聚焦",
"keymap key binding shortcut quick terminal 快速终端 独立窗口 已有窗口 按键映射 快捷键",
"advanced 高级 session 会话 tray 托盘 restore 恢复 startup autostart login silent 自启动 静默启动 开机 登录",
"advanced 高级 session 会话 tray 托盘 restore 恢复 startup autostart login silent 自启动 静默启动 开机 登录 command output 命令输出 最近命令 清除输出",
"backup cloud sync 云备份 云同步 云存储 备份 export 导出 restore 恢复 webdav s3 sftp 坚果云 123 123云盘 nextcloud synology 群晖 nas r2 minio snapshots 快照",
"agents agent hook hooks 智能体 钩子 接入 claude codex opencode cursor kimi pi omp copilot grok",
];
Expand Down
Loading