Skip to content

Commit fb4407f

Browse files
committed
feat: Add show command to track active sessions
1 parent 16e74c7 commit fb4407f

31 files changed

Lines changed: 7057 additions & 4377 deletions

.claude/hooks/session-start.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,36 @@
33

44
declare(strict_types=1);
55

6-
7-
8-
9-
10-
11-
6+
/**
7+
* SessionStart Hook
8+
*
9+
* Updates the lock file with Claude's session_id for statusline matching.
10+
* Reads session_id from stdin JSON and writes to lock file specified in LARACODE_LOCK_FILE env var.
11+
*/
1212
$input = file_get_contents('php://stdin');
1313
$data = $input ? json_decode($input, true) : [];
1414

1515
$sessionId = $data['session_id'] ?? null;
1616
$lockFile = getenv('LARACODE_LOCK_FILE');
1717

1818
if (! $sessionId || ! $lockFile || ! file_exists($lockFile)) {
19-
exit(0);
19+
exit(0);
2020
}
2121

2222
$lockContent = file_get_contents($lockFile);
2323
if ($lockContent === false) {
24-
exit(0);
24+
exit(0);
2525
}
2626

2727
$lockData = json_decode($lockContent, true);
2828
if (! is_array($lockData)) {
29-
exit(0);
29+
exit(0);
3030
}
3131

3232
$lockData['session_id'] = $sessionId;
3333

3434
$result = file_put_contents($lockFile, json_encode($lockData, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
3535
if ($result === false) {
36-
fwrite(STDERR, "Failed to write session_id to lock file: {$lockFile}\n");
37-
exit(1);
36+
fwrite(STDERR, "Failed to write session_id to lock file: {$lockFile}\n");
37+
exit(1);
3838
}

.claude/scripts/statusline.php

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
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';
3437
if (isset($status['model'])) {
@@ -52,8 +55,11 @@
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

5965
if ($lockFile && file_exists($lockFile)) {
@@ -78,6 +84,10 @@
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+
8191
if ($taskInfo) {
8292
$statusLine .= "\033[36m{$taskInfo}\033[0m"; // Cyan for task info
8393
}
@@ -91,9 +101,19 @@
91101
echo $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)) {

.laracode/settings.json

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
{
22
"watch": {
33
"paths": [
4-
"app/",
5-
"routes/",
6-
"resources/"
4+
"app",
5+
"config",
6+
"resources",
7+
"tests"
78
],
89
"searchWord": "@claude",
910
"stopWord": "claude!",
@@ -19,5 +20,21 @@
1920
"**/*.log",
2021
"**/.DS_Store"
2122
]
22-
}
23+
},
24+
"testing": {
25+
"commands": [
26+
"composer test",
27+
"composer checks"
28+
]
29+
},
30+
"linting": {
31+
"commands": [
32+
"composer lint",
33+
"composer phpstan"
34+
]
35+
},
36+
"worktrees": {
37+
"defaultSourceBranch": "master"
38+
},
39+
"defaultMode": "yolo"
2340
}

0 commit comments

Comments
 (0)