forked from farhoodlabs/paperclip
feat(skills): add dryRun flag for scan prune path
Add a `dryRun` option to the scan-projects endpoint. When true, the scan identifies which skills would be pruned and which agents would be affected, but does not delete anything or modify agent configs. The response now includes: - `pruned[]`: list of skills that would be (or were) removed, with affected agent names - `dryRun`: boolean echoed back so callers can distinguish preview results from live mutations This lets callers preview destructive prune operations before committing to them, addressing the review concern about silent deletion of production data. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
@@ -17,6 +17,7 @@ import type {
|
||||
CompanySkillImportResult,
|
||||
CompanySkillListItem,
|
||||
CompanySkillProjectScanConflict,
|
||||
CompanySkillProjectScanPruned,
|
||||
CompanySkillProjectScanRequest,
|
||||
CompanySkillProjectScanResult,
|
||||
CompanySkillProjectScanSkipped,
|
||||
@@ -1860,8 +1861,10 @@ export function companySkillService(db: Db) {
|
||||
? await projects.listByIds(companyId, input.projectIds)
|
||||
: await projects.list(companyId);
|
||||
const workspaceFilter = new Set(input.workspaceIds ?? []);
|
||||
const dryRun = input.dryRun === true;
|
||||
const skipped: CompanySkillProjectScanSkipped[] = [];
|
||||
const conflicts: CompanySkillProjectScanConflict[] = [];
|
||||
const pruned: CompanySkillProjectScanPruned[] = [];
|
||||
const warnings: string[] = [];
|
||||
const imported: CompanySkill[] = [];
|
||||
const updated: CompanySkill[] = [];
|
||||
@@ -2043,6 +2046,18 @@ export function companySkillService(db: Db) {
|
||||
for (const skill of skillsAtSource) {
|
||||
if (currentSlugs.has(skill.slug)) continue;
|
||||
const usedByAgents = await usage(companyId, skill.key);
|
||||
const affectedAgentNames = usedByAgents.map((a) => a.name);
|
||||
|
||||
pruned.push({
|
||||
skillId: skill.id,
|
||||
slug: skill.slug,
|
||||
key: skill.key,
|
||||
sourceLocator: skill.sourceLocator,
|
||||
affectedAgents: affectedAgentNames,
|
||||
});
|
||||
|
||||
if (dryRun) continue;
|
||||
|
||||
if (usedByAgents.length > 0) {
|
||||
// Detach the skill from all agents that have it, then delete
|
||||
for (const agent of usedByAgents) {
|
||||
@@ -2059,7 +2074,7 @@ export function companySkillService(db: Db) {
|
||||
}
|
||||
}
|
||||
warnings.push(
|
||||
`Skill "${skill.slug}" was removed from ${sourceLocator} and detached from ${usedByAgents.map((a) => a.name).join(", ")}.`,
|
||||
`Skill "${skill.slug}" was removed from ${sourceLocator} and detached from ${affectedAgentNames.join(", ")}.`,
|
||||
);
|
||||
} else {
|
||||
warnings.push(
|
||||
@@ -2082,7 +2097,9 @@ export function companySkillService(db: Db) {
|
||||
updated,
|
||||
skipped,
|
||||
conflicts,
|
||||
pruned,
|
||||
warnings,
|
||||
dryRun,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user