jfl 0.1.1 → 0.2.0

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.
Files changed (112) hide show
  1. package/README.md +77 -7
  2. package/clawdbot-plugin/clawdbot.plugin.json +20 -0
  3. package/clawdbot-plugin/index.js +555 -0
  4. package/clawdbot-plugin/index.ts +582 -0
  5. package/clawdbot-skill/SKILL.md +33 -336
  6. package/clawdbot-skill/index.ts +491 -321
  7. package/clawdbot-skill/skill.json +4 -13
  8. package/dist/commands/clawdbot.d.ts +11 -0
  9. package/dist/commands/clawdbot.d.ts.map +1 -0
  10. package/dist/commands/clawdbot.js +215 -0
  11. package/dist/commands/clawdbot.js.map +1 -0
  12. package/dist/commands/gtm-process-update.d.ts +10 -0
  13. package/dist/commands/gtm-process-update.d.ts.map +1 -0
  14. package/dist/commands/gtm-process-update.js +101 -0
  15. package/dist/commands/gtm-process-update.js.map +1 -0
  16. package/dist/commands/onboard.d.ts.map +1 -1
  17. package/dist/commands/onboard.js +203 -15
  18. package/dist/commands/onboard.js.map +1 -1
  19. package/dist/commands/openclaw.d.ts +56 -0
  20. package/dist/commands/openclaw.d.ts.map +1 -0
  21. package/dist/commands/openclaw.js +700 -0
  22. package/dist/commands/openclaw.js.map +1 -0
  23. package/dist/commands/service-validate.d.ts +12 -0
  24. package/dist/commands/service-validate.d.ts.map +1 -0
  25. package/dist/commands/service-validate.js +611 -0
  26. package/dist/commands/service-validate.js.map +1 -0
  27. package/dist/commands/services-create.d.ts +15 -0
  28. package/dist/commands/services-create.d.ts.map +1 -0
  29. package/dist/commands/services-create.js +1452 -0
  30. package/dist/commands/services-create.js.map +1 -0
  31. package/dist/commands/services-sync-agents.d.ts +23 -0
  32. package/dist/commands/services-sync-agents.d.ts.map +1 -0
  33. package/dist/commands/services-sync-agents.js +207 -0
  34. package/dist/commands/services-sync-agents.js.map +1 -0
  35. package/dist/commands/services.d.ts +7 -1
  36. package/dist/commands/services.d.ts.map +1 -1
  37. package/dist/commands/services.js +347 -22
  38. package/dist/commands/services.js.map +1 -1
  39. package/dist/commands/update.js +0 -0
  40. package/dist/commands/validate-settings.d.ts +37 -0
  41. package/dist/commands/validate-settings.d.ts.map +1 -0
  42. package/dist/commands/validate-settings.js +197 -0
  43. package/dist/commands/validate-settings.js.map +1 -0
  44. package/dist/index.js +155 -60
  45. package/dist/index.js.map +1 -1
  46. package/dist/lib/agent-generator.d.ts.map +1 -1
  47. package/dist/lib/agent-generator.js +94 -1
  48. package/dist/lib/agent-generator.js.map +1 -1
  49. package/dist/lib/openclaw-registry.d.ts +48 -0
  50. package/dist/lib/openclaw-registry.d.ts.map +1 -0
  51. package/dist/lib/openclaw-registry.js +181 -0
  52. package/dist/lib/openclaw-registry.js.map +1 -0
  53. package/dist/lib/openclaw-sdk.d.ts +107 -0
  54. package/dist/lib/openclaw-sdk.d.ts.map +1 -0
  55. package/dist/lib/openclaw-sdk.js +208 -0
  56. package/dist/lib/openclaw-sdk.js.map +1 -0
  57. package/dist/lib/peer-agent-generator.d.ts +44 -0
  58. package/dist/lib/peer-agent-generator.d.ts.map +1 -0
  59. package/dist/lib/peer-agent-generator.js +286 -0
  60. package/dist/lib/peer-agent-generator.js.map +1 -0
  61. package/dist/lib/service-detector.d.ts +1 -1
  62. package/dist/lib/service-detector.d.ts.map +1 -1
  63. package/dist/lib/service-detector.js +118 -5
  64. package/dist/lib/service-detector.js.map +1 -1
  65. package/dist/lib/service-gtm.d.ts +157 -0
  66. package/dist/lib/service-gtm.d.ts.map +1 -0
  67. package/dist/lib/service-gtm.js +786 -0
  68. package/dist/lib/service-gtm.js.map +1 -0
  69. package/dist/lib/service-mcp-base.d.ts +10 -1
  70. package/dist/lib/service-mcp-base.d.ts.map +1 -1
  71. package/dist/lib/service-mcp-base.js +20 -1
  72. package/dist/lib/service-mcp-base.js.map +1 -1
  73. package/dist/mcp/service-peer-mcp.d.ts +36 -0
  74. package/dist/mcp/service-peer-mcp.d.ts.map +1 -0
  75. package/dist/mcp/service-peer-mcp.js +220 -0
  76. package/dist/mcp/service-peer-mcp.js.map +1 -0
  77. package/dist/mcp/service-registry-mcp.js +0 -0
  78. package/dist/utils/settings-validator.d.ts +4 -1
  79. package/dist/utils/settings-validator.d.ts.map +1 -1
  80. package/dist/utils/settings-validator.js +25 -1
  81. package/dist/utils/settings-validator.js.map +1 -1
  82. package/package.json +2 -1
  83. package/template/.claude/service-settings.json +32 -0
  84. package/template/.claude/settings.json +10 -0
  85. package/template/.claude/skills/end/SKILL.md +1780 -0
  86. package/template/.jfl/config.json +2 -1
  87. package/template/.mcp.json +1 -7
  88. package/template/CLAUDE.md +1042 -248
  89. package/template/CLAUDE.md.bak +1187 -0
  90. package/template/scripts/commit-gtm.sh +56 -0
  91. package/template/scripts/commit-product.sh +68 -0
  92. package/template/scripts/migrate-to-branch-sessions.sh +201 -0
  93. package/template/scripts/session/auto-commit.sh +4 -3
  94. package/template/scripts/session/jfl-doctor.sh +222 -83
  95. package/template/scripts/session/session-cleanup.sh +109 -21
  96. package/template/scripts/session/session-end.sh +26 -13
  97. package/template/scripts/session/session-init.sh +280 -98
  98. package/template/scripts/session/test-critical-infrastructure.sh +293 -0
  99. package/template/scripts/session/test-experience-level.sh +336 -0
  100. package/template/scripts/session/test-session-cleanup.sh +268 -0
  101. package/template/scripts/session/test-session-sync.sh +320 -0
  102. package/template/scripts/where-am-i.sh +78 -0
  103. package/template/templates/service-agent/.claude/settings.json +32 -0
  104. package/template/templates/service-agent/CLAUDE.md +334 -0
  105. package/template/templates/service-agent/knowledge/ARCHITECTURE.md +115 -0
  106. package/template/templates/service-agent/knowledge/DEPLOYMENT.md +199 -0
  107. package/template/templates/service-agent/knowledge/RUNBOOK.md +412 -0
  108. package/template/templates/service-agent/knowledge/SERVICE_SPEC.md +77 -0
  109. package/dist/commands/session-mgmt.d.ts +0 -33
  110. package/dist/commands/session-mgmt.d.ts.map +0 -1
  111. package/dist/commands/session-mgmt.js +0 -404
  112. package/dist/commands/session-mgmt.js.map +0 -1
@@ -3,16 +3,18 @@
3
3
  # session-init.sh - Initialize a JFL session properly
4
4
  #
5
5
  # Called by SessionStart hook. Does:
6
- # 1. Quick health check (warn only)
7
- # 2. Create new session branch
8
- # 3. Start auto-commit
6
+ # 1. Quick doctor check (warn only, don't block)
7
+ # 2. Clean up stale sessions if > 5
8
+ # 3. Create new worktree for this session
9
+ # 4. Output path for Claude to cd into
9
10
  #
10
- # @purpose Session initialization with branch creation
11
+ # @purpose Session initialization with worktree creation
11
12
 
12
13
  set -e
13
14
 
14
15
  SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
15
16
  REPO_DIR="${JFL_REPO_DIR:-$(pwd)}"
17
+ WORKTREES_DIR="$REPO_DIR/worktrees"
16
18
 
17
19
  cd "$REPO_DIR" || exit 1
18
20
 
@@ -32,7 +34,7 @@ echo "━━━━━━━━━━━━━━━━━━━━━━━━
32
34
  echo " JFL Session Init"
33
35
  echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
34
36
 
35
- # Sync repos before creating branch (ensures we start from latest main)
37
+ # Sync repos before creating worktree (ensures worktree is from latest main)
36
38
  if [[ -x "$SCRIPT_DIR/session-sync.sh" ]]; then
37
39
  echo ""
38
40
  "$SCRIPT_DIR/session-sync.sh" || {
@@ -44,125 +46,305 @@ fi
44
46
  # Step 1: Quick health check (warn only)
45
47
  # ==============================================================================
46
48
 
47
- # Check for uncommitted changes on main
48
- if [[ -n $(git status --porcelain 2>/dev/null) ]]; then
49
- echo ""
50
- echo -e "${YELLOW}⚠${NC} Uncommitted changes on main branch"
51
- echo ""
49
+ # Count stale sessions (no PID or PID not running)
50
+ stale_count=0
51
+ active_count=0
52
52
 
53
- # List changed files
54
- git status --short | head -10
53
+ if [[ -d "$WORKTREES_DIR" ]]; then
54
+ for worktree in "$WORKTREES_DIR"/session-*; do
55
+ if [[ -d "$worktree" ]]; then
56
+ pid_file="$worktree/.jfl/auto-commit.pid"
57
+ if [[ -f "$pid_file" ]]; then
58
+ pid=$(cat "$pid_file" 2>/dev/null)
59
+ if [[ -n "$pid" ]] && kill -0 "$pid" 2>/dev/null; then
60
+ active_count=$((active_count + 1))
61
+ continue
62
+ fi
63
+ fi
64
+ stale_count=$((stale_count + 1))
65
+ fi
66
+ done
67
+ fi
55
68
 
56
- echo ""
57
- echo -e "${YELLOW}These changes should be committed before starting a session.${NC}"
58
- echo ""
69
+ # Report status
70
+ if [[ $stale_count -gt 0 ]]; then
71
+ echo -e "${YELLOW}⚠${NC} $stale_count stale sessions, $active_count active"
72
+ else
73
+ echo -e "${GREEN}✓${NC} $active_count active sessions"
74
+ fi
59
75
 
60
- # Check if running non-interactively (hook context)
61
- if [[ ! -t 0 ]]; then
62
- # Non-interactive - auto-commit (safest)
63
- echo "Running non-interactively - auto-committing changes..."
64
- choice="1"
65
- else
66
- # Interactive - ask user
67
- echo "Options:"
68
- echo " 1) Auto-commit and continue"
69
- echo " 2) Skip and continue anyway"
70
- echo " 3) Cancel session start"
71
- echo ""
72
- read -p "Choose [1-3]: " choice
73
- fi
76
+ # ==============================================================================
77
+ # Step 2: Auto-cleanup if too many stale sessions
78
+ # ==============================================================================
74
79
 
75
- case "$choice" in
76
- 1)
77
- echo ""
78
- echo -e "${CYAN}→${NC} Auto-committing changes..."
79
- # Critical paths
80
- git add knowledge/ previews/ content/ suggestions/ CLAUDE.md .jfl/ 2>/dev/null || true
80
+ if [[ $stale_count -gt 5 ]]; then
81
+ echo -e "${YELLOW}→${NC} Cleaning up stale sessions (> 5)..."
82
+ "$SCRIPT_DIR/jfl-doctor.sh" --fix 2>/dev/null | grep -E "^ (Cleaning|✓)" || true
83
+ fi
81
84
 
82
- if git commit -m "auto: pre-session save" 2>/dev/null; then
83
- echo -e " ${GREEN}✓${NC} Changes committed"
84
- git push origin main 2>/dev/null || true
85
+ # ==============================================================================
86
+ # Step 2.5: Crash Reconciliation - Check for uncommitted work in stale sessions
87
+ # ==============================================================================
88
+
89
+ if [[ -d "$WORKTREES_DIR" ]]; then
90
+ worktrees_with_changes=""
91
+ change_count=0
92
+
93
+ for worktree in "$WORKTREES_DIR"/session-*; do
94
+ if [[ -d "$worktree" ]]; then
95
+ # Check if worktree has uncommitted changes
96
+ cd "$worktree"
97
+ if [[ -n $(git status --porcelain 2>/dev/null) ]]; then
98
+ session_name=$(basename "$worktree")
99
+ worktrees_with_changes="$worktrees_with_changes $session_name"
100
+ change_count=$((change_count + 1))
85
101
  fi
86
- ;;
87
- 2)
88
- echo ""
89
- echo -e "${YELLOW}Continuing with uncommitted changes...${NC}"
90
- ;;
91
- 3)
92
- echo ""
93
- echo "Session start cancelled."
94
- exit 1
95
- ;;
96
- *)
102
+ cd "$REPO_DIR"
103
+ fi
104
+ done
105
+
106
+ if [[ $change_count -gt 0 ]]; then
107
+ echo ""
108
+ echo -e "${RED}⚠${NC} Found $change_count session(s) with uncommitted work"
109
+ echo ""
110
+
111
+ for session in $worktrees_with_changes; do
112
+ worktree_path="$WORKTREES_DIR/$session"
113
+ cd "$worktree_path"
114
+ files=$(git status --porcelain | wc -l | tr -d ' ')
115
+ echo " • $session ($files files)"
116
+ cd "$REPO_DIR"
117
+ done
118
+
119
+ echo ""
120
+ echo -e "${YELLOW}This work needs to be saved before continuing.${NC}"
121
+ echo ""
122
+
123
+ # Check if running non-interactively (hook context)
124
+ if [[ ! -t 0 ]]; then
125
+ # Non-interactive - auto-commit (safest)
126
+ echo "Running non-interactively - auto-committing all changes..."
127
+ choice="1"
128
+ else
129
+ # Interactive - ask user
130
+ echo "Options:"
131
+ echo " 1) Auto-commit all and continue (safest - no work lost)"
132
+ echo " 2) Show me the changes (for review)"
133
+ echo " 3) Skip for now (manual cleanup)"
97
134
  echo ""
98
- echo -e "${RED}Invalid choice. Continuing anyway.${NC}"
99
- ;;
100
- esac
135
+ read -p "Choose [1-3]: " choice
136
+ fi
137
+
138
+ case "$choice" in
139
+ 1)
140
+ echo ""
141
+ echo -e "${CYAN}→${NC} Auto-committing all changes..."
142
+ for session in $worktrees_with_changes; do
143
+ worktree_path="$WORKTREES_DIR/$session"
144
+ cd "$worktree_path"
145
+
146
+ if [[ -n $(git status --porcelain 2>/dev/null) ]]; then
147
+ # Critical paths
148
+ git add knowledge/ previews/ content/ suggestions/ CLAUDE.md .jfl/ 2>/dev/null || true
149
+
150
+ if git commit -m "crash recovery: auto-save uncommitted work from $session" 2>/dev/null; then
151
+ echo -e " ${GREEN}✓${NC} $session - committed and saved"
152
+ git push origin "$(git branch --show-current)" 2>/dev/null || true
153
+ fi
154
+ fi
155
+
156
+ cd "$REPO_DIR"
157
+ done
158
+ echo ""
159
+ echo -e "${GREEN}✓${NC} All changes saved. Continuing..."
160
+ ;;
161
+ 2)
162
+ echo ""
163
+ for session in $worktrees_with_changes; do
164
+ worktree_path="$WORKTREES_DIR/$session"
165
+ echo "─────────────────────────────────────"
166
+ echo "$session:"
167
+ echo ""
168
+ cd "$worktree_path"
169
+ git status --short
170
+ cd "$REPO_DIR"
171
+ echo ""
172
+ done
173
+ echo "─────────────────────────────────────"
174
+ echo ""
175
+ read -p "Commit these changes? [y/N]: " commit_choice
176
+ if [[ "$commit_choice" =~ ^[Yy]$ ]]; then
177
+ for session in $worktrees_with_changes; do
178
+ worktree_path="$WORKTREES_DIR/$session"
179
+ cd "$worktree_path"
180
+ git add knowledge/ previews/ content/ suggestions/ CLAUDE.md .jfl/ 2>/dev/null || true
181
+ git commit -m "crash recovery: manual save from $session" 2>/dev/null || true
182
+ git push origin "$(git branch --show-current)" 2>/dev/null || true
183
+ cd "$REPO_DIR"
184
+ done
185
+ echo -e "${GREEN}✓${NC} Changes committed"
186
+ fi
187
+ ;;
188
+ 3)
189
+ echo ""
190
+ echo -e "${YELLOW}Skipping crash recovery.${NC}"
191
+ echo "You can manually handle these sessions later."
192
+ echo ""
193
+ ;;
194
+ *)
195
+ echo ""
196
+ echo -e "${RED}Invalid choice. Skipping.${NC}"
197
+ ;;
198
+ esac
199
+ fi
101
200
  fi
102
201
 
103
202
  # ==============================================================================
104
- # Step 2: Create new session branch
203
+ # Step 2.9: Check for concurrent sessions via jfl-services
105
204
  # ==============================================================================
106
205
 
107
- # Generate session name with collision protection
206
+ # Generate session details first
108
207
  user=$(git config user.name 2>/dev/null | tr ' ' '-' | tr '[:upper:]' '[:lower:]' | tr -cd 'a-z0-9-' || echo "user")
109
- # Truncate long usernames to prevent issues
110
208
  user="${user:0:30}"
111
209
  date_str=$(date +%Y%m%d)
112
210
  time_str=$(date +%H%M)
211
+ random_id=$(openssl rand -hex 3 2>/dev/null || printf "%06x" $RANDOM$RANDOM)
212
+ session_name="session-${user}-${date_str}-${time_str}-${random_id}"
113
213
 
114
- # Generate unique session name, retry if collision detected
115
- max_attempts=5
116
- attempt=0
117
- while [[ $attempt -lt $max_attempts ]]; do
118
- random_id=$(openssl rand -hex 3 2>/dev/null || printf "%06x" $RANDOM$RANDOM)
119
- session_name="session-${user}-${date_str}-${time_str}-${random_id}"
120
-
121
- # Check for collision: journal file or branch already exists
122
- if [[ -f "$REPO_DIR/.jfl/journal/${session_name}.jsonl" ]] || git rev-parse --verify "$session_name" >/dev/null 2>&1; then
123
- echo -e "${YELLOW}⚠${NC} Session name collision, regenerating..."
124
- attempt=$((attempt + 1))
125
- sleep 0.1 # Brief pause before retry
126
- else
127
- break
128
- fi
129
- done
130
-
131
- if [[ $attempt -ge $max_attempts ]]; then
132
- echo -e "${RED}✗${NC} Failed to generate unique session name after $max_attempts attempts"
133
- exit 1
214
+ # Get working branch (from config or current branch)
215
+ working_branch=$(jq -r '.working_branch // empty' .jfl/config.json 2>/dev/null)
216
+ if [[ -z "$working_branch" ]]; then
217
+ working_branch=$(git branch --show-current)
134
218
  fi
135
219
 
136
- echo ""
137
- echo "Creating session: $session_name"
220
+ # Check for concurrent sessions via jfl-services API
221
+ use_worktree=false
222
+ api_response=""
223
+ if command -v curl >/dev/null 2>&1; then
224
+ api_response=$(curl -s -X GET "http://localhost:3401/sessions/active?projectPath=$(pwd)" 2>/dev/null || echo "")
225
+
226
+ if [[ -n "$api_response" ]] && echo "$api_response" | jq -e '.count' >/dev/null 2>&1; then
227
+ session_count=$(echo "$api_response" | jq -r '.count // 0')
138
228
 
139
- # Create session branch from main
140
- if git checkout -b "$session_name" 2>&1 | head -3; then
141
- echo -e "${GREEN}✓${NC} Session branch created"
229
+ if [[ $session_count -gt 0 ]]; then
230
+ use_worktree=true
231
+ echo -e "${YELLOW}→${NC} Multiple sessions detected ($session_count active) - using worktree for isolation"
232
+ else
233
+ echo -e "${GREEN}→${NC} Single session - working directly on branch $working_branch"
234
+ fi
235
+ else
236
+ # API unavailable - fall back to local detection
237
+ echo -e "${YELLOW}→${NC} jfl-services unavailable - checking locally..."
238
+ local_sessions=$(ps aux | grep -c "claude.*$(pwd)" 2>/dev/null || echo "1")
239
+ if [[ $local_sessions -gt 2 ]]; then
240
+ use_worktree=true
241
+ echo -e "${YELLOW}→${NC} Multiple processes detected - using worktree for isolation"
242
+ fi
243
+ fi
142
244
  else
143
- echo -e "${RED}✗${NC} Failed to create session branch"
144
- exit 1
245
+ # No curl - assume single session
246
+ echo -e "${GREEN}→${NC} Working directly on branch $working_branch"
145
247
  fi
146
248
 
147
- # Create session directories
148
- mkdir -p .jfl/logs
149
- mkdir -p .jfl/journal
150
-
151
- # Start auto-commit in background
152
- if [[ -x "$SCRIPT_DIR/auto-commit.sh" ]]; then
153
- "$SCRIPT_DIR/auto-commit.sh" start >> .jfl/logs/auto-commit.log 2>&1 &
154
- echo -e "${GREEN}✓${NC} Auto-commit started"
249
+ # Register this session with jfl-services
250
+ if command -v curl >/dev/null 2>&1; then
251
+ curl -s -X POST "http://localhost:3401/sessions/start" \
252
+ -H "Content-Type: application/json" \
253
+ -d "{\"id\":\"$session_name\",\"projectPath\":\"$(pwd)\",\"branch\":\"$working_branch\",\"user\":\"$user\",\"pid\":$$,\"worktree\":\"$use_worktree\"}" \
254
+ >/dev/null 2>&1 || true
155
255
  fi
156
256
 
157
257
  # ==============================================================================
158
- # Step 3: Save state and output instructions
258
+ # Step 3: Create worktree (if needed) or work directly
159
259
  # ==============================================================================
160
260
 
161
- # Save session name
162
- echo "$session_name" > "$REPO_DIR/.jfl/current-session-branch.txt"
261
+ if [[ "$use_worktree" == "true" ]]; then
262
+ # WORKTREE MODE: Multiple sessions detected
263
+ echo ""
264
+ echo "Creating worktree session: $session_name"
163
265
 
164
- echo ""
165
- echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
166
- echo -e " ${CYAN}Session:${NC} $session_name"
167
- echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
168
- echo ""
266
+ worktree_path="$WORKTREES_DIR/$session_name"
267
+
268
+ # Create worktree
269
+ if git worktree add "$worktree_path" -b "$session_name" 2>&1 | head -3; then
270
+ echo -e "${GREEN}✓${NC} Worktree created"
271
+ else
272
+ echo -e "${RED}✗${NC} Failed to create worktree"
273
+ # Fall back to direct branch mode
274
+ use_worktree=false
275
+ fi
276
+
277
+ if [[ "$use_worktree" == "true" ]]; then
278
+ # Initialize submodules in worktree (quick, no network)
279
+ cd "$worktree_path"
280
+ if [[ -f ".gitmodules" ]]; then
281
+ if [[ ! -d "product/.git" ]] && [[ ! -f "product/.git" ]]; then
282
+ echo "→ Initializing submodules..."
283
+ git submodule update --init --depth 1 product 2>/dev/null || true
284
+ fi
285
+ fi
286
+
287
+ # Create session directories
288
+ mkdir -p .jfl/logs
289
+
290
+ # CRITICAL: Symlink journal to main repo so entries persist after worktree cleanup
291
+ rm -rf .jfl/journal 2>/dev/null || true
292
+ ln -sf "$REPO_DIR/.jfl/journal" .jfl/journal
293
+ echo -e "${GREEN}✓${NC} Journal symlinked to main repo"
294
+
295
+ # Start auto-commit in background
296
+ if [[ -x "$SCRIPT_DIR/auto-commit.sh" ]]; then
297
+ "$SCRIPT_DIR/auto-commit.sh" start >> .jfl/logs/auto-commit.log 2>&1 &
298
+ echo -e "${GREEN}✓${NC} Auto-commit started"
299
+ fi
300
+
301
+ cd "$REPO_DIR"
302
+
303
+ # Save paths
304
+ echo "$worktree_path" > "$REPO_DIR/.jfl/current-worktree.txt"
305
+ echo "$session_name" > "$REPO_DIR/.jfl/current-session-branch.txt"
306
+ echo "$session_name" > "$worktree_path/.jfl/current-session-branch.txt"
307
+
308
+ echo ""
309
+ echo -e "${GREEN}✓${NC} Session ready in worktree: $worktree_path"
310
+ echo ""
311
+ fi
312
+ fi
313
+
314
+ if [[ "$use_worktree" != "true" ]]; then
315
+ # DIRECT MODE: Single session, work on current branch
316
+ echo ""
317
+ echo "Direct session mode: $session_name"
318
+
319
+ # Ensure we're on working branch
320
+ current_branch=$(git branch --show-current)
321
+ if [[ "$current_branch" != "$working_branch" ]]; then
322
+ echo "→ Switching to working branch: $working_branch"
323
+ git checkout "$working_branch" 2>&1 | head -3
324
+ fi
325
+
326
+ # Create session branch from working branch
327
+ if git checkout -b "$session_name" 2>&1 | head -3; then
328
+ echo -e "${GREEN}✓${NC} Session branch created: $session_name"
329
+ else
330
+ echo -e "${YELLOW}⚠${NC} Continuing on branch: $current_branch"
331
+ session_name="$current_branch"
332
+ fi
333
+
334
+ # Create session directories
335
+ mkdir -p .jfl/logs
336
+
337
+ # Start auto-commit in background
338
+ if [[ -x "$SCRIPT_DIR/auto-commit.sh" ]]; then
339
+ "$SCRIPT_DIR/auto-commit.sh" start >> .jfl/logs/auto-commit.log 2>&1 &
340
+ echo -e "${GREEN}✓${NC} Auto-commit started"
341
+ fi
342
+
343
+ # Save session info (no worktree path in direct mode)
344
+ echo "direct" > "$REPO_DIR/.jfl/current-worktree.txt"
345
+ echo "$session_name" > "$REPO_DIR/.jfl/current-session-branch.txt"
346
+
347
+ echo ""
348
+ echo -e "${GREEN}✓${NC} Session ready on branch: $session_name"
349
+ echo ""
350
+ fi