From b4582c465dbc6f8ac9baab85357a80dcc5ac4677 Mon Sep 17 00:00:00 2001 From: Rohit Ghumare <48523873+rohitg00@users.noreply.github.com> Date: Sat, 11 Apr 2026 11:50:17 +0100 Subject: [PATCH] feat: add centralized lock.json for installed skill tracking Introduce ~/.skillkit/lock.json with LockEntry/LockFile schemas to track all installed skills in a single file. Install writes entries, remove deletes them. Enables future team sync and reproducible setups. --- packages/cli/src/commands/install.ts | 10 +++++++++ packages/cli/src/commands/remove.ts | 3 ++- packages/core/src/config.ts | 31 +++++++++++++++++++++++++++- packages/core/src/types.ts | 17 +++++++++++++++ 4 files changed, 59 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/commands/install.ts b/packages/cli/src/commands/install.ts index 61740c8f..319108ee 100644 --- a/packages/cli/src/commands/install.ts +++ b/packages/cli/src/commands/install.ts @@ -29,6 +29,7 @@ import { TrustScorer, readSkillContent, computeSkillChecksum, + addSkillToLock, } from "@skillkit/core"; import type { SkillsShStats } from "@skillkit/core"; import type { SkillMetadata, GitProvider, AgentType } from "@skillkit/core"; @@ -584,6 +585,15 @@ export class InstallCommand extends Command { metadata.checksum = computeSkillChecksum(targetPath); saveSkillMetadata(targetPath, metadata); + addSkillToLock(skillName, { + source: this.source, + sourceType: providerAdapter!.type, + installedAt: new Date().toISOString(), + checksum: metadata.checksum, + agents: [agentType], + path: targetPath, + }); + installedAgents.push(agentType); s.stop(`Installed ${skillName} to ${adapter.name}${useSymlink ? " (symlink)" : ""}`); } catch (err) { diff --git a/packages/cli/src/commands/remove.ts b/packages/cli/src/commands/remove.ts index 8e061dd1..e67062d8 100644 --- a/packages/cli/src/commands/remove.ts +++ b/packages/cli/src/commands/remove.ts @@ -2,7 +2,7 @@ import { existsSync, rmSync, readFileSync, writeFileSync } from 'node:fs'; import { join, dirname, basename } from 'node:path'; import { colors, warn, success, error } from '../onboarding/index.js'; import { Command, Option } from 'clipanion'; -import { findSkill, findAllSkills, loadMetadata, AgentsMdParser, AgentsMdGenerator } from '@skillkit/core'; +import { findSkill, findAllSkills, loadMetadata, AgentsMdParser, AgentsMdGenerator, removeSkillFromLock } from '@skillkit/core'; import { getSearchDirs } from '../helpers.js'; export class RemoveCommand extends Command { @@ -88,6 +88,7 @@ export class RemoveCommand extends Command { const metaSibling = join(dirname(skillPath), `.${basename(skillPath, '.md')}.skillkit.json`); if (existsSync(metaSibling)) rmSync(metaSibling); } + removeSkillFromLock(skillName); success(`Removed: ${skillName}`); removed++; } catch (err) { diff --git a/packages/core/src/config.ts b/packages/core/src/config.ts index df20f041..4a766230 100644 --- a/packages/core/src/config.ts +++ b/packages/core/src/config.ts @@ -3,7 +3,7 @@ import { join, dirname, basename } from 'node:path'; import { homedir } from 'node:os'; import { createHash } from 'node:crypto'; import { parse as parseYaml, stringify as stringifyYaml } from 'yaml'; -import { SkillkitConfig, type AgentType, type SkillMetadata, type AgentAdapterInfo } from './types.js'; +import { SkillkitConfig, LockFile, type AgentType, type SkillMetadata, type AgentAdapterInfo, type LockEntry } from './types.js'; const CONFIG_FILE = 'skillkit.yaml'; const METADATA_FILE = '.skillkit.json'; @@ -157,6 +157,35 @@ export function computeSkillChecksum(skillPath: string): string { return createHash('sha256').update(readFileSync(mdPath)).digest('hex').slice(0, 16); } +const LOCK_FILE = join(homedir(), '.skillkit', 'lock.json'); + +export function loadLockFile(): LockFile { + if (!existsSync(LOCK_FILE)) return { version: 1, skills: {} }; + try { + return LockFile.parse(JSON.parse(readFileSync(LOCK_FILE, 'utf-8'))); + } catch { + return { version: 1, skills: {} }; + } +} + +export function saveLockFile(lock: LockFile): void { + const dir = dirname(LOCK_FILE); + if (!existsSync(dir)) mkdirSync(dir, { recursive: true }); + writeFileSync(LOCK_FILE, JSON.stringify(lock, null, 2), 'utf-8'); +} + +export function addSkillToLock(name: string, entry: LockEntry): void { + const lock = loadLockFile(); + lock.skills[name] = entry; + saveLockFile(lock); +} + +export function removeSkillFromLock(name: string): void { + const lock = loadLockFile(); + delete lock.skills[name]; + saveLockFile(lock); +} + export async function initProject( type: AgentType, adapter: AgentAdapterInfo diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index d5c04586..e288c99c 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -94,6 +94,23 @@ export const SkillMetadata = z.object({ }); export type SkillMetadata = z.infer; +export const LockEntry = z.object({ + source: z.string(), + sourceType: GitProvider, + installedAt: z.string().datetime(), + updatedAt: z.string().datetime().optional(), + checksum: z.string().optional(), + agents: z.array(z.string()), + path: z.string(), +}); +export type LockEntry = z.infer; + +export const LockFile = z.object({ + version: z.literal(1), + skills: z.record(z.string(), LockEntry), +}); +export type LockFile = z.infer; + export const SkillLocation = z.enum(["project", "global"]); export type SkillLocation = z.infer;