s9n-devops-agent 1.6.0 → 1.6.2
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 +1 -1
- package/src/cs-devops-agent-worker.js +144 -1
- package/start-devops-session.sh +1 -1
package/package.json
CHANGED
|
@@ -1789,10 +1789,153 @@ 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
|
+
// Get the main repo root
|
|
1801
|
+
const repoRoot = path.resolve(currentDir, '../../../');
|
|
1802
|
+
|
|
1803
|
+
// Read session lock file to get merge configuration
|
|
1804
|
+
let mergeConfig = null;
|
|
1805
|
+
let shouldMerge = false;
|
|
1806
|
+
let targetBranch = 'main';
|
|
1807
|
+
|
|
1808
|
+
try {
|
|
1809
|
+
const lockFile = path.join(repoRoot, 'local_deploy', 'session-locks', `${sessionId}.lock`);
|
|
1810
|
+
if (fs.existsSync(lockFile)) {
|
|
1811
|
+
const sessionData = JSON.parse(fs.readFileSync(lockFile, 'utf8'));
|
|
1812
|
+
mergeConfig = sessionData.mergeConfig;
|
|
1813
|
+
}
|
|
1814
|
+
} catch (err) {
|
|
1815
|
+
console.log(`\x1b[2mCould not read session config: ${err.message}\x1b[0m`);
|
|
1816
|
+
}
|
|
1817
|
+
|
|
1818
|
+
// Check if auto-merge is configured
|
|
1819
|
+
if (mergeConfig && mergeConfig.autoMerge && mergeConfig.targetBranch) {
|
|
1820
|
+
// Auto-merge is configured
|
|
1821
|
+
shouldMerge = true;
|
|
1822
|
+
targetBranch = mergeConfig.targetBranch;
|
|
1823
|
+
console.log("\n" + "─".repeat(60));
|
|
1824
|
+
console.log("AUTO-MERGE CONFIGURED");
|
|
1825
|
+
console.log("─".repeat(60));
|
|
1826
|
+
console.log(`\nAuto-merging \x1b[1m${currentBranchName}\x1b[0m → \x1b[1m${targetBranch}\x1b[0m`);
|
|
1827
|
+
console.log(`\x1b[2m(Configured during session start)\x1b[0m`);
|
|
1828
|
+
} else {
|
|
1829
|
+
// No auto-merge configured, ask the user
|
|
1830
|
+
console.log("\n" + "─".repeat(60));
|
|
1831
|
+
console.log("MERGE TO TARGET BRANCH");
|
|
1832
|
+
console.log("─".repeat(60));
|
|
1833
|
+
console.log(`\nMerge \x1b[1m${currentBranchName}\x1b[0m → target branch before cleanup?`);
|
|
1834
|
+
console.log(" y/yes - Merge to target branch");
|
|
1835
|
+
console.log(" n/no - Skip merge");
|
|
1836
|
+
|
|
1837
|
+
rl.prompt();
|
|
1838
|
+
const mergeAnswer = await new Promise(resolve => {
|
|
1839
|
+
rl.once('line', resolve);
|
|
1840
|
+
});
|
|
1841
|
+
|
|
1842
|
+
shouldMerge = mergeAnswer.toLowerCase() === 'y' || mergeAnswer.toLowerCase() === 'yes';
|
|
1843
|
+
|
|
1844
|
+
if (shouldMerge) {
|
|
1845
|
+
// Ask for target branch
|
|
1846
|
+
console.log(`\nTarget branch [${targetBranch}]: `);
|
|
1847
|
+
rl.prompt();
|
|
1848
|
+
const targetAnswer = await new Promise(resolve => {
|
|
1849
|
+
rl.once('line', resolve);
|
|
1850
|
+
});
|
|
1851
|
+
|
|
1852
|
+
if (targetAnswer.trim()) {
|
|
1853
|
+
targetBranch = targetAnswer.trim();
|
|
1854
|
+
}
|
|
1855
|
+
}
|
|
1856
|
+
}
|
|
1857
|
+
|
|
1858
|
+
let mergeCompleted = false;
|
|
1859
|
+
if (shouldMerge) {
|
|
1860
|
+
try {
|
|
1861
|
+
console.log(`\n\x1b[34mMerging ${currentBranchName} into ${targetBranch}...\x1b[0m`);
|
|
1862
|
+
|
|
1863
|
+
// Check if target branch exists locally
|
|
1864
|
+
let branchExists = false;
|
|
1865
|
+
try {
|
|
1866
|
+
execSync(`git rev-parse --verify ${targetBranch}`, { cwd: repoRoot, stdio: 'pipe' });
|
|
1867
|
+
branchExists = true;
|
|
1868
|
+
} catch (err) {
|
|
1869
|
+
// Branch doesn't exist locally
|
|
1870
|
+
}
|
|
1871
|
+
|
|
1872
|
+
if (!branchExists) {
|
|
1873
|
+
// Check if branch exists on remote
|
|
1874
|
+
try {
|
|
1875
|
+
const remoteCheck = execSync(`git ls-remote --heads origin ${targetBranch}`, {
|
|
1876
|
+
cwd: repoRoot,
|
|
1877
|
+
encoding: 'utf8'
|
|
1878
|
+
}).trim();
|
|
1879
|
+
|
|
1880
|
+
if (remoteCheck) {
|
|
1881
|
+
// Branch exists on remote, fetch it
|
|
1882
|
+
console.log(`\x1b[2mTarget branch doesn't exist locally, fetching from remote...\x1b[0m`);
|
|
1883
|
+
execSync(`git fetch origin ${targetBranch}:${targetBranch}`, { cwd: repoRoot, stdio: 'pipe' });
|
|
1884
|
+
} else {
|
|
1885
|
+
// Branch doesn't exist on remote either, create it
|
|
1886
|
+
console.log(`\x1b[33mTarget branch '${targetBranch}' doesn't exist. Creating it...\x1b[0m`);
|
|
1887
|
+
execSync(`git checkout -b ${targetBranch}`, { cwd: repoRoot, stdio: 'pipe' });
|
|
1888
|
+
execSync(`git push -u origin ${targetBranch}`, { cwd: repoRoot, stdio: 'pipe' });
|
|
1889
|
+
console.log(`\x1b[32m✓\x1b[0m Created new branch ${targetBranch}`);
|
|
1890
|
+
}
|
|
1891
|
+
} catch (err) {
|
|
1892
|
+
console.error(`\x1b[31m✗ Error checking/creating remote branch: ${err.message}\x1b[0m`);
|
|
1893
|
+
throw err;
|
|
1894
|
+
}
|
|
1895
|
+
}
|
|
1896
|
+
|
|
1897
|
+
// Switch to target branch
|
|
1898
|
+
execSync(`git checkout ${targetBranch}`, { cwd: repoRoot, stdio: 'pipe' });
|
|
1899
|
+
|
|
1900
|
+
// Pull latest (if branch already existed)
|
|
1901
|
+
if (branchExists) {
|
|
1902
|
+
try {
|
|
1903
|
+
execSync(`git pull origin ${targetBranch}`, { cwd: repoRoot, stdio: 'pipe' });
|
|
1904
|
+
} catch (err) {
|
|
1905
|
+
console.log(`\x1b[2mCould not pull latest changes (may be new branch)\x1b[0m`);
|
|
1906
|
+
}
|
|
1907
|
+
}
|
|
1908
|
+
|
|
1909
|
+
// Merge the session branch
|
|
1910
|
+
execSync(`git merge --no-ff ${currentBranchName} -m "Merge session ${sessionId}: session work"`, {
|
|
1911
|
+
cwd: repoRoot,
|
|
1912
|
+
stdio: 'pipe'
|
|
1913
|
+
});
|
|
1914
|
+
|
|
1915
|
+
// Push merged changes
|
|
1916
|
+
execSync(`git push origin ${targetBranch}`, { cwd: repoRoot, stdio: 'pipe' });
|
|
1917
|
+
|
|
1918
|
+
console.log(`\x1b[32m✓\x1b[0m Successfully merged to ${targetBranch}`);
|
|
1919
|
+
|
|
1920
|
+
// Delete remote branch after successful merge
|
|
1921
|
+
try {
|
|
1922
|
+
execSync(`git push origin --delete ${currentBranchName}`, { cwd: repoRoot, stdio: 'pipe' });
|
|
1923
|
+
console.log(`\x1b[32m✓\x1b[0m Deleted remote branch ${currentBranchName}`);
|
|
1924
|
+
} catch (err) {
|
|
1925
|
+
console.log(`\x1b[2mCould not delete remote branch\x1b[0m`);
|
|
1926
|
+
}
|
|
1927
|
+
|
|
1928
|
+
mergeCompleted = true;
|
|
1929
|
+
} catch (err) {
|
|
1930
|
+
console.error(`\x1b[31m✗ Merge failed: ${err.message}\x1b[0m`);
|
|
1931
|
+
console.log(`\x1b[33mYou may need to resolve conflicts manually\x1b[0m`);
|
|
1932
|
+
}
|
|
1933
|
+
}
|
|
1934
|
+
|
|
1935
|
+
// Now ask about worktree removal
|
|
1936
|
+
console.log("\n" + "─".repeat(60));
|
|
1937
|
+
console.log("WORKTREE CLEANUP");
|
|
1938
|
+
console.log("─".repeat(60));
|
|
1796
1939
|
console.log("\nWould you like to remove this worktree now?");
|
|
1797
1940
|
console.log(" y/yes - Remove worktree and close session");
|
|
1798
1941
|
console.log(" n/no - Keep worktree for later use");
|
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.6.
|
|
44
|
+
echo " Version 1.6.2 | Build 20251009.14"
|
|
45
45
|
echo " "
|
|
46
46
|
echo " Copyright (c) 2024 SecondBrain Labs"
|
|
47
47
|
echo " Author: Sachin Dev Duggal"
|