mirror of
https://github.com/rohitg00/skillkit.git
synced 2026-11-20 20:34:46 +00:00
83 lines
2.9 KiB
TypeScript
83 lines
2.9 KiB
TypeScript
import {
|
|
loadConfig,
|
|
getSearchDirs as coreGetSearchDirs,
|
|
getInstallDir as coreGetInstallDir,
|
|
getAgentConfigPath as coreGetAgentConfigPath,
|
|
initProject as coreInitProject,
|
|
loadSkillMetadata as coreLoadSkillMetadata,
|
|
saveSkillMetadata as coreSaveSkillMetadata,
|
|
} from "@skillkit/core";
|
|
import { getAdapter, detectAgent, getAllAdapters } from "@skillkit/agents";
|
|
import type { AgentType, AgentAdapterInfo } from "@skillkit/core";
|
|
|
|
export const loadSkillMetadata = coreLoadSkillMetadata;
|
|
export const saveSkillMetadata = coreSaveSkillMetadata;
|
|
|
|
function toAdapterInfo(adapter: { type: AgentType; name: string; skillsDir: string; configFile: string }): AgentAdapterInfo {
|
|
return { type: adapter.type, name: adapter.name, skillsDir: adapter.skillsDir, configFile: adapter.configFile };
|
|
}
|
|
|
|
export function getSearchDirs(agentType?: AgentType): string[] {
|
|
const dirs = new Set<string>();
|
|
const adapters = agentType ? [getAdapter(agentType)] : getAllAdapters();
|
|
for (const adapter of adapters) {
|
|
for (const dir of coreGetSearchDirs(toAdapterInfo(adapter))) {
|
|
dirs.add(dir);
|
|
}
|
|
}
|
|
return [...dirs];
|
|
}
|
|
|
|
export function getInstallDir(global = false, agentType?: AgentType): string {
|
|
const type = agentType || loadConfig().agent;
|
|
return coreGetInstallDir(toAdapterInfo(getAdapter(type)), global);
|
|
}
|
|
|
|
export function getAgentConfigPath(agentType?: AgentType): string {
|
|
const type = agentType || loadConfig().agent;
|
|
return coreGetAgentConfigPath(toAdapterInfo(getAdapter(type)));
|
|
}
|
|
|
|
export async function initProject(agentType?: AgentType): Promise<void> {
|
|
const type = agentType || (await detectAgent());
|
|
return coreInitProject(type, toAdapterInfo(getAdapter(type)));
|
|
}
|
|
|
|
export function formatCount(count: number): string {
|
|
if (count >= 1_000_000) return `${(count / 1_000_000).toFixed(1)}M`;
|
|
if (count >= 1_000) return `${(count / 1_000).toFixed(1)}K`;
|
|
return String(count);
|
|
}
|
|
|
|
export function timeAgo(dateStr: string): string {
|
|
const now = Date.now();
|
|
const then = new Date(dateStr).getTime();
|
|
if (Number.isNaN(then)) return 'unknown';
|
|
const days = Math.floor((now - then) / 86_400_000);
|
|
if (days === 0) return 'today';
|
|
if (days === 1) return 'yesterday';
|
|
if (days < 30) return `${days}d ago`;
|
|
if (days < 365) return `${Math.floor(days / 30)}mo ago`;
|
|
return `${Math.floor(days / 365)}y ago`;
|
|
}
|
|
|
|
export async function fetchGitHubActivity(
|
|
owner: string,
|
|
repo: string,
|
|
): Promise<{ stars: number; pushedAt: string | null } | null> {
|
|
try {
|
|
const response = await fetch(
|
|
`https://api.github.com/repos/${owner}/${repo}`,
|
|
{ signal: AbortSignal.timeout(5000) },
|
|
);
|
|
if (!response.ok) return null;
|
|
const data = (await response.json()) as Record<string, unknown>;
|
|
return {
|
|
stars: typeof data.stargazers_count === 'number' ? data.stargazers_count : 0,
|
|
pushedAt: typeof data.pushed_at === 'string' ? data.pushed_at : null,
|
|
};
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|