jettypod 4.4.66 → 4.4.67

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/jettypod.js CHANGED
@@ -1294,18 +1294,26 @@ switch (command) {
1294
1294
  }
1295
1295
  } else if (subcommand === 'cleanup') {
1296
1296
  const workCommands = require('./lib/work-commands/index.js');
1297
- const dryRun = args[0] === '--dry-run';
1297
+ const dryRun = args.includes('--dry-run');
1298
+ // Find numeric arg for specific work item cleanup
1299
+ const workItemId = args.find(a => /^\d+$/.test(a)) ? parseInt(args.find(a => /^\d+$/.test(a))) : null;
1298
1300
 
1299
1301
  try {
1300
- const results = await workCommands.cleanupWorktrees({ dryRun });
1301
-
1302
- if (results.cleaned === 0 && results.failed === 0) {
1303
- console.log(`\n${results.message || 'No worktrees needed cleanup'}`);
1302
+ if (workItemId) {
1303
+ // Clean up specific work item's worktree
1304
+ await workCommands.cleanupWorkItem(workItemId);
1304
1305
  } else {
1305
- console.log(`\n✓ Cleanup complete:`);
1306
- console.log(` Cleaned: ${results.cleaned}`);
1307
- if (results.failed > 0) {
1308
- console.log(` Failed: ${results.failed}`);
1306
+ // Batch cleanup of all orphaned worktrees
1307
+ const results = await workCommands.cleanupWorktrees({ dryRun });
1308
+
1309
+ if (results.cleaned === 0 && results.failed === 0) {
1310
+ console.log(`\n${results.message || 'No worktrees needed cleanup'}`);
1311
+ } else {
1312
+ console.log(`\n✓ Cleanup complete:`);
1313
+ console.log(` Cleaned: ${results.cleaned}`);
1314
+ if (results.failed > 0) {
1315
+ console.log(` Failed: ${results.failed}`);
1316
+ }
1309
1317
  }
1310
1318
  }
1311
1319
  } catch (err) {
@@ -1130,6 +1130,106 @@ async function cleanupWorktrees(options = {}) {
1130
1130
  return results;
1131
1131
  }
1132
1132
 
1133
+ /**
1134
+ * Clean up a specific worktree after merge
1135
+ * Should be run from main repo after cd'ing out of the worktree
1136
+ * @param {number} workItemId - The work item ID to clean up
1137
+ * @returns {Promise<Object>} Result with success status
1138
+ */
1139
+ async function cleanupWorkItem(workItemId) {
1140
+ const db = getDb();
1141
+ const gitRoot = getGitRoot();
1142
+
1143
+ // Check we're not inside the worktree being deleted
1144
+ const cwd = process.cwd();
1145
+ if (cwd.includes('.jettypod-work')) {
1146
+ return Promise.reject(new Error(
1147
+ `Cannot cleanup from inside a worktree.\n\n` +
1148
+ `Run this first: cd ${gitRoot}`
1149
+ ));
1150
+ }
1151
+
1152
+ // Find the worktree for this work item
1153
+ const worktree = await new Promise((resolve, reject) => {
1154
+ db.get(
1155
+ `SELECT w.id, w.worktree_path, w.branch_name, w.status, wi.title
1156
+ FROM worktrees w
1157
+ JOIN work_items wi ON w.work_item_id = wi.id
1158
+ WHERE w.work_item_id = ?`,
1159
+ [workItemId],
1160
+ (err, row) => {
1161
+ if (err) return reject(err);
1162
+ resolve(row);
1163
+ }
1164
+ );
1165
+ });
1166
+
1167
+ if (!worktree) {
1168
+ console.log(`No worktree found for work item #${workItemId}`);
1169
+ return { success: true, message: 'No worktree to clean up' };
1170
+ }
1171
+
1172
+ if (worktree.status === 'active') {
1173
+ return Promise.reject(new Error(
1174
+ `Worktree for #${workItemId} is still active.\n` +
1175
+ `Run 'jettypod work merge ${workItemId}' first.`
1176
+ ));
1177
+ }
1178
+
1179
+ console.log(`Cleaning up worktree for #${workItemId}: ${worktree.title}`);
1180
+
1181
+ // Remove git worktree if it exists
1182
+ if (worktree.worktree_path && fs.existsSync(worktree.worktree_path)) {
1183
+ try {
1184
+ execSync(`git worktree remove "${worktree.worktree_path}" --force`, {
1185
+ cwd: gitRoot,
1186
+ stdio: 'pipe'
1187
+ });
1188
+ console.log('✅ Removed worktree directory');
1189
+ } catch (err) {
1190
+ console.log(`⚠️ Failed to remove worktree directory: ${err.message}`);
1191
+ }
1192
+ }
1193
+
1194
+ // Delete the branch if it exists
1195
+ if (worktree.branch_name) {
1196
+ try {
1197
+ execSync(`git branch -d "${worktree.branch_name}"`, {
1198
+ cwd: gitRoot,
1199
+ stdio: 'pipe'
1200
+ });
1201
+ console.log('✅ Deleted branch');
1202
+ } catch (err) {
1203
+ // Branch might not exist or might not be fully merged
1204
+ // Try force delete if regular delete failed
1205
+ try {
1206
+ execSync(`git branch -D "${worktree.branch_name}"`, {
1207
+ cwd: gitRoot,
1208
+ stdio: 'pipe'
1209
+ });
1210
+ console.log('✅ Deleted branch (force)');
1211
+ } catch {
1212
+ console.log(`⚠️ Could not delete branch: ${err.message}`);
1213
+ }
1214
+ }
1215
+ }
1216
+
1217
+ // Delete worktree record from database
1218
+ await new Promise((resolve, reject) => {
1219
+ db.run(
1220
+ `DELETE FROM worktrees WHERE id = ?`,
1221
+ [worktree.id],
1222
+ (err) => {
1223
+ if (err) return reject(err);
1224
+ resolve();
1225
+ }
1226
+ );
1227
+ });
1228
+
1229
+ console.log('✅ Worktree cleaned up');
1230
+ return { success: true };
1231
+ }
1232
+
1133
1233
  // Re-export getCurrentWork from shared module for backwards compatibility
1134
1234
  // (used by jettypod.js)
1135
1235
 
@@ -1590,49 +1690,32 @@ async function mergeWork(options = {}) {
1590
1690
  );
1591
1691
  });
1592
1692
 
1593
- // Clean up worktree if it exists
1594
- if (worktree && worktree.worktree_path && fs.existsSync(worktree.worktree_path)) {
1595
- // Check if shell CWD is inside the worktree being deleted
1596
- const shellCwd = process.cwd();
1597
- const worktreePath = path.resolve(worktree.worktree_path);
1598
- const cwdWillBeInvalid = shellCwd.startsWith(worktreePath);
1599
-
1600
- console.log('Cleaning up worktree...');
1601
- try {
1602
- // Remove the git worktree
1603
- execSync(`git worktree remove "${worktree.worktree_path}" --force`, {
1604
- cwd: gitRoot,
1605
- stdio: 'pipe'
1606
- });
1607
-
1608
- // Delete worktree record from database
1609
- await new Promise((resolve, reject) => {
1610
- db.run(
1611
- `DELETE FROM worktrees WHERE id = ?`,
1612
- [worktree.id],
1613
- (err) => {
1614
- if (err) return reject(err);
1615
- resolve();
1616
- }
1617
- );
1618
- });
1619
-
1620
- console.log('✅ Worktree cleaned up');
1621
-
1622
- // Warn if shell CWD was inside deleted worktree
1623
- if (cwdWillBeInvalid) {
1624
- console.log('');
1625
- console.log('⚠️ Your shell was inside the deleted worktree.');
1626
- console.log(` Run this to fix: cd ${gitRoot}`);
1627
- }
1628
- } catch (worktreeErr) {
1629
- console.warn(`Warning: Failed to clean up worktree: ${worktreeErr.message}`);
1630
- // Non-fatal - continue with merge success
1631
- }
1693
+ // Mark worktree as merged but DON'T delete it yet
1694
+ // This prevents shell CWD corruption when merge is run from inside the worktree
1695
+ // User must run `jettypod work cleanup` separately after cd'ing to main repo
1696
+ if (worktree && worktree.worktree_path) {
1697
+ await new Promise((resolve, reject) => {
1698
+ db.run(
1699
+ `UPDATE worktrees SET status = 'merged' WHERE id = ?`,
1700
+ [worktree.id],
1701
+ (err) => {
1702
+ if (err) return reject(err);
1703
+ resolve();
1704
+ }
1705
+ );
1706
+ });
1632
1707
  }
1633
1708
 
1634
1709
  console.log(`✅ Work item #${currentWork.id} marked as done`);
1635
1710
 
1711
+ // Instruct user to cleanup worktree separately
1712
+ if (worktree && worktree.worktree_path && fs.existsSync(worktree.worktree_path)) {
1713
+ console.log('');
1714
+ console.log('📁 Worktree preserved. To clean up:');
1715
+ console.log(` cd ${gitRoot}`);
1716
+ console.log(` jettypod work cleanup ${currentWork.id}`);
1717
+ }
1718
+
1636
1719
  if (withTransition) {
1637
1720
  // Hold lock for transition phase (BDD generation)
1638
1721
  // Work is done and worktree is cleaned up, but lock is held so no other merges
@@ -1897,46 +1980,11 @@ async function testsMerge(featureId) {
1897
1980
  console.log('⚠️ Failed to push (non-fatal):', err.message);
1898
1981
  }
1899
1982
 
1900
- // Clean up the worktree
1901
- // Check if shell CWD is inside the worktree being deleted
1902
- const shellCwd = process.cwd();
1903
- const resolvedWorktreePath = path.resolve(worktreePath);
1904
- const cwdWillBeInvalid = shellCwd.startsWith(resolvedWorktreePath);
1905
-
1906
- try {
1907
- execSync(`git worktree remove "${worktreePath}" --force`, {
1908
- cwd: gitRoot,
1909
- encoding: 'utf8',
1910
- stdio: 'pipe'
1911
- });
1912
- console.log('✅ Removed worktree directory');
1913
-
1914
- // Warn if shell CWD was inside deleted worktree
1915
- if (cwdWillBeInvalid) {
1916
- console.log('');
1917
- console.log('⚠️ Your shell was inside the deleted worktree.');
1918
- console.log(` Run this to fix: cd ${gitRoot}`);
1919
- }
1920
- } catch (err) {
1921
- console.log('⚠️ Failed to remove worktree (non-fatal):', err.message);
1922
- }
1923
-
1924
- // Delete the test branch
1925
- try {
1926
- execSync(`git branch -d ${branchName}`, {
1927
- cwd: gitRoot,
1928
- encoding: 'utf8',
1929
- stdio: 'pipe'
1930
- });
1931
- console.log('✅ Deleted test branch');
1932
- } catch (err) {
1933
- console.log('⚠️ Failed to delete branch (non-fatal):', err.message);
1934
- }
1935
-
1936
- // Delete worktree record from database (cleanup complete)
1983
+ // Mark worktree as merged but DON'T delete it yet
1984
+ // This prevents shell CWD corruption when merge is run from inside the worktree
1937
1985
  await new Promise((resolve, reject) => {
1938
1986
  db.run(
1939
- `DELETE FROM worktrees WHERE id = ?`,
1987
+ `UPDATE worktrees SET status = 'merged' WHERE id = ?`,
1940
1988
  [worktree.id],
1941
1989
  (err) => {
1942
1990
  if (err) return reject(err);
@@ -1954,6 +2002,14 @@ async function testsMerge(featureId) {
1954
2002
  console.log('');
1955
2003
  console.log(`✅ Test worktree for feature #${featureId} merged successfully`);
1956
2004
 
2005
+ // Instruct user to cleanup worktree separately
2006
+ if (fs.existsSync(worktreePath)) {
2007
+ console.log('');
2008
+ console.log('📁 Worktree preserved. To clean up:');
2009
+ console.log(` cd ${gitRoot}`);
2010
+ console.log(` jettypod work cleanup ${featureId}`);
2011
+ }
2012
+
1957
2013
  return Promise.resolve();
1958
2014
  }
1959
2015
 
@@ -1962,6 +2018,7 @@ module.exports = {
1962
2018
  stopWork,
1963
2019
  getCurrentWork,
1964
2020
  cleanupWorktrees,
2021
+ cleanupWorkItem,
1965
2022
  mergeWork,
1966
2023
  testsWork,
1967
2024
  testsMerge
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jettypod",
3
- "version": "4.4.66",
3
+ "version": "4.4.67",
4
4
  "description": "AI-powered development workflow manager with TDD, BDD, and automatic test generation",
5
5
  "main": "jettypod.js",
6
6
  "bin": {
@@ -373,22 +373,23 @@ git commit -m "chore: [brief description]"
373
373
  git push
374
374
  ```
375
375
 
376
- **🚨 CRITICAL: Shell CWD Corruption Prevention**
376
+ **Merge and cleanup (3 steps):**
377
377
 
378
- The merge will delete the worktree. You must be in the main repo BEFORE merging.
378
+ ```bash
379
+ # Step 1: Merge (can run from worktree - it won't delete it)
380
+ jettypod work merge [chore-id]
381
+ ```
379
382
 
380
383
  ```bash
381
- # First, cd to the main repo (worktrees are in .jettypod-work/ inside main repo)
384
+ # Step 2: cd to main repo
382
385
  cd /path/to/main/repo
383
-
384
- # Verify you're in the main repo
385
- pwd && ls .jettypod
386
-
387
- # Then merge (pass the work item ID explicitly)
388
- jettypod work merge [chore-id]
386
+ pwd && ls .jettypod # verify
389
387
  ```
390
388
 
391
- **Why not `cd $(git rev-parse --show-toplevel)/..`?** Inside a worktree, `--show-toplevel` returns the worktree path, not the main repo. Going `..` from there doesn't reach the main repo.
389
+ ```bash
390
+ # Step 3: Clean up the worktree (now safe since shell is in main repo)
391
+ jettypod work cleanup [chore-id]
392
+ ```
392
393
 
393
394
  **Display:**
394
395
 
@@ -653,8 +653,10 @@ Write your BDD files to:
653
653
  <worktree>/features/email-login.feature
654
654
  <worktree>/features/step_definitions/email-login.steps.js
655
655
 
656
- When done, cd to main repo and merge:
657
- cd /path/to/main/repo && jettypod work tests merge 42
656
+ When done, merge then cleanup:
657
+ jettypod work tests merge 42
658
+ cd /path/to/main/repo
659
+ jettypod work cleanup 42
658
660
  ```
659
661
 
660
662
  **🛑 STOP AND CHECK:** Verify worktree was created successfully. If you see an error, investigate before continuing.
@@ -613,28 +613,25 @@ More speed mode chores remain. Starting next chore:
613
613
 
614
614
  **Merge and start next:**
615
615
 
616
- **🚨 CRITICAL: Shell CWD Corruption Prevention**
617
-
618
- The merge will delete the worktree. You must be in the main repo BEFORE merging.
619
-
620
616
  ```bash
621
617
  # Commit changes in the worktree
622
618
  git add . && git commit -m "feat: [brief description of what was implemented]"
623
619
  ```
624
620
 
625
621
  ```bash
626
- # cd to the main repo first (worktrees are in .jettypod-work/ inside main repo)
627
- cd /path/to/main/repo
628
-
629
- # Verify you're in the main repo
630
- pwd && ls .jettypod
631
-
632
- # Then merge
622
+ # Step 1: Merge (can run from worktree - it won't delete it)
633
623
  jettypod work merge [current-chore-id]
634
624
  ```
635
625
 
636
626
  ```bash
637
- # Start next chore
627
+ # Step 2: cd to main repo
628
+ cd /path/to/main/repo
629
+ pwd && ls .jettypod # verify
630
+ ```
631
+
632
+ ```bash
633
+ # Step 3: Clean up the worktree, then start next chore
634
+ jettypod work cleanup [current-chore-id]
638
635
  jettypod work start [next-chore-id]
639
636
  ```
640
637
 
@@ -674,29 +671,28 @@ npx cucumber-js <scenario-file-path> --name "User can reach" --format progress
674
671
 
675
672
  #### Step 7B: Merge Final Speed Chore
676
673
 
677
- **🚨 CRITICAL: Shell CWD Corruption Prevention**
678
-
679
- The merge will delete the worktree. You must be in the main repo BEFORE merging.
680
-
681
674
  ```bash
682
675
  # Commit changes in the worktree
683
676
  git add . && git commit -m "feat: [brief description of what was implemented]"
684
677
  ```
685
678
 
686
679
  ```bash
687
- # cd to the main repo first (worktrees are in .jettypod-work/ inside main repo)
688
- cd /path/to/main/repo
689
-
690
- # Verify you're in the main repo
691
- pwd && ls .jettypod
692
-
693
- # Then merge with transition flag
680
+ # Step 1: Merge with transition flag (can run from worktree - it won't delete it)
694
681
  jettypod work merge [current-chore-id] --with-transition
695
682
  ```
696
683
 
697
- **Why not `cd $(git rev-parse --show-toplevel)/..`?** Inside a worktree, `--show-toplevel` returns the worktree path, not the main repo. Going `..` from there doesn't reach the main repo.
684
+ ```bash
685
+ # Step 2: cd to main repo
686
+ cd /path/to/main/repo
687
+ pwd && ls .jettypod # verify
688
+ ```
689
+
690
+ ```bash
691
+ # Step 3: Clean up the worktree
692
+ jettypod work cleanup [current-chore-id]
693
+ ```
698
694
 
699
- After merge, you are on main branch. Ready to generate stable mode scenarios.
695
+ After cleanup, you are on main branch. Ready to generate stable mode scenarios.
700
696
 
701
697
  #### Step 7C: Generate and Propose Stable Mode Chores
702
698
 
@@ -572,28 +572,25 @@ More stable mode chores remain. Starting next chore:
572
572
 
573
573
  **Merge and start next:**
574
574
 
575
- **🚨 CRITICAL: Shell CWD Corruption Prevention**
576
-
577
- The merge will delete the worktree. You must be in the main repo BEFORE merging.
578
-
579
575
  ```bash
580
576
  # Commit changes in the worktree
581
577
  git add . && git commit -m "feat: [brief description of error handling added]"
582
578
  ```
583
579
 
584
580
  ```bash
585
- # cd to the main repo first (worktrees are in .jettypod-work/ inside main repo)
586
- cd /path/to/main/repo
587
-
588
- # Verify you're in the main repo
589
- pwd && ls .jettypod
590
-
591
- # Then merge
581
+ # Step 1: Merge (can run from worktree - it won't delete it)
592
582
  jettypod work merge [current-chore-id]
593
583
  ```
594
584
 
595
585
  ```bash
596
- # Start next chore
586
+ # Step 2: cd to main repo
587
+ cd /path/to/main/repo
588
+ pwd && ls .jettypod # verify
589
+ ```
590
+
591
+ ```bash
592
+ # Step 3: Clean up the worktree, then start next chore
593
+ jettypod work cleanup [current-chore-id]
597
594
  jettypod work start [next-chore-id]
598
595
  ```
599
596
 
@@ -613,21 +610,24 @@ If the query returns no remaining chores, proceed to Step 7.
613
610
 
614
611
  **First, merge the final stable chore:**
615
612
 
616
- **🚨 CRITICAL: Shell CWD Corruption Prevention**
617
-
618
613
  ```bash
619
614
  git add . && git commit -m "feat: [brief description of error handling added]"
620
615
  ```
621
616
 
622
617
  ```bash
623
- # cd to the main repo first (worktrees are in .jettypod-work/ inside main repo)
624
- cd /path/to/main/repo
618
+ # Step 1: Merge (can run from worktree - it won't delete it)
619
+ jettypod work merge [current-chore-id]
620
+ ```
625
621
 
626
- # Verify you're in the main repo
627
- pwd && ls .jettypod
622
+ ```bash
623
+ # Step 2: cd to main repo
624
+ cd /path/to/main/repo
625
+ pwd && ls .jettypod # verify
626
+ ```
628
627
 
629
- # Then merge
630
- jettypod work merge [current-chore-id]
628
+ ```bash
629
+ # Step 3: Clean up the worktree
630
+ jettypod work cleanup [current-chore-id]
631
631
  ```
632
632
 
633
633
  **Then check project state:**