ai-dev-diary
Version:
Intelligent development diary system for AI-assisted projects
234 lines ⢠9.84 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;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.teamCommand = void 0;
const commander_1 = require("commander");
const chalk_1 = __importDefault(require("chalk"));
const fs = __importStar(require("fs-extra"));
const path = __importStar(require("path"));
const glob = __importStar(require("glob"));
const ora_1 = __importDefault(require("ora"));
const github_1 = require("../utils/github");
exports.teamCommand = new commander_1.Command('team')
.description('Team collaboration features');
exports.teamCommand
.command('list')
.description('List team members and their recent entries')
.option('-l, --limit <n>', 'Number of entries per member', '5')
.action(async (options) => {
const basePath = '.ai-diary';
const teamPath = path.join(basePath, 'team');
if (!await fs.pathExists(teamPath)) {
console.log(chalk_1.default.yellow('Team mode not enabled in this project'));
return;
}
const spinner = (0, ora_1.default)('Loading team entries...').start();
try {
const members = await fs.readdir(teamPath);
const memberStats = [];
for (const member of members) {
if (!member.startsWith('@'))
continue;
const memberPath = path.join(teamPath, member);
const entriesPath = path.join(memberPath, 'entries');
if (!await fs.pathExists(entriesPath))
continue;
const entryFiles = glob.sync('**/*.md', {
cwd: entriesPath,
nodir: true
}).sort().reverse().slice(0, parseInt(options.limit));
const entries = [];
for (const file of entryFiles) {
const content = await fs.readFile(path.join(entriesPath, file), 'utf-8');
const titleMatch = content.match(/^# (.+)$/m);
const dateMatch = content.match(/Date: (.+)$/m);
const typeMatch = content.match(/Type: (.+)$/m);
if (titleMatch && dateMatch) {
entries.push({
title: titleMatch[1],
date: dateMatch[1],
type: typeMatch ? typeMatch[1] : 'unknown',
file: file
});
}
}
memberStats.push({
member,
totalEntries: glob.sync('**/*.md', { cwd: entriesPath, nodir: true }).length,
recentEntries: entries
});
}
spinner.succeed('Team entries loaded');
console.log(chalk_1.default.blue.bold('\nš Team Activity Summary\n'));
for (const stat of memberStats) {
console.log(chalk_1.default.cyan.bold(`${stat.member} (${stat.totalEntries} total entries)`));
if (stat.recentEntries.length === 0) {
console.log(chalk_1.default.gray(' No entries yet'));
}
else {
for (const entry of stat.recentEntries) {
const icon = getEntryIcon(entry.type);
console.log(chalk_1.default.gray(` ${icon} ${entry.date} - ${entry.title}`));
}
}
console.log();
}
}
catch (error) {
spinner.fail('Failed to load team entries');
console.error(chalk_1.default.red(error));
}
});
exports.teamCommand
.command('search <query>')
.description('Search across all team entries')
.option('-t, --type <type>', 'Filter by entry type')
.option('-a, --author <name>', 'Filter by author')
.action(async (query, options) => {
const basePath = '.ai-diary';
const teamPath = path.join(basePath, 'team');
if (!await fs.pathExists(teamPath)) {
console.log(chalk_1.default.yellow('Team mode not enabled in this project'));
return;
}
const spinner = (0, ora_1.default)('Searching team entries...').start();
const results = [];
try {
const members = await fs.readdir(teamPath);
for (const member of members) {
if (!member.startsWith('@'))
continue;
if (options.author && member !== (0, github_1.formatAuthorName)(options.author))
continue;
const entriesPath = path.join(teamPath, member, 'entries');
if (!await fs.pathExists(entriesPath))
continue;
const entryFiles = glob.sync('**/*.md', { cwd: entriesPath, nodir: true });
for (const file of entryFiles) {
const content = await fs.readFile(path.join(entriesPath, file), 'utf-8');
if (options.type) {
const typeMatch = content.match(/type: (.+)$/m);
if (!typeMatch || typeMatch[1] !== options.type)
continue;
}
if (content.toLowerCase().includes(query.toLowerCase())) {
const titleMatch = content.match(/^# (.+)$/m);
const dateMatch = content.match(/Date: (.+)$/m);
const typeMatch = content.match(/Type: (.+)$/m);
const lines = content.split('\n');
const queryLower = query.toLowerCase();
let snippet = '';
for (let i = 0; i < lines.length; i++) {
if (lines[i].toLowerCase().includes(queryLower)) {
const start = Math.max(0, i - 1);
const end = Math.min(lines.length, i + 2);
snippet = lines.slice(start, end).join('\n');
break;
}
}
results.push({
member,
file,
title: titleMatch ? titleMatch[1] : 'Untitled',
date: dateMatch ? dateMatch[1] : 'Unknown date',
type: typeMatch ? typeMatch[1] : 'unknown',
snippet: snippet.trim()
});
}
}
}
spinner.succeed(`Found ${results.length} matches`);
if (results.length === 0) {
console.log(chalk_1.default.gray('\nNo entries found matching your query'));
return;
}
console.log(chalk_1.default.blue.bold(`\nš Search Results for "${query}"\n`));
for (const result of results) {
const icon = getEntryIcon(result.type);
console.log(chalk_1.default.cyan(`${icon} ${result.title}`));
console.log(chalk_1.default.gray(` Author: ${result.member} | Date: ${result.date}`));
console.log(chalk_1.default.gray(` File: ${result.file}`));
if (result.snippet) {
console.log(chalk_1.default.gray(` Preview: ${result.snippet.split('\n')[0]}...`));
}
console.log();
}
}
catch (error) {
spinner.fail('Search failed');
console.error(chalk_1.default.red(error));
}
});
exports.teamCommand
.command('share <entryId>')
.description('Share a personal entry to team knowledge base')
.option('-c, --category <category>', 'Category for shared knowledge')
.action(async () => {
console.log(chalk_1.default.yellow('Share feature coming soon!'));
});
exports.teamCommand
.command('sync')
.description('Sync team knowledge from remote repository')
.action(async () => {
const spinner = (0, ora_1.default)('Syncing team knowledge...').start();
try {
const isGitRepo = await fs.pathExists('.git');
if (!isGitRepo) {
spinner.fail('Not in a git repository');
return;
}
const { execSync } = require('child_process');
execSync('git pull --rebase', { encoding: 'utf-8' });
spinner.succeed('Team knowledge synced successfully');
}
catch (error) {
spinner.fail('Failed to sync');
console.error(chalk_1.default.red(error));
}
});
function getEntryIcon(type) {
const icons = {
journey: 'š',
insight: 'š”',
mistake: 'ā',
breakthrough: 'šÆ',
context: 'š',
};
return icons[type] || 'š';
}
//# sourceMappingURL=team.js.map