2929
3030$ status = $ input ? json_decode ($ input , true ) : [];
3131
32+ // Extract session_id for lock file matching
33+ $ sessionId = $ status ['session_id ' ] ?? null ;
34+
3235// Extract model - handle both nested format and simple string
3336$ model = 'Unknown ' ;
3437if (isset ($ status ['model ' ])) {
5255 }
5356}
5457
55- // Find active build lock file
56- $ lockFile = findActiveLock ();
58+ // Get current git branch
59+ $ gitBranch = getCurrentBranch ();
60+
61+ // Find active build lock file (matching session_id if available)
62+ $ lockFile = findActiveLock ($ sessionId );
5763$ taskInfo = '' ;
5864
5965if ($ lockFile && file_exists ($ lockFile )) {
7884// Build the status line with ANSI colors
7985$ statusLine = '' ;
8086
87+ if ($ gitBranch ) {
88+ $ statusLine .= "\033[35m[ {$ gitBranch }] \033[0m " ; // Magenta for branch
89+ }
90+
8191if ($ taskInfo ) {
8292 $ statusLine .= "\033[36m {$ taskInfo }\033[0m " ; // Cyan for task info
8393}
91101echo $ statusLine ;
92102
93103/**
94- * Find the active lock file in .laracode/specs/
104+ * Get current git branch name
105+ */
106+ function getCurrentBranch (): ?string
107+ {
108+ $ result = exec ('git rev-parse --abbrev-ref HEAD 2>/dev/null ' , $ output , $ returnCode );
109+
110+ return $ returnCode === 0 && $ result ? trim ($ result ) : null ;
111+ }
112+
113+ /**
114+ * Find the active lock file in .laracode/specs/ matching the session_id
95115 */
96- function findActiveLock (): ?string
116+ function findActiveLock (? string $ sessionId ): ?string
97117{
98118 $ cwd = getcwd ();
99119 if ($ cwd === false ) {
@@ -110,6 +130,23 @@ function findActiveLock(): ?string
110130 return null ;
111131 }
112132
133+ // First pass: try to match by session_id
134+ if ($ sessionId !== null ) {
135+ foreach ($ dirs as $ dir ) {
136+ $ lockPath = $ dir .'/index.lock ' ;
137+ if (file_exists ($ lockPath )) {
138+ $ content = file_get_contents ($ lockPath );
139+ if ($ content !== false ) {
140+ $ data = json_decode ($ content , true );
141+ if (isset ($ data ['session_id ' ]) && $ data ['session_id ' ] === $ sessionId ) {
142+ return $ lockPath ;
143+ }
144+ }
145+ }
146+ }
147+ }
148+
149+ // Fallback: return first lock file (backward compatibility)
113150 foreach ($ dirs as $ dir ) {
114151 $ lockPath = $ dir .'/index.lock ' ;
115152 if (file_exists ($ lockPath )) {
0 commit comments