Skip to content

Commit 985f7a3

Browse files
committed
chore(process-daemon): move opencode-pty into the monorepo
1 parent 3f74f03 commit 985f7a3

58 files changed

Lines changed: 12790 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
name: Process daemon
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- packages/process-daemon/**
7+
- .github/workflows/check-process-daemon.yml
8+
push:
9+
branches: [dev]
10+
paths:
11+
- packages/process-daemon/**
12+
- .github/workflows/check-process-daemon.yml
13+
workflow_dispatch:
14+
15+
permissions:
16+
contents: read
17+
18+
concurrency:
19+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
20+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
21+
22+
defaults:
23+
run:
24+
working-directory: packages/process-daemon
25+
26+
jobs:
27+
miri:
28+
name: Miri (callback ownership)
29+
runs-on: ubuntu-22.04
30+
timeout-minutes: 15
31+
env:
32+
CARGO_TARGET_DIR: target/miri
33+
steps:
34+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
35+
- name: Install Miri
36+
run: rustup toolchain install nightly-2026-09-02 --profile minimal --component miri --component rust-src
37+
- run: cargo +nightly-2026-09-02 miri setup
38+
- name: Check Stacked Borrows
39+
run: |
40+
cargo +nightly-2026-09-02 miri test --locked --manifest-path tests/ghostty-effects/Cargo.toml
41+
cargo +nightly-2026-09-02 miri test --locked --manifest-path tests/transport-retained/Cargo.toml
42+
- name: Check Tree Borrows
43+
env:
44+
MIRIFLAGS: -Zmiri-tree-borrows
45+
run: |
46+
cargo +nightly-2026-09-02 miri test --locked --manifest-path tests/ghostty-effects/Cargo.toml
47+
cargo +nightly-2026-09-02 miri test --locked --manifest-path tests/transport-retained/Cargo.toml
48+
49+
test:
50+
name: Core (${{ matrix.os }})
51+
runs-on: ${{ matrix.os }}
52+
timeout-minutes: 30
53+
strategy:
54+
fail-fast: false
55+
matrix:
56+
os: [ubuntu-22.04, macos-15]
57+
steps:
58+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
59+
- uses: mlugg/setup-zig@8d6198c65fb0feaa111df26e6b467fea8345e46f # v2.0.5
60+
with:
61+
version: 0.16.0
62+
- name: Install Rust
63+
run: rustup toolchain install 1.90.0 --profile minimal --component rustfmt --component clippy
64+
- uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2
65+
with:
66+
key: core-${{ matrix.os }}-zig-0.16.0
67+
workspaces: packages/process-daemon -> target
68+
cache-workspace-crates: true
69+
- run: cargo fmt --check
70+
- run: cargo clippy --locked --all-targets --all-features -- -D warnings
71+
- name: Test Linux
72+
if: runner.os == 'Linux'
73+
run: cargo test --locked
74+
# Match the release workflow's macOS playground exclusion.
75+
- name: Test macOS
76+
if: runner.os == 'macOS'
77+
run: cargo test --locked --lib --test service --test runtime --test ownership --test rows --test ghostty-effects
78+
79+
windows:
80+
name: Windows (${{ matrix.arch }})
81+
runs-on: ${{ matrix.runner }}
82+
timeout-minutes: 30
83+
strategy:
84+
fail-fast: false
85+
matrix:
86+
include:
87+
- arch: x64
88+
runner: windows-2025
89+
target: x86_64-pc-windows-msvc
90+
machine: "8664"
91+
- arch: arm64
92+
runner: windows-11-arm
93+
target: aarch64-pc-windows-msvc
94+
machine: "aa64"
95+
defaults:
96+
run:
97+
shell: pwsh
98+
working-directory: packages/process-daemon
99+
env:
100+
CARGO_TERM_COLOR: always
101+
CARGO_BUILD_TARGET: ${{ matrix.target }}
102+
RUSTUP_TOOLCHAIN: 1.90.0-x86_64-pc-windows-msvc
103+
RUST_BACKTRACE: "1"
104+
steps:
105+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
106+
- name: Enable long dependency paths
107+
run: git config --global core.longpaths true
108+
- uses: mlugg/setup-zig@8d6198c65fb0feaa111df26e6b467fea8345e46f # v2.0.5
109+
if: matrix.arch == 'x64'
110+
with:
111+
version: 0.16.0
112+
cache-key: ${{ matrix.target }}
113+
# Zig 0.16 crashes when building Ghostty on the native ARM64 host.
114+
# Use x64-hosted compilers on this ARM64 runner, but execute ARM64 tests natively.
115+
- name: Install x64 Zig for ARM64 cross-compilation
116+
if: matrix.arch == 'arm64'
117+
run: |
118+
$archive = Join-Path $env:RUNNER_TEMP 'zig-x64.zip'
119+
Invoke-WebRequest 'https://ziglang.org/download/0.16.0/zig-x86_64-windows-0.16.0.zip' -OutFile $archive
120+
if ((Get-FileHash $archive -Algorithm SHA256).Hash -ne '68659eb5f1e4eb1437a722f1dd889c5a322c9954607f5edcf337bc3684a75a7e') { throw 'Zig archive checksum mismatch' }
121+
Expand-Archive $archive -DestinationPath $env:RUNNER_TEMP
122+
Join-Path $env:RUNNER_TEMP 'zig-x86_64-windows-0.16.0' >> $env:GITHUB_PATH
123+
- name: Fix Zig 0.16 ARM64 function-pointer alignment
124+
if: matrix.arch == 'arm64'
125+
run: |
126+
# ARM64 function pointers require 4-byte alignment, unlike *anyopaque.
127+
# Zig 0.16's Windows stack-trace helper omits the required alignment assertion.
128+
$file = Join-Path $env:RUNNER_TEMP 'zig-x86_64-windows-0.16.0/lib/std/debug/SelfInfo/Windows.zig'
129+
$source = [System.IO.File]::ReadAllText($file)
130+
$old = '@ptrCast(try si.loadNtdllProc(@tagName(proc)))'
131+
if (!$source.Contains($old)) { throw 'Zig alignment workaround no longer matches; re-evaluate it' }
132+
[System.IO.File]::WriteAllText($file, $source.Replace($old, '@ptrCast(@alignCast(try si.loadNtdllProc(@tagName(proc))))'))
133+
- name: Install Rust toolchain and target
134+
run: rustup toolchain install $env:RUSTUP_TOOLCHAIN --force-non-host --profile minimal --component rustfmt --component clippy --target $env:CARGO_BUILD_TARGET
135+
- name: Verify runner and compiler architecture
136+
env:
137+
EXPECTED_ARCH: ${{ matrix.arch }}
138+
run: |
139+
$arch = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString()
140+
Write-Output "Windows architecture: $arch"
141+
if ($arch -ine $env:EXPECTED_ARCH) { throw "Expected native $env:EXPECTED_ARCH runner, got $arch" }
142+
$compiler = rustc -vV
143+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
144+
$compiler
145+
if ($compiler -notcontains 'host: x86_64-pc-windows-msvc') { throw 'Unexpected Rust compiler host' }
146+
Write-Output "Executable target: $env:CARGO_BUILD_TARGET"
147+
zig version
148+
# No cache-on-failure: a timed-out run once saved a partial cache that broke re-runs.
149+
- uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2
150+
with:
151+
key: windows-${{ matrix.target }}-zig-0.16.0
152+
workspaces: packages/process-daemon -> target
153+
# The native Ghostty build is now an output of the workspace crate.
154+
cache-workspace-crates: true
155+
- name: Check formatting
156+
run: cargo fmt --check
157+
- name: Check Clippy
158+
run: cargo clippy --locked --all-targets --all-features -- -D warnings
159+
- name: Build executable
160+
id: build
161+
run: cargo build --locked
162+
- name: Run tests
163+
id: tests
164+
timeout-minutes: 10
165+
run: cargo test --locked --all-targets --all-features
166+
- name: Run standalone library tests
167+
env:
168+
EXPECTED_MACHINE: ${{ matrix.machine }}
169+
run: |
170+
$artifacts = cargo test --locked --lib --no-run --message-format=json | ForEach-Object { $_ | ConvertFrom-Json }
171+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
172+
$binary = ($artifacts | Where-Object { $_.reason -eq 'compiler-artifact' -and $_.profile.test -and $_.executable }).executable
173+
# Cargo adds native library paths to PATH, which can hide accidental DLL dependencies.
174+
# Copy only the executable so neither Cargo nor adjacent build artifacts can supply them.
175+
$directory = Join-Path $env:RUNNER_TEMP 'pty-standalone-tests'
176+
New-Item -ItemType Directory -Force $directory | Out-Null
177+
$standalone = Join-Path $directory 'opencode-pty-tests.exe'
178+
Copy-Item $binary $standalone
179+
$bytes = [System.IO.File]::ReadAllBytes($standalone)
180+
$header = [BitConverter]::ToInt32($bytes, 0x3c)
181+
$machine = [BitConverter]::ToUInt16($bytes, $header + 4)
182+
if ($machine -ne [Convert]::ToUInt16($env:EXPECTED_MACHINE, 16)) { throw 'Test executable architecture does not match the runner' }
183+
& $standalone
184+
- name: Diagnose failed library tests
185+
if: failure() && steps.tests.outcome == 'failure'
186+
timeout-minutes: 10
187+
run: cargo test --locked --lib --all-features -- --test-threads=1 --nocapture
188+
- name: Diagnose failed runtime tests
189+
if: failure() && steps.tests.outcome == 'failure'
190+
timeout-minutes: 3
191+
run: cargo test --locked --test runtime -- --test-threads=1 --nocapture
192+
- name: Diagnose failed daemon tests
193+
if: failure() && steps.tests.outcome == 'failure'
194+
timeout-minutes: 3
195+
run: cargo test --locked --test windows-daemon -- --test-threads=1 --nocapture
196+
- name: Smoke test executable
197+
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
198+
run: |
199+
$metadata = cargo metadata --locked --no-deps --format-version 1 | ConvertFrom-Json
200+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
201+
$version = ($metadata.packages | Where-Object name -eq 'opencode-pty').version
202+
$binary = Join-Path $metadata.target_directory "$env:CARGO_BUILD_TARGET/debug/opencode-pty.exe"
203+
$output = & $binary --version
204+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
205+
Write-Output $output
206+
if ($output -ne "opencode-pty $version (protocol 7)") { throw "Unexpected executable version: $output" }
207+
- name: Document current coverage
208+
if: always()
209+
run: |
210+
@"
211+
## Windows ${{ matrix.arch }}
212+
213+
Target: $env:CARGO_BUILD_TARGET
214+
215+
This job builds the executable and runs all enabled tests natively, including libghostty parser, protocol, direct TerminalService ConPTY runtime, named-pipe transport, and daemon tests.
216+
The runtime suite spawns real Rust console children and checks input/output, Unicode, cwd/environment/argv/PATH, OS resize, snapshots, replay, terminal replies, and independent terminals.
217+
Daemon tests cover private atomic registration, ownership/handoff, stale registration/locking, partial requests, blocked subscribers, and live ConPTY operations over real named pipes.
218+
The older service, ownership, playground, and rows integration suites remain Unix-only.
219+
Basic tests do not establish exhaustive lifecycle coverage or Windows interactive CLI parity.
220+
No packages or releases are published.
221+
"@ >> $env:GITHUB_STEP_SUMMARY

‎packages/process-daemon/.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/target
2+
/tests/*/target

‎packages/process-daemon/AGENTS.md‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# opencode-pty
2+
3+
## Objective
4+
5+
Build a persistent Rust PTY service. The service owns multiple terminal child
6+
processes, continuously drains output, parses it with libghostty-vt, retains a
7+
bounded raw replay tail, and exposes thread-safe terminal operations.
8+
9+
## Current Scope
10+
11+
- Use portable-pty directly.
12+
- Give each terminal blocking reader, actor/parser, writer, and child-wait
13+
threads.
14+
- Keep libghostty-vt on the actor thread that creates it.
15+
- Bound raw output, input, and actor queues.
16+
- Make libghostty authoritative for terminal-generated PTY responses.
17+
- Provide an interactive local CLI for exercising multiple terminals.
18+
- Do not add OpenCode IPC integration yet.
19+
- Do not implement descriptor passing or live service replacement.
20+
21+
## Engineering Rules
22+
23+
- Never block the service control path on PTY I/O.
24+
- Never perform a blocking write from a libghostty callback.
25+
- Keep exactly one PTY reader and one PTY writer per terminal.
26+
- Preserve child-exit and PTY-EOF as distinct lifecycle signals.
27+
- Treat PID as metadata, never terminal identity.
28+
- Bound by bytes, not only message count.
29+
- Do not expose borrowed libghostty values outside the actor thread.
30+
- Keep terminal shutdown idempotent and join all worker threads.
31+
32+
## Verification
33+
34+
```sh
35+
cargo fmt --check
36+
cargo clippy --all-targets --all-features -- -D warnings
37+
cargo test
38+
cargo run -- play
39+
```

0 commit comments

Comments
 (0)