simplify: extract toAdapterInfo helper, remove spawnGit overloads

- helpers.ts: extract toAdapterInfo() to eliminate 4x repeated object
  construction
- base.ts: remove redundant spawnGit overload signatures, remove
  ?? (() => {}) since spawnGit already handles undefined onProgress
This commit is contained in:
Rohit Ghumare
2026-04-10 22:06:06 +01:00
parent 84fb16486b
commit b1e1e2f266
2 changed files with 12 additions and 44 deletions
+9 -39
View File
@@ -1,4 +1,3 @@
// Re-export commonly used functions with proper adapters
import {
loadConfig,
getSearchDirs as coreGetSearchDirs,
@@ -11,66 +10,37 @@ import {
import { getAdapter, detectAgent, getAllAdapters } from "@skillkit/agents";
import type { AgentType, AgentAdapterInfo } from "@skillkit/core";
// Re-export metadata functions directly (they don't need adapter bridging)
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();
const adapters = agentType ? [getAdapter(agentType)] : getAllAdapters();
for (const adapter of adapters) {
const info: AgentAdapterInfo = {
type: adapter.type,
name: adapter.name,
skillsDir: adapter.skillsDir,
configFile: adapter.configFile,
};
for (const dir of coreGetSearchDirs(info)) {
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;
const adapter = getAdapter(type);
const adapterInfo: AgentAdapterInfo = {
type: adapter.type,
name: adapter.name,
skillsDir: adapter.skillsDir,
configFile: adapter.configFile,
};
return coreGetInstallDir(adapterInfo, global);
return coreGetInstallDir(toAdapterInfo(getAdapter(type)), global);
}
export function getAgentConfigPath(agentType?: AgentType): string {
const type = agentType || loadConfig().agent;
const adapter = getAdapter(type);
const adapterInfo: AgentAdapterInfo = {
type: adapter.type,
name: adapter.name,
skillsDir: adapter.skillsDir,
configFile: adapter.configFile,
};
return coreGetAgentConfigPath(adapterInfo);
return coreGetAgentConfigPath(toAdapterInfo(getAdapter(type)));
}
export async function initProject(agentType?: AgentType): Promise<void> {
const type = agentType || (await detectAgent());
const adapter = getAdapter(type);
const adapterInfo: AgentAdapterInfo = {
type: adapter.type,
name: adapter.name,
skillsDir: adapter.skillsDir,
configFile: adapter.configFile,
};
return coreInitProject(type, adapterInfo);
return coreInitProject(type, toAdapterInfo(getAdapter(type)));
}
export function formatCount(count: number): string {
+3 -5
View File
@@ -50,8 +50,6 @@ function parseGitProgress(text: string): string | null {
return null;
}
function spawnGit(args: string[]): Promise<void>;
function spawnGit(args: string[], onProgress: (msg: string) => void): Promise<void>;
function spawnGit(args: string[], onProgress?: (msg: string) => void): Promise<void> {
return new Promise<void>((resolve, reject) => {
const proc = spawn('git', args, { stdio: ['pipe', 'ignore', 'pipe'] });
@@ -96,7 +94,7 @@ export async function cloneRepo(
let partialCloneOk = false;
try {
await spawnGit(partialArgs, options.onProgress ?? (() => {}));
await spawnGit(partialArgs, options.onProgress);
partialCloneOk = true;
} catch {
options.onProgress?.('Partial clone unsupported, falling back to full clone');
@@ -124,14 +122,14 @@ export async function cloneRepo(
);
options.onProgress?.('Checking out files');
await spawnGit(['-C', tempDir, 'checkout'], options.onProgress ?? (() => {}));
await spawnGit(['-C', tempDir, 'checkout'], options.onProgress);
return;
}
}
args.push(cloneUrl, tempDir);
await spawnGit(args, options.onProgress ?? (() => {}));
await spawnGit(args, options.onProgress);
}
export function parseShorthand(source: string): { owner: string; repo: string; subpath?: string } | null {