mirror of
https://github.com/davidkaya/aryx.git
synced 2026-08-03 18:38:35 +02:00
feat: allow deletion of built-in orchestration patterns
Remove the restriction that prevented users from deleting built-in patterns (those with IDs prefixed 'pattern-'). Built-in patterns are intended as starting points, not permanent fixtures. Changes: - Add deletedBuiltinPatternIds field to WorkspaceState to track which built-in patterns the user has removed - Update mergePatterns to skip deleted built-ins during workspace load, preventing them from being re-added - Remove the isBuiltinPattern guard from AryxAppService.deletePattern; when a built-in is deleted, its ID is recorded in the tracking list - Enable the delete button in SettingsPanel and PatternEditor for all patterns (keep the 'Built-in pattern' label for context) - Add 3 tests covering built-in deletion, custom deletion, and selectedPatternId fallback Users can still restore deleted built-ins via workspace reset. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -710,13 +710,15 @@ export class AryxAppService extends EventEmitter<AppServiceEvents> {
|
||||
}
|
||||
|
||||
async deletePattern(patternId: string): Promise<WorkspaceState> {
|
||||
if (isBuiltinPattern(patternId)) {
|
||||
throw new Error('Built-in patterns cannot be deleted.');
|
||||
}
|
||||
|
||||
const workspace = await this.loadWorkspace();
|
||||
workspace.patterns = workspace.patterns.filter((pattern) => pattern.id !== patternId);
|
||||
|
||||
if (isBuiltinPattern(patternId)) {
|
||||
const deletedIds = new Set(workspace.deletedBuiltinPatternIds ?? []);
|
||||
deletedIds.add(patternId);
|
||||
workspace.deletedBuiltinPatternIds = [...deletedIds];
|
||||
}
|
||||
|
||||
if (workspace.selectedPatternId === patternId) {
|
||||
workspace.selectedPatternId = workspace.patterns[0]?.id;
|
||||
}
|
||||
|
||||
@@ -30,13 +30,16 @@ import {
|
||||
} from '@main/persistence/appPaths';
|
||||
import { readJsonFile, writeJsonFile } from '@main/persistence/jsonStore';
|
||||
|
||||
function mergePatterns(existingPatterns: PatternDefinition[]): PatternDefinition[] {
|
||||
function mergePatterns(existingPatterns: PatternDefinition[], deletedBuiltinIds: string[]): PatternDefinition[] {
|
||||
const builtinTimestamp = nowIso();
|
||||
const builtinPatterns = createBuiltinPatterns(builtinTimestamp);
|
||||
const builtinIds = new Set(builtinPatterns.map((pattern) => pattern.id));
|
||||
const deletedSet = new Set(deletedBuiltinIds);
|
||||
const existingMap = new Map(existingPatterns.map((pattern) => [pattern.id, pattern]));
|
||||
|
||||
const mergedBuiltins = builtinPatterns.map((builtin) => {
|
||||
const mergedBuiltins = builtinPatterns
|
||||
.filter((builtin) => !deletedSet.has(builtin.id))
|
||||
.map((builtin) => {
|
||||
const existing = existingMap.get(builtin.id);
|
||||
if (!existing) {
|
||||
return builtin;
|
||||
@@ -108,9 +111,11 @@ export class WorkspaceRepository {
|
||||
}));
|
||||
const settings = normalizeWorkspaceSettings(stored.settings);
|
||||
|
||||
const deletedBuiltinPatternIds = stored.deletedBuiltinPatternIds ?? [];
|
||||
|
||||
const workspace: WorkspaceState = {
|
||||
...stored,
|
||||
patterns: mergePatterns(stored.patterns ?? []).map((pattern) => ({
|
||||
patterns: mergePatterns(stored.patterns ?? [], deletedBuiltinPatternIds).map((pattern) => ({
|
||||
...pattern,
|
||||
approvalPolicy: applyDefaultToolApprovalPolicy(pattern.approvalPolicy),
|
||||
graph: resolvePatternGraph(pattern),
|
||||
@@ -118,6 +123,7 @@ export class WorkspaceRepository {
|
||||
projects,
|
||||
sessions,
|
||||
settings,
|
||||
deletedBuiltinPatternIds,
|
||||
selectedProjectId: projects.some((project) => project.id === stored.selectedProjectId)
|
||||
? stored.selectedProjectId
|
||||
: projects[0]?.id,
|
||||
|
||||
Reference in New Issue
Block a user