refactor(db): group database domain modules

This commit is contained in:
ZacharyZhang-NY committed 2026-04-22 19:24:25 -04:00
1 parent e43a89096d
commit 6da0a58769
160 files changed
+2124 -1999

No files matched your search

+3 -3
View File
@@ -72,16 +72,16 @@ export function autoAssignSkillsForHire(
return { assignedSkillIds: [] };
}
const alreadyAssigned = new Set(db.skills.listAgentSkillAssignments(input.agentId));
const alreadyAssigned = new Set(db.core.skills.listAgentSkillAssignments(input.agentId));
const wanted = new Set(categories);
const catalogue = db.skills.listCompanySkills(input.companyId);
const catalogue = db.core.skills.listCompanySkills(input.companyId);
const assigned: string[] = [];
for (const skill of catalogue) {
if (alreadyAssigned.has(skill.id)) continue;
const category = readBuiltinCategory(skill.metadata);
if (!category || !wanted.has(category)) continue;
db.skills.assignSkillToAgent(input.agentId, skill.id);
db.core.skills.assignSkillToAgent(input.agentId, skill.id);
assigned.push(skill.id);
}
+8 -8
View File
@@ -23,11 +23,11 @@ export function createSkillCrud({ db, logger, cleanupSkillFiles, parseGitHubUrl
}
function listForCompany(companyId: string): SkillRecord[] {
return db.skills.listCompanySkills(companyId);
return db.core.skills.listCompanySkills(companyId);
}
function getDetail(companyId: string, skillId: string): DesktopResult<SkillRecord> {
const skill = db.skills.getCompanySkill(companyId, skillId);
const skill = db.core.skills.getCompanySkill(companyId, skillId);
if (!skill) return fail("not_found", `Skill ${skillId} not found`);
return ok(skill);
}
@@ -36,12 +36,12 @@ export function createSkillCrud({ db, logger, cleanupSkillFiles, parseGitHubUrl
companyId: string,
skillId: string,
): Promise<DesktopResult<void>> {
const skill = db.skills.getCompanySkill(companyId, skillId);
const skill = db.core.skills.getCompanySkill(companyId, skillId);
if (!skill) return fail("not_found", `Skill ${skillId} not found`);
try {
await cleanupSkillFiles(companyId, skill.slug);
db.skills.deleteCompanySkill(companyId, skillId);
db.core.skills.deleteCompanySkill(companyId, skillId);
logger.info(`Skill deleted: ${skill.key}`);
return ok(undefined);
} catch (err) {
@@ -56,9 +56,9 @@ export function createSkillCrud({ db, logger, cleanupSkillFiles, parseGitHubUrl
agentId: string,
skillId: string,
): DesktopResult<void> {
const skill = db.skills.getCompanySkill(companyId, skillId);
const skill = db.core.skills.getCompanySkill(companyId, skillId);
if (!skill) return fail("not_found", `Skill ${skillId} not found for company`);
db.skills.assignSkillToAgent(agentId, skillId);
db.core.skills.assignSkillToAgent(agentId, skillId);
return ok(undefined);
}
@@ -67,7 +67,7 @@ export function createSkillCrud({ db, logger, cleanupSkillFiles, parseGitHubUrl
agentId: string,
skillId: string,
): DesktopResult<void> {
db.skills.removeSkillFromAgent(agentId, skillId);
db.core.skills.removeSkillFromAgent(agentId, skillId);
return ok(undefined);
}
@@ -75,7 +75,7 @@ export function createSkillCrud({ db, logger, cleanupSkillFiles, parseGitHubUrl
companyId: string,
skillId: string,
): Promise<DesktopResult<SkillUpdateStatus>> {
const skill = db.skills.getCompanySkill(companyId, skillId);
const skill = db.core.skills.getCompanySkill(companyId, skillId);
if (!skill) return fail("not_found", `Skill ${skillId} not found`);
if (skill.sourceType !== "github" && skill.sourceType !== "skills_sh") {
+1 -1
View File
@@ -155,7 +155,7 @@ export function createGitHubImporter({ db, logger, skillFilesDir }: GitHubImport
await materializeSkillFiles(companyId, rawSlug, ghSkill.markdown, inventory);
const { isUpdate } = db.skills.upsertCompanySkill({
const { isUpdate } = db.core.skills.upsertCompanySkill({
id: skillId,
companyId,
key,
+2 -2
View File
@@ -69,7 +69,7 @@ export async function importFromLocal(
const skillId = randomUUID();
await materializeSkillFiles(skillFilesDir(companyId, rawSlug), markdown, inventory);
const { isUpdate } = db.skills.upsertCompanySkill({
const { isUpdate } = db.core.skills.upsertCompanySkill({
id: skillId,
companyId,
key,
@@ -121,7 +121,7 @@ export async function importFromLocal(
const skillId = randomUUID();
await materializeSkillFiles(skillFilesDir(companyId, rawSlug), markdown, inventory);
const { isUpdate } = db.skills.upsertCompanySkill({
const { isUpdate } = db.core.skills.upsertCompanySkill({
id: skillId,
companyId,
key,
+1 -1
View File
@@ -59,7 +59,7 @@ export async function importFromUrl(
const skillId = randomUUID();
await materializeSkillFiles(skillFilesDir(companyId, rawSlug), markdown, inventory);
const { isUpdate } = db.skills.upsertCompanySkill({
const { isUpdate } = db.core.skills.upsertCompanySkill({
id: skillId,
companyId,
key,
+5 -5
View File
@@ -35,9 +35,9 @@ export function createSkillRuntime({ db, logger, skillsRoot, skillFilesDir, impo
agentId: string,
_connectorId: string,
): ProjectedSkill[] {
const assignedIds = new Set(db.skills.listAgentSkillAssignments(agentId));
const assignedIds = new Set(db.core.skills.listAgentSkillAssignments(agentId));
if (assignedIds.size === 0) return [];
const companySkills = db.skills.listCompanySkills(companyId);
const companySkills = db.core.skills.listCompanySkills(companyId);
const skillPaths = companySkills
.filter((s) => assignedIds.has(s.id))
.map((s) => skillFilesDir(companyId, s.slug));
@@ -82,7 +82,7 @@ export function createSkillRuntime({ db, logger, skillsRoot, skillFilesDir, impo
}
}
const workspacePaths = db.workspacesMod.listWorkspaceLocalPaths(companyId);
const workspacePaths = db.core.workspaces.listWorkspaceLocalPaths(companyId);
for (const wsPath of workspacePaths) {
const agentcompanySkillsDir = join(wsPath, ".agentcompany", "skills");
if (!existsSync(agentcompanySkillsDir)) continue;
@@ -159,12 +159,12 @@ export function createSkillRuntime({ db, logger, skillsRoot, skillFilesDir, impo
const results = await importFromLocal(companyId, categoryDir);
for (const result of results) {
try {
const skill = db.skills.getCompanySkill(companyId, result.skillId);
const skill = db.core.skills.getCompanySkill(companyId, result.skillId);
if (skill) {
const existingMeta = skill.metadata ? JSON.parse(typeof skill.metadata === "string" ? skill.metadata : JSON.stringify(skill.metadata)) : {};
existingMeta.builtinCategory = category;
existingMeta.sourceKind = "builtin";
db.skills.updateCompanySkillMetadata(companyId, result.skillId, JSON.stringify(existingMeta));
db.core.skills.updateCompanySkillMetadata(companyId, result.skillId, JSON.stringify(existingMeta));
}
} catch (error) {
logger.warn(