feat: add hook env vars (folder, branch) and fix dtach cleanup#56
Merged
feat: add hook env vars (folder, branch) and fix dtach cleanup#56
Conversation
Terminal hooks (on_create, shell_wrapper) previously received zero environment variables. Now they export OKENA_PROJECT_ID, OKENA_PROJECT_NAME, OKENA_PROJECT_PATH, and OKENA_BRANCH (for worktree projects) into the shell session so they persist after the hook command runs. Also adds OKENA_TERMINAL_NAME and OKENA_BRANCH to terminal.on_close, and fixes on_worktree_close being the only worktree hook missing OKENA_BRANCH. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
After a crash or ungraceful exit, dtach socket files in /tmp/okena-<uid>/ were left behind indefinitely. Add a startup cleanup that scans the socket directory, checks each .sock file with lsof, and removes any that have no active process — preventing unbounded accumulation of orphaned sockets. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Folder context was missing from hook environment variables. Add folder_id and folder_name to project_env() and propagate through all fire_* functions. For worktree projects, falls back to the parent project's folder. Also includes the missing pty_manager.kill() call on natural terminal exit to prevent orphaned dtach daemons. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
8a1e19c to
81baa50
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
OKENA_FOLDER_IDandOKENA_FOLDER_NAMEenvironment variables to all hook types, with parent-folder fallback for worktree projectsOKENA_BRANCHto terminal hooks (on_create,shell_wrapper,on_close) for worktree projectskill_session()on natural PTY exit and cleaning up stale sockets on startupChanges
Hook environment variables
project_env()now accepts optionalfolder_id/folder_nameand setsOKENA_FOLDER_ID/OKENA_FOLDER_NAMEfire_*functions propagated with folder paramsfolder_for_project_or_parent()helper falls back to parent project's folder for worktreesterminal_hook_env()includesOKENA_BRANCHfor worktree projectson_worktree_closehook now correctly receives the branch name resolved before worktree deletiondtach cleanup
pty_manager.kill()called on natural PTY exit (prevents orphaned dtach daemons)PtyManager::cleanup_stale_sockets()Documentation
docs/hooks.mdupdated with newFOLDER_*variables in base vars table and availability matrixTest plan
terminal.on_createhook that echoes$OKENA_FOLDER_ID $OKENA_FOLDER_NAME— verify populated for projects in foldersOKENA_BRANCHis set in terminal hooks for worktree projectscargo test— all tests pass