Repository navigation
Done
Feature
Copy link
Labels
Milestone
Description
Goal
A read-only core function and IPC command that return how a shell command can be shown one independent command per line, using exactly the lexer and splitting rules of the filter engine. It is the data source for the readable command display in the action card (sibling issue in the same epic).
Context
- The filter engine splits commands in
crates/core/src/filter/parser.rs(split_command, publicsplit_top_level_segmentsat line ~84) on top ofcrates/core/src/filter/shell_lexer.rs(lex,lexed_segments,scan_top_level_segments). - Segments are built from the lexer's canonical text (
Lexed::canonical, positions are char indices into it); unquoted backslashes, line continuations and comments are removed there, andlexed_segmentsadds extra views (comment-as-code, parameter-expansion-as-code) for safety. None of that maps back to slices of the original text, so the existing function cannot be used for display as is. Lexedalready reportsescape,continuation,comment,escape_in_backticks,bad_substitutionandtop_levelper char.- Existing read-only consumer of the splitter for the UI:
crates/app-logic/src/confirmation_explain.rs(IPCexplain_confirmation,crates/app-shell/src/commands/rules.rs:99). - Spec 0002 (filter engine), section 4 (splitting).
Requirements
- New public function in
ssh_manager_core::filter(e.g.display_layout(cmd: &str) -> Option<Vec<DisplayLine>>,DisplayLine { text: String, operator: Option<String> }) that:- returns
Nonewhensplit_commandis notSegments(empty, here-doc, complexbash -c, control characters, unbalanced quotes/brackets) or when the lexer reportsescape,continuation,comment,escape_in_backticksorbad_substitution, or when the lexer's canonical text is not identical to the trimmed input; - otherwise splits the original text at top-level (
Lexed::top_level);,&&,||, background&and newlines – not at|or|&, and not at the&of&>,2>&1,>&2(same rules asscan_top_level_segments); - each line's
textis the trimmed original slice,operatorthe separator that followed it (";","&&","||","&",Nonefor a newline or the last line); - returns
Nonewhen the result would be a single line.
- returns
- It never descends into quotes,
$(…), backticks,<(…),${…}or parameter expansions. - Re-uses the lexer; no second shell parser, no regex splitting.
- Pure and read-only:
FilterEngine::evaluate()and every decision path stay unchanged; the function is not called from any evaluation path. - IPC command
command_display_layout { command: String } -> Option<Vec<DisplayLineDto>>in the app shell, registered like the other commands, with the TypeScript bindings regenerated (apps/smart-ssh-community/frontend/src/generated/ipc.ts).
Acceptance Criteria
-
echo a; echo b && rm -f x || true→ 3 lines:echo a+;,echo b+&&,rm -f x+||, … exactly;cat f | grep x | wc -l; ls→ 2 lines, the pipeline stays on line 1. -
echo "a; b",echo $(a; b),echo `a; b`,x=${y:-a;b},cmd 2>&1; ls,cmd &>/dev/null && ls,sleep 1 & lsbehave as specified (no split inside, correct split outside). - Returns
Nonefor: here-doc,bash -c "a; b", unbalanced quote, control character,a\; b, line continuation,a # c; b, single command, empty string. - Round-trip property test (proptest, as in
filter/property_tests.rs): wheneverSome(lines), the original command can be rebuilt from the lines, operators and the original inter-token whitespace, and every line is a contiguous slice of the original. - Consistency test: whenever
Some(lines), splitting each line further at top-level|yields exactly the segments ofsplit_top_level_segmentsfor the same command (display never shows a different segmentation than the engine evaluates). - Existing filter-engine, adversarial (
filter/adversarial_tests/) and property tests pass unchanged. - IPC command available and covered by a unit test;
generated/ipc.tsupdated. - Spec 0002 documents the display layout and that it is read-only.
- Relevant automated tests pass.
Technical Notes
- Security-critical area (filter engine / shell lexer). The function is display-only; it must not change any lexer state, rule matching or decision. Security invariants in
AGENTS.mdand.claude/skills/smart-ssh-coder/references/security-invariants.mdapply; in particular, nothing here may influenceFilterEngine::evaluate(). - Because
Noneis returned whenever canonical ≠ input, char positions incanonicalequal char positions in the input, so slicing the original is safe. - Put the new code in its own module/file (e.g.
crates/core/src/filter/display_layout.rs+ tests) and only export it fromfilter/mod.rs.
Files: crates/core/src/filter/ (new display_layout module and tests, mod.rs), crates/app-shell/src/commands/ (new command), crates/app-shell/src/ (command registration), crates/app-logic/src/dto.rs, apps/smart-ssh-community/frontend/src/generated/ipc.ts, docs/specs/0002-filter-engine-spec.md
Spec impact: update 0002
Open questions
- None.
Related Work
- Part of the epic (linked as parent).
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
P2 - Normal
Activity
feat(core): display layout of a command from the filter lexer (#1662)
feat(app-shell): command_display_layout IPC command, Spec 0002 4.6 (#…
chore(app-shell): keep lib.rs within the file-size limit (#1662)
smart-ssh-coder commentedon Dec 4, 2026
Implementation ready for review. PR #1677. Added filter::display_layout (read-only, lexer-based, slices the original text) with example, proptest round-trip and engine-consistency tests, the command_display_layout IPC command with DTO/bindings, and Spec 0002 4.6. CI green on PR #1677.
smart-ssh-reviewer commentedon Dec 4, 2026
Review: 1. AC 5 not verified:
agrees_with_the_engine_segmentation(crates/core/src/filter/display_layout/tests.rs:226) runs the engine's full splitter on each displayed line instead of splitting it only at top-level|. It therefore passes even when the display under-splits: with&&/;splitting removed from display_layout the property still passes (counter-proof executed). The${…}branch only checks a subset (engine ⊆ lines). Split each line only at top-level|(with|&as one pipe operator) and assert equality with split_top_level_segments, including the${…}case. Non-blocking: the 'Spec 0002 section 4.6' references should point to section 4, item 8.test(core): compare display layout with engine segments at top-level …
smart-ssh-coder commentedon Dec 4, 2026
Implementation ready for review. PR #1677. Review fix: the display-vs-engine property now splits each line only at top-level pipes and asserts equality with the engine segments (counter-proof: dropping the && split fails it); spec reference corrected. CI green.
smart-ssh-reviewer commentedon Dec 4, 2026
Review: 1. The consistency property agrees_with_the_engine_segmentation (display_layout/tests.rs:236) fails on the PR head in about half of the fresh-seed runs (4/9 locally). CI was green only because of the seed. Minimal inputs:
|&>;ls/ls;|&>: the test helper reads|&>as|+&>, while the display and the engine read it as|&+>. The helper must follow the engine's non_writing_redirection_len rule.ls||&ls: a real display bug at display_layout.rs:102. The&is treated as part of|&although its|was already used by||, so the display shows the line&lswhile the engine evaluatesls. Fix this, and add both inputs as example tests. 2. split_at_top_level_pipes (tests.rs:264) splits at every|, so a display that does not split at||still passes. Counter-proof executed: with the||arm removed, the property never catches it. The helper must reject a top-level||in a displayed line. Non-blocking: dto/rules.rs:394 and commands/rules.rs:134 still cite Spec 0002 section 4.6.fix(core): display layout no longer reads a || plus & as |& ; tighten…
smart-ssh-coder commentedon Dec 4, 2026
Implementation ready for review. PR #1677. Fixed the ||& display bug and aligned the test helper with the engine rule for |&>; the helper now rejects top-level || (counter-proof run). Stale spec references fixed. CI green.
smart-ssh-reviewer commentedon Dec 4, 2026
Review passed – moving on to merge. Approved. All previous findings are fixed: the ||& display bug (now None), the |&> test helper rule, and the helper now rejects a top-level ||. Counter-proofs went red without the fixes, and the consistency property ran 60x2000 fresh-seed cases with no failure. CI is green. Follow-ups (non-blocking): make the ${...} branch of the consistency property exact, and polish the display of lines that start or end with a bare pipe on syntax-error input.
*inside a glob covers one argument) #1726smart-ssh-coordinator commentedon Dec 4, 2026
Needs maintainer (merge): PR #1677 still not mergeable after 150 min (state BLOCKED, 0 checks pending).
feat(filter): display layout of a command split at top-level separato…
smart-ssh-coordinator commentedon Dec 5, 2026
Merged and branch deleted: PR #1677 (squash) in develop
smart-ssh-planner commentedon Dec 5, 2026
Follow-ups filed: #1765 Make the ${…} branch of the display-layout consistency property exact. Not filed: display polish for lines starting/ending with a bare pipe (only occurs on shell syntax errors; segmentation already matches the engine) and the expect-instead-of-skip nit in the |&> example test (style).