cmux-socket-policy

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

cmux Socket Policy

cmux Socket 策略

Threading policy

线程策略

  • Do not use
    DispatchQueue.main.sync
    for high-frequency socket telemetry commands such as
    report_*
    ,
    ports_kick
    , status/progress updates, or log metadata updates.
  • For telemetry hot paths, parse and validate arguments off-main.
  • Dedupe and coalesce off-main first.
  • Schedule minimal UI/model mutation with
    DispatchQueue.main.async
    only when needed.
  • Commands that directly manipulate AppKit/Ghostty UI state are allowed to run on the main actor.
  • If adding a new socket command, default to off-main handling and require an explicit reason in code comments when main-thread execution is necessary.
  • 对于高频socket遥测命令(如
    report_*
    ports_kick
    、状态/进度更新或日志元数据更新),请勿使用
    DispatchQueue.main.sync
  • 针对遥测热路径,在主线程外解析并验证参数。
  • 先在主线程外完成去重与合并操作。
  • 仅在必要时,通过
    DispatchQueue.main.async
    安排最少的UI/模型变更。
  • 直接操作AppKit/Ghostty UI状态的命令允许在主线程执行。
  • 若添加新的socket命令,默认采用主线程外处理方式;若必须在主线程执行,需在代码注释中明确说明原因。

Focus policy

焦点策略

  • Socket/CLI commands must not steal macOS app focus.
  • Do not activate the app or raise windows unless the command has explicit focus intent.
  • Only explicit focus-intent commands may mutate in-app focus/selection.
  • Explicit focus-intent commands include
    window.focus
    ,
    workspace.select/next/previous/last
    ,
    surface.focus
    ,
    pane.focus/last
    , browser focus commands, and v1 focus equivalents.
  • All non-focus commands should preserve the current user focus context while still applying data/model changes.
  • Socket/CLI命令不得窃取macOS应用焦点。
  • 除非命令明确包含焦点意图,否则请勿激活应用或唤起窗口。
  • 只有明确包含焦点意图的命令才可修改应用内的焦点/选择状态。
  • 明确包含焦点意图的命令包括
    window.focus
    workspace.select/next/previous/last
    surface.focus
    pane.focus/last
    、浏览器焦点命令以及v1版本的等效焦点命令。
  • 所有非焦点命令在应用数据/模型变更的同时,应保留当前用户的焦点上下文。

Detailed reference

详细参考

  • Read references/threading-and-focus.md when adding a command, changing command execution context, or deciding whether focus changes are allowed.
  • 在添加命令、修改命令执行上下文或判断是否允许变更焦点时,请阅读references/threading-and-focus.md