chore: migrate to oxlint and oxfmt
Co-authored-by: Christoph Nakazawa <christoph.pojer@gmail.com>
This commit is contained in:
@@ -16,10 +16,7 @@ function isTruthy(value: unknown): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
export function resolveConfigPath(
|
||||
config: ClawdbotConfig | undefined,
|
||||
pathStr: string,
|
||||
) {
|
||||
export function resolveConfigPath(config: ClawdbotConfig | undefined, pathStr: string) {
|
||||
const parts = pathStr.split(".").filter(Boolean);
|
||||
let current: unknown = config;
|
||||
for (const part of parts) {
|
||||
@@ -29,10 +26,7 @@ export function resolveConfigPath(
|
||||
return current;
|
||||
}
|
||||
|
||||
export function isConfigPathTruthy(
|
||||
config: ClawdbotConfig | undefined,
|
||||
pathStr: string,
|
||||
): boolean {
|
||||
export function isConfigPathTruthy(config: ClawdbotConfig | undefined, pathStr: string): boolean {
|
||||
const value = resolveConfigPath(config, pathStr);
|
||||
if (value === undefined && pathStr in DEFAULT_CONFIG_VALUES) {
|
||||
return DEFAULT_CONFIG_VALUES[pathStr] === true;
|
||||
@@ -66,16 +60,11 @@ function isBundledSkill(entry: SkillEntry): boolean {
|
||||
return entry.skill.source === "clawdbot-bundled";
|
||||
}
|
||||
|
||||
export function resolveBundledAllowlist(
|
||||
config?: ClawdbotConfig,
|
||||
): string[] | undefined {
|
||||
export function resolveBundledAllowlist(config?: ClawdbotConfig): string[] | undefined {
|
||||
return normalizeAllowlist(config?.skills?.allowBundled);
|
||||
}
|
||||
|
||||
export function isBundledSkillAllowed(
|
||||
entry: SkillEntry,
|
||||
allowlist?: string[],
|
||||
): boolean {
|
||||
export function isBundledSkillAllowed(entry: SkillEntry, allowlist?: string[]): boolean {
|
||||
if (!allowlist || allowlist.length === 0) return true;
|
||||
if (!isBundledSkill(entry)) return true;
|
||||
const key = resolveSkillKey(entry.skill, entry);
|
||||
|
||||
@@ -3,10 +3,7 @@ import { resolveSkillConfig } from "./config.js";
|
||||
import { resolveSkillKey } from "./frontmatter.js";
|
||||
import type { SkillEntry, SkillSnapshot } from "./types.js";
|
||||
|
||||
export function applySkillEnvOverrides(params: {
|
||||
skills: SkillEntry[];
|
||||
config?: ClawdbotConfig;
|
||||
}) {
|
||||
export function applySkillEnvOverrides(params: { skills: SkillEntry[]; config?: ClawdbotConfig }) {
|
||||
const { skills, config } = params;
|
||||
const updates: Array<{ key: string; prev: string | undefined }> = [];
|
||||
|
||||
@@ -58,11 +55,7 @@ export function applySkillEnvOverridesFromSnapshot(params: {
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
skill.primaryEnv &&
|
||||
skillConfig.apiKey &&
|
||||
!process.env[skill.primaryEnv]
|
||||
) {
|
||||
if (skill.primaryEnv && skillConfig.apiKey && !process.env[skill.primaryEnv]) {
|
||||
updates.push({
|
||||
key: skill.primaryEnv,
|
||||
prev: process.env[skill.primaryEnv],
|
||||
|
||||
@@ -53,11 +53,7 @@ function parseInstallSpec(input: unknown): SkillInstallSpec | undefined {
|
||||
if (!input || typeof input !== "object") return undefined;
|
||||
const raw = input as Record<string, unknown>;
|
||||
const kindRaw =
|
||||
typeof raw.kind === "string"
|
||||
? raw.kind
|
||||
: typeof raw.type === "string"
|
||||
? raw.type
|
||||
: "";
|
||||
typeof raw.kind === "string" ? raw.kind : typeof raw.type === "string" ? raw.type : "";
|
||||
const kind = kindRaw.trim().toLowerCase();
|
||||
if (kind !== "brew" && kind !== "node" && kind !== "go" && kind !== "uv") {
|
||||
return undefined;
|
||||
@@ -78,10 +74,7 @@ function parseInstallSpec(input: unknown): SkillInstallSpec | undefined {
|
||||
return spec;
|
||||
}
|
||||
|
||||
function getFrontmatterValue(
|
||||
frontmatter: ParsedSkillFrontmatter,
|
||||
key: string,
|
||||
): string | undefined {
|
||||
function getFrontmatterValue(frontmatter: ParsedSkillFrontmatter, key: string): string | undefined {
|
||||
const raw = frontmatter[key];
|
||||
return typeof raw === "string" ? raw : undefined;
|
||||
}
|
||||
@@ -101,32 +94,17 @@ export function resolveClawdbotMetadata(
|
||||
typeof clawdbotObj.requires === "object" && clawdbotObj.requires !== null
|
||||
? (clawdbotObj.requires as Record<string, unknown>)
|
||||
: undefined;
|
||||
const installRaw = Array.isArray(clawdbotObj.install)
|
||||
? (clawdbotObj.install as unknown[])
|
||||
: [];
|
||||
const installRaw = Array.isArray(clawdbotObj.install) ? (clawdbotObj.install as unknown[]) : [];
|
||||
const install = installRaw
|
||||
.map((entry) => parseInstallSpec(entry))
|
||||
.filter((entry): entry is SkillInstallSpec => Boolean(entry));
|
||||
const osRaw = normalizeStringList(clawdbotObj.os);
|
||||
return {
|
||||
always:
|
||||
typeof clawdbotObj.always === "boolean"
|
||||
? clawdbotObj.always
|
||||
: undefined,
|
||||
emoji:
|
||||
typeof clawdbotObj.emoji === "string" ? clawdbotObj.emoji : undefined,
|
||||
homepage:
|
||||
typeof clawdbotObj.homepage === "string"
|
||||
? clawdbotObj.homepage
|
||||
: undefined,
|
||||
skillKey:
|
||||
typeof clawdbotObj.skillKey === "string"
|
||||
? clawdbotObj.skillKey
|
||||
: undefined,
|
||||
primaryEnv:
|
||||
typeof clawdbotObj.primaryEnv === "string"
|
||||
? clawdbotObj.primaryEnv
|
||||
: undefined,
|
||||
always: typeof clawdbotObj.always === "boolean" ? clawdbotObj.always : undefined,
|
||||
emoji: typeof clawdbotObj.emoji === "string" ? clawdbotObj.emoji : undefined,
|
||||
homepage: typeof clawdbotObj.homepage === "string" ? clawdbotObj.homepage : undefined,
|
||||
skillKey: typeof clawdbotObj.skillKey === "string" ? clawdbotObj.skillKey : undefined,
|
||||
primaryEnv: typeof clawdbotObj.primaryEnv === "string" ? clawdbotObj.primaryEnv : undefined,
|
||||
os: osRaw.length > 0 ? osRaw : undefined,
|
||||
requires: requiresRaw
|
||||
? {
|
||||
|
||||
@@ -13,11 +13,7 @@ import { resolveBundledSkillsDir } from "./bundled-dir.js";
|
||||
import { shouldIncludeSkill } from "./config.js";
|
||||
import { parseFrontmatter, resolveClawdbotMetadata } from "./frontmatter.js";
|
||||
import { serializeByKey } from "./serialize.js";
|
||||
import type {
|
||||
ParsedSkillFrontmatter,
|
||||
SkillEntry,
|
||||
SkillSnapshot,
|
||||
} from "./types.js";
|
||||
import type { ParsedSkillFrontmatter, SkillEntry, SkillSnapshot } from "./types.js";
|
||||
|
||||
const fsp = fs.promises;
|
||||
|
||||
@@ -26,23 +22,17 @@ function filterSkillEntries(
|
||||
config?: ClawdbotConfig,
|
||||
skillFilter?: string[],
|
||||
): SkillEntry[] {
|
||||
let filtered = entries.filter((entry) =>
|
||||
shouldIncludeSkill({ entry, config }),
|
||||
);
|
||||
let filtered = entries.filter((entry) => shouldIncludeSkill({ entry, config }));
|
||||
// If skillFilter is provided, only include skills in the filter list.
|
||||
if (skillFilter !== undefined) {
|
||||
const normalized = skillFilter
|
||||
.map((entry) => String(entry).trim())
|
||||
.filter(Boolean);
|
||||
const normalized = skillFilter.map((entry) => String(entry).trim()).filter(Boolean);
|
||||
const label = normalized.length > 0 ? normalized.join(", ") : "(none)";
|
||||
console.log(`[skills] Applying skill filter: ${label}`);
|
||||
filtered =
|
||||
normalized.length > 0
|
||||
? filtered.filter((entry) => normalized.includes(entry.skill.name))
|
||||
: [];
|
||||
console.log(
|
||||
`[skills] After filter: ${filtered.map((entry) => entry.skill.name).join(", ")}`,
|
||||
);
|
||||
console.log(`[skills] After filter: ${filtered.map((entry) => entry.skill.name).join(", ")}`);
|
||||
}
|
||||
return filtered;
|
||||
}
|
||||
@@ -69,8 +59,7 @@ function loadSkillEntries(
|
||||
return [];
|
||||
};
|
||||
|
||||
const managedSkillsDir =
|
||||
opts?.managedSkillsDir ?? path.join(CONFIG_DIR, "skills");
|
||||
const managedSkillsDir = opts?.managedSkillsDir ?? path.join(CONFIG_DIR, "skills");
|
||||
const workspaceSkillsDir = path.join(workspaceDir, "skills");
|
||||
const bundledSkillsDir = opts?.bundledSkillsDir ?? resolveBundledSkillsDir();
|
||||
const extraDirsRaw = opts?.config?.skills?.load?.extraDirs ?? [];
|
||||
@@ -107,22 +96,20 @@ function loadSkillEntries(
|
||||
for (const skill of managedSkills) merged.set(skill.name, skill);
|
||||
for (const skill of workspaceSkills) merged.set(skill.name, skill);
|
||||
|
||||
const skillEntries: SkillEntry[] = Array.from(merged.values()).map(
|
||||
(skill) => {
|
||||
let frontmatter: ParsedSkillFrontmatter = {};
|
||||
try {
|
||||
const raw = fs.readFileSync(skill.filePath, "utf-8");
|
||||
frontmatter = parseFrontmatter(raw);
|
||||
} catch {
|
||||
// ignore malformed skills
|
||||
}
|
||||
return {
|
||||
skill,
|
||||
frontmatter,
|
||||
clawdbot: resolveClawdbotMetadata(frontmatter),
|
||||
};
|
||||
},
|
||||
);
|
||||
const skillEntries: SkillEntry[] = Array.from(merged.values()).map((skill) => {
|
||||
let frontmatter: ParsedSkillFrontmatter = {};
|
||||
try {
|
||||
const raw = fs.readFileSync(skill.filePath, "utf-8");
|
||||
frontmatter = parseFrontmatter(raw);
|
||||
} catch {
|
||||
// ignore malformed skills
|
||||
}
|
||||
return {
|
||||
skill,
|
||||
frontmatter,
|
||||
clawdbot: resolveClawdbotMetadata(frontmatter),
|
||||
};
|
||||
});
|
||||
return skillEntries;
|
||||
}
|
||||
|
||||
@@ -138,11 +125,7 @@ export function buildWorkspaceSkillSnapshot(
|
||||
},
|
||||
): SkillSnapshot {
|
||||
const skillEntries = opts?.entries ?? loadSkillEntries(workspaceDir, opts);
|
||||
const eligible = filterSkillEntries(
|
||||
skillEntries,
|
||||
opts?.config,
|
||||
opts?.skillFilter,
|
||||
);
|
||||
const eligible = filterSkillEntries(skillEntries, opts?.config, opts?.skillFilter);
|
||||
const resolvedSkills = eligible.map((entry) => entry.skill);
|
||||
return {
|
||||
prompt: formatSkillsForPrompt(resolvedSkills),
|
||||
@@ -166,11 +149,7 @@ export function buildWorkspaceSkillsPrompt(
|
||||
},
|
||||
): string {
|
||||
const skillEntries = opts?.entries ?? loadSkillEntries(workspaceDir, opts);
|
||||
const eligible = filterSkillEntries(
|
||||
skillEntries,
|
||||
opts?.config,
|
||||
opts?.skillFilter,
|
||||
);
|
||||
const eligible = filterSkillEntries(skillEntries, opts?.config, opts?.skillFilter);
|
||||
return formatSkillsForPrompt(eligible.map((entry) => entry.skill));
|
||||
}
|
||||
|
||||
@@ -234,11 +213,8 @@ export async function syncSkillsToWorkspace(params: {
|
||||
force: true,
|
||||
});
|
||||
} catch (error) {
|
||||
const message =
|
||||
error instanceof Error ? error.message : JSON.stringify(error);
|
||||
console.warn(
|
||||
`[skills] Failed to copy ${entry.skill.name} to sandbox: ${message}`,
|
||||
);
|
||||
const message = error instanceof Error ? error.message : JSON.stringify(error);
|
||||
console.warn(`[skills] Failed to copy ${entry.skill.name} to sandbox: ${message}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user