From e68287ca807397456d6f0eab9e4c8d80213b374a Mon Sep 17 00:00:00 2001 From: mpstaton Date: Sat, 9 May 2026 17:25:06 -0500 Subject: [PATCH] feat(directory-templates): stamp cf_last_run / cf_last_run_model in target frontmatter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Every successful applyTemplate now writes two keys back to the target file's frontmatter, via app.fileManager.processFrontMatter so other keys remain untouched: - cf_last_run: ISO 8601 timestamp (e.g. "2026-05-09T20:14:32.451Z"). - cf_last_run_model: provider + model id (e.g. "Perplexity sonar-deep-research"). Lets the vault be queried for staleness — e.g. "show all files in Tooling/AI-Toolkit/Agentic AI/Agentic Workspaces sorted by oldest cf_last_run" to find which entries need a refresh. Mirrors the og_last_fetch pattern from metafetch. Stamping happens only on { status: 'applied' } — errors and skips do not touch frontmatter. Co-Authored-By: Claude Opus 4.7 (1M context) --- src/services/directoryTemplateService.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/services/directoryTemplateService.ts b/src/services/directoryTemplateService.ts index fe4bfb2..60a94d7 100644 --- a/src/services/directoryTemplateService.ts +++ b/src/services/directoryTemplateService.ts @@ -469,6 +469,26 @@ export async function applyTemplate( const finalContent = `${initialContent}${cleanedStreamed}\n${sourcesFooter}`; await app.vault.modify(target, finalContent); + // Stamp run metadata in the target's frontmatter so files can be + // queried for staleness ("which Tooling/ entries were last refreshed + // before ?"). Uses fileManager.processFrontMatter so other + // frontmatter keys remain byte-identical apart from these two. + const provider = typeof template.cftConfig['provider'] === 'string' + ? template.cftConfig['provider'] + : 'unknown'; + const modelName = typeof template.cftConfig['model'] === 'string' + ? template.cftConfig['model'] + : 'unknown'; + const providerLabel = provider.length > 0 + ? provider.charAt(0).toUpperCase() + provider.slice(1) + : provider; + const runTimestamp = new Date().toISOString(); + const runModelLabel = `${providerLabel} ${modelName}`.trim(); + await app.fileManager.processFrontMatter(target, (fm: Record) => { + fm['cf_last_run'] = runTimestamp; + fm['cf_last_run_model'] = runModelLabel; + }); + if (!quiet) { const verb = mode === 'fill' ? 'Filled' : 'Appended to'; new Notice(`${verb} "${target.basename}" using ${template.file.basename} (${sources.length.toString()} sources)`);