From cad5e54acab0acbfed8131f81dc36a7a31ed2864 Mon Sep 17 00:00:00 2001 From: dtzp555 Date: Tue, 31 Mar 2026 14:57:49 +1000 Subject: [PATCH] feat: auto-extract #tags from sessions to memory/tags.md (v3.2) Co-Authored-By: Claude Sonnet 4.6 --- index.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/index.js b/index.js index 2d88de7..6648cc8 100644 --- a/index.js +++ b/index.js @@ -231,6 +231,9 @@ function writeSessionLog(workspaceDir, messages, config = {}) { const isNew = !fs.existsSync(logFile); const prefix = isNew ? `# Session Log — ${dateStr}\n\n` : ""; fs.appendFileSync(logFile, prefix + entry, "utf8"); + + // Extract and index #tags from the topic + updateTagIndex(workspaceDir, topic, dateStr); } /** @@ -464,6 +467,42 @@ function generateWeeklySummary(workspaceDir, config = {}) { fs.writeFileSync(weeklyFile, summary, "utf8"); } +/** + * Extract #tags from a session topic and update the tag index. + * Tags file: memory/tags.md — simple markdown index mapping tags to dates. + */ +function updateTagIndex(workspaceDir, topic, dateStr) { + if (!topic) return; + + // Extract #tags (word chars + hyphens after #) + const tags = topic.match(/#[\w-]+/g); + if (!tags || tags.length === 0) return; + + const tagsFile = path.join(workspaceDir, "memory", "tags.md"); + let existing = readFile(tagsFile) || "# Tag Index\n\n"; + + for (const tag of tags) { + const normalizedTag = tag.toLowerCase(); + // Check if this tag+date combo already exists + if (existing.includes(`${normalizedTag}`) && existing.includes(dateStr)) continue; + + // Find or create tag section + const tagHeader = `## ${normalizedTag}`; + if (existing.includes(tagHeader)) { + // Append date to existing tag section + existing = existing.replace( + tagHeader, + `${tagHeader}\n- ${dateStr}` + ); + } else { + // Add new tag section + existing += `${tagHeader}\n- ${dateStr}\n\n`; + } + } + + writeFile(tagsFile, existing); +} + function extractStateFromMessages(messages) { if (!messages || messages.length === 0) return null;