s9n-devops-agent 1.5.9 → 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
|
@@ -1789,10 +1789,121 @@ console.log();
|
|
|
1789
1789
|
|
|
1790
1790
|
if (isWorktree) {
|
|
1791
1791
|
console.log("\n" + "=".repeat(60));
|
|
1792
|
-
console.log("
|
|
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");
|
|
@@ -1689,15 +1689,15 @@ The DevOps agent is monitoring this worktree for changes.
|
|
|
1689
1689
|
|
|
1690
1690
|
console.log(`\n${CONFIG.colors.yellow}Worktree Cleanup Options${CONFIG.colors.reset}`);
|
|
1691
1691
|
|
|
1692
|
+
// Get target branch from merge config or default to 'main'
|
|
1693
|
+
let targetBranch = session.mergeConfig?.targetBranch || 'main';
|
|
1694
|
+
|
|
1692
1695
|
const mergeFirst = await new Promise(resolve => {
|
|
1693
|
-
rl.question(`\nMerge ${session.branchName}
|
|
1696
|
+
rl.question(`\nMerge ${CONFIG.colors.bright}${session.branchName}${CONFIG.colors.reset} → ${CONFIG.colors.bright}${targetBranch}${CONFIG.colors.reset} before cleanup? (y/N): `, resolve);
|
|
1694
1697
|
});
|
|
1695
1698
|
rl.close();
|
|
1696
1699
|
|
|
1697
1700
|
if (mergeFirst.toLowerCase() === 'y') {
|
|
1698
|
-
// Get target branch from merge config or ask
|
|
1699
|
-
let targetBranch = session.mergeConfig?.targetBranch || 'main';
|
|
1700
|
-
|
|
1701
1701
|
rl = readline.createInterface({
|
|
1702
1702
|
input: process.stdin,
|
|
1703
1703
|
output: process.stdout
|
|
@@ -1715,11 +1715,42 @@ The DevOps agent is monitoring this worktree for changes.
|
|
|
1715
1715
|
try {
|
|
1716
1716
|
console.log(`\n${CONFIG.colors.blue}Merging ${session.branchName} into ${targetBranch}...${CONFIG.colors.reset}`);
|
|
1717
1717
|
|
|
1718
|
+
// Check if target branch exists locally
|
|
1719
|
+
let branchExists = false;
|
|
1720
|
+
try {
|
|
1721
|
+
execSync(`git rev-parse --verify ${targetBranch}`, { cwd: this.repoRoot, stdio: 'pipe' });
|
|
1722
|
+
branchExists = true;
|
|
1723
|
+
} catch (err) {
|
|
1724
|
+
// Branch doesn't exist locally
|
|
1725
|
+
}
|
|
1726
|
+
|
|
1727
|
+
if (!branchExists) {
|
|
1728
|
+
// Check if branch exists on remote
|
|
1729
|
+
try {
|
|
1730
|
+
execSync(`git ls-remote --heads origin ${targetBranch}`, { cwd: this.repoRoot, stdio: 'pipe' });
|
|
1731
|
+
// Branch exists on remote, fetch it
|
|
1732
|
+
console.log(`${CONFIG.colors.dim}Target branch doesn't exist locally, fetching from remote...${CONFIG.colors.reset}`);
|
|
1733
|
+
execSync(`git fetch origin ${targetBranch}:${targetBranch}`, { cwd: this.repoRoot, stdio: 'pipe' });
|
|
1734
|
+
} catch (err) {
|
|
1735
|
+
// Branch doesn't exist on remote either, create it
|
|
1736
|
+
console.log(`${CONFIG.colors.yellow}Target branch '${targetBranch}' doesn't exist. Creating it...${CONFIG.colors.reset}`);
|
|
1737
|
+
execSync(`git checkout -b ${targetBranch}`, { cwd: this.repoRoot, stdio: 'pipe' });
|
|
1738
|
+
execSync(`git push -u origin ${targetBranch}`, { cwd: this.repoRoot, stdio: 'pipe' });
|
|
1739
|
+
console.log(`${CONFIG.colors.green}✓${CONFIG.colors.reset} Created new branch ${targetBranch}`);
|
|
1740
|
+
}
|
|
1741
|
+
}
|
|
1742
|
+
|
|
1718
1743
|
// Switch to target branch in main repo
|
|
1719
1744
|
execSync(`git checkout ${targetBranch}`, { cwd: this.repoRoot, stdio: 'pipe' });
|
|
1720
1745
|
|
|
1721
|
-
// Pull latest
|
|
1722
|
-
|
|
1746
|
+
// Pull latest (if branch already existed)
|
|
1747
|
+
if (branchExists) {
|
|
1748
|
+
try {
|
|
1749
|
+
execSync(`git pull origin ${targetBranch}`, { cwd: this.repoRoot, stdio: 'pipe' });
|
|
1750
|
+
} catch (err) {
|
|
1751
|
+
console.log(`${CONFIG.colors.dim}Could not pull latest changes (may be new branch)${CONFIG.colors.reset}`);
|
|
1752
|
+
}
|
|
1753
|
+
}
|
|
1723
1754
|
|
|
1724
1755
|
// Merge the session branch
|
|
1725
1756
|
execSync(`git merge --no-ff ${session.branchName} -m "Merge session ${sessionId}: ${session.task}"`, {
|
package/start-devops-session.sh
CHANGED
|
@@ -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.
|
|
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"
|