terminal
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTerminal — 双向交互终端会话
Terminal — Bidirectional Interactive Terminal Session
统一封装串口、SSH 和本地 Shell 的双向交互会话。它补齐 的“监控/发送是分离命令”和 的“远程命令多为一次性执行”之间的空白:当目标需要保持登录状态、菜单状态、REPL 状态或设备 CLI 上下文时,使用本 skill。
serialsshUnified encapsulation of bidirectional interactive sessions for serial ports, SSH, and local shells. It fills the gap between 's "monitoring/sending are separate commands" and 's "remote commands are mostly one-time executions": Use this skill when the target requires maintaining login status, menu status, REPL status, or device CLI context.
serialssh定位
Positioning
- :扫描、监控、单次发送、日志、Hex 查看。
serial - :OpenSSH 配置、远程命令、传输、隧道。
ssh - :保持一个可持续读写的交互式会话,并通过
terminal驱动下一步判断。send/read
- : Scanning, monitoring, one-time sending, logging, Hex viewing.
serial - : OpenSSH configuration, remote commands, file transfer, tunneling.
ssh - : Maintain a sustainable read-write interactive session, and drive subsequent judgments through
terminal.send/read
配置
Configuration
环境级配置 (config.json
)
config.jsonEnvironment-level Configuration (config.json
)
config.jsonterminal skill 的环境级配置目前为空对象 。交互终端的关键参数通常和具体会话绑定,优先通过 命令显式传入,避免误连设备或误用凭据。
{}startThe environment-level configuration for the terminal skill is currently an empty object . Key parameters for interactive terminals are usually bound to specific sessions, and are preferably passed explicitly via the command to avoid misconnecting devices or misusing credentials.
{}start会话状态 (.embeddedskills/state.json
)
.embeddedskills/state.jsonSession State (.embeddedskills/state.json
)
.embeddedskills/state.json后台会话运行时状态保存到工作区的 ,使用 字段记录会话名、后端、PID、TCP 控制端口和日志路径。
.embeddedskills/state.jsonterminal_sessionsThe runtime state of background sessions is saved to the workspace's , using the field to record session names, backends, PIDs, TCP control ports, and log paths.
.embeddedskills/state.jsonterminal_sessions参数优先级
Parameter Priority
- CLI 参数 (,
--port,--baudrate,--host等) - 最高优先级--name - 会话状态 (中已启动的
.embeddedskills/state.json)terminal_sessions - 默认值 - 最低优先级
- CLI Parameters (,
--port,--baudrate,--host, etc.) - Highest priority--name - Session State (already started in
terminal_sessions).embeddedskills/state.json - Default Values - Lowest priority
子命令
Subcommands
| 子命令 | 用途 | 风险 |
|---|---|---|
| 启动一个后台交互会话 | 中 |
| 列出现有会话 | 低 |
| 查询单个会话状态 | 低 |
| 向会话写入文本或 Hex 数据 | 中 |
| 读取并清空会话输出缓冲 | 低 |
| 前台行模式接入会话 | 中 |
| 停止会话并清理状态 | 中 |
| Subcommand | Purpose | Risk |
|---|---|---|
| Start a background interactive session | Medium |
| List existing sessions | Low |
| Query the status of a single session | Low |
| Write text or Hex data to the session | Medium |
| Read and clear the session output buffer | Low |
| Access the session in foreground line mode | Medium |
| Stop the session and clean up state | Medium |
后端
Backends
| 后端 | 适用场景 | 依赖 |
|---|---|---|
| MCU UART 控制台、AT 命令、Bootloader 菜单、板卡 CLI | |
| Linux 开发板交互 Shell、登录后持续操作 | OpenSSH 客户端 |
| 本机临时 Shell、REPL、CLI 程序交互 | Python 标准库 |
| Backend | Applicable Scenarios | Dependencies |
|---|---|---|
| MCU UART console, AT commands, Bootloader menus, board CLI | |
| Linux development board interactive shells, continuous operations after login | OpenSSH client |
| Local temporary shells, REPL, CLI program interaction | Python standard library |
脚本调用
Script Invocation
所有脚本位于 skill 目录的 下,通过 直接调用。命令示例均以当前 skill 目录为基准。
scripts/pythonbash
undefinedAll scripts are located in the directory of the skill, and can be called directly via . Command examples are based on the current skill directory.
scripts/pythonbash
undefined启动串口终端
Start serial terminal
python scripts/terminal_session.py start serial --port COM11 --baudrate 115200 --name board
python scripts/terminal_session.py start serial --port COM11 --baudrate 115200 --name board
启动 SSH 终端,host 使用 ~/.ssh/config 中的 Host 别名
Start SSH terminal, use Host alias from ~/.ssh/config
python scripts/terminal_session.py start ssh --host 1380-P904 --name devboard
python scripts/terminal_session.py start ssh --host 1380-P904 --name devboard
启动本地 Shell
Start local Shell
python scripts/terminal_session.py start local --name local-shell
python scripts/terminal_session.py start local --name local-shell
发送一行命令并追加 CRLF
Send a command line with appended CRLF
python scripts/terminal_session.py send board "help" --crlf
python scripts/terminal_session.py send board "help" --crlf
读取输出,最多等待 1 秒
Read output, wait up to 1 second
python scripts/terminal_session.py read board --timeout 1
python scripts/terminal_session.py read board --timeout 1
前台行模式接入
Access in foreground line mode
python scripts/terminal_session.py attach board
python scripts/terminal_session.py attach board
查询与停止
Query and stop
python scripts/terminal_session.py list
python scripts/terminal_session.py status board
python scripts/terminal_session.py stop board
undefinedpython scripts/terminal_session.py list
python scripts/terminal_session.py status board
python scripts/terminal_session.py stop board
undefined会话状态详情
Session State Details
会话元数据保存到工作区:
text
.embeddedskills/state.json使用 字段记录:
terminal_sessionsjson
{
"terminal_sessions": {
"board": {
"backend": "serial",
"tcp_port": 23145,
"pid": 1234,
"started_at": "2026-05-26T10:00:00+08:00"
}
}
}后台进程日志保存到:
text
.embeddedskills/logs/terminal/Session metadata is saved to the workspace:
text
.embeddedskills/state.jsonRecorded using the field:
terminal_sessionsjson
{
"terminal_sessions": {
"board": {
"backend": "serial",
"tcp_port": 23145,
"pid": 1234,
"started_at": "2026-05-26T10:00:00+08:00"
}
}
}Background process logs are saved to:
text
.embeddedskills/logs/terminal/输出格式
Output Format
脚本默认输出 JSON:
json
{
"status": "ok",
"action": "read",
"summary": "读取 42 字节",
"details": {
"session": "board",
"text": "help\r\n..."
}
}错误输出:
json
{
"status": "error",
"action": "send",
"error": {
"code": "session_unreachable",
"message": "会话不可达,可能已退出"
}
}Scripts output JSON by default:
json
{
"status": "ok",
"action": "read",
"summary": "Read 42 bytes",
"details": {
"session": "board",
"text": "help\r\n..."
}
}Error output:
json
{
"status": "error",
"action": "send",
"error": {
"code": "session_unreachable",
"message": "Session unreachable, may have exited"
}
}操作流程
Operation Process
- 判断是否真的需要保持交互状态;若只是一次性远程命令,优先使用 ;若只是串口抓日志,优先使用
ssh。serial - 选择后端:串口控制台用 ,远程 shell 用
serial,本机交互程序用ssh。local - 后先
start获取启动横幅、登录提示或 shell prompt。read --timeout 1 - 每次 后都用
send观察反馈,再决定下一步。read --timeout <秒> - 完成后执行 ,避免后台进程长期占用串口、SSH 连接或本地 Shell。
stop
- Determine whether interactive state retention is truly needed; if it's just a one-time remote command, prioritize using ; if it's just serial port log capturing, prioritize using
ssh.serial - Select the backend: use for serial consoles,
serialfor remote shells, andsshfor local interactive programs.local - After , first use
startto get the startup banner, login prompt, or shell prompt.read --timeout 1 - After each , use
sendto observe feedback before deciding the next step.read --timeout <seconds> - Execute after completion to avoid background processes occupying serial ports, SSH connections, or local shells for long periods.
stop
核心规则
Core Rules
- 不自动猜测串口端口、波特率、SSH Host 或登录凭据。
- 未明确用途时不主动发送任何会改变设备状态的命令。
- 多个会话必须使用不同 ,避免输出混淆。
--name - 会清空当前输出缓冲;重要输出需要及时记录到最终回复。
read - 是行模式,不等同于完整 TTY/raw 模式;需要全屏程序、vim、top、交互式密码输入时,优先让用户使用真实终端工具。
attach - 串口会话会独占真实串口;如果需要和外部串口工具共享端口,先使用 skill 的 mux 能力。
serial - SSH 后端使用 的 Host 别名;配置主机、跳板机、传输文件仍交给
~/.ssh/configskill。ssh - 失败时保留真实错误:端口占用、缺少 、
pyserial不存在、Host 别名无法解析、进程已退出等都不要吞掉。ssh
- Do not automatically guess serial ports, baud rates, SSH Hosts, or login credentials.
- Do not actively send any commands that change device status when the purpose is unclear.
- Multiple sessions must use different to avoid output confusion.
--name - will clear the current output buffer; important output needs to be recorded in the final reply promptly.
read - is line mode, not equivalent to full TTY/raw mode; when full-screen programs, vim, top, or interactive password input are needed, prioritize letting users use real terminal tools.
attach - Serial sessions will occupy the physical serial port exclusively; if sharing the port with external serial tools is needed, first use the mux capability of the skill.
serial - The SSH backend uses Host aliases from ; configuration of hosts, jump servers, and file transfer are still handled by the
~/.ssh/configskill.ssh - Retain real errors when failures occur: do not swallow errors such as port occupation, missing , non-existent
pyserial, unresolvable Host aliases, exited processes, etc.ssh