s9n-devops-agent 1.6.0 → 1.6.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "s9n-devops-agent",
3
- "version": "1.6.0",
3
+ "version": "1.6.1",
4
4
  "description": "CS_DevOpsAgent - Intelligent Git Automation System with multi-agent support and session management",
5
5
  "type": "module",
6
6
  "main": "src/cs-devops-agent-worker.js",
@@ -1789,10 +1789,121 @@ console.log();
1789
1789
 
1790
1790
  if (isWorktree) {
1791
1791
  console.log("\n" + "=".repeat(60));
1792
- console.log("WORKTREE CLEANUP");
1792
+ console.log("SESSION CLEANUP OPTIONS");
1793
1793
  console.log("=".repeat(60));
1794
1794
  console.log("\nThis session is running in a worktree:");
1795
1795
  console.log(` ${currentDir}`);
1796
+
1797
+ // Get current branch
1798
+ const currentBranchName = await currentBranch();
1799
+
1800
+ // Ask about merging to target branch first
1801
+ const defaultTarget = 'main';
1802
+ console.log("\n" + "─".repeat(60));
1803
+ console.log("MERGE TO TARGET BRANCH");
1804
+ console.log("─".repeat(60));
1805
+ console.log(`\nMerge \x1b[1m${currentBranchName}\x1b[0m → \x1b[1m${defaultTarget}\x1b[0m before cleanup?`);
1806
+ console.log(" y/yes - Merge to target branch");
1807
+ console.log(" n/no - Skip merge");
1808
+
1809
+ rl.prompt();
1810
+ const mergeAnswer = await new Promise(resolve => {
1811
+ rl.once('line', resolve);
1812
+ });
1813
+
1814
+ let mergeCompleted = false;
1815
+ if (mergeAnswer.toLowerCase() === 'y' || mergeAnswer.toLowerCase() === 'yes') {
1816
+ // Ask for target branch confirmation
1817
+ console.log(`\nTarget branch [${defaultTarget}]: `);
1818
+ rl.prompt();
1819
+ const targetAnswer = await new Promise(resolve => {
1820
+ rl.once('line', resolve);
1821
+ });
1822
+
1823
+ const targetBranch = targetAnswer.trim() || defaultTarget;
1824
+
1825
+ try {
1826
+ // Get the main repo root
1827
+ const repoRoot = path.resolve(currentDir, '../../../');
1828
+
1829
+ console.log(`\n\x1b[34mMerging ${currentBranchName} into ${targetBranch}...\x1b[0m`);
1830
+
1831
+ // Check if target branch exists locally
1832
+ let branchExists = false;
1833
+ try {
1834
+ execSync(`git rev-parse --verify ${targetBranch}`, { cwd: repoRoot, stdio: 'pipe' });
1835
+ branchExists = true;
1836
+ } catch (err) {
1837
+ // Branch doesn't exist locally
1838
+ }
1839
+
1840
+ if (!branchExists) {
1841
+ // Check if branch exists on remote
1842
+ try {
1843
+ const remoteCheck = execSync(`git ls-remote --heads origin ${targetBranch}`, {
1844
+ cwd: repoRoot,
1845
+ encoding: 'utf8'
1846
+ }).trim();
1847
+
1848
+ if (remoteCheck) {
1849
+ // Branch exists on remote, fetch it
1850
+ console.log(`\x1b[2mTarget branch doesn't exist locally, fetching from remote...\x1b[0m`);
1851
+ execSync(`git fetch origin ${targetBranch}:${targetBranch}`, { cwd: repoRoot, stdio: 'pipe' });
1852
+ } else {
1853
+ // Branch doesn't exist on remote either, create it
1854
+ console.log(`\x1b[33mTarget branch '${targetBranch}' doesn't exist. Creating it...\x1b[0m`);
1855
+ execSync(`git checkout -b ${targetBranch}`, { cwd: repoRoot, stdio: 'pipe' });
1856
+ execSync(`git push -u origin ${targetBranch}`, { cwd: repoRoot, stdio: 'pipe' });
1857
+ console.log(`\x1b[32m✓\x1b[0m Created new branch ${targetBranch}`);
1858
+ }
1859
+ } catch (err) {
1860
+ console.error(`\x1b[31m✗ Error checking/creating remote branch: ${err.message}\x1b[0m`);
1861
+ throw err;
1862
+ }
1863
+ }
1864
+
1865
+ // Switch to target branch
1866
+ execSync(`git checkout ${targetBranch}`, { cwd: repoRoot, stdio: 'pipe' });
1867
+
1868
+ // Pull latest (if branch already existed)
1869
+ if (branchExists) {
1870
+ try {
1871
+ execSync(`git pull origin ${targetBranch}`, { cwd: repoRoot, stdio: 'pipe' });
1872
+ } catch (err) {
1873
+ console.log(`\x1b[2mCould not pull latest changes (may be new branch)\x1b[0m`);
1874
+ }
1875
+ }
1876
+
1877
+ // Merge the session branch
1878
+ execSync(`git merge --no-ff ${currentBranchName} -m "Merge session ${sessionId}: session work"`, {
1879
+ cwd: repoRoot,
1880
+ stdio: 'pipe'
1881
+ });
1882
+
1883
+ // Push merged changes
1884
+ execSync(`git push origin ${targetBranch}`, { cwd: repoRoot, stdio: 'pipe' });
1885
+
1886
+ console.log(`\x1b[32m✓\x1b[0m Successfully merged to ${targetBranch}`);
1887
+
1888
+ // Delete remote branch after successful merge
1889
+ try {
1890
+ execSync(`git push origin --delete ${currentBranchName}`, { cwd: repoRoot, stdio: 'pipe' });
1891
+ console.log(`\x1b[32m✓\x1b[0m Deleted remote branch ${currentBranchName}`);
1892
+ } catch (err) {
1893
+ console.log(`\x1b[2mCould not delete remote branch\x1b[0m`);
1894
+ }
1895
+
1896
+ mergeCompleted = true;
1897
+ } catch (err) {
1898
+ console.error(`\x1b[31m✗ Merge failed: ${err.message}\x1b[0m`);
1899
+ console.log(`\x1b[33mYou may need to resolve conflicts manually\x1b[0m`);
1900
+ }
1901
+ }
1902
+
1903
+ // Now ask about worktree removal
1904
+ console.log("\n" + "─".repeat(60));
1905
+ console.log("WORKTREE CLEANUP");
1906
+ console.log("─".repeat(60));
1796
1907
  console.log("\nWould you like to remove this worktree now?");
1797
1908
  console.log(" y/yes - Remove worktree and close session");
1798
1909
  console.log(" n/no - Keep worktree for later use");
@@ -41,7 +41,7 @@ show_copyright() {
41
41
  echo "======================================================================"
42
42
  echo
43
43
  echo " CS_DevOpsAgent - Intelligent Git Automation System"
44
- echo " Version 1.6.0 | Build 20251009.12"
44
+ echo " Version 1.6.1 | Build 20251009.13"
45
45
  echo " "
46
46
  echo " Copyright (c) 2024 SecondBrain Labs"
47
47
  echo " Author: Sachin Dev Duggal"