UNPKG

jrnl-mcp

Version:

Model Context Protocol server for jrnl CLI journal application

58 lines (57 loc) 1.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.listJournals = listJournals; exports.setJournal = setJournal; exports.getCurrentJournal = getCurrentJournal; const commandBuilder_1 = require("../utils/commandBuilder"); let currentJournal = undefined; async function listJournals(executor) { const command = (0, commandBuilder_1.buildListJournalsCommand)(); const result = await executor.execute(command); try { // Parse jrnl --list output // Format can be: // Journals defined in config (/path/to/config) // * default -> /path/to/default.txt // work -> /path/to/work.txt const lines = result.trim().split("\n"); const journals = []; for (const line of lines) { // Skip header lines if (line.includes("Journals defined in config") || line.trim() === "") { continue; } const match = line.match(/^(\s*\*?\s*)(\w+)\s*->\s*(.+)$/); if (match) { const isDefault = line.trim().startsWith("*"); const name = match[2].trim(); const path = match[3].trim(); journals.push({ name, path, isDefault, }); if (isDefault && !currentJournal) { currentJournal = name; } } } return { journals, currentJournal, }; } catch (error) { throw new Error(`Failed to parse journal list: ${error}`); } } async function setJournal(journalName) { currentJournal = journalName; return { success: true, currentJournal: journalName, }; } function getCurrentJournal() { return currentJournal; }