初始提交:terminalX 可运行态(M0/M1/M1.5 已真机验证)

- M0: libghostty SSH 终端(渲染/输入/连接)+ 白屏修复(OutputGate) + 会话状态机/自动重连
- M1: tsnet 用户态组网 + SSH-over-tsnet(fd 桥),shell 级真机验证;R5(Go+gvisor+C+++Swift 同进程) retire
- M1.5: tmux -CC 原生 tab(MVP)
- 结构: packages/(TXCore·TXTransport), apps/TerminalX, vendor/(libghostty-spm/libssh2/mbedtls/tsnet-bridge), artifacts/
- 文档: CLAUDE.md + docs/HANDOFF.md(新会话入口)
- 环境: 认证代理→依赖 vendor 本地化;Go 在 ~/.local/go;仅模拟器/未签名
- 待续: M2 mosh, tmux 多 pane, M4 安全(host key/SE)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
kid
2026-07-24 10:20:46 +08:00
commit aa92d0e676
2761 changed files with 803505 additions and 0 deletions

View File

@@ -0,0 +1,70 @@
//
// TerminalViewState+Delegate.swift
// libghostty-spm
//
// Created by Lakr233 on 2026/3/16.
//
import Foundation
import GhosttyKit
extension TerminalViewState:
TerminalSurfaceTitleDelegate,
TerminalSurfaceGridResizeDelegate,
TerminalSurfaceFocusDelegate,
TerminalSurfaceCloseDelegate,
TerminalSurfaceBellDelegate,
TerminalSurfaceDesktopNotificationDelegate,
TerminalSurfacePwdDelegate,
TerminalSurfaceScrollbarDelegate,
TerminalSurfaceCommandFinishedDelegate,
TerminalSurfaceLifecycleDelegate
{
public func terminalDidChangeTitle(_ title: String) {
self.title = title
}
public func terminalDidResize(_ size: TerminalGridMetrics) {
surfaceSize = size
}
public func terminalDidChangeFocus(_ focused: Bool) {
isFocused = focused
}
public func terminalDidClose(processAlive: Bool) {
onClose?(processAlive)
}
public func terminalDidRingBell() {
bellCount += 1
lastBellAt = Date()
}
public func terminalDidRequestDesktopNotification(title: String, body: String) {
lastDesktopNotificationTitle = title
lastDesktopNotificationBody = body
lastDesktopNotificationAt = Date()
}
public func terminalDidChangeWorkingDirectory(_ path: String) {
workingDirectory = path
}
public func terminalDidUpdateScrollbar(_ scrollbar: TerminalScrollbar) {
self.scrollbar = scrollbar
}
public func terminalDidFinishCommand(exitCode: Int?, durationNanos: UInt64) {
lastCommandExitCode = exitCode
lastCommandDurationNanos = durationNanos
}
public func terminalDidAttachSurface(_ surface: TerminalSurface) {
self.surface = surface
}
public func terminalDidDetachSurface() {
surface = nil
}
}

View File

@@ -0,0 +1,37 @@
//
// TerminalViewState+Mutation.swift
// libghostty-spm
//
// Created by Lakr233 on 2026/3/17.
//
import SwiftUI
public extension TerminalViewState {
func adopt(colorScheme: ColorScheme) {
adopt(terminalColorScheme: TerminalColorScheme(colorScheme))
}
func adopt(terminalColorScheme colorScheme: TerminalColorScheme) {
guard colorScheme != controller.effectiveColorScheme else { return }
controller.setColorScheme(colorScheme) {
self.objectWillChange.send()
}
}
@discardableResult
func setTheme(_ theme: TerminalTheme) -> Bool {
return controller.setTheme(theme) {
self.objectWillChange.send()
}
}
@discardableResult
func setTerminalConfiguration(
_ terminalConfiguration: TerminalConfiguration
) -> Bool {
return controller.setTerminalConfiguration(terminalConfiguration) {
self.objectWillChange.send()
}
}
}

View File

@@ -0,0 +1,115 @@
//
// TerminalViewState.swift
// libghostty-spm
//
// Created by Lakr233 on 2026/3/16.
//
import Foundation
import SwiftUI
@MainActor
public final class TerminalViewState: ObservableObject {
@Published public internal(set) var title: String = ""
@Published public internal(set) var surfaceSize: TerminalGridMetrics?
@Published public internal(set) var isFocused: Bool = false
@Published public internal(set) var bellCount: Int = 0
@Published public internal(set) var lastBellAt: Date?
@Published public internal(set) var lastDesktopNotificationTitle: String?
@Published public internal(set) var lastDesktopNotificationBody: String?
@Published public internal(set) var lastDesktopNotificationAt: Date?
@Published public internal(set) var workingDirectory: String?
@Published public internal(set) var lastCommandExitCode: Int?
@Published public internal(set) var lastCommandDurationNanos: UInt64?
/// Latest scrollbar geometry reported by the terminal (nil until the first
/// update). Drives a host-drawn scrollbar.
@Published public internal(set) var scrollbar: TerminalScrollbar?
public internal(set) weak var surface: TerminalSurface?
@Published public var configuration: TerminalSurfaceOptions = .init()
public var onClose: ((Bool) -> Void)?
@Published public internal(set) var controller: TerminalController
/// Sends text to the attached surface.
@discardableResult
public func send(_ text: String) -> Bool {
guard let surface else {
TerminalDebugLog.log(.input, "view state send ignored: missing surface")
return false
}
return surface.sendText(text)
}
/// Invoke a named Ghostty binding action on the attached surface.
@discardableResult
public func performBindingAction(_ action: String) -> Bool {
surface?.performBindingAction(action) ?? false
}
/// Jump the viewport by a number of shell prompts.
///
/// Negative offsets move toward older prompts and positive offsets move
/// toward newer prompts. Prompt navigation requires shell integration.
@discardableResult
public func jumpToPrompt(by offset: Int16) -> Bool {
surface?.jumpToPrompt(by: offset) ?? false
}
/// Reveal an absolute scrollback row, where zero is the first row.
@discardableResult
public func scrollToRow(_ row: UInt) -> Bool {
surface?.scrollToRow(row) ?? false
}
public convenience init() {
self.init(configSource: .none)
}
public convenience init(configFilePath: String?) {
if let configFilePath {
self.init(configSource: .file(configFilePath))
} else {
self.init(configSource: .none)
}
}
public init(
configSource: TerminalController.ConfigSource = .none,
theme: TerminalTheme = .default,
terminalConfiguration: TerminalConfiguration = .init()
) {
controller = TerminalController(
configSource: configSource,
theme: theme,
terminalConfiguration: terminalConfiguration
)
}
public init(controller: TerminalController) {
self.controller = controller
}
// MARK: - Forwarded from Controller (single source of truth)
public var renderedConfig: String {
controller.renderedConfig
}
public var effectiveColorScheme: TerminalColorScheme {
controller.effectiveColorScheme
}
public var theme: TerminalTheme {
controller.theme
}
public var terminalConfiguration: TerminalConfiguration {
controller.terminalConfiguration
}
}