Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ tar = "0.4.44"
toml = "1.1.5"
ulid = { version = "3.0.0", features = ["serde"] }
unicode-width = "0.2.2"
vte = "0.14.1"
zstd = "0.14.0"
zip = { version = "8.2.0", default-features = false, features = ["deflate"] }
toml_edit = "0.25.15"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ path. On Windows the database defaults to `%LOCALAPPDATA%\recall\recall.db`.
```toml
[general]
max_output_bytes = 1048576 # per-command output cap (before compression)
strip_ansi = true
strip_ansi = false

[proxy]
login_shell = true # spawn the shell with -l (default: true on macOS)
Expand Down Expand Up @@ -395,7 +395,7 @@ terminal emulator ──▶ recall proxy (PTY/ConPTY) ──▶ shell (zsh/bash/
- The proxy parses and strips these markers, so command boundaries are exact and
the prompt is never captured. There is no side channel or socket, which
keeps recall shell- and OS-agnostic.
- Output is ANSI-stripped, classified, capped, zstd-compressed and stored in
- Output is classified, capped, zstd-compressed and stored in
SQLite together with self-contained command metadata. Optional imports are
tracked in a separate, source-neutral provenance table.

Expand Down
4 changes: 2 additions & 2 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ Linux/macOS 为 `~/.config/recall/config.toml`,Windows 为
```toml
[general]
max_output_bytes = 1048576 # 单条命令输出上限(压缩前)
strip_ansi = true
strip_ansi = false

[proxy]
login_shell = true # 以 -l 启动 shell(macOS 默认开启)
Expand Down Expand Up @@ -352,7 +352,7 @@ date_format = "%Y-%m-%d %H:%M:%S"
标记,携带 `{command, cwd, start}`;并在下一个提示符绘制前写入带退出码的结束标记。
- 代理解析并剥离这些标记,因此命令边界精确,提示符永远不会被捕获。没有旁路通道
或 socket,这让 recall 与 shell、操作系统无关。
- 输出经过去 ANSI、分类、限长、zstd 压缩后,与完整命令元数据一起存入 SQLite。
- 输出经过分类、限长、zstd 压缩后,与完整命令元数据一起存入 SQLite。
可选导入的来源关系保存在独立、与具体来源无关的记录表中。

## 兼容性
Expand Down
4 changes: 2 additions & 2 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ choose_search_key() {

case "${RECALL_SEARCH_KEY:-}" in
"" ) ;;
default | alt-r ) return 0 ;;
default | alt-r ) search_key="alt-r"; return 0 ;;
* ) search_key=$RECALL_SEARCH_KEY; return 0 ;;
esac

Expand All @@ -261,7 +261,7 @@ choose_search_key() {
IFS= read -r answer < /dev/tty || answer=""
case "$answer" in
2) search_key="ctrl-t" ;;
3) search_key="" ;;
3) search_key="alt-r" ;;
*) search_key="ctrl-x ctrl-r" ;;
esac
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/dev-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ else
if [ -n "$shell_path" ]; then
say ""
say "Start an isolated shell with:"
say " env HOME=\"$install_home\" ZDOTDIR=\"$install_home\" XDG_CONFIG_HOME=\"$config_home\" XDG_DATA_HOME=\"$data_home\" RECALL_CONFIG=\"$recall_config\" PATH=\"$install_dir:\$PATH\" SHELL=\"$shell_path\" TERM=\"$test_term\" \"$shell_path\" -i"
say " env -u RECALL_PROXY_ACTIVE -u RECALL_AUTO_LAUNCH -u RECALL_SESSION -u RECALL_PROXY HOME=\"$install_home\" ZDOTDIR=\"$install_home\" XDG_CONFIG_HOME=\"$config_home\" XDG_DATA_HOME=\"$data_home\" RECALL_CONFIG=\"$recall_config\" PATH=\"$install_dir:\$PATH\" SHELL=\"$shell_path\" TERM=\"$test_term\" \"$shell_path\" -i"
fi
say ""
say "Remove the sandbox when finished:"
Expand Down
53 changes: 42 additions & 11 deletions src/capture/classifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub fn detect_interactive(raw: &[u8]) -> bool {
.any(|marker| raw.windows(marker.len()).any(|w| w == *marker))
}

/// Classify captured output and produce the storable plain-text form.
/// Classify visible text while optionally retaining terminal styling in storage.
pub fn classify(input: ClassifyInput<'_>) -> Classified {
let ClassifyInput {
raw,
Expand All @@ -43,13 +43,7 @@ pub fn classify(input: ClassifyInput<'_>) -> Classified {
};
}

let text = if strip_ansi {
crate::util::strip_ansi(raw)
} else {
raw.to_vec()
};

let text = trim_trailing(&text);
let text = trim_trailing(&crate::util::strip_ansi(raw));

if text.is_empty() {
return Classified {
Expand All @@ -67,8 +61,14 @@ pub fn classify(input: ClassifyInput<'_>) -> Classified {
};
}

if text.len() > max_output_bytes {
let mut out = text[..max_output_bytes].to_vec();
let output = if strip_ansi {
text
} else {
trim_trailing(&normalize_crlf(raw))
};

if output.len() > max_output_bytes {
let mut out = output[..max_output_bytes].to_vec();
out.extend_from_slice(b"\n[recall: output truncated]\n");
return Classified {
kind: BlockKind::Normal,
Expand All @@ -79,11 +79,26 @@ pub fn classify(input: ClassifyInput<'_>) -> Classified {

Classified {
kind: BlockKind::Normal,
output: Some(text),
output: Some(output),
truncated: false,
}
}

fn normalize_crlf(data: &[u8]) -> Vec<u8> {
let mut normalized = Vec::with_capacity(data.len());
let mut i = 0;
while i < data.len() {
if data[i] == b'\r' && data.get(i + 1) == Some(&b'\n') {
normalized.push(b'\n');
i += 2;
} else {
normalized.push(data[i]);
i += 1;
}
}
normalized
}

fn trim_trailing(data: &[u8]) -> Vec<u8> {
let end = data
.iter()
Expand Down Expand Up @@ -164,4 +179,20 @@ mod tests {
assert!(out.truncated);
assert!(out.output.unwrap().len() < 4096);
}

#[test]
fn retains_style_without_treating_escapes_as_binary() {
let out = classify(ClassifyInput {
raw: b"\x1b[31mred\x1b[0m\n",
interactive: false,
max_output_bytes: 1024,
strip_ansi: false,
mark_interactive: true,
});
assert_eq!(out.kind, BlockKind::Normal);
assert_eq!(
out.output.as_deref(),
Some(b"\x1b[31mred\x1b[0m".as_slice())
);
}
}
12 changes: 10 additions & 2 deletions src/capture/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,10 @@ fn finalize(

if !active.exclude_output
&& shared.config.proxy.secrets_filter
&& looks_secret(&active.command, &classified.output)
&& looks_secret(
&active.command,
&classified.output.as_ref().map(|out| util::strip_ansi(out)),
)
{
classified = classifier::Classified {
kind: BlockKind::Filtered,
Expand All @@ -334,7 +337,12 @@ fn finalize(
let output_lines = classified
.output
.as_ref()
.map(|out| out.iter().filter(|&&b| b == b'\n').count() as i64)
.map(|out| {
util::strip_ansi(out)
.iter()
.filter(|&&b| b == b'\n')
.count() as i64
})
.unwrap_or(0);

Block {
Expand Down
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl Default for General {
Self {
db_path: default_data_dir().join("recall.db"),
max_output_bytes: 1024 * 1024,
strip_ansi: true,
strip_ansi: false,
hostname: None,
}
}
Expand Down
34 changes: 32 additions & 2 deletions src/db/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ fn insert_block(conn: &Connection, block: &Block) -> Result<()> {
let (blob, codec, text) = match &block.output {
Some(raw) if !raw.is_empty() => {
let compressed = compress(raw)?;
let projection_len = raw.len().min(SEARCH_PROJECTION_BYTES);
let projection = String::from_utf8_lossy(&raw[..projection_len]).into_owned();
let plain = crate::util::strip_ansi(raw);
let projection_len = plain.len().min(SEARCH_PROJECTION_BYTES);
let projection = String::from_utf8_lossy(&plain[..projection_len]).into_owned();
(Some(compressed), Some("zstd".to_string()), Some(projection))
}
_ => (None, None, None),
Expand Down Expand Up @@ -369,6 +370,35 @@ mod tests {
assert_eq!(hits.len(), 1);
}

#[test]
fn styled_output_has_plain_search_projection() {
let db = Db::open_in_memory().unwrap();
let block = Block {
id: "styled".to_string(),
command: "printf color".to_string(),
output: Some(b"\x1b[31mred\x1b[0m".to_vec()),
..Block::default()
};
insert(&db.conn, &block).unwrap();
let projection: String = db
.conn
.query_row(
"SELECT output_text FROM blocks WHERE id = 'styled'",
[],
|row| row.get(0),
)
.unwrap();
assert_eq!(projection, "red");
assert_eq!(
recent(&db.conn, 1).unwrap()[0].output.as_deref(),
Some(b"red".as_slice())
);
assert_eq!(
get(&db.conn, "styled").unwrap().unwrap().output,
block.output
);
}

#[test]
fn settings_roundtrip() {
let db = Db::open_in_memory().unwrap();
Expand Down
Loading
Loading