@quantiya/codevibe-codex-plugin 2.0.14 → 2.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -36,6 +36,10 @@ while [ -L "$SOURCE" ]; do
36
36
  done
37
37
  SCRIPT_DIR="$(cd -P "$(dirname "$SOURCE")" && pwd)"
38
38
  PLUGIN_DIR="$(dirname "$SCRIPT_DIR")"
39
+ # Match Codex's documented configuration discovery. This also lets isolated
40
+ # candidate runs keep hooks/config separate without changing HOME, which owns
41
+ # the user's independent CodeVibe authentication state.
42
+ CODEX_CONFIG_HOME="${CODEX_HOME:-$HOME/.codex}"
39
43
 
40
44
  # ─── PATH augmentation ───────────────────────────────────────────────
41
45
  # When the install one-liner runs in a fresh terminal, Homebrew's
@@ -162,8 +166,8 @@ _CV_OS_VER="$(uname -s | cv_sanitize)"
162
166
  [ -z "$_CV_OS_VER" ] && _CV_OS_VER="unknown"
163
167
  _CV_ARCH_VER="$(uname -m | cv_sanitize)"
164
168
  [ -z "$_CV_ARCH_VER" ] && _CV_ARCH_VER="unknown"
165
- _CV_CODEX_AUTH="false"; [ -f "$HOME/.codex/auth.json" ] && _CV_CODEX_AUTH="true"
166
- _CV_CODEX_CONFIG="false"; [ -f "$HOME/.codex/config.toml" ] && _CV_CODEX_CONFIG="true"
169
+ _CV_CODEX_AUTH="false"; [ -f "$CODEX_CONFIG_HOME/auth.json" ] && _CV_CODEX_AUTH="true"
170
+ _CV_CODEX_CONFIG="false"; [ -f "$CODEX_CONFIG_HOME/config.toml" ] && _CV_CODEX_CONFIG="true"
167
171
  _CV_INSIDE_TMUX="false"; [ -n "$TMUX" ] && _CV_INSIDE_TMUX="true"
168
172
  _CV_IS_TTY="false"; { [ -t 0 ] && [ -t 1 ]; } && _CV_IS_TTY="true"
169
173
  cv_telem "wrapper_started" "\"invocation\":\"session\",\"os\":\"$_CV_OS_VER\",\"arch\":\"$_CV_ARCH_VER\",\"codex_version\":\"$_CV_CODEX_VER\",\"node_version\":\"$_CV_NODE_VER\",\"tmux_version\":\"$_CV_TMUX_VER\",\"codex_auth_present\":$_CV_CODEX_AUTH,\"codex_config_present\":$_CV_CODEX_CONFIG,\"inside_tmux\":$_CV_INSIDE_TMUX,\"is_terminal\":$_CV_IS_TTY"
@@ -177,6 +181,27 @@ log() {
177
181
  echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*" >> "$LOG_FILE"
178
182
  }
179
183
 
184
+ tmux_session_state() {
185
+ local target="$1"
186
+ local output
187
+ local rc
188
+ output="$(tmux has-session -t "$target" 2>&1)"
189
+ rc=$?
190
+ if [ "$rc" -eq 0 ]; then
191
+ printf '%s\n' "alive"
192
+ return
193
+ fi
194
+ case "$output" in
195
+ "can't find session:"*|"no server running on "*|"error connecting to "*" (No such file or directory)"|"error connecting to "*" (Connection refused)")
196
+ printf '%s\n' "absent"
197
+ ;;
198
+ *)
199
+ log "WARN: tmux inspection failed for $target; preserving daemon: $output"
200
+ printf '%s\n' "unknown"
201
+ ;;
202
+ esac
203
+ }
204
+
180
205
  # Cleanup function to kill server when wrapper exits
181
206
  cleanup() {
182
207
  local wrapper_exit_code=$?
@@ -187,11 +212,17 @@ cleanup() {
187
212
  # that live Codex session disconnected on mobile. The daemon now monitors
188
213
  # this exact tmux session and performs normal cleanup when the native
189
214
  # session actually ends, so a detach transfers lifecycle ownership to it.
190
- if [ "${_CV_TMUX_STARTED:-false}" = "true" ] \
191
- && tmux has-session -t "$SESSION_NAME" 2>/dev/null; then
192
- log "Tmux client detached while Codex remains active; leaving daemon running"
193
- rm -f "${CODEVIBE_TMPDIR}/codevibe-codex-server-$$.pid"
194
- return
215
+ if [ "${_CV_TMUX_STARTED:-false}" = "true" ]; then
216
+ local tmux_state
217
+ tmux_state="$(tmux_session_state "$SESSION_NAME")"
218
+ if [ "$tmux_state" = "alive" ]; then
219
+ log "Tmux client detached while Codex remains active; leaving daemon running"
220
+ return
221
+ fi
222
+ if [ "$tmux_state" = "unknown" ]; then
223
+ log "Tmux state is ambiguous; preserving daemon and native session"
224
+ return
225
+ fi
195
226
  fi
196
227
 
197
228
  # Fire wrapper_exited telemetry BEFORE killing the server so the MCP
@@ -247,7 +278,8 @@ cleanup() {
247
278
  rm -f "${CODEVIBE_TMPDIR}/codevibe-codex-${SESSION_NAME}.port"
248
279
  rm -f "$_CV_CODEX_EXIT_FILE"
249
280
 
250
- # Remove our hooks from ~/.codex/hooks.json (idempotent, concurrent-safe).
281
+ # Remove our hooks from Codex's configured hooks.json (idempotent,
282
+ # concurrent-safe).
251
283
  # Uses Node (always available — required to run the daemon) so users
252
284
  # without jq don't end up with stale CodeVibe hook entries leftover
253
285
  # after the wrapper exits. Ownership check is path-prefix + filename
@@ -255,13 +287,13 @@ cleanup() {
255
287
  # that happen to contain the string codevibe-codex (e.g. a username,
256
288
  # a directory like /Users/codevibe-codex/) cannot trigger removal of
257
289
  # the user's unrelated hooks.
258
- if [ -f "$HOME/.codex/hooks.json" ] && command -v node &> /dev/null; then
290
+ if [ -f "$CODEX_CONFIG_HOME/hooks.json" ] && command -v node &> /dev/null; then
259
291
  # Only remove if no other codevibe-codex sessions are running
260
292
  if [ "$(pgrep -f 'codevibe-codex' | wc -l)" -le 1 ]; then
261
- log "Removing CodeVibe hooks from $HOME/.codex/hooks.json"
293
+ log "Removing CodeVibe hooks from $CODEX_CONFIG_HOME/hooks.json"
262
294
  # The shared helper keeps install and cleanup ownership rules in
263
295
  # lockstep, including task-named CodeVibe agent worktrees.
264
- if CV_HOOKS_FILE="$HOME/.codex/hooks.json" \
296
+ if CV_HOOKS_FILE="$CODEX_CONFIG_HOME/hooks.json" \
265
297
  node "$PLUGIN_DIR/libexec/codex-hook-config.js" cleanup 2>>"$LOG_FILE"; then
266
298
  :
267
299
  else
@@ -313,6 +345,7 @@ fi
313
345
  # Generate a unique session name
314
346
  SESSION_NAME="${TMUX_SESSION_PREFIX}-$$"
315
347
  WORKING_DIR="$(pwd)"
348
+ export CODEVIBE_CODEX_WRAPPER_PID="$$"
316
349
 
317
350
  log "Starting codevibe-codex with session: $SESSION_NAME"
318
351
  log "Working directory: $WORKING_DIR"
@@ -360,7 +393,7 @@ export CODEVIBE_CODEX_PLUGIN_DIR="$PLUGIN_DIR"
360
393
  # Install hooks.json for Codex CLI with absolute paths (idempotent)
361
394
  # Codex CLI does NOT expand env vars in hook commands, so we must
362
395
  # write absolute paths at runtime.
363
- CODEX_HOOKS_FILE="$HOME/.codex/hooks.json"
396
+ CODEX_HOOKS_FILE="$CODEX_CONFIG_HOME/hooks.json"
364
397
  HOOKS_DIR="$PLUGIN_DIR/hooks"
365
398
 
366
399
  generate_hooks_json() {
@@ -379,8 +412,8 @@ HOOKEOF
379
412
  }
380
413
 
381
414
  # Ensure hooks feature flag is enabled in Codex config
382
- CODEX_CONFIG="$HOME/.codex/config.toml"
383
- mkdir -p "$HOME/.codex"
415
+ CODEX_CONFIG="$CODEX_CONFIG_HOME/config.toml"
416
+ mkdir -p "$CODEX_CONFIG_HOME"
384
417
  if [ ! -f "$CODEX_CONFIG" ]; then
385
418
  printf '[features]\nhooks = true\n' > "$CODEX_CONFIG"
386
419
  log "Created config.toml with hooks feature flag"
@@ -331,8 +331,8 @@ ifeq ($(strip $(foreach prefix,$(NO_LOAD),\
331
331
  endif
332
332
 
333
333
  quiet_cmd_regen_makefile = ACTION Regenerating $@
334
- cmd_regen_makefile = cd $(srcdir); /opt/homebrew/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py -fmake --ignore-environment "-Dlibrary=shared_library" "-Dvisibility=default" "-Dnode_root_dir=/Users/hendryyeh/Library/Caches/node-gyp/24.4.0" "-Dnode_gyp_dir=/opt/homebrew/lib/node_modules/npm/node_modules/node-gyp" "-Dnode_lib_file=/Users/hendryyeh/Library/Caches/node-gyp/24.4.0/<(target_arch)/node.lib" "-Dmodule_root_dir=/Users/hendryyeh/Workspace/CodeVibe/.agent-worktrees/codex-1/p17-retry-containment/codevibe-codex-plugin/node_modules/fs-ext" "-Dnode_engine=v8" "--depth=." "-Goutput_dir=." "--generator-output=build" -I/Users/hendryyeh/Workspace/CodeVibe/.agent-worktrees/codex-1/p17-retry-containment/codevibe-codex-plugin/node_modules/fs-ext/build/config.gypi -I/opt/homebrew/lib/node_modules/npm/node_modules/node-gyp/addon.gypi -I/Users/hendryyeh/Library/Caches/node-gyp/24.4.0/include/node/common.gypi "--toplevel-dir=." binding.gyp
335
- Makefile: $(srcdir)/../../../../../../../../Library/Caches/node-gyp/24.4.0/include/node/common.gypi $(srcdir)/build/config.gypi $(srcdir)/../../../../../../../../../../opt/homebrew/lib/node_modules/npm/node_modules/node-gyp/addon.gypi $(srcdir)/binding.gyp
334
+ cmd_regen_makefile = cd $(srcdir); /opt/homebrew/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py -fmake --ignore-environment "-Dlibrary=shared_library" "-Dvisibility=default" "-Dnode_root_dir=/Users/hendryyeh/Library/Caches/node-gyp/24.4.0" "-Dnode_gyp_dir=/opt/homebrew/lib/node_modules/npm/node_modules/node-gyp" "-Dnode_lib_file=/Users/hendryyeh/Library/Caches/node-gyp/24.4.0/<(target_arch)/node.lib" "-Dmodule_root_dir=/Users/hendryyeh/Workspace/CodeVibe/codevibe-codex-plugin/node_modules/fs-ext" "-Dnode_engine=v8" "--depth=." "-Goutput_dir=." "--generator-output=build" -I/Users/hendryyeh/Workspace/CodeVibe/codevibe-codex-plugin/node_modules/fs-ext/build/config.gypi -I/opt/homebrew/lib/node_modules/npm/node_modules/node-gyp/addon.gypi -I/Users/hendryyeh/Library/Caches/node-gyp/24.4.0/include/node/common.gypi "--toplevel-dir=." binding.gyp
335
+ Makefile: $(srcdir)/../../../../../../../opt/homebrew/lib/node_modules/npm/node_modules/node-gyp/addon.gypi $(srcdir)/../../../../../Library/Caches/node-gyp/24.4.0/include/node/common.gypi $(srcdir)/binding.gyp $(srcdir)/build/config.gypi
336
336
  $(call do_cmd,regen_makefile)
337
337
 
338
338
  # "all" is a concatenation of the "all" targets from all the included
@@ -490,7 +490,7 @@
490
490
  "python": "/opt/homebrew/opt/python@3.14/bin/python3.14",
491
491
  "standalone_static_library": 1,
492
492
  "global_prefix": "/opt/homebrew",
493
- "local_prefix": "/Users/hendryyeh/Workspace/CodeVibe/.agent-worktrees/codex-1/p17-retry-containment/codevibe-codex-plugin",
493
+ "local_prefix": "/Users/hendryyeh/Workspace/CodeVibe/codevibe-codex-plugin",
494
494
  "globalconfig": "/opt/homebrew/etc/npmrc",
495
495
  "init_module": "/Users/hendryyeh/.npm-init.js",
496
496
  "userconfig": "/Users/hendryyeh/.npmrc",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quantiya/codevibe-codex-plugin",
3
- "version": "2.0.14",
3
+ "version": "2.0.16",
4
4
  "description": "Control OpenAI Codex CLI from your iPhone and Android — real-time sync, approve file edits, send prompts by voice. Part of CodeVibe.",
5
5
  "main": "dist/server.js",
6
6
  "codevibe": {