Skip to content
Closed
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
ffb6d1d
test: reproduce Claude NODE_OPTIONS tmpdir purge
austinywang Sep 6, 2026
8440946
fix: keep Claude NODE_OPTIONS restore shim durable
austinywang Sep 6, 2026
6f41dfd
Merge remote-tracking branch 'origin/main' into issue-12022-wrapper-s…
austinywang Sep 6, 2026
b079d3e
chore: normalize CLI source wiring
austinywang Sep 6, 2026
1d7a358
test: clean up Claude wrapper regression harness
austinywang Sep 6, 2026
d692992
fix: restore legacy Claude preload paths
austinywang Sep 6, 2026
5a06975
test: cover legacy Claude preload migration
austinywang Sep 6, 2026
e5ec22e
fix: preserve quoted Claude node options
austinywang Sep 6, 2026
41a82ff
fix: localize Claude node options error
austinywang Sep 6, 2026
989359a
Merge remote-tracking branch 'origin/main' into issue-12022-wrapper-s…
austinywang Sep 6, 2026
a70322a
fix: place Claude error localization in catalog
austinywang Sep 6, 2026
a0bc896
fix: restore main build compatibility
austinywang Sep 6, 2026
1c7bdeb
Merge remote-tracking branch 'origin/main' into issue-12022-wrapper-s…
austinywang Sep 6, 2026
b909c31
fix(cloud): restore catalog rename compatibility APIs
austinywang Sep 6, 2026
8635e54
fix: clear current main warning budget
austinywang Sep 6, 2026
5af2d06
fix: correct browser payload mutability
austinywang Sep 6, 2026
89959e7
Merge branch 'main' into issue-12022-wrapper-shim-tmpdir
austinywang Sep 6, 2026
b83b585
Merge branch 'main' into issue-12022-wrapper-shim-tmpdir
austinywang Sep 7, 2026
348021c
Merge branch 'main' into issue-12022-wrapper-shim-tmpdir
austinywang Sep 8, 2026
5017b6e
Merge branch 'main' into issue-12022-wrapper-shim-tmpdir
austinywang Sep 8, 2026
8e73509
Merge branch 'main' into issue-12022-wrapper-shim-tmpdir
austinywang Sep 8, 2026
1aaabcc
fix: wire local tmux helpers into app-host tests
austinywang Sep 8, 2026
9f204cc
Merge remote-tracking branch 'origin/main' into issue-12022-wrapper-s…
austinywang Sep 8, 2026
6060750
fix: filter duplicate Claude restore preloads
austinywang Sep 8, 2026
1afa1ee
fix: remove duplicate cli definitions after main extraction
austinywang Sep 8, 2026
72f4796
Merge remote-tracking branch 'origin/main' into issue-12022-wrapper-s…
austinywang Sep 8, 2026
6c50790
fix: restore semantic hook delivery after merge
austinywang Sep 8, 2026
2a1dc98
fix: expose shared CLI helpers across files
austinywang Sep 8, 2026
dde447a
fix: wire Claude node options into CLI target
austinywang Sep 8, 2026
9902ade
fix: remove duplicate Claude node option helpers
austinywang Sep 8, 2026
d0fe0f7
fix: wire cloud rename compatibility into app target
austinywang Sep 8, 2026
d4e26db
fix: preserve unset NODE_OPTIONS during legacy migration
austinywang Sep 8, 2026
250a4b2
Merge remote-tracking branch 'origin/main' into issue-12022-wrapper-s…
austinywang Sep 8, 2026
12737f0
chore: remove obsolete Swift warning budget entries
austinywang Sep 8, 2026
eb47397
chore: normalize Xcode project wiring
austinywang Sep 8, 2026
91271ef
fix: restore semantic hook journal delivery
austinywang Sep 8, 2026
e236673
Merge remote-tracking branch 'origin/main' into issue-12022-wrapper-s…
austinywang Sep 8, 2026
fa993cf
fix: preserve approval clears without request identity
austinywang Sep 8, 2026
40877a2
fix: harden Claude hook fallback paths
austinywang Sep 8, 2026
18e69b3
Merge remote-tracking branch 'origin/main' into issue-12022-wrapper-s…
austinywang Sep 8, 2026
201268e
ci: rerun required checks after hosted runner flakes
austinywang Sep 9, 2026
58e39b8
Merge remote-tracking branch 'origin/main' into issue-12022-wrapper-s…
austinywang Sep 9, 2026
fc9fc6e
ci: grandfather pre-existing determinism findings
austinywang Sep 9, 2026
a6fc232
ci: install Node for semantic integration tests
austinywang Sep 9, 2026
cfb4826
test: pass explicit Node path to Xcode harness
austinywang Sep 9, 2026
e177006
ci: forward Node path to Xcode test runner
austinywang Sep 9, 2026
0c36a75
test: keep OpenCode socket path short on macOS
austinywang Sep 9, 2026
6820f8f
ci: install Node for app-host tests
austinywang Sep 9, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/test-determinism-allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# Format: relpath<TAB>rule<TAB>short reason
# A finding whose (path, rule) appears here is suppressed.
# Remove a line once the underlying test is determinized.
Packages/Shared/CMUXMobileCore/Tests/CMUXMobileCoreTests/CmxRetryAfterPolicyTests.swift sleep-then-assert pre-existing on origin/main in #12179; injected policy sleep, remove when determinism checker recognizes it
Packages/iOS/CmuxMobileShell/Tests/CmuxMobileShellTests/MobileTerminalLaneCoordinatorTests.swift sleep-then-assert pre-existing on origin/main in #12007; remove when determinized
Packages/iOS/CmuxMobileRPC/Tests/CmuxMobileRPCTests/MobileCoreRPCTransportDrainTests.swift sleep-then-assert temporary outage debt owned by #8931; remove when determinized
Packages/iOS/CmuxMobileShellUI/Tests/CmuxMobileShellUITests/OnboardingMacDiscoveryKeepAliveTests.swift sleep-then-assert temporary outage debt owned by #9163; remove when determinized
cmuxTests/WorkspaceForkConversationContextMenuTests.swift assert-on-duration grandfathered
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1389,6 +1389,7 @@ jobs:
CMUX_CLI_BIN="$CLI_BIN" python3 tests/test_cli_socket_autodiscovery.py
python3 tests/test_codex_wrapper_resume_hooks.py
python3 tests/test_claude_wrapper_hooks.py
python3 tests/test_claude_wrapper_node_options_survives_tmpdir_purge.py
python3 tests/test_codex_wrapper_computer_use_mcp.py
python3 tests/test_cmux_cua_mcp_smoke.py
python3 tests/test_cmux_cua_build_cache_safety.py
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/test-depot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ jobs:
set -euo pipefail
./scripts/select-ci-xcode.sh

- name: Setup Node
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: "20"

- name: Export Node path for Xcode test bundles
run: echo "CMUX_NODE_BINARY=$(command -v node)" >> "$GITHUB_ENV"

- name: Setup Bun
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2

Expand Down
366 changes: 366 additions & 0 deletions CLI/CMUXCLI+ClaudeNodeOptions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,366 @@
import Darwin
import Foundation

extension CMUXCLI {
private static let claudeNodeOptionsRestoreModule = """
const hadOriginalNodeOptions = process.env.CMUX_ORIGINAL_NODE_OPTIONS_PRESENT === "1";
if (hadOriginalNodeOptions) {
process.env.NODE_OPTIONS = process.env.CMUX_ORIGINAL_NODE_OPTIONS ?? "";
} else {
delete process.env.NODE_OPTIONS;
}
delete process.env.CMUX_ORIGINAL_NODE_OPTIONS;
delete process.env.CMUX_ORIGINAL_NODE_OPTIONS_PRESENT;
""" + "\n"

private struct ClaudeNodeOptionsCachePathError: LocalizedError {
let reason: String
let path: String

var errorDescription: String? {
String(
localized: "cli.claude.nodeOptionsRestoreError",
defaultValue: "Claude integration could not prepare its runtime environment."
)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}
}

private struct CachePathState {
let owner: uid_t
let isSymbolicLink: Bool
}

private static let unsafeNodeOptionsPathCharacters = CharacterSet(charactersIn: "\\\"'")

private static func nodeOptionsPathIsSafe(_ path: String) -> Bool {
path.hasPrefix("/")
&& path.rangeOfCharacter(from: unsafeNodeOptionsPathCharacters) == nil
}

private static func unquoteNodeOptionsPath(_ path: String) -> String {
guard path.count >= 2,
let first = path.first,
let last = path.last,
(first == "\"" && last == "\"") || (first == "'" && last == "'") else {
return path
}
return String(path.dropFirst().dropLast())
}

private static func nodeOptionsTokens(_ existing: String) -> [String]? {
var tokens: [String] = []
var current = ""
var quote: Character?
var escaped = false
var tokenStarted = false

for character in existing {
if escaped {
current.append(character)
escaped = false
tokenStarted = true
continue
}
if character == "\\" && quote != "'" {
current.append(character)
escaped = true
tokenStarted = true
continue
}
if let activeQuote = quote {
current.append(character)
if character == activeQuote {
quote = nil
}
tokenStarted = true
continue
}
if character == "'" || character == "\"" {
quote = character
current.append(character)
tokenStarted = true
} else if character.isWhitespace {
if tokenStarted {
tokens.append(current)
current = ""
tokenStarted = false
}
} else {
current.append(character)
tokenStarted = true
}
}

guard !escaped, quote == nil else { return nil }
if tokenStarted {
tokens.append(current)
}
return tokens
}

private static func cachePathState(at url: URL) throws -> CachePathState? {
var statValue = stat()
guard lstat(url.path, &statValue) == 0 else {
guard errno == ENOENT else {
throw NSError(
domain: NSPOSIXErrorDomain,
code: Int(errno),
userInfo: [NSFilePathErrorKey: url.path]
)
}
return nil
}
return CachePathState(
owner: statValue.st_uid,
isSymbolicLink: (statValue.st_mode & mode_t(S_IFMT)) == mode_t(S_IFLNK)
)
}

private static func validateCachePath(_ url: URL, expectedOwner: uid_t) throws {
guard let state = try cachePathState(at: url) else { return }
guard !state.isSymbolicLink else {
throw ClaudeNodeOptionsCachePathError(reason: "cache path is a symlink", path: url.path)
}
guard state.owner == expectedOwner else {
throw ClaudeNodeOptionsCachePathError(
reason: "cache path is owned by a different uid",
path: url.path
)
}
}

private static func claudeNodeOptionsRestoreModuleRoot() throws -> URL {
let environment = ProcessInfo.processInfo.environment
guard let home = environment["HOME"], !home.isEmpty else {
throw ClaudeNodeOptionsCachePathError(reason: "HOME is unavailable", path: "")
}
let root = URL(fileURLWithPath: home, isDirectory: true)
.appendingPathComponent(".cmuxterm", isDirectory: true)
.appendingPathComponent("cmux-claude-node-options", isDirectory: true)
guard nodeOptionsPathIsSafe(root.path) else {
throw ClaudeNodeOptionsCachePathError(reason: "path is unsafe for --require", path: root.path)
}
return root
}

private func nodeOptionsRequirePaths(_ existing: String) -> [String] {
guard let tokens = Self.nodeOptionsTokens(existing) else { return [] }
var paths: [String] = []
var index = 0
while index < tokens.count {
let token = tokens[index]
if token == "--require" || token == "-r" {
if index + 1 < tokens.count {
paths.append(Self.unquoteNodeOptionsPath(tokens[index + 1]))
index += 2
continue
}
} else if token.hasPrefix("--require=") {
paths.append(Self.unquoteNodeOptionsPath(String(token.dropFirst("--require=".count))))
} else if token.hasPrefix("-r=") {
paths.append(Self.unquoteNodeOptionsPath(String(token.dropFirst("-r=".count))))
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}
index += 1
}
return paths
}

private func isClaudeNodeOptionsRestorePath(_ path: String) -> Bool {
path.hasSuffix("/cmux-claude-node-options/restore-node-options.cjs")
}

private func recreateLegacyNodeOptionsRestoreModules(excluding currentURL: URL) {
guard let existing = ProcessInfo.processInfo.environment["NODE_OPTIONS"] else { return }
let legacySuffix = "/cmux-claude-node-options/restore-node-options.cjs"
let expectedOwner = getuid()
for path in nodeOptionsRequirePaths(existing) {
guard path.hasSuffix(legacySuffix),
Self.nodeOptionsPathIsSafe(path),
path != currentURL.path else { continue }
let url = URL(fileURLWithPath: path, isDirectory: false)
let directory = url.deletingLastPathComponent()
do {
try Self.validateCachePath(directory, expectedOwner: expectedOwner)
try FileManager.default.createDirectory(
at: directory,
withIntermediateDirectories: true,
attributes: [.posixPermissions: 0o700]
)
try Self.validateCachePath(directory, expectedOwner: expectedOwner)
if try Self.cachePathState(at: url) != nil {
try Self.validateCachePath(url, expectedOwner: expectedOwner)
continue
}
try writeShimIfChanged(Self.claudeNodeOptionsRestoreModule, to: url)
try FileManager.default.setAttributes([.posixPermissions: 0o600], ofItemAtPath: url.path)
try Self.validateCachePath(url, expectedOwner: expectedOwner)
} catch {
continue
}
}
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
}

func createClaudeNodeOptionsRestoreModule() throws -> URL {
let root = try Self.claudeNodeOptionsRestoreModuleRoot()
try Self.validateCachePath(root, expectedOwner: getuid())
try FileManager.default.createDirectory(
at: root,
withIntermediateDirectories: true,
attributes: [.posixPermissions: 0o700]
)
try Self.validateCachePath(root, expectedOwner: getuid())
try FileManager.default.setAttributes([.posixPermissions: 0o700], ofItemAtPath: root.path)

let restoreModuleURL = root.appendingPathComponent("restore-node-options.cjs", isDirectory: false)
try writeShimIfChanged(Self.claudeNodeOptionsRestoreModule, to: restoreModuleURL)
try FileManager.default.setAttributes([.posixPermissions: 0o600], ofItemAtPath: restoreModuleURL.path)
recreateLegacyNodeOptionsRestoreModules(excluding: restoreModuleURL)
return restoreModuleURL
}

func mergedNodeOptions(existing: String?, restoreModulePath: String) -> String {
let escapedPath = restoreModulePath
.replacingOccurrences(of: "\\", with: "\\\\")
.replacingOccurrences(of: "\"", with: "\\\"")
let requireOption = "--require=\"\(escapedPath)\""
let memoryOption = "--max-old-space-size=4096"
let cleanedExisting = cleanedNodeOptions(existing)
guard !cleanedExisting.isEmpty else {
return "\(requireOption) \(memoryOption)"
}
return "\(requireOption) \(memoryOption) \(cleanedExisting)"
}

func configureClaudeNodeOptionsEnvironment(
processEnvironment: [String: String],
restoreModuleURL: URL
) {
switch processEnvironment["CMUX_ORIGINAL_NODE_OPTIONS_PRESENT"] {
case "1":
setenv("CMUX_ORIGINAL_NODE_OPTIONS_PRESENT", "1", 1)
setenv("CMUX_ORIGINAL_NODE_OPTIONS", processEnvironment["CMUX_ORIGINAL_NODE_OPTIONS"] ?? "", 1)
case "0":
setenv("CMUX_ORIGINAL_NODE_OPTIONS_PRESENT", "0", 1)
unsetenv("CMUX_ORIGINAL_NODE_OPTIONS")
default:
if let existing = processEnvironment["NODE_OPTIONS"] {
let normalized = normalizedNodeOptionsForRestore(existing)
if !normalized.isEmpty || !nodeOptionsContainOnlyManagedRestoreModules(existing) {
setenv("CMUX_ORIGINAL_NODE_OPTIONS_PRESENT", "1", 1)
setenv("CMUX_ORIGINAL_NODE_OPTIONS", normalized, 1)
} else {
setenv("CMUX_ORIGINAL_NODE_OPTIONS_PRESENT", "0", 1)
unsetenv("CMUX_ORIGINAL_NODE_OPTIONS")
}
} else {
setenv("CMUX_ORIGINAL_NODE_OPTIONS_PRESENT", "0", 1)
unsetenv("CMUX_ORIGINAL_NODE_OPTIONS")
}
}
Comment thread
austinywang marked this conversation as resolved.
Resolved
setenv(
"NODE_OPTIONS",
mergedNodeOptions(
existing: processEnvironment["NODE_OPTIONS"],
restoreModulePath: restoreModuleURL.path
),
1
)
}

private func cleanedNodeOptions(_ existing: String?) -> String {
guard let tokens = Self.nodeOptionsTokens(existing ?? "") else { return existing ?? "" }
guard !tokens.isEmpty else { return "" }

var filtered: [String] = []
var index = 0
while index < tokens.count {
let token = tokens[index]
if token == "--require" || token == "-r",
index + 1 < tokens.count,
isClaudeNodeOptionsRestorePath(Self.unquoteNodeOptionsPath(tokens[index + 1])) {
index += 2
continue
}
if token.hasPrefix("--require=") || token.hasPrefix("-r=") {
let separator = token.hasPrefix("--require=") ? "--require=" : "-r="
let path = Self.unquoteNodeOptionsPath(String(token.dropFirst(separator.count)))
if isClaudeNodeOptionsRestorePath(path) {
index += 1
continue
}
}
if token == "--max-old-space-size" {
index += min(2, tokens.count - index)
continue
}
if token.hasPrefix("--max-old-space-size=") {
index += 1
continue
}
filtered.append(token)
index += 1
}
return filtered.joined(separator: " ")
}

private func nodeOptionsContainOnlyManagedRestoreModules(_ existing: String) -> Bool {
guard let tokens = Self.nodeOptionsTokens(existing), !tokens.isEmpty else { return false }
var foundRestoreModule = false
var index = 0
while index < tokens.count {
let token = tokens[index]
if token == "--require" || token == "-r" {
guard index + 1 < tokens.count,
isClaudeNodeOptionsRestorePath(Self.unquoteNodeOptionsPath(tokens[index + 1])) else {
return false
}
foundRestoreModule = true
index += 2
continue
}
if token.hasPrefix("--require=") || token.hasPrefix("-r=") {
let separator = token.hasPrefix("--require=") ? "--require=" : "-r="
let path = Self.unquoteNodeOptionsPath(String(token.dropFirst(separator.count)))
guard isClaudeNodeOptionsRestorePath(path) else { return false }
foundRestoreModule = true
index += 1
continue
}
return false
}
return foundRestoreModule
}

func normalizedNodeOptionsForRestore(_ existing: String) -> String {
guard let tokens = Self.nodeOptionsTokens(existing) else { return existing }
guard !tokens.isEmpty else { return "" }

var normalized: [String] = []
var index = 0
while index < tokens.count {
let token = tokens[index]
if token == "--require" || token == "-r",
index + 1 < tokens.count,
isClaudeNodeOptionsRestorePath(Self.unquoteNodeOptionsPath(tokens[index + 1])) {
index += 2
continue
}
if token.hasPrefix("--require=") || token.hasPrefix("-r=") {
let separator = token.hasPrefix("--require=") ? "--require=" : "-r="
let path = Self.unquoteNodeOptionsPath(String(token.dropFirst(separator.count)))
if isClaudeNodeOptionsRestorePath(path) {
index += 1
continue
}
}
if token == "--max-old-space-size", index + 1 < tokens.count {
normalized.append("--max-old-space-size=\(tokens[index + 1])")
index += 2
continue
}
normalized.append(token)
index += 1
}
return normalized.joined(separator: " ")
}
}
Loading
Loading