engine

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 3, 2026 License: Apache-2.0 Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package engine 托管伪终端(PTY)会话:开 shell、持有会话表、维护回放缓冲、 向多个订阅者广播输出、按进程组终止。

职责:

  • 会话的完整生命周期:创建、写入、订阅、调尺寸、显式关闭、自然退出
  • 每会话一个环形缓冲,支撑断线重连的 since 续传
  • 多方接入时的尺寸协商(取所有订阅者中的最小值)

边界:

  • 不认识 HTTP / WebSocket / JSON,也不认识 agentd 的任务模型
  • 不做鉴权,不做 base_path 白名单校验(那是 agentd 接口层的参数校验)
  • 不落盘:会话表只在内存里,随 agentd 生死(spec §3.1、§10)
  • 不解析终端转义序列,只搬字节

PTY 的 unix 平台原语:开伪终端、起 login shell、调尺寸、按进程组终止。

职责:

  • 把 openpty 与进程组信号这两件平台相关的事收敛在本文件
  • 向上只暴露与 platform_other.go 完全同签名的五个函数

边界:

  • 不认识会话、缓冲、订阅者——那是 ptyhost.go 的事
  • 不做参数校验(shell 是否存在等),失败原样上抛

日志:本文件不打日志。所有错误原样上抛,由 ptyhost.go 带着会话 id 统一记录, 避免同一个失败在两层各留一条无法关联的记录。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine 是一个进程内 PTY 引擎的会话持有者。零值不可用,请用 New。

func New

func New(log *slog.Logger) *Engine

New 创建一个 Engine。参数 log 用于记录会话生命周期与错误,不得为 nil。

func (*Engine) Attach

func (h *Engine) Attach(id string, since uint64) (*ptyhost.Attachment, error)

Attach 订阅一个会话,并原子地取回 since 之后的历史。

「原子」是关键:回放与订阅必须在同一把锁里完成,否则两者之间产生的输出 会两头都不落,用户看到的历史就缺了一段。

func (*Engine) Close

func (h *Engine) Close(id string) error

Close 显式关闭会话:整组 SIGTERM,宽限 termGrace 后 SIGKILL,并等待已有 reap。

会话表仍在发信号前摘除,保持 List/第二次 Close 的同步语义;但函数返回前必须 观察 exitedDone,确保 shell 的 EXIT trap、exit code、订阅关闭和 PTY 文件关闭已经完成。

func (*Engine) Get

func (h *Engine) Get(id string) (ptyhost.Session, bool)

Get 取单个会话快照。第二个返回值 false = 不存在。

func (*Engine) List

func (h *Engine) List() []ptyhost.Session

List 返回全部会话快照(含已退出但未被显式关闭的)。

func (*Engine) Open

func (h *Engine) Open(opt ptyhost.OpenOptions) (ptyhost.Session, error)

Open 起一个新会话。失败时不留残骸。

func (*Engine) Supported

func (h *Engine) Supported() bool

Supported 报告引擎所在编译目标是否支持 PTY。

func (*Engine) Write

func (h *Engine) Write(id string, p []byte) error

Write 把用户按键送进 PTY。会话已退出时返回 ErrSessionExited。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL