agp-cli
Version:
Agentic Programming Project CLI - Standardized knowledge layer for AI-assisted development
130 lines (124 loc) • 4.8 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.startAgpSession = startAgpSession;
const fs = __importStar(require("fs-extra"));
const path = __importStar(require("path"));
async function startAgpSession() {
const cwd = process.cwd();
const agpPath = path.join(cwd, '.agp');
const configPath = path.join(agpPath, '.config.json');
// Check if AGP is initialized
if (!(await fs.pathExists(agpPath))) {
throw new Error('AGP not initialized. Run "agp init" first.');
}
if (!(await fs.pathExists(configPath))) {
throw new Error('AGP config not found. Run "agp init" to reinitialize.');
}
// Read existing config
let config;
try {
const configContent = await fs.readFile(configPath, 'utf8');
config = JSON.parse(configContent);
}
catch (error) {
throw new Error('Failed to read AGP config. Please run "agp init" to reinitialize.');
}
// Get or prompt for user name
let userName = config.session.user;
if (!userName || userName.trim() === '') {
// Use readline for simpler input
const readline = await Promise.resolve().then(() => __importStar(require('readline')));
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
userName = await new Promise((resolve) => {
rl.question('Enter your name: ', (answer) => {
rl.close();
resolve(answer.trim());
});
});
if (!userName) {
throw new Error('Name is required');
}
}
// Create user session directory if it doesn't exist
const userSessionDir = path.join(agpPath, 'sessions', userName);
await fs.ensureDir(userSessionDir);
// Create or load user session file
const sessionFilePath = path.join(userSessionDir, 'index.md');
const isNewUser = !(await fs.pathExists(sessionFilePath));
if (isNewUser) {
await createNewSessionFile(sessionFilePath, userName);
}
else {
await loadExistingSession(sessionFilePath);
}
// Update config with current user and session
config.session.user = userName;
config.session.current = `.agp/sessions/${userName}/index.md`;
await fs.writeFile(configPath, JSON.stringify(config, null, 2));
// Success handled by spinner
}
async function createNewSessionFile(sessionFilePath, userName) {
const sessionContent = `# ${userName} - Current Session
## Active Files
(No active files yet)
## In Progress
- [ ] Welcome to AGP! Start by exploring the project structure
## Blocked
(No blocked tasks)
## Next Up
- [ ] Read .agp/architecture/overview.md to understand project structure
- [ ] Review .agp/patterns/overview.md for implementation patterns
## Decisions Made
- ${new Date().toISOString().split('T')[0]} ${new Date().toTimeString().split(' ')[0]}: Started using AGP for project management
## Notes & Context
- First session created
- Ready to begin development work with AI assistance
`;
await fs.writeFile(sessionFilePath, sessionContent);
}
async function loadExistingSession(sessionFilePath) {
// Just validate that the file exists and is readable
try {
await fs.readFile(sessionFilePath, 'utf8');
}
catch (error) {
throw new Error('Failed to load existing session file');
}
}
//# sourceMappingURL=agp-start.js.map