agp-cli
Version:
Agentic Programming Project CLI - Standardized knowledge layer for AI-assisted development
141 lines • 5.63 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.pushAgpChanges = pushAgpChanges;
const child_process_1 = require("child_process");
const path = __importStar(require("path"));
const fs = __importStar(require("fs-extra"));
const logger_1 = require("./logger");
// Helper function to execute commands asynchronously
function execAsync(command, args) {
return new Promise((resolve, reject) => {
let cmd;
let cmdArgs;
if (args) {
cmd = command;
cmdArgs = args;
}
else {
const parts = command.split(' ');
cmd = parts[0] || '';
cmdArgs = parts.slice(1);
}
if (!cmd) {
reject(new Error('Empty command'));
return;
}
const child = (0, child_process_1.spawn)(cmd, cmdArgs, {
stdio: ['ignore', 'ignore', 'ignore']
});
child.on('close', (code) => {
if (code === 0) {
resolve();
}
else {
reject(new Error(`Command failed with code ${code}: ${cmd} ${cmdArgs.join(' ')}`));
}
});
child.on('error', (error) => {
reject(error);
});
});
}
async function pushAgpChanges(options) {
const cwd = process.cwd();
const agpPath = path.join(cwd, '.agp');
// Check if .agp directory exists
if (!(await fs.pathExists(agpPath))) {
throw new Error('AGP directory not found. Run "agp init" first.');
}
// Check if .agp is a git repository
const agpGitPath = path.join(agpPath, '.git');
if (!(await fs.pathExists(agpGitPath))) {
throw new Error('AGP directory is not a git repository. Please check your setup.');
}
try {
// Change to .agp directory
process.chdir(agpPath);
// Check if there are any changes
const status = (0, child_process_1.execSync)('git status --porcelain', { encoding: 'utf8' });
if (!status.trim()) {
logger_1.logger.success('No changes to push');
return;
}
const changedFiles = status.trim().split('\n');
// Generate commit message if not provided
const commitMessage = options.message || generateCommitMessage(changedFiles);
// Use spinner for actual Git operations
await logger_1.logger.withSpinner(`Pushing ${changedFiles.length} AGP files`, async () => {
// Execute git commands asynchronously to keep spinner running
await execAsync('git', ['add', '.']);
await execAsync('git', ['commit', '-m', commitMessage]);
await execAsync('git', ['push']);
// Update submodule reference in parent repository
process.chdir(cwd);
await execAsync('git', ['add', '.agp']);
// Check if parent has changes to commit
const parentStatus = (0, child_process_1.execSync)('git status --porcelain', { encoding: 'utf8' });
if (parentStatus.includes('.agp')) {
await execAsync('git', ['commit', '-m', 'chore: update AGP submodule pointer']);
}
});
}
catch (error) {
throw new Error(`Failed to push AGP changes: ${error instanceof Error ? error.message : 'Unknown error'}`);
}
finally {
// Always return to original directory
process.chdir(cwd);
}
}
function generateCommitMessage(changedFiles) {
const sessionFiles = changedFiles.filter((f) => f.includes('sessions/'));
const knowledgeFiles = changedFiles.filter((f) => f.includes('project/'));
const patternFiles = changedFiles.filter((f) => f.includes('patterns/'));
const architectureFiles = changedFiles.filter((f) => f.includes('architecture/'));
const parts = [];
if (sessionFiles.length > 0)
parts.push('session progress');
if (knowledgeFiles.length > 0)
parts.push('project knowledge');
if (patternFiles.length > 0)
parts.push('patterns');
if (architectureFiles.length > 0)
parts.push('architecture');
if (parts.length === 0)
return 'docs: update AGP knowledge';
return `docs: update ${parts.join(', ')}`;
}
//# sourceMappingURL=agp-push.js.map