feat(directory-templates): stamp cf_last_run / cf_last_run_model in target frontmatter

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) <noreply@anthropic.com>
This commit is contained in:
mpstaton 2026-05-09 17:25:06 -05:00
parent 293a2bd860
commit e68287ca80

View file

@ -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 <date>?"). 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<string, unknown>) => {
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)`);