Long Context Shell
Use this skill when a shell command is likely to produce long output, keep running, refresh continuously, or require structured monitoring instead of raw stdout.
Invoke When
- - The command may print more than a small screen of output
- The command may run for a long time
- The command may stream continuously, such as
watch, top, tail -f, ping, or log followers - The command fails and you need a lightweight scan instead of manually reviewing a large log
Core Behavior
- - Always write stdout and stderr to a timestamped log file
- Return a compact status card instead of raw full output
- Truncate long previews by default and point to the log file for deeper inspection
- Preserve timestamps so you can inspect the latest state or a specific time window
- Offer a lightweight scan step for locating likely errors, warnings, and failures
Tools
long_context_shell_run
Run a shell command in a detached process with file-backed logging.
Inputs
- -
command (string, required): shell command to run - INLINECODE6 (number, optional): how long to wait before returning an initial status card
- INLINECODE7 (boolean, optional): force monitor-first mode and return quickly for later peeks
- INLINECODE8 (number, optional): lines to show from the beginning of the log
- INLINECODE9 (number, optional): lines to show from the end of the log
Behavior
- 1. Start the command through the platform shell
- Write stdout and stderr to a log file with timestamps
- If
background is true, prefer a short initial wait and return control quickly - Return a status card with session id, log path, line count, byte count, status, background mode, and truncated preview
- If the command still runs, use
long_context_shell_peek later instead of rerunning the command
long_context_shell_peek
Read the latest state of an existing session or log file.
Inputs
- -
sessionId (string, optional): previously returned session id - INLINECODE14 (string, optional): direct path to a log file if session id is unavailable
- INLINECODE15 (number, optional): lines to show from the beginning
- INLINECODE16 (number, optional): lines to show from the end
- INLINECODE17 (string, optional): timestamp fragment to filter lines, such as INLINECODE18
Behavior
- 1. Resolve the session or log file
- Detect whether the process is still running or already exited
- Return a compact status card with truncated preview
- If
timeQuery is present, return matching lines for that timestamp fragment
long_context_shell_scan
Scan a large log for likely failures instead of manually reading the full file.
Inputs
- -
sessionId (string, optional): previously returned session id - INLINECODE22 (string, optional): direct path to a log file
- INLINECODE23 (array of strings, optional): custom match patterns
- INLINECODE24 (number, optional): surrounding lines to include around each match
- INLINECODE25 (number, optional): maximum number of matches to return
Behavior
- 1. Search the log for strong failure signals such as
error, exception, failed, fatal, and INLINECODE30 - Rank matches by severity so likely root-cause lines appear before generic warnings
- Return the strongest matches with line numbers, severity, and short context
- Prefer this tool over manual full-log inspection when output is large
long_context_shell_stop
Stop a running session when monitoring is no longer needed.
Inputs
- -
sessionId (string, required): session to stop
Recommended Workflow
- 1. Use
long_context_shell_run for long or continuous commands - If status is
running, use long_context_shell_peek to monitor progress - If status is
failed or the preview is too short to explain the problem, use INLINECODE37 - Only read the full log manually when the scan still leaves important ambiguity
Debug Tips
- - Start with a small
waitMs and inspect the first status card before increasing complexity - If a command is expected to keep running, set
background: true and observe with repeated INLINECODE40 - Use
timeQuery with the startedAt timestamp prefix to zoom into a suspicious time slice without reading the whole log - If
preview is truncated, treat logPath as the source of truth and use scan before opening the whole file - If
scan misses the real issue, retry with custom patterns that match the toolchain, framework, or service you are debugging - When shell quoting gets tricky, first validate the raw command directly in the terminal, then move the exact command string into INLINECODE48
- Prefer short self-contained repro commands such as
node -e or a tiny script file when debugging behavior across shells - Remember that shell syntax can differ across Unix and Windows, so commands using pipes, redirects, or quoting may need platform-specific forms
- For continuous commands, always finish the debug loop with
long_context_shell_stop so old sessions do not keep running in the background - To review a human-readable end-to-end scenario, run
node manual-flow-test.js and inspect the printed status cards and scan output
Safety
- - Do not run destructive commands without explicit user approval
- Ask before using commands that delete files, reformat disks, reboot the machine, or escalate privileges
- Prefer
long_context_shell_scan over full-log manual review when output is large - Use
long_context_shell_stop when a continuous command is no longer needed, especially for tail -f, watch, or similar monitoring sessions
Examples
-
long_context_shell_run({ command: "npm run build", waitMs: 1500 })
-
long_context_shell_run({ command: "tail -f app.log", background: true, waitMs: 500 })
-
long_context_shell_peek({ sessionId: "..." })
- - Check a specific timestamp:
-
long_context_shell_peek({ sessionId: "...", timeQuery: "2026-03-24T10:15" })
-
long_context_shell_scan({ sessionId: "..." })
- - Human-readable flow test:
- INLINECODE61
长上下文Shell
当Shell命令可能产生较长输出、持续运行、不断刷新,或需要结构化监控而非原始标准输出时,使用此技能。
调用时机
- - 命令可能输出超过一小屏的内容
- 命令可能运行较长时间
- 命令可能持续输出流,例如watch、top、tail -f、ping或日志跟踪程序
- 命令执行失败,需要轻量级扫描而非手动审查大量日志
核心行为
- - 始终将标准输出和标准错误写入带时间戳的日志文件
- 返回紧凑的状态卡片而非原始完整输出
- 默认截断长预览,并指向日志文件供深入检查
- 保留时间戳,以便检查最新状态或特定时间窗口
- 提供轻量级扫描步骤,用于定位可能的错误、警告和故障
工具
longcontextshell_run
在分离进程中运行Shell命令,并启用文件日志记录。
输入参数
- - command(字符串,必填):要运行的Shell命令
- waitMs(数字,可选):返回初始状态卡片前的等待时间
- background(布尔值,可选):强制优先监控模式,快速返回以便后续查看
- headLines(数字,可选):从日志开头显示的行数
- tailLines(数字,可选):从日志末尾显示的行数
行为
- 1. 通过平台Shell启动命令
- 将标准输出和标准错误写入带时间戳的日志文件
- 如果background为true,优先短时初始等待并快速返回控制权
- 返回包含会话ID、日志路径、行数、字节数、状态、后台模式和截断预览的状态卡片
- 如果命令仍在运行,后续使用longcontextshell_peek而非重新运行命令
longcontextshell_peek
读取现有会话或日志文件的最新状态。
输入参数
- - sessionId(字符串,可选):之前返回的会话ID
- logPath(字符串,可选):日志文件的直接路径(当会话ID不可用时)
- headLines(数字,可选):从开头显示的行数
- tailLines(数字,可选):从末尾显示的行数
- timeQuery(字符串,可选):用于过滤行的时间戳片段,例如2026-03-24T10:15
行为
- 1. 解析会话或日志文件
- 检测进程是否仍在运行或已退出
- 返回包含截断预览的紧凑状态卡片
- 如果提供了timeQuery,返回该时间戳片段的匹配行
longcontextshell_scan
扫描大型日志以查找可能的故障,而非手动读取完整文件。
输入参数
- - sessionId(字符串,可选):之前返回的会话ID
- logPath(字符串,可选):日志文件的直接路径
- patterns(字符串数组,可选):自定义匹配模式
- contextLines(数字,可选):每个匹配项周围包含的上下文行数
- limit(数字,可选):返回的最大匹配数量
行为
- 1. 搜索日志中的强故障信号,如error、exception、failed、fatal和timeout
- 按严重程度对匹配项排序,使可能的根因行出现在通用警告之前
- 返回最强匹配项及其行号、严重程度和简短上下文
- 当输出较大时,优先使用此工具而非手动完整日志检查
longcontextshell_stop
当不再需要监控时停止正在运行的会话。
输入参数
- - sessionId(字符串,必填):要停止的会话
推荐工作流程
- 1. 对于长时间或持续运行的命令,使用longcontextshellrun
- 如果状态为running,使用longcontextshellpeek监控进度
- 如果状态为failed或预览过短无法解释问题,使用longcontextshell_scan
- 仅在扫描后仍存在重要歧义时,才手动读取完整日志
调试技巧
- - 从较小的waitMs开始,在增加复杂度前检查第一个状态卡片
- 如果命令预期持续运行,设置background: true并通过重复调用longcontextshellpeek观察
- 使用timeQuery配合startedAt时间戳前缀,聚焦可疑时间片段,无需读取整个日志
- 如果preview被截断,将logPath视为真实来源,在打开完整文件前使用scan
- 如果scan遗漏了实际问题,使用匹配您正在调试的工具链、框架或服务的自定义patterns重试
- 当Shell引号变得棘手时,先在终端中直接验证原始命令,然后将确切的命令字符串移入longcontextshellrun
- 在跨Shell调试行为时,优先使用简短的自包含复现命令,如node -e或小型脚本文件
- 记住Shell语法在Unix和Windows上可能不同,因此使用管道、重定向或引号的命令可能需要平台特定的形式
- 对于持续命令,始终以longcontextshell_stop结束调试循环,以免旧会话在后台持续运行
- 要查看人类可读的端到端场景,运行node manual-flow-test.js并检查打印的状态卡片和扫描输出
安全
- - 未经用户明确批准,不要运行破坏性命令
- 在使用删除文件、格式化磁盘、重启机器或提升权限的命令前,先询问
- 当输出较大时,优先使用longcontextshellscan而非手动完整日志审查
- 当不再需要持续命令时,使用longcontextshellstop,特别是对于tail -f、watch或类似的监控会话
示例
- long
contextshell_run({ command: npm run build, waitMs: 1500 })
- long
contextshell_run({ command: tail -f app.log, background: true, waitMs: 500 })
- long
contextshell_peek({ sessionId: ... })
- long
contextshell_peek({ sessionId: ..., timeQuery: 2026-03-24T10:15 })
- long
contextshell_scan({ sessionId: ... })
- node manual-flow-test.js