From a815df126b105c7b9b3f0b816165cd491113ea0e Mon Sep 17 00:00:00 2001 From: oritwoen <18102267+oritwoen@users.noreply.github.com> Date: Tue, 28 Apr 2026 17:14:20 +0200 Subject: [PATCH] refactor: reuse current ISO date helper --- src/agent/prompts/skill.ts | 3 ++- src/commands/prepare.ts | 3 ++- src/commands/sync-git.ts | 6 +++--- src/commands/sync-parallel.ts | 4 ++-- src/commands/sync-shared.ts | 3 ++- src/commands/sync.ts | 8 ++++---- src/core/formatting.ts | 4 ++++ test/unit/formatting.test.ts | 13 +++++++++++++ 8 files changed, 32 insertions(+), 12 deletions(-) create mode 100644 test/unit/formatting.test.ts diff --git a/src/agent/prompts/skill.ts b/src/agent/prompts/skill.ts index 1978961e..755574e7 100644 --- a/src/agent/prompts/skill.ts +++ b/src/agent/prompts/skill.ts @@ -3,6 +3,7 @@ */ import type { FeaturesConfig } from '../../core/config.ts' +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' @@ -220,7 +221,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 9b4146c0..9af9147e 100644 --- a/src/commands/sync-git.ts +++ b/src/commands/sync-git.ts @@ -26,7 +26,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' @@ -153,7 +153,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', }) } @@ -270,7 +270,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 6ab2aff4..75f61dd9 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 { 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 f462a174..59f7c776 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 c1a4fc26..701517ea 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 { parsePackages, readLock, removeLockEntry, writeLock } from '../core/lockfile.ts' import { parseFrontmatter } from '../core/markdown.ts' import { parseSkillInput, resolveSkillName, toStoragePackageName } from '../core/prefix.ts' @@ -466,7 +466,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', }) @@ -1258,7 +1258,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() + }) +})