large update

This commit is contained in:
ZacharyZhang-NY committed 2026-03-29 14:08:15 -04:00
1 parent 2ed952f19c
commit 65e85135c1
111 files changed
+3936 -2933

No files matched your search

+1 -40
View File
@@ -1,7 +1,5 @@
// ---------------------------------------------------------------------------
// SkillService -- full skill lifecycle: import, CRUD, assignment, token budget,
// update detection. Factory pattern following createOrchestrationService.
// ---------------------------------------------------------------------------
import { randomUUID } from "node:crypto";
import { existsSync, mkdirSync, readdirSync, readFileSync, statSync } from "node:fs";
@@ -35,10 +33,7 @@ import {
} from "./skill-github.js";
import { TOKEN_BUDGETS } from "./skill-types.js";
// ---------------------------------------------------------------------------
// Types
// ---------------------------------------------------------------------------
interface SkillServiceDependencies {
db: AppDatabase;
profileDir: string;
@@ -49,10 +44,7 @@ interface SkillServiceDependencies {
};
}
// ---------------------------------------------------------------------------
// Factory
// ---------------------------------------------------------------------------
export function createSkillService({ db, profileDir, logger }: SkillServiceDependencies) {
// ---- Result helpers ----
function ok<T>(data: T): DesktopResult<T> {
@@ -75,8 +67,6 @@ export function createSkillService({ db, profileDir, logger }: SkillServiceDepen
return join(skillsRoot(companyId), "__runtime__");
}
// ---- File materialization helpers ----
/**
* Write SKILL.md (and tracked inventory files from GitHub downloads)
* to the local skill directory.
@@ -101,8 +91,6 @@ export function createSkillService({ db, profileDir, logger }: SkillServiceDepen
}
}
// ---- GitHub URL parser ----
function parseGitHubUrl(url: string): { owner: string; repo: string } | null {
try {
const parsed = new URL(url);
@@ -118,8 +106,6 @@ export function createSkillService({ db, profileDir, logger }: SkillServiceDepen
}
}
// ---- Import routing ----
/**
* Import skills from any supported source.
* Routes to the correct handler based on parseSkillImportSource.
@@ -178,8 +164,6 @@ export function createSkillService({ db, profileDir, logger }: SkillServiceDepen
}
}
// ---- GitHub import (SKILL-01) ----
async function importFromGitHub(
companyId: string,
url: string,
@@ -296,8 +280,6 @@ export function createSkillService({ db, profileDir, logger }: SkillServiceDepen
return results;
}
// ---- Local path import (SKILL-02, D-04) ----
async function importFromLocal(
companyId: string,
localPath: string,
@@ -416,8 +398,6 @@ export function createSkillService({ db, profileDir, logger }: SkillServiceDepen
return results;
}
// ---- URL import (SKILL-03, D-05) ----
async function importFromUrl(
companyId: string,
url: string,
@@ -487,8 +467,6 @@ export function createSkillService({ db, profileDir, logger }: SkillServiceDepen
return results;
}
// ---- CRUD ----
function listForCompany(companyId: string): SkillRecord[] {
return db.listCompanySkills(companyId);
}
@@ -522,8 +500,6 @@ export function createSkillService({ db, profileDir, logger }: SkillServiceDepen
}
}
// ---- Agent assignment (SKILL-07) ----
function assignToAgent(
companyId: string,
agentId: string,
@@ -544,8 +520,6 @@ export function createSkillService({ db, profileDir, logger }: SkillServiceDepen
return ok(undefined);
}
// ---- Update detection (SKILL-11, D-11) ----
async function checkUpdateStatus(
companyId: string,
skillId: string,
@@ -603,8 +577,6 @@ export function createSkillService({ db, profileDir, logger }: SkillServiceDepen
});
}
// ---- Runtime skill entries (SKILL-09 token budget) ----
/**
* Build the list of RuntimeSkillEntry for adapter injection.
* Applies token budget enforcement: skills sorted by creation date,
@@ -617,12 +589,7 @@ export function createSkillService({ db, profileDir, logger }: SkillServiceDepen
): RuntimeSkillEntry[] {
const allSkills = db.listCompanySkills(companyId);
const agentAssignments = db.listAgentSkillAssignments(agentId);
// If agent has specific assignments, filter to those; otherwise use all
const skills =
agentAssignments.length > 0
? allSkills.filter((s) => agentAssignments.includes(s.id))
: allSkills;
const skills = allSkills.filter((s) => agentAssignments.includes(s.id));
// Sort by creation date (oldest first -- first imported gets priority)
const sorted = [...skills].sort(
@@ -653,8 +620,6 @@ export function createSkillService({ db, profileDir, logger }: SkillServiceDepen
return entries;
}
// ---- Local directory walker ----
function findSkillMdFiles(rootDir: string): string[] {
const found: string[] = [];
function walk(dir: string) {
@@ -701,8 +666,6 @@ export function createSkillService({ db, profileDir, logger }: SkillServiceDepen
return inventory;
}
// ---- Workspace .agents/skills/ scanning (Bug 6) ----
/**
* Scan all workspace local paths for a company, looking for
* `.agents/skills/` directories containing SKILL.md files.
@@ -761,8 +724,6 @@ export function createSkillService({ db, profileDir, logger }: SkillServiceDepen
return allResults;
}
// ---- Public API ----
return {
importFromSource,
importFromGitHub,