Skip to content

feat: add terminal settings support for create_session API #540

@xdlkc

Description

@xdlkc

Feature Category

  • Sandbox
  • Actions
  • Deployments
  • SDK & API
  • Envhub
  • CLI
  • Performance & Optimization
  • Documentation & Examples

Problem Statement
create_session API 缺乏终端配置能力,导致依赖终端的程序无法正常工作

Proposed Solution
CreateBashSessionRequest 添加终端参数

Detailed Feature Description

  1. 目标

create_session API 添加终端信息配置能力,允许用户在创建 bash session 时设置终端类型、尺寸、字符编码等参数。

  1. 参数规格
参数 类型 默认值 说明
term str "xterm-256color" 终端类型 (TERM 环境变量)
columns int 80 终端宽度(列数),必须 >= 1
lines int 24 终端高度(行数),必须 >= 1
lang str "en_US.UTF-8" 字符编码 (LANG 环境变量)
  1. 环境变量映射
参数 环境变量
term TERM
columns COLUMNS
lines LINES
lang LANG
  1. 参数优先级
优先级 来源
1 (最高) env 参数中的同名变量
2 专用终端参数 (term, columns, lines, lang)
3 如果 env_enable=True,继承宿主机环境变量
4 (最低) 参数默认值
  1. pexpect 配置

同时设置 pexpect 的 dimensions 参数,确保 stty size 命令返回正确值:

pexpect.spawn(
    command,
    dimensions=(lines, columns),  # (rows, cols)
    ...
)
  1. 实现位置
文件 修改内容
rock/actions/sandbox/request.py 添加终端参数到 CreateBashSessionRequest
rock/rocklet/local_sandbox.py BashSession.start() 设置环境变量和 dimensions
  1. 测试用例
测试 描述
test_default_terminal_settings 验证默认值 TERM=xterm-256color, LANG=en_US.UTF-8
test_custom_terminal_settings 验证自定义值
test_terminal_size_stty 验证 stty size 输出正确
test_env_overrides_terminal_params 验证 env 参数优先级
  1. 向后兼容

所有新参数都有默认值,现有代码无需修改即可正常工作。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions