Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
refactor: Extract shared POSIX directive parser for bash/zsh
Maximilian Roos3c02157151d2
diff --git a/src/shell.rs b/src/shell.rsindex add0e0ae2..34dfe9ae6 100644--- a/src/shell.rs+++ b/src/shell.rs@@ -1,6 +1,8 @@use askama::Template;use std::path::PathBuf;+const POSIX_DIRECTIVE_SHIM: &str = include_str!("../templates/posix_directives.sh");+/// Supported shells#[derive(Debug, Clone, Copy, clap::ValueEnum, strum::Display, strum::EnumString)]#[strum(serialize_all = "lowercase", ascii_case_insensitive)]@@ -301,12 +303,14 @@ impl ShellInit {let template = BashTemplate {shell_name: self.shell.to_string(),cmd_prefix: &self.cmd_prefix,+ posix_shim: POSIX_DIRECTIVE_SHIM,};template.render()}Shell::Zsh => {let template = ZshTemplate {cmd_prefix: &self.cmd_prefix,+ posix_shim: POSIX_DIRECTIVE_SHIM,};template.render()}@@ -353,6 +357,7 @@ impl ShellInit {struct BashTemplate<'a> {shell_name: String,cmd_prefix: &'a str,+ posix_shim: &'a str,}/// Zsh shell template@@ -360,6 +365,7 @@ struct BashTemplate<'a> {#[template(path = "zsh.zsh", escape = "none")]struct ZshTemplate<'a> {cmd_prefix: &'a str,+ posix_shim: &'a str,}/// Fish shell templatediff --git a/templates/bash.sh b/templates/bash.shindex 5453420eb..15c14ed7d 100644--- a/templates/bash.sh+++ b/templates/bash.sh@@ -6,49 +6,7 @@ if command -v {{ cmd_prefix }} >/dev/null 2>&1 || [[ -n "${WORKTRUNK_BIN:-}" ]];# This allows testing development builds: export WORKTRUNK_BIN=./target/debug/{{ cmd_prefix }}_WORKTRUNK_CMD="${WORKTRUNK_BIN:-{{ cmd_prefix }}}"- # Helper function to parse wt output and handle directives- # Directives are NUL-terminated to support multi-line commands- _wt_exec() {- local exec_cmd="" chunk exit_code- local exit_code_file- exit_code_file=$(mktemp) || { echo "Failed to create temp file" >&2; return 1; }-- # Parse stdout for directives (NUL-delimited)- # Let stderr pass through to terminal (preserves TTY for color detection)- # Write exit code to temp file since it can't be captured from process substitution- # The || [[ -n "$chunk" ]] handles non-NUL-terminated output (e.g., error messages)- while IFS= read -r -d '' chunk || [[ -n "$chunk" ]]; do- if [[ "$chunk" == __WORKTRUNK_CD__* ]]; then- # CD directive - extract path and change directory- local path="${chunk#__WORKTRUNK_CD__}"- \cd "$path"- elif [[ "$chunk" == __WORKTRUNK_EXEC__* ]]; then- # EXEC directive - extract command (may contain newlines)- exec_cmd="${chunk#__WORKTRUNK_EXEC__}"- else- # Regular output - print it with newline- printf '%s\n' "$chunk"- fi- done < <(command "$_WORKTRUNK_CMD" "$@"; echo "$?" > "$exit_code_file")-- # Read exit code from temp file- exit_code=$(cat "$exit_code_file" 2>/dev/null || echo 0)-- # Cleanup temp file- \rm -f "$exit_code_file"-- # Execute command if one was specified- # Security: Command is user-provided from -x flag; eval is intentional.- # NUL-termination allows multi-line commands.- # Exit code semantics: If wt fails, returns wt's exit code (command never executes).- # If wt succeeds but command fails, returns the command's exit code.- if [[ -n "$exec_cmd" ]]; then- eval "$exec_cmd"- exit_code=$?- fi-- return $exit_code- }+{{ posix_shim }}# Override {{ cmd_prefix }} command to add --internal flag{{ cmd_prefix }}() {diff --git a/templates/posix_directives.sh b/templates/posix_directives.shnew file mode 100644index 000000000..57a7104ac--- /dev/null+++ b/templates/posix_directives.sh@@ -0,0 +1,57 @@+# Shared directive parser for POSIX shells (bash, zsh, oil).+# Reads worktrunk's NUL-delimited output in real-time via a FIFO so progress+# and hint messages stream immediately while keeping stderr attached to the TTY.+_wt_exec() {+ local exec_cmd="" chunk="" exit_code=0 tmp_dir="" exit_file="" fifo_path="" runner_pid=""++ tmp_dir=$(mktemp -d "${TMPDIR:-/tmp}/wt.XXXXXX") || {+ echo "Failed to create temp directory for worktrunk shim" >&2+ return 1+ }++ exit_file="$tmp_dir/exit-code"+ fifo_path="$tmp_dir/stdout.fifo"++ if ! mkfifo "$fifo_path"; then+ echo "Failed to create FIFO for worktrunk shim" >&2+ /bin/rm -rf "$tmp_dir"+ return 1+ fi++ (+ command "$_WORKTRUNK_CMD" "$@"+ printf '%s' "$?" >"$exit_file"+ ) >"$fifo_path" &+ runner_pid=$!++ # Read directives as they arrive; keep looping even if the final chunk isn't NUL-terminated.+ while IFS= read -r -d '' chunk || [[ -n "$chunk" ]]; do+ if [[ "$chunk" == __WORKTRUNK_CD__* ]]; then+ local path="${chunk#__WORKTRUNK_CD__}"+ \cd "$path"+ elif [[ "$chunk" == __WORKTRUNK_EXEC__* ]]; then+ exec_cmd="${chunk#__WORKTRUNK_EXEC__}"+ else+ printf '%s\n' "$chunk"+ fi+ done <"$fifo_path"++ # Ensure the background runner has exited before reading artifacts.+ if [[ -n "$runner_pid" ]]; then+ wait "$runner_pid" >/dev/null 2>&1 || true+ fi++ if [[ -f "$exit_file" ]]; then+ read -r exit_code < "$exit_file"+ fi++ /bin/rm -f "$exit_file" "$fifo_path"+ /bin/rmdir "$tmp_dir" 2>/dev/null || true++ if [[ -n "$exec_cmd" ]]; then+ eval "$exec_cmd"+ exit_code=$?+ fi++ return "$exit_code"+}diff --git a/templates/zsh.zsh b/templates/zsh.zshindex 53a11d055..921b6ba6f 100644--- a/templates/zsh.zsh+++ b/templates/zsh.zsh@@ -6,54 +6,7 @@ if command -v {{ cmd_prefix }} >/dev/null 2>&1 || [[ -n "${WORKTRUNK_BIN:-}" ]];# This allows testing development builds: export WORKTRUNK_BIN=./target/debug/{{ cmd_prefix }}_WORKTRUNK_CMD="${WORKTRUNK_BIN:-{{ cmd_prefix }}}"- # Helper function to parse wt output and handle directives- # Directives are NUL-terminated to support multi-line commands- _wt_exec() {- local exec_cmd="" chunk exit_code- local exit_code_file stdout_file- exit_code_file=$(mktemp) || { echo "Failed to create temp file" >&2; return 1; }- stdout_file=$(mktemp) || { /bin/rm -f "$exit_code_file" 2>/dev/null; echo "Failed to create temp file" >&2; return 1; }-- # Run command and capture output to file to avoid process substitution issues- # Process substitution in zsh can hang in non-interactive mode- # Let stderr pass through to terminal (preserves TTY for color detection)- command "$_WORKTRUNK_CMD" "$@" > "$stdout_file"- echo "$?" > "$exit_code_file"-- # Parse stdout for directives (NUL-delimited)- # The || [[ -n "$chunk" ]] handles non-NUL-terminated output (e.g., error messages)- while IFS= read -r -d '' chunk || [[ -n "$chunk" ]]; do- if [[ "$chunk" == __WORKTRUNK_CD__* ]]; then- # CD directive - extract path and change directory- local path="${chunk#__WORKTRUNK_CD__}"- \cd "$path"- elif [[ "$chunk" == __WORKTRUNK_EXEC__* ]]; then- # EXEC directive - extract command (may contain newlines)- exec_cmd="${chunk#__WORKTRUNK_EXEC__}"- else- # Regular output - print it with newline- printf '%s\n' "$chunk"- fi- done < "$stdout_file"-- # Read exit code from temp file- exit_code=$(cat "$exit_code_file" 2>/dev/null || echo 0)-- # Cleanup temp files (use absolute path for --no-rcs compatibility)- /bin/rm -f "$exit_code_file" "$stdout_file" 2>/dev/null || true-- # Execute command if one was specified- # Security: Command is user-provided from -x flag; eval is intentional.- # NUL-termination allows multi-line commands.- # Exit code semantics: If wt fails, returns wt's exit code (command never executes).- # If wt succeeds but command fails, returns the command's exit code.- if [[ -n "$exec_cmd" ]]; then- eval "$exec_cmd"- exit_code=$?- fi-- return $exit_code- }+{{ posix_shim }}# Override {{ cmd_prefix }} command to add --internal flag{{ cmd_prefix }}() {diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_mixed_stdout_stderr_zsh.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_mixed_stdout_stderr_zsh.snapindex 07fba04a8..83da391ca 100644--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_mixed_stdout_stderr_zsh.snap+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_mixed_stdout_stderr_zsh.snap@@ -2,6 +2,9 @@source: tests/integration_tests/shell_wrapper.rsexpression: output.normalized()---+π [36mRunning pre-merge [1mcheck1[0m:[0m+[40m [0m [1m[34m[WORKSPACE]/tests/fixtures/mixed-output.sh[0m check1 3[0m+[check1] stdout line 1[check1] stderr line 1[check1] stdout line 2@@ -10,6 +13,10 @@ expression: output.normalized()[check1] stderr line 3[check1] stdout complete[check1] stderr complete++π [36mRunning pre-merge [1mcheck2[0m:[0m+[40m [0m [1m[34m[WORKSPACE]/tests/fixtures/mixed-output.sh[0m check2 3[0m+[check2] stdout line 1[check2] stderr line 1[check2] stdout line 2@@ -18,13 +25,6 @@ expression: output.normalized()[check2] stderr line 3[check2] stdout complete[check2] stderr complete-π [36mRunning pre-merge [1mcheck1[0m:[0m-[40m [0m [1m[34m[WORKSPACE]/tests/fixtures/mixed-output.sh[0m check1 3[0m---π [36mRunning pre-merge [1mcheck2[0m:[0m-[40m [0m [1m[34m[WORKSPACE]/tests/fixtures/mixed-output.sh[0m check2 3[0m-π [36mMerging 1 commit to [1m[36mmain[0m[36m @ [2m[36m[HASH][0m[0m (no commit/squash/rebase needed)diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_failure_zsh.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_failure_zsh.snapindex 93c1a6485..218fd4dae 100644--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_failure_zsh.snap+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_failure_zsh.snap@@ -2,15 +2,15 @@source: tests/integration_tests/shell_wrapper.rsexpression: output.normalized()----β Code formatting check passed-β Test suite failed: 3 tests failingπ [36mRunning pre-merge [1mformat[0m:[0m[40m [0m [1m[34mecho[0m [32m'β Code formatting check passed'[0m[0m+β Code formatting check passedπ [36mRunning pre-merge [1mtest[0m:[0m[40m [0m [1m[34mecho[0m [32m'β Test suite failed: 3 tests failing'[0m [36m&&[0m [1m[34mexit[0m 1[0m+β Test suite failed: 3 tests failingβ [31mpre-merge command failed: [1m[31mtest[0m: exit status: 1[0mπ‘ [2mUse --no-verify to skip pre-merge commands[0mdiff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_success_zsh.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_success_zsh.snapindex 448ecefc2..238fc6b08 100644--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_success_zsh.snap+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_success_zsh.snap@@ -2,20 +2,20 @@source: tests/integration_tests/shell_wrapper.rsexpression: output.normalized()----β Code formatting check passed-β Linting passed - no warnings-β All 47 tests passed in 2.3sπ [36mRunning pre-merge [1mformat[0m:[0m[40m [0m [1m[34mecho[0m [32m'β Code formatting check passed'[0m[0m+β Code formatting check passedπ [36mRunning pre-merge [1mlint[0m:[0m[40m [0m [1m[34mecho[0m [32m'β Linting passed - no warnings'[0m[0m+β Linting passed - no warningsπ [36mRunning pre-merge [1mtest[0m:[0m[40m [0m [1m[34mecho[0m [32m'β All 47 tests passed in 2.3s'[0m[0m+β All 47 tests passed in 2.3sπ [36mMerging 1 commit to [1m[36mmain[0m[36m @ [2m[36m[HASH][0m[0m (no commit/squash/rebase needed)diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_hooks_zsh.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_hooks_zsh.snapindex 0a9640851..8be679a0d 100644--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_hooks_zsh.snap+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_hooks_zsh.snap@@ -2,15 +2,15 @@source: tests/integration_tests/shell_wrapper.rsexpression: output.normalized()----Installing dependencies...-Building project...π [36mRunning post-create:[0m[40m [0m [1m[34mecho[0m [32m'Installing dependencies...'[0m[0m+Installing dependencies...π [36mRunning post-create:[0m[40m [0m [1m[34mecho[0m [32m'Building project...'[0m[0m+Building project...β [32mCreated new worktree for [1m[32mfeature-hooks[0m[32m from [1m[32mmain[0m[32m at [1m[32m[TMPDIR]/test-repo.feature-hooks[0m[0mπ [36mRunning post-start [1mserver[0m:[0mdiff --git a/tests/snapshots/integration__integration_tests__init__init_bash.snap b/tests/snapshots/integration__integration_tests__init__init_bash.snapindex b10285728..bd51bf447 100644--- a/tests/snapshots/integration__integration_tests__init__init_bash.snap+++ b/tests/snapshots/integration__integration_tests__init__init_bash.snap@@ -16,7 +16,7 @@ info:LANG: CLC_ALL: CSOURCE_DATE_EPOCH: "1761609600"- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmp4sEkZq/test-config.toml+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpiqC07O/test-config.toml---success: trueexit_code: 0@@ -29,49 +29,64 @@ if command -v wt >/dev/null 2>&1 || [[ -n "${WORKTRUNK_BIN:-}" ]]; then# This allows testing development builds: export WORKTRUNK_BIN=./target/debug/wt_WORKTRUNK_CMD="${WORKTRUNK_BIN:-wt}"- # Helper function to parse wt output and handle directives- # Directives are NUL-terminated to support multi-line commands- _wt_exec() {- local exec_cmd="" chunk exit_code- local exit_code_file- exit_code_file=$(mktemp) || { echo "Failed to create temp file" >&2; return 1; }+# Shared directive parser for POSIX shells (bash, zsh, oil).+# Reads worktrunk's NUL-delimited output in real-time via a FIFO so progress+# and hint messages stream immediately while keeping stderr attached to the TTY.+_wt_exec() {+ local exec_cmd="" chunk="" exit_code=0 tmp_dir="" exit_file="" fifo_path="" runner_pid=""- # Parse stdout for directives (NUL-delimited)- # Let stderr pass through to terminal (preserves TTY for color detection)- # Write exit code to temp file since it can't be captured from process substitution- # The || [[ -n "$chunk" ]] handles non-NUL-terminated output (e.g., error messages)- while IFS= read -r -d '' chunk || [[ -n "$chunk" ]]; do- if [[ "$chunk" == __WORKTRUNK_CD__* ]]; then- # CD directive - extract path and change directory- local path="${chunk#__WORKTRUNK_CD__}"- \cd "$path"- elif [[ "$chunk" == __WORKTRUNK_EXEC__* ]]; then- # EXEC directive - extract command (may contain newlines)- exec_cmd="${chunk#__WORKTRUNK_EXEC__}"- else- # Regular output - print it with newline- printf '%s\n' "$chunk"- fi- done < <(command "$_WORKTRUNK_CMD" "$@"; echo "$?" > "$exit_code_file")+ tmp_dir=$(mktemp -d "${TMPDIR:-/tmp}/wt.XXXXXX") || {+ echo "Failed to create temp directory for worktrunk shim" >&2+ return 1+ }++ exit_file="$tmp_dir/exit-code"+ fifo_path="$tmp_dir/stdout.fifo"- # Read exit code from temp file- exit_code=$(cat "$exit_code_file" 2>/dev/null || echo 0)+ if ! mkfifo "$fifo_path"; then+ echo "Failed to create FIFO for worktrunk shim" >&2+ /bin/rm -rf "$tmp_dir"+ return 1+ fi- # Cleanup temp file- \rm -f "$exit_code_file"+ (+ command "$_WORKTRUNK_CMD" "$@"+ printf '%s' "$?" >"$exit_file"+ ) >"$fifo_path" &+ runner_pid=$!- # Execute command if one was specified- # Security: Command is user-provided from -x flag; eval is intentional.- # NUL-termination allows multi-line commands.- # Exit code semantics: If wt fails, returns wt's exit code (command never executes).- # If wt succeeds but command fails, returns the command's exit code.- if [[ -n "$exec_cmd" ]]; then- eval "$exec_cmd"- exit_code=$?+ # Read directives as they arrive; keep looping even if the final chunk isn't NUL-terminated.+ while IFS= read -r -d '' chunk || [[ -n "$chunk" ]]; do+ if [[ "$chunk" == __WORKTRUNK_CD__* ]]; then+ local path="${chunk#__WORKTRUNK_CD__}"+ \cd "$path"+ elif [[ "$chunk" == __WORKTRUNK_EXEC__* ]]; then+ exec_cmd="${chunk#__WORKTRUNK_EXEC__}"+ else+ printf '%s\n' "$chunk"fi+ done <"$fifo_path"++ # Ensure the background runner has exited before reading artifacts.+ if [[ -n "$runner_pid" ]]; then+ wait "$runner_pid" >/dev/null 2>&1 || true+ fi++ if [[ -f "$exit_file" ]]; then+ read -r exit_code < "$exit_file"+ fi++ /bin/rm -f "$exit_file" "$fifo_path"+ /bin/rmdir "$tmp_dir" 2>/dev/null || true++ if [[ -n "$exec_cmd" ]]; then+ eval "$exec_cmd"+ exit_code=$?+ fi++ return "$exit_code"+}- return $exit_code- }# Override wt command to add --internal flagwt() {diff --git a/tests/snapshots/integration__integration_tests__init__init_zsh.snap b/tests/snapshots/integration__integration_tests__init__init_zsh.snapindex 194584f96..4e8c8b8a6 100644--- a/tests/snapshots/integration__integration_tests__init__init_zsh.snap+++ b/tests/snapshots/integration__integration_tests__init__init_zsh.snap@@ -16,7 +16,7 @@ info:LANG: CLC_ALL: CSOURCE_DATE_EPOCH: "1761609600"- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpIZkO2j/test-config.toml+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpPLmErG/test-config.toml---success: trueexit_code: 0@@ -29,55 +29,65 @@ if command -v wt >/dev/null 2>&1 || [[ -n "${WORKTRUNK_BIN:-}" ]]; then# This allows testing development builds: export WORKTRUNK_BIN=./target/debug/wt_WORKTRUNK_CMD="${WORKTRUNK_BIN:-wt}"- # Helper function to parse wt output and handle directives- # Directives are NUL-terminated to support multi-line commands- _wt_exec() {- local exec_cmd="" chunk exit_code- local exit_code_file stdout_file- exit_code_file=$(mktemp) || { echo "Failed to create temp file" >&2; return 1; }- stdout_file=$(mktemp) || { /bin/rm -f "$exit_code_file" 2>/dev/null; echo "Failed to create temp file" >&2; return 1; }-- # Run command and capture output to file to avoid process substitution issues- # Process substitution in zsh can hang in non-interactive mode- # Let stderr pass through to terminal (preserves TTY for color detection)- command "$_WORKTRUNK_CMD" "$@" > "$stdout_file"- echo "$?" > "$exit_code_file"-- # Parse stdout for directives (NUL-delimited)- # The || [[ -n "$chunk" ]] handles non-NUL-terminated output (e.g., error messages)- while IFS= read -r -d '' chunk || [[ -n "$chunk" ]]; do- if [[ "$chunk" == __WORKTRUNK_CD__* ]]; then- # CD directive - extract path and change directory- local path="${chunk#__WORKTRUNK_CD__}"- \cd "$path"- elif [[ "$chunk" == __WORKTRUNK_EXEC__* ]]; then- # EXEC directive - extract command (may contain newlines)- exec_cmd="${chunk#__WORKTRUNK_EXEC__}"- else- # Regular output - print it with newline- printf '%s\n' "$chunk"- fi- done < "$stdout_file"-- # Read exit code from temp file- exit_code=$(cat "$exit_code_file" 2>/dev/null || echo 0)-- # Cleanup temp files (use absolute path for --no-rcs compatibility)- /bin/rm -f "$exit_code_file" "$stdout_file" 2>/dev/null || true-- # Execute command if one was specified- # Security: Command is user-provided from -x flag; eval is intentional.- # NUL-termination allows multi-line commands.- # Exit code semantics: If wt fails, returns wt's exit code (command never executes).- # If wt succeeds but command fails, returns the command's exit code.- if [[ -n "$exec_cmd" ]]; then- eval "$exec_cmd"- exit_code=$?- fi+# Shared directive parser for POSIX shells (bash, zsh, oil).+# Reads worktrunk's NUL-delimited output in real-time via a FIFO so progress+# and hint messages stream immediately while keeping stderr attached to the TTY.+_wt_exec() {+ local exec_cmd="" chunk="" exit_code=0 tmp_dir="" exit_file="" fifo_path="" runner_pid=""- return $exit_code+ tmp_dir=$(mktemp -d "${TMPDIR:-/tmp}/wt.XXXXXX") || {+ echo "Failed to create temp directory for worktrunk shim" >&2+ return 1}+ exit_file="$tmp_dir/exit-code"+ fifo_path="$tmp_dir/stdout.fifo"++ if ! mkfifo "$fifo_path"; then+ echo "Failed to create FIFO for worktrunk shim" >&2+ /bin/rm -rf "$tmp_dir"+ return 1+ fi++ (+ command "$_WORKTRUNK_CMD" "$@"+ printf '%s' "$?" >"$exit_file"+ ) >"$fifo_path" &+ runner_pid=$!++ # Read directives as they arrive; keep looping even if the final chunk isn't NUL-terminated.+ while IFS= read -r -d '' chunk || [[ -n "$chunk" ]]; do+ if [[ "$chunk" == __WORKTRUNK_CD__* ]]; then+ local path="${chunk#__WORKTRUNK_CD__}"+ \cd "$path"+ elif [[ "$chunk" == __WORKTRUNK_EXEC__* ]]; then+ exec_cmd="${chunk#__WORKTRUNK_EXEC__}"+ else+ printf '%s\n' "$chunk"+ fi+ done <"$fifo_path"++ # Ensure the background runner has exited before reading artifacts.+ if [[ -n "$runner_pid" ]]; then+ wait "$runner_pid" >/dev/null 2>&1 || true+ fi++ if [[ -f "$exit_file" ]]; then+ read -r exit_code < "$exit_file"+ fi++ /bin/rm -f "$exit_file" "$fifo_path"+ /bin/rmdir "$tmp_dir" 2>/dev/null || true++ if [[ -n "$exec_cmd" ]]; then+ eval "$exec_cmd"+ exit_code=$?+ fi++ return "$exit_code"+}++# Override wt command to add --internal flagwt() {local use_source=false