mirror of
https://github.com/rohitg00/skillkit.git
synced 2026-11-18 18:04:26 +00:00
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.
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -94,6 +94,23 @@ export const SkillMetadata = z.object({
|
||||
});
|
||||
export type SkillMetadata = z.infer<typeof SkillMetadata>;
|
||||
|
||||
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<typeof LockEntry>;
|
||||
|
||||
export const LockFile = z.object({
|
||||
version: z.literal(1),
|
||||
skills: z.record(z.string(), LockEntry),
|
||||
});
|
||||
export type LockFile = z.infer<typeof LockFile>;
|
||||
|
||||
export const SkillLocation = z.enum(["project", "global"]);
|
||||
export type SkillLocation = z.infer<typeof SkillLocation>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user