Skip to content

The open-source app everyone uses to manage agents at work

Add project folder browsing to skill imports (#9930)

Dotta717684ad8f5f
diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.ts
index 7ea8c6ac51..3135cf1820 100644
--- a/packages/shared/src/index.ts
+++ b/packages/shared/src/index.ts
@@ -682,6 +682,9 @@ export type {
CompanySkillImportRequest,
CompanySkillImportResult,
CompanySkillProjectScanRequest,
+ CompanySkillProjectBrowseRequest,
+ CompanySkillProjectBrowseEntry,
+ CompanySkillProjectBrowseResult,
CompanySkillProjectScanCandidateStatus,
CompanySkillProjectScanCandidate,
CompanySkillProjectScanSkipped,
@@ -2045,6 +2048,9 @@ export {
companySkillAuditResultSchema,
companySkillImportSchema,
companySkillProjectScanRequestSchema,
+ companySkillProjectBrowseRequestSchema,
+ companySkillProjectBrowseEntrySchema,
+ companySkillProjectBrowseResultSchema,
companySkillProjectScanSkippedSchema,
companySkillProjectScanConflictSchema,
companySkillProjectScanResultSchema,
diff --git a/packages/shared/src/types/company-skill.ts b/packages/shared/src/types/company-skill.ts
index 4d72d2e674..ad8bb1fb63 100644
--- a/packages/shared/src/types/company-skill.ts
+++ b/packages/shared/src/types/company-skill.ts
@@ -343,6 +343,29 @@ export interface CompanySkillProjectScanRequest {
}>;
}
+export interface CompanySkillProjectBrowseRequest {
+ projectId: string;
+ workspaceId: string;
+ path?: string | null;
+}
+
+export interface CompanySkillProjectBrowseEntry {
+ name: string;
+ path: string;
+ kind: "directory" | "file";
+ isSkill: boolean;
+}
+
+export interface CompanySkillProjectBrowseResult {
+ projectId: string;
+ workspaceId: string;
+ workspaceName: string;
+ path: string;
+ parentPath: string | null;
+ entries: CompanySkillProjectBrowseEntry[];
+ truncated: boolean;
+}
+
export type CompanySkillProjectScanCandidateStatus = "new" | "already_imported" | "conflict" | "skipped";
export interface CompanySkillProjectScanCandidate {
diff --git a/packages/shared/src/types/index.ts b/packages/shared/src/types/index.ts
index 59466c41a7..eab32cbc7c 100644
--- a/packages/shared/src/types/index.ts
+++ b/packages/shared/src/types/index.ts
@@ -168,6 +168,9 @@ export type {
CompanySkillImportRequest,
CompanySkillImportResult,
CompanySkillProjectScanRequest,
+ CompanySkillProjectBrowseRequest,
+ CompanySkillProjectBrowseEntry,
+ CompanySkillProjectBrowseResult,
CompanySkillProjectScanCandidateStatus,
CompanySkillProjectScanCandidate,
CompanySkillProjectScanSkipped,
diff --git a/packages/shared/src/validators/company-skill.ts b/packages/shared/src/validators/company-skill.ts
index bc9c7bd292..70bcafde27 100644
--- a/packages/shared/src/validators/company-skill.ts
+++ b/packages/shared/src/validators/company-skill.ts
@@ -286,6 +286,29 @@ export const companySkillProjectScanRequestSchema = z.object({
})).optional(),
});
+export const companySkillProjectBrowseRequestSchema = z.object({
+ projectId: z.string().uuid(),
+ workspaceId: z.string().uuid(),
+ path: z.string().nullable().optional(),
+});
+
+export const companySkillProjectBrowseEntrySchema = z.object({
+ name: z.string().min(1),
+ path: z.string().min(1),
+ kind: z.enum(["directory", "file"]),
+ isSkill: z.boolean(),
+});
+
+export const companySkillProjectBrowseResultSchema = z.object({
+ projectId: z.string().uuid(),
+ workspaceId: z.string().uuid(),
+ workspaceName: z.string().min(1),
+ path: z.string().min(1),
+ parentPath: z.string().nullable(),
+ entries: z.array(companySkillProjectBrowseEntrySchema),
+ truncated: z.boolean(),
+});
+
export const companySkillProjectScanCandidateSchema = z.object({
slug: z.string().min(1),
name: z.string().min(1),
@@ -569,6 +592,7 @@ export const companySkillInstallCatalogResultSchema = z.object({
export type CompanySkillImport = z.infer<typeof companySkillImportSchema>;
export type CompanySkillListQuery = z.infer<typeof companySkillListQuerySchema>;
export type CompanySkillProjectScan = z.infer<typeof companySkillProjectScanRequestSchema>;
+export type CompanySkillProjectBrowse = z.infer<typeof companySkillProjectBrowseRequestSchema>;
export type CompanySkillCreate = z.infer<typeof companySkillCreateSchema>;
export type CompanySkillFileUpdate = z.infer<typeof companySkillFileUpdateSchema>;
export type CompanySkillFileDelete = z.infer<typeof companySkillFileDeleteSchema>;
diff --git a/packages/shared/src/validators/index.ts b/packages/shared/src/validators/index.ts
index ed562e0e45..da5d5ca7a9 100644
--- a/packages/shared/src/validators/index.ts
+++ b/packages/shared/src/validators/index.ts
@@ -185,6 +185,9 @@ export {
companySkillAuditResultSchema,
companySkillImportSchema,
companySkillProjectScanRequestSchema,
+ companySkillProjectBrowseRequestSchema,
+ companySkillProjectBrowseEntrySchema,
+ companySkillProjectBrowseResultSchema,
companySkillProjectScanSkippedSchema,
companySkillProjectScanConflictSchema,
companySkillProjectScanResultSchema,
@@ -218,6 +221,7 @@ export {
type CompanySkillImport,
type CompanySkillListQuery,
type CompanySkillProjectScan,
+ type CompanySkillProjectBrowse,
type CompanySkillCreate,
type CompanySkillFileUpdate,
type CompanySkillTestInputCreate,
diff --git a/server/src/__tests__/company-skills-service.test.ts b/server/src/__tests__/company-skills-service.test.ts
index 4697b67f0c..c2c3541bfc 100644
--- a/server/src/__tests__/company-skills-service.test.ts
+++ b/server/src/__tests__/company-skills-service.test.ts
@@ -2058,6 +2058,66 @@ describeEmbeddedPostgres("companySkillService.list", () => {
expect(versions).toHaveLength(2);
});
+ it("browses project folders and imports a selected non-standard skill", async () => {
+ const companyId = randomUUID();
+ const projectId = randomUUID();
+ const workspaceId = randomUUID();
+ const workspaceDir = await fs.mkdtemp(path.join(os.tmpdir(), "paperclip-skill-browse-"));
+ cleanupDirs.add(workspaceDir);
+ const skillDir = path.join(workspaceDir, "content", "teams", "editorial");
+ await fs.mkdir(skillDir, { recursive: true });
+ await fs.writeFile(path.join(skillDir, "SKILL.md"), "---\nname: Editorial\n---\n", "utf8");
+ await fs.writeFile(path.join(workspaceDir, "content", "README.md"), "# Content\n", "utf8");
+ await fs.writeFile(path.join(workspaceDir, "content", "skill.md"), "# Not a valid skill filename\n", "utf8");
+ for (let entryIndex = 0; entryIndex < 251; entryIndex += 1) {
+ await fs.symlink(skillDir, path.join(workspaceDir, `ignored-${String(entryIndex).padStart(3, "0")}`));
+ }
+ await db.insert(companies).values({
+ id: companyId,
+ name: "Paperclip",
+ issuePrefix: `T${companyId.replace(/-/g, "").slice(0, 6).toUpperCase()}`,
+ requireBoardApprovalForNewAgents: false,
+ });
+ await db.insert(projects).values({ id: projectId, companyId, name: "Skills Project" });
+ await db.insert(projectWorkspaces).values({
+ id: workspaceId,
+ companyId,
+ projectId,
+ name: "Primary",
+ cwd: workspaceDir,
+ isPrimary: true,
+ });
+
+ const root = await svc.browseProjectWorkspace(companyId, { projectId, workspaceId });
+ expect(root.entries).toEqual([expect.objectContaining({ name: "content", kind: "directory", isSkill: false })]);
+ expect(root.truncated).toBe(false);
+
+ const content = await svc.browseProjectWorkspace(companyId, { projectId, workspaceId, path: "content" });
+ expect(content).toMatchObject({ path: "content", parentPath: "." });
+ expect(content.entries).toEqual([
+ expect.objectContaining({ name: "teams", kind: "directory", isSkill: false }),
+ expect.objectContaining({ name: "README.md", kind: "file", isSkill: false }),
+ expect.objectContaining({ name: "skill.md", kind: "file", isSkill: false }),
+ ]);
+
+ const teams = await svc.browseProjectWorkspace(companyId, { projectId, workspaceId, path: "content/teams" });
+ expect(teams.entries).toEqual([
+ expect.objectContaining({
+ name: "editorial",
+ path: "content/teams/editorial",
+ kind: "directory",
+ isSkill: true,
+ }),
+ ]);
+
+ const imported = await svc.scanProjectWorkspaces(companyId, {
+ projectIds: [projectId],
+ mode: "import",
+ selection: [{ workspaceId, path: "content/teams/editorial" }],
+ });
+ expect(imported.imported).toEqual([expect.objectContaining({ name: "Editorial" })]);
+ });
+
it("previews project workspace skill candidates without importing them", async () => {
const companyId = randomUUID();
const projectId = randomUUID();
@@ -2477,7 +2537,9 @@ describeEmbeddedPostgres("companySkillService.list", () => {
const outsideSkillFile = path.join(outsideDir, "outside-skill.md");
await fs.mkdir(linkedSkillDir, { recursive: true });
await fs.writeFile(outsideSkillFile, "---\nname: Outside Skill\n---\n", "utf8");
+ await fs.writeFile(path.join(outsideDir, "SKILL.md"), "---\nname: Outside Directory Skill\n---\n", "utf8");
await fs.symlink(outsideSkillFile, path.join(linkedSkillDir, "SKILL.md"));
+ await fs.symlink(outsideDir, path.join(workspaceDir, "linked-directory"));
await db.insert(companies).values({
id: companyId,
name: "Paperclip",
@@ -2497,7 +2559,10 @@ describeEmbeddedPostgres("companySkillService.list", () => {
const result = await svc.scanProjectWorkspaces(companyId, {
mode: "import",
workspaceIds: [workspaceId],
- selection: [{ workspaceId, path: ".codex/skills/linked-skill" }],
+ selection: [
+ { workspaceId, path: ".codex/skills/linked-skill" },
+ { workspaceId, path: "linked-directory" },
+ ],
});
expect(result.imported).toEqual([]);
@@ -2508,13 +2573,18 @@ describeEmbeddedPostgres("companySkillService.list", () => {
reason: expect.stringContaining("symbolic link"),
}),
]);
- expect(result.skipped).toEqual([
+ expect(result.skipped).toEqual(expect.arrayContaining([
expect.objectContaining({
workspaceId,
path: linkedSkillDir,
reason: expect.stringContaining("symbolic link"),
}),
- ]);
+ expect.objectContaining({
+ workspaceId,
+ path: "linked-directory",
+ reason: expect.stringContaining("was not rediscovered"),
+ }),
+ ]));
expect(result.candidates[0]?.reason).not.toContain(workspaceDir);
expect(result.candidates[0]?.reason).not.toContain(outsideDir);
expect(result.skipped[0]?.reason).not.toContain(workspaceDir);
diff --git a/server/src/__tests__/company-skills.test.ts b/server/src/__tests__/company-skills.test.ts
index d30fb48ce2..eaacabb060 100644
--- a/server/src/__tests__/company-skills.test.ts
+++ b/server/src/__tests__/company-skills.test.ts
@@ -366,6 +366,29 @@ describe("project workspace skill discovery", () => {
expect(imported.description).toBe("First line second line");
});
+ it("includes explicitly selected skills from non-standard folders", async () => {
+ const workspace = await makeTempDir("paperclip-skill-workspace-");
+ await writeSkillDir(path.join(workspace, "content", "specialists", "editorial"), "Editorial");
+
+ const discovered = await discoverProjectWorkspaceSkillDirectories({
+ projectId: "11111111-1111-1111-1111-111111111111",
+ projectName: "Repo",
+ workspaceId: "22222222-2222-2222-2222-222222222222",
+ workspaceName: "Main",
+ workspaceCwd: workspace,
+ }, ["content/specialists/editorial"]);
+
+ expect(discovered).toEqual([
+ {
+ skillDir: path.resolve(workspace, "content", "specialists", "editorial"),
+ directoryRoot: "content/specialists",
+ relativePath: "content/specialists/editorial",
+ inventoryMode: "full",
+ },
+ ]);
+ });
+
+
});
describe("missing local skill reconciliation", () => {
diff --git a/server/src/routes/company-skills.ts b/server/src/routes/company-skills.ts
index 80966a15a8..1aaba318e3 100644
--- a/server/src/routes/company-skills.ts
+++ b/server/src/routes/company-skills.ts
@@ -12,6 +12,7 @@ import {
companySkillInstallCatalogSchema,
companySkillInstallUpdateSchema,
companySkillListQuerySchema,
+ companySkillProjectBrowseRequestSchema,
companySkillProjectScanRequestSchema,
companySkillRenameSchema,
companySkillResetSchema,
@@ -1210,6 +1211,17 @@ export function companySkillRoutes(db: Db) {
},
);
+ router.post(
+ "/companies/:companyId/skills/browse-project",
+ validate(companySkillProjectBrowseRequestSchema),
+ async (req, res) => {
+ const companyId = req.params.companyId as string;
+ await assertCanMutateCompanySkills(req, companyId, "skills.import", { sourceType: "workspace" });
+ const result = await svc.browseProjectWorkspace(companyId, req.body);
+ res.json(result);
+ },
+ );
+
router.post(
"/companies/:companyId/skills/scan-projects",
validate(companySkillProjectScanRequestSchema),
diff --git a/server/src/routes/openapi.ts b/server/src/routes/openapi.ts
index 91aea336a5..b8701b6724 100644
--- a/server/src/routes/openapi.ts
+++ b/server/src/routes/openapi.ts
@@ -119,6 +119,8 @@ import {
companySkillFileDeleteSchema,
companySkillFileUpdateSchema,
companySkillImportSchema,
+ companySkillProjectBrowseRequestSchema,
+ companySkillProjectBrowseResultSchema,
companySkillProjectScanRequestSchema,
companySkillProjectScanResultSchema,
companySkillRenameResultSchema,
@@ -4726,6 +4728,18 @@ registry.registerPath({
responses: { 200: r.ok(), 400: r.badRequest, 401: r.unauthorized },
});
+registry.registerPath({
+ method: "post",
+ path: "/api/companies/{companyId}/skills/browse-project",
+ tags: ["skills"],
+ summary: "Browse a project workspace for skills",
+ request: {
+ params: z.object({ companyId: z.string() }),
+ body: jsonBody(companySkillProjectBrowseRequestSchema),
+ },
+ responses: { 200: r.ok(companySkillProjectBrowseResultSchema), 400: r.badRequest, 401: r.unauthorized },
+});
+
registry.registerPath({
method: "post",
path: "/api/companies/{companyId}/skills/scan-projects",
diff --git a/server/src/services/company-skills.ts b/server/src/services/company-skills.ts
index f5b03985c1..4776fadfa2 100644
--- a/server/src/services/company-skills.ts
+++ b/server/src/services/company-skills.ts
@@ -56,6 +56,8 @@ import type {
CompanySkillListItem,
CompanySkillLastEditor,
CompanySkillOriginalSummary,
+ CompanySkillProjectBrowseRequest,
+ CompanySkillProjectBrowseResult,
CompanySkillProjectScanConflict,
CompanySkillProjectScanCandidate,
CompanySkillProjectScanRequest,
@@ -1407,7 +1409,10 @@ export async function readLocalSkillImportFromDirectory(
};
}
-export async function discoverProjectWorkspaceSkillDirectories(target: ProjectSkillScanTarget): Promise<Array<{
+export async function discoverProjectWorkspaceSkillDirectories(
+ target: ProjectSkillScanTarget,
+ explicitPaths: string[] = [],
+): Promise<Array<{
skillDir: string;
directoryRoot: string;
relativePath: string;
@@ -1418,17 +1423,41 @@ export async function discoverProjectWorkspaceSkillDirectories(target: ProjectSk
relativePath: string;
inventoryMode: LocalSkillInventoryMode;
}>();
- const rootSkillPath = path.join(target.workspaceCwd, "SKILL.md");
+ const workspaceRoot = await fs.realpath(path.resolve(target.workspaceCwd)).catch(() => null);
+ if (!workspaceRoot) return [];
+ const rootSkillPath = path.join(workspaceRoot, "SKILL.md");
if ((await statPath(rootSkillPath))?.isFile()) {
- discovered.set(path.resolve(target.workspaceCwd), {
+ discovered.set(workspaceRoot, {
directoryRoot: ".",
relativePath: ".",
inventoryMode: "project_root",
});
}
+ for (const explicitPath of explicitPaths) {
+ const relativeSkillDir = explicitPath.toLowerCase().endsWith("/skill.md")
+ ? path.posix.dirname(explicitPath)
+ : explicitPath.toLowerCase() === "skill.md"
+ ? "."
+ : explicitPath;
+ const absoluteSkillDir = await fs.realpath(path.resolve(workspaceRoot, relativeSkillDir)).catch(() => null);
+ if (!absoluteSkillDir) continue;
+ const relativeToWorkspace = path.relative(workspaceRoot, absoluteSkillDir);
+ if (
+ relativeToWorkspace === ".."
+ || relativeToWorkspace.startsWith(`..${path.sep}`)
+ || path.isAbsolute(relativeToWorkspace)
+ ) continue;
+ if (!(await statPath(path.join(absoluteSkillDir, "SKILL.md")))?.isFile()) continue;
+ discovered.set(absoluteSkillDir, {
+ directoryRoot: relativeSkillDir === "." ? "." : path.posix.dirname(relativeSkillDir),
+ relativePath: relativeSkillDir,
+ inventoryMode: relativeSkillDir === "." ? "project_root" : "full",
+ });
+ }
+
for (const relativeRoot of PROJECT_SCAN_DIRECTORY_ROOTS) {
- const absoluteRoot = path.join(target.workspaceCwd, relativeRoot);
+ const absoluteRoot = path.join(workspaceRoot, relativeRoot);
const rootStat = await statPath(absoluteRoot);
if (!rootStat?.isDirectory()) continue;
@@ -1440,7 +1469,7 @@ export async function discoverProjectWorkspaceSkillDirectories(target: ProjectSk
if (!(await statPath(path.join(absoluteSkillDir, "SKILL.md")))?.isFile()) continue;
discovered.set(absoluteSkillDir, {
directoryRoot: relativeRoot,
- relativePath: normalizePortablePath(path.relative(target.workspaceCwd, absoluteSkillDir)),
+ relativePath: normalizePortablePath(path.relative(workspaceRoot, absoluteSkillDir)),
inventoryMode: "full",
});
}
@@ -4782,6 +4811,66 @@ export function companySkillService(db: Db) {
return persistAuditMetadata(reset, postAudit);
}
+ async function browseProjectWorkspace(
+ companyId: string,
+ input: CompanySkillProjectBrowseRequest,
+ ): Promise<CompanySkillProjectBrowseResult> {
+ const project = (await projects.listByIds(companyId, [input.projectId]))[0];
+ if (!project) throw notFound("Project not found");
+ const workspace = project.workspaces.find((entry) => entry.id === input.workspaceId);
+ if (!workspace) throw notFound("Project workspace not found");
+ const workspaceCwd = asString(workspace.cwd);
+ if (!workspaceCwd || workspace.sourceType === "remote_managed") {
+ throw unprocessable("Project workspace is not available for local browsing.");
+ }
+
+ const normalizedPath = input.path?.trim() ? normalizeProjectScanSelectionPath(input.path) : ".";
+ if (!normalizedPath) throw unprocessable("Project workspace path is invalid.");
+ const workspaceRoot = await fs.realpath(path.resolve(workspaceCwd)).catch(() => null);
+ if (!workspaceRoot) throw unprocessable("Project workspace is not available locally.");
+ const targetPath = await fs.realpath(path.resolve(workspaceRoot, normalizedPath)).catch(() => null);
+ if (!targetPath) throw notFound("Project workspace folder not found");
+ const relativeTarget = path.relative(workspaceRoot, targetPath);
+ if (relativeTarget === ".." || relativeTarget.startsWith(`..${path.sep}`) || path.isAbsolute(relativeTarget)) {
+ throw forbidden("Project workspace path is outside the workspace.");
+ }
+ const targetStat = await fs.stat(targetPath);
+ if (!targetStat.isDirectory()) throw unprocessable("Project workspace path must be a folder.");
+
+ const directoryEntries = await fs.readdir(targetPath, { withFileTypes: true });
+ const visibleDirectoryEntries = directoryEntries.filter((entry) => (
+ !entry.isSymbolicLink()
+ && entry.name !== ".git"
+ && entry.name !== "node_modules"
+ && (entry.isDirectory() || entry.isFile())
+ ));
+ const entries: CompanySkillProjectBrowseResult["entries"] = [];
+ for (const entry of visibleDirectoryEntries.slice(0, 250)) {
+ const entryPath = normalizedPath === "." ? entry.name : `${normalizedPath}/${entry.name}`;
+ entries.push({
+ name: entry.name,
+ path: entryPath,
+ kind: entry.isDirectory() ? "directory" : "file",
+ isSkill: entry.isDirectory()
+ ? Boolean((await statPath(path.join(targetPath, entry.name, "SKILL.md")))?.isFile())
+ : entry.name === "SKILL.md",
+ });
+ }
+ entries.sort((left, right) => {
+ if (left.kind !== right.kind) return left.kind === "directory" ? -1 : 1;
+ return left.name.localeCompare(right.name);
+ });
+ return {
+ projectId: project.id,
+ workspaceId: workspace.id,
+ workspaceName: workspace.name,
+ path: normalizedPath,
+ parentPath: normalizedPath === "." ? null : path.posix.dirname(normalizedPath) || ".",
+ entries,
+ truncated: visibleDirectoryEntries.length > 250,
+ };
+ }
+
async function scanProjectWorkspaces(
companyId: string,
input: CompanySkillProjectScanRequest = {},
@@ -4897,7 +4986,10 @@ export function companySkillService(db: Db) {
for (const target of scanTargets) {
scannedProjectIds.add(target.projectId);
- const directories = await discoverProjectWorkspaceSkillDirectories(target);
+ const explicitPaths = Array.from(selectedPaths.values())
+ .filter((selection) => selection.workspaceId === target.workspaceId)
+ .map((selection) => selection.path);
+ const directories = await discoverProjectWorkspaceSkillDirectories(target, explicitPaths);
for (const directory of directories) {
discovered += 1;
@@ -6835,6 +6927,7 @@ export function companySkillService(db: Db) {
pruneExpiredTestHarnessIssues,
importFromSource,
installFromCatalog,
+ browseProjectWorkspace,
scanProjectWorkspaces,
importPackageFiles,
auditSkill,
diff --git a/ui/src/api/companySkills.ts b/ui/src/api/companySkills.ts
index 731a8f6da7..f80d0b8629 100644
--- a/ui/src/api/companySkills.ts
+++ b/ui/src/api/companySkills.ts
@@ -20,6 +20,8 @@ import type {
CompanySkillInstallCatalogResult,
CompanySkillListQuery,
CompanySkillListItem,
+ CompanySkillProjectBrowseRequest,
+ CompanySkillProjectBrowseResult,
CompanySkillProjectScanRequest,
CompanySkillProjectScanResult,
CompanySkillStarResult,
@@ -215,6 +217,11 @@ export const companySkillsApi = {
`/companies/${encodeURIComponent(companyId)}/skills/import`,
{ source },
),
+ browseProject: (companyId: string, payload: CompanySkillProjectBrowseRequest) =>
+ api.post<CompanySkillProjectBrowseResult>(
+ `/companies/${encodeURIComponent(companyId)}/skills/browse-project`,
+ payload,
+ ),
scanProjects: (companyId: string, payload: CompanySkillProjectScanRequest = {}) =>
api.post<CompanySkillProjectScanResult>(
`/companies/${encodeURIComponent(companyId)}/skills/scan-projects`,
diff --git a/ui/src/pages/skills/ImportSkillsFromProjectDialog.tsx b/ui/src/pages/skills/ImportSkillsFromProjectDialog.tsx
index 019a3a1a1a..f20b87625b 100644
--- a/ui/src/pages/skills/ImportSkillsFromProjectDialog.tsx
+++ b/ui/src/pages/skills/ImportSkillsFromProjectDialog.tsx
@@ -5,8 +5,12 @@ import {
AlertTriangle,
ArrowLeft,
CheckCircle2,
+ ChevronRight,
ExternalLink,
+ FileText,
FileWarning,
+ Folder,
+ FolderOpen,
FolderSearch,
Layers,
Link2,
@@ -17,6 +21,7 @@ import {
} from "lucide-react";
import type {
CompanySkill,
+ CompanySkillProjectBrowseEntry,
CompanySkillProjectScanCandidate,
CompanySkillProjectScanResult,
Project,
@@ -287,6 +292,8 @@ export function ImportSkillsFromProjectDialog({
const [scanError, setScanError] = useState<unknown>(null);
const [selection, setSelection] = useState<Map<string, SkillSelection>>(new Map());
const [importResult, setImportResult] = useState<CompanySkillProjectScanResult | null>(null);
+ const [browseOpen, setBrowseOpen] = useState(false);
+ const [browseAddingKey, setBrowseAddingKey] = useState<string | null>(null);
const scanTokenRef = useRef(0);
const projectsQuery = useQuery({
@@ -306,6 +313,8 @@ export function ImportSkillsFromProjectDialog({
setScanError(null);
setSelection(new Map());
setImportResult(null);
+ setBrowseOpen(false);
+ setBrowseAddingKey(null);
scanTokenRef.current += 1;
}, [open]);
@@ -421,6 +430,50 @@ export function ImportSkillsFromProjectDialog({
});
}
+ async function addBrowsedSkill(workspaceId: string, selectedPath: string) {
+ if (!selectedProject) return;
+ const skillPath = selectedPath.toLowerCase().endsWith("/skill.md")
+ ? selectedPath.slice(0, -"/SKILL.md".length) || "."
+ : selectedPath.toLowerCase() === "skill.md"
+ ? "."
+ : selectedPath;
+ const key = selectionKey(workspaceId, skillPath);
+ setBrowseAddingKey(key);
+ try {
+ const result = await companySkillsApi.scanProjects(companyId, {
+ projectIds: [selectedProject.id],
+ mode: "preview",
+ selection: [{ workspaceId, path: skillPath }],
+ });
+ setScanResult(result);
+ const candidate = result.candidates.find((entry) => (
+ entry.workspaceId === workspaceId && entry.relativePath === skillPath
+ ));
+ if (candidate && isSelectableCandidate(candidate)) {
+ setSelection((previous) => {
+ const next = new Map(previous);
+ next.set(key, {
+ workspaceId,
+ path: skillPath,
+ ...(candidate.status === "conflict" ? { slug: suggestedConflictSlug(candidate) } : {}),
+ });
+ return next;
+ });
+ setBrowseOpen(false);
+ } else {
+ toast.pushToast({
+ tone: "warn",
+ title: candidate?.status === "already_imported" ? "Skill already imported" : "Skill could not be added",
+ body: candidate?.reason ?? "The selected folder does not contain a valid SKILL.md file.",
+ });
+ }
+ } catch (error) {
+ toast.pushToast({ tone: "error", title: "Could not inspect skill", body: readableErrorMessage(error) });
+ } finally {
+ setBrowseAddingKey(null);
+ }
+ }
+
function selectAll() {
setSelection(selectAllSelection(candidates));
}
@@ -501,6 +554,12 @@ export function ImportSkillsFromProjectDialog({
selection={selection}
toggleCandidate={toggleCandidate}
renameCandidate={renameCandidate}
+ project={selectedProject}
+ companyId={companyId}
+ browseOpen={browseOpen}
+ onBrowseOpenChange={setBrowseOpen}
+ onAddBrowsedSkill={addBrowsedSkill}
+ browseAddingKey={browseAddingKey}
/>
)}
{step === "result" && importResult && <ResultStep result={importResult} />}
@@ -717,6 +776,131 @@ function ScanningStep({ projectName }: { projectName: string }) {
);
}
+
+function ProjectSkillBrowser({
+ companyId,
+ project,
+ onBack,
+ onAddSkill,
+ addingKey,
+}: {
+ companyId: string;
+ project: Project;
+ onBack: () => void;
+ onAddSkill: (workspaceId: string, path: string) => void;
+ addingKey: string | null;
+}) {
+ const workspaces = scannableWorkspaces(project);
+ const initialWorkspace = workspaces.find((workspace) => workspace.isPrimary) ?? workspaces[0] ?? null;
+ const [workspaceId, setWorkspaceId] = useState(initialWorkspace?.id ?? "");
+ const [folderPath, setFolderPath] = useState(".");
+ const browseQuery = useQuery({
+ queryKey: ["company-skills", "browse-project", companyId, project.id, workspaceId, folderPath],
+ queryFn: () => companySkillsApi.browseProject(companyId, {
+ projectId: project.id,
+ workspaceId,
+ path: folderPath,
+ }),
+ enabled: Boolean(workspaceId),
+ });
+ const result = browseQuery.data;
+
+ function changeWorkspace(nextWorkspaceId: string) {
+ setWorkspaceId(nextWorkspaceId);
+ setFolderPath(".");
+ }
+
+ return (
+ <div className="flex min-h-0 flex-1 flex-col" data-testid="project-skill-browser">
+ <div className="shrink-0 border-b border-border/60 px-5 py-3">
+ <div className="flex flex-wrap items-center justify-between gap-3">
+ <div>
+ <p className="text-sm font-medium">Browse project folders</p>
+ <p className="mt-0.5 text-xs text-muted-foreground">Open any folder and add directories or individual SKILL.md files.</p>
+ </div>
+ <Button variant="outline" size="sm" onClick={onBack}>
+ <ArrowLeft className="mr-1 h-3.5 w-3.5" /> Discovered skills
+ </Button>
+ </div>
+ {workspaces.length > 1 && (
+ <div className="mt-3 flex flex-wrap gap-1.5" aria-label="Project workspace">
+ {workspaces.map((workspace) => (
+ <Button
+ key={workspace.id}
+ type="button"
+ variant={workspace.id === workspaceId ? "secondary" : "ghost"}
+ size="sm"
+ onClick={() => changeWorkspace(workspace.id)}
+ >
+ {workspace.name}
+ </Button>
+ ))}
+ </div>
+ )}
+ </div>
+ <div className="flex shrink-0 items-center gap-2 border-b border-border/60 bg-muted/20 px-5 py-2">
+ <Button
+ variant="ghost"
+ size="sm"
+ onClick={() => result?.parentPath && setFolderPath(result.parentPath)}
+ disabled={!result?.parentPath}
+ aria-label="Open parent folder"
+ >
+ <ArrowLeft className="h-3.5 w-3.5" />
+ </Button>
+ <span className="min-w-0 truncate font-mono text-xs text-muted-foreground">{result?.path ?? folderPath}</span>
+ </div>
+ <div className="min-h-0 flex-1 overflow-y-auto">
+ {browseQuery.isLoading ? (
+ <div className="flex items-center justify-center gap-2 p-8 text-sm text-muted-foreground">
+ <Loader2 className="h-4 w-4 animate-spin" /> Loading folder…
+ </div>
+ ) : browseQuery.error ? (
+ <div className="p-6 text-sm text-destructive">{readableErrorMessage(browseQuery.error)}</div>
+ ) : result?.entries.length ? (
+ <ul className="divide-y divide-border/60">
+ {result.entries.map((entry: CompanySkillProjectBrowseEntry) => {
+ const selectablePath = entry.kind === "file"
+ ? entry.path.toLowerCase() === "skill.md" ? "." : entry.path.slice(0, -"/SKILL.md".length)
+ : entry.path;
+ const key = selectionKey(workspaceId, selectablePath);
+ return (
+ <li key={entry.path} className="flex items-center gap-3 px-5 py-2.5">
+ {entry.kind === "directory" ? (
+ <Folder className="h-4 w-4 shrink-0 text-muted-foreground" />
+ ) : (
+ <FileText className="h-4 w-4 shrink-0 text-muted-foreground" />
+ )}
+ <button
+ type="button"
+ className={cn("min-w-0 flex-1 truncate text-left text-sm", entry.kind === "directory" && "font-medium hover:underline")}
+ onClick={() => entry.kind === "directory" && setFolderPath(entry.path)}
+ disabled={entry.kind === "file"}
+ >
+ {entry.name}
+ </button>
+ {entry.isSkill ? (
+ <Button size="sm" onClick={() => onAddSkill(workspaceId, entry.path)} disabled={addingKey === key}>
+ {addingKey === key ? <Loader2 className="h-3.5 w-3.5 animate-spin" /> : "Add skill"}
+ </Button>
+ ) : entry.kind === "directory" ? (
+ <ChevronRight className="h-4 w-4 text-muted-foreground" />
+ ) : null}
+ </li>
+ );
+ })}
+ </ul>
+ ) : (
+ <div className="p-8 text-center text-sm text-muted-foreground">This folder is empty.</div>
+ )}
+ {result?.truncated && (
+ <p className="border-t border-border/60 px-5 py-2 text-xs text-muted-foreground">Showing the first 250 entries.</p>
+ )}
+ </div>
+ </div>
+ );
+}
+
interface SelectStepProps {
scanError: unknown;
onRetry: () => void;
@@ -728,6 +912,12 @@ interface SelectStepProps {
selection: Map<string, SkillSelection>;
toggleCandidate: (candidate: CompanySkillProjectScanCandidate) => void;
renameCandidate: (candidate: CompanySkillProjectScanCandidate, slug: string) => void;
+ project: Project | null;
+ companyId: string;
+ browseOpen: boolean;
+ onBrowseOpenChange: (open: boolean) => void;
+ onAddBrowsedSkill: (workspaceId: string, path: string) => void;
+ browseAddingKey: string | null;
}
function SelectStep({
@@ -741,6 +931,12 @@ function SelectStep({
selection,
toggleCandidate,
renameCandidate,
+ project,
+ companyId,
+ browseOpen,
+ onBrowseOpenChange,
+ onAddBrowsedSkill,
+ browseAddingKey,
}: SelectStepProps) {
if (scanError) {
const grant = isGrantError(scanError);
@@ -772,6 +968,18 @@ function SelectStep({
);
}
+ if (browseOpen && project) {
+ return (
+ <ProjectSkillBrowser
+ companyId={companyId}
+ project={project}
+ onBack={() => onBrowseOpenChange(false)}
+ onAddSkill={onAddBrowsedSkill}
+ addingKey={browseAddingKey}
+ />
+ );
+ }
+
if (totalCandidates === 0) {
return (
<div
@@ -790,6 +998,15 @@ function SelectStep({
HIGHLIGHTED_SCAN_FOLDERS.length}{" "}
other agent-harness folders.
</p>
+ <Button
+ variant="outline"
+ size="sm"
+ className="mt-4"
+ onClick={() => onBrowseOpenChange(true)}
+ data-testid="browse-project-folders-empty"
+ >
+ <FolderOpen className="mr-1.5 h-3.5 w-3.5" /> Browse project folders
+ </Button>
{onImportFromPath && (
<p className="mt-3 text-sm text-muted-foreground">
For skills in non-standard folders, use{" "}
@@ -810,6 +1027,12 @@ function SelectStep({
return (
<div className="flex min-h-0 flex-1 flex-col" data-testid="candidate-list">
+ <div className="flex shrink-0 items-center justify-between gap-3 border-b border-border/60 px-5 py-2.5">
+ <p className="text-xs text-muted-foreground">Choose discovered skills, or browse any workspace folder.</p>
+ <Button variant="outline" size="sm" onClick={() => onBrowseOpenChange(true)} data-testid="browse-project-folders">
+ <FolderOpen className="mr-1.5 h-3.5 w-3.5" /> Browse folders
+ </Button>
+ </div>
<div className="shrink-0 border-b border-border/60 px-5 py-2.5">
<div className="relative">
<Search className="absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground" />