Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
8f91d6b
Add failing regression tests for layout capture of cmux-injected code…
austinywang Jul 8, 2026
160bb0c
Sanitize captured agent commands via shared sanitizer; fail loudly on…
austinywang Jul 8, 2026
9e079ee
Strip only cmux's own codex hook flags; gate node/bun unwrap on node_…
austinywang Jul 8, 2026
0398d3c
Gate node/bun agent unwrap on cmux wrapper-injected hook markers
austinywang Jul 8, 2026
e9573a9
Derive unwrap agent name from cmux marker for package entrypoints lik…
austinywang Jul 8, 2026
266668c
Move file-local codex launch helpers to file scope
austinywang Jul 8, 2026
a920f3f
Require the marker agent's package path for basename-less unwrap fall…
austinywang Jul 8, 2026
8de4c82
Replay marker-bearing native agent launches through the bare name
austinywang Jul 8, 2026
ce1da96
Fix save-dialog disclosure text views rendering blank
austinywang Jul 8, 2026
f25045b
Split save-dialog accessory regression test into its own wired test file
austinywang Jul 8, 2026
7d6ca65
Normalize project.pbxproj
austinywang Jul 8, 2026
d815bca
Merge origin/main into save layout commands
austinywang Jul 8, 2026
0bdb341
Fix save layout review findings
austinywang Jul 8, 2026
f354c9d
Tighten save layout wrapper proof
austinywang Jul 8, 2026
1138177
Merge remote-tracking branch 'origin/main' into issue-7631-save-layou…
austinywang Jul 8, 2026
6b4cce1
Add Claude session wrapper regression coverage
austinywang Jul 8, 2026
8aaea83
Recognize Claude wrapper session marker
austinywang Jul 8, 2026
7a84a1b
Use instance unwrapper for runtime agent argv
austinywang Jul 8, 2026
1699b18
Add Claude wrapper identity regression coverage
austinywang Jul 8, 2026
ad693db
Require structured Claude wrapper marker
austinywang Jul 8, 2026
5c7035b
Update Claude wrapper app test fixture
austinywang Jul 8, 2026
3de96e6
Route marker-backed Codex replays through wrapper
austinywang Jul 8, 2026
22759b2
Split JavaScript runtime launch unwrapper
austinywang Jul 8, 2026
54ccbc7
Trim action saver test file under guard budget
austinywang Jul 8, 2026
4346df8
Preserve explicit Codex executable with hook config
austinywang Jul 8, 2026
a0bfeb5
Sanitize node-hosted Codex resume captures
austinywang Jul 8, 2026
956edff
Preserve hook config for captured agent paths
austinywang Jul 8, 2026
1baeb11
Move Claude launch preservation out of sanitizer namespace
austinywang Jul 9, 2026
a7fa722
Strip cmux hook payloads from saved layout commands
austinywang Jul 9, 2026
a9eef49
Route stripped saved-layout agents through wrappers
austinywang Jul 9, 2026
3288aca
Preserve captured agent executables for saved layouts
austinywang Jul 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
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public enum AgentLaunchSanitizer {
return result
}

var tail = args; var preservePositionals = false
var tail = removingCmuxInjectedCodexHookArguments(args); var preservePositionals = false
if let forkCommand = codexForkCommand(in: tail) {
tail = dropForkPositionals(tail, forkCommand: forkCommand); preservePositionals = preservePromptTags
}
Expand All @@ -135,7 +135,7 @@ public enum AgentLaunchSanitizer {
case "claude":
return preserveOptions(args, policy: claudePolicy)
case "codex":
return preserveOptions(args, policy: codexPolicy)
return preserveOptions(removingCmuxInjectedCodexHookArguments(args), policy: codexPolicy)
case "codex-fork-replay": return preserveCodexFork(true)
case "codex-fork-restore": return preserveCodexFork(false)
case "grok":
Expand Down Expand Up @@ -295,86 +295,7 @@ public enum AgentLaunchSanitizer {
return result
}

private static func preservedCodexLaunchArguments(args: [String]) -> [String]? {
if let forkCommand = codexForkCommand(in: args) {
return CodexForkLaunchCapture(args: args, forkIndex: forkCommand.forkIndex, sessionIndex: forkCommand.sessionIndex, preserveOptions: preserveOptions)
.arguments()
}
return preservedArguments(kind: "codex", args: args)
}

private struct CodexForkCommand {
let forkIndex: Int
let sessionIndex: Int
}

private static func codexForkCommand(in args: [String]) -> CodexForkCommand? {
var index = 0
while index < args.count {
let arg = args[index]
if arg == "--" {
return nil
}
if !isOptionToken(arg) || arg == "-" {
guard arg == "fork",
let sessionIndex = codexForkCommandSessionIndex(args, forkIndex: index) else {
return nil
}
return CodexForkCommand(forkIndex: index, sessionIndex: sessionIndex)
}
let width = optionWidth(args, index: index, policy: codexPolicy)
if codexPolicy.variadicOptions.contains(arg) {
let end = min(args.count, index + width)
if index + 2 < end {
for candidateIndex in (index + 2)..<end where args[candidateIndex] == "fork" {
if let sessionIndex = codexForkCommandSessionIndex(args, forkIndex: candidateIndex) {
return CodexForkCommand(forkIndex: candidateIndex, sessionIndex: sessionIndex)
}
}
}
}
index += width
}
return nil
}

private static func codexForkCommandSessionIndex(_ args: [String], forkIndex: Int) -> Int? {
var index = forkIndex + 1
while index < args.count {
let argument = args[index]
if argument == "--" {
return nil
}
if !argument.hasPrefix("-") || argument == "-" {
return looksLikeCodexSessionIdentifier(argument) ? index : nil
}
let width = optionWidth(args, index: index, policy: codexPolicy)
if codexPolicy.variadicOptions.contains(argument) {
let end = min(args.count, index + width)
if index + 2 < end {
for candidateIndex in (index + 2)..<end {
if looksLikeCodexSessionIdentifier(args[candidateIndex]) {
return candidateIndex
}
}
}
}
index += width
}
return nil
}

private static func looksLikeCodexSessionIdentifier(_ value: String) -> Bool {
let trimmed = value.trimmingCharacters(in: .whitespacesAndNewlines)
guard trimmed.count >= 20 else { return false }
if trimmed.hasPrefix("019") {
return true
}
let allowed = CharacterSet(charactersIn: "0123456789abcdefABCDEF-")
return trimmed.unicodeScalars.allSatisfy { allowed.contains($0) } && trimmed.contains("-")
}

private static func preserveOptions(_ args: [String], policy: Policy) -> [String]? {
static func preserveOptions(_ args: [String], policy: Policy) -> [String]? {
var result: [String] = []
var index = 0
var consumedFirstPositional = false
Expand Down Expand Up @@ -470,7 +391,7 @@ public enum AgentLaunchSanitizer {
return runtimeOnlyOptionWidths[String(arg[..<equals])].map { _ in 1 }
}

private static func optionWidth(
static func optionWidth(
_ args: [String],
index: Int,
policy: Policy,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
import Foundation

extension AgentLaunchSanitizer {
static func preservedCodexLaunchArguments(args: [String]) -> [String]? {
let args = removingCmuxInjectedCodexHookArguments(args)
if let forkCommand = codexForkCommand(in: args) {
return CodexForkLaunchCapture(
args: args,
forkIndex: forkCommand.forkIndex,
sessionIndex: forkCommand.sessionIndex,
preserveOptions: preserveOptions
).arguments()
}
return preservedArguments(kind: "codex", args: args)
}

static func removingCmuxInjectedCodexHookArguments(_ args: [String]) -> [String] {
guard containsCmuxInjectedCodexHookConfig(args) else { return args }
var result: [String] = []
var index = 0
while index < args.count {
let arg = args[index]
if isCmuxInjectedCodexHookConfigOption(arg) {
index += 1
continue
}
if (arg == "-c" || arg == "--config"),
index + 1 < args.count,
isCmuxInjectedCodexHookConfigValue(args[index + 1]) {
index += 2
continue
}
if arg == "--enable", index + 1 < args.count, args[index + 1] == "hooks" {
index += 2
continue
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 User Hooks Lose Enable Flag

When a Codex argv contains both cmux-injected hook config and a user-owned hook config, the cmux marker makes this branch remove --enable hooks globally while the user hook config is preserved. The saved command can then replay with -c hooks... but without enabling hooks, so the user's hook no longer runs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 9e079ee: the stripper now removes exactly one instance of --enable hooks and one --dangerously-bypass-hook-trust (the single pair the cmux wrapper splices in alongside its marker configs), so a user's own enable flag and hooks.* config survive and stay enabled on replay. Regression test added: 'Keeps user hook enabling flags when cmux injection is stripped'.

— Claude Code

if arg == "--enable=hooks" || arg == "--dangerously-bypass-hook-trust" {
index += 1
continue
}
result.append(arg)
index += 1
}
return result
}

/// Unwraps a node/bun-hosted known agent to a bare agent executable argv.
///
/// Captured foreground argv may look like `node .../bin/codex <flags>` when
/// cmux launched the agent through a JavaScript runtime wrapper. Returning a
/// bare executable name such as `codex` deliberately routes replay through
/// the per-surface PATH shim and cmux wrapper, so hooks are re-injected fresh
/// instead of persisting the runtime script path.
public static func unwrappedJavaScriptRuntimeAgentArgv(
_ argv: [String],
isKnownAgentExecutableName: (String) -> Bool
) -> [String]? {
guard let executable = argv.first else { return nil }
let runtimeName = (executable as NSString).lastPathComponent.lowercased()
guard runtimeName == "node" || runtimeName == "bun",
let scriptIndex = javaScriptRuntimeScriptArgumentIndex(argv) else {
return nil
}
let scriptName = (argv[scriptIndex] as NSString).lastPathComponent
let matchedName: String
if isKnownAgentExecutableName(scriptName) {
matchedName = scriptName
} else if let strippedName = scriptName.removingSingleJavaScriptExtension(),
isKnownAgentExecutableName(strippedName) {
matchedName = strippedName
} else {
return nil
}
return [matchedName] + Array(argv.dropFirst(scriptIndex + 1))
}

struct CodexForkCommand {
let forkIndex: Int
let sessionIndex: Int
}

static func codexForkCommand(in args: [String]) -> CodexForkCommand? {
var index = 0
while index < args.count {
let arg = args[index]
if arg == "--" {
return nil
}
if !isOptionToken(arg) || arg == "-" {
guard arg == "fork",
let sessionIndex = codexForkCommandSessionIndex(args, forkIndex: index) else {
return nil
}
return CodexForkCommand(forkIndex: index, sessionIndex: sessionIndex)
}
let width = optionWidth(args, index: index, policy: codexPolicy)
if codexPolicy.variadicOptions.contains(arg) {
let end = min(args.count, index + width)
if index + 2 < end {
for candidateIndex in (index + 2)..<end where args[candidateIndex] == "fork" {
if let sessionIndex = codexForkCommandSessionIndex(args, forkIndex: candidateIndex) {
return CodexForkCommand(forkIndex: candidateIndex, sessionIndex: sessionIndex)
}
}
}
}
index += width
}
return nil
}

static func codexForkCommandSessionIndex(_ args: [String], forkIndex: Int) -> Int? {
var index = forkIndex + 1
while index < args.count {
let argument = args[index]
if argument == "--" {
return nil
}
if !argument.hasPrefix("-") || argument == "-" {
return looksLikeCodexSessionIdentifier(argument) ? index : nil
}
let width = optionWidth(args, index: index, policy: codexPolicy)
if codexPolicy.variadicOptions.contains(argument) {
let end = min(args.count, index + width)
if index + 2 < end {
for candidateIndex in (index + 2)..<end {
if looksLikeCodexSessionIdentifier(args[candidateIndex]) {
return candidateIndex
}
}
}
}
index += width
}
return nil
}

static func looksLikeCodexSessionIdentifier(_ value: String) -> Bool {
let trimmed = value.trimmingCharacters(in: .whitespacesAndNewlines)
guard trimmed.count >= 20 else { return false }
if trimmed.hasPrefix("019") {
return true
}
let allowed = CharacterSet(charactersIn: "0123456789abcdefABCDEF-")
return trimmed.unicodeScalars.allSatisfy { allowed.contains($0) } && trimmed.contains("-")
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

private static func containsCmuxInjectedCodexHookConfig(_ args: [String]) -> Bool {
var index = 0
while index < args.count {
let arg = args[index]
if isCmuxInjectedCodexHookConfigOption(arg) {
return true
}
if (arg == "-c" || arg == "--config"),
index + 1 < args.count,
isCmuxInjectedCodexHookConfigValue(args[index + 1]) {
return true
}
index += 1
}
return false
}

private static func isCmuxInjectedCodexHookConfigOption(_ arg: String) -> Bool {
for prefix in ["-c=", "--config="] where arg.hasPrefix(prefix) {
return isCmuxInjectedCodexHookConfigValue(String(arg.dropFirst(prefix.count)))
}
return false
}

private static func isCmuxInjectedCodexHookConfigValue(_ value: String) -> Bool {
value.hasPrefix("hooks.") && value.contains("cmux-codex-hook")
}

private static func javaScriptRuntimeScriptArgumentIndex(_ argv: [String]) -> Int? {
var index = 1
while index < argv.count {
let argument = argv[index]
if argument == "--" {
let nextIndex = index + 1
return nextIndex < argv.count ? nextIndex : nil
}
if argument.hasPrefix("-") {
if nodeOptionConsumesScript(argument) {
return nil
}
index += 1 + nodeOptionValueCount(argument)
continue
}
return index
}
return nil
}

private static func nodeOptionConsumesScript(_ argument: String) -> Bool {
let option = argument.split(separator: "=", maxSplits: 1).first.map(String.init) ?? argument
switch option {
case "-e", "--eval", "-p", "--print", "-c", "--check":
return true
default:
return false
}
}

private static func nodeOptionValueCount(_ argument: String) -> Int {
if argument.contains("=") {
return 0
}
switch argument {
case "-r", "--require", "--import", "--loader", "--experimental-loader",
"--conditions", "-C", "--title":
return 1
default:
return 0
}
}
}
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved

private extension String {
func removingSingleJavaScriptExtension() -> String? {
for suffix in [".js", ".mjs", ".cjs"] where hasSuffix(suffix) {
return String(dropLast(suffix.count))
}
return nil
}
}
Loading
Loading