mirror-magi-meta-agent
Version:
AI-powered development planning and execution system with Supabase integration
96 lines (86 loc) • 2.14 kB
JavaScript
const { exec } = require('child_process');
const { promisify } = require('util');
const execAsync = promisify(exec);
module.exports = {
/**
* Get git status in porcelain format
*/
async status() {
try {
const { stdout } = await execAsync('git status --porcelain');
return stdout.trim().split('\n').filter(line => line.length > 0);
} catch (error) {
throw new Error('Not a git repository');
}
},
/**
* Check if there are any uncommitted changes
*/
async hasChanges() {
const changes = await this.status();
return changes.length > 0;
},
/**
* Stage files for commit
*/
async add(files = '.') {
await execAsync(`git add ${files}`);
},
/**
* Create a commit with the given message
*/
async commit(message) {
// Escape double quotes in the message
const escapedMessage = message.replace(/"/g, '\\"');
await execAsync(`git commit -m "${escapedMessage}"`);
},
/**
* Get the current branch name
*/
async getCurrentBranch() {
const { stdout } = await execAsync('git branch --show-current');
return stdout.trim();
},
/**
* Get diff of staged or unstaged changes
*/
async diff(staged = false) {
const { stdout } = await execAsync(`git diff ${staged ? '--staged' : ''}`);
return stdout;
},
/**
* Stash changes with a message
*/
async stash(message) {
await execAsync(`git stash push -m "${message}"`);
},
/**
* Get the last commit message
*/
async getLastCommit() {
const { stdout } = await execAsync('git log -1 --pretty=%B');
return stdout.trim();
},
/**
* Check if we're in a git repository
*/
async isGitRepo() {
try {
await execAsync('git rev-parse --git-dir');
return true;
} catch {
return false;
}
},
/**
* Get list of modified files for a specific path pattern
*/
async getModifiedFiles(pattern) {
try {
const { stdout } = await execAsync(`git diff --name-only ${pattern || ''}`);
return stdout.trim().split('\n').filter(line => line.length > 0);
} catch {
return [];
}
}
};