Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
74f9d98
build(tooling): allow cli scope in commitlint
HalfSweet Nov 29, 2026
4b5f387
feat(capture): add channel profiling, transitions and timing queries
HalfSweet Nov 29, 2026
2b95203
feat(decode): add stream summaries and structured filters in hsync-ui…
HalfSweet Nov 29, 2026
b4c1eb8
feat(session): expose decoder wait, summary and filter queries
HalfSweet Nov 29, 2026
9a3e5bf
feat(cli): add standalone agent-friendly hsync-cli binary
HalfSweet Nov 29, 2026
31a6cc7
test(cli): add end-to-end integration tests for hsync-cli
HalfSweet Nov 29, 2026
873b9aa
docs: document hsync-cli and add official agent skill
HalfSweet Nov 29, 2026
a0302ab
fix(uiharu): satisfy Rust 1.100 clippy needless_range_loop
HalfSweet Nov 30, 2026
f40d52f
fix(capture): satisfy Rust 1.100 clippy needless_range_loop
HalfSweet Nov 30, 2026
74c748e
fix(decode): avoid DecodeSet::wait deadlock and harden event filters
HalfSweet Nov 30, 2026
a038948
fix(cli): harden flag parsing, exec timeouts, units and command edges
HalfSweet Nov 30, 2026
d05f1e2
test(cli): add regression tests for exec timeout, flags and queries
HalfSweet Nov 30, 2026
3ed300f
refactor(cli): expose reusable config, catalog and query helpers
HalfSweet Nov 29, 2026
09bd565
feat(cli): add stateful stdio MCP server in hsync-cli mcp
HalfSweet Nov 29, 2026
5acadce
test(cli): add stdio JSON-RPC integration tests for hsync-cli mcp
HalfSweet Nov 29, 2026
0538e2b
docs: document hsync-cli mcp server in docs, skill and READMEs
HalfSweet Nov 29, 2026
254e7f1
fix(cli): harden MCP JSON-RPC batching, armed lifecycle and validation
HalfSweet Nov 30, 2026
e1e9674
test(cli): add MCP tests for batching, validation and arm recovery
HalfSweet Nov 30, 2026
134baf8
feat(cli): add diff, assert and live protocol-event stop commands
HalfSweet Nov 29, 2026
18314d2
feat(cli): expose diff, assert and protocol stop in hsync-cli mcp
HalfSweet Nov 29, 2026
44493d1
test(cli): add CLI and MCP tests for diff, assert and protocol stop
HalfSweet Nov 29, 2026
1e51abb
docs: document diff, assert and live protocol-event stop
HalfSweet Nov 29, 2026
390be6d
fix(cli): harden diff, assert and live protocol-event stop
HalfSweet Nov 30, 2026
f0c983a
test(cli): add regression tests for diff, assert and demo protocol stop
HalfSweet Nov 30, 2026
4eb1917
docs: exempt hsync-cli from the i18n-keys-only rule in AGENTS.md
HalfSweet Dec 1, 2026
2ae6452
refactor(cli): define CliError as a thiserror enum
HalfSweet Dec 1, 2026
8fdfe1e
fix(cli): honour fired buffer triggers and bound waits after stop
HalfSweet Dec 1, 2026
3e333a2
fix(cli): stop --exec from hanging on background processes
HalfSweet Dec 1, 2026
fb2cd9f
fix(cli): give --exec a grace period before killing it
HalfSweet Dec 1, 2026
c8cd009
fix(cli): pass --exec commands to cmd.exe verbatim on Windows
HalfSweet Dec 1, 2026
c534a24
fix(cli): apply raw device options before sizing --duration
HalfSweet Dec 1, 2026
bcb4d7a
fix(cli): scale the default --timeout with the requested capture
HalfSweet Dec 1, 2026
2381e97
perf(decode): visit filtered decode events in one pass
HalfSweet Dec 1, 2026
9a4990e
perf(cli): stream decode ndjson output in one pass per stream
HalfSweet Dec 1, 2026
406c38d
fix(cli): keep the view session when decode saves an .hsync file
HalfSweet Dec 1, 2026
7d932fd
fix(cli): mark pulses cut off by the capture boundary
HalfSweet Dec 1, 2026
f06b961
fix(cli): fit wave columns to windows narrower than --width
HalfSweet Dec 1, 2026
b45cc61
fix(cli): reject search patterns on channels the capture lacks
HalfSweet Dec 1, 2026
f927fd1
fix(cli): exit quietly when stdout is closed early
HalfSweet Dec 1, 2026
fb6c7c0
test(decode): cover one-pass for_each_match over a decode store
HalfSweet Dec 1, 2026
09eaf6a
test(cli): cover capture deadlines, default timeout and exec grace
HalfSweet Dec 1, 2026
94bd4a6
test(cli): add regression tests for options, decode save and queries
HalfSweet Dec 1, 2026
35130aa
docs: document --exec-grace, timeout defaults and truncated pulses
HalfSweet Dec 1, 2026
3d392f4
Merge branch 'feat/hsync-cli' into feat/hsync-mcp
HalfSweet Dec 1, 2026
6e15b30
fix(cli): run MCP captures through the CLI's capture loop
HalfSweet Dec 1, 2026
27a5472
fix(cli): count capture_collect timeouts from the collect call
HalfSweet Dec 1, 2026
acea9d6
fix(cli): keep MCP captures whose save fails
HalfSweet Dec 1, 2026
55b5ef3
fix(cli): restore the previous decoders when decode_set fails
HalfSweet Dec 1, 2026
f7cb141
fix(cli): give --exec commands an empty stdin
HalfSweet Dec 1, 2026
fcd3ef1
fix(cli): answer non-UTF-8 MCP input with a parse error
HalfSweet Dec 1, 2026
3c1ff8e
feat(session): let a decode wait give up when cancelled
HalfSweet Dec 1, 2026
3ec3e7c
fix(cli): cancel running MCP captures on notifications/cancelled
HalfSweet Dec 1, 2026
c8352c6
fix(cli): reject mistyped and unknown MCP tool arguments
HalfSweet Dec 1, 2026
478a2b1
fix(cli): range-check MCP integer arguments before narrowing them
HalfSweet Dec 1, 2026
6ca0974
feat(session): load a decoder module from its IR text
HalfSweet Dec 1, 2026
b83ac4f
fix(cli): keep MCP decoder modules in memory and load them everywhere
HalfSweet Dec 1, 2026
062b478
fix(session): forget an open device that was plugged back in
HalfSweet Dec 1, 2026
9bbc0c9
fix(cli): reopen an analyzer that went away in the MCP server
HalfSweet Dec 1, 2026
f373b2b
fix(cli): count held captures against the MCP maxMemory guardrail
HalfSweet Dec 1, 2026
0d435f5
fix(cli): check decode_query's view before filtering streams
HalfSweet Dec 1, 2026
1882b69
fix(cli): mark pulses cut off by the capture in MCP capture_measure
HalfSweet Dec 1, 2026
38c423a
fix(cli): fit MCP capture_wave to windows narrower than its width
HalfSweet Dec 1, 2026
17916c8
fix(cli): reject MCP search patterns on channels the capture lacks
HalfSweet Dec 1, 2026
3501608
fix(cli): keep the view session when MCP capture_save writes .hsync
HalfSweet Dec 1, 2026
07c2466
test(cli): cover the shared capture loop, argument checks and cancels
HalfSweet Dec 1, 2026
2d75c54
test(session): cover module text, cancelled decode waits and unplugging
HalfSweet Dec 1, 2026
a412139
test(cli): cover the MCP fixes over real stdio
HalfSweet Dec 1, 2026
32af36a
docs: describe how the MCP tools check, time out, cancel and save
HalfSweet Dec 1, 2026
d829f56
Merge branch 'feat/hsync-mcp' into feat/cli-verify
HalfSweet Dec 1, 2026
32630a2
feat(decode): read a decode stream's events once as they settle
HalfSweet Dec 1, 2026
48226b9
fix(cli): look only at newly settled events in protocol stops
HalfSweet Dec 1, 2026
b8eb5fa
fix(cli): stop at the Nth match when --stop-after-events has a filter
HalfSweet Dec 1, 2026
4c862d2
fix(cli): fail protocol stops at once when they can never match
HalfSweet Dec 1, 2026
536d044
fix(cli): report device failures before unmet protocol stops
HalfSweet Dec 1, 2026
d6ea3e4
fix(cli): report protocolTrigger only when the hit stopped the capture
HalfSweet Dec 1, 2026
56a2e8d
fix(cli): reject protocol stop options that cannot take effect
HalfSweet Dec 1, 2026
0d2f6bc
feat(session): expose the open device's capture preset
HalfSweet Dec 1, 2026
565b043
fix(cli): keep the Demo pattern's channel names with explicit decoders
HalfSweet Dec 1, 2026
5e772cf
fix(cli): report a capture whose thread vanished as a lost device
HalfSweet Dec 1, 2026
6b3ac72
fix(cli): call long but equal decoded streams identical in diff
HalfSweet Dec 1, 2026
87edf91
perf(cli): read each decoded stream in one pass for diff
HalfSweet Dec 1, 2026
87ee0b8
refactor(capture): visit every edge delta through for_each_edge_delta
HalfSweet Dec 1, 2026
2f1e180
fix(cli): check every edge pair in deltaBound assertions
HalfSweet Dec 1, 2026
aa635c9
fix(cli): read assertion fields in camelCase
HalfSweet Dec 1, 2026
6413e43
fix(cli): accept only known channelActivity expectations
HalfSweet Dec 1, 2026
cabe5de
fix(cli): select assertion streams by one name-or-label rule
HalfSweet Dec 1, 2026
4a8ac5a
fix(cli): fail stream assertions on a decoder that failed part-way
HalfSweet Dec 1, 2026
ab3e0a7
refactor(cli): judge a finished protocol stop in one place
HalfSweet Dec 1, 2026
eb97bdc
refactor(cli): compare each decoded stream of a diff in diff_stream
HalfSweet Dec 1, 2026
1356b3f
test(decode): cover reading a store's events once by start window
HalfSweet Dec 1, 2026
460ed5c
test(session): cover settled windows over a decode set and the demo p…
HalfSweet Dec 1, 2026
8a478e7
test(capture): cover visiting every edge delta past the profile cap
HalfSweet Dec 1, 2026
a3e0948
test(cli): cover protocol stop, diff and assert fixes in unit tests
HalfSweet Dec 1, 2026
3325235
test(cli): cover protocol stop and assertion fixes over the CLI and MCP
HalfSweet Dec 1, 2026
fee4295
docs: describe protocol stop, diff and assert behaviour after the fixes
HalfSweet Dec 1, 2026
8ece7a1
docs(cli): name println! in the output module's doc comments
HalfSweet Dec 1, 2026
1e53c71
Merge branch 'feat/hsync-cli' into feat/hsync-mcp
HalfSweet Dec 1, 2026
ab914ca
Merge branch 'feat/hsync-mcp' into feat/cli-verify
HalfSweet Dec 1, 2026
dc37025
Merge remote-tracking branch 'origin/main' into feat/cli-verify
HalfSweet Dec 1, 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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ Sipeed has given strong support to HSync's work on its SLogic analyzers.

### Command line & automation (`hsync-cli`)

- **Standalone headless CLI (`hsync-cli`)** for scripts, hardware-in-the-loop tests and AI coding agents: `doctor`, `devices`, `catalog`, declarative `capture` (with `--trigger-timeout`, `--fallback-instant`, memory guardrails and `--exec` arm-then-act DUT stimulation), L0 signal `inspect`, L1/L2 `decode` (shorthand pipelines, summaries, structured `--where` filters, compact protocol transcripts and NDJSON), L3 `transitions`, Unicode `wave`, `measure` (pulses, edges, glitches, cross-channel deltas), `search` and `export`.
- **Built-in stateful MCP server (`hsync-cli mcp`)** over stdio JSON-RPC 2.0: keeps USB analyzers and captures open in memory across multi-turn agent sessions, exposes two-phase `capture_arm` / `capture_collect` and hot-loading custom `uiharu` DSL IR modules.
- **Standalone headless CLI (`hsync-cli`)** for scripts, hardware-in-the-loop tests and AI coding agents: `doctor`, `devices`, `catalog`, declarative `capture` (with `--trigger-timeout`, `--fallback-instant`, memory guardrails, `--exec` arm-then-act DUT stimulation and live software protocol-event early stop via `--stop-on-error` / `--stop-on-event` / `--post-trigger`), L0 signal `inspect`, L1/L2 `decode` (shorthand pipelines, summaries, structured `--where` filters, compact protocol transcripts and NDJSON), L3 `transitions`, Unicode `wave`, `measure` (pulses, edges, glitches, cross-channel deltas), `search`, before/after `diff`, declarative `assert` and `export`.
- **Built-in stateful MCP server (`hsync-cli mcp`)** over stdio JSON-RPC 2.0: keeps USB analyzers and captures open in memory across multi-turn agent sessions, exposes two-phase `capture_arm` / `capture_collect`, live protocol-event early stop, `capture_diff`, `capture_assert` and hot-loading custom `uiharu` DSL IR modules.
- **Structured `--json` mode** across every command (including dual sample/time coordinates and actionable error hints) plus a ready-to-use Agent Skill in [skills/hsync-cli/SKILL.md](skills/hsync-cli/SKILL.md). See the [CLI guide](docs/cli.md).

## Download
Expand Down
4 changes: 2 additions & 2 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ SLogic 系列逻辑分析仪的适配得到了矽速科技(Sipeed)的大力

### 命令行与自动化(`hsync-cli`)

- **独立无头命令行工具(`hsync-cli`)**,面向脚本、硬件在环测试与 AI Agent:涵盖 `doctor`、`devices`、`catalog`、声明式 `capture`(支持 `--trigger-timeout`、`--fallback-instant`、内存护栏与 `--exec` 先武装后激励协同)、L0 信号体检 `inspect`、L1/L2 `decode`(简写流水线、解码摘要、结构化 `--where` 过滤、紧凑协议视图与 NDJSON)、L3 `transitions` / Unicode `wave` / `measure`(脉宽、边沿、毛刺、跨通道延迟)、`search` 与 `export`。
- **内置有状态 MCP 服务器(`hsync-cli mcp`)**(stdio JSON-RPC 2.0):在多轮 Agent 会话期间保持 USB 逻辑分析仪常驻与采集数据驻留内存,提供两阶段 `capture_arm` / `capture_collect` 与自定义 `uiharu` DSL IR 模块热加载。
- **独立无头命令行工具(`hsync-cli`)**,面向脚本、硬件在环测试与 AI Agent:涵盖 `doctor`、`devices`、`catalog`、声明式 `capture`(支持 `--trigger-timeout`、`--fallback-instant`、内存护栏、`--exec` 先武装后激励协同,以及基于 `--stop-on-error` / `--stop-on-event` / `--post-trigger` 的实时协议事件软件触发早停)、L0 信号体检 `inspect`、L1/L2 `decode`(简写流水线、解码摘要、结构化 `--where` 过滤、紧凑协议视图与 NDJSON)、L3 `transitions` / Unicode `wave` / `measure`(脉宽、边沿、毛刺、跨通道延迟)、`search`、前后对照 `diff`、声明式断言 `assert` 与 `export`。
- **内置有状态 MCP 服务器(`hsync-cli mcp`)**(stdio JSON-RPC 2.0):在多轮 Agent 会话期间保持 USB 逻辑分析仪常驻与采集数据驻留内存,提供两阶段 `capture_arm` / `capture_collect`、实时协议事件早停、`capture_diff`、`capture_assert` 与自定义 `uiharu` DSL IR 模块热加载。
- **全局 `--json` 结构化输出**(统一双坐标系与可恢复错误提示),并在 [skills/hsync-cli/SKILL.md](skills/hsync-cli/SKILL.md) 提供官方 Agent Skill。参见[命令行指南(英文)](docs/cli.md)。

## 下载
Expand Down
142 changes: 99 additions & 43 deletions crates/hsync-capture/src/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use std::ops::Range;

use hsync_core::{ChannelIndex, SampleIndex};
use serde::Serialize;
use serde::{Deserialize, Serialize};

use crate::capture::LogicCapture;
use crate::channel::ChannelData;
Expand All @@ -19,7 +19,7 @@ pub const DEFAULT_PROFILE_EDGE_LIMIT: usize = 65_536;
pub const DEFAULT_MAX_BURSTS: usize = 32;

/// High-level state of a logic channel over an inspected range.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum ChannelActivity {
/// The inspected range holds no samples.
Expand Down Expand Up @@ -601,43 +601,25 @@ impl LogicCapture {
Some((rows, false))
}

/// Measures delays from each `from_edge` on `from_edge.0` inside `range` to the first
/// subsequent `to_edge` on `to_edge.0` (at or after the reference edge, within `range` and
/// optional `max_delta`).
pub fn measure_edge_deltas(
/// Visits, in order, the delay from each `from_edge` on `from_edge.0` inside `range` to the
/// first subsequent `to_edge` on `to_edge.0` (at or after the reference edge, within `range`
/// and optional `max_delta`), until `visit` returns `false`. Every pair is visited, however
/// many there are; `None` when either channel is missing.
pub fn for_each_edge_delta(
&self,
from_edge: (ChannelIndex, EdgeKind),
to_edge: (ChannelIndex, EdgeKind),
range: Range<SampleIndex>,
max_delta: Option<SampleIndex>,
limit: usize,
) -> Option<EdgeDeltaSummary> {
mut visit: impl FnMut(EdgeDeltaHit) -> bool,
) -> Option<()> {
let (ch_a, edge_a) = from_edge;
let (ch_b, edge_b) = to_edge;
let data_a = self.channel(ch_a)?;
let data_b = self.channel(ch_b)?;
let to = range.end.min(self.len());
let from = range.start.min(to);
if from >= to {
return Some(EdgeDeltaSummary {
count: 0,
min: None,
p5: None,
median: None,
p95: None,
max: None,
mean: None,
hits: Vec::new(),
truncated: false,
});
}

let mut deltas = Vec::new();
let mut hits = Vec::new();
let mut truncated = false;
let mut cursor = from;
let cap = DEFAULT_PROFILE_EDGE_LIMIT;

while let Some(sample_a) = next_matching_edge(data_a, cursor, to, edge_a) {
cursor = sample_a;
let search_end = max_delta
Expand All @@ -654,24 +636,48 @@ impl LogicCapture {
} else {
next_matching_edge(data_b, sample_a, search_end, edge_b)
};
if let Some(sample_b) = target {
let delta = sample_b - sample_a;
if deltas.len() >= cap {
truncated = true;
break;
}
deltas.push(delta);
if hits.len() < limit {
hits.push(EdgeDeltaHit {
from_sample: sample_a,
to_sample: sample_b,
delta,
});
} else {
truncated = true;
}
if let Some(sample_b) = target
&& !visit(EdgeDeltaHit {
from_sample: sample_a,
to_sample: sample_b,
delta: sample_b - sample_a,
})
{
break;
}
}
Some(())
}

/// Measures delays from each `from_edge` on `from_edge.0` inside `range` to the first
/// subsequent `to_edge` on `to_edge.0` (at or after the reference edge, within `range` and
/// optional `max_delta`). At most [`DEFAULT_PROFILE_EDGE_LIMIT`] pairs are measured; use
/// [`Self::for_each_edge_delta`] to look at every one.
pub fn measure_edge_deltas(
&self,
from_edge: (ChannelIndex, EdgeKind),
to_edge: (ChannelIndex, EdgeKind),
range: Range<SampleIndex>,
max_delta: Option<SampleIndex>,
limit: usize,
) -> Option<EdgeDeltaSummary> {
let mut deltas = Vec::new();
let mut hits = Vec::new();
let mut truncated = false;
let cap = DEFAULT_PROFILE_EDGE_LIMIT;
self.for_each_edge_delta(from_edge, to_edge, range, max_delta, |hit| {
if deltas.len() >= cap {
truncated = true;
return false;
}
deltas.push(hit.delta);
if hits.len() < limit {
hits.push(hit);
} else {
truncated = true;
}
true
})?;

let dist = summarize_distribution(deltas, truncated);
Some(EdgeDeltaSummary {
Expand Down Expand Up @@ -840,4 +846,54 @@ mod tests {
}]
);
}

#[test]
fn for_each_edge_delta_visits_every_pair_past_the_profile_cap() {
// 2,188 words of one-sample high pulses (bits 1010…, 70,016 pulses), then one
// 12-sample pulse.
let mut words = vec![0x5555_5555_5555_5555u64; 2_188];
words.push(0x0000_0000_0000_FFF0);
let mut capture = LogicCapture::new(1_000_000, [0]);
capture
.channel_mut(0)
.expect("channel")
.append_words(&words);
let len = capture.len();
let rise = (0, EdgeKind::Rise);
let fall = (0, EdgeKind::Fall);

let mut count = 0u64;
let mut widest = 0u64;
capture
.for_each_edge_delta(rise, fall, 0..len, None, |hit| {
count += 1;
widest = widest.max(hit.delta);
true
})
.expect("channel exists");
// The first pulse starts at sample 0, which is no edge; the wide one makes up for it.
assert_eq!(count, 2_188 * 32);
assert_eq!(widest, 12);

// The capped summary stops short of the wide pulse.
let capped = capture
.measure_edge_deltas(rise, fall, 0..len, None, 5)
.expect("channel exists");
assert_eq!(capped.count, DEFAULT_PROFILE_EDGE_LIMIT as u64);
assert!(capped.truncated);
assert_eq!(capped.max, Some(1));

// The visitor stops when asked, and a missing channel is `None`.
let mut visited = 0;
capture.for_each_edge_delta(rise, fall, 0..len, None, |_| {
visited += 1;
visited < 3
});
assert_eq!(visited, 3);
assert!(
capture
.for_each_edge_delta((9, EdgeKind::Rise), fall, 0..len, None, |_| true)
.is_none()
);
}
}
Loading