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.
- package/README.md +77 -7
- package/clawdbot-plugin/clawdbot.plugin.json +20 -0
- package/clawdbot-plugin/index.js +555 -0
- package/clawdbot-plugin/index.ts +582 -0
- package/clawdbot-skill/SKILL.md +33 -336
- package/clawdbot-skill/index.ts +491 -321
- package/clawdbot-skill/skill.json +4 -13
- package/dist/commands/clawdbot.d.ts +11 -0
- package/dist/commands/clawdbot.d.ts.map +1 -0
- package/dist/commands/clawdbot.js +215 -0
- package/dist/commands/clawdbot.js.map +1 -0
- package/dist/commands/gtm-process-update.d.ts +10 -0
- package/dist/commands/gtm-process-update.d.ts.map +1 -0
- package/dist/commands/gtm-process-update.js +101 -0
- package/dist/commands/gtm-process-update.js.map +1 -0
- package/dist/commands/onboard.d.ts.map +1 -1
- package/dist/commands/onboard.js +203 -15
- package/dist/commands/onboard.js.map +1 -1
- package/dist/commands/openclaw.d.ts +56 -0
- package/dist/commands/openclaw.d.ts.map +1 -0
- package/dist/commands/openclaw.js +700 -0
- package/dist/commands/openclaw.js.map +1 -0
- package/dist/commands/service-validate.d.ts +12 -0
- package/dist/commands/service-validate.d.ts.map +1 -0
- package/dist/commands/service-validate.js +611 -0
- package/dist/commands/service-validate.js.map +1 -0
- package/dist/commands/services-create.d.ts +15 -0
- package/dist/commands/services-create.d.ts.map +1 -0
- package/dist/commands/services-create.js +1452 -0
- package/dist/commands/services-create.js.map +1 -0
- package/dist/commands/services-sync-agents.d.ts +23 -0
- package/dist/commands/services-sync-agents.d.ts.map +1 -0
- package/dist/commands/services-sync-agents.js +207 -0
- package/dist/commands/services-sync-agents.js.map +1 -0
- package/dist/commands/services.d.ts +7 -1
- package/dist/commands/services.d.ts.map +1 -1
- package/dist/commands/services.js +347 -22
- package/dist/commands/services.js.map +1 -1
- package/dist/commands/update.js +0 -0
- package/dist/commands/validate-settings.d.ts +37 -0
- package/dist/commands/validate-settings.d.ts.map +1 -0
- package/dist/commands/validate-settings.js +197 -0
- package/dist/commands/validate-settings.js.map +1 -0
- package/dist/index.js +155 -60
- package/dist/index.js.map +1 -1
- package/dist/lib/agent-generator.d.ts.map +1 -1
- package/dist/lib/agent-generator.js +94 -1
- package/dist/lib/agent-generator.js.map +1 -1
- package/dist/lib/openclaw-registry.d.ts +48 -0
- package/dist/lib/openclaw-registry.d.ts.map +1 -0
- package/dist/lib/openclaw-registry.js +181 -0
- package/dist/lib/openclaw-registry.js.map +1 -0
- package/dist/lib/openclaw-sdk.d.ts +107 -0
- package/dist/lib/openclaw-sdk.d.ts.map +1 -0
- package/dist/lib/openclaw-sdk.js +208 -0
- package/dist/lib/openclaw-sdk.js.map +1 -0
- package/dist/lib/peer-agent-generator.d.ts +44 -0
- package/dist/lib/peer-agent-generator.d.ts.map +1 -0
- package/dist/lib/peer-agent-generator.js +286 -0
- package/dist/lib/peer-agent-generator.js.map +1 -0
- package/dist/lib/service-detector.d.ts +1 -1
- package/dist/lib/service-detector.d.ts.map +1 -1
- package/dist/lib/service-detector.js +118 -5
- package/dist/lib/service-detector.js.map +1 -1
- package/dist/lib/service-gtm.d.ts +157 -0
- package/dist/lib/service-gtm.d.ts.map +1 -0
- package/dist/lib/service-gtm.js +786 -0
- package/dist/lib/service-gtm.js.map +1 -0
- package/dist/lib/service-mcp-base.d.ts +10 -1
- package/dist/lib/service-mcp-base.d.ts.map +1 -1
- package/dist/lib/service-mcp-base.js +20 -1
- package/dist/lib/service-mcp-base.js.map +1 -1
- package/dist/mcp/service-peer-mcp.d.ts +36 -0
- package/dist/mcp/service-peer-mcp.d.ts.map +1 -0
- package/dist/mcp/service-peer-mcp.js +220 -0
- package/dist/mcp/service-peer-mcp.js.map +1 -0
- package/dist/mcp/service-registry-mcp.js +0 -0
- package/dist/utils/settings-validator.d.ts +4 -1
- package/dist/utils/settings-validator.d.ts.map +1 -1
- package/dist/utils/settings-validator.js +25 -1
- package/dist/utils/settings-validator.js.map +1 -1
- package/package.json +2 -1
- package/template/.claude/service-settings.json +32 -0
- package/template/.claude/settings.json +10 -0
- package/template/.claude/skills/end/SKILL.md +1780 -0
- package/template/.jfl/config.json +2 -1
- package/template/.mcp.json +1 -7
- package/template/CLAUDE.md +1042 -248
- package/template/CLAUDE.md.bak +1187 -0
- package/template/scripts/commit-gtm.sh +56 -0
- package/template/scripts/commit-product.sh +68 -0
- package/template/scripts/migrate-to-branch-sessions.sh +201 -0
- package/template/scripts/session/auto-commit.sh +4 -3
- package/template/scripts/session/jfl-doctor.sh +222 -83
- package/template/scripts/session/session-cleanup.sh +109 -21
- package/template/scripts/session/session-end.sh +26 -13
- package/template/scripts/session/session-init.sh +280 -98
- package/template/scripts/session/test-critical-infrastructure.sh +293 -0
- package/template/scripts/session/test-experience-level.sh +336 -0
- package/template/scripts/session/test-session-cleanup.sh +268 -0
- package/template/scripts/session/test-session-sync.sh +320 -0
- package/template/scripts/where-am-i.sh +78 -0
- package/template/templates/service-agent/.claude/settings.json +32 -0
- package/template/templates/service-agent/CLAUDE.md +334 -0
- package/template/templates/service-agent/knowledge/ARCHITECTURE.md +115 -0
- package/template/templates/service-agent/knowledge/DEPLOYMENT.md +199 -0
- package/template/templates/service-agent/knowledge/RUNBOOK.md +412 -0
- package/template/templates/service-agent/knowledge/SERVICE_SPEC.md +77 -0
- package/dist/commands/session-mgmt.d.ts +0 -33
- package/dist/commands/session-mgmt.d.ts.map +0 -1
- package/dist/commands/session-mgmt.js +0 -404
- 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
|
|
7
|
-
# 2.
|
|
8
|
-
# 3.
|
|
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
|
|
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
|
|
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
|
-
#
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
54
|
-
|
|
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
|
-
|
|
57
|
-
|
|
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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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:
|
|
203
|
+
# Step 2.9: Check for concurrent sessions via jfl-services
|
|
105
204
|
# ==============================================================================
|
|
106
205
|
|
|
107
|
-
# Generate session
|
|
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
|
-
#
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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
|
-
|
|
137
|
-
|
|
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
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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
|
-
|
|
144
|
-
|
|
245
|
+
# No curl - assume single session
|
|
246
|
+
echo -e "${GREEN}→${NC} Working directly on branch $working_branch"
|
|
145
247
|
fi
|
|
146
248
|
|
|
147
|
-
#
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
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:
|
|
258
|
+
# Step 3: Create worktree (if needed) or work directly
|
|
159
259
|
# ==============================================================================
|
|
160
260
|
|
|
161
|
-
|
|
162
|
-
|
|
261
|
+
if [[ "$use_worktree" == "true" ]]; then
|
|
262
|
+
# WORKTREE MODE: Multiple sessions detected
|
|
263
|
+
echo ""
|
|
264
|
+
echo "Creating worktree session: $session_name"
|
|
163
265
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
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
|