diff --git a/src/agent/prompts/skill.ts b/src/agent/prompts/skill.ts index 89701121..0cb840fd 100644 --- a/src/agent/prompts/skill.ts +++ b/src/agent/prompts/skill.ts @@ -5,6 +5,7 @@ import type { FeaturesConfig } from '../../core/config.ts' import { writeFileSync } from 'node:fs' import { join } from 'pathe' +import { todayIsoDate } from '../../core/formatting.ts' import { repairMarkdown, sanitizeMarkdown } from '../../core/sanitize.ts' import { resolveSkilldCommand } from '../../core/shared.ts' import { yamlEscape } from '../../core/yaml.ts' @@ -232,7 +233,7 @@ function generateFrontmatter({ name, version, description: pkgDescription, globs metaEntries.push(` version: ${yamlEscape(version)}`) if (body && generatedBy) metaEntries.push(` generated_by: ${yamlEscape(generatedBy)}`) - metaEntries.push(` generated_at: ${new Date().toISOString().split('T')[0]}`) + metaEntries.push(` generated_at: ${todayIsoDate()}`) if (metaEntries.length) { lines.push('metadata:') lines.push(...metaEntries) diff --git a/src/commands/prepare.ts b/src/commands/prepare.ts index 59a4f9d1..59a1e54e 100644 --- a/src/commands/prepare.ts +++ b/src/commands/prepare.ts @@ -13,6 +13,7 @@ import { defineCommand } from 'citty' import { join } from 'pathe' import { agents, linkSkillToAgents } from '../agent/index.ts' import { resolveAgent } from '../cli-helpers.ts' +import { todayIsoDate } from '../core/formatting.ts' import { readLock, writeLock } from '../core/lockfile.ts' import { getShippedSkills, linkShippedSkill, restorePkgSymlink } from '../core/prepare.ts' import { getSharedSkillsDir } from '../core/shared.ts' @@ -91,7 +92,7 @@ export const prepareCommandDef = defineCommand({ packageName: entry.packageName, version, source: 'shipped', - syncedAt: new Date().toISOString().split('T')[0], + syncedAt: todayIsoDate(), generator: 'skilld', }) diff --git a/src/commands/sync-git.ts b/src/commands/sync-git.ts index 54ca969e..3e4ad685 100644 --- a/src/commands/sync-git.ts +++ b/src/commands/sync-git.ts @@ -27,7 +27,7 @@ import { resolvePkgDir, } from '../cache/index.ts' import { defaultFeatures, readConfig, registerProject } from '../core/config.ts' -import { timedSpinner } from '../core/formatting.ts' +import { timedSpinner, todayIsoDate } from '../core/formatting.ts' import { writeLock } from '../core/lockfile.ts' import { sanitizeMarkdown } from '../core/sanitize.ts' import { getSharedSkillsDir } from '../core/shared.ts' @@ -154,7 +154,7 @@ export async function syncGitSkills(opts: GitSyncOptions): Promise { repo: source.type === 'local' ? source.localPath : `${source.owner}/${source.repo}`, path: skill.path || undefined, ref: source.ref || 'main', - syncedAt: new Date().toISOString().split('T')[0], + syncedAt: todayIsoDate(), generator: 'external', }) } @@ -271,7 +271,7 @@ async function syncGitHubRepo(opts: GitSyncOptions): Promise { version, repo: `${owner}/${repo}`, source: resources.docSource, - syncedAt: new Date().toISOString().split('T')[0], + syncedAt: todayIsoDate(), generator: 'skilld', }) diff --git a/src/commands/sync-parallel.ts b/src/commands/sync-parallel.ts index 9e48b3b6..dea5f300 100644 --- a/src/commands/sync-parallel.ts +++ b/src/commands/sync-parallel.ts @@ -32,7 +32,7 @@ import { resolvePkgDir, } from '../cache/index.ts' import { defaultFeatures, readConfig, registerProject } from '../core/config.ts' -import { formatDuration } from '../core/formatting.ts' +import { formatDuration, todayIsoDate } from '../core/formatting.ts' import { parsePackageNames, parsePackages, readLock, writeLock } from '../core/lockfile.ts' import { parseFrontmatter } from '../core/markdown.ts' import { getSharedSkillsDir, semverDiff, SHARED_SKILLS_DIR } from '../core/shared.ts' @@ -566,7 +566,7 @@ async function syncBaseSkill( version, repo: repoSlug, source: resources.docSource, - syncedAt: new Date().toISOString().split('T')[0], + syncedAt: todayIsoDate(), generator: 'skilld', }) diff --git a/src/commands/sync-shared.ts b/src/commands/sync-shared.ts index f67e8121..e0f5e1bd 100644 --- a/src/commands/sync-shared.ts +++ b/src/commands/sync-shared.ts @@ -36,6 +36,7 @@ import { } from '../cache/index.ts' import { isInteractive, NO_MODELS_MESSAGE, pickModel } from '../cli-helpers.ts' import { defaultFeatures, readConfig, registerProject, updateConfig } from '../core/config.ts' +import { todayIsoDate } from '../core/formatting.ts' import { parsePackages, readLock, writeLock } from '../core/lockfile.ts' import { parseFrontmatter } from '../core/markdown.ts' import { readPackageJsonSafe } from '../core/package-json.ts' @@ -239,7 +240,7 @@ export function handleShippedSkills( packageName, version, source: 'shipped', - syncedAt: new Date().toISOString().split('T')[0], + syncedAt: todayIsoDate(), generator: 'skilld', }) } diff --git a/src/commands/sync.ts b/src/commands/sync.ts index 5ca0a262..097a3777 100644 --- a/src/commands/sync.ts +++ b/src/commands/sync.ts @@ -35,7 +35,7 @@ import { } from '../cache/index.ts' import { getInstalledGenerators, introLine, isInteractive, promptForAgent, resolveAgent, sharedArgs, suggestPrepareHook } from '../cli-helpers.ts' import { defaultFeatures, hasCompletedWizard, readConfig, registerProject } from '../core/config.ts' -import { timedSpinner } from '../core/formatting.ts' +import { timedSpinner, todayIsoDate } from '../core/formatting.ts' import { parsePackageNames, parsePackages, readLock, removeLockEntry, writeLock } from '../core/lockfile.ts' import { parseFrontmatter } from '../core/markdown.ts' import { parseSkillInput, resolveSkillName, toStoragePackageName } from '../core/prefix.ts' @@ -467,7 +467,7 @@ async function syncSinglePackage(packageSpec: string, config: SyncConfig): Promi version, repo: repoSlug, source: existingLock.source, - syncedAt: new Date().toISOString().split('T')[0], + syncedAt: todayIsoDate(), generator: 'skilld', }) @@ -579,7 +579,7 @@ async function syncSinglePackage(packageSpec: string, config: SyncConfig): Promi version, repo: repoSlug, source: resources.docSource, - syncedAt: new Date().toISOString().split('T')[0], + syncedAt: todayIsoDate(), generator: 'skilld', }) @@ -1255,7 +1255,7 @@ export async function exportPortablePrompts(packageSpec: string, opts: { version, repo: repoSlug, source: resources.docSource, - syncedAt: new Date().toISOString().split('T')[0], + syncedAt: todayIsoDate(), generator: 'skilld', }) diff --git a/src/core/formatting.ts b/src/core/formatting.ts index 0c337d9a..e72c4611 100644 --- a/src/core/formatting.ts +++ b/src/core/formatting.ts @@ -2,6 +2,10 @@ import type { SearchSnippet } from '../retriv/index.ts' import type { ProjectState } from './skills.ts' import * as p from '@clack/prompts' +export function todayIsoDate(): string { + return new Date().toISOString().split('T')[0]! +} + export function timeAgo(iso?: string): string { if (!iso) return '' diff --git a/test/unit/formatting.test.ts b/test/unit/formatting.test.ts new file mode 100644 index 00000000..40607d98 --- /dev/null +++ b/test/unit/formatting.test.ts @@ -0,0 +1,13 @@ +import { describe, expect, it, vi } from 'vitest' +import { todayIsoDate } from '../../src/core/formatting' + +describe('formatting', () => { + it('formats the current UTC day as YYYY-MM-DD', () => { + vi.useFakeTimers() + vi.setSystemTime(new Date('2026-04-28T23:59:59.000Z')) + + expect(todayIsoDate()).toBe('2026-04-28') + + vi.useRealTimers() + }) +})