Skip to content

feat(terminal): triggers that type text when the prompt matches a regex - #1345

Open
chansigit wants to merge 3 commits into
l0ng-ai:mainfrom
chansigit:feature/triggers
Open

chansigit wants to merge 3 commits into
l0ng-ai:mainfrom
chansigit:feature/triggers

Conversation

@chansigit

Copy link
Copy Markdown

What

Adds triggers, in the spirit of iTerm2's Send Text trigger: when the line before the cursor matches a regular expression, tty7 types a configured text into the pane. The usual use is answering a prompt such as Password: or a 2FA menu during an SSH login.

"triggers": [
  { "name": "ssh", "regex": "(?i)password:\\s*$", "text": "hunter2\r" }
]

They can also be edited under Settings → Triggers (list of rows with an enable switch, and a form for name / regex / text).

How

  • Config.triggers: Vec<Trigger> (name, regex, text, enabled), parsed leniently like custom_shells.
  • Matching runs in the pane's reader thread, right after a batch is fed to the emulator, because that is the only place a grid exists. The text is sent as an AlacEvent::PtyWrite, the same path query replies take.
  • A trigger fires once per match and re-arms when the line stops matching.
  • Nothing fires on the alternate screen, or while a pane is replaying on attach (an old Password: in the replay must not be answered again).
  • The line is read up to the cursor, including the last cell when a wrap is pending, and from the first row of a soft-wrapped prompt (up to 8 rows).
  • Triggers follow config reloads; the settings page pushes changes to open panes at once.
  • No cost when no trigger is configured: the reader skips the grid lock entirely.

Limits worth knowing

  • Triggers only fire while a GUI is attached, since the daemon has no grid.
  • The text is stored in config.json in plain text. The docs and the settings page say so.
  • A trigger does not check that the terminal has echo off, so a line that merely prints Password: will also match. Regexes should be specific.

Testing

  • Unit tests for matching, re-arming, config swaps, escapes, and line extraction (plain, row-filling, soft-wrapped, alternate screen).
  • A reader test that feeds Password: through a RemoteTerminal and expects the PtyWrite.
  • cargo test -p tty7 --bin tty7-app: 2604 passed. cargo fmt --check and check-host-boundary.sh are clean.
  • End to end on macOS (arm64): a pane running a shell that prints a prompt and reads a line received the trigger's text.

The settings page is covered by the existing settings tests (search catalog, i18n coverage) but has had little hands-on use so far, and the ja / ru strings would benefit from a native speaker's look.

When the text before the cursor matches a trigger's regex, its text is
written to the pane, like iTerm2's Send Text triggers (e.g. answering a
Password: prompt). A trigger fires once per match, and is skipped on the
alternate screen and while a pane is replaying on attach.

The grid lives in the GUI process, so matching runs in the reader thread
after each batch of output is fed to the emulator. Triggers come from the
new `triggers` list in config.json and follow config reloads.
A prompt that exactly fills the row leaves the cursor on its last cell
with a wrap pending, and one longer than the row soft-wraps; both were
matched without their tail or head. The line is now built into a buffer
the reader keeps instead of a fresh String per batch.
A list of the config's triggers, each with a switch and a form for its
name, regex and text. The text is shown with its control characters as
escapes, so a trailing Return reads as \r. Changes reach open panes at
once.
@mintlify

mintlify Bot commented Nov 26, 2026

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 2a1543f.

Approve preview

@chansigit

Copy link
Copy Markdown
Author

The Linux failure is pwsh_reports_the_full_prompt_cycle_over_a_real_pty_on_unix, and it doesn't look related to this change: PSReadLine crashes on its first read with
mkdirat(…, "/run/user/1001/.dotnet/shm/session…") == -1; errno == ENOENT while creating its history mutex, so the 133;C mark never arrives.

The same test fails with the same exception on other branches, including main (e.g. runs 44744330422, 44743001815, 45421364533). I couldn't reproduce it locally in a container with the same PowerShell 7.6.10 / PSReadLine 2.4.5, so I don't know the trigger. Could someone re-run the job?

@chansigit chansigit closed this Nov 28, 2026
@chansigit chansigit reopened this Nov 28, 2026
@chansigit

Copy link
Copy Markdown
Author

CI is green now. The earlier Linux failure was the flaky pwsh_reports_the_full_prompt_cycle_over_a_real_pty_on_unix test, and it passed on a re-run with no code changes.

Whenever you have time, I'd appreciate a review. A quick summary of what this adds:

  • A triggers list in config.json: each entry has a regex and a text to type when the line before the cursor matches.
  • A Triggers section in Settings to add, edit, enable and remove them, with strings for en/zh/ja/ru.
  • Matching runs in the GUI reader thread, only on the primary screen, and each trigger re-arms once the prompt stops matching.

Happy to split it up, rename things, or change the config shape if you'd prefer a different direction.

This branch has not been deployed

No deployments
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.

1 participant